@modootoday/pmcp 0.24.1 → 0.26.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 (116) 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/{affected-IPFJM2KD.js → affected-4FILH743.js} +174 -77
  6. package/dist/{apply-CDJQJAZH.js → apply-HJUCYQDQ.js} +18 -15
  7. package/dist/{broadcast-VKZY7WSD.js → broadcast-U7ZYOJWE.js} +7 -4
  8. package/dist/{chunk-GEDRPMBH.js → chunk-2GL5L2G5.js} +2 -2
  9. package/dist/{chunk-AQM2JZMB.js → chunk-2JUHFM4V.js} +2 -2
  10. package/dist/{chunk-UKR64U7J.js → chunk-374AZ4J4.js} +2 -2
  11. package/dist/{chunk-MZ52S4YJ.js → chunk-3JOFDNL4.js} +2 -2
  12. package/dist/{chunk-264DIB5U.js → chunk-3KISMGVP.js} +4 -4
  13. package/dist/{chunk-V5PXMLLL.js → chunk-6XE3WW7S.js} +3 -3
  14. package/dist/{chunk-7CGGDX7X.js → chunk-7FHOSWNQ.js} +2 -2
  15. package/dist/{chunk-5NQZGNKT.js → chunk-7PBWLYCO.js} +3 -3
  16. package/dist/{chunk-2GZKA33O.js → chunk-A4P3IIPE.js} +2 -2
  17. package/dist/{chunk-3O3JZTUU.js → chunk-C7Y2MBCN.js} +3 -3
  18. package/dist/chunk-D7IDT7OA.js +21 -0
  19. package/dist/chunk-E272CFPS.js +14 -0
  20. package/dist/chunk-FLG7VRTC.js +1 -0
  21. package/dist/{chunk-X3RUXLAV.js → chunk-FXDGW2IH.js} +3 -3
  22. package/dist/{chunk-DLIO2D7S.js → chunk-GIL3RBRX.js} +27 -20
  23. package/dist/{chunk-ARXCYFFZ.js → chunk-GQRDEIQA.js} +22 -2
  24. package/dist/chunk-J43Z4O3G.js +7 -0
  25. package/dist/chunk-KLIYFD3W.js +32 -0
  26. package/dist/{chunk-PG62GOPU.js → chunk-KQV2EPAP.js} +2 -2
  27. package/dist/{chunk-LNKAR3IS.js → chunk-LCPCRZ7N.js} +2 -2
  28. package/dist/chunk-NQCAKDRY.js +156 -0
  29. package/dist/{chunk-3SEJNT6F.js → chunk-NQZMGQFG.js} +5 -5
  30. package/dist/{chunk-DGXZBQCA.js → chunk-OBCBCLS2.js} +7 -7
  31. package/dist/{chunk-D4FIBB2G.js → chunk-OG2ESRQP.js} +5 -5
  32. package/dist/{chunk-43MXRTKH.js → chunk-OHCUPXU4.js} +26 -8
  33. package/dist/chunk-OIKT4SYO.js +42 -0
  34. package/dist/{chunk-3V37OZQH.js → chunk-PAY6HEEY.js} +2 -2
  35. package/dist/{chunk-QY2P54Z2.js → chunk-PZ6D3WKD.js} +125 -8
  36. package/dist/{chunk-MOKZPZZO.js → chunk-Q5BQIRM3.js} +2 -2
  37. package/dist/{chunk-VYQJPT27.js → chunk-S2FUWBLO.js} +18 -4
  38. package/dist/{chunk-OGCJO6HQ.js → chunk-TQRLWO4F.js} +2 -2
  39. package/dist/{chunk-VBWB2T3C.js → chunk-UVPIVSZB.js} +14 -6
  40. package/dist/{chunk-MHKY6TNF.js → chunk-VN34GLGJ.js} +3 -3
  41. package/dist/chunk-WUFNKK3U.js +71 -0
  42. package/dist/{chunk-2ZH77O2D.js → chunk-Y7FYCVUK.js} +646 -103
  43. package/dist/{chunk-HES44LTA.js → chunk-YJVSN6UN.js} +29 -5
  44. package/dist/{chunk-EWYLWBKS.js → chunk-YKICVMF7.js} +22 -5
  45. package/dist/{cli-OV5LSSGE.js → cli-FVUHK2NB.js} +7 -7
  46. package/dist/{cli-GFDT4YXM.js → cli-ZOY2274X.js} +9 -9
  47. package/dist/cli.js +40 -6
  48. package/dist/{completion-QNDCU4MF.js → completion-ZKWGPMEK.js} +6 -5
  49. package/dist/{diagnostics-TPK3VC5F.js → diagnostics-IM2OPAPL.js} +7 -7
  50. package/dist/{doctor-K2LADSW2.js → doctor-VZTHEPVC.js} +32 -20
  51. package/dist/{entry-HFQHKL5L.js → entry-Q4EI4PNO.js} +13 -13
  52. package/dist/{exec-mcp-I2YGGWY4.js → exec-mcp-AWGUQVT2.js} +15 -12
  53. package/dist/{harness-BMWGAXCF.js → harness-L4C5XWKR.js} +3 -3
  54. package/dist/harness-launch-gate.js +5 -5
  55. package/dist/harness-worker.js +7 -7
  56. package/dist/{heavy-G6CYQQ7O.js → heavy-OG3UVZNY.js} +327 -131
  57. package/dist/hook-body.js +664 -161
  58. package/dist/{hook-spec-Bd24eo2L.d.ts → hook-spec-u7hnz571.d.ts} +10 -0
  59. package/dist/{hooks-R7AYQXHY.js → hooks-2E6PJJQK.js} +4 -4
  60. package/dist/{host-PLE2T55E.js → host-OQDBQJB2.js} +8 -8
  61. package/dist/{host-EUD6GLWV.js → host-RJJGTKWA.js} +20 -65
  62. package/dist/{host-run-QFNGIDL5.js → host-run-PWCIXJDN.js} +6 -6
  63. package/dist/http.js +1 -1
  64. package/dist/{import-mcp-DVKJOEOE.js → import-mcp-2H2NRUCL.js} +14 -11
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.js +18 -15
  67. package/dist/{init-DKWNL62M.js → init-O2UCU2WT.js} +2 -2
  68. package/dist/{invoke-U6JTPTXT.js → invoke-SJ3JHRJU.js} +9 -9
  69. package/dist/{list-YKQFJN3G.js → list-SJVXZGKK.js} +17 -14
  70. package/dist/{logout-5YSKC46N.js → logout-ROKXWR3T.js} +15 -12
  71. package/dist/{logs-2JEMSNSG.js → logs-J4W6GFMK.js} +4 -4
  72. package/dist/{mailbox-5FVFMQ2J.js → mailbox-6MHH6CUA.js} +22 -8
  73. package/dist/{mainline-D3PSR6AJ.js → mainline-SWZPKA7U.js} +19 -9
  74. package/dist/{mcp-CHKKXHBB.js → mcp-U7MVFAB4.js} +2 -2
  75. package/dist/owners-MPI22SFU.js +63 -0
  76. package/dist/{pause-CMZOIHTJ.js → pause-3IMVYXQQ.js} +7 -4
  77. package/dist/project/hook-adapter.d.ts +1 -1
  78. package/dist/{project-QEYXISHC.js → project-MGUYHUF7.js} +4 -4
  79. package/dist/{report-UB7MXAUB.js → report-MWXB5XKE.js} +5 -5
  80. package/dist/{resume-PAKIT4TT.js → resume-7LCSV4X3.js} +7 -4
  81. package/dist/{run-HKMYYEZJ.js → run-DDWLS6FY.js} +14 -11
  82. package/dist/{run-FYKDIW4C.js → run-TBO5JO4Y.js} +4 -4
  83. package/dist/{serve-QZNG5UUV.js → serve-RBQYB3FP.js} +3 -3
  84. package/dist/{setup-GRWLDBVB.js → setup-7JHWLV7K.js} +6 -4
  85. package/dist/{smoke-6X6IXQIQ.js → smoke-GZECLXOJ.js} +3 -3
  86. package/dist/{start-login-4GPM32RA.js → start-login-SOTNDUP6.js} +15 -12
  87. package/dist/{status-55CD352M.js → status-EBIUQIGY.js} +35 -30
  88. package/dist/{status-4PYPTYUB.js → status-QFMN7IUG.js} +8 -5
  89. package/dist/{status-W6SCF2GF.js → status-TSTOFNZU.js} +15 -12
  90. package/dist/stdio.js +2 -2
  91. package/dist/{sweep-VURZU6DI.js → sweep-BS7HVSNP.js} +7 -4
  92. package/dist/{test-XYEMYZ2P.js → test-4PZHHWOQ.js} +28 -16
  93. package/dist/{tui-FXSWN2PV.js → tui-QD2LMXHV.js} +4 -4
  94. package/dist/{unbroadcast-7AMLURCG.js → unbroadcast-GRGX3F6T.js} +7 -4
  95. package/dist/{worker-Q4I4EIAJ.js → worker-SPJ4HFWV.js} +11 -11
  96. package/dist/{worktree-list-2HV6ODBS.js → worktree-list-WZC75NLF.js} +8 -9
  97. package/dist/{worktree-sync-MUVKK2CV.js → worktree-sync-BQZD4J73.js} +5 -2
  98. package/docs/commands.md +18 -7
  99. package/docs/git-workflow.md +40 -5
  100. package/docs/glossary.md +1 -1
  101. package/docs/hooks.md +75 -16
  102. package/docs/project-configuration.md +136 -40
  103. package/docs/sessions.md +9 -2
  104. package/docs/upgrading.md +71 -0
  105. package/gemini-extension.json +2 -2
  106. package/mcp.json +1 -1
  107. package/package.json +5 -5
  108. package/plugin.json +1 -1
  109. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  110. package/plugins/pmcp/.mcp.json +1 -1
  111. package/plugins/pmcp/gemini-extension.json +2 -2
  112. package/plugins/pmcp/mcp.json +1 -1
  113. package/plugins/pmcp/plugin.json +1 -1
  114. package/dist/chunk-65H4PN33.js +0 -7
  115. package/dist/chunk-7TD53M7L.js +0 -13
  116. package/dist/chunk-FQLCD4HU.js +0 -24
