@ymy88/pi-subagents 0.0.0-stage → 0.24.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 (196) hide show
  1. package/CHANGELOG.md +904 -0
  2. package/CONTRIBUTING.md +72 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1170 -2
  5. package/SECURITY.md +95 -0
  6. package/dist/abortable.d.ts +12 -0
  7. package/dist/abortable.js +42 -0
  8. package/dist/agent-color.d.ts +35 -0
  9. package/dist/agent-color.js +123 -0
  10. package/dist/agent-file-toggle.d.ts +133 -0
  11. package/dist/agent-file-toggle.js +287 -0
  12. package/dist/agent-manager.d.ts +552 -0
  13. package/dist/agent-manager.js +1466 -0
  14. package/dist/agent-record-entry.d.ts +96 -0
  15. package/dist/agent-record-entry.js +121 -0
  16. package/dist/agent-runner.d.ts +310 -0
  17. package/dist/agent-runner.js +1195 -0
  18. package/dist/agent-source-badge.d.ts +50 -0
  19. package/dist/agent-source-badge.js +74 -0
  20. package/dist/agent-types.d.ts +119 -0
  21. package/dist/agent-types.js +286 -0
  22. package/dist/child-context.d.ts +2 -0
  23. package/dist/child-context.js +12 -0
  24. package/dist/completion-outbox.d.ts +63 -0
  25. package/dist/completion-outbox.js +104 -0
  26. package/dist/context.d.ts +12 -0
  27. package/dist/context.js +56 -0
  28. package/dist/cross-extension-rpc.d.ts +72 -0
  29. package/dist/cross-extension-rpc.js +153 -0
  30. package/dist/custom-agents.d.ts +77 -0
  31. package/dist/custom-agents.js +396 -0
  32. package/dist/default-agents.d.ts +7 -0
  33. package/dist/default-agents.js +121 -0
  34. package/dist/enabled-models.d.ts +49 -0
  35. package/dist/enabled-models.js +145 -0
  36. package/dist/env.d.ts +6 -0
  37. package/dist/env.js +28 -0
  38. package/dist/group-join.d.ts +32 -0
  39. package/dist/group-join.js +116 -0
  40. package/dist/index.d.ts +50 -0
  41. package/dist/index.js +4111 -0
  42. package/dist/invocation-config.d.ts +108 -0
  43. package/dist/invocation-config.js +83 -0
  44. package/dist/memory.d.ts +53 -0
  45. package/dist/memory.js +165 -0
  46. package/dist/mention-clone.d.ts +79 -0
  47. package/dist/mention-clone.js +155 -0
  48. package/dist/mention.d.ts +81 -0
  49. package/dist/mention.js +131 -0
  50. package/dist/model-resolver.d.ts +36 -0
  51. package/dist/model-resolver.js +95 -0
  52. package/dist/model-scope.d.ts +49 -0
  53. package/dist/model-scope.js +48 -0
  54. package/dist/nested-tools.d.ts +57 -0
  55. package/dist/nested-tools.js +303 -0
  56. package/dist/output-file.d.ts +43 -0
  57. package/dist/output-file.js +153 -0
  58. package/dist/package-resources.d.ts +240 -0
  59. package/dist/package-resources.js +519 -0
  60. package/dist/prompts.d.ts +76 -0
  61. package/dist/prompts.js +121 -0
  62. package/dist/schedule-store.d.ts +38 -0
  63. package/dist/schedule-store.js +155 -0
  64. package/dist/schedule.d.ts +109 -0
  65. package/dist/schedule.js +359 -0
  66. package/dist/settings.d.ts +398 -0
  67. package/dist/settings.js +282 -0
  68. package/dist/skill-loader.d.ts +24 -0
  69. package/dist/skill-loader.js +93 -0
  70. package/dist/status-note.d.ts +61 -0
  71. package/dist/status-note.js +85 -0
  72. package/dist/structured-output.d.ts +61 -0
  73. package/dist/structured-output.js +112 -0
  74. package/dist/types.d.ts +391 -0
  75. package/dist/types.js +5 -0
  76. package/dist/ui/agent-mention.d.ts +82 -0
  77. package/dist/ui/agent-mention.js +187 -0
  78. package/dist/ui/agent-widget.d.ts +219 -0
  79. package/dist/ui/agent-widget.js +585 -0
  80. package/dist/ui/conversation-viewer.d.ts +177 -0
  81. package/dist/ui/conversation-viewer.js +905 -0
  82. package/dist/ui/fleet-list.d.ts +211 -0
  83. package/dist/ui/fleet-list.js +489 -0
  84. package/dist/ui/schedule-menu.d.ts +16 -0
  85. package/dist/ui/schedule-menu.js +94 -0
  86. package/dist/ui/select-item.d.ts +27 -0
  87. package/dist/ui/select-item.js +34 -0
  88. package/dist/ui/viewer-keys.d.ts +22 -0
  89. package/dist/ui/viewer-keys.js +18 -0
  90. package/dist/ui/workflow-card.d.ts +175 -0
  91. package/dist/ui/workflow-card.js +332 -0
  92. package/dist/ui/workflow-dialog.d.ts +305 -0
  93. package/dist/ui/workflow-dialog.js +843 -0
  94. package/dist/ui/workflow-menu.d.ts +60 -0
  95. package/dist/ui/workflow-menu.js +147 -0
  96. package/dist/usage.d.ts +135 -0
  97. package/dist/usage.js +120 -0
  98. package/dist/workflow/collisions.d.ts +95 -0
  99. package/dist/workflow/collisions.js +88 -0
  100. package/dist/workflow/entry.d.ts +32 -0
  101. package/dist/workflow/entry.js +29 -0
  102. package/dist/workflow/host.d.ts +62 -0
  103. package/dist/workflow/host.js +419 -0
  104. package/dist/workflow/journal.d.ts +97 -0
  105. package/dist/workflow/journal.js +120 -0
  106. package/dist/workflow/json-schema.d.ts +52 -0
  107. package/dist/workflow/json-schema.js +112 -0
  108. package/dist/workflow/meta.d.ts +67 -0
  109. package/dist/workflow/meta.js +317 -0
  110. package/dist/workflow/progress.d.ts +224 -0
  111. package/dist/workflow/progress.js +361 -0
  112. package/dist/workflow/runtime.d.ts +334 -0
  113. package/dist/workflow/runtime.js +830 -0
  114. package/dist/workflow/saved.d.ts +102 -0
  115. package/dist/workflow/saved.js +247 -0
  116. package/dist/workflow/task.d.ts +136 -0
  117. package/dist/workflow/task.js +207 -0
  118. package/dist/workflow/tool-description.d.ts +38 -0
  119. package/dist/workflow/tool-description.js +199 -0
  120. package/dist/workflow/worker-source.d.ts +47 -0
  121. package/dist/workflow/worker-source.js +778 -0
  122. package/dist/worktree.d.ts +52 -0
  123. package/dist/worktree.js +164 -0
  124. package/dist/xml.d.ts +10 -0
  125. package/dist/xml.js +12 -0
  126. package/docs/packages.md +211 -0
  127. package/docs/rpc.md +192 -0
  128. package/docs/workflows.md +447 -0
  129. package/examples/agent-tool-description.md +42 -0
  130. package/examples/workflows/compose.js +51 -0
  131. package/examples/workflows/fan-out-audit.js +47 -0
  132. package/examples/workflows/gated-fix.js +60 -0
  133. package/examples/workflows/lib/count-child.js +27 -0
  134. package/examples/workflows/review-panel.js +63 -0
  135. package/examples/workflows/structured-findings.js +78 -0
  136. package/package.json +74 -4
  137. package/src/abortable.ts +43 -0
  138. package/src/agent-color.ts +161 -0
  139. package/src/agent-file-toggle.ts +297 -0
  140. package/src/agent-manager.ts +1735 -0
  141. package/src/agent-record-entry.ts +153 -0
  142. package/src/agent-runner.ts +1468 -0
  143. package/src/agent-source-badge.ts +75 -0
  144. package/src/agent-types.ts +346 -0
  145. package/src/child-context.ts +15 -0
  146. package/src/completion-outbox.ts +116 -0
  147. package/src/context.ts +58 -0
  148. package/src/cross-extension-rpc.ts +221 -0
  149. package/src/custom-agents.ts +452 -0
  150. package/src/default-agents.ts +125 -0
  151. package/src/enabled-models.ts +180 -0
  152. package/src/env.ts +33 -0
  153. package/src/group-join.ts +141 -0
  154. package/src/index.ts +4433 -0
  155. package/src/invocation-config.ts +155 -0
  156. package/src/memory.ts +179 -0
  157. package/src/mention-clone.ts +195 -0
  158. package/src/mention.ts +141 -0
  159. package/src/model-resolver.ts +118 -0
  160. package/src/model-scope.ts +70 -0
  161. package/src/nested-tools.ts +426 -0
  162. package/src/output-file.ts +164 -0
  163. package/src/package-resources.ts +652 -0
  164. package/src/prompts.ts +171 -0
  165. package/src/schedule-store.ts +153 -0
  166. package/src/schedule.ts +386 -0
  167. package/src/settings.ts +650 -0
  168. package/src/skill-loader.ts +102 -0
  169. package/src/status-note.ts +90 -0
  170. package/src/structured-output.ts +130 -0
  171. package/src/types.ts +404 -0
  172. package/src/ui/agent-mention.ts +216 -0
  173. package/src/ui/agent-widget.ts +661 -0
  174. package/src/ui/conversation-viewer.ts +928 -0
  175. package/src/ui/fleet-list.ts +559 -0
  176. package/src/ui/schedule-menu.ts +105 -0
  177. package/src/ui/select-item.ts +45 -0
  178. package/src/ui/viewer-keys.ts +43 -0
  179. package/src/ui/workflow-card.ts +470 -0
  180. package/src/ui/workflow-dialog.ts +1115 -0
  181. package/src/ui/workflow-menu.ts +193 -0
  182. package/src/usage.ts +167 -0
  183. package/src/workflow/collisions.ts +123 -0
  184. package/src/workflow/entry.ts +47 -0
  185. package/src/workflow/host.ts +467 -0
  186. package/src/workflow/journal.ts +164 -0
  187. package/src/workflow/json-schema.ts +129 -0
  188. package/src/workflow/meta.ts +325 -0
  189. package/src/workflow/progress.ts +551 -0
  190. package/src/workflow/runtime.ts +1219 -0
  191. package/src/workflow/saved.ts +259 -0
  192. package/src/workflow/task.ts +302 -0
  193. package/src/workflow/tool-description.ts +200 -0
  194. package/src/workflow/worker-source.ts +781 -0
  195. package/src/worktree.ts +205 -0
  196. package/src/xml.ts +13 -0
