@modootoday/pmcp 0.17.4 → 0.18.0
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 +1 -1
- package/CHANGELOG.md +60 -0
- package/README.md +29 -24
- package/dist/apply-4IGTXOCQ.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-3RY3OZGY.js +18 -0
- package/dist/chunk-25GHX674.js +1246 -0
- package/dist/chunk-2P4Z2NUX.js +28 -0
- package/dist/chunk-34DECPVC.js +22 -0
- package/dist/chunk-3NYG4SGU.js +45 -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-4VCC2NXE.js +104 -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-65ZHM5RH.js +4985 -0
- package/dist/chunk-665TA55Z.js +419 -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-7BLPN3W6.js +31 -0
- package/dist/chunk-7DLZC73N.js +29 -0
- package/dist/chunk-7GBYECSK.js +72 -0
- package/dist/chunk-7TD53M7L.js +13 -0
- package/dist/chunk-A4PKLESO.js +112 -0
- package/dist/chunk-ABTJQ4QV.js +74 -0
- package/dist/chunk-BBTBJCFA.js +380 -0
- package/dist/chunk-BU65MNVU.js +13 -0
- package/dist/chunk-BVCTKPT3.js +83 -0
- package/dist/chunk-C4NHQGHL.js +142 -0
- package/dist/chunk-CJTKR6K6.js +1213 -0
- package/dist/chunk-DCU2EXQV.js +78 -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-E7OOHLQR.js +7 -0
- package/dist/chunk-EATCUWGG.js +66 -0
- package/dist/chunk-EIDIVIAD.js +33 -0
- package/dist/chunk-EJBZGIDK.js +1934 -0
- package/dist/chunk-ELAGZ635.js +252 -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-IGYRMM62.js +28 -0
- package/dist/chunk-IJBSOWHK.js +86 -0
- package/dist/chunk-INT7QLEU.js +114 -0
- package/dist/chunk-J6QLLQVL.js +1025 -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-JUXNIXN4.js +42 -0
- package/dist/chunk-JWRZDYB5.js +59 -0
- package/dist/chunk-KMXRRSKT.js +660 -0
- package/dist/chunk-LAZQBMAU.js +67 -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-MM2Y43LC.js +87 -0
- package/dist/chunk-MPSQXSC6.js +346 -0
- package/dist/chunk-MVFH26QT.js +97 -0
- package/dist/chunk-MWFOUBFC.js +39 -0
- package/dist/chunk-N5AQ3PP7.js +211 -0
- package/dist/chunk-NQPURJT5.js +44 -0
- package/dist/chunk-NRBQK6UX.js +105 -0
- package/dist/chunk-NZS5CD72.js +333 -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-PLX3BOOS.js +396 -0
- package/dist/chunk-PMJG2CXF.js +122 -0
- package/dist/chunk-PWSJJXLQ.js +643 -0
- package/dist/chunk-Q5H3L6Y4.js +23 -0
- package/dist/chunk-Q65R3XKX.js +155 -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-R4L6LJJ2.js +778 -0
- package/dist/chunk-R5MT42JS.js +284 -0
- package/dist/chunk-RK4PYD7L.js +73 -0
- package/dist/chunk-RMATE45Z.js +197 -0
- package/dist/chunk-S3PIAMXV.js +230 -0
- package/dist/chunk-SG5TPMKH.js +93 -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-UOCLRM7P.js +151 -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-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-YMHUM7AV.js +22 -0
- package/dist/chunk-YSAWTGNA.js +117 -0
- package/dist/chunk-Z4HRRXRF.js +478 -0
- package/dist/chunk-ZH6R642Z.js +102 -0
- package/dist/claude-U2JC2DNQ.js +77 -0
- package/dist/cli-VYCQJZ5X.js +41 -0
- package/dist/cli-ZTCBSDW4.js +46 -0
- package/dist/cli.js +144 -16197
- package/dist/completion-E7RRG3ZT.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-XXH4FLUG.js +93 -0
- package/dist/doctor-ZIOESU3N.js +538 -0
- package/dist/entry-ZNFCTDVE.js +305 -0
- package/dist/exec-mcp-X6372BLE.js +365 -0
- package/dist/harness-F2XFDYXF.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 +5221 -0
- package/dist/hook-spec-C5fWTSCH.d.ts +100 -0
- package/dist/hook.js +26 -0
- package/dist/hooks-FYE2L5RW.js +21 -0
- package/dist/host-GRY3VAHH.js +22 -0
- package/dist/host-X6BR6X4O.js +200 -0
- package/dist/host-run-GCA6H6SR.js +307 -0
- package/dist/http.d.ts +5 -42
- package/dist/http.js +21 -2234
- package/dist/import-mcp-2TTBPVLY.js +400 -0
- package/dist/index.d.ts +146 -168
- package/dist/index.js +133 -4948
- package/dist/init-627KFXTG.js +14 -0
- package/dist/install-GG7HHZK2.js +796 -0
- package/dist/invoke-LW22Z6ET.js +23 -0
- package/dist/list-MCP2FXUF.js +68 -0
- package/dist/list-NGMSQ5SH.js +65 -0
- package/dist/load-BEUBABtB.d.ts +21 -0
- package/dist/logout-6CSHUWWE.js +44 -0
- package/dist/logs-SPB6AANY.js +107 -0
- package/dist/mailbox/index.d.ts +10 -5
- package/dist/mailbox/index.js +53 -1572
- package/dist/mailbox-7BV54Q4R.js +285 -0
- package/dist/mailbox-GDJ7BWQN.js +189 -0
- package/dist/mainline-JQTTYJMI.js +639 -0
- package/dist/marketplace-G4VQET5W.js +191 -0
- package/dist/mcp-2DKVU3SW.js +15 -0
- package/dist/mcp-V23HC3LB.js +193 -0
- package/dist/models-ISU4DCMA.js +32 -0
- package/dist/opencode-CN7JLQYO.js +60 -0
- package/dist/pause-FFAYRBWI.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-FY62G55N.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-UU4HZIUP.js +18 -0
- package/dist/run-HALGEJNJ.js +19 -0
- package/dist/run-OGA3P7FC.js +126 -0
- package/dist/serve-NBKT5BKY.js +104 -0
- package/dist/session-XM2CR425.js +159 -0
- package/dist/setup-DTKZLZUT.js +18 -0
- package/dist/start-login-UIQYQBMC.js +416 -0
- package/dist/status-A2OUTNGK.js +9 -0
- package/dist/status-H2VAHIDV.js +10 -0
- package/dist/status-NOOHW5WA.js +43 -0
- package/dist/status-VHODZPXB.js +55 -0
- package/dist/status-XQANBVXW.js +286 -0
- package/dist/stdio.d.ts +3 -13
- package/dist/stdio.js +16 -3186
- package/dist/sweep-64JDCGK6.js +18 -0
- package/dist/test-MKAXFJOL.js +561 -0
- package/dist/tools-gpHNq9Dh.d.ts +328 -0
- package/dist/tui-MWKAXE4K.js +153 -0
- package/dist/unbroadcast-KPUEFLZD.js +18 -0
- package/dist/validate-5GZ5YWNA.js +46 -0
- package/dist/worker-RQ575EJL.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/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/project-configuration.md +821 -4
- package/docs/terminal-harness.md +71 -28
- package/docs/terminal-workspace.md +91 -170
- package/gemini-extension.json +1 -1
- package/package.json +13 -1
- package/plugin.json +1 -1
- package/plugins/pmcp/.claude-plugin/plugin.json +4 -2
- package/plugins/pmcp/gemini-extension.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 +1 -1
- package/plugins/pmcp/skills/agent-assets-migrate/SKILL.md +96 -0
- package/plugins/pmcp/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
- package/plugins/pmcp/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/plugins/pmcp/skills/package-skill-catalog/SKILL.md +51 -11
- package/plugins/pmcp/skills/pmcp-project-init/SKILL.md +145 -0
- package/plugins/pmcp/skills/pmcp-sessions-and-git/SKILL.md +104 -0
- package/plugins/pmcp/skills/skill-package-scaffold/SKILL.md +88 -0
- package/schema/catalog-v1.json +158 -0
- package/schema/library.json +164 -0
- package/schema/marketplace-manifest.json +130 -0
- package/schema/plugin-manifest.json +55 -0
- package/schema/skill-frontmatter.json +144 -0
- package/schema/skill-metadata-core.json +110 -0
- package/skills/agent-assets-migrate/SKILL.md +96 -0
- package/skills/headless-agents-ci-scaffold/SKILL.md +100 -0
- package/skills/marketplace-plugin-scaffold/SKILL.md +87 -0
- package/skills/package-skill-catalog/SKILL.md +51 -11
- package/skills/pmcp-project-init/SKILL.md +145 -0
- package/skills/pmcp-sessions-and-git/SKILL.md +104 -0
- package/skills/skill-package-scaffold/SKILL.md +88 -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/dist/{tui-worker.d.ts → hook.d.ts} +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installIfStale,
|
|
3
|
+
movableSubmodules,
|
|
4
|
+
updateToPins
|
|
5
|
+
} from "./chunk-XELAZAIM.js";
|
|
6
|
+
import {
|
|
7
|
+
cherry,
|
|
8
|
+
distance
|
|
9
|
+
} from "./chunk-QEW4J3IZ.js";
|
|
10
|
+
import {
|
|
11
|
+
git,
|
|
12
|
+
gitText
|
|
13
|
+
} from "./chunk-OPYFEHKG.js";
|
|
14
|
+
|
|
15
|
+
// src/git/worktrees/sync.ts
|
|
16
|
+
function heldBy(root, upstream, ahead) {
|
|
17
|
+
const dirty = gitText(root, [
|
|
18
|
+
"status",
|
|
19
|
+
"--porcelain",
|
|
20
|
+
"--untracked-files=no",
|
|
21
|
+
"--ignore-submodules=all"
|
|
22
|
+
]);
|
|
23
|
+
if (dirty) return "uncommitted changes";
|
|
24
|
+
if (ahead === 0) return null;
|
|
25
|
+
const own = cherry(root, upstream).missing.length;
|
|
26
|
+
if (own > 0) return `${own} unlanded commit(s)`;
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function syncWorktree(options) {
|
|
30
|
+
const { ctx, report } = options;
|
|
31
|
+
if (!ctx.linked)
|
|
32
|
+
throw new Error(
|
|
33
|
+
"worktree sync moves a linked worktree; the main checkout uses pmcp git sync"
|
|
34
|
+
);
|
|
35
|
+
if (options.fetch !== false && git(ctx.root, ["fetch", "-q", ctx.remote, ctx.mainline]).status !== 0)
|
|
36
|
+
report.warn(
|
|
37
|
+
`fetch from ${ctx.remote} failed; judging against the last fetched ${ctx.upstream}`
|
|
38
|
+
);
|
|
39
|
+
const counted = distance(ctx.root, ctx.upstream);
|
|
40
|
+
if (counted === null)
|
|
41
|
+
throw new Error(`cannot compare HEAD with ${ctx.upstream}`);
|
|
42
|
+
if (counted.behind === 0) {
|
|
43
|
+
report.info(`already on ${ctx.upstream}`);
|
|
44
|
+
if (options.install !== void 0)
|
|
45
|
+
installIfStale(ctx.root, options.install, report);
|
|
46
|
+
return "current";
|
|
47
|
+
}
|
|
48
|
+
const holds = heldBy(ctx.root, ctx.upstream, counted.ahead);
|
|
49
|
+
if (holds !== null) {
|
|
50
|
+
report.warn(
|
|
51
|
+
`${counted.behind} commit(s) behind ${ctx.upstream} and holds ${holds}; left where it is`
|
|
52
|
+
);
|
|
53
|
+
return "held";
|
|
54
|
+
}
|
|
55
|
+
const submodules = options.followSubmodules ? movableSubmodules(ctx.root) : [];
|
|
56
|
+
const before = gitText(ctx.root, ["rev-parse", "HEAD"]);
|
|
57
|
+
const args = counted.ahead > 0 ? ["reset", "--keep", "-q", ctx.upstream] : ["merge", "--ff-only", "-q", ctx.upstream];
|
|
58
|
+
const moved = git(ctx.root, args);
|
|
59
|
+
if (moved.status !== 0) {
|
|
60
|
+
report.warn(
|
|
61
|
+
`could not move to ${ctx.upstream}: ${moved.stderr.trim().split("\n")[0] ?? ""}`
|
|
62
|
+
);
|
|
63
|
+
return "held";
|
|
64
|
+
}
|
|
65
|
+
const after = gitText(ctx.root, ["rev-parse", "HEAD"]);
|
|
66
|
+
report.info(
|
|
67
|
+
`moved ${before.slice(0, 10)} -> ${after.slice(0, 10)}, ${counted.behind} commit(s)`
|
|
68
|
+
);
|
|
69
|
+
for (const line of updateToPins(ctx.root, submodules)) report.info(line);
|
|
70
|
+
if (options.install !== void 0)
|
|
71
|
+
installIfStale(ctx.root, options.install, report);
|
|
72
|
+
return "moved";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
syncWorktree
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=chunk-DCU2EXQV.js.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// src/locks/file-lock.ts
|
|
2
|
+
import { spawnSync } from "child_process";
|
|
3
|
+
import {
|
|
4
|
+
closeSync,
|
|
5
|
+
constants,
|
|
6
|
+
openSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
renameSync,
|
|
9
|
+
unlinkSync,
|
|
10
|
+
writeSync
|
|
11
|
+
} from "fs";
|
|
12
|
+
var flockSeen;
|
|
13
|
+
function flockAvailable() {
|
|
14
|
+
flockSeen ??= spawnSync("flock", ["--version"], { stdio: "ignore" }).status === 0;
|
|
15
|
+
return flockSeen;
|
|
16
|
+
}
|
|
17
|
+
function processStart(pid) {
|
|
18
|
+
if (process.platform === "linux") {
|
|
19
|
+
try {
|
|
20
|
+
const text = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
21
|
+
return text.slice(text.lastIndexOf(")") + 2).split(" ")[19] ?? null;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const run = spawnSync("ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
27
|
+
encoding: "utf8"
|
|
28
|
+
});
|
|
29
|
+
const start = run.status === 0 ? run.stdout.trim() : "";
|
|
30
|
+
return start || null;
|
|
31
|
+
}
|
|
32
|
+
function alive(pid) {
|
|
33
|
+
try {
|
|
34
|
+
process.kill(pid, 0);
|
|
35
|
+
return true;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return error.code === "EPERM";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function owner(path) {
|
|
41
|
+
try {
|
|
42
|
+
const value = JSON.parse(readFileSync(path, "utf8"));
|
|
43
|
+
return Number.isInteger(value.pid) ? value : null;
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function stale(found) {
|
|
49
|
+
if (!found) return true;
|
|
50
|
+
return !alive(found.pid) || processStart(found.pid) !== found.start;
|
|
51
|
+
}
|
|
52
|
+
function tryCreate(path, me) {
|
|
53
|
+
let fd;
|
|
54
|
+
try {
|
|
55
|
+
fd = openSync(
|
|
56
|
+
path,
|
|
57
|
+
constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY,
|
|
58
|
+
384
|
|
59
|
+
);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error.code === "EEXIST") return false;
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
writeSync(fd, `${JSON.stringify(me)}
|
|
66
|
+
`);
|
|
67
|
+
} finally {
|
|
68
|
+
closeSync(fd);
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
function takeOver(path, me) {
|
|
73
|
+
if (tryCreate(path, me)) return true;
|
|
74
|
+
if (!stale(owner(path))) return false;
|
|
75
|
+
const aside = `${path}.stale-${process.pid}-${Date.now()}`;
|
|
76
|
+
try {
|
|
77
|
+
renameSync(path, aside);
|
|
78
|
+
unlinkSync(aside);
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return tryCreate(path, me);
|
|
83
|
+
}
|
|
84
|
+
function sleep(ms) {
|
|
85
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
86
|
+
}
|
|
87
|
+
function lockFile(path, waitMs) {
|
|
88
|
+
const me = { pid: process.pid, start: processStart(process.pid) ?? "" };
|
|
89
|
+
const end = Date.now() + waitMs;
|
|
90
|
+
while (!takeOver(path, me)) {
|
|
91
|
+
if (Date.now() >= end) return null;
|
|
92
|
+
sleep(100);
|
|
93
|
+
}
|
|
94
|
+
let held = true;
|
|
95
|
+
return {
|
|
96
|
+
release: () => {
|
|
97
|
+
if (!held) return;
|
|
98
|
+
held = false;
|
|
99
|
+
if (owner(path)?.pid === process.pid) unlinkSync(path);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async function lockFileAsync(path, waitMs) {
|
|
104
|
+
const end = Date.now() + waitMs;
|
|
105
|
+
for (; ; ) {
|
|
106
|
+
const lock = lockFile(path, 0);
|
|
107
|
+
if (lock || Date.now() >= end) return lock;
|
|
108
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function runLocked(lock, waitSeconds, argv, options) {
|
|
112
|
+
if (flockAvailable()) {
|
|
113
|
+
const wait = waitSeconds > 0 ? ["--wait", String(waitSeconds)] : ["--nonblock"];
|
|
114
|
+
const flags = [...wait, "--close", "--conflict-exit-code", "73", lock];
|
|
115
|
+
return spawnSync("flock", [...flags, ...argv], options);
|
|
116
|
+
}
|
|
117
|
+
const held = lockFile(lock, waitSeconds * 1e3);
|
|
118
|
+
if (!held) {
|
|
119
|
+
const busy = { status: 73, stdout: "", stderr: "", output: [] };
|
|
120
|
+
return { ...busy, pid: 0, signal: null };
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
return spawnSync(argv[0], argv.slice(1), options);
|
|
124
|
+
} finally {
|
|
125
|
+
held.release();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
flockAvailable,
|
|
131
|
+
lockFile,
|
|
132
|
+
lockFileAsync,
|
|
133
|
+
runLocked
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=chunk-DZ2MRTYT.js.map
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import {
|
|
2
|
+
flockAvailable,
|
|
3
|
+
lockFileAsync
|
|
4
|
+
} from "./chunk-DZ2MRTYT.js";
|
|
5
|
+
import {
|
|
6
|
+
boundSession,
|
|
7
|
+
clearCredentials,
|
|
8
|
+
credentialPath,
|
|
9
|
+
privateDirectory,
|
|
10
|
+
readCredentials,
|
|
11
|
+
request,
|
|
12
|
+
responseObject,
|
|
13
|
+
writeCredentials
|
|
14
|
+
} from "./chunk-UPQTAHUK.js";
|
|
15
|
+
import {
|
|
16
|
+
McpAuthError,
|
|
17
|
+
safeEndpoint
|
|
18
|
+
} from "./chunk-Q5H3L6Y4.js";
|
|
19
|
+
|
|
20
|
+
// src/mcp-auth/store/lock.ts
|
|
21
|
+
import { spawn } from "child_process";
|
|
22
|
+
import { closeSync, constants, openSync } from "fs";
|
|
23
|
+
async function withCredentialLock(name, env, action) {
|
|
24
|
+
privateDirectory(env);
|
|
25
|
+
const path = `${credentialPath(name, env)}.lock`;
|
|
26
|
+
const fd = openSync(
|
|
27
|
+
path,
|
|
28
|
+
constants.O_CREAT | constants.O_RDWR | constants.O_NOFOLLOW,
|
|
29
|
+
384
|
|
30
|
+
);
|
|
31
|
+
closeSync(fd);
|
|
32
|
+
if (!flockAvailable()) {
|
|
33
|
+
const held = await lockFileAsync(path, 3e4);
|
|
34
|
+
if (!held) throw new McpAuthError("MCP credential lock timed out");
|
|
35
|
+
try {
|
|
36
|
+
return await action();
|
|
37
|
+
} finally {
|
|
38
|
+
held.release();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const holder = spawn(
|
|
42
|
+
"flock",
|
|
43
|
+
[
|
|
44
|
+
"--exclusive",
|
|
45
|
+
"--timeout",
|
|
46
|
+
"30",
|
|
47
|
+
path,
|
|
48
|
+
process.execPath,
|
|
49
|
+
"-e",
|
|
50
|
+
'process.stdout.write("locked\\n");\nprocess.stdin.resume();'
|
|
51
|
+
],
|
|
52
|
+
{ stdio: ["pipe", "pipe", "ignore"] }
|
|
53
|
+
);
|
|
54
|
+
const exited = new Promise(
|
|
55
|
+
(resolve) => holder.once("close", () => resolve())
|
|
56
|
+
);
|
|
57
|
+
try {
|
|
58
|
+
await new Promise((resolve, reject) => {
|
|
59
|
+
holder.once(
|
|
60
|
+
"error",
|
|
61
|
+
() => reject(
|
|
62
|
+
new McpAuthError(
|
|
63
|
+
"Cannot acquire MCP credential lock; flock is required"
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
holder.once(
|
|
68
|
+
"exit",
|
|
69
|
+
() => reject(new McpAuthError("MCP credential lock timed out"))
|
|
70
|
+
);
|
|
71
|
+
holder.stdout.once("data", () => resolve());
|
|
72
|
+
});
|
|
73
|
+
return await action();
|
|
74
|
+
} finally {
|
|
75
|
+
holder.stdin.end();
|
|
76
|
+
await exited;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/mcp-auth/oauth/tokens.ts
|
|
81
|
+
async function tokenRequest(oauth, serverUrl, grant, previous) {
|
|
82
|
+
if (safeEndpoint(oauth.tokenEndpoint).origin !== safeEndpoint(oauth.issuer).origin)
|
|
83
|
+
throw new McpAuthError("OAuth token endpoint does not match the issuer");
|
|
84
|
+
const form = new URLSearchParams({
|
|
85
|
+
...grant,
|
|
86
|
+
client_id: oauth.clientId,
|
|
87
|
+
resource: serverUrl
|
|
88
|
+
});
|
|
89
|
+
if (oauth.clientSecret) form.set("client_secret", oauth.clientSecret);
|
|
90
|
+
const response = await request(oauth.tokenEndpoint, {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
93
|
+
body: form.toString()
|
|
94
|
+
});
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
await response.body?.cancel();
|
|
97
|
+
throw new McpAuthError(
|
|
98
|
+
"MCP authentication failed or was revoked; run pmcp mcp login again"
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const body = await responseObject(response);
|
|
102
|
+
if (typeof body.access_token !== "string" || !body.access_token || body.token_type !== void 0 && String(body.token_type).toLowerCase() !== "bearer")
|
|
103
|
+
throw new McpAuthError(
|
|
104
|
+
"OAuth response is missing a supported access token"
|
|
105
|
+
);
|
|
106
|
+
const lifetime = body.expires_in === void 0 ? void 0 : Number(body.expires_in);
|
|
107
|
+
if (lifetime !== void 0 && (!Number.isFinite(lifetime) || lifetime < 0))
|
|
108
|
+
throw new McpAuthError("OAuth response has an invalid expiry");
|
|
109
|
+
const scopes = typeof body.scope === "string" ? body.scope.split(/\s+/u).filter(Boolean) : previous?.scopes ?? [];
|
|
110
|
+
return {
|
|
111
|
+
serverUrl,
|
|
112
|
+
kind: "oauth",
|
|
113
|
+
oauth,
|
|
114
|
+
accessToken: body.access_token,
|
|
115
|
+
refreshToken: typeof body.refresh_token === "string" ? body.refresh_token : previous?.refreshToken,
|
|
116
|
+
expiresAt: lifetime === void 0 ? void 0 : Date.now() + lifetime * 1e3,
|
|
117
|
+
scopes
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async function revokeSession(session) {
|
|
121
|
+
const oauth = session.oauth;
|
|
122
|
+
if (!oauth?.revocationEndpoint) return;
|
|
123
|
+
if (safeEndpoint(oauth.revocationEndpoint).origin !== safeEndpoint(oauth.issuer).origin)
|
|
124
|
+
throw new McpAuthError(
|
|
125
|
+
"OAuth revocation endpoint does not match the issuer"
|
|
126
|
+
);
|
|
127
|
+
for (const token of [session.refreshToken, session.accessToken]) {
|
|
128
|
+
if (!token) continue;
|
|
129
|
+
const form = new URLSearchParams({ token, client_id: oauth.clientId });
|
|
130
|
+
if (oauth.clientSecret) form.set("client_secret", oauth.clientSecret);
|
|
131
|
+
const response = await request(oauth.revocationEndpoint, {
|
|
132
|
+
method: "POST",
|
|
133
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
134
|
+
body: form.toString()
|
|
135
|
+
});
|
|
136
|
+
await response.body?.cancel();
|
|
137
|
+
if (!response.ok)
|
|
138
|
+
throw new McpAuthError(
|
|
139
|
+
"Remote OAuth revocation failed; local credentials were cleared"
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/mcp-auth/session.ts
|
|
145
|
+
async function accessToken(name, serverUrl, env = process.env, rejected) {
|
|
146
|
+
const current = boundSession(name, serverUrl, env);
|
|
147
|
+
if (!current) return void 0;
|
|
148
|
+
const usable = (session) => session.accessToken !== rejected && (session.expiresAt === void 0 || session.expiresAt > Date.now() + 3e4);
|
|
149
|
+
if (usable(current)) return current.accessToken;
|
|
150
|
+
return withCredentialLock(name, env, async () => {
|
|
151
|
+
const session = boundSession(name, serverUrl, env);
|
|
152
|
+
if (!session)
|
|
153
|
+
throw new McpAuthError(
|
|
154
|
+
"MCP credentials were removed; run pmcp mcp login again"
|
|
155
|
+
);
|
|
156
|
+
if (usable(session)) return session.accessToken;
|
|
157
|
+
if (!session.refreshToken || !session.oauth)
|
|
158
|
+
throw new McpAuthError(
|
|
159
|
+
"MCP authentication expired or was revoked; run pmcp mcp login again"
|
|
160
|
+
);
|
|
161
|
+
const refreshed = await tokenRequest(
|
|
162
|
+
session.oauth,
|
|
163
|
+
serverUrl,
|
|
164
|
+
{ grant_type: "refresh_token", refresh_token: session.refreshToken },
|
|
165
|
+
session
|
|
166
|
+
);
|
|
167
|
+
writeCredentials(
|
|
168
|
+
name,
|
|
169
|
+
{ ...readCredentials(name, env), session: refreshed },
|
|
170
|
+
env
|
|
171
|
+
);
|
|
172
|
+
return refreshed.accessToken;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
async function storeBearer(name, serverUrl, token, env = process.env) {
|
|
176
|
+
if (!token || /[\r\n]/u.test(token))
|
|
177
|
+
throw new McpAuthError(
|
|
178
|
+
"The bearer token environment variable is missing or invalid"
|
|
179
|
+
);
|
|
180
|
+
await withCredentialLock(
|
|
181
|
+
name,
|
|
182
|
+
env,
|
|
183
|
+
async () => writeCredentials(
|
|
184
|
+
name,
|
|
185
|
+
{
|
|
186
|
+
session: { serverUrl, kind: "bearer", accessToken: token, scopes: [] }
|
|
187
|
+
},
|
|
188
|
+
env
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
async function logout(name, serverUrl, env = process.env) {
|
|
193
|
+
await withCredentialLock(name, env, async () => {
|
|
194
|
+
const session = boundSession(name, serverUrl, env);
|
|
195
|
+
clearCredentials(name, env);
|
|
196
|
+
if (session) await revokeSession(session);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export {
|
|
201
|
+
withCredentialLock,
|
|
202
|
+
tokenRequest,
|
|
203
|
+
accessToken,
|
|
204
|
+
storeBearer,
|
|
205
|
+
logout
|
|
206
|
+
};
|
|
207
|
+
//# sourceMappingURL=chunk-E2YOZ2FF.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
jsonOption
|
|
3
|
+
} from "./chunk-XNML2KIC.js";
|
|
4
|
+
|
|
5
|
+
// src/commands/specs/mcp.ts
|
|
6
|
+
var mcpSpec = {
|
|
7
|
+
name: "mcp",
|
|
8
|
+
describe: "Manage the project's shared remote MCP authentication",
|
|
9
|
+
usage: "pmcp mcp <login|logout|status> <name> [--config <file>]",
|
|
10
|
+
options: [
|
|
11
|
+
jsonOption,
|
|
12
|
+
{
|
|
13
|
+
name: "config",
|
|
14
|
+
describe: "Read this project configuration.",
|
|
15
|
+
placeholder: "<file>"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "code",
|
|
19
|
+
describe: "Complete a pending login with a callback URL or authorization code.",
|
|
20
|
+
placeholder: "<callback-or-code>"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "no-wait",
|
|
24
|
+
describe: "Print the authorization URL and save a pending login for later completion.",
|
|
25
|
+
boolean: true
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "port",
|
|
29
|
+
describe: "Loopback callback port; zero chooses an available port.",
|
|
30
|
+
placeholder: "<port>"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "client-id",
|
|
34
|
+
describe: "Use a pre-registered OAuth client identifier.",
|
|
35
|
+
placeholder: "<id>"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "bearer-env",
|
|
39
|
+
describe: "Store a bearer session from this environment variable without printing it.",
|
|
40
|
+
placeholder: "<name>"
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
mcpSpec
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chunk-E3DQB5LS.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/sessions/projector-cli.ts
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
3
|
+
import { delimiter, join } from "path";
|
|
4
|
+
var PROJECTOR_FILE = "projector.json";
|
|
5
|
+
function readJson(path) {
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function localCli(root) {
|
|
13
|
+
const own = join(root, "node_modules/@modootoday/pmcp/dist/cli.js");
|
|
14
|
+
if (existsSync(own)) return own;
|
|
15
|
+
try {
|
|
16
|
+
const target = realpathSync(join(root, "node_modules/.bin/pmcp"));
|
|
17
|
+
return /\.[cm]?js$/u.test(target) ? target : null;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function recordedCli(root, stateDir) {
|
|
23
|
+
const known = readJson(join(stateDir, PROJECTOR_FILE));
|
|
24
|
+
let checkout;
|
|
25
|
+
try {
|
|
26
|
+
checkout = realpathSync(root);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const entry = known?.[checkout];
|
|
31
|
+
return typeof entry?.cli === "string" ? entry.cli : null;
|
|
32
|
+
}
|
|
33
|
+
function projectingCli(root, stateDir) {
|
|
34
|
+
const cli = localCli(root) ?? recordedCli(root, stateDir);
|
|
35
|
+
return cli && existsSync(cli) ? cli : null;
|
|
36
|
+
}
|
|
37
|
+
function pathPmcp(path) {
|
|
38
|
+
for (const dir of (path ?? "").split(delimiter).filter(Boolean)) {
|
|
39
|
+
try {
|
|
40
|
+
return realpathSync(join(dir, "pmcp"));
|
|
41
|
+
} catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
48
|
+
function pmcpCommand(root, stateDir, path) {
|
|
49
|
+
const cli = projectingCli(root, stateDir);
|
|
50
|
+
if (!cli) return "pmcp";
|
|
51
|
+
let real = cli;
|
|
52
|
+
try {
|
|
53
|
+
real = realpathSync(cli);
|
|
54
|
+
} catch {
|
|
55
|
+
return "pmcp";
|
|
56
|
+
}
|
|
57
|
+
return pathPmcp(path) === real ? "pmcp" : `node ${quote(real)}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
localCli,
|
|
62
|
+
recordedCli,
|
|
63
|
+
pathPmcp,
|
|
64
|
+
pmcpCommand
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=chunk-EATCUWGG.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/commands/specs/session.ts
|
|
2
|
+
var loginSpec = {
|
|
3
|
+
name: "login",
|
|
4
|
+
describe: "Sign in on this machine, to obtain skills this project lacks",
|
|
5
|
+
usage: "pmcp login [--issuer <url>]",
|
|
6
|
+
options: [
|
|
7
|
+
{
|
|
8
|
+
name: "issuer",
|
|
9
|
+
describe: "override the auth issuer",
|
|
10
|
+
placeholder: "<url>"
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
};
|
|
14
|
+
var logoutSpec = {
|
|
15
|
+
name: "logout",
|
|
16
|
+
describe: "Forget the sign-in on this machine",
|
|
17
|
+
usage: "pmcp logout"
|
|
18
|
+
};
|
|
19
|
+
var whoamiSpec = {
|
|
20
|
+
name: "whoami",
|
|
21
|
+
describe: "Whether this machine is signed in, and to what",
|
|
22
|
+
usage: "pmcp whoami [--json]",
|
|
23
|
+
options: [
|
|
24
|
+
{ name: "json", describe: "Print the answer as JSON.", boolean: true }
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
loginSpec,
|
|
30
|
+
logoutSpec,
|
|
31
|
+
whoamiSpec
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=chunk-EIDIVIAD.js.map
|