@really-knows-ai/foundry 2.1.0 → 2.3.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.
@@ -14,34 +14,48 @@ Before running this skill, verify that the `foundry/` directory exists in the pr
14
14
 
15
15
  > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
16
16
 
17
+ ## Stage lifecycle (mandatory)
18
+
19
+ Appraise runs inside an enforced stage. Your **first** and **last** tool calls are fixed:
20
+
21
+ 1. **First:** `foundry_stage_begin({stage, cycle, token})` — copy the token verbatim from the dispatch prompt.
22
+ 2. **Last:** `foundry_stage_end({summary})`.
23
+
24
+ Appraise makes **no disk writes**. All output flows through `foundry_feedback_add`. `foundry_stage_finalize` flags any unexpected writes as a violation.
25
+
17
26
  ## Protocol
18
27
 
19
- 1. Gather context:
20
- - Call `foundry_workfile_get` — identify the artefact to appraise and its type
21
- - Call `foundry_config_laws` — get all applicable laws (global + type-specific)
22
- - Call `foundry_config_artefact_type` with the type ID get the artefact type definition
23
- - Call `foundry_appraisers_select` with the type ID returns selected appraiser personalities with their raw model IDs
28
+ 1. `foundry_stage_begin(...)`.
29
+ 2. Gather context:
30
+ - `foundry_workfile_get` — read the `cycle` from frontmatter
31
+ - `foundry_artefacts_list({cycle: <current-cycle>})` enumerate this cycle's artefacts. Always pass the `cycle` filter; omitting it returns stale rows from prior sessions. Skip rows whose status is `done` or `blocked`.
32
+ - For each remaining row, gather its type-specific context:
33
+ - `foundry_config_laws` with the row's type — applicable laws (global + type-specific)
34
+ - `foundry_config_artefact_type` with the type ID — the artefact type definition
35
+ - `foundry_appraisers_select` with the type ID — selected appraiser personalities with their raw model IDs
24
36
 
25
- 2. Dispatch each appraiser as an independent sub-agent (see Dispatch below)
37
+ 3. Dispatch each appraiser as an independent sub-agent (see Dispatch below). If this cycle produced multiple artefacts, appraisers evaluate each.
26
38
 
27
- 3. Collect results from all appraisers
39
+ 4. Collect results from all appraisers
28
40
 
29
- 4. Consolidate (this is judgment):
41
+ 5. Consolidate (this is judgment):
30
42
  - Union of all issues — if any one appraiser flags it, it's feedback
31
43
  - De-duplicate: merge overlapping observations into a single feedback item
32
44
  - Preserve which appraiser(s) raised each issue (for traceability)
33
45
 
34
- 5. For each consolidated issue: call `foundry_feedback_add` with the artefact file path, the issue description, and tag `law:<law-id>`
46
+ 6. For each consolidated issue: `foundry_feedback_add(file, text, tag: 'law:<law-id>')`. Tag MUST start with `law:` — the tool rejects other tags during appraise. The tool also de-duplicates by text-hash.
47
+
48
+ 7. If no appraiser found any issues, the artefact clears appraisal.
35
49
 
36
- 6. If no appraiser found any issues, the artefact clears appraisal
50
+ 8. `foundry_stage_end({summary})`.
37
51
 
38
52
  ## Reviewing actioned and wont-fix feedback
39
53
 
40
54
  On subsequent passes, review previously actioned and wont-fix items:
41
55
 
42
- 1. Call `foundry_feedback_list` to find `actioned` and `wontfix` items for this artefact
43
- 2. For each item, the appraiser sub-agents evaluate whether the change addresses the issue (actioned) or the justification is sound (wont-fix)
44
- 3. Call `foundry_feedback_resolve` with disposition `"approved"` or `"rejected"` (with reason) for each
56
+ 1. `foundry_feedback_list` find `actioned` and `wont-fix` items for this artefact.
57
+ 2. Appraiser sub-agents evaluate whether the change addresses the issue (`actioned`) or the justification is sound (`wont-fix`).
58
+ 3. `foundry_feedback_resolve(file, index, resolution: 'approved'|'rejected', reason?)`. Appraise is the only stage (other than human-appraise) allowed to resolve `wont-fix` items.
45
59
 
46
60
  ## Dispatch
47
61
 
@@ -91,7 +105,7 @@ If there are no issues, return an empty list.
91
105
 
92
106
  ## History
93
107
 
94
- Do NOT call `foundry_history_append` — the sort skill (your caller) is responsible for writing history. Instead, return a clear summary of what you found (e.g., "3 issues found across 2 appraisers" or "No issues found") so sort can log it.
108
+ Do NOT call `foundry_history_append` or `foundry_git_commit` — the sort skill handles those. Return a summary via `foundry_stage_end` (e.g., "3 issues found across 2 appraisers" or "No issues found").
95
109
 
