@caupulican/pi-adaptative 0.81.39 → 0.81.41
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 +77 -0
- package/README.md +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -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 +3 -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 +4 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
- package/dist/cli/args.d.ts +4 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +31 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-directory-layout.d.ts +15 -0
- package/dist/core/agent-directory-layout.d.ts.map +1 -0
- package/dist/core/agent-directory-layout.js +72 -0
- package/dist/core/agent-directory-layout.js.map +1 -0
- package/dist/core/agent-paths.d.ts +25 -2
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +79 -4
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +293 -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 +52 -8
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +400 -79
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +74 -518
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +370 -1432
- 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/approval-gate.d.ts +3 -2
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
- package/dist/core/autonomy/approval-gate.js +6 -28
- package/dist/core/autonomy/approval-gate.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +1 -1
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +20 -12
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
- package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
- package/dist/core/autonomy/foreground-envelope.js +8 -25
- package/dist/core/autonomy/foreground-envelope.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +8 -10
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
- package/dist/core/autonomy/lane-private-paths.js +16 -0
- package/dist/core/autonomy/lane-private-paths.js.map +1 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +48 -9
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/lane-tracker.d.ts +14 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +38 -0
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/autonomy/risk-assessment.d.ts +1 -2
- package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
- package/dist/core/autonomy/risk-assessment.js +1 -123
- package/dist/core/autonomy/risk-assessment.js.map +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts +4 -4
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.js +16 -29
- package/dist/core/autonomy/session-lane-record.js.map +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
- package/dist/core/autonomy/telemetry-events.js +1 -1
- package/dist/core/autonomy/telemetry-events.js.map +1 -1
- package/dist/core/autonomy-telemetry.d.ts +7 -7
- package/dist/core/autonomy-telemetry.d.ts.map +1 -1
- package/dist/core/autonomy-telemetry.js +9 -9
- package/dist/core/autonomy-telemetry.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +56 -236
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +141 -1273
- 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/capability-contract.d.ts +4 -0
- package/dist/core/capability-contract.d.ts.map +1 -0
- package/dist/core/capability-contract.js +28 -0
- package/dist/core/capability-contract.js.map +1 -0
- package/dist/core/compaction-controller.d.ts +90 -0
- package/dist/core/compaction-controller.d.ts.map +1 -0
- package/dist/core/compaction-controller.js +452 -0
- package/dist/core/compaction-controller.js.map +1 -0
- package/dist/core/compaction-support.d.ts +13 -17
- 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/context-artifacts.d.ts +6 -2
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +34 -2
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts +8 -2
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +158 -35
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/okf-memory.d.ts.map +1 -1
- package/dist/core/context/okf-memory.js +9 -11
- package/dist/core/context/okf-memory.js.map +1 -1
- package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
- package/dist/core/context/sqlite-runtime-index.js +6 -8
- package/dist/core/context/sqlite-runtime-index.js.map +1 -1
- package/dist/core/context-gc.d.ts +3 -0
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +10 -5
- package/dist/core/context-gc.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 +16 -37
- 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 +2 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
- package/dist/core/delegation/managed-lane-controller.js +217 -0
- package/dist/core/delegation/managed-lane-controller.js.map +1 -0
- package/dist/core/delegation/session-worker-claim.d.ts +44 -0
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/session-worker-claim.js +98 -0
- package/dist/core/delegation/session-worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +7 -5
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +20 -4
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
- package/dist/core/delegation/worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
- package/dist/core/delegation/worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.js +861 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
- package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-request.js +2 -0
- package/dist/core/delegation/worker-delegation-request.js.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
- package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-execution-policy.js +160 -0
- package/dist/core/delegation/worker-execution-policy.js.map +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
- package/dist/core/delegation/worker-lane-projection.js +100 -0
- package/dist/core/delegation/worker-lane-projection.js.map +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
- package/dist/core/delegation/worker-lifecycle.js +339 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.js +90 -0
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.js +113 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +25 -14
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +122 -53
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-label.d.ts +3 -0
- package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
- package/dist/core/delegation/worker-task-label.js +11 -0
- package/dist/core/delegation/worker-task-label.js.map +1 -0
- package/dist/core/doctor.d.ts +8 -0
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +32 -1
- package/dist/core/doctor.js.map +1 -1
- 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/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +5 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +52 -18
- 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 +20 -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/storage.d.ts +8 -0
- package/dist/core/extensions/storage.d.ts.map +1 -0
- package/dist/core/extensions/storage.js +28 -0
- package/dist/core/extensions/storage.js.map +1 -0
- package/dist/core/extensions/types.d.ts +78 -21
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/failure-corpus.d.ts +1 -15
- package/dist/core/failure-corpus.d.ts.map +1 -1
- package/dist/core/failure-corpus.js +9 -37
- package/dist/core/failure-corpus.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +53 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
- package/dist/core/foreground-recovery-controller.js +111 -0
- package/dist/core/foreground-recovery-controller.js.map +1 -0
- package/dist/core/gateways/channel-provider.d.ts +3 -0
- package/dist/core/gateways/channel-provider.d.ts.map +1 -1
- package/dist/core/gateways/channel-provider.js +31 -6
- package/dist/core/gateways/channel-provider.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 +11 -0
- package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
- package/dist/core/goals/goal-acceptance.js +27 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts +28 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.js +90 -0
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
- 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 +52 -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 +43 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
- package/dist/core/goals/goal-lifecycle.js +102 -0
- package/dist/core/goals/goal-lifecycle.js.map +1 -0
- 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-runtime-snapshot.d.ts +11 -9
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.js +10 -8
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
- 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 +46 -25
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +91 -24
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +9 -10
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +60 -75
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +20 -12
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +133 -33
- 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/human-input.d.ts +100 -0
- package/dist/core/human-input.d.ts.map +1 -0
- package/dist/core/human-input.js +362 -0
- package/dist/core/human-input.js.map +1 -0
- package/dist/core/index.d.ts +9 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +9 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
- package/dist/core/install-telemetry.d.ts.map +1 -0
- package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
- package/dist/core/install-telemetry.js.map +1 -0
- package/dist/core/keybindings.d.ts +17 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/learning/learning-audit.d.ts +2 -4
- package/dist/core/learning/learning-audit.d.ts.map +1 -1
- package/dist/core/learning/learning-audit.js +9 -29
- package/dist/core/learning/learning-audit.js.map +1 -1
- package/dist/core/learning/learning-gate.d.ts.map +1 -1
- package/dist/core/learning/learning-gate.js +1 -6
- package/dist/core/learning/learning-gate.js.map +1 -1
- package/dist/core/learning/session-learning-decision.d.ts +2 -4
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
- package/dist/core/learning/session-learning-decision.js +9 -29
- package/dist/core/learning/session-learning-decision.js.map +1 -1
- 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/memory-controller.d.ts.map +1 -1
- package/dist/core/memory-controller.js +4 -4
- package/dist/core/memory-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 +1 -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 +17 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +38 -25
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router/intent-classifier.d.ts +1 -4
- package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
- package/dist/core/model-router/intent-classifier.js +1 -156
- package/dist/core/model-router/intent-classifier.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 +2 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.d.ts +5 -5
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +23 -0
- package/dist/core/model-tool-protocol.d.ts.map +1 -0
- package/dist/core/model-tool-protocol.js +43 -0
- package/dist/core/model-tool-protocol.js.map +1 -0
- package/dist/core/models/adaptation-store.d.ts +4 -6
- package/dist/core/models/adaptation-store.d.ts.map +1 -1
- package/dist/core/models/adaptation-store.js +95 -83
- package/dist/core/models/adaptation-store.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts +2 -12
- package/dist/core/models/fitness-store.d.ts.map +1 -1
- package/dist/core/models/fitness-store.js +84 -57
- package/dist/core/models/fitness-store.js.map +1 -1
- package/dist/core/models/host-state-store.d.ts +34 -0
- package/dist/core/models/host-state-store.d.ts.map +1 -0
- package/dist/core/models/host-state-store.js +86 -0
- package/dist/core/models/host-state-store.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +24 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
- package/dist/core/orchestration/agent-resume.js +90 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +61 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
- package/dist/core/orchestration/capability-gateway.js +152 -0
- package/dist/core/orchestration/capability-gateway.js.map +1 -0
- package/dist/core/orchestration/contracts.d.ts +343 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -0
- package/dist/core/orchestration/contracts.js +135 -0
- package/dist/core/orchestration/contracts.js.map +1 -0
- package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
- package/dist/core/orchestration/delegation-ledger.js +200 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -0
- package/dist/core/orchestration/event-store.d.ts +83 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -0
- package/dist/core/orchestration/event-store.js +560 -0
- package/dist/core/orchestration/event-store.js.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.js +37 -0
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
- package/dist/core/orchestration/model-binding.d.ts +15 -0
- package/dist/core/orchestration/model-binding.d.ts.map +1 -0
- package/dist/core/orchestration/model-binding.js +29 -0
- package/dist/core/orchestration/model-binding.js.map +1 -0
- package/dist/core/orchestration/policy-compiler.d.ts +49 -0
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
- package/dist/core/orchestration/policy-compiler.js +191 -0
- package/dist/core/orchestration/policy-compiler.js.map +1 -0
- package/dist/core/orchestration/policy-gate.d.ts +18 -0
- package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
- package/dist/core/orchestration/policy-gate.js +24 -0
- package/dist/core/orchestration/policy-gate.js.map +1 -0
- package/dist/core/orchestration/profile-registry.d.ts +51 -0
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
- package/dist/core/orchestration/profile-registry.js +393 -0
- package/dist/core/orchestration/profile-registry.js.map +1 -0
- package/dist/core/orchestration/profile-store.d.ts +31 -0
- package/dist/core/orchestration/profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/profile-store.js +136 -0
- package/dist/core/orchestration/profile-store.js.map +1 -0
- package/dist/core/orchestration/risk-budget.d.ts +9 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
- package/dist/core/orchestration/risk-budget.js +48 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -0
- package/dist/core/orchestration/task-runtime.d.ts +168 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime.js +1600 -0
- package/dist/core/orchestration/task-runtime.js.map +1 -0
- package/dist/core/orchestration/work-state-projection.d.ts +32 -0
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
- package/dist/core/orchestration/work-state-projection.js +116 -0
- package/dist/core/orchestration/work-state-projection.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.js +179 -0
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.js +109 -0
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
- 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/process-identity.d.ts +11 -0
- package/dist/core/process-identity.d.ts.map +1 -0
- package/dist/core/process-identity.js +26 -0
- package/dist/core/process-identity.js.map +1 -0
- package/dist/core/process-matrix/codes.d.ts +14 -3
- package/dist/core/process-matrix/codes.d.ts.map +1 -1
- package/dist/core/process-matrix/codes.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
- package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
- package/dist/core/process-matrix/resume-launcher.js +62 -0
- package/dist/core/process-matrix/resume-launcher.js.map +1 -0
- package/dist/core/process-matrix/runtime.d.ts +37 -22
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +399 -76
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/process-matrix/store.d.ts +5 -2
- package/dist/core/process-matrix/store.d.ts.map +1 -1
- package/dist/core/process-matrix/store.js +123 -14
- package/dist/core/process-matrix/store.js.map +1 -1
- package/dist/core/process-matrix/supervisor.d.ts +10 -7
- package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
- package/dist/core/process-matrix/supervisor.js +45 -14
- package/dist/core/process-matrix/supervisor.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/profile-registry.d.ts.map +1 -1
- package/dist/core/profile-registry.js +6 -8
- package/dist/core/profile-registry.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 +5 -5
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +5 -2
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/reload-blockers.d.ts.map +1 -1
- package/dist/core/reload-blockers.js +6 -8
- package/dist/core/reload-blockers.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.map +1 -1
- package/dist/core/research/evidence-bundle.js +1 -6
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/research/lane-model-resolver.d.ts +33 -0
- package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
- package/dist/core/research/lane-model-resolver.js +65 -0
- package/dist/core/research/lane-model-resolver.js.map +1 -0
- package/dist/core/research/model-fitness-controller.d.ts +38 -0
- package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
- package/dist/core/research/model-fitness-controller.js +106 -0
- package/dist/core/research/model-fitness-controller.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +1 -1
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +4 -4
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-gate.d.ts.map +1 -1
- package/dist/core/research/research-gate.js +7 -7
- package/dist/core/research/research-gate.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +62 -0
- package/dist/core/research/research-lane-controller.d.ts.map +1 -0
- package/dist/core/research/research-lane-controller.js +292 -0
- package/dist/core/research/research-lane-controller.js.map +1 -0
- package/dist/core/research/session-evidence-bundle.d.ts +2 -4
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/session-evidence-bundle.js +10 -46
- package/dist/core/research/session-evidence-bundle.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +23 -8
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.d.ts +6 -0
- package/dist/core/risk-classifier.d.ts.map +1 -0
- package/dist/core/risk-classifier.js +233 -0
- package/dist/core/risk-classifier.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +41 -23
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +365 -253
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/sdk.d.ts +6 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +68 -25
- 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 +67 -70
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-image-store.d.ts +33 -0
- package/dist/core/session-image-store.d.ts.map +1 -0
- package/dist/core/session-image-store.js +283 -0
- package/dist/core/session-image-store.js.map +1 -0
- package/dist/core/session-role.d.ts +11 -4
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +24 -5
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/session-snapshot.d.ts +34 -0
- package/dist/core/session-snapshot.d.ts.map +1 -0
- package/dist/core/session-snapshot.js +68 -0
- package/dist/core/session-snapshot.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +31 -0
- package/dist/core/session-supervision-runtime.d.ts.map +1 -0
- package/dist/core/session-supervision-runtime.js +97 -0
- package/dist/core/session-supervision-runtime.js.map +1 -0
- 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 +10 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +81 -29
- 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/tasks/session-task-state.d.ts +2 -4
- package/dist/core/tasks/session-task-state.d.ts.map +1 -1
- package/dist/core/tasks/session-task-state.js +10 -28
- package/dist/core/tasks/session-task-state.js.map +1 -1
- package/dist/core/tasks/task-projection.d.ts +20 -0
- package/dist/core/tasks/task-projection.d.ts.map +1 -0
- package/dist/core/tasks/task-projection.js +47 -0
- package/dist/core/tasks/task-projection.js.map +1 -0
- package/dist/core/tasks/task-state.d.ts +4 -0
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +28 -11
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +13 -0
- package/dist/core/tool-capability-policy.d.ts.map +1 -0
- package/dist/core/tool-capability-policy.js +86 -0
- package/dist/core/tool-capability-policy.js.map +1 -0
- 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 +89 -0
- package/dist/core/tool-protocol-controller.d.ts.map +1 -0
- package/dist/core/tool-protocol-controller.js +512 -0
- package/dist/core/tool-protocol-controller.js.map +1 -0
- package/dist/core/tool-recovery-log-records.d.ts +2 -3
- package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-records.js +9 -35
- package/dist/core/tool-recovery-log-records.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/tool-selection/tool-performance-store.d.ts +3 -7
- package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.js +97 -138
- package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
- package/dist/core/tools/ask-question.d.ts +124 -0
- package/dist/core/tools/ask-question.d.ts.map +1 -0
- package/dist/core/tools/ask-question.js +693 -0
- package/dist/core/tools/ask-question.js.map +1 -0
- 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 +31 -3
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +148 -29
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +15 -13
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +106 -23
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +1 -0
- package/dist/core/tools/extensionify.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 +10 -8
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +106 -28
- 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/model-fitness.d.ts.map +1 -1
- package/dist/core/tools/model-fitness.js +2 -2
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +40 -0
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
- package/dist/core/tools/orchestration-panel.js +124 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -0
- 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 +26 -0
- package/dist/core/tools/run-process.d.ts.map +1 -0
- package/dist/core/tools/run-process.js +138 -0
- package/dist/core/tools/run-process.js.map +1 -0
- 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/task-steps.d.ts +2 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +99 -0
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +3 -5
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +4 -4
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +4 -6
- package/dist/core/tools/windows-shell-engine.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-jsonl.d.ts +10 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
- package/dist/core/util/bounded-jsonl.js +75 -0
- package/dist/core/util/bounded-jsonl.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +5 -0
- package/dist/core/util/value-guards.d.ts.map +1 -0
- package/dist/core/util/value-guards.js +12 -0
- package/dist/core/util/value-guards.js.map +1 -0
- package/dist/core/worktree-sync/store.d.ts +3 -3
- package/dist/core/worktree-sync/store.d.ts.map +1 -1
- package/dist/core/worktree-sync/store.js +10 -5
- package/dist/core/worktree-sync/store.js.map +1 -1
- package/dist/index.d.ts +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +149 -51
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +4 -6
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +186 -28
- package/dist/migrations.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/clipboard-input.d.ts +7 -1
- package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
- package/dist/modes/interactive/clipboard-input.js +44 -6
- package/dist/modes/interactive/clipboard-input.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/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +6 -6
- 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/config-backup.d.ts.map +1 -1
- package/dist/modes/interactive/config-backup.js +5 -4
- package/dist/modes/interactive/config-backup.js.map +1 -1
- package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +77 -15
- 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 +22 -24
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +245 -595
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +1 -1
- package/dist/modes/interactive/key-handlers.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/profile-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.js +7 -7
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +21 -0
- package/dist/modes/interactive/report-commands.js.map +1 -1
- 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 +27 -8
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +150 -64
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-io-commands.js +16 -6
- package/dist/modes/interactive/session-io-commands.js.map +1 -1
- package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
- package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
- package/dist/modes/interactive/session-replacement-errors.js +15 -0
- package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
- package/dist/modes/interactive/startup-checks.js +1 -1
- package/dist/modes/interactive/startup-checks.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/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +82 -23
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +138 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -13
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +52 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/platform.d.ts +3 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +8 -0
- package/dist/utils/platform.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/dist/utils/work-directory.d.ts +11 -0
- package/dist/utils/work-directory.d.ts.map +1 -1
- package/dist/utils/work-directory.js +30 -9
- package/dist/utils/work-directory.js.map +1 -1
- package/docs/UI_POLISH_ORCHESTRATION.md +38 -0
- package/docs/UI_QUALITY_ORCHESTRATION.md +28 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +62 -2
- package/docs/harness-architecture.md +156 -0
- package/docs/keybindings.md +11 -1
- package/docs/process-matrix.md +59 -26
- package/docs/providers.md +9 -1
- package/docs/rpc.md +45 -2
- package/docs/sessions.md +15 -0
- package/docs/settings.md +125 -11
- package/docs/task-steps.md +8 -0
- package/docs/telemetry.md +19 -0
- package/docs/tmux-agent-manager.md +10 -3
- package/docs/ui-reference/README.md +9 -0
- package/docs/ui-reference/orchestration-after.txt +14 -0
- package/docs/ui-reference/orchestration-before.txt +13 -0
- package/docs/ui-reference/orchestration-reference.txt +16 -0
- package/docs/usage.md +22 -2
- package/docs/work-directory.md +19 -8
- 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/question.ts +34 -245
- package/examples/extensions/questionnaire.ts +41 -407
- 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
- package/dist/core/delegation/session-worker-result.d.ts +0 -46
- package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
- package/dist/core/delegation/session-worker-result.js +0 -113
- package/dist/core/delegation/session-worker-result.js.map +0 -1
- package/dist/core/delegation/worker-result.d.ts.map +0 -1
- package/dist/core/delegation/worker-result.js.map +0 -1
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js.map +0 -1
|
@@ -47,6 +47,8 @@ export class OutputAccumulator {
|
|
|
47
47
|
maxBytes;
|
|
48
48
|
tempFilePrefix;
|
|
49
49
|
tempDirectory;
|
|
50
|
+
persistAllOutput;
|
|
51
|
+
maxPersistedBytes;
|
|
50
52
|
decoder = new TextDecoder();
|
|
51
53
|
rawChunks = [];
|
|
52
54
|
tailLines = [];
|
|
@@ -67,11 +69,15 @@ export class OutputAccumulator {
|
|
|
67
69
|
tempFilePath;
|
|
68
70
|
tempFileFd;
|
|
69
71
|
tempFileError;
|
|
72
|
+
persistedOutputBytes = 0;
|
|
73
|
+
persistedOutputTruncated = false;
|
|
70
74
|
constructor(options = {}) {
|
|
71
75
|
this.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
72
76
|
this.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
73
77
|
this.tempFilePrefix = options.tempFilePrefix ?? "pi-output";
|
|
74
78
|
this.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), "outputs", "tool-streams").path;
|
|
79
|
+
this.persistAllOutput = options.persistAllOutput ?? false;
|
|
80
|
+
this.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;
|
|
75
81
|
}
|
|
76
82
|
append(data) {
|
|
77
83
|
if (this.finished) {
|
|
@@ -100,6 +106,8 @@ export class OutputAccumulator {
|
|
|
100
106
|
...snapshot,
|
|
101
107
|
fullOutputPath: this.fullOutputPath(),
|
|
102
108
|
fullOutputError: this.tempFileError,
|
|
109
|
+
persistedOutputTruncated: this.persistedOutputTruncated || undefined,
|
|
110
|
+
persistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,
|
|
103
111
|
};
|
|
104
112
|
}
|
|
105
113
|
preview(maxLines, maxBytes = this.maxBytes) {
|
|
@@ -118,6 +126,8 @@ export class OutputAccumulator {
|
|
|
118
126
|
...snapshot,
|
|
119
127
|
fullOutputPath: this.fullOutputPath(),
|
|
120
128
|
fullOutputError: this.tempFileError,
|
|
129
|
+
persistedOutputTruncated: this.persistedOutputTruncated || undefined,
|
|
130
|
+
persistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,
|
|
121
131
|
};
|
|
122
132
|
}
|
|
123
133
|
async closeTempFile() {
|
|
@@ -142,7 +152,7 @@ export class OutputAccumulator {
|
|
|
142
152
|
if (this.tempFileFd !== undefined || this.shouldUseTempFile()) {
|
|
143
153
|
if (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {
|
|
144
154
|
try {
|
|
145
|
-
|
|
155
|
+
this.writePersisted(data);
|
|
146
156
|
}
|
|
147
157
|
catch (error) {
|
|
148
158
|
this.recordTempFileError(error);
|
|
@@ -290,7 +300,10 @@ export class OutputAccumulator {
|
|
|
290
300
|
};
|
|
291
301
|
}
|
|
292
302
|
shouldUseTempFile() {
|
|
293
|
-
return (this.
|
|
303
|
+
return (this.persistAllOutput ||
|
|
304
|
+
this.totalRawBytes > this.maxBytes ||
|
|
305
|
+
this.totalDecodedBytes > this.maxBytes ||
|
|
306
|
+
this.totalLines > this.maxLines);
|
|
294
307
|
}
|
|
295
308
|
fullOutputPath() {
|
|
296
309
|
return this.tempFileError === undefined ? this.tempFilePath : undefined;
|
|
@@ -306,7 +319,7 @@ export class OutputAccumulator {
|
|
|
306
319
|
this.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);
|
|
307
320
|
this.tempFileFd = openSync(this.tempFilePath, "w");
|
|
308
321
|
for (const chunk of this.rawChunks) {
|
|
309
|
-
|
|
322
|
+
this.writePersisted(chunk);
|
|
310
323
|
}
|
|
311
324
|
this.rawChunks = [];
|
|
312
325
|
return true;
|
|
@@ -316,6 +329,26 @@ export class OutputAccumulator {
|
|
|
316
329
|
return false;
|
|
317
330
|
}
|
|
318
331
|
}
|
|
332
|
+
writePersisted(data) {
|
|
333
|
+
if (this.tempFileFd === undefined || data.length === 0)
|
|
334
|
+
return;
|
|
335
|
+
const remaining = Math.max(0, this.maxPersistedBytes - this.persistedOutputBytes);
|
|
336
|
+
if (remaining === 0) {
|
|
337
|
+
this.persistedOutputTruncated = true;
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const bounded = data.length > remaining ? data.subarray(0, remaining) : data;
|
|
341
|
+
let offset = 0;
|
|
342
|
+
while (offset < bounded.length) {
|
|
343
|
+
const written = writeSync(this.tempFileFd, bounded, offset, bounded.length - offset);
|
|
344
|
+
if (written <= 0)
|
|
345
|
+
throw new Error("Managed output write made no progress");
|
|
346
|
+
offset += written;
|
|
347
|
+
this.persistedOutputBytes += written;
|
|
348
|
+
}
|
|
349
|
+
if (bounded.length < data.length)
|
|
350
|
+
this.persistedOutputTruncated = true;
|
|
351
|
+
}
|
|
319
352
|
recordTempFileError(error) {
|
|
320
353
|
this.tempFileError ??= formatIoError(error);
|
|
321
354
|
const fd = this.tempFileFd;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OA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YAAC,OAAO,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,aAAa,IAAI,mBAAmB,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;YACtE,CAAC;QACF,CAAC;IAAA,CACD;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { closeSync, openSync, writeSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult } from \"@caupulican/pi-agent-core/node\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\ttempDirectory?: string;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n}\n\nexport interface OutputPreview {\n\tcontent: string;\n\tskippedLines: number;\n}\n\nfunction defaultTempFilePath(directory: string, prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(directory, `${prefix}-${id}.log`);\n}\n\nconst MAX_APPEND_CHUNK_BYTES = 64 * 1024;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nfunction formatIoError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code ? `${code}: ${error.message}` : error.message;\n\t}\n\treturn String(error);\n}\n\nfunction tailUtf8String(text: string, maxBytes: number): { text: string; bytes: number } {\n\tif (maxBytes <= 0 || text.length === 0) {\n\t\treturn { text: \"\", bytes: 0 };\n\t}\n\n\tconst buffer = Buffer.from(text, \"utf-8\");\n\tif (buffer.length <= maxBytes) {\n\t\treturn { text, bytes: buffer.length };\n\t}\n\n\tlet start = buffer.length - maxBytes;\n\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\tconst result = buffer.subarray(start).toString(\"utf-8\");\n\treturn { text: result, bytes: byteLength(result) };\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps a bounded tail of\n * logical lines, and opens a temp file when the full output needs preserving.\n * Snapshot and preview work is bounded by configured output limits, never by\n * total command history.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly tempDirectory: string;\n\tprivate readonly decoder = new TextDecoder();\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate tailLines: string[] = [];\n\tprivate tailLineBytes: number[] = [];\n\tprivate tailLineStoredBytes: number[] = [];\n\tprivate tailStart = 0;\n\tprivate tailStoredBytes = 0;\n\tprivate currentLineText = \"\";\n\tprivate currentLineBytes = 0;\n\tprivate currentLineStoredBytes = 0;\n\tprivate lastCompletedLineBytes = 0;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileFd: number | undefined;\n\tprivate tempFileError: string | undefined;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), \"outputs\", \"tool-streams\").path;\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tfor (let offset = 0; offset < data.length; offset += MAX_APPEND_CHUNK_BYTES) {\n\t\t\tthis.appendBlock(data.subarray(offset, offset + MAX_APPEND_CHUNK_BYTES));\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(this.maxLines, this.maxBytes);\n\n\t\tif (options.persistIfTruncated && snapshot.truncation.truncated) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tpreview(maxLines: number, maxBytes = this.maxBytes): OutputPreview {\n\t\tconst snapshot = this.previewSnapshot(maxLines, maxBytes);\n\t\treturn {\n\t\t\tcontent: snapshot.content,\n\t\t\tskippedLines: Math.max(0, this.totalLines - snapshot.truncation.outputLines),\n\t\t};\n\t}\n\n\tpreviewSnapshot(\n\t\tmaxLines: number,\n\t\tmaxBytes = this.maxBytes,\n\t\toptions: { persistIfFullTruncated?: boolean } = {},\n\t): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (options.persistIfFullTruncated && this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst fd = this.tempFileFd;\n\t\tif (fd === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFileFd = undefined;\n\t\ttry {\n\t\t\tcloseSync(fd);\n\t\t} catch (error) {\n\t\t\tthis.tempFileError ??= formatIoError(error);\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.hasOpenLine ? this.currentLineBytes : this.lastCompletedLineBytes;\n\t}\n\n\tprivate appendBlock(data: Buffer): void {\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileFd !== undefined || this.shouldUseTempFile()) {\n\t\t\tif (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\twriteSync(this.tempFileFd, data);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.recordTempFileError(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.length > 0) {\n\t\t\t// Copy retained chunks: Buffer.subarray would pin a large caller buffer in memory.\n\t\t\tthis.rawChunks.push(Buffer.from(data));\n\t\t}\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += byteLength(text);\n\n\t\tlet segmentStart = 0;\n\t\tfor (\n\t\t\tlet newlineIndex = text.indexOf(\"\\n\");\n\t\t\tnewlineIndex !== -1;\n\t\t\tnewlineIndex = text.indexOf(\"\\n\", segmentStart)\n\t\t) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart, newlineIndex));\n\t\t\tthis.pushCompletedCurrentLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\n\t\tif (segmentStart < text.length) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart));\n\t\t}\n\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate appendToCurrentLine(segment: string): void {\n\t\tif (segment.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst segmentBytes = byteLength(segment);\n\t\tthis.currentLineBytes += segmentBytes;\n\t\tthis.hasOpenLine = true;\n\n\t\tif (segmentBytes >= this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(segment, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentLineText += segment;\n\t\tthis.currentLineStoredBytes += segmentBytes;\n\t\tif (this.currentLineStoredBytes > this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(this.currentLineText, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t}\n\t}\n\n\tprivate pushCompletedCurrentLine(): void {\n\t\tthis.completedLines++;\n\t\tthis.lastCompletedLineBytes = this.currentLineBytes;\n\t\tthis.tailLines.push(this.currentLineText);\n\t\tthis.tailLineBytes.push(this.currentLineBytes);\n\t\tthis.tailLineStoredBytes.push(this.currentLineStoredBytes);\n\t\tthis.tailStoredBytes += this.currentLineStoredBytes;\n\t\tthis.currentLineText = \"\";\n\t\tthis.currentLineBytes = 0;\n\t\tthis.currentLineStoredBytes = 0;\n\t\tthis.hasOpenLine = false;\n\t\tthis.trimStoredTail();\n\t}\n\n\tprivate trimStoredTail(): void {\n\t\twhile (this.completedTailLineCount() > this.maxLines || this.tailStoredBytes > this.maxBytes) {\n\t\t\tthis.tailStoredBytes -= this.tailLineStoredBytes[this.tailStart] ?? 0;\n\t\t\tthis.tailStart++;\n\t\t}\n\n\t\tif (this.tailStart > 1024 && this.tailStart * 2 > this.tailLines.length) {\n\t\t\tthis.tailLines = this.tailLines.slice(this.tailStart);\n\t\t\tthis.tailLineBytes = this.tailLineBytes.slice(this.tailStart);\n\t\t\tthis.tailLineStoredBytes = this.tailLineStoredBytes.slice(this.tailStart);\n\t\t\tthis.tailStart = 0;\n\t\t}\n\t}\n\n\tprivate completedTailLineCount(): number {\n\t\treturn this.tailLines.length - this.tailStart;\n\t}\n\n\tprivate buildSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst truncated = this.totalLines > maxLines || this.totalDecodedBytes > maxBytes;\n\t\tconst outputLines: string[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet outputLineCount = 0;\n\t\tlet truncatedBy: \"lines\" | \"bytes\" = this.totalLines > maxLines ? \"lines\" : \"bytes\";\n\t\tlet lastLinePartial = false;\n\t\tlet readCurrent = this.hasOpenLine;\n\t\tlet completedIndex = this.tailLines.length - 1;\n\n\t\twhile (outputLineCount < maxLines) {\n\t\t\tlet line: string;\n\t\t\tlet lineBytes: number;\n\t\t\tlet storedBytes: number;\n\t\t\tif (readCurrent) {\n\t\t\t\tline = this.currentLineText;\n\t\t\t\tlineBytes = this.currentLineBytes;\n\t\t\t\tstoredBytes = this.currentLineStoredBytes;\n\t\t\t\treadCurrent = false;\n\t\t\t} else {\n\t\t\t\tif (completedIndex < this.tailStart) break;\n\t\t\t\tline = this.tailLines[completedIndex] ?? \"\";\n\t\t\t\tlineBytes = this.tailLineBytes[completedIndex] ?? 0;\n\t\t\t\tstoredBytes = this.tailLineStoredBytes[completedIndex] ?? 0;\n\t\t\t\tcompletedIndex--;\n\t\t\t}\n\n\t\t\tconst separatorBytes = outputLineCount > 0 ? 1 : 0;\n\t\t\tconst fullLineBytes = lineBytes + separatorBytes;\n\t\t\tif (outputBytes + fullLineBytes > maxBytes) {\n\t\t\t\ttruncatedBy = \"bytes\";\n\t\t\t\tif (outputLineCount === 0) {\n\t\t\t\t\tconst partial =\n\t\t\t\t\t\tlineBytes > maxBytes ? tailUtf8String(line, maxBytes) : { text: line, bytes: storedBytes };\n\t\t\t\t\toutputLines.unshift(partial.text);\n\t\t\t\t\toutputBytes = partial.bytes;\n\t\t\t\t\toutputLineCount = 1;\n\t\t\t\t\tlastLinePartial = lineBytes > partial.bytes;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toutputLines.unshift(line);\n\t\t\toutputBytes += storedBytes + separatorBytes;\n\t\t\toutputLineCount++;\n\t\t}\n\n\t\tlet content = outputLines.join(\"\\n\");\n\t\tif (!truncated && !this.hasOpenLine && this.totalLines > 0) {\n\t\t\tcontent += \"\\n\";\n\t\t\toutputBytes += 1;\n\t\t}\n\n\t\tconst effectiveTruncatedBy = truncated ? truncatedBy : null;\n\t\tconst truncation: TruncationResult = {\n\t\t\tcontent,\n\t\t\ttruncated,\n\t\t\ttruncatedBy: effectiveTruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\toutputLines: outputLineCount,\n\t\t\toutputBytes,\n\t\t\tlastLinePartial,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate fullOutputPath(): string | undefined {\n\t\treturn this.tempFileError === undefined ? this.tempFilePath : undefined;\n\t}\n\n\tprivate tryEnsureTempFile(): boolean {\n\t\tif (this.tempFileError !== undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.tempFileFd !== undefined) {\n\t\t\treturn true;\n\t\t}\n\t\ttry {\n\t\t\tthis.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);\n\t\t\tthis.tempFileFd = openSync(this.tempFilePath, \"w\");\n\t\t\tfor (const chunk of this.rawChunks) {\n\t\t\t\twriteSync(this.tempFileFd, chunk);\n\t\t\t}\n\t\t\tthis.rawChunks = [];\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.recordTempFileError(error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate recordTempFileError(error: unknown): void {\n\t\tthis.tempFileError ??= formatIoError(error);\n\t\tconst fd = this.tempFileFd;\n\t\tthis.tempFileFd = undefined;\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch (closeError) {\n\t\t\t\tthis.tempFileError += `; close failed: ${formatIoError(closeError)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,MAAM,gCAAgC,CAAC;AAC7G,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AA2BlE,SAAS,mBAAmB,CAAC,SAAiB,EAAE,MAAc,EAAU;IACvE,MAAM,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,IAAI,CAAC,SAAS,EAAE,GAAG,MAAM,IAAI,EAAE,MAAM,CAAC,CAAC;AAAA,CAC9C;AAED,MAAM,sBAAsB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzC,SAAS,UAAU,CAAC,IAAY,EAAU;IACzC,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAAA,CACxC;AAED,SAAS,aAAa,CAAC,KAAc,EAAU;IAC9C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAI,KAA+B,CAAC,IAAI,CAAC;QACnD,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAC3D,CAAC;IACD,OAAO,MAAM,CAAC,KA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,OAAO,IAAI,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3E,MAAM,IAAI,OAAO,CAAC;YAClB,IAAI,CAAC,oBAAoB,IAAI,OAAO,CAAC;QACtC,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC;IAAA,CACvE;IAEO,mBAAmB,CAAC,KAAc,EAAQ;QACjD,IAAI,CAAC,aAAa,KAAK,aAAa,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;YACtB,IAAI,CAAC;gBACJ,SAAS,CAAC,EAAE,CAAC,CAAC;YACf,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,aAAa,IAAI,mBAAmB,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;YACtE,CAAC;QACF,CAAC;IAAA,CACD;CACD","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport { closeSync, openSync, writeSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult } from \"@caupulican/pi-agent-core/node\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { getProcessWorkRun } from \"../../utils/work-directory.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\ttempDirectory?: string;\n\t/** Stream the complete output to disk even when the bounded in-memory view is not truncated. */\n\tpersistAllOutput?: boolean;\n\t/** Maximum raw bytes persisted to the managed output file. Defaults to no additional cap. */\n\tmaxPersistedBytes?: number;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n\tfullOutputError?: string;\n\tpersistedOutputTruncated?: boolean;\n\tpersistedOutputBytes?: number;\n}\n\nexport interface OutputPreview {\n\tcontent: string;\n\tskippedLines: number;\n}\n\nfunction defaultTempFilePath(directory: string, prefix: string): string {\n\tconst id = randomBytes(8).toString(\"hex\");\n\treturn join(directory, `${prefix}-${id}.log`);\n}\n\nconst MAX_APPEND_CHUNK_BYTES = 64 * 1024;\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\nfunction formatIoError(error: unknown): string {\n\tif (error instanceof Error) {\n\t\tconst code = (error as NodeJS.ErrnoException).code;\n\t\treturn code ? `${code}: ${error.message}` : error.message;\n\t}\n\treturn String(error);\n}\n\nfunction tailUtf8String(text: string, maxBytes: number): { text: string; bytes: number } {\n\tif (maxBytes <= 0 || text.length === 0) {\n\t\treturn { text: \"\", bytes: 0 };\n\t}\n\n\tconst buffer = Buffer.from(text, \"utf-8\");\n\tif (buffer.length <= maxBytes) {\n\t\treturn { text, bytes: buffer.length };\n\t}\n\n\tlet start = buffer.length - maxBytes;\n\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\tstart++;\n\t}\n\n\tconst result = buffer.subarray(start).toString(\"utf-8\");\n\treturn { text: result, bytes: byteLength(result) };\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps a bounded tail of\n * logical lines, and opens a temp file when the full output needs preserving.\n * Snapshot and preview work is bounded by configured output limits, never by\n * total command history.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly tempDirectory: string;\n\tprivate readonly persistAllOutput: boolean;\n\tprivate readonly maxPersistedBytes: number;\n\tprivate readonly decoder = new TextDecoder();\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate tailLines: string[] = [];\n\tprivate tailLineBytes: number[] = [];\n\tprivate tailLineStoredBytes: number[] = [];\n\tprivate tailStart = 0;\n\tprivate tailStoredBytes = 0;\n\tprivate currentLineText = \"\";\n\tprivate currentLineBytes = 0;\n\tprivate currentLineStoredBytes = 0;\n\tprivate lastCompletedLineBytes = 0;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileFd: number | undefined;\n\tprivate tempFileError: string | undefined;\n\tprivate persistedOutputBytes = 0;\n\tprivate persistedOutputTruncated = false;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t\tthis.tempDirectory = options.tempDirectory ?? getProcessWorkRun(getAgentDir(), \"outputs\", \"tool-streams\").path;\n\t\tthis.persistAllOutput = options.persistAllOutput ?? false;\n\t\tthis.maxPersistedBytes = options.maxPersistedBytes ?? Number.POSITIVE_INFINITY;\n\t}\n\n\tappend(data: Buffer): void {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tfor (let offset = 0; offset < data.length; offset += MAX_APPEND_CHUNK_BYTES) {\n\t\t\tthis.appendBlock(data.subarray(offset, offset + MAX_APPEND_CHUNK_BYTES));\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendDecodedText(this.decoder.decode());\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(this.maxLines, this.maxBytes);\n\n\t\tif (options.persistIfTruncated && snapshot.truncation.truncated) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t\tpersistedOutputTruncated: this.persistedOutputTruncated || undefined,\n\t\t\tpersistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,\n\t\t};\n\t}\n\n\tpreview(maxLines: number, maxBytes = this.maxBytes): OutputPreview {\n\t\tconst snapshot = this.previewSnapshot(maxLines, maxBytes);\n\t\treturn {\n\t\t\tcontent: snapshot.content,\n\t\t\tskippedLines: Math.max(0, this.totalLines - snapshot.truncation.outputLines),\n\t\t};\n\t}\n\n\tpreviewSnapshot(\n\t\tmaxLines: number,\n\t\tmaxBytes = this.maxBytes,\n\t\toptions: { persistIfFullTruncated?: boolean } = {},\n\t): OutputSnapshot {\n\t\tconst snapshot = this.buildSnapshot(maxLines, maxBytes);\n\t\tif (options.persistIfFullTruncated && this.shouldUseTempFile()) {\n\t\t\tthis.tryEnsureTempFile();\n\t\t}\n\t\treturn {\n\t\t\t...snapshot,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t\tpersistedOutputTruncated: this.persistedOutputTruncated || undefined,\n\t\t\tpersistedOutputBytes: this.persistedOutputTruncated ? this.persistedOutputBytes : undefined,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tconst fd = this.tempFileFd;\n\t\tif (fd === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tthis.tempFileFd = undefined;\n\t\ttry {\n\t\t\tcloseSync(fd);\n\t\t} catch (error) {\n\t\t\tthis.tempFileError ??= formatIoError(error);\n\t\t}\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.hasOpenLine ? this.currentLineBytes : this.lastCompletedLineBytes;\n\t}\n\n\tprivate appendBlock(data: Buffer): void {\n\t\tthis.totalRawBytes += data.length;\n\t\tthis.appendDecodedText(this.decoder.decode(data, { stream: true }));\n\n\t\tif (this.tempFileFd !== undefined || this.shouldUseTempFile()) {\n\t\t\tif (this.tryEnsureTempFile() && this.tempFileFd !== undefined) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.writePersisted(data);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.recordTempFileError(error);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.length > 0) {\n\t\t\t// Copy retained chunks: Buffer.subarray would pin a large caller buffer in memory.\n\t\t\tthis.rawChunks.push(Buffer.from(data));\n\t\t}\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.totalDecodedBytes += byteLength(text);\n\n\t\tlet segmentStart = 0;\n\t\tfor (\n\t\t\tlet newlineIndex = text.indexOf(\"\\n\");\n\t\t\tnewlineIndex !== -1;\n\t\t\tnewlineIndex = text.indexOf(\"\\n\", segmentStart)\n\t\t) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart, newlineIndex));\n\t\t\tthis.pushCompletedCurrentLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\n\t\tif (segmentStart < text.length) {\n\t\t\tthis.appendToCurrentLine(text.slice(segmentStart));\n\t\t}\n\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate appendToCurrentLine(segment: string): void {\n\t\tif (segment.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst segmentBytes = byteLength(segment);\n\t\tthis.currentLineBytes += segmentBytes;\n\t\tthis.hasOpenLine = true;\n\n\t\tif (segmentBytes >= this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(segment, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.currentLineText += segment;\n\t\tthis.currentLineStoredBytes += segmentBytes;\n\t\tif (this.currentLineStoredBytes > this.maxBytes) {\n\t\t\tconst tail = tailUtf8String(this.currentLineText, this.maxBytes);\n\t\t\tthis.currentLineText = tail.text;\n\t\t\tthis.currentLineStoredBytes = tail.bytes;\n\t\t}\n\t}\n\n\tprivate pushCompletedCurrentLine(): void {\n\t\tthis.completedLines++;\n\t\tthis.lastCompletedLineBytes = this.currentLineBytes;\n\t\tthis.tailLines.push(this.currentLineText);\n\t\tthis.tailLineBytes.push(this.currentLineBytes);\n\t\tthis.tailLineStoredBytes.push(this.currentLineStoredBytes);\n\t\tthis.tailStoredBytes += this.currentLineStoredBytes;\n\t\tthis.currentLineText = \"\";\n\t\tthis.currentLineBytes = 0;\n\t\tthis.currentLineStoredBytes = 0;\n\t\tthis.hasOpenLine = false;\n\t\tthis.trimStoredTail();\n\t}\n\n\tprivate trimStoredTail(): void {\n\t\twhile (this.completedTailLineCount() > this.maxLines || this.tailStoredBytes > this.maxBytes) {\n\t\t\tthis.tailStoredBytes -= this.tailLineStoredBytes[this.tailStart] ?? 0;\n\t\t\tthis.tailStart++;\n\t\t}\n\n\t\tif (this.tailStart > 1024 && this.tailStart * 2 > this.tailLines.length) {\n\t\t\tthis.tailLines = this.tailLines.slice(this.tailStart);\n\t\t\tthis.tailLineBytes = this.tailLineBytes.slice(this.tailStart);\n\t\t\tthis.tailLineStoredBytes = this.tailLineStoredBytes.slice(this.tailStart);\n\t\t\tthis.tailStart = 0;\n\t\t}\n\t}\n\n\tprivate completedTailLineCount(): number {\n\t\treturn this.tailLines.length - this.tailStart;\n\t}\n\n\tprivate buildSnapshot(maxLines: number, maxBytes: number): OutputSnapshot {\n\t\tconst truncated = this.totalLines > maxLines || this.totalDecodedBytes > maxBytes;\n\t\tconst outputLines: string[] = [];\n\t\tlet outputBytes = 0;\n\t\tlet outputLineCount = 0;\n\t\tlet truncatedBy: \"lines\" | \"bytes\" = this.totalLines > maxLines ? \"lines\" : \"bytes\";\n\t\tlet lastLinePartial = false;\n\t\tlet readCurrent = this.hasOpenLine;\n\t\tlet completedIndex = this.tailLines.length - 1;\n\n\t\twhile (outputLineCount < maxLines) {\n\t\t\tlet line: string;\n\t\t\tlet lineBytes: number;\n\t\t\tlet storedBytes: number;\n\t\t\tif (readCurrent) {\n\t\t\t\tline = this.currentLineText;\n\t\t\t\tlineBytes = this.currentLineBytes;\n\t\t\t\tstoredBytes = this.currentLineStoredBytes;\n\t\t\t\treadCurrent = false;\n\t\t\t} else {\n\t\t\t\tif (completedIndex < this.tailStart) break;\n\t\t\t\tline = this.tailLines[completedIndex] ?? \"\";\n\t\t\t\tlineBytes = this.tailLineBytes[completedIndex] ?? 0;\n\t\t\t\tstoredBytes = this.tailLineStoredBytes[completedIndex] ?? 0;\n\t\t\t\tcompletedIndex--;\n\t\t\t}\n\n\t\t\tconst separatorBytes = outputLineCount > 0 ? 1 : 0;\n\t\t\tconst fullLineBytes = lineBytes + separatorBytes;\n\t\t\tif (outputBytes + fullLineBytes > maxBytes) {\n\t\t\t\ttruncatedBy = \"bytes\";\n\t\t\t\tif (outputLineCount === 0) {\n\t\t\t\t\tconst partial =\n\t\t\t\t\t\tlineBytes > maxBytes ? tailUtf8String(line, maxBytes) : { text: line, bytes: storedBytes };\n\t\t\t\t\toutputLines.unshift(partial.text);\n\t\t\t\t\toutputBytes = partial.bytes;\n\t\t\t\t\toutputLineCount = 1;\n\t\t\t\t\tlastLinePartial = lineBytes > partial.bytes;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\toutputLines.unshift(line);\n\t\t\toutputBytes += storedBytes + separatorBytes;\n\t\t\toutputLineCount++;\n\t\t}\n\n\t\tlet content = outputLines.join(\"\\n\");\n\t\tif (!truncated && !this.hasOpenLine && this.totalLines > 0) {\n\t\t\tcontent += \"\\n\";\n\t\t\toutputBytes += 1;\n\t\t}\n\n\t\tconst effectiveTruncatedBy = truncated ? truncatedBy : null;\n\t\tconst truncation: TruncationResult = {\n\t\t\tcontent,\n\t\t\ttruncated,\n\t\t\ttruncatedBy: effectiveTruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\toutputLines: outputLineCount,\n\t\t\toutputBytes,\n\t\t\tlastLinePartial,\n\t\t\tfirstLineExceedsLimit: false,\n\t\t\tmaxLines,\n\t\t\tmaxBytes,\n\t\t};\n\n\t\treturn {\n\t\t\tcontent,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.fullOutputPath(),\n\t\t\tfullOutputError: this.tempFileError,\n\t\t};\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.persistAllOutput ||\n\t\t\tthis.totalRawBytes > this.maxBytes ||\n\t\t\tthis.totalDecodedBytes > this.maxBytes ||\n\t\t\tthis.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate fullOutputPath(): string | undefined {\n\t\treturn this.tempFileError === undefined ? this.tempFilePath : undefined;\n\t}\n\n\tprivate tryEnsureTempFile(): boolean {\n\t\tif (this.tempFileError !== undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tif (this.tempFileFd !== undefined) {\n\t\t\treturn true;\n\t\t}\n\t\ttry {\n\t\t\tthis.tempFilePath ??= defaultTempFilePath(this.tempDirectory, this.tempFilePrefix);\n\t\t\tthis.tempFileFd = openSync(this.tempFilePath, \"w\");\n\t\t\tfor (const chunk of this.rawChunks) {\n\t\t\t\tthis.writePersisted(chunk);\n\t\t\t}\n\t\t\tthis.rawChunks = [];\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\tthis.recordTempFileError(error);\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tprivate writePersisted(data: Buffer): void {\n\t\tif (this.tempFileFd === undefined || data.length === 0) return;\n\t\tconst remaining = Math.max(0, this.maxPersistedBytes - this.persistedOutputBytes);\n\t\tif (remaining === 0) {\n\t\t\tthis.persistedOutputTruncated = true;\n\t\t\treturn;\n\t\t}\n\t\tconst bounded = data.length > remaining ? data.subarray(0, remaining) : data;\n\t\tlet offset = 0;\n\t\twhile (offset < bounded.length) {\n\t\t\tconst written = writeSync(this.tempFileFd, bounded, offset, bounded.length - offset);\n\t\t\tif (written <= 0) throw new Error(\"Managed output write made no progress\");\n\t\t\toffset += written;\n\t\t\tthis.persistedOutputBytes += written;\n\t\t}\n\t\tif (bounded.length < data.length) this.persistedOutputTruncated = true;\n\t}\n\n\tprivate recordTempFileError(error: unknown): void {\n\t\tthis.tempFileError ??= formatIoError(error);\n\t\tconst fd = this.tempFileFd;\n\t\tthis.tempFileFd = undefined;\n\t\tif (fd !== undefined) {\n\t\t\ttry {\n\t\t\t\tcloseSync(fd);\n\t\t\t} catch (closeError) {\n\t\t\t\tthis.tempFileError += `; close failed: ${formatIoError(closeError)}`;\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -54,6 +54,8 @@ export interface PythonOperations {
|
|
|
54
54
|
export interface PythonToolOptions {
|
|
55
55
|
resolveRuntime?: () => Promise<PythonRuntimeOutcome>;
|
|
56
56
|
operations?: PythonOperations;
|
|
57
|
+
/** Additional process environment resolved from the final execution cwd. */
|
|
58
|
+
environment?: (cwd: string) => NodeJS.ProcessEnv;
|
|
57
59
|
/** Override only for tests or embedded runtimes; production uses the process work directory. */
|
|
58
60
|
outputDirectory?: string;
|
|
59
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../../src/core/tools/python.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAuB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,C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WAAW,qBAAqB;IACrC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACzC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAChC,IAAI,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACtE;AAED,MAAM,WAAW,iBAAiB;IACjC,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACrD,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,gGAAgG;IAChG,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC1C,MAAM,CAER;AAsDD,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,iBAAsB,GAC7B,cAAc,CAAC,OAAO,YAAY,EAAE,iBAAiB,CAAC,CAoJxD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC,OAAO,YAAY,CAAC,CAE7G","sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { posix, win32 } from \"node:path\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport type { TruncationResult } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"../python-runtime.ts\";\nimport { withExclusiveMutationBarrier } from \"./file-mutation-queue.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nexport const DEFAULT_PYTHON_TIMEOUT_SECONDS = 30;\nexport const MAX_PYTHON_TIMEOUT_SECONDS = 300;\nexport const MAX_PYTHON_OUTPUT_BYTES = 200_000;\nconst MIN_PYTHON_OUTPUT_BYTES = 1_000;\nconst PYTHON_KILL_GRACE_MS = 2_000;\n\nconst pythonSchema = Type.Object(\n\t{\n\t\tcode: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python code to execute on stdin. Provide exactly one of code or scriptPath.\",\n\t\t\t\tmaxLength: 200_000,\n\t\t\t}),\n\t\t),\n\t\tscriptPath: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python script path. Relative paths resolve from cwd; one leading @ is ignored.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\targs: Type.Optional(\n\t\t\tType.Array(Type.String({ maxLength: 16_384 }), {\n\t\t\t\tdescription: \"Arguments passed directly to Python after '-' or scriptPath; no shell interpolation.\",\n\t\t\t\tmaxItems: 256,\n\t\t\t}),\n\t\t),\n\t\tcwd: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Working directory. Defaults to Pi's cwd; relative paths resolve from Pi's cwd.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\ttimeoutSeconds: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Wall-clock timeout. Defaults to ${DEFAULT_PYTHON_TIMEOUT_SECONDS} seconds and is capped at ${MAX_PYTHON_TIMEOUT_SECONDS}.`,\n\t\t\t}),\n\t\t),\n\t\tmaxOutputBytes: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Maximum returned bytes per stream before full output spills to a work artifact. Maximum ${MAX_PYTHON_OUTPUT_BYTES}.`,\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type PythonToolInput = Static<typeof pythonSchema>;\n\nexport interface PythonToolDetails {\n\tmode: \"code\" | \"script\";\n\tcwd: string;\n\tuvPath: string;\n\tpythonPath: string;\n\tscriptPath?: string;\n\targs: string[];\n\texitCode: number | null;\n\tsignal: string | null;\n\ttimedOut: boolean;\n\tstdoutTruncation?: TruncationResult;\n\tstderrTruncation?: TruncationResult;\n\tstdoutOutputPath?: string;\n\tstderrOutputPath?: string;\n\tstdoutOutputError?: string;\n\tstderrOutputError?: string;\n}\n\nexport interface PythonExecutionRequest {\n\tpython: string;\n\targs: string[];\n\tcwd: string;\n\tstdin?: string;\n\ttimeoutMs: number;\n\tsignal?: AbortSignal;\n\tenv: NodeJS.ProcessEnv;\n\tonStdout: (chunk: Buffer) => void;\n\tonStderr: (chunk: Buffer) => void;\n}\n\nexport interface PythonExecutionResult {\n\texitCode: number | null;\n\treason: \"exited\" | \"aborted\" | \"timeout\";\n\tsignal: string | null;\n}\n\nexport interface PythonOperations {\n\texec(request: PythonExecutionRequest): Promise<PythonExecutionResult>;\n}\n\nexport interface PythonToolOptions {\n\tresolveRuntime?: () => Promise<PythonRuntimeOutcome>;\n\toperations?: PythonOperations;\n\t/** Override only for tests or embedded runtimes; production uses the process work directory. */\n\toutputDirectory?: string;\n}\n\nfunction stripAtPrefix(value: string): string {\n\treturn value.startsWith(\"@\") ? value.slice(1) : value;\n}\n\nexport function resolvePythonToolPath(\n\tbase: string,\n\trequested: string,\n\tplatform: NodeJS.Platform = process.platform,\n): string {\n\treturn (platform === \"win32\" ? win32 : posix).resolve(base, stripAtPrefix(requested));\n}\n\nasync function resolveWorkingDirectory(baseCwd: string, requested?: string): Promise<string> {\n\tconst cwd = requested ? resolvePythonToolPath(baseCwd, requested) : baseCwd;\n\tconst entry = await stat(cwd).catch(() => {\n\t\tthrow new Error(`cwd does not exist: ${cwd}`);\n\t});\n\tif (!entry.isDirectory()) throw new Error(`cwd is not a directory: ${cwd}`);\n\treturn cwd;\n}\n\nasync function resolveScriptPath(cwd: string, requested: string): Promise<string> {\n\tconst scriptPath = resolvePythonToolPath(cwd, requested);\n\tconst entry = await stat(scriptPath).catch(() => {\n\t\tthrow new Error(`scriptPath does not exist: ${scriptPath}`);\n\t});\n\tif (!entry.isFile()) throw new Error(`scriptPath is not a file: ${scriptPath}`);\n\treturn scriptPath;\n}\n\nfunction clampInteger(value: number | undefined, fallback: number, minimum: number, maximum: number): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value <= 0) return fallback;\n\treturn Math.max(minimum, Math.min(maximum, Math.trunc(value)));\n}\n\nfunction createLocalPythonOperations(): PythonOperations {\n\treturn {\n\t\tasync exec(request) {\n\t\t\tif (request.signal?.aborted) throw new Error(\"Python execution aborted before start\");\n\t\t\tconst child = spawnProcess(request.python, request.args, {\n\t\t\t\tcwd: request.cwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: request.env,\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => request.onStdout(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => request.onStderr(chunk));\n\t\t\tchild.stdin?.end(request.stdin ?? \"\");\n\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\tkillGraceMs: PYTHON_KILL_GRACE_MS,\n\t\t\t\tsignal: request.signal,\n\t\t\t\ttimeoutMs: request.timeoutMs,\n\t\t\t});\n\t\t\treturn { exitCode: terminal.code, reason: terminal.reason, signal: child.signalCode };\n\t\t},\n\t};\n}\n\nfunction renderStreamNotice(label: string, path: string | undefined, error: string | undefined): string | undefined {\n\tif (path) return `[${label} truncated; full output: ${path}]`;\n\tif (error) return `[${label} truncated; full-output artifact failed: ${error}]`;\n\treturn undefined;\n}\n\nexport function createPythonToolDefinition(\n\tbaseCwd: string,\n\toptions: PythonToolOptions = {},\n): ToolDefinition<typeof pythonSchema, PythonToolDetails> {\n\tconst resolveRuntime = options.resolveRuntime ?? (() => ensurePythonRuntime({ silent: true }));\n\tconst operations = options.operations ?? createLocalPythonOperations();\n\treturn {\n\t\tname: \"python\",\n\t\tlabel: \"python\",\n\t\tdescription: `Run a bounded Python snippet or script without a shell. Pi resolves Python through uv, defaults to a ${DEFAULT_PYTHON_TIMEOUT_SECONDS}-second wall-clock timeout (maximum ${MAX_PYTHON_TIMEOUT_SECONDS}), streams bounded stdout/stderr, and spills truncated full output to the process work directory rather than the repository.`,\n\t\tpromptSnippet: \"Run bounded Python snippets or scripts through Pi's uv-managed runtime.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Prefer python for bounded scripts, data shaping, structured transformations, and cross-platform logic when it is clearer than a shell pipeline.\",\n\t\t\t\"Prefer read/edit/write for small exact source edits. For Python file transformations, preserve encoding and newline style, write atomically, and verify the resulting diff.\",\n\t\t\t\"Keep work scoped: avoid recursive home/filesystem scans, pass explicit roots and filters, and request a larger timeout only when the bounded workload justifies it.\",\n\t\t\t\"Do not use python for destructive deletion, credentials, publish/push/release, or long-running services without explicit user approval.\",\n\t\t],\n\t\tparameters: pythonSchema,\n\t\tasync execute(_toolCallId, input, signal) {\n\t\t\tconst hasCode = typeof input.code === \"string\";\n\t\t\tconst hasScript = typeof input.scriptPath === \"string\" && input.scriptPath.trim().length > 0;\n\t\t\tif (hasCode === hasScript) throw new Error(\"Provide exactly one of code or scriptPath.\");\n\t\t\tconst cwd = await resolveWorkingDirectory(baseCwd, input.cwd);\n\t\t\tconst scriptPath = hasScript ? await resolveScriptPath(cwd, input.scriptPath as string) : undefined;\n\t\t\tconst runtime = await resolveRuntime();\n\t\t\tif (runtime.status !== \"ready\") throw new Error(runtime.reason);\n\t\t\tconst args = input.args ? [...input.args] : [];\n\t\t\tconst timeoutSeconds = clampInteger(\n\t\t\t\tinput.timeoutSeconds,\n\t\t\t\tDEFAULT_PYTHON_TIMEOUT_SECONDS,\n\t\t\t\t1,\n\t\t\t\tMAX_PYTHON_TIMEOUT_SECONDS,\n\t\t\t);\n\t\t\tconst maxOutputBytes = clampInteger(\n\t\t\t\tinput.maxOutputBytes,\n\t\t\t\t50 * 1024,\n\t\t\t\tMIN_PYTHON_OUTPUT_BYTES,\n\t\t\t\tMAX_PYTHON_OUTPUT_BYTES,\n\t\t\t);\n\t\t\tconst accumulatorOptions = {\n\t\t\t\tmaxBytes: maxOutputBytes,\n\t\t\t\t...(options.outputDirectory ? { tempDirectory: options.outputDirectory } : {}),\n\t\t\t};\n\t\t\tconst stdout = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stdout\" });\n\t\t\tconst stderr = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stderr\" });\n\t\t\tconst finishStreams = () => {\n\t\t\t\tstdout.finish();\n\t\t\t\tstderr.finish();\n\t\t\t\treturn {\n\t\t\t\t\tstdout: stdout.snapshot({ persistIfTruncated: true }),\n\t\t\t\t\tstderr: stderr.snapshot({ persistIfTruncated: true }),\n\t\t\t\t};\n\t\t\t};\n\t\t\tlet execution: PythonExecutionResult;\n\t\t\ttry {\n\t\t\t\texecution = await withExclusiveMutationBarrier(() =>\n\t\t\t\t\toperations.exec({\n\t\t\t\t\t\tpython: runtime.pythonPath,\n\t\t\t\t\t\targs: scriptPath ? [\"-B\", scriptPath, ...args] : [\"-B\", \"-\", ...args],\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tstdin: hasCode ? input.code : undefined,\n\t\t\t\t\t\ttimeoutMs: timeoutSeconds * 1000,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tenv: {\n\t\t\t\t\t\t\t...process.env,\n\t\t\t\t\t\t\tPI_PYTHON_TOOL: \"1\",\n\t\t\t\t\t\t\tPYTHONDONTWRITEBYTECODE: \"1\",\n\t\t\t\t\t\t\tPYTHONIOENCODING: \"utf-8\",\n\t\t\t\t\t\t\tPYTHONUNBUFFERED: \"1\",\n\t\t\t\t\t\t\tPYTHONUTF8: \"1\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonStdout: (chunk) => stdout.append(chunk),\n\t\t\t\t\t\tonStderr: (chunk) => stderr.append(chunk),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconst snapshots = finishStreams();\n\t\t\t\tconst sections: string[] = [];\n\t\t\t\tif (snapshots.stdout.content) sections.push(snapshots.stdout.content.trimEnd());\n\t\t\t\tif (snapshots.stderr.content) sections.push(`[stderr]\\n${snapshots.stderr.content.trimEnd()}`);\n\t\t\t\tconst stdoutNotice = renderStreamNotice(\n\t\t\t\t\t\"stdout\",\n\t\t\t\t\tsnapshots.stdout.fullOutputPath,\n\t\t\t\t\tsnapshots.stdout.fullOutputError,\n\t\t\t\t);\n\t\t\t\tconst stderrNotice = renderStreamNotice(\n\t\t\t\t\t\"stderr\",\n\t\t\t\t\tsnapshots.stderr.fullOutputPath,\n\t\t\t\t\tsnapshots.stderr.fullOutputError,\n\t\t\t\t);\n\t\t\t\tif (stdoutNotice) sections.push(stdoutNotice);\n\t\t\t\tif (stderrNotice) sections.push(stderrNotice);\n\t\t\t\tconst status = `[python exitCode=${execution.exitCode ?? \"null\"}${execution.signal ? `; signal=${execution.signal}` : \"\"}]`;\n\t\t\t\tsections.push(status);\n\t\t\t\tconst text = sections.join(\"\\n\\n\");\n\t\t\t\tif (execution.reason === \"timeout\")\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython timed out after ${timeoutSeconds} seconds`);\n\t\t\t\tif (execution.reason === \"aborted\") throw new Error(`${text}\\n\\nPython execution aborted`);\n\t\t\t\tif (execution.exitCode !== 0) {\n\t\t\t\t\tconst termination = execution.signal\n\t\t\t\t\t\t? `signal ${execution.signal}`\n\t\t\t\t\t\t: `code ${execution.exitCode ?? \"unknown\"}`;\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython exited with ${termination}`);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: scriptPath ? \"script\" : \"code\",\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tuvPath: runtime.uvPath,\n\t\t\t\t\t\tpythonPath: runtime.pythonPath,\n\t\t\t\t\t\tscriptPath,\n\t\t\t\t\t\targs,\n\t\t\t\t\t\texitCode: execution.exitCode,\n\t\t\t\t\t\tsignal: execution.signal,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\t...(snapshots.stdout.truncation.truncated ? { stdoutTruncation: snapshots.stdout.truncation } : {}),\n\t\t\t\t\t\t...(snapshots.stderr.truncation.truncated ? { stderrTruncation: snapshots.stderr.truncation } : {}),\n\t\t\t\t\t\tstdoutOutputPath: snapshots.stdout.fullOutputPath,\n\t\t\t\t\t\tstderrOutputPath: snapshots.stderr.fullOutputPath,\n\t\t\t\t\t\tstdoutOutputError: snapshots.stdout.fullOutputError,\n\t\t\t\t\t\tstderrOutputError: snapshots.stderr.fullOutputError,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tawait Promise.all([stdout.closeTempFile(), stderr.closeTempFile()]);\n\t\t\t}\n\t\t},\n\t\trenderCall(args, theme) {\n\t\t\tconst mode = args.scriptPath ? args.scriptPath : \"code\";\n\t\t\treturn new Text(`${theme.fg(\"toolTitle\", theme.bold(\"python\"))} ${theme.fg(\"muted\", mode)}`, 0, 0);\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return new Text(theme.fg(\"warning\", \"python running\"), 0, 0);\n\t\t\tconst details = result.details as PythonToolDetails | undefined;\n\t\t\tif (!details) return new Text(theme.fg(\"dim\", \"python done\"), 0, 0);\n\t\t\tconst status =\n\t\t\t\tdetails.exitCode === 0 && !details.timedOut ? \"python ok\" : `python exit ${details.exitCode ?? \"unknown\"}`;\n\t\t\tlet text = theme.fg(details.exitCode === 0 ? \"success\" : \"warning\", status);\n\t\t\tif (expanded) {\n\t\t\t\tconst content = result.content[0];\n\t\t\t\tif (content?.type === \"text\") {\n\t\t\t\t\tconst lines = content.text.split(\"\\n\").slice(-20);\n\t\t\t\t\tfor (const line of lines) text += `\\n${theme.fg(\"dim\", line)}`;\n\t\t\t\t}\n\t\t\t\tfor (const outputPath of [details.stdoutOutputPath, details.stderrOutputPath]) {\n\t\t\t\t\tif (outputPath) text += `\\n${theme.fg(\"muted\", `full output: ${outputPath}`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t};\n}\n\nexport function createPythonTool(baseCwd: string, options?: PythonToolOptions): AgentTool<typeof pythonSchema> {\n\treturn wrapToolDefinition(createPythonToolDefinition(baseCwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../../src/core/tools/python.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAuB,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAKtF,eAAO,MAAM,8BAA8B,KAAK,CAAC;AACjD,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAI/C,QAAA,MAAM,YAAY;;;;;;;EAsCjB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;AAE1D,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf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,CAAC,UAAU,CAAC;IACjD,gGAAgG;IAChG,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD,wBAAgB,qBAAqB,CACpC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAC1C,MAAM,CAER;AAsDD,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,iBAAsB,GAC7B,cAAc,CAAC,OAAO,YAAY,EAAE,iBAAiB,CAAC,CAsJxD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC,OAAO,YAAY,CAAC,CAE7G","sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { posix, win32 } from \"node:path\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport type { TruncationResult } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"../python-runtime.ts\";\nimport { withExclusiveMutationBarrier } from \"./file-mutation-queue.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nexport const DEFAULT_PYTHON_TIMEOUT_SECONDS = 30;\nexport const MAX_PYTHON_TIMEOUT_SECONDS = 300;\nexport const MAX_PYTHON_OUTPUT_BYTES = 200_000;\nconst MIN_PYTHON_OUTPUT_BYTES = 1_000;\nconst PYTHON_KILL_GRACE_MS = 2_000;\n\nconst pythonSchema = Type.Object(\n\t{\n\t\tcode: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python code to execute on stdin. Provide exactly one of code or scriptPath.\",\n\t\t\t\tmaxLength: 200_000,\n\t\t\t}),\n\t\t),\n\t\tscriptPath: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python script path. Relative paths resolve from cwd; one leading @ is ignored.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\targs: Type.Optional(\n\t\t\tType.Array(Type.String({ maxLength: 16_384 }), {\n\t\t\t\tdescription: \"Arguments passed directly to Python after '-' or scriptPath; no shell interpolation.\",\n\t\t\t\tmaxItems: 256,\n\t\t\t}),\n\t\t),\n\t\tcwd: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Working directory. Defaults to Pi's cwd; relative paths resolve from Pi's cwd.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\ttimeoutSeconds: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Wall-clock timeout. Defaults to ${DEFAULT_PYTHON_TIMEOUT_SECONDS} seconds and is capped at ${MAX_PYTHON_TIMEOUT_SECONDS}.`,\n\t\t\t}),\n\t\t),\n\t\tmaxOutputBytes: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Maximum returned bytes per stream before full output spills to a work artifact. Maximum ${MAX_PYTHON_OUTPUT_BYTES}.`,\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type PythonToolInput = Static<typeof pythonSchema>;\n\nexport interface PythonToolDetails {\n\tmode: \"code\" | \"script\";\n\tcwd: string;\n\tuvPath: string;\n\tpythonPath: string;\n\tscriptPath?: string;\n\targs: string[];\n\texitCode: number | null;\n\tsignal: string | null;\n\ttimedOut: boolean;\n\tstdoutTruncation?: TruncationResult;\n\tstderrTruncation?: TruncationResult;\n\tstdoutOutputPath?: string;\n\tstderrOutputPath?: string;\n\tstdoutOutputError?: string;\n\tstderrOutputError?: string;\n}\n\nexport interface PythonExecutionRequest {\n\tpython: string;\n\targs: string[];\n\tcwd: string;\n\tstdin?: string;\n\ttimeoutMs: number;\n\tsignal?: AbortSignal;\n\tenv: NodeJS.ProcessEnv;\n\tonStdout: (chunk: Buffer) => void;\n\tonStderr: (chunk: Buffer) => void;\n}\n\nexport interface PythonExecutionResult {\n\texitCode: number | null;\n\treason: \"exited\" | \"aborted\" | \"timeout\";\n\tsignal: string | null;\n}\n\nexport interface PythonOperations {\n\texec(request: PythonExecutionRequest): Promise<PythonExecutionResult>;\n}\n\nexport interface PythonToolOptions {\n\tresolveRuntime?: () => Promise<PythonRuntimeOutcome>;\n\toperations?: PythonOperations;\n\t/** Additional process environment resolved from the final execution cwd. */\n\tenvironment?: (cwd: string) => NodeJS.ProcessEnv;\n\t/** Override only for tests or embedded runtimes; production uses the process work directory. */\n\toutputDirectory?: string;\n}\n\nfunction stripAtPrefix(value: string): string {\n\treturn value.startsWith(\"@\") ? value.slice(1) : value;\n}\n\nexport function resolvePythonToolPath(\n\tbase: string,\n\trequested: string,\n\tplatform: NodeJS.Platform = process.platform,\n): string {\n\treturn (platform === \"win32\" ? win32 : posix).resolve(base, stripAtPrefix(requested));\n}\n\nasync function resolveWorkingDirectory(baseCwd: string, requested?: string): Promise<string> {\n\tconst cwd = requested ? resolvePythonToolPath(baseCwd, requested) : baseCwd;\n\tconst entry = await stat(cwd).catch(() => {\n\t\tthrow new Error(`cwd does not exist: ${cwd}`);\n\t});\n\tif (!entry.isDirectory()) throw new Error(`cwd is not a directory: ${cwd}`);\n\treturn cwd;\n}\n\nasync function resolveScriptPath(cwd: string, requested: string): Promise<string> {\n\tconst scriptPath = resolvePythonToolPath(cwd, requested);\n\tconst entry = await stat(scriptPath).catch(() => {\n\t\tthrow new Error(`scriptPath does not exist: ${scriptPath}`);\n\t});\n\tif (!entry.isFile()) throw new Error(`scriptPath is not a file: ${scriptPath}`);\n\treturn scriptPath;\n}\n\nfunction clampInteger(value: number | undefined, fallback: number, minimum: number, maximum: number): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value <= 0) return fallback;\n\treturn Math.max(minimum, Math.min(maximum, Math.trunc(value)));\n}\n\nfunction createLocalPythonOperations(): PythonOperations {\n\treturn {\n\t\tasync exec(request) {\n\t\t\tif (request.signal?.aborted) throw new Error(\"Python execution aborted before start\");\n\t\t\tconst child = spawnProcess(request.python, request.args, {\n\t\t\t\tcwd: request.cwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: request.env,\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => request.onStdout(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => request.onStderr(chunk));\n\t\t\tchild.stdin?.end(request.stdin ?? \"\");\n\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\tkillGraceMs: PYTHON_KILL_GRACE_MS,\n\t\t\t\tsignal: request.signal,\n\t\t\t\ttimeoutMs: request.timeoutMs,\n\t\t\t});\n\t\t\treturn { exitCode: terminal.code, reason: terminal.reason, signal: child.signalCode };\n\t\t},\n\t};\n}\n\nfunction renderStreamNotice(label: string, path: string | undefined, error: string | undefined): string | undefined {\n\tif (path) return `[${label} truncated; full output: ${path}]`;\n\tif (error) return `[${label} truncated; full-output artifact failed: ${error}]`;\n\treturn undefined;\n}\n\nexport function createPythonToolDefinition(\n\tbaseCwd: string,\n\toptions: PythonToolOptions = {},\n): ToolDefinition<typeof pythonSchema, PythonToolDetails> {\n\tconst resolveRuntime = options.resolveRuntime ?? (() => ensurePythonRuntime({ silent: true }));\n\tconst operations = options.operations ?? createLocalPythonOperations();\n\treturn {\n\t\tname: \"python\",\n\t\tlabel: \"python\",\n\t\tdescription: `Run a bounded Python snippet or script without a shell. Pi resolves Python through uv, defaults to a ${DEFAULT_PYTHON_TIMEOUT_SECONDS}-second wall-clock timeout (maximum ${MAX_PYTHON_TIMEOUT_SECONDS}), streams bounded stdout/stderr, and spills truncated full output to the process work directory rather than the repository.`,\n\t\tpromptSnippet: \"Run bounded Python snippets or scripts through Pi's uv-managed runtime.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Prefer python for bounded scripts, data shaping, structured transformations, and cross-platform logic when it is clearer than a shell pipeline.\",\n\t\t\t\"Prefer read/edit/write for small exact source edits. For Python file transformations, preserve encoding and newline style, write atomically, and verify the resulting diff.\",\n\t\t\t\"Keep work scoped: avoid recursive home/filesystem scans, pass explicit roots and filters, and request a larger timeout only when the bounded workload justifies it.\",\n\t\t\t\"Do not inspect or print credentials. When secret_store activates a bound profile, use its injected environment only through the credential-consuming program.\",\n\t\t\t\"Do not use python for destructive deletion, publish/push/release, or long-running services without explicit user approval.\",\n\t\t],\n\t\tparameters: pythonSchema,\n\t\tasync execute(_toolCallId, input, signal) {\n\t\t\tconst hasCode = typeof input.code === \"string\";\n\t\t\tconst hasScript = typeof input.scriptPath === \"string\" && input.scriptPath.trim().length > 0;\n\t\t\tif (hasCode === hasScript) throw new Error(\"Provide exactly one of code or scriptPath.\");\n\t\t\tconst cwd = await resolveWorkingDirectory(baseCwd, input.cwd);\n\t\t\tconst scriptPath = hasScript ? await resolveScriptPath(cwd, input.scriptPath as string) : undefined;\n\t\t\tconst runtime = await resolveRuntime();\n\t\t\tif (runtime.status !== \"ready\") throw new Error(runtime.reason);\n\t\t\tconst args = input.args ? [...input.args] : [];\n\t\t\tconst timeoutSeconds = clampInteger(\n\t\t\t\tinput.timeoutSeconds,\n\t\t\t\tDEFAULT_PYTHON_TIMEOUT_SECONDS,\n\t\t\t\t1,\n\t\t\t\tMAX_PYTHON_TIMEOUT_SECONDS,\n\t\t\t);\n\t\t\tconst maxOutputBytes = clampInteger(\n\t\t\t\tinput.maxOutputBytes,\n\t\t\t\t50 * 1024,\n\t\t\t\tMIN_PYTHON_OUTPUT_BYTES,\n\t\t\t\tMAX_PYTHON_OUTPUT_BYTES,\n\t\t\t);\n\t\t\tconst accumulatorOptions = {\n\t\t\t\tmaxBytes: maxOutputBytes,\n\t\t\t\t...(options.outputDirectory ? { tempDirectory: options.outputDirectory } : {}),\n\t\t\t};\n\t\t\tconst stdout = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stdout\" });\n\t\t\tconst stderr = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stderr\" });\n\t\t\tconst finishStreams = () => {\n\t\t\t\tstdout.finish();\n\t\t\t\tstderr.finish();\n\t\t\t\treturn {\n\t\t\t\t\tstdout: stdout.snapshot({ persistIfTruncated: true }),\n\t\t\t\t\tstderr: stderr.snapshot({ persistIfTruncated: true }),\n\t\t\t\t};\n\t\t\t};\n\t\t\tlet execution: PythonExecutionResult;\n\t\t\ttry {\n\t\t\t\texecution = await withExclusiveMutationBarrier(() =>\n\t\t\t\t\toperations.exec({\n\t\t\t\t\t\tpython: runtime.pythonPath,\n\t\t\t\t\t\targs: scriptPath ? [\"-B\", scriptPath, ...args] : [\"-B\", \"-\", ...args],\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tstdin: hasCode ? input.code : undefined,\n\t\t\t\t\t\ttimeoutMs: timeoutSeconds * 1000,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tenv: {\n\t\t\t\t\t\t\t...process.env,\n\t\t\t\t\t\t\t...options.environment?.(cwd),\n\t\t\t\t\t\t\tPI_PYTHON_TOOL: \"1\",\n\t\t\t\t\t\t\tPYTHONDONTWRITEBYTECODE: \"1\",\n\t\t\t\t\t\t\tPYTHONIOENCODING: \"utf-8\",\n\t\t\t\t\t\t\tPYTHONUNBUFFERED: \"1\",\n\t\t\t\t\t\t\tPYTHONUTF8: \"1\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonStdout: (chunk) => stdout.append(chunk),\n\t\t\t\t\t\tonStderr: (chunk) => stderr.append(chunk),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconst snapshots = finishStreams();\n\t\t\t\tconst sections: string[] = [];\n\t\t\t\tif (snapshots.stdout.content) sections.push(snapshots.stdout.content.trimEnd());\n\t\t\t\tif (snapshots.stderr.content) sections.push(`[stderr]\\n${snapshots.stderr.content.trimEnd()}`);\n\t\t\t\tconst stdoutNotice = renderStreamNotice(\n\t\t\t\t\t\"stdout\",\n\t\t\t\t\tsnapshots.stdout.fullOutputPath,\n\t\t\t\t\tsnapshots.stdout.fullOutputError,\n\t\t\t\t);\n\t\t\t\tconst stderrNotice = renderStreamNotice(\n\t\t\t\t\t\"stderr\",\n\t\t\t\t\tsnapshots.stderr.fullOutputPath,\n\t\t\t\t\tsnapshots.stderr.fullOutputError,\n\t\t\t\t);\n\t\t\t\tif (stdoutNotice) sections.push(stdoutNotice);\n\t\t\t\tif (stderrNotice) sections.push(stderrNotice);\n\t\t\t\tconst status = `[python exitCode=${execution.exitCode ?? \"null\"}${execution.signal ? `; signal=${execution.signal}` : \"\"}]`;\n\t\t\t\tsections.push(status);\n\t\t\t\tconst text = sections.join(\"\\n\\n\");\n\t\t\t\tif (execution.reason === \"timeout\")\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython timed out after ${timeoutSeconds} seconds`);\n\t\t\t\tif (execution.reason === \"aborted\") throw new Error(`${text}\\n\\nPython execution aborted`);\n\t\t\t\tif (execution.exitCode !== 0) {\n\t\t\t\t\tconst termination = execution.signal\n\t\t\t\t\t\t? `signal ${execution.signal}`\n\t\t\t\t\t\t: `code ${execution.exitCode ?? \"unknown\"}`;\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython exited with ${termination}`);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: scriptPath ? \"script\" : \"code\",\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tuvPath: runtime.uvPath,\n\t\t\t\t\t\tpythonPath: runtime.pythonPath,\n\t\t\t\t\t\tscriptPath,\n\t\t\t\t\t\targs,\n\t\t\t\t\t\texitCode: execution.exitCode,\n\t\t\t\t\t\tsignal: execution.signal,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\t...(snapshots.stdout.truncation.truncated ? { stdoutTruncation: snapshots.stdout.truncation } : {}),\n\t\t\t\t\t\t...(snapshots.stderr.truncation.truncated ? { stderrTruncation: snapshots.stderr.truncation } : {}),\n\t\t\t\t\t\tstdoutOutputPath: snapshots.stdout.fullOutputPath,\n\t\t\t\t\t\tstderrOutputPath: snapshots.stderr.fullOutputPath,\n\t\t\t\t\t\tstdoutOutputError: snapshots.stdout.fullOutputError,\n\t\t\t\t\t\tstderrOutputError: snapshots.stderr.fullOutputError,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tawait Promise.all([stdout.closeTempFile(), stderr.closeTempFile()]);\n\t\t\t}\n\t\t},\n\t\trenderCall(args, theme) {\n\t\t\tconst mode = args.scriptPath ? args.scriptPath : \"code\";\n\t\t\treturn new Text(`${theme.fg(\"toolTitle\", theme.bold(\"python\"))} ${theme.fg(\"muted\", mode)}`, 0, 0);\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return new Text(theme.fg(\"warning\", \"python running\"), 0, 0);\n\t\t\tconst details = result.details as PythonToolDetails | undefined;\n\t\t\tif (!details) return new Text(theme.fg(\"dim\", \"python done\"), 0, 0);\n\t\t\tconst status =\n\t\t\t\tdetails.exitCode === 0 && !details.timedOut ? \"python ok\" : `python exit ${details.exitCode ?? \"unknown\"}`;\n\t\t\tlet text = theme.fg(details.exitCode === 0 ? \"success\" : \"warning\", status);\n\t\t\tif (expanded) {\n\t\t\t\tconst content = result.content[0];\n\t\t\t\tif (content?.type === \"text\") {\n\t\t\t\t\tconst lines = content.text.split(\"\\n\").slice(-20);\n\t\t\t\t\tfor (const line of lines) text += `\\n${theme.fg(\"dim\", line)}`;\n\t\t\t\t}\n\t\t\t\tfor (const outputPath of [details.stdoutOutputPath, details.stderrOutputPath]) {\n\t\t\t\t\tif (outputPath) text += `\\n${theme.fg(\"muted\", `full output: ${outputPath}`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t};\n}\n\nexport function createPythonTool(baseCwd: string, options?: PythonToolOptions): AgentTool<typeof pythonSchema> {\n\treturn wrapToolDefinition(createPythonToolDefinition(baseCwd, options));\n}\n"]}
|
|
@@ -107,7 +107,8 @@ export function createPythonToolDefinition(baseCwd, options = {}) {
|
|
|
107
107
|
"Prefer python for bounded scripts, data shaping, structured transformations, and cross-platform logic when it is clearer than a shell pipeline.",
|
|
108
108
|
"Prefer read/edit/write for small exact source edits. For Python file transformations, preserve encoding and newline style, write atomically, and verify the resulting diff.",
|
|
109
109
|
"Keep work scoped: avoid recursive home/filesystem scans, pass explicit roots and filters, and request a larger timeout only when the bounded workload justifies it.",
|
|
110
|
-
"Do not
|
|
110
|
+
"Do not inspect or print credentials. When secret_store activates a bound profile, use its injected environment only through the credential-consuming program.",
|
|
111
|
+
"Do not use python for destructive deletion, publish/push/release, or long-running services without explicit user approval.",
|
|
111
112
|
],
|
|
112
113
|
parameters: pythonSchema,
|
|
113
114
|
async execute(_toolCallId, input, signal) {
|
|
@@ -148,6 +149,7 @@ export function createPythonToolDefinition(baseCwd, options = {}) {
|
|
|
148
149
|
signal,
|
|
149
150
|
env: {
|
|
150
151
|
...process.env,
|
|
152
|
+
...options.environment?.(cwd),
|
|
151
153
|
PI_PYTHON_TOOL: "1",
|
|
152
154
|
PYTHONDONTWRITEBYTECODE: "1",
|
|
153
155
|
PYTHONIOENCODING: "utf-8",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python.js","sourceRoot":"","sources":["../../../src/core/tools/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5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AI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAAA,CAC5B;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,OAA2B,EAAkC;IAC9G,OAAO,kBAAkB,CAAC,0BAA0B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACxE","sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { posix, win32 } from \"node:path\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport type { TruncationResult } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"../python-runtime.ts\";\nimport { withExclusiveMutationBarrier } from \"./file-mutation-queue.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nexport const DEFAULT_PYTHON_TIMEOUT_SECONDS = 30;\nexport const MAX_PYTHON_TIMEOUT_SECONDS = 300;\nexport const MAX_PYTHON_OUTPUT_BYTES = 200_000;\nconst MIN_PYTHON_OUTPUT_BYTES = 1_000;\nconst PYTHON_KILL_GRACE_MS = 2_000;\n\nconst pythonSchema = Type.Object(\n\t{\n\t\tcode: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python code to execute on stdin. Provide exactly one of code or scriptPath.\",\n\t\t\t\tmaxLength: 200_000,\n\t\t\t}),\n\t\t),\n\t\tscriptPath: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python script path. Relative paths resolve from cwd; one leading @ is ignored.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\targs: Type.Optional(\n\t\t\tType.Array(Type.String({ maxLength: 16_384 }), {\n\t\t\t\tdescription: \"Arguments passed directly to Python after '-' or scriptPath; no shell interpolation.\",\n\t\t\t\tmaxItems: 256,\n\t\t\t}),\n\t\t),\n\t\tcwd: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Working directory. Defaults to Pi's cwd; relative paths resolve from Pi's cwd.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\ttimeoutSeconds: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Wall-clock timeout. Defaults to ${DEFAULT_PYTHON_TIMEOUT_SECONDS} seconds and is capped at ${MAX_PYTHON_TIMEOUT_SECONDS}.`,\n\t\t\t}),\n\t\t),\n\t\tmaxOutputBytes: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Maximum returned bytes per stream before full output spills to a work artifact. Maximum ${MAX_PYTHON_OUTPUT_BYTES}.`,\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type PythonToolInput = Static<typeof pythonSchema>;\n\nexport interface PythonToolDetails {\n\tmode: \"code\" | \"script\";\n\tcwd: string;\n\tuvPath: string;\n\tpythonPath: string;\n\tscriptPath?: string;\n\targs: string[];\n\texitCode: number | null;\n\tsignal: string | null;\n\ttimedOut: boolean;\n\tstdoutTruncation?: TruncationResult;\n\tstderrTruncation?: TruncationResult;\n\tstdoutOutputPath?: string;\n\tstderrOutputPath?: string;\n\tstdoutOutputError?: string;\n\tstderrOutputError?: string;\n}\n\nexport interface PythonExecutionRequest {\n\tpython: string;\n\targs: string[];\n\tcwd: string;\n\tstdin?: string;\n\ttimeoutMs: number;\n\tsignal?: AbortSignal;\n\tenv: NodeJS.ProcessEnv;\n\tonStdout: (chunk: Buffer) => void;\n\tonStderr: (chunk: Buffer) => void;\n}\n\nexport interface PythonExecutionResult {\n\texitCode: number | null;\n\treason: \"exited\" | \"aborted\" | \"timeout\";\n\tsignal: string | null;\n}\n\nexport interface PythonOperations {\n\texec(request: PythonExecutionRequest): Promise<PythonExecutionResult>;\n}\n\nexport interface PythonToolOptions {\n\tresolveRuntime?: () => Promise<PythonRuntimeOutcome>;\n\toperations?: PythonOperations;\n\t/** Override only for tests or embedded runtimes; production uses the process work directory. */\n\toutputDirectory?: string;\n}\n\nfunction stripAtPrefix(value: string): string {\n\treturn value.startsWith(\"@\") ? value.slice(1) : value;\n}\n\nexport function resolvePythonToolPath(\n\tbase: string,\n\trequested: string,\n\tplatform: NodeJS.Platform = process.platform,\n): string {\n\treturn (platform === \"win32\" ? win32 : posix).resolve(base, stripAtPrefix(requested));\n}\n\nasync function resolveWorkingDirectory(baseCwd: string, requested?: string): Promise<string> {\n\tconst cwd = requested ? resolvePythonToolPath(baseCwd, requested) : baseCwd;\n\tconst entry = await stat(cwd).catch(() => {\n\t\tthrow new Error(`cwd does not exist: ${cwd}`);\n\t});\n\tif (!entry.isDirectory()) throw new Error(`cwd is not a directory: ${cwd}`);\n\treturn cwd;\n}\n\nasync function resolveScriptPath(cwd: string, requested: string): Promise<string> {\n\tconst scriptPath = resolvePythonToolPath(cwd, requested);\n\tconst entry = await stat(scriptPath).catch(() => {\n\t\tthrow new Error(`scriptPath does not exist: ${scriptPath}`);\n\t});\n\tif (!entry.isFile()) throw new Error(`scriptPath is not a file: ${scriptPath}`);\n\treturn scriptPath;\n}\n\nfunction clampInteger(value: number | undefined, fallback: number, minimum: number, maximum: number): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value <= 0) return fallback;\n\treturn Math.max(minimum, Math.min(maximum, Math.trunc(value)));\n}\n\nfunction createLocalPythonOperations(): PythonOperations {\n\treturn {\n\t\tasync exec(request) {\n\t\t\tif (request.signal?.aborted) throw new Error(\"Python execution aborted before start\");\n\t\t\tconst child = spawnProcess(request.python, request.args, {\n\t\t\t\tcwd: request.cwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: request.env,\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => request.onStdout(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => request.onStderr(chunk));\n\t\t\tchild.stdin?.end(request.stdin ?? \"\");\n\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\tkillGraceMs: PYTHON_KILL_GRACE_MS,\n\t\t\t\tsignal: request.signal,\n\t\t\t\ttimeoutMs: request.timeoutMs,\n\t\t\t});\n\t\t\treturn { exitCode: terminal.code, reason: terminal.reason, signal: child.signalCode };\n\t\t},\n\t};\n}\n\nfunction renderStreamNotice(label: string, path: string | undefined, error: string | undefined): string | undefined {\n\tif (path) return `[${label} truncated; full output: ${path}]`;\n\tif (error) return `[${label} truncated; full-output artifact failed: ${error}]`;\n\treturn undefined;\n}\n\nexport function createPythonToolDefinition(\n\tbaseCwd: string,\n\toptions: PythonToolOptions = {},\n): ToolDefinition<typeof pythonSchema, PythonToolDetails> {\n\tconst resolveRuntime = options.resolveRuntime ?? (() => ensurePythonRuntime({ silent: true }));\n\tconst operations = options.operations ?? createLocalPythonOperations();\n\treturn {\n\t\tname: \"python\",\n\t\tlabel: \"python\",\n\t\tdescription: `Run a bounded Python snippet or script without a shell. Pi resolves Python through uv, defaults to a ${DEFAULT_PYTHON_TIMEOUT_SECONDS}-second wall-clock timeout (maximum ${MAX_PYTHON_TIMEOUT_SECONDS}), streams bounded stdout/stderr, and spills truncated full output to the process work directory rather than the repository.`,\n\t\tpromptSnippet: \"Run bounded Python snippets or scripts through Pi's uv-managed runtime.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Prefer python for bounded scripts, data shaping, structured transformations, and cross-platform logic when it is clearer than a shell pipeline.\",\n\t\t\t\"Prefer read/edit/write for small exact source edits. For Python file transformations, preserve encoding and newline style, write atomically, and verify the resulting diff.\",\n\t\t\t\"Keep work scoped: avoid recursive home/filesystem scans, pass explicit roots and filters, and request a larger timeout only when the bounded workload justifies it.\",\n\t\t\t\"Do not use python for destructive deletion, credentials, publish/push/release, or long-running services without explicit user approval.\",\n\t\t],\n\t\tparameters: pythonSchema,\n\t\tasync execute(_toolCallId, input, signal) {\n\t\t\tconst hasCode = typeof input.code === \"string\";\n\t\t\tconst hasScript = typeof input.scriptPath === \"string\" && input.scriptPath.trim().length > 0;\n\t\t\tif (hasCode === hasScript) throw new Error(\"Provide exactly one of code or scriptPath.\");\n\t\t\tconst cwd = await resolveWorkingDirectory(baseCwd, input.cwd);\n\t\t\tconst scriptPath = hasScript ? await resolveScriptPath(cwd, input.scriptPath as string) : undefined;\n\t\t\tconst runtime = await resolveRuntime();\n\t\t\tif (runtime.status !== \"ready\") throw new Error(runtime.reason);\n\t\t\tconst args = input.args ? [...input.args] : [];\n\t\t\tconst timeoutSeconds = clampInteger(\n\t\t\t\tinput.timeoutSeconds,\n\t\t\t\tDEFAULT_PYTHON_TIMEOUT_SECONDS,\n\t\t\t\t1,\n\t\t\t\tMAX_PYTHON_TIMEOUT_SECONDS,\n\t\t\t);\n\t\t\tconst maxOutputBytes = clampInteger(\n\t\t\t\tinput.maxOutputBytes,\n\t\t\t\t50 * 1024,\n\t\t\t\tMIN_PYTHON_OUTPUT_BYTES,\n\t\t\t\tMAX_PYTHON_OUTPUT_BYTES,\n\t\t\t);\n\t\t\tconst accumulatorOptions = {\n\t\t\t\tmaxBytes: maxOutputBytes,\n\t\t\t\t...(options.outputDirectory ? { tempDirectory: options.outputDirectory } : {}),\n\t\t\t};\n\t\t\tconst stdout = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stdout\" });\n\t\t\tconst stderr = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stderr\" });\n\t\t\tconst finishStreams = () => {\n\t\t\t\tstdout.finish();\n\t\t\t\tstderr.finish();\n\t\t\t\treturn {\n\t\t\t\t\tstdout: stdout.snapshot({ persistIfTruncated: true }),\n\t\t\t\t\tstderr: stderr.snapshot({ persistIfTruncated: true }),\n\t\t\t\t};\n\t\t\t};\n\t\t\tlet execution: PythonExecutionResult;\n\t\t\ttry {\n\t\t\t\texecution = await withExclusiveMutationBarrier(() =>\n\t\t\t\t\toperations.exec({\n\t\t\t\t\t\tpython: runtime.pythonPath,\n\t\t\t\t\t\targs: scriptPath ? [\"-B\", scriptPath, ...args] : [\"-B\", \"-\", ...args],\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tstdin: hasCode ? input.code : undefined,\n\t\t\t\t\t\ttimeoutMs: timeoutSeconds * 1000,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tenv: {\n\t\t\t\t\t\t\t...process.env,\n\t\t\t\t\t\t\tPI_PYTHON_TOOL: \"1\",\n\t\t\t\t\t\t\tPYTHONDONTWRITEBYTECODE: \"1\",\n\t\t\t\t\t\t\tPYTHONIOENCODING: \"utf-8\",\n\t\t\t\t\t\t\tPYTHONUNBUFFERED: \"1\",\n\t\t\t\t\t\t\tPYTHONUTF8: \"1\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonStdout: (chunk) => stdout.append(chunk),\n\t\t\t\t\t\tonStderr: (chunk) => stderr.append(chunk),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconst snapshots = finishStreams();\n\t\t\t\tconst sections: string[] = [];\n\t\t\t\tif (snapshots.stdout.content) sections.push(snapshots.stdout.content.trimEnd());\n\t\t\t\tif (snapshots.stderr.content) sections.push(`[stderr]\\n${snapshots.stderr.content.trimEnd()}`);\n\t\t\t\tconst stdoutNotice = renderStreamNotice(\n\t\t\t\t\t\"stdout\",\n\t\t\t\t\tsnapshots.stdout.fullOutputPath,\n\t\t\t\t\tsnapshots.stdout.fullOutputError,\n\t\t\t\t);\n\t\t\t\tconst stderrNotice = renderStreamNotice(\n\t\t\t\t\t\"stderr\",\n\t\t\t\t\tsnapshots.stderr.fullOutputPath,\n\t\t\t\t\tsnapshots.stderr.fullOutputError,\n\t\t\t\t);\n\t\t\t\tif (stdoutNotice) sections.push(stdoutNotice);\n\t\t\t\tif (stderrNotice) sections.push(stderrNotice);\n\t\t\t\tconst status = `[python exitCode=${execution.exitCode ?? \"null\"}${execution.signal ? `; signal=${execution.signal}` : \"\"}]`;\n\t\t\t\tsections.push(status);\n\t\t\t\tconst text = sections.join(\"\\n\\n\");\n\t\t\t\tif (execution.reason === \"timeout\")\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython timed out after ${timeoutSeconds} seconds`);\n\t\t\t\tif (execution.reason === \"aborted\") throw new Error(`${text}\\n\\nPython execution aborted`);\n\t\t\t\tif (execution.exitCode !== 0) {\n\t\t\t\t\tconst termination = execution.signal\n\t\t\t\t\t\t? `signal ${execution.signal}`\n\t\t\t\t\t\t: `code ${execution.exitCode ?? \"unknown\"}`;\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython exited with ${termination}`);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: scriptPath ? \"script\" : \"code\",\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tuvPath: runtime.uvPath,\n\t\t\t\t\t\tpythonPath: runtime.pythonPath,\n\t\t\t\t\t\tscriptPath,\n\t\t\t\t\t\targs,\n\t\t\t\t\t\texitCode: execution.exitCode,\n\t\t\t\t\t\tsignal: execution.signal,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\t...(snapshots.stdout.truncation.truncated ? { stdoutTruncation: snapshots.stdout.truncation } : {}),\n\t\t\t\t\t\t...(snapshots.stderr.truncation.truncated ? { stderrTruncation: snapshots.stderr.truncation } : {}),\n\t\t\t\t\t\tstdoutOutputPath: snapshots.stdout.fullOutputPath,\n\t\t\t\t\t\tstderrOutputPath: snapshots.stderr.fullOutputPath,\n\t\t\t\t\t\tstdoutOutputError: snapshots.stdout.fullOutputError,\n\t\t\t\t\t\tstderrOutputError: snapshots.stderr.fullOutputError,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tawait Promise.all([stdout.closeTempFile(), stderr.closeTempFile()]);\n\t\t\t}\n\t\t},\n\t\trenderCall(args, theme) {\n\t\t\tconst mode = args.scriptPath ? args.scriptPath : \"code\";\n\t\t\treturn new Text(`${theme.fg(\"toolTitle\", theme.bold(\"python\"))} ${theme.fg(\"muted\", mode)}`, 0, 0);\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return new Text(theme.fg(\"warning\", \"python running\"), 0, 0);\n\t\t\tconst details = result.details as PythonToolDetails | undefined;\n\t\t\tif (!details) return new Text(theme.fg(\"dim\", \"python done\"), 0, 0);\n\t\t\tconst status =\n\t\t\t\tdetails.exitCode === 0 && !details.timedOut ? \"python ok\" : `python exit ${details.exitCode ?? \"unknown\"}`;\n\t\t\tlet text = theme.fg(details.exitCode === 0 ? \"success\" : \"warning\", status);\n\t\t\tif (expanded) {\n\t\t\t\tconst content = result.content[0];\n\t\t\t\tif (content?.type === \"text\") {\n\t\t\t\t\tconst lines = content.text.split(\"\\n\").slice(-20);\n\t\t\t\t\tfor (const line of lines) text += `\\n${theme.fg(\"dim\", line)}`;\n\t\t\t\t}\n\t\t\t\tfor (const outputPath of [details.stdoutOutputPath, details.stderrOutputPath]) {\n\t\t\t\t\tif (outputPath) text += `\\n${theme.fg(\"muted\", `full output: ${outputPath}`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t};\n}\n\nexport function createPythonTool(baseCwd: string, options?: PythonToolOptions): AgentTool<typeof pythonSchema> {\n\treturn wrapToolDefinition(createPythonToolDefinition(baseCwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"python.js","sourceRoot":"","sources":["../../../src/core/tools/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EAAE,IAAI,EAAE,M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AU;wBAAE,IAAI,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,gBAAgB,UAAU,EAAE,CAAC,EAAE,CAAC;gBAChF,CAAC;YACF,CAAC;YACD,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAAA,CAC5B;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,OAA2B,EAAkC;IAC9G,OAAO,kBAAkB,CAAC,0BAA0B,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CACxE","sourcesContent":["import { stat } from \"node:fs/promises\";\nimport { posix, win32 } from \"node:path\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport type { TruncationResult } from \"@caupulican/pi-agent-core/node\";\nimport { Text } from \"@caupulican/pi-tui\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { ensurePythonRuntime, type PythonRuntimeOutcome } from \"../python-runtime.ts\";\nimport { withExclusiveMutationBarrier } from \"./file-mutation-queue.ts\";\nimport { OutputAccumulator } from \"./output-accumulator.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nexport const DEFAULT_PYTHON_TIMEOUT_SECONDS = 30;\nexport const MAX_PYTHON_TIMEOUT_SECONDS = 300;\nexport const MAX_PYTHON_OUTPUT_BYTES = 200_000;\nconst MIN_PYTHON_OUTPUT_BYTES = 1_000;\nconst PYTHON_KILL_GRACE_MS = 2_000;\n\nconst pythonSchema = Type.Object(\n\t{\n\t\tcode: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python code to execute on stdin. Provide exactly one of code or scriptPath.\",\n\t\t\t\tmaxLength: 200_000,\n\t\t\t}),\n\t\t),\n\t\tscriptPath: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Python script path. Relative paths resolve from cwd; one leading @ is ignored.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\targs: Type.Optional(\n\t\t\tType.Array(Type.String({ maxLength: 16_384 }), {\n\t\t\t\tdescription: \"Arguments passed directly to Python after '-' or scriptPath; no shell interpolation.\",\n\t\t\t\tmaxItems: 256,\n\t\t\t}),\n\t\t),\n\t\tcwd: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tdescription: \"Working directory. Defaults to Pi's cwd; relative paths resolve from Pi's cwd.\",\n\t\t\t\tmaxLength: 32_768,\n\t\t\t}),\n\t\t),\n\t\ttimeoutSeconds: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Wall-clock timeout. Defaults to ${DEFAULT_PYTHON_TIMEOUT_SECONDS} seconds and is capped at ${MAX_PYTHON_TIMEOUT_SECONDS}.`,\n\t\t\t}),\n\t\t),\n\t\tmaxOutputBytes: Type.Optional(\n\t\t\tType.Number({\n\t\t\t\tdescription: `Maximum returned bytes per stream before full output spills to a work artifact. Maximum ${MAX_PYTHON_OUTPUT_BYTES}.`,\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type PythonToolInput = Static<typeof pythonSchema>;\n\nexport interface PythonToolDetails {\n\tmode: \"code\" | \"script\";\n\tcwd: string;\n\tuvPath: string;\n\tpythonPath: string;\n\tscriptPath?: string;\n\targs: string[];\n\texitCode: number | null;\n\tsignal: string | null;\n\ttimedOut: boolean;\n\tstdoutTruncation?: TruncationResult;\n\tstderrTruncation?: TruncationResult;\n\tstdoutOutputPath?: string;\n\tstderrOutputPath?: string;\n\tstdoutOutputError?: string;\n\tstderrOutputError?: string;\n}\n\nexport interface PythonExecutionRequest {\n\tpython: string;\n\targs: string[];\n\tcwd: string;\n\tstdin?: string;\n\ttimeoutMs: number;\n\tsignal?: AbortSignal;\n\tenv: NodeJS.ProcessEnv;\n\tonStdout: (chunk: Buffer) => void;\n\tonStderr: (chunk: Buffer) => void;\n}\n\nexport interface PythonExecutionResult {\n\texitCode: number | null;\n\treason: \"exited\" | \"aborted\" | \"timeout\";\n\tsignal: string | null;\n}\n\nexport interface PythonOperations {\n\texec(request: PythonExecutionRequest): Promise<PythonExecutionResult>;\n}\n\nexport interface PythonToolOptions {\n\tresolveRuntime?: () => Promise<PythonRuntimeOutcome>;\n\toperations?: PythonOperations;\n\t/** Additional process environment resolved from the final execution cwd. */\n\tenvironment?: (cwd: string) => NodeJS.ProcessEnv;\n\t/** Override only for tests or embedded runtimes; production uses the process work directory. */\n\toutputDirectory?: string;\n}\n\nfunction stripAtPrefix(value: string): string {\n\treturn value.startsWith(\"@\") ? value.slice(1) : value;\n}\n\nexport function resolvePythonToolPath(\n\tbase: string,\n\trequested: string,\n\tplatform: NodeJS.Platform = process.platform,\n): string {\n\treturn (platform === \"win32\" ? win32 : posix).resolve(base, stripAtPrefix(requested));\n}\n\nasync function resolveWorkingDirectory(baseCwd: string, requested?: string): Promise<string> {\n\tconst cwd = requested ? resolvePythonToolPath(baseCwd, requested) : baseCwd;\n\tconst entry = await stat(cwd).catch(() => {\n\t\tthrow new Error(`cwd does not exist: ${cwd}`);\n\t});\n\tif (!entry.isDirectory()) throw new Error(`cwd is not a directory: ${cwd}`);\n\treturn cwd;\n}\n\nasync function resolveScriptPath(cwd: string, requested: string): Promise<string> {\n\tconst scriptPath = resolvePythonToolPath(cwd, requested);\n\tconst entry = await stat(scriptPath).catch(() => {\n\t\tthrow new Error(`scriptPath does not exist: ${scriptPath}`);\n\t});\n\tif (!entry.isFile()) throw new Error(`scriptPath is not a file: ${scriptPath}`);\n\treturn scriptPath;\n}\n\nfunction clampInteger(value: number | undefined, fallback: number, minimum: number, maximum: number): number {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value <= 0) return fallback;\n\treturn Math.max(minimum, Math.min(maximum, Math.trunc(value)));\n}\n\nfunction createLocalPythonOperations(): PythonOperations {\n\treturn {\n\t\tasync exec(request) {\n\t\t\tif (request.signal?.aborted) throw new Error(\"Python execution aborted before start\");\n\t\t\tconst child = spawnProcess(request.python, request.args, {\n\t\t\t\tcwd: request.cwd,\n\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\tenv: request.env,\n\t\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t\t});\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => request.onStdout(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => request.onStderr(chunk));\n\t\t\tchild.stdin?.end(request.stdin ?? \"\");\n\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\tkillGraceMs: PYTHON_KILL_GRACE_MS,\n\t\t\t\tsignal: request.signal,\n\t\t\t\ttimeoutMs: request.timeoutMs,\n\t\t\t});\n\t\t\treturn { exitCode: terminal.code, reason: terminal.reason, signal: child.signalCode };\n\t\t},\n\t};\n}\n\nfunction renderStreamNotice(label: string, path: string | undefined, error: string | undefined): string | undefined {\n\tif (path) return `[${label} truncated; full output: ${path}]`;\n\tif (error) return `[${label} truncated; full-output artifact failed: ${error}]`;\n\treturn undefined;\n}\n\nexport function createPythonToolDefinition(\n\tbaseCwd: string,\n\toptions: PythonToolOptions = {},\n): ToolDefinition<typeof pythonSchema, PythonToolDetails> {\n\tconst resolveRuntime = options.resolveRuntime ?? (() => ensurePythonRuntime({ silent: true }));\n\tconst operations = options.operations ?? createLocalPythonOperations();\n\treturn {\n\t\tname: \"python\",\n\t\tlabel: \"python\",\n\t\tdescription: `Run a bounded Python snippet or script without a shell. Pi resolves Python through uv, defaults to a ${DEFAULT_PYTHON_TIMEOUT_SECONDS}-second wall-clock timeout (maximum ${MAX_PYTHON_TIMEOUT_SECONDS}), streams bounded stdout/stderr, and spills truncated full output to the process work directory rather than the repository.`,\n\t\tpromptSnippet: \"Run bounded Python snippets or scripts through Pi's uv-managed runtime.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Prefer python for bounded scripts, data shaping, structured transformations, and cross-platform logic when it is clearer than a shell pipeline.\",\n\t\t\t\"Prefer read/edit/write for small exact source edits. For Python file transformations, preserve encoding and newline style, write atomically, and verify the resulting diff.\",\n\t\t\t\"Keep work scoped: avoid recursive home/filesystem scans, pass explicit roots and filters, and request a larger timeout only when the bounded workload justifies it.\",\n\t\t\t\"Do not inspect or print credentials. When secret_store activates a bound profile, use its injected environment only through the credential-consuming program.\",\n\t\t\t\"Do not use python for destructive deletion, publish/push/release, or long-running services without explicit user approval.\",\n\t\t],\n\t\tparameters: pythonSchema,\n\t\tasync execute(_toolCallId, input, signal) {\n\t\t\tconst hasCode = typeof input.code === \"string\";\n\t\t\tconst hasScript = typeof input.scriptPath === \"string\" && input.scriptPath.trim().length > 0;\n\t\t\tif (hasCode === hasScript) throw new Error(\"Provide exactly one of code or scriptPath.\");\n\t\t\tconst cwd = await resolveWorkingDirectory(baseCwd, input.cwd);\n\t\t\tconst scriptPath = hasScript ? await resolveScriptPath(cwd, input.scriptPath as string) : undefined;\n\t\t\tconst runtime = await resolveRuntime();\n\t\t\tif (runtime.status !== \"ready\") throw new Error(runtime.reason);\n\t\t\tconst args = input.args ? [...input.args] : [];\n\t\t\tconst timeoutSeconds = clampInteger(\n\t\t\t\tinput.timeoutSeconds,\n\t\t\t\tDEFAULT_PYTHON_TIMEOUT_SECONDS,\n\t\t\t\t1,\n\t\t\t\tMAX_PYTHON_TIMEOUT_SECONDS,\n\t\t\t);\n\t\t\tconst maxOutputBytes = clampInteger(\n\t\t\t\tinput.maxOutputBytes,\n\t\t\t\t50 * 1024,\n\t\t\t\tMIN_PYTHON_OUTPUT_BYTES,\n\t\t\t\tMAX_PYTHON_OUTPUT_BYTES,\n\t\t\t);\n\t\t\tconst accumulatorOptions = {\n\t\t\t\tmaxBytes: maxOutputBytes,\n\t\t\t\t...(options.outputDirectory ? { tempDirectory: options.outputDirectory } : {}),\n\t\t\t};\n\t\t\tconst stdout = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stdout\" });\n\t\t\tconst stderr = new OutputAccumulator({ ...accumulatorOptions, tempFilePrefix: \"pi-python-stderr\" });\n\t\t\tconst finishStreams = () => {\n\t\t\t\tstdout.finish();\n\t\t\t\tstderr.finish();\n\t\t\t\treturn {\n\t\t\t\t\tstdout: stdout.snapshot({ persistIfTruncated: true }),\n\t\t\t\t\tstderr: stderr.snapshot({ persistIfTruncated: true }),\n\t\t\t\t};\n\t\t\t};\n\t\t\tlet execution: PythonExecutionResult;\n\t\t\ttry {\n\t\t\t\texecution = await withExclusiveMutationBarrier(() =>\n\t\t\t\t\toperations.exec({\n\t\t\t\t\t\tpython: runtime.pythonPath,\n\t\t\t\t\t\targs: scriptPath ? [\"-B\", scriptPath, ...args] : [\"-B\", \"-\", ...args],\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tstdin: hasCode ? input.code : undefined,\n\t\t\t\t\t\ttimeoutMs: timeoutSeconds * 1000,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tenv: {\n\t\t\t\t\t\t\t...process.env,\n\t\t\t\t\t\t\t...options.environment?.(cwd),\n\t\t\t\t\t\t\tPI_PYTHON_TOOL: \"1\",\n\t\t\t\t\t\t\tPYTHONDONTWRITEBYTECODE: \"1\",\n\t\t\t\t\t\t\tPYTHONIOENCODING: \"utf-8\",\n\t\t\t\t\t\t\tPYTHONUNBUFFERED: \"1\",\n\t\t\t\t\t\t\tPYTHONUTF8: \"1\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tonStdout: (chunk) => stdout.append(chunk),\n\t\t\t\t\t\tonStderr: (chunk) => stderr.append(chunk),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tconst snapshots = finishStreams();\n\t\t\t\tconst sections: string[] = [];\n\t\t\t\tif (snapshots.stdout.content) sections.push(snapshots.stdout.content.trimEnd());\n\t\t\t\tif (snapshots.stderr.content) sections.push(`[stderr]\\n${snapshots.stderr.content.trimEnd()}`);\n\t\t\t\tconst stdoutNotice = renderStreamNotice(\n\t\t\t\t\t\"stdout\",\n\t\t\t\t\tsnapshots.stdout.fullOutputPath,\n\t\t\t\t\tsnapshots.stdout.fullOutputError,\n\t\t\t\t);\n\t\t\t\tconst stderrNotice = renderStreamNotice(\n\t\t\t\t\t\"stderr\",\n\t\t\t\t\tsnapshots.stderr.fullOutputPath,\n\t\t\t\t\tsnapshots.stderr.fullOutputError,\n\t\t\t\t);\n\t\t\t\tif (stdoutNotice) sections.push(stdoutNotice);\n\t\t\t\tif (stderrNotice) sections.push(stderrNotice);\n\t\t\t\tconst status = `[python exitCode=${execution.exitCode ?? \"null\"}${execution.signal ? `; signal=${execution.signal}` : \"\"}]`;\n\t\t\t\tsections.push(status);\n\t\t\t\tconst text = sections.join(\"\\n\\n\");\n\t\t\t\tif (execution.reason === \"timeout\")\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython timed out after ${timeoutSeconds} seconds`);\n\t\t\t\tif (execution.reason === \"aborted\") throw new Error(`${text}\\n\\nPython execution aborted`);\n\t\t\t\tif (execution.exitCode !== 0) {\n\t\t\t\t\tconst termination = execution.signal\n\t\t\t\t\t\t? `signal ${execution.signal}`\n\t\t\t\t\t\t: `code ${execution.exitCode ?? \"unknown\"}`;\n\t\t\t\t\tthrow new Error(`${text}\\n\\nPython exited with ${termination}`);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tmode: scriptPath ? \"script\" : \"code\",\n\t\t\t\t\t\tcwd,\n\t\t\t\t\t\tuvPath: runtime.uvPath,\n\t\t\t\t\t\tpythonPath: runtime.pythonPath,\n\t\t\t\t\t\tscriptPath,\n\t\t\t\t\t\targs,\n\t\t\t\t\t\texitCode: execution.exitCode,\n\t\t\t\t\t\tsignal: execution.signal,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\t...(snapshots.stdout.truncation.truncated ? { stdoutTruncation: snapshots.stdout.truncation } : {}),\n\t\t\t\t\t\t...(snapshots.stderr.truncation.truncated ? { stderrTruncation: snapshots.stderr.truncation } : {}),\n\t\t\t\t\t\tstdoutOutputPath: snapshots.stdout.fullOutputPath,\n\t\t\t\t\t\tstderrOutputPath: snapshots.stderr.fullOutputPath,\n\t\t\t\t\t\tstdoutOutputError: snapshots.stdout.fullOutputError,\n\t\t\t\t\t\tstderrOutputError: snapshots.stderr.fullOutputError,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tawait Promise.all([stdout.closeTempFile(), stderr.closeTempFile()]);\n\t\t\t}\n\t\t},\n\t\trenderCall(args, theme) {\n\t\t\tconst mode = args.scriptPath ? args.scriptPath : \"code\";\n\t\t\treturn new Text(`${theme.fg(\"toolTitle\", theme.bold(\"python\"))} ${theme.fg(\"muted\", mode)}`, 0, 0);\n\t\t},\n\t\trenderResult(result, { expanded, isPartial }, theme) {\n\t\t\tif (isPartial) return new Text(theme.fg(\"warning\", \"python running\"), 0, 0);\n\t\t\tconst details = result.details as PythonToolDetails | undefined;\n\t\t\tif (!details) return new Text(theme.fg(\"dim\", \"python done\"), 0, 0);\n\t\t\tconst status =\n\t\t\t\tdetails.exitCode === 0 && !details.timedOut ? \"python ok\" : `python exit ${details.exitCode ?? \"unknown\"}`;\n\t\t\tlet text = theme.fg(details.exitCode === 0 ? \"success\" : \"warning\", status);\n\t\t\tif (expanded) {\n\t\t\t\tconst content = result.content[0];\n\t\t\t\tif (content?.type === \"text\") {\n\t\t\t\t\tconst lines = content.text.split(\"\\n\").slice(-20);\n\t\t\t\t\tfor (const line of lines) text += `\\n${theme.fg(\"dim\", line)}`;\n\t\t\t\t}\n\t\t\t\tfor (const outputPath of [details.stdoutOutputPath, details.stderrOutputPath]) {\n\t\t\t\t\tif (outputPath) text += `\\n${theme.fg(\"muted\", `full output: ${outputPath}`)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn new Text(text, 0, 0);\n\t\t},\n\t};\n}\n\nexport function createPythonTool(baseCwd: string, options?: PythonToolOptions): AgentTool<typeof pythonSchema> {\n\treturn wrapToolDefinition(createPythonToolDefinition(baseCwd, options));\n}\n"]}
|