@agimon-ai/po-skill 0.0.0-alpha.21 → 0.0.0-alpha.211

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 (39) hide show
  1. package/LICENSE +21 -149
  2. package/README.md +27 -25
  3. package/dist/apiContracts.cjs.map +1 -1
  4. package/dist/apiContracts.d.mts +2 -2
  5. package/dist/catalog.cjs +31 -8
  6. package/dist/catalog.cjs.map +1 -1
  7. package/dist/catalog.d.mts +5 -0
  8. package/dist/catalog.d.mts.map +1 -1
  9. package/dist/catalog.mjs +31 -8
  10. package/dist/catalog.mjs.map +1 -1
  11. package/dist/extensions/mcp-ui.mjs +7 -5
  12. package/dist/extensions/mcp-ui.mjs.map +1 -1
  13. package/dist/extensions/mcp.cjs +28 -16
  14. package/dist/extensions/mcp.cjs.map +1 -1
  15. package/dist/extensions/mcp.d.mts.map +1 -1
  16. package/dist/extensions/mcp.mjs +28 -16
  17. package/dist/extensions/mcp.mjs.map +1 -1
  18. package/dist/extensions/native.mjs +313 -0
  19. package/dist/extensions/native.mjs.map +1 -0
  20. package/dist/extensions/server.cjs +309 -129
  21. package/dist/extensions/server.cjs.map +1 -1
  22. package/dist/extensions/server.d.mts.map +1 -1
  23. package/dist/extensions/server.mjs +311 -131
  24. package/dist/extensions/server.mjs.map +1 -1
  25. package/dist/extensions/web.mjs +282 -0
  26. package/dist/extensions/web.mjs.map +1 -0
  27. package/dist/index.d.mts +1 -0
  28. package/dist/index.d.mts.map +1 -1
  29. package/dist/po-runtime-identity.json +1 -0
  30. package/dist/skills-Ccvg1Hcz.mjs.map +1 -1
  31. package/dist/skills-ComtgYb1.cjs.map +1 -1
  32. package/llms.txt +3 -2
  33. package/locales/vi.json +17 -0
  34. package/locales/zh-CN.json +17 -0
  35. package/package.json +87 -16
  36. package/src/prompts/codemode-how-to-skills/SKILL.md +15 -0
  37. package/src/prompts/help-how-to-author-skill/SKILL.md +52 -0
  38. package/src/prompts/{po-use-skill → help-how-to-skill}/SKILL.md +3 -1
  39. package/src/prompts/po-author-skill/SKILL.md +0 -37
@@ -1,17 +1,21 @@
1
1
  import { n as SKILL_COMMAND_PREFIX, r as SKILL_INVOCATION_PREFIX, t as SKILLS_COMMAND } from "../skills-Ccvg1Hcz.mjs";
2
2
  import path from "node:path";
3
- import { listDomainNamesAsync, resolvePluginEntriesAsync, resolveSharedSkillsAsync } from "@agimon-ai/po-config/domains";
4
- import { BACKGROUND_CONTEXT, getOrThrow, nodeHost, requirePoFs, withAbortSignal } from "@agimon-ai/po-core/platform";
3
+ import { domainNamesOf, loadDomainsAsync, resolveManifestPluginEntriesAsync, sharedSkillsFor } from "@agimon-ai/po-config/domains";
4
+ import { BACKGROUND_CONTEXT, PO_ISOLATE_SERVICE, getOrThrow, nodeHost, readPoIsolate, requirePoFs, withAbortSignal } from "@agimon-ai/po-core/platform";
5
5
  import { materializePluginEntries } from "@agimon-ai/po-domain/plugins";
6
6
  import { formatSkillsForPrompt, getAgentDir, loadSkills, stripFrontmatter } from "@earendil-works/pi-coding-agent";
7
7
  import { composeServerProviderOverrides, defineServerPlugin, packageResourcePath, readPackageResource } from "@agimon-ai/po-core/serverPlugin";
8
- import { composeRootHooks, composeRootInjects, defineRoot, defineRoutedContribution } from "@agimon-ai/po-core/extensionFile";
8
+ import { composeRootHooks, composeRootInjects, defineResource, defineRoot, defineRoutedContribution } from "@agimon-ai/po-core/extensionFile";
9
+ import { readPoLang, readPoPersonLocale } from "@agimon-ai/po-core/locale";
9
10
  import { readHarnessState } from "@agimon-ai/po-config/harnessState";
10
- import { Type } from "typebox";
11
+ import { PO_HELP_WHEN } from "@agimon-ai/po-core/help";
11
12
  import { collectResources, discoverSkillsAsync } from "@agimon-ai/po-domain/resources";
12
- import fs from "node:fs";
13
+ import fs from "node:fs/promises";
13
14
  import { fileURLToPath, pathToFileURL } from "node:url";
