@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
@@ -8,34 +8,29 @@ description: Creates a new artefact type, checking for conflicts with existing t
8
8
 
9
9
  You help the user create a new artefact type. You ensure it avoids conflicts with existing types, scaffold the directory structure, and walk the user through defining laws and their optional validators.
10
10
 
11
- ## Prerequisites
11
+ ## Foundry Agent Preflight
12
12
 
13
- Before running this skill, verify all three of the following:
13
+ If you are clearly operating as the Foundry agent, continue.
14
14
 
15
- 1. The `foundry/` directory exists in the project root. If it does not
16
- exist, stop and tell the user:
15
+ If you are not clearly operating as the Foundry agent, pause and tell the user:
17
16
 
18
- > Foundry is not initialized in this project. Run the
19
- > `init-foundry` skill first to create the foundry/ directory
20
- > structure.
17
+ > This work is best handled by the Foundry agent. Restart OpenCode if you have just initialised Foundry, switch to the **Foundry** agent, and continue this request there.
21
18
 
22
- 2. The current git branch is a `config/*` branch. Run
23
- `git rev-parse --abbrev-ref HEAD` and confirm it matches
24
- `config/<description>`.
19
+ This is an advisory guard. Continue only when the active instructions make it clear you are the Foundry agent or the user explicitly asks to proceed here.
25
20
 
26
- 3. If the branch does not start with `config/`, instruct the user to
27
- create one before continuing:
21
+ ## Config Branch Handling
28
22
 
29
- > Foundry configuration changes must be made on a config/* branch.
30
- > From a clean main branch, call:
31
- >
32
- > `foundry_git_branch({ kind: "config", description: "<short-name>" })`
33
- >
34
- > Then re-run this skill.
23
+ Before writing Foundry configuration:
35
24
 
36
- If the user is on a `dry-run/*/*` branch, they must finish
37
- that dry-run first (`foundry_git_finish({ message, confirm: true })`)
38
- before re-running this skill on the parent `config/*`.
25
+ - Confirm `foundry/` exists. If it is missing, initialise Foundry first when that serves the user's goal.
26
+ - Check the current branch.
27
+ - On `main` or another clean non-work branch, create a `config/<short-description>` branch internally.
28
+ - On `config/*`, continue on the current branch.
29
+ - On `work/*`, stop and explain that active flow work must be finished before configuration changes.
30
+ - On `dry-run/*/*`, stop and explain that the dry run must be finished before configuration changes.
31
+ - If unrelated uncommitted changes could be affected by branching or writing files, ask before proceeding.
32
+
33
+ Do not tell the user to call branch tools directly.
39
34
 
40
35
  ## Protocol
41
36
 
@@ -105,6 +100,8 @@ in the `## Definition` prose.
105
100
 
106
101
  Ask: does this capture the artefact type correctly?
107
102
 
103
+ When laws or validators are clearly part of the requested artefact type, draft them during artefact-type creation. Use the validator contract from `add-law` and prefer established packages installed with the project package manager.
104
+
108
105
  ### 5. Laws (optional)
109
106
 
110
107
  Ask:
