@caupulican/pi-adaptative 0.90.7 → 0.90.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -0
- package/dist/bundled-resources/skills/tool-call-repair/SKILL.md +5 -4
- package/dist/bundled-resources/skills/tool-call-repair/references/failure-grammar.md +6 -3
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +1 -0
- package/dist/core/agent-session-contracts.d.ts +2 -0
- package/dist/core/agent-session-contracts.d.ts.map +1 -1
- package/dist/core/agent-session-contracts.js.map +1 -1
- package/dist/core/agent-session.d.ts +8 -7
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +80 -196
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +7 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +8 -2
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +1 -1
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +14 -0
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +32 -0
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/billing-failover-controller.js +1 -1
- package/dist/core/billing-failover-controller.js.map +1 -1
- package/dist/core/context/current-work-memory.d.ts +1 -1
- package/dist/core/context/current-work-memory.d.ts.map +1 -1
- package/dist/core/context/current-work-memory.js +2 -1
- package/dist/core/context/current-work-memory.js.map +1 -1
- package/dist/core/context/long-term-memory-trigger.d.ts +1 -1
- package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
- package/dist/core/context/long-term-memory-trigger.js +2 -1
- package/dist/core/context/long-term-memory-trigger.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +2 -2
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +13 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +71 -8
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +13 -8
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js +14 -1
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +3 -2
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +95 -42
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.js +5 -1
- package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js +7 -4
- package/dist/core/delegation/worker-lane-projection.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +8 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.d.ts +21 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.js +65 -2
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +7 -0
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +24 -7
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-system-prompt.d.ts +54 -0
- package/dist/core/delegation/worker-system-prompt.d.ts.map +1 -0
- package/dist/core/delegation/worker-system-prompt.js +85 -0
- package/dist/core/delegation/worker-system-prompt.js.map +1 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.js +4 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +4 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js +28 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.d.ts.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.js +14 -3
- package/dist/core/durable-custom-message-turn-controller.js.map +1 -1
- package/dist/core/extension-binding-controller.d.ts +107 -0
- package/dist/core/extension-binding-controller.d.ts.map +1 -0
- package/dist/core/extension-binding-controller.js +224 -0
- package/dist/core/extension-binding-controller.js.map +1 -0
- package/dist/core/extensions/types.d.ts +2 -0
- 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.d.ts +9 -0
- package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +35 -9
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +10 -1
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +2 -1
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-execution-errors.d.ts +18 -0
- package/dist/core/goals/goal-execution-errors.d.ts.map +1 -0
- package/dist/core/goals/goal-execution-errors.js +21 -0
- package/dist/core/goals/goal-execution-errors.js.map +1 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
- package/dist/core/goals/goal-lifecycle.js +3 -3
- package/dist/core/goals/goal-lifecycle.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +11 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +74 -14
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/goals/goal-state.js +1 -1
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +2 -2
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/natural-language-goal.d.ts +18 -0
- package/dist/core/goals/natural-language-goal.d.ts.map +1 -1
- package/dist/core/goals/natural-language-goal.js +99 -16
- package/dist/core/goals/natural-language-goal.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +10 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +3 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +4 -4
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +8 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +9 -7
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/task-runtime-reducer.js +1 -1
- package/dist/core/orchestration/task-runtime-reducer.js.map +1 -1
- package/dist/core/orchestration/worker-model-pins.d.ts +7 -0
- package/dist/core/orchestration/worker-model-pins.d.ts.map +1 -1
- package/dist/core/orchestration/worker-model-pins.js +17 -1
- package/dist/core/orchestration/worker-model-pins.js.map +1 -1
- package/dist/core/provider-request-runtime-controller.d.ts +9 -0
- package/dist/core/provider-request-runtime-controller.d.ts.map +1 -1
- package/dist/core/provider-request-runtime-controller.js +17 -3
- package/dist/core/provider-request-runtime-controller.js.map +1 -1
- package/dist/core/provider-tool-text.d.ts +15 -1
- package/dist/core/provider-tool-text.d.ts.map +1 -1
- package/dist/core/provider-tool-text.js +42 -10
- package/dist/core/provider-tool-text.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +1 -1
- package/dist/core/research/research-lane-controller.d.ts.map +1 -1
- package/dist/core/research/research-lane-controller.js +2 -1
- package/dist/core/research/research-lane-controller.js.map +1 -1
- package/dist/core/resource-loader.d.ts +3 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +8 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +8 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +6 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/session-supervision-runtime.d.ts.map +1 -1
- package/dist/core/session-supervision-runtime.js +2 -1
- package/dist/core/session-supervision-runtime.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +7 -2
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +13 -0
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +20 -18
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/util/atomic-file.d.ts +7 -0
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +8 -6
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/core/util/faultable-fs.d.ts +30 -0
- package/dist/core/util/faultable-fs.d.ts.map +1 -0
- package/dist/core/util/faultable-fs.js +30 -0
- package/dist/core/util/faultable-fs.js.map +1 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +1 -0
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
- package/dist/modes/interactive/components/activity-lane.js +4 -3
- package/dist/modes/interactive/components/activity-lane.js.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +2 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +3 -2
- package/dist/modes/interactive/components/oauth-selector.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/session-flow-commands.d.ts +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +3 -2
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/docs/providers.md +3 -0
- package/docs/settings.md +4 -2
- package/docs/tool-repair.md +1 -0
- 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/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +9 -4
|
@@ -16,7 +16,13 @@ export type BoundedCompletionFailureStatus = "canceled" | "timeout" | "failed" |
|
|
|
16
16
|
export declare class BoundedCompletionFailureError extends Error {
|
|
17
17
|
readonly status: BoundedCompletionFailureStatus;
|
|
18
18
|
readonly reasonCode: string;
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* `cause`, when the error wraps an upstream failure (e.g. an exhausted provider retry ladder),
|
|
21
|
+
* preserves the original error's identity/type/stack for callers that need to inspect it —
|
|
22
|
+
* wrapping otherwise launders it down to a message string, which the redacted `detail` extracted
|
|
23
|
+
* by {@link boundedFailureDetail} intentionally is not a substitute for.
|
|
24
|
+
*/
|
|
25
|
+
constructor(status: BoundedCompletionFailureStatus, reasonCode: string, message: string, cause?: unknown);
|
|
20
26
|
}
|
|
21
27
|
export interface BoundedCompletionOutcome {
|
|
22
28
|
/** Present when the executor settled; may coexist with `failure` when an abort raced the result. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-completion.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/bounded-completion.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,8BAA8B,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,kBAAkB,CAAC;AAEpG;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;IACvD,QAAQ,CAAC,MAAM,EAAE,8BAA8B,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B,YAAY,MAAM,EAAE,8BAA8B,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"bounded-completion.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/bounded-completion.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,8BAA8B,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,kBAAkB,CAAC;AAEpG;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;IACvD,QAAQ,CAAC,MAAM,EAAE,8BAA8B,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;;;OAKG;IACH,YAAY,MAAM,EAAE,8BAA8B,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAKvG;CACD;AAED,MAAM,WAAW,wBAAwB;IACxC,oGAAoG;IACpG,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,8BAA8B,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1F;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIvE;AA2BD,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAChD,qDAAqD;IACrD,cAAc,EAAE,MAAM,CAAC;IACvB,qDAAqD;IACrD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC7D,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAmFpC"}
|
|
@@ -4,8 +4,14 @@ import { boundedRedactedDiagnosticText } from "../security/secret-text.js";
|
|
|
4
4
|
* completion envelope to infer a bounded denial from human-readable error text.
|
|
5
5
|
*/
|
|
6
6
|
export class BoundedCompletionFailureError extends Error {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* `cause`, when the error wraps an upstream failure (e.g. an exhausted provider retry ladder),
|
|
9
|
+
* preserves the original error's identity/type/stack for callers that need to inspect it —
|
|
10
|
+
* wrapping otherwise launders it down to a message string, which the redacted `detail` extracted
|
|
11
|
+
* by {@link boundedFailureDetail} intentionally is not a substitute for.
|
|
12
|
+
*/
|
|
13
|
+
constructor(status, reasonCode, message, cause) {
|
|
14
|
+
super(message, cause !== undefined ? { cause } : undefined);
|
|
9
15
|
this.name = "BoundedCompletionFailureError";
|
|
10
16
|
this.status = status;
|
|
11
17
|
this.reasonCode = reasonCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-completion.js","sourceRoot":"","sources":["../../../src/core/autonomy/bounded-completion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAgB3E;;;GAGG;AACH,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IAIvD,YAAY,MAAsC,EAAE,UAAkB,EAAE,OAAe;QACtF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAQD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAClD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACvG,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,OAAO,6BAA6B,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AAID,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAE9C,SAAS,YAAY,CAAC,IAGrB;IACA,IAAI,IAAI,CAAC,cAAc,EAAE,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC9F,IAAI,IAAI,CAAC,aAAa,CAAC,OAAO;QAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,qBAAqB,EAAE,CAA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AAC,OAAO,EAAE,CAAC;YAC9D,OAAO;gBACN,UAAU;gBACV,OAAO,EAAE,YAAY,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,iBAAiB,CAAC,MAAM,EAAE,CAAC;aAC/F,CAAC;QACH,CAAC;QACD,OAAO,EAAE,UAAU,EAAE,CAAC;IACvB,CAAC;YAAS,CAAC;QACV,IAAI,YAAY,KAAK,SAAS;YAAE,YAAY,CAAC,YAAY,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAC5D,CAAC;AACF,CAAC","sourcesContent":["import { boundedRedactedDiagnosticText } from \"../security/secret-text.ts\";\n\n/**\n * Shared wall-clock/cancellation envelope for one-shot lane completions (research and delegated workers).\n * Composes an optional external abort signal with an internal wall-clock timeout, executes the\n * injected completion, and maps every failure to a stable status/reasonCode pair. Never throws.\n */\n\nexport interface BoundedCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n}\n\nexport type BoundedCompletionFailureStatus = \"canceled\" | \"timeout\" | \"failed\" | \"budget_exhausted\";\n\n/**\n * Typed failure crossing the executor boundary. Policy owners use this instead of forcing the\n * completion envelope to infer a bounded denial from human-readable error text.\n */\nexport class BoundedCompletionFailureError extends Error {\n\treadonly status: BoundedCompletionFailureStatus;\n\treadonly reasonCode: string;\n\n\tconstructor(status: BoundedCompletionFailureStatus, reasonCode: string, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"BoundedCompletionFailureError\";\n\t\tthis.status = status;\n\t\tthis.reasonCode = reasonCode;\n\t}\n}\n\nexport interface BoundedCompletionOutcome {\n\t/** Present when the executor settled; may coexist with `failure` when an abort raced the result. */\n\tcompletion?: BoundedCompletion;\n\tfailure?: { status: BoundedCompletionFailureStatus; reasonCode: string; detail?: string };\n}\n\n/**\n * Preserve the executor's actual error alongside the stable reason code. A bare\n * `completion_error` is undiagnosable from lane records alone (field lesson: workers dying\n * on provider socket drops and budget denials all flattened to the same code).\n */\nexport function boundedFailureDetail(error: unknown): string | undefined {\n\tconst message = error instanceof Error ? error.message : typeof error === \"string\" ? error : undefined;\n\tif (!message) return undefined;\n\treturn boundedRedactedDiagnosticText(message);\n}\n\ntype ExecutorSettlement = { kind: \"completion\"; completion: BoundedCompletion } | { kind: \"error\"; error: unknown };\n\nconst MAX_HOST_TIMER_DELAY_MS = 2_147_483_647;\n\nfunction abortFailure(args: {\n\texternalSignal?: AbortSignal;\n\ttimeoutSignal: AbortSignal;\n}): BoundedCompletionOutcome[\"failure\"] {\n\tif (args.externalSignal?.aborted) return { status: \"canceled\", reasonCode: \"external_abort\" };\n\tif (args.timeoutSignal.aborted) return { status: \"timeout\", reasonCode: \"wall_clock_exceeded\" };\n\treturn { status: \"failed\", reasonCode: \"completion_error\" };\n}\n\nfunction executorFailure(error: unknown): BoundedCompletionOutcome[\"failure\"] {\n\tconst detail = boundedFailureDetail(error);\n\tif (error instanceof BoundedCompletionFailureError) {\n\t\treturn {\n\t\t\tstatus: error.status,\n\t\t\treasonCode: error.reasonCode,\n\t\t\t...(detail ? { detail } : {}),\n\t\t};\n\t}\n\treturn { status: \"failed\", reasonCode: \"completion_error\", ...(detail ? { detail } : {}) };\n}\n\nexport async function runBoundedCompletion(args: {\n\t/** Wall-clock budget in milliseconds; 0 disables. */\n\tmaxWallClockMs: number;\n\t/** External cancellation (e.g. session disposal). */\n\tsignal?: AbortSignal;\n\texecute: (signal: AbortSignal) => Promise<BoundedCompletion>;\n}): Promise<BoundedCompletionOutcome> {\n\tconst timeoutController = new AbortController();\n\tlet resolveAbort!: () => void;\n\tconst abortPromise = new Promise<{ kind: \"abort\" }>((resolve) => {\n\t\tresolveAbort = () => resolve({ kind: \"abort\" });\n\t});\n\tconst onExternalAbort = (): void => resolveAbort();\n\targs.signal?.addEventListener(\"abort\", onExternalAbort, { once: true });\n\tlet timeoutTimer: ReturnType<typeof setTimeout> | undefined;\n\tlet remainingWallClockMs = args.maxWallClockMs;\n\tconst armTimeout = (): void => {\n\t\tconst delayMs = Math.min(remainingWallClockMs, MAX_HOST_TIMER_DELAY_MS);\n\t\ttimeoutTimer = setTimeout(() => {\n\t\t\tremainingWallClockMs -= delayMs;\n\t\t\tif (remainingWallClockMs > 0) {\n\t\t\t\tarmTimeout();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttimeoutController.abort();\n\t\t\tresolveAbort();\n\t\t}, delayMs);\n\t\tif (typeof timeoutTimer === \"object\" && \"unref\" in timeoutTimer) {\n\t\t\tconst { unref } = timeoutTimer as { unref?: () => void };\n\t\t\tunref?.call(timeoutTimer);\n\t\t}\n\t};\n\tif (args.maxWallClockMs > 0) armTimeout();\n\tconst signals: AbortSignal[] = [timeoutController.signal];\n\tif (args.signal) signals.push(args.signal);\n\tconst signal = AbortSignal.any(signals);\n\n\tlet settled: ExecutorSettlement | undefined;\n\tconst execution = Promise.resolve()\n\t\t.then(() => args.execute(signal))\n\t\t.then<ExecutorSettlement, ExecutorSettlement>(\n\t\t\t(completion) => {\n\t\t\t\tsettled = { kind: \"completion\", completion };\n\t\t\t\treturn settled;\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tsettled = { kind: \"error\", error };\n\t\t\t\treturn settled;\n\t\t\t},\n\t\t);\n\tif (args.signal?.aborted) resolveAbort();\n\n\ttry {\n\t\tconst winner = await Promise.race([execution, abortPromise]);\n\t\tif (winner.kind === \"abort\") {\n\t\t\t// An abort and a completion can settle in the same microtask turn. Give the already-queued\n\t\t\t// executor handlers one chance to retain that completion (and its visible spend) without\n\t\t\t// ever waiting for a non-cooperative executor. Later settlement remains observed by\n\t\t\t// `execution`'s rejection handler, preventing an unhandled rejection after this returns.\n\t\t\tfor (let flush = 0; flush < 4 && settled === undefined; flush++) {\n\t\t\t\tawait Promise.resolve();\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...(settled?.kind === \"completion\" ? { completion: settled.completion } : {}),\n\t\t\t\tfailure: abortFailure({ externalSignal: args.signal, timeoutSignal: timeoutController.signal }),\n\t\t\t};\n\t\t}\n\n\t\tif (winner.kind === \"error\") {\n\t\t\treturn {\n\t\t\t\tfailure:\n\t\t\t\t\targs.signal?.aborted || timeoutController.signal.aborted\n\t\t\t\t\t\t? abortFailure({ externalSignal: args.signal, timeoutSignal: timeoutController.signal })\n\t\t\t\t\t\t: executorFailure(winner.error),\n\t\t\t};\n\t\t}\n\n\t\tconst completion = winner.completion;\n\t\tif (args.signal?.aborted || timeoutController.signal.aborted) {\n\t\t\treturn {\n\t\t\t\tcompletion,\n\t\t\t\tfailure: abortFailure({ externalSignal: args.signal, timeoutSignal: timeoutController.signal }),\n\t\t\t};\n\t\t}\n\t\treturn { completion };\n\t} finally {\n\t\tif (timeoutTimer !== undefined) clearTimeout(timeoutTimer);\n\t\targs.signal?.removeEventListener(\"abort\", onExternalAbort);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bounded-completion.js","sourceRoot":"","sources":["../../../src/core/autonomy/bounded-completion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAgB3E;;;GAGG;AACH,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IAIvD;;;;;OAKG;IACH,YAAY,MAAsC,EAAE,UAAkB,EAAE,OAAe,EAAE,KAAe;QACvG,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC9B,CAAC;CACD;AAQD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAClD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,C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iB,CAAC,MAAM,EAAE,CAAC;aAC/F,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC7B,OAAO;gBACN,OAAO,EACN,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,OAAO;oBACvD,CAAC,CAAC,YAAY,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,iBAAiB,CAAC,MAAM,EAAE,CAAC;oBACxF,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC;aACjC,CAAC;QACH,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAC9D,OAAO;gBACN,UAAU;gBACV,OAAO,EAAE,YAAY,CAAC,EAAE,cAAc,EAAE,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,iBAAiB,CAAC,MAAM,EAAE,CAAC;aAC/F,CAAC;QACH,CAAC;QACD,OAAO,EAAE,UAAU,EAAE,CAAC;IACvB,CAAC;YAAS,CAAC;QACV,IAAI,YAAY,KAAK,SAAS;YAAE,YAAY,CAAC,YAAY,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAC5D,CAAC;AACF,CAAC","sourcesContent":["import { boundedRedactedDiagnosticText } from \"../security/secret-text.ts\";\n\n/**\n * Shared wall-clock/cancellation envelope for one-shot lane completions (research and delegated workers).\n * Composes an optional external abort signal with an internal wall-clock timeout, executes the\n * injected completion, and maps every failure to a stable status/reasonCode pair. Never throws.\n */\n\nexport interface BoundedCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n}\n\nexport type BoundedCompletionFailureStatus = \"canceled\" | \"timeout\" | \"failed\" | \"budget_exhausted\";\n\n/**\n * Typed failure crossing the executor boundary. Policy owners use this instead of forcing the\n * completion envelope to infer a bounded denial from human-readable error text.\n */\nexport class BoundedCompletionFailureError extends Error {\n\treadonly status: BoundedCompletionFailureStatus;\n\treadonly reasonCode: string;\n\n\t/**\n\t * `cause`, when the error wraps an upstream failure (e.g. an exhausted provider retry ladder),\n\t * preserves the original error's identity/type/stack for callers that need to inspect it —\n\t * wrapping otherwise launders it down to a message string, which the redacted `detail` extracted\n\t * by {@link boundedFailureDetail} intentionally is not a substitute for.\n\t */\n\tconstructor(status: BoundedCompletionFailureStatus, reasonCode: string, message: string, cause?: unknown) {\n\t\tsuper(message, cause !== undefined ? { cause } : undefined);\n\t\tthis.name = \"BoundedCompletionFailureError\";\n\t\tthis.status = status;\n\t\tthis.reasonCode = reasonCode;\n\t}\n}\n\nexport interface BoundedCompletionOutcome {\n\t/** Present when the executor settled; may coexist with `failure` when an abort raced the result. */\n\tcompletion?: BoundedCompletion;\n\tfailure?: { status: BoundedCompletionFailureStatus; reasonCode: string; detail?: string };\n}\n\n/**\n * Preserve the executor's actual error alongside the stable reason code. A bare\n * `completion_error` is undiagnosable from lane records alone (field lesson: workers dying\n * on provider socket drops and budget denials all flattened to the same code).\n */\nexport function boundedFailureDetail(error: unknown): string | undefined {\n\tconst message = error instanceof Error ? error.message : typeof error === \"string\" ? error : undefined;\n\tif (!message) return undefined;\n\treturn boundedRedactedDiagnosticText(message);\n}\n\ntype ExecutorSettlement = { kind: \"completion\"; completion: BoundedCompletion } | { kind: \"error\"; error: unknown };\n\nconst MAX_HOST_TIMER_DELAY_MS = 2_147_483_647;\n\nfunction abortFailure(args: {\n\texternalSignal?: AbortSignal;\n\ttimeoutSignal: AbortSignal;\n}): BoundedCompletionOutcome[\"failure\"] {\n\tif (args.externalSignal?.aborted) return { status: \"canceled\", reasonCode: \"external_abort\" };\n\tif (args.timeoutSignal.aborted) return { status: \"timeout\", reasonCode: \"wall_clock_exceeded\" };\n\treturn { status: \"failed\", reasonCode: \"completion_error\" };\n}\n\nfunction executorFailure(error: unknown): BoundedCompletionOutcome[\"failure\"] {\n\tconst detail = boundedFailureDetail(error);\n\tif (error instanceof BoundedCompletionFailureError) {\n\t\treturn {\n\t\t\tstatus: error.status,\n\t\t\treasonCode: error.reasonCode,\n\t\t\t...(detail ? { detail } : {}),\n\t\t};\n\t}\n\treturn { status: \"failed\", reasonCode: \"completion_error\", ...(detail ? { detail } : {}) };\n}\n\nexport async function runBoundedCompletion(args: {\n\t/** Wall-clock budget in milliseconds; 0 disables. */\n\tmaxWallClockMs: number;\n\t/** External cancellation (e.g. session disposal). */\n\tsignal?: AbortSignal;\n\texecute: (signal: AbortSignal) => Promise<BoundedCompletion>;\n}): Promise<BoundedCompletionOutcome> {\n\tconst timeoutController = new AbortController();\n\tlet resolveAbort!: () => void;\n\tconst abortPromise = new Promise<{ kind: \"abort\" }>((resolve) => {\n\t\tresolveAbort = () => resolve({ kind: \"abort\" });\n\t});\n\tconst onExternalAbort = (): void => resolveAbort();\n\targs.signal?.addEventListener(\"abort\", onExternalAbort, { once: true });\n\tlet timeoutTimer: ReturnType<typeof setTimeout> | undefined;\n\tlet remainingWallClockMs = args.maxWallClockMs;\n\tconst armTimeout = (): void => {\n\t\tconst delayMs = Math.min(remainingWallClockMs, MAX_HOST_TIMER_DELAY_MS);\n\t\ttimeoutTimer = setTimeout(() => {\n\t\t\tremainingWallClockMs -= delayMs;\n\t\t\tif (remainingWallClockMs > 0) {\n\t\t\t\tarmTimeout();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttimeoutController.abort();\n\t\t\tresolveAbort();\n\t\t}, delayMs);\n\t\tif (typeof timeoutTimer === \"object\" && \"unref\" in timeoutTimer) {\n\t\t\tconst { unref } = timeoutTimer as { unref?: () => void };\n\t\t\tunref?.call(timeoutTimer);\n\t\t}\n\t};\n\tif (args.maxWallClockMs > 0) armTimeout();\n\tconst signals: AbortSignal[] = [timeoutController.signal];\n\tif (args.signal) signals.push(args.signal);\n\tconst signal = AbortSignal.any(signals);\n\n\tlet settled: ExecutorSettlement | undefined;\n\tconst execution = Promise.resolve()\n\t\t.then(() => args.execute(signal))\n\t\t.then<ExecutorSettlement, ExecutorSettlement>(\n\t\t\t(completion) => {\n\t\t\t\tsettled = { kind: \"completion\", completion };\n\t\t\t\treturn settled;\n\t\t\t},\n\t\t\t(error: unknown) => {\n\t\t\t\tsettled = { kind: \"error\", error };\n\t\t\t\treturn settled;\n\t\t\t},\n\t\t);\n\tif (args.signal?.aborted) resolveAbort();\n\n\ttry {\n\t\tconst winner = await Promise.race([execution, abortPromise]);\n\t\tif (winner.kind === \"abort\") {\n\t\t\t// An abort and a completion can settle in the same microtask turn. Give the already-queued\n\t\t\t// executor handlers one chance to retain that completion (and its visible spend) without\n\t\t\t// ever waiting for a non-cooperative executor. Later settlement remains observed by\n\t\t\t// `execution`'s rejection handler, preventing an unhandled rejection after this returns.\n\t\t\tfor (let flush = 0; flush < 4 && settled === undefined; flush++) {\n\t\t\t\tawait Promise.resolve();\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...(settled?.kind === \"completion\" ? { completion: settled.completion } : {}),\n\t\t\t\tfailure: abortFailure({ externalSignal: args.signal, timeoutSignal: timeoutController.signal }),\n\t\t\t};\n\t\t}\n\n\t\tif (winner.kind === \"error\") {\n\t\t\treturn {\n\t\t\t\tfailure:\n\t\t\t\t\targs.signal?.aborted || timeoutController.signal.aborted\n\t\t\t\t\t\t? abortFailure({ externalSignal: args.signal, timeoutSignal: timeoutController.signal })\n\t\t\t\t\t\t: executorFailure(winner.error),\n\t\t\t};\n\t\t}\n\n\t\tconst completion = winner.completion;\n\t\tif (args.signal?.aborted || timeoutController.signal.aborted) {\n\t\t\treturn {\n\t\t\t\tcompletion,\n\t\t\t\tfailure: abortFailure({ externalSignal: args.signal, timeoutSignal: timeoutController.signal }),\n\t\t\t};\n\t\t}\n\t\treturn { completion };\n\t} finally {\n\t\tif (timeoutTimer !== undefined) clearTimeout(timeoutTimer);\n\t\targs.signal?.removeEventListener(\"abort\", onExternalAbort);\n\t}\n}\n"]}
|
|
@@ -106,7 +106,7 @@ export interface WorkerRequest {
|
|
|
106
106
|
maxEstimatedUsd?: number;
|
|
107
107
|
createdAt?: string;
|
|
108
108
|
}
|
|
109
|
-
export type WorkerClaimStatus = "completed" | "blocked" | "failed" | "cancelled";
|
|
109
|
+
export type WorkerClaimStatus = "completed" | "partial" | "blocked" | "failed" | "cancelled";
|
|
110
110
|
export type WorkerClaimOutputFormat = "structured" | "plain_text";
|
|
111
111
|
export interface WorkerClaimVerificationDecision {
|
|
112
112
|
subjectTaskId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AACnF,MAAM,WAAW,UAAU;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,UAAU,CAAC;AAEtE,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,cAAc,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAE3F,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,cAAc,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAE/F,MAAM,WAAW,mBAAmB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,E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AC,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;4EAGwE;IACxE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;sGAEkG;IAClG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,wEAAwE;IACxE,YAAY,CAAC,EAAE,+BAA+B,CAAC;CAC/C;AAED,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,UAAU,GAAG,OAAO,CAAC;AAElE,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../../src/core/autonomy/contracts.ts"],"names":[],"mappings":"","sourcesContent":["import type { HarnessCapability } from \"../capability-contract.ts\";\n\nexport type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };\nexport interface JsonObject {\n\t[key: string]: JsonValue;\n}\n\nexport type ModelTier = \"cheap\" | \"medium\" | \"expensive\" | \"learning\";\n\nexport type RouteRisk = \"read-only\" | \"scoped-write\" | \"high-impact\" | \"approval-required\";\n\nexport type OperationRisk = \"read-only\" | \"scoped-write\" | \"high-impact\" | \"approval-required\";\n\nexport interface RiskAssessmentInput {\n\toperation: string;\n\ttoolName?: string;\n\tcommand?: string;\n\tpaths?: readonly string[];\n\tcapabilities?: readonly HarnessCapability[];\n}\n\nexport interface RiskAssessment {\n\trisk: OperationRisk;\n\treasonCode: string;\n\treasons: readonly string[];\n\trequiresApproval: boolean;\n}\n\nexport type PathScopeDecisionKind = \"inside\" | \"outside\" | \"denied\" | \"missing\";\n\nexport interface PathScope {\n\troot: string;\n\tallowedPaths?: readonly string[];\n\tdeniedPaths?: readonly string[];\n\tfollowSymlinks?: boolean;\n}\n\nexport interface PathScopeDecision {\n\tkind: PathScopeDecisionKind;\n\tpath: string;\n\tresolvedPath?: string;\n\tmatchedRule?: string;\n\treasonCode: string;\n}\n\nexport interface RouteDecision {\n\ttier: ModelTier;\n\tmodel?: string;\n\trisk: RouteRisk;\n\tconfidence: number;\n\treasonCode: string;\n\treasons: readonly string[];\n\tfallbackFrom?: ModelTier;\n\tcreatedAt?: string;\n}\n\nexport interface CapabilityEnvelope {\n\tid: string;\n\tprofileId?: string;\n\tcapabilities: readonly HarnessCapability[];\n\tallowedTools?: readonly string[];\n\tdeniedTools?: readonly string[];\n\tallowedPaths?: readonly string[];\n\tdeniedPaths?: readonly string[];\n\tmaxEstimatedUsd?: number;\n\tcreatedAt?: string;\n}\n\nexport type GateOutcomeKind = \"allow\" | \"downgrade\" | \"escalate\" | \"ask-user\" | \"block\";\n\nexport interface GateOutcome {\n\toutcome: GateOutcomeKind;\n\tgate: string;\n\treasonCode: string;\n\tmessage?: string;\n\treversible?: boolean;\n\tdetails?: JsonObject;\n}\n\nexport interface ApprovalRequest {\n\tid: string;\n\toperation: string;\n\ttarget: string;\n\treversible: boolean;\n\tcapabilities: readonly HarnessCapability[];\n\treasonCode: string;\n\tcreatedAt?: string;\n}\n\nexport type EvidenceSourceKind = \"workspace\" | \"transcript\" | \"automata\" | \"web\" | \"user\" | \"tool\";\n\nexport interface EvidenceRef {\n\tid: string;\n\tkind: EvidenceSourceKind;\n\ttitle?: string;\n\turi?: string;\n\ttrusted: boolean;\n\texcerpt?: string;\n\tmetadata?: JsonObject;\n}\n\nexport interface Finding {\n\tid: string;\n\tsummary: string;\n\tevidenceIds: readonly string[];\n\tconfidence?: number;\n}\n\nexport interface EvidenceBundle {\n\tquery: string;\n\tsources: readonly EvidenceRef[];\n\tfindings: readonly Finding[];\n\tcreatedAt?: string;\n}\n\nexport interface WorkerRequest {\n\tid: string;\n\tinstructions: string;\n\troute: RouteDecision;\n\tenvelope: CapabilityEnvelope;\n\tevidence?: EvidenceBundle;\n\tmaxEstimatedUsd?: number;\n\tcreatedAt?: string;\n}\n\nexport type WorkerClaimStatus = \"completed\" | \"blocked\" | \"failed\" | \"cancelled\";\n\nexport type WorkerClaimOutputFormat = \"structured\" | \"plain_text\";\n\nexport interface WorkerClaimVerificationDecision {\n\tsubjectTaskId: string;\n\tverdict: \"accepted\" | \"rejected\";\n\treasonCodes: readonly string[];\n}\n\n/** Untrusted worker-authored report. Only host adjudication can turn this into a durable result. */\nexport interface WorkerClaim {\n\trequestId: string;\n\t/** Host-stamped durable attempt identity for replay-safe claim persistence. */\n\tterminalAttemptId?: string;\n\tstatus: WorkerClaimStatus;\n\tsummary: string;\n\toutputFormat?: WorkerClaimOutputFormat;\n\tevidence?: EvidenceBundle;\n\tchangedFiles: readonly string[];\n\tblockers?: readonly string[];\n\tusageReportId?: string;\n\tcreatedAt?: string;\n\t/** Stamped at persistence time when validateWorkerClaim's gate flagged this claim\n\t * \"ask-user\"/\"parent_review_required\" (mutated files or blockers on an otherwise-completed run).\n\t * Undefined when not computable because an externally managed lane had no WorkerRequest —\n\t * distinct from `false`, which means the gate explicitly cleared it. */\n\tparentReviewRequired?: boolean;\n\t/** ISO 8601 timestamp set once the parent explicitly acknowledges an unreviewed mutation via\n\t * delegate's \"review\" action. Presence means reviewed; absence keeps the notice sticky.\n\t * The ack is durable — re-derived from the latest persisted snapshot, not session-local state. */\n\tparentReviewedAt?: string;\n\t/** Typed semantic verdict emitted only by a verifier-profile worker. */\n\tverification?: WorkerClaimVerificationDecision;\n}\n\nexport type LearningDecisionKind = \"no-op\" | \"proposal\" | \"apply\";\n\nexport interface LearningDecision {\n\tkind: LearningDecisionKind;\n\treasonCode: string;\n\tconfidence: number;\n\tsummary: string;\n\trequiresApproval: boolean;\n\tcreatedAt?: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../../src/core/autonomy/contracts.ts"],"names":[],"mappings":"","sourcesContent":["import type { HarnessCapability } from \"../capability-contract.ts\";\n\nexport type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };\nexport interface JsonObject {\n\t[key: string]: JsonValue;\n}\n\nexport type ModelTier = \"cheap\" | \"medium\" | \"expensive\" | \"learning\";\n\nexport type RouteRisk = \"read-only\" | \"scoped-write\" | \"high-impact\" | \"approval-required\";\n\nexport type OperationRisk = \"read-only\" | \"scoped-write\" | \"high-impact\" | \"approval-required\";\n\nexport interface RiskAssessmentInput {\n\toperation: string;\n\ttoolName?: string;\n\tcommand?: string;\n\tpaths?: readonly string[];\n\tcapabilities?: readonly HarnessCapability[];\n}\n\nexport interface RiskAssessment {\n\trisk: OperationRisk;\n\treasonCode: string;\n\treasons: readonly string[];\n\trequiresApproval: boolean;\n}\n\nexport type PathScopeDecisionKind = \"inside\" | \"outside\" | \"denied\" | \"missing\";\n\nexport interface PathScope {\n\troot: string;\n\tallowedPaths?: readonly string[];\n\tdeniedPaths?: readonly string[];\n\tfollowSymlinks?: boolean;\n}\n\nexport interface PathScopeDecision {\n\tkind: PathScopeDecisionKind;\n\tpath: string;\n\tresolvedPath?: string;\n\tmatchedRule?: string;\n\treasonCode: string;\n}\n\nexport interface RouteDecision {\n\ttier: ModelTier;\n\tmodel?: string;\n\trisk: RouteRisk;\n\tconfidence: number;\n\treasonCode: string;\n\treasons: readonly string[];\n\tfallbackFrom?: ModelTier;\n\tcreatedAt?: string;\n}\n\nexport interface CapabilityEnvelope {\n\tid: string;\n\tprofileId?: string;\n\tcapabilities: readonly HarnessCapability[];\n\tallowedTools?: readonly string[];\n\tdeniedTools?: readonly string[];\n\tallowedPaths?: readonly string[];\n\tdeniedPaths?: readonly string[];\n\tmaxEstimatedUsd?: number;\n\tcreatedAt?: string;\n}\n\nexport type GateOutcomeKind = \"allow\" | \"downgrade\" | \"escalate\" | \"ask-user\" | \"block\";\n\nexport interface GateOutcome {\n\toutcome: GateOutcomeKind;\n\tgate: string;\n\treasonCode: string;\n\tmessage?: string;\n\treversible?: boolean;\n\tdetails?: JsonObject;\n}\n\nexport interface ApprovalRequest {\n\tid: string;\n\toperation: string;\n\ttarget: string;\n\treversible: boolean;\n\tcapabilities: readonly HarnessCapability[];\n\treasonCode: string;\n\tcreatedAt?: string;\n}\n\nexport type EvidenceSourceKind = \"workspace\" | \"transcript\" | \"automata\" | \"web\" | \"user\" | \"tool\";\n\nexport interface EvidenceRef {\n\tid: string;\n\tkind: EvidenceSourceKind;\n\ttitle?: string;\n\turi?: string;\n\ttrusted: boolean;\n\texcerpt?: string;\n\tmetadata?: JsonObject;\n}\n\nexport interface Finding {\n\tid: string;\n\tsummary: string;\n\tevidenceIds: readonly string[];\n\tconfidence?: number;\n}\n\nexport interface EvidenceBundle {\n\tquery: string;\n\tsources: readonly EvidenceRef[];\n\tfindings: readonly Finding[];\n\tcreatedAt?: string;\n}\n\nexport interface WorkerRequest {\n\tid: string;\n\tinstructions: string;\n\troute: RouteDecision;\n\tenvelope: CapabilityEnvelope;\n\tevidence?: EvidenceBundle;\n\tmaxEstimatedUsd?: number;\n\tcreatedAt?: string;\n}\n\nexport type WorkerClaimStatus = \"completed\" | \"partial\" | \"blocked\" | \"failed\" | \"cancelled\";\n\nexport type WorkerClaimOutputFormat = \"structured\" | \"plain_text\";\n\nexport interface WorkerClaimVerificationDecision {\n\tsubjectTaskId: string;\n\tverdict: \"accepted\" | \"rejected\";\n\treasonCodes: readonly string[];\n}\n\n/** Untrusted worker-authored report. Only host adjudication can turn this into a durable result. */\nexport interface WorkerClaim {\n\trequestId: string;\n\t/** Host-stamped durable attempt identity for replay-safe claim persistence. */\n\tterminalAttemptId?: string;\n\tstatus: WorkerClaimStatus;\n\tsummary: string;\n\toutputFormat?: WorkerClaimOutputFormat;\n\tevidence?: EvidenceBundle;\n\tchangedFiles: readonly string[];\n\tblockers?: readonly string[];\n\tusageReportId?: string;\n\tcreatedAt?: string;\n\t/** Stamped at persistence time when validateWorkerClaim's gate flagged this claim\n\t * \"ask-user\"/\"parent_review_required\" (mutated files or blockers on an otherwise-completed run).\n\t * Undefined when not computable because an externally managed lane had no WorkerRequest —\n\t * distinct from `false`, which means the gate explicitly cleared it. */\n\tparentReviewRequired?: boolean;\n\t/** ISO 8601 timestamp set once the parent explicitly acknowledges an unreviewed mutation via\n\t * delegate's \"review\" action. Presence means reviewed; absence keeps the notice sticky.\n\t * The ack is durable — re-derived from the latest persisted snapshot, not session-local state. */\n\tparentReviewedAt?: string;\n\t/** Typed semantic verdict emitted only by a verifier-profile worker. */\n\tverification?: WorkerClaimVerificationDecision;\n}\n\nexport type LearningDecisionKind = \"no-op\" | \"proposal\" | \"apply\";\n\nexport interface LearningDecision {\n\tkind: LearningDecisionKind;\n\treasonCode: string;\n\tconfidence: number;\n\tsummary: string;\n\trequiresApproval: boolean;\n\tcreatedAt?: string;\n}\n"]}
|
|
@@ -76,6 +76,20 @@ export declare class BackgroundLaneController implements WorkerAgentControlPort
|
|
|
76
76
|
private _getWorkerController;
|
|
77
77
|
private _getWorkerLifecycle;
|
|
78
78
|
private _getWorkerNotificationCoordinator;
|
|
79
|
+
/**
|
|
80
|
+
* Backfills a durable notification for every record about to be flushed, through the SAME
|
|
81
|
+
* durable notification store `_getWorkerLifecycle()` already replays from on construction
|
|
82
|
+
* (`getPendingTerminalNotifications()` / `markNotificationsDelivered()`) -- not a new
|
|
83
|
+
* persistence subsystem. `WorkerLifecycle.getTerminalNotification()` is idempotent (it reuses
|
|
84
|
+
* an existing durable entry for the same laneId/attemptId or creates exactly one), so calling
|
|
85
|
+
* it for a record that already has a durable notification is a safe no-op. Without this, a
|
|
86
|
+
* "transient:<laneId>:<completedAt>" record (recorded without a durableNotificationId — e.g.
|
|
87
|
+
* because no attempt was resolvable at record time) has no trace in the durable ledger at all:
|
|
88
|
+
* if it's still stuck behind an unresolved notify() when the process restarts, the replay on
|
|
89
|
+
* the next construction can only find what was durably enqueued, so it would be lost instead of
|
|
90
|
+
* replayed.
|
|
91
|
+
*/
|
|
92
|
+
private _ensureDurableNotifications;
|
|
79
93
|
private _getManagedLaneController;
|
|
80
94
|
private _hydrateManagedLanes;
|
|
81
95
|
/** Live lane records tracked by this process (running and terminal). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background-lane-controller.d.ts","sourceRoot":"","sources":["../../src/core/background-lane-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EACX,2BAA2B,EAC3B,0BAA0B,EAC1B,aAAa,EACb,sBAAsB,EACtB,0BAA0B,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,4BAA4B,CAAC;AAG1E,OAAO,KAAK,EACX,gBAAgB,EAChB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EACX,oCAAoC,EACpC,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,4BAA4B,EAC5B,mBAAmB,EACnB,qBAAqB,EACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAEN,KAAK,8BAA8B,EACnC,MAAM,8CAA8C,CAAC;AACtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAGzF,OAAO,KAAK,EAAE,gBAAgB,EAA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CAAC;IACvC,gGAAgG;IAChG,uBAAuB,IAAI,IAAI,CAAC;CAChC;AAED,qBAAa,wBAAyB,YAAW,sBAAsB;IACtE,uFAAuF;IACvF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6B;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,+EAA+E;IAC/E,OAAO,CAAC,aAAa,CAAoC;IACzD,iGAAiG;IACjG,OAAO,CAAC,QAAQ,CAAyC;IACzD,sEAAsE;IACtE,OAAO,CAAC,gBAAgB,CAA8B;IACtD,0FAA0F;IAC1F,OAAO,CAAC,oBAAoB,CAA4C;IACxE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA+B;IAEpD;oGACgG;IAChG,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,qBAAqB;IAI7B,YAAY,IAAI,EAAE,4BAA4B,EAkB7C;IAED,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,iCAAiC;
|
|
1
|
+
{"version":3,"file":"background-lane-controller.d.ts","sourceRoot":"","sources":["../../src/core/background-lane-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EACX,2BAA2B,EAC3B,0BAA0B,EAC1B,aAAa,EACb,sBAAsB,EACtB,0BAA0B,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,KAAK,UAAU,EAAe,MAAM,4BAA4B,CAAC;AAG1E,OAAO,KAAK,EACX,gBAAgB,EAChB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,MAAM,sCAAsC,CAAC;AAC9C,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AE,GAAG;QAAE,OAAO,EAAE,KAAK,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAEjH;IAED,mGAAmG;IACnG,4BAA4B,IAAI,IAAI,CAEnC;IAED,mGAAmG;IACnG,uBAAuB,IAAI,mBAAmB,EAAE,CAE/C;CACD"}
|
|
@@ -82,6 +82,13 @@ export class BackgroundLaneController {
|
|
|
82
82
|
this._workerNotifications ??= new WorkerNotificationCoordinator({
|
|
83
83
|
getWorkerRecords: () => this._workerLifecycle?.getAllRecords() ?? [],
|
|
84
84
|
emitStatus: (status) => {
|
|
85
|
+
// Runs once per flush, with the EXACT batch about to be handed to notify() -- the
|
|
86
|
+
// natural checkpoint to backfill durability before that batch can get stuck behind
|
|
87
|
+
// an unsettled notify() call with no durable trace. (getOutstandingRecords() is not
|
|
88
|
+
// usable here: the coordinator emits status BEFORE moving this same batch from
|
|
89
|
+
// `pending` into `inFlight`, so at this exact moment it would report nothing
|
|
90
|
+
// outstanding — status.terminalSinceFlush is the batch, directly, no timing gap.)
|
|
91
|
+
this._ensureDurableNotifications(status.terminalSinceFlush);
|
|
85
92
|
try {
|
|
86
93
|
this.deps.emit({
|
|
87
94
|
type: "delegate_workers",
|
|
@@ -99,6 +106,31 @@ export class BackgroundLaneController {
|
|
|
99
106
|
});
|
|
100
107
|
return this._workerNotifications;
|
|
101
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Backfills a durable notification for every record about to be flushed, through the SAME
|
|
111
|
+
* durable notification store `_getWorkerLifecycle()` already replays from on construction
|
|
112
|
+
* (`getPendingTerminalNotifications()` / `markNotificationsDelivered()`) -- not a new
|
|
113
|
+
* persistence subsystem. `WorkerLifecycle.getTerminalNotification()` is idempotent (it reuses
|
|
114
|
+
* an existing durable entry for the same laneId/attemptId or creates exactly one), so calling
|
|
115
|
+
* it for a record that already has a durable notification is a safe no-op. Without this, a
|
|
116
|
+
* "transient:<laneId>:<completedAt>" record (recorded without a durableNotificationId — e.g.
|
|
117
|
+
* because no attempt was resolvable at record time) has no trace in the durable ledger at all:
|
|
118
|
+
* if it's still stuck behind an unresolved notify() when the process restarts, the replay on
|
|
119
|
+
* the next construction can only find what was durably enqueued, so it would be lost instead of
|
|
120
|
+
* replayed.
|
|
121
|
+
*/
|
|
122
|
+
_ensureDurableNotifications(records) {
|
|
123
|
+
if (!this._workerLifecycle)
|
|
124
|
+
return;
|
|
125
|
+
for (const record of records) {
|
|
126
|
+
try {
|
|
127
|
+
this._workerLifecycle.getTerminalNotification(record.laneId);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
this._safeWarn(`Failed to durably back the worker terminal notification for ${record.laneId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
102
134
|
_getManagedLaneController() {
|
|
103
135
|
this._managedLanes ??= new ManagedLaneController(this.deps, this._getWorkerLifecycle(), (record, notificationId) => this._recordWorkerTerminal(record, notificationId), (message) => this._safeWarn(message));
|
|
104
136
|
return this._managedLanes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background-lane-controller.js","sourceRoot":"","sources":["../../src/core/background-lane-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,OAAO,EAAmB,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAC3G,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAsBhF,OAAO,EACN,0BAA0B,GAE1B,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAEhG,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAWtF,OAAO,EAAE,iBAAiB,EAA8B,MAAM,mCAAmC,CAAC;AAElG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2B;QAE3B,OAAO,IAAI,CAAC,oBAAoB,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;IAChF,CAAC;IACD;;;;;OAKG;IACH,KAAK,CAAC,eAAe,CAAC,IAKrB;QACA,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,mGAAmG;IACnG,4BAA4B;QAC3B,IAAI,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE;YAAE,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,CAAC;IAC7E,CAAC;IAED,mGAAmG;IACnG,uBAAuB;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC;CACD","sourcesContent":["/**\n * Execution-plane coordinator for goal continuation, research, managed lanes, worker delegation,\n * and model fitness.\n *\n * Coordination state is owned by focused controllers. This coordinator retains one AgentSession\n * composition seam and a shared lane read model. Everything it needs\n * — the session manager, settings, model registry, live model, capability envelope, the goal\n * continuation LOOP, the isolated-completion primitive, spawned-usage accounting, and the telemetry\n * sink — is reached through narrow deps accessors rather than the whole AgentSession.\n *\n * Drive-loop boundary (deliberate): the idle triggers ({@link scheduleGoalAutoContinueFromIdle},\n * {@link scheduleResearchLaneFromIdle}) are invoked from the session's prompt tail as one-line\n * delegations; goal auto-continue itself only ever asks the session to `continueGoalLoop`, so this\n * controller never touches `prompt()`, the last-assistant-message, retry, or streaming state.\n */\n\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport type {\n\tGoalContinuationLoopOptions,\n\tGoalContinuationLoopResult,\n\tPromptOptions,\n\tResearchLaneRunOutcome,\n\tWorkerDelegationRunOutcome,\n} from \"./agent-session-contracts.ts\";\nimport { type LaneRecord, LaneTracker } from \"./autonomy/lane-tracker.ts\";\nimport { appendLaneRecordSnapshot, getLatestLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport { ManagedLaneController } from \"./delegation/managed-lane-controller.ts\";\nimport type {\n\tSessionRootReply,\n\tSessionRootReplyQuery,\n\tSessionRootReplyWaitOptions,\n\tSessionRootReplyWaitResult,\n} from \"./delegation/session-root-mailbox.ts\";\nimport type {\n\tSessionRootWorkerAgentMessageOptions,\n\tWorkerAgentActivity,\n\tWorkerAgentBroadcastOptions,\n\tWorkerAgentBroadcastResult,\n\tWorkerAgentControlPort,\n\tWorkerAgentControlScope,\n\tWorkerAgentMessageOptions,\n\tWorkerAgentReplyResult,\n\tWorkerAgentRetireResult,\n\tWorkerAgentTaskStartOptions,\n\tWorkerAgentTranscriptOptions,\n\tWorkerAgentWaitMode,\n\tWorkerAgentWaitResult,\n} from \"./delegation/worker-agent-control.ts\";\nimport {\n\tWorkerDelegationController,\n\ttype WorkerDelegationControllerDeps,\n} from \"./delegation/worker-delegation-controller.ts\";\nimport type { WorkerDelegationRequest } from \"./delegation/worker-delegation-request.ts\";\nimport { WorkerLifecycle } from \"./delegation/worker-lifecycle.ts\";\nimport { WorkerNotificationCoordinator } from \"./delegation/worker-notification-coordinator.ts\";\nimport type { ManagedLaneEvent } from \"./extensions/types.ts\";\nimport { GoalAutoContinueController } from \"./goals/goal-auto-continue-controller.ts\";\nimport type { GoalRuntimeSnapshot, GoalRuntimeSnapshotSettings } from \"./goals/goal-runtime-snapshot.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { ModelCapabilityProfile } from \"./model-capability.ts\";\nimport type { StoredFitnessReport } from \"./models/fitness-store.ts\";\nimport type {\n\tTaskProfileCreateInput,\n\tTaskProfileCreateResult,\n\tTaskProfileInspection,\n} from \"./orchestration/task-profile-writer.ts\";\nimport type { TaskRuntimeProjection } from \"./orchestration/task-runtime.ts\";\nimport { LaneModelResolver, type LaneModelResolverDeps } from \"./research/lane-model-resolver.ts\";\nimport type { ModelFitnessReport } from \"./research/model-fitness.ts\";\nimport { ModelFitnessController, type ModelFitnessControllerDeps } from \"./research/model-fitness-controller.ts\";\nimport { ResearchLaneController, type ResearchLaneControllerDeps } from \"./research/research-lane-controller.ts\";\nimport { getActiveSessionBranchEntries } from \"./session-snapshot.ts\";\n\nexport { isLocalExecutionModel } from \"./delegation/worker-delegation-controller.ts\";\nexport { clampLaneMaxUsd } from \"./research/lane-model-resolver.ts\";\n\nexport interface BackgroundLaneControllerDeps\n\textends WorkerDelegationControllerDeps,\n\t\tResearchLaneControllerDeps,\n\t\tModelFitnessControllerDeps,\n\t\tLaneModelResolverDeps {\n\t/** True iff the `goal` tool is in the session's ACTIVE surface -- the capability-adaptive gate\n\t * for every goal-continuation loop (see `continueGoalLoopExclusive`): a surface without the\n\t * goal tool (lean capability blocklist, worker role ceiling, --tools/profile exclusion) must\n\t * never be driven with continuation prompts it cannot execute. */\n\tisGoalToolActive(): boolean;\n\t/** Capability profile of the SESSION model (gates background lanes, scales continuation budgets). */\n\tgetModelCapabilityProfile(): ModelCapabilityProfile;\n\t/** Continuation gate + goal state for the idle autosteer scheduler. */\n\tgetGoalRuntimeSnapshot(settings: GoalRuntimeSnapshotSettings): GoalRuntimeSnapshot;\n\t/** Drive-loop boundary: the session's bounded goal-continuation loop (owns `prompt()`, not us). */\n\tcontinueGoalLoop(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult>;\n\t/** True while the session owns a foreground prompt/retry/follow-up run. */\n\tisForegroundBusy(): boolean;\n\t/** Resolve only after the complete foreground retry/follow-up run releases the session. */\n\twaitForForegroundIdle(): Promise<void>;\n\t/** Persist an explicit stopped state when the selected surface cannot drive the active goal. */\n\tmarkGoalToolUnavailable(): void;\n}\n\nexport class BackgroundLaneController implements WorkerAgentControlPort {\n\t/** Live lane registry — the real source for AutonomyStatusSnapshot.activeLaneCount. */\n\tprivate readonly _laneTracker = new LaneTracker();\n\tprivate readonly _laneModels: LaneModelResolver;\n\tprivate readonly _goalAutoContinue: GoalAutoContinueController;\n\tprivate readonly _research: ResearchLaneController;\n\tprivate readonly _fitness: ModelFitnessController;\n\t/** Lazily materialized only when managed-lane state is queried or reported. */\n\tprivate _managedLanes: ManagedLaneController | undefined;\n\t/** Lazily materialized so a UAC surface without `delegate` allocates no worker runtime state. */\n\tprivate _workers: WorkerDelegationController | undefined;\n\t/** One durable lifecycle shared by every worker execution adapter. */\n\tprivate _workerLifecycle: WorkerLifecycle | undefined;\n\t/** Shared terminal outbox for managed and in-process workers; lazy under UAC omission. */\n\tprivate _workerNotifications: WorkerNotificationCoordinator | undefined;\n\tprivate readonly deps: BackgroundLaneControllerDeps;\n\n\t/** Emit a warning without ever throwing — used from disposal-adjacent persistence where a\n\t * listener failure (or a bare test double missing `emit`) must never block or crash cleanup. */\n\tprivate _safeWarn(message: string): void {\n\t\ttry {\n\t\t\tthis.deps.emit({ type: \"warning\", message });\n\t\t} catch {\n\t\t\t// Dispose must never throw.\n\t\t}\n\t}\n\n\tprivate _recordWorkerTerminal(record: LaneRecord, durableNotificationId: string): void {\n\t\tthis._getWorkerNotificationCoordinator().recordTerminal(record, durableNotificationId);\n\t}\n\n\tconstructor(deps: BackgroundLaneControllerDeps) {\n\t\tthis.deps = deps;\n\t\tthis._laneModels = new LaneModelResolver(deps);\n\t\tthis._research = new ResearchLaneController(deps, this._laneTracker, this._laneModels);\n\t\tthis._fitness = new ModelFitnessController(deps, this._laneModels);\n\t\tthis._goalAutoContinue = new GoalAutoContinueController({\n\t\t\tisDisposed: deps.isDisposed,\n\t\t\tisGoalToolActive: deps.isGoalToolActive,\n\t\t\tgetSettingsManager: deps.getSettingsManager,\n\t\t\tgetModelCapabilityProfile: deps.getModelCapabilityProfile,\n\t\t\tgetGoalRuntimeSnapshot: deps.getGoalRuntimeSnapshot,\n\t\t\thasInFlightLaneForGoal: (goalId) => this._hasInFlightLaneForGoal(goalId),\n\t\t\tcontinueGoalLoop: deps.continueGoalLoop,\n\t\t\tisForegroundBusy: deps.isForegroundBusy,\n\t\t\twaitForForegroundIdle: deps.waitForForegroundIdle,\n\t\t\tmarkGoalToolUnavailable: deps.markGoalToolUnavailable,\n\t\t\temit: deps.emit,\n\t\t});\n\t}\n\n\tprivate _getWorkerController(): WorkerDelegationController {\n\t\tthis._workers ??= new WorkerDelegationController(\n\t\t\tthis.deps,\n\t\t\tthis._getWorkerNotificationCoordinator(),\n\t\t\tthis._getWorkerLifecycle(),\n\t\t);\n\t\treturn this._workers;\n\t}\n\n\tprivate _getWorkerLifecycle(): WorkerLifecycle {\n\t\tif (this._workerLifecycle) return this._workerLifecycle;\n\t\tconst lifecycle = new WorkerLifecycle({\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tsessionId: this.deps.getSessionId(),\n\t\t});\n\t\tthis._workerLifecycle = lifecycle;\n\t\tfor (const notification of lifecycle.getPendingTerminalNotifications()) {\n\t\t\tthis._getWorkerNotificationCoordinator().recordTerminal(notification.record, notification.notificationId);\n\t\t}\n\t\treturn lifecycle;\n\t}\n\n\tprivate _getWorkerNotificationCoordinator(): WorkerNotificationCoordinator {\n\t\tthis._workerNotifications ??= new WorkerNotificationCoordinator({\n\t\t\tgetWorkerRecords: () => this._workerLifecycle?.getAllRecords() ?? [],\n\t\t\temitStatus: (status) => {\n\t\t\t\ttry {\n\t\t\t\t\tthis.deps.emit({\n\t\t\t\t\t\ttype: \"delegate_workers\",\n\t\t\t\t\t\t...status,\n\t\t\t\t\t\tterminalSinceFlush: [...status.terminalSinceFlush],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\t// A partial integration must not crash the event-driven terminal outbox.\n\t\t\t\t}\n\t\t\t},\n\t\t\tnotify: (records) => this.deps.notifyWorkerTerminalHandoff(records),\n\t\t\twarn: (message) => this._safeWarn(message),\n\t\t\tmarkDurableDelivered: (notificationIds) => this._workerLifecycle?.markNotificationsDelivered(notificationIds),\n\t\t});\n\t\treturn this._workerNotifications;\n\t}\n\n\tprivate _getManagedLaneController(): ManagedLaneController {\n\t\tthis._managedLanes ??= new ManagedLaneController(\n\t\t\tthis.deps,\n\t\t\tthis._getWorkerLifecycle(),\n\t\t\t(record, notificationId) => this._recordWorkerTerminal(record, notificationId),\n\t\t\t(message) => this._safeWarn(message),\n\t\t);\n\t\treturn this._managedLanes;\n\t}\n\n\tprivate _hydrateManagedLanes(): void {\n\t\tif (this._managedLanes) {\n\t\t\tthis._managedLanes.ensureHydrated();\n\t\t\treturn;\n\t\t}\n\t\tconst hasPersistedActiveManagedLane = getLatestLaneRecordSnapshots(\n\t\t\tgetActiveSessionBranchEntries(this.deps.getSessionManager()),\n\t\t).some((record) => record.type === \"tmux-worker\" && (record.status === \"queued\" || record.status === \"running\"));\n\t\tif (hasPersistedActiveManagedLane) this._getManagedLaneController().ensureHydrated();\n\t}\n\n\t/** Live lane records tracked by this process (running and terminal). */\n\tgetLaneRecords(): LaneRecord[] {\n\t\tthis._hydrateManagedLanes();\n\t\tconst workerRecords =\n\t\t\tthis._workers?.getRecords() ??\n\t\t\t(this.deps.isDelegateToolActive?.() ? this._getWorkerController().getRecords() : []);\n\t\treturn [\n\t\t\t...this._laneTracker.getRecords(),\n\t\t\t...workerRecords,\n\t\t\t...(this._workerLifecycle?.getManagedRecords() ?? []),\n\t\t];\n\t}\n\n\t/** Does not materialize the worker controller when UAC omitted delegation. */\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection | undefined {\n\t\treturn this._workerLifecycle?.getTaskRuntimeSnapshot();\n\t}\n\n\t/** Reconcile only when delegation has already been materialized; UAC omission stays zero-load. */\n\tsynchronizeGoalState(goal: GoalState): void {\n\t\tthis._workers?.synchronizeGoalState(goal);\n\t}\n\n\t/**\n\t * Resolve a tracked managed-lane dispatch. The caller's stable id is also the canonical durable\n\t * lane id, so this is an existence check rather than an id translation.\n\t */\n\tresolveManagedLaneId(callerLaneId: string): string | undefined {\n\t\treturn this._getManagedLaneController().resolve(callerLaneId);\n\t}\n\n\t/** Live count of active lanes — the real source for AutonomyStatusSnapshot.activeLaneCount. */\n\tgetActiveLaneCount(): number {\n\t\treturn this.getLaneRecords().filter((record) => record.status === \"queued\" || record.status === \"running\").length;\n\t}\n\n\t/** Belt-and-braces guard: whether ANY queued/running lane is tagged with this goalId. */\n\tprivate _hasInFlightLaneForGoal(goalId: string): boolean {\n\t\treturn this.getLaneRecords().some(\n\t\t\t(record) => record.goalId === goalId && (record.status === \"queued\" || record.status === \"running\"),\n\t\t);\n\t}\n\n\t/** Delegate the out-of-process dispatch/terminal claim to its single lifecycle owner. */\n\trecordManagedLane(event: ManagedLaneEvent): LaneRecord | undefined {\n\t\treturn this._getManagedLaneController().record(event);\n\t}\n\n\t/** Why the last idle research-lane evaluation skipped, for /autonomy diagnostics. */\n\tgetLastResearchLaneSkipReason(): string | undefined {\n\t\treturn this._research.getLastSkipReason();\n\t}\n\n\t/**\n\t * Abort in-flight research and delegate worker disposal to its single owning controller.\n\t *\n\t * This synchronous body is the LAST provably-safe write window for canceled/in-flight work.\n\t * `dispose()` (agent-session.ts) has already set the session's own disposed flag but has not yet\n\t * returned — no successor session (e.g. a `/reload` adoption) can exist yet, so an append here\n\t * cannot interleave with one; a post-await continuation resuming AFTER this method returns must\n\t * not append (see the disposed branch in `runWorkerDelegationOnce`). Persist FIRST, then\n\t * complete-in-memory, so a throw from one lane's persist cannot skip another's; each persist gets\n\t * its own try/catch — dispose must never throw.\n\t */\n\tabortInFlightLanes(): void {\n\t\tthis._goalAutoContinue.clearTimer();\n\t\tthis._research.abort();\n\t\tthis._fitness.abort();\n\t\tfor (const record of this._laneTracker.getRecords()) {\n\t\t\tif (record.status !== \"queued\" && record.status !== \"running\") continue;\n\t\t\tif (record.type === \"tmux-worker\") continue;\n\t\t\tconst canceled = this._laneTracker.complete(record.laneId, {\n\t\t\t\tstatus: \"canceled\",\n\t\t\t\treasonCode: \"session_disposed\",\n\t\t\t});\n\t\t\tif (!canceled) continue;\n\t\t\ttry {\n\t\t\t\tappendLaneRecordSnapshot(this.deps.getSessionManager(), canceled);\n\t\t\t} catch (error) {\n\t\t\t\tthis._safeWarn(\n\t\t\t\t\t`Failed to persist canceled lane record ${canceled.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis._managedLanes?.release();\n\n\t\tthis._workers?.abort();\n\t\tthis._workerNotifications?.dispose();\n\t}\n\n\tclearGoalAutoContinueTimer(): void {\n\t\tthis._goalAutoContinue.clearTimer();\n\t}\n\n\tscheduleGoalAutoContinueFromIdle(options?: PromptOptions): void {\n\t\tthis._goalAutoContinue.scheduleFromIdle(options);\n\t}\n\n\t/**\n\t * Single-flight entry point for EVERY goal-continuation loop invocation — idle autosteer\n\t * ({@link _runScheduledGoalAutoContinue}) AND the manual `/goal start` / `/goal-continue`\n\t * commands (reached through `AgentSession.continueGoalLoop`). Both paths ultimately submit\n\t * continuation prompts through the session's single `prompt()` path, so two loops racing throws\n\t * \"Agent is already processing\" from whichever submits second. `_isGoalAutoContinuing` is the\n\t * ONE owner of that mutex; `deps.continueGoalLoop` (the raw {@link GoalLoopController} loop)\n\t * must never be called directly outside this method, or the guard is bypassed.\n\t */\n\tasync continueGoalLoopExclusive(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult> {\n\t\treturn this._goalAutoContinue.continueExclusive(options);\n\t}\n\n\tclearResearchLaneTimer(): void {\n\t\tthis._research.clearTimer();\n\t}\n\n\tscheduleResearchLaneFromIdle(): void {\n\t\tthis._research.scheduleFromIdle();\n\t}\n\n\tresolveLaneModel(configuredPattern: string | undefined): Model<Api> | undefined {\n\t\treturn this._laneModels.resolveModel(configuredPattern);\n\t}\n\n\tgetOrchestrationProfileCatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\treturn this._getWorkerController().getProfileCatalog();\n\t}\n\n\tinspectTaskProfileOptions(): TaskProfileInspection {\n\t\treturn this._getWorkerController().inspectTaskProfileOptions();\n\t}\n\n\tcreateTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult {\n\t\treturn this._getWorkerController().createTaskProfile(input);\n\t}\n\n\t/**\n\t * Run one bounded, read-only research pass and persist its results: evidence bundle snapshot,\n\t * terminal lane record, and spawned-usage cost report (single-hop invariant, idempotent on the\n\t * lane's reportId). Explicit calls (e.g. `/autonomy research`) express user intent and bypass the\n\t * enabled/mode/dedupe gates the idle scheduler enforces; budget and capability gates always apply.\n\t */\n\tasync runResearchLaneOnce(request?: {\n\t\tquery?: string;\n\t\tcontext?: string;\n\t\tgoalId?: string;\n\t}): Promise<ResearchLaneRunOutcome> {\n\t\treturn this._research.runOnce(request);\n\t}\n\t/** Start a durable recursive agent with inherited, preset, or model-selected authority. */\n\tstartWorkerDelegation(\n\t\trequest: WorkerDelegationRequest,\n\t): { started: false; skipReason: string } | { started: true; record: LaneRecord } {\n\t\treturn this._getWorkerController().start(request);\n\t}\n\n\t/** Durable logical-worker controls. Each checks UAC before materializing worker state. */\n\tlistWorkerAgents(scope?: WorkerAgentControlScope): ReturnType<WorkerAgentControlPort[\"listWorkerAgents\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().listWorkerAgents(scope);\n\t}\n\n\tgetWorkerTaskSessionView(): ReturnType<WorkerAgentControlPort[\"getWorkerTaskSessionView\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().getWorkerTaskSessionView();\n\t}\n\n\tgetWorkerAgentActivity(agentId: string, scope?: WorkerAgentControlScope): WorkerAgentActivity {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().getWorkerAgentActivity(agentId, scope);\n\t}\n\n\treadWorkerAgentTranscript(\n\t\tagentId: string,\n\t\toptions?: WorkerAgentTranscriptOptions,\n\t): ReturnType<WorkerAgentControlPort[\"readWorkerAgentTranscript\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().readWorkerAgentTranscript(agentId, options);\n\t}\n\n\tsendWorkerAgentMessage(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: WorkerAgentMessageOptions,\n\t): { messageId: string; queued: true } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().sendWorkerAgentMessage(agentId, message, options);\n\t}\n\n\tfollowUpWorkerAgent(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: WorkerAgentMessageOptions,\n\t): { started: boolean; steering: boolean; messageId: string; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().followUpWorkerAgent(agentId, message, options);\n\t}\n\n\tsendSessionRootWorkerAgentMessage(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: SessionRootWorkerAgentMessageOptions,\n\t): { messageId: string; queued: true } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().sendSessionRootWorkerAgentMessage(agentId, message, options);\n\t}\n\n\tfollowUpSessionRootWorkerAgent(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: SessionRootWorkerAgentMessageOptions,\n\t): { started: boolean; steering: boolean; messageId: string; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().followUpSessionRootWorkerAgent(agentId, message, options);\n\t}\n\n\treplyToWorkerAgentMessage(sourceAgentId: string, message: string, replyToMessageId: string): WorkerAgentReplyResult {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController()\n\t\t\t.getAgentControl()\n\t\t\t.replyToWorkerAgentMessage(sourceAgentId, message, replyToMessageId);\n\t}\n\n\tlistSessionRootReplies(query?: SessionRootReplyQuery): SessionRootReply[] {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().listSessionRootReplies(query);\n\t}\n\n\twaitForSessionRootReplies(options?: SessionRootReplyWaitOptions): Promise<SessionRootReplyWaitResult> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().waitForSessionRootReplies(options);\n\t}\n\n\tacknowledgeSessionRootReply(messageId: string, ackToken: string): boolean {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().acknowledgeSessionRootReply(messageId, ackToken);\n\t}\n\n\treconcileSessionRootReplies(): void {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\tthis._getWorkerController().getAgentControl().reconcileSessionRootReplies();\n\t}\n\n\tstartWorkerAgentTask(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: WorkerAgentTaskStartOptions,\n\t): ReturnType<WorkerAgentControlPort[\"startWorkerAgentTask\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().startWorkerAgentTask(agentId, message, options);\n\t}\n\n\tinterruptWorkerAgent(agentId: string, scope?: WorkerAgentControlScope): { interrupted: boolean; reason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().interruptWorkerAgent(agentId, scope);\n\t}\n\n\tresumeWorkerAgent(\n\t\tagentId: string,\n\t\tscope?: WorkerAgentControlScope,\n\t): { started: boolean; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().resumeWorkerAgent(agentId, scope);\n\t}\n\n\tcancelWorkerAgent(agentId: string, reasonCode?: string, scope?: WorkerAgentControlScope): LaneRecord | undefined {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().cancelWorkerAgent(agentId, reasonCode, scope);\n\t}\n\n\tretireWorkerAgent(agentId: string, scope?: WorkerAgentControlScope): WorkerAgentRetireResult {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().retireWorkerAgent(agentId, scope);\n\t}\n\n\twaitForWorkerAgent(\n\t\tagentId: string,\n\t\ttimeoutMs?: number,\n\t\tscope?: WorkerAgentControlScope,\n\t): ReturnType<WorkerAgentControlPort[\"waitForWorkerAgent\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().waitForWorkerAgent(agentId, timeoutMs, scope);\n\t}\n\n\twaitForWorkerAgents(\n\t\tagentIds: readonly string[],\n\t\tmode: WorkerAgentWaitMode,\n\t\ttimeoutMs?: number,\n\t\tscope?: WorkerAgentControlScope,\n\t): Promise<WorkerAgentWaitResult> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().waitForWorkerAgents(agentIds, mode, timeoutMs, scope);\n\t}\n\n\tbroadcastWorkerAgentMessage(\n\t\tagentIds: readonly string[],\n\t\tmessage: string,\n\t\toptions: WorkerAgentBroadcastOptions,\n\t): WorkerAgentBroadcastResult {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().broadcastWorkerAgentMessage(agentIds, message, options);\n\t}\n\n\t/** Run one worker immediately; used by focused integrations and tests. */\n\tasync runWorkerDelegationOnce(\n\t\trequest: WorkerDelegationRequest,\n\t\tonStarted?: (record: LaneRecord) => void,\n\t\texistingRecord?: LaneRecord,\n\t): Promise<WorkerDelegationRunOutcome> {\n\t\treturn this._getWorkerController().runOnce(request, onStarted, existingRecord);\n\t}\n\t/**\n\t * Probe a candidate model against the subagent contracts (research/worker/judge/search/\n\t * tool-call surfaces) via {@link runModelFitnessProbe}. The model must resolve and\n\t * authenticate; every probe call runs as an isolated completion on that model, and probe\n\t * spend is reported through spawned-usage accounting.\n\t */\n\tasync runModelFitness(args: {\n\t\tmodel: string;\n\t\ttrials?: number;\n\t\t/** LLM tool-call id, present only via the model_fitness tool path — see model-fitness.ts. */\n\t\ttoolCallId?: string;\n\t}): Promise<{ started: true; model: string; report: ModelFitnessReport } | { started: false; skipReason: string }> {\n\t\treturn this._fitness.run(args);\n\t}\n\n\t/** Start every capacity-eligible queued worker at the owner session's foreground-idle boundary. */\n\tdrainQueuedWorkerDelegations(): void {\n\t\tif (this.deps.isDelegateToolActive?.()) this._getWorkerController().drain();\n\t}\n\n\t/** Fitness reports persisted for THIS host (measured evidence for architect/profile decisions). */\n\tgetStoredFitnessReports(): StoredFitnessReport[] {\n\t\treturn this._fitness.getStoredReports();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"background-lane-controller.js","sourceRoot":"","sources":["../../src/core/background-lane-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;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F,CAAC;IACD;;;;;OAKG;IACH,KAAK,CAAC,eAAe,CAAC,IAKrB;QACA,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,mGAAmG;IACnG,4BAA4B;QAC3B,IAAI,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,EAAE;YAAE,IAAI,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,CAAC;IAC7E,CAAC;IAED,mGAAmG;IACnG,uBAAuB;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC;CACD","sourcesContent":["/**\n * Execution-plane coordinator for goal continuation, research, managed lanes, worker delegation,\n * and model fitness.\n *\n * Coordination state is owned by focused controllers. This coordinator retains one AgentSession\n * composition seam and a shared lane read model. Everything it needs\n * — the session manager, settings, model registry, live model, capability envelope, the goal\n * continuation LOOP, the isolated-completion primitive, spawned-usage accounting, and the telemetry\n * sink — is reached through narrow deps accessors rather than the whole AgentSession.\n *\n * Drive-loop boundary (deliberate): the idle triggers ({@link scheduleGoalAutoContinueFromIdle},\n * {@link scheduleResearchLaneFromIdle}) are invoked from the session's prompt tail as one-line\n * delegations; goal auto-continue itself only ever asks the session to `continueGoalLoop`, so this\n * controller never touches `prompt()`, the last-assistant-message, retry, or streaming state.\n */\n\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport type {\n\tGoalContinuationLoopOptions,\n\tGoalContinuationLoopResult,\n\tPromptOptions,\n\tResearchLaneRunOutcome,\n\tWorkerDelegationRunOutcome,\n} from \"./agent-session-contracts.ts\";\nimport { type LaneRecord, LaneTracker } from \"./autonomy/lane-tracker.ts\";\nimport { appendLaneRecordSnapshot, getLatestLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport { ManagedLaneController } from \"./delegation/managed-lane-controller.ts\";\nimport type {\n\tSessionRootReply,\n\tSessionRootReplyQuery,\n\tSessionRootReplyWaitOptions,\n\tSessionRootReplyWaitResult,\n} from \"./delegation/session-root-mailbox.ts\";\nimport type {\n\tSessionRootWorkerAgentMessageOptions,\n\tWorkerAgentActivity,\n\tWorkerAgentBroadcastOptions,\n\tWorkerAgentBroadcastResult,\n\tWorkerAgentControlPort,\n\tWorkerAgentControlScope,\n\tWorkerAgentMessageOptions,\n\tWorkerAgentReplyResult,\n\tWorkerAgentRetireResult,\n\tWorkerAgentTaskStartOptions,\n\tWorkerAgentTranscriptOptions,\n\tWorkerAgentWaitMode,\n\tWorkerAgentWaitResult,\n} from \"./delegation/worker-agent-control.ts\";\nimport {\n\tWorkerDelegationController,\n\ttype WorkerDelegationControllerDeps,\n} from \"./delegation/worker-delegation-controller.ts\";\nimport type { WorkerDelegationRequest } from \"./delegation/worker-delegation-request.ts\";\nimport { WorkerLifecycle } from \"./delegation/worker-lifecycle.ts\";\nimport { WorkerNotificationCoordinator } from \"./delegation/worker-notification-coordinator.ts\";\nimport type { ManagedLaneEvent } from \"./extensions/types.ts\";\nimport { GoalAutoContinueController } from \"./goals/goal-auto-continue-controller.ts\";\nimport type { GoalRuntimeSnapshot, GoalRuntimeSnapshotSettings } from \"./goals/goal-runtime-snapshot.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { ModelCapabilityProfile } from \"./model-capability.ts\";\nimport type { StoredFitnessReport } from \"./models/fitness-store.ts\";\nimport type {\n\tTaskProfileCreateInput,\n\tTaskProfileCreateResult,\n\tTaskProfileInspection,\n} from \"./orchestration/task-profile-writer.ts\";\nimport type { TaskRuntimeProjection } from \"./orchestration/task-runtime.ts\";\nimport { LaneModelResolver, type LaneModelResolverDeps } from \"./research/lane-model-resolver.ts\";\nimport type { ModelFitnessReport } from \"./research/model-fitness.ts\";\nimport { ModelFitnessController, type ModelFitnessControllerDeps } from \"./research/model-fitness-controller.ts\";\nimport { ResearchLaneController, type ResearchLaneControllerDeps } from \"./research/research-lane-controller.ts\";\nimport { getActiveSessionBranchEntries } from \"./session-snapshot.ts\";\n\nexport { isLocalExecutionModel } from \"./delegation/worker-delegation-controller.ts\";\nexport { clampLaneMaxUsd } from \"./research/lane-model-resolver.ts\";\n\nexport interface BackgroundLaneControllerDeps\n\textends WorkerDelegationControllerDeps,\n\t\tResearchLaneControllerDeps,\n\t\tModelFitnessControllerDeps,\n\t\tLaneModelResolverDeps {\n\t/** True iff the `goal` tool is in the session's ACTIVE surface -- the capability-adaptive gate\n\t * for every goal-continuation loop (see `continueGoalLoopExclusive`): a surface without the\n\t * goal tool (lean capability blocklist, worker role ceiling, --tools/profile exclusion) must\n\t * never be driven with continuation prompts it cannot execute. */\n\tisGoalToolActive(): boolean;\n\t/** Capability profile of the SESSION model (gates background lanes, scales continuation budgets). */\n\tgetModelCapabilityProfile(): ModelCapabilityProfile;\n\t/** Continuation gate + goal state for the idle autosteer scheduler. */\n\tgetGoalRuntimeSnapshot(settings: GoalRuntimeSnapshotSettings): GoalRuntimeSnapshot;\n\t/** Drive-loop boundary: the session's bounded goal-continuation loop (owns `prompt()`, not us). */\n\tcontinueGoalLoop(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult>;\n\t/** True while the session owns a foreground prompt/retry/follow-up run. */\n\tisForegroundBusy(): boolean;\n\t/** Resolve only after the complete foreground retry/follow-up run releases the session. */\n\twaitForForegroundIdle(): Promise<void>;\n\t/** Persist an explicit stopped state when the selected surface cannot drive the active goal. */\n\tmarkGoalToolUnavailable(): void;\n}\n\nexport class BackgroundLaneController implements WorkerAgentControlPort {\n\t/** Live lane registry — the real source for AutonomyStatusSnapshot.activeLaneCount. */\n\tprivate readonly _laneTracker = new LaneTracker();\n\tprivate readonly _laneModels: LaneModelResolver;\n\tprivate readonly _goalAutoContinue: GoalAutoContinueController;\n\tprivate readonly _research: ResearchLaneController;\n\tprivate readonly _fitness: ModelFitnessController;\n\t/** Lazily materialized only when managed-lane state is queried or reported. */\n\tprivate _managedLanes: ManagedLaneController | undefined;\n\t/** Lazily materialized so a UAC surface without `delegate` allocates no worker runtime state. */\n\tprivate _workers: WorkerDelegationController | undefined;\n\t/** One durable lifecycle shared by every worker execution adapter. */\n\tprivate _workerLifecycle: WorkerLifecycle | undefined;\n\t/** Shared terminal outbox for managed and in-process workers; lazy under UAC omission. */\n\tprivate _workerNotifications: WorkerNotificationCoordinator | undefined;\n\tprivate readonly deps: BackgroundLaneControllerDeps;\n\n\t/** Emit a warning without ever throwing — used from disposal-adjacent persistence where a\n\t * listener failure (or a bare test double missing `emit`) must never block or crash cleanup. */\n\tprivate _safeWarn(message: string): void {\n\t\ttry {\n\t\t\tthis.deps.emit({ type: \"warning\", message });\n\t\t} catch {\n\t\t\t// Dispose must never throw.\n\t\t}\n\t}\n\n\tprivate _recordWorkerTerminal(record: LaneRecord, durableNotificationId: string): void {\n\t\tthis._getWorkerNotificationCoordinator().recordTerminal(record, durableNotificationId);\n\t}\n\n\tconstructor(deps: BackgroundLaneControllerDeps) {\n\t\tthis.deps = deps;\n\t\tthis._laneModels = new LaneModelResolver(deps);\n\t\tthis._research = new ResearchLaneController(deps, this._laneTracker, this._laneModels);\n\t\tthis._fitness = new ModelFitnessController(deps, this._laneModels);\n\t\tthis._goalAutoContinue = new GoalAutoContinueController({\n\t\t\tisDisposed: deps.isDisposed,\n\t\t\tisGoalToolActive: deps.isGoalToolActive,\n\t\t\tgetSettingsManager: deps.getSettingsManager,\n\t\t\tgetModelCapabilityProfile: deps.getModelCapabilityProfile,\n\t\t\tgetGoalRuntimeSnapshot: deps.getGoalRuntimeSnapshot,\n\t\t\thasInFlightLaneForGoal: (goalId) => this._hasInFlightLaneForGoal(goalId),\n\t\t\tcontinueGoalLoop: deps.continueGoalLoop,\n\t\t\tisForegroundBusy: deps.isForegroundBusy,\n\t\t\twaitForForegroundIdle: deps.waitForForegroundIdle,\n\t\t\tmarkGoalToolUnavailable: deps.markGoalToolUnavailable,\n\t\t\temit: deps.emit,\n\t\t});\n\t}\n\n\tprivate _getWorkerController(): WorkerDelegationController {\n\t\tthis._workers ??= new WorkerDelegationController(\n\t\t\tthis.deps,\n\t\t\tthis._getWorkerNotificationCoordinator(),\n\t\t\tthis._getWorkerLifecycle(),\n\t\t);\n\t\treturn this._workers;\n\t}\n\n\tprivate _getWorkerLifecycle(): WorkerLifecycle {\n\t\tif (this._workerLifecycle) return this._workerLifecycle;\n\t\tconst lifecycle = new WorkerLifecycle({\n\t\t\tagentDir: this.deps.getAgentDir(),\n\t\t\tsessionId: this.deps.getSessionId(),\n\t\t});\n\t\tthis._workerLifecycle = lifecycle;\n\t\tfor (const notification of lifecycle.getPendingTerminalNotifications()) {\n\t\t\tthis._getWorkerNotificationCoordinator().recordTerminal(notification.record, notification.notificationId);\n\t\t}\n\t\treturn lifecycle;\n\t}\n\n\tprivate _getWorkerNotificationCoordinator(): WorkerNotificationCoordinator {\n\t\tthis._workerNotifications ??= new WorkerNotificationCoordinator({\n\t\t\tgetWorkerRecords: () => this._workerLifecycle?.getAllRecords() ?? [],\n\t\t\temitStatus: (status) => {\n\t\t\t\t// Runs once per flush, with the EXACT batch about to be handed to notify() -- the\n\t\t\t\t// natural checkpoint to backfill durability before that batch can get stuck behind\n\t\t\t\t// an unsettled notify() call with no durable trace. (getOutstandingRecords() is not\n\t\t\t\t// usable here: the coordinator emits status BEFORE moving this same batch from\n\t\t\t\t// `pending` into `inFlight`, so at this exact moment it would report nothing\n\t\t\t\t// outstanding — status.terminalSinceFlush is the batch, directly, no timing gap.)\n\t\t\t\tthis._ensureDurableNotifications(status.terminalSinceFlush);\n\t\t\t\ttry {\n\t\t\t\t\tthis.deps.emit({\n\t\t\t\t\t\ttype: \"delegate_workers\",\n\t\t\t\t\t\t...status,\n\t\t\t\t\t\tterminalSinceFlush: [...status.terminalSinceFlush],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\t// A partial integration must not crash the event-driven terminal outbox.\n\t\t\t\t}\n\t\t\t},\n\t\t\tnotify: (records) => this.deps.notifyWorkerTerminalHandoff(records),\n\t\t\twarn: (message) => this._safeWarn(message),\n\t\t\tmarkDurableDelivered: (notificationIds) => this._workerLifecycle?.markNotificationsDelivered(notificationIds),\n\t\t});\n\t\treturn this._workerNotifications;\n\t}\n\n\t/**\n\t * Backfills a durable notification for every record about to be flushed, through the SAME\n\t * durable notification store `_getWorkerLifecycle()` already replays from on construction\n\t * (`getPendingTerminalNotifications()` / `markNotificationsDelivered()`) -- not a new\n\t * persistence subsystem. `WorkerLifecycle.getTerminalNotification()` is idempotent (it reuses\n\t * an existing durable entry for the same laneId/attemptId or creates exactly one), so calling\n\t * it for a record that already has a durable notification is a safe no-op. Without this, a\n\t * \"transient:<laneId>:<completedAt>\" record (recorded without a durableNotificationId — e.g.\n\t * because no attempt was resolvable at record time) has no trace in the durable ledger at all:\n\t * if it's still stuck behind an unresolved notify() when the process restarts, the replay on\n\t * the next construction can only find what was durably enqueued, so it would be lost instead of\n\t * replayed.\n\t */\n\tprivate _ensureDurableNotifications(records: readonly Pick<LaneRecord, \"laneId\">[]): void {\n\t\tif (!this._workerLifecycle) return;\n\t\tfor (const record of records) {\n\t\t\ttry {\n\t\t\t\tthis._workerLifecycle.getTerminalNotification(record.laneId);\n\t\t\t} catch (error) {\n\t\t\t\tthis._safeWarn(\n\t\t\t\t\t`Failed to durably back the worker terminal notification for ${record.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _getManagedLaneController(): ManagedLaneController {\n\t\tthis._managedLanes ??= new ManagedLaneController(\n\t\t\tthis.deps,\n\t\t\tthis._getWorkerLifecycle(),\n\t\t\t(record, notificationId) => this._recordWorkerTerminal(record, notificationId),\n\t\t\t(message) => this._safeWarn(message),\n\t\t);\n\t\treturn this._managedLanes;\n\t}\n\n\tprivate _hydrateManagedLanes(): void {\n\t\tif (this._managedLanes) {\n\t\t\tthis._managedLanes.ensureHydrated();\n\t\t\treturn;\n\t\t}\n\t\tconst hasPersistedActiveManagedLane = getLatestLaneRecordSnapshots(\n\t\t\tgetActiveSessionBranchEntries(this.deps.getSessionManager()),\n\t\t).some((record) => record.type === \"tmux-worker\" && (record.status === \"queued\" || record.status === \"running\"));\n\t\tif (hasPersistedActiveManagedLane) this._getManagedLaneController().ensureHydrated();\n\t}\n\n\t/** Live lane records tracked by this process (running and terminal). */\n\tgetLaneRecords(): LaneRecord[] {\n\t\tthis._hydrateManagedLanes();\n\t\tconst workerRecords =\n\t\t\tthis._workers?.getRecords() ??\n\t\t\t(this.deps.isDelegateToolActive?.() ? this._getWorkerController().getRecords() : []);\n\t\treturn [\n\t\t\t...this._laneTracker.getRecords(),\n\t\t\t...workerRecords,\n\t\t\t...(this._workerLifecycle?.getManagedRecords() ?? []),\n\t\t];\n\t}\n\n\t/** Does not materialize the worker controller when UAC omitted delegation. */\n\tgetTaskRuntimeSnapshot(): TaskRuntimeProjection | undefined {\n\t\treturn this._workerLifecycle?.getTaskRuntimeSnapshot();\n\t}\n\n\t/** Reconcile only when delegation has already been materialized; UAC omission stays zero-load. */\n\tsynchronizeGoalState(goal: GoalState): void {\n\t\tthis._workers?.synchronizeGoalState(goal);\n\t}\n\n\t/**\n\t * Resolve a tracked managed-lane dispatch. The caller's stable id is also the canonical durable\n\t * lane id, so this is an existence check rather than an id translation.\n\t */\n\tresolveManagedLaneId(callerLaneId: string): string | undefined {\n\t\treturn this._getManagedLaneController().resolve(callerLaneId);\n\t}\n\n\t/** Live count of active lanes — the real source for AutonomyStatusSnapshot.activeLaneCount. */\n\tgetActiveLaneCount(): number {\n\t\treturn this.getLaneRecords().filter((record) => record.status === \"queued\" || record.status === \"running\").length;\n\t}\n\n\t/** Belt-and-braces guard: whether ANY queued/running lane is tagged with this goalId. */\n\tprivate _hasInFlightLaneForGoal(goalId: string): boolean {\n\t\treturn this.getLaneRecords().some(\n\t\t\t(record) => record.goalId === goalId && (record.status === \"queued\" || record.status === \"running\"),\n\t\t);\n\t}\n\n\t/** Delegate the out-of-process dispatch/terminal claim to its single lifecycle owner. */\n\trecordManagedLane(event: ManagedLaneEvent): LaneRecord | undefined {\n\t\treturn this._getManagedLaneController().record(event);\n\t}\n\n\t/** Why the last idle research-lane evaluation skipped, for /autonomy diagnostics. */\n\tgetLastResearchLaneSkipReason(): string | undefined {\n\t\treturn this._research.getLastSkipReason();\n\t}\n\n\t/**\n\t * Abort in-flight research and delegate worker disposal to its single owning controller.\n\t *\n\t * This synchronous body is the LAST provably-safe write window for canceled/in-flight work.\n\t * `dispose()` (agent-session.ts) has already set the session's own disposed flag but has not yet\n\t * returned — no successor session (e.g. a `/reload` adoption) can exist yet, so an append here\n\t * cannot interleave with one; a post-await continuation resuming AFTER this method returns must\n\t * not append (see the disposed branch in `runWorkerDelegationOnce`). Persist FIRST, then\n\t * complete-in-memory, so a throw from one lane's persist cannot skip another's; each persist gets\n\t * its own try/catch — dispose must never throw.\n\t */\n\tabortInFlightLanes(): void {\n\t\tthis._goalAutoContinue.clearTimer();\n\t\tthis._research.abort();\n\t\tthis._fitness.abort();\n\t\tfor (const record of this._laneTracker.getRecords()) {\n\t\t\tif (record.status !== \"queued\" && record.status !== \"running\") continue;\n\t\t\tif (record.type === \"tmux-worker\") continue;\n\t\t\tconst canceled = this._laneTracker.complete(record.laneId, {\n\t\t\t\tstatus: \"canceled\",\n\t\t\t\treasonCode: \"session_disposed\",\n\t\t\t});\n\t\t\tif (!canceled) continue;\n\t\t\ttry {\n\t\t\t\tappendLaneRecordSnapshot(this.deps.getSessionManager(), canceled);\n\t\t\t} catch (error) {\n\t\t\t\tthis._safeWarn(\n\t\t\t\t\t`Failed to persist canceled lane record ${canceled.laneId}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tthis._managedLanes?.release();\n\n\t\tthis._workers?.abort();\n\t\tthis._workerNotifications?.dispose();\n\t}\n\n\tclearGoalAutoContinueTimer(): void {\n\t\tthis._goalAutoContinue.clearTimer();\n\t}\n\n\tscheduleGoalAutoContinueFromIdle(options?: PromptOptions): void {\n\t\tthis._goalAutoContinue.scheduleFromIdle(options);\n\t}\n\n\t/**\n\t * Single-flight entry point for EVERY goal-continuation loop invocation — idle autosteer\n\t * ({@link _runScheduledGoalAutoContinue}) AND the manual `/goal start` / `/goal-continue`\n\t * commands (reached through `AgentSession.continueGoalLoop`). Both paths ultimately submit\n\t * continuation prompts through the session's single `prompt()` path, so two loops racing throws\n\t * \"Agent is already processing\" from whichever submits second. `_isGoalAutoContinuing` is the\n\t * ONE owner of that mutex; `deps.continueGoalLoop` (the raw {@link GoalLoopController} loop)\n\t * must never be called directly outside this method, or the guard is bypassed.\n\t */\n\tasync continueGoalLoopExclusive(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult> {\n\t\treturn this._goalAutoContinue.continueExclusive(options);\n\t}\n\n\tclearResearchLaneTimer(): void {\n\t\tthis._research.clearTimer();\n\t}\n\n\tscheduleResearchLaneFromIdle(): void {\n\t\tthis._research.scheduleFromIdle();\n\t}\n\n\tresolveLaneModel(configuredPattern: string | undefined): Model<Api> | undefined {\n\t\treturn this._laneModels.resolveModel(configuredPattern);\n\t}\n\n\tgetOrchestrationProfileCatalog(): Array<{ profileId: string; role: string; description: string }> {\n\t\treturn this._getWorkerController().getProfileCatalog();\n\t}\n\n\tinspectTaskProfileOptions(): TaskProfileInspection {\n\t\treturn this._getWorkerController().inspectTaskProfileOptions();\n\t}\n\n\tcreateTaskProfile(input: TaskProfileCreateInput): TaskProfileCreateResult {\n\t\treturn this._getWorkerController().createTaskProfile(input);\n\t}\n\n\t/**\n\t * Run one bounded, read-only research pass and persist its results: evidence bundle snapshot,\n\t * terminal lane record, and spawned-usage cost report (single-hop invariant, idempotent on the\n\t * lane's reportId). Explicit calls (e.g. `/autonomy research`) express user intent and bypass the\n\t * enabled/mode/dedupe gates the idle scheduler enforces; budget and capability gates always apply.\n\t */\n\tasync runResearchLaneOnce(request?: {\n\t\tquery?: string;\n\t\tcontext?: string;\n\t\tgoalId?: string;\n\t}): Promise<ResearchLaneRunOutcome> {\n\t\treturn this._research.runOnce(request);\n\t}\n\t/** Start a durable recursive agent with inherited, preset, or model-selected authority. */\n\tstartWorkerDelegation(\n\t\trequest: WorkerDelegationRequest,\n\t): { started: false; skipReason: string } | { started: true; record: LaneRecord } {\n\t\treturn this._getWorkerController().start(request);\n\t}\n\n\t/** Durable logical-worker controls. Each checks UAC before materializing worker state. */\n\tlistWorkerAgents(scope?: WorkerAgentControlScope): ReturnType<WorkerAgentControlPort[\"listWorkerAgents\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().listWorkerAgents(scope);\n\t}\n\n\tgetWorkerTaskSessionView(): ReturnType<WorkerAgentControlPort[\"getWorkerTaskSessionView\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().getWorkerTaskSessionView();\n\t}\n\n\tgetWorkerAgentActivity(agentId: string, scope?: WorkerAgentControlScope): WorkerAgentActivity {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().getWorkerAgentActivity(agentId, scope);\n\t}\n\n\treadWorkerAgentTranscript(\n\t\tagentId: string,\n\t\toptions?: WorkerAgentTranscriptOptions,\n\t): ReturnType<WorkerAgentControlPort[\"readWorkerAgentTranscript\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().readWorkerAgentTranscript(agentId, options);\n\t}\n\n\tsendWorkerAgentMessage(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: WorkerAgentMessageOptions,\n\t): { messageId: string; queued: true } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().sendWorkerAgentMessage(agentId, message, options);\n\t}\n\n\tfollowUpWorkerAgent(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: WorkerAgentMessageOptions,\n\t): { started: boolean; steering: boolean; messageId: string; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().followUpWorkerAgent(agentId, message, options);\n\t}\n\n\tsendSessionRootWorkerAgentMessage(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: SessionRootWorkerAgentMessageOptions,\n\t): { messageId: string; queued: true } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().sendSessionRootWorkerAgentMessage(agentId, message, options);\n\t}\n\n\tfollowUpSessionRootWorkerAgent(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: SessionRootWorkerAgentMessageOptions,\n\t): { started: boolean; steering: boolean; messageId: string; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().followUpSessionRootWorkerAgent(agentId, message, options);\n\t}\n\n\treplyToWorkerAgentMessage(sourceAgentId: string, message: string, replyToMessageId: string): WorkerAgentReplyResult {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController()\n\t\t\t.getAgentControl()\n\t\t\t.replyToWorkerAgentMessage(sourceAgentId, message, replyToMessageId);\n\t}\n\n\tlistSessionRootReplies(query?: SessionRootReplyQuery): SessionRootReply[] {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().listSessionRootReplies(query);\n\t}\n\n\twaitForSessionRootReplies(options?: SessionRootReplyWaitOptions): Promise<SessionRootReplyWaitResult> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().waitForSessionRootReplies(options);\n\t}\n\n\tacknowledgeSessionRootReply(messageId: string, ackToken: string): boolean {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().acknowledgeSessionRootReply(messageId, ackToken);\n\t}\n\n\treconcileSessionRootReplies(): void {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\tthis._getWorkerController().getAgentControl().reconcileSessionRootReplies();\n\t}\n\n\tstartWorkerAgentTask(\n\t\tagentId: string,\n\t\tmessage: string,\n\t\toptions?: WorkerAgentTaskStartOptions,\n\t): ReturnType<WorkerAgentControlPort[\"startWorkerAgentTask\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().startWorkerAgentTask(agentId, message, options);\n\t}\n\n\tinterruptWorkerAgent(agentId: string, scope?: WorkerAgentControlScope): { interrupted: boolean; reason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().interruptWorkerAgent(agentId, scope);\n\t}\n\n\tresumeWorkerAgent(\n\t\tagentId: string,\n\t\tscope?: WorkerAgentControlScope,\n\t): { started: boolean; record?: LaneRecord; skipReason?: string } {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().resumeWorkerAgent(agentId, scope);\n\t}\n\n\tcancelWorkerAgent(agentId: string, reasonCode?: string, scope?: WorkerAgentControlScope): LaneRecord | undefined {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().cancelWorkerAgent(agentId, reasonCode, scope);\n\t}\n\n\tretireWorkerAgent(agentId: string, scope?: WorkerAgentControlScope): WorkerAgentRetireResult {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().retireWorkerAgent(agentId, scope);\n\t}\n\n\twaitForWorkerAgent(\n\t\tagentId: string,\n\t\ttimeoutMs?: number,\n\t\tscope?: WorkerAgentControlScope,\n\t): ReturnType<WorkerAgentControlPort[\"waitForWorkerAgent\"]> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().waitForWorkerAgent(agentId, timeoutMs, scope);\n\t}\n\n\twaitForWorkerAgents(\n\t\tagentIds: readonly string[],\n\t\tmode: WorkerAgentWaitMode,\n\t\ttimeoutMs?: number,\n\t\tscope?: WorkerAgentControlScope,\n\t): Promise<WorkerAgentWaitResult> {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().waitForWorkerAgents(agentIds, mode, timeoutMs, scope);\n\t}\n\n\tbroadcastWorkerAgentMessage(\n\t\tagentIds: readonly string[],\n\t\tmessage: string,\n\t\toptions: WorkerAgentBroadcastOptions,\n\t): WorkerAgentBroadcastResult {\n\t\tif (!this.deps.isDelegateToolActive())\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\treturn this._getWorkerController().getAgentControl().broadcastWorkerAgentMessage(agentIds, message, options);\n\t}\n\n\t/** Run one worker immediately; used by focused integrations and tests. */\n\tasync runWorkerDelegationOnce(\n\t\trequest: WorkerDelegationRequest,\n\t\tonStarted?: (record: LaneRecord) => void,\n\t\texistingRecord?: LaneRecord,\n\t): Promise<WorkerDelegationRunOutcome> {\n\t\treturn this._getWorkerController().runOnce(request, onStarted, existingRecord);\n\t}\n\t/**\n\t * Probe a candidate model against the subagent contracts (research/worker/judge/search/\n\t * tool-call surfaces) via {@link runModelFitnessProbe}. The model must resolve and\n\t * authenticate; every probe call runs as an isolated completion on that model, and probe\n\t * spend is reported through spawned-usage accounting.\n\t */\n\tasync runModelFitness(args: {\n\t\tmodel: string;\n\t\ttrials?: number;\n\t\t/** LLM tool-call id, present only via the model_fitness tool path — see model-fitness.ts. */\n\t\ttoolCallId?: string;\n\t}): Promise<{ started: true; model: string; report: ModelFitnessReport } | { started: false; skipReason: string }> {\n\t\treturn this._fitness.run(args);\n\t}\n\n\t/** Start every capacity-eligible queued worker at the owner session's foreground-idle boundary. */\n\tdrainQueuedWorkerDelegations(): void {\n\t\tif (this.deps.isDelegateToolActive?.()) this._getWorkerController().drain();\n\t}\n\n\t/** Fitness reports persisted for THIS host (measured evidence for architect/profile decisions). */\n\tgetStoredFitnessReports(): StoredFitnessReport[] {\n\t\treturn this._fitness.getStoredReports();\n\t}\n}\n"]}
|
|
@@ -52,7 +52,7 @@ export class BillingFailoverController {
|
|
|
52
52
|
const hop = defaultModelId ? this.deps.modelRegistry.find(failedModel.provider, defaultModelId) : undefined;
|
|
53
53
|
const action = decideBillingFailover({
|
|
54
54
|
failedModel: { provider: failedModel.provider, id: failedModel.id },
|
|
55
|
-
billingClass: this.deps.modelRegistry.
|
|
55
|
+
billingClass: this.deps.modelRegistry.isUsingSubscription(failedModel) ? "subscription" : "metered",
|
|
56
56
|
providerDefaultModelId: defaultModelId,
|
|
57
57
|
hopResolvesWithAuth: Boolean(hop && this.deps.modelRegistry.hasConfiguredAuth(hop)),
|
|
58
58
|
hopExhausted: hop ? this.deps.exhausted.isExhausted(`${hop.provider}/${hop.id}`) : false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing-failover-controller.js","sourceRoot":"","sources":["../../src/core/billing-failover-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAE9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAI9D,MAAM,0BAA0B,GAA2B;IAC1D,cAAc,EAAE,aAAa;CAC7B,CAAC;AAEF,MAAM,OAAO,yBAAyB;IAAtC;QACkB,cAAS,GAAG,IAAI,GAAG,EAA8B,CAAC;IAiBpE,CAAC;IAfA,aAAa,CAAC,GAAW,EAAE,KAAc;QACxC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,WAAW,CAAC,GAAW;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;YAAE,OAAO,IAAI,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,OAAO,KAAK,CAAC;IACd,CAAC;IAED,QAAQ;QACP,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1E,CAAC;CACD;AAgBD,MAAM,OAAO,yBAAyB;IAIrC,YAAY,IAAmC;QAC9C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,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,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED,SAAS,oBAAoB,CAAC,YAAgC;IAC7D,OAAO,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,CAAC;AAC3E,CAAC","sourcesContent":["import type { Agent } from \"@caupulican/pi-agent-core/agent\";\nimport { type ClassifiedError, classifyFailure } from \"@caupulican/pi-agent-core/reliability\";\nimport type { Api, AssistantMessage, Model } from \"@caupulican/pi-ai\";\nimport { decideBillingFailover } from \"./billing-failover.ts\";\nimport type { ModelRegistry } from \"./model-registry.ts\";\nimport type { ModelRouterFailoverStatus } from \"./model-router/status.ts\";\n\nconst DEFAULT_MODEL_PER_PROVIDER: Record<string, string> = {\n\t\"openai-codex\": \"gpt-5.6-sol\",\n};\n\nexport class ExhaustedProviderRegistry {\n\tprivate readonly exhausted = new Map<string, number | undefined>();\n\n\tmarkExhausted(ref: string, until?: number): void {\n\t\tthis.exhausted.set(ref, until);\n\t}\n\n\tisExhausted(ref: string): boolean {\n\t\tconst until = this.exhausted.get(ref);\n\t\tif (until === undefined) return this.exhausted.has(ref);\n\t\tif (Date.now() < until) return true;\n\t\tthis.exhausted.delete(ref);\n\t\treturn false;\n\t}\n\n\tsnapshot(): string[] {\n\t\treturn [...this.exhausted.keys()].filter((ref) => this.isExhausted(ref));\n\t}\n}\n\nexport interface BillingFailoverControllerDeps {\n\tagent: Agent;\n\tmodelRegistry: ModelRegistry;\n\temit(event: { type: \"warning\"; message: string }): void;\n\texhausted: ExhaustedProviderRegistry;\n\tsubscriptionHop?: boolean;\n\trecordFailure?(args: {\n\t\tprovider?: string;\n\t\tmodelId?: string;\n\t\tmessage: string;\n\t\tclassified: ReturnType<typeof classifyFailure>;\n\t}): void;\n}\n\nexport class BillingFailoverController {\n\tprivate readonly deps: BillingFailoverControllerDeps;\n\tprivate lastNotice: string | undefined;\n\n\tconstructor(deps: BillingFailoverControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tisExhausted(ref: string): boolean {\n\t\treturn this.deps.exhausted.isExhausted(ref);\n\t}\n\n\tsnapshotExhausted(): string[] {\n\t\treturn this.deps.exhausted.snapshot();\n\t}\n\n\tgetLastNotice(): string | undefined {\n\t\treturn this.lastNotice;\n\t}\n\n\tgetStatus(): ModelRouterFailoverStatus {\n\t\treturn { exhausted: this.snapshotExhausted(), lastNotice: this.lastNotice };\n\t}\n\n\tasync handleAssistantError(message: AssistantMessage, classified?: ClassifiedError): Promise<boolean> {\n\t\tif (message.stopReason !== \"error\") return false;\n\t\tclassified ??= classifyFailure({ message: message.errorMessage ?? \"\", provider: message.provider });\n\t\tif (classified.reason !== \"billing_or_quota\") return false;\n\t\tconst failedModel = this.deps.modelRegistry.find(message.provider, message.model) ?? this.deps.agent.state.model;\n\t\tconst failedRef = `${failedModel.provider}/${failedModel.id}`;\n\t\tthis.deps.exhausted.markExhausted(failedRef, expiryFromRetryAfter(classified.retryAfterMs));\n\n\t\tconst defaultModelId = DEFAULT_MODEL_PER_PROVIDER[failedModel.provider];\n\t\tconst hop = defaultModelId ? this.deps.modelRegistry.find(failedModel.provider, defaultModelId) : undefined;\n\t\tconst action = decideBillingFailover({\n\t\t\tfailedModel: { provider: failedModel.provider, id: failedModel.id },\n\t\t\tbillingClass: this.deps.modelRegistry.isUsingSubscription(failedModel) ? \"subscription\" : \"metered\",\n\t\t\tproviderDefaultModelId: defaultModelId,\n\t\t\thopResolvesWithAuth: Boolean(hop && this.deps.modelRegistry.hasConfiguredAuth(hop)),\n\t\t\thopExhausted: hop ? this.deps.exhausted.isExhausted(`${hop.provider}/${hop.id}`) : false,\n\t\t\tsubscriptionHop: this.deps.subscriptionHop,\n\t\t});\n\t\tif (action.action === \"failover\") {\n\t\t\tthis.deps.agent.state.model = hop as Model<Api>;\n\t\t}\n\t\tthis.lastNotice = action.notice;\n\t\tthis.deps.emit({ type: \"warning\", message: action.notice });\n\t\treturn true;\n\t}\n}\n\nfunction expiryFromRetryAfter(retryAfterMs: number | undefined): number | undefined {\n\treturn retryAfterMs === undefined ? undefined : Date.now() + retryAfterMs;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-work-memory.d.ts","sourceRoot":"","sources":["../../../src/core/context/current-work-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"current-work-memory.d.ts","sourceRoot":"","sources":["../../../src/core/context/current-work-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA2C,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,WAAW,sBAAsB;IACtC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAiCD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,sBAAsB,GAAG,mBAAmB,EAAE,CAoC7F"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isGoalExecutionActive } from "../goals/goal-state.js";
|
|
1
2
|
function shortText(text, maxChars) {
|
|
2
3
|
const normalized = text.replace(/\s+/g, " ").trim();
|
|
3
4
|
if (normalized.length <= maxChars)
|
|
@@ -26,7 +27,7 @@ function requirementSummary(requirements) {
|
|
|
26
27
|
}
|
|
27
28
|
export function collectCurrentWorkMemory(input) {
|
|
28
29
|
const candidates = [];
|
|
29
|
-
if (input.goalState
|
|
30
|
+
if (input.goalState !== undefined && isGoalExecutionActive(input.goalState.status)) {
|
|
30
31
|
const requirementText = requirementSummary(input.goalState.requirements);
|
|
31
32
|
const goalSummary = shortText(input.goalState.userGoal, 96);
|
|
32
33
|
const suffix = requirementText.length > 0 ? `; ${requirementText}` : "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"current-work-memory.js","sourceRoot":"","sources":["../../../src/core/context/current-work-memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"current-work-memory.js","sourceRoot":"","sources":["../../../src/core/context/current-work-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,qBAAqB,EAAoB,MAAM,wBAAwB,CAAC;AASjG,SAAS,SAAS,CAAC,IAAY,EAAE,QAAgB;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACpD,IAAI,UAAU,CAAC,MAAM,IAAI,QAAQ;QAAE,OAAO,UAAU,CAAC;IACrD,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAC7D,CAAC;AAED,SAAS,kBAAkB,CAAC,YAAoC;IAC/D,MAAM,IAAI,GAAG,YAAY;SACvB,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,MAAM,CAAC;SACtD,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,YAAY;SAC1B,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,SAAS,CAAC;SACzD,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAClB,KAAK,CAAC,IAAI,CACT,SAAS,IAAI;aACX,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAA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C,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClF,UAAU,CAAC,IAAI,CAAC;YACf,EAAE,EAAE,QAAQ,KAAK,CAAC,cAAc,EAAE;YAClC,IAAI,EAAE,cAAc;YACpB,WAAW,EAAE,WAAW;YACxB,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC;YAC7C,KAAK,EAAE,GAAG;SACV,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,KAAK,CAAC,WAAW,KAAK,SAAS,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5E,UAAU,CAAC,IAAI,CAAC;YACf,EAAE,EAAE,cAAc;YAClB,IAAI,EAAE,cAAc;YACpB,WAAW,EAAE,YAAY;YACzB,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC;YAC1C,KAAK,EAAE,GAAG;SACV,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import { type GoalState, isGoalExecutionActive, type Requirement } from \"../goals/goal-state.ts\";\nimport type { MemoryTierCandidate } from \"./memory-tier-composer.ts\";\n\nexport interface CurrentWorkMemoryInput {\n\tgoalState?: GoalState;\n\tactivePlanPath?: string;\n\tlatestTopic?: string;\n}\n\nfunction shortText(text: string, maxChars: number): string {\n\tconst normalized = text.replace(/\\s+/g, \" \").trim();\n\tif (normalized.length <= maxChars) return normalized;\n\treturn `${normalized.slice(0, Math.max(0, maxChars - 1))}…`;\n}\n\nfunction requirementSummary(requirements: readonly Requirement[]): string {\n\tconst open = requirements\n\t\t.filter((requirement) => requirement.status === \"open\")\n\t\t.map((requirement) => requirement.text);\n\tconst blocked = requirements\n\t\t.filter((requirement) => requirement.status === \"blocked\")\n\t\t.map((requirement) => requirement.text);\n\tconst parts: string[] = [];\n\tif (open.length > 0)\n\t\tparts.push(\n\t\t\t`open: ${open\n\t\t\t\t.slice(0, 3)\n\t\t\t\t.map((text) => shortText(text, 64))\n\t\t\t\t.join(\"; \")}`,\n\t\t);\n\tif (blocked.length > 0)\n\t\tparts.push(\n\t\t\t`blocked: ${blocked\n\t\t\t\t.slice(0, 2)\n\t\t\t\t.map((text) => shortText(text, 64))\n\t\t\t\t.join(\"; \")}`,\n\t\t);\n\treturn parts.join(\" | \");\n}\n\nexport function collectCurrentWorkMemory(input: CurrentWorkMemoryInput): MemoryTierCandidate[] {\n\tconst candidates: MemoryTierCandidate[] = [];\n\tif (input.goalState !== undefined && isGoalExecutionActive(input.goalState.status)) {\n\t\tconst requirementText = requirementSummary(input.goalState.requirements);\n\t\tconst goalSummary = shortText(input.goalState.userGoal, 96);\n\t\tconst suffix = requirementText.length > 0 ? `; ${requirementText}` : \"\";\n\t\tcandidates.push({\n\t\t\tid: `goal:${input.goalState.goalId}`,\n\t\t\ttier: \"current_work\",\n\t\t\tsourceLabel: \"work:goal\",\n\t\t\tsummary: `${input.goalState.goalId} — ${goalSummary}${suffix}`,\n\t\t\tscore: 1,\n\t\t});\n\t}\n\n\tif (input.activePlanPath !== undefined && input.activePlanPath.trim().length > 0) {\n\t\tcandidates.push({\n\t\t\tid: `plan:${input.activePlanPath}`,\n\t\t\ttier: \"current_work\",\n\t\t\tsourceLabel: \"work:plan\",\n\t\t\tsummary: shortText(input.activePlanPath, 120),\n\t\t\tscore: 0.9,\n\t\t});\n\t}\n\n\tif (input.latestTopic !== undefined && input.latestTopic.trim().length > 0) {\n\t\tcandidates.push({\n\t\t\tid: \"topic:latest\",\n\t\t\ttier: \"current_work\",\n\t\t\tsourceLabel: \"work:topic\",\n\t\t\tsummary: shortText(input.latestTopic, 120),\n\t\t\tscore: 0.8,\n\t\t});\n\t}\n\n\treturn candidates;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type GoalState } from "../goals/goal-state.ts";
|
|
2
2
|
import type { MemoryPromptBudget } from "./memory-prompt-budget.ts";
|
|
3
3
|
export type LongTermMemoryTriggerReason = "explicit_recall" | "goal_continuation_missing_context" | "user_or_project_preference" | "durable_identifier" | "missing_background" | "short_or_grounded_turn" | "budget_disabled" | "secret_like_query";
|
|
4
4
|
export interface LongTermMemoryTriggerInput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"long-term-memory-trigger.d.ts","sourceRoot":"","sources":["../../../src/core/context/long-term-memory-trigger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"long-term-memory-trigger.d.ts","sourceRoot":"","sources":["../../../src/core/context/long-term-memory-trigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,wBAAwB,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAGpE,MAAM,MAAM,2BAA2B,GACpC,iBAAiB,GACjB,mCAAmC,GACnC,4BAA4B,GAC5B,oBAAoB,GACpB,oBAAoB,GACpB,wBAAwB,GACxB,iBAAiB,GACjB,mBAAmB,CAAC;AAEvB,MAAM,WAAW,0BAA0B;IAC1C,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,6BAA6B;IAC7C,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,EAAE,2BAA2B,CAAC;CACpC;AAkBD,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,0BAA0B,GAAG,6BAA6B,CAyB1G"}
|