@calliopelabs/cli 3.0.0 → 3.2.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/README.md +54 -7
- package/dist/acp.d.ts +1 -4
- package/dist/acp.d.ts.map +1 -1
- package/dist/acp.js +118 -217
- package/dist/acp.js.map +1 -1
- package/dist/approvals/commands.d.ts +35 -0
- package/dist/approvals/commands.d.ts.map +1 -0
- package/dist/approvals/commands.js +51 -0
- package/dist/approvals/commands.js.map +1 -0
- package/dist/approvals/index.d.ts +6 -0
- package/dist/approvals/index.d.ts.map +1 -0
- package/dist/approvals/index.js +6 -0
- package/dist/approvals/index.js.map +1 -0
- package/dist/approvals/queue.d.ts +18 -0
- package/dist/approvals/queue.d.ts.map +1 -0
- package/dist/approvals/queue.js +46 -0
- package/dist/approvals/queue.js.map +1 -0
- package/dist/approvals/request.d.ts +13 -0
- package/dist/approvals/request.d.ts.map +1 -0
- package/dist/approvals/request.js +102 -0
- package/dist/approvals/request.js.map +1 -0
- package/dist/approvals/store.d.ts +24 -0
- package/dist/approvals/store.d.ts.map +1 -0
- package/dist/approvals/store.js +229 -0
- package/dist/approvals/store.js.map +1 -0
- package/dist/approvals/types.d.ts +27 -0
- package/dist/approvals/types.d.ts.map +1 -0
- package/dist/approvals/types.js +4 -0
- package/dist/approvals/types.js.map +1 -0
- package/dist/auto-compressor.d.ts +3 -2
- package/dist/auto-compressor.d.ts.map +1 -1
- package/dist/auto-compressor.js +9 -9
- package/dist/auto-compressor.js.map +1 -1
- package/dist/bin.d.ts.map +1 -1
- package/dist/bin.js +125 -22
- package/dist/bin.js.map +1 -1
- package/dist/brain/access.d.ts +65 -0
- package/dist/brain/access.d.ts.map +1 -0
- package/dist/brain/access.js +216 -0
- package/dist/brain/access.js.map +1 -0
- package/dist/brain/actions.d.ts +120 -0
- package/dist/brain/actions.d.ts.map +1 -0
- package/dist/brain/actions.js +270 -0
- package/dist/brain/actions.js.map +1 -0
- package/dist/brain/cli.d.ts +17 -0
- package/dist/brain/cli.d.ts.map +1 -0
- package/dist/brain/cli.js +206 -0
- package/dist/brain/cli.js.map +1 -0
- package/dist/brain/index.d.ts +16 -0
- package/dist/brain/index.d.ts.map +1 -0
- package/dist/brain/index.js +16 -0
- package/dist/brain/index.js.map +1 -0
- package/dist/brain/journal.d.ts +17 -0
- package/dist/brain/journal.d.ts.map +1 -0
- package/dist/brain/journal.js +189 -0
- package/dist/brain/journal.js.map +1 -0
- package/dist/brain/kg.d.ts +23 -0
- package/dist/brain/kg.d.ts.map +1 -0
- package/dist/brain/kg.js +36 -0
- package/dist/brain/kg.js.map +1 -0
- package/dist/brain/presentation.d.ts +3 -0
- package/dist/brain/presentation.d.ts.map +1 -0
- package/dist/brain/presentation.js +48 -0
- package/dist/brain/presentation.js.map +1 -0
- package/dist/brain/queries.d.ts +179 -0
- package/dist/brain/queries.d.ts.map +1 -0
- package/dist/brain/queries.js +210 -0
- package/dist/brain/queries.js.map +1 -0
- package/dist/brain/run-ingest.d.ts +29 -0
- package/dist/brain/run-ingest.d.ts.map +1 -0
- package/dist/brain/run-ingest.js +200 -0
- package/dist/brain/run-ingest.js.map +1 -0
- package/dist/brain/sqlite.d.ts +19 -0
- package/dist/brain/sqlite.d.ts.map +1 -0
- package/dist/brain/sqlite.js +252 -0
- package/dist/brain/sqlite.js.map +1 -0
- package/dist/brain/store.d.ts +31 -0
- package/dist/brain/store.d.ts.map +1 -0
- package/dist/brain/store.js +324 -0
- package/dist/brain/store.js.map +1 -0
- package/dist/brain/tool-query.d.ts +6 -0
- package/dist/brain/tool-query.d.ts.map +1 -0
- package/dist/brain/tool-query.js +42 -0
- package/dist/brain/tool-query.js.map +1 -0
- package/dist/brain/tools.d.ts +13 -0
- package/dist/brain/tools.d.ts.map +1 -0
- package/dist/brain/tools.js +20 -0
- package/dist/brain/tools.js.map +1 -0
- package/dist/brain/transfer.d.ts +57 -0
- package/dist/brain/transfer.d.ts.map +1 -0
- package/dist/brain/transfer.js +266 -0
- package/dist/brain/transfer.js.map +1 -0
- package/dist/brain/types.d.ts +145 -0
- package/dist/brain/types.d.ts.map +1 -0
- package/dist/brain/types.js +38 -0
- package/dist/brain/types.js.map +1 -0
- package/dist/brain/validation.d.ts +15 -0
- package/dist/brain/validation.d.ts.map +1 -0
- package/dist/brain/validation.js +163 -0
- package/dist/brain/validation.js.map +1 -0
- package/dist/budget.d.ts +5 -4
- package/dist/budget.d.ts.map +1 -1
- package/dist/budget.js +16 -38
- package/dist/budget.js.map +1 -1
- package/dist/cancellation.d.ts +8 -0
- package/dist/cancellation.d.ts.map +1 -0
- package/dist/cancellation.js +42 -0
- package/dist/cancellation.js.map +1 -0
- package/dist/checkpoint.d.ts +2 -2
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +5 -5
- package/dist/checkpoint.js.map +1 -1
- package/dist/circuit-breaker/breaker.d.ts.map +1 -1
- package/dist/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +32 -8
- package/dist/config.js.map +1 -1
- package/dist/cost.js.map +1 -1
- package/dist/diff.js.map +1 -1
- package/dist/doctor.d.ts +30 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +124 -0
- package/dist/doctor.js.map +1 -0
- package/dist/env-expansion.js.map +1 -1
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +33 -9
- package/dist/errors.js.map +1 -1
- package/dist/execution/attribution.d.ts +17 -0
- package/dist/execution/attribution.d.ts.map +1 -0
- package/dist/execution/attribution.js +21 -0
- package/dist/execution/attribution.js.map +1 -0
- package/dist/execution/authority.d.ts +22 -0
- package/dist/execution/authority.d.ts.map +1 -0
- package/dist/execution/authority.js +134 -0
- package/dist/execution/authority.js.map +1 -0
- package/dist/execution/billing.d.ts +100 -0
- package/dist/execution/billing.d.ts.map +1 -0
- package/dist/execution/billing.js +166 -0
- package/dist/execution/billing.js.map +1 -0
- package/dist/execution/child-grants.d.ts +9 -0
- package/dist/execution/child-grants.d.ts.map +1 -0
- package/dist/execution/child-grants.js +55 -0
- package/dist/execution/child-grants.js.map +1 -0
- package/dist/execution/files.d.ts +6 -0
- package/dist/execution/files.d.ts.map +1 -0
- package/dist/execution/files.js +159 -0
- package/dist/execution/files.js.map +1 -0
- package/dist/execution/guard.d.ts +50 -0
- package/dist/execution/guard.d.ts.map +1 -0
- package/dist/execution/guard.js +158 -0
- package/dist/execution/guard.js.map +1 -0
- package/dist/execution/index.d.ts +12 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +12 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/ledger.d.ts +23 -0
- package/dist/execution/ledger.d.ts.map +1 -0
- package/dist/execution/ledger.js +379 -0
- package/dist/execution/ledger.js.map +1 -0
- package/dist/execution/project-spend.d.ts +45 -0
- package/dist/execution/project-spend.d.ts.map +1 -0
- package/dist/execution/project-spend.js +274 -0
- package/dist/execution/project-spend.js.map +1 -0
- package/dist/execution/quote.d.ts +19 -0
- package/dist/execution/quote.d.ts.map +1 -0
- package/dist/execution/quote.js +116 -0
- package/dist/execution/quote.js.map +1 -0
- package/dist/execution/types.d.ts +113 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +9 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/execution/writer-recovery.d.ts +3 -0
- package/dist/execution/writer-recovery.d.ts.map +1 -0
- package/dist/execution/writer-recovery.js +85 -0
- package/dist/execution/writer-recovery.js.map +1 -0
- package/dist/fuzzy-search.js.map +1 -1
- package/dist/goals/accounting.d.ts +69 -0
- package/dist/goals/accounting.d.ts.map +1 -0
- package/dist/goals/accounting.js +100 -0
- package/dist/goals/accounting.js.map +1 -0
- package/dist/goals/actions.d.ts +33 -0
- package/dist/goals/actions.d.ts.map +1 -0
- package/dist/goals/actions.js +261 -0
- package/dist/goals/actions.js.map +1 -0
- package/dist/goals/authority.d.ts +9 -0
- package/dist/goals/authority.d.ts.map +1 -0
- package/dist/goals/authority.js +47 -0
- package/dist/goals/authority.js.map +1 -0
- package/dist/goals/cli.d.ts +10 -0
- package/dist/goals/cli.d.ts.map +1 -0
- package/dist/goals/cli.js +169 -0
- package/dist/goals/cli.js.map +1 -0
- package/dist/goals/contracts.d.ts +18 -0
- package/dist/goals/contracts.d.ts.map +1 -0
- package/dist/goals/contracts.js +127 -0
- package/dist/goals/contracts.js.map +1 -0
- package/dist/goals/index.d.ts +17 -0
- package/dist/goals/index.d.ts.map +1 -0
- package/dist/goals/index.js +16 -0
- package/dist/goals/index.js.map +1 -0
- package/dist/goals/journal.d.ts +5 -0
- package/dist/goals/journal.d.ts.map +1 -0
- package/dist/goals/journal.js +142 -0
- package/dist/goals/journal.js.map +1 -0
- package/dist/goals/metrics.d.ts +53 -0
- package/dist/goals/metrics.d.ts.map +1 -0
- package/dist/goals/metrics.js +141 -0
- package/dist/goals/metrics.js.map +1 -0
- package/dist/goals/repair.d.ts +10 -0
- package/dist/goals/repair.d.ts.map +1 -0
- package/dist/goals/repair.js +50 -0
- package/dist/goals/repair.js.map +1 -0
- package/dist/goals/routing.d.ts +18 -0
- package/dist/goals/routing.d.ts.map +1 -0
- package/dist/goals/routing.js +60 -0
- package/dist/goals/routing.js.map +1 -0
- package/dist/goals/store.d.ts +30 -0
- package/dist/goals/store.d.ts.map +1 -0
- package/dist/goals/store.js +314 -0
- package/dist/goals/store.js.map +1 -0
- package/dist/goals/supervised-cli.d.ts +5 -0
- package/dist/goals/supervised-cli.d.ts.map +1 -0
- package/dist/goals/supervised-cli.js +44 -0
- package/dist/goals/supervised-cli.js.map +1 -0
- package/dist/goals/supervised.d.ts +8 -0
- package/dist/goals/supervised.d.ts.map +1 -0
- package/dist/goals/supervised.js +65 -0
- package/dist/goals/supervised.js.map +1 -0
- package/dist/goals/team.d.ts +8 -0
- package/dist/goals/team.d.ts.map +1 -0
- package/dist/goals/team.js +64 -0
- package/dist/goals/team.js.map +1 -0
- package/dist/goals/types.d.ts +174 -0
- package/dist/goals/types.d.ts.map +1 -0
- package/dist/goals/types.js +2 -0
- package/dist/goals/types.js.map +1 -0
- package/dist/goals/validation.d.ts +17 -0
- package/dist/goals/validation.d.ts.map +1 -0
- package/dist/goals/validation.js +172 -0
- package/dist/goals/validation.js.map +1 -0
- package/dist/headless.d.ts +1 -0
- package/dist/headless.d.ts.map +1 -1
- package/dist/headless.js +98 -275
- package/dist/headless.js.map +1 -1
- package/dist/health/index.d.ts +5 -0
- package/dist/health/index.d.ts.map +1 -0
- package/dist/health/index.js +5 -0
- package/dist/health/index.js.map +1 -0
- package/dist/health/store.d.ts +24 -0
- package/dist/health/store.d.ts.map +1 -0
- package/dist/health/store.js +190 -0
- package/dist/health/store.js.map +1 -0
- package/dist/health/summary.d.ts +10 -0
- package/dist/health/summary.d.ts.map +1 -0
- package/dist/health/summary.js +95 -0
- package/dist/health/summary.js.map +1 -0
- package/dist/health/target.d.ts +3 -0
- package/dist/health/target.d.ts.map +1 -0
- package/dist/health/target.js +53 -0
- package/dist/health/target.js.map +1 -0
- package/dist/health/types.d.ts +72 -0
- package/dist/health/types.d.ts.map +1 -0
- package/dist/health/types.js +2 -0
- package/dist/health/types.js.map +1 -0
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +35 -17
- package/dist/hooks.js.map +1 -1
- package/dist/improvement/actions.d.ts +27 -0
- package/dist/improvement/actions.d.ts.map +1 -0
- package/dist/improvement/actions.js +116 -0
- package/dist/improvement/actions.js.map +1 -0
- package/dist/improvement/cli.d.ts +9 -0
- package/dist/improvement/cli.d.ts.map +1 -0
- package/dist/improvement/cli.js +58 -0
- package/dist/improvement/cli.js.map +1 -0
- package/dist/improvement/feedback.d.ts +30 -0
- package/dist/improvement/feedback.d.ts.map +1 -0
- package/dist/improvement/feedback.js +7 -0
- package/dist/improvement/feedback.js.map +1 -0
- package/dist/improvement/index.d.ts +7 -0
- package/dist/improvement/index.d.ts.map +1 -0
- package/dist/improvement/index.js +7 -0
- package/dist/improvement/index.js.map +1 -0
- package/dist/improvement/metrics.d.ts +4 -0
- package/dist/improvement/metrics.d.ts.map +1 -0
- package/dist/improvement/metrics.js +38 -0
- package/dist/improvement/metrics.js.map +1 -0
- package/dist/improvement/projection.d.ts +7 -0
- package/dist/improvement/projection.d.ts.map +1 -0
- package/dist/improvement/projection.js +135 -0
- package/dist/improvement/projection.js.map +1 -0
- package/dist/improvement/types.d.ts +115 -0
- package/dist/improvement/types.d.ts.map +1 -0
- package/dist/improvement/types.js +2 -0
- package/dist/improvement/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/instructions.d.ts +10 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/instructions.js +93 -0
- package/dist/instructions.js.map +1 -0
- package/dist/isolation/contracts.d.ts +42 -0
- package/dist/isolation/contracts.d.ts.map +1 -0
- package/dist/isolation/contracts.js +33 -0
- package/dist/isolation/contracts.js.map +1 -0
- package/dist/isolation/coordinator.d.ts +10 -0
- package/dist/isolation/coordinator.d.ts.map +1 -0
- package/dist/isolation/coordinator.js +79 -0
- package/dist/isolation/coordinator.js.map +1 -0
- package/dist/isolation/index.d.ts +5 -0
- package/dist/isolation/index.d.ts.map +1 -0
- package/dist/isolation/index.js +5 -0
- package/dist/isolation/index.js.map +1 -0
- package/dist/isolation/process.d.ts +11 -0
- package/dist/isolation/process.d.ts.map +1 -0
- package/dist/isolation/process.js +131 -0
- package/dist/isolation/process.js.map +1 -0
- package/dist/isolation/worktree.d.ts +25 -0
- package/dist/isolation/worktree.d.ts.map +1 -0
- package/dist/isolation/worktree.js +282 -0
- package/dist/isolation/worktree.js.map +1 -0
- package/dist/iteration-ledger.d.ts.map +1 -1
- package/dist/iteration-ledger.js.map +1 -1
- package/dist/local-model.d.ts +2 -2
- package/dist/local-model.d.ts.map +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +5 -1
- package/dist/memory.js.map +1 -1
- package/dist/model-detection.d.ts +14 -18
- package/dist/model-detection.d.ts.map +1 -1
- package/dist/model-detection.js +287 -149
- package/dist/model-detection.js.map +1 -1
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +3 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/metadata.d.ts +43 -0
- package/dist/models/metadata.d.ts.map +1 -0
- package/dist/models/metadata.js +72 -0
- package/dist/models/metadata.js.map +1 -0
- package/dist/models/openrouter.d.ts +6 -0
- package/dist/models/openrouter.d.ts.map +1 -0
- package/dist/models/openrouter.js +38 -0
- package/dist/models/openrouter.js.map +1 -0
- package/dist/orchestration/accounting.d.ts +35 -0
- package/dist/orchestration/accounting.d.ts.map +1 -0
- package/dist/orchestration/accounting.js +27 -0
- package/dist/orchestration/accounting.js.map +1 -0
- package/dist/orchestration/actions.d.ts +23 -0
- package/dist/orchestration/actions.d.ts.map +1 -0
- package/dist/orchestration/actions.js +65 -0
- package/dist/orchestration/actions.js.map +1 -0
- package/dist/orchestration/cli.d.ts +28 -0
- package/dist/orchestration/cli.d.ts.map +1 -0
- package/dist/orchestration/cli.js +178 -0
- package/dist/orchestration/cli.js.map +1 -0
- package/dist/orchestration/coordinator-actions.d.ts +15 -0
- package/dist/orchestration/coordinator-actions.d.ts.map +1 -0
- package/dist/orchestration/coordinator-actions.js +79 -0
- package/dist/orchestration/coordinator-actions.js.map +1 -0
- package/dist/orchestration/coordinator-types.d.ts +193 -0
- package/dist/orchestration/coordinator-types.d.ts.map +1 -0
- package/dist/orchestration/coordinator-types.js +2 -0
- package/dist/orchestration/coordinator-types.js.map +1 -0
- package/dist/orchestration/coordinator.d.ts +32 -0
- package/dist/orchestration/coordinator.d.ts.map +1 -0
- package/dist/orchestration/coordinator.js +405 -0
- package/dist/orchestration/coordinator.js.map +1 -0
- package/dist/orchestration/execution-cli.d.ts +11 -0
- package/dist/orchestration/execution-cli.d.ts.map +1 -0
- package/dist/orchestration/execution-cli.js +183 -0
- package/dist/orchestration/execution-cli.js.map +1 -0
- package/dist/orchestration/execution-journal.d.ts +15 -0
- package/dist/orchestration/execution-journal.d.ts.map +1 -0
- package/dist/orchestration/execution-journal.js +477 -0
- package/dist/orchestration/execution-journal.js.map +1 -0
- package/dist/orchestration/execution-store.d.ts +39 -0
- package/dist/orchestration/execution-store.d.ts.map +1 -0
- package/dist/orchestration/execution-store.js +325 -0
- package/dist/orchestration/execution-store.js.map +1 -0
- package/dist/orchestration/execution.d.ts +8 -0
- package/dist/orchestration/execution.d.ts.map +1 -0
- package/dist/orchestration/execution.js +47 -0
- package/dist/orchestration/execution.js.map +1 -0
- package/dist/orchestration/index.d.ts +20 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +17 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/orchestration/progress.d.ts +19 -0
- package/dist/orchestration/progress.d.ts.map +1 -0
- package/dist/orchestration/progress.js +20 -0
- package/dist/orchestration/progress.js.map +1 -0
- package/dist/orchestration/recovery.d.ts +4 -0
- package/dist/orchestration/recovery.d.ts.map +1 -0
- package/dist/orchestration/recovery.js +121 -0
- package/dist/orchestration/recovery.js.map +1 -0
- package/dist/orchestration/request-accounting.d.ts +35 -0
- package/dist/orchestration/request-accounting.d.ts.map +1 -0
- package/dist/orchestration/request-accounting.js +71 -0
- package/dist/orchestration/request-accounting.js.map +1 -0
- package/dist/orchestration/routing.d.ts +20 -0
- package/dist/orchestration/routing.d.ts.map +1 -0
- package/dist/orchestration/routing.js +38 -0
- package/dist/orchestration/routing.js.map +1 -0
- package/dist/orchestration/store.d.ts +26 -0
- package/dist/orchestration/store.d.ts.map +1 -0
- package/dist/orchestration/store.js +381 -0
- package/dist/orchestration/store.js.map +1 -0
- package/dist/orchestration/types.d.ts +201 -0
- package/dist/orchestration/types.d.ts.map +1 -0
- package/dist/orchestration/types.js +11 -0
- package/dist/orchestration/types.js.map +1 -0
- package/dist/orchestration/validation.d.ts +29 -0
- package/dist/orchestration/validation.d.ts.map +1 -0
- package/dist/orchestration/validation.js +440 -0
- package/dist/orchestration/validation.js.map +1 -0
- package/dist/orchestration/verification.d.ts +30 -0
- package/dist/orchestration/verification.d.ts.map +1 -0
- package/dist/orchestration/verification.js +204 -0
- package/dist/orchestration/verification.js.map +1 -0
- package/dist/orchestration/worker-context.d.ts +33 -0
- package/dist/orchestration/worker-context.d.ts.map +1 -0
- package/dist/orchestration/worker-context.js +31 -0
- package/dist/orchestration/worker-context.js.map +1 -0
- package/dist/parallel-tools.js.map +1 -1
- package/dist/plugins.d.ts.map +1 -1
- package/dist/policy.d.ts +1 -0
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +25 -5
- package/dist/policy.js.map +1 -1
- package/dist/preferences/controls.d.ts +21 -0
- package/dist/preferences/controls.d.ts.map +1 -0
- package/dist/preferences/controls.js +36 -0
- package/dist/preferences/controls.js.map +1 -0
- package/dist/preferences/flags.d.ts +8 -0
- package/dist/preferences/flags.d.ts.map +1 -0
- package/dist/preferences/flags.js +27 -0
- package/dist/preferences/flags.js.map +1 -0
- package/dist/preferences/index.d.ts +9 -0
- package/dist/preferences/index.d.ts.map +1 -0
- package/dist/preferences/index.js +9 -0
- package/dist/preferences/index.js.map +1 -0
- package/dist/preferences/once.d.ts +8 -0
- package/dist/preferences/once.d.ts.map +1 -0
- package/dist/preferences/once.js +28 -0
- package/dist/preferences/once.js.map +1 -0
- package/dist/preferences/resolve.d.ts +14 -0
- package/dist/preferences/resolve.d.ts.map +1 -0
- package/dist/preferences/resolve.js +58 -0
- package/dist/preferences/resolve.js.map +1 -0
- package/dist/preferences/store.d.ts +19 -0
- package/dist/preferences/store.d.ts.map +1 -0
- package/dist/preferences/store.js +147 -0
- package/dist/preferences/store.js.map +1 -0
- package/dist/preferences/submission.d.ts +16 -0
- package/dist/preferences/submission.d.ts.map +1 -0
- package/dist/preferences/submission.js +29 -0
- package/dist/preferences/submission.js.map +1 -0
- package/dist/preferences/types.d.ts +23 -0
- package/dist/preferences/types.d.ts.map +1 -0
- package/dist/preferences/types.js +2 -0
- package/dist/preferences/types.js.map +1 -0
- package/dist/preferences/validate.d.ts +3 -0
- package/dist/preferences/validate.d.ts.map +1 -0
- package/dist/preferences/validate.js +15 -0
- package/dist/preferences/validate.js.map +1 -0
- package/dist/process-cancellation.d.ts +6 -0
- package/dist/process-cancellation.d.ts.map +1 -0
- package/dist/process-cancellation.js +39 -0
- package/dist/process-cancellation.js.map +1 -0
- package/dist/providers/anthropic.d.ts +7 -2
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +72 -41
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/bedrock.d.ts +1 -1
- package/dist/providers/bedrock.d.ts.map +1 -1
- package/dist/providers/bedrock.js +39 -23
- package/dist/providers/bedrock.js.map +1 -1
- package/dist/providers/compat.d.ts +4 -3
- package/dist/providers/compat.d.ts.map +1 -1
- package/dist/providers/compat.js +49 -31
- package/dist/providers/compat.js.map +1 -1
- package/dist/providers/deepseek-reasoning.d.ts +64 -0
- package/dist/providers/deepseek-reasoning.d.ts.map +1 -0
- package/dist/providers/deepseek-reasoning.js +28 -0
- package/dist/providers/deepseek-reasoning.js.map +1 -0
- package/dist/providers/google.d.ts +4 -3
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +128 -19
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +216 -36
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/ollama.d.ts.map +1 -1
- package/dist/providers/ollama.js +79 -43
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts +12 -12
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +54 -46
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/openrouter-bounds.d.ts +22 -0
- package/dist/providers/openrouter-bounds.d.ts.map +1 -0
- package/dist/providers/openrouter-bounds.js +16 -0
- package/dist/providers/openrouter-bounds.js.map +1 -0
- package/dist/providers/stream-attempt.d.ts +29 -0
- package/dist/providers/stream-attempt.d.ts.map +1 -0
- package/dist/providers/stream-attempt.js +63 -0
- package/dist/providers/stream-attempt.js.map +1 -0
- package/dist/providers/types.d.ts +40 -4
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +19 -0
- package/dist/providers/types.js.map +1 -1
- package/dist/replay.d.ts.map +1 -1
- package/dist/replay.js +16 -0
- package/dist/replay.js.map +1 -1
- package/dist/risk.d.ts.map +1 -1
- package/dist/risk.js +5 -0
- package/dist/risk.js.map +1 -1
- package/dist/router.d.ts +7 -110
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +0 -451
- package/dist/router.js.map +1 -1
- package/dist/routing/index.d.ts +6 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +5 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/prompt.d.ts +4 -0
- package/dist/routing/prompt.d.ts.map +1 -0
- package/dist/routing/prompt.js +14 -0
- package/dist/routing/prompt.js.map +1 -0
- package/dist/routing/select.d.ts +9 -0
- package/dist/routing/select.d.ts.map +1 -0
- package/dist/routing/select.js +279 -0
- package/dist/routing/select.js.map +1 -0
- package/dist/routing/smart.d.ts +31 -0
- package/dist/routing/smart.d.ts.map +1 -0
- package/dist/routing/smart.js +46 -0
- package/dist/routing/smart.js.map +1 -0
- package/dist/routing/types.d.ts +79 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/routing/types.js +2 -0
- package/dist/routing/types.js.map +1 -0
- package/dist/runlog.d.ts +32 -4
- package/dist/runlog.d.ts.map +1 -1
- package/dist/runlog.js +22 -6
- package/dist/runlog.js.map +1 -1
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +6 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/permissions.d.ts +21 -0
- package/dist/runtime/permissions.d.ts.map +1 -0
- package/dist/runtime/permissions.js +110 -0
- package/dist/runtime/permissions.js.map +1 -0
- package/dist/runtime/repair.d.ts +20 -0
- package/dist/runtime/repair.d.ts.map +1 -0
- package/dist/runtime/repair.js +50 -0
- package/dist/runtime/repair.js.map +1 -0
- package/dist/runtime/tool-retry.d.ts +3 -0
- package/dist/runtime/tool-retry.d.ts.map +1 -0
- package/dist/runtime/tool-retry.js +12 -0
- package/dist/runtime/tool-retry.js.map +1 -0
- package/dist/runtime/turn.d.ts +97 -0
- package/dist/runtime/turn.d.ts.map +1 -0
- package/dist/runtime/turn.js +437 -0
- package/dist/runtime/turn.js.map +1 -0
- package/dist/runtime/types.d.ts +11 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +5 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/sandbox/docker.d.ts +4 -4
- package/dist/sandbox/docker.d.ts.map +1 -1
- package/dist/sandbox/docker.js +55 -16
- package/dist/sandbox/docker.js.map +1 -1
- package/dist/sandbox/native.d.ts +1 -0
- package/dist/sandbox/native.d.ts.map +1 -1
- package/dist/sandbox/native.js +11 -2
- package/dist/sandbox/native.js.map +1 -1
- package/dist/scope.d.ts +5 -9
- package/dist/scope.d.ts.map +1 -1
- package/dist/scope.js +43 -20
- package/dist/scope.js.map +1 -1
- package/dist/scuttlebot/client.d.ts.map +1 -1
- package/dist/scuttlebot/client.js.map +1 -1
- package/dist/scuttlebot/http-client.d.ts.map +1 -1
- package/dist/scuttlebot/irc-client.d.ts +5 -5
- package/dist/scuttlebot/irc-client.d.ts.map +1 -1
- package/dist/scuttlebot/irc-client.js.map +1 -1
- package/dist/session-management/actions.d.ts +28 -0
- package/dist/session-management/actions.d.ts.map +1 -0
- package/dist/session-management/actions.js +78 -0
- package/dist/session-management/actions.js.map +1 -0
- package/dist/session-management/cli.d.ts +24 -0
- package/dist/session-management/cli.d.ts.map +1 -0
- package/dist/session-management/cli.js +92 -0
- package/dist/session-management/cli.js.map +1 -0
- package/dist/session-management/files.d.ts +5 -0
- package/dist/session-management/files.d.ts.map +1 -0
- package/dist/session-management/files.js +92 -0
- package/dist/session-management/files.js.map +1 -0
- package/dist/session-management/index.d.ts +7 -0
- package/dist/session-management/index.d.ts.map +1 -0
- package/dist/session-management/index.js +7 -0
- package/dist/session-management/index.js.map +1 -0
- package/dist/session-management/permissions.d.ts +12 -0
- package/dist/session-management/permissions.d.ts.map +1 -0
- package/dist/session-management/permissions.js +33 -0
- package/dist/session-management/permissions.js.map +1 -0
- package/dist/session-management/presentation.d.ts +5 -0
- package/dist/session-management/presentation.d.ts.map +1 -0
- package/dist/session-management/presentation.js +10 -0
- package/dist/session-management/presentation.js.map +1 -0
- package/dist/session-management/transfer.d.ts +9 -0
- package/dist/session-management/transfer.d.ts.map +1 -0
- package/dist/session-management/transfer.js +39 -0
- package/dist/session-management/transfer.js.map +1 -0
- package/dist/sessions/context.d.ts +4 -0
- package/dist/sessions/context.d.ts.map +1 -0
- package/dist/sessions/context.js +6 -0
- package/dist/sessions/context.js.map +1 -0
- package/dist/sessions/format.d.ts +38 -0
- package/dist/sessions/format.d.ts.map +1 -0
- package/dist/sessions/format.js +116 -0
- package/dist/sessions/format.js.map +1 -0
- package/dist/sessions/history.d.ts +37 -0
- package/dist/sessions/history.d.ts.map +1 -0
- package/dist/sessions/history.js +197 -0
- package/dist/sessions/history.js.map +1 -0
- package/dist/sessions/index.d.ts +8 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/sessions/index.js +8 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/output.d.ts +31 -0
- package/dist/sessions/output.d.ts.map +1 -0
- package/dist/sessions/output.js +115 -0
- package/dist/sessions/output.js.map +1 -0
- package/dist/sessions/portable.d.ts +26 -0
- package/dist/sessions/portable.d.ts.map +1 -0
- package/dist/sessions/portable.js +105 -0
- package/dist/sessions/portable.js.map +1 -0
- package/dist/sessions/snapshot.d.ts +11 -0
- package/dist/sessions/snapshot.d.ts.map +1 -0
- package/dist/sessions/snapshot.js +118 -0
- package/dist/sessions/snapshot.js.map +1 -0
- package/dist/sessions/tool-state.d.ts +11 -0
- package/dist/sessions/tool-state.d.ts.map +1 -0
- package/dist/sessions/tool-state.js +152 -0
- package/dist/sessions/tool-state.js.map +1 -0
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +16 -5
- package/dist/setup.js.map +1 -1
- package/dist/spawning/actions.d.ts +23 -0
- package/dist/spawning/actions.d.ts.map +1 -0
- package/dist/spawning/actions.js +120 -0
- package/dist/spawning/actions.js.map +1 -0
- package/dist/spawning/authority.d.ts +15 -0
- package/dist/spawning/authority.d.ts.map +1 -0
- package/dist/spawning/authority.js +16 -0
- package/dist/spawning/authority.js.map +1 -0
- package/dist/spawning/cli.d.ts +4 -0
- package/dist/spawning/cli.d.ts.map +1 -0
- package/dist/spawning/cli.js +46 -0
- package/dist/spawning/cli.js.map +1 -0
- package/dist/spawning/execution.d.ts +13 -0
- package/dist/spawning/execution.d.ts.map +1 -0
- package/dist/spawning/execution.js +59 -0
- package/dist/spawning/execution.js.map +1 -0
- package/dist/spawning/index.d.ts +8 -0
- package/dist/spawning/index.d.ts.map +1 -0
- package/dist/spawning/index.js +8 -0
- package/dist/spawning/index.js.map +1 -0
- package/dist/spawning/store.d.ts +12 -0
- package/dist/spawning/store.d.ts.map +1 -0
- package/dist/spawning/store.js +93 -0
- package/dist/spawning/store.js.map +1 -0
- package/dist/spawning/types.d.ts +34 -0
- package/dist/spawning/types.d.ts.map +1 -0
- package/dist/spawning/types.js +2 -0
- package/dist/spawning/types.js.map +1 -0
- package/dist/spawning/validation.d.ts +14 -0
- package/dist/spawning/validation.d.ts.map +1 -0
- package/dist/spawning/validation.js +95 -0
- package/dist/spawning/validation.js.map +1 -0
- package/dist/storage.d.ts +29 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +112 -40
- package/dist/storage.js.map +1 -1
- package/dist/streaming.d.ts.map +1 -1
- package/dist/streaming.js.map +1 -1
- package/dist/styles.d.ts +56 -56
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js.map +1 -1
- package/dist/summarization.d.ts.map +1 -1
- package/dist/summarization.js.map +1 -1
- package/dist/supervision/approval.d.ts +4 -0
- package/dist/supervision/approval.d.ts.map +1 -0
- package/dist/supervision/approval.js +7 -0
- package/dist/supervision/approval.js.map +1 -0
- package/dist/supervision/availability.d.ts +34 -0
- package/dist/supervision/availability.d.ts.map +1 -0
- package/dist/supervision/availability.js +44 -0
- package/dist/supervision/availability.js.map +1 -0
- package/dist/supervision/context.d.ts +36 -0
- package/dist/supervision/context.d.ts.map +1 -0
- package/dist/supervision/context.js +52 -0
- package/dist/supervision/context.js.map +1 -0
- package/dist/supervision/contracts.d.ts +7 -0
- package/dist/supervision/contracts.d.ts.map +1 -0
- package/dist/supervision/contracts.js +86 -0
- package/dist/supervision/contracts.js.map +1 -0
- package/dist/supervision/effects.d.ts +15 -0
- package/dist/supervision/effects.d.ts.map +1 -0
- package/dist/supervision/effects.js +19 -0
- package/dist/supervision/effects.js.map +1 -0
- package/dist/supervision/evidence.d.ts +32 -0
- package/dist/supervision/evidence.d.ts.map +1 -0
- package/dist/supervision/evidence.js +68 -0
- package/dist/supervision/evidence.js.map +1 -0
- package/dist/supervision/health.d.ts +16 -0
- package/dist/supervision/health.d.ts.map +1 -0
- package/dist/supervision/health.js +86 -0
- package/dist/supervision/health.js.map +1 -0
- package/dist/supervision/index.d.ts +13 -0
- package/dist/supervision/index.d.ts.map +1 -0
- package/dist/supervision/index.js +13 -0
- package/dist/supervision/index.js.map +1 -0
- package/dist/supervision/journal.d.ts +16 -0
- package/dist/supervision/journal.d.ts.map +1 -0
- package/dist/supervision/journal.js +311 -0
- package/dist/supervision/journal.js.map +1 -0
- package/dist/supervision/receipts.d.ts +4 -0
- package/dist/supervision/receipts.d.ts.map +1 -0
- package/dist/supervision/receipts.js +21 -0
- package/dist/supervision/receipts.js.map +1 -0
- package/dist/supervision/reply.d.ts +12 -0
- package/dist/supervision/reply.d.ts.map +1 -0
- package/dist/supervision/reply.js +50 -0
- package/dist/supervision/reply.js.map +1 -0
- package/dist/supervision/runtime.d.ts +8 -0
- package/dist/supervision/runtime.d.ts.map +1 -0
- package/dist/supervision/runtime.js +188 -0
- package/dist/supervision/runtime.js.map +1 -0
- package/dist/supervision/types.d.ts +174 -0
- package/dist/supervision/types.d.ts.map +1 -0
- package/dist/supervision/types.js +2 -0
- package/dist/supervision/types.js.map +1 -0
- package/dist/terminal-image.js.map +1 -1
- package/dist/tools.d.ts +12 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +131 -23
- package/dist/tools.js.map +1 -1
- package/dist/trust.js.map +1 -1
- package/dist/turn-controller.d.ts +12 -0
- package/dist/turn-controller.d.ts.map +1 -0
- package/dist/turn-controller.js +51 -0
- package/dist/turn-controller.js.map +1 -0
- package/dist/types.d.ts +7 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -1
- package/dist/ui/agent.d.ts +11 -10
- package/dist/ui/agent.d.ts.map +1 -1
- package/dist/ui/agent.js +293 -897
- package/dist/ui/agent.js.map +1 -1
- package/dist/ui/chat-input.d.ts +2 -1
- package/dist/ui/chat-input.d.ts.map +1 -1
- package/dist/ui/commands.d.ts +20 -2
- package/dist/ui/commands.d.ts.map +1 -1
- package/dist/ui/commands.js +208 -155
- package/dist/ui/commands.js.map +1 -1
- package/dist/ui/completions.d.ts.map +1 -1
- package/dist/ui/completions.js +16 -5
- package/dist/ui/completions.js.map +1 -1
- package/dist/ui/components.d.ts +6 -6
- package/dist/ui/components.d.ts.map +1 -1
- package/dist/ui/debug-log.d.ts.map +1 -1
- package/dist/ui/error-boundary.d.ts +1 -1
- package/dist/ui/error-boundary.d.ts.map +1 -1
- package/dist/ui/frame.d.ts +1 -1
- package/dist/ui/frame.d.ts.map +1 -1
- package/dist/ui/index.d.ts +7 -3
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +13 -11
- package/dist/ui/index.js.map +1 -1
- package/dist/ui/messages.d.ts +1 -1
- package/dist/ui/messages.d.ts.map +1 -1
- package/dist/ui/messages.js +5 -0
- package/dist/ui/messages.js.map +1 -1
- package/dist/ui/modals/index.d.ts +1 -0
- package/dist/ui/modals/index.d.ts.map +1 -1
- package/dist/ui/modals/index.js +1 -0
- package/dist/ui/modals/index.js.map +1 -1
- package/dist/ui/modals/prompts.d.ts +9 -11
- package/dist/ui/modals/prompts.d.ts.map +1 -1
- package/dist/ui/modals/prompts.js +15 -11
- package/dist/ui/modals/prompts.js.map +1 -1
- package/dist/ui/modals/selectors.d.ts +5 -3
- package/dist/ui/modals/selectors.d.ts.map +1 -1
- package/dist/ui/modals/selectors.js +3 -2
- package/dist/ui/modals/selectors.js.map +1 -1
- package/dist/ui/modals/setup.d.ts +3 -2
- package/dist/ui/modals/setup.d.ts.map +1 -1
- package/dist/ui/modals/setup.js +1 -1
- package/dist/ui/modals/tool-output.d.ts +8 -0
- package/dist/ui/modals/tool-output.d.ts.map +1 -0
- package/dist/ui/modals/tool-output.js +26 -0
- package/dist/ui/modals/tool-output.js.map +1 -0
- package/dist/ui/model-commands.d.ts +4 -0
- package/dist/ui/model-commands.d.ts.map +1 -0
- package/dist/ui/model-commands.js +69 -0
- package/dist/ui/model-commands.js.map +1 -0
- package/dist/ui/regions/input-region.d.ts +1 -1
- package/dist/ui/regions/input-region.d.ts.map +1 -1
- package/dist/ui/regions/modal-host.d.ts +4 -1
- package/dist/ui/regions/modal-host.d.ts.map +1 -1
- package/dist/ui/regions/modal-host.js +7 -1
- package/dist/ui/regions/modal-host.js.map +1 -1
- package/dist/ui/regions/static-scrollback.d.ts +1 -1
- package/dist/ui/regions/static-scrollback.d.ts.map +1 -1
- package/dist/ui/regions/status-region.d.ts +2 -1
- package/dist/ui/regions/status-region.d.ts.map +1 -1
- package/dist/ui/regions/status-region.js +2 -2
- package/dist/ui/regions/status-region.js.map +1 -1
- package/dist/ui/regions/tool-activity.d.ts +6 -0
- package/dist/ui/regions/tool-activity.d.ts.map +1 -0
- package/dist/ui/regions/tool-activity.js +9 -0
- package/dist/ui/regions/tool-activity.js.map +1 -0
- package/dist/ui/regions/transcript-region.d.ts +1 -1
- package/dist/ui/regions/transcript-region.d.ts.map +1 -1
- package/dist/ui/regions/transcript-region.js +3 -2
- package/dist/ui/regions/transcript-region.js.map +1 -1
- package/dist/ui/regions/workflow-region.d.ts +9 -0
- package/dist/ui/regions/workflow-region.d.ts.map +1 -0
- package/dist/ui/regions/workflow-region.js +11 -0
- package/dist/ui/regions/workflow-region.js.map +1 -0
- package/dist/ui/self-restart.js.map +1 -1
- package/dist/ui/session-commands.d.ts +3 -0
- package/dist/ui/session-commands.d.ts.map +1 -0
- package/dist/ui/session-commands.js +141 -0
- package/dist/ui/session-commands.js.map +1 -0
- package/dist/ui/state/use-approval-state.d.ts +9 -0
- package/dist/ui/state/use-approval-state.d.ts.map +1 -0
- package/dist/ui/state/use-approval-state.js +18 -0
- package/dist/ui/state/use-approval-state.js.map +1 -0
- package/dist/ui/state/use-chat-controller.d.ts +4 -1
- package/dist/ui/state/use-chat-controller.d.ts.map +1 -1
- package/dist/ui/state/use-chat-controller.js +256 -180
- package/dist/ui/state/use-chat-controller.js.map +1 -1
- package/dist/ui/state/use-modal-state.d.ts +6 -8
- package/dist/ui/state/use-modal-state.d.ts.map +1 -1
- package/dist/ui/state/use-modal-state.js +3 -4
- package/dist/ui/state/use-modal-state.js.map +1 -1
- package/dist/ui/state/use-model-state.d.ts +7 -3
- package/dist/ui/state/use-model-state.d.ts.map +1 -1
- package/dist/ui/state/use-model-state.js +24 -17
- package/dist/ui/state/use-model-state.js.map +1 -1
- package/dist/ui/state/use-processing-state.js.map +1 -1
- package/dist/ui/state/use-queue-state.d.ts +4 -3
- package/dist/ui/state/use-queue-state.d.ts.map +1 -1
- package/dist/ui/state/use-queue-state.js +11 -8
- package/dist/ui/state/use-queue-state.js.map +1 -1
- package/dist/ui/state/use-session-init.d.ts +4 -0
- package/dist/ui/state/use-session-init.d.ts.map +1 -1
- package/dist/ui/state/use-session-init.js +19 -3
- package/dist/ui/state/use-session-init.js.map +1 -1
- package/dist/ui/state/use-transcript-state.d.ts +6 -3
- package/dist/ui/state/use-transcript-state.d.ts.map +1 -1
- package/dist/ui/state/use-transcript-state.js +27 -15
- package/dist/ui/state/use-transcript-state.js.map +1 -1
- package/dist/ui/status-bar.d.ts +3 -2
- package/dist/ui/status-bar.d.ts.map +1 -1
- package/dist/ui/status-bar.js +3 -3
- package/dist/ui/status-bar.js.map +1 -1
- package/dist/ui/tool-output-cache.d.ts +12 -0
- package/dist/ui/tool-output-cache.d.ts.map +1 -0
- package/dist/ui/tool-output-cache.js +27 -0
- package/dist/ui/tool-output-cache.js.map +1 -0
- package/dist/ui/tool-output-commands.d.ts +3 -0
- package/dist/ui/tool-output-commands.d.ts.map +1 -0
- package/dist/ui/tool-output-commands.js +37 -0
- package/dist/ui/tool-output-commands.js.map +1 -0
- package/dist/ui/tool-output-wrap.d.ts +3 -0
- package/dist/ui/tool-output-wrap.d.ts.map +1 -0
- package/dist/ui/tool-output-wrap.js +24 -0
- package/dist/ui/tool-output-wrap.js.map +1 -0
- package/dist/ui/tool-progress.d.ts +23 -0
- package/dist/ui/tool-progress.d.ts.map +1 -0
- package/dist/ui/tool-progress.js +42 -0
- package/dist/ui/tool-progress.js.map +1 -0
- package/dist/ui/types.d.ts +8 -0
- package/dist/ui/types.d.ts.map +1 -1
- package/dist/ui/workflow-progress.d.ts +21 -0
- package/dist/ui/workflow-progress.d.ts.map +1 -0
- package/dist/ui/workflow-progress.js +107 -0
- package/dist/ui/workflow-progress.js.map +1 -0
- package/dist/version-check.js.map +1 -1
- package/package.json +21 -12
- package/scripts/verify-runlog.mjs +208 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { dirname, relative, resolve, isAbsolute } from 'node:path';
|
|
3
|
+
import { canonicalPath } from '../approvals/index.js';
|
|
4
|
+
import { throwIfCancelled } from '../cancellation.js';
|
|
5
|
+
import { executionToolDenial, executionPathDenial, accountLineage, checkExecutionIdentity, integer, assertExecutionStoreOutsideProject } from './authority.js';
|
|
6
|
+
import { requestCostNanos } from './ledger.js';
|
|
7
|
+
import { ExecutionLimitError } from './types.js';
|
|
8
|
+
import { getBudgetCaps, projectBudgetPath } from '../budget.js';
|
|
9
|
+
import { ProjectSpendLedger } from './project-spend.js';
|
|
10
|
+
import { providerQuote, costCapNanos } from './quote.js';
|
|
11
|
+
import { effectiveExecutionManifest } from './child-grants.js';
|
|
12
|
+
import { BRAIN_TOOLS, BRAIN_TOOL_NAMES } from '../brain/tools.js';
|
|
13
|
+
import { readBillingEvidence } from './billing.js';
|
|
14
|
+
import { validateRequestAttribution } from './attribution.js';
|
|
15
|
+
export class ExecutionGuard {
|
|
16
|
+
cwd;
|
|
17
|
+
manifest;
|
|
18
|
+
deadline;
|
|
19
|
+
expectedHash;
|
|
20
|
+
agentId;
|
|
21
|
+
ledger;
|
|
22
|
+
maxOutputTokens;
|
|
23
|
+
assertAuthority;
|
|
24
|
+
filesRoot;
|
|
25
|
+
workspace;
|
|
26
|
+
attribution;
|
|
27
|
+
measuredInputReservation;
|
|
28
|
+
constructor(execution, cwd) {
|
|
29
|
+
this.cwd = cwd;
|
|
30
|
+
this.attribution = execution.attribution === undefined ? undefined : validateRequestAttribution(execution.attribution);
|
|
31
|
+
this.measuredInputReservation = execution.measuredInputReservation === true;
|
|
32
|
+
this.assertAuthority = execution.assertAuthority;
|
|
33
|
+
this.assertAuthority?.();
|
|
34
|
+
this.workspace = execution.workspace;
|
|
35
|
+
this.workspace?.assertIdentity();
|
|
36
|
+
const saved = execution.ledger.read(cwd);
|
|
37
|
+
assertExecutionStoreOutsideProject(saved.manifest.project.root, dirname(execution.ledger.root));
|
|
38
|
+
if (saved.projection.manifestHash !== execution.manifestHash)
|
|
39
|
+
throw new ExecutionLimitError('conflict', 'Execution contract does not match the budget ledger.');
|
|
40
|
+
const effective = effectiveExecutionManifest(saved.manifest, saved.projection), agent = accountLineage(effective, execution.agentId)[0];
|
|
41
|
+
integer(execution.maxOutputTokens, 1, 100000000);
|
|
42
|
+
this.manifest = effective;
|
|
43
|
+
this.expectedHash = execution.manifestHash;
|
|
44
|
+
this.agentId = agent.id;
|
|
45
|
+
this.ledger = execution.ledger;
|
|
46
|
+
this.maxOutputTokens = execution.maxOutputTokens;
|
|
47
|
+
this.deadline = Math.min(saved.manifest.deadline, agent.deadline);
|
|
48
|
+
this.filesRoot = this.workspace?.filesRoot ?? this.manifest.project.root;
|
|
49
|
+
if (this.workspace)
|
|
50
|
+
assertExecutionStoreOutsideProject(this.manifest.project.root, this.filesRoot);
|
|
51
|
+
}
|
|
52
|
+
check = (call, cwd = this.cwd) => {
|
|
53
|
+
this.assertAuthority?.();
|
|
54
|
+
this.workspace?.assertIdentity();
|
|
55
|
+
if (this.workspace && call.name === 'shell')
|
|
56
|
+
return 'Isolated workers cannot issue model-selected shell commands; use the declared coordinator verifier.';
|
|
57
|
+
const denial = executionToolDenial(this.manifest, this.agentId, call, cwd);
|
|
58
|
+
if (denial || !this.workspace)
|
|
59
|
+
return denial;
|
|
60
|
+
if (['read_file', 'write_file', 'edit_file', 'list_files'].includes(call.name))
|
|
61
|
+
try {
|
|
62
|
+
this.filePath(resolve(cwd, String(call.arguments.path ?? '.')));
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return 'Isolated file path is outside its workspace or aliases Git metadata.';
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
filePath(file) {
|
|
70
|
+
if (!this.workspace)
|
|
71
|
+
return file;
|
|
72
|
+
this.workspace.assertIdentity();
|
|
73
|
+
const rel = relative(this.manifest.project.root, file);
|
|
74
|
+
if (rel === '..' || rel.startsWith('../') || isAbsolute(rel) || rel.split('/').some(p => p.toLowerCase() === '.git'))
|
|
75
|
+
throw new ExecutionLimitError('authority', 'Isolated file path exceeds its project scope.');
|
|
76
|
+
const path = resolve(this.filesRoot, rel);
|
|
77
|
+
if (canonicalPath(path) !== path)
|
|
78
|
+
throw new ExecutionLimitError('authority', 'Isolated file path became an alias.');
|
|
79
|
+
return path;
|
|
80
|
+
}
|
|
81
|
+
tools(tools) {
|
|
82
|
+
const allowed = accountLineage(this.manifest, this.agentId)[0].allowedTools;
|
|
83
|
+
return [...tools.filter(t => !BRAIN_TOOL_NAMES.includes(t.name)), ...BRAIN_TOOLS].filter(tool => allowed.includes(tool.name) && ['think', 'ask_question', 'create_plan', 'read_file', 'write_file', 'edit_file', 'list_files', ...BRAIN_TOOL_NAMES].includes(tool.name));
|
|
84
|
+
}
|
|
85
|
+
brainContext() {
|
|
86
|
+
return { assertActive: signal => this.assertActive(signal), sourceDenial: source => {
|
|
87
|
+
const locator = source.locator;
|
|
88
|
+
if (locator.path && !locator.projectKey)
|
|
89
|
+
return 'Knowledge file locator lacks a project binding.';
|
|
90
|
+
if (locator.projectKey && locator.projectKey !== this.manifest.project.key)
|
|
91
|
+
return 'Knowledge source belongs to another project.';
|
|
92
|
+
return executionPathDenial(this.manifest, accountLineage(this.manifest, this.agentId)[0], locator.projectKey === this.manifest.project.key ? locator.path ?? '.' : '.', 'read');
|
|
93
|
+
} };
|
|
94
|
+
}
|
|
95
|
+
assertActive(signal) {
|
|
96
|
+
throwIfCancelled(signal);
|
|
97
|
+
this.assertAuthority?.();
|
|
98
|
+
this.workspace?.assertIdentity();
|
|
99
|
+
checkExecutionIdentity(this.manifest, this.cwd);
|
|
100
|
+
if (Date.now() >= this.deadline)
|
|
101
|
+
throw new ExecutionLimitError('deadline', 'Agent deadline expired.');
|
|
102
|
+
const saved = this.ledger.read(this.cwd);
|
|
103
|
+
if (saved.projection.manifestHash !== this.expectedHash)
|
|
104
|
+
throw new ExecutionLimitError('conflict', 'Execution contract changed.');
|
|
105
|
+
if (saved.projection.exceeded)
|
|
106
|
+
throw new ExecutionLimitError('budget', 'Provider usage exceeded its reservation; further execution is stopped.');
|
|
107
|
+
const project = new ProjectSpendLedger(projectBudgetPath(this.cwd)).read(), caps = getBudgetCaps();
|
|
108
|
+
if (project.blocked || caps.maxCostPerProject !== undefined && project.spentUsd > caps.maxCostPerProject || caps.maxTokensPerRun !== undefined && saved.projection.spent.tokens > caps.maxTokensPerRun || caps.maxCostPerRun !== undefined && saved.projection.spent.costNanos > costCapNanos(caps.maxCostPerRun))
|
|
109
|
+
throw new ExecutionLimitError('budget', 'Current project or run policy no longer permits execution.');
|
|
110
|
+
}
|
|
111
|
+
budget(route, messages, tools, streaming, signal, onEvent) {
|
|
112
|
+
this.assertActive(signal);
|
|
113
|
+
route = structuredClone(route);
|
|
114
|
+
const billing = readBillingEvidence(route, this.manifest.project.root);
|
|
115
|
+
const base = providerQuote(route, messages, tools, streaming, this.maxOutputTokens, billing, undefined, this.measuredInputReservation);
|
|
116
|
+
const projectLedger = new ProjectSpendLedger(projectBudgetPath(this.cwd));
|
|
117
|
+
return {
|
|
118
|
+
...(base.provider === 'openrouter' ? { priceCeiling: Object.freeze({ input: base.inputPrice, output: base.outputPrice }) } : {}),
|
|
119
|
+
...(billing?.profile.admission === 'provider-count-v1' ? { inputCounting: 'anthropic-count-tokens' } : {}),
|
|
120
|
+
reserve: async (actual) => {
|
|
121
|
+
this.assertActive(signal);
|
|
122
|
+
if (actual.provider !== base.provider || actual.model !== base.model || actual.target !== base.target || actual.maxOutputTokens !== base.outputTokens)
|
|
123
|
+
throw new ExecutionLimitError('authority', 'Provider attempt does not match its discovered budget quote.');
|
|
124
|
+
if (base.provider === 'openrouter' && (actual.priceCeiling?.input !== base.inputPrice || actual.priceCeiling?.output !== base.outputPrice))
|
|
125
|
+
throw new ExecutionLimitError('authority', 'Provider price ceiling changed after budget admission.');
|
|
126
|
+
if (billing && ((billing.profile.admission === 'provider-count-v1' && !actual.inputCount) || readBillingEvidence(route, this.manifest.project.root)?.hash !== billing.hash))
|
|
127
|
+
throw new ExecutionLimitError('authority', 'Billing admission was revoked or omitted its count.');
|
|
128
|
+
const quote = providerQuote(route, messages, tools, streaming, this.maxOutputTokens, billing, actual.inputCount, this.measuredInputReservation);
|
|
129
|
+
const id = randomUUID(), caps = getBudgetCaps();
|
|
130
|
+
await projectLedger.reserve(id, this.manifest.runId, quote.costNanos, caps.maxCostPerProject === undefined ? Number.MAX_SAFE_INTEGER : costCapNanos(caps.maxCostPerProject), signal);
|
|
131
|
+
const limits = { ...(caps.maxTokensPerRun === undefined ? {} : { tokens: caps.maxTokensPerRun }), ...(caps.maxCostPerRun === undefined ? {} : { costNanos: costCapNanos(caps.maxCostPerRun) }) };
|
|
132
|
+
let state;
|
|
133
|
+
try {
|
|
134
|
+
state = await this.ledger.reserve(this.cwd, this.expectedHash, { id, agentId: this.agentId, ...quote, limits, ...(this.attribution ? { attribution: this.attribution } : {}) }, signal);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
await projectLedger.settle(id, 0);
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
onEvent?.({ requestId: id, stage: 'reserved', revision: state.revision, ...state.spent });
|
|
141
|
+
this.assertActive(signal);
|
|
142
|
+
if (billing && readBillingEvidence(route, this.manifest.project.root)?.hash !== billing.hash)
|
|
143
|
+
throw new ExecutionLimitError('authority', 'Billing admission was revoked while committing its reservation.');
|
|
144
|
+
return id;
|
|
145
|
+
},
|
|
146
|
+
settle: async (id, outcome, usage) => {
|
|
147
|
+
const valid = !usage || [usage.inputTokens, usage.outputTokens].every(n => Number.isSafeInteger(n) && n >= 0 && n <= 100000000);
|
|
148
|
+
const state = await this.ledger.settle(this.cwd, this.expectedHash, { requestId: id, outcome: valid ? outcome : 'invalid-usage', ...(usage && valid ? { usage } : {}) });
|
|
149
|
+
const quote = state.requests[id].reservation;
|
|
150
|
+
await projectLedger.settle(id, outcome === 'success' && valid && usage ? requestCostNanos(usage.inputTokens, usage.outputTokens, quote.inputPrice, quote.outputPrice) : null, state.exceeded);
|
|
151
|
+
onEvent?.({ requestId: id, stage: state.requests[id].state, revision: state.revision, ...state.spent });
|
|
152
|
+
if (state.exceeded)
|
|
153
|
+
throw new ExecutionLimitError('budget', 'Provider reported usage beyond the reserved bound; execution stopped.');
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/execution/guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAC,OAAO,EAAC,QAAQ,EAAC,OAAO,EAAC,UAAU,EAAC,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAIpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,cAAc,EAAE,sBAAsB,EAAE,OAAO,EAAC,kCAAkC,EAAE,MAAM,gBAAgB,CAAC;AAC9J,OAAO,EAAqB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAA0B,MAAM,YAAY,CAAC;AACzE,OAAO,EAAC,aAAa,EAAC,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAC,aAAa,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACtD,OAAO,EAAC,0BAA0B,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,WAAW,EAAC,gBAAgB,EAAuB,MAAM,mBAAmB,CAAC;AACrF,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AACjD,OAAO,EAAC,0BA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AAG,KAAK,CAAC,QAAQ;oBAAC,MAAM,IAAI,mBAAmB,CAAC,QAAQ,EAAC,uEAAuE,CAAC,CAAC;YACpI,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './authority.js';
|
|
3
|
+
export * from './ledger.js';
|
|
4
|
+
export * from './guard.js';
|
|
5
|
+
export * from './files.js';
|
|
6
|
+
export * from './project-spend.js';
|
|
7
|
+
export * from './quote.js';
|
|
8
|
+
export * from './billing.js';
|
|
9
|
+
export * from './child-grants.js';
|
|
10
|
+
export * from './writer-recovery.js';
|
|
11
|
+
export * from './attribution.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/execution/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './authority.js';
|
|
3
|
+
export * from './ledger.js';
|
|
4
|
+
export * from './guard.js';
|
|
5
|
+
export * from './files.js';
|
|
6
|
+
export * from './project-spend.js';
|
|
7
|
+
export * from './quote.js';
|
|
8
|
+
export * from './billing.js';
|
|
9
|
+
export * from './child-grants.js';
|
|
10
|
+
export * from './writer-recovery.js';
|
|
11
|
+
export * from './attribution.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/execution/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ExecutionManifest, type RequestReservation, type RequestSettlement, type ReservationEvent, type ReservationProjection, type ChildGrant } from './types.js';
|
|
2
|
+
export declare const MAX_RESERVATION_EVENTS = 10000, MAX_RESERVATION_BYTES: number;
|
|
3
|
+
export declare function requestCostNanos(input: number, output: number, inputPrice: number, outputPrice: number): number;
|
|
4
|
+
/** Pure replay includes unresolved reservations in every ancestor's spend. */
|
|
5
|
+
export declare function replayReservations(input: ExecutionManifest, events: ReservationEvent[]): ReservationProjection;
|
|
6
|
+
export declare class ReservationLedger {
|
|
7
|
+
private readonly now;
|
|
8
|
+
readonly root: string;
|
|
9
|
+
constructor(root: string, now?: () => number);
|
|
10
|
+
/** Explicit creation only. A missing journal inside an existing directory never resets spend. */
|
|
11
|
+
create(input: ExecutionManifest, signal?: AbortSignal): ReservationProjection;
|
|
12
|
+
read(cwd: string): {
|
|
13
|
+
manifest: ExecutionManifest;
|
|
14
|
+
events: ReservationEvent[];
|
|
15
|
+
projection: ReservationProjection;
|
|
16
|
+
};
|
|
17
|
+
reserve(cwd: string, expectedManifest: string, value: RequestReservation, signal?: AbortSignal): Promise<ReservationProjection>;
|
|
18
|
+
grantChildren(cwd: string, expectedManifest: string, grant: ChildGrant, signal?: AbortSignal, beforeCommit?: () => void): Promise<ReservationProjection>;
|
|
19
|
+
/** Settlement is allowed after cancellation/deadline so known spend can still be recorded. */
|
|
20
|
+
settle(cwd: string, expectedManifest: string, value: RequestSettlement): Promise<ReservationProjection>;
|
|
21
|
+
private append;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=ledger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/execution/ledger.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,KAAK,qBAAqB,EAAC,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAM7L,eAAO,MAAM,sBAAsB,QAAQ,EAAE,qBAAqB,QAAmB,CAAC;AAEtF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAK/G;AA8BD,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,qBAAqB,CA0C9G;AA+BD,qBAAa,iBAAiB;IAEJ,OAAO,CAAC,QAAQ,CAAC,GAAG;IAD5C,QAAQ,CAAC,IAAI,EAAC,MAAM,CAAC;IACrB,YAAY,IAAI,EAAC,MAAM,EAAkB,GAAG,eAAS,EAA2B;IAChF,iGAAiG;IACjG,MAAM,CAAC,KAAK,EAAC,iBAAiB,EAAC,MAAM,CAAC,EAAC,WAAW,GAAE,qBAAqB,CAUxE;IACD,IAAI,CAAC,GAAG,EAAC,MAAM,GAAE;QAAC,QAAQ,EAAC,iBAAiB,CAAC;QAAA,MAAM,EAAC,gBAAgB,EAAE,CAAC;QAAA,UAAU,EAAC,qBAAqB,CAAA;KAAC,CAGvG;IACK,OAAO,CAAC,GAAG,EAAC,MAAM,EAAC,gBAAgB,EAAC,MAAM,EAAC,KAAK,EAAC,kBAAkB,EAAC,MAAM,CAAC,EAAC,WAAW,GAAE,OAAO,CAAC,qBAAqB,CAAC,CAE5H;IACK,aAAa,CAAC,GAAG,EAAC,MAAM,EAAC,gBAAgB,EAAC,MAAM,EAAC,KAAK,EAAC,UAAU,EAAC,MAAM,CAAC,EAAC,WAAW,EAAC,YAAY,CAAC,EAAC,MAAI,IAAI,GAAE,OAAO,CAAC,qBAAqB,CAAC,CAEjJ;IACD,8FAA8F;IACxF,MAAM,CAAC,GAAG,EAAC,MAAM,EAAC,gBAAgB,EAAC,MAAM,EAAC,KAAK,EAAC,iBAAiB,GAAE,OAAO,CAAC,qBAAqB,CAAC,CAEtG;YACa,MAAM;CAyBrB"}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/** Reservations are charged before dispatch; unknown outcomes never restore capacity. */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { randomUUID } from 'node:crypto';
|
|
5
|
+
import { canonicalJson, canonicalPath, digest } from '../approvals/index.js';
|
|
6
|
+
import { cancellableDelay, throwIfCancelled } from '../cancellation.js';
|
|
7
|
+
import { accountLineage, checkExecutionIdentity, hex, identifier, integer, invalid, manifestHash, shape, uuid, validateExecutionManifest } from './authority.js';
|
|
8
|
+
import { ExecutionLimitError } from './types.js';
|
|
9
|
+
import { validateChildGrant, applyChildGrant, assertChildCapacity, effectiveExecutionManifest } from './child-grants.js';
|
|
10
|
+
import { validateQuoteEvidence, fullContextTerms } from './billing.js';
|
|
11
|
+
import { recoverDeadWriterLock } from './writer-recovery.js';
|
|
12
|
+
import { validateRequestAttribution } from './attribution.js';
|
|
13
|
+
export const MAX_RESERVATION_EVENTS = 10000, MAX_RESERVATION_BYTES = 16 * 1024 * 1024;
|
|
14
|
+
const unavailable = () => new ExecutionLimitError('unavailable', 'Execution budget history is unavailable or damaged; preserve it and restore a verified backup. No request was authorized.');
|
|
15
|
+
export function requestCostNanos(input, output, inputPrice, outputPrice) {
|
|
16
|
+
integer(input, 0, 100000000);
|
|
17
|
+
integer(output, 0, 100000000);
|
|
18
|
+
for (const price of [inputPrice, outputPrice])
|
|
19
|
+
if (!Number.isFinite(price) || price < 0 || price > 1000000)
|
|
20
|
+
invalid();
|
|
21
|
+
// Round each price up to a nano-dollar per token; never round a reservation down.
|
|
22
|
+
const nanos = input * Math.ceil(inputPrice * 1000) + output * Math.ceil(outputPrice * 1000);
|
|
23
|
+
integer(nanos);
|
|
24
|
+
return nanos;
|
|
25
|
+
}
|
|
26
|
+
function reservation(value) {
|
|
27
|
+
shape(value, ['id', 'agentId', 'provider', 'model', 'target', 'inputTokens', 'outputTokens', 'costNanos', 'inputPrice', 'outputPrice'], ['limits', 'quoteEvidence', 'attribution']);
|
|
28
|
+
if (!uuid(value.id) || !hex(value.target))
|
|
29
|
+
invalid();
|
|
30
|
+
identifier(value.agentId);
|
|
31
|
+
if (typeof value.provider !== 'string' || !/^[a-z][a-z0-9-]{0,63}$/.test(value.provider) || typeof value.model !== 'string' || !value.model || value.model.length > 256 || /[\x00-\x1f\x7f]/.test(value.model))
|
|
32
|
+
invalid();
|
|
33
|
+
integer(value.inputTokens, 1, 100000000);
|
|
34
|
+
integer(value.outputTokens, 1, 100000000);
|
|
35
|
+
integer(value.costNanos);
|
|
36
|
+
if (value.costNanos !== requestCostNanos(value.inputTokens, value.outputTokens, value.inputPrice, value.outputPrice))
|
|
37
|
+
invalid();
|
|
38
|
+
if (value.quoteEvidence !== undefined) {
|
|
39
|
+
const proof = validateQuoteEvidence(value.quoteEvidence), p = proof.profile;
|
|
40
|
+
if (value.provider !== p.provider || value.model !== p.model || value.target !== p.target || Number(value.inputPrice) < p.prices.input || Number(value.outputPrice) < p.prices.output)
|
|
41
|
+
invalid();
|
|
42
|
+
if (proof.version === 1) {
|
|
43
|
+
if (value.inputTokens < proof.count.inputTokens || value.inputTokens > proof.count.inputTokens * 2 + 1024)
|
|
44
|
+
invalid();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const terms = fullContextTerms(proof);
|
|
48
|
+
if ((proof.measuredInput !== true && value.inputTokens !== terms.inputTokens) || value.inputTokens < 1 || value.inputTokens > terms.inputTokens || value.outputTokens > terms.maxOutputTokens || value.inputPrice !== terms.inputPrice || value.outputPrice !== terms.outputPrice)
|
|
49
|
+
invalid();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (value.limits !== undefined) {
|
|
53
|
+
shape(value.limits, [], ['tokens', 'costNanos']);
|
|
54
|
+
for (const cap of Object.values(value.limits))
|
|
55
|
+
integer(cap);
|
|
56
|
+
}
|
|
57
|
+
if (value.attribution !== undefined)
|
|
58
|
+
validateRequestAttribution(value.attribution);
|
|
59
|
+
}
|
|
60
|
+
function settlement(value) {
|
|
61
|
+
shape(value, ['requestId', 'outcome'], ['usage']);
|
|
62
|
+
if (!uuid(value.requestId) || !['success', 'error', 'cancelled', 'invalid-usage'].includes(String(value.outcome)))
|
|
63
|
+
invalid();
|
|
64
|
+
if (value.usage !== undefined) {
|
|
65
|
+
shape(value.usage, ['inputTokens', 'outputTokens']);
|
|
66
|
+
integer(value.usage.inputTokens, 0, 100000000);
|
|
67
|
+
integer(value.usage.outputTokens, 0, 100000000);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function validateEvent(value) {
|
|
71
|
+
shape(value, ['version', 'id', 'at', 'previous', 'change', 'hash']);
|
|
72
|
+
if (![1, 2, 3, 4].includes(value.version) || !uuid(value.id) || !hex(value.previous) || !hex(value.hash))
|
|
73
|
+
invalid();
|
|
74
|
+
integer(value.at, 1, 8640000000000000);
|
|
75
|
+
shape(value.change, ['type'], ['reservation', 'settlement', 'grant']);
|
|
76
|
+
if (value.change.type === 'reserve') {
|
|
77
|
+
shape(value.change, ['type', 'reservation']);
|
|
78
|
+
reservation(value.change.reservation);
|
|
79
|
+
}
|
|
80
|
+
else if (value.change.type === 'settle') {
|
|
81
|
+
shape(value.change, ['type', 'settlement']);
|
|
82
|
+
settlement(value.change.settlement);
|
|
83
|
+
}
|
|
84
|
+
else if (value.change.type === 'child_grant') {
|
|
85
|
+
shape(value.change, ['type', 'grant']);
|
|
86
|
+
validateChildGrant(value.change.grant);
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
invalid();
|
|
90
|
+
const change = value.change;
|
|
91
|
+
if (value.version !== reservationVersion(change))
|
|
92
|
+
invalid();
|
|
93
|
+
const { hash, ...body } = value;
|
|
94
|
+
if (hash !== digest(canonicalJson(body)))
|
|
95
|
+
throw unavailable();
|
|
96
|
+
}
|
|
97
|
+
/** Pure replay includes unresolved reservations in every ancestor's spend. */
|
|
98
|
+
export function replayReservations(input, events) {
|
|
99
|
+
const base = validateExecutionManifest(input), initial = manifestHash(base);
|
|
100
|
+
let manifest = base;
|
|
101
|
+
if (!Array.isArray(events) || events.length > MAX_RESERVATION_EVENTS)
|
|
102
|
+
throw unavailable();
|
|
103
|
+
const state = { version: 1, runId: manifest.runId, manifestHash: initial, revision: initial, spent: { tokens: 0, costNanos: 0 }, accounts: {}, requests: {}, exceeded: false };
|
|
104
|
+
for (const account of manifest.accounts)
|
|
105
|
+
Object.defineProperty(state.accounts, account.id, { value: { tokens: 0, costNanos: 0 }, enumerable: true });
|
|
106
|
+
const ids = new Set();
|
|
107
|
+
let at = manifest.createdAt;
|
|
108
|
+
const apply = (agentId, tokens, costNanos) => {
|
|
109
|
+
state.spent.tokens += tokens;
|
|
110
|
+
state.spent.costNanos += costNanos;
|
|
111
|
+
for (const account of accountLineage(manifest, agentId)) {
|
|
112
|
+
state.accounts[account.id].tokens += tokens;
|
|
113
|
+
state.accounts[account.id].costNanos += costNanos;
|
|
114
|
+
}
|
|
115
|
+
integer(state.spent.tokens);
|
|
116
|
+
integer(state.spent.costNanos);
|
|
117
|
+
};
|
|
118
|
+
for (const event of events) {
|
|
119
|
+
validateEvent(event);
|
|
120
|
+
if (ids.has(event.id) || event.previous !== state.revision || event.at < at)
|
|
121
|
+
throw unavailable();
|
|
122
|
+
ids.add(event.id);
|
|
123
|
+
at = event.at;
|
|
124
|
+
if (event.change.type === 'child_grant') {
|
|
125
|
+
manifest = applyChildGrant(base, manifest, state, { grant: event.change.grant, eventId: event.id, eventHash: event.hash, at: event.at });
|
|
126
|
+
}
|
|
127
|
+
else if (event.change.type === 'reserve') {
|
|
128
|
+
const next = event.change.reservation, lineage = accountLineage(manifest, next.agentId), tokens = next.inputTokens + next.outputTokens;
|
|
129
|
+
if (state.exceeded || Object.hasOwn(state.requests, next.id) || event.at >= manifest.deadline || lineage.some(a => event.at >= a.deadline))
|
|
130
|
+
throw new ExecutionLimitError('deadline', 'Execution cannot admit this request after a deadline or budget violation.');
|
|
131
|
+
if (state.spent.tokens + tokens > manifest.tokenBudget || state.spent.costNanos + next.costNanos > manifest.costBudgetNanos ||
|
|
132
|
+
next.limits?.tokens !== undefined && state.spent.tokens + tokens > next.limits.tokens || next.limits?.costNanos !== undefined && state.spent.costNanos + next.costNanos > next.limits.costNanos ||
|
|
133
|
+
lineage.some(a => state.accounts[a.id].tokens + tokens > a.tokenBudget || state.accounts[a.id].costNanos + next.costNanos > a.costBudgetNanos))
|
|
134
|
+
throw new ExecutionLimitError('budget', 'Request reservation exceeds the available agent, ancestor or run budget.');
|
|
135
|
+
if (state.childGrants?.length)
|
|
136
|
+
assertChildCapacity(manifest, state, next.agentId, tokens, next.costNanos);
|
|
137
|
+
apply(next.agentId, tokens, next.costNanos);
|
|
138
|
+
state.requests[next.id] = { reservation: structuredClone(next), state: 'pending', ...(next.attribution ? { accounted: { tokens, costNanos: next.costNanos } } : {}) };
|
|
139
|
+
if (next.attribution)
|
|
140
|
+
state.version = 3;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
const result = event.change.settlement, entry = state.requests[result.requestId];
|
|
144
|
+
if (!entry || entry.state !== 'pending')
|
|
145
|
+
throw new ExecutionLimitError('conflict', 'Request was already settled or was never reserved.');
|
|
146
|
+
if (result.outcome === 'invalid-usage') {
|
|
147
|
+
entry.state = 'exceeded';
|
|
148
|
+
state.exceeded = true;
|
|
149
|
+
}
|
|
150
|
+
else if (result.outcome !== 'success' || !result.usage)
|
|
151
|
+
entry.state = 'unknown';
|
|
152
|
+
else {
|
|
153
|
+
const r = entry.reservation, usage = result.usage, cost = requestCostNanos(usage.inputTokens, usage.outputTokens, r.inputPrice, r.outputPrice);
|
|
154
|
+
if (usage.inputTokens > r.inputTokens || usage.outputTokens > r.outputTokens || cost > r.costNanos) {
|
|
155
|
+
entry.state = 'exceeded';
|
|
156
|
+
state.exceeded = true;
|
|
157
|
+
if (entry.accounted)
|
|
158
|
+
entry.accounted = { tokens: Math.max(usage.inputTokens + usage.outputTokens, r.inputTokens + r.outputTokens), costNanos: Math.max(cost, r.costNanos) };
|
|
159
|
+
apply(r.agentId, Math.max(usage.inputTokens + usage.outputTokens, r.inputTokens + r.outputTokens) - (r.inputTokens + r.outputTokens), Math.max(cost, r.costNanos) - r.costNanos);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
entry.state = 'settled';
|
|
163
|
+
if (entry.accounted)
|
|
164
|
+
entry.accounted = { tokens: usage.inputTokens + usage.outputTokens, costNanos: cost };
|
|
165
|
+
apply(r.agentId, usage.inputTokens + usage.outputTokens - r.inputTokens - r.outputTokens, cost - r.costNanos);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
state.revision = event.hash;
|
|
170
|
+
}
|
|
171
|
+
return state;
|
|
172
|
+
}
|
|
173
|
+
function reservationVersion(change) {
|
|
174
|
+
return change.type === 'reserve' && change.reservation.quoteEvidence?.version === 2 ? 4 : change.type === 'reserve' && change.reservation.attribution ? 3 : change.type === 'child_grant' ? 2 : 1;
|
|
175
|
+
}
|
|
176
|
+
function decode(raw) {
|
|
177
|
+
let value;
|
|
178
|
+
try {
|
|
179
|
+
value = JSON.parse(raw);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
throw unavailable();
|
|
183
|
+
}
|
|
184
|
+
shape(value, ['version', 'manifest', 'events', 'hash']);
|
|
185
|
+
if (value.version !== 1 || !Array.isArray(value.events) || value.events.length > MAX_RESERVATION_EVENTS || !hex(value.hash))
|
|
186
|
+
throw unavailable();
|
|
187
|
+
const manifest = validateExecutionManifest(value.manifest), events = value.events;
|
|
188
|
+
for (const event of events)
|
|
189
|
+
validateEvent(event);
|
|
190
|
+
if (digest(canonicalJson({ manifest: manifestHash(manifest), events: events.map(event => event.hash) })) !== value.hash)
|
|
191
|
+
throw unavailable();
|
|
192
|
+
return { version: 1, manifest, events, hash: value.hash };
|
|
193
|
+
}
|
|
194
|
+
function encode(manifest, events) {
|
|
195
|
+
const raw = JSON.stringify({ version: 1, manifest, events, hash: digest(canonicalJson({ manifest: manifestHash(manifest), events: events.map(event => event.hash) })) });
|
|
196
|
+
if (Buffer.byteLength(raw) > MAX_RESERVATION_BYTES)
|
|
197
|
+
throw new ExecutionLimitError('limit', 'Budget history reached its byte limit; existing reservations remain charged.');
|
|
198
|
+
return raw;
|
|
199
|
+
}
|
|
200
|
+
function directory(path) {
|
|
201
|
+
const stat = fs.lstatSync(path);
|
|
202
|
+
if (!stat.isDirectory() || stat.isSymbolicLink() || stat.mode & 0o077 || fs.realpathSync(path) !== path)
|
|
203
|
+
throw unavailable();
|
|
204
|
+
return stat;
|
|
205
|
+
}
|
|
206
|
+
function sameDirectory(path, before) { const current = directory(path); if (current.dev !== before.dev || current.ino !== before.ino)
|
|
207
|
+
throw new ExecutionLimitError('conflict', 'Budget directory changed during the operation.'); }
|
|
208
|
+
function read(file) {
|
|
209
|
+
let fd;
|
|
210
|
+
try {
|
|
211
|
+
fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
throw unavailable();
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
const stat = fs.fstatSync(fd);
|
|
218
|
+
if (!stat.isFile() || stat.mode & 0o077 || stat.size > MAX_RESERVATION_BYTES)
|
|
219
|
+
throw unavailable();
|
|
220
|
+
const buffer = Buffer.alloc(stat.size + 1);
|
|
221
|
+
let size = 0, n;
|
|
222
|
+
while (size < buffer.length && (n = fs.readSync(fd, buffer, size, buffer.length - size, null)) > 0)
|
|
223
|
+
size += n;
|
|
224
|
+
if (size !== stat.size)
|
|
225
|
+
throw unavailable();
|
|
226
|
+
return buffer.subarray(0, size).toString('utf8');
|
|
227
|
+
}
|
|
228
|
+
finally {
|
|
229
|
+
fs.closeSync(fd);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function writeNew(file, raw) { const fd = fs.openSync(file, 'wx', 0o600); try {
|
|
233
|
+
fs.writeFileSync(fd, raw);
|
|
234
|
+
fs.fsyncSync(fd);
|
|
235
|
+
}
|
|
236
|
+
finally {
|
|
237
|
+
fs.closeSync(fd);
|
|
238
|
+
} }
|
|
239
|
+
function syncDir(path) { const fd = fs.openSync(path, 'r'); try {
|
|
240
|
+
fs.fsyncSync(fd);
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
fs.closeSync(fd);
|
|
244
|
+
} }
|
|
245
|
+
export class ReservationLedger {
|
|
246
|
+
now;
|
|
247
|
+
root;
|
|
248
|
+
constructor(root, now = Date.now) {
|
|
249
|
+
this.now = now;
|
|
250
|
+
this.root = resolve(root);
|
|
251
|
+
}
|
|
252
|
+
/** Explicit creation only. A missing journal inside an existing directory never resets spend. */
|
|
253
|
+
create(input, signal) {
|
|
254
|
+
throwIfCancelled(signal);
|
|
255
|
+
const manifest = validateExecutionManifest(input);
|
|
256
|
+
checkExecutionIdentity(manifest, manifest.project.root);
|
|
257
|
+
if (this.now() >= manifest.deadline)
|
|
258
|
+
throw new ExecutionLimitError('deadline', 'Run deadline expired.');
|
|
259
|
+
if (canonicalPath(this.root) !== this.root)
|
|
260
|
+
throw unavailable();
|
|
261
|
+
// The caller owns creation of the private run directory; never create arbitrary ancestors.
|
|
262
|
+
directory(dirname(this.root));
|
|
263
|
+
try {
|
|
264
|
+
fs.mkdirSync(this.root, { mode: 0o700 });
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (error.code !== 'EEXIST')
|
|
268
|
+
throw error;
|
|
269
|
+
const existing = this.read(manifest.project.root);
|
|
270
|
+
if (existing.projection.manifestHash !== manifestHash(manifest))
|
|
271
|
+
throw new ExecutionLimitError('conflict', 'Budget history belongs to another execution contract.');
|
|
272
|
+
return existing.projection;
|
|
273
|
+
}
|
|
274
|
+
const before = directory(this.root);
|
|
275
|
+
throwIfCancelled(signal);
|
|
276
|
+
writeNew(join(this.root, 'history.json'), encode(manifest, []));
|
|
277
|
+
sameDirectory(this.root, before);
|
|
278
|
+
syncDir(this.root);
|
|
279
|
+
syncDir(dirname(this.root));
|
|
280
|
+
return replayReservations(manifest, []);
|
|
281
|
+
}
|
|
282
|
+
read(cwd) {
|
|
283
|
+
directory(this.root);
|
|
284
|
+
const journal = decode(read(join(this.root, 'history.json')));
|
|
285
|
+
checkExecutionIdentity(journal.manifest, cwd);
|
|
286
|
+
return { ...journal, projection: replayReservations(journal.manifest, journal.events) };
|
|
287
|
+
}
|
|
288
|
+
async reserve(cwd, expectedManifest, value, signal) {
|
|
289
|
+
reservation(value);
|
|
290
|
+
return this.append(cwd, expectedManifest, { type: 'reserve', reservation: structuredClone(value) }, signal);
|
|
291
|
+
}
|
|
292
|
+
async grantChildren(cwd, expectedManifest, grant, signal, beforeCommit) {
|
|
293
|
+
validateChildGrant(grant);
|
|
294
|
+
return this.append(cwd, expectedManifest, { type: 'child_grant', grant: structuredClone(grant) }, signal, beforeCommit);
|
|
295
|
+
}
|
|
296
|
+
/** Settlement is allowed after cancellation/deadline so known spend can still be recorded. */
|
|
297
|
+
async settle(cwd, expectedManifest, value) {
|
|
298
|
+
settlement(value);
|
|
299
|
+
return this.append(cwd, expectedManifest, { type: 'settle', settlement: structuredClone(value) });
|
|
300
|
+
}
|
|
301
|
+
async append(cwd, expectedManifest, change, signal, beforeCommit) {
|
|
302
|
+
throwIfCancelled(signal);
|
|
303
|
+
const before = directory(this.root), file = join(this.root, 'history.json'), lock = join(this.root, 'writer.lock');
|
|
304
|
+
let fd;
|
|
305
|
+
for (let attempt = 0; attempt <= 50; attempt++) {
|
|
306
|
+
throwIfCancelled(signal);
|
|
307
|
+
sameDirectory(this.root, before);
|
|
308
|
+
try {
|
|
309
|
+
fd = fs.openSync(lock, 'wx', 0o600);
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
if (error.code !== 'EEXIST')
|
|
314
|
+
throw unavailable();
|
|
315
|
+
recoverDeadWriterLock(lock);
|
|
316
|
+
if (attempt === 50)
|
|
317
|
+
throw new ExecutionLimitError('locked', 'Budget writer is busy; no request was authorized.');
|
|
318
|
+
await cancellableDelay(10, signal);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const identity = fs.fstatSync(fd);
|
|
322
|
+
let temp;
|
|
323
|
+
try {
|
|
324
|
+
fs.writeFileSync(fd, String(process.pid));
|
|
325
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
326
|
+
throwIfCancelled(signal);
|
|
327
|
+
sameDirectory(this.root, before);
|
|
328
|
+
const raw = read(file), journal = decode(raw), current = replayReservations(journal.manifest, journal.events);
|
|
329
|
+
checkExecutionIdentity(journal.manifest, cwd);
|
|
330
|
+
if (current.manifestHash !== expectedManifest)
|
|
331
|
+
throw new ExecutionLimitError('conflict', 'Execution contract changed; request denied.');
|
|
332
|
+
if (change.type === 'child_grant') {
|
|
333
|
+
const prior = current.childGrants?.find(r => r.grant.id === change.grant.id);
|
|
334
|
+
if (prior) {
|
|
335
|
+
if (canonicalJson(prior.grant) !== canonicalJson(change.grant))
|
|
336
|
+
throw new ExecutionLimitError('conflict', 'Child grant identity already belongs to another proposal.');
|
|
337
|
+
beforeCommit?.();
|
|
338
|
+
throwIfCancelled(signal);
|
|
339
|
+
return current;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Leave enough room to settle every pending reservation.
|
|
343
|
+
const pending = Object.values(current.requests).filter(r => r.state === 'pending').length;
|
|
344
|
+
if (journal.events.length + (change.type !== 'settle' ? pending + 2 : 1) > MAX_RESERVATION_EVENTS)
|
|
345
|
+
throw new ExecutionLimitError('limit', 'Budget history reached its event limit; pending reservations remain charged.');
|
|
346
|
+
const body = { version: reservationVersion(change), id: randomUUID(), at: Math.max(this.now(), journal.events.at(-1)?.at ?? journal.manifest.createdAt), previous: current.revision, change };
|
|
347
|
+
const event = { ...body, hash: digest(canonicalJson(body)) }, events = [...journal.events, event], next = replayReservations(journal.manifest, events), output = encode(journal.manifest, events);
|
|
348
|
+
temp = join(this.root, `${randomUUID()}.tmp`);
|
|
349
|
+
writeNew(temp, output);
|
|
350
|
+
throwIfCancelled(signal);
|
|
351
|
+
sameDirectory(this.root, before);
|
|
352
|
+
checkExecutionIdentity(journal.manifest, cwd);
|
|
353
|
+
const effective = effectiveExecutionManifest(journal.manifest, next);
|
|
354
|
+
if (change.type === 'reserve' && this.now() >= Math.min(effective.deadline, ...accountLineage(effective, change.reservation.agentId).map(a => a.deadline)) || change.type === 'child_grant' && change.grant.accounts.some(a => this.now() >= a.deadline))
|
|
355
|
+
throw new ExecutionLimitError('deadline', 'Agent deadline expired before reservation or grant commit.');
|
|
356
|
+
if (read(file) !== raw)
|
|
357
|
+
throw new ExecutionLimitError('conflict', 'Budget history changed before commit.');
|
|
358
|
+
beforeCommit?.();
|
|
359
|
+
throwIfCancelled(signal);
|
|
360
|
+
fs.renameSync(temp, file);
|
|
361
|
+
temp = undefined;
|
|
362
|
+
syncDir(this.root);
|
|
363
|
+
return next;
|
|
364
|
+
}
|
|
365
|
+
finally {
|
|
366
|
+
fs.closeSync(fd);
|
|
367
|
+
try {
|
|
368
|
+
sameDirectory(this.root, before);
|
|
369
|
+
if (temp)
|
|
370
|
+
fs.unlinkSync(temp);
|
|
371
|
+
const current = fs.lstatSync(lock);
|
|
372
|
+
if (current.ino === identity.ino && current.dev === identity.dev)
|
|
373
|
+
fs.unlinkSync(lock);
|
|
374
|
+
}
|
|
375
|
+
catch { /* Preserve foreign directories and locks. */ }
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
//# sourceMappingURL=ledger.js.map
|