@kontourai/flow-agents 3.6.0 → 3.7.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/build/src/builder-flow-run-adapter.d.ts +22 -2
  3. package/build/src/builder-flow-run-adapter.js +93 -28
  4. package/build/src/builder-flow-runtime.d.ts +8 -3
  5. package/build/src/builder-flow-runtime.js +308 -47
  6. package/build/src/cli/assignment-provider.d.ts +4 -7
  7. package/build/src/cli/assignment-provider.js +67 -13
  8. package/build/src/cli/builder-run.js +14 -18
  9. package/build/src/cli/workflow-sidecar.d.ts +28 -4
  10. package/build/src/cli/workflow-sidecar.js +801 -97
  11. package/build/src/cli/workflow.js +290 -42
  12. package/build/src/flow-kit/validate.d.ts +17 -0
  13. package/build/src/flow-kit/validate.js +340 -2
  14. package/build/src/index.js +5 -5
  15. package/build/src/lib/observed-command.d.ts +7 -0
  16. package/build/src/lib/observed-command.js +100 -0
  17. package/build/src/tools/generate-context-map.js +5 -3
  18. package/context/scripts/hooks/lib/kit-catalog.js +1 -1
  19. package/context/scripts/hooks/stop-goal-fit.js +78 -9
  20. package/docs/context-map.md +22 -20
  21. package/docs/developer-architecture.md +1 -1
  22. package/docs/public-workflow-cli.md +76 -7
  23. package/docs/skills-map.md +51 -27
  24. package/docs/spec/builder-flow-runtime.md +41 -40
  25. package/docs/workflow-usage-guide.md +109 -42
  26. package/evals/fixtures/hook-influence/cases.json +2 -2
  27. package/evals/integration/test_builder_entry_enforcement.sh +52 -41
  28. package/evals/integration/test_builder_step_producers.sh +297 -6
  29. package/evals/integration/test_bundle_install.sh +212 -63
  30. package/evals/integration/test_critique_supersession_roundtrip.sh +21 -8
  31. package/evals/integration/test_current_json_per_actor.sh +12 -0
  32. package/evals/integration/test_dual_emit_flow_step.sh +62 -43
  33. package/evals/integration/test_flowdef_session_activation.sh +145 -25
  34. package/evals/integration/test_flowdef_session_history_preservation.sh +23 -21
  35. package/evals/integration/test_gate_lockdown.sh +3 -5
  36. package/evals/integration/test_goal_fit_hook.sh +60 -2
  37. package/evals/integration/test_liveness_verdict.sh +14 -17
  38. package/evals/integration/test_phase_map_and_gate_claim.sh +63 -38
  39. package/evals/integration/test_public_workflow_cli.sh +325 -11
  40. package/evals/integration/test_pull_work_liveness_preflight.sh +22 -66
  41. package/evals/integration/test_sidecar_field_preservation.sh +36 -11
  42. package/evals/integration/test_workflow_sidecar_writer.sh +277 -44
  43. package/evals/integration/test_workflow_steering_hook.sh +15 -38
  44. package/evals/run.sh +2 -0
  45. package/evals/static/test_builder_skill_coherence.sh +247 -0
  46. package/evals/static/test_library_exports.sh +5 -2
  47. package/evals/static/test_workflow_skills.sh +13 -325
  48. package/kits/builder/flows/build.flow.json +22 -0
  49. package/kits/builder/flows/shape.flow.json +9 -9
  50. package/kits/builder/kit.json +70 -16
  51. package/kits/builder/skills/builder-shape/SKILL.md +75 -75
  52. package/kits/builder/skills/continue-work/SKILL.md +45 -106
  53. package/kits/builder/skills/deliver/SKILL.md +96 -442
  54. package/kits/builder/skills/design-probe/SKILL.md +40 -139
  55. package/kits/builder/skills/evidence-gate/SKILL.md +59 -201
  56. package/kits/builder/skills/execute-plan/SKILL.md +54 -125
  57. package/kits/builder/skills/fix-bug/SKILL.md +42 -132
  58. package/kits/builder/skills/gate-review/SKILL.md +60 -211
  59. package/kits/builder/skills/idea-to-backlog/SKILL.md +63 -244
  60. package/kits/builder/skills/learning-review/SKILL.md +63 -170
  61. package/kits/builder/skills/pickup-probe/SKILL.md +54 -111
  62. package/kits/builder/skills/plan-work/SKILL.md +51 -185
  63. package/kits/builder/skills/pull-work/SKILL.md +136 -485
  64. package/kits/builder/skills/release-readiness/SKILL.md +66 -107
  65. package/kits/builder/skills/review-work/SKILL.md +89 -176
  66. package/kits/builder/skills/tdd-workflow/SKILL.md +53 -147
  67. package/kits/builder/skills/verify-work/SKILL.md +101 -113
  68. package/package.json +2 -2
  69. package/scripts/hooks/lib/kit-catalog.js +1 -1
  70. package/scripts/hooks/stop-goal-fit.js +78 -9
  71. package/src/builder-flow-run-adapter.ts +118 -32
  72. package/src/builder-flow-runtime.ts +331 -61
  73. package/src/cli/assignment-provider-lock.test.mjs +83 -0
  74. package/src/cli/assignment-provider.ts +62 -13
  75. package/src/cli/builder-flow-run-adapter.test.mjs +4 -2
  76. package/src/cli/builder-flow-runtime.test.mjs +194 -8
  77. package/src/cli/builder-run.ts +3 -9
  78. package/src/cli/kit-metadata-security.test.mjs +232 -6
  79. package/src/cli/public-api.test.mjs +15 -0
  80. package/src/cli/workflow-sidecar-execution-proof.test.mjs +90 -0
  81. package/src/cli/workflow-sidecar.ts +724 -97
  82. package/src/cli/workflow.ts +277 -40
  83. package/src/flow-kit/validate.ts +320 -2
  84. package/src/index.ts +6 -5
  85. package/src/lib/observed-command.ts +96 -0
  86. package/src/tools/generate-context-map.ts +5 -3
