@modootoday/pmcp 0.24.0 → 0.25.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 (105) 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-D6FRJPPI.js → affected-IPFJM2KD.js} +484 -140
  6. package/dist/{apply-6JVJ7FDZ.js → apply-6XLLYLJT.js} +15 -14
  7. package/dist/{broadcast-VKZY7WSD.js → broadcast-34CEG2NQ.js} +5 -2
  8. package/dist/{chunk-B3OZ4GGO.js → chunk-23PE3HZB.js} +16 -1
  9. package/dist/{chunk-42SO7KYX.js → chunk-2GD7PQ7J.js} +2 -2
  10. package/dist/{chunk-7A6QIROT.js → chunk-2TXVOHRS.js} +3 -3
  11. package/dist/{chunk-QR4GXET7.js → chunk-3P6Y2BAO.js} +3 -3
  12. package/dist/{chunk-5QBOGEVE.js → chunk-5MUD7FHP.js} +2 -2
  13. package/dist/{chunk-2GZKA33O.js → chunk-A4P3IIPE.js} +2 -2
  14. package/dist/{chunk-UFWW4H6V.js → chunk-BG6TONJO.js} +2 -2
  15. package/dist/{chunk-HES44LTA.js → chunk-C3KRMTIZ.js} +28 -4
  16. package/dist/{chunk-QY2P54Z2.js → chunk-DITIXBFB.js} +61 -8
  17. package/dist/{chunk-6UGHVU5B.js → chunk-DWHM5BAY.js} +2 -2
  18. package/dist/{chunk-TIH7JFPJ.js → chunk-EC5QLEZD.js} +2 -2
  19. package/dist/{chunk-RZYZILU4.js → chunk-EWYLWBKS.js} +2 -2
  20. package/dist/{chunk-LI3BII4F.js → chunk-ISWR2XIU.js} +2 -2
  21. package/dist/{chunk-WNP2BXR7.js → chunk-LZVHFPN6.js} +5 -5
  22. package/dist/{chunk-K6ATERWS.js → chunk-MBHI2TKQ.js} +4 -4
  23. package/dist/{chunk-43MXRTKH.js → chunk-NAHAESFV.js} +9 -4
  24. package/dist/chunk-NQCAKDRY.js +156 -0
  25. package/dist/chunk-OIKT4SYO.js +42 -0
  26. package/dist/{chunk-D2MHB5EF.js → chunk-PECS47OL.js} +3 -3
  27. package/dist/{chunk-62BC3K4Z.js → chunk-PGZZI42O.js} +2 -2
  28. package/dist/{chunk-S6G7YWNE.js → chunk-QYHM6554.js} +2 -2
  29. package/dist/{chunk-2W2F5BWF.js → chunk-RF6RDJYH.js} +16 -16
  30. package/dist/{chunk-SUDG7B6S.js → chunk-SDFJJJB5.js} +2 -2
  31. package/dist/chunk-SMBU3QLE.js +7 -0
  32. package/dist/{chunk-644GNYMB.js → chunk-SRSKCFFS.js} +3 -3
  33. package/dist/{chunk-LB2WXBPA.js → chunk-SSQ6EWNA.js} +5 -5
  34. package/dist/{chunk-56VBB3H7.js → chunk-TJW4DP26.js} +2 -2
  35. package/dist/{chunk-25M2YWBH.js → chunk-TOR6SKRB.js} +146 -63
  36. package/dist/{chunk-ISGHJHVH.js → chunk-UQHJUTDW.js} +2 -2
  37. package/dist/{chunk-M6X6HVQK.js → chunk-VQBXWMLT.js} +2 -2
  38. package/dist/{chunk-UYBWUOLR.js → chunk-VYQJPT27.js} +4 -4
  39. package/dist/{cli-GFDT4YXM.js → cli-5G2OYTIL.js} +9 -9
  40. package/dist/{cli-WWNTQJPV.js → cli-QDQYUHAP.js} +9 -9
  41. package/dist/cli.js +38 -5
  42. package/dist/{completion-I63UIDZ7.js → completion-3GVNPLZY.js} +4 -4
  43. package/dist/{diagnostics-RUJZBPNZ.js → diagnostics-2W7QDQNG.js} +6 -6
  44. package/dist/{doctor-CLUFTEFO.js → doctor-3TDO5LJ5.js} +17 -16
  45. package/dist/{entry-QSJCFI5Z.js → entry-E62DZQJF.js} +10 -10
  46. package/dist/{exec-mcp-AFPUJTN7.js → exec-mcp-4N7FLY52.js} +13 -12
  47. package/dist/{harness-PPM32AI5.js → harness-E2AUZDLV.js} +3 -3
  48. package/dist/harness-launch-gate.js +4 -4
  49. package/dist/harness-worker.js +6 -6
  50. package/dist/{heavy-TEHP5PHT.js → heavy-HZQVFI6P.js} +182 -52
  51. package/dist/hook-body.js +116 -45
  52. package/dist/{hooks-L4PXVEGR.js → hooks-VAEAK2FY.js} +4 -4
  53. package/dist/{host-MU2GRH57.js → host-4GJDGTLW.js} +7 -7
  54. package/dist/{host-LBTL47X7.js → host-I2EMQ7UE.js} +18 -65
  55. package/dist/{host-run-IRSAQA5Z.js → host-run-DDMKD3BU.js} +5 -5
  56. package/dist/http.js +1 -1
  57. package/dist/{import-mcp-QVPW6A2Q.js → import-mcp-TNSAMJXI.js} +12 -11
  58. package/dist/index.d.ts +1 -1
  59. package/dist/index.js +16 -15
  60. package/dist/{init-46STH6FP.js → init-UA7MDNTZ.js} +2 -2
  61. package/dist/{invoke-I6C6UT6Q.js → invoke-HW7NBPGP.js} +8 -8
  62. package/dist/{list-HXG6EB7V.js → list-A7VQJXE5.js} +14 -13
  63. package/dist/{logout-SSUXJ6SE.js → logout-HNPLUKJY.js} +13 -12
  64. package/dist/{mailbox-5FVFMQ2J.js → mailbox-MR6TPD3P.js} +20 -6
  65. package/dist/{mainline-4XP6ZORU.js → mainline-MSLW3UFD.js} +14 -8
  66. package/dist/{mcp-L6X45IOS.js → mcp-6C23GX2E.js} +2 -2
  67. package/dist/{modes-SEINLLMK.js → modes-7OY7R73T.js} +3 -3
  68. package/dist/{pause-CMZOIHTJ.js → pause-H6ZYZF7C.js} +5 -2
  69. package/dist/{project-4JPKU2D7.js → project-BX6NCGKB.js} +4 -4
  70. package/dist/{report-UB7MXAUB.js → report-43SFNNCF.js} +2 -2
  71. package/dist/{resume-PAKIT4TT.js → resume-2BWGSTCN.js} +5 -2
  72. package/dist/{run-PMASXIGY.js → run-2UVAWBAF.js} +12 -11
  73. package/dist/{run-OW7436TY.js → run-7TRWZFEZ.js} +4 -4
  74. package/dist/{serve-P3HJN6AF.js → serve-4XZ5SKJJ.js} +3 -3
  75. package/dist/{setup-6AQUOWOH.js → setup-GRWLDBVB.js} +4 -4
  76. package/dist/{start-login-P7YDRTA3.js → start-login-AR7ITWNV.js} +13 -12
  77. package/dist/{status-4PYPTYUB.js → status-2GDYLIR3.js} +6 -3
  78. package/dist/{status-DAXQKT35.js → status-VQCMJFVE.js} +31 -28
  79. package/dist/{status-DLGZDYEP.js → status-ZY6LDQSF.js} +13 -12
  80. package/dist/stdio.js +2 -2
  81. package/dist/{sweep-VURZU6DI.js → sweep-76BUOGEI.js} +5 -2
  82. package/dist/{test-H243OTSK.js → test-VWGNFSH5.js} +15 -13
  83. package/dist/{tui-P6XTSTQO.js → tui-TUMOQBE7.js} +4 -4
  84. package/dist/{unbroadcast-7AMLURCG.js → unbroadcast-HJHYUHZL.js} +5 -2
  85. package/dist/{worker-5YJLIGTU.js → worker-NEEPJRVV.js} +8 -8
  86. package/dist/{worktree-create-FTSLMZWS.js → worktree-create-ZQRN5JBD.js} +2 -2
  87. package/dist/{worktree-list-WH6OX6U7.js → worktree-list-WZC75NLF.js} +11 -12
  88. package/dist/{worktree-sync-DGNHSQ64.js → worktree-sync-MUVKK2CV.js} +5 -5
  89. package/docs/commands.md +9 -7
  90. package/docs/git-workflow.md +7 -1
  91. package/docs/glossary.md +1 -1
  92. package/docs/hooks.md +20 -16
  93. package/docs/project-configuration.md +76 -37
  94. package/docs/sessions.md +9 -2
  95. package/docs/upgrading.md +58 -0
  96. package/gemini-extension.json +2 -2
  97. package/mcp.json +1 -1
  98. package/package.json +5 -5
  99. package/plugin.json +1 -1
  100. package/plugins/pmcp/.claude-plugin/plugin.json +1 -1
  101. package/plugins/pmcp/.mcp.json +1 -1
  102. package/plugins/pmcp/gemini-extension.json +2 -2
  103. package/plugins/pmcp/mcp.json +1 -1
  104. package/plugins/pmcp/plugin.json +1 -1
  105. package/dist/chunk-LTMHE5VL.js +0 -7
