@really-knows-ai/foundry 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/concepts.md CHANGED
@@ -1,59 +1,122 @@
1
1
  # Concepts
2
2
 
3
- Core concepts and how they relate.
3
+ This is the glossary. Every term here has a single definition and links out to the spec document that elaborates it. Concepts are arranged roughly top-down: flows contain cycles, cycles contain stages, stages operate on artefacts, artefacts are governed by laws and evaluated by appraisers.
4
4
 
5
- ## Foundry Flow
5
+ ---
6
6
 
7
- A foundry flow is the top-level unit of work. It is defined in `foundry/flows/` and lists the foundry cycles to execute in order. Starting a foundry flow creates a work branch and a WORK.md file. A foundry flow is complete when all its foundry cycles are done.
7
+ ## Flow
8
8
 
9
- ## Foundry Cycle
9
+ The top-level unit of work. Defined in `foundry/flows/*.md`. A flow declares:
10
10
 
11
- A foundry cycle is an iterative loop that produces a single artefact type. It is defined in `foundry/cycles/` and specifies:
12
- - An output artefact type (read-write)
13
- - Zero or more input artefact types (read-only, from previous foundry cycles)
11
+ - A `starting-cycles` list hints about which cycles can be entered first when the flow begins.
12
+ - A set of cycles (listed under `## Cycles`). Order is not implied — routing between cycles is owned by cycles themselves via their `targets` field.
14
13
 
15
- A foundry cycle runs: forge quench appraise, repeating until all feedback is resolved or the iteration limit is hit.
14
+ Running a flow creates a work branch and a `WORK.md`. The flow completes when no more reachable cycles remain to run, or when the user decides to stop.
15
+
16
+ ## Cycle
17
+
18
+ An iterative loop that produces a single artefact type. Defined in `foundry/cycles/*.md`. A cycle declares:
19
+
20
+ - `output` — the artefact type it produces (read-write).
21
+ - `inputs` — a contract (`any-of` / `all-of`) over other artefact types. Inputs are discovered on disk; they are read-only unless the output type's patterns happen to cover them.
22
+ - `targets` — the cycle(s) that may run after this one. May be empty (terminal cycle).
23
+ - `human-appraise` — whether a human quality gate runs every iteration (default: `false`).
24
+ - `deadlock-appraise` — whether a human is pulled in when LLM appraisers deadlock (default: `true`).
25
+ - `deadlock-iterations` — deadlock threshold (default: `5`).
26
+ - `models` — optional per-stage model overrides.
27
+
28
+ A cycle runs **forge → quench → appraise** (and optionally **human-appraise**), looping until all feedback is resolved or `max-iterations` is hit.
16
29
 
17
30
  ## Stage
18
31
 
19
- The steps within a foundry cycle. Each stage is referenced using a `base:alias` format (e.g. `forge:write-haiku`) where the base is the stage type and the alias describes its role in that cycle.
32
+ A single step within a cycle. Every stage is referenced as `base:alias` (e.g. `forge:write-haiku`, `quench:check-syllables`) the base is the stage type; the alias makes the stage's role self-documenting in WORK.md.
20
33
 
