@really-knows-ai/foundry 3.0.2 → 3.2.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 (42) hide show
  1. package/README.md +12 -15
  2. package/dist/.opencode/plugins/foundry-tools/agent-refresh.js +184 -0
  3. package/dist/.opencode/plugins/foundry-tools/helpers.js +17 -20
  4. package/dist/.opencode/plugins/foundry-tools/refresh-agents-tool.js +27 -0
  5. package/dist/.opencode/plugins/foundry.js +114 -5
  6. package/dist/CHANGELOG.md +161 -0
  7. package/dist/README.md +12 -15
  8. package/dist/agents/foundry.md +37 -0
  9. package/dist/docs/README.md +1 -1
  10. package/dist/docs/architecture.md +8 -5
  11. package/dist/docs/concepts.md +2 -2
  12. package/dist/docs/getting-started.md +55 -135
  13. package/dist/docs/tools.md +21 -1
  14. package/dist/scripts/lib/foundational-guards.js +1 -1
  15. package/dist/scripts/lib/memory/admin/init.js +1 -1
  16. package/dist/scripts/sort.js +1 -1
  17. package/dist/skills/add-appraiser/SKILL.md +19 -34
  18. package/dist/skills/add-artefact-type/SKILL.md +19 -22
  19. package/dist/skills/add-cycle/SKILL.md +28 -37
  20. package/dist/skills/add-extractor/SKILL.md +21 -35
  21. package/dist/skills/add-flow/SKILL.md +43 -88
  22. package/dist/skills/add-law/SKILL.md +19 -24
  23. package/dist/skills/add-memory-edge-type/SKILL.md +12 -20
  24. package/dist/skills/add-memory-entity-type/SKILL.md +10 -19
  25. package/dist/skills/appraise/SKILL.md +1 -1
  26. package/dist/skills/change-embedding-model/SKILL.md +7 -11
  27. package/dist/skills/drop-memory-edge-type/SKILL.md +7 -11
  28. package/dist/skills/drop-memory-entity-type/SKILL.md +7 -11
  29. package/dist/skills/dry-run/SKILL.md +11 -28
  30. package/dist/skills/flow/SKILL.md +2 -2
  31. package/dist/skills/forge/SKILL.md +1 -1
  32. package/dist/skills/human-appraise/SKILL.md +1 -1
  33. package/dist/skills/init-memory/SKILL.md +12 -25
  34. package/dist/skills/list-agents/SKILL.md +1 -1
  35. package/dist/skills/quench/SKILL.md +1 -1
  36. package/dist/skills/refresh-agents/SKILL.md +4 -26
  37. package/dist/skills/rename-memory-edge-type/SKILL.md +7 -11
  38. package/dist/skills/rename-memory-entity-type/SKILL.md +7 -11
  39. package/dist/skills/reset-memory/SKILL.md +10 -18
  40. package/dist/skills/upgrade-foundry/SKILL.md +3 -3
  41. package/package.json +2 -1
  42. package/dist/skills/init-foundry/SKILL.md +0 -91
package/dist/README.md CHANGED
@@ -105,7 +105,7 @@ Add the plugin to `opencode.json`:
105
105
 
106
106
  Restart OpenCode so the plugin registers its tools and skills. You will see new
107
107
  tools and skills become available in OpenCode's command palette once the restart
108
- completes. The `init-foundry` skill and flow-management tools are now ready to use.
108
+ completes. Flow-management tools are now ready to use.
109
109
 
110
110
  ---
111
111
 
@@ -132,26 +132,23 @@ Add the plugin to `opencode.json` (see Install section above):
132
132
 
133
133
  Then restart OpenCode so the plugin registers its tools and skills. You will see new
134
134
  tools and skills become available in OpenCode's command palette once the restart
135
- completes. The `init-foundry` skill and flow-management tools are now ready to use.
135
+ completes. Flow-management tools are now ready to use.
136
136
 
137
137
  ### Phase 2 — Initialise
138
138
 
139
- Open OpenCode in your project repo and say:
139
+ Restart OpenCode after adding the plugin. On boot, the plugin's config hook runs
140
+ a decision tree: if `foundry/` is missing or its VERSION does not match the
141
+ installed plugin version, it bootstraps the directory structure, generates
142
+ `foundry-<model>` stage agent files, installs the user-facing `Foundry` guide
143
+ agent, and tells you to restart again.
140
144
 
141
- ```
142
- > run init-foundry
143
- ```
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.
149
-
150
- Restart OpenCode so the new `foundry-<model>` agents register — multi-model dispatch cannot route to agents it cannot discover.
145
+ Restart OpenCode a second time so the new agents register. After the restart,
146
+ switch to the **Foundry** agent. The Foundry agent is the normal interface for
147
+ authoring and running Foundry workflows.
151
148
 
152
- ### Phase 3 — Build a flow without writing one
149
+ ### Phase 3 — Ask the Foundry agent for a flow
153
150
 
154
- Ask Foundry to set up a flow:
151
+ With the **Foundry** agent active, ask it to set up a flow:
155
152
 