@@ -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-NAHAESFV.js";
13
19
  import "./chunk-JPYQDOEW.js";
14
20
  import {
15
21
  ArgumentError,
@@ -21,7 +27,7 @@ import {
21
27
  DISABLE_ENV,
22
28
  NOW_ENV,
23
29
  leaseSettingsFor
24
- } from "./chunk-QY2P54Z2.js";
30
+ } from "./chunk-DITIXBFB.js";
25
31
  import {
26
32
  LANES,
27
33
  describeRecord,
@@ -100,19 +106,24 @@ function applyIo(host, scope, weight, max) {
100
106
  for (let at = 1; at < parts.length; at += 1)
101
107
  enable(join(host.root, ...parts.slice(0, at)));
102
108
  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
- }
109
+ if (!controllers(dir).includes("io"))
110
+ return { weight: false, max: max ? "failed" : "unset" };
111
+ const write = (file, text) => {
112
+ try {
113
+ writeFileSync(join(dir, file), text);
114
+ return true;
115
+ } catch {
116
+ return false;
117
+ }
118
+ };
119
+ const written = write("io.weight", `default ${weight}`);
120
+ if (!max) return { weight: written, max: "unset" };
121
+ return { weight: written, max: write("io.max", max) ? "set" : "failed" };
111
122
  }
