voratiq 0.1.0-beta.2 → 0.1.0-beta.21
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 +41 -29
- package/dist/agents/launch/chat.d.ts +23 -0
- package/dist/agents/launch/chat.js +44 -0
- package/dist/agents/launch/environment.d.ts +8 -0
- package/dist/{commands/run/agents/workspace-prep.js → agents/launch/environment.js} +5 -27
- package/dist/agents/launch/prompt.d.ts +6 -0
- package/dist/agents/launch/prompt.js +12 -0
- package/dist/agents/launch/provider-state.d.ts +39 -0
- package/dist/agents/launch/provider-state.js +103 -0
- package/dist/agents/runtime/auth.d.ts +27 -0
- package/dist/agents/runtime/auth.js +72 -0
- package/dist/agents/runtime/chat.d.ts +5 -0
- package/dist/agents/runtime/chat.js +7 -0
- package/dist/agents/runtime/errors.d.ts +27 -0
- package/dist/agents/runtime/errors.js +51 -0
- package/dist/{commands/run/agents → agents/runtime}/failures.d.ts +0 -1
- package/dist/agents/runtime/failures.js +136 -0
- package/dist/agents/runtime/harness.d.ts +2 -0
- package/dist/agents/runtime/harness.js +119 -0
- package/dist/{commands/run/agents/sandbox-launcher.d.ts → agents/runtime/launcher.d.ts} +18 -6
- package/dist/{commands/run/agents/sandbox-launcher.js → agents/runtime/launcher.js} +17 -39
- package/dist/{commands/run/agents/workspace-prep.d.ts → agents/runtime/manifest.d.ts} +6 -6
- package/dist/agents/runtime/manifest.js +34 -0
- package/dist/agents/runtime/policy.d.ts +32 -0
- package/dist/agents/runtime/policy.js +240 -0
- package/dist/agents/runtime/registry.d.ts +4 -0
- package/dist/agents/runtime/registry.js +54 -0
- package/dist/{commands/run → agents/runtime}/sandbox.d.ts +8 -2
- package/dist/{commands/run → agents/runtime}/sandbox.js +28 -67
- package/dist/agents/runtime/shim/run-agent-shim.d.ts +1 -0
- package/dist/agents/runtime/shim/run-agent-shim.js +276 -0
- package/dist/agents/runtime/types.d.ts +91 -0
- package/dist/{commands/run/agents → agents/runtime}/watchdog.d.ts +4 -3
- package/dist/{commands/run/agents → agents/runtime}/watchdog.js +155 -26
- package/dist/auth/providers/codex.js +7 -2
- package/dist/auth/providers/gemini.js +14 -6
- package/dist/auth/providers/types.d.ts +1 -0
- package/dist/auth/providers/utils.d.ts +0 -1
- package/dist/auth/providers/utils.js +1 -49
- package/dist/bin.js +369 -71
- package/dist/cli/apply.d.ts +4 -0
- package/dist/cli/apply.js +28 -9
- package/dist/cli/auto.d.ts +32 -0
- package/dist/cli/auto.js +232 -0
- package/dist/cli/contract.d.ts +328 -0
- package/dist/cli/contract.js +480 -0
- package/dist/cli/errors.d.ts +3 -0
- package/dist/cli/errors.js +21 -3
- package/dist/cli/init.d.ts +5 -0
- package/dist/cli/init.js +34 -6
- package/dist/cli/list.d.ts +6 -4
- package/dist/cli/list.js +39 -16
- package/dist/cli/mcp.d.ts +2 -0
- package/dist/cli/mcp.js +16 -0
- package/dist/cli/message.d.ts +28 -0
- package/dist/cli/message.js +147 -0
- package/dist/cli/operator-envelope.d.ts +180 -0
- package/dist/cli/operator-envelope.js +425 -0
- package/dist/cli/output.d.ts +15 -1
- package/dist/cli/output.js +153 -5
- package/dist/cli/prune.d.ts +7 -3
- package/dist/cli/prune.js +57 -12
- package/dist/cli/reduce.d.ts +29 -0
- package/dist/cli/reduce.js +211 -0
- package/dist/cli/root-launcher.d.ts +4 -0
- package/dist/cli/root-launcher.js +15 -0
- package/dist/cli/run.d.ts +27 -1
- package/dist/cli/run.js +108 -16
- package/dist/cli/spec.d.ts +31 -0
- package/dist/cli/spec.js +180 -0
- package/dist/cli/verify.d.ts +35 -0
- package/dist/cli/verify.js +297 -0
- package/dist/commands/apply/command.d.ts +2 -0
- package/dist/commands/apply/command.js +145 -6
- package/dist/commands/apply/errors.d.ts +43 -4
- package/dist/commands/apply/errors.js +100 -22
- package/dist/commands/apply/types.d.ts +2 -1
- package/dist/commands/auto/command.d.ts +145 -0
- package/dist/commands/auto/command.js +433 -0
- package/dist/commands/auto/errors.d.ts +19 -0
- package/dist/commands/auto/errors.js +19 -0
- package/dist/commands/auto/validation.d.ts +14 -0
- package/dist/commands/auto/validation.js +90 -0
- package/dist/commands/fetch.d.ts +2 -2
- package/dist/commands/fetch.js +4 -4
- package/dist/commands/init/agents.d.ts +2 -1
- package/dist/commands/init/agents.js +66 -63
- package/dist/commands/init/command.js +300 -16
- package/dist/commands/init/types.d.ts +18 -7
- package/dist/commands/interactive/lifecycle.d.ts +15 -0
- package/dist/commands/interactive/lifecycle.js +141 -0
- package/dist/commands/list/command.d.ts +10 -3
- package/dist/commands/list/command.js +597 -40
- package/dist/commands/message/command.d.ts +23 -0
- package/dist/commands/message/command.js +215 -0
- package/dist/commands/message/errors.d.ts +9 -0
- package/dist/commands/message/errors.js +20 -0
- package/dist/commands/message/lifecycle.d.ts +14 -0
- package/dist/commands/message/lifecycle.js +128 -0
- package/dist/commands/prune/command.d.ts +2 -1
- package/dist/commands/prune/command.js +61 -10
- package/dist/commands/prune/errors.d.ts +1 -1
- package/dist/commands/prune/errors.js +5 -5
- package/dist/commands/prune/types.d.ts +21 -0
- package/dist/commands/reduce/command.d.ts +26 -0
- package/dist/commands/reduce/command.js +145 -0
- package/dist/commands/reduce/errors.d.ts +17 -0
- package/dist/commands/reduce/errors.js +32 -0
- package/dist/commands/reduce/targets.d.ts +11 -0
- package/dist/commands/reduce/targets.js +271 -0
- package/dist/commands/root-launcher/command.d.ts +31 -0
- package/dist/commands/root-launcher/command.js +233 -0
- package/dist/commands/run/command.d.ts +6 -1
- package/dist/commands/run/command.js +70 -40
- package/dist/commands/run/lifecycle.d.ts +7 -5
- package/dist/commands/run/lifecycle.js +45 -23
- package/dist/commands/run/record-init.d.ts +4 -1
- package/dist/commands/run/record-init.js +5 -2
- package/dist/commands/run/shim/run-agent-shim.d.ts +2 -1
- package/dist/commands/run/shim/run-agent-shim.js +4 -219
- package/dist/commands/run/validation.d.ts +2 -3
- package/dist/commands/run/validation.js +54 -25
- package/dist/commands/shared/max-parallel.d.ts +5 -0
- package/dist/commands/shared/max-parallel.js +15 -0
- package/dist/commands/shared/preview.d.ts +10 -0
- package/dist/commands/shared/preview.js +60 -0
- package/dist/commands/shared/resolve-reduction-competitors.d.ts +15 -0
- package/dist/commands/shared/resolve-reduction-competitors.js +13 -0
- package/dist/commands/shared/resolve-stage-competitors.d.ts +19 -0
- package/dist/commands/shared/resolve-stage-competitors.js +171 -0
- package/dist/commands/shared/session-id.d.ts +1 -0
- package/dist/commands/shared/session-id.js +1 -0
- package/dist/commands/spec/command.d.ts +22 -0
- package/dist/commands/spec/command.js +330 -0
- package/dist/commands/spec/errors.d.ts +11 -0
- package/dist/commands/spec/errors.js +23 -0
- package/dist/commands/verify/agents.d.ts +8 -0
- package/dist/commands/verify/agents.js +29 -0
- package/dist/commands/verify/command.d.ts +23 -0
- package/dist/commands/verify/command.js +168 -0
- package/dist/commands/verify/lifecycle.d.ts +14 -0
- package/dist/commands/verify/lifecycle.js +229 -0
- package/dist/commands/verify/max-parallel.d.ts +7 -0
- package/dist/commands/verify/max-parallel.js +15 -0
- package/dist/commands/verify/targets.d.ts +18 -0
- package/dist/commands/verify/targets.js +420 -0
- package/dist/competition/command-adapter.d.ts +35 -0
- package/dist/competition/command-adapter.js +20 -0
- package/dist/competition/core.d.ts +41 -0
- package/dist/competition/core.js +181 -0
- package/dist/competition/shared/extra-context.d.ts +14 -0
- package/dist/competition/shared/extra-context.js +100 -0
- package/dist/competition/shared/preflight.d.ts +11 -0
- package/dist/competition/shared/preflight.js +39 -0
- package/dist/competition/shared/prompt-helpers.d.ts +16 -0
- package/dist/competition/shared/prompt-helpers.js +27 -0
- package/dist/competition/shared/prune.d.ts +1 -0
- package/dist/competition/shared/prune.js +4 -0
- package/dist/competition/shared/sandbox-policy.d.ts +9 -0
- package/dist/competition/shared/sandbox-policy.js +7 -0
- package/dist/competition/shared/teardown.d.ts +36 -0
- package/dist/competition/shared/teardown.js +101 -0
- package/dist/configs/agents/defaults.d.ts +31 -2
- package/dist/configs/agents/defaults.js +346 -30
- package/dist/configs/agents/errors.js +14 -11
- package/dist/configs/agents/loader.d.ts +11 -1
- package/dist/configs/agents/loader.js +71 -4
- package/dist/configs/agents/types.js +2 -2
- package/dist/configs/environment/detect.js +9 -4
- package/dist/configs/environment/errors.js +4 -4
- package/dist/configs/environment/loader.d.ts +1 -1
- package/dist/configs/environment/loader.js +3 -3
- package/dist/configs/orchestration/bootstrap.d.ts +16 -0
- package/dist/configs/orchestration/bootstrap.js +122 -0
- package/dist/configs/orchestration/errors.d.ts +15 -0
- package/dist/configs/orchestration/errors.js +28 -0
- package/dist/configs/orchestration/loader.d.ts +9 -0
- package/dist/configs/orchestration/loader.js +148 -0
- package/dist/configs/orchestration/types.d.ts +102 -0
- package/dist/configs/orchestration/types.js +65 -0
- package/dist/configs/sandbox/defaults.js +14 -4
- package/dist/configs/sandbox/errors.d.ts +1 -1
- package/dist/configs/sandbox/errors.js +1 -1
- package/dist/configs/sandbox/loader.js +6 -4
- package/dist/configs/sandbox/schemas.js +4 -2
- package/dist/configs/settings/loader.d.ts +7 -0
- package/dist/configs/settings/loader.js +81 -0
- package/dist/configs/settings/types.d.ts +47 -0
- package/dist/configs/settings/types.js +23 -0
- package/dist/configs/verification/errors.d.ts +11 -0
- package/dist/configs/verification/errors.js +21 -0
- package/dist/configs/verification/loader.d.ts +8 -0
- package/dist/configs/verification/loader.js +43 -0
- package/dist/configs/verification/methods.d.ts +35 -0
- package/dist/configs/verification/methods.js +41 -0
- package/dist/configs/verification/programmatic-defaults.d.ts +10 -0
- package/dist/configs/verification/programmatic-defaults.js +42 -0
- package/dist/configs/verification/programmatic-detect.d.ts +10 -0
- package/dist/configs/{evals/detect.js → verification/programmatic-detect.js} +22 -33
- package/dist/configs/verification/types.d.ts +49 -0
- package/dist/configs/verification/types.js +45 -0
- package/dist/contracts/list.d.ts +207 -0
- package/dist/contracts/list.js +154 -0
- package/dist/domain/interactive/model/types.d.ts +104 -0
- package/dist/domain/interactive/model/types.js +83 -0
- package/dist/domain/interactive/persistence/adapter.d.ts +39 -0
- package/dist/domain/interactive/persistence/adapter.js +144 -0
- package/dist/domain/interactive/prompt.d.ts +3 -0
- package/dist/domain/interactive/prompt.js +7 -0
- package/dist/domain/message/competition/adapter.d.ts +36 -0
- package/dist/domain/message/competition/adapter.js +197 -0
- package/dist/domain/message/competition/prompt.d.ts +8 -0
- package/dist/domain/message/competition/prompt.js +29 -0
- package/dist/domain/message/model/mutators.d.ts +17 -0
- package/dist/domain/message/model/mutators.js +107 -0
- package/dist/domain/message/model/types.d.ts +100 -0
- package/dist/domain/message/model/types.js +87 -0
- package/dist/domain/message/persistence/adapter.d.ts +43 -0
- package/dist/domain/message/persistence/adapter.js +124 -0
- package/dist/domain/reduce/competition/adapter.d.ts +42 -0
- package/dist/domain/reduce/competition/adapter.js +826 -0
- package/dist/domain/reduce/competition/output-validation.d.ts +4 -0
- package/dist/domain/reduce/competition/output-validation.js +18 -0
- package/dist/domain/reduce/competition/prompt.d.ts +10 -0
- package/dist/domain/reduce/competition/prompt.js +96 -0
- package/dist/domain/reduce/competition/reduction.d.ts +9 -0
- package/dist/domain/reduce/competition/reduction.js +32 -0
- package/dist/domain/reduce/model/types.d.ts +122 -0
- package/dist/domain/reduce/model/types.js +84 -0
- package/dist/domain/reduce/persistence/adapter.d.ts +43 -0
- package/dist/domain/reduce/persistence/adapter.js +126 -0
- package/dist/domain/run/competition/adapter.d.ts +30 -0
- package/dist/domain/run/competition/adapter.js +39 -0
- package/dist/domain/run/competition/agent-execution.d.ts +20 -0
- package/dist/domain/run/competition/agent-execution.js +45 -0
- package/dist/domain/run/competition/agent-preparation.d.ts +12 -0
- package/dist/domain/run/competition/agent-preparation.js +24 -0
- package/dist/domain/run/competition/agents/artifacts.d.ts +17 -0
- package/dist/domain/run/competition/agents/artifacts.js +173 -0
- package/dist/{commands/run → domain/run/competition}/agents/lifecycle.d.ts +3 -3
- package/dist/{commands/run → domain/run/competition}/agents/lifecycle.js +84 -64
- package/dist/domain/run/competition/agents/post-processing.d.ts +12 -0
- package/dist/domain/run/competition/agents/post-processing.js +4 -0
- package/dist/domain/run/competition/agents/preparation.js +64 -0
- package/dist/{commands/run → domain/run/competition}/agents/run-context.d.ts +9 -16
- package/dist/{commands/run → domain/run/competition}/agents/run-context.js +22 -70
- package/dist/{commands/run → domain/run/competition}/agents/types.d.ts +10 -13
- package/dist/domain/run/competition/agents/workspace.d.ts +21 -0
- package/dist/domain/run/competition/agents/workspace.js +47 -0
- package/dist/{commands/run → domain/run/competition}/errors.d.ts +8 -1
- package/dist/{commands/run → domain/run/competition}/errors.js +39 -9
- package/dist/{commands/run → domain/run/competition}/phases.d.ts +1 -2
- package/dist/domain/run/competition/phases.js +1 -0
- package/dist/domain/run/competition/prompt.d.ts +7 -0
- package/dist/domain/run/competition/prompt.js +27 -0
- package/dist/{commands/run → domain/run/competition}/reports.d.ts +5 -3
- package/dist/{commands/run → domain/run/competition}/reports.js +7 -19
- package/dist/domain/run/competition/termination-state.d.ts +4 -0
- package/dist/domain/run/competition/termination-state.js +12 -0
- package/dist/{records → domain/run/model}/enhanced.d.ts +6 -7
- package/dist/{records → domain/run/model}/enhanced.js +11 -11
- package/dist/{records → domain/run/model}/errors.d.ts +1 -1
- package/dist/{records → domain/run/model}/errors.js +5 -5
- package/dist/{records → domain/run/model}/mutators.d.ts +4 -3
- package/dist/{records → domain/run/model}/mutators.js +58 -36
- package/dist/domain/run/model/types.d.ts +376 -0
- package/dist/domain/run/model/types.js +192 -0
- package/dist/{records/persistence.d.ts → domain/run/persistence/adapter.d.ts} +9 -3
- package/dist/domain/run/persistence/adapter.js +340 -0
- package/dist/domain/run/persistence/error-mapping.d.ts +2 -0
- package/dist/domain/run/persistence/error-mapping.js +17 -0
- package/dist/domain/shared/lifecycle.d.ts +54 -0
- package/dist/domain/shared/lifecycle.js +165 -0
- package/dist/domain/shared/token-usage.d.ts +21 -0
- package/dist/domain/shared/token-usage.js +38 -0
- package/dist/domain/spec/competition/adapter.d.ts +31 -0
- package/dist/domain/spec/competition/adapter.js +196 -0
- package/dist/domain/spec/competition/prompt.d.ts +11 -0
- package/dist/domain/spec/competition/prompt.js +44 -0
- package/dist/domain/spec/model/output.d.ts +13 -0
- package/dist/domain/spec/model/output.js +36 -0
- package/dist/domain/spec/model/types.d.ts +98 -0
- package/dist/domain/spec/model/types.js +84 -0
- package/dist/domain/spec/persistence/adapter.d.ts +51 -0
- package/dist/domain/spec/persistence/adapter.js +140 -0
- package/dist/domain/verify/blinding/aliases.d.ts +7 -0
- package/dist/domain/verify/blinding/aliases.js +23 -0
- package/dist/domain/verify/competition/adapter.d.ts +54 -0
- package/dist/domain/verify/competition/adapter.js +444 -0
- package/dist/domain/verify/competition/artifacts.d.ts +6 -0
- package/dist/domain/verify/competition/artifacts.js +7 -0
- package/dist/domain/verify/competition/blinding.d.ts +24 -0
- package/dist/domain/verify/competition/blinding.js +109 -0
- package/dist/domain/verify/competition/finalize.d.ts +11 -0
- package/dist/domain/verify/competition/finalize.js +65 -0
- package/dist/domain/verify/competition/programmatic.d.ts +15 -0
- package/dist/domain/verify/competition/programmatic.js +352 -0
- package/dist/domain/verify/competition/prompt.d.ts +19 -0
- package/dist/domain/verify/competition/prompt.js +63 -0
- package/dist/domain/verify/competition/rubric.d.ts +23 -0
- package/dist/domain/verify/competition/rubric.js +77 -0
- package/dist/domain/verify/competition/shared-layout.d.ts +121 -0
- package/dist/domain/verify/competition/shared-layout.js +365 -0
- package/dist/domain/verify/competition/target.d.ts +47 -0
- package/dist/domain/verify/competition/target.js +1 -0
- package/dist/domain/verify/model/mutators.d.ts +16 -0
- package/dist/domain/verify/model/mutators.js +126 -0
- package/dist/domain/verify/model/types.d.ts +408 -0
- package/dist/domain/verify/model/types.js +289 -0
- package/dist/domain/verify/persistence/adapter.d.ts +43 -0
- package/dist/domain/verify/persistence/adapter.js +126 -0
- package/dist/domain/verify/programmatic/runner.d.ts +22 -0
- package/dist/domain/verify/programmatic/runner.js +209 -0
- package/dist/domain/verify/rubric-result.d.ts +28 -0
- package/dist/domain/verify/rubric-result.js +121 -0
- package/dist/extra-context/contract.d.ts +17 -0
- package/dist/extra-context/contract.js +60 -0
- package/dist/interactive/index.d.ts +2 -0
- package/dist/interactive/index.js +1 -0
- package/dist/interactive/providers/launch.d.ts +23 -0
- package/dist/interactive/providers/launch.js +203 -0
- package/dist/interactive/providers/mcp.d.ts +13 -0
- package/dist/interactive/providers/mcp.js +547 -0
- package/dist/interactive/providers/shared.d.ts +2 -0
- package/dist/interactive/providers/shared.js +1 -0
- package/dist/interactive/providers.d.ts +3 -0
- package/dist/interactive/providers.js +3 -0
- package/dist/interactive/records.d.ts +2 -0
- package/dist/interactive/records.js +1 -0
- package/dist/interactive/substrate.d.ts +21 -0
- package/dist/interactive/substrate.js +522 -0
- package/dist/interactive/types.d.ts +101 -0
- package/dist/interactive/types.js +1 -0
- package/dist/mcp/server.d.ts +88 -0
- package/dist/mcp/server.js +790 -0
- package/dist/persistence/error-mapping.d.ts +19 -0
- package/dist/persistence/error-mapping.js +44 -0
- package/dist/persistence/errors.d.ts +26 -0
- package/dist/persistence/errors.js +49 -0
- package/dist/persistence/extra-context.d.ts +9 -0
- package/dist/persistence/extra-context.js +60 -0
- package/dist/{records → persistence}/history-lock.js +2 -2
- package/dist/persistence/record-path-schema.d.ts +3 -0
- package/dist/persistence/record-path-schema.js +16 -0
- package/dist/persistence/session-store.d.ts +92 -0
- package/dist/persistence/session-store.js +412 -0
- package/dist/policy/auto.d.ts +13 -0
- package/dist/policy/auto.js +22 -0
- package/dist/policy/index.d.ts +5 -0
- package/dist/policy/index.js +5 -0
- package/dist/policy/resolution.d.ts +6 -0
- package/dist/policy/resolution.js +23 -0
- package/dist/policy/result.d.ts +53 -0
- package/dist/policy/result.js +15 -0
- package/dist/policy/selector.d.ts +11 -0
- package/dist/policy/selector.js +57 -0
- package/dist/policy/verification.d.ts +77 -0
- package/dist/policy/verification.js +365 -0
- package/dist/policy/verifier-selection.d.ts +13 -0
- package/dist/policy/verifier-selection.js +78 -0
- package/dist/preflight/branch.d.ts +9 -0
- package/dist/preflight/branch.js +48 -0
- package/dist/preflight/errors.d.ts +3 -0
- package/dist/preflight/errors.js +10 -3
- package/dist/preflight/index.d.ts +13 -0
- package/dist/preflight/index.js +43 -8
- package/dist/render/interactions/confirmation.js +4 -2
- package/dist/render/transcripts/apply.js +9 -10
- package/dist/render/transcripts/auto.d.ts +27 -0
- package/dist/render/transcripts/auto.js +21 -0
- package/dist/render/transcripts/init.d.ts +4 -15
- package/dist/render/transcripts/init.js +71 -72
- package/dist/render/transcripts/list.d.ts +10 -1
- package/dist/render/transcripts/list.js +121 -15
- package/dist/render/transcripts/message.d.ts +72 -0
- package/dist/render/transcripts/message.js +362 -0
- package/dist/render/transcripts/prune.d.ts +7 -2
- package/dist/render/transcripts/prune.js +64 -17
- package/dist/render/transcripts/reduce.d.ts +74 -0
- package/dist/render/transcripts/reduce.js +395 -0
- package/dist/render/transcripts/root-launcher.d.ts +19 -0
- package/dist/render/transcripts/root-launcher.js +40 -0
- package/dist/render/transcripts/run.d.ts +35 -6
- package/dist/render/transcripts/run.js +241 -165
- package/dist/render/transcripts/shared.d.ts +2 -0
- package/dist/render/transcripts/shared.js +11 -4
- package/dist/render/transcripts/spec.d.ts +74 -0
- package/dist/render/transcripts/spec.js +394 -0
- package/dist/render/transcripts/stage-progress.d.ts +22 -0
- package/dist/render/transcripts/stage-progress.js +6 -0
- package/dist/render/transcripts/update-check.d.ts +2 -0
- package/dist/render/transcripts/update-check.js +22 -0
- package/dist/render/transcripts/verify.d.ts +74 -0
- package/dist/render/transcripts/verify.js +409 -0
- package/dist/render/utils/agents.d.ts +10 -9
- package/dist/render/utils/agents.js +30 -82
- package/dist/render/utils/badges.d.ts +3 -20
- package/dist/render/utils/badges.js +3 -36
- package/dist/render/utils/duration.d.ts +12 -0
- package/dist/render/utils/duration.js +37 -0
- package/dist/render/utils/interactive-frame.d.ts +6 -0
- package/dist/render/utils/interactive-frame.js +38 -0
- package/dist/render/utils/records.js +4 -4
- package/dist/render/utils/runs.d.ts +3 -9
- package/dist/render/utils/runs.js +16 -48
- package/dist/render/utils/stage-output.d.ts +20 -0
- package/dist/render/utils/stage-output.js +44 -0
- package/dist/render/utils/timezone.d.ts +2 -0
- package/dist/render/utils/timezone.js +42 -0
- package/dist/render/utils/transcript-shell.d.ts +66 -0
- package/dist/render/utils/transcript-shell.js +155 -0
- package/dist/render/utils/transcript.d.ts +7 -1
- package/dist/render/utils/transcript.js +12 -2
- package/dist/render/utils/wrap.d.ts +1 -0
- package/dist/render/utils/wrap.js +20 -0
- package/dist/status/colors.d.ts +2 -3
- package/dist/status/colors.js +3 -3
- package/dist/status/index.d.ts +108 -8
- package/dist/status/index.js +164 -5
- package/dist/update-check/checker.d.ts +24 -0
- package/dist/update-check/checker.js +130 -0
- package/dist/update-check/prompt.d.ts +25 -0
- package/dist/update-check/prompt.js +62 -0
- package/dist/update-check/semver.d.ts +17 -0
- package/dist/update-check/semver.js +36 -0
- package/dist/update-check/state-path.d.ts +8 -0
- package/dist/update-check/state-path.js +18 -0
- package/dist/utils/binaries.js +14 -8
- package/dist/utils/errors.d.ts +3 -1
- package/dist/utils/errors.js +3 -1
- package/dist/utils/git.d.ts +10 -0
- package/dist/utils/git.js +15 -3
- package/dist/utils/output.d.ts +5 -1
- package/dist/utils/output.js +4 -2
- package/dist/utils/process.d.ts +2 -1
- package/dist/utils/process.js +7 -3
- package/dist/utils/session-id.d.ts +1 -0
- package/dist/utils/session-id.js +22 -0
- package/dist/utils/slug.d.ts +2 -0
- package/dist/utils/slug.js +15 -0
- package/dist/utils/voratiq-cli-target.d.ts +9 -0
- package/dist/utils/voratiq-cli-target.js +58 -0
- package/dist/workspace/agents.d.ts +13 -16
- package/dist/workspace/agents.js +22 -147
- package/dist/workspace/chat/artifacts.d.ts +9 -0
- package/dist/workspace/chat/artifacts.js +82 -12
- package/dist/workspace/chat/native-usage.d.ts +13 -0
- package/dist/workspace/chat/native-usage.js +60 -0
- package/dist/workspace/chat/sources.d.ts +9 -5
- package/dist/workspace/chat/sources.js +89 -23
- package/dist/workspace/chat/token-usage-result.d.ts +23 -0
- package/dist/workspace/chat/token-usage-result.js +7 -0
- package/dist/workspace/chat/usage-extractor.d.ts +30 -0
- package/dist/workspace/chat/usage-extractor.js +461 -0
- package/dist/workspace/chat/usage-mappings.d.ts +20 -0
- package/dist/workspace/chat/usage-mappings.js +136 -0
- package/dist/workspace/credential-guard.js +1 -1
- package/dist/workspace/dependencies.js +4 -4
- package/dist/workspace/errors.d.ts +5 -0
- package/dist/workspace/errors.js +13 -3
- package/dist/workspace/layout.d.ts +17 -6
- package/dist/workspace/layout.js +51 -32
- package/dist/workspace/promotion.d.ts +32 -0
- package/dist/workspace/promotion.js +34 -0
- package/dist/workspace/prune.d.ts +1 -1
- package/dist/workspace/run.d.ts +1 -3
- package/dist/workspace/run.js +6 -15
- package/dist/workspace/setup.d.ts +8 -0
- package/dist/workspace/setup.js +359 -56
- package/dist/workspace/shim.js +1 -1
- package/dist/workspace/structure.d.ts +91 -26
- package/dist/workspace/structure.js +227 -43
- package/dist/workspace/templates.d.ts +9 -3
- package/dist/workspace/templates.js +26 -15
- package/dist/workspace/verification-defaults.d.ts +12 -0
- package/dist/workspace/verification-defaults.js +1017 -0
- package/package.json +30 -24
- package/dist/cli/review.d.ts +0 -12
- package/dist/cli/review.js +0 -33
- package/dist/commands/errors.d.ts +0 -4
- package/dist/commands/errors.js +0 -7
- package/dist/commands/init/evals.d.ts +0 -4
- package/dist/commands/init/evals.js +0 -219
- package/dist/commands/review/command.d.ts +0 -10
- package/dist/commands/review/command.js +0 -26
- package/dist/commands/run/agent-execution.d.ts +0 -19
- package/dist/commands/run/agent-execution.js +0 -63
- package/dist/commands/run/agents/auth-stage.d.ts +0 -23
- package/dist/commands/run/agents/auth-stage.js +0 -108
- package/dist/commands/run/agents/chat-preserver.d.ts +0 -9
- package/dist/commands/run/agents/chat-preserver.js +0 -35
- package/dist/commands/run/agents/eval-runner.d.ts +0 -19
- package/dist/commands/run/agents/eval-runner.js +0 -27
- package/dist/commands/run/agents/failures.js +0 -32
- package/dist/commands/run/agents/preparation.js +0 -123
- package/dist/commands/run/agents.d.ts +0 -14
- package/dist/commands/run/agents.js +0 -47
- package/dist/commands/run/prompts.d.ts +0 -4
- package/dist/commands/run/prompts.js +0 -16
- package/dist/commands/run/sandbox-registry.d.ts +0 -4
- package/dist/commands/run/sandbox-registry.js +0 -54
- package/dist/configs/evals/defaults.d.ts +0 -8
- package/dist/configs/evals/defaults.js +0 -28
- package/dist/configs/evals/detect.d.ts +0 -10
- package/dist/configs/evals/errors.d.ts +0 -16
- package/dist/configs/evals/errors.js +0 -29
- package/dist/configs/evals/loader.d.ts +0 -9
- package/dist/configs/evals/loader.js +0 -46
- package/dist/configs/evals/types.d.ts +0 -42
- package/dist/configs/evals/types.js +0 -74
- package/dist/evals/runner.d.ts +0 -16
- package/dist/evals/runner.js +0 -132
- package/dist/records/persistence.js +0 -469
- package/dist/records/types.d.ts +0 -255
- package/dist/records/types.js +0 -160
- package/dist/render/transcripts/review.d.ts +0 -2
- package/dist/render/transcripts/review.js +0 -36
- /package/dist/{commands/run → agents/runtime}/shim/agent-manifest.d.ts +0 -0
- /package/dist/{commands/run → agents/runtime}/shim/agent-manifest.js +0 -0
- /package/dist/{commands/run → agents/runtime/shim}/argv.d.ts +0 -0
- /package/dist/{commands/run → agents/runtime/shim}/argv.js +0 -0
- /package/dist/{commands/run/agents → agents/runtime}/types.js +0 -0
- /package/dist/{commands/run → domain/run/competition}/agents/preparation.d.ts +0 -0
- /package/dist/{commands/run/phases.js → domain/run/competition/agents/types.js} +0 -0
- /package/dist/{commands/run → domain/run/model}/id.d.ts +0 -0
- /package/dist/{commands/run → domain/run/model}/id.js +0 -0
- /package/dist/{records → persistence}/history-lock.d.ts +0 -0
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { externalApplyExecutionInputSchema, externalListInspectionInputSchema, externalMessageExecutionInputSchema, externalPruneExecutionInputSchema, externalReduceExecutionInputSchema, externalRunExecutionInputSchema, externalSpecExecutionInputSchema, externalVerifyExecutionInputSchema, } from "../cli/contract.js";
|
|
5
|
+
import { operatorResultEnvelopeSchema, } from "../cli/operator-envelope.js";
|
|
6
|
+
import { listJsonOutputSchema, } from "../contracts/list.js";
|
|
7
|
+
import { getVoratiqVersion } from "../utils/version.js";
|
|
8
|
+
import { createEntrypointVoratiqCliTarget as createEntrypointCliTarget, resolveVoratiqCliTarget, } from "../utils/voratiq-cli-target.js";
|
|
9
|
+
const JSON_RPC_VERSION = "2.0";
|
|
10
|
+
const HEADER_DELIMITER = Buffer.from("\r\n\r\n", "utf8");
|
|
11
|
+
const LF_HEADER_DELIMITER = Buffer.from("\n\n", "utf8");
|
|
12
|
+
const JSON_RPC_PARSE_ERROR = -32700;
|
|
13
|
+
const JSON_RPC_INVALID_REQUEST = -32600;
|
|
14
|
+
const JSON_RPC_METHOD_NOT_FOUND = -32601;
|
|
15
|
+
const JSON_RPC_INVALID_PARAMS = -32602;
|
|
16
|
+
const JSON_RPC_INTERNAL_ERROR = -32603;
|
|
17
|
+
export const VORATIQ_MCP_PROTOCOL_VERSION = "2025-11-25";
|
|
18
|
+
export const VORATIQ_SUPPORTED_MCP_PROTOCOL_VERSIONS = [
|
|
19
|
+
VORATIQ_MCP_PROTOCOL_VERSION,
|
|
20
|
+
"2025-06-18",
|
|
21
|
+
"2024-11-05",
|
|
22
|
+
];
|
|
23
|
+
function isSupportedMcpProtocolVersion(protocolVersion) {
|
|
24
|
+
return VORATIQ_SUPPORTED_MCP_PROTOCOL_VERSIONS.includes(protocolVersion);
|
|
25
|
+
}
|
|
26
|
+
const initializeRequestParamsSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
protocolVersion: z.string(),
|
|
29
|
+
})
|
|
30
|
+
.passthrough();
|
|
31
|
+
const callToolParamsSchema = z
|
|
32
|
+
.object({
|
|
33
|
+
name: z.string(),
|
|
34
|
+
arguments: z.record(z.string(), z.unknown()).optional(),
|
|
35
|
+
})
|
|
36
|
+
.passthrough();
|
|
37
|
+
const toolSpecs = [
|
|
38
|
+
{
|
|
39
|
+
name: "voratiq_spec",
|
|
40
|
+
operator: "spec",
|
|
41
|
+
description: "Draft or refine a Voratiq spec session from a task description, an existing spec, or related repo context.",
|
|
42
|
+
inputSchemaSource: externalSpecExecutionInputSchema,
|
|
43
|
+
buildArgs: (input) => buildSpecExecutionArgs(input),
|
|
44
|
+
outputContract: "execution",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "voratiq_run",
|
|
48
|
+
operator: "run",
|
|
49
|
+
description: "Execute a Voratiq spec session and create a run with agent outputs and artifacts.",
|
|
50
|
+
inputSchemaSource: externalRunExecutionInputSchema,
|
|
51
|
+
buildArgs: (input) => buildRunExecutionArgs(input),
|
|
52
|
+
outputContract: "execution",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "voratiq_reduce",
|
|
56
|
+
operator: "reduce",
|
|
57
|
+
description: "Reduce a set of Voratiq artifacts into a summarized output for comparison or follow-on work.",
|
|
58
|
+
inputSchemaSource: externalReduceExecutionInputSchema,
|
|
59
|
+
buildArgs: (input) => buildReduceExecutionArgs(input),
|
|
60
|
+
outputContract: "execution",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "voratiq_verify",
|
|
64
|
+
operator: "verify",
|
|
65
|
+
description: "Verify a Voratiq spec, run, reduction, or message session and record the evaluation result.",
|
|
66
|
+
inputSchemaSource: externalVerifyExecutionInputSchema,
|
|
67
|
+
buildArgs: (input) => buildVerifyExecutionArgs(input),
|
|
68
|
+
outputContract: "execution",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "voratiq_message",
|
|
72
|
+
operator: "message",
|
|
73
|
+
description: "Send an isolated prompt to one or more Voratiq agents and persist their independent replies as a durable message session.",
|
|
74
|
+
inputSchemaSource: externalMessageExecutionInputSchema,
|
|
75
|
+
buildArgs: (input) => buildMessageExecutionArgs(input),
|
|
76
|
+
outputContract: "execution",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "voratiq_apply",
|
|
80
|
+
operator: "apply",
|
|
81
|
+
description: "Apply an accepted Voratiq run diff into the current working tree.",
|
|
82
|
+
inputSchemaSource: externalApplyExecutionInputSchema,
|
|
83
|
+
buildArgs: (input) => buildApplyExecutionArgs(input),
|
|
84
|
+
outputContract: "execution",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "voratiq_list",
|
|
88
|
+
operator: "list",
|
|
89
|
+
description: "List recorded Voratiq sessions for one operator (`spec`, `run`, `reduce`, `verify`, or `message`) in table or detail mode.",
|
|
90
|
+
inputSchemaSource: externalListInspectionInputSchema,
|
|
91
|
+
mcpInputSchema: createListMcpInputSchema(),
|
|
92
|
+
buildArgs: (input) => buildListInspectionArgs(input),
|
|
93
|
+
outputContract: "list",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "voratiq_prune",
|
|
97
|
+
operator: "prune",
|
|
98
|
+
description: "Prune Voratiq run workspaces or all pruneable run state after confirmation.",
|
|
99
|
+
inputSchemaSource: externalPruneExecutionInputSchema,
|
|
100
|
+
mcpInputSchema: createPruneMcpInputSchema(),
|
|
101
|
+
buildArgs: (input) => buildPruneExecutionArgs(input),
|
|
102
|
+
outputContract: "execution",
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
const toolDefinitions = toolSpecs.map((tool) => ({
|
|
106
|
+
name: tool.name,
|
|
107
|
+
description: tool.description,
|
|
108
|
+
inputSchema: tool.mcpInputSchema ?? toToolInputJsonSchema(tool.inputSchemaSource),
|
|
109
|
+
}));
|
|
110
|
+
const VORATIQ_MCP_SERVER_INSTRUCTIONS = "Voratiq tools operate on Voratiq workflow state in the current repository. Use voratiq_list for questions about recent or specific spec, run, reduce, verify, or message sessions. Use voratiq_spec, voratiq_run, voratiq_reduce, voratiq_verify, voratiq_message, voratiq_apply, and voratiq_prune for the normal Voratiq workflow. Prefer these tools over shell inspection when the task is about Voratiq workflow history or state.";
|
|
111
|
+
const toolSpecsByName = new Map(toolSpecs.map((tool) => [tool.name, tool]));
|
|
112
|
+
export function getVoratiqMcpToolDefinitions() {
|
|
113
|
+
return toolDefinitions;
|
|
114
|
+
}
|
|
115
|
+
export function createVoratiqMcpRequestHandler(options = {}) {
|
|
116
|
+
const invokeCliJsonContract = options.invokeCliJsonContract;
|
|
117
|
+
const serverVersion = options.serverVersion ?? getVoratiqVersion();
|
|
118
|
+
let hasInitialized = false;
|
|
119
|
+
return {
|
|
120
|
+
async handleRequest(message) {
|
|
121
|
+
if (message.method === "initialize") {
|
|
122
|
+
if (hasInitialized) {
|
|
123
|
+
return createErrorResponse(message.id, JSON_RPC_INVALID_REQUEST, "Server is already initialized.");
|
|
124
|
+
}
|
|
125
|
+
const parsedParams = initializeRequestParamsSchema.safeParse(message.params ?? {});
|
|
126
|
+
if (!parsedParams.success) {
|
|
127
|
+
return createErrorResponse(message.id, JSON_RPC_INVALID_PARAMS, "Invalid initialize params.", {
|
|
128
|
+
validation: z.flattenError(parsedParams.error),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (!isSupportedMcpProtocolVersion(parsedParams.data.protocolVersion)) {
|
|
132
|
+
return createErrorResponse(message.id, JSON_RPC_INVALID_PARAMS, "Unsupported MCP protocol version.", {
|
|
133
|
+
expectedProtocolVersion: VORATIQ_MCP_PROTOCOL_VERSION,
|
|
134
|
+
supportedProtocolVersions: [
|
|
135
|
+
...VORATIQ_SUPPORTED_MCP_PROTOCOL_VERSIONS,
|
|
136
|
+
],
|
|
137
|
+
receivedProtocolVersion: parsedParams.data.protocolVersion,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
hasInitialized = true;
|
|
141
|
+
return createSuccessResponse(message.id, {
|
|
142
|
+
protocolVersion: parsedParams.data.protocolVersion,
|
|
143
|
+
capabilities: {
|
|
144
|
+
tools: {
|
|
145
|
+
listChanged: true,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
instructions: VORATIQ_MCP_SERVER_INSTRUCTIONS,
|
|
149
|
+
serverInfo: {
|
|
150
|
+
name: "voratiq",
|
|
151
|
+
version: serverVersion,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (!hasInitialized) {
|
|
156
|
+
return createErrorResponse(message.id, JSON_RPC_INVALID_REQUEST, "Server not initialized.");
|
|
157
|
+
}
|
|
158
|
+
if (message.method === "ping") {
|
|
159
|
+
return createSuccessResponse(message.id, {});
|
|
160
|
+
}
|
|
161
|
+
if (message.method === "tools/list") {
|
|
162
|
+
return createSuccessResponse(message.id, {
|
|
163
|
+
tools: getVoratiqMcpToolDefinitions(),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
if (message.method === "tools/call") {
|
|
167
|
+
const parsed = callToolParamsSchema.safeParse(message.params ?? {});
|
|
168
|
+
if (!parsed.success) {
|
|
169
|
+
return createErrorResponse(message.id, JSON_RPC_INVALID_PARAMS, "Invalid tools/call params.", {
|
|
170
|
+
validation: z.flattenError(parsed.error),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const toolName = parsed.data.name;
|
|
174
|
+
const tool = toolSpecsByName.get(toolName);
|
|
175
|
+
if (!tool) {
|
|
176
|
+
return createErrorResponse(message.id, JSON_RPC_INVALID_PARAMS, `Unknown tool: ${parsed.data.name}`);
|
|
177
|
+
}
|
|
178
|
+
if (!invokeCliJsonContract) {
|
|
179
|
+
return createErrorResponse(message.id, JSON_RPC_INTERNAL_ERROR, "No CLI invocation bridge configured for MCP tool execution.");
|
|
180
|
+
}
|
|
181
|
+
const result = await executeToolCall({
|
|
182
|
+
tool,
|
|
183
|
+
rawInput: parsed.data.arguments ?? {},
|
|
184
|
+
invokeCliJsonContract,
|
|
185
|
+
});
|
|
186
|
+
return createSuccessResponse(message.id, result);
|
|
187
|
+
}
|
|
188
|
+
return createErrorResponse(message.id, JSON_RPC_METHOD_NOT_FOUND, `Method not found: ${message.method}`);
|
|
189
|
+
},
|
|
190
|
+
handleNotification(message) {
|
|
191
|
+
if (message.method === "notifications/initialized") {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
export async function runVoratiqMcpStdioServer(options = {}) {
|
|
198
|
+
const stdin = options.stdin ?? process.stdin;
|
|
199
|
+
const stdout = options.stdout ?? process.stdout;
|
|
200
|
+
const invokeCliJsonContract = options.invokeCliJsonContract ??
|
|
201
|
+
createDefaultCliJsonContractInvoker(options.selfCliTarget ?? resolveVoratiqCliTarget());
|
|
202
|
+
const requestHandler = createVoratiqMcpRequestHandler({
|
|
203
|
+
invokeCliJsonContract,
|
|
204
|
+
serverVersion: options.serverVersion,
|
|
205
|
+
});
|
|
206
|
+
let buffer = Buffer.alloc(0);
|
|
207
|
+
const pendingPayloads = [];
|
|
208
|
+
let isDraining = false;
|
|
209
|
+
let hasEnded = false;
|
|
210
|
+
let transportEncoding = "framed";
|
|
211
|
+
await new Promise((resolve, reject) => {
|
|
212
|
+
const tryResolve = () => {
|
|
213
|
+
if (!hasEnded) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (isDraining) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (pendingPayloads.length > 0) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
resolve();
|
|
223
|
+
};
|
|
224
|
+
const drainQueue = () => {
|
|
225
|
+
if (isDraining) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
isDraining = true;
|
|
229
|
+
void (async () => {
|
|
230
|
+
while (pendingPayloads.length > 0) {
|
|
231
|
+
const payload = pendingPayloads.shift();
|
|
232
|
+
if (payload === undefined) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
const parsed = JSON.parse(payload);
|
|
237
|
+
const message = normalizeIncomingMessage(parsed);
|
|
238
|
+
if (!message) {
|
|
239
|
+
writeMessage(stdout, transportEncoding, createErrorResponse(null, JSON_RPC_INVALID_REQUEST, "Invalid JSON-RPC message."));
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if ("id" in message) {
|
|
243
|
+
const response = await requestHandler.handleRequest(message);
|
|
244
|
+
writeMessage(stdout, transportEncoding, response);
|
|
245
|
+
if (message.method === "initialize" && !("error" in response)) {
|
|
246
|
+
writeMessage(stdout, transportEncoding, createNotification("notifications/tools/list_changed"));
|
|
247
|
+
}
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
await requestHandler.handleNotification(message);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
if (error instanceof SyntaxError) {
|
|
254
|
+
writeMessage(stdout, transportEncoding, createErrorResponse(null, JSON_RPC_PARSE_ERROR, "Failed to parse JSON-RPC payload.", { message: error.message }));
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
writeMessage(stdout, transportEncoding, createErrorResponse(null, JSON_RPC_INTERNAL_ERROR, "Unhandled MCP server error.", {
|
|
258
|
+
message: toErrorMessage(error),
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
isDraining = false;
|
|
263
|
+
tryResolve();
|
|
264
|
+
})();
|
|
265
|
+
};
|
|
266
|
+
stdin.on("data", (chunk) => {
|
|
267
|
+
buffer = Buffer.concat([buffer, toBuffer(chunk)]);
|
|
268
|
+
while (true) {
|
|
269
|
+
const extracted = extractNextPayload(buffer, transportEncoding);
|
|
270
|
+
if (!extracted) {
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
if (extracted.kind === "invalid") {
|
|
274
|
+
writeMessage(stdout, transportEncoding, createErrorResponse(null, JSON_RPC_INVALID_REQUEST, extracted.message));
|
|
275
|
+
buffer = Buffer.alloc(0);
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
transportEncoding = extracted.transportEncoding;
|
|
279
|
+
pendingPayloads.push(extracted.payload);
|
|
280
|
+
buffer = Buffer.from(extracted.remaining);
|
|
281
|
+
}
|
|
282
|
+
drainQueue();
|
|
283
|
+
});
|
|
284
|
+
stdin.on("end", () => {
|
|
285
|
+
const trailingPayload = extractTrailingJsonLine(buffer);
|
|
286
|
+
if (trailingPayload) {
|
|
287
|
+
transportEncoding = "jsonl";
|
|
288
|
+
pendingPayloads.push(trailingPayload);
|
|
289
|
+
buffer = Buffer.alloc(0);
|
|
290
|
+
drainQueue();
|
|
291
|
+
}
|
|
292
|
+
hasEnded = true;
|
|
293
|
+
tryResolve();
|
|
294
|
+
});
|
|
295
|
+
stdin.on("error", (error) => {
|
|
296
|
+
reject(error);
|
|
297
|
+
});
|
|
298
|
+
stdin.resume();
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async function executeToolCall(options) {
|
|
302
|
+
const { tool, rawInput, invokeCliJsonContract } = options;
|
|
303
|
+
const parsedInput = tool.inputSchemaSource.safeParse(rawInput);
|
|
304
|
+
if (!parsedInput.success) {
|
|
305
|
+
return buildTransportFailureCallResult({
|
|
306
|
+
failureKind: "invalid_input",
|
|
307
|
+
operator: tool.operator,
|
|
308
|
+
message: "Tool input failed schema validation.",
|
|
309
|
+
details: {
|
|
310
|
+
validation: z.flattenError(parsedInput.error),
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
const invocation = await invokeCliJsonContract({
|
|
315
|
+
operator: tool.operator,
|
|
316
|
+
args: tool.buildArgs(parsedInput.data),
|
|
317
|
+
});
|
|
318
|
+
if (invocation.kind === "spawn_failed") {
|
|
319
|
+
return buildTransportFailureCallResult({
|
|
320
|
+
failureKind: "spawn_failed",
|
|
321
|
+
operator: tool.operator,
|
|
322
|
+
message: `Failed to start voratiq ${tool.operator} --json.`,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
const payloadText = invocation.stdout.trim();
|
|
326
|
+
if (payloadText.length === 0) {
|
|
327
|
+
return buildTransportFailureCallResult({
|
|
328
|
+
failureKind: "malformed_json",
|
|
329
|
+
operator: tool.operator,
|
|
330
|
+
message: "CLI did not emit JSON output.",
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
let payload;
|
|
334
|
+
try {
|
|
335
|
+
payload = JSON.parse(payloadText);
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
return buildTransportFailureCallResult({
|
|
339
|
+
failureKind: "malformed_json",
|
|
340
|
+
operator: tool.operator,
|
|
341
|
+
message: "CLI emitted malformed JSON.",
|
|
342
|
+
details: {
|
|
343
|
+
message: toErrorMessage(error),
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
if (tool.outputContract === "execution") {
|
|
348
|
+
const envelopeResult = operatorResultEnvelopeSchema.safeParse(payload);
|
|
349
|
+
if (!envelopeResult.success) {
|
|
350
|
+
return buildTransportFailureCallResult({
|
|
351
|
+
failureKind: "contract_mismatch",
|
|
352
|
+
operator: tool.operator,
|
|
353
|
+
message: "CLI JSON did not match OperatorResultEnvelope.",
|
|
354
|
+
details: {
|
|
355
|
+
expectedContractType: "OperatorResultEnvelope",
|
|
356
|
+
validation: z.flattenError(envelopeResult.error),
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
const envelope = envelopeResult.data;
|
|
361
|
+
const isError = envelope.status === "failed" || invocation.exitCode !== 0;
|
|
362
|
+
return buildCallToolResult(envelope, isError);
|
|
363
|
+
}
|
|
364
|
+
const listResult = listJsonOutputSchema.safeParse(payload);
|
|
365
|
+
if (!listResult.success) {
|
|
366
|
+
return buildTransportFailureCallResult({
|
|
367
|
+
failureKind: "contract_mismatch",
|
|
368
|
+
operator: tool.operator,
|
|
369
|
+
message: "CLI JSON did not match ListJsonOutput.",
|
|
370
|
+
details: {
|
|
371
|
+
expectedContractType: "ListJsonOutput",
|
|
372
|
+
validation: z.flattenError(listResult.error),
|
|
373
|
+
},
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
const listOutput = listResult.data;
|
|
377
|
+
const isError = invocation.exitCode !== 0;
|
|
378
|
+
return buildCallToolResult(listOutput, isError);
|
|
379
|
+
}
|
|
380
|
+
function buildCallToolResult(payload, isError) {
|
|
381
|
+
return {
|
|
382
|
+
content: [
|
|
383
|
+
{
|
|
384
|
+
type: "text",
|
|
385
|
+
text: JSON.stringify(payload),
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
structuredContent: payload,
|
|
389
|
+
isError,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function createNotification(method, params) {
|
|
393
|
+
return params === undefined
|
|
394
|
+
? {
|
|
395
|
+
jsonrpc: JSON_RPC_VERSION,
|
|
396
|
+
method,
|
|
397
|
+
}
|
|
398
|
+
: {
|
|
399
|
+
jsonrpc: JSON_RPC_VERSION,
|
|
400
|
+
method,
|
|
401
|
+
params,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
function buildTransportFailureCallResult(payload) {
|
|
405
|
+
return buildCallToolResult(payload, true);
|
|
406
|
+
}
|
|
407
|
+
function buildSpecExecutionArgs(input) {
|
|
408
|
+
const args = ["spec", "--description", input.description];
|
|
409
|
+
appendRepeatedStringFlag(args, "--agent", input.agentIds);
|
|
410
|
+
appendOptionalStringFlag(args, "--profile", input.profile);
|
|
411
|
+
appendOptionalNumberFlag(args, "--max-parallel", input.maxParallel);
|
|
412
|
+
appendOptionalStringFlag(args, "--title", input.title);
|
|
413
|
+
appendRepeatedStringFlag(args, "--extra-context", input.extraContext);
|
|
414
|
+
args.push("--json");
|
|
415
|
+
return args;
|
|
416
|
+
}
|
|
417
|
+
function buildRunExecutionArgs(input) {
|
|
418
|
+
const args = ["run", "--spec", input.specPath];
|
|
419
|
+
appendRepeatedStringFlag(args, "--agent", input.agentIds);
|
|
420
|
+
appendOptionalStringFlag(args, "--profile", input.profile);
|
|
421
|
+
appendOptionalNumberFlag(args, "--max-parallel", input.maxParallel);
|
|
422
|
+
appendOptionalTrueFlag(args, "--branch", input.branch);
|
|
423
|
+
appendRepeatedStringFlag(args, "--extra-context", input.extraContext);
|
|
424
|
+
args.push("--json");
|
|
425
|
+
return args;
|
|
426
|
+
}
|
|
427
|
+
function buildMessageExecutionArgs(input) {
|
|
428
|
+
const args = ["message", "--prompt", input.prompt];
|
|
429
|
+
appendRepeatedStringFlag(args, "--agent", input.agentIds);
|
|
430
|
+
appendOptionalStringFlag(args, "--profile", input.profile);
|
|
431
|
+
appendOptionalNumberFlag(args, "--max-parallel", input.maxParallel);
|
|
432
|
+
appendRepeatedStringFlag(args, "--extra-context", input.extraContext);
|
|
433
|
+
args.push("--json");
|
|
434
|
+
return args;
|
|
435
|
+
}
|
|
436
|
+
function buildReduceExecutionArgs(input) {
|
|
437
|
+
const args = ["reduce", `--${input.target.type}`, input.target.id];
|
|
438
|
+
appendRepeatedStringFlag(args, "--agent", input.agentIds);
|
|
439
|
+
appendOptionalStringFlag(args, "--profile", input.profile);
|
|
440
|
+
appendOptionalNumberFlag(args, "--max-parallel", input.maxParallel);
|
|
441
|
+
appendRepeatedStringFlag(args, "--extra-context", input.extraContext);
|
|
442
|
+
args.push("--json");
|
|
443
|
+
return args;
|
|
444
|
+
}
|
|
445
|
+
function buildVerifyExecutionArgs(input) {
|
|
446
|
+
const args = ["verify", `--${input.target.kind}`, input.target.sessionId];
|
|
447
|
+
appendRepeatedStringFlag(args, "--agent", input.agentIds);
|
|
448
|
+
appendOptionalStringFlag(args, "--profile", input.profile);
|
|
449
|
+
appendOptionalNumberFlag(args, "--max-parallel", input.maxParallel);
|
|
450
|
+
appendRepeatedStringFlag(args, "--extra-context", input.extraContext);
|
|
451
|
+
args.push("--json");
|
|
452
|
+
return args;
|
|
453
|
+
}
|
|
454
|
+
function buildApplyExecutionArgs(input) {
|
|
455
|
+
const args = ["apply", "--run", input.runId, "--agent", input.agentId];
|
|
456
|
+
appendOptionalTrueFlag(args, "--ignore-base-mismatch", input.ignoreBaseMismatch);
|
|
457
|
+
appendOptionalTrueFlag(args, "--commit", input.commit);
|
|
458
|
+
args.push("--json");
|
|
459
|
+
return args;
|
|
460
|
+
}
|
|
461
|
+
function buildPruneExecutionArgs(input) {
|
|
462
|
+
const args = input.scope === "all"
|
|
463
|
+
? ["prune", "--all"]
|
|
464
|
+
: ["prune", "--run", input.runId];
|
|
465
|
+
appendOptionalTrueFlag(args, "--purge", input.purge);
|
|
466
|
+
args.push("--yes", "--json");
|
|
467
|
+
return args;
|
|
468
|
+
}
|
|
469
|
+
function buildListInspectionArgs(input) {
|
|
470
|
+
const args = ["list", `--${input.operator}`];
|
|
471
|
+
if (input.mode === "detail") {
|
|
472
|
+
args.push(input.sessionId);
|
|
473
|
+
}
|
|
474
|
+
appendOptionalTrueFlag(args, "--verbose", input.verbose);
|
|
475
|
+
appendOptionalNumberFlag(args, "--limit", input.limit);
|
|
476
|
+
args.push("--json");
|
|
477
|
+
return args;
|
|
478
|
+
}
|
|
479
|
+
function appendRepeatedStringFlag(args, flag, values) {
|
|
480
|
+
for (const value of values ?? []) {
|
|
481
|
+
args.push(flag, value);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function appendOptionalStringFlag(args, flag, value) {
|
|
485
|
+
if (value !== undefined) {
|
|
486
|
+
args.push(flag, value);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function appendOptionalNumberFlag(args, flag, value) {
|
|
490
|
+
if (value !== undefined) {
|
|
491
|
+
args.push(flag, String(value));
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
function appendOptionalTrueFlag(args, flag, enabled) {
|
|
495
|
+
if (enabled === true) {
|
|
496
|
+
args.push(flag);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
export { createEntrypointCliTarget, resolveVoratiqCliTarget };
|
|
500
|
+
export function createDefaultCliJsonContractInvoker(target = resolveVoratiqCliTarget()) {
|
|
501
|
+
return async (input) => await invokeSubprocess({
|
|
502
|
+
command: target.command,
|
|
503
|
+
args: [...target.argsPrefix, ...input.args],
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
async function invokeSubprocess(options) {
|
|
507
|
+
return await new Promise((resolve) => {
|
|
508
|
+
let settled = false;
|
|
509
|
+
const child = spawn(options.command, options.args, {
|
|
510
|
+
cwd: process.cwd(),
|
|
511
|
+
env: {
|
|
512
|
+
...process.env,
|
|
513
|
+
},
|
|
514
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
515
|
+
});
|
|
516
|
+
const stdoutChunks = [];
|
|
517
|
+
const stderrChunks = [];
|
|
518
|
+
child.stdout?.setEncoding("utf8");
|
|
519
|
+
child.stderr?.setEncoding("utf8");
|
|
520
|
+
child.stdout?.on("data", (chunk) => {
|
|
521
|
+
stdoutChunks.push(chunk);
|
|
522
|
+
});
|
|
523
|
+
child.stderr?.on("data", (chunk) => {
|
|
524
|
+
stderrChunks.push(chunk);
|
|
525
|
+
});
|
|
526
|
+
child.once("error", (error) => {
|
|
527
|
+
if (settled) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
settled = true;
|
|
531
|
+
resolve({
|
|
532
|
+
kind: "spawn_failed",
|
|
533
|
+
error,
|
|
534
|
+
});
|
|
535
|
+
});
|
|
536
|
+
child.once("close", (code) => {
|
|
537
|
+
if (settled) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
settled = true;
|
|
541
|
+
resolve({
|
|
542
|
+
kind: "success",
|
|
543
|
+
exitCode: code ?? 0,
|
|
544
|
+
stdout: stdoutChunks.join(""),
|
|
545
|
+
stderr: stderrChunks.join(""),
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
function toToolInputJsonSchema(schema) {
|
|
551
|
+
const jsonSchema = z.toJSONSchema(schema, {
|
|
552
|
+
io: "input",
|
|
553
|
+
});
|
|
554
|
+
delete jsonSchema.$schema;
|
|
555
|
+
return jsonSchema;
|
|
556
|
+
}
|
|
557
|
+
function createPruneMcpInputSchema() {
|
|
558
|
+
return toToolInputJsonSchema(z
|
|
559
|
+
.object({
|
|
560
|
+
scope: z.enum(["run", "all"]),
|
|
561
|
+
runId: z
|
|
562
|
+
.string()
|
|
563
|
+
.min(1)
|
|
564
|
+
.optional()
|
|
565
|
+
.describe("Required when scope is `run`."),
|
|
566
|
+
purge: z.boolean().optional(),
|
|
567
|
+
confirmed: z
|
|
568
|
+
.literal(true)
|
|
569
|
+
.describe("Must be true to confirm prune operations."),
|
|
570
|
+
})
|
|
571
|
+
.strict());
|
|
572
|
+
}
|
|
573
|
+
function createListMcpInputSchema() {
|
|
574
|
+
return toToolInputJsonSchema(z
|
|
575
|
+
.object({
|
|
576
|
+
operator: z.enum(["spec", "run", "reduce", "verify", "message"]),
|
|
577
|
+
mode: z
|
|
578
|
+
.enum(["table", "detail"])
|
|
579
|
+
.describe("Use `detail` only when inspecting a specific session."),
|
|
580
|
+
sessionId: z
|
|
581
|
+
.string()
|
|
582
|
+
.min(1)
|
|
583
|
+
.optional()
|
|
584
|
+
.describe("Required when mode is `detail`."),
|
|
585
|
+
verbose: z.boolean().optional(),
|
|
586
|
+
limit: z.number().int().positive().optional(),
|
|
587
|
+
})
|
|
588
|
+
.strict());
|
|
589
|
+
}
|
|
590
|
+
function createSuccessResponse(id, result) {
|
|
591
|
+
return {
|
|
592
|
+
jsonrpc: JSON_RPC_VERSION,
|
|
593
|
+
id,
|
|
594
|
+
result,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function createErrorResponse(id, code, message, data) {
|
|
598
|
+
return {
|
|
599
|
+
jsonrpc: JSON_RPC_VERSION,
|
|
600
|
+
id,
|
|
601
|
+
error: {
|
|
602
|
+
code,
|
|
603
|
+
message,
|
|
604
|
+
...(data === undefined ? {} : { data }),
|
|
605
|
+
},
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function normalizeIncomingMessage(input) {
|
|
609
|
+
if (!isRecord(input)) {
|
|
610
|
+
return undefined;
|
|
611
|
+
}
|
|
612
|
+
if (input.jsonrpc !== JSON_RPC_VERSION) {
|
|
613
|
+
return undefined;
|
|
614
|
+
}
|
|
615
|
+
if (typeof input.method !== "string" || input.method.length === 0) {
|
|
616
|
+
return undefined;
|
|
617
|
+
}
|
|
618
|
+
if ("id" in input) {
|
|
619
|
+
const id = input.id;
|
|
620
|
+
if (id !== null && typeof id !== "string" && typeof id !== "number") {
|
|
621
|
+
return undefined;
|
|
622
|
+
}
|
|
623
|
+
return {
|
|
624
|
+
jsonrpc: JSON_RPC_VERSION,
|
|
625
|
+
method: input.method,
|
|
626
|
+
id,
|
|
627
|
+
params: input.params,
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
return {
|
|
631
|
+
jsonrpc: JSON_RPC_VERSION,
|
|
632
|
+
method: input.method,
|
|
633
|
+
params: input.params,
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function parseContentLength(headerBlock) {
|
|
637
|
+
const lines = headerBlock.split(/\r?\n/u);
|
|
638
|
+
for (const line of lines) {
|
|
639
|
+
const separatorIndex = line.indexOf(":");
|
|
640
|
+
if (separatorIndex <= 0) {
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
const key = line.slice(0, separatorIndex).trim().toLowerCase();
|
|
644
|
+
if (key !== "content-length") {
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
const rawValue = line.slice(separatorIndex + 1).trim();
|
|
648
|
+
if (!/^\d+$/u.test(rawValue)) {
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
const value = Number(rawValue);
|
|
652
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
653
|
+
return null;
|
|
654
|
+
}
|
|
655
|
+
return value;
|
|
656
|
+
}
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
function findHeaderDelimiter(buffer) {
|
|
660
|
+
const crlfIndex = buffer.indexOf(HEADER_DELIMITER);
|
|
661
|
+
const lfIndex = buffer.indexOf(LF_HEADER_DELIMITER);
|
|
662
|
+
if (crlfIndex < 0 && lfIndex < 0) {
|
|
663
|
+
return undefined;
|
|
664
|
+
}
|
|
665
|
+
if (crlfIndex < 0) {
|
|
666
|
+
return {
|
|
667
|
+
index: lfIndex,
|
|
668
|
+
delimiter: LF_HEADER_DELIMITER,
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
if (lfIndex < 0 || crlfIndex <= lfIndex) {
|
|
672
|
+
return {
|
|
673
|
+
index: crlfIndex,
|
|
674
|
+
delimiter: HEADER_DELIMITER,
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
return {
|
|
678
|
+
index: lfIndex,
|
|
679
|
+
delimiter: LF_HEADER_DELIMITER,
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
function writeMessage(stdout, transportEncoding, message) {
|
|
683
|
+
if (transportEncoding === "jsonl") {
|
|
684
|
+
stdout.write(`${JSON.stringify(message)}\n`);
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
writeFramedMessage(stdout, message);
|
|
688
|
+
}
|
|
689
|
+
function writeFramedMessage(stdout, message) {
|
|
690
|
+
const payload = Buffer.from(JSON.stringify(message), "utf8");
|
|
691
|
+
const header = Buffer.from(`Content-Length: ${payload.byteLength}\r\n\r\n`);
|
|
692
|
+
stdout.write(Buffer.concat([header, payload]));
|
|
693
|
+
}
|
|
694
|
+
function extractNextPayload(buffer, currentTransportEncoding) {
|
|
695
|
+
if (currentTransportEncoding === "framed" &&
|
|
696
|
+
(startsWithContentLengthHeader(buffer) || looksLikeFramedTransport(buffer))) {
|
|
697
|
+
return extractFramedPayload(buffer);
|
|
698
|
+
}
|
|
699
|
+
const jsonLinePayload = extractJsonLinePayload(buffer);
|
|
700
|
+
if (jsonLinePayload) {
|
|
701
|
+
return jsonLinePayload;
|
|
702
|
+
}
|
|
703
|
+
if (currentTransportEncoding === "framed") {
|
|
704
|
+
return extractFramedPayload(buffer);
|
|
705
|
+
}
|
|
706
|
+
return undefined;
|
|
707
|
+
}
|
|
708
|
+
function startsWithContentLengthHeader(buffer) {
|
|
709
|
+
const firstLineEnd = buffer.indexOf("\n");
|
|
710
|
+
const firstLine = firstLineEnd >= 0
|
|
711
|
+
? buffer.subarray(0, firstLineEnd).toString("utf8")
|
|
712
|
+
: buffer.toString("utf8");
|
|
713
|
+
return /^content-length\s*:/iu.test(firstLine.trim());
|
|
714
|
+
}
|
|
715
|
+
function looksLikeFramedTransport(buffer) {
|
|
716
|
+
const headerDelimiter = findHeaderDelimiter(buffer);
|
|
717
|
+
if (!headerDelimiter) {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
const headerBlock = buffer
|
|
721
|
+
.subarray(0, headerDelimiter.index)
|
|
722
|
+
.toString("utf8");
|
|
723
|
+
return /(^|\r?\n)content-length\s*:/iu.test(headerBlock);
|
|
724
|
+
}
|
|
725
|
+
function extractFramedPayload(buffer) {
|
|
726
|
+
const headerDelimiter = findHeaderDelimiter(buffer);
|
|
727
|
+
if (!headerDelimiter) {
|
|
728
|
+
return undefined;
|
|
729
|
+
}
|
|
730
|
+
const headerBlock = buffer
|
|
731
|
+
.subarray(0, headerDelimiter.index)
|
|
732
|
+
.toString("utf8");
|
|
733
|
+
const contentLength = parseContentLength(headerBlock);
|
|
734
|
+
if (contentLength === null) {
|
|
735
|
+
return {
|
|
736
|
+
kind: "invalid",
|
|
737
|
+
message: "Missing or invalid Content-Length header.",
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
const messageStart = headerDelimiter.index + headerDelimiter.delimiter.length;
|
|
741
|
+
const messageEnd = messageStart + contentLength;
|
|
742
|
+
if (buffer.length < messageEnd) {
|
|
743
|
+
return undefined;
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
kind: "payload",
|
|
747
|
+
payload: buffer.subarray(messageStart, messageEnd).toString("utf8"),
|
|
748
|
+
remaining: buffer.subarray(messageEnd),
|
|
749
|
+
transportEncoding: "framed",
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
function extractJsonLinePayload(buffer) {
|
|
753
|
+
const newlineIndex = buffer.indexOf("\n");
|
|
754
|
+
if (newlineIndex < 0) {
|
|
755
|
+
return undefined;
|
|
756
|
+
}
|
|
757
|
+
const line = buffer
|
|
758
|
+
.subarray(0, newlineIndex)
|
|
759
|
+
.toString("utf8")
|
|
760
|
+
.replace(/\r$/u, "");
|
|
761
|
+
const remaining = buffer.subarray(newlineIndex + 1);
|
|
762
|
+
if (line.trim().length === 0) {
|
|
763
|
+
return extractJsonLinePayload(remaining);
|
|
764
|
+
}
|
|
765
|
+
return {
|
|
766
|
+
kind: "payload",
|
|
767
|
+
payload: line,
|
|
768
|
+
remaining,
|
|
769
|
+
transportEncoding: "jsonl",
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
function extractTrailingJsonLine(buffer) {
|
|
773
|
+
const payload = buffer.toString("utf8").trim();
|
|
774
|
+
return payload.length > 0 ? payload : undefined;
|
|
775
|
+
}
|
|
776
|
+
function toBuffer(chunk) {
|
|
777
|
+
return typeof chunk === "string" ? Buffer.from(chunk, "utf8") : chunk;
|
|
778
|
+
}
|
|
779
|
+
function isRecord(value) {
|
|
780
|
+
return value !== null && typeof value === "object";
|
|
781
|
+
}
|
|
782
|
+
function toErrorMessage(error) {
|
|
783
|
+
if (error instanceof Error) {
|
|
784
|
+
return error.message;
|
|
785
|
+
}
|
|
786
|
+
if (typeof error === "string") {
|
|
787
|
+
return error;
|
|
788
|
+
}
|
|
789
|
+
return "Unknown error";
|
|
790
|
+
}
|