@caupulican/pi-adaptative 0.86.17 → 0.90.2
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 +43 -0
- package/README.md +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -15
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -16
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +4 -4
- package/dist/core/agent-session.d.ts +23 -33
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +81 -110
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +16 -0
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.d.ts +2 -1
- package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
- package/dist/core/autonomy/subagent-prompt.js +2 -18
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-tool-task-controller.js +5 -5
- package/dist/core/background-tool-task-controller.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +22 -2
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +75 -39
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/context/brain-curator.d.ts +2 -3
- package/dist/core/context/brain-curator.d.ts.map +1 -1
- package/dist/core/context/brain-curator.js +3 -20
- package/dist/core/context/brain-curator.js.map +1 -1
- package/dist/core/context/context-composition.d.ts +2 -1
- package/dist/core/context/context-composition.d.ts.map +1 -1
- package/dist/core/context/context-composition.js +6 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/memory-prompt-block.js +1 -1
- package/dist/core/context/memory-prompt-block.js.map +1 -1
- package/dist/core/context/tool-output-packer.js +1 -1
- package/dist/core/context/tool-output-packer.js.map +1 -1
- package/dist/core/context-gc.js +10 -10
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +4 -4
- package/dist/core/context-pipeline.js +4 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -2
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts +2 -2
- package/dist/core/delegation/session-worker-claim.js +2 -2
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-resource-materializer.js +3 -3
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +2 -13
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +5 -67
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/extensions/builtin.js +4 -4
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +6 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +21 -9
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +9 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +2 -2
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +13 -9
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +1 -1
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +6 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +16 -13
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/human-input-controller.js +1 -1
- package/dist/core/human-input-controller.js.map +1 -1
- package/dist/core/improvement-loop.js +13 -13
- package/dist/core/improvement-loop.js.map +1 -1
- package/dist/core/learning/reflection-engine.d.ts +2 -1
- package/dist/core/learning/reflection-engine.d.ts.map +1 -1
- package/dist/core/learning/reflection-engine.js +4 -24
- package/dist/core/learning/reflection-engine.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -1
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-router/route-judge.d.ts +2 -1
- package/dist/core/model-router/route-judge.d.ts.map +1 -1
- package/dist/core/model-router/route-judge.js +4 -12
- package/dist/core/model-router/route-judge.js.map +1 -1
- package/dist/core/models/perf-profile.d.ts +1 -1
- package/dist/core/models/perf-profile.d.ts.map +1 -1
- package/dist/core/models/perf-profile.js +2 -8
- package/dist/core/models/perf-profile.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +1 -6
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.js +3 -3
- package/dist/core/process-matrix/resume-launcher.js.map +1 -1
- package/dist/core/process-matrix/runtime.d.ts +2 -0
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +23 -19
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/provider-prompt-contracts.d.ts +34 -0
- package/dist/core/provider-prompt-contracts.d.ts.map +1 -0
- package/dist/core/provider-prompt-contracts.js +133 -0
- package/dist/core/provider-prompt-contracts.js.map +1 -0
- package/dist/core/provider-request-context-controller.d.ts +40 -0
- package/dist/core/provider-request-context-controller.d.ts.map +1 -0
- package/dist/core/provider-request-context-controller.js +68 -0
- package/dist/core/provider-request-context-controller.js.map +1 -0
- package/dist/core/provider-request-runtime-controller.d.ts +22 -0
- package/dist/core/provider-request-runtime-controller.d.ts.map +1 -0
- package/dist/core/provider-request-runtime-controller.js +87 -0
- package/dist/core/provider-request-runtime-controller.js.map +1 -0
- package/dist/core/provider-tool-text.d.ts +7 -0
- package/dist/core/provider-tool-text.d.ts.map +1 -0
- package/dist/core/provider-tool-text.js +42 -0
- package/dist/core/provider-tool-text.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +2 -5
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +2 -20
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-runner.d.ts +2 -1
- package/dist/core/research/research-runner.d.ts.map +1 -1
- package/dist/core/research/research-runner.js +6 -21
- package/dist/core/research/research-runner.js.map +1 -1
- package/dist/core/risk-classifier.d.ts.map +1 -1
- package/dist/core/risk-classifier.js +9 -1
- package/dist/core/risk-classifier.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +3 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +20 -25
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/scout-controller.d.ts +2 -1
- package/dist/core/scout-controller.d.ts.map +1 -1
- package/dist/core/scout-controller.js +2 -16
- package/dist/core/scout-controller.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +6 -6
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/secrets/credential-manager.d.ts +11 -1
- package/dist/core/secrets/credential-manager.d.ts.map +1 -1
- package/dist/core/secrets/credential-manager.js +28 -7
- package/dist/core/secrets/credential-manager.js.map +1 -1
- package/dist/core/secrets/credential-migration-source.d.ts +20 -0
- package/dist/core/secrets/credential-migration-source.d.ts.map +1 -0
- package/dist/core/secrets/credential-migration-source.js +113 -0
- package/dist/core/secrets/credential-migration-source.js.map +1 -0
- package/dist/core/secrets/credential-session-connection.d.ts +9 -0
- package/dist/core/secrets/credential-session-connection.d.ts.map +1 -0
- package/dist/core/secrets/credential-session-connection.js +39 -0
- package/dist/core/secrets/credential-session-connection.js.map +1 -0
- package/dist/core/security/untrusted-boundary.d.ts +2 -2
- package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
- package/dist/core/security/untrusted-boundary.js +3 -10
- package/dist/core/security/untrusted-boundary.js.map +1 -1
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +1 -2
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/skill-vault.d.ts +98 -0
- package/dist/core/skill-vault.d.ts.map +1 -0
- package/dist/core/skill-vault.js +270 -0
- package/dist/core/skill-vault.js.map +1 -0
- package/dist/core/skills.d.ts +10 -9
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +42 -50
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt-builder.d.ts +1 -1
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +20 -60
- package/dist/core/system-prompt-builder.js.map +1 -1
- package/dist/core/system-prompt.d.ts +4 -4
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +87 -121
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +6 -7
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +2 -1
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts.map +1 -1
- package/dist/core/tool-protocol-controller.js +4 -7
- package/dist/core/tool-protocol-controller.js.map +1 -1
- package/dist/core/tool-selection/promotion.d.ts.map +1 -1
- package/dist/core/tool-selection/promotion.js +2 -6
- package/dist/core/tool-selection/promotion.js.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts +2 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.js +2 -14
- package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
- package/dist/core/tools/ask-question.js +6 -6
- package/dist/core/tools/ask-question.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +8 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +17 -13
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +111 -226
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +29 -2
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +149 -48
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit.js +3 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/extensionify-runtime.js +4 -4
- package/dist/core/tools/extensionify-runtime.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +2 -4
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/goal.js +3 -3
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/grep.js +2 -2
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/model-fitness.js +4 -4
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +30 -16
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +98 -59
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/python.js +6 -6
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/run-process.js +4 -4
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/run-toolkit-script.js +4 -4
- package/dist/core/tools/run-toolkit-script.js.map +1 -1
- package/dist/core/tools/secret-store.d.ts +32 -3
- package/dist/core/tools/secret-store.d.ts.map +1 -1
- package/dist/core/tools/secret-store.js +141 -34
- package/dist/core/tools/secret-store.js.map +1 -1
- package/dist/core/tools/skill.d.ts +29 -0
- package/dist/core/tools/skill.d.ts.map +1 -0
- package/dist/core/tools/skill.js +79 -0
- package/dist/core/tools/skill.js.map +1 -0
- package/dist/core/tools/task-steps.js +4 -4
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/tool-task.d.ts.map +1 -1
- package/dist/core/tools/tool-task.js +4 -0
- package/dist/core/tools/tool-task.js.map +1 -1
- package/dist/core/tools/worktree-sync.js +6 -6
- package/dist/core/tools/worktree-sync.js.map +1 -1
- package/dist/core/tools/write.js +3 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +1 -1
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/report-commands.js +1 -1
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.js +2 -18
- package/dist/modes/interactive/secret-menu-controller.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +1 -1
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/docs/compaction.md +45 -25
- package/docs/extensions.md +23 -7
- package/docs/settings.md +3 -3
- package/docs/skills.md +14 -10
- package/docs/task-steps.md +2 -2
- package/docs/tmux-agent-manager.md +1 -1
- package/docs/tool-repair.md +18 -1
- package/docs/usage.md +4 -2
- package/docs/worker-profiles.md +3 -3
- package/docs/worktree-sync.md +2 -2
- package/examples/extensions/custom-compaction.ts +5 -17
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +3 -5
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/04-skills.ts +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
- package/dist/core/util/json-size.d.ts +0 -3
- package/dist/core/util/json-size.d.ts.map +0 -1
- package/dist/core/util/json-size.js +0 -95
- package/dist/core/util/json-size.js.map +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { injectCompactGoalContext } from "./goals/compact-goal-context.js";
|
|
3
|
+
/** Coordinates replay-safe request context planning and accepted-plan lifecycle commit. */
|
|
4
|
+
export class ProviderRequestContextController {
|
|
5
|
+
constructor(deps) {
|
|
6
|
+
this.deps = deps;
|
|
7
|
+
}
|
|
8
|
+
async plan(messages, signal) {
|
|
9
|
+
const transformed = this.deps.transformBase ? await this.deps.transformBase(messages, signal) : messages;
|
|
10
|
+
const extensionPlan = await this.deps.transformExtensions(transformed);
|
|
11
|
+
const durableMessages = injectCompactGoalContext(extensionPlan.messages, undefined);
|
|
12
|
+
const extensionMessages = [...durableMessages, ...extensionPlan.transientMessages];
|
|
13
|
+
const auditReport = this.deps.runContextAudit(extensionMessages);
|
|
14
|
+
const shadowReport = this.deps.runPromptPolicyPlanning(auditReport);
|
|
15
|
+
const memoryReport = await this.deps.runMemoryRetrieval(extensionMessages);
|
|
16
|
+
const previewGc = this.deps.applyContextGc(durableMessages, false);
|
|
17
|
+
const previewProviderMessages = [...previewGc.messages, ...extensionPlan.transientMessages];
|
|
18
|
+
const previewEnforcement = this.deps.runPromptEnforcement(previewProviderMessages, shadowReport);
|
|
19
|
+
if (previewEnforcement.messages.length !== previewProviderMessages.length) {
|
|
20
|
+
throw new Error("Provider request enforcement changed message cardinality");
|
|
21
|
+
}
|
|
22
|
+
const compactableMessages = previewEnforcement.messages.slice(0, previewGc.messages.length);
|
|
23
|
+
const goalState = this.deps.getGoalState();
|
|
24
|
+
const withExtensionTransients = previewEnforcement.messages.slice(previewGc.messages.length);
|
|
25
|
+
const withMemory = this.deps.appendMemoryEvidence([...compactableMessages, ...withExtensionTransients], memoryReport);
|
|
26
|
+
const beforeSkill = injectCompactGoalContext(withMemory, goalState);
|
|
27
|
+
const plannedMessages = this.deps.skillVault.previewContext(beforeSkill);
|
|
28
|
+
if (!isDeepStrictEqual(plannedMessages.slice(0, compactableMessages.length), compactableMessages)) {
|
|
29
|
+
throw new Error("Provider request transient contributors changed compactable history");
|
|
30
|
+
}
|
|
31
|
+
const transientMessages = plannedMessages.slice(compactableMessages.length);
|
|
32
|
+
const skillRevision = this.deps.skillVault.getContextRevision();
|
|
33
|
+
const dependenciesCurrent = () => extensionPlan.isCurrent?.() !== false &&
|
|
34
|
+
this.deps.skillVault.getContextRevision() === skillRevision &&
|
|
35
|
+
isDeepStrictEqual(this.deps.getGoalState(), goalState);
|
|
36
|
+
const projectCommit = (writePayloads) => {
|
|
37
|
+
const gc = this.deps.applyContextGc(durableMessages, writePayloads);
|
|
38
|
+
const providerMessages = [...gc.messages, ...extensionPlan.transientMessages];
|
|
39
|
+
const enforcement = this.deps.runPromptEnforcement(providerMessages, shadowReport);
|
|
40
|
+
return { enforcement, gc, providerMessages };
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
messages: compactableMessages,
|
|
44
|
+
transientMessages,
|
|
45
|
+
isCurrent: dependenciesCurrent,
|
|
46
|
+
prepareCommit: () => {
|
|
47
|
+
if (!dependenciesCurrent())
|
|
48
|
+
return false;
|
|
49
|
+
const projected = projectCommit(false);
|
|
50
|
+
return (isDeepStrictEqual(projected.enforcement.messages, previewEnforcement.messages) &&
|
|
51
|
+
isDeepStrictEqual(this.deps.skillVault.previewContext(beforeSkill), plannedMessages));
|
|
52
|
+
},
|
|
53
|
+
commit: () => {
|
|
54
|
+
const committed = projectCommit(true);
|
|
55
|
+
if (!isDeepStrictEqual(committed.enforcement.messages, previewEnforcement.messages)) {
|
|
56
|
+
throw new Error("Committed provider request context diverged from its accepted plan");
|
|
57
|
+
}
|
|
58
|
+
this.deps.correlatePromptPolicyWithContextGc(committed.gc.report);
|
|
59
|
+
this.deps.enqueueRelevanceCuration(committed.providerMessages, shadowReport);
|
|
60
|
+
this.deps.maybeDrainBrainCuration();
|
|
61
|
+
if (!isDeepStrictEqual(this.deps.skillVault.projectContext(beforeSkill), plannedMessages)) {
|
|
62
|
+
throw new Error("Committed active skill context diverged from its accepted plan");
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=provider-request-context-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-request-context-controller.js","sourceRoot":"","sources":["../../src/core/provider-request-context-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAO9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AA8B3E,2FAA2F;AAC3F,MAAM,OAAO,gCAAgC;IAG5C,YAAY,IAA0C;QACrD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAwB,EAAE,MAAoB;QACx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AAC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,eAAe,CAAC,EAAE,CAAC;oBAC3F,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;gBACnF,CAAC;YACF,CAAC;SACD,CAAC;IACH,CAAC;CACD","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport type { AgentContextPlan, AgentMessage } from \"@caupulican/pi-agent-core/types\";\nimport type { ContextAuditReport } from \"./context/context-audit.ts\";\nimport type { PromptEnforcementReport } from \"./context/context-prompt-enforcement.ts\";\nimport type { PromptPolicyShadowReport } from \"./context/context-prompt-policy.ts\";\nimport type { MemoryRetrievalReport } from \"./context/memory-retrieval.ts\";\nimport type { ContextGcReport } from \"./context-gc.ts\";\nimport { injectCompactGoalContext } from \"./goals/compact-goal-context.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { SkillVaultController } from \"./skill-vault.ts\";\n\nexport interface ProviderRequestContextControllerDeps {\n\ttransformBase?: (messages: AgentMessage[], signal?: AbortSignal) => Promise<AgentMessage[]>;\n\ttransformExtensions(messages: AgentMessage[]): Promise<{\n\t\tmessages: AgentMessage[];\n\t\ttransientMessages: AgentMessage[];\n\t\tisCurrent?(): boolean;\n\t}>;\n\trunContextAudit(messages: AgentMessage[]): ContextAuditReport;\n\trunPromptPolicyPlanning(report: ContextAuditReport): PromptPolicyShadowReport;\n\trunMemoryRetrieval(messages: AgentMessage[]): Promise<MemoryRetrievalReport>;\n\tapplyContextGc(\n\t\tmessages: AgentMessage[],\n\t\twritePayloads: boolean,\n\t): { messages: AgentMessage[]; report: ContextGcReport };\n\tcorrelatePromptPolicyWithContextGc(report: ContextGcReport): void;\n\trunPromptEnforcement(\n\t\tmessages: AgentMessage[],\n\t\treport: PromptPolicyShadowReport,\n\t): { messages: AgentMessage[]; report: PromptEnforcementReport };\n\tenqueueRelevanceCuration(messages: AgentMessage[], report: PromptPolicyShadowReport): void;\n\tmaybeDrainBrainCuration(): void;\n\tappendMemoryEvidence(messages: AgentMessage[], report: MemoryRetrievalReport): AgentMessage[];\n\tgetGoalState(): GoalState | undefined;\n\tskillVault: SkillVaultController;\n}\n\n/** Coordinates replay-safe request context planning and accepted-plan lifecycle commit. */\nexport class ProviderRequestContextController {\n\tprivate readonly deps: ProviderRequestContextControllerDeps;\n\n\tconstructor(deps: ProviderRequestContextControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tasync plan(messages: AgentMessage[], signal?: AbortSignal): Promise<AgentContextPlan> {\n\t\tconst transformed = this.deps.transformBase ? await this.deps.transformBase(messages, signal) : messages;\n\t\tconst extensionPlan = await this.deps.transformExtensions(transformed);\n\t\tconst durableMessages = injectCompactGoalContext(extensionPlan.messages, undefined);\n\t\tconst extensionMessages = [...durableMessages, ...extensionPlan.transientMessages];\n\t\tconst auditReport = this.deps.runContextAudit(extensionMessages);\n\t\tconst shadowReport = this.deps.runPromptPolicyPlanning(auditReport);\n\t\tconst memoryReport = await this.deps.runMemoryRetrieval(extensionMessages);\n\t\tconst previewGc = this.deps.applyContextGc(durableMessages, false);\n\t\tconst previewProviderMessages = [...previewGc.messages, ...extensionPlan.transientMessages];\n\t\tconst previewEnforcement = this.deps.runPromptEnforcement(previewProviderMessages, shadowReport);\n\t\tif (previewEnforcement.messages.length !== previewProviderMessages.length) {\n\t\t\tthrow new Error(\"Provider request enforcement changed message cardinality\");\n\t\t}\n\t\tconst compactableMessages = previewEnforcement.messages.slice(0, previewGc.messages.length);\n\t\tconst goalState = this.deps.getGoalState();\n\t\tconst withExtensionTransients = previewEnforcement.messages.slice(previewGc.messages.length);\n\t\tconst withMemory = this.deps.appendMemoryEvidence(\n\t\t\t[...compactableMessages, ...withExtensionTransients],\n\t\t\tmemoryReport,\n\t\t);\n\t\tconst beforeSkill = injectCompactGoalContext(withMemory, goalState);\n\t\tconst plannedMessages = this.deps.skillVault.previewContext(beforeSkill);\n\t\tif (!isDeepStrictEqual(plannedMessages.slice(0, compactableMessages.length), compactableMessages)) {\n\t\t\tthrow new Error(\"Provider request transient contributors changed compactable history\");\n\t\t}\n\t\tconst transientMessages = plannedMessages.slice(compactableMessages.length);\n\t\tconst skillRevision = this.deps.skillVault.getContextRevision();\n\t\tconst dependenciesCurrent = () =>\n\t\t\textensionPlan.isCurrent?.() !== false &&\n\t\t\tthis.deps.skillVault.getContextRevision() === skillRevision &&\n\t\t\tisDeepStrictEqual(this.deps.getGoalState(), goalState);\n\t\tconst projectCommit = (writePayloads: boolean) => {\n\t\t\tconst gc = this.deps.applyContextGc(durableMessages, writePayloads);\n\t\t\tconst providerMessages = [...gc.messages, ...extensionPlan.transientMessages];\n\t\t\tconst enforcement = this.deps.runPromptEnforcement(providerMessages, shadowReport);\n\t\t\treturn { enforcement, gc, providerMessages };\n\t\t};\n\n\t\treturn {\n\t\t\tmessages: compactableMessages,\n\t\t\ttransientMessages,\n\t\t\tisCurrent: dependenciesCurrent,\n\t\t\tprepareCommit: () => {\n\t\t\t\tif (!dependenciesCurrent()) return false;\n\t\t\t\tconst projected = projectCommit(false);\n\t\t\t\treturn (\n\t\t\t\t\tisDeepStrictEqual(projected.enforcement.messages, previewEnforcement.messages) &&\n\t\t\t\t\tisDeepStrictEqual(this.deps.skillVault.previewContext(beforeSkill), plannedMessages)\n\t\t\t\t);\n\t\t\t},\n\t\t\tcommit: () => {\n\t\t\t\tconst committed = projectCommit(true);\n\t\t\t\tif (!isDeepStrictEqual(committed.enforcement.messages, previewEnforcement.messages)) {\n\t\t\t\t\tthrow new Error(\"Committed provider request context diverged from its accepted plan\");\n\t\t\t\t}\n\t\t\t\tthis.deps.correlatePromptPolicyWithContextGc(committed.gc.report);\n\t\t\t\tthis.deps.enqueueRelevanceCuration(committed.providerMessages, shadowReport);\n\t\t\t\tthis.deps.maybeDrainBrainCuration();\n\t\t\t\tif (!isDeepStrictEqual(this.deps.skillVault.projectContext(beforeSkill), plannedMessages)) {\n\t\t\t\t\tthrow new Error(\"Committed active skill context diverged from its accepted plan\");\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Agent } from "@caupulican/pi-agent-core/agent";
|
|
2
|
+
import type { CompactionController } from "./compaction-controller.ts";
|
|
3
|
+
import type { ProviderRequestContextController } from "./provider-request-context-controller.ts";
|
|
4
|
+
export interface ProviderRequestRuntimeControllerDeps {
|
|
5
|
+
agent: Agent;
|
|
6
|
+
compaction: Pick<CompactionController, "admitProviderRequest">;
|
|
7
|
+
context: ProviderRequestContextController;
|
|
8
|
+
}
|
|
9
|
+
/** Installs and owns the one provider planning/admission hook generation on an Agent. */
|
|
10
|
+
export declare class ProviderRequestRuntimeController {
|
|
11
|
+
private readonly deps;
|
|
12
|
+
private previousTransformContext;
|
|
13
|
+
private previousPlanContext;
|
|
14
|
+
private previousAdmission;
|
|
15
|
+
private installedTransformContext;
|
|
16
|
+
private installedPlanContext;
|
|
17
|
+
private installedAdmission;
|
|
18
|
+
constructor(deps: ProviderRequestRuntimeControllerDeps);
|
|
19
|
+
install(): void;
|
|
20
|
+
dispose(): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=provider-request-runtime-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-request-runtime-controller.d.ts","sourceRoot":"","sources":["../../src/core/provider-request-runtime-controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAC;AAEjG,MAAM,WAAW,oCAAoC;IACpD,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,IAAI,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;IAC/D,OAAO,EAAE,gCAAgC,CAAC;CAC1C;AAED,yFAAyF;AACzF,qBAAa,gCAAgC;IAC5C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAuC;IAC5D,OAAO,CAAC,wBAAwB,CAA4B;IAC5D,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,iBAAiB,CAAgC;IACzD,OAAO,CAAC,yBAAyB,CAA4B;IAC7D,OAAO,CAAC,oBAAoB,CAAuB;IACnD,OAAO,CAAC,kBAAkB,CAAgC;IAE1D,YAAY,IAAI,EAAE,oCAAoC,EAErD;IAED,OAAO,IAAI,IAAI,CA8Dd;IAED,OAAO,IAAI,IAAI,CAYd;CACD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { estimateProviderRequestTokens } from "@caupulican/pi-agent-core";
|
|
2
|
+
/** Installs and owns the one provider planning/admission hook generation on an Agent. */
|
|
3
|
+
export class ProviderRequestRuntimeController {
|
|
4
|
+
constructor(deps) {
|
|
5
|
+
this.deps = deps;
|
|
6
|
+
}
|
|
7
|
+
install() {
|
|
8
|
+
if (this.installedPlanContext)
|
|
9
|
+
return;
|
|
10
|
+
const agent = this.deps.agent;
|
|
11
|
+
this.previousTransformContext = agent.transformContext;
|
|
12
|
+
this.previousPlanContext = agent.planContext;
|
|
13
|
+
this.previousAdmission = agent.admitProviderRequest;
|
|
14
|
+
const previousTransformContext = this.previousTransformContext?.bind(agent);
|
|
15
|
+
const previousPlanContext = this.previousPlanContext?.bind(agent);
|
|
16
|
+
const previousAdmission = this.previousAdmission?.bind(agent);
|
|
17
|
+
this.installedPlanContext = async ({ messages, attempt }, signal) => {
|
|
18
|
+
const basePlan = previousPlanContext
|
|
19
|
+
? await previousPlanContext({ messages, attempt }, signal)
|
|
20
|
+
: {
|
|
21
|
+
messages: previousTransformContext ? await previousTransformContext(messages, signal) : messages,
|
|
22
|
+
};
|
|
23
|
+
const sessionPlan = await this.deps.context.plan(basePlan.messages, signal);
|
|
24
|
+
return {
|
|
25
|
+
messages: sessionPlan.messages,
|
|
26
|
+
transientMessages: [...(basePlan.transientMessages ?? []), ...(sessionPlan.transientMessages ?? [])],
|
|
27
|
+
isCurrent: () => basePlan.isCurrent?.() !== false && sessionPlan.isCurrent?.() !== false,
|
|
28
|
+
prepareCommit: () => {
|
|
29
|
+
if (basePlan.isCurrent?.() === false || sessionPlan.isCurrent?.() === false)
|
|
30
|
+
return false;
|
|
31
|
+
return basePlan.prepareCommit?.() !== false && sessionPlan.prepareCommit?.() !== false;
|
|
32
|
+
},
|
|
33
|
+
commit: () => {
|
|
34
|
+
basePlan.commit?.();
|
|
35
|
+
sessionPlan.commit?.();
|
|
36
|
+
},
|
|
37
|
+
discard: () => {
|
|
38
|
+
sessionPlan.discard?.();
|
|
39
|
+
basePlan.discard?.();
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
this.installedTransformContext = async (messages, signal) => {
|
|
44
|
+
const plan = await this.installedPlanContext?.({ messages, attempt: 0 }, signal);
|
|
45
|
+
if (!plan)
|
|
46
|
+
return messages;
|
|
47
|
+
try {
|
|
48
|
+
return [...plan.messages, ...(plan.transientMessages ?? [])];
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
plan.discard?.();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
this.installedAdmission = async (request, signal) => {
|
|
55
|
+
const decision = await this.deps.compaction.admitProviderRequest({
|
|
56
|
+
requestTokens: estimateProviderRequestTokens(request.context),
|
|
57
|
+
nonCompactableTokens: estimateProviderRequestTokens(request.nonCompactableContext),
|
|
58
|
+
attempt: request.attempt,
|
|
59
|
+
});
|
|
60
|
+
if (decision.action === "replan") {
|
|
61
|
+
return {
|
|
62
|
+
action: "replan",
|
|
63
|
+
context: { ...request.sourceContext, messages: agent.state.messages.slice() },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return (await previousAdmission?.(request, signal)) ?? { action: "send" };
|
|
67
|
+
};
|
|
68
|
+
agent.planContext = this.installedPlanContext;
|
|
69
|
+
agent.transformContext = this.installedTransformContext;
|
|
70
|
+
agent.admitProviderRequest = this.installedAdmission;
|
|
71
|
+
}
|
|
72
|
+
dispose() {
|
|
73
|
+
const agent = this.deps.agent;
|
|
74
|
+
if (agent.transformContext === this.installedTransformContext) {
|
|
75
|
+
agent.transformContext = this.previousTransformContext;
|
|
76
|
+
}
|
|
77
|
+
if (agent.planContext === this.installedPlanContext)
|
|
78
|
+
agent.planContext = this.previousPlanContext;
|
|
79
|
+
if (agent.admitProviderRequest === this.installedAdmission) {
|
|
80
|
+
agent.admitProviderRequest = this.previousAdmission;
|
|
81
|
+
}
|
|
82
|
+
this.installedTransformContext = undefined;
|
|
83
|
+
this.installedPlanContext = undefined;
|
|
84
|
+
this.installedAdmission = undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=provider-request-runtime-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-request-runtime-controller.js","sourceRoot":"","sources":["../../src/core/provider-request-runtime-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAW1E,yFAAyF;AACzF,MAAM,OAAO,gCAAgC;IAS5C,YAAY,IAA0C;QACrD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,OAAO;QACN,IAAI,IAAI,CAAC,oBAAoB;YAAE,OAAO;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9B,IAAI,CAAC,wBAAwB,GAAG,KAAK,CAAC,gBAAgB,CAAC;QACvD,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAAC;QAC7C,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,oBAAoB,CAAC;QACpD,MAAM,wBAAwB,GAAG,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5E,MAAM,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,EA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AC,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE;iBAC7E,CAAC;YACH,CAAC;YACD,OAAO,CAAC,MAAM,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAC3E,CAAC,CAAC;QAEF,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC;QAC9C,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC,yBAAyB,CAAC;QACxD,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAC,kBAAkB,CAAC;IACtD,CAAC;IAED,OAAO;QACN,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9B,IAAI,KAAK,CAAC,gBAAgB,KAAK,IAAI,CAAC,yBAAyB,EAAE,CAAC;YAC/D,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC,wBAAwB,CAAC;QACxD,CAAC;QACD,IAAI,KAAK,CAAC,WAAW,KAAK,IAAI,CAAC,oBAAoB;YAAE,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAClG,IAAI,KAAK,CAAC,oBAAoB,KAAK,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5D,KAAK,CAAC,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,CAAC;QACrD,CAAC;QACD,IAAI,CAAC,yBAAyB,GAAG,SAAS,CAAC;QAC3C,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;QACtC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;IACrC,CAAC;CACD","sourcesContent":["import { estimateProviderRequestTokens } from \"@caupulican/pi-agent-core\";\nimport type { Agent } from \"@caupulican/pi-agent-core/agent\";\nimport type { CompactionController } from \"./compaction-controller.ts\";\nimport type { ProviderRequestContextController } from \"./provider-request-context-controller.ts\";\n\nexport interface ProviderRequestRuntimeControllerDeps {\n\tagent: Agent;\n\tcompaction: Pick<CompactionController, \"admitProviderRequest\">;\n\tcontext: ProviderRequestContextController;\n}\n\n/** Installs and owns the one provider planning/admission hook generation on an Agent. */\nexport class ProviderRequestRuntimeController {\n\tprivate readonly deps: ProviderRequestRuntimeControllerDeps;\n\tprivate previousTransformContext: Agent[\"transformContext\"];\n\tprivate previousPlanContext: Agent[\"planContext\"];\n\tprivate previousAdmission: Agent[\"admitProviderRequest\"];\n\tprivate installedTransformContext: Agent[\"transformContext\"];\n\tprivate installedPlanContext: Agent[\"planContext\"];\n\tprivate installedAdmission: Agent[\"admitProviderRequest\"];\n\n\tconstructor(deps: ProviderRequestRuntimeControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tinstall(): void {\n\t\tif (this.installedPlanContext) return;\n\t\tconst agent = this.deps.agent;\n\t\tthis.previousTransformContext = agent.transformContext;\n\t\tthis.previousPlanContext = agent.planContext;\n\t\tthis.previousAdmission = agent.admitProviderRequest;\n\t\tconst previousTransformContext = this.previousTransformContext?.bind(agent);\n\t\tconst previousPlanContext = this.previousPlanContext?.bind(agent);\n\t\tconst previousAdmission = this.previousAdmission?.bind(agent);\n\n\t\tthis.installedPlanContext = async ({ messages, attempt }, signal) => {\n\t\t\tconst basePlan = previousPlanContext\n\t\t\t\t? await previousPlanContext({ messages, attempt }, signal)\n\t\t\t\t: {\n\t\t\t\t\t\tmessages: previousTransformContext ? await previousTransformContext(messages, signal) : messages,\n\t\t\t\t\t};\n\t\t\tconst sessionPlan = await this.deps.context.plan(basePlan.messages, signal);\n\t\t\treturn {\n\t\t\t\tmessages: sessionPlan.messages,\n\t\t\t\ttransientMessages: [...(basePlan.transientMessages ?? []), ...(sessionPlan.transientMessages ?? [])],\n\t\t\t\tisCurrent: () => basePlan.isCurrent?.() !== false && sessionPlan.isCurrent?.() !== false,\n\t\t\t\tprepareCommit: () => {\n\t\t\t\t\tif (basePlan.isCurrent?.() === false || sessionPlan.isCurrent?.() === false) return false;\n\t\t\t\t\treturn basePlan.prepareCommit?.() !== false && sessionPlan.prepareCommit?.() !== false;\n\t\t\t\t},\n\t\t\t\tcommit: () => {\n\t\t\t\t\tbasePlan.commit?.();\n\t\t\t\t\tsessionPlan.commit?.();\n\t\t\t\t},\n\t\t\t\tdiscard: () => {\n\t\t\t\t\tsessionPlan.discard?.();\n\t\t\t\t\tbasePlan.discard?.();\n\t\t\t\t},\n\t\t\t};\n\t\t};\n\t\tthis.installedTransformContext = async (messages, signal) => {\n\t\t\tconst plan = await this.installedPlanContext?.({ messages, attempt: 0 }, signal);\n\t\t\tif (!plan) return messages;\n\t\t\ttry {\n\t\t\t\treturn [...plan.messages, ...(plan.transientMessages ?? [])];\n\t\t\t} finally {\n\t\t\t\tplan.discard?.();\n\t\t\t}\n\t\t};\n\t\tthis.installedAdmission = async (request, signal) => {\n\t\t\tconst decision = await this.deps.compaction.admitProviderRequest({\n\t\t\t\trequestTokens: estimateProviderRequestTokens(request.context),\n\t\t\t\tnonCompactableTokens: estimateProviderRequestTokens(request.nonCompactableContext),\n\t\t\t\tattempt: request.attempt,\n\t\t\t});\n\t\t\tif (decision.action === \"replan\") {\n\t\t\t\treturn {\n\t\t\t\t\taction: \"replan\",\n\t\t\t\t\tcontext: { ...request.sourceContext, messages: agent.state.messages.slice() },\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn (await previousAdmission?.(request, signal)) ?? { action: \"send\" };\n\t\t};\n\n\t\tagent.planContext = this.installedPlanContext;\n\t\tagent.transformContext = this.installedTransformContext;\n\t\tagent.admitProviderRequest = this.installedAdmission;\n\t}\n\n\tdispose(): void {\n\t\tconst agent = this.deps.agent;\n\t\tif (agent.transformContext === this.installedTransformContext) {\n\t\t\tagent.transformContext = this.previousTransformContext;\n\t\t}\n\t\tif (agent.planContext === this.installedPlanContext) agent.planContext = this.previousPlanContext;\n\t\tif (agent.admitProviderRequest === this.installedAdmission) {\n\t\t\tagent.admitProviderRequest = this.previousAdmission;\n\t\t}\n\t\tthis.installedTransformContext = undefined;\n\t\tthis.installedPlanContext = undefined;\n\t\tthis.installedAdmission = undefined;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Provider-bound tool prose budgets. Structural schemas remain separate and exact. */
|
|
2
|
+
export declare const MAX_PROVIDER_TOOL_SNIPPET_CHARS = 120;
|
|
3
|
+
export declare const MAX_PROVIDER_TOOL_GUIDELINE_CHARS = 140;
|
|
4
|
+
export declare const MAX_PROVIDER_TOOL_GUIDELINES_CHARS = 1200;
|
|
5
|
+
export declare function normalizeProviderPromptSnippet(text: string | undefined): string | undefined;
|
|
6
|
+
export declare function normalizeProviderPromptGuidelines(guidelines: string[] | undefined): string[];
|
|
7
|
+
//# sourceMappingURL=provider-tool-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-tool-text.d.ts","sourceRoot":"","sources":["../../src/core/provider-tool-text.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,eAAO,MAAM,+BAA+B,MAAM,CAAC;AACnD,eAAO,MAAM,iCAAiC,MAAM,CAAC;AACrD,eAAO,MAAM,kCAAkC,OAAQ,CAAC;AASxD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAU3F;AAED,wBAAgB,iCAAiC,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,EAAE,CAqB5F"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Provider-bound tool prose budgets. Structural schemas remain separate and exact. */
|
|
2
|
+
export const MAX_PROVIDER_TOOL_SNIPPET_CHARS = 120;
|
|
3
|
+
export const MAX_PROVIDER_TOOL_GUIDELINE_CHARS = 140;
|
|
4
|
+
export const MAX_PROVIDER_TOOL_GUIDELINES_CHARS = 1_200;
|
|
5
|
+
function oneLine(text) {
|
|
6
|
+
return text
|
|
7
|
+
.replace(/[\r\n]+/g, " ")
|
|
8
|
+
.replace(/\s+/g, " ")
|
|
9
|
+
.trim();
|
|
10
|
+
}
|
|
11
|
+
export function normalizeProviderPromptSnippet(text) {
|
|
12
|
+
if (!text)
|
|
13
|
+
return undefined;
|
|
14
|
+
const normalized = oneLine(text);
|
|
15
|
+
if (normalized.length === 0)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (normalized.length > MAX_PROVIDER_TOOL_SNIPPET_CHARS) {
|
|
18
|
+
throw new Error(`Provider tool snippet exceeds ${MAX_PROVIDER_TOOL_SNIPPET_CHARS} characters (${normalized.length}): ${normalized.slice(0, 48)}`);
|
|
19
|
+
}
|
|
20
|
+
return normalized;
|
|
21
|
+
}
|
|
22
|
+
export function normalizeProviderPromptGuidelines(guidelines) {
|
|
23
|
+
if (!guidelines || guidelines.length === 0)
|
|
24
|
+
return [];
|
|
25
|
+
const unique = new Set();
|
|
26
|
+
let total = 0;
|
|
27
|
+
for (const guideline of guidelines) {
|
|
28
|
+
const normalized = oneLine(guideline);
|
|
29
|
+
if (normalized.length === 0 || unique.has(normalized))
|
|
30
|
+
continue;
|
|
31
|
+
if (normalized.length > MAX_PROVIDER_TOOL_GUIDELINE_CHARS) {
|
|
32
|
+
throw new Error(`Provider tool guideline exceeds ${MAX_PROVIDER_TOOL_GUIDELINE_CHARS} characters (${normalized.length}): ${normalized.slice(0, 48)}`);
|
|
33
|
+
}
|
|
34
|
+
total += normalized.length;
|
|
35
|
+
if (total > MAX_PROVIDER_TOOL_GUIDELINES_CHARS) {
|
|
36
|
+
throw new Error(`Provider tool guidelines exceed ${MAX_PROVIDER_TOOL_GUIDELINES_CHARS} characters (${total}).`);
|
|
37
|
+
}
|
|
38
|
+
unique.add(normalized);
|
|
39
|
+
}
|
|
40
|
+
return Array.from(unique);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=provider-tool-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-tool-text.js","sourceRoot":"","sources":["../../src/core/provider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AAU,CAAC,MAAM,GAAG,iCAAiC,EAAE,CAAC;YAC3D,MAAM,IAAI,KAAK,CACd,mCAAmC,iCAAiC,gBAAgB,UAAU,CAAC,MAAM,MAAM,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CACpI,CAAC;QACH,CAAC;QACD,KAAK,IAAI,UAAU,CAAC,MAAM,CAAC;QAC3B,IAAI,KAAK,GAAG,kCAAkC,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CACd,mCAAmC,kCAAkC,gBAAgB,KAAK,IAAI,CAC9F,CAAC;QACH,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["/** Provider-bound tool prose budgets. Structural schemas remain separate and exact. */\nexport const MAX_PROVIDER_TOOL_SNIPPET_CHARS = 120;\nexport const MAX_PROVIDER_TOOL_GUIDELINE_CHARS = 140;\nexport const MAX_PROVIDER_TOOL_GUIDELINES_CHARS = 1_200;\n\nfunction oneLine(text: string): string {\n\treturn text\n\t\t.replace(/[\\r\\n]+/g, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nexport function normalizeProviderPromptSnippet(text: string | undefined): string | undefined {\n\tif (!text) return undefined;\n\tconst normalized = oneLine(text);\n\tif (normalized.length === 0) return undefined;\n\tif (normalized.length > MAX_PROVIDER_TOOL_SNIPPET_CHARS) {\n\t\tthrow new Error(\n\t\t\t`Provider tool snippet exceeds ${MAX_PROVIDER_TOOL_SNIPPET_CHARS} characters (${normalized.length}): ${normalized.slice(0, 48)}`,\n\t\t);\n\t}\n\treturn normalized;\n}\n\nexport function normalizeProviderPromptGuidelines(guidelines: string[] | undefined): string[] {\n\tif (!guidelines || guidelines.length === 0) return [];\n\tconst unique = new Set<string>();\n\tlet total = 0;\n\tfor (const guideline of guidelines) {\n\t\tconst normalized = oneLine(guideline);\n\t\tif (normalized.length === 0 || unique.has(normalized)) continue;\n\t\tif (normalized.length > MAX_PROVIDER_TOOL_GUIDELINE_CHARS) {\n\t\t\tthrow new Error(\n\t\t\t\t`Provider tool guideline exceeds ${MAX_PROVIDER_TOOL_GUIDELINE_CHARS} characters (${normalized.length}): ${normalized.slice(0, 48)}`,\n\t\t\t);\n\t\t}\n\t\ttotal += normalized.length;\n\t\tif (total > MAX_PROVIDER_TOOL_GUIDELINES_CHARS) {\n\t\t\tthrow new Error(\n\t\t\t\t`Provider tool guidelines exceed ${MAX_PROVIDER_TOOL_GUIDELINES_CHARS} characters (${total}).`,\n\t\t\t);\n\t\t}\n\t\tunique.add(normalized);\n\t}\n\treturn Array.from(unique);\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CAPACITY_PROBE_SYSTEM_PROMPT, CURATION_DIGEST_SYSTEM_PROMPT, SEARCH_PROBE_SYSTEM_PROMPT, TOOL_CALL_PROBE_SYSTEM_PROMPT } from "../provider-prompt-contracts.ts";
|
|
2
|
+
export { CAPACITY_PROBE_SYSTEM_PROMPT, CURATION_DIGEST_SYSTEM_PROMPT as DIGEST_PROBE_SYSTEM_PROMPT, SEARCH_PROBE_SYSTEM_PROMPT, TOOL_CALL_PROBE_SYSTEM_PROMPT, };
|
|
1
3
|
/**
|
|
2
4
|
* Model fitness probe: measures whether a candidate model can actually drive the harness's
|
|
3
5
|
* subagent contracts — the research lane, the delegated-worker lane, and the routing judge — by
|
|
@@ -87,11 +89,6 @@ export interface ModelFitnessReport {
|
|
|
87
89
|
capacity?: CapacityFitnessScore;
|
|
88
90
|
totalCostUsd: number;
|
|
89
91
|
}
|
|
90
|
-
/** Static prompts for the heavy-lifter surfaces (stable for provider prompt caching). */
|
|
91
|
-
export declare const SEARCH_PROBE_SYSTEM_PROMPT: string;
|
|
92
|
-
export declare const TOOL_CALL_PROBE_SYSTEM_PROMPT: string;
|
|
93
|
-
export declare const CAPACITY_PROBE_SYSTEM_PROMPT: string;
|
|
94
|
-
export { CURATION_DIGEST_SYSTEM_PROMPT as DIGEST_PROBE_SYSTEM_PROMPT } from "../context/brain-curator.ts";
|
|
95
92
|
export declare function runModelFitnessProbe(options: ModelFitnessOptions): Promise<ModelFitnessReport>;
|
|
96
93
|
/**
|
|
97
94
|
* Pure verdict: true when the probe found ZERO successes on every LANE surface it actually graded
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-fitness.d.ts","sourceRoot":"","sources":["../../../src/core/research/model-fitness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"model-fitness.d.ts","sourceRoot":"","sources":["../../../src/core/research/model-fitness.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,4BAA4B,EAC5B,6BAA6B,EAC7B,0BAA0B,EAC1B,6BAA6B,EAC7B,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACN,4BAA4B,EAC5B,6BAA6B,IAAI,0BAA0B,EAC3D,0BAA0B,EAC1B,6BAA6B,GAC7B,CAAC;AAEF;;;;;;GAMG;AAEH,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,iGAAiG;IACjG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kGAAkG;IAClG,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAEjC,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,qFAAqF;AACrF,eAAO,MAAM,6BAA6B,EAAE,SAAS,k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C,MAAM,EAAE,MAAM,CAAC;IACf,yFAAyF;IACzF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,MAAM,EAAE,gBAAgB,CAAC;IACzB,KAAK,EAAE,iBAAiB,CAAC;IACzB,8EAA8E;IAC9E,MAAM,EAAE,gBAAgB,CAAC;IACzB,yFAAyF;IACzF,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,qGAAqG;IACrG,MAAM,EAAE,gBAAgB,CAAC;IACzB,qFAAqF;IACrF,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,YAAY,EAAE,MAAM,CAAC;CACrB;AA8JD,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA+KpG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAQpE;AAED,kGAAkG;AAClG,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAsB1F"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { runBoundedCompletion } from "../autonomy/bounded-completion.js";
|
|
2
|
-
import { CURATION_DIGEST_SYSTEM_PROMPT } from "../context/brain-curator.js";
|
|
3
2
|
import { runWorker } from "../delegation/worker-runner.js";
|
|
4
3
|
import { parseModelOutputJsonObject } from "../model-output-json.js";
|
|
5
4
|
import { runRouteJudge } from "../model-router/route-judge.js";
|
|
5
|
+
import { CAPACITY_PROBE_SYSTEM_PROMPT, CURATION_DIGEST_SYSTEM_PROMPT, SEARCH_PROBE_SYSTEM_PROMPT, TOOL_CALL_PROBE_SYSTEM_PROMPT, } from "../provider-prompt-contracts.js";
|
|
6
6
|
import { runResearch } from "./research-runner.js";
|
|
7
|
+
export { CAPACITY_PROBE_SYSTEM_PROMPT, CURATION_DIGEST_SYSTEM_PROMPT as DIGEST_PROBE_SYSTEM_PROMPT, SEARCH_PROBE_SYSTEM_PROMPT, TOOL_CALL_PROBE_SYSTEM_PROMPT, };
|
|
7
8
|
/** Default judge probe set: three planning-shaped prompts, three trivial lookups. */
|
|
8
9
|
export const DEFAULT_JUDGE_FITNESS_PROMPTS = [
|
|
9
10
|
{ prompt: "how should we plan the migration of the session storage layer?", planning: true },
|
|
@@ -14,30 +15,11 @@ export const DEFAULT_JUDGE_FITNESS_PROMPTS = [
|
|
|
14
15
|
{ prompt: "why is this test flaky?", planning: false },
|
|
15
16
|
];
|
|
16
17
|
/** Static prompts for the heavy-lifter surfaces (stable for provider prompt caching). */
|
|
17
|
-
export const SEARCH_PROBE_SYSTEM_PROMPT = [
|
|
18
|
-
"You plan code searches for a coding agent. You never answer the question yourself.",
|
|
19
|
-
"Given a question about a codebase, respond with STRICT JSON only - no prose:",
|
|
20
|
-
'{"queries":[{"pattern":"<regex or literal to grep>","glob":"<file glob like **/*.ts>"}]}',
|
|
21
|
-
"Return 1 to 4 queries, most specific first.",
|
|
22
|
-
].join("\n");
|
|
23
|
-
export const TOOL_CALL_PROBE_SYSTEM_PROMPT = [
|
|
24
|
-
"You operate tools for a coding agent. You have exactly one tool:",
|
|
25
|
-
"grep(pattern: string, path: string) - search files under a path for a pattern.",
|
|
26
|
-
"Respond to every task with STRICT JSON only - no prose:",
|
|
27
|
-
'{"tool":"grep","arguments":{"pattern":"<pattern>","path":"<path>"}}',
|
|
28
|
-
].join("\n");
|
|
29
|
-
export const CAPACITY_PROBE_SYSTEM_PROMPT = [
|
|
30
|
-
"You are a context-window capacity probe for a local model server.",
|
|
31
|
-
"Find the unique NEEDLE token in the user's text and echo that token only.",
|
|
32
|
-
"Do not summarize, explain, or add punctuation.",
|
|
33
|
-
].join("\n");
|
|
34
18
|
const SEARCH_PROBE_TASKS = [
|
|
35
19
|
"Where is the retry/backoff logic for HTTP requests implemented?",
|
|
36
20
|
"Which files define the settings for background research?",
|
|
37
21
|
"Find where session entries of type custom are appended.",
|
|
38
22
|
];
|
|
39
|
-
// The probe measures the REAL curation contract — same prompt the BrainCurator ships.
|
|
40
|
-
export { CURATION_DIGEST_SYSTEM_PROMPT as DIGEST_PROBE_SYSTEM_PROMPT } from "../context/brain-curator.js";
|
|
41
23
|
/**
|
|
42
24
|
* Digest probe chunks each carry a NONCE identifier that cannot be guessed from the
|
|
43
25
|
* instructions: acceptance requires the digest to RETAIN the nonce verbatim, so the score
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-fitness.js","sourceRoot":"","sources":["../../../src/core/research/model-fitness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAgCnD,qFAAqF;AACrF,MAAM,CAAC,MAAM,6BAA6B,GAAkC;IAC3E,EAAE,MAAM,EAAE,gEAAgE,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC5F,EAAE,MAAM,EAAE,uDAAuD,EAAE,QAAQ,EAAE,IAAI,EAAE;IACnF,EAAE,MAAM,EAAE,yCAAyC,EAAE,QAAQ,EAAE,IAAI,EAAE;IACrE,EAAE,MAAM,EAAE,4CAA4C,EAAE,QAAQ,EAAE,KAAK,EAAE;IACzE,EAAE,MAAM,EAAE,yCAAyC,EAAE,QAAQ,EAAE,KAAK,EAAE;IACtE,EAAE,MAAM,EAAE,yBAAyB,EAAE,QAAQ,EAAE,KAAK,EAAE;CACtD,CAAC;AAqEF,yFAAyF;AACzF,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACzC,oFAAoF;IACpF,8EAA8E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K,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE;QACtS,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,EAAE,CAAC;KAC3D,CAAC;IACF,IAAI,MAAM,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import { runBoundedCompletion } from \"../autonomy/bounded-completion.ts\";\nimport type { CapabilityEnvelope } from \"../autonomy/contracts.ts\";\nimport { CURATION_DIGEST_SYSTEM_PROMPT } from \"../context/brain-curator.ts\";\nimport { runWorker } from \"../delegation/worker-runner.ts\";\nimport { parseModelOutputJsonObject } from \"../model-output-json.ts\";\nimport { runRouteJudge } from \"../model-router/route-judge.ts\";\nimport { runResearch } from \"./research-runner.ts\";\n\n/**\n * Model fitness probe: measures whether a candidate model can actually drive the harness's\n * subagent contracts — the research lane, the delegated-worker lane, and the routing judge — by\n * running each real runner against the model and scoring parse/success rates plus judge\n * discrimination. Provider-free: the completion executor is injected, so this works against any\n * registered model (local Ollama models included) and against faux providers in tests.\n */\n\nexport interface FitnessCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n\t/** Output tokens generated (for tok/s). Optional: providers that don't report it are skipped. */\n\toutputTokens?: number;\n\t/** Pure generation time in ms (e.g. Ollama eval_duration). Falls back to wall-clock if absent. */\n\tevalMs?: number;\n}\n\nexport type FitnessComplete = (args: {\n\tsystemPrompt: string;\n\tuserPrompt: string;\n\tsignal?: AbortSignal;\n}) => Promise<FitnessCompletion>;\n\nexport interface JudgeFitnessPrompt {\n\tprompt: string;\n\t/** True when the prompt is planning-shaped and must never route cheap. */\n\tplanning: boolean;\n}\n\n/** Default judge probe set: three planning-shaped prompts, three trivial lookups. */\nexport const DEFAULT_JUDGE_FITNESS_PROMPTS: readonly JudgeFitnessPrompt[] = [\n\t{ prompt: \"how should we plan the migration of the session storage layer?\", planning: true },\n\t{ prompt: \"design an approach for splitting the settings manager\", planning: true },\n\t{ prompt: \"draft a roadmap for the autonomy rework\", planning: true },\n\t{ prompt: \"what does the resolvePath function return?\", planning: false },\n\t{ prompt: \"list the files in the delegation module\", planning: false },\n\t{ prompt: \"why is this test flaky?\", planning: false },\n];\n\nexport interface CapacityProbeOptions {\n\tregisteredContextWindow: number;\n\t/** Smallest candidate window to try before declaring the capacity unknown. Default 1024. */\n\tminContextWindow?: number;\n}\n\nexport interface ModelFitnessOptions {\n\tcomplete: FitnessComplete;\n\t/** Trials per lane surface. Default 3. */\n\ttrials?: number;\n\t/** Wall-clock budget per call in ms. Default 120000. */\n\tmaxWallClockMs?: number;\n\tjudgePrompts?: readonly JudgeFitnessPrompt[];\n\t/** Optional local-model capacity lane: measures the actually served context window. */\n\tcapacityProbe?: CapacityProbeOptions;\n\tsignal?: AbortSignal;\n\t/** Injected clock for latency measurement (test seam). Defaults to Date.now. */\n\tnow?: () => number;\n}\n\nexport interface LaneFitnessScore {\n\tsucceeded: number;\n\ttotal: number;\n\toutcomes: string[];\n\tmeanMs: number;\n\t/** Mean output tokens/second across the surface's calls; undefined when not reported. */\n\ttokensPerSecond?: number;\n}\n\nexport interface JudgeFitnessScore {\n\tparsed: number;\n\tplanningElevated: number;\n\tplanningTotal: number;\n\ttrivialCheap: number;\n\ttrivialTotal: number;\n\ttotal: number;\n\toutcomes: string[];\n\tmeanMs: number;\n\t/** Mean output tokens/second across the judge calls; undefined when not reported. */\n\ttokensPerSecond?: number;\n}\n\nexport interface CapacityFitnessScore {\n\tregisteredContextWindow: number;\n\tservedContextWindow: number;\n\toutcomes: string[];\n\tmeanMs: number;\n}\n\nexport interface ModelFitnessReport {\n\ttrials: number;\n\t/** Aggregate output tokens/second across ALL probe calls (the headline speed number). */\n\ttokensPerSecond?: number;\n\tresearch: LaneFitnessScore;\n\tworker: LaneFitnessScore;\n\tjudge: JudgeFitnessScore;\n\t/** Heavy-lifter surface: can the model formulate a structured search plan? */\n\tsearch: LaneFitnessScore;\n\t/** Heavy-lifter surface: can the model emit a well-formed tool call against a schema? */\n\ttoolCall: LaneFitnessScore;\n\t/** Curator surface: can the model digest a context chunk to strict JSON WITHOUT losing key facts? */\n\tdigest: LaneFitnessScore;\n\t/** Local-model capacity lane: measured context window the server actually serves. */\n\tcapacity?: CapacityFitnessScore;\n\ttotalCostUsd: number;\n}\n\n/** Static prompts for the heavy-lifter surfaces (stable for provider prompt caching). */\nexport const SEARCH_PROBE_SYSTEM_PROMPT = [\n\t\"You plan code searches for a coding agent. You never answer the question yourself.\",\n\t\"Given a question about a codebase, respond with STRICT JSON only - no prose:\",\n\t'{\"queries\":[{\"pattern\":\"<regex or literal to grep>\",\"glob\":\"<file glob like **/*.ts>\"}]}',\n\t\"Return 1 to 4 queries, most specific first.\",\n].join(\"\\n\");\n\nexport const TOOL_CALL_PROBE_SYSTEM_PROMPT = [\n\t\"You operate tools for a coding agent. You have exactly one tool:\",\n\t\"grep(pattern: string, path: string) - search files under a path for a pattern.\",\n\t\"Respond to every task with STRICT JSON only - no prose:\",\n\t'{\"tool\":\"grep\",\"arguments\":{\"pattern\":\"<pattern>\",\"path\":\"<path>\"}}',\n].join(\"\\n\");\n\nexport const CAPACITY_PROBE_SYSTEM_PROMPT = [\n\t\"You are a context-window capacity probe for a local model server.\",\n\t\"Find the unique NEEDLE token in the user's text and echo that token only.\",\n\t\"Do not summarize, explain, or add punctuation.\",\n].join(\"\\n\");\n\nconst SEARCH_PROBE_TASKS: readonly string[] = [\n\t\"Where is the retry/backoff logic for HTTP requests implemented?\",\n\t\"Which files define the settings for background research?\",\n\t\"Find where session entries of type custom are appended.\",\n];\n\n// The probe measures the REAL curation contract — same prompt the BrainCurator ships.\nexport { CURATION_DIGEST_SYSTEM_PROMPT as DIGEST_PROBE_SYSTEM_PROMPT } from \"../context/brain-curator.ts\";\n\n/**\n * Digest probe chunks each carry a NONCE identifier that cannot be guessed from the\n * instructions: acceptance requires the digest to RETAIN the nonce verbatim, so the score\n * measures extraction fidelity, not narration (a model cannot pass by paraphrasing).\n */\nconst DIGEST_PROBE_TASKS: readonly { chunk: string; nonce: string }[] = [\n\t{\n\t\tnonce: \"retryWithJitter_zx41\",\n\t\tchunk: [\n\t\t\t\"grep results for 'retry' under src/http:\",\n\t\t\t\"src/http/client.ts:88: export function retryWithJitter_zx41(fn, attempts = 3) {\",\n\t\t\t\"src/http/client.ts:112: // exponential backoff capped at 30s\",\n\t\t\t\"src/http/pool.ts:41: client.retry = false\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tnonce: \"ERR_QM_7734\",\n\t\tchunk: [\n\t\t\t\"$ npm run migrate\",\n\t\t\t\"migrating 14 files...\",\n\t\t\t\"error ERR_QM_7734: column 'owner_id' missing on table sessions (migration 0009)\",\n\t\t\t\"exit code 1\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tnonce: \"v3.9.2-hotfix.1\",\n\t\tchunk: [\n\t\t\t\"read package.json (34 lines):\",\n\t\t\t' \"name\": \"acme-billing\",',\n\t\t\t' \"version\": \"v3.9.2-hotfix.1\",',\n\t\t\t' \"engines\": { \"node\": \">=22\" },',\n\t\t].join(\"\\n\"),\n\t},\n];\n\nfunction parseDigest(text: string, nonce: string): boolean {\n\tconst parsed = parseModelOutputJsonObject(text);\n\tif (!parsed) return false;\n\tconst digest = (parsed as { digest?: unknown }).digest;\n\tif (typeof digest !== \"string\") return false;\n\tconst trimmed = digest.trim();\n\t// Bounded and faithful: short enough to be a stub annotation, still carrying the nonce fact.\n\treturn trimmed.length > 0 && trimmed.length <= 240 && trimmed.includes(nonce);\n}\n\nconst TOOL_CALL_PROBE_TASKS: readonly string[] = [\n\t\"Find usages of the function resolveCliModel under src/.\",\n\t\"Search for the string 'budget_exhausted' in the core directory.\",\n\t\"Locate where LaneTracker is instantiated under src/core.\",\n];\n\nfunction parseSearchPlan(text: string): boolean {\n\tconst parsed = parseModelOutputJsonObject(text);\n\tif (!parsed) return false;\n\tconst queries = (parsed as { queries?: unknown }).queries;\n\tif (!Array.isArray(queries) || queries.length === 0 || queries.length > 8) return false;\n\treturn queries.every(\n\t\t(query) =>\n\t\t\tquery &&\n\t\t\ttypeof query === \"object\" &&\n\t\t\ttypeof (query as { pattern?: unknown }).pattern === \"string\" &&\n\t\t\t(query as { pattern: string }).pattern.trim().length > 0,\n\t);\n}\n\nfunction parseToolCall(text: string): boolean {\n\tconst parsed = parseModelOutputJsonObject(text);\n\tif (!parsed) return false;\n\tconst record = parsed as { tool?: unknown; arguments?: unknown };\n\tif (record.tool !== \"grep\") return false;\n\tconst args = record.arguments;\n\tif (!args || typeof args !== \"object\" || Array.isArray(args)) return false;\n\tconst pattern = (args as { pattern?: unknown }).pattern;\n\tconst path = (args as { path?: unknown }).path;\n\treturn (\n\t\ttypeof pattern === \"string\" && pattern.trim().length > 0 && typeof path === \"string\" && path.trim().length > 0\n\t);\n}\n\nfunction fitnessEnvelope(): CapabilityEnvelope {\n\treturn {\n\t\tid: \"model-fitness-probe\",\n\t\tcapabilities: [\"research.execute\", \"filesystem.read\", \"memory.query\"],\n\t\tmaxEstimatedUsd: 1,\n\t\tcreatedAt: new Date().toISOString(),\n\t};\n}\n\nfunction buildCapacityProbePrompt(targetTokens: number, startNeedle: string, endNeedle: string): string {\n\tconst targetChars = Math.max(\n\t\tstartNeedle.length + endNeedle.length + 64,\n\t\ttargetTokens * 4 - CAPACITY_PROBE_SYSTEM_PROMPT.length,\n\t);\n\tconst prefix = `CAPACITY PROBE START\\n${startNeedle}\\n`;\n\tconst suffix = `\\n${endNeedle}\\nCAPACITY PROBE END`;\n\tconst fillerLength = Math.max(0, targetChars - prefix.length - suffix.length);\n\treturn `${prefix}${\"x \".repeat(Math.ceil(fillerLength / 2)).slice(0, fillerLength)}${suffix}`;\n}\n\nasync function measureServedContextWindow(args: {\n\tprobe: CapacityProbeOptions;\n\tcomplete: FitnessComplete;\n\tmaxWallClockMs: number;\n\tsignal?: AbortSignal;\n\tnow: () => number;\n}): Promise<{ score: CapacityFitnessScore; costUsd: number }> {\n\tconst registered = Math.max(1, Math.floor(args.probe.registeredContextWindow));\n\tconst minWindow = Math.max(1, Math.floor(args.probe.minContextWindow ?? 1024));\n\tconst nonce = `${registered.toString(16).toUpperCase()}_${minWindow.toString(16).toUpperCase()}`;\n\tconst startNeedle = `NEEDLE_START_${nonce}`;\n\tconst endNeedle = `NEEDLE_END_${nonce}`;\n\tconst score: CapacityFitnessScore = {\n\t\tregisteredContextWindow: registered,\n\t\tservedContextWindow: 0,\n\t\toutcomes: [],\n\t\tmeanMs: 0,\n\t};\n\tlet candidate = registered;\n\tlet costUsd = 0;\n\tlet calls = 0;\n\twhile (candidate >= minWindow) {\n\t\tconst started = args.now();\n\t\tcalls++;\n\t\tconst bounded = await runBoundedCompletion({\n\t\t\tmaxWallClockMs: args.maxWallClockMs,\n\t\t\tsignal: args.signal,\n\t\t\texecute: (signal) =>\n\t\t\t\targs.complete({\n\t\t\t\t\tsystemPrompt: CAPACITY_PROBE_SYSTEM_PROMPT,\n\t\t\t\t\tuserPrompt: buildCapacityProbePrompt(candidate, startNeedle, endNeedle),\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t});\n\t\tscore.meanMs += args.now() - started;\n\t\tif (bounded.completion) costUsd += bounded.completion.costUsd;\n\t\tconst output = bounded.completion?.text.trim() ?? \"\";\n\t\tconst recalled = !bounded.failure && output.includes(startNeedle) && output.includes(endNeedle);\n\t\tscore.outcomes.push(`${candidate}:${recalled ? \"ok\" : (bounded.failure?.status ?? \"miss\")}`);\n\t\tif (recalled) {\n\t\t\tscore.servedContextWindow = candidate;\n\t\t\tbreak;\n\t\t}\n\t\tcandidate = Math.floor(candidate / 2);\n\t}\n\tif (score.servedContextWindow === 0) score.servedContextWindow = minWindow;\n\tscore.meanMs = calls > 0 ? Math.round(score.meanMs / calls) : 0;\n\treturn { score, costUsd };\n}\n\nexport async function runModelFitnessProbe(options: ModelFitnessOptions): Promise<ModelFitnessReport> {\n\tconst trials = Math.max(1, Math.min(options.trials ?? 3, 20));\n\tconst maxWallClockMs = options.maxWallClockMs ?? 120_000;\n\tconst judgePrompts = options.judgePrompts ?? DEFAULT_JUDGE_FITNESS_PROMPTS;\n\tconst now = options.now ?? Date.now;\n\tlet totalCostUsd = 0;\n\n\t// Token-speed instrumentation: the lane runners' own contracts carry text/cost only, so the\n\t// completer is wrapped once here and generation stats are accumulated per surface.\n\tconst overallSpeed = { tokens: 0, evalMs: 0 };\n\tlet surfaceSpeed = { tokens: 0, evalMs: 0 };\n\tconst complete: FitnessComplete = async (args) => {\n\t\tconst completion = await options.complete(args);\n\t\tconst tokens = completion.outputTokens ?? 0;\n\t\tconst evalMs = completion.evalMs ?? 0;\n\t\tif (tokens > 0 && evalMs > 0) {\n\t\t\tsurfaceSpeed.tokens += tokens;\n\t\t\tsurfaceSpeed.evalMs += evalMs;\n\t\t\toverallSpeed.tokens += tokens;\n\t\t\toverallSpeed.evalMs += evalMs;\n\t\t}\n\t\treturn completion;\n\t};\n\tconst takeSurfaceSpeed = (): number | undefined => {\n\t\tconst speed =\n\t\t\tsurfaceSpeed.evalMs > 0 ? Math.round((surfaceSpeed.tokens / surfaceSpeed.evalMs) * 1000) : undefined;\n\t\tsurfaceSpeed = { tokens: 0, evalMs: 0 };\n\t\treturn speed;\n\t};\n\n\tconst research: LaneFitnessScore = { succeeded: 0, total: trials, outcomes: [], meanMs: 0 };\n\tfor (let i = 0; i < trials; i++) {\n\t\tconst started = now();\n\t\tconst result = await runResearch({\n\t\t\tquery: `fitness:probe requirements:req-${i}`,\n\t\t\tcontext: [\n\t\t\t\t\"Goal: add a retry helper to the HTTP client module\",\n\t\t\t\t\"Open requirements:\",\n\t\t\t\t\"- Find what retry/backoff conventions the codebase already uses\",\n\t\t\t\t\"- Identify which call sites would adopt the helper\",\n\t\t\t].join(\"\\n\"),\n\t\t\tenvelope: fitnessEnvelope(),\n\t\t\tmaxUsd: 1,\n\t\t\tmaxSources: 8,\n\t\t\tmaxFindings: 5,\n\t\t\tmaxWallClockMs,\n\t\t\tsignal: options.signal,\n\t\t\tcomplete,\n\t\t});\n\t\tresearch.meanMs += now() - started;\n\t\ttotalCostUsd += result.costUsd;\n\t\tif (result.status === \"succeeded\") research.succeeded++;\n\t\tresearch.outcomes.push(`${result.status}/${result.reasonCode}`);\n\t}\n\tresearch.meanMs = Math.round(research.meanMs / trials);\n\tresearch.tokensPerSecond = takeSurfaceSpeed();\n\n\tconst worker: LaneFitnessScore = { succeeded: 0, total: trials, outcomes: [], meanMs: 0 };\n\tfor (let i = 0; i < trials; i++) {\n\t\tconst started = now();\n\t\tconst outcome = await runWorker({\n\t\t\trequest: {\n\t\t\t\tid: `fitness-worker-${i}`,\n\t\t\t\tinstructions:\n\t\t\t\t\t\"Summarize in two sentences what a capability envelope is: a declared set of allowed tools, paths, and capability names that bounds what a delegated worker may do.\",\n\t\t\t\troute: { tier: \"cheap\", risk: \"read-only\", confidence: 1, reasonCode: \"fitness_probe\", reasons: [] },\n\t\t\t\tenvelope: { id: `fitness-env-${i}`, capabilities: [\"filesystem.read\"], maxEstimatedUsd: 1 },\n\t\t\t\tmaxEstimatedUsd: 1,\n\t\t\t},\n\t\t\tmaxUsd: 1,\n\t\t\tmaxWallClockMs,\n\t\t\tusageReportId: `fitness:${i}`,\n\t\t\tsignal: options.signal,\n\t\t\tcomplete,\n\t\t});\n\t\tworker.meanMs += now() - started;\n\t\ttotalCostUsd += outcome.costUsd;\n\t\tif (outcome.claim.status === \"completed\" && outcome.accepted) worker.succeeded++;\n\t\tworker.outcomes.push(`${outcome.claim.status}/${outcome.reasonCode}`);\n\t}\n\tworker.meanMs = Math.round(worker.meanMs / trials);\n\tworker.tokensPerSecond = takeSurfaceSpeed();\n\n\tconst judge: JudgeFitnessScore = {\n\t\tparsed: 0,\n\t\tplanningElevated: 0,\n\t\tplanningTotal: judgePrompts.filter((entry) => entry.planning).length,\n\t\ttrivialCheap: 0,\n\t\ttrivialTotal: judgePrompts.filter((entry) => !entry.planning).length,\n\t\ttotal: judgePrompts.length,\n\t\toutcomes: [],\n\t\tmeanMs: 0,\n\t};\n\tfor (const entry of judgePrompts) {\n\t\tconst started = now();\n\t\tconst result = await runRouteJudge({\n\t\t\tprompt: entry.prompt,\n\t\t\tbaseline: { tier: \"cheap\", risk: \"read-only\", confidence: 0.5, reasonCode: \"fitness_probe\", reasons: [] },\n\t\t\tmaxWallClockMs,\n\t\t\tsignal: options.signal,\n\t\t\tcomplete,\n\t\t});\n\t\tjudge.meanMs += now() - started;\n\t\ttotalCostUsd += result.costUsd;\n\t\tconst tier = result.decision.tier;\n\t\tif (result.verdict) {\n\t\t\tjudge.parsed++;\n\t\t\t// A useful judge must both keep planning off the cheap tier AND actually send trivial\n\t\t\t// prompts there — all-medium verdicts are safe but save nothing.\n\t\t\tif (entry.planning && tier !== \"cheap\") judge.planningElevated++;\n\t\t\tif (!entry.planning && tier === \"cheap\") judge.trivialCheap++;\n\t\t}\n\t\tjudge.outcomes.push(\n\t\t\t`\"${entry.prompt.slice(0, 40)}\" -> ${tier}${result.fallbackReason ? ` (${result.fallbackReason})` : \"\"}`,\n\t\t);\n\t}\n\tjudge.meanMs = judgePrompts.length > 0 ? Math.round(judge.meanMs / judgePrompts.length) : 0;\n\tjudge.tokensPerSecond = takeSurfaceSpeed();\n\n\tconst probeSurface = async (\n\t\tsystemPrompt: string,\n\t\ttasks: readonly string[],\n\t\taccepts: (text: string, taskIndex: number) => boolean,\n\t): Promise<LaneFitnessScore> => {\n\t\tconst score: LaneFitnessScore = { succeeded: 0, total: tasks.length, outcomes: [], meanMs: 0 };\n\t\tfor (const [taskIndex, task] of tasks.entries()) {\n\t\t\tconst started = now();\n\t\t\t// Same wall-clock envelope as the lane surfaces — a hung model must not hang the probe.\n\t\t\tconst bounded = await runBoundedCompletion({\n\t\t\t\tmaxWallClockMs,\n\t\t\t\tsignal: options.signal,\n\t\t\t\texecute: (signal) => complete({ systemPrompt, userPrompt: task, signal }),\n\t\t\t});\n\t\t\tif (bounded.completion) totalCostUsd += bounded.completion.costUsd;\n\t\t\tif (bounded.failure || !bounded.completion) {\n\t\t\t\tscore.outcomes.push(bounded.failure ? bounded.failure.status : \"completion_error\");\n\t\t\t} else {\n\t\t\t\tconst ok = accepts(bounded.completion.text, taskIndex);\n\t\t\t\tif (ok) score.succeeded++;\n\t\t\t\tscore.outcomes.push(ok ? \"ok\" : \"unparseable_output\");\n\t\t\t}\n\t\t\tscore.meanMs += now() - started;\n\t\t}\n\t\tscore.meanMs = tasks.length > 0 ? Math.round(score.meanMs / tasks.length) : 0;\n\t\treturn score;\n\t};\n\n\tconst search = await probeSurface(SEARCH_PROBE_SYSTEM_PROMPT, SEARCH_PROBE_TASKS, parseSearchPlan);\n\tsearch.tokensPerSecond = takeSurfaceSpeed();\n\tconst toolCall = await probeSurface(TOOL_CALL_PROBE_SYSTEM_PROMPT, TOOL_CALL_PROBE_TASKS, parseToolCall);\n\ttoolCall.tokensPerSecond = takeSurfaceSpeed();\n\tconst digest = await probeSurface(\n\t\tCURATION_DIGEST_SYSTEM_PROMPT,\n\t\tDIGEST_PROBE_TASKS.map((task) => task.chunk),\n\t\t(text, taskIndex) => parseDigest(text, DIGEST_PROBE_TASKS[taskIndex]!.nonce),\n\t);\n\tdigest.tokensPerSecond = takeSurfaceSpeed();\n\n\tlet capacity: CapacityFitnessScore | undefined;\n\tif (options.capacityProbe) {\n\t\tconst result = await measureServedContextWindow({\n\t\t\tprobe: options.capacityProbe,\n\t\t\tcomplete,\n\t\t\tmaxWallClockMs,\n\t\t\tsignal: options.signal,\n\t\t\tnow,\n\t\t});\n\t\tcapacity = result.score;\n\t\ttotalCostUsd += result.costUsd;\n\t}\n\n\tconst tokensPerSecond =\n\t\toverallSpeed.evalMs > 0 ? Math.round((overallSpeed.tokens / overallSpeed.evalMs) * 1000) : undefined;\n\n\treturn { trials, tokensPerSecond, research, worker, judge, search, toolCall, digest, capacity, totalCostUsd };\n}\n\n/**\n * Pure verdict: true when the probe found ZERO successes on every LANE surface it actually graded\n * AND the judge (if it ran) also failed. A lane/judge with total 0 (i.e. never run) carries no\n * evidence and is excluded from the lane check — but at least one lane must actually have been\n * graded for an all-failed verdict at all: `gradedLanes.every(...)` is vacuously true over an\n * empty array, so a report where only the judge ran (every research/worker/search/toolCall/digest\n * lane is ungraded) is excluded explicitly rather than misread as \"all lanes failed\" on zero lane\n * evidence. An empty/degenerate report (nothing graded at all, lanes AND judge) is likewise never\n * mistaken for a failed one. This is the gate adoption flows must consult before assigning a role —\n * see `isProbeAllFailed` callers in interactive-mode.ts and agent-session.ts.\n */\nexport function isProbeAllFailed(report: ModelFitnessReport): boolean {\n\tconst lanes = [report.research, report.worker, report.search, report.toolCall, report.digest];\n\tconst gradedLanes = lanes.filter((lane) => lane.total > 0);\n\tconst judgeGraded = report.judge.total > 0;\n\tif (gradedLanes.length === 0 && !judgeGraded) return false;\n\tconst lanesAllFailed = gradedLanes.length > 0 && gradedLanes.every((lane) => lane.succeeded === 0);\n\tconst judgeFailed = !judgeGraded || report.judge.parsed === 0;\n\treturn lanesAllFailed && judgeFailed;\n}\n\n/** Compact human-readable report for tool output / interactive display. Bounded, no raw dumps. */\nexport function formatModelFitnessReport(model: string, report: ModelFitnessReport): string {\n\tconst speed = (tokensPerSecond: number | undefined) =>\n\t\ttokensPerSecond !== undefined ? `, ~${tokensPerSecond} tok/s` : \"\";\n\tconst lines = [\n\t\t`Model fitness: ${model} (${report.trials} trials/lane${speed(report.tokensPerSecond)})`,\n\t\t`- research lane: ${report.research.succeeded}/${report.research.total} succeeded, mean ${report.research.meanMs}ms${speed(report.research.tokensPerSecond)} [${report.research.outcomes.join(\", \")}]`,\n\t\t`- worker lane: ${report.worker.succeeded}/${report.worker.total} completed+accepted, mean ${report.worker.meanMs}ms${speed(report.worker.tokensPerSecond)} [${report.worker.outcomes.join(\", \")}]`,\n\t\t`- search plans: ${report.search.succeeded}/${report.search.total} well-formed, mean ${report.search.meanMs}ms${speed(report.search.tokensPerSecond)}`,\n\t\t`- tool calls: ${report.toolCall.succeeded}/${report.toolCall.total} well-formed, mean ${report.toolCall.meanMs}ms${speed(report.toolCall.tokensPerSecond)}`,\n\t\t`- digests: ${report.digest.succeeded}/${report.digest.total} faithful, mean ${report.digest.meanMs}ms${speed(report.digest.tokensPerSecond)}`,\n\t\t...(report.capacity\n\t\t\t? [\n\t\t\t\t\t`- capacity: served window ${report.capacity.servedContextWindow}/${report.capacity.registeredContextWindow} tokens, mean ${report.capacity.meanMs}ms`,\n\t\t\t\t]\n\t\t\t: []),\n\t\t`- route judge: parsed ${report.judge.parsed}/${report.judge.total}, planning-elevated ${report.judge.planningElevated}/${report.judge.planningTotal}, trivial-cheap ${report.judge.trivialCheap}/${report.judge.trivialTotal}, mean ${report.judge.meanMs}ms${speed(report.judge.tokensPerSecond)}`,\n\t\t...report.judge.outcomes.map((outcome) => ` ${outcome}`),\n\t];\n\tif (report.totalCostUsd > 0) {\n\t\tlines.push(`- probe cost: $${report.totalCostUsd.toFixed(4)}`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-fitness.js","sourceRoot":"","sources":["../../../src/core/research/model-fitness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,EACN,4BAA4B,EAC5B,6BAA6B,EAC7B,0BAA0B,EAC1B,6BAA6B,GAC7B,MAAM,iCAAiC,CAAC;AACzC,OA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uB,MAAM,CAAC,KAAK,CAAC,gBAAgB,IAAI,MAAM,CAAC,KAAK,CAAC,aAAa,mBAAmB,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,MAAM,CAAC,KAAK,CAAC,YAAY,UAAU,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE;QACtS,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,EAAE,CAAC;KAC3D,CAAC;IACF,IAAI,MAAM,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import { runBoundedCompletion } from \"../autonomy/bounded-completion.ts\";\nimport type { CapabilityEnvelope } from \"../autonomy/contracts.ts\";\nimport { runWorker } from \"../delegation/worker-runner.ts\";\nimport { parseModelOutputJsonObject } from \"../model-output-json.ts\";\nimport { runRouteJudge } from \"../model-router/route-judge.ts\";\nimport {\n\tCAPACITY_PROBE_SYSTEM_PROMPT,\n\tCURATION_DIGEST_SYSTEM_PROMPT,\n\tSEARCH_PROBE_SYSTEM_PROMPT,\n\tTOOL_CALL_PROBE_SYSTEM_PROMPT,\n} from \"../provider-prompt-contracts.ts\";\nimport { runResearch } from \"./research-runner.ts\";\n\nexport {\n\tCAPACITY_PROBE_SYSTEM_PROMPT,\n\tCURATION_DIGEST_SYSTEM_PROMPT as DIGEST_PROBE_SYSTEM_PROMPT,\n\tSEARCH_PROBE_SYSTEM_PROMPT,\n\tTOOL_CALL_PROBE_SYSTEM_PROMPT,\n};\n\n/**\n * Model fitness probe: measures whether a candidate model can actually drive the harness's\n * subagent contracts — the research lane, the delegated-worker lane, and the routing judge — by\n * running each real runner against the model and scoring parse/success rates plus judge\n * discrimination. Provider-free: the completion executor is injected, so this works against any\n * registered model (local Ollama models included) and against faux providers in tests.\n */\n\nexport interface FitnessCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n\t/** Output tokens generated (for tok/s). Optional: providers that don't report it are skipped. */\n\toutputTokens?: number;\n\t/** Pure generation time in ms (e.g. Ollama eval_duration). Falls back to wall-clock if absent. */\n\tevalMs?: number;\n}\n\nexport type FitnessComplete = (args: {\n\tsystemPrompt: string;\n\tuserPrompt: string;\n\tsignal?: AbortSignal;\n}) => Promise<FitnessCompletion>;\n\nexport interface JudgeFitnessPrompt {\n\tprompt: string;\n\t/** True when the prompt is planning-shaped and must never route cheap. */\n\tplanning: boolean;\n}\n\n/** Default judge probe set: three planning-shaped prompts, three trivial lookups. */\nexport const DEFAULT_JUDGE_FITNESS_PROMPTS: readonly JudgeFitnessPrompt[] = [\n\t{ prompt: \"how should we plan the migration of the session storage layer?\", planning: true },\n\t{ prompt: \"design an approach for splitting the settings manager\", planning: true },\n\t{ prompt: \"draft a roadmap for the autonomy rework\", planning: true },\n\t{ prompt: \"what does the resolvePath function return?\", planning: false },\n\t{ prompt: \"list the files in the delegation module\", planning: false },\n\t{ prompt: \"why is this test flaky?\", planning: false },\n];\n\nexport interface CapacityProbeOptions {\n\tregisteredContextWindow: number;\n\t/** Smallest candidate window to try before declaring the capacity unknown. Default 1024. */\n\tminContextWindow?: number;\n}\n\nexport interface ModelFitnessOptions {\n\tcomplete: FitnessComplete;\n\t/** Trials per lane surface. Default 3. */\n\ttrials?: number;\n\t/** Wall-clock budget per call in ms. Default 120000. */\n\tmaxWallClockMs?: number;\n\tjudgePrompts?: readonly JudgeFitnessPrompt[];\n\t/** Optional local-model capacity lane: measures the actually served context window. */\n\tcapacityProbe?: CapacityProbeOptions;\n\tsignal?: AbortSignal;\n\t/** Injected clock for latency measurement (test seam). Defaults to Date.now. */\n\tnow?: () => number;\n}\n\nexport interface LaneFitnessScore {\n\tsucceeded: number;\n\ttotal: number;\n\toutcomes: string[];\n\tmeanMs: number;\n\t/** Mean output tokens/second across the surface's calls; undefined when not reported. */\n\ttokensPerSecond?: number;\n}\n\nexport interface JudgeFitnessScore {\n\tparsed: number;\n\tplanningElevated: number;\n\tplanningTotal: number;\n\ttrivialCheap: number;\n\ttrivialTotal: number;\n\ttotal: number;\n\toutcomes: string[];\n\tmeanMs: number;\n\t/** Mean output tokens/second across the judge calls; undefined when not reported. */\n\ttokensPerSecond?: number;\n}\n\nexport interface CapacityFitnessScore {\n\tregisteredContextWindow: number;\n\tservedContextWindow: number;\n\toutcomes: string[];\n\tmeanMs: number;\n}\n\nexport interface ModelFitnessReport {\n\ttrials: number;\n\t/** Aggregate output tokens/second across ALL probe calls (the headline speed number). */\n\ttokensPerSecond?: number;\n\tresearch: LaneFitnessScore;\n\tworker: LaneFitnessScore;\n\tjudge: JudgeFitnessScore;\n\t/** Heavy-lifter surface: can the model formulate a structured search plan? */\n\tsearch: LaneFitnessScore;\n\t/** Heavy-lifter surface: can the model emit a well-formed tool call against a schema? */\n\ttoolCall: LaneFitnessScore;\n\t/** Curator surface: can the model digest a context chunk to strict JSON WITHOUT losing key facts? */\n\tdigest: LaneFitnessScore;\n\t/** Local-model capacity lane: measured context window the server actually serves. */\n\tcapacity?: CapacityFitnessScore;\n\ttotalCostUsd: number;\n}\n\n/** Static prompts for the heavy-lifter surfaces (stable for provider prompt caching). */\nconst SEARCH_PROBE_TASKS: readonly string[] = [\n\t\"Where is the retry/backoff logic for HTTP requests implemented?\",\n\t\"Which files define the settings for background research?\",\n\t\"Find where session entries of type custom are appended.\",\n];\n\n/**\n * Digest probe chunks each carry a NONCE identifier that cannot be guessed from the\n * instructions: acceptance requires the digest to RETAIN the nonce verbatim, so the score\n * measures extraction fidelity, not narration (a model cannot pass by paraphrasing).\n */\nconst DIGEST_PROBE_TASKS: readonly { chunk: string; nonce: string }[] = [\n\t{\n\t\tnonce: \"retryWithJitter_zx41\",\n\t\tchunk: [\n\t\t\t\"grep results for 'retry' under src/http:\",\n\t\t\t\"src/http/client.ts:88: export function retryWithJitter_zx41(fn, attempts = 3) {\",\n\t\t\t\"src/http/client.ts:112: // exponential backoff capped at 30s\",\n\t\t\t\"src/http/pool.ts:41: client.retry = false\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tnonce: \"ERR_QM_7734\",\n\t\tchunk: [\n\t\t\t\"$ npm run migrate\",\n\t\t\t\"migrating 14 files...\",\n\t\t\t\"error ERR_QM_7734: column 'owner_id' missing on table sessions (migration 0009)\",\n\t\t\t\"exit code 1\",\n\t\t].join(\"\\n\"),\n\t},\n\t{\n\t\tnonce: \"v3.9.2-hotfix.1\",\n\t\tchunk: [\n\t\t\t\"read package.json (34 lines):\",\n\t\t\t' \"name\": \"acme-billing\",',\n\t\t\t' \"version\": \"v3.9.2-hotfix.1\",',\n\t\t\t' \"engines\": { \"node\": \">=22\" },',\n\t\t].join(\"\\n\"),\n\t},\n];\n\nfunction parseDigest(text: string, nonce: string): boolean {\n\tconst parsed = parseModelOutputJsonObject(text);\n\tif (!parsed) return false;\n\tconst digest = (parsed as { digest?: unknown }).digest;\n\tif (typeof digest !== \"string\") return false;\n\tconst trimmed = digest.trim();\n\t// Bounded and faithful: short enough to be a stub annotation, still carrying the nonce fact.\n\treturn trimmed.length > 0 && trimmed.length <= 240 && trimmed.includes(nonce);\n}\n\nconst TOOL_CALL_PROBE_TASKS: readonly string[] = [\n\t\"Find usages of the function resolveCliModel under src/.\",\n\t\"Search for the string 'budget_exhausted' in the core directory.\",\n\t\"Locate where LaneTracker is instantiated under src/core.\",\n];\n\nfunction parseSearchPlan(text: string): boolean {\n\tconst parsed = parseModelOutputJsonObject(text);\n\tif (!parsed) return false;\n\tconst queries = (parsed as { queries?: unknown }).queries;\n\tif (!Array.isArray(queries) || queries.length === 0 || queries.length > 8) return false;\n\treturn queries.every(\n\t\t(query) =>\n\t\t\tquery &&\n\t\t\ttypeof query === \"object\" &&\n\t\t\ttypeof (query as { pattern?: unknown }).pattern === \"string\" &&\n\t\t\t(query as { pattern: string }).pattern.trim().length > 0,\n\t);\n}\n\nfunction parseToolCall(text: string): boolean {\n\tconst parsed = parseModelOutputJsonObject(text);\n\tif (!parsed) return false;\n\tconst record = parsed as { tool?: unknown; arguments?: unknown };\n\tif (record.tool !== \"grep\") return false;\n\tconst args = record.arguments;\n\tif (!args || typeof args !== \"object\" || Array.isArray(args)) return false;\n\tconst pattern = (args as { pattern?: unknown }).pattern;\n\tconst path = (args as { path?: unknown }).path;\n\treturn (\n\t\ttypeof pattern === \"string\" && pattern.trim().length > 0 && typeof path === \"string\" && path.trim().length > 0\n\t);\n}\n\nfunction fitnessEnvelope(): CapabilityEnvelope {\n\treturn {\n\t\tid: \"model-fitness-probe\",\n\t\tcapabilities: [\"research.execute\", \"filesystem.read\", \"memory.query\"],\n\t\tmaxEstimatedUsd: 1,\n\t\tcreatedAt: new Date().toISOString(),\n\t};\n}\n\nfunction buildCapacityProbePrompt(targetTokens: number, startNeedle: string, endNeedle: string): string {\n\tconst targetChars = Math.max(\n\t\tstartNeedle.length + endNeedle.length + 64,\n\t\ttargetTokens * 4 - CAPACITY_PROBE_SYSTEM_PROMPT.length,\n\t);\n\tconst prefix = `CAPACITY PROBE START\\n${startNeedle}\\n`;\n\tconst suffix = `\\n${endNeedle}\\nCAPACITY PROBE END`;\n\tconst fillerLength = Math.max(0, targetChars - prefix.length - suffix.length);\n\treturn `${prefix}${\"x \".repeat(Math.ceil(fillerLength / 2)).slice(0, fillerLength)}${suffix}`;\n}\n\nasync function measureServedContextWindow(args: {\n\tprobe: CapacityProbeOptions;\n\tcomplete: FitnessComplete;\n\tmaxWallClockMs: number;\n\tsignal?: AbortSignal;\n\tnow: () => number;\n}): Promise<{ score: CapacityFitnessScore; costUsd: number }> {\n\tconst registered = Math.max(1, Math.floor(args.probe.registeredContextWindow));\n\tconst minWindow = Math.max(1, Math.floor(args.probe.minContextWindow ?? 1024));\n\tconst nonce = `${registered.toString(16).toUpperCase()}_${minWindow.toString(16).toUpperCase()}`;\n\tconst startNeedle = `NEEDLE_START_${nonce}`;\n\tconst endNeedle = `NEEDLE_END_${nonce}`;\n\tconst score: CapacityFitnessScore = {\n\t\tregisteredContextWindow: registered,\n\t\tservedContextWindow: 0,\n\t\toutcomes: [],\n\t\tmeanMs: 0,\n\t};\n\tlet candidate = registered;\n\tlet costUsd = 0;\n\tlet calls = 0;\n\twhile (candidate >= minWindow) {\n\t\tconst started = args.now();\n\t\tcalls++;\n\t\tconst bounded = await runBoundedCompletion({\n\t\t\tmaxWallClockMs: args.maxWallClockMs,\n\t\t\tsignal: args.signal,\n\t\t\texecute: (signal) =>\n\t\t\t\targs.complete({\n\t\t\t\t\tsystemPrompt: CAPACITY_PROBE_SYSTEM_PROMPT,\n\t\t\t\t\tuserPrompt: buildCapacityProbePrompt(candidate, startNeedle, endNeedle),\n\t\t\t\t\tsignal,\n\t\t\t\t}),\n\t\t});\n\t\tscore.meanMs += args.now() - started;\n\t\tif (bounded.completion) costUsd += bounded.completion.costUsd;\n\t\tconst output = bounded.completion?.text.trim() ?? \"\";\n\t\tconst recalled = !bounded.failure && output.includes(startNeedle) && output.includes(endNeedle);\n\t\tscore.outcomes.push(`${candidate}:${recalled ? \"ok\" : (bounded.failure?.status ?? \"miss\")}`);\n\t\tif (recalled) {\n\t\t\tscore.servedContextWindow = candidate;\n\t\t\tbreak;\n\t\t}\n\t\tcandidate = Math.floor(candidate / 2);\n\t}\n\tif (score.servedContextWindow === 0) score.servedContextWindow = minWindow;\n\tscore.meanMs = calls > 0 ? Math.round(score.meanMs / calls) : 0;\n\treturn { score, costUsd };\n}\n\nexport async function runModelFitnessProbe(options: ModelFitnessOptions): Promise<ModelFitnessReport> {\n\tconst trials = Math.max(1, Math.min(options.trials ?? 3, 20));\n\tconst maxWallClockMs = options.maxWallClockMs ?? 120_000;\n\tconst judgePrompts = options.judgePrompts ?? DEFAULT_JUDGE_FITNESS_PROMPTS;\n\tconst now = options.now ?? Date.now;\n\tlet totalCostUsd = 0;\n\n\t// Token-speed instrumentation: the lane runners' own contracts carry text/cost only, so the\n\t// completer is wrapped once here and generation stats are accumulated per surface.\n\tconst overallSpeed = { tokens: 0, evalMs: 0 };\n\tlet surfaceSpeed = { tokens: 0, evalMs: 0 };\n\tconst complete: FitnessComplete = async (args) => {\n\t\tconst completion = await options.complete(args);\n\t\tconst tokens = completion.outputTokens ?? 0;\n\t\tconst evalMs = completion.evalMs ?? 0;\n\t\tif (tokens > 0 && evalMs > 0) {\n\t\t\tsurfaceSpeed.tokens += tokens;\n\t\t\tsurfaceSpeed.evalMs += evalMs;\n\t\t\toverallSpeed.tokens += tokens;\n\t\t\toverallSpeed.evalMs += evalMs;\n\t\t}\n\t\treturn completion;\n\t};\n\tconst takeSurfaceSpeed = (): number | undefined => {\n\t\tconst speed =\n\t\t\tsurfaceSpeed.evalMs > 0 ? Math.round((surfaceSpeed.tokens / surfaceSpeed.evalMs) * 1000) : undefined;\n\t\tsurfaceSpeed = { tokens: 0, evalMs: 0 };\n\t\treturn speed;\n\t};\n\n\tconst research: LaneFitnessScore = { succeeded: 0, total: trials, outcomes: [], meanMs: 0 };\n\tfor (let i = 0; i < trials; i++) {\n\t\tconst started = now();\n\t\tconst result = await runResearch({\n\t\t\tquery: `fitness:probe requirements:req-${i}`,\n\t\t\tcontext: [\n\t\t\t\t\"Goal: add a retry helper to the HTTP client module\",\n\t\t\t\t\"Open requirements:\",\n\t\t\t\t\"- Find what retry/backoff conventions the codebase already uses\",\n\t\t\t\t\"- Identify which call sites would adopt the helper\",\n\t\t\t].join(\"\\n\"),\n\t\t\tenvelope: fitnessEnvelope(),\n\t\t\tmaxUsd: 1,\n\t\t\tmaxSources: 8,\n\t\t\tmaxFindings: 5,\n\t\t\tmaxWallClockMs,\n\t\t\tsignal: options.signal,\n\t\t\tcomplete,\n\t\t});\n\t\tresearch.meanMs += now() - started;\n\t\ttotalCostUsd += result.costUsd;\n\t\tif (result.status === \"succeeded\") research.succeeded++;\n\t\tresearch.outcomes.push(`${result.status}/${result.reasonCode}`);\n\t}\n\tresearch.meanMs = Math.round(research.meanMs / trials);\n\tresearch.tokensPerSecond = takeSurfaceSpeed();\n\n\tconst worker: LaneFitnessScore = { succeeded: 0, total: trials, outcomes: [], meanMs: 0 };\n\tfor (let i = 0; i < trials; i++) {\n\t\tconst started = now();\n\t\tconst outcome = await runWorker({\n\t\t\trequest: {\n\t\t\t\tid: `fitness-worker-${i}`,\n\t\t\t\tinstructions:\n\t\t\t\t\t\"Summarize in two sentences what a capability envelope is: a declared set of allowed tools, paths, and capability names that bounds what a delegated worker may do.\",\n\t\t\t\troute: { tier: \"cheap\", risk: \"read-only\", confidence: 1, reasonCode: \"fitness_probe\", reasons: [] },\n\t\t\t\tenvelope: { id: `fitness-env-${i}`, capabilities: [\"filesystem.read\"], maxEstimatedUsd: 1 },\n\t\t\t\tmaxEstimatedUsd: 1,\n\t\t\t},\n\t\t\tmaxUsd: 1,\n\t\t\tmaxWallClockMs,\n\t\t\tusageReportId: `fitness:${i}`,\n\t\t\tsignal: options.signal,\n\t\t\tcomplete,\n\t\t});\n\t\tworker.meanMs += now() - started;\n\t\ttotalCostUsd += outcome.costUsd;\n\t\tif (outcome.claim.status === \"completed\" && outcome.accepted) worker.succeeded++;\n\t\tworker.outcomes.push(`${outcome.claim.status}/${outcome.reasonCode}`);\n\t}\n\tworker.meanMs = Math.round(worker.meanMs / trials);\n\tworker.tokensPerSecond = takeSurfaceSpeed();\n\n\tconst judge: JudgeFitnessScore = {\n\t\tparsed: 0,\n\t\tplanningElevated: 0,\n\t\tplanningTotal: judgePrompts.filter((entry) => entry.planning).length,\n\t\ttrivialCheap: 0,\n\t\ttrivialTotal: judgePrompts.filter((entry) => !entry.planning).length,\n\t\ttotal: judgePrompts.length,\n\t\toutcomes: [],\n\t\tmeanMs: 0,\n\t};\n\tfor (const entry of judgePrompts) {\n\t\tconst started = now();\n\t\tconst result = await runRouteJudge({\n\t\t\tprompt: entry.prompt,\n\t\t\tbaseline: { tier: \"cheap\", risk: \"read-only\", confidence: 0.5, reasonCode: \"fitness_probe\", reasons: [] },\n\t\t\tmaxWallClockMs,\n\t\t\tsignal: options.signal,\n\t\t\tcomplete,\n\t\t});\n\t\tjudge.meanMs += now() - started;\n\t\ttotalCostUsd += result.costUsd;\n\t\tconst tier = result.decision.tier;\n\t\tif (result.verdict) {\n\t\t\tjudge.parsed++;\n\t\t\t// A useful judge must both keep planning off the cheap tier AND actually send trivial\n\t\t\t// prompts there — all-medium verdicts are safe but save nothing.\n\t\t\tif (entry.planning && tier !== \"cheap\") judge.planningElevated++;\n\t\t\tif (!entry.planning && tier === \"cheap\") judge.trivialCheap++;\n\t\t}\n\t\tjudge.outcomes.push(\n\t\t\t`\"${entry.prompt.slice(0, 40)}\" -> ${tier}${result.fallbackReason ? ` (${result.fallbackReason})` : \"\"}`,\n\t\t);\n\t}\n\tjudge.meanMs = judgePrompts.length > 0 ? Math.round(judge.meanMs / judgePrompts.length) : 0;\n\tjudge.tokensPerSecond = takeSurfaceSpeed();\n\n\tconst probeSurface = async (\n\t\tsystemPrompt: string,\n\t\ttasks: readonly string[],\n\t\taccepts: (text: string, taskIndex: number) => boolean,\n\t): Promise<LaneFitnessScore> => {\n\t\tconst score: LaneFitnessScore = { succeeded: 0, total: tasks.length, outcomes: [], meanMs: 0 };\n\t\tfor (const [taskIndex, task] of tasks.entries()) {\n\t\t\tconst started = now();\n\t\t\t// Same wall-clock envelope as the lane surfaces — a hung model must not hang the probe.\n\t\t\tconst bounded = await runBoundedCompletion({\n\t\t\t\tmaxWallClockMs,\n\t\t\t\tsignal: options.signal,\n\t\t\t\texecute: (signal) => complete({ systemPrompt, userPrompt: task, signal }),\n\t\t\t});\n\t\t\tif (bounded.completion) totalCostUsd += bounded.completion.costUsd;\n\t\t\tif (bounded.failure || !bounded.completion) {\n\t\t\t\tscore.outcomes.push(bounded.failure ? bounded.failure.status : \"completion_error\");\n\t\t\t} else {\n\t\t\t\tconst ok = accepts(bounded.completion.text, taskIndex);\n\t\t\t\tif (ok) score.succeeded++;\n\t\t\t\tscore.outcomes.push(ok ? \"ok\" : \"unparseable_output\");\n\t\t\t}\n\t\t\tscore.meanMs += now() - started;\n\t\t}\n\t\tscore.meanMs = tasks.length > 0 ? Math.round(score.meanMs / tasks.length) : 0;\n\t\treturn score;\n\t};\n\n\tconst search = await probeSurface(SEARCH_PROBE_SYSTEM_PROMPT, SEARCH_PROBE_TASKS, parseSearchPlan);\n\tsearch.tokensPerSecond = takeSurfaceSpeed();\n\tconst toolCall = await probeSurface(TOOL_CALL_PROBE_SYSTEM_PROMPT, TOOL_CALL_PROBE_TASKS, parseToolCall);\n\ttoolCall.tokensPerSecond = takeSurfaceSpeed();\n\tconst digest = await probeSurface(\n\t\tCURATION_DIGEST_SYSTEM_PROMPT,\n\t\tDIGEST_PROBE_TASKS.map((task) => task.chunk),\n\t\t(text, taskIndex) => parseDigest(text, DIGEST_PROBE_TASKS[taskIndex]!.nonce),\n\t);\n\tdigest.tokensPerSecond = takeSurfaceSpeed();\n\n\tlet capacity: CapacityFitnessScore | undefined;\n\tif (options.capacityProbe) {\n\t\tconst result = await measureServedContextWindow({\n\t\t\tprobe: options.capacityProbe,\n\t\t\tcomplete,\n\t\t\tmaxWallClockMs,\n\t\t\tsignal: options.signal,\n\t\t\tnow,\n\t\t});\n\t\tcapacity = result.score;\n\t\ttotalCostUsd += result.costUsd;\n\t}\n\n\tconst tokensPerSecond =\n\t\toverallSpeed.evalMs > 0 ? Math.round((overallSpeed.tokens / overallSpeed.evalMs) * 1000) : undefined;\n\n\treturn { trials, tokensPerSecond, research, worker, judge, search, toolCall, digest, capacity, totalCostUsd };\n}\n\n/**\n * Pure verdict: true when the probe found ZERO successes on every LANE surface it actually graded\n * AND the judge (if it ran) also failed. A lane/judge with total 0 (i.e. never run) carries no\n * evidence and is excluded from the lane check — but at least one lane must actually have been\n * graded for an all-failed verdict at all: `gradedLanes.every(...)` is vacuously true over an\n * empty array, so a report where only the judge ran (every research/worker/search/toolCall/digest\n * lane is ungraded) is excluded explicitly rather than misread as \"all lanes failed\" on zero lane\n * evidence. An empty/degenerate report (nothing graded at all, lanes AND judge) is likewise never\n * mistaken for a failed one. This is the gate adoption flows must consult before assigning a role —\n * see `isProbeAllFailed` callers in interactive-mode.ts and agent-session.ts.\n */\nexport function isProbeAllFailed(report: ModelFitnessReport): boolean {\n\tconst lanes = [report.research, report.worker, report.search, report.toolCall, report.digest];\n\tconst gradedLanes = lanes.filter((lane) => lane.total > 0);\n\tconst judgeGraded = report.judge.total > 0;\n\tif (gradedLanes.length === 0 && !judgeGraded) return false;\n\tconst lanesAllFailed = gradedLanes.length > 0 && gradedLanes.every((lane) => lane.succeeded === 0);\n\tconst judgeFailed = !judgeGraded || report.judge.parsed === 0;\n\treturn lanesAllFailed && judgeFailed;\n}\n\n/** Compact human-readable report for tool output / interactive display. Bounded, no raw dumps. */\nexport function formatModelFitnessReport(model: string, report: ModelFitnessReport): string {\n\tconst speed = (tokensPerSecond: number | undefined) =>\n\t\ttokensPerSecond !== undefined ? `, ~${tokensPerSecond} tok/s` : \"\";\n\tconst lines = [\n\t\t`Model fitness: ${model} (${report.trials} trials/lane${speed(report.tokensPerSecond)})`,\n\t\t`- research lane: ${report.research.succeeded}/${report.research.total} succeeded, mean ${report.research.meanMs}ms${speed(report.research.tokensPerSecond)} [${report.research.outcomes.join(\", \")}]`,\n\t\t`- worker lane: ${report.worker.succeeded}/${report.worker.total} completed+accepted, mean ${report.worker.meanMs}ms${speed(report.worker.tokensPerSecond)} [${report.worker.outcomes.join(\", \")}]`,\n\t\t`- search plans: ${report.search.succeeded}/${report.search.total} well-formed, mean ${report.search.meanMs}ms${speed(report.search.tokensPerSecond)}`,\n\t\t`- tool calls: ${report.toolCall.succeeded}/${report.toolCall.total} well-formed, mean ${report.toolCall.meanMs}ms${speed(report.toolCall.tokensPerSecond)}`,\n\t\t`- digests: ${report.digest.succeeded}/${report.digest.total} faithful, mean ${report.digest.meanMs}ms${speed(report.digest.tokensPerSecond)}`,\n\t\t...(report.capacity\n\t\t\t? [\n\t\t\t\t\t`- capacity: served window ${report.capacity.servedContextWindow}/${report.capacity.registeredContextWindow} tokens, mean ${report.capacity.meanMs}ms`,\n\t\t\t\t]\n\t\t\t: []),\n\t\t`- route judge: parsed ${report.judge.parsed}/${report.judge.total}, planning-elevated ${report.judge.planningElevated}/${report.judge.planningTotal}, trivial-cheap ${report.judge.trivialCheap}/${report.judge.trivialTotal}, mean ${report.judge.meanMs}ms${speed(report.judge.tokensPerSecond)}`,\n\t\t...report.judge.outcomes.map((outcome) => ` ${outcome}`),\n\t];\n\tif (report.totalCostUsd > 0) {\n\t\tlines.push(`- probe cost: $${report.totalCostUsd.toFixed(4)}`);\n\t}\n\treturn lines.join(\"\\n\");\n}\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { CapabilityEnvelope, EvidenceBundle, EvidenceRef, GateOutcome } from "../autonomy/contracts.ts";
|
|
2
2
|
import { type EvidenceFindingDraft } from "../autonomy/evidence-finding-projection.ts";
|
|
3
|
+
import { RESEARCH_LANE_SYSTEM_PROMPT } from "../provider-prompt-contracts.ts";
|
|
4
|
+
export { RESEARCH_LANE_SYSTEM_PROMPT };
|
|
3
5
|
/**
|
|
4
6
|
* Pure orchestration for one autonomous research pass: gate -> bounded isolated completion ->
|
|
5
7
|
* parse -> evidence bundle. The model executor is injected so this stays provider-free and
|
|
@@ -9,7 +11,6 @@ import { type EvidenceFindingDraft } from "../autonomy/evidence-finding-projecti
|
|
|
9
11
|
* surface, and the output is an `EvidenceBundle` whose model-synthesized findings are untrusted.
|
|
10
12
|
*/
|
|
11
13
|
/** Static across calls so callers can use `cacheRetention: "short"` and only pay for the variable tail. */
|
|
12
|
-
export declare const RESEARCH_LANE_SYSTEM_PROMPT: string;
|
|
13
14
|
export interface ResearchCompletion {
|
|
14
15
|
text: string;
|
|
15
16
|
costUsd: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"research-runner.d.ts","sourceRoot":"","sources":["../../../src/core/research/research-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC7G,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"research-runner.d.ts","sourceRoot":"","sources":["../../../src/core/research/research-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC7G,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAI9E,OAAO,EAAE,2BAA2B,EAAE,CAAC;AAEvC;;;;;;;GAOG;AAEH,2GAA2G;AAC3G,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,iGAAiG;IACjG,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,QAAQ,EAAE,kBAAkB,CAAC;IAC7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IACjC,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,cAAc,EAAE,MAAM,CAAC;IACvB,wFAAwF;IACxF,QAAQ,EAAE,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CA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