cool-workflow 0.1.98 → 0.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/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +11 -2
- package/apps/architecture-review/app.json +1 -1
- package/apps/architecture-review-fast/app.json +1 -1
- package/apps/end-to-end-golden-path/app.json +1 -1
- package/apps/pr-review-fix-ci/app.json +1 -1
- package/apps/release-cut/app.json +1 -1
- package/apps/research-synthesis/app.json +1 -1
- package/dist/cli/dispatch.js +236 -0
- package/dist/cli/entry.js +120 -0
- package/dist/cli/io.js +21 -4
- package/dist/cli/parseargv.js +157 -0
- package/dist/cli.js +6 -33
- package/dist/core/capability-table.js +3534 -0
- package/dist/core/format/help.js +314 -0
- package/dist/{state-explosion/format.js → core/format/state-explosion-text.js} +10 -1
- package/dist/core/hash.js +137 -0
- package/dist/core/multi-agent/candidate-scoring.js +219 -0
- package/dist/core/multi-agent/collaboration.js +481 -0
- package/dist/core/multi-agent/coordinator.js +515 -0
- package/dist/core/multi-agent/eval-replay.js +306 -0
- package/dist/core/multi-agent/runtime.js +929 -0
- package/dist/core/multi-agent/topology.js +298 -0
- package/dist/core/multi-agent/trust-policy.js +197 -0
- package/dist/core/pipeline/commit-gate.js +320 -0
- package/dist/{pipeline-contract.js → core/pipeline/contract.js} +24 -37
- package/dist/core/pipeline/dispatch.js +103 -0
- package/dist/core/pipeline/drive-decide.js +227 -0
- package/dist/core/pipeline/error-feedback.js +161 -0
- package/dist/core/pipeline/loop-expansion.js +124 -0
- package/dist/{result-normalize.js → core/pipeline/result-normalize.js} +14 -37
- package/dist/core/pipeline/runner.js +230 -0
- package/dist/{contract-migration.js → core/state/contract-migration.js} +68 -92
- package/dist/{state-migrations.js → core/state/migrations.js} +103 -96
- package/dist/core/state/node-projection.js +95 -0
- package/dist/core/state/node-snapshot.js +230 -0
- package/dist/core/state/run-paths.js +93 -0
- package/dist/{schema-validate.js → core/state/schema-validate.js} +35 -28
- package/dist/core/state/schema.js +50 -0
- package/dist/core/state/state-explosion/digest.js +243 -0
- package/dist/core/state/state-explosion/graph.js +527 -0
- package/dist/{state-explosion → core/state/state-explosion}/helpers.js +34 -3
- package/dist/core/state/state-explosion/report.js +187 -0
- package/dist/{state-explosion → core/state/state-explosion}/size.js +25 -7
- package/dist/{state-node.js → core/state/state-node.js} +90 -113
- package/dist/core/state/types.js +19 -0
- package/dist/{validation.js → core/state/validation.js} +64 -131
- package/dist/core/trust/evidence-grounding.js +134 -0
- package/dist/core/trust/ledger.js +199 -0
- package/dist/{telemetry-attestation.js → core/trust/telemetry-attestation.js} +94 -68
- package/dist/core/trust/telemetry-ledger.js +127 -0
- package/dist/core/types.js +20 -0
- package/dist/core/version.js +16 -0
- package/dist/{workflow-app-framework.js → core/workflow-apps/app-schema.js} +337 -426
- package/dist/mcp/dispatch.js +104 -0
- package/dist/mcp/server.js +144 -0
- package/dist/mcp-server.js +6 -84
- package/dist/{agent-config.js → shell/agent-config.js} +118 -71
- package/dist/shell/app-run-cli.js +88 -0
- package/dist/shell/audit-cli.js +259 -0
- package/dist/shell/audit-provenance.js +83 -0
- package/dist/shell/candidate-scoring-io.js +459 -0
- package/dist/shell/collaboration-io.js +264 -0
- package/dist/shell/commit-summary.js +104 -0
- package/dist/shell/commit.js +290 -0
- package/dist/shell/coordinator-io.js +476 -0
- package/dist/shell/demo-cli.js +19 -0
- package/dist/shell/dispatch.js +162 -0
- package/dist/{doctor.js → shell/doctor.js} +123 -56
- package/dist/shell/drive.js +873 -0
- package/dist/shell/error-feedback-io.js +305 -0
- package/dist/shell/eval-io.js +473 -0
- package/dist/{multi-agent-eval/format.js → shell/eval-text.js} +78 -49
- package/dist/{evidence-reasoning.js → shell/evidence-reasoning.js} +124 -255
- package/dist/shell/exec-backend-cli.js +88 -0
- package/dist/shell/execution-backend/agent.js +475 -0
- package/dist/shell/execution-backend/ci.js +15 -0
- package/dist/shell/execution-backend/container.js +69 -0
- package/dist/shell/execution-backend/envelopes.js +55 -0
- package/dist/shell/execution-backend/local.js +113 -0
- package/dist/shell/execution-backend/probes.js +175 -0
- package/dist/shell/execution-backend/registry.js +402 -0
- package/dist/shell/execution-backend/remote.js +128 -0
- package/dist/shell/execution-backend/types.js +11 -0
- package/dist/shell/feedback-cli.js +81 -0
- package/dist/shell/feedback-operations.js +48 -0
- package/dist/shell/fs-atomic.js +276 -0
- package/dist/shell/harness.js +98 -0
- package/dist/shell/ledger-cli.js +212 -0
- package/dist/shell/ledger-io.js +169 -0
- package/dist/shell/man-cli.js +89 -0
- package/dist/shell/metrics-cli.js +98 -0
- package/dist/shell/multi-agent-cli.js +1002 -0
- package/dist/shell/multi-agent-host.js +563 -0
- package/dist/shell/multi-agent-io.js +387 -0
- package/dist/{multi-agent-operator-ux.js → shell/multi-agent-operator-ux.js} +234 -191
- package/dist/shell/node-store.js +124 -0
- package/dist/{observability/format.js → shell/observability-format.js} +7 -1
- package/dist/{observability/intake.js → shell/observability-intake.js} +79 -56
- package/dist/{observability.js → shell/observability.js} +159 -332
- package/dist/{onramp.js → shell/onramp.js} +11 -0
- package/dist/{operator-ux/format.js → shell/operator-ux-text.js} +250 -239
- package/dist/shell/operator-ux.js +431 -0
- package/dist/shell/orchestrator.js +231 -0
- package/dist/shell/pipeline-cli.js +667 -0
- package/dist/shell/pipeline.js +217 -0
- package/dist/shell/reclamation-io.js +1366 -0
- package/dist/shell/registry-cli.js +329 -0
- package/dist/{remote-source.js → shell/remote-source.js} +2 -2
- package/dist/shell/report-cli.js +101 -0
- package/dist/shell/report-view-cli.js +117 -0
- package/dist/{orchestrator → shell}/report.js +289 -282
- package/dist/shell/reporter.js +62 -0
- package/dist/shell/run-export-cli.js +106 -0
- package/dist/shell/run-export.js +680 -0
- package/dist/shell/run-registry-io.js +1014 -0
- package/dist/shell/run-store.js +164 -0
- package/dist/{sandbox-profile.js → shell/sandbox-profile.js} +134 -95
- package/dist/{scheduler.js → shell/scheduler-io.js} +248 -48
- package/dist/shell/scheduling-io.js +311 -0
- package/dist/shell/state-cli.js +181 -0
- package/dist/shell/state-explosion-cli.js +197 -0
- package/dist/shell/telemetry-cli.js +85 -0
- package/dist/{telemetry-demo.js → shell/telemetry-demo.js} +149 -119
- package/dist/shell/telemetry-ledger-io.js +132 -0
- package/dist/{term.js → shell/term.js} +36 -46
- package/dist/shell/topology-io.js +361 -0
- package/dist/shell/trust-audit.js +471 -0
- package/dist/{multi-agent-trust.js → shell/trust-policy-io.js} +67 -205
- package/dist/shell/verifier.js +48 -0
- package/dist/shell/workbench-host.js +250 -0
- package/dist/shell/workbench-text.js +18 -0
- package/dist/shell/workbench.js +175 -0
- package/dist/shell/worker-cli.js +124 -0
- package/dist/shell/worker-isolation.js +852 -0
- package/dist/shell/workflow-app-loader.js +650 -0
- package/docs/agent-delegation-drive.7.md +2 -0
- package/docs/cli-mcp-parity.7.md +280 -219
- package/docs/contract-migration-tooling.7.md +2 -0
- package/docs/control-plane-scheduling.7.md +2 -0
- package/docs/durable-state-and-locking.7.md +2 -0
- package/docs/evidence-adoption-reasoning-chain.7.md +2 -0
- package/docs/execution-backends.7.md +2 -0
- package/docs/multi-agent-cli-mcp-surface.7.md +2 -0
- package/docs/multi-agent-eval-replay-harness.7.md +2 -0
- package/docs/multi-agent-operator-ux.7.md +2 -0
- package/docs/node-snapshot-diff-replay.7.md +2 -0
- package/docs/observability-cost-accounting.7.md +2 -0
- package/docs/project-index.md +132 -71
- package/docs/real-execution-backends.7.md +2 -0
- package/docs/release-and-migration.7.md +2 -0
- package/docs/release-tooling.7.md +2 -0
- package/docs/run-registry-control-plane.7.md +2 -0
- package/docs/run-retention-reclamation.7.md +23 -0
- package/docs/state-explosion-management.7.md +2 -0
- package/docs/team-collaboration.7.md +2 -0
- package/docs/web-desktop-workbench.7.md +2 -0
- package/manifest/plugin.manifest.json +1 -1
- package/manifest/source-context-profiles.json +9 -13
- package/package.json +1 -1
- package/scripts/agents/cw-attest-wrap.js +2 -2
- package/scripts/bump-version.js +4 -3
- package/scripts/canonical-apps.js +4 -4
- package/scripts/dogfood-architecture-review.js +2 -3
- package/scripts/dogfood-release.js +3 -3
- package/scripts/gen-parity-doc.js +15 -2
- package/scripts/golden-path.js +4 -4
- package/scripts/onramp-check.js +1 -1
- package/scripts/parity-check.js +38 -21
- package/scripts/release-flow.js +2 -2
- package/scripts/sync-project-index.js +51 -27
- package/scripts/validate-run-state-schema.js +2 -2
- package/scripts/version-sync-check.js +30 -30
- package/dist/candidate-scoring.js +0 -729
- package/dist/capability-core.js +0 -1189
- package/dist/capability-registry.js +0 -885
- package/dist/cli/command-surface.js +0 -494
- package/dist/cli/format.js +0 -56
- package/dist/cli/handlers/audit.js +0 -82
- package/dist/cli/handlers/blackboard.js +0 -81
- package/dist/cli/handlers/candidate.js +0 -40
- package/dist/cli/handlers/clones.js +0 -34
- package/dist/cli/handlers/collaboration.js +0 -61
- package/dist/cli/handlers/eval.js +0 -40
- package/dist/cli/handlers/ledger.js +0 -169
- package/dist/cli/handlers/maintenance.js +0 -107
- package/dist/cli/handlers/multi-agent.js +0 -165
- package/dist/cli/handlers/node.js +0 -41
- package/dist/cli/handlers/operational.js +0 -155
- package/dist/cli/handlers/operator.js +0 -146
- package/dist/cli/handlers/registry.js +0 -68
- package/dist/cli/handlers/run.js +0 -153
- package/dist/cli/handlers/scheduling.js +0 -132
- package/dist/cli/handlers/workbench.js +0 -41
- package/dist/cli/handlers/worker.js +0 -45
- package/dist/cli/run-summary.js +0 -45
- package/dist/clones.js +0 -162
- package/dist/collaboration.js +0 -726
- package/dist/commit.js +0 -592
- package/dist/compare.js +0 -18
- package/dist/coordinator/classify.js +0 -45
- package/dist/coordinator/paths.js +0 -42
- package/dist/coordinator/util.js +0 -126
- package/dist/coordinator.js +0 -990
- package/dist/daemon.js +0 -44
- package/dist/dispatch.js +0 -250
- package/dist/drive.js +0 -864
- package/dist/error-feedback.js +0 -419
- package/dist/evidence-grounding.js +0 -184
- package/dist/execution-backend/agent.js +0 -354
- package/dist/execution-backend/probes.js +0 -112
- package/dist/execution-backend/util.js +0 -47
- package/dist/execution-backend.js +0 -961
- package/dist/gates.js +0 -48
- package/dist/harness.js +0 -61
- package/dist/ledger.js +0 -313
- package/dist/loop-expansion.js +0 -60
- package/dist/mcp/tool-call.js +0 -470
- package/dist/mcp/tool-definitions.js +0 -1066
- package/dist/mcp-surface.js +0 -30
- package/dist/multi-agent/graph.js +0 -84
- package/dist/multi-agent/helpers.js +0 -141
- package/dist/multi-agent/ids.js +0 -20
- package/dist/multi-agent/paths.js +0 -22
- package/dist/multi-agent-eval/normalize.js +0 -51
- package/dist/multi-agent-eval.js +0 -678
- package/dist/multi-agent-host.js +0 -777
- package/dist/multi-agent.js +0 -984
- package/dist/node-projection.js +0 -59
- package/dist/node-snapshot.js +0 -260
- package/dist/operator-ux.js +0 -631
- package/dist/orchestrator/app-operations.js +0 -211
- package/dist/orchestrator/audit-operations.js +0 -182
- package/dist/orchestrator/candidate-operations.js +0 -117
- package/dist/orchestrator/cli-options.js +0 -294
- package/dist/orchestrator/collaboration-operations.js +0 -86
- package/dist/orchestrator/feedback-operations.js +0 -81
- package/dist/orchestrator/host-operations.js +0 -78
- package/dist/orchestrator/lifecycle-operations.js +0 -650
- package/dist/orchestrator/migration-operations.js +0 -44
- package/dist/orchestrator/multi-agent-operations.js +0 -362
- package/dist/orchestrator/topology-operations.js +0 -84
- package/dist/orchestrator.js +0 -925
- package/dist/pipeline-runner.js +0 -285
- package/dist/reclamation/hash.js +0 -72
- package/dist/reclamation.js +0 -812
- package/dist/reporter.js +0 -67
- package/dist/run-export.js +0 -815
- package/dist/run-registry/derive.js +0 -175
- package/dist/run-registry/format.js +0 -124
- package/dist/run-registry/gc.js +0 -251
- package/dist/run-registry/policy.js +0 -16
- package/dist/run-registry/queue.js +0 -115
- package/dist/run-registry.js +0 -850
- package/dist/run-state-schema.js +0 -68
- package/dist/scheduling.js +0 -184
- package/dist/state-explosion.js +0 -1014
- package/dist/state.js +0 -367
- package/dist/telemetry-ledger.js +0 -196
- package/dist/topology.js +0 -565
- package/dist/triggers.js +0 -184
- package/dist/trust-audit.js +0 -644
- package/dist/types/blackboard.js +0 -2
- package/dist/types/candidate.js +0 -2
- package/dist/types/collaboration.js +0 -2
- package/dist/types/core.js +0 -2
- package/dist/types/drive.js +0 -10
- package/dist/types/error-feedback.js +0 -2
- package/dist/types/evidence-reasoning.js +0 -2
- package/dist/types/execution-backend.js +0 -2
- package/dist/types/multi-agent.js +0 -2
- package/dist/types/observability.js +0 -2
- package/dist/types/pipeline.js +0 -2
- package/dist/types/reclamation.js +0 -8
- package/dist/types/report-bundle.js +0 -6
- package/dist/types/result.js +0 -2
- package/dist/types/run-registry.js +0 -2
- package/dist/types/run.js +0 -2
- package/dist/types/sandbox.js +0 -2
- package/dist/types/schedule.js +0 -2
- package/dist/types/state-node.js +0 -2
- package/dist/types/topology.js +0 -2
- package/dist/types/trust.js +0 -2
- package/dist/types/workbench.js +0 -2
- package/dist/types/worker.js +0 -2
- package/dist/types/workflow-app.js +0 -2
- package/dist/types.js +0 -44
- package/dist/util/fingerprint.js +0 -19
- package/dist/util/fingerprint.test.js +0 -27
- package/dist/verifier.js +0 -78
- package/dist/version.js +0 -8
- package/dist/workbench-host.js +0 -192
- package/dist/workbench.js +0 -192
- package/dist/worker-accept/acceptance.js +0 -114
- package/dist/worker-accept/blackboard-fanout.js +0 -80
- package/dist/worker-accept/blackboard-linkage.js +0 -19
- package/dist/worker-accept/context.js +0 -2
- package/dist/worker-accept/telemetry-ledger.js +0 -126
- package/dist/worker-accept/validation.js +0 -77
- package/dist/worker-accept/verifier-completion.js +0 -73
- package/dist/worker-isolation/helpers.js +0 -51
- package/dist/worker-isolation/paths.js +0 -46
- package/dist/worker-isolation.js +0 -656
- package/dist/workflow-api.js +0 -131
- /package/dist/{types → core/types}/boundary.js +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// shell/exec-backend-cli.ts — CLI/MCP-reachable bodies for the execution-
|
|
3
|
+
// backend + sandbox-profile capability rows (backend.list|show|probe,
|
|
4
|
+
// backend.agent.config.show|set, sandbox.list|show|validate).
|
|
5
|
+
//
|
|
6
|
+
// MILESTONE 5. Byte-exact port of the old build's orchestrator methods
|
|
7
|
+
// (src/orchestrator.ts:260-284 listSandboxProfiles/showSandboxProfile/
|
|
8
|
+
// validateSandboxProfile/listBackends/showBackend/probeBackend) plus
|
|
9
|
+
// src/cli/handlers/operational.ts's handleSandbox/handleBackend argv
|
|
10
|
+
// shape. Impure (fs/env) — this is the shell layer the capability-table's
|
|
11
|
+
// CLI/MCP handlers delegate to.
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.backendAgentConfigShow = exports.backendAgentConfigSet = void 0;
|
|
47
|
+
exports.listSandboxProfilesCli = listSandboxProfilesCli;
|
|
48
|
+
exports.showSandboxProfileCli = showSandboxProfileCli;
|
|
49
|
+
exports.validateSandboxProfileCli = validateSandboxProfileCli;
|
|
50
|
+
exports.listBackendsCli = listBackendsCli;
|
|
51
|
+
exports.showBackendCli = showBackendCli;
|
|
52
|
+
exports.probeBackendCli = probeBackendCli;
|
|
53
|
+
const path = __importStar(require("node:path"));
|
|
54
|
+
const registry_1 = require("./execution-backend/registry");
|
|
55
|
+
const sandbox_profile_1 = require("./sandbox-profile");
|
|
56
|
+
const agent_config_1 = require("./agent-config");
|
|
57
|
+
Object.defineProperty(exports, "backendAgentConfigSet", { enumerable: true, get: function () { return agent_config_1.backendAgentConfigSet; } });
|
|
58
|
+
Object.defineProperty(exports, "backendAgentConfigShow", { enumerable: true, get: function () { return agent_config_1.backendAgentConfigShow; } });
|
|
59
|
+
function resolveCwd(options) {
|
|
60
|
+
return path.resolve(String(options.cwd || process.cwd()));
|
|
61
|
+
}
|
|
62
|
+
function resolveFromBase(target, options) {
|
|
63
|
+
return path.resolve(resolveCwd(options), target);
|
|
64
|
+
}
|
|
65
|
+
// ---------------------------------------------------------------------
|
|
66
|
+
// sandbox.list | sandbox.show | sandbox.validate
|
|
67
|
+
// ---------------------------------------------------------------------
|
|
68
|
+
function listSandboxProfilesCli(options = {}) {
|
|
69
|
+
return (0, sandbox_profile_1.listBundledSandboxProfiles)((0, sandbox_profile_1.sandboxContextForValidation)(resolveCwd(options)));
|
|
70
|
+
}
|
|
71
|
+
function showSandboxProfileCli(profileId, options = {}) {
|
|
72
|
+
return (0, sandbox_profile_1.showBundledSandboxProfile)(profileId, (0, sandbox_profile_1.sandboxContextForValidation)(resolveCwd(options)));
|
|
73
|
+
}
|
|
74
|
+
function validateSandboxProfileCli(profileFile, options = {}) {
|
|
75
|
+
return (0, sandbox_profile_1.validateSandboxProfileFile)(resolveFromBase(profileFile, options), (0, sandbox_profile_1.sandboxContextForValidation)(resolveCwd(options)));
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------
|
|
78
|
+
// backend.list | backend.show | backend.probe
|
|
79
|
+
// ---------------------------------------------------------------------
|
|
80
|
+
function listBackendsCli() {
|
|
81
|
+
return (0, registry_1.backendListPayload)();
|
|
82
|
+
}
|
|
83
|
+
function showBackendCli(backendId) {
|
|
84
|
+
return (0, registry_1.backendShowPayload)(backendId);
|
|
85
|
+
}
|
|
86
|
+
function probeBackendCli(backendId, options = {}) {
|
|
87
|
+
return (0, registry_1.backendProbePayload)(backendId, { cwd: resolveCwd(options) });
|
|
88
|
+
}
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// shell/execution-backend/agent.ts — agent-delegation pure helpers +
|
|
3
|
+
// concurrent batch fulfillment.
|
|
4
|
+
//
|
|
5
|
+
// MILESTONE 5 (v2/PLAN.md build order, step 5). Byte-exact port of
|
|
6
|
+
// plugins/cool-workflow/src/execution-backend/agent.ts. This module holds
|
|
7
|
+
// the PURE data-transform helpers (invocation resolution, arg substitution,
|
|
8
|
+
// secret redaction, report parsing) plus the batch delegate-child spawn.
|
|
9
|
+
//
|
|
10
|
+
// THE RED LINE: CW spawns the agent and records its attested output. It
|
|
11
|
+
// NEVER imports a model SDK, holds an API key, or constructs a model API
|
|
12
|
+
// request. Any API key flows from the agent's OWN inherited env; CW never
|
|
13
|
+
// reads or records it. The operator-chosen CW_AGENT_MODEL is interpolated
|
|
14
|
+
// into `{{model}}` as policy and recorded ONLY in secret-stripped args — it
|
|
15
|
+
// is NEVER the attested model id.
|
|
16
|
+
//
|
|
17
|
+
// Evidence: SPEC/execution-backend.md "agent driver", "Concurrent batch".
|
|
18
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(o, k2, desc);
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
35
|
+
var ownKeys = function(o) {
|
|
36
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
37
|
+
var ar = [];
|
|
38
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
39
|
+
return ar;
|
|
40
|
+
};
|
|
41
|
+
return ownKeys(o);
|
|
42
|
+
};
|
|
43
|
+
return function (mod) {
|
|
44
|
+
if (mod && mod.__esModule) return mod;
|
|
45
|
+
var result = {};
|
|
46
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
47
|
+
__setModuleDefault(result, mod);
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
})();
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
exports.resolveAgentInvocation = resolveAgentInvocation;
|
|
53
|
+
exports.stripSecretArgs = stripSecretArgs;
|
|
54
|
+
exports.parseAgentReport = parseAgentReport;
|
|
55
|
+
exports.agentSubstitutions = agentSubstitutions;
|
|
56
|
+
exports.substituteAgentArg = substituteAgentArg;
|
|
57
|
+
exports.recordedAgentHandle = recordedAgentHandle;
|
|
58
|
+
exports.extractEndpointResult = extractEndpointResult;
|
|
59
|
+
exports.agentHandle = agentHandle;
|
|
60
|
+
exports.prepareAgentSpawn = prepareAgentSpawn;
|
|
61
|
+
exports.reconcileBatchOutcomes = reconcileBatchOutcomes;
|
|
62
|
+
exports.runAgentBatchOutcomes = runAgentBatchOutcomes;
|
|
63
|
+
exports.shouldStreamAgentStderr = shouldStreamAgentStderr;
|
|
64
|
+
exports.runAgentProcess = runAgentProcess;
|
|
65
|
+
const fs = __importStar(require("node:fs"));
|
|
66
|
+
const path = __importStar(require("node:path"));
|
|
67
|
+
const node_child_process_1 = require("node:child_process");
|
|
68
|
+
const local_1 = require("./local");
|
|
69
|
+
const envelopes_1 = require("./envelopes");
|
|
70
|
+
function messageOf(error) {
|
|
71
|
+
return error instanceof Error ? error.message : String(error);
|
|
72
|
+
}
|
|
73
|
+
/** Resolve the agent invocation from the request delegation > env.
|
|
74
|
+
* Vendor-neutral; the durable file config is folded in by the drive layer
|
|
75
|
+
* before this point (see shell/agent-config.ts's resolveAgentConfig). */
|
|
76
|
+
function resolveAgentInvocation(request, env = process.env) {
|
|
77
|
+
const delegation = request.delegation || {};
|
|
78
|
+
const envCommand = (env.CW_AGENT_COMMAND || "").trim();
|
|
79
|
+
const endpoint = delegation.endpoint || (env.CW_AGENT_ENDPOINT || "").trim() || undefined;
|
|
80
|
+
const model = delegation.model || (env.CW_AGENT_MODEL || "").trim() || undefined;
|
|
81
|
+
let binary = delegation.command || request.command || undefined;
|
|
82
|
+
let rawArgs = delegation.args ? [...delegation.args] : request.args ? [...request.args] : [];
|
|
83
|
+
if (!binary && envCommand) {
|
|
84
|
+
const parts = envCommand.split(/\s+/).filter(Boolean);
|
|
85
|
+
binary = parts[0];
|
|
86
|
+
if (!delegation.args)
|
|
87
|
+
rawArgs = parts.slice(1);
|
|
88
|
+
}
|
|
89
|
+
else if (binary && !delegation.args && /\s/.test(binary)) {
|
|
90
|
+
const parts = binary.split(/\s+/).filter(Boolean);
|
|
91
|
+
binary = parts[0];
|
|
92
|
+
rawArgs = parts.slice(1);
|
|
93
|
+
}
|
|
94
|
+
return { binary, rawArgs, endpoint, model, timeoutMs: request.timeoutMs };
|
|
95
|
+
}
|
|
96
|
+
const AGENT_SECRET_FLAGS = new Set([
|
|
97
|
+
"--api-key",
|
|
98
|
+
"--apikey",
|
|
99
|
+
"--token",
|
|
100
|
+
"--key",
|
|
101
|
+
"--secret",
|
|
102
|
+
"--password",
|
|
103
|
+
"--auth",
|
|
104
|
+
"--bearer",
|
|
105
|
+
]);
|
|
106
|
+
/** Redact secrets from recorded agent args: a value FOLLOWING a known secret
|
|
107
|
+
* flag, an `--x-key=...` inline value, or a token that LOOKS like a
|
|
108
|
+
* credential. Never record a raw secret in provenance/evidence. */
|
|
109
|
+
function stripSecretArgs(args) {
|
|
110
|
+
const out = [];
|
|
111
|
+
for (let i = 0; i < args.length; i++) {
|
|
112
|
+
const arg = String(args[i]);
|
|
113
|
+
if (AGENT_SECRET_FLAGS.has(arg.toLowerCase())) {
|
|
114
|
+
out.push(arg);
|
|
115
|
+
if (i + 1 < args.length) {
|
|
116
|
+
out.push("<redacted>");
|
|
117
|
+
i++;
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const inline = arg.match(/^(--?[A-Za-z][\w-]*(?:key|token|secret|password|auth|bearer)[\w-]*)=.*/i);
|
|
122
|
+
if (inline) {
|
|
123
|
+
out.push(`${inline[1]}=<redacted>`);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (/^(sk-|ghp_|gho_|github_pat_|xox[abpr]-|Bearer\s)/.test(arg) ||
|
|
127
|
+
(arg.length >= 32 && /^[A-Za-z0-9_-]{32,}$/.test(arg))) {
|
|
128
|
+
out.push("<redacted>");
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
out.push(arg);
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
/** Best-effort parse of the AGENT-reported model id from its stdout. SOLELY
|
|
136
|
+
* the agent's own report — `unreported` when absent. Never CW_AGENT_MODEL. */
|
|
137
|
+
function parseAgentReport(stdout) {
|
|
138
|
+
const text = String(stdout || "").trim();
|
|
139
|
+
if (!text)
|
|
140
|
+
return {};
|
|
141
|
+
const tryObj = (value) => {
|
|
142
|
+
try {
|
|
143
|
+
const parsed = JSON.parse(value);
|
|
144
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : undefined;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
let obj = tryObj(text);
|
|
151
|
+
if (!obj) {
|
|
152
|
+
const line = text
|
|
153
|
+
.split(/\r?\n/)
|
|
154
|
+
.reverse()
|
|
155
|
+
.find((entry) => entry.trim().startsWith("{") && entry.trim().endsWith("}"));
|
|
156
|
+
if (line)
|
|
157
|
+
obj = tryObj(line.trim());
|
|
158
|
+
}
|
|
159
|
+
if (!obj)
|
|
160
|
+
return {};
|
|
161
|
+
const usage = obj.usage && typeof obj.usage === "object" ? obj.usage : undefined;
|
|
162
|
+
let model = typeof obj.model === "string"
|
|
163
|
+
? obj.model
|
|
164
|
+
: usage && typeof usage.model === "string"
|
|
165
|
+
? usage.model
|
|
166
|
+
: typeof obj.modelId === "string"
|
|
167
|
+
? obj.modelId
|
|
168
|
+
: undefined;
|
|
169
|
+
if (!model && obj.modelUsage && typeof obj.modelUsage === "object" && !Array.isArray(obj.modelUsage)) {
|
|
170
|
+
const entries = Object.entries(obj.modelUsage);
|
|
171
|
+
if (entries.length) {
|
|
172
|
+
const tokensOf = (value) => {
|
|
173
|
+
const record = value && typeof value === "object" ? value : {};
|
|
174
|
+
const input = Number(record.inputTokens ?? record.input_tokens ?? 0);
|
|
175
|
+
return Number.isFinite(input) ? input : 0;
|
|
176
|
+
};
|
|
177
|
+
entries.sort((left, right) => tokensOf(right[1]) - tokensOf(left[1]));
|
|
178
|
+
model = entries[0][0];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const usageSignature = typeof obj.usageSignature === "string"
|
|
182
|
+
? obj.usageSignature
|
|
183
|
+
: typeof obj.usage_signature === "string"
|
|
184
|
+
? obj.usage_signature
|
|
185
|
+
: undefined;
|
|
186
|
+
return { model, usage, usageSignature };
|
|
187
|
+
}
|
|
188
|
+
function agentSubstitutions(request, model) {
|
|
189
|
+
const manifest = request.manifest;
|
|
190
|
+
const workerDir = manifest?.workerDir || request.cwd || "";
|
|
191
|
+
return {
|
|
192
|
+
manifest: manifest?.manifestPath || (workerDir ? path.join(workerDir, "manifest.json") : ""),
|
|
193
|
+
input: manifest?.inputPath || "",
|
|
194
|
+
result: manifest?.resultPath || "",
|
|
195
|
+
workerDir,
|
|
196
|
+
model: model || "",
|
|
197
|
+
prompt: manifest?.prompt || "",
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function substituteAgentArg(arg, subst) {
|
|
201
|
+
return arg.replace(/\{\{(\w+)\}\}/g, (_, key) => (key in subst ? subst[key] : `{{${key}}}`));
|
|
202
|
+
}
|
|
203
|
+
/** Build the recorded process handle for the envelope — secret-stripped +
|
|
204
|
+
* the agent-reported model. Same SHAPE that lands in provenance, never in
|
|
205
|
+
* evidence. */
|
|
206
|
+
function recordedAgentHandle(binary, endpoint, recordedArgs, model, reportedModel, reportedUsage, usageSignature) {
|
|
207
|
+
const ref = binary ? [binary, ...recordedArgs].join(" ") : endpoint || "";
|
|
208
|
+
return {
|
|
209
|
+
kind: "process",
|
|
210
|
+
ref,
|
|
211
|
+
endpoint,
|
|
212
|
+
metadata: {
|
|
213
|
+
mode: binary ? "command" : "endpoint",
|
|
214
|
+
command: binary,
|
|
215
|
+
args: recordedArgs,
|
|
216
|
+
model,
|
|
217
|
+
reportedModel,
|
|
218
|
+
...(reportedUsage ? { reportedUsage } : {}),
|
|
219
|
+
...(usageSignature ? { usageSignature } : {}),
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function extractEndpointResult(stdout) {
|
|
224
|
+
const text = String(stdout || "").trim();
|
|
225
|
+
if (!text)
|
|
226
|
+
return undefined;
|
|
227
|
+
try {
|
|
228
|
+
const parsed = JSON.parse(text);
|
|
229
|
+
if (parsed && typeof parsed === "object") {
|
|
230
|
+
if (typeof parsed.result === "string")
|
|
231
|
+
return parsed.result;
|
|
232
|
+
if (typeof parsed.resultMarkdown === "string") {
|
|
233
|
+
return parsed.resultMarkdown;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch {
|
|
238
|
+
return text;
|
|
239
|
+
}
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
function agentHandle(request, env = process.env) {
|
|
243
|
+
const resolved = resolveAgentInvocation(request, env);
|
|
244
|
+
if (!resolved.binary && !resolved.endpoint)
|
|
245
|
+
return undefined;
|
|
246
|
+
const strippedArgs = stripSecretArgs(resolved.rawArgs);
|
|
247
|
+
const ref = resolved.binary ? [resolved.binary, ...strippedArgs].join(" ") : resolved.endpoint || "";
|
|
248
|
+
return {
|
|
249
|
+
kind: "process",
|
|
250
|
+
ref,
|
|
251
|
+
endpoint: resolved.endpoint,
|
|
252
|
+
metadata: {
|
|
253
|
+
mode: resolved.binary ? "command" : "endpoint",
|
|
254
|
+
command: resolved.binary,
|
|
255
|
+
args: strippedArgs,
|
|
256
|
+
model: resolved.model,
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Resolve a request to a spawn-style batch job, or undefined when the agent
|
|
261
|
+
* is endpoint-configured/unconfigured (those settle through the serial
|
|
262
|
+
* path). */
|
|
263
|
+
function prepareAgentSpawn(request) {
|
|
264
|
+
const resolved = resolveAgentInvocation(request);
|
|
265
|
+
if (!resolved.binary)
|
|
266
|
+
return undefined;
|
|
267
|
+
const subst = agentSubstitutions(request, resolved.model);
|
|
268
|
+
return {
|
|
269
|
+
binary: resolved.binary,
|
|
270
|
+
args: resolved.rawArgs.map((arg) => substituteAgentArg(arg, subst)),
|
|
271
|
+
cwd: request.cwd,
|
|
272
|
+
timeoutMs: resolved.timeoutMs || 600000,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
// __dirname is dist/shell/execution-backend at runtime — THREE levels up
|
|
276
|
+
// (execution-backend -> shell -> dist -> package root) reaches scripts/,
|
|
277
|
+
// a sibling of dist/, not two (that was a bug: it resolved to a
|
|
278
|
+
// dist/scripts/... path that is never compiled/copied there — batch
|
|
279
|
+
// concurrent dispatch failed closed with "batch delegate exited with 1"
|
|
280
|
+
// until this was traced to the wrong relative depth).
|
|
281
|
+
const BATCH_DELEGATE_CHILD_SCRIPT = path.resolve(__dirname, "..", "..", "..", "scripts", "children", "batch-delegate-child.js");
|
|
282
|
+
/** Parse the delegate child's NDJSON stdout and reconcile it against `jobs`
|
|
283
|
+
* by index. See SPEC/execution-backend.md "Concurrent batch" for the
|
|
284
|
+
* byte-boundary rationale (split on the raw newline byte, one line at a
|
|
285
|
+
* time, never decode the whole combined buffer as one string). */
|
|
286
|
+
function reconcileBatchOutcomes(jobs, child) {
|
|
287
|
+
const buf = Buffer.isBuffer(child.stdout) ? child.stdout : Buffer.from(String(child.stdout || ""), "utf8");
|
|
288
|
+
const byIndex = new Map();
|
|
289
|
+
let lineStart = 0;
|
|
290
|
+
for (let i = 0; i < buf.length; i++) {
|
|
291
|
+
if (buf[i] !== 0x0a)
|
|
292
|
+
continue;
|
|
293
|
+
const lineBuf = buf.subarray(lineStart, i);
|
|
294
|
+
lineStart = i + 1;
|
|
295
|
+
if (lineBuf.length === 0)
|
|
296
|
+
continue;
|
|
297
|
+
let parsed;
|
|
298
|
+
try {
|
|
299
|
+
parsed = JSON.parse(lineBuf.toString("utf8"));
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (typeof parsed.i !== "number" || parsed.i < 0 || parsed.i >= jobs.length)
|
|
305
|
+
continue;
|
|
306
|
+
byIndex.set(parsed.i, {
|
|
307
|
+
...(parsed.spawnError ? { spawnError: parsed.spawnError } : {}),
|
|
308
|
+
exitCode: typeof parsed.exitCode === "number" ? parsed.exitCode : null,
|
|
309
|
+
stdout: String(parsed.stdout || ""),
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
const reason = child.error
|
|
313
|
+
? messageOf(child.error)
|
|
314
|
+
: typeof child.status === "number" && child.status !== 0
|
|
315
|
+
? `batch delegate exited with ${child.status}`
|
|
316
|
+
: "batch delegate produced no outcome for this job";
|
|
317
|
+
return jobs.map((_, index) => byIndex.get(index) || { spawnError: `batch delegate failed: ${reason}`, exitCode: null, stdout: "" });
|
|
318
|
+
}
|
|
319
|
+
/** Run a batch of agent spawns concurrently; outcomes index-align with
|
|
320
|
+
* jobs. See SPEC/execution-backend.md's rebuild-risk note on maxBuffer
|
|
321
|
+
* scaling with job count and the no-`encoding` (raw Buffer) requirement. */
|
|
322
|
+
function runAgentBatchOutcomes(jobs) {
|
|
323
|
+
if (!jobs.length)
|
|
324
|
+
return [];
|
|
325
|
+
const maxTimeout = Math.max(...jobs.map((job) => job.timeoutMs));
|
|
326
|
+
let child;
|
|
327
|
+
try {
|
|
328
|
+
child = (0, node_child_process_1.spawnSync)(process.execPath, [BATCH_DELEGATE_CHILD_SCRIPT], {
|
|
329
|
+
input: JSON.stringify(jobs),
|
|
330
|
+
maxBuffer: 34 * 1024 * 1024 * jobs.length,
|
|
331
|
+
timeout: maxTimeout + 30000,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
child = { error: error instanceof Error ? error : new Error(String(error)), status: null, stdout: null };
|
|
336
|
+
}
|
|
337
|
+
return reconcileBatchOutcomes(jobs, child);
|
|
338
|
+
}
|
|
339
|
+
// ---------------------------------------------------------------------------
|
|
340
|
+
// The stateful agent runners (spawn + settle). Byte-exact port of
|
|
341
|
+
// src/execution-backend.ts's runAgentProcess (:915-995), runAgentEndpoint
|
|
342
|
+
// (:1002-1062), and shouldStreamAgentStderr (:908-913).
|
|
343
|
+
// ---------------------------------------------------------------------------
|
|
344
|
+
/** Decide whether cw FORWARDS the agent wrapper's live stderr view (stdio
|
|
345
|
+
* "inherit") or captures it ("pipe"). CW_NO_STREAM=1 wins over everything;
|
|
346
|
+
* CW_AGENT_STREAM=0/1 are explicit off/on; else follow isTTY. */
|
|
347
|
+
function shouldStreamAgentStderr(env, isTTY) {
|
|
348
|
+
if (env.CW_NO_STREAM === "1")
|
|
349
|
+
return false;
|
|
350
|
+
if (env.CW_AGENT_STREAM === "0")
|
|
351
|
+
return false;
|
|
352
|
+
if (env.CW_AGENT_STREAM === "1")
|
|
353
|
+
return true;
|
|
354
|
+
return isTTY;
|
|
355
|
+
}
|
|
356
|
+
// Same package-root depth fix as BATCH_DELEGATE_CHILD_SCRIPT above.
|
|
357
|
+
const HTTP_DELEGATE_CHILD_SCRIPT = path.resolve(__dirname, "..", "..", "..", "scripts", "children", "http-delegate-child.js");
|
|
358
|
+
/** agent — spawns an EXTERNAL agent process per worker argv-style
|
|
359
|
+
* (shell:false), or POSTs the manifest to a configured HTTP agent
|
|
360
|
+
* endpoint. Byte-exact port of src/execution-backend.ts:915-995. */
|
|
361
|
+
function runAgentProcess(descriptor, policy, request, label, attestation) {
|
|
362
|
+
const resolved = resolveAgentInvocation(request);
|
|
363
|
+
const subst = agentSubstitutions(request, resolved.model);
|
|
364
|
+
if (resolved.binary) {
|
|
365
|
+
const realArgs = resolved.rawArgs.map((arg) => substituteAgentArg(arg, subst));
|
|
366
|
+
const recordedArgs = stripSecretArgs(realArgs);
|
|
367
|
+
let outcome;
|
|
368
|
+
if (request.preparedAgentOutcome) {
|
|
369
|
+
outcome = request.preparedAgentOutcome;
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
const streamStderr = shouldStreamAgentStderr(process.env, Boolean(process.stderr.isTTY));
|
|
373
|
+
const childEnv = (0, local_1.buildChildEnv)(policy);
|
|
374
|
+
for (const key of Object.keys(process.env)) {
|
|
375
|
+
if (/^(CW_|ANTHROPIC_|OPENAI_|GEMINI_|DEEPSEEK_|CODEX_|GOOGLE_|COHERE_|MISTRAL_|OLLAMA_|AZURE_|AWS_)/i.test(key)) {
|
|
376
|
+
childEnv[key] = process.env[key];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const child = (0, node_child_process_1.spawnSync)(resolved.binary, realArgs, {
|
|
380
|
+
cwd: request.cwd,
|
|
381
|
+
env: childEnv,
|
|
382
|
+
encoding: "utf8",
|
|
383
|
+
timeout: resolved.timeoutMs || 600000,
|
|
384
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
385
|
+
shell: false,
|
|
386
|
+
stdio: ["ignore", "pipe", streamStderr ? "inherit" : "pipe"],
|
|
387
|
+
});
|
|
388
|
+
outcome = {
|
|
389
|
+
...(child.error ? { spawnError: messageOf(child.error) } : {}),
|
|
390
|
+
exitCode: typeof child.status === "number" ? child.status : null,
|
|
391
|
+
stdout: String(child.stdout || ""),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
if (outcome.spawnError) {
|
|
395
|
+
const handleOut = recordedAgentHandle(resolved.binary, undefined, recordedArgs, resolved.model, "unreported");
|
|
396
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "delegation-failed", `agent process failed to spawn: ${outcome.spawnError}`, {
|
|
397
|
+
...attestation,
|
|
398
|
+
handle: handleOut,
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
const exitCode = outcome.exitCode;
|
|
402
|
+
const stdout = outcome.stdout;
|
|
403
|
+
const report = parseAgentReport(stdout);
|
|
404
|
+
const reportedModel = report.model && report.model.trim() ? report.model.trim() : "unreported";
|
|
405
|
+
const handleOut = recordedAgentHandle(resolved.binary, undefined, recordedArgs, resolved.model, reportedModel, report.usage, report.usageSignature);
|
|
406
|
+
if (exitCode === null) {
|
|
407
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "delegation-failed", `agent process returned no exit code (timed out or killed)`, { ...attestation, handle: handleOut });
|
|
408
|
+
}
|
|
409
|
+
return (0, envelopes_1.delegatedEnvelope)(descriptor, label, handleOut, { ...attestation, handle: handleOut }, resolved.binary, recordedArgs, exitCode, stdout);
|
|
410
|
+
}
|
|
411
|
+
if (resolved.endpoint) {
|
|
412
|
+
return runAgentEndpoint(descriptor, policy, request, label, resolved, attestation);
|
|
413
|
+
}
|
|
414
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "delegation-target-missing", `Backend ${descriptor.id} has no command-template or endpoint configured`, attestation);
|
|
415
|
+
}
|
|
416
|
+
/** Agent HTTP endpoint variant — POSTs the worker manifest/prompt to a
|
|
417
|
+
* configured agent endpoint via the shared Node delegate child. Byte-exact
|
|
418
|
+
* port of src/execution-backend.ts:1002-1062. */
|
|
419
|
+
function runAgentEndpoint(descriptor, policy, request, label, resolved, attestation) {
|
|
420
|
+
const endpoint = resolved.endpoint;
|
|
421
|
+
const manifest = request.manifest;
|
|
422
|
+
const job = JSON.stringify({
|
|
423
|
+
manifest,
|
|
424
|
+
prompt: manifest?.prompt,
|
|
425
|
+
model: resolved.model,
|
|
426
|
+
resultPath: manifest?.resultPath,
|
|
427
|
+
sandboxProfileId: policy.id,
|
|
428
|
+
});
|
|
429
|
+
const child = (0, node_child_process_1.spawnSync)(process.execPath, [HTTP_DELEGATE_CHILD_SCRIPT], {
|
|
430
|
+
input: job,
|
|
431
|
+
env: { ...process.env, CW_DELEGATE_ENDPOINT: endpoint },
|
|
432
|
+
encoding: "utf8",
|
|
433
|
+
timeout: resolved.timeoutMs || 600000,
|
|
434
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
435
|
+
});
|
|
436
|
+
const baseHandle = recordedAgentHandle(undefined, endpoint, [], resolved.model, "unreported");
|
|
437
|
+
if (child.error) {
|
|
438
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "delegation-failed", `agent endpoint delegation failed: ${messageOf(child.error)}`, {
|
|
439
|
+
...attestation,
|
|
440
|
+
handle: baseHandle,
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
let parsed;
|
|
444
|
+
try {
|
|
445
|
+
parsed = JSON.parse(String(child.stdout || "").trim() || "{}");
|
|
446
|
+
}
|
|
447
|
+
catch {
|
|
448
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "delegation-failed", `agent endpoint returned an unparseable response`, {
|
|
449
|
+
...attestation,
|
|
450
|
+
handle: baseHandle,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
if (parsed.error || typeof parsed.exitCode !== "number") {
|
|
454
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "delegation-failed", `agent endpoint error: ${parsed.error || "no exitCode reported"}`, {
|
|
455
|
+
...attestation,
|
|
456
|
+
handle: baseHandle,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
const stdout = String(parsed.stdout || "");
|
|
460
|
+
const report = parseAgentReport(stdout);
|
|
461
|
+
if (manifest?.resultPath && report.usage === undefined) {
|
|
462
|
+
const body = extractEndpointResult(stdout);
|
|
463
|
+
if (body && !fs.existsSync(manifest.resultPath)) {
|
|
464
|
+
try {
|
|
465
|
+
fs.writeFileSync(manifest.resultPath, body, "utf8");
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
/* the accept layer will fail closed on a missing result.md */
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const reportedModel = report.model && report.model.trim() ? report.model.trim() : "unreported";
|
|
473
|
+
const handleOut = recordedAgentHandle(undefined, endpoint, [], resolved.model, reportedModel, report.usage, report.usageSignature);
|
|
474
|
+
return (0, envelopes_1.delegatedEnvelope)(descriptor, label, handleOut, { ...attestation, handle: handleOut }, "agent-endpoint", [endpoint], parsed.exitCode, stdout);
|
|
475
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// shell/execution-backend/ci.ts — the ci delegating driver.
|
|
3
|
+
//
|
|
4
|
+
// MILESTONE 5 (v2/PLAN.md build order, step 5). The ci driver shares its
|
|
5
|
+
// entire HTTP-delegation body with the remote driver (byte-exact port of
|
|
6
|
+
// plugins/cool-workflow/src/execution-backend.ts, which also shares
|
|
7
|
+
// `runHttpDelegation` between the two); this file just re-exports the ci
|
|
8
|
+
// handle builder + the shared delegation runner under the ci-specific name
|
|
9
|
+
// so the registry's driver table reads naturally (one module per driver id,
|
|
10
|
+
// per PLAN.md's target shape `container.ts, remote.ts, ci.ts`).
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.runCiDelegation = exports.ciHandle = void 0;
|
|
13
|
+
var remote_1 = require("./remote");
|
|
14
|
+
Object.defineProperty(exports, "ciHandle", { enumerable: true, get: function () { return remote_1.ciHandle; } });
|
|
15
|
+
Object.defineProperty(exports, "runCiDelegation", { enumerable: true, get: function () { return remote_1.runHttpDelegation; } });
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// shell/execution-backend/container.ts — the container delegating driver.
|
|
3
|
+
//
|
|
4
|
+
// MILESTONE 5 (v2/PLAN.md build order, step 5). Byte-exact port of
|
|
5
|
+
// plugins/cool-workflow/src/execution-backend.ts's container handle builder
|
|
6
|
+
// (:1068-1075) and `runContainer` (:720-792).
|
|
7
|
+
//
|
|
8
|
+
// Evidence: SPEC/execution-backend.md "container driver (runContainer)".
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.containerHandle = containerHandle;
|
|
11
|
+
exports.runContainer = runContainer;
|
|
12
|
+
const node_child_process_1 = require("node:child_process");
|
|
13
|
+
const probes_1 = require("./probes");
|
|
14
|
+
const envelopes_1 = require("./envelopes");
|
|
15
|
+
function messageOf(error) {
|
|
16
|
+
return error instanceof Error ? error.message : String(error);
|
|
17
|
+
}
|
|
18
|
+
function containerHandle(request, env = process.env) {
|
|
19
|
+
const delegation = request.delegation || {};
|
|
20
|
+
const image = delegation.image || (env.CW_CONTAINER_IMAGE || "").trim() || undefined;
|
|
21
|
+
if (!image)
|
|
22
|
+
return undefined;
|
|
23
|
+
const digest = delegation.digest || (env.CW_CONTAINER_DIGEST || "").trim() || undefined;
|
|
24
|
+
const ref = digest ? `${image}@${digest}` : image;
|
|
25
|
+
return { kind: "container", ref, image, digest };
|
|
26
|
+
}
|
|
27
|
+
/** container — real `docker`/`podman run` under the sandbox contract. Fails
|
|
28
|
+
* closed when no runtime is on PATH, the daemon is unreachable, or the
|
|
29
|
+
* runtime itself errors (exit 125) — distinct from the command's own
|
|
30
|
+
* non-zero exit. Byte-exact port of src/execution-backend.ts:720-792. */
|
|
31
|
+
function runContainer(descriptor, policy, request, label, handle, attestation) {
|
|
32
|
+
const runtime = (0, probes_1.hasExecutable)("docker") ? "docker" : (0, probes_1.hasExecutable)("podman") ? "podman" : undefined;
|
|
33
|
+
if (!runtime) {
|
|
34
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "runtime-unavailable", "no container runtime (docker/podman) on PATH", attestation);
|
|
35
|
+
}
|
|
36
|
+
const ping = (0, node_child_process_1.spawnSync)(runtime, ["version", "--format", "{{.Server.Version}}"], { encoding: "utf8", timeout: 15000 });
|
|
37
|
+
const daemonUp = !ping.error && ping.status === 0 && String(ping.stdout || "").trim().length > 0;
|
|
38
|
+
if (!daemonUp) {
|
|
39
|
+
const why = (String(ping.stderr || "").split("\n").find((line) => line.trim()) || `${runtime} daemon not reachable`).trim();
|
|
40
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "runtime-unavailable", `${runtime} daemon is not reachable: ${why}`, attestation);
|
|
41
|
+
}
|
|
42
|
+
const command = String(request.command);
|
|
43
|
+
const args = (request.args || []).map(String);
|
|
44
|
+
const cwd = request.cwd || process.cwd();
|
|
45
|
+
const runArgs = ["run", "--rm"];
|
|
46
|
+
if (policy.network.mode !== "any")
|
|
47
|
+
runArgs.push("--network", "none");
|
|
48
|
+
runArgs.push("-v", `${cwd}:${cwd}:ro`, "-w", cwd);
|
|
49
|
+
if (policy.env.inherit || (policy.env.expose && policy.env.expose.length)) {
|
|
50
|
+
for (const name of policy.env.inherit ? Object.keys(process.env) : policy.env.expose || []) {
|
|
51
|
+
if (name === "PATH" || name === "HOME")
|
|
52
|
+
continue;
|
|
53
|
+
const value = process.env[name];
|
|
54
|
+
if (value !== undefined)
|
|
55
|
+
runArgs.push("-e", `${name}=${value}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
runArgs.push(handle.ref, command, ...args);
|
|
59
|
+
const result = (0, node_child_process_1.spawnSync)(runtime, runArgs, { cwd, encoding: "utf8", timeout: request.timeoutMs, maxBuffer: 32 * 1024 * 1024 });
|
|
60
|
+
if (result.error) {
|
|
61
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "delegation-failed", `${runtime} run failed: ${messageOf(result.error)}`, attestation);
|
|
62
|
+
}
|
|
63
|
+
const exitCode = typeof result.status === "number" ? result.status : null;
|
|
64
|
+
if (exitCode === 125 || exitCode === null) {
|
|
65
|
+
const why = (String(result.stderr || "").split("\n").find((line) => line.trim()) || "container runtime error").trim();
|
|
66
|
+
return (0, envelopes_1.refusedEnvelope)(descriptor, policy, label, "runtime-unavailable", `${runtime} could not run the container: ${why}`, attestation);
|
|
67
|
+
}
|
|
68
|
+
return (0, envelopes_1.delegatedEnvelope)(descriptor, label, handle, attestation, command, args, exitCode, String(result.stdout || ""));
|
|
69
|
+
}
|