96
110
  ### Human override awareness
97
111
 
@@ -99,6 +113,8 @@ When reviewing an artefact, check the feedback history for `#human` tagged items
99
113
 
100
114
  ## What you do NOT do
101
115
 
102
- - You do not revise the artefact
103
- - You do not check deterministic rules — that is the quench skill's job
104
- - You do not filter out feedback because only one appraiser raised it — one is enough
116
+ - You do not write files — all output goes through `foundry_feedback_add`.
117
+ - You do not revise the artefact.
118
+ - You do not check deterministic rules that is the quench skill's job.
119
+ - You do not filter out feedback because only one appraiser raised it — one is enough.
120
+ - You do not register artefacts — that happens automatically via `foundry_stage_finalize`.
@@ -2,7 +2,7 @@
2
2
  name: flow
3
3
  type: composite
4
4
  description: Runs a defined foundry flow to produce artefacts. Use this whenever the user references a flow by id, name, or paraphrase (e.g. "use the creative flow", "run creative-flow"). Do not brainstorm — the flow's cycles already define the work. The user's request is the goal to pass in.
5
- composes: [cycle]
5
+ composes: [orchestrate]
6
6
  ---
7
7
 
8
8
  # Flow
@@ -23,8 +23,15 @@ Before running this skill, verify that the `foundry/` directory exists in the pr
23
23
  - If only one starting cycle, use it
24
24
  - If multiple starting cycles, check whether the user's request makes the choice obvious (e.g., "write a haiku" clearly maps to `create-haiku`)
25
25
  - If ambiguous, prompt the user to choose
26
- 4. Call `foundry_workfile_create` with **only** the flow ID, chosen cycle ID, and goal do **not** pass `stages` or `maxIterations`. The `cycle` skill will read the cycle definition and populate those via `foundry_workfile_set` in the next step.
27
- 5. Execute the cycle by invoking the cycle skill
26
+ 4. Pre-check for an existing workfile (prevents silent data loss from an aborted prior session):
27
+ a. Call `foundry_workfile_get`.
28
+ b. If it returns `{error: ...}` (no WORK.md), proceed to step 5.
29
+ c. If it returns an existing workfile, present its `flow`, `cycle`, and `goal` to the user alongside the values just requested, then prompt for one of:
30
+ - **Resume** — keep the existing workfile and skip to step 6. **Only offer resume if the existing `flow` AND `cycle` match what the user just asked for.** If either differs, do not offer resume — running the wrong cycle against stale state corrupts the workflow.
31
+ - **Discard** — call `foundry_workfile_delete`, then proceed to step 5.
32
+ - **Abort** — stop the skill without modifying anything.
33
+ 5. Call `foundry_workfile_create` with **only** the flow ID, chosen cycle ID, and goal — do **not** pass `stages` or `maxIterations`. The `orchestrate` skill will read the cycle definition and handle setup on its first call.
34
+ 6. Execute the cycle by invoking the orchestrate skill
28
35
 
29
36
  ## Between cycles
30
37
 
@@ -42,9 +49,9 @@ When a cycle completes (sort returns `done`):
42
49
  - Check input contracts for each
43
50
  - The user chooses which target to pursue (or which to pursue first)
44
51
  5. Set up the next cycle:
45
- - Call `foundry_workfile_set` with `key: "cycle"`, `value: <next-cycle-id>`
46
- - Reset stages and iteration count for the new cycle
47
- - Execute the cycle by invoking the cycle skill
52
+ - Call `foundry_workfile_delete` to clear the completed cycle's WORK.md
53
+ - Call `foundry_workfile_create` with **only** the flow ID, the next cycle ID, and the goal — do **not** pass `stages` or `maxIterations`. The orchestrate skill will detect `needsSetup` on its first call and bootstrap the rest of the frontmatter from the cycle definition.
54
+ - Execute the cycle by invoking the orchestrate skill
48
55
 
49
56
  ## Completing a flow
50
57
 
@@ -14,33 +14,42 @@ Before running this skill, verify that the `foundry/` directory exists in the pr
14
14
 
15
15
  > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
16
16
 
17
+ ## Stage lifecycle (mandatory)
18
+
19
+ Forge runs inside an enforced stage. Your **first** and **last** tool calls are fixed:
20
+
21
+ 1. **First:** `foundry_stage_begin({stage, cycle, token})` — the orchestrator hands you `stage`, `cycle`, and an opaque `token` string in the dispatch prompt. Copy the token verbatim; never invent, edit, or re-sign it. No other tool call is permitted before this one. Any writes before `stage_begin` will be blocked by preconditions.
22
+ 2. **Last:** `foundry_stage_end({summary})` — return control to the orchestrator. After `stage_end`, the orchestrator calls `foundry_stage_finalize` which scans the disk and registers your output artefact. **You do not register artefacts yourself.**
23
+
17
24
  ## Protocol
