@really-knows-ai/foundry 3.0.2 → 3.1.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 (34) hide show
  1. package/README.md +8 -7
  2. package/dist/.opencode/plugins/foundry-tools/helpers.js +10 -19
  3. package/dist/.opencode/plugins/foundry-tools/refresh-agents-tool.js +88 -0
  4. package/dist/.opencode/plugins/foundry.js +2 -0
  5. package/dist/CHANGELOG.md +113 -0
  6. package/dist/README.md +8 -7
  7. package/dist/agents/foundry.md +37 -0
  8. package/dist/docs/architecture.md +6 -3
  9. package/dist/docs/concepts.md +1 -1
  10. package/dist/docs/getting-started.md +57 -135
  11. package/dist/docs/tools.md +21 -1
  12. package/dist/scripts/sort.js +1 -1
  13. package/dist/skills/add-appraiser/SKILL.md +19 -34
  14. package/dist/skills/add-artefact-type/SKILL.md +19 -22
  15. package/dist/skills/add-cycle/SKILL.md +28 -37
  16. package/dist/skills/add-extractor/SKILL.md +21 -33
  17. package/dist/skills/add-flow/SKILL.md +43 -88
  18. package/dist/skills/add-law/SKILL.md +19 -24
  19. package/dist/skills/add-memory-edge-type/SKILL.md +11 -17
  20. package/dist/skills/add-memory-entity-type/SKILL.md +9 -16
  21. package/dist/skills/change-embedding-model/SKILL.md +6 -8
  22. package/dist/skills/drop-memory-edge-type/SKILL.md +6 -8
  23. package/dist/skills/drop-memory-entity-type/SKILL.md +6 -8
  24. package/dist/skills/dry-run/SKILL.md +11 -28
  25. package/dist/skills/flow/SKILL.md +1 -1
  26. package/dist/skills/init-foundry/SKILL.md +30 -25
  27. package/dist/skills/init-memory/SKILL.md +11 -22
  28. package/dist/skills/list-agents/SKILL.md +1 -1
  29. package/dist/skills/refresh-agents/SKILL.md +4 -26
  30. package/dist/skills/rename-memory-edge-type/SKILL.md +6 -8
  31. package/dist/skills/rename-memory-entity-type/SKILL.md +6 -8
  32. package/dist/skills/reset-memory/SKILL.md +10 -16
  33. package/dist/skills/upgrade-foundry/SKILL.md +1 -1
  34. package/package.json +2 -1
@@ -26,24 +26,16 @@ OpenCode resolves the package itself — `npm install` is **not** required. Rest
26
26
  Optionally, if you want the package available to your project's local node_modules (for editor tooling or scripts), run:
27
27
 
28
28
  ```sh
29
- npm install --save-dev @really-knows-ai/foundry
29
+ pnpm add -D @really-knows-ai/foundry
30
30
  ```
31
31
 
32
32
  ## Initialise
33
33
 
34
- In your project, invoke the `init-foundry` skill. It:
34
+ Run the `init-foundry` skill.
35
35
 
36
- 1. Creates the `foundry/` directory structure:
37
- ```
38
- foundry/
39
- artefacts/.gitkeep
40
- flows/.gitkeep
41
- cycles/.gitkeep
42
- laws/.gitkeep
43
- appraisers/.gitkeep
44
- ```
45
- 2. Runs `refresh-agents` to generate `.opencode/agents/foundry-*.md` — one per available model — so cycles can dispatch to specific models later.
46
- 3. Commits the scaffolding.
36
+ Initialisation installs the user-facing `Foundry` agent at `.opencode/agents/foundry.md` and generates model-routing `foundry-*` stage agents for any models available in your OpenCode session.
37
+
38
+ Restart OpenCode after initialisation. Then switch to the **Foundry** agent before authoring flows. The Foundry agent understands Foundry's authoring workflow and handles dependent setup such as artefact types, laws, validators, appraisers, cycles, and config branches.
47
39
 
48
40
  The `.foundry/` runtime directory (holding `.secret` for stage tokens) is created automatically on first plugin boot and added to `.gitignore`.
49
41
 
@@ -51,134 +43,67 @@ The `.foundry/` runtime directory (holding `.secret` for stage tokens) is create
51
43
 
52
44
  ## Author the configuration
53
45
 
