@really-knows-ai/foundry 3.0.1 → 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 (36) hide show
  1. package/README.md +8 -7
  2. package/dist/.opencode/plugins/foundry-tools/config-law-tools.js +53 -69
  3. package/dist/.opencode/plugins/foundry-tools/helpers.js +10 -19
  4. package/dist/.opencode/plugins/foundry-tools/refresh-agents-tool.js +88 -0
  5. package/dist/.opencode/plugins/foundry-tools/validate-tools.js +37 -29
  6. package/dist/.opencode/plugins/foundry.js +2 -0
  7. package/dist/CHANGELOG.md +182 -0
  8. package/dist/README.md +8 -7
  9. package/dist/agents/foundry.md +37 -0
  10. package/dist/docs/architecture.md +6 -3
  11. package/dist/docs/concepts.md +1 -1
  12. package/dist/docs/getting-started.md +57 -135
  13. package/dist/docs/tools.md +21 -1
  14. package/dist/scripts/sort.js +1 -1
  15. package/dist/skills/add-appraiser/SKILL.md +19 -34
  16. package/dist/skills/add-artefact-type/SKILL.md +47 -43
  17. package/dist/skills/add-cycle/SKILL.md +28 -37
  18. package/dist/skills/add-extractor/SKILL.md +21 -33
  19. package/dist/skills/add-flow/SKILL.md +43 -88
  20. package/dist/skills/add-law/SKILL.md +132 -26
  21. package/dist/skills/add-memory-edge-type/SKILL.md +11 -17
  22. package/dist/skills/add-memory-entity-type/SKILL.md +9 -16
  23. package/dist/skills/change-embedding-model/SKILL.md +6 -8
  24. package/dist/skills/drop-memory-edge-type/SKILL.md +6 -8
  25. package/dist/skills/drop-memory-entity-type/SKILL.md +6 -8
  26. package/dist/skills/dry-run/SKILL.md +11 -28
  27. package/dist/skills/flow/SKILL.md +1 -1
  28. package/dist/skills/init-foundry/SKILL.md +47 -27
  29. package/dist/skills/init-memory/SKILL.md +11 -22
  30. package/dist/skills/list-agents/SKILL.md +1 -1
  31. package/dist/skills/refresh-agents/SKILL.md +4 -26
  32. package/dist/skills/rename-memory-edge-type/SKILL.md +6 -8
  33. package/dist/skills/rename-memory-entity-type/SKILL.md +6 -8
  34. package/dist/skills/reset-memory/SKILL.md +10 -16
  35. package/dist/skills/upgrade-foundry/SKILL.md +1 -1
  36. package/package.json +2 -1
