@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
@@ -0,0 +1,171 @@
1
+ # Gate rules — the semantic layer
2
+
3
+ The runner (`flow.sh`) checks the mechanical gate: no `[FILL]`, no unchecked `- [ ]`, valid
4
+ card status, non-empty evidence. **This file is what YOU check after the script passes.**
5
+ The script cannot judge truth or quality; you can. For each stage, after a mechanical PASS,
6
+ run the challenge below. If it fails, tell the operator: *"mechanically passed, but
7
+ qualitatively weak: <reason>"* and let them decide — never silently advance a hollow
8
+ artifact, never silently block a sound one.
9
+
10
+ > Rule of behavior: in `teach` mode you do NOT edit the artifact or tick boxes. You report.
11
+ > In `work` mode you authored it, so you self-challenge before presenting.
12
+
13
+ > Authoring note (when editing these challenges): **match the form to the failure.** A challenge
14
+ > that fights a *discipline drift* — the agent rationalizing a hollow artifact through (grade
15
+ > laundering, fabricated quotes, "merge ≈ shipped") — is rightly a prohibition + the specific
16
+ > rationalization it counters. A challenge that fixes a *wrong-shaped artifact* (a missing field, a
17
+ > drifted name) is better written as a positive recipe — "every interface has both shapes, names
18
+ > that won't drift" — than as a ban; a bare prohibition on a shaping problem can produce *more* of
19
+ > the bad shape, not less, and a hedging "unless it matters" clause turns a crisp recipe noisy. Pick
20
+ > the form deliberately; don't reflexively reach for another "do NOT".
21
+
22
+ ## Stage 00 — Idea
23
+ Mechanical: pitch present, one real person named, no FILL.
24
+ **Challenge:** Is the pitch really 3 sentences (who / pain / what)? Is the named person a
25
+ *real, specific* person or group ("my uncle's 20-unit building"), not "people who..." or
26
+ "users"? Is the pain concrete, not a category?
27
+
28
+ ## Stage 01 — Research
29
+ Mechanical: 7 boxes checked, no FILL.
30
+ **Apply the lens by project type (`/flow project-type`, default web):**
31
+ - **web / market product** → the strict version below. Reject the soft "non-web" framing for a
32
+ product that has a real market: a real product DOES have online complaints + a GTM channel,
33
+ and dodging them is the failure this gate exists to catch.
34
+ - **cli / library / skill / internal tool** → items 2+4 use first-party friction + who-benefits.
35
+ Demand it be *concrete and real* (a named observed pain, named beneficiaries) — not vague.
36
+ "No market channel" is expected here and is NOT a kill signal.
37
+ **Challenge (highest fabrication risk):**
38
+ - Were 3 competitors *actually opened*? Each note should read like someone used the tool. (all types)
39
+ - web: are the 3 complaints *real quotes with working source links*? · non-web: is the
40
+ first-party friction *concrete and observed* (who hit it, when), not a guess?
41
+ - Are competitor/status-quo costs *real* (web: prices+who-pays · non-web: time/manual-work spent today)?
42
+ - web: is the first-10-users channel a *specific place* (reject "social media"/"online") ·
43
+ non-web: are the *named beneficiaries* + how-they-learn real?
44
+ - Does the switch reason name what makes the *named* users move off today's workaround?
45
+
46
+ ## Stage 02 — Scope (the decision stage)
47
+ Mechanical: every feature has Impact (H/M/L) + Grade (A/B/C), no L-above-A in v1, cut list,
48
+ GO/KILL, no FILL.
49
+ **Challenge — watch for GRADE LAUNDERING:**
50
+ - Is any expensive feature quietly graded B when it's really C? (realtime, payments from
51
+ scratch, custom auth, autonomous agentic pipeline, heavy concurrency = C). Call C a C.
52
+ - For every C in scope, is it justified as one of: (1) C IS the product -> it goes FIRST;
53
+ (2) re-architected C->B (e.g. multi-step agent -> single structured call; auto-send ->
54
+ human-approves-draft; custom -> managed service); (3) irreducible -> KILL/re-budget?
55
+ - Classic failure: v1 full of A-grade L-impact features (cheap to build, worthless to sell).
56
+ - If the product itself is a C, is it FIRST in build order with sibling Cs on the cut list?
57
+
58
+ ## Stage 03 — PRD
59
+ Mechanical: filled from stage 02, numeric success metric, pain&gain table, no FILL.
60
+ **Challenge:**
61
+ - Is the success metric a real NUMBER ("first response < 2h"), not "save time" / "better UX"?
62
+ - The pain&gain table is the spine: does *every pain* cite evidence (a stage-01 quote or
63
+ named observation) AND name the v1 feature that kills it? Does *every v1 feature* kill at
64
+ least one pain? Orphans on either side = scope drift.
65
+ - Could a stranger build v1 from this without asking the operator anything?
66
+
67
+ ## Stage 04 — ADR
68
+ Mechanical: each decision has why + rejected, NOT-doing list, covers storage/auth/deploy.
69
+ **Challenge:** Does each decision name a *real* rejected alternative (not a strawman)? Are
70
+ data storage, auth approach, and deploy target all actually decided (not "TBD")? Is the
71
+ NOT-doing list honest about what's deferred?
72
+ - **Optional `ck-predict` (when present, non-trivial decision).** Before locking a risky
73
+ decision, offer a 5-persona debate (`ck-predict`) — it surfaces arch/security/perf/UX defects
74
+ when reversal is cheapest. Output INFORMS this challenge; it never passes the gate. Skip on a
75
+ trivial ADR (opt-in-with-prompt — see `claudekit-skills.md`).
76
+
77
+ ## Stage 05 — Contract (the seam)
78
+ Mechanical: every PRD feature -> >=1 interface, every interface has input+output shapes,
79
+ access/effects column filled, no FILL.
80
+ **The "interface" is the project type's seam** (`/flow project-type`): web=endpoint,
81
+ cli=command+flags+output/exit, library=public function+args+return, skill=command/file.
82
+ **Challenge — this is where producer/consumer drift is born (every type):**
83
+ - Does every PRD feature map to at least one interface, and vice versa?
84
+ - Does every interface have BOTH input and output shapes, with field/flag names that will not
85
+ drift (the #1 AI-build failure: backend ships `player_email`, UI assumed `email`, both green;
86
+ the cli equivalent: `--out` vs `--output`)?
87
+ - Is the access/effects column real for every interface (web: public/token/admin · non-web:
88
+ writes/side-effects or "none")? Do NOT let a web product blank the access column.
89
+ - One-way rule: this file is planning source of truth. For web the served spec
90
+ (`/openapi.json`) is the runtime artifact of the SAME contract (amend file -> code -> spec).
91
+ For non-web there is no served spec — the no-drift check is the per-type done-evidence.
92
+ - **Self-consistency pass (the contract is ground truth every downstream card trusts).** Before
93
+ passing this gate, read the contract AGAINST any doc it names as its own source of truth and
94
+ re-state each shared rule in your own words — a contradiction here ships as "passed" and every
95
+ card inherits it. (This gate once passed an internally-inconsistent seam that only a later
96
+ cross-model review caught — catch that class HERE, at its source, where it is cheapest.) When the
97
+ **codex tier is USABLE**, an OPTIONAL opt-in **cross-model** check of the contract is the
98
+ highest-value single Codex call in a run — a different engine breaks the same-model blind spot at
99
+ the one artifact whose drift is most expensive downstream.
100
+ - **Optional `ck-scenario` (when present).** Offer 12-dimension edge-case decomposition to
101
+ harden the seam: each case becomes an acceptance criterion + a per-type no-drift check, so the
102
+ contract is exhaustive before any card trusts it. Complements `/flow consistency` (it
103
+ *generates* cases; consistency checks *coherence*). INFORMS the gate; never auto-passes it.
104
+ Opt-in-with-prompt — see `claudekit-skills.md`.
105
+
106
+ ## Card gate (`/flow check C-NNN`)
107
+ Mechanical: no FILL, valid status, required sections, if done -> verify boxes checked +
108
+ evidence non-empty.
109
+ **Challenge:**
110
+ - Is the scope ONE thing? If it's two, split the card.
111
+ - Does the diff touch only `## Allowed files`? Drift outside = stop, amend the card first.
112
+ - Do request/response shapes match `flow/05-contract.md` exactly? No improvised shapes.
113
+ - For UI cards: reviewed against `law/DESIGN.md` (tokens, affordance ladder, object-first,
114
+ no engine words, no emoji, no gradient on inputs/tables)?
115
+ - **Is `## Evidence` real world-state** — a clickable URL, real curl output, a DB row — and
116
+ NOT "tests pass" / "code merged" / "deployed successfully"? Merge != shipped: the proof is
117
+ the live surface changing, verified as a user.
118
+ - **If this card fixes a bug/regression**, the evidence includes the red→green proof that the
119
+ new test was actually tied to the bug (`ground-truth-gates.md` → "Bug-fix cards"), not just a
120
+ green run.
121
+
122
+ ## Cross-artifact consistency (`/flow consistency`)
123
+ Run after the Contract gate and before building cards (advisory; never blocks the build path).
124
+ The runner does the **precise, ID-based** passes mechanically: every PRD `FRn` is claimed by a
125
+ card (`implements:`) and served by an interface, the success metric carries a number, no leftover
126
+ placeholders. **You do the passes that need judgment, not string-matching:**
127
+ - **Hollow coverage:** an `FRn` is "covered" by a card whose scope does not actually deliver it
128
+ (the id is referenced but the work isn't there). Mechanical coverage can be gamed by pasting an
129
+ id; read the card scope against the feature.
130
+ - **Conflicting requirements:** two artifacts state incompatible things (PRD says no-login, ADR
131
+ decides OAuth; scope cut a feature the PRD still lists). The runner won't catch a contradiction
132
+ expressed in different words — you must.
133
+ - **Cut-list contradiction:** a feature on the stage-02 cut list reappears (by name, not id) as a
134
+ v1 PRD feature or a card. Scope drift in disguise.
135
+ - **Terminology drift:** the same entity named differently across artifacts (`ticket`/`issue`/
136
+ `request`) — the seed of producer/consumer drift the contract gate guards against.
137
+ If you find any, report *"`consistency` passed mechanically, but <artifact> contradicts <artifact>
138
+ on <thing>"* and let the operator decide — same posture as every other gate.
139
+
140
+ **Canonical form the mechanical pass expects** (deviate and coverage silently can't map — the runner
141
+ then prints "no FR ids found" rather than a false pass, but be aware): FR ids are **uppercase `FRn`**,
142
+ declared in the PRD's **`## Features`** section (ids in prose or the pain table are intentionally
143
+ ignored so a legacy mention can't inflate the set). A blank success-metric body is the gate's job, not
144
+ this probe's (it only checks "if a metric exists, it carries a number"). When `consistency` reports
145
+ "no FR ids found", treat it as *coverage-unverified*, not *coverage-clean*.
146
+
147
+ ## Constitution challenge (operator invariants — run at scope/PRD/contract)
148
+
149
+ `flow.sh constitution` is the mechanical half: it proves the `flow/constitution.md` table is
150
+ well-formed (no placeholder, every invariant has an ID) and scans any declared grep-marker. It
151
+ **cannot** tell whether the artifact you just wrote actually *honors* the invariant — that is your
152
+ job. After the mechanical pass, for each invariant whose `applies-at` includes the current stage,
153
+ challenge the stage artifact against it:
154
+
155
+ - Read each invariant (e.g. "all PII access is facility-scoped", "no API surface ships without a
156
+ `flow/05-contract.md` entry").
157
+ - Walk the current artifact (scope / PRD / contract) and ask: does anything here *violate* it, or
158
+ quietly assume an exception? A contract endpoint exposing cross-tenant data violates a
159
+ facility-scoped invariant even though the table is structurally clean.
160
+ - If you find a violation, report *"constitution passed mechanically, but `<artifact>` violates
161
+ invariant `<ID>` (`<rule>`)"* and let the operator decide — same posture as every other gate.
162
+
163
+ This is **advisory and per-project**; it never auto-blocks `next`, and it does NOT replace the
164
+ security-class Tier-C halt (a constitution rule may *restate* a security concern, but the halt is
165
+ the enforcement). Low-noise by design: the mechanical layer is structural, the judgement is yours.
166
+
167
+ ## Debt (deliberate skips)
168
+ If the operator deliberately skips/reorders a gate, ensure a line opens in `DEBT.md` naming
169
+ the skip, the concrete exposure, and the close condition. **Security-class skips** (auth,
170
+ admin exposure, tenancy, payments) are never silent and never your decision — the operator
171
+ accepts the exposure in writing. In `/flow auto`, that is a Tier-C halt.
@@ -0,0 +1,49 @@
1
+ # Ground-truth gates
2
+
3
+ At any decision point that advances, merges, or marks done, the gate condition MUST be a
4
+ mechanical signal — not the model's opinion that it's fine. LLM self-assessment is advisory
5
+ and used only to add color, never to pass a gate.
6
+
7
+ ## The signal per gate
8
+
9
+ | Decision | Ground-truth signal | NOT acceptable as the gate |
10
+ |---|---|---|
11
+ | Stage 00-05 advance | `flow.sh next` exit 0 (no `[FILL]`, no unchecked box) | "the artifact looks complete" |
12
+ | Card valid | `flow.sh check C-NNN` exit 0 | "I filled the card" |
13
+ | Card behavior works | the card's `## Verify` steps RUN for real (curl/click/command + expected output) | "the code should work" / "tests would pass" |
14
+ | Story proof | `flow.sh harness story verify <id>` -> `verify_command` exit 0 | "I wrote tests" |
15
+ | Build merged-safe | review green (adversarial) + `flow.sh check` pass | "the diff is small" |
16
+ | Card DONE | deploy ran + **live URL verified as a user** (world-state evidence pasted) | "merged" / "deploy succeeded" / "tests pass" |
17
+ | Contract not drifted | contract-test card asserts every endpoint exists in live `/openapi.json` with matching shape | "backend and UI agree" (they don't, silently) |
18
+
19
+ ## Rules
20
+ 1. **The model never grades its own gate.** Use `flow.sh` exit codes and real command
21
+ output. If a tool can produce a number/exit code, that is the gate.
22
+ 2. **"Tests pass" is mid-pipeline, not done.** Done = a surface that changed in the world,
23
+ verified live. (buildflow rule 3.)
24
+ 3. **Self-assessment is color, not verdict.** An agent saying "looks correct" can accompany
25
+ a green signal; it can never substitute for one.
26
+ 4. **A red signal stops the run.** No "probably fine" override. Fix or open debt.
27
+ 5. **Capture the proof.** Paste the real curl/URL/exit into the card `## Evidence` and the
28
+ harness `trace` — so the next session sees ground truth, not a claim.
29
+
30
+ ## Bug-fix cards: prove the test was tied to the bug
31
+ When a card's job is fixing a bug/regression (not new behavior), a passing test is not yet
32
+ ground truth — a test written after the fix can pass without ever having exercised the bug. The
33
+ ground-truth signal is the **red→green** pair: with the fix reverted the new test FAILS, with the
34
+ fix restored it PASSES. Paste both runs into `## Evidence`. The reverted-failure must fail **for the
35
+ bug's reason** — its message names the bugged behavior/output (a wrong value, a missing rejection, a
36
+ bad status), NOT an `ImportError`/compile/setup/typo error. A revert that errors before reaching the
37
+ asserted behavior proves nothing; if you see a collection/import/syntax error on revert, the test is
38
+ not yet tied to the bug — fix the harness and re-run. This is a *technique for this card class*, not a
39
+ project-wide test-first law — flow stays contract-/evidence-first. It is cleanest for
40
+ `cli`/`library`/`skill` cards where a fix reverts in isolation. For a `web` card whose fix genuinely
41
+ cannot revert cleanly (migration, stateful backend), the waiver is **not** agent-self-asserted: name
42
+ the **specific** blocking dependency in `## Evidence` (e.g. "irreversible migration `0042_*`",
43
+ "shared session store") and still paste a live `## Verify` reproduction that shows the **original
44
+ symptom before** the fix and its absence **after** — a bare post-fix green is not the signal.
45
+
46
+ ## Why
47
+ LLM-as-judge is useful for triage and prioritization but unreliable at the exact moment a
48
+ mistake becomes expensive (a merge, a deploy, a "done"). The whole buildflow philosophy —
49
+ "done = proof in the world" — is ground-truth gating made into a method.
@@ -0,0 +1,52 @@
1
+ # Loop & harness engineering principles (2026)
2
+
3
+ The principles `/flow` enforces during loops and autonomous runs. Distilled from current
4
+ agentic-engineering practice and mapped to concrete flow points. We apply the **principles**;
5
+ where a source cited a specific number, treat it as illustrative and verify in context.
6
+ (Source: `research-report-agent-orchestration-2026.md`.)
7
+
8
+ ## 1. Harness-first, not prompt-first
9
+ Quality comes from the scaffold (gates, loop control, durable state, budget), not from
10
+ prompt tuning. `/flow` IS that scaffold: `flow.sh` gates + `harness/` durable records +
11
+ the AUTO loop. When a run goes wrong, fix the harness (open a `backlog` item), don't just
12
+ re-prompt. -> `flow.sh harness backlog add` (growth rule).
13
+
14
+ ## 2. Hard stops are mandatory
15
+ Every loop/auto run declares caps: **max iterations per card**, **token budget**,
16
+ **wall-clock**. Exceed any -> HALT + report, never continue silently. A loop with no
17
+ termination criterion is an antipattern. -> see `auto-run.md` "Hard stops".
18
+
19
+ ## 3. Ground-truth verification at decision points
20
+ At a gate that decides "advance/merge/done", trust a mechanical signal, not the model's
21
+ self-assessment: `flow.sh` exit code, story `verify_command` exit, the card's `## Verify`
22
+ run for real, the deploy + live-URL check. LLM-as-judge is advisory only, never the gate.
23
+ -> `ground-truth-gates.md`.
24
+
25
+ ## 4. Adversarial verification before committing
26
+ Before a card merges, an independent reviewer (or 3, with information asymmetry) must try
27
+ to REFUTE it. "Must find issues; zero findings -> re-analyze." -> `adversarial-review.md`.
28
+
29
+ ## 5. Context isolation fights context rot
30
+ Model accuracy degrades as the window fills. Keep each subagent's context small and scoped
31
+ (task + files + acceptance + relevant law excerpts — no session history), and push durable
32
+ state OUT to `harness/` (external memory) and `flow/` + `cards/` (on-disk artifacts). One
33
+ card = one fresh, small context. -> `agent-detection.md` context rules.
34
+
35
+ ## 6. Spec/contract-first prevents drift
36
+ The #1 AI-build failure is producer/consumer drift (backend ships one shape, UI assumes
37
+ another, both green). The contract (stage 05) written before code, asserted against the
38
+ live spec by the contract-test card, is the cheap fix. "Contract is the seam."
39
+
40
+ ## 7. Make truncation legible
41
+ If a run bounds coverage (top-N cards, skipped a gate, sampled), SAY so. A silent cap reads
42
+ as "covered everything". Debt is the ledger for deliberate skips -> `debt-and-halts.md`.
43
+
44
+ ## Mapping to flow points
45
+ | Principle | Enforced at |
46
+ |---|---|
47
+ | Hard stops | `/flow auto` loop (iteration/token/time caps) |
48
+ | Ground-truth | every gate decision (`flow.sh` exit, verify runs, live check) |
49
+ | Adversarial | Review step before merge (`code-reviewer` / `bmad-code-review`) |
50
+ | Context isolation | per-card scoped subagent brief + `harness/` external memory |
51
+ | Contract-first | stage 05 + contract-test card |
52
+ | Legible truncation | `DEBT.md` + `AUTO-LOG.md` + announce path/verdict |
@@ -0,0 +1,37 @@
1
+ # Mode: work (AI drafts, gates still bind)
2
+
3
+ `MODE` file at project root (default `teach`). Set with `/flow mode work`.
4
+
5
+ - **teach** — the operator writes every artifact; you only gatekeep. Default.
6
+ - **work** — you interview the operator ONCE, draft stages 00-05 yourself, pause only for
7
+ scope sign-off, deliver the card set as one summary. **Gates and done-rules are identical
8
+ to teach** — you still pass every gate, you just also author.
9
+
10
+ ## The work-mode shape (interview once -> draft -> one pause -> summary)
11
+
12
+ 1. **Interview once.** Ask a single tight batch (use `AskUserQuestion`): the idea in one
13
+ line, who has the pain (a real named person/group), the rough budget/time, the stack if
14
+ they have a preference, and the one channel for the first users. Don't drip questions
15
+ across stages.
16
+ 2. **Draft 00 -> 01 -> 02.** Fill idea, do real research (delegate to `researcher` per
17
+ `agent-stage-mapping.md` — actually open competitors, quote real complaints with links),
18
+ and produce the scope table with honest Impact + Grade. Run each gate with `flow.sh next`.
19
+ 3. **ONE scope pause.** Stop at the Scope gate (stage 02). Present the GO/KILL + cut list +
20
+ any C-feature path decisions and get explicit sign-off. This is the only mandatory pause
21
+ in work mode — scope is the operator's call, and killing here is cheap.
22
+ 4. **Draft 03 -> 05.** PRD (numeric metric, pain->feature mapping), ADR (delegate to
23
+ `architect`/`bmad-create-architecture`), Contract (the seam; consider `bmad-spec` kernel).
24
+ Run each gate.
25
+ 5. **Deliver the card set as one summary.** After stage 05 passes, run `/flow card` to
26
+ create the cards, fill their scopes, and present the whole set + build order + which are
27
+ parallel-safe (`/flow ready`) in a single summary for the operator to review.
28
+
29
+ ## Rules that still hold in work mode
30
+ - Every gate must pass mechanically (`flow.sh`) AND semantically (`gate-rules.md`). Drafting
31
+ does not lower the bar — self-challenge before presenting (you are now the author AND under
32
+ review, so apply the adversarial lens to your own draft).
33
+ - Research must be real (opened competitors, quoted complaints with links) — no fabrication.
34
+ This is the highest-risk stage for an AI author; verify every quote has a source.
35
+ - Scope honesty: do not grade-launder your own C features to B. Call C a C, justify the path.
36
+ - Done is still world-state evidence; you cannot mark a card done without real proof.
37
+ - Write durable records (intake/decision/story) as you go, same as teach mode.
@@ -0,0 +1,42 @@
1
+ # Project types — adapting the gates to what you're building
2
+
3
+ `/flow` was born web-shaped. Set the type with `flow.sh project-type <web|cli|library|skill>`
4
+ (stored in `PROJECT_TYPE`, default `web`). The type adapts three things: what the Contract
5
+ "seam" is, the standard card sequence, and — most importantly — what **done-evidence** means.
6
+ The *spirit* of every gate is unchanged ("done = proof in the world", "contract before
7
+ code"); only the shape of the proof changes.
8
+
9
+ ## Per-type table
10
+
11
+ | Type | Contract seam (stage 05) | Done-evidence (the real proof) | Card sequence |
12
+ |---|---|---|---|
13
+ | **web** | HTTP endpoints (Method/Path/Auth/Request/Response); OpenAPI served | a live deployed URL + real curl output | scaffold+`/healthz` -> vertical slice (endpoint+page) -> backend -> contract-test -> UI mock -> frontend -> e2e |
14
+ | **cli** | commands + flags + output shapes + exit codes | the tool **installs and a real invocation returns the expected output + exit code** | scaffold+one real command -> subcommand groups -> tests -> install smoke on a clean dir |
15
+ | **library** | the public API surface (exported functions/types + their shapes) | the **public API imports + a usage example runs + coverage threshold met** | scaffold+core API -> rounds of API -> tests -> a runnable usage example -> publish dry-run |
16
+ | **skill** | the commands + files the agent reads (SKILL.md surface) | **installed into `~/.claude/skills` + a real run reaches its own done-definition** | scaffold+one runnable command -> references/law -> install -> a dogfood run |
17
+
18
+ ## What stays the same (all types)
19
+ - Every PRD feature maps to an interface; every interface has its shapes written BEFORE code.
20
+ - "Tests pass" / "merged" is mid-pipeline, never done — done is the type's real-world proof above.
21
+ - The contract is the seam: producers build TO it, consumers FROM it; amend the contract first.
22
+
23
+ ## Gate-wording note (known web-flavoring — see backlog #4)
24
+ The stage-05 gate text still says "endpoint" and "auth (public/token/admin)". For non-web
25
+ types, read "endpoint" as "interface/command" and replace the auth column with
26
+ "writes/side-effects" (the stage-05 preamble explicitly licenses this adaptation). The
27
+ `web`-only OpenAPI/Swagger rule is N/A for cli/library/skill — the equivalent "no drift"
28
+ check is the per-type done-evidence actually passing.
29
+
30
+ ## Legitimate gate-skips
31
+ When a gate genuinely doesn't fit your type (e.g. the Research market-research items for an
32
+ internal tool), record it and skip honestly:
33
+ ```
34
+ /flow debt add "skip 01-research" "<exposure>" "<close-before condition>"
35
+ /flow skip 01-research --reason "internal tool, no public market"
36
+ ```
37
+ `skip` advances ONLY when an open DEBT line **names that exact stage** AND the reason is
38
+ non-security-class; `planning_complete` then tolerates that stage so `/flow card` is not
39
+ blocked forever. Guards (in order): the **contract (05) can never be skipped** — it is the
40
+ seam, adapt it per project type instead; a **security-class reason HALTS** (auth/authz/
41
+ admin/tenancy/payments/credential/permission/role/rbac/login/pii/data/migration/validation —
42
+ operator-only); and the DEBT must name the stage (an unrelated open DEBT will not unlock it).
@@ -0,0 +1,47 @@
1
+ # Stage state machine
2
+
3
+ How `/flow` advances. The runner computes "current stage" as the highest-numbered stage
4
+ file that exists in `flow/`. `/flow next` gate-checks that stage and, on pass, unlocks the
5
+ next one. Planning is complete only when **all six** stage gates are clean; only then does
6
+ `/flow card` unlock.
7
+
8
+ ```
9
+ (no flow/) --/flow next--> flow/00-idea.md [stage 00 unlocked]
10
+ flow/00-idea.md gate clean --/flow next--> flow/01-research.md [stage 01 unlocked]
11
+ flow/01-research.md gate clean --/flow next--> flow/02-scope.md [stage 02 unlocked]
12
+ flow/02-scope.md gate clean --/flow next--> flow/03-prd.md [stage 03 unlocked]
13
+ flow/03-prd.md gate clean --/flow next--> flow/04-adr.md [stage 04 unlocked]
14
+ flow/04-adr.md gate clean --/flow next--> flow/05-contract.md [stage 05 unlocked]
15
+ flow/05-contract.md gate clean --/flow next--> PLANNING COMPLETE [/flow card unlocks]
16
+ all 6 gates clean --/flow card--> cards/C-001.md, C-002.md, ...
17
+ cards built + verified --/flow check-> per-card exit gate (status done + evidence)
18
+ all cards done --/flow retro-> one line in RETRO.md
19
+ ```
20
+
21
+ A gate FAIL never advances; it lists every unchecked box and `[FILL]` with line numbers.
22
+ **Kill is also a terminal state** — stopping at any gate (especially Scope) is a valid,
23
+ honored outcome, not a failure of the flow.
24
+
25
+ ## What each artifact must contain (so the gate is meaningful)
26
+
27
+ | Stage | File | Must contain |
28
+ |---|---|---|
29
+ | 00 Idea | `flow/00-idea.md` | 3-sentence pitch (who/pain/what) + one named real person with the pain |
30
+ | 01 Research | `flow/01-research.md` | 3 opened competitors, 3 quoted complaints w/ links, real prices, ONE named first-10 channel, switch reason, free-vs-hard |
31
+ | 02 Scope | `flow/02-scope.md` | every feature Impact(H/M/L)+Grade(A/B/C), C-justification path, cut list, GO/KILL |
32
+ | 03 PRD | `flow/03-prd.md` | numeric success metric, pain&gain mapping table, user-action->observable-result features |
33
+ | 04 ADR | `flow/04-adr.md` | decisions with why+rejected covering storage/auth/deploy, NOT-doing list |
34
+ | 05 Contract | `flow/05-contract.md` | every feature->endpoint, request+response shapes, auth per endpoint |
35
+ | Card | `cards/C-NNN.md` | one-thing scope, deps, allowed files, verify steps, named done-evidence, pasted evidence when done |
36
+
37
+ ## Shipping stages live inside cards
38
+ Build -> Review -> Deploy -> Verify-live are NOT `/flow next` stages. They happen inside
39
+ each card: the `## Verify` checklist (run for real) and `## Evidence` (world-state proof).
40
+ Card sequence (scaffold/CI -> vertical slice -> backend -> contract-tests -> UI mock ->
41
+ frontend -> e2e) is governed by `law/CLAUDE.md`.
42
+
43
+ ## Runner contract
44
+ - `flow.sh` exit `0` = pass/advanced, `1` = gate fail or usage error.
45
+ - Reads/writes `flow/`, `cards/`, `MODE`, `RETRO.md`, and seeds `DESIGN.md` once, under `FLOW_PROJECT_ROOT` (default `$PWD`).
46
+ - `DEBT.md` is written by the **semantic layer** (Claude), not the runner — the runner only reminds.
47
+ - Templates are read-only from `<skill>/_templates`; never edited during a run.
@@ -0,0 +1,49 @@
1
+ # 7 UI patterns + T-C-R framework
2
+
3
+ For AI-product UIs. Pick a pattern, then layer T-C-R (Transparency / Control / Recovery) —
4
+ the load-bearing frame for trustworthy agentic UI. (Source: ai20k workshop-0422.)
5
+
6
+ ## The 7 patterns
7
+ | # | Pattern | Use for |
8
+ |---|---|---|
9
+ | 1 | **Chat + context panel** | AI TA, RAG chatbot, Socratic tutor (conversation left, evidence right) |
10
+ | 2 | **Upload -> dashboard** | survey analysis, report summarizer, invoice extractor |
11
+ | 3 | **Query -> structured result** | text-to-SQL, digital-twin Q&A (NL -> table/chart) |
12
+ | 4 | **Wizard + inline audit** | syllabus/compliance/onboarding (multi-step form, AI checks each step) |
13
+ | 5 | **Draft -> approve -> send** | emergency comms, email assistant (AI drafts, human approves, system sends) |
14
+ | 6 | **Queue + approval** | moderation, grading at scale, contract review (batch AI labels, human clears) |
15
+ | 7 | **Real-time streaming** | voice Q&A, live transcription (live pipeline) |
16
+
17
+ **Meta-pattern:** Pattern 1 with a swappable panel covers most cases (panel = sources->RAG,
18
+ progress->long agent, reasoning->research, chart->data Q&A, queue->inbox).
19
+
20
+ ## Priority rules to choose a pattern (top wins)
21
+ irreversible action -> **5** · batch -> **6** · streaming -> **7** · multi-step form -> **4**
22
+ · file upload -> **2** · text->chart/table -> **3** · text->text+sources -> **1** ·
23
+ ambiguous -> **1 + pick the panel payload**.
24
+
25
+ ## T-C-R (add to whatever pattern you chose; compounds when added in order)
26
+ - **T = Transparency.** Show what the AI is doing: status line ("Đang tra cứu 3 nguồn..."),
27
+ sources panel, confidence traffic-light (green >0.8, amber 0.5-0.8, red <0.5), visible
28
+ SQL/reasoning/plan, which model.
29
+ - **C = Control.** Let the user stop/edit/override BEFORE an irreversible act: abort button,
30
+ edit-before-execute, dry-run preview, bulk + keyboard shortcuts, pin/clear.
31
+ - **R = Recovery.** Pre-flight validation + post-hoc repair: validate input before the call,
32
+ retry, undo, "flag as bad" (becomes a training signal), regenerate, preview+cancel.
33
+
34
+ > If a UI element doesn't map cleanly to T, C, or R, rewrite it until it does. This frame is
35
+ > load-bearing — it's what makes an agentic UI trustworthy for non-technical users.
36
+
37
+ ## T-C-R per pattern (quick matrix)
38
+ | Pattern | T | C | R |
39
+ |---|---|---|---|
40
+ | 1 Chat+panel | sources panel, streaming status, confidence dot | stop streaming, edit last msg, clear | error-bubble retry, thumbs-down |
41
+ | 2 Upload->dash | parse/extract progress, per-insight source | cancel, preview modal for big files | file pre-flight, "try another", keep-previous undo |
42
+ | 3 Query->result | "view SQL", confidence badge, rows/ms/model | edit query before run, confirm destructive | retry, "rephrase" feeds error back, history |
43
+ | 4 Wizard+audit | per-field ok/warn/fail + reason | back/forward no data loss, save draft, override warning | validate per step, preview+edit before submit |
44
+ | 5 Draft->send | confidence/section, recipient preview | mandatory preview (no generate-and-send), edit any field | "sent - undo" 10s, retry, keep draft on fail |
45
+ | 6 Queue | confidence dot/item, 1-line reason, counts | bulk + shift-click, J/K/A/R keys, filter by confidence | undo stack, "flag for review" not reject, re-surface |
46
+ | 7 Streaming | live status, token-by-token, latency | stop aborts, pause/resume | auto-reconnect (max 3), preserve buffer, manual restart |
47
+
48
+ Combine with `law/DESIGN.md` (tokens, affordance ladder, object-first) — T-C-R is the
49
+ behavior frame, DESIGN.md is the visual law. Both bind every UI card.
@@ -0,0 +1,18 @@
1
+ @echo off
2
+ rem flow gate-engine launcher for Windows shells (PowerShell / cmd / Codex).
3
+ rem Codex and PowerShell resolve a bare `bash` to WSL (C:\WINDOWS\system32\bash.exe),
4
+ rem which cannot read C:/ paths and fails with "No such file or directory".
5
+ rem This finds Git Bash and runs the runner with a forward-slash path it accepts.
6
+ setlocal
7
+ set "SELF=%~dp0flow.sh"
8
+ set "SELF=%SELF:\=/%"
9
+ set "GB=%ProgramFiles%\Git\bin\bash.exe"
10
+ if not exist "%GB%" set "GB=%ProgramFiles(x86)%\Git\bin\bash.exe"
11
+ if not exist "%GB%" set "GB=%LOCALAPPDATA%\Programs\Git\bin\bash.exe"
12
+ if not exist "%GB%" (
13
+ echo flow: Git Bash not found - install Git for Windows ^(https://git-scm.com^) so the gate engine can run.
14
+ exit /b 1
15
+ )
16
+ "%GB%" "%SELF%" %*
17
+ rem propagate the gate engine's exit code (0/1) - it is flow's ground truth
18
+ exit /b %ERRORLEVEL%