14
15
  import { Worker } from "node:worker_threads";
16
+ import { PO_CODEMODE_SERVICE, readPoCodemode } from "@agimon-ai/po-core/codemode";
17
+ import { PO_SKILLS_NAMESPACE } from "@agimon-ai/po-core/headless";
18
+ import { Type } from "typebox";
15
19
  //#region src/constants/skillInventory.ts
16
20
  /**
17
21
  * How long sessions with the same inputs share one skill inventory instead of each reading the disk.
@@ -31,7 +35,7 @@ function mountMcpSkills(groups, fs, signal) {
31
35
  const domains = remote.selection.read().domains;
32
36
  const skills = /* @__PURE__ */ new Map();
33
37
  for (const group of groups) {
34
- if (group.domain !== void 0 && !domains.includes(group.domain)) continue;
38
+ if (group.domains !== void 0 && !group.domains.some((domain) => domains.includes(domain))) continue;
35
39
  for (const skill of group.skills) {
36
40
  if (skills.has(skill.name)) continue;
37
41
  skills.set(skill.name, {
@@ -51,37 +55,6 @@ function mountMcpSkills(groups, fs, signal) {
51
55
  } });
52
56
  };
53
57
  }
54
- Type.Object({ query: Type.Optional(Type.String()) });
55
- const loadSkillParameters = Type.Object({ name: Type.String() });
56
- //#endregion
57
- //#region src/services/mcpSkillTools/index.ts
58
- function text(text) {
59
- return { content: [{
60
- type: "text",
61
- text
62
- }] };
63
- }
64
- /**
65
- * The session agent's way into a skill. Its skills are listed in the prompt, which Po
66
- * controls, so it needs no search; a remote agent's prompt is not ours, hence the pair above.
67
- */
68
- function createSessionLoadSkillTool(host) {
69
- return {
70
- name: "load_skill",
71
- label: "Load skill",
72
- description: "Load the full instructions of a skill from the available skills list by exact name.",
73
- parameters: loadSkillParameters,
74
- executionMode: "parallel",
75
- async execute(_toolCallId, { name }) {
76
- const body = host.readSkill(name);
77
- if (body === void 0) return {
78
- ...text(`No skill named ${name} is available in this session.`),
79
- isError: true
80
- };
81
- return text(body);
82
- }
83
- };
84
- }
85
58
  //#endregion
86
59
  //#region src/services/deferredSkills/index.ts
87
60
  const PI_PACKAGE = "@earendil-works/pi-coding-agent";
@@ -98,7 +71,7 @@ void (async () => {
98
71
  }
99
72
  })();
100
73
  `;
101
- function installedPiModuleUrl() {
74
+ async function installedPiModuleUrl() {
102
75
  const anchors = [
103
76
  process.argv[1],
104
77
  fileURLToPath(import.meta.url),
@@ -111,12 +84,14 @@ function installedPiModuleUrl() {
111
84
  const packageRoot = path.join(directory, "node_modules", PI_PACKAGE);
112
85
  const manifestPath = path.join(packageRoot, PACKAGE_MANIFEST);
113
86
  try {
114
- const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
87
+ const manifest = JSON.parse(await fs.readFile(manifestPath, "utf8"));
115
88
  if (typeof manifest.main === "string") {
116
89
  const entry = path.resolve(packageRoot, manifest.main);
117
90
  const skills = path.join(packageRoot, PI_SKILLS_MODULE);
118
- if (fs.existsSync(skills)) return pathToFileURL(skills).href;
119
- if (fs.existsSync(entry)) return pathToFileURL(entry).href;
91
+ for (const candidate of [skills, entry]) try {
92
+ await fs.access(candidate);
93
+ return pathToFileURL(candidate).href;
94
+ } catch {}
120
95
  }
121
96
  } catch {}
122
97
  const parent = path.dirname(directory);
@@ -190,7 +165,13 @@ var DeferredSkillLoader = class {
190
165
  #load() {
191
166
  return this.#snapshot((this.#options.load ?? loadSkills)(this.#loadOptions()));
192
167
  }
193
- #loadInWorker() {
168
+ async #loadInWorker() {
169
+ let piModuleUrl;
170
+ try {
171
+ piModuleUrl = this.#options.piModuleUrl ?? await installedPiModuleUrl();
172
+ } catch (error) {
173
+ return this.#failure(error);
174
+ }
194
175
  return new Promise((resolve) => {
195
176
  let settled = false;
196
177
  const settle = (snapshot) => {
@@ -203,7 +184,7 @@ var DeferredSkillLoader = class {
203
184
  worker = new Worker(SKILL_WORKER_SOURCE, {
204
185
  eval: true,
205
186
  workerData: {
206
- piModuleUrl: this.#options.piModuleUrl ?? installedPiModuleUrl(),
187
+ piModuleUrl,
207
188
  loadOptions: this.#loadOptions()
208
189
  }
209
190
  });
@@ -226,8 +207,11 @@ var DeferredSkillLoader = class {
226
207
  });
227
208
  }
228
209
  };
229
- /** Expands a deferred `/skill:name` before Pi consults its synchronous inventory. */
230
- function expandDeferredSkillCommand(text, skills) {
210
+ /**
211
+ * Expands a deferred `/skill:name` before Pi consults its synchronous inventory. Node discovered the
212
+ * skill on the host disk, so it reads it there; the edge build reads through `fs` instead.
213
+ */
214
+ async function expandDeferredSkillCommand(text, skills, _fs) {
231
215
  if (!text.startsWith("/skill:")) return text;
232
216
  const spaceIndex = text.indexOf(" ");
233
217
  const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);
@@ -235,7 +219,7 @@ function expandDeferredSkillCommand(text, skills) {
235
219
  if (!skill) return text;
236
220
  try {
237
221
  const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1).trim();
238
- const body = stripFrontmatter(fs.readFileSync(skill.filePath, "utf8")).trim();
222
+ const body = stripFrontmatter(await fs.readFile(skill.filePath, "utf8")).trim();
239
223
  const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${skill.baseDir}.\n\n${body}\n</skill>`;
