@agimon-ai/po-team 0.0.0-alpha.21 → 0.0.0-alpha.210

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 (112) hide show
  1. package/LICENSE +95 -171
  2. package/NOTICE +35 -0
  3. package/README.md +24 -111
  4. package/dist/{agentDiscovery-ZNG8iZXV.mjs → agentDiscovery-BiMO2Ibu.mjs} +190 -193
  5. package/dist/agentDiscovery-BiMO2Ibu.mjs.map +1 -0
  6. package/dist/{agentDiscovery-DTTlM_LT.cjs → agentDiscovery-D0VcSETk.cjs} +268 -227
  7. package/dist/agentDiscovery-D0VcSETk.cjs.map +1 -0
  8. package/dist/apiContracts.cjs +1 -1
  9. package/dist/apiContracts.cjs.map +1 -1
  10. package/dist/apiContracts.d.mts +2 -2
  11. package/dist/apiContracts.mjs +1 -1
  12. package/dist/apiContracts.mjs.map +1 -1
  13. package/dist/{capabilityCeiling-BaHT9v9S.mjs → capabilityCeiling-DFcqYSTc.mjs} +3 -22
  14. package/dist/capabilityCeiling-DFcqYSTc.mjs.map +1 -0
  15. package/dist/{capabilityCeiling-CO3ZjYmY.cjs → capabilityCeiling-x2WmB2TL.cjs} +3 -22
  16. package/dist/capabilityCeiling-x2WmB2TL.cjs.map +1 -0
  17. package/dist/capabilityCeiling.cjs +2 -2
  18. package/dist/capabilityCeiling.d.mts +2 -4
  19. package/dist/capabilityCeiling.d.mts.map +1 -1
  20. package/dist/capabilityCeiling.mjs +2 -2
  21. package/dist/coordinatorSessions.cjs +14 -0
  22. package/dist/coordinatorSessions.d.mts +2 -0
  23. package/dist/coordinatorSessions.mjs +1 -0
  24. package/dist/env.cjs +1 -2
  25. package/dist/env.d.mts +2 -2
  26. package/dist/env.mjs +1 -1
  27. package/dist/{environment-BtvJI2S-.mjs → environment-BKQikJyW.mjs} +2 -11
  28. package/dist/environment-BKQikJyW.mjs.map +1 -0
  29. package/dist/{environment-Bz1OlWIT.d.mts → environment-CE9zbaE4.d.mts} +2 -9
  30. package/dist/environment-CE9zbaE4.d.mts.map +1 -0
  31. package/dist/{environment-Cqs7vHJL.cjs → environment-COaoVl5M.cjs} +1 -16
  32. package/dist/environment-COaoVl5M.cjs.map +1 -0
  33. package/dist/extensions/native.mjs +2477 -208
  34. package/dist/extensions/native.mjs.map +1 -1
  35. package/dist/extensions/server.cjs +4645 -3681
  36. package/dist/extensions/server.cjs.map +1 -1
  37. package/dist/extensions/server.d.mts.map +1 -1
  38. package/dist/extensions/server.mjs +5299 -4333
  39. package/dist/extensions/server.mjs.map +1 -1
  40. package/dist/extensions/web.mjs +1573 -573
  41. package/dist/extensions/web.mjs.map +1 -1
  42. package/dist/index.cjs +3 -4
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.d.mts +3 -3
  45. package/dist/index.mjs +2 -2
  46. package/dist/index.mjs.map +1 -1
  47. package/dist/po-runtime-identity.json +1 -0
  48. package/dist/runtimeSubagentPolicy.cjs +1 -1
  49. package/dist/runtimeSubagentPolicy.d.mts +1 -1
  50. package/dist/runtimeSubagentPolicy.mjs +1 -1
  51. package/dist/runtimeSubagentTool.cjs +1 -1
  52. package/dist/runtimeSubagentTool.d.mts +1 -1
  53. package/dist/runtimeSubagentTool.mjs +1 -1
  54. package/dist/{subagentPolicy-BE-OZoa-.d.mts → subagentPolicy-CN-AYfeB.d.mts} +1 -2
  55. package/dist/subagentPolicy-CN-AYfeB.d.mts.map +1 -0
  56. package/dist/{subagentPolicy-LfcXuqO5.mjs → subagentPolicy-CXqAT9aI.mjs} +1 -5
  57. package/dist/subagentPolicy-CXqAT9aI.mjs.map +1 -0
  58. package/dist/{subagentPolicy-DIpaKHO8.cjs → subagentPolicy-DYj_SOTG.cjs} +1 -5
  59. package/dist/subagentPolicy-DYj_SOTG.cjs.map +1 -0
  60. package/dist/subagentPolicy.cjs +1 -1
  61. package/dist/subagentPolicy.d.mts +1 -1
  62. package/dist/subagentPolicy.mjs +1 -1
  63. package/dist/{subagentTool-UdB3s6Mn.d.mts → subagentTool-BHY7OcDf.d.mts} +3 -3
  64. package/dist/{subagentTool-UdB3s6Mn.d.mts.map → subagentTool-BHY7OcDf.d.mts.map} +1 -1
  65. package/dist/{subagentTool-a2oh2v5B.mjs → subagentTool-CCeGXaPL.mjs} +3 -4
  66. package/dist/subagentTool-CCeGXaPL.mjs.map +1 -0
  67. package/dist/{subagentTool-BueNPGHo.cjs → subagentTool-CqXgI3iD.cjs} +3 -4
  68. package/dist/subagentTool-CqXgI3iD.cjs.map +1 -0
  69. package/dist/subagentTool.cjs +1 -1
  70. package/dist/subagentTool.d.mts +1 -1
  71. package/dist/subagentTool.mjs +1 -1
  72. package/dist/teamSnapshot.d.mts.map +1 -1
  73. package/llms.txt +12 -0
  74. package/locales/vi.json +325 -0
  75. package/locales/zh-CN.json +325 -0
  76. package/package.json +129 -43
  77. package/src/prompts/codemode-how-to-team/SKILL.md +71 -0
  78. package/src/prompts/help-how-to-team/SKILL.md +91 -0
  79. package/dist/agentDiscovery-DTTlM_LT.cjs.map +0 -1
  80. package/dist/agentDiscovery-ZNG8iZXV.mjs.map +0 -1
  81. package/dist/atomicJson-DRT03Ql5.cjs +0 -824
  82. package/dist/atomicJson-DRT03Ql5.cjs.map +0 -1
  83. package/dist/atomicJson-VVM1iAPu.mjs +0 -712
  84. package/dist/atomicJson-VVM1iAPu.mjs.map +0 -1
  85. package/dist/capabilityCeiling-BaHT9v9S.mjs.map +0 -1
  86. package/dist/capabilityCeiling-CO3ZjYmY.cjs.map +0 -1
  87. package/dist/environment-BtvJI2S-.mjs.map +0 -1
  88. package/dist/environment-Bz1OlWIT.d.mts.map +0 -1
  89. package/dist/environment-Cqs7vHJL.cjs.map +0 -1
  90. package/dist/fablePlan.cjs +0 -17
  91. package/dist/fablePlan.d.mts +0 -2
  92. package/dist/fablePlan.mjs +0 -1
  93. package/dist/fablePlanApi-BTNKjLni.d.mts +0 -97
  94. package/dist/fablePlanApi-BTNKjLni.d.mts.map +0 -1
  95. package/dist/fablePlanApi-BhI4jnDP.cjs +0 -207
  96. package/dist/fablePlanApi-BhI4jnDP.cjs.map +0 -1
  97. package/dist/fablePlanApi-DuMg43Hu.mjs +0 -118
  98. package/dist/fablePlanApi-DuMg43Hu.mjs.map +0 -1
  99. package/dist/fablePlanApi.cjs +0 -17
  100. package/dist/fablePlanApi.d.mts +0 -2
  101. package/dist/fablePlanApi.mjs +0 -1
  102. package/dist/rolldown-runtime-VH7oDXx4.cjs +0 -28
  103. package/dist/runs/background/cliRunnerEntry.cjs +0 -540
  104. package/dist/runs/background/cliRunnerEntry.cjs.map +0 -1
  105. package/dist/runs/background/cliRunnerEntry.d.mts +0 -1
  106. package/dist/runs/background/cliRunnerEntry.mjs +0 -537
  107. package/dist/runs/background/cliRunnerEntry.mjs.map +0 -1
  108. package/dist/subagentPolicy-BE-OZoa-.d.mts.map +0 -1
  109. package/dist/subagentPolicy-DIpaKHO8.cjs.map +0 -1
  110. package/dist/subagentPolicy-LfcXuqO5.mjs.map +0 -1
  111. package/dist/subagentTool-BueNPGHo.cjs.map +0 -1
  112. package/dist/subagentTool-a2oh2v5B.mjs.map +0 -1