@@ -4,12 +4,18 @@ import {
4
4
  import {
5
5
  inferSession
6
6
  } from "./chunk-65BW7Y6O.js";
7
+ import {
8
+ isOperator,
9
+ requireOperatorFor
10
+ } from "./chunk-OIKT4SYO.js";
7
11
  import {
8
12
  flockAvailable
9
13
  } from "./chunk-DZ2MRTYT.js";
14
+ import "./chunk-NQCAKDRY.js";
15
+ import "./chunk-Z6WRFOFT.js";
10
16
  import {
11
17
  heavySpec
12
- } from "./chunk-43MXRTKH.js";
18
+ } from "./chunk-OHCUPXU4.js";
13
19
  import "./chunk-JPYQDOEW.js";
14
20
  import {
15
21
  ArgumentError,
@@ -18,10 +24,13 @@ import {
18
24
  } from "./chunk-Y6NFETNG.js";
19
25
  import {
20
26
  BUSY_EXIT,
27
+ DEFAULT_JOB_LOG_BYTES,
21
28
  DISABLE_ENV,
29
+ JobLog,
22
30
  NOW_ENV,
23
- leaseSettingsFor
24
- } from "./chunk-QY2P54Z2.js";
31
+ leaseSettingsFor,
32
+ readJobLog
33
+ } from "./chunk-PZ6D3WKD.js";
25
34
  import {
26
35
  LANES,
27
36
  describeRecord,
@@ -51,6 +60,87 @@ import "./chunk-PMJG2CXF.js";
51
60
  // src/commands/heavy.ts
52
61
  import { dirname } from "path";
53
62
 
63
+ // src/lease/queue.ts
64
+ import { readFileSync as readFileSync2 } from "fs";
65
+
66
+ // src/lease/host.ts
67
+ import { readFileSync, writeFileSync } from "fs";
68
+ function hostSources(env) {
69
+ return {
70
+ loadavg: env["PMCP_HEAVY_LOADAVG_FILE"] || "/proc/loadavg",
71
+ pressure: env["PMCP_HEAVY_PRESSURE_FILE"] || "/proc/pressure/io"
72
+ };
73
+ }
74
+ function read(file) {
75
+ try {
76
+ return readFileSync(file, "utf8");
77
+ } catch {
78
+ return null;
79
+ }
80
+ }
81
+ function readHost(sources) {
82
+ const load = read(sources.loadavg)?.split(" ")[0]?.trim() || null;
83
+ const some = read(sources.pressure)?.match(/^some (.*)$/mu)?.[1] ?? "";
84
+ const pressure = {};
85
+ for (const [, key, value] of some.matchAll(/(avg\d+)=([0-9.]+)/gu))
86
+ pressure[key] = value;
87
+ return { load, io: pressure["avg10"] ?? null, pressure };
88
+ }
89
+ function hostNow(reading) {
90
+ return `load ${reading.load ?? "n/a"} io ${reading.io ?? "n/a"}`;
91
+ }
92
+ function below(value, max) {
93
+ return value === null || Number(value) < max;
94
+ }
95
+ function hostSettled(settings2, paths, sources) {
96
+ const reading = readHost(sources);
97
+ if (!below(reading.load, settings2.maxLoad)) return false;
98
+ const io2 = reading.pressure[settings2.ioWindow] ?? reading.io;
99
+ if (!below(io2, settings2.maxIo)) return false;
100
+ try {
101
+ writeFileSync(paths.settled, `${nowUtc()}
102
+ `);
103
+ } catch {
104
+ }
105
+ return true;
106
+ }
107
+ function sleepSeconds(seconds) {
108
+ if (seconds <= 0) return;
109
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, seconds * 1e3);
110
+ }
111
+
112
+ // src/lease/queue.ts
113
+ function sessionOf(env, cwd) {
114
+ const inferred = inferSession(env, [], []).session;
115
+ if (inferred) return inferred;
116
+ try {
117
+ const stat = readFileSync2("/proc/self/stat", "utf8");
118
+ const group = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[2];
119
+ if (group) return `pgid:${group}`;
120
+ } catch {
121
+ }
122
+ return `cwd:${cwd}`;
123
+ }
124
+ var CAPPED = ["interactive", "bulk"];
125
+ function parkForSession(park) {
126
+ if (park.cap === 0 || !CAPPED.includes(park.lane)) return 0;
127
+ const started = epoch();
128
+ const queued = () => liveWaiters(park.paths).filter(
129
+ (record2) => record2.session === park.session && record2.lane === park.lane
130
+ ).length;
131
+ let count = queued();
132
+ if (count < park.cap) return 0;
133
+ park.say(
134
+ `parked outside the queue: this session already has ${count} queued ${park.lane} job(s) (per_session ${park.cap})`
135
+ );
136
+ for (; ; ) {
137
+ if (epoch() - started >= park.maxWait) return null;
138
+ sleepSeconds(1);
139
+ count = queued();
140
+ if (count < park.cap) return epoch() - started;
141
+ }
142
+ }
143
+
54
144
  // src/lease/run.ts
