@manhquy/flow-skill 0.1.0-rc.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +21 -0
  3. package/README.md +152 -0
  4. package/README_VN.md +134 -0
  5. package/SECURITY.md +69 -0
  6. package/bin/cli.mjs +382 -0
  7. package/package.json +52 -0
  8. package/skills/flow/SKILL.md +234 -0
  9. package/skills/flow/_templates/00-idea.md +16 -0
  10. package/skills/flow/_templates/00-inspect.md +42 -0
  11. package/skills/flow/_templates/01-research.md +59 -0
  12. package/skills/flow/_templates/02-scope.md +71 -0
  13. package/skills/flow/_templates/03-prd.md +57 -0
  14. package/skills/flow/_templates/04-adr.md +21 -0
  15. package/skills/flow/_templates/05-contract.md +59 -0
  16. package/skills/flow/_templates/card.md +26 -0
  17. package/skills/flow/_templates/constitution.md +22 -0
  18. package/skills/flow/eval/fixtures/f01a/flow/01-research.md +77 -0
  19. package/skills/flow/eval/fixtures/f01b/flow/01-research.md +75 -0
  20. package/skills/flow/eval/fixtures/f02a/flow/02-scope.md +56 -0
  21. package/skills/flow/eval/fixtures/f02b/flow/02-scope.md +65 -0
  22. package/skills/flow/eval/fixtures/fcda/.flow/.gitkeep +0 -0
  23. package/skills/flow/eval/fixtures/fcda/cards/C-001.md +46 -0
  24. package/skills/flow/eval/fixtures/fcdb/.flow/.gitkeep +0 -0
  25. package/skills/flow/eval/fixtures/fcdb/cards/C-001.md +35 -0
  26. package/skills/flow/eval/manifest.tsv +7 -0
  27. package/skills/flow/harness/README.md +117 -0
  28. package/skills/flow/harness/_db.py +228 -0
  29. package/skills/flow/harness/_domain.py +161 -0
  30. package/skills/flow/harness/_presence.py +109 -0
  31. package/skills/flow/harness/flow_harness.py +1103 -0
  32. package/skills/flow/harness/repo_map.py +93 -0
  33. package/skills/flow/harness/schema/001-init.sql +129 -0
  34. package/skills/flow/harness/schema/002-story-verify.sql +9 -0
  35. package/skills/flow/harness/schema/003-tool-registry.sql +15 -0
  36. package/skills/flow/harness/schema/004-intervention.sql +15 -0
  37. package/skills/flow/harness/schema/005-tool-extensions.sql +20 -0
  38. package/skills/flow/harness/schema/009-accessed-count.sql +11 -0
  39. package/skills/flow/harness/schema/010-usage-event.sql +42 -0
  40. package/skills/flow/harness/schema/011-usage-gate-reason.sql +8 -0
  41. package/skills/flow/harness/schema/012-usage-ephemeral.sql +10 -0
  42. package/skills/flow/law/CLAUDE.md +140 -0
  43. package/skills/flow/law/DESIGN.md +141 -0
  44. package/skills/flow/law/RETRO.md +13 -0
  45. package/skills/flow/playbooks/README.md +28 -0
  46. package/skills/flow/playbooks/cloudflare-ai-gateway-qwen.md +346 -0
  47. package/skills/flow/playbooks/docker-deploy-stale-cache.md +32 -0
  48. package/skills/flow/playbooks/rag-lite-postgres-cloudflare.md +192 -0
  49. package/skills/flow/playbooks/windows-gitbash-jsonl-telemetry.md +57 -0
  50. package/skills/flow/references/adversarial-review.md +197 -0
  51. package/skills/flow/references/agent-detection.md +88 -0
  52. package/skills/flow/references/agent-stage-mapping.md +114 -0
  53. package/skills/flow/references/antigravity-integration.md +92 -0
  54. package/skills/flow/references/auto-run.md +81 -0
  55. package/skills/flow/references/claudekit-skills.md +128 -0
  56. package/skills/flow/references/codex-integration.md +104 -0
  57. package/skills/flow/references/command-dispatch.md +54 -0
  58. package/skills/flow/references/debt-and-halts.md +41 -0
  59. package/skills/flow/references/design-review-checklist.md +42 -0
  60. package/skills/flow/references/gate-eval.md +186 -0
  61. package/skills/flow/references/gate-rules.md +171 -0
  62. package/skills/flow/references/ground-truth-gates.md +49 -0
  63. package/skills/flow/references/loop-harness-2026-principles.md +52 -0
  64. package/skills/flow/references/mode-work.md +37 -0
  65. package/skills/flow/references/project-types.md +42 -0
  66. package/skills/flow/references/stage-state-machine.md +47 -0
  67. package/skills/flow/references/ui-patterns-tcr.md +49 -0
  68. package/skills/flow/runner/flow.cmd +18 -0
  69. package/skills/flow/runner/flow.sh +3297 -0
  70. package/skills-manifest.json +70 -0
  71. package/src/constants.mjs +65 -0
  72. package/src/detect.mjs +36 -0
  73. package/src/help.mjs +42 -0
  74. package/src/installer.mjs +231 -0
  75. package/src/prompt.mjs +60 -0
  76. package/src/tty.mjs +11 -0
