@dhzh/foundry 7.0.0 → 7.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.
@@ -1,31 +1,162 @@
1
1
  # Encrypted backups
2
2
 
3
- Use `FOUNDRY_PASSPHRASE` from the execution environment to keep secrets out of
4
- shell history. Both commands also accept `--passphrase <text>`.
3
+ ## Overview
4
+
5
+ Foundry can export its supported data to an encrypted `.foundry-backup` archive
6
+ and import such an archive as a complete replacement. Import is destructive and
7
+ does not merge records.
8
+
9
+ The current payload contains normalized settings, instruction records, and agent
10
+ assignment profiles. It is not a snapshot of all Foundry runtime files.
11
+
12
+ | Data | Included in backup |
13
+ | --- | --- |
14
+ | Normalized settings and retained backend feature settings | Yes |
15
+ | Instructions, including Markdown content and timestamps | Yes |
16
+ | Agent assignments, order, and enabled state | Yes |
17
+ | External `~/.codex/AGENTS.md` and `~/.claude/CLAUDE.md` files | No |
18
+ | Provider, capture, and fetch-job records | No |
19
+
20
+ ## When to use
21
+
22
+ Use export/import when the user wants to:
23
+
24
+ - Move supported Foundry settings to another installation.
25
+ - Move the instruction library and agent assignments to another installation.
26
+ - Preserve settings before a risky change.
27
+ - Replace current settings, instructions, and assignments with a snapshot.
28
+
29
+ Do not use a backup to preserve external agent files, providers, captures, or
30
+ fetch jobs. Those require a separate, explicitly chosen process.
31
+
32
+ Import updates Foundry's own agent profiles but never rewrites external agent
33
+ instruction files. If an imported agent is enabled, run
34
+ `foundry agents instructions reapply <agent>` to write its managed block on the
35
+ current machine.
36
+
37
+ ## Passphrase handling
38
+
39
+ Export and import require the same non-empty passphrase.
40
+
41
+ - Preferred: set `FOUNDRY_PASSPHRASE` in the execution environment so the value
42
+ does not appear in shell history.
43
+ - Alternative: pass `--passphrase <text>`.
44
+ - Never print a passphrase or include it in logs, issue reports, or responses.
45
+ - A lost passphrase cannot be recovered. A wrong passphrase cannot be bypassed.
46
+
47
+ If neither the environment variable nor the flag is present, the command fails
48
+ with `PASSPHRASE_REQUIRED`.
49
+
50
+ ## Export
5
51
 
6
52
  ```bash
7
53
  foundry settings export --output ./backup.foundry-backup
54
+ ```
55
+
56
+ Behavior:
57
+
58
+ - Writes an encrypted archive with private file permissions (`0600` where
59
+ supported).
60
+ - Omitting `--output` creates a timestamped filename in the working directory.
61
+ - The `.foundry-backup` extension is appended when absent.
62
+ - An existing destination fails with `OUTPUT_EXISTS` unless `--force` is used.
63
+ - The response contains the absolute destination:
64
+
65
+ ```json
66
+ { "filePath": "/home/alice/backup.foundry-backup" }
67
+ ```
68
+
69
+ Overwrite only when the user explicitly intends to replace that file:
70
+
71
+ ```bash
72
+ foundry settings export \
73
+ --output ./backup.foundry-backup \
74
+ --force
75
+ ```
76
+
77
+ ## Import
78
+
79
+ ```bash
8
80
  foundry settings import ./backup.foundry-backup
9
81
  ```
10
82
 