@@ -1,8 +1,7 @@
1
1
  import * as path from "node:path";
2
2
  import { getOrThrow, readTextIfExists } from "@agimon-ai/po-core/platform";
3
- import * as fs from "node:fs";
4
- import * as os from "node:os";
5
3
  import { piAgentDirectory } from "@agimon-ai/po-core/piSettings";
4
+ import * as fs from "node:fs/promises";
6
5
  //#region src/services/agentFrontmatter/index.ts
7
6
  /**
8
7
  * Parsing the YAML frontmatter block at the head of an agent or chain file.
@@ -154,185 +153,6 @@ function parseFrontmatter(content) {
154
153
  };
155
154
  }
156
155
  //#endregion
157
- //#region src/services/configDir/index.ts
158
- /**
159
- * Locating the coding agent's config directory.
160
- *
161
- * The directory is normally `.pi`, but a rebranded build of the coding agent
162
- * can rename it, so the real name is discovered from the running installation
163
- * rather than assumed. Discovery order runs from most to least authoritative:
164
- * the loaded module's own export, then an explicitly configured package root,
165
- * then a walk upward from the process entry point, then the default.
166
- *
167
- * DESIGN PATTERNS:
168
- * - Resolution is a pure function of its inputs; the process-wide convenience
169
- * wrapper is a separate, memoized entry point
170
- * - Every discovery step is best-effort. A detached runner must still start
171
- * when package metadata is unreadable, so failures fall through to the default
172
- *
173
- * PERFORMANCE:
174
- * `getConfigDirName` is memoized because the uncached path walks from the entry
175
- * point to the filesystem root, reading and parsing a package.json per level.
176
- * Callers join it into paths, so it was previously re-walked per path built.
177
- *
178
- * AVOID:
179
- * - Hardcoding `.pi` at a call site
180
- * - Calling the uncached resolver on a hot path
181
- */
182
- const DEFAULT_CONFIG_DIR_NAME = ".pi";
183
- const PI_CODING_AGENT_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
184
- /** Overrides the upward package walk when the installation root is known. */
185
- const PI_CODING_AGENT_PACKAGE_ROOT_ENV = "PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT";
186
- function validConfigDirName(value) {
187
- return typeof value === "string" && value.trim() ? value : void 0;
188
- }
189
- /** Read the config dir name from a directory, if it is the coding agent's package root. */
190
- function readConfigDirNameFromPackageRoot(packageRoot) {
191
- if (!packageRoot) return void 0;
192
- try {
193
- const manifest = JSON.parse(fs.readFileSync(path.join(packageRoot, "package.json"), "utf-8"));
194
- if (typeof manifest !== "object" || manifest === null) return void 0;
195
- const record = manifest;
196
- if (record.name !== PI_CODING_AGENT_PACKAGE_NAME) return void 0;
197
- return validConfigDirName((typeof record.piConfig === "object" && record.piConfig !== null ? record.piConfig : void 0)?.configDir);
198
- } catch {
199
- return;
200
- }
201
- }
202
- function resolveConfigDirNameFromPackageJson(entryPoint = process.argv[1], packageRoot = process.env[PI_CODING_AGENT_PACKAGE_ROOT_ENV]) {
203
- const configuredRootValue = readConfigDirNameFromPackageRoot(packageRoot);
204
- if (configuredRootValue) return configuredRootValue;
205
- if (!entryPoint) return void 0;
206
- try {
207
- let dir = path.dirname(fs.realpathSync(entryPoint));
208
- while (dir !== path.dirname(dir)) {
209
- const value = readConfigDirNameFromPackageRoot(dir);
210
- if (value) return value;
211
- dir = path.dirname(dir);
212
- }
213
- } catch {}
214
- }
215
- /**
216
- * Resolve the config directory name from explicit inputs.
217
- *
218
- * Pure with respect to its arguments, which is what makes it testable; the
219
- * process-wide answer comes from `getConfigDirName`.
220
- */
221
- function resolveConfigDirName(codingAgentModule, entryPoint, packageRoot) {
222
- return (codingAgentModule && typeof codingAgentModule === "object" ? validConfigDirName(codingAgentModule.CONFIG_DIR_NAME) : void 0) ?? resolveConfigDirNameFromPackageJson(entryPoint, packageRoot) ?? DEFAULT_CONFIG_DIR_NAME;
223
- }
224
- let memoizedConfigDirName;
225
- /** The config directory name for this process. Resolved once, then reused. */
226
- function getConfigDirName(environment = process.env) {
227
- if (environment !== process.env) return resolveConfigDirName(void 0, process.argv[1], environment["PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT"] ?? "");
228
- memoizedConfigDirName ??= resolveConfigDirName();
229
- return memoizedConfigDirName;
230
- }
231
- /** The project-local config directory, for example `<projectRoot>/.pi`. */
232
- function getProjectConfigDir(projectRoot, environment = process.env) {
233
- return path.join(projectRoot, getConfigDirName(environment));
234
- }
235
- /** The user-level agent directory Po runs with, from Po's own resolver. */
236
- function getAgentDir(environment = process.env) {
237
- return piAgentDirectory(environment, environment.HOME ?? os.homedir());
238
- }
239
- //#endregion
240
- //#region src/services/agentProjectRoot/sync.ts
241
- /** @deprecated Node-only shim. */
242
- /**
243
- * Locating the project root that agent configuration hangs off.
244
- *
245
- * A project root is any ancestor of the working directory that carries a config
246
- * directory or a legacy `.agents` directory. There can be several: a package
247
- * inside a monorepo and the monorepo itself both qualify. Which one wins is a
248
- * setting, because both answers are legitimate. Teams that keep one shared set
249
- * of agents at the repository root want `git-root`, teams that give each package
250
- * its own want `nearest`, and neither can be inferred from the tree alone.
251
- *
252
- * DESIGN PATTERNS:
253
- * - Candidates are collected once, nearest first, then a policy picks from them.
254
- * Separating collection from policy is what lets `git-root` be answered
255
- * without a second walk
256
- * - Path derivation goes through `shared/configDir.ts`, so a rebranded build
257
- * that renames its config directory needs no change here
258
- *
259
- * AVOID:
260
- * - Hardcoding the config directory name; it is discovered, not assumed
261
- * - Treating the nearest candidate as the project root without reading the
262
- * setting first
263
- */
264
- /** Stable cache identity for equivalent absolute, relative, and symlinked cwd spellings. */
265
- function canonicalizeDiscoveryCwd$1(cwd) {
266
- const resolved = path.resolve(cwd);
267
- try {
268
- return fs.realpathSync.native(resolved);
269
- } catch {
270
- return resolved;
271
- }
272
- }
273
- //#endregion
274
- //#region src/services/agentMemory/index.ts
275
- /** Tools that let an agent append to its own memory file. */
276
- const WRITE_TOOLS = /* @__PURE__ */ new Set([
277
- "edit",
278
- "write",
279
- "bash"
280
- ]);
281
- function unquoteFrontmatterValue(value) {
282
- const trimmed = value.trim();
283
- if (trimmed.startsWith("\"") && trimmed.endsWith("\"") || trimmed.startsWith("'") && trimmed.endsWith("'")) return trimmed.slice(1, -1);
284
- return trimmed;
285
- }
286
- function parseMemoryScope(value) {
287
- return value === "project" || value === "user" ? value : void 0;
288
- }
289
- function parseMemoryBoolean(value) {
290
- if (value === "true") return true;
291
- if (value === "false") return false;
292
- }
293
- function parsePositiveInteger(value) {
294
- if (value === void 0) return void 0;
295
- const parsed = Number(value);
296
- return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
297
- }
298
- /** Split a `memory` frontmatter block into key/value pairs, either spelling. */
299
- function readMemoryEntries(raw) {
300
- const entries = /* @__PURE__ */ new Map();
301
- const inlineObject = raw.trim().match(/^\{(.*)\}$/s);
302
- const parts = inlineObject?.[1] !== void 0 ? inlineObject[1].split(",") : raw.split("\n");
303
- for (const part of parts) {
304
- const match = part.trim().match(/^([\w-]+)\s*:\s*(.*)$/);
305
- if (!match?.[1] || match[2] === void 0) continue;
306
- entries.set(match[1], unquoteFrontmatterValue(match[2]));
307
- }
308
- return entries;
309
- }
310
- /**
311
- * Parse a `memory` frontmatter block, or undefined when it declares nothing.
312
- *
313
- * Accepts both the inline `{ scope: project }` form and the indented block form,
314
- * because agent files in the wild use each.
315
- */
316
- function parseMemoryFrontmatter(raw) {
317
- if (!raw) return void 0;
318
- const entries = readMemoryEntries(raw);
319
- const enabled = parseMemoryBoolean(entries.get("enabled"));
320
- const scope = parseMemoryScope(entries.get("scope"));
321
- const maxEntries = parsePositiveInteger(entries.get("maxEntries"));
322
- if (enabled === void 0 && scope === void 0 && maxEntries === void 0) return void 0;
323
- const config = {};
324
- if (enabled !== void 0) config.enabled = enabled;
325
- if (scope !== void 0) config.scope = scope;
326
- if (maxEntries !== void 0) config.maxEntries = maxEntries;
327
- return config;
328
- }
329
- /** Whether an agent can write files this run. An unset `tools` inherits the builtins. */
330
- function agentHasWriteTools(agent) {
331
- const tools = agent.tools;
332
- if (!tools) return true;
333
- return tools.some((tool) => WRITE_TOOLS.has(tool));
334
- }
335
- //#endregion
336
156
  //#region src/services/agentProjectRoot/index.ts