240
224
  return args ? `${skillBlock}\n\n${args}` : skillBlock;
241
225
  } catch {
@@ -243,13 +227,20 @@ function expandDeferredSkillCommand(text, skills) {
243
227
  }
244
228
  }
245
229
  //#endregion
246
- //#region src/services/serverInventory/index.ts
230
+ //#region src/services/serverInventory/grouping.ts
231
+ /**
232
+ * Each condition that activates a group: its domains, then each plugin turned on for this session only.
233
+ * Declare one contribution per condition; the host keeps one per name once gating has run.
234
+ */
235
+ function groupConditions(group) {
236
+ return [group.domains === void 0 ? void 0 : { domains: group.domains }, ...(group.plugins ?? []).map((plugin) => ({ state: { plugins: plugin } }))];
237
+ }
247
238
  const LOCAL_ONLY_MCP_PACKAGES = /* @__PURE__ */ new Set([
248
239
  "@agimon-ai/po-author",
249
240
  "@agimon-ai/po-git",
250
241
  "@agimon-ai/po-goal",
251
242
  "@agimon-ai/po-help",
252
- "@agimon-ai/po-loop",
243
+ "@agimon-ai/po-calendar",
253
244
  "@agimon-ai/po-user-feedback",
254
245
  "@agimon-ai/po-voice",
255
246
  "@agimon-ai/po-workflow"
@@ -282,6 +273,26 @@ function within(filePath, roots) {
282
273
  });
283
274
  }
284
275
  /**
276
+ * One group per loaded skill, merging every source admitting that exact path.
277
+ * MCP admission is merged separately so local-only sources cannot broaden it.
278
+ */
279
+ function groupSkills(skills, sources, key) {
280
+ return skills.flatMap((skill) => {
281
+ const admitting = sources.filter((source) => within(skill.filePath, source[key]));
282
+ if (admitting.length === 0) return [];
283
+ const domains = [...new Set(admitting.flatMap((source) => source.domain === void 0 ? [] : [source.domain]))];
284
+ const plugins = [...new Set(admitting.flatMap((source) => source.plugin === void 0 ? [] : [source.plugin]))];
285
+ const repository = admitting.some((source) => source.domain === void 0 && source.plugin === void 0);
286
+ return [{
287
+ ...repository ? {} : { domains },
288
+ ...repository || plugins.length === 0 ? {} : { plugins },
289
+ skills: [skill]
290
+ }];
291
+ });
292
+ }
293
+ //#endregion
294
+ //#region src/services/serverInventory/index.ts
295
+ /**
285
296
  * Every skill the session could reach, grouped by what activates it.
286
297
  *
287
298
  * A cockpit `/domains` switch reconciles contributions rather than rebuilding
@@ -289,7 +300,7 @@ function within(filePath, roots) {
289
300
  * launch selection would freeze the command list at whatever was selected when
290
301
  * the session host was built. Enumerating every domain up front and tagging
291
302
  * each group with its `when` lets the existing kernel refresh do the work, the
292
- * same way domainServerResources registers per-domain skill resources.
303
+ * same way other host contributions follow selection changes.
293
304
  */