55
145
  import { spawn } from "child_process";
56
146
  import { constants } from "os";
@@ -62,12 +152,12 @@ import { join as join2 } from "path";
62
152
 
63
153
  // src/lease/iocontrol.ts
64
154
  import { spawnSync } from "child_process";
65
- import { readFileSync, writeFileSync } from "fs";
155
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
66
156
  import { join } from "path";
67
157
  function cgroupHost() {
68
158
  let self = "";
69
159
  try {
70
- const line = readFileSync("/proc/self/cgroup", "utf8").split("\n").find((entry) => entry.startsWith("0::"));
160
+ const line = readFileSync3("/proc/self/cgroup", "utf8").split("\n").find((entry) => entry.startsWith("0::"));
71
161
  self = line?.slice(3) ?? "";
72
162
  } catch {
73
163
  }
@@ -75,7 +165,7 @@ function cgroupHost() {
75
165
  }
76
166
  function controllers(dir) {
77
167
  try {
78
- return readFileSync(join(dir, "cgroup.controllers"), "utf8").trim().split(/\s+/u);
168
+ return readFileSync3(join(dir, "cgroup.controllers"), "utf8").trim().split(/\s+/u);
79
169
  } catch {
80
170
  return [];
81
171
  }
@@ -90,8 +180,8 @@ function ioDelegated(host) {
90
180
  function enable(dir) {
91
181
  const file = join(dir, "cgroup.subtree_control");
92
182
  try {
93
- if (readFileSync(file, "utf8").split(/\s+/u).includes("io")) return;
94
- writeFileSync(file, "+io");
183
+ if (readFileSync3(file, "utf8").split(/\s+/u).includes("io")) return;
184
+ writeFileSync2(file, "+io");
95
185
  } catch {
96
186
  }
97
187
  }
@@ -100,19 +190,24 @@ function applyIo(host, scope, weight, max) {
100
190
  for (let at = 1; at < parts.length; at += 1)
101
191
  enable(join(host.root, ...parts.slice(0, at)));
102
192
  const dir = join(host.root, ...parts);
103
- if (!controllers(dir).includes("io")) return false;
104
- try {
105
- writeFileSync(join(dir, "io.weight"), `default ${weight}`);
106
- if (max) writeFileSync(join(dir, "io.max"), max);
107
- return true;
108
- } catch {
109
- return false;
110
- }
193
+ if (!controllers(dir).includes("io"))
194
+ return { weight: false, max: max ? "failed" : "unset" };
195
+ const write = (file, text) => {
196
+ try {
197
+ writeFileSync2(join(dir, file), text);
198
+ return true;
199
+ } catch {
200
+ return false;
201
+ }
202
+ };
203
+ const written = write("io.weight", `default ${weight}`);
204
+ if (!max) return { weight: written, max: "unset" };
205
+ return { weight: written, max: write("io.max", max) ? "set" : "failed" };
111
206
  }
112
207
  function scopeCgroup(unit) {
113
208
  const run2 = spawnSync(
114
209
  "systemctl",
115
- ["--user", "show", unit, "-p", "ControlGroup", "--value"],
210
+ ["--user", "show", `${unit}.scope`, "-p", "ControlGroup", "--value"],
116
211
  { encoding: "utf8" }
117
212
  );
118
213
  const path = run2.status === 0 ? run2.stdout.trim() : "";
@@ -174,8 +269,10 @@ async function weigh(unit, settings2, lane, host, say, onCgroup) {
174
269
  settings2.io.weights[lane],
175
270
  settings2.io.max[lane]
176
271
  );
177
- if (!set && settings2.io.enabled === true)
272
+ if (!set.weight)
178
273
  say(`io control did not reach ${scope}; running without io.weight`);
274
+ if (set.max === "failed")
275
+ say(`io.max for the ${lane} lane was refused; the job runs without it`);
179
276
  return;
180
277
  }
181
278
  await new Promise((resolve) => setTimeout(resolve, 100));
@@ -275,85 +372,6 @@ function waiterFile(paths, pid) {
275
372
  return join3(paths.waiters, String(pid));
276
373
  }
277
374
 
278
- // src/lease/host.ts
279
- import { readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
280
- function hostSources(env) {
281
- return {
282
- loadavg: env["PMCP_HEAVY_LOADAVG_FILE"] || "/proc/loadavg",
283
- pressure: env["PMCP_HEAVY_PRESSURE_FILE"] || "/proc/pressure/io"
284
- };
285
- }
286
- function read(file) {
287
- try {
288
- return readFileSync2(file, "utf8");
289
- } catch {
290
- return null;
291
- }
292
- }
293
- function readHost(sources) {
294
- const load = read(sources.loadavg)?.split(" ")[0]?.trim() || null;
295
- const some = read(sources.pressure)?.match(/^some (.*)$/mu)?.[1] ?? "";
296
- const pressure = {};
297
- for (const [, key, value] of some.matchAll(/(avg\d+)=([0-9.]+)/gu))
298
- pressure[key] = value;
299
- return { load, io: pressure["avg10"] ?? null, pressure };
300
- }
301
- function hostNow(reading) {
302
- return `load ${reading.load ?? "n/a"} io ${reading.io ?? "n/a"}`;
303
- }
304
- function below(value, max) {
305
- return value === null || Number(value) < max;
306
- }
307
- function hostSettled(settings2, paths, sources) {
308
- const reading = readHost(sources);
309
- if (!below(reading.load, settings2.maxLoad)) return false;
310
- const io2 = reading.pressure[settings2.ioWindow] ?? reading.io;
311
- if (!below(io2, settings2.maxIo)) return false;
312
- try {
313
- writeFileSync2(paths.settled, `${nowUtc()}
314
- `);
315
- } catch {
316
- }
317
- return true;
318
- }
319
- function sleepSeconds(seconds) {
320
- if (seconds <= 0) return;
321
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, seconds * 1e3);
322
- }
323
-
324
- // src/lease/queue.ts
325
- import { readFileSync as readFileSync3 } from "fs";
326
- function sessionOf(env, cwd) {
327
- const inferred = inferSession(env, [], []).session;
328
- if (inferred) return inferred;
329
- try {
330
- const stat = readFileSync3("/proc/self/stat", "utf8");
331
- const group = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[2];
332
- if (group) return `pgid:${group}`;
333
- } catch {
334
- }
335
- return `cwd:${cwd}`;
336
- }
337
- var CAPPED = ["interactive", "bulk"];
338
- function parkForSession(park) {
339
- if (park.cap === 0 || !CAPPED.includes(park.lane)) return 0;
340
- const started = epoch();
341
- const queued = () => liveWaiters(park.paths).filter(
342
- (record2) => record2.session === park.session && record2.lane === park.lane
343
- ).length;
344
- let count = queued();
345
- if (count < park.cap) return 0;
346
- park.say(
347
- `parked outside the queue: this session already has ${count} queued ${park.lane} job(s) (per_session ${park.cap})`
348
- );
349
- for (; ; ) {
350
- if (epoch() - started >= park.maxWait) return null;
351
- sleepSeconds(1);
352
- count = queued();
353
- if (count < park.cap) return epoch() - started;
354
- }
355
- }
356
-
357
375
  // src/lease/settle.ts
358
376
  function io(settings2, reading) {
359
377
  return reading.pressure[settings2.ioWindow] ?? reading.io;
@@ -381,6 +399,30 @@ function hostVerdict(settings2, reading, waiting) {
381
399
  return "wait";
382
400
  }
383
401
 
402
+ // src/lease/skip.ts
403
+ var NESTED = "nested";
404
+ var OPERATOR = "operator";
405
+ var LEGACY_NESTED = /^inside pmcp heavy \d+$/u;
406
+ function allowedReasons(settings2) {
407
+ return [
408
+ .../* @__PURE__ */ new Set([
409
+ NESTED,
410
+ OPERATOR,
411
+ ...settings2.skipReasons,
412
+ ...settings2.skipAlways
413
+ ])
414
+ ];
415
+ }
416
+ function skipRefusal(settings2, reason2, checks) {
417
+ if (reason2 === NESTED || LEGACY_NESTED.test(reason2))
418
+ return checks.nested() ? null : `${NESTED} is the reason pmcp sets inside a leased job, and no leased job encloses this one`;
419
+ if (reason2 === OPERATOR)
420
+ return checks.operator() ? null : `${OPERATOR} is the operator's own skip, from the operator's terminal or with the operator token`;
421
+ if (settings2.skipReasons.includes(reason2)) return null;
422
+ if (settings2.skipAlways.includes(reason2)) return null;
423
+ return `"${reason2}" is not a lease skip reason`;
424
+ }
425
+
384
426
  // src/lease/acquire.ts
385
427
  var STEP_SECONDS = 1;
386
428
  function skipSource(settings2, env) {
@@ -510,8 +552,7 @@ function held(options, paths, fd, start) {
510
552
  const pid = String(process.pid);
511
553
  const env = { [settings2.markerEnv]: pid };
512
554
  if (settings2.legacyMarkerEnv) env[settings2.legacyMarkerEnv] = pid;
513
- if (settings2.legacySkipEnv)
514
- env[settings2.legacySkipEnv] = `inside pmcp heavy ${pid}`;
555
+ if (settings2.legacySkipEnv) env[settings2.legacySkipEnv] = NESTED;
515
556
  let open = true;
516
557
  return {
517
558
  kind: "held",
@@ -529,6 +570,23 @@ function acquireLease(options) {
529
570
  if (!settings2.enabled) return { kind: "disabled" };
530
571
  const paths = leasePaths(settings2.dir);
531
572
  const skip = skipSource(settings2, env);
573
+ const invalid = skip === null ? null : skipRefusal(settings2, skip.reason, {
574
+ nested: () => reentrant(settings2, env),
575
+ operator: () => options.operator?.() ?? false
576
+ });
577
+ if (skip !== null && invalid !== null) {
578
+ if (reentrant(settings2, env)) return { kind: "reentrant" };
579
+ say(
580
+ `${invalid} (${skip.variable}); allowed: ${allowedReasons(settings2).join(", ")}. List a reason in [host.lease] skip_reasons, or run without ${skip.variable} and wait for the lease.`
581
+ );
582
+ logEvent(
583
+ paths,
584
+ process.pid,
585
+ "skip-invalid",
586
+ `reason=${skip.reason} env=${skip.variable} cwd=${options.cwd} label=${label}`
587
+ );
588
+ return { kind: "invalid", reason: skip.reason, variable: skip.variable };
589
+ }
532
590
  const refused = skip !== null && options.lane === "bulk" && !settings2.skipAlways.includes(skip.reason);
533
591
  if (refused && reentrant(settings2, env)) return { kind: "reentrant" };
534
592
  if (skip !== null && refused) {
@@ -755,6 +813,17 @@ function skipShare(records) {
755
813
  runs: ran.length
756
814
  };
757
815
  }
816
+ function skipReasons(records) {
817
+ const honoured = {};
818
+ const invalid = {};
819
+ for (const record2 of records) {
820
+ if (record2.skip !== void 0)
821
+ honoured[record2.skip] = (honoured[record2.skip] ?? 0) + 1;
822
+ if (record2.skip_invalid !== void 0)
823
+ invalid[record2.skip_invalid] = (invalid[record2.skip_invalid] ?? 0) + 1;
824
+ }
825
+ return { honoured, invalid };
826
+ }
758
827
  function percentile(values, share) {
759
828
  const sorted = [...values].sort((a, b) => a - b);
760
829
  return sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * share))] ?? 0;
@@ -780,7 +849,9 @@ function usageStats(records) {
780
849
  signature: key,
781
850
  samples: ran.length,
782
851
  failed: ran.filter((record2) => record2.exit !== 0).length,
783
- timeouts: list.length - ran.length,
852
+ timeouts: list.filter(
853
+ (record2) => record2.outcome !== "ran" && record2.outcome !== "invalid"
854
+ ).length,
784
855
  skipped: ran.filter((record2) => record2.skip !== void 0).length,
785
856
  p50: pick(0.5),
786
857
  p90: pick(0.9)
@@ -911,6 +982,8 @@ var Sampler = class {
911
982
  };
912
983
 
913
984
  // src/lease/run.ts
985
+ var DRAIN_MS = 2e3;
986
+ var INVALID_EXIT = 2;
914
987
  function prefixed(argv, prefix) {
915
988
  const name = (word = "") => word.slice(word.lastIndexOf("/") + 1);
916
989
  return argv.length >= prefix.length && prefix.every((word, at) => (at === 0 ? name(argv[0]) : argv[at]) === word);
@@ -929,15 +1002,26 @@ var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
929
1002
  var HEAD = 2048;
930
1003
  function execute(argv, run2, extra, watch) {
931
1004
  const [bin, ...rest] = argv;
1005
+ const kept = run2.output;
1006
+ const echo = run2.echo !== false;
932
1007
  return new Promise((resolve) => {
933
1008
  const child = spawn(bin ?? "true", rest, {
934
1009
  cwd: run2.cwd,
935
1010
  env: { ...run2.env, ...extra },
936
- stdio: ["inherit", "inherit", watch.stderrHead ? "pipe" : "inherit"]
1011
+ stdio: [
1012
+ "inherit",
1013
+ kept ? "pipe" : "inherit",
1014
+ kept || watch.stderrHead ? "pipe" : "inherit"
1015
+ ]
937
1016
  });
938
1017
  let head = "";
1018
+ child.stdout?.on("data", (chunk) => {
1019
+ if (echo) process.stdout.write(chunk);
1020
+ kept?.write(chunk);
1021
+ });
939
1022
  child.stderr?.on("data", (chunk) => {
940
- process.stderr.write(chunk);
1023
+ if (echo) process.stderr.write(chunk);
1024
+ kept?.write(chunk);
941
1025
  if (head.length >= HEAD) return;
942
1026
  head += chunk.toString("utf8");
943
1027
  watch.stderrHead?.(head.slice(0, HEAD));
@@ -946,7 +1030,10 @@ function execute(argv, run2, extra, watch) {
946
1030
  const forward = (signal) => child.kill(signal);
947
1031
  for (const signal of SIGNALS) process.on(signal, forward);
948
1032
  const timer = setInterval(() => watch.tick(child.pid), 1e3);
1033
+ let finished = false;
949
1034
  const done = (code) => {
1035
+ if (finished) return;
1036
+ finished = true;
950
1037
  clearInterval(timer);
951
1038
  for (const signal of SIGNALS) process.off(signal, forward);
952
1039
  resolve(code);
@@ -956,8 +1043,13 @@ function execute(argv, run2, extra, watch) {
956
1043
  done(127);
957
1044
  });
958
1045
  child.on("exit", (code, signal) => {
959
- if (code !== null) return done(code);
960
- done(128 + (signal && constants.signals[signal] || 15));
1046
+ const exit = code ?? 128 + (signal && constants.signals[signal] || 15);
1047
+ if (!child.stdout && !child.stderr) return done(exit);
1048
+ const drained = setTimeout(() => done(exit), DRAIN_MS);
1049
+ child.on("close", () => {
1050
+ clearTimeout(drained);
1051
+ done(exit);
1052
+ });
961
1053
  });
962
1054
  });
963
1055
  }
@@ -992,6 +1084,8 @@ function record(run2, fields) {
992
1084
  run2.onUsage?.(usage);
993
1085
  }
994
1086
  function skipFields(run2, outcome) {
1087
+ if (outcome.kind === "invalid")
1088
+ return { skip_invalid: outcome.reason, skip_env: outcome.variable };
995
1089
  if (outcome.kind === "skipped")
996
1090
  return {
997
1091
  skip: outcome.reason,
@@ -1021,6 +1115,18 @@ async function runHeavy(run2) {
1021
1115
  } else {
1022
1116
  outcome = acquireLease({ ...run2, label, lane, weight });
1023
1117
  }
1118
+ if (outcome.kind === "invalid") {
1119
+ record(run2, {
1120
+ ...NOTHING,
1121
+ lane,
1122
+ weight,
1123
+ start: "none",
1124
+ outcome: "invalid",
1125
+ exit: INVALID_EXIT,
1126
+ ...skipFields(run2, outcome)
1127
+ });
1128
+ return INVALID_EXIT;
1129
+ }
1024
1130
  if (outcome.kind === "cancelled") {
1025
1131
  record(run2, {
1026
1132
  ...NOTHING,
@@ -1394,7 +1500,13 @@ function prune(dir) {
1394
1500
  }
1395
1501
  }
1396
1502
  }
1397
- function submit(request) {
1503
+ function ticketOwner(dir, id) {
1504
+ const request = readJson(
1505
+ join5(ticketDir(dir, id), "request.json")
1506
+ );
1507
+ return typeof request?.session === "string" ? request.session : null;
1508
+ }
1509
+ function openTicket(request, blocking) {
1398
1510
  prune(request.dir);
1399
1511
  const id = `${Math.floor(Date.now() / 1e3)}-${randomBytes(3).toString("hex")}`;
1400
1512
  const path = ticketDir(request.dir, id);
@@ -1404,9 +1516,25 @@ function submit(request) {
1404
1516
  ticket: id,
1405
1517
  label: request.label,
1406
1518
  cwd: request.cwd,
1519
+ ...request.session ? { session: request.session } : {},
1520
+ ...blocking ? { blocking: true } : {},
1407
1521
  created: (/* @__PURE__ */ new Date()).toISOString()
1408
1522
  });
1409
- const log = openSync4(join5(path, "log"), "a");
1523
+ return id;
1524
+ }
1525
+ function blockingTicket(request) {
1526
+ const id = openTicket(request, true);
1527
+ writeFileSync4(join5(ticketDir(request.dir, id), "pid"), `${process.pid}
1528
+ `);
1529
+ return id;
1530
+ }
1531
+ function jobLogPath(dir, id) {
1532
+ return join5(ticketDir(dir, id), "log");
1533
+ }
1534
+ function submit(request) {
1535
+ const id = openTicket(request, false);
1536
+ const path = ticketDir(request.dir, id);
1537
+ const log = openSync4(join5(path, "runner.log"), "a");
1410
1538
  const [bin, ...args] = request.runner(id);
1411
1539
  const child = spawn2(bin, args, {
1412
1540
  cwd: request.cwd,
@@ -1459,8 +1587,7 @@ function recentTickets(dir) {
1459
1587
  }
1460
1588
  function logTail(dir, id, lines = 20) {
1461
1589
  try {
1462
- const text = readFileSync8(join5(ticketDir(dir, id), "log"), "utf8");
1463
- return text.split("\n").slice(-lines - 1).join("\n");
1590
+ return readJobLog(jobLogPath(dir, id)).split("\n").slice(-lines - 1).join("\n");
1464
1591
  } catch {
1465
1592
  return "";
1466
1593
  }
@@ -1707,11 +1834,11 @@ function queueList(context, settings2) {
1707
1834
  return EXIT.ok;
1708
1835
  }
1709
1836
  if (snapshot.waiters.length === 0) context.ui.data("queue: empty\n");
1710
- for (const w of snapshot.waiters)
1711
- context.ui.data(
1712
- `${w.id} ${w.lane} position ${w.position} waited ${w.waited_s}s eta ${w.eta_s ?? "?"}s weight ${w.weight} pid ${w.pid} ${w.session ?? "-"} ${w.label}
1713
- `
1714
- );
1837
+ context.ui.results.records(
1838
+ snapshot.waiters.map(
1839
+ (w) => `${w.id} ${w.lane} position ${w.position} waited ${w.waited_s}s eta ${w.eta_s ?? "?"}s weight ${w.weight} pid ${w.pid} ${w.session ?? "-"} ${w.label}`
1840
+ )
1841
+ );
1715
1842
  return EXIT.ok;
1716
1843
  }
1717
1844
  function queuePromote(context, settings2, id) {
@@ -1720,6 +1847,7 @@ function queuePromote(context, settings2, id) {
1720
1847
  throw new ArgumentError(
1721
1848
  "promote starts a job at once: pass --now --reason <text>"
1722
1849
  );
1850
+ requireOperatorFor(context, "pmcp heavy promote --now");
1723
1851
  const paths = leasePaths(settings2.dir);
1724
1852
  return report(
1725
1853
  context,
@@ -1756,8 +1884,15 @@ function queueCancel(context, settings2, id) {
1756
1884
  return EXIT.ok;
1757
1885
  }
1758
1886
  const running = findRunning(paths, id);
1887
+ const force = context.args.flags.has("force");
1888
+ const owner = (ticket ? ticketOwner(settings2.dir, id) : null) ?? running?.session;
1889
+ if (force && owner !== void 0 && owner !== who(context).session)
1890
+ requireOperatorFor(
1891
+ context,
1892
+ `pmcp heavy cancel --force on another session's job (${owner})`
1893
+ );
1759
1894
  if (running !== null && !ticket) {
1760
- if (!context.args.flags.has("force")) {
1895
+ if (!force) {
1761
1896
  context.ui.error(`${id} is running; --force stops it`);
1762
1897
  return EXIT.failure;
1763
1898
  }
@@ -1770,7 +1905,7 @@ function queueCancel(context, settings2, id) {
1770
1905
  context.ui.error(waiting.why);
1771
1906
  return EXIT.failure;
1772
1907
  }
1773
- const done = cancel(settings2.dir, id, context.args.flags.has("force"));
1908
+ const done = cancel(settings2.dir, id, force);
1774
1909
  if (done === "running") {
1775
1910
  context.ui.error(`${id} is running; --force stops it`);
1776
1911
  return EXIT.failure;
@@ -1801,7 +1936,8 @@ function submitTicket(context, settings2, command) {
1801
1936
  ...command
1802
1937
  ],
1803
1938
  cwd: context.cwd,
1804
- env: context.env
1939
+ env: context.env,
1940
+ session: sessionOf(context.env, context.cwd)
1805
1941
  });
1806
1942
  context.ui.data(`${id}
1807
1943
  `);
@@ -1825,6 +1961,16 @@ function viewOf(settings2, id) {
1825
1961
  }
1826
1962
  function ticketResult(context, settings2, id) {
1827
1963
  const view = viewOf(settings2, id);
1964
+ const tailText = one(context.args, "tail");
1965
+ if (tailText !== void 0 && !context.args.flags.has("log"))
1966
+ throw new ArgumentError("--tail goes with --log");
1967
+ if (context.args.flags.has("log")) {
1968
+ const tail2 = tailText === void 0 ? void 0 : Number(tailText);
1969
+ if (tail2 !== void 0 && !(Number.isInteger(tail2) && tail2 >= 1))
1970
+ throw new ArgumentError("--tail is a whole number of at least 1");
1971
+ context.ui.data(readJobLog(jobLogPath(settings2.dir, view.id), tail2));
1972
+ return EXIT.ok;
1973
+ }
1828
1974
  if (context.args.flags.has("json"))
1829
1975
  context.ui.data(`${JSON.stringify({ version: 1, ...view })}
1830
1976
  `);
@@ -1880,26 +2026,41 @@ function statLine(stat) {
1880
2026
  `write ${pair("write_bytes", 1e6, "MB")}`
1881
2027
  ].join(" ");
1882
2028
  }
2029
+ function top(context) {
2030
+ const text = one(context.args, "top");
2031
+ if (text === void 0) return void 0;
2032
+ const count = Number(text);
2033
+ if (!Number.isInteger(count) || count < 1)
2034
+ throw new ArgumentError("--top is a whole number of at least 1");
2035
+ return count;
2036
+ }
1883
2037
  function stats(context) {
1884
2038
  const records = readUsage(leasePaths(settings(context).dir).usage);
1885
- const found = usageStats(records);
2039
+ const limit = top(context);
2040
+ const found = usageStats(records).slice(0, limit);
1886
2041
  if (context.args.flags.has("json")) {
1887
2042
  context.ui.data(`${JSON.stringify(found)}
1888
2043
  `);
1889
2044
  return EXIT.ok;
1890
2045
  }
1891
- if (found.length === 0) context.ui.data("no usage recorded yet\n");
2046
+ const lines = [];
2047
+ if (found.length === 0) lines.push("no usage recorded yet");
1892
2048
  const { skipped, runs } = skipShare(records);
1893
2049
  if (runs > 0)
1894
- context.ui.data(
1895
- `skipped the lease: ${skipped} of ${runs} runs (${Math.round(skipped / runs * 100)}%)
1896
- `
2050
+ lines.push(
2051
+ `skipped the lease: ${skipped} of ${runs} runs (${Math.round(skipped / runs * 100)}%)`
1897
2052
  );
1898
- context.ui.data(
1899
- "signature @ dir samples p50/p90 of wall, cpu, rss, read, write\n"
2053
+ const reasons = skipReasons(records);
2054
+ const counted = (counts) => Object.entries(counts).sort(([a, x], [b, y]) => y - x || a.localeCompare(b)).map(([name, count]) => `${name} ${count}`).join(", ");
2055
+ if (Object.keys(reasons.honoured).length > 0)
2056
+ lines.push(`skip reasons: ${counted(reasons.honoured)}`);
2057
+ if (Object.keys(reasons.invalid).length > 0)
2058
+ lines.push(`refused skip reasons: ${counted(reasons.invalid)}`);
2059
+ lines.push(
2060
+ "signature @ dir samples p50/p90 of wall, cpu, rss, read, write"
1900
2061
  );
1901
- for (const stat of found) context.ui.data(`${statLine(stat)}
1902
- `);
2062
+ lines.push(...found.map(statLine));
2063
+ context.ui.results.records(lines);
1903
2064
  return EXIT.ok;
1904
2065
  }
1905
2066
  function verbs(context) {
@@ -1930,9 +2091,9 @@ function subcommand(context) {
1930
2091
  `);
1931
2092
  return EXIT.ok;
1932
2093
  }
1933
- for (const line of leaseStatus({ settings: lease, env: context.env }))
1934
- context.ui.data(`${line}
1935
- `);
2094
+ context.ui.results.records(
2095
+ leaseStatus({ settings: lease, env: context.env })
2096
+ );
1936
2097
  return EXIT.ok;
1937
2098
  }
1938
2099
  async function run(context) {
@@ -1972,7 +2133,10 @@ async function run(context) {
1972
2133
  if (now) throw new ArgumentError("--now runs at once; it is not submitted");
1973
2134
  return submitTicket(context, lease, args.passthrough);
1974
2135
  }
1975
- const ticket = one(args, "ticket");
2136
+ if (now) requireOperatorFor(context, "pmcp heavy --now");
2137
+ const submitted = one(args, "ticket");
2138
+ const kept = keepOutput(context, lease, label, submitted);
2139
+ const ticket = submitted ?? kept?.id;
1976
2140
  let result = null;
1977
2141
  const config = one(args, "config") ?? findConfig(context.cwd);
1978
2142
  const code = await runHeavy({
@@ -1983,17 +2147,24 @@ async function run(context) {
1983
2147
  ...weight !== void 0 ? { weight } : {},
1984
2148
  ...now ? { now: reason2 } : {},
1985
2149
  root: config ? dirname(config) : context.cwd,
2150
+ operator: () => isOperator(context),
1986
2151
  ...ticket ? { id: ticket } : {},
1987
2152
  argv: args.passthrough,
1988
2153
  cwd: context.cwd,
1989
2154
  env: context.env,
1990
- say,
2155
+ say: (line) => {
2156
+ say(line);
2157
+ kept?.log.write(`pmcp heavy: ${line}
2158
+ `);
2159
+ },
2160
+ ...kept ? { output: kept.log, echo: submitted === void 0 } : {},
1991
2161
  ...ticket ? {
1992
2162
  onUsage: (usage) => {
1993
2163
  result = { version: 1, ticket, ...usage };
1994
2164
  }
1995
2165
  } : {}
1996
2166
  });
2167
+ kept?.log.close();
1997
2168
  if (ticket)
1998
2169
  writeResult(
1999
2170
  lease.dir,
@@ -2001,10 +2172,35 @@ async function run(context) {
2001
2172
  result ?? { version: 1, ticket, exit: code, outcome: "ran" },
2002
2173
  true
2003
2174
  );
2175
+ if (kept && submitted === void 0 && code !== 0)
2176
+ say(`output kept: pmcp heavy result ${kept.id} --log`);
2004
2177
  return code;
2005
2178
  }
2179
+ function keepOutput(context, lease, label, submitted) {
2180
+ const cap = lease.jobLogBytes ?? DEFAULT_JOB_LOG_BYTES;
2181
+ try {
2182
+ if (submitted !== void 0)
2183
+ return {
2184
+ id: submitted,
2185
+ log: new JobLog(
2186
+ jobLogPath(lease.dir, submitted),
2187
+ cap || DEFAULT_JOB_LOG_BYTES
2188
+ )
2189
+ };
2190
+ if (cap === 0 || !lease.enabled) return null;
2191
+ const id = blockingTicket({
2192
+ dir: lease.dir,
2193
+ label: label ?? context.args.passthrough.join(" "),
2194
+ cwd: context.cwd,
2195
+ session: sessionOf(context.env, context.cwd)
2196
+ });
2197
+ return { id, log: new JobLog(jobLogPath(lease.dir, id), cap) };
2198
+ } catch {
2199
+ return null;
2200
+ }
2201
+ }
2006
2202
  var heavyCommand = { ...heavySpec, run };
2007
2203
  export {
2008
2204
  heavyCommand
2009
2205
  };
2010
- //# sourceMappingURL=heavy-G6CYQQ7O.js.map
2206
+ //# sourceMappingURL=heavy-OG3UVZNY.js.map