@namzu/sdk 35.0.0 → 37.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +218 -0
- package/README.md +68 -41
- package/dist/bridge/a2a/mapper.d.ts.map +1 -1
- package/dist/bridge/a2a/mapper.js +2 -0
- package/dist/bridge/a2a/mapper.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +2 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/compaction/extractor.d.ts +1 -1
- package/dist/compaction/extractor.d.ts.map +1 -1
- package/dist/compaction/extractor.js +15 -7
- package/dist/compaction/extractor.js.map +1 -1
- package/dist/compaction/manager.d.ts +2 -0
- package/dist/compaction/manager.d.ts.map +1 -1
- package/dist/compaction/manager.js +12 -1
- package/dist/compaction/manager.js.map +1 -1
- package/dist/compaction/verifier.d.ts.map +1 -1
- package/dist/compaction/verifier.js +82 -15
- package/dist/compaction/verifier.js.map +1 -1
- package/dist/contracts/schemas.d.ts +10 -10
- package/dist/eval/harness-verification.d.ts +63 -0
- package/dist/eval/harness-verification.d.ts.map +1 -0
- package/dist/eval/harness-verification.js +165 -0
- package/dist/eval/harness-verification.js.map +1 -0
- package/dist/eval/index.d.ts +2 -0
- package/dist/eval/index.d.ts.map +1 -1
- package/dist/eval/index.js +1 -0
- package/dist/eval/index.js.map +1 -1
- package/dist/execution/code-runtime/json-value.d.ts +10 -0
- package/dist/execution/code-runtime/json-value.d.ts.map +1 -0
- package/dist/execution/code-runtime/json-value.js +89 -0
- package/dist/execution/code-runtime/json-value.js.map +1 -0
- package/dist/execution/code-runtime/worker-program.d.ts +8 -0
- package/dist/execution/code-runtime/worker-program.d.ts.map +1 -0
- package/dist/execution/code-runtime/worker-program.js +240 -0
- package/dist/execution/code-runtime/worker-program.js.map +1 -0
- package/dist/execution/code-runtime/worker.d.ts +22 -0
- package/dist/execution/code-runtime/worker.d.ts.map +1 -1
- package/dist/execution/code-runtime/worker.js +148 -111
- package/dist/execution/code-runtime/worker.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts +12 -0
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +306 -37
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/run/persistence.d.ts +2 -0
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +6 -0
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/provider/capabilities.d.ts +3 -1
- package/dist/provider/capabilities.d.ts.map +1 -1
- package/dist/provider/capabilities.js +13 -0
- package/dist/provider/capabilities.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +2 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/token-budget.d.ts.map +1 -1
- package/dist/provider/token-budget.js +56 -8
- package/dist/provider/token-budget.js.map +1 -1
- package/dist/public-runtime.d.ts +5 -3
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +3 -2
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-tools.d.ts +1 -1
- package/dist/public-tools.d.ts.map +1 -1
- package/dist/public-tools.js +1 -1
- package/dist/public-tools.js.map +1 -1
- package/dist/public-types.d.ts +1 -0
- package/dist/public-types.d.ts.map +1 -1
- package/dist/registry/tool/execute.d.ts +3 -0
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +11 -80
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/run/command-gate.d.ts.map +1 -1
- package/dist/run/command-gate.js +65 -12
- package/dist/run/command-gate.js.map +1 -1
- package/dist/run/index.d.ts +2 -0
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +1 -0
- package/dist/run/index.js.map +1 -1
- package/dist/run/memory-promoter.d.ts +3 -35
- package/dist/run/memory-promoter.d.ts.map +1 -1
- package/dist/run/memory-promoter.js +32 -40
- package/dist/run/memory-promoter.js.map +1 -1
- package/dist/run/memory-recall.d.ts +25 -0
- package/dist/run/memory-recall.d.ts.map +1 -0
- package/dist/run/memory-recall.js +228 -0
- package/dist/run/memory-recall.js.map +1 -0
- package/dist/run/reporter.d.ts.map +1 -1
- package/dist/run/reporter.js +1 -0
- package/dist/run/reporter.js.map +1 -1
- package/dist/run/token-budget.d.ts +2 -0
- package/dist/run/token-budget.d.ts.map +1 -1
- package/dist/run/token-budget.js +4 -0
- package/dist/run/token-budget.js.map +1 -1
- package/dist/run/workspace-fingerprint.d.ts +10 -3
- package/dist/run/workspace-fingerprint.d.ts.map +1 -1
- package/dist/run/workspace-fingerprint.js +17 -8
- package/dist/run/workspace-fingerprint.js.map +1 -1
- package/dist/runtime/query/checkpoint.d.ts +14 -0
- package/dist/runtime/query/checkpoint.d.ts.map +1 -1
- package/dist/runtime/query/checkpoint.js +82 -1
- package/dist/runtime/query/checkpoint.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +6 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +120 -24
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +12 -8
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +55 -7
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +13 -3
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +356 -42
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/native-output.d.ts +10 -0
- package/dist/runtime/query/iteration/native-output.d.ts.map +1 -0
- package/dist/runtime/query/iteration/native-output.js +32 -0
- package/dist/runtime/query/iteration/native-output.js.map +1 -0
- package/dist/runtime/query/iteration/phases/advisory.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.js +18 -13
- package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts +2 -0
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +32 -11
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +11 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/iteration/phases/working-memory.d.ts +1 -1
- package/dist/runtime/query/iteration/phases/working-memory.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/working-memory.js +23 -6
- package/dist/runtime/query/iteration/phases/working-memory.js.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.d.ts.map +1 -1
- package/dist/runtime/query/iteration/stream-turn.js +12 -5
- package/dist/runtime/query/iteration/stream-turn.js.map +1 -1
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js +14 -4
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +6 -2
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +17 -2
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/runtime/query/tool-call-budget.d.ts +19 -0
- package/dist/runtime/query/tool-call-budget.d.ts.map +1 -0
- package/dist/runtime/query/tool-call-budget.js +110 -0
- package/dist/runtime/query/tool-call-budget.js.map +1 -0
- package/dist/runtime/query/tooling.d.ts +2 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +4 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/sandbox/file-walk-program.d.ts +3 -0
- package/dist/sandbox/file-walk-program.d.ts.map +1 -0
- package/dist/sandbox/file-walk-program.js +94 -0
- package/dist/sandbox/file-walk-program.js.map +1 -0
- package/dist/sandbox/file-walk.d.ts +12 -0
- package/dist/sandbox/file-walk.d.ts.map +1 -0
- package/dist/sandbox/file-walk.js +429 -0
- package/dist/sandbox/file-walk.js.map +1 -0
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +1 -0
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +9 -0
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/scheduler/completion-inbox.d.ts +3 -2
- package/dist/scheduler/completion-inbox.d.ts.map +1 -1
- package/dist/scheduler/completion-inbox.js +29 -15
- package/dist/scheduler/completion-inbox.js.map +1 -1
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +1 -0
- package/dist/scheduler/local.js.map +1 -1
- package/dist/session/handoff/capacity.d.ts +2 -2
- package/dist/session/handoff/capacity.d.ts.map +1 -1
- package/dist/session/handoff/capacity.js +3 -2
- package/dist/session/handoff/capacity.js.map +1 -1
- package/dist/store/memory/disk.d.ts +6 -2
- package/dist/store/memory/disk.d.ts.map +1 -1
- package/dist/store/memory/disk.js +42 -25
- package/dist/store/memory/disk.js.map +1 -1
- package/dist/store/memory/index.d.ts +4 -0
- package/dist/store/memory/index.d.ts.map +1 -1
- package/dist/store/memory/index.js +55 -19
- package/dist/store/memory/index.js.map +1 -1
- package/dist/store/memory/memory.d.ts +3 -2
- package/dist/store/memory/memory.d.ts.map +1 -1
- package/dist/store/memory/memory.js +11 -2
- package/dist/store/memory/memory.js.map +1 -1
- package/dist/store/memory/operation-lock.d.ts +11 -0
- package/dist/store/memory/operation-lock.d.ts.map +1 -0
- package/dist/store/memory/operation-lock.js +94 -0
- package/dist/store/memory/operation-lock.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +215 -59
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +60 -10
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/glob.d.ts +2 -1
- package/dist/tools/builtins/glob.d.ts.map +1 -1
- package/dist/tools/builtins/glob.js +95 -103
- package/dist/tools/builtins/glob.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +155 -111
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/ls.js +2 -2
- package/dist/tools/builtins/ls.js.map +1 -1
- package/dist/tools/builtins/run-code.d.ts +6 -0
- package/dist/tools/builtins/run-code.d.ts.map +1 -1
- package/dist/tools/builtins/run-code.js +15 -4
- package/dist/tools/builtins/run-code.js.map +1 -1
- package/dist/tools/builtins/search-tools.d.ts.map +1 -1
- package/dist/tools/builtins/search-tools.js +14 -2
- package/dist/tools/builtins/search-tools.js.map +1 -1
- package/dist/tools/defineTool.d.ts +2 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +3 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/memory/delete.d.ts +4 -0
- package/dist/tools/memory/delete.d.ts.map +1 -0
- package/dist/tools/memory/delete.js +26 -0
- package/dist/tools/memory/delete.js.map +1 -0
- package/dist/tools/memory/index.d.ts +2 -0
- package/dist/tools/memory/index.d.ts.map +1 -1
- package/dist/tools/memory/index.js +6 -0
- package/dist/tools/memory/index.js.map +1 -1
- package/dist/tools/memory/save.d.ts.map +1 -1
- package/dist/tools/memory/save.js +3 -2
- package/dist/tools/memory/save.js.map +1 -1
- package/dist/tools/memory/search.d.ts.map +1 -1
- package/dist/tools/memory/search.js +12 -5
- package/dist/tools/memory/search.js.map +1 -1
- package/dist/tools/memory/update.d.ts +4 -0
- package/dist/tools/memory/update.d.ts.map +1 -0
- package/dist/tools/memory/update.js +47 -0
- package/dist/tools/memory/update.js.map +1 -0
- package/dist/types/agent/scheduler.d.ts +5 -0
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +10 -0
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/computer-use/index.d.ts +6 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.js.map +1 -1
- package/dist/types/errors/catalog.js +1 -1
- package/dist/types/errors/catalog.js.map +1 -1
- package/dist/types/hitl/index.d.ts +11 -1
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/memory/index.d.ts +14 -1
- package/dist/types/memory/index.d.ts.map +1 -1
- package/dist/types/project/entity.d.ts +1 -0
- package/dist/types/project/entity.d.ts.map +1 -1
- package/dist/types/provider/config.d.ts +2 -0
- package/dist/types/provider/config.d.ts.map +1 -1
- package/dist/types/provider/model.d.ts +4 -0
- package/dist/types/provider/model.d.ts.map +1 -1
- package/dist/types/run/answer-review.d.ts +2 -0
- package/dist/types/run/answer-review.d.ts.map +1 -1
- package/dist/types/run/events.d.ts +9 -0
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/events.js.map +1 -1
- package/dist/types/run/prepare-step.d.ts +19 -1
- package/dist/types/run/prepare-step.d.ts.map +1 -1
- package/dist/types/sandbox/index.d.ts +20 -0
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/structured-output/index.d.ts +8 -2
- package/dist/types/structured-output/index.d.ts.map +1 -1
- package/dist/types/tool/index.d.ts +15 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/utils/json-snapshot.d.ts +3 -0
- package/dist/utils/json-snapshot.d.ts.map +1 -0
- package/dist/utils/json-snapshot.js +79 -0
- package/dist/utils/json-snapshot.js.map +1 -0
- package/package.json +8 -1
- package/src/bridge/a2a/mapper.ts +2 -0
- package/src/bridge/sse/mapper.ts +2 -0
- package/src/compaction/extractor.ts +21 -8
- package/src/compaction/manager.ts +11 -1
- package/src/compaction/verifier.ts +80 -18
- package/src/eval/harness-verification.ts +270 -0
- package/src/eval/index.ts +10 -0
- package/src/execution/code-runtime/json-value.ts +82 -0
- package/src/execution/code-runtime/worker-program.ts +239 -0
- package/src/execution/code-runtime/worker.ts +164 -111
- package/src/manager/agent/lifecycle.ts +340 -45
- package/src/manager/run/persistence.ts +7 -0
- package/src/provider/capabilities.ts +25 -1
- package/src/provider/fallback.ts +2 -0
- package/src/provider/token-budget.ts +52 -8
- package/src/public-runtime.ts +6 -1
- package/src/public-tools.ts +5 -1
- package/src/public-types.ts +1 -0
- package/src/registry/tool/execute.ts +17 -79
- package/src/run/command-gate.ts +61 -13
- package/src/run/index.ts +2 -0
- package/src/run/memory-promoter.ts +32 -40
- package/src/run/memory-recall.ts +254 -0
- package/src/run/reporter.ts +1 -0
- package/src/run/token-budget.ts +4 -0
- package/src/run/workspace-fingerprint.ts +17 -8
- package/src/runtime/query/checkpoint.ts +96 -2
- package/src/runtime/query/executor.ts +131 -28
- package/src/runtime/query/index.ts +81 -16
- package/src/runtime/query/iteration/index.ts +406 -53
- package/src/runtime/query/iteration/native-output.ts +35 -0
- package/src/runtime/query/iteration/phases/advisory.ts +21 -11
- package/src/runtime/query/iteration/phases/compaction.ts +36 -14
- package/src/runtime/query/iteration/phases/context.ts +11 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +5 -1
- package/src/runtime/query/iteration/phases/working-memory.ts +23 -5
- package/src/runtime/query/iteration/stream-turn.ts +11 -5
- package/src/runtime/query/prompt.ts +21 -4
- package/src/runtime/query/steering.ts +19 -2
- package/src/runtime/query/tool-call-budget.ts +115 -0
- package/src/runtime/query/tooling.ts +6 -0
- package/src/sandbox/file-walk-program.ts +93 -0
- package/src/sandbox/file-walk.ts +463 -0
- package/src/sandbox/index.ts +2 -0
- package/src/sandbox/provider/local.ts +13 -0
- package/src/scheduler/completion-inbox.ts +29 -19
- package/src/scheduler/local.ts +1 -0
- package/src/session/handoff/capacity.ts +7 -3
- package/src/store/memory/disk.ts +52 -30
- package/src/store/memory/index.ts +75 -27
- package/src/store/memory/memory.ts +18 -6
- package/src/store/memory/operation-lock.ts +99 -0
- package/src/tools/builtins/bash.ts +230 -58
- package/src/tools/builtins/computer-use.ts +61 -7
- package/src/tools/builtins/glob.ts +104 -122
- package/src/tools/builtins/grep.ts +166 -132
- package/src/tools/builtins/ls.ts +2 -2
- package/src/tools/builtins/run-code.ts +24 -5
- package/src/tools/builtins/search-tools.ts +18 -3
- package/src/tools/defineTool.ts +5 -0
- package/src/tools/memory/delete.ts +29 -0
- package/src/tools/memory/index.ts +6 -0
- package/src/tools/memory/save.ts +4 -2
- package/src/tools/memory/search.ts +12 -5
- package/src/tools/memory/update.ts +50 -0
- package/src/types/agent/scheduler.ts +6 -0
- package/src/types/agent/task.ts +13 -0
- package/src/types/computer-use/index.ts +6 -0
- package/src/types/errors/catalog.ts +1 -1
- package/src/types/hitl/index.ts +11 -1
- package/src/types/memory/index.ts +16 -1
- package/src/types/project/entity.ts +1 -0
- package/src/types/provider/config.ts +2 -0
- package/src/types/provider/model.ts +4 -0
- package/src/types/run/answer-review.ts +2 -0
- package/src/types/run/events.ts +10 -0
- package/src/types/run/prepare-step.ts +19 -1
- package/src/types/sandbox/index.ts +21 -0
- package/src/types/structured-output/index.ts +15 -2
- package/src/types/tool/index.ts +16 -0
- package/src/utils/json-snapshot.ts +76 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/store/memory/index.ts"],"names":[],"mappings":"AAQA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/store/memory/index.ts"],"names":[],"mappings":"AAQA,SAAS,KAAK,CAAC,IAAY;IAC1B,OAAO,IAAI,GAAG,CACb,IAAI;SACF,SAAS,CAAC,MAAM,CAAC;SACjB,WAAW,EAAE;SACb,KAAK,CAAC,iBAAiB,CAAC,IAAI,E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CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IACzC,CAAC;IAED,KAAK;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;IACzB,CAAC;IAED,OAAO,CAAC,OAA2B;QAClC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;QACpB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;QAClC,CAAC;IACF,CAAC;IAED,GAAG,CAAC,KAAuB;QAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;IAClC,CAAC;IAED,MAAM,CAAC,EAAY;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC/B,CAAC;CACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MemoryId } from '../../types/ids/index.js';
|
|
2
|
-
import type { CreateMemoryParams, MemoryContent, MemoryIndexEntry, MemorySearchParams, MemorySearchResult, MemoryStore } from '../../types/memory/index.js';
|
|
2
|
+
import type { CreateMemoryParams, MemoryContent, MemoryIndexEntry, MemoryRecord, MemorySearchParams, MemorySearchResult, MemoryStore, UpdateMemoryParams } from '../../types/memory/index.js';
|
|
3
3
|
import { InMemoryMemoryIndex } from './index.js';
|
|
4
4
|
export declare class InMemoryMemoryStore implements MemoryStore {
|
|
5
5
|
private content;
|
|
@@ -9,7 +9,8 @@ export declare class InMemoryMemoryStore implements MemoryStore {
|
|
|
9
9
|
content: MemoryContent;
|
|
10
10
|
}>;
|
|
11
11
|
get(id: MemoryId): Promise<MemoryContent | undefined>;
|
|
12
|
-
|
|
12
|
+
getRecord(id: MemoryId): Promise<MemoryRecord | undefined>;
|
|
13
|
+
update(id: MemoryId, updates: UpdateMemoryParams): Promise<MemoryIndexEntry | undefined>;
|
|
13
14
|
delete(id: MemoryId): Promise<boolean>;
|
|
14
15
|
list(params?: MemorySearchParams): Promise<MemorySearchResult>;
|
|
15
16
|
getIndex(): InMemoryMemoryIndex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/store/memory/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EACX,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/store/memory/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EACX,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,MAAM,6BAA6B,CAAA;AAGpC,OAAO,EAAE,mBAAmB,EAAuB,MAAM,YAAY,CAAA;AAErE,qBAAa,mBAAoB,YAAW,WAAW;IACtD,OAAO,CAAC,OAAO,CAAmC;IAClD,OAAO,CAAC,KAAK,CAA4B;IAEnC,MAAM,CACX,MAAM,EAAE,kBAAkB,GACxB,OAAO,CAAC;QAAE,KAAK,EAAE,gBAAgB,CAAC;QAAC,OAAO,EAAE,aAAa,CAAA;KAAE,CAAC;IA2BzD,GAAG,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAIrD,SAAS,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAM1D,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAuCxF,MAAM,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAMtC,IAAI,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAQpE,QAAQ,IAAI,mBAAmB;CAG/B"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { assertMemoryStatus } from '../../types/memory/index.js';
|
|
1
2
|
import { generateMemoryId } from '../../utils/id.js';
|
|
2
|
-
import { InMemoryMemoryIndex } from './index.js';
|
|
3
|
+
import { InMemoryMemoryIndex, searchMemoryEntries } from './index.js';
|
|
3
4
|
export class InMemoryMemoryStore {
|
|
4
5
|
content = new Map();
|
|
5
6
|
index = new InMemoryMemoryIndex();
|
|
@@ -28,7 +29,14 @@ export class InMemoryMemoryStore {
|
|
|
28
29
|
async get(id) {
|
|
29
30
|
return this.content.get(id);
|
|
30
31
|
}
|
|
32
|
+
async getRecord(id) {
|
|
33
|
+
const entry = this.index.getEntry(id);
|
|
34
|
+
const content = this.content.get(id);
|
|
35
|
+
return entry && content ? structuredClone({ entry, content }) : undefined;
|
|
36
|
+
}
|
|
31
37
|
async update(id, updates) {
|
|
38
|
+
if (updates.status !== undefined)
|
|
39
|
+
assertMemoryStatus(updates.status);
|
|
32
40
|
const existing = this.index.getEntry(id);
|
|
33
41
|
if (!existing)
|
|
34
42
|
return undefined;
|
|
@@ -38,6 +46,7 @@ export class InMemoryMemoryStore {
|
|
|
38
46
|
title: updates.title ?? existing.title,
|
|
39
47
|
summary: updates.summary ?? existing.summary,
|
|
40
48
|
tags: updates.tags ? [...updates.tags] : existing.tags,
|
|
49
|
+
status: updates.status ?? existing.status,
|
|
41
50
|
updatedAt: now,
|
|
42
51
|
};
|
|
43
52
|
this.index.set(updated);
|
|
@@ -63,7 +72,7 @@ export class InMemoryMemoryStore {
|
|
|
63
72
|
return existed;
|
|
64
73
|
}
|
|
65
74
|
async list(params) {
|
|
66
|
-
return this.index.
|
|
75
|
+
return searchMemoryEntries(this.index.allEntries(), params ?? {}, (id) => this.content.get(id)?.content ?? '');
|
|
67
76
|
}
|
|
68
77
|
getIndex() {
|
|
69
78
|
return this.index;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/store/memory/memory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/store/memory/memory.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,MAAM,OAAO,mBAAmB;IACvB,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAA;IAC1C,KAAK,GAAG,IAAI,mBAAmB,EAAE,CAAA;IAEzC,KAAK,CAAC,MAAM,CACX,MAA0B;QAE1B,MAAM,EAAE,GAAG,gBAAgB,EAAE,CAAA;QAC7B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAEtB,MAAM,KAAK,GAAqB;YAC/B,EAAE;YACF,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;YACzC,MAAM,EAAE,QAAQ;YAChB,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,GAAG;SACd,CAAA;QAED,MAAM,aAAa,GAAkB;YACpC,EAAE;YACF,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,MAAM;YAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,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AI,CAAC,KAAK,CAAC,UAAU,EAAE,EACvB,MAAM,IAAI,EAAE,EACZ,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,IAAI,EAAE,CAC3C,CAAA;IACF,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,KAAK,CAAA;IAClB,CAAC;CACD"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Wait bound, not a lease: a slow or crashed owner is never silently replaced. */
|
|
2
|
+
export declare const DEFAULT_MEMORY_LOCK_TIMEOUT_MS = 10000;
|
|
3
|
+
export declare function validateMemoryLockTimeout(timeoutMs: number): void;
|
|
4
|
+
/**
|
|
5
|
+
* Local-filesystem exclusion for cooperating processes. Atomic rename of the
|
|
6
|
+
* index alone cannot serialize the index/content read-modify-write transaction.
|
|
7
|
+
* An abandoned lock fails closed; guessing a lease expired would permit two
|
|
8
|
+
* live writers to overwrite each other again.
|
|
9
|
+
*/
|
|
10
|
+
export declare function acquireMemoryOperationLock(path: string, timeoutMs: number): Promise<() => Promise<void>>;
|
|
11
|
+
//# sourceMappingURL=operation-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-lock.d.ts","sourceRoot":"","sources":["../../../src/store/memory/operation-lock.ts"],"names":[],"mappings":"AAMA,mFAAmF;AACnF,eAAO,MAAM,8BAA8B,QAAS,CAAA;AAEpD,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAQjE;AAWD;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC/C,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CA6D9B"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstat, open, readFile, unlink } from 'node:fs/promises';
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
|
+
import { NamzuError } from '../../types/errors/index.js';
|
|
5
|
+
/** Wait bound, not a lease: a slow or crashed owner is never silently replaced. */
|
|
6
|
+
export const DEFAULT_MEMORY_LOCK_TIMEOUT_MS = 10_000;
|
|
7
|
+
export function validateMemoryLockTimeout(timeoutMs) {
|
|
8
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0) {
|
|
9
|
+
throw new NamzuError({
|
|
10
|
+
code: 'invalid_config',
|
|
11
|
+
message: 'DiskMemoryStore lockTimeoutMs must be a positive safe integer.',
|
|
12
|
+
retryable: false,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function lockError(path, reason, timeoutMs) {
|
|
17
|
+
return new NamzuError({
|
|
18
|
+
code: 'storage_error',
|
|
19
|
+
message: `Memory operation lock ${path}: ${reason}. Stop all processes using this memory store and inspect the lock owner before removing a stale lock; it is never broken automatically.`,
|
|
20
|
+
details: { lockPath: path, timeoutMs },
|
|
21
|
+
retryable: false,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Local-filesystem exclusion for cooperating processes. Atomic rename of the
|
|
26
|
+
* index alone cannot serialize the index/content read-modify-write transaction.
|
|
27
|
+
* An abandoned lock fails closed; guessing a lease expired would permit two
|
|
28
|
+
* live writers to overwrite each other again.
|
|
29
|
+
*/
|
|
30
|
+
export async function acquireMemoryOperationLock(path, timeoutMs) {
|
|
31
|
+
const deadline = performance.now() + timeoutMs;
|
|
32
|
+
let attempted = false;
|
|
33
|
+
for (;;) {
|
|
34
|
+
if (attempted && performance.now() >= deadline) {
|
|
35
|
+
throw lockError(path, `acquisition timed out after ${timeoutMs} ms`, timeoutMs);
|
|
36
|
+
}
|
|
37
|
+
attempted = true;
|
|
38
|
+
let handle;
|
|
39
|
+
try {
|
|
40
|
+
handle = await open(path, 'wx', 0o600);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code !== 'EEXIST')
|
|
44
|
+
throw error;
|
|
45
|
+
const existing = await lstat(path).catch((statError) => {
|
|
46
|
+
if (statError.code === 'ENOENT')
|
|
47
|
+
return undefined;
|
|
48
|
+
throw statError;
|
|
49
|
+
});
|
|
50
|
+
if (!existing)
|
|
51
|
+
continue;
|
|
52
|
+
if (!existing.isFile() || existing.isSymbolicLink()) {
|
|
53
|
+
throw lockError(path, 'the occupied lock is not a regular file', timeoutMs);
|
|
54
|
+
}
|
|
55
|
+
if (performance.now() >= deadline) {
|
|
56
|
+
throw lockError(path, `acquisition timed out after ${timeoutMs} ms`, timeoutMs);
|
|
57
|
+
}
|
|
58
|
+
await delay(Math.min(25, Math.max(1, deadline - performance.now())));
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const owner = `${JSON.stringify({ pid: process.pid, token: randomUUID(), acquiredAt: Date.now() })}\n`;
|
|
62
|
+
const identity = await handle.stat().catch(async (error) => {
|
|
63
|
+
await handle.close();
|
|
64
|
+
// Exclusive create happened, but ownership could not be established.
|
|
65
|
+
// Leave the path for explicit recovery rather than unlink an unknown inode.
|
|
66
|
+
throw error;
|
|
67
|
+
});
|
|
68
|
+
try {
|
|
69
|
+
await handle.writeFile(owner, 'utf8');
|
|
70
|
+
await handle.sync();
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
await handle.close();
|
|
74
|
+
const current = await lstat(path).catch(() => undefined);
|
|
75
|
+
if (current?.dev === identity.dev && current.ino === identity.ino) {
|
|
76
|
+
await unlink(path).catch(() => undefined);
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
await handle.close();
|
|
81
|
+
return async () => {
|
|
82
|
+
const current = await lstat(path);
|
|
83
|
+
if (!current.isFile() ||
|
|
84
|
+
current.isSymbolicLink() ||
|
|
85
|
+
current.dev !== identity.dev ||
|
|
86
|
+
current.ino !== identity.ino ||
|
|
87
|
+
(await readFile(path, 'utf8')) !== owner) {
|
|
88
|
+
throw lockError(path, 'the lock owner changed before release', timeoutMs);
|
|
89
|
+
}
|
|
90
|
+
await unlink(path);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=operation-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation-lock.js","sourceRoot":"","sources":["../../../src/store/memory/operation-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAmB,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACjF,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAExD,mFAAmF;AACnF,MAAM,CAAC,MAAM,8BAA8B,GAAG,MAAM,CAAA;AAEpD,MAAM,UAAU,yBAAyB,CAAC,SAAiB;IAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;QACxD,MAAM,IAAI,UAAU,CAAC;YACpB,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,gEAAgE;YACzE,SAAS,EAAE,KAAK;SAChB,CAAC,CAAA;IACH,CAAC;AACF,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,MAAc,EAAE,SAAiB;IACjE,OAAO,IAAI,UAAU,CAAC;QACrB,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,yBAAyB,IAAI,KAAK,MAAM,yIAAyI;QAC1L,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE;QACtC,SAAS,EAAE,KAAK;KAChB,CAAC,CAAA;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC/C,IAAY,E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AC,MAAM,EAAE;gBACjB,OAAO,CAAC,cAAc,EAAE;gBACxB,OAAO,CAAC,GAAG,KAAK,QAAQ,CAAC,GAAG;gBAC5B,OAAO,CAAC,GAAG,KAAK,QAAQ,CAAC,GAAG;gBAC5B,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,KAAK,EACvC,CAAC;gBACF,MAAM,SAAS,CAAC,IAAI,EAAE,uCAAuC,EAAE,SAAS,CAAC,CAAA;YAC1E,CAAC;YACD,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;QACnB,CAAC,CAAA;IACF,CAAC;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/bash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/tools/builtins/bash.ts"],"names":[],"mappings":"AAoRA,6GAA6G;AAC7G,eAAO,MAAM,qBAAqB,4NACwL,CAAA;AAE1N,eAAO,MAAM,QAAQ;;;;EAqOnB,CAAA"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
import { SANDBOX_KILL_GRACE_MS } from '../../constants/sandbox/index.js';
|
|
4
5
|
import { DANGEROUS_PATTERNS } from '../../constants/tools/index.js';
|
|
6
|
+
import { killTree } from '../../process/kill-tree.js';
|
|
7
|
+
import { subscribeToAbort } from '../../utils/abort.js';
|
|
5
8
|
import { defineTool } from '../defineTool.js';
|
|
6
9
|
import { scrubInheritedEnv } from '../env-scrub.js';
|
|
7
|
-
const execAsync = promisify(exec);
|
|
8
10
|
// Namzu owns its own bash timeout knob — `NAMZU_BASH_TIMEOUT_MS`.
|
|
9
11
|
// The Vandal fallback (`VANDAL_NAMZU_TIMEOUT_MS`) lived here as a
|
|
10
12
|
// historical bridge while Namzu was carved out of the Vandal repo,
|
|
@@ -49,26 +51,192 @@ const inputSchema = z.object({
|
|
|
49
51
|
.optional()
|
|
50
52
|
.describe('Start the command as a background job and return its id immediately, instead of waiting. The turn is not held open; read its output with the `job` tool. Use for watchers, dev servers and long builds. Do NOT write `cmd &` yourself — under the sandbox the shell that backgrounds it exits immediately and takes the job with it.'),
|
|
51
53
|
});
|
|
54
|
+
const MAX_SHELL_PROGRESS_CHARS = 160;
|
|
55
|
+
/** Keep a bounded tail even when a process never writes a newline. */
|
|
56
|
+
function appendProgressTail(previous, chunk, start, end) {
|
|
57
|
+
return (previous + chunk.slice(Math.max(start, end - MAX_SHELL_PROGRESS_CHARS), end)).slice(-MAX_SHELL_PROGRESS_CHARS);
|
|
58
|
+
}
|
|
59
|
+
/** Clipping a UTF-16 string must not display half of a surrogate pair. */
|
|
60
|
+
function progressLine(value) {
|
|
61
|
+
let line = value.trim();
|
|
62
|
+
const first = line.charCodeAt(0);
|
|
63
|
+
if (first >= 0xdc00 && first <= 0xdfff)
|
|
64
|
+
line = line.slice(1);
|
|
65
|
+
const last = line.charCodeAt(line.length - 1);
|
|
66
|
+
if (last >= 0xd800 && last <= 0xdbff)
|
|
67
|
+
line = line.slice(0, -1);
|
|
68
|
+
return line;
|
|
69
|
+
}
|
|
52
70
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* replaces it as the next arrives, so sending a whole chunk sends a wall
|
|
57
|
-
* of text into a slot that shows one line of it. A chunk usually ends
|
|
58
|
-
* mid-line and usually ends with a newline, so the last NON-EMPTY line is
|
|
59
|
-
* the most recent complete thing the command actually said.
|
|
60
|
-
*
|
|
61
|
-
* Progress is capped rather than truncated with an ellipsis: this is
|
|
62
|
-
* glanced at, and a marker in a line nobody reads to the end is noise.
|
|
71
|
+
* One latest line per stream, independent of transport chunk boundaries.
|
|
72
|
+
* Reports stay synchronous: the executor owns coalescing and backpressure.
|
|
73
|
+
* This projection adds neither an output log nor a queue of pending reports.
|
|
63
74
|
*/
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
function shellProgress(report) {
|
|
76
|
+
if (!report)
|
|
77
|
+
return undefined;
|
|
78
|
+
const partial = { stdout: '', stderr: '' };
|
|
79
|
+
let lastMessage = '';
|
|
80
|
+
return ({ stream, data }) => {
|
|
81
|
+
let line = partial[stream];
|
|
82
|
+
let latest = '';
|
|
83
|
+
let start = 0;
|
|
84
|
+
// Scan delimiters without allocating an array for arbitrarily chatty output.
|
|
85
|
+
for (const match of data.matchAll(/[\r\n]/g)) {
|
|
86
|
+
line = appendProgressTail(line, data, start, match.index);
|
|
87
|
+
latest = progressLine(line) || latest;
|
|
88
|
+
line = '';
|
|
89
|
+
start = match.index + 1;
|
|
90
|
+
}
|
|
91
|
+
line = appendProgressTail(line, data, start, data.length);
|
|
92
|
+
partial[stream] = line;
|
|
93
|
+
const message = progressLine(line) || latest;
|
|
94
|
+
if (!message || message === lastMessage)
|
|
95
|
+
return;
|
|
96
|
+
lastMessage = message;
|
|
97
|
+
try {
|
|
98
|
+
report(message);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// A diagnostic observer cannot break the process output reader.
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Keep the shell's process group until inherited pipes close. Node's exec
|
|
107
|
+
* timeout/AbortSignal kills only the wrapper and closes its pipes immediately,
|
|
108
|
+
* leaving the command and its descendants running after the promise settles.
|
|
109
|
+
*/
|
|
110
|
+
function execHostShell(command, options) {
|
|
111
|
+
options.signal?.throwIfAborted();
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
const child = spawn(command, {
|
|
114
|
+
cwd: options.cwd,
|
|
115
|
+
env: options.env,
|
|
116
|
+
shell: true,
|
|
117
|
+
// killTree's negative PID must never target the caller's own group.
|
|
118
|
+
detached: process.platform !== 'win32',
|
|
119
|
+
});
|
|
120
|
+
const captures = {
|
|
121
|
+
stdout: {
|
|
122
|
+
chunks: [],
|
|
123
|
+
bytes: 0,
|
|
124
|
+
truncated: false,
|
|
125
|
+
decoder: new StringDecoder('utf8'),
|
|
126
|
+
},
|
|
127
|
+
stderr: {
|
|
128
|
+
chunks: [],
|
|
129
|
+
bytes: 0,
|
|
130
|
+
truncated: false,
|
|
131
|
+
decoder: new StringDecoder('utf8'),
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
let cause;
|
|
135
|
+
let failure;
|
|
136
|
+
let escalation;
|
|
137
|
+
let disposeAbort;
|
|
138
|
+
let closed = false;
|
|
139
|
+
const cancel = (origin) => {
|
|
140
|
+
if (closed || cause !== undefined)
|
|
141
|
+
return;
|
|
142
|
+
cause = origin;
|
|
143
|
+
escalation = setTimeout(() => {
|
|
144
|
+
escalation = undefined;
|
|
145
|
+
killTree(child, 'SIGKILL');
|
|
146
|
+
// A descendant can deliberately start a separate session. It is
|
|
147
|
+
// outside this group, but its inherited pipes must not hold the
|
|
148
|
+
// cancelled call forever. Keep what was captured during grace.
|
|
149
|
+
child.stdin?.destroy();
|
|
150
|
+
child.stdout?.destroy();
|
|
151
|
+
child.stderr?.destroy();
|
|
152
|
+
}, SANDBOX_KILL_GRACE_MS);
|
|
153
|
+
escalation.unref?.();
|
|
154
|
+
killTree(child, 'SIGTERM');
|
|
155
|
+
};
|
|
156
|
+
const capture = (stream, chunk) => {
|
|
157
|
+
const state = captures[stream];
|
|
158
|
+
const kept = Math.min(chunk.length, options.maxBuffer - state.bytes);
|
|
159
|
+
if (kept > 0) {
|
|
160
|
+
state.chunks.push(Buffer.from(chunk.subarray(0, kept)));
|
|
161
|
+
state.bytes += kept;
|
|
162
|
+
}
|
|
163
|
+
if (kept < chunk.length) {
|
|
164
|
+
state.truncated = true;
|
|
165
|
+
if (cause === undefined) {
|
|
166
|
+
failure = Object.assign(new RangeError(`${stream} maxBuffer length exceeded`), {
|
|
167
|
+
code: 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER',
|
|
168
|
+
});
|
|
169
|
+
cancel('maxBuffer');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (options.onOutput) {
|
|
173
|
+
const data = state.decoder.write(chunk);
|
|
174
|
+
if (data)
|
|
175
|
+
options.onOutput({ stream, data });
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const onStdout = (chunk) => capture('stdout', chunk);
|
|
179
|
+
const onStderr = (chunk) => capture('stderr', chunk);
|
|
180
|
+
child.stdout?.on('data', onStdout);
|
|
181
|
+
child.stderr?.on('data', onStderr);
|
|
182
|
+
child.once('error', (error) => {
|
|
183
|
+
failure ??= error;
|
|
184
|
+
});
|
|
185
|
+
child.once('close', (code, signal) => {
|
|
186
|
+
closed = true;
|
|
187
|
+
disposeAbort?.();
|
|
188
|
+
clearTimeout(deadline);
|
|
189
|
+
if (escalation !== undefined) {
|
|
190
|
+
clearTimeout(escalation);
|
|
191
|
+
// Pipes closing can precede a descendant which closed its copies.
|
|
192
|
+
// Force the owned group now instead of retaining its PID in a timer.
|
|
193
|
+
killTree(child, 'SIGKILL');
|
|
194
|
+
}
|
|
195
|
+
child.stdout?.off('data', onStdout);
|
|
196
|
+
child.stderr?.off('data', onStderr);
|
|
197
|
+
for (const stream of ['stdout', 'stderr']) {
|
|
198
|
+
const data = captures[stream].decoder.end();
|
|
199
|
+
if (data)
|
|
200
|
+
options.onOutput?.({ stream, data });
|
|
201
|
+
}
|
|
202
|
+
const decodeCapture = (stream) => {
|
|
203
|
+
const state = captures[stream];
|
|
204
|
+
const bytes = Buffer.concat(state.chunks, state.bytes);
|
|
205
|
+
// Do not flush an incomplete UTF-8 character cut by our byte cap.
|
|
206
|
+
return state.truncated ? new StringDecoder('utf8').write(bytes) : bytes.toString('utf8');
|
|
207
|
+
};
|
|
208
|
+
const stdout = decodeCapture('stdout');
|
|
209
|
+
const stderr = decodeCapture('stderr');
|
|
210
|
+
if (!failure && cause === undefined && code === 0 && signal === null) {
|
|
211
|
+
resolve({ stdout, stderr });
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const error = failure ??
|
|
215
|
+
(cause === 'caller'
|
|
216
|
+
? Object.assign(new Error('The operation was aborted', { cause: options.signal?.reason }), {
|
|
217
|
+
name: 'AbortError',
|
|
218
|
+
code: 'ABORT_ERR',
|
|
219
|
+
})
|
|
220
|
+
: new Error(`Command failed: ${command}\n${stderr}`));
|
|
221
|
+
reject(Object.assign(error, {
|
|
222
|
+
stdout,
|
|
223
|
+
stderr,
|
|
224
|
+
stdoutTruncated: captures.stdout.truncated,
|
|
225
|
+
stderrTruncated: captures.stderr.truncated,
|
|
226
|
+
code: failure?.code ?? (cause === 'caller' ? 'ABORT_ERR' : code),
|
|
227
|
+
killed: cause !== undefined,
|
|
228
|
+
signal,
|
|
229
|
+
timedOut: cause === 'timeout',
|
|
230
|
+
}));
|
|
231
|
+
});
|
|
232
|
+
const deadline = setTimeout(() => cancel('timeout'), options.timeout);
|
|
233
|
+
deadline.unref?.();
|
|
234
|
+
if (options.signal) {
|
|
235
|
+
disposeAbort = subscribeToAbort(options.signal, () => cancel('caller'));
|
|
236
|
+
if (options.signal.aborted)
|
|
237
|
+
cancel('caller');
|
|
238
|
+
}
|
|
239
|
+
});
|
|
72
240
|
}
|
|
73
241
|
function isDangerousCommand(command) {
|
|
74
242
|
return DANGEROUS_PATTERNS.some((pattern) => pattern.test(command));
|
|
@@ -167,6 +335,7 @@ export const BashTool = defineTool({
|
|
|
167
335
|
// sandbox can be added later as an explicit
|
|
168
336
|
// `SandboxExecOptions.workspaceRelativeCwd` field; the bash
|
|
169
337
|
// builtin doesn't have that requirement today.
|
|
338
|
+
const onOutput = shellProgress(context.report);
|
|
170
339
|
if (context.sandbox) {
|
|
171
340
|
const result = await context.sandbox.exec('/bin/sh', ['-c', input.command], {
|
|
172
341
|
timeout: input.timeout,
|
|
@@ -181,21 +350,8 @@ export const BashTool = defineTool({
|
|
|
181
350
|
// durable transcript — so this is a progress signal, not a
|
|
182
351
|
// second copy of the output. `result.stdout` remains the
|
|
183
352
|
// answer the model is given.
|
|
184
|
-
onOutput
|
|
185
|
-
? ({ data }) => {
|
|
186
|
-
const line = lastNonEmptyLine(data);
|
|
187
|
-
if (line)
|
|
188
|
-
context.report?.(line);
|
|
189
|
-
}
|
|
190
|
-
: undefined,
|
|
353
|
+
onOutput,
|
|
191
354
|
});
|
|
192
|
-
if (result.timedOut) {
|
|
193
|
-
return {
|
|
194
|
-
success: false,
|
|
195
|
-
output: '',
|
|
196
|
-
error: `Command timed out after ${input.timeout}ms`,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
355
|
// The sandbox reports when IT clipped a stream. Dropping those
|
|
200
356
|
// flags meant the model saw a complete-looking result that had
|
|
201
357
|
// silently lost its tail — and the kernel's own convention is
|
|
@@ -208,39 +364,30 @@ export const BashTool = defineTool({
|
|
|
208
364
|
result.stdout ? `STDOUT:\n${result.stdout}` : '',
|
|
209
365
|
result.stderr ? `STDERR:\n${result.stderr}` : '',
|
|
210
366
|
clipped.length > 0
|
|
211
|
-
? `[${clipped.join(' and ')} was truncated by the sandbox output cap
|
|
367
|
+
? `[${clipped.join(' and ')} was truncated by the sandbox output cap. The omitted output is unavailable in this result. Use a saved artifact or a read-only observation; do not repeat a state-changing action to recover its output.]`
|
|
212
368
|
: '',
|
|
213
369
|
]
|
|
214
370
|
.filter(Boolean)
|
|
215
371
|
.join('\n\n');
|
|
216
372
|
return {
|
|
217
|
-
success: result.exitCode === 0,
|
|
373
|
+
success: !result.timedOut && result.exitCode === 0,
|
|
218
374
|
output: output || '(no output)',
|
|
219
375
|
data: {
|
|
220
376
|
exitCode: result.exitCode,
|
|
221
377
|
sandboxed: true,
|
|
378
|
+
timedOut: result.timedOut,
|
|
222
379
|
stdoutTruncated: result.stdoutTruncated ?? false,
|
|
223
380
|
stderrTruncated: result.stderrTruncated ?? false,
|
|
224
381
|
},
|
|
225
|
-
error: result.
|
|
382
|
+
error: result.timedOut
|
|
383
|
+
? `Command timed out after ${input.timeout}ms. Any captured output before the deadline is above.`
|
|
384
|
+
: result.exitCode !== 0
|
|
385
|
+
? `Command exited with code ${result.exitCode}`
|
|
386
|
+
: undefined,
|
|
226
387
|
};
|
|
227
388
|
}
|
|
228
|
-
//
|
|
229
|
-
// a
|
|
230
|
-
// and the executor's deadline could only ever DETACH from the tool
|
|
231
|
-
// rather than end the work it started.
|
|
232
|
-
// `exec` REJECTS on a non-zero exit, on its own timeout, and on a
|
|
233
|
-
// kill — and the rejection carries `stdout`, `stderr`, `code` and
|
|
234
|
-
// `killed`. Letting it propagate threw all of that away: the registry
|
|
235
|
-
// turned the throw into a structured failure, so the model was told a
|
|
236
|
-
// command failed and not one word about how.
|
|
237
|
-
//
|
|
238
|
-
// That is the common case, not an edge one. A failing test run and a
|
|
239
|
-
// failing build are the two things an agent runs bash for most, and
|
|
240
|
-
// both exit non-zero WITH the output that explains why. The sandbox
|
|
241
|
-
// branch above already reports all of it; this branch did not, so the
|
|
242
|
-
// same command told the model two different amounts depending on where
|
|
243
|
-
// it happened to run.
|
|
389
|
+
// The owned runner retains stdout/stderr on non-zero exit and timeout,
|
|
390
|
+
// so a failed command still returns the evidence explaining its failure.
|
|
244
391
|
// The inherited half is scrubbed; `context.env` is not. Inheritance is
|
|
245
392
|
// implicit — nobody decided this command should see `process.env` — while
|
|
246
393
|
// a `context.env` key is one a host wrote on purpose. See
|
|
@@ -248,12 +395,13 @@ export const BashTool = defineTool({
|
|
|
248
395
|
// the sandbox, and for what it therefore does not catch.
|
|
249
396
|
const inherited = scrubInheritedEnv();
|
|
250
397
|
try {
|
|
251
|
-
const { stdout, stderr } = await
|
|
398
|
+
const { stdout, stderr } = await execHostShell(input.command, {
|
|
252
399
|
cwd: context.workingDirectory,
|
|
253
400
|
timeout: input.timeout,
|
|
254
401
|
env: { ...inherited.env, ...context.env },
|
|
255
402
|
maxBuffer: DEFAULT_BASH_MAX_BUFFER_BYTES,
|
|
256
403
|
signal: context.abortSignal,
|
|
404
|
+
onOutput,
|
|
257
405
|
});
|
|
258
406
|
return {
|
|
259
407
|
success: true,
|
|
@@ -266,17 +414,23 @@ export const BashTool = defineTool({
|
|
|
266
414
|
// A caller-owned Stop is the caller's, not a command failure.
|
|
267
415
|
if (context.abortSignal?.aborted)
|
|
268
416
|
throw err;
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
|
|
272
|
-
const timedOut = failure.killed === true && failure.signal === 'SIGTERM';
|
|
417
|
+
// A maxBuffer stop or an ordinary signal is not a deadline. The
|
|
418
|
+
// runner latches the first cancellation cause before signalling.
|
|
419
|
+
const timedOut = failure.timedOut === true;
|
|
273
420
|
const exitCode = typeof failure.code === 'number' ? failure.code : undefined;
|
|
421
|
+
const clipped = [
|
|
422
|
+
failure.stdoutTruncated ? 'stdout' : '',
|
|
423
|
+
failure.stderrTruncated ? 'stderr' : '',
|
|
424
|
+
].filter(Boolean);
|
|
274
425
|
// Only on the failure path. A successful command did not need to know,
|
|
275
426
|
// and appending this to every result would make the common case noisy
|
|
276
427
|
// to buy nothing. A failing one is exactly where "authentication
|
|
277
428
|
// failed" has to be distinguishable from "the variable was withheld".
|
|
278
429
|
const output = [
|
|
279
430
|
formatShellOutput(failure.stdout, failure.stderr),
|
|
431
|
+
clipped.length > 0
|
|
432
|
+
? `[${clipped.join(' and ')} ${clipped.length === 1 ? 'was' : 'were'} truncated by the host output cap. The omitted output is unavailable in this result.]`
|
|
433
|
+
: '',
|
|
280
434
|
describeWithheldEnv(inherited.dropped),
|
|
281
435
|
]
|
|
282
436
|
.filter(Boolean)
|
|
@@ -287,6 +441,8 @@ export const BashTool = defineTool({
|
|
|
287
441
|
data: {
|
|
288
442
|
...(exitCode !== undefined ? { exitCode } : {}),
|
|
289
443
|
timedOut,
|
|
444
|
+
stdoutTruncated: failure.stdoutTruncated ?? false,
|
|
445
|
+
stderrTruncated: failure.stderrTruncated ?? false,
|
|
290
446
|
...(failure.signal ? { signal: failure.signal } : {}),
|
|
291
447
|
},
|
|
292
448
|
error: timedOut
|