This commit is contained in:
Christian Gunderman
2026-02-03 00:01:33 -08:00
parent 3dce0fe6e5
commit 411520a328
4 changed files with 28 additions and 14 deletions

View File

@@ -40,25 +40,27 @@ describe('AcknowledgedAgentsService', () => {
const service = new AcknowledgedAgentsService();
const ackPath = Storage.getAcknowledgedAgentsPath();
await service.acknowledge('/project', 'AgentA', 'hash1');
await service.acknowledge('/project', 'AgentA', 'content1');
// Verify file exists and content
const content = await fs.readFile(ackPath, 'utf-8');
expect(content).toContain('"AgentA": "hash1"');
const hash1 = AcknowledgedAgentsService.computeHash('content1');
expect(content).toContain(`"AgentA": "${hash1}"`);
});
it('should return true for acknowledged agent', async () => {
const service = new AcknowledgedAgentsService();
await service.acknowledge('/project', 'AgentA', 'hash1');
await service.acknowledge('/project', 'AgentA', 'content1');
expect(await service.isAcknowledged('/project', 'AgentA', 'hash1')).toBe(
const hash1 = AcknowledgedAgentsService.computeHash('content1');
expect(await service.isAcknowledged('/project', 'AgentA', hash1)).toBe(
true,
);
expect(await service.isAcknowledged('/project', 'AgentA', 'hash2')).toBe(
false,
);
expect(await service.isAcknowledged('/project', 'AgentB', 'hash1')).toBe(
expect(await service.isAcknowledged('/project', 'AgentB', hash1)).toBe(
false,
);
});

View File

@@ -78,8 +78,9 @@ export class AcknowledgedAgentsService {
async acknowledge(
projectPath: string,
agentName: string,
hash: string,
content: string,
): Promise<void> {
const hash = AcknowledgedAgentsService.computeHash(content);
await this.load();
if (!this.acknowledgedAgents[projectPath]) {
this.acknowledgedAgents[projectPath] = {};

View File

@@ -4,11 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/
import * as fs from 'node:fs/promises';
import { Storage } from '../config/storage.js';
import { CoreEvent, coreEvents } from '../utils/events.js';
import type { AgentOverride, Config } from '../config/config.js';
import type { AgentDefinition, LocalAgentDefinition } from './types.js';
import { loadAgentsFromDirectory } from './agentLoader.js';
import { AcknowledgedAgentsService } from './acknowledgedAgents.js';
import { CodebaseInvestigatorAgent } from './codebase-investigator.js';
import { CliHelpAgent } from './cli-help-agent.js';
import { GeneralistAgent } from './generalist-agent.js';
@@ -81,11 +83,19 @@ export class AgentRegistry {
const ackService = this.config.getAcknowledgedAgentsService();
const projectRoot = this.config.getProjectRoot();
if (agent.metadata?.hash) {
await ackService.acknowledge(
projectRoot,
agent.name,
agent.metadata.hash,
);
let content: string;
if (agent.kind === 'remote') {
content = agent.agentCardUrl;
} else {
if (!agent.metadata.filePath) {
throw new Error(
`Cannot acknowledge local agent ${agent.name}: missing file path`,
);
}
content = await fs.readFile(agent.metadata.filePath, 'utf-8');
}
await ackService.acknowledge(projectRoot, agent.name, content);
await this.registerAgent(agent);
coreEvents.emitAgentsRefreshed();
}
@@ -146,7 +156,9 @@ export class AgentRegistry {
if (!agent.metadata) {
agent.metadata = {};
}
agent.metadata.hash = agent.agentCardUrl;
agent.metadata.hash = AcknowledgedAgentsService.computeHash(
agent.agentCardUrl,
);
}
if (!agent.metadata?.hash) {

View File

@@ -369,8 +369,7 @@ export class TestRig {
try {
const service = new AcknowledgedAgentsService();
for (const [name, content] of Object.entries(agents)) {
const hash = AcknowledgedAgentsService.computeHash(content);
await service.acknowledge(projectRoot, name, hash);
await service.acknowledge(projectRoot, name, content);
}
} finally {
if (originalHome) {