156
153
  ```
157
154
  > 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.
@@ -10,7 +10,7 @@ Getting oriented with Foundry means understanding both the concepts it uses and
10
10
 
11
11
  **Reading order:** Work through them in order; [getting-started.md](getting-started.md) builds hands-on confidence, and [concepts.md](concepts.md) provides reference depth. Most implementers spend 1–2 hours on getting-started before moving to Reference materials.
12
12
 
13
- - **getting-started.md** — Complete end-to-end installation, bootstrap (`init-foundry`), and first flow walkthrough. Read this immediately after installing the plugin and before authoring any of your own configuration.
13
+ - **getting-started.md** — Complete end-to-end installation, auto-bootstrapping, and first flow walkthrough. Read this immediately after installing the plugin and before authoring any of your own configuration.
14
14
 
15
15
  It establishes the operating model, directory structure, and practical confidence in one pass. Includes hands-on guidance on authoring the five foundational concepts (artefact types, laws, appraisers, cycles, flows) with worked examples you can run against real code. Also covers the optional flow-memory path: initialise memory, declare vocabulary, add extractors, and opt a cycle into assay for codebase-aware flows.
16
16
 
@@ -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 the plugin's `config` hook 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
 
@@ -328,7 +330,7 @@ Implementation: `src/plugin/tools/helpers.js` (`buildCyclePromptExtras`) and `sr
328
330
  │ │ ├── quench/
329
331
  │ │ ├── appraise/
330
332
  │ │ ├── human-appraise/
331
- │ │ ├── init-foundry/ # authoring
333
+ │ │ ├── add-artefact-type/ # authoring
332
334
  │ │ ├── add-artefact-type/
333
335
  │ │ ├── add-law/
334
336
  │ │ ├── add-appraiser/
@@ -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/
@@ -389,7 +391,7 @@ Implementation: `src/plugin/tools/helpers.js` (`buildCyclePromptExtras`) and `sr
389
391
  └── README.md
390
392
  ```
391
393
 
392
- ### User project (after `init-foundry`)
394
+ ### User project (after auto-bootstrapping)
393
395
 
394
396
  ```
395
397
  your-project/
@@ -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
  ```
@@ -252,7 +252,7 @@ plain-files directory at `.snapshots/<runId>/` on the parent
252
252
  - `trace.jsonl` — the full tool-call trace.
253
253
 
254
254
  `runId` is `<branch-slug>-<ulid>`. Snapshots are gitignored