112
123
  function scopeCgroup(unit) {
113
124
  const run2 = spawnSync(
114
125
  "systemctl",
115
- ["--user", "show", unit, "-p", "ControlGroup", "--value"],
126
+ ["--user", "show", `${unit}.scope`, "-p", "ControlGroup", "--value"],
116
127
  { encoding: "utf8" }
117
128
  );
118
129
  const path = run2.status === 0 ? run2.stdout.trim() : "";
@@ -174,8 +185,10 @@ async function weigh(unit, settings2, lane, host, say, onCgroup) {
174
185
  settings2.io.weights[lane],
175
186
  settings2.io.max[lane]
176
187
  );
177
- if (!set && settings2.io.enabled === true)
188
+ if (!set.weight)
178
189
  say(`io control did not reach ${scope}; running without io.weight`);
190
+ if (set.max === "failed")
191
+ say(`io.max for the ${lane} lane was refused; the job runs without it`);
179
192
  return;
180
193
  }
181
194
  await new Promise((resolve) => setTimeout(resolve, 100));
@@ -381,13 +394,41 @@ function hostVerdict(settings2, reading, waiting) {
381
394
  return "wait";
382
395
  }
383
396
 
397
+ // src/lease/skip.ts
398
+ var NESTED = "nested";
399
+ var OPERATOR = "operator";
400
+ var LEGACY_NESTED = /^inside pmcp heavy \d+$/u;
401
+ function allowedReasons(settings2) {
402
+ return [
403
+ .../* @__PURE__ */ new Set([
404
+ NESTED,
405
+ OPERATOR,
406
+ ...settings2.skipReasons,
407
+ ...settings2.skipAlways
408
+ ])
409
+ ];
410
+ }
411
+ function skipRefusal(settings2, reason2, checks) {
412
+ if (reason2 === NESTED || LEGACY_NESTED.test(reason2))
413
+ return checks.nested() ? null : `${NESTED} is the reason pmcp sets inside a leased job, and no leased job encloses this one`;
414
+ if (reason2 === OPERATOR)
415
+ return checks.operator() ? null : `${OPERATOR} is the operator's own skip, from the operator's terminal or with the operator token`;
416
+ if (settings2.skipReasons.includes(reason2)) return null;
417
+ if (settings2.skipAlways.includes(reason2)) return null;
418
+ return `"${reason2}" is not a lease skip reason`;
419
+ }
420
+
384
421
  // src/lease/acquire.ts