@@ -173,7 +170,7 @@ Call `foundry_config_create_artefact_type({ name: "<id>", body: "<full markdown>
173
170
  - writes `foundry/artefacts/<id>/definition.md`;
174
171
  - produces one git commit on the current `config/*` branch.
175
172
 
176
- If the tool returns `{ ok: false, errors }` because the target file already exists, the user should edit the file by hand on this `config/*` branch `foundry_config_create_artefact_type` does not support updates.
173
+ If the tool returns `{ ok: false, errors }` because the target file already exists, read the existing file, incorporate the user's requested changes into the current body, propose the merged result for review, then write and commit the updated file.
177
174
 
178
175
  Show the user the resulting commit hash from the response.
179
176
 
@@ -8,34 +8,29 @@ description: Creates a new foundry cycle within a foundry flow, specifying the o
8
8
 
9
9
  You help the user create a new foundry cycle and add it to an existing foundry flow. A foundry cycle produces one artefact type (read-write), declares its input contract, targets the next cycle(s), and optionally enables human-appraise as a quality gate.
10
10
 
11
- ## Prerequisites
11
+ ## Foundry Agent Preflight
12
12
 
13
- Before running this skill, verify all three of the following:
13
+ If you are clearly operating as the Foundry agent, continue.
14
14
 
15
- 1. The `foundry/` directory exists in the project root. If it does not
16
- exist, stop and tell the user:
15
+ If you are not clearly operating as the Foundry agent, pause and tell the user:
17
16
 
18
- > Foundry is not initialized in this project. Run the
19
- > `init-foundry` skill first to create the foundry/ directory
20
- > structure.
17
+ > This work is best handled by the Foundry agent. Restart OpenCode if you have just initialised Foundry, switch to the **Foundry** agent, and continue this request there.
21
18
 
22
- 2. The current git branch is a `config/*` branch. Run
23
- `git rev-parse --abbrev-ref HEAD` and confirm it matches
24
- `config/<description>`.
19
+ This is an advisory guard. Continue only when the active instructions make it clear you are the Foundry agent or the user explicitly asks to proceed here.
25
20
 
26
- 3. If the branch does not start with `config/`, instruct the user to
27
- create one before continuing:
21
+ ## Config Branch Handling
28
22
 
29
- > Foundry configuration changes must be made on a config/* branch.
30
- > From a clean main branch, call:
31
- >
32
- > `foundry_git_branch({ kind: "config", description: "<short-name>" })`
33
- >
34
- > Then re-run this skill.
23
+ Before writing Foundry configuration:
35
24
 
36
- If the user is on a `dry-run/*/*` branch, they must finish
37
- that dry-run first (`foundry_git_finish({ message, confirm: true })`)
38
- before re-running this skill on the parent `config/*`.
25
+ - Confirm `foundry/` exists. If it is missing, initialise Foundry first when that serves the user's goal.
26
+ - Check the current branch.
27
+ - On `main` or another clean non-work branch, create a `config/<short-description>` branch internally.
28
+ - On `config/*`, continue on the current branch.
29
+ - On `work/*`, stop and explain that active flow work must be finished before configuration changes.
30
+ - On `dry-run/*/*`, stop and explain that the dry run must be finished before configuration changes.
31
+ - If unrelated uncommitted changes could be affected by branching or writing files, ask before proceeding.
32
+
33
+ Do not tell the user to call branch tools directly.
39
34
 
40
35
  ## Protocol
41
36
 
@@ -43,7 +38,7 @@ Before running this skill, verify all three of the following:
43
38
 
44
39
  From the user's prompt, identify which foundry flow this foundry cycle belongs to. If not specified, list available flows from `foundry/flows/` and ask.
45
40
 
46
- Verify the flow exists. If it doesn't, tell the user and ask if they want to create the foundry flow first (separate skill).
41
+ If the parent flow or required artefact type is missing and the user's goal clearly requires it, create that dependency first. If multiple designs are plausible, ask one focused question before creating it.
47
42
 
48
43
  ### 2. Gather basics
49
44
 
@@ -64,7 +59,7 @@ If any of these are missing, ask.
64
59
 
65
60
  For each stage in the cycle (forge, quench, appraise), ask the user if they want to specify a model:
66
61
 
67
- > Each stage can optionally run on a specific model for model diversity. Available models are listed as `foundry-*` agent files in `.opencode/agents/`. Run the `list-agents` skill to see them.
62
+ > Each stage can optionally run on a specific model for model diversity. Available session models are listed in your session configuration.
68
63
  >
69
64
  > For each stage, specify a model ID (e.g., `openai/gpt-4o`) or leave blank to use the session's default model:
70
65
  > - forge: ___
@@ -73,15 +68,17 @@ For each stage in the cycle (forge, quench, appraise), ask the user if they want
73
68
 
74
69
  Only stages with an explicitly specified model are included in the `models` frontmatter map.
75
70
 
71
+ If the user has no preference, omit the `models` map and use the session defaults.
72
+
76
73
  ### 4. Configure human appraise
77
74
 
78
75
  Ask the user:
79
76
 
80
- > Human-appraise has two independent knobs:
77
+ > Human-appraise has two independent knobs and one dependent setting:
81
78
  >
82
79
  > 1. `human-appraise` — should a human review the artefact every iteration? Default: no.
83
80
  > 2. `deadlock-appraise` — should a human be pulled in only when LLM appraisers deadlock? Default: yes.
84
- > 3. If either is enabled, `deadlock-iterations` sets the deadlock threshold (default: 5).
81
+ > 3. `deadlock-iterations` the deadlock threshold (default: 5). Only applies when `deadlock-appraise` or `human-appraise` is enabled.
85
82
  >
86
83
  > - human-appraise: yes/no (default no)
87
84
  > - deadlock-appraise: yes/no (default yes)
@@ -89,9 +86,9 @@ Ask the user:
89
86
 
90
87
  ### 5. Validate artefact types
91
88
 
92
- For `output-type` and each entry in `inputs`:
93
- - Verify the artefact type exists in `foundry/artefacts/<type>/definition.md`
94
- - If it doesn't, tell the user and ask if they want to create it first (separate skill)
89
+ For `output-type` and each entry in `inputs`, verify the artefact type exists in `foundry/artefacts/<type>/definition.md`.
90
+
91
+ If a required artefact type is missing and the user's goal clearly requires it, create that dependency first. If the file pattern or type design cannot be inferred safely, ask one focused question before creating it.
95
92
 
96
93
  ### 6. Validate against the foundry flow
97
94
 
@@ -175,7 +172,7 @@ Call `foundry_config_create_cycle({ name: "<id>", body: "<full markdown>" })`. T
175
172
  - writes `foundry/cycles/<id>.md`;
176
173
  - produces one git commit on the current `config/*` branch.
177
174
 
178
- If the tool returns `{ ok: false, errors }` because the target file already exists, the user should edit the file by hand on this `config/*` branch — `foundry_config_create_cycle` does not support updates.
175
+ If the tool returns `{ ok: false, errors }` because the target file already exists, read the existing cycle file, apply any necessary updates, write it back, and commit on this `config/*` branch.
179
176
 
180
177
  Show the user the resulting commit hash from the response.
181
178
 
@@ -183,12 +180,7 @@ Show the user the resulting commit hash from the response.
183
180
 
184
181
  `foundry_config_create_cycle` writes the cycle file only. The cycle still needs to appear in the parent flow's `## Cycles` list.
185
182
 
186
- Edit `foundry/flows/<flow-id>.md` by hand on this same `config/*` branch using the `Edit` tool. Add the new cycle id under `## Cycles` (if not already present). Commit that edit by hand as a separate microcommit, e.g.:
187
-
188
- ```
189
- git add foundry/flows/<flow-id>.md
190
- git commit -m "config(flow): add <cycle-id> to <flow-id>"
191
- ```
183
+ Read the existing flow file from `foundry/flows/<flow-id>.md`. Add the new cycle id under `## Cycles` if it is not already present. Write the updated file back and commit on this same `config/*` branch.
192
184
 
193
185
  ### 14. Confirm
194
186
 
@@ -198,5 +190,4 @@ Show the user the cycle file, the updated flow file, and both commit hashes.
198
190
 
199
191
  - You do not create foundry cycles that output an artefact type already produced by another foundry cycle in the same foundry flow
200
192
  - You do not skip artefact type validation
201
- - You do not create artefact types that is a separate skill
202
- - You do not create foundry flows — that is a separate skill
193
+ - You do not create dependencies (artefact types, flows) unless the user's stated goal clearly requires them; ask one focused question when multiple designs are plausible
@@ -15,32 +15,23 @@ Before running this skill, verify all of the following:
15
15
  1. The `foundry/` directory exists in the project root. If it does not
16
16
  exist, stop and tell the user:
17
17
 
18
- > Foundry is not initialized in this project. Run the
19
- > `init-foundry` skill first to create the foundry/ directory
20
- > structure.
18
+ > Restart OpenCode to initialise Foundry, then retry this command.
21
19
 
22
20
  2. The current git branch is a `config/*` branch. Run
23
21
  `git rev-parse --abbrev-ref HEAD` and confirm it matches
24
22
  `config/<description>`.
25
23
 
26
- 3. If the branch does not start with `config/`, instruct the user to
27
- create one before continuing:
24
+ 3. If the branch does not start with `config/`, move to a suitable
25
+ `config/*` branch internally when the current branch is safe. If
26
+ the current branch is `work/*` or `dry-run/*/*`, stop and explain
27
+ the active work must be finished first. When unrelated uncommitted
28
+ changes could be affected by branching or writing files, ask before
29
+ proceeding.
28
30
 
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).
31
+ 4. `foundry/memory/config.md` exists and has `enabled: true` (initialise
32
+ memory internally first if not). Missing memory entity or edge type
33
+ dependencies are created or composed internally when they are part of
34
+ the user's stated goal.
44
35
 
45
36
  ## Steps
46
37
 
@@ -50,7 +41,7 @@ Ask the user for, in this order (one question at a time):
50
41
 
51
42
  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
43
  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.
44
+ 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
45
  4. **Timeout** (optional). Duration string like `30s`, `2m`, or a number of milliseconds. Defaults to 60 seconds if omitted.
55
46
  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
47
 
@@ -111,23 +102,18 @@ git add foundry/memory/extractors/<name>.md scripts/<command>
111
102
  git commit -m "feat(memory): add '<name>' extractor"
112
103
  ```