11
- Export writes an encrypted `.foundry-backup` file with private file permissions.
12
- An omitted output uses a timestamped filename in the working directory. The
13
- extension is appended when absent. An existing destination is rejected unless
14
- `--force` is supplied. The response contains `filePath`.
15
-
16
- Import validates the encrypted archive, manifest version, checksum and basic
17
- data structure, normalizes settings using Foundry's settings rules, and fully
18
- replaces the supported data. It does not merge or offer a preview session.
19
- Missing or invalid fields follow the same normalization rules as regular settings
20
- reads, including default values and numeric bounds. The last successful write
21
- wins. Current backup data includes retained backend feature settings. It is not
22
- limited to the four CLI get/set fields. Provider, capture, and fetch-job records
23
- are outside this backup dataset.
24
-
25
- Import is destructive. Run it when the user intends to replace current data.
26
- After `{"status":"imported"}`, verify with `foundry settings get`. Import from
27
- the Web UI reloads the page without the hash route; the normal root route opens
28
- Dashboard.
29
-
30
- Never print passphrases. A lost passphrase cannot be recovered. Wrong
31
- passphrases or invalid backups return a JSON error without replacing settings.
83
+ Import:
84
+
85
+ 1. Reads and decrypts the archive.
86
+ 2. Validates the manifest version, checksum, archive structure, settings,
87
+ instruction records, agent profiles, and instruction references.
88
+ 3. Normalizes settings with Foundry's regular rules, including defaults and
89
+ numeric bounds for retained backend fields.
90
+ 4. Replaces settings, instructions, and agent profiles completely.
91
+ 5. Returns `{ "status": "imported" }`.
92
+
93
+ There is no preview, merge, or partial apply. The last successful write wins.
94
+ Invalid or missing settings fields are normalized rather than rejected field by
95
+ field; invalid instruction or agent records are rejected instead. An unreadable
96
+ archive, wrong checksum, unsupported version, or wrong passphrase fails before
97
+ replacement.
98
+
99
+ ### Verify after import
100
+
101
+ ```bash
102
+ foundry settings get
103
+ foundry instructions list
104
+ foundry agents instructions list
105
+ ```
106
+
107
+ Confirm the expected theme, language, time zone, and time format. If the import
108
+ was initiated from the Web UI, the page reloads without the hash route and the
109
+ normal root route opens Dashboard.
110
+
111
+ For every imported agent that should be active, reapply its managed block:
112
+
113
+ ```bash
114
+ foundry agents instructions reapply chatgpt
115
+ foundry agents instructions reapply claude-code
116
+ ```
117
+
118
+ ## Common scenarios
119
+
120
+ ### Back up current data before a migration
121
+
122
+ ```bash
123
+ export FOUNDRY_PASSPHRASE="<secret>"
124
+ foundry settings export --output ./before-migration.foundry-backup
125
+ ```
126
+
127
+ ### Restore a known-good data snapshot
128
+
129
+ ```bash
130
+ export FOUNDRY_PASSPHRASE="<secret>"
131
+ foundry settings import ./before-migration.foundry-backup
132
+ foundry settings get
133
+ ```
134
+
135
+ Only run the import after confirming that replacing current data is the user's
136
+ intent.
137
+
138
+ ### Export without overwriting an existing file
139
+
140
+ Use a new filename, or add `--force` only after confirming the destination is
141
+ disposable. Without `--force`, the command fails instead of silently replacing
142
+ the archive.
143
+
144
+ ## Failure modes
145
+
146
+ | Code | Meaning | Data changed? |
147
+ | --- | --- | --- |
148
+ | `PASSPHRASE_REQUIRED` | No passphrase supplied | No |
149
+ | `INVALID_PASSPHRASE` | Wrong passphrase or corrupted encrypted content | No |
150
+ | `INVALID_BACKUP` | Invalid manifest, checksum, structure, records, or references | No |
151
+ | `OUTPUT_EXISTS` | Export destination exists and `--force` was not supplied | No |
152
+ | `IMPORT_FAILED` | Unexpected import failure | No verified replacement |
153
+ | `IO_ERROR` | Export encryption or filesystem read/write failure | No verified replacement |
154
+
155
+ Successful export does not verify that the archive can be decrypted with a
156
+ different copy of the passphrase; store the passphrase securely.
157
+
158
+ ## Related
159
+
160
+ - [Settings](settings.md): the CLI-visible preference keys.
161
+ - [Instructions](instructions.md): backed-up instruction records and deletion.
162
+ - [Agents](agents.md): assignment state and reapplying external files.
@@ -0,0 +1,323 @@
1
+ # Instructions
2
+
3
+ ## Overview
4
+
5
+ An instruction is reusable Markdown content stored by Foundry under a stable
6
+ ID. Instructions are the source material for agent orchestration: an agent
7
+ assignment selects instruction IDs and an order, then `enable` composes their
8
+ content into that agent's instruction file.
9
+
10
+ Instructions are independent of any one agent. The same instruction can be
11
+ assigned to ChatGPT and Claude Code, and removing it from one agent does not
12
+ change the other agent or the stored instruction.
13
+
14
+ Use this reference when the task is to create, read, edit, delete, list, or
15
+ inspect the instruction library. Read [Agents](agents.md) when the task also
16
+ assigns instructions to an agent or writes them into an agent file.
17
+
18
+ ## When to use
19
+
20
+ Create an instruction for durable guidance that should be reused across
21
+ sessions, for example:
22
+
23
+ - Repository conventions such as test commands, formatting rules, or review
24
+ checklists.
25
+ - A release or deployment checklist that should be applied to multiple coding
26
+ agents.
27
+ - A reusable prompt fragment or operating procedure the user wants to keep and
28
+ edit outside a single conversation.
29
+ - Shared behavior for both ChatGPT and Claude Code.
30
+ - Removing obsolete guidance after checking that no agent assignment still
31
+ references it.
32
+
33
+ Keep one-off task text in the conversation rather than creating an instruction.
34
+ An instruction is a stored record, not a temporary prompt.
35
+
36
+ ## Concepts
37
+
38
+ | Term | Meaning |
39
+ | --- | --- |
40
+ | Instruction | One Markdown record in the Foundry library |
41
+ | ID | Lowercase UUID assigned at creation; also the Markdown filename |
42
+ | Name | Human-readable label, trimmed, maximum 200 characters |
43
+ | Content | Markdown body preserved as supplied |
44
+ | Assignment | Ordered list of instruction IDs stored on an agent |
45
+ | In use | At least one agent assignment still contains the instruction ID |
46
+ | Managed block | The marked region Foundry writes into an agent file |
47
+
48
+ Instructions are not automatically active. They affect an agent only after the
49
+ instruction is assigned and that agent is enabled. See [Agents](agents.md) for
50
+ the assignment and write rules.
51
+
52
+ ## Create an instruction
53
+
54
+ Create a record with `foundry instructions new`. Both `--name` and `--content`
55
+ are required.
56
+
57
+ ```bash
58
+ foundry instructions new \
59
+ --name "Release checklist" \
60
+ --content "# Release
61
+
62
+ - Run tests
63
+ - Update the changelog"
64
+ ```
65
+
66
+ Quote content containing spaces or newlines. The shell passes the quoted
67
+ multi-line value as one argument.
68
+
69
+ The command prints the created record as JSON:
70
+
71
+ ```json
72
+ {
73
+ "id": "0a5fab1b-df3c-4721-8b0c-63ee87856292",
74
+ "name": "Release checklist",
75
+ "content": "# Release\n\n- Run tests\n- Update the changelog",
76
+ "createdAt": 1795801802798,
77
+ "updatedAt": 1795801802798
78
+ }
79
+ ```
80
+
81
+ Save the returned `id` when the next step assigns the instruction to an agent.
82
+
83
+ ### Creation rules
84
+
85
+ | Field | Rule |
86
+ | --- | --- |
87
+ | `name` | Required; surrounding whitespace is trimmed; 1–200 characters after trimming |
88
+ | `content` | Required; must contain a non-whitespace character; maximum 1,000,000 characters |
89
+ | Markdown body | Preserved from the supplied value; leading/trailing whitespace is not normalized |
90
+
91
+ Invalid input fails with code `INVALID_INSTRUCTION_INPUT` and no file is
92
+ created or changed. Missing flags are reported by the CLI argument parser
93
+ instead.
94
+
95
+ ## List instructions
96
+
97
+ ```bash
98
+ foundry instructions list
99
+ ```
100
+
101
+ The command prints a JSON array ordered by `updatedAt`, newest first. Each item
102
+ has the same shape as the creation result, including the full Markdown content.
103
+ Both timestamps are Unix epoch milliseconds as numbers.
104
+
105
+ Because the full library can be large, prefer the agent-oriented view when only
106
+ assignment names and order are needed:
107
+
108
+ ```bash
109
+ foundry agents instructions list
110
+ foundry agents instructions list chatgpt
111
+ ```
112
+
113
+ That command resolves IDs to instruction names and does not print content. See
114
+ [Agents](agents.md#inspect-assignments).
115
+
116
+ ## Read one instruction
117
+
118
+ ```bash
119
+ foundry instructions get <id>
120
+ ```
121
+
122
+ Prints one instruction as JSON with the same shape as the list result. Use the
123
+ ID printed by `new` or returned by `list`. A missing or malformed ID fails with
124
+ `INSTRUCTION_NOT_FOUND`.
125
+
126
+ ## Edit an instruction
127
+
128
+ ```bash
129
+ foundry instructions edit <id> \
130
+ --name "Release checklist" \
131
+ --content "# Release
132
+
133
+ - Run tests
134
+ - Verify the changelog"
135
+ ```
136
+
137
+ Both `--name` and `--content` are required. Edit replaces both fields, uses the
138
+ same validation rules as creation, keeps the instruction ID and `createdAt`,
139
+ and advances `updatedAt`. It prints the updated record as JSON.
140
+
141
+ Editing changes the stored instruction only. Enabled agent files keep the
142
+ content from their previous write until the affected agent is reapplied:
143
+
144
+ ```bash
145
+ foundry agents instructions reapply chatgpt
146
+ ```
147
+
148
+ Read the current assignment first with
149
+ `foundry agents instructions list <agent>` when it is unclear which agents use
150
+ the instruction.
151
+
152
+ ## Delete an instruction
153
+
154
+ ```bash
155
+ foundry instructions delete <id>
156
+ ```
157
+
158
+ The command removes the instruction Markdown file and prints the deleted record
159
+ as JSON. It does not remove assignments first.
160
+
161
+ Deletion is allowed only when no agent assignment references the ID. If any
162
+ assignment still contains it, the command fails with `INSTRUCTION_IN_USE` and
163
+ leaves the file unchanged. Clear the instruction from every agent before
164
+ retrying:
165
+
166
+ ```bash
167
+ foundry agents instructions list
168
+ foundry agents instructions assign chatgpt --instructions <remaining-ids>
169
+ foundry agents instructions assign claude-code --instructions ""
170
+ foundry instructions delete <id>
171
+ ```
172
+
173
+ Use `--instructions ""` when the agent should have no instructions. Otherwise
174
+ pass the remaining IDs in their existing order. If an agent is enabled, that
175
+ assignment update also rewrites or removes its managed block.
176
+
177
+ A missing or malformed ID fails with `INSTRUCTION_NOT_FOUND`.
178
+
179
+ ## Common workflows
180
+
181
+ ### Apply a new instruction to both agents
182
+
183
+ ```bash
184
+ foundry instructions new \
185
+ --name "Code review rules" \
186
+ --content "Review for correctness, tests, and regressions."
187
+ ```
188
+
189
+ Use the returned ID with each agent:
190
+
191
+ ```bash
192
+ foundry agents instructions assign chatgpt --instructions <instruction-id>
193
+ foundry agents instructions enable chatgpt
194
+
195
+ foundry agents instructions assign claude-code --instructions <instruction-id>
196
+ foundry agents instructions enable claude-code
197
+ ```
198
+
199
+ ### Add an instruction while preserving the existing order
200
+
201
+ 1. Read the current assignment:
202
+
203
+ ```bash
204
+ foundry agents instructions list chatgpt
205
+ ```
206
+
207
+ 2. Reassign with the full list, placing the new ID where it should appear:
208
+
209
+ ```bash
210
+ foundry agents instructions assign chatgpt \
211
+ --instructions <existing-id-1>,<existing-id-2>,<new-id>
212
+ ```
213
+
214
+ `assign` replaces the entire assignment, so omitting an existing ID removes it.
215
+
216
+ ### Replace instruction content
217
+
218
+ 1. Read the current record:
219
+
220
+ ```bash
221
+ foundry instructions get <id>
222
+ ```
223
+
224
+ 2. Edit it, keeping the ID stable:
225
+
226
+ ```bash
227
+ foundry instructions edit <id> \
228
+ --name "Release checklist" \
229
+ --content "# Release
230
+
231
+ - Run tests
232
+ - Verify the changelog"
233
+ ```
234
+
235
+ 3. Reapply each enabled agent that uses the instruction.
236
+
237
+ Agent assignments reference the stable ID, so editing does not require
238
+ reassigning the instruction. To remove the record instead, clear all
239
+ assignments and use `foundry instructions delete`.
240
+
241
+ ### Remove an instruction from the library
242
+
243
+ 1. Find which agents still reference it:
244
+
245
+ ```bash
246
+ foundry agents instructions list
247
+ ```
248
+
249
+ 2. Remove the ID from each agent assignment:
250
+
251
+ ```bash
252
+ foundry agents instructions assign chatgpt \
253
+ --instructions <remaining-id-1>,<remaining-id-2>
254
+ foundry agents instructions assign claude-code --instructions ""
255
+ ```
256
+
257
+ 3. Delete the unused record:
258
+
259
+ ```bash
260
+ foundry instructions delete <id>
261
+ ```
262
+
263
+ Deletion is intentionally blocked until every assignment is clear, so a
264
+ managed agent file can never keep a dangling instruction reference.
265
+
266
+ ## Storage and format
267
+
268
+ Each instruction is stored as one Markdown file:
269
+
270
+ ```text
271
+ <home>/.foundry/instructions/<id>.md
272
+ ```
273
+
274
+ The file uses YAML frontmatter followed by the untouched Markdown body:
275
+
276
+ ```md
277
+ ---
278
+ id: 0a5fab1b-df3c-4721-8b0c-63ee87856292
279
+ name: Release checklist
280
+ createdAt: 1795801802798
281
+ updatedAt: 1795801802798
282
+ ---
283
+
284
+ # Release
285
+
286
+ - Run tests
287
+ ```
288
+
289
+ - The filename must match the frontmatter `id`.
290
+ - The leading frontmatter block is parsed with YAML; later `---` blocks belong
291
+ to the instruction body.
292
+ - A malformed frontmatter block, invalid ID, non-millisecond timestamp, or
293
+ filename/ID mismatch makes that file fail validation instead of producing a
294
+ partial record.
295
+ - There is no separate index or database. An absent directory means an empty
296
+ instruction list.
297
+ - On POSIX, the directory and files are private (`0700` / `0600`).
298
+
299
+ ## Failure modes
300
+
301
+ | Symptom | Likely cause | Action |
302
+ | --- | --- | --- |
303
+ | `INVALID_INSTRUCTION_INPUT` | Empty name/content, over-limit value, or invalid input shape | Fix the argument and retry |
304
+ | `INSTRUCTION_NOT_FOUND` | The ID is missing, malformed, or no longer stored | Run `foundry instructions list` and use a current ID |
305
+ | `INSTRUCTION_IN_USE` | At least one agent assignment still contains the instruction | Run `foundry agents instructions list`, clear the ID from every agent, then retry |
306
+ | CLI reports a missing required option | `--name` or `--content` omitted | Add both flags |
307
+ | `Invalid instruction file: ...` | A stored Markdown file is malformed or its ID/filename mismatch | Inspect that file in `<home>/.foundry/instructions`; do not guess which record is broken |
308
+ | Created instruction is not active in an agent | Creation does not assign or enable it | Use `agents instructions assign` and `enable` |
309
+ | Edited content is missing from an agent file | Editing does not rewrite external files | Run `agents instructions reapply` for that agent |
310
+
311
+ ## Backup boundary
312
+
313
+ Encrypted backups include all instruction records, including Markdown content
314
+ and timestamps, plus agent assignments. Import fully replaces both and removes
315
+ stored instructions that are absent from the backup. External agent instruction
316
+ files are not included; reapply enabled agents after import. See
317
+ [Encrypted backups](backups.md#overview).
318
+
319
+ ## Related
320
+
321
+ - [Agents](agents.md): assign, reorder, enable, disable, and reapply.
322
+ - [Settings](settings.md): application preferences and Skill installation.
323
+ - [Encrypted backups](backups.md): export and destructive replacement import.