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