385
422
  var STEP_SECONDS = 1;
423
+ function skipSource(settings2, env) {
424
+ for (const variable of [DISABLE_ENV, settings2.legacySkipEnv]) {
425
+ const reason2 = variable ? env[variable] : void 0;
426
+ if (variable && reason2) return { reason: reason2, variable };
427
+ }
428
+ return null;
429
+ }
386
430
  function skipReason(settings2, env) {
387
- const own = env[DISABLE_ENV];
388
- if (own) return own;
389
- const legacy = settings2.legacySkipEnv ? env[settings2.legacySkipEnv] : "";
390
- return legacy || null;
431
+ return skipSource(settings2, env)?.reason ?? null;
391
432
  }
392
433
  function reentrant(settings2, env) {
393
434
  const paths = leasePaths(settings2.dir);
@@ -506,8 +547,7 @@ function held(options, paths, fd, start) {
506
547
  const pid = String(process.pid);
507
548
  const env = { [settings2.markerEnv]: pid };
508
549
  if (settings2.legacyMarkerEnv) env[settings2.legacyMarkerEnv] = pid;
509
- if (settings2.legacySkipEnv)
510
- env[settings2.legacySkipEnv] = `inside pmcp heavy ${pid}`;
550
+ if (settings2.legacySkipEnv) env[settings2.legacySkipEnv] = NESTED;
511
551
  let open = true;
512
552
  return {
513
553
  kind: "held",
@@ -524,29 +564,46 @@ function acquireLease(options) {
524
564
  const { settings: settings2, env, label, say } = options;
525
565
  if (!settings2.enabled) return { kind: "disabled" };
526
566
  const paths = leasePaths(settings2.dir);
527
- const skip = skipReason(settings2, env);
528
- const refused = skip !== null && options.lane === "bulk" && !settings2.skipAlways.includes(skip);
567
+ const skip = skipSource(settings2, env);
568
+ const invalid = skip === null ? null : skipRefusal(settings2, skip.reason, {
569
+ nested: () => reentrant(settings2, env),
570
+ operator: () => options.operator?.() ?? false
571
+ });
572
+ if (skip !== null && invalid !== null) {
573
+ if (reentrant(settings2, env)) return { kind: "reentrant" };
574
+ say(
575
+ `${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.`
576
+ );
577
+ logEvent(
578
+ paths,
579
+ process.pid,
580
+ "skip-invalid",
581
+ `reason=${skip.reason} env=${skip.variable} cwd=${options.cwd} label=${label}`
582
+ );
583
+ return { kind: "invalid", reason: skip.reason, variable: skip.variable };
584
+ }
585
+ const refused = skip !== null && options.lane === "bulk" && !settings2.skipAlways.includes(skip.reason);
529
586
  if (refused && reentrant(settings2, env)) return { kind: "reentrant" };
530
587
  if (skip !== null && refused) {
531
588
  say(
532
- `the lease skip (${skip}) is not honoured for a bulk job (--lane bulk, or a [[host.lease.commands]] entry with lane = "bulk"); it queues in the bulk lane. For an emergency run: pmcp heavy --now --reason <text> -- <command>`
589
+ `the lease skip (${skip.reason}) is not honoured for a bulk job (--lane bulk, or a [[host.lease.commands]] entry with lane = "bulk"); it queues in the bulk lane. For an emergency run: pmcp heavy --now --reason <text> -- <command>`
533
590
  );
534
591
  logEvent(
535
592
  paths,
536
593
  process.pid,
537
594
  "skip-refused",
538
- `reason=${skip} cwd=${options.cwd} label=${label}`
595
+ `reason=${skip.reason} env=${skip.variable} cwd=${options.cwd} label=${label}`
539
596
  );
540
597
  }
541
598
  if (skip !== null && !refused) {
542
- say(`running without the host lease: ${skip}`);
599
+ say(`running without the host lease: ${skip.reason}`);
543
600
  logEvent(
544
601
  paths,
545
602
  process.pid,
546
603
  "skip",
547
- `reason=${skip} cwd=${options.cwd} label=${label}`
604
+ `reason=${skip.reason} env=${skip.variable} cwd=${options.cwd} label=${label}`
548
605
  );
549
- return { kind: "skipped", reason: skip };
606
+ return { kind: "skipped", ...skip };
550
607
  }
551
608
  if (!flockAvailable()) {
552
609
  say("flock is not installed; running without the host lease");
@@ -751,6 +808,17 @@ function skipShare(records) {
751
808
  runs: ran.length
752
809
  };
753
810
  }
811
+ function skipReasons(records) {
812
+ const honoured = {};
813
+ const invalid = {};
814
+ for (const record2 of records) {
815
+ if (record2.skip !== void 0)
816
+ honoured[record2.skip] = (honoured[record2.skip] ?? 0) + 1;
817
+ if (record2.skip_invalid !== void 0)
818
+ invalid[record2.skip_invalid] = (invalid[record2.skip_invalid] ?? 0) + 1;
819
+ }
820
+ return { honoured, invalid };
821
+ }
754
822
  function percentile(values, share) {
755
823
  const sorted = [...values].sort((a, b) => a - b);
756
824
  return sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * share))] ?? 0;
@@ -776,7 +844,9 @@ function usageStats(records) {
776
844
  signature: key,
777
845
  samples: ran.length,
778
846
  failed: ran.filter((record2) => record2.exit !== 0).length,
779
- timeouts: list.length - ran.length,
847
+ timeouts: list.filter(
848
+ (record2) => record2.outcome !== "ran" && record2.outcome !== "invalid"
849
+ ).length,
780
850
  skipped: ran.filter((record2) => record2.skip !== void 0).length,
781
851
  p50: pick(0.5),
782
852
  p90: pick(0.9)
@@ -907,6 +977,7 @@ var Sampler = class {
907
977
  };
908
978
 
909
979
  // src/lease/run.ts
980
+ var INVALID_EXIT = 2;
910
981
  function prefixed(argv, prefix) {
911
982
  const name = (word = "") => word.slice(word.lastIndexOf("/") + 1);
912
983
  return argv.length >= prefix.length && prefix.every((word, at) => (at === 0 ? name(argv[0]) : argv[at]) === word);
@@ -987,6 +1058,18 @@ function record(run2, fields) {
987
1058
  appendUsage(leasePaths(run2.settings.dir).usage, usage, run2.settings.usageCap);
988
1059
  run2.onUsage?.(usage);
989
1060
  }
1061
+ function skipFields(run2, outcome) {
1062
+ if (outcome.kind === "invalid")
1063
+ return { skip_invalid: outcome.reason, skip_env: outcome.variable };
1064
+ if (outcome.kind === "skipped")
1065
+ return {
1066
+ skip: outcome.reason,
1067
+ ...outcome.variable ? { skip_env: outcome.variable } : {}
1068
+ };
1069
+ if (outcome.kind === "disabled" || outcome.kind === "reentrant") return {};
1070
+ const refused = skipSource(run2.settings, run2.env);
1071
+ return refused ? { skip_refused: refused.reason, skip_env: refused.variable } : {};
1072
+ }
990
1073
  var CANCELLED_EXIT = 130;
991
1074
  var NOTHING = {
992
1075
  wall_s: 0,
@@ -1007,6 +1090,18 @@ async function runHeavy(run2) {
1007
1090
  } else {
1008
1091
  outcome = acquireLease({ ...run2, label, lane, weight });
1009
1092
  }
1093
+ if (outcome.kind === "invalid") {
1094
+ record(run2, {
1095
+ ...NOTHING,
1096
+ lane,
1097
+ weight,
1098
+ start: "none",
1099
+ outcome: "invalid",
1100
+ exit: INVALID_EXIT,
1101
+ ...skipFields(run2, outcome)
1102
+ });
1103
+ return INVALID_EXIT;
1104
+ }
1010
1105
  if (outcome.kind === "cancelled") {
1011
1106
  record(run2, {
1012
1107
  ...NOTHING,
@@ -1014,7 +1109,8 @@ async function runHeavy(run2) {
1014
1109
  weight,
1015
1110
  start: "none",
1016
1111
  outcome: "cancelled",
1017
- exit: CANCELLED_EXIT
1112
+ exit: CANCELLED_EXIT,
1113
+ ...skipFields(run2, outcome)
1018
1114
  });
1019
1115
  return CANCELLED_EXIT;
1020
1116
  }
@@ -1033,7 +1129,8 @@ async function runHeavy(run2) {
1033
1129
  weight,
1034
1130
  start: "none",
1035
1131
  outcome: "timeout",
1036
- exit: BUSY_EXIT
1132
+ exit: BUSY_EXIT,
1133
+ ...skipFields(run2, outcome)
1037
1134
  });
1038
1135
  return BUSY_EXIT;
1039
1136
  }
@@ -1084,7 +1181,7 @@ async function runHeavy(run2) {
1084
1181
  start: held2 ? held2.start : "none",
1085
1182
  outcome: "ran",
1086
1183
  exit: code,
1087
- ...outcome.kind === "skipped" ? { skip: outcome.reason } : {}
1184
+ ...skipFields(run2, outcome)
1088
1185
  });
1089
1186
  }
1090
1187
  return code;
@@ -1304,10 +1401,10 @@ function leaseStatus(options) {
1304
1401
  );
1305
1402
  const outside = options.outside ?? ((pids) => outsideLease({ holders: pids }));
1306
1403
  lines.push(...outsideLines(outside(running.map((job2) => job2.pid))));
1307
- const skip = skipReason(settings2, env);
1404
+ const skip = skipSource(settings2, env);
1308
1405
  if (skip !== null)
1309
1406
  lines.push(
1310
- `skip: this shell runs without the lease (${DISABLE_ENV}): ${skip}`
1407
+ `skip: this shell runs without the lease (${skip.variable}): ${skip.reason}`
1311
1408
  );
1312
1409
  return lines;
1313
1410
  }
@@ -1378,6 +1475,12 @@ function prune(dir) {
1378
1475
  }
1379
1476
  }