@@ -0,0 +1,287 @@
1
+ /**
2
+ * agent-file-toggle.ts — Pure helpers for the `/agents` file-editing operations:
3
+ * locating an agent's .md file, toggling its `enabled:` frontmatter flag, and
4
+ * serializing an AgentConfig back to frontmatter for eject.
5
+ *
6
+ * These live outside src/index.ts so they can be tested directly: the `/agents`
7
+ * command handler is an ~890-line closure reached only through `registerCommand`,
8
+ * which every test mocks.
9
+ *
10
+ * The read side of this data (src/custom-agents.ts) parses frontmatter with a
11
+ * real YAML parser, so it honors `enabled: false` at any position in the block.
12
+ * This module must agree with it, and splits the work accordingly:
13
+ *
14
+ * - Deciding whether a file is disabled is a *read*, so it calls that same parser
15
+ * (`isDisabledContent`) instead of mirroring it. A mirror has to be right about
16
+ * YAML's boolean spellings and about pi's fence scan, and a regex was wrong
17
+ * about both.
18
+ * - *Editing* cannot go through the parser, because re-serializing a parsed
19
+ * document would reformat a file the README tells users to hand-author —
20
+ * discarding their comments, key order, and quoting. So the edits are line-wise
21
+ * and preserve everything they don't touch.
22
+ *
23
+ * That leaves removal best-effort: it recognizes a lowercase bare `false`, and
24
+ * reports `changed: false` for the spellings it cannot rewrite, so the caller
25
+ * refuses honestly rather than announcing a change it did not make.
26
+ */
27
+ import { existsSync } from "node:fs";
28
+ import { join, sep } from "node:path";
29
+ import { getAgentDir } from "@earendil-works/pi-coding-agent";
30
+ import { parseAgentFrontmatter } from "./custom-agents.js";
31
+ export const projectAgentsDir = (cwd = process.cwd()) => join(cwd, ".pi", "agents");
32
+ export const workspaceAgentsDir = (cwd = process.cwd()) => join(cwd, ".agents", "agents");
33
+ export const personalAgentsDir = () => join(getAgentDir(), "agents");
34
+ /**
35
+ * Find the file path of a custom agent by name, in discovery-precedence order
36
+ * (project, workspace, then global). Mirrors the load-side precedence in
37
+ * src/custom-agents.ts — if the two drift, `/agents` edits a file the loader
38
+ * isn't reading.
39
+ */
40
+ export function findAgentFile(name, cwd = process.cwd()) {
41
+ const projectPath = join(projectAgentsDir(cwd), `${name}.md`);
42
+ if (existsSync(projectPath))
43
+ return { path: projectPath, location: "project" };
44
+ const workspacePath = join(workspaceAgentsDir(cwd), `${name}.md`);
45
+ if (existsSync(workspacePath))
46
+ return { path: workspacePath, location: "workspace" };
47
+ const personalPath = join(personalAgentsDir(), `${name}.md`);
48
+ if (existsSync(personalPath))
49
+ return { path: personalPath, location: "personal" };
50
+ return undefined;
51
+ }
52
+ /**
53
+ * Find the *editable* file behind a loaded agent, preferring the path the loader
54
+ * actually read (`AgentConfig.sourcePath`) over the `<type>.md` guess.
55
+ *
56
+ * An agent's type comes from its frontmatter `name:` now, so the two can
57
+ * disagree: `reviewer.md` declaring `name: code-reviewer` is loaded as
58
+ * `code-reviewer`, and probing for `code-reviewer.md` finds nothing. That is
59
+ * not a harmless miss — `/agents → Disable` would then take the no-file branch
60
+ * and write a NEW `code-reviewer.md` stub, which loses to `reviewer.md` on
61
+ * load, leaving the agent enabled while reporting success.
62
+ *
63
+ * The probe stays as the fallback: a built-in that was never ejected has no
64
+ * `sourcePath`, and a path can go stale between a load and this call.
65
+ *
66
+ * **A package agent has no editable file.** Its `sourcePath` points inside pi's
67
+ * install root, where an edit is lost on the next `pi update` and a delete is
68
+ * undone by the next `pi install`. Passing `source` lets that rule live here
69
+ * rather than at each `/agents` call site: the package path is ignored, and the
70
+ * name probe runs instead — which finds the local stub shadowing it, if one
71
+ * exists, and otherwise nothing. Callers then take their no-file branch, which
72
+ * is the Eject-or-shadow behaviour a not-yet-ejected builtin already gets.
73
+ */
74
+ export function locateAgentFile(name, sourcePath, cwd = process.cwd(), source) {
75
+ if (source !== "package" && sourcePath && existsSync(sourcePath)) {
76
+ return { path: sourcePath, location: classifyAgentDir(sourcePath, cwd) };
77
+ }
78
+ return findAgentFile(name, cwd);
79
+ }
80
+ /**
81
+ * Which discovery location a loaded agent's file came from. Only ever names
82
+ * a directory in a confirmation prompt, so an unrecognized parent reports as
83
+ * personal rather than widening the type for a case that has no better answer.
84
+ *
85
+ * Package-provided paths never reach here: `locateAgentFile` drops them above,
86
+ * because none of the three locations this classifies is where they live.
87
+ */
88
+ function classifyAgentDir(path, cwd) {
89
+ if (path.startsWith(projectAgentsDir(cwd) + sep))
90
+ return "project";
91
+ if (path.startsWith(workspaceAgentsDir(cwd) + sep))
92
+ return "workspace";
93
+ return "personal";
94
+ }
95
+ /** A line that sets `enabled: false`, ignoring trailing whitespace / CR. */
96
+ const ENABLED_FALSE = /^enabled:[ \t]*false[ \t]*$/;
97
+ /** An opening or closing `---` fence line. */
98
+ const FENCE = /^---[ \t]*$/;
99
+ /**
100
+ * Split a file into its frontmatter lines and everything else, agreeing with
101
+ * what `parseAgentFrontmatter` (the load side) considers a frontmatter block —
102
+ * including its BOM normalisation, which is why the fence test looks past one.
103
+ * The BOM itself stays in `lines[0]`: it belongs to the file's encoding, not to
104
+ * the block, and an edit must not strip it from the user's file.
105
+ *
106
+ * Lines keep their terminators, so an edit preserves the file's existing line
107
+ * endings instead of rewriting CRLF to LF. Returns undefined when there is no
108
+ * usable block.
109
+ */
110
+ function splitFrontmatter(content) {
111
+ const lines = content.split(/(?<=\n)/);
112
+ if (lines.length === 0)
113
+ return undefined;
114
+ // The BOM stays where it is — it belongs to the file, not the block — so the
115
+ // fence test looks past it and every index below is unaffected.
116
+ const bom = content.startsWith("\uFEFF");
117
+ const first = (bom ? lines[0].slice(1) : lines[0]).replace(/\r?\n$/, "");
118
+ if (!FENCE.test(first))
119
+ return undefined;
120
+ const closeIdx = lines.findIndex((l, i) => i > 0 && FENCE.test(l.replace(/\r?\n$/, "")));
121
+ if (closeIdx === -1)
122
+ return undefined;
123
+ return { lines, openIdx: 0, closeIdx, eol: lines[0].endsWith("\r\n") ? "\r\n" : "\n" };
124
+ }
125
+ /**
126
+ * Does the loader consider this file disabled?
127
+ *
128
+ * Detection is a READ operation, so it asks the same parser the loader uses
129
+ * rather than mirroring it with a regex — that mirror has to be right about
130
+ * YAML's boolean spellings (`False`, `FALSE`, a trailing `# comment`, a quoted
131
+ * key) *and* about pi's fence scan, which closes the block on any line starting
132
+ * `---` and so ends it early on `----`. A throw means the file is already
133
+ * unparseable, which is what the loader sees too: it skips the agent, so there
134
+ * is no "disabled" state to report.
135
+ */
136
+ export function isDisabledContent(content) {
137
+ try {
138
+ return parseAgentFrontmatter(content).frontmatter.enabled === false;
139
+ }
140
+ catch {
141
+ return false;
142
+ }
143
+ }
144
+ /**
145
+ * Add `enabled: false` to a file's frontmatter.
146
+ *
147
+ * `outcome` distinguishes a real edit from a no-op so the caller can report
148
+ * honestly instead of unconditionally claiming success.
149
+ */
150
+ export function disableInContent(content) {
151
+ const block = splitFrontmatter(content);
152
+ if (!block)
153
+ return { content, outcome: "no-frontmatter" };
154
+ if (isDisabledContent(content))
155
+ return { content, outcome: "already-disabled" };
156
+ const lines = [...block.lines];
157
+ lines.splice(1, 0, `enabled: false${block.eol}`);
158
+ return { content: lines.join(""), outcome: "disabled" };
159
+ }
160
+ /**
161
+ * Remove `enabled: false` from a file's frontmatter, wherever it appears in the
162
+ * block — the loader honors the key at any position, so the two must agree or a
163
+ * hand-authored agent can be disabled and never re-enabled.
164
+ *
165
+ * `changed` is false when the key wasn't found, so the caller can avoid
166
+ * reporting "Enabled <name>" for a write that did nothing.
167
+ */
168
+ export function enableInContent(content) {
169
+ const block = splitFrontmatter(content);
170
+ if (!block)
171
+ return { content, changed: false };
172
+ const kept = block.lines.filter((l, i) => !(i > 0 && i < block.closeIdx && ENABLED_FALSE.test(l.replace(/\r?\n$/, ""))));
173
+ if (kept.length === block.lines.length)
174
+ return { content, changed: false };
175
+ return { content: kept.join(""), changed: true };
176
+ }
177
+ /** Is this the empty stub `/agents` writes when disabling a built-in default? */
178
+ export function isEmptyStub(content) {
179
+ return content.replace(/\r\n/g, "\n").trim() === "---\n---";
180
+ }
181
+ /**
182
+ * Build the .md file the create wizard writes.
183
+ *
184
+ * `description` and `model` come straight from a free-text prompt, so they are
185
+ * quoted rather than interpolated — `serializeAgentFile` above quotes the
186
+ * description for the same reason. An unquoted YAML scalar mishandles ordinary
187
+ * input in two ways, and both are silent: a colon ("Scout: find things") makes
188
+ * the file unparseable, and since #212 an unparseable agent file is *skipped*,
189
+ * so the wizard reports success for an agent that does not exist; a `#`
190
+ * ("audit #security") opens a comment and truncates the value. `model` can
191
+ * carry a colon too — pi accepts a `provider/model:thinking` suffix.
192
+ *
193
+ * `tools` and `thinking` are not quoted: both are chosen from fixed menus, and
194
+ * `tools` is a CSV that must stay a bare scalar for the loader's parser.
195
+ */
196
+ export function buildNewAgentFile(input) {
197
+ const modelLine = input.model ? `\nmodel: ${JSON.stringify(input.model)}` : "";
198
+ const thinkingLine = input.thinking ? `\nthinking: ${input.thinking}` : "";
199
+ return `---
200
+ description: ${JSON.stringify(input.description)}
201
+ tools: ${input.tools}${modelLine}${thinkingLine}
202
+ prompt_mode: replace
203
+ ---
204
+
205
+ ${input.systemPrompt}
206
+ `;
207
+ }
208
+ /**
209
+ * Rebuild the `tools:` CSV from the parts the loader split it into.
210
+ *
211
+ * `extSelectors` and `mcpToolPatterns` have to come back with the built-ins:
212
+ * `parseToolsField` splits `tools: read, ext:mcp/github` into `["read"]` and
213
+ * `["ext:mcp/github"]`, so writing only the first half hands the ejected copy a
214
+ * *narrower* toolset than the file it came from. That was invisible while Eject
215
+ * only ever ran on built-in defaults, which carry no selectors; a package agent can.
216
+ *
217
+ * Zero built-ins with selectors present is not `none` — `none` means no tools at
218
+ * all, while `ext:` entries alone mean "extension tools only", which the loader
219
+ * reads back from a `tools:` line carrying just those entries.
220
+ */
221
+ function formatToolsField(tools, extSelectors, mcpToolPatterns) {
222
+ const selectors = [...(extSelectors ?? []), ...(mcpToolPatterns ?? [])];
223
+ if (tools === undefined)
224
+ return selectors.length > 0 ? ["*", ...selectors].join(", ") : "all";
225
+ if (tools.length === 0)
226
+ return selectors.length > 0 ? selectors.join(", ") : "none";
227
+ return [...tools, ...selectors].join(", ");
228
+ }
229
+ /** Serialize an AgentConfig to a full .md file (frontmatter + system prompt) for eject. */
230
+ export function serializeAgentFile(cfg) {
231
+ const fmFields = [];
232
+ fmFields.push(`description: ${JSON.stringify(cfg.description)}`);
233
+ if (cfg.displayName)
234
+ fmFields.push(`display_name: ${cfg.displayName}`);
235
+ if (cfg.color)
236
+ fmFields.push(`color: ${JSON.stringify(cfg.color)}`);
237
+ // Absent means "all built-ins"; an EMPTY list means explicitly zero. Writing
238
+ // `all` for both would hand a deliberately tool-less agent the whole toolbox
239
+ // the first time it is ejected.
240
+ fmFields.push(`tools: ${formatToolsField(cfg.builtinToolNames, cfg.extSelectors, cfg.mcpToolPatterns)}`);
241
+ if (cfg.model)
242
+ fmFields.push(`model: ${cfg.model}`);
243
+ if (cfg.thinking)
244
+ fmFields.push(`thinking: ${cfg.thinking}`);
245
+ if (cfg.maxTurns)
246
+ fmFields.push(`max_turns: ${cfg.maxTurns}`);
247
+ if (cfg.allowedSubagents !== undefined) {
248
+ fmFields.push(`allowed_subagents: ${cfg.allowedSubagents === "all" ? "all" : cfg.allowedSubagents.join(", ")}`);
249
+ }
250
+ fmFields.push(`prompt_mode: ${cfg.promptMode}`);
251
+ if (cfg.extensions === false)
252
+ fmFields.push("extensions: false");
253
+ else if (Array.isArray(cfg.extensions))
254
+ fmFields.push(`extensions: ${cfg.extensions.join(", ")}`);
255
+ if (cfg.excludeExtensions?.length)
256
+ fmFields.push(`exclude_extensions: ${cfg.excludeExtensions.join(", ")}`);
257
+ if (cfg.skills === false)
258
+ fmFields.push("skills: false");
259
+ else if (Array.isArray(cfg.skills))
260
+ fmFields.push(`skills: ${cfg.skills.join(", ")}`);
261
+ if (cfg.disallowedTools?.length)
262
+ fmFields.push(`disallowed_tools: ${cfg.disallowedTools.join(", ")}`);
263
+ if (cfg.inheritContext)
264
+ fmFields.push("inherit_context: true");
265
+ // Both cases, not just `true`: with `backgroundByDefault` on, omitting the
266
+ // field means background, so `false` is the only way to pin an agent file to
267
+ // foreground and is no longer interchangeable with absence. Reachable since
268
+ // package agents became ejectable — a built-in default omits the field.
269
+ if (cfg.runInBackground !== undefined)
270
+ fmFields.push(`run_in_background: ${cfg.runInBackground}`);
271
+ if (cfg.outputTranscript === false)
272
+ fmFields.push("output_transcript: false");
273
+ if (cfg.isolated)
274
+ fmFields.push("isolated: true");
275
+ if (cfg.memory)
276
+ fmFields.push(`memory: ${cfg.memory}`);
277
+ if (cfg.isolation)
278
+ fmFields.push(`isolation: ${cfg.isolation}`);
279
+ // Also only reachable through a package agent: no built-in default sets
280
+ // either. Omitting them would have the ejected copy silently stop persisting
281
+ // its session, or write it somewhere else.
282
+ if (cfg.persistSession !== undefined)
283
+ fmFields.push(`persist_session: ${cfg.persistSession}`);
284
+ if (cfg.sessionDir)
285
+ fmFields.push(`session_dir: ${JSON.stringify(cfg.sessionDir)}`);
286
+ return `---\n${fmFields.join("\n")}\n---\n\n${cfg.systemPrompt}\n`;
287
+ }