@modootoday/pmcp 0.18.4 → 0.19.1

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.
Files changed (103) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/.mcp.json +1 -1
  5. package/dist/{apply-75UWIUVQ.js → apply-IPTASVRS.js} +16 -17
  6. package/dist/{broadcast-CBMVOV3G.js → broadcast-56NPEJWM.js} +3 -4
  7. package/dist/{chunk-ARA4VDHD.js → chunk-2DAC45ZT.js} +2 -2
  8. package/dist/{chunk-JS5RTH4I.js → chunk-2Q6MNGU5.js} +2 -2
  9. package/dist/{chunk-ZWLUH3F2.js → chunk-2W6CEJD7.js} +2 -2
  10. package/dist/{chunk-YRGDWUFY.js → chunk-3BLHIEAK.js} +2 -2
  11. package/dist/{chunk-R26RWSFW.js → chunk-3CLLHFP7.js} +2 -2
  12. package/dist/{chunk-HE2C2S5A.js → chunk-3H5FZCKX.js} +3 -3
  13. package/dist/{chunk-TFRJ5QOS.js → chunk-7FAA32PB.js} +3 -3
  14. package/dist/{chunk-DCU2EXQV.js → chunk-D5D3V6RU.js} +4 -4
  15. package/dist/{chunk-LTZH5E3G.js → chunk-DHAPQUEF.js} +235 -30
  16. package/dist/{chunk-LBXO4VPG.js → chunk-E4FJOLPJ.js} +6 -3
  17. package/dist/{chunk-OPYFEHKG.js → chunk-G7JONWL4.js} +29 -1
  18. package/dist/{chunk-4JUSGIMX.js → chunk-G7NN23YK.js} +2 -2
  19. package/dist/chunk-GPSOPGJA.js +7 -0
  20. package/dist/{chunk-LGO2SZAS.js → chunk-IKJOXDCF.js} +2 -2
  21. package/dist/{chunk-QEW4J3IZ.js → chunk-ISNRDHSD.js} +2 -2
  22. package/dist/{chunk-S3PIAMXV.js → chunk-J5XQW2CM.js} +68 -8
  23. package/dist/{chunk-LFR245MZ.js → chunk-JAICIL6H.js} +5 -5
  24. package/dist/{chunk-GZHHEHKY.js → chunk-JJBSYUSQ.js} +19 -7
  25. package/dist/{chunk-YSUINA5Q.js → chunk-MB72PZH7.js} +8 -8
  26. package/dist/{chunk-3CA3NNVH.js → chunk-MFPQDXUQ.js} +5 -5
  27. package/dist/{chunk-VQ2HEGWH.js → chunk-OKW7VKNQ.js} +2 -2
  28. package/dist/{chunk-6UXJ62XJ.js → chunk-OWW5VY4D.js} +3 -3
  29. package/dist/{chunk-OB3P5RMN.js → chunk-U2FPMGEM.js} +2 -2
  30. package/dist/{chunk-XELAZAIM.js → chunk-UD3BEEBQ.js} +54 -12
  31. package/dist/{chunk-EAWPJHJ7.js → chunk-UGODVKBJ.js} +2 -2
  32. package/dist/{chunk-MSOZPOPX.js → chunk-UOLV2AWA.js} +7 -3
  33. package/dist/{chunk-FBIDDE3N.js → chunk-XKGS2FNF.js} +71 -51
  34. package/dist/{chunk-XMXBE5IQ.js → chunk-XS2QM6AT.js} +5 -5
  35. package/dist/{chunk-45Y3KZ3Q.js → chunk-Y65MO2SS.js} +87 -20
  36. package/dist/{chunk-DAR6RGRN.js → chunk-YTSJRA4Z.js} +2 -2
  37. package/dist/{chunk-QBJC4DRP.js → chunk-ZYMJV7YX.js} +14 -14
  38. package/dist/{cli-ZN7ZVDEZ.js → cli-MUP2NSXT.js} +10 -9
  39. package/dist/{cli-MI4ZCAZ3.js → cli-T5LHBUY2.js} +8 -8
  40. package/dist/cli.js +3 -3
  41. package/dist/{completion-WYJAKJE4.js → completion-ZY5P443T.js} +2 -2
  42. package/dist/{diagnostics-ADIVFSBW.js → diagnostics-KUNS6LCZ.js} +12 -12
  43. package/dist/{doctor-BBCS4DF5.js → doctor-UH7KEOSO.js} +18 -19
  44. package/dist/{entry-DMOTX4SS.js → entry-DOUDMRO2.js} +10 -10
  45. package/dist/{exec-mcp-OBUM3DVW.js → exec-mcp-TGW6FXGC.js} +13 -14
  46. package/dist/{harness-6AUE3I4Q.js → harness-7HC6UR2D.js} +3 -3
  47. package/dist/harness-launch-gate.js +4 -4
  48. package/dist/harness-worker.js +6 -6
  49. package/dist/hook-body.js +446 -278
  50. package/dist/{hook-spec-C5fWTSCH.d.ts → hook-spec-0aGt29Pg.d.ts} +22 -2
  51. package/dist/{hooks-HLPQPVRY.js → hooks-L2MKB75Z.js} +3 -3
  52. package/dist/{host-5Q3X6OY7.js → host-OAQZTYII.js} +15 -16
  53. package/dist/{host-LGSWU3PJ.js → host-QSBXKTWT.js} +7 -7
  54. package/dist/{host-run-4NMQQASQ.js → host-run-HFOADX32.js} +10 -6
  55. package/dist/http.js +1 -1
  56. package/dist/{import-mcp-WU7TO2RT.js → import-mcp-BCYXJAIU.js} +11 -12
  57. package/dist/index.d.ts +2 -2
  58. package/dist/index.js +17 -18
  59. package/dist/{init-XA6XXLGA.js → init-NVJVNZOD.js} +2 -2
  60. package/dist/{invoke-CYQZYU5T.js → invoke-KVTEPXSC.js} +8 -8
  61. package/dist/{list-FNGXY5D7.js → list-2VRPMASP.js} +13 -14
  62. package/dist/{logout-N753FBZP.js → logout-6T5ZDLHQ.js} +12 -13
  63. package/dist/{logs-TBUA4UWU.js → logs-H3RPKNTE.js} +3 -4
  64. package/dist/{mailbox-BMTZOSZ7.js → mailbox-O3MX6QPF.js} +3 -4
  65. package/dist/{mainline-KAD2ERLP.js → mainline-DG75NLBS.js} +306 -57
  66. package/dist/{mcp-GR4VXKTG.js → mcp-7UKG5TD3.js} +2 -2
  67. package/dist/{pause-7LILUVGL.js → pause-2HQ7CKMR.js} +3 -4
  68. package/dist/project/hook-adapter.d.ts +1 -1
  69. package/dist/{project-OEBACWEX.js → project-BPKQOSKQ.js} +4 -4
  70. package/dist/{resume-26VFAAMH.js → resume-ETFTR5V3.js} +3 -4
  71. package/dist/{run-MDRUOEFL.js → run-5JD62E7R.js} +11 -12
  72. package/dist/{run-7XNGPU2I.js → run-WGIRM6Z7.js} +4 -4
  73. package/dist/{serve-HXHNWKEK.js → serve-J575WVIU.js} +3 -3
  74. package/dist/setup-T6T2PFC4.js +20 -0
  75. package/dist/{start-login-PWCEKNED.js → start-login-2AYCHWLV.js} +12 -13
  76. package/dist/{status-QFOBQ42J.js → status-2YWTJOMH.js} +20 -27
  77. package/dist/{status-54IYX2FN.js → status-425ZKIE6.js} +12 -13
  78. package/dist/{status-RO55QPKV.js → status-GPSLH4VO.js} +3 -4
  79. package/dist/stdio.js +2 -2
  80. package/dist/{sweep-35LGQTTO.js → sweep-VY2TNOO5.js} +3 -4
  81. package/dist/{test-36ZUVALT.js → test-XBLZOX52.js} +50 -15
  82. package/dist/{tui-CSRW4DN2.js → tui-WNVBHP65.js} +4 -4
  83. package/dist/{unbroadcast-5QNGAJR2.js → unbroadcast-RKTBP57G.js} +3 -4
  84. package/dist/{worker-EODWT4KK.js → worker-CGF3UIJE.js} +8 -8
  85. package/dist/{worktree-create-PZSRB7PH.js → worktree-create-NO4UOOEP.js} +2 -2
  86. package/dist/{worktree-list-JYB6VXLW.js → worktree-list-NEIDD66X.js} +4 -4
  87. package/dist/{worktree-sync-UF5CXPWV.js → worktree-sync-W4BDDLRO.js} +8 -9
  88. package/docs/commands.md +1 -1
  89. package/docs/git-workflow.md +58 -1
  90. package/docs/hooks.md +29 -0
  91. package/docs/project-configuration.md +7 -7
  92. package/gemini-extension.json +2 -2
  93. package/mcp.json +1 -1
  94. package/package.json +5 -5
  95. package/plugin.json +1 -1
  96. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  97. package/plugins/pmcp/.mcp.json +1 -1
  98. package/plugins/pmcp/gemini-extension.json +2 -2
  99. package/plugins/pmcp/mcp.json +1 -1
  100. package/plugins/pmcp/plugin.json +1 -1
  101. package/dist/chunk-26WLNWDG.js +0 -93
  102. package/dist/chunk-MZCRCMEY.js +0 -7
  103. package/dist/setup-DTKZLZUT.js +0 -18
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  gateTreePath,
3
3
  leaseSpecs
4
- } from "./chunk-GZHHEHKY.js";
4
+ } from "./chunk-JJBSYUSQ.js";
5
5
  import {
6
6
  off
7
7
  } from "./chunk-YIXDHQYE.js";
@@ -9,35 +9,49 @@ import {
9
9
  flockAvailable,
10
10
  lockFile
11
11
  } from "./chunk-DZ2MRTYT.js";
12
- import "./chunk-S3PIAMXV.js";
13
- import "./chunk-JS5RTH4I.js";
12
+ import "./chunk-J5XQW2CM.js";
13
+ import "./chunk-2Q6MNGU5.js";
14
14
  import {
15
15
  followPins,
16
- installIfStale
17
- } from "./chunk-XELAZAIM.js";
16
+ installIfStale,
17
+ installSpec,
18
+ installState,
19
+ lockHash
20
+ } from "./chunk-UD3BEEBQ.js";
18
21
  import {
19
22
  cherry,
20
23
  isAncestor,
21
24
  touchedPaths,
22
25
  undelivered
23
- } from "./chunk-QEW4J3IZ.js";
26
+ } from "./chunk-ISNRDHSD.js";
24
27
  import {
25
28
  git,
26
29
  gitOk,
27
30
  gitText,
28
- runCommand
29
- } from "./chunk-OPYFEHKG.js";
31
+ runCommand,
32
+ runCommandLogged
33
+ } from "./chunk-G7JONWL4.js";
30
34
  import {
31
35
  createFilesStore
32
- } from "./chunk-LTZH5E3G.js";
36
+ } from "./chunk-DHAPQUEF.js";
33
37
  import "./chunk-C4NHQGHL.js";
34
38
  import "./chunk-OEH47H6A.js";
35
39
  import "./chunk-IJBSOWHK.js";
36
40
  import "./chunk-QPL7E2HW.js";
37
41
  import "./chunk-PMJG2CXF.js";
38
42
 
43
+ // src/git/mainline/deliver.ts
44
+ import { readFileSync as readFileSync2 } from "fs";
45
+ import { loadavg } from "os";
46
+
39
47
  // src/git/mainline/gate.ts
40
- import { existsSync, mkdirSync, symlinkSync } from "fs";
48
+ import {
49
+ existsSync,
50
+ mkdirSync,
51
+ readdirSync,
52
+ rmSync,
53
+ symlinkSync
54
+ } from "fs";
41
55
  import { dirname, join } from "path";
42
56
  function gateTree(tree) {
43
57
  return { tree, lock: join(dirname(tree), "lock") };
@@ -96,17 +110,31 @@ function prepareGateTree(mainRoot, tree, tip, links) {
96
110
  }
97
111
  return null;
98
112
  }
99
- function runGate(mainRoot, tree, tip, command, links, report) {
113
+ var KEEP_LOGS = 20;
114
+ function gateLog(dir, tip) {
115
+ mkdirSync(dir, { recursive: true });
116
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/gu, "-");
117
+ const logs = readdirSync(dir).filter((name) => name.endsWith(".log")).sort();
118
+ for (const old of logs.slice(0, Math.max(0, logs.length - KEEP_LOGS + 1)))
119
+ rmSync(join(dir, old), { force: true });
120
+ return join(dir, `${stamp}-${tip.slice(0, 10)}.log`);
121
+ }
122
+ function runGate(mainRoot, tree, tip, command, links, report, lockEnv, logDir = join(dirname(tree), "logs")) {
100
123
  const problem = prepareGateTree(mainRoot, tree, tip, links);
101
124
  if (problem !== null) {
102
125
  report.warn(`the gate did not run: ${problem}`);
103
- return 1;
126
+ return { code: 1, log: null };
104
127
  }
105
- report.info(`gate on ${tip.slice(0, 10)} in ${tree}`);
106
- return runCommand(command, tree, {
128
+ const log = gateLog(logDir, tip);
129
+ report.info(`gate on ${tip.slice(0, 10)} in ${tree}; gate log: ${log}`);
130
+ const code = runCommandLogged(command, tree, log, {
107
131
  PMCP_GATE_TIP: tip,
108
- PMCP_GATE_MAIN: mainRoot
132
+ PMCP_GATE_MAIN: mainRoot,
133
+ ...lockEnv ? { [lockEnv]: "1" } : {}
109
134
  });
135
+ if (code !== 0)
136
+ report.warn(`the gate failed (exit ${code}); full gate log: ${log}`);
137
+ return { code, log };
110
138
  }
111
139
 
112
140
  // src/git/mainline/lock.ts
@@ -116,6 +144,7 @@ import {
116
144
  mkdirSync as mkdirSync2,
117
145
  openSync,
118
146
  readFileSync,
147
+ rmSync as rmSync2,
119
148
  writeFileSync
120
149
  } from "fs";
121
150
  import { dirname as dirname2, join as join2 } from "path";
@@ -169,6 +198,10 @@ function writeHolder(lockPath, holder) {
169
198
  writeFileSync(holderFile(lockPath), `${JSON.stringify(record)}
170
199
  `);
171
200
  }
201
+ function removeHolder(lockPath) {
202
+ if (readHolder(lockPath)?.pid === process.pid)
203
+ rmSync2(holderFile(lockPath), { force: true });
204
+ }
172
205
  function readHolder(lockPath) {
173
206
  try {
174
207
  return JSON.parse(readFileSync(holderFile(lockPath), "utf8"));
@@ -177,6 +210,79 @@ function readHolder(lockPath) {
177
210
  }
178
211
  }
179
212
 
213
+ // src/git/mainline/pins.ts
214
+ import { existsSync as existsSync2 } from "fs";
215
+ import { join as join3 } from "path";
216
+ var GITLINK = /^:(?:160000|000000) 160000 [0-9a-f]{40} ([0-9a-f]{40}) [AM]\t(.+)$/u;
217
+ function pins(root, upstream, tip) {
218
+ const raw = gitText(root, [
219
+ "diff",
220
+ "--raw",
221
+ "--abbrev=40",
222
+ "--no-renames",
223
+ upstream,
224
+ tip
225
+ ]);
226
+ const found = [];
227
+ for (const line of raw.split("\n")) {
228
+ const match = GITLINK.exec(line);
229
+ if (match) found.push([match[2], match[1]]);
230
+ }
231
+ return found;
232
+ }
233
+ function branchOf(root, path) {
234
+ const named = gitText(root, [
235
+ "config",
236
+ "-f",
237
+ ".gitmodules",
238
+ "--get",
239
+ `submodule.${path}.branch`
240
+ ]);
241
+ return named || "main";
242
+ }
243
+ function pushPins(root, upstream, tip, report) {
244
+ for (const [path, pin] of pins(root, upstream, tip)) {
245
+ const dir = join3(root, path);
246
+ const short = pin.slice(0, 10);
247
+ if (!existsSync2(join3(dir, ".git"))) {
248
+ report.warn(
249
+ `${path}: not checked out here, so ${short} cannot be pushed`
250
+ );
251
+ return false;
252
+ }
253
+ git(dir, ["fetch", "-q", "origin"]);
254
+ if (gitText(dir, ["branch", "-r", "--contains", pin]) !== "") {
255
+ report.info(`${path}: ${short} is already on its origin`);
256
+ continue;
257
+ }
258
+ if (!gitOk(dir, ["cat-file", "-e", `${pin}^{commit}`])) {
259
+ report.warn(`${path}: ${short} is neither here nor on its origin`);
260
+ return false;
261
+ }
262
+ const branch = branchOf(root, path);
263
+ const remote = `origin/${branch}`;
264
+ if (gitOk(dir, ["rev-parse", "-q", "--verify", remote]) && !gitOk(dir, ["merge-base", "--is-ancestor", remote, pin])) {
265
+ report.warn(
266
+ `${path}: ${remote} moved past what ${short} builds on; rebase the submodule change and pin it again`
267
+ );
268
+ return false;
269
+ }
270
+ const pushed = git(dir, [
271
+ "push",
272
+ "-q",
273
+ "origin",
274
+ `${pin}:refs/heads/${branch}`
275
+ ]);
276
+ if (pushed.status !== 0) {
277
+ report.warn(`${path}: pushing ${short} failed:
278
+ ${pushed.stderr.trim()}`);
279
+ return false;
280
+ }
281
+ report.info(`${path}: pushed ${short} to ${remote}`);
282
+ }
283
+ return true;
284
+ }
285
+
180
286
  // src/git/mainline/lease-wait.ts
181
287
  function foreign(store, specs) {
182
288
  for (const spec of specs) {
@@ -209,14 +315,14 @@ function waitForLeases(store, specs, waitSeconds, report, pollMs = 1e3) {
209
315
  }
210
316
 
211
317
  // src/git/mainline/replay.ts
212
- import { mkdtempSync, rmdirSync, rmSync } from "fs";
318
+ import { mkdtempSync, rmdirSync, rmSync as rmSync3 } from "fs";
213
319
  import { tmpdir } from "os";
214
- import { join as join3 } from "path";
320
+ import { join as join4 } from "path";
215
321
  function remove(root, dir) {
216
322
  const removed = git(root, ["worktree", "remove", "--force", dir]);
217
323
  if (removed.status !== 0)
218
324
  return `worktree cleanup failed; preserved ${dir}: ${removed.stderr.trim()}`;
219
- rmSync(dir, { recursive: true, force: true });
325
+ rmSync3(dir, { recursive: true, force: true });
220
326
  return null;
221
327
  }
222
328
  function pick(dir, commits) {
@@ -235,7 +341,7 @@ ${picked.stderr.trim()}`
235
341
  };
236
342
  }
237
343
  function replay(root, base, commits) {
238
- const dir = mkdtempSync(join3(tmpdir(), "pmcp-deliver-"));
344
+ const dir = mkdtempSync(join4(tmpdir(), "pmcp-deliver-"));
239
345
  const added = git(root, ["worktree", "add", "-q", "--detach", dir, base]);
240
346
  if (added.status !== 0) {
241
347
  rmdirSync(dir);
@@ -260,6 +366,7 @@ function attempts(options) {
260
366
  const { ctx, report } = options;
261
367
  const { lock, tree } = gateTree(options.tree);
262
368
  for (let attempt = 1; attempt <= options.deliver.attempts; attempt += 1) {
369
+ if (options.track) options.track.attempts = attempt;
263
370
  if (!fetch(ctx)) {
264
371
  report.warn(`fetch from ${ctx.remote} failed`);
265
372
  return 2;
@@ -284,16 +391,22 @@ function attempts(options) {
284
391
  return 1;
285
392
  }
286
393
  const command = options.gate?.command;
287
- if (command !== void 0 && runGate(
288
- ctx.mainRoot,
289
- tree,
290
- replayed.tip,
291
- command,
292
- options.links,
293
- report
294
- ) !== 0) {
295
- report.warn("the gate failed; nothing was pushed");
296
- return 1;
394
+ if (command !== void 0) {
395
+ const run = runGate(
396
+ ctx.mainRoot,
397
+ tree,
398
+ replayed.tip,
399
+ command,
400
+ options.links,
401
+ report,
402
+ options.gate?.lockEnv,
403
+ options.gate?.logDir
404
+ );
405
+ if (options.track) options.track.gate = { exit: run.code, log: run.log };
406
+ if (run.code !== 0) {
407
+ report.warn("the gate failed; nothing was pushed");
408
+ return 1;
409
+ }
297
410
  }
298
411
  const pushed = git(
299
412
  ctx.root,
@@ -303,6 +416,7 @@ function attempts(options) {
303
416
  }
304
417
  );
305
418
  if (pushed.status === 0) {
419
+ if (options.track) options.track.delivered = replayed.tip;
306
420
  report.info(`delivered ${replayed.tip.slice(0, 10)} to ${ctx.upstream}`);
307
421
  return 0;
308
422
  }
@@ -321,9 +435,51 @@ ${pushed.stderr.trim()}`
321
435
  );
322
436
  return 1;
323
437
  }
438
+ function hostLoad() {
439
+ try {
440
+ return Number(readFileSync2("/proc/loadavg", "utf8").split(" ")[0]);
441
+ } catch {
442
+ return loadavg()[0] ?? 0;
443
+ }
444
+ }
445
+ function loadAllows(options) {
446
+ const max = options.gate?.maxLoad;
447
+ if (max === void 0) return true;
448
+ const read = options.loadavg ?? hostLoad;
449
+ const wait = options.gate?.loadWaitSeconds ?? 1800;
450
+ const poll = options.loadPollMs ?? 15e3;
451
+ const deadline = Date.now() + wait * 1e3;
452
+ let load = read();
453
+ if (load < max) return true;
454
+ options.report.info(
455
+ `waiting for load ${load.toFixed(2)} to fall below ${max}`
456
+ );
457
+ while (Date.now() < deadline) {
458
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, poll);
459
+ load = read();
460
+ if (load < max) return true;
461
+ }
462
+ options.report.warn(
463
+ `load stayed at or above ${max} for ${wait}s (now ${load.toFixed(2)}); nothing ran`
464
+ );
465
+ return false;
466
+ }
467
+ function pinsPushed(options) {
468
+ const { ctx } = options;
469
+ const commits = undelivered(ctx.root, ctx.upstream, options.named);
470
+ const tip = commits.at(-1);
471
+ return tip === void 0 || pushPins(ctx.root, ctx.upstream, tip, options.report);
472
+ }
324
473
  function underLock(options) {
325
474
  const { lock } = gateTree(options.tree);
326
475
  const wait = options.gate?.lockWaitSeconds ?? 5400;
476
+ const lockEnv = options.gate?.lockEnv;
477
+ if (lockEnv && process.env[lockEnv] === "1") {
478
+ options.report.info(
479
+ `the gate lock is held by the caller (${lockEnv}=1); not taking it again`
480
+ );
481
+ return attempts(options);
482
+ }
327
483
  const held = acquireHostLock(lock, wait, () => {
328
484
  const holder = readHolder(lock);
329
485
  const who = holder === null ? "another delivery" : `${holder.tip.slice(0, 10)} "${holder.subject}" (pid ${holder.pid})`;
@@ -333,9 +489,17 @@ function underLock(options) {
333
489
  options.report.warn(`the gate lock stayed held for ${wait}s`);
334
490
  return 1;
335
491
  }
492
+ writeHolder(lock, {
493
+ tip: gitText(options.ctx.root, ["rev-parse", "HEAD"]),
494
+ subject: subject(options.ctx.root, "HEAD"),
495
+ checkout: options.ctx.root
496
+ });
336
497
  try {
498
+ if (!loadAllows(options)) return 1;
499
+ if (options.pushPins && !pinsPushed(options)) return 1;
337
500
  return attempts(options);
338
501
  } finally {
502
+ removeHolder(lock);
339
503
  held.release();
340
504
  }
341
505
  }
@@ -353,6 +517,29 @@ function blocked(options) {
353
517
  );
354
518
  }
355
519
  function deliver(options) {
520
+ const track = { attempts: 0, gate: null, delivered: null, leases: [] };
521
+ let reason;
522
+ const report = {
523
+ info: (line) => options.report.info(line),
524
+ warn: (line) => {
525
+ reason = line;
526
+ options.report.warn(line);
527
+ }
528
+ };
529
+ const code = deliverOnce({ ...options, report, track });
530
+ options.onReceipt?.({
531
+ ok: code === 0,
532
+ code,
533
+ delivered: track.delivered,
534
+ upstream: options.ctx.upstream,
535
+ attempts: track.attempts,
536
+ gate: track.gate,
537
+ leases: track.leases,
538
+ ...code !== 0 && reason ? { reason } : {}
539
+ });
540
+ return code;
541
+ }
542
+ function deliverOnce(options) {
356
543
  const { ctx, report } = options;
357
544
  const refusal2 = blocked(options);
358
545
  if (refusal2 !== null) {
@@ -383,11 +570,18 @@ function deliver(options) {
383
570
  return 1;
384
571
  }
385
572
  taken.push(spec.name);
573
+ options.track?.leases.push(spec.name);
386
574
  report.info(`took lease ${spec.name}`);
387
575
  }
388
576
  const code = underLock(options);
389
577
  if (code !== 0) return code;
390
578
  options.afterDeliver?.();
579
+ if (taken.length > 0)
580
+ options.recordDelivery?.({
581
+ leases: taken,
582
+ subject: lease.subject,
583
+ commit: gitText(ctx.root, ["rev-parse", "--short=10", ctx.upstream])
584
+ });
391
585
  if (options.deliver.notify !== void 0 && commits.length > 0)
392
586
  runCommand(options.deliver.notify, ctx.root, {
393
587
  PMCP_DELIVERED: gitText(ctx.root, ["rev-parse", ctx.upstream])
@@ -398,9 +592,41 @@ function deliver(options) {
398
592
  }
399
593
  }
400
594
 
595
+ // src/git/mainline/delivery-events.ts
596
+ import { appendFileSync, mkdirSync as mkdirSync3 } from "fs";
597
+ import { dirname as dirname3 } from "path";
598
+ function deliveryEvents(setup) {
599
+ return (delivery) => {
600
+ const specs = leaseSpecs(setup.config);
601
+ const sync = setup.config.sync;
602
+ const root = setup.ctx.mainRoot;
603
+ for (const name of delivery.leases) {
604
+ const events = setup.leaseFiles[name]?.events;
605
+ if (!events) continue;
606
+ const paths = specs.find((spec2) => spec2.name === name)?.paths ?? [];
607
+ const spec = installSpec(sync, setup.stateDir);
608
+ const state = spec ? installState(root, spec) : { hash: lockHash(root, paths), installed: false };
609
+ const { hash, installed } = state;
610
+ mkdirSync3(dirname3(events), { recursive: true });
611
+ appendFileSync(
612
+ events,
613
+ `${JSON.stringify({
614
+ at: (/* @__PURE__ */ new Date()).toISOString(),
615
+ subject: delivery.subject,
616
+ commit: delivery.commit,
617
+ hash,
618
+ installed,
619
+ lease: name
620
+ })}
621
+ `
622
+ );
623
+ }
624
+ };
625
+ }
626
+
401
627
  // src/git/mainline/store.ts
402
- function filesSessionGate(stateDir) {
403
- const store = createFilesStore(stateDir);
628
+ function filesSessionGate(stateDir, leaseFiles = {}) {
629
+ const store = createFilesStore(stateDir, { leaseFiles });
404
630
  return {
405
631
  pause: store.pause,
406
632
  leases: {
@@ -412,23 +638,23 @@ function filesSessionGate(stateDir) {
412
638
  }
413
639
 
414
640
  // src/git/mainline/sync.ts
415
- import { existsSync as existsSync3 } from "fs";
416
- import { join as join5 } from "path";
641
+ import { existsSync as existsSync4 } from "fs";
642
+ import { join as join6 } from "path";
417
643
 
418
644
  // src/git/mainline/identical-files.ts
419
645
  import { spawnSync as spawnSync2 } from "child_process";
420
646
  import {
421
647
  closeSync as closeSync2,
422
648
  copyFileSync,
423
- existsSync as existsSync2,
649
+ existsSync as existsSync3,
424
650
  lstatSync,
425
651
  mkdtempSync as mkdtempSync2,
426
652
  openSync as openSync2,
427
- readFileSync as readFileSync2,
653
+ readFileSync as readFileSync3,
428
654
  renameSync,
429
- rmSync as rmSync2
655
+ rmSync as rmSync4
430
656
  } from "fs";
431
- import { join as join4 } from "path";
657
+ import { join as join5 } from "path";
432
658
  var FILE_MODES = /* @__PURE__ */ new Set(["100644", "100755"]);
433
659
  function refuse(path) {
434
660
  return {
@@ -442,14 +668,14 @@ function identical(cwd, path, mode, oid) {
442
668
  if (!FILE_MODES.has(mode)) return false;
443
669
  let current = cwd;
444
670
  for (const segment of path.split("/")) {
445
- current = join4(current, segment);
671
+ current = join5(current, segment);
446
672
  if (lstatSync(current).isSymbolicLink()) return false;
447
673
  }
448
674
  const stat = lstatSync(current);
449
675
  if (!stat.isFile()) return false;
450
676
  if (Boolean(stat.mode & 73) !== (mode === "100755")) return false;
451
677
  const blob = spawnSync2("git", ["cat-file", "blob", oid], { cwd });
452
- return blob.status === 0 && readFileSync2(current).equals(blob.stdout);
678
+ return blob.status === 0 && readFileSync3(current).equals(blob.stdout);
453
679
  }
454
680
  function adopt(cwd, target, env) {
455
681
  const incoming = git(cwd, ["ls-tree", "-rz", "--full-tree", target], env);
@@ -467,7 +693,7 @@ function adopt(cwd, target, env) {
467
693
  if (!match) continue;
468
694
  const [, mode = "", oid = "", path = ""] = match;
469
695
  if (existing.has(path)) continue;
470
- if (!lstatSync(join4(cwd, path), { throwIfNoEntry: false })) continue;
696
+ if (!lstatSync(join5(cwd, path), { throwIfNoEntry: false })) continue;
471
697
  if (!identical(cwd, path, mode, oid)) return refuse(path);
472
698
  const added = git(
473
699
  cwd,
@@ -494,7 +720,7 @@ function resetKeepingIdenticalFiles(cwd, target) {
494
720
  try {
495
721
  fd = openSync2(lock, "wx");
496
722
  temporary = mkdtempSync2(`${index}.sync-`);
497
- const scratch = join4(temporary, "index");
723
+ const scratch = join5(temporary, "index");
498
724
  copyFileSync(index, scratch);
499
725
  const env = { GIT_INDEX_FILE: scratch };
500
726
  const refused = adopt(cwd, target, env);
@@ -506,7 +732,7 @@ function resetKeepingIdenticalFiles(cwd, target) {
506
732
  closeSync2(fd);
507
733
  fd = void 0;
508
734
  renameSync(lock, index);
509
- rmSync2(temporary, { recursive: true, force: true });
735
+ rmSync4(temporary, { recursive: true, force: true });
510
736
  return moved;
511
737
  } catch (error) {
512
738
  const recovery = movedHead ? `; HEAD moved, recovery index kept at ${temporary}/index` : "";
@@ -516,8 +742,8 @@ function resetKeepingIdenticalFiles(cwd, target) {
516
742
  } finally {
517
743
  if (fd !== void 0) closeSync2(fd);
518
744
  if (temporary !== void 0 && !movedHead)
519
- rmSync2(temporary, { recursive: true, force: true });
520
- if (fd !== void 0 && !movedHead && existsSync2(lock)) rmSync2(lock);
745
+ rmSync4(temporary, { recursive: true, force: true });
746
+ if (fd !== void 0 && !movedHead && existsSync3(lock)) rmSync4(lock);
521
747
  }
522
748
  }
523
749
 
@@ -538,20 +764,15 @@ function refusal(ctx) {
538
764
  if (branch !== ctx.mainline)
539
765
  return `the main checkout is on ${branch || "a detached HEAD"}, not ${ctx.mainline}`;
540
766
  for (const marker of IN_PROGRESS) {
541
- if (existsSync3(join5(ctx.gitDir, marker)))
767
+ if (existsSync4(join6(ctx.gitDir, marker)))
542
768
  return `${marker} is present; another git command is running or unfinished`;
543
769
  }
544
770
  return null;
545
771
  }
546
772
  function install(options) {
547
773
  const { ctx, sync, report } = options;
548
- if (sync.install === void 0 || sync.installWhenChanged.length === 0)
549
- return 0;
550
- const spec = {
551
- command: sync.install,
552
- when: sync.installWhenChanged,
553
- stateDir: options.stateDir
554
- };
774
+ const spec = installSpec(sync, options.stateDir);
775
+ if (spec === void 0) return 0;
555
776
  const status = installIfStale(ctx.root, spec, report);
556
777
  if (status === null || status === 0) return 0;
557
778
  return 1;
@@ -594,7 +815,13 @@ ${moved.stderr.trim()}`
594
815
  `${ctx.mainline} ${head.slice(0, 10)} -> ${target.slice(0, 10)}; dropped ${carried.length} landed duplicate(s), uncommitted edits kept`
595
816
  );
596
817
  if (options.followSubmodules) {
597
- for (const line of followPins(ctx.root, head, target)) report.info(line);
818
+ for (const line of followPins(
819
+ ctx.root,
820
+ head,
821
+ target,
822
+ options.sharedSubmodules
823
+ ))
824
+ report.info(line);
598
825
  }
599
826
  return install(options);
600
827
  }
@@ -604,7 +831,15 @@ var mainlineSync = (setup, _context, report) => {
604
831
  const sync = setup.config.sync ?? off("git.mainline.sync");
605
832
  const followSubmodules = setup.config.submodules?.follow === "clean_pins";
606
833
  const { ctx, stateDir } = setup;
607
- return syncMainline({ ctx, sync, followSubmodules, stateDir, report });
834
+ const sharedSubmodules = setup.config.submodules?.shared ?? [];
835
+ return syncMainline({
836
+ ctx,
837
+ sync,
838
+ followSubmodules,
839
+ sharedSubmodules,
840
+ stateDir,
841
+ report
842
+ });
608
843
  };
609
844
  var mainlineDeliver = (setup, context, report) => {
610
845
  const { config, ctx, stateDir } = setup;
@@ -613,7 +848,15 @@ var mainlineDeliver = (setup, context, report) => {
613
848
  const afterDeliver = () => {
614
849
  if (sync === void 0 || ctx.linked) return;
615
850
  const followSubmodules = config.submodules?.follow === "clean_pins";
616
- if (syncMainline({ ctx, sync, followSubmodules, stateDir, report }) !== 0)
851
+ const sharedSubmodules = config.submodules?.shared ?? [];
852
+ if (syncMainline({
853
+ ctx,
854
+ sync,
855
+ followSubmodules,
856
+ sharedSubmodules,
857
+ stateDir,
858
+ report
859
+ }) !== 0)
617
860
  report.warn(
618
861
  "delivered; only the main checkout did not catch up, run pmcp git sync after the refusal above is cleared"
619
862
  );
@@ -626,9 +869,15 @@ var mainlineDeliver = (setup, context, report) => {
626
869
  tree: gateTreePath(setup),
627
870
  links: config.worktrees?.linkFromMain ?? [],
628
871
  leases: leaseSpecs(config),
629
- store: filesSessionGate(setup.stateDir),
872
+ store: filesSessionGate(setup.stateDir, setup.leaseFiles),
630
873
  duringPause: context.args.flags.has("during-pause"),
631
874
  afterDeliver,
875
+ recordDelivery: deliveryEvents(setup),
876
+ pushPins: config.submodules?.push === "pins",
877
+ ...context.args.flags.has("json") ? {
878
+ onReceipt: (receipt) => context.ui.data(`${JSON.stringify(receipt)}
879
+ `)
880
+ } : {},
632
881
  report
633
882
  });
634
883
  };
@@ -636,4 +885,4 @@ export {
636
885
  mainlineDeliver,
637
886
  mainlineSync
638
887
  };
639
- //# sourceMappingURL=mainline-KAD2ERLP.js.map
888
+ //# sourceMappingURL=mainline-DG75NLBS.js.map
@@ -5,11 +5,11 @@ import "./chunk-XNML2KIC.js";
5
5
 
6
6
  // src/commands/mcp.ts
7
7
  async function run(context) {
8
- const { executeMcpCommand } = await import("./run-7XNGPU2I.js");
8
+ const { executeMcpCommand } = await import("./run-WGIRM6Z7.js");
9
9
  return executeMcpCommand(context);
10
10
  }
11
11
  var mcpCommand = { ...mcpSpec, run };
12
12
  export {
13
13
  mcpCommand
14
14
  };
15
- //# sourceMappingURL=mcp-GR4VXKTG.js.map
15
+ //# sourceMappingURL=mcp-7UKG5TD3.js.map
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  change
3
- } from "./chunk-LBXO4VPG.js";
4
- import "./chunk-26WLNWDG.js";
5
- import "./chunk-LTZH5E3G.js";
3
+ } from "./chunk-E4FJOLPJ.js";
4
+ import "./chunk-DHAPQUEF.js";
6
5
  import "./chunk-C4NHQGHL.js";
7
6
  import "./chunk-A4PKLESO.js";
8
7
  import "./chunk-OEH47H6A.js";
@@ -15,4 +14,4 @@ var run = (context) => change(context, "pause");
15
14
  export {
16
15
  run
17
16
  };
18
- //# sourceMappingURL=pause-7LILUVGL.js.map
17
+ //# sourceMappingURL=pause-2HQ7CKMR.js.map
@@ -1,4 +1,4 @@
1
- import { S as ShellHookSpec, H as HookTool } from '../hook-spec-C5fWTSCH.js';
1
+ import { S as ShellHookSpec, H as HookTool } from '../hook-spec-0aGt29Pg.js';
2
2
 
3
3
  declare function guardPath(root: string, command: readonly string[]): string;
4
4
 
@@ -19,7 +19,7 @@ async function route(context, verb, name) {
19
19
  if (name === void 0 || context.args.flags.has("check") || context.args.flags.has("write") || many(context.args, "source").length > 0 || many(context.args, "name").length > 0) {
20
20
  throw new ArgumentError("exec-mcp takes only a declared MCP alias");
21
21
  }
22
- const { runExecMcp } = await import("./exec-mcp-OBUM3DVW.js");
22
+ const { runExecMcp } = await import("./exec-mcp-TGW6FXGC.js");
23
23
  return await runExecMcp(context, name);
24
24
  }
25
25
  if (verb === "import-mcp") {
@@ -28,13 +28,13 @@ async function route(context, verb, name) {
28
28
  "import-mcp takes --source, --name and --write; no positional name or --check"
29
29
  );
30
30
  }
31
- const { importMcp } = await import("./import-mcp-WU7TO2RT.js");
31
+ const { importMcp } = await import("./import-mcp-BCYXJAIU.js");
32
32
  return importMcp(context);
33
33
  }
34
34
  if (many(context.args, "source").length > 0 || one(context.args, "name") !== void 0 || context.args.flags.has("write")) {
35
35
  throw new ArgumentError("--source, --name and --write require import-mcp");
36
36
  }
37
- const apply = await import("./apply-75UWIUVQ.js");
37
+ const apply = await import("./apply-IPTASVRS.js");
38
38
  if (verb === void 0) return apply.projectOrCheck(context);
39
39
  if (context.args.flags.has("check")) {
40
40
  throw new ArgumentError("--check takes no subcommand");
@@ -67,4 +67,4 @@ var projectCommand = {
67
67
  export {
68
68
  projectCommand
69
69
  };
70
- //# sourceMappingURL=project-OEBACWEX.js.map
70
+ //# sourceMappingURL=project-BPKQOSKQ.js.map