18
25
 
19
26
  ### First generation (no artefact registered yet)
20
27
 
21
- 1. Call `foundry_workfile_get` understand the goal
22
- 2. Call `foundry_config_cycle` — understand what to produce and what inputs are available
23
- 3. Call `foundry_config_artefact_type` with the output type ID get the artefact type definition
24
- 4. Call `foundry_config_laws` — get all applicable laws (global + type-specific)
25
- 5. If the cycle has inputs, read the input artefacts (read-only context)
26
- 6. Produce the artefact, respecting all applicable laws from the start (this is judgment — use your craft)
27
- 7. Write the artefact file to the location specified in the artefact type definition
28
- 8. Call `foundry_artefacts_add` with the file path, type, and cycle to register it with status `"draft"`
28
+ 1. `foundry_stage_begin(...)` with the token from the dispatch prompt.
29
+ 2. `foundry_workfile_get` — understand the goal.
30
+ 3. `foundry_config_cycle` understand what to produce and what inputs are available.
31
+ 4. `foundry_config_artefact_type` with the output type ID — get the artefact type definition, especially its `file-patterns`.
32
+ 5. `foundry_config_laws` get all applicable laws (global + type-specific).
33
+ 6. If the cycle has inputs, read the input artefacts (read-only context).
34
+ 7. Produce the artefact, respecting all applicable laws from the start.
35
+ 8. Write the artefact file to a location that matches the artefact type's `file-patterns`.
36
+ 9. `foundry_stage_end({summary})`.
29
37
 
30
38
  ### Revision (feedback exists)
31
39
 
32
- 1. Call `foundry_feedback_list` to find unresolved feedback for the artefact
33
- 2. Read the artefact file
34
- 3. If the cycle has inputs, read the input artefacts (read-only context)
35
- 4. For each unresolved feedback item, either:
36
- - Address it and call `foundry_feedback_action` with the item ID (marks as actioned)
37
- - Call `foundry_feedback_wontfix` with the item ID and a justification (appraisal feedback only)
38
- 5. Update the artefact file
39
- 6. Wont-fix is only available for `law:` feedback (subjective appraisal). Validation feedback must be actioned — deterministic rules are not negotiable.
40
+ 1. `foundry_stage_begin(...)`.
41
+ 2. `foundry_feedback_list` — find unresolved feedback for the artefact.
42
+ 3. Read the artefact file.
43
+ 4. If the cycle has inputs, read the input artefacts (read-only context).
44
+ 5. For each unresolved feedback item, either:
45
+ - Address it and call `foundry_feedback_action` (marks item `actioned`), or
46
+ - Call `foundry_feedback_wontfix` with a justification — available only for `law:` / `human` tags (validation feedback must be actioned).
47
+ 6. Update the artefact file.
48
+ 7. `foundry_stage_end({summary})`.
40
49
 
41
- ### After (both paths)
50
+ ## File-pattern hygiene
42
51
 
43
- Do NOT call `foundry_history_append` the sort skill (your caller) is responsible for writing history. Instead, return a clear summary of what you did so sort can log it.
52
+ Writes during forge must match the output artefact type's `file-patterns`. Writing to any other path causes `foundry_stage_finalize` to return `{error: 'unexpected_files'}` and the orchestrator will mark the cycle's target artefact `blocked`. You will not get a retry. Plus `WORK.md` and `WORK.history.yaml` (managed by tools). Nothing else.
44
53
 
45
54
  ## Unresolved feedback
46
55
 
@@ -53,14 +62,17 @@ An item is resolved if it is `approved`.
53
62
  ## #human feedback
54
63
 
55
64
  Feedback tagged `human` (from the human-appraise stage) takes absolute priority:
56
- - You MUST address it — you cannot wont-fix `#human` feedback
57
- - When `#human` feedback contradicts LLM appraiser feedback on the same topic, follow the human's direction
58
- - Acknowledge the human's input in your revision
65
+ - You MUST address it — you cannot wont-fix `#human` feedback.
66
+ - When `#human` feedback contradicts LLM appraiser feedback on the same topic, follow the human's direction.
67
+ - Acknowledge the human's input in your revision.
59
68
 
60
69
  ## What you do NOT do
61
70
 