54
- 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.
55
-
56
- Before using any schema-writing skill, open a config branch. All schema-mutation tools (`foundry_config_create_*`, `foundry_memory_create_*`, `foundry_extractor_create`, the memory admin family) refuse off `main` and off flow branches:
57
-
58
- ```text
59
- foundry_git_branch({ kind: "config", description: "<short-name>" })
60
- ```
61
-
62
- This typically puts you on `config/<short-name>` from `main`. Make all the
63
- edits below on this branch, then `foundry_git_finish({ message: "...",
64
- baseBranch: "main", confirm: true })` squashes the work back to
65
- `main` in one commit. To trial the in-progress edits against a real
66
- flow before merging, see "Trial config edits with dry-run" below.
67
-
68
- ### 1. Define an artefact type
69
-
70
- Run `add-artefact-type`. It walks you through:
71
-
72
- - `id` (lowercase, hyphenated), `name`, prose description.
73
- - `file-patterns` — glob patterns describing which files this type owns. Forge's write scope is exactly these patterns; anything written outside them violates the cycle. The skill refuses patterns that overlap with existing types.
74
- - Appraiser config — how many appraisers evaluate this type and which personalities are allowed.
75
- - Optional `laws.md` — type-specific criteria, with optional validators for deterministic checks.
76
-
77
- Produces `foundry/artefacts/<id>/definition.md` (+ optional `laws.md`).
78
-
79
- ### 2. Write laws
80
-
81
- Laws are subjective pass/fail criteria evaluated by appraisers. Two scopes:
82
-
83
- - **Global** — `foundry/laws/*.md`. All files are concatenated and apply to every artefact.
84
- - **Type-specific** — `foundry/artefacts/<type>/laws.md`.
85
-
86
- 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.
87
-
88
- ### 3. Create appraisers
89
-
90
- 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`).
46
+ Foundry's configuration is five things: artefact types, laws, appraisers, cycles, and flows. The Foundry agent handles branch setup, conflict checking, scaffolding, and validation for normal authoring.
91
47
 
92
- ### 4. Define a cycle
48
+ ### Author through the Foundry agent
93
49
 
94
- Run `add-cycle`. A cycle produces one artefact type and declares:
50
+ Ask the Foundry agent to author or modify any part of the configuration. For example:
95
51
 
96
- - `output-type` — the artefact type (must already exist).
97
- - `inputs` — a contract (`any-of` or `all-of`) over other types. Empty for starting cycles.
98
- - `targets` — the cycle(s) that may run after this one. Empty for terminal cycles.
99
- - `human-appraise` / `deadlock-appraise` / `deadlock-iterations` — human-gate config.
100
- - `models` — optional per-stage model overrides.
52
+ > Add a `haiku` artefact type with a `poetic-form` appraiser.
101
53
 
102
- Example:
54
+ > Add a law that requires at least one sensory metaphor in every haiku.
103
55
 
104
- ```markdown
105
- ---
106
- id: haiku-creation
107
- name: Haiku Creation
108
- output-type: haiku
109
- inputs:
110
- type: any-of
111
- artefacts:
112
- - petition
113
- targets: []
114
- human-appraise: false
115
- deadlock-appraise: true
116
- deadlock-iterations: 5
117
- models:
118
- appraise: openai/gpt-5
119
- ---
56
+ > Create a cycle that produces haikus from petitions.
120
57
 
121
- # Haiku Creation
58
+ > Set up a `make-haiku` flow starting from `haiku-ideation`.
122
59
 
123
- Writes a haiku satisfying the petition produced by haiku-ideation.
124
- ```
60
+ The agent opens a config branch, creates the files, validates them, and commits the result. To trial in-progress edits against a real flow before merging, see "Trial config edits with dry-run" below.
125
61
 
126
- The skill validates that every input type can be produced by some cycle in the flow and that targets are reachable.
62
+ ### Configuration reference
127
63
 
128
- ### 5. Define a flow
64
+ These are the five pieces of a Foundry configuration, in dependency order:
129
65
 
130
- Run `add-flow`. A flow groups cycles and declares starting points:
66
+ 1. **Artefact types** — define the output of each cycle. Each type has an `id`, `name`, prose description, `file-patterns` (forge's write scope), appraiser config, and optional type-specific `laws.md`. Produces `foundry/artefacts/<id>/definition.md`.
131
67
 
132
- ```markdown
133
- ---
134
- id: make-haiku
135
- name: Make a Haiku
136
- starting-cycles:
137
- - haiku-ideation
138
- ---
68
+ 2. **Laws** — subjective pass/fail criteria evaluated by appraisers. Two scopes: global (`foundry/laws/*.md`, concatenated for every artefact) and type-specific (`foundry/artefacts/<type>/laws.md`). Each law is a `## heading` (its identifier, referenced as `law:<id>` in feedback) with a description, passing criteria, and failing criteria.
139
69
 