package/bin/cli.mjs ADDED
@@ -0,0 +1,382 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from 'node:util';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { join, resolve } from 'node:path';
5
+ import { existsSync } from 'node:fs';
6
+
7
+ import { TARGETS, TARGET_NAMES, PKG_VERSION } from '../src/constants.mjs';
8
+ import { defaultSelection, detectAll } from '../src/detect.mjs';
9
+ import { renderHelp } from '../src/help.mjs';
10
+ import { install, installAntigravity } from '../src/installer.mjs';
11
+ import { isInteractive } from '../src/tty.mjs';
12
+
13
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
14
+ const pkgRoot = resolve(__dirname, '..');
15
+ const bundledSkillDir = join(pkgRoot, 'skills', 'flow');
16
+
17
+ // F5 — runtime Node version guard. `engines` in package.json is advisory only; npm >=8 respects
18
+ // it during install but `npx --yes` (and standalone `node`) do not. Fail loudly instead.
19
+ // Floor is Node 22.14 for two reasons: (1) Node 20 EOL passed April 2026, (2) our publish
20
+ // workflow requires npm >=11.5.1 which ships bundled with Node 22.14.0+ (needed for OIDC
21
+ // Trusted Publisher handshake). Users on Node 20 will still install because npm engines is
22
+ // advisory, but they get a loud error here rather than a mysterious runtime failure later.
23
+ const MIN_NODE = [22, 14, 0];
24
+ function checkNodeVersion() {
25
+ const parts = process.versions.node.split('.').map((n) => parseInt(n, 10));
26
+ for (let i = 0; i < MIN_NODE.length; i++) {
27
+ if (parts[i] > MIN_NODE[i]) return;
28
+ if (parts[i] < MIN_NODE[i]) {
29
+ process.stderr.write(
30
+ `flow-skill requires Node.js >=${MIN_NODE.join('.')} (running ${process.versions.node}).\n`
31
+ );
32
+ process.exit(2);
33
+ }
34
+ }
35
+ }
36
+ checkNodeVersion();
37
+
38
+ function parseCliArgs(argv) {
39
+ const { values } = parseArgs({
40
+ args: argv,
41
+ allowPositionals: false,
42
+ options: {
43
+ yes: { type: 'boolean', short: 'y', default: false },
44
+ target: { type: 'string', short: 't', multiple: true, default: [] },
45
+ all: { type: 'boolean', default: false },
46
+ project: { type: 'boolean', default: false },
47
+ dir: { type: 'string' },
48
+ json: { type: 'boolean', default: false },
49
+ 'dry-run': { type: 'boolean', default: false },
50
+ help: { type: 'boolean', short: 'h', default: false },
51
+ },
52
+ });
53
+ // Split comma-form (-t claude,codex) into individual entries. mri wouldn't do this;
54
+ // parseArgs preserves the raw string, so we normalize here.
55
+ const targets = values.target
56
+ .flatMap((t) => String(t).split(','))
57
+ .map((t) => t.trim())
58
+ .filter(Boolean);
59
+ return {
60
+ yes: values.yes,
61
+ targets,
62
+ all: values.all,
63
+ project: values.project,
64
+ dir: values.dir,
65
+ json: values.json,
66
+ dryRun: values['dry-run'],
67
+ help: values.help,
68
+ };
69
+ }
70
+
71
+ function emit(event, jsonMode) {
72
+ if (jsonMode) {
73
+ process.stdout.write(JSON.stringify(event) + '\n');
74
+ }
75
+ }
76
+
77
+ function log(msg, jsonMode) {
78
+ if (!jsonMode) process.stdout.write(msg + '\n');
79
+ }
80
+
81
+ function warn(msg, jsonMode) {
82
+ if (!jsonMode) process.stderr.write(msg + '\n');
83
+ }
84
+
85
+ function errorExit(msg, code, jsonMode) {
86
+ if (jsonMode) {
87
+ process.stdout.write(
88
+ JSON.stringify({ event: 'error', message: msg, exitCode: code }) + '\n'
89
+ );
90
+ } else {
91
+ process.stderr.write(`Error: ${msg}\n`);
92
+ }
93
+ process.exit(code);
94
+ }
95
+
96
+ function validateTargetNames(names) {
97
+ const invalid = names.filter((n) => !TARGET_NAMES.includes(n));
98
+ if (invalid.length) {
99
+ return `unknown target(s): ${invalid.join(', ')}. Valid: ${TARGET_NAMES.join(', ')}`;
100
+ }
101
+ return null;
102
+ }
103
+
104
+ // Non-interactive selection: --all wins, else explicit -t, else default (alwaysInclude || detected).
105
+ function selectNonInteractive({ entries, targets, all }) {
106
+ if (all) return entries.map((e) => e.name);
107
+ if (targets.length) return targets;
108
+ return defaultSelection(entries);
109
+ }
110
+
111
+ // L15/R2-A: project scope allows only projectScopeAllowed=true targets.
112
+ function enforceProjectScope(selectedNames, project) {
113
+ if (!project) return { ok: true, kept: selectedNames, dropped: [] };
114
+ const kept = selectedNames.filter(
115
+ (n) => TARGETS.find((t) => t.name === n)?.projectScopeAllowed
116
+ );
117
+ const dropped = selectedNames.filter((n) => !kept.includes(n));
118
+ return { ok: kept.length > 0, kept, dropped };
119
+ }
120
+
121
+ // Build the concrete install plan (target -> destination list).
122
+ function buildPlan(selectedNames, entries, { project, dir }) {
123
+ const projectDir = dir || process.cwd();
124
+ return selectedNames.map((name) => {
125
+ const t = entries.find((e) => e.name === name);
126
+ if (!t) throw new Error(`internal: no entry for ${name}`);
127
+ const dests = project ? [join(projectDir, '.claude', 'skills', 'flow')] : t.dests;
128
+ return { target: name, label: t.label, dests };
129
+ });
130
+ }
131
+
132
+ function humanPlan(plan, scope, dir) {
133
+ const lines = [`Install plan (scope: ${scope}${scope === 'project' ? `, dir: ${dir}` : ''})`];
134
+ for (const step of plan) {
135
+ lines.push(` - ${step.target.padEnd(12)} ${step.label}`);
136
+ for (const d of step.dests) lines.push(` -> ${d}`);
137
+ }
138
+ return lines.join('\n');
139
+ }
140
+
141
+ function humanResult(target, result) {
142
+ const status = result.success ? '✔' : '✗';
143
+ const dests = Array.isArray(result.dests)
144
+ ? result.dests.join(', ')
145
+ : result.dest || '';
146
+ const err = result.success ? '' : ` (${result.error})`;
147
+ return `${status} ${target} -> ${dests}${err}`;
148
+ }
149
+
150
+ async function main() {
151
+ const rawArgs = process.argv.slice(2);
152
+ let opts;
153
+ try {
154
+ opts = parseCliArgs(rawArgs);
155
+ } catch (err) {
156
+ process.stderr.write(`Error: ${err.message}\nRun with --help for usage.\n`);
157
+ process.exit(2);
158
+ }
159
+
160
+ if (opts.help) {
161
+ process.stdout.write(renderHelp());
162
+ process.exit(0);
163
+ }
164
+
165
+ // Confirm the bundled skill exists — sync must have run before packaging.
166
+ if (!existsSync(join(bundledSkillDir, 'SKILL.md'))) {
167
+ errorExit(
168
+ `bundled skill not found at ${bundledSkillDir}. If running from a dev checkout, run 'npm run sync' first.`,
169
+ 3,
170
+ opts.json
171
+ );
172
+ }
173
+
174
+ const invalid = validateTargetNames(opts.targets);
175
+ if (invalid) errorExit(invalid, 2, opts.json);
176
+
177
+ const entries = detectAll();
178
+
179
+ // Interactive path: only when no flags force a decision AND we have a real TTY on both ends.
180
+ // --dry-run + interactive is fine (we'll still prompt so the user can preview the plan).
181
+ const useInteractive =
182
+ !opts.yes &&
183
+ !opts.all &&
184
+ !opts.targets.length &&
185
+ !opts.project &&
186
+ !opts.json &&
187
+ isInteractive();
188
+
189
+ let selected;
190
+ let scope;
191
+ let projectDir;
192
+
193
+ if (useInteractive) {
194
+ const { promptTargets, promptScope, promptConfirm, filterProjectScope, intro, outro, cancel } =
195
+ await import('../src/prompt.mjs');
196
+ intro('flow-skill installer');
197
+
198
+ const t = await promptTargets(entries);
199
+ if (t.cancelled) {
200
+ cancel('cancelled');
201
+ process.exit(130);
202
+ }
203
+ selected = t.targets;
204
+
205
+ const s = await promptScope(process.cwd());
206
+ if (s.cancelled) {
207
+ cancel('cancelled');
208
+ process.exit(130);
209
+ }
210
+ scope = s.scope;
211
+ projectDir = process.cwd();
212
+
213
+ if (scope === 'project') {
214
+ const { kept, dropped } = filterProjectScope(selected);
215
+ if (dropped.length) {
216
+ warn(
217
+ `Project scope drops non-claude targets: ${dropped.join(', ')}`,
218
+ false
219
+ );
220
+ }
221
+ if (!kept.length) {
222
+ errorExit(
223
+ `--project scope supports only 'claude' target and no claude target selected.`,
224
+ 2,
225
+ false
226
+ );
227
+ }
228
+ selected = kept;
229
+ }
230
+
231
+ const c = await promptConfirm({ count: selected.length });
232
+ if (c.cancelled || !c.ok) {
233
+ cancel('cancelled');
234
+ process.exit(0);
235
+ }
236
+ outro('installing...');
237
+ } else {
238
+ selected = selectNonInteractive({
239
+ entries,
240
+ targets: opts.targets,
241
+ all: opts.all,
242
+ });
243
+ const scopeCheck = enforceProjectScope(selected, opts.project);
244
+ if (!scopeCheck.ok) {
245
+ errorExit(
246
+ `--project scope supports only 'claude' target. Invalid: ${scopeCheck.dropped.join(', ') || '(none selected)'}.`,
247
+ 2,
248
+ opts.json
249
+ );
250
+ }
251
+ if (scopeCheck.dropped.length && !opts.json) {
252
+ warn(
253
+ `Warning: project scope drops non-claude targets: ${scopeCheck.dropped.join(', ')}`,
254
+ false
255
+ );
256
+ }
257
+ selected = scopeCheck.kept;
258
+ scope = opts.project ? 'project' : 'global';
259
+ projectDir = opts.dir || process.cwd();
260
+ }
261
+
262
+ const plan = buildPlan(selected, entries, { project: scope === 'project', dir: projectDir });
263
+
264
+ emit(
265
+ {
266
+ event: 'plan',
267
+ version: PKG_VERSION,
268
+ dryRun: opts.dryRun,
269
+ scope,
270
+ targets: plan.map((p) => p.target),
271
+ },
272
+ opts.json
273
+ );
274
+
275
+ if (opts.dryRun) {
276
+ log(humanPlan(plan, scope, projectDir), opts.json);
277
+ process.exit(0);
278
+ }
279
+
280
+ // F4 — declare `results` BEFORE the SIGINT handler that closes over it. Const-after-handler
281
+ // would TDZ-throw if the user presses Ctrl+C before we ever get to the loop.
282
+ const results = [];
283
+ let aborted = false;
284
+
285
+ // SIGINT: flip a flag that the loop reads BETWEEN install() calls, after each install's
286
+ // finally-block has released its lock. We cannot preempt a synchronous cpSync/rmSync — Node
287
+ // signal handlers only fire when the JS stack unwinds. So this handler only affects
288
+ // multi-target runs (it stops the next iteration). Single-target Ctrl+C during copy relies
289
+ // on Node's default (exit 130 at loop unwind). No second-strike hard-exit — that was
290
+ // aspirational and would have leaked the current install's lock.
291
+ const onSigint = () => {
292
+ aborted = true;
293
+ };
294
+ process.on('SIGINT', onSigint);
295
+ for (const step of plan) {
296
+ if (aborted) break;
297
+ emit(
298
+ { event: 'install:start', target: step.target, dests: step.dests },
299
+ opts.json
300
+ );
301
+
302
+ let result;
303
+ if (step.target === 'antigravity') {
304
+ result = installAntigravity({ sourceDir: bundledSkillDir, dests: step.dests });
305
+ } else {
306
+ // Non-antigravity targets always have exactly one destination.
307
+ result = install({ sourceDir: bundledSkillDir, destDir: step.dests[0] });
308
+ }
309
+
310
+ results.push({ ...result, target: step.target, dests: step.dests });
311
+
312
+ emit(
313
+ {
314
+ event: 'install:done',
315
+ target: step.target,
316
+ dests: step.dests,
317
+ result: result.success ? 'success' : 'failed',
318
+ error: result.error ?? null,
319
+ warnings: result.warnings ?? [],
320
+ },
321
+ opts.json
322
+ );
323
+
324
+ log(humanResult(step.target, { ...result, dests: step.dests }), opts.json);
325
+
326
+ if (!result.success) break; // fail-fast
327
+ if (aborted) break; // Ctrl+C received; installer.mjs's finally already released the lock
328
+ }
329
+
330
+ process.off('SIGINT', onSigint);
331
+
332
+ const success =
333
+ !aborted && results.length === plan.length && results.every((r) => r.success);
334
+ emit(
335
+ {
336
+ event: 'summary',
337
+ success,
338
+ total: plan.length,
339
+ attempted: results.length,
340
+ installed: results.filter((r) => r.success).length,
341
+ failed: results.filter((r) => !r.success).length,
342
+ skipped: plan.length - results.length,
343
+ aborted,
344
+ },
345
+ opts.json
346
+ );
347
+
348
+ if (!opts.json && success) {
349
+ log(
350
+ '\nDone. Claude Code: type /flow | Codex CLI: type $flow (restart Codex once).',
351
+ false
352
+ );
353
+ }
354
+
355
+ // If aborted mid-loop, exit 130 (matches shell convention) instead of the generic failure.
356
+ if (aborted) process.exit(130);
357
+ process.exit(success ? 0 : 1);
358
+ }
359
+
360
+ main().catch((err) => {
361
+ // F2 — a crash inside main() must not truncate JSONL: emit a machine-parseable summary
362
+ // before exit so CI consumers can distinguish "crashed" from "hung".
363
+ const isJson = process.argv.includes('--json');
364
+ const message = err?.message ?? String(err);
365
+ if (isJson) {
366
+ process.stdout.write(
367
+ JSON.stringify({
368
+ event: 'summary',
369
+ success: false,
370
+ total: 0,
371
+ attempted: 0,
372
+ installed: 0,
373
+ failed: 0,
374
+ skipped: 0,
375
+ aborted: false,
376
+ error: message,
377
+ }) + '\n'
378
+ );
379
+ }
380
+ process.stderr.write(`Fatal: ${err?.stack ?? err}\n`);
381
+ process.exit(1);
382
+ });
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@manhquy/flow-skill",
3
+ "version": "0.1.0-rc.1",
4
+ "description": "Install the flow skill (buildflow gated build process) into your coding agent(s) via one npx command",
5
+ "type": "module",
6
+ "bin": {
7
+ "flow-skill": "bin/cli.mjs"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "src/",
12
+ "skills/",
13
+ "skills-manifest.json",
14
+ "README.md",
15
+ "README_VN.md",
16
+ "LICENSE",
17
+ "SECURITY.md",
18
+ "CHANGELOG.md"
19
+ ],
20
+ "engines": {
21
+ "node": ">=22.14.0"
22
+ },
23
+ "scripts": {
24
+ "sync": "node scripts/sync.mjs",
25
+ "prepack": "node scripts/sync.mjs",
26
+ "test": "node --test test/installer.test.mjs test/detect.test.mjs test/cli.test.mjs test/lock-atomicity.test.mjs",
27
+ "smoke": "node scripts/smoke.mjs"
28
+ },
29
+ "dependencies": {
30
+ "@clack/prompts": "~0.11.0"
31
+ },
32
+ "keywords": [
33
+ "flow",
34
+ "skill",
35
+ "npx",
36
+ "installer",
37
+ "coding-agent",
38
+ "claude-code",
39
+ "codex",
40
+ "antigravity"
41
+ ],
42
+ "author": "manhquy <manhquy.mqy@gmail.com>",
43
+ "license": "MIT",
44
+ "homepage": "https://github.com/manhquydev/flow-skill#readme",
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/manhquydev/flow-skill.git"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/manhquydev/flow-skill/issues"
51
+ }
52
+ }
@@ -0,0 +1,234 @@
1
+ ---
2
+ name: flow
3
+ description: Run the buildflow gated build process from idea to real done-evidence. Walk gated stages (Idea->Research->Scope->PRD->ADR->Contract->Cards->Build->Review->Deploy/Ship->Verify->Retro), each with a honest gate that must pass before advancing. Adapts to project type (web|cli|library|skill). Use when starting or driving a real product build, when the user types /flow, /flow next, /flow card, /flow check, or asks to scope/plan/ship a project through gates. Kill at any gate is a valid outcome.
4
+ user-invocable: true
5
+ when_to_use: "User wants to build a real product end-to-end with discipline (idea -> a deployed URL for web, or installs+runs for a CLI/library/skill), or types any /flow command, or asks for a gated build process, scope decision, contract-first plan, or card-based shipping."
6
+ argument-hint: "[ resume | next | card | check C-NNN | project-type web|cli|library|skill | mode teach|work | skip <stage> | ready | workspace add|list|enter|remove|check|doctor | auto | doctor | retro | eval --stage 01|02|card --fixture <id> --n 3 --keep-going --report ]"
7
+ keywords: [flow, buildflow, gate, build, ship, scope, prd, contract, card, deploy, vertical-slice, cli, library, skill, worktree, parallel-agents, workspace, multi-agent]
8
+ license: MIT
9
+ metadata:
10
+ author: flow-skill
11
+ version: "0.21.0"
12
+ attribution: "Methodology from ai20k-build-phase/buildflow (Tony, arealisticdreamer.com); harness/agent layers from repository-harness, claudekit-engineer, BMAD-METHOD."
13
+ ---
14
+
15
+ # /flow — buildflow gated build harness
16
+
17
+ Idea to a **deployed URL**, not idea to paperwork. You walk gated stages; each has an
18
+ **output artifact** and a **GATE** — a checklist that must be honestly satisfied before
19
+ you advance. **Kill at any gate is a valid, honored outcome** (killing a weak idea at
20
+ Scope is cheap and smart).
21
+
22
+ ```
23
+ Idea -> Research -> Scope -> PRD -> ADR -> Contract -> Cards -> Build -> Review -> Deploy -> Verify-live -> Retro
24
+ |------------------ planning (files in flow/) ------------------| |------- shipping (inside cards/) -------|
25
+ ```
26
+
27
+ ## Two-layer harness (this is the core idea)
28
+
29
+ `/flow` is **two layers working together**:
30
+
31
+ 1. **Mechanical layer — `runner/flow.sh`** (deterministic, exit 0/1). It manages the
32
+ stage/card lifecycle and checks the *cheatable* things: unchecked gate boxes,
33
+ leftover `[FILL]` placeholders, card status validity, empty done-evidence. Always run
34
+ it first — its exit code is ground truth, never your own judgment.
35
+ 2. **Semantic layer — YOU (Claude), via this skill** (quality gatekeeper). The script
36
+ cannot tell a real competitor quote from a fabricated one, or a grade-laundered C
37
+ feature from an honest B. **That is your job.** After the script passes, apply the
38
+ per-stage challenges in `references/gate-rules.md` before you let the operator advance.
39
+
40
+ A gate is only truly passed when **both** layers agree. The script can pass while the
41
+ content is hollow — catch that.
42
+
43
+ ## Running the mechanical layer
44
+
45
+ From the **project root** (where `flow/` and `cards/` live), run the runner that ships
46
+ with this skill:
47
+
48
+ ```
49
+ # macOS / Linux / Windows Git Bash:
50
+ bash <skill-dir>/runner/flow.sh <command> # e.g. bash ~/.claude/skills/flow/runner/flow.sh next
51
+
52
+ # Windows PowerShell or cmd (INCLUDING inside Codex): use the .cmd launcher, NOT bare `bash`.
53
+ <skill-dir>\runner\flow.cmd <command> # e.g. ...\.codex\skills\flow\runner\flow.cmd status
54
+ # from PowerShell call it directly: & "<skill-dir>\runner\flow.cmd" status
55
+ ```
56
+
57
+ **Windows / Codex gotcha (read this):** in PowerShell/Codex a bare `bash` usually resolves to
58
+ **WSL** (`C:\WINDOWS\system32\bash.exe`), which **cannot** read `C:/...` or `/c/...` paths and
59
+ fails with `No such file or directory` — the mechanical layer then looks "broken" when it is not.
60
+ **Always invoke `runner/flow.cmd`** on Windows; it locates Git Bash and runs the engine with a
61
+ path Git Bash accepts. Only call `bash flow.sh` directly when you've confirmed `bash` is Git Bash.
62
+
63
+ `<skill-dir>` is wherever this skill is installed (`~/.claude/skills/flow`, `~/.codex/skills/flow`,
64
+ `~/.agents/skills/flow`, the Antigravity homes `~/.gemini/antigravity-cli/skills/flow` (CLI) /
65
+ `~/.gemini/config/skills/flow` (IDE), or a project `.claude/skills/flow`). The runner reads/writes
66
+ `flow/` and `cards/` under the current directory (override with `FLOW_PROJECT_ROOT`).
67
+
68
+ **Antigravity (`agy` CLI / IDE):** flow installs as the same `SKILL.md` bundle; run `agy inspect` to
69
+ confirm Antigravity discovered it. The mechanical layer is the **same** `bash flow.sh` / `flow.cmd`
70
+ runner — the Windows WSL-bash trap below applies identically (use `flow.cmd` from a Windows shell).
71
+ The Antigravity agent invokes shell tools, so it drives `flow.sh` like any other harness.
72
+
73
+ **One session per project (concurrency lock).** Two `/flow` sessions sharing one project
74
+ will stomp each other's plan. The runner keeps a `flow/.lock` (auto-reclaimed after
75
+ `FLOW_LOCK_TTL`, default 900s): mutating commands (`next`/`card`/`skip`/`auto`) refuse a
76
+ fresh **foreign** lock and `status` warns. For hard protection, **export a stable
77
+ `FLOW_SESSION_ID` once per session** and pass it on every call (e.g.
78
+ `FLOW_SESSION_ID=$mysid bash <skill-dir>/runner/flow.sh next`) — without it the runner can
79
+ only warn (it can't prove a different session, so it never self-blocks). `FLOW_FORCE=1`
80
+ takes over a lock you're sure is dead; `/flow unlock` clears it.
81
+
82
+ ## Commands
83
+
84
+ | You type | Skill does |
85
+ |---|---|
86
+ | `/flow` | `flow.sh status` — where am I, what's blocking, card states |
87
+ | `/flow resume` | `flow.sh resume` — **read-only session-story brief for entering a project mid-cycle**: last session (command names only, never raw args), in-flight card + dwell, gate state, one `NEXT ->` line. No lock. Run this FIRST when picking up an existing project (see the dispatch rule below). |
88
+ | `/flow next` | `flow.sh next` — gate-check current stage; on pass, unlock next stage. **Then** you apply the semantic challenge for the stage just passed. |
89
+ | `/flow assess` | `flow.sh assess` — **brownfield**: scaffold + gate a current-state assessment (`flow/00-inspect.md`, auto-scan seeded) for an EXISTING codebase before planning. Operator-reviewed. |
90
+ | `/flow card` | `flow.sh card` — create next build card (only after all 6 planning gates pass) |
91
+ | `/flow card start C-NNN` | `flow.sh card start` — mark a card **in flight** (operator-visible in-progress; shown in `/flow status`). Tracked in a portable `cards/.inflight` registry, never touches the gated `status:` field. Optional convenience — coexists with hand-editing. |
92
+ | `/flow card done C-NNN` | `flow.sh card done` — CLI-owned flip of a card to `done`, gated by the SAME done-rules as `check` (real Evidence + checked Verify); **reverts** if the gate fails (never a hollow done). Coexists with hand-editing `status: done` + `/flow check`. |
93
+ | `/flow check C-NNN` | `flow.sh check C-NNN` — validate a card; **then** you review diff-vs-scope, allowed-files drift, contract shapes, DESIGN.md for UI, and that evidence is real world-state |
94
+ | `/flow mode teach\|work` | set who writes the artifacts (default `teach`) |
95
+ | `/flow ready` | `flow.sh ready` — which todo cards are buildable + parallel-safety hint |
96
+ | `/flow workspace add\|list\|enter\|remove\|check\|doctor` | `flow.sh workspace …` — **multi-agent worktree isolation** for running several agents (Claude/Codex/Antigravity, many terminals) in parallel WITHOUT the "one agent switches branch → every terminal flips" trap. Each agent gets its own `git worktree` (own HEAD/index/files, shared object store); git is the live registry (`git worktree list`) and a 10-field JSONL side-file (`.flow/workspaces.jsonl`) adds vendor/card/port/task. `add <branch> [--card C-NNN] [--vendor …] [--task …] [--copy-env]` provisions a worktree + distinct port-offset + paste-ready cd/env block; `list` shows who-is-where; `enter <branch>` re-prints a crashed terminal's env; `check <branch> [--card]` flags branch-claim + allowed-files overlap before you launch; `remove <branch> [--force]` tears down safely (never auto-forces); `doctor` reconciles orphan trees/records. Advisory layer; git's refusal to check out one branch twice is the real lock. |
97
+ | `/flow auto` | `flow.sh auto` preflight, then drive the autonomous run (see AUTO principles) |
98
+ | `/flow recall` | `flow.sh recall` — read back durable memory (open debt, recent retro, previous-card scope, harness friction/backlog, playbooks) **at the start of a stage/card** so you don't re-learn known pain |
99
+ | `/flow usage` | `flow.sh usage` — roll up the mechanical usage log (JSONL flight-recorder of every invocation) into `usage_event` and print build analytics: cycle-time, gate fail-rate, per-stage dwell, cycle completion, command breakdown. `--global` for the device-wide view; `--prune [--keep N]` caps the log (crash-safe). Local-only; disable with `FLOW_LOG_DISABLE=1`/`DO_NOT_TRACK=1`. `recall` now surfaces a one-line usage digest and `retro`'s `propose` flags chronically-failing stages. |
100
+ | `/flow contract` | `flow.sh contract` — flag client base-URL vs served-path prefix drift (web; advisory; run after the contract gate) |
101
+ | `/flow tokens` | `flow.sh tokens` — flag DESIGN.md vs CSS design-token drift: unused tokens + value mismatches + orphan vars (advisory; UI cards) |
102
+ | `/flow coherence` | `flow.sh coherence` — flag version drift across declared version fields (doc-vs-code coherence; advisory) |
103
+ | `/flow consistency` | `flow.sh consistency` — audit cross-artifact coverage: every PRD `FRn` is claimed by a card (`implements:`) and served by a contract interface; numeric success metric; no leftover placeholders (advisory; run after the contract gate, before cards) |
104
+ | `/flow constitution` | `flow.sh constitution` — check operator-authored per-project invariants in `flow/constitution.md` (structure + optional grep-markers); **advisory and NOT a `next` gate** — run it at the scope/PRD/contract seam, then apply the semantic challenge in `gate-rules.md` |
105
+ | `/flow eval [--stage 01\|02\|card] [--fixture <id>] [--n 3] [--timeout <s>] [--keep-going]` | `flow.sh eval` — **behavioral eval**: does the LLM semantic gate (`gate-rules.md`) actually flag a hollow-but-mechanically-clean fixture? Opt-in, **billable** (skips cleanly, zero calls, if `claude` CLI absent); prints a per-stage scorecard. v0.21: on a final-INVALID vote, raw stdout + stderr + rc are persisted to `.flow/eval-raw/<run_id>/` (git-ignored, envelope-stripped) so an INVALID storm is postmortemable; the first UNRELIABLE fixture aborts the batch (`--keep-going` forces full-batch, worst-case ~37 calls at `--n 3`); the retry backoff is env-injectable (`FLOW_EVAL_RETRY_BACKOFF`, default 5s, set 0 in tests). See `references/gate-eval.md` for scope/cost/limitations. |
106
+ | `/flow eval --report` | `flow.sh eval --report` — **offline**, zero calls: last complete batch's scorecard + drift vs the prior complete batch |
107
+ | `/flow promote <file>` | `flow.sh promote <file>` — copy a playbook into the cross-project KB (`~/.claude/flow/playbooks`); `recall` then surfaces it everywhere |
108
+ | `/flow project-type <web\|cli\|library\|skill>` | `flow.sh project-type` — set/read the project type that selects the per-type gate lens (`references/project-types.md`) |
109
+ | `/flow skip <stage>` | `flow.sh skip` — advance past a gate that has a matching open `DEBT.md` line; **security-class skips are operator-only and HALT** (never auto-skipped) |
110
+ | `/flow doctor` | `flow.sh doctor` — environment/install self-check (paths, runner, Git Bash) |
111
+ | `/flow harness … \| debt … \| design` | runner subsystems: `harness` (durable intake/story/trace/decision/backlog — see `harness/README.md`), `debt` (record/list deliberate gate-skips), `design` (mechanical UI-token check) |
112
+ | `/flow unlock` | `flow.sh unlock` — clear this project's concurrency lock after a crashed/abandoned session |
113
+ | `/flow retro` | the 3 retro questions; the operator writes the line, never you |
114
+
115
+ ## Dispatch rules (how to behave for each command)
116
+
117
+ 1. **Entering a project mid-cycle? Run `/flow resume` before any other flow verb.** If this is
118
+ a fresh session (no prior context in this conversation) and the project already has a
119
+ `flow/` or `cards/` dir, `resume` is the read-only session-story brief that replaces
120
+ re-deriving state from scratch — last session, in-flight card + dwell, gate state, one
121
+ `NEXT ->` line. Skip this only when you already have live context (e.g. you were the one who
122
+ just ran `next`/`card` this same session) — running it every single command is unnecessary.
123
+ 2. **Always call `flow.sh` first** and read its exit code + output. Relay it faithfully. If it
124
+ reports **BLOCKED by another session's lock**, STOP and coordinate — never `FLOW_FORCE` past a
125
+ live session; concurrent `/flow` runs corrupt the plan.
126
+ 3. **On `next`:** if the script FAILS, stop — report exactly what it listed (line numbers),
127
+ and offer to help fill, but **never check a box or write an artifact on the operator's
128
+ behalf** in `teach` mode. If the script PASSES, run the **semantic gate** for the stage
129
+ just completed (see `references/gate-rules.md`). If you find hollow content (fabricated
130
+ quotes, grade-laundering, a pain with no feature, an endpoint with no auth), tell the
131
+ operator it mechanically passed but is qualitatively weak, and let them decide. Do not
132
+ silently advance past a hollow artifact; do not silently block a sound one.
133
+ 4. **On `card`/`check`:** enforce the build-session laws in `law/CLAUDE.md` — one card per
134
+ session, touch only `## Allowed files`, contract is the seam, done = world-state proof.
135
+ **Before authoring a new stage or card, run `/flow recall`** and treat its output (prior
136
+ debt / retro / friction / previous-card scope) as context to apply, not noise.
137
+ 5. **Mode `work`:** interview the operator once, draft stages 00–05 yourself, pause only
138
+ for scope sign-off, deliver the card set as one summary. Gates and done-rules are
139
+ identical to `teach` — you still must pass every gate, you just also author.
140
+ 6. **Never** edit `_templates/` or `runner/flow.sh` during a project run. Read any file the
141
+ runner just created before editing it.
142
+
143
+ ## The three rules under everything (from law/CLAUDE.md)
144
+
145
+ 1. **Inspect first.** Before planning, look at what already exists (competitors, live
146
+ systems, code). Evidence, not vibes.
147
+ 2. **Contract is the seam.** The API contract (stage 05) is written before any code.
148
+ Backend builds TO it, UI consumes FROM it. Never improvise a shape; amend the contract
149
+ first, then code. Honor a shape now (null/stub) even when its value ships in a later card.
150
+ 3. **Done = proof in the world.** Every card names its done-evidence up front. Verify on
151
+ the live URL as a user. "Tests pass" / "code merged" are mid-pipeline, never done.
152
+
153
+ ## Agent orchestration
154
+
155
+ Each stage can delegate to a specialist agent, and degrades to built-in behavior when none
156
+ exist — `/flow` stays portable. Priority: **ck: agents first, bmad-* skills as alternative,
157
+ built-in fallback** (`references/agent-detection.md`). When the `openai-codex` plugin is present
158
+ **and usable**, a cross-vendor **Codex (GPT-5.x) second engine** unlocks — used at three gated
159
+ moments: two-strikes rescue, cross-model adversarial review (a different *model*, not just a
160
+ different context), and opt-in primary drafter at research/build (default stays ck:). It detects
161
+ and degrades like every other tier (installed≠usable; absence never breaks a run). Full seam,
162
+ cost gate, and shapes: **`references/codex-integration.md`**. When `agy`/the Antigravity IDE is
163
+ present **and usable**, a cross-vendor **Antigravity (Gemini-3) third engine** unlocks too — same
164
+ high-value moments, giving a **three-model** adversarial gate. Antigravity needs the strictest
165
+ usability check (`agy -p` returns exit 0 + empty stdout even when unauthenticated, so route only on
166
+ non-empty expected output, never exit code; headless capture is unreliable → interactive review is
167
+ the supported default). Full seam: **`references/antigravity-integration.md`**. The stage→agent map, scoped prompt
168
+ template, and durable-record hooks are in `references/agent-stage-mapping.md`:
169
+ research→`researcher`, scope/PRD→`planner`, ADR→`architect`, contract→`bmad-spec` kernel,
170
+ build→`fullstack-developer`, review→`code-reviewer` or `bmad-code-review` (3-layer
171
+ adversarial), verify-live→`tester`. **The gate is identical on every path** — an agent
172
+ drafts, the gate still judges. Give each subagent ONLY task + files + acceptance + relevant
173
+ law/contract excerpts (no session history); each returns DONE/DONE_WITH_CONCERNS/BLOCKED/
174
+ NEEDS_CONTEXT. After a delegation: run the gate, apply the semantic challenge, write the
175
+ durable hook (`flow.sh harness ...`), announce which path ran.
176
+
177
+ Mode `work` (`references/mode-work.md`): interview once → draft 00-05 → one scope pause →
178
+ deliver the card set as one summary. Gates bind the same as `teach`.
179
+
180
+ ## AUTO principles
181
+
182
+ `/flow auto` drives the build phase autonomously (`references/auto-run.md`). Operator
183
+ setting: **Tier-A auto-merge green cards; halt at security-class.** Per card: tier-classify
184
+ → one scoped subagent in its own worktree → build to contract → adversarial review →
185
+ `flow.sh check` PASS → merge in card order → deploy → **verify on the LIVE URL** (merge ≠
186
+ shipped) → world-state evidence → `status: done` → durable trace + `AUTO-LOG.md`.
187
+ - **Tier A**: green + no security-class → auto-merge, no ask.
188
+ - **Tier B**: fixable issues → one repair by a FRESH subagent (two-strikes), else escalate.
189
+ If the fix needs >1 experimental attempt against a single numeric target (not a review
190
+ disagreement), reach for `flow.sh loop-prep` + the `ck-loop` skill instead — see
191
+ "Loop vs two-strikes" in `references/claudekit-skills.md`.
192
+ - **Tier C**: security-class (auth, authorization, admin exposure, tenancy, payments, data
193
+ migration, removing validation) → **HALT.** Operator accepts the exposure in `DEBT.md`,
194
+ in writing. Never planner-decided.
195
+ Hard stops (iteration/token/time caps) and ground-truth gates (`flow.sh` exit, real
196
+ `## Verify` runs, live check — never an agent's self-assessment) are mandatory.
197
+
198
+ ## Law & reference files
199
+
200
+ - `law/CLAUDE.md` — build-session discipline, card sequence, PR/merge, debt, worktree, forbidden. **Read before building any card.**
201
+ - `law/DESIGN.md` — UI law for every mock/frontend card (tokens, affordance ladder, object-first, never-do list).
202
+ - `law/RETRO.md` — one honest line per run.
203
+ - `references/gate-rules.md` — the per-stage semantic challenges (the heart of your gatekeeping).
204
+ - `references/stage-state-machine.md` — stage order, unlock conditions, what each artifact must contain.
205
+ - `references/project-types.md` — per-type (web|cli|library|skill) adaptations of the stages, gate lenses, and done-evidence.
206
+ - `references/command-dispatch.md` — exact mapping of each `/flow` command to runner call + your duties.
207
+ - `references/agent-detection.md` — detect ck:/bmad agents + priority + fallback.
208
+ - `references/agent-stage-mapping.md` — stage→agent map, scoped prompt template, durable hooks.
209
+ - `references/claudekit-skills.md` — the **skill layer** on top of the agents: the curated per-stage ck-skill whitelist ("what to use when"), the 6 deep-wired high-ROI skills (ck-predict@ADR, ck-scenario@Contract, review-pr@Review/Ship, ck-security@security-cards, retro@Retro, ck-loop@Build/Verify), the binding rules (skill INFORMS / gate JUDGES; Claude-side detection + silent degrade; opt-in-with-prompt, off the hot path), and the loop-vs-two-strikes decision matrix (`flow.sh loop-prep`/`loop-log` plumbing, ck-loop as the untouched execution engine).
210
+ - `references/codex-integration.md` — the Codex cross-vendor second-engine seam: detection (installed≠usable), cost gate, invocation surfaces, ReviewResult shape, gate parity.
211
+ - `references/antigravity-integration.md` — the Antigravity (Gemini-3) cross-vendor third-engine seam: install homes, strict usability (exit code lies → route on non-empty output), interactive-default review, cost/data gate, gate parity.
212
+ - `references/gate-rules.md` → "Cross-artifact consistency" — the semantic passes behind `/flow consistency` (hollow coverage, conflicting requirements, cut-list contradiction, terminology drift) that the runner's ID-based check can't judge.
213
+ - `references/mode-work.md` — work-mode script (interview once → draft → one scope pause → summary).
214
+ - `references/auto-run.md` — `/flow auto` tiers, worktree loop, AUTO-LOG, security-class halt.
215
+ - `references/loop-harness-2026-principles.md` — harness-first, hard stops, ground-truth, context isolation.
216
+ - `references/ground-truth-gates.md` — the mechanical signal each gate decides on (never self-assessment).
217
+ - `references/adversarial-review.md` — the 3-layer "must find issues" Review gate + triage.
218
+ - `references/debt-and-halts.md` — `DEBT.md` ledger, security-class Tier-C halt, when a run halts.
219
+ - `references/design-review-checklist.md` — UI card review (mechanical `flow.sh design` + semantic DESIGN.md).
220
+ - `references/ui-patterns-tcr.md` — 7 UI patterns + T-C-R frame + pattern-choice priority rules.
221
+ - `references/gate-eval.md` — `/flow eval` behavioral proof for the semantic layer: what it
222
+ measures (a fresh-judge lower bound, NOT the work-mode self-challenge), cost, thresholds,
223
+ and the honest authorship-bias limitation. Read before running or relaying a scorecard.
224
+ - `harness/` — durable layer (`flow.sh harness ...`): intake/story/trace/decision/backlog. See `harness/README.md`. Read it back with `/flow recall` (open debt, retro, previous-card, friction, backlog, playbooks) — this is the capture→reuse loop.
225
+ - `playbooks/` — paid-for stack knowledge: read before building a card on that stack, harvest the lesson after.
226
+ - `_templates/` — the 7 artifacts the runner copies into `flow/` and `cards/`. Never edit during a run.
227
+
228
+ ## Forbidden
229
+
230
+ - Checking a gate box or writing a planning artifact on the operator's behalf (in `teach` mode).
231
+ - Setting a card `done` without pasted world-state evidence.
232
+ - Building two cards in one session, or in parallel before `/flow ready` marks them safe.
233
+ - Frontend code before the UI mock card is approved.
234
+ - Editing `_templates/` or `runner/flow.sh` during a project run.