From d0d2f513de21b01e60286d651623e5bed3147f00 Mon Sep 17 00:00:00 2001 From: Dukeabadoon Date: Wed, 12 Aug 2026 14:01:09 +0800 Subject: [PATCH 1/4] fix(core): harden ledger concurrency tests and races Replace the fixed 100ms worker sleep with a SharedArrayBuffer barrier so all workers reach contention before the test lock releases. Recover from concurrent UNIQUE inserts in appendSupportingArtifact by reconciling the existing row instead of surfacing raw SQLite errors. --- packages/core/src/ledger.test.ts | 82 ++-------------- packages/core/src/ledger.ts | 61 ++++++++---- packages/mcp/src/pipeline.e2e.test.ts | 107 +++++---------------- test/helpers/blocked-sqlite-workers.ts | 97 +++++++++++++++++++ test/helpers/supporting-artifact-worker.ts | 14 ++- 5 files changed, 186 insertions(+), 175 deletions(-) create mode 100644 test/helpers/blocked-sqlite-workers.ts diff --git a/packages/core/src/ledger.test.ts b/packages/core/src/ledger.test.ts index f2c8be0..8980bd4 100644 --- a/packages/core/src/ledger.test.ts +++ b/packages/core/src/ledger.test.ts @@ -10,88 +10,19 @@ import { import { tmpdir } from "node:os"; import { join } from "node:path"; import { DatabaseSync } from "node:sqlite"; -import { Worker } from "node:worker_threads"; import { afterEach, describe, expect, it } from "vitest"; +import { runBlockedWorkers } from "../../../test/helpers/blocked-sqlite-workers.js"; import { SqliteLedger } from "./ledger.js"; import type { ArtifactSubmission, RunRecord } from "./types.js"; const ledgers: SqliteLedger[] = []; -type WorkerResult = - | { kind: "result"; ok: true; artifact: unknown } - | { kind: "result"; ok: false; error: string }; - -function workerMessage(worker: Worker, kind: string): Promise { - return new Promise((resolvePromise, rejectPromise) => { - const onMessage = (message: { kind?: unknown }): void => { - if (message.kind !== kind) return; - cleanup(); - resolvePromise(message as T); - }; - const onError = (error: Error): void => { - cleanup(); - rejectPromise(error); - }; - const onExit = (code: number): void => { - cleanup(); - rejectPromise( - new Error( - `Supporting worker exited with code ${String(code)} before ${kind}`, - ), - ); - }; - const cleanup = (): void => { - worker.off("message", onMessage); - worker.off("error", onError); - worker.off("exit", onExit); - }; - worker.on("message", onMessage); - worker.on("error", onError); - worker.on("exit", onExit); - }); -} - -async function runBlockedWorkers( - databasePath: string, - workerData: readonly Record[], -): Promise { - const workerUrl = new URL( - "../../../test/helpers/supporting-artifact-worker.ts", - import.meta.url, - ); - const workers = workerData.map( - (data) => - new Worker(workerUrl, { - workerData: data, - execArgv: ["--import", "tsx"], - }), - ); - await Promise.all( - workers.map(async (worker) => workerMessage(worker, "ready")), - ); - const blocker = new DatabaseSync(databasePath); - blocker.exec("PRAGMA busy_timeout = 5000; BEGIN IMMEDIATE;"); - let locked = true; - try { - const starting = workers.map(async (worker) => - workerMessage(worker, "starting"), - ); - const results = workers.map(async (worker) => - workerMessage(worker, "result"), - ); - for (const worker of workers) worker.postMessage("go"); - await Promise.all(starting); - await new Promise((resolvePromise) => setTimeout(resolvePromise, 100)); - blocker.exec("COMMIT"); - locked = false; - return await Promise.all(results); - } finally { - if (locked) blocker.exec("ROLLBACK"); - blocker.close(); - } -} +const supportingWorkerUrl = new URL( + "../../../test/helpers/supporting-artifact-worker.ts", + import.meta.url, +); function createRun(): RunRecord { return { @@ -345,6 +276,7 @@ describe("SQLite ledger and content-addressed artifacts", () => { decisionSummary: "Stored bounded evidence.", }; const results = await runBlockedWorkers( + supportingWorkerUrl, ledger.databasePath, Array.from({ length: 2 }, () => ({ kind: "ledger", @@ -377,7 +309,7 @@ describe("SQLite ledger and content-addressed artifacts", () => { eventType: "evidence_captured", decisionSummary: "Stored bounded evidence.", }; - const results = await runBlockedWorkers(ledger.databasePath, [ + const results = await runBlockedWorkers(supportingWorkerUrl, ledger.databasePath, [ { kind: "ledger", stateDirectory: ledger.rootDirectory, diff --git a/packages/core/src/ledger.ts b/packages/core/src/ledger.ts index 6c0de2e..404c5c8 100644 --- a/packages/core/src/ledger.ts +++ b/packages/core/src/ledger.ts @@ -454,6 +454,36 @@ export class SqliteLedger { } } + private reconcileExistingSupportingArtifact( + existing: HydratedArtifact, + artifact: ArtifactSubmission, + ): StoredArtifact { + const expectedSourceRefs = artifact.sourceRefs ?? []; + const expectedRedaction = artifact.redaction ?? "none"; + if ( + existing.type !== artifact.type || + existing.schemaVersion !== artifact.schemaVersion || + existing.producer !== artifact.producer || + existing.sha256 !== sha256Json(artifact.body) || + canonicalJson(existing.sourceRefs) !== + canonicalJson(expectedSourceRefs) || + existing.redaction !== expectedRedaction + ) { + throw new Error( + `Supporting artifact replay conflicts with immutable artifact: ${artifact.id}`, + ); + } + const { body: _body, ...stored } = existing; + return stored; + } + + private isUniqueConstraintError(error: unknown): boolean { + return ( + error instanceof Error && + /UNIQUE constraint failed/i.test(error.message) + ); + } + appendSupportingArtifact( artifact: ArtifactSubmission, event: Omit & { phase?: Phase }, @@ -464,29 +494,26 @@ export class SqliteLedger { const run = this.requireRun(artifact.runId); const existing = this.getArtifact(artifact.runId, artifact.id); if (existing) { - const expectedSourceRefs = artifact.sourceRefs ?? []; - const expectedRedaction = artifact.redaction ?? "none"; - if ( - existing.type !== artifact.type || - existing.schemaVersion !== artifact.schemaVersion || - existing.producer !== artifact.producer || - existing.sha256 !== sha256Json(artifact.body) || - canonicalJson(existing.sourceRefs) !== - canonicalJson(expectedSourceRefs) || - existing.redaction !== expectedRedaction - ) { - throw new Error( - `Supporting artifact replay conflicts with immutable artifact: ${artifact.id}`, - ); - } - const { body: _body, ...stored } = existing; + const stored = this.reconcileExistingSupportingArtifact( + existing, + artifact, + ); this.database.exec("COMMIT"); return stored; } this.assertArtifactSlot(artifact.runId, artifact.id); if (quota) this.assertSupportingArtifactQuota(artifact, quota); const stored = this.prepareArtifact(artifact); - this.insertPreparedArtifact(stored); + try { + this.insertPreparedArtifact(stored); + } catch (error) { + if (!this.isUniqueConstraintError(error)) throw error; + const raced = this.getArtifact(artifact.runId, artifact.id); + if (!raced) throw error; + const replay = this.reconcileExistingSupportingArtifact(raced, artifact); + this.database.exec("COMMIT"); + return replay; + } this.insertEvent(run, { ...event, phase: event.phase ?? run.phase, diff --git a/packages/mcp/src/pipeline.e2e.test.ts b/packages/mcp/src/pipeline.e2e.test.ts index 3cf9685..6b0b158 100644 --- a/packages/mcp/src/pipeline.e2e.test.ts +++ b/packages/mcp/src/pipeline.e2e.test.ts @@ -1,8 +1,6 @@ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; -import { DatabaseSync } from "node:sqlite"; -import { Worker } from "node:worker_threads"; import { afterEach, describe, expect, it } from "vitest"; @@ -10,43 +8,17 @@ import { NO_PERMISSIONS, VALID_ARTIFACT_BODIES, } from "../../protocol/test/test-helpers.js"; +import { + runBlockedWorkers, + type BlockedWorkerResult, +} from "../../../test/helpers/blocked-sqlite-workers.js"; import { TelicService } from "./service.js"; const services: TelicService[] = []; - -type SupportingWorkerResult = - | { kind: "result"; ok: true; artifact: unknown } - | { kind: "result"; ok: false; error: string }; - -function supportingWorkerMessage(worker: Worker, kind: string): Promise { - return new Promise((resolvePromise, rejectPromise) => { - const onMessage = (message: { kind?: unknown }): void => { - if (message.kind !== kind) return; - cleanup(); - resolvePromise(message as T); - }; - const onError = (error: Error): void => { - cleanup(); - rejectPromise(error); - }; - const onExit = (code: number): void => { - cleanup(); - rejectPromise( - new Error( - `Supporting worker exited with code ${String(code)} before ${kind}`, - ), - ); - }; - const cleanup = (): void => { - worker.off("message", onMessage); - worker.off("error", onError); - worker.off("exit", onExit); - }; - worker.on("message", onMessage); - worker.on("error", onError); - worker.on("exit", onExit); - }); -} +const supportingWorkerUrl = new URL( + "../../../test/helpers/supporting-artifact-worker.ts", + import.meta.url, +); async function runBlockedServiceWorkers( harness: Awaited>, @@ -55,53 +27,24 @@ async function runBlockedServiceWorkers( producer: string; body: Record; }[], -): Promise { - const workerUrl = new URL( - "../../../test/helpers/supporting-artifact-worker.ts", - import.meta.url, - ); - const workers = submissions.map( - (submission) => - new Worker(workerUrl, { - workerData: { - kind: "service", - repositoryRoot: harness.service.repositoryRoot, - stateDirectory: harness.service.stateDirectory, - artifact: { - id: submission.body.id, - runId: harness.started.run.runId, - type: submission.type, - schemaVersion: "1.0", - producer: submission.producer, - body: submission.body, - }, - }, - execArgv: ["--import", "tsx"], - }), - ); - await Promise.all( - workers.map(async (worker) => supportingWorkerMessage(worker, "ready")), +): Promise { + return runBlockedWorkers( + supportingWorkerUrl, + harness.service.ledger.databasePath, + submissions.map((submission) => ({ + kind: "service" as const, + repositoryRoot: harness.service.repositoryRoot, + stateDirectory: harness.service.stateDirectory, + artifact: { + id: submission.body.id, + runId: harness.started.run.runId, + type: submission.type, + schemaVersion: "1.0", + producer: submission.producer, + body: submission.body, + }, + })), ); - const blocker = new DatabaseSync(harness.service.ledger.databasePath); - blocker.exec("PRAGMA busy_timeout = 5000; BEGIN IMMEDIATE;"); - let locked = true; - try { - const starting = workers.map(async (worker) => - supportingWorkerMessage(worker, "starting"), - ); - const results = workers.map(async (worker) => - supportingWorkerMessage(worker, "result"), - ); - for (const worker of workers) worker.postMessage("go"); - await Promise.all(starting); - await new Promise((resolvePromise) => setTimeout(resolvePromise, 100)); - blocker.exec("COMMIT"); - locked = false; - return await Promise.all(results); - } finally { - if (locked) blocker.exec("ROLLBACK"); - blocker.close(); - } } afterEach(() => { diff --git a/test/helpers/blocked-sqlite-workers.ts b/test/helpers/blocked-sqlite-workers.ts new file mode 100644 index 0000000..cf6ecc6 --- /dev/null +++ b/test/helpers/blocked-sqlite-workers.ts @@ -0,0 +1,97 @@ +import { DatabaseSync } from "node:sqlite"; +import { Worker } from "node:worker_threads"; + +export type BlockedWorkerResult = + | { kind: "result"; ok: true; artifact: unknown } + | { kind: "result"; ok: false; error: string }; + +function workerMessage(worker: Worker, kind: string): Promise { + return new Promise((resolvePromise, rejectPromise) => { + const onMessage = (message: { kind?: unknown }): void => { + if (message.kind !== kind) return; + cleanup(); + resolvePromise(message as T); + }; + const onError = (error: Error): void => { + cleanup(); + rejectPromise(error); + }; + const onExit = (code: number): void => { + cleanup(); + rejectPromise( + new Error( + `Supporting worker exited with code ${String(code)} before ${kind}`, + ), + ); + }; + const cleanup = (): void => { + worker.off("message", onMessage); + worker.off("error", onError); + worker.off("exit", onExit); + }; + worker.on("message", onMessage); + worker.on("error", onError); + worker.on("exit", onExit); + }); +} + +function createContentionBarrier(workerCount: number): SharedArrayBuffer { + const buffer = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT); + const counter = new Int32Array(buffer); + counter[0] = workerCount; + return buffer; +} + +async function waitForContentionBarrier( + buffer: SharedArrayBuffer, + timeoutMs = 5000, +): Promise { + const counter = new Int32Array(buffer); + const deadline = Date.now() + timeoutMs; + while (Date.now() < deadline) { + if (Atomics.load(counter, 0) <= 0) return; + Atomics.wait(counter, 0, Atomics.load(counter, 0), 25); + } + throw new Error( + `Timed out waiting for ${String(Atomics.load(counter, 0))} workers to reach ledger contention`, + ); +} + +export async function runBlockedWorkers>( + workerModuleUrl: URL, + databasePath: string, + workerData: readonly T[], + options?: { execArgv?: string[] }, +): Promise { + const contentionBarrier = createContentionBarrier(workerData.length); + const workers = workerData.map( + (data) => + new Worker(workerModuleUrl, { + workerData: { ...data, contentionBarrier }, + execArgv: options?.execArgv ?? ["--import", "tsx"], + }), + ); + await Promise.all( + workers.map(async (worker) => workerMessage(worker, "ready")), + ); + const blocker = new DatabaseSync(databasePath); + blocker.exec("PRAGMA busy_timeout = 5000; BEGIN IMMEDIATE;"); + let locked = true; + try { + const starting = workers.map(async (worker) => + workerMessage(worker, "starting"), + ); + const results = workers.map(async (worker) => + workerMessage(worker, "result"), + ); + for (const worker of workers) worker.postMessage("go"); + await Promise.all(starting); + await waitForContentionBarrier(contentionBarrier); + blocker.exec("COMMIT"); + locked = false; + return await Promise.all(results); + } finally { + if (locked) blocker.exec("ROLLBACK"); + blocker.close(); + } +} diff --git a/test/helpers/supporting-artifact-worker.ts b/test/helpers/supporting-artifact-worker.ts index a693a25..1f1257b 100644 --- a/test/helpers/supporting-artifact-worker.ts +++ b/test/helpers/supporting-artifact-worker.ts @@ -25,9 +25,20 @@ type ServiceWorkerData = { artifact: ArtifactSubmission; }; +type WorkerData = (LedgerWorkerData | ServiceWorkerData) & { + contentionBarrier?: SharedArrayBuffer; +}; + +function signalContentionReady(contentionBarrier: SharedArrayBuffer | undefined): void { + if (contentionBarrier === undefined) return; + const counter = new Int32Array(contentionBarrier); + const remaining = Atomics.sub(counter, 0, 1) - 1; + if (remaining === 0) Atomics.notify(counter, 0); +} + if (parentPort === null) throw new Error("Supporting worker requires a parent"); -const data = workerData as LedgerWorkerData | ServiceWorkerData; +const data = workerData as WorkerData; const target = data.kind === "ledger" ? new SqliteLedger(data.stateDirectory) @@ -40,6 +51,7 @@ parentPort.postMessage({ kind: "ready" }); parentPort.once("message", (message: unknown) => { if (message !== "go") return; parentPort.postMessage({ kind: "starting" }); + signalContentionReady(data.contentionBarrier); try { const artifact = data.kind === "ledger" From d1a4a0d2055012edc8a84ddcf3b3f4c49e5bde06 Mon Sep 17 00:00:00 2001 From: Dukeabadoon Date: Wed, 12 Aug 2026 14:44:33 +0800 Subject: [PATCH 2/4] style: format ledger concurrency files --- packages/core/src/ledger.test.ts | 32 ++++++++++++---------- packages/core/src/ledger.ts | 8 ++++-- test/helpers/supporting-artifact-worker.ts | 4 ++- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/packages/core/src/ledger.test.ts b/packages/core/src/ledger.test.ts index 8980bd4..403124e 100644 --- a/packages/core/src/ledger.test.ts +++ b/packages/core/src/ledger.test.ts @@ -309,20 +309,24 @@ describe("SQLite ledger and content-addressed artifacts", () => { eventType: "evidence_captured", decisionSummary: "Stored bounded evidence.", }; - const results = await runBlockedWorkers(supportingWorkerUrl, ledger.databasePath, [ - { - kind: "ledger", - stateDirectory: ledger.rootDirectory, - artifact: base, - event, - }, - { - kind: "ledger", - stateDirectory: ledger.rootDirectory, - artifact: { ...base, body: { content: "second bounded result" } }, - event, - }, - ]); + const results = await runBlockedWorkers( + supportingWorkerUrl, + ledger.databasePath, + [ + { + kind: "ledger", + stateDirectory: ledger.rootDirectory, + artifact: base, + event, + }, + { + kind: "ledger", + stateDirectory: ledger.rootDirectory, + artifact: { ...base, body: { content: "second bounded result" } }, + event, + }, + ], + ); expect(results.filter((result) => result.ok)).toHaveLength(1); expect( diff --git a/packages/core/src/ledger.ts b/packages/core/src/ledger.ts index 404c5c8..cddbbd6 100644 --- a/packages/core/src/ledger.ts +++ b/packages/core/src/ledger.ts @@ -479,8 +479,7 @@ export class SqliteLedger { private isUniqueConstraintError(error: unknown): boolean { return ( - error instanceof Error && - /UNIQUE constraint failed/i.test(error.message) + error instanceof Error && /UNIQUE constraint failed/i.test(error.message) ); } @@ -510,7 +509,10 @@ export class SqliteLedger { if (!this.isUniqueConstraintError(error)) throw error; const raced = this.getArtifact(artifact.runId, artifact.id); if (!raced) throw error; - const replay = this.reconcileExistingSupportingArtifact(raced, artifact); + const replay = this.reconcileExistingSupportingArtifact( + raced, + artifact, + ); this.database.exec("COMMIT"); return replay; } diff --git a/test/helpers/supporting-artifact-worker.ts b/test/helpers/supporting-artifact-worker.ts index 1f1257b..34ddd3b 100644 --- a/test/helpers/supporting-artifact-worker.ts +++ b/test/helpers/supporting-artifact-worker.ts @@ -29,7 +29,9 @@ type WorkerData = (LedgerWorkerData | ServiceWorkerData) & { contentionBarrier?: SharedArrayBuffer; }; -function signalContentionReady(contentionBarrier: SharedArrayBuffer | undefined): void { +function signalContentionReady( + contentionBarrier: SharedArrayBuffer | undefined, +): void { if (contentionBarrier === undefined) return; const counter = new Int32Array(contentionBarrier); const remaining = Atomics.sub(counter, 0, 1) - 1; From d41542d313fc468f297c94b1706e2873dc1036f1 Mon Sep 17 00:00:00 2001 From: Dukeabadoon Date: Wed, 12 Aug 2026 15:06:31 +0800 Subject: [PATCH 3/4] fix(core): move ledger test helpers under packages/core Relocate blocked-sqlite-workers into packages/core/src/testing so tsc -b includes them. Exclude the worker entry from compilation. --- packages/core/src/ledger.test.ts | 4 +- .../src/testing}/blocked-sqlite-workers.ts | 0 .../testing}/supporting-artifact-worker.ts | 6 +- packages/core/tsconfig.json | 3 +- packages/mcp/src/pipeline.e2e.test.ts | 4 +- packages/mcp/src/service.d.ts | 159 +++++ packages/mcp/src/service.d.ts.map | 1 + packages/mcp/src/service.js | 636 ++++++++++++++++++ packages/mcp/src/service.js.map | 1 + 9 files changed, 806 insertions(+), 8 deletions(-) rename {test/helpers => packages/core/src/testing}/blocked-sqlite-workers.ts (100%) rename {test/helpers => packages/core/src/testing}/supporting-artifact-worker.ts (92%) create mode 100644 packages/mcp/src/service.d.ts create mode 100644 packages/mcp/src/service.d.ts.map create mode 100644 packages/mcp/src/service.js create mode 100644 packages/mcp/src/service.js.map diff --git a/packages/core/src/ledger.test.ts b/packages/core/src/ledger.test.ts index 403124e..e4e6ce4 100644 --- a/packages/core/src/ledger.test.ts +++ b/packages/core/src/ledger.test.ts @@ -13,14 +13,14 @@ import { DatabaseSync } from "node:sqlite"; import { afterEach, describe, expect, it } from "vitest"; -import { runBlockedWorkers } from "../../../test/helpers/blocked-sqlite-workers.js"; +import { runBlockedWorkers } from "./testing/blocked-sqlite-workers.js"; import { SqliteLedger } from "./ledger.js"; import type { ArtifactSubmission, RunRecord } from "./types.js"; const ledgers: SqliteLedger[] = []; const supportingWorkerUrl = new URL( - "../../../test/helpers/supporting-artifact-worker.ts", + "./testing/supporting-artifact-worker.ts", import.meta.url, ); diff --git a/test/helpers/blocked-sqlite-workers.ts b/packages/core/src/testing/blocked-sqlite-workers.ts similarity index 100% rename from test/helpers/blocked-sqlite-workers.ts rename to packages/core/src/testing/blocked-sqlite-workers.ts diff --git a/test/helpers/supporting-artifact-worker.ts b/packages/core/src/testing/supporting-artifact-worker.ts similarity index 92% rename from test/helpers/supporting-artifact-worker.ts rename to packages/core/src/testing/supporting-artifact-worker.ts index 34ddd3b..6f2cba2 100644 --- a/test/helpers/supporting-artifact-worker.ts +++ b/packages/core/src/testing/supporting-artifact-worker.ts @@ -4,9 +4,9 @@ import { SqliteLedger, type SubmissionEvent, type SupportingArtifactQuota, -} from "../../packages/core/src/ledger.ts"; -import type { ArtifactSubmission } from "../../packages/core/src/types.ts"; -import { TelicService } from "../../packages/mcp/src/service.ts"; +} from "../ledger.js"; +import type { ArtifactSubmission } from "../types.js"; +import { TelicService } from "../../../mcp/src/service.js"; type LedgerWorkerData = { kind: "ledger"; diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 70d64c9..4bd9607 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -6,5 +6,6 @@ "outDir": "dist", "tsBuildInfoFile": "dist/.tsbuildinfo" }, - "include": ["src/**/*.ts"] + "include": ["src/**/*.ts"], + "exclude": ["src/testing/supporting-artifact-worker.ts"] } diff --git a/packages/mcp/src/pipeline.e2e.test.ts b/packages/mcp/src/pipeline.e2e.test.ts index 6b0b158..501b238 100644 --- a/packages/mcp/src/pipeline.e2e.test.ts +++ b/packages/mcp/src/pipeline.e2e.test.ts @@ -11,12 +11,12 @@ import { import { runBlockedWorkers, type BlockedWorkerResult, -} from "../../../test/helpers/blocked-sqlite-workers.js"; +} from "../../core/src/testing/blocked-sqlite-workers.js"; import { TelicService } from "./service.js"; const services: TelicService[] = []; const supportingWorkerUrl = new URL( - "../../../test/helpers/supporting-artifact-worker.ts", + "../../core/src/testing/supporting-artifact-worker.ts", import.meta.url, ); diff --git a/packages/mcp/src/service.d.ts b/packages/mcp/src/service.d.ts new file mode 100644 index 0000000..3099b31 --- /dev/null +++ b/packages/mcp/src/service.d.ts @@ -0,0 +1,159 @@ +import { type GroundingBudgetInput } from "@telic/context"; +import { type NextAction, RunController, SqliteLedger, type ArtifactSubmission, type BrokerDecision, type IntentMode, type ReplayReport, type RunRecord } from "@telic/core"; +export interface ServiceOptions { + repositoryRoot: string; + stateDirectory?: string; +} +export declare function defaultStateDirectory(repositoryRoot: string): string; +export interface StartRunRequest { + originalRequest: string; + mode: IntentMode; + hostName?: string; + nativeSubagents?: "available" | "unavailable" | "unknown"; + hostCapabilities?: string[]; + authorizationGranted?: string[]; + authorizationDenied?: string[]; + shellExecuteAllowlist?: string[]; + networkReadDomains?: string[]; + topologyOverride?: import("@telic/core").RunTopology | null; + priorRunId?: string | null; +} +export interface GroundContextRequest { + runId: string; + activePaths?: string[]; + budget?: GroundingBudgetInput; +} +export type RunSummary = Pick; +export declare class TelicService { + readonly repositoryRoot: string; + readonly stateDirectory: string; + readonly ledger: SqliteLedger; + readonly controller: RunController; + constructor(options: ServiceOptions); + close(): void; + assertActionToken(runId: string, actionId: string, expectedRunVersion: number): void; + startRun(input: StartRunRequest): { + run: RunRecord; + nextAction: NextAction; + }; + private publishActiveSession; + groundContext(input: GroundContextRequest): Promise<{ + run: RunRecord; + nextAction: NextAction; + manifest: { + schemaVersion: "1.0"; + id: string; + runId: string; + repositoryFingerprint: { + headCommit: string | null; + dirtyWorktreeHash: string; + }; + pinnedRefs: string[]; + candidates: ({ + id: string; + ref: string; + locations: string[]; + contentHash: string; + byteSize: number; + decision: "selected"; + selectionReason: string; + path: string; + score: number; + pinned: boolean; + } | { + id: string; + ref: string; + locations: string[]; + contentHash: string | null; + byteSize: number | null; + decision: "excluded"; + exclusionReason: string; + })[]; + derivedRefs: string[]; + excludedCandidateSummaries: { + reason: "binary_file" | "duplicate_content" | "excluded_directory" | "file_count_budget" | "file_too_large" | "invalid_path" | "invalid_utf8" | "inventory_budget" | "low_relevance" | "non_regular_file" | "path_escape" | "secret_content" | "secret_like_file" | "symlink_escape" | "total_bytes_budget" | "unreadable_file"; + count: number; + }[]; + inventorySource: "filesystem" | "git" | "ripgrep"; + warnings: string[]; + budget: { + maximumFiles: number; + maximumFileBytes: number; + maximumTotalBytes: number; + maximumInventoryFiles: number; + candidateFiles: number; + selectedFiles: number; + estimatedTokens: number; + selectedBytes: number; + }; + }; + }>; + submitArtifact(input: ArtifactSubmission): { + run: RunRecord; + nextAction: NextAction; + } | { + run: RunRecord; + artifact: import("@telic/core").StoredArtifact; + nextAction: NextAction; + }; + answerClarification(runId: string, response: string): { + run: RunRecord; + nextAction: NextAction; + }; + cancelRun(runId: string, actionId: string, expectedRunVersion: number): { + run: RunRecord; + nextAction: NextAction; + }; + listRuns(limit?: number): RunSummary[]; + getRun(runId: string): { + run: RunRecord; + artifacts: import("@telic/core").StoredArtifact[]; + nextAction: NextAction; + }; + getArtifact(runId: string, artifactId: string): import("@telic/core").HydratedArtifact; + checkToolAction(input: { + runId: string; + actionId: string; + expectedRunVersion: number; + capability: string; + target?: string; + }): BrokerDecision; + replayRun(runId: string): ReplayReport; + getTrace(runId: string, afterSequence?: number, limit?: number): { + schemaVersion: "1.0"; + id: string; + runId: string; + sequence: number; + timestamp: string; + actor: "controller" | "executor" | "host" | "quality_controller" | "release_auditor" | "scenario_author" | "task_compiler" | "tool" | "user"; + phase: "agent_1_frame" | "agent_1_review" | "agent_2_compile" | "agent_2_revision" | "agent_3_evidence_reverify" | "agent_3_plan" | "agent_3_quality_review" | "agent_4_execute" | "agent_4_remediation" | "agent_5_release_audit" | "awaiting_clarification" | "blocked" | "cancelled" | "completed" | "context_discovery" | "contract_validation" | "diagnosis_review" | "partial" | "plan_validation" | "received" | "remediation_plan" | "user_report"; + eventType: "artifact_recorded" | "broker_decision" | "budget_consumed" | "clarification_requested" | "context_selected" | "digest_verified" | "lineage_linked" | "permission_checked" | "phase_started" | "phase_submitted" | "redaction_applied" | "run_started" | "run_terminated" | "tool_finished" | "tool_started" | "topology_classified" | "topology_escalated" | "transition_allowed" | "transition_denied"; + inputRefs: string[]; + outputRefs: string[]; + tool: { + name: string; + argumentsRef: string | null; + resultRef: string | null; + exitStatus: number | null; + } | null; + permissionDecision: { + decision: "allow" | "deny"; + capability: string; + scope: string; + policyRefs: string[]; + rationaleSummary: string; + } | null; + budgetSnapshot: { + promptRevisions: number; + postExecutionRemediations: number; + transportRetries: number; + }; + rationaleSummary: string; + redactions: { + id: string; + targetRef: string; + category: "credential" | "personal_data" | "secret" | "sensitive_output"; + }[]; + }[]; +} +//# sourceMappingURL=service.d.ts.map \ No newline at end of file diff --git a/packages/mcp/src/service.d.ts.map b/packages/mcp/src/service.d.ts.map new file mode 100644 index 0000000..35d1449 --- /dev/null +++ b/packages/mcp/src/service.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["service.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,KAAK,UAAU,EACf,aAAa,EACb,YAAY,EAIZ,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AAWrB,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAUpE;AAED,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,SAAS,CAAC;IAC1D,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,gBAAgB,CAAC,EAAE,OAAO,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,CAAC,EAAE,oBAAoB,CAAC;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AAE,MAAM,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,cAAc,CA8CjB;IAED,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAGrC;IAED,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,SAAI,EAAE,KAAK,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA6BxD;CACF"} \ No newline at end of file diff --git a/packages/mcp/src/service.js b/packages/mcp/src/service.js new file mode 100644 index 0000000..cc2adc8 --- /dev/null +++ b/packages/mcp/src/service.js @@ -0,0 +1,636 @@ +import { createHash } from "node:crypto"; +import { existsSync, realpathSync } from "node:fs"; +import { homedir } from "node:os"; +import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path"; +import { containsLikelySecret, groundRepository, isInstructionPath, } from "@telic/context"; +import { clearActiveSession, writeActiveSession, RunController, SqliteLedger, evaluateBrokerAction, inspectRunReplay, permissionsFromEnvelope, } from "@telic/core"; +import { isArtifactType, getArtifactJsonSchema, normalizeContextManifestWire, parseArtifactBody, parseContextManifest, } from "@telic/protocol"; +export function defaultStateDirectory(repositoryRoot) { + const canonicalRoot = realpathSync(resolve(repositoryRoot)); + const repositoryKey = createHash("sha256") + .update(canonicalRoot) + .digest("hex") + .slice(0, 24); + const stateHome = process.env.XDG_STATE_HOME + ? resolve(process.env.XDG_STATE_HOME) + : join(homedir(), ".local", "state"); + return join(stateHome, "telic", "repositories", repositoryKey); +} +function protocolValidator(type, body) { + if (!isArtifactType(type)) + throw new Error(`Unsupported artifact type: ${type}`); + return parseArtifactBody(type, body); +} +function defaultCapabilities(mode) { + switch (mode) { + case "report_only": + return []; + case "plan_only": + return ["repository.read"]; + case "analyze_only": + return [ + "repository.read", + "shell.inspect", + "runtime.inspect", + "browser.inspect", + ]; + case "fix_only": + case "analyze_and_fix": + return [ + "repository.read", + "repository.write", + "shell.inspect", + "runtime.inspect", + ]; + } +} +function intersectCapabilities(granted, available) { + const availableSet = new Set(available); + return [...new Set(granted)] + .filter((capability) => availableSet.has(capability)) + .sort(); +} +const MAX_TRACE_INPUT_REFS = 256; +const MAX_DECODED_EVIDENCE_BYTES = 2 * 1024 * 1024; +const MAX_EVIDENCE_PER_WORK_PLAN = 128; +const MAX_SCENARIO_SPECS_PER_FRAME = 1; +const REFERENCE_URI_PATTERN = /^(?:artifact|repo|trace):\/\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]+$/u; +const CANONICAL_BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u; +function isPathContained(root, target) { + const fromRoot = relative(root, target); + return (fromRoot === "" || + (fromRoot !== ".." && + !fromRoot.startsWith(`..${sep}`) && + !isAbsolute(fromRoot))); +} +function canonicalProspectivePath(path) { + let existingAncestor = resolve(path); + const missingSegments = []; + while (!existsSync(existingAncestor)) { + const parent = dirname(existingAncestor); + if (parent === existingAncestor) + return resolve(path); + missingSegments.unshift(basename(existingAncestor)); + existingAncestor = parent; + } + return resolve(realpathSync(existingAncestor), ...missingSegments); +} +function assertStateOutsideRepository(repositoryRoot, stateDirectory) { + const lexicalState = resolve(stateDirectory); + const canonicalState = canonicalProspectivePath(lexicalState); + if (isPathContained(repositoryRoot, lexicalState) || + isPathContained(lexicalState, repositoryRoot) || + isPathContained(repositoryRoot, canonicalState) || + isPathContained(canonicalState, repositoryRoot)) { + throw new Error("Telic state directory must be outside the repository being grounded and must not contain it"); + } +} +function containsLikelySecretInValue(value, seen = new WeakSet()) { + if (typeof value === "string") + return containsLikelySecret(value); + if (typeof value !== "object" || value === null) + return false; + if (seen.has(value)) + return false; + seen.add(value); + const values = Array.isArray(value) ? value : Object.values(value); + const containsSecret = values.some((child) => containsLikelySecretInValue(child, seen)); + seen.delete(value); + return containsSecret; +} +function evidenceContentForSecretScan(encoding, content) { + if (encoding === "utf8") + return content; + if (!CANONICAL_BASE64_PATTERN.test(content)) { + throw new Error("Evidence content is not canonical base64"); + } + const decoded = Buffer.from(content, "base64"); + if (decoded.byteLength > MAX_DECODED_EVIDENCE_BYTES) { + throw new Error(`Decoded evidence exceeds ${String(MAX_DECODED_EVIDENCE_BYTES)} bytes`); + } + if (decoded.toString("base64") !== content) { + throw new Error("Evidence content is not canonical base64"); + } + return decoded.toString("utf8"); +} +function collectBodyReferenceUris(value, references, key = "", depth = 0, seen = new WeakSet()) { + if (depth > 64) + return; + if (typeof value === "string") { + if ((key === "ref" || + key === "evidenceInspected" || + key.endsWith("Ref") || + key.endsWith("Refs")) && + REFERENCE_URI_PATTERN.test(value)) { + references.add(value); + } + return; + } + if (typeof value !== "object" || value === null) + return; + if (seen.has(value)) + return; + seen.add(value); + if (Array.isArray(value)) { + for (const item of value) { + collectBodyReferenceUris(item, references, key, depth + 1, seen); + } + } + else { + for (const [childKey, child] of Object.entries(value)) { + collectBodyReferenceUris(child, references, childKey, depth + 1, seen); + } + } + seen.delete(value); +} +function traceInputRefs(ledger, runId, body, supplied = []) { + if (new Set(supplied).size !== supplied.length) { + throw new Error("Artifact sourceRefs must be unique"); + } + const result = new Set(supplied); + if (result.size > MAX_TRACE_INPUT_REFS) { + throw new Error(`Artifact sourceRefs exceed the ${String(MAX_TRACE_INPUT_REFS)} item limit`); + } + const bodyReferences = new Set(); + collectBodyReferenceUris(body, bodyReferences); + const existingArtifacts = new Set(ledger + .listArtifacts(runId) + .map((artifact) => `artifact://${runId}/${artifact.id}`)); + for (const reference of bodyReferences) { + if (reference.startsWith("artifact://system/")) + continue; + if (reference.startsWith("artifact://") && + !existingArtifacts.has(reference)) { + continue; + } + result.add(reference); + if (result.size > MAX_TRACE_INPUT_REFS) { + throw new Error(`Artifact sourceRefs exceed the ${String(MAX_TRACE_INPUT_REFS)} item limit`); + } + } + return [...result]; +} +function internalDocumentId(contextId, hash, index) { + return `${contextId}-source-${String(index + 1).padStart(3, "0")}-${hash.slice("sha256:".length, 20)}`; +} +function emptyReportOnlyManifest(run) { + const digest = createHash("sha256").update("").digest("hex"); + return parseContextManifest({ + schemaVersion: "1.0", + id: `context-report-only-${run.runId.slice(0, 12)}`, + runId: run.runId, + repositoryFingerprint: { + headCommit: null, + dirtyWorktreeHash: `sha256:${digest}`, + }, + pinnedRefs: [], + candidates: [], + derivedRefs: [], + excludedCandidateSummaries: [], + inventorySource: "filesystem", + warnings: [ + "report_only mode intentionally skipped new repository discovery.", + ], + budget: { + maximumFiles: 1, + maximumFileBytes: 1, + maximumTotalBytes: 1, + maximumInventoryFiles: 1, + candidateFiles: 0, + selectedFiles: 0, + selectedBytes: 0, + estimatedTokens: 0, + }, + }); +} +const tracePhase = { + context_grounding: "context_discovery", + agent_1_frame: "agent_1_frame", + agent_2_compile: "agent_2_compile", + agent_1_review: "agent_1_review", + agent_2_revise: "agent_2_revision", + agent_3_plan: "agent_3_plan", + agent_4_execute: "agent_4_execute", + agent_3_review: "agent_3_quality_review", + agent_3_evidence_reverify: "agent_3_evidence_reverify", + agent_5_audit: "agent_5_release_audit", + agent_5_report: "user_report", +}; +const canonicalTraceEventType = { + run_started: "run_started", + context_source_stored: "artifact_recorded", + evidence_captured: "artifact_recorded", + scenario_presentation_stored: "artifact_recorded", + phase_submitted: "phase_submitted", + clarification_requested: "clarification_requested", + permission_checked: "permission_checked", + broker_decision: "broker_decision", + clarification_answered: "transition_allowed", + run_cancelled: "run_terminated", + topology_classified: "topology_classified", + digest_verified: "digest_verified", + lineage_linked: "lineage_linked", + topology_escalated: "topology_escalated", +}; +const traceActors = new Set([ + "controller", + "scenario_author", + "task_compiler", + "quality_controller", + "executor", + "release_auditor", + "host", + "tool", + "user", +]); +export class TelicService { + repositoryRoot; + stateDirectory; + ledger; + controller; + constructor(options) { + this.repositoryRoot = realpathSync(resolve(options.repositoryRoot)); + const stateDirectory = resolve(options.stateDirectory ?? defaultStateDirectory(this.repositoryRoot)); + assertStateOutsideRepository(this.repositoryRoot, stateDirectory); + this.stateDirectory = stateDirectory; + this.ledger = new SqliteLedger(this.stateDirectory); + this.controller = new RunController(this.ledger, protocolValidator, (type) => { + if (!isArtifactType(type)) { + throw new Error(`Unsupported artifact type: ${type}`); + } + return getArtifactJsonSchema(type); + }); + } + close() { + this.ledger.close(); + } + assertActionToken(runId, actionId, expectedRunVersion) { + const run = this.ledger.requireRun(runId); + if (run.version !== expectedRunVersion) { + throw new Error(`Stale run version ${String(expectedRunVersion)}; current version is ${String(run.version)}`); + } + const action = this.controller.getNextAction(runId); + if (action.id !== actionId) { + throw new Error("Stale or foreign action_id; reload the next action"); + } + } + startRun(input) { + const hostCapabilities = [ + ...new Set(input.hostCapabilities ?? ["repository.read"]), + ].sort(); + const desired = input.authorizationGranted ?? defaultCapabilities(input.mode); + const granted = intersectCapabilities(desired, hostCapabilities); + const denied = [...new Set(input.authorizationDenied ?? [])].sort(); + const started = this.controller.startRun({ + repositoryRoot: this.repositoryRoot, + originalRequest: input.originalRequest, + requestedMode: input.mode, + ...(input.topologyOverride !== undefined + ? { topologyOverride: input.topologyOverride } + : {}), + ...(input.priorRunId !== undefined + ? { priorRunId: input.priorRunId } + : {}), + host: { + name: input.hostName ?? "mcp-host", + nativeSubagents: input.nativeSubagents ?? "unknown", + capabilities: hostCapabilities, + }, + authorization: { + granted, + denied, + ...(input.shellExecuteAllowlist + ? { shellExecuteAllowlist: input.shellExecuteAllowlist } + : {}), + ...(input.networkReadDomains + ? { networkReadDomains: input.networkReadDomains } + : {}), + }, + }); + this.publishActiveSession(started.run, started.nextAction); + return started; + } + publishActiveSession(run, nextAction) { + if (run.status !== "running") { + clearActiveSession(this.stateDirectory); + return; + } + writeActiveSession(this.stateDirectory, { + schemaVersion: "1.0", + runId: run.runId, + actionId: nextAction.id, + runVersion: run.version, + repositoryRoot: run.repositoryRoot, + requestedMode: run.requestedMode, + updatedAt: new Date().toISOString(), + }); + } + async groundContext(input) { + const run = this.ledger.requireRun(input.runId); + if (run.phase !== "context_grounding" || run.status !== "running") { + throw new Error(`Run ${run.runId} is not awaiting context grounding`); + } + let manifest; + let sourceRefs = []; + if (run.requestedMode === "report_only") { + manifest = emptyReportOnlyManifest(run); + } + else { + const requestRecord = this.ledger + .listArtifacts(run.runId) + .find((artifact) => artifact.type === "UserMessage"); + if (!requestRecord) + throw new Error("Run is missing its immutable original request"); + const requestArtifact = this.ledger.getArtifact(run.runId, requestRecord.id); + const requestBody = requestArtifact?.body; + if (typeof requestBody !== "object" || + requestBody === null || + !("content" in requestBody) || + typeof requestBody.content !== "string") { + throw new Error("Original request artifact is invalid"); + } + const grounded = await groundRepository({ + run_id: run.runId, + repository_root: run.repositoryRoot, + request: requestBody.content, + excluded_roots: [this.stateDirectory], + ...(input.activePaths ? { active_paths: input.activePaths } : {}), + ...(input.budget ? { budget: input.budget } : {}), + }); + for (const [index, document] of grounded.documents.entries()) { + const id = internalDocumentId(grounded.manifest.id, document.content_hash, index); + const uri = `artifact://${run.runId}/${id}`; + sourceRefs.push(uri); + this.ledger.appendSupportingArtifact({ + id, + runId: run.runId, + type: "ContextDocument", + schemaVersion: "1.0", + producer: "controller", + sourceRefs: [document.ref], + body: { + schemaVersion: "1.0", + id, + runId: run.runId, + repositoryRef: document.ref, + contentHash: document.content_hash, + sizeBytes: document.size_bytes, + trustKind: isInstructionPath(document.path) + ? "applicable_instruction" + : "untrusted_repository_content", + instructionScope: isInstructionPath(document.path) + ? document.path.includes("/") + ? document.path.slice(0, document.path.lastIndexOf("/")) + : "." + : null, + content: document.content, + }, + }, { + actor: "controller", + eventType: "context_source_stored", + inputRefs: [document.ref], + decisionSummary: `Stored selected source ${document.ref} once in the content-addressed artifact store.`, + }); + } + manifest = normalizeContextManifestWire({ + ...grounded.manifest, + derived_refs: sourceRefs, + }); + } + const groundingAction = this.controller.getNextAction(run.runId); + if (groundingAction.kind === "phase") { + sourceRefs = [ + ...new Set([...groundingAction.inputRefs, ...sourceRefs]), + ].slice(0, MAX_TRACE_INPUT_REFS); + } + const result = this.controller.submitArtifact({ + id: manifest.id, + runId: run.runId, + type: "ContextManifest", + schemaVersion: "1.0", + producer: "controller", + sourceRefs, + body: manifest, + }); + this.publishActiveSession(result.run, result.nextAction); + return { ...result, manifest }; + } + submitArtifact(input) { + if (input.type === "RunEnvelope" || + input.type === "ContextManifest" || + input.type === "NextAction" || + input.type === "TraceEvent") { + throw new Error(`${input.type} is controller-owned and cannot be submitted by a host role`); + } + if (input.type === "Evidence") { + const run = this.ledger.requireRun(input.runId); + if (run.status !== "running" || run.phase !== "agent_4_execute") { + throw new Error("Evidence may be captured only during the bounded executor phase"); + } + const body = parseArtifactBody("Evidence", input.body); + if (input.producer !== "executor" || + input.id !== body.id || + input.runId !== body.runId || + input.schemaVersion !== body.schemaVersion) { + throw new Error("Evidence metadata or producer does not match its body"); + } + const sourceRefs = traceInputRefs(this.ledger, input.runId, body, input.sourceRefs); + const decodedContent = evidenceContentForSecretScan(body.encoding, body.content); + if (containsLikelySecretInValue(body) || + containsLikelySecret(decodedContent) || + containsLikelySecretInValue(sourceRefs)) { + throw new Error("Evidence contains a likely credential; redact the value before submission"); + } + this.controller.assertArtifactReferences({ ...input, body, sourceRefs }); + for (const sourceRef of body.sourceRefs) { + if (!sourceRef.startsWith("artifact://")) + continue; + const match = /^artifact:\/\/([^/]+)\/([^/]+)$/.exec(sourceRef); + if (!match || + match[1] !== input.runId || + !this.ledger.getArtifact(input.runId, match[2])) { + throw new Error(`Evidence source reference is missing or belongs to another run: ${sourceRef}`); + } + } + const stored = this.ledger.appendSupportingArtifact({ ...input, body, sourceRefs }, { + actor: "executor", + eventType: "evidence_captured", + inputRefs: sourceRefs, + decisionSummary: `Captured a redacted ${body.kind} evidence artifact.`, + }, { + scope: "after_latest", + anchorType: "WorkPlan", + maximum: MAX_EVIDENCE_PER_WORK_PLAN, + errorMessage: `Evidence quota of ${String(MAX_EVIDENCE_PER_WORK_PLAN)} per WorkPlan reached`, + }); + return { + run, + artifact: stored, + nextAction: this.controller.getNextAction(input.runId), + }; + } + if (input.type === "ScenarioSpec") { + const run = this.ledger.requireRun(input.runId); + if (run.status !== "running" || run.phase !== "agent_2_compile") { + throw new Error("Optional ScenarioSpec must immediately follow its accepted ProblemFrame"); + } + const body = parseArtifactBody("ScenarioSpec", input.body); + if (input.producer !== "scenario_author" || + input.id !== body.id || + input.runId !== body.runId || + input.schemaVersion !== body.schemaVersion) { + throw new Error("ScenarioSpec metadata or producer does not match its body"); + } + const sourceRefs = traceInputRefs(this.ledger, input.runId, body, input.sourceRefs); + this.controller.assertArtifactReferences({ ...input, body, sourceRefs }); + const match = /^artifact:\/\/([^/]+)\/([^/]+)$/.exec(body.problemFrameRef); + if (!match || + match[1] !== input.runId || + !this.ledger.getArtifact(input.runId, match[2])) { + throw new Error("ScenarioSpec must reference an existing ProblemFrame in the same run"); + } + const stored = this.ledger.appendSupportingArtifact({ ...input, body, sourceRefs }, { + actor: input.producer, + eventType: "scenario_presentation_stored", + inputRefs: sourceRefs, + decisionSummary: "Stored an optional sourced scenario presentation; the ProblemFrame remains authoritative.", + }, { + scope: "matching_body_field", + field: "problemFrameRef", + value: body.problemFrameRef, + maximum: MAX_SCENARIO_SPECS_PER_FRAME, + errorMessage: "Only one ScenarioSpec may be stored for the current ProblemFrame", + }); + return { + run, + artifact: stored, + nextAction: this.controller.getNextAction(input.runId), + }; + } + if (!isArtifactType(input.type)) { + throw new Error(`Unsupported artifact type: ${input.type}`); + } + const body = parseArtifactBody(input.type, input.body); + const submitted = this.controller.submitArtifact({ + ...input, + body, + sourceRefs: traceInputRefs(this.ledger, input.runId, body, input.sourceRefs), + }); + this.publishActiveSession(submitted.run, submitted.nextAction); + return submitted; + } + answerClarification(runId, response) { + const answered = this.controller.answerClarification(runId, response); + this.publishActiveSession(answered.run, answered.nextAction); + return answered; + } + cancelRun(runId, actionId, expectedRunVersion) { + this.assertActionToken(runId, actionId, expectedRunVersion); + const run = this.controller.cancelRun(runId); + const nextAction = this.controller.getNextAction(runId); + this.publishActiveSession(run, nextAction); + return { run, nextAction }; + } + listRuns(limit = 20) { + if (!Number.isInteger(limit) || limit < 1 || limit > 100) { + throw new Error("Run list limit must be an integer from 1 to 100"); + } + return this.ledger + .listRuns(limit) + .map(({ runId, schemaVersion, requestedMode, topology, status, phase, resumePhase, version, outcomeHint, createdAt, updatedAt, }) => ({ + runId, + schemaVersion, + requestedMode, + topology, + status, + phase, + resumePhase, + version, + outcomeHint, + createdAt, + updatedAt, + })); + } + getRun(runId) { + const run = this.ledger.requireRun(runId); + return { + run, + artifacts: this.ledger.listArtifacts(runId), + nextAction: this.controller.getNextAction(runId), + }; + } + getArtifact(runId, artifactId) { + const artifact = this.ledger.getArtifact(runId, artifactId); + if (!artifact) + throw new Error(`Artifact not found: ${artifactId}`); + return artifact; + } + checkToolAction(input) { + this.assertActionToken(input.runId, input.actionId, input.expectedRunVersion); + const run = this.ledger.requireRun(input.runId); + const envelopeRecord = this.ledger.findLatestArtifact(input.runId, "RunEnvelope"); + const envelopeBody = envelopeRecord + ? this.ledger.getArtifact(input.runId, envelopeRecord.id)?.body + : null; + const envelopeRef = envelopeRecord + ? "artifact://" + input.runId + "/" + envelopeRecord.id + : null; + const decision = evaluateBrokerAction({ + repositoryRoot: run.repositoryRoot, + mode: run.requestedMode, + permissions: permissionsFromEnvelope(run.requestedMode, envelopeBody), + ...(envelopeRef ? { policyRefs: [envelopeRef] } : {}), + }, { + capability: input.capability, + ...(input.target !== undefined ? { target: input.target } : {}), + runId: input.runId, + actionId: input.actionId, + }); + this.ledger.appendTraceEvent(input.runId, { + actor: "host", + eventType: "broker_decision", + phase: run.phase, + inputRefs: envelopeRef ? [envelopeRef] : [], + permissionDecision: decision.permissionDecision, + decisionSummary: decision.allowed + ? "Broker allowed " + input.capability + "." + : "Broker denied " + + input.capability + + ": " + + decision.reasonCode + + ".", + }); + return decision; + } + replayRun(runId) { + const run = this.ledger.requireRun(runId); + return inspectRunReplay(this.ledger, run); + } + getTrace(runId, afterSequence = 0, limit = 10_000) { + this.ledger.requireRun(runId); + return this.ledger.listTrace(runId, afterSequence, limit).map((event) => parseArtifactBody("TraceEvent", { + schemaVersion: "1.0", + id: event.id, + runId: event.runId, + sequence: event.sequence, + timestamp: event.timestamp, + actor: traceActors.has(event.actor) + ? event.actor + : "host", + phase: tracePhase[event.phase], + eventType: canonicalTraceEventType[event.eventType] ?? "artifact_recorded", + inputRefs: event.inputRefs, + outputRefs: event.outputRefs, + tool: null, + permissionDecision: event.permissionDecision, + budgetSnapshot: { + promptRevisions: event.budgetSnapshot.promptRevisionsRemaining, + postExecutionRemediations: event.budgetSnapshot.postExecutionRemediationsRemaining, + transportRetries: 0, + }, + rationaleSummary: event.decisionSummary, + redactions: [], + })); + } +} +//# sourceMappingURL=service.js.map \ No newline at end of file diff --git a/packages/mcp/src/service.js.map b/packages/mcp/src/service.js.map new file mode 100644 index 0000000..af58089 --- /dev/null +++ b/packages/mcp/src/service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"service.js","sourceRoot":"","sources":["service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EACL,QAAQ,EACR,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,GAElB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAElB,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,GAMxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,oBAAoB,GAGrB,MAAM,iBAAiB,CAAC;AAOzB,MAAM,UA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,CAAC,CACH,CAAC;IACJ,CAAC;CACF"} \ No newline at end of file From 43d833a15bec9a80548564b8a47a95a93cad91d8 Mon Sep 17 00:00:00 2001 From: Dukeabadoon Date: Wed, 12 Aug 2026 15:07:25 +0800 Subject: [PATCH 4/4] chore: drop accidental mcp build artifacts --- packages/mcp/src/service.d.ts | 159 -------- packages/mcp/src/service.d.ts.map | 1 - packages/mcp/src/service.js | 636 ------------------------------ packages/mcp/src/service.js.map | 1 - 4 files changed, 797 deletions(-) delete mode 100644 packages/mcp/src/service.d.ts delete mode 100644 packages/mcp/src/service.d.ts.map delete mode 100644 packages/mcp/src/service.js delete mode 100644 packages/mcp/src/service.js.map diff --git a/packages/mcp/src/service.d.ts b/packages/mcp/src/service.d.ts deleted file mode 100644 index 3099b31..0000000 --- a/packages/mcp/src/service.d.ts +++ /dev/null @@ -1,159 +0,0 @@ -import { type GroundingBudgetInput } from "@telic/context"; -import { type NextAction, RunController, SqliteLedger, type ArtifactSubmission, type BrokerDecision, type IntentMode, type ReplayReport, type RunRecord } from "@telic/core"; -export interface ServiceOptions { - repositoryRoot: string; - stateDirectory?: string; -} -export declare function defaultStateDirectory(repositoryRoot: string): string; -export interface StartRunRequest { - originalRequest: string; - mode: IntentMode; - hostName?: string; - nativeSubagents?: "available" | "unavailable" | "unknown"; - hostCapabilities?: string[]; - authorizationGranted?: string[]; - authorizationDenied?: string[]; - shellExecuteAllowlist?: string[]; - networkReadDomains?: string[]; - topologyOverride?: import("@telic/core").RunTopology | null; - priorRunId?: string | null; -} -export interface GroundContextRequest { - runId: string; - activePaths?: string[]; - budget?: GroundingBudgetInput; -} -export type RunSummary = Pick; -export declare class TelicService { - readonly repositoryRoot: string; - readonly stateDirectory: string; - readonly ledger: SqliteLedger; - readonly controller: RunController; - constructor(options: ServiceOptions); - close(): void; - assertActionToken(runId: string, actionId: string, expectedRunVersion: number): void; - startRun(input: StartRunRequest): { - run: RunRecord; - nextAction: NextAction; - }; - private publishActiveSession; - groundContext(input: GroundContextRequest): Promise<{ - run: RunRecord; - nextAction: NextAction; - manifest: { - schemaVersion: "1.0"; - id: string; - runId: string; - repositoryFingerprint: { - headCommit: string | null; - dirtyWorktreeHash: string; - }; - pinnedRefs: string[]; - candidates: ({ - id: string; - ref: string; - locations: string[]; - contentHash: string; - byteSize: number; - decision: "selected"; - selectionReason: string; - path: string; - score: number; - pinned: boolean; - } | { - id: string; - ref: string; - locations: string[]; - contentHash: string | null; - byteSize: number | null; - decision: "excluded"; - exclusionReason: string; - })[]; - derivedRefs: string[]; - excludedCandidateSummaries: { - reason: "binary_file" | "duplicate_content" | "excluded_directory" | "file_count_budget" | "file_too_large" | "invalid_path" | "invalid_utf8" | "inventory_budget" | "low_relevance" | "non_regular_file" | "path_escape" | "secret_content" | "secret_like_file" | "symlink_escape" | "total_bytes_budget" | "unreadable_file"; - count: number; - }[]; - inventorySource: "filesystem" | "git" | "ripgrep"; - warnings: string[]; - budget: { - maximumFiles: number; - maximumFileBytes: number; - maximumTotalBytes: number; - maximumInventoryFiles: number; - candidateFiles: number; - selectedFiles: number; - estimatedTokens: number; - selectedBytes: number; - }; - }; - }>; - submitArtifact(input: ArtifactSubmission): { - run: RunRecord; - nextAction: NextAction; - } | { - run: RunRecord; - artifact: import("@telic/core").StoredArtifact; - nextAction: NextAction; - }; - answerClarification(runId: string, response: string): { - run: RunRecord; - nextAction: NextAction; - }; - cancelRun(runId: string, actionId: string, expectedRunVersion: number): { - run: RunRecord; - nextAction: NextAction; - }; - listRuns(limit?: number): RunSummary[]; - getRun(runId: string): { - run: RunRecord; - artifacts: import("@telic/core").StoredArtifact[]; - nextAction: NextAction; - }; - getArtifact(runId: string, artifactId: string): import("@telic/core").HydratedArtifact; - checkToolAction(input: { - runId: string; - actionId: string; - expectedRunVersion: number; - capability: string; - target?: string; - }): BrokerDecision; - replayRun(runId: string): ReplayReport; - getTrace(runId: string, afterSequence?: number, limit?: number): { - schemaVersion: "1.0"; - id: string; - runId: string; - sequence: number; - timestamp: string; - actor: "controller" | "executor" | "host" | "quality_controller" | "release_auditor" | "scenario_author" | "task_compiler" | "tool" | "user"; - phase: "agent_1_frame" | "agent_1_review" | "agent_2_compile" | "agent_2_revision" | "agent_3_evidence_reverify" | "agent_3_plan" | "agent_3_quality_review" | "agent_4_execute" | "agent_4_remediation" | "agent_5_release_audit" | "awaiting_clarification" | "blocked" | "cancelled" | "completed" | "context_discovery" | "contract_validation" | "diagnosis_review" | "partial" | "plan_validation" | "received" | "remediation_plan" | "user_report"; - eventType: "artifact_recorded" | "broker_decision" | "budget_consumed" | "clarification_requested" | "context_selected" | "digest_verified" | "lineage_linked" | "permission_checked" | "phase_started" | "phase_submitted" | "redaction_applied" | "run_started" | "run_terminated" | "tool_finished" | "tool_started" | "topology_classified" | "topology_escalated" | "transition_allowed" | "transition_denied"; - inputRefs: string[]; - outputRefs: string[]; - tool: { - name: string; - argumentsRef: string | null; - resultRef: string | null; - exitStatus: number | null; - } | null; - permissionDecision: { - decision: "allow" | "deny"; - capability: string; - scope: string; - policyRefs: string[]; - rationaleSummary: string; - } | null; - budgetSnapshot: { - promptRevisions: number; - postExecutionRemediations: number; - transportRetries: number; - }; - rationaleSummary: string; - redactions: { - id: string; - targetRef: string; - category: "credential" | "personal_data" | "secret" | "sensitive_output"; - }[]; - }[]; -} -//# sourceMappingURL=service.d.ts.map \ No newline at end of file diff --git a/packages/mcp/src/service.d.ts.map b/packages/mcp/src/service.d.ts.map deleted file mode 100644 index 35d1449..0000000 --- a/packages/mcp/src/service.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["service.ts"],"names":[],"mappings":"AAaA,OAAO,EAIL,KAAK,oBAAoB,EAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,KAAK,UAAU,EACf,aAAa,EACb,YAAY,EAIZ,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,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IAEnC,YAAY,OAAO,EAAE,cAAc,EAkBlC;IAED,KAAK,IAAI,IAAI,CAEZ;IAED,iBAAiB,CACf,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,MAAM,GACzB,IAAI,CAWN;IAED,QAAQ,CAAC,KAAK,EAAE,eAAe;;;MAoC9B;IAED,OAAO,CAAC,oBAAoB;IAgBtB,aAAa,CAAC,KAAK,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyG9C;IAED,cAAc,CAAC,KAAK,EAAE,kBAAkB;;;;;;;MAgKvC;IAED,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;;;MAIlD;IAED,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM;;;MAMpE;IAED,QAAQ,CAAC,KAAK,SAAK,GAAG,UAAU,EAAE,CAiCjC;IAED,MAAM,CAAC,KAAK,EAAE,MAAM;;;;MAOnB;IAED,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,0CAI5C;IAED,eAAe,CAAC,KAAK,EAAE;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,cAAc,CA8CjB;IAED,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAGrC;IAED,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,SAAI,EAAE,KAAK,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA6BxD;CACF"} \ No newline at end of file diff --git a/packages/mcp/src/service.js b/packages/mcp/src/service.js deleted file mode 100644 index cc2adc8..0000000 --- a/packages/mcp/src/service.js +++ /dev/null @@ -1,636 +0,0 @@ -import { createHash } from "node:crypto"; -import { existsSync, realpathSync } from "node:fs"; -import { homedir } from "node:os"; -import { basename, dirname, isAbsolute, join, relative, resolve, sep, } from "node:path"; -import { containsLikelySecret, groundRepository, isInstructionPath, } from "@telic/context"; -import { clearActiveSession, writeActiveSession, RunController, SqliteLedger, evaluateBrokerAction, inspectRunReplay, permissionsFromEnvelope, } from "@telic/core"; -import { isArtifactType, getArtifactJsonSchema, normalizeContextManifestWire, parseArtifactBody, parseContextManifest, } from "@telic/protocol"; -export function defaultStateDirectory(repositoryRoot) { - const canonicalRoot = realpathSync(resolve(repositoryRoot)); - const repositoryKey = createHash("sha256") - .update(canonicalRoot) - .digest("hex") - .slice(0, 24); - const stateHome = process.env.XDG_STATE_HOME - ? resolve(process.env.XDG_STATE_HOME) - : join(homedir(), ".local", "state"); - return join(stateHome, "telic", "repositories", repositoryKey); -} -function protocolValidator(type, body) { - if (!isArtifactType(type)) - throw new Error(`Unsupported artifact type: ${type}`); - return parseArtifactBody(type, body); -} -function defaultCapabilities(mode) { - switch (mode) { - case "report_only": - return []; - case "plan_only": - return ["repository.read"]; - case "analyze_only": - return [ - "repository.read", - "shell.inspect", - "runtime.inspect", - "browser.inspect", - ]; - case "fix_only": - case "analyze_and_fix": - return [ - "repository.read", - "repository.write", - "shell.inspect", - "runtime.inspect", - ]; - } -} -function intersectCapabilities(granted, available) { - const availableSet = new Set(available); - return [...new Set(granted)] - .filter((capability) => availableSet.has(capability)) - .sort(); -} -const MAX_TRACE_INPUT_REFS = 256; -const MAX_DECODED_EVIDENCE_BYTES = 2 * 1024 * 1024; -const MAX_EVIDENCE_PER_WORK_PLAN = 128; -const MAX_SCENARIO_SPECS_PER_FRAME = 1; -const REFERENCE_URI_PATTERN = /^(?:artifact|repo|trace):\/\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]+$/u; -const CANONICAL_BASE64_PATTERN = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u; -function isPathContained(root, target) { - const fromRoot = relative(root, target); - return (fromRoot === "" || - (fromRoot !== ".." && - !fromRoot.startsWith(`..${sep}`) && - !isAbsolute(fromRoot))); -} -function canonicalProspectivePath(path) { - let existingAncestor = resolve(path); - const missingSegments = []; - while (!existsSync(existingAncestor)) { - const parent = dirname(existingAncestor); - if (parent === existingAncestor) - return resolve(path); - missingSegments.unshift(basename(existingAncestor)); - existingAncestor = parent; - } - return resolve(realpathSync(existingAncestor), ...missingSegments); -} -function assertStateOutsideRepository(repositoryRoot, stateDirectory) { - const lexicalState = resolve(stateDirectory); - const canonicalState = canonicalProspectivePath(lexicalState); - if (isPathContained(repositoryRoot, lexicalState) || - isPathContained(lexicalState, repositoryRoot) || - isPathContained(repositoryRoot, canonicalState) || - isPathContained(canonicalState, repositoryRoot)) { - throw new Error("Telic state directory must be outside the repository being grounded and must not contain it"); - } -} -function containsLikelySecretInValue(value, seen = new WeakSet()) { - if (typeof value === "string") - return containsLikelySecret(value); - if (typeof value !== "object" || value === null) - return false; - if (seen.has(value)) - return false; - seen.add(value); - const values = Array.isArray(value) ? value : Object.values(value); - const containsSecret = values.some((child) => containsLikelySecretInValue(child, seen)); - seen.delete(value); - return containsSecret; -} -function evidenceContentForSecretScan(encoding, content) { - if (encoding === "utf8") - return content; - if (!CANONICAL_BASE64_PATTERN.test(content)) { - throw new Error("Evidence content is not canonical base64"); - } - const decoded = Buffer.from(content, "base64"); - if (decoded.byteLength > MAX_DECODED_EVIDENCE_BYTES) { - throw new Error(`Decoded evidence exceeds ${String(MAX_DECODED_EVIDENCE_BYTES)} bytes`); - } - if (decoded.toString("base64") !== content) { - throw new Error("Evidence content is not canonical base64"); - } - return decoded.toString("utf8"); -} -function collectBodyReferenceUris(value, references, key = "", depth = 0, seen = new WeakSet()) { - if (depth > 64) - return; - if (typeof value === "string") { - if ((key === "ref" || - key === "evidenceInspected" || - key.endsWith("Ref") || - key.endsWith("Refs")) && - REFERENCE_URI_PATTERN.test(value)) { - references.add(value); - } - return; - } - if (typeof value !== "object" || value === null) - return; - if (seen.has(value)) - return; - seen.add(value); - if (Array.isArray(value)) { - for (const item of value) { - collectBodyReferenceUris(item, references, key, depth + 1, seen); - } - } - else { - for (const [childKey, child] of Object.entries(value)) { - collectBodyReferenceUris(child, references, childKey, depth + 1, seen); - } - } - seen.delete(value); -} -function traceInputRefs(ledger, runId, body, supplied = []) { - if (new Set(supplied).size !== supplied.length) { - throw new Error("Artifact sourceRefs must be unique"); - } - const result = new Set(supplied); - if (result.size > MAX_TRACE_INPUT_REFS) { - throw new Error(`Artifact sourceRefs exceed the ${String(MAX_TRACE_INPUT_REFS)} item limit`); - } - const bodyReferences = new Set(); - collectBodyReferenceUris(body, bodyReferences); - const existingArtifacts = new Set(ledger - .listArtifacts(runId) - .map((artifact) => `artifact://${runId}/${artifact.id}`)); - for (const reference of bodyReferences) { - if (reference.startsWith("artifact://system/")) - continue; - if (reference.startsWith("artifact://") && - !existingArtifacts.has(reference)) { - continue; - } - result.add(reference); - if (result.size > MAX_TRACE_INPUT_REFS) { - throw new Error(`Artifact sourceRefs exceed the ${String(MAX_TRACE_INPUT_REFS)} item limit`); - } - } - return [...result]; -} -function internalDocumentId(contextId, hash, index) { - return `${contextId}-source-${String(index + 1).padStart(3, "0")}-${hash.slice("sha256:".length, 20)}`; -} -function emptyReportOnlyManifest(run) { - const digest = createHash("sha256").update("").digest("hex"); - return parseContextManifest({ - schemaVersion: "1.0", - id: `context-report-only-${run.runId.slice(0, 12)}`, - runId: run.runId, - repositoryFingerprint: { - headCommit: null, - dirtyWorktreeHash: `sha256:${digest}`, - }, - pinnedRefs: [], - candidates: [], - derivedRefs: [], - excludedCandidateSummaries: [], - inventorySource: "filesystem", - warnings: [ - "report_only mode intentionally skipped new repository discovery.", - ], - budget: { - maximumFiles: 1, - maximumFileBytes: 1, - maximumTotalBytes: 1, - maximumInventoryFiles: 1, - candidateFiles: 0, - selectedFiles: 0, - selectedBytes: 0, - estimatedTokens: 0, - }, - }); -} -const tracePhase = { - context_grounding: "context_discovery", - agent_1_frame: "agent_1_frame", - agent_2_compile: "agent_2_compile", - agent_1_review: "agent_1_review", - agent_2_revise: "agent_2_revision", - agent_3_plan: "agent_3_plan", - agent_4_execute: "agent_4_execute", - agent_3_review: "agent_3_quality_review", - agent_3_evidence_reverify: "agent_3_evidence_reverify", - agent_5_audit: "agent_5_release_audit", - agent_5_report: "user_report", -}; -const canonicalTraceEventType = { - run_started: "run_started", - context_source_stored: "artifact_recorded", - evidence_captured: "artifact_recorded", - scenario_presentation_stored: "artifact_recorded", - phase_submitted: "phase_submitted", - clarification_requested: "clarification_requested", - permission_checked: "permission_checked", - broker_decision: "broker_decision", - clarification_answered: "transition_allowed", - run_cancelled: "run_terminated", - topology_classified: "topology_classified", - digest_verified: "digest_verified", - lineage_linked: "lineage_linked", - topology_escalated: "topology_escalated", -}; -const traceActors = new Set([ - "controller", - "scenario_author", - "task_compiler", - "quality_controller", - "executor", - "release_auditor", - "host", - "tool", - "user", -]); -export class TelicService { - repositoryRoot; - stateDirectory; - ledger; - controller; - constructor(options) { - this.repositoryRoot = realpathSync(resolve(options.repositoryRoot)); - const stateDirectory = resolve(options.stateDirectory ?? defaultStateDirectory(this.repositoryRoot)); - assertStateOutsideRepository(this.repositoryRoot, stateDirectory); - this.stateDirectory = stateDirectory; - this.ledger = new SqliteLedger(this.stateDirectory); - this.controller = new RunController(this.ledger, protocolValidator, (type) => { - if (!isArtifactType(type)) { - throw new Error(`Unsupported artifact type: ${type}`); - } - return getArtifactJsonSchema(type); - }); - } - close() { - this.ledger.close(); - } - assertActionToken(runId, actionId, expectedRunVersion) { - const run = this.ledger.requireRun(runId); - if (run.version !== expectedRunVersion) { - throw new Error(`Stale run version ${String(expectedRunVersion)}; current version is ${String(run.version)}`); - } - const action = this.controller.getNextAction(runId); - if (action.id !== actionId) { - throw new Error("Stale or foreign action_id; reload the next action"); - } - } - startRun(input) { - const hostCapabilities = [ - ...new Set(input.hostCapabilities ?? ["repository.read"]), - ].sort(); - const desired = input.authorizationGranted ?? defaultCapabilities(input.mode); - const granted = intersectCapabilities(desired, hostCapabilities); - const denied = [...new Set(input.authorizationDenied ?? [])].sort(); - const started = this.controller.startRun({ - repositoryRoot: this.repositoryRoot, - originalRequest: input.originalRequest, - requestedMode: input.mode, - ...(input.topologyOverride !== undefined - ? { topologyOverride: input.topologyOverride } - : {}), - ...(input.priorRunId !== undefined - ? { priorRunId: input.priorRunId } - : {}), - host: { - name: input.hostName ?? "mcp-host", - nativeSubagents: input.nativeSubagents ?? "unknown", - capabilities: hostCapabilities, - }, - authorization: { - granted, - denied, - ...(input.shellExecuteAllowlist - ? { shellExecuteAllowlist: input.shellExecuteAllowlist } - : {}), - ...(input.networkReadDomains - ? { networkReadDomains: input.networkReadDomains } - : {}), - }, - }); - this.publishActiveSession(started.run, started.nextAction); - return started; - } - publishActiveSession(run, nextAction) { - if (run.status !== "running") { - clearActiveSession(this.stateDirectory); - return; - } - writeActiveSession(this.stateDirectory, { - schemaVersion: "1.0", - runId: run.runId, - actionId: nextAction.id, - runVersion: run.version, - repositoryRoot: run.repositoryRoot, - requestedMode: run.requestedMode, - updatedAt: new Date().toISOString(), - }); - } - async groundContext(input) { - const run = this.ledger.requireRun(input.runId); - if (run.phase !== "context_grounding" || run.status !== "running") { - throw new Error(`Run ${run.runId} is not awaiting context grounding`); - } - let manifest; - let sourceRefs = []; - if (run.requestedMode === "report_only") { - manifest = emptyReportOnlyManifest(run); - } - else { - const requestRecord = this.ledger - .listArtifacts(run.runId) - .find((artifact) => artifact.type === "UserMessage"); - if (!requestRecord) - throw new Error("Run is missing its immutable original request"); - const requestArtifact = this.ledger.getArtifact(run.runId, requestRecord.id); - const requestBody = requestArtifact?.body; - if (typeof requestBody !== "object" || - requestBody === null || - !("content" in requestBody) || - typeof requestBody.content !== "string") { - throw new Error("Original request artifact is invalid"); - } - const grounded = await groundRepository({ - run_id: run.runId, - repository_root: run.repositoryRoot, - request: requestBody.content, - excluded_roots: [this.stateDirectory], - ...(input.activePaths ? { active_paths: input.activePaths } : {}), - ...(input.budget ? { budget: input.budget } : {}), - }); - for (const [index, document] of grounded.documents.entries()) { - const id = internalDocumentId(grounded.manifest.id, document.content_hash, index); - const uri = `artifact://${run.runId}/${id}`; - sourceRefs.push(uri); - this.ledger.appendSupportingArtifact({ - id, - runId: run.runId, - type: "ContextDocument", - schemaVersion: "1.0", - producer: "controller", - sourceRefs: [document.ref], - body: { - schemaVersion: "1.0", - id, - runId: run.runId, - repositoryRef: document.ref, - contentHash: document.content_hash, - sizeBytes: document.size_bytes, - trustKind: isInstructionPath(document.path) - ? "applicable_instruction" - : "untrusted_repository_content", - instructionScope: isInstructionPath(document.path) - ? document.path.includes("/") - ? document.path.slice(0, document.path.lastIndexOf("/")) - : "." - : null, - content: document.content, - }, - }, { - actor: "controller", - eventType: "context_source_stored", - inputRefs: [document.ref], - decisionSummary: `Stored selected source ${document.ref} once in the content-addressed artifact store.`, - }); - } - manifest = normalizeContextManifestWire({ - ...grounded.manifest, - derived_refs: sourceRefs, - }); - } - const groundingAction = this.controller.getNextAction(run.runId); - if (groundingAction.kind === "phase") { - sourceRefs = [ - ...new Set([...groundingAction.inputRefs, ...sourceRefs]), - ].slice(0, MAX_TRACE_INPUT_REFS); - } - const result = this.controller.submitArtifact({ - id: manifest.id, - runId: run.runId, - type: "ContextManifest", - schemaVersion: "1.0", - producer: "controller", - sourceRefs, - body: manifest, - }); - this.publishActiveSession(result.run, result.nextAction); - return { ...result, manifest }; - } - submitArtifact(input) { - if (input.type === "RunEnvelope" || - input.type === "ContextManifest" || - input.type === "NextAction" || - input.type === "TraceEvent") { - throw new Error(`${input.type} is controller-owned and cannot be submitted by a host role`); - } - if (input.type === "Evidence") { - const run = this.ledger.requireRun(input.runId); - if (run.status !== "running" || run.phase !== "agent_4_execute") { - throw new Error("Evidence may be captured only during the bounded executor phase"); - } - const body = parseArtifactBody("Evidence", input.body); - if (input.producer !== "executor" || - input.id !== body.id || - input.runId !== body.runId || - input.schemaVersion !== body.schemaVersion) { - throw new Error("Evidence metadata or producer does not match its body"); - } - const sourceRefs = traceInputRefs(this.ledger, input.runId, body, input.sourceRefs); - const decodedContent = evidenceContentForSecretScan(body.encoding, body.content); - if (containsLikelySecretInValue(body) || - containsLikelySecret(decodedContent) || - containsLikelySecretInValue(sourceRefs)) { - throw new Error("Evidence contains a likely credential; redact the value before submission"); - } - this.controller.assertArtifactReferences({ ...input, body, sourceRefs }); - for (const sourceRef of body.sourceRefs) { - if (!sourceRef.startsWith("artifact://")) - continue; - const match = /^artifact:\/\/([^/]+)\/([^/]+)$/.exec(sourceRef); - if (!match || - match[1] !== input.runId || - !this.ledger.getArtifact(input.runId, match[2])) { - throw new Error(`Evidence source reference is missing or belongs to another run: ${sourceRef}`); - } - } - const stored = this.ledger.appendSupportingArtifact({ ...input, body, sourceRefs }, { - actor: "executor", - eventType: "evidence_captured", - inputRefs: sourceRefs, - decisionSummary: `Captured a redacted ${body.kind} evidence artifact.`, - }, { - scope: "after_latest", - anchorType: "WorkPlan", - maximum: MAX_EVIDENCE_PER_WORK_PLAN, - errorMessage: `Evidence quota of ${String(MAX_EVIDENCE_PER_WORK_PLAN)} per WorkPlan reached`, - }); - return { - run, - artifact: stored, - nextAction: this.controller.getNextAction(input.runId), - }; - } - if (input.type === "ScenarioSpec") { - const run = this.ledger.requireRun(input.runId); - if (run.status !== "running" || run.phase !== "agent_2_compile") { - throw new Error("Optional ScenarioSpec must immediately follow its accepted ProblemFrame"); - } - const body = parseArtifactBody("ScenarioSpec", input.body); - if (input.producer !== "scenario_author" || - input.id !== body.id || - input.runId !== body.runId || - input.schemaVersion !== body.schemaVersion) { - throw new Error("ScenarioSpec metadata or producer does not match its body"); - } - const sourceRefs = traceInputRefs(this.ledger, input.runId, body, input.sourceRefs); - this.controller.assertArtifactReferences({ ...input, body, sourceRefs }); - const match = /^artifact:\/\/([^/]+)\/([^/]+)$/.exec(body.problemFrameRef); - if (!match || - match[1] !== input.runId || - !this.ledger.getArtifact(input.runId, match[2])) { - throw new Error("ScenarioSpec must reference an existing ProblemFrame in the same run"); - } - const stored = this.ledger.appendSupportingArtifact({ ...input, body, sourceRefs }, { - actor: input.producer, - eventType: "scenario_presentation_stored", - inputRefs: sourceRefs, - decisionSummary: "Stored an optional sourced scenario presentation; the ProblemFrame remains authoritative.", - }, { - scope: "matching_body_field", - field: "problemFrameRef", - value: body.problemFrameRef, - maximum: MAX_SCENARIO_SPECS_PER_FRAME, - errorMessage: "Only one ScenarioSpec may be stored for the current ProblemFrame", - }); - return { - run, - artifact: stored, - nextAction: this.controller.getNextAction(input.runId), - }; - } - if (!isArtifactType(input.type)) { - throw new Error(`Unsupported artifact type: ${input.type}`); - } - const body = parseArtifactBody(input.type, input.body); - const submitted = this.controller.submitArtifact({ - ...input, - body, - sourceRefs: traceInputRefs(this.ledger, input.runId, body, input.sourceRefs), - }); - this.publishActiveSession(submitted.run, submitted.nextAction); - return submitted; - } - answerClarification(runId, response) { - const answered = this.controller.answerClarification(runId, response); - this.publishActiveSession(answered.run, answered.nextAction); - return answered; - } - cancelRun(runId, actionId, expectedRunVersion) { - this.assertActionToken(runId, actionId, expectedRunVersion); - const run = this.controller.cancelRun(runId); - const nextAction = this.controller.getNextAction(runId); - this.publishActiveSession(run, nextAction); - return { run, nextAction }; - } - listRuns(limit = 20) { - if (!Number.isInteger(limit) || limit < 1 || limit > 100) { - throw new Error("Run list limit must be an integer from 1 to 100"); - } - return this.ledger - .listRuns(limit) - .map(({ runId, schemaVersion, requestedMode, topology, status, phase, resumePhase, version, outcomeHint, createdAt, updatedAt, }) => ({ - runId, - schemaVersion, - requestedMode, - topology, - status, - phase, - resumePhase, - version, - outcomeHint, - createdAt, - updatedAt, - })); - } - getRun(runId) { - const run = this.ledger.requireRun(runId); - return { - run, - artifacts: this.ledger.listArtifacts(runId), - nextAction: this.controller.getNextAction(runId), - }; - } - getArtifact(runId, artifactId) { - const artifact = this.ledger.getArtifact(runId, artifactId); - if (!artifact) - throw new Error(`Artifact not found: ${artifactId}`); - return artifact; - } - checkToolAction(input) { - this.assertActionToken(input.runId, input.actionId, input.expectedRunVersion); - const run = this.ledger.requireRun(input.runId); - const envelopeRecord = this.ledger.findLatestArtifact(input.runId, "RunEnvelope"); - const envelopeBody = envelopeRecord - ? this.ledger.getArtifact(input.runId, envelopeRecord.id)?.body - : null; - const envelopeRef = envelopeRecord - ? "artifact://" + input.runId + "/" + envelopeRecord.id - : null; - const decision = evaluateBrokerAction({ - repositoryRoot: run.repositoryRoot, - mode: run.requestedMode, - permissions: permissionsFromEnvelope(run.requestedMode, envelopeBody), - ...(envelopeRef ? { policyRefs: [envelopeRef] } : {}), - }, { - capability: input.capability, - ...(input.target !== undefined ? { target: input.target } : {}), - runId: input.runId, - actionId: input.actionId, - }); - this.ledger.appendTraceEvent(input.runId, { - actor: "host", - eventType: "broker_decision", - phase: run.phase, - inputRefs: envelopeRef ? [envelopeRef] : [], - permissionDecision: decision.permissionDecision, - decisionSummary: decision.allowed - ? "Broker allowed " + input.capability + "." - : "Broker denied " + - input.capability + - ": " + - decision.reasonCode + - ".", - }); - return decision; - } - replayRun(runId) { - const run = this.ledger.requireRun(runId); - return inspectRunReplay(this.ledger, run); - } - getTrace(runId, afterSequence = 0, limit = 10_000) { - this.ledger.requireRun(runId); - return this.ledger.listTrace(runId, afterSequence, limit).map((event) => parseArtifactBody("TraceEvent", { - schemaVersion: "1.0", - id: event.id, - runId: event.runId, - sequence: event.sequence, - timestamp: event.timestamp, - actor: traceActors.has(event.actor) - ? event.actor - : "host", - phase: tracePhase[event.phase], - eventType: canonicalTraceEventType[event.eventType] ?? "artifact_recorded", - inputRefs: event.inputRefs, - outputRefs: event.outputRefs, - tool: null, - permissionDecision: event.permissionDecision, - budgetSnapshot: { - promptRevisions: event.budgetSnapshot.promptRevisionsRemaining, - postExecutionRemediations: event.budgetSnapshot.postExecutionRemediationsRemaining, - transportRetries: 0, - }, - rationaleSummary: event.decisionSummary, - redactions: [], - })); - } -} -//# sourceMappingURL=service.js.map \ No newline at end of file diff --git a/packages/mcp/src/service.js.map b/packages/mcp/src/service.js.map deleted file mode 100644 index af58089..0000000 --- a/packages/mcp/src/service.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"service.js","sourceRoot":"","sources":["service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EACL,QAAQ,EACR,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,GAElB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAElB,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,GAMxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,4BAA4B,EAC5B,iBAAiB,EACjB,oBAAoB,GAGrB,MAAM,iBAAiB,CAAC;AAOzB,MAAM,UAAU,qBAAqB,CAAC,cAAsB;IAC1D,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC;IAC5D,MAAM,aAAa,GAAG,UAAU,CAAC,QAAQ,CAAC;SACvC,MAAM,CAAC,aAAa,CAAC;SACrB,MAAM,CAAC,KAAK,CAAC;SACb,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChB,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc;QAC1C,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;Q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