@@ -1,465 +1,119 @@
1
1
  ---
2
2
  name: "deliver"
3
- description: "Delivery workflow selected work to delivered code. Ensures pull-work + pickup-probe preflight, then chains plan-work execute-plan review-work verify-work → loop on failure without requiring user interaction between cleanly determined stages."
3
+ description: "Builder Kit build entrypoint. Starts or continues a selected Work Item through builder.build by composing the build primitives without owning their step evidence."
4
4
  ---
5
5
 
6
6
  # Deliver
7
7
 
8
- Takes a goal, chains the three primitives, loops until the user-facing goal is met. The orchestrator coordinates — it never touches source files.
8
+ ## Role and Boundary
9
9
 
10
- ## Agents
10
+ **Role:** Builder Kit entrypoint for standard `builder.build` delivery.
11
11
 
12
- Inherited from primitives:
12
+ Select this entrypoint when the user asks to build or deliver a selected Work
13
+ Item without requesting test-first development. For test-first delivery, select
14
+ the `tdd-workflow` `builder.build` profile instead.
13
15
 
14
- | Agent | Used by |
15
- |---|---|
16
- | tool-planner | plan-work |
17
- | tool-worker (x4) | execute-plan |
18
- | tool-code-reviewer | review-work |
19
- | tool-security-reviewer | review-work (conditional — security-sensitive changes) |
20
- | tool-verifier | verify-work |
21
- | tool-playwright | verify-work |
16
+ `deliver` coordinates the standard build primitives:
22
17
 