140
- # Make a Haiku
141
-
142
- End-to-end flow: petition → haiku, with a human quality gate.
143
-
144
- ## Cycles
145
-
146
- - haiku-ideation
147
- - haiku-creation
148
- ```
70
+ 3. **Appraisers** — independent evaluators with named personalities. Each may override the cycle-level appraise model via a `model` field. Artefact types pick which appraisers may evaluate them (`appraisers.allowed`).
149
71
 
150
- Routing between cycles is owned by individual cycles via their `targets`, not by the flow.
72
+ 4. **Cycles** produce one artefact type and declare `output-type`, `inputs` (a contract over other types), `targets` (reachable downstream cycles), human-gate config, and optional per-stage model overrides. Example:
151
73
 
152
- ### 6. Validate before writing (optional)
74
+ ```markdown
75
+ ---
76
+ id: haiku-creation
77
+ name: Haiku Creation
78
+ output-type: haiku
79
+ inputs:
80
+ type: any-of
81
+ artefacts:
82
+ - petition
83
+ targets: []
84
+ human-appraise: false
85
+ deadlock-appraise: true
86
+ deadlock-iterations: 5
87
+ models:
88
+ appraise: openai/gpt-5
89
+ ---
90
+ ```
153
91
 
154
- Each `add-*` skill writes and commits in one step. When you want to validate a draft body without committing it, call the matching validator first:
92
+ 5. **Flows** group cycles and declare starting points. Routing between cycles is owned by individual cycles via their `targets`.
155
93
 
156
- ```text
157
- foundry_config_validate_artefact_type({ name, body })
158
- foundry_config_validate_law({ name, body })
159
- foundry_config_validate_appraiser({ name, body })
160
- foundry_config_validate_cycle({ name, body })
161
- foundry_config_validate_flow({ name, body })
162
- ```
94
+ ### Hand-authoring configuration files
163
95
 
164
- Validators return `{ok: true}` on success or
165
- `{ok: false, errors: [...]}` on a parse / schema / overlap problem; nothing
166
- is written either way. Once the validator is happy, call the
167
- matching `_create_*` tool to commit it.
96
+ Users who prefer to write configuration files by hand open a config branch first. The Foundry agent handles this automatically; hand-authoring is for users who choose to work outside the agent. See [`docs/tools.md`](./tools.md) for the full list of schema-mutation and validation tools.
168
97
 
169
98
  ---
170
99
 
171
100
  ## Run the flow
172
101
 
173
- Tell OpenCode something like:
174
-
175
- > Run the `make-haiku` flow to write a haiku about autumn rain.
176
-
177
- The `flow` skill will:
102
+ To run a flow, ask the Foundry agent with your goal as the input (e.g. "Run the make-haiku flow to write a haiku about autumn rain"). The Foundry agent dispatches the `flow` skill, which:
178
103
 
179
- 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.
180
- 2. Create a work branch and scaffold `WORK.md` with the goal.
181
- 3. Hand off to `orchestrate`, which drives the cycle:
104
+ 1. Checks prerequisites and picks 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.
105
+ 2. Creates a work branch and scaffolds `WORK.md` with the goal.
106
+ 3. Hands off to `orchestrate`, which drives the cycle:
182
107
  - **forge** writes the artefact.
183
108
  - **quench** runs CLI validators (if configured).
184
109
  - **appraise** dispatches parallel appraiser sub-agents and consolidates their `law:<id>` feedback.
@@ -197,19 +122,14 @@ When you've changed a law, an appraiser, or a cycle on a `config/*`
197
122
  branch and want to see how the change behaves end-to-end before
198
123
  merging, use dry-run mode.
199
124
 
200
- ```text
201
- # starting on a config/* branch with the in-progress edit
202
- foundry_git_branch({ kind: "dry-run", flowId: "make-haiku",
203
- description: "stricter-imagery-law" })
204
- # now on dry-run/<parent>/make-haiku-stricter-imagery-law
205
-
206
- # run the flow as you normally would
207
- # every foundry_* call is traced to .foundry/trace/<branch>.jsonl
208
-
209
- foundry_git_finish({ message: "trial: stricter imagery law", confirm: true })
210
- # writes .snapshots/<run-id>/{README.md, work/WORK*, diff.patch, trace.jsonl}
211
- # on the parent config/* working tree and force-deletes the dry-run branch
212
- ```
125
+ Starting on the `config/*` branch with the in-progress edit, ask the
126
+ Foundry agent to trial the change with dry-run mode for the target flow
127
+ and a short purpose such as `stricter-imagery-law`. The agent creates a
128
+ `dry-run/<parent>/<flow>-<purpose>` branch, runs the flow, records every
129
+ Foundry tool call in `.foundry/trace/<branch>.jsonl`, then finishes the
130
+ dry-run with a findings summary. Finishing writes
131
+ `.snapshots/<run-id>/{README.md, work/WORK*, diff.patch, trace.jsonl}`
132
+ on the parent `config/*` working tree and deletes the dry-run branch.
213
133
 
214
134
  Inspect the snapshot at `.snapshots/<run-id>/`, decide whether to keep
215
135
  the config edit, and either commit/merge from the parent `config/*`
@@ -263,11 +183,11 @@ Foundry ships a typed, graph-shaped memory store that persists across cycles. Us
263
183
 
264
184
  ### Initialise
265
185
 
266
- Memory init and vocabulary edits are schema mutations, so they run
267
- on a config branch open one first if you are not already on it
268
- (`foundry_git_branch({ kind: "config", description: "memory-setup" })`).
186
+ Memory init and vocabulary edits are schema mutations, so they run on a
187
+ config branch. The Foundry agent opens a suitable config branch when it
188
+ is safe; if you are working by hand, open one first.
269
189
 
270
- Run the `init-memory` skill. It asks whether to enable embeddings (default: yes, targeting local Ollama `nomic-embed-text` on `http://localhost:11434/v1`) and then invokes `foundry_memory_init`, which deterministically:
190
+ To enable memory, ask the Foundry agent to add flow memory. It asks whether to enable embeddings (default: yes, targeting local Ollama `nomic-embed-text` on `http://localhost:11434/v1`) and then initialises memory, which deterministically:
271
191
 
272
192
  - creates `foundry/memory/entities/` and `edges/` (each with `.gitkeep`) plus the top-level sibling `foundry-memory/relations/` for committed row data,
273
193
  - writes `foundry/memory/config.md` (frontmatter driven by your embeddings choice) and `foundry/memory/schema.json`,
@@ -278,6 +198,8 @@ Run the `init-memory` skill. It asks whether to enable embeddings (default: yes,
278
198
 
279
199
  Two concepts: **entity types** (things memory knows about, e.g. `class`, `method`) and **edge types** (directed relationships, e.g. `calls`, `references`).
280
200
 
201
+ The Foundry agent handles vocabulary setup as part of the normal authoring path — declare what you need in prose and it creates the types. For reference or hand-authoring, the underlying skills are:
202
+
281
203
  - `add-memory-entity-type` — name + prose body (naming convention, what `value` should contain, likely related edges). The body is injected into the prompt of every cycle that reads/writes this type, so write it for an LLM reader.
282
204
  - `add-memory-edge-type` — name, `sources` (list of entity types or `any`), `targets` (list or `any`), and a prose body that describes **when** the edge holds and **what it does not cover**.
283
205
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Generated from the v3.0.x public plugin API. The authoritative tool set is
4
4
  enforced by `tests/plugin/tool-registration.test.js` — if that snapshot
5
- drifts, this doc must be updated. Total: **65 tools**.
5
+ drifts, this doc must be updated. Total: **66 tools**.
6
6
 
7
7
  All tools accept arguments as a JSON object and return JSON-stringified
8
8
  results. Errors are returned as a stringified `{error: "..."}` object (not
@@ -118,6 +118,9 @@ state machine, see [`docs/concepts.md`](./concepts.md) and
118
118
  - [`foundry_attestation_verify`](#foundry_attestation_verify)
119
119
  - [`foundry_attest`](#foundry_attest)
120
120
 
121
+ **Maintenance**
122
+ - [`foundry_refresh_agents`](#foundry_refresh_agents)
123
+
121
124
  **Memory — Data**
122
125
  - [`foundry_memory_put`](#foundry_memory_put)
123
126
  - [`foundry_memory_relate`](#foundry_memory_relate)
@@ -782,6 +785,23 @@ success. `{ error: ... }` when verification fails.
782
785
 
783
786
  ---
784
787
 
788
+ ## Maintenance
789
+
790
+ ### `foundry_refresh_agents`
791
+
792
+ > Regenerate `.opencode/agents/foundry-*.md` stage-agent files from the currently available models.
793
+
794
+ **Args:** none.
795
+
796
+ **Returns:** `{ ok: true, count: <n> }` on success. `{ ok: false, error: "..." }` on failure.
797
+
798
+ **Failure modes:**
799
+ - `opencode models` exits non-zero or produces no output → returns an error describing the issue.
800
+
801
+ **Side effects:** creates `.opencode/agents/` if absent; deletes stale generated `.opencode/agents/foundry-*.md` stage agents; writes one fresh stage-agent file per model returned by `opencode models`.
802
+
803
+ ---
804
+
785
805
  ## Config — Schema mutation
786
806
 
787
807
  These tools each write one named config artefact and produce a single
@@ -156,7 +156,7 @@ function resolveModel(route, frontmatter, agentsDir, io) {
156
156
  if (!io.exists(agentPath)) {
157
157
  return {
158
158
  error: `Missing required subagent: ${model}.md is not present in ${agentsDir}/. `
159
- + `Run the refresh-agents skill to regenerate agent files, then restart.`,
159
+ + `Call foundry_refresh_agents() to regenerate agent files, then restart.`,
160
160
  };
161
161
  }
162
162
  return model;
@@ -8,34 +8,29 @@ description: Creates a new appraiser personality, checking for semantic overlap
8
8
 
9
9
  You help the user create a new appraiser personality. You ensure it's genuinely distinct from existing appraisers and scaffold the definition file.
10
10
 
11
- ## Prerequisites
11
+ ## Foundry Agent Preflight
12
12
 
13
- Before running this skill, verify all three of the following:
13
+ If you are clearly operating as the Foundry agent, continue.
14
14
 
15
- 1. The `foundry/` directory exists in the project root. If it does not
16
- exist, stop and tell the user:
15
+ If you are not clearly operating as the Foundry agent, pause and tell the user:
17
16
 
18
- > Foundry is not initialized in this project. Run the
19
- > `init-foundry` skill first to create the foundry/ directory
20
- > structure.
17
+ > This work is best handled by the Foundry agent. Restart OpenCode if you have just initialised Foundry, switch to the **Foundry** agent, and continue this request there.
21
18
 
22
- 2. The current git branch is a `config/*` branch. Run
23
- `git rev-parse --abbrev-ref HEAD` and confirm it matches
24
- `config/<description>`.
19
+ This is an advisory guard. Continue only when the active instructions make it clear you are the Foundry agent or the user explicitly asks to proceed here.
25
20
 
26
- 3. If the branch does not start with `config/`, instruct the user to
27
- create one before continuing:
21
+ ## Config Branch Handling
28
22
 
29
- > Foundry configuration changes must be made on a config/* branch.
30
- > From a clean main branch, call:
31
- >
32
- > `foundry_git_branch({ kind: "config", description: "<short-name>" })`
33
- >
34
- > Then re-run this skill.
23
+ Before writing Foundry configuration:
35
24
 
36
- If the user is on a `dry-run/*/*` branch, they must finish
37
- that dry-run first (`foundry_git_finish({ message, confirm: true })`)
38
- before re-running this skill on the parent `config/*`.
25
+ - Confirm `foundry/` exists. If it is missing, initialise Foundry first when that serves the user's goal.
26
+ - Check the current branch.
27
+ - On `main` or another clean non-work branch, create a `config/<short-description>` branch internally.
28
+ - On `config/*`, continue on the current branch.
29
+ - On `work/*`, stop and explain that active flow work must be finished before configuration changes.
30
+ - On `dry-run/*/*`, stop and explain that the dry run must be finished before configuration changes.
31
+ - If unrelated uncommitted changes could be affected by branching or writing files, ask before proceeding.
32
+
33
+ Do not tell the user to call branch tools directly.
39
34
 
40
35
  ## Protocol
41
36
 
@@ -118,26 +113,16 @@ Call `foundry_config_create_appraiser({ name: "<id>", body: "<full markdown>" })
118
113
  - writes `foundry/appraisers/<id>.md`;