113
104
 
114
- ### 6. Guide the user on wiring it in
105
+ ### 6. Compose into a cycle when the user's goal requires it
115
106
 
116
- After creation, tell the user how to opt a cycle into this extractor:
107
+ 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
108
 
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.
109
+ ## Dependency composition
110
+
111
+ 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
112
 
129
113
  ## What this skill must not do
130
114
 
131
115
  - **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.
116
+
117
+ ## Composing cycle definitions
118
+
119
+ 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.
@@ -8,34 +8,29 @@ description: Creates a new law, checking for conflicts with existing laws.
8
8
 
9
9
  You help the user create a new law. You ensure it's well-scoped, doesn't conflict with existing laws, and ends up in the right 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
 
@@ -49,7 +44,7 @@ If the user doesn't specify, ask:
49
44
 
50
45
  > Should this law apply globally to all artefact types, or to a specific type?
51
46
 
52
- If they name a type, verify it exists in `foundry/artefacts/`. If it doesn't, tell them and ask if they want to create the artefact type first.
47
+ If the user names a type-specific law for an artefact type that does not exist, create the artefact type first when that supports the user's stated goal. Use the `add-artefact-type` workflow internally, and ask for the file pattern only when it cannot be inferred safely.
53
48
 
54
49
  ### 2. Draft the law