337
157
  /**
338
158
  * Locating the project root that agent configuration hangs off.
@@ -396,14 +216,16 @@ async function canonicalizeDiscoveryCwd(io, cwd) {
396
216
  return resolved;
397
217
  }
398
218
  }
219
+ /** What a path names once symlinks are followed, or undefined when it cannot be resolved or read. */
220
+ async function statFollowing(io, filePath) {
221
+ const canonical = await io.fs.canonicalPath(filePath, io.context);
222
+ if (!canonical.ok) return void 0;
223
+ const info = await io.fs.fileInfo(canonical.value, io.context);
224
+ return info.ok ? info.value : void 0;
225
+ }
399
226
  /** Whether a path exists and is a directory. Any failure reads as "no". */
400
227
  async function isDirectory(io, dirPath) {
401
- try {
402
- const canonical = getOrThrow(await io.fs.canonicalPath(dirPath, io.context));
403
- return getOrThrow(await io.fs.fileInfo(canonical, io.context)).kind === "directory";
404
- } catch {
405
- return false;
406
- }
228
+ return (await statFollowing(io, dirPath))?.kind === "directory";
407
229
  }
408
230
  /** True when `dir` carries either marker that makes it a project root. */
409
231
  async function isProjectRootCandidate(io, dir) {
@@ -514,6 +336,156 @@ async function resolveNearestProjectAgentDirs(io, cwd) {
514
336
  };
515
337
  }