62
- - You do not evaluate or score the artefact
63
- - You do not add feedback — that is the quench skill's and appraise skill's job
64
- - You do not mark feedback as actioned unless you actually changed the artefact to address it
65
- - You do not wont-fix validation feedback
66
- - You do not modify input artefacts they are read-only
71
+ - You do not add feedback that is the quench and appraise skills' job. (`foundry_feedback_add` is blocked for you at the tool layer.)
72
+ - You do not `foundry_feedback_resolve` — that belongs to quench/appraise/human-appraise.
73
+ - You do not register artefacts `foundry_stage_finalize` handles that automatically.
74
+ - You do not call `foundry_history_append` or `foundry_git_commit` — the sort skill does.
75
+ - You do not evaluate or score the artefact.
76
+ - You do not mark feedback as actioned unless you actually changed the artefact to address it.
77
+ - You do not wont-fix validation feedback.
78
+ - You do not modify input artefacts — they are read-only.
@@ -14,17 +14,39 @@ Before running this skill, verify that the `foundry/` directory exists in the pr
14
14
 
15
15
  > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
16
16
 
17
+ ## Stage lifecycle (mandatory)
18
+
19
+ Human-appraise runs inside an enforced stage. Your **first** and **last** tool calls are fixed:
20
+
21
+ 1. **First:** `foundry_stage_begin({stage, cycle, token})` — copy the token verbatim from the dispatch prompt.
22
+ 2. **Last:** `foundry_stage_end({summary})`.
23
+
24
+ Human-appraise makes **no disk writes**. All output flows through `foundry_feedback_add` / `foundry_feedback_resolve` / `foundry_artefacts_set_status`. `foundry_stage_finalize` flags unexpected writes as a violation.
25
+
26
+ ## Input
27
+
28
+ When invoked from orchestrate, you receive `{cycle, token, context}`:
29
+ - `cycle` — the current cycle id
30
+ - `token` — single-use token for `foundry_stage_begin`
31
+ - `context.artefact_file` — the target artefact
32
+ - `context.recent_feedback` — recent deadlocked feedback items to present to the user
33
+
34
+ Your FIRST tool call must be `foundry_stage_begin({stage: 'human-appraise:<cycle>', cycle, token})`.
35
+
36
+ Your LAST tool call must be `foundry_stage_end({summary: '<one-sentence description of the user verdict>'})` — orchestrate reads this summary for the commit message.
37
+
17
38
  ## Protocol
18
39
 
19
- 1. Gather context by calling:
20
- - `foundry_workfile_get` current state, goal, artefacts
21
- - `foundry_artefacts_list` — current artefact files and status
40
+ 1. `foundry_stage_begin(...)`.
41
+ 2. Gather context by calling:
42
+ - `foundry_workfile_get` — current state, goal, cycle
43
+ - `foundry_artefacts_list({cycle: <current-cycle>})` — this cycle's artefact files and status (always pass the `cycle` filter; omitting it returns stale rows from prior sessions)
22
44
  - `foundry_feedback_list` — all existing feedback
23
45
  - `foundry_history_list` — what has happened so far
24
46
 
25
- 2. Read the artefact file(s) for this cycle.
47
+ 3. Read the artefact file(s) for this cycle.
26
48
 
27
- 3. Present to the human:
49
+ 4. Present to the human:
28
50
  - The current artefact content (full file content or multi-file diff)
29
51
  - A summary of this iteration's feedback (resolved and open)
30
52
  - If this is a deadlock escalation, clearly explain the deadlock:
@@ -33,15 +55,15 @@ Before running this skill, verify that the `foundry/` directory exists in the pr
33
55
  - Forge's wont-fix or revision justification
34
56
  - Ask the human to resolve the disagreement
35
57
 
36
- 4. Wait for the human's response.
58
+ 5. Wait for the human's response.
37
59
 
38
- 5. Act on the response:
39
- - **Approve** — "looks good" / "continue" — no feedback added, sort will advance
40
- - **Provide feedback** — call `foundry_feedback_add` with the human's feedback and tag `human`. Sort will route back to forge.
41
- - **Dismiss deadlocked feedback** — call `foundry_feedback_resolve` with `resolution: "approved"` on the deadlocked item(s). This overrides the appraiser.
42
- - **Abort** — call `foundry_artefacts_set_status` with status `"blocked"`, cycle ends
60
+ 6. Act on the response (tag MUST be `human` on any added feedback — the tool rejects other tags during human-appraise):
61
+ - **Approve** — "looks good" / "continue" — no feedback added, sort will advance.
62
+ - **Provide feedback** — `foundry_feedback_add(file, text, tag: 'human')`. Sort will route back to forge.
63
+ - **Dismiss deadlocked feedback** — `foundry_feedback_resolve(file, index, resolution: 'approved')`. Human-appraise may resolve items in state `actioned` or `wont-fix`. This overrides the appraiser.
64
+ - **Abort** — `foundry_artefacts_set_status(file, 'blocked')`, cycle ends.
43
65
 
44
- 6. Return a clear summary of what the human decided so sort can log it in history.
66
+ 7. `foundry_stage_end({summary})` describe what the human decided so sort can log it.
45
67
 
46
68
  ## #human feedback rules
47
69
 
@@ -51,8 +73,10 @@ Before running this skill, verify that the `foundry/` directory exists in the pr
51
73
 
