FN-5758: add cited-goal audit aggregation and runtime route

Add end-to-end goal-citation audit trail plumbing across core, engine, CLI, and dashboard.

- extend goal citation extraction with aggregation logic and new core coverage
- expose cited-goal runtime data through dashboard routes with dedicated API tests
- wire goal-citation audit details into engine diagnostics and CLI extension audit expectations
- document the new audit behavior and publish a patch changeset for @runfusion/fusion

Files changed:
 .changeset/fn-5758-goal-citation-audit.md          |  9 +++
 docs/dashboard-guide.md                            |  2 +
 docs/diagnostics.md                                |  4 ++
 .../__tests__/extension-goal-tools-audit.test.ts   |  6 +-
 packages/cli/src/extension.ts                      |  3 +
 .../goal-citation-audit-aggregation.test.ts        | 63 ++++++++++++++++++
 packages/core/src/goal-citation-extractor.ts       | 54 ++++++++++++++-
 packages/core/src/index.ts                         |  1 +
 .../src/__tests__/routes-run-cited-goals.test.ts   | 77 ++++++++++++++++++++++
 packages/dashboard/src/routes.ts                   | 11 ++++
 .../src/routes/register-agent-runtime-routes.ts    | 49 ++++++++++++++
 .../src/__tests__/goal-anchoring-audit.test.ts     | 40 +++++++----
 packages/engine/src/goal-anchoring-audit.ts        |  4 ++
 packages/engine/src/goal-injection-diagnostics.ts  |  1 +
 14 files changed, 308 insertions(+), 16 deletions(-)

Fusion-Task-Id: FN-5758

Fusion-Task-Lineage: b077c0b7-6ca4-489d-8c36-73d80a2afdb2
This commit is contained in:
gsxdsm
2026-05-30 22:53:24 -07:00
parent d98ff8780c
commit 194dfa9387
14 changed files with 308 additions and 16 deletions

View File

@@ -0,0 +1,63 @@
import { describe, expect, it } from "vitest";
import type { RunAuditEvent } from "../types.js";
import { collectCitedGoalIdsFromAudit } from "../goal-citation-extractor.js";
function event(partial: Partial<RunAuditEvent>): RunAuditEvent {
return {
id: "e-1",
timestamp: new Date().toISOString(),
agentId: "agent-1",
runId: "run-1",
domain: "database",
mutationType: "task:update",
target: "task",
...partial,
};
}
describe("collectCitedGoalIdsFromAudit", () => {
it("returns empty collections for empty events", () => {
expect(collectCitedGoalIdsFromAudit([])).toEqual({
injectedGoalIds: [],
retrievedGoalIds: [],
citedGoalIds: [],
});
});
it("collects injection goal ids", () => {
const result = collectCitedGoalIdsFromAudit([
event({ mutationType: "goal:injection-applied", metadata: { goalIds: ["G-A", "G-B"] } }),
event({ mutationType: "prompt:goal-injection", metadata: { goalIds: ["G-B", "G-C"] } }),
]);
expect(result).toEqual({
injectedGoalIds: ["G-A", "G-B", "G-C"],
retrievedGoalIds: [],
citedGoalIds: ["G-A", "G-B", "G-C"],
});
});
it("collects retrieval goal ids from metadata, target, and goalId", () => {
const result = collectCitedGoalIdsFromAudit([
event({ mutationType: "goal:retrieval-invoked", target: "G-A", metadata: { goalIds: ["G-B"], goalId: "G-C" } }),
event({ mutationType: "goal:retrieval-invoked", target: "goals", metadata: { goalId: "G-D" } }),
]);
expect(result).toEqual({
injectedGoalIds: [],
retrievedGoalIds: ["G-B", "G-A", "G-C", "G-D"],
citedGoalIds: ["G-B", "G-A", "G-C", "G-D"],
});
});
it("dedupes and ignores malformed/non-goal ids", () => {
const result = collectCitedGoalIdsFromAudit([
event({ mutationType: "goal:injection-skipped", metadata: { goalIds: ["G-1", "FN-1", 42, "G-1"] } }),
event({ mutationType: "goal:retrieval-invoked", target: "goals", metadata: { goalIds: ["G-1", "G-2", "task-1"], goalId: "G-2" } }),
event({ mutationType: "goal:retrieval-invoked", target: "FN-9", metadata: { goalId: "not-a-goal" } }),
]);
expect(result).toEqual({
injectedGoalIds: ["G-1"],
retrievedGoalIds: ["G-1", "G-2"],
citedGoalIds: ["G-1", "G-2"],
});
});
});