516
338
  //#endregion
339
+ //#region src/services/codingAgentHost/index.ts
340
+ /**
341
+ * Facts about the host the coding agent runs on: its installation and the
342
+ * executables it can launch.
343
+ *
344
+ * The config directory is normally `.pi`, but a rebranded build of the coding
345
+ * agent can rename it, so the real name is discovered from the running
346
+ * installation rather than assumed. Discovery order runs from most to least
347
+ * authoritative: the loaded module's own export, then an explicitly configured
348
+ * package root, then a walk upward from the process entry point, then the
349
+ * default.
350
+ *
351
+ * Node-only: an installation and its executables are files on this host. The
352
+ * edge build swaps in `index.edge.ts`, where neither exists.
353
+ *
354
+ * DESIGN PATTERNS:
355
+ * - Every discovery step is best-effort. A detached runner must still start
356
+ * when package metadata is unreadable, so failures fall through to the default
357
+ *
358
+ * PERFORMANCE:
359
+ * Discovery is memoized per package root because the uncached path walks from
360
+ * the entry point to the filesystem root, reading and parsing a package.json
361
+ * per level.
362
+ */
363
+ const DEFAULT_CONFIG_DIR_NAME = ".pi";
364
+ const PI_CODING_AGENT_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
365
+ /** Whether this host may execute the file, by the operating system's own rule. */
366
+ async function canExecute(filePath) {
367
+ try {
368
+ await fs.access(filePath, fs.constants.X_OK);
369
+ return true;
370
+ } catch {
371
+ return false;
372
+ }
373
+ }
374
+ function validConfigDirName(value) {
375
+ return typeof value === "string" && value.trim() ? value : void 0;
376
+ }
377
+ /** Read the config dir name from a directory, if it is the coding agent's package root. */
378
+ async function readConfigDirNameFromPackageRoot(packageRoot) {
379
+ if (!packageRoot) return void 0;
380
+ try {
381
+ const manifest = JSON.parse(await fs.readFile(path.join(packageRoot, "package.json"), "utf-8"));
382
+ if (typeof manifest !== "object" || manifest === null) return void 0;
383
+ const record = manifest;
384
+ if (record.name !== PI_CODING_AGENT_PACKAGE_NAME) return void 0;
385
+ return validConfigDirName((typeof record.piConfig === "object" && record.piConfig !== null ? record.piConfig : void 0)?.configDir);
386
+ } catch {
387
+ return;
388
+ }
389
+ }
390
+ async function resolveConfigDirNameFromPackageJson(entryPoint, packageRoot) {
391
+ const configuredRootValue = await readConfigDirNameFromPackageRoot(packageRoot);
392
+ if (configuredRootValue) return configuredRootValue;
393
+ if (!entryPoint) return void 0;
394
+ try {
395
+ let dir = path.dirname(await fs.realpath(entryPoint));
396
+ while (dir !== path.dirname(dir)) {
397
+ const value = await readConfigDirNameFromPackageRoot(dir);
398
+ if (value) return value;
399
+ dir = path.dirname(dir);
400
+ }
401
+ } catch {}
402
+ }
403
+ /** Resolve the config directory name from explicit inputs. Pure with respect to its arguments. */
404
+ async function resolveConfigDirName(codingAgentModule, entryPoint, packageRoot) {
405
+ return (codingAgentModule && typeof codingAgentModule === "object" ? validConfigDirName(codingAgentModule.CONFIG_DIR_NAME) : void 0) ?? await resolveConfigDirNameFromPackageJson(entryPoint, packageRoot) ?? DEFAULT_CONFIG_DIR_NAME;
406
+ }
407
+ const discovered = /* @__PURE__ */ new Map();
408
+ /** This installation's config directory name, walking up from the process entry point. Memoized per root. */
409
+ function discoverConfigDirName(packageRoot) {
410
+ const key = packageRoot ?? "";
411
+ let name = discovered.get(key);
412
+ if (!name) {
413
+ name = resolveConfigDirName(void 0, process.argv[1], packageRoot);
414
+ discovered.set(key, name);
415
+ }
416
+ return name;
417
+ }
418
+ /** The config directory name for this installation, resolved once per package root. */
419
+ async function getConfigDirName(environment = {}) {
420
+ return discoverConfigDirName(environment["PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT"] || void 0);
421
+ }
422
+ /** The user-level agent directory Po runs with, from Po's own resolver. */
423
+ function getAgentDir(environment, homeDirectory) {
424
+ return piAgentDirectory(environment, homeDirectory);
425
+ }
426
+ //#endregion
427
+ //#region src/services/agentMemory/index.ts
428
+ /** Tools that let an agent append to its own memory file. */
429
+ const WRITE_TOOLS = /* @__PURE__ */ new Set([
430
+ "edit",
431
+ "write",
432
+ "bash"
433
+ ]);
434
+ function unquoteFrontmatterValue(value) {
435
+ const trimmed = value.trim();
436
+ if (trimmed.startsWith("\"") && trimmed.endsWith("\"") || trimmed.startsWith("'") && trimmed.endsWith("'")) return trimmed.slice(1, -1);
437
+ return trimmed;
438
+ }
439
+ function parseMemoryScope(value) {
440
+ return value === "project" || value === "user" ? value : void 0;
441
+ }
442
+ function parseMemoryBoolean(value) {
443
+ if (value === "true") return true;
444
+ if (value === "false") return false;
445
+ }
446
+ function parsePositiveInteger(value) {
447
+ if (value === void 0) return void 0;
448
+ const parsed = Number(value);
449
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
450
+ }
451
+ /** Split a `memory` frontmatter block into key/value pairs, either spelling. */
452
+ function readMemoryEntries(raw) {
453
+ const entries = /* @__PURE__ */ new Map();
454
+ const inlineObject = raw.trim().match(/^\{(.*)\}$/s);
455
+ const parts = inlineObject?.[1] !== void 0 ? inlineObject[1].split(",") : raw.split("\n");
456
+ for (const part of parts) {
457
+ const match = part.trim().match(/^([\w-]+)\s*:\s*(.*)$/);
458
+ if (!match?.[1] || match[2] === void 0) continue;
459
+ entries.set(match[1], unquoteFrontmatterValue(match[2]));
460
+ }
461
+ return entries;
462
+ }
463
+ /**
464
+ * Parse a `memory` frontmatter block, or undefined when it declares nothing.
465
+ *
466
+ * Accepts both the inline `{ scope: project }` form and the indented block form,
467
+ * because agent files in the wild use each.
468
+ */
469
+ function parseMemoryFrontmatter(raw) {
470
+ if (!raw) return void 0;
471
+ const entries = readMemoryEntries(raw);
472
+ const enabled = parseMemoryBoolean(entries.get("enabled"));
473
+ const scope = parseMemoryScope(entries.get("scope"));
474
+ const maxEntries = parsePositiveInteger(entries.get("maxEntries"));
475
+ if (enabled === void 0 && scope === void 0 && maxEntries === void 0) return void 0;
476
+ const config = {};
477
+ if (enabled !== void 0) config.enabled = enabled;
478
+ if (scope !== void 0) config.scope = scope;
479
+ if (maxEntries !== void 0) config.maxEntries = maxEntries;
480
+ return config;
481
+ }
482
+ /** Whether an agent can write files this run. An unset `tools` inherits the builtins. */
483
+ function agentHasWriteTools(agent) {
484
+ const tools = agent.tools;
485
+ if (!tools) return true;
486
+ return tools.some((tool) => WRITE_TOOLS.has(tool));
487
+ }
488
+ //#endregion
517
489
  //#region src/services/agentSettings/index.ts