52
74
  ## What you do NOT do
53
75
 
54
- - You do not make decisions for the human present the state and wait
55
- - You do not modify the artefact
56
- - You do not skip the pause — the human must respond before continuing
57
- - You do not filter or summarise away important details show the full picture
58
- - You do not call `foundry_history_append`sort owns history writing
76
+ - You do not write files all output goes through foundry tools.
77
+ - You do not make decisions for the human — present the state and wait.
78
+ - You do not modify the artefact.
79
+ - You do not skip the pause the human must respond before continuing.
80
+ - You do not filter or summarise away important details show the full picture.
81
+ - You do not call `foundry_history_append` or `foundry_git_commit` — sort owns those.
82
+ - You do not register artefacts — handled by `foundry_stage_finalize`.
@@ -0,0 +1,69 @@
1
+ ---
2
+ name: orchestrate
3
+ description: Runs a foundry cycle by calling foundry_orchestrate in a loop and acting on the returned action.
4
+ ---
5
+
6
+ # Orchestrate
7
+
8
+ You drive a foundry cycle by calling `foundry_orchestrate` repeatedly and acting on each returned `action`. The tool owns all step-ordering, history, committing, and routing. Your job is to dispatch subagents, run human-appraise when asked, and report terminal states.
9
+
10
+ ## Prerequisites
11
+
12
+ Before running this skill, verify that `foundry/` exists in the project root and `WORK.md` has been created by the flow skill (with `flow`, `cycle`, and `goal` fields). If not, stop and tell the user to run the flow skill first.
13
+
14
+ ## Protocol
15
+
16
+ Loop until `foundry_orchestrate` returns a terminal action (`done`, `blocked`, or `violation`):
17
+
18
+ 1. Call `foundry_orchestrate({lastResult})`. Omit `lastResult` on the first iteration. On subsequent iterations, pass `{kind, ok}` reflecting the previous action's outcome.
19
+
20
+ 2. Switch on the returned `action`:
21
+
22
+ ### `dispatch`
23
+
24
+ Payload: `{stage, subagent_type, prompt}`.
25
+
26
+ Call the `task` tool:
27
+ ```
28
+ task tool:
29
+ subagent_type: <subagent_type-from-payload>
30
+ description: "Run <stage> for <cycle>"
31
+ prompt: <prompt-from-payload — pass verbatim>
32
+ ```
33
+
34
+ When the task returns, call `foundry_orchestrate({lastResult: {kind: 'dispatch', ok: true}})`. If the task tool itself errored or reported a subagent crash, pass `{kind: 'dispatch', ok: false, error: '<message>'}`.
35
+
36
+ ### `human_appraise`
37
+
38
+ Payload: `{stage, token, context}`.
39
+
40
+ Invoke the `human-appraise` skill inline, passing `{cycle, token, context}`. The skill will prompt the user, collect feedback, and call `foundry_stage_end({summary})`.
41
+
42
+ When it returns, call `foundry_orchestrate({lastResult: {kind: 'human_appraise', ok: true}})`.
43
+
44
+ ### `done`
45
+
46
+ Payload: `{cycle, artefact_file, next_cycles}`.
47
+
48
+ 1. Call `foundry_artefacts_set_status({file: artefact_file, status: 'done'})`.
49
+ 2. Report to the user: "Cycle `<cycle>` complete. Output: `<artefact_file>`. Next cycles available: `<next_cycles>`."
50
+ 3. Return control to the flow skill.
51
+
52
+ ### `blocked`
53
+
54
+ Payload: `{cycle, artefact_file, reason}`.
55
+
56
+ Report to the user: "Cycle `<cycle>` blocked on `<artefact_file>`: `<reason>`." Return control to the flow skill. The artefact has already been marked blocked.
57
+
58
+ ### `violation`
59
+
60
+ Payload: `{details, affected_files}`.
61
+
62
+ Report to the user: "Cycle halted (violation): `<details>`. Affected files: `<affected_files>`." Return control to the flow skill. Affected artefacts have already been marked blocked.
63
+
64
+ ## What you do NOT do
65
+
66
+ - You do NOT inline forge / quench / appraise work. Always dispatch via `task`.
67
+ - You do NOT mint, modify, or cache tokens. The `prompt` from orchestrate already contains the token verbatim.
68
+ - You do NOT call `foundry_history_append`, `foundry_git_commit`, `foundry_stage_finalize`, or `foundry_sort`. These are not registered tools in v2.3+; orchestrate handles them internally.
69
+ - You do NOT reorder the protocol. `foundry_orchestrate` returns, you act, you call back. Nothing else between.
@@ -14,33 +14,49 @@ Before running this skill, verify that the `foundry/` directory exists in the pr
14
14
 
15
15
  > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
16
16
 
