@caupulican/pi-adaptative 0.86.17 → 0.90.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -15
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -16
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +4 -4
- package/dist/core/agent-session.d.ts +23 -33
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +81 -110
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +16 -0
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.d.ts +2 -1
- package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
- package/dist/core/autonomy/subagent-prompt.js +2 -18
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-tool-task-controller.js +5 -5
- package/dist/core/background-tool-task-controller.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +22 -2
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +75 -39
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/context/brain-curator.d.ts +2 -3
- package/dist/core/context/brain-curator.d.ts.map +1 -1
- package/dist/core/context/brain-curator.js +3 -20
- package/dist/core/context/brain-curator.js.map +1 -1
- package/dist/core/context/context-composition.d.ts +2 -1
- package/dist/core/context/context-composition.d.ts.map +1 -1
- package/dist/core/context/context-composition.js +6 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/memory-prompt-block.js +1 -1
- package/dist/core/context/memory-prompt-block.js.map +1 -1
- package/dist/core/context/tool-output-packer.js +1 -1
- package/dist/core/context/tool-output-packer.js.map +1 -1
- package/dist/core/context-gc.js +10 -10
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +4 -4
- package/dist/core/context-pipeline.js +4 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -2
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts +2 -2
- package/dist/core/delegation/session-worker-claim.js +2 -2
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-resource-materializer.js +3 -3
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +2 -13
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +5 -67
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/extensions/builtin.js +4 -4
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +6 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +21 -9
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +9 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +2 -2
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +13 -9
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +1 -1
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +6 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +16 -13
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/human-input-controller.js +1 -1
- package/dist/core/human-input-controller.js.map +1 -1
- package/dist/core/improvement-loop.js +13 -13
- package/dist/core/improvement-loop.js.map +1 -1
- package/dist/core/learning/reflection-engine.d.ts +2 -1
- package/dist/core/learning/reflection-engine.d.ts.map +1 -1
- package/dist/core/learning/reflection-engine.js +4 -24
- package/dist/core/learning/reflection-engine.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -1
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-router/route-judge.d.ts +2 -1
- package/dist/core/model-router/route-judge.d.ts.map +1 -1
- package/dist/core/model-router/route-judge.js +4 -12
- package/dist/core/model-router/route-judge.js.map +1 -1
- package/dist/core/models/perf-profile.d.ts +1 -1
- package/dist/core/models/perf-profile.d.ts.map +1 -1
- package/dist/core/models/perf-profile.js +2 -8
- package/dist/core/models/perf-profile.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +1 -6
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.js +3 -3
- package/dist/core/process-matrix/resume-launcher.js.map +1 -1
- package/dist/core/process-matrix/runtime.d.ts +2 -0
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +23 -19
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/provider-prompt-contracts.d.ts +34 -0
- package/dist/core/provider-prompt-contracts.d.ts.map +1 -0
- package/dist/core/provider-prompt-contracts.js +133 -0
- package/dist/core/provider-prompt-contracts.js.map +1 -0
- package/dist/core/provider-request-context-controller.d.ts +40 -0
- package/dist/core/provider-request-context-controller.d.ts.map +1 -0
- package/dist/core/provider-request-context-controller.js +68 -0
- package/dist/core/provider-request-context-controller.js.map +1 -0
- package/dist/core/provider-request-runtime-controller.d.ts +22 -0
- package/dist/core/provider-request-runtime-controller.d.ts.map +1 -0
- package/dist/core/provider-request-runtime-controller.js +87 -0
- package/dist/core/provider-request-runtime-controller.js.map +1 -0
- package/dist/core/provider-tool-text.d.ts +7 -0
- package/dist/core/provider-tool-text.d.ts.map +1 -0
- package/dist/core/provider-tool-text.js +42 -0
- package/dist/core/provider-tool-text.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +2 -5
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +2 -20
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-runner.d.ts +2 -1
- package/dist/core/research/research-runner.d.ts.map +1 -1
- package/dist/core/research/research-runner.js +6 -21
- package/dist/core/research/research-runner.js.map +1 -1
- package/dist/core/risk-classifier.d.ts.map +1 -1
- package/dist/core/risk-classifier.js +9 -1
- package/dist/core/risk-classifier.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +3 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +20 -25
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/scout-controller.d.ts +2 -1
- package/dist/core/scout-controller.d.ts.map +1 -1
- package/dist/core/scout-controller.js +2 -16
- package/dist/core/scout-controller.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +6 -6
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/secrets/credential-manager.d.ts +11 -1
- package/dist/core/secrets/credential-manager.d.ts.map +1 -1
- package/dist/core/secrets/credential-manager.js +28 -7
- package/dist/core/secrets/credential-manager.js.map +1 -1
- package/dist/core/secrets/credential-migration-source.d.ts +20 -0
- package/dist/core/secrets/credential-migration-source.d.ts.map +1 -0
- package/dist/core/secrets/credential-migration-source.js +113 -0
- package/dist/core/secrets/credential-migration-source.js.map +1 -0
- package/dist/core/secrets/credential-session-connection.d.ts +9 -0
- package/dist/core/secrets/credential-session-connection.d.ts.map +1 -0
- package/dist/core/secrets/credential-session-connection.js +39 -0
- package/dist/core/secrets/credential-session-connection.js.map +1 -0
- package/dist/core/security/untrusted-boundary.d.ts +2 -2
- package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
- package/dist/core/security/untrusted-boundary.js +3 -10
- package/dist/core/security/untrusted-boundary.js.map +1 -1
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +1 -2
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/skill-vault.d.ts +98 -0
- package/dist/core/skill-vault.d.ts.map +1 -0
- package/dist/core/skill-vault.js +270 -0
- package/dist/core/skill-vault.js.map +1 -0
- package/dist/core/skills.d.ts +10 -9
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +42 -50
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt-builder.d.ts +1 -1
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +20 -60
- package/dist/core/system-prompt-builder.js.map +1 -1
- package/dist/core/system-prompt.d.ts +4 -4
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +87 -121
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +6 -7
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +2 -1
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts.map +1 -1
- package/dist/core/tool-protocol-controller.js +4 -7
- package/dist/core/tool-protocol-controller.js.map +1 -1
- package/dist/core/tool-selection/promotion.d.ts.map +1 -1
- package/dist/core/tool-selection/promotion.js +2 -6
- package/dist/core/tool-selection/promotion.js.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts +2 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.js +2 -14
- package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
- package/dist/core/tools/ask-question.js +6 -6
- package/dist/core/tools/ask-question.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +8 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +17 -13
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +111 -226
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +29 -2
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +149 -48
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit.js +3 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/extensionify-runtime.js +4 -4
- package/dist/core/tools/extensionify-runtime.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +2 -4
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/goal.js +3 -3
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/grep.js +2 -2
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/model-fitness.js +4 -4
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +30 -16
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +98 -59
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/python.js +6 -6
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/run-process.js +4 -4
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/run-toolkit-script.js +4 -4
- package/dist/core/tools/run-toolkit-script.js.map +1 -1
- package/dist/core/tools/secret-store.d.ts +32 -3
- package/dist/core/tools/secret-store.d.ts.map +1 -1
- package/dist/core/tools/secret-store.js +141 -34
- package/dist/core/tools/secret-store.js.map +1 -1
- package/dist/core/tools/skill.d.ts +29 -0
- package/dist/core/tools/skill.d.ts.map +1 -0
- package/dist/core/tools/skill.js +79 -0
- package/dist/core/tools/skill.js.map +1 -0
- package/dist/core/tools/task-steps.js +4 -4
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/tool-task.d.ts.map +1 -1
- package/dist/core/tools/tool-task.js +4 -0
- package/dist/core/tools/tool-task.js.map +1 -1
- package/dist/core/tools/worktree-sync.js +6 -6
- package/dist/core/tools/worktree-sync.js.map +1 -1
- package/dist/core/tools/write.js +3 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +1 -1
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/report-commands.js +1 -1
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.js +2 -18
- package/dist/modes/interactive/secret-menu-controller.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +1 -1
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/docs/compaction.md +45 -25
- package/docs/extensions.md +23 -7
- package/docs/settings.md +3 -3
- package/docs/skills.md +14 -10
- package/docs/task-steps.md +2 -2
- package/docs/tmux-agent-manager.md +1 -1
- package/docs/tool-repair.md +18 -1
- package/docs/usage.md +4 -2
- package/docs/worker-profiles.md +3 -3
- package/docs/worktree-sync.md +2 -2
- package/examples/extensions/custom-compaction.ts +5 -17
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/summarize.ts +3 -5
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/04-skills.ts +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
- package/dist/core/util/json-size.d.ts +0 -3
- package/dist/core/util/json-size.d.ts.map +0 -1
- package/dist/core/util/json-size.js +0 -95
- package/dist/core/util/json-size.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-process.js","sourceRoot":"","sources":["../../../src/core/tools/run-process.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAEhG,OAAO,EACN,sCAAsC,GAEtC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,gCAAgC,GAAG,KAAK,CAAC;AAC/C,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAC7C,MAAM,yBAAyB,GAAG,EAAE,CAAC;AACrC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7C,MAAM,6BAA6B,GAAG,SAAS,CAAC;AAChD,MAAM,uBA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AC,YAAY,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,iBAAiB;iBACnE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACb,OAAO;oBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;oBAChD,GAAG,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;oBAClD,OAAO,EAAE;wBACR,OAAO;wBACP,UAAU,EAAE,KAAK,CAAC,UAAU;wBAC5B,QAAQ,EAAE,QAAQ,CAAC,IAAI;wBACvB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;wBAClC,SAAS,EAAE,QAAQ,CAAC,SAAS;qBACD;iBAC7B,CAAC;YACH,CAAC;oBAAS,CAAC;gBACV,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC5C,gBAAgB,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC7D,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW,EAAE,OAA8B;IAC/E,OAAO,kBAAkB,CAAC,8BAA8B,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tMAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES,\n\ttype OrchestrationExecutionPolicy,\n} from \"../orchestration/contracts.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_RUN_PROCESS_EXECUTABLE_CHARS = 4_096;\nconst MAX_RUN_PROCESS_ARGUMENT_CHARS = 4_096;\nconst MAX_RUN_PROCESS_ARGUMENTS = 64;\nconst MAX_RUN_PROCESS_ARGV_BYTES = 32 * 1024;\nconst MAX_RUN_PROCESS_WALL_CLOCK_MS = 3_600_000;\nconst MAX_VISIBLE_EXECUTABLES = 16;\nconst MAX_VISIBLE_EXECUTABLE_CHARS = 64;\n\nconst runProcessSchema = Type.Object(\n\t{\n\t\texecutable: Type.String({\n\t\t\tmaxLength: MAX_RUN_PROCESS_EXECUTABLE_CHARS,\n\t\t\tdescription: \"Exact owner-allowed executable name or path.\",\n\t\t}),\n\t\targs: Type.Optional(\n\t\t\tType.Array(Type.String({ maxLength: MAX_RUN_PROCESS_ARGUMENT_CHARS }), {\n\t\t\t\tmaxItems: MAX_RUN_PROCESS_ARGUMENTS,\n\t\t\t\tdescription: \"Direct argv entries. No shell parsing occurs.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type RunProcessInput = Static<typeof runProcessSchema>;\n\nexport interface RunProcessDetails {\n\toutcome: \"exited\" | \"failed\" | \"aborted\" | \"timeout\" | \"output_limit\";\n\texecutable: string;\n\texitCode: number | null;\n\tdurationMs: number;\n\ttruncated: boolean;\n}\n\nexport interface RunProcessToolOptions {\n\tpolicy: OrchestrationExecutionPolicy;\n\tmaxWallClockMs: number;\n\tspawn?: typeof spawnProcess;\n\t/** Additional environment resolved for the execution cwd; the policy allowlist still applies. */\n\tenvironment?: (cwd: string) => NodeJS.ProcessEnv;\n}\n\nconst SAFE_ENVIRONMENT_VARIABLES = [\n\t\"PATH\",\n\t\"PATHEXT\",\n\t\"SystemRoot\",\n\t\"WINDIR\",\n\t\"COMSPEC\",\n\t\"TMPDIR\",\n\t\"TMP\",\n\t\"TEMP\",\n] as const;\nconst OWNER_CONTROL_PLANE_ENVIRONMENT_VARIABLES = new Set([\"BW_SESSION\"]);\n\nfunction scopedEnvironment(allowedNames: readonly string[], additional: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n\tconst names = new Set<string>([...SAFE_ENVIRONMENT_VARIABLES, ...allowedNames]);\n\tconst environment: NodeJS.ProcessEnv = {};\n\tfor (const name of names) {\n\t\tif (OWNER_CONTROL_PLANE_ENVIRONMENT_VARIABLES.has(name)) continue;\n\t\tconst value = additional[name] ?? process.env[name];\n\t\tif (value !== undefined) environment[name] = value;\n\t}\n\treturn environment;\n}\n\nfunction executableCatalogDescription(allowedExecutables: readonly string[]): string {\n\tconst visible = allowedExecutables\n\t\t.slice(0, MAX_VISIBLE_EXECUTABLES)\n\t\t.map((executable) => executable.slice(0, MAX_VISIBLE_EXECUTABLE_CHARS));\n\tconst omitted = allowedExecutables.length - visible.length;\n\treturn `${allowedExecutables.length} configured: ${visible.join(\", \")}${omitted > 0 ? `; ${omitted} omitted` : \"\"}`;\n}\n\nfunction resolveProcessPolicy(options: RunProcessToolOptions): { maxOutputBytes: number; timeoutMs: number } {\n\tif (\n\t\t!Number.isSafeInteger(options.policy.maxOutputBytes) ||\n\t\toptions.policy.maxOutputBytes <= 0 ||\n\t\t!Number.isSafeInteger(options.maxWallClockMs) ||\n\t\toptions.maxWallClockMs < 0\n\t) {\n\t\tthrow new TypeError(\"process_policy_invalid: output and wall-clock limits must be bounded integers.\");\n\t}\n\treturn {\n\t\tmaxOutputBytes: Math.min(options.policy.maxOutputBytes, MAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES),\n\t\t// A zero lane-level budget disables that budget, not the execution-plane safety ceiling.\n\t\ttimeoutMs:\n\t\t\toptions.maxWallClockMs === 0\n\t\t\t\t? MAX_RUN_PROCESS_WALL_CLOCK_MS\n\t\t\t\t: Math.min(options.maxWallClockMs, MAX_RUN_PROCESS_WALL_CLOCK_MS),\n\t};\n}\n\nfunction validateProcessInput(input: RunProcessInput): string[] {\n\tif (\n\t\ttypeof input.executable !== \"string\" ||\n\t\tinput.executable.length === 0 ||\n\t\tinput.executable.length > MAX_RUN_PROCESS_EXECUTABLE_CHARS ||\n\t\tinput.executable.includes(\"\\0\")\n\t) {\n\t\tthrow new Error(\"process_argument_invalid: executable is empty, oversized, or contains a NUL byte.\");\n\t}\n\tif (\n\t\tinput.args !== undefined &&\n\t\t(!Array.isArray(input.args) ||\n\t\t\tinput.args.length > MAX_RUN_PROCESS_ARGUMENTS ||\n\t\t\tinput.args.some(\n\t\t\t\t(argument) =>\n\t\t\t\t\ttypeof argument !== \"string\" ||\n\t\t\t\t\targument.length > MAX_RUN_PROCESS_ARGUMENT_CHARS ||\n\t\t\t\t\targument.includes(\"\\0\"),\n\t\t\t))\n\t) {\n\t\tthrow new Error(\"process_argument_invalid: argv exceeds its count/size bound or contains a NUL byte.\");\n\t}\n\tconst args = input.args ?? [];\n\tlet argvBytes = Buffer.byteLength(input.executable, \"utf-8\");\n\tfor (const argument of args) {\n\t\targvBytes += 1 + Buffer.byteLength(argument, \"utf-8\");\n\t\tif (argvBytes > MAX_RUN_PROCESS_ARGV_BYTES) {\n\t\t\tthrow new Error(`process_argument_invalid: executable and argv exceed ${MAX_RUN_PROCESS_ARGV_BYTES} bytes.`);\n\t\t}\n\t}\n\treturn args;\n}\n\nfunction collectBoundedOutput(\n\tchild: ChildProcess,\n\tmaxBytes: number,\n\tabort: () => void,\n): {\n\tread(): { stdout: string; stderr: string; truncated: boolean };\n} {\n\tlet remaining = maxBytes;\n\tlet truncated = false;\n\tconst stdout: Buffer[] = [];\n\tconst stderr: Buffer[] = [];\n\tconst collect = (target: Buffer[]) => (chunk: Buffer) => {\n\t\tif (remaining <= 0) return;\n\t\tconst retained = chunk.subarray(0, remaining);\n\t\ttarget.push(retained);\n\t\tremaining -= retained.length;\n\t\tif (retained.length < chunk.length || remaining === 0) {\n\t\t\ttruncated = true;\n\t\t\tabort();\n\t\t}\n\t};\n\tchild.stdout?.on(\"data\", collect(stdout));\n\tchild.stderr?.on(\"data\", collect(stderr));\n\treturn {\n\t\tread: () => ({\n\t\t\tstdout: Buffer.concat(stdout).toString(\"utf-8\"),\n\t\t\tstderr: Buffer.concat(stderr).toString(\"utf-8\"),\n\t\t\ttruncated,\n\t\t}),\n\t};\n}\n\nexport function createRunProcessToolDefinition(cwd: string, options: RunProcessToolOptions): ToolDefinition {\n\tconst processPolicy = resolveProcessPolicy(options);\n\tconst allowedExecutables = new Set(options.policy.allowedExecutables);\n\treturn {\n\t\tname: \"run_process\",\n\t\tlabel: \"Run Process\",\n\t\tdescription: `Run one owner-allowed executable using direct argv without a shell. Allowed executables: ${executableCatalogDescription(options.policy.allowedExecutables)}.`,\n\t\tpromptSnippet: \"Run an owner-allowed executable through a constrained direct-argv launcher (not OS isolation).\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use only an executable listed by the profile. Arguments are passed literally; shell operators and interpolation are unavailable.\",\n\t\t\t\"Owner-authorized project credentials are injected only when their variable names are also allowed by the execution profile.\",\n\t\t\t\"Treat a non-zero exit code, timeout, abort, or output-limit termination as failure.\",\n\t\t],\n\t\tparameters: runProcessSchema,\n\t\tasync execute(_toolCallId, input: RunProcessInput, signal) {\n\t\t\tconst args = validateProcessInput(input);\n\t\t\tif (!allowedExecutables.has(input.executable)) {\n\t\t\t\tthrow new Error(`process_executable_denied: '${input.executable}' is not owner-allowed.`);\n\t\t\t}\n\t\t\tconst startedAt = Date.now();\n\t\t\tconst outputLimitAbort = new AbortController();\n\t\t\tlet outputLimitReached = false;\n\t\t\tconst child = (options.spawn ?? spawnProcess)(input.executable, [...args], {\n\t\t\t\tcwd,\n\t\t\t\tenv: scopedEnvironment(options.policy.allowedEnvironmentVariables, options.environment?.(cwd) ?? {}),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tconst output = collectBoundedOutput(child, processPolicy.maxOutputBytes, () => {\n\t\t\t\toutputLimitReached = true;\n\t\t\t\toutputLimitAbort.abort();\n\t\t\t});\n\t\t\tconst combinedAbort = new AbortController();\n\t\t\tconst abort = () => combinedAbort.abort();\n\t\t\tif (signal?.aborted || outputLimitAbort.signal.aborted) abort();\n\t\t\telse {\n\t\t\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\t\t\toutputLimitAbort.signal.addEventListener(\"abort\", abort, { once: true });\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\t\tsignal: combinedAbort.signal,\n\t\t\t\t\ttimeoutMs: processPolicy.timeoutMs,\n\t\t\t\t\tkillGraceMs: 2_000,\n\t\t\t\t});\n\t\t\t\tconst captured = output.read();\n\t\t\t\tconst outcome: RunProcessDetails[\"outcome\"] = outputLimitReached\n\t\t\t\t\t? \"output_limit\"\n\t\t\t\t\t: terminal.reason === \"timeout\"\n\t\t\t\t\t\t? \"timeout\"\n\t\t\t\t\t\t: terminal.reason === \"aborted\"\n\t\t\t\t\t\t\t? \"aborted\"\n\t\t\t\t\t\t\t: terminal.code === 0\n\t\t\t\t\t\t\t\t? \"exited\"\n\t\t\t\t\t\t\t\t: \"failed\";\n\t\t\t\tconst body = [\n\t\t\t\t\t`outcome: ${outcome}`,\n\t\t\t\t\t`exitCode: ${terminal.code ?? \"null\"}`,\n\t\t\t\t\tcaptured.stdout ? `stdout:\\n${captured.stdout}` : \"stdout: (empty)\",\n\t\t\t\t\tcaptured.stderr ? `stderr:\\n${captured.stderr}` : \"stderr: (empty)\",\n\t\t\t\t].join(\"\\n\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: body }],\n\t\t\t\t\t...(outcome === \"exited\" ? {} : { isError: true }),\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\toutcome,\n\t\t\t\t\t\texecutable: input.executable,\n\t\t\t\t\t\texitCode: terminal.code,\n\t\t\t\t\t\tdurationMs: Date.now() - startedAt,\n\t\t\t\t\t\ttruncated: captured.truncated,\n\t\t\t\t\t} satisfies RunProcessDetails,\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\t\toutputLimitAbort.signal.removeEventListener(\"abort\", abort);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function createRunProcessTool(cwd: string, options: RunProcessToolOptions): AgentTool {\n\treturn wrapToolDefinition(createRunProcessToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"run-process.js","sourceRoot":"","sources":["../../../src/core/tools/run-process.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,kCAAkC,EAAE,MAAM,8BAA8B,CAAC;AAEhG,OAAO,EACN,sCAAsC,GAEtC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,gCAAgC,GAAG,KAAK,CAAC;AAC/C,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAC7C,MAAM,yBAAyB,GAAG,EAAE,CAAC;AACrC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7C,MAAM,6BAA6B,GAAG,SAAS,CAAC;AAChD,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAExC,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CACnC;IACC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC;QACvB,SAAS,EAAE,gCAAgC;QAC3C,WAAW,EAAE,8CAA8C;KAC3D,CAAC;IACF,IAAI,EAAE,IAAI,CAAC,QAAQ,CAClB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,8BAA8B,EAAE,CAAC,EAAE;QACtE,QAAQ,EAAE,yBAAyB;QACnC,WAAW,EAAE,+CAA+C;KAC5D,CAAC,CACF;CACD,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AAoBF,MAAM,0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E,QAAQ,CAAC,SAAS;qBACD;iBAC7B,CAAC;YACH,CAAC;oBAAS,CAAC;gBACV,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC5C,gBAAgB,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YAC7D,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,GAAW,EAAE,OAA8B;IAC/E,OAAO,kBAAkB,CAAC,8BAA8B,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import type { ChildProcess } from \"node:child_process\";\nimport type { AgentTool } from \"@caupulican/pi-agent-core\";\nimport { type Static, Type } from \"typebox\";\nimport { spawnProcess, waitForChildProcessWithTermination } from \"../../utils/child-process.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tMAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES,\n\ttype OrchestrationExecutionPolicy,\n} from \"../orchestration/contracts.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\nconst MAX_RUN_PROCESS_EXECUTABLE_CHARS = 4_096;\nconst MAX_RUN_PROCESS_ARGUMENT_CHARS = 4_096;\nconst MAX_RUN_PROCESS_ARGUMENTS = 64;\nconst MAX_RUN_PROCESS_ARGV_BYTES = 32 * 1024;\nconst MAX_RUN_PROCESS_WALL_CLOCK_MS = 3_600_000;\nconst MAX_VISIBLE_EXECUTABLES = 16;\nconst MAX_VISIBLE_EXECUTABLE_CHARS = 64;\n\nconst runProcessSchema = Type.Object(\n\t{\n\t\texecutable: Type.String({\n\t\t\tmaxLength: MAX_RUN_PROCESS_EXECUTABLE_CHARS,\n\t\t\tdescription: \"Exact owner-allowed executable name or path.\",\n\t\t}),\n\t\targs: Type.Optional(\n\t\t\tType.Array(Type.String({ maxLength: MAX_RUN_PROCESS_ARGUMENT_CHARS }), {\n\t\t\t\tmaxItems: MAX_RUN_PROCESS_ARGUMENTS,\n\t\t\t\tdescription: \"Direct argv entries. No shell parsing occurs.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type RunProcessInput = Static<typeof runProcessSchema>;\n\nexport interface RunProcessDetails {\n\toutcome: \"exited\" | \"failed\" | \"aborted\" | \"timeout\" | \"output_limit\";\n\texecutable: string;\n\texitCode: number | null;\n\tdurationMs: number;\n\ttruncated: boolean;\n}\n\nexport interface RunProcessToolOptions {\n\tpolicy: OrchestrationExecutionPolicy;\n\tmaxWallClockMs: number;\n\tspawn?: typeof spawnProcess;\n\t/** Additional environment resolved for the execution cwd; the policy allowlist still applies. */\n\tenvironment?: (cwd: string) => NodeJS.ProcessEnv;\n}\n\nconst SAFE_ENVIRONMENT_VARIABLES = [\n\t\"PATH\",\n\t\"PATHEXT\",\n\t\"SystemRoot\",\n\t\"WINDIR\",\n\t\"COMSPEC\",\n\t\"TMPDIR\",\n\t\"TMP\",\n\t\"TEMP\",\n] as const;\nconst OWNER_CONTROL_PLANE_ENVIRONMENT_VARIABLES = new Set([\"BW_SESSION\"]);\n\nfunction scopedEnvironment(allowedNames: readonly string[], additional: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n\tconst names = new Set<string>([...SAFE_ENVIRONMENT_VARIABLES, ...allowedNames]);\n\tconst environment: NodeJS.ProcessEnv = {};\n\tfor (const name of names) {\n\t\tif (OWNER_CONTROL_PLANE_ENVIRONMENT_VARIABLES.has(name)) continue;\n\t\tconst value = additional[name] ?? process.env[name];\n\t\tif (value !== undefined) environment[name] = value;\n\t}\n\treturn environment;\n}\n\nfunction executableCatalogDescription(allowedExecutables: readonly string[]): string {\n\tconst visible = allowedExecutables\n\t\t.slice(0, MAX_VISIBLE_EXECUTABLES)\n\t\t.map((executable) => executable.slice(0, MAX_VISIBLE_EXECUTABLE_CHARS));\n\tconst omitted = allowedExecutables.length - visible.length;\n\treturn `${allowedExecutables.length} configured: ${visible.join(\", \")}${omitted > 0 ? `; ${omitted} omitted` : \"\"}`;\n}\n\nfunction resolveProcessPolicy(options: RunProcessToolOptions): { maxOutputBytes: number; timeoutMs: number } {\n\tif (\n\t\t!Number.isSafeInteger(options.policy.maxOutputBytes) ||\n\t\toptions.policy.maxOutputBytes <= 0 ||\n\t\t!Number.isSafeInteger(options.maxWallClockMs) ||\n\t\toptions.maxWallClockMs < 0\n\t) {\n\t\tthrow new TypeError(\"process_policy_invalid: output and wall-clock limits must be bounded integers.\");\n\t}\n\treturn {\n\t\tmaxOutputBytes: Math.min(options.policy.maxOutputBytes, MAX_ORCHESTRATION_PROCESS_OUTPUT_BYTES),\n\t\t// A zero lane-level budget disables that budget, not the execution-plane safety ceiling.\n\t\ttimeoutMs:\n\t\t\toptions.maxWallClockMs === 0\n\t\t\t\t? MAX_RUN_PROCESS_WALL_CLOCK_MS\n\t\t\t\t: Math.min(options.maxWallClockMs, MAX_RUN_PROCESS_WALL_CLOCK_MS),\n\t};\n}\n\nfunction validateProcessInput(input: RunProcessInput): string[] {\n\tif (\n\t\ttypeof input.executable !== \"string\" ||\n\t\tinput.executable.length === 0 ||\n\t\tinput.executable.length > MAX_RUN_PROCESS_EXECUTABLE_CHARS ||\n\t\tinput.executable.includes(\"\\0\")\n\t) {\n\t\tthrow new Error(\"process_argument_invalid: executable is empty, oversized, or contains a NUL byte.\");\n\t}\n\tif (\n\t\tinput.args !== undefined &&\n\t\t(!Array.isArray(input.args) ||\n\t\t\tinput.args.length > MAX_RUN_PROCESS_ARGUMENTS ||\n\t\t\tinput.args.some(\n\t\t\t\t(argument) =>\n\t\t\t\t\ttypeof argument !== \"string\" ||\n\t\t\t\t\targument.length > MAX_RUN_PROCESS_ARGUMENT_CHARS ||\n\t\t\t\t\targument.includes(\"\\0\"),\n\t\t\t))\n\t) {\n\t\tthrow new Error(\"process_argument_invalid: argv exceeds its count/size bound or contains a NUL byte.\");\n\t}\n\tconst args = input.args ?? [];\n\tlet argvBytes = Buffer.byteLength(input.executable, \"utf-8\");\n\tfor (const argument of args) {\n\t\targvBytes += 1 + Buffer.byteLength(argument, \"utf-8\");\n\t\tif (argvBytes > MAX_RUN_PROCESS_ARGV_BYTES) {\n\t\t\tthrow new Error(`process_argument_invalid: executable and argv exceed ${MAX_RUN_PROCESS_ARGV_BYTES} bytes.`);\n\t\t}\n\t}\n\treturn args;\n}\n\nfunction collectBoundedOutput(\n\tchild: ChildProcess,\n\tmaxBytes: number,\n\tabort: () => void,\n): {\n\tread(): { stdout: string; stderr: string; truncated: boolean };\n} {\n\tlet remaining = maxBytes;\n\tlet truncated = false;\n\tconst stdout: Buffer[] = [];\n\tconst stderr: Buffer[] = [];\n\tconst collect = (target: Buffer[]) => (chunk: Buffer) => {\n\t\tif (remaining <= 0) return;\n\t\tconst retained = chunk.subarray(0, remaining);\n\t\ttarget.push(retained);\n\t\tremaining -= retained.length;\n\t\tif (retained.length < chunk.length || remaining === 0) {\n\t\t\ttruncated = true;\n\t\t\tabort();\n\t\t}\n\t};\n\tchild.stdout?.on(\"data\", collect(stdout));\n\tchild.stderr?.on(\"data\", collect(stderr));\n\treturn {\n\t\tread: () => ({\n\t\t\tstdout: Buffer.concat(stdout).toString(\"utf-8\"),\n\t\t\tstderr: Buffer.concat(stderr).toString(\"utf-8\"),\n\t\t\ttruncated,\n\t\t}),\n\t};\n}\n\nexport function createRunProcessToolDefinition(cwd: string, options: RunProcessToolOptions): ToolDefinition {\n\tconst processPolicy = resolveProcessPolicy(options);\n\tconst allowedExecutables = new Set(options.policy.allowedExecutables);\n\treturn {\n\t\tname: \"run_process\",\n\t\tlabel: \"Run Process\",\n\t\tdescription: `Run one owner-allowed executable using direct argv without a shell. Allowed executables: ${executableCatalogDescription(options.policy.allowedExecutables)}.`,\n\t\tpromptSnippet: \"Run owner-allowed executable via constrained direct argv; not OS isolation.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Executable must be profile-listed. Arguments literal; no shell operators/interpolation.\",\n\t\t\t\"Project credentials inject only when execution profile also allows variable names.\",\n\t\t\t\"Nonzero exit/timeout/abort/output-limit means failure.\",\n\t\t],\n\t\tparameters: runProcessSchema,\n\t\tasync execute(_toolCallId, input: RunProcessInput, signal) {\n\t\t\tconst args = validateProcessInput(input);\n\t\t\tif (!allowedExecutables.has(input.executable)) {\n\t\t\t\tthrow new Error(`process_executable_denied: '${input.executable}' is not owner-allowed.`);\n\t\t\t}\n\t\t\tconst startedAt = Date.now();\n\t\t\tconst outputLimitAbort = new AbortController();\n\t\t\tlet outputLimitReached = false;\n\t\t\tconst child = (options.spawn ?? spawnProcess)(input.executable, [...args], {\n\t\t\t\tcwd,\n\t\t\t\tenv: scopedEnvironment(options.policy.allowedEnvironmentVariables, options.environment?.(cwd) ?? {}),\n\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\twindowsHide: true,\n\t\t\t});\n\t\t\tconst output = collectBoundedOutput(child, processPolicy.maxOutputBytes, () => {\n\t\t\t\toutputLimitReached = true;\n\t\t\t\toutputLimitAbort.abort();\n\t\t\t});\n\t\t\tconst combinedAbort = new AbortController();\n\t\t\tconst abort = () => combinedAbort.abort();\n\t\t\tif (signal?.aborted || outputLimitAbort.signal.aborted) abort();\n\t\t\telse {\n\t\t\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\t\t\toutputLimitAbort.signal.addEventListener(\"abort\", abort, { once: true });\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tconst terminal = await waitForChildProcessWithTermination(child, {\n\t\t\t\t\tsignal: combinedAbort.signal,\n\t\t\t\t\ttimeoutMs: processPolicy.timeoutMs,\n\t\t\t\t\tkillGraceMs: 2_000,\n\t\t\t\t});\n\t\t\t\tconst captured = output.read();\n\t\t\t\tconst outcome: RunProcessDetails[\"outcome\"] = outputLimitReached\n\t\t\t\t\t? \"output_limit\"\n\t\t\t\t\t: terminal.reason === \"timeout\"\n\t\t\t\t\t\t? \"timeout\"\n\t\t\t\t\t\t: terminal.reason === \"aborted\"\n\t\t\t\t\t\t\t? \"aborted\"\n\t\t\t\t\t\t\t: terminal.code === 0\n\t\t\t\t\t\t\t\t? \"exited\"\n\t\t\t\t\t\t\t\t: \"failed\";\n\t\t\t\tconst body = [\n\t\t\t\t\t`outcome: ${outcome}`,\n\t\t\t\t\t`exitCode: ${terminal.code ?? \"null\"}`,\n\t\t\t\t\tcaptured.stdout ? `stdout:\\n${captured.stdout}` : \"stdout: (empty)\",\n\t\t\t\t\tcaptured.stderr ? `stderr:\\n${captured.stderr}` : \"stderr: (empty)\",\n\t\t\t\t].join(\"\\n\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\" as const, text: body }],\n\t\t\t\t\t...(outcome === \"exited\" ? {} : { isError: true }),\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\toutcome,\n\t\t\t\t\t\texecutable: input.executable,\n\t\t\t\t\t\texitCode: terminal.code,\n\t\t\t\t\t\tdurationMs: Date.now() - startedAt,\n\t\t\t\t\t\ttruncated: captured.truncated,\n\t\t\t\t\t} satisfies RunProcessDetails,\n\t\t\t\t};\n\t\t\t} finally {\n\t\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\t\toutputLimitAbort.signal.removeEventListener(\"abort\", abort);\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport function createRunProcessTool(cwd: string, options: RunProcessToolOptions): AgentTool {\n\treturn wrapToolDefinition(createRunProcessToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -16,11 +16,11 @@ export function createRunToolkitScriptToolDefinition(deps) {
|
|
|
16
16
|
name: "run_toolkit_script",
|
|
17
17
|
label: "run_toolkit_script",
|
|
18
18
|
description: "Run one of the user's registered toolkit scripts (daily-ops allowlist). Finding is a registry lookup — ambiguous requests return a shortlist to disambiguate, never a guess. The harness executes (uv/powershell/bash) and ALWAYS returns exit code, stdout, and stderr; failures are reported as errors — a failed script can never look like success.",
|
|
19
|
-
promptSnippet: "Run
|
|
19
|
+
promptSnippet: "Run registered toolkit script by name/alias; structured output/errors.",
|
|
20
20
|
promptGuidelines: [
|
|
21
|
-
"Prefer
|
|
22
|
-
"
|
|
23
|
-
"Report
|
|
21
|
+
"Prefer exact name. Shortlist: ask owner; pick only if request clearly names one.",
|
|
22
|
+
"Dangerous script needs explicit user confirmation, then confirm:true.",
|
|
23
|
+
"Report real output/exitCode; never claim success for nonzero exitCode.",
|
|
24
24
|
],
|
|
25
25
|
parameters: runToolkitScriptSchema,
|
|
26
26
|
async execute(toolCallId, input) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-toolkit-script.js","sourceRoot":"","sources":["../../../src/core/tools/run-toolkit-script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAExF,OAAO,EAAE,gBAAgB,EAAmB,MAAM,kCAAkC,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAsB,MAAM,+BAA+B,CAAC;AAGvF,MAAM,sBAAsB,GAAG,IAAI,CAAC,MAAM,CACzC;IACC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;QACnB,WAAW,EACV,iMAAiM;KAClM,CAAC;IACF,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,EAAE,WAAW,EAAE,uCAAuC,EAAE,CAAC,CAAC;IACxG,OAAO,EAAE,IAAI,CAAC,QAAQ,CACrB,IAAI,CAAC,OAAO,CAAC;QACZ,WAAW,EAAE,8FAA8F;KAC3G,CAAC,CACF;CACD,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AA0BF,MAAM,UAAU,oCAAoC,CAAC,IAAkC;IACtF,OAAO;QACN,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EACV,yVAAyV;QAC1V,aAAa,E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G,IAAI,EAAE;aACjD,EACD,IAAI,CAAC,aAAa,EAClB,UAAU,CACV,CAAC;YACF,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU;gBAC7B,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO,QAAQ,oBAAoB,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG;gBACrE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;YAElB,OAAO;gBACN,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;gBAChD,OAAO,EAAE;oBACR,GAAG,CAAC,WAAW;wBACd,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,UAAU,EAAE,EAAE;wBAC1F,CAAC,CAAC,EAAE,CAAC;oBACN,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU;oBACvC,UAAU,EAAE,MAAM,CAAC,IAAI;oBACvB,QAAQ,EAAE,SAAS,CAAC,QAAQ;oBAC5B,UAAU,EAAE,SAAS,CAAC,UAAU;oBAChC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC/D;gBACD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpC,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ArtifactStore } from \"../context/context-artifacts.ts\";\nimport { formatArtifactNotice, packToolOutput } from \"../context/tool-output-packer.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { acceptReflexPlan, type ReflexPlan } from \"../toolkit/reflex-interpreter.ts\";\nimport { matchToolkitScript, type ToolkitScript } from \"../toolkit/script-registry.ts\";\nimport type { ScriptExecution } from \"../toolkit/script-runner.ts\";\n\nconst runToolkitScriptSchema = Type.Object(\n\t{\n\t\tscript: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"The toolkit script to run: its registered name, a taught alias, or a natural request (e.g. 'restore-db' or 'restore the database'). Ambiguous requests return a shortlist instead of executing.\",\n\t\t}),\n\t\targs: Type.Optional(Type.Array(Type.String(), { description: \"Arguments passed to the script as-is.\" })),\n\t\tconfirm: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Required true to run a script flagged danger: scripts marked dangerous never run without it.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type RunToolkitScriptInput = Static<typeof runToolkitScriptSchema>;\n\nexport interface RunToolkitScriptDetails {\n\toutcome: \"executed\" | \"failed\" | \"ambiguous\" | \"not_found\" | \"confirmation_required\" | \"empty_registry\";\n\tscriptName?: string;\n\texitCode?: number | null;\n\tdurationMs?: number;\n\tshortlist?: string[];\n\tartifactId?: string;\n}\n\nexport interface RunToolkitScriptDependencies {\n\tgetScripts: () => ToolkitScript[];\n\texecute: (script: ToolkitScript, args: readonly string[]) => Promise<ScriptExecution>;\n\tartifactStore?: ArtifactStore;\n\t/**\n\t * Optional reflex interpreter (local brain): consulted ONLY when the deterministic Level-0\n\t * matcher is ambiguous, to resolve fuzzy phrasing (\"prepare db\" vs \"update db\") into a\n\t * registry pick. Its plan is advisory — the danger/confirm rules and structural execution\n\t * contract apply identically to brain-selected scripts.\n\t */\n\tinterpret?: (request: string, scripts: readonly ToolkitScript[]) => Promise<ReflexPlan | undefined>;\n}\n\nexport function createRunToolkitScriptToolDefinition(deps: RunToolkitScriptDependencies): ToolDefinition {\n\treturn {\n\t\tname: \"run_toolkit_script\",\n\t\tlabel: \"run_toolkit_script\",\n\t\tdescription:\n\t\t\t\"Run one of the user's registered toolkit scripts (daily-ops allowlist). Finding is a registry lookup — ambiguous requests return a shortlist to disambiguate, never a guess. The harness executes (uv/powershell/bash) and ALWAYS returns exit code, stdout, and stderr; failures are reported as errors — a failed script can never look like success.\",\n\t\tpromptSnippet: \"Run a registered toolkit script by name/alias; output and errors come back structurally.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Prefer the exact registered name; on a shortlist response, ask the user which one (or pick only when their request clearly names it).\",\n\t\t\t\"Scripts flagged dangerous require confirm: true — obtain explicit user confirmation first.\",\n\t\t\t\"Report the script's real output/exit code; never claim success when exitCode is non-zero.\",\n\t\t],\n\t\tparameters: runToolkitScriptSchema,\n\t\tasync execute(\n\t\t\ttoolCallId,\n\t\t\tinput: RunToolkitScriptInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: RunToolkitScriptDetails;\n\t\t\tisError?: boolean;\n\t\t}> {\n\t\t\tconst scripts = deps.getScripts();\n\t\t\tif (scripts.length === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: \"run_toolkit_script: no scripts registered (settings.toolkit.scripts).\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { outcome: \"empty_registry\" },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst match = matchToolkitScript(input.script, scripts);\n\t\t\tif (match.kind === \"none\") {\n\t\t\t\tconst closest = match.closest.map((script) => `${script.name} — ${script.description}`).join(\"\\n\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `script_not_found: nothing registered matches \"${input.script}\".${closest ? `\\nClosest:\\n${closest}` : \"\"}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { outcome: \"not_found\" },\n\t\t\t\t\tisError: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tlet interpreted: { script: ToolkitScript; args: string[]; confidence: number } | undefined;\n\t\t\tif (match.kind === \"ambiguous\" && deps.interpret) {\n\t\t\t\ttry {\n\t\t\t\t\tconst plan = await deps.interpret(input.script, scripts);\n\t\t\t\t\tconst accepted = acceptReflexPlan(plan, scripts);\n\t\t\t\t\tif (accepted && plan) {\n\t\t\t\t\t\tinterpreted = { ...accepted, confidence: plan.confidence };\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// interpreter is best-effort; ambiguity handling below stays authoritative\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (match.kind === \"ambiguous\" && !interpreted) {\n\t\t\t\tconst shortlist = match.shortlist.map((script) => `${script.name} — ${script.description}`);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Ambiguous request — did you mean:\\n${shortlist.join(\"\\n\")}\\nCall again with the exact name.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { outcome: \"ambiguous\", shortlist: match.shortlist.map((script) => script.name) },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst script = interpreted?.script ?? (match as { script: ToolkitScript }).script;\n\t\t\tif (script.danger && input.confirm !== true) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `\"${script.name}\" is flagged DANGEROUS (${script.description}). It was NOT run. Confirm with the user, then call again with confirm: true.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { outcome: \"confirmation_required\", scriptName: script.name },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Explicit args from the caller win; a brain-extracted arg list fills in for fuzzy requests.\n\t\t\tconst execution = await deps.execute(script, input.args ?? interpreted?.args ?? []);\n\t\t\tconst failed = execution.exitCode !== 0 || execution.timedOut;\n\t\t\tconst header = failed\n\t\t\t\t? `FAILED: ${script.name} exited ${execution.timedOut ? \"by timeout\" : execution.exitCode} after ${execution.durationMs}ms`\n\t\t\t\t: `${script.name} succeeded in ${execution.durationMs}ms`;\n\t\t\tconst rawBody = [\n\t\t\t\theader,\n\t\t\t\texecution.stdout.trim() ? `stdout:\\n${execution.stdout.trim()}` : \"stdout: (empty)\",\n\t\t\t\texecution.stderr.trim() ? `stderr:\\n${execution.stderr.trim()}` : \"\",\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(\"\\n\");\n\t\t\tconst packed = packToolOutput(\n\t\t\t\t{\n\t\t\t\t\ttoolName: \"run_toolkit_script\",\n\t\t\t\t\tcommand: script.name,\n\t\t\t\t\tpath: script.path,\n\t\t\t\t\trawContent: rawBody,\n\t\t\t\t\treproducible: false,\n\t\t\t\t\ttruncation: { maxLines: 400, maxBytes: 8 * 1024 },\n\t\t\t\t},\n\t\t\t\tdeps.artifactStore,\n\t\t\t\ttoolCallId,\n\t\t\t);\n\t\t\tconst body = packed.artifactId\n\t\t\t\t? `${packed.content}\\n\\n[${formatArtifactNotice(packed.artifactId)}]`\n\t\t\t\t: packed.content;\n\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: body }],\n\t\t\t\tdetails: {\n\t\t\t\t\t...(interpreted\n\t\t\t\t\t\t? { interpreter: { script: interpreted.script.name, confidence: interpreted.confidence } }\n\t\t\t\t\t\t: {}),\n\t\t\t\t\toutcome: failed ? \"failed\" : \"executed\",\n\t\t\t\t\tscriptName: script.name,\n\t\t\t\t\texitCode: execution.exitCode,\n\t\t\t\t\tdurationMs: execution.durationMs,\n\t\t\t\t\t...(packed.artifactId ? { artifactId: packed.artifactId } : {}),\n\t\t\t\t},\n\t\t\t\t...(failed ? { isError: true } : {}),\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"run-toolkit-script.js","sourceRoot":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,WAAW;wBACd,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,UAAU,EAAE,EAAE;wBAC1F,CAAC,CAAC,EAAE,CAAC;oBACN,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU;oBACvC,UAAU,EAAE,MAAM,CAAC,IAAI;oBACvB,QAAQ,EAAE,SAAS,CAAC,QAAQ;oBAC5B,UAAU,EAAE,SAAS,CAAC,UAAU;oBAChC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC/D;gBACD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpC,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ArtifactStore } from \"../context/context-artifacts.ts\";\nimport { formatArtifactNotice, packToolOutput } from \"../context/tool-output-packer.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport { acceptReflexPlan, type ReflexPlan } from \"../toolkit/reflex-interpreter.ts\";\nimport { matchToolkitScript, type ToolkitScript } from \"../toolkit/script-registry.ts\";\nimport type { ScriptExecution } from \"../toolkit/script-runner.ts\";\n\nconst runToolkitScriptSchema = Type.Object(\n\t{\n\t\tscript: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"The toolkit script to run: its registered name, a taught alias, or a natural request (e.g. 'restore-db' or 'restore the database'). Ambiguous requests return a shortlist instead of executing.\",\n\t\t}),\n\t\targs: Type.Optional(Type.Array(Type.String(), { description: \"Arguments passed to the script as-is.\" })),\n\t\tconfirm: Type.Optional(\n\t\t\tType.Boolean({\n\t\t\t\tdescription: \"Required true to run a script flagged danger: scripts marked dangerous never run without it.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type RunToolkitScriptInput = Static<typeof runToolkitScriptSchema>;\n\nexport interface RunToolkitScriptDetails {\n\toutcome: \"executed\" | \"failed\" | \"ambiguous\" | \"not_found\" | \"confirmation_required\" | \"empty_registry\";\n\tscriptName?: string;\n\texitCode?: number | null;\n\tdurationMs?: number;\n\tshortlist?: string[];\n\tartifactId?: string;\n}\n\nexport interface RunToolkitScriptDependencies {\n\tgetScripts: () => ToolkitScript[];\n\texecute: (script: ToolkitScript, args: readonly string[]) => Promise<ScriptExecution>;\n\tartifactStore?: ArtifactStore;\n\t/**\n\t * Optional reflex interpreter (local brain): consulted ONLY when the deterministic Level-0\n\t * matcher is ambiguous, to resolve fuzzy phrasing (\"prepare db\" vs \"update db\") into a\n\t * registry pick. Its plan is advisory — the danger/confirm rules and structural execution\n\t * contract apply identically to brain-selected scripts.\n\t */\n\tinterpret?: (request: string, scripts: readonly ToolkitScript[]) => Promise<ReflexPlan | undefined>;\n}\n\nexport function createRunToolkitScriptToolDefinition(deps: RunToolkitScriptDependencies): ToolDefinition {\n\treturn {\n\t\tname: \"run_toolkit_script\",\n\t\tlabel: \"run_toolkit_script\",\n\t\tdescription:\n\t\t\t\"Run one of the user's registered toolkit scripts (daily-ops allowlist). Finding is a registry lookup — ambiguous requests return a shortlist to disambiguate, never a guess. The harness executes (uv/powershell/bash) and ALWAYS returns exit code, stdout, and stderr; failures are reported as errors — a failed script can never look like success.\",\n\t\tpromptSnippet: \"Run registered toolkit script by name/alias; structured output/errors.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Prefer exact name. Shortlist: ask owner; pick only if request clearly names one.\",\n\t\t\t\"Dangerous script needs explicit user confirmation, then confirm:true.\",\n\t\t\t\"Report real output/exitCode; never claim success for nonzero exitCode.\",\n\t\t],\n\t\tparameters: runToolkitScriptSchema,\n\t\tasync execute(\n\t\t\ttoolCallId,\n\t\t\tinput: RunToolkitScriptInput,\n\t\t): Promise<{\n\t\t\tcontent: Array<{ type: \"text\"; text: string }>;\n\t\t\tdetails: RunToolkitScriptDetails;\n\t\t\tisError?: boolean;\n\t\t}> {\n\t\t\tconst scripts = deps.getScripts();\n\t\t\tif (scripts.length === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: \"run_toolkit_script: no scripts registered (settings.toolkit.scripts).\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { outcome: \"empty_registry\" },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst match = matchToolkitScript(input.script, scripts);\n\t\t\tif (match.kind === \"none\") {\n\t\t\t\tconst closest = match.closest.map((script) => `${script.name} — ${script.description}`).join(\"\\n\");\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `script_not_found: nothing registered matches \"${input.script}\".${closest ? `\\nClosest:\\n${closest}` : \"\"}`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { outcome: \"not_found\" },\n\t\t\t\t\tisError: true,\n\t\t\t\t};\n\t\t\t}\n\t\t\tlet interpreted: { script: ToolkitScript; args: string[]; confidence: number } | undefined;\n\t\t\tif (match.kind === \"ambiguous\" && deps.interpret) {\n\t\t\t\ttry {\n\t\t\t\t\tconst plan = await deps.interpret(input.script, scripts);\n\t\t\t\t\tconst accepted = acceptReflexPlan(plan, scripts);\n\t\t\t\t\tif (accepted && plan) {\n\t\t\t\t\t\tinterpreted = { ...accepted, confidence: plan.confidence };\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// interpreter is best-effort; ambiguity handling below stays authoritative\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (match.kind === \"ambiguous\" && !interpreted) {\n\t\t\t\tconst shortlist = match.shortlist.map((script) => `${script.name} — ${script.description}`);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `Ambiguous request — did you mean:\\n${shortlist.join(\"\\n\")}\\nCall again with the exact name.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { outcome: \"ambiguous\", shortlist: match.shortlist.map((script) => script.name) },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst script = interpreted?.script ?? (match as { script: ToolkitScript }).script;\n\t\t\tif (script.danger && input.confirm !== true) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\t\ttext: `\"${script.name}\" is flagged DANGEROUS (${script.description}). It was NOT run. Confirm with the user, then call again with confirm: true.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { outcome: \"confirmation_required\", scriptName: script.name },\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Explicit args from the caller win; a brain-extracted arg list fills in for fuzzy requests.\n\t\t\tconst execution = await deps.execute(script, input.args ?? interpreted?.args ?? []);\n\t\t\tconst failed = execution.exitCode !== 0 || execution.timedOut;\n\t\t\tconst header = failed\n\t\t\t\t? `FAILED: ${script.name} exited ${execution.timedOut ? \"by timeout\" : execution.exitCode} after ${execution.durationMs}ms`\n\t\t\t\t: `${script.name} succeeded in ${execution.durationMs}ms`;\n\t\t\tconst rawBody = [\n\t\t\t\theader,\n\t\t\t\texecution.stdout.trim() ? `stdout:\\n${execution.stdout.trim()}` : \"stdout: (empty)\",\n\t\t\t\texecution.stderr.trim() ? `stderr:\\n${execution.stderr.trim()}` : \"\",\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(\"\\n\");\n\t\t\tconst packed = packToolOutput(\n\t\t\t\t{\n\t\t\t\t\ttoolName: \"run_toolkit_script\",\n\t\t\t\t\tcommand: script.name,\n\t\t\t\t\tpath: script.path,\n\t\t\t\t\trawContent: rawBody,\n\t\t\t\t\treproducible: false,\n\t\t\t\t\ttruncation: { maxLines: 400, maxBytes: 8 * 1024 },\n\t\t\t\t},\n\t\t\t\tdeps.artifactStore,\n\t\t\t\ttoolCallId,\n\t\t\t);\n\t\t\tconst body = packed.artifactId\n\t\t\t\t? `${packed.content}\\n\\n[${formatArtifactNotice(packed.artifactId)}]`\n\t\t\t\t: packed.content;\n\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\" as const, text: body }],\n\t\t\t\tdetails: {\n\t\t\t\t\t...(interpreted\n\t\t\t\t\t\t? { interpreter: { script: interpreted.script.name, confidence: interpreted.confidence } }\n\t\t\t\t\t\t: {}),\n\t\t\t\t\toutcome: failed ? \"failed\" : \"executed\",\n\t\t\t\t\tscriptName: script.name,\n\t\t\t\t\texitCode: execution.exitCode,\n\t\t\t\t\tdurationMs: execution.durationMs,\n\t\t\t\t\t...(packed.artifactId ? { artifactId: packed.artifactId } : {}),\n\t\t\t\t},\n\t\t\t\t...(failed ? { isError: true } : {}),\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { type Static, Type } from "typebox";
|
|
2
2
|
import { type CredentialManager, type CredentialProfileSummary } from "../secrets/credential-manager.ts";
|
|
3
|
+
import { type CredentialMigrationSourceResolver } from "../secrets/credential-migration-source.ts";
|
|
3
4
|
declare const secretStoreSchema: Type.TObject<{
|
|
4
|
-
action: Type.TUnion<[Type.TLiteral<"status">, Type.TLiteral<"list">, Type.TLiteral<"activate">]>;
|
|
5
|
+
action: Type.TUnion<[Type.TLiteral<"status">, Type.TLiteral<"list">, Type.TLiteral<"activate">, Type.TLiteral<"migrate">]>;
|
|
5
6
|
profile: Type.TOptional<Type.TString>;
|
|
7
|
+
description: Type.TOptional<Type.TString>;
|
|
8
|
+
overwrite: Type.TOptional<Type.TBoolean>;
|
|
9
|
+
sources: Type.TOptional<Type.TArray<Type.TUnion<[Type.TObject<{
|
|
10
|
+
kind: Type.TLiteral<"environment">;
|
|
11
|
+
name: Type.TString;
|
|
12
|
+
}>, Type.TObject<{
|
|
13
|
+
kind: Type.TLiteral<"dotenv_file">;
|
|
14
|
+
path: Type.TString;
|
|
15
|
+
}>, Type.TObject<{
|
|
16
|
+
kind: Type.TLiteral<"file">;
|
|
17
|
+
path: Type.TString;
|
|
18
|
+
variable: Type.TString;
|
|
19
|
+
}>]>>>;
|
|
6
20
|
}>;
|
|
7
21
|
export type SecretStoreToolInput = Static<typeof secretStoreSchema>;
|
|
8
|
-
export type SecretStoreStatus = "activated" | "available" | "cancelled" | "error" | "listed" | "unavailable";
|
|
22
|
+
export type SecretStoreStatus = "activated" | "available" | "cancelled" | "error" | "listed" | "migrated" | "unavailable";
|
|
9
23
|
export interface SecretStoreToolDetails {
|
|
10
24
|
action: SecretStoreToolInput["action"];
|
|
11
25
|
status: SecretStoreStatus;
|
|
@@ -16,13 +30,28 @@ export interface SecretStoreToolDetails {
|
|
|
16
30
|
connected?: boolean;
|
|
17
31
|
code?: string;
|
|
18
32
|
message?: string;
|
|
33
|
+
sourceRetained?: boolean;
|
|
19
34
|
}
|
|
20
35
|
export interface SecretStoreToolOptions {
|
|
21
36
|
manager: CredentialManager;
|
|
37
|
+
resolveMigrationSources?: CredentialMigrationSourceResolver;
|
|
22
38
|
}
|
|
23
39
|
export declare function createSecretStoreToolDefinition(options: SecretStoreToolOptions): import("../extensions/types.ts").ToolDefinition<Type.TObject<{
|
|
24
|
-
action: Type.TUnion<[Type.TLiteral<"status">, Type.TLiteral<"list">, Type.TLiteral<"activate">]>;
|
|
40
|
+
action: Type.TUnion<[Type.TLiteral<"status">, Type.TLiteral<"list">, Type.TLiteral<"activate">, Type.TLiteral<"migrate">]>;
|
|
25
41
|
profile: Type.TOptional<Type.TString>;
|
|
42
|
+
description: Type.TOptional<Type.TString>;
|
|
43
|
+
overwrite: Type.TOptional<Type.TBoolean>;
|
|
44
|
+
sources: Type.TOptional<Type.TArray<Type.TUnion<[Type.TObject<{
|
|
45
|
+
kind: Type.TLiteral<"environment">;
|
|
46
|
+
name: Type.TString;
|
|
47
|
+
}>, Type.TObject<{
|
|
48
|
+
kind: Type.TLiteral<"dotenv_file">;
|
|
49
|
+
path: Type.TString;
|
|
50
|
+
}>, Type.TObject<{
|
|
51
|
+
kind: Type.TLiteral<"file">;
|
|
52
|
+
path: Type.TString;
|
|
53
|
+
variable: Type.TString;
|
|
54
|
+
}>]>>>;
|
|
26
55
|
}>, SecretStoreToolDetails, any> & import("../extensions/types.ts").ToolDefinition<any, any, any>;
|
|
27
56
|
export {};
|
|
28
57
|
//# sourceMappingURL=secret-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret-store.d.ts","sourceRoot":"","sources":["../../../src/core/tools/secret-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EACN,KAAK,iBAAiB,EAEtB,KAAK,wBAAwB,EAE7B,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"secret-store.d.ts","sourceRoot":"","sources":["../../../src/core/tools/secret-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EACN,KAAK,iBAAiB,EAEtB,KAAK,wBAAwB,EAE7B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAEN,KAAK,iCAAiC,EAEtC,MAAM,2CAA2C,CAAC;AAkCnD,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;EA6BtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEpE,MAAM,MAAM,iBAAiB,GAC1B,WAAW,GACX,WAAW,GACX,WAAW,GACX,OAAO,GACP,QAAQ,GACR,UAAU,GACV,aAAa,CAAC;AAEjB,MAAM,WAAW,sBAAsB;IACtC,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,wBAAwB,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,sBAAsB;IACtC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,uBAAuB,CAAC,EAAE,iCAAiC,CAAC;CAC5D;AA4HD,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,sBAAsB;;;;;;;;;;;;;;;;kGA4I9E"}
|
|
@@ -1,22 +1,66 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { defineTool } from "../extensions/types.js";
|
|
3
3
|
import { CredentialManagerError, CredentialStorageError, } from "../secrets/credential-manager.js";
|
|
4
|
+
import { CredentialMigrationSourceError, resolveCredentialMigrationSources, } from "../secrets/credential-migration-source.js";
|
|
5
|
+
import { connectCredentialSessionWithMaskedPrompt, isCredentialSessionKeyRequired, } from "../secrets/credential-session-connection.js";
|
|
6
|
+
import { SECRET_VARIABLE_NAME_MAX_CHARS, SECRET_VARIABLE_NAME_PATTERN } from "../secrets/secret-dotenv.js";
|
|
4
7
|
import { emptyOrchestrationCall, OrchestrationPanelComponent, } from "./orchestration-panel.js";
|
|
8
|
+
const migrationSourceSchema = Type.Union([
|
|
9
|
+
Type.Object({
|
|
10
|
+
kind: Type.Literal("environment"),
|
|
11
|
+
name: Type.String({ maxLength: SECRET_VARIABLE_NAME_MAX_CHARS, pattern: SECRET_VARIABLE_NAME_PATTERN }),
|
|
12
|
+
}, { additionalProperties: false }),
|
|
13
|
+
Type.Object({ kind: Type.Literal("dotenv_file"), path: Type.String({ minLength: 1, maxLength: 4096 }) }, { additionalProperties: false }),
|
|
14
|
+
Type.Object({
|
|
15
|
+
kind: Type.Literal("file"),
|
|
16
|
+
path: Type.String({ minLength: 1, maxLength: 4096 }),
|
|
17
|
+
variable: Type.String({ maxLength: SECRET_VARIABLE_NAME_MAX_CHARS, pattern: SECRET_VARIABLE_NAME_PATTERN }),
|
|
18
|
+
}, { additionalProperties: false }),
|
|
19
|
+
]);
|
|
5
20
|
const secretStoreSchema = Type.Object({
|
|
6
|
-
action: Type.Union([Type.Literal("status"), Type.Literal("list"), Type.Literal("activate")], {
|
|
7
|
-
description: "
|
|
21
|
+
action: Type.Union([Type.Literal("status"), Type.Literal("list"), Type.Literal("activate"), Type.Literal("migrate")], {
|
|
22
|
+
description: "Inspect, activate, or migrate model-blind credential sources.",
|
|
8
23
|
}),
|
|
9
24
|
profile: Type.Optional(Type.String({
|
|
10
25
|
minLength: 1,
|
|
11
26
|
maxLength: 96,
|
|
12
27
|
pattern: "^[A-Za-z0-9][A-Za-z0-9._-]*$",
|
|
13
|
-
description: "
|
|
28
|
+
description: "Profile to activate or create during migration.",
|
|
29
|
+
})),
|
|
30
|
+
description: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),
|
|
31
|
+
overwrite: Type.Optional(Type.Boolean({ description: "Explicitly replace an existing profile while preserving project bindings." })),
|
|
32
|
+
sources: Type.Optional(Type.Array(migrationSourceSchema, {
|
|
33
|
+
minItems: 1,
|
|
34
|
+
maxItems: 64,
|
|
35
|
+
description: "Host-side credential sources. Values are never accepted in tool arguments.",
|
|
14
36
|
})),
|
|
15
37
|
}, { additionalProperties: false });
|
|
16
38
|
function result(details, text) {
|
|
17
39
|
return { content: [{ type: "text", text }], details };
|
|
18
40
|
}
|
|
41
|
+
function ownerSetupRequired(action) {
|
|
42
|
+
const message = "Bitwarden needs one owner input: a BW_SESSION key supplied through Pi's masked prompt or process environment, never through chat.";
|
|
43
|
+
return result({
|
|
44
|
+
action,
|
|
45
|
+
status: "unavailable",
|
|
46
|
+
...(action === "status" ? { connected: false } : {}),
|
|
47
|
+
code: "owner_setup_required",
|
|
48
|
+
message,
|
|
49
|
+
}, message);
|
|
50
|
+
}
|
|
51
|
+
function cancelled(action) {
|
|
52
|
+
return result({ action, status: "cancelled", code: "cancelled" }, "Credential action cancelled.");
|
|
53
|
+
}
|
|
19
54
|
function invalid(input) {
|
|
55
|
+
if (input.action === "migrate") {
|
|
56
|
+
if (!input.profile || !input.sources) {
|
|
57
|
+
return result({ action: input.action, status: "error", code: "missing_migration_input" }, "Credential migration requires a profile and at least one source.");
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (input.description !== undefined || input.sources !== undefined || input.overwrite !== undefined) {
|
|
62
|
+
return result({ action: input.action, status: "error", code: "unexpected_migration_input" }, `Action ${input.action} does not accept migration inputs.`);
|
|
63
|
+
}
|
|
20
64
|
if (input.action !== "activate" && input.profile !== undefined) {
|
|
21
65
|
return result({
|
|
22
66
|
action: input.action,
|
|
@@ -28,9 +72,21 @@ function invalid(input) {
|
|
|
28
72
|
return undefined;
|
|
29
73
|
}
|
|
30
74
|
function failed(input, error) {
|
|
31
|
-
const known = error instanceof CredentialManagerError ||
|
|
75
|
+
const known = error instanceof CredentialManagerError ||
|
|
76
|
+
error instanceof CredentialStorageError ||
|
|
77
|
+
error instanceof CredentialMigrationSourceError;
|
|
32
78
|
const code = known ? error.code : "safe_failure";
|
|
33
|
-
const
|
|
79
|
+
const migrationMessages = {
|
|
80
|
+
duplicate_variable: "Credential migration defines the same variable more than once.",
|
|
81
|
+
invalid_source: "Credential migration source data is invalid.",
|
|
82
|
+
source_not_found: "A requested credential source is unavailable.",
|
|
83
|
+
source_unavailable: "A requested credential source could not be read.",
|
|
84
|
+
};
|
|
85
|
+
const message = error instanceof CredentialMigrationSourceError
|
|
86
|
+
? (migrationMessages[error.code] ?? "Credential migration failed safely without exposing values.")
|
|
87
|
+
: known
|
|
88
|
+
? error.message
|
|
89
|
+
: "Credential action failed safely without exposing values.";
|
|
34
90
|
const status = ["owner_setup_required", "not_connected", "provider_unavailable"].includes(code)
|
|
35
91
|
? "unavailable"
|
|
36
92
|
: "error";
|
|
@@ -45,7 +101,7 @@ function failed(input, error) {
|
|
|
45
101
|
function panelModel(details, expanded) {
|
|
46
102
|
if (!details)
|
|
47
103
|
return { label: "secrets", status: "error", emptyText: "No credential result was retained." };
|
|
48
|
-
const success = ["activated", "available", "listed"].includes(details.status);
|
|
104
|
+
const success = ["activated", "available", "listed", "migrated"].includes(details.status);
|
|
49
105
|
return {
|
|
50
106
|
label: "secrets",
|
|
51
107
|
action: details.status,
|
|
@@ -74,17 +130,22 @@ function panelModel(details, expanded) {
|
|
|
74
130
|
}
|
|
75
131
|
export function createSecretStoreToolDefinition(options) {
|
|
76
132
|
const { manager } = options;
|
|
133
|
+
const resolveSources = options.resolveMigrationSources ?? resolveCredentialMigrationSources;
|
|
77
134
|
return defineTool({
|
|
78
135
|
name: "secret_store",
|
|
79
136
|
label: "Secret Store",
|
|
80
|
-
description: "Discover and activate
|
|
81
|
-
promptSnippet: "
|
|
137
|
+
description: "Discover, migrate, and activate Bitwarden credential profiles for the current project without exposing values.",
|
|
138
|
+
promptSnippet: "Migrate accessible credentials into Bitwarden, activate project credentials; never expose values.",
|
|
82
139
|
promptGuidelines: [
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
140
|
+
"Active user-plane host gate authorizes model-blind migration; never ask duplicate confirmation.",
|
|
141
|
+
"Credentials needed: call secret_store. If disconnected, TUI asks for one masked BW_SESSION only; never request chat/setup work.",
|
|
142
|
+
"activate before credential work; TUI/print/RPC return metadata only.",
|
|
143
|
+
"One project binding: omit profile. Multiple: use list, select authorized profile.",
|
|
144
|
+
"Never request credentials in chat/tool arguments.",
|
|
145
|
+
"After activation, run consumer normally; never print/inspect/grep/echo credential environment values.",
|
|
146
|
+
"migrate accepts environment names, dotenv paths, key-file paths; never credential values.",
|
|
147
|
+
"Migration keeps sources. overwrite only for intentional Bitwarden profile replacement.",
|
|
148
|
+
"owner_setup_required without UI: report only BW_SESSION missing, supplied out of band to Pi; never request more/retry.",
|
|
88
149
|
],
|
|
89
150
|
parameters: secretStoreSchema,
|
|
90
151
|
executionMode: "sequential",
|
|
@@ -104,7 +165,7 @@ export function createSecretStoreToolDefinition(options) {
|
|
|
104
165
|
},
|
|
105
166
|
async execute(_toolCallId, input, signal, _onUpdate, ctx) {
|
|
106
167
|
if (signal?.aborted) {
|
|
107
|
-
return
|
|
168
|
+
return cancelled(input.action);
|
|
108
169
|
}
|
|
109
170
|
const validation = invalid(input);
|
|
110
171
|
if (validation)
|
|
@@ -112,31 +173,77 @@ export function createSecretStoreToolDefinition(options) {
|
|
|
112
173
|
try {
|
|
113
174
|
if (input.action === "status") {
|
|
114
175
|
const status = manager.status;
|
|
115
|
-
if (!status.sessionAvailable)
|
|
116
|
-
return
|
|
117
|
-
action: input.action,
|
|
118
|
-
status: "unavailable",
|
|
119
|
-
connected: false,
|
|
120
|
-
code: "owner_setup_required",
|
|
121
|
-
message: "The owner must connect Bitwarden with /secrets.",
|
|
122
|
-
}, "Bitwarden owner setup is required. Run /secrets in a TUI session.");
|
|
123
|
-
}
|
|
176
|
+
if (!status.sessionAvailable)
|
|
177
|
+
return ownerSetupRequired(input.action);
|
|
124
178
|
return result({ action: input.action, status: "available", connected: status.connected }, status.connected
|
|
125
179
|
? "Bitwarden is connected for this Pi session."
|
|
126
180
|
: "A Bitwarden session key is available and will be validated on activation.");
|
|
127
181
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
182
|
+
const executeCredentialAction = async () => {
|
|
183
|
+
if (input.action === "list") {
|
|
184
|
+
const profiles = await manager.listForProject(ctx.cwd, signal);
|
|
185
|
+
return result({ action: input.action, status: "listed", profiles }, `Found ${profiles.length} credential profile${profiles.length === 1 ? "" : "s"}; only metadata was returned.`);
|
|
186
|
+
}
|
|
187
|
+
if (input.action === "migrate") {
|
|
188
|
+
const { profile, sources } = input;
|
|
189
|
+
if (!profile || !sources) {
|
|
190
|
+
return result({ action: input.action, status: "error", code: "missing_migration_input" }, "Credential migration requires a profile and at least one source.");
|
|
191
|
+
}
|
|
192
|
+
await manager.prepareForMigration(ctx.cwd, { profile, replaceExisting: input.overwrite === true }, signal);
|
|
193
|
+
let variables = await resolveSources(sources, ctx.cwd, signal);
|
|
194
|
+
try {
|
|
195
|
+
const migrated = await manager.storeVariablesForProject(ctx.cwd, {
|
|
196
|
+
profile,
|
|
197
|
+
...(input.description ? { description: input.description } : {}),
|
|
198
|
+
variables,
|
|
199
|
+
replaceExisting: input.overwrite === true,
|
|
200
|
+
}, signal);
|
|
201
|
+
return result({
|
|
202
|
+
action: input.action,
|
|
203
|
+
status: "migrated",
|
|
204
|
+
profile: migrated.profile,
|
|
205
|
+
variableNames: migrated.variableNames,
|
|
206
|
+
project: migrated.project,
|
|
207
|
+
sourceRetained: true,
|
|
208
|
+
}, `Migrated and activated ${migrated.profile} for ${migrated.project}. Source material was retained.`);
|
|
209
|
+
}
|
|
210
|
+
finally {
|
|
211
|
+
for (const variable of variables)
|
|
212
|
+
variable.value = "";
|
|
213
|
+
variables = [];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const activated = await manager.activateForProject(ctx.cwd, input.profile, signal);
|
|
217
|
+
return result({
|
|
218
|
+
action: input.action,
|
|
219
|
+
status: "activated",
|
|
220
|
+
profile: activated.profile,
|
|
221
|
+
variableNames: activated.variableNames,
|
|
222
|
+
project: activated.project,
|
|
223
|
+
}, `Activated ${activated.profile} for ${activated.project}. Credential values remain hidden.`);
|
|
224
|
+
};
|
|
225
|
+
const connectWithOwnerKey = async () => {
|
|
226
|
+
if (!ctx.hasUI)
|
|
227
|
+
return ownerSetupRequired(input.action);
|
|
228
|
+
const connection = await connectCredentialSessionWithMaskedPrompt(manager, ctx.ui, signal);
|
|
229
|
+
return connection === "connected" ? undefined : cancelled(input.action);
|
|
230
|
+
};
|
|
231
|
+
if (!manager.status.sessionAvailable) {
|
|
232
|
+
const setup = await connectWithOwnerKey();
|
|
233
|
+
if (setup)
|
|
234
|
+
return setup;
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
return await executeCredentialAction();
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
if (!isCredentialSessionKeyRequired(error))
|
|
241
|
+
throw error;
|
|
242
|
+
const setup = await connectWithOwnerKey();
|
|
243
|
+
if (setup)
|
|
244
|
+
return setup;
|
|
245
|
+
return await executeCredentialAction();
|
|
131
246
|
}
|
|
132
|
-
const activated = await manager.activateForProject(ctx.cwd, input.profile, signal);
|
|
133
|
-
return result({
|
|
134
|
-
action: input.action,
|
|
135
|
-
status: "activated",
|
|
136
|
-
profile: activated.profile,
|
|
137
|
-
variableNames: activated.variableNames,
|
|
138
|
-
project: activated.project,
|
|
139
|
-
}, `Activated ${activated.profile} for ${activated.project}. Credential values remain hidden.`);
|
|
140
247
|
}
|
|
141
248
|
catch (error) {
|
|
142
249
|
return failed(input, error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret-store.js","sourceRoot":"","sources":["../../../src/core/tools/secret-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAEN,sBAAsB,EAEtB,sBAAsB,GACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,sBAAsB,EACtB,2BAA2B,GAE3B,MAAM,0BAA0B,CAAC;AAElC,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,C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AAW;oBACnB,OAAO,EAAE,SAAS,CAAC,OAAO;oBAC1B,aAAa,EAAE,SAAS,CAAC,aAAa;oBACtC,OAAO,EAAE,SAAS,CAAC,OAAO;iBAC1B,EACD,aAAa,SAAS,CAAC,OAAO,QAAQ,SAAS,CAAC,OAAO,oCAAoC,CAC3F,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { defineTool } from \"../extensions/types.ts\";\nimport {\n\ttype CredentialManager,\n\tCredentialManagerError,\n\ttype CredentialProfileSummary,\n\tCredentialStorageError,\n} from \"../secrets/credential-manager.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n} from \"./orchestration-panel.ts\";\n\nconst secretStoreSchema = Type.Object(\n\t{\n\t\taction: Type.Union([Type.Literal(\"status\"), Type.Literal(\"list\"), Type.Literal(\"activate\")], {\n\t\t\tdescription: \"Credential-use action. Credential mutation is owner-only through /secrets.\",\n\t\t}),\n\t\tprofile: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: 96,\n\t\t\t\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._-]*$\",\n\t\t\t\tdescription: \"Bound profile to activate. Omit when the project has exactly one bound profile.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type SecretStoreToolInput = Static<typeof secretStoreSchema>;\n\nexport type SecretStoreStatus = \"activated\" | \"available\" | \"cancelled\" | \"error\" | \"listed\" | \"unavailable\";\n\nexport interface SecretStoreToolDetails {\n\taction: SecretStoreToolInput[\"action\"];\n\tstatus: SecretStoreStatus;\n\tprofile?: string;\n\tvariableNames?: string[];\n\tprofiles?: CredentialProfileSummary[];\n\tproject?: string;\n\tconnected?: boolean;\n\tcode?: string;\n\tmessage?: string;\n}\n\nexport interface SecretStoreToolOptions {\n\tmanager: CredentialManager;\n}\n\ntype SecretStoreResult = {\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: SecretStoreToolDetails;\n};\n\nfunction result(details: SecretStoreToolDetails, text: string): SecretStoreResult {\n\treturn { content: [{ type: \"text\", text }], details };\n}\n\nfunction invalid(input: SecretStoreToolInput): SecretStoreResult | undefined {\n\tif (input.action !== \"activate\" && input.profile !== undefined) {\n\t\treturn result(\n\t\t\t{\n\t\t\t\taction: input.action,\n\t\t\t\tstatus: \"error\",\n\t\t\t\tcode: \"unexpected_profile\",\n\t\t\t\tmessage: `Action ${input.action} does not accept a profile.`,\n\t\t\t},\n\t\t\t`Secret store request is invalid: action ${input.action} does not accept a profile.`,\n\t\t);\n\t}\n\treturn undefined;\n}\n\nfunction failed(input: SecretStoreToolInput, error: unknown): SecretStoreResult {\n\tconst known = error instanceof CredentialManagerError || error instanceof CredentialStorageError;\n\tconst code = known ? error.code : \"safe_failure\";\n\tconst message = known ? error.message : \"Credential activation failed safely without exposing values.\";\n\tconst status: SecretStoreStatus = [\"owner_setup_required\", \"not_connected\", \"provider_unavailable\"].includes(code)\n\t\t? \"unavailable\"\n\t\t: \"error\";\n\treturn result(\n\t\t{\n\t\t\taction: input.action,\n\t\t\tstatus,\n\t\t\t...(input.profile ? { profile: input.profile } : {}),\n\t\t\tcode,\n\t\t\tmessage,\n\t\t},\n\t\t`Credential action failed: ${message}`,\n\t);\n}\n\nfunction panelModel(details: SecretStoreToolDetails | undefined, expanded: boolean): OrchestrationPanelModel {\n\tif (!details) return { label: \"secrets\", status: \"error\", emptyText: \"No credential result was retained.\" };\n\tconst success = [\"activated\", \"available\", \"listed\"].includes(details.status);\n\treturn {\n\t\tlabel: \"secrets\",\n\t\taction: details.status,\n\t\tstatus: success ? \"success\" : details.status === \"cancelled\" ? \"warning\" : \"error\",\n\t\tsummary: [\n\t\t\tdetails.profile,\n\t\t\tdetails.project,\n\t\t\tdetails.variableNames\n\t\t\t\t? `${details.variableNames.length} variable${details.variableNames.length === 1 ? \"\" : \"s\"}`\n\t\t\t\t: undefined,\n\t\t\tdetails.profiles ? `${details.profiles.length} profile${details.profiles.length === 1 ? \"\" : \"s\"}` : undefined,\n\t\t].filter((value): value is string => value !== undefined),\n\t\trows: expanded\n\t\t\t? details.profiles?.map((profile) => ({\n\t\t\t\t\tstatus: profile.boundToCurrentProject ? (\"succeeded\" as const) : (\"info\" as const),\n\t\t\t\t\tlabel: profile.profile,\n\t\t\t\t\tmeta: [\n\t\t\t\t\t\t`${profile.variableNames.length} variable${profile.variableNames.length === 1 ? \"\" : \"s\"}`,\n\t\t\t\t\t\tprofile.boundToCurrentProject ? \"bound here\" : \"not bound here\",\n\t\t\t\t\t],\n\t\t\t\t\tdetails: profile.description ? [profile.description] : undefined,\n\t\t\t\t}))\n\t\t\t: undefined,\n\t\tnotices:\n\t\t\texpanded && details.message ? [{ status: success ? \"info\" : \"error\", text: details.message }] : undefined,\n\t};\n}\n\nexport function createSecretStoreToolDefinition(options: SecretStoreToolOptions) {\n\tconst { manager } = options;\n\treturn defineTool<typeof secretStoreSchema, SecretStoreToolDetails>({\n\t\tname: \"secret_store\",\n\t\tlabel: \"Secret Store\",\n\t\tdescription:\n\t\t\t\"Discover and activate owner-authorized Bitwarden credential profiles for the current project without exposing values.\",\n\t\tpromptSnippet:\n\t\t\t\"Activate project credentials with secret_store before credential-dependent commands. Credential setup and mutation are owner-only through /secrets.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Use secret_store activate before credential-dependent work. It works in TUI, print, and RPC modes and returns metadata only.\",\n\t\t\t\"Omit profile when the project has one binding. Use list to select among multiple authorized profiles.\",\n\t\t\t\"Never ask the owner to paste a credential into chat or pass a value through tool arguments.\",\n\t\t\t\"After activation, run the consuming command normally. Never print, inspect, grep, or echo credential environment values.\",\n\t\t\t\"If owner_setup_required is returned, tell the owner to run /secrets in a TUI session. Do not repeatedly retry.\",\n\t\t],\n\t\tparameters: secretStoreSchema,\n\t\texecutionMode: \"sequential\",\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(toolResult, { expanded, isPartial }, theme: Theme) {\n\t\t\tif (isPartial) {\n\t\t\t\treturn new OrchestrationPanelComponent(theme, {\n\t\t\t\t\tlabel: \"secrets\",\n\t\t\t\t\taction: \"activating\",\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, panelModel(toolResult.details, expanded), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input, signal, _onUpdate, ctx) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\treturn result(\n\t\t\t\t\t{ action: input.action, status: \"cancelled\", code: \"cancelled\" },\n\t\t\t\t\t\"Credential action cancelled.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst validation = invalid(input);\n\t\t\tif (validation) return validation;\n\t\t\ttry {\n\t\t\t\tif (input.action === \"status\") {\n\t\t\t\t\tconst status = manager.status;\n\t\t\t\t\tif (!status.sessionAvailable) {\n\t\t\t\t\t\treturn result(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\t\t\tstatus: \"unavailable\",\n\t\t\t\t\t\t\t\tconnected: false,\n\t\t\t\t\t\t\t\tcode: \"owner_setup_required\",\n\t\t\t\t\t\t\t\tmessage: \"The owner must connect Bitwarden with /secrets.\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"Bitwarden owner setup is required. Run /secrets in a TUI session.\",\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn result(\n\t\t\t\t\t\t{ action: input.action, status: \"available\", connected: status.connected },\n\t\t\t\t\t\tstatus.connected\n\t\t\t\t\t\t\t? \"Bitwarden is connected for this Pi session.\"\n\t\t\t\t\t\t\t: \"A Bitwarden session key is available and will be validated on activation.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (input.action === \"list\") {\n\t\t\t\t\tconst profiles = await manager.listForProject(ctx.cwd, signal);\n\t\t\t\t\treturn result(\n\t\t\t\t\t\t{ action: input.action, status: \"listed\", profiles },\n\t\t\t\t\t\t`Found ${profiles.length} credential profile${profiles.length === 1 ? \"\" : \"s\"}; only metadata was returned.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst activated = await manager.activateForProject(ctx.cwd, input.profile, signal);\n\t\t\t\treturn result(\n\t\t\t\t\t{\n\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\tstatus: \"activated\",\n\t\t\t\t\t\tprofile: activated.profile,\n\t\t\t\t\t\tvariableNames: activated.variableNames,\n\t\t\t\t\t\tproject: activated.project,\n\t\t\t\t\t},\n\t\t\t\t\t`Activated ${activated.profile} for ${activated.project}. Credential values remain hidden.`,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\treturn failed(input, error);\n\t\t\t}\n\t\t},\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"secret-store.js","sourceRoot":"","sources":["../../../src/core/tools/secret-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAEN,sBAAsB,EAEtB,sBAAsB,GACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,8BAA8B,EAE9B,iCAAiC,GACjC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACN,wCAAwC,EACxC,8BAA8B,GAC9B,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AAC3G,OAAO,EACN,sBAAsB,EACtB,2BAA2B,GAE3B,MAAM,0BAA0B,CA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AAE,CAAC;gBACxC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,IAAI,CAAC,8BAA8B,CAAC,KAAK,CAAC;wBAAE,MAAM,KAAK,CAAC;oBACxD,MAAM,KAAK,GAAG,MAAM,mBAAmB,EAAE,CAAC;oBAC1C,IAAI,KAAK;wBAAE,OAAO,KAAK,CAAC;oBACxB,OAAO,MAAM,uBAAuB,EAAE,CAAC;gBACxC,CAAC;YACF,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { defineTool } from \"../extensions/types.ts\";\nimport {\n\ttype CredentialManager,\n\tCredentialManagerError,\n\ttype CredentialProfileSummary,\n\tCredentialStorageError,\n} from \"../secrets/credential-manager.ts\";\nimport {\n\tCredentialMigrationSourceError,\n\ttype CredentialMigrationSourceResolver,\n\tresolveCredentialMigrationSources,\n} from \"../secrets/credential-migration-source.ts\";\nimport {\n\tconnectCredentialSessionWithMaskedPrompt,\n\tisCredentialSessionKeyRequired,\n} from \"../secrets/credential-session-connection.ts\";\nimport { SECRET_VARIABLE_NAME_MAX_CHARS, SECRET_VARIABLE_NAME_PATTERN } from \"../secrets/secret-dotenv.ts\";\nimport {\n\temptyOrchestrationCall,\n\tOrchestrationPanelComponent,\n\ttype OrchestrationPanelModel,\n} from \"./orchestration-panel.ts\";\n\nconst migrationSourceSchema = Type.Union([\n\tType.Object(\n\t\t{\n\t\t\tkind: Type.Literal(\"environment\"),\n\t\t\tname: Type.String({ maxLength: SECRET_VARIABLE_NAME_MAX_CHARS, pattern: SECRET_VARIABLE_NAME_PATTERN }),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n\tType.Object(\n\t\t{ kind: Type.Literal(\"dotenv_file\"), path: Type.String({ minLength: 1, maxLength: 4096 }) },\n\t\t{ additionalProperties: false },\n\t),\n\tType.Object(\n\t\t{\n\t\t\tkind: Type.Literal(\"file\"),\n\t\t\tpath: Type.String({ minLength: 1, maxLength: 4096 }),\n\t\t\tvariable: Type.String({ maxLength: SECRET_VARIABLE_NAME_MAX_CHARS, pattern: SECRET_VARIABLE_NAME_PATTERN }),\n\t\t},\n\t\t{ additionalProperties: false },\n\t),\n]);\n\nconst secretStoreSchema = Type.Object(\n\t{\n\t\taction: Type.Union(\n\t\t\t[Type.Literal(\"status\"), Type.Literal(\"list\"), Type.Literal(\"activate\"), Type.Literal(\"migrate\")],\n\t\t\t{\n\t\t\t\tdescription: \"Inspect, activate, or migrate model-blind credential sources.\",\n\t\t\t},\n\t\t),\n\t\tprofile: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: 96,\n\t\t\t\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._-]*$\",\n\t\t\t\tdescription: \"Profile to activate or create during migration.\",\n\t\t\t}),\n\t\t),\n\t\tdescription: Type.Optional(Type.String({ minLength: 1, maxLength: 256 })),\n\t\toverwrite: Type.Optional(\n\t\t\tType.Boolean({ description: \"Explicitly replace an existing profile while preserving project bindings.\" }),\n\t\t),\n\t\tsources: Type.Optional(\n\t\t\tType.Array(migrationSourceSchema, {\n\t\t\t\tminItems: 1,\n\t\t\t\tmaxItems: 64,\n\t\t\t\tdescription: \"Host-side credential sources. Values are never accepted in tool arguments.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\nexport type SecretStoreToolInput = Static<typeof secretStoreSchema>;\n\nexport type SecretStoreStatus =\n\t| \"activated\"\n\t| \"available\"\n\t| \"cancelled\"\n\t| \"error\"\n\t| \"listed\"\n\t| \"migrated\"\n\t| \"unavailable\";\n\nexport interface SecretStoreToolDetails {\n\taction: SecretStoreToolInput[\"action\"];\n\tstatus: SecretStoreStatus;\n\tprofile?: string;\n\tvariableNames?: string[];\n\tprofiles?: CredentialProfileSummary[];\n\tproject?: string;\n\tconnected?: boolean;\n\tcode?: string;\n\tmessage?: string;\n\tsourceRetained?: boolean;\n}\n\nexport interface SecretStoreToolOptions {\n\tmanager: CredentialManager;\n\tresolveMigrationSources?: CredentialMigrationSourceResolver;\n}\n\ntype SecretStoreResult = {\n\tcontent: Array<{ type: \"text\"; text: string }>;\n\tdetails: SecretStoreToolDetails;\n};\n\nfunction result(details: SecretStoreToolDetails, text: string): SecretStoreResult {\n\treturn { content: [{ type: \"text\", text }], details };\n}\n\nfunction ownerSetupRequired(action: SecretStoreToolInput[\"action\"]): SecretStoreResult {\n\tconst message =\n\t\t\"Bitwarden needs one owner input: a BW_SESSION key supplied through Pi's masked prompt or process environment, never through chat.\";\n\treturn result(\n\t\t{\n\t\t\taction,\n\t\t\tstatus: \"unavailable\",\n\t\t\t...(action === \"status\" ? { connected: false } : {}),\n\t\t\tcode: \"owner_setup_required\",\n\t\t\tmessage,\n\t\t},\n\t\tmessage,\n\t);\n}\n\nfunction cancelled(action: SecretStoreToolInput[\"action\"]): SecretStoreResult {\n\treturn result({ action, status: \"cancelled\", code: \"cancelled\" }, \"Credential action cancelled.\");\n}\n\nfunction invalid(input: SecretStoreToolInput): SecretStoreResult | undefined {\n\tif (input.action === \"migrate\") {\n\t\tif (!input.profile || !input.sources) {\n\t\t\treturn result(\n\t\t\t\t{ action: input.action, status: \"error\", code: \"missing_migration_input\" },\n\t\t\t\t\"Credential migration requires a profile and at least one source.\",\n\t\t\t);\n\t\t}\n\t\treturn undefined;\n\t}\n\tif (input.description !== undefined || input.sources !== undefined || input.overwrite !== undefined) {\n\t\treturn result(\n\t\t\t{ action: input.action, status: \"error\", code: \"unexpected_migration_input\" },\n\t\t\t`Action ${input.action} does not accept migration inputs.`,\n\t\t);\n\t}\n\tif (input.action !== \"activate\" && input.profile !== undefined) {\n\t\treturn result(\n\t\t\t{\n\t\t\t\taction: input.action,\n\t\t\t\tstatus: \"error\",\n\t\t\t\tcode: \"unexpected_profile\",\n\t\t\t\tmessage: `Action ${input.action} does not accept a profile.`,\n\t\t\t},\n\t\t\t`Secret store request is invalid: action ${input.action} does not accept a profile.`,\n\t\t);\n\t}\n\treturn undefined;\n}\n\nfunction failed(input: SecretStoreToolInput, error: unknown): SecretStoreResult {\n\tconst known =\n\t\terror instanceof CredentialManagerError ||\n\t\terror instanceof CredentialStorageError ||\n\t\terror instanceof CredentialMigrationSourceError;\n\tconst code = known ? error.code : \"safe_failure\";\n\tconst migrationMessages: Record<string, string> = {\n\t\tduplicate_variable: \"Credential migration defines the same variable more than once.\",\n\t\tinvalid_source: \"Credential migration source data is invalid.\",\n\t\tsource_not_found: \"A requested credential source is unavailable.\",\n\t\tsource_unavailable: \"A requested credential source could not be read.\",\n\t};\n\tconst message =\n\t\terror instanceof CredentialMigrationSourceError\n\t\t\t? (migrationMessages[error.code] ?? \"Credential migration failed safely without exposing values.\")\n\t\t\t: known\n\t\t\t\t? error.message\n\t\t\t\t: \"Credential action failed safely without exposing values.\";\n\tconst status: SecretStoreStatus = [\"owner_setup_required\", \"not_connected\", \"provider_unavailable\"].includes(code)\n\t\t? \"unavailable\"\n\t\t: \"error\";\n\treturn result(\n\t\t{\n\t\t\taction: input.action,\n\t\t\tstatus,\n\t\t\t...(input.profile ? { profile: input.profile } : {}),\n\t\t\tcode,\n\t\t\tmessage,\n\t\t},\n\t\t`Credential action failed: ${message}`,\n\t);\n}\n\nfunction panelModel(details: SecretStoreToolDetails | undefined, expanded: boolean): OrchestrationPanelModel {\n\tif (!details) return { label: \"secrets\", status: \"error\", emptyText: \"No credential result was retained.\" };\n\tconst success = [\"activated\", \"available\", \"listed\", \"migrated\"].includes(details.status);\n\treturn {\n\t\tlabel: \"secrets\",\n\t\taction: details.status,\n\t\tstatus: success ? \"success\" : details.status === \"cancelled\" ? \"warning\" : \"error\",\n\t\tsummary: [\n\t\t\tdetails.profile,\n\t\t\tdetails.project,\n\t\t\tdetails.variableNames\n\t\t\t\t? `${details.variableNames.length} variable${details.variableNames.length === 1 ? \"\" : \"s\"}`\n\t\t\t\t: undefined,\n\t\t\tdetails.profiles ? `${details.profiles.length} profile${details.profiles.length === 1 ? \"\" : \"s\"}` : undefined,\n\t\t].filter((value): value is string => value !== undefined),\n\t\trows: expanded\n\t\t\t? details.profiles?.map((profile) => ({\n\t\t\t\t\tstatus: profile.boundToCurrentProject ? (\"succeeded\" as const) : (\"info\" as const),\n\t\t\t\t\tlabel: profile.profile,\n\t\t\t\t\tmeta: [\n\t\t\t\t\t\t`${profile.variableNames.length} variable${profile.variableNames.length === 1 ? \"\" : \"s\"}`,\n\t\t\t\t\t\tprofile.boundToCurrentProject ? \"bound here\" : \"not bound here\",\n\t\t\t\t\t],\n\t\t\t\t\tdetails: profile.description ? [profile.description] : undefined,\n\t\t\t\t}))\n\t\t\t: undefined,\n\t\tnotices:\n\t\t\texpanded && details.message ? [{ status: success ? \"info\" : \"error\", text: details.message }] : undefined,\n\t};\n}\n\nexport function createSecretStoreToolDefinition(options: SecretStoreToolOptions) {\n\tconst { manager } = options;\n\tconst resolveSources = options.resolveMigrationSources ?? resolveCredentialMigrationSources;\n\treturn defineTool<typeof secretStoreSchema, SecretStoreToolDetails>({\n\t\tname: \"secret_store\",\n\t\tlabel: \"Secret Store\",\n\t\tdescription:\n\t\t\t\"Discover, migrate, and activate Bitwarden credential profiles for the current project without exposing values.\",\n\t\tpromptSnippet:\n\t\t\t\"Migrate accessible credentials into Bitwarden, activate project credentials; never expose values.\",\n\t\tpromptGuidelines: [\n\t\t\t\"Active user-plane host gate authorizes model-blind migration; never ask duplicate confirmation.\",\n\t\t\t\"Credentials needed: call secret_store. If disconnected, TUI asks for one masked BW_SESSION only; never request chat/setup work.\",\n\t\t\t\"activate before credential work; TUI/print/RPC return metadata only.\",\n\t\t\t\"One project binding: omit profile. Multiple: use list, select authorized profile.\",\n\t\t\t\"Never request credentials in chat/tool arguments.\",\n\t\t\t\"After activation, run consumer normally; never print/inspect/grep/echo credential environment values.\",\n\t\t\t\"migrate accepts environment names, dotenv paths, key-file paths; never credential values.\",\n\t\t\t\"Migration keeps sources. overwrite only for intentional Bitwarden profile replacement.\",\n\t\t\t\"owner_setup_required without UI: report only BW_SESSION missing, supplied out of band to Pi; never request more/retry.\",\n\t\t],\n\t\tparameters: secretStoreSchema,\n\t\texecutionMode: \"sequential\",\n\t\trenderShell: \"self\",\n\t\trenderCall() {\n\t\t\treturn emptyOrchestrationCall();\n\t\t},\n\t\trenderResult(toolResult, { expanded, isPartial }, theme: Theme) {\n\t\t\tif (isPartial) {\n\t\t\t\treturn new OrchestrationPanelComponent(theme, {\n\t\t\t\t\tlabel: \"secrets\",\n\t\t\t\t\taction: \"activating\",\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn new OrchestrationPanelComponent(theme, panelModel(toolResult.details, expanded), expanded);\n\t\t},\n\t\tasync execute(_toolCallId, input, signal, _onUpdate, ctx) {\n\t\t\tif (signal?.aborted) {\n\t\t\t\treturn cancelled(input.action);\n\t\t\t}\n\t\t\tconst validation = invalid(input);\n\t\t\tif (validation) return validation;\n\t\t\ttry {\n\t\t\t\tif (input.action === \"status\") {\n\t\t\t\t\tconst status = manager.status;\n\t\t\t\t\tif (!status.sessionAvailable) return ownerSetupRequired(input.action);\n\t\t\t\t\treturn result(\n\t\t\t\t\t\t{ action: input.action, status: \"available\", connected: status.connected },\n\t\t\t\t\t\tstatus.connected\n\t\t\t\t\t\t\t? \"Bitwarden is connected for this Pi session.\"\n\t\t\t\t\t\t\t: \"A Bitwarden session key is available and will be validated on activation.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst executeCredentialAction = async (): Promise<SecretStoreResult> => {\n\t\t\t\t\tif (input.action === \"list\") {\n\t\t\t\t\t\tconst profiles = await manager.listForProject(ctx.cwd, signal);\n\t\t\t\t\t\treturn result(\n\t\t\t\t\t\t\t{ action: input.action, status: \"listed\", profiles },\n\t\t\t\t\t\t\t`Found ${profiles.length} credential profile${profiles.length === 1 ? \"\" : \"s\"}; only metadata was returned.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (input.action === \"migrate\") {\n\t\t\t\t\t\tconst { profile, sources } = input;\n\t\t\t\t\t\tif (!profile || !sources) {\n\t\t\t\t\t\t\treturn result(\n\t\t\t\t\t\t\t\t{ action: input.action, status: \"error\", code: \"missing_migration_input\" },\n\t\t\t\t\t\t\t\t\"Credential migration requires a profile and at least one source.\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait manager.prepareForMigration(\n\t\t\t\t\t\t\tctx.cwd,\n\t\t\t\t\t\t\t{ profile, replaceExisting: input.overwrite === true },\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tlet variables = await resolveSources(sources, ctx.cwd, signal);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst migrated = await manager.storeVariablesForProject(\n\t\t\t\t\t\t\t\tctx.cwd,\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tprofile,\n\t\t\t\t\t\t\t\t\t...(input.description ? { description: input.description } : {}),\n\t\t\t\t\t\t\t\t\tvariables,\n\t\t\t\t\t\t\t\t\treplaceExisting: input.overwrite === true,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn result(\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\t\t\t\tstatus: \"migrated\",\n\t\t\t\t\t\t\t\t\tprofile: migrated.profile,\n\t\t\t\t\t\t\t\t\tvariableNames: migrated.variableNames,\n\t\t\t\t\t\t\t\t\tproject: migrated.project,\n\t\t\t\t\t\t\t\t\tsourceRetained: true,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t`Migrated and activated ${migrated.profile} for ${migrated.project}. Source material was retained.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tfor (const variable of variables) variable.value = \"\";\n\t\t\t\t\t\t\tvariables = [];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst activated = await manager.activateForProject(ctx.cwd, input.profile, signal);\n\t\t\t\t\treturn result(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taction: input.action,\n\t\t\t\t\t\t\tstatus: \"activated\",\n\t\t\t\t\t\t\tprofile: activated.profile,\n\t\t\t\t\t\t\tvariableNames: activated.variableNames,\n\t\t\t\t\t\t\tproject: activated.project,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t`Activated ${activated.profile} for ${activated.project}. Credential values remain hidden.`,\n\t\t\t\t\t);\n\t\t\t\t};\n\n\t\t\t\tconst connectWithOwnerKey = async (): Promise<SecretStoreResult | undefined> => {\n\t\t\t\t\tif (!ctx.hasUI) return ownerSetupRequired(input.action);\n\t\t\t\t\tconst connection = await connectCredentialSessionWithMaskedPrompt(manager, ctx.ui, signal);\n\t\t\t\t\treturn connection === \"connected\" ? undefined : cancelled(input.action);\n\t\t\t\t};\n\n\t\t\t\tif (!manager.status.sessionAvailable) {\n\t\t\t\t\tconst setup = await connectWithOwnerKey();\n\t\t\t\t\tif (setup) return setup;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\treturn await executeCredentialAction();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isCredentialSessionKeyRequired(error)) throw error;\n\t\t\t\t\tconst setup = await connectWithOwnerKey();\n\t\t\t\t\tif (setup) return setup;\n\t\t\t\t\treturn await executeCredentialAction();\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\treturn failed(input, error);\n\t\t\t}\n\t\t},\n\t});\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Static, Type } from "typebox";
|
|
2
|
+
import type { ToolDefinition } from "../extensions/types.ts";
|
|
3
|
+
import type { SkillLoadResult, SkillSearchResult, SkillVaultController, SkillVaultStatus } from "../skill-vault.ts";
|
|
4
|
+
declare const skillSchema: Type.TObject<{
|
|
5
|
+
action: Type.TUnion<[Type.TLiteral<"search">, Type.TLiteral<"load">, Type.TLiteral<"unload">, Type.TLiteral<"status">]>;
|
|
6
|
+
query: Type.TOptional<Type.TString>;
|
|
7
|
+
name: Type.TOptional<Type.TString>;
|
|
8
|
+
}>;
|
|
9
|
+
export type SkillToolInput = Static<typeof skillSchema>;
|
|
10
|
+
export type SkillToolDetails = {
|
|
11
|
+
action: "search";
|
|
12
|
+
result: SkillSearchResult;
|
|
13
|
+
} | {
|
|
14
|
+
action: "load";
|
|
15
|
+
result: SkillLoadResult;
|
|
16
|
+
} | {
|
|
17
|
+
action: "unload";
|
|
18
|
+
result: {
|
|
19
|
+
ok: true;
|
|
20
|
+
unloaded?: string;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
action: "status";
|
|
24
|
+
result: SkillVaultStatus;
|
|
25
|
+
};
|
|
26
|
+
/** One compact agent surface over the host-owned skill lifecycle. */
|
|
27
|
+
export declare function createSkillVaultToolDefinition(vault: SkillVaultController): ToolDefinition<typeof skillSchema>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=skill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../../src/core/tools/skill.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEpH,QAAA,MAAM,WAAW;;;;EAUhB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAC;AACxD,MAAM,MAAM,gBAAgB,GACzB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAA;CAAE,GAC/C;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GAC3C;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAC7D;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAalD,qEAAqE;AACrE,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,oBAAoB,GAAG,cAAc,CAAC,OAAO,WAAW,CAAC,CA2D9G"}
|