23
- ## Model Routing
24
-
25
- Delegates are spawned with an explicit model override resolved from
26
- `.datum/config.json` via `npx @kontourai/datum resolve <role> --json`
27
- (see `context/contracts/execution-contract.md` § Delegation: Model Routing —
28
- that contract is the consumption instruction, `.datum/config.json` is the
29
- source of truth for the mapping):
30
-
31
- | Delegate | Role |
32
- |---|---|
33
- | tool-worker | `delegate-mechanical` for fully-specified mechanical tasks, `delegate-implementation` for precisely-planned implementation, `delegate-design` when the task needs design latitude |
34
- | tool-planner | `delegate-design` |
35
- | tool-code-reviewer / tool-security-reviewer | `delegate-implementation` by default, raised to the worker's tier when higher — never below the tier of the checked work (Goodhart guard) |
36
- | tool-verifier / tool-playwright | `delegate-implementation` by default, raised to the worker's tier when higher — never below the tier of the checked work (Goodhart guard) |
37
-
38
- On a review/verify gate failure, re-dispatch the fix one tier higher on the
39
- ladder and record the escalation in the session artifact via
40
- `record-agent-event --kind escalation --role <higher> --escalated-from <lower>`
41
- (see `context/contracts/execution-contract.md` § Escalation on gate failure and
42
- § Routing decisions in the run artifact). If datum or the config is absent, fall
43
- back to the runtime's inherited model and note the fallback in the session
44
- artifact.
45
-
46
- ## Orchestrator Rule
47
-
48
- You never use `read`, `glob`, `grep`, or `code` on source files. You only read/write the session file and artifact files in `.kontourai/flow-agents/<slug>/`.
49
-
50
- ## Shared Contracts
51
-
52
- Follow:
53
- - `context/contracts/standing-directives.md`
54
- - `context/contracts/artifact-contract.md`
55
- - `context/contracts/planning-contract.md`
56
- - `context/contracts/execution-contract.md`
57
- - `context/contracts/review-contract.md`
58
- - `context/contracts/verification-contract.md`
59
- - `context/contracts/delivery-contract.md`
60
-
61
- This skill owns orchestration across the full loop. The contracts own artifact shape, Definition Of Done, execution handoff, verification verdicts, Goal Fit, and Final Acceptance.
62
-
63
- When you report progress or final evidence, use exact delegate ids such as `tool-planner`, `tool-worker`, `tool-verifier`, and `tool-playwright`. Do not collapse them to generic labels when the gate is part of acceptance evidence.
64
-
65
- ## Sidecar Writer Adoption
66
-
67
- When the repository provides `npm run workflow:sidecar --`, use it for routine workflow state instead of hand-writing JSON:
68
-
69
- - `ensure-session` before planning starts
70
- - `current --format path` when resuming or handing work to delegates
71
- - `record-agent-event` for delegated progress, handoffs, blockers, and evidence pointers
72
- - `advance-state` at each phase transition
73
- - `record-evidence` after verification
74
- - `record-critique` or `import-critique` after review
75
- - `record-release` for release-readiness decisions
76
- - `record-learning` for learning-review outcomes
77
- - `dogfood-pass` for Flow Agents repo changes that should record evidence, critique, optional learning, state, and handoff in one validated pass
78
-
79
- After writer updates, run `npm run workflow:validate-artifacts -- --require-sidecars .kontourai/flow-agents/<slug>` when local validation is available. If the writer or validation is unavailable or blocked by sandbox policy, record the exact gap in the session artifact as `NOT_VERIFIED` instead of pretending structured state exists.
80
-
81
- `ensure-session` maintains `.kontourai/flow-agents/current.json`. The orchestrator is responsible for keeping root `state.json` and `handoff.json` current, but performs every such update **exclusively** through the sidecar writer (`npm run workflow:sidecar -- advance-state` for state transitions, `init-plan` for the initial plan write) — never through a direct Write/Edit tool call against the sidecar path. `config-protection.js` blocks direct tool-mediated writes to `state.json` by design; that block is expected and correct, not a bug to route around. Delegated agents must be given the workflow artifact root and should append events under `agents/<agent-id>/events.jsonl` through `record-agent-event` instead of guessing the slug or rewriting root state.
82
-
83
- ## Input
84
-
85
- - **Goal**: what to build (from conversation context or explicit instruction)
86
- - **Directory**: working directory
87
- - **Selected work evidence**: existing `pull-work` and `pickup-probe` artifacts when the user is continuing provider-backed or productized backlog work
88
-
89
- ## TDD Mode
90
-
91
- If the user requests test-driven development, activate the `tdd-workflow` skill instead. It wraps the same plan → execute → verify chain with test-first constraints and git checkpoints. deliver is for standard (implementation-first) workflows.
92
-
93
- ## Required Preflight
94
-
95
- Before planning implementation, determine whether the request is direct ad hoc delivery or pickup of provider-backed/productized backlog work.
96
-
97
- - If the user asks to pick up work, continue backlog work, build the next item, or deliver a selected issue, run or consume `pull-work` first. `pull-work` must enforce board selection, WIP/shepherding, dependency, grouping, and worktree logic.
98
- - After `pull-work`, run or consume `pickup-probe` before `plan-work`. The pickup Probe must record selected item ids, scope, acceptance quality, provider state, WIP/conflict scan, dependency freshness, expected modified files, sandbox/worktree mode, decisions, unresolved questions, accepted gaps, and planning readiness.
99
- - If current artifacts already prove `pull-work` and `pickup-probe` are fresh for the selected item or justified group, consume those artifacts and continue to `plan-work`.
100
- - If the preflight is missing, stale, contradictory, or for a different selected item, stop before planning and route through `pull-work -> pickup-probe`; for pickup/planning gaps, route `decision_gap` back to `design-probe`.
101
- - If the user gives a raw product idea instead of ready backlog work, suggest Builder Kit shape (`design-probe` + `idea-to-backlog`) rather than forcing delivery.
102
-
103
- Direct ad hoc implementation requests that are not provider-backed backlog pickup may still start at `plan-work`, but `deliver` must record why pull/pickup preflight was not applicable.
104
-
105
- ## Session File
106
-
107
- Path: `.kontourai/flow-agents/<slug>/<slug>--deliver.md`
108
-
109
- ```markdown
110
- # <Goal one-liner>
111
-
112
- branch: <branch>
113
- worktree: <worktree>
114
- created: <date>
115
- status: planning | executing | reviewing | verifying | delivered
116
- type: deliver
117
- iteration: 0
118
-
119
- ## Workflow Rules (re-read at each phase transition)
120
-
121
- - Reviewers and verifiers are REPORT ONLY — they never fix code
122
- - Any code change requires re-review + re-verify before delivery
123
- - Loop exits only when review + verify are both clean in same iteration
124
- - Loop exits only after the Goal Fit Gate is fully checked or explicitly accepted
125
- - CRITICAL/HIGH → re-plan → execute → review → verify
126
- - MEDIUM/FAIL → execute fix pass → review → verify
127
- - Temporary planning and execution artifacts live in `.kontourai/flow-agents/<slug>/`; durable feature documentation is promoted after CI/merge
128
- - Local runtime work stays under `.kontourai/flow-agents/` and remains untracked; durable outcomes must be promoted before merge to `main`
129
-
130
- ## Plan
131
-
132
- (populated by plan-work)
133
-
134
- ## Definition Of Done
135
-
136
- (copied from plan-work; this is the user-facing stop condition)
137
-
138
- ## Execution Progress
139
-
140
- (populated by execute-plan)
141
-
142
- ## Verification Report
143
-
144
- (populated by verify-work)
145
-
146
- ## Goal Fit Gate
147
-
148
- Use the Goal Fit Gate from `context/contracts/delivery-contract.md`.
149
-
150
- ## Final Acceptance
151
-
152
- Use the Final Acceptance checklist from `context/contracts/delivery-contract.md`.
153
-
154
- ## History
155
-
156
- - iteration 1: partial — auth routes done, form validation missing
157
- - iteration 2: pass — all acceptance criteria met
158
- ```
159
-
160
- `<branch>` is the branch recorded in `state.json`'s `branch` field (`ensure-session` derives `agent/<actor>/<slug>`; an explicit `--branch` flag overrides on a new session). `ensure-session` only records the name — creating and checking out the actual git branch/worktree remains this skill's responsibility.
161
-
162
- The `status:` values in this Markdown session file are human-readable delivery progress labels. They are not the machine-readable `state.phase` enum; structured workflow sidecars must use the canonical lifecycle values from `context/contracts/artifact-contract.md`. In particular, review-work records critique through the critique artifact/sink while the sidecar lifecycle remains in a canonical phase such as `execution`, not a `review` phase.
163
-
164
- ## Workflow
165
-
166
- ### 1. Create session file
167
-
168
- Create the session file with `status: planning`, `iteration: 0`. Use the sidecar writer when available:
169
-
170
- ```bash
171
- npm run workflow:sidecar -- ensure-session \
172
- --source-request "<original request>" \
173
- --summary "<current delivery goal>" \
174
- --criterion "<acceptance criterion>" \
175
- --flow-id builder.build
176
- ```
177
-
178
- `--flow-id builder.build` activates the FlowDefinition-driven path for this session. Producers fire, gates enforce on builder.* claims, and `advance-state` sets `active_step_id` automatically via the `builder.build` phase_map. Keep this flag on all `deliver`-initiated sessions; do not remove it for direct ad-hoc requests that are not builder-flow pickup.
179
-
180
- ### 2. Plan (plan-work)
181
-
182
- Invoke plan-work with the goal, directory, session file path, and any pull-work / pickup-probe artifact refs. The plan must include `## Definition Of Done`. Present the plan to the user when a user decision is actually needed; otherwise record the plan artifact and continue automatically to execution.
183
-
184
- This is a delegation gate. `plan-work` must delegate to `tool-planner` when that delegate is available, even if the environment is read-only or the repo cannot yet be modified. If the gate is blocked, preserve the attempted delegation/blocker in the session artifact and treat the delivery as `NOT_VERIFIED` or incomplete rather than substituting a local plan.
185
-
186
- ### 3. Execute (execute-plan)
187
-
188
- Re-read the session file `## Workflow Rules` section before proceeding. Then invoke execute-plan with the plan artifact path and session file path.
189
-
190
- ### 4. Review (REPORT ONLY — review-work)
191
-
192
- Invoke `review-work` with the session file path. Reviewers produce findings through the critique artifact/sink, currently `critique.json` locally. **They NEVER fix code.** No writes, no patches, no "found and fixed."
193
-
194
- This is a delegation gate. `review-work` must delegate to `tool-code-reviewer` when that delegate is available. If security-sensitive files or behaviors are in scope, it must also delegate to `tool-security-reviewer`. Architecture and standards concerns are part of the code review scope unless the project configures a more specific reviewer.
195
-
196
- ### 5. Verify (REPORT ONLY — verify-work)
197
-
198
- Invoke verify-work with the session file path. Verifiers run checks and report status, including acceptance criteria and Goal Fit. **They NEVER fix code.** No format fixes, no lint auto-fixes, no patches.
199
-
200
- This is a delegation gate. `verify-work` must delegate to `tool-verifier` when that delegate is available. If UI or browser-facing behavior is in scope, delegate that evidence collection to `tool-playwright` as well. If the gate is blocked, report the exact `NOT_VERIFIED` evidence gap; do not replace verification with an orchestrator-only summary.
201
-
202
- ### 6. Route on findings
203
-
204
- Combine the critique artifact/sink verdict + verification verdict:
205
-
206
- - **Clean** (no issues, all PASS) → deliver
207
- - **Goal Fit Gate incomplete** → fix pass or final acceptance decision
208
- - **CRITICAL or HIGH review findings** → re-plan (step 7a)
209
- - **MEDIUM review findings needing code changes** → fix pass (step 7b)
210
- - **Any verification FAIL** → fix pass (step 7b)
211
- - **Any NOT_VERIFIED** → surface to user, they decide
212
-
213
- When the route is deterministic, continue without asking the user between stages. Use the local stop/steering hooks when available to resume automatically after phase transitions. Ask the user only for explicit approval, missing authority, unsafe escalation, accepted gaps, unresolved `NOT_VERIFIED`, provider decisions, or scope changes.
214
-
215
- ### 7. Loop (mandatory re-verify)
216
-
217
- **Any code change requires a subsequent clean review + verify pass. No exceptions.**
218
-
219
- #### 7a. Re-plan (CRITICAL/HIGH issues)
220
-
221
- 1. Increment `iteration` in session file
222
- 2. Re-invoke plan-work with: original goal + failure summary → updated plan
223
- 3. Back to step 3 (Execute) → then step 4 (Review) → step 5 (Verify)
224
-
225
- #### 7b. Fix pass (MEDIUM issues / verification failures)
226
-
227
- 1. Increment `iteration` in session file
228
- 2. Back to step 3 (Execute) with the specific findings to fix
229
- 3. Then step 4 (Review) → step 5 (Verify)
230
-
231
- **The loop exits ONLY when review + verify both produce zero findings, all PASS in the same iteration, and Goal Fit Gate is complete.** Not when fixes are applied — when fixes are *verified clean and useful to the user*.
232
-
233
- ### 8. Goal Fit Gate
18
+ `pull-work` -> `design-probe` -> `plan-work` -> `execute-plan` ->
19
+ `review-work` -> `verify-work`, followed by the applicable publish and learning
20
+ activities.
234
21
 
