cool-workflow 0.1.78
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 +20 -0
- package/.codex-plugin/mcp.json +10 -0
- package/.codex-plugin/plugin.json +38 -0
- package/.mcp.json +10 -0
- package/LICENSE +24 -0
- package/README.md +638 -0
- package/apps/architecture-review/app.json +51 -0
- package/apps/architecture-review/workflow.js +116 -0
- package/apps/end-to-end-golden-path/app.json +30 -0
- package/apps/end-to-end-golden-path/workflow.js +33 -0
- package/apps/pr-review-fix-ci/app.json +59 -0
- package/apps/pr-review-fix-ci/workflow.js +90 -0
- package/apps/release-cut/app.json +54 -0
- package/apps/release-cut/workflow.js +82 -0
- package/apps/research-synthesis/app.json +50 -0
- package/apps/research-synthesis/workflow.js +76 -0
- package/apps/workflow-app-framework-demo/app.json +29 -0
- package/apps/workflow-app-framework-demo/workflow.js +44 -0
- package/dist/agent-config.js +223 -0
- package/dist/candidate-scoring.js +715 -0
- package/dist/capability-core.js +630 -0
- package/dist/capability-dispatcher.js +86 -0
- package/dist/capability-registry.js +523 -0
- package/dist/cli.js +1276 -0
- package/dist/collaboration.js +727 -0
- package/dist/commit.js +570 -0
- package/dist/contract-migration.js +234 -0
- package/dist/coordinator.js +1163 -0
- package/dist/daemon.js +44 -0
- package/dist/dispatch.js +201 -0
- package/dist/drive.js +503 -0
- package/dist/error-feedback.js +415 -0
- package/dist/evidence-grounding.js +179 -0
- package/dist/evidence-reasoning.js +733 -0
- package/dist/execution-backend.js +1279 -0
- package/dist/harness.js +61 -0
- package/dist/mcp-server.js +1615 -0
- package/dist/multi-agent-eval.js +857 -0
- package/dist/multi-agent-host.js +764 -0
- package/dist/multi-agent-operator-ux.js +537 -0
- package/dist/multi-agent-trust.js +366 -0
- package/dist/multi-agent.js +1173 -0
- package/dist/node-snapshot.js +270 -0
- package/dist/observability.js +922 -0
- package/dist/operator-ux.js +971 -0
- package/dist/orchestrator/audit-operations.js +182 -0
- package/dist/orchestrator/candidate-operations.js +117 -0
- package/dist/orchestrator/cli-options.js +288 -0
- package/dist/orchestrator/collaboration-operations.js +86 -0
- package/dist/orchestrator/feedback-operations.js +81 -0
- package/dist/orchestrator/host-operations.js +78 -0
- package/dist/orchestrator/lifecycle-operations.js +462 -0
- package/dist/orchestrator/migration-operations.js +44 -0
- package/dist/orchestrator/multi-agent-operations.js +362 -0
- package/dist/orchestrator/report.js +369 -0
- package/dist/orchestrator/topology-operations.js +84 -0
- package/dist/orchestrator.js +874 -0
- package/dist/pipeline-contract.js +92 -0
- package/dist/pipeline-runner.js +285 -0
- package/dist/reclamation.js +882 -0
- package/dist/result-normalize.js +194 -0
- package/dist/run-export.js +64 -0
- package/dist/run-registry.js +1347 -0
- package/dist/run-state-schema.js +67 -0
- package/dist/sandbox-profile.js +471 -0
- package/dist/scheduler.js +266 -0
- package/dist/scheduling.js +184 -0
- package/dist/schema-validate.js +98 -0
- package/dist/state-explosion.js +1213 -0
- package/dist/state-migrations.js +463 -0
- package/dist/state-node.js +301 -0
- package/dist/state.js +308 -0
- package/dist/telemetry-attestation.js +156 -0
- package/dist/telemetry-ledger.js +145 -0
- package/dist/topology.js +527 -0
- package/dist/triggers.js +159 -0
- package/dist/trust-audit.js +475 -0
- package/dist/types/blackboard.js +2 -0
- package/dist/types/boundary.js +29 -0
- package/dist/types/candidate.js +2 -0
- package/dist/types/collaboration.js +2 -0
- package/dist/types/core.js +2 -0
- package/dist/types/drive.js +10 -0
- package/dist/types/error-feedback.js +2 -0
- package/dist/types/evidence-reasoning.js +2 -0
- package/dist/types/execution-backend.js +2 -0
- package/dist/types/multi-agent.js +2 -0
- package/dist/types/observability.js +2 -0
- package/dist/types/pipeline.js +2 -0
- package/dist/types/reclamation.js +8 -0
- package/dist/types/result.js +2 -0
- package/dist/types/run-registry.js +2 -0
- package/dist/types/run.js +2 -0
- package/dist/types/sandbox.js +2 -0
- package/dist/types/schedule.js +2 -0
- package/dist/types/state-node.js +2 -0
- package/dist/types/topology.js +2 -0
- package/dist/types/trust.js +2 -0
- package/dist/types/workbench.js +2 -0
- package/dist/types/worker.js +2 -0
- package/dist/types/workflow-app.js +2 -0
- package/dist/types.js +43 -0
- package/dist/verifier-registry.js +46 -0
- package/dist/verifier.js +78 -0
- package/dist/version.js +8 -0
- package/dist/workbench-host.js +172 -0
- package/dist/workbench.js +190 -0
- package/dist/worker-isolation.js +1028 -0
- package/dist/workflow-api.js +98 -0
- package/dist/workflow-app-framework.js +626 -0
- package/docs/agent-delegation-drive.7.md +190 -0
- package/docs/agent-framework.md +176 -0
- package/docs/candidate-scoring.7.md +106 -0
- package/docs/canonical-workflow-apps.7.md +137 -0
- package/docs/capability-topology-registry.7.md +168 -0
- package/docs/cli-mcp-parity.7.md +373 -0
- package/docs/contract-migration-tooling.7.md +123 -0
- package/docs/control-plane-scheduling.7.md +110 -0
- package/docs/coordinator-blackboard.7.md +183 -0
- package/docs/dogfood/architecture-review-cool-workflow.md +16 -0
- package/docs/dogfood-one-real-repo.7.md +168 -0
- package/docs/durable-state-and-locking.7.md +107 -0
- package/docs/end-to-end-golden-path.7.md +117 -0
- package/docs/error-feedback.7.md +153 -0
- package/docs/evidence-adoption-reasoning-chain.7.md +270 -0
- package/docs/execution-backends.7.md +300 -0
- package/docs/getting-started.md +99 -0
- package/docs/index.md +41 -0
- package/docs/mcp-app-surface.7.md +235 -0
- package/docs/multi-agent-cli-mcp-surface.7.md +265 -0
- package/docs/multi-agent-eval-replay-harness.7.md +302 -0
- package/docs/multi-agent-operator-ux.7.md +314 -0
- package/docs/multi-agent-runtime-core.7.md +231 -0
- package/docs/multi-agent-topologies.7.md +103 -0
- package/docs/multi-agent-trust-policy-audit.7.md +154 -0
- package/docs/node-snapshot-diff-replay.7.md +135 -0
- package/docs/observability-cost-accounting.7.md +194 -0
- package/docs/operator-ux.7.md +180 -0
- package/docs/pipeline-runner.7.md +136 -0
- package/docs/project-index.md +261 -0
- package/docs/real-execution-backends.7.md +142 -0
- package/docs/release-and-migration.7.md +280 -0
- package/docs/release-tooling.7.md +159 -0
- package/docs/routines.md +48 -0
- package/docs/run-registry-control-plane.7.md +312 -0
- package/docs/run-retention-reclamation.7.md +191 -0
- package/docs/sandbox-profiles.7.md +137 -0
- package/docs/scheduled-tasks.md +80 -0
- package/docs/security-trust-hardening.7.md +117 -0
- package/docs/state-explosion-management.7.md +264 -0
- package/docs/state-node.7.md +96 -0
- package/docs/team-collaboration.7.md +207 -0
- package/docs/unix-principles.md +192 -0
- package/docs/verifier-gated-commit.7.md +140 -0
- package/docs/web-desktop-workbench.7.md +215 -0
- package/docs/worker-isolation.7.md +167 -0
- package/docs/workflow-app-framework.7.md +274 -0
- package/manifest/README.md +43 -0
- package/manifest/plugin.manifest.json +316 -0
- package/manifest/pricing.policy.json +14 -0
- package/package.json +79 -0
- package/scripts/agents/claude-p-agent.js +104 -0
- package/scripts/agents/claude-p-agent.sh +9 -0
- package/scripts/agents/cw-attest-keygen.js +55 -0
- package/scripts/agents/cw-attest-wrap.js +143 -0
- package/scripts/block-unapproved-tag.sh +39 -0
- package/scripts/bump-version.js +249 -0
- package/scripts/canonical-apps.js +171 -0
- package/scripts/cw.js +4 -0
- package/scripts/dist-drift-check.js +79 -0
- package/scripts/dogfood-architecture-review.js +237 -0
- package/scripts/dogfood-release.js +624 -0
- package/scripts/forward-ref-docs.js +73 -0
- package/scripts/gen-manifests.js +232 -0
- package/scripts/golden-path.js +300 -0
- package/scripts/mcp-server.js +4 -0
- package/scripts/new-feature.js +121 -0
- package/scripts/parity-check.js +213 -0
- package/scripts/release-check.js +118 -0
- package/scripts/release-flow.js +272 -0
- package/scripts/release-gate.sh +85 -0
- package/scripts/sync-project-index.js +387 -0
- package/scripts/validate-run-state-schema.js +126 -0
- package/scripts/verify-container-selfref.js +64 -0
- package/scripts/version-sync-check.js +237 -0
- package/skills/cool-workflow/SKILL.md +162 -0
- package/skills/cool-workflow/references/commands.md +282 -0
- package/tsconfig.json +16 -0
- package/ui/workbench/app.css +76 -0
- package/ui/workbench/app.js +159 -0
- package/ui/workbench/index.html +32 -0
- package/workflows/architecture-review.workflow.js +84 -0
- package/workflows/research-synthesis.workflow.js +47 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Verifier Registry — open pluggability for commit-gate verifiers.
|
|
3
|
+
//
|
|
4
|
+
// BSD discipline (mechanism separate from policy):
|
|
5
|
+
// - MECHANISM: a Map<string, Verifier> with register + resolve.
|
|
6
|
+
// - POLICY: which verifiers exist is declared via registerVerifier() at load time.
|
|
7
|
+
// - FAIL CLOSED: unknown verifier id → named refusal.
|
|
8
|
+
// - COMPOSABLE: multiple verifiers can be chained; each runs in registration order.
|
|
9
|
+
//
|
|
10
|
+
// From v0.1.58: the built-in verifier (validateResultEnvelope, validateRunGates,
|
|
11
|
+
// hasGroundedEvidence) remains the default. Registered verifiers run BEFORE the
|
|
12
|
+
// default — they can block or add evidence but cannot override the default gate.
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.registerVerifier = registerVerifier;
|
|
15
|
+
exports.getVerifier = getVerifier;
|
|
16
|
+
exports.listVerifiers = listVerifiers;
|
|
17
|
+
exports.runAllVerifiers = runAllVerifiers;
|
|
18
|
+
const _verifierRegistry = new Map();
|
|
19
|
+
function registerVerifier(verifier) {
|
|
20
|
+
_verifierRegistry.set(verifier.id, verifier);
|
|
21
|
+
}
|
|
22
|
+
function getVerifier(id) {
|
|
23
|
+
return _verifierRegistry.get(id);
|
|
24
|
+
}
|
|
25
|
+
function listVerifiers() {
|
|
26
|
+
return [..._verifierRegistry.values()];
|
|
27
|
+
}
|
|
28
|
+
/** Run all registered verifiers against a run. Returns the aggregated verdict:
|
|
29
|
+
* "pass" if all pass, "block" if any block (first block reason wins). */
|
|
30
|
+
async function runAllVerifiers(input) {
|
|
31
|
+
const reasons = [];
|
|
32
|
+
const evidence = [];
|
|
33
|
+
for (const verifier of _verifierRegistry.values()) {
|
|
34
|
+
const result = await verifier.verify(input);
|
|
35
|
+
if (result.evidence)
|
|
36
|
+
evidence.push(...result.evidence);
|
|
37
|
+
if (result.verdict === "block") {
|
|
38
|
+
reasons.push(`[${verifier.id}] ${result.reason || "blocked by verifier"}`);
|
|
39
|
+
}
|
|
40
|
+
else if (result.verdict === "warn") {
|
|
41
|
+
reasons.push(`[${verifier.id}] warn: ${result.reason || "warning"}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const blocked = reasons.some((r) => !r.includes("warn:"));
|
|
45
|
+
return { verdict: blocked ? "block" : "pass", reasons, evidence };
|
|
46
|
+
}
|
package/dist/verifier.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertTaskCanComplete = assertTaskCanComplete;
|
|
4
|
+
exports.parseResultEnvelope = parseResultEnvelope;
|
|
5
|
+
exports.taskRequiresEvidence = taskRequiresEvidence;
|
|
6
|
+
exports.validateResultEnvelope = validateResultEnvelope;
|
|
7
|
+
exports.validateRunGates = validateRunGates;
|
|
8
|
+
const dispatch_1 = require("./dispatch");
|
|
9
|
+
const evidence_grounding_1 = require("./evidence-grounding");
|
|
10
|
+
const result_normalize_1 = require("./result-normalize");
|
|
11
|
+
const schema_validate_1 = require("./schema-validate");
|
|
12
|
+
function assertTaskCanComplete(run, task) {
|
|
13
|
+
const runnablePhase = (0, dispatch_1.firstRunnablePhase)(run);
|
|
14
|
+
if (!runnablePhase || runnablePhase.name !== task.phase) {
|
|
15
|
+
throw new Error(`Phase gate blocked task ${task.id}; current runnable phase is ${runnablePhase?.name || "none"}`);
|
|
16
|
+
}
|
|
17
|
+
if (!["pending", "running"].includes(task.status)) {
|
|
18
|
+
throw new Error(`Task ${task.id} cannot be completed from status ${task.status}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
// Ingest is delegated to the robust normalizer (v0.1.42): canonical
|
|
22
|
+
// `{summary, findings, evidence}` passes through unchanged, but when the agent
|
|
23
|
+
// uses its own shape (or prose) CW extracts findings from alternative keys and
|
|
24
|
+
// DERIVES grounded evidence itself rather than capturing nothing.
|
|
25
|
+
function parseResultEnvelope(markdown) {
|
|
26
|
+
return (0, result_normalize_1.normalizeResultEnvelope)(markdown);
|
|
27
|
+
}
|
|
28
|
+
/** Whether a task's result MUST carry evidence (verify/verdict/synthesis tasks
|
|
29
|
+
* and any task that opted in via requiresEvidence). The commit gate reuses this
|
|
30
|
+
* so its evidence-grounding check matches the acceptance-time policy exactly. */
|
|
31
|
+
function taskRequiresEvidence(task) {
|
|
32
|
+
return Boolean(task.requiresEvidence ||
|
|
33
|
+
/^verify[:/]/i.test(task.id) ||
|
|
34
|
+
/^verdict[:/]/i.test(task.id) ||
|
|
35
|
+
/^synthesis[:/]/i.test(task.id));
|
|
36
|
+
}
|
|
37
|
+
function validateResultEnvelope(task, result) {
|
|
38
|
+
const mustHaveEvidence = taskRequiresEvidence(task);
|
|
39
|
+
if (mustHaveEvidence && !(0, evidence_grounding_1.hasGroundedEvidence)(result.evidence)) {
|
|
40
|
+
throw new Error(`Task ${task.id} requires grounded cw:result evidence (a path-like locator, URL, or namespace:value token — not free text)`);
|
|
41
|
+
}
|
|
42
|
+
for (const finding of result.findings || []) {
|
|
43
|
+
validateFinding(task, finding);
|
|
44
|
+
}
|
|
45
|
+
// Track 3: if the task declared an output schema, the accepted result envelope
|
|
46
|
+
// must conform. Fail-closed (throw ⇒ the drive parks the hop), consistent with
|
|
47
|
+
// the checks above. No schema declared ⇒ no check (opt-in by declaration).
|
|
48
|
+
if (task.schema) {
|
|
49
|
+
const violations = (0, schema_validate_1.validateAgainstSchema)(result, task.schema);
|
|
50
|
+
if (violations.length) {
|
|
51
|
+
throw new Error(`Task ${task.id} result violates declared schema: ${violations.slice(0, 5).join("; ")}${violations.length > 5 ? ` (+${violations.length - 5} more)` : ""}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function validateRunGates(run) {
|
|
56
|
+
const verdictTasks = run.tasks.filter((task) => /^verdict[:/]|^synthesis[:/]/i.test(task.id));
|
|
57
|
+
for (const verdictTask of verdictTasks) {
|
|
58
|
+
if (verdictTask.status !== "completed")
|
|
59
|
+
continue;
|
|
60
|
+
const verdictPhaseIndex = run.phases.findIndex((phase) => phase.name === verdictTask.phase);
|
|
61
|
+
const earlierPhases = run.phases.slice(0, verdictPhaseIndex);
|
|
62
|
+
const incompleteEarlier = earlierPhases.find((phase) => phase.status !== "completed");
|
|
63
|
+
if (incompleteEarlier) {
|
|
64
|
+
throw new Error(`Verdict gate blocked ${verdictTask.id}; phase ${incompleteEarlier.name} is not complete`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function validateFinding(task, finding) {
|
|
69
|
+
if (!finding.id)
|
|
70
|
+
throw new Error(`Task ${task.id} has a finding without id`);
|
|
71
|
+
if (finding.classification &&
|
|
72
|
+
!["real", "conditional", "non-issue", "unknown"].includes(finding.classification)) {
|
|
73
|
+
throw new Error(`Task ${task.id} finding ${finding.id} has invalid classification`);
|
|
74
|
+
}
|
|
75
|
+
if (["P0", "P1", "P2"].includes(finding.severity || "") && !(0, evidence_grounding_1.hasGroundedEvidence)(finding.evidence)) {
|
|
76
|
+
throw new Error(`Task ${task.id} finding ${finding.id} severity ${finding.severity} requires grounded evidence (a path-like locator, URL, or namespace:value token)`);
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MIN_SUPPORTED_RUN_STATE_SCHEMA_VERSION = exports.LEGACY_RUN_STATE_SCHEMA_VERSION = exports.CURRENT_RUN_STATE_SCHEMA_VERSION = exports.WORKFLOW_APP_SCHEMA_VERSION = exports.CURRENT_COOL_WORKFLOW_VERSION = void 0;
|
|
4
|
+
exports.CURRENT_COOL_WORKFLOW_VERSION = "0.1.78";
|
|
5
|
+
exports.WORKFLOW_APP_SCHEMA_VERSION = 1;
|
|
6
|
+
exports.CURRENT_RUN_STATE_SCHEMA_VERSION = 1;
|
|
7
|
+
exports.LEGACY_RUN_STATE_SCHEMA_VERSION = 0;
|
|
8
|
+
exports.MIN_SUPPORTED_RUN_STATE_SCHEMA_VERSION = 0;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Web / Desktop Workbench host (v0.1.30) — a thin, OPTIONAL localhost renderer.
|
|
3
|
+
//
|
|
4
|
+
// BSD discipline:
|
|
5
|
+
// - LEAST PRIVILEGE, LOCAL BY DEFAULT. Binds 127.0.0.1 ONLY, serves read-only
|
|
6
|
+
// derived views, exposes nothing beyond the current user's `.cw/` scope and
|
|
7
|
+
// the v0.1.28 registry's registered repos. It also rejects non-localhost Host
|
|
8
|
+
// headers (DNS-rebinding defense) and fails closed on anything it cannot read.
|
|
9
|
+
// - READ-ONLY BY DEFAULT. Every route is GET; any write verb is refused 405.
|
|
10
|
+
// The host offers no actions — it is pure inspection. (A future action would
|
|
11
|
+
// have to route through a declared capability core entry, never a parallel
|
|
12
|
+
// path, so it stays parity-gated.)
|
|
13
|
+
// - NO HIDDEN DASHBOARD / OPTIONAL SURFACE. The host imports the kernel, never
|
|
14
|
+
// the reverse. It holds zero authoritative state: every response is re-derived
|
|
15
|
+
// on demand from disk via the SAME core entries the CLI/MCP use. The committed
|
|
16
|
+
// `dist/` + plain `node` runtime keep working with this file deleted.
|
|
17
|
+
//
|
|
18
|
+
// See src/workbench.ts and docs/web-desktop-workbench.7.md.
|
|
19
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.WorkbenchHost = void 0;
|
|
24
|
+
const node_http_1 = __importDefault(require("node:http"));
|
|
25
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
26
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
27
|
+
const workbench_1 = require("./workbench");
|
|
28
|
+
const ALLOWED_HOSTNAMES = new Set(["127.0.0.1", "localhost", "::1", "[::1]"]);
|
|
29
|
+
const CONTENT_TYPES = {
|
|
30
|
+
".html": "text/html; charset=utf-8",
|
|
31
|
+
".js": "text/javascript; charset=utf-8",
|
|
32
|
+
".css": "text/css; charset=utf-8",
|
|
33
|
+
".json": "application/json; charset=utf-8",
|
|
34
|
+
".svg": "image/svg+xml"
|
|
35
|
+
};
|
|
36
|
+
class WorkbenchHost {
|
|
37
|
+
runner;
|
|
38
|
+
cwd;
|
|
39
|
+
port;
|
|
40
|
+
scope;
|
|
41
|
+
host = "127.0.0.1";
|
|
42
|
+
server;
|
|
43
|
+
constructor(options) {
|
|
44
|
+
this.runner = options.runner;
|
|
45
|
+
this.cwd = node_path_1.default.resolve(String(options.cwd || process.cwd()));
|
|
46
|
+
this.port = options.port && options.port > 0 ? Math.floor(options.port) : workbench_1.WORKBENCH_DEFAULT_PORT;
|
|
47
|
+
this.scope = options.scope === "repo" ? "repo" : "home";
|
|
48
|
+
}
|
|
49
|
+
/** The canonical serve descriptor — identical to `cw workbench serve --json`. */
|
|
50
|
+
descriptor(once) {
|
|
51
|
+
return (0, workbench_1.buildWorkbenchServeDescriptor)(this.runner, { cwd: this.cwd, port: this.port, scope: this.scope, once });
|
|
52
|
+
}
|
|
53
|
+
/** Start listening on loopback only. Resolves with the actually-bound port
|
|
54
|
+
* (an ephemeral 0 becomes a real port — useful for tests). */
|
|
55
|
+
listen() {
|
|
56
|
+
const server = node_http_1.default.createServer((req, res) => this.handle(req, res));
|
|
57
|
+
this.server = server;
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
server.once("error", reject);
|
|
60
|
+
// Bind the loopback interface ONLY — never a public address.
|
|
61
|
+
server.listen(this.port, this.host, () => {
|
|
62
|
+
const address = server.address();
|
|
63
|
+
const port = address && typeof address === "object" ? address.port : this.port;
|
|
64
|
+
resolve({ host: this.host, port });
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
close() {
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
if (!this.server)
|
|
71
|
+
return resolve();
|
|
72
|
+
this.server.close(() => resolve());
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** Run until interrupted (the CLI default `workbench serve`). */
|
|
76
|
+
async run() {
|
|
77
|
+
const bound = await this.listen();
|
|
78
|
+
process.stdout.write(`${JSON.stringify({ ...this.descriptor(false), boundPort: bound.port })}\n`);
|
|
79
|
+
}
|
|
80
|
+
handle(req, res) {
|
|
81
|
+
try {
|
|
82
|
+
// Fail closed on anything but a localhost GET.
|
|
83
|
+
if (!isLocalHost(req.headers.host))
|
|
84
|
+
return this.send(res, 403, { error: "forbidden: non-localhost Host header" });
|
|
85
|
+
if ((req.method || "GET").toUpperCase() !== "GET") {
|
|
86
|
+
return this.send(res, 405, { error: "read-only: only GET is permitted" }, { Allow: "GET" });
|
|
87
|
+
}
|
|
88
|
+
const url = new URL(req.url || "/", `http://${this.host}`);
|
|
89
|
+
const route = decodeURIComponent(url.pathname);
|
|
90
|
+
if (route === "/" || route === "/index.html")
|
|
91
|
+
return this.sendAsset(res, "index.html");
|
|
92
|
+
if (route.startsWith("/ui/"))
|
|
93
|
+
return this.sendAsset(res, route.slice("/ui/".length));
|
|
94
|
+
if (route === "/api/serve")
|
|
95
|
+
return this.send(res, 200, this.descriptor(true));
|
|
96
|
+
if (route === "/api/index") {
|
|
97
|
+
const args = Object.fromEntries(url.searchParams.entries());
|
|
98
|
+
return this.send(res, 200, (0, workbench_1.buildWorkbenchIndex)(this.runner, { cwd: this.cwd, scope: this.scope, ...args }));
|
|
99
|
+
}
|
|
100
|
+
const runMatch = /^\/api\/run\/([^/]+)$/.exec(route);
|
|
101
|
+
if (runMatch) {
|
|
102
|
+
const previousCwd = process.cwd();
|
|
103
|
+
process.chdir(this.cwd);
|
|
104
|
+
try {
|
|
105
|
+
return this.send(res, 200, (0, workbench_1.buildWorkbenchRunView)(this.runner, runMatch[1]));
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
process.chdir(previousCwd);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
this.send(res, 404, { error: `no such read-only view: ${route}` });
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
this.send(res, 500, { error: error instanceof Error ? error.message : String(error) });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Serve a static UI asset from disk, re-read on every request (no caching of
|
|
118
|
+
* authoritative state). Path-traversal is refused; a missing asset is an
|
|
119
|
+
* honest 404 — the framework ships fine without the UI installed. */
|
|
120
|
+
sendAsset(res, relative) {
|
|
121
|
+
const uiRoot = (0, workbench_1.workbenchUiRoot)(this.runner);
|
|
122
|
+
const resolved = node_path_1.default.resolve(uiRoot, relative);
|
|
123
|
+
if (resolved !== uiRoot && !resolved.startsWith(uiRoot + node_path_1.default.sep)) {
|
|
124
|
+
return this.send(res, 403, { error: "forbidden: path traversal" });
|
|
125
|
+
}
|
|
126
|
+
let body;
|
|
127
|
+
try {
|
|
128
|
+
body = node_fs_1.default.readFileSync(resolved);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
if (relative === "index.html") {
|
|
132
|
+
return this.sendRaw(res, 200, CONTENT_TYPES[".html"], Buffer.from(FALLBACK_HTML(uiRoot)));
|
|
133
|
+
}
|
|
134
|
+
return this.send(res, 404, { error: `UI asset not installed: ${relative}` });
|
|
135
|
+
}
|
|
136
|
+
this.sendRaw(res, 200, CONTENT_TYPES[node_path_1.default.extname(resolved)] || "application/octet-stream", body);
|
|
137
|
+
}
|
|
138
|
+
send(res, status, body, headers = {}) {
|
|
139
|
+
this.sendRaw(res, status, CONTENT_TYPES[".json"], Buffer.from(JSON.stringify(body, null, 2)), headers);
|
|
140
|
+
}
|
|
141
|
+
sendRaw(res, status, contentType, body, headers = {}) {
|
|
142
|
+
res.writeHead(status, {
|
|
143
|
+
"Content-Type": contentType,
|
|
144
|
+
"Cache-Control": "no-store",
|
|
145
|
+
"X-Content-Type-Options": "nosniff",
|
|
146
|
+
...headers
|
|
147
|
+
});
|
|
148
|
+
res.end(body);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.WorkbenchHost = WorkbenchHost;
|
|
152
|
+
function isLocalHost(hostHeader) {
|
|
153
|
+
if (!hostHeader)
|
|
154
|
+
return true; // HTTP/1.0 / no Host — loopback bind already constrains us.
|
|
155
|
+
const hostname = hostHeader.replace(/:\d+$/, "");
|
|
156
|
+
return ALLOWED_HOSTNAMES.has(hostname);
|
|
157
|
+
}
|
|
158
|
+
function FALLBACK_HTML(uiRoot) {
|
|
159
|
+
return [
|
|
160
|
+
"<!doctype html><meta charset=utf-8><title>Cool Workflow Workbench</title>",
|
|
161
|
+
"<body style=\"font-family:system-ui;margin:2rem;color:#222\">",
|
|
162
|
+
"<h1>Cool Workflow Workbench</h1>",
|
|
163
|
+
"<p>The static UI assets are not installed at:</p>",
|
|
164
|
+
`<pre>${escapeHtml(uiRoot)}</pre>`,
|
|
165
|
+
"<p>The read-only JSON views are still served:</p>",
|
|
166
|
+
"<ul><li><a href=\"/api/index\">/api/index</a></li><li><code>/api/run/<runId></code></li><li><a href=\"/api/serve\">/api/serve</a></li></ul>",
|
|
167
|
+
"</body>"
|
|
168
|
+
].join("");
|
|
169
|
+
}
|
|
170
|
+
function escapeHtml(value) {
|
|
171
|
+
return value.replace(/[&<>]/g, (ch) => (ch === "&" ? "&" : ch === "<" ? "<" : ">"));
|
|
172
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Web / Desktop Workbench core (v0.1.30) — the SINGLE source of the human
|
|
3
|
+
// console's view models, and a THIRD FRONT DOOR over ONE mechanism.
|
|
4
|
+
//
|
|
5
|
+
// BSD discipline:
|
|
6
|
+
// - MECHANISM VS POLICY. The kernel + durable `.cw/` state are the mechanism.
|
|
7
|
+
// The CLI renders for human speed, MCP for machine context, and the Workbench
|
|
8
|
+
// for human inspection at a glance. All three are presentation POLICY over the
|
|
9
|
+
// same data. This module computes, decides, and stores NOTHING the CLI/MCP
|
|
10
|
+
// cannot already produce — every panel embeds, verbatim, the canonical
|
|
11
|
+
// `--json` payload of ONE already-declared capability, assembled by calling
|
|
12
|
+
// the SAME runner core entries the CLI and MCP route through.
|
|
13
|
+
// - NO HIDDEN DASHBOARD. These are DERIVED, read-only projections. They hold no
|
|
14
|
+
// authoritative state; refresh re-derives everything from disk. Delete the
|
|
15
|
+
// host process and nothing is lost — the data is the files.
|
|
16
|
+
// - EXPLICIT, INSPECTABLE, FAIL CLOSED. When a source capability is unreadable
|
|
17
|
+
// (e.g. a run with no blackboard yet, or unresolvable state), the panel is
|
|
18
|
+
// rendered `absent` with the honest error; we never fabricate a view.
|
|
19
|
+
//
|
|
20
|
+
// See docs/web-desktop-workbench.7.md, src/capability-registry.ts, and the
|
|
21
|
+
// v0.1.27 parity contract (docs/cli-mcp-parity.7.md).
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.WORKBENCH_UI_RELATIVE = exports.WORKBENCH_DEFAULT_PORT = void 0;
|
|
27
|
+
exports.buildWorkbenchRunView = buildWorkbenchRunView;
|
|
28
|
+
exports.buildWorkbenchIndex = buildWorkbenchIndex;
|
|
29
|
+
exports.workbenchUiRoot = workbenchUiRoot;
|
|
30
|
+
exports.buildWorkbenchServeDescriptor = buildWorkbenchServeDescriptor;
|
|
31
|
+
const capability_core_1 = require("./capability-core");
|
|
32
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
33
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
34
|
+
/** Default loopback port. Local by default, least privilege — never a public
|
|
35
|
+
* interface. Overridable with `--port`. */
|
|
36
|
+
exports.WORKBENCH_DEFAULT_PORT = 7717;
|
|
37
|
+
/** Relative location of the optional, dependency-light static UI assets. Kept
|
|
38
|
+
* OUT of the kernel: the host reads them lazily at request time, so the framework
|
|
39
|
+
* builds and runs with the Workbench (and these files) absent. */
|
|
40
|
+
exports.WORKBENCH_UI_RELATIVE = node_path_1.default.join("ui", "workbench");
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// Panel assembly — each panel IS one capability payload, embedded verbatim.
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
/** Render one panel by invoking its single source capability. On success `data`
|
|
45
|
+
* equals `cw <cmd> --json` byte-for-byte; on failure the panel is `absent` with
|
|
46
|
+
* the honest reason (fail closed) — exactly what the CLI would report. */
|
|
47
|
+
function panel(capability, cli, mcp, produce) {
|
|
48
|
+
try {
|
|
49
|
+
return { capability, cli, mcp, status: "present", data: produce() };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return { capability, cli, mcp, status: "absent", error: error instanceof Error ? error.message : String(error) };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function buildPanels(runner, runId) {
|
|
56
|
+
return {
|
|
57
|
+
// Run graph — operator + multi-agent, including the v0.1.25 compact and
|
|
58
|
+
// critical-path views. Backend ids/attestations (v0.1.29) ride on the nodes.
|
|
59
|
+
graph: {
|
|
60
|
+
operator: panel("graph", `cw graph ${runId} --json`, "cw_operator_graph", () => runner.operatorGraph(runId)),
|
|
61
|
+
multiAgent: panel("multi-agent.graph", `cw multi-agent graph ${runId} --json`, "cw_multi_agent_graph", () => runner.multiAgentOperatorGraph(runId)),
|
|
62
|
+
compact: panel("multi-agent.graph.compact", `cw multi-agent graph ${runId} --view compact --json`, "cw_multi_agent_graph_compact", () => runner.multiAgentGraphView(runId, { view: "compact" })),
|
|
63
|
+
criticalPath: panel("multi-agent.graph.compact", `cw multi-agent graph ${runId} --view critical-path --json`, "cw_multi_agent_graph_compact", () => runner.multiAgentGraphView(runId, { view: "critical-path" }))
|
|
64
|
+
},
|
|
65
|
+
// Blackboard — coordinator topics/messages/contexts/artifacts/snapshots/
|
|
66
|
+
// decisions/conflicts/adopted+missing evidence.
|
|
67
|
+
blackboard: {
|
|
68
|
+
coordinator: panel("coordinator.summary", `cw coordinator summary ${runId}`, "cw_coordinator_summary", () => runner.coordinatorSummary(runId)),
|
|
69
|
+
digest: panel("blackboard.summarize", `cw blackboard summarize ${runId} --json`, "cw_blackboard_summarize", () => runner.blackboardSummarize(runId)),
|
|
70
|
+
graph: panel("blackboard.graph", `cw blackboard graph ${runId}`, "cw_blackboard_graph", () => runner.blackboardGraph(runId))
|
|
71
|
+
},
|
|
72
|
+
// Worker logs — manifests, outputs, scoped results, failures, and the
|
|
73
|
+
// recorded execution backend + sandbox attestation.
|
|
74
|
+
worker: {
|
|
75
|
+
summary: panel("worker.summary", `cw worker summary ${runId} --json`, "cw_worker_summary", () => runner.summarizeWorkerRecords(runId))
|
|
76
|
+
},
|
|
77
|
+
// Candidate compare — scores/selection/rejection, plus the v0.1.26
|
|
78
|
+
// evidence-adoption reasoning chain (why adopted).
|
|
79
|
+
candidate: {
|
|
80
|
+
summary: panel("candidate.summary", `cw candidate summary ${runId} --json`, "cw_candidate_summary", () => runner.summarizeCandidateOperatorRecords(runId)),
|
|
81
|
+
reasoning: panel("multi-agent.reasoning", `cw multi-agent reasoning ${runId} --json`, "cw_evidence_reasoning", () => runner.multiAgentReasoning(runId))
|
|
82
|
+
},
|
|
83
|
+
// Observability + cost (v0.1.31) — durations, failure/verifier/acceptance
|
|
84
|
+
// rates with sample counts, attested usage + cost, coverage, `unreported`/
|
|
85
|
+
// `n/a` shown honestly. Equals `cw metrics show <run> --json` byte-for-byte.
|
|
86
|
+
metrics: {
|
|
87
|
+
report: panel("metrics.show", `cw metrics show ${runId} --json`, "cw_metrics_show", () => runner.metricsShow(runId))
|
|
88
|
+
},
|
|
89
|
+
// Audit timeline — trust-audit events, role policy decisions, provenance,
|
|
90
|
+
// judge/chair rationale, and policy violations.
|
|
91
|
+
audit: {
|
|
92
|
+
summary: panel("audit.summary", `cw audit summary ${runId}`, "cw_audit_summary", () => runner.auditSummary(runId)),
|
|
93
|
+
multiAgent: panel("audit.multi-agent", `cw audit multi-agent ${runId} --json`, "cw_audit_multi_agent", () => runner.auditMultiAgent(runId)),
|
|
94
|
+
policy: panel("audit.policy", `cw audit policy ${runId} --json`, "cw_audit_policy", () => runner.auditPolicy(runId)),
|
|
95
|
+
judge: panel("audit.judge", `cw audit judge ${runId} --json`, "cw_audit_judge", () => runner.auditJudge(runId))
|
|
96
|
+
},
|
|
97
|
+
// Collaboration (v0.1.32) — derived per-target review state (pending/approved/
|
|
98
|
+
// rejected/blocked/unattributed, required vs recorded), the append-only
|
|
99
|
+
// approval/comment/handoff timeline, and the run owner. Read-only; equals
|
|
100
|
+
// `cw review status <run> --json` and `cw comment list <run> --json`.
|
|
101
|
+
collaboration: {
|
|
102
|
+
review: panel("review.status", `cw review status ${runId} --json`, "cw_review_status", () => runner.reviewStatus(runId)),
|
|
103
|
+
comments: panel("comment.list", `cw comment list ${runId} --json`, "cw_comment_list", () => runner.collaborationCommentList(runId))
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** Assemble the read-only five-panel view of ONE run. The run is first resolved
|
|
108
|
+
* from its durable `.cw/runs/<id>/state.json`; when that source is unreadable
|
|
109
|
+
* the view is `resolved: false` and every panel is `absent` — fail closed,
|
|
110
|
+
* never fabricated. */
|
|
111
|
+
function buildWorkbenchRunView(runner, runId) {
|
|
112
|
+
const id = String(runId || "");
|
|
113
|
+
let resolved = true;
|
|
114
|
+
let error;
|
|
115
|
+
try {
|
|
116
|
+
runner.loadRun(id);
|
|
117
|
+
}
|
|
118
|
+
catch (caught) {
|
|
119
|
+
resolved = false;
|
|
120
|
+
error = caught instanceof Error ? caught.message : String(caught);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
schemaVersion: 1,
|
|
124
|
+
surface: "workbench",
|
|
125
|
+
runId: id,
|
|
126
|
+
resolved,
|
|
127
|
+
...(error ? { error } : {}),
|
|
128
|
+
panels: buildPanels(runner, id)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Cross-run entry (v0.1.28 Run Registry) — composed from already-declared
|
|
133
|
+
// capabilities; adds NO new source of truth.
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
/** Build the cross-run index: the registry index plus the run list (or a
|
|
136
|
+
* filtered search). Each field equals the corresponding `cw <cmd> --json`
|
|
137
|
+
* payload; the Workbench can show nothing the CLI/MCP cannot. */
|
|
138
|
+
function buildWorkbenchIndex(runner, args = {}) {
|
|
139
|
+
const scope = args.scope === "repo" ? "repo" : "home";
|
|
140
|
+
const scoped = { ...args, scope };
|
|
141
|
+
const registry = (0, capability_core_1.runRegistryShow)((0, capability_core_1.runRegistryFor)(scoped, runner), scoped);
|
|
142
|
+
const filtered = Boolean(args.text || args.q || args.query || args.app || args.appId || args.status || args.repo || args.since || args.until);
|
|
143
|
+
const runs = filtered ? (0, capability_core_1.runSearch)((0, capability_core_1.runRegistryFor)(scoped, runner), scoped) : (0, capability_core_1.runList)((0, capability_core_1.runRegistryFor)(scoped, runner), scoped);
|
|
144
|
+
return { schemaVersion: 1, surface: "workbench", command: "index", scope, registry, runs };
|
|
145
|
+
}
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
// Serve descriptor — describes the OPTIONAL localhost host (no state).
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
/** Absolute path to the optional static UI assets for this plugin install. */
|
|
150
|
+
function workbenchUiRoot(runner) {
|
|
151
|
+
return node_path_1.default.join(runner.pluginRoot, exports.WORKBENCH_UI_RELATIVE);
|
|
152
|
+
}
|
|
153
|
+
/** The canonical `cw workbench serve` payload: a description of the localhost
|
|
154
|
+
* bind and its read-only routes. Holds zero authoritative state. The CLI emits
|
|
155
|
+
* this under `--json`/`--once`; `cw_workbench_serve` returns it directly. */
|
|
156
|
+
function buildWorkbenchServeDescriptor(runner, args = {}) {
|
|
157
|
+
const scope = args.scope === "repo" ? "repo" : "home";
|
|
158
|
+
const root = node_path_1.default.resolve(String(args.cwd || process.cwd()));
|
|
159
|
+
const portRaw = Number(args.port);
|
|
160
|
+
const port = Number.isFinite(portRaw) && portRaw > 0 ? Math.floor(portRaw) : exports.WORKBENCH_DEFAULT_PORT;
|
|
161
|
+
const uiRoot = workbenchUiRoot(runner);
|
|
162
|
+
return {
|
|
163
|
+
schemaVersion: 1,
|
|
164
|
+
surface: "workbench",
|
|
165
|
+
command: "serve",
|
|
166
|
+
host: "127.0.0.1",
|
|
167
|
+
port,
|
|
168
|
+
once: Boolean(args.once),
|
|
169
|
+
readOnly: true,
|
|
170
|
+
scope,
|
|
171
|
+
root,
|
|
172
|
+
uiAvailable: dirExists(uiRoot),
|
|
173
|
+
uiRoot,
|
|
174
|
+
routes: [
|
|
175
|
+
{ method: "GET", path: "/", description: "Workbench UI shell (static, dependency-light)." },
|
|
176
|
+
{ method: "GET", path: "/ui/*", description: "Static UI assets (read from disk; absent if not installed)." },
|
|
177
|
+
{ method: "GET", path: "/api/index", description: "Cross-run index: registry show + run list/search (v0.1.28)." },
|
|
178
|
+
{ method: "GET", path: "/api/serve", description: "This serve descriptor." },
|
|
179
|
+
{ method: "GET", path: "/api/run/:runId", description: "Five-panel WorkbenchRunView for one run (read-only)." }
|
|
180
|
+
]
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function dirExists(target) {
|
|
184
|
+
try {
|
|
185
|
+
return node_fs_1.default.statSync(target).isDirectory();
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|