@modootoday/pmcp 0.17.4 → 0.18.2
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/plugins/marketplace.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +2 -2
- package/.mcp.json +1 -1
- package/CHANGELOG.md +152 -0
- package/CONTRIBUTING.md +71 -0
- package/README.md +98 -201
- package/SECURITY.md +17 -1
- package/dist/apply-JUTGS5WZ.js +242 -0
- package/dist/{attachment-tU5FZrgZ.d.ts → attachment-D84OGI6n.d.ts} +1 -1
- package/dist/available-DBSIVVJ6.js +73 -0
- package/dist/broadcast-CBMVOV3G.js +18 -0
- package/dist/chunk-26WLNWDG.js +93 -0
- package/dist/chunk-2FIV63WC.js +252 -0
- package/dist/chunk-2P4Z2NUX.js +28 -0
- package/dist/chunk-34DECPVC.js +22 -0
- package/dist/chunk-3FCFAQDG.js +42 -0
- package/dist/chunk-3IDXEV5E.js +1934 -0
- package/dist/chunk-3PW4FI7U.js +32 -0
- package/dist/chunk-3Y3HDMHA.js +108 -0
- package/dist/chunk-47O3X4VS.js +113 -0
- package/dist/chunk-4NDEP7HU.js +26 -0
- package/dist/chunk-5OMOPUE6.js +39 -0
- package/dist/chunk-5QQWS4US.js +53 -0
- package/dist/chunk-5ZABTVSW.js +48 -0
- package/dist/chunk-65KAQSJP.js +7 -0
- package/dist/chunk-6STKGOCW.js +27 -0
- package/dist/chunk-6WXMJOMI.js +9 -0
- package/dist/chunk-73AKO4UL.js +24 -0
- package/dist/chunk-7DLZC73N.js +29 -0
- package/dist/chunk-7GBYECSK.js +72 -0
- package/dist/chunk-7HFIGCSL.js +419 -0
- package/dist/chunk-7TD53M7L.js +13 -0
- package/dist/chunk-7UCZAN4J.js +778 -0
- package/dist/chunk-A4PKLESO.js +112 -0
- package/dist/chunk-A7VF7A35.js +1025 -0
- package/dist/chunk-ABTJQ4QV.js +74 -0
- package/dist/chunk-AJ4VXM2U.js +349 -0
- package/dist/chunk-BBTBJCFA.js +380 -0
- package/dist/chunk-BU65MNVU.js +13 -0
- package/dist/chunk-C4NHQGHL.js +142 -0
- package/dist/chunk-CJTKR6K6.js +1213 -0
- package/dist/chunk-D77IRGHO.js +1246 -0
- package/dist/chunk-DCU2EXQV.js +78 -0
- package/dist/chunk-DMZHQZ7P.js +104 -0
- package/dist/chunk-DZ2MRTYT.js +135 -0
- package/dist/chunk-E2YOZ2FF.js +207 -0
- package/dist/chunk-E3DQB5LS.js +48 -0
- package/dist/chunk-EATCUWGG.js +66 -0
- package/dist/chunk-EAWPJHJ7.js +155 -0
- package/dist/chunk-EIDIVIAD.js +33 -0
- package/dist/chunk-F5QYZK7E.js +396 -0
- package/dist/chunk-F5XMGOOX.js +28 -0
- package/dist/chunk-FENOGX3U.js +31 -0
- package/dist/chunk-GZHHEHKY.js +44 -0
- package/dist/chunk-HDMBVLCZ.js +53 -0
- package/dist/chunk-HQOB7OQS.js +81 -0
- package/dist/chunk-I2ZP2PSA.js +211 -0
- package/dist/chunk-IG33DXLT.js +151 -0
- package/dist/chunk-IJBSOWHK.js +86 -0
- package/dist/chunk-INT7QLEU.js +114 -0
- package/dist/chunk-J7UYNJCR.js +9 -0
- package/dist/chunk-JEL35P7S.js +53 -0
- package/dist/chunk-JGJ4INEN.js +32 -0
- package/dist/chunk-JS5RTH4I.js +84 -0
- package/dist/chunk-JWRZDYB5.js +59 -0
- package/dist/chunk-KMXRRSKT.js +660 -0
- package/dist/chunk-LBXO4VPG.js +73 -0
- package/dist/chunk-LLBPVZXM.js +67 -0
- package/dist/chunk-LLT5FQBE.js +57 -0
- package/dist/chunk-LMT3PPXJ.js +17 -0
- package/dist/chunk-LMUBBIE2.js +83 -0
- package/dist/chunk-LTZH5E3G.js +479 -0
- package/dist/chunk-LW4TG7EL.js +39 -0
- package/dist/chunk-MPSQXSC6.js +346 -0
- package/dist/chunk-MVFH26QT.js +97 -0
- package/dist/chunk-NLEXKE7U.js +67 -0
- package/dist/chunk-NQPURJT5.js +44 -0
- package/dist/chunk-NRBQK6UX.js +105 -0
- package/dist/chunk-OEH47H6A.js +48 -0
- package/dist/chunk-OG7QR2DP.js +75 -0
- package/dist/chunk-OPYFEHKG.js +52 -0
- package/dist/chunk-P4N7DBD5.js +83 -0
- package/dist/chunk-PAX3QXX2.js +140 -0
- package/dist/chunk-PKODFR5F.js +102 -0
- package/dist/chunk-PMJG2CXF.js +122 -0
- package/dist/chunk-Q5H3L6Y4.js +23 -0
- package/dist/chunk-QEF7EK3T.js +28 -0
- package/dist/chunk-QEW4J3IZ.js +74 -0
- package/dist/chunk-QPL7E2HW.js +464 -0
- package/dist/chunk-R2GPCZUX.js +22 -0
- package/dist/chunk-R5MT42JS.js +284 -0
- package/dist/chunk-RMATE45Z.js +197 -0
- package/dist/chunk-RPQOBHVU.js +87 -0
- package/dist/chunk-S3PIAMXV.js +230 -0
- package/dist/chunk-T3LKX23M.js +168 -0
- package/dist/chunk-T6GOWHK6.js +30 -0
- package/dist/chunk-TIA4SPU2.js +10 -0
- package/dist/chunk-TNCZ6444.js +57 -0
- package/dist/chunk-TVL5RTE6.js +269 -0
- package/dist/chunk-TXQ7L33K.js +45 -0
- package/dist/chunk-UPQTAHUK.js +189 -0
- package/dist/chunk-V4NPDK6X.js +14 -0
- package/dist/chunk-VJFEN6DJ.js +38 -0
- package/dist/chunk-VMHUEOT5.js +643 -0
- package/dist/chunk-VRPMYPZU.js +4985 -0
- package/dist/chunk-WIW772I3.js +25 -0
- package/dist/chunk-XELAZAIM.js +136 -0
- package/dist/chunk-XNML2KIC.js +23 -0
- package/dist/chunk-XP2U3LO3.js +30 -0
- package/dist/chunk-YGOWIJPE.js +51 -0
- package/dist/chunk-YIXDHQYE.js +11 -0
- package/dist/chunk-YSAWTGNA.js +117 -0
- package/dist/claude-U2JC2DNQ.js +77 -0
- package/dist/cli-MI4ZCAZ3.js +41 -0
- package/dist/cli-ZN7ZVDEZ.js +46 -0
- package/dist/cli.js +144 -16197
- package/dist/completion-ILSRB3LW.js +142 -0
- package/dist/config-DnpLL2kT.d.ts +46 -0
- package/dist/{service-qpCsOXkQ.d.ts → core-C1LPjxK6.d.ts} +2 -6
- package/dist/diagnostics-XKXVVQWH.js +93 -0
- package/dist/doctor-O2E63YGO.js +538 -0
- package/dist/entry-X6CSYQRQ.js +305 -0
- package/dist/exec-mcp-2PMWBPD7.js +365 -0
- package/dist/harness-L2KSI2ZB.js +177 -0
- package/dist/harness-egress-bridge.js +4 -4
- package/dist/harness-launch-gate.js +47 -940
- package/dist/harness-pane-runner.js +13 -80
- package/dist/harness-worker.js +21 -2703
- package/dist/hook-body.js +5222 -0
- package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
- package/dist/hook.js +26 -0
- package/dist/hooks-BHTA44X7.js +21 -0
- package/dist/host-UIZAXXQH.js +22 -0
- package/dist/host-UWK754BW.js +210 -0
- package/dist/host-run-BI2OTZDZ.js +307 -0
- package/dist/http.d.ts +5 -42
- package/dist/http.js +21 -2234
- package/dist/import-mcp-GPKJI7DI.js +400 -0
- package/dist/index.d.ts +146 -168
- package/dist/index.js +133 -4948
- package/dist/init-3C2Y7BNJ.js +14 -0
- package/dist/install-GG7HHZK2.js +796 -0
- package/dist/invoke-44CJRVMK.js +23 -0
- package/dist/list-MCP2FXUF.js +68 -0
- package/dist/list-WL6L4J5H.js +65 -0
- package/dist/load-BEUBABtB.d.ts +21 -0
- package/dist/logout-F5EJ5MOU.js +44 -0
- package/dist/logs-TBUA4UWU.js +107 -0
- package/dist/mailbox/index.d.ts +10 -5
- package/dist/mailbox/index.js +53 -1572
- package/dist/mailbox-BMTZOSZ7.js +285 -0
- package/dist/mailbox-GDJ7BWQN.js +189 -0
- package/dist/mainline-KAD2ERLP.js +639 -0
- package/dist/marketplace-G4VQET5W.js +191 -0
- package/dist/mcp-235QZN2A.js +15 -0
- package/dist/mcp-FJ2UQ4RH.js +193 -0
- package/dist/models-ISU4DCMA.js +32 -0
- package/dist/opencode-CN7JLQYO.js +60 -0
- package/dist/pause-7LILUVGL.js +18 -0
- package/dist/preview-DT7DWG5F.js +91 -0
- package/dist/project/hook-adapter.d.ts +5 -2
- package/dist/project/hook-adapter.js +41 -27
- package/dist/project-5YV5CUEG.js +70 -0
- package/dist/pty-XTJ4MIWK.js +94 -0
- package/dist/recovery-U6QB3PMT.js +100 -0
- package/dist/reindex-Y27QJFDB.js +22 -0
- package/dist/resume-26VFAAMH.js +18 -0
- package/dist/run-3AXTZSR7.js +126 -0
- package/dist/run-3SOVRQIA.js +19 -0
- package/dist/serve-DQMKTFIV.js +104 -0
- package/dist/session-XM2CR425.js +159 -0
- package/dist/setup-DTKZLZUT.js +18 -0
- package/dist/start-login-YTZV6KMF.js +416 -0
- package/dist/status-A2OUTNGK.js +9 -0
- package/dist/status-H2VAHIDV.js +10 -0
- package/dist/status-MROQ7WR7.js +43 -0
- package/dist/status-RO55QPKV.js +55 -0
- package/dist/status-UME2L33L.js +286 -0
- package/dist/stdio.d.ts +3 -13
- package/dist/stdio.js +16 -3186
- package/dist/sweep-35LGQTTO.js +18 -0
- package/dist/test-AGZOJLRZ.js +561 -0
- package/dist/tools-gpHNq9Dh.d.ts +328 -0
- package/dist/tui-G5LLWCSV.js +153 -0
- package/dist/unbroadcast-5QNGAJR2.js +18 -0
- package/dist/validate-IU52H2IC.js +46 -0
- package/dist/worker-QZ5T6LJD.js +80 -0
- package/dist/worktree-create-PZSRB7PH.js +89 -0
- package/dist/worktree-list-JYB6VXLW.js +51 -0
- package/dist/worktree-sync-UF5CXPWV.js +30 -0
- package/docs/authoring.md +82 -0
- package/docs/browser-and-desktop.md +46 -0
- package/docs/commands.md +325 -0
- package/docs/compare.md +35 -0
- package/docs/compatibility.md +55 -0
- package/docs/embeddings.md +1 -1
- package/docs/getting-started.md +105 -0
- package/docs/git-workflow.md +60 -0
- package/docs/glossary.md +31 -0
- package/docs/hooks/capabilities/antigravity.json +199 -0
- package/docs/hooks/capabilities/claude.json +179 -0
- package/docs/hooks/capabilities/codex.json +179 -0
- package/docs/hooks/capabilities/gemini.json +196 -0
- package/docs/hooks/capabilities/grok.json +192 -0
- package/docs/hooks/capabilities/opencode.json +184 -0
- package/docs/hooks.md +264 -0
- package/docs/install.md +72 -0
- package/docs/library-skills.md +132 -0
- package/docs/mailbox.md +16 -5
- package/docs/project-configuration.md +540 -58
- package/docs/sessions.md +64 -0
- package/docs/skills.md +4 -45
- package/docs/terminal-harness.md +92 -44
- package/docs/terminal-workspace.md +81 -169
- package/gemini-extension.json +2 -2
- package/mcp.json +1 -1
- package/package.json +16 -2
- package/plugin.json +2 -2
- package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
- package/plugins/pmcp/.mcp.json +1 -1
- package/plugins/pmcp/gemini-extension.json +2 -2
- package/plugins/pmcp/mcp.json +1 -1
- package/plugins/pmcp/mod/commands.ts +72 -0
- package/plugins/pmcp/mod/contract.d.ts +39 -0
- package/plugins/pmcp/mod/draw.tsx +216 -0
- package/plugins/pmcp/mod/guard.ts +42 -0
- package/plugins/pmcp/mod/hooks.json +4 -0
- package/plugins/pmcp/mod/host.ts +46 -0
- package/plugins/pmcp/mod/model.ts +144 -0
- package/plugins/pmcp/mod/reader/index.ts +18 -0
- package/plugins/pmcp/mod/reader/read.ts +76 -0
- package/plugins/pmcp/mod/reader/settings.ts +54 -0
- package/plugins/pmcp/mod/reader/types.ts +38 -0
- package/plugins/pmcp/mod/register.tsx +73 -0
- package/plugins/pmcp/mod/sessions/format.ts +91 -0
- package/plugins/pmcp/mod/sessions/types.ts +162 -0
- package/plugins/pmcp/mod/snapshot.ts +75 -0
- package/plugins/pmcp/mod/spinner.tsx +30 -0
- package/plugins/pmcp/mod/state.ts +28 -0
- package/plugins/pmcp/plugin.json +2 -2
- package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
- package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +101 -0
- package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -15
- package/plugins/pmcp/skills/pmcp-browser/SKILL.md +27 -0
- package/plugins/pmcp/skills/pmcp-desktop/SKILL.md +25 -0
- package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +153 -0
- package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +96 -0
- package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +89 -0
- package/schema/catalog-v1.json +187 -0
- package/schema/library.json +196 -0
- package/schema/marketplace-manifest.json +144 -0
- package/schema/plugin-manifest.json +59 -0
- package/schema/skill-frontmatter.json +170 -0
- package/schema/skill-metadata-core.json +131 -0
- package/skills/agent-assets-migrate/SKILL.md +96 -0
- package/skills/headless-agents-ci-scaffold/SKILL.md +101 -0
- package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/skills/package-skill-catalog/SKILL.md +51 -15
- package/skills/pmcp-browser/SKILL.md +27 -0
- package/skills/pmcp-desktop/SKILL.md +25 -0
- package/skills/pmcp-project-init/SKILL.md +153 -0
- package/skills/pmcp-sessions-and-git/SKILL.md +96 -0
- package/skills/skill-package-scaffold/SKILL.md +89 -0
- package/dist/config-BkSpjUG6.d.ts +0 -50
- package/dist/embed-DRROSD3F.d.ts +0 -53
- package/dist/hook-spec-CSJJySsH.d.ts +0 -11
- package/dist/server-VWSY3Shw.d.ts +0 -543
- package/dist/tui-worker.js +0 -6549
- package/docs/manual-library-skills.md +0 -74
- /package/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fingerprint,
|
|
3
|
+
installContext,
|
|
4
|
+
installedPackageDirectory,
|
|
5
|
+
integrityArguments,
|
|
6
|
+
planInstall,
|
|
7
|
+
readInstalledDependencies
|
|
8
|
+
} from "./chunk-BBTBJCFA.js";
|
|
9
|
+
import {
|
|
10
|
+
invocation
|
|
11
|
+
} from "./chunk-J7UYNJCR.js";
|
|
12
|
+
import {
|
|
13
|
+
DEFAULT_API_ORIGIN,
|
|
14
|
+
apiOrigin,
|
|
15
|
+
catalogEndpoint,
|
|
16
|
+
catalogProvider,
|
|
17
|
+
projectFrom,
|
|
18
|
+
remoteCatalog
|
|
19
|
+
} from "./chunk-R5MT42JS.js";
|
|
20
|
+
import {
|
|
21
|
+
readSession
|
|
22
|
+
} from "./chunk-RMATE45Z.js";
|
|
23
|
+
import "./chunk-73AKO4UL.js";
|
|
24
|
+
import {
|
|
25
|
+
installSpec,
|
|
26
|
+
syncSpec
|
|
27
|
+
} from "./chunk-ABTJQ4QV.js";
|
|
28
|
+
import {
|
|
29
|
+
ArgumentError
|
|
30
|
+
} from "./chunk-A4PKLESO.js";
|
|
31
|
+
import "./chunk-KMXRRSKT.js";
|
|
32
|
+
import "./chunk-YSAWTGNA.js";
|
|
33
|
+
|
|
34
|
+
// src/install/public.ts
|
|
35
|
+
import { lstatSync, readFileSync as readFileSync2, readdirSync as readdirSync2 } from "fs";
|
|
36
|
+
import { join as join2 } from "path";
|
|
37
|
+
|
|
38
|
+
// src/install/verify-content.ts
|
|
39
|
+
import { createHash } from "crypto";
|
|
40
|
+
import { readdirSync, readFileSync, statSync } from "fs";
|
|
41
|
+
import { join, relative, resolve, sep } from "path";
|
|
42
|
+
var SKILL = "SKILL.md";
|
|
43
|
+
var SKIP = /* @__PURE__ */ new Set(["node_modules", ".git", ".cache"]);
|
|
44
|
+
function skillFiles(root) {
|
|
45
|
+
const found = /* @__PURE__ */ new Map();
|
|
46
|
+
const walk = (dir) => {
|
|
47
|
+
let entries;
|
|
48
|
+
try {
|
|
49
|
+
entries = readdirSync(dir);
|
|
50
|
+
} catch {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
for (const name of entries) {
|
|
54
|
+
if (SKIP.has(name)) continue;
|
|
55
|
+
const path = join(dir, name);
|
|
56
|
+
let stats;
|
|
57
|
+
try {
|
|
58
|
+
stats = statSync(path);
|
|
59
|
+
} catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (stats.isDirectory()) walk(path);
|
|
63
|
+
else if (name === SKILL)
|
|
64
|
+
found.set(
|
|
65
|
+
relative(root, path).split(sep).join("/"),
|
|
66
|
+
readFileSync(path, "utf8")
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
walk(root);
|
|
71
|
+
return found;
|
|
72
|
+
}
|
|
73
|
+
function contentDigest(files) {
|
|
74
|
+
const hash = createHash("sha256");
|
|
75
|
+
for (const path of [...files.keys()].sort()) {
|
|
76
|
+
const body = files.get(path);
|
|
77
|
+
hash.update(`${path.length}:${path}:${body.length}:${body}`);
|
|
78
|
+
}
|
|
79
|
+
return `sha256:${hash.digest("hex")}`;
|
|
80
|
+
}
|
|
81
|
+
function verifyInstalledContent(project, packageName, expected) {
|
|
82
|
+
let root = resolve(project, "node_modules", ...packageName.split("/"));
|
|
83
|
+
try {
|
|
84
|
+
root = installedPackageDirectory(project, packageName);
|
|
85
|
+
} catch {
|
|
86
|
+
root = resolve(project, "node_modules", ...packageName.split("/"));
|
|
87
|
+
}
|
|
88
|
+
const files = skillFiles(root);
|
|
89
|
+
const actual = contentDigest(files);
|
|
90
|
+
return {
|
|
91
|
+
packageName,
|
|
92
|
+
expected,
|
|
93
|
+
actual,
|
|
94
|
+
matched: files.size > 0 && actual === expected,
|
|
95
|
+
skillCount: files.size
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/install/archive.ts
|
|
100
|
+
import { createHash as createHash2 } from "crypto";
|
|
101
|
+
import { gzipSync, gunzipSync } from "zlib";
|
|
102
|
+
var maximumSize = 32 * 1024 * 1024;
|
|
103
|
+
function integrity(bytes) {
|
|
104
|
+
return `sha512-${createHash2("sha512").update(bytes).digest("base64")}`;
|
|
105
|
+
}
|
|
106
|
+
function safePath(path) {
|
|
107
|
+
if (!/^package\//u.test(path) || path.includes("\\") || path.split("/").some((part) => !part || part === "." || part === ".."))
|
|
108
|
+
throw new Error("Unsafe archive path");
|
|
109
|
+
}
|
|
110
|
+
function readArchive(bytes) {
|
|
111
|
+
const tar = gunzipSync(bytes, { maxOutputLength: maximumSize });
|
|
112
|
+
const files = /* @__PURE__ */ new Map();
|
|
113
|
+
let offset = 0;
|
|
114
|
+
while (offset + 512 <= tar.length) {
|
|
115
|
+
const header = tar.subarray(offset, offset + 512);
|
|
116
|
+
if (header.every((value) => value === 0)) break;
|
|
117
|
+
const string = (start, length) => header.subarray(start, start + length).toString("utf8").replace(/\0.*$/su, "");
|
|
118
|
+
const name = string(0, 100);
|
|
119
|
+
const prefix = string(345, 155);
|
|
120
|
+
const path = prefix ? `${prefix}/${name}` : name;
|
|
121
|
+
safePath(path);
|
|
122
|
+
if (header[156] !== 0 && header[156] !== 48)
|
|
123
|
+
throw new Error("Archive contains a non-regular file");
|
|
124
|
+
const expected = Number.parseInt(string(148, 8).trim(), 8);
|
|
125
|
+
const actual = header.reduce(
|
|
126
|
+
(sum, byte, index) => sum + (index >= 148 && index < 156 ? 32 : byte),
|
|
127
|
+
0
|
|
128
|
+
);
|
|
129
|
+
if (expected !== actual)
|
|
130
|
+
throw new Error("Archive header checksum mismatch");
|
|
131
|
+
const size = Number.parseInt(string(124, 12).trim(), 8);
|
|
132
|
+
if (!Number.isSafeInteger(size) || size < 0 || offset + 512 + size > tar.length)
|
|
133
|
+
throw new Error("Archive member is truncated");
|
|
134
|
+
if (files.has(path)) throw new Error("Archive contains duplicate members");
|
|
135
|
+
files.set(path, tar.subarray(offset + 512, offset + 512 + size));
|
|
136
|
+
offset += 512 + Math.ceil(size / 512) * 512;
|
|
137
|
+
}
|
|
138
|
+
if (!files.size) throw new Error("Archive contains no files");
|
|
139
|
+
return files;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/install/public.ts
|
|
143
|
+
var MAX_ARCHIVE_BYTES = 8 * 1024 * 1024;
|
|
144
|
+
function publicArchiveUrl(entry) {
|
|
145
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(entry.productId) || entry.line === void 0)
|
|
146
|
+
throw new Error(
|
|
147
|
+
"The public catalog requires a product identifier and major line"
|
|
148
|
+
);
|
|
149
|
+
return `https://pmcp.build/skills/${entry.productId}/${entry.line.major}/releases/${entry.delivery.version}.tgz`;
|
|
150
|
+
}
|
|
151
|
+
function publicEntry(catalog, change) {
|
|
152
|
+
const entry = catalog.entries.find(
|
|
153
|
+
(item) => item.delivery.packageName === change.packageName && item.delivery.version === change.version
|
|
154
|
+
);
|
|
155
|
+
if (!entry || entry.delivery.integrity !== change.integrity)
|
|
156
|
+
throw new Error("The public delivery is absent from the catalog");
|
|
157
|
+
return entry;
|
|
158
|
+
}
|
|
159
|
+
function publicInstallPlan(plan, catalog) {
|
|
160
|
+
const specs = new Map(
|
|
161
|
+
plan.changes.map((change) => [
|
|
162
|
+
`${change.packageName}@${change.version}`,
|
|
163
|
+
`${change.packageName}@${publicArchiveUrl(publicEntry(catalog, change))}`
|
|
164
|
+
])
|
|
165
|
+
);
|
|
166
|
+
return {
|
|
167
|
+
...plan,
|
|
168
|
+
command: {
|
|
169
|
+
...plan.command,
|
|
170
|
+
args: plan.command.args.map(
|
|
171
|
+
(argument) => specs.get(argument) ?? argument
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function publicArchiveFiles(entry, bytes) {
|
|
177
|
+
if (bytes.length > MAX_ARCHIVE_BYTES || integrity(bytes) !== entry.delivery.integrity)
|
|
178
|
+
throw new Error("Public archive integrity differs from the catalog");
|
|
179
|
+
const files = readArchive(bytes);
|
|
180
|
+
const manifest = JSON.parse(
|
|
181
|
+
files.get("package/package.json")?.toString("utf8") ?? "null"
|
|
182
|
+
);
|
|
183
|
+
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest))
|
|
184
|
+
throw new Error("Public archive has no package manifest");
|
|
185
|
+
const metadata = manifest;
|
|
186
|
+
if (metadata.name !== entry.delivery.packageName || metadata.version !== entry.delivery.version)
|
|
187
|
+
throw new Error("Public archive identity differs from the catalog");
|
|
188
|
+
for (const key of [
|
|
189
|
+
"scripts",
|
|
190
|
+
"dependencies",
|
|
191
|
+
"optionalDependencies",
|
|
192
|
+
"peerDependencies",
|
|
193
|
+
"bundledDependencies",
|
|
194
|
+
"bundleDependencies",
|
|
195
|
+
"bin",
|
|
196
|
+
"workspaces"
|
|
197
|
+
])
|
|
198
|
+
if (metadata[key] !== void 0)
|
|
199
|
+
throw new Error("Public skill packages must be content-only");
|
|
200
|
+
const skills = /* @__PURE__ */ new Map();
|
|
201
|
+
if (!files.has("package/LICENSE"))
|
|
202
|
+
throw new Error("Public skill packages must include their license");
|
|
203
|
+
for (const [path, content] of files) {
|
|
204
|
+
if (path === "package/package.json" || path === "package/LICENSE") continue;
|
|
205
|
+
if (!/^package\/skills\/[a-z0-9]+(?:-[a-z0-9]+)*\/(?:SKILL\.md|references\/.+)$/u.test(
|
|
206
|
+
path
|
|
207
|
+
))
|
|
208
|
+
throw new Error("Public archive contains an unexpected resource");
|
|
209
|
+
if (path.endsWith("/SKILL.md"))
|
|
210
|
+
skills.set(path.slice("package/".length), content.toString("utf8"));
|
|
211
|
+
}
|
|
212
|
+
if (skills.size !== 1 || contentDigest(skills) !== entry.contentDigest)
|
|
213
|
+
throw new Error("Public skill content differs from the catalog");
|
|
214
|
+
return files;
|
|
215
|
+
}
|
|
216
|
+
async function downloadArchive(url, fetcher) {
|
|
217
|
+
const response = await fetcher(url, {
|
|
218
|
+
redirect: "error",
|
|
219
|
+
signal: AbortSignal.timeout(15e3)
|
|
220
|
+
});
|
|
221
|
+
if (!response.ok || !response.body)
|
|
222
|
+
throw new Error(`Public archive request failed (${response.status})`);
|
|
223
|
+
const reader = response.body.getReader();
|
|
224
|
+
const chunks = [];
|
|
225
|
+
let size = 0;
|
|
226
|
+
try {
|
|
227
|
+
for (; ; ) {
|
|
228
|
+
const { done, value } = await reader.read();
|
|
229
|
+
if (done) break;
|
|
230
|
+
size += value.byteLength;
|
|
231
|
+
if (size > MAX_ARCHIVE_BYTES)
|
|
232
|
+
throw new Error("Public archive exceeds the download budget");
|
|
233
|
+
chunks.push(value);
|
|
234
|
+
}
|
|
235
|
+
} finally {
|
|
236
|
+
await reader.cancel().catch(() => void 0);
|
|
237
|
+
reader.releaseLock();
|
|
238
|
+
}
|
|
239
|
+
return Buffer.concat(chunks);
|
|
240
|
+
}
|
|
241
|
+
async function preparePublicDelivery(plan, catalog, fetcher = fetch) {
|
|
242
|
+
const verified = /* @__PURE__ */ new Map();
|
|
243
|
+
const resources = /* @__PURE__ */ new Map();
|
|
244
|
+
for (const change of plan.changes) {
|
|
245
|
+
const entry = publicEntry(catalog, change);
|
|
246
|
+
const url = publicArchiveUrl(entry);
|
|
247
|
+
const bytes = await downloadArchive(url, fetcher);
|
|
248
|
+
resources.set(change.packageName, publicArchiveFiles(entry, bytes));
|
|
249
|
+
const identity = `${change.packageName}@${change.version}`;
|
|
250
|
+
verified.set(identity, integrity(bytes));
|
|
251
|
+
}
|
|
252
|
+
return { integrity: verified, resources };
|
|
253
|
+
}
|
|
254
|
+
function verifyPublicDelivery(project, delivery) {
|
|
255
|
+
for (const [name, files] of delivery.resources) {
|
|
256
|
+
const root = installedPackageDirectory(project, name);
|
|
257
|
+
const expected = new Set(
|
|
258
|
+
[...files.keys()].map((path) => path.slice("package/".length))
|
|
259
|
+
);
|
|
260
|
+
const walk = (directory, prefix = "") => {
|
|
261
|
+
for (const entry of readdirSync2(directory, { withFileTypes: true })) {
|
|
262
|
+
const path = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
263
|
+
if (entry.isDirectory()) {
|
|
264
|
+
walk(join2(directory, entry.name), path);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (!entry.isFile() || !expected.has(path))
|
|
268
|
+
throw new Error(
|
|
269
|
+
"Installed public package contains unexpected resources"
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
walk(root);
|
|
274
|
+
for (const [path, bytes] of files) {
|
|
275
|
+
const destination = join2(root, path.slice("package/".length));
|
|
276
|
+
if (!lstatSync(destination).isFile() || !readFileSync2(destination).equals(bytes))
|
|
277
|
+
throw new Error(
|
|
278
|
+
"Installed public package differs from its verified archive; inspect the project before retrying"
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/commands/install/_shared.ts
|
|
285
|
+
function verification(context, project, digests) {
|
|
286
|
+
const mismatched = (packages) => packages.map(
|
|
287
|
+
(name) => verifyInstalledContent(project, name, digests.get(name) ?? "")
|
|
288
|
+
).filter((check) => !check.matched);
|
|
289
|
+
const reportMismatch = (checks) => {
|
|
290
|
+
for (const check of checks) {
|
|
291
|
+
context.ui.error(
|
|
292
|
+
"installed content does not match the catalog",
|
|
293
|
+
`${check.packageName}: expected ${check.expected}, found ${check.actual} across ${check.skillCount} skill files`
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
return { mismatched, reportMismatch };
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/commands/install/plan.ts
|
|
301
|
+
async function prepare(context, sync) {
|
|
302
|
+
const dryRun = context.args.flags.has("dry-run");
|
|
303
|
+
const yes = context.args.flags.has("yes");
|
|
304
|
+
if (dryRun && yes)
|
|
305
|
+
throw new ArgumentError("choose --dry-run or --yes, not both");
|
|
306
|
+
if (sync && context.args.positional.length)
|
|
307
|
+
throw new ArgumentError("sync takes no package arguments");
|
|
308
|
+
if (!sync && !context.args.positional.length && !context.args.flags.has("all")) {
|
|
309
|
+
throw new ArgumentError("select a skill package or pass --all");
|
|
310
|
+
}
|
|
311
|
+
const project = projectFrom(context);
|
|
312
|
+
const provider = catalogProvider(context);
|
|
313
|
+
const install = installContext(project);
|
|
314
|
+
const inventory = readInstalledDependencies(project);
|
|
315
|
+
const catalog = await remoteCatalog(context);
|
|
316
|
+
const selectedPlan = planInstall({
|
|
317
|
+
context: install,
|
|
318
|
+
inventory,
|
|
319
|
+
catalog,
|
|
320
|
+
selected: context.args.positional,
|
|
321
|
+
all: context.args.flags.has("all"),
|
|
322
|
+
sync
|
|
323
|
+
});
|
|
324
|
+
const plan = provider === "public" ? publicInstallPlan(selectedPlan, catalog) : selectedPlan;
|
|
325
|
+
const digests = new Map(
|
|
326
|
+
catalog.entries.map((entry) => [
|
|
327
|
+
entry.delivery.packageName,
|
|
328
|
+
entry.contentDigest
|
|
329
|
+
])
|
|
330
|
+
);
|
|
331
|
+
const report = {
|
|
332
|
+
catalogRevision: plan.catalogRevision,
|
|
333
|
+
project,
|
|
334
|
+
changes: plan.changes,
|
|
335
|
+
command: plan.command
|
|
336
|
+
};
|
|
337
|
+
return {
|
|
338
|
+
project,
|
|
339
|
+
provider,
|
|
340
|
+
inventory,
|
|
341
|
+
catalog,
|
|
342
|
+
plan,
|
|
343
|
+
digests,
|
|
344
|
+
report,
|
|
345
|
+
...verification(context, project, digests)
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/commands/install/approval.ts
|
|
350
|
+
import { createInterface } from "readline/promises";
|
|
351
|
+
async function approve(context) {
|
|
352
|
+
if (!process.stdin.isTTY || !process.stderr.isTTY || context.args.flags.has("json")) {
|
|
353
|
+
throw new ArgumentError(
|
|
354
|
+
"use --yes to apply non-interactively or --dry-run to inspect the plan"
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
const prompt = createInterface({
|
|
358
|
+
input: process.stdin,
|
|
359
|
+
output: process.stderr
|
|
360
|
+
});
|
|
361
|
+
try {
|
|
362
|
+
const answer = await prompt.question(
|
|
363
|
+
"Update this project's dependencies and lockfile? [y/N] "
|
|
364
|
+
);
|
|
365
|
+
if (!/^y(?:es)?$/iu.test(answer.trim())) {
|
|
366
|
+
context.ui.info("cancelled", "nothing written");
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
} finally {
|
|
370
|
+
prompt.close();
|
|
371
|
+
}
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/commands/install/report.ts
|
|
376
|
+
function reportPlan(context, operation) {
|
|
377
|
+
const { project, plan } = operation;
|
|
378
|
+
if (!context.args.flags.has("json")) {
|
|
379
|
+
context.ui.info("project", project);
|
|
380
|
+
for (const entry of plan.changes)
|
|
381
|
+
context.ui.line(` ${entry.packageName}@${entry.version}`);
|
|
382
|
+
if (plan.changes.length)
|
|
383
|
+
context.ui.line(
|
|
384
|
+
` ${plan.command.executable} ${plan.command.args.join(" ")}`
|
|
385
|
+
);
|
|
386
|
+
for (const entry of plan.recalled) {
|
|
387
|
+
context.ui.warn(
|
|
388
|
+
"recalled",
|
|
389
|
+
`${entry.packageName} is written for versions a ${entry.line.recall?.severity ?? "high"} advisory covers`
|
|
390
|
+
);
|
|
391
|
+
if (entry.line.recall) {
|
|
392
|
+
context.ui.line(` ${entry.line.recall.summary}`);
|
|
393
|
+
context.ui.line(` ${entry.line.recall.advisoryUrl}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// src/install/apply.ts
|
|
400
|
+
import { spawnSync } from "child_process";
|
|
401
|
+
function environment(userConfig, base) {
|
|
402
|
+
return userConfig ? {
|
|
403
|
+
...base,
|
|
404
|
+
NPM_CONFIG_USERCONFIG: userConfig,
|
|
405
|
+
npm_config_userconfig: userConfig
|
|
406
|
+
} : base;
|
|
407
|
+
}
|
|
408
|
+
function createPackageManagerRunner(userConfig, baseEnv = process.env, verifiedIntegrity) {
|
|
409
|
+
return {
|
|
410
|
+
integrity(packageSpec, plan) {
|
|
411
|
+
const alreadyVerified = verifiedIntegrity?.get(packageSpec);
|
|
412
|
+
if (alreadyVerified) return alreadyVerified;
|
|
413
|
+
const { manager, project } = plan.context;
|
|
414
|
+
const args = integrityArguments(manager, packageSpec);
|
|
415
|
+
const result = spawnSync(manager, args, {
|
|
416
|
+
cwd: project,
|
|
417
|
+
env: environment(userConfig, baseEnv),
|
|
418
|
+
encoding: "utf8",
|
|
419
|
+
shell: false,
|
|
420
|
+
timeout: 3e4,
|
|
421
|
+
maxBuffer: 1024 * 1024
|
|
422
|
+
});
|
|
423
|
+
if (result.error || result.status !== 0) {
|
|
424
|
+
const detail = `${result.error?.message ?? ""} ${result.stderr ?? ""}`.replace(/pmcp_[A-Za-z0-9_-]{43}/gu, "[redacted]").trim().slice(0, 300);
|
|
425
|
+
throw new Error(
|
|
426
|
+
`package manager could not verify registry integrity${detail ? `: ${detail}` : ""}`
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
const value = JSON.parse(result.stdout.trim());
|
|
430
|
+
if (typeof value !== "string")
|
|
431
|
+
throw new Error("registry returned no package integrity");
|
|
432
|
+
return value;
|
|
433
|
+
},
|
|
434
|
+
install(plan) {
|
|
435
|
+
const args = [...plan.command.args];
|
|
436
|
+
const result = spawnSync(plan.command.executable, args, {
|
|
437
|
+
cwd: plan.command.cwd,
|
|
438
|
+
env: environment(userConfig, baseEnv),
|
|
439
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
440
|
+
encoding: "utf8",
|
|
441
|
+
shell: false,
|
|
442
|
+
maxBuffer: 8 * 1024 * 1024
|
|
443
|
+
});
|
|
444
|
+
if (result.error)
|
|
445
|
+
throw new Error(
|
|
446
|
+
"package manager execution failed; inspect the project before retrying"
|
|
447
|
+
);
|
|
448
|
+
if (result.stdout) process.stderr.write(result.stdout);
|
|
449
|
+
if (result.stderr) process.stderr.write(result.stderr);
|
|
450
|
+
return result.status ?? 1;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
var packageManagerRunner = createPackageManagerRunner();
|
|
455
|
+
function applyInstallPlan(plan, runner = packageManagerRunner) {
|
|
456
|
+
if (!plan.changes.length) return 0;
|
|
457
|
+
if (fingerprint(plan.context.files) !== plan.context.fingerprint)
|
|
458
|
+
throw new Error("project changed after planning; create a new plan");
|
|
459
|
+
for (const entry of plan.changes) {
|
|
460
|
+
const integrity2 = runner.integrity(
|
|
461
|
+
`${entry.packageName}@${entry.version}`,
|
|
462
|
+
plan
|
|
463
|
+
);
|
|
464
|
+
if (integrity2 !== entry.integrity)
|
|
465
|
+
throw new Error(
|
|
466
|
+
"registry integrity differs from the catalog; nothing was installed"
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
if (fingerprint(plan.context.files) !== plan.context.fingerprint)
|
|
470
|
+
throw new Error("project changed during registry verification");
|
|
471
|
+
const code = runner.install(plan);
|
|
472
|
+
if (code !== 0) return code;
|
|
473
|
+
const after = readInstalledDependencies(plan.context.project);
|
|
474
|
+
for (const entry of plan.changes) {
|
|
475
|
+
const found = after.dependencies.find(
|
|
476
|
+
(dependency) => dependency.requestedAs === entry.packageName
|
|
477
|
+
);
|
|
478
|
+
if (!found || found.name !== entry.packageName || found.version !== entry.version) {
|
|
479
|
+
throw new Error(
|
|
480
|
+
"package manager exited successfully but the planned version is not installed"
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return 0;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/commands/install/public-delivery.ts
|
|
488
|
+
async function applyPublic(context, operation) {
|
|
489
|
+
const { project, plan, catalog, report } = operation;
|
|
490
|
+
const delivery = await preparePublicDelivery(plan, catalog);
|
|
491
|
+
const code = applyInstallPlan(
|
|
492
|
+
plan,
|
|
493
|
+
createPackageManagerRunner(void 0, process.env, delivery.integrity)
|
|
494
|
+
);
|
|
495
|
+
if (code !== 0) {
|
|
496
|
+
context.ui.error(
|
|
497
|
+
"package manager failed",
|
|
498
|
+
`exit ${code}; inspect the project before retrying`
|
|
499
|
+
);
|
|
500
|
+
return code;
|
|
501
|
+
}
|
|
502
|
+
verifyPublicDelivery(project, delivery);
|
|
503
|
+
if (context.args.flags.has("json")) {
|
|
504
|
+
context.ui.data(
|
|
505
|
+
`${JSON.stringify({ status: "applied", ...report }, null, 2)}
|
|
506
|
+
`
|
|
507
|
+
);
|
|
508
|
+
return 0;
|
|
509
|
+
}
|
|
510
|
+
context.ui.success(`${plan.changes.length} public skill packages installed`);
|
|
511
|
+
return 0;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// src/remote/distribution.ts
|
|
515
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "fs";
|
|
516
|
+
import { tmpdir } from "os";
|
|
517
|
+
import { join as join3 } from "path";
|
|
518
|
+
function api(origin, path) {
|
|
519
|
+
const base = new URL(catalogEndpoint(origin));
|
|
520
|
+
base.pathname = path;
|
|
521
|
+
return base.href;
|
|
522
|
+
}
|
|
523
|
+
function credential(value) {
|
|
524
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
525
|
+
throw new Error("invalid distribution credential response");
|
|
526
|
+
const row = value;
|
|
527
|
+
if (!row["credential"] || typeof row["credential"] !== "object" || Array.isArray(row["credential"])) {
|
|
528
|
+
throw new Error("invalid distribution credential response");
|
|
529
|
+
}
|
|
530
|
+
const item = row["credential"];
|
|
531
|
+
for (const key of ["id", "token", "registry", "scope", "expiresAt"]) {
|
|
532
|
+
if (typeof item[key] !== "string" || item[key] === "")
|
|
533
|
+
throw new Error("invalid distribution credential response");
|
|
534
|
+
}
|
|
535
|
+
const registry = new URL(item["registry"]);
|
|
536
|
+
if (registry.href !== "https://api.pmcp.build/npm/" || item["scope"] !== "@modootoday" || !/^pmcp_[A-Za-z0-9_-]{43}$/u.test(item["token"]) || !Number.isFinite(Date.parse(item["expiresAt"]))) {
|
|
537
|
+
throw new Error("invalid distribution credential response");
|
|
538
|
+
}
|
|
539
|
+
return item;
|
|
540
|
+
}
|
|
541
|
+
var REFUSALS = {
|
|
542
|
+
401: "sign in again before installing skills",
|
|
543
|
+
402: "a subscription is needed to install these skills",
|
|
544
|
+
403: "sign in again to approve skill downloads"
|
|
545
|
+
};
|
|
546
|
+
function helpUrl(body) {
|
|
547
|
+
const error = body["error"];
|
|
548
|
+
if (!error || typeof error !== "object") return void 0;
|
|
549
|
+
const help = error["help"];
|
|
550
|
+
if (!help || typeof help !== "object") return void 0;
|
|
551
|
+
const url = help["subscribeUrl"];
|
|
552
|
+
if (typeof url !== "string") return void 0;
|
|
553
|
+
const parsed = URL.parse(url);
|
|
554
|
+
if (!parsed || parsed.protocol !== "https:") return void 0;
|
|
555
|
+
return parsed.host === "pmcp.build" ? parsed.href : void 0;
|
|
556
|
+
}
|
|
557
|
+
async function refusal(response, fallback, subjects = []) {
|
|
558
|
+
let requestId;
|
|
559
|
+
let where;
|
|
560
|
+
try {
|
|
561
|
+
const body = await response.json();
|
|
562
|
+
const value = body && typeof body === "object" && !Array.isArray(body) ? body : {};
|
|
563
|
+
if (typeof value["requestId"] === "string" && value["requestId"] !== "") {
|
|
564
|
+
requestId = value["requestId"];
|
|
565
|
+
}
|
|
566
|
+
where = helpUrl(value);
|
|
567
|
+
} catch {
|
|
568
|
+
}
|
|
569
|
+
const said = REFUSALS[response.status] ?? `${fallback} (${response.status})`;
|
|
570
|
+
const named = subjects.length > 0 ? `${said}: ${subjects.join(", ")}` : said;
|
|
571
|
+
return new Error(
|
|
572
|
+
[
|
|
573
|
+
named,
|
|
574
|
+
where ? `subscribe at ${where}` : "",
|
|
575
|
+
requestId ? `[request ${requestId}]` : ""
|
|
576
|
+
].filter((part) => part !== "").join("\n ")
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
async function issueDistributionCredential(accessToken, origin = DEFAULT_API_ORIGIN, fetcher = fetch, subjects = []) {
|
|
580
|
+
const response = await fetcher(api(origin, "/v1/distribution/credentials"), {
|
|
581
|
+
method: "POST",
|
|
582
|
+
redirect: "error",
|
|
583
|
+
signal: AbortSignal.timeout(15e3),
|
|
584
|
+
headers: {
|
|
585
|
+
authorization: `Bearer ${accessToken}`,
|
|
586
|
+
accept: "application/json"
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
if (!response.ok)
|
|
590
|
+
throw await refusal(
|
|
591
|
+
response,
|
|
592
|
+
"distribution credential request failed",
|
|
593
|
+
subjects
|
|
594
|
+
);
|
|
595
|
+
return credential(await response.json());
|
|
596
|
+
}
|
|
597
|
+
async function verifyRegistryIntegrity(entries, value, fetcher = fetch) {
|
|
598
|
+
const verified = /* @__PURE__ */ new Map();
|
|
599
|
+
for (const entry of entries) {
|
|
600
|
+
if (!entry.packageName.startsWith(`${value.scope}/pmcp-`))
|
|
601
|
+
throw new Error(
|
|
602
|
+
"catalog delivery name is not a skill package for this credential"
|
|
603
|
+
);
|
|
604
|
+
const endpoint = new URL(
|
|
605
|
+
encodeURIComponent(entry.packageName),
|
|
606
|
+
value.registry
|
|
607
|
+
);
|
|
608
|
+
const response = await fetcher(endpoint, {
|
|
609
|
+
method: "GET",
|
|
610
|
+
redirect: "error",
|
|
611
|
+
signal: AbortSignal.timeout(15e3),
|
|
612
|
+
headers: {
|
|
613
|
+
authorization: `Bearer ${value.token}`,
|
|
614
|
+
accept: "application/json"
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
if (!response.ok)
|
|
618
|
+
throw await refusal(response, "registry metadata request failed");
|
|
619
|
+
const raw = await response.text();
|
|
620
|
+
if (raw.length > 2 * 1024 * 1024)
|
|
621
|
+
throw new Error("registry metadata exceeds the supported size");
|
|
622
|
+
const body = JSON.parse(raw);
|
|
623
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
624
|
+
throw new Error("registry returned invalid metadata");
|
|
625
|
+
const versions = body["versions"];
|
|
626
|
+
if (!versions || typeof versions !== "object" || Array.isArray(versions))
|
|
627
|
+
throw new Error("registry metadata contains no versions");
|
|
628
|
+
const release = versions[entry.version];
|
|
629
|
+
if (!release || typeof release !== "object" || Array.isArray(release))
|
|
630
|
+
throw new Error("registry does not contain the catalog version");
|
|
631
|
+
const dist = release["dist"];
|
|
632
|
+
if (!dist || typeof dist !== "object" || Array.isArray(dist) || dist["integrity"] !== entry.integrity) {
|
|
633
|
+
throw new Error("registry integrity differs from the catalog");
|
|
634
|
+
}
|
|
635
|
+
verified.set(`${entry.packageName}@${entry.version}`, entry.integrity);
|
|
636
|
+
}
|
|
637
|
+
return verified;
|
|
638
|
+
}
|
|
639
|
+
async function revokeDistributionCredential(accessToken, id, origin = DEFAULT_API_ORIGIN, fetcher = fetch) {
|
|
640
|
+
try {
|
|
641
|
+
const response = await fetcher(api(origin, "/v1/distribution/revoke"), {
|
|
642
|
+
method: "POST",
|
|
643
|
+
redirect: "error",
|
|
644
|
+
signal: AbortSignal.timeout(15e3),
|
|
645
|
+
headers: {
|
|
646
|
+
authorization: `Bearer ${accessToken}`,
|
|
647
|
+
"content-type": "application/json"
|
|
648
|
+
},
|
|
649
|
+
body: JSON.stringify({ id })
|
|
650
|
+
});
|
|
651
|
+
return response.ok || response.status === 404;
|
|
652
|
+
} catch {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
function temporaryRegistryConfig(value) {
|
|
657
|
+
const directory = mkdtempSync(join3(tmpdir(), "pmcp-registry-"));
|
|
658
|
+
chmodSync(directory, 448);
|
|
659
|
+
const path = join3(directory, ".npmrc");
|
|
660
|
+
const registry = new URL(value.registry);
|
|
661
|
+
const auth = `//${registry.host}${registry.pathname}:_authToken=${value.token}`;
|
|
662
|
+
writeFileSync(path, `${value.scope}:registry=${registry.href}
|
|
663
|
+
${auth}
|
|
664
|
+
`, {
|
|
665
|
+
mode: 384
|
|
666
|
+
});
|
|
667
|
+
chmodSync(path, 384);
|
|
668
|
+
return {
|
|
669
|
+
path,
|
|
670
|
+
environment: { HOME: directory },
|
|
671
|
+
close() {
|
|
672
|
+
rmSync(directory, { recursive: true, force: true });
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// src/commands/install/hosted-delivery.ts
|
|
678
|
+
async function applyHosted(context, operation) {
|
|
679
|
+
const { plan, report, mismatched, reportMismatch } = operation;
|
|
680
|
+
const session = readSession();
|
|
681
|
+
if (!session || session.expiresAt !== void 0 && session.expiresAt <= Date.now()) {
|
|
682
|
+
throw new Error(
|
|
683
|
+
`run ${invocation()} login before installing paid skill packages`
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
const origin = apiOrigin(context);
|
|
687
|
+
const credential2 = await issueDistributionCredential(
|
|
688
|
+
session.accessToken,
|
|
689
|
+
origin,
|
|
690
|
+
fetch,
|
|
691
|
+
plan.changes.map((entry) => entry.packageName)
|
|
692
|
+
);
|
|
693
|
+
const registry = temporaryRegistryConfig(credential2);
|
|
694
|
+
let revoked = false;
|
|
695
|
+
try {
|
|
696
|
+
const verified = await verifyRegistryIntegrity(plan.changes, credential2);
|
|
697
|
+
const code = applyInstallPlan(
|
|
698
|
+
plan,
|
|
699
|
+
createPackageManagerRunner(
|
|
700
|
+
registry.path,
|
|
701
|
+
{ ...process.env, ...registry.environment },
|
|
702
|
+
verified
|
|
703
|
+
)
|
|
704
|
+
);
|
|
705
|
+
if (code !== 0) {
|
|
706
|
+
context.ui.error(
|
|
707
|
+
"package manager failed",
|
|
708
|
+
`exit ${code}; inspect the project before retrying`
|
|
709
|
+
);
|
|
710
|
+
return code;
|
|
711
|
+
}
|
|
712
|
+
const wrong = mismatched(plan.changes.map((change) => change.packageName));
|
|
713
|
+
if (wrong.length > 0) {
|
|
714
|
+
reportMismatch(wrong);
|
|
715
|
+
return 1;
|
|
716
|
+
}
|
|
717
|
+
if (context.args.flags.has("json")) {
|
|
718
|
+
context.ui.data(
|
|
719
|
+
`${JSON.stringify({ status: "applied", ...report }, null, 2)}
|
|
720
|
+
`
|
|
721
|
+
);
|
|
722
|
+
return 0;
|
|
723
|
+
}
|
|
724
|
+
context.ui.success(`${plan.changes.length} skill packages installed`);
|
|
725
|
+
return 0;
|
|
726
|
+
} finally {
|
|
727
|
+
registry.close();
|
|
728
|
+
revoked = await revokeDistributionCredential(
|
|
729
|
+
session.accessToken,
|
|
730
|
+
credential2.id,
|
|
731
|
+
origin
|
|
732
|
+
);
|
|
733
|
+
if (!revoked)
|
|
734
|
+
context.ui.warn(
|
|
735
|
+
"temporary registry credential expires automatically",
|
|
736
|
+
credential2.expiresAt
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// src/commands/install/run.ts
|
|
742
|
+
async function manage(context, sync) {
|
|
743
|
+
const dryRun = context.args.flags.has("dry-run");
|
|
744
|
+
const yes = context.args.flags.has("yes");
|
|
745
|
+
const operation = await prepare(context, sync);
|
|
746
|
+
const {
|
|
747
|
+
provider,
|
|
748
|
+
inventory,
|
|
749
|
+
plan,
|
|
750
|
+
digests,
|
|
751
|
+
report,
|
|
752
|
+
mismatched,
|
|
753
|
+
reportMismatch
|
|
754
|
+
} = operation;
|
|
755
|
+
reportPlan(context, operation);
|
|
756
|
+
if (!dryRun && plan.changes.length === 0) {
|
|
757
|
+
const drifted = mismatched(
|
|
758
|
+
inventory.dependencies.filter((dependency) => digests.has(dependency.name)).map((dependency) => dependency.name)
|
|
759
|
+
);
|
|
760
|
+
if (drifted.length > 0) {
|
|
761
|
+
reportMismatch(drifted);
|
|
762
|
+
return 1;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
if (dryRun || plan.changes.length === 0) {
|
|
766
|
+
const status = dryRun ? "planned" : "unchanged";
|
|
767
|
+
if (context.args.flags.has("json")) {
|
|
768
|
+
context.ui.data(`${JSON.stringify({ status, ...report }, null, 2)}
|
|
769
|
+
`);
|
|
770
|
+
} else {
|
|
771
|
+
context.ui.info(
|
|
772
|
+
status,
|
|
773
|
+
`${plan.changes.length} changes; nothing written`
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
return 0;
|
|
777
|
+
}
|
|
778
|
+
if (!yes && !await approve(context)) return 1;
|
|
779
|
+
if (provider === "public") return applyPublic(context, operation);
|
|
780
|
+
return applyHosted(context, operation);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// src/commands/install.ts
|
|
784
|
+
var installCommand = {
|
|
785
|
+
...installSpec,
|
|
786
|
+
run: (context) => manage(context, false)
|
|
787
|
+
};
|
|
788
|
+
var syncCommand = {
|
|
789
|
+
...syncSpec,
|
|
790
|
+
run: (context) => manage(context, true)
|
|
791
|
+
};
|
|
792
|
+
export {
|
|
793
|
+
installCommand,
|
|
794
|
+
syncCommand
|
|
795
|
+
};
|
|
796
|
+
//# sourceMappingURL=install-GG7HHZK2.js.map
|