1380
1477
  }
1478
+ function ticketOwner(dir, id) {
1479
+ const request = readJson(
1480
+ join5(ticketDir(dir, id), "request.json")
1481
+ );
1482
+ return typeof request?.session === "string" ? request.session : null;
1483
+ }
1381
1484
  function submit(request) {
1382
1485
  prune(request.dir);
1383
1486
  const id = `${Math.floor(Date.now() / 1e3)}-${randomBytes(3).toString("hex")}`;
@@ -1388,6 +1491,7 @@ function submit(request) {
1388
1491
  ticket: id,
1389
1492
  label: request.label,
1390
1493
  cwd: request.cwd,
1494
+ ...request.session ? { session: request.session } : {},
1391
1495
  created: (/* @__PURE__ */ new Date()).toISOString()
1392
1496
  });
1393
1497
  const log = openSync4(join5(path, "log"), "a");
@@ -1691,11 +1795,11 @@ function queueList(context, settings2) {
1691
1795
  return EXIT.ok;
1692
1796
  }
1693
1797
  if (snapshot.waiters.length === 0) context.ui.data("queue: empty\n");
1694
- for (const w of snapshot.waiters)
1695
- context.ui.data(
1696
- `${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}
1697
- `
1698
- );
1798
+ context.ui.results.records(
1799
+ snapshot.waiters.map(
1800
+ (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}`
1801
+ )
1802
+ );
1699
1803
  return EXIT.ok;
1700
1804
  }
1701
1805
  function queuePromote(context, settings2, id) {
@@ -1704,6 +1808,7 @@ function queuePromote(context, settings2, id) {
1704
1808
  throw new ArgumentError(
1705
1809
  "promote starts a job at once: pass --now --reason <text>"
1706
1810
  );
1811
+ requireOperatorFor(context, "pmcp heavy promote --now");
1707
1812
  const paths = leasePaths(settings2.dir);
1708
1813
  return report(
1709
1814
  context,
@@ -1740,8 +1845,15 @@ function queueCancel(context, settings2, id) {
1740
1845
  return EXIT.ok;
1741
1846
  }
1742
1847
  const running = findRunning(paths, id);
1848
+ const force = context.args.flags.has("force");
1849
+ const owner = (ticket ? ticketOwner(settings2.dir, id) : null) ?? running?.session;
1850
+ if (force && owner !== void 0 && owner !== who(context).session)
1851
+ requireOperatorFor(
1852
+ context,
1853
+ `pmcp heavy cancel --force on another session's job (${owner})`
1854
+ );
1743
1855
  if (running !== null && !ticket) {
1744
- if (!context.args.flags.has("force")) {
1856
+ if (!force) {
1745
1857
  context.ui.error(`${id} is running; --force stops it`);
1746
1858
  return EXIT.failure;
1747
1859
  }
@@ -1754,7 +1866,7 @@ function queueCancel(context, settings2, id) {
1754
1866
  context.ui.error(waiting.why);
1755
1867
  return EXIT.failure;
1756
1868
  }
1757
- const done = cancel(settings2.dir, id, context.args.flags.has("force"));
1869
+ const done = cancel(settings2.dir, id, force);
1758
1870
  if (done === "running") {
1759
1871
  context.ui.error(`${id} is running; --force stops it`);
1760
1872
  return EXIT.failure;
@@ -1785,7 +1897,8 @@ function submitTicket(context, settings2, command) {
1785
1897
  ...command
1786
1898
  ],
1787
1899
  cwd: context.cwd,
1788
- env: context.env
1900
+ env: context.env,
1901
+ session: sessionOf(context.env, context.cwd)
1789
1902
  });
1790
1903
  context.ui.data(`${id}
1791
1904
  `);
@@ -1864,26 +1977,41 @@ function statLine(stat) {
1864
1977
  `write ${pair("write_bytes", 1e6, "MB")}`
1865
1978
  ].join(" ");
1866
1979
  }
1980
+ function top(context) {
1981
+ const text = one(context.args, "top");
1982
+ if (text === void 0) return void 0;
1983
+ const count = Number(text);
1984
+ if (!Number.isInteger(count) || count < 1)
1985
+ throw new ArgumentError("--top is a whole number of at least 1");
1986
+ return count;
1987
+ }
1867
1988
  function stats(context) {
1868
1989
  const records = readUsage(leasePaths(settings(context).dir).usage);
1869
- const found = usageStats(records);
1990
+ const limit = top(context);
1991
+ const found = usageStats(records).slice(0, limit);
1870
1992
  if (context.args.flags.has("json")) {
1871
1993
  context.ui.data(`${JSON.stringify(found)}
1872
1994
  `);
1873
1995
  return EXIT.ok;
1874
1996
  }
1875
- if (found.length === 0) context.ui.data("no usage recorded yet\n");
1997
+ const lines = [];
1998
+ if (found.length === 0) lines.push("no usage recorded yet");
1876
1999
  const { skipped, runs } = skipShare(records);
1877
2000
  if (runs > 0)
1878
- context.ui.data(
1879
- `skipped the lease: ${skipped} of ${runs} runs (${Math.round(skipped / runs * 100)}%)
1880
- `
2001
+ lines.push(
2002
+ `skipped the lease: ${skipped} of ${runs} runs (${Math.round(skipped / runs * 100)}%)`
1881
2003
  );
1882
- context.ui.data(
1883
- "signature @ dir samples p50/p90 of wall, cpu, rss, read, write\n"
2004
+ const reasons = skipReasons(records);
2005
+ const counted = (counts) => Object.entries(counts).sort(([a, x], [b, y]) => y - x || a.localeCompare(b)).map(([name, count]) => `${name} ${count}`).join(", ");
2006
+ if (Object.keys(reasons.honoured).length > 0)
2007
+ lines.push(`skip reasons: ${counted(reasons.honoured)}`);
2008
+ if (Object.keys(reasons.invalid).length > 0)
2009
+ lines.push(`refused skip reasons: ${counted(reasons.invalid)}`);
2010
+ lines.push(
2011
+ "signature @ dir samples p50/p90 of wall, cpu, rss, read, write"
1884
2012
  );
1885
- for (const stat of found) context.ui.data(`${statLine(stat)}
1886
- `);
2013
+ lines.push(...found.map(statLine));
2014
+ context.ui.results.records(lines);
1887
2015
  return EXIT.ok;
1888
2016
  }
1889
2017
  function verbs(context) {
@@ -1914,9 +2042,9 @@ function subcommand(context) {
1914
2042
  `);
1915
2043
  return EXIT.ok;
1916
2044
  }
1917
- for (const line of leaseStatus({ settings: lease, env: context.env }))
1918
- context.ui.data(`${line}
1919
- `);
2045
+ context.ui.results.records(
2046
+ leaseStatus({ settings: lease, env: context.env })
2047
+ );
1920
2048
  return EXIT.ok;
1921
2049
  }
1922
2050
  async function run(context) {
@@ -1956,6 +2084,7 @@ async function run(context) {
1956
2084
  if (now) throw new ArgumentError("--now runs at once; it is not submitted");
1957
2085
  return submitTicket(context, lease, args.passthrough);
1958
2086
  }
2087
+ if (now) requireOperatorFor(context, "pmcp heavy --now");
1959
2088
  const ticket = one(args, "ticket");
1960
2089
  let result = null;
1961
2090
  const config = one(args, "config") ?? findConfig(context.cwd);
@@ -1967,6 +2096,7 @@ async function run(context) {
1967
2096
  ...weight !== void 0 ? { weight } : {},
1968
2097
  ...now ? { now: reason2 } : {},
1969
2098
  root: config ? dirname(config) : context.cwd,
2099
+ operator: () => isOperator(context),
1970
2100
  ...ticket ? { id: ticket } : {},
1971
2101
  argv: args.passthrough,
1972
2102
  cwd: context.cwd,
@@ -1991,4 +2121,4 @@ var heavyCommand = { ...heavySpec, run };
1991
2121
  export {
1992
2122
  heavyCommand
1993
2123
  };
1994
- //# sourceMappingURL=heavy-TEHP5PHT.js.map
2124
+ //# sourceMappingURL=heavy-HZQVFI6P.js.map