119
114
  - produces one git commit on the current `config/*` branch.
120
115
 
121
- If the tool returns `{ ok: false, errors }` because the target file already exists, the user should edit the file by hand on this `config/*` branch `foundry_config_create_appraiser` does not support updates.
116
+ If the tool returns `{ ok: false, errors }` because the target file already exists, read the existing file, incorporate the user's requested changes into the current body, propose the merged result for review, then write and commit the updated file.
122
117
 
123
118
  Show the user the resulting commit hash from the response.
124
119
 
125
120
  ### 8. Mention artefact type configuration
126
121
 
127
- After creating the appraiser, remind the user:
128
-
129
- > Appraiser `<id>` is now available. To use it for a specific artefact type, add it to the `appraisers.allowed` list in that type's `definition.md` frontmatter:
130
- >
131
- > ```yaml
132
- > appraisers:
133
- > count: 3
134
- > allowed: [<id>, ...]
135
- > ```
136
- >
137
- > If no `allowed` list is specified, all available appraisers (including this new one) are eligible.
122
+ After creating the appraiser, offer to connect it to relevant artefact-type configuration when doing so supports the user's stated goal. If the user confirms, update the artefact type's `appraisers.allowed` list on the same config branch.
138
123
 
139
124
  ## What you do NOT do
