harnery 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/commander.d.ts.map +1 -1
- package/dist/commander.js +2 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +38 -0
- package/dist/commands/grep.d.ts +35 -2
- package/dist/commands/grep.d.ts.map +1 -1
- package/dist/commands/grep.js +427 -139
- package/dist/commands/init.d.ts +15 -5
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +125 -14
- package/dist/commands/workflow.d.ts +4 -0
- package/dist/commands/workflow.d.ts.map +1 -0
- package/dist/commands/workflow.js +89 -0
- package/dist/core/agents/cli.js +10 -3
- package/dist/core/agents/rules/claim-conflict.d.ts.map +1 -1
- package/dist/core/agents/rules/claim-conflict.js +26 -1
- package/dist/core/agents/rules/stop-hook.d.ts +8 -0
- package/dist/core/agents/rules/stop-hook.d.ts.map +1 -1
- package/dist/core/agents/rules/stop-hook.js +8 -0
- package/dist/core/agents/state/heartbeat-projector.d.ts +2 -0
- package/dist/core/agents/state/heartbeat-projector.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-projector.js +13 -2
- package/dist/core/agents/state/heartbeat-writer.d.ts +16 -2
- package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
- package/dist/core/agents/state/heartbeat-writer.js +21 -4
- package/dist/core/config.d.ts +9 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +19 -0
- package/dist/core/hooks/cli.js +29 -3
- package/dist/core/hooks/events/schema.d.ts +4 -0
- package/dist/core/hooks/events/schema.d.ts.map +1 -1
- package/dist/core/hooks/harness/events.d.ts +7 -0
- package/dist/core/hooks/harness/events.d.ts.map +1 -1
- package/dist/core/hooks/harness/events.js +1 -0
- package/dist/core/hooks/resolve/coord-root.d.ts +11 -0
- package/dist/core/hooks/resolve/coord-root.d.ts.map +1 -1
- package/dist/core/hooks/resolve/coord-root.js +28 -6
- package/dist/core/workflow/billing.d.ts +48 -0
- package/dist/core/workflow/billing.d.ts.map +1 -0
- package/dist/core/workflow/billing.js +102 -0
- package/dist/core/workflow/child-env.d.ts +30 -0
- package/dist/core/workflow/child-env.d.ts.map +1 -0
- package/dist/core/workflow/child-env.js +43 -0
- package/dist/core/workflow/engine.d.ts +21 -0
- package/dist/core/workflow/engine.d.ts.map +1 -0
- package/dist/core/workflow/engine.js +340 -0
- package/dist/core/workflow/harnesses.d.ts +17 -0
- package/dist/core/workflow/harnesses.d.ts.map +1 -0
- package/dist/core/workflow/harnesses.js +30 -0
- package/dist/core/workflow/spawn-claude.d.ts +22 -0
- package/dist/core/workflow/spawn-claude.d.ts.map +1 -0
- package/dist/core/workflow/spawn-claude.js +82 -0
- package/dist/core/workflow/spawn-codex.d.ts +19 -0
- package/dist/core/workflow/spawn-codex.d.ts.map +1 -0
- package/dist/core/workflow/spawn-codex.js +66 -0
- package/dist/core/workflow/spawn-cursor.d.ts +26 -0
- package/dist/core/workflow/spawn-cursor.d.ts.map +1 -0
- package/dist/core/workflow/spawn-cursor.js +72 -0
- package/dist/core/workflow/types.d.ts +145 -0
- package/dist/core/workflow/types.d.ts.map +1 -0
- package/dist/core/workflow/types.js +9 -0
- package/dist/core/workflow/validate.d.ts +15 -0
- package/dist/core/workflow/validate.d.ts.map +1 -0
- package/dist/core/workflow/validate.js +70 -0
- package/package.json +1 -1
- package/src/commander.ts +2 -0
- package/src/commands/doctor.ts +45 -0
- package/src/commands/grep.ts +535 -142
- package/src/commands/init.ts +138 -17
- package/src/commands/workflow.ts +132 -0
- package/src/core/agents/cli.ts +11 -4
- package/src/core/agents/rules/claim-conflict.ts +26 -1
- package/src/core/agents/rules/stop-hook.ts +17 -0
- package/src/core/agents/state/heartbeat-projector.ts +13 -1
- package/src/core/agents/state/heartbeat-writer.ts +30 -5
- package/src/core/config.ts +23 -0
- package/src/core/hooks/cli.ts +30 -3
- package/src/core/hooks/events/schema.ts +4 -0
- package/src/core/hooks/harness/events.ts +8 -0
- package/src/core/hooks/resolve/coord-root.ts +28 -6
- package/src/core/workflow/billing.ts +146 -0
- package/src/core/workflow/child-env.ts +47 -0
- package/src/core/workflow/engine.ts +394 -0
- package/src/core/workflow/harnesses.ts +38 -0
- package/src/core/workflow/spawn-claude.ts +99 -0
- package/src/core/workflow/spawn-codex.ts +74 -0
- package/src/core/workflow/spawn-cursor.ts +89 -0
- package/src/core/workflow/types.ts +153 -0
- package/src/core/workflow/validate.ts +75 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cursor spawn adapter: runs one subagent as a headless `cursor-agent -p`
|
|
3
|
+
* subprocess with `--output-format json`.
|
|
4
|
+
*
|
|
5
|
+
* Contract notes (LIVE-VERIFIED 2026-07-17 against cursor-agent
|
|
6
|
+
* 2026.07.16-899851b: schema-gated triage + text stages round-trip via
|
|
7
|
+
* `--harness cursor`, session_id parses from the envelope):
|
|
8
|
+
* - `cursor-agent -p "<prompt>" --output-format json` prints a single result
|
|
9
|
+
* envelope modeled on Claude Code's (`{type: "result", is_error, result,
|
|
10
|
+
* session_id, …}`).
|
|
11
|
+
* - `--trust` is required: headless runs refuse untrusted workspaces (exit 1,
|
|
12
|
+
* "Workspace Trust Required") — see the argv comment below.
|
|
13
|
+
* - Envelope drift guard: when stdout doesn't parse as JSON but the process
|
|
14
|
+
* exited 0, the raw stdout is returned as the reply text.
|
|
15
|
+
* - No per-run cost surface → undefined. No max-turns equivalent → `maxTurns`
|
|
16
|
+
* accepted and ignored (documented in the CLI docs page).
|
|
17
|
+
*/
|
|
18
|
+
import { exec } from "../../lib/exec.js";
|
|
19
|
+
import { buildChildEnv } from "./child-env.js";
|
|
20
|
+
import { notFoundError } from "./harnesses.js";
|
|
21
|
+
/** Exported for unit tests (no live binary to test against). */
|
|
22
|
+
export function parseCursorOutput(stdout) {
|
|
23
|
+
try {
|
|
24
|
+
const envelope = JSON.parse(stdout);
|
|
25
|
+
return {
|
|
26
|
+
text: String(envelope.result ?? ""),
|
|
27
|
+
sessionId: envelope.session_id,
|
|
28
|
+
isError: Boolean(envelope.is_error),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { text: stdout, isError: false };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export const cursorSpawner = async (req) => {
|
|
36
|
+
const t0 = Date.now();
|
|
37
|
+
// --trust: headless cursor-agent refuses untrusted workspaces (exit 1,
|
|
38
|
+
// "Workspace Trust Required"). Workflow children run in the engine's cwd
|
|
39
|
+
// deliberately and may edit files — the same posture as the codex adapter's
|
|
40
|
+
// `--sandbox workspace-write` — so trusting that directory is implied.
|
|
41
|
+
const argv = ["cursor-agent", "-p", req.prompt, "--output-format", "json", "--trust"];
|
|
42
|
+
if (req.model)
|
|
43
|
+
argv.push("--model", req.model);
|
|
44
|
+
const r = await exec(argv, {
|
|
45
|
+
cwd: req.cwd,
|
|
46
|
+
env: buildChildEnv(req.runId, { subscriptionOnly: req.subscriptionOnly }),
|
|
47
|
+
timeout: req.timeoutMs,
|
|
48
|
+
});
|
|
49
|
+
const durationMs = Date.now() - t0;
|
|
50
|
+
if (r.exitCode === 127) {
|
|
51
|
+
return { ok: false, text: "", durationMs, error: notFoundError("cursor") };
|
|
52
|
+
}
|
|
53
|
+
if (r.exitCode !== 0) {
|
|
54
|
+
return {
|
|
55
|
+
ok: false,
|
|
56
|
+
text: "",
|
|
57
|
+
durationMs,
|
|
58
|
+
error: `cursor-agent exited ${r.exitCode}: ${(r.stderr || r.stdout).slice(0, 500)}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const parsed = parseCursorOutput(r.stdout);
|
|
62
|
+
if (parsed.isError) {
|
|
63
|
+
return {
|
|
64
|
+
ok: false,
|
|
65
|
+
text: parsed.text,
|
|
66
|
+
sessionId: parsed.sessionId,
|
|
67
|
+
durationMs,
|
|
68
|
+
error: `cursor-agent reported is_error: ${parsed.text.slice(0, 300)}`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return { ok: true, text: parsed.text, sessionId: parsed.sessionId, durationMs };
|
|
72
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow engine contracts. A workflow is a small throwaway JS script with
|
|
3
|
+
* bounded, schema-gated stages that fan work out to headless harness-CLI
|
|
4
|
+
* subagents; the SCRIPT (deterministic code), not any model, decides routing
|
|
5
|
+
* between stages, and the run always terminates when the script returns.
|
|
6
|
+
*
|
|
7
|
+
* Design record: decision 0015 (portable coordination-aware workflows).
|
|
8
|
+
*/
|
|
9
|
+
import type { BillingMode, BillingProber } from "./billing.js";
|
|
10
|
+
/** JSON-schema *subset* accepted by stage gates (see validate.ts). */
|
|
11
|
+
export interface StageSchema {
|
|
12
|
+
type: "object" | "array" | "string" | "number" | "boolean";
|
|
13
|
+
/** type=object */
|
|
14
|
+
properties?: Record<string, StageSchema>;
|
|
15
|
+
required?: string[];
|
|
16
|
+
/** type=array */
|
|
17
|
+
items?: StageSchema;
|
|
18
|
+
/** any type: closed value set (compared with ===) */
|
|
19
|
+
enum?: Array<string | number | boolean>;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentOpts {
|
|
22
|
+
/** Stage gate: when present, the agent's reply must strict-parse as JSON and
|
|
23
|
+
* validate; the engine retries with the validation error appended, up to
|
|
24
|
+
* `maxAttempts`. Without it, `agent()` resolves to the raw reply text. */
|
|
25
|
+
schema?: StageSchema;
|
|
26
|
+
/** Model slug passed through to the harness CLI (default: the CLI's default). */
|
|
27
|
+
model?: string;
|
|
28
|
+
/** Attempt ceiling for the schema-retry loop (default 2). */
|
|
29
|
+
maxAttempts?: number;
|
|
30
|
+
/** Subprocess timeout ms (default 300_000). */
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
/** Harness-turn ceiling for the child (default 25; use 1 for pure
|
|
33
|
+
* classification stages — cheaper and faster). */
|
|
34
|
+
maxTurns?: number;
|
|
35
|
+
/** Display label in the journal (default: prompt head). */
|
|
36
|
+
label?: string;
|
|
37
|
+
/** Which harness runs this agent (default: the run's default harness).
|
|
38
|
+
* Mixed-harness workflows are legal: triage on one CLI, deep work on
|
|
39
|
+
* another. */
|
|
40
|
+
harness?: HarnessName;
|
|
41
|
+
}
|
|
42
|
+
export type HarnessName = "claude-code" | "codex" | "cursor";
|
|
43
|
+
/** What a spawn adapter returns for one subagent run. */
|
|
44
|
+
export interface SpawnResult {
|
|
45
|
+
ok: boolean;
|
|
46
|
+
/** The model's final reply text (envelope-unwrapped). */
|
|
47
|
+
text: string;
|
|
48
|
+
/** Child harness session id when the envelope carries one. */
|
|
49
|
+
sessionId?: string;
|
|
50
|
+
costUsd?: number;
|
|
51
|
+
durationMs: number;
|
|
52
|
+
/** Populated when ok=false. */
|
|
53
|
+
error?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface SpawnRequest {
|
|
56
|
+
prompt: string;
|
|
57
|
+
model?: string;
|
|
58
|
+
timeoutMs: number;
|
|
59
|
+
maxTurns: number;
|
|
60
|
+
cwd: string;
|
|
61
|
+
/** Run id, stamped into the child env (HARNERY_WORKFLOW_RUN_ID) so the
|
|
62
|
+
* coord layer can associate child sessions with their workflow run. */
|
|
63
|
+
runId?: string;
|
|
64
|
+
/** Scrub all API-key vars from the child env so it can only authenticate
|
|
65
|
+
* via its stored (subscription) login. See billing.ts. */
|
|
66
|
+
subscriptionOnly?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** One headless-subagent runner. The engine is adapter-agnostic; claude-code
|
|
69
|
+
* ships first, codex/cursor land behind the same signature (plan Phase 4). */
|
|
70
|
+
export type Spawner = (req: SpawnRequest) => Promise<SpawnResult>;
|
|
71
|
+
/** The API surface injected into a workflow script's default export. Explicit
|
|
72
|
+
* injection (no ambient globals): keeps scripts portable and unit-testable. */
|
|
73
|
+
export interface WorkflowContext {
|
|
74
|
+
/** Spawn one subagent; resolves to validated JSON (schema) or reply text. */
|
|
75
|
+
agent: (prompt: string, opts?: AgentOpts) => Promise<unknown>;
|
|
76
|
+
/** Run thunks with bounded concurrency; a rejected thunk resolves to null. */
|
|
77
|
+
parallel: <T>(thunks: Array<() => Promise<T>>) => Promise<Array<T | null>>;
|
|
78
|
+
/** Declare the current stage (journal + progress grouping). */
|
|
79
|
+
stage: (title: string) => void;
|
|
80
|
+
/** Narrate progress (stderr + journal). */
|
|
81
|
+
log: (message: string) => void;
|
|
82
|
+
}
|
|
83
|
+
export interface WorkflowMeta {
|
|
84
|
+
name: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
}
|
|
87
|
+
/** Loaded script shape: `export const meta` + `export default async (ctx) => …`. */
|
|
88
|
+
export interface WorkflowModule {
|
|
89
|
+
meta?: WorkflowMeta;
|
|
90
|
+
default: (ctx: WorkflowContext) => Promise<unknown>;
|
|
91
|
+
}
|
|
92
|
+
export interface EngineOpts {
|
|
93
|
+
/** Repo root whose .harnery/ receives the run journal. */
|
|
94
|
+
coordRoot: string;
|
|
95
|
+
/** Spawner registry keyed by harness. A single-harness caller registers one
|
|
96
|
+
* entry and names it in `defaultHarness`. */
|
|
97
|
+
spawners: Partial<Record<HarnessName, Spawner>>;
|
|
98
|
+
/** Harness used when an agent() call doesn't name one (default "claude-code"). */
|
|
99
|
+
defaultHarness?: HarnessName;
|
|
100
|
+
/** Resume: run id of a prior run whose journal supplies cached results.
|
|
101
|
+
* agent() calls whose (stage, prompt, model, maxTurns, schema) key matches a
|
|
102
|
+
* completed prior agent return the journaled result without spawning. */
|
|
103
|
+
resumeFrom?: string;
|
|
104
|
+
/** Total-agent ceiling for the run (default 50): the runaway backstop. */
|
|
105
|
+
maxAgents?: number;
|
|
106
|
+
/** Concurrent-subagent cap for parallel() (default 4). */
|
|
107
|
+
concurrency?: number;
|
|
108
|
+
/** Working directory children spawn in (default: coordRoot). */
|
|
109
|
+
cwd?: string;
|
|
110
|
+
/** Progress sink (default: process.stderr). */
|
|
111
|
+
onLog?: (line: string) => void;
|
|
112
|
+
/** Guarantee subscription billing: API-key vars are scrubbed from every
|
|
113
|
+
* child env, and a harness whose stored login is provably absent fails
|
|
114
|
+
* loud before spawning. */
|
|
115
|
+
subscriptionOnly?: boolean;
|
|
116
|
+
/** Permit the api-key-override billing state (an exported API key silently
|
|
117
|
+
* shadowing a stored subscription login), which the engine otherwise
|
|
118
|
+
* refuses. Deliberate key-only hosts don't need this — only the
|
|
119
|
+
* both-present case does. */
|
|
120
|
+
allowApiBilling?: boolean;
|
|
121
|
+
/** Billing-probe override for tests (default: the real probeBilling). */
|
|
122
|
+
probeBilling?: BillingProber;
|
|
123
|
+
}
|
|
124
|
+
export interface RunReport {
|
|
125
|
+
runId: string;
|
|
126
|
+
name: string;
|
|
127
|
+
/** What the script's default export returned. */
|
|
128
|
+
result: unknown;
|
|
129
|
+
agentsSpawned: number;
|
|
130
|
+
/** agent() calls satisfied from the resumeFrom journal without spawning. */
|
|
131
|
+
agentsCached: number;
|
|
132
|
+
costUsd: number;
|
|
133
|
+
durationMs: number;
|
|
134
|
+
journalPath: string;
|
|
135
|
+
/** Estimated tokens of repo instructions (CLAUDE.md/AGENTS.md at the child
|
|
136
|
+
* cwd) that EVERY child cache-writes on spawn — the fixed per-child context
|
|
137
|
+
* overhead a fan-out multiplies. bytes/4 heuristic; 0 when no such file. */
|
|
138
|
+
contextTokensPerChildEstimate: number;
|
|
139
|
+
/** Billing mode per harness actually used this run (probed on first use). */
|
|
140
|
+
billing: Array<{
|
|
141
|
+
harness: HarnessName;
|
|
142
|
+
mode: BillingMode;
|
|
143
|
+
}>;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/workflow/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE/D,sEAAsE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c,CAAC,EAAE,WAAW,CAAC;IAC7B;;6EAEyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B;;+BAE2B;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;iCAG6B;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,yEAAyE;IACzE,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB;;gFAE4E;IAC5E,6BAA6B,EAAE,MAAM,CAAC;IACtC,6EAA6E;IAC7E,OAAO,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,WAAW,CAAC;QAAC,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;CAC7D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow engine contracts. A workflow is a small throwaway JS script with
|
|
3
|
+
* bounded, schema-gated stages that fan work out to headless harness-CLI
|
|
4
|
+
* subagents; the SCRIPT (deterministic code), not any model, decides routing
|
|
5
|
+
* between stages, and the run always terminates when the script returns.
|
|
6
|
+
*
|
|
7
|
+
* Design record: decision 0015 (portable coordination-aware workflows).
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal validator for the StageSchema JSON-schema subset. Deliberately tiny:
|
|
3
|
+
* a full JSON Schema implementation would pull a dependency (ajv) for
|
|
4
|
+
* validation depth workflow gates don't need. Supported: type, properties,
|
|
5
|
+
* required, items, enum. Returns a list of human-readable problems (empty =
|
|
6
|
+
* valid) so the engine can feed failures back into the retry prompt verbatim.
|
|
7
|
+
*/
|
|
8
|
+
import type { StageSchema } from "./types.js";
|
|
9
|
+
export declare function validateAgainstSchema(value: unknown, schema: StageSchema, path?: string): string[];
|
|
10
|
+
/** Strip accidental markdown code fences, then strict-parse JSON. */
|
|
11
|
+
export declare function parseStageOutput(text: string): {
|
|
12
|
+
value?: unknown;
|
|
13
|
+
error?: string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../src/core/workflow/validate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,SAAM,GAAG,MAAM,EAAE,CA8C/F;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAUlF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal validator for the StageSchema JSON-schema subset. Deliberately tiny:
|
|
3
|
+
* a full JSON Schema implementation would pull a dependency (ajv) for
|
|
4
|
+
* validation depth workflow gates don't need. Supported: type, properties,
|
|
5
|
+
* required, items, enum. Returns a list of human-readable problems (empty =
|
|
6
|
+
* valid) so the engine can feed failures back into the retry prompt verbatim.
|
|
7
|
+
*/
|
|
8
|
+
export function validateAgainstSchema(value, schema, path = "$") {
|
|
9
|
+
const problems = [];
|
|
10
|
+
if (schema.enum) {
|
|
11
|
+
if (!schema.enum.some((v) => v === value)) {
|
|
12
|
+
problems.push(`${path}: expected one of ${JSON.stringify(schema.enum)}, got ${short(value)}`);
|
|
13
|
+
}
|
|
14
|
+
return problems; // enum is exhaustive; type check is implied by membership
|
|
15
|
+
}
|
|
16
|
+
switch (schema.type) {
|
|
17
|
+
case "object": {
|
|
18
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
19
|
+
return [`${path}: expected object, got ${short(value)}`];
|
|
20
|
+
}
|
|
21
|
+
const obj = value;
|
|
22
|
+
for (const key of schema.required ?? []) {
|
|
23
|
+
if (!(key in obj))
|
|
24
|
+
problems.push(`${path}.${key}: required property missing`);
|
|
25
|
+
}
|
|
26
|
+
for (const [key, sub] of Object.entries(schema.properties ?? {})) {
|
|
27
|
+
if (key in obj)
|
|
28
|
+
problems.push(...validateAgainstSchema(obj[key], sub, `${path}.${key}`));
|
|
29
|
+
}
|
|
30
|
+
return problems;
|
|
31
|
+
}
|
|
32
|
+
case "array": {
|
|
33
|
+
if (!Array.isArray(value))
|
|
34
|
+
return [`${path}: expected array, got ${short(value)}`];
|
|
35
|
+
if (schema.items) {
|
|
36
|
+
for (const [i, item] of value.entries()) {
|
|
37
|
+
problems.push(...validateAgainstSchema(item, schema.items, `${path}[${i}]`));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return problems;
|
|
41
|
+
}
|
|
42
|
+
case "string":
|
|
43
|
+
case "number":
|
|
44
|
+
case "boolean": {
|
|
45
|
+
if (typeof value !== schema.type) {
|
|
46
|
+
problems.push(`${path}: expected ${schema.type}, got ${short(value)}`);
|
|
47
|
+
}
|
|
48
|
+
return problems;
|
|
49
|
+
}
|
|
50
|
+
default:
|
|
51
|
+
return [`${path}: unsupported schema type ${String(schema.type)}`];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Strip accidental markdown code fences, then strict-parse JSON. */
|
|
55
|
+
export function parseStageOutput(text) {
|
|
56
|
+
const stripped = text
|
|
57
|
+
.trim()
|
|
58
|
+
.replace(/^```(?:json)?\s*/i, "")
|
|
59
|
+
.replace(/\s*```$/, "");
|
|
60
|
+
try {
|
|
61
|
+
return { value: JSON.parse(stripped) };
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
return { error: `not valid JSON: ${err.message}` };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function short(value) {
|
|
68
|
+
const s = JSON.stringify(value);
|
|
69
|
+
return s === undefined ? String(value) : s.length > 60 ? `${s.slice(0, 60)}…` : s;
|
|
70
|
+
}
|
package/package.json
CHANGED
package/src/commander.ts
CHANGED
|
@@ -49,6 +49,7 @@ import { registerSectionCommand, registerTocCommand } from "./commands/toc.ts";
|
|
|
49
49
|
import { registerTokensCommand } from "./commands/tokens.ts";
|
|
50
50
|
import { registerTunnelCommand } from "./commands/tunnel.ts";
|
|
51
51
|
import { registerWebCommand } from "./commands/web.ts";
|
|
52
|
+
import { registerWorkflowCommand } from "./commands/workflow.ts";
|
|
52
53
|
|
|
53
54
|
export interface HarneryContextOpts {
|
|
54
55
|
/**
|
|
@@ -277,6 +278,7 @@ export function createHarneryProgram(opts: HarneryContextOpts = {}): Command {
|
|
|
277
278
|
registerDeinitCommand(program, emit, opts.binName);
|
|
278
279
|
registerBackupCommand(program, emit);
|
|
279
280
|
registerSyncCommand(program, emit);
|
|
281
|
+
registerWorkflowCommand(program, emit);
|
|
280
282
|
if (include("web")) registerWebCommand(program, emit);
|
|
281
283
|
|
|
282
284
|
return program;
|
package/src/commands/doctor.ts
CHANGED
|
@@ -19,6 +19,13 @@ import type { Command } from "commander";
|
|
|
19
19
|
import type { EmitContext } from "../commander.ts";
|
|
20
20
|
import { resolveBinName, ripgrepAutoInstall } from "../core/config.ts";
|
|
21
21
|
import { loadHarnessWiring } from "../core/hooks/harness/wiring.ts";
|
|
22
|
+
import { probeBilling } from "../core/workflow/billing.ts";
|
|
23
|
+
import {
|
|
24
|
+
HARNESS_BINARIES,
|
|
25
|
+
HARNESS_INSTALL_HINTS,
|
|
26
|
+
HARNESS_LOGIN_HINTS,
|
|
27
|
+
} from "../core/workflow/harnesses.ts";
|
|
28
|
+
import type { HarnessName } from "../core/workflow/types.ts";
|
|
22
29
|
import { findRg, installRg, managedRgPath, rgInstallSupported } from "../lib/tools/ripgrep.ts";
|
|
23
30
|
|
|
24
31
|
type Severity = "ok" | "warn" | "fail";
|
|
@@ -96,6 +103,9 @@ export function runChecks(): Check[] {
|
|
|
96
103
|
checkRipgrep(),
|
|
97
104
|
checkHarneryDir(),
|
|
98
105
|
checkHarnessHooks(),
|
|
106
|
+
checkWorkflowHarness("claude-code"),
|
|
107
|
+
checkWorkflowHarness("codex"),
|
|
108
|
+
checkWorkflowHarness("cursor"),
|
|
99
109
|
checkRestic(),
|
|
100
110
|
checkRclone(),
|
|
101
111
|
checkPlaywright(),
|
|
@@ -144,6 +154,41 @@ function whichVersion(bin: string, args: string[] = ["--version"]): { ok: boolea
|
|
|
144
154
|
return { ok: true, out };
|
|
145
155
|
}
|
|
146
156
|
|
|
157
|
+
/**
|
|
158
|
+
* One workflow spawn target: is the harness CLI installed, and how will its
|
|
159
|
+
* headless children bill (subscription login vs API key — see billing.ts)?
|
|
160
|
+
* Missing is a warn, not a fail: workflows degrade to the harnesses you have.
|
|
161
|
+
*/
|
|
162
|
+
function checkWorkflowHarness(harness: HarnessName): Check {
|
|
163
|
+
const bin = HARNESS_BINARIES[harness];
|
|
164
|
+
const name = `workflow:${harness}`;
|
|
165
|
+
const r = whichVersion(bin);
|
|
166
|
+
if (!r.ok) {
|
|
167
|
+
return {
|
|
168
|
+
name,
|
|
169
|
+
severity: "warn",
|
|
170
|
+
detail: `${bin} missing (workflow --harness ${harness} unavailable)`,
|
|
171
|
+
hint: `${HARNESS_INSTALL_HINTS[harness]} then: ${HARNESS_LOGIN_HINTS[harness]}`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
const probe = probeBilling(harness);
|
|
175
|
+
if (probe.login === "absent" && !probe.apiKeyPresent) {
|
|
176
|
+
return {
|
|
177
|
+
name,
|
|
178
|
+
severity: "warn",
|
|
179
|
+
detail: `${r.out} — installed, but no stored login or API key detected`,
|
|
180
|
+
hint: HARNESS_LOGIN_HINTS[harness],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const billing =
|
|
184
|
+
probe.mode === "subscription"
|
|
185
|
+
? probe.login === "present"
|
|
186
|
+
? "billing: subscription"
|
|
187
|
+
: "billing: subscription (login unverifiable, CLI is the authority)"
|
|
188
|
+
: `billing: ${probe.mode} (${probe.apiKeySource})`;
|
|
189
|
+
return { name, severity: "ok", detail: `${r.out} — ${billing}` };
|
|
190
|
+
}
|
|
191
|
+
|
|
147
192
|
function checkNode(): Check {
|
|
148
193
|
const v = process.versions.node;
|
|
149
194
|
const major = Number.parseInt(v.split(".")[0], 10);
|