package/dist/CHANGELOG.md CHANGED
@@ -1,5 +1,187 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.1.0] - 2026-05-11
4
+
5
+ The Foundry guide agent release. Foundry now ships a user-facing agent that
6
+ routes configuration authoring through Foundry concepts — users ask the Foundry
7
+ agent for outcomes, and the agent composes dependent work internally rather than
8
+ handing users a chain of individual tools and skills.
9
+
10
+ ### Added
11
+
12
+ - **Foundry guide agent** (`src/agents/foundry.md`). A user-facing agent with
13
+ identity marker *"You are the Foundry agent"* that maps user requests to
14
+ Foundry concepts, routes through the standard config-branch workflow, and
15
+ delegates to authoring skills internally.
16
+ - **`foundry_refresh_agents` tool.** Deterministic stage-agent generation: runs
17
+ `opencode models`, deletes stale `.opencode/agents/foundry-*.md` files, and
18
+ writes fresh agent files — one per available model. Replaces the prior
19
+ skill-only protocol where the LLM had to implement the logic with shell
20
+ commands.
21
+ - **`init-foundry` installs the guide agent.** Step 5 creates
22
+ `.opencode/agents/foundry.md` (preferring `dist/agents/foundry.md`, falling
23
+ back to `src/agents/foundry.md`), then instructs the user to restart OpenCode
24
+ and switch to the Foundry agent.
25
+ - **Comprehensive guidance audit tests.** `tests/skills/foundry-guidance-audit.test.js`
26
+ (357 lines) and `tests/skills/authoring-guidance.test.js` (45 lines) enforce
27
+ that skills avoid dead-end delegation patterns, route through the Foundry
28
+ agent, keep internal tool-call syntax out of normal user guidance, and handle
29
+ config branches and dependencies internally.
30
+ - **Packaging test** (`tests/plugin/packaging.test.js`). Verifies the published
31
+ package ships `dist/agents/` so `init-foundry` can locate the guide agent
32
+ template in a packaged install.
33
+
34
+ ### Changed
35
+
36
+ - **Authoring skills reworked around the Foundry agent.** `add-flow`,
37
+ `add-cycle`, `add-artefact-type`, `add-law`, and `add-appraiser` now include a
38
+ `## Foundry Agent Preflight` section; and frame user requests as Foundry
39
+ outcomes, compose missing dependencies internally in validation order, and
40
+ hide internal tool-call syntax from normal user guidance (`foundry_git_branch`,
41
+ `foundry_git_finish`, `foundry_config_create_*`).
42
+ - **Memory/config skills handle branches and dependencies internally.**
43
+ `init-memory`, `reset-memory`, `add-memory-entity-type`, `add-memory-edge-type`,
44
+ `add-extractor`, and the `rename-memory-*` / `drop-memory-*` /
45
+ `change-embedding-model` skills no longer tell the user to create config
46
+ branches or run prerequisite skills. All use *"move to a suitable `config/*`
47
+ branch internally when the current branch is safe"* with `work/*` /
48
+ `dry-run/*/*` / uncommitted-change guards.
49
+ - **`add-extractor` composes cycle wiring internally.** The skill updates
50
+ relevant cycle definitions rather than presenting manual frontmatter editing
51
+ as the normal outcome.
52
+ - **`add-cycle` hides generated stage-agent files.** Model selection guidance
53
+ now references *"Available session models are listed in your session
54
+ configuration"* instead of exposing `.opencode/agents/foundry-*.md`.
55
+ - **Existing-file recovery keeps the agent in the loop.** When
56
+ `foundry_config_create_*` returns `{ ok: false }` because the target file
57
+ already exists, `add-artefact-type`, `add-appraiser`, `add-law`, and
58
+ `add-cycle` now read the existing content, incorporate the user's requested
59
+ changes, propose the merged result, and commit — rather than telling the user
60
+ to *"edit by hand."*
61
+ - **Bootstrap context** (`helpers.js`) presents capabilities as Foundry
62
+ outcomes (*"ask the Foundry agent to add flow memory"*, *"ask the Foundry
63
+ agent to run that flow"*) instead of listing internal skills.
64
+ - **`getting-started.md` reworked.** The walkthrough now routes through the
65
+ Foundry agent, removes direct `foundry_git_branch({` /
66
+ `foundry_git_finish({` / `Run \`add-*\`` / `foundry_config_validate_*({` /
67
+ `foundry_config_create_*({` references, and uses `pnpm add -D
68
+ @really-knows-ai/foundry`.
69
+ - **`README.md` quick-start** updated for the install → init → ask-agent
70
+ workflow (`pnpm add -D @really-knows-ai/foundry`, ask the Foundry agent
71
+ to add a haiku flow).
72
+ - **`refresh-agents` skill** delegates to `foundry_refresh_agents()`. The skill
73
+ is now a thin wrapper around the deterministic tool.
74
+ - **`init-foundry`, `list-agents`, `sort.js`, `upgrade-foundry`** updated to
75
+ reference the `foundry_refresh_agents` tool.
76
+ - **Docs** (`architecture.md`, `concepts.md`, `tools.md`) updated to reference
77
+ guide-agent installation and the refresh tool. Tool count increased from 66 to
78
+ 67.
79
+
80
+ ### Fixed
81
+
82
+ - **`dist/agents/` added to the published package.** The build script already
83
+ copied `src/agents/` to `dist/agents/`, but the `files` array in
84
+ `package.json` excluded `dist/agents/`. `init-foundry` can now locate the
85
+ guide agent template in a packaged install.
86
+ - **`foundry_refresh_agents` preserves the guide agent.** Only
87
+ `foundry-*.md` stage agents are regenerated; `.opencode/agents/foundry.md`
88
+ survives refresh.
89
+
90
+ ## [3.0.3] - 2026-05-11
91
+
92
+ A patch release that makes agent-file generation deterministic by moving
93
+ `refresh-agents` from a skill-only protocol into a tested plugin tool.
94
+
95
+ ### Added
96
+
97
+ - **`foundry_refresh_agents` tool.** Runs `opencode models`, deletes stale
98
+ `.opencode/agents/foundry-*.md` files, and generates fresh agent files — one
99
+ per available model. The tool is idempotent, handles missing directories, and
100
+ returns `{ ok: true, count: <n> }` on success. This replaces the prior
101
+ skill-only protocol where the LLM had to implement the logic with shell
102
+ commands, which was error-prone and non-deterministic.
103
+
104
+ ### Changed
105
+
106
+ - **`refresh-agents` skill** now simply calls `foundry_refresh_agents()` and
107
+ reports the result.
108
+ - **`init-foundry` skill** step 4 now calls `foundry_refresh_agents()` instead
109
+ of instructing the LLM to run the `refresh-agents` skill.
110
+ - **`list-agents` skill** error message now references the tool.
111
+ - **`sort.js`** missing-agent error now references the tool.
112
+ - **`helpers.js`** bootstrap message now references the tool.
113
+ - **Docs** (`tools.md`, `getting-started.md`, `architecture.md`, `concepts.md`)
114
+ updated to reference the tool. Tool count increased from 65 to 66.
115
+
116
+ ## [3.0.2] - 2026-05-11
117
+
118
+ A documentation and tool-correctness patch driven by a failing
119
+ haiku-flow setup session. Closes the loop on the laws-with-validators
120
+ migration: the validator contract is now fully documented in
121
+ `add-law`; the `add_law` tool appends additional laws to an existing
122
+ file and rolls back its file write when the commit fails;
123
+ `init-foundry` seeds a `node_modules/` ignore so npm-installed
124
+ validator dependencies never collide with the config-tier write
125
+ guard.
126
+
127
+ ### Validator contract is canonical in `add-law`
128
+
129
+ - `add-law` SKILL.md gains a **§7a. Validator contract** that covers
130
+ the JSONL output shape (`file`, `text` required; `location`,
131
+ `severity` optional), command placeholders, working directory, skip
132
+ rule, and a worked Node example. Authors no longer need to read
133
+ plugin source to write a validator.
134
+ - `add-artefact-type` step 5 drops its half-duplicate contract and
135
+ cross-references `add-law` §7a. Step 1 and step 4 now make clear
136
+ that the frontmatter `name:` field equals the artefact type's id
137
+ (lowercase, hyphenated); human-readable labels go in the
138
+ `## Definition` prose. Step 9 reflects the new append-aware
139
+ `add_law`.
140
+
141
+ ### Validator command placeholders split
142
+
143
+ - `{pattern}` now renders the artefact type's `file-patterns:` as
144
+ space-separated, shell-quoted globs (e.g.
145
+ `'haikus/*.md' 'drafts/*.md'`). Use it when a validator does its
146
+ own globbing or accepts globs directly (e.g. `rg --glob`).
147
+ - `{files}` renders the matching files in the worktree as
148
+ space-separated, shell-quoted paths. Use it when the validator
149
+ takes an explicit list of file paths.
150
+ - A validator is skipped iff its command contains `{files}` and there
151
+ are no matching files. `{pattern}`-only and verbatim commands
152
+ always run.
153
+ - **Migration:** any existing validator authored against the prior
154
+ semantics (where `{pattern}` substituted expanded paths) must be
155
+ updated to use `{files}` instead. Foundry was tagged 3.0.1 only
156
+ 12 hours before this release; no migration helper is provided.
157
+
158
+ ### `foundry_config_add_law` correctness
159
+
160
+ - The tool now appends a new law to an existing `laws.md` instead of
161
+ erroring on file-exists. It only errors when a law with the same
162
+ id is already present in the file — in that case the caller
163
+ switches to `foundry_config_edit_law`.
164
+ - File writes are atomic with the commit. If the commit fails (most
165
+ commonly `unexpected_files`), the tool restores `laws.md` to its
166
+ prior content (or deletes it if it didn't exist before the call).
167
+ This eliminates the orphaned-file state that previously broke the
168
+ next call with "already exists".
169
+
170
+ ### `init-foundry` seeds `node_modules/`
171
+
172
+ - `.gitignore` now starts with `.snapshots/`, `node_modules/`, and
173
+ `.DS_Store`. The new entry stops `npm install` from immediately
174
+ blocking every config-tier tool with `unexpected_files`.
175
+
176
+ ### Migration
177
+
178
+ - Update any validator commands that used `{pattern}` for file
179
+ expansion to use `{files}` instead.
180
+ - No action needed for projects already on 3.0.1 that have not yet
181
+ authored validators using `{pattern}`.
182
+ - Existing projects can add `node_modules/` to `.gitignore` by hand;
183
+ the `init-foundry` change only affects newly-initialised projects.
184
+
3
185
  ## [3.0.1] - 2026-05-11
4
186
 
5
187
  A documentation and cleanup patch. No runtime behaviour change. `quench`
package/dist/README.md CHANGED
@@ -142,16 +142,17 @@ Open OpenCode in your project repo and say:
142
142
  > run init-foundry
143
143
  ```
144
144
 
145
- Foundry scaffolds a `foundry/` directory, generates one `foundry-<model>` agent file
146
- per model available in your session, commits the structure, and then asks you to
147
- restart. All the foundational configuration directories are created; you will
148
- populate them next.
145
+ Foundry scaffolds a `foundry/` directory, generates one `foundry-<model>` stage agent
146
+ file per model available in your session, installs the user-facing `Foundry` guide
147
+ agent, commits the structure, and asks you to restart.
149
148
 
150
- Restart OpenCode so the new `foundry-<model>` agents register multi-model dispatch cannot route to agents it cannot discover.
149
+ Restart OpenCode so the new agents register. After the restart, switch to the
150
+ **Foundry** agent. The Foundry agent is the normal interface for authoring and
151
+ running Foundry workflows.
151
152
 
152
- ### Phase 3 — Build a flow without writing one
153
+ ### Phase 3 — Ask the Foundry agent for a flow
153
154
 
154
- Ask Foundry to set up a flow:
155
+ With the **Foundry** agent active, ask it to set up a flow:
155
156
 
156
157
  ```
157
158
  > set up a flow that writes haikus
@@ -0,0 +1,37 @@
1
+ ---
2
+ description: "Guide users through Foundry authoring and flow execution"
3
+ mode: primary
4
+ ---
5
+ You are the Foundry agent.
6
+
7
+ Foundry is a framework for governed AI artefact generation. Your role is to help the user reach their stated Foundry outcome by understanding the goal, handling prerequisites, composing dependent configuration, and explaining progress in Foundry concepts.
8
+
9
+ ## Operating Principles
10
+
11
+ - Treat user requests as goals to satisfy.
12
+ - Use Foundry skills and tools internally.
13
+ - Keep tool names, JSON arguments, and tool-call syntax out of normal user-facing instructions.
14
+ - Create missing dependencies when they are part of the user's stated goal.
15
+ - Handle config branches, validation, commits, and dependency ordering when safe.
16
+ - Ask one focused question when intent, safety, or irreversible project state requires user input.
17
+ - Report outcomes as Foundry concepts, files created or updated, validations run, and commits made.
18
+
19
+ ## Authoring Posture
20
+
21
+ When the user asks to create or change a flow, work backwards from the requested outcome. A flow may require artefact types, laws, validators, appraisers, cycles, memory configuration, and branch setup. Create or reuse those pieces as needed instead of telling the user to invoke another skill.
22
+
23
+ When a dependency is ambiguous, present the smallest useful choice. When a dependency is missing and the user's goal clearly requires it, create it. When a hard conflict exists, stop and explain the conflict in Foundry terms.
24
+
25
+ ## Safety Boundaries
26
+
27
+ - Preserve user changes.
28
+ - Do not overwrite unrelated files.
29
+ - Do not bypass Foundry validation.
30
+ - Do not create overlapping artefact file patterns.
31
+ - Do not change Foundry configuration on an active `work/*` branch.
32
+ - Do not continue configuration work from `dry-run/*/*`; finish the dry run first.
33
+ - Do not push, publish, or create pull requests unless the user explicitly asks.
34
+
35
+ ## User-Facing Style
36
+
37
+ Speak directly and concretely. Explain what you are creating and why it supports the user's goal. Prefer Foundry terms such as artefact type, law, validator, appraiser, cycle, and flow. Avoid exposing implementation details unless the user asks for them.
@@ -300,7 +300,9 @@ Different stages can run on different models for cognitive diversity. Cycle defi
300
300
 
301
301
  ### Agent files
302
302
 
303
- `refresh-agents` generates a `foundry-<slug>.md` agent file in `.opencode/agents/` for every model available in the session, where `<slug>` is the model ID with both `/` and `.` replaced by `-` (e.g. `anthropic-claude-opus-4-7.md`).
303
+ The user-facing `Foundry` agent is installed by `init-foundry` as `.opencode/agents/foundry.md`. Users switch to this agent after restarting OpenCode. It guides authoring and flow execution while generated `foundry-*` stage agents remain hidden routing targets for specific models.
304
+
305
+ `foundry_refresh_agents()` generates a `foundry-<slug>.md` agent file in `.opencode/agents/` for every model available in the session, where `<slug>` is the model ID with both `/` and `.` replaced by `-` (e.g. `anthropic-claude-opus-4-7.md`).
304
306
 
305
307
  ### Dispatch behaviour
306
308
 
@@ -336,7 +338,7 @@ Implementation: `src/plugin/tools/helpers.js` (`buildCyclePromptExtras`) and `sr
336
338
  │ │ ├── add-flow/
337
339
  │ │ ├── add-extractor/
338
340
  │ │ ├── list-agents/ # utility
339
- │ │ ├── refresh-agents/
341
+ │ │ ├── refresh-agents/ # utility (now backed by foundry_refresh_agents tool)
340
342
  │ │ ├── upgrade-foundry/
341
343
  │ │ ├── init-memory/ # memory
342
344
  │ │ ├── add-memory-entity-type/
@@ -415,7 +417,8 @@ your-project/
415
417
  │ └── .secret # per-worktree HMAC key (mode 0600)
416
418
  ├── .opencode/
417
419
  │ └── agents/
418
- └── foundry-*.md # generated by refresh-agents
420
+ ├── foundry.md # user-facing Foundry guide agent
421
+ │ └── foundry-*.md # generated stage agents for model routing
419
422
  ├── opencode.json
420
423
  └── ...
421
424
  ```
@@ -265,7 +265,7 @@ All deterministic pipeline operations are exposed as custom tools by the Foundry
265
265
 
266
266
  ## Skill
267
267
 
268
- 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`), utility skills (`list-agents`, `refresh-agents`, `upgrade-foundry`), and memory skills (`init-memory`, `add-memory-*`, `rename-memory-*`, `drop-memory-*`, `reset-memory`, `change-embedding-model`). Skills are either **atomic** (do one thing) or **composite** (orchestrate other skills).
268
+ A self-contained workflow written as markdown with YAML frontmatter. Foundry ships a user-facing `Foundry` guide agent plus skills for pipeline execution, authoring, maintenance, and memory administration. The guide agent is the normal interface for users; skills and tools provide the internal workflows it uses to initialise projects, create artefact types, define laws, configure appraisers, build cycles and flows, and run governed artefact generation. Skills are either **atomic** (do one thing) or **composite** (orchestrate other skills).
269
269
 
270
270
  ---
271
271
 
@@ -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;