140
125
 
141
126
  - You do not skip the semantic overlap check
142
- - You do not modify artefact type definitions that is the user's choice
127
+ - You do not modify artefact type definitions without the user's confirmation
143
128
  - You do not create appraisers with duplicate ids
@@ -8,34 +8,29 @@ description: Creates a new artefact type, checking for conflicts with existing t
8
8
 
9
9
  You help the user create a new artefact type. You ensure it avoids conflicts with existing types, scaffold the directory structure, and walk the user through defining laws and their optional validators.
10
10
 
11
- ## Prerequisites
11
+ ## Foundry Agent Preflight
12
12
 
13
- Before running this skill, verify all three of the following:
13
+ If you are clearly operating as the Foundry agent, continue.
14
14
 
15
- 1. The `foundry/` directory exists in the project root. If it does not
16
- exist, stop and tell the user:
15
+ If you are not clearly operating as the Foundry agent, pause and tell the user:
17
16
 
18
- > Foundry is not initialized in this project. Run the
19
- > `init-foundry` skill first to create the foundry/ directory
20
- > structure.
17
+ > This work is best handled by the Foundry agent. Restart OpenCode if you have just initialised Foundry, switch to the **Foundry** agent, and continue this request there.
21
18
 
22
- 2. The current git branch is a `config/*` branch. Run
23
- `git rev-parse --abbrev-ref HEAD` and confirm it matches
24
- `config/<description>`.
19
+ This is an advisory guard. Continue only when the active instructions make it clear you are the Foundry agent or the user explicitly asks to proceed here.
25
20
 
