@modootoday/pmcp 0.25.0 → 0.26.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 (111) 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-6XLLYLJT.js → apply-7HWNHSQB.js} +17 -15
  7. package/dist/{broadcast-34CEG2NQ.js → broadcast-U7ZYOJWE.js} +4 -4
  8. package/dist/{chunk-2TXVOHRS.js → chunk-2VL3C52Y.js} +4 -4
  9. package/dist/{chunk-UKR64U7J.js → chunk-374AZ4J4.js} +2 -2
  10. package/dist/{chunk-ISWR2XIU.js → chunk-3T7CJS4A.js} +2 -2
  11. package/dist/{chunk-PGZZI42O.js → chunk-5ZP3ABPI.js} +2 -2
  12. package/dist/{chunk-SSQ6EWNA.js → chunk-A7MF7RMO.js} +7 -7
  13. package/dist/{chunk-3P6Y2BAO.js → chunk-BSG74PTY.js} +3 -3
  14. package/dist/{chunk-SRSKCFFS.js → chunk-CJD2HFXF.js} +3 -3
  15. package/dist/chunk-D7IDT7OA.js +21 -0
  16. package/dist/chunk-E272CFPS.js +14 -0
  17. package/dist/{chunk-LZVHFPN6.js → chunk-E7BPELYH.js} +5 -5
  18. package/dist/chunk-EIBKHS74.js +7 -0
  19. package/dist/chunk-FLG7VRTC.js +1 -0
  20. package/dist/{chunk-BG6TONJO.js → chunk-GIK4TROM.js} +2 -2
  21. package/dist/{chunk-ARXCYFFZ.js → chunk-GQRDEIQA.js} +22 -2
  22. package/dist/{chunk-UQHJUTDW.js → chunk-GYL2C2Y5.js} +2 -2
  23. package/dist/{chunk-TOR6SKRB.js → chunk-JDVDA5HW.js} +508 -48
  24. package/dist/chunk-KLIYFD3W.js +32 -0
  25. package/dist/{chunk-5MUD7FHP.js → chunk-KWEW5EBE.js} +2 -2
  26. package/dist/{chunk-PECS47OL.js → chunk-M2XABD33.js} +3 -3
  27. package/dist/{chunk-MBHI2TKQ.js → chunk-MFQAQ4IJ.js} +5 -5
  28. package/dist/{chunk-NAHAESFV.js → chunk-OHCUPXU4.js} +18 -5
  29. package/dist/{chunk-3V37OZQH.js → chunk-PAY6HEEY.js} +2 -2
  30. package/dist/{chunk-DITIXBFB.js → chunk-PZ6D3WKD.js} +65 -1
  31. package/dist/{chunk-QYHM6554.js → chunk-RGTWJWQ7.js} +3 -3
  32. package/dist/{chunk-VYQJPT27.js → chunk-S2FUWBLO.js} +18 -4
  33. package/dist/{chunk-DWHM5BAY.js → chunk-T52AGUO7.js} +2 -2
  34. package/dist/{chunk-OGCJO6HQ.js → chunk-TQRLWO4F.js} +2 -2
  35. package/dist/{chunk-EC5QLEZD.js → chunk-UHKHXS3E.js} +14 -6
  36. package/dist/{chunk-MHKY6TNF.js → chunk-VN34GLGJ.js} +3 -3
  37. package/dist/chunk-WUFNKK3U.js +71 -0
  38. package/dist/chunk-X6W7JIED.js +25 -0
  39. package/dist/{chunk-RF6RDJYH.js → chunk-XPLT6DJC.js} +26 -19
  40. package/dist/{chunk-C3KRMTIZ.js → chunk-YJVSN6UN.js} +2 -2
  41. package/dist/{chunk-EWYLWBKS.js → chunk-YKICVMF7.js} +22 -5
  42. package/dist/{chunk-TJW4DP26.js → chunk-ZT75ACJ2.js} +2 -2
  43. package/dist/{cli-QDQYUHAP.js → cli-FVUHK2NB.js} +6 -6
  44. package/dist/{cli-5G2OYTIL.js → cli-ZOY2274X.js} +8 -8
  45. package/dist/cli.js +9 -14
  46. package/dist/{completion-3GVNPLZY.js → completion-O3KRUSJG.js} +5 -4
  47. package/dist/{diagnostics-2W7QDQNG.js → diagnostics-PB5TKIAL.js} +7 -7
  48. package/dist/{doctor-3TDO5LJ5.js → doctor-JVWINJT5.js} +31 -20
  49. package/dist/{entry-E62DZQJF.js → entry-CY74PLN3.js} +13 -13
  50. package/dist/{exec-mcp-4N7FLY52.js → exec-mcp-HAKUGQZM.js} +14 -12
  51. package/dist/{harness-E2AUZDLV.js → harness-N234LNM7.js} +3 -3
  52. package/dist/harness-launch-gate.js +5 -5
  53. package/dist/harness-worker.js +7 -7
  54. package/dist/{heavy-HZQVFI6P.js → heavy-X3KZ7WBU.js} +186 -99
  55. package/dist/hook-body.js +548 -116
  56. package/dist/{hook-spec-Bd24eo2L.d.ts → hook-spec-u7hnz571.d.ts} +10 -0
  57. package/dist/{hooks-VAEAK2FY.js → hooks-7K624JQC.js} +4 -4
  58. package/dist/{host-I2EMQ7UE.js → host-CCJFOCZJ.js} +16 -14
  59. package/dist/{host-4GJDGTLW.js → host-PT7NRWG6.js} +8 -8
  60. package/dist/{host-run-DDMKD3BU.js → host-run-RRBFTVYW.js} +6 -6
  61. package/dist/http.js +1 -1
  62. package/dist/{import-mcp-TNSAMJXI.js → import-mcp-GCNNSLWH.js} +13 -11
  63. package/dist/index.d.ts +2 -2
  64. package/dist/index.js +17 -15
  65. package/dist/{init-UA7MDNTZ.js → init-A4NLTERR.js} +2 -2
  66. package/dist/{invoke-HW7NBPGP.js → invoke-G4LNWPTL.js} +9 -9
  67. package/dist/{list-A7VQJXE5.js → list-EZYULVDW.js} +16 -14
  68. package/dist/{logout-HNPLUKJY.js → logout-BYO3UJUH.js} +14 -12
  69. package/dist/{logs-2JEMSNSG.js → logs-J4W6GFMK.js} +4 -4
  70. package/dist/{mailbox-MR6TPD3P.js → mailbox-6MHH6CUA.js} +4 -4
  71. package/dist/{mainline-MSLW3UFD.js → mainline-SWZPKA7U.js} +13 -9
  72. package/dist/{mcp-6C23GX2E.js → mcp-CZNYDYTJ.js} +2 -2
  73. package/dist/owners-MPI22SFU.js +63 -0
  74. package/dist/{pause-H6ZYZF7C.js → pause-3IMVYXQQ.js} +4 -4
  75. package/dist/project/hook-adapter.d.ts +1 -1
  76. package/dist/{project-BX6NCGKB.js → project-GLT3SO7Y.js} +4 -4
  77. package/dist/{report-43SFNNCF.js → report-MWXB5XKE.js} +4 -4
  78. package/dist/{resume-2BWGSTCN.js → resume-7LCSV4X3.js} +4 -4
  79. package/dist/{run-2UVAWBAF.js → run-J5O2V3MB.js} +13 -11
  80. package/dist/{run-7TRWZFEZ.js → run-OBQBKBPV.js} +4 -4
  81. package/dist/{serve-4XZ5SKJJ.js → serve-QCG4PCVS.js} +3 -3
  82. package/dist/{setup-GRWLDBVB.js → setup-7JHWLV7K.js} +6 -4
  83. package/dist/{smoke-6X6IXQIQ.js → smoke-GZECLXOJ.js} +3 -3
  84. package/dist/{start-login-AR7ITWNV.js → start-login-LRO3RTHD.js} +14 -12
  85. package/dist/{status-ZY6LDQSF.js → status-BQLT7JRE.js} +14 -12
  86. package/dist/{status-VQCMJFVE.js → status-EZTFSD5S.js} +18 -16
  87. package/dist/{status-2GDYLIR3.js → status-QFMN7IUG.js} +4 -4
  88. package/dist/stdio.js +2 -2
  89. package/dist/{sweep-76BUOGEI.js → sweep-BS7HVSNP.js} +4 -4
  90. package/dist/{test-VWGNFSH5.js → test-O7TN5SBA.js} +25 -15
  91. package/dist/{tui-TUMOQBE7.js → tui-ODLF6QWC.js} +4 -4
  92. package/dist/{unbroadcast-HJHYUHZL.js → unbroadcast-GRGX3F6T.js} +4 -4
  93. package/dist/{worker-NEEPJRVV.js → worker-AK4GLGPZ.js} +11 -11
  94. package/dist/{worktree-sync-MUVKK2CV.js → worktree-sync-BQZD4J73.js} +5 -2
  95. package/docs/commands.md +12 -3
  96. package/docs/git-workflow.md +40 -5
  97. package/docs/hooks.md +69 -14
  98. package/docs/project-configuration.md +63 -4
  99. package/docs/upgrading.md +13 -0
  100. package/gemini-extension.json +2 -2
  101. package/mcp.json +1 -1
  102. package/package.json +5 -5
  103. package/plugin.json +1 -1
  104. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  105. package/plugins/pmcp/.mcp.json +1 -1
  106. package/plugins/pmcp/gemini-extension.json +2 -2
  107. package/plugins/pmcp/mcp.json +1 -1
  108. package/plugins/pmcp/plugin.json +1 -1
  109. package/dist/chunk-7TD53M7L.js +0 -13
  110. package/dist/chunk-FQLCD4HU.js +0 -24
  111. package/dist/chunk-SMBU3QLE.js +0 -7