294
305
  async function discoverServerSkills(execution, fs, signal) {
295
306
  signal.throwIfAborted();
@@ -299,31 +310,64 @@ async function discoverServerSkills(execution, fs, signal) {
299
310
  const repoSkills = path.join(execution.repoRoot, ".po", "skills");
300
311
  const sources = [];
301
312
  const diagnostics = [];
302
- const domains = [];
303
- try {
304
- domains.push(...await listDomainNamesAsync(fs, execution.repoRoot, context, home));
305
- } catch (error) {
313
+ const descriptors = /* @__PURE__ */ new Map();
314
+ const manifest = await loadDomainsAsync(fs, execution.repoRoot, context, home, execution.environment).catch((error) => {
306
315
  diagnostics.push(`Domain skills are unavailable: ${error instanceof Error ? error.message : String(error)}`);
307
- }
308
- for (const domain of domains) {
316
+ });
317
+ const domains = manifest ? domainNamesOf(manifest) : [];
318
+ const discovered = /* @__PURE__ */ new Map();
319
+ if (manifest) for (const domain of domains) {
309
320
  signal.throwIfAborted();
310
321
  try {
311
- const plugins = await materializePluginEntries(await resolvePluginEntriesAsync(fs, execution.repoRoot, [domain], [], context, home));
322
+ const plugins = await materializePluginEntries(await resolveManifestPluginEntriesAsync(fs, manifest, [domain], [], context, home), {
323
+ homeDirectory: home,
324
+ environment: execution.environment
325
+ });
326
+ const key = JSON.stringify(plugins.map(({ directory, skillDiscovery, skills, source }) => ({
327
+ directory,
328
+ skillDiscovery,
329
+ skills,
330
+ source
331
+ })));
332
+ const previous = discovered.get(key);
333
+ if (previous) {
334
+ sources.push({
335
+ domain,
336
+ paths: [...previous.paths],
337
+ mcpPaths: [...previous.mcpPaths]
338
+ }, ...previous.plugins);
339
+ continue;
340
+ }
312
341
  const mcpPluginRoots = (await Promise.all(plugins.map(async (plugin) => await isMcpSkillPlugin(fs, plugin, context) ? path.join(plugin.directory, "skills") : void 0))).filter((root) => root !== void 0);
313
342
  const collected = await collectResources(execution.repoRoot, plugins, {
314
343
  agents: false,
344
+ discoverAgents: false,
315
345
  mcp: false,
316
- sharedSkills: false
346
+ sharedSkills: false,
347
+ environment: execution.environment
317
348
  });
318
349
  try {
319
- if (collected.skillDirectories.length > 0) {
320
- const paths = [...collected.skillDirectories];
321
- sources.push({
322
- domain,
323
- paths,
324
- mcpPaths: paths.filter((skillPath) => within(skillPath, mcpPluginRoots))
325
- });
326
- }
350
+ for (const descriptor of collected.skillSources) descriptors.set(descriptor.path, descriptor);
351
+ const paths = Object.freeze([...collected.skillDirectories]);
352
+ const mcpPaths = Object.freeze(paths.filter((skillPath) => within(skillPath, mcpPluginRoots)));
353
+ const pluginSources = plugins.flatMap(({ name, directory }) => {
354
+ const own = paths.filter((skillPath) => within(skillPath, [directory]));
355
+ return name === void 0 || own.length === 0 ? [] : [{
356
+ plugin: name,
357
+ paths: own,
358
+ mcpPaths: []
359
+ }];
360
+ });
361
+ discovered.set(key, Object.freeze({
362
+ paths,
363
+ mcpPaths,
364
+ plugins: pluginSources
365
+ }));
366
+ if (paths.length > 0) sources.push({
367
+ domain,
368
+ paths: [...paths],
369
+ mcpPaths: [...mcpPaths]
370
+ }, ...pluginSources);
327
371
  } finally {
328
372
  await collected.cleanup();
329
373
  }
@@ -332,20 +376,20 @@ async function discoverServerSkills(execution, fs, signal) {
332
376
  }
333
377
  }
334
378
  signal.throwIfAborted();
335
- const shared = await discoverSkillsAsync(execution.repoRoot, path.join(execution.repoRoot, ".claude", "skills"));
336
- if (shared.length > 0) {
379
+ const shared = await discoverSkillsAsync(execution.repoRoot, path.join(execution.repoRoot, ".claude", "skills"), "recursive", void 0, execution.environment);
380
+ for (const descriptor of shared) descriptors.set(descriptor.path, descriptor);
381
+ for (const descriptor of await discoverSkillsAsync(execution.repoRoot, repoSkills, "recursive", void 0, execution.environment)) descriptors.set(descriptor.path, descriptor);
382
+ if (shared.length > 0 && manifest) {
337
383
  const sharedPaths = shared.map((skill) => skill.path);
338
- for (const domain of domains) if (await resolveSharedSkillsAsync(fs, execution.repoRoot, [domain], context, home)) sources.push({
384
+ for (const domain of domains) if (sharedSkillsFor(manifest, [domain])) sources.push({
339
385
  domain,
340
386
  paths: sharedPaths,
341
- mcpPaths: sharedPaths,
342
- listed: true
387
+ mcpPaths: sharedPaths
343
388
  });
344
389
  }
345
390
  sources.push({
346
391
  paths: [repoSkills],
347
- mcpPaths: [repoSkills],
348
- listed: true
392
+ mcpPaths: [repoSkills]
349
393
  });
350
394
  signal.throwIfAborted();
351
395
  const unique = [.../* @__PURE__ */ new Set([...sources.flatMap((source) => source.paths), ...state.skillDirectories ?? []])];
@@ -354,18 +398,9 @@ async function discoverServerSkills(execution, fs, signal) {
354
398
  skillPaths: unique
355
399
  }).ready();
356
400
  signal.throwIfAborted();
357
- const groups = sources.map((source) => ({
358
- ...source.domain === void 0 ? {} : { domain: source.domain },
359
- skills: inventory.skills.filter((skill) => within(skill.filePath, source.paths))
360
- })).filter((group) => group.skills.length > 0);
361
- const listed = sources.filter((source) => source.listed === true).map((source) => ({
362
- ...source.domain === void 0 ? {} : { domain: source.domain },
363
- skills: inventory.skills.filter((skill) => within(skill.filePath, source.paths))
364
- })).filter((group) => group.skills.length > 0);
365
- const mcpGroups = sources.map((source) => ({
366
- ...source.domain === void 0 ? {} : { domain: source.domain },
367
- skills: inventory.skills.filter((skill) => within(skill.filePath, source.mcpPaths))
368
- })).filter((group) => group.skills.length > 0);
401
+ for (const descriptor of descriptors.values()) for (const diagnostic of descriptor.diagnostics ?? []) diagnostics.push(`${descriptor.path}: ${diagnostic}`);
402
+ const groups = groupSkills(inventory.skills, sources, "paths");
403
+ const mcpGroups = groupSkills(inventory.skills, sources, "mcpPaths");
369
404
  const activeSkills = inventory.skills.filter((skill) => within(skill.filePath, [...state.skillDirectories ?? [], repoSkills]));
370
405
  return {
371
406
  inventory: {
@@ -374,11 +409,160 @@ async function discoverServerSkills(execution, fs, signal) {
374
409
  },
375
410
  groups,
376
411
  mcpGroups,
377
- listed,
412
+ relations: Object.fromEntries([...descriptors].map(([filePath, descriptor]) => [filePath, descriptor.relations ?? []])),
378
413
  catalog: formatSkillsForPrompt(activeSkills) || "(no discovered skills)"
379
414
  };
380
415
  }
381
416
  //#endregion
417
+ //#region src/schemas/mcpSkillTools.ts
418
+ const searchSkillsParameters = Type.Object({ query: Type.Optional(Type.String()) });
419
+ const loadSkillParameters = Type.Object({ name: Type.String() });
420
+ //#endregion
421
+ //#region src/services/mcpSkillTools/index.ts
422
+ function text(text) {
423
+ return { content: [{
424
+ type: "text",
425
+ text
426
+ }] };
427
+ }
428
+ /** Case-insensitive substring match on name and description; an empty query keeps everything, in order. */
429
+ function matchSkills(skills, query) {
430
+ const needle = query?.trim().toLocaleLowerCase();
431
+ if (needle === void 0 || needle === "") return [...skills];
432
+ return skills.filter(({ name, description }) => `${name}\n${description}`.toLocaleLowerCase().includes(needle));
433
+ }
434
+ function createSessionSearchSkillsTool(host) {
435
+ return {
436
+ name: "search_skills",
437
+ label: "Search skills",
438
+ description: "Search available session skills by name or description.",
439
+ parameters: searchSkillsParameters,
440
+ annotations: {
441
+ readOnlyHint: true,
442
+ destructiveHint: false,
443
+ openWorldHint: false
444
+ },
445
+ executionMode: "parallel",
446
+ async execute(_toolCallId, { query }) {
447
+ const matches = matchSkills(host.listSkills().map(({ name, description }) => ({
448
+ name,
449
+ description
450
+ })), query);
451
+ return {
452
+ ...text(JSON.stringify(matches)),
453
+ structuredContent: { skills: matches }
454
+ };
455
+ }
456
+ };
457
+ }
458
+ function createSessionLoadSkillTool(host) {
459
+ return {
460
+ name: "load_skill",
461
+ label: "Load skill",
462
+ description: "Load the full instructions of an available session skill by exact name.",
463
+ parameters: loadSkillParameters,
464
+ executionMode: "parallel",
465
+ async execute(_toolCallId, { name }) {
466
+ const body = host.readSkill(name);
467
+ if (body === void 0) return {
468
+ ...text(`No skill named ${name} is available in this session.`),
469
+ isError: true
470
+ };
471
+ return text(body);
472
+ }
473
+ };
474
+ }
475
+ //#endregion
476
+ //#region src/services/skillNamespace/index.ts
477
+ const SKILL_NAMESPACE_SOURCE = "@agimon-ai/po-skill";
478
+ function queryOf(input) {
479
+ if (input === void 0) return void 0;
480
+ const query = typeof input === "object" && input !== null ? input.query : 0;
481
+ if (query === void 0 || typeof query === "string") return query;
482
+ throw new Error("Pass { query?: string }.");
483
+ }
484
+ function nameOf(input) {
485
+ const name = input?.name;
486
+ if (typeof name !== "string" || name.trim() === "") throw new Error("Pass { name: string }, a name from skills.search.");
487
+ return name;
488
+ }
489
+ /**
490
+ * Skills of every domain in domains.yaml, selected or not, plus the session's own. Reading one never selects its
491
+ * domain or plugin, so it grants no tools, hooks or MCP servers. Disabled plugins never reach the inventory.
492
+ */
493
+ function createSkillNamespace(host, inventory, fs) {
494
+ return {
495
+ name: PO_SKILLS_NAMESPACE,
496
+ summary: "Search and read skills beyond the active set, including unselected domains. Reading enables nothing.",
497
+ declarations: `declare const skills: {
498
+ /** Active skills first, then skills of unselected domains. Omit query to list everything. */
499
+ search(input?: { query?: string }): Promise<{ name: string; description: string; active: boolean }[]>;
500
+ /** Full SKILL.md text by exact name from search. Grants no tools, hooks or MCP servers. */
501
+ load(input: { name: string }): Promise<string>;
502
+ };`,
503
+ bind(run) {
504
+ if (run.sessionId !== host.context.sessionId) throw new Error("Skills namespace belongs to another session.");
505
+ let disposed = false;
506
+ run.onDispose(() => {
507
+ disposed = true;
508
+ });
509
+ const check = () => {
510
+ if (disposed) throw new Error("Skills namespace run is disposed.");
511
+ run.signal.throwIfAborted();
512
+ };
513
+ return {
514
+ async search(input) {
515
+ const query = queryOf(input);
516
+ check();
517
+ const seen = /* @__PURE__ */ new Set();
518
+ const all = [];
519
+ for (const { name, description } of host.listSkills()) {
520
+ seen.add(name);
521
+ all.push({
522
+ name,
523
+ description,
524
+ active: true
525
+ });
526
+ }
527
+ for (const { name, description } of inventory.skills) if (!seen.has(name)) all.push({
528
+ name,
529
+ description,
530
+ active: false
531
+ });
532
+ return matchSkills(all, query);
533
+ },
534
+ async load(input) {
535
+ const name = nameOf(input);
536
+ check();
537
+ const active = host.readSkill(name);
538
+ if (active !== void 0) return active;
539
+ const skill = inventory.skills.find((entry) => entry.name === name);
540
+ if (!skill) throw new Error(`No skill named ${name}. Use skills.search to find one.`);
541
+ const text = getOrThrow(await fs.readTextFile(skill.filePath, withAbortSignal(run.signal, BACKGROUND_CONTEXT)));
542
+ check();
543
+ return text;
544
+ }
545
+ };
546
+ }
547
+ };
548
+ }
549
+ function mountSkillNamespace(host, inventory, fs) {
550
+ return (context) => {
551
+ const tools = [host.registerTool(createSessionLoadSkillTool(host)), host.registerTool(createSessionSearchSkillsTool(host))];
552
+ const withdraw = () => {
553
+ for (const tool of tools.splice(0)) tool.dispose();
554
+ };
555
+ context.effect(() => withdraw, "session skill tools");
556
+ context.inject([PO_CODEMODE_SERVICE, PO_ISOLATE_SERVICE], (bound) => {
557
+ const codemode = readPoCodemode(bound);
558
+ if (!codemode) return void 0;
559
+ const registration = codemode.register(SKILL_NAMESPACE_SOURCE, createSkillNamespace(host, inventory, fs));
560
+ if (readPoIsolate(bound)?.liveObjects === true) withdraw();
561
+ return () => registration.dispose();
562
+ });
563
+ };
564
+ }
565
+ //#endregion
382
566
  //#region src/extensions/workspaces/sessions/(backend)/_lib/skillCommands.ts
383
567
  /**
384
568
  * One command per skill, gated by whatever activates that skill.
@@ -388,40 +572,51 @@ async function discoverServerSkills(execution, fs, signal) {
388
572
  * active, and looking it up in the union keeps one lookup table instead of one
389
573
  * per domain.
390
574
  */
391
- function skillCommand(skill, domain, inventory) {
575
+ function skillCommand(skill, when, inventory, fs) {
392
576
  return {
393
- ...domain === void 0 ? {} : { when: { domain } },
577
+ ...when === void 0 ? {} : { when },
394
578
  name: `${SKILL_COMMAND_PREFIX}${skill.name}`,
395
579
  description: skill.description,
396
580
  execute: async (args, execution) => {
397
581
  const text = `${SKILL_INVOCATION_PREFIX}${skill.name}${args ? ` ${args}` : ""}`;
398
- const expanded = expandDeferredSkillCommand(text, inventory.skills);
582
+ const expanded = await expandDeferredSkillCommand(text, inventory.skills, fs);
399
583
  if (expanded === text) throw new Error(`Skill '${skill.name}' is no longer readable.`);
400
- await execution.session.prompt(expanded);
584
+ await admit(execution.session, expanded);
401
585
  }
402
586
  };
403
587
  }
404
- function createSkillCommands(inventory, catalog, groups) {
588
+ /**
589
+ * The dispatching prompt acks when this command returns, so awaiting the whole
590
+ * turn (session.prompt) kept the composer draft until the run ended.
591
+ */
592
+ function admit(session, text) {
593
+ return session.admitPrompt ? session.admitPrompt(text, "prompt", "operator") : session.prompt(text);
594
+ }
595
+ function createSkillCommands(inventory, catalog, groups, fs, t = (_key, fallback) => fallback) {
405
596
  return [{
406
597
  name: SKILLS_COMMAND,
407
598
  description: "List discovered skills or invoke one by name.",
408
599
  async execute(args, execution) {
409
600
  const requested = args.trim();
410
601
  if (requested) {
411
- await execution.session.prompt(expandDeferredSkillCommand(`${SKILL_INVOCATION_PREFIX}${requested}`, inventory.skills));
602
+ await admit(execution.session, await expandDeferredSkillCommand(`${SKILL_INVOCATION_PREFIX}${requested}`, inventory.skills, fs));
412
603
  return;
413
604
  }
414
605
  await execution.client.notify({
415
- title: "Po skills",
606
+ title: t("skill.notification.catalog", "Po skills"),
607
+ localization: { title: {
608
+ key: "skill.notification.catalog",
609
+ fallback: "Po skills"
610
+ } },
416
611
  body: catalog,
417
612
  level: "info"
418
613
  });
419
614
  }
420
- }, ...groups.flatMap((group) => group.skills.map((skill) => skillCommand(skill, group.domain, inventory)))];
615
+ }, ...groups.flatMap((group) => groupConditions(group).flatMap((when) => group.skills.map((skill) => skillCommand(skill, when, inventory, fs))))];
421
616
  }
422
617
  //#endregion
423
618
  //#region src/extensions/workspaces/sessions/(backend)/_lib/skillServer.ts
424
- async function createSkillServer(agent, fs, signal, resources) {
619
+ async function createSkillServer(agent, fs, signal, resources, t) {
425
620
  const execution = agent.context;
426
621
  const key = [
427
622
  "inventory",
@@ -431,39 +626,27 @@ async function createSkillServer(agent, fs, signal, resources) {
431
626
  ...readHarnessState(execution.environment).skillDirectories ?? [],
432
627
  Math.floor(Date.now() / SKILL_INVENTORY_FRESH_MS)
433
628
  ];
434
- const { inventory, catalog, groups, mcpGroups, listed } = await resources.acquire(key, () => discoverServerSkills(execution, fs, new AbortController().signal));
629
+ const { inventory, catalog, groups, mcpGroups, relations } = await resources.acquire(key, () => discoverServerSkills(execution, fs, new AbortController().signal));
435
630
  return {
436
- commands: createSkillCommands(inventory, catalog, groups),
437
- tools: [createSessionLoadSkillTool(agent)],
438
- services: [mountMcpSkills(mcpGroups, fs, signal)],
439
- resources: [...listed.flatMap((group) => group.skills.map((skill) => ({
631
+ commands: createSkillCommands(inventory, catalog, groups, fs, t),
632
+ services: [mountMcpSkills(mcpGroups, fs, signal), mountSkillNamespace(agent, inventory, fs)],
633
+ resources: [...groups.flatMap((group) => groupConditions(group).flatMap((when) => group.skills.map((skill) => ({
440
634
  name: skill.name,
441
635
  description: skill.description,
442
636
  path: skill.filePath,
443
637
  kind: "skill",
444
- ...group.domain === void 0 ? {} : { when: {
445
- domain: group.domain,
446
- attribution: {
447
- kind: "domain",
448
- mode: group.domain
449
- }
450
- } },
638
+ ...relations?.[skill.filePath] === void 0 ? {} : { relations: relations[skill.filePath] },
639
+ ...when === void 0 ? {} : { when },
451
640
  read: async () => getOrThrow(await fs.readTextFile(skill.filePath, BACKGROUND_CONTEXT))
452
- }))), ...[{
453
- name: "po-author-skill",
641
+ })))), ...[{
642
+ name: "help-how-to-author-skill",
454
643
  description: "Author and distribute Po agent skills. Use when creating a SKILL.md, contributing a runtime skill directory, or publishing activation-gated Help prompts and diagnostic tools."
455
644
  }, {
456
- name: "po-use-skill",
645
+ name: "help-how-to-skill",
457
646
  description: "Use Po's skill catalog and deferred discovery. Diagnose missing or shadowed skills and invoke the narrowest available guidance."
458
647
  }].map((skill) => ({
459
648
  ...skill,
460
- when: {
461
- state: { "minor-mode": "help" },
462
- attribution: {
463
- kind: "minor",
464
- mode: "help"
465
- }
466
- },
649
+ when: PO_HELP_WHEN,
467
650
  kind: "skill",
468
651
  path: packageResourcePath(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),
469
652
  read: () => readPackageResource(import.meta.url, `src/prompts/${skill.name}/SKILL.md`)
@@ -473,7 +656,7 @@ async function createSkillServer(agent, fs, signal, resources) {
473
656
  //#endregion
474
657
  //#region src/extensions/workspaces/sessions/(backend)/root.server.ts
475
658
  var root_server_default = defineRoot(async ({ agent, context: root, signal, resources }) => {
476
- const runtime = agent ? await createSkillServer(agent, requirePoFs(root), signal, resources) : {
659
+ const runtime = agent ? await createSkillServer(agent, requirePoFs(root), signal, resources, (key, fallback) => readPoLang(root)?.t(readPoPersonLocale(root)?.read(), key, fallback) ?? fallback) : {
477
660
  commands: [],
478
661
  resources: []
479
662
  };
@@ -486,25 +669,25 @@ var root_server_default = defineRoot(async ({ agent, context: root, signal, reso
486
669
  //#region src/extensions/workspaces/sessions/(backend)/command/skills.server.ts
487
670
  var skills_server_default$1 = defineRoutedContribution((context) => context.root.commands, { cardinality: "many" });
488
671
  //#endregion
672
+ //#region src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts
673
+ var codemode_how_to_skills_server_default = defineResource({
674
+ name: "codemode-how-to-skills",
675
+ description: "Search and load any skill by name through the skills namespace: the listed ones, the rest of the active catalog, and skills of unselected domains. Use before a task that a skill may cover.",
676
+ pinned: true,
677
+ kind: "skill",
678
+ path: packageResourcePath(import.meta.url, "src/prompts/codemode-how-to-skills/SKILL.md"),
679
+ read: () => readPackageResource(import.meta.url, "src/prompts/codemode-how-to-skills/SKILL.md")
680
+ });
681
+ //#endregion
489
682
  //#region src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts
490
683
  var skills_server_default = defineRoutedContribution((context) => context.root.resources, { cardinality: "many" });
491
684
  //#endregion
492
- //#region src/extensions/workspaces/sessions/(backend)/tool/load_skill.server.ts
493
- /** The session agent's skill loader; the Pi CLI keeps Pi's own skill handling. */
494
- var load_skill_server_default = defineRoutedContribution((context) => context.root.tools?.[0], { cardinality: "optional" });
495
- //#endregion
496
685
  //#region generated/server.ts
497
686
  const at = (value, context) => typeof value === "function" ? value(context) : value;
498
687
  const many = (value, context) => {
499
688
  const resolved = typeof value === "function" ? value(context) : value;
500
689
  return Array.isArray(resolved) ? resolved : [resolved];
501
690
  };
502
- /* v8 ignore next -- generated normalization branch */
503
- const defined = (values) => values.filter((value) => value !== void 0);
504
- const via = (identity, value) => value === void 0 ? void 0 : {
505
- ...identity,
506
- ...value
507
- };
508
691
  const serverPlugin = defineServerPlugin({
509
692
  name: "@agimon-ai/po-skill",
510
693
  providerOverrides: composeServerProviderOverrides(root_server_default),
@@ -521,10 +704,7 @@ const serverPlugin = defineServerPlugin({
521
704
  return [...many(skills_server_default$1, contextSession)];
522
705
  },
523
706
  get resources() {
524
- return [...many(skills_server_default, contextSession)];
525
- },
526
- get tools() {
527
- return defined([via({ name: "load_skill" }, at(load_skill_server_default, contextSession))]);
707
+ return [at(codemode_how_to_skills_server_default, contextSession), ...many(skills_server_default, contextSession)];
528
708
  },
529
709
  services: [...scopeSession.services ?? []],
530
710
  get activities() {