55
50
 
@@ -154,7 +149,7 @@ Show the user the resulting commit hash from the response.
154
149
 
155
150
  ### 7. Verify uniqueness
156
151
 
157
- After the file is created, confirm the law id is unique across all law files. If a collision exists, ask the user to rename and edit by hand on this branch.
152
+ After the file is created, confirm the law id is unique across all law files. If a collision exists, read the colliding law, present the conflict to the user, propose a rename or merge, ask one focused question about the user's preference, then write and commit the resolution.
158
153
 
159
154
  ### 7a. Validator contract
160
155
 
@@ -299,4 +294,4 @@ Validate the result. If the tool returns `{ ok: true }`, show the user the commi
299
294
 
300
295
  - You do not skip the conflict check
301
296
  - You do not silently overwrite existing laws
302
- - You do not create artefact types that is a separate skill
297
+ - You do not create artefact types unless the user's stated goal clearly requires it; ask one focused question when multiple designs are plausible
@@ -13,31 +13,23 @@ Before running this skill, verify all of the following:
13
13
  1. The `foundry/` directory exists in the project root. If it does not
14
14
  exist, stop and tell the user:
15
15
 
16
- > Foundry is not initialized in this project. Run the
17
- > `init-foundry` skill first to create the foundry/ directory
18
- > structure.
16
+ > Restart OpenCode to initialise Foundry, then retry this command.
19
17
 
