@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
@@ -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,44 +8,41 @@ 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
 
42
37
  ### 1. Gather basics
43
38
 
44
39
  From the user's prompt, establish:
45
- - `id` — lowercase, hyphenated identifier
46
- - `name` human-readable name
47
- - `file-patterns` glob patterns for files this type produces (forge's write scope is exactly these patterns)
48
- - A prose description of what this artefact type is
40
+ - `id` — lowercase, hyphenated identifier (e.g. `haiku`). The
41
+ frontmatter `name:` field must equal this id; any human-readable
42
+ label goes in the `## Definition` prose, not in frontmatter.
43
+ - `file-patterns` glob patterns for files this type produces
44
+ (forge's write scope is exactly these patterns).
45
+ - A prose description of what this artefact type is.
49
46
 
50
47
  If any of these are missing, ask.
51
48
 
@@ -87,7 +84,7 @@ Present the definition to the user:
87
84
 
88
85
  ```markdown
89
86
  ---
90
- name: <name>
87
+ name: <id>
91
88
  file-patterns:
92
89
  - "<pattern>"
93
90
  ---
@@ -97,8 +94,14 @@ file-patterns:
97
94
  <description>
98
95
  ```
99
96
 
97
+ The `name:` value must exactly match the artefact type's `id`
98
+ (lowercase, hyphenated). If you want a human-readable label, put it
99
+ in the `## Definition` prose.
100
+
100
101
  Ask: does this capture the artefact type correctly?
101
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
+
102
105
  ### 5. Laws (optional)
103
106
 
104
107
  Ask:
@@ -110,22 +113,18 @@ If yes, walk through each law using the same format as `add-law`:
110
113
  - Check for conflicts with global laws and any existing type-specific laws
111
114
  - Confirm with the user
112
115
 
113
- Each law may declare an optional `validators:` block. Include validators only when a deterministic check is needed. The format matches `add-law`:
114
-
115
- ```markdown
116
- ## <law-id>
117
-
118
- <What this law checks — one or two sentences.>
119
-
120
- validators:
121
- - id: validator-id
122
- command: ./script.sh
123
- failure-means: (optional description)
124
- ```
125
-
126
- The `validators` block is optional. When present, `quench` runs each validator for this law. Validator scripts live within the artefact type directory (e.g., `foundry/artefacts/<type>/check-foo.mjs`).
116
+ Each law may declare an optional `validators:` block; the YAML shape,
117
+ JSONL output contract, `{pattern}` / `{files}` placeholders, skip
118
+ rule, working directory, and a worked example are documented once in
119
+ the `add-law` skill under **§7a. Validator contract**. Authors of
120
+ type-specific laws must follow that contract — do not invent a
121
+ different one here.
127
122
 
128
- **Use existing libraries:** Before writing custom validation logic, search npm for well-tested libraries that solve the problem (e.g., `syllable` for syllable counting, `natural` for NLP tasks). Hand-rolled heuristics are fragile — prefer battle-tested packages. Install them as project dependencies.
123
+ **Use existing libraries:** Before writing custom validation logic,
124
+ search npm for well-tested libraries that solve the problem (e.g.
125
+ `syllable` for syllable counting, `natural` for NLP tasks).
126
+ Hand-rolled heuristics are fragile — prefer battle-tested packages.
127
+ Install them as project dependencies.
129
128
 
130
129
  Check the project's `package.json` for `"type": "module"`:
131
130
  - If ESM (`"type": "module"`): use `import` syntax, or name scripts with `.mjs` extension
@@ -171,13 +170,18 @@ Call `foundry_config_create_artefact_type({ name: "<id>", body: "<full markdown>
171
170
  - writes `foundry/artefacts/<id>/definition.md`;
172
171
  - produces one git commit on the current `config/*` branch.
173
172
 
174
- 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.
175
174
 
176
175
  Show the user the resulting commit hash from the response.
177
176
 
178
177
  ### 9. Add laws file (if defined)
179
178
 
180
- The create tool writes only `definition.md`. If you drafted any type-specific laws in step 5, append them to `foundry/artefacts/<id>/laws.md` by hand on this same `config/*` branch (use the `Edit` tool to create the file) and commit that as a separate microcommit.
179
+ If you drafted any type-specific laws in step 5, add them via
180
+ `foundry_config_add_law` (one call per law) with
181
+ `target: { kind: "type-specific", typeId: "<id>" }`. The first call
182
+ creates `foundry/artefacts/<id>/laws.md`; subsequent calls append to
183
+ that same file. Each call produces its own microcommit. See the
184
+ `add-law` skill for the full protocol.
181
185
 
182
186
  ### 10. Confirm
183
187
 
@@ -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
@@ -23,24 +23,17 @@ Before running this skill, verify all of the following:
23
23
  `git rev-parse --abbrev-ref HEAD` and confirm it matches
24
24
  `config/<description>`.
25
25
 
26
- 3. If the branch does not start with `config/`, instruct the user to
27
- create one before continuing:
28
-
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.
35
-
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/*`.
39
-
40
- 4. `foundry/memory/config.md` exists and has `enabled: true` (run
41
- `init-memory` first if not). Every entity type the extractor will
42
- populate must already be declared in `foundry/memory/entities/`
43
- (use `add-memory-entity-type` to create any that are missing).
26
+ 3. If the branch does not start with `config/`, move to a suitable
27
+ `config/*` branch internally when the current branch is safe. If
28
+ the current branch is `work/*` or `dry-run/*/*`, stop and explain
29
+ the active work must be finished first. When unrelated uncommitted
30
+ changes could be affected by branching or writing files, ask before
31
+ proceeding.
32
+
33
+ 4. `foundry/memory/config.md` exists and has `enabled: true` (initialise
34
+ memory internally first if not). Missing memory entity or edge type
35
+ dependencies are created or composed internally when they are part of
36
+ the user's stated goal.
44
37
 
45
38
  ## Steps
46
39
 
@@ -50,7 +43,7 @@ Ask the user for, in this order (one question at a time):
50
43
 
51
44
  1. **Extractor name.** Lowercase kebab-case (`java-symbols`, `python-classes`, `tree-sitter-rust`). This becomes the filename under `foundry/memory/extractors/<name>.md` and the identifier referenced from cycle frontmatter.
52
45
  2. **Command.** The path to the executable (relative to the repo root, e.g. `scripts/extract-java-symbols.sh`) or a short shell command. This is passed to `/bin/sh -c` at runtime.
53
- 3. **Entity types to populate (`memoryWrite`).** A list of entity type names already declared in this project's memory vocabulary. Validate against what exists; if the user names a type that doesn't exist, either offer to create it via `add-memory-entity-type` first or ask them to adjust.
46
+ 3. **Entity types to populate (`memoryWrite`).** A list of entity type names already declared in this project's memory vocabulary. Validate against what exists; if the user names a type that doesn't exist, compose or create it internally when it is part of the user's stated goal, or ask one focused question when schema design is ambiguous.
54
47
  4. **Timeout** (optional). Duration string like `30s`, `2m`, or a number of milliseconds. Defaults to 60 seconds if omitted.
55
48
  5. **Brief description.** 1–3 paragraphs of prose describing what this extractor extracts, what it requires on `PATH`, and any re-run triggers. This body is injected into the forge prompt of every cycle that uses this extractor, so clarity here translates to better downstream generation.
56
49
 
@@ -111,23 +104,18 @@ git add foundry/memory/extractors/<name>.md scripts/<command>
111
104
  git commit -m "feat(memory): add '<name>' extractor"
112
105
  ```
113
106
 
114
- ### 6. Guide the user on wiring it in
107
+ ### 6. Compose into a cycle when the user's goal requires it
115
108
 
116
- After creation, tell the user how to opt a cycle into this extractor:
109
+ When the user's stated goal is to add memory extraction to a flow or cycle, compose this extractor into the relevant cycle definition. See **Composing cycle definitions** below.
117
110
 
118
- > To use this extractor, add the following to the cycle's frontmatter:
119
- >
120
- > ```yaml
121
- > memory:
122
- > write: [<each type in memoryWrite>] # must include every type the extractor writes
123
- > assay:
124
- > extractors: [<this extractor's name>]
125
- > ```
126
- >
127
- > Then run the `flow` or `orchestrate` skill. On the first iteration of the cycle, the assay stage will execute this extractor before forge.
111
+ ## Dependency composition
112
+
113
+ Missing memory entity or edge type dependencies are **composed internally** when they are part of the user's stated goal. Compose into the appropriate memory vocabulary when schema design is ambiguous — ask one focused question rather than stalling.
128
114
 
129
115
  ## What this skill must not do
130
116
 
131
117
  - **Must not** run the extractor script itself to verify it works. That is the author's job.
132
- - **Must not** modify cycle definitions. Opting a cycle into the extractor is an explicit editorial step for the user to take.
133
- - **Must not** create entity or edge types that don't already exist. Compose into `add-memory-entity-type` / `add-memory-edge-type` for any missing vocabulary.
118
+
119
+ ## Composing cycle definitions
120
+
121
+ When the user's stated goal includes opting an existing cycle into this extractor, update the cycle definition internally to add the `extractors` and `memoryWrite` fields. Ask for confirmation or one focused question when cycle selection or wiring is ambiguous.
@@ -6,119 +6,74 @@ description: Creates a new foundry flow definition.
6
6
 
7
7
  # Add Flow
8
8
 
9
- You help the user create a new foundry flow. A foundry flow is a set of foundry cycles with declared starting points cycles own their own routing via targets and input contracts.
9
+ You help the user create a complete Foundry flow for their stated outcome. A flow may require artefact types, laws, validators, appraisers, and cycles before the flow file itself can validate. Work backwards from the requested outcome and create missing dependencies in validation order.
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.
39
32
 
40
- ## Protocol
41
-
42
- ### 1. Gather basics
43
-
44
- From the user's prompt, establish:
45
- - `id` — lowercase, hyphenated identifier
46
- - `name` — human-readable name
47
- - A prose description of what this foundry flow achieves end-to-end
48
-
49
- If any of these are missing, ask.
50
-
51
- ### 2. Check for id conflicts
52
-
53
- Read all existing flow definitions in `foundry/flows/*.md`.
54
-
55
- - Exact id match → hard conflict, must choose a different id
56
- - Semantically similar name or description → warn and ask if the new foundry flow is genuinely distinct
57
-
58
- ### 3. Determine foundry cycles and starting cycles
59
-
60
- Ask the user which foundry cycles this flow includes. List available cycles from `foundry/cycles/*.md` for reference.
33
+ Do not tell the user to call branch tools directly.
61
34
 
62
- Then ask: which of these are **starting cycles** — the cycles that can be entered first when the flow begins?
63
-
64
- - Starting cycles typically have no input dependencies
65
- - Multiple starting cycles are fine — the user (or context) determines which one to run first
66
-
67
- ### 4. Validate cycle graph
68
-
69
- For each non-starting cycle, verify it is reachable:
70
- - At least one other cycle in the flow has it as a target
71
- - Its input contract can be satisfied by cycles in the flow
72
-
73
- If a cycle is unreachable (no cycle targets it and it's not a starting cycle), warn:
74
-
75
- > Cycle `<id>` is not a starting cycle and no other cycle targets it. It will never be reached in this flow.
76
-
77
- ### 5. Draft the definition
35
+ ## Protocol
78
36
 
79
- Present the flow definition to the user:
37
+ ### 1. Understand the outcome
80
38
 
81
- ```markdown
82
- ---
83
- id: <id>
84
- name: <name>
85
- starting-cycles:
86
- - <cycle-id>
87
- ---
39
+ Extract or ask for the flow purpose, expected final artefact, output location, and any quality constraints. Prefer practical defaults for common requests.
88
40
 
89
- # <Name>
41
+ ### 2. Inventory existing configuration
90
42
 
91
- <description>
43
+ Read existing flows in `foundry/flows/*.md`, cycles in `foundry/cycles/*.md`, artefact types in `foundry/artefacts/*/definition.md`, laws in `foundry/laws/*.md`, and appraisers in `foundry/appraisers/*.md`. Identify reusable pieces and conflicts.
92
44
 
93
- ## Cycles
45
+ Reject duplicate flow IDs — if a flow with the same ID already exists, choose a different ID. Warn about semantic duplicates (different ID but near-identical purpose) and ask whether the new flow is genuinely distinct.
94
46
 
95
- - <cycle-id>
96
- - <cycle-id>
97
- ```
47
+ ### 3. Design the dependency set
98
48
 
99
- The `starting-cycles` field lists entry points. `## Cycles` lists all cycles in the flow (no ordering implied — routing is owned by individual cycle definitions via their `targets` field).
49
+ Create missing dependencies in validation order:
100
50
 
101
- Ask: does this capture the flow correctly?
51
+ 1. Artefact type and file patterns.
52
+ 2. Type-specific laws.
53
+ 3. Deterministic validators attached to laws.
54
+ 4. Appraisers or appraiser selection.
55
+ 5. Cycles that produce the artefact types.
56
+ 6. Flow tying starting cycles and cycle list together.
102
57
 
103
- ### 6. Validate the draft
58
+ For the haiku example, default to a `haiku` artefact type, `haikus/*.md` file pattern, laws for form, imagery, and mood, a deterministic syllable validator where project dependencies allow it, two or three distinct appraisers, one cycle, and one flow.
104
59
 
105
- Call `foundry_config_validate_flow({ name: "<id>", body: "<full markdown>" })`.
60
+ After designing cycles, validate the cycle graph: verify each non-starting cycle is reachable from a starting cycle through the `targets` graph, and verify each cycle's input contracts can be satisfied by other cycles in the flow. Warn about unreachable cycles or unsatisfiable contracts before proceeding.
106
61
 
107
- If the result is `{ ok: false, errors: [...] }`, address each error (adjust the body) and re-run until you get `{ ok: true }`. Common issues: missing required frontmatter keys, references to artefact types or flows that don't exist yet.
62
+ ### 4. Confirm ambiguous choices
108
63
 
109
- ### 7. Create the file
64
+ Ask only for choices that affect the user's goal or safety. Reuse compatible existing configuration when it clearly fits.
110
65
 
111
- Call `foundry_config_create_flow({ name: "<id>", body: "<full markdown>" })`. The tool:
66
+ ### 5. Validate and create each piece
112
67
 
113
- - re-validates the body (TOCTOU);
114
- - writes `foundry/flows/<id>.md`;
115
- - produces one git commit on the current `config/*` branch.
68
+ For each definition, use the `foundry_config_validate_*` tool family to validate it first. Resolve any validation errors, then use the corresponding `foundry_config_create_*` tool to create it. Summarise each created file and commit hash in Foundry terms.
116
69
 
117
- 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_flow` does not support updates.
70
+ ### 6. Final summary
118
71
 
119
- Show the user the resulting commit hash from the response.
72
+ Report the flow, starting cycles, artefact type, laws, validators, appraisers, and files created. Tell the user they can now ask the Foundry agent to run the flow.
120
73
 
121
- ## What you do NOT do
74
+ ## Safety Rules
122
75
 
123
- - You do not create foundry cycles that is a separate skill
124
- - You do not skip dependency validation
76
+ - Do not create overlapping artefact file patterns.
77
+ - Do not skip dependency validation.
78
+ - Do not expose internal tool-call syntax to the user.
79
+ - Do not continue when a branch or worktree state could overwrite user changes.