17
+ ## Stage lifecycle (mandatory)
18
+
19
+ Quench runs inside an enforced stage. Your **first** and **last** tool calls are fixed:
20
+
21
+ 1. **First:** `foundry_stage_begin({stage, cycle, token})` — copy the token verbatim from the dispatch prompt. Any other tool call before this will be blocked.
22
+ 2. **Last:** `foundry_stage_end({summary})`.
23
+
24
+ Quench makes **no disk writes**. You produce feedback via `foundry_feedback_add`, never by creating or modifying files. `foundry_stage_finalize` (run by the orchestrator after you return) will flag any unexpected writes as a violation.
25
+
17
26
  ## Protocol
18
27
 
19
- 1. Call `foundry_workfile_get` to identify the artefact and its type.
20
- 2. Call `foundry_config_validation` with the artefact type ID. If it returns null, output SKIP and stop there is no validation for this type.
21
- 3. Call `foundry_validate_run` with the type ID and artefact file path. It executes all validation commands and returns results.
22
- 4. For each failure: call `foundry_feedback_add` with the artefact file path, a description of the failure, and tag `"validation"`.
23
- 5. If all commands pass, add no new feedback.
28
+ 1. `foundry_stage_begin(...)`.
29
+ 2. `foundry_workfile_get` — read the `cycle` from frontmatter.
30
+ 3. `foundry_artefacts_list({cycle: <current-cycle>})` enumerate the artefacts produced by **this** cycle. Always pass the `cycle` filter; omitting it returns rows from prior sessions and validates stale files. Skip rows whose status is `done` or `blocked`.
31
+ 4. For each remaining row:
32
+ a. `foundry_config_validation` with the row's type. If it returns null, skip this row.
33
+ b. `foundry_validate_run` with the type ID and the row's file path — executes all validation commands and returns results.
34
+ c. For each failure: `foundry_feedback_add(file, text, tag: 'validation')`. Tag MUST be `validation` — the tool rejects other tags during quench.
35
+ 5. If every command passes for every row, add no new feedback.
36
+ 6. If the artefact table has no rows for this cycle, `foundry_stage_end({summary: 'SKIP: no artefacts registered for this cycle'})` and stop.
37
+ 7. `foundry_stage_end({summary})`.
24
38
 
25
39
  ## Reviewing actioned feedback
26
40
 
27
41
  On subsequent passes, review previously actioned items:
28
42
 
29
- 1. Call `foundry_feedback_list` to find `actioned` items tagged `validation` for this artefact.
43
+ 1. `foundry_feedback_list` find `actioned` items tagged `validation` for artefacts in this cycle (use the file list from step 3 above).
30
44
  2. Re-run the relevant command via `foundry_validate_run`.
31
- 3. If the check now passes: call `foundry_feedback_resolve` with disposition `"approved"`.
32
- 4. If it still fails: call `foundry_feedback_resolve` with disposition `"rejected"` and a reason.
45
+ 3. If the check now passes: `foundry_feedback_resolve(file, index, resolution: 'approved')`.
46
+ 4. If it still fails: `foundry_feedback_resolve(file, index, resolution: 'rejected', reason)`.
33
47
 
34
- There is no wont-fix for validation feedback. Deterministic rules are not negotiable.
48
+ There is no wont-fix for validation feedback deterministic rules are not negotiable. Quench may only resolve items in state `actioned`; the feedback tool enforces this.
35
49
 
36
50
  ## History
37
51
 
38
- Do NOT call `foundry_history_append` — the sort skill (your caller) is responsible for writing history. Instead, return a clear summary of what you found (e.g., "2 validation issues found" or "Validation passed") so sort can log it.
52
+ Do NOT call `foundry_history_append` or `foundry_git_commit` — the sort skill handles those. Return a clear summary via `foundry_stage_end` (e.g., "2 validation issues found" or "Validation passed").
39
53
 
40
54
  ## What you do NOT do
41
55
 