518
490
  const SUBAGENTS_SETTINGS_KEY = "subagents";
519
491
  const AGENT_OVERRIDES_KEY = "agentOverrides";
@@ -835,6 +807,30 @@ function applySubagentDefaults(agents, defaultModel, defaultThinking, defaultExt
835
807
  return applySubagentDefaultExtensions(applySubagentDefaultThinking(applySubagentDefaultFallbackModels(applySubagentDefaultModel(agents, defaultModel), defaultFallbackModels), defaultThinking), defaultExtensions);
836
808
  }
837
809
  /**
810
+ * Apply `subagents.agents` from Po config: the person picked these for one named agent, so they win
811
+ * over that agent's frontmatter and every default. A run call's own `model` still wins over them.
812
+ */
813
+ function applyConfiguredAgents(agents, configured, path) {
814
+ if (!configured) return agents;
815
+ return agents.map((agent) => {
816
+ const entry = Object.hasOwn(configured, agent.name) ? configured[agent.name] : void 0;
817
+ if (!entry?.model && !entry?.thinking) return agent;
818
+ return inheritFrontmatterFields(agent, {
819
+ ...agent,
820
+ ...entry.model ? {
821
+ model: entry.model,
822
+ modelSource: {
823
+ type: "config.subagents.agents",
824
+ scope: "config",
825
+ path,
826
+ model: entry.model
827
+ }
828
+ } : {},
829
+ ...entry.thinking ? { thinking: entry.thinking } : {}
830
+ });
831
+ });
832
+ }
833
+ /**
838
834
  * Snapshot the fields an override may replace, so it can be undone.
839
835
  *
840
836
  * `extensions` is omitted when it came from a settings default rather than the
@@ -1421,21 +1417,22 @@ var AgentDiscoveryService = class {
1421
1417
  const userSettings = scope === "project" ? EMPTY_SUBAGENT_SETTINGS : await readSubagentSettings(this.io, userSettingsPath);
1422
1418
  const projectSettings = scope === "user" ? EMPTY_SUBAGENT_SETTINGS : await readSubagentSettings(this.io, projectSettingsPath);
1423
1419
  const legacyDefaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath);
1420
+ const configModels = team?.defaults?.model !== void 0 || team?.defaults?.fallbackModels !== void 0;
1424
1421
  const packagePrimaryModel = team?.models?.[0];
1425
1422
  const defaultModel = packagePrimaryModel && team ? {
1426
- type: "packages.team.defaultModel",
1427
- scope: "package",
1423
+ type: configModels ? "config.subagents.model" : "packages.team.defaultModel",
1424
+ scope: configModels ? "config" : "package",
1428
1425
  path: team.path ?? "",
1429
1426
  model: packagePrimaryModel
1430
1427
  } : legacyDefaultModel;
1431
- const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
1428
+ const defaultThinking = team?.defaults?.thinking ?? resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
1432
1429
  const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
1433
1430
  const resolve = (agents) => applyCustomAgentOverrides(applySubagentDefaults(agents, defaultModel, defaultThinking, defaultExtensions), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
1434
1431
  const projectDirs = await resolveNearestProjectAgentDirs(this.io, cwd);
1435
1432
  const loadDirs = async (dirs, source) => resolve((await Promise.all(dirs.map((dir) => loadAgentsFromDir(this.io, dir, source)))).flat());
1436
1433
  const plugin = await loadDirs(pluginAgentDirs(this.io.environment), "plugin");
1437
1434
  return {
1438
- agents: mergeAgentsForScope(scope, scope === "project" ? [] : await loadDirs(userAgentDirs(this.io), "user"), scope === "user" ? [] : await loadDirs(projectDirs.readDirs, "project"), plugin).filter((agent) => agent.disabled !== true),
1435
+ agents: applyConfiguredAgents(mergeAgentsForScope(scope, scope === "project" ? [] : await loadDirs(userAgentDirs(this.io), "user"), scope === "user" ? [] : await loadDirs(projectDirs.readDirs, "project"), plugin), team?.defaults?.agents, "config.yaml").filter((agent) => agent.disabled !== true),
1439
1436
  projectAgentsDir: projectDirs.preferredDir,
1440
1437
  modelScope: projectSettings.modelScope ?? userSettings.modelScope
1441
1438
  };
@@ -1455,6 +1452,6 @@ function cloneResult(result) {
1455
1452
  };
1456
1453
  }
1457
1454
  //#endregion
1458
- export { getAgentDir as a, canonicalizeDiscoveryCwd$1 as i, LruCache as n, getConfigDirName as o, agentHasWriteTools as r, getProjectConfigDir as s, AgentDiscoveryService as t };
1455
+ export { getConfigDirName as a, resolveNearestProjectAgentDirs as c, getAgentDir as i, statFollowing as l, LruCache as n, canExecute as o, agentHasWriteTools as r, canonicalizeDiscoveryCwd as s, AgentDiscoveryService as t, parseFrontmatter as u };
1459
1456
 
1460
- //# sourceMappingURL=agentDiscovery-ZNG8iZXV.mjs.map
1457
+ //# sourceMappingURL=agentDiscovery-BiMO2Ibu.mjs.map