26
- 3. If the branch does not start with `config/`, instruct the user to
27
- create one before continuing:
21
+ ## Config Branch Handling
28
22
 
29
- > Foundry configuration changes must be made on a config/* branch.
30
- > From a clean main branch, call:
31
- >
32
- > `foundry_git_branch({ kind: "config", description: "<short-name>" })`
33
- >
34
- > Then re-run this skill.
23
+ Before writing Foundry configuration:
35
24
 
36
- If the user is on a `dry-run/*/*` branch, they must finish
37
- that dry-run first (`foundry_git_finish({ message, confirm: true })`)
38
- before re-running this skill on the parent `config/*`.
25
+ - Confirm `foundry/` exists. If it is missing, initialise Foundry first when that serves the user's goal.
26
+ - Check the current branch.
27
+ - On `main` or another clean non-work branch, create a `config/<short-description>` branch internally.
28
+ - On `config/*`, continue on the current branch.
29
+ - On `work/*`, stop and explain that active flow work must be finished before configuration changes.
30
+ - On `dry-run/*/*`, stop and explain that the dry run must be finished before configuration changes.
31
+ - If unrelated uncommitted changes could be affected by branching or writing files, ask before proceeding.
32
+
33
+ Do not tell the user to call branch tools directly.
39
34
 
40
35
  ## Protocol
41
36
 
@@ -105,6 +100,8 @@ in the `## Definition` prose.
105
100
 
106
101
  Ask: does this capture the artefact type correctly?
107
102
 
103
+ When laws or validators are clearly part of the requested artefact type, draft them during artefact-type creation. Use the validator contract from `add-law` and prefer established packages installed with the project package manager.
104
+
108
105
  ### 5. Laws (optional)