@@ -13,9 +13,12 @@ import {
13
13
  } from "./chunk-DZ2MRTYT.js";
14
14
  import "./chunk-NQCAKDRY.js";
15
15
  import "./chunk-Z6WRFOFT.js";
16
+ import {
17
+ holdOnClosedPipe
18
+ } from "./chunk-X6W7JIED.js";
16
19
  import {
17
20
  heavySpec
18
- } from "./chunk-NAHAESFV.js";
21
+ } from "./chunk-OHCUPXU4.js";
19
22
  import "./chunk-JPYQDOEW.js";
20
23
  import {
21
24
  ArgumentError,
@@ -24,10 +27,13 @@ import {
24
27
  } from "./chunk-Y6NFETNG.js";
25
28
  import {
26
29
  BUSY_EXIT,
30
+ DEFAULT_JOB_LOG_BYTES,
27
31
  DISABLE_ENV,
32
+ JobLog,
28
33
  NOW_ENV,
29
- leaseSettingsFor
30
- } from "./chunk-DITIXBFB.js";
34
+ leaseSettingsFor,
35
+ readJobLog
36
+ } from "./chunk-PZ6D3WKD.js";
31
37
  import {
32
38
  LANES,
33
39
  describeRecord,
@@ -57,6 +63,87 @@ import "./chunk-PMJG2CXF.js";
57
63
  // src/commands/heavy.ts
58
64
  import { dirname } from "path";
59
65
 
66
+ // src/lease/queue.ts
67
+ import { readFileSync as readFileSync2 } from "fs";
68
+
69
+ // src/lease/host.ts
70
+ import { readFileSync, writeFileSync } from "fs";
71
+ function hostSources(env) {
72
+ return {
73
+ loadavg: env["PMCP_HEAVY_LOADAVG_FILE"] || "/proc/loadavg",
74
+ pressure: env["PMCP_HEAVY_PRESSURE_FILE"] || "/proc/pressure/io"
75
+ };
76
+ }
77
+ function read(file) {
78
+ try {
79
+ return readFileSync(file, "utf8");
80
+ } catch {
81
+ return null;
82
+ }
83
+ }
84
+ function readHost(sources) {
85
+ const load = read(sources.loadavg)?.split(" ")[0]?.trim() || null;
86
+ const some = read(sources.pressure)?.match(/^some (.*)$/mu)?.[1] ?? "";
87
+ const pressure = {};
88
+ for (const [, key, value] of some.matchAll(/(avg\d+)=([0-9.]+)/gu))
89
+ pressure[key] = value;
90
+ return { load, io: pressure["avg10"] ?? null, pressure };
91
+ }
92
+ function hostNow(reading) {
93
+ return `load ${reading.load ?? "n/a"} io ${reading.io ?? "n/a"}`;
94
+ }
95
+ function below(value, max) {
96
+ return value === null || Number(value) < max;
97
+ }
98
+ function hostSettled(settings2, paths, sources) {
99
+ const reading = readHost(sources);
100
+ if (!below(reading.load, settings2.maxLoad)) return false;
101
+ const io2 = reading.pressure[settings2.ioWindow] ?? reading.io;
102
+ if (!below(io2, settings2.maxIo)) return false;
103
+ try {
104
+ writeFileSync(paths.settled, `${nowUtc()}
105
+ `);
106
+ } catch {
107
+ }
108
+ return true;
109
+ }
110
+ function sleepSeconds(seconds) {
111
+ if (seconds <= 0) return;
112
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, seconds * 1e3);
113
+ }
114
+
115
+ // src/lease/queue.ts
116
+ function sessionOf(env, cwd) {
117
+ const inferred = inferSession(env, [], []).session;
118
+ if (inferred) return inferred;
119
+ try {
120
+ const stat = readFileSync2("/proc/self/stat", "utf8");
121
+ const group = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[2];
122
+ if (group) return `pgid:${group}`;
123
+ } catch {
124
+ }
125
+ return `cwd:${cwd}`;
126
+ }
127
+ var CAPPED = ["interactive", "bulk"];
128
+ function parkForSession(park) {
129
+ if (park.cap === 0 || !CAPPED.includes(park.lane)) return 0;
130
+ const started = epoch();
131
+ const queued = () => liveWaiters(park.paths).filter(
132
+ (record2) => record2.session === park.session && record2.lane === park.lane
133
+ ).length;
134
+ let count = queued();
135
+ if (count < park.cap) return 0;
136
+ park.say(
137
+ `parked outside the queue: this session already has ${count} queued ${park.lane} job(s) (per_session ${park.cap})`
138
+ );
139
+ for (; ; ) {
140
+ if (epoch() - started >= park.maxWait) return null;
141
+ sleepSeconds(1);
142
+ count = queued();
143
+ if (count < park.cap) return epoch() - started;
144
+ }
145
+ }
146
+
60
147
  // src/lease/run.ts
