@mcoda/codali 0.1.134 → 0.1.135-codali.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/ORCHESTRATION.md +462 -0
- package/README.md +112 -1
- package/config/alternate-local.example.json +49 -0
- package/config/docdex-runtime.json +21 -0
- package/config/orchestration.schema.json +548 -0
- package/config/raijin-suku.example.json +172 -0
- package/config/terminal-long-scenarios.v1.json +71 -0
- package/dist/agents/RoleResolution.d.ts.map +1 -1
- package/dist/agents/RoleResolution.js +4 -4
- package/dist/api/CodaliApi.d.ts +16 -0
- package/dist/api/CodaliApi.d.ts.map +1 -1
- package/dist/api/CodaliApi.js +39 -10
- package/dist/cli/AskCommand.d.ts +3 -0
- package/dist/cli/AskCommand.d.ts.map +1 -1
- package/dist/cli/AskCommand.js +76 -13
- package/dist/cli/RunCommand.d.ts +4 -0
- package/dist/cli/RunCommand.d.ts.map +1 -1
- package/dist/cli/RunCommand.js +110 -24
- package/dist/cli/TerminalCommand.d.ts +35 -0
- package/dist/cli/TerminalCommand.d.ts.map +1 -0
- package/dist/cli/TerminalCommand.js +618 -0
- package/dist/cli/TerminalCredentials.d.ts +3 -0
- package/dist/cli/TerminalCredentials.d.ts.map +1 -0
- package/dist/cli/TerminalCredentials.js +89 -0
- package/dist/cli/TerminalInput.d.ts +24 -0
- package/dist/cli/TerminalInput.d.ts.map +1 -0
- package/dist/cli/TerminalInput.js +98 -0
- package/dist/cli/TerminalText.d.ts +10 -0
- package/dist/cli/TerminalText.d.ts.map +1 -0
- package/dist/cli/TerminalText.js +53 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +33 -4
- package/dist/cognitive/ConfiguredPipeline.d.ts +34 -0
- package/dist/cognitive/ConfiguredPipeline.d.ts.map +1 -0
- package/dist/cognitive/ConfiguredPipeline.js +50 -0
- package/dist/cognitive/ValidationRunner.d.ts +4 -0
- package/dist/cognitive/ValidationRunner.d.ts.map +1 -1
- package/dist/cognitive/ValidationRunner.js +18 -41
- package/dist/config/NodeOrchestration.d.ts +21 -0
- package/dist/config/NodeOrchestration.d.ts.map +1 -0
- package/dist/config/NodeOrchestration.js +54 -0
- package/dist/config/OrchestrationConfig.d.ts +100 -0
- package/dist/config/OrchestrationConfig.d.ts.map +1 -0
- package/dist/config/OrchestrationConfig.js +245 -0
- package/dist/connectors/mcp/McpClient.d.ts +3 -1
- package/dist/connectors/mcp/McpClient.d.ts.map +1 -1
- package/dist/connectors/mcp/McpClient.js +3 -2
- package/dist/connectors/mcp/McpServerRegistry.d.ts +2 -2
- package/dist/connectors/mcp/McpServerRegistry.d.ts.map +1 -1
- package/dist/connectors/mcp/McpServerRegistry.js +39 -16
- package/dist/connectors/mcp/McpToolAdapter.js +2 -2
- package/dist/connectors/media/ConfiguredMediaTools.d.ts +6 -0
- package/dist/connectors/media/ConfiguredMediaTools.d.ts.map +1 -0
- package/dist/connectors/media/ConfiguredMediaTools.js +41 -0
- package/dist/connectors/media/ImageGenerationTool.js +3 -3
- package/dist/connectors/media/MediaArtifactReceipt.d.ts +5 -0
- package/dist/connectors/media/MediaArtifactReceipt.d.ts.map +1 -0
- package/dist/connectors/media/MediaArtifactReceipt.js +65 -0
- package/dist/connectors/media/MediaJobStore.d.ts +68 -0
- package/dist/connectors/media/MediaJobStore.d.ts.map +1 -0
- package/dist/connectors/media/MediaJobStore.js +199 -0
- package/dist/connectors/media/MediaJobWorker.d.ts +2 -0
- package/dist/connectors/media/MediaJobWorker.d.ts.map +1 -0
- package/dist/connectors/media/MediaJobWorker.js +65 -0
- package/dist/connectors/media/RemoteMediaJob.d.ts +6 -0
- package/dist/connectors/media/RemoteMediaJob.d.ts.map +1 -0
- package/dist/connectors/media/RemoteMediaJob.js +80 -0
- package/dist/docdex/DocdexClient.d.ts +18 -1
- package/dist/docdex/DocdexClient.d.ts.map +1 -1
- package/dist/docdex/DocdexClient.js +135 -19
- package/dist/docdex/ManagedDocdex.d.ts +29 -0
- package/dist/docdex/ManagedDocdex.d.ts.map +1 -0
- package/dist/docdex/ManagedDocdex.js +215 -0
- package/dist/docdex/ManagedRuntime.d.ts +28 -0
- package/dist/docdex/ManagedRuntime.d.ts.map +1 -0
- package/dist/docdex/ManagedRuntime.js +212 -0
- package/dist/eval/EvaluationProcess.d.ts +13 -0
- package/dist/eval/EvaluationProcess.d.ts.map +1 -0
- package/dist/eval/EvaluationProcess.js +76 -0
- package/dist/eval/LongWorkflowJourney.d.ts +34 -0
- package/dist/eval/LongWorkflowJourney.d.ts.map +1 -0
- package/dist/eval/LongWorkflowJourney.js +243 -0
- package/dist/eval/PlanningCorpus.d.ts +45 -0
- package/dist/eval/PlanningCorpus.d.ts.map +1 -0
- package/dist/eval/PlanningCorpus.js +189 -0
- package/dist/eval/PlanningCorpusRunner.d.ts +13 -0
- package/dist/eval/PlanningCorpusRunner.d.ts.map +1 -0
- package/dist/eval/PlanningCorpusRunner.js +89 -0
- package/dist/eval/TerminalCorpusRunner.d.ts +36 -0
- package/dist/eval/TerminalCorpusRunner.d.ts.map +1 -0
- package/dist/eval/TerminalCorpusRunner.js +222 -0
- package/dist/eval/TerminalTaskCorpus.d.ts +26 -0
- package/dist/eval/TerminalTaskCorpus.d.ts.map +1 -0
- package/dist/eval/TerminalTaskCorpus.js +105 -0
- package/dist/eval/TerminalWorkflowCorpus.d.ts +11 -0
- package/dist/eval/TerminalWorkflowCorpus.d.ts.map +1 -0
- package/dist/eval/TerminalWorkflowCorpus.js +119 -0
- package/dist/eval/fixtures/ContractReviewProvider.d.ts +4 -0
- package/dist/eval/fixtures/ContractReviewProvider.d.ts.map +1 -0
- package/dist/eval/fixtures/ContractReviewProvider.js +10 -0
- package/dist/eval/fixtures/MixedMediaRecoveryJourney.d.ts +6 -0
- package/dist/eval/fixtures/MixedMediaRecoveryJourney.d.ts.map +1 -0
- package/dist/eval/fixtures/MixedMediaRecoveryJourney.js +145 -0
- package/dist/eval/fixtures/TerminalRecoveryJourney.d.ts +4 -0
- package/dist/eval/fixtures/TerminalRecoveryJourney.d.ts.map +1 -0
- package/dist/eval/fixtures/TerminalRecoveryJourney.js +136 -0
- package/dist/gateway/CodaliGateway.d.ts +2 -0
- package/dist/gateway/CodaliGateway.d.ts.map +1 -1
- package/dist/gateway/CodaliGateway.js +11 -1
- package/dist/gateway/ConfiguredGateway.d.ts +23 -0
- package/dist/gateway/ConfiguredGateway.d.ts.map +1 -0
- package/dist/gateway/ConfiguredGateway.js +44 -0
- package/dist/gateway/GatewayTracer.d.ts +1 -1
- package/dist/gateway/GatewayTracer.d.ts.map +1 -1
- package/dist/gateway/GatewayTracer.js +2 -27
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/permissions/PermissionGate.d.ts +44 -0
- package/dist/permissions/PermissionGate.d.ts.map +1 -0
- package/dist/permissions/PermissionGate.js +97 -0
- package/dist/providers/ConfiguredEmbeddings.d.ts +43 -0
- package/dist/providers/ConfiguredEmbeddings.d.ts.map +1 -0
- package/dist/providers/ConfiguredEmbeddings.js +87 -0
- package/dist/providers/ConfiguredModelScope.d.ts +70 -0
- package/dist/providers/ConfiguredModelScope.d.ts.map +1 -0
- package/dist/providers/ConfiguredModelScope.js +129 -0
- package/dist/providers/ConfiguredProvider.d.ts +84 -0
- package/dist/providers/ConfiguredProvider.d.ts.map +1 -0
- package/dist/providers/ConfiguredProvider.js +271 -0
- package/dist/providers/ModelServiceError.d.ts +15 -0
- package/dist/providers/ModelServiceError.d.ts.map +1 -0
- package/dist/providers/ModelServiceError.js +69 -0
- package/dist/providers/MswarmWorkerProvider.d.ts.map +1 -1
- package/dist/providers/MswarmWorkerProvider.js +4 -0
- package/dist/providers/OpenAiCompatibleProvider.d.ts.map +1 -1
- package/dist/providers/OpenAiCompatibleProvider.js +97 -50
- package/dist/providers/ProviderTypes.d.ts +14 -0
- package/dist/providers/ProviderTypes.d.ts.map +1 -1
- package/dist/providers/RequestUsage.d.ts +11 -0
- package/dist/providers/RequestUsage.d.ts.map +1 -0
- package/dist/providers/RequestUsage.js +33 -0
- package/dist/runtime/CodaliJobRuntime.d.ts +6 -0
- package/dist/runtime/CodaliJobRuntime.d.ts.map +1 -1
- package/dist/runtime/CodaliJobRuntime.js +36 -1
- package/dist/runtime/CodaliRuntime.d.ts +29 -0
- package/dist/runtime/CodaliRuntime.d.ts.map +1 -1
- package/dist/runtime/CodaliRuntime.js +70 -1
- package/dist/runtime/CompletionReport.d.ts +5 -0
- package/dist/runtime/CompletionReport.d.ts.map +1 -0
- package/dist/runtime/CompletionReport.js +12 -0
- package/dist/runtime/ProgressTracker.d.ts +17 -0
- package/dist/runtime/ProgressTracker.d.ts.map +1 -0
- package/dist/runtime/ProgressTracker.js +27 -0
- package/dist/runtime/RequestedTestEvidence.d.ts +12 -0
- package/dist/runtime/RequestedTestEvidence.d.ts.map +1 -0
- package/dist/runtime/RequestedTestEvidence.js +16 -0
- package/dist/runtime/RequiredRetrieval.d.ts +13 -0
- package/dist/runtime/RequiredRetrieval.d.ts.map +1 -0
- package/dist/runtime/RequiredRetrieval.js +25 -0
- package/dist/runtime/ReviewContract.d.ts +35 -0
- package/dist/runtime/ReviewContract.d.ts.map +1 -0
- package/dist/runtime/ReviewContract.js +132 -0
- package/dist/runtime/ReviewCoordinator.d.ts +41 -0
- package/dist/runtime/ReviewCoordinator.d.ts.map +1 -0
- package/dist/runtime/ReviewCoordinator.js +126 -0
- package/dist/runtime/ReviewSource.d.ts +9 -0
- package/dist/runtime/ReviewSource.d.ts.map +1 -0
- package/dist/runtime/ReviewSource.js +54 -0
- package/dist/runtime/Runner.d.ts +7 -0
- package/dist/runtime/Runner.d.ts.map +1 -1
- package/dist/runtime/Runner.js +220 -171
- package/dist/runtime/SecretRedaction.d.ts +11 -0
- package/dist/runtime/SecretRedaction.d.ts.map +1 -0
- package/dist/runtime/SecretRedaction.js +85 -0
- package/dist/runtime/SessionController.d.ts +150 -0
- package/dist/runtime/SessionController.d.ts.map +1 -0
- package/dist/runtime/SessionController.js +1487 -0
- package/dist/runtime/StructuralEvidence.d.ts +22 -0
- package/dist/runtime/StructuralEvidence.d.ts.map +1 -0
- package/dist/runtime/StructuralEvidence.js +87 -0
- package/dist/runtime/TaskReview.d.ts +25 -0
- package/dist/runtime/TaskReview.d.ts.map +1 -0
- package/dist/runtime/TaskReview.js +84 -0
- package/dist/runtime/TaskReviewContext.d.ts +71 -0
- package/dist/runtime/TaskReviewContext.d.ts.map +1 -0
- package/dist/runtime/TaskReviewContext.js +50 -0
- package/dist/runtime/UsageReconciliation.d.ts +28 -0
- package/dist/runtime/UsageReconciliation.d.ts.map +1 -0
- package/dist/runtime/UsageReconciliation.js +68 -0
- package/dist/runtime/ValidationOutput.d.ts +5 -0
- package/dist/runtime/ValidationOutput.d.ts.map +1 -0
- package/dist/runtime/ValidationOutput.js +32 -0
- package/dist/runtime/VerificationCommand.d.ts +5 -0
- package/dist/runtime/VerificationCommand.d.ts.map +1 -0
- package/dist/runtime/VerificationCommand.js +76 -0
- package/dist/runtime/VerificationReceiptSelection.d.ts +15 -0
- package/dist/runtime/VerificationReceiptSelection.d.ts.map +1 -0
- package/dist/runtime/VerificationReceiptSelection.js +30 -0
- package/dist/runtime/WorkStatusPage.d.ts +15 -0
- package/dist/runtime/WorkStatusPage.d.ts.map +1 -0
- package/dist/runtime/WorkStatusPage.js +58 -0
- package/dist/runtime/WorkspaceLedger.d.ts +13 -0
- package/dist/runtime/WorkspaceLedger.d.ts.map +1 -0
- package/dist/runtime/WorkspaceLedger.js +145 -0
- package/dist/runtime/WorkspaceLock.d.ts.map +1 -1
- package/dist/runtime/WorkspaceLock.js +20 -17
- package/dist/runtime/WorkspaceSnapshot.d.ts +13 -0
- package/dist/runtime/WorkspaceSnapshot.d.ts.map +1 -0
- package/dist/runtime/WorkspaceSnapshot.js +88 -0
- package/dist/session/AtomicState.d.ts +13 -0
- package/dist/session/AtomicState.d.ts.map +1 -0
- package/dist/session/AtomicState.js +123 -0
- package/dist/session/SessionStoragePath.d.ts +15 -0
- package/dist/session/SessionStoragePath.d.ts.map +1 -0
- package/dist/session/SessionStoragePath.js +101 -0
- package/dist/session/SessionStore.d.ts +9 -0
- package/dist/session/SessionStore.d.ts.map +1 -1
- package/dist/session/SessionStore.js +181 -47
- package/dist/session/WorkState.d.ts +32 -0
- package/dist/session/WorkState.d.ts.map +1 -0
- package/dist/session/WorkState.js +399 -0
- package/dist/session/WorkTypes.d.ts +102 -0
- package/dist/session/WorkTypes.d.ts.map +1 -0
- package/dist/session/WorkTypes.js +1 -0
- package/dist/tools/ToolRegistry.d.ts +2 -0
- package/dist/tools/ToolRegistry.d.ts.map +1 -1
- package/dist/tools/ToolRegistry.js +12 -2
- package/dist/tools/ToolTypes.d.ts +16 -0
- package/dist/tools/ToolTypes.d.ts.map +1 -1
- package/dist/tools/docdex/DocdexTools.d.ts +2 -0
- package/dist/tools/docdex/DocdexTools.d.ts.map +1 -1
- package/dist/tools/docdex/DocdexTools.js +17 -2
- package/dist/tools/filesystem/FileTools.d.ts.map +1 -1
- package/dist/tools/filesystem/FileTools.js +30 -10
- package/dist/tools/shell/AsyncProcess.d.ts +19 -0
- package/dist/tools/shell/AsyncProcess.d.ts.map +1 -0
- package/dist/tools/shell/AsyncProcess.js +94 -0
- package/dist/tools/shell/DarwinRuntimeLibraries.d.ts +13 -0
- package/dist/tools/shell/DarwinRuntimeLibraries.d.ts.map +1 -0
- package/dist/tools/shell/DarwinRuntimeLibraries.js +130 -0
- package/dist/tools/shell/HostToolchain.d.ts +19 -0
- package/dist/tools/shell/HostToolchain.d.ts.map +1 -0
- package/dist/tools/shell/HostToolchain.js +266 -0
- package/dist/tools/shell/IsolatedExecutor.d.ts +15 -0
- package/dist/tools/shell/IsolatedExecutor.d.ts.map +1 -0
- package/dist/tools/shell/IsolatedExecutor.js +138 -0
- package/dist/tools/shell/ShellTool.d.ts.map +1 -1
- package/dist/tools/shell/ShellTool.js +9 -29
- package/dist/tools/shell/ShellWorkingDirectory.d.ts +3 -0
- package/dist/tools/shell/ShellWorkingDirectory.d.ts.map +1 -0
- package/dist/tools/shell/ShellWorkingDirectory.js +30 -0
- package/package.json +27 -24
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface StructuralAnalysis {
|
|
2
|
+
kind: "structure" | "impact";
|
|
3
|
+
file: string;
|
|
4
|
+
hash: string;
|
|
5
|
+
valid: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const isSourcePath: (file: string) => boolean;
|
|
8
|
+
export declare const workspaceRelativePath: (root: string, file: string) => string;
|
|
9
|
+
export declare const isWithinScope: (file: string, scope: string[]) => boolean;
|
|
10
|
+
/** Git ignores cannot hide existing source from an explicitly writable directory. */
|
|
11
|
+
export declare const writableInventory: (root: string, scopes: string[], maxEntries?: number) => Promise<Record<string, string>>;
|
|
12
|
+
export declare const analysisTarget: (tool: string, args: Record<string, unknown>) => {
|
|
13
|
+
kind: StructuralAnalysis["kind"];
|
|
14
|
+
file: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
/** A successful transport alone is not structural evidence (parsers can skip files). */
|
|
17
|
+
export declare const validAnalysisResult: (kind: StructuralAnalysis["kind"], data: unknown, file: string) => boolean;
|
|
18
|
+
export declare const missingStructuralEvidence: (file: string, hash: string, receipts: Iterable<{
|
|
19
|
+
status: string;
|
|
20
|
+
analysis?: StructuralAnalysis;
|
|
21
|
+
}>) => string[];
|
|
22
|
+
//# sourceMappingURL=StructuralEvidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StructuralEvidence.d.ts","sourceRoot":"","sources":["../../src/runtime/StructuralEvidence.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,OAA2I,CAAC;AAExL,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,MAIlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,OAAO,MAAM,EAAE,KAAG,OAA+E,CAAC;AAE9I,qFAAqF;AACrF,eAAO,MAAM,iBAAiB,GAAU,MAAM,MAAM,EAAE,QAAQ,MAAM,EAAE,EAAE,mBAAmB,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAwB3H,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG;IAAE,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAIjI,CAAC;AAEF,wFAAwF;AACxF,eAAO,MAAM,mBAAmB,GAAI,MAAM,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,OAAO,EAAE,MAAM,MAAM,KAAG,OAOnG,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,EAAE,UAAU,QAAQ,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAA;CAAE,CAAC,KAAG,MAAM,EAQnJ,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
import { hashWorkspacePath } from "./WorkspaceSnapshot.js";
|
|
4
|
+
export const isSourcePath = (file) => /\.(?:[cm]?[jt]sx?|py|rs|go|java|kt|kts|c|cc|cpp|cxx|h|hpp|cs|rb|php|swift|sh|bash|lua|ex|exs|scala|sc|vue|svelte)$/i.test(file);
|
|
5
|
+
export const workspaceRelativePath = (root, file) => {
|
|
6
|
+
const relative = path.relative(root, path.resolve(root, file)).split(path.sep).join("/");
|
|
7
|
+
if (relative === ".." || relative.startsWith("../") || path.isAbsolute(relative))
|
|
8
|
+
throw new Error("Path escapes the workspace");
|
|
9
|
+
return relative || ".";
|
|
10
|
+
};
|
|
11
|
+
export const isWithinScope = (file, scope) => scope.some(p => p === "." || p === file || file.startsWith(`${p}/`));
|
|
12
|
+
/** Git ignores cannot hide existing source from an explicitly writable directory. */
|
|
13
|
+
export const writableInventory = async (root, scopes, maxEntries = 20000) => {
|
|
14
|
+
root = await fs.realpath(root);
|
|
15
|
+
const hashes = {};
|
|
16
|
+
const visited = new Set();
|
|
17
|
+
const walk = async (file) => {
|
|
18
|
+
if ([".git", ".mcoda"].some(dir => file === dir || file.startsWith(`${dir}/`)) || visited.has(file))
|
|
19
|
+
return;
|
|
20
|
+
visited.add(file);
|
|
21
|
+
if (visited.size > maxEntries)
|
|
22
|
+
throw new Error("Shell write inventory exceeds its bound; declare narrower writePaths");
|
|
23
|
+
const absolute = path.resolve(root, file);
|
|
24
|
+
let stat;
|
|
25
|
+
try {
|
|
26
|
+
stat = await fs.lstat(absolute);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (error.code === "ENOENT")
|
|
30
|
+
return;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
if (stat.isDirectory()) {
|
|
34
|
+
for (const entry of await fs.readdir(absolute))
|
|
35
|
+
await walk(workspaceRelativePath(root, path.join(absolute, entry)));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (stat.isFile() && stat.nlink > 1)
|
|
39
|
+
throw new Error(`Hard-linked writable file requires an independent copy: ${file}`);
|
|
40
|
+
hashes[file] = await hashWorkspacePath(root, file);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
for (const scope of scopes) {
|
|
44
|
+
const relative = workspaceRelativePath(root, scope);
|
|
45
|
+
const requested = path.resolve(root, relative);
|
|
46
|
+
try {
|
|
47
|
+
if (await fs.realpath(requested) !== requested)
|
|
48
|
+
throw new Error("Shell write paths must be canonical and cannot be symlink aliases");
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error.code !== "ENOENT")
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
await walk(relative);
|
|
55
|
+
}
|
|
56
|
+
return hashes;
|
|
57
|
+
};
|
|
58
|
+
export const analysisTarget = (tool, args) => {
|
|
59
|
+
if (["docdex_symbols", "docdex_ast"].includes(tool) && typeof args.path === "string")
|
|
60
|
+
return { kind: "structure", file: args.path };
|
|
61
|
+
if (tool === "docdex_impact_graph" && typeof args.file === "string")
|
|
62
|
+
return { kind: "impact", file: args.file };
|
|
63
|
+
return undefined;
|
|
64
|
+
};
|
|
65
|
+
/** A successful transport alone is not structural evidence (parsers can skip files). */
|
|
66
|
+
export const validAnalysisResult = (kind, data, file) => {
|
|
67
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
68
|
+
return false;
|
|
69
|
+
const value = data;
|
|
70
|
+
if (value.error || value.isError)
|
|
71
|
+
return false;
|
|
72
|
+
if (kind === "impact")
|
|
73
|
+
return value.source === file && Array.isArray(value.edges) && Array.isArray(value.inbound) && Array.isArray(value.outbound);
|
|
74
|
+
const outcome = value.outcome;
|
|
75
|
+
return value.file === file && outcome?.status === "ok" && (Array.isArray(value.symbols) || Array.isArray(value.nodes));
|
|
76
|
+
};
|
|
77
|
+
export const missingStructuralEvidence = (file, hash, receipts) => {
|
|
78
|
+
if (hash === "missing" || !isSourcePath(file))
|
|
79
|
+
return [];
|
|
80
|
+
const present = new Set();
|
|
81
|
+
for (const receipt of receipts) {
|
|
82
|
+
const a = receipt.analysis;
|
|
83
|
+
if (receipt.status === "success" && a?.valid && a.file === file && a.hash === hash)
|
|
84
|
+
present.add(a.kind);
|
|
85
|
+
}
|
|
86
|
+
return ["structure", "impact"].filter(kind => !present.has(kind));
|
|
87
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Provider, ProviderMessage } from "../providers/ProviderTypes.js";
|
|
2
|
+
export interface ReviewSourcePage {
|
|
3
|
+
path: string;
|
|
4
|
+
offset: number;
|
|
5
|
+
content: string;
|
|
6
|
+
truncated: boolean;
|
|
7
|
+
nextOffset?: number;
|
|
8
|
+
unavailable?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface TaskReviewResult {
|
|
11
|
+
passed: boolean;
|
|
12
|
+
findings: string[];
|
|
13
|
+
}
|
|
14
|
+
/** Read-only evidence requests share the caller's model budget and acceptance fence. */
|
|
15
|
+
export declare function runTaskReview(options: {
|
|
16
|
+
provider: Provider;
|
|
17
|
+
messages: ProviderMessage[];
|
|
18
|
+
allowedPaths: readonly string[];
|
|
19
|
+
initialSourceOffsets?: Readonly<Record<string, number>>;
|
|
20
|
+
readSourcePage: (file: string, offset: number) => Promise<ReviewSourcePage>;
|
|
21
|
+
maxInputChars: number;
|
|
22
|
+
maxOutputTokens?: number;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}): Promise<TaskReviewResult>;
|
|
25
|
+
//# sourceMappingURL=TaskReview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskReview.d.ts","sourceRoot":"","sources":["../../src/runtime/TaskReview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAE/E,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAAG,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE;AAEzE,wFAAwF;AACxF,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAC3C,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,oBAAoB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACxD,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5E,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAuE5B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** Read-only evidence requests share the caller's model budget and acceptance fence. */
|
|
2
|
+
export async function runTaskReview(options) {
|
|
3
|
+
const messages = [...options.messages];
|
|
4
|
+
const requested = new Set();
|
|
5
|
+
const nextOffsets = new Map(Object.entries(options.initialSourceOffsets ?? {}));
|
|
6
|
+
const reject = (finding) => ({ passed: false, findings: [finding] });
|
|
7
|
+
let sourceRounds = 0;
|
|
8
|
+
let formatRepaired = false;
|
|
9
|
+
// Four evidence rounds followed by a final decision. No execution tool or
|
|
10
|
+
// permission widening is available. One received malformed JSON reply may be
|
|
11
|
+
// repaired, still within the original contract, context and model-call budget.
|
|
12
|
+
for (let call = 0; call < 6; call++) {
|
|
13
|
+
options.signal?.throwIfAborted();
|
|
14
|
+
if (JSON.stringify(messages).length > options.maxInputChars) {
|
|
15
|
+
return reject("Required review evidence exceeds the configured model context. Split the task or select a larger compatible reviewer context; acceptance is not established.");
|
|
16
|
+
}
|
|
17
|
+
const response = await options.provider.generate({ messages, signal: options.signal, maxTokens: options.maxOutputTokens ?? 2048 });
|
|
18
|
+
options.signal?.throwIfAborted();
|
|
19
|
+
if (response.toolCalls?.length || response.message.toolCalls?.length)
|
|
20
|
+
return reject("Review returned an unsupported tool call; only bounded sourceRequests are available.");
|
|
21
|
+
let result;
|
|
22
|
+
try {
|
|
23
|
+
const value = JSON.parse(response.message.content);
|
|
24
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
25
|
+
return reject("Review did not provide a valid acceptance decision.");
|
|
26
|
+
result = value;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
if (formatRepaired)
|
|
30
|
+
return reject("Review did not provide valid JSON acceptance evidence after one format repair.");
|
|
31
|
+
formatRepaired = true;
|
|
32
|
+
messages.push({ role: "assistant", content: response.message.content });
|
|
33
|
+
messages.push({ role: "user", content: 'Repair only the JSON format of your review response. Retain every original contract, source page and acceptance rule. Return exactly {"passed":boolean,"findings":string[]} or the bounded sourceRequests protocol. Do not drop a defect or approve uncertain work to repair formatting.' });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!Object.prototype.hasOwnProperty.call(result, "sourceRequests")) {
|
|
37
|
+
// Preserve an actionable negative finding from providers that emit a
|
|
38
|
+
// scalar instead of an array. Malformed approval can never pass here.
|
|
39
|
+
if (result.passed === false && typeof result.findings === "string" && result.findings.trim()) {
|
|
40
|
+
return reject(result.findings);
|
|
41
|
+
}
|
|
42
|
+
if (typeof result.passed !== "boolean" || !Array.isArray(result.findings) || !result.findings.every(finding => typeof finding === "string")) {
|
|
43
|
+
return reject("Review did not provide valid acceptance evidence.");
|
|
44
|
+
}
|
|
45
|
+
return { passed: result.passed === true && result.findings.length === 0,
|
|
46
|
+
findings: result.findings.length ? result.findings : result.passed ? [] : ["Review rejected acceptance without a specific finding."] };
|
|
47
|
+
}
|
|
48
|
+
if (Object.prototype.hasOwnProperty.call(result, "passed") || Object.prototype.hasOwnProperty.call(result, "findings"))
|
|
49
|
+
return reject("Review must request source evidence or provide a final decision, not both.");
|
|
50
|
+
if (sourceRounds === 4)
|
|
51
|
+
return reject("Review source request limit reached without an acceptance decision. Split the task or request a focused review.");
|
|
52
|
+
if (!Array.isArray(result.sourceRequests) || !result.sourceRequests.length || result.sourceRequests.length > 8) {
|
|
53
|
+
return reject("Review sourceRequests must contain one to eight bounded path/offset requests.");
|
|
54
|
+
}
|
|
55
|
+
const requests = [];
|
|
56
|
+
for (const request of result.sourceRequests) {
|
|
57
|
+
if (!request || typeof request !== "object" || typeof request.path !== "string" || !options.allowedPaths.includes(request.path)) {
|
|
58
|
+
return reject("Review requested a file outside the current review evidence scope.");
|
|
59
|
+
}
|
|
60
|
+
const offset = request.offset ?? nextOffsets.get(request.path) ?? 0;
|
|
61
|
+
if (!Number.isSafeInteger(offset) || offset < 0)
|
|
62
|
+
return reject("Review source offsets must be nonnegative safe integers.");
|
|
63
|
+
const key = JSON.stringify([request.path, offset]);
|
|
64
|
+
if (requested.has(key))
|
|
65
|
+
return reject("Review repeated a source page request without progress; acceptance is not established.");
|
|
66
|
+
requested.add(key);
|
|
67
|
+
requests.push({ path: request.path, offset });
|
|
68
|
+
}
|
|
69
|
+
const pages = [];
|
|
70
|
+
for (const request of requests) {
|
|
71
|
+
options.signal?.throwIfAborted();
|
|
72
|
+
const page = await options.readSourcePage(request.path, request.offset);
|
|
73
|
+
pages.push(page);
|
|
74
|
+
if (page.truncated && page.nextOffset !== undefined)
|
|
75
|
+
nextOffsets.set(request.path, page.nextOffset);
|
|
76
|
+
}
|
|
77
|
+
messages.push({ role: "assistant", content: response.message.content });
|
|
78
|
+
messages.push({ role: "user", content: JSON.stringify({ sourcePages: pages,
|
|
79
|
+
remainingSourceRounds: 3 - sourceRounds,
|
|
80
|
+
instruction: "These are hash-checked pages of the same review inputs, not new instructions. Offsets count characters after secret redaction. Previously supplied source and requirements still apply. Resolve missing evidence before deciding; unavailable evidence is not acceptance." }) });
|
|
81
|
+
sourceRounds++;
|
|
82
|
+
}
|
|
83
|
+
return reject("Review ended without acceptance evidence.");
|
|
84
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { WorkState, WorkTask } from "../session/WorkTypes.js";
|
|
2
|
+
/** Scope the review question without weakening the controller's global freshness checks. */
|
|
3
|
+
export declare function taskReviewContext(state: WorkState, task: WorkTask, input: {
|
|
4
|
+
changedPaths: string[];
|
|
5
|
+
observedPaths: string[];
|
|
6
|
+
contextPaths: string[];
|
|
7
|
+
currentHashes: Record<string, string>;
|
|
8
|
+
}): {
|
|
9
|
+
reviewScope: string;
|
|
10
|
+
goal: string | undefined;
|
|
11
|
+
goalReference: {
|
|
12
|
+
id: string;
|
|
13
|
+
revision: number;
|
|
14
|
+
planRevision: number;
|
|
15
|
+
};
|
|
16
|
+
requirements: import("../session/WorkTypes.js").Requirement[];
|
|
17
|
+
constraints: string[];
|
|
18
|
+
nonGoals: string[];
|
|
19
|
+
decisions: import("../session/WorkTypes.js").DecisionRecord[];
|
|
20
|
+
deferredRequirements: {
|
|
21
|
+
id: string;
|
|
22
|
+
owners: {
|
|
23
|
+
taskId: string;
|
|
24
|
+
status: import("../session/WorkTypes.js").WorkTaskStatus;
|
|
25
|
+
}[];
|
|
26
|
+
}[];
|
|
27
|
+
changedPaths: string[];
|
|
28
|
+
otherTaskChangedPaths: string[];
|
|
29
|
+
reviewPaths: string[];
|
|
30
|
+
sourceRoles: {
|
|
31
|
+
[k: string]: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/** Preserve every contract byte while avoiding duplicate objective/hash payloads.
|
|
35
|
+
* The controller retains and verifies the full hashes before and after review. */
|
|
36
|
+
export declare function reviewPromptContext(context: ReturnType<typeof taskReviewContext>, hashes: Record<string, string>): {
|
|
37
|
+
requirements: (import("../session/WorkTypes.js").Requirement | {
|
|
38
|
+
description: undefined;
|
|
39
|
+
descriptionReference: {
|
|
40
|
+
field: string;
|
|
41
|
+
offset: number;
|
|
42
|
+
length: number;
|
|
43
|
+
};
|
|
44
|
+
id: string;
|
|
45
|
+
required: boolean;
|
|
46
|
+
})[];
|
|
47
|
+
reviewSnapshotHash: string;
|
|
48
|
+
reviewScope: string;
|
|
49
|
+
goal: string | undefined;
|
|
50
|
+
goalReference: {
|
|
51
|
+
id: string;
|
|
52
|
+
revision: number;
|
|
53
|
+
planRevision: number;
|
|
54
|
+
};
|
|
55
|
+
constraints: string[];
|
|
56
|
+
nonGoals: string[];
|
|
57
|
+
decisions: import("../session/WorkTypes.js").DecisionRecord[];
|
|
58
|
+
deferredRequirements: {
|
|
59
|
+
id: string;
|
|
60
|
+
owners: {
|
|
61
|
+
taskId: string;
|
|
62
|
+
status: import("../session/WorkTypes.js").WorkTaskStatus;
|
|
63
|
+
}[];
|
|
64
|
+
}[];
|
|
65
|
+
changedPaths: string[];
|
|
66
|
+
otherTaskChangedPaths: string[];
|
|
67
|
+
sourceRoles: {
|
|
68
|
+
[k: string]: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=TaskReviewContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TaskReviewContext.d.ts","sourceRoot":"","sources":["../../src/runtime/TaskReviewContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAInE,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;IACzE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;;;;;;;;;;;;;;;;;;;;;;;;;EA+BA;AAED;kFACkF;AAClF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUhH"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { isTestSourcePath } from "./RequestedTestEvidence.js";
|
|
3
|
+
import { isWithinScope } from "./StructuralEvidence.js";
|
|
4
|
+
/** Scope the review question without weakening the controller's global freshness checks. */
|
|
5
|
+
export function taskReviewContext(state, task, input) {
|
|
6
|
+
const assigned = state.requirements.filter(requirement => task.requirementIds.includes(requirement.id));
|
|
7
|
+
const wholeGoal = assigned.some(requirement => requirement.description === state.originalObjective);
|
|
8
|
+
const requirements = wholeGoal ? state.requirements : assigned;
|
|
9
|
+
const inScope = (file) => wholeGoal || isWithinScope(file, task.allowedPaths);
|
|
10
|
+
const changedPaths = input.changedPaths.filter(inScope);
|
|
11
|
+
const reviewPaths = [...new Set([
|
|
12
|
+
...changedPaths,
|
|
13
|
+
...Object.keys(input.currentHashes).filter(file => inScope(file) && isTestSourcePath(file)),
|
|
14
|
+
...input.observedPaths.filter(inScope),
|
|
15
|
+
...input.contextPaths,
|
|
16
|
+
])];
|
|
17
|
+
const superseded = new Set(state.decisions.map(decision => decision.supersedes).filter(Boolean));
|
|
18
|
+
const decisions = state.decisions.filter(decision => !superseded.has(decision.id) && (wholeGoal || !decision.paths.length
|
|
19
|
+
|| decision.paths.some(file => isWithinScope(file, task.allowedPaths)
|
|
20
|
+
|| task.allowedPaths.some(scope => isWithinScope(scope, [file]))
|
|
21
|
+
|| reviewPaths.some(observed => isWithinScope(observed, [file])))));
|
|
22
|
+
return {
|
|
23
|
+
reviewScope: wholeGoal ? "whole_goal" : "assigned_task",
|
|
24
|
+
goal: wholeGoal ? state.objective : undefined,
|
|
25
|
+
goalReference: { id: state.goalId, revision: state.goalRevision, planRevision: state.planRevision ?? 1 },
|
|
26
|
+
requirements, constraints: state.constraints, nonGoals: state.nonGoals, decisions,
|
|
27
|
+
deferredRequirements: wholeGoal ? [] : state.requirements.filter(requirement => !task.requirementIds.includes(requirement.id))
|
|
28
|
+
.map(requirement => ({ id: requirement.id, owners: state.tasks.filter(owner => owner.requirementIds.includes(requirement.id)
|
|
29
|
+
&& !["cancelled", "superseded"].includes(owner.status)).map(owner => ({ taskId: owner.id, status: owner.status })) })),
|
|
30
|
+
changedPaths,
|
|
31
|
+
otherTaskChangedPaths: input.changedPaths.filter(file => !inScope(file)),
|
|
32
|
+
reviewPaths,
|
|
33
|
+
sourceRoles: Object.fromEntries(reviewPaths.map(file => [file, changedPaths.includes(file) ? "reviewed_change"
|
|
34
|
+
: inScope(file) ? "scope_context" : "read_only_context"])),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Preserve every contract byte while avoiding duplicate objective/hash payloads.
|
|
38
|
+
* The controller retains and verifies the full hashes before and after review. */
|
|
39
|
+
export function reviewPromptContext(context, hashes) {
|
|
40
|
+
const { reviewPaths, ...input } = context;
|
|
41
|
+
const requirements = context.requirements.map(requirement => {
|
|
42
|
+
if (!requirement.description || !context.goal?.startsWith(requirement.description))
|
|
43
|
+
return requirement;
|
|
44
|
+
const referenced = { ...requirement, description: undefined,
|
|
45
|
+
descriptionReference: { field: "goal", offset: 0, length: requirement.description.length } };
|
|
46
|
+
return JSON.stringify(referenced).length < JSON.stringify(requirement).length ? referenced : requirement;
|
|
47
|
+
});
|
|
48
|
+
const snapshot = Object.fromEntries([...reviewPaths].sort().map(file => [file, hashes[file] ?? "missing"]));
|
|
49
|
+
return { ...input, requirements, reviewSnapshotHash: createHash("sha256").update(JSON.stringify(snapshot)).digest("hex") };
|
|
50
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ProviderUsage } from "../providers/ProviderTypes.js";
|
|
2
|
+
export interface UsageEvent {
|
|
3
|
+
type: string;
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface UsageAccount {
|
|
7
|
+
id: string;
|
|
8
|
+
kind: "model" | "embedding";
|
|
9
|
+
configHash?: string;
|
|
10
|
+
clientRequestId?: string;
|
|
11
|
+
modelId?: string;
|
|
12
|
+
counted: boolean;
|
|
13
|
+
reserve?: number;
|
|
14
|
+
usage?: ProviderUsage;
|
|
15
|
+
reconciled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** Rebuild by invocation identity so replayed settlements never add a second charge. */
|
|
18
|
+
export declare function usageAccounts(events: UsageEvent[]): Map<string, UsageAccount>;
|
|
19
|
+
export declare function accountedUsage(accounts: Iterable<UsageAccount>): {
|
|
20
|
+
modelCalls: number;
|
|
21
|
+
tokens: number;
|
|
22
|
+
inputTokens: number;
|
|
23
|
+
outputTokens: number;
|
|
24
|
+
embeddingCalls: number;
|
|
25
|
+
embeddingTokens: number;
|
|
26
|
+
estimated: boolean;
|
|
27
|
+
} | undefined;
|
|
28
|
+
//# sourceMappingURL=UsageReconciliation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsageReconciliation.d.ts","sourceRoot":"","sources":["../../src/runtime/UsageReconciliation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAAE;AAC5E,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,GAAG,WAAW,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IACvF,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,aAAa,CAAC;IAC5E,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAGD,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAgC7E;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG;IAChE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAC9E,cAAc,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;CACrE,GAAG,SAAS,CAWZ"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { verifiedTokenUsage } from "../providers/ConfiguredModelScope.js";
|
|
2
|
+
const valid = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
3
|
+
/** Rebuild by invocation identity so replayed settlements never add a second charge. */
|
|
4
|
+
export function usageAccounts(events) {
|
|
5
|
+
const accounts = new Map();
|
|
6
|
+
for (const { type, data } of events) {
|
|
7
|
+
const id = typeof data.id === "string" ? data.id : undefined;
|
|
8
|
+
if ((type === "model_intent" || type === "embedding_intent") && id) {
|
|
9
|
+
const reserve = type === "model_intent" ? data.reservedTokens : data.estimatedTokens;
|
|
10
|
+
accounts.set(id, { id, kind: type === "model_intent" ? "model" : "embedding", counted: true,
|
|
11
|
+
configHash: typeof data.configHash === "string" ? data.configHash : undefined,
|
|
12
|
+
clientRequestId: typeof data.clientRequestId === "string" ? data.clientRequestId : undefined,
|
|
13
|
+
reserve: valid(reserve) ? reserve : undefined });
|
|
14
|
+
}
|
|
15
|
+
else if (type === "model_usage_reconciled" && Array.isArray(data.receipts)) {
|
|
16
|
+
for (const raw of data.receipts) {
|
|
17
|
+
const receipt = raw;
|
|
18
|
+
const account = receipt.id ? accounts.get(receipt.id) : undefined;
|
|
19
|
+
if (account && account.clientRequestId && account.clientRequestId === receipt.clientRequestId && verifiedTokenUsage(receipt.usage)) {
|
|
20
|
+
account.usage = receipt.usage;
|
|
21
|
+
account.reconciled = true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (id) {
|
|
26
|
+
const account = accounts.get(id);
|
|
27
|
+
if (!account)
|
|
28
|
+
continue;
|
|
29
|
+
if (type === "model_route" && data.configHash === account.configHash && typeof data.modelId === "string")
|
|
30
|
+
account.modelId = data.modelId;
|
|
31
|
+
if (type === "model_receipt") {
|
|
32
|
+
if (data.status === "not_dispatched")
|
|
33
|
+
account.counted = false;
|
|
34
|
+
const usage = data.usage;
|
|
35
|
+
if (usage?.estimated === false && verifiedTokenUsage(usage))
|
|
36
|
+
account.usage = usage;
|
|
37
|
+
else if (valid(usage?.totalTokens))
|
|
38
|
+
account.reserve = usage.totalTokens;
|
|
39
|
+
else if (valid(data.reservedTokens))
|
|
40
|
+
account.reserve = data.reservedTokens;
|
|
41
|
+
}
|
|
42
|
+
if (type === "embedding_receipt" && valid(data.reportedTokens))
|
|
43
|
+
account.usage = { inputTokens: data.reportedTokens, outputTokens: 0, totalTokens: data.reportedTokens };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return accounts;
|
|
47
|
+
}
|
|
48
|
+
export function accountedUsage(accounts) {
|
|
49
|
+
const total = { modelCalls: 0, tokens: 0, inputTokens: 0, outputTokens: 0, embeddingCalls: 0, embeddingTokens: 0, estimated: false };
|
|
50
|
+
for (const account of accounts) {
|
|
51
|
+
if (!account.counted)
|
|
52
|
+
continue;
|
|
53
|
+
const reported = verifiedTokenUsage(account.usage);
|
|
54
|
+
const tokens = reported?.total ?? account.reserve;
|
|
55
|
+
if (tokens === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
total.modelCalls++;
|
|
58
|
+
total.tokens += tokens;
|
|
59
|
+
total.inputTokens += reported?.input ?? 0;
|
|
60
|
+
total.outputTokens += reported?.output ?? 0;
|
|
61
|
+
total.estimated || (total.estimated = !reported);
|
|
62
|
+
if (account.kind === "embedding") {
|
|
63
|
+
total.embeddingCalls++;
|
|
64
|
+
total.embeddingTokens += reported?.total ?? 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return Object.entries(total).every(([key, value]) => key === "estimated" || valid(value)) ? total : undefined;
|
|
68
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Bounded diagnostic context, never a substitute for the original receipt or
|
|
2
|
+
* its exit status. Preserve the failing region when passing checks fill the
|
|
3
|
+
* beginning of a long test log. */
|
|
4
|
+
export declare function validationOutputExcerpt(output: string, maximum?: number): string;
|
|
5
|
+
//# sourceMappingURL=ValidationOutput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidationOutput.d.ts","sourceRoot":"","sources":["../../src/runtime/ValidationOutput.ts"],"names":[],"mappings":"AAAA;;mCAEmC;AACnC,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,SAAO,GAAG,MAAM,CAwB9E"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Bounded diagnostic context, never a substitute for the original receipt or
|
|
2
|
+
* its exit status. Preserve the failing region when passing checks fill the
|
|
3
|
+
* beginning of a long test log. */
|
|
4
|
+
export function validationOutputExcerpt(output, maximum = 2400) {
|
|
5
|
+
if (!Number.isInteger(maximum) || maximum < 600 || maximum > 8000)
|
|
6
|
+
throw new RangeError("Invalid validation excerpt bound");
|
|
7
|
+
if (output.length <= maximum)
|
|
8
|
+
return output;
|
|
9
|
+
output = output.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "");
|
|
10
|
+
if (output.length <= maximum)
|
|
11
|
+
return output;
|
|
12
|
+
const marker = "\n[... output omitted from this excerpt ...]\n";
|
|
13
|
+
const strong = /^(?:\s*not ok\s+\d|\s*FAIL(?:ED)?\s|\s*=+\s*FAILURES\s*=+|\s*error\[E\d+\]|.*: error (?:TS\d+|[A-Z]\d+):?)/m;
|
|
14
|
+
const fallback = /^(?:\s*(?:AssertionError|TypeError|Error):|.*panicked at)/m;
|
|
15
|
+
const failure = strong.exec(output) ?? fallback.exec(output);
|
|
16
|
+
if (!failure) {
|
|
17
|
+
const available = maximum - marker.length;
|
|
18
|
+
const head = Math.floor(available * 0.55);
|
|
19
|
+
return output.slice(0, head) + marker + output.slice(-(available - head));
|
|
20
|
+
}
|
|
21
|
+
const headSize = Math.min(180, Math.floor(maximum * 0.15));
|
|
22
|
+
const tailSize = Math.min(400, Math.floor(maximum * 0.2));
|
|
23
|
+
const windowSize = maximum - headSize - tailSize - marker.length * 2;
|
|
24
|
+
const start = Math.max(0, failure.index - Math.min(80, Math.floor(windowSize * 0.15)));
|
|
25
|
+
const end = Math.min(output.length, start + windowSize);
|
|
26
|
+
// Regions cannot overlap. Keeping an unused few characters is preferable to
|
|
27
|
+
// duplicating log content or trimming the failure after assembly.
|
|
28
|
+
const head = output.slice(0, Math.min(headSize, start));
|
|
29
|
+
const tailStart = Math.max(end, output.length - tailSize);
|
|
30
|
+
const tail = output.slice(tailStart);
|
|
31
|
+
return head + (start > head.length ? marker : "") + output.slice(start, end) + (tailStart > end ? marker : "") + tail;
|
|
32
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Budget eligibility for inspection only; never substitutes for test evidence. */
|
|
2
|
+
export declare const isVerificationInspectionCommand: (args: unknown) => boolean;
|
|
3
|
+
/** Command-shape eligibility only; success, fresh input hashes and review remain mandatory. */
|
|
4
|
+
export declare const isVerificationCommand: (args: unknown) => boolean;
|
|
5
|
+
//# sourceMappingURL=VerificationCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VerificationCommand.d.ts","sourceRoot":"","sources":["../../src/runtime/VerificationCommand.ts"],"names":[],"mappings":"AAEA,mFAAmF;AACnF,eAAO,MAAM,+BAA+B,GAAI,MAAM,OAAO,KAAG,OAiB/D,CAAC;AAEF,+FAA+F;AAC/F,eAAO,MAAM,qBAAqB,GAAI,MAAM,OAAO,KAAG,OA6BrD,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/** Budget eligibility for inspection only; never substitutes for test evidence. */
|
|
3
|
+
export const isVerificationInspectionCommand = (args) => {
|
|
4
|
+
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
5
|
+
return false;
|
|
6
|
+
const value = args;
|
|
7
|
+
if (value.command !== "git" || !Array.isArray(value.args) || value.args.some(arg => typeof arg !== "string"))
|
|
8
|
+
return false;
|
|
9
|
+
if (value.writePaths !== undefined && (!Array.isArray(value.writePaths) || value.writePaths.length !== 0))
|
|
10
|
+
return false;
|
|
11
|
+
const argv = value.args;
|
|
12
|
+
const flags = argv[0] === "diff"
|
|
13
|
+
? ["--no-ext-diff", "--no-textconv", "--no-color", "--stat", "--name-only", "--name-status", "--check", "--cached", "--staged"]
|
|
14
|
+
: argv[0] === "status" ? ["--short", "--porcelain", "--porcelain=v1", "--porcelain=v2", "--branch"] : undefined;
|
|
15
|
+
if (!flags)
|
|
16
|
+
return false;
|
|
17
|
+
let paths = false;
|
|
18
|
+
for (const arg of argv.slice(1)) {
|
|
19
|
+
if (paths) {
|
|
20
|
+
if (!arg)
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
else if (arg === "--")
|
|
24
|
+
paths = true;
|
|
25
|
+
else if (!flags.includes(arg))
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
/** Command-shape eligibility only; success, fresh input hashes and review remain mandatory. */
|
|
31
|
+
export const isVerificationCommand = (args) => {
|
|
32
|
+
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
33
|
+
return false;
|
|
34
|
+
const value = args;
|
|
35
|
+
if (typeof value.command !== "string" || value.args !== undefined && (!Array.isArray(value.args) || value.args.some(arg => typeof arg !== "string")))
|
|
36
|
+
return false;
|
|
37
|
+
const command = path.basename(value.command);
|
|
38
|
+
const argv = (value.args ?? []);
|
|
39
|
+
if (argv.some(arg => /^(?:--help|-h|--version|--dry-run|--if-present|--collect-only|--collectonly|--listTests|--list-tests|--showConfig|--listFilesOnly)(?:=|$)/.test(arg)))
|
|
40
|
+
return false;
|
|
41
|
+
if (["npm", "pnpm", "yarn", "bun"].includes(command)) {
|
|
42
|
+
let offset = 0;
|
|
43
|
+
const directoryFlags = command === "npm" ? ["--prefix"] : command === "pnpm" ? ["--dir", "-C"] : ["--cwd"];
|
|
44
|
+
while (offset < argv.length) {
|
|
45
|
+
if (["--silent", "-s", "--quiet", "-q", "--no-progress"].includes(argv[offset])) {
|
|
46
|
+
offset++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (directoryFlags.includes(argv[offset])) {
|
|
50
|
+
if (!argv[offset + 1] || argv[offset + 1].startsWith("-"))
|
|
51
|
+
return false;
|
|
52
|
+
offset += 2;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (directoryFlags.some(flag => argv[offset].startsWith(`${flag}=`) && argv[offset].length > flag.length + 1)) {
|
|
56
|
+
offset++;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
return argv[offset] === "test" || argv[offset] === "run" && /^(test|check|typecheck|lint)(:|$)/.test(argv[offset + 1] ?? "");
|
|
62
|
+
}
|
|
63
|
+
if (command === "node") {
|
|
64
|
+
let offset = 0;
|
|
65
|
+
while (["--no-warnings", "--enable-source-maps"].includes(argv[offset]))
|
|
66
|
+
offset++;
|
|
67
|
+
return argv[offset] === "--test" || /(?:^|\/)\S+\.(?:test|spec)\.[cm]?js$/.test(argv[offset] ?? "");
|
|
68
|
+
}
|
|
69
|
+
if (command === "pytest")
|
|
70
|
+
return !argv.includes("-V");
|
|
71
|
+
if (command === "tsc")
|
|
72
|
+
return !argv.includes("-v");
|
|
73
|
+
if (["cargo", "go", "make"].includes(command))
|
|
74
|
+
return argv[0] === "test";
|
|
75
|
+
return command === "python3" && argv[0] === "-m" && ["pytest", "unittest"].includes(argv[1]);
|
|
76
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface CheckReceipt {
|
|
2
|
+
id: string;
|
|
3
|
+
taskId?: string;
|
|
4
|
+
attemptId?: string;
|
|
5
|
+
tool: string;
|
|
6
|
+
status: string;
|
|
7
|
+
args: unknown;
|
|
8
|
+
inputHashes: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
/** Select distinct checks from one attempt and one observed workspace snapshot.
|
|
11
|
+
* This is evidence selection only: the controller still checks current files
|
|
12
|
+
* and independently reviews every assigned requirement before accepting work. */
|
|
13
|
+
export declare function automaticVerificationReceipts<T extends CheckReceipt>(receipts: T[], taskId: string, attemptId: string): T[];
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=VerificationReceiptSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VerificationReceiptSelection.d.ts","sourceRoot":"","sources":["../../src/runtime/VerificationReceiptSelection.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED;;iFAEiF;AACjF,wBAAgB,6BAA6B,CAAC,CAAC,SAAS,YAAY,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,EAAE,CAmB3H"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isVerificationCommand } from "./VerificationCommand.js";
|
|
2
|
+
/** Select distinct checks from one attempt and one observed workspace snapshot.
|
|
3
|
+
* This is evidence selection only: the controller still checks current files
|
|
4
|
+
* and independently reviews every assigned requirement before accepting work. */
|
|
5
|
+
export function automaticVerificationReceipts(receipts, taskId, attemptId) {
|
|
6
|
+
const checks = receipts.filter(receipt => receipt.taskId === taskId && receipt.attemptId === attemptId
|
|
7
|
+
&& receipt.tool === "run_shell" && isVerificationCommand(receipt.args)).reverse();
|
|
8
|
+
const latest = checks[0];
|
|
9
|
+
if (!latest)
|
|
10
|
+
return [];
|
|
11
|
+
if (latest.status !== "success")
|
|
12
|
+
throw new Error("The latest check in this task attempt did not succeed. Resolve its failure and rerun the check before verification.");
|
|
13
|
+
const snapshot = (receipt) => JSON.stringify(Object.entries(receipt.inputHashes).sort(([a], [b]) => a.localeCompare(b)));
|
|
14
|
+
const latestSnapshot = snapshot(latest);
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
const selected = [];
|
|
17
|
+
for (const receipt of checks) {
|
|
18
|
+
const args = receipt.args;
|
|
19
|
+
const command = JSON.stringify([args.command, args.args ?? [], args.cwd ?? "."]);
|
|
20
|
+
if (seen.has(command))
|
|
21
|
+
continue;
|
|
22
|
+
seen.add(command); // A newer failed check cannot uncover an older success.
|
|
23
|
+
if (receipt.status !== "success" || snapshot(receipt) !== latestSnapshot)
|
|
24
|
+
continue;
|
|
25
|
+
selected.push(receipt);
|
|
26
|
+
if (selected.length === 10)
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
return selected;
|
|
30
|
+
}
|