@unbrained/pm-cli 2026.8.26 → 2026.8.28
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/.agents/skills/HARNESS_COMPATIBILITY.md +32 -0
- package/.agents/skills/README.md +47 -0
- package/.agents/skills/pm-developer/SKILL.md +117 -0
- package/.agents/skills/pm-developer/references/COMMAND_PLAYBOOK.md +49 -0
- package/.agents/skills/pm-developer/references/GRAPH_AND_RELATIONSHIPS.md +91 -0
- package/.agents/skills/pm-developer/references/MULTI_AGENT_MERGE.md +72 -0
- package/.agents/skills/pm-developer/references/PROMPTS.md +17 -0
- package/.agents/skills/pm-developer/references/SCRIPTING_COMPOSITION.md +82 -0
- package/.agents/skills/pm-developer/references/TOKEN_BUDGETS.md +85 -0
- package/.agents/skills/pm-extensions/SKILL.md +106 -0
- package/.agents/skills/pm-extensions/references/AUTHORING.md +95 -0
- package/.agents/skills/pm-extensions/references/LIFECYCLE.md +40 -0
- package/.agents/skills/pm-extensions/references/TROUBLESHOOTING.md +25 -0
- package/.agents/skills/pm-sdk/SKILL.md +107 -0
- package/.agents/skills/pm-sdk/references/DOMAIN_MODELING.md +78 -0
- package/.agents/skills/pm-sdk/references/INTEGRATION_CHECKLIST.md +31 -0
- package/.agents/skills/pm-sdk/references/PROMPTS.md +13 -0
- package/.agents/skills/pm-sdk/references/SURFACE_MAP.md +82 -0
- package/.agents/skills/pm-user/SKILL.md +111 -0
- package/.agents/skills/pm-user/references/BACKLOG_SHAPING.md +105 -0
- package/.agents/skills/pm-user/references/PROMPTS.md +17 -0
- package/.agents/skills/pm-user/references/WORKFLOWS.md +35 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +50 -4
- package/README.md +8 -5
- package/dist/cli/commander-usage.js +11 -7
- package/dist/cli/error-guidance.js +62 -8
- package/dist/cli/help-content.d.ts +2 -0
- package/dist/cli/help-content.js +53 -17
- package/dist/cli/help-json-payload.d.ts +8 -2
- package/dist/cli/help-json-payload.js +46 -12
- package/dist/cli/main.js +52 -74
- package/dist/cli/register-annotations.js +83 -60
- package/dist/cli/register-setup.js +98 -57
- package/dist/cli-bundle/bundle-manifest.json +151 -151
- package/dist/cli-bundle/chunks/{chunk-UKBCRPA2.js → chunk-BY2FQ2NI.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-E73FDIWT.js +3 -0
- package/dist/cli-bundle/chunks/{chunk-WRHJ3MB6.js → chunk-FEVBFFCQ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-KBFP3E4E.js → chunk-M7OXRQE3.js} +66 -44
- package/dist/cli-bundle/chunks/{chunk-S4U76VZF.js → chunk-NBCBFVZI.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-ZNRLJ54C.js → chunk-NTXZHRKA.js} +45 -45
- package/dist/cli-bundle/chunks/chunk-QE6WQXFO.js +3 -0
- package/dist/cli-bundle/chunks/chunk-TIQ6AMH2.js +13 -0
- package/dist/cli-bundle/chunks/chunk-X2RROGZE.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-E2GCFJSU.js → chunk-XRVVYRRO.js} +33 -33
- package/dist/cli-bundle/chunks/chunk-XWEQGHHG.js +202 -0
- package/dist/cli-bundle/chunks/{register-list-query-EMCPMICY.js → register-list-query-J35ZPQQ5.js} +2 -2
- package/dist/cli-bundle/chunks/{register-mutation-OJ67ABCB.js → register-mutation-J6XJJOGU.js} +4 -4
- package/dist/cli-bundle/chunks/{register-operations-H2GLP7LT.js → register-operations-AE3JEMFT.js} +2 -2
- package/dist/cli-bundle/chunks/register-setup-OQERLLWE.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-72T6JGAE.js → chunk-4ZDRZYYJ.js} +43 -43
- package/dist/cli-bundle/focused-chunks/{chunk-OHIHZ7HS.js → chunk-6GCRSLPG.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-UYBA57GY.js → chunk-AD6ULRAF.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-FXDLT6FL.js → chunk-AHAM2HAU.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-LV5N3LK5.js → chunk-FC2AXLB5.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-IBHXMFE7.js → chunk-HC7ODMH3.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-4K2II4TV.js → chunk-HVQ22RC4.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-MMXUPDDJ.js → chunk-JZYPPMXF.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-LLNTHF5X.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-LYFWQMVC.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-A644DUFQ.js → chunk-MEASX544.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-YO3ZF3FI.js → chunk-THEPQMLX.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-57XY346D.js → chunk-XDPYBQCF.js} +9 -9
- package/dist/cli-bundle/focused-chunks/{chunk-TMJDFHVD.js → chunk-Y3JJXRVK.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-66VGB23P.js → chunk-Y5A7SJJ7.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-YJLDHJOD.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-P2E6LDAE.js → chunk-YVVZ3LQ6.js} +3 -3
- package/dist/cli-bundle/focused-chunks/chunk-Z2USIBR2.js +5 -0
- package/dist/cli-bundle/main.js +15 -14
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +2 -2
- package/dist/cli-bundle/sdk-core.js +31 -31
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +31 -31
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +32 -7
- package/dist/core/governance/issue-codes.d.ts +11 -2
- package/dist/core/governance/issue-codes.js +29 -10
- package/dist/core/item/item-format.js +3 -3
- package/dist/core/store/item-store.js +12 -5
- package/dist/mcp/server.js +123 -9
- package/dist/mcp/tool-definitions.d.ts +2 -0
- package/dist/mcp/tool-definitions.js +5 -5
- package/dist/sdk/agent/closed-domain-contracts.d.ts +1 -1
- package/dist/sdk/agent/closed-domain-contracts.js +24 -2
- package/dist/sdk/agent/command-recovery.js +3 -3
- package/dist/sdk/agent/task-transcript-contracts.d.ts +52 -0
- package/dist/sdk/agent/task-transcript-contracts.js +198 -0
- package/dist/sdk/agent-capability-contracts.js +6 -2
- package/dist/sdk/annotations.d.ts +5 -2
- package/dist/sdk/annotations.js +66 -36
- package/dist/sdk/cli-bootstrap.d.ts +2 -8
- package/dist/sdk/cli-bootstrap.js +7 -66
- package/dist/sdk/cli-contracts/bootstrap-command-scanner.d.ts +23 -0
- package/dist/sdk/cli-contracts/bootstrap-command-scanner.js +80 -0
- package/dist/sdk/cli-contracts/command-aliases.js +15 -2
- package/dist/sdk/cli-contracts/enum-contracts.d.ts +4 -1
- package/dist/sdk/cli-contracts/enum-contracts.js +7 -2
- package/dist/sdk/cli-contracts/flag-contracts.js +12 -5
- package/dist/sdk/cli-contracts/flag-lexicon-contracts.js +5 -5
- package/dist/sdk/cli-contracts/grammar-contracts.d.ts +3 -3
- package/dist/sdk/cli-contracts/grammar-contracts.js +24 -17
- package/dist/sdk/cli-contracts/runtime-contracts.js +13 -11
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +15 -2
- package/dist/sdk/cli-contracts/tool-schema.d.ts +1 -1
- package/dist/sdk/cli-contracts/tool-schema.js +32 -16
- package/dist/sdk/cli-contracts.d.ts +1 -1
- package/dist/sdk/cli-contracts.js +3 -3
- package/dist/sdk/cli-program.js +3 -2
- package/dist/sdk/comments.d.ts +4 -0
- package/dist/sdk/comments.js +2 -2
- package/dist/sdk/completion.js +47 -16
- package/dist/sdk/contracts.d.ts +1 -0
- package/dist/sdk/contracts.js +3 -2
- package/dist/sdk/extension/install-sources.d.ts +13 -0
- package/dist/sdk/extension/install-sources.js +62 -30
- package/dist/sdk/generated/generated-error-code-catalog-part-1.js +26 -2
- package/dist/sdk/generated/generated-error-code-catalog-part-2.js +38 -14
- package/dist/sdk/governance/upgrade.d.ts +2 -0
- package/dist/sdk/governance/upgrade.js +30 -8
- package/dist/sdk/governance/validate.js +8 -6
- package/dist/sdk/guide-topics.js +6 -6
- package/dist/sdk/index.d.ts +5 -2
- package/dist/sdk/index.js +6 -3
- package/dist/sdk/learnings.d.ts +4 -0
- package/dist/sdk/learnings.js +7 -4
- package/dist/sdk/lifecycle/close.js +4 -3
- package/dist/sdk/mcp/apps.d.ts +70 -0
- package/dist/sdk/mcp/apps.js +154 -0
- package/dist/sdk/mcp/skills.d.ts +127 -0
- package/dist/sdk/mcp/skills.js +390 -0
- package/dist/sdk/notes.d.ts +4 -0
- package/dist/sdk/notes.js +2 -2
- package/dist/sdk/read-output-contracts.js +16 -3
- package/dist/sdk/runtime-action-aliases.js +7 -3
- package/dist/sdk/runtime-input.js +15 -4
- package/dist/sdk/runtime-primitives.d.ts +1 -1
- package/dist/sdk/runtime-primitives.js +3 -3
- package/dist/sdk/runtime.d.ts +6 -6
- package/dist/sdk/runtime.js +8 -8
- package/docs/CLI_GRAMMAR.md +7 -1
- package/docs/COMMANDS.md +5 -4
- package/docs/EXTENSIONS.md +33 -32
- package/docs/MCP_2026_07_28.md +24 -2
- package/docs/MCP_2026_07_28_CONFORMANCE.md +4 -4
- package/docs/MCP_SKILLS_AND_APPS.md +107 -0
- package/docs/OUTPUT_TOKEN_ACCOUNTING.md +20 -7
- package/docs/QUICKSTART.md +15 -15
- package/docs/README.md +1 -0
- package/docs/RELEASING.md +20 -4
- package/docs/SDK.md +12 -0
- package/docs/SDK_CONTEXT_INTEGRITY.md +18 -1
- package/docs/SDK_EVIDENCE_TRACEABILITY.md +9 -1
- package/docs/SDK_RUNTIME_BOUNDARIES.md +10 -0
- package/docs/TESTING.md +6 -2
- package/docs/agent-task-token-baseline.json +97 -11
- package/docs/agent-task-transcripts.json +211 -0
- package/docs/generated/AGENT_CAPABILITY_ROUTING.md +1 -1
- package/docs/generated/FLAG_LEXICON_BUDGETS.md +3 -3
- package/docs/generated/REFUSAL_CLOSURE_CENSUS.md +11 -7
- package/docs/performance/cli-transport-overhead.md +10 -2
- package/marketplace.json +2 -2
- package/package.json +10 -8
- package/packages/pm-beads/README.md +12 -6
- package/packages/pm-beads/docs/MIGRATION.md +53 -0
- package/packages/pm-beads/extensions/beads/index.ts +8 -0
- package/packages/pm-beads/extensions/beads/runtime.ts +671 -112
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-digital-twin/package.json +1 -1
- package/packages/pm-governance-audit/package.json +1 -1
- package/packages/pm-guide-shell/package.json +1 -1
- package/packages/pm-kanban/package.json +1 -1
- package/packages/pm-lifecycle-hooks/package.json +1 -1
- package/packages/pm-linked-test-adapters/package.json +1 -1
- package/packages/pm-search-advanced/package.json +1 -1
- package/packages/pm-templates/package.json +1 -1
- package/packages/pm-todos/package.json +1 -1
- package/packages/pm-vcs/package.json +1 -1
- package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/sdk/public-surface.json +430 -36
- package/dist/cli-bundle/chunks/chunk-ES25LX3D.js +0 -202
- package/dist/cli-bundle/chunks/chunk-FRDWWB6R.js +0 -3
- package/dist/cli-bundle/chunks/chunk-ICQ3RVIY.js +0 -2
- package/dist/cli-bundle/chunks/chunk-IV64RJVE.js +0 -13
- package/dist/cli-bundle/chunks/chunk-MVYLQ67M.js +0 -3
- package/dist/cli-bundle/chunks/register-setup-GLZAHLVI.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-4XNH2HM7.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-7I23XGWO.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-7YCDTCBC.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-LMKG3DFE.js +0 -5
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e6c49c89-781e-59a3-9c19-6a1c40424587")}catch(e){}}();
|
|
3
|
+
import { PM_MCP_ERROR_CODES, PmMcpProtocolError, isMcpRecord, } from "./protocol.js";
|
|
4
|
+
/** Stable MCP Apps extension identifier. */
|
|
5
|
+
export const PM_MCP_APPS_EXTENSION = "io.modelcontextprotocol/ui";
|
|
6
|
+
/** Stable MCP Apps specification revision implemented by pm. */
|
|
7
|
+
export const PM_MCP_APPS_SPEC_VERSION = "2026-01-26";
|
|
8
|
+
/** Official MIME type for MCP App HTML resources. */
|
|
9
|
+
export const PM_MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
|
|
10
|
+
/** Server-side MCP Apps capability advertised through discovery. */
|
|
11
|
+
export const PM_MCP_APPS_SERVER_CAPABILITY = Object.freeze({
|
|
12
|
+
specVersion: PM_MCP_APPS_SPEC_VERSION,
|
|
13
|
+
mimeTypes: [PM_MCP_APP_MIME_TYPE],
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Resolve whether a request negotiated MCP Apps, rejecting malformed explicit
|
|
17
|
+
* declarations instead of silently serving a different extension revision.
|
|
18
|
+
*/
|
|
19
|
+
export function hasPmMcpAppsCapability(context) {
|
|
20
|
+
const extensions = context.clientCapabilities.extensions;
|
|
21
|
+
if (!isMcpRecord(extensions))
|
|
22
|
+
return false;
|
|
23
|
+
const declaration = extensions[PM_MCP_APPS_EXTENSION];
|
|
24
|
+
if (declaration === undefined)
|
|
25
|
+
return false;
|
|
26
|
+
if (!isMcpRecord(declaration)) {
|
|
27
|
+
throw new PmMcpProtocolError("Invalid MCP Apps client capability", PM_MCP_ERROR_CODES.missingRequiredClientCapability, { requiredCapabilities: { extensions: { [PM_MCP_APPS_EXTENSION]: PM_MCP_APPS_SERVER_CAPABILITY } } });
|
|
28
|
+
}
|
|
29
|
+
const mimeTypes = declaration.mimeTypes;
|
|
30
|
+
const specVersion = declaration.specVersion;
|
|
31
|
+
if (!Array.isArray(mimeTypes) ||
|
|
32
|
+
!mimeTypes.includes(PM_MCP_APP_MIME_TYPE) ||
|
|
33
|
+
(specVersion !== undefined && specVersion !== PM_MCP_APPS_SPEC_VERSION)) {
|
|
34
|
+
throw new PmMcpProtocolError("Unsupported MCP Apps client capability", PM_MCP_ERROR_CODES.missingRequiredClientCapability, { requiredCapabilities: { extensions: { [PM_MCP_APPS_EXTENSION]: PM_MCP_APPS_SERVER_CAPABILITY } } });
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
const PRIVATE_APP_RESOURCE_META = {
|
|
39
|
+
csp: { connectDomains: [], resourceDomains: [], frameDomains: [] },
|
|
40
|
+
permissions: {},
|
|
41
|
+
prefersBorder: true,
|
|
42
|
+
};
|
|
43
|
+
/** Canonical optional pm MCP Apps. */
|
|
44
|
+
export const PM_MCP_APP_CONTRACTS = Object.freeze([
|
|
45
|
+
{
|
|
46
|
+
id: "context",
|
|
47
|
+
name: "Context explorer",
|
|
48
|
+
description: "Inspect bounded project context, provenance, omissions, and token accounting.",
|
|
49
|
+
toolName: "pm_context",
|
|
50
|
+
uri: "ui://pm/context.html",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "graph",
|
|
54
|
+
name: "Relationship graph",
|
|
55
|
+
description: "Explore typed relationships, explaining paths, and graph-governance evidence.",
|
|
56
|
+
toolName: "pm_graph",
|
|
57
|
+
uri: "ui://pm/graph.html",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "plan",
|
|
61
|
+
name: "Plan and milestone view",
|
|
62
|
+
description: "Review durable plan steps, dependencies, decisions, discoveries, and validation state.",
|
|
63
|
+
toolName: "pm_plan",
|
|
64
|
+
uri: "ui://pm/plan.html",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "assurance",
|
|
68
|
+
name: "Assurance dashboard",
|
|
69
|
+
description: "Inspect validation verdicts, evidence, omissions, and actionable recovery paths.",
|
|
70
|
+
toolName: "pm_validate",
|
|
71
|
+
uri: "ui://pm/assurance.html",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: "operations",
|
|
75
|
+
name: "Long-operation view",
|
|
76
|
+
description: "Inspect durable test and operation results without creating a second task store.",
|
|
77
|
+
toolName: "pm_test",
|
|
78
|
+
uri: "ui://pm/operations.html",
|
|
79
|
+
},
|
|
80
|
+
].map((contract) => ({
|
|
81
|
+
...contract,
|
|
82
|
+
toolMeta: {
|
|
83
|
+
resourceUri: contract.uri,
|
|
84
|
+
visibility: ["model", "app"],
|
|
85
|
+
},
|
|
86
|
+
resourceMeta: PRIVATE_APP_RESOURCE_META,
|
|
87
|
+
})));
|
|
88
|
+
/** Return the app contract for a resource URI. */
|
|
89
|
+
export function findPmMcpAppByUri(uri) {
|
|
90
|
+
return PM_MCP_APP_CONTRACTS.find((contract) => contract.uri === uri);
|
|
91
|
+
}
|
|
92
|
+
/** Attach negotiated MCP App metadata to matching tool definitions. */
|
|
93
|
+
export function decoratePmMcpToolsWithApps(tools) {
|
|
94
|
+
const appsByTool = new Map(PM_MCP_APP_CONTRACTS.map((contract) => [contract.toolName, contract]));
|
|
95
|
+
return tools.map((tool) => {
|
|
96
|
+
const app = appsByTool.get(tool.name);
|
|
97
|
+
return app
|
|
98
|
+
? {
|
|
99
|
+
...tool,
|
|
100
|
+
_meta: { ...tool._meta, ui: app.toolMeta },
|
|
101
|
+
}
|
|
102
|
+
: { ...tool };
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function escapeHtml(value) {
|
|
106
|
+
return value
|
|
107
|
+
.replaceAll("&", "&")
|
|
108
|
+
.replaceAll("<", "<")
|
|
109
|
+
.replaceAll(">", ">")
|
|
110
|
+
.replaceAll('"', """)
|
|
111
|
+
.replaceAll("'", "'");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Render a self-contained, sandbox-compatible MCP App document.
|
|
115
|
+
*
|
|
116
|
+
* The view keeps no durable state and exposes no mutation control. It receives
|
|
117
|
+
* the authoritative tool input/result from the host, bounds large rendering,
|
|
118
|
+
* and presents the text fallback when structured content is unavailable.
|
|
119
|
+
*/
|
|
120
|
+
export function renderPmMcpAppHtml(contract) {
|
|
121
|
+
const title = escapeHtml(contract.name);
|
|
122
|
+
const description = escapeHtml(contract.description);
|
|
123
|
+
const appInfo = JSON.stringify({
|
|
124
|
+
name: `pm-${contract.id}-view`,
|
|
125
|
+
version: PM_MCP_APPS_SPEC_VERSION,
|
|
126
|
+
});
|
|
127
|
+
const protocolVersion = JSON.stringify(PM_MCP_APPS_SPEC_VERSION);
|
|
128
|
+
return `<!doctype html>
|
|
129
|
+
<html lang="en">
|
|
130
|
+
<head>
|
|
131
|
+
<meta charset="utf-8">
|
|
132
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
133
|
+
<title>${title}</title>
|
|
134
|
+
<style>
|
|
135
|
+
:root{color-scheme:light dark;--ink:#172554;--muted:#526078;--panel:#f8fafc;--line:#cbd5e1;--signal:#0f766e;--accent:#4338ca;--danger:#b91c1c;font-family:Inter,ui-sans-serif,system-ui,sans-serif}
|
|
136
|
+
@media(prefers-color-scheme:dark){:root{--ink:#e0e7ff;--muted:#a8b3c7;--panel:#111827;--line:#334155;--signal:#5eead4;--accent:#a5b4fc;--danger:#fca5a5}}
|
|
137
|
+
*{box-sizing:border-box}body{margin:0;background:var(--panel);color:var(--ink)}main{display:grid;gap:1rem;padding:clamp(.9rem,3vw,1.5rem);max-width:76rem;margin:auto}header{display:grid;gap:.35rem;border-bottom:1px solid var(--line);padding-bottom:.8rem}h1{font-size:clamp(1.2rem,3vw,1.75rem);line-height:1.1;margin:0;letter-spacing:-.02em}p{margin:0;color:var(--muted);line-height:1.5}.status{display:flex;align-items:center;gap:.5rem;font:600 .75rem ui-monospace,monospace;text-transform:uppercase;letter-spacing:.06em}.status::before{content:"";width:.55rem;height:.55rem;border-radius:50%;background:var(--signal)}section{border:1px solid var(--line);border-radius:.8rem;padding:1rem;background:color-mix(in srgb,var(--panel) 92%,var(--accent) 8%)}h2{font-size:.75rem;text-transform:uppercase;letter-spacing:.08em;margin:0 0 .7rem;color:var(--accent)}pre{white-space:pre-wrap;overflow-wrap:anywhere;max-height:34rem;overflow:auto;margin:0;font:500 .78rem/1.55 ui-monospace,SFMono-Regular,monospace;tab-size:2}button{justify-self:start;border:1px solid var(--accent);border-radius:.45rem;background:transparent;color:var(--accent);padding:.55rem .75rem;font:600 .78rem inherit;cursor:pointer}button:focus-visible{outline:3px solid var(--signal);outline-offset:2px}.notice{color:var(--danger)}@media(max-width:40rem){main{padding:.75rem}section{padding:.8rem}pre{max-height:24rem}}@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important;transition:none!important}}
|
|
138
|
+
</style>
|
|
139
|
+
</head>
|
|
140
|
+
<body>
|
|
141
|
+
<main>
|
|
142
|
+
<header><div class="status" id="status" role="status" aria-live="polite">Connecting to host</div><h1>${title}</h1><p>${description}</p></header>
|
|
143
|
+
<section aria-labelledby="summary-title"><h2 id="summary-title">Authoritative result</h2><pre id="result" tabindex="0">Waiting for the host tool result…</pre></section>
|
|
144
|
+
<section aria-labelledby="input-title"><h2 id="input-title">Invocation context</h2><pre id="input" tabindex="0">No tool input received.</pre></section>
|
|
145
|
+
<button type="button" id="copy">Copy visible evidence</button>
|
|
146
|
+
</main>
|
|
147
|
+
<script>
|
|
148
|
+
(()=>{"use strict";const MAX=24000,status=document.querySelector("#status"),result=document.querySelector("#result"),input=document.querySelector("#input"),pending=new Map();let nextId=1;const render=(node,value)=>{let text;try{text=typeof value==="string"?value:JSON.stringify(value,null,2)}catch{text="Result could not be serialized."}if(text.length>MAX)text=text.slice(0,MAX)+"\\n\\n[View truncated at "+MAX+" characters; use the authoritative pm tool with a cursor or narrower projection.]";node.textContent=text};const send=(message)=>window.parent.postMessage(message,"*");window.addEventListener("message",event=>{if(event.source!==window.parent||!event.data||event.data.jsonrpc!=="2.0")return;const message=event.data;if(message.id!==undefined&&pending.has(message.id)){pending.get(message.id)(message);pending.delete(message.id);return}if(message.method==="ui/notifications/tool-input"||message.method==="ui/notifications/tool-input-partial"){render(input,message.params?.arguments??message.params);status.textContent="Input received"}else if(message.method==="ui/notifications/tool-result"){render(result,message.params);status.textContent="Current tool result"}else if(message.method==="ui/notifications/tool-cancelled"){status.textContent="Tool call cancelled";status.classList.add("notice")}else if(message.method==="ui/notifications/host-context-changed"&&message.params?.theme){document.documentElement.style.colorScheme=message.params.theme}});const request=(method,params)=>new Promise(resolve=>{const id=nextId++;pending.set(id,resolve);send({jsonrpc:"2.0",id,method,params})});document.querySelector("#copy").addEventListener("click",async()=>{const text=result.textContent+"\\n\\n"+input.textContent;try{await navigator.clipboard.writeText(text);status.textContent="Visible evidence copied"}catch{status.textContent="Clipboard permission unavailable";status.classList.add("notice")}});request("ui/initialize",{appInfo:${appInfo},appCapabilities:{},protocolVersion:${protocolVersion}}).then(message=>{if(message.error){status.textContent="Host rejected MCP App initialization";status.classList.add("notice");return}send({jsonrpc:"2.0",method:"ui/notifications/initialized"});status.textContent="Connected — awaiting authoritative result"})})();
|
|
149
|
+
</script>
|
|
150
|
+
</body>
|
|
151
|
+
</html>`;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=apps.js.map
|
|
154
|
+
//# debugId=e6c49c89-781e-59a3-9c19-6a1c40424587
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { PM_MCP_PROTOCOL_VERSION, type PmMcpRequestContext } from "./protocol.js";
|
|
2
|
+
/** Draft extension identifier proposed by SEP-2640. */
|
|
3
|
+
export declare const PM_MCP_SKILLS_EXTENSION: "io.modelcontextprotocol/skills";
|
|
4
|
+
/** Exact draft proposal revision implemented by pm. */
|
|
5
|
+
export declare const PM_MCP_SKILLS_DRAFT_REVISION: "SEP-2640@a3e147ca2710f68214247aecc729731ee1ae8d03";
|
|
6
|
+
/** Server-side draft capability advertised through discovery. */
|
|
7
|
+
export declare const PM_MCP_SKILLS_SERVER_CAPABILITY: Readonly<{
|
|
8
|
+
revision: "SEP-2640@a3e147ca2710f68214247aecc729731ee1ae8d03";
|
|
9
|
+
status: "draft";
|
|
10
|
+
directoryRead: true;
|
|
11
|
+
}>;
|
|
12
|
+
/** Require exact draft negotiation for a skills method. */
|
|
13
|
+
export declare function assertPmMcpSkillsCapability(context: PmMcpRequestContext, directoryRead?: boolean): void;
|
|
14
|
+
/** Security and context limits applied independently to every skill origin. */
|
|
15
|
+
export declare const PM_MCP_SKILL_LIMITS: Readonly<{
|
|
16
|
+
maxFilesPerSkill: 512;
|
|
17
|
+
maxFileBytes: number;
|
|
18
|
+
maxSkillBytes: number;
|
|
19
|
+
defaultPageSize: 20;
|
|
20
|
+
maxPageSize: 100;
|
|
21
|
+
}>;
|
|
22
|
+
/** Origin from which a skill was loaded. */
|
|
23
|
+
export type PmMcpSkillOrigin = "package" | "workspace";
|
|
24
|
+
/** One immutable file advertised by a skill. */
|
|
25
|
+
export interface PmMcpSkillResource {
|
|
26
|
+
/** Addressable skill resource URI. */
|
|
27
|
+
uri: string;
|
|
28
|
+
/** SEP-2640 SHA-256 digest of the exact bytes returned by reads. */
|
|
29
|
+
digest: string;
|
|
30
|
+
/** Exact byte length. */
|
|
31
|
+
size: number;
|
|
32
|
+
}
|
|
33
|
+
/** Discoverable skill descriptor from the current SEP draft. */
|
|
34
|
+
export interface PmMcpSkillDescriptor {
|
|
35
|
+
/** URI of the skill's mandatory SKILL.md. */
|
|
36
|
+
uri: string;
|
|
37
|
+
/** Parsed, verbatim frontmatter object. */
|
|
38
|
+
frontmatter: Record<string, unknown>;
|
|
39
|
+
/** Every bounded file in the skill directory. */
|
|
40
|
+
resources: PmMcpSkillResource[];
|
|
41
|
+
/** pm-specific compatibility and trust provenance. */
|
|
42
|
+
_meta: {
|
|
43
|
+
contractVersion: 1;
|
|
44
|
+
extensionRevision: typeof PM_MCP_SKILLS_DRAFT_REVISION;
|
|
45
|
+
origin: PmMcpSkillOrigin;
|
|
46
|
+
packageVersion: string;
|
|
47
|
+
protocolVersion: typeof PM_MCP_PROTOCOL_VERSION;
|
|
48
|
+
trust: "untrusted";
|
|
49
|
+
estimatedTokens: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Inputs for loading the canonical package skills plus repository overrides. */
|
|
53
|
+
export interface LoadPmMcpSkillsOptions {
|
|
54
|
+
/** pm package root containing `.agents/skills`. */
|
|
55
|
+
packageRoot: string;
|
|
56
|
+
/** Workspace root whose `.agents/skills` override package skills by name. */
|
|
57
|
+
workspaceRoot?: string;
|
|
58
|
+
/** Exact package version included in compatibility metadata. */
|
|
59
|
+
packageVersion: string;
|
|
60
|
+
}
|
|
61
|
+
/** List request inputs with opaque cursor pagination. */
|
|
62
|
+
export interface ListPmMcpSkillsOptions {
|
|
63
|
+
/** Opaque cursor returned by a previous page. */
|
|
64
|
+
cursor?: string;
|
|
65
|
+
/** Requested page size, bounded to 100. */
|
|
66
|
+
limit?: number;
|
|
67
|
+
}
|
|
68
|
+
/** One deterministic list page. */
|
|
69
|
+
export interface ListPmMcpSkillsResult {
|
|
70
|
+
/** Skills in lexical URI order. */
|
|
71
|
+
skills: PmMcpSkillDescriptor[];
|
|
72
|
+
/** Opaque continuation cursor when more skills exist. */
|
|
73
|
+
nextCursor?: string;
|
|
74
|
+
/** Explicit completeness signal. */
|
|
75
|
+
hasMore: boolean;
|
|
76
|
+
}
|
|
77
|
+
/** Exact read result for one skill resource. */
|
|
78
|
+
export interface ReadPmMcpSkillResourceResult {
|
|
79
|
+
/** Resource content returned as UTF-8 text or lossless Base64 bytes. */
|
|
80
|
+
contents: Array<{
|
|
81
|
+
uri: string;
|
|
82
|
+
mimeType: "text/markdown" | "text/plain";
|
|
83
|
+
text: string;
|
|
84
|
+
_meta: {
|
|
85
|
+
digest: string;
|
|
86
|
+
origin: PmMcpSkillOrigin;
|
|
87
|
+
trust: "untrusted";
|
|
88
|
+
};
|
|
89
|
+
} | {
|
|
90
|
+
uri: string;
|
|
91
|
+
mimeType: "application/octet-stream";
|
|
92
|
+
blob: string;
|
|
93
|
+
_meta: {
|
|
94
|
+
digest: string;
|
|
95
|
+
origin: PmMcpSkillOrigin;
|
|
96
|
+
trust: "untrusted";
|
|
97
|
+
};
|
|
98
|
+
}>;
|
|
99
|
+
}
|
|
100
|
+
/** Direct-child directory listing defined by the current SEP draft. */
|
|
101
|
+
export interface ReadPmMcpSkillDirectoryResult {
|
|
102
|
+
/** Direct child file and directory resources in lexical URI order. */
|
|
103
|
+
resources: Array<{
|
|
104
|
+
uri: string;
|
|
105
|
+
name: string;
|
|
106
|
+
mimeType: "application/octet-stream" | "inode/directory" | "text/markdown" | "text/plain";
|
|
107
|
+
}>;
|
|
108
|
+
/** Opaque continuation cursor when more direct children exist. */
|
|
109
|
+
nextCursor?: string;
|
|
110
|
+
/** Explicit completeness signal for this directory page. */
|
|
111
|
+
hasMore: boolean;
|
|
112
|
+
}
|
|
113
|
+
/** Immutable in-memory registry for one request's package/workspace origins. */
|
|
114
|
+
export declare class PmMcpSkillRegistry {
|
|
115
|
+
#private;
|
|
116
|
+
private constructor();
|
|
117
|
+
/** Load package skills and apply validated workspace overrides by name. */
|
|
118
|
+
static load(options: LoadPmMcpSkillsOptions): Promise<PmMcpSkillRegistry>;
|
|
119
|
+
/** List skills in deterministic pages without loading file bodies. */
|
|
120
|
+
list(options?: ListPmMcpSkillsOptions): ListPmMcpSkillsResult;
|
|
121
|
+
/** Get one skill descriptor by its SKILL.md URI. */
|
|
122
|
+
get(uri: string): PmMcpSkillDescriptor;
|
|
123
|
+
/** Read one digest-bound skill resource without following filesystem links. */
|
|
124
|
+
read(uri: string): ReadPmMcpSkillResourceResult;
|
|
125
|
+
/** List one directory's direct children with opaque cursor pagination. */
|
|
126
|
+
readDirectory(uri: string, options?: ListPmMcpSkillsOptions): ReadPmMcpSkillDirectoryResult;
|
|
127
|
+
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module sdk/mcp/skills
|
|
3
|
+
*
|
|
4
|
+
* Implements pm's draft Skills over MCP registry with bounded filesystem
|
|
5
|
+
* discovery, per-file digests, origin provenance, pagination, and fail-closed
|
|
6
|
+
* revision negotiation.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5f60bc89-c81b-57ee-a8f2-0d0b18d0af1b")}catch(e){}}();
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { lstat, readdir, readFile } from "node:fs/promises";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { parseDocument } from "yaml";
|
|
14
|
+
import { isFileAbsentError } from "../../core/fs/fs-utils.js";
|
|
15
|
+
import { PM_MCP_ERROR_CODES, PM_MCP_PROTOCOL_VERSION, PmMcpProtocolError, isMcpRecord, } from "./protocol.js";
|
|
16
|
+
/** Draft extension identifier proposed by SEP-2640. */
|
|
17
|
+
export const PM_MCP_SKILLS_EXTENSION = "io.modelcontextprotocol/skills";
|
|
18
|
+
/** Exact draft proposal revision implemented by pm. */
|
|
19
|
+
export const PM_MCP_SKILLS_DRAFT_REVISION = "SEP-2640@a3e147ca2710f68214247aecc729731ee1ae8d03";
|
|
20
|
+
/** Server-side draft capability advertised through discovery. */
|
|
21
|
+
export const PM_MCP_SKILLS_SERVER_CAPABILITY = Object.freeze({
|
|
22
|
+
revision: PM_MCP_SKILLS_DRAFT_REVISION,
|
|
23
|
+
status: "draft",
|
|
24
|
+
directoryRead: true,
|
|
25
|
+
});
|
|
26
|
+
/** Require exact draft negotiation for a skills method. */
|
|
27
|
+
export function assertPmMcpSkillsCapability(context, directoryRead = false) {
|
|
28
|
+
const extensions = context.clientCapabilities.extensions;
|
|
29
|
+
const declaration = isMcpRecord(extensions)
|
|
30
|
+
? extensions[PM_MCP_SKILLS_EXTENSION]
|
|
31
|
+
: undefined;
|
|
32
|
+
if (!isMcpRecord(declaration) ||
|
|
33
|
+
declaration.revision !== PM_MCP_SKILLS_DRAFT_REVISION ||
|
|
34
|
+
(directoryRead && declaration.directoryRead !== true)) {
|
|
35
|
+
throw new PmMcpProtocolError("Missing or incompatible Skills over MCP draft capability", PM_MCP_ERROR_CODES.missingRequiredClientCapability, {
|
|
36
|
+
requiredCapabilities: {
|
|
37
|
+
extensions: {
|
|
38
|
+
[PM_MCP_SKILLS_EXTENSION]: PM_MCP_SKILLS_SERVER_CAPABILITY,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Security and context limits applied independently to every skill origin. */
|
|
45
|
+
export const PM_MCP_SKILL_LIMITS = Object.freeze({
|
|
46
|
+
maxFilesPerSkill: 512,
|
|
47
|
+
maxFileBytes: 16 * 1024 * 1024,
|
|
48
|
+
maxSkillBytes: 16 * 1024 * 1024,
|
|
49
|
+
defaultPageSize: 20,
|
|
50
|
+
maxPageSize: 100,
|
|
51
|
+
});
|
|
52
|
+
const MAX_MCP_SKILLS_PER_ORIGIN = 100;
|
|
53
|
+
const MAX_MCP_SKILL_ORIGIN_BYTES = 32 * 1024 * 1024;
|
|
54
|
+
const SKILL_NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
55
|
+
const SKILL_PAGE_SIZES = new Set(Array.from({ length: PM_MCP_SKILL_LIMITS.maxPageSize }, (_, index) => index + 1));
|
|
56
|
+
function skillError(message, data) {
|
|
57
|
+
throw new PmMcpProtocolError(message, -32602, data);
|
|
58
|
+
}
|
|
59
|
+
function skillFileMimeType(name, bytes) {
|
|
60
|
+
try {
|
|
61
|
+
new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
62
|
+
return name.endsWith(".md") ? "text/markdown" : "text/plain";
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return "application/octet-stream";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function parseSkillFrontmatter(content, source) {
|
|
69
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/u.exec(content);
|
|
70
|
+
if (!match)
|
|
71
|
+
skillError(`Skill ${source} is missing YAML frontmatter.`);
|
|
72
|
+
const document = parseDocument(match[1], {
|
|
73
|
+
prettyErrors: false,
|
|
74
|
+
strict: true,
|
|
75
|
+
uniqueKeys: true,
|
|
76
|
+
});
|
|
77
|
+
if (document.errors.length > 0) {
|
|
78
|
+
skillError(`Skill ${source} has invalid YAML frontmatter.`, {
|
|
79
|
+
errors: document.errors.map((error) => error.message),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
let value;
|
|
83
|
+
try {
|
|
84
|
+
value = document.toJS({ maxAliasCount: 0 });
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
skillError(`Skill ${source} has unsupported YAML aliases.`, {
|
|
88
|
+
error: String(error),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
92
|
+
skillError(`Skill ${source} frontmatter must be an object.`);
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
async function readBoundedSkillFile(filePath, relative, size, budget) {
|
|
97
|
+
if (size > PM_MCP_SKILL_LIMITS.maxFileBytes) {
|
|
98
|
+
skillError(`Skill resource exceeds the per-file limit: ${relative}.`);
|
|
99
|
+
}
|
|
100
|
+
budget.files += 1;
|
|
101
|
+
if (budget.files > PM_MCP_SKILL_LIMITS.maxFilesPerSkill) {
|
|
102
|
+
skillError(`Skill exceeds ${PM_MCP_SKILL_LIMITS.maxFilesPerSkill} files.`);
|
|
103
|
+
}
|
|
104
|
+
budget.skillBytes += size;
|
|
105
|
+
if (budget.skillBytes > PM_MCP_SKILL_LIMITS.maxSkillBytes) {
|
|
106
|
+
skillError(`Skill exceeds the aggregate byte limit: ${relative}.`);
|
|
107
|
+
}
|
|
108
|
+
budget.originBytes.value += size;
|
|
109
|
+
if (budget.originBytes.value > MAX_MCP_SKILL_ORIGIN_BYTES) {
|
|
110
|
+
skillError(`Skill origin exceeds the aggregate byte limit: ${relative}.`);
|
|
111
|
+
}
|
|
112
|
+
return readFile(filePath);
|
|
113
|
+
}
|
|
114
|
+
async function collectSkillFiles(root, relative, budget) {
|
|
115
|
+
const directory = path.join(root, relative);
|
|
116
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
117
|
+
const files = [];
|
|
118
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
119
|
+
const childRelative = path.posix.join(relative.split(path.sep).join("/"), entry.name);
|
|
120
|
+
const childPath = path.join(root, ...childRelative.split("/"));
|
|
121
|
+
const stats = await lstat(childPath);
|
|
122
|
+
if (stats.isSymbolicLink()) {
|
|
123
|
+
skillError(`Skill resource must not be a symbolic link: ${childRelative}.`);
|
|
124
|
+
}
|
|
125
|
+
if (stats.isDirectory()) {
|
|
126
|
+
files.push(...(await collectSkillFiles(root, childRelative, budget)));
|
|
127
|
+
}
|
|
128
|
+
else if (stats.isFile()) {
|
|
129
|
+
files.push({
|
|
130
|
+
relative: childRelative,
|
|
131
|
+
bytes: await readBoundedSkillFile(childPath, childRelative, stats.size, budget),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
skillError(`Skill resource must be a regular file or directory: ${childRelative}.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return files;
|
|
139
|
+
}
|
|
140
|
+
async function loadSkillOrigin(skillsRoot, origin, packageVersion) {
|
|
141
|
+
const skills = new Map();
|
|
142
|
+
let entries;
|
|
143
|
+
try {
|
|
144
|
+
entries = await readdir(skillsRoot, { withFileTypes: true });
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (isFileAbsentError(error)) {
|
|
148
|
+
return skills;
|
|
149
|
+
}
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
const skillEntries = entries
|
|
153
|
+
.filter((entry) => entry.isDirectory() && SKILL_NAME_PATTERN.test(entry.name))
|
|
154
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
155
|
+
if (skillEntries.length > MAX_MCP_SKILLS_PER_ORIGIN) {
|
|
156
|
+
skillError(`Skill origin exceeds ${MAX_MCP_SKILLS_PER_ORIGIN} directories.`);
|
|
157
|
+
}
|
|
158
|
+
const originBytes = { value: 0 };
|
|
159
|
+
for (const entry of skillEntries) {
|
|
160
|
+
const files = await collectSkillFiles(path.join(skillsRoot, entry.name), "", {
|
|
161
|
+
files: 0,
|
|
162
|
+
skillBytes: 0,
|
|
163
|
+
originBytes,
|
|
164
|
+
});
|
|
165
|
+
const totalBytes = files.reduce((sum, file) => sum + file.bytes.byteLength, 0);
|
|
166
|
+
const main = files.find((file) => file.relative === "SKILL.md");
|
|
167
|
+
if (!main)
|
|
168
|
+
continue;
|
|
169
|
+
const frontmatter = parseSkillFrontmatter(main.bytes.toString("utf8"), entry.name);
|
|
170
|
+
if (frontmatter.name !== entry.name) {
|
|
171
|
+
skillError(`Skill directory ${entry.name} must match frontmatter name.`, {
|
|
172
|
+
actual: frontmatter.name ?? null,
|
|
173
|
+
expected: entry.name,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (typeof frontmatter.description !== "string" ||
|
|
177
|
+
frontmatter.description.trim().length === 0) {
|
|
178
|
+
skillError(`Skill ${entry.name} requires a non-empty frontmatter description.`, {
|
|
179
|
+
required: ["description"],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const resources = files.map((file) => ({
|
|
183
|
+
uri: `skill://${entry.name}/${file.relative}`,
|
|
184
|
+
digest: `sha256:${createHash("sha256").update(file.bytes).digest("hex")}`,
|
|
185
|
+
size: file.bytes.byteLength,
|
|
186
|
+
}));
|
|
187
|
+
const fingerprint = createHash("sha256")
|
|
188
|
+
.update(resources
|
|
189
|
+
.map((resource) => `${resource.uri}:${resource.digest}`)
|
|
190
|
+
.join("\n"))
|
|
191
|
+
.digest("hex");
|
|
192
|
+
skills.set(entry.name, {
|
|
193
|
+
uri: `skill://${entry.name}/SKILL.md`,
|
|
194
|
+
frontmatter,
|
|
195
|
+
resources,
|
|
196
|
+
_meta: {
|
|
197
|
+
contractVersion: 1,
|
|
198
|
+
extensionRevision: PM_MCP_SKILLS_DRAFT_REVISION,
|
|
199
|
+
origin,
|
|
200
|
+
packageVersion,
|
|
201
|
+
protocolVersion: PM_MCP_PROTOCOL_VERSION,
|
|
202
|
+
trust: "untrusted",
|
|
203
|
+
estimatedTokens: Math.ceil(totalBytes / 4),
|
|
204
|
+
},
|
|
205
|
+
files: new Map(files.map((file) => [file.relative, file.bytes])),
|
|
206
|
+
fingerprint,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return skills;
|
|
210
|
+
}
|
|
211
|
+
function projectSkill(skill) {
|
|
212
|
+
const { files: _files, fingerprint: _fingerprint, ...descriptor } = skill;
|
|
213
|
+
return descriptor;
|
|
214
|
+
}
|
|
215
|
+
/** Immutable in-memory registry for one request's package/workspace origins. */
|
|
216
|
+
export class PmMcpSkillRegistry {
|
|
217
|
+
#skills;
|
|
218
|
+
#fingerprint;
|
|
219
|
+
constructor(skills) {
|
|
220
|
+
this.#skills = skills;
|
|
221
|
+
this.#fingerprint = createHash("sha256")
|
|
222
|
+
.update([...skills.entries()]
|
|
223
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
224
|
+
.map(([name, skill]) => `${name}:${skill.fingerprint}`)
|
|
225
|
+
.join("\n"))
|
|
226
|
+
.digest("hex")
|
|
227
|
+
.slice(0, 16);
|
|
228
|
+
}
|
|
229
|
+
/** Decode one registry-bound cursor for a list or directory scope. */
|
|
230
|
+
#decodeCursor(cursor, scope) {
|
|
231
|
+
if (!cursor)
|
|
232
|
+
return 0;
|
|
233
|
+
try {
|
|
234
|
+
const parsed = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
235
|
+
if (typeof parsed !== "object" ||
|
|
236
|
+
parsed === null ||
|
|
237
|
+
!("fingerprint" in parsed) ||
|
|
238
|
+
parsed.fingerprint !== this.#fingerprint ||
|
|
239
|
+
!("scope" in parsed) ||
|
|
240
|
+
parsed.scope !== scope ||
|
|
241
|
+
!("offset" in parsed) ||
|
|
242
|
+
!Number.isInteger(parsed.offset) ||
|
|
243
|
+
Number(parsed.offset) < 0) {
|
|
244
|
+
skillError("Skill cursor is invalid or stale.");
|
|
245
|
+
}
|
|
246
|
+
return Number(parsed.offset);
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
if (error instanceof PmMcpProtocolError)
|
|
250
|
+
throw error;
|
|
251
|
+
return skillError("Skill cursor is invalid or stale.");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** Encode one registry-bound continuation cursor. */
|
|
255
|
+
#encodeCursor(offset, scope) {
|
|
256
|
+
return Buffer.from(JSON.stringify({ fingerprint: this.#fingerprint, offset, scope })).toString("base64url");
|
|
257
|
+
}
|
|
258
|
+
/** Load package skills and apply validated workspace overrides by name. */
|
|
259
|
+
static async load(options) {
|
|
260
|
+
const packaged = await loadSkillOrigin(path.join(options.packageRoot, ".agents", "skills"), "package", options.packageVersion);
|
|
261
|
+
if (options.workspaceRoot) {
|
|
262
|
+
const packageSkillsRoot = path.resolve(options.packageRoot, ".agents", "skills");
|
|
263
|
+
const workspaceSkillsRoot = path.resolve(options.workspaceRoot, ".agents", "skills");
|
|
264
|
+
if (workspaceSkillsRoot !== packageSkillsRoot) {
|
|
265
|
+
const overrides = await loadSkillOrigin(workspaceSkillsRoot, "workspace", options.packageVersion);
|
|
266
|
+
for (const [name, skill] of overrides)
|
|
267
|
+
packaged.set(name, skill);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return new PmMcpSkillRegistry(packaged);
|
|
271
|
+
}
|
|
272
|
+
/** List skills in deterministic pages without loading file bodies. */
|
|
273
|
+
list(options = {}) {
|
|
274
|
+
const limit = options.limit ?? PM_MCP_SKILL_LIMITS.defaultPageSize;
|
|
275
|
+
if (!SKILL_PAGE_SIZES.has(limit)) {
|
|
276
|
+
skillError(`Skill list limit must be an integer from 1 to ${PM_MCP_SKILL_LIMITS.maxPageSize}.`);
|
|
277
|
+
}
|
|
278
|
+
const offset = this.#decodeCursor(options.cursor, "skills/list");
|
|
279
|
+
const ordered = [...this.#skills.values()].sort((left, right) => left.uri.localeCompare(right.uri));
|
|
280
|
+
const page = ordered.slice(offset, offset + limit);
|
|
281
|
+
const nextOffset = offset + page.length;
|
|
282
|
+
const hasMore = nextOffset < ordered.length;
|
|
283
|
+
return {
|
|
284
|
+
skills: page.map(projectSkill),
|
|
285
|
+
hasMore,
|
|
286
|
+
...(hasMore
|
|
287
|
+
? {
|
|
288
|
+
nextCursor: this.#encodeCursor(nextOffset, "skills/list"),
|
|
289
|
+
}
|
|
290
|
+
: {}),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/** Get one skill descriptor by its SKILL.md URI. */
|
|
294
|
+
get(uri) {
|
|
295
|
+
const match = /^skill:\/\/([a-z0-9]+(?:-[a-z0-9]+)*)\/SKILL\.md$/u.exec(uri);
|
|
296
|
+
const skill = match ? this.#skills.get(match[1]) : undefined;
|
|
297
|
+
if (!skill)
|
|
298
|
+
skillError(`Unknown pm MCP skill: ${uri}.`, { field: "uri" });
|
|
299
|
+
return projectSkill(skill);
|
|
300
|
+
}
|
|
301
|
+
/** Read one digest-bound skill resource without following filesystem links. */
|
|
302
|
+
read(uri) {
|
|
303
|
+
const match = /^skill:\/\/([a-z0-9]+(?:-[a-z0-9]+)*)\/(.+)$/u.exec(uri);
|
|
304
|
+
const skill = match ? this.#skills.get(match[1]) : undefined;
|
|
305
|
+
const relative = match?.[2] ?? "";
|
|
306
|
+
const bytes = skill && relative ? skill.files.get(relative) : undefined;
|
|
307
|
+
const resource = skill?.resources.find((candidate) => candidate.uri === uri);
|
|
308
|
+
if (!skill || !bytes || !resource) {
|
|
309
|
+
skillError(`Unknown pm MCP skill resource: ${uri}.`, { field: "uri" });
|
|
310
|
+
}
|
|
311
|
+
const metadata = {
|
|
312
|
+
digest: resource.digest,
|
|
313
|
+
origin: skill._meta.origin,
|
|
314
|
+
trust: "untrusted",
|
|
315
|
+
};
|
|
316
|
+
const mimeType = skillFileMimeType(relative, bytes);
|
|
317
|
+
if (mimeType !== "application/octet-stream") {
|
|
318
|
+
return {
|
|
319
|
+
contents: [
|
|
320
|
+
{
|
|
321
|
+
uri,
|
|
322
|
+
mimeType,
|
|
323
|
+
text: bytes.toString("utf8"),
|
|
324
|
+
_meta: metadata,
|
|
325
|
+
},
|
|
326
|
+
],
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
contents: [
|
|
331
|
+
{
|
|
332
|
+
uri,
|
|
333
|
+
mimeType,
|
|
334
|
+
blob: bytes.toString("base64"),
|
|
335
|
+
_meta: metadata,
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
/** List one directory's direct children with opaque cursor pagination. */
|
|
341
|
+
readDirectory(uri, options = {}) {
|
|
342
|
+
const match = /^skill:\/\/([a-z0-9]+(?:-[a-z0-9]+)*)(?:\/(.+))?$/u.exec(uri);
|
|
343
|
+
const skill = match ? this.#skills.get(match[1]) : undefined;
|
|
344
|
+
if (!skill)
|
|
345
|
+
skillError(`Unknown pm MCP skill directory: ${uri}.`, { field: "uri" });
|
|
346
|
+
const directory = (match?.[2] ?? "").replace(/\/$/u, "");
|
|
347
|
+
const prefix = directory.length > 0 ? `${directory}/` : "";
|
|
348
|
+
const base = `skill://${match[1]}`;
|
|
349
|
+
const children = new Map();
|
|
350
|
+
for (const resource of skill.resources) {
|
|
351
|
+
const relative = resource.uri.slice(`${base}/`.length);
|
|
352
|
+
if (!relative.startsWith(prefix))
|
|
353
|
+
continue;
|
|
354
|
+
const remainder = relative.slice(prefix.length);
|
|
355
|
+
const [name, ...descendants] = remainder.split("/");
|
|
356
|
+
const childUri = `${base}/${prefix}${name}`;
|
|
357
|
+
const childBytes = skill.files.get(`${prefix}${name}`);
|
|
358
|
+
children.set(name, {
|
|
359
|
+
uri: childUri,
|
|
360
|
+
name,
|
|
361
|
+
mimeType: descendants.length > 0
|
|
362
|
+
? "inode/directory"
|
|
363
|
+
: skillFileMimeType(name, childBytes),
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (directory.length > 0 && children.size === 0) {
|
|
367
|
+
skillError(`Unknown pm MCP skill directory: ${uri}.`, { field: "uri" });
|
|
368
|
+
}
|
|
369
|
+
const limit = options.limit ?? PM_MCP_SKILL_LIMITS.maxPageSize;
|
|
370
|
+
if (!SKILL_PAGE_SIZES.has(limit)) {
|
|
371
|
+
skillError(`Skill directory limit must be an integer from 1 to ${PM_MCP_SKILL_LIMITS.maxPageSize}.`);
|
|
372
|
+
}
|
|
373
|
+
const offset = this.#decodeCursor(options.cursor, uri);
|
|
374
|
+
const ordered = [...children.values()].sort((left, right) => left.uri.localeCompare(right.uri));
|
|
375
|
+
const resources = ordered.slice(offset, offset + limit);
|
|
376
|
+
const nextOffset = offset + resources.length;
|
|
377
|
+
const hasMore = nextOffset < ordered.length;
|
|
378
|
+
return {
|
|
379
|
+
resources,
|
|
380
|
+
hasMore,
|
|
381
|
+
...(hasMore
|
|
382
|
+
? {
|
|
383
|
+
nextCursor: this.#encodeCursor(nextOffset, uri),
|
|
384
|
+
}
|
|
385
|
+
: {}),
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
//# sourceMappingURL=skills.js.map
|
|
390
|
+
//# debugId=5f60bc89-c81b-57ee-a8f2-0d0b18d0af1b
|