@agimon-ai/po-skill 0.0.0-alpha.208 → 0.0.0-alpha.209
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/README.md +4 -1
- package/dist/extensions/server.cjs +70 -71
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +71 -72
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/po-runtime-identity.json +1 -1
- package/package.json +9 -9
- package/src/prompts/codemode-how-to-skills/SKILL.md +4 -4
- package/src/prompts/help-how-to-author-skill/SKILL.md +1 -1
- package/src/prompts/help-how-to-skill/SKILL.md +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,10 @@ The session agent uses `load_skill` to read instructions by exact name. With at
|
|
|
14
14
|
skills, its tool description lists their names and descriptions and `search_skills` is hidden.
|
|
15
15
|
Above 20, `search_skills` is available with all active names in its description, and returns
|
|
16
16
|
matching names and descriptions without bodies or paths. The host updates this surface as
|
|
17
|
-
skill activation changes.
|
|
17
|
+
skill activation changes. Where code mode binds live objects, the `skills` namespace replaces
|
|
18
|
+
both tools: `skills.search` and `skills.load` cover the active catalog and unselected domains,
|
|
19
|
+
and the prompt lists only pinned guides. Remote MCP clients keep their own `load_skill` and
|
|
20
|
+
`search_skills`.
|
|
18
21
|
|
|
19
22
|
## Contributing skills
|
|
20
23
|
|
|
@@ -15,13 +15,14 @@ let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile
|
|
|
15
15
|
let _agimon_ai_po_core_locale = require("@agimon-ai/po-core/locale");
|
|
16
16
|
let _agimon_ai_po_config_harnessState = require("@agimon-ai/po-config/harnessState");
|
|
17
17
|
let _agimon_ai_po_core_help = require("@agimon-ai/po-core/help");
|
|
18
|
-
let typebox = require("typebox");
|
|
19
18
|
let _agimon_ai_po_domain_resources = require("@agimon-ai/po-domain/resources");
|
|
20
19
|
let node_fs_promises = require("node:fs/promises");
|
|
21
20
|
node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises, 1);
|
|
22
21
|
let node_url = require("node:url");
|
|
23
22
|
let node_worker_threads = require("node:worker_threads");
|
|
24
23
|
let _agimon_ai_po_core_codemode = require("@agimon-ai/po-core/codemode");
|
|
24
|
+
let _agimon_ai_po_core_headless = require("@agimon-ai/po-core/headless");
|
|
25
|
+
let typebox = require("typebox");
|
|
25
26
|
//#region src/constants/skillInventory.ts
|
|
26
27
|
/**
|
|
27
28
|
* How long sessions with the same inputs share one skill inventory instead of each reading the disk.
|
|
@@ -62,65 +63,6 @@ function mountMcpSkills(groups, fs, signal) {
|
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
//#endregion
|
|
65
|
-
//#region src/schemas/mcpSkillTools.ts
|
|
66
|
-
const searchSkillsParameters = typebox.Type.Object({ query: typebox.Type.Optional(typebox.Type.String()) });
|
|
67
|
-
const loadSkillParameters = typebox.Type.Object({ name: typebox.Type.String() });
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/services/mcpSkillTools/index.ts
|
|
70
|
-
function text(text) {
|
|
71
|
-
return { content: [{
|
|
72
|
-
type: "text",
|
|
73
|
-
text
|
|
74
|
-
}] };
|
|
75
|
-
}
|
|
76
|
-
/** Case-insensitive substring match on name and description; an empty query keeps everything, in order. */
|
|
77
|
-
function matchSkills(skills, query) {
|
|
78
|
-
const needle = query?.trim().toLocaleLowerCase();
|
|
79
|
-
if (needle === void 0 || needle === "") return [...skills];
|
|
80
|
-
return skills.filter(({ name, description }) => `${name}\n${description}`.toLocaleLowerCase().includes(needle));
|
|
81
|
-
}
|
|
82
|
-
function createSessionSearchSkillsTool(host) {
|
|
83
|
-
return {
|
|
84
|
-
name: "search_skills",
|
|
85
|
-
label: "Search skills",
|
|
86
|
-
description: "Search available session skills by name or description.",
|
|
87
|
-
parameters: searchSkillsParameters,
|
|
88
|
-
annotations: {
|
|
89
|
-
readOnlyHint: true,
|
|
90
|
-
destructiveHint: false,
|
|
91
|
-
openWorldHint: false
|
|
92
|
-
},
|
|
93
|
-
executionMode: "parallel",
|
|
94
|
-
async execute(_toolCallId, { query }) {
|
|
95
|
-
const matches = matchSkills(host.listSkills().map(({ name, description }) => ({
|
|
96
|
-
name,
|
|
97
|
-
description
|
|
98
|
-
})), query);
|
|
99
|
-
return {
|
|
100
|
-
...text(JSON.stringify(matches)),
|
|
101
|
-
structuredContent: { skills: matches }
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function createSessionLoadSkillTool(host) {
|
|
107
|
-
return {
|
|
108
|
-
name: "load_skill",
|
|
109
|
-
label: "Load skill",
|
|
110
|
-
description: "Load the full instructions of an available session skill by exact name.",
|
|
111
|
-
parameters: loadSkillParameters,
|
|
112
|
-
executionMode: "parallel",
|
|
113
|
-
async execute(_toolCallId, { name }) {
|
|
114
|
-
const body = host.readSkill(name);
|
|
115
|
-
if (body === void 0) return {
|
|
116
|
-
...text(`No skill named ${name} is available in this session.`),
|
|
117
|
-
isError: true
|
|
118
|
-
};
|
|
119
|
-
return text(body);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
//#endregion
|
|
124
66
|
//#region src/services/deferredSkills/index.ts
|
|
125
67
|
const PI_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
126
68
|
const PACKAGE_MANIFEST = "package.json";
|
|
@@ -479,6 +421,65 @@ async function discoverServerSkills(execution, fs, signal) {
|
|
|
479
421
|
};
|
|
480
422
|
}
|
|
481
423
|
//#endregion
|
|
424
|
+
//#region src/schemas/mcpSkillTools.ts
|
|
425
|
+
const searchSkillsParameters = typebox.Type.Object({ query: typebox.Type.Optional(typebox.Type.String()) });
|
|
426
|
+
const loadSkillParameters = typebox.Type.Object({ name: typebox.Type.String() });
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/services/mcpSkillTools/index.ts
|
|
429
|
+
function text(text) {
|
|
430
|
+
return { content: [{
|
|
431
|
+
type: "text",
|
|
432
|
+
text
|
|
433
|
+
}] };
|
|
434
|
+
}
|
|
435
|
+
/** Case-insensitive substring match on name and description; an empty query keeps everything, in order. */
|
|
436
|
+
function matchSkills(skills, query) {
|
|
437
|
+
const needle = query?.trim().toLocaleLowerCase();
|
|
438
|
+
if (needle === void 0 || needle === "") return [...skills];
|
|
439
|
+
return skills.filter(({ name, description }) => `${name}\n${description}`.toLocaleLowerCase().includes(needle));
|
|
440
|
+
}
|
|
441
|
+
function createSessionSearchSkillsTool(host) {
|
|
442
|
+
return {
|
|
443
|
+
name: "search_skills",
|
|
444
|
+
label: "Search skills",
|
|
445
|
+
description: "Search available session skills by name or description.",
|
|
446
|
+
parameters: searchSkillsParameters,
|
|
447
|
+
annotations: {
|
|
448
|
+
readOnlyHint: true,
|
|
449
|
+
destructiveHint: false,
|
|
450
|
+
openWorldHint: false
|
|
451
|
+
},
|
|
452
|
+
executionMode: "parallel",
|
|
453
|
+
async execute(_toolCallId, { query }) {
|
|
454
|
+
const matches = matchSkills(host.listSkills().map(({ name, description }) => ({
|
|
455
|
+
name,
|
|
456
|
+
description
|
|
457
|
+
})), query);
|
|
458
|
+
return {
|
|
459
|
+
...text(JSON.stringify(matches)),
|
|
460
|
+
structuredContent: { skills: matches }
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
function createSessionLoadSkillTool(host) {
|
|
466
|
+
return {
|
|
467
|
+
name: "load_skill",
|
|
468
|
+
label: "Load skill",
|
|
469
|
+
description: "Load the full instructions of an available session skill by exact name.",
|
|
470
|
+
parameters: loadSkillParameters,
|
|
471
|
+
executionMode: "parallel",
|
|
472
|
+
async execute(_toolCallId, { name }) {
|
|
473
|
+
const body = host.readSkill(name);
|
|
474
|
+
if (body === void 0) return {
|
|
475
|
+
...text(`No skill named ${name} is available in this session.`),
|
|
476
|
+
isError: true
|
|
477
|
+
};
|
|
478
|
+
return text(body);
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
//#endregion
|
|
482
483
|
//#region src/services/skillNamespace/index.ts
|
|
483
484
|
const SKILL_NAMESPACE_SOURCE = "@agimon-ai/po-skill";
|
|
484
485
|
function queryOf(input) {
|
|
@@ -498,7 +499,7 @@ function nameOf(input) {
|
|
|
498
499
|
*/
|
|
499
500
|
function createSkillNamespace(host, inventory, fs) {
|
|
500
501
|
return {
|
|
501
|
-
name:
|
|
502
|
+
name: _agimon_ai_po_core_headless.PO_SKILLS_NAMESPACE,
|
|
502
503
|
summary: "Search and read skills beyond the active set, including unselected domains. Reading enables nothing.",
|
|
503
504
|
declarations: `declare const skills: {
|
|
504
505
|
/** Active skills first, then skills of unselected domains. Omit query to list everything. */
|
|
@@ -554,10 +555,16 @@ function createSkillNamespace(host, inventory, fs) {
|
|
|
554
555
|
}
|
|
555
556
|
function mountSkillNamespace(host, inventory, fs) {
|
|
556
557
|
return (context) => {
|
|
557
|
-
|
|
558
|
+
const tools = [host.registerTool(createSessionLoadSkillTool(host)), host.registerTool(createSessionSearchSkillsTool(host))];
|
|
559
|
+
const withdraw = () => {
|
|
560
|
+
for (const tool of tools.splice(0)) tool.dispose();
|
|
561
|
+
};
|
|
562
|
+
context.effect(() => withdraw, "session skill tools");
|
|
563
|
+
context.inject([_agimon_ai_po_core_codemode.PO_CODEMODE_SERVICE, _agimon_ai_po_core_platform.PO_ISOLATE_SERVICE], (bound) => {
|
|
558
564
|
const codemode = (0, _agimon_ai_po_core_codemode.readPoCodemode)(bound);
|
|
559
565
|
if (!codemode) return void 0;
|
|
560
566
|
const registration = codemode.register(SKILL_NAMESPACE_SOURCE, createSkillNamespace(host, inventory, fs));
|
|
567
|
+
if ((0, _agimon_ai_po_core_platform.readPoIsolate)(bound)?.liveObjects === true) withdraw();
|
|
561
568
|
return () => registration.dispose();
|
|
562
569
|
});
|
|
563
570
|
};
|
|
@@ -629,7 +636,6 @@ async function createSkillServer(agent, fs, signal, resources, t) {
|
|
|
629
636
|
const { inventory, catalog, groups, mcpGroups, relations } = await resources.acquire(key, () => discoverServerSkills(execution, fs, new AbortController().signal));
|
|
630
637
|
return {
|
|
631
638
|
commands: createSkillCommands(inventory, catalog, groups, fs, t),
|
|
632
|
-
tools: [createSessionLoadSkillTool(agent), createSessionSearchSkillsTool(agent)],
|
|
633
639
|
services: [mountMcpSkills(mcpGroups, fs, signal), mountSkillNamespace(agent, inventory, fs)],
|
|
634
640
|
resources: [...groups.flatMap((group) => groupConditions(group).flatMap((when) => group.skills.map((skill) => ({
|
|
635
641
|
name: skill.name,
|
|
@@ -673,7 +679,7 @@ var skills_server_default$1 = (0, _agimon_ai_po_core_extensionFile.defineRoutedC
|
|
|
673
679
|
//#region src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts
|
|
674
680
|
var codemode_how_to_skills_server_default = (0, _agimon_ai_po_core_extensionFile.defineResource)({
|
|
675
681
|
name: "codemode-how-to-skills",
|
|
676
|
-
description: "Search and
|
|
682
|
+
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.",
|
|
677
683
|
pinned: true,
|
|
678
684
|
kind: "skill",
|
|
679
685
|
path: (0, _agimon_ai_po_core_serverPlugin.packageResourcePath)(require("url").pathToFileURL(__filename).href, "src/prompts/codemode-how-to-skills/SKILL.md"),
|
|
@@ -683,10 +689,6 @@ var codemode_how_to_skills_server_default = (0, _agimon_ai_po_core_extensionFile
|
|
|
683
689
|
//#region src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts
|
|
684
690
|
var skills_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoutedContribution)((context) => context.root.resources, { cardinality: "many" });
|
|
685
691
|
//#endregion
|
|
686
|
-
//#region src/extensions/workspaces/sessions/(backend)/tool/load_skill.server.ts
|
|
687
|
-
/** The session agent's skill tools; the Pi CLI keeps Pi's own skill handling. */
|
|
688
|
-
var load_skill_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoutedContribution)((context) => context.root.tools ?? [], { cardinality: "many" });
|
|
689
|
-
//#endregion
|
|
690
692
|
//#region generated/server.ts
|
|
691
693
|
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
692
694
|
const many = (value, context) => {
|
|
@@ -711,9 +713,6 @@ const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
|
|
|
711
713
|
get resources() {
|
|
712
714
|
return [at(codemode_how_to_skills_server_default, contextSession), ...many(skills_server_default, contextSession)];
|
|
713
715
|
},
|
|
714
|
-
get tools() {
|
|
715
|
-
return [...many(load_skill_server_default, contextSession)];
|
|
716
|
-
},
|
|
717
716
|
services: [...scopeSession.services ?? []],
|
|
718
717
|
get activities() {
|
|
719
718
|
return [...scopeSession.activities ?? []];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.cjs","names":["getOrThrow","withAbortSignal","BACKGROUND_CONTEXT","Type","path","fileURLToPath","fs","pathToFileURL","getAgentDir","loadSkills","Worker","stripFrontmatter","path","withAbortSignal","BACKGROUND_CONTEXT","readHarnessState","nodeHost","path","loadDomainsAsync","domainNamesOf","materializePluginEntries","resolveManifestPluginEntriesAsync","collectResources","discoverSkillsAsync","sharedSkillsFor","formatSkillsForPrompt","getOrThrow","withAbortSignal","BACKGROUND_CONTEXT","PO_CODEMODE_SERVICE","readPoCodemode","SKILL_COMMAND_PREFIX","SKILL_INVOCATION_PREFIX","SKILLS_COMMAND","nodeHost","readHarnessState","getOrThrow","BACKGROUND_CONTEXT","PO_HELP_WHEN","packageResourcePath","readPackageResource","defineRoot","requirePoFs","readPoLang","readPoPersonLocale","defineRoutedContribution","defineResource","packageResourcePath","readPackageResource","defineRoutedContribution","defineRoutedContribution","defineServerPlugin","composeServerProviderOverrides","rootSession","composeRootInjects","composeRootHooks","commandSkills","resourceCodemodeHowToSkills","resourceSkills","toolLoadSkill"],"sources":["../../src/constants/skillInventory.ts","../../src/services/mcpSkills/index.ts","../../src/schemas/mcpSkillTools.ts","../../src/services/mcpSkillTools/index.ts","../../src/services/deferredSkills/index.ts","../../src/services/serverInventory/grouping.ts","../../src/services/serverInventory/index.ts","../../src/services/skillNamespace/index.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/skillCommands.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/skillServer.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/extensions/workspaces/sessions/(backend)/command/skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/tool/load_skill.server.ts","../../generated/server.ts"],"sourcesContent":["/**\n * How long sessions with the same inputs share one skill inventory instead of each reading the disk.\n * ponytail: a skill added on disk reaches new sessions within this window, not at once; watch the\n * skill roots if that lag matters.\n */\nexport const SKILL_INVENTORY_FRESH_MS = 60_000;\n","import type { PoMcpPluginContext, PoMcpSkill } from '@agimon-ai/po-core/mcpFacet';\nimport { BACKGROUND_CONTEXT, getOrThrow, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { ServerSkillGroup } from '../serverInventory';\n\nexport const MCP_SKILLS_SERVICE = 'po/discovered-mcp-skills';\n\nexport interface McpSkillProvider {\n list(context: PoMcpPluginContext): readonly PoMcpSkill[];\n}\n\n/** Explicit remote provider, never a projection of the local resource registry. */\nexport function mountMcpSkills(groups: readonly ServerSkillGroup[], fs: FileSystem, signal: AbortSignal) {\n return (context: Context): void => {\n context.provide(MCP_SKILLS_SERVICE, {\n list(remote) {\n signal.throwIfAborted();\n remote.signal.throwIfAborted();\n const domains = remote.selection.read().domains;\n const skills = new Map<string, PoMcpSkill>();\n for (const group of groups) {\n if (group.domains !== undefined && !group.domains.some((domain) => domains.includes(domain))) continue;\n for (const skill of group.skills) {\n // Retain name precedence defensively for remote providers.\n if (skills.has(skill.name)) continue;\n skills.set(skill.name, {\n name: skill.name,\n description: skill.description,\n async read() {\n const readSignal = AbortSignal.any([signal, remote.signal]);\n readSignal.throwIfAborted();\n const text = getOrThrow(\n await fs.readTextFile(skill.filePath, withAbortSignal(readSignal, BACKGROUND_CONTEXT)),\n );\n readSignal.throwIfAborted();\n return text;\n },\n });\n }\n }\n return [...skills.values()];\n },\n } satisfies McpSkillProvider);\n };\n}\n\nexport function bindMcpSkills(context: PoMcpPluginContext): readonly PoMcpSkill[] {\n const provider = context.services.get<McpSkillProvider>(MCP_SKILLS_SERVICE);\n if (!provider) throw new Error('Discovered MCP skills are unavailable.');\n return provider.list(context);\n}\n","import { Type } from 'typebox';\n\nexport const searchSkillsParameters = Type.Object({ query: Type.Optional(Type.String()) });\nexport const loadSkillParameters = Type.Object({ name: Type.String() });\n","import type { PoHeadlessHostService, PoHeadlessTool } from '@agimon-ai/po-core/headless';\n\nimport { loadSkillParameters, searchSkillsParameters } from '../../schemas/mcpSkillTools';\n\nfunction text(text: string) {\n return { content: [{ type: 'text' as const, text }] };\n}\n\nfunction skills(context: Parameters<PoHeadlessTool['execute']>[4]) {\n if (context.mcpSkills === undefined) throw new Error('Remote skill access is unavailable.');\n return context.mcpSkills;\n}\n\n/** Case-insensitive substring match on name and description; an empty query keeps everything, in order. */\nexport function matchSkills<T extends { name: string; description: string }>(\n skills: readonly T[],\n query?: string,\n): T[] {\n const needle = query?.trim().toLocaleLowerCase();\n if (needle === undefined || needle === '') return [...skills];\n return skills.filter(({ name, description }) => `${name}\\n${description}`.toLocaleLowerCase().includes(needle));\n}\n\nexport function createSearchSkillsTool(): PoHeadlessTool<typeof searchSkillsParameters> {\n return {\n name: 'search_skills',\n label: 'Search skills',\n description: 'Discover repository and active-domain skills available to this remote connection.',\n parameters: searchSkillsParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n async execute(_toolCallId, { query }, _signal, _onUpdate, context) {\n const matches = matchSkills(await skills(context).list(), query);\n return { ...text(JSON.stringify(matches)), structuredContent: { skills: matches } };\n },\n };\n}\n\nexport function createSessionSearchSkillsTool(\n host: Pick<PoHeadlessHostService, 'listSkills'>,\n): PoHeadlessTool<typeof searchSkillsParameters> {\n return {\n name: 'search_skills',\n label: 'Search skills',\n description: 'Search available session skills by name or description.',\n parameters: searchSkillsParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n executionMode: 'parallel',\n async execute(_toolCallId, { query }) {\n const matches = matchSkills(\n host.listSkills().map(({ name, description }) => ({ name, description })),\n query,\n );\n return { ...text(JSON.stringify(matches)), structuredContent: { skills: matches } };\n },\n };\n}\n\nexport function createSessionLoadSkillTool(\n host: Pick<PoHeadlessHostService, 'readSkill'>,\n): PoHeadlessTool<typeof loadSkillParameters> {\n return {\n // PO_LOAD_SKILL_TOOL, spelled out so the renderer rule can read it.\n name: 'load_skill',\n label: 'Load skill',\n description: 'Load the full instructions of an available session skill by exact name.',\n parameters: loadSkillParameters,\n executionMode: 'parallel',\n async execute(_toolCallId, { name }) {\n const body = host.readSkill(name);\n if (body === undefined) return { ...text(`No skill named ${name} is available in this session.`), isError: true };\n return text(body);\n },\n };\n}\n\nexport function createLoadSkillTool(): PoHeadlessTool<typeof loadSkillParameters> {\n return {\n name: 'load_skill',\n label: 'Load skill',\n description: 'Load the full Markdown instructions for an available remote skill by exact name.',\n parameters: loadSkillParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n async execute(_toolCallId, { name }, _signal, _onUpdate, context) {\n return text(await skills(context).read(name));\n },\n };\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { Worker } from 'node:worker_threads';\n\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n type BuildSystemPromptOptions,\n formatSkillsForPrompt,\n getAgentDir,\n loadSkills,\n type Skill,\n stripFrontmatter,\n} from '@earendil-works/pi-coding-agent';\n\nimport type { DeferredSkillLoaderOptions, DeferredSkillSnapshot } from '../../types/skills';\n\nexport type { DeferredSkillLoaderOptions, DeferredSkillSnapshot } from '../../types/skills';\n\nconst PI_PACKAGE = '@earendil-works/pi-coding-agent';\nconst PACKAGE_MANIFEST = 'package.json';\n// A fresh worker takes ~240 ms to import Pi's main entry but ~20 ms for this module alone, and\n// every session spawns one. ponytail: not in Pi's exports map, so a Pi release that moves it\n// falls back to the main entry (slow, still correct); deferredSkills.test.ts pins the path.\nconst PI_SKILLS_MODULE = path.join('dist', 'core', 'skills.js');\nconst SKILL_WORKER_SOURCE = `\nconst { parentPort, workerData } = require('node:worker_threads');\nvoid (async () => {\n try {\n const { loadSkills } = await import(workerData.piModuleUrl);\n parentPort.postMessage({ ok: true, result: loadSkills(workerData.loadOptions) });\n } catch (error) {\n parentPort.postMessage({ ok: false, error: error instanceof Error ? error.message : String(error) });\n }\n})();\n`;\n\nasync function installedPiModuleUrl(): Promise<string> {\n const anchors = [process.argv[1], fileURLToPath(import.meta.url), path.join(process.cwd(), PACKAGE_MANIFEST)];\n for (const anchor of anchors) {\n if (!anchor) continue;\n let directory = path.dirname(path.resolve(anchor));\n while (true) {\n const packageRoot = path.join(directory, 'node_modules', PI_PACKAGE);\n const manifestPath = path.join(packageRoot, PACKAGE_MANIFEST);\n try {\n const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')) as { main?: unknown };\n if (typeof manifest.main === 'string') {\n const entry = path.resolve(packageRoot, manifest.main);\n const skills = path.join(packageRoot, PI_SKILLS_MODULE);\n for (const candidate of [skills, entry]) {\n try {\n await fs.access(candidate);\n return pathToFileURL(candidate).href;\n } catch {\n // Try the next entry before walking up the module chain.\n }\n }\n }\n } catch {\n // This anchor does not expose Pi at this level; continue up its module chain.\n }\n const parent = path.dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n }\n throw new Error(`Cannot resolve ${PI_PACKAGE} from the Po or host module trees`);\n}\n\ninterface SkillWorkerResult {\n ok: boolean;\n result?: { skills: Skill[]; diagnostics: Array<{ path?: string; message: string }> };\n error?: string;\n}\n\n/**\n * One session's Po-selected skill inventory.\n *\n * Construction is deliberately cheap. `start()` schedules the synchronous Pi\n * walker after session_start returns, while `ready()` is the single promise the\n * first input awaits before Pi expands `/skill:name`.\n */\nexport class DeferredSkillLoader {\n readonly #options: DeferredSkillLoaderOptions;\n #promise: Promise<DeferredSkillSnapshot> | undefined;\n\n constructor(options: DeferredSkillLoaderOptions) {\n this.#options = options;\n }\n\n start(): Promise<DeferredSkillSnapshot> {\n if (this.#promise) return this.#promise;\n\n if (!this.#options.schedule && !this.#options.load) {\n this.#promise = this.#loadInWorker();\n return this.#promise;\n }\n\n const schedule = this.#options.schedule ?? ((load: () => void) => setImmediate(load));\n this.#promise = new Promise((resolve) => {\n const fail = (error: unknown): void => {\n resolve(this.#failure(error));\n };\n try {\n schedule(() => {\n try {\n resolve(this.#load());\n } catch (error) {\n fail(error);\n }\n });\n } catch (error) {\n fail(error);\n }\n });\n return this.#promise;\n }\n\n ready(): Promise<DeferredSkillSnapshot> {\n return this.start();\n }\n\n #loadOptions(): { cwd: string; agentDir: string; skillPaths: string[]; includeDefaults: boolean } {\n return {\n cwd: this.#options.cwd,\n agentDir: this.#options.agentDir ?? getAgentDir(),\n skillPaths: [...this.#options.skillPaths],\n includeDefaults: false,\n };\n }\n\n #snapshot(result: {\n skills: Skill[];\n diagnostics: Array<{ path?: string; message: string }>;\n }): DeferredSkillSnapshot {\n return {\n skills: result.skills,\n diagnostics: result.diagnostics.map(\n (diagnostic) => `${diagnostic.path ?? this.#options.cwd}: ${diagnostic.message}`,\n ),\n };\n }\n\n #failure(error: unknown): DeferredSkillSnapshot {\n return {\n skills: [],\n diagnostics: [`${this.#options.cwd}: ${error instanceof Error ? error.message : String(error)}`],\n };\n }\n\n #load(): DeferredSkillSnapshot {\n return this.#snapshot((this.#options.load ?? loadSkills)(this.#loadOptions()));\n }\n\n async #loadInWorker(): Promise<DeferredSkillSnapshot> {\n let piModuleUrl: string;\n try {\n piModuleUrl = this.#options.piModuleUrl ?? (await installedPiModuleUrl());\n } catch (error) {\n return this.#failure(error);\n }\n return new Promise((resolve) => {\n let settled = false;\n const settle = (snapshot: DeferredSkillSnapshot): void => {\n if (settled) return;\n settled = true;\n resolve(snapshot);\n };\n let worker: Worker;\n try {\n worker = new Worker(SKILL_WORKER_SOURCE, {\n eval: true,\n workerData: {\n piModuleUrl,\n loadOptions: this.#loadOptions(),\n },\n });\n } catch (error) {\n settle(this.#failure(error));\n return;\n }\n worker.unref();\n worker.once('message', (message: SkillWorkerResult) => {\n if (!message.ok || !message.result) {\n settle(this.#failure(message.error ?? 'Skill worker failed'));\n return;\n }\n settle(this.#snapshot(message.result));\n });\n worker.once('error', (error) => settle(this.#failure(error)));\n worker.once('exit', (code) => {\n if (code !== 0) settle(this.#failure(`Skill worker exited with code ${code}`));\n });\n });\n }\n}\n\n/** Appends only the inventory Pi would append for these deferred skills. */\nexport function buildPromptWithDeferredSkills(\n systemPrompt: string,\n options: BuildSystemPromptOptions,\n skills: Skill[],\n): string {\n if (options.selectedTools && !options.selectedTools.includes('read')) return systemPrompt;\n return `${systemPrompt}${formatSkillsForPrompt(skills)}`;\n}\n\n/**\n * Expands a deferred `/skill:name` before Pi consults its synchronous inventory. Node discovered the\n * skill on the host disk, so it reads it there; the edge build reads through `fs` instead.\n */\nexport async function expandDeferredSkillCommand(\n text: string,\n skills: readonly Skill[],\n _fs?: FileSystem,\n): Promise<string> {\n if (!text.startsWith('/skill:')) return text;\n const spaceIndex = text.indexOf(' ');\n const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);\n const skill = skills.find((candidate) => candidate.name === skillName);\n if (!skill) return text;\n\n try {\n const args = spaceIndex === -1 ? '' : text.slice(spaceIndex + 1).trim();\n const body = stripFrontmatter(await fs.readFile(skill.filePath, 'utf8')).trim();\n const skillBlock = `<skill name=\"${skill.name}\" location=\"${skill.filePath}\">\\nReferences are relative to ${skill.baseDir}.\\n\\n${body}\\n</skill>`;\n return args ? `${skillBlock}\\n\\n${args}` : skillBlock;\n } catch {\n // Pi uses the same literal-text fallback if a skill disappears between\n // discovery and submission; the agent can still respond to the command.\n return text;\n }\n}\n","import path from 'node:path';\n\nimport type { PluginEntry } from '@agimon-ai/po-config/domains';\nimport type { PoHeadlessCondition } from '@agimon-ai/po-core/headless';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Skill } from '@earendil-works/pi-coding-agent';\n\nimport type { ServerSkillGroup } from '../../types/skills';\n\n/**\n * Each condition that activates a group: its domains, then each plugin turned on for this session only.\n * Declare one contribution per condition; the host keeps one per name once gating has run.\n */\nexport function groupConditions(group: ServerSkillGroup): (PoHeadlessCondition | undefined)[] {\n return [\n group.domains === undefined ? undefined : { domains: group.domains },\n // `plugins` is po-domain's session state key, spelled out so this runs on hosts with an older po-core.\n ...(group.plugins ?? []).map((plugin) => ({ state: { plugins: plugin } })),\n ];\n}\n/**\n * Skill paths one domain admits, or one plugin's session-only activation (`plugin`), or the repository when\n * neither is set.\n */\nexport interface SkillSource {\n readonly domain?: string;\n readonly plugin?: string;\n readonly paths: readonly string[];\n readonly mcpPaths: readonly string[];\n}\n\nconst LOCAL_ONLY_MCP_PACKAGES = new Set([\n '@agimon-ai/po-author',\n '@agimon-ai/po-git',\n '@agimon-ai/po-goal',\n '@agimon-ai/po-help',\n '@agimon-ai/po-calendar',\n '@agimon-ai/po-user-feedback',\n '@agimon-ai/po-voice',\n '@agimon-ai/po-workflow',\n]);\n\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\nexport async function isMcpSkillPlugin(fs: FileSystem, entry: PluginEntry, context: IoContext): Promise<boolean> {\n if (entry.source?.type === 'npm') return !LOCAL_ONLY_MCP_PACKAGES.has(entry.source.package);\n // A package manifest is optional for catalog plugins, but a present identity\n // that cannot be read or parsed must never make the plugin remotely eligible.\n const source = await fs.readTextFile(path.join(entry.directory, 'package.json'), context);\n if (!source.ok) return source.error.code === 'not_found';\n try {\n const manifest = JSON.parse(source.value) as unknown;\n if (typeof manifest !== 'object' || manifest === null || Array.isArray(manifest)) return false;\n const name = (manifest as { name?: unknown }).name;\n return typeof name === 'string' && name.length > 0 && name.trim() === name && !LOCAL_ONLY_MCP_PACKAGES.has(name);\n } catch {\n return false;\n }\n}\n\n/**\n * Whether a discovered skill came from one of these paths.\n *\n * A source holds exact SKILL.md files for plugin and shared skills, but a bare\n * directory for `.po/skills`, so membership is containment rather than\n * equality.\n */\nexport function within(filePath: string, roots: readonly string[]): boolean {\n const resolved = path.resolve(filePath);\n return roots.some((root) => {\n const base = path.resolve(root);\n return resolved === base || resolved.startsWith(`${base}${path.sep}`);\n });\n}\n\n/**\n * One group per loaded skill, merging every source admitting that exact path.\n * MCP admission is merged separately so local-only sources cannot broaden it.\n */\nexport function groupSkills(\n skills: readonly Skill[],\n sources: readonly SkillSource[],\n key: 'paths' | 'mcpPaths',\n): ServerSkillGroup[] {\n return skills.flatMap((skill) => {\n const admitting = sources.filter((source) => within(skill.filePath, source[key]));\n if (admitting.length === 0) return [];\n const domains = [...new Set(admitting.flatMap((source) => (source.domain === undefined ? [] : [source.domain])))];\n const plugins = [...new Set(admitting.flatMap((source) => (source.plugin === undefined ? [] : [source.plugin])))];\n const repository = admitting.some((source) => source.domain === undefined && source.plugin === undefined);\n return [\n {\n ...(repository ? {} : { domains }),\n ...(repository || plugins.length === 0 ? {} : { plugins }),\n skills: [skill],\n },\n ];\n });\n}\n","import path from 'node:path';\n\nimport {\n domainNamesOf,\n loadDomainsAsync,\n resolveManifestPluginEntriesAsync,\n sharedSkillsFor,\n} from '@agimon-ai/po-config/domains';\nimport { readHarnessState } from '@agimon-ai/po-config/harnessState';\nimport type { PoHeadlessExecutionContext } from '@agimon-ai/po-core/headless';\nimport { BACKGROUND_CONTEXT, nodeHost, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport { materializePluginEntries } from '@agimon-ai/po-domain/plugins';\nimport { collectResources, discoverSkillsAsync, type NamedResource } from '@agimon-ai/po-domain/resources';\nimport { formatSkillsForPrompt } from '@earendil-works/pi-coding-agent';\n\nimport type { ServerSkillInventory } from '../../types/skills';\nimport { DeferredSkillLoader } from '../deferredSkills';\nimport { groupSkills, isMcpSkillPlugin, type SkillSource, within } from './grouping';\n\nexport type { ServerSkillGroup, ServerSkillInventory } from '../../types/skills';\n\n/**\n * Every skill the session could reach, grouped by what activates it.\n *\n * A cockpit `/domains` switch reconciles contributions rather than rebuilding\n * the server plugin: the session declaration is mounted once. So enumerating only the\n * launch selection would freeze the command list at whatever was selected when\n * the session host was built. Enumerating every domain up front and tagging\n * each group with its `when` lets the existing kernel refresh do the work, the\n * same way other host contributions follow selection changes.\n */\nexport async function discoverServerSkills(\n execution: PoHeadlessExecutionContext,\n fs: FileSystem,\n signal: AbortSignal,\n): Promise<ServerSkillInventory> {\n signal.throwIfAborted();\n const context = withAbortSignal(signal, BACKGROUND_CONTEXT);\n const state = readHarnessState(execution.environment);\n const home = execution.environment.HOME ?? nodeHost.homeDirectory();\n const repoSkills = path.join(execution.repoRoot, '.po', 'skills');\n const sources: SkillSource[] = [];\n const diagnostics: string[] = [];\n const descriptors = new Map<string, NamedResource>();\n // A malformed domain is a configuration error in one domain, so it must not\n // remove every other domain's skills. Enumerating the whole manifest is new\n // exposure here: reading the launch selection could not fail this way.\n const manifest = await loadDomainsAsync(fs, execution.repoRoot, context, home, execution.environment).catch(\n (error: unknown) => {\n diagnostics.push(`Domain skills are unavailable: ${error instanceof Error ? error.message : String(error)}`);\n return undefined;\n },\n );\n const domains = manifest ? domainNamesOf(manifest) : [];\n\n // Plugin sources precede shared sources, then repository sources.\n // ponytail: Pi globally name-dedupes before domain gating. A loaded plugin\n // shadows a same-name shared fallback even when its domain is off. This is\n // the current ceiling; upgrade to selection-aware loading if collisions arise.\n // Reuse only immutable discovery paths within this invocation. The key keeps\n // plugin ordering and subsets; fs, repo, home and admitted environment are\n // fixed here. No inventory, cleanup handle or session state survives a call.\n const discovered = new Map<\n string,\n Readonly<{ paths: readonly string[]; mcpPaths: readonly string[]; plugins: readonly SkillSource[] }>\n >();\n if (manifest) {\n for (const domain of domains) {\n signal.throwIfAborted();\n try {\n const plugins = await materializePluginEntries(\n await resolveManifestPluginEntriesAsync(fs, manifest, [domain], [], context, home),\n { homeDirectory: home, environment: execution.environment },\n );\n const key = JSON.stringify(\n plugins.map(({ directory, skillDiscovery, skills, source }) => ({\n directory,\n skillDiscovery,\n skills,\n source,\n })),\n );\n const previous = discovered.get(key);\n if (previous) {\n sources.push({ domain, paths: [...previous.paths], mcpPaths: [...previous.mcpPaths] }, ...previous.plugins);\n continue;\n }\n const mcpPluginRoots = (\n await Promise.all(\n plugins.map(async (plugin) =>\n (await isMcpSkillPlugin(fs, plugin, context)) ? path.join(plugin.directory, 'skills') : undefined,\n ),\n )\n ).filter((root): root is string => root !== undefined);\n const collected = await collectResources(execution.repoRoot, plugins, {\n agents: false,\n discoverAgents: false,\n mcp: false,\n sharedSkills: false,\n environment: execution.environment,\n });\n try {\n for (const descriptor of collected.skillSources) descriptors.set(descriptor.path, descriptor);\n const paths = Object.freeze([...collected.skillDirectories]);\n // Exact collected paths retain this domain's per-plugin skill subset.\n // A plugin root would also admit skills loaded for another domain.\n const mcpPaths = Object.freeze(paths.filter((skillPath) => within(skillPath, mcpPluginRoots)));\n // The same skills, admitted one plugin at a time for session-only activation. Never remote: no mcpPaths.\n const pluginSources = plugins.flatMap(({ name, directory }) => {\n const own = paths.filter((skillPath) => within(skillPath, [directory]));\n return name === undefined || own.length === 0 ? [] : [{ plugin: name, paths: own, mcpPaths: [] }];\n });\n discovered.set(key, Object.freeze({ paths, mcpPaths, plugins: pluginSources }));\n if (paths.length > 0) sources.push({ domain, paths: [...paths], mcpPaths: [...mcpPaths] }, ...pluginSources);\n } finally {\n await collected.cleanup();\n }\n } catch (error) {\n diagnostics.push(`Domain '${domain}': ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n }\n\n // Shared skills are admitted by any domain that keeps them.\n signal.throwIfAborted();\n const shared = await discoverSkillsAsync(\n execution.repoRoot,\n path.join(execution.repoRoot, '.claude', 'skills'),\n 'recursive',\n undefined,\n execution.environment,\n );\n for (const descriptor of shared) descriptors.set(descriptor.path, descriptor);\n for (const descriptor of await discoverSkillsAsync(\n execution.repoRoot,\n repoSkills,\n 'recursive',\n undefined,\n execution.environment,\n ))\n descriptors.set(descriptor.path, descriptor);\n if (shared.length > 0 && manifest) {\n const sharedPaths = shared.map((skill) => skill.path);\n for (const domain of domains) {\n if (sharedSkillsFor(manifest, [domain])) {\n sources.push({ domain, paths: sharedPaths, mcpPaths: sharedPaths });\n }\n }\n }\n\n // Repository-local skills belong to the repository, not to a selection.\n sources.push({ paths: [repoSkills], mcpPaths: [repoSkills] });\n\n signal.throwIfAborted();\n // One walk for every group. Pi drops a path it has already loaded, so the\n // loader gets the unique set and each group selects its own skills back out.\n const unique = [...new Set([...sources.flatMap((source) => source.paths), ...(state.skillDirectories ?? [])])];\n const inventory = await new DeferredSkillLoader({ cwd: execution.cwd, skillPaths: unique }).ready();\n signal.throwIfAborted();\n\n for (const descriptor of descriptors.values()) {\n for (const diagnostic of descriptor.diagnostics ?? []) diagnostics.push(`${descriptor.path}: ${diagnostic}`);\n }\n const groups = groupSkills(inventory.skills, sources, 'paths');\n const mcpGroups = groupSkills(inventory.skills, sources, 'mcpPaths');\n\n // The catalog still describes the active selection rather than everything on\n // disk, because it is prompt text rather than a menu.\n const activeSkills = inventory.skills.filter((skill) =>\n within(skill.filePath, [...(state.skillDirectories ?? []), repoSkills]),\n );\n return {\n inventory: { skills: inventory.skills, diagnostics: [...inventory.diagnostics, ...diagnostics] },\n groups,\n mcpGroups,\n relations: Object.fromEntries(\n [...descriptors].map(([filePath, descriptor]) => [filePath, descriptor.relations ?? []]),\n ),\n catalog: formatSkillsForPrompt(activeSkills) || '(no discovered skills)',\n };\n}\n","import { PO_CODEMODE_SERVICE, readPoCodemode, type PoCodemodeNamespace } from '@agimon-ai/po-core/codemode';\nimport type { PoHeadlessHostService } from '@agimon-ai/po-core/headless';\nimport { BACKGROUND_CONTEXT, getOrThrow, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { DeferredSkillSnapshot } from '../../types/skills';\nimport { matchSkills } from '../mcpSkillTools';\n\nexport const SKILL_NAMESPACE_SOURCE = '@agimon-ai/po-skill';\n\ninterface SkillMatch {\n name: string;\n description: string;\n active: boolean;\n}\n\nfunction queryOf(input: unknown): string | undefined {\n if (input === undefined) return undefined;\n const query = typeof input === 'object' && input !== null ? (input as { query?: unknown }).query : 0;\n if (query === undefined || typeof query === 'string') return query;\n throw new Error('Pass { query?: string }.');\n}\n\nfunction nameOf(input: unknown): string {\n const name = (input as { name?: unknown } | null)?.name;\n if (typeof name !== 'string' || name.trim() === '')\n throw new Error('Pass { name: string }, a name from skills.search.');\n return name;\n}\n\n/**\n * Skills of every domain in domains.yaml, selected or not, plus the session's own. Reading one never selects its\n * domain or plugin, so it grants no tools, hooks or MCP servers. Disabled plugins never reach the inventory.\n */\nexport function createSkillNamespace(\n host: Pick<PoHeadlessHostService, 'listSkills' | 'readSkill' | 'context'>,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem,\n): PoCodemodeNamespace {\n return {\n name: 'skills',\n summary: 'Search and read skills beyond the active set, including unselected domains. Reading enables nothing.',\n declarations: `declare const skills: {\n /** Active skills first, then skills of unselected domains. Omit query to list everything. */\n search(input?: { query?: string }): Promise<{ name: string; description: string; active: boolean }[]>;\n /** Full SKILL.md text by exact name from search. Grants no tools, hooks or MCP servers. */\n load(input: { name: string }): Promise<string>;\n};`,\n bind(run) {\n if (run.sessionId !== host.context.sessionId) throw new Error('Skills namespace belongs to another session.');\n let disposed = false;\n run.onDispose(() => {\n disposed = true;\n });\n const check = () => {\n if (disposed) throw new Error('Skills namespace run is disposed.');\n run.signal.throwIfAborted();\n };\n return {\n async search(input?: unknown): Promise<SkillMatch[]> {\n const query = queryOf(input);\n check();\n const seen = new Set<string>();\n const all: SkillMatch[] = [];\n for (const { name, description } of host.listSkills()) {\n seen.add(name);\n all.push({ name, description, active: true });\n }\n for (const { name, description } of inventory.skills)\n if (!seen.has(name)) all.push({ name, description, active: false });\n return matchSkills(all, query);\n },\n async load(input: unknown): Promise<string> {\n const name = nameOf(input);\n check();\n const active = host.readSkill(name);\n if (active !== undefined) return active;\n // Exact inventory names only, so a script can never steer the read to another path.\n const skill = inventory.skills.find((entry) => entry.name === name);\n if (!skill) throw new Error(`No skill named ${name}. Use skills.search to find one.`);\n const text = getOrThrow(\n await fs.readTextFile(skill.filePath, withAbortSignal(run.signal, BACKGROUND_CONTEXT)),\n );\n check();\n return text;\n },\n };\n },\n };\n}\n\nexport function mountSkillNamespace(\n host: Pick<PoHeadlessHostService, 'listSkills' | 'readSkill' | 'context'>,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem,\n) {\n return (context: Context): void => {\n context.inject([PO_CODEMODE_SERVICE], (bound) => {\n const codemode = readPoCodemode(bound);\n if (!codemode) return undefined;\n const registration = codemode.register(SKILL_NAMESPACE_SOURCE, createSkillNamespace(host, inventory, fs));\n return () => registration.dispose();\n });\n };\n}\n","import type { PoHeadlessCommand, PoHeadlessCondition } from '@agimon-ai/po-core/headless';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Skill } from '@earendil-works/pi-coding-agent';\n\nimport { expandDeferredSkillCommand, type DeferredSkillSnapshot } from '../../../../../services/deferredSkills';\nimport type { ServerSkillGroup } from '../../../../../services/serverInventory';\nimport { groupConditions } from '../../../../../services/serverInventory/grouping';\nimport { SKILL_COMMAND_PREFIX, SKILL_INVOCATION_PREFIX, SKILLS_COMMAND } from '../../../../../types/skills';\n\n/**\n * One command per skill, gated by whatever activates that skill.\n *\n * Expansion always reads the full inventory, not the group: a command is only\n * dispatchable while its condition holds, so by the time one runs its skill is\n * active, and looking it up in the union keeps one lookup table instead of one\n * per domain.\n */\nfunction skillCommand(\n skill: Skill,\n when: PoHeadlessCondition | undefined,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem | undefined,\n): PoHeadlessCommand {\n return {\n ...(when === undefined ? {} : { when }),\n name: `${SKILL_COMMAND_PREFIX}${skill.name}`,\n description: skill.description,\n execute: async (args, execution) => {\n const text = `${SKILL_INVOCATION_PREFIX}${skill.name}${args ? ` ${args}` : ''}`;\n const expanded = await expandDeferredSkillCommand(text, inventory.skills, fs);\n if (expanded === text) throw new Error(`Skill '${skill.name}' is no longer readable.`);\n await admit(execution.session, expanded);\n },\n };\n}\n\n/**\n * The dispatching prompt acks when this command returns, so awaiting the whole\n * turn (session.prompt) kept the composer draft until the run ended.\n */\nfunction admit(session: Parameters<PoHeadlessCommand['execute']>[1]['session'], text: string): Promise<void> {\n return session.admitPrompt ? session.admitPrompt(text, 'prompt', 'operator') : session.prompt(text);\n}\nexport function createSkillCommands(\n inventory: DeferredSkillSnapshot,\n catalog: string,\n groups: readonly ServerSkillGroup[],\n fs?: FileSystem,\n t: (key: string, fallback: string) => string = (_key, fallback) => fallback,\n): readonly PoHeadlessCommand[] {\n return [\n {\n name: SKILLS_COMMAND,\n description: 'List discovered skills or invoke one by name.',\n async execute(args, execution) {\n const requested = args.trim();\n if (requested) {\n await admit(\n execution.session,\n await expandDeferredSkillCommand(`${SKILL_INVOCATION_PREFIX}${requested}`, inventory.skills, fs),\n );\n return;\n }\n await execution.client.notify({\n title: t('skill.notification.catalog', 'Po skills'),\n localization: { title: { key: 'skill.notification.catalog', fallback: 'Po skills' } },\n body: catalog,\n level: 'info',\n });\n },\n },\n ...groups.flatMap((group) =>\n groupConditions(group).flatMap((when) => group.skills.map((skill) => skillCommand(skill, when, inventory, fs))),\n ),\n ];\n}\n","import { readHarnessState } from '@agimon-ai/po-config/harnessState';\nimport type { PoHeadlessHostService } from '@agimon-ai/po-core/headless';\nimport { PO_HELP_WHEN } from '@agimon-ai/po-core/help';\nimport { BACKGROUND_CONTEXT, getOrThrow, nodeHost, type FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n type PoServerResources,\n type PoServerSessionPlugin,\n packageResourcePath,\n readPackageResource,\n} from '@agimon-ai/po-core/serverPlugin';\n\nimport { SKILL_INVENTORY_FRESH_MS } from '../../../../../constants/skillInventory';\nimport { mountMcpSkills } from '../../../../../services/mcpSkills';\nimport { createSessionLoadSkillTool, createSessionSearchSkillsTool } from '../../../../../services/mcpSkillTools';\nimport { discoverServerSkills } from '../../../../../services/serverInventory';\nimport { groupConditions } from '../../../../../services/serverInventory/grouping';\nimport { mountSkillNamespace } from '../../../../../services/skillNamespace';\nimport { createSkillCommands } from './skillCommands';\n\nexport async function createSkillServer(\n agent: PoHeadlessHostService,\n fs: FileSystem,\n signal: AbortSignal,\n resources: PoServerResources,\n t?: (key: string, fallback: string) => string,\n): Promise<PoServerSessionPlugin> {\n const execution = agent.context;\n // Sessions with the same inputs share one discovery. The key holds every input discoverServerSkills\n // reads besides the disk, so equal keys give equal inventories, and the window bounds how old that\n // read of the disk can be.\n const key = [\n 'inventory',\n execution.repoRoot,\n execution.cwd,\n execution.environment.HOME ?? nodeHost.homeDirectory(),\n ...(readHarnessState(execution.environment).skillDirectories ?? []),\n Math.floor(Date.now() / SKILL_INVENTORY_FRESH_MS),\n ];\n const { inventory, catalog, groups, mcpGroups, relations } = await resources.acquire(key, () =>\n // Every session sharing the discovery waits on it, so none of their signals may abort it.\n discoverServerSkills(execution, fs, new AbortController().signal),\n );\n return {\n commands: createSkillCommands(inventory, catalog, groups, fs, t),\n tools: [createSessionLoadSkillTool(agent), createSessionSearchSkillsTool(agent)],\n services: [mountMcpSkills(mcpGroups, fs, signal), mountSkillNamespace(agent, inventory, fs)],\n resources: [\n // Each skill joins the prompt's one <available_skills> list, gated like the rest.\n ...groups.flatMap((group) =>\n groupConditions(group).flatMap((when) =>\n group.skills.map((skill) => ({\n name: skill.name,\n description: skill.description,\n path: skill.filePath,\n kind: 'skill' as const,\n ...(relations?.[skill.filePath] === undefined ? {} : { relations: relations[skill.filePath] }),\n ...(when === undefined ? {} : { when }),\n read: async () => getOrThrow(await fs.readTextFile(skill.filePath, BACKGROUND_CONTEXT)),\n })),\n ),\n ),\n ...[\n {\n name: 'help-how-to-author-skill',\n description:\n '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.',\n },\n {\n name: 'help-how-to-skill',\n description:\n \"Use Po's skill catalog and deferred discovery. Diagnose missing or shadowed skills and invoke the narrowest available guidance.\",\n },\n ].map((skill) => ({\n ...skill,\n when: PO_HELP_WHEN,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),\n read: () => readPackageResource(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),\n })),\n ],\n };\n}\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\nimport { readPoLang, readPoPersonLocale } from '@agimon-ai/po-core/locale';\nimport { requirePoFs } from '@agimon-ai/po-core/platform';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nimport { createSkillServer } from './_lib/skillServer';\n\nexport default defineRoot(async ({ agent, context: root, signal, resources }: PoServerPluginContext) => {\n const runtime: PoServerSessionPlugin = agent\n ? await createSkillServer(\n agent,\n requirePoFs(root),\n signal,\n resources,\n (key, fallback) => readPoLang(root)?.t(readPoPersonLocale(root)?.read(), key, fallback) ?? fallback,\n )\n : { commands: [], resources: [] };\n return { value: runtime, services: runtime.services };\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.commands!,\n { cardinality: 'many' },\n);\n","// @scaffold-generated\nimport { defineResource } from '@agimon-ai/po-core/extensionFile';\nimport { packageResourcePath, readPackageResource } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineResource({\n name: 'codemode-how-to-skills',\n description:\n 'Search and read skills outside the active set, including skills of unselected domains, through the skills namespace. Use when no listed skill fits the task.',\n // A code-mode guide: listed in the system prompt, outside the searchable catalog.\n pinned: true,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, 'src/prompts/codemode-how-to-skills/SKILL.md'),\n read: () => readPackageResource(import.meta.url, 'src/prompts/codemode-how-to-skills/SKILL.md'),\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.resources!,\n { cardinality: 'many' },\n);\n","import { defineRoutedContribution, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\n/** The session agent's skill tools; the Pi CLI keeps Pi's own skill handling. */\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.tools ?? [],\n { cardinality: 'many' },\n);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverPlugin';\nimport { composeRootHooks, composeRootInjects } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport commandSkills from '../src/extensions/workspaces/sessions/(backend)/command/skills.server';\nimport resourceCodemodeHowToSkills from '../src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server';\nimport resourceSkills from '../src/extensions/workspaces/sessions/(backend)/resource/skills.server';\nimport toolLoadSkill from '../src/extensions/workspaces/sessions/(backend)/tool/load_skill.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\ntype ManyFactory<T, C> = (context: C) => T | readonly T[];\nconst many = <T, C>(value: T | readonly T[] | ManyFactory<T, C>, context: C): readonly T[] => {\n const resolved = typeof value === 'function' ? (value as ManyFactory<T, C>)(context) : value;\n return Array.isArray(resolved) ? resolved : [resolved as T];\n};\n\nexport const serverPlugin = defineServerPlugin({\n name: '@agimon-ai/po-skill',\n providerOverrides: composeServerProviderOverrides(rootSession),\n injects: composeRootInjects({ session: [rootSession] }),\n session: async (context) => {\n const scopeSession = await context.scopeRoot('session', rootSession, context);\n const contextSession = { ...context, root: scopeSession.value };\n return {\n ...composeRootHooks(scopeSession),\n get commands(): PoServerSessionPlugin['commands'] { return [...many(commandSkills, contextSession)]; },\n get resources(): PoServerSessionPlugin['resources'] { return [at(resourceCodemodeHowToSkills, contextSession), ...many(resourceSkills, contextSession)]; },\n get tools(): PoServerSessionPlugin['tools'] { return [...many(toolLoadSkill, contextSession)]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): PoServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default serverPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAa,2BAA2B;;;ACCxC,MAAa,qBAAqB;;AAOlC,SAAgB,eAAe,QAAqC,IAAgB,QAAqB;CACvG,QAAQ,YAA2B;EACjC,QAAQ,QAAQ,oBAAoB,EAClC,KAAK,QAAQ;GACX,OAAO,eAAe;GACtB,OAAO,OAAO,eAAe;GAC7B,MAAM,UAAU,OAAO,UAAU,KAAK,CAAC,CAAC;GACxC,MAAM,yBAAS,IAAI,IAAwB;GAC3C,KAAK,MAAM,SAAS,QAAQ;IAC1B,IAAI,MAAM,YAAY,KAAA,KAAa,CAAC,MAAM,QAAQ,MAAM,WAAW,QAAQ,SAAS,MAAM,CAAC,GAAG;IAC9F,KAAK,MAAM,SAAS,MAAM,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;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"server.cjs","names":["getOrThrow","withAbortSignal","BACKGROUND_CONTEXT","path","fileURLToPath","fs","pathToFileURL","getAgentDir","loadSkills","Worker","stripFrontmatter","path","withAbortSignal","BACKGROUND_CONTEXT","readHarnessState","nodeHost","path","loadDomainsAsync","domainNamesOf","materializePluginEntries","resolveManifestPluginEntriesAsync","collectResources","discoverSkillsAsync","sharedSkillsFor","formatSkillsForPrompt","Type","PO_SKILLS_NAMESPACE","getOrThrow","withAbortSignal","BACKGROUND_CONTEXT","PO_CODEMODE_SERVICE","PO_ISOLATE_SERVICE","readPoCodemode","readPoIsolate","SKILL_COMMAND_PREFIX","SKILL_INVOCATION_PREFIX","SKILLS_COMMAND","nodeHost","readHarnessState","getOrThrow","BACKGROUND_CONTEXT","PO_HELP_WHEN","packageResourcePath","readPackageResource","defineRoot","requirePoFs","readPoLang","readPoPersonLocale","defineRoutedContribution","defineResource","packageResourcePath","readPackageResource","defineRoutedContribution","defineServerPlugin","composeServerProviderOverrides","rootSession","composeRootInjects","composeRootHooks","commandSkills","resourceCodemodeHowToSkills","resourceSkills"],"sources":["../../src/constants/skillInventory.ts","../../src/services/mcpSkills/index.ts","../../src/services/deferredSkills/index.ts","../../src/services/serverInventory/grouping.ts","../../src/services/serverInventory/index.ts","../../src/schemas/mcpSkillTools.ts","../../src/services/mcpSkillTools/index.ts","../../src/services/skillNamespace/index.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/skillCommands.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/skillServer.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/extensions/workspaces/sessions/(backend)/command/skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts","../../generated/server.ts"],"sourcesContent":["/**\n * How long sessions with the same inputs share one skill inventory instead of each reading the disk.\n * ponytail: a skill added on disk reaches new sessions within this window, not at once; watch the\n * skill roots if that lag matters.\n */\nexport const SKILL_INVENTORY_FRESH_MS = 60_000;\n","import type { PoMcpPluginContext, PoMcpSkill } from '@agimon-ai/po-core/mcpFacet';\nimport { BACKGROUND_CONTEXT, getOrThrow, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { ServerSkillGroup } from '../serverInventory';\n\nexport const MCP_SKILLS_SERVICE = 'po/discovered-mcp-skills';\n\nexport interface McpSkillProvider {\n list(context: PoMcpPluginContext): readonly PoMcpSkill[];\n}\n\n/** Explicit remote provider, never a projection of the local resource registry. */\nexport function mountMcpSkills(groups: readonly ServerSkillGroup[], fs: FileSystem, signal: AbortSignal) {\n return (context: Context): void => {\n context.provide(MCP_SKILLS_SERVICE, {\n list(remote) {\n signal.throwIfAborted();\n remote.signal.throwIfAborted();\n const domains = remote.selection.read().domains;\n const skills = new Map<string, PoMcpSkill>();\n for (const group of groups) {\n if (group.domains !== undefined && !group.domains.some((domain) => domains.includes(domain))) continue;\n for (const skill of group.skills) {\n // Retain name precedence defensively for remote providers.\n if (skills.has(skill.name)) continue;\n skills.set(skill.name, {\n name: skill.name,\n description: skill.description,\n async read() {\n const readSignal = AbortSignal.any([signal, remote.signal]);\n readSignal.throwIfAborted();\n const text = getOrThrow(\n await fs.readTextFile(skill.filePath, withAbortSignal(readSignal, BACKGROUND_CONTEXT)),\n );\n readSignal.throwIfAborted();\n return text;\n },\n });\n }\n }\n return [...skills.values()];\n },\n } satisfies McpSkillProvider);\n };\n}\n\nexport function bindMcpSkills(context: PoMcpPluginContext): readonly PoMcpSkill[] {\n const provider = context.services.get<McpSkillProvider>(MCP_SKILLS_SERVICE);\n if (!provider) throw new Error('Discovered MCP skills are unavailable.');\n return provider.list(context);\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { Worker } from 'node:worker_threads';\n\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n type BuildSystemPromptOptions,\n formatSkillsForPrompt,\n getAgentDir,\n loadSkills,\n type Skill,\n stripFrontmatter,\n} from '@earendil-works/pi-coding-agent';\n\nimport type { DeferredSkillLoaderOptions, DeferredSkillSnapshot } from '../../types/skills';\n\nexport type { DeferredSkillLoaderOptions, DeferredSkillSnapshot } from '../../types/skills';\n\nconst PI_PACKAGE = '@earendil-works/pi-coding-agent';\nconst PACKAGE_MANIFEST = 'package.json';\n// A fresh worker takes ~240 ms to import Pi's main entry but ~20 ms for this module alone, and\n// every session spawns one. ponytail: not in Pi's exports map, so a Pi release that moves it\n// falls back to the main entry (slow, still correct); deferredSkills.test.ts pins the path.\nconst PI_SKILLS_MODULE = path.join('dist', 'core', 'skills.js');\nconst SKILL_WORKER_SOURCE = `\nconst { parentPort, workerData } = require('node:worker_threads');\nvoid (async () => {\n try {\n const { loadSkills } = await import(workerData.piModuleUrl);\n parentPort.postMessage({ ok: true, result: loadSkills(workerData.loadOptions) });\n } catch (error) {\n parentPort.postMessage({ ok: false, error: error instanceof Error ? error.message : String(error) });\n }\n})();\n`;\n\nasync function installedPiModuleUrl(): Promise<string> {\n const anchors = [process.argv[1], fileURLToPath(import.meta.url), path.join(process.cwd(), PACKAGE_MANIFEST)];\n for (const anchor of anchors) {\n if (!anchor) continue;\n let directory = path.dirname(path.resolve(anchor));\n while (true) {\n const packageRoot = path.join(directory, 'node_modules', PI_PACKAGE);\n const manifestPath = path.join(packageRoot, PACKAGE_MANIFEST);\n try {\n const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')) as { main?: unknown };\n if (typeof manifest.main === 'string') {\n const entry = path.resolve(packageRoot, manifest.main);\n const skills = path.join(packageRoot, PI_SKILLS_MODULE);\n for (const candidate of [skills, entry]) {\n try {\n await fs.access(candidate);\n return pathToFileURL(candidate).href;\n } catch {\n // Try the next entry before walking up the module chain.\n }\n }\n }\n } catch {\n // This anchor does not expose Pi at this level; continue up its module chain.\n }\n const parent = path.dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n }\n throw new Error(`Cannot resolve ${PI_PACKAGE} from the Po or host module trees`);\n}\n\ninterface SkillWorkerResult {\n ok: boolean;\n result?: { skills: Skill[]; diagnostics: Array<{ path?: string; message: string }> };\n error?: string;\n}\n\n/**\n * One session's Po-selected skill inventory.\n *\n * Construction is deliberately cheap. `start()` schedules the synchronous Pi\n * walker after session_start returns, while `ready()` is the single promise the\n * first input awaits before Pi expands `/skill:name`.\n */\nexport class DeferredSkillLoader {\n readonly #options: DeferredSkillLoaderOptions;\n #promise: Promise<DeferredSkillSnapshot> | undefined;\n\n constructor(options: DeferredSkillLoaderOptions) {\n this.#options = options;\n }\n\n start(): Promise<DeferredSkillSnapshot> {\n if (this.#promise) return this.#promise;\n\n if (!this.#options.schedule && !this.#options.load) {\n this.#promise = this.#loadInWorker();\n return this.#promise;\n }\n\n const schedule = this.#options.schedule ?? ((load: () => void) => setImmediate(load));\n this.#promise = new Promise((resolve) => {\n const fail = (error: unknown): void => {\n resolve(this.#failure(error));\n };\n try {\n schedule(() => {\n try {\n resolve(this.#load());\n } catch (error) {\n fail(error);\n }\n });\n } catch (error) {\n fail(error);\n }\n });\n return this.#promise;\n }\n\n ready(): Promise<DeferredSkillSnapshot> {\n return this.start();\n }\n\n #loadOptions(): { cwd: string; agentDir: string; skillPaths: string[]; includeDefaults: boolean } {\n return {\n cwd: this.#options.cwd,\n agentDir: this.#options.agentDir ?? getAgentDir(),\n skillPaths: [...this.#options.skillPaths],\n includeDefaults: false,\n };\n }\n\n #snapshot(result: {\n skills: Skill[];\n diagnostics: Array<{ path?: string; message: string }>;\n }): DeferredSkillSnapshot {\n return {\n skills: result.skills,\n diagnostics: result.diagnostics.map(\n (diagnostic) => `${diagnostic.path ?? this.#options.cwd}: ${diagnostic.message}`,\n ),\n };\n }\n\n #failure(error: unknown): DeferredSkillSnapshot {\n return {\n skills: [],\n diagnostics: [`${this.#options.cwd}: ${error instanceof Error ? error.message : String(error)}`],\n };\n }\n\n #load(): DeferredSkillSnapshot {\n return this.#snapshot((this.#options.load ?? loadSkills)(this.#loadOptions()));\n }\n\n async #loadInWorker(): Promise<DeferredSkillSnapshot> {\n let piModuleUrl: string;\n try {\n piModuleUrl = this.#options.piModuleUrl ?? (await installedPiModuleUrl());\n } catch (error) {\n return this.#failure(error);\n }\n return new Promise((resolve) => {\n let settled = false;\n const settle = (snapshot: DeferredSkillSnapshot): void => {\n if (settled) return;\n settled = true;\n resolve(snapshot);\n };\n let worker: Worker;\n try {\n worker = new Worker(SKILL_WORKER_SOURCE, {\n eval: true,\n workerData: {\n piModuleUrl,\n loadOptions: this.#loadOptions(),\n },\n });\n } catch (error) {\n settle(this.#failure(error));\n return;\n }\n worker.unref();\n worker.once('message', (message: SkillWorkerResult) => {\n if (!message.ok || !message.result) {\n settle(this.#failure(message.error ?? 'Skill worker failed'));\n return;\n }\n settle(this.#snapshot(message.result));\n });\n worker.once('error', (error) => settle(this.#failure(error)));\n worker.once('exit', (code) => {\n if (code !== 0) settle(this.#failure(`Skill worker exited with code ${code}`));\n });\n });\n }\n}\n\n/** Appends only the inventory Pi would append for these deferred skills. */\nexport function buildPromptWithDeferredSkills(\n systemPrompt: string,\n options: BuildSystemPromptOptions,\n skills: Skill[],\n): string {\n if (options.selectedTools && !options.selectedTools.includes('read')) return systemPrompt;\n return `${systemPrompt}${formatSkillsForPrompt(skills)}`;\n}\n\n/**\n * Expands a deferred `/skill:name` before Pi consults its synchronous inventory. Node discovered the\n * skill on the host disk, so it reads it there; the edge build reads through `fs` instead.\n */\nexport async function expandDeferredSkillCommand(\n text: string,\n skills: readonly Skill[],\n _fs?: FileSystem,\n): Promise<string> {\n if (!text.startsWith('/skill:')) return text;\n const spaceIndex = text.indexOf(' ');\n const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);\n const skill = skills.find((candidate) => candidate.name === skillName);\n if (!skill) return text;\n\n try {\n const args = spaceIndex === -1 ? '' : text.slice(spaceIndex + 1).trim();\n const body = stripFrontmatter(await fs.readFile(skill.filePath, 'utf8')).trim();\n const skillBlock = `<skill name=\"${skill.name}\" location=\"${skill.filePath}\">\\nReferences are relative to ${skill.baseDir}.\\n\\n${body}\\n</skill>`;\n return args ? `${skillBlock}\\n\\n${args}` : skillBlock;\n } catch {\n // Pi uses the same literal-text fallback if a skill disappears between\n // discovery and submission; the agent can still respond to the command.\n return text;\n }\n}\n","import path from 'node:path';\n\nimport type { PluginEntry } from '@agimon-ai/po-config/domains';\nimport type { PoHeadlessCondition } from '@agimon-ai/po-core/headless';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Skill } from '@earendil-works/pi-coding-agent';\n\nimport type { ServerSkillGroup } from '../../types/skills';\n\n/**\n * Each condition that activates a group: its domains, then each plugin turned on for this session only.\n * Declare one contribution per condition; the host keeps one per name once gating has run.\n */\nexport function groupConditions(group: ServerSkillGroup): (PoHeadlessCondition | undefined)[] {\n return [\n group.domains === undefined ? undefined : { domains: group.domains },\n // `plugins` is po-domain's session state key, spelled out so this runs on hosts with an older po-core.\n ...(group.plugins ?? []).map((plugin) => ({ state: { plugins: plugin } })),\n ];\n}\n/**\n * Skill paths one domain admits, or one plugin's session-only activation (`plugin`), or the repository when\n * neither is set.\n */\nexport interface SkillSource {\n readonly domain?: string;\n readonly plugin?: string;\n readonly paths: readonly string[];\n readonly mcpPaths: readonly string[];\n}\n\nconst LOCAL_ONLY_MCP_PACKAGES = new Set([\n '@agimon-ai/po-author',\n '@agimon-ai/po-git',\n '@agimon-ai/po-goal',\n '@agimon-ai/po-help',\n '@agimon-ai/po-calendar',\n '@agimon-ai/po-user-feedback',\n '@agimon-ai/po-voice',\n '@agimon-ai/po-workflow',\n]);\n\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\nexport async function isMcpSkillPlugin(fs: FileSystem, entry: PluginEntry, context: IoContext): Promise<boolean> {\n if (entry.source?.type === 'npm') return !LOCAL_ONLY_MCP_PACKAGES.has(entry.source.package);\n // A package manifest is optional for catalog plugins, but a present identity\n // that cannot be read or parsed must never make the plugin remotely eligible.\n const source = await fs.readTextFile(path.join(entry.directory, 'package.json'), context);\n if (!source.ok) return source.error.code === 'not_found';\n try {\n const manifest = JSON.parse(source.value) as unknown;\n if (typeof manifest !== 'object' || manifest === null || Array.isArray(manifest)) return false;\n const name = (manifest as { name?: unknown }).name;\n return typeof name === 'string' && name.length > 0 && name.trim() === name && !LOCAL_ONLY_MCP_PACKAGES.has(name);\n } catch {\n return false;\n }\n}\n\n/**\n * Whether a discovered skill came from one of these paths.\n *\n * A source holds exact SKILL.md files for plugin and shared skills, but a bare\n * directory for `.po/skills`, so membership is containment rather than\n * equality.\n */\nexport function within(filePath: string, roots: readonly string[]): boolean {\n const resolved = path.resolve(filePath);\n return roots.some((root) => {\n const base = path.resolve(root);\n return resolved === base || resolved.startsWith(`${base}${path.sep}`);\n });\n}\n\n/**\n * One group per loaded skill, merging every source admitting that exact path.\n * MCP admission is merged separately so local-only sources cannot broaden it.\n */\nexport function groupSkills(\n skills: readonly Skill[],\n sources: readonly SkillSource[],\n key: 'paths' | 'mcpPaths',\n): ServerSkillGroup[] {\n return skills.flatMap((skill) => {\n const admitting = sources.filter((source) => within(skill.filePath, source[key]));\n if (admitting.length === 0) return [];\n const domains = [...new Set(admitting.flatMap((source) => (source.domain === undefined ? [] : [source.domain])))];\n const plugins = [...new Set(admitting.flatMap((source) => (source.plugin === undefined ? [] : [source.plugin])))];\n const repository = admitting.some((source) => source.domain === undefined && source.plugin === undefined);\n return [\n {\n ...(repository ? {} : { domains }),\n ...(repository || plugins.length === 0 ? {} : { plugins }),\n skills: [skill],\n },\n ];\n });\n}\n","import path from 'node:path';\n\nimport {\n domainNamesOf,\n loadDomainsAsync,\n resolveManifestPluginEntriesAsync,\n sharedSkillsFor,\n} from '@agimon-ai/po-config/domains';\nimport { readHarnessState } from '@agimon-ai/po-config/harnessState';\nimport type { PoHeadlessExecutionContext } from '@agimon-ai/po-core/headless';\nimport { BACKGROUND_CONTEXT, nodeHost, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport { materializePluginEntries } from '@agimon-ai/po-domain/plugins';\nimport { collectResources, discoverSkillsAsync, type NamedResource } from '@agimon-ai/po-domain/resources';\nimport { formatSkillsForPrompt } from '@earendil-works/pi-coding-agent';\n\nimport type { ServerSkillInventory } from '../../types/skills';\nimport { DeferredSkillLoader } from '../deferredSkills';\nimport { groupSkills, isMcpSkillPlugin, type SkillSource, within } from './grouping';\n\nexport type { ServerSkillGroup, ServerSkillInventory } from '../../types/skills';\n\n/**\n * Every skill the session could reach, grouped by what activates it.\n *\n * A cockpit `/domains` switch reconciles contributions rather than rebuilding\n * the server plugin: the session declaration is mounted once. So enumerating only the\n * launch selection would freeze the command list at whatever was selected when\n * the session host was built. Enumerating every domain up front and tagging\n * each group with its `when` lets the existing kernel refresh do the work, the\n * same way other host contributions follow selection changes.\n */\nexport async function discoverServerSkills(\n execution: PoHeadlessExecutionContext,\n fs: FileSystem,\n signal: AbortSignal,\n): Promise<ServerSkillInventory> {\n signal.throwIfAborted();\n const context = withAbortSignal(signal, BACKGROUND_CONTEXT);\n const state = readHarnessState(execution.environment);\n const home = execution.environment.HOME ?? nodeHost.homeDirectory();\n const repoSkills = path.join(execution.repoRoot, '.po', 'skills');\n const sources: SkillSource[] = [];\n const diagnostics: string[] = [];\n const descriptors = new Map<string, NamedResource>();\n // A malformed domain is a configuration error in one domain, so it must not\n // remove every other domain's skills. Enumerating the whole manifest is new\n // exposure here: reading the launch selection could not fail this way.\n const manifest = await loadDomainsAsync(fs, execution.repoRoot, context, home, execution.environment).catch(\n (error: unknown) => {\n diagnostics.push(`Domain skills are unavailable: ${error instanceof Error ? error.message : String(error)}`);\n return undefined;\n },\n );\n const domains = manifest ? domainNamesOf(manifest) : [];\n\n // Plugin sources precede shared sources, then repository sources.\n // ponytail: Pi globally name-dedupes before domain gating. A loaded plugin\n // shadows a same-name shared fallback even when its domain is off. This is\n // the current ceiling; upgrade to selection-aware loading if collisions arise.\n // Reuse only immutable discovery paths within this invocation. The key keeps\n // plugin ordering and subsets; fs, repo, home and admitted environment are\n // fixed here. No inventory, cleanup handle or session state survives a call.\n const discovered = new Map<\n string,\n Readonly<{ paths: readonly string[]; mcpPaths: readonly string[]; plugins: readonly SkillSource[] }>\n >();\n if (manifest) {\n for (const domain of domains) {\n signal.throwIfAborted();\n try {\n const plugins = await materializePluginEntries(\n await resolveManifestPluginEntriesAsync(fs, manifest, [domain], [], context, home),\n { homeDirectory: home, environment: execution.environment },\n );\n const key = JSON.stringify(\n plugins.map(({ directory, skillDiscovery, skills, source }) => ({\n directory,\n skillDiscovery,\n skills,\n source,\n })),\n );\n const previous = discovered.get(key);\n if (previous) {\n sources.push({ domain, paths: [...previous.paths], mcpPaths: [...previous.mcpPaths] }, ...previous.plugins);\n continue;\n }\n const mcpPluginRoots = (\n await Promise.all(\n plugins.map(async (plugin) =>\n (await isMcpSkillPlugin(fs, plugin, context)) ? path.join(plugin.directory, 'skills') : undefined,\n ),\n )\n ).filter((root): root is string => root !== undefined);\n const collected = await collectResources(execution.repoRoot, plugins, {\n agents: false,\n discoverAgents: false,\n mcp: false,\n sharedSkills: false,\n environment: execution.environment,\n });\n try {\n for (const descriptor of collected.skillSources) descriptors.set(descriptor.path, descriptor);\n const paths = Object.freeze([...collected.skillDirectories]);\n // Exact collected paths retain this domain's per-plugin skill subset.\n // A plugin root would also admit skills loaded for another domain.\n const mcpPaths = Object.freeze(paths.filter((skillPath) => within(skillPath, mcpPluginRoots)));\n // The same skills, admitted one plugin at a time for session-only activation. Never remote: no mcpPaths.\n const pluginSources = plugins.flatMap(({ name, directory }) => {\n const own = paths.filter((skillPath) => within(skillPath, [directory]));\n return name === undefined || own.length === 0 ? [] : [{ plugin: name, paths: own, mcpPaths: [] }];\n });\n discovered.set(key, Object.freeze({ paths, mcpPaths, plugins: pluginSources }));\n if (paths.length > 0) sources.push({ domain, paths: [...paths], mcpPaths: [...mcpPaths] }, ...pluginSources);\n } finally {\n await collected.cleanup();\n }\n } catch (error) {\n diagnostics.push(`Domain '${domain}': ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n }\n\n // Shared skills are admitted by any domain that keeps them.\n signal.throwIfAborted();\n const shared = await discoverSkillsAsync(\n execution.repoRoot,\n path.join(execution.repoRoot, '.claude', 'skills'),\n 'recursive',\n undefined,\n execution.environment,\n );\n for (const descriptor of shared) descriptors.set(descriptor.path, descriptor);\n for (const descriptor of await discoverSkillsAsync(\n execution.repoRoot,\n repoSkills,\n 'recursive',\n undefined,\n execution.environment,\n ))\n descriptors.set(descriptor.path, descriptor);\n if (shared.length > 0 && manifest) {\n const sharedPaths = shared.map((skill) => skill.path);\n for (const domain of domains) {\n if (sharedSkillsFor(manifest, [domain])) {\n sources.push({ domain, paths: sharedPaths, mcpPaths: sharedPaths });\n }\n }\n }\n\n // Repository-local skills belong to the repository, not to a selection.\n sources.push({ paths: [repoSkills], mcpPaths: [repoSkills] });\n\n signal.throwIfAborted();\n // One walk for every group. Pi drops a path it has already loaded, so the\n // loader gets the unique set and each group selects its own skills back out.\n const unique = [...new Set([...sources.flatMap((source) => source.paths), ...(state.skillDirectories ?? [])])];\n const inventory = await new DeferredSkillLoader({ cwd: execution.cwd, skillPaths: unique }).ready();\n signal.throwIfAborted();\n\n for (const descriptor of descriptors.values()) {\n for (const diagnostic of descriptor.diagnostics ?? []) diagnostics.push(`${descriptor.path}: ${diagnostic}`);\n }\n const groups = groupSkills(inventory.skills, sources, 'paths');\n const mcpGroups = groupSkills(inventory.skills, sources, 'mcpPaths');\n\n // The catalog still describes the active selection rather than everything on\n // disk, because it is prompt text rather than a menu.\n const activeSkills = inventory.skills.filter((skill) =>\n within(skill.filePath, [...(state.skillDirectories ?? []), repoSkills]),\n );\n return {\n inventory: { skills: inventory.skills, diagnostics: [...inventory.diagnostics, ...diagnostics] },\n groups,\n mcpGroups,\n relations: Object.fromEntries(\n [...descriptors].map(([filePath, descriptor]) => [filePath, descriptor.relations ?? []]),\n ),\n catalog: formatSkillsForPrompt(activeSkills) || '(no discovered skills)',\n };\n}\n","import { Type } from 'typebox';\n\nexport const searchSkillsParameters = Type.Object({ query: Type.Optional(Type.String()) });\nexport const loadSkillParameters = Type.Object({ name: Type.String() });\n","import type { PoHeadlessHostService, PoHeadlessTool } from '@agimon-ai/po-core/headless';\n\nimport { loadSkillParameters, searchSkillsParameters } from '../../schemas/mcpSkillTools';\n\nfunction text(text: string) {\n return { content: [{ type: 'text' as const, text }] };\n}\n\nfunction skills(context: Parameters<PoHeadlessTool['execute']>[4]) {\n if (context.mcpSkills === undefined) throw new Error('Remote skill access is unavailable.');\n return context.mcpSkills;\n}\n\n/** Case-insensitive substring match on name and description; an empty query keeps everything, in order. */\nexport function matchSkills<T extends { name: string; description: string }>(\n skills: readonly T[],\n query?: string,\n): T[] {\n const needle = query?.trim().toLocaleLowerCase();\n if (needle === undefined || needle === '') return [...skills];\n return skills.filter(({ name, description }) => `${name}\\n${description}`.toLocaleLowerCase().includes(needle));\n}\n\nexport function createSearchSkillsTool(): PoHeadlessTool<typeof searchSkillsParameters> {\n return {\n name: 'search_skills',\n label: 'Search skills',\n description: 'Discover repository and active-domain skills available to this remote connection.',\n parameters: searchSkillsParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n async execute(_toolCallId, { query }, _signal, _onUpdate, context) {\n const matches = matchSkills(await skills(context).list(), query);\n return { ...text(JSON.stringify(matches)), structuredContent: { skills: matches } };\n },\n };\n}\n\nexport function createSessionSearchSkillsTool(\n host: Pick<PoHeadlessHostService, 'listSkills'>,\n): PoHeadlessTool<typeof searchSkillsParameters> {\n return {\n name: 'search_skills',\n label: 'Search skills',\n description: 'Search available session skills by name or description.',\n parameters: searchSkillsParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n executionMode: 'parallel',\n async execute(_toolCallId, { query }) {\n const matches = matchSkills(\n host.listSkills().map(({ name, description }) => ({ name, description })),\n query,\n );\n return { ...text(JSON.stringify(matches)), structuredContent: { skills: matches } };\n },\n };\n}\n\nexport function createSessionLoadSkillTool(\n host: Pick<PoHeadlessHostService, 'readSkill'>,\n): PoHeadlessTool<typeof loadSkillParameters> {\n return {\n // PO_LOAD_SKILL_TOOL, spelled out so the renderer rule can read it.\n name: 'load_skill',\n label: 'Load skill',\n description: 'Load the full instructions of an available session skill by exact name.',\n parameters: loadSkillParameters,\n executionMode: 'parallel',\n async execute(_toolCallId, { name }) {\n const body = host.readSkill(name);\n if (body === undefined) return { ...text(`No skill named ${name} is available in this session.`), isError: true };\n return text(body);\n },\n };\n}\n\nexport function createLoadSkillTool(): PoHeadlessTool<typeof loadSkillParameters> {\n return {\n name: 'load_skill',\n label: 'Load skill',\n description: 'Load the full Markdown instructions for an available remote skill by exact name.',\n parameters: loadSkillParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n async execute(_toolCallId, { name }, _signal, _onUpdate, context) {\n return text(await skills(context).read(name));\n },\n };\n}\n","import { PO_CODEMODE_SERVICE, readPoCodemode, type PoCodemodeNamespace } from '@agimon-ai/po-core/codemode';\nimport { PO_SKILLS_NAMESPACE, type PoHeadlessHostService } from '@agimon-ai/po-core/headless';\nimport {\n BACKGROUND_CONTEXT,\n getOrThrow,\n PO_ISOLATE_SERVICE,\n readPoIsolate,\n withAbortSignal,\n type FileSystem,\n} from '@agimon-ai/po-core/platform';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { DeferredSkillSnapshot } from '../../types/skills';\nimport { createSessionLoadSkillTool, createSessionSearchSkillsTool, matchSkills } from '../mcpSkillTools';\n\nexport const SKILL_NAMESPACE_SOURCE = '@agimon-ai/po-skill';\n\ninterface SkillMatch {\n name: string;\n description: string;\n active: boolean;\n}\n\nfunction queryOf(input: unknown): string | undefined {\n if (input === undefined) return undefined;\n const query = typeof input === 'object' && input !== null ? (input as { query?: unknown }).query : 0;\n if (query === undefined || typeof query === 'string') return query;\n throw new Error('Pass { query?: string }.');\n}\n\nfunction nameOf(input: unknown): string {\n const name = (input as { name?: unknown } | null)?.name;\n if (typeof name !== 'string' || name.trim() === '')\n throw new Error('Pass { name: string }, a name from skills.search.');\n return name;\n}\n\n/**\n * Skills of every domain in domains.yaml, selected or not, plus the session's own. Reading one never selects its\n * domain or plugin, so it grants no tools, hooks or MCP servers. Disabled plugins never reach the inventory.\n */\nexport function createSkillNamespace(\n host: Pick<PoHeadlessHostService, 'listSkills' | 'readSkill' | 'context'>,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem,\n): PoCodemodeNamespace {\n return {\n name: PO_SKILLS_NAMESPACE,\n summary: 'Search and read skills beyond the active set, including unselected domains. Reading enables nothing.',\n declarations: `declare const skills: {\n /** Active skills first, then skills of unselected domains. Omit query to list everything. */\n search(input?: { query?: string }): Promise<{ name: string; description: string; active: boolean }[]>;\n /** Full SKILL.md text by exact name from search. Grants no tools, hooks or MCP servers. */\n load(input: { name: string }): Promise<string>;\n};`,\n bind(run) {\n if (run.sessionId !== host.context.sessionId) throw new Error('Skills namespace belongs to another session.');\n let disposed = false;\n run.onDispose(() => {\n disposed = true;\n });\n const check = () => {\n if (disposed) throw new Error('Skills namespace run is disposed.');\n run.signal.throwIfAborted();\n };\n return {\n async search(input?: unknown): Promise<SkillMatch[]> {\n const query = queryOf(input);\n check();\n const seen = new Set<string>();\n const all: SkillMatch[] = [];\n for (const { name, description } of host.listSkills()) {\n seen.add(name);\n all.push({ name, description, active: true });\n }\n for (const { name, description } of inventory.skills)\n if (!seen.has(name)) all.push({ name, description, active: false });\n return matchSkills(all, query);\n },\n async load(input: unknown): Promise<string> {\n const name = nameOf(input);\n check();\n const active = host.readSkill(name);\n if (active !== undefined) return active;\n // Exact inventory names only, so a script can never steer the read to another path.\n const skill = inventory.skills.find((entry) => entry.name === name);\n if (!skill) throw new Error(`No skill named ${name}. Use skills.search to find one.`);\n const text = getOrThrow(\n await fs.readTextFile(skill.filePath, withAbortSignal(run.signal, BACKGROUND_CONTEXT)),\n );\n check();\n return text;\n },\n };\n },\n };\n}\n\nexport function mountSkillNamespace(\n host: Pick<PoHeadlessHostService, 'listSkills' | 'readSkill' | 'context' | 'registerTool'>,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem,\n) {\n return (context: Context): void => {\n // The direct tools stay only where exec cannot bind this non-portable namespace, which covers both.\n // Registered here rather than restricted, so the remote MCP load_skill and search_skills stay.\n const tools = [\n host.registerTool(createSessionLoadSkillTool(host)),\n host.registerTool(createSessionSearchSkillsTool(host)),\n ];\n const withdraw = () => {\n for (const tool of tools.splice(0)) tool.dispose();\n };\n context.effect(() => withdraw, 'session skill tools');\n context.inject([PO_CODEMODE_SERVICE, PO_ISOLATE_SERVICE], (bound) => {\n const codemode = readPoCodemode(bound);\n if (!codemode) return undefined;\n const registration = codemode.register(SKILL_NAMESPACE_SOURCE, createSkillNamespace(host, inventory, fs));\n // ponytail: the tools do not come back if code mode leaves mid-session; the next session has them.\n if (readPoIsolate(bound)?.liveObjects === true) withdraw();\n return () => registration.dispose();\n });\n };\n}\n","import type { PoHeadlessCommand, PoHeadlessCondition } from '@agimon-ai/po-core/headless';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Skill } from '@earendil-works/pi-coding-agent';\n\nimport { expandDeferredSkillCommand, type DeferredSkillSnapshot } from '../../../../../services/deferredSkills';\nimport type { ServerSkillGroup } from '../../../../../services/serverInventory';\nimport { groupConditions } from '../../../../../services/serverInventory/grouping';\nimport { SKILL_COMMAND_PREFIX, SKILL_INVOCATION_PREFIX, SKILLS_COMMAND } from '../../../../../types/skills';\n\n/**\n * One command per skill, gated by whatever activates that skill.\n *\n * Expansion always reads the full inventory, not the group: a command is only\n * dispatchable while its condition holds, so by the time one runs its skill is\n * active, and looking it up in the union keeps one lookup table instead of one\n * per domain.\n */\nfunction skillCommand(\n skill: Skill,\n when: PoHeadlessCondition | undefined,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem | undefined,\n): PoHeadlessCommand {\n return {\n ...(when === undefined ? {} : { when }),\n name: `${SKILL_COMMAND_PREFIX}${skill.name}`,\n description: skill.description,\n execute: async (args, execution) => {\n const text = `${SKILL_INVOCATION_PREFIX}${skill.name}${args ? ` ${args}` : ''}`;\n const expanded = await expandDeferredSkillCommand(text, inventory.skills, fs);\n if (expanded === text) throw new Error(`Skill '${skill.name}' is no longer readable.`);\n await admit(execution.session, expanded);\n },\n };\n}\n\n/**\n * The dispatching prompt acks when this command returns, so awaiting the whole\n * turn (session.prompt) kept the composer draft until the run ended.\n */\nfunction admit(session: Parameters<PoHeadlessCommand['execute']>[1]['session'], text: string): Promise<void> {\n return session.admitPrompt ? session.admitPrompt(text, 'prompt', 'operator') : session.prompt(text);\n}\nexport function createSkillCommands(\n inventory: DeferredSkillSnapshot,\n catalog: string,\n groups: readonly ServerSkillGroup[],\n fs?: FileSystem,\n t: (key: string, fallback: string) => string = (_key, fallback) => fallback,\n): readonly PoHeadlessCommand[] {\n return [\n {\n name: SKILLS_COMMAND,\n description: 'List discovered skills or invoke one by name.',\n async execute(args, execution) {\n const requested = args.trim();\n if (requested) {\n await admit(\n execution.session,\n await expandDeferredSkillCommand(`${SKILL_INVOCATION_PREFIX}${requested}`, inventory.skills, fs),\n );\n return;\n }\n await execution.client.notify({\n title: t('skill.notification.catalog', 'Po skills'),\n localization: { title: { key: 'skill.notification.catalog', fallback: 'Po skills' } },\n body: catalog,\n level: 'info',\n });\n },\n },\n ...groups.flatMap((group) =>\n groupConditions(group).flatMap((when) => group.skills.map((skill) => skillCommand(skill, when, inventory, fs))),\n ),\n ];\n}\n","import { readHarnessState } from '@agimon-ai/po-config/harnessState';\nimport type { PoHeadlessHostService } from '@agimon-ai/po-core/headless';\nimport { PO_HELP_WHEN } from '@agimon-ai/po-core/help';\nimport { BACKGROUND_CONTEXT, getOrThrow, nodeHost, type FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n type PoServerResources,\n type PoServerSessionPlugin,\n packageResourcePath,\n readPackageResource,\n} from '@agimon-ai/po-core/serverPlugin';\n\nimport { SKILL_INVENTORY_FRESH_MS } from '../../../../../constants/skillInventory';\nimport { mountMcpSkills } from '../../../../../services/mcpSkills';\nimport { discoverServerSkills } from '../../../../../services/serverInventory';\nimport { groupConditions } from '../../../../../services/serverInventory/grouping';\nimport { mountSkillNamespace } from '../../../../../services/skillNamespace';\nimport { createSkillCommands } from './skillCommands';\n\nexport async function createSkillServer(\n agent: PoHeadlessHostService,\n fs: FileSystem,\n signal: AbortSignal,\n resources: PoServerResources,\n t?: (key: string, fallback: string) => string,\n): Promise<PoServerSessionPlugin> {\n const execution = agent.context;\n // Sessions with the same inputs share one discovery. The key holds every input discoverServerSkills\n // reads besides the disk, so equal keys give equal inventories, and the window bounds how old that\n // read of the disk can be.\n const key = [\n 'inventory',\n execution.repoRoot,\n execution.cwd,\n execution.environment.HOME ?? nodeHost.homeDirectory(),\n ...(readHarnessState(execution.environment).skillDirectories ?? []),\n Math.floor(Date.now() / SKILL_INVENTORY_FRESH_MS),\n ];\n const { inventory, catalog, groups, mcpGroups, relations } = await resources.acquire(key, () =>\n // Every session sharing the discovery waits on it, so none of their signals may abort it.\n discoverServerSkills(execution, fs, new AbortController().signal),\n );\n return {\n commands: createSkillCommands(inventory, catalog, groups, fs, t),\n services: [mountMcpSkills(mcpGroups, fs, signal), mountSkillNamespace(agent, inventory, fs)],\n resources: [\n // Each skill joins the prompt's one <available_skills> list, gated like the rest.\n ...groups.flatMap((group) =>\n groupConditions(group).flatMap((when) =>\n group.skills.map((skill) => ({\n name: skill.name,\n description: skill.description,\n path: skill.filePath,\n kind: 'skill' as const,\n ...(relations?.[skill.filePath] === undefined ? {} : { relations: relations[skill.filePath] }),\n ...(when === undefined ? {} : { when }),\n read: async () => getOrThrow(await fs.readTextFile(skill.filePath, BACKGROUND_CONTEXT)),\n })),\n ),\n ),\n ...[\n {\n name: 'help-how-to-author-skill',\n description:\n '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.',\n },\n {\n name: 'help-how-to-skill',\n description:\n \"Use Po's skill catalog and deferred discovery. Diagnose missing or shadowed skills and invoke the narrowest available guidance.\",\n },\n ].map((skill) => ({\n ...skill,\n when: PO_HELP_WHEN,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),\n read: () => readPackageResource(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),\n })),\n ],\n };\n}\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\nimport { readPoLang, readPoPersonLocale } from '@agimon-ai/po-core/locale';\nimport { requirePoFs } from '@agimon-ai/po-core/platform';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nimport { createSkillServer } from './_lib/skillServer';\n\nexport default defineRoot(async ({ agent, context: root, signal, resources }: PoServerPluginContext) => {\n const runtime: PoServerSessionPlugin = agent\n ? await createSkillServer(\n agent,\n requirePoFs(root),\n signal,\n resources,\n (key, fallback) => readPoLang(root)?.t(readPoPersonLocale(root)?.read(), key, fallback) ?? fallback,\n )\n : { commands: [], resources: [] };\n return { value: runtime, services: runtime.services };\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.commands!,\n { cardinality: 'many' },\n);\n","// @scaffold-generated\nimport { defineResource } from '@agimon-ai/po-core/extensionFile';\nimport { packageResourcePath, readPackageResource } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineResource({\n name: 'codemode-how-to-skills',\n description:\n '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.',\n // A code-mode guide: listed in the system prompt, outside the searchable catalog.\n pinned: true,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, 'src/prompts/codemode-how-to-skills/SKILL.md'),\n read: () => readPackageResource(import.meta.url, 'src/prompts/codemode-how-to-skills/SKILL.md'),\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.resources!,\n { cardinality: 'many' },\n);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverPlugin';\nimport { composeRootHooks, composeRootInjects } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport commandSkills from '../src/extensions/workspaces/sessions/(backend)/command/skills.server';\nimport resourceCodemodeHowToSkills from '../src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server';\nimport resourceSkills from '../src/extensions/workspaces/sessions/(backend)/resource/skills.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\ntype ManyFactory<T, C> = (context: C) => T | readonly T[];\nconst many = <T, C>(value: T | readonly T[] | ManyFactory<T, C>, context: C): readonly T[] => {\n const resolved = typeof value === 'function' ? (value as ManyFactory<T, C>)(context) : value;\n return Array.isArray(resolved) ? resolved : [resolved as T];\n};\n\nexport const serverPlugin = defineServerPlugin({\n name: '@agimon-ai/po-skill',\n providerOverrides: composeServerProviderOverrides(rootSession),\n injects: composeRootInjects({ session: [rootSession] }),\n session: async (context) => {\n const scopeSession = await context.scopeRoot('session', rootSession, context);\n const contextSession = { ...context, root: scopeSession.value };\n return {\n ...composeRootHooks(scopeSession),\n get commands(): PoServerSessionPlugin['commands'] { return [...many(commandSkills, contextSession)]; },\n get resources(): PoServerSessionPlugin['resources'] { return [at(resourceCodemodeHowToSkills, contextSession), ...many(resourceSkills, contextSession)]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): PoServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default serverPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAa,2BAA2B;;;ACCxC,MAAa,qBAAqB;;AAOlC,SAAgB,eAAe,QAAqC,IAAgB,QAAqB;CACvG,QAAQ,YAA2B;EACjC,QAAQ,QAAQ,oBAAoB,EAClC,KAAK,QAAQ;GACX,OAAO,eAAe;GACtB,OAAO,OAAO,eAAe;GAC7B,MAAM,UAAU,OAAO,UAAU,KAAK,CAAC,CAAC;GACxC,MAAM,yBAAS,IAAI,IAAwB;GAC3C,KAAK,MAAM,SAAS,QAAQ;IAC1B,IAAI,MAAM,YAAY,KAAA,KAAa,CAAC,MAAM,QAAQ,MAAM,WAAW,QAAQ,SAAS,MAAM,CAAC,GAAG;IAC9F,KAAK,MAAM,SAAS,MAAM,QAAQ;KAEhC,IAAI,OAAO,IAAI,MAAM,IAAI,GAAG;KAC5B,OAAO,IAAI,MAAM,MAAM;MACrB,MAAM,MAAM;MACZ,aAAa,MAAM;MACnB,MAAM,OAAO;OACX,MAAM,aAAa,YAAY,IAAI,CAAC,QAAQ,OAAO,MAAM,CAAC;OAC1D,WAAW,eAAe;OAC1B,MAAM,QAAA,GAAOA,4BAAAA,WAAAA,CACX,MAAM,GAAG,aAAa,MAAM,WAAA,GAAUC,4BAAAA,gBAAAA,CAAgB,YAAYC,4BAAAA,kBAAkB,CAAC,CACvF;OACA,WAAW,eAAe;OAC1B,OAAO;MACT;KACF,CAAC;IACH;GACF;GACA,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC;EAC5B,EACF,CAA4B;CAC9B;AACF;;;AC1BA,MA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AAU,aAAc,MAA4B,OAAO,IAAI;CACvF,OAAO,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAa;AAC5D;AAEA,MAAa,gBAAA,GAAeC,gCAAAA,mBAAAA,CAAmB;CAC7C,MAAM;CACN,oBAAA,GAAmBC,gCAAAA,+BAAAA,CAA+BC,mBAAW;CAC7D,UAAA,GAASC,iCAAAA,mBAAAA,CAAmB,EAAE,SAAS,CAACD,mBAAW,EAAE,CAAC;CACtD,SAAS,OAAO,YAAY;EAC1B,MAAM,eAAe,MAAM,QAAQ,UAAU,WAAWA,qBAAa,OAAO;EAC5E,MAAM,iBAAiB;GAAE,GAAG;GAAS,MAAM,aAAa;EAAM;EAC9D,OAAO;GACL,IAAA,GAAGE,iCAAAA,iBAAAA,CAAiB,YAAY;GAChC,IAAI,WAA8C;IAAE,OAAO,CAAC,GAAG,KAAKC,yBAAe,cAAc,CAAC;GAAG;GACrG,IAAI,YAAgD;IAAE,OAAO,CAAC,GAAGC,uCAA6B,cAAc,GAAG,GAAG,KAAKC,uBAAgB,cAAc,CAAC;GAAG;GACzJ,UAAU,CAAC,GAAI,aAAa,YAAY,CAAC,CAAE;GAC3C,IAAI,aAAkD;IAAE,OAAO,CAAC,GAAI,aAAa,cAAc,CAAC,CAAE;GAAG;EACvG;CACF;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.mts","names":[],"sources":["../../generated/server.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../../generated/server.ts"],"mappings":";qBAmBa,wDAAY"}
|
|
@@ -1,7 +1,7 @@
|
|
|
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
3
|
import { domainNamesOf, loadDomainsAsync, resolveManifestPluginEntriesAsync, sharedSkillsFor } from "@agimon-ai/po-config/domains";
|
|
4
|
-
import { BACKGROUND_CONTEXT, getOrThrow, nodeHost, requirePoFs, withAbortSignal } from "@agimon-ai/po-core/platform";
|
|
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";
|
|
@@ -9,12 +9,13 @@ import { composeRootHooks, composeRootInjects, defineResource, defineRoot, defin
|
|
|
9
9
|
import { readPoLang, readPoPersonLocale } from "@agimon-ai/po-core/locale";
|
|
10
10
|
import { readHarnessState } from "@agimon-ai/po-config/harnessState";
|
|
11
11
|
import { PO_HELP_WHEN } from "@agimon-ai/po-core/help";
|
|
12
|
-
import { Type } from "typebox";
|
|
13
12
|
import { collectResources, discoverSkillsAsync } from "@agimon-ai/po-domain/resources";
|
|
14
13
|
import fs from "node:fs/promises";
|
|
15
14
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
16
15
|
import { Worker } from "node:worker_threads";
|
|
17
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";
|
|
18
19
|
//#region src/constants/skillInventory.ts
|
|
19
20
|
/**
|
|
20
21
|
* How long sessions with the same inputs share one skill inventory instead of each reading the disk.
|
|
@@ -55,65 +56,6 @@ function mountMcpSkills(groups, fs, signal) {
|
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
//#endregion
|
|
58
|
-
//#region src/schemas/mcpSkillTools.ts
|
|
59
|
-
const searchSkillsParameters = Type.Object({ query: Type.Optional(Type.String()) });
|
|
60
|
-
const loadSkillParameters = Type.Object({ name: Type.String() });
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/services/mcpSkillTools/index.ts
|
|
63
|
-
function text(text) {
|
|
64
|
-
return { content: [{
|
|
65
|
-
type: "text",
|
|
66
|
-
text
|
|
67
|
-
}] };
|
|
68
|
-
}
|
|
69
|
-
/** Case-insensitive substring match on name and description; an empty query keeps everything, in order. */
|
|
70
|
-
function matchSkills(skills, query) {
|
|
71
|
-
const needle = query?.trim().toLocaleLowerCase();
|
|
72
|
-
if (needle === void 0 || needle === "") return [...skills];
|
|
73
|
-
return skills.filter(({ name, description }) => `${name}\n${description}`.toLocaleLowerCase().includes(needle));
|
|
74
|
-
}
|
|
75
|
-
function createSessionSearchSkillsTool(host) {
|
|
76
|
-
return {
|
|
77
|
-
name: "search_skills",
|
|
78
|
-
label: "Search skills",
|
|
79
|
-
description: "Search available session skills by name or description.",
|
|
80
|
-
parameters: searchSkillsParameters,
|
|
81
|
-
annotations: {
|
|
82
|
-
readOnlyHint: true,
|
|
83
|
-
destructiveHint: false,
|
|
84
|
-
openWorldHint: false
|
|
85
|
-
},
|
|
86
|
-
executionMode: "parallel",
|
|
87
|
-
async execute(_toolCallId, { query }) {
|
|
88
|
-
const matches = matchSkills(host.listSkills().map(({ name, description }) => ({
|
|
89
|
-
name,
|
|
90
|
-
description
|
|
91
|
-
})), query);
|
|
92
|
-
return {
|
|
93
|
-
...text(JSON.stringify(matches)),
|
|
94
|
-
structuredContent: { skills: matches }
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function createSessionLoadSkillTool(host) {
|
|
100
|
-
return {
|
|
101
|
-
name: "load_skill",
|
|
102
|
-
label: "Load skill",
|
|
103
|
-
description: "Load the full instructions of an available session skill by exact name.",
|
|
104
|
-
parameters: loadSkillParameters,
|
|
105
|
-
executionMode: "parallel",
|
|
106
|
-
async execute(_toolCallId, { name }) {
|
|
107
|
-
const body = host.readSkill(name);
|
|
108
|
-
if (body === void 0) return {
|
|
109
|
-
...text(`No skill named ${name} is available in this session.`),
|
|
110
|
-
isError: true
|
|
111
|
-
};
|
|
112
|
-
return text(body);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
//#endregion
|
|
117
59
|
//#region src/services/deferredSkills/index.ts
|
|
118
60
|
const PI_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
119
61
|
const PACKAGE_MANIFEST = "package.json";
|
|
@@ -472,6 +414,65 @@ async function discoverServerSkills(execution, fs, signal) {
|
|
|
472
414
|
};
|
|
473
415
|
}
|
|
474
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
|
|
475
476
|
//#region src/services/skillNamespace/index.ts
|
|
476
477
|
const SKILL_NAMESPACE_SOURCE = "@agimon-ai/po-skill";
|
|
477
478
|
function queryOf(input) {
|
|
@@ -491,7 +492,7 @@ function nameOf(input) {
|
|
|
491
492
|
*/
|
|
492
493
|
function createSkillNamespace(host, inventory, fs) {
|
|
493
494
|
return {
|
|
494
|
-
name:
|
|
495
|
+
name: PO_SKILLS_NAMESPACE,
|
|
495
496
|
summary: "Search and read skills beyond the active set, including unselected domains. Reading enables nothing.",
|
|
496
497
|
declarations: `declare const skills: {
|
|
497
498
|
/** Active skills first, then skills of unselected domains. Omit query to list everything. */
|
|
@@ -547,10 +548,16 @@ function createSkillNamespace(host, inventory, fs) {
|
|
|
547
548
|
}
|
|
548
549
|
function mountSkillNamespace(host, inventory, fs) {
|
|
549
550
|
return (context) => {
|
|
550
|
-
|
|
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) => {
|
|
551
557
|
const codemode = readPoCodemode(bound);
|
|
552
558
|
if (!codemode) return void 0;
|
|
553
559
|
const registration = codemode.register(SKILL_NAMESPACE_SOURCE, createSkillNamespace(host, inventory, fs));
|
|
560
|
+
if (readPoIsolate(bound)?.liveObjects === true) withdraw();
|
|
554
561
|
return () => registration.dispose();
|
|
555
562
|
});
|
|
556
563
|
};
|
|
@@ -622,7 +629,6 @@ async function createSkillServer(agent, fs, signal, resources, t) {
|
|
|
622
629
|
const { inventory, catalog, groups, mcpGroups, relations } = await resources.acquire(key, () => discoverServerSkills(execution, fs, new AbortController().signal));
|
|
623
630
|
return {
|
|
624
631
|
commands: createSkillCommands(inventory, catalog, groups, fs, t),
|
|
625
|
-
tools: [createSessionLoadSkillTool(agent), createSessionSearchSkillsTool(agent)],
|
|
626
632
|
services: [mountMcpSkills(mcpGroups, fs, signal), mountSkillNamespace(agent, inventory, fs)],
|
|
627
633
|
resources: [...groups.flatMap((group) => groupConditions(group).flatMap((when) => group.skills.map((skill) => ({
|
|
628
634
|
name: skill.name,
|
|
@@ -666,7 +672,7 @@ var skills_server_default$1 = defineRoutedContribution((context) => context.root
|
|
|
666
672
|
//#region src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts
|
|
667
673
|
var codemode_how_to_skills_server_default = defineResource({
|
|
668
674
|
name: "codemode-how-to-skills",
|
|
669
|
-
description: "Search and
|
|
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.",
|
|
670
676
|
pinned: true,
|
|
671
677
|
kind: "skill",
|
|
672
678
|
path: packageResourcePath(import.meta.url, "src/prompts/codemode-how-to-skills/SKILL.md"),
|
|
@@ -676,10 +682,6 @@ var codemode_how_to_skills_server_default = defineResource({
|
|
|
676
682
|
//#region src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts
|
|
677
683
|
var skills_server_default = defineRoutedContribution((context) => context.root.resources, { cardinality: "many" });
|
|
678
684
|
//#endregion
|
|
679
|
-
//#region src/extensions/workspaces/sessions/(backend)/tool/load_skill.server.ts
|
|
680
|
-
/** The session agent's skill tools; the Pi CLI keeps Pi's own skill handling. */
|
|
681
|
-
var load_skill_server_default = defineRoutedContribution((context) => context.root.tools ?? [], { cardinality: "many" });
|
|
682
|
-
//#endregion
|
|
683
685
|
//#region generated/server.ts
|
|
684
686
|
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
685
687
|
const many = (value, context) => {
|
|
@@ -704,9 +706,6 @@ const serverPlugin = defineServerPlugin({
|
|
|
704
706
|
get resources() {
|
|
705
707
|
return [at(codemode_how_to_skills_server_default, contextSession), ...many(skills_server_default, contextSession)];
|
|
706
708
|
},
|
|
707
|
-
get tools() {
|
|
708
|
-
return [...many(load_skill_server_default, contextSession)];
|
|
709
|
-
},
|
|
710
709
|
services: [...scopeSession.services ?? []],
|
|
711
710
|
get activities() {
|
|
712
711
|
return [...scopeSession.activities ?? []];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","names":["rootSession","commandSkills","resourceCodemodeHowToSkills","resourceSkills","toolLoadSkill"],"sources":["../../src/constants/skillInventory.ts","../../src/services/mcpSkills/index.ts","../../src/schemas/mcpSkillTools.ts","../../src/services/mcpSkillTools/index.ts","../../src/services/deferredSkills/index.ts","../../src/services/serverInventory/grouping.ts","../../src/services/serverInventory/index.ts","../../src/services/skillNamespace/index.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/skillCommands.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/skillServer.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/extensions/workspaces/sessions/(backend)/command/skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/tool/load_skill.server.ts","../../generated/server.ts"],"sourcesContent":["/**\n * How long sessions with the same inputs share one skill inventory instead of each reading the disk.\n * ponytail: a skill added on disk reaches new sessions within this window, not at once; watch the\n * skill roots if that lag matters.\n */\nexport const SKILL_INVENTORY_FRESH_MS = 60_000;\n","import type { PoMcpPluginContext, PoMcpSkill } from '@agimon-ai/po-core/mcpFacet';\nimport { BACKGROUND_CONTEXT, getOrThrow, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { ServerSkillGroup } from '../serverInventory';\n\nexport const MCP_SKILLS_SERVICE = 'po/discovered-mcp-skills';\n\nexport interface McpSkillProvider {\n list(context: PoMcpPluginContext): readonly PoMcpSkill[];\n}\n\n/** Explicit remote provider, never a projection of the local resource registry. */\nexport function mountMcpSkills(groups: readonly ServerSkillGroup[], fs: FileSystem, signal: AbortSignal) {\n return (context: Context): void => {\n context.provide(MCP_SKILLS_SERVICE, {\n list(remote) {\n signal.throwIfAborted();\n remote.signal.throwIfAborted();\n const domains = remote.selection.read().domains;\n const skills = new Map<string, PoMcpSkill>();\n for (const group of groups) {\n if (group.domains !== undefined && !group.domains.some((domain) => domains.includes(domain))) continue;\n for (const skill of group.skills) {\n // Retain name precedence defensively for remote providers.\n if (skills.has(skill.name)) continue;\n skills.set(skill.name, {\n name: skill.name,\n description: skill.description,\n async read() {\n const readSignal = AbortSignal.any([signal, remote.signal]);\n readSignal.throwIfAborted();\n const text = getOrThrow(\n await fs.readTextFile(skill.filePath, withAbortSignal(readSignal, BACKGROUND_CONTEXT)),\n );\n readSignal.throwIfAborted();\n return text;\n },\n });\n }\n }\n return [...skills.values()];\n },\n } satisfies McpSkillProvider);\n };\n}\n\nexport function bindMcpSkills(context: PoMcpPluginContext): readonly PoMcpSkill[] {\n const provider = context.services.get<McpSkillProvider>(MCP_SKILLS_SERVICE);\n if (!provider) throw new Error('Discovered MCP skills are unavailable.');\n return provider.list(context);\n}\n","import { Type } from 'typebox';\n\nexport const searchSkillsParameters = Type.Object({ query: Type.Optional(Type.String()) });\nexport const loadSkillParameters = Type.Object({ name: Type.String() });\n","import type { PoHeadlessHostService, PoHeadlessTool } from '@agimon-ai/po-core/headless';\n\nimport { loadSkillParameters, searchSkillsParameters } from '../../schemas/mcpSkillTools';\n\nfunction text(text: string) {\n return { content: [{ type: 'text' as const, text }] };\n}\n\nfunction skills(context: Parameters<PoHeadlessTool['execute']>[4]) {\n if (context.mcpSkills === undefined) throw new Error('Remote skill access is unavailable.');\n return context.mcpSkills;\n}\n\n/** Case-insensitive substring match on name and description; an empty query keeps everything, in order. */\nexport function matchSkills<T extends { name: string; description: string }>(\n skills: readonly T[],\n query?: string,\n): T[] {\n const needle = query?.trim().toLocaleLowerCase();\n if (needle === undefined || needle === '') return [...skills];\n return skills.filter(({ name, description }) => `${name}\\n${description}`.toLocaleLowerCase().includes(needle));\n}\n\nexport function createSearchSkillsTool(): PoHeadlessTool<typeof searchSkillsParameters> {\n return {\n name: 'search_skills',\n label: 'Search skills',\n description: 'Discover repository and active-domain skills available to this remote connection.',\n parameters: searchSkillsParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n async execute(_toolCallId, { query }, _signal, _onUpdate, context) {\n const matches = matchSkills(await skills(context).list(), query);\n return { ...text(JSON.stringify(matches)), structuredContent: { skills: matches } };\n },\n };\n}\n\nexport function createSessionSearchSkillsTool(\n host: Pick<PoHeadlessHostService, 'listSkills'>,\n): PoHeadlessTool<typeof searchSkillsParameters> {\n return {\n name: 'search_skills',\n label: 'Search skills',\n description: 'Search available session skills by name or description.',\n parameters: searchSkillsParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n executionMode: 'parallel',\n async execute(_toolCallId, { query }) {\n const matches = matchSkills(\n host.listSkills().map(({ name, description }) => ({ name, description })),\n query,\n );\n return { ...text(JSON.stringify(matches)), structuredContent: { skills: matches } };\n },\n };\n}\n\nexport function createSessionLoadSkillTool(\n host: Pick<PoHeadlessHostService, 'readSkill'>,\n): PoHeadlessTool<typeof loadSkillParameters> {\n return {\n // PO_LOAD_SKILL_TOOL, spelled out so the renderer rule can read it.\n name: 'load_skill',\n label: 'Load skill',\n description: 'Load the full instructions of an available session skill by exact name.',\n parameters: loadSkillParameters,\n executionMode: 'parallel',\n async execute(_toolCallId, { name }) {\n const body = host.readSkill(name);\n if (body === undefined) return { ...text(`No skill named ${name} is available in this session.`), isError: true };\n return text(body);\n },\n };\n}\n\nexport function createLoadSkillTool(): PoHeadlessTool<typeof loadSkillParameters> {\n return {\n name: 'load_skill',\n label: 'Load skill',\n description: 'Load the full Markdown instructions for an available remote skill by exact name.',\n parameters: loadSkillParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n async execute(_toolCallId, { name }, _signal, _onUpdate, context) {\n return text(await skills(context).read(name));\n },\n };\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { Worker } from 'node:worker_threads';\n\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n type BuildSystemPromptOptions,\n formatSkillsForPrompt,\n getAgentDir,\n loadSkills,\n type Skill,\n stripFrontmatter,\n} from '@earendil-works/pi-coding-agent';\n\nimport type { DeferredSkillLoaderOptions, DeferredSkillSnapshot } from '../../types/skills';\n\nexport type { DeferredSkillLoaderOptions, DeferredSkillSnapshot } from '../../types/skills';\n\nconst PI_PACKAGE = '@earendil-works/pi-coding-agent';\nconst PACKAGE_MANIFEST = 'package.json';\n// A fresh worker takes ~240 ms to import Pi's main entry but ~20 ms for this module alone, and\n// every session spawns one. ponytail: not in Pi's exports map, so a Pi release that moves it\n// falls back to the main entry (slow, still correct); deferredSkills.test.ts pins the path.\nconst PI_SKILLS_MODULE = path.join('dist', 'core', 'skills.js');\nconst SKILL_WORKER_SOURCE = `\nconst { parentPort, workerData } = require('node:worker_threads');\nvoid (async () => {\n try {\n const { loadSkills } = await import(workerData.piModuleUrl);\n parentPort.postMessage({ ok: true, result: loadSkills(workerData.loadOptions) });\n } catch (error) {\n parentPort.postMessage({ ok: false, error: error instanceof Error ? error.message : String(error) });\n }\n})();\n`;\n\nasync function installedPiModuleUrl(): Promise<string> {\n const anchors = [process.argv[1], fileURLToPath(import.meta.url), path.join(process.cwd(), PACKAGE_MANIFEST)];\n for (const anchor of anchors) {\n if (!anchor) continue;\n let directory = path.dirname(path.resolve(anchor));\n while (true) {\n const packageRoot = path.join(directory, 'node_modules', PI_PACKAGE);\n const manifestPath = path.join(packageRoot, PACKAGE_MANIFEST);\n try {\n const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')) as { main?: unknown };\n if (typeof manifest.main === 'string') {\n const entry = path.resolve(packageRoot, manifest.main);\n const skills = path.join(packageRoot, PI_SKILLS_MODULE);\n for (const candidate of [skills, entry]) {\n try {\n await fs.access(candidate);\n return pathToFileURL(candidate).href;\n } catch {\n // Try the next entry before walking up the module chain.\n }\n }\n }\n } catch {\n // This anchor does not expose Pi at this level; continue up its module chain.\n }\n const parent = path.dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n }\n throw new Error(`Cannot resolve ${PI_PACKAGE} from the Po or host module trees`);\n}\n\ninterface SkillWorkerResult {\n ok: boolean;\n result?: { skills: Skill[]; diagnostics: Array<{ path?: string; message: string }> };\n error?: string;\n}\n\n/**\n * One session's Po-selected skill inventory.\n *\n * Construction is deliberately cheap. `start()` schedules the synchronous Pi\n * walker after session_start returns, while `ready()` is the single promise the\n * first input awaits before Pi expands `/skill:name`.\n */\nexport class DeferredSkillLoader {\n readonly #options: DeferredSkillLoaderOptions;\n #promise: Promise<DeferredSkillSnapshot> | undefined;\n\n constructor(options: DeferredSkillLoaderOptions) {\n this.#options = options;\n }\n\n start(): Promise<DeferredSkillSnapshot> {\n if (this.#promise) return this.#promise;\n\n if (!this.#options.schedule && !this.#options.load) {\n this.#promise = this.#loadInWorker();\n return this.#promise;\n }\n\n const schedule = this.#options.schedule ?? ((load: () => void) => setImmediate(load));\n this.#promise = new Promise((resolve) => {\n const fail = (error: unknown): void => {\n resolve(this.#failure(error));\n };\n try {\n schedule(() => {\n try {\n resolve(this.#load());\n } catch (error) {\n fail(error);\n }\n });\n } catch (error) {\n fail(error);\n }\n });\n return this.#promise;\n }\n\n ready(): Promise<DeferredSkillSnapshot> {\n return this.start();\n }\n\n #loadOptions(): { cwd: string; agentDir: string; skillPaths: string[]; includeDefaults: boolean } {\n return {\n cwd: this.#options.cwd,\n agentDir: this.#options.agentDir ?? getAgentDir(),\n skillPaths: [...this.#options.skillPaths],\n includeDefaults: false,\n };\n }\n\n #snapshot(result: {\n skills: Skill[];\n diagnostics: Array<{ path?: string; message: string }>;\n }): DeferredSkillSnapshot {\n return {\n skills: result.skills,\n diagnostics: result.diagnostics.map(\n (diagnostic) => `${diagnostic.path ?? this.#options.cwd}: ${diagnostic.message}`,\n ),\n };\n }\n\n #failure(error: unknown): DeferredSkillSnapshot {\n return {\n skills: [],\n diagnostics: [`${this.#options.cwd}: ${error instanceof Error ? error.message : String(error)}`],\n };\n }\n\n #load(): DeferredSkillSnapshot {\n return this.#snapshot((this.#options.load ?? loadSkills)(this.#loadOptions()));\n }\n\n async #loadInWorker(): Promise<DeferredSkillSnapshot> {\n let piModuleUrl: string;\n try {\n piModuleUrl = this.#options.piModuleUrl ?? (await installedPiModuleUrl());\n } catch (error) {\n return this.#failure(error);\n }\n return new Promise((resolve) => {\n let settled = false;\n const settle = (snapshot: DeferredSkillSnapshot): void => {\n if (settled) return;\n settled = true;\n resolve(snapshot);\n };\n let worker: Worker;\n try {\n worker = new Worker(SKILL_WORKER_SOURCE, {\n eval: true,\n workerData: {\n piModuleUrl,\n loadOptions: this.#loadOptions(),\n },\n });\n } catch (error) {\n settle(this.#failure(error));\n return;\n }\n worker.unref();\n worker.once('message', (message: SkillWorkerResult) => {\n if (!message.ok || !message.result) {\n settle(this.#failure(message.error ?? 'Skill worker failed'));\n return;\n }\n settle(this.#snapshot(message.result));\n });\n worker.once('error', (error) => settle(this.#failure(error)));\n worker.once('exit', (code) => {\n if (code !== 0) settle(this.#failure(`Skill worker exited with code ${code}`));\n });\n });\n }\n}\n\n/** Appends only the inventory Pi would append for these deferred skills. */\nexport function buildPromptWithDeferredSkills(\n systemPrompt: string,\n options: BuildSystemPromptOptions,\n skills: Skill[],\n): string {\n if (options.selectedTools && !options.selectedTools.includes('read')) return systemPrompt;\n return `${systemPrompt}${formatSkillsForPrompt(skills)}`;\n}\n\n/**\n * Expands a deferred `/skill:name` before Pi consults its synchronous inventory. Node discovered the\n * skill on the host disk, so it reads it there; the edge build reads through `fs` instead.\n */\nexport async function expandDeferredSkillCommand(\n text: string,\n skills: readonly Skill[],\n _fs?: FileSystem,\n): Promise<string> {\n if (!text.startsWith('/skill:')) return text;\n const spaceIndex = text.indexOf(' ');\n const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);\n const skill = skills.find((candidate) => candidate.name === skillName);\n if (!skill) return text;\n\n try {\n const args = spaceIndex === -1 ? '' : text.slice(spaceIndex + 1).trim();\n const body = stripFrontmatter(await fs.readFile(skill.filePath, 'utf8')).trim();\n const skillBlock = `<skill name=\"${skill.name}\" location=\"${skill.filePath}\">\\nReferences are relative to ${skill.baseDir}.\\n\\n${body}\\n</skill>`;\n return args ? `${skillBlock}\\n\\n${args}` : skillBlock;\n } catch {\n // Pi uses the same literal-text fallback if a skill disappears between\n // discovery and submission; the agent can still respond to the command.\n return text;\n }\n}\n","import path from 'node:path';\n\nimport type { PluginEntry } from '@agimon-ai/po-config/domains';\nimport type { PoHeadlessCondition } from '@agimon-ai/po-core/headless';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Skill } from '@earendil-works/pi-coding-agent';\n\nimport type { ServerSkillGroup } from '../../types/skills';\n\n/**\n * Each condition that activates a group: its domains, then each plugin turned on for this session only.\n * Declare one contribution per condition; the host keeps one per name once gating has run.\n */\nexport function groupConditions(group: ServerSkillGroup): (PoHeadlessCondition | undefined)[] {\n return [\n group.domains === undefined ? undefined : { domains: group.domains },\n // `plugins` is po-domain's session state key, spelled out so this runs on hosts with an older po-core.\n ...(group.plugins ?? []).map((plugin) => ({ state: { plugins: plugin } })),\n ];\n}\n/**\n * Skill paths one domain admits, or one plugin's session-only activation (`plugin`), or the repository when\n * neither is set.\n */\nexport interface SkillSource {\n readonly domain?: string;\n readonly plugin?: string;\n readonly paths: readonly string[];\n readonly mcpPaths: readonly string[];\n}\n\nconst LOCAL_ONLY_MCP_PACKAGES = new Set([\n '@agimon-ai/po-author',\n '@agimon-ai/po-git',\n '@agimon-ai/po-goal',\n '@agimon-ai/po-help',\n '@agimon-ai/po-calendar',\n '@agimon-ai/po-user-feedback',\n '@agimon-ai/po-voice',\n '@agimon-ai/po-workflow',\n]);\n\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\nexport async function isMcpSkillPlugin(fs: FileSystem, entry: PluginEntry, context: IoContext): Promise<boolean> {\n if (entry.source?.type === 'npm') return !LOCAL_ONLY_MCP_PACKAGES.has(entry.source.package);\n // A package manifest is optional for catalog plugins, but a present identity\n // that cannot be read or parsed must never make the plugin remotely eligible.\n const source = await fs.readTextFile(path.join(entry.directory, 'package.json'), context);\n if (!source.ok) return source.error.code === 'not_found';\n try {\n const manifest = JSON.parse(source.value) as unknown;\n if (typeof manifest !== 'object' || manifest === null || Array.isArray(manifest)) return false;\n const name = (manifest as { name?: unknown }).name;\n return typeof name === 'string' && name.length > 0 && name.trim() === name && !LOCAL_ONLY_MCP_PACKAGES.has(name);\n } catch {\n return false;\n }\n}\n\n/**\n * Whether a discovered skill came from one of these paths.\n *\n * A source holds exact SKILL.md files for plugin and shared skills, but a bare\n * directory for `.po/skills`, so membership is containment rather than\n * equality.\n */\nexport function within(filePath: string, roots: readonly string[]): boolean {\n const resolved = path.resolve(filePath);\n return roots.some((root) => {\n const base = path.resolve(root);\n return resolved === base || resolved.startsWith(`${base}${path.sep}`);\n });\n}\n\n/**\n * One group per loaded skill, merging every source admitting that exact path.\n * MCP admission is merged separately so local-only sources cannot broaden it.\n */\nexport function groupSkills(\n skills: readonly Skill[],\n sources: readonly SkillSource[],\n key: 'paths' | 'mcpPaths',\n): ServerSkillGroup[] {\n return skills.flatMap((skill) => {\n const admitting = sources.filter((source) => within(skill.filePath, source[key]));\n if (admitting.length === 0) return [];\n const domains = [...new Set(admitting.flatMap((source) => (source.domain === undefined ? [] : [source.domain])))];\n const plugins = [...new Set(admitting.flatMap((source) => (source.plugin === undefined ? [] : [source.plugin])))];\n const repository = admitting.some((source) => source.domain === undefined && source.plugin === undefined);\n return [\n {\n ...(repository ? {} : { domains }),\n ...(repository || plugins.length === 0 ? {} : { plugins }),\n skills: [skill],\n },\n ];\n });\n}\n","import path from 'node:path';\n\nimport {\n domainNamesOf,\n loadDomainsAsync,\n resolveManifestPluginEntriesAsync,\n sharedSkillsFor,\n} from '@agimon-ai/po-config/domains';\nimport { readHarnessState } from '@agimon-ai/po-config/harnessState';\nimport type { PoHeadlessExecutionContext } from '@agimon-ai/po-core/headless';\nimport { BACKGROUND_CONTEXT, nodeHost, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport { materializePluginEntries } from '@agimon-ai/po-domain/plugins';\nimport { collectResources, discoverSkillsAsync, type NamedResource } from '@agimon-ai/po-domain/resources';\nimport { formatSkillsForPrompt } from '@earendil-works/pi-coding-agent';\n\nimport type { ServerSkillInventory } from '../../types/skills';\nimport { DeferredSkillLoader } from '../deferredSkills';\nimport { groupSkills, isMcpSkillPlugin, type SkillSource, within } from './grouping';\n\nexport type { ServerSkillGroup, ServerSkillInventory } from '../../types/skills';\n\n/**\n * Every skill the session could reach, grouped by what activates it.\n *\n * A cockpit `/domains` switch reconciles contributions rather than rebuilding\n * the server plugin: the session declaration is mounted once. So enumerating only the\n * launch selection would freeze the command list at whatever was selected when\n * the session host was built. Enumerating every domain up front and tagging\n * each group with its `when` lets the existing kernel refresh do the work, the\n * same way other host contributions follow selection changes.\n */\nexport async function discoverServerSkills(\n execution: PoHeadlessExecutionContext,\n fs: FileSystem,\n signal: AbortSignal,\n): Promise<ServerSkillInventory> {\n signal.throwIfAborted();\n const context = withAbortSignal(signal, BACKGROUND_CONTEXT);\n const state = readHarnessState(execution.environment);\n const home = execution.environment.HOME ?? nodeHost.homeDirectory();\n const repoSkills = path.join(execution.repoRoot, '.po', 'skills');\n const sources: SkillSource[] = [];\n const diagnostics: string[] = [];\n const descriptors = new Map<string, NamedResource>();\n // A malformed domain is a configuration error in one domain, so it must not\n // remove every other domain's skills. Enumerating the whole manifest is new\n // exposure here: reading the launch selection could not fail this way.\n const manifest = await loadDomainsAsync(fs, execution.repoRoot, context, home, execution.environment).catch(\n (error: unknown) => {\n diagnostics.push(`Domain skills are unavailable: ${error instanceof Error ? error.message : String(error)}`);\n return undefined;\n },\n );\n const domains = manifest ? domainNamesOf(manifest) : [];\n\n // Plugin sources precede shared sources, then repository sources.\n // ponytail: Pi globally name-dedupes before domain gating. A loaded plugin\n // shadows a same-name shared fallback even when its domain is off. This is\n // the current ceiling; upgrade to selection-aware loading if collisions arise.\n // Reuse only immutable discovery paths within this invocation. The key keeps\n // plugin ordering and subsets; fs, repo, home and admitted environment are\n // fixed here. No inventory, cleanup handle or session state survives a call.\n const discovered = new Map<\n string,\n Readonly<{ paths: readonly string[]; mcpPaths: readonly string[]; plugins: readonly SkillSource[] }>\n >();\n if (manifest) {\n for (const domain of domains) {\n signal.throwIfAborted();\n try {\n const plugins = await materializePluginEntries(\n await resolveManifestPluginEntriesAsync(fs, manifest, [domain], [], context, home),\n { homeDirectory: home, environment: execution.environment },\n );\n const key = JSON.stringify(\n plugins.map(({ directory, skillDiscovery, skills, source }) => ({\n directory,\n skillDiscovery,\n skills,\n source,\n })),\n );\n const previous = discovered.get(key);\n if (previous) {\n sources.push({ domain, paths: [...previous.paths], mcpPaths: [...previous.mcpPaths] }, ...previous.plugins);\n continue;\n }\n const mcpPluginRoots = (\n await Promise.all(\n plugins.map(async (plugin) =>\n (await isMcpSkillPlugin(fs, plugin, context)) ? path.join(plugin.directory, 'skills') : undefined,\n ),\n )\n ).filter((root): root is string => root !== undefined);\n const collected = await collectResources(execution.repoRoot, plugins, {\n agents: false,\n discoverAgents: false,\n mcp: false,\n sharedSkills: false,\n environment: execution.environment,\n });\n try {\n for (const descriptor of collected.skillSources) descriptors.set(descriptor.path, descriptor);\n const paths = Object.freeze([...collected.skillDirectories]);\n // Exact collected paths retain this domain's per-plugin skill subset.\n // A plugin root would also admit skills loaded for another domain.\n const mcpPaths = Object.freeze(paths.filter((skillPath) => within(skillPath, mcpPluginRoots)));\n // The same skills, admitted one plugin at a time for session-only activation. Never remote: no mcpPaths.\n const pluginSources = plugins.flatMap(({ name, directory }) => {\n const own = paths.filter((skillPath) => within(skillPath, [directory]));\n return name === undefined || own.length === 0 ? [] : [{ plugin: name, paths: own, mcpPaths: [] }];\n });\n discovered.set(key, Object.freeze({ paths, mcpPaths, plugins: pluginSources }));\n if (paths.length > 0) sources.push({ domain, paths: [...paths], mcpPaths: [...mcpPaths] }, ...pluginSources);\n } finally {\n await collected.cleanup();\n }\n } catch (error) {\n diagnostics.push(`Domain '${domain}': ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n }\n\n // Shared skills are admitted by any domain that keeps them.\n signal.throwIfAborted();\n const shared = await discoverSkillsAsync(\n execution.repoRoot,\n path.join(execution.repoRoot, '.claude', 'skills'),\n 'recursive',\n undefined,\n execution.environment,\n );\n for (const descriptor of shared) descriptors.set(descriptor.path, descriptor);\n for (const descriptor of await discoverSkillsAsync(\n execution.repoRoot,\n repoSkills,\n 'recursive',\n undefined,\n execution.environment,\n ))\n descriptors.set(descriptor.path, descriptor);\n if (shared.length > 0 && manifest) {\n const sharedPaths = shared.map((skill) => skill.path);\n for (const domain of domains) {\n if (sharedSkillsFor(manifest, [domain])) {\n sources.push({ domain, paths: sharedPaths, mcpPaths: sharedPaths });\n }\n }\n }\n\n // Repository-local skills belong to the repository, not to a selection.\n sources.push({ paths: [repoSkills], mcpPaths: [repoSkills] });\n\n signal.throwIfAborted();\n // One walk for every group. Pi drops a path it has already loaded, so the\n // loader gets the unique set and each group selects its own skills back out.\n const unique = [...new Set([...sources.flatMap((source) => source.paths), ...(state.skillDirectories ?? [])])];\n const inventory = await new DeferredSkillLoader({ cwd: execution.cwd, skillPaths: unique }).ready();\n signal.throwIfAborted();\n\n for (const descriptor of descriptors.values()) {\n for (const diagnostic of descriptor.diagnostics ?? []) diagnostics.push(`${descriptor.path}: ${diagnostic}`);\n }\n const groups = groupSkills(inventory.skills, sources, 'paths');\n const mcpGroups = groupSkills(inventory.skills, sources, 'mcpPaths');\n\n // The catalog still describes the active selection rather than everything on\n // disk, because it is prompt text rather than a menu.\n const activeSkills = inventory.skills.filter((skill) =>\n within(skill.filePath, [...(state.skillDirectories ?? []), repoSkills]),\n );\n return {\n inventory: { skills: inventory.skills, diagnostics: [...inventory.diagnostics, ...diagnostics] },\n groups,\n mcpGroups,\n relations: Object.fromEntries(\n [...descriptors].map(([filePath, descriptor]) => [filePath, descriptor.relations ?? []]),\n ),\n catalog: formatSkillsForPrompt(activeSkills) || '(no discovered skills)',\n };\n}\n","import { PO_CODEMODE_SERVICE, readPoCodemode, type PoCodemodeNamespace } from '@agimon-ai/po-core/codemode';\nimport type { PoHeadlessHostService } from '@agimon-ai/po-core/headless';\nimport { BACKGROUND_CONTEXT, getOrThrow, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { DeferredSkillSnapshot } from '../../types/skills';\nimport { matchSkills } from '../mcpSkillTools';\n\nexport const SKILL_NAMESPACE_SOURCE = '@agimon-ai/po-skill';\n\ninterface SkillMatch {\n name: string;\n description: string;\n active: boolean;\n}\n\nfunction queryOf(input: unknown): string | undefined {\n if (input === undefined) return undefined;\n const query = typeof input === 'object' && input !== null ? (input as { query?: unknown }).query : 0;\n if (query === undefined || typeof query === 'string') return query;\n throw new Error('Pass { query?: string }.');\n}\n\nfunction nameOf(input: unknown): string {\n const name = (input as { name?: unknown } | null)?.name;\n if (typeof name !== 'string' || name.trim() === '')\n throw new Error('Pass { name: string }, a name from skills.search.');\n return name;\n}\n\n/**\n * Skills of every domain in domains.yaml, selected or not, plus the session's own. Reading one never selects its\n * domain or plugin, so it grants no tools, hooks or MCP servers. Disabled plugins never reach the inventory.\n */\nexport function createSkillNamespace(\n host: Pick<PoHeadlessHostService, 'listSkills' | 'readSkill' | 'context'>,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem,\n): PoCodemodeNamespace {\n return {\n name: 'skills',\n summary: 'Search and read skills beyond the active set, including unselected domains. Reading enables nothing.',\n declarations: `declare const skills: {\n /** Active skills first, then skills of unselected domains. Omit query to list everything. */\n search(input?: { query?: string }): Promise<{ name: string; description: string; active: boolean }[]>;\n /** Full SKILL.md text by exact name from search. Grants no tools, hooks or MCP servers. */\n load(input: { name: string }): Promise<string>;\n};`,\n bind(run) {\n if (run.sessionId !== host.context.sessionId) throw new Error('Skills namespace belongs to another session.');\n let disposed = false;\n run.onDispose(() => {\n disposed = true;\n });\n const check = () => {\n if (disposed) throw new Error('Skills namespace run is disposed.');\n run.signal.throwIfAborted();\n };\n return {\n async search(input?: unknown): Promise<SkillMatch[]> {\n const query = queryOf(input);\n check();\n const seen = new Set<string>();\n const all: SkillMatch[] = [];\n for (const { name, description } of host.listSkills()) {\n seen.add(name);\n all.push({ name, description, active: true });\n }\n for (const { name, description } of inventory.skills)\n if (!seen.has(name)) all.push({ name, description, active: false });\n return matchSkills(all, query);\n },\n async load(input: unknown): Promise<string> {\n const name = nameOf(input);\n check();\n const active = host.readSkill(name);\n if (active !== undefined) return active;\n // Exact inventory names only, so a script can never steer the read to another path.\n const skill = inventory.skills.find((entry) => entry.name === name);\n if (!skill) throw new Error(`No skill named ${name}. Use skills.search to find one.`);\n const text = getOrThrow(\n await fs.readTextFile(skill.filePath, withAbortSignal(run.signal, BACKGROUND_CONTEXT)),\n );\n check();\n return text;\n },\n };\n },\n };\n}\n\nexport function mountSkillNamespace(\n host: Pick<PoHeadlessHostService, 'listSkills' | 'readSkill' | 'context'>,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem,\n) {\n return (context: Context): void => {\n context.inject([PO_CODEMODE_SERVICE], (bound) => {\n const codemode = readPoCodemode(bound);\n if (!codemode) return undefined;\n const registration = codemode.register(SKILL_NAMESPACE_SOURCE, createSkillNamespace(host, inventory, fs));\n return () => registration.dispose();\n });\n };\n}\n","import type { PoHeadlessCommand, PoHeadlessCondition } from '@agimon-ai/po-core/headless';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Skill } from '@earendil-works/pi-coding-agent';\n\nimport { expandDeferredSkillCommand, type DeferredSkillSnapshot } from '../../../../../services/deferredSkills';\nimport type { ServerSkillGroup } from '../../../../../services/serverInventory';\nimport { groupConditions } from '../../../../../services/serverInventory/grouping';\nimport { SKILL_COMMAND_PREFIX, SKILL_INVOCATION_PREFIX, SKILLS_COMMAND } from '../../../../../types/skills';\n\n/**\n * One command per skill, gated by whatever activates that skill.\n *\n * Expansion always reads the full inventory, not the group: a command is only\n * dispatchable while its condition holds, so by the time one runs its skill is\n * active, and looking it up in the union keeps one lookup table instead of one\n * per domain.\n */\nfunction skillCommand(\n skill: Skill,\n when: PoHeadlessCondition | undefined,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem | undefined,\n): PoHeadlessCommand {\n return {\n ...(when === undefined ? {} : { when }),\n name: `${SKILL_COMMAND_PREFIX}${skill.name}`,\n description: skill.description,\n execute: async (args, execution) => {\n const text = `${SKILL_INVOCATION_PREFIX}${skill.name}${args ? ` ${args}` : ''}`;\n const expanded = await expandDeferredSkillCommand(text, inventory.skills, fs);\n if (expanded === text) throw new Error(`Skill '${skill.name}' is no longer readable.`);\n await admit(execution.session, expanded);\n },\n };\n}\n\n/**\n * The dispatching prompt acks when this command returns, so awaiting the whole\n * turn (session.prompt) kept the composer draft until the run ended.\n */\nfunction admit(session: Parameters<PoHeadlessCommand['execute']>[1]['session'], text: string): Promise<void> {\n return session.admitPrompt ? session.admitPrompt(text, 'prompt', 'operator') : session.prompt(text);\n}\nexport function createSkillCommands(\n inventory: DeferredSkillSnapshot,\n catalog: string,\n groups: readonly ServerSkillGroup[],\n fs?: FileSystem,\n t: (key: string, fallback: string) => string = (_key, fallback) => fallback,\n): readonly PoHeadlessCommand[] {\n return [\n {\n name: SKILLS_COMMAND,\n description: 'List discovered skills or invoke one by name.',\n async execute(args, execution) {\n const requested = args.trim();\n if (requested) {\n await admit(\n execution.session,\n await expandDeferredSkillCommand(`${SKILL_INVOCATION_PREFIX}${requested}`, inventory.skills, fs),\n );\n return;\n }\n await execution.client.notify({\n title: t('skill.notification.catalog', 'Po skills'),\n localization: { title: { key: 'skill.notification.catalog', fallback: 'Po skills' } },\n body: catalog,\n level: 'info',\n });\n },\n },\n ...groups.flatMap((group) =>\n groupConditions(group).flatMap((when) => group.skills.map((skill) => skillCommand(skill, when, inventory, fs))),\n ),\n ];\n}\n","import { readHarnessState } from '@agimon-ai/po-config/harnessState';\nimport type { PoHeadlessHostService } from '@agimon-ai/po-core/headless';\nimport { PO_HELP_WHEN } from '@agimon-ai/po-core/help';\nimport { BACKGROUND_CONTEXT, getOrThrow, nodeHost, type FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n type PoServerResources,\n type PoServerSessionPlugin,\n packageResourcePath,\n readPackageResource,\n} from '@agimon-ai/po-core/serverPlugin';\n\nimport { SKILL_INVENTORY_FRESH_MS } from '../../../../../constants/skillInventory';\nimport { mountMcpSkills } from '../../../../../services/mcpSkills';\nimport { createSessionLoadSkillTool, createSessionSearchSkillsTool } from '../../../../../services/mcpSkillTools';\nimport { discoverServerSkills } from '../../../../../services/serverInventory';\nimport { groupConditions } from '../../../../../services/serverInventory/grouping';\nimport { mountSkillNamespace } from '../../../../../services/skillNamespace';\nimport { createSkillCommands } from './skillCommands';\n\nexport async function createSkillServer(\n agent: PoHeadlessHostService,\n fs: FileSystem,\n signal: AbortSignal,\n resources: PoServerResources,\n t?: (key: string, fallback: string) => string,\n): Promise<PoServerSessionPlugin> {\n const execution = agent.context;\n // Sessions with the same inputs share one discovery. The key holds every input discoverServerSkills\n // reads besides the disk, so equal keys give equal inventories, and the window bounds how old that\n // read of the disk can be.\n const key = [\n 'inventory',\n execution.repoRoot,\n execution.cwd,\n execution.environment.HOME ?? nodeHost.homeDirectory(),\n ...(readHarnessState(execution.environment).skillDirectories ?? []),\n Math.floor(Date.now() / SKILL_INVENTORY_FRESH_MS),\n ];\n const { inventory, catalog, groups, mcpGroups, relations } = await resources.acquire(key, () =>\n // Every session sharing the discovery waits on it, so none of their signals may abort it.\n discoverServerSkills(execution, fs, new AbortController().signal),\n );\n return {\n commands: createSkillCommands(inventory, catalog, groups, fs, t),\n tools: [createSessionLoadSkillTool(agent), createSessionSearchSkillsTool(agent)],\n services: [mountMcpSkills(mcpGroups, fs, signal), mountSkillNamespace(agent, inventory, fs)],\n resources: [\n // Each skill joins the prompt's one <available_skills> list, gated like the rest.\n ...groups.flatMap((group) =>\n groupConditions(group).flatMap((when) =>\n group.skills.map((skill) => ({\n name: skill.name,\n description: skill.description,\n path: skill.filePath,\n kind: 'skill' as const,\n ...(relations?.[skill.filePath] === undefined ? {} : { relations: relations[skill.filePath] }),\n ...(when === undefined ? {} : { when }),\n read: async () => getOrThrow(await fs.readTextFile(skill.filePath, BACKGROUND_CONTEXT)),\n })),\n ),\n ),\n ...[\n {\n name: 'help-how-to-author-skill',\n description:\n '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.',\n },\n {\n name: 'help-how-to-skill',\n description:\n \"Use Po's skill catalog and deferred discovery. Diagnose missing or shadowed skills and invoke the narrowest available guidance.\",\n },\n ].map((skill) => ({\n ...skill,\n when: PO_HELP_WHEN,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),\n read: () => readPackageResource(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),\n })),\n ],\n };\n}\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\nimport { readPoLang, readPoPersonLocale } from '@agimon-ai/po-core/locale';\nimport { requirePoFs } from '@agimon-ai/po-core/platform';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nimport { createSkillServer } from './_lib/skillServer';\n\nexport default defineRoot(async ({ agent, context: root, signal, resources }: PoServerPluginContext) => {\n const runtime: PoServerSessionPlugin = agent\n ? await createSkillServer(\n agent,\n requirePoFs(root),\n signal,\n resources,\n (key, fallback) => readPoLang(root)?.t(readPoPersonLocale(root)?.read(), key, fallback) ?? fallback,\n )\n : { commands: [], resources: [] };\n return { value: runtime, services: runtime.services };\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.commands!,\n { cardinality: 'many' },\n);\n","// @scaffold-generated\nimport { defineResource } from '@agimon-ai/po-core/extensionFile';\nimport { packageResourcePath, readPackageResource } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineResource({\n name: 'codemode-how-to-skills',\n description:\n 'Search and read skills outside the active set, including skills of unselected domains, through the skills namespace. Use when no listed skill fits the task.',\n // A code-mode guide: listed in the system prompt, outside the searchable catalog.\n pinned: true,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, 'src/prompts/codemode-how-to-skills/SKILL.md'),\n read: () => readPackageResource(import.meta.url, 'src/prompts/codemode-how-to-skills/SKILL.md'),\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.resources!,\n { cardinality: 'many' },\n);\n","import { defineRoutedContribution, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\n/** The session agent's skill tools; the Pi CLI keeps Pi's own skill handling. */\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.tools ?? [],\n { cardinality: 'many' },\n);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverPlugin';\nimport { composeRootHooks, composeRootInjects } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport commandSkills from '../src/extensions/workspaces/sessions/(backend)/command/skills.server';\nimport resourceCodemodeHowToSkills from '../src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server';\nimport resourceSkills from '../src/extensions/workspaces/sessions/(backend)/resource/skills.server';\nimport toolLoadSkill from '../src/extensions/workspaces/sessions/(backend)/tool/load_skill.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\ntype ManyFactory<T, C> = (context: C) => T | readonly T[];\nconst many = <T, C>(value: T | readonly T[] | ManyFactory<T, C>, context: C): readonly T[] => {\n const resolved = typeof value === 'function' ? (value as ManyFactory<T, C>)(context) : value;\n return Array.isArray(resolved) ? resolved : [resolved as T];\n};\n\nexport const serverPlugin = defineServerPlugin({\n name: '@agimon-ai/po-skill',\n providerOverrides: composeServerProviderOverrides(rootSession),\n injects: composeRootInjects({ session: [rootSession] }),\n session: async (context) => {\n const scopeSession = await context.scopeRoot('session', rootSession, context);\n const contextSession = { ...context, root: scopeSession.value };\n return {\n ...composeRootHooks(scopeSession),\n get commands(): PoServerSessionPlugin['commands'] { return [...many(commandSkills, contextSession)]; },\n get resources(): PoServerSessionPlugin['resources'] { return [at(resourceCodemodeHowToSkills, contextSession), ...many(resourceSkills, contextSession)]; },\n get tools(): PoServerSessionPlugin['tools'] { return [...many(toolLoadSkill, contextSession)]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): PoServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default serverPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAa,2BAA2B;;;ACCxC,MAAa,qBAAqB;;AAOlC,SAAgB,eAAe,QAAqC,IAAgB,QAAqB;CACvG,QAAQ,YAA2B;EACjC,QAAQ,QAAQ,oBAAoB,EAClC,KAAK,QAAQ;GACX,OAAO,eAAe;GACtB,OAAO,OAAO,eAAe;GAC7B,MAAM,UAAU,OAAO,UAAU,KAAK,CAAC,CAAC;GACxC,MAAM,yBAAS,IAAI,IAAwB;GAC3C,KAAK,MAAM,SAAS,QAAQ;IAC1B,IAAI,MAAM,YAAY,KAAA,KAAa,CAAC,MAAM,QAAQ,MAAM,WAAW,QAAQ,SAAS,MAAM,CAAC,GAAG;IAC9F,KAAK,MAAM,SAAS,MAAM,QAAQ;KAEhC,IAAI,OAAO,IAAI,MAAM,IAAI,GAAG;KAC5B,OAAO,IAAI,MAAM,MAAM;MACrB,MAAM,MAAM;MACZ,aAAa,MAAM;MACnB,MAAM,OAAO;OACX,MAAM,aAAa,YAAY,IAAI,CAAC,QAAQ,OAAO,MAAM,CAA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AC5F,MAAM,WAAW,OAAO,UAAU,aAAc,MAA4B,OAAO,IAAI;CACvF,OAAO,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAa;AAC5D;AAEA,MAAa,eAAe,mBAAmB;CAC7C,MAAM;CACN,mBAAmB,+BAA+BA,mBAAW;CAC7D,SAAS,mBAAmB,EAAE,SAAS,CAACA,mBAAW,EAAE,CAAC;CACtD,SAAS,OAAO,YAAY;EAC1B,MAAM,eAAe,MAAM,QAAQ,UAAU,WAAWA,qBAAa,OAAO;EAC5E,MAAM,iBAAiB;GAAE,GAAG;GAAS,MAAM,aAAa;EAAM;EAC9D,OAAO;GACL,GAAG,iBAAiB,YAAY;GAChC,IAAI,WAA8C;IAAE,OAAO,CAAC,GAAG,KAAKC,yBAAe,cAAc,CAAC;GAAG;GACrG,IAAI,YAAgD;IAAE,OAAO,CAAC,GAAGC,uCAA6B,cAAc,GAAG,GAAG,KAAKC,uBAAgB,cAAc,CAAC;GAAG;GACzJ,IAAI,QAAwC;IAAE,OAAO,CAAC,GAAG,KAAKC,2BAAe,cAAc,CAAC;GAAG;GAC/F,UAAU,CAAC,GAAI,aAAa,YAAY,CAAC,CAAE;GAC3C,IAAI,aAAkD;IAAE,OAAO,CAAC,GAAI,aAAa,cAAc,CAAC,CAAE;GAAG;EACvG;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"server.mjs","names":["rootSession","commandSkills","resourceCodemodeHowToSkills","resourceSkills"],"sources":["../../src/constants/skillInventory.ts","../../src/services/mcpSkills/index.ts","../../src/services/deferredSkills/index.ts","../../src/services/serverInventory/grouping.ts","../../src/services/serverInventory/index.ts","../../src/schemas/mcpSkillTools.ts","../../src/services/mcpSkillTools/index.ts","../../src/services/skillNamespace/index.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/skillCommands.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/skillServer.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/extensions/workspaces/sessions/(backend)/command/skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts","../../generated/server.ts"],"sourcesContent":["/**\n * How long sessions with the same inputs share one skill inventory instead of each reading the disk.\n * ponytail: a skill added on disk reaches new sessions within this window, not at once; watch the\n * skill roots if that lag matters.\n */\nexport const SKILL_INVENTORY_FRESH_MS = 60_000;\n","import type { PoMcpPluginContext, PoMcpSkill } from '@agimon-ai/po-core/mcpFacet';\nimport { BACKGROUND_CONTEXT, getOrThrow, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { ServerSkillGroup } from '../serverInventory';\n\nexport const MCP_SKILLS_SERVICE = 'po/discovered-mcp-skills';\n\nexport interface McpSkillProvider {\n list(context: PoMcpPluginContext): readonly PoMcpSkill[];\n}\n\n/** Explicit remote provider, never a projection of the local resource registry. */\nexport function mountMcpSkills(groups: readonly ServerSkillGroup[], fs: FileSystem, signal: AbortSignal) {\n return (context: Context): void => {\n context.provide(MCP_SKILLS_SERVICE, {\n list(remote) {\n signal.throwIfAborted();\n remote.signal.throwIfAborted();\n const domains = remote.selection.read().domains;\n const skills = new Map<string, PoMcpSkill>();\n for (const group of groups) {\n if (group.domains !== undefined && !group.domains.some((domain) => domains.includes(domain))) continue;\n for (const skill of group.skills) {\n // Retain name precedence defensively for remote providers.\n if (skills.has(skill.name)) continue;\n skills.set(skill.name, {\n name: skill.name,\n description: skill.description,\n async read() {\n const readSignal = AbortSignal.any([signal, remote.signal]);\n readSignal.throwIfAborted();\n const text = getOrThrow(\n await fs.readTextFile(skill.filePath, withAbortSignal(readSignal, BACKGROUND_CONTEXT)),\n );\n readSignal.throwIfAborted();\n return text;\n },\n });\n }\n }\n return [...skills.values()];\n },\n } satisfies McpSkillProvider);\n };\n}\n\nexport function bindMcpSkills(context: PoMcpPluginContext): readonly PoMcpSkill[] {\n const provider = context.services.get<McpSkillProvider>(MCP_SKILLS_SERVICE);\n if (!provider) throw new Error('Discovered MCP skills are unavailable.');\n return provider.list(context);\n}\n","import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { Worker } from 'node:worker_threads';\n\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n type BuildSystemPromptOptions,\n formatSkillsForPrompt,\n getAgentDir,\n loadSkills,\n type Skill,\n stripFrontmatter,\n} from '@earendil-works/pi-coding-agent';\n\nimport type { DeferredSkillLoaderOptions, DeferredSkillSnapshot } from '../../types/skills';\n\nexport type { DeferredSkillLoaderOptions, DeferredSkillSnapshot } from '../../types/skills';\n\nconst PI_PACKAGE = '@earendil-works/pi-coding-agent';\nconst PACKAGE_MANIFEST = 'package.json';\n// A fresh worker takes ~240 ms to import Pi's main entry but ~20 ms for this module alone, and\n// every session spawns one. ponytail: not in Pi's exports map, so a Pi release that moves it\n// falls back to the main entry (slow, still correct); deferredSkills.test.ts pins the path.\nconst PI_SKILLS_MODULE = path.join('dist', 'core', 'skills.js');\nconst SKILL_WORKER_SOURCE = `\nconst { parentPort, workerData } = require('node:worker_threads');\nvoid (async () => {\n try {\n const { loadSkills } = await import(workerData.piModuleUrl);\n parentPort.postMessage({ ok: true, result: loadSkills(workerData.loadOptions) });\n } catch (error) {\n parentPort.postMessage({ ok: false, error: error instanceof Error ? error.message : String(error) });\n }\n})();\n`;\n\nasync function installedPiModuleUrl(): Promise<string> {\n const anchors = [process.argv[1], fileURLToPath(import.meta.url), path.join(process.cwd(), PACKAGE_MANIFEST)];\n for (const anchor of anchors) {\n if (!anchor) continue;\n let directory = path.dirname(path.resolve(anchor));\n while (true) {\n const packageRoot = path.join(directory, 'node_modules', PI_PACKAGE);\n const manifestPath = path.join(packageRoot, PACKAGE_MANIFEST);\n try {\n const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8')) as { main?: unknown };\n if (typeof manifest.main === 'string') {\n const entry = path.resolve(packageRoot, manifest.main);\n const skills = path.join(packageRoot, PI_SKILLS_MODULE);\n for (const candidate of [skills, entry]) {\n try {\n await fs.access(candidate);\n return pathToFileURL(candidate).href;\n } catch {\n // Try the next entry before walking up the module chain.\n }\n }\n }\n } catch {\n // This anchor does not expose Pi at this level; continue up its module chain.\n }\n const parent = path.dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n }\n throw new Error(`Cannot resolve ${PI_PACKAGE} from the Po or host module trees`);\n}\n\ninterface SkillWorkerResult {\n ok: boolean;\n result?: { skills: Skill[]; diagnostics: Array<{ path?: string; message: string }> };\n error?: string;\n}\n\n/**\n * One session's Po-selected skill inventory.\n *\n * Construction is deliberately cheap. `start()` schedules the synchronous Pi\n * walker after session_start returns, while `ready()` is the single promise the\n * first input awaits before Pi expands `/skill:name`.\n */\nexport class DeferredSkillLoader {\n readonly #options: DeferredSkillLoaderOptions;\n #promise: Promise<DeferredSkillSnapshot> | undefined;\n\n constructor(options: DeferredSkillLoaderOptions) {\n this.#options = options;\n }\n\n start(): Promise<DeferredSkillSnapshot> {\n if (this.#promise) return this.#promise;\n\n if (!this.#options.schedule && !this.#options.load) {\n this.#promise = this.#loadInWorker();\n return this.#promise;\n }\n\n const schedule = this.#options.schedule ?? ((load: () => void) => setImmediate(load));\n this.#promise = new Promise((resolve) => {\n const fail = (error: unknown): void => {\n resolve(this.#failure(error));\n };\n try {\n schedule(() => {\n try {\n resolve(this.#load());\n } catch (error) {\n fail(error);\n }\n });\n } catch (error) {\n fail(error);\n }\n });\n return this.#promise;\n }\n\n ready(): Promise<DeferredSkillSnapshot> {\n return this.start();\n }\n\n #loadOptions(): { cwd: string; agentDir: string; skillPaths: string[]; includeDefaults: boolean } {\n return {\n cwd: this.#options.cwd,\n agentDir: this.#options.agentDir ?? getAgentDir(),\n skillPaths: [...this.#options.skillPaths],\n includeDefaults: false,\n };\n }\n\n #snapshot(result: {\n skills: Skill[];\n diagnostics: Array<{ path?: string; message: string }>;\n }): DeferredSkillSnapshot {\n return {\n skills: result.skills,\n diagnostics: result.diagnostics.map(\n (diagnostic) => `${diagnostic.path ?? this.#options.cwd}: ${diagnostic.message}`,\n ),\n };\n }\n\n #failure(error: unknown): DeferredSkillSnapshot {\n return {\n skills: [],\n diagnostics: [`${this.#options.cwd}: ${error instanceof Error ? error.message : String(error)}`],\n };\n }\n\n #load(): DeferredSkillSnapshot {\n return this.#snapshot((this.#options.load ?? loadSkills)(this.#loadOptions()));\n }\n\n async #loadInWorker(): Promise<DeferredSkillSnapshot> {\n let piModuleUrl: string;\n try {\n piModuleUrl = this.#options.piModuleUrl ?? (await installedPiModuleUrl());\n } catch (error) {\n return this.#failure(error);\n }\n return new Promise((resolve) => {\n let settled = false;\n const settle = (snapshot: DeferredSkillSnapshot): void => {\n if (settled) return;\n settled = true;\n resolve(snapshot);\n };\n let worker: Worker;\n try {\n worker = new Worker(SKILL_WORKER_SOURCE, {\n eval: true,\n workerData: {\n piModuleUrl,\n loadOptions: this.#loadOptions(),\n },\n });\n } catch (error) {\n settle(this.#failure(error));\n return;\n }\n worker.unref();\n worker.once('message', (message: SkillWorkerResult) => {\n if (!message.ok || !message.result) {\n settle(this.#failure(message.error ?? 'Skill worker failed'));\n return;\n }\n settle(this.#snapshot(message.result));\n });\n worker.once('error', (error) => settle(this.#failure(error)));\n worker.once('exit', (code) => {\n if (code !== 0) settle(this.#failure(`Skill worker exited with code ${code}`));\n });\n });\n }\n}\n\n/** Appends only the inventory Pi would append for these deferred skills. */\nexport function buildPromptWithDeferredSkills(\n systemPrompt: string,\n options: BuildSystemPromptOptions,\n skills: Skill[],\n): string {\n if (options.selectedTools && !options.selectedTools.includes('read')) return systemPrompt;\n return `${systemPrompt}${formatSkillsForPrompt(skills)}`;\n}\n\n/**\n * Expands a deferred `/skill:name` before Pi consults its synchronous inventory. Node discovered the\n * skill on the host disk, so it reads it there; the edge build reads through `fs` instead.\n */\nexport async function expandDeferredSkillCommand(\n text: string,\n skills: readonly Skill[],\n _fs?: FileSystem,\n): Promise<string> {\n if (!text.startsWith('/skill:')) return text;\n const spaceIndex = text.indexOf(' ');\n const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);\n const skill = skills.find((candidate) => candidate.name === skillName);\n if (!skill) return text;\n\n try {\n const args = spaceIndex === -1 ? '' : text.slice(spaceIndex + 1).trim();\n const body = stripFrontmatter(await fs.readFile(skill.filePath, 'utf8')).trim();\n const skillBlock = `<skill name=\"${skill.name}\" location=\"${skill.filePath}\">\\nReferences are relative to ${skill.baseDir}.\\n\\n${body}\\n</skill>`;\n return args ? `${skillBlock}\\n\\n${args}` : skillBlock;\n } catch {\n // Pi uses the same literal-text fallback if a skill disappears between\n // discovery and submission; the agent can still respond to the command.\n return text;\n }\n}\n","import path from 'node:path';\n\nimport type { PluginEntry } from '@agimon-ai/po-config/domains';\nimport type { PoHeadlessCondition } from '@agimon-ai/po-core/headless';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Skill } from '@earendil-works/pi-coding-agent';\n\nimport type { ServerSkillGroup } from '../../types/skills';\n\n/**\n * Each condition that activates a group: its domains, then each plugin turned on for this session only.\n * Declare one contribution per condition; the host keeps one per name once gating has run.\n */\nexport function groupConditions(group: ServerSkillGroup): (PoHeadlessCondition | undefined)[] {\n return [\n group.domains === undefined ? undefined : { domains: group.domains },\n // `plugins` is po-domain's session state key, spelled out so this runs on hosts with an older po-core.\n ...(group.plugins ?? []).map((plugin) => ({ state: { plugins: plugin } })),\n ];\n}\n/**\n * Skill paths one domain admits, or one plugin's session-only activation (`plugin`), or the repository when\n * neither is set.\n */\nexport interface SkillSource {\n readonly domain?: string;\n readonly plugin?: string;\n readonly paths: readonly string[];\n readonly mcpPaths: readonly string[];\n}\n\nconst LOCAL_ONLY_MCP_PACKAGES = new Set([\n '@agimon-ai/po-author',\n '@agimon-ai/po-git',\n '@agimon-ai/po-goal',\n '@agimon-ai/po-help',\n '@agimon-ai/po-calendar',\n '@agimon-ai/po-user-feedback',\n '@agimon-ai/po-voice',\n '@agimon-ai/po-workflow',\n]);\n\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\nexport async function isMcpSkillPlugin(fs: FileSystem, entry: PluginEntry, context: IoContext): Promise<boolean> {\n if (entry.source?.type === 'npm') return !LOCAL_ONLY_MCP_PACKAGES.has(entry.source.package);\n // A package manifest is optional for catalog plugins, but a present identity\n // that cannot be read or parsed must never make the plugin remotely eligible.\n const source = await fs.readTextFile(path.join(entry.directory, 'package.json'), context);\n if (!source.ok) return source.error.code === 'not_found';\n try {\n const manifest = JSON.parse(source.value) as unknown;\n if (typeof manifest !== 'object' || manifest === null || Array.isArray(manifest)) return false;\n const name = (manifest as { name?: unknown }).name;\n return typeof name === 'string' && name.length > 0 && name.trim() === name && !LOCAL_ONLY_MCP_PACKAGES.has(name);\n } catch {\n return false;\n }\n}\n\n/**\n * Whether a discovered skill came from one of these paths.\n *\n * A source holds exact SKILL.md files for plugin and shared skills, but a bare\n * directory for `.po/skills`, so membership is containment rather than\n * equality.\n */\nexport function within(filePath: string, roots: readonly string[]): boolean {\n const resolved = path.resolve(filePath);\n return roots.some((root) => {\n const base = path.resolve(root);\n return resolved === base || resolved.startsWith(`${base}${path.sep}`);\n });\n}\n\n/**\n * One group per loaded skill, merging every source admitting that exact path.\n * MCP admission is merged separately so local-only sources cannot broaden it.\n */\nexport function groupSkills(\n skills: readonly Skill[],\n sources: readonly SkillSource[],\n key: 'paths' | 'mcpPaths',\n): ServerSkillGroup[] {\n return skills.flatMap((skill) => {\n const admitting = sources.filter((source) => within(skill.filePath, source[key]));\n if (admitting.length === 0) return [];\n const domains = [...new Set(admitting.flatMap((source) => (source.domain === undefined ? [] : [source.domain])))];\n const plugins = [...new Set(admitting.flatMap((source) => (source.plugin === undefined ? [] : [source.plugin])))];\n const repository = admitting.some((source) => source.domain === undefined && source.plugin === undefined);\n return [\n {\n ...(repository ? {} : { domains }),\n ...(repository || plugins.length === 0 ? {} : { plugins }),\n skills: [skill],\n },\n ];\n });\n}\n","import path from 'node:path';\n\nimport {\n domainNamesOf,\n loadDomainsAsync,\n resolveManifestPluginEntriesAsync,\n sharedSkillsFor,\n} from '@agimon-ai/po-config/domains';\nimport { readHarnessState } from '@agimon-ai/po-config/harnessState';\nimport type { PoHeadlessExecutionContext } from '@agimon-ai/po-core/headless';\nimport { BACKGROUND_CONTEXT, nodeHost, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport { materializePluginEntries } from '@agimon-ai/po-domain/plugins';\nimport { collectResources, discoverSkillsAsync, type NamedResource } from '@agimon-ai/po-domain/resources';\nimport { formatSkillsForPrompt } from '@earendil-works/pi-coding-agent';\n\nimport type { ServerSkillInventory } from '../../types/skills';\nimport { DeferredSkillLoader } from '../deferredSkills';\nimport { groupSkills, isMcpSkillPlugin, type SkillSource, within } from './grouping';\n\nexport type { ServerSkillGroup, ServerSkillInventory } from '../../types/skills';\n\n/**\n * Every skill the session could reach, grouped by what activates it.\n *\n * A cockpit `/domains` switch reconciles contributions rather than rebuilding\n * the server plugin: the session declaration is mounted once. So enumerating only the\n * launch selection would freeze the command list at whatever was selected when\n * the session host was built. Enumerating every domain up front and tagging\n * each group with its `when` lets the existing kernel refresh do the work, the\n * same way other host contributions follow selection changes.\n */\nexport async function discoverServerSkills(\n execution: PoHeadlessExecutionContext,\n fs: FileSystem,\n signal: AbortSignal,\n): Promise<ServerSkillInventory> {\n signal.throwIfAborted();\n const context = withAbortSignal(signal, BACKGROUND_CONTEXT);\n const state = readHarnessState(execution.environment);\n const home = execution.environment.HOME ?? nodeHost.homeDirectory();\n const repoSkills = path.join(execution.repoRoot, '.po', 'skills');\n const sources: SkillSource[] = [];\n const diagnostics: string[] = [];\n const descriptors = new Map<string, NamedResource>();\n // A malformed domain is a configuration error in one domain, so it must not\n // remove every other domain's skills. Enumerating the whole manifest is new\n // exposure here: reading the launch selection could not fail this way.\n const manifest = await loadDomainsAsync(fs, execution.repoRoot, context, home, execution.environment).catch(\n (error: unknown) => {\n diagnostics.push(`Domain skills are unavailable: ${error instanceof Error ? error.message : String(error)}`);\n return undefined;\n },\n );\n const domains = manifest ? domainNamesOf(manifest) : [];\n\n // Plugin sources precede shared sources, then repository sources.\n // ponytail: Pi globally name-dedupes before domain gating. A loaded plugin\n // shadows a same-name shared fallback even when its domain is off. This is\n // the current ceiling; upgrade to selection-aware loading if collisions arise.\n // Reuse only immutable discovery paths within this invocation. The key keeps\n // plugin ordering and subsets; fs, repo, home and admitted environment are\n // fixed here. No inventory, cleanup handle or session state survives a call.\n const discovered = new Map<\n string,\n Readonly<{ paths: readonly string[]; mcpPaths: readonly string[]; plugins: readonly SkillSource[] }>\n >();\n if (manifest) {\n for (const domain of domains) {\n signal.throwIfAborted();\n try {\n const plugins = await materializePluginEntries(\n await resolveManifestPluginEntriesAsync(fs, manifest, [domain], [], context, home),\n { homeDirectory: home, environment: execution.environment },\n );\n const key = JSON.stringify(\n plugins.map(({ directory, skillDiscovery, skills, source }) => ({\n directory,\n skillDiscovery,\n skills,\n source,\n })),\n );\n const previous = discovered.get(key);\n if (previous) {\n sources.push({ domain, paths: [...previous.paths], mcpPaths: [...previous.mcpPaths] }, ...previous.plugins);\n continue;\n }\n const mcpPluginRoots = (\n await Promise.all(\n plugins.map(async (plugin) =>\n (await isMcpSkillPlugin(fs, plugin, context)) ? path.join(plugin.directory, 'skills') : undefined,\n ),\n )\n ).filter((root): root is string => root !== undefined);\n const collected = await collectResources(execution.repoRoot, plugins, {\n agents: false,\n discoverAgents: false,\n mcp: false,\n sharedSkills: false,\n environment: execution.environment,\n });\n try {\n for (const descriptor of collected.skillSources) descriptors.set(descriptor.path, descriptor);\n const paths = Object.freeze([...collected.skillDirectories]);\n // Exact collected paths retain this domain's per-plugin skill subset.\n // A plugin root would also admit skills loaded for another domain.\n const mcpPaths = Object.freeze(paths.filter((skillPath) => within(skillPath, mcpPluginRoots)));\n // The same skills, admitted one plugin at a time for session-only activation. Never remote: no mcpPaths.\n const pluginSources = plugins.flatMap(({ name, directory }) => {\n const own = paths.filter((skillPath) => within(skillPath, [directory]));\n return name === undefined || own.length === 0 ? [] : [{ plugin: name, paths: own, mcpPaths: [] }];\n });\n discovered.set(key, Object.freeze({ paths, mcpPaths, plugins: pluginSources }));\n if (paths.length > 0) sources.push({ domain, paths: [...paths], mcpPaths: [...mcpPaths] }, ...pluginSources);\n } finally {\n await collected.cleanup();\n }\n } catch (error) {\n diagnostics.push(`Domain '${domain}': ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n }\n\n // Shared skills are admitted by any domain that keeps them.\n signal.throwIfAborted();\n const shared = await discoverSkillsAsync(\n execution.repoRoot,\n path.join(execution.repoRoot, '.claude', 'skills'),\n 'recursive',\n undefined,\n execution.environment,\n );\n for (const descriptor of shared) descriptors.set(descriptor.path, descriptor);\n for (const descriptor of await discoverSkillsAsync(\n execution.repoRoot,\n repoSkills,\n 'recursive',\n undefined,\n execution.environment,\n ))\n descriptors.set(descriptor.path, descriptor);\n if (shared.length > 0 && manifest) {\n const sharedPaths = shared.map((skill) => skill.path);\n for (const domain of domains) {\n if (sharedSkillsFor(manifest, [domain])) {\n sources.push({ domain, paths: sharedPaths, mcpPaths: sharedPaths });\n }\n }\n }\n\n // Repository-local skills belong to the repository, not to a selection.\n sources.push({ paths: [repoSkills], mcpPaths: [repoSkills] });\n\n signal.throwIfAborted();\n // One walk for every group. Pi drops a path it has already loaded, so the\n // loader gets the unique set and each group selects its own skills back out.\n const unique = [...new Set([...sources.flatMap((source) => source.paths), ...(state.skillDirectories ?? [])])];\n const inventory = await new DeferredSkillLoader({ cwd: execution.cwd, skillPaths: unique }).ready();\n signal.throwIfAborted();\n\n for (const descriptor of descriptors.values()) {\n for (const diagnostic of descriptor.diagnostics ?? []) diagnostics.push(`${descriptor.path}: ${diagnostic}`);\n }\n const groups = groupSkills(inventory.skills, sources, 'paths');\n const mcpGroups = groupSkills(inventory.skills, sources, 'mcpPaths');\n\n // The catalog still describes the active selection rather than everything on\n // disk, because it is prompt text rather than a menu.\n const activeSkills = inventory.skills.filter((skill) =>\n within(skill.filePath, [...(state.skillDirectories ?? []), repoSkills]),\n );\n return {\n inventory: { skills: inventory.skills, diagnostics: [...inventory.diagnostics, ...diagnostics] },\n groups,\n mcpGroups,\n relations: Object.fromEntries(\n [...descriptors].map(([filePath, descriptor]) => [filePath, descriptor.relations ?? []]),\n ),\n catalog: formatSkillsForPrompt(activeSkills) || '(no discovered skills)',\n };\n}\n","import { Type } from 'typebox';\n\nexport const searchSkillsParameters = Type.Object({ query: Type.Optional(Type.String()) });\nexport const loadSkillParameters = Type.Object({ name: Type.String() });\n","import type { PoHeadlessHostService, PoHeadlessTool } from '@agimon-ai/po-core/headless';\n\nimport { loadSkillParameters, searchSkillsParameters } from '../../schemas/mcpSkillTools';\n\nfunction text(text: string) {\n return { content: [{ type: 'text' as const, text }] };\n}\n\nfunction skills(context: Parameters<PoHeadlessTool['execute']>[4]) {\n if (context.mcpSkills === undefined) throw new Error('Remote skill access is unavailable.');\n return context.mcpSkills;\n}\n\n/** Case-insensitive substring match on name and description; an empty query keeps everything, in order. */\nexport function matchSkills<T extends { name: string; description: string }>(\n skills: readonly T[],\n query?: string,\n): T[] {\n const needle = query?.trim().toLocaleLowerCase();\n if (needle === undefined || needle === '') return [...skills];\n return skills.filter(({ name, description }) => `${name}\\n${description}`.toLocaleLowerCase().includes(needle));\n}\n\nexport function createSearchSkillsTool(): PoHeadlessTool<typeof searchSkillsParameters> {\n return {\n name: 'search_skills',\n label: 'Search skills',\n description: 'Discover repository and active-domain skills available to this remote connection.',\n parameters: searchSkillsParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n async execute(_toolCallId, { query }, _signal, _onUpdate, context) {\n const matches = matchSkills(await skills(context).list(), query);\n return { ...text(JSON.stringify(matches)), structuredContent: { skills: matches } };\n },\n };\n}\n\nexport function createSessionSearchSkillsTool(\n host: Pick<PoHeadlessHostService, 'listSkills'>,\n): PoHeadlessTool<typeof searchSkillsParameters> {\n return {\n name: 'search_skills',\n label: 'Search skills',\n description: 'Search available session skills by name or description.',\n parameters: searchSkillsParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n executionMode: 'parallel',\n async execute(_toolCallId, { query }) {\n const matches = matchSkills(\n host.listSkills().map(({ name, description }) => ({ name, description })),\n query,\n );\n return { ...text(JSON.stringify(matches)), structuredContent: { skills: matches } };\n },\n };\n}\n\nexport function createSessionLoadSkillTool(\n host: Pick<PoHeadlessHostService, 'readSkill'>,\n): PoHeadlessTool<typeof loadSkillParameters> {\n return {\n // PO_LOAD_SKILL_TOOL, spelled out so the renderer rule can read it.\n name: 'load_skill',\n label: 'Load skill',\n description: 'Load the full instructions of an available session skill by exact name.',\n parameters: loadSkillParameters,\n executionMode: 'parallel',\n async execute(_toolCallId, { name }) {\n const body = host.readSkill(name);\n if (body === undefined) return { ...text(`No skill named ${name} is available in this session.`), isError: true };\n return text(body);\n },\n };\n}\n\nexport function createLoadSkillTool(): PoHeadlessTool<typeof loadSkillParameters> {\n return {\n name: 'load_skill',\n label: 'Load skill',\n description: 'Load the full Markdown instructions for an available remote skill by exact name.',\n parameters: loadSkillParameters,\n annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false },\n async execute(_toolCallId, { name }, _signal, _onUpdate, context) {\n return text(await skills(context).read(name));\n },\n };\n}\n","import { PO_CODEMODE_SERVICE, readPoCodemode, type PoCodemodeNamespace } from '@agimon-ai/po-core/codemode';\nimport { PO_SKILLS_NAMESPACE, type PoHeadlessHostService } from '@agimon-ai/po-core/headless';\nimport {\n BACKGROUND_CONTEXT,\n getOrThrow,\n PO_ISOLATE_SERVICE,\n readPoIsolate,\n withAbortSignal,\n type FileSystem,\n} from '@agimon-ai/po-core/platform';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport type { DeferredSkillSnapshot } from '../../types/skills';\nimport { createSessionLoadSkillTool, createSessionSearchSkillsTool, matchSkills } from '../mcpSkillTools';\n\nexport const SKILL_NAMESPACE_SOURCE = '@agimon-ai/po-skill';\n\ninterface SkillMatch {\n name: string;\n description: string;\n active: boolean;\n}\n\nfunction queryOf(input: unknown): string | undefined {\n if (input === undefined) return undefined;\n const query = typeof input === 'object' && input !== null ? (input as { query?: unknown }).query : 0;\n if (query === undefined || typeof query === 'string') return query;\n throw new Error('Pass { query?: string }.');\n}\n\nfunction nameOf(input: unknown): string {\n const name = (input as { name?: unknown } | null)?.name;\n if (typeof name !== 'string' || name.trim() === '')\n throw new Error('Pass { name: string }, a name from skills.search.');\n return name;\n}\n\n/**\n * Skills of every domain in domains.yaml, selected or not, plus the session's own. Reading one never selects its\n * domain or plugin, so it grants no tools, hooks or MCP servers. Disabled plugins never reach the inventory.\n */\nexport function createSkillNamespace(\n host: Pick<PoHeadlessHostService, 'listSkills' | 'readSkill' | 'context'>,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem,\n): PoCodemodeNamespace {\n return {\n name: PO_SKILLS_NAMESPACE,\n summary: 'Search and read skills beyond the active set, including unselected domains. Reading enables nothing.',\n declarations: `declare const skills: {\n /** Active skills first, then skills of unselected domains. Omit query to list everything. */\n search(input?: { query?: string }): Promise<{ name: string; description: string; active: boolean }[]>;\n /** Full SKILL.md text by exact name from search. Grants no tools, hooks or MCP servers. */\n load(input: { name: string }): Promise<string>;\n};`,\n bind(run) {\n if (run.sessionId !== host.context.sessionId) throw new Error('Skills namespace belongs to another session.');\n let disposed = false;\n run.onDispose(() => {\n disposed = true;\n });\n const check = () => {\n if (disposed) throw new Error('Skills namespace run is disposed.');\n run.signal.throwIfAborted();\n };\n return {\n async search(input?: unknown): Promise<SkillMatch[]> {\n const query = queryOf(input);\n check();\n const seen = new Set<string>();\n const all: SkillMatch[] = [];\n for (const { name, description } of host.listSkills()) {\n seen.add(name);\n all.push({ name, description, active: true });\n }\n for (const { name, description } of inventory.skills)\n if (!seen.has(name)) all.push({ name, description, active: false });\n return matchSkills(all, query);\n },\n async load(input: unknown): Promise<string> {\n const name = nameOf(input);\n check();\n const active = host.readSkill(name);\n if (active !== undefined) return active;\n // Exact inventory names only, so a script can never steer the read to another path.\n const skill = inventory.skills.find((entry) => entry.name === name);\n if (!skill) throw new Error(`No skill named ${name}. Use skills.search to find one.`);\n const text = getOrThrow(\n await fs.readTextFile(skill.filePath, withAbortSignal(run.signal, BACKGROUND_CONTEXT)),\n );\n check();\n return text;\n },\n };\n },\n };\n}\n\nexport function mountSkillNamespace(\n host: Pick<PoHeadlessHostService, 'listSkills' | 'readSkill' | 'context' | 'registerTool'>,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem,\n) {\n return (context: Context): void => {\n // The direct tools stay only where exec cannot bind this non-portable namespace, which covers both.\n // Registered here rather than restricted, so the remote MCP load_skill and search_skills stay.\n const tools = [\n host.registerTool(createSessionLoadSkillTool(host)),\n host.registerTool(createSessionSearchSkillsTool(host)),\n ];\n const withdraw = () => {\n for (const tool of tools.splice(0)) tool.dispose();\n };\n context.effect(() => withdraw, 'session skill tools');\n context.inject([PO_CODEMODE_SERVICE, PO_ISOLATE_SERVICE], (bound) => {\n const codemode = readPoCodemode(bound);\n if (!codemode) return undefined;\n const registration = codemode.register(SKILL_NAMESPACE_SOURCE, createSkillNamespace(host, inventory, fs));\n // ponytail: the tools do not come back if code mode leaves mid-session; the next session has them.\n if (readPoIsolate(bound)?.liveObjects === true) withdraw();\n return () => registration.dispose();\n });\n };\n}\n","import type { PoHeadlessCommand, PoHeadlessCondition } from '@agimon-ai/po-core/headless';\nimport type { FileSystem } from '@agimon-ai/po-core/platform';\nimport type { Skill } from '@earendil-works/pi-coding-agent';\n\nimport { expandDeferredSkillCommand, type DeferredSkillSnapshot } from '../../../../../services/deferredSkills';\nimport type { ServerSkillGroup } from '../../../../../services/serverInventory';\nimport { groupConditions } from '../../../../../services/serverInventory/grouping';\nimport { SKILL_COMMAND_PREFIX, SKILL_INVOCATION_PREFIX, SKILLS_COMMAND } from '../../../../../types/skills';\n\n/**\n * One command per skill, gated by whatever activates that skill.\n *\n * Expansion always reads the full inventory, not the group: a command is only\n * dispatchable while its condition holds, so by the time one runs its skill is\n * active, and looking it up in the union keeps one lookup table instead of one\n * per domain.\n */\nfunction skillCommand(\n skill: Skill,\n when: PoHeadlessCondition | undefined,\n inventory: DeferredSkillSnapshot,\n fs: FileSystem | undefined,\n): PoHeadlessCommand {\n return {\n ...(when === undefined ? {} : { when }),\n name: `${SKILL_COMMAND_PREFIX}${skill.name}`,\n description: skill.description,\n execute: async (args, execution) => {\n const text = `${SKILL_INVOCATION_PREFIX}${skill.name}${args ? ` ${args}` : ''}`;\n const expanded = await expandDeferredSkillCommand(text, inventory.skills, fs);\n if (expanded === text) throw new Error(`Skill '${skill.name}' is no longer readable.`);\n await admit(execution.session, expanded);\n },\n };\n}\n\n/**\n * The dispatching prompt acks when this command returns, so awaiting the whole\n * turn (session.prompt) kept the composer draft until the run ended.\n */\nfunction admit(session: Parameters<PoHeadlessCommand['execute']>[1]['session'], text: string): Promise<void> {\n return session.admitPrompt ? session.admitPrompt(text, 'prompt', 'operator') : session.prompt(text);\n}\nexport function createSkillCommands(\n inventory: DeferredSkillSnapshot,\n catalog: string,\n groups: readonly ServerSkillGroup[],\n fs?: FileSystem,\n t: (key: string, fallback: string) => string = (_key, fallback) => fallback,\n): readonly PoHeadlessCommand[] {\n return [\n {\n name: SKILLS_COMMAND,\n description: 'List discovered skills or invoke one by name.',\n async execute(args, execution) {\n const requested = args.trim();\n if (requested) {\n await admit(\n execution.session,\n await expandDeferredSkillCommand(`${SKILL_INVOCATION_PREFIX}${requested}`, inventory.skills, fs),\n );\n return;\n }\n await execution.client.notify({\n title: t('skill.notification.catalog', 'Po skills'),\n localization: { title: { key: 'skill.notification.catalog', fallback: 'Po skills' } },\n body: catalog,\n level: 'info',\n });\n },\n },\n ...groups.flatMap((group) =>\n groupConditions(group).flatMap((when) => group.skills.map((skill) => skillCommand(skill, when, inventory, fs))),\n ),\n ];\n}\n","import { readHarnessState } from '@agimon-ai/po-config/harnessState';\nimport type { PoHeadlessHostService } from '@agimon-ai/po-core/headless';\nimport { PO_HELP_WHEN } from '@agimon-ai/po-core/help';\nimport { BACKGROUND_CONTEXT, getOrThrow, nodeHost, type FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n type PoServerResources,\n type PoServerSessionPlugin,\n packageResourcePath,\n readPackageResource,\n} from '@agimon-ai/po-core/serverPlugin';\n\nimport { SKILL_INVENTORY_FRESH_MS } from '../../../../../constants/skillInventory';\nimport { mountMcpSkills } from '../../../../../services/mcpSkills';\nimport { discoverServerSkills } from '../../../../../services/serverInventory';\nimport { groupConditions } from '../../../../../services/serverInventory/grouping';\nimport { mountSkillNamespace } from '../../../../../services/skillNamespace';\nimport { createSkillCommands } from './skillCommands';\n\nexport async function createSkillServer(\n agent: PoHeadlessHostService,\n fs: FileSystem,\n signal: AbortSignal,\n resources: PoServerResources,\n t?: (key: string, fallback: string) => string,\n): Promise<PoServerSessionPlugin> {\n const execution = agent.context;\n // Sessions with the same inputs share one discovery. The key holds every input discoverServerSkills\n // reads besides the disk, so equal keys give equal inventories, and the window bounds how old that\n // read of the disk can be.\n const key = [\n 'inventory',\n execution.repoRoot,\n execution.cwd,\n execution.environment.HOME ?? nodeHost.homeDirectory(),\n ...(readHarnessState(execution.environment).skillDirectories ?? []),\n Math.floor(Date.now() / SKILL_INVENTORY_FRESH_MS),\n ];\n const { inventory, catalog, groups, mcpGroups, relations } = await resources.acquire(key, () =>\n // Every session sharing the discovery waits on it, so none of their signals may abort it.\n discoverServerSkills(execution, fs, new AbortController().signal),\n );\n return {\n commands: createSkillCommands(inventory, catalog, groups, fs, t),\n services: [mountMcpSkills(mcpGroups, fs, signal), mountSkillNamespace(agent, inventory, fs)],\n resources: [\n // Each skill joins the prompt's one <available_skills> list, gated like the rest.\n ...groups.flatMap((group) =>\n groupConditions(group).flatMap((when) =>\n group.skills.map((skill) => ({\n name: skill.name,\n description: skill.description,\n path: skill.filePath,\n kind: 'skill' as const,\n ...(relations?.[skill.filePath] === undefined ? {} : { relations: relations[skill.filePath] }),\n ...(when === undefined ? {} : { when }),\n read: async () => getOrThrow(await fs.readTextFile(skill.filePath, BACKGROUND_CONTEXT)),\n })),\n ),\n ),\n ...[\n {\n name: 'help-how-to-author-skill',\n description:\n '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.',\n },\n {\n name: 'help-how-to-skill',\n description:\n \"Use Po's skill catalog and deferred discovery. Diagnose missing or shadowed skills and invoke the narrowest available guidance.\",\n },\n ].map((skill) => ({\n ...skill,\n when: PO_HELP_WHEN,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),\n read: () => readPackageResource(import.meta.url, `src/prompts/${skill.name}/SKILL.md`),\n })),\n ],\n };\n}\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\nimport { readPoLang, readPoPersonLocale } from '@agimon-ai/po-core/locale';\nimport { requirePoFs } from '@agimon-ai/po-core/platform';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nimport { createSkillServer } from './_lib/skillServer';\n\nexport default defineRoot(async ({ agent, context: root, signal, resources }: PoServerPluginContext) => {\n const runtime: PoServerSessionPlugin = agent\n ? await createSkillServer(\n agent,\n requirePoFs(root),\n signal,\n resources,\n (key, fallback) => readPoLang(root)?.t(readPoPersonLocale(root)?.read(), key, fallback) ?? fallback,\n )\n : { commands: [], resources: [] };\n return { value: runtime, services: runtime.services };\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.commands!,\n { cardinality: 'many' },\n);\n","// @scaffold-generated\nimport { defineResource } from '@agimon-ai/po-core/extensionFile';\nimport { packageResourcePath, readPackageResource } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineResource({\n name: 'codemode-how-to-skills',\n description:\n '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.',\n // A code-mode guide: listed in the system prompt, outside the searchable catalog.\n pinned: true,\n kind: 'skill' as const,\n path: packageResourcePath(import.meta.url, 'src/prompts/codemode-how-to-skills/SKILL.md'),\n read: () => readPackageResource(import.meta.url, 'src/prompts/codemode-how-to-skills/SKILL.md'),\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext, PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\n\nexport default defineRoutedContribution(\n (context: WithRoot<PoServerPluginContext, PoServerSessionPlugin>) => context.root.resources!,\n { cardinality: 'many' },\n);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverPlugin';\nimport { composeRootHooks, composeRootInjects } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport commandSkills from '../src/extensions/workspaces/sessions/(backend)/command/skills.server';\nimport resourceCodemodeHowToSkills from '../src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server';\nimport resourceSkills from '../src/extensions/workspaces/sessions/(backend)/resource/skills.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\ntype ManyFactory<T, C> = (context: C) => T | readonly T[];\nconst many = <T, C>(value: T | readonly T[] | ManyFactory<T, C>, context: C): readonly T[] => {\n const resolved = typeof value === 'function' ? (value as ManyFactory<T, C>)(context) : value;\n return Array.isArray(resolved) ? resolved : [resolved as T];\n};\n\nexport const serverPlugin = defineServerPlugin({\n name: '@agimon-ai/po-skill',\n providerOverrides: composeServerProviderOverrides(rootSession),\n injects: composeRootInjects({ session: [rootSession] }),\n session: async (context) => {\n const scopeSession = await context.scopeRoot('session', rootSession, context);\n const contextSession = { ...context, root: scopeSession.value };\n return {\n ...composeRootHooks(scopeSession),\n get commands(): PoServerSessionPlugin['commands'] { return [...many(commandSkills, contextSession)]; },\n get resources(): PoServerSessionPlugin['resources'] { return [at(resourceCodemodeHowToSkills, contextSession), ...many(resourceSkills, contextSession)]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): PoServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default serverPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAa,2BAA2B;;;ACCxC,MAAa,qBAAqB;;AAOlC,SAAgB,eAAe,QAAqC,IAAgB,QAAqB;CACvG,QAAQ,YAA2B;EACjC,QAAQ,QAAQ,oBAAoB,EAClC,KAAK,QAAQ;GACX,OAAO,eAAe;GACtB,OAAO,OAAO,eAAe;GAC7B,MAAM,UAAU,OAAO,UAAU,KAAK,CAAC,CAAC;GACxC,MAAM,yBAAS,IAAI,IAAwB;GAC3C,KAAK,MAAM,SAAS,QAAQ;IAC1B,IAAI,MAAM,YAAY,KAAA,KAAa,CAAC,MAAM,QAAQ,MAAM,WAAW,QAAQ,SAAS,MAAM,CAAC,GAAG;IAC9F,KAAK,MAAM,SAAS,MAAM,QAAQ;KAEhC,IAAI,OAAO,IAAI,MAAM,IAAI,GAAG;KAC5B,OAAO,IAAI,MAAM,MAAM;MACrB,MAAM,MAAM;MACZ,aAAa,MAAM;MACnB,MAAM,OAAO;OACX,MAAM,aAAa,YAAY,IAAI,CAAC,QAAQ,OAAO,MAAM,CAAC;OAC1D,WAAW,eAAe;OAC1B,MAAM,OAAO,WACX,MAAM,GAAG,aAAa,MAAM,UAAU,gBAAgB,YAAY,kBAAkB,CAAC,CACvF;O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AAc,OAA6C,YAA6B;CAC5F,MAAM,WAAW,OAAO,UAAU,aAAc,MAA4B,OAAO,IAAI;CACvF,OAAO,MAAM,QAAQ,QAAQ,IAAI,WAAW,CAAC,QAAa;AAC5D;AAEA,MAAa,eAAe,mBAAmB;CAC7C,MAAM;CACN,mBAAmB,+BAA+BA,mBAAW;CAC7D,SAAS,mBAAmB,EAAE,SAAS,CAACA,mBAAW,EAAE,CAAC;CACtD,SAAS,OAAO,YAAY;EAC1B,MAAM,eAAe,MAAM,QAAQ,UAAU,WAAWA,qBAAa,OAAO;EAC5E,MAAM,iBAAiB;GAAE,GAAG;GAAS,MAAM,aAAa;EAAM;EAC9D,OAAO;GACL,GAAG,iBAAiB,YAAY;GAChC,IAAI,WAA8C;IAAE,OAAO,CAAC,GAAG,KAAKC,yBAAe,cAAc,CAAC;GAAG;GACrG,IAAI,YAAgD;IAAE,OAAO,CAAC,GAAGC,uCAA6B,cAAc,GAAG,GAAG,KAAKC,uBAAgB,cAAc,CAAC;GAAG;GACzJ,UAAU,CAAC,GAAI,aAAa,YAAY,CAAC,CAAE;GAC3C,IAAI,aAAkD;IAAE,OAAO,CAAC,GAAI,aAAa,cAAc,CAAC,CAAE;GAAG;EACvG;CACF;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"platformRequirements":{},"sourceFiles":["LICENSE","README.md","generated/mcp-ui.ts","generated/mcp.ts","generated/native.ts","generated/server.ts","generated/web.ts","llms.txt","package.json","src/constants/skillInventory.ts","src/exports/apiContracts.ts","src/exports/catalog.ts","src/exports/index.ts","src/extensions/workspaces/sessions/(backend)/_lib/skillCommands.ts","src/extensions/workspaces/sessions/(backend)/_lib/skillServer.ts","src/extensions/workspaces/sessions/(backend)/command/skills.server.ts","src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts","src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts","src/extensions/workspaces/sessions/(backend)/root.server.ts","src/extensions/workspaces/sessions/(backend)/skill/discovered.mcp.ts","src/extensions/workspaces/sessions/(backend)/skill/help-how-to-author-skill.mcp.ts","src/extensions/workspaces/sessions/(backend)/skill/help-how-to-skill.mcp.ts","src/extensions/workspaces/sessions/(backend)/tool/load_skill.mcp.ts","src/extensions/workspaces/sessions/(backend)/tool/
|
|
1
|
+
{"version":1,"platformRequirements":{},"sourceFiles":["LICENSE","README.md","generated/mcp-ui.ts","generated/mcp.ts","generated/native.ts","generated/server.ts","generated/web.ts","llms.txt","package.json","src/constants/skillInventory.ts","src/exports/apiContracts.ts","src/exports/catalog.ts","src/exports/index.ts","src/extensions/workspaces/sessions/(backend)/_lib/skillCommands.ts","src/extensions/workspaces/sessions/(backend)/_lib/skillServer.ts","src/extensions/workspaces/sessions/(backend)/command/skills.server.ts","src/extensions/workspaces/sessions/(backend)/resource/codemode-how-to-skills.server.ts","src/extensions/workspaces/sessions/(backend)/resource/skills.server.ts","src/extensions/workspaces/sessions/(backend)/root.server.ts","src/extensions/workspaces/sessions/(backend)/skill/discovered.mcp.ts","src/extensions/workspaces/sessions/(backend)/skill/help-how-to-author-skill.mcp.ts","src/extensions/workspaces/sessions/(backend)/skill/help-how-to-skill.mcp.ts","src/extensions/workspaces/sessions/(backend)/tool/load_skill.mcp.ts","src/extensions/workspaces/sessions/(backend)/tool/search_skills.mcp.ts","src/extensions/workspaces/sessions/(frontend)/fill/Skills.help.guides.native.ts","src/extensions/workspaces/sessions/(frontend)/fill/Skills.help.guides.web.ts","src/extensions/workspaces/sessions/(frontend)/fill/_lib/helpGuides.ts","src/extensions/workspaces/sessions/(frontend)/tool/_components/LoadSkillToolMessage.native.stories.tsx","src/extensions/workspaces/sessions/(frontend)/tool/_components/LoadSkillToolMessage.native.tsx","src/extensions/workspaces/sessions/(frontend)/tool/_components/LoadSkillToolMessage.stories.tsx","src/extensions/workspaces/sessions/(frontend)/tool/_components/LoadSkillToolMessage.tsx","src/extensions/workspaces/sessions/(frontend)/tool/_components/SearchSkillsToolMessage.native.stories.tsx","src/extensions/workspaces/sessions/(frontend)/tool/_components/SearchSkillsToolMessage.native.tsx","src/extensions/workspaces/sessions/(frontend)/tool/_components/SearchSkillsToolMessage.stories.tsx","src/extensions/workspaces/sessions/(frontend)/tool/_components/SearchSkillsToolMessage.tsx","src/extensions/workspaces/sessions/(frontend)/tool/_lib/skillToolView.ts","src/extensions/workspaces/sessions/(frontend)/tool/load_skill.mcp.tsx","src/extensions/workspaces/sessions/(frontend)/tool/load_skill.native.tsx","src/extensions/workspaces/sessions/(frontend)/tool/load_skill.web.tsx","src/extensions/workspaces/sessions/(frontend)/tool/search_skills.mcp.tsx","src/extensions/workspaces/sessions/(frontend)/tool/search_skills.native.tsx","src/extensions/workspaces/sessions/(frontend)/tool/search_skills.web.tsx","src/prompts/codemode-how-to-skills/SKILL.md","src/prompts/help-how-to-author-skill/SKILL.md","src/prompts/help-how-to-skill/SKILL.md","src/schemas/apiContracts.ts","src/schemas/mcpSkillTools.ts","src/services/deferredSkills/index.edge.ts","src/services/deferredSkills/index.ts","src/services/mcpSkillTools/index.ts","src/services/mcpSkills/index.ts","src/services/serverInventory/catalog.ts","src/services/serverInventory/grouping.ts","src/services/serverInventory/index.edge.ts","src/services/serverInventory/index.ts","src/services/skillCatalog/index.ts","src/services/skillNamespace/index.ts","src/types/skills.ts","tsdown.config.ts"],"sourceRevision":"a193a7904c3861807b82cd842c3163c9","manifestRevision":"2354f906e75a7907504f9653fdac212c","outputFiles":["LICENSE","README.md","dist/apiContracts.cjs","dist/apiContracts.mjs","dist/catalog.cjs","dist/catalog.mjs","dist/extensions/mcp-ui.mjs","dist/extensions/mcp.cjs","dist/extensions/mcp.mjs","dist/extensions/native.mjs","dist/extensions/server.cjs","dist/extensions/server.mjs","dist/extensions/web.mjs","dist/index.cjs","dist/index.mjs","dist/rolldown-runtime-VH7oDXx4.cjs","dist/skills-Ccvg1Hcz.mjs","dist/skills-ComtgYb1.cjs","llms.txt","src/prompts/codemode-how-to-skills/SKILL.md","src/prompts/help-how-to-author-skill/SKILL.md","src/prompts/help-how-to-skill/SKILL.md"],"outputRevision":"5aee8bfbda1569f2f74a89a436963cb9"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/po-skill",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.209",
|
|
4
4
|
"description": "Session skill catalogue, deferred skill discovery, and the skill browser for Po.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-skills",
|
|
@@ -71,18 +71,18 @@
|
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@agimon-ai/po-config": "0.0.0-alpha.
|
|
75
|
-
"@agimon-ai/po-core": "0.0.0-alpha.
|
|
76
|
-
"@agimon-ai/po-domain": "0.0.0-alpha.
|
|
77
|
-
"@agimon-ai/po-web-components": "0.0.0-alpha.
|
|
74
|
+
"@agimon-ai/po-config": "0.0.0-alpha.209",
|
|
75
|
+
"@agimon-ai/po-core": "0.0.0-alpha.209",
|
|
76
|
+
"@agimon-ai/po-domain": "0.0.0-alpha.209",
|
|
77
|
+
"@agimon-ai/po-web-components": "0.0.0-alpha.209",
|
|
78
78
|
"@deepseek-ai/cordis": "4.0.5",
|
|
79
79
|
"gpt-tokenizer": "4.1.0",
|
|
80
80
|
"typebox": "1.4.2"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
|
-
"@agimon-ai/po-build": "0.0.0-alpha.
|
|
84
|
-
"@agimon-ai/po-native-components": "0.0.0-alpha.
|
|
85
|
-
"@agimon-ai/vibe-lint-plugin-po-extension": "0.0.0-alpha.
|
|
83
|
+
"@agimon-ai/po-build": "0.0.0-alpha.209",
|
|
84
|
+
"@agimon-ai/po-native-components": "0.0.0-alpha.209",
|
|
85
|
+
"@agimon-ai/vibe-lint-plugin-po-extension": "0.0.0-alpha.209",
|
|
86
86
|
"@deepseek-ai/cordis": "4.0.5",
|
|
87
87
|
"@earendil-works/pi-coding-agent": "1.6.1",
|
|
88
88
|
"@types/node": "26.6.5",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"vitest": "5.0.4"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
101
|
-
"@agimon-ai/po-native-components": "0.0.0-alpha.
|
|
101
|
+
"@agimon-ai/po-native-components": "0.0.0-alpha.209",
|
|
102
102
|
"@earendil-works/pi-coding-agent": "1.6.1",
|
|
103
103
|
"react-native": "0.88.1",
|
|
104
104
|
"react-native-unistyles": "^3.5.3"
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: codemode-how-to-skills
|
|
3
|
-
description: 'Search and
|
|
3
|
+
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.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# Find and read skills
|
|
7
7
|
|
|
8
|
-
The person picks domains to keep the prompt small
|
|
8
|
+
In code mode `skills.search` and `skills.load` replace the `search_skills` and `load_skill` tools. The prompt lists only pinned guides, so search for the rest. The person picks domains to keep the prompt small; search also reaches skills of domains they did not select, without asking them to switch.
|
|
9
9
|
|
|
10
|
-
-
|
|
10
|
+
- Load a listed skill with `skills.load({ name })` when its description matches the task.
|
|
11
11
|
- `skills.search({ query })` returns active skills first, then skills of domains in `domains.yaml` that this session has not selected. `active: false` marks the second kind. Use short, specific words; omit `query` only when you need the whole list.
|
|
12
12
|
- `skills.load({ name })` takes an exact name from search and returns the full SKILL.md text. Never pass a path.
|
|
13
13
|
- Reading a skill enables nothing. Its instructions may name tools, MCP servers or agents its plugin provides; those stay unavailable until the plugin is active. When the task needs them, ask to turn the plugin on with `plugins.enable` (see `codemode-how-to-plugins`) rather than improvising a substitute.
|
|
@@ -45,7 +45,7 @@ Pi Help descriptors carry only `name` and `description`. The Help service resolv
|
|
|
45
45
|
|
|
46
46
|
On the server host, contribute the same Help skill through a named `resource/*.server.ts` route with `when: PO_HELP_WHEN` from `@agimon-ai/po-core/help`. Include its useful description and an absolute `path` resolved with `packageResourcePath(import.meta.url, ...)`; a reader alone does not make the skill discoverable in the agent prompt. Keep ordinary runtime skills under their existing conditions.
|
|
47
47
|
|
|
48
|
-
Package-owned Help tools use ordinary named tool routes, not documentation descriptors. Server tools use the existing Help condition and execution guards. Pi tools also need `createPiHelpToolGate(packageName, toolNames)`: install its services and onStart in the owning root, then authorize each invocation with `gate.assertActive`. Portable `when` metadata alone does not enforce the Pi gate. The Help README and
|
|
48
|
+
Package-owned Help tools use ordinary named tool routes, not documentation descriptors. Server tools use the existing Help condition and execution guards. Pi tools also need `createPiHelpToolGate(packageName, toolNames)`: install its services and onStart in the owning root, then authorize each invocation with `gate.assertActive`. Portable `when` metadata alone does not enforce the Pi gate. The Help README and the Distribution package's `diagnose_setup` route show the complete server pattern. Bound diagnostics to the current session, omit secrets, and use existing approval mechanisms for repairs.
|
|
49
49
|
|
|
50
50
|
## Verification
|
|
51
51
|
|
|
@@ -7,7 +7,7 @@ description: Use Po's skill catalog and deferred discovery. Use when browsing av
|
|
|
7
7
|
|
|
8
8
|
Open the skill browser with `/skills` or `SPC e s`. The catalog groups normal session skills, package Help skills, plugin skills, and extension-contributed directories by owner.
|
|
9
9
|
|
|
10
|
-
For agent tool calls, use `load_skill` with the exact name. With at most 20 active skills, its description lists the names and descriptions. Above 20, use `search_skills` to find skills by name or description, then load the chosen name. Search returns metadata only, not skill instructions or paths.
|
|
10
|
+
For agent tool calls, use `load_skill` with the exact name. With at most 20 active skills, its description lists the names and descriptions. Above 20, use `search_skills` to find skills by name or description, then load the chosen name. Search returns metadata only, not skill instructions or paths. Where code mode binds live objects, both tools are replaced by `skills.search` and `skills.load` (see `codemode-how-to-skills`), and the prompt lists only pinned guides.
|
|
11
11
|
|
|
12
12
|
Invoke a skill with `/skill:<name>`. Po expands deferred skills before Pi handles the input, so a skill can be invokable even when its full body was not placed in the initial prompt. Help skills appear only while Help mode is active.
|
|
13
13
|
|