@agimon-ai/po-team 0.0.0-alpha.149 → 0.0.0-alpha.150
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.
- package/dist/{agentDiscovery-4MvlNlGi.cjs → agentDiscovery-C-RbBodf.cjs} +197 -220
- package/dist/agentDiscovery-C-RbBodf.cjs.map +1 -0
- package/dist/{agentDiscovery-Dwa6VguJ.mjs → agentDiscovery-CCOjpnJ-.mjs} +161 -189
- package/dist/agentDiscovery-CCOjpnJ-.mjs.map +1 -0
- package/dist/extensions/native.mjs +1 -0
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +336 -396
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.mjs +337 -395
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +1 -0
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +10 -10
- package/dist/agentDiscovery-4MvlNlGi.cjs.map +0 -1
- package/dist/agentDiscovery-Dwa6VguJ.mjs.map +0 -1
|
@@ -23,11 +23,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
let node_path = require("node:path");
|
|
24
24
|
node_path = __toESM(node_path, 1);
|
|
25
25
|
let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
|
|
26
|
+
let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
|
|
26
27
|
let node_fs_promises = require("node:fs/promises");
|
|
27
28
|
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
28
|
-
let node_os = require("node:os");
|
|
29
|
-
node_os = __toESM(node_os, 1);
|
|
30
|
-
let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
|
|
31
29
|
//#region src/services/agentFrontmatter/index.ts
|
|
32
30
|
/**
|
|
33
31
|
* Parsing the YAML frontmatter block at the head of an agent or chain file.
|
|
@@ -179,213 +177,6 @@ function parseFrontmatter(content) {
|
|
|
179
177
|
};
|
|
180
178
|
}
|
|
181
179
|
//#endregion
|
|
182
|
-
//#region src/services/configDir/index.ts
|
|
183
|
-
/**
|
|
184
|
-
* Locating the coding agent's config directory.
|
|
185
|
-
*
|
|
186
|
-
* The directory is normally `.pi`, but a rebranded build of the coding agent
|
|
187
|
-
* can rename it, so the real name is discovered from the running installation
|
|
188
|
-
* rather than assumed. Discovery order runs from most to least authoritative:
|
|
189
|
-
* the loaded module's own export, then an explicitly configured package root,
|
|
190
|
-
* then a walk upward from the process entry point, then the default.
|
|
191
|
-
*
|
|
192
|
-
* DESIGN PATTERNS:
|
|
193
|
-
* - Resolution is a pure function of its inputs; the process-wide convenience
|
|
194
|
-
* wrapper is a separate, memoized entry point
|
|
195
|
-
* - Every discovery step is best-effort. A detached runner must still start
|
|
196
|
-
* when package metadata is unreadable, so failures fall through to the default
|
|
197
|
-
*
|
|
198
|
-
* PERFORMANCE:
|
|
199
|
-
* `getConfigDirName` is memoized because the uncached path walks from the entry
|
|
200
|
-
* point to the filesystem root, reading and parsing a package.json per level.
|
|
201
|
-
* Callers join it into paths, so it was previously re-walked per path built.
|
|
202
|
-
*
|
|
203
|
-
* AVOID:
|
|
204
|
-
* - Hardcoding `.pi` at a call site
|
|
205
|
-
* - Calling the uncached resolver on a hot path
|
|
206
|
-
*/
|
|
207
|
-
const DEFAULT_CONFIG_DIR_NAME = ".pi";
|
|
208
|
-
const PI_CODING_AGENT_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
|
|
209
|
-
/** Overrides the upward package walk when the installation root is known. */
|
|
210
|
-
const PI_CODING_AGENT_PACKAGE_ROOT_ENV = "PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT";
|
|
211
|
-
function validConfigDirName(value) {
|
|
212
|
-
return typeof value === "string" && value.trim() ? value : void 0;
|
|
213
|
-
}
|
|
214
|
-
/** Read the config dir name from a directory, if it is the coding agent's package root. */
|
|
215
|
-
async function readConfigDirNameFromPackageRoot(packageRoot) {
|
|
216
|
-
if (!packageRoot) return void 0;
|
|
217
|
-
try {
|
|
218
|
-
const manifest = JSON.parse(await node_fs_promises.readFile(node_path.join(packageRoot, "package.json"), "utf-8"));
|
|
219
|
-
if (typeof manifest !== "object" || manifest === null) return void 0;
|
|
220
|
-
const record = manifest;
|
|
221
|
-
if (record.name !== PI_CODING_AGENT_PACKAGE_NAME) return void 0;
|
|
222
|
-
return validConfigDirName((typeof record.piConfig === "object" && record.piConfig !== null ? record.piConfig : void 0)?.configDir);
|
|
223
|
-
} catch {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
async function resolveConfigDirNameFromPackageJson(entryPoint = process.argv[1], packageRoot = process.env[PI_CODING_AGENT_PACKAGE_ROOT_ENV]) {
|
|
228
|
-
const configuredRootValue = await readConfigDirNameFromPackageRoot(packageRoot);
|
|
229
|
-
if (configuredRootValue) return configuredRootValue;
|
|
230
|
-
if (!entryPoint) return void 0;
|
|
231
|
-
try {
|
|
232
|
-
let dir = node_path.dirname(await node_fs_promises.realpath(entryPoint));
|
|
233
|
-
while (dir !== node_path.dirname(dir)) {
|
|
234
|
-
const value = await readConfigDirNameFromPackageRoot(dir);
|
|
235
|
-
if (value) return value;
|
|
236
|
-
dir = node_path.dirname(dir);
|
|
237
|
-
}
|
|
238
|
-
} catch {}
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Resolve the config directory name from explicit inputs.
|
|
242
|
-
*
|
|
243
|
-
* Pure with respect to its arguments, which is what makes it testable; the
|
|
244
|
-
* process-wide answer comes from `getConfigDirName`.
|
|
245
|
-
*/
|
|
246
|
-
async function resolveConfigDirName(codingAgentModule, entryPoint, packageRoot) {
|
|
247
|
-
return (codingAgentModule && typeof codingAgentModule === "object" ? validConfigDirName(codingAgentModule.CONFIG_DIR_NAME) : void 0) ?? await resolveConfigDirNameFromPackageJson(entryPoint, packageRoot) ?? DEFAULT_CONFIG_DIR_NAME;
|
|
248
|
-
}
|
|
249
|
-
let memoizedConfigDirName;
|
|
250
|
-
/** The config directory name for this process. Resolved once, then reused. */
|
|
251
|
-
async function getConfigDirName(environment = process.env) {
|
|
252
|
-
if (environment !== process.env) return resolveConfigDirName(void 0, process.argv[1], environment["PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT"] ?? "");
|
|
253
|
-
memoizedConfigDirName ??= resolveConfigDirName();
|
|
254
|
-
return memoizedConfigDirName;
|
|
255
|
-
}
|
|
256
|
-
/** The project-local config directory, for example `<projectRoot>/.pi`. */
|
|
257
|
-
async function getProjectConfigDir(projectRoot, environment = process.env) {
|
|
258
|
-
return node_path.join(projectRoot, await getConfigDirName(environment));
|
|
259
|
-
}
|
|
260
|
-
/** The user-level agent directory Po runs with, from Po's own resolver. */
|
|
261
|
-
function getAgentDir(environment = process.env) {
|
|
262
|
-
return (0, _agimon_ai_po_core_piSettings.piAgentDirectory)(environment, environment.HOME ?? node_os.homedir());
|
|
263
|
-
}
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/services/agentProjectRoot/sync.ts
|
|
266
|
-
/** @deprecated Node-only shim. */
|
|
267
|
-
/**
|
|
268
|
-
* Locating the project root that agent configuration hangs off.
|
|
269
|
-
*
|
|
270
|
-
* A project root is any ancestor of the working directory that carries a config
|
|
271
|
-
* directory or a legacy `.agents` directory. There can be several: a package
|
|
272
|
-
* inside a monorepo and the monorepo itself both qualify. Which one wins is a
|
|
273
|
-
* setting, because both answers are legitimate. Teams that keep one shared set
|
|
274
|
-
* of agents at the repository root want `git-root`, teams that give each package
|
|
275
|
-
* its own want `nearest`, and neither can be inferred from the tree alone.
|
|
276
|
-
*
|
|
277
|
-
* DESIGN PATTERNS:
|
|
278
|
-
* - Candidates are collected once, nearest first, then a policy picks from them.
|
|
279
|
-
* Separating collection from policy is what lets `git-root` be answered
|
|
280
|
-
* without a second walk
|
|
281
|
-
* - Path derivation goes through `shared/configDir.ts`, so a rebranded build
|
|
282
|
-
* that renames its config directory needs no change here
|
|
283
|
-
*
|
|
284
|
-
* AVOID:
|
|
285
|
-
* - Hardcoding the config directory name; it is discovered, not assumed
|
|
286
|
-
* - Treating the nearest candidate as the project root without reading the
|
|
287
|
-
* setting first
|
|
288
|
-
*/
|
|
289
|
-
/** Stable cache identity for equivalent absolute, relative, and symlinked cwd spellings. */
|
|
290
|
-
async function canonicalizeDiscoveryCwd$1(cwd) {
|
|
291
|
-
const resolved = node_path.resolve(cwd);
|
|
292
|
-
try {
|
|
293
|
-
return await node_fs_promises.realpath(resolved);
|
|
294
|
-
} catch {
|
|
295
|
-
return resolved;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
//#endregion
|
|
299
|
-
//#region src/services/agentMemory/index.ts
|
|
300
|
-
/**
|
|
301
|
-
* Per-agent persistent memory, injected into a child system prompt.
|
|
302
|
-
*
|
|
303
|
-
* An agent may opt into a durable, role-specific memory scope via its `memory`
|
|
304
|
-
* frontmatter. The opening lines of a `MEMORY.md` in the resolved directory are
|
|
305
|
-
* injected so a recurring custom agent can recall accumulated role notes:
|
|
306
|
-
* threat models, gotchas, verified commands, decisions. An agent with no write
|
|
307
|
-
* tools gets a read-only variant of the block instead.
|
|
308
|
-
*
|
|
309
|
-
* DESIGN PATTERNS:
|
|
310
|
-
* - The directory is derived from the agent's name, never from a user-supplied
|
|
311
|
-
* path, so no agent can name its way into another agent's notes
|
|
312
|
-
* - The file is opened once with O_NOFOLLOW and every subsequent check runs on
|
|
313
|
-
* that descriptor, so a symlink swapped in after the check cannot be followed
|
|
314
|
-
* - Reads are capped in both lines and bytes, and stop early. A memory file that
|
|
315
|
-
* grew unbounded must not be able to consume the child's whole context window
|
|
316
|
-
* - Every containment failure degrades to no injection. A prompt with no memory
|
|
317
|
-
* is correct; a prompt pointed at an unverified path is not
|
|
318
|
-
*
|
|
319
|
-
* WHY THE DIRECTORY IS NAMESPACED:
|
|
320
|
-
* Memory lives under a dedicated `agent-memory/` subdirectory so it can never
|
|
321
|
-
* collide with the coding agent's own `memory/{project}/` tree.
|
|
322
|
-
*
|
|
323
|
-
* AVOID:
|
|
324
|
-
* - Injecting memory contents without the boundary instruction; the file is data
|
|
325
|
-
* a previous run wrote, and a prompt-injection payload could have landed in it
|
|
326
|
-
* - Re-stat'ing by path between the open and the read
|
|
327
|
-
*/
|
|
328
|
-
/** Tools that let an agent append to its own memory file. */
|
|
329
|
-
const WRITE_TOOLS = /* @__PURE__ */ new Set([
|
|
330
|
-
"edit",
|
|
331
|
-
"write",
|
|
332
|
-
"bash"
|
|
333
|
-
]);
|
|
334
|
-
function unquoteFrontmatterValue(value) {
|
|
335
|
-
const trimmed = value.trim();
|
|
336
|
-
if (trimmed.startsWith("\"") && trimmed.endsWith("\"") || trimmed.startsWith("'") && trimmed.endsWith("'")) return trimmed.slice(1, -1);
|
|
337
|
-
return trimmed;
|
|
338
|
-
}
|
|
339
|
-
function parseMemoryScope(value) {
|
|
340
|
-
return value === "project" || value === "user" ? value : void 0;
|
|
341
|
-
}
|
|
342
|
-
function parseMemoryBoolean(value) {
|
|
343
|
-
if (value === "true") return true;
|
|
344
|
-
if (value === "false") return false;
|
|
345
|
-
}
|
|
346
|
-
function parsePositiveInteger(value) {
|
|
347
|
-
if (value === void 0) return void 0;
|
|
348
|
-
const parsed = Number(value);
|
|
349
|
-
return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
350
|
-
}
|
|
351
|
-
/** Split a `memory` frontmatter block into key/value pairs, either spelling. */
|
|
352
|
-
function readMemoryEntries(raw) {
|
|
353
|
-
const entries = /* @__PURE__ */ new Map();
|
|
354
|
-
const inlineObject = raw.trim().match(/^\{(.*)\}$/s);
|
|
355
|
-
const parts = inlineObject?.[1] !== void 0 ? inlineObject[1].split(",") : raw.split("\n");
|
|
356
|
-
for (const part of parts) {
|
|
357
|
-
const match = part.trim().match(/^([\w-]+)\s*:\s*(.*)$/);
|
|
358
|
-
if (!match?.[1] || match[2] === void 0) continue;
|
|
359
|
-
entries.set(match[1], unquoteFrontmatterValue(match[2]));
|
|
360
|
-
}
|
|
361
|
-
return entries;
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Parse a `memory` frontmatter block, or undefined when it declares nothing.
|
|
365
|
-
*
|
|
366
|
-
* Accepts both the inline `{ scope: project }` form and the indented block form,
|
|
367
|
-
* because agent files in the wild use each.
|
|
368
|
-
*/
|
|
369
|
-
function parseMemoryFrontmatter(raw) {
|
|
370
|
-
if (!raw) return void 0;
|
|
371
|
-
const entries = readMemoryEntries(raw);
|
|
372
|
-
const enabled = parseMemoryBoolean(entries.get("enabled"));
|
|
373
|
-
const scope = parseMemoryScope(entries.get("scope"));
|
|
374
|
-
const maxEntries = parsePositiveInteger(entries.get("maxEntries"));
|
|
375
|
-
if (enabled === void 0 && scope === void 0 && maxEntries === void 0) return void 0;
|
|
376
|
-
const config = {};
|
|
377
|
-
if (enabled !== void 0) config.enabled = enabled;
|
|
378
|
-
if (scope !== void 0) config.scope = scope;
|
|
379
|
-
if (maxEntries !== void 0) config.maxEntries = maxEntries;
|
|
380
|
-
return config;
|
|
381
|
-
}
|
|
382
|
-
/** Whether an agent can write files this run. An unset `tools` inherits the builtins. */
|
|
383
|
-
function agentHasWriteTools(agent) {
|
|
384
|
-
const tools = agent.tools;
|
|
385
|
-
if (!tools) return true;
|
|
386
|
-
return tools.some((tool) => WRITE_TOOLS.has(tool));
|
|
387
|
-
}
|
|
388
|
-
//#endregion
|
|
389
180
|
//#region src/services/agentProjectRoot/index.ts
|
|
390
181
|
/**
|
|
391
182
|
* Locating the project root that agent configuration hangs off.
|
|
@@ -449,14 +240,16 @@ async function canonicalizeDiscoveryCwd(io, cwd) {
|
|
|
449
240
|
return resolved;
|
|
450
241
|
}
|
|
451
242
|
}
|
|
243
|
+
/** What a path names once symlinks are followed, or undefined when it cannot be resolved or read. */
|
|
244
|
+
async function statFollowing(io, filePath) {
|
|
245
|
+
const canonical = await io.fs.canonicalPath(filePath, io.context);
|
|
246
|
+
if (!canonical.ok) return void 0;
|
|
247
|
+
const info = await io.fs.fileInfo(canonical.value, io.context);
|
|
248
|
+
return info.ok ? info.value : void 0;
|
|
249
|
+
}
|
|
452
250
|
/** Whether a path exists and is a directory. Any failure reads as "no". */
|
|
453
251
|
async function isDirectory(io, dirPath) {
|
|
454
|
-
|
|
455
|
-
const canonical = (0, _agimon_ai_po_core_platform.getOrThrow)(await io.fs.canonicalPath(dirPath, io.context));
|
|
456
|
-
return (0, _agimon_ai_po_core_platform.getOrThrow)(await io.fs.fileInfo(canonical, io.context)).kind === "directory";
|
|
457
|
-
} catch {
|
|
458
|
-
return false;
|
|
459
|
-
}
|
|
252
|
+
return (await statFollowing(io, dirPath))?.kind === "directory";
|
|
460
253
|
}
|
|
461
254
|
/** True when `dir` carries either marker that makes it a project root. */
|
|
462
255
|
async function isProjectRootCandidate(io, dir) {
|
|
@@ -567,6 +360,184 @@ async function resolveNearestProjectAgentDirs(io, cwd) {
|
|
|
567
360
|
};
|
|
568
361
|
}
|
|
569
362
|
//#endregion
|
|
363
|
+
//#region src/services/codingAgentHost/index.ts
|
|
364
|
+
/**
|
|
365
|
+
* Facts about the host the coding agent runs on: its installation and the
|
|
366
|
+
* executables it can launch.
|
|
367
|
+
*
|
|
368
|
+
* The config directory is normally `.pi`, but a rebranded build of the coding
|
|
369
|
+
* agent can rename it, so the real name is discovered from the running
|
|
370
|
+
* installation rather than assumed. Discovery order runs from most to least
|
|
371
|
+
* authoritative: the loaded module's own export, then an explicitly configured
|
|
372
|
+
* package root, then a walk upward from the process entry point, then the
|
|
373
|
+
* default.
|
|
374
|
+
*
|
|
375
|
+
* Node-only: an installation and its executables are files on this host. The
|
|
376
|
+
* edge build swaps in `index.edge.ts`, where neither exists.
|
|
377
|
+
*
|
|
378
|
+
* DESIGN PATTERNS:
|
|
379
|
+
* - Every discovery step is best-effort. A detached runner must still start
|
|
380
|
+
* when package metadata is unreadable, so failures fall through to the default
|
|
381
|
+
*
|
|
382
|
+
* PERFORMANCE:
|
|
383
|
+
* Discovery is memoized per package root because the uncached path walks from
|
|
384
|
+
* the entry point to the filesystem root, reading and parsing a package.json
|
|
385
|
+
* per level.
|
|
386
|
+
*/
|
|
387
|
+
const DEFAULT_CONFIG_DIR_NAME = ".pi";
|
|
388
|
+
const PI_CODING_AGENT_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
|
|
389
|
+
/** Whether this host may execute the file, by the operating system's own rule. */
|
|
390
|
+
async function canExecute(filePath) {
|
|
391
|
+
try {
|
|
392
|
+
await node_fs_promises.access(filePath, node_fs_promises.constants.X_OK);
|
|
393
|
+
return true;
|
|
394
|
+
} catch {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
function validConfigDirName(value) {
|
|
399
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
400
|
+
}
|
|
401
|
+
/** Read the config dir name from a directory, if it is the coding agent's package root. */
|
|
402
|
+
async function readConfigDirNameFromPackageRoot(packageRoot) {
|
|
403
|
+
if (!packageRoot) return void 0;
|
|
404
|
+
try {
|
|
405
|
+
const manifest = JSON.parse(await node_fs_promises.readFile(node_path.join(packageRoot, "package.json"), "utf-8"));
|
|
406
|
+
if (typeof manifest !== "object" || manifest === null) return void 0;
|
|
407
|
+
const record = manifest;
|
|
408
|
+
if (record.name !== PI_CODING_AGENT_PACKAGE_NAME) return void 0;
|
|
409
|
+
return validConfigDirName((typeof record.piConfig === "object" && record.piConfig !== null ? record.piConfig : void 0)?.configDir);
|
|
410
|
+
} catch {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
async function resolveConfigDirNameFromPackageJson(entryPoint, packageRoot) {
|
|
415
|
+
const configuredRootValue = await readConfigDirNameFromPackageRoot(packageRoot);
|
|
416
|
+
if (configuredRootValue) return configuredRootValue;
|
|
417
|
+
if (!entryPoint) return void 0;
|
|
418
|
+
try {
|
|
419
|
+
let dir = node_path.dirname(await node_fs_promises.realpath(entryPoint));
|
|
420
|
+
while (dir !== node_path.dirname(dir)) {
|
|
421
|
+
const value = await readConfigDirNameFromPackageRoot(dir);
|
|
422
|
+
if (value) return value;
|
|
423
|
+
dir = node_path.dirname(dir);
|
|
424
|
+
}
|
|
425
|
+
} catch {}
|
|
426
|
+
}
|
|
427
|
+
/** Resolve the config directory name from explicit inputs. Pure with respect to its arguments. */
|
|
428
|
+
async function resolveConfigDirName(codingAgentModule, entryPoint, packageRoot) {
|
|
429
|
+
return (codingAgentModule && typeof codingAgentModule === "object" ? validConfigDirName(codingAgentModule.CONFIG_DIR_NAME) : void 0) ?? await resolveConfigDirNameFromPackageJson(entryPoint, packageRoot) ?? DEFAULT_CONFIG_DIR_NAME;
|
|
430
|
+
}
|
|
431
|
+
const discovered = /* @__PURE__ */ new Map();
|
|
432
|
+
/** This installation's config directory name, walking up from the process entry point. Memoized per root. */
|
|
433
|
+
function discoverConfigDirName(packageRoot) {
|
|
434
|
+
const key = packageRoot ?? "";
|
|
435
|
+
let name = discovered.get(key);
|
|
436
|
+
if (!name) {
|
|
437
|
+
name = resolveConfigDirName(void 0, process.argv[1], packageRoot);
|
|
438
|
+
discovered.set(key, name);
|
|
439
|
+
}
|
|
440
|
+
return name;
|
|
441
|
+
}
|
|
442
|
+
/** The config directory name for this installation, resolved once per package root. */
|
|
443
|
+
async function getConfigDirName(environment = {}) {
|
|
444
|
+
return discoverConfigDirName(environment["PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT"] || void 0);
|
|
445
|
+
}
|
|
446
|
+
/** The user-level agent directory Po runs with, from Po's own resolver. */
|
|
447
|
+
function getAgentDir(environment, homeDirectory) {
|
|
448
|
+
return (0, _agimon_ai_po_core_piSettings.piAgentDirectory)(environment, homeDirectory);
|
|
449
|
+
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/services/agentMemory/index.ts
|
|
452
|
+
/**
|
|
453
|
+
* Per-agent persistent memory, injected into a child system prompt.
|
|
454
|
+
*
|
|
455
|
+
* An agent may opt into a durable, role-specific memory scope via its `memory`
|
|
456
|
+
* frontmatter. The opening lines of a `MEMORY.md` in the resolved directory are
|
|
457
|
+
* injected so a recurring custom agent can recall accumulated role notes:
|
|
458
|
+
* threat models, gotchas, verified commands, decisions. An agent with no write
|
|
459
|
+
* tools gets a read-only variant of the block instead.
|
|
460
|
+
*
|
|
461
|
+
* DESIGN PATTERNS:
|
|
462
|
+
* - The directory is derived from the agent's name, never from a user-supplied
|
|
463
|
+
* path, so no agent can name its way into another agent's notes
|
|
464
|
+
* - The file is opened once without following a final symlink, and every
|
|
465
|
+
* subsequent read runs on that handle, so a symlink swapped in later is not followed
|
|
466
|
+
* - Reads are capped in both lines and bytes, and stop early. A memory file that
|
|
467
|
+
* grew unbounded must not be able to consume the child's whole context window
|
|
468
|
+
* - Every containment failure degrades to no injection. A prompt with no memory
|
|
469
|
+
* is correct; a prompt pointed at an unverified path is not
|
|
470
|
+
*
|
|
471
|
+
* WHY THE DIRECTORY IS NAMESPACED:
|
|
472
|
+
* Memory lives under a dedicated `agent-memory/` subdirectory so it can never
|
|
473
|
+
* collide with the coding agent's own `memory/{project}/` tree.
|
|
474
|
+
*
|
|
475
|
+
* AVOID:
|
|
476
|
+
* - Injecting memory contents without the boundary instruction; the file is data
|
|
477
|
+
* a previous run wrote, and a prompt-injection payload could have landed in it
|
|
478
|
+
* - Re-stat'ing by path between the open and the read
|
|
479
|
+
*/
|
|
480
|
+
/** Tools that let an agent append to its own memory file. */
|
|
481
|
+
const WRITE_TOOLS = /* @__PURE__ */ new Set([
|
|
482
|
+
"edit",
|
|
483
|
+
"write",
|
|
484
|
+
"bash"
|
|
485
|
+
]);
|
|
486
|
+
function unquoteFrontmatterValue(value) {
|
|
487
|
+
const trimmed = value.trim();
|
|
488
|
+
if (trimmed.startsWith("\"") && trimmed.endsWith("\"") || trimmed.startsWith("'") && trimmed.endsWith("'")) return trimmed.slice(1, -1);
|
|
489
|
+
return trimmed;
|
|
490
|
+
}
|
|
491
|
+
function parseMemoryScope(value) {
|
|
492
|
+
return value === "project" || value === "user" ? value : void 0;
|
|
493
|
+
}
|
|
494
|
+
function parseMemoryBoolean(value) {
|
|
495
|
+
if (value === "true") return true;
|
|
496
|
+
if (value === "false") return false;
|
|
497
|
+
}
|
|
498
|
+
function parsePositiveInteger(value) {
|
|
499
|
+
if (value === void 0) return void 0;
|
|
500
|
+
const parsed = Number(value);
|
|
501
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
502
|
+
}
|
|
503
|
+
/** Split a `memory` frontmatter block into key/value pairs, either spelling. */
|
|
504
|
+
function readMemoryEntries(raw) {
|
|
505
|
+
const entries = /* @__PURE__ */ new Map();
|
|
506
|
+
const inlineObject = raw.trim().match(/^\{(.*)\}$/s);
|
|
507
|
+
const parts = inlineObject?.[1] !== void 0 ? inlineObject[1].split(",") : raw.split("\n");
|
|
508
|
+
for (const part of parts) {
|
|
509
|
+
const match = part.trim().match(/^([\w-]+)\s*:\s*(.*)$/);
|
|
510
|
+
if (!match?.[1] || match[2] === void 0) continue;
|
|
511
|
+
entries.set(match[1], unquoteFrontmatterValue(match[2]));
|
|
512
|
+
}
|
|
513
|
+
return entries;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Parse a `memory` frontmatter block, or undefined when it declares nothing.
|
|
517
|
+
*
|
|
518
|
+
* Accepts both the inline `{ scope: project }` form and the indented block form,
|
|
519
|
+
* because agent files in the wild use each.
|
|
520
|
+
*/
|
|
521
|
+
function parseMemoryFrontmatter(raw) {
|
|
522
|
+
if (!raw) return void 0;
|
|
523
|
+
const entries = readMemoryEntries(raw);
|
|
524
|
+
const enabled = parseMemoryBoolean(entries.get("enabled"));
|
|
525
|
+
const scope = parseMemoryScope(entries.get("scope"));
|
|
526
|
+
const maxEntries = parsePositiveInteger(entries.get("maxEntries"));
|
|
527
|
+
if (enabled === void 0 && scope === void 0 && maxEntries === void 0) return void 0;
|
|
528
|
+
const config = {};
|
|
529
|
+
if (enabled !== void 0) config.enabled = enabled;
|
|
530
|
+
if (scope !== void 0) config.scope = scope;
|
|
531
|
+
if (maxEntries !== void 0) config.maxEntries = maxEntries;
|
|
532
|
+
return config;
|
|
533
|
+
}
|
|
534
|
+
/** Whether an agent can write files this run. An unset `tools` inherits the builtins. */
|
|
535
|
+
function agentHasWriteTools(agent) {
|
|
536
|
+
const tools = agent.tools;
|
|
537
|
+
if (!tools) return true;
|
|
538
|
+
return tools.some((tool) => WRITE_TOOLS.has(tool));
|
|
539
|
+
}
|
|
540
|
+
//#endregion
|
|
570
541
|
//#region src/services/agentSettings/index.ts
|
|
571
542
|
const SUBAGENTS_SETTINGS_KEY = "subagents";
|
|
572
543
|
const AGENT_OVERRIDES_KEY = "agentOverrides";
|
|
@@ -1533,10 +1504,16 @@ Object.defineProperty(exports, "agentHasWriteTools", {
|
|
|
1533
1504
|
return agentHasWriteTools;
|
|
1534
1505
|
}
|
|
1535
1506
|
});
|
|
1507
|
+
Object.defineProperty(exports, "canExecute", {
|
|
1508
|
+
enumerable: true,
|
|
1509
|
+
get: function() {
|
|
1510
|
+
return canExecute;
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1536
1513
|
Object.defineProperty(exports, "canonicalizeDiscoveryCwd", {
|
|
1537
1514
|
enumerable: true,
|
|
1538
1515
|
get: function() {
|
|
1539
|
-
return canonicalizeDiscoveryCwd
|
|
1516
|
+
return canonicalizeDiscoveryCwd;
|
|
1540
1517
|
}
|
|
1541
1518
|
});
|
|
1542
1519
|
Object.defineProperty(exports, "getAgentDir", {
|
|
@@ -1551,11 +1528,11 @@ Object.defineProperty(exports, "getConfigDirName", {
|
|
|
1551
1528
|
return getConfigDirName;
|
|
1552
1529
|
}
|
|
1553
1530
|
});
|
|
1554
|
-
Object.defineProperty(exports, "
|
|
1531
|
+
Object.defineProperty(exports, "statFollowing", {
|
|
1555
1532
|
enumerable: true,
|
|
1556
1533
|
get: function() {
|
|
1557
|
-
return
|
|
1534
|
+
return statFollowing;
|
|
1558
1535
|
}
|
|
1559
1536
|
});
|
|
1560
1537
|
|
|
1561
|
-
//# sourceMappingURL=agentDiscovery-
|
|
1538
|
+
//# sourceMappingURL=agentDiscovery-C-RbBodf.cjs.map
|