@caupulican/pi-adaptative 0.81.40 → 0.81.42
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 +41 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +1 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +1 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +5 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
- package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +26 -3
- package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +4 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +2 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +2 -0
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +22 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-paths.d.ts +38 -0
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +77 -0
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +311 -0
- package/dist/core/agent-session-contracts.d.ts.map +1 -0
- package/dist/core/agent-session-contracts.js +26 -0
- package/dist/core/agent-session-contracts.js.map +1 -0
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +3 -0
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +26 -405
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +90 -316
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -1
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +2 -0
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.js +4 -9
- package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +19 -5
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/path-scope.d.ts +14 -0
- package/dist/core/autonomy/path-scope.d.ts.map +1 -1
- package/dist/core/autonomy/path-scope.js +37 -6
- package/dist/core/autonomy/path-scope.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +30 -2
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +33 -1
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/bedrock-sso-login.d.ts +16 -0
- package/dist/core/bedrock-sso-login.d.ts.map +1 -0
- package/dist/core/bedrock-sso-login.js +98 -0
- package/dist/core/bedrock-sso-login.js.map +1 -0
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +1 -1
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/compaction-support.d.ts +3 -8
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +3 -3
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +7 -33
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js +5 -3
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +4 -5
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +84 -41
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/session-worker-claim.js +4 -3
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-action-journal.d.ts +73 -0
- package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
- package/dist/core/delegation/worker-action-journal.js +297 -0
- package/dist/core/delegation/worker-action-journal.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +36 -1
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +171 -46
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +75 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js +218 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-agent-control.d.ts +66 -0
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
- package/dist/core/delegation/worker-agent-control.js +163 -0
- package/dist/core/delegation/worker-agent-control.js.map +1 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
- package/dist/core/delegation/worker-attempt-executor.js +343 -0
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
- package/dist/core/delegation/worker-claim.d.ts +30 -0
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js +205 -53
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
- package/dist/core/delegation/worker-conversation-store.js +442 -0
- package/dist/core/delegation/worker-conversation-store.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +386 -251
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.js +16 -6
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +5 -7
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +120 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-process-owner.d.ts +18 -0
- package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
- package/dist/core/delegation/worker-process-owner.js +54 -0
- package/dist/core/delegation/worker-process-owner.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +8 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.js +181 -0
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
- package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
- package/dist/core/delegation/worker-resource-catalog.js +116 -0
- package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
- package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
- package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
- package/dist/core/delegation/worker-resource-materializer.js +137 -0
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +3 -1
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +189 -54
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
- package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
- package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
- package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.js +107 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
- package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
- package/dist/core/delegation/worker-write-reservation.js +348 -0
- package/dist/core/delegation/worker-write-reservation.js.map +1 -0
- package/dist/core/extension-import-authority.d.ts +6 -0
- package/dist/core/extension-import-authority.d.ts.map +1 -0
- package/dist/core/extension-import-authority.js +10 -0
- package/dist/core/extension-import-authority.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +2 -3
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +14 -5
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/stale-context.d.ts +2 -0
- package/dist/core/extensions/stale-context.d.ts.map +1 -0
- package/dist/core/extensions/stale-context.js +2 -0
- package/dist/core/extensions/stale-context.js.map +1 -0
- package/dist/core/extensions/types.d.ts +8 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +1 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
- package/dist/core/foreground-recovery-controller.js +13 -13
- package/dist/core/foreground-recovery-controller.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts +14 -9
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +47 -75
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +11 -0
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -0
- package/dist/core/goals/compact-goal-context.js +59 -0
- package/dist/core/goals/compact-goal-context.js.map +1 -0
- package/dist/core/goals/goal-acceptance.d.ts.map +1 -1
- package/dist/core/goals/goal-acceptance.js +2 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.d.ts +2 -1
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js +5 -8
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-controller.d.ts +2 -2
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js +42 -11
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.d.ts +4 -29
- package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.js +4 -32
- package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts +8 -18
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +9 -179
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-lifecycle.d.ts +35 -12
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
- package/dist/core/goals/goal-lifecycle.js +98 -13
- package/dist/core/goals/goal-lifecycle.js.map +1 -1
- package/dist/core/goals/goal-record.d.ts +17 -0
- package/dist/core/goals/goal-record.d.ts.map +1 -0
- package/dist/core/goals/goal-record.js +31 -0
- package/dist/core/goals/goal-record.js.map +1 -0
- package/dist/core/goals/goal-session-controller.d.ts +42 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-session-controller.js +128 -0
- package/dist/core/goals/goal-session-controller.js.map +1 -0
- package/dist/core/goals/goal-state.d.ts +45 -25
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +85 -15
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +1 -4
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +49 -34
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +18 -8
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +134 -11
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/human-input-controller.d.ts +47 -0
- package/dist/core/human-input-controller.d.ts.map +1 -0
- package/dist/core/human-input-controller.js +181 -0
- package/dist/core/human-input-controller.js.map +1 -0
- package/dist/core/local-runtime-controller.d.ts +1 -1
- package/dist/core/local-runtime-controller.d.ts.map +1 -1
- package/dist/core/local-runtime-controller.js.map +1 -1
- package/dist/core/model-capability.d.ts +0 -19
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +0 -19
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-registry.d.ts +6 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -5
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +16 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +32 -16
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +1 -1
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.d.ts +1 -1
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/models/model-endpoint.d.ts +3 -0
- package/dist/core/models/model-endpoint.d.ts.map +1 -0
- package/dist/core/models/model-endpoint.js +11 -0
- package/dist/core/models/model-endpoint.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +2 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
- package/dist/core/orchestration/agent-resume.js +7 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -1
- package/dist/core/orchestration/attempt-usage.d.ts +28 -0
- package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
- package/dist/core/orchestration/attempt-usage.js +168 -0
- package/dist/core/orchestration/attempt-usage.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +19 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +128 -28
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +35 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +17 -0
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +81 -3
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +1 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +78 -38
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +81 -41
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/profile-store.d.ts.map +1 -1
- package/dist/core/orchestration/profile-store.js +18 -4
- package/dist/core/orchestration/profile-store.js.map +1 -1
- package/dist/core/orchestration/risk-budget.d.ts +2 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
- package/dist/core/orchestration/risk-budget.js +26 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -1
- package/dist/core/orchestration/task-runtime.d.ts +13 -1
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +127 -16
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -1
- package/dist/core/orchestration/work-state-projection.js +1 -1
- package/dist/core/orchestration/work-state-projection.js.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +75 -23
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.js +167 -14
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +20 -3
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/profile-filter-controller.d.ts +8 -1
- package/dist/core/profile-filter-controller.d.ts.map +1 -1
- package/dist/core/profile-filter-controller.js +23 -5
- package/dist/core/profile-filter-controller.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +18 -29
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +2 -2
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +92 -54
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/request-auth.d.ts +7 -0
- package/dist/core/request-auth.d.ts.map +1 -0
- package/dist/core/request-auth.js +8 -0
- package/dist/core/request-auth.js.map +1 -0
- package/dist/core/research/evidence-bundle.d.ts +20 -0
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +173 -69
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +16 -6
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.d.ts.map +1 -1
- package/dist/core/risk-classifier.js +8 -0
- package/dist/core/risk-classifier.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +22 -3
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +147 -80
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +7 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.d.ts +9 -0
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -0
- package/dist/core/secrets/credential-exposure-guard.js +241 -0
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -0
- package/dist/core/secrets/secret-dotenv.d.ts +27 -0
- package/dist/core/secrets/secret-dotenv.d.ts.map +1 -0
- package/dist/core/secrets/secret-dotenv.js +183 -0
- package/dist/core/secrets/secret-dotenv.js.map +1 -0
- package/dist/core/secrets/secret-vault-format.d.ts +112 -0
- package/dist/core/secrets/secret-vault-format.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault-format.js +397 -0
- package/dist/core/secrets/secret-vault-format.js.map +1 -0
- package/dist/core/secrets/secret-vault.d.ts +72 -0
- package/dist/core/secrets/secret-vault.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault.js +671 -0
- package/dist/core/secrets/secret-vault.js.map +1 -0
- package/dist/core/session-analytics.d.ts +4 -23
- package/dist/core/session-analytics.d.ts.map +1 -1
- package/dist/core/session-analytics.js +39 -69
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-artifact-bundle.d.ts +35 -0
- package/dist/core/session-artifact-bundle.d.ts.map +1 -0
- package/dist/core/session-artifact-bundle.js +61 -0
- package/dist/core/session-artifact-bundle.js.map +1 -0
- package/dist/core/session-role.d.ts +5 -0
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +14 -1
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/session-tree-navigator.d.ts +4 -6
- package/dist/core/session-tree-navigator.d.ts.map +1 -1
- package/dist/core/session-tree-navigator.js +4 -1
- package/dist/core/session-tree-navigator.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +1 -0
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-gate-controller.d.ts.map +1 -1
- package/dist/core/tool-gate-controller.js +8 -2
- package/dist/core/tool-gate-controller.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts +2 -4
- package/dist/core/tool-protocol-controller.d.ts.map +1 -1
- package/dist/core/tool-protocol-controller.js.map +1 -1
- package/dist/core/tool-recovery-stats.d.ts +21 -1
- package/dist/core/tool-recovery-stats.d.ts.map +1 -1
- package/dist/core/tool-recovery-stats.js.map +1 -1
- package/dist/core/tools/bash.d.ts +5 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +59 -5
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +6 -1
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +106 -25
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +9 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +329 -69
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts +1 -8
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +2 -63
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/goal.d.ts +5 -3
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +97 -19
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -0
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +1 -4
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -1
- package/dist/core/tools/orchestration-panel.js +0 -44
- package/dist/core/tools/orchestration-panel.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +11 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +36 -3
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/python.d.ts +2 -0
- package/dist/core/tools/python.d.ts.map +1 -1
- package/dist/core/tools/python.js +3 -1
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +1 -1
- package/dist/core/tools/run-process.d.ts.map +1 -1
- package/dist/core/tools/run-process.js +69 -9
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/search-command-guard.d.ts +14 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -0
- package/dist/core/tools/search-command-guard.js +333 -0
- package/dist/core/tools/search-command-guard.js.map +1 -0
- package/dist/core/tools/secret-store.d.ts +38 -0
- package/dist/core/tools/secret-store.d.ts.map +1 -0
- package/dist/core/tools/secret-store.js +412 -0
- package/dist/core/tools/secret-store.js.map +1 -0
- package/dist/core/tools/shell-command-parser.d.ts +16 -0
- package/dist/core/tools/shell-command-parser.d.ts.map +1 -0
- package/dist/core/tools/shell-command-parser.js +113 -0
- package/dist/core/tools/shell-command-parser.js.map +1 -0
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +12 -5
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +4 -7
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/util/atomic-file.d.ts +6 -2
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +4 -4
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/core/util/bounded-file.d.ts +15 -0
- package/dist/core/util/bounded-file.d.ts.map +1 -0
- package/dist/core/util/bounded-file.js +120 -0
- package/dist/core/util/bounded-file.js.map +1 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
- package/dist/core/util/bounded-jsonl.js +119 -9
- package/dist/core/util/bounded-jsonl.js.map +1 -1
- package/dist/core/util/bounded-value.d.ts +3 -0
- package/dist/core/util/bounded-value.d.ts.map +1 -0
- package/dist/core/util/bounded-value.js +12 -0
- package/dist/core/util/bounded-value.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +2 -0
- package/dist/core/util/value-guards.d.ts.map +1 -1
- package/dist/core/util/value-guards.js +5 -0
- package/dist/core/util/value-guards.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +25 -11
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.d.ts +4 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +60 -1
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts +55 -0
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -0
- package/dist/modes/interactive/components/activity-lane.js +304 -0
- package/dist/modes/interactive/components/activity-lane.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +19 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/expandable-text.d.ts +12 -0
- package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/expandable-text.js +17 -0
- package/dist/modes/interactive/components/expandable-text.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +15 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +30 -21
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +6 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +23 -14
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +27 -44
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +4 -4
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +19 -11
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +53 -20
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +3 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/usage-action-selector.d.ts +16 -0
- package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/usage-action-selector.js +46 -0
- package/dist/modes/interactive/components/usage-action-selector.js.map +1 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +1 -0
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +15 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +27 -19
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/history-reload-math.d.ts +6 -2
- package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
- package/dist/modes/interactive/history-reload-math.js +10 -5
- package/dist/modes/interactive/history-reload-math.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts +74 -0
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-event-controller.js +328 -0
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +20 -25
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +196 -608
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/loaded-resources-view.d.ts +20 -0
- package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -0
- package/dist/modes/interactive/loaded-resources-view.js +147 -0
- package/dist/modes/interactive/loaded-resources-view.js.map +1 -0
- package/dist/modes/interactive/resource-display.d.ts.map +1 -1
- package/dist/modes/interactive/resource-display.js +8 -2
- package/dist/modes/interactive/resource-display.js.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.d.ts +1 -5
- package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.js +0 -5
- package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +10 -6
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +123 -70
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/usage-commands.d.ts +34 -0
- package/dist/modes/interactive/usage-commands.d.ts.map +1 -0
- package/dist/modes/interactive/usage-commands.js +225 -0
- package/dist/modes/interactive/usage-commands.js.map +1 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +5 -3
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- package/docs/UI_POLISH_ORCHESTRATION.md +25 -31
- package/docs/UI_QUALITY_ORCHESTRATION.md +22 -24
- package/docs/providers.md +9 -1
- package/docs/tool-repair.md +3 -0
- package/docs/ui-reference/README.md +6 -6
- package/docs/ui-reference/orchestration-after.txt +14 -7
- package/docs/ui-reference/orchestration-before.txt +12 -6
- package/docs/ui-reference/orchestration-reference.txt +15 -5
- package/docs/usage.md +9 -1
- package/docs/windows.md +4 -2
- 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 +13 -13
- package/package.json +4 -4
|
@@ -1,72 +1,135 @@
|
|
|
1
|
-
import { existsSync, mkdirSync,
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, relative, resolve } from "node:path";
|
|
3
3
|
import { validateToolArguments } from "@caupulican/pi-ai";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
5
|
import { safeRealpathSync } from "../autonomy/path-scope.js";
|
|
6
6
|
import { CapabilityGatewayDeniedError } from "../orchestration/capability-gateway.js";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
import { readBoundedTextFileSync } from "../util/bounded-file.js";
|
|
8
|
+
import { isPlainRecord } from "../util/value-guards.js";
|
|
9
|
+
/** Bounded model-to-filesystem mutation contract. All execution callers pass through this owner. */
|
|
10
|
+
export const MAX_WORKER_ACTIONS = 20;
|
|
11
|
+
export const MAX_WORKER_ACTION_PATH_CHARS = 2_048;
|
|
12
|
+
export const MAX_WORKER_ACTION_TEXT_CHARS = 512 * 1024;
|
|
13
|
+
/** Limits all source/replacement payloads for one atomic worker action batch. */
|
|
14
|
+
export const MAX_WORKER_ACTION_PAYLOAD_CHARS = 512 * 1024;
|
|
15
|
+
/**
|
|
16
|
+
* A structured edit only needs bounded source/replacement text. Limit the target read to 2 MiB:
|
|
17
|
+
* this admits the largest UTF-8 text payload (512 Ki code units at four bytes each)
|
|
18
|
+
* without letting a small edit cause an unbounded repository-file allocation.
|
|
19
|
+
*/
|
|
20
|
+
export const MAX_WORKER_ACTION_EDIT_TARGET_BYTES = 2 * 1024 * 1024;
|
|
9
21
|
const workerActionSchema = Type.Union([
|
|
10
22
|
Type.Object({
|
|
11
23
|
op: Type.Literal("write"),
|
|
12
|
-
path: Type.String({ minLength: 1 }),
|
|
13
|
-
content: Type.String({ maxLength:
|
|
14
|
-
}),
|
|
24
|
+
path: Type.String({ minLength: 1, maxLength: MAX_WORKER_ACTION_PATH_CHARS }),
|
|
25
|
+
content: Type.String({ maxLength: MAX_WORKER_ACTION_TEXT_CHARS }),
|
|
26
|
+
}, { additionalProperties: false }),
|
|
15
27
|
Type.Object({
|
|
16
28
|
op: Type.Literal("edit"),
|
|
17
|
-
path: Type.String({ minLength: 1 }),
|
|
18
|
-
old: Type.String({ minLength: 1 }),
|
|
19
|
-
new: Type.String({ maxLength:
|
|
20
|
-
}),
|
|
29
|
+
path: Type.String({ minLength: 1, maxLength: MAX_WORKER_ACTION_PATH_CHARS }),
|
|
30
|
+
old: Type.String({ minLength: 1, maxLength: MAX_WORKER_ACTION_TEXT_CHARS }),
|
|
31
|
+
new: Type.String({ maxLength: MAX_WORKER_ACTION_TEXT_CHARS }),
|
|
32
|
+
}, { additionalProperties: false }),
|
|
21
33
|
]);
|
|
22
34
|
const workerActionsTool = {
|
|
23
35
|
name: "worker_actions",
|
|
24
36
|
description: "Worker filesystem action list",
|
|
25
|
-
parameters: Type.Object({ actions: Type.Array(workerActionSchema) }),
|
|
37
|
+
parameters: Type.Object({ actions: Type.Array(workerActionSchema, { maxItems: MAX_WORKER_ACTIONS }) }, { additionalProperties: false }),
|
|
26
38
|
};
|
|
39
|
+
function rejectWorkerActions(reasonCode) {
|
|
40
|
+
const messages = {
|
|
41
|
+
worker_actions_invalid_shape: "worker actions must be a strict JSON write/edit action list",
|
|
42
|
+
worker_actions_too_many: `worker actions exceed the ${MAX_WORKER_ACTIONS}-action limit`,
|
|
43
|
+
worker_actions_path_too_long: "worker action path exceeds the allowed limit",
|
|
44
|
+
worker_actions_field_too_large: "worker actions contain a field larger than the allowed limit",
|
|
45
|
+
worker_actions_payload_too_large: "worker actions exceed the aggregate payload limit",
|
|
46
|
+
};
|
|
47
|
+
return { kind: "rejected", reasonCode, message: messages[reasonCode] };
|
|
48
|
+
}
|
|
27
49
|
function validateWorkerActions(raw, validation) {
|
|
28
50
|
try {
|
|
29
51
|
const validated = validateToolArguments(workerActionsTool, { type: "toolCall", id: "worker-actions", name: "worker_actions", arguments: { actions: raw } }, validation).actions;
|
|
30
|
-
return Array.isArray(validated) ? validated :
|
|
52
|
+
return Array.isArray(validated) ? validated : undefined;
|
|
31
53
|
}
|
|
32
54
|
catch {
|
|
33
|
-
return
|
|
55
|
+
return undefined;
|
|
34
56
|
}
|
|
35
57
|
}
|
|
36
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Normalizes every model or direct caller before it can reach the gateway, journal, or filesystem.
|
|
60
|
+
* Any malformed entry rejects the entire batch so a partially malformed request cannot mutate a
|
|
61
|
+
* surprising prefix.
|
|
62
|
+
*/
|
|
63
|
+
function normalizeWorkerActions(raw) {
|
|
64
|
+
if (raw.length > MAX_WORKER_ACTIONS)
|
|
65
|
+
return rejectWorkerActions("worker_actions_too_many");
|
|
37
66
|
const actions = [];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
let payloadChars = 0;
|
|
68
|
+
for (const entry of raw) {
|
|
69
|
+
if (!isPlainRecord(entry))
|
|
70
|
+
return rejectWorkerActions("worker_actions_invalid_shape");
|
|
71
|
+
const descriptors = Object.getOwnPropertyDescriptors(entry);
|
|
72
|
+
const op = descriptors.op?.value;
|
|
73
|
+
if (op !== "write" && op !== "edit")
|
|
74
|
+
return rejectWorkerActions("worker_actions_invalid_shape");
|
|
75
|
+
const expectedKeys = op === "write" ? ["op", "path", "content"] : ["op", "path", "old", "new"];
|
|
76
|
+
if (Reflect.ownKeys(entry).length !== expectedKeys.length ||
|
|
77
|
+
!expectedKeys.every((key) => {
|
|
78
|
+
const descriptor = descriptors[key];
|
|
79
|
+
return descriptor?.enumerable === true && "value" in descriptor;
|
|
80
|
+
}))
|
|
81
|
+
return rejectWorkerActions("worker_actions_invalid_shape");
|
|
82
|
+
const actionPath = descriptors.path?.value;
|
|
83
|
+
if (typeof actionPath !== "string" || actionPath.length === 0)
|
|
84
|
+
return rejectWorkerActions("worker_actions_invalid_shape");
|
|
85
|
+
if (actionPath.length > MAX_WORKER_ACTION_PATH_CHARS)
|
|
86
|
+
return rejectWorkerActions("worker_actions_path_too_long");
|
|
87
|
+
if (op === "write") {
|
|
88
|
+
const content = descriptors.content?.value;
|
|
89
|
+
if (typeof content !== "string")
|
|
90
|
+
return rejectWorkerActions("worker_actions_invalid_shape");
|
|
91
|
+
if (content.length > MAX_WORKER_ACTION_TEXT_CHARS)
|
|
92
|
+
return rejectWorkerActions("worker_actions_field_too_large");
|
|
93
|
+
if (payloadChars + content.length > MAX_WORKER_ACTION_PAYLOAD_CHARS)
|
|
94
|
+
return rejectWorkerActions("worker_actions_payload_too_large");
|
|
95
|
+
payloadChars += content.length;
|
|
96
|
+
actions.push({ op: "write", path: actionPath, content });
|
|
50
97
|
}
|
|
51
98
|
else {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (typeof
|
|
55
|
-
|
|
56
|
-
|
|
99
|
+
const old = descriptors.old?.value;
|
|
100
|
+
const replacement = descriptors.new?.value;
|
|
101
|
+
if (typeof old !== "string" || old.length === 0 || typeof replacement !== "string")
|
|
102
|
+
return rejectWorkerActions("worker_actions_invalid_shape");
|
|
103
|
+
if (old.length > MAX_WORKER_ACTION_TEXT_CHARS || replacement.length > MAX_WORKER_ACTION_TEXT_CHARS)
|
|
104
|
+
return rejectWorkerActions("worker_actions_field_too_large");
|
|
105
|
+
if (payloadChars + old.length + replacement.length > MAX_WORKER_ACTION_PAYLOAD_CHARS)
|
|
106
|
+
return rejectWorkerActions("worker_actions_payload_too_large");
|
|
107
|
+
payloadChars += old.length + replacement.length;
|
|
108
|
+
actions.push({ op: "edit", path: actionPath, old, new: replacement });
|
|
57
109
|
}
|
|
58
110
|
}
|
|
59
|
-
return actions;
|
|
111
|
+
return { kind: "accepted", actions };
|
|
60
112
|
}
|
|
61
113
|
export function parseWorkerActions(raw, validation) {
|
|
62
|
-
if (
|
|
63
|
-
return
|
|
64
|
-
|
|
114
|
+
if (raw === undefined)
|
|
115
|
+
return { kind: "accepted", actions: [] };
|
|
116
|
+
const candidate = Array.isArray(raw) ? normalizeWorkerActions(raw) : undefined;
|
|
117
|
+
if (candidate?.kind === "rejected")
|
|
118
|
+
return candidate;
|
|
119
|
+
const validated = validateWorkerActions(candidate?.actions ?? raw, validation);
|
|
120
|
+
if (!validated)
|
|
121
|
+
return rejectWorkerActions("worker_actions_invalid_shape");
|
|
122
|
+
return normalizeWorkerActions(validated);
|
|
65
123
|
}
|
|
66
124
|
export function applyWorkerActions(args) {
|
|
67
|
-
const report = { changedFiles: [], refused: [], failed: [] };
|
|
125
|
+
const report = { changedFiles: [], refused: [], failed: [], inspectionRequired: [] };
|
|
68
126
|
const manifests = new Map(args.toolManifests.map((manifest) => [manifest.toolName, manifest]));
|
|
69
|
-
|
|
127
|
+
const parsedActions = parseWorkerActions(args.actions);
|
|
128
|
+
if (parsedActions.kind === "rejected") {
|
|
129
|
+
report.failed.push({ path: "<worker_actions>", reason: `${parsedActions.reasonCode}: ${parsedActions.message}` });
|
|
130
|
+
return report;
|
|
131
|
+
}
|
|
132
|
+
for (const [index, action] of parsedActions.actions.entries()) {
|
|
70
133
|
const manifest = manifests.get(action.op);
|
|
71
134
|
if (!manifest) {
|
|
72
135
|
report.refused.push({
|
|
@@ -85,30 +148,92 @@ export function applyWorkerActions(args) {
|
|
|
85
148
|
}
|
|
86
149
|
throw error;
|
|
87
150
|
}
|
|
88
|
-
|
|
89
|
-
|
|
151
|
+
let target;
|
|
152
|
+
let relativePath;
|
|
153
|
+
try {
|
|
154
|
+
target = safeRealpathSync(resolve(args.cwd, action.path));
|
|
155
|
+
relativePath = relative(args.cwd, target).replaceAll("\\", "/");
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
report.failed.push({ path: action.path, reason: "target path could not be resolved" });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
let journalPermit;
|
|
162
|
+
if (args.actionJournal) {
|
|
163
|
+
try {
|
|
164
|
+
journalPermit = args.actionJournal.begin({ index, action, targetPath: target });
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
report.failed.push({ path: action.path, reason: "mutation journal intent could not be persisted" });
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (journalPermit.kind === "inspection_required") {
|
|
171
|
+
report.inspectionRequired.push({
|
|
172
|
+
path: action.path,
|
|
173
|
+
actionId: journalPermit.actionId,
|
|
174
|
+
state: journalPermit.state,
|
|
175
|
+
reasonCode: journalPermit.reasonCode,
|
|
176
|
+
...(journalPermit.evidencePointer ? { evidencePointer: journalPermit.evidencePointer } : {}),
|
|
177
|
+
});
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
let mutationStarted = false;
|
|
90
182
|
try {
|
|
91
183
|
if (action.op === "write") {
|
|
184
|
+
// mkdir may create one or more parents before an error or process interruption. Once it
|
|
185
|
+
// is invoked the durable intent is conservatively unknown, never replayed as a precondition failure.
|
|
186
|
+
mutationStarted = true;
|
|
92
187
|
mkdirSync(dirname(target), { recursive: true });
|
|
93
188
|
writeFileSync(target, action.content ?? "", "utf-8");
|
|
94
189
|
}
|
|
95
190
|
else {
|
|
96
191
|
if (!existsSync(target)) {
|
|
97
|
-
|
|
98
|
-
continue;
|
|
192
|
+
throw new Error("worker_action_file_missing");
|
|
99
193
|
}
|
|
100
|
-
const current =
|
|
194
|
+
const current = readBoundedTextFileSync(target, MAX_WORKER_ACTION_EDIT_TARGET_BYTES, "Worker action edit target");
|
|
101
195
|
if (!action.old || !current.includes(action.old)) {
|
|
102
|
-
|
|
103
|
-
continue;
|
|
196
|
+
throw new Error("worker_action_old_text_missing");
|
|
104
197
|
}
|
|
198
|
+
mutationStarted = true;
|
|
105
199
|
writeFileSync(target, current.replace(action.old, () => action.new ?? ""), "utf-8");
|
|
106
200
|
}
|
|
107
201
|
if (!report.changedFiles.includes(relativePath))
|
|
108
202
|
report.changedFiles.push(relativePath);
|
|
203
|
+
journalPermit?.kind === "execute" &&
|
|
204
|
+
args.actionJournal?.recordSucceeded(journalPermit, {
|
|
205
|
+
evidencePointer: `workspace:file:${target}`,
|
|
206
|
+
});
|
|
109
207
|
}
|
|
110
|
-
catch
|
|
111
|
-
|
|
208
|
+
catch {
|
|
209
|
+
if (mutationStarted && journalPermit?.kind === "execute") {
|
|
210
|
+
report.inspectionRequired.push({
|
|
211
|
+
path: action.path,
|
|
212
|
+
actionId: journalPermit.actionId,
|
|
213
|
+
state: "unknown",
|
|
214
|
+
reasonCode: "worker_action_outcome_unknown",
|
|
215
|
+
evidencePointer: `workspace:file:${target}`,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
if (journalPermit?.kind === "execute") {
|
|
220
|
+
try {
|
|
221
|
+
args.actionJournal?.recordFailed(journalPermit, "worker_action_precondition_failed", {
|
|
222
|
+
evidencePointer: `workspace:file:${target}`,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
report.inspectionRequired.push({
|
|
227
|
+
path: action.path,
|
|
228
|
+
actionId: journalPermit.actionId,
|
|
229
|
+
state: "unknown",
|
|
230
|
+
reasonCode: "worker_action_outcome_unknown",
|
|
231
|
+
evidencePointer: `workspace:file:${target}`,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
report.failed.push({ path: action.path, reason: "action precondition or filesystem operation failed" });
|
|
236
|
+
}
|
|
112
237
|
}
|
|
113
238
|
}
|
|
114
239
|
return report;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-actions.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAA0B,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAuB9G,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,CAAC;AAErC,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC;QACX,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACzB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;QACnC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;KACtD,CAAC;IACF,IAAI,CAAC,MAAM,CAAC;QACX,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACxB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;QACnC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;QAClC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,iB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C,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC3G,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, relative, resolve } from \"node:path\";\nimport type { Tool, ToolArgumentValidationOptions } from \"@caupulican/pi-ai\";\nimport { validateToolArguments } from \"@caupulican/pi-ai\";\nimport { Type } from \"typebox\";\nimport { safeRealpathSync } from \"../autonomy/path-scope.ts\";\nimport { type CapabilityGateway, CapabilityGatewayDeniedError } from \"../orchestration/capability-gateway.ts\";\nimport type { ToolCapabilityManifest } from \"../orchestration/contracts.ts\";\n\n/**\n * Code-writing workers (G2): the worker MODEL never touches the filesystem — it emits strict-JSON\n * actions, and this RUNNER-side module applies them deterministically through the compiled\n * execution grant. That keeps the structural-contract philosophy (a local model without\n * tool-calling templates can still write code) and makes enforcement execution-time, not\n * validation-only: an out-of-scope action is REFUSED with a reason, never silently dropped, and\n * refusals surface as blockers on the result.\n */\n\nexport interface WorkerAction {\n\top: \"write\" | \"edit\";\n\tpath: string;\n\t/** write: full file content. */\n\tcontent?: string;\n\t/** edit: exact string to replace (must occur in the file). */\n\told?: string;\n\t/** edit: replacement text. */\n\tnew?: string;\n}\n\nconst MAX_ACTIONS = 20;\nconst MAX_CONTENT_CHARS = 512 * 1024;\n\nconst workerActionSchema = Type.Union([\n\tType.Object({\n\t\top: Type.Literal(\"write\"),\n\t\tpath: Type.String({ minLength: 1 }),\n\t\tcontent: Type.String({ maxLength: MAX_CONTENT_CHARS }),\n\t}),\n\tType.Object({\n\t\top: Type.Literal(\"edit\"),\n\t\tpath: Type.String({ minLength: 1 }),\n\t\told: Type.String({ minLength: 1 }),\n\t\tnew: Type.String({ maxLength: MAX_CONTENT_CHARS }),\n\t}),\n]);\n\nconst workerActionsTool: Tool = {\n\tname: \"worker_actions\",\n\tdescription: \"Worker filesystem action list\",\n\tparameters: Type.Object({ actions: Type.Array(workerActionSchema) }),\n};\n\nfunction validateWorkerActions(raw: unknown, validation?: ToolArgumentValidationOptions): unknown[] {\n\ttry {\n\t\tconst validated = validateToolArguments(\n\t\t\tworkerActionsTool,\n\t\t\t{ type: \"toolCall\", id: \"worker-actions\", name: \"worker_actions\", arguments: { actions: raw } },\n\t\t\tvalidation,\n\t\t).actions;\n\t\treturn Array.isArray(validated) ? validated : [];\n\t} catch {\n\t\treturn [];\n\t}\n}\n\nfunction sanitizeWorkerActions(raw: readonly unknown[]): WorkerAction[] {\n\tconst actions: WorkerAction[] = [];\n\tfor (const entry of raw.slice(0, MAX_ACTIONS)) {\n\t\tif (!entry || typeof entry !== \"object\") continue;\n\t\tconst record = entry as Record<string, unknown>;\n\t\tif (record.op !== \"write\" && record.op !== \"edit\") continue;\n\t\tif (typeof record.path !== \"string\" || record.path.length === 0) continue;\n\t\tif (record.op === \"write\") {\n\t\t\tif (typeof record.content !== \"string\" || record.content.length > MAX_CONTENT_CHARS) continue;\n\t\t\tactions.push({ op: \"write\", path: record.path, content: record.content });\n\t\t} else {\n\t\t\tif (typeof record.old !== \"string\" || record.old.length === 0) continue;\n\t\t\tif (typeof record.new !== \"string\" || record.new.length > MAX_CONTENT_CHARS) continue;\n\t\t\tactions.push({ op: \"edit\", path: record.path, old: record.old, new: record.new });\n\t\t}\n\t}\n\treturn actions;\n}\n\nexport function parseWorkerActions(raw: unknown, validation?: ToolArgumentValidationOptions): WorkerAction[] {\n\tif (Array.isArray(raw)) return sanitizeWorkerActions(validateWorkerActions(sanitizeWorkerActions(raw), validation));\n\treturn sanitizeWorkerActions(validateWorkerActions(raw, validation));\n}\n\nexport interface AppliedActionsReport {\n\t/** Repo-relative paths actually changed. */\n\tchangedFiles: string[];\n\t/** Grant refusals (execution-time enforcement) — surfaced, never silent. */\n\trefused: Array<{ path: string; reason: string }>;\n\t/** Actions that were in scope but could not be applied (missing file, old-text not found). */\n\tfailed: Array<{ path: string; reason: string }>;\n}\n\nexport function applyWorkerActions(args: {\n\tactions: readonly WorkerAction[];\n\tgateway: CapabilityGateway;\n\ttoolManifests: readonly ToolCapabilityManifest[];\n\tcwd: string;\n}): AppliedActionsReport {\n\tconst report: AppliedActionsReport = { changedFiles: [], refused: [], failed: [] };\n\tconst manifests = new Map(args.toolManifests.map((manifest) => [manifest.toolName, manifest]));\n\tfor (const action of args.actions) {\n\t\tconst manifest = manifests.get(action.op);\n\t\tif (!manifest) {\n\t\t\treport.refused.push({\n\t\t\t\tpath: action.path,\n\t\t\t\treason: `${action.op} is not present in the compiled tool manifest`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\targs.gateway.authorizeToolCall(manifest, action.op, { path: action.path });\n\t\t} catch (error) {\n\t\t\tif (error instanceof CapabilityGatewayDeniedError) {\n\t\t\t\treport.refused.push({ path: action.path, reason: `${error.reasonCode}: ${error.message}` });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tconst target = safeRealpathSync(resolve(args.cwd, action.path));\n\t\tconst relativePath = relative(args.cwd, target).replaceAll(\"\\\\\", \"/\");\n\t\ttry {\n\t\t\tif (action.op === \"write\") {\n\t\t\t\tmkdirSync(dirname(target), { recursive: true });\n\t\t\t\twriteFileSync(target, action.content ?? \"\", \"utf-8\");\n\t\t\t} else {\n\t\t\t\tif (!existsSync(target)) {\n\t\t\t\t\treport.failed.push({ path: action.path, reason: \"file does not exist\" });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst current = readFileSync(target, \"utf-8\");\n\t\t\t\tif (!action.old || !current.includes(action.old)) {\n\t\t\t\t\treport.failed.push({ path: action.path, reason: \"edit old-text not found in file\" });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\twriteFileSync(\n\t\t\t\t\ttarget,\n\t\t\t\t\tcurrent.replace(action.old, () => action.new ?? \"\"),\n\t\t\t\t\t\"utf-8\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!report.changedFiles.includes(relativePath)) report.changedFiles.push(relativePath);\n\t\t} catch (error) {\n\t\t\treport.failed.push({ path: action.path, reason: error instanceof Error ? error.message : String(error) });\n\t\t}\n\t}\n\treturn report;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-actions.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAA0B,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAE9G,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AA4CxD,oGAAoG;AACpG,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAClD,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,GAAG,IAAI,CAAC;AACvD,iFAAiF;AACjF,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,GAAG,IAAI,CAAC;AAC1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAEnE,MAAM,kBAAkB,GAAG,IAAI,CAAC,KAAK,CAAC;IACrC,IAAI,CAAC,MAAM,CACV;QACC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QACzB,IAAI,EAAE,IA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I;4BACjB,QAAQ,EAAE,aAAa,CAAC,QAAQ;4BAChC,KAAK,EAAE,SAAS;4BAChB,UAAU,EAAE,+BAA+B;4BAC3C,eAAe,EAAE,kBAAkB,MAAM,EAAE;yBAC3C,CAAC,CAAC;oBACJ,CAAC;gBACF,CAAC;gBACD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,oDAAoD,EAAE,CAAC,CAAC;YACzG,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, relative, resolve } from \"node:path\";\nimport type { Tool, ToolArgumentValidationOptions } from \"@caupulican/pi-ai\";\nimport { validateToolArguments } from \"@caupulican/pi-ai\";\nimport { Type } from \"typebox\";\nimport { safeRealpathSync } from \"../autonomy/path-scope.ts\";\nimport { type CapabilityGateway, CapabilityGatewayDeniedError } from \"../orchestration/capability-gateway.ts\";\nimport type { ToolCapabilityManifest } from \"../orchestration/contracts.ts\";\nimport { readBoundedTextFileSync } from \"../util/bounded-file.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\nimport type { WorkerActionInspectionRequired, WorkerActionJournal } from \"./worker-action-journal.ts\";\n\n/**\n * Code-writing workers (G2): the worker MODEL never touches the filesystem — it emits strict-JSON\n * actions, and this RUNNER-side module applies them deterministically through the compiled\n * execution grant. That keeps the structural-contract philosophy (a local model without\n * tool-calling templates can still write code) and makes enforcement execution-time, not\n * validation-only: an out-of-scope action is REFUSED with a reason, never silently dropped, and\n * refusals surface as blockers on the result.\n */\n\nexport interface WorkerAction {\n\top: \"write\" | \"edit\";\n\tpath: string;\n\t/** write: full file content. */\n\tcontent?: string;\n\t/** edit: exact string to replace (must occur in the file). */\n\told?: string;\n\t/** edit: replacement text. */\n\tnew?: string;\n}\n\nexport type WorkerActionRejectionCode =\n\t| \"worker_actions_invalid_shape\"\n\t| \"worker_actions_too_many\"\n\t| \"worker_actions_path_too_long\"\n\t| \"worker_actions_field_too_large\"\n\t| \"worker_actions_payload_too_large\";\n\nexport interface AcceptedWorkerActions {\n\tkind: \"accepted\";\n\tactions: WorkerAction[];\n}\n\nexport interface RejectedWorkerActions {\n\tkind: \"rejected\";\n\treasonCode: WorkerActionRejectionCode;\n\tmessage: string;\n}\n\n/** The sole structured-action admission result used before execution or worker-result projection. */\nexport type WorkerActionParseOutcome = AcceptedWorkerActions | RejectedWorkerActions;\n\n/** Bounded model-to-filesystem mutation contract. All execution callers pass through this owner. */\nexport const MAX_WORKER_ACTIONS = 20;\nexport const MAX_WORKER_ACTION_PATH_CHARS = 2_048;\nexport const MAX_WORKER_ACTION_TEXT_CHARS = 512 * 1024;\n/** Limits all source/replacement payloads for one atomic worker action batch. */\nexport const MAX_WORKER_ACTION_PAYLOAD_CHARS = 512 * 1024;\n/**\n * A structured edit only needs bounded source/replacement text. Limit the target read to 2 MiB:\n * this admits the largest UTF-8 text payload (512 Ki code units at four bytes each)\n * without letting a small edit cause an unbounded repository-file allocation.\n */\nexport const MAX_WORKER_ACTION_EDIT_TARGET_BYTES = 2 * 1024 * 1024;\n\nconst workerActionSchema = Type.Union([\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"write\"),\n\t\t\tpath: Type.String({ minLength: 1, maxLength: MAX_WORKER_ACTION_PATH_CHARS }),\n\t\t\tcontent: Type.String({ maxLength: MAX_WORKER_ACTION_TEXT_CHARS }),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n\tType.Object(\n\t\t{\n\t\t\top: Type.Literal(\"edit\"),\n\t\t\tpath: Type.String({ minLength: 1, maxLength: MAX_WORKER_ACTION_PATH_CHARS }),\n\t\t\told: Type.String({ minLength: 1, maxLength: MAX_WORKER_ACTION_TEXT_CHARS }),\n\t\t\tnew: Type.String({ maxLength: MAX_WORKER_ACTION_TEXT_CHARS }),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n]);\n\nconst workerActionsTool: Tool = {\n\tname: \"worker_actions\",\n\tdescription: \"Worker filesystem action list\",\n\tparameters: Type.Object(\n\t\t{ actions: Type.Array(workerActionSchema, { maxItems: MAX_WORKER_ACTIONS }) },\n\t\t{ additionalProperties: false },\n\t),\n};\n\nfunction rejectWorkerActions(reasonCode: WorkerActionRejectionCode): RejectedWorkerActions {\n\tconst messages: Record<WorkerActionRejectionCode, string> = {\n\t\tworker_actions_invalid_shape: \"worker actions must be a strict JSON write/edit action list\",\n\t\tworker_actions_too_many: `worker actions exceed the ${MAX_WORKER_ACTIONS}-action limit`,\n\t\tworker_actions_path_too_long: \"worker action path exceeds the allowed limit\",\n\t\tworker_actions_field_too_large: \"worker actions contain a field larger than the allowed limit\",\n\t\tworker_actions_payload_too_large: \"worker actions exceed the aggregate payload limit\",\n\t};\n\treturn { kind: \"rejected\", reasonCode, message: messages[reasonCode] };\n}\n\nfunction validateWorkerActions(\n\traw: unknown,\n\tvalidation?: ToolArgumentValidationOptions,\n): readonly unknown[] | undefined {\n\ttry {\n\t\tconst validated = validateToolArguments(\n\t\t\tworkerActionsTool,\n\t\t\t{ type: \"toolCall\", id: \"worker-actions\", name: \"worker_actions\", arguments: { actions: raw } },\n\t\t\tvalidation,\n\t\t).actions;\n\t\treturn Array.isArray(validated) ? validated : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Normalizes every model or direct caller before it can reach the gateway, journal, or filesystem.\n * Any malformed entry rejects the entire batch so a partially malformed request cannot mutate a\n * surprising prefix.\n */\nfunction normalizeWorkerActions(raw: readonly unknown[]): WorkerActionParseOutcome {\n\tif (raw.length > MAX_WORKER_ACTIONS) return rejectWorkerActions(\"worker_actions_too_many\");\n\tconst actions: WorkerAction[] = [];\n\tlet payloadChars = 0;\n\tfor (const entry of raw) {\n\t\tif (!isPlainRecord(entry)) return rejectWorkerActions(\"worker_actions_invalid_shape\");\n\t\tconst descriptors = Object.getOwnPropertyDescriptors(entry);\n\t\tconst op = descriptors.op?.value;\n\t\tif (op !== \"write\" && op !== \"edit\") return rejectWorkerActions(\"worker_actions_invalid_shape\");\n\t\tconst expectedKeys = op === \"write\" ? [\"op\", \"path\", \"content\"] : [\"op\", \"path\", \"old\", \"new\"];\n\t\tif (\n\t\t\tReflect.ownKeys(entry).length !== expectedKeys.length ||\n\t\t\t!expectedKeys.every((key) => {\n\t\t\t\tconst descriptor = descriptors[key];\n\t\t\t\treturn descriptor?.enumerable === true && \"value\" in descriptor;\n\t\t\t})\n\t\t)\n\t\t\treturn rejectWorkerActions(\"worker_actions_invalid_shape\");\n\t\tconst actionPath = descriptors.path?.value;\n\t\tif (typeof actionPath !== \"string\" || actionPath.length === 0)\n\t\t\treturn rejectWorkerActions(\"worker_actions_invalid_shape\");\n\t\tif (actionPath.length > MAX_WORKER_ACTION_PATH_CHARS) return rejectWorkerActions(\"worker_actions_path_too_long\");\n\t\tif (op === \"write\") {\n\t\t\tconst content = descriptors.content?.value;\n\t\t\tif (typeof content !== \"string\") return rejectWorkerActions(\"worker_actions_invalid_shape\");\n\t\t\tif (content.length > MAX_WORKER_ACTION_TEXT_CHARS)\n\t\t\t\treturn rejectWorkerActions(\"worker_actions_field_too_large\");\n\t\t\tif (payloadChars + content.length > MAX_WORKER_ACTION_PAYLOAD_CHARS)\n\t\t\t\treturn rejectWorkerActions(\"worker_actions_payload_too_large\");\n\t\t\tpayloadChars += content.length;\n\t\t\tactions.push({ op: \"write\", path: actionPath, content });\n\t\t} else {\n\t\t\tconst old = descriptors.old?.value;\n\t\t\tconst replacement = descriptors.new?.value;\n\t\t\tif (typeof old !== \"string\" || old.length === 0 || typeof replacement !== \"string\")\n\t\t\t\treturn rejectWorkerActions(\"worker_actions_invalid_shape\");\n\t\t\tif (old.length > MAX_WORKER_ACTION_TEXT_CHARS || replacement.length > MAX_WORKER_ACTION_TEXT_CHARS)\n\t\t\t\treturn rejectWorkerActions(\"worker_actions_field_too_large\");\n\t\t\tif (payloadChars + old.length + replacement.length > MAX_WORKER_ACTION_PAYLOAD_CHARS)\n\t\t\t\treturn rejectWorkerActions(\"worker_actions_payload_too_large\");\n\t\t\tpayloadChars += old.length + replacement.length;\n\t\t\tactions.push({ op: \"edit\", path: actionPath, old, new: replacement });\n\t\t}\n\t}\n\treturn { kind: \"accepted\", actions };\n}\n\nexport function parseWorkerActions(raw: unknown, validation?: ToolArgumentValidationOptions): WorkerActionParseOutcome {\n\tif (raw === undefined) return { kind: \"accepted\", actions: [] };\n\tconst candidate = Array.isArray(raw) ? normalizeWorkerActions(raw) : undefined;\n\tif (candidate?.kind === \"rejected\") return candidate;\n\tconst validated = validateWorkerActions(candidate?.actions ?? raw, validation);\n\tif (!validated) return rejectWorkerActions(\"worker_actions_invalid_shape\");\n\treturn normalizeWorkerActions(validated);\n}\n\nexport interface AppliedActionsReport {\n\t/** Repo-relative paths actually changed. */\n\tchangedFiles: string[];\n\t/** Grant refusals (execution-time enforcement) — surfaced, never silent. */\n\trefused: Array<{ path: string; reason: string }>;\n\t/** Actions that were in scope but could not be applied (missing file, old-text not found). */\n\tfailed: Array<{ path: string; reason: string }>;\n\t/** Durable replay blocks. The parent must inspect workspace/evidence instead of re-executing. */\n\tinspectionRequired: Array<{\n\t\tpath: string;\n\t\tactionId: string;\n\t\tstate: WorkerActionInspectionRequired[\"state\"];\n\t\treasonCode: string;\n\t\tevidencePointer?: string;\n\t}>;\n}\n\nexport function applyWorkerActions(args: {\n\tactions: readonly WorkerAction[];\n\tgateway: CapabilityGateway;\n\ttoolManifests: readonly ToolCapabilityManifest[];\n\tcwd: string;\n\t/** Optional durable mutation journal for one fenced worker attempt. */\n\tactionJournal?: WorkerActionJournal;\n}): AppliedActionsReport {\n\tconst report: AppliedActionsReport = { changedFiles: [], refused: [], failed: [], inspectionRequired: [] };\n\tconst manifests = new Map(args.toolManifests.map((manifest) => [manifest.toolName, manifest]));\n\tconst parsedActions = parseWorkerActions(args.actions);\n\tif (parsedActions.kind === \"rejected\") {\n\t\treport.failed.push({ path: \"<worker_actions>\", reason: `${parsedActions.reasonCode}: ${parsedActions.message}` });\n\t\treturn report;\n\t}\n\tfor (const [index, action] of parsedActions.actions.entries()) {\n\t\tconst manifest = manifests.get(action.op);\n\t\tif (!manifest) {\n\t\t\treport.refused.push({\n\t\t\t\tpath: action.path,\n\t\t\t\treason: `${action.op} is not present in the compiled tool manifest`,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\targs.gateway.authorizeToolCall(manifest, action.op, { path: action.path });\n\t\t} catch (error) {\n\t\t\tif (error instanceof CapabilityGatewayDeniedError) {\n\t\t\t\treport.refused.push({ path: action.path, reason: `${error.reasonCode}: ${error.message}` });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tlet target: string;\n\t\tlet relativePath: string;\n\t\ttry {\n\t\t\ttarget = safeRealpathSync(resolve(args.cwd, action.path));\n\t\t\trelativePath = relative(args.cwd, target).replaceAll(\"\\\\\", \"/\");\n\t\t} catch {\n\t\t\treport.failed.push({ path: action.path, reason: \"target path could not be resolved\" });\n\t\t\tcontinue;\n\t\t}\n\t\tlet journalPermit: ReturnType<WorkerActionJournal[\"begin\"]> | undefined;\n\t\tif (args.actionJournal) {\n\t\t\ttry {\n\t\t\t\tjournalPermit = args.actionJournal.begin({ index, action, targetPath: target });\n\t\t\t} catch {\n\t\t\t\treport.failed.push({ path: action.path, reason: \"mutation journal intent could not be persisted\" });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (journalPermit.kind === \"inspection_required\") {\n\t\t\t\treport.inspectionRequired.push({\n\t\t\t\t\tpath: action.path,\n\t\t\t\t\tactionId: journalPermit.actionId,\n\t\t\t\t\tstate: journalPermit.state,\n\t\t\t\t\treasonCode: journalPermit.reasonCode,\n\t\t\t\t\t...(journalPermit.evidencePointer ? { evidencePointer: journalPermit.evidencePointer } : {}),\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tlet mutationStarted = false;\n\t\ttry {\n\t\t\tif (action.op === \"write\") {\n\t\t\t\t// mkdir may create one or more parents before an error or process interruption. Once it\n\t\t\t\t// is invoked the durable intent is conservatively unknown, never replayed as a precondition failure.\n\t\t\t\tmutationStarted = true;\n\t\t\t\tmkdirSync(dirname(target), { recursive: true });\n\t\t\t\twriteFileSync(target, action.content ?? \"\", \"utf-8\");\n\t\t\t} else {\n\t\t\t\tif (!existsSync(target)) {\n\t\t\t\t\tthrow new Error(\"worker_action_file_missing\");\n\t\t\t\t}\n\t\t\t\tconst current = readBoundedTextFileSync(\n\t\t\t\t\ttarget,\n\t\t\t\t\tMAX_WORKER_ACTION_EDIT_TARGET_BYTES,\n\t\t\t\t\t\"Worker action edit target\",\n\t\t\t\t);\n\t\t\t\tif (!action.old || !current.includes(action.old)) {\n\t\t\t\t\tthrow new Error(\"worker_action_old_text_missing\");\n\t\t\t\t}\n\t\t\t\tmutationStarted = true;\n\t\t\t\twriteFileSync(\n\t\t\t\t\ttarget,\n\t\t\t\t\tcurrent.replace(action.old, () => action.new ?? \"\"),\n\t\t\t\t\t\"utf-8\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!report.changedFiles.includes(relativePath)) report.changedFiles.push(relativePath);\n\t\t\tjournalPermit?.kind === \"execute\" &&\n\t\t\t\targs.actionJournal?.recordSucceeded(journalPermit, {\n\t\t\t\t\tevidencePointer: `workspace:file:${target}`,\n\t\t\t\t});\n\t\t} catch {\n\t\t\tif (mutationStarted && journalPermit?.kind === \"execute\") {\n\t\t\t\treport.inspectionRequired.push({\n\t\t\t\t\tpath: action.path,\n\t\t\t\t\tactionId: journalPermit.actionId,\n\t\t\t\t\tstate: \"unknown\",\n\t\t\t\t\treasonCode: \"worker_action_outcome_unknown\",\n\t\t\t\t\tevidencePointer: `workspace:file:${target}`,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tif (journalPermit?.kind === \"execute\") {\n\t\t\t\t\ttry {\n\t\t\t\t\t\targs.actionJournal?.recordFailed(journalPermit, \"worker_action_precondition_failed\", {\n\t\t\t\t\t\t\tevidencePointer: `workspace:file:${target}`,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch {\n\t\t\t\t\t\treport.inspectionRequired.push({\n\t\t\t\t\t\t\tpath: action.path,\n\t\t\t\t\t\t\tactionId: journalPermit.actionId,\n\t\t\t\t\t\t\tstate: \"unknown\",\n\t\t\t\t\t\t\treasonCode: \"worker_action_outcome_unknown\",\n\t\t\t\t\t\t\tevidencePointer: `workspace:file:${target}`,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treport.failed.push({ path: action.path, reason: \"action precondition or filesystem operation failed\" });\n\t\t\t}\n\t\t}\n\t}\n\treturn report;\n}\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { AgentMessage } from "@caupulican/pi-agent-core";
|
|
2
|
+
import type { WorkerDelegationRunOutcome } from "../agent-session-contracts.ts";
|
|
3
|
+
import type { LaneRecord } from "../autonomy/lane-tracker.ts";
|
|
4
|
+
import type { AttemptRuntimeState } from "../orchestration/task-runtime.ts";
|
|
5
|
+
import { type WorkerAgentControlPort } from "./worker-agent-control.ts";
|
|
6
|
+
import type { WorkerConversation } from "./worker-conversation-store.ts";
|
|
7
|
+
import type { WorkerDelegationRequest } from "./worker-delegation-request.ts";
|
|
8
|
+
import type { WorkerDispatchScheduler } from "./worker-dispatch-scheduler.ts";
|
|
9
|
+
import type { WorkerLifecycle } from "./worker-lifecycle.ts";
|
|
10
|
+
export interface WorkerAgentControlCoordinatorOptions {
|
|
11
|
+
agentDir: string;
|
|
12
|
+
parentSessionId: string;
|
|
13
|
+
processOwnerId: string;
|
|
14
|
+
isControlAvailable(): boolean;
|
|
15
|
+
getLifecycle(): WorkerLifecycle;
|
|
16
|
+
recoveredRequest(attempt: AttemptRuntimeState): WorkerDelegationRequest;
|
|
17
|
+
run(request: WorkerDelegationRequest, record: LaneRecord): Promise<WorkerDelegationRunOutcome>;
|
|
18
|
+
scheduler: Pick<WorkerDispatchScheduler, "enqueue" | "track" | "drain">;
|
|
19
|
+
statusChanged(): void;
|
|
20
|
+
abortLane(laneId: string, reasonCode: string): void;
|
|
21
|
+
cancelLane(laneId: string, reasonCode: string): LaneRecord | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Sole owner of model-facing logical-agent controls and their durable inboxes.
|
|
25
|
+
*
|
|
26
|
+
* It deliberately owns no worker execution policy, provider loop, or terminal persistence. Those
|
|
27
|
+
* controller-owned callbacks keep this narrow port from becoming a second lifecycle authority.
|
|
28
|
+
*/
|
|
29
|
+
export declare class WorkerAgentControlCoordinator implements WorkerAgentControlPort {
|
|
30
|
+
private readonly options;
|
|
31
|
+
private readonly mailboxes;
|
|
32
|
+
private readonly stateListeners;
|
|
33
|
+
constructor(options: WorkerAgentControlCoordinatorOptions);
|
|
34
|
+
getProcessOwnerId(): string;
|
|
35
|
+
sendWorkerAgentMessage(agentId: string, message: string): {
|
|
36
|
+
messageId: string;
|
|
37
|
+
queued: true;
|
|
38
|
+
};
|
|
39
|
+
followUpWorkerAgent(agentId: string, message: string): {
|
|
40
|
+
started: boolean;
|
|
41
|
+
steering: boolean;
|
|
42
|
+
messageId: string;
|
|
43
|
+
record?: LaneRecord;
|
|
44
|
+
skipReason?: string;
|
|
45
|
+
};
|
|
46
|
+
interruptWorkerAgent(agentId: string): {
|
|
47
|
+
interrupted: boolean;
|
|
48
|
+
reason?: string;
|
|
49
|
+
};
|
|
50
|
+
resumeWorkerAgent(agentId: string): {
|
|
51
|
+
started: boolean;
|
|
52
|
+
record?: LaneRecord;
|
|
53
|
+
skipReason?: string;
|
|
54
|
+
};
|
|
55
|
+
cancelWorkerAgent(agentId: string, reasonCode?: string): LaneRecord | undefined;
|
|
56
|
+
/** Event-driven wait: durable projection plus state/mailbox notifications, never output polling. */
|
|
57
|
+
waitForWorkerAgent(agentId: string, timeoutMs?: number): Promise<{
|
|
58
|
+
status: "active" | "suspended" | "idle" | "unknown";
|
|
59
|
+
}>;
|
|
60
|
+
/** Read mailbox items at a safe boundary and reconcile the narrow append-before-ack crash window. */
|
|
61
|
+
mailboxMessagesForConversation(agentId: string, conversation: WorkerConversation, includeFollowUp: boolean): AgentMessage[];
|
|
62
|
+
/** Acknowledge only after the exact child transcript message has been durably appended. */
|
|
63
|
+
acknowledgeMailboxMessage(agentId: string, message: {
|
|
64
|
+
role: string;
|
|
65
|
+
content: unknown;
|
|
66
|
+
}): void;
|
|
67
|
+
/** Called by controller-owned execution transitions after lifecycle state changed. */
|
|
68
|
+
signalStateChanged(): void;
|
|
69
|
+
private requireControl;
|
|
70
|
+
private requireKnownAgent;
|
|
71
|
+
private getMailbox;
|
|
72
|
+
private subscribeStateChanges;
|
|
73
|
+
private mailboxMessage;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=worker-agent-control-coordinator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-agent-control-coordinator.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-agent-control-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,KAAK,sBAAsB,EAA+C,MAAM,2BAA2B,CAAC;AACrH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC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AC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAiCtG;IAED,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAgB/E;IAED,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,UAAU,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAYjG;IAED,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,SAAoB,GAAG,UAAU,GAAG,SAAS,CAUzF;IAED,oGAAoG;IACpG,kBAAkB,CACjB,OAAO,EAAE,MAAM,EACf,SAAS,SAAS,GAChB,OAAO,CAAC;QAAE,MAAM,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC,CAsClE;IAED,qGAAqG;IACrG,8BAA8B,CAC7B,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,kBAAkB,EAChC,eAAe,EAAE,OAAO,GACtB,YAAY,EAAE,CAUhB;IAED,2FAA2F;IAC3F,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAI5F;IAED,sFAAsF;IACtF,kBAAkB,IAAI,IAAI,CAEzB;IAED,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,UAAU;IAalB,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,cAAc;CAOtB","sourcesContent":["import type { AgentMessage } from \"@caupulican/pi-agent-core\";\nimport type { WorkerDelegationRunOutcome } from \"../agent-session-contracts.ts\";\nimport type { LaneRecord } from \"../autonomy/lane-tracker.ts\";\nimport type { AgentBindingContract } from \"../orchestration/contracts.ts\";\nimport type { AttemptRuntimeState } from \"../orchestration/task-runtime.ts\";\nimport { type WorkerAgentControlPort, WorkerAgentMailbox, type WorkerAgentMessage } from \"./worker-agent-control.ts\";\nimport type { WorkerConversation } from \"./worker-conversation-store.ts\";\nimport type { WorkerDelegationRequest } from \"./worker-delegation-request.ts\";\nimport type { WorkerDispatchScheduler } from \"./worker-dispatch-scheduler.ts\";\nimport type { WorkerLifecycle } from \"./worker-lifecycle.ts\";\n\nexport interface WorkerAgentControlCoordinatorOptions {\n\tagentDir: string;\n\tparentSessionId: string;\n\tprocessOwnerId: string;\n\tisControlAvailable(): boolean;\n\tgetLifecycle(): WorkerLifecycle;\n\trecoveredRequest(attempt: AttemptRuntimeState): WorkerDelegationRequest;\n\trun(request: WorkerDelegationRequest, record: LaneRecord): Promise<WorkerDelegationRunOutcome>;\n\tscheduler: Pick<WorkerDispatchScheduler, \"enqueue\" | \"track\" | \"drain\">;\n\tstatusChanged(): void;\n\tabortLane(laneId: string, reasonCode: string): void;\n\tcancelLane(laneId: string, reasonCode: string): LaneRecord | undefined;\n}\n\n/**\n * Sole owner of model-facing logical-agent controls and their durable inboxes.\n *\n * It deliberately owns no worker execution policy, provider loop, or terminal persistence. Those\n * controller-owned callbacks keep this narrow port from becoming a second lifecycle authority.\n */\nexport class WorkerAgentControlCoordinator implements WorkerAgentControlPort {\n\tprivate readonly options: WorkerAgentControlCoordinatorOptions;\n\tprivate readonly mailboxes = new Map<string, WorkerAgentMailbox>();\n\tprivate readonly stateListeners = new Set<() => void>();\n\n\tconstructor(options: WorkerAgentControlCoordinatorOptions) {\n\t\tthis.options = options;\n\t}\n\n\tgetProcessOwnerId(): string {\n\t\treturn this.options.processOwnerId;\n\t}\n\n\tsendWorkerAgentMessage(agentId: string, message: string): { messageId: string; queued: true } {\n\t\tthis.requireControl();\n\t\tconst agent = this.requireKnownAgent(agentId);\n\t\tconst queued = this.getMailbox(agent.agentId).enqueue({ kind: \"follow_up\", content: message });\n\t\tthis.signalStateChanged();\n\t\treturn { messageId: queued.messageId, queued: true };\n\t}\n\n\tfollowUpWorkerAgent(\n\t\tagentId: string,\n\t\tmessage: string,\n\t): { started: boolean; steering: boolean; messageId: string; record?: LaneRecord; skipReason?: string } {\n\t\tthis.requireControl();\n\t\tconst agent = this.requireKnownAgent(agentId);\n\t\tconst canonicalAgentId = agent.agentId;\n\t\tconst active = agent.activeAttemptId\n\t\t\t? this.options.getLifecycle().getTaskRuntimeSnapshot().attempts[agent.activeAttemptId]\n\t\t\t: undefined;\n\t\tif (active?.status === \"running\" || active?.status === \"leased\") {\n\t\t\tconst queued = this.getMailbox(canonicalAgentId).enqueue({ kind: \"steer\", content: message });\n\t\t\tthis.signalStateChanged();\n\t\t\treturn { started: false, steering: true, messageId: queued.messageId };\n\t\t}\n\t\tif (agent.status !== \"registered\") {\n\t\t\treturn { started: false, steering: false, messageId: \"\", skipReason: `agent_${agent.status}` };\n\t\t}\n\t\tconst queued = this.getMailbox(canonicalAgentId).enqueue({ kind: \"follow_up\", content: message });\n\t\ttry {\n\t\t\tconst prepared = this.options\n\t\t\t\t.getLifecycle()\n\t\t\t\t.prepareAgentTurn({ agentId: canonicalAgentId, instructions: message });\n\t\t\tthis.options.scheduler.enqueue(prepared.record, this.options.recoveredRequest(prepared.attempt));\n\t\t\tthis.options.statusChanged();\n\t\t\tthis.options.scheduler.drain();\n\t\t\tthis.signalStateChanged();\n\t\t\treturn { started: true, steering: false, messageId: queued.messageId, record: prepared.record };\n\t\t} catch (error) {\n\t\t\treturn {\n\t\t\t\tstarted: false,\n\t\t\t\tsteering: false,\n\t\t\t\tmessageId: queued.messageId,\n\t\t\t\tskipReason: error instanceof Error ? error.message : String(error),\n\t\t\t};\n\t\t}\n\t}\n\n\tinterruptWorkerAgent(agentId: string): { interrupted: boolean; reason?: string } {\n\t\tthis.requireControl();\n\t\tconst agent = this.requireKnownAgent(agentId);\n\t\tconst attemptId = agent.activeAttemptId;\n\t\tconst attempt = attemptId ? this.options.getLifecycle().getTaskRuntimeSnapshot().attempts[attemptId] : undefined;\n\t\tif (!attempt || (attempt.status !== \"running\" && attempt.status !== \"leased\")) {\n\t\t\treturn { interrupted: false, reason: \"agent_not_running\" };\n\t\t}\n\t\ttry {\n\t\t\tthis.options.getLifecycle().suspendAgent(attempt.taskId, agent.agentId, this.options.processOwnerId);\n\t\t\tthis.options.abortLane(attempt.taskId, \"agent_interrupted\");\n\t\t\tthis.signalStateChanged();\n\t\t\treturn { interrupted: true };\n\t\t} catch (error) {\n\t\t\treturn { interrupted: false, reason: error instanceof Error ? error.message : String(error) };\n\t\t}\n\t}\n\n\tresumeWorkerAgent(agentId: string): { started: boolean; record?: LaneRecord; skipReason?: string } {\n\t\tthis.requireControl();\n\t\tconst agent = this.requireKnownAgent(agentId);\n\t\tconst attemptId = agent.activeAttemptId;\n\t\tconst attempt = attemptId ? this.options.getLifecycle().getTaskRuntimeSnapshot().attempts[attemptId] : undefined;\n\t\tif (!attempt || attempt.status !== \"suspended\") return { started: false, skipReason: \"agent_not_suspended\" };\n\t\tconst record = this.options.getLifecycle().getRecord(attempt.taskId);\n\t\tif (!record) return { started: false, skipReason: \"orchestration_projection_missing\" };\n\t\tconst promise = this.options.run(this.options.recoveredRequest(attempt), record);\n\t\tthis.options.scheduler.track(record.laneId, promise);\n\t\tthis.signalStateChanged();\n\t\treturn { started: true, record };\n\t}\n\n\tcancelWorkerAgent(agentId: string, reasonCode = \"agent_cancelled\"): LaneRecord | undefined {\n\t\tthis.requireControl();\n\t\tconst agent = this.requireKnownAgent(agentId);\n\t\tconst attemptId = agent.activeAttemptId;\n\t\tconst attempt = attemptId ? this.options.getLifecycle().getTaskRuntimeSnapshot().attempts[attemptId] : undefined;\n\t\tif (!attempt) return undefined;\n\t\tthis.options.abortLane(attempt.taskId, reasonCode);\n\t\tconst record = this.options.cancelLane(attempt.taskId, reasonCode);\n\t\tthis.signalStateChanged();\n\t\treturn record;\n\t}\n\n\t/** Event-driven wait: durable projection plus state/mailbox notifications, never output polling. */\n\twaitForWorkerAgent(\n\t\tagentId: string,\n\t\ttimeoutMs = 30_000,\n\t): Promise<{ status: \"active\" | \"suspended\" | \"idle\" | \"unknown\" }> {\n\t\tthis.requireControl();\n\t\tconst canonicalAgentId = agentId.trim();\n\t\tconst boundedTimeoutMs = Number.isFinite(timeoutMs)\n\t\t\t? Math.max(1, Math.min(Math.floor(timeoutMs), 300_000))\n\t\t\t: 30_000;\n\t\tconst currentStatus = (): \"active\" | \"suspended\" | \"idle\" | \"unknown\" => {\n\t\t\tconst agent = this.options.getLifecycle().getAgent(canonicalAgentId);\n\t\t\tif (!agent) return \"unknown\";\n\t\t\tif (agent.status === \"active\" || agent.status === \"resuming\") return \"active\";\n\t\t\tif (agent.status === \"suspended\") return \"suspended\";\n\t\t\treturn \"idle\";\n\t\t};\n\t\tconst immediate = currentStatus();\n\t\tif (immediate !== \"active\") return Promise.resolve({ status: immediate });\n\t\treturn new Promise((resolve) => {\n\t\t\tlet settled = false;\n\t\t\tconst settle = () => {\n\t\t\t\tif (settled) return;\n\t\t\t\tconst next = currentStatus();\n\t\t\t\tif (next === \"active\") return;\n\t\t\t\tsettled = true;\n\t\t\t\tunsubscribeMailbox();\n\t\t\t\tunsubscribeState();\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tresolve({ status: next });\n\t\t\t};\n\t\t\tconst unsubscribeMailbox = this.getMailbox(canonicalAgentId).subscribe(settle);\n\t\t\tconst unsubscribeState = this.subscribeStateChanges(settle);\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tunsubscribeMailbox();\n\t\t\t\tunsubscribeState();\n\t\t\t\tresolve({ status: currentStatus() });\n\t\t\t}, boundedTimeoutMs);\n\t\t\tif (typeof timeout === \"object\" && \"unref\" in timeout) timeout.unref();\n\t\t});\n\t}\n\n\t/** Read mailbox items at a safe boundary and reconcile the narrow append-before-ack crash window. */\n\tmailboxMessagesForConversation(\n\t\tagentId: string,\n\t\tconversation: WorkerConversation,\n\t\tincludeFollowUp: boolean,\n\t): AgentMessage[] {\n\t\tconst mailbox = this.getMailbox(agentId);\n\t\tconst pending = mailbox.pending();\n\t\tif (pending.length === 0) return [];\n\t\tconst delivered = conversation.findDeliveredWorkerControlMessageIds(pending.map((message) => message.messageId));\n\t\tfor (const messageId of delivered) mailbox.acknowledgeDelivered(messageId);\n\t\treturn mailbox\n\t\t\t.pending()\n\t\t\t.filter((message) => message.kind === \"steer\" || includeFollowUp)\n\t\t\t.map((message) => this.mailboxMessage(message));\n\t}\n\n\t/** Acknowledge only after the exact child transcript message has been durably appended. */\n\tacknowledgeMailboxMessage(agentId: string, message: { role: string; content: unknown }): void {\n\t\tif (message.role !== \"user\" || typeof message.content !== \"string\") return;\n\t\tconst messageId = /^\\[Worker control (worker-message-[^\\]]+)\\]\\n/.exec(message.content)?.[1];\n\t\tif (messageId) this.getMailbox(agentId).acknowledgeDelivered(messageId);\n\t}\n\n\t/** Called by controller-owned execution transitions after lifecycle state changed. */\n\tsignalStateChanged(): void {\n\t\tfor (const listener of this.stateListeners) listener();\n\t}\n\n\tprivate requireControl(): void {\n\t\tif (!this.options.isControlAvailable()) {\n\t\t\tthrow new Error(\"Worker delegation control is unavailable in this UAC surface.\");\n\t\t}\n\t}\n\n\tprivate requireKnownAgent(agentId: string): AgentBindingContract {\n\t\tconst normalized = agentId.trim();\n\t\tif (!normalized) throw new Error(\"Logical worker agent id is required.\");\n\t\tconst agent = this.options.getLifecycle().getAgent(normalized);\n\t\tif (!agent) throw new Error(`Unknown logical worker agent '${normalized}'.`);\n\t\treturn agent;\n\t}\n\n\tprivate getMailbox(agentId: string): WorkerAgentMailbox {\n\t\tlet mailbox = this.mailboxes.get(agentId);\n\t\tif (!mailbox) {\n\t\t\tmailbox = new WorkerAgentMailbox({\n\t\t\t\tagentDir: this.options.agentDir,\n\t\t\t\tparentSessionId: this.options.parentSessionId,\n\t\t\t\tagentId,\n\t\t\t});\n\t\t\tthis.mailboxes.set(agentId, mailbox);\n\t\t}\n\t\treturn mailbox;\n\t}\n\n\tprivate subscribeStateChanges(listener: () => void): () => void {\n\t\tthis.stateListeners.add(listener);\n\t\treturn () => this.stateListeners.delete(listener);\n\t}\n\n\tprivate mailboxMessage(message: WorkerAgentMessage): AgentMessage {\n\t\treturn {\n\t\t\trole: \"user\",\n\t\t\tcontent: `[Worker control ${message.messageId}]\\n${message.content}`,\n\t\t\ttimestamp: Date.now(),\n\t\t};\n\t}\n}\n"]}
|