109
106
 
110
107
  Ask:
@@ -173,7 +170,7 @@ Call `foundry_config_create_artefact_type({ name: "<id>", body: "<full markdown>
173
170
  - writes `foundry/artefacts/<id>/definition.md`;
174
171
  - produces one git commit on the current `config/*` branch.
175
172
 
176
- If the tool returns `{ ok: false, errors }` because the target file already exists, the user should edit the file by hand on this `config/*` branch `foundry_config_create_artefact_type` does not support updates.
173
+ If the tool returns `{ ok: false, errors }` because the target file already exists, read the existing file, incorporate the user's requested changes into the current body, propose the merged result for review, then write and commit the updated file.
177
174
 
178
175
  Show the user the resulting commit hash from the response.
179
176
 
@@ -8,34 +8,29 @@ description: Creates a new foundry cycle within a foundry flow, specifying the o
8
8
 
9
9
  You help the user create a new foundry cycle and add it to an existing foundry flow. A foundry cycle produces one artefact type (read-write), declares its input contract, targets the next cycle(s), and optionally enables human-appraise as a quality gate.
10
10
 
11
- ## Prerequisites
11
+ ## Foundry Agent Preflight
12
12
 
13
- Before running this skill, verify all three of the following:
13
+ If you are clearly operating as the Foundry agent, continue.
14
14
 
15
- 1. The `foundry/` directory exists in the project root. If it does not
16
- exist, stop and tell the user:
15
+ If you are not clearly operating as the Foundry agent, pause and tell the user:
17
16
 
18
- > Foundry is not initialized in this project. Run the
19
- > `init-foundry` skill first to create the foundry/ directory
20
- > structure.
17
+ > This work is best handled by the Foundry agent. Restart OpenCode if you have just initialised Foundry, switch to the **Foundry** agent, and continue this request there.
21
18
 
22
- 2. The current git branch is a `config/*` branch. Run
23
- `git rev-parse --abbrev-ref HEAD` and confirm it matches
24
- `config/<description>`.
19
+ This is an advisory guard. Continue only when the active instructions make it clear you are the Foundry agent or the user explicitly asks to proceed here.
25
20
 
26
- 3. If the branch does not start with `config/`, instruct the user to
27
- create one before continuing:
21
+ ## Config Branch Handling
28
22
 
29
- > Foundry configuration changes must be made on a config/* branch.
30
- > From a clean main branch, call:
31
- >
32
- > `foundry_git_branch({ kind: "config", description: "<short-name>" })`
33
- >
34
- > Then re-run this skill.
23
+ Before writing Foundry configuration:
35
24
 
36
- If the user is on a `dry-run/*/*` branch, they must finish
37
- that dry-run first (`foundry_git_finish({ message, confirm: true })`)
38
- before re-running this skill on the parent `config/*`.
25
+ - Confirm `foundry/` exists. If it is missing, initialise Foundry first when that serves the user's goal.
26
+ - Check the current branch.
27
+ - On `main` or another clean non-work branch, create a `config/<short-description>` branch internally.
28
+ - On `config/*`, continue on the current branch.
29
+ - On `work/*`, stop and explain that active flow work must be finished before configuration changes.
30
+ - On `dry-run/*/*`, stop and explain that the dry run must be finished before configuration changes.
31
+ - If unrelated uncommitted changes could be affected by branching or writing files, ask before proceeding.
32
+
33
+ Do not tell the user to call branch tools directly.
39
34
 
40
35
  ## Protocol
41
36
 
@@ -43,7 +38,7 @@ Before running this skill, verify all three of the following:
43
38
 
44
39
  From the user's prompt, identify which foundry flow this foundry cycle belongs to. If not specified, list available flows from `foundry/flows/` and ask.
45
40
 
46
- Verify the flow exists. If it doesn't, tell the user and ask if they want to create the foundry flow first (separate skill).
41
+ If the parent flow or required artefact type is missing and the user's goal clearly requires it, create that dependency first. If multiple designs are plausible, ask one focused question before creating it.
47
42
 
48
43
  ### 2. Gather basics
49
44
 
@@ -64,7 +59,7 @@ If any of these are missing, ask.
64
59
 
65
60
  For each stage in the cycle (forge, quench, appraise), ask the user if they want to specify a model:
66
61
 
67
- > Each stage can optionally run on a specific model for model diversity. Available models are listed as `foundry-*` agent files in `.opencode/agents/`. Run the `list-agents` skill to see them.
62
+ > Each stage can optionally run on a specific model for model diversity. Available session models are listed in your session configuration.
68
63
  >
69
64
  > For each stage, specify a model ID (e.g., `openai/gpt-4o`) or leave blank to use the session's default model:
70
65
  > - forge: ___
@@ -73,15 +68,17 @@ For each stage in the cycle (forge, quench, appraise), ask the user if they want
73
68
 
74
69
  Only stages with an explicitly specified model are included in the `models` frontmatter map.
75
70
 
71
+ If the user has no preference, omit the `models` map and use the session defaults.
72
+
76
73
  ### 4. Configure human appraise
77
74
 
78
75
  Ask the user:
79
76
 
80
- > Human-appraise has two independent knobs:
77
+ > Human-appraise has two independent knobs and one dependent setting:
81
78
  >
82
79
  > 1. `human-appraise` — should a human review the artefact every iteration? Default: no.
83
80
  > 2. `deadlock-appraise` — should a human be pulled in only when LLM appraisers deadlock? Default: yes.
84
- > 3. If either is enabled, `deadlock-iterations` sets the deadlock threshold (default: 5).
81
+ > 3. `deadlock-iterations` the deadlock threshold (default: 5). Only applies when `deadlock-appraise` or `human-appraise` is enabled.
85
82
  >
86
83
  > - human-appraise: yes/no (default no)
87
84
  > - deadlock-appraise: yes/no (default yes)
@@ -89,9 +86,9 @@ Ask the user:
89
86
 
90
87
  ### 5. Validate artefact types
91
88
 
92
- For `output-type` and each entry in `inputs`:
93
- - Verify the artefact type exists in `foundry/artefacts/<type>/definition.md`
94
- - If it doesn't, tell the user and ask if they want to create it first (separate skill)
89
+ For `output-type` and each entry in `inputs`, verify the artefact type exists in `foundry/artefacts/<type>/definition.md`.
90
+
91
+ If a required artefact type is missing and the user's goal clearly requires it, create that dependency first. If the file pattern or type design cannot be inferred safely, ask one focused question before creating it.
95
92
 
96
93
  ### 6. Validate against the foundry flow
97
94
 
@@ -175,7 +172,7 @@ Call `foundry_config_create_cycle({ name: "<id>", body: "<full markdown>" })`. T
175
172
  - writes `foundry/cycles/<id>.md`;
176
173
  - produces one git commit on the current `config/*` branch.
177
174
 
178
- If the tool returns `{ ok: false, errors }` because the target file already exists, the user should edit the file by hand on this `config/*` branch — `foundry_config_create_cycle` does not support updates.
175
+ If the tool returns `{ ok: false, errors }` because the target file already exists, read the existing cycle file, apply any necessary updates, write it back, and commit on this `config/*` branch.
179
176
 
180
177
  Show the user the resulting commit hash from the response.
181
178
 
@@ -183,12 +180,7 @@ Show the user the resulting commit hash from the response.
183
180
 
184
181
  `foundry_config_create_cycle` writes the cycle file only. The cycle still needs to appear in the parent flow's `## Cycles` list.
185
182
 
186
- Edit `foundry/flows/<flow-id>.md` by hand on this same `config/*` branch using the `Edit` tool. Add the new cycle id under `## Cycles` (if not already present). Commit that edit by hand as a separate microcommit, e.g.:
187
-
188
- ```
189
- git add foundry/flows/<flow-id>.md
190
- git commit -m "config(flow): add <cycle-id> to <flow-id>"
191
- ```
183
+ Read the existing flow file from `foundry/flows/<flow-id>.md`. Add the new cycle id under `## Cycles` if it is not already present. Write the updated file back and commit on this same `config/*` branch.
192
184
 
193
185
  ### 14. Confirm
194
186
 
@@ -198,5 +190,4 @@ Show the user the cycle file, the updated flow file, and both commit hashes.
198
190
 
199
191
  - You do not create foundry cycles that output an artefact type already produced by another foundry cycle in the same foundry flow
200
192
  - You do not skip artefact type validation
201
- - You do not create artefact types that is a separate skill
202
- - You do not create foundry flows — that is a separate skill
193
+ - You do not create dependencies (artefact types, flows) unless the user's stated goal clearly requires them; ask one focused question when multiple designs are plausible