42
- - You do not make subjective judgments
43
- - You do not revise the artefact
44
- - You do not evaluate laws — that is the appraise skill's job
45
- - You do not invent validation rules you only run commands from the validation config
46
- - You do not duplicate feedback that already exists
56
+ - You do not write files — all output goes through `foundry_feedback_add`.
57
+ - You do not make subjective judgments.
58
+ - You do not revise the artefact (forge's job).
59
+ - You do not evaluate lawsthat is the appraise skill's job.
60
+ - You do not invent validation rules you only run commands from the validation config.
61
+ - You do not duplicate feedback that already exists (the tool de-duplicates by text-hash, but don't rely on it).
62
+ - You do not register artefacts — that happens automatically.
@@ -46,7 +46,7 @@ Check each file against the current expected format:
46
46
  - Has `targets` field? If not → needs target routing
47
47
  - Has `inputs.type` (`any-of`/`all-of`)? If `inputs` is a plain list → needs contract type
48
48
  - Has `hitl` in stages or frontmatter? → needs human-appraise migration
49
- - Has `human-appraise` config? Check format is correct
49
+ - Has nested `human-appraise: {enabled, deadlock-threshold}`? v2.2.1 flat-keys migration (see §4b)
50
50
  - Has `models` map? Check format
51
51
 
52
52
  **Artefact types:**
@@ -98,6 +98,69 @@ For each `.opencode/agents/foundry-*.md` file with a `.` in its filename:
98
98
 
99
99
  After renaming, remind the user: **Restart OpenCode** for the new agent filenames to register.
100
100
 
101
+ ### 4a. v2.2.0 lifecycle upgrade
102
+
103
+ Foundry v2.2.0 introduces a tool-enforced stage lifecycle (`stage_begin` / `stage_end` / `stage_finalize`) backed by a per-project state directory and HMAC-signed dispatch tokens. The upgrade is non-destructive — no WORK.md or artefact migration is required — but the project needs three small changes:
104
+
105
+ 1. **Create `.foundry/`** (if absent):
106
+ - `mkdir -p .foundry`
107
+ - The plugin auto-creates `.foundry/.secret` on first boot via `readOrCreateSecret`. You do not need to generate it by hand; just ensure the directory exists and is writable.
108
+ 2. **Gitignore `.foundry/`**:
109
+ - Ensure `.gitignore` contains a line `.foundry/` (append if missing; do not duplicate). The directory holds a per-worktree HMAC secret and transient active-stage state — neither should be committed.
110
+ 3. **Pre-existing state:** v2.2.0 is a fresh state system. There is no `active-stage.json` to migrate. If one happens to exist from a manually-aborted prior run, leave it alone — the new plugin treats its absence as "no active stage" and its presence as a legitimate in-flight stage.
111
+
112
+ The `foundry_artefacts_add` tool has been removed in v2.2.0 — artefact registration now happens automatically via `foundry_stage_finalize`. No existing config references this tool, so there is nothing to migrate in `foundry/`.
113
+
114
+ ### 4b. v2.2.1 cycle-definition flat human-appraise keys
115
+
116
+ v2.2.1 replaces the nested `human-appraise: {enabled, deadlock-threshold}` block in cycle definitions with three flat keys:
117
+
118
+ ```yaml
119
+ human-appraise: <true|false> # default: false — run human-appraise every iteration
120
+ deadlock-appraise: <true|false> # default: true — pull in human-appraise when LLM appraisers deadlock
121
+ deadlock-iterations: <number> # default: 5 — deadlock detection threshold
122
+ ```
123
+
124
+ For each `foundry/cycles/*.md` whose frontmatter has the old nested form, migrate:
125
+
126
+ - `human-appraise.enabled: true` → `human-appraise: true`
127
+ - `human-appraise.enabled: false` (or missing) → `human-appraise: false`
128
+ - `human-appraise.deadlock-threshold: N` → `deadlock-iterations: N`
129
+ - Always add `deadlock-appraise: true` unless the user explicitly wants the stricter "no human ever" behavior (`deadlock-appraise: false` → deadlock marks the cycle `blocked`).
130
+
131
+ The old nested form is no longer read. After migration, verify by asking: "cycle `<id>`: human-appraise every iteration? deadlock-appraise on? deadlock-iterations = N?".
132
+
133
+ ### 4c. v2.2.x → v2.3.0
134
+
135
+ v2.3.0 replaces the LLM-driven sort orchestrator with the `foundry_orchestrate` plugin tool. The `cycle` and `sort` skills are removed. Six tools are deregistered: `foundry_sort`, `foundry_history_append`, `foundry_stage_finalize`, `foundry_git_commit`, `foundry_workfile_configure_from_cycle`, `foundry_workfile_set`.
136
+
137
+ #### Pre-flight checks
138
+
139
+ Before upgrading, verify a clean base state. Abort the upgrade if any of these fail:
140
+
141
+ 1. **Branch**: must be on `main` (or the user's configured default base branch).
142
+ - Check: `git rev-parse --abbrev-ref HEAD` — must match expected default.
143
+ - If on `work/*`: abort with "You're on a work branch. Switch to main and complete or discard any in-flight flow before upgrading."
144
+
145
+ 2. **Working tree**: must be clean.
146
+ - Check: `git status --porcelain` — must be empty.
147
+ - If dirty: abort with "Uncommitted changes. Commit or stash before upgrading."
148
+
149
+ 3. **In-flight workfile**: `WORK.md` must not exist.
150
+ - Check: is `WORK.md` present in the repo root?
151
+ - If yes: abort with "In-flight workfile detected. Delete it (`foundry_workfile_delete`) or complete the cycle before upgrading."
152
+
153
+ Only when all three pass, proceed with the plugin swap.
154
+
155
+ #### Upgrade steps
156
+
157
+ 1. Install the new plugin package version: `npm install @really-knows-ai/foundry@2.3.0 --save-dev`.
158
+ 2. Swap `.opencode/plugins/foundry.js` with the new version from `node_modules/@really-knows-ai/foundry/.opencode/plugins/foundry.js`.
159
+ 3. Remove `skills/cycle/` and `skills/sort/` directories from the project if they exist locally (they shouldn't — skills live in the package).
160
+ 4. Commit the upgrade: `chore: upgrade foundry to 2.3.0`.
161
+
162
+ No state migration is performed. In-flight cycles from v2.2.x must be completed or discarded before upgrading.
163
+
101
164
  ### 5. Migrate flows
102
165
 
103
166
  For each flow needing migration:
@@ -1,81 +0,0 @@
1
- ---
2
- name: cycle
3
- type: composite
4
- description: Runs a foundry cycle by delegating all routing to the sort skill.
5
- composes: [sort, forge, quench, appraise, human-appraise]
6
- ---
7
-
8
- # Cycle
9
-
10
- A foundry cycle reads its definition, sets up the work file for routing, then hands control to the sort skill which drives the forge/quench/appraise/human-appraise loop.
11
-
12
- ## Prerequisites
13
-
14
- Before running this skill, verify that the `foundry/` directory exists in the project root. If it does not exist, stop and tell the user:
15
-
16
- > Foundry is not initialized in this project. Run the `init-foundry` skill first to create the foundry/ directory structure.
17
-
18
- ## Starting a foundry cycle
19
-
20
- 1. Call `foundry_config_cycle` with the cycle ID — get the cycle definition
21
- 2. Call `foundry_config_artefact_type` with the output type ID — get the artefact type definition
22
- 3. Determine the stage route:
23
- - Use the cycle definition's `stages` field if present
24
- - Otherwise generate defaults: always `forge`, add `quench` if `foundry_config_validation` returns non-null for the type, always `appraise`
25
- - If the cycle definition has `human-appraise.enabled: true`, append `human-appraise` as the final stage
26
- - Stages should use `base:alias` format (e.g. `forge:write-haiku`, `quench:check-syllables`). If you pass bare names, the tool will auto-append the cycle ID as the alias.
27
- 4. Call `foundry_workfile_set` to configure the work file:
28
- - `key: "cycle"`, `value: <cycle-id>`
29
- - `key: "stages"`, `value: <determined stages list>`
30
- - `key: "max-iterations"`, `value: <default 3 or from cycle definition>`
31
- - If the cycle definition has a `models` map: `key: "models"`, `value: <models map>`
32
- 5. Invoke the sort skill
33
-
34
- ## Sort drives everything
35
-
36
- Once sort is invoked, it calls `foundry_sort` to determine the next stage, invokes the corresponding skill, then calls sort again. This repeats until sort returns `done` or `blocked`.
37
-
38
- The cycle skill does not contain routing logic — sort owns all of that.
39
-
40
- ## Completing a foundry cycle
41
-
42
- When sort returns `done`:
43
- - Call `foundry_artefacts_set_status` with status `"done"`
44
- - Return control to the flow skill
45
-
46
- When sort returns `blocked`:
47
- - Call `foundry_artefacts_set_status` with status `"blocked"`
48
- - Return control to the flow skill (the flow decides how to handle it)
49
-
50
- ## Human Appraise
51
-
52
- If the cycle definition has `human-appraise.enabled: true`, the human-appraise stage is included after appraise. Sort will route to it after LLM appraisers pass, or earlier if a deadlock is detected.
53
-
54
- ## Micro commits
55
-
56
- Every stage must end with a micro commit. Call `foundry_git_commit` with message format: `[<cycle-id>] <base>:<alias>: <brief description>`
57
-
58
- Examples:
59
- - `[haiku-creation] forge:write-haiku: initial draft`
60
- - `[haiku-creation] quench:check-syllables: checked syllable pattern`
61
- - `[haiku-creation] forge:write-haiku: addressed validation feedback`
62
-
63
- ## Feedback states
64
-
65
- ```
66
- open - needs generator action
67
- actioned - needs approval
68
- wont-fix - needs approval (appraisal only)
69
- approved - resolved
70
- rejected - re-opened
71
- ```
72
-
73
- Tag types: `validation` (from quench), `law:<law-id>` (from appraise), `human` (from human-appraise) — indicates the source and category of feedback.
74
-
75
- ## What you do NOT do
76
-
77
- - You do not make routing decisions — sort does that
78
- - You do not change the laws mid-cycle
79
- - You do not decide the artefact is "close enough" — it passes or it doesn't
80
- - You do not proceed past a file modification violation
81
- - You do not modify input artefacts — they are read-only