@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.
- package/LICENSE +95 -171
- package/NOTICE +35 -0
- package/README.md +24 -111
- package/dist/{agentDiscovery-ZNG8iZXV.mjs → agentDiscovery-BiMO2Ibu.mjs} +190 -193
- package/dist/agentDiscovery-BiMO2Ibu.mjs.map +1 -0
- package/dist/{agentDiscovery-DTTlM_LT.cjs → agentDiscovery-D0VcSETk.cjs} +268 -227
- package/dist/agentDiscovery-D0VcSETk.cjs.map +1 -0
- package/dist/apiContracts.cjs +1 -1
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/apiContracts.mjs +1 -1
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/{capabilityCeiling-BaHT9v9S.mjs → capabilityCeiling-DFcqYSTc.mjs} +3 -22
- package/dist/capabilityCeiling-DFcqYSTc.mjs.map +1 -0
- package/dist/{capabilityCeiling-CO3ZjYmY.cjs → capabilityCeiling-x2WmB2TL.cjs} +3 -22
- package/dist/capabilityCeiling-x2WmB2TL.cjs.map +1 -0
- package/dist/capabilityCeiling.cjs +2 -2
- package/dist/capabilityCeiling.d.mts +2 -4
- package/dist/capabilityCeiling.d.mts.map +1 -1
- package/dist/capabilityCeiling.mjs +2 -2
- package/dist/coordinatorSessions.cjs +14 -0
- package/dist/coordinatorSessions.d.mts +2 -0
- package/dist/coordinatorSessions.mjs +1 -0
- package/dist/env.cjs +1 -2
- package/dist/env.d.mts +2 -2
- package/dist/env.mjs +1 -1
- package/dist/{environment-BtvJI2S-.mjs → environment-BKQikJyW.mjs} +2 -11
- package/dist/environment-BKQikJyW.mjs.map +1 -0
- package/dist/{environment-Bz1OlWIT.d.mts → environment-CE9zbaE4.d.mts} +2 -9
- package/dist/environment-CE9zbaE4.d.mts.map +1 -0
- package/dist/{environment-Cqs7vHJL.cjs → environment-COaoVl5M.cjs} +1 -16
- package/dist/environment-COaoVl5M.cjs.map +1 -0
- package/dist/extensions/native.mjs +2477 -208
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +4645 -3681
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +5299 -4333
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +1573 -573
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +3 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/po-runtime-identity.json +1 -0
- package/dist/runtimeSubagentPolicy.cjs +1 -1
- package/dist/runtimeSubagentPolicy.d.mts +1 -1
- package/dist/runtimeSubagentPolicy.mjs +1 -1
- package/dist/runtimeSubagentTool.cjs +1 -1
- package/dist/runtimeSubagentTool.d.mts +1 -1
- package/dist/runtimeSubagentTool.mjs +1 -1
- package/dist/{subagentPolicy-BE-OZoa-.d.mts → subagentPolicy-CN-AYfeB.d.mts} +1 -2
- package/dist/subagentPolicy-CN-AYfeB.d.mts.map +1 -0
- package/dist/{subagentPolicy-LfcXuqO5.mjs → subagentPolicy-CXqAT9aI.mjs} +1 -5
- package/dist/subagentPolicy-CXqAT9aI.mjs.map +1 -0
- package/dist/{subagentPolicy-DIpaKHO8.cjs → subagentPolicy-DYj_SOTG.cjs} +1 -5
- package/dist/subagentPolicy-DYj_SOTG.cjs.map +1 -0
- package/dist/subagentPolicy.cjs +1 -1
- package/dist/subagentPolicy.d.mts +1 -1
- package/dist/subagentPolicy.mjs +1 -1
- package/dist/{subagentTool-UdB3s6Mn.d.mts → subagentTool-BHY7OcDf.d.mts} +3 -3
- package/dist/{subagentTool-UdB3s6Mn.d.mts.map → subagentTool-BHY7OcDf.d.mts.map} +1 -1
- package/dist/{subagentTool-a2oh2v5B.mjs → subagentTool-CCeGXaPL.mjs} +3 -4
- package/dist/subagentTool-CCeGXaPL.mjs.map +1 -0
- package/dist/{subagentTool-BueNPGHo.cjs → subagentTool-CqXgI3iD.cjs} +3 -4
- package/dist/subagentTool-CqXgI3iD.cjs.map +1 -0
- package/dist/subagentTool.cjs +1 -1
- package/dist/subagentTool.d.mts +1 -1
- package/dist/subagentTool.mjs +1 -1
- package/dist/teamSnapshot.d.mts.map +1 -1
- package/llms.txt +12 -0
- package/locales/vi.json +325 -0
- package/locales/zh-CN.json +325 -0
- package/package.json +129 -43
- package/src/prompts/codemode-how-to-team/SKILL.md +71 -0
- package/src/prompts/help-how-to-team/SKILL.md +91 -0
- package/dist/agentDiscovery-DTTlM_LT.cjs.map +0 -1
- package/dist/agentDiscovery-ZNG8iZXV.mjs.map +0 -1
- package/dist/atomicJson-DRT03Ql5.cjs +0 -824
- package/dist/atomicJson-DRT03Ql5.cjs.map +0 -1
- package/dist/atomicJson-VVM1iAPu.mjs +0 -712
- package/dist/atomicJson-VVM1iAPu.mjs.map +0 -1
- package/dist/capabilityCeiling-BaHT9v9S.mjs.map +0 -1
- package/dist/capabilityCeiling-CO3ZjYmY.cjs.map +0 -1
- package/dist/environment-BtvJI2S-.mjs.map +0 -1
- package/dist/environment-Bz1OlWIT.d.mts.map +0 -1
- package/dist/environment-Cqs7vHJL.cjs.map +0 -1
- package/dist/fablePlan.cjs +0 -17
- package/dist/fablePlan.d.mts +0 -2
- package/dist/fablePlan.mjs +0 -1
- package/dist/fablePlanApi-BTNKjLni.d.mts +0 -97
- package/dist/fablePlanApi-BTNKjLni.d.mts.map +0 -1
- package/dist/fablePlanApi-BhI4jnDP.cjs +0 -207
- package/dist/fablePlanApi-BhI4jnDP.cjs.map +0 -1
- package/dist/fablePlanApi-DuMg43Hu.mjs +0 -118
- package/dist/fablePlanApi-DuMg43Hu.mjs.map +0 -1
- package/dist/fablePlanApi.cjs +0 -17
- package/dist/fablePlanApi.d.mts +0 -2
- package/dist/fablePlanApi.mjs +0 -1
- package/dist/rolldown-runtime-VH7oDXx4.cjs +0 -28
- package/dist/runs/background/cliRunnerEntry.cjs +0 -540
- package/dist/runs/background/cliRunnerEntry.cjs.map +0 -1
- package/dist/runs/background/cliRunnerEntry.d.mts +0 -1
- package/dist/runs/background/cliRunnerEntry.mjs +0 -537
- package/dist/runs/background/cliRunnerEntry.mjs.map +0 -1
- package/dist/subagentPolicy-BE-OZoa-.d.mts.map +0 -1
- package/dist/subagentPolicy-DIpaKHO8.cjs.map +0 -1
- package/dist/subagentPolicy-LfcXuqO5.mjs.map +0 -1
- package/dist/subagentTool-BueNPGHo.cjs.map +0 -1
- package/dist/subagentTool-a2oh2v5B.mjs.map +0 -1
|
@@ -1,12 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
2
23
|
let node_path = require("node:path");
|
|
3
|
-
node_path =
|
|
24
|
+
node_path = __toESM(node_path, 1);
|
|
4
25
|
let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
|
|
5
|
-
let node_fs = require("node:fs");
|
|
6
|
-
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
7
|
-
let node_os = require("node:os");
|
|
8
|
-
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
9
26
|
let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
|
|
27
|
+
let node_fs_promises = require("node:fs/promises");
|
|
28
|
+
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
10
29
|
//#region src/services/agentFrontmatter/index.ts
|
|
11
30
|
/**
|
|
12
31
|
* Parsing the YAML frontmatter block at the head of an agent or chain file.
|
|
@@ -158,213 +177,6 @@ function parseFrontmatter(content) {
|
|
|
158
177
|
};
|
|
159
178
|
}
|
|
160
179
|
//#endregion
|
|
161
|
-
//#region src/services/configDir/index.ts
|
|
162
|
-
/**
|
|
163
|
-
* Locating the coding agent's config directory.
|
|
164
|
-
*
|
|
165
|
-
* The directory is normally `.pi`, but a rebranded build of the coding agent
|
|
166
|
-
* can rename it, so the real name is discovered from the running installation
|
|
167
|
-
* rather than assumed. Discovery order runs from most to least authoritative:
|
|
168
|
-
* the loaded module's own export, then an explicitly configured package root,
|
|
169
|
-
* then a walk upward from the process entry point, then the default.
|
|
170
|
-
*
|
|
171
|
-
* DESIGN PATTERNS:
|
|
172
|
-
* - Resolution is a pure function of its inputs; the process-wide convenience
|
|
173
|
-
* wrapper is a separate, memoized entry point
|
|
174
|
-
* - Every discovery step is best-effort. A detached runner must still start
|
|
175
|
-
* when package metadata is unreadable, so failures fall through to the default
|
|
176
|
-
*
|
|
177
|
-
* PERFORMANCE:
|
|
178
|
-
* `getConfigDirName` is memoized because the uncached path walks from the entry
|
|
179
|
-
* point to the filesystem root, reading and parsing a package.json per level.
|
|
180
|
-
* Callers join it into paths, so it was previously re-walked per path built.
|
|
181
|
-
*
|
|
182
|
-
* AVOID:
|
|
183
|
-
* - Hardcoding `.pi` at a call site
|
|
184
|
-
* - Calling the uncached resolver on a hot path
|
|
185
|
-
*/
|
|
186
|
-
const DEFAULT_CONFIG_DIR_NAME = ".pi";
|
|
187
|
-
const PI_CODING_AGENT_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
|
|
188
|
-
/** Overrides the upward package walk when the installation root is known. */
|
|
189
|
-
const PI_CODING_AGENT_PACKAGE_ROOT_ENV = "PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT";
|
|
190
|
-
function validConfigDirName(value) {
|
|
191
|
-
return typeof value === "string" && value.trim() ? value : void 0;
|
|
192
|
-
}
|
|
193
|
-
/** Read the config dir name from a directory, if it is the coding agent's package root. */
|
|
194
|
-
function readConfigDirNameFromPackageRoot(packageRoot) {
|
|
195
|
-
if (!packageRoot) return void 0;
|
|
196
|
-
try {
|
|
197
|
-
const manifest = JSON.parse(node_fs.readFileSync(node_path.join(packageRoot, "package.json"), "utf-8"));
|
|
198
|
-
if (typeof manifest !== "object" || manifest === null) return void 0;
|
|
199
|
-
const record = manifest;
|
|
200
|
-
if (record.name !== PI_CODING_AGENT_PACKAGE_NAME) return void 0;
|
|
201
|
-
return validConfigDirName((typeof record.piConfig === "object" && record.piConfig !== null ? record.piConfig : void 0)?.configDir);
|
|
202
|
-
} catch {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
function resolveConfigDirNameFromPackageJson(entryPoint = process.argv[1], packageRoot = process.env[PI_CODING_AGENT_PACKAGE_ROOT_ENV]) {
|
|
207
|
-
const configuredRootValue = readConfigDirNameFromPackageRoot(packageRoot);
|
|
208
|
-
if (configuredRootValue) return configuredRootValue;
|
|
209
|
-
if (!entryPoint) return void 0;
|
|
210
|
-
try {
|
|
211
|
-
let dir = node_path.dirname(node_fs.realpathSync(entryPoint));
|
|
212
|
-
while (dir !== node_path.dirname(dir)) {
|
|
213
|
-
const value = readConfigDirNameFromPackageRoot(dir);
|
|
214
|
-
if (value) return value;
|
|
215
|
-
dir = node_path.dirname(dir);
|
|
216
|
-
}
|
|
217
|
-
} catch {}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Resolve the config directory name from explicit inputs.
|
|
221
|
-
*
|
|
222
|
-
* Pure with respect to its arguments, which is what makes it testable; the
|
|
223
|
-
* process-wide answer comes from `getConfigDirName`.
|
|
224
|
-
*/
|
|
225
|
-
function resolveConfigDirName(codingAgentModule, entryPoint, packageRoot) {
|
|
226
|
-
return (codingAgentModule && typeof codingAgentModule === "object" ? validConfigDirName(codingAgentModule.CONFIG_DIR_NAME) : void 0) ?? resolveConfigDirNameFromPackageJson(entryPoint, packageRoot) ?? DEFAULT_CONFIG_DIR_NAME;
|
|
227
|
-
}
|
|
228
|
-
let memoizedConfigDirName;
|
|
229
|
-
/** The config directory name for this process. Resolved once, then reused. */
|
|
230
|
-
function getConfigDirName(environment = process.env) {
|
|
231
|
-
if (environment !== process.env) return resolveConfigDirName(void 0, process.argv[1], environment["PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROOT"] ?? "");
|
|
232
|
-
memoizedConfigDirName ??= resolveConfigDirName();
|
|
233
|
-
return memoizedConfigDirName;
|
|
234
|
-
}
|
|
235
|
-
/** The project-local config directory, for example `<projectRoot>/.pi`. */
|
|
236
|
-
function getProjectConfigDir(projectRoot, environment = process.env) {
|
|
237
|
-
return node_path.join(projectRoot, getConfigDirName(environment));
|
|
238
|
-
}
|
|
239
|
-
/** The user-level agent directory Po runs with, from Po's own resolver. */
|
|
240
|
-
function getAgentDir(environment = process.env) {
|
|
241
|
-
return (0, _agimon_ai_po_core_piSettings.piAgentDirectory)(environment, environment.HOME ?? node_os.homedir());
|
|
242
|
-
}
|
|
243
|
-
//#endregion
|
|
244
|
-
//#region src/services/agentProjectRoot/sync.ts
|
|
245
|
-
/** @deprecated Node-only shim. */
|
|
246
|
-
/**
|
|
247
|
-
* Locating the project root that agent configuration hangs off.
|
|
248
|
-
*
|
|
249
|
-
* A project root is any ancestor of the working directory that carries a config
|
|
250
|
-
* directory or a legacy `.agents` directory. There can be several: a package
|
|
251
|
-
* inside a monorepo and the monorepo itself both qualify. Which one wins is a
|
|
252
|
-
* setting, because both answers are legitimate. Teams that keep one shared set
|
|
253
|
-
* of agents at the repository root want `git-root`, teams that give each package
|
|
254
|
-
* its own want `nearest`, and neither can be inferred from the tree alone.
|
|
255
|
-
*
|
|
256
|
-
* DESIGN PATTERNS:
|
|
257
|
-
* - Candidates are collected once, nearest first, then a policy picks from them.
|
|
258
|
-
* Separating collection from policy is what lets `git-root` be answered
|
|
259
|
-
* without a second walk
|
|
260
|
-
* - Path derivation goes through `shared/configDir.ts`, so a rebranded build
|
|
261
|
-
* that renames its config directory needs no change here
|
|
262
|
-
*
|
|
263
|
-
* AVOID:
|
|
264
|
-
* - Hardcoding the config directory name; it is discovered, not assumed
|
|
265
|
-
* - Treating the nearest candidate as the project root without reading the
|
|
266
|
-
* setting first
|
|
267
|
-
*/
|
|
268
|
-
/** Stable cache identity for equivalent absolute, relative, and symlinked cwd spellings. */
|
|
269
|
-
function canonicalizeDiscoveryCwd$1(cwd) {
|
|
270
|
-
const resolved = node_path.resolve(cwd);
|
|
271
|
-
try {
|
|
272
|
-
return node_fs.realpathSync.native(resolved);
|
|
273
|
-
} catch {
|
|
274
|
-
return resolved;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
//#endregion
|
|
278
|
-
//#region src/services/agentMemory/index.ts
|
|
279
|
-
/**
|
|
280
|
-
* Per-agent persistent memory, injected into a child system prompt.
|
|
281
|
-
*
|
|
282
|
-
* An agent may opt into a durable, role-specific memory scope via its `memory`
|
|
283
|
-
* frontmatter. The opening lines of a `MEMORY.md` in the resolved directory are
|
|
284
|
-
* injected so a recurring custom agent can recall accumulated role notes:
|
|
285
|
-
* threat models, gotchas, verified commands, decisions. An agent with no write
|
|
286
|
-
* tools gets a read-only variant of the block instead.
|
|
287
|
-
*
|
|
288
|
-
* DESIGN PATTERNS:
|
|
289
|
-
* - The directory is derived from the agent's name, never from a user-supplied
|
|
290
|
-
* path, so no agent can name its way into another agent's notes
|
|
291
|
-
* - The file is opened once with O_NOFOLLOW and every subsequent check runs on
|
|
292
|
-
* that descriptor, so a symlink swapped in after the check cannot be followed
|
|
293
|
-
* - Reads are capped in both lines and bytes, and stop early. A memory file that
|
|
294
|
-
* grew unbounded must not be able to consume the child's whole context window
|
|
295
|
-
* - Every containment failure degrades to no injection. A prompt with no memory
|
|
296
|
-
* is correct; a prompt pointed at an unverified path is not
|
|
297
|
-
*
|
|
298
|
-
* WHY THE DIRECTORY IS NAMESPACED:
|
|
299
|
-
* Memory lives under a dedicated `agent-memory/` subdirectory so it can never
|
|
300
|
-
* collide with the coding agent's own `memory/{project}/` tree.
|
|
301
|
-
*
|
|
302
|
-
* AVOID:
|
|
303
|
-
* - Injecting memory contents without the boundary instruction; the file is data
|
|
304
|
-
* a previous run wrote, and a prompt-injection payload could have landed in it
|
|
305
|
-
* - Re-stat'ing by path between the open and the read
|
|
306
|
-
*/
|
|
307
|
-
/** Tools that let an agent append to its own memory file. */
|
|
308
|
-
const WRITE_TOOLS = /* @__PURE__ */ new Set([
|
|
309
|
-
"edit",
|
|
310
|
-
"write",
|
|
311
|
-
"bash"
|
|
312
|
-
]);
|
|
313
|
-
function unquoteFrontmatterValue(value) {
|
|
314
|
-
const trimmed = value.trim();
|
|
315
|
-
if (trimmed.startsWith("\"") && trimmed.endsWith("\"") || trimmed.startsWith("'") && trimmed.endsWith("'")) return trimmed.slice(1, -1);
|
|
316
|
-
return trimmed;
|
|
317
|
-
}
|
|
318
|
-
function parseMemoryScope(value) {
|
|
319
|
-
return value === "project" || value === "user" ? value : void 0;
|
|
320
|
-
}
|
|
321
|
-
function parseMemoryBoolean(value) {
|
|
322
|
-
if (value === "true") return true;
|
|
323
|
-
if (value === "false") return false;
|
|
324
|
-
}
|
|
325
|
-
function parsePositiveInteger(value) {
|
|
326
|
-
if (value === void 0) return void 0;
|
|
327
|
-
const parsed = Number(value);
|
|
328
|
-
return Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
|
|
329
|
-
}
|
|
330
|
-
/** Split a `memory` frontmatter block into key/value pairs, either spelling. */
|
|
331
|
-
function readMemoryEntries(raw) {
|
|
332
|
-
const entries = /* @__PURE__ */ new Map();
|
|
333
|
-
const inlineObject = raw.trim().match(/^\{(.*)\}$/s);
|
|
334
|
-
const parts = inlineObject?.[1] !== void 0 ? inlineObject[1].split(",") : raw.split("\n");
|
|
335
|
-
for (const part of parts) {
|
|
336
|
-
const match = part.trim().match(/^([\w-]+)\s*:\s*(.*)$/);
|
|
337
|
-
if (!match?.[1] || match[2] === void 0) continue;
|
|
338
|
-
entries.set(match[1], unquoteFrontmatterValue(match[2]));
|
|
339
|
-
}
|
|
340
|
-
return entries;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Parse a `memory` frontmatter block, or undefined when it declares nothing.
|
|
344
|
-
*
|
|
345
|
-
* Accepts both the inline `{ scope: project }` form and the indented block form,
|
|
346
|
-
* because agent files in the wild use each.
|
|
347
|
-
*/
|
|
348
|
-
function parseMemoryFrontmatter(raw) {
|
|
349
|
-
if (!raw) return void 0;
|
|
350
|
-
const entries = readMemoryEntries(raw);
|
|
351
|
-
const enabled = parseMemoryBoolean(entries.get("enabled"));
|
|
352
|
-
const scope = parseMemoryScope(entries.get("scope"));
|
|
353
|
-
const maxEntries = parsePositiveInteger(entries.get("maxEntries"));
|
|
354
|
-
if (enabled === void 0 && scope === void 0 && maxEntries === void 0) return void 0;
|
|
355
|
-
const config = {};
|
|
356
|
-
if (enabled !== void 0) config.enabled = enabled;
|
|
357
|
-
if (scope !== void 0) config.scope = scope;
|
|
358
|
-
if (maxEntries !== void 0) config.maxEntries = maxEntries;
|
|
359
|
-
return config;
|
|
360
|
-
}
|
|
361
|
-
/** Whether an agent can write files this run. An unset `tools` inherits the builtins. */
|
|
362
|
-
function agentHasWriteTools(agent) {
|
|
363
|
-
const tools = agent.tools;
|
|
364
|
-
if (!tools) return true;
|
|
365
|
-
return tools.some((tool) => WRITE_TOOLS.has(tool));
|
|
366
|
-
}
|
|
367
|
-
//#endregion
|
|
368
180
|
//#region src/services/agentProjectRoot/index.ts
|
|
369
181
|
/**
|
|
370
182
|
* Locating the project root that agent configuration hangs off.
|
|
@@ -428,14 +240,16 @@ async function canonicalizeDiscoveryCwd(io, cwd) {
|
|
|
428
240
|
return resolved;
|
|
429
241
|
}
|
|
430
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
|
+
}
|
|
431
250
|
/** Whether a path exists and is a directory. Any failure reads as "no". */
|
|
432
251
|
async function isDirectory(io, dirPath) {
|
|
433
|
-
|
|
434
|
-
const canonical = (0, _agimon_ai_po_core_platform.getOrThrow)(await io.fs.canonicalPath(dirPath, io.context));
|
|
435
|
-
return (0, _agimon_ai_po_core_platform.getOrThrow)(await io.fs.fileInfo(canonical, io.context)).kind === "directory";
|
|
436
|
-
} catch {
|
|
437
|
-
return false;
|
|
438
|
-
}
|
|
252
|
+
return (await statFollowing(io, dirPath))?.kind === "directory";
|
|
439
253
|
}
|
|
440
254
|
/** True when `dir` carries either marker that makes it a project root. */
|
|
441
255
|
async function isProjectRootCandidate(io, dir) {
|
|
@@ -546,6 +360,184 @@ async function resolveNearestProjectAgentDirs(io, cwd) {
|
|
|
546
360
|
};
|
|
547
361
|
}
|
|
548
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
|
|
549
541
|
//#region src/services/agentSettings/index.ts
|
|
550
542
|
const SUBAGENTS_SETTINGS_KEY = "subagents";
|
|
551
543
|
const AGENT_OVERRIDES_KEY = "agentOverrides";
|
|
@@ -867,6 +859,30 @@ function applySubagentDefaults(agents, defaultModel, defaultThinking, defaultExt
|
|
|
867
859
|
return applySubagentDefaultExtensions(applySubagentDefaultThinking(applySubagentDefaultFallbackModels(applySubagentDefaultModel(agents, defaultModel), defaultFallbackModels), defaultThinking), defaultExtensions);
|
|
868
860
|
}
|
|
869
861
|
/**
|
|
862
|
+
* Apply `subagents.agents` from Po config: the person picked these for one named agent, so they win
|
|
863
|
+
* over that agent's frontmatter and every default. A run call's own `model` still wins over them.
|
|
864
|
+
*/
|
|
865
|
+
function applyConfiguredAgents(agents, configured, path) {
|
|
866
|
+
if (!configured) return agents;
|
|
867
|
+
return agents.map((agent) => {
|
|
868
|
+
const entry = Object.hasOwn(configured, agent.name) ? configured[agent.name] : void 0;
|
|
869
|
+
if (!entry?.model && !entry?.thinking) return agent;
|
|
870
|
+
return inheritFrontmatterFields(agent, {
|
|
871
|
+
...agent,
|
|
872
|
+
...entry.model ? {
|
|
873
|
+
model: entry.model,
|
|
874
|
+
modelSource: {
|
|
875
|
+
type: "config.subagents.agents",
|
|
876
|
+
scope: "config",
|
|
877
|
+
path,
|
|
878
|
+
model: entry.model
|
|
879
|
+
}
|
|
880
|
+
} : {},
|
|
881
|
+
...entry.thinking ? { thinking: entry.thinking } : {}
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
870
886
|
* Snapshot the fields an override may replace, so it can be undone.
|
|
871
887
|
*
|
|
872
888
|
* `extensions` is omitted when it came from a settings default rather than the
|
|
@@ -1453,21 +1469,22 @@ var AgentDiscoveryService = class {
|
|
|
1453
1469
|
const userSettings = scope === "project" ? EMPTY_SUBAGENT_SETTINGS : await readSubagentSettings(this.io, userSettingsPath);
|
|
1454
1470
|
const projectSettings = scope === "user" ? EMPTY_SUBAGENT_SETTINGS : await readSubagentSettings(this.io, projectSettingsPath);
|
|
1455
1471
|
const legacyDefaultModel = resolveSubagentDefaultModel(userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1472
|
+
const configModels = team?.defaults?.model !== void 0 || team?.defaults?.fallbackModels !== void 0;
|
|
1456
1473
|
const packagePrimaryModel = team?.models?.[0];
|
|
1457
1474
|
const defaultModel = packagePrimaryModel && team ? {
|
|
1458
|
-
type: "packages.team.defaultModel",
|
|
1459
|
-
scope: "package",
|
|
1475
|
+
type: configModels ? "config.subagents.model" : "packages.team.defaultModel",
|
|
1476
|
+
scope: configModels ? "config" : "package",
|
|
1460
1477
|
path: team.path ?? "",
|
|
1461
1478
|
model: packagePrimaryModel
|
|
1462
1479
|
} : legacyDefaultModel;
|
|
1463
|
-
const defaultThinking = resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
|
|
1480
|
+
const defaultThinking = team?.defaults?.thinking ?? resolveSubagentDefaultThinking(userSettings, projectSettings, projectSettingsPath);
|
|
1464
1481
|
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
1465
1482
|
const resolve = (agents) => applyCustomAgentOverrides(applySubagentDefaults(agents, defaultModel, defaultThinking, defaultExtensions), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
1466
1483
|
const projectDirs = await resolveNearestProjectAgentDirs(this.io, cwd);
|
|
1467
1484
|
const loadDirs = async (dirs, source) => resolve((await Promise.all(dirs.map((dir) => loadAgentsFromDir(this.io, dir, source)))).flat());
|
|
1468
1485
|
const plugin = await loadDirs(pluginAgentDirs(this.io.environment), "plugin");
|
|
1469
1486
|
return {
|
|
1470
|
-
agents: mergeAgentsForScope(scope, scope === "project" ? [] : await loadDirs(userAgentDirs(this.io), "user"), scope === "user" ? [] : await loadDirs(projectDirs.readDirs, "project"), plugin).filter((agent) => agent.disabled !== true),
|
|
1487
|
+
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),
|
|
1471
1488
|
projectAgentsDir: projectDirs.preferredDir,
|
|
1472
1489
|
modelScope: projectSettings.modelScope ?? userSettings.modelScope
|
|
1473
1490
|
};
|
|
@@ -1499,16 +1516,28 @@ Object.defineProperty(exports, "LruCache", {
|
|
|
1499
1516
|
return LruCache;
|
|
1500
1517
|
}
|
|
1501
1518
|
});
|
|
1519
|
+
Object.defineProperty(exports, "__toESM", {
|
|
1520
|
+
enumerable: true,
|
|
1521
|
+
get: function() {
|
|
1522
|
+
return __toESM;
|
|
1523
|
+
}
|
|
1524
|
+
});
|
|
1502
1525
|
Object.defineProperty(exports, "agentHasWriteTools", {
|
|
1503
1526
|
enumerable: true,
|
|
1504
1527
|
get: function() {
|
|
1505
1528
|
return agentHasWriteTools;
|
|
1506
1529
|
}
|
|
1507
1530
|
});
|
|
1531
|
+
Object.defineProperty(exports, "canExecute", {
|
|
1532
|
+
enumerable: true,
|
|
1533
|
+
get: function() {
|
|
1534
|
+
return canExecute;
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1508
1537
|
Object.defineProperty(exports, "canonicalizeDiscoveryCwd", {
|
|
1509
1538
|
enumerable: true,
|
|
1510
1539
|
get: function() {
|
|
1511
|
-
return canonicalizeDiscoveryCwd
|
|
1540
|
+
return canonicalizeDiscoveryCwd;
|
|
1512
1541
|
}
|
|
1513
1542
|
});
|
|
1514
1543
|
Object.defineProperty(exports, "getAgentDir", {
|
|
@@ -1523,11 +1552,23 @@ Object.defineProperty(exports, "getConfigDirName", {
|
|
|
1523
1552
|
return getConfigDirName;
|
|
1524
1553
|
}
|
|
1525
1554
|
});
|
|
1526
|
-
Object.defineProperty(exports, "
|
|
1555
|
+
Object.defineProperty(exports, "parseFrontmatter", {
|
|
1556
|
+
enumerable: true,
|
|
1557
|
+
get: function() {
|
|
1558
|
+
return parseFrontmatter;
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1561
|
+
Object.defineProperty(exports, "resolveNearestProjectAgentDirs", {
|
|
1562
|
+
enumerable: true,
|
|
1563
|
+
get: function() {
|
|
1564
|
+
return resolveNearestProjectAgentDirs;
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
Object.defineProperty(exports, "statFollowing", {
|
|
1527
1568
|
enumerable: true,
|
|
1528
1569
|
get: function() {
|
|
1529
|
-
return
|
|
1570
|
+
return statFollowing;
|
|
1530
1571
|
}
|
|
1531
1572
|
});
|
|
1532
1573
|
|
|
1533
|
-
//# sourceMappingURL=agentDiscovery-
|
|
1574
|
+
//# sourceMappingURL=agentDiscovery-D0VcSETk.cjs.map
|