21
- - Forge — produce or revise the artefact
22
- - Quench — run deterministic CLI checks
23
- - Appraisesubjective evaluation by multiple appraisers
24
- - HITLhuman-in-the-loop checkpoint (see below)
34
+ Stage bases:
35
+
36
+ - **forge**produce or revise the artefact.
37
+ - **quench**run deterministic CLI checks (skipped if the artefact type has no `validation.md`).
38
+ - **appraise** — subjective evaluation by multiple appraiser sub-agents.
39
+ - **human-appraise** — human quality gate. Can run every iteration, only on deadlock, or both.
40
+
41
+ Every stage runs inside a token-gated lifecycle (`foundry_stage_begin` / `foundry_stage_end` / `foundry_stage_finalize`). Mutation tools are stage-locked: a forge stage can't add feedback, a quench stage can't register artefacts. See the enforcement section of the [README](../README.md#enforcement-model).
25
42
 
26
43
  ## Artefact type
27
44
 
28
- A definition of what kind of thing is being produced. Lives in `foundry/artefacts/<type>/` with:
29
- - `definition.md` — identity, file patterns, output location, prose description
30
- - `laws.md` — type-specific subjective evaluation criteria
31
- - `validation.md` — CLI commands for deterministic quench checks
45
+ A definition of what is being produced. Lives in `foundry/artefacts/<type>/`:
46
+
47
+ - `definition.md` — identity, file patterns, output directory, appraiser config, prose description.
48
+ - `laws.md` *(optional)* type-specific subjective criteria.
49
+ - `validation.md` *(optional)* — CLI commands for deterministic quench checks.
50
+
51
+ File patterns must not overlap with any other artefact type's patterns — the write-invariant enforcer needs to know which type owns a given file.
32
52
 
33
53
  ## Law
34
54
 
35
- A subjective pass/fail criterion. Global laws live in `foundry/laws/` (all files concatenated). Type-specific laws live in `foundry/artefacts/<type>/laws.md`. Each law has an identifier (its heading), used in feedback tags.
55
+ A subjective pass/fail criterion. Two scopes:
56
+
57
+ - **Global** — `foundry/laws/*.md`, all files concatenated, applies to every artefact.
58
+ - **Type-specific** — `foundry/artefacts/<type>/laws.md`.
59
+
60
+ Each law is a `## heading` (its identifier, used in feedback tags as `#law:<id>`) with a description, passing criteria, and failing criteria.
36
61
 
37
62
  ## Appraiser
38
63
 
39
- An independent evaluator with a defined personality. Lives in `foundry/appraisers/`. Each appraiser can optionally specify a `model` to override the cycle-level appraise model. Model diversity is configured at the cycle level (via the `models` frontmatter map) and optionally per-appraiser. They can be assigned to specific artefact types or appraise everything.
64
+ An independent evaluator with a defined personality. Lives in `foundry/appraisers/*.md`. Appraisers may specify a `model` field to override the cycle-level appraise model. Each artefact type picks which appraisers may evaluate it (`appraisers.allowed`) and how many run per iteration (`appraisers.count`). Selection distributes evenly across allowed personalities.
40
65
 
41
66
  ## WORK.md
42
67
 
43
- The transient shared state for a foundry flow. Created on the work branch, it tracks: where the foundry flow is (frontmatter cursor), what artefacts exist, and all feedback with its full lifecycle. See [work-spec.md](work-spec.md) for the full spec.
68
+ The transient shared state for a flow. Created on the work branch by the flow skill, it tracks:
69
+
70
+ - Current position (flow, cycle, stage list, iteration limits) in frontmatter.
71
+ - The goal (prose — written once).
72
+ - An artefact registry (file, type, cycle, status).
73
+ - All feedback with its full lifecycle.
74
+
75
+ See [work-spec.md](work-spec.md) for the full spec.
76
+
77
+ ## WORK.history.yaml
78
+
79
+ Append-only log of every stage execution, sitting next to WORK.md. Used by sort to reconstruct what has happened in the current cycle. See [work-spec.md](work-spec.md).
44
80
 
45
81
  ## Feedback
46
82
 
47
- The communication mechanism between stages. Written as markdown checklist items in WORK.md with tags (`#validation` or `#law:<id>`). Follows a lifecycle: open → actioned/wont-fix → approved/rejected. See [work-spec.md](work-spec.md) for details.
83
+ The communication mechanism between stages. Written as markdown checklist items in WORK.md, grouped by artefact file, tagged by source:
84
+
85
+ - `#validation` — from a deterministic quench command. Cannot be wont-fixed.
86
+ - `#law:<law-id>` — from an appraiser, tied to a specific law. May be wont-fixed with justification.
87
+ - `#human` — from a human-appraise stage. Takes absolute priority; cannot be wont-fixed.
88
+
89
+ Lifecycle: `open` → `actioned` / `wont-fix` → `approved` / `rejected`. `approved` is terminal; `rejected` re-opens. Items are never deleted.
90
+
91
+ ## HITL / human-appraise
92
+
93
+ Human-in-the-loop checkpoint. A stage where Foundry pauses and asks a human for input. Two triggers:
94
+
95
+ 1. **Every-iteration** — the cycle declares `human-appraise: true`. The `human-appraise` stage runs after LLM appraise each iteration.
96
+ 2. **Deadlock** — the cycle declares `deadlock-appraise: true` (default). If forge and appraisers ping-pong on the same items for `deadlock-iterations` (default 5) iterations, sort inserts a `human-appraise` stage to break the tie.
48
97
 
49
- ## HITL
98
+ Human feedback is tagged `#human` and takes priority over LLM feedback on the same topic.
50
99
 
51
- Human-in-the-loop checkpoint. A stage type that pauses the foundry cycle and requests human input before continuing. Configured per cycle by including a `hitl:alias` entry in the `stages` list. When a hitl stage runs, it presents the current artefact state to the human and collects feedback tagged `#hitl`. Like other feedback, hitl feedback follows the standard lifecycle (open → actioned → approved/rejected).
100
+ ## Micro-commit
52
101
 
53
- ## Micro commit
102
+ Every stage ends with a commit made by the orchestrator. This enables two things: file-modification enforcement (the write-invariant check compares the stage's diff to its allowed patterns) and recoverability (a crash mid-flow leaves a clean commit boundary to resume from). Orchestration refuses to proceed if uncommitted work is lingering in `WORK.md`, `WORK.history.yaml`, or `.foundry/`.
54
103
 
55
- Every stage ends with a commit (via the `foundry_git_commit` tool). This enables file modification enforcement — the sort tool checks the git diff to ensure each stage only touched files it was allowed to.
104
+ ## Stage token
105
+
106
+ A single-use HMAC-signed string, minted by `foundry_orchestrate` when a stage is dispatched. The sub-agent must redeem the token via `foundry_stage_begin`; mutation tools then check the active stage matches their role. Keys live in `.foundry/.secret` (mode 0600, gitignored, one per worktree). This prevents out-of-band mutations, replayed stages, and sub-agents skipping the lifecycle.
107
+
108
+ ## `.foundry/` state directory
109
+
110
+ A gitignored directory created on first plugin boot, holding runtime state:
111
+
112
+ - `.secret` — the HMAC key.
113
+ - `active-stage.json` — present only during an active stage.
114
+ - `last-stage.json` — used by `foundry_stage_finalize` after `stage_end`.
56
115
 
57
116
  ## Custom tools
58
117
 
59
- All deterministic pipeline operations are exposed as custom tools via the Foundry plugin. Skills call tools instead of manipulating files directly. The tools are backed by shared library modules in `scripts/lib/` with injectable I/O for testability. This separation ensures that file format parsing, state transitions, and routing logic are handled by tested code rather than LLM interpretation.
118
+ All deterministic pipeline operations are exposed as custom tools by the Foundry plugin. Skills call these tools instead of manipulating files directly. Tools are backed by shared library modules in `scripts/lib/` with injectable I/O so they can be unit-tested. This separation ensures state transitions and routing logic are tested code, not LLM interpretation. See the [README](../README.md#custom-tools) for the full catalogue.
119
+
120
+ ## Skill
121
+
122
+ A self-contained workflow written as markdown with YAML frontmatter. Foundry ships pipeline skills (`flow`, `orchestrate`, `forge`, `quench`, `appraise`, `human-appraise`), authoring skills (`add-*`, `init-foundry`), and utility skills (`list-agents`, `refresh-agents`, `upgrade-foundry`). Skills are either **atomic** (do one thing) or **composite** (orchestrate other skills).
@@ -1,78 +1,187 @@
1
1
  # Getting Started
2
2
 
3
- How to set up and run your first foundry flow.
3
+ End-to-end walkthrough for setting up Foundry and running your first flow.
4
+
5
+ ---
4
6
 
5
7
  ## Prerequisites
6
8
 
7
- - Git repository initialised
8
- - Node.js available (for validation scripts)
9
- - An AI coding tool that supports skills (OpenCode, Claude Code, Copilot CLI, etc.)
9
+ - A git repository initialised with a clean working tree.
10
+ - Node.js 18.3.0 (for the plugin and validation scripts).
11
+ - [OpenCode](https://opencode.ai) (primary target multi-model routing relies on OpenCode's agent files).
12
+
13
+ ## Install
14
+
15
+ Add Foundry to `opencode.json`:
16
+
17
+ ```json
18
+ {
19
+ "packages": {
20
+ "@really-knows-ai/foundry": "latest"
21
+ }
22
+ }
23
+ ```
24
+
25
+ Restart OpenCode (or reload plugins) so the plugin registers its tools and skills.
26
+
27
+ ## Initialize
28
+
29
+ In your project, invoke the `init-foundry` skill. It:
30
+
31
+ 1. Creates the `foundry/` directory structure:
32
+ ```
33
+ foundry/
34
+ artefacts/.gitkeep
35
+ flows/.gitkeep
36
+ cycles/.gitkeep
37
+ laws/.gitkeep
38
+ appraisers/.gitkeep
39
+ ```
40
+ 2. Runs `refresh-agents` to generate `.opencode/agents/foundry-*.md` — one per available model — so cycles can dispatch to specific models later.
41
+ 3. Commits the scaffolding.
42
+
43
+ The `.foundry/` runtime directory (holding `.secret` for stage tokens) is created automatically on first plugin boot and added to `.gitignore`.
10
44
 
11
- ## Step by step
45
+ ---
46
+
47
+ ## Author the configuration
48
+
49
+ Foundry's configuration is five things: artefact types, laws, appraisers, cycles, and flows. You can write the files by hand, but the authoring skills do conflict checking, scaffolding, and validation — use them.
12
50
 
13
51
  ### 1. Define an artefact type
14
52
 
15
- Create a directory under `foundry/artefacts/` with three files:
53
+ Run `add-artefact-type`. It walks you through:
16
54
 
17
- ```
18
- foundry/artefacts/my-type/
19
- definition.md # what it is, file patterns, output location
20
- laws.md # subjective laws (optional)
21
- validation.md # CLI validation commands (optional)
22
- ```
55
+ - `id` (lowercase, hyphenated), `name`, prose description.
56
+ - `file-patterns` — glob patterns describing which files this type owns. The skill refuses patterns that overlap with existing types.
57
+ - `output-dir` where forge should write new files.
58
+ - Appraiser config — how many appraisers evaluate this type and which personalities are allowed.
59
+ - Optional `laws.md` type-specific criteria.
60
+ - Optional `validation.md` — CLI commands for quench (non-zero exit = failure).
23
61
 
24
- Use the `init-foundry` skill to scaffold the `foundry/` directory, then use `add-artefact-type` to create your first artefact type interactively — or create the directory structure above manually.
62
+ Produces `foundry/artefacts/<id>/definition.md` (+ optional `laws.md`, `validation.md`).
25
63
 
26
64
  ### 2. Write laws
27
65
 
28
- Add global laws to any `.md` file in `foundry/laws/`. Add type-specific laws to `foundry/artefacts/<type>/laws.md`.
66
+ Laws are subjective pass/fail criteria evaluated by appraisers. Two scopes:
67
+
68
+ - **Global** — `foundry/laws/*.md`. All files are concatenated and apply to every artefact.
69
+ - **Type-specific** — `foundry/artefacts/<type>/laws.md`.
29
70
 
30
- Each law is a `##` heading with: a description, what passing looks like, and what failing looks like.
71
+ Run `add-law` to create one with conflict detection. Each law is a `## heading` (its identifier, referenced as `#law:<id>` in feedback) with a description, passing criteria, and failing criteria.
31
72
 
32
- ### 3. Define a foundry cycle
73
+ ### 3. Create appraisers
33
74
 
34
- Create a file in `foundry/cycles/` that specifies what artefact type the foundry cycle produces and what inputs it reads:
75
+ Appraisers are independent evaluators with named personalities. Run `add-appraiser`. Each appraiser may override the cycle-level appraise model via a `model` field. Artefact types pick which appraisers may evaluate them (`appraisers.allowed`).
35
76
 
36
- ```yaml
77
+ ### 4. Define a cycle
78
+
79
+ Run `add-cycle`. A cycle produces one artefact type and declares:
80
+
81
+ - `output` — the artefact type (must already exist).
82
+ - `inputs` — a contract (`any-of` or `all-of`) over other types. Empty for starting cycles.
83
+ - `targets` — the cycle(s) that may run after this one. Empty for terminal cycles.
84
+ - `human-appraise` / `deadlock-appraise` / `deadlock-iterations` — human-gate config.
85
+ - `models` — optional per-stage model overrides.
86
+
87
+ Example:
88
+
89
+ ```markdown
37
90
  ---
38
- id: my-cycle
39
- name: My Cycle
40
- output: my-type
41
- inputs: []
91
+ id: haiku-creation
92
+ name: Haiku Creation
93
+ output: haiku
94
+ inputs:
95
+ type: any-of
96
+ artefacts:
97
+ - petition
98
+ targets: []
99
+ human-appraise: false
100
+ deadlock-appraise: true
101
+ deadlock-iterations: 5
102
+ models:
103
+ appraise: openai/gpt-5
42
104
  ---
105
+
106
+ # Haiku Creation
107
+
108
+ Writes a haiku satisfying the petition produced by haiku-ideation.
43
109
  ```
44
110
 
45
- Cycles list their stages using `base:alias` format e.g. `forge:write-haiku`, `quench:check-syllables`. The alias makes each stage's purpose clear when reading WORK.md. You can also include `hitl:alias` stages for human-in-the-loop checkpoints.
111
+ The skill validates that every input type can be produced by some cycle in the flow and that targets are reachable.
46
112
 
47
- ### 4. Define a foundry flow
113
+ ### 5. Define a flow
48
114
 
49
- Create a file in `foundry/flows/` that lists foundry cycles in order:
115
+ Run `add-flow`. A flow groups cycles and declares starting points:
50
116
 
51
117
  ```markdown
52
118
  ---
53
- id: my-flow
54
- name: My Flow
119
+ id: make-haiku
120
+ name: Make a Haiku
121
+ starting-cycles:
122
+ - haiku-ideation
55
123
  ---
56
124
 
57
- # My Flow
125
+ # Make a Haiku
58
126
 
59
- Description of what this flow produces.
127
+ End-to-end flow: petition haiku, with a human quality gate.
60
128
 
61
129
  ## Cycles
62
130
 
63
- 1. my-cycle
131
+ - haiku-ideation
132
+ - haiku-creation
64
133
  ```
65
134
 
66
- ### 5. Run the foundry flow
135
+ Routing between cycles is owned by individual cycles via their `targets`, not by the flow.
136
+
137
+ ---
138
+
139
+ ## Run the flow
140
+
141
+ Tell OpenCode something like:
142
+
143
+ > Run the `make-haiku` flow to write a haiku about autumn rain.
144
+
145
+ The `flow` skill will:
146
+
147
+ 1. Check prerequisites and pick a starting cycle — matching your prose to a cycle's output type. If the request is ambiguous, it prompts (defaulting to `starting-cycles`). If a cycle's input contract can't be satisfied from files on disk, it won't be chosen.
148
+ 2. Create a work branch and scaffold `WORK.md` with the goal.
149
+ 3. Hand off to `orchestrate`, which drives the cycle:
150
+ - **forge** writes the artefact.
151
+ - **quench** runs CLI validators (if configured).
152
+ - **appraise** dispatches parallel appraiser sub-agents and consolidates their `#law:<id>` feedback.
153
+ - **human-appraise** (if configured, or on deadlock) asks you for input.
154
+ - If any unresolved feedback remains, another forge iteration begins.
155
+ 4. When the cycle completes, the flow skill checks the cycle's `targets`. If a target's input contract is satisfied, it asks whether to proceed.
156
+ 5. When all desired cycles are done, the flow skill summarises the output and asks how to finish — squash-merge, PR, or leave the branch.
157
+
158
+ Every stage ends with a micro-commit. Violations of the write invariant (writing to disallowed files) hard-stop the cycle.
159
+
160
+ ---
161
+
162
+ ## Inspecting progress
163
+
164
+ While a flow is running, the state of the world is in three places:
67
165
 
68
- Tell your AI tool to start the foundry flow. It will create a work branch, initialise WORK.md, and begin executing foundry cycles.
166
+ - `WORK.md` current cycle, goal, artefact table, all feedback with full lifecycle.
167
+ - `WORK.history.yaml` — append-only log of every stage execution.
168
+ - `git log` — one commit per stage.
169
+
170
+ You can pause and resume: if the flow skill sees an existing `WORK.md` when you start, it asks whether to resume, discard, or abort. Resume is only offered if the existing flow and cycle match the current request.
171
+
172
+ ---
173
+
174
+ ## Cleaning up
175
+
176
+ Before squash-merging the work branch back into main, **delete `WORK.md` and `WORK.history.yaml`** — they're ephemeral per-flow state, not artefacts. `.foundry/` is gitignored and doesn't need cleanup.
177
+
178
+ If you used `foundry_git_finish`, it handles this for you.
179
+
180
+ ---
69
181
 
70
- ## What happens during a foundry flow
182
+ ## Next steps
71
183
 
72
- 1. The foundry flow skill creates a branch and WORK.md
73
- 2. For each foundry cycle:
74
- - Forge produces the artefact
75
- - Quench runs CLI commands (if defined)
76
- - Appraise dispatches sub-agent appraisers against the laws
77
- - If feedback exists, forge revises and the foundry cycle repeats
78
- 3. When all foundry cycles complete, the human decides to merge, PR, or discard
184
+ - [docs/concepts.md](concepts.md) concise glossary.
185
+ - [docs/work-spec.md](work-spec.md) full WORK.md spec.
186
+ - [README.md](../README.md) architecture, enforcement, design decisions.
187
+ - [CHANGELOG.md](../CHANGELOG.md) version history.
package/docs/work-spec.md CHANGED
@@ -10,23 +10,31 @@ flow: <flow-id>
10
10
  cycle: <current-cycle-id>
11
11
  stages: [forge:write-haiku, quench:check-syllables, appraise:evaluate-quality]
12
12
  max-iterations: 3
13
+ human-appraise: false
14
+ deadlock-appraise: true
15
+ deadlock-iterations: 5
16
+ models:
17
+ forge: anthropic/claude-opus-4.7
18
+ appraise: openai/gpt-5
13
19
  ---
14
20
  ```
15
21
 
16
22
  Fields:
17
- - `flow` — the foundry flow being executed
18
- - `cycle` — the current foundry cycle id
19
- - `stages` — the ordered route for this foundry cycle, set when the foundry cycle starts. Each entry uses `base:alias` format where `base` is the stage type (`forge`, `quench`, `appraise`, or `hitl`) and `alias` is a human-readable name for what that stage does in this cycle. Determined from the artefact type: if `validation.md` exists, include `quench`; always include `forge` and `appraise`. A `hitl` stage can be included for human-in-the-loop checkpoints.
20
- - `max-iterations` — how many forge passes before the foundry cycle is blocked (default: 3)
23
+ - `flow` — the foundry flow being executed.
24
+ - `cycle` — the current cycle id.
25
+ - `stages` — the ordered route for this cycle. Each entry uses `base:alias` format where `base` is the stage type (`forge`, `quench`, `appraise`, or `human-appraise`) and `alias` is a human-readable name for what that stage does in this cycle. Derived from the cycle and artefact type: `forge` + `appraise` are always included, `quench` is included iff the artefact type has `validation.md`, `human-appraise` is included iff the cycle sets `human-appraise: true`.
26
+ - `max-iterations` — how many forge passes before the cycle is blocked (default: 3).
27
+ - `human-appraise` — run human-appraise every iteration (default: `false`).
28
+ - `deadlock-appraise` — route to human-appraise when LLM appraisers deadlock (default: `true`).
29
+ - `deadlock-iterations` — deadlock threshold (default: 5).
30
+ - `models` — optional per-stage model overrides; individual appraisers may further override via their own `model` field.
21
31
 
22
- The `stages` list is the happy path. Sort follows it but loops back to `forge` when unresolved feedback demands it.
32
+ The `stages` list is the happy path. Sort follows it but loops back to `forge` when unresolved feedback demands it, and inserts a `human-appraise` stage on deadlock.
23
33
 
24
34
  ### Who sets what
25
35
 
26
- - `flow` — set by the foundry flow skill at foundry flow start, never changes
27
- - `cycle` — set by the foundry flow skill when starting each foundry cycle
28
- - `stages` — set by the orchestrate skill when starting each foundry cycle (reads artefact type to determine if quench is needed)
29
- - `max-iterations` — set by the orchestrate skill (default 3, could be overridden in foundry cycle definition)
36
+ - `flow`, `cycle`, `goal` — set by the `flow` skill via `foundry_workfile_create` at flow/cycle boundaries.
37
+ - `stages`, `max-iterations`, `human-appraise`, `deadlock-appraise`, `deadlock-iterations`, `models` — set by `foundry_orchestrate` on the first call of each cycle (via internal `workfile_configure_from_cycle`, reading the cycle definition).
30
38
 
31
39
  ## Sections
32
40
 
@@ -70,7 +78,7 @@ Grouped by artefact file path. Each item is a checklist entry with a tag indicat
70
78
 
71
79
  - `#validation` — from a deterministic quench command
72
80
  - `#law:<law-id>` — from subjective appraise, tied to a specific law
73
- - `#hitl` — from human-provided feedback at a hitl checkpoint
81
+ - `#human` — from human-provided feedback at a human-appraise checkpoint
74
82
 
75
83
  #### Lifecycle states
76
84
 
@@ -86,20 +94,23 @@ Grouped by artefact file path. Each item is a checklist entry with a tag indicat
86
94
 
87
95
  #### Rules
88
96
 
89
- - Validation feedback (`#validation`) cannot be wont-fixed
90
- - Feedback is never deleted — it stays as a record of the iteration history
91
- - New feedback is appended, not inserted
92
- - Items are grouped under the artefact they relate to
97
+ - Validation feedback (`#validation`) cannot be wont-fixed — deterministic rules are not negotiable.
98
+ - Human feedback (`#human`) cannot be wont-fixed — it takes absolute priority over LLM feedback.
99
+ - Feedback is never deleted — it stays as a record of the iteration history.
100
+ - New feedback is appended, not inserted.
101
+ - Items are grouped under the artefact they relate to.
93
102
 
94
103
  ## Who writes what
95
104
 
96
105
  | Section | Written by | Updated by |
97
106
  |---------|-----------|------------|
98
- | Frontmatter (`flow`) | `foundry_workfile_create` (flow skill) | nobody |
99
- | Frontmatter (`cycle`, `stages`, `max-iterations`) | `foundry_workfile_set` (orchestrate skill) | `foundry_workfile_set` (reset on each new cycle) |
107
+ | Frontmatter (`flow`, `cycle`, `goal`) | `foundry_workfile_create` (flow skill) | `foundry_workfile_delete` + re-create between cycles |
108
+ | Frontmatter (`stages`, `max-iterations`, `human-appraise`, `deadlock-appraise`, `deadlock-iterations`, `models`) | `foundry_orchestrate` (first call of each cycle, internally) | reset on each new cycle |
100
109
  | Goal | `foundry_workfile_create` (flow skill) | nobody |
101
- | Artefacts | `foundry_artefacts_add` (forge skill) | `foundry_artefacts_set_status` (orchestrate skill) |
102
- | Feedback | `foundry_feedback_add` (quench/appraise/hitl) | `foundry_feedback_action`/`foundry_feedback_wontfix` (forge), `foundry_feedback_resolve` (quench/appraise/hitl) |
110
+ | Artefacts | `foundry_stage_finalize` (orchestrator, after forge closes) | `foundry_artefacts_set_status` (orchestrator → `done`/`blocked`) |
111
+ | Feedback | `foundry_feedback_add` (quench / appraise / human-appraise) | `foundry_feedback_action` / `foundry_feedback_wontfix` (forge), `foundry_feedback_resolve` (quench / appraise / human-appraise) |
112
+
113
+ Note: `foundry_artefacts_add` no longer exists as a public tool — artefact registration is automatic via `stage_finalize`, which scans the git diff and registers files matching the output type's `file-patterns` as `draft`.
103
114
 
104
115
  ## WORK.history.yaml
105
116
 
@@ -141,20 +152,20 @@ A separate file (`WORK.history.yaml`) alongside WORK.md. Append-only log of ever
141
152
 
142
153
  - `timestamp` — ISO 8601 UTC
143
154
  - `cycle` — which foundry cycle this entry belongs to
144
- - `stage` — which stage just completed, in `base:alias` format (e.g. `forge:draft-petition`, `quench:validate-petition`, `appraise:review-petition`, `hitl:human-review`)
155
+ - `stage` — which stage just completed, in `base:alias` format (e.g. `forge:draft-petition`, `quench:validate-petition`, `appraise:review-petition`, `human-appraise:human-review`)
145
156
  - `iteration` — the current iteration number (increments each time forge runs within a cycle)
146
157
  - `comment` — brief description of what happened
147
158
 
148
159
  ### Rules
149
160
 
150
- - Append-only — never edit or delete entries
151
- - Every stage skill appends an entry when it completes
152
- - The sort tool reads this to determine what has happened in the current foundry cycle
153
- - Iteration is derived from counting forge entries for the current foundry cycle
161
+ - Append-only — never edit or delete entries.
162
+ - Every stage produces an entry when it completes.
163
+ - Sort reads this to determine what has happened in the current cycle.
164
+ - Iteration is derived from counting forge entries for the current cycle.
154
165
 
155
166
  ### Who writes
156
167
 
157
- Every stage skill (forge, quench, appraise, hitl) appends an entry when it finishes via the `foundry_history_append` tool.
168
+ History entries are written by `foundry_orchestrate` after each stage closes (via its internal `foundry_history_append` — the tool is not registered publicly). Sub-agents never append history directly.
158
169
 
159
170
  ## Example
160
171
 
@@ -166,6 +177,9 @@ flow: make-haiku
166
177
  cycle: haiku-creation
167
178
  stages: [forge:write-haiku, quench:check-syllables, appraise:evaluate-quality]
168
179
  max-iterations: 3
180
+ human-appraise: false
181
+ deadlock-appraise: true
182
+ deadlock-iterations: 5
169
183
  ---
170
184
 
171
185
  # Goal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@really-knows-ai/foundry",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "description": "A structured framework for AI-driven artefact creation with deterministic routing, quality gates, and iterative refinement cycles.",
5
5
  "type": "module",
6
6
  "main": ".opencode/plugins/foundry.js",
@@ -10,9 +10,15 @@ You help the user create a new appraiser personality. You ensure it's genuinely
10
10
 
11
11
  ## Prerequisites
12
12
 
13
- Before running this skill, verify that the `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
13
+ Before running this skill, verify both of the following:
14
14
 
15
- > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
15
+ 1. The `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
16
+
17
+ > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
18
+
19
+ 2. The current git branch is not a work branch. Run `git rev-parse --abbrev-ref HEAD` — if it starts with `work/`, stop and tell the user:
20
+
21
+ > You're on a work branch (`<branch>`). Foundry configuration changes must be made on the base branch (usually `main`). Complete or discard the in-flight flow (`foundry_git_finish`, or switch branches and delete it), then re-run this skill from the base branch.
16
22
 
17
23
  ## Protocol
18
24
 
@@ -10,9 +10,15 @@ You help the user create a new artefact type. You ensure it doesn't conflict wit
10
10
 
11
11
  ## Prerequisites
12
12
 
13
- Before running this skill, verify that the `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
13
+ Before running this skill, verify both of the following:
14
14
 
15
- > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
15
+ 1. The `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
16
+
17
+ > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
18
+
19
+ 2. The current git branch is not a work branch. Run `git rev-parse --abbrev-ref HEAD` — if it starts with `work/`, stop and tell the user:
20
+
21
+ > You're on a work branch (`<branch>`). Foundry configuration changes must be made on the base branch (usually `main`). Complete or discard the in-flight flow (`foundry_git_finish`, or switch branches and delete it), then re-run this skill from the base branch.
16
22
 
17
23
  ## Protocol
18
24
 
@@ -10,9 +10,15 @@ You help the user create a new foundry cycle and add it to an existing foundry f
10
10
 
11
11
  ## Prerequisites
12
12
 
13
- Before running this skill, verify that the `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
13
+ Before running this skill, verify both of the following:
14
14
 
15
- > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
15
+ 1. The `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
16
+
17
+ > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
18
+
19
+ 2. The current git branch is not a work branch. Run `git rev-parse --abbrev-ref HEAD` — if it starts with `work/`, stop and tell the user:
20
+
21
+ > You're on a work branch (`<branch>`). Foundry configuration changes must be made on the base branch (usually `main`). Complete or discard the in-flight flow (`foundry_git_finish`, or switch branches and delete it), then re-run this skill from the base branch.
16
22
 
17
23
  ## Protocol
18
24
 
@@ -10,9 +10,15 @@ You help the user create a new foundry flow. A foundry flow is a set of foundry
10
10
 
11
11
  ## Prerequisites
12
12
 
13
- Before running this skill, verify that the `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
13
+ Before running this skill, verify both of the following:
14
14
 
15
- > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
15
+ 1. The `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
16
+
17
+ > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
18
+
19
+ 2. The current git branch is not a work branch. Run `git rev-parse --abbrev-ref HEAD` — if it starts with `work/`, stop and tell the user:
20
+
21
+ > You're on a work branch (`<branch>`). Foundry configuration changes must be made on the base branch (usually `main`). Complete or discard the in-flight flow (`foundry_git_finish`, or switch branches and delete it), then re-run this skill from the base branch.
16
22
 
17
23
  ## Protocol
18
24
 
@@ -10,9 +10,15 @@ You help the user create a new law. You ensure it's well-scoped, doesn't conflic
10
10
 
11
11
  ## Prerequisites
12
12
 
13
- Before running this skill, verify that the `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
13
+ Before running this skill, verify both of the following:
14
14
 
15
- > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
15
+ 1. The `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
16
+
17
+ > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
18
+
19
+ 2. The current git branch is not a work branch. Run `git rev-parse --abbrev-ref HEAD` — if it starts with `work/`, stop and tell the user:
20
+
21
+ > You're on a work branch (`<branch>`). Foundry configuration changes must be made on the base branch (usually `main`). Complete or discard the in-flight flow (`foundry_git_finish`, or switch branches and delete it), then re-run this skill from the base branch.
16
22
 
17
23
  ## Protocol
18
24