cool-workflow 0.1.98 → 0.2.1
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 +18 -7
- package/apps/architecture-review/app.json +2 -2
- package/apps/architecture-review/workflow.js +12 -12
- 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 +3518 -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/shell/doctor.js +292 -0
- package/dist/shell/drive.js +885 -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 +507 -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 +100 -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 +344 -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} +257 -48
- package/dist/shell/scheduling-io.js +321 -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 +472 -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 +258 -0
- package/dist/shell/workbench-text.js +18 -0
- package/dist/shell/workbench.js +170 -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 +4 -0
- package/docs/cli-mcp-parity.7.md +282 -219
- package/docs/contract-migration-tooling.7.md +4 -0
- package/docs/control-plane-scheduling.7.md +4 -0
- package/docs/durable-state-and-locking.7.md +4 -0
- package/docs/evidence-adoption-reasoning-chain.7.md +4 -0
- package/docs/execution-backends.7.md +4 -0
- package/docs/multi-agent-cli-mcp-surface.7.md +4 -0
- package/docs/multi-agent-eval-replay-harness.7.md +4 -0
- package/docs/multi-agent-operator-ux.7.md +4 -0
- package/docs/node-snapshot-diff-replay.7.md +4 -0
- package/docs/observability-cost-accounting.7.md +6 -1
- package/docs/project-index.md +137 -71
- package/docs/real-execution-backends.7.md +4 -0
- package/docs/release-and-migration.7.md +4 -0
- package/docs/release-tooling.7.md +4 -0
- package/docs/remote-source-review.7.md +4 -4
- package/docs/report-verifiable-bundle.7.md +1 -1
- package/docs/run-registry-control-plane.7.md +4 -0
- package/docs/run-retention-reclamation.7.md +25 -0
- package/docs/security-trust-hardening.7.md +3 -1
- package/docs/state-explosion-management.7.md +4 -0
- package/docs/team-collaboration.7.md +4 -0
- package/docs/web-desktop-workbench.7.md +15 -1
- package/manifest/plugin.manifest.json +1 -1
- package/manifest/source-context-profiles.json +9 -13
- package/package.json +1 -1
- package/scripts/agents/agent-adapter-core.js +22 -2
- package/scripts/agents/claude-p-agent.js +8 -3
- package/scripts/agents/cw-attest-wrap.js +2 -2
- package/scripts/agents/gemini-agent.js +5 -1
- package/scripts/agents/opencode-agent.js +5 -1
- 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/doctor.js +0 -212
- 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,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// core/state/node-snapshot.ts — snapshotNode / diffNodeSnapshots /
|
|
3
|
+
// replayNodeSnapshot / verifyNodeReplay.
|
|
4
|
+
//
|
|
5
|
+
// MILESTONE 3. Byte-exact port of the old build's src/node-snapshot.ts,
|
|
6
|
+
// split into a PURE half (this file) and a shell half (shell/node-
|
|
7
|
+
// store.ts, which supplies the actual `writeJson` persistence and file
|
|
8
|
+
// scans for readNodeSnapshot/readNodeReplay). Every function here is pure
|
|
9
|
+
// given `(run, clock)` — no direct fs/Date calls; `now` is always an
|
|
10
|
+
// explicit parameter, `persist` is always a caller-supplied callback.
|
|
11
|
+
//
|
|
12
|
+
// RAW vs NORMALIZED fingerprints [docs/rebuild/PLAN.md byte-compat item 8 — do not
|
|
13
|
+
// merge these two code paths]:
|
|
14
|
+
// - `sourceFingerprint` is RAW: built from the node's raw id/status/
|
|
15
|
+
// updatedAt plus raw artifact/evidence id+path strings. ANY transition
|
|
16
|
+
// (even just `updatedAt` ticking) flips it — this is what freshness
|
|
17
|
+
// detection needs.
|
|
18
|
+
// - `body`/`outputFingerprint` are NORMALIZED via `projectNodeBody`/
|
|
19
|
+
// `replayStableStringify` (node-projection.ts): no timestamps, scrubbed
|
|
20
|
+
// paths, so replay output is byte-stable across recaptures of the same
|
|
21
|
+
// logical state.
|
|
22
|
+
// These stay two separate functions (`sourceFingerprint` vs
|
|
23
|
+
// `snapshotBody`/`outputFingerprint`'s computation) — never one call.
|
|
24
|
+
//
|
|
25
|
+
// Evidence: SPEC/state-core.md "src/node-snapshot.ts — snapshot / diff /
|
|
26
|
+
// replay", "Raw vs. normalized fingerprints", "Snapshot freshness
|
|
27
|
+
// fail-closed".
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.NodeSnapshotError = exports.NODE_SNAPSHOT_SCHEMA_VERSION = void 0;
|
|
30
|
+
exports.findRunNode = findRunNode;
|
|
31
|
+
exports.sourceFingerprint = sourceFingerprint;
|
|
32
|
+
exports.snapshotNode = snapshotNode;
|
|
33
|
+
exports.loadNodeSnapshot = loadNodeSnapshot;
|
|
34
|
+
exports.diffNodeSnapshots = diffNodeSnapshots;
|
|
35
|
+
exports.replayNodeSnapshot = replayNodeSnapshot;
|
|
36
|
+
exports.verifyNodeReplay = verifyNodeReplay;
|
|
37
|
+
const hash_1 = require("../hash");
|
|
38
|
+
const node_projection_1 = require("./node-projection");
|
|
39
|
+
exports.NODE_SNAPSHOT_SCHEMA_VERSION = 1;
|
|
40
|
+
/** Structured fail-closed error (mirrors PipelineContractError's shape). */
|
|
41
|
+
class NodeSnapshotError extends Error {
|
|
42
|
+
code;
|
|
43
|
+
freshness;
|
|
44
|
+
details;
|
|
45
|
+
constructor(code, message, options = {}) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = "NodeSnapshotError";
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.freshness = options.freshness;
|
|
50
|
+
this.details = options.details;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.NodeSnapshotError = NodeSnapshotError;
|
|
54
|
+
const SNAPSHOT_SECTIONS = [
|
|
55
|
+
"status",
|
|
56
|
+
"inputs",
|
|
57
|
+
"outputs",
|
|
58
|
+
"artifacts",
|
|
59
|
+
"evidence",
|
|
60
|
+
"errors",
|
|
61
|
+
"links",
|
|
62
|
+
"metadata",
|
|
63
|
+
];
|
|
64
|
+
/** Look up a StateNode by id in `run.nodes`, or `undefined` if absent. Pure
|
|
65
|
+
* data lookup — no fs. */
|
|
66
|
+
function findRunNode(run, nodeId) {
|
|
67
|
+
return (run.nodes || []).find((candidate) => candidate.id === nodeId);
|
|
68
|
+
}
|
|
69
|
+
/** NORMALIZED projection of a node — timestamps/paths stripped, so it is
|
|
70
|
+
* byte-stable across captures of the same logical state. */
|
|
71
|
+
function snapshotBody(node) {
|
|
72
|
+
return (0, node_projection_1.projectNodeBody)(node);
|
|
73
|
+
}
|
|
74
|
+
/** RAW fingerprint (NOT normalized): any transition (updatedAt/status) or
|
|
75
|
+
* artifact/evidence change flips it — this is how drift is detected. */
|
|
76
|
+
function sourceFingerprint(node) {
|
|
77
|
+
return (0, hash_1.fingerprintStrings)([
|
|
78
|
+
`node:${node.id}:${node.status}:${node.updatedAt}`,
|
|
79
|
+
...node.artifacts.map((artifact) => `artifact:${artifact.id}:${artifact.path}`),
|
|
80
|
+
...node.evidence.map((evidence) => `evidence:${evidence.id}:${evidence.path || ""}`),
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
/** Snapshot one StateNode by id. Throws (fail closed) if the node is
|
|
84
|
+
* absent. */
|
|
85
|
+
function snapshotNode(run, nodeId, options = {}) {
|
|
86
|
+
const node = findRunNode(run, nodeId);
|
|
87
|
+
if (!node) {
|
|
88
|
+
throw new NodeSnapshotError("node-absent", `Cannot snapshot: node ${nodeId} not found in run ${run.id}`, {
|
|
89
|
+
freshness: "absent",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const fingerprint = sourceFingerprint(node);
|
|
93
|
+
const snapshot = {
|
|
94
|
+
schemaVersion: 1,
|
|
95
|
+
snapshotId: `snap-${safeFileNamePure(nodeId)}-${fingerprint.replace("sha256:", "").slice(0, 12)}`,
|
|
96
|
+
runId: run.id,
|
|
97
|
+
nodeId,
|
|
98
|
+
capturedAt: options.now || new Date(0).toISOString(),
|
|
99
|
+
sourceFingerprint: fingerprint,
|
|
100
|
+
body: snapshotBody(node),
|
|
101
|
+
};
|
|
102
|
+
if (options.persist !== false && typeof options.persist === "function")
|
|
103
|
+
options.persist(snapshot);
|
|
104
|
+
return snapshot;
|
|
105
|
+
}
|
|
106
|
+
/** Recompute freshness from the CURRENT source. `valid | stale | absent`. */
|
|
107
|
+
function loadNodeSnapshot(run, snapshot, pathExists = () => true) {
|
|
108
|
+
const node = findRunNode(run, snapshot.nodeId);
|
|
109
|
+
if (!node) {
|
|
110
|
+
return { snapshot, freshness: "absent", reason: `source node ${snapshot.nodeId} is gone from run ${run.id}` };
|
|
111
|
+
}
|
|
112
|
+
const missingArtifact = node.artifacts.find((artifact) => artifact.path && !pathExists(artifact.path));
|
|
113
|
+
if (missingArtifact) {
|
|
114
|
+
return { snapshot, freshness: "absent", reason: `referenced artifact path is unreadable: ${missingArtifact.id}` };
|
|
115
|
+
}
|
|
116
|
+
if (sourceFingerprint(node) !== snapshot.sourceFingerprint) {
|
|
117
|
+
return { snapshot, freshness: "stale", reason: `source node ${snapshot.nodeId} changed since capture` };
|
|
118
|
+
}
|
|
119
|
+
return { snapshot, freshness: "valid" };
|
|
120
|
+
}
|
|
121
|
+
function sectionValue(body, section) {
|
|
122
|
+
if (section === "links")
|
|
123
|
+
return { parents: body.parents, children: body.children };
|
|
124
|
+
return body[section];
|
|
125
|
+
}
|
|
126
|
+
/** Stable, structural diff of two snapshots: 8 sections, in fixed order. */
|
|
127
|
+
function diffNodeSnapshots(baseline, candidate) {
|
|
128
|
+
const sections = SNAPSHOT_SECTIONS.map((section) => {
|
|
129
|
+
const baselineValue = sectionValue(baseline.body, section);
|
|
130
|
+
const candidateValue = sectionValue(candidate.body, section);
|
|
131
|
+
const sameBytes = (0, node_projection_1.replayStableStringify)(baselineValue) === (0, node_projection_1.replayStableStringify)(candidateValue);
|
|
132
|
+
let change;
|
|
133
|
+
if (sameBytes)
|
|
134
|
+
change = "same";
|
|
135
|
+
else if (baselineValue === undefined)
|
|
136
|
+
change = "added";
|
|
137
|
+
else if (candidateValue === undefined)
|
|
138
|
+
change = "removed";
|
|
139
|
+
else
|
|
140
|
+
change = "changed";
|
|
141
|
+
const entry = { section, change };
|
|
142
|
+
if (change !== "same") {
|
|
143
|
+
entry.baseline = baselineValue;
|
|
144
|
+
entry.candidate = candidateValue;
|
|
145
|
+
}
|
|
146
|
+
return entry;
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
schemaVersion: 1,
|
|
150
|
+
runId: baseline.runId,
|
|
151
|
+
baselineSnapshotId: baseline.snapshotId,
|
|
152
|
+
candidateSnapshotId: candidate.snapshotId,
|
|
153
|
+
baselineNodeId: baseline.nodeId,
|
|
154
|
+
candidateNodeId: candidate.nodeId,
|
|
155
|
+
changed: sections.some((entry) => entry.change !== "same"),
|
|
156
|
+
sections,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** Deterministically replay one node from its snapshot, fail-closed on
|
|
160
|
+
* drift: freshness not `valid` throws `snapshot-stale`/`snapshot-absent`
|
|
161
|
+
* BEFORE any replay bytes are built. */
|
|
162
|
+
function replayNodeSnapshot(run, snapshot, options = {}) {
|
|
163
|
+
const { freshness, reason } = loadNodeSnapshot(run, snapshot, options.pathExists);
|
|
164
|
+
if (freshness !== "valid") {
|
|
165
|
+
throw new NodeSnapshotError(freshness === "stale" ? "snapshot-stale" : "snapshot-absent", reason || `cannot replay a ${freshness} snapshot of node ${snapshot.nodeId}`, { freshness, details: { runId: run.id, nodeId: snapshot.nodeId } });
|
|
166
|
+
}
|
|
167
|
+
const body = (0, node_projection_1.normalizeValue)(snapshot.body);
|
|
168
|
+
const outputFingerprint = (0, hash_1.fingerprintStrings)([(0, node_projection_1.replayStableStringify)(body)]);
|
|
169
|
+
const replay = {
|
|
170
|
+
schemaVersion: 1,
|
|
171
|
+
replayId: `replay-${snapshot.snapshotId}-${outputFingerprint.replace("sha256:", "").slice(0, 8)}`,
|
|
172
|
+
runId: run.id,
|
|
173
|
+
nodeId: snapshot.nodeId,
|
|
174
|
+
snapshotId: snapshot.snapshotId,
|
|
175
|
+
replayedAt: options.now || new Date(0).toISOString(),
|
|
176
|
+
freshness: "valid",
|
|
177
|
+
contractValidated: Boolean(snapshot.body.contractId),
|
|
178
|
+
outputFingerprint,
|
|
179
|
+
body,
|
|
180
|
+
};
|
|
181
|
+
if (options.persist !== false && typeof options.persist === "function")
|
|
182
|
+
options.persist(replay);
|
|
183
|
+
return replay;
|
|
184
|
+
}
|
|
185
|
+
/** Compare a replay to a FRESH (non-persisted) snapshot of the source node;
|
|
186
|
+
* pass = byte-identical normalized body. Never throws — a drifted source
|
|
187
|
+
* is a `pass:false` finding, not an exception. */
|
|
188
|
+
function verifyNodeReplay(run, replay, options = {}) {
|
|
189
|
+
const fresh = findRunNode(run, replay.nodeId);
|
|
190
|
+
if (!fresh) {
|
|
191
|
+
return {
|
|
192
|
+
schemaVersion: 1,
|
|
193
|
+
runId: run.id,
|
|
194
|
+
nodeId: replay.nodeId,
|
|
195
|
+
replayId: replay.replayId,
|
|
196
|
+
pass: false,
|
|
197
|
+
freshness: "absent",
|
|
198
|
+
findings: [{ id: "source-absent", severity: "error", category: "source", reason: `source node ${replay.nodeId} is gone` }],
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const freshSnapshot = snapshotNode(run, replay.nodeId, { now: options.now, persist: false });
|
|
202
|
+
const diff = diffNodeSnapshots(freshSnapshot, { ...freshSnapshot, body: replay.body, snapshotId: replay.snapshotId });
|
|
203
|
+
const findings = diff.sections
|
|
204
|
+
.filter((section) => section.change !== "same")
|
|
205
|
+
.map((section) => ({
|
|
206
|
+
id: `drift:${section.section}`,
|
|
207
|
+
severity: "error",
|
|
208
|
+
category: section.section,
|
|
209
|
+
reason: `replay diverged from source in ${section.section}`,
|
|
210
|
+
baselineRef: replay.snapshotId,
|
|
211
|
+
replayRef: replay.replayId,
|
|
212
|
+
}));
|
|
213
|
+
return {
|
|
214
|
+
schemaVersion: 1,
|
|
215
|
+
runId: run.id,
|
|
216
|
+
nodeId: replay.nodeId,
|
|
217
|
+
replayId: replay.replayId,
|
|
218
|
+
pass: findings.length === 0,
|
|
219
|
+
freshness: "valid",
|
|
220
|
+
findings,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** Pure re-implementation of shell/fs-atomic.ts's naming rule (replaces
|
|
224
|
+
* every run of chars outside `[a-zA-Z0-9_.:-]` with a single `_`), needed
|
|
225
|
+
* here purely as a STRING transform for id formatting — no fs. Kept in
|
|
226
|
+
* sync with `safeFileName` by the same regex; both are pinned by the same
|
|
227
|
+
* SPEC line (state-core.md's `safeFileName(value)`). */
|
|
228
|
+
function safeFileNamePure(value) {
|
|
229
|
+
return value.replace(/[^a-zA-Z0-9_.:-]+/g, "_");
|
|
230
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// core/state/run-paths.ts — createRunPaths, ensureRunDirs.
|
|
3
|
+
//
|
|
4
|
+
// MILESTONE 3. Byte-exact port of the old build's src/state.ts:10-50.
|
|
5
|
+
// `createRunPaths` is pure path math (core/); `ensureRunDirs` touches disk
|
|
6
|
+
// (mkdirSync) so it lives here but is called from shell/run-store.ts, the
|
|
7
|
+
// only place that actually creates a run directory tree.
|
|
8
|
+
//
|
|
9
|
+
// Evidence: SPEC/state-core.md "src/state.ts — persistence kernel" and "The
|
|
10
|
+
// full .cw/runs/<run-id>/ layout".
|
|
11
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
15
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperty(o, k2, desc);
|
|
18
|
+
}) : (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
o[k2] = m[k];
|
|
21
|
+
}));
|
|
22
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
23
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
24
|
+
}) : function(o, v) {
|
|
25
|
+
o["default"] = v;
|
|
26
|
+
});
|
|
27
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
28
|
+
var ownKeys = function(o) {
|
|
29
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
30
|
+
var ar = [];
|
|
31
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
32
|
+
return ar;
|
|
33
|
+
};
|
|
34
|
+
return ownKeys(o);
|
|
35
|
+
};
|
|
36
|
+
return function (mod) {
|
|
37
|
+
if (mod && mod.__esModule) return mod;
|
|
38
|
+
var result = {};
|
|
39
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
40
|
+
__setModuleDefault(result, mod);
|
|
41
|
+
return result;
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.createRunPaths = createRunPaths;
|
|
46
|
+
exports.ensureRunDirs = ensureRunDirs;
|
|
47
|
+
const fs = __importStar(require("node:fs"));
|
|
48
|
+
const path = __importStar(require("node:path"));
|
|
49
|
+
/** The 16-key RunPaths object, all joined under `runDir`. */
|
|
50
|
+
function createRunPaths(runDir) {
|
|
51
|
+
return {
|
|
52
|
+
runDir,
|
|
53
|
+
state: path.join(runDir, "state.json"),
|
|
54
|
+
report: path.join(runDir, "report.md"),
|
|
55
|
+
tasksDir: path.join(runDir, "tasks"),
|
|
56
|
+
resultsDir: path.join(runDir, "results"),
|
|
57
|
+
dispatchesDir: path.join(runDir, "dispatches"),
|
|
58
|
+
artifactsDir: path.join(runDir, "artifacts"),
|
|
59
|
+
commitsDir: path.join(runDir, "commits"),
|
|
60
|
+
stateNodesDir: path.join(runDir, "nodes"),
|
|
61
|
+
feedbackDir: path.join(runDir, "feedback"),
|
|
62
|
+
auditDir: path.join(runDir, "audit"),
|
|
63
|
+
workersDir: path.join(runDir, "workers"),
|
|
64
|
+
candidatesDir: path.join(runDir, "candidates"),
|
|
65
|
+
multiAgentDir: path.join(runDir, "multi-agent"),
|
|
66
|
+
blackboardDir: path.join(runDir, "blackboard"),
|
|
67
|
+
topologiesDir: path.join(runDir, "topologies"),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** `mkdirSync` (recursive) every dir this run needs. Missing optional dir
|
|
71
|
+
* fields fall back to `path.join(runDir, "<name>")`, matching the old
|
|
72
|
+
* build's defensive default (a RunPaths loaded from an old/partial
|
|
73
|
+
* state.json may be missing an optional key). */
|
|
74
|
+
function ensureRunDirs(paths) {
|
|
75
|
+
const dirs = [
|
|
76
|
+
paths.runDir,
|
|
77
|
+
paths.tasksDir,
|
|
78
|
+
paths.resultsDir,
|
|
79
|
+
paths.dispatchesDir,
|
|
80
|
+
paths.artifactsDir,
|
|
81
|
+
paths.commitsDir,
|
|
82
|
+
paths.stateNodesDir,
|
|
83
|
+
paths.feedbackDir,
|
|
84
|
+
paths.auditDir || path.join(paths.runDir, "audit"),
|
|
85
|
+
paths.workersDir || path.join(paths.runDir, "workers"),
|
|
86
|
+
paths.candidatesDir || path.join(paths.runDir, "candidates"),
|
|
87
|
+
paths.multiAgentDir || path.join(paths.runDir, "multi-agent"),
|
|
88
|
+
paths.blackboardDir || path.join(paths.runDir, "blackboard"),
|
|
89
|
+
paths.topologiesDir || path.join(paths.runDir, "topologies"),
|
|
90
|
+
];
|
|
91
|
+
for (const dir of dirs)
|
|
92
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
93
|
+
}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
//
|
|
2
|
+
// core/state/schema-validate.ts — dependency-free JSON-schema subset.
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
4
|
+
// MILESTONE 3. Byte-exact port of the old build's src/schema-validate.ts.
|
|
5
|
+
// Deliberately a SUBSET of JSON Schema (type, const, enum, required,
|
|
6
|
+
// properties, additionalProperties:false, items) — adds no runtime
|
|
7
|
+
// dependency. Unsupported keywords are surfaced as a stderr diagnostic
|
|
8
|
+
// (TTY only), never enforced.
|
|
8
9
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// Supported keywords cover structured-agent-output contracts:
|
|
12
|
-
// type (object|array|string|number|integer|boolean|null, or an array of them),
|
|
13
|
-
// enum, const, required, properties, additionalProperties (false), items.
|
|
14
|
-
// Unsupported keywords ($ref, allOf/anyOf/oneOf, pattern, formats, numeric
|
|
15
|
-
// bounds) are surfaced as WARNINGS (a constraint that wasn't checked), so the
|
|
16
|
-
// operator can see their schema reliance is incomplete.
|
|
17
|
-
// (If full JSON Schema is needed later, swap this module's impl for ajv behind
|
|
18
|
-
// the same signature.)
|
|
10
|
+
// Evidence: SPEC/state-core.md "src/schema-validate.ts — dependency-free
|
|
11
|
+
// JSON-schema subset", "Schema-validator error strings".
|
|
19
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
13
|
exports.validateAgainstSchema = validateAgainstSchema;
|
|
21
14
|
function typeOf(value) {
|
|
@@ -23,7 +16,7 @@ function typeOf(value) {
|
|
|
23
16
|
return "null";
|
|
24
17
|
if (Array.isArray(value))
|
|
25
18
|
return "array";
|
|
26
|
-
return typeof value;
|
|
19
|
+
return typeof value;
|
|
27
20
|
}
|
|
28
21
|
function matchesType(value, type) {
|
|
29
22
|
switch (type) {
|
|
@@ -42,38 +35,53 @@ function matchesType(value, type) {
|
|
|
42
35
|
case "null":
|
|
43
36
|
return value === null;
|
|
44
37
|
default:
|
|
45
|
-
return true; // unknown declared type
|
|
38
|
+
return true; // unknown declared type => not enforced (never a false fail)
|
|
46
39
|
}
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
const UNSUPPORTED_KEYWORDS = new Set([
|
|
42
|
+
"$ref",
|
|
43
|
+
"allOf",
|
|
44
|
+
"anyOf",
|
|
45
|
+
"oneOf",
|
|
46
|
+
"not",
|
|
47
|
+
"pattern",
|
|
48
|
+
"format",
|
|
49
|
+
"minimum",
|
|
50
|
+
"maximum",
|
|
51
|
+
"minLength",
|
|
52
|
+
"maxLength",
|
|
53
|
+
"minItems",
|
|
54
|
+
"maxItems",
|
|
55
|
+
"uniqueItems",
|
|
56
|
+
"contains",
|
|
57
|
+
"if",
|
|
58
|
+
"then",
|
|
59
|
+
"else",
|
|
60
|
+
]);
|
|
61
|
+
/** Validate `value` against `schema`. Returns a list of human-readable
|
|
62
|
+
* errors; empty means valid. Pure + deterministic; never throws on a
|
|
63
|
+
* malformed schema. */
|
|
51
64
|
function validateAgainstSchema(value, schema, path = "$") {
|
|
52
65
|
const errors = [];
|
|
53
66
|
if (!schema || typeof schema !== "object")
|
|
54
67
|
return errors;
|
|
55
|
-
|
|
56
|
-
const UNSUPPORTED = new Set(["$ref", "allOf", "anyOf", "oneOf", "not", "pattern", "format", "minimum", "maximum", "minLength", "maxLength", "minItems", "maxItems", "uniqueItems", "contains", "if", "then", "else"]);
|
|
57
|
-
const unsupported = Object.keys(schema).filter((k) => UNSUPPORTED.has(k));
|
|
68
|
+
const unsupported = Object.keys(schema).filter((k) => UNSUPPORTED_KEYWORDS.has(k));
|
|
58
69
|
if (unsupported.length && process.stderr.isTTY) {
|
|
59
70
|
process.stderr.write(`[cw] schema at ${path}: unsupported keywords ignored: ${unsupported.join(", ")}\n`);
|
|
60
71
|
}
|
|
61
|
-
// type
|
|
62
72
|
if (schema.type !== undefined) {
|
|
63
73
|
const types = Array.isArray(schema.type) ? schema.type.map(String) : [String(schema.type)];
|
|
64
74
|
if (!types.some((t) => matchesType(value, t))) {
|
|
65
75
|
errors.push(`${path}: expected type ${types.join("|")}, got ${typeOf(value)}`);
|
|
66
|
-
return errors; // type mismatch
|
|
76
|
+
return errors; // type mismatch => downstream keyword checks would be noise
|
|
67
77
|
}
|
|
68
78
|
}
|
|
69
|
-
// const / enum
|
|
70
79
|
if ("const" in schema && JSON.stringify(value) !== JSON.stringify(schema.const)) {
|
|
71
80
|
errors.push(`${path}: expected const ${JSON.stringify(schema.const)}`);
|
|
72
81
|
}
|
|
73
82
|
if (Array.isArray(schema.enum) && !schema.enum.some((option) => JSON.stringify(option) === JSON.stringify(value))) {
|
|
74
83
|
errors.push(`${path}: ${JSON.stringify(value)} is not one of ${JSON.stringify(schema.enum)}`);
|
|
75
84
|
}
|
|
76
|
-
// object: required, properties, additionalProperties:false
|
|
77
85
|
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
78
86
|
const obj = value;
|
|
79
87
|
if (Array.isArray(schema.required)) {
|
|
@@ -94,7 +102,6 @@ function validateAgainstSchema(value, schema, path = "$") {
|
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
104
|
}
|
|
97
|
-
// array: items (single schema applied to every element)
|
|
98
105
|
if (Array.isArray(value) && schema.items && typeof schema.items === "object" && !Array.isArray(schema.items)) {
|
|
99
106
|
value.forEach((element, index) => {
|
|
100
107
|
errors.push(...validateAgainstSchema(element, schema.items, `${path}[${index}]`));
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// core/state/schema.ts — the single field-list source for WorkflowRun.
|
|
3
|
+
//
|
|
4
|
+
// MILESTONE 3. Byte-exact port of the old build's src/run-state-schema.ts.
|
|
5
|
+
// Both migrations.ts's validation AND (eventually) a build gate derive
|
|
6
|
+
// their field knowledge from this module — a field added to WorkflowRun
|
|
7
|
+
// must be added here too.
|
|
8
|
+
//
|
|
9
|
+
// Evidence: SPEC/state-core.md "src/run-state-schema.ts — the single
|
|
10
|
+
// field-list source".
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OPTIONAL_TOP_LEVEL_KEYS = exports.REQUIRED_RECORD_KEYS = exports.REQUIRED_ARRAY_KEYS = exports.REQUIRED_TOP_LEVEL_KEYS = void 0;
|
|
13
|
+
/** Top-level required keys of WorkflowRun — every key that must exist
|
|
14
|
+
* after migration. */
|
|
15
|
+
exports.REQUIRED_TOP_LEVEL_KEYS = [
|
|
16
|
+
"schemaVersion",
|
|
17
|
+
"id",
|
|
18
|
+
"createdAt",
|
|
19
|
+
"updatedAt",
|
|
20
|
+
"cwd",
|
|
21
|
+
"workflow",
|
|
22
|
+
"inputs",
|
|
23
|
+
"loopStage",
|
|
24
|
+
"phases",
|
|
25
|
+
"tasks",
|
|
26
|
+
"dispatches",
|
|
27
|
+
"commits",
|
|
28
|
+
"paths",
|
|
29
|
+
];
|
|
30
|
+
/** Top-level keys that must be arrays after migration. */
|
|
31
|
+
exports.REQUIRED_ARRAY_KEYS = ["phases", "tasks", "dispatches", "commits"];
|
|
32
|
+
/** Top-level keys that must be objects (Record) after migration. */
|
|
33
|
+
exports.REQUIRED_RECORD_KEYS = ["workflow", "paths", "multiAgent", "blackboard", "topologies"];
|
|
34
|
+
/** Keys from the WorkflowRun type that are OPTIONAL (exist at type level
|
|
35
|
+
* but are not required by validateMigratedRunState). */
|
|
36
|
+
exports.OPTIONAL_TOP_LEVEL_KEYS = [
|
|
37
|
+
"nodes",
|
|
38
|
+
"contracts",
|
|
39
|
+
"feedback",
|
|
40
|
+
"audit",
|
|
41
|
+
"workers",
|
|
42
|
+
"sandboxProfiles",
|
|
43
|
+
"customSandboxProfiles",
|
|
44
|
+
"candidates",
|
|
45
|
+
"candidateSelections",
|
|
46
|
+
"multiAgent",
|
|
47
|
+
"blackboard",
|
|
48
|
+
"topologies",
|
|
49
|
+
"collaboration",
|
|
50
|
+
];
|