255
- (`.snapshots/` is added to `.gitignore` by `init-foundry`) and
255
+ (`.snapshots/` is added to `.gitignore` by the plugin's auto-bootstrapping) and
256
256
  accumulate locally; `foundry_snapshot_list` enumerates them,
257
257
  `foundry_snapshot_show` returns a structured summary,
258
258
  `foundry_snapshot_delete` removes one, and
@@ -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,14 @@ 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
+ Restart OpenCode after adding the plugin. On boot, the plugin's config hook checks project state: if `foundry/` is missing or its VERSION does not match the installed plugin version, it bootstraps the directory structure, generates model-routing `foundry-*` stage agents, installs the user-facing `Foundry` guide agent, and prompts a second restart.
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
+ Restart OpenCode again so the new agents register. 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
37
 
48
38
  The `.foundry/` runtime directory (holding `.secret` for stage tokens) is created automatically on first plugin boot and added to `.gitignore`.
49
39
 
@@ -51,134 +41,67 @@ The `.foundry/` runtime directory (holding `.secret` for stage tokens) is create
51
41
 
52
42
  ## Author the configuration
53
43
 
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
- ```
44
+ 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.
61
45
 
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.
46
+ ### Author through the Foundry agent
67
47
 
68
- ### 1. Define an artefact type
48
+ Ask the Foundry agent to author or modify any part of the configuration. For example:
69
49
 
70
- Run `add-artefact-type`. It walks you through:
50
+ > Add a `haiku` artefact type with a `poetic-form` appraiser.
71
51
 
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.
52
+ > Add a law that requires at least one sensory metaphor in every haiku.
76
53
 
77
- Produces `foundry/artefacts/<id>/definition.md` (+ optional `laws.md`).
54
+ > Create a cycle that produces haikus from petitions.
78
55
 
79
- ### 2. Write laws
56
+ > Set up a `make-haiku` flow starting from `haiku-ideation`.
80
57
 
81
- Laws are subjective pass/fail criteria evaluated by appraisers. Two scopes:
58
+ 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.
82
59
 
83
- - **Global** — `foundry/laws/*.md`. All files are concatenated and apply to every artefact.
84
- - **Type-specific** — `foundry/artefacts/<type>/laws.md`.
60
+ ### Configuration reference
85
61
 
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.
62
+ These are the five pieces of a Foundry configuration, in dependency order:
87
63
 
88
- ### 3. Create appraisers
64
+ 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`.
89
65
 
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`).
66
+ 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.
91
67
 
92
- ### 4. Define a cycle
68
+ 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`).
93
69
 
94
- Run `add-cycle`. A cycle produces one artefact type and declares:
70
+ 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:
95
71
 
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.
101
-
102
- Example:
103
-
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
- ---
120
-
121
- # Haiku Creation
122
-
123
- Writes a haiku satisfying the petition produced by haiku-ideation.
124
- ```
125
-
126
- The skill validates that every input type can be produced by some cycle in the flow and that targets are reachable.
127
-
128
- ### 5. Define a flow
129
-
130
- Run `add-flow`. A flow groups cycles and declares starting points:
131
-
132
- ```markdown
133
- ---
134
- id: make-haiku
135
- name: Make a Haiku
136
- starting-cycles:
137
- - haiku-ideation
138
- ---
139
-
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
- ```
149
-
150
- Routing between cycles is owned by individual cycles via their `targets`, not by the flow.
151
-
152
- ### 6. Validate before writing (optional)
72
+ ```markdown
73
+ ---
74
+ id: haiku-creation
75
+ name: Haiku Creation
76
+ output-type: haiku
77
+ inputs:
78
+ type: any-of
79
+ artefacts:
80
+ - petition
81
+ targets: []
82
+ human-appraise: false
83
+ deadlock-appraise: true
84
+ deadlock-iterations: 5
85
+ models:
86
+ appraise: openai/gpt-5
87
+ ---
88
+ ```
153
89
 
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:
90
+ 5. **Flows** group cycles and declare starting points. Routing between cycles is owned by individual cycles via their `targets`.
155
91
 
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
- ```
92
+ ### Hand-authoring configuration files
163
93
 
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.
94
+ 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
95
 
169
96
  ---
170
97
 
171
98
  ## Run the flow
172
99
 
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:
100
+ 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
101
 
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:
102
+ 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.
103
+ 2. Creates a work branch and scaffolds `WORK.md` with the goal.
104
+ 3. Hands off to `orchestrate`, which drives the cycle:
182
105
  - **forge** writes the artefact.
183
106
  - **quench** runs CLI validators (if configured).
184
107
  - **appraise** dispatches parallel appraiser sub-agents and consolidates their `law:<id>` feedback.
@@ -197,19 +120,14 @@ When you've changed a law, an appraiser, or a cycle on a `config/*`
197
120
  branch and want to see how the change behaves end-to-end before
198
121
  merging, use dry-run mode.
199
122
 
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
- ```
123
+ Starting on the `config/*` branch with the in-progress edit, ask the
124
+ Foundry agent to trial the change with dry-run mode for the target flow
125
+ and a short purpose such as `stricter-imagery-law`. The agent creates a
126
+ `dry-run/<parent>/<flow>-<purpose>` branch, runs the flow, records every
127
+ Foundry tool call in `.foundry/trace/<branch>.jsonl`, then finishes the
128
+ dry-run with a findings summary. Finishing writes
129
+ `.snapshots/<run-id>/{README.md, work/WORK*, diff.patch, trace.jsonl}`
130
+ on the parent `config/*` working tree and deletes the dry-run branch.
213
131
 
214
132
  Inspect the snapshot at `.snapshots/<run-id>/`, decide whether to keep
215
133
  the config edit, and either commit/merge from the parent `config/*`
@@ -263,11 +181,11 @@ Foundry ships a typed, graph-shaped memory store that persists across cycles. Us
263
181
 
264
182
  ### Initialise
265
183
 
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" })`).
184
+ Memory init and vocabulary edits are schema mutations, so they run on a
185
+ config branch. The Foundry agent opens a suitable config branch when it
186
+ is safe; if you are working by hand, open one first.
269
187
 
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:
188
+ 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
189
 
272
190
  - creates `foundry/memory/entities/` and `edges/` (each with `.gitkeep`) plus the top-level sibling `foundry-memory/relations/` for committed row data,
273
191
  - writes `foundry/memory/config.md` (frontmatter driven by your embeddings choice) and `foundry/memory/schema.json`,
@@ -278,6 +196,8 @@ Run the `init-memory` skill. It asks whether to enable embeddings (default: yes,
278
196
 
279
197
  Two concepts: **entity types** (things memory knows about, e.g. `class`, `method`) and **edge types** (directed relationships, e.g. `calls`, `references`).
280
198
 
199
+ 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:
200
+
281
201
  - `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
202
  - `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
203
 
@@ -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
@@ -8,6 +8,6 @@ export function requireFoundryRoot(io) {
8
8
  if (io.exists('foundry')) return { ok: true };
9
9
  return {
10
10
  ok: false,
11
- error: 'foundry/ directory not found at worktree root. Run the init-foundry skill to scaffold it.',
11
+ error: 'foundry/ directory not found at worktree root. Restart OpenCode to initialise Foundry.',
12
12
  };
13
13
  }
@@ -87,7 +87,7 @@ function buildSchema(embeddingsEnabled, model, dimensions) {
87
87
 
88
88
  async function validatePrerequisites(io, p) {
89
89
  if (!(await io.exists('foundry'))) {
90
- throw new Error('foundry/ does not exist; run init-foundry first');
90
+ throw new Error('foundry/ does not exist. Restart OpenCode to initialise Foundry.');
91
91
  }
92
92
  if (await io.exists(p.root)) {
93
93
  throw new Error('foundry/memory/ already exists');
@@ -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