235
- Before final response, update `## Goal Fit Gate` in the session file. If any box is unchecked, either keep working or surface the exact decision needed. Do not hide open gaps in a summary.
22
+ It does not reproduce those primitives' detailed procedure, write source code,
23
+ or own **any step-gate evidence**. Each primitive produces and records the
24
+ evidence for its own step. `deliver` consumes their results only to select the
25
+ next primitive or surface a blocker.
236
26
 
237
- Record the final local state with `advance-state`. Use `status: verified` only when verification and critique are clean; use `status: needs_decision`, `failed`, or `not_verified` for unresolved gaps.
238
-
239
- ### 9. Publish Verified Change
240
-
241
- After review, verification, evidence, and Goal Fit are clean for the same diff:
242
-
243
- 1. Confirm the working tree contains only verified scope.
244
- 2. Publish the session trust bundle so the CI trust-reconcile job can verify what the agent claimed. `record-release` (via the sidecar writer) does this automatically (best-effort). To publish or re-publish explicitly:
245
-
246
- ```bash
247
- npm run workflow:sidecar -- publish-delivery .kontourai/flow-agents/<slug>
248
- ```
249
-
250
- **#356 — local reconcile-shape preflight.** `publish-delivery`/`record-release` now run a
251
- local, pre-push **reconcile-shape preflight** on the session's `trust.bundle` before
252
- copying anything into `delivery/`. It reuses the exact same claim-shape classification
253
- `scripts/ci/trust-reconcile.js` enforces in CI (`scripts/lib/reconcile-shape.js`), so it
254
- can never silently drift from what the required Trust Reconcile check actually does. If
255
- the bundle is ADR-0020-invalid (e.g. a command-backed claim whose command isn't in the
256
- reconcile manifest, an unwaived `assumed` claim, or an un-superseded disputed critique),
257
- publish is **refused, fail-closed** — non-zero exit, a loud `REFUSING to publish` message
258
- naming each invalid claim and its fix, and nothing is written to `delivery/`. This is
259
- distinct from the existing fail-**soft** behavior when no `trust.bundle` exists yet at all
260
- (still a silent no-op). When refused: fix the named claim (re-record evidence, add a
261
- missing waiver, or supersede the disputed critique), then retry — do not attempt to push
262
- past the refusal. You can also run the same check manually, any time before publish, to
263
- catch a shape issue locally instead of discovering it minutes later in CI:
264
-
265
- ```bash
266
- npm run workflow:sidecar -- reconcile-preflight .kontourai/flow-agents/<slug>
267
- ```
268
-
269
- **#381 — manifest-lane constraint: which commands may be `kind:"command"` checks.** A check/claim
270
- is only CI-reconcilable as `kind:"command"` (Surface's `test_output` evidence type) if its
271
- command is a registered entry in the **trust-reconcile manifest** — the same
272
- `{"id":..,"command":..,"lanes":[..]}` list `evals/ci/run-baseline.sh --manifest-json` emits
273
- from its `CHECKS` array (source of truth: `evals/ci/run-baseline.sh` lines 12-67 for the
274
- array, 166-182 for `emit_manifest_json`). `scripts/ci/trust-reconcile.js` resolves this same
275
- manifest (`resolveManifest`/`manifestByCmd`, lines 292-370, 1101-1104) and reconciles a
276
- `kind:"command"` claim's `execution.label` ONLY against it — a command not in the manifest
277
- can never reconcile, and CI's reconciler names it exactly this way: `trust divergence: agent
278
- claimed '<cmd>' passed; command is not in the reconcile manifest — a test_output claim must
279
- name a manifest/required-lane command (CI cannot self-declare an arbitrary command)`. An
280
- honest capture-backed check recorded against a real, passing, non-manifest command still
281
- becomes this `not-run` divergence at CI reconcile time — it is not a shape bug to route
282
- around, it is the manifest boundary working as designed. Anything that is not a registered
283
- manifest command records as `kind:"external"` (a session-local attestation — e.g. a manual
284
- code-review judgment) or `kind:"policy"` (a policy/compliance attestation — e.g. `promote`'s
285
- claim, which carries no `command`/`execution.label` and therefore can never require a
286
- manifest entry). This matters at every writer call that can produce a `kind:"command"`
287
- check — `record-evidence`, `record-gate-claim --command`, and `record-check` — and again at
288
- the `publish-delivery`/`reconcile-preflight` step above, which is where a non-manifest
289
- command surfaces as a refusal before CI ever sees it. Gate claims recorded earlier in a
290
- session are not special-cased here: the compose-safe writer path keeps every prior gate
291
- claim's declared claim type intact across later `record-evidence`/`record-critique`/
292
- `record-learning` calls, so a gate claim never needs to be the last write of a session to
293
- survive.
294
-
295
- - `kind:"command"` (manifest-backed) example — a real, currently-registered manifest entry
296
- ("Source tree validation" → `npm run validate:source --`):
297
-
298
- ```bash
299
- npm run workflow:sidecar -- record-check .kontourai/flow-agents/<slug> -- npm run validate:source --
300
- ```
301
-
302
- - `kind:"external"` (non-manifest attestation) example — no `--command`, so nothing is
303
- ever executed; the prose lives in `--summary`:
304
-
305
- ```bash
306
- npm run workflow:sidecar -- record-gate-claim .kontourai/flow-agents/<slug> \
307
- --status pass \
308
- --summary "Manual code review confirmed no regressions in the affected module."
309
- ```
310
-
311
- **#379 — per-session delivery paths.** `publishDelivery()` writes to a PER-SESSION path
312
- `delivery/<slug>/trust.bundle` (+ `trust.checkpoint.json` companions), where `<slug>` is
313
- your session artifact dir's basename — NOT the old shared flat `delivery/trust.bundle`.
314
- This is deliberate: a shared path guaranteed a git merge conflict between ANY two
315
- concurrent deliveries, and a conflicting PR gets no CI (see the loud callout below). The
316
- CI reconciler discovers both the flat (back-compat) and per-session layouts and selects
317
- the NEWEST candidate whose checkpoint attests THIS change by commit ancestry — so an older
318
- inherited bundle that also happens to be an ancestor of your change is ignored in favour of
319
- your fresh one, and stale siblings from other sessions are ignored. `publishDelivery()`
320
- also prunes inherited per-session sibling seal dirs (unique-named, never a cross-PR
321
- conflict) so `delivery/` stays small; it deliberately does NOT delete the shared flat
322
- `delivery/trust.bundle` legacy path (a concurrent PR may still seal there, and deleting it
323
- would cause the DIRTY→no-CI conflict in the callout below).
324
-
325
- Then force-stage the per-session trust dir for the delivery commit. It is gitignored by
326
- default (runtime artifacts written on every local delivery) — `-f` commits it
327
- deliberately into THIS delivery PR so CI's trust-reconcile job can reconcile the
328
- session's claims against fresh CI results:
329
-
330
- ```bash
331
- git add -f delivery/<slug>/
332
- ```
333
-
334
- (If `publishDelivery()` pruned a superseded per-session SIBLING dir, stage that deletion
335
- too — `git add -A delivery/` after the force-add. Do NOT hand-delete the flat
336
- `delivery/trust.bundle` in a delivery PR while other PRs may still seal to it.)
337
-
338
- **#293 — verify-hold gate. HARD STOP.** Before committing/pushing/opening a PR/merging,
339
- run the verify-hold check (it also runs automatically inside `publish-delivery` /
340
- `record-release` / `advance-state --status delivered`, but run it explicitly here BEFORE
341
- committing/pushing, since by the time `record-release` runs the branch may already be
342
- pushed). **The command differs by this repo's configured assignment provider kind — a bare
343
- `verify-hold <slug>` with no provider flag always defaults to `--assignment-provider
344
- local-file` (`runVerifyHold`'s documented default), so on a `github`-provider repo it reads
345
- no local claim record and silently resolves `free`/PASS regardless of the real GitHub hold
346
- state. The local-file-only invocation below is NOT sufficient for a `github`-provider repo —
347
- the github branch is MANDATORY for that provider kind:**
27
+ ## Model Routing
348
28
 
349
- - **local-file provider** (this repo's configured assignment provider, from
350
- `effective-assignment-provider-settings`, is `local-file`):
29
+ Use `delegate-mechanical` for selection bookkeeping, `delegate-design` for
30
+ probing and planning, and `delegate-implementation` for execution, review, and
31
+ verification. Resolve each role from `.datum/config.json` under
32
+ `context/contracts/execution-contract.md`; this entrypoint does not pin models
33
+ or reasoning effort itself.
351
34
 
352
- ```bash
353
- npm run workflow:sidecar -- verify-hold .kontourai/flow-agents/<slug>
354
- ```
35
+ ## Inputs and Provider Adapters
355
36
 
356
- - **github provider**: render-then-execute, mirroring `pull-work`'s SKILL.md claim-side
357
- pattern for the same ADR 0021 §1 join — first read the effective state (no live `gh` call
358
- happens inside `workflow-sidecar.ts`; the skill renders it here), then pass the rendered
359
- `.effective` JSON into `verify-hold` via `--effective-state-json`:
37
+ Use the following provider-neutral inputs:
360
38
 
361
- ```bash
362
- gh issue view <issue-number> --json assignees,labels,comments > /tmp/issue.json
363
- npm run assignment-provider -- status \
364
- --provider github \
365
- --subject-id <slug> \
366
- --issue-json /tmp/issue.json \
367
- --liveness-stream <path-to-events.jsonl> \
368
- --self-actor <actor> \
369
- > /tmp/assignment-status.json
370
- npm run workflow:sidecar -- verify-hold .kontourai/flow-agents/<slug> \
371
- --assignment-provider github \
372
- --effective-state-json /tmp/assignment-status.json
373
- ```
39
+ - **Work Item adapter:** selected work, scope, acceptance context, and identity.
40
+ - **Board adapter:** availability, priority, WIP, dependencies, and selection
41
+ state when work comes from a queue.
42
+ - **Repository adapter:** checkout, branch/worktree policy, and local checks.
43
+ - **Change adapter:** proposed change and, when applicable, review, CI, merge,
44
+ and release state.
374
45
 
375
- (`/tmp/assignment-status.json`'s top-level shape is `{ role, provider, assignment,
376
- effective }`; `verify-hold --effective-state-json` reads the `.effective` field, matching
377
- `assignment-provider status`'s own output shape directly no reshaping needed.)
46
+ A provider may implement any adapter. A Work Item reference is a stable,
47
+ human-readable provider reference that the configured Work Item adapter can
48
+ resolve; GitHub issues are one example, not the contract. For a direct local
49
+ request, use an already-bound local session. Do not invent a provider record or
50
+ claim a fresh binding when the configured adapter cannot resolve the selected
51
+ reference.
378
52
 
379
- This is the ONE point in the whole workflow that BLOCKS instead of warns (ADR 0021 §3). It
380
- asks exactly one question: is this actor still the fresh, non-superseded holder of this
381
- subject (or is the subject free/self-held)? **If the check reports not-fresh-holder (exit
382
- non-zero, `ok:false` in the JSON result): DO NOT commit, push, open a PR, or merge.** This
383
- is a different failure mode from the `publish-delivery`/reconcile-shape preflight paragraph
384
- above — that one is about the trust *bundle's shape* being invalid; this one is about
385
- *actor hold* — another actor holds a fresh claim on this subject, your own claim has gone
386
- stale, or the subject is assigned to a human. Do not conflate the two "REFUSING to publish"
387
- messages. When refused, follow the reconcile guidance (the CLI's own `guidance` field, or
388
- verbatim): re-run `pull-work`/`pickup-probe` to discover the current holder and hand off
389
- cleanly (`learning-review`/handoff), or, if a human confirms this session should resume
390
- ownership, run `ensure-session --supersede-stale` before retrying.
53
+ ## Flow Selection and Run Behavior
391
54
 
392
- 3. Commit the verified diff, including the force-added `delivery/<slug>/` trust artifacts.
393
- 4. Push the branch.
55
+ Before starting a run, require a completed `pull-work` artifact showing readiness,
56
+ WIP and conflict assessment, assignment/liveness preflight, post-claim ownership
57
+ confirmation, and the selected Work Item binding. A Work Item reference alone is
58
+ not sufficient preflight.
394
59
 
395
- > **⚠ LOUD FAILURE MODE a DIRTY PR gets NO CI, silently (#335/#379).** If `main` moves
396
- > under your open PR and produces a merge conflict, GitHub marks the PR `DIRTY` and
397
- > **schedules NO `pull_request` workflows for it** — zero checks, no error, nothing. The
398
- > required **Trust Reconcile** gate then silently never runs, and the PR sits unbuildable
399
- > looking like "CI vanished" rather than "conflict." Per-session delivery paths (#379)
400
- > remove the STRUCTURAL cause for delivery-artifact conflicts (concurrent seals no longer
401
- > share a file), but ANY other same-file conflict with `main` can still trigger it.
402
- > **Diagnose it explicitly — do not assume a missing required check means "not run yet":**
403
- >
404
- > ```bash
405
- > gh pr view <pr> --json mergeStateStatus,mergeable,statusCheckRollup
406
- > ```
407
- >
408
- > `mergeStateStatus: DIRTY` (or `CONFLICTING`) with an ABSENT Trust Reconcile check is the
409
- > signature. Fix by rebasing/merging `main` to clear the conflict and re-pushing — that
410
- > re-triggers the `pull_request` workflows. A green-looking PR with the required gate simply
411
- > MISSING is not "pending"; it is this failure mode until proven otherwise.
412
- 5. Open or update the provider change record with issue links, closing refs, evidence links, and verification summary, or record an explicit no-provider-change reason.
413
- 6. Wait for provider checks/CI or record missing checks as `NOT_VERIFIED`.
414
- 7. Record the gate claim for the Builder Kit `pr-open` step immediately after the PR is opened or updated:
60
+ After those conditions hold, start the selected Work Item with the public
61
+ workflow interface:
415
62
 
416
- ```bash
417
- npm run workflow:sidecar -- record-gate-claim .kontourai/flow-agents/<slug> \
418
- --expectation pull-request-opened \
419
- --status pass \
420
- --summary "PR opened: <pr-url>. Linked to <work-item-ref>, implementation summary and verification evidence attached." \
421
- --evidence-ref-json '{"kind":"provider","url":"<pr-url>"}'
63
+ ```sh
64
+ flow-agents workflow start --flow builder.build --work-item <provider-ref> \
65
+ --assignment-provider <configured-kind> \
66
+ [--effective-state-json <provider-status.json>]
422
67
  ```
423
68
 
424
- Use `--status fail` when the PR cannot be opened or when no provider change record is created and the reason is not an accepted no-provider-change path. Use `--status not_verified` when provider access is unavailable and the PR creation cannot be confirmed.
425
-
426
- Do not invoke `release-readiness` before this gate unless the user explicitly accepts a no-provider-change/no-push path and the reason is recorded in the session artifact. For GitHub, the first `ChangeProvider` adapter example is a PR with PR checks.
427
-
428
- ### 10. Final Acceptance And Docs Promotion
429
-
430
- After CI passes and the work is merged or otherwise accepted:
431
-
432
- 1. Update `## Final Acceptance` in the session file.
433
- 2. Archive the working artifacts under `.kontourai/flow-agents/<slug>/archive/` or keep a stable link to them.
434
- 3. Record provider records, verification evidence, durable docs targets, accepted gaps, and follow-up routing in durable docs or provider records.
435
- 4. Promote the relevant plan, decision, evidence, and usage notes into long-lived docs such as `docs/`, `README.md`, or a project decision record.
436
-
437
- **Assisted promotion path (Knowledge Kit `knowledge.promote` sub-flow).** Rather than
438
- deciding WHAT to promote by ad-hoc judgement, run the Knowledge Kit promote sub-flow
439
- (`kits/knowledge/flows/promote.flow.json`, id `knowledge.promote`) over the session
440
- directory. It ingests the session's plan/evidence/critique/learnings/transcripts,
441
- distills schema-valid DRAFT decision-registry deltas (per
442
- `context/contracts/decision-registry-contract.md`), CONTEXT.md vocabulary additions,
443
- and learning entries, links each to the PR + merge SHA + session archive + touched
444
- topics, and health-checks the registry for contradictions (proposing merge-repair).
445
- It is PROPOSALS-ONLY: every output lands under `<session>/proposals/` it never writes
446
- docs directly. You apply the drafts you accept, then record what was promoted where with
447
- the `promote` CLI (below), which stays the recording mechanism. The sub-flow is the
448
- assisted path; the `promote` claim is the gate. `knowledge.promote` is a true composable
449
- FlowDefinition (a parent step can `uses_flow: "knowledge.promote"`); it is invoked here
450
- from the promote step rather than nested as a builder gate because the `promote` CLI —
451
- not a flow gate is #312's recording mechanism and the sub-flow's outputs are proposals
452
- a human/agent applies.
453
- 5. Link the long-lived doc back to the provider record, archived plan artifact, or accepted evidence when useful so future readers can see why and how the feature was built.
454
- 6. Confirm `.kontourai/flow-agents/` runtime artifacts remain untracked before merge to `main`.
455
- 7. **Clean up the workspace once the merge is confirmed.** First verify the merge actually happened from the provider's own record (a merge commit / `mergedAt`) — not a green check or a watcher's exit code. Then honor the `worktree_lifecycle` recorded by `pull-work` (`retain_until: pr_merged`): remove the isolated worktree (`git worktree remove <path>`) and delete the now-merged branch locally and on the remote. Never delete a branch or worktree before the merge is confirmed — a closed-but-unmerged PR or a prematurely deleted branch loses work. The task is not done while it leaves a stale worktree or merged branch behind.
456
- 8. Hand off to `learning-review` for terminal closeout. Clean runs record a lightweight no-correction-needed learning record (`correction.needed: false`, closed routing such as `target: "none"`); mismatches, friction, missing docs, failed gates, incidents, or product follow-up record `correction.needed: true` or `FOLLOWUP_REQUIRED` with routed prevention/follow-up. Do not skip learning just because the delivery looked clean.
457
-
458
- ### 11. Deliver
459
-
460
- 1. Include the verification report verbatim in your delivery message
461
- 2. `git diff --stat`
462
- 3. Summarize: what was built, iterations taken, issues resolved, Goal Fit status, and final acceptance/docs status
463
- 4. Set `status: delivered`
464
-
465
- {context?}
69
+ Use `flow-agents workflow status --session-dir <session-dir> --json` to inspect
70
+ an existing canonical run. For an interrupted active run, follow the returned
71
+ `next_action` and use its exact idempotent command. Use `flow-agents workflow
72
+ resume --session-dir <session-dir> --reason "Continue the bound Work Item"` only
73
+ for an existing paused run. Use no private workflow interface, internal writer,
74
+ or caller-selected run/step recovery command.
75
+
76
+ For provider-backed work, begin with `pull-work` and `design-probe`. For a
77
+ direct local Work Item, resume its already-bound session; if none exists, report
78
+ the missing adapter binding rather than bypassing Flow. If the request is only
79
+ a raw idea, offer `builder-shape`; do not start delivery until a Work Item is
80
+ selected.
81
+
82
+ ## Orchestration Rules
83
+
84
+ - Delegate planning, implementation, review, and verification to their named
85
+ primitives. Keep model routing and worker parallelism in those primitives;
86
+ this entrypoint sets neither a worker count nor a coverage threshold.
87
+ - A failed review or verification result returns to the appropriate planning or
88
+ execution primitive. A `NOT_VERIFIED` result remains visible as a gap.
89
+ - At each transition, compare the Work Item goal, acceptance criteria, current
90
+ artifacts, and unresolved gaps. Route back to the earliest primitive that can
91
+ correct a failed condition; do not wait until final verification to expose a
92
+ known mismatch.
93
+ - Use the Repository and Change adapters to decide whether publishing,
94
+ release-readiness, or learning applies. Do not treat a remote change or merge
95
+ as implicit authorization.
96
+ - Preserve the exact commands and evidence emitted by primitives rather than
97
+ replacing them with orchestration prose.
98
+
99
+ ## Output Responsibility
100
+
101
+ `deliver` produces no separate artifact and no gate evidence. The active
102
+ `builder.build` run and the artifacts produced by its primitives are the output
103
+ of delivery. Report the Work Item, current run status, completed primitive
104
+ outputs, remaining gaps, and any Change-adapter state to the user.
105
+
106
+ Before closeout, perform a Final Acceptance reconciliation across the selected
107
+ Work Item, actual changed scope, criterion verdicts, critique, and Flow status.
108
+ Do not describe delivery as complete while required behavior, evidence, or
109
+ follow-up remains unresolved. Route eligible outcomes into publish/readiness and
110
+ learning through their owning Builder skills.
111
+
112
+ ## Standalone and No-Active-Run Behavior
113
+
114
+ If no active run exists, require a selected Work Item and start
115
+ `builder.build` only after the completed preflight above; do not create a partial
116
+ or preflight-bypassing run. If an active run exists,
117
+ inspect its public status and continue only from its canonical next action. If
118
+ selection, adapter access, or authorization is missing, stop and report the
119
+ specific blocker.