61
148
  import { spawn } from "child_process";
62
149
  import { constants } from "os";
@@ -68,12 +155,12 @@ import { join as join2 } from "path";
68
155
 
69
156
  // src/lease/iocontrol.ts
70
157
  import { spawnSync } from "child_process";
71
- import { readFileSync, writeFileSync } from "fs";
158
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
72
159
  import { join } from "path";
73
160
  function cgroupHost() {
74
161
  let self = "";
75
162
  try {
76
- const line = readFileSync("/proc/self/cgroup", "utf8").split("\n").find((entry) => entry.startsWith("0::"));
163
+ const line = readFileSync3("/proc/self/cgroup", "utf8").split("\n").find((entry) => entry.startsWith("0::"));
77
164
  self = line?.slice(3) ?? "";
78
165
  } catch {
79
166
  }
@@ -81,7 +168,7 @@ function cgroupHost() {
81
168
  }
82
169
  function controllers(dir) {
83
170
  try {
84
- return readFileSync(join(dir, "cgroup.controllers"), "utf8").trim().split(/\s+/u);
171
+ return readFileSync3(join(dir, "cgroup.controllers"), "utf8").trim().split(/\s+/u);
85
172
  } catch {
86
173
  return [];
87
174
  }
@@ -96,8 +183,8 @@ function ioDelegated(host) {
96
183
  function enable(dir) {
97
184
  const file = join(dir, "cgroup.subtree_control");
98
185
  try {
99
- if (readFileSync(file, "utf8").split(/\s+/u).includes("io")) return;
100
- writeFileSync(file, "+io");
186
+ if (readFileSync3(file, "utf8").split(/\s+/u).includes("io")) return;
187
+ writeFileSync2(file, "+io");
101
188
  } catch {
102
189
  }
103
190
  }
@@ -110,7 +197,7 @@ function applyIo(host, scope, weight, max) {
110
197
  return { weight: false, max: max ? "failed" : "unset" };
111
198
  const write = (file, text) => {
112
199
  try {
113
- writeFileSync(join(dir, file), text);
200
+ writeFileSync2(join(dir, file), text);
114
201
  return true;
115
202
  } catch {
116
203
  return false;
@@ -288,85 +375,6 @@ function waiterFile(paths, pid) {
288
375
  return join3(paths.waiters, String(pid));
289
376
  }
290
377
 
291
- // src/lease/host.ts
292
- import { readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
293
- function hostSources(env) {
294
- return {
295
- loadavg: env["PMCP_HEAVY_LOADAVG_FILE"] || "/proc/loadavg",
296
- pressure: env["PMCP_HEAVY_PRESSURE_FILE"] || "/proc/pressure/io"
297
- };
298
- }
299
- function read(file) {
300
- try {
301
- return readFileSync2(file, "utf8");
302
- } catch {
303
- return null;
304
- }
305
- }
306
- function readHost(sources) {
307
- const load = read(sources.loadavg)?.split(" ")[0]?.trim() || null;
308
- const some = read(sources.pressure)?.match(/^some (.*)$/mu)?.[1] ?? "";
309
- const pressure = {};
310
- for (const [, key, value] of some.matchAll(/(avg\d+)=([0-9.]+)/gu))
311
- pressure[key] = value;
312
- return { load, io: pressure["avg10"] ?? null, pressure };
313
- }
314
- function hostNow(reading) {
315
- return `load ${reading.load ?? "n/a"} io ${reading.io ?? "n/a"}`;
316
- }
317
- function below(value, max) {
318
- return value === null || Number(value) < max;
319
- }
320
- function hostSettled(settings2, paths, sources) {
321
- const reading = readHost(sources);
322
- if (!below(reading.load, settings2.maxLoad)) return false;
323
- const io2 = reading.pressure[settings2.ioWindow] ?? reading.io;
324
- if (!below(io2, settings2.maxIo)) return false;
325
- try {
326
- writeFileSync2(paths.settled, `${nowUtc()}
327
- `);
328
- } catch {
329
- }
330
- return true;
331
- }
332
- function sleepSeconds(seconds) {
333
- if (seconds <= 0) return;
334
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, seconds * 1e3);
335
- }
336
-
337
- // src/lease/queue.ts
338
- import { readFileSync as readFileSync3 } from "fs";
339
- function sessionOf(env, cwd) {
340
- const inferred = inferSession(env, [], []).session;
341
- if (inferred) return inferred;
342
- try {
343
- const stat = readFileSync3("/proc/self/stat", "utf8");
344
- const group = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[2];
345
- if (group) return `pgid:${group}`;
346
- } catch {
347
- }
348
- return `cwd:${cwd}`;
349
- }
350
- var CAPPED = ["interactive", "bulk"];
351
- function parkForSession(park) {
352
- if (park.cap === 0 || !CAPPED.includes(park.lane)) return 0;
353
- const started = epoch();
354
- const queued = () => liveWaiters(park.paths).filter(
355
- (record2) => record2.session === park.session && record2.lane === park.lane
356
- ).length;
357
- let count = queued();
358
- if (count < park.cap) return 0;
359
- park.say(
360
- `parked outside the queue: this session already has ${count} queued ${park.lane} job(s) (per_session ${park.cap})`
361
- );
362
- for (; ; ) {
363
- if (epoch() - started >= park.maxWait) return null;
364
- sleepSeconds(1);
365
- count = queued();
366
- if (count < park.cap) return epoch() - started;
367
- }
368
- }
369
-
370
378
  // src/lease/settle.ts
371
379
  function io(settings2, reading) {
372
380
  return reading.pressure[settings2.ioWindow] ?? reading.io;
@@ -977,6 +985,7 @@ var Sampler = class {
977
985
  };
978
986
 
979
987
  // src/lease/run.ts
988
+ var DRAIN_MS = 2e3;
980
989
  var INVALID_EXIT = 2;
981
990
  function prefixed(argv, prefix) {
982
991
  const name = (word = "") => word.slice(word.lastIndexOf("/") + 1);
@@ -996,15 +1005,26 @@ var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
996
1005
  var HEAD = 2048;
997
1006
  function execute(argv, run2, extra, watch) {
998
1007
  const [bin, ...rest] = argv;
1008
+ const kept = run2.output;
1009
+ const echo = run2.echo !== false;
999
1010
  return new Promise((resolve) => {
1000
1011
  const child = spawn(bin ?? "true", rest, {
1001
1012
  cwd: run2.cwd,
1002
1013
  env: { ...run2.env, ...extra },
1003
- stdio: ["inherit", "inherit", watch.stderrHead ? "pipe" : "inherit"]
1014
+ stdio: [
1015
+ "inherit",
1016
+ kept ? "pipe" : "inherit",
1017
+ kept || watch.stderrHead ? "pipe" : "inherit"
1018
+ ]
1004
1019
  });
1005
1020
  let head = "";
1021
+ child.stdout?.on("data", (chunk) => {
1022
+ if (echo) process.stdout.write(chunk);
1023
+ kept?.write(chunk);
1024
+ });
1006
1025
  child.stderr?.on("data", (chunk) => {
1007
- process.stderr.write(chunk);
1026
+ if (echo) process.stderr.write(chunk);
1027
+ kept?.write(chunk);
1008
1028
  if (head.length >= HEAD) return;
1009
1029
  head += chunk.toString("utf8");
1010
1030
  watch.stderrHead?.(head.slice(0, HEAD));
@@ -1012,8 +1032,13 @@ function execute(argv, run2, extra, watch) {
1012
1032
  void watch.started?.();
1013
1033
  const forward = (signal) => child.kill(signal);
1014
1034
  for (const signal of SIGNALS) process.on(signal, forward);
1035
+ const release2 = holdOnClosedPipe();
1015
1036
  const timer = setInterval(() => watch.tick(child.pid), 1e3);
1037
+ let finished = false;
1016
1038
  const done = (code) => {
1039
+ if (finished) return;
1040
+ finished = true;
1041
+ release2();
1017
1042
  clearInterval(timer);
1018
1043
  for (const signal of SIGNALS) process.off(signal, forward);
1019
1044
  resolve(code);
@@ -1023,8 +1048,13 @@ function execute(argv, run2, extra, watch) {
1023
1048
  done(127);
1024
1049
  });
1025
1050
  child.on("exit", (code, signal) => {
1026
- if (code !== null) return done(code);
1027
- done(128 + (signal && constants.signals[signal] || 15));
1051
+ const exit = code ?? 128 + (signal && constants.signals[signal] || 15);
1052
+ if (!child.stdout && !child.stderr) return done(exit);
1053
+ const drained = setTimeout(() => done(exit), DRAIN_MS);
1054
+ child.on("close", () => {
1055
+ clearTimeout(drained);
1056
+ done(exit);
1057
+ });
1028
1058
  });
1029
1059
  });
1030
1060
  }
@@ -1481,7 +1511,7 @@ function ticketOwner(dir, id) {
1481
1511
  );
1482
1512
  return typeof request?.session === "string" ? request.session : null;
1483
1513
  }
1484
- function submit(request) {
1514
+ function openTicket(request, blocking) {
1485
1515
  prune(request.dir);
1486
1516
  const id = `${Math.floor(Date.now() / 1e3)}-${randomBytes(3).toString("hex")}`;
1487
1517
  const path = ticketDir(request.dir, id);
@@ -1492,9 +1522,24 @@ function submit(request) {
1492
1522
  label: request.label,
1493
1523
  cwd: request.cwd,
1494
1524
  ...request.session ? { session: request.session } : {},
1525
+ ...blocking ? { blocking: true } : {},
1495
1526
  created: (/* @__PURE__ */ new Date()).toISOString()
1496
1527
  });
1497
- const log = openSync4(join5(path, "log"), "a");
1528
+ return id;
1529
+ }
1530
+ function blockingTicket(request) {
1531
+ const id = openTicket(request, true);
1532
+ writeFileSync4(join5(ticketDir(request.dir, id), "pid"), `${process.pid}
1533
+ `);
1534
+ return id;
1535
+ }
1536
+ function jobLogPath(dir, id) {
1537
+ return join5(ticketDir(dir, id), "log");
1538
+ }
1539
+ function submit(request) {
1540
+ const id = openTicket(request, false);
1541
+ const path = ticketDir(request.dir, id);
1542
+ const log = openSync4(join5(path, "runner.log"), "a");
1498
1543
  const [bin, ...args] = request.runner(id);
1499
1544
  const child = spawn2(bin, args, {
1500
1545
  cwd: request.cwd,
@@ -1547,8 +1592,7 @@ function recentTickets(dir) {
1547
1592
  }
1548
1593
  function logTail(dir, id, lines = 20) {
1549
1594
  try {
1550
- const text = readFileSync8(join5(ticketDir(dir, id), "log"), "utf8");
1551
- return text.split("\n").slice(-lines - 1).join("\n");
1595
+ return readJobLog(jobLogPath(dir, id)).split("\n").slice(-lines - 1).join("\n");
1552
1596
  } catch {
1553
1597
  return "";
1554
1598
  }
@@ -1922,6 +1966,16 @@ function viewOf(settings2, id) {
1922
1966
  }
1923
1967
  function ticketResult(context, settings2, id) {
1924
1968
  const view = viewOf(settings2, id);
1969
+ const tailText = one(context.args, "tail");
1970
+ if (tailText !== void 0 && !context.args.flags.has("log"))
1971
+ throw new ArgumentError("--tail goes with --log");
1972
+ if (context.args.flags.has("log")) {
1973
+ const tail2 = tailText === void 0 ? void 0 : Number(tailText);
1974
+ if (tail2 !== void 0 && !(Number.isInteger(tail2) && tail2 >= 1))
1975
+ throw new ArgumentError("--tail is a whole number of at least 1");
1976
+ context.ui.data(readJobLog(jobLogPath(settings2.dir, view.id), tail2));
1977
+ return EXIT.ok;
1978
+ }
1925
1979
  if (context.args.flags.has("json"))
1926
1980
  context.ui.data(`${JSON.stringify({ version: 1, ...view })}
1927
1981
  `);
@@ -2085,7 +2139,9 @@ async function run(context) {
2085
2139
  return submitTicket(context, lease, args.passthrough);
2086
2140
  }
2087
2141
  if (now) requireOperatorFor(context, "pmcp heavy --now");
2088
- const ticket = one(args, "ticket");
2142
+ const submitted = one(args, "ticket");
2143
+ const kept = keepOutput(context, lease, label, submitted);
2144
+ const ticket = submitted ?? kept?.id;
2089
2145
  let result = null;
2090
2146
  const config = one(args, "config") ?? findConfig(context.cwd);
2091
2147
  const code = await runHeavy({
@@ -2101,13 +2157,19 @@ async function run(context) {
2101
2157
  argv: args.passthrough,
2102
2158
  cwd: context.cwd,
2103
2159
  env: context.env,
2104
- say,
2160
+ say: (line) => {
2161
+ say(line);
2162
+ kept?.log.write(`pmcp heavy: ${line}
2163
+ `);
2164
+ },
2165
+ ...kept ? { output: kept.log, echo: submitted === void 0 } : {},
2105
2166
  ...ticket ? {
2106
2167
  onUsage: (usage) => {
2107
2168
  result = { version: 1, ticket, ...usage };
2108
2169
  }
2109
2170
  } : {}
2110
2171
  });
2172
+ kept?.log.close();
2111
2173
  if (ticket)
2112
2174
  writeResult(
2113
2175
  lease.dir,
@@ -2115,10 +2177,35 @@ async function run(context) {
2115
2177
  result ?? { version: 1, ticket, exit: code, outcome: "ran" },
2116
2178
  true
2117
2179
  );
2180
+ if (kept && submitted === void 0 && code !== 0)
2181
+ say(`output kept: pmcp heavy result ${kept.id} --log`);
2118
2182
  return code;
2119
2183
  }
2184
+ function keepOutput(context, lease, label, submitted) {
2185
+ const cap = lease.jobLogBytes ?? DEFAULT_JOB_LOG_BYTES;
2186
+ try {
2187
+ if (submitted !== void 0)
2188
+ return {
2189
+ id: submitted,
2190
+ log: new JobLog(
2191
+ jobLogPath(lease.dir, submitted),
2192
+ cap || DEFAULT_JOB_LOG_BYTES
2193
+ )
2194
+ };
2195
+ if (cap === 0 || !lease.enabled) return null;
2196
+ const id = blockingTicket({
2197
+ dir: lease.dir,
2198
+ label: label ?? context.args.passthrough.join(" "),
2199
+ cwd: context.cwd,
2200
+ session: sessionOf(context.env, context.cwd)
2201
+ });
2202
+ return { id, log: new JobLog(jobLogPath(lease.dir, id), cap) };
2203
+ } catch {
2204
+ return null;
2205
+ }
2206
+ }
2120
2207
  var heavyCommand = { ...heavySpec, run };
2121
2208
  export {
2122
2209
  heavyCommand
2123
2210
  };
2124
- //# sourceMappingURL=heavy-HZQVFI6P.js.map
2211
+ //# sourceMappingURL=heavy-X3KZ7WBU.js.map