@caupulican/pi-adaptative 0.94.1 → 0.95.0
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 +39 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/README.md +32 -13
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +7 -4
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +173 -293
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +247 -392
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.d.ts +52 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.d.ts.map +1 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.js +118 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.js.map +1 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.ts +169 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/templates/builder-validator.json +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/templates/provider-prompt-smoke.json +1 -1
- package/dist/bundled-resources/skills/pi-harness-learning/SKILL.md +13 -7
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +11 -11
- package/dist/core/agent-session.d.ts +11 -41
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +93 -160
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts +6 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.js +26 -25
- package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -1
- package/dist/core/autonomy/lane-private-paths.js +2 -1
- package/dist/core/autonomy/lane-private-paths.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +8 -8
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +45 -30
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/worker-session-private-scope.d.ts +12 -0
- package/dist/core/autonomy/worker-session-private-scope.d.ts.map +1 -0
- package/dist/core/autonomy/worker-session-private-scope.js +42 -0
- package/dist/core/autonomy/worker-session-private-scope.js.map +1 -0
- package/dist/core/autonomy/worker-tool-adapter-registry.d.ts +65 -0
- package/dist/core/autonomy/worker-tool-adapter-registry.d.ts.map +1 -0
- package/dist/core/autonomy/worker-tool-adapter-registry.js +145 -0
- package/dist/core/autonomy/worker-tool-adapter-registry.js.map +1 -0
- package/dist/core/background-lane-controller.d.ts +1 -1
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +1 -1
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/background-tool-task-controller.d.ts +8 -2
- package/dist/core/background-tool-task-controller.d.ts.map +1 -1
- package/dist/core/background-tool-task-controller.js +10 -2
- package/dist/core/background-tool-task-controller.js.map +1 -1
- package/dist/core/cost-guard-controller.d.ts +37 -0
- package/dist/core/cost-guard-controller.d.ts.map +1 -0
- package/dist/core/cost-guard-controller.js +71 -0
- package/dist/core/cost-guard-controller.js.map +1 -0
- package/dist/core/cost-guard.d.ts +9 -4
- package/dist/core/cost-guard.d.ts.map +1 -1
- package/dist/core/cost-guard.js +7 -3
- package/dist/core/cost-guard.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +0 -1
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts +16 -3
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.js +114 -55
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/delegation/worker-claim.d.ts +1 -2
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +19 -6
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +125 -40
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +3 -3
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js +13 -19
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts +3 -2
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +54 -39
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.d.ts +3 -3
- package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.js +7 -7
- package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
- package/dist/core/delegation/worker-machine-scope.d.ts +12 -0
- package/dist/core/delegation/worker-machine-scope.d.ts.map +1 -0
- package/dist/core/delegation/worker-machine-scope.js +38 -0
- package/dist/core/delegation/worker-machine-scope.js.map +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.js +6 -1
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +5 -7
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +1 -4
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +3 -2
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js +50 -25
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.d.ts +6 -0
- package/dist/core/durable-custom-message-turn-controller.d.ts.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.js +38 -15
- package/dist/core/durable-custom-message-turn-controller.js.map +1 -1
- package/dist/core/extension-binding-controller.d.ts +5 -1
- package/dist/core/extension-binding-controller.d.ts.map +1 -1
- package/dist/core/extension-binding-controller.js +15 -0
- package/dist/core/extension-binding-controller.js.map +1 -1
- package/dist/core/extensions/factory-runtime.d.ts.map +1 -1
- package/dist/core/extensions/factory-runtime.js +5 -0
- package/dist/core/extensions/factory-runtime.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +1 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +8 -4
- 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 +14 -0
- package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +188 -72
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +2 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +8 -0
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +5 -4
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +23 -19
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/learning/auto-learn-settings.d.ts +84 -0
- package/dist/core/learning/auto-learn-settings.d.ts.map +1 -0
- package/dist/core/learning/auto-learn-settings.js +66 -0
- package/dist/core/learning/auto-learn-settings.js.map +1 -0
- package/dist/core/learning/reflection-engine.d.ts +4 -0
- package/dist/core/learning/reflection-engine.d.ts.map +1 -1
- package/dist/core/learning/reflection-engine.js +48 -10
- package/dist/core/learning/reflection-engine.js.map +1 -1
- package/dist/core/local-prefix-warm-controller.d.ts +24 -0
- package/dist/core/local-prefix-warm-controller.d.ts.map +1 -0
- package/dist/core/local-prefix-warm-controller.js +79 -0
- package/dist/core/local-prefix-warm-controller.js.map +1 -0
- package/dist/core/memory/providers/file-store.d.ts +2 -0
- package/dist/core/memory/providers/file-store.d.ts.map +1 -1
- package/dist/core/memory/providers/file-store.js +71 -15
- package/dist/core/memory/providers/file-store.js.map +1 -1
- package/dist/core/memory/worker-memory-tools.d.ts +5 -0
- package/dist/core/memory/worker-memory-tools.d.ts.map +1 -0
- package/dist/core/memory/worker-memory-tools.js +5 -0
- package/dist/core/memory/worker-memory-tools.js.map +1 -0
- package/dist/core/model-capability.d.ts +7 -0
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +12 -0
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +2 -10
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +3 -2
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +3 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +16 -12
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +2 -2
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +2 -2
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +6 -1
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +14 -0
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/task-profile-writer.d.ts +7 -4
- package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -1
- package/dist/core/orchestration/task-profile-writer.js +71 -59
- package/dist/core/orchestration/task-profile-writer.js.map +1 -1
- package/dist/core/orchestration/thinking-level-schema.d.ts +7 -0
- package/dist/core/orchestration/thinking-level-schema.d.ts.map +1 -0
- package/dist/core/orchestration/thinking-level-schema.js +19 -0
- package/dist/core/orchestration/thinking-level-schema.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +12 -5
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/provider-prompt-contracts.d.ts +1 -4
- package/dist/core/provider-prompt-contracts.d.ts.map +1 -1
- package/dist/core/provider-prompt-contracts.js +4 -10
- package/dist/core/provider-prompt-contracts.js.map +1 -1
- package/dist/core/provider-request-context-controller.d.ts +2 -0
- package/dist/core/provider-request-context-controller.d.ts.map +1 -1
- package/dist/core/provider-request-context-controller.js +10 -3
- package/dist/core/provider-request-context-controller.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +56 -27
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +206 -117
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +1 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +25 -14
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +55 -10
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/session-role.d.ts +6 -8
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +8 -18
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/settings-manager.d.ts +13 -16
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +53 -50
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skill-vault.d.ts +15 -0
- package/dist/core/skill-vault.d.ts.map +1 -1
- package/dist/core/skill-vault.js +79 -45
- package/dist/core/skill-vault.js.map +1 -1
- package/dist/core/skills.d.ts +3 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +6 -6
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt-builder.d.ts +2 -0
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +52 -12
- package/dist/core/system-prompt-builder.js.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +3 -0
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +13 -2
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/toolkit/script-runner.d.ts +2 -1
- package/dist/core/toolkit/script-runner.d.ts.map +1 -1
- package/dist/core/toolkit/script-runner.js +10 -2
- package/dist/core/toolkit/script-runner.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +1 -1
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +1 -1
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +4 -15
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +111 -73
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/goal.d.ts +3 -4
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +24 -7
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +2 -8
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +6 -18
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/run-toolkit-script.d.ts +1 -1
- package/dist/core/tools/run-toolkit-script.d.ts.map +1 -1
- package/dist/core/tools/run-toolkit-script.js +2 -2
- package/dist/core/tools/run-toolkit-script.js.map +1 -1
- package/dist/core/tools/skill-audit.d.ts +28 -1
- package/dist/core/tools/skill-audit.d.ts.map +1 -1
- package/dist/core/tools/skill-audit.js +56 -12
- package/dist/core/tools/skill-audit.js.map +1 -1
- package/dist/core/tools/skill.d.ts +12 -1
- package/dist/core/tools/skill.d.ts.map +1 -1
- package/dist/core/tools/skill.js +52 -0
- package/dist/core/tools/skill.js.map +1 -1
- package/dist/core/tools/skillify.d.ts.map +1 -1
- package/dist/core/tools/skillify.js +16 -7
- package/dist/core/tools/skillify.js.map +1 -1
- package/dist/core/tools/task-steps.js +1 -1
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +4 -16
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +5 -20
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/worktree-sync/codes.d.ts +1 -2
- package/dist/core/worktree-sync/codes.d.ts.map +1 -1
- package/dist/core/worktree-sync/codes.js +1 -2
- package/dist/core/worktree-sync/codes.js.map +1 -1
- package/dist/core/worktree-sync/lane-gate.d.ts +4 -8
- package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -1
- package/dist/core/worktree-sync/lane-gate.js +5 -51
- package/dist/core/worktree-sync/lane-gate.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.d.ts +6 -7
- package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.js +30 -207
- package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
- package/dist/modes/interactive/autonomy-commands.js +2 -2
- package/dist/modes/interactive/autonomy-commands.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +17 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.js +2 -2
- package/dist/modes/interactive/components/fitness-role-selector.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/settings-selector.d.ts +4 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +150 -73
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +8 -4
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
- package/dist/modes/interactive/settings-selector-flow.js +10 -0
- package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
- package/docs/extensions.md +8 -0
- package/docs/harness-architecture.md +28 -32
- package/docs/index.md +1 -1
- package/docs/process-matrix.md +8 -6
- package/docs/resources.md +1 -1
- package/docs/settings.md +61 -51
- package/docs/tmux-agent-manager.md +47 -40
- package/docs/usage.md +1 -1
- package/docs/worker-profiles.md +8 -6
- package/docs/worktree-sync.md +26 -20
- 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 +4 -4
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +0 -133
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +0 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +0 -199
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +0 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +0 -312
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
3
|
import { resolveModelThinkingLevel } from "@caupulican/pi-ai/models";
|
|
3
4
|
import { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from "../default-tool-surface.js";
|
|
5
|
+
import { ROOT_MEMORY_TOOL_NAME, WORKER_MEMORY_READ_TOOL_NAME, WORKER_ROOT_MEMORY_TOOL_NAMES, } from "../memory/worker-memory-tools.js";
|
|
4
6
|
import { ORCHESTRATION_SCHEMA_VERSION, } from "../orchestration/contracts.js";
|
|
5
7
|
import { CLASSIFIED_LANE_TOOL_NAMES } from "../orchestration/lane-tool-manifests.js";
|
|
6
8
|
import { resolvePinnedOrchestrationModel } from "../orchestration/model-binding.js";
|
|
7
9
|
import { envelopeHasToolCapability, getToolCapabilityPolicy } from "../tool-capability-policy.js";
|
|
8
|
-
import {
|
|
10
|
+
import { LEAF_WORKER_DELEGATION_LIMITS } from "./worker-fleet-limits.js";
|
|
11
|
+
import { resolveWorkerWorkspacePath } from "./worker-machine-scope.js";
|
|
9
12
|
/**
|
|
10
13
|
* Smallest token grant a worker can survive on. A worker's first response pays the full
|
|
11
14
|
* uncached system prompt (~3.3k budgeted tokens in the field), so grants below this floor
|
|
@@ -22,11 +25,13 @@ const DEFAULT_TOOL_NAMES = [
|
|
|
22
25
|
"ls",
|
|
23
26
|
"write",
|
|
24
27
|
"edit",
|
|
25
|
-
"
|
|
28
|
+
"python",
|
|
26
29
|
STABLE_SHELL_TOOL_NAME,
|
|
27
|
-
"
|
|
30
|
+
"artifact_retrieve",
|
|
31
|
+
"skill",
|
|
32
|
+
"skill_audit",
|
|
28
33
|
];
|
|
29
|
-
const AVAILABLE_TOOL_NAMES = new Set(
|
|
34
|
+
const AVAILABLE_TOOL_NAMES = new Set(CLASSIFIED_LANE_TOOL_NAMES);
|
|
30
35
|
const DEFAULT_CAPABILITIES = [
|
|
31
36
|
"filesystem.read",
|
|
32
37
|
"filesystem.write",
|
|
@@ -35,9 +40,43 @@ const DEFAULT_CAPABILITIES = [
|
|
|
35
40
|
"process.exec",
|
|
36
41
|
"network.http",
|
|
37
42
|
"service.mcp",
|
|
38
|
-
"
|
|
43
|
+
"skill.read",
|
|
39
44
|
];
|
|
40
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Bind a compiled implementation profile to the compiled verifier identity it will persist.
|
|
47
|
+
* Verifier admission can legitimately derive a new immutable profile id (for example when the
|
|
48
|
+
* host forces a legacy delegation-capable preset to the leaf contract), so retaining the
|
|
49
|
+
* configured source id would make the execution contract internally inconsistent. Rebinding changes compiled
|
|
50
|
+
* content and therefore derives a fresh implementation identity as well.
|
|
51
|
+
*/
|
|
52
|
+
export function bindCompiledVerifierIdentity(shipment, verifierProfileId) {
|
|
53
|
+
if (shipment.profile.verificationProfileId === verifierProfileId)
|
|
54
|
+
return shipment;
|
|
55
|
+
const profile = {
|
|
56
|
+
...shipment.profile,
|
|
57
|
+
verificationProfileId: verifierProfileId,
|
|
58
|
+
profileId: adaptiveProfileId({
|
|
59
|
+
baseProfileId: shipment.profile.profileId,
|
|
60
|
+
verificationProfileId: verifierProfileId,
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
return { ...shipment, profile };
|
|
64
|
+
}
|
|
65
|
+
/** Bind the immutable profile snapshot to the exact native tools its host plan materialized. */
|
|
66
|
+
export function bindCompiledToolSurface(shipment, toolNames) {
|
|
67
|
+
if (isDeepStrictEqual(shipment.profile.toolNames, toolNames))
|
|
68
|
+
return shipment;
|
|
69
|
+
const profile = {
|
|
70
|
+
...shipment.profile,
|
|
71
|
+
toolNames: [...toolNames],
|
|
72
|
+
profileId: adaptiveProfileId({
|
|
73
|
+
baseProfileId: shipment.profile.profileId,
|
|
74
|
+
toolNames,
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
return { ...shipment, profile };
|
|
78
|
+
}
|
|
79
|
+
function selectModelBinding(modelPin, authority, base, foregroundModel, foregroundThinkingLevel, modelRegistry) {
|
|
41
80
|
if (modelPin)
|
|
42
81
|
return { ...modelPin };
|
|
43
82
|
const provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;
|
|
@@ -50,7 +89,7 @@ function selectModelBinding(modelPin, authority, base, foregroundModel, modelReg
|
|
|
50
89
|
(sameAsBase
|
|
51
90
|
? base.modelBinding.thinkingLevel
|
|
52
91
|
: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id
|
|
53
|
-
? resolveModelThinkingLevel(foregroundModel, undefined)
|
|
92
|
+
? (foregroundThinkingLevel ?? resolveModelThinkingLevel(foregroundModel, undefined))
|
|
54
93
|
: selectedModel
|
|
55
94
|
? resolveModelThinkingLevel(selectedModel, undefined)
|
|
56
95
|
: "off");
|
|
@@ -66,51 +105,62 @@ function tokenBudgetFloorFailure(maxTokens) {
|
|
|
66
105
|
}
|
|
67
106
|
/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */
|
|
68
107
|
export function resolveWorkerAuthority(input) {
|
|
69
|
-
|
|
70
|
-
const floorFailure = tokenBudgetFloorFailure(input.base.profile.budget.maxTokens);
|
|
71
|
-
if (floorFailure)
|
|
72
|
-
return { ok: false, reason: floorFailure };
|
|
73
|
-
if (!input.modelPin)
|
|
74
|
-
return { ok: true, shipment: input.base };
|
|
75
|
-
const resolvedModel = resolvePinnedOrchestrationModel(input.modelPin, input.modelRegistry, input.isModelExhausted);
|
|
76
|
-
if (!resolvedModel)
|
|
77
|
-
return { ok: false, reason: "orchestration_model_unavailable" };
|
|
78
|
-
return {
|
|
79
|
-
ok: true,
|
|
80
|
-
shipment: {
|
|
81
|
-
...input.base,
|
|
82
|
-
model: resolvedModel.model,
|
|
83
|
-
modelBinding: resolvedModel.binding,
|
|
84
|
-
profile: {
|
|
85
|
-
...input.base.profile,
|
|
86
|
-
modelPolicy: { mode: "fixed", candidates: [resolvedModel.binding] },
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
const binding = selectModelBinding(input.modelPin, input.authority, input.base, input.foregroundModel, input.modelRegistry);
|
|
108
|
+
const binding = selectModelBinding(input.modelPin, input.authority, input.base, input.foregroundModel, input.foregroundThinkingLevel, input.modelRegistry);
|
|
92
109
|
if (!binding)
|
|
93
110
|
return { ok: false, reason: "orchestration_model_required" };
|
|
94
111
|
const resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);
|
|
95
112
|
if (!resolvedModel)
|
|
96
113
|
return { ok: false, reason: "orchestration_model_unavailable" };
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
if (input.modelPin &&
|
|
115
|
+
((input.authority?.model !== undefined &&
|
|
116
|
+
(input.authority.model.provider !== input.modelPin.provider ||
|
|
117
|
+
input.authority.model.modelId !== input.modelPin.modelId)) ||
|
|
118
|
+
(input.authority?.thinkingLevel !== undefined &&
|
|
119
|
+
input.authority.thinkingLevel !== input.modelPin.thinkingLevel))) {
|
|
120
|
+
return {
|
|
121
|
+
ok: false,
|
|
122
|
+
reason: `worker_model_pin_conflict:${input.authority?.role ?? input.base?.profile.role ?? "implementer"}`,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const inheritedForegroundToolNames = mapToolNamesForPlatform(input.foregroundToolNames ?? input.foregroundEnvelope?.allowedTools ?? DEFAULT_TOOL_NAMES).filter((toolName) => AVAILABLE_TOOL_NAMES.has(toolName) && !WORKER_ROOT_MEMORY_TOOL_NAMES.has(toolName));
|
|
126
|
+
const requestedForbiddenTool = input.authority?.toolNames?.find((toolName) => WORKER_ROOT_MEMORY_TOOL_NAMES.has(toolName));
|
|
127
|
+
if (requestedForbiddenTool) {
|
|
128
|
+
return { ok: false, reason: `orchestration_tool_unavailable:${requestedForbiddenTool}` };
|
|
129
|
+
}
|
|
130
|
+
const baseForbiddenTool = input.base?.profile.toolNames.find((toolName) => WORKER_ROOT_MEMORY_TOOL_NAMES.has(toolName));
|
|
131
|
+
if (baseForbiddenTool) {
|
|
132
|
+
return { ok: false, reason: `orchestration_tool_unavailable:${baseForbiddenTool}` };
|
|
133
|
+
}
|
|
134
|
+
const configuredToolNames = mapToolNamesForPlatform(input.authority?.toolNames ?? input.base?.profile.toolNames ?? inheritedForegroundToolNames).filter((toolName) => !WORKER_ROOT_MEMORY_TOOL_NAMES.has(toolName));
|
|
135
|
+
const deniedForegroundTools = new Set(input.base ? [] : (input.foregroundEnvelope?.deniedTools ?? []));
|
|
136
|
+
const uniqueToolNames = [
|
|
137
|
+
...new Set(configuredToolNames.filter((toolName) => toolName !== "delegate" && !deniedForegroundTools.has(toolName))),
|
|
138
|
+
];
|
|
139
|
+
if (input.authority?.toolNames?.includes("delegate")) {
|
|
140
|
+
return { ok: false, reason: "orchestration_tool_unavailable:delegate" };
|
|
141
|
+
}
|
|
106
142
|
const unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));
|
|
107
143
|
if (unavailableTools.length > 0) {
|
|
108
144
|
return { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(",")}` };
|
|
109
145
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
146
|
+
if (input.authority?.toolNames !== undefined) {
|
|
147
|
+
const inheritedSurface = new Set(input.base ? mapToolNamesForPlatform(input.base.profile.toolNames) : inheritedForegroundToolNames);
|
|
148
|
+
const foregroundTools = input.foregroundToolNames ?? input.foregroundEnvelope?.allowedTools ?? DEFAULT_TOOL_NAMES;
|
|
149
|
+
const boundedMemoryReadInherited = uniqueToolNames.includes(WORKER_MEMORY_READ_TOOL_NAME) &&
|
|
150
|
+
foregroundTools.includes(ROOT_MEMORY_TOOL_NAME) &&
|
|
151
|
+
input.foregroundEnvelope?.capabilities.includes("memory.query") === true;
|
|
152
|
+
const uninheritedTools = uniqueToolNames.filter((toolName) => !inheritedSurface.has(toolName) &&
|
|
153
|
+
!(toolName === WORKER_MEMORY_READ_TOOL_NAME && boundedMemoryReadInherited));
|
|
154
|
+
if (uninheritedTools.length > 0) {
|
|
155
|
+
return { ok: false, reason: `orchestration_tool_unavailable:${uninheritedTools.join(",")}` };
|
|
156
|
+
}
|
|
113
157
|
}
|
|
158
|
+
const capabilities = new Set(input.authority?.capabilities ??
|
|
159
|
+
input.base?.profile.capabilityCeiling ??
|
|
160
|
+
input.foregroundEnvelope?.capabilities ??
|
|
161
|
+
DEFAULT_CAPABILITIES);
|
|
162
|
+
capabilities.delete("workflow.delegate");
|
|
163
|
+
capabilities.delete("memory.mutate");
|
|
114
164
|
const capabilityList = [...capabilities];
|
|
115
165
|
const toolNames = [];
|
|
116
166
|
for (const toolName of uniqueToolNames) {
|
|
@@ -129,44 +179,55 @@ export function resolveWorkerAuthority(input) {
|
|
|
129
179
|
const floorFailure = tokenBudgetFloorFailure(budget.maxTokens);
|
|
130
180
|
if (floorFailure)
|
|
131
181
|
return { ok: false, reason: floorFailure };
|
|
132
|
-
const role = input.authority?.role ?? input.base?.profile.role ?? "
|
|
133
|
-
const delegationLimits =
|
|
134
|
-
|
|
135
|
-
|
|
182
|
+
const role = input.authority?.role ?? input.base?.profile.role ?? "implementer";
|
|
183
|
+
const delegationLimits = structuredClone(LEAF_WORKER_DELEGATION_LIMITS);
|
|
184
|
+
const requestedWorkspacePath = input.authority?.path ?? input.base?.profile.workspacePath;
|
|
185
|
+
const workspacePath = requestedWorkspacePath
|
|
186
|
+
? resolveWorkerWorkspacePath(input.cwd ?? process.cwd(), requestedWorkspacePath)
|
|
187
|
+
: undefined;
|
|
136
188
|
const now = new Date().toISOString();
|
|
137
189
|
const descriptor = {
|
|
190
|
+
baseProfileId: input.base?.profile.profileId ?? null,
|
|
138
191
|
role,
|
|
139
192
|
binding: resolvedModel.binding,
|
|
140
193
|
capabilities: [...capabilities],
|
|
141
194
|
toolNames,
|
|
142
195
|
budget,
|
|
143
196
|
delegationLimits: delegationLimits ?? null,
|
|
197
|
+
workspacePath: workspacePath ?? null,
|
|
144
198
|
resourceProfileNames: input.base?.profile.resourceProfileNames ?? [],
|
|
199
|
+
dispatchProfileIds: input.base?.profile.dispatchProfileIds ?? [],
|
|
200
|
+
executionPolicy: input.base?.profile.executionPolicy ?? null,
|
|
201
|
+
requireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,
|
|
202
|
+
verificationProfileId: input.base?.profile.verificationProfileId ?? null,
|
|
145
203
|
};
|
|
146
204
|
const maxWallClockMs = budget.maxWallClockMs ?? 0;
|
|
147
205
|
const wallClockLeaseTtlMs = maxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;
|
|
148
206
|
const profile = {
|
|
149
207
|
schemaVersion: ORCHESTRATION_SCHEMA_VERSION,
|
|
150
|
-
profileId:
|
|
151
|
-
description: "Admission-time adaptive agent authority",
|
|
208
|
+
profileId: input.base?.profile.profileId ?? "",
|
|
209
|
+
description: input.base?.profile.description ?? "Admission-time adaptive agent authority",
|
|
152
210
|
role,
|
|
153
211
|
modelPolicy: { mode: "fixed", candidates: [resolvedModel.binding] },
|
|
154
212
|
capabilityCeiling: [...capabilities],
|
|
155
213
|
toolNames,
|
|
214
|
+
...(workspacePath ? { workspacePath } : {}),
|
|
156
215
|
resourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],
|
|
157
|
-
dispatchProfileIds: [],
|
|
216
|
+
dispatchProfileIds: [...(input.base?.profile.dispatchProfileIds ?? [])],
|
|
158
217
|
...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),
|
|
159
|
-
|
|
218
|
+
delegationLimits,
|
|
160
219
|
budget,
|
|
161
|
-
maxConcurrent: Number.MAX_SAFE_INTEGER,
|
|
220
|
+
maxConcurrent: input.base?.profile.maxConcurrent ?? Number.MAX_SAFE_INTEGER,
|
|
162
221
|
leaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),
|
|
163
222
|
requireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,
|
|
164
223
|
...(input.base?.profile.verificationProfileId
|
|
165
224
|
? { verificationProfileId: input.base.profile.verificationProfileId }
|
|
166
225
|
: {}),
|
|
167
|
-
createdAt: now,
|
|
168
|
-
updatedAt: now,
|
|
226
|
+
createdAt: input.base?.profile.createdAt ?? now,
|
|
227
|
+
updatedAt: input.base?.profile.updatedAt ?? now,
|
|
169
228
|
};
|
|
229
|
+
const unchangedBase = input.base && isDeepStrictEqual(profile, input.base.profile);
|
|
230
|
+
profile.profileId = unchangedBase ? profile.profileId : adaptiveProfileId(descriptor);
|
|
170
231
|
return {
|
|
171
232
|
ok: true,
|
|
172
233
|
shipment: {
|
|
@@ -176,8 +237,6 @@ export function resolveWorkerAuthority(input) {
|
|
|
176
237
|
resourcePointers: structuredClone(input.base?.resourcePointers ?? []),
|
|
177
238
|
...(input.base?.soul ? { soul: input.base.soul } : {}),
|
|
178
239
|
},
|
|
179
|
-
...(input.authority?.readPaths ? { requestedReadPaths: [...input.authority.readPaths] } : {}),
|
|
180
|
-
...(input.authority?.writePaths ? { requestedWritePaths: [...input.authority.writePaths] } : {}),
|
|
181
240
|
};
|
|
182
241
|
}
|
|
183
242
|
//# sourceMappingURL=worker-authority-resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-authority-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B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,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChG,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport { resolveModelThinkingLevel } from \"@caupulican/pi-ai/models\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport {\n\ttype HarnessCapability,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationModelBinding,\n\ttype OrchestrationProfile,\n} from \"../orchestration/contracts.ts\";\nimport { CLASSIFIED_LANE_TOOL_NAMES } from \"../orchestration/lane-tool-manifests.ts\";\nimport { resolvePinnedOrchestrationModel } from \"../orchestration/model-binding.ts\";\nimport { envelopeHasToolCapability, getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\nimport type { WorkerDelegationAuthorityRequest } from \"./worker-delegation-request.ts\";\nimport { LEAN_WORKER_DELEGATION_LIMITS } from \"./worker-fleet-limits.ts\";\nimport type { ResolvedWorkerProfile } from \"./worker-profile-resolver.ts\";\n\n/**\n * Smallest token grant a worker can survive on. A worker's first response pays the full\n * uncached system prompt (~3.3k budgeted tokens in the field), so grants below this floor\n * starve mid-flight with every tool call denied `token_budget_exhausted` — reject them at\n * admission with an explicit reason instead (field session 019fd4dc: 8-9k grants died in\n * 2-3 responses under face-value cache-read counting; the floor plus discounted counting\n * makes small grants viable again).\n */\nexport const MIN_VIABLE_WORKER_TOKEN_BUDGET = 5_000;\n\nconst DEFAULT_TOOL_NAMES = [\n\t\"read\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"write\",\n\t\"edit\",\n\t\"memory\",\n\tSTABLE_SHELL_TOOL_NAME,\n\t\"delegate\",\n] as const;\nconst AVAILABLE_TOOL_NAMES: ReadonlySet<string> = new Set([...CLASSIFIED_LANE_TOOL_NAMES, \"delegate\"]);\nconst DEFAULT_CAPABILITIES: readonly HarnessCapability[] = [\n\t\"filesystem.read\",\n\t\"filesystem.write\",\n\t\"worktree.read\",\n\t\"worktree.mutate\",\n\t\"process.exec\",\n\t\"network.http\",\n\t\"service.mcp\",\n\t\"memory.query\",\n];\n\nexport interface WorkerAuthorityResolutionInput {\n\tauthority?: WorkerDelegationAuthorityRequest;\n\tbase?: ResolvedWorkerProfile;\n\tmodelPin?: OrchestrationModelBinding;\n\tforegroundModel?: Model<Api>;\n\tmodelRegistry: ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n}\n\nexport type WorkerAuthorityResolution =\n\t| {\n\t\t\tok: true;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t\t\trequestedReadPaths?: readonly string[];\n\t\t\trequestedWritePaths?: readonly string[];\n\t }\n\t| { ok: false; reason: string };\n\nfunction selectModelBinding(\n\tmodelPin: OrchestrationModelBinding | undefined,\n\tauthority: WorkerDelegationAuthorityRequest | undefined,\n\tbase: ResolvedWorkerProfile | undefined,\n\tforegroundModel: Model<Api> | undefined,\n\tmodelRegistry: ModelRegistry,\n): OrchestrationModelBinding | undefined {\n\tif (modelPin) return { ...modelPin };\n\tconst provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;\n\tconst modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;\n\tif (!provider || !modelId) return undefined;\n\tconst sameAsBase = provider === base?.modelBinding.provider && modelId === base.modelBinding.modelId;\n\tconst selectedModel = modelRegistry.find(provider, modelId);\n\tconst thinkingLevel =\n\t\tauthority?.thinkingLevel ??\n\t\t(sameAsBase\n\t\t\t? base.modelBinding.thinkingLevel\n\t\t\t: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id\n\t\t\t\t? resolveModelThinkingLevel(foregroundModel, undefined)\n\t\t\t\t: selectedModel\n\t\t\t\t\t? resolveModelThinkingLevel(selectedModel, undefined)\n\t\t\t\t\t: \"off\");\n\treturn { provider, modelId, thinkingLevel };\n}\n\nfunction adaptiveProfileId(value: object): string {\n\treturn `adaptive-${createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\").slice(0, 32)}`;\n}\n\nfunction tokenBudgetFloorFailure(maxTokens: number | undefined): string | undefined {\n\treturn maxTokens !== undefined && maxTokens < MIN_VIABLE_WORKER_TOKEN_BUDGET\n\t\t? `token_budget_below_floor:requested=${maxTokens},min=${MIN_VIABLE_WORKER_TOKEN_BUDGET}`\n\t\t: undefined;\n}\n\n/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */\nexport function resolveWorkerAuthority(input: WorkerAuthorityResolutionInput): WorkerAuthorityResolution {\n\tif (!input.authority && input.base) {\n\t\tconst floorFailure = tokenBudgetFloorFailure(input.base.profile.budget.maxTokens);\n\t\tif (floorFailure) return { ok: false, reason: floorFailure };\n\t\tif (!input.modelPin) return { ok: true, shipment: input.base };\n\t\tconst resolvedModel = resolvePinnedOrchestrationModel(\n\t\t\tinput.modelPin,\n\t\t\tinput.modelRegistry,\n\t\t\tinput.isModelExhausted,\n\t\t);\n\t\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\t\treturn {\n\t\t\tok: true,\n\t\t\tshipment: {\n\t\t\t\t...input.base,\n\t\t\t\tmodel: resolvedModel.model,\n\t\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\t\tprofile: {\n\t\t\t\t\t...input.base.profile,\n\t\t\t\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}\n\tconst binding = selectModelBinding(\n\t\tinput.modelPin,\n\t\tinput.authority,\n\t\tinput.base,\n\t\tinput.foregroundModel,\n\t\tinput.modelRegistry,\n\t);\n\tif (!binding) return { ok: false, reason: \"orchestration_model_required\" };\n\tconst resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);\n\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\n\tconst configuredToolNames = mapToolNamesForPlatform(\n\t\tinput.authority?.toolNames ?? input.base?.profile.toolNames ?? DEFAULT_TOOL_NAMES,\n\t);\n\tconst inheritsDelegation =\n\t\tinput.authority?.capabilities === undefined &&\n\t\t(input.base === undefined ||\n\t\t\t(input.base.profile.toolNames.includes(\"delegate\") &&\n\t\t\t\tinput.base.profile.capabilityCeiling.includes(\"workflow.delegate\")));\n\tconst requestedToolNames =\n\t\tinheritsDelegation && !configuredToolNames.includes(\"delegate\")\n\t\t\t? [...configuredToolNames, \"delegate\"]\n\t\t\t: configuredToolNames;\n\tconst uniqueToolNames = [...new Set(requestedToolNames)];\n\tconst unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));\n\tif (unavailableTools.length > 0) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(\",\")}` };\n\t}\n\tconst capabilities = new Set<HarnessCapability>(\n\t\tinput.authority?.capabilities ?? input.base?.profile.capabilityCeiling ?? DEFAULT_CAPABILITIES,\n\t);\n\tif (uniqueToolNames.includes(\"delegate\") && inheritsDelegation) {\n\t\tcapabilities.add(\"workflow.delegate\");\n\t}\n\tconst capabilityList = [...capabilities];\n\tconst toolNames: string[] = [];\n\tfor (const toolName of uniqueToolNames) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tif (!policy) return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };\n\t\tif (envelopeHasToolCapability(capabilityList, toolName)) {\n\t\t\ttoolNames.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tif (input.authority?.toolNames !== undefined) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_capability_missing:${toolName}` };\n\t\t}\n\t}\n\tconst budget = structuredClone(input.authority?.budget ?? input.base?.profile.budget ?? {});\n\tconst floorFailure = tokenBudgetFloorFailure(budget.maxTokens);\n\tif (floorFailure) return { ok: false, reason: floorFailure };\n\tconst role = input.authority?.role ?? input.base?.profile.role ?? \"orchestrator\";\n\tconst delegationLimits = input.base\n\t\t? input.base.profile.delegationLimits\n\t\t: structuredClone(LEAN_WORKER_DELEGATION_LIMITS);\n\tconst now = new Date().toISOString();\n\tconst descriptor = {\n\t\trole,\n\t\tbinding: resolvedModel.binding,\n\t\tcapabilities: [...capabilities],\n\t\ttoolNames,\n\t\tbudget,\n\t\tdelegationLimits: delegationLimits ?? null,\n\t\tresourceProfileNames: input.base?.profile.resourceProfileNames ?? [],\n\t};\n\tconst maxWallClockMs = budget.maxWallClockMs ?? 0;\n\tconst wallClockLeaseTtlMs =\n\t\tmaxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;\n\tconst profile: OrchestrationProfile = {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: adaptiveProfileId(descriptor),\n\t\tdescription: \"Admission-time adaptive agent authority\",\n\t\trole,\n\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\tcapabilityCeiling: [...capabilities],\n\t\ttoolNames,\n\t\tresourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],\n\t\tdispatchProfileIds: [],\n\t\t...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),\n\t\t...(delegationLimits ? { delegationLimits: structuredClone(delegationLimits) } : {}),\n\t\tbudget,\n\t\tmaxConcurrent: Number.MAX_SAFE_INTEGER,\n\t\tleaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\t...(input.base?.profile.verificationProfileId\n\t\t\t? { verificationProfileId: input.base.profile.verificationProfileId }\n\t\t\t: {}),\n\t\tcreatedAt: now,\n\t\tupdatedAt: now,\n\t};\n\treturn {\n\t\tok: true,\n\t\tshipment: {\n\t\t\tmodel: resolvedModel.model,\n\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\tprofile,\n\t\t\tresourcePointers: structuredClone(input.base?.resourcePointers ?? []),\n\t\t\t...(input.base?.soul ? { soul: input.base.soul } : {}),\n\t\t},\n\t\t...(input.authority?.readPaths ? { requestedReadPaths: [...input.authority.readPaths] } : {}),\n\t\t...(input.authority?.writePaths ? { requestedWritePaths: [...input.authority.writePaths] } : {}),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-authority-resolver.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-authority-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,EACN,qBAAqB,EACrB,4BAA4B,EAC5B,6BAA6B,GAC7B,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAEN,4BAA4B,GAI5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAElG,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AAGvE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAEpD,MAAM,kBAAkB,GAAG;IAC1B,MAAM;IACN,MAAM;IACN,MAAM;IACN,IAAI;IACJ,OAAO;IACP,MAAM;IACN,QAAQ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,IAAI,CAAC,OAAO,CAAC,CAAC;IACnF,OAAO,CAAC,SAAS,GAAG,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACtF,OAAO;QACN,EAAE,EAAE,IAAI;QACR,QAAQ,EAAE;YACT,KAAK,EAAE,aAAa,CAAC,KAAK;YAC1B,YAAY,EAAE,aAAa,CAAC,OAAO;YACnC,OAAO;YACP,gBAAgB,EAAE,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,gBAAgB,IAAI,EAAE,CAAC;YACrE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACtD;KACD,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport { resolveModelThinkingLevel } from \"@caupulican/pi-ai/models\";\nimport type { CapabilityEnvelope } from \"../autonomy/contracts.ts\";\nimport { mapToolNamesForPlatform, STABLE_SHELL_TOOL_NAME } from \"../default-tool-surface.ts\";\nimport {\n\tROOT_MEMORY_TOOL_NAME,\n\tWORKER_MEMORY_READ_TOOL_NAME,\n\tWORKER_ROOT_MEMORY_TOOL_NAMES,\n} from \"../memory/worker-memory-tools.ts\";\nimport type { ModelRegistry } from \"../model-registry.ts\";\nimport {\n\ttype HarnessCapability,\n\tORCHESTRATION_SCHEMA_VERSION,\n\ttype OrchestrationModelBinding,\n\ttype OrchestrationProfile,\n\ttype OrchestrationThinkingLevel,\n} from \"../orchestration/contracts.ts\";\nimport { CLASSIFIED_LANE_TOOL_NAMES } from \"../orchestration/lane-tool-manifests.ts\";\nimport { resolvePinnedOrchestrationModel } from \"../orchestration/model-binding.ts\";\nimport { envelopeHasToolCapability, getToolCapabilityPolicy } from \"../tool-capability-policy.ts\";\nimport type { WorkerDelegationAuthorityRequest } from \"./worker-delegation-request.ts\";\nimport { LEAF_WORKER_DELEGATION_LIMITS } from \"./worker-fleet-limits.ts\";\nimport { resolveWorkerWorkspacePath } from \"./worker-machine-scope.ts\";\nimport type { ResolvedWorkerProfile } from \"./worker-profile-resolver.ts\";\n\n/**\n * Smallest token grant a worker can survive on. A worker's first response pays the full\n * uncached system prompt (~3.3k budgeted tokens in the field), so grants below this floor\n * starve mid-flight with every tool call denied `token_budget_exhausted` — reject them at\n * admission with an explicit reason instead (field session 019fd4dc: 8-9k grants died in\n * 2-3 responses under face-value cache-read counting; the floor plus discounted counting\n * makes small grants viable again).\n */\nexport const MIN_VIABLE_WORKER_TOKEN_BUDGET = 5_000;\n\nconst DEFAULT_TOOL_NAMES = [\n\t\"read\",\n\t\"grep\",\n\t\"find\",\n\t\"ls\",\n\t\"write\",\n\t\"edit\",\n\t\"python\",\n\tSTABLE_SHELL_TOOL_NAME,\n\t\"artifact_retrieve\",\n\t\"skill\",\n\t\"skill_audit\",\n] as const;\nconst AVAILABLE_TOOL_NAMES: ReadonlySet<string> = new Set(CLASSIFIED_LANE_TOOL_NAMES);\nconst DEFAULT_CAPABILITIES: readonly HarnessCapability[] = [\n\t\"filesystem.read\",\n\t\"filesystem.write\",\n\t\"worktree.read\",\n\t\"worktree.mutate\",\n\t\"process.exec\",\n\t\"network.http\",\n\t\"service.mcp\",\n\t\"skill.read\",\n];\nexport interface WorkerAuthorityResolutionInput {\n\tauthority?: WorkerDelegationAuthorityRequest;\n\tbase?: ResolvedWorkerProfile;\n\tmodelPin?: OrchestrationModelBinding;\n\tforegroundModel?: Model<Api>;\n\tforegroundThinkingLevel?: OrchestrationThinkingLevel;\n\tforegroundToolNames?: readonly string[];\n\tforegroundEnvelope?: CapabilityEnvelope;\n\tcwd?: string;\n\tmodelRegistry: ModelRegistry;\n\tisModelExhausted(model: Model<Api>): boolean;\n}\n\nexport type WorkerAuthorityResolution =\n\t| {\n\t\t\tok: true;\n\t\t\tshipment: ResolvedWorkerProfile;\n\t }\n\t| { ok: false; reason: string };\n\n/**\n * Bind a compiled implementation profile to the compiled verifier identity it will persist.\n * Verifier admission can legitimately derive a new immutable profile id (for example when the\n * host forces a legacy delegation-capable preset to the leaf contract), so retaining the\n * configured source id would make the execution contract internally inconsistent. Rebinding changes compiled\n * content and therefore derives a fresh implementation identity as well.\n */\nexport function bindCompiledVerifierIdentity(\n\tshipment: ResolvedWorkerProfile,\n\tverifierProfileId: string,\n): ResolvedWorkerProfile {\n\tif (shipment.profile.verificationProfileId === verifierProfileId) return shipment;\n\tconst profile: OrchestrationProfile = {\n\t\t...shipment.profile,\n\t\tverificationProfileId: verifierProfileId,\n\t\tprofileId: adaptiveProfileId({\n\t\t\tbaseProfileId: shipment.profile.profileId,\n\t\t\tverificationProfileId: verifierProfileId,\n\t\t}),\n\t};\n\treturn { ...shipment, profile };\n}\n\n/** Bind the immutable profile snapshot to the exact native tools its host plan materialized. */\nexport function bindCompiledToolSurface(\n\tshipment: ResolvedWorkerProfile,\n\ttoolNames: readonly string[],\n): ResolvedWorkerProfile {\n\tif (isDeepStrictEqual(shipment.profile.toolNames, toolNames)) return shipment;\n\tconst profile: OrchestrationProfile = {\n\t\t...shipment.profile,\n\t\ttoolNames: [...toolNames],\n\t\tprofileId: adaptiveProfileId({\n\t\t\tbaseProfileId: shipment.profile.profileId,\n\t\t\ttoolNames,\n\t\t}),\n\t};\n\treturn { ...shipment, profile };\n}\n\nfunction selectModelBinding(\n\tmodelPin: OrchestrationModelBinding | undefined,\n\tauthority: WorkerDelegationAuthorityRequest | undefined,\n\tbase: ResolvedWorkerProfile | undefined,\n\tforegroundModel: Model<Api> | undefined,\n\tforegroundThinkingLevel: OrchestrationThinkingLevel | undefined,\n\tmodelRegistry: ModelRegistry,\n): OrchestrationModelBinding | undefined {\n\tif (modelPin) return { ...modelPin };\n\tconst provider = authority?.model?.provider ?? base?.modelBinding.provider ?? foregroundModel?.provider;\n\tconst modelId = authority?.model?.modelId ?? base?.modelBinding.modelId ?? foregroundModel?.id;\n\tif (!provider || !modelId) return undefined;\n\tconst sameAsBase = provider === base?.modelBinding.provider && modelId === base.modelBinding.modelId;\n\tconst selectedModel = modelRegistry.find(provider, modelId);\n\tconst thinkingLevel =\n\t\tauthority?.thinkingLevel ??\n\t\t(sameAsBase\n\t\t\t? base.modelBinding.thinkingLevel\n\t\t\t: foregroundModel && provider === foregroundModel.provider && modelId === foregroundModel.id\n\t\t\t\t? (foregroundThinkingLevel ?? resolveModelThinkingLevel(foregroundModel, undefined))\n\t\t\t\t: selectedModel\n\t\t\t\t\t? resolveModelThinkingLevel(selectedModel, undefined)\n\t\t\t\t\t: \"off\");\n\treturn { provider, modelId, thinkingLevel };\n}\n\nfunction adaptiveProfileId(value: object): string {\n\treturn `adaptive-${createHash(\"sha256\").update(JSON.stringify(value)).digest(\"hex\").slice(0, 32)}`;\n}\n\nfunction tokenBudgetFloorFailure(maxTokens: number | undefined): string | undefined {\n\treturn maxTokens !== undefined && maxTokens < MIN_VIABLE_WORKER_TOKEN_BUDGET\n\t\t? `token_budget_below_floor:requested=${maxTokens},min=${MIN_VIABLE_WORKER_TOKEN_BUDGET}`\n\t\t: undefined;\n}\n\n/** Materialize free-form model choices as one immutable profile-shaped execution snapshot. */\nexport function resolveWorkerAuthority(input: WorkerAuthorityResolutionInput): WorkerAuthorityResolution {\n\tconst binding = selectModelBinding(\n\t\tinput.modelPin,\n\t\tinput.authority,\n\t\tinput.base,\n\t\tinput.foregroundModel,\n\t\tinput.foregroundThinkingLevel,\n\t\tinput.modelRegistry,\n\t);\n\tif (!binding) return { ok: false, reason: \"orchestration_model_required\" };\n\tconst resolvedModel = resolvePinnedOrchestrationModel(binding, input.modelRegistry, input.isModelExhausted);\n\tif (!resolvedModel) return { ok: false, reason: \"orchestration_model_unavailable\" };\n\tif (\n\t\tinput.modelPin &&\n\t\t((input.authority?.model !== undefined &&\n\t\t\t(input.authority.model.provider !== input.modelPin.provider ||\n\t\t\t\tinput.authority.model.modelId !== input.modelPin.modelId)) ||\n\t\t\t(input.authority?.thinkingLevel !== undefined &&\n\t\t\t\tinput.authority.thinkingLevel !== input.modelPin.thinkingLevel))\n\t) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\treason: `worker_model_pin_conflict:${input.authority?.role ?? input.base?.profile.role ?? \"implementer\"}`,\n\t\t};\n\t}\n\n\tconst inheritedForegroundToolNames = mapToolNamesForPlatform(\n\t\tinput.foregroundToolNames ?? input.foregroundEnvelope?.allowedTools ?? DEFAULT_TOOL_NAMES,\n\t).filter((toolName) => AVAILABLE_TOOL_NAMES.has(toolName) && !WORKER_ROOT_MEMORY_TOOL_NAMES.has(toolName));\n\tconst requestedForbiddenTool = input.authority?.toolNames?.find((toolName) =>\n\t\tWORKER_ROOT_MEMORY_TOOL_NAMES.has(toolName),\n\t);\n\tif (requestedForbiddenTool) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${requestedForbiddenTool}` };\n\t}\n\tconst baseForbiddenTool = input.base?.profile.toolNames.find((toolName) =>\n\t\tWORKER_ROOT_MEMORY_TOOL_NAMES.has(toolName),\n\t);\n\tif (baseForbiddenTool) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${baseForbiddenTool}` };\n\t}\n\tconst configuredToolNames = mapToolNamesForPlatform(\n\t\tinput.authority?.toolNames ?? input.base?.profile.toolNames ?? inheritedForegroundToolNames,\n\t).filter((toolName) => !WORKER_ROOT_MEMORY_TOOL_NAMES.has(toolName));\n\tconst deniedForegroundTools = new Set(input.base ? [] : (input.foregroundEnvelope?.deniedTools ?? []));\n\tconst uniqueToolNames = [\n\t\t...new Set(\n\t\t\tconfiguredToolNames.filter((toolName) => toolName !== \"delegate\" && !deniedForegroundTools.has(toolName)),\n\t\t),\n\t];\n\tif (input.authority?.toolNames?.includes(\"delegate\")) {\n\t\treturn { ok: false, reason: \"orchestration_tool_unavailable:delegate\" };\n\t}\n\tconst unavailableTools = uniqueToolNames.filter((toolName) => !AVAILABLE_TOOL_NAMES.has(toolName));\n\tif (unavailableTools.length > 0) {\n\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${unavailableTools.join(\",\")}` };\n\t}\n\tif (input.authority?.toolNames !== undefined) {\n\t\tconst inheritedSurface = new Set(\n\t\t\tinput.base ? mapToolNamesForPlatform(input.base.profile.toolNames) : inheritedForegroundToolNames,\n\t\t);\n\t\tconst foregroundTools = input.foregroundToolNames ?? input.foregroundEnvelope?.allowedTools ?? DEFAULT_TOOL_NAMES;\n\t\tconst boundedMemoryReadInherited =\n\t\t\tuniqueToolNames.includes(WORKER_MEMORY_READ_TOOL_NAME) &&\n\t\t\tforegroundTools.includes(ROOT_MEMORY_TOOL_NAME) &&\n\t\t\tinput.foregroundEnvelope?.capabilities.includes(\"memory.query\") === true;\n\t\tconst uninheritedTools = uniqueToolNames.filter(\n\t\t\t(toolName) =>\n\t\t\t\t!inheritedSurface.has(toolName) &&\n\t\t\t\t!(toolName === WORKER_MEMORY_READ_TOOL_NAME && boundedMemoryReadInherited),\n\t\t);\n\t\tif (uninheritedTools.length > 0) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_unavailable:${uninheritedTools.join(\",\")}` };\n\t\t}\n\t}\n\tconst capabilities = new Set<HarnessCapability>(\n\t\tinput.authority?.capabilities ??\n\t\t\tinput.base?.profile.capabilityCeiling ??\n\t\t\tinput.foregroundEnvelope?.capabilities ??\n\t\t\tDEFAULT_CAPABILITIES,\n\t);\n\tcapabilities.delete(\"workflow.delegate\");\n\tcapabilities.delete(\"memory.mutate\");\n\tconst capabilityList = [...capabilities];\n\tconst toolNames: string[] = [];\n\tfor (const toolName of uniqueToolNames) {\n\t\tconst policy = getToolCapabilityPolicy(toolName);\n\t\tif (!policy) return { ok: false, reason: `orchestration_tool_unclassified:${toolName}` };\n\t\tif (envelopeHasToolCapability(capabilityList, toolName)) {\n\t\t\ttoolNames.push(toolName);\n\t\t\tcontinue;\n\t\t}\n\t\tif (input.authority?.toolNames !== undefined) {\n\t\t\treturn { ok: false, reason: `orchestration_tool_capability_missing:${toolName}` };\n\t\t}\n\t}\n\tconst budget = structuredClone(input.authority?.budget ?? input.base?.profile.budget ?? {});\n\tconst floorFailure = tokenBudgetFloorFailure(budget.maxTokens);\n\tif (floorFailure) return { ok: false, reason: floorFailure };\n\tconst role = input.authority?.role ?? input.base?.profile.role ?? \"implementer\";\n\tconst delegationLimits = structuredClone(LEAF_WORKER_DELEGATION_LIMITS);\n\tconst requestedWorkspacePath = input.authority?.path ?? input.base?.profile.workspacePath;\n\tconst workspacePath = requestedWorkspacePath\n\t\t? resolveWorkerWorkspacePath(input.cwd ?? process.cwd(), requestedWorkspacePath)\n\t\t: undefined;\n\tconst now = new Date().toISOString();\n\tconst descriptor = {\n\t\tbaseProfileId: input.base?.profile.profileId ?? null,\n\t\trole,\n\t\tbinding: resolvedModel.binding,\n\t\tcapabilities: [...capabilities],\n\t\ttoolNames,\n\t\tbudget,\n\t\tdelegationLimits: delegationLimits ?? null,\n\t\tworkspacePath: workspacePath ?? null,\n\t\tresourceProfileNames: input.base?.profile.resourceProfileNames ?? [],\n\t\tdispatchProfileIds: input.base?.profile.dispatchProfileIds ?? [],\n\t\texecutionPolicy: input.base?.profile.executionPolicy ?? null,\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\tverificationProfileId: input.base?.profile.verificationProfileId ?? null,\n\t};\n\tconst maxWallClockMs = budget.maxWallClockMs ?? 0;\n\tconst wallClockLeaseTtlMs =\n\t\tmaxWallClockMs > Number.MAX_SAFE_INTEGER - 30_000 ? Number.MAX_SAFE_INTEGER : maxWallClockMs + 30_000;\n\tconst profile: OrchestrationProfile = {\n\t\tschemaVersion: ORCHESTRATION_SCHEMA_VERSION,\n\t\tprofileId: input.base?.profile.profileId ?? \"\",\n\t\tdescription: input.base?.profile.description ?? \"Admission-time adaptive agent authority\",\n\t\trole,\n\t\tmodelPolicy: { mode: \"fixed\", candidates: [resolvedModel.binding] },\n\t\tcapabilityCeiling: [...capabilities],\n\t\ttoolNames,\n\t\t...(workspacePath ? { workspacePath } : {}),\n\t\tresourceProfileNames: [...(input.base?.profile.resourceProfileNames ?? [])],\n\t\tdispatchProfileIds: [...(input.base?.profile.dispatchProfileIds ?? [])],\n\t\t...(input.base?.profile.executionPolicy ? { executionPolicy: input.base.profile.executionPolicy } : {}),\n\t\tdelegationLimits,\n\t\tbudget,\n\t\tmaxConcurrent: input.base?.profile.maxConcurrent ?? Number.MAX_SAFE_INTEGER,\n\t\tleaseTtlMs: Math.max(input.base?.profile.leaseTtlMs ?? 0, wallClockLeaseTtlMs, 90_000),\n\t\trequireIndependentVerification: input.base?.profile.requireIndependentVerification ?? false,\n\t\t...(input.base?.profile.verificationProfileId\n\t\t\t? { verificationProfileId: input.base.profile.verificationProfileId }\n\t\t\t: {}),\n\t\tcreatedAt: input.base?.profile.createdAt ?? now,\n\t\tupdatedAt: input.base?.profile.updatedAt ?? now,\n\t};\n\tconst unchangedBase = input.base && isDeepStrictEqual(profile, input.base.profile);\n\tprofile.profileId = unchangedBase ? profile.profileId : adaptiveProfileId(descriptor);\n\treturn {\n\t\tok: true,\n\t\tshipment: {\n\t\t\tmodel: resolvedModel.model,\n\t\t\tmodelBinding: resolvedModel.binding,\n\t\t\tprofile,\n\t\t\tresourcePointers: structuredClone(input.base?.resourcePointers ?? []),\n\t\t\t...(input.base?.soul ? { soul: input.base.soul } : {}),\n\t\t},\n\t};\n}\n"]}
|
|
@@ -78,8 +78,7 @@ export declare function validateWorkerClaim(args: {
|
|
|
78
78
|
*/
|
|
79
79
|
export declare function reviewManagedLaneChangedFiles(args: {
|
|
80
80
|
changedFiles: readonly string[];
|
|
81
|
-
/** The scope to validate against
|
|
82
|
-
* per-launch tmux standing grant envelope lands in a later wave (documented follow-up). */
|
|
81
|
+
/** The immutable managed-launch profile scope to validate against. */
|
|
83
82
|
envelope: Pick<CapabilityEnvelope, "allowedPaths" | "deniedPaths">;
|
|
84
83
|
cwd?: string;
|
|
85
84
|
}): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-claim.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-claim.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAM5G,eAAO,MAAM,8BAA8B,QAAoB,CAAC;AAChE,eAAO,MAAM,8BAA8B,QAAoB,CAAC;AAChE,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAC5C,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AACpD,eAAO,MAAM,8BAA8B,MAAM,CAAC;AAClD,eAAO,MAAM,mCAAmC,OAAQ,CAAC;AACzD,eAAO,MAAM,iCAAiC,MAAM,CAAC;AACrD,eAAO,MAAM,0CAA0C,MAAM,CAAC;AAC9D,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAC1D,eAAO,MAAM,gCAAgC,MAAM,CAAC;AACpD,eAAO,MAAM,8CAA8C,MAAM,CAAC;AAClE,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAChD,eAAO,MAAM,kCAAkC,MAAM,CAAC;AAEtD,MAAM,WAAW,yBAAyB;IACzC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;CACpB;AAyBD,uGAAuG;AACvG,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,yBAAyB,CAEtG;AAED,kGAAkG;AAClG,wBAAgB,qCAAqC,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,yBAAyB,CAO1G;AAmCD,gFAAgF;AAChF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,MAAM,CAMzE;AAuBD,wBAAgB,yBAAyB,CACxC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,YAAY,EAAE,M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GAAG,qBAAqB,CAAC;IAC1C,MAAM,UAAU,GAAG,mBAAmB,CAAC;QACtC,OAAO,EAAE;YACR,EAAE,EAAE,WAAW;YACf,YAAY,EAAE,EAAE;YAChB,KAAK,EAAE;gBACN,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,cAAc;gBACpB,UAAU,EAAE,CAAC;gBACb,UAAU,EAAE,qBAAqB;gBACjC,OAAO,EAAE,EAAE;aACX;YACD,QAAQ,EAAE;gBACT,EAAE,EAAE,WAAW;gBACf,YAAY,EAAE,CAAC,kBAAkB,CAAC;gBAClC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY;gBACxC,WAAW,EAAE,IAAI,CAAC,QAAQ,CAAC,WAAW;aACtC;SACD;QACD,KAAK,EAAE;YACN,SAAS,EAAE,WAAW;YACtB,MAAM,EAAE,WAAW;YACnB,OAAO,EAAE,mCAAmC;YAC5C,YAAY,EAAE,mBAAmB;YACjC,aAAa,EAAE,WAAW;SAC1B;QACD,GAAG,EAAE,IAAI,CAAC,GAAG;KACb,CAAC,CAAC;IACH,OAAO,EAAE,cAAc,EAAE,UAAU,CAAC,OAAO,KAAK,OAAO,EAAE,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE,CAAC;AAC9F,CAAC","sourcesContent":["import path from \"node:path\";\nimport { DEFAULT_MAX_BYTES } from \"@caupulican/pi-agent-core/truncate\";\nimport type { CapabilityEnvelope, GateOutcome, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport { checkPathScope } from \"../autonomy/path-scope.ts\";\nimport { normalizeEvidenceBundleForStorage } from \"../research/evidence-bundle.ts\";\nimport { utf8PrefixByBytes } from \"../util/bounded-value.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport const MAX_WORKER_CLAIM_SUMMARY_CHARS = DEFAULT_MAX_BYTES;\nexport const MAX_WORKER_CLAIM_SUMMARY_BYTES = DEFAULT_MAX_BYTES;\nexport const MAX_WORKER_CLAIM_BLOCKERS = 32;\nexport const MAX_WORKER_CLAIM_BLOCKER_CHARS = 1_000;\nexport const MAX_WORKER_CLAIM_CHANGED_FILES = 128;\nexport const MAX_WORKER_CLAIM_CHANGED_FILE_CHARS = 2_048;\nexport const MAX_WORKER_CLAIM_REQUEST_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_TERMINAL_ATTEMPT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_USAGE_REPORT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_TIMESTAMP_CHARS = 128;\nexport const MAX_WORKER_CLAIM_VERIFICATION_SUBJECT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_REASON_CODES = 32;\nexport const MAX_WORKER_CLAIM_REASON_CODE_CHARS = 128;\n\nexport interface BoundedWorkerClaimStrings {\n\tvalues: string[];\n\toverflowed: boolean;\n}\n\nfunction collectBoundedWorkerClaimStrings(\n\tvalues: readonly string[],\n\tmaximumCount: number,\n\tmaximumChars: number,\n\ttrim: boolean,\n): BoundedWorkerClaimStrings {\n\tconst bounded: string[] = [];\n\tconst seen = new Set<string>();\n\tlet overflowed = values.length > maximumCount;\n\tfor (let index = 0; index < Math.min(values.length, maximumCount); index++) {\n\t\tconst raw = values[index];\n\t\tif (typeof raw !== \"string\" || raw.length > maximumChars) {\n\t\t\toverflowed = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst normalized = trim ? raw.trim() : raw;\n\t\tif (!normalized || seen.has(normalized)) continue;\n\t\tseen.add(normalized);\n\t\tbounded.push(normalized);\n\t}\n\treturn { values: bounded, overflowed };\n}\n\n/** Native host observations may be reduced for terminal storage, but callers must surface overflow. */\nexport function collectBoundedWorkerClaimBlockers(values: readonly string[]): BoundedWorkerClaimStrings {\n\treturn collectBoundedWorkerClaimStrings(values, MAX_WORKER_CLAIM_BLOCKERS, MAX_WORKER_CLAIM_BLOCKER_CHARS, true);\n}\n\n/** Changed paths preserve their exact spelling; trimming a real path could change its meaning. */\nexport function collectBoundedWorkerClaimChangedFiles(values: readonly string[]): BoundedWorkerClaimStrings {\n\treturn collectBoundedWorkerClaimStrings(\n\t\tvalues,\n\t\tMAX_WORKER_CLAIM_CHANGED_FILES,\n\t\tMAX_WORKER_CLAIM_CHANGED_FILE_CHARS,\n\t\tfalse,\n\t);\n}\n\nfunction invalidWorkerClaim(message: string): never {\n\tthrow new Error(`Invalid worker claim: ${message}`);\n}\n\n/**\n * The worker boundary must not evaluate accessors from managed/external reports. Copy only own\n * data descriptors, then validate and construct a fresh contract object from the bounded values.\n */\nfunction ownWorkerClaimDataRecord(value: unknown, label: string): Record<string, unknown> {\n\tif (!isPlainRecord(value)) invalidWorkerClaim(`${label} must be a plain object.`);\n\tconst descriptors = Object.getOwnPropertyDescriptors(value);\n\tconst record: Record<string, unknown> = Object.create(null) as Record<string, unknown>;\n\tfor (const [key, descriptor] of Object.entries(descriptors)) {\n\t\tif (!(\"value\" in descriptor)) invalidWorkerClaim(`${label}.${key} must not be an accessor.`);\n\t\trecord[key] = descriptor.value;\n\t}\n\treturn record;\n}\n\nfunction requiredWorkerClaimString(value: unknown, label: string, maximumChars: number): string {\n\tif (typeof value !== \"string\" || value.length === 0) invalidWorkerClaim(`${label} must be a non-empty string.`);\n\tif (value.length > maximumChars) invalidWorkerClaim(`${label} exceeds ${maximumChars} characters.`);\n\treturn value;\n}\n\nfunction requiredWorkerClaimSummary(value: unknown): string {\n\tconst summary = requiredWorkerClaimString(value, \"claim.summary\", MAX_WORKER_CLAIM_SUMMARY_CHARS);\n\tif (Buffer.byteLength(summary, \"utf8\") > MAX_WORKER_CLAIM_SUMMARY_BYTES) {\n\t\tinvalidWorkerClaim(`claim.summary exceeds ${MAX_WORKER_CLAIM_SUMMARY_BYTES} bytes.`);\n\t}\n\treturn summary;\n}\n\n/** Bound a host-produced claim summary without splitting a UTF-8 code point. */\nexport function clipWorkerClaimSummary(value: string, suffix = \"\"): string {\n\tconst suffixBytes = Buffer.byteLength(suffix, \"utf8\");\n\tif (suffixBytes > MAX_WORKER_CLAIM_SUMMARY_BYTES) {\n\t\tthrow new TypeError(\"Worker claim summary suffix exceeds the inline output ceiling.\");\n\t}\n\treturn `${utf8PrefixByBytes(value, MAX_WORKER_CLAIM_SUMMARY_BYTES - suffixBytes)}${suffix}`;\n}\n\nfunction optionalWorkerClaimString(value: unknown, label: string, maximumChars: number): string | undefined {\n\tif (value === undefined) return undefined;\n\treturn requiredWorkerClaimString(value, label, maximumChars);\n}\n\nfunction workerClaimStringArray(value: unknown, label: string, maximumCount: number, maximumChars: number): string[] {\n\tif (!Array.isArray(value)) invalidWorkerClaim(`${label} must be an array.`);\n\tif (value.length > maximumCount) invalidWorkerClaim(`${label} exceeds ${maximumCount} entries.`);\n\tconst copied: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\tif (!descriptor || !(\"value\" in descriptor)) invalidWorkerClaim(`${label}[${index}] must be a data value.`);\n\t\tconst item = requiredWorkerClaimString(descriptor.value, `${label}[${index}]`, maximumChars);\n\t\tif (seen.has(item)) continue;\n\t\tseen.add(item);\n\t\tcopied.push(item);\n\t}\n\treturn copied;\n}\n\nexport function boundedWorkerClaimStrings(\n\tvalues: readonly string[],\n\tmaximumCount: number,\n\tmaximumChars: number,\n): string[] {\n\tconst bounded: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const value of values) {\n\t\tconst normalized = value.trim().slice(0, maximumChars);\n\t\tif (!normalized || seen.has(normalized)) continue;\n\t\tseen.add(normalized);\n\t\tbounded.push(normalized);\n\t\tif (bounded.length >= maximumCount) break;\n\t}\n\treturn bounded;\n}\n\nexport function boundedWorkerClaimBlockers(values: readonly string[]): string[] {\n\treturn collectBoundedWorkerClaimBlockers(values).values;\n}\n\nexport function boundedWorkerClaimChangedFiles(values: readonly string[]): string[] {\n\treturn collectBoundedWorkerClaimChangedFiles(values).values;\n}\n\n/**\n * Applies the one mandatory bounded claim contract before persistence, review, finalization, or\n * artifact inspection. Host-built/native reports have already bounded their model output; foreign\n * reports must fit the exact same envelope and are rejected before cloning or getter invocation.\n */\nexport function normalizeWorkerClaimForHost(value: unknown): WorkerClaim {\n\tconst claim = ownWorkerClaimDataRecord(value, \"claim\");\n\tconst status = claim.status;\n\tif (\n\t\tstatus !== \"completed\" &&\n\t\tstatus !== \"partial\" &&\n\t\tstatus !== \"blocked\" &&\n\t\tstatus !== \"failed\" &&\n\t\tstatus !== \"cancelled\"\n\t) {\n\t\tinvalidWorkerClaim(\"claim.status is invalid.\");\n\t}\n\tif (claim.outputFormat !== undefined && claim.outputFormat !== \"structured\" && claim.outputFormat !== \"plain_text\") {\n\t\tinvalidWorkerClaim(\"claim.outputFormat is invalid.\");\n\t}\n\tif (claim.parentReviewRequired !== undefined && typeof claim.parentReviewRequired !== \"boolean\") {\n\t\tinvalidWorkerClaim(\"claim.parentReviewRequired must be boolean.\");\n\t}\n\tconst verification =\n\t\tclaim.verification === undefined ? undefined : ownWorkerClaimDataRecord(claim.verification, \"claim.verification\");\n\tif (verification && verification.verdict !== \"accepted\" && verification.verdict !== \"rejected\") {\n\t\tinvalidWorkerClaim(\"claim.verification.verdict is invalid.\");\n\t}\n\tconst normalizedVerification: WorkerClaim[\"verification\"] = verification\n\t\t? {\n\t\t\t\tsubjectTaskId: requiredWorkerClaimString(\n\t\t\t\t\tverification.subjectTaskId,\n\t\t\t\t\t\"claim.verification.subjectTaskId\",\n\t\t\t\t\tMAX_WORKER_CLAIM_VERIFICATION_SUBJECT_ID_CHARS,\n\t\t\t\t),\n\t\t\t\tverdict: verification.verdict === \"accepted\" ? \"accepted\" : \"rejected\",\n\t\t\t\treasonCodes: workerClaimStringArray(\n\t\t\t\t\tverification.reasonCodes,\n\t\t\t\t\t\"claim.verification.reasonCodes\",\n\t\t\t\t\tMAX_WORKER_CLAIM_REASON_CODES,\n\t\t\t\t\tMAX_WORKER_CLAIM_REASON_CODE_CHARS,\n\t\t\t\t),\n\t\t\t}\n\t\t: undefined;\n\tif (normalizedVerification && normalizedVerification.reasonCodes.length === 0) {\n\t\tinvalidWorkerClaim(\"claim.verification.reasonCodes must not be empty.\");\n\t}\n\treturn {\n\t\trequestId: requiredWorkerClaimString(claim.requestId, \"claim.requestId\", MAX_WORKER_CLAIM_REQUEST_ID_CHARS),\n\t\t...(claim.terminalAttemptId !== undefined\n\t\t\t? {\n\t\t\t\t\tterminalAttemptId: requiredWorkerClaimString(\n\t\t\t\t\t\tclaim.terminalAttemptId,\n\t\t\t\t\t\t\"claim.terminalAttemptId\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TERMINAL_ATTEMPT_ID_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\tstatus,\n\t\tsummary: requiredWorkerClaimSummary(claim.summary),\n\t\t...(claim.outputFormat !== undefined ? { outputFormat: claim.outputFormat } : {}),\n\t\t...(claim.evidence !== undefined ? { evidence: normalizeEvidenceBundleForStorage(claim.evidence) } : {}),\n\t\tchangedFiles: workerClaimStringArray(\n\t\t\tclaim.changedFiles,\n\t\t\t\"claim.changedFiles\",\n\t\t\tMAX_WORKER_CLAIM_CHANGED_FILES,\n\t\t\tMAX_WORKER_CLAIM_CHANGED_FILE_CHARS,\n\t\t),\n\t\t...(claim.blockers !== undefined\n\t\t\t? {\n\t\t\t\t\tblockers: workerClaimStringArray(\n\t\t\t\t\t\tclaim.blockers,\n\t\t\t\t\t\t\"claim.blockers\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_BLOCKERS,\n\t\t\t\t\t\tMAX_WORKER_CLAIM_BLOCKER_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.usageReportId !== undefined\n\t\t\t? {\n\t\t\t\t\tusageReportId: requiredWorkerClaimString(\n\t\t\t\t\t\tclaim.usageReportId,\n\t\t\t\t\t\t\"claim.usageReportId\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_USAGE_REPORT_ID_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.createdAt !== undefined\n\t\t\t? {\n\t\t\t\t\tcreatedAt: optionalWorkerClaimString(\n\t\t\t\t\t\tclaim.createdAt,\n\t\t\t\t\t\t\"claim.createdAt\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TIMESTAMP_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.parentReviewRequired !== undefined ? { parentReviewRequired: claim.parentReviewRequired } : {}),\n\t\t...(claim.parentReviewedAt !== undefined\n\t\t\t? {\n\t\t\t\t\tparentReviewedAt: optionalWorkerClaimString(\n\t\t\t\t\t\tclaim.parentReviewedAt,\n\t\t\t\t\t\t\"claim.parentReviewedAt\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TIMESTAMP_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(normalizedVerification ? { verification: normalizedVerification } : {}),\n\t};\n}\n\nexport function normalizeWorkerClaimReasonCode(value: unknown, fallback: string): string {\n\treturn (typeof value === \"string\" && value.trim() ? value.trim() : fallback).slice(\n\t\t0,\n\t\tMAX_WORKER_CLAIM_REASON_CODE_CHARS,\n\t);\n}\n\nexport function cloneWorkerClaimForStorage(claim: WorkerClaim): WorkerClaim {\n\treturn normalizeWorkerClaimForHost(claim);\n}\n\nexport function isWorkerClaim(value: unknown): value is WorkerClaim {\n\ttry {\n\t\tnormalizeWorkerClaimForHost(value);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function requiresParentReview(claim: WorkerClaim): boolean {\n\tif (claim.status !== \"completed\") {\n\t\treturn true;\n\t}\n\tif (claim.blockers && claim.blockers.length > 0) {\n\t\treturn true;\n\t}\n\tif (claim.changedFiles.length > 0) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * True iff {@link validateWorkerClaim}'s gate would flag this claim \"ask-user\" /\n * \"parent_review_required\" (the two branches at :110 and :178 below) — an otherwise-completed\n * claim the parent must explicitly look at because it reports blockers, or reports file mutations\n * that passed path-scope validation. Reuses `validateWorkerClaim` itself rather than a\n * separately-maintained heuristic, so a persisted review marker can never drift from the\n * gate's actual verdict.\n */\nexport function isParentReviewRequired(args: { request: WorkerRequest; claim: WorkerClaim; cwd?: string }): boolean {\n\tconst acceptance = validateWorkerClaim(args);\n\treturn acceptance.outcome === \"ask-user\" && acceptance.reasonCode === \"parent_review_required\";\n}\n\nexport function validateWorkerClaim(args: {\n\trequest: WorkerRequest;\n\tclaim: WorkerClaim;\n\t/**\n\t * Baseline for relative paths — BOTH the runner's cwd-relative `changedFiles` and the\n\t * envelope's possibly-relative path scopes resolve against this. Defaults to process.cwd()\n\t * for callers whose session cwd is the process cwd.\n\t */\n\tcwd?: string;\n}): GateOutcome {\n\tconst { request } = args;\n\tlet claim: WorkerClaim;\n\ttry {\n\t\tclaim = normalizeWorkerClaimForHost(args.claim);\n\t} catch (error) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"invalid_worker_claim\",\n\t\t\tmessage: error instanceof Error ? error.message : \"Worker claim failed host validation.\",\n\t\t};\n\t}\n\tconst baseDir = args.cwd ?? process.cwd();\n\n\tif (claim.requestId !== request.id) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"request_id_mismatch\",\n\t\t\tmessage: `Claim requestId '${claim.requestId}' does not match request id '${request.id}'.`,\n\t\t};\n\t}\n\n\tif (claim.status === \"partial\") {\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: `Worker finished with partial claim status '${claim.status}'.`,\n\t\t\tdetails: claim.blockers && claim.blockers.length > 0 ? { blockers: [...claim.blockers] } : undefined,\n\t\t};\n\t}\n\n\tif (claim.status !== \"completed\") {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"worker_not_completed\",\n\t\t\tmessage: `Worker finished with status '${claim.status}'.`,\n\t\t\tdetails: claim.blockers && claim.blockers.length > 0 ? { blockers: [...claim.blockers] } : undefined,\n\t\t};\n\t}\n\n\tif (!claim.usageReportId) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"missing_usage_report\",\n\t\t\tmessage: \"Completed worker claim is missing usageReportId.\",\n\t\t};\n\t}\n\n\tif (claim.blockers && claim.blockers.length > 0) {\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: \"Completed worker claim includes blockers and requires parent review.\",\n\t\t\tdetails: { blockers: [...claim.blockers] },\n\t\t};\n\t}\n\n\tif (claim.changedFiles.length > 0) {\n\t\tif (!request.envelope.allowedPaths || request.envelope.allowedPaths.length === 0) {\n\t\t\treturn {\n\t\t\t\toutcome: \"block\",\n\t\t\t\tgate: \"worker_claim\",\n\t\t\t\treasonCode: \"missing_path_scope\",\n\t\t\t\tmessage: \"Worker changed files but no allowedPaths are configured in the envelope.\",\n\t\t\t};\n\t\t}\n\n\t\t// The runner reports changed files relative to the session cwd — resolve file and scope\n\t\t// roots against the SAME baseline. Resolving per-root double-prefixed nested names and\n\t\t// let a denied subtree slip past the deny rule.\n\t\tconst resolvedAllowed = request.envelope.allowedPaths.map((p) => path.resolve(baseDir, p));\n\t\tconst resolvedDenied = request.envelope.deniedPaths?.map((p) => path.resolve(baseDir, p));\n\t\tfor (const changedFile of claim.changedFiles) {\n\t\t\tlet isInsideAny = false;\n\t\t\tlet isDenied = false;\n\n\t\t\tconst scopedChangedFile = path.resolve(baseDir, changedFile);\n\t\t\tfor (const root of resolvedAllowed) {\n\t\t\t\tconst decision = checkPathScope(\n\t\t\t\t\t{\n\t\t\t\t\t\troot,\n\t\t\t\t\t\tallowedPaths: resolvedAllowed,\n\t\t\t\t\t\tdeniedPaths: resolvedDenied,\n\t\t\t\t\t},\n\t\t\t\t\tscopedChangedFile,\n\t\t\t\t);\n\n\t\t\t\tif (decision.kind === \"denied\") {\n\t\t\t\t\tisDenied = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (decision.kind === \"inside\") {\n\t\t\t\t\tisInsideAny = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isDenied) {\n\t\t\t\treturn {\n\t\t\t\t\toutcome: \"block\",\n\t\t\t\t\tgate: \"worker_claim\",\n\t\t\t\t\treasonCode: \"changed_file_denied\",\n\t\t\t\t\tmessage: `Worker changed file '${changedFile}' which matches a denied path.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (!isInsideAny) {\n\t\t\t\treturn {\n\t\t\t\t\toutcome: \"block\",\n\t\t\t\t\tgate: \"worker_claim\",\n\t\t\t\t\treasonCode: \"changed_file_outside_scope\",\n\t\t\t\t\tmessage: `Worker changed file '${changedFile}' outside allowed scope.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Files are inside scope, but worker output is untrusted\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: \"Worker changed files require parent review.\",\n\t\t};\n\t}\n\n\treturn {\n\t\toutcome: \"allow\",\n\t\tgate: \"worker_claim\",\n\t\treasonCode: \"allowed\",\n\t\tmessage: \"Worker claim is read-only and allowed.\",\n\t};\n}\n\n/**\n * Path-scope-only re-review for a SELF-REPORTED (out-of-process) worker's claimed `changedFiles`\n * -- e.g. a tmux worker's own completion report, which (unlike an in-process worker's) never\n * passed through this process's `applyWorkerActions` envelope enforcement before the write\n * happened; the tmux worker's tool loop runs in a separate process this session does not gate.\n * Reuses {@link validateWorkerClaim}'s exact symlink-safe scope check verbatim -- never\n * reimplement path resolution: synthesizes a minimal, always-\"completed\" request/claim pair\n * carrying only the reported `changedFiles` and the scope's `allowedPaths`/`deniedPaths`, so the\n * ONLY thing that can vary the verdict is the path-scope branch.\n *\n * Deliberately broader than {@link isParentReviewRequired}: that helper only flags the gate's\n * \"ask-user\" branch, which is correct for an in-process worker (a write that would have been\n * \"block\"-worthy was already refused before it could happen, by the SAME envelope, via\n * `applyWorkerActions`). A self-reported claim has no such backstop -- an out-of-scope or denied\n * path already happened on the real filesystem whether or not this gate would allow it, so here\n * ANY non-\"allow\" verdict (in scope, out of scope, or no scope configured at all) means a human\n * must look, not \"the write didn't happen\".\n */\nexport function reviewManagedLaneChangedFiles(args: {\n\tchangedFiles: readonly string[];\n\t/** The scope to validate against -- e.g. the session's active `CapabilityEnvelope`, until a\n\t * per-launch tmux standing grant envelope lands in a later wave (documented follow-up). */\n\tenvelope: Pick<CapabilityEnvelope, \"allowedPaths\" | \"deniedPaths\">;\n\tcwd?: string;\n}): { reviewRequired: boolean; reasonCode: string } {\n\tconst boundedChangedFiles = normalizeWorkerClaimForHost({\n\t\trequestId: \"managed-lane-review\",\n\t\tstatus: \"completed\",\n\t\tsummary: \"Managed lane changed-file review.\",\n\t\tchangedFiles: args.changedFiles,\n\t\tusageReportId: \"managed-lane-review\",\n\t}).changedFiles;\n\tif (boundedChangedFiles.length === 0) {\n\t\treturn { reviewRequired: false, reasonCode: \"no_changed_files\" };\n\t}\n\tconst syntheticId = \"managed-lane-review\";\n\tconst acceptance = validateWorkerClaim({\n\t\trequest: {\n\t\t\tid: syntheticId,\n\t\t\tinstructions: \"\",\n\t\t\troute: {\n\t\t\t\ttier: \"cheap\",\n\t\t\t\trisk: \"scoped-write\",\n\t\t\t\tconfidence: 1,\n\t\t\t\treasonCode: \"managed_lane_review\",\n\t\t\t\treasons: [],\n\t\t\t},\n\t\t\tenvelope: {\n\t\t\t\tid: syntheticId,\n\t\t\t\tcapabilities: [\"filesystem.write\"],\n\t\t\t\tallowedPaths: args.envelope.allowedPaths,\n\t\t\t\tdeniedPaths: args.envelope.deniedPaths,\n\t\t\t},\n\t\t},\n\t\tclaim: {\n\t\t\trequestId: syntheticId,\n\t\t\tstatus: \"completed\",\n\t\t\tsummary: \"Managed lane changed-file review.\",\n\t\t\tchangedFiles: boundedChangedFiles,\n\t\t\tusageReportId: syntheticId,\n\t\t},\n\t\tcwd: args.cwd,\n\t});\n\treturn { reviewRequired: acceptance.outcome !== \"allow\", reasonCode: acceptance.reasonCode };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-claim.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-claim.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,iCAAiC,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,MAAM,CAAC,MAAM,8BAA8B,GAAG,iBAAiB,CAAC;AAChE,MAAM,CAAC,MAAM,8BAA8B,GAAG,iBAAiB,CAAC;AAChE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAC5C,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AACpD,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAClD,MAAM,CAAC,MAAM,mCAAmC,GAAG,KAAK,CAAC;AACzD,MAAM,CAAC,MAAM,iCAAiC,GAAG,GAAG,CAAC;AACrD,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAG,CAAC;AAC9D,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAC1D,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAAG,CAAC;AACpD,MAAM,CAAC,MAAM,8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AAU,EAAE,CAAC;AAC9F,CAAC","sourcesContent":["import path from \"node:path\";\nimport { DEFAULT_MAX_BYTES } from \"@caupulican/pi-agent-core/truncate\";\nimport type { CapabilityEnvelope, GateOutcome, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport { checkPathScope } from \"../autonomy/path-scope.ts\";\nimport { normalizeEvidenceBundleForStorage } from \"../research/evidence-bundle.ts\";\nimport { utf8PrefixByBytes } from \"../util/bounded-value.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nexport const MAX_WORKER_CLAIM_SUMMARY_CHARS = DEFAULT_MAX_BYTES;\nexport const MAX_WORKER_CLAIM_SUMMARY_BYTES = DEFAULT_MAX_BYTES;\nexport const MAX_WORKER_CLAIM_BLOCKERS = 32;\nexport const MAX_WORKER_CLAIM_BLOCKER_CHARS = 1_000;\nexport const MAX_WORKER_CLAIM_CHANGED_FILES = 128;\nexport const MAX_WORKER_CLAIM_CHANGED_FILE_CHARS = 2_048;\nexport const MAX_WORKER_CLAIM_REQUEST_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_TERMINAL_ATTEMPT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_USAGE_REPORT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_TIMESTAMP_CHARS = 128;\nexport const MAX_WORKER_CLAIM_VERIFICATION_SUBJECT_ID_CHARS = 256;\nexport const MAX_WORKER_CLAIM_REASON_CODES = 32;\nexport const MAX_WORKER_CLAIM_REASON_CODE_CHARS = 128;\n\nexport interface BoundedWorkerClaimStrings {\n\tvalues: string[];\n\toverflowed: boolean;\n}\n\nfunction collectBoundedWorkerClaimStrings(\n\tvalues: readonly string[],\n\tmaximumCount: number,\n\tmaximumChars: number,\n\ttrim: boolean,\n): BoundedWorkerClaimStrings {\n\tconst bounded: string[] = [];\n\tconst seen = new Set<string>();\n\tlet overflowed = values.length > maximumCount;\n\tfor (let index = 0; index < Math.min(values.length, maximumCount); index++) {\n\t\tconst raw = values[index];\n\t\tif (typeof raw !== \"string\" || raw.length > maximumChars) {\n\t\t\toverflowed = true;\n\t\t\tcontinue;\n\t\t}\n\t\tconst normalized = trim ? raw.trim() : raw;\n\t\tif (!normalized || seen.has(normalized)) continue;\n\t\tseen.add(normalized);\n\t\tbounded.push(normalized);\n\t}\n\treturn { values: bounded, overflowed };\n}\n\n/** Native host observations may be reduced for terminal storage, but callers must surface overflow. */\nexport function collectBoundedWorkerClaimBlockers(values: readonly string[]): BoundedWorkerClaimStrings {\n\treturn collectBoundedWorkerClaimStrings(values, MAX_WORKER_CLAIM_BLOCKERS, MAX_WORKER_CLAIM_BLOCKER_CHARS, true);\n}\n\n/** Changed paths preserve their exact spelling; trimming a real path could change its meaning. */\nexport function collectBoundedWorkerClaimChangedFiles(values: readonly string[]): BoundedWorkerClaimStrings {\n\treturn collectBoundedWorkerClaimStrings(\n\t\tvalues,\n\t\tMAX_WORKER_CLAIM_CHANGED_FILES,\n\t\tMAX_WORKER_CLAIM_CHANGED_FILE_CHARS,\n\t\tfalse,\n\t);\n}\n\nfunction invalidWorkerClaim(message: string): never {\n\tthrow new Error(`Invalid worker claim: ${message}`);\n}\n\n/**\n * The worker boundary must not evaluate accessors from managed/external reports. Copy only own\n * data descriptors, then validate and construct a fresh contract object from the bounded values.\n */\nfunction ownWorkerClaimDataRecord(value: unknown, label: string): Record<string, unknown> {\n\tif (!isPlainRecord(value)) invalidWorkerClaim(`${label} must be a plain object.`);\n\tconst descriptors = Object.getOwnPropertyDescriptors(value);\n\tconst record: Record<string, unknown> = Object.create(null) as Record<string, unknown>;\n\tfor (const [key, descriptor] of Object.entries(descriptors)) {\n\t\tif (!(\"value\" in descriptor)) invalidWorkerClaim(`${label}.${key} must not be an accessor.`);\n\t\trecord[key] = descriptor.value;\n\t}\n\treturn record;\n}\n\nfunction requiredWorkerClaimString(value: unknown, label: string, maximumChars: number): string {\n\tif (typeof value !== \"string\" || value.length === 0) invalidWorkerClaim(`${label} must be a non-empty string.`);\n\tif (value.length > maximumChars) invalidWorkerClaim(`${label} exceeds ${maximumChars} characters.`);\n\treturn value;\n}\n\nfunction requiredWorkerClaimSummary(value: unknown): string {\n\tconst summary = requiredWorkerClaimString(value, \"claim.summary\", MAX_WORKER_CLAIM_SUMMARY_CHARS);\n\tif (Buffer.byteLength(summary, \"utf8\") > MAX_WORKER_CLAIM_SUMMARY_BYTES) {\n\t\tinvalidWorkerClaim(`claim.summary exceeds ${MAX_WORKER_CLAIM_SUMMARY_BYTES} bytes.`);\n\t}\n\treturn summary;\n}\n\n/** Bound a host-produced claim summary without splitting a UTF-8 code point. */\nexport function clipWorkerClaimSummary(value: string, suffix = \"\"): string {\n\tconst suffixBytes = Buffer.byteLength(suffix, \"utf8\");\n\tif (suffixBytes > MAX_WORKER_CLAIM_SUMMARY_BYTES) {\n\t\tthrow new TypeError(\"Worker claim summary suffix exceeds the inline output ceiling.\");\n\t}\n\treturn `${utf8PrefixByBytes(value, MAX_WORKER_CLAIM_SUMMARY_BYTES - suffixBytes)}${suffix}`;\n}\n\nfunction optionalWorkerClaimString(value: unknown, label: string, maximumChars: number): string | undefined {\n\tif (value === undefined) return undefined;\n\treturn requiredWorkerClaimString(value, label, maximumChars);\n}\n\nfunction workerClaimStringArray(value: unknown, label: string, maximumCount: number, maximumChars: number): string[] {\n\tif (!Array.isArray(value)) invalidWorkerClaim(`${label} must be an array.`);\n\tif (value.length > maximumCount) invalidWorkerClaim(`${label} exceeds ${maximumCount} entries.`);\n\tconst copied: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(value, String(index));\n\t\tif (!descriptor || !(\"value\" in descriptor)) invalidWorkerClaim(`${label}[${index}] must be a data value.`);\n\t\tconst item = requiredWorkerClaimString(descriptor.value, `${label}[${index}]`, maximumChars);\n\t\tif (seen.has(item)) continue;\n\t\tseen.add(item);\n\t\tcopied.push(item);\n\t}\n\treturn copied;\n}\n\nexport function boundedWorkerClaimStrings(\n\tvalues: readonly string[],\n\tmaximumCount: number,\n\tmaximumChars: number,\n): string[] {\n\tconst bounded: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const value of values) {\n\t\tconst normalized = value.trim().slice(0, maximumChars);\n\t\tif (!normalized || seen.has(normalized)) continue;\n\t\tseen.add(normalized);\n\t\tbounded.push(normalized);\n\t\tif (bounded.length >= maximumCount) break;\n\t}\n\treturn bounded;\n}\n\nexport function boundedWorkerClaimBlockers(values: readonly string[]): string[] {\n\treturn collectBoundedWorkerClaimBlockers(values).values;\n}\n\nexport function boundedWorkerClaimChangedFiles(values: readonly string[]): string[] {\n\treturn collectBoundedWorkerClaimChangedFiles(values).values;\n}\n\n/**\n * Applies the one mandatory bounded claim contract before persistence, review, finalization, or\n * artifact inspection. Host-built/native reports have already bounded their model output; foreign\n * reports must fit the exact same envelope and are rejected before cloning or getter invocation.\n */\nexport function normalizeWorkerClaimForHost(value: unknown): WorkerClaim {\n\tconst claim = ownWorkerClaimDataRecord(value, \"claim\");\n\tconst status = claim.status;\n\tif (\n\t\tstatus !== \"completed\" &&\n\t\tstatus !== \"partial\" &&\n\t\tstatus !== \"blocked\" &&\n\t\tstatus !== \"failed\" &&\n\t\tstatus !== \"cancelled\"\n\t) {\n\t\tinvalidWorkerClaim(\"claim.status is invalid.\");\n\t}\n\tif (claim.outputFormat !== undefined && claim.outputFormat !== \"structured\" && claim.outputFormat !== \"plain_text\") {\n\t\tinvalidWorkerClaim(\"claim.outputFormat is invalid.\");\n\t}\n\tif (claim.parentReviewRequired !== undefined && typeof claim.parentReviewRequired !== \"boolean\") {\n\t\tinvalidWorkerClaim(\"claim.parentReviewRequired must be boolean.\");\n\t}\n\tconst verification =\n\t\tclaim.verification === undefined ? undefined : ownWorkerClaimDataRecord(claim.verification, \"claim.verification\");\n\tif (verification && verification.verdict !== \"accepted\" && verification.verdict !== \"rejected\") {\n\t\tinvalidWorkerClaim(\"claim.verification.verdict is invalid.\");\n\t}\n\tconst normalizedVerification: WorkerClaim[\"verification\"] = verification\n\t\t? {\n\t\t\t\tsubjectTaskId: requiredWorkerClaimString(\n\t\t\t\t\tverification.subjectTaskId,\n\t\t\t\t\t\"claim.verification.subjectTaskId\",\n\t\t\t\t\tMAX_WORKER_CLAIM_VERIFICATION_SUBJECT_ID_CHARS,\n\t\t\t\t),\n\t\t\t\tverdict: verification.verdict === \"accepted\" ? \"accepted\" : \"rejected\",\n\t\t\t\treasonCodes: workerClaimStringArray(\n\t\t\t\t\tverification.reasonCodes,\n\t\t\t\t\t\"claim.verification.reasonCodes\",\n\t\t\t\t\tMAX_WORKER_CLAIM_REASON_CODES,\n\t\t\t\t\tMAX_WORKER_CLAIM_REASON_CODE_CHARS,\n\t\t\t\t),\n\t\t\t}\n\t\t: undefined;\n\tif (normalizedVerification && normalizedVerification.reasonCodes.length === 0) {\n\t\tinvalidWorkerClaim(\"claim.verification.reasonCodes must not be empty.\");\n\t}\n\treturn {\n\t\trequestId: requiredWorkerClaimString(claim.requestId, \"claim.requestId\", MAX_WORKER_CLAIM_REQUEST_ID_CHARS),\n\t\t...(claim.terminalAttemptId !== undefined\n\t\t\t? {\n\t\t\t\t\tterminalAttemptId: requiredWorkerClaimString(\n\t\t\t\t\t\tclaim.terminalAttemptId,\n\t\t\t\t\t\t\"claim.terminalAttemptId\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TERMINAL_ATTEMPT_ID_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\tstatus,\n\t\tsummary: requiredWorkerClaimSummary(claim.summary),\n\t\t...(claim.outputFormat !== undefined ? { outputFormat: claim.outputFormat } : {}),\n\t\t...(claim.evidence !== undefined ? { evidence: normalizeEvidenceBundleForStorage(claim.evidence) } : {}),\n\t\tchangedFiles: workerClaimStringArray(\n\t\t\tclaim.changedFiles,\n\t\t\t\"claim.changedFiles\",\n\t\t\tMAX_WORKER_CLAIM_CHANGED_FILES,\n\t\t\tMAX_WORKER_CLAIM_CHANGED_FILE_CHARS,\n\t\t),\n\t\t...(claim.blockers !== undefined\n\t\t\t? {\n\t\t\t\t\tblockers: workerClaimStringArray(\n\t\t\t\t\t\tclaim.blockers,\n\t\t\t\t\t\t\"claim.blockers\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_BLOCKERS,\n\t\t\t\t\t\tMAX_WORKER_CLAIM_BLOCKER_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.usageReportId !== undefined\n\t\t\t? {\n\t\t\t\t\tusageReportId: requiredWorkerClaimString(\n\t\t\t\t\t\tclaim.usageReportId,\n\t\t\t\t\t\t\"claim.usageReportId\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_USAGE_REPORT_ID_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.createdAt !== undefined\n\t\t\t? {\n\t\t\t\t\tcreatedAt: optionalWorkerClaimString(\n\t\t\t\t\t\tclaim.createdAt,\n\t\t\t\t\t\t\"claim.createdAt\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TIMESTAMP_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(claim.parentReviewRequired !== undefined ? { parentReviewRequired: claim.parentReviewRequired } : {}),\n\t\t...(claim.parentReviewedAt !== undefined\n\t\t\t? {\n\t\t\t\t\tparentReviewedAt: optionalWorkerClaimString(\n\t\t\t\t\t\tclaim.parentReviewedAt,\n\t\t\t\t\t\t\"claim.parentReviewedAt\",\n\t\t\t\t\t\tMAX_WORKER_CLAIM_TIMESTAMP_CHARS,\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(normalizedVerification ? { verification: normalizedVerification } : {}),\n\t};\n}\n\nexport function normalizeWorkerClaimReasonCode(value: unknown, fallback: string): string {\n\treturn (typeof value === \"string\" && value.trim() ? value.trim() : fallback).slice(\n\t\t0,\n\t\tMAX_WORKER_CLAIM_REASON_CODE_CHARS,\n\t);\n}\n\nexport function cloneWorkerClaimForStorage(claim: WorkerClaim): WorkerClaim {\n\treturn normalizeWorkerClaimForHost(claim);\n}\n\nexport function isWorkerClaim(value: unknown): value is WorkerClaim {\n\ttry {\n\t\tnormalizeWorkerClaimForHost(value);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nexport function requiresParentReview(claim: WorkerClaim): boolean {\n\tif (claim.status !== \"completed\") {\n\t\treturn true;\n\t}\n\tif (claim.blockers && claim.blockers.length > 0) {\n\t\treturn true;\n\t}\n\tif (claim.changedFiles.length > 0) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * True iff {@link validateWorkerClaim}'s gate would flag this claim \"ask-user\" /\n * \"parent_review_required\" (the two branches at :110 and :178 below) — an otherwise-completed\n * claim the parent must explicitly look at because it reports blockers, or reports file mutations\n * that passed path-scope validation. Reuses `validateWorkerClaim` itself rather than a\n * separately-maintained heuristic, so a persisted review marker can never drift from the\n * gate's actual verdict.\n */\nexport function isParentReviewRequired(args: { request: WorkerRequest; claim: WorkerClaim; cwd?: string }): boolean {\n\tconst acceptance = validateWorkerClaim(args);\n\treturn acceptance.outcome === \"ask-user\" && acceptance.reasonCode === \"parent_review_required\";\n}\n\nexport function validateWorkerClaim(args: {\n\trequest: WorkerRequest;\n\tclaim: WorkerClaim;\n\t/**\n\t * Baseline for relative paths — BOTH the runner's cwd-relative `changedFiles` and the\n\t * envelope's possibly-relative path scopes resolve against this. Defaults to process.cwd()\n\t * for callers whose session cwd is the process cwd.\n\t */\n\tcwd?: string;\n}): GateOutcome {\n\tconst { request } = args;\n\tlet claim: WorkerClaim;\n\ttry {\n\t\tclaim = normalizeWorkerClaimForHost(args.claim);\n\t} catch (error) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"invalid_worker_claim\",\n\t\t\tmessage: error instanceof Error ? error.message : \"Worker claim failed host validation.\",\n\t\t};\n\t}\n\tconst baseDir = args.cwd ?? process.cwd();\n\n\tif (claim.requestId !== request.id) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"request_id_mismatch\",\n\t\t\tmessage: `Claim requestId '${claim.requestId}' does not match request id '${request.id}'.`,\n\t\t};\n\t}\n\n\tif (claim.status === \"partial\") {\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: `Worker finished with partial claim status '${claim.status}'.`,\n\t\t\tdetails: claim.blockers && claim.blockers.length > 0 ? { blockers: [...claim.blockers] } : undefined,\n\t\t};\n\t}\n\n\tif (claim.status !== \"completed\") {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"worker_not_completed\",\n\t\t\tmessage: `Worker finished with status '${claim.status}'.`,\n\t\t\tdetails: claim.blockers && claim.blockers.length > 0 ? { blockers: [...claim.blockers] } : undefined,\n\t\t};\n\t}\n\n\tif (!claim.usageReportId) {\n\t\treturn {\n\t\t\toutcome: \"block\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"missing_usage_report\",\n\t\t\tmessage: \"Completed worker claim is missing usageReportId.\",\n\t\t};\n\t}\n\n\tif (claim.blockers && claim.blockers.length > 0) {\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: \"Completed worker claim includes blockers and requires parent review.\",\n\t\t\tdetails: { blockers: [...claim.blockers] },\n\t\t};\n\t}\n\n\tif (claim.changedFiles.length > 0) {\n\t\tif (!request.envelope.allowedPaths || request.envelope.allowedPaths.length === 0) {\n\t\t\treturn {\n\t\t\t\toutcome: \"block\",\n\t\t\t\tgate: \"worker_claim\",\n\t\t\t\treasonCode: \"missing_path_scope\",\n\t\t\t\tmessage: \"Worker changed files but no allowedPaths are configured in the envelope.\",\n\t\t\t};\n\t\t}\n\n\t\t// The runner reports changed files relative to the session cwd — resolve file and scope\n\t\t// roots against the SAME baseline. Resolving per-root double-prefixed nested names and\n\t\t// let a denied subtree slip past the deny rule.\n\t\tconst resolvedAllowed = request.envelope.allowedPaths.map((p) => path.resolve(baseDir, p));\n\t\tconst resolvedDenied = request.envelope.deniedPaths?.map((p) => path.resolve(baseDir, p));\n\t\tfor (const changedFile of claim.changedFiles) {\n\t\t\tlet isInsideAny = false;\n\t\t\tlet isDenied = false;\n\n\t\t\tconst scopedChangedFile = path.resolve(baseDir, changedFile);\n\t\t\tfor (const root of resolvedAllowed) {\n\t\t\t\tconst decision = checkPathScope(\n\t\t\t\t\t{\n\t\t\t\t\t\troot,\n\t\t\t\t\t\tallowedPaths: resolvedAllowed,\n\t\t\t\t\t\tdeniedPaths: resolvedDenied,\n\t\t\t\t\t},\n\t\t\t\t\tscopedChangedFile,\n\t\t\t\t);\n\n\t\t\t\tif (decision.kind === \"denied\") {\n\t\t\t\t\tisDenied = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (decision.kind === \"inside\") {\n\t\t\t\t\tisInsideAny = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isDenied) {\n\t\t\t\treturn {\n\t\t\t\t\toutcome: \"block\",\n\t\t\t\t\tgate: \"worker_claim\",\n\t\t\t\t\treasonCode: \"changed_file_denied\",\n\t\t\t\t\tmessage: `Worker changed file '${changedFile}' which matches a denied path.`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (!isInsideAny) {\n\t\t\t\treturn {\n\t\t\t\t\toutcome: \"block\",\n\t\t\t\t\tgate: \"worker_claim\",\n\t\t\t\t\treasonCode: \"changed_file_outside_scope\",\n\t\t\t\t\tmessage: `Worker changed file '${changedFile}' outside allowed scope.`,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Files are inside scope, but worker output is untrusted\n\t\treturn {\n\t\t\toutcome: \"ask-user\",\n\t\t\tgate: \"worker_claim\",\n\t\t\treasonCode: \"parent_review_required\",\n\t\t\tmessage: \"Worker changed files require parent review.\",\n\t\t};\n\t}\n\n\treturn {\n\t\toutcome: \"allow\",\n\t\tgate: \"worker_claim\",\n\t\treasonCode: \"allowed\",\n\t\tmessage: \"Worker claim is read-only and allowed.\",\n\t};\n}\n\n/**\n * Path-scope-only re-review for a SELF-REPORTED (out-of-process) worker's claimed `changedFiles`\n * -- e.g. a tmux worker's own completion report, which (unlike an in-process worker's) never\n * passed through this process's `applyWorkerActions` envelope enforcement before the write\n * happened; the tmux worker's tool loop runs in a separate process this session does not gate.\n * Reuses {@link validateWorkerClaim}'s exact symlink-safe scope check verbatim -- never\n * reimplement path resolution: synthesizes a minimal, always-\"completed\" request/claim pair\n * carrying only the reported `changedFiles` and the scope's `allowedPaths`/`deniedPaths`, so the\n * ONLY thing that can vary the verdict is the path-scope branch.\n *\n * Deliberately broader than {@link isParentReviewRequired}: that helper only flags the gate's\n * \"ask-user\" branch, which is correct for an in-process worker (a write that would have been\n * \"block\"-worthy was already refused before it could happen, by the SAME envelope, via\n * `applyWorkerActions`). A self-reported claim has no such backstop -- an out-of-scope or denied\n * path already happened on the real filesystem whether or not this gate would allow it, so here\n * ANY non-\"allow\" verdict (in scope, out of scope, or no scope configured at all) means a human\n * must look, not \"the write didn't happen\".\n */\nexport function reviewManagedLaneChangedFiles(args: {\n\tchangedFiles: readonly string[];\n\t/** The immutable managed-launch profile scope to validate against. */\n\tenvelope: Pick<CapabilityEnvelope, \"allowedPaths\" | \"deniedPaths\">;\n\tcwd?: string;\n}): { reviewRequired: boolean; reasonCode: string } {\n\tconst boundedChangedFiles = normalizeWorkerClaimForHost({\n\t\trequestId: \"managed-lane-review\",\n\t\tstatus: \"completed\",\n\t\tsummary: \"Managed lane changed-file review.\",\n\t\tchangedFiles: args.changedFiles,\n\t\tusageReportId: \"managed-lane-review\",\n\t}).changedFiles;\n\tif (boundedChangedFiles.length === 0) {\n\t\treturn { reviewRequired: false, reasonCode: \"no_changed_files\" };\n\t}\n\tconst syntheticId = \"managed-lane-review\";\n\tconst acceptance = validateWorkerClaim({\n\t\trequest: {\n\t\t\tid: syntheticId,\n\t\t\tinstructions: \"\",\n\t\t\troute: {\n\t\t\t\ttier: \"cheap\",\n\t\t\t\trisk: \"scoped-write\",\n\t\t\t\tconfidence: 1,\n\t\t\t\treasonCode: \"managed_lane_review\",\n\t\t\t\treasons: [],\n\t\t\t},\n\t\t\tenvelope: {\n\t\t\t\tid: syntheticId,\n\t\t\t\tcapabilities: [\"filesystem.write\"],\n\t\t\t\tallowedPaths: args.envelope.allowedPaths,\n\t\t\t\tdeniedPaths: args.envelope.deniedPaths,\n\t\t\t},\n\t\t},\n\t\tclaim: {\n\t\t\trequestId: syntheticId,\n\t\t\tstatus: \"completed\",\n\t\t\tsummary: \"Managed lane changed-file review.\",\n\t\t\tchangedFiles: boundedChangedFiles,\n\t\t\tusageReportId: syntheticId,\n\t\t},\n\t\tcwd: args.cwd,\n\t});\n\treturn { reviewRequired: acceptance.outcome !== \"allow\", reasonCode: acceptance.reasonCode };\n}\n"]}
|