20
18
  2. The current git branch is a `config/*` branch. Run
21
19
  `git rev-parse --abbrev-ref HEAD` and confirm it matches
22
20
  `config/<description>`.
23
21
 
24
- 3. If the branch does not start with `config/`, instruct the user to
25
- create one before continuing:
26
-
27
- > Foundry configuration changes must be made on a config/* branch.
28
- > From a clean main branch, call:
29
- >
30
- > `foundry_git_branch({ kind: "config", description: "<short-name>" })`
31
- >
32
- > Then re-run this skill.
33
-
34
- If the user is on a `dry-run/*/*` branch, they must finish
35
- that dry-run first (`foundry_git_finish({ message, confirm: true })`)
36
- before re-running this skill on the parent `config/*`.
37
-
38
- 4. Memory is initialised (`foundry/memory/` exists; run `init-memory`
39
- if not). Entity types referenced in `sources` and `targets` must
40
- already exist (or be added first).
22
+ 3. If the branch does not start with `config/`, move to a suitable
23
+ `config/*` branch internally when the current branch is safe. If
24
+ the current branch is `work/*` or `dry-run/*/*`, stop and explain
25
+ the active work must be finished first. When unrelated uncommitted
26
+ changes could be affected by branching or writing files, ask before
27
+ proceeding.
28
+
29
+ 4. Memory is initialised (`foundry/memory/` exists; initialise memory
30
+ internally first if not). Entity types referenced in `sources` and
31
+ `targets` must already exist (or be created or composed internally
32
+ when they are part of the user's stated goal).
41
33
 
42
34
  ## Steps
43
35
 
@@ -16,30 +16,21 @@ Before running this skill, verify all of the following:
16
16
  1. The `foundry/` directory exists in the project root. If it does not
17
17
  exist, stop and tell the user:
18
18
 
19
- > Foundry is not initialized in this project. Run the
20
- > `init-foundry` skill first to create the foundry/ directory
21
- > structure.
19
+ > Restart OpenCode to initialise Foundry, then retry this command.
22
20
 
23
21
  2. The current git branch is a `config/*` branch. Run
24
22
  `git rev-parse --abbrev-ref HEAD` and confirm it matches
25
23
  `config/<description>`.
26
24
 
27
- 3. If the branch does not start with `config/`, instruct the user to
28
- create one before continuing:
25
+ 3. If the branch does not start with `config/`, move to a suitable
26
+ `config/*` branch internally when the current branch is safe. If
27
+ the current branch is `work/*` or `dry-run/*/*`, stop and explain
28
+ the active work must be finished first. When unrelated uncommitted
29
+ changes could be affected by branching or writing files, ask before
30
+ proceeding.
29
31
 
30
- > Foundry configuration changes must be made on a config/* branch.
31
- > From a clean main branch, call:
32
- >
33
- > `foundry_git_branch({ kind: "config", description: "<short-name>" })`
34
- >
35
- > Then re-run this skill.
36
-
37
- If the user is on a `dry-run/*/*` branch, they must finish
38
- that dry-run first (`foundry_git_finish({ message, confirm: true })`)
39
- before re-running this skill on the parent `config/*`.
40
-
41
- 4. Memory is initialised (`foundry/memory/` exists; run `init-memory`
42
- if not).
32
+ 4. Memory is initialised (`foundry/memory/` exists; initialise memory
33
+ internally first if not).
43
34
 
44
35
  ## Steps
45
36
 
@@ -71,4 +62,4 @@ Before running this skill, verify all of the following:
71
62
  git commit -m "feat(memory): add entity type <name>"
72
63
  ```
73
64
 
74
- 6. **Guidance to the user**: suggest they also add relevant edge types using `add-memory-edge-type`.
65
+ 6. **Dependency composition**: if related edge types would serve the user's stated goal, compose them internally with one focused question for ambiguity.