@modootoday/pmcp 0.18.4 → 0.19.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.
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-JVLYYXAG.js} +16 -17
  6. package/dist/{broadcast-CBMVOV3G.js → broadcast-56NPEJWM.js} +3 -4
  7. package/dist/{chunk-JS5RTH4I.js → chunk-2Q6MNGU5.js} +2 -2
  8. package/dist/{chunk-YSUINA5Q.js → chunk-3O3FS6KM.js} +8 -8
  9. package/dist/{chunk-6UXJ62XJ.js → chunk-3TG3KVHZ.js} +3 -3
  10. package/dist/{chunk-LGO2SZAS.js → chunk-47ZGCZQA.js} +2 -2
  11. package/dist/{chunk-TFRJ5QOS.js → chunk-4LV7KDTS.js} +3 -3
  12. package/dist/{chunk-DAR6RGRN.js → chunk-6MZTOC6H.js} +2 -2
  13. package/dist/{chunk-LFR245MZ.js → chunk-CYQIAEQT.js} +5 -5
  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-FGEBSQQJ.js +7 -0
  18. package/dist/{chunk-OPYFEHKG.js → chunk-G7JONWL4.js} +29 -1
  19. package/dist/{chunk-4JUSGIMX.js → chunk-HEPSITZX.js} +2 -2
  20. package/dist/{chunk-YRGDWUFY.js → chunk-IEK4U5RR.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-GZHHEHKY.js → chunk-JJBSYUSQ.js} +19 -7
  24. package/dist/{chunk-45Y3KZ3Q.js → chunk-KHQQGBFJ.js} +87 -20
  25. package/dist/{chunk-XMXBE5IQ.js → chunk-LCENQ6JR.js} +5 -5
  26. package/dist/{chunk-HE2C2S5A.js → chunk-NLKAEKSG.js} +3 -3
  27. package/dist/{chunk-ARA4VDHD.js → chunk-OHW3A7Z3.js} +2 -2
  28. package/dist/{chunk-ZWLUH3F2.js → chunk-PFWTGEZJ.js} +2 -2
  29. package/dist/{chunk-3CA3NNVH.js → chunk-Q3GLKL4B.js} +5 -5
  30. package/dist/{chunk-MSOZPOPX.js → chunk-QJRJCXX2.js} +7 -3
  31. package/dist/{chunk-R26RWSFW.js → chunk-QXRD7N35.js} +2 -2
  32. package/dist/{chunk-OB3P5RMN.js → chunk-TPLV2YX2.js} +2 -2
  33. package/dist/{chunk-XELAZAIM.js → chunk-UD3BEEBQ.js} +54 -12
  34. package/dist/{chunk-EAWPJHJ7.js → chunk-UGODVKBJ.js} +2 -2
  35. package/dist/{chunk-QBJC4DRP.js → chunk-UQNCBXXH.js} +14 -14
  36. package/dist/{chunk-VQ2HEGWH.js → chunk-WJJ2KYE4.js} +2 -2
  37. package/dist/{chunk-FBIDDE3N.js → chunk-Y2MZ5RE3.js} +71 -51
  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-CCK3LWVR.js} +2 -2
  42. package/dist/{diagnostics-ADIVFSBW.js → diagnostics-6WON3VMZ.js} +12 -12
  43. package/dist/{doctor-BBCS4DF5.js → doctor-UEXUOW5O.js} +18 -19
  44. package/dist/{entry-DMOTX4SS.js → entry-GMC6LRO2.js} +10 -10
  45. package/dist/{exec-mcp-OBUM3DVW.js → exec-mcp-FS7IPXNC.js} +13 -14
  46. package/dist/{harness-6AUE3I4Q.js → harness-32PERNQY.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-VQCLHXRZ.js} +3 -3
  52. package/dist/{host-LGSWU3PJ.js → host-4WNPLAD5.js} +7 -7
  53. package/dist/{host-5Q3X6OY7.js → host-ED3XRUNM.js} +15 -16
  54. package/dist/{host-run-4NMQQASQ.js → host-run-PNY6NAYW.js} +10 -6
  55. package/dist/http.js +1 -1
  56. package/dist/{import-mcp-WU7TO2RT.js → import-mcp-WEUY6IVK.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-5ZDPHPWB.js} +2 -2
  60. package/dist/{invoke-CYQZYU5T.js → invoke-MB4SWBIE.js} +8 -8
  61. package/dist/{list-FNGXY5D7.js → list-U4SUFIS7.js} +13 -14
  62. package/dist/{logout-N753FBZP.js → logout-M76LEHVP.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-NSKAEV7J.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-FTXIKBML.js} +4 -4
  70. package/dist/{resume-26VFAAMH.js → resume-ETFTR5V3.js} +3 -4
  71. package/dist/{run-7XNGPU2I.js → run-UMHKF2GM.js} +4 -4
  72. package/dist/{run-MDRUOEFL.js → run-Y7NKULSP.js} +11 -12
  73. package/dist/{serve-HXHNWKEK.js → serve-MRWTSSAU.js} +3 -3
  74. package/dist/setup-T6T2PFC4.js +20 -0
  75. package/dist/{start-login-PWCEKNED.js → start-login-POISLJD2.js} +12 -13
  76. package/dist/{status-QFOBQ42J.js → status-GGDHOPSE.js} +20 -27
  77. package/dist/{status-RO55QPKV.js → status-GPSLH4VO.js} +3 -4
  78. package/dist/{status-54IYX2FN.js → status-XMATSURN.js} +12 -13
  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-ULKQY6FV.js} +50 -15
  82. package/dist/{tui-CSRW4DN2.js → tui-NGBCIBRW.js} +4 -4
  83. package/dist/{unbroadcast-5QNGAJR2.js → unbroadcast-RKTBP57G.js} +3 -4
  84. package/dist/{worker-EODWT4KK.js → worker-Q7JWY6BR.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
@@ -9,6 +9,10 @@ import {
9
9
  isLive,
10
10
  leaseFile
11
11
  } from "./chunk-C4NHQGHL.js";
12
+ import {
13
+ expandPath,
14
+ projectStateDir
15
+ } from "./chunk-OEH47H6A.js";
12
16
  import {
13
17
  checkoutOf
14
18
  } from "./chunk-IJBSOWHK.js";
@@ -127,10 +131,10 @@ function filesBroadcast(dir, keep, registry) {
127
131
  return {
128
132
  list,
129
133
  unseen(session) {
130
- const record = registry.get(session);
131
- const own = new Set([session, record?.alias].filter(Boolean));
132
- const seen = Number(record?.seenBroadcast ?? 0);
133
- const started = Date.parse(record?.startedAt ?? "") || 0;
134
+ const record2 = registry.get(session);
135
+ const own = new Set([session, record2?.alias].filter(Boolean));
136
+ const seen = Number(record2?.seenBroadcast ?? 0);
137
+ const started = Date.parse(record2?.startedAt ?? "") || 0;
134
138
  const all = list();
135
139
  const latest = all.at(-1);
136
140
  const unseen = all.filter(
@@ -159,33 +163,59 @@ function filesBroadcast(dir, keep, registry) {
159
163
  }
160
164
 
161
165
  // src/sessions/files/leases.ts
162
- import { rmSync as rmSync2 } from "fs";
163
- import { join as join2 } from "path";
164
- var leasePath = (dir, name) => join2(dir, leaseFile(name));
165
- function filesLeases(dir) {
166
+ import {
167
+ linkSync,
168
+ mkdirSync as mkdirSync2,
169
+ renameSync as renameSync2,
170
+ rmSync as rmSync2,
171
+ writeFileSync as writeFileSync2
172
+ } from "fs";
173
+ import { dirname as dirname2, join as join2 } from "path";
174
+ function filesLeases(dir, files = {}) {
175
+ const leasePath = (name) => files[name]?.file ?? join2(dir, leaseFile(name));
166
176
  const read = (name) => {
167
- const lease = asLease(readJson(leasePath(dir, name)));
177
+ const lease = asLease(readJson(leasePath(name)));
168
178
  if (!lease || !alive(lease.pid)) return null;
169
179
  return lease;
170
180
  };
171
181
  return {
172
182
  read,
183
+ // Atomic against another process taking the same file (another tool may share it): the
184
+ // record is linked into place, and a dead holder's record is replaced and then re-read, so
185
+ // of two takers replacing it at once only the one whose record stays holds the lease.
173
186
  take(name, lease) {
174
- const held = read(name);
187
+ const path = leasePath(name);
175
188
  const pid = lease.pid ?? process.pid;
176
- if (held && held.pid !== pid) return false;
177
- writeJson(leasePath(dir, name), {
189
+ const record2 = {
178
190
  pid,
179
191
  subject: lease.subject,
180
192
  ...lease.cwd ? { cwd: lease.cwd } : {},
181
193
  since: (/* @__PURE__ */ new Date()).toISOString()
182
- });
183
- return true;
194
+ };
195
+ mkdirSync2(dirname2(path), { recursive: true });
196
+ const temp = `${path}.${process.pid}.${Date.now()}.tmp`;
197
+ writeFileSync2(temp, `${JSON.stringify(record2)}
198
+ `);
199
+ try {
200
+ try {
201
+ linkSync(temp, path);
202
+ return true;
203
+ } catch (error) {
204
+ if (error.code !== "EEXIST") throw error;
205
+ }
206
+ const held = read(name);
207
+ if (held && held.pid !== pid) return false;
208
+ renameSync2(temp, path);
209
+ return asLease(readJson(path))?.pid === pid;
210
+ } finally {
211
+ rmSync2(temp, { force: true });
212
+ }
184
213
  },
185
214
  release(name, pid = process.pid) {
186
- const held = asLease(readJson(leasePath(dir, name)));
215
+ const path = leasePath(name);
216
+ const held = asLease(readJson(path));
187
217
  if (!held || held.pid === pid || !alive(held.pid)) {
188
- rmSync2(leasePath(dir, name), { force: true });
218
+ rmSync2(path, { force: true });
189
219
  }
190
220
  }
191
221
  };
@@ -195,12 +225,12 @@ function filesLeases(dir) {
195
225
  import {
196
226
  appendFileSync,
197
227
  existsSync,
198
- linkSync,
199
- mkdirSync as mkdirSync2,
228
+ linkSync as linkSync2,
229
+ mkdirSync as mkdirSync3,
200
230
  readdirSync,
201
231
  rmSync as rmSync3,
202
232
  unlinkSync,
203
- writeFileSync as writeFileSync2
233
+ writeFileSync as writeFileSync3
204
234
  } from "fs";
205
235
  import { join as join3 } from "path";
206
236
 
@@ -265,9 +295,9 @@ function filesMailbox(dir, settings) {
265
295
  });
266
296
  };
267
297
  const touch = (path) => {
268
- mkdirSync2(join3(path, ".."), { recursive: true, mode: 448 });
298
+ mkdirSync3(join3(path, ".."), { recursive: true, mode: 448 });
269
299
  try {
270
- writeFileSync2(path, "", { flag: "wx", mode: 384 });
300
+ writeFileSync3(path, "", { flag: "wx", mode: 384 });
271
301
  return true;
272
302
  } catch {
273
303
  return false;
@@ -288,7 +318,7 @@ function filesMailbox(dir, settings) {
288
318
  return {
289
319
  settings,
290
320
  send(input) {
291
- mkdirSync2(messages, { recursive: true, mode: 448 });
321
+ mkdirSync3(messages, { recursive: true, mode: 448 });
292
322
  const created = Date.now();
293
323
  const ttl = input.ttlMinutes ?? settings.ttlMinutes;
294
324
  for (let attempt = 0; ; attempt += 1) {
@@ -308,12 +338,12 @@ function filesMailbox(dir, settings) {
308
338
  ...input.broadcastId ? { broadcastId: input.broadcastId } : {}
309
339
  };
310
340
  const temporary = `${pathOf(id)}.${process.pid}.tmp`;
311
- writeFileSync2(temporary, `${JSON.stringify(message, null, 2)}
341
+ writeFileSync3(temporary, `${JSON.stringify(message, null, 2)}
312
342
  `, {
313
343
  mode: 384
314
344
  });
315
345
  try {
316
- linkSync(temporary, pathOf(id));
346
+ linkSync2(temporary, pathOf(id));
317
347
  } catch {
318
348
  continue;
319
349
  } finally {
@@ -393,7 +423,7 @@ function filesRegistry(dir, staleMs) {
393
423
  } catch {
394
424
  return [];
395
425
  }
396
- return names.map((name) => asRecord(readJson(join5(fleetDir, name)))).filter((record) => record !== null).map((record) => ({ ...record, live: isLive(record, now, staleMs) }));
426
+ return names.map((name) => asRecord(readJson(join5(fleetDir, name)))).filter((record2) => record2 !== null).map((record2) => ({ ...record2, live: isLive(record2, now, staleMs) }));
397
427
  };
398
428
  const remove = (session) => {
399
429
  if (SESSION_ID.test(session)) rmSync5(pathOf(session), { force: true });
@@ -420,8 +450,8 @@ function filesRegistry(dir, staleMs) {
420
450
  return next;
421
451
  },
422
452
  sweep(now = Date.now()) {
423
- const stale = list(now).filter((record) => !record.live);
424
- stale.forEach((record) => remove(record.session));
453
+ const stale = list(now).filter((record2) => !record2.live);
454
+ stale.forEach((record2) => remove(record2.session));
425
455
  return stale.length;
426
456
  }
427
457
  };
@@ -442,7 +472,7 @@ function createFilesStore(dir, options = {}) {
442
472
  dir,
443
473
  registry,
444
474
  pause: filesPause(dir),
445
- leases: filesLeases(dir),
475
+ leases: filesLeases(dir, options.leaseFiles),
446
476
  // With the mailbox on, a broadcast is also a message to all, which the mailbox delivers;
447
477
  // broadcast.json stays the record status, snapshot and the Claude band read.
448
478
  broadcast: !mailbox.settings.enabled ? broadcast : {
@@ -466,6 +496,178 @@ function createFilesStore(dir, options = {}) {
466
496
  };
467
497
  }
468
498
 
499
+ // src/sessions/lease-files.ts
500
+ import { dirname as dirname3, isAbsolute, join as join6 } from "path";
501
+ var GATE_DIR = "${gate_dir}/";
502
+ function record(value, where) {
503
+ if (value === null || typeof value !== "object" || Array.isArray(value))
504
+ throw new Error(`${where} must be a table`);
505
+ return value;
506
+ }
507
+ function setting(value, where) {
508
+ if (value === void 0) return void 0;
509
+ if (typeof value !== "string" || value === "")
510
+ throw new Error(`${where} must be a path`);
511
+ if (value.startsWith(GATE_DIR)) return value;
512
+ const home = value === "~" || value.startsWith("~/") || value.startsWith("$HOME/");
513
+ const path = home ? expandPath("/", value) : value;
514
+ if (!isAbsolute(path))
515
+ throw new Error(
516
+ `${where} must be absolute, start with ~/ or start with \${gate_dir}/`
517
+ );
518
+ return path;
519
+ }
520
+ function readLeaseFiles(leases) {
521
+ if (leases === void 0) return {};
522
+ const out = {};
523
+ for (const [name, raw] of Object.entries(
524
+ record(leases, "[sessions.leases]")
525
+ )) {
526
+ const where = `[sessions.leases.${name}]`;
527
+ const table2 = record(raw, where);
528
+ const file = setting(table2["file"], `${where} file`);
529
+ const events = setting(table2["events"], `${where} events`);
530
+ if (file || events)
531
+ out[name] = { ...file ? { file } : {}, ...events ? { events } : {} };
532
+ }
533
+ return out;
534
+ }
535
+ function readGateLocation(git) {
536
+ if (git === null || typeof git !== "object") return {};
537
+ const mainline = git["mainline"];
538
+ if (mainline === null || typeof mainline !== "object") return {};
539
+ const gate = mainline["gate"];
540
+ if (gate === null || typeof gate !== "object") return {};
541
+ const { tree, tree_env: treeEnv } = gate;
542
+ return {
543
+ ...typeof tree === "string" ? { tree } : {},
544
+ ...typeof treeEnv === "string" ? { treeEnv } : {}
545
+ };
546
+ }
547
+ function gateTree(root, stateDir, gate, env) {
548
+ const override = gate.treeEnv ? env[gate.treeEnv] : void 0;
549
+ if (override) return override;
550
+ return gate.tree ? expandPath(root, gate.tree) : join6(stateDir, "gate", "tree");
551
+ }
552
+ function resolveLeaseFiles(files, gateDir) {
553
+ const resolve2 = (path) => path?.startsWith(GATE_DIR) ? join6(gateDir, path.slice(GATE_DIR.length)) : path;
554
+ return Object.fromEntries(
555
+ Object.entries(files ?? {}).map(([name, f]) => {
556
+ const file = resolve2(f.file);
557
+ const events = resolve2(f.events);
558
+ return [
559
+ name,
560
+ { ...file ? { file } : {}, ...events ? { events } : {} }
561
+ ];
562
+ })
563
+ );
564
+ }
565
+ function leaseFilesFor(root, stateDir, files, gate, env) {
566
+ if (!files || Object.keys(files).length === 0) return {};
567
+ return resolveLeaseFiles(
568
+ files,
569
+ dirname3(gateTree(root, stateDir, gate ?? {}, env))
570
+ );
571
+ }
572
+
573
+ // src/sessions/settings.ts
574
+ var MAILBOX_KEYS = [
575
+ "enabled",
576
+ "ttl_minutes",
577
+ "max_delivered",
578
+ "audit",
579
+ "wake"
580
+ ];
581
+ function flag(value, where, fallback) {
582
+ if (value === void 0) return fallback;
583
+ if (typeof value !== "boolean")
584
+ throw new Error(`${where} must be true or false`);
585
+ return value;
586
+ }
587
+ function readMailbox(raw) {
588
+ if (raw === void 0)
589
+ return { enabled: false, ttlMinutes: 1440, maxDelivered: 5, audit: true };
590
+ const mailbox = table(raw, "[sessions.mailbox]");
591
+ const unknown = Object.keys(mailbox).find(
592
+ (key) => !MAILBOX_KEYS.includes(key)
593
+ );
594
+ if (unknown) throw new Error(`[sessions.mailbox] unknown key ${unknown}`);
595
+ return {
596
+ enabled: flag(mailbox["enabled"], "[sessions.mailbox] enabled", true),
597
+ ttlMinutes: positiveInteger(
598
+ mailbox["ttl_minutes"],
599
+ "[sessions.mailbox] ttl_minutes",
600
+ 1440
601
+ ),
602
+ maxDelivered: positiveInteger(
603
+ mailbox["max_delivered"],
604
+ "[sessions.mailbox] max_delivered",
605
+ 5
606
+ ),
607
+ audit: flag(mailbox["audit"], "[sessions.mailbox] audit", true),
608
+ // Only when on, so mailboxes without wake keep the same compiled policy and hash.
609
+ ...flag(mailbox["wake"], "[sessions.mailbox] wake", false) ? { wake: true } : {}
610
+ };
611
+ }
612
+ function table(value, where) {
613
+ if (value === void 0) return {};
614
+ if (value === null || typeof value !== "object" || Array.isArray(value))
615
+ throw new Error(`${where} must be a table`);
616
+ return value;
617
+ }
618
+ function positiveInteger(value, where, fallback) {
619
+ if (value === void 0) return fallback;
620
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
621
+ throw new Error(`${where} must be a positive integer`);
622
+ }
623
+ return value;
624
+ }
625
+ function readStoreSettings(raw, git) {
626
+ const sessions = table(raw, "[sessions]");
627
+ if ((sessions["store"] ?? "files") !== "files")
628
+ throw new Error('[sessions] store must be "files"');
629
+ const stateDir = sessions["state_dir"];
630
+ if (stateDir !== void 0 && (typeof stateDir !== "string" || stateDir === "")) {
631
+ throw new Error("[sessions] state_dir must be a path");
632
+ }
633
+ const registry = table(sessions["registry"], "[sessions.registry]");
634
+ const broadcast = table(sessions["broadcast"], "[sessions.broadcast]");
635
+ return {
636
+ ...typeof stateDir === "string" ? { stateDir } : {},
637
+ staleMs: positiveInteger(
638
+ registry["stale_minutes"],
639
+ "[sessions.registry] stale_minutes",
640
+ 30
641
+ ) * 6e4,
642
+ keepBroadcasts: positiveInteger(
643
+ broadcast["keep"],
644
+ "[sessions.broadcast] keep",
645
+ 10
646
+ ),
647
+ mailbox: readMailbox(sessions["mailbox"]),
648
+ ...leaseSettings(sessions["leases"], git)
649
+ };
650
+ }
651
+ function leaseSettings(leases, git) {
652
+ const leaseFiles = readLeaseFiles(leases);
653
+ if (Object.keys(leaseFiles).length === 0) return {};
654
+ const gate = readGateLocation(git);
655
+ return { leaseFiles, ...Object.keys(gate).length > 0 ? { gate } : {} };
656
+ }
657
+ function openStore(root, settings, env = process.env) {
658
+ const dir = projectStateDir(root, settings.stateDir, env);
659
+ return createFilesStore(dir, {
660
+ ...settings,
661
+ leaseFiles: leaseFilesFor(
662
+ root,
663
+ dir,
664
+ settings.leaseFiles,
665
+ settings.gate,
666
+ env
667
+ )
668
+ });
669
+ }
670
+
469
671
  export {
470
672
  noticeOf,
471
673
  normalizeSelector,
@@ -474,6 +676,9 @@ export {
474
676
  inboxKey,
475
677
  writeJson,
476
678
  SESSION_ID,
477
- createFilesStore
679
+ createFilesStore,
680
+ resolveLeaseFiles,
681
+ readStoreSettings,
682
+ openStore
478
683
  };
479
- //# sourceMappingURL=chunk-LTZH5E3G.js.map
684
+ //# sourceMappingURL=chunk-DHAPQUEF.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  openStore,
3
3
  readStoreSettings
4
- } from "./chunk-26WLNWDG.js";
4
+ } from "./chunk-DHAPQUEF.js";
5
5
  import {
6
6
  ArgumentError,
7
7
  one
@@ -20,7 +20,10 @@ function storeFrom(context) {
20
20
  const sessions = config.raw["sessions"] ?? {};
21
21
  const leases = Object.keys(sessions["leases"] ?? {});
22
22
  return {
23
- store: openStore(config.dir, readStoreSettings(sessions)),
23
+ store: openStore(
24
+ config.dir,
25
+ readStoreSettings(sessions, config.raw["git"])
26
+ ),
24
27
  leases,
25
28
  root: config.dir
26
29
  };
@@ -70,4 +73,4 @@ export {
70
73
  storeFrom,
71
74
  change
72
75
  };
73
- //# sourceMappingURL=chunk-LBXO4VPG.js.map
76
+ //# sourceMappingURL=chunk-E4FJOLPJ.js.map
@@ -0,0 +1,7 @@
1
+ // src/commands/version.ts
2
+ var VERSION = "0.19.0";
3
+
4
+ export {
5
+ VERSION
6
+ };
7
+ //# sourceMappingURL=chunk-FGEBSQQJ.js.map
@@ -32,6 +32,33 @@ function gitText(cwd, args) {
32
32
  function gitOk(cwd, args) {
33
33
  return git(cwd, args).status === 0;
34
34
  }
35
+ var TEE = `
36
+ const fs = require("node:fs");
37
+ const { spawn } = require("node:child_process");
38
+ const [log, bin, ...args] = process.argv.slice(1);
39
+ const out = fs.openSync(log, "a");
40
+ const child = spawn(bin, args, { stdio: ["ignore", "pipe", "pipe"] });
41
+ for (const stream of [child.stdout, child.stderr])
42
+ stream.on("data", (chunk) => {
43
+ process.stderr.write(chunk);
44
+ fs.writeSync(out, chunk);
45
+ });
46
+ child.on("error", (error) => {
47
+ fs.writeSync(out, String(error) + "\\n");
48
+ process.stderr.write(String(error) + "\\n");
49
+ process.exit(127);
50
+ });
51
+ child.on("close", (code) => process.exit(code ?? 1));
52
+ `;
53
+ function runCommandLogged(argv, cwd, log, extra) {
54
+ if (argv[0] === void 0) return 0;
55
+ const run = spawnSync(process.execPath, ["-e", TEE, log, ...argv], {
56
+ cwd,
57
+ stdio: ["ignore", 2, 2],
58
+ env: cleanEnv(extra)
59
+ });
60
+ return run.status ?? 1;
61
+ }
35
62
  function runCommand(argv, cwd, extra) {
36
63
  const [bin, ...rest] = argv;
37
64
  if (bin === void 0) return 0;
@@ -47,6 +74,7 @@ export {
47
74
  git,
48
75
  gitText,
49
76
  gitOk,
77
+ runCommandLogged,
50
78
  runCommand
51
79
  };
52
- //# sourceMappingURL=chunk-OPYFEHKG.js.map
80
+ //# sourceMappingURL=chunk-G7JONWL4.js.map
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-34DECPVC.js";
7
7
  import {
8
8
  ptyBinary
9
- } from "./chunk-MSOZPOPX.js";
9
+ } from "./chunk-QJRJCXX2.js";
10
10
 
11
11
  // src/harness/adapters/systemd/admission.ts
12
12
  var nativeHostTools = ["systemctl", "systemd-run"];
@@ -36,4 +36,4 @@ export {
36
36
  nativeHostTools,
37
37
  assertNativeHost
38
38
  };
39
- //# sourceMappingURL=chunk-4JUSGIMX.js.map
39
+ //# sourceMappingURL=chunk-HEPSITZX.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  HOST_MANIFEST,
3
3
  HOST_POLICY
4
- } from "./chunk-MSOZPOPX.js";
4
+ } from "./chunk-QJRJCXX2.js";
5
5
  import {
6
6
  projectStateDir
7
7
  } from "./chunk-OEH47H6A.js";
@@ -99,4 +99,4 @@ export {
99
99
  hostApprovalDoctor,
100
100
  writeApproval
101
101
  };
102
- //# sourceMappingURL=chunk-YRGDWUFY.js.map
102
+ //# sourceMappingURL=chunk-IEK4U5RR.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  git,
3
3
  gitText
4
- } from "./chunk-OPYFEHKG.js";
4
+ } from "./chunk-G7JONWL4.js";
5
5
 
6
6
  // src/git/landed.ts
7
7
  function cherry(cwd, upstream, head = "HEAD") {
@@ -71,4 +71,4 @@ export {
71
71
  isAncestor,
72
72
  distance
73
73
  };
74
- //# sourceMappingURL=chunk-QEW4J3IZ.js.map
74
+ //# sourceMappingURL=chunk-ISNRDHSD.js.map
@@ -32,6 +32,12 @@ var Reader = class {
32
32
  this.fail(key, "a non-empty string");
33
33
  return value;
34
34
  }
35
+ envName(key) {
36
+ const value = this.string(key);
37
+ if (value !== void 0 && !/^[A-Z_][A-Z0-9_]{0,127}$/u.test(value))
38
+ this.fail(key, "an environment variable name (A-Z, 0-9, _)");
39
+ return value;
40
+ }
35
41
  oneOf(key, values, fallback) {
36
42
  const value = this.table[key] ?? fallback;
37
43
  if (!values.includes(value)) this.fail(key, values.join(" | "));
@@ -48,6 +54,13 @@ var Reader = class {
48
54
  this.fail(key, "a positive integer");
49
55
  return value;
50
56
  }
57
+ positive(key) {
58
+ const value = this.table[key];
59
+ if (value === void 0) return void 0;
60
+ if (typeof value !== "number" || !(value > 0))
61
+ this.fail(key, "a positive number");
62
+ return value;
63
+ }
51
64
  list(key) {
52
65
  const value = this.table[key] ?? [];
53
66
  if (!Array.isArray(value) || !value.every((v) => typeof v === "string"))
@@ -71,6 +84,7 @@ function child(path, parent, name, key) {
71
84
  }
72
85
 
73
86
  // src/git/config/tables.ts
87
+ import { isAbsolute } from "path";
74
88
  function worktrees(path, source) {
75
89
  const read = new Reader(path, "git.worktrees", source, [
76
90
  "root",
@@ -119,13 +133,27 @@ function gate(path, dir, source) {
119
133
  const read = new Reader(path, "git.mainline.gate", source, [
120
134
  "command",
121
135
  "tree",
122
- "lock_wait_seconds"
136
+ "lock_wait_seconds",
137
+ "lock_env",
138
+ "tree_env",
139
+ "log_dir",
140
+ "max_load",
141
+ "load_wait_seconds"
123
142
  ]);
124
143
  const tree = read.string("tree");
144
+ const lockEnv = read.envName("lock_env");
145
+ const treeEnv = read.envName("tree_env");
146
+ const logDir = read.string("log_dir");
147
+ const maxLoad = read.positive("max_load");
125
148
  return {
126
149
  command: read.argv("command"),
127
150
  tree: tree === void 0 ? void 0 : expandPath(dir, tree),
128
- lockWaitSeconds: read.int("lock_wait_seconds", 5400)
151
+ lockWaitSeconds: read.int("lock_wait_seconds", 5400),
152
+ loadWaitSeconds: read.int("load_wait_seconds", 1800),
153
+ ...maxLoad ? { maxLoad } : {},
154
+ ...lockEnv ? { lockEnv } : {},
155
+ ...treeEnv ? { treeEnv } : {},
156
+ ...logDir ? { logDir: expandPath(dir, logDir) } : {}
129
157
  };
130
158
  }
131
159
  function deliver(path, source) {
@@ -149,18 +177,50 @@ function mainlineSync(path, source) {
149
177
  "install",
150
178
  "install_when_changed",
151
179
  "keep_identical_files",
152
- "refuse_with_unlanded"
180
+ "refuse_with_unlanded",
181
+ "stamp",
182
+ "stamp_hash"
153
183
  ]);
184
+ const installWhenChanged = read.list("install_when_changed");
185
+ const stamp = read.string("stamp");
186
+ const hash = read.oneOf("stamp_hash", ["pmcp", "plain"], "pmcp");
187
+ if (stamp !== void 0) {
188
+ const home = stamp.startsWith("~/") || stamp.startsWith("$HOME/");
189
+ if (!stamp.startsWith("${git_dir}/") && !home && !isAbsolute(stamp))
190
+ throw new ConfigError(
191
+ path,
192
+ "[git.mainline.sync] stamp must start with ${git_dir}/, ~/ or /"
193
+ );
194
+ if (hash === "plain" && installWhenChanged.length !== 1)
195
+ throw new ConfigError(
196
+ path,
197
+ '[git.mainline.sync] stamp_hash = "plain" needs exactly one install_when_changed path'
198
+ );
199
+ }
154
200
  return {
155
201
  install: read.argv("install"),
156
- installWhenChanged: read.list("install_when_changed"),
202
+ installWhenChanged,
157
203
  keepIdenticalFiles: read.bool("keep_identical_files", true),
158
- refuseWithUnlanded: read.bool("refuse_with_unlanded", true)
204
+ refuseWithUnlanded: read.bool("refuse_with_unlanded", true),
205
+ ...stamp !== void 0 ? {
206
+ stamp: {
207
+ path: stamp.startsWith("${git_dir}/") ? stamp : expandPath("/", stamp),
208
+ hash
209
+ }
210
+ } : {}
159
211
  };
160
212
  }
161
213
  function submodules(path, source) {
162
- const read = new Reader(path, "git.submodules", source, ["follow"]);
163
- return { follow: read.oneOf("follow", ["clean_pins", "off"], "clean_pins") };
214
+ const read = new Reader(path, "git.submodules", source, [
215
+ "follow",
216
+ "shared",
217
+ "push"
218
+ ]);
219
+ return {
220
+ follow: read.oneOf("follow", ["clean_pins", "off"], "clean_pins"),
221
+ shared: read.list("shared"),
222
+ push: read.oneOf("push", ["pins", "off"], "off")
223
+ };
164
224
  }
165
225
  function leases(path, sessions) {
166
226
  const declared = child(path, sessions, "sessions", "leases");
@@ -227,4 +287,4 @@ function readGitConfig(config) {
227
287
  export {
228
288
  readGitConfig
229
289
  };
230
- //# sourceMappingURL=chunk-S3PIAMXV.js.map
290
+ //# sourceMappingURL=chunk-J5XQW2CM.js.map
@@ -1,9 +1,13 @@
1
1
  import {
2
2
  readGitConfig
3
- } from "./chunk-S3PIAMXV.js";
3
+ } from "./chunk-J5XQW2CM.js";
4
4
  import {
5
5
  detect
6
- } from "./chunk-JS5RTH4I.js";
6
+ } from "./chunk-2Q6MNGU5.js";
7
+ import {
8
+ readStoreSettings,
9
+ resolveLeaseFiles
10
+ } from "./chunk-DHAPQUEF.js";
7
11
  import {
8
12
  projectStateDir
9
13
  } from "./chunk-OEH47H6A.js";
@@ -13,21 +17,29 @@ import {
13
17
  } from "./chunk-QPL7E2HW.js";
14
18
 
15
19
  // src/git/setup.ts
16
- import { join, resolve } from "path";
20
+ import { dirname, join, resolve } from "path";
17
21
  function loadGit(cwd, configPath, env) {
18
22
  const path = configPath === void 0 ? findConfig(cwd) : resolve(cwd, configPath);
19
23
  if (path === null)
20
24
  return new Error("no pmcp.toml found; the git workflow is opt-in");
21
- const config = readGitConfig(readConfig(path));
25
+ const project = readConfig(path);
26
+ const config = readGitConfig(project);
22
27
  if (config === null)
23
28
  return new Error(`[git] is absent or disabled in ${path}`);
24
29
  const ctx = detect(cwd, { remote: config.remote, mainline: config.mainline });
25
30
  if (ctx === null) return new Error(`${cwd} is not inside a git checkout`);
26
31
  const stateDir = projectStateDir(ctx.root, config.stateDir, env);
27
- return { config, ctx, stateDir };
32
+ const override = config.gate?.treeEnv ? env[config.gate.treeEnv] : void 0;
33
+ const tree = override || (config.gate?.tree ?? join(stateDir, "gate", "tree"));
34
+ const settings = readStoreSettings(
35
+ project.raw["sessions"],
36
+ project.raw["git"]
37
+ );
38
+ const leaseFiles = resolveLeaseFiles(settings.leaseFiles, dirname(tree));
39
+ return { config, ctx, stateDir, gateTree: tree, leaseFiles };
28
40
  }
29
41
  function gateTreePath(setup) {
30
- return setup.config.gate?.tree ?? join(setup.stateDir, "gate", "tree");
42
+ return setup.gateTree;
31
43
  }
32
44
  function leaseSpecs(config) {
33
45
  if (config.leases.length > 0) return config.leases;
@@ -41,4 +53,4 @@ export {
41
53
  gateTreePath,
42
54
  leaseSpecs
43
55
  };
44
- //# sourceMappingURL=chunk-GZHHEHKY.js.map
56
+ //# sourceMappingURL=chunk-JJBSYUSQ.js.map