privateer-agent 0.15.4 → 0.15.6

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 (229) hide show
  1. package/README.md +11 -0
  2. package/bin/boot-bundle.d.mts +2 -0
  3. package/bin/boot-bundle.mjs +44 -0
  4. package/bin/fresh-supervisor.d.mts +5 -1
  5. package/bin/fresh-supervisor.mjs +47 -10
  6. package/bin/privateer-launch.mjs +27 -3
  7. package/bin/privateer-subagent.mjs +5 -2
  8. package/bin/privateer-verify.mjs +12 -0
  9. package/bin/session-recovery.d.mts +53 -0
  10. package/bin/session-recovery.mjs +240 -0
  11. package/bin/session-seal-preload.mjs +17 -0
  12. package/bin/session-seal.d.mts +25 -0
  13. package/bin/session-seal.mjs +242 -0
  14. package/dist-boot/boot.mjs +3 -0
  15. package/dist-boot/c-27JKSMWL.mjs +1460 -0
  16. package/dist-boot/c-2BMRFV24.mjs +269 -0
  17. package/dist-boot/c-2CTF6JA3.mjs +166 -0
  18. package/dist-boot/c-2G3BBHRJ.mjs +84 -0
  19. package/dist-boot/c-2IDLKXX6.mjs +250 -0
  20. package/dist-boot/c-2NJD5VYM.mjs +8 -0
  21. package/dist-boot/c-2S5EEQPW.mjs +1602 -0
  22. package/dist-boot/c-2WRDCUVI.mjs +25 -0
  23. package/dist-boot/c-2YN3M256.mjs +14 -0
  24. package/dist-boot/c-37GM3GMU.mjs +187 -0
  25. package/dist-boot/c-3STKRSVO.mjs +2480 -0
  26. package/dist-boot/c-3TPV6TQQ.mjs +2320 -0
  27. package/dist-boot/c-3UVHLQDJ.mjs +225 -0
  28. package/dist-boot/c-42PUUZYC.mjs +697 -0
  29. package/dist-boot/c-4D5UMWVW.mjs +683 -0
  30. package/dist-boot/c-4ETZRMTA.mjs +46 -0
  31. package/dist-boot/c-4QT25BD5.mjs +1482 -0
  32. package/dist-boot/c-4WVR32AP.mjs +2579 -0
  33. package/dist-boot/c-5EMM567G.mjs +152 -0
  34. package/dist-boot/c-5FA4CV63.mjs +145 -0
  35. package/dist-boot/c-5GV3X3RB.mjs +14 -0
  36. package/dist-boot/c-5JCEPRIY.mjs +52 -0
  37. package/dist-boot/c-5NDKIIWT.mjs +16 -0
  38. package/dist-boot/c-5QL3AR26.mjs +4665 -0
  39. package/dist-boot/c-5XY6MFKN.mjs +5142 -0
  40. package/dist-boot/c-65UZIZC7.mjs +2897 -0
  41. package/dist-boot/c-6FUXKHOK.mjs +1969 -0
  42. package/dist-boot/c-6JHWQE4V.mjs +18242 -0
  43. package/dist-boot/c-6LOBR4I6.mjs +5280 -0
  44. package/dist-boot/c-6QHOZXKQ.mjs +14394 -0
  45. package/dist-boot/c-6ZO2SADQ.mjs +178 -0
  46. package/dist-boot/c-6ZORVVZP.mjs +1449 -0
  47. package/dist-boot/c-76QH4UCP.mjs +2441 -0
  48. package/dist-boot/c-77GO5L5Y.mjs +20982 -0
  49. package/dist-boot/c-7M23XFTN.mjs +5052 -0
  50. package/dist-boot/c-7TC367E2.mjs +32 -0
  51. package/dist-boot/c-7UOG7POX.mjs +1524 -0
  52. package/dist-boot/c-7VHP3FLN.mjs +376 -0
  53. package/dist-boot/c-A73JHZP2.mjs +13207 -0
  54. package/dist-boot/c-ABXULAFL.mjs +71 -0
  55. package/dist-boot/c-ANDD2AQO.mjs +74 -0
  56. package/dist-boot/c-AOY77AZL.mjs +1430 -0
  57. package/dist-boot/c-AXEPZ22I.mjs +108 -0
  58. package/dist-boot/c-B2Y7VNHU.mjs +427 -0
  59. package/dist-boot/c-B7VJUH73.mjs +77 -0
  60. package/dist-boot/c-BFW6CDVL.mjs +24 -0
  61. package/dist-boot/c-BHNIF2AR.mjs +188 -0
  62. package/dist-boot/c-BKF2O6BL.mjs +23 -0
  63. package/dist-boot/c-BOZXFTZN.mjs +8 -0
  64. package/dist-boot/c-BRNYJWZL.mjs +28 -0
  65. package/dist-boot/c-C3N4Z2HO.mjs +93 -0
  66. package/dist-boot/c-C4IV7ZFG.mjs +717 -0
  67. package/dist-boot/c-C5NK6UYV.mjs +793 -0
  68. package/dist-boot/c-C67644MB.mjs +1659 -0
  69. package/dist-boot/c-C6S2YB53.mjs +620 -0
  70. package/dist-boot/c-CDBEJSBF.mjs +37 -0
  71. package/dist-boot/c-CG47HBKU.mjs +435 -0
  72. package/dist-boot/c-CKCTWCT5.mjs +51 -0
  73. package/dist-boot/c-CN77DCGF.mjs +60 -0
  74. package/dist-boot/c-CRBXNKFO.mjs +1795 -0
  75. package/dist-boot/c-CRIHASQ6.mjs +973 -0
  76. package/dist-boot/c-CU4NGAUO.mjs +3786 -0
  77. package/dist-boot/c-CWRFLGQU.mjs +1883 -0
  78. package/dist-boot/c-CYQB2USO.mjs +32 -0
  79. package/dist-boot/c-DEE67DJO.mjs +379 -0
  80. package/dist-boot/c-DIFDBYOP.mjs +1258 -0
  81. package/dist-boot/c-DOSGVXDZ.mjs +34879 -0
  82. package/dist-boot/c-DR7XQI32.mjs +381 -0
  83. package/dist-boot/c-DTGPSB46.mjs +14666 -0
  84. package/dist-boot/c-DTHDNA4P.mjs +320 -0
  85. package/dist-boot/c-E4Z3Y5B5.mjs +3864 -0
  86. package/dist-boot/c-E66Z2TI7.mjs +203 -0
  87. package/dist-boot/c-EBU6RLRV.mjs +1527 -0
  88. package/dist-boot/c-EBZZNGSF.mjs +432 -0
  89. package/dist-boot/c-EC3LJ2KF.mjs +1032 -0
  90. package/dist-boot/c-EQBKXWNX.mjs +15829 -0
  91. package/dist-boot/c-EUEPIW4S.mjs +574 -0
  92. package/dist-boot/c-EX4YVWAT.mjs +378 -0
  93. package/dist-boot/c-EYZGSAJU.mjs +98 -0
  94. package/dist-boot/c-F75VRKY4.mjs +172 -0
  95. package/dist-boot/c-FH4NXKHV.mjs +177 -0
  96. package/dist-boot/c-FHNUCTEM.mjs +140 -0
  97. package/dist-boot/c-FJ5T42DS.mjs +5349 -0
  98. package/dist-boot/c-FPCNRL7G.mjs +1728 -0
  99. package/dist-boot/c-G4DLN7Q4.mjs +8 -0
  100. package/dist-boot/c-G56GYQFZ.mjs +2507 -0
  101. package/dist-boot/c-GLIOERDQ.mjs +1200 -0
  102. package/dist-boot/c-GMJ5HUBM.mjs +14 -0
  103. package/dist-boot/c-H3HSGMAQ.mjs +461 -0
  104. package/dist-boot/c-HIKTO6P7.mjs +275 -0
  105. package/dist-boot/c-I2MCJ34O.mjs +464 -0
  106. package/dist-boot/c-I3C6LBW4.mjs +765 -0
  107. package/dist-boot/c-I54OKQHW.mjs +387 -0
  108. package/dist-boot/c-IFSP3R4D.mjs +80 -0
  109. package/dist-boot/c-IZK77VB7.mjs +171 -0
  110. package/dist-boot/c-J3Y25UGE.mjs +54 -0
  111. package/dist-boot/c-J5IESS7W.mjs +27750 -0
  112. package/dist-boot/c-JJWZBY7L.mjs +254 -0
  113. package/dist-boot/c-JKTFXTGF.mjs +463 -0
  114. package/dist-boot/c-JN57AXQ4.mjs +77 -0
  115. package/dist-boot/c-KFIO6LUW.mjs +1096 -0
  116. package/dist-boot/c-KIEMEFWW.mjs +478 -0
  117. package/dist-boot/c-KIVXWBYD.mjs +28 -0
  118. package/dist-boot/c-KP6CRIP4.mjs +580 -0
  119. package/dist-boot/c-L26VOJX4.mjs +11558 -0
  120. package/dist-boot/c-L5GHWG5G.mjs +5988 -0
  121. package/dist-boot/c-M7NSQAKK.mjs +353 -0
  122. package/dist-boot/c-MCEWOPBW.mjs +56 -0
  123. package/dist-boot/c-MGPIEG7I.mjs +20 -0
  124. package/dist-boot/c-NREXJV3M.mjs +393 -0
  125. package/dist-boot/c-O5PP6CTX.mjs +162 -0
  126. package/dist-boot/c-OBQDHSXM.mjs +1774 -0
  127. package/dist-boot/c-OLQHHDD4.mjs +21 -0
  128. package/dist-boot/c-OXW4JQQH.mjs +319 -0
  129. package/dist-boot/c-P3D7ZUWN.mjs +1288 -0
  130. package/dist-boot/c-P4PQZVV5.mjs +948 -0
  131. package/dist-boot/c-P63T3XL2.mjs +26373 -0
  132. package/dist-boot/c-P6N5DQGZ.mjs +194 -0
  133. package/dist-boot/c-P7MLKQFC.mjs +58 -0
  134. package/dist-boot/c-PB3PZJL5.mjs +1276 -0
  135. package/dist-boot/c-PTN4S6G2.mjs +1259 -0
  136. package/dist-boot/c-PYCE5J7U.mjs +1083 -0
  137. package/dist-boot/c-Q4HYCRLB.mjs +19410 -0
  138. package/dist-boot/c-QUXMETGG.mjs +68 -0
  139. package/dist-boot/c-RDMJZCOX.mjs +356 -0
  140. package/dist-boot/c-ROGJK76M.mjs +17 -0
  141. package/dist-boot/c-RQJJ26T4.mjs +708 -0
  142. package/dist-boot/c-RSKCUPJF.mjs +7559 -0
  143. package/dist-boot/c-RVJU4O6P.mjs +37 -0
  144. package/dist-boot/c-S2RVHR3M.mjs +165 -0
  145. package/dist-boot/c-SKMK3PEE.mjs +91120 -0
  146. package/dist-boot/c-TI7SM4EG.mjs +20 -0
  147. package/dist-boot/c-TILJ6GXD.mjs +1235 -0
  148. package/dist-boot/c-TT6BCUJD.mjs +114 -0
  149. package/dist-boot/c-U4ITOXAN.mjs +2107 -0
  150. package/dist-boot/c-UGERXVO2.mjs +7120 -0
  151. package/dist-boot/c-UPBH5AXY.mjs +1363 -0
  152. package/dist-boot/c-US2PUNZL.mjs +597 -0
  153. package/dist-boot/c-UU4WZPPE.mjs +20 -0
  154. package/dist-boot/c-UWVIYPQS.mjs +39 -0
  155. package/dist-boot/c-V4RHQBPQ.mjs +17683 -0
  156. package/dist-boot/c-V5MRVK47.mjs +351 -0
  157. package/dist-boot/c-V6CL266R.mjs +1755 -0
  158. package/dist-boot/c-VJTMFKYE.mjs +14975 -0
  159. package/dist-boot/c-VJTRUKIB.mjs +773 -0
  160. package/dist-boot/c-W4IFSHPW.mjs +43 -0
  161. package/dist-boot/c-WETGB2CF.mjs +113 -0
  162. package/dist-boot/c-WO3QSZUU.mjs +1337 -0
  163. package/dist-boot/c-WQLH73TY.mjs +242 -0
  164. package/dist-boot/c-XL735JW5.mjs +500 -0
  165. package/dist-boot/c-Y7HADL5B.mjs +1107 -0
  166. package/dist-boot/c-YGQHSVSK.mjs +41 -0
  167. package/dist-boot/c-YMP2AMEB.mjs +10350 -0
  168. package/dist-boot/c-YRDO2WEF.mjs +12012 -0
  169. package/dist-boot/c-YUSTRATJ.mjs +8 -0
  170. package/dist-boot/c-Z2262R22.mjs +2697 -0
  171. package/dist-boot/c-Z4ALQMJC.mjs +709 -0
  172. package/dist-boot/c-Z5ZUQVUY.mjs +62 -0
  173. package/dist-boot/c-ZDZUKXF7.mjs +874 -0
  174. package/dist-boot/c-ZJYLGIC3.mjs +32 -0
  175. package/dist-boot/c-ZNA5CDMI.mjs +77 -0
  176. package/dist-boot/c-ZSO6DI3M.mjs +204 -0
  177. package/dist-boot/c-ZWUVHKMK.mjs +100 -0
  178. package/dist-boot/c-ZY4MESEW.mjs +832 -0
  179. package/dist-boot/c-ZZ5REI4L.mjs +329 -0
  180. package/dist-boot/cli.mjs +51 -0
  181. package/dist-boot/ext-anthropic-attribution.mjs +207 -0
  182. package/dist-boot/ext-pi-background-tasks.mjs +7234 -0
  183. package/dist-boot/ext-pi-subagents.mjs +37 -0
  184. package/dist-boot/ext-privateer-account.mjs +4426 -0
  185. package/dist-boot/ext-privateer-brand.mjs +5274 -0
  186. package/dist-boot/ext-privateer-codemode.mjs +37 -0
  187. package/dist-boot/ext-privateer-computer.mjs +626 -0
  188. package/dist-boot/ext-privateer-connect.mjs +1862 -0
  189. package/dist-boot/ext-privateer-context.mjs +323 -0
  190. package/dist-boot/ext-privateer-desktop.mjs +92 -0
  191. package/dist-boot/ext-privateer-final-audit.mjs +48 -0
  192. package/dist-boot/ext-privateer-fresh.mjs +81 -0
  193. package/dist-boot/ext-privateer-gate.mjs +5959 -0
  194. package/dist-boot/ext-privateer-hints.mjs +236 -0
  195. package/dist-boot/ext-privateer-media.mjs +2626 -0
  196. package/dist-boot/ext-privateer-models.mjs +3397 -0
  197. package/dist-boot/ext-privateer-posture.mjs +3006 -0
  198. package/dist-boot/ext-privateer-privacy.mjs +4578 -0
  199. package/dist-boot/ext-privateer-recovery.mjs +287 -0
  200. package/dist-boot/ext-privateer-speak.mjs +4754 -0
  201. package/dist-boot/ext-privateer-terminals.mjs +725 -0
  202. package/dist-boot/ext-privateer-tools.mjs +528 -0
  203. package/dist-boot/ext-privateer-truncation.mjs +74 -0
  204. package/dist-boot/ext-privateer-update.mjs +210 -0
  205. package/dist-boot/ext-privateer-vision.mjs +148 -0
  206. package/dist-boot/ext-privateer-web.mjs +543 -0
  207. package/dist-boot/ext-rpiv-ask-user-question.mjs +710 -0
  208. package/dist-boot/manifest.json +9 -0
  209. package/extensions/privateer-brand.ts +3 -1
  210. package/extensions/privateer-context.ts +4 -2
  211. package/extensions/privateer-final-audit.ts +17 -0
  212. package/extensions/privateer-gate.ts +55 -9
  213. package/extensions/privateer-recovery.ts +175 -0
  214. package/extensions/privateer-web.ts +4 -4
  215. package/package.json +3 -1
  216. package/patches/@earendil-works+pi-coding-agent+1.3.0.patch +199 -2
  217. package/patches/pi-background-tasks+2.6.10.patch +91 -7
  218. package/src/cli/chat.ts +7 -1
  219. package/src/config/moatManifest.json +2 -0
  220. package/src/config/whatsNew.json +4 -4
  221. package/src/context.ts +33 -5
  222. package/src/engine/finalAudit.ts +38 -0
  223. package/src/engine/stallWatchdog.ts +8 -1
  224. package/src/providers/account.ts +34 -3
  225. package/src/remote/attentionPush.ts +40 -0
  226. package/src/remote/liveTaskSession.ts +7 -1
  227. package/src/remote/relayClient.ts +38 -4
  228. package/src/remote/remoteBridge.ts +17 -0
  229. package/src/remote/transcriptSnapshot.ts +104 -0
@@ -0,0 +1,765 @@
1
+ import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
2
+ import {
3
+ DEFAULT_MAX_BYTES
4
+ } from "./c-7UOG7POX.mjs";
5
+ import {
6
+ __name
7
+ } from "./c-CN77DCGF.mjs";
8
+
9
+ // node_modules/pi-background-tasks/src/core/common.ts?ext=pi-background-tasks
10
+ import { accessSync, constants, statSync } from "node:fs";
11
+ import { open } from "node:fs/promises";
12
+ import { basename, delimiter, extname, isAbsolute, join, resolve, win32 } from "node:path";
13
+ var ReloadSurvivalError = class extends Error {
14
+ constructor(code, message) {
15
+ super(`${code}: ${message}`);
16
+ this.code = code;
17
+ this.name = "ReloadSurvivalError";
18
+ }
19
+ code;
20
+ static {
21
+ __name(this, "ReloadSurvivalError");
22
+ }
23
+ };
24
+ function rejectSurvivalForTaskKind(value, kind) {
25
+ if (!Object.prototype.hasOwnProperty.call(value, "surviveReload")) return;
26
+ throw new ReloadSurvivalError(
27
+ "pi_bg_survive_reload_unsupported_task_kind",
28
+ `${kind} does not support surviveReload; only ordinary isAgent:false shell tasks may survive reload`
29
+ );
30
+ }
31
+ __name(rejectSurvivalForTaskKind, "rejectSurvivalForTaskKind");
32
+ function deriveCompletionDeliveryGuidance(notifyOnCompletion, triggerOnCompletion) {
33
+ if (notifyOnCompletion && triggerOnCompletion) {
34
+ return {
35
+ mode: "notification-and-wake",
36
+ notificationEnabled: true,
37
+ automaticWakeEnabled: true,
38
+ text: [
39
+ "Terminal notification: enabled.",
40
+ "Automatic follow-up turn: enabled.",
41
+ "Next action: do not poll or sleep merely to wait; continue only independent useful work, otherwise end this turn and wait for <background-task-notification>."
42
+ ].join("\n")
43
+ };
44
+ }
45
+ if (notifyOnCompletion) {
46
+ return {
47
+ mode: "notification-only",
48
+ notificationEnabled: true,
49
+ automaticWakeEnabled: false,
50
+ text: [
51
+ "Terminal notification: enabled.",
52
+ "Automatic follow-up turn: disabled. The terminal notification will be delivered, but it will not start an agent turn.",
53
+ "Next action: automatic wake-up was explicitly disabled; use bg_status/bg_logs only when deliberate monitoring is required, without tight polling."
54
+ ].join("\n")
55
+ };
56
+ }
57
+ return {
58
+ mode: "manual-monitoring",
59
+ notificationEnabled: false,
60
+ automaticWakeEnabled: false,
61
+ text: [
62
+ "Terminal notification: disabled.",
63
+ triggerOnCompletion ? "Automatic follow-up turn: disabled because terminal notifications are disabled. triggerOnCompletion has no effect while notifyOnCompletion is false." : "Automatic follow-up turn: disabled.",
64
+ "Next action: completion delivery was explicitly disabled; use bg_status/bg_logs only for deliberate manual monitoring, without tight polling."
65
+ ].join("\n")
66
+ };
67
+ }
68
+ __name(deriveCompletionDeliveryGuidance, "deriveCompletionDeliveryGuidance");
69
+ var DEFAULT_LOG_BYTES = Math.min(DEFAULT_MAX_BYTES, 50 * 1024);
70
+ var MAX_LOG_BYTES = Math.min(DEFAULT_MAX_BYTES, 50 * 1024);
71
+ var COMMAND_PREVIEW_CHARS = 90;
72
+ var parseJsonValue = globalThis.JSON.parse;
73
+ function isJsonObject(value) {
74
+ return typeof value === "object" && value !== null;
75
+ }
76
+ __name(isJsonObject, "isJsonObject");
77
+ function parseJsonText(text) {
78
+ return parseJsonValue(text);
79
+ }
80
+ __name(parseJsonText, "parseJsonText");
81
+ function sanitizePathSegment(value) {
82
+ const sanitized = value.replace(/[^a-zA-Z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "");
83
+ return sanitized || "session";
84
+ }
85
+ __name(sanitizePathSegment, "sanitizePathSegment");
86
+ function stripMatchingQuotes(value) {
87
+ const trimmed = value.trim();
88
+ if (trimmed.length >= 2) {
89
+ const first = trimmed[0];
90
+ const last = trimmed[trimmed.length - 1];
91
+ if (first === '"' && last === '"' || first === "'" && last === "'") {
92
+ return trimmed.slice(1, -1);
93
+ }
94
+ }
95
+ return trimmed;
96
+ }
97
+ __name(stripMatchingQuotes, "stripMatchingQuotes");
98
+ function compactWhitespace(value) {
99
+ return value.replace(/\s+/g, " ").trim();
100
+ }
101
+ __name(compactWhitespace, "compactWhitespace");
102
+ function truncateChars(value, maxChars) {
103
+ if (value.length <= maxChars) return value;
104
+ return `${value.slice(0, Math.max(0, maxChars - 1))}\u2026`;
105
+ }
106
+ __name(truncateChars, "truncateChars");
107
+ function normalizeTaskName(value) {
108
+ if (typeof value !== "string") return void 0;
109
+ const normalized = compactWhitespace(stripMatchingQuotes(value));
110
+ if (!normalized) return void 0;
111
+ return truncateChars(normalized, 80);
112
+ }
113
+ __name(normalizeTaskName, "normalizeTaskName");
114
+ function deriveTaskNameFromCommand(command) {
115
+ const normalized = compactWhitespace(stripMatchingQuotes(command));
116
+ if (!normalized) return "Background task";
117
+ const packageScript = /^(npm|pnpm|yarn|bun)\s+(?:(run)\s+)?([^\s;&|]+)/.exec(normalized);
118
+ if (packageScript) {
119
+ const runner = packageScript[1] ?? "npm";
120
+ const run = packageScript[2] !== void 0 ? " run" : "";
121
+ const script = packageScript[3] ?? "";
122
+ return truncateChars(`${runner}${run} ${script}`, 48);
123
+ }
124
+ const words = normalized.split(/\s+/).slice(0, 5).join(" ");
125
+ return truncateChars(words.length > 0 ? words : normalized, 48);
126
+ }
127
+ __name(deriveTaskNameFromCommand, "deriveTaskNameFromCommand");
128
+ function taskDisplayName(task) {
129
+ const commandName = task.command && task.command.length > 0 ? deriveTaskNameFromCommand(task.command) : void 0;
130
+ return normalizeTaskName(task.name) ?? normalizeTaskName(task.description) ?? commandName ?? task.id ?? "Background task";
131
+ }
132
+ __name(taskDisplayName, "taskDisplayName");
133
+ function parseNameValueAndRest(valueAndRest) {
134
+ const input = valueAndRest.trimStart();
135
+ if (!input) return void 0;
136
+ const quote = input[0];
137
+ if (quote === '"' || quote === "'") {
138
+ let escaped = false;
139
+ let value = "";
140
+ for (let i = 1; i < input.length; i++) {
141
+ const char = input.charAt(i);
142
+ if (escaped) {
143
+ value += char;
144
+ escaped = false;
145
+ continue;
146
+ }
147
+ if (char === "\\") {
148
+ escaped = true;
149
+ continue;
150
+ }
151
+ if (char === quote) {
152
+ return { value, rest: input.slice(i + 1).trimStart() };
153
+ }
154
+ value += char;
155
+ }
156
+ return void 0;
157
+ }
158
+ const match = /^(\S+)(?:\s+([\s\S]*))?$/.exec(input);
159
+ if (!match) return void 0;
160
+ const parsedValue = match[1];
161
+ if (parsedValue === void 0) return void 0;
162
+ return { value: parsedValue, rest: match[2]?.trimStart() ?? "" };
163
+ }
164
+ __name(parseNameValueAndRest, "parseNameValueAndRest");
165
+ function parseBgCommandArgs(args) {
166
+ let input = args.trim();
167
+ let name;
168
+ let isAgent = false;
169
+ let surviveReload = false;
170
+ while (input) {
171
+ let consumed = false;
172
+ for (const prefix of ["--name=", "-n="]) {
173
+ if (input.startsWith(prefix)) {
174
+ const parsed = parseNameValueAndRest(input.slice(prefix.length));
175
+ if (!parsed) throw new Error(`${prefix.slice(0, -1)} requires a task name`);
176
+ name = normalizeTaskName(parsed.value);
177
+ input = parsed.rest;
178
+ consumed = true;
179
+ break;
180
+ }
181
+ }
182
+ if (consumed) continue;
183
+ for (const prefix of ["--name", "-n"]) {
184
+ if (input === prefix || input.startsWith(`${prefix} `) || input.startsWith(`${prefix} `)) {
185
+ const parsed = parseNameValueAndRest(input.slice(prefix.length));
186
+ if (!parsed) throw new Error(`${prefix} requires a task name`);
187
+ name = normalizeTaskName(parsed.value);
188
+ input = parsed.rest;
189
+ consumed = true;
190
+ break;
191
+ }
192
+ }
193
+ if (consumed) continue;
194
+ for (const flag of ["--agent", "--llm-agent"]) {
195
+ if (input === flag || input.startsWith(`${flag} `) || input.startsWith(`${flag} `)) {
196
+ isAgent = true;
197
+ input = input.slice(flag.length).trimStart();
198
+ consumed = true;
199
+ break;
200
+ }
201
+ }
202
+ if (consumed) continue;
203
+ for (const flag of ["--script", "--no-agent"]) {
204
+ if (input === flag || input.startsWith(`${flag} `) || input.startsWith(`${flag} `)) {
205
+ isAgent = false;
206
+ input = input.slice(flag.length).trimStart();
207
+ consumed = true;
208
+ break;
209
+ }
210
+ }
211
+ if (consumed) continue;
212
+ if (input === "--survive-reload" || input.startsWith("--survive-reload ") || input.startsWith("--survive-reload ")) {
213
+ if (surviveReload) {
214
+ throw new ReloadSurvivalError(
215
+ "pi_bg_survive_reload_invalid",
216
+ "/bg accepts --survive-reload at most once"
217
+ );
218
+ }
219
+ surviveReload = true;
220
+ input = input.slice("--survive-reload".length).trimStart();
221
+ continue;
222
+ }
223
+ if (input.startsWith("--survive-reload=")) {
224
+ throw new ReloadSurvivalError(
225
+ "pi_bg_survive_reload_invalid",
226
+ "/bg accepts only the bare --survive-reload flag"
227
+ );
228
+ }
229
+ if (input === "--") {
230
+ input = "";
231
+ break;
232
+ }
233
+ if (input.startsWith("-- ")) {
234
+ input = input.slice(3).trimStart();
235
+ break;
236
+ }
237
+ break;
238
+ }
239
+ if (surviveReload && isAgent) {
240
+ throw new ReloadSurvivalError(
241
+ "pi_bg_survive_reload_requires_non_agent",
242
+ "surviveReload requires isAgent:false"
243
+ );
244
+ }
245
+ return name ? { name, command: input, isAgent, surviveReload } : { command: input, isAgent, surviveReload };
246
+ }
247
+ __name(parseBgCommandArgs, "parseBgCommandArgs");
248
+ function formatDuration(ms) {
249
+ if (ms < 1e3) return `${String(ms)}ms`;
250
+ const seconds = Math.floor(ms / 1e3);
251
+ if (seconds < 60) return `${String(seconds)}s`;
252
+ const minutes = Math.floor(seconds / 60);
253
+ const remSeconds = seconds % 60;
254
+ if (minutes < 60) return `${String(minutes)}m${remSeconds > 0 ? `${String(remSeconds)}s` : ""}`;
255
+ const hours = Math.floor(minutes / 60);
256
+ const remMinutes = minutes % 60;
257
+ return `${String(hours)}h${remMinutes > 0 ? `${String(remMinutes)}m` : ""}`;
258
+ }
259
+ __name(formatDuration, "formatDuration");
260
+ function formatCompactNumber(count) {
261
+ const normalized = Math.max(0, Math.floor(count));
262
+ if (normalized < 1e3) return normalized.toString();
263
+ if (normalized < 1e4) return `${(normalized / 1e3).toFixed(1)}k`;
264
+ if (normalized < 1e6) return `${String(Math.round(normalized / 1e3))}k`;
265
+ if (normalized < 1e7) return `${(normalized / 1e6).toFixed(1)}M`;
266
+ return `${String(Math.round(normalized / 1e6))}M`;
267
+ }
268
+ __name(formatCompactNumber, "formatCompactNumber");
269
+ function formatContextUsageSummary(usage) {
270
+ if (usage?.contextWindow === void 0 || usage.contextWindow <= 0) return void 0;
271
+ const window = formatCompactNumber(usage.contextWindow);
272
+ if (usage.percent === null || usage.tokens === null) return `ctx=?/${window}`;
273
+ return `ctx=${usage.percent.toFixed(1)}%/${window}`;
274
+ }
275
+ __name(formatContextUsageSummary, "formatContextUsageSummary");
276
+ function formatTokenUsageSummary(usage) {
277
+ if (!usage || usage.totalTokens <= 0) return void 0;
278
+ return `tokens=${formatCompactNumber(usage.totalTokens)}`;
279
+ }
280
+ __name(formatTokenUsageSummary, "formatTokenUsageSummary");
281
+ function formatToolUsageSummary(usage) {
282
+ if (!usage || usage.total <= 0 && usage.failed <= 0) return void 0;
283
+ const failed = usage.failed > 0 ? ` failed=${String(usage.failed)}` : "";
284
+ return `tools=${String(usage.total)}${failed}`;
285
+ }
286
+ __name(formatToolUsageSummary, "formatToolUsageSummary");
287
+ function formatModelSummary(model) {
288
+ if (!model) return void 0;
289
+ return `model=${model}`;
290
+ }
291
+ __name(formatModelSummary, "formatModelSummary");
292
+ var AGENT_ACTIVITY_TYPE = "background-task-activity";
293
+ var AGENT_ACTIVITY_DETAIL_MAX = 80;
294
+ function readActivityString(record, key) {
295
+ const value = record[key];
296
+ return typeof value === "string" ? value : void 0;
297
+ }
298
+ __name(readActivityString, "readActivityString");
299
+ function parseAgentActivity(payload) {
300
+ if (!isJsonObject(payload)) return void 0;
301
+ const record = payload;
302
+ if (record.type !== AGENT_ACTIVITY_TYPE) return void 0;
303
+ const kind = record.kind;
304
+ if (kind === "assistant_text" || kind === "reasoning") {
305
+ const text = readActivityString(record, "text");
306
+ if (text === void 0) return void 0;
307
+ return { kind, text };
308
+ }
309
+ if (kind === "tool_start") {
310
+ const tool = readActivityString(record, "tool");
311
+ if (!tool) return void 0;
312
+ return { kind, tool, argsSummary: readActivityString(record, "argsSummary") ?? "" };
313
+ }
314
+ if (kind === "tool_end") {
315
+ const tool = readActivityString(record, "tool");
316
+ if (!tool) return void 0;
317
+ const activity = { kind, tool, isError: record.isError === true };
318
+ const error = readActivityString(record, "error");
319
+ if (error !== void 0 && error.trim().length > 0) activity.error = error;
320
+ return activity;
321
+ }
322
+ return void 0;
323
+ }
324
+ __name(parseAgentActivity, "parseAgentActivity");
325
+ function formatAgentActivityLine(activity) {
326
+ if (activity.kind === "assistant_text") {
327
+ const text = activity.text.replace(/\s+$/u, "");
328
+ return text.trim().length > 0 ? text : void 0;
329
+ }
330
+ if (activity.kind === "reasoning") {
331
+ const text = activity.text.replace(/\s+$/u, "");
332
+ return text.trim().length > 0 ? `\u2026 ${text}` : void 0;
333
+ }
334
+ if (activity.kind === "tool_start") {
335
+ const summary = compactWhitespace(activity.argsSummary);
336
+ const suffix = summary.length > 0 ? ` ${truncateChars(summary, AGENT_ACTIVITY_DETAIL_MAX)}` : "";
337
+ return `\u2192 ${activity.tool}${suffix}`;
338
+ }
339
+ if (!activity.isError) return void 0;
340
+ const detail = activity.error ? `: ${truncateChars(compactWhitespace(activity.error), AGENT_ACTIVITY_DETAIL_MAX)}` : "";
341
+ return `\u2717 ${activity.tool} failed${detail}`;
342
+ }
343
+ __name(formatAgentActivityLine, "formatAgentActivityLine");
344
+ function shellQuote(value) {
345
+ return `'${value.replace(/'/g, `'"'"'`)}'`;
346
+ }
347
+ __name(shellQuote, "shellQuote");
348
+ var ShellInvocationError = class extends Error {
349
+ static {
350
+ __name(this, "ShellInvocationError");
351
+ }
352
+ code = "pi_bg_shell_invalid";
353
+ constructor(message) {
354
+ super(`pi_bg_shell_invalid: ${message}`);
355
+ this.name = "ShellInvocationError";
356
+ }
357
+ };
358
+ var POSIX_FUNCTION_SHELLS = /* @__PURE__ */ new Set([
359
+ "sh",
360
+ "dash",
361
+ "ash",
362
+ "ksh",
363
+ "ksh93",
364
+ "mksh",
365
+ "pdksh",
366
+ "zsh",
367
+ "yash",
368
+ "posh"
369
+ ]);
370
+ function failShellInvocation(message) {
371
+ throw new ShellInvocationError(message);
372
+ }
373
+ __name(failShellInvocation, "failShellInvocation");
374
+ function shellErrorMessage(error) {
375
+ return error instanceof Error ? error.message : String(error);
376
+ }
377
+ __name(shellErrorMessage, "shellErrorMessage");
378
+ function freezeShellPolicy(policy) {
379
+ return Object.freeze({
380
+ ...policy,
381
+ argvPrefix: Object.freeze([...policy.argvPrefix])
382
+ });
383
+ }
384
+ __name(freezeShellPolicy, "freezeShellPolicy");
385
+ function shellPolicySnapshot(policy) {
386
+ return Object.freeze({
387
+ policy: policy.policy,
388
+ executable: policy.executable,
389
+ argvPrefix: Object.freeze([...policy.argvPrefix]),
390
+ dialect: policy.dialect
391
+ });
392
+ }
393
+ __name(shellPolicySnapshot, "shellPolicySnapshot");
394
+ function isWindowsExecutablePath(path) {
395
+ const extension = extname(path).toLowerCase();
396
+ return extension === ".exe" || extension === ".com";
397
+ }
398
+ __name(isWindowsExecutablePath, "isWindowsExecutablePath");
399
+ function validateWindowsShellPath(path, label) {
400
+ if (path.length === 0) failShellInvocation(`${label} is empty`);
401
+ if (!isAbsolute(path) && !win32.isAbsolute(path)) {
402
+ failShellInvocation(`${label} must be an absolute path`);
403
+ }
404
+ if (!isWindowsExecutablePath(path)) {
405
+ failShellInvocation(`${label} must point to a .exe or .com file`);
406
+ }
407
+ let stats;
408
+ try {
409
+ stats = statSync(path);
410
+ } catch (error) {
411
+ failShellInvocation(`${label} stat failed: ${shellErrorMessage(error)}`);
412
+ }
413
+ if (!stats.isFile()) failShellInvocation(`${label} must point to a regular file`);
414
+ return path;
415
+ }
416
+ __name(validateWindowsShellPath, "validateWindowsShellPath");
417
+ function inspectWindowsShellCandidate(path) {
418
+ if (!isWindowsExecutablePath(path)) {
419
+ return { found: false, diagnostic: `${path} is not a .exe or .com path` };
420
+ }
421
+ try {
422
+ const stats = statSync(path);
423
+ if (stats.isFile()) return { found: true };
424
+ return { found: false, diagnostic: `${path} is not a regular file` };
425
+ } catch (error) {
426
+ return { found: false, diagnostic: `${path}: ${shellErrorMessage(error)}` };
427
+ }
428
+ }
429
+ __name(inspectWindowsShellCandidate, "inspectWindowsShellCandidate");
430
+ function windowsPathValue(env) {
431
+ return env["PATH"] ?? env["Path"] ?? env["path"] ?? "";
432
+ }
433
+ __name(windowsPathValue, "windowsPathValue");
434
+ function resolveWindowsBash(env) {
435
+ const pathValue = windowsPathValue(env);
436
+ const diagnostics = [];
437
+ for (const dir of pathValue.split(";").filter((entry) => entry.length > 0)) {
438
+ for (const name of ["bash.exe", "bash.com"]) {
439
+ const candidate = join(dir, name);
440
+ const result = inspectWindowsShellCandidate(candidate);
441
+ if (result.found) return candidate;
442
+ diagnostics.push(result.diagnostic);
443
+ }
444
+ }
445
+ const suffix = diagnostics.length > 0 ? `: ${diagnostics.join("; ")}` : "";
446
+ failShellInvocation(`PI_BG_SHELL=bash could not resolve bash.exe or bash.com on PATH${suffix}`);
447
+ }
448
+ __name(resolveWindowsBash, "resolveWindowsBash");
449
+ function validatePosixShellPath(path, label) {
450
+ if (path.length === 0) failShellInvocation(`${label} is empty`);
451
+ if (!isAbsolute(path)) failShellInvocation(`${label} must be an absolute path`);
452
+ let stats;
453
+ try {
454
+ stats = statSync(path);
455
+ } catch (error) {
456
+ failShellInvocation(`${label} stat failed: ${shellErrorMessage(error)}`);
457
+ }
458
+ if (!stats.isFile()) failShellInvocation(`${label} must point to a regular file`);
459
+ try {
460
+ accessSync(path, constants.X_OK);
461
+ } catch (error) {
462
+ failShellInvocation(`${label} must be executable: ${shellErrorMessage(error)}`);
463
+ }
464
+ return path;
465
+ }
466
+ __name(validatePosixShellPath, "validatePosixShellPath");
467
+ function inspectPosixShellCandidate(path) {
468
+ try {
469
+ const stats = statSync(path);
470
+ if (!stats.isFile()) return false;
471
+ accessSync(path, constants.X_OK);
472
+ return true;
473
+ } catch {
474
+ return false;
475
+ }
476
+ }
477
+ __name(inspectPosixShellCandidate, "inspectPosixShellCandidate");
478
+ function resolvePosixExecutable(name, env, activationCwd) {
479
+ const binCandidate = `/bin/${name}`;
480
+ if (inspectPosixShellCandidate(binCandidate)) return binCandidate;
481
+ const pathValue = env["PATH"] ?? "";
482
+ for (const entry of pathValue.split(delimiter)) {
483
+ if (entry.length === 0) continue;
484
+ const directory = isAbsolute(entry) ? entry : resolve(activationCwd, entry);
485
+ const candidate = join(directory, name);
486
+ if (inspectPosixShellCandidate(candidate)) return candidate;
487
+ }
488
+ failShellInvocation(
489
+ `PI_BG_POSIX_SHELL=${name} could not resolve executable ${binCandidate} or ${name} on PATH`
490
+ );
491
+ }
492
+ __name(resolvePosixExecutable, "resolvePosixExecutable");
493
+ function inheritedPosixDialect(executable) {
494
+ const name = basename(executable).toLowerCase();
495
+ if (name === "bash") return "bash";
496
+ return POSIX_FUNCTION_SHELLS.has(name) ? "posix" : "user-non-posix";
497
+ }
498
+ __name(inheritedPosixDialect, "inheritedPosixDialect");
499
+ function resolveShellPolicy(platform = process.platform, env = process.env, activationCwd = process.cwd()) {
500
+ if (platform === "win32") {
501
+ const requestedShell = env["PI_BG_SHELL"];
502
+ const requestedPath = env["PI_BG_SHELL_PATH"];
503
+ if (requestedShell === void 0) {
504
+ if (requestedPath !== void 0)
505
+ failShellInvocation("PI_BG_SHELL_PATH requires PI_BG_SHELL");
506
+ const comSpec = env["ComSpec"];
507
+ return freezeShellPolicy({
508
+ policy: "cmd",
509
+ executable: comSpec && comSpec.length > 0 ? comSpec : "cmd.exe",
510
+ argvPrefix: ["/d", "/s", "/c"],
511
+ dialect: "cmd",
512
+ supportsPosixFunctionWrapper: false,
513
+ windowsVerbatimArguments: true
514
+ });
515
+ }
516
+ if (requestedShell !== "cmd" && requestedShell !== "bash") {
517
+ failShellInvocation("PI_BG_SHELL must be exactly cmd or bash");
518
+ }
519
+ const explicitPath = requestedPath !== void 0 ? validateWindowsShellPath(requestedPath, "PI_BG_SHELL_PATH") : void 0;
520
+ if (requestedShell === "cmd") {
521
+ const comSpec = env["ComSpec"];
522
+ return freezeShellPolicy({
523
+ policy: "cmd",
524
+ executable: explicitPath ?? (comSpec && comSpec.length > 0 ? comSpec : "cmd.exe"),
525
+ argvPrefix: ["/d", "/s", "/c"],
526
+ dialect: "cmd",
527
+ supportsPosixFunctionWrapper: false,
528
+ windowsVerbatimArguments: true
529
+ });
530
+ }
531
+ return freezeShellPolicy({
532
+ policy: "bash",
533
+ executable: explicitPath ?? resolveWindowsBash(env),
534
+ argvPrefix: ["-c"],
535
+ dialect: "bash",
536
+ supportsPosixFunctionWrapper: true,
537
+ windowsVerbatimArguments: false
538
+ });
539
+ }
540
+ const configuredPolicy = env["PI_BG_POSIX_SHELL"];
541
+ if (configuredPolicy !== void 0 && configuredPolicy !== "inherit" && configuredPolicy !== "bash" && configuredPolicy !== "sh") {
542
+ failShellInvocation("PI_BG_POSIX_SHELL must be exactly inherit, bash, or sh");
543
+ }
544
+ const policy = configuredPolicy ?? "inherit";
545
+ const configuredPath = env["PI_BG_POSIX_SHELL_PATH"];
546
+ if (policy === "inherit") {
547
+ if (configuredPath !== void 0) {
548
+ failShellInvocation(
549
+ "PI_BG_POSIX_SHELL_PATH requires PI_BG_POSIX_SHELL=bash or PI_BG_POSIX_SHELL=sh"
550
+ );
551
+ }
552
+ const inherited = env["SHELL"];
553
+ const executable2 = inherited && inherited.length > 0 ? inherited : "/bin/sh";
554
+ const dialect = inheritedPosixDialect(executable2);
555
+ return freezeShellPolicy({
556
+ policy,
557
+ executable: executable2,
558
+ argvPrefix: ["-c"],
559
+ dialect,
560
+ supportsPosixFunctionWrapper: dialect === "bash" || dialect === "posix",
561
+ windowsVerbatimArguments: false
562
+ });
563
+ }
564
+ const executable = configuredPath !== void 0 ? validatePosixShellPath(configuredPath, "PI_BG_POSIX_SHELL_PATH") : resolvePosixExecutable(policy, env, activationCwd);
565
+ return freezeShellPolicy({
566
+ policy,
567
+ executable,
568
+ argvPrefix: ["-c"],
569
+ dialect: policy === "bash" ? "bash" : "posix",
570
+ supportsPosixFunctionWrapper: true,
571
+ windowsVerbatimArguments: false
572
+ });
573
+ }
574
+ __name(resolveShellPolicy, "resolveShellPolicy");
575
+ function shellInvocationForPolicy(command, policy) {
576
+ const dialect = policy.dialect === "bash" ? "posix" : policy.dialect;
577
+ return {
578
+ shell: policy.executable,
579
+ args: policy.dialect === "cmd" ? [...policy.argvPrefix, `"${command}"`] : [...policy.argvPrefix, command],
580
+ dialect,
581
+ windowsVerbatimArguments: policy.windowsVerbatimArguments
582
+ };
583
+ }
584
+ __name(shellInvocationForPolicy, "shellInvocationForPolicy");
585
+ function normalizeMaxBytes(value, fallback = DEFAULT_LOG_BYTES) {
586
+ const raw = typeof value === "number" && Number.isFinite(value) ? Math.floor(value) : fallback;
587
+ return Math.max(1, Math.min(MAX_LOG_BYTES, raw));
588
+ }
589
+ __name(normalizeMaxBytes, "normalizeMaxBytes");
590
+ function snapshot(task) {
591
+ return {
592
+ id: task.id,
593
+ name: taskDisplayName(task),
594
+ command: task.command,
595
+ description: task.description,
596
+ status: task.status,
597
+ outputPath: task.outputPath,
598
+ cwd: task.cwd,
599
+ startTime: task.startTime,
600
+ endTime: task.endTime,
601
+ exitCode: task.exitCode,
602
+ signal: task.signal,
603
+ pid: task.pid,
604
+ bytesWritten: task.bytesWritten,
605
+ isAgent: task.isAgent,
606
+ surviveReload: task.surviveReload === true,
607
+ reloadSurvival: task.reloadSurvival,
608
+ error: task.error,
609
+ notified: task.notified,
610
+ notifyOnCompletion: task.notifyOnCompletion,
611
+ triggerOnCompletion: task.triggerOnCompletion,
612
+ timeoutSeconds: task.timeoutSeconds,
613
+ contextUsage: task.contextUsage,
614
+ tokenUsage: task.tokenUsage,
615
+ toolUsage: task.toolUsage,
616
+ model: task.model,
617
+ telemetryUnavailableReason: task.telemetryUnavailableReason,
618
+ shellPolicy: task.shellPolicy,
619
+ attestationPath: task.attestationPath,
620
+ delegate: task.delegate,
621
+ fusion: task.fusion
622
+ };
623
+ }
624
+ __name(snapshot, "snapshot");
625
+ function formatSnapshotList(tasks, now = Date.now()) {
626
+ if (tasks.length === 0) return "No background tasks in this Pi extension runtime.";
627
+ return tasks.map((task) => {
628
+ const statusIcon = task.status === "running" ? "\u25B6" : task.status === "completed" ? "\u2713" : task.status === "killed" ? "\u25A0" : "\u2717";
629
+ const age = formatDuration((task.endTime ?? now) - task.startTime);
630
+ const code = task.exitCode !== void 0 ? ` exit=${String(task.exitCode)}` : "";
631
+ const pid = task.pid !== void 0 ? ` pid=${String(task.pid)}` : "";
632
+ const error = task.error ? ` error=${truncateChars(task.error, 80)}` : "";
633
+ const telemetry = [
634
+ formatContextUsageSummary(task.contextUsage),
635
+ formatModelSummary(task.model),
636
+ formatTokenUsageSummary(task.tokenUsage),
637
+ formatToolUsageSummary(task.toolUsage)
638
+ ].filter(Boolean).join(" ");
639
+ const telemetryText = telemetry ? ` ${telemetry}` : "";
640
+ return `${statusIcon} ${task.id} ${task.status} ${age}${code}${pid}${telemetryText} \u2014 ${truncateChars(taskDisplayName(task), COMMAND_PREVIEW_CHARS)}${error}
641
+ output: ${task.outputPath}`;
642
+ }).join("\n");
643
+ }
644
+ __name(formatSnapshotList, "formatSnapshotList");
645
+ async function boundedRead(filePath, maxBytes, tail) {
646
+ const stats = statSync(filePath);
647
+ const totalBytes = stats.size;
648
+ const bytesToRead = Math.min(totalBytes, maxBytes);
649
+ if (bytesToRead === 0) return { content: "", truncated: false, bytesRead: 0, totalBytes };
650
+ const file = await open(filePath, "r");
651
+ try {
652
+ const buffer = Buffer.alloc(bytesToRead);
653
+ const position = tail ? Math.max(0, totalBytes - bytesToRead) : 0;
654
+ const { bytesRead } = await file.read(buffer, 0, bytesToRead, position);
655
+ return {
656
+ content: buffer.subarray(0, bytesRead).toString("utf8"),
657
+ truncated: totalBytes > bytesRead,
658
+ bytesRead,
659
+ totalBytes
660
+ };
661
+ } finally {
662
+ await file.close();
663
+ }
664
+ }
665
+ __name(boundedRead, "boundedRead");
666
+ function escapeXml(value) {
667
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
668
+ }
669
+ __name(escapeXml, "escapeXml");
670
+ var UPDATE_COMMAND = "/bg-update";
671
+ var SEMVER_PATTERN = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
672
+ function parseSemver(value) {
673
+ if (typeof value !== "string") return void 0;
674
+ const match = SEMVER_PATTERN.exec(value.trim());
675
+ if (!match) return void 0;
676
+ const majorRaw = match[1];
677
+ const minorRaw = match[2];
678
+ const patchRaw = match[3];
679
+ if (majorRaw === void 0 || minorRaw === void 0 || patchRaw === void 0) return void 0;
680
+ const major = Number(majorRaw);
681
+ const minor = Number(minorRaw);
682
+ const patch = Number(patchRaw);
683
+ if (!Number.isInteger(major) || !Number.isInteger(minor) || !Number.isInteger(patch))
684
+ return void 0;
685
+ const prerelease = match[4] !== void 0 ? match[4].split(".") : [];
686
+ return { major, minor, patch, prerelease };
687
+ }
688
+ __name(parseSemver, "parseSemver");
689
+ function comparePrerelease(a, b) {
690
+ if (a.length === 0 && b.length === 0) return 0;
691
+ if (a.length === 0) return 1;
692
+ if (b.length === 0) return -1;
693
+ const shared = Math.min(a.length, b.length);
694
+ for (let i = 0; i < shared; i++) {
695
+ const idA = a[i];
696
+ const idB = b[i];
697
+ if (idA === void 0 || idB === void 0) break;
698
+ if (idA === idB) continue;
699
+ const numericA = /^\d+$/.test(idA);
700
+ const numericB = /^\d+$/.test(idB);
701
+ if (numericA && numericB) {
702
+ const diff = Number(idA) - Number(idB);
703
+ if (diff !== 0) return diff < 0 ? -1 : 1;
704
+ continue;
705
+ }
706
+ if (numericA) return -1;
707
+ if (numericB) return 1;
708
+ return idA < idB ? -1 : 1;
709
+ }
710
+ if (a.length === b.length) return 0;
711
+ return a.length < b.length ? -1 : 1;
712
+ }
713
+ __name(comparePrerelease, "comparePrerelease");
714
+ function compareSemver(a, b) {
715
+ const left = parseSemver(a);
716
+ const right = parseSemver(b);
717
+ if (!left || !right) return void 0;
718
+ if (left.major !== right.major) return left.major < right.major ? -1 : 1;
719
+ if (left.minor !== right.minor) return left.minor < right.minor ? -1 : 1;
720
+ if (left.patch !== right.patch) return left.patch < right.patch ? -1 : 1;
721
+ return comparePrerelease(left.prerelease, right.prerelease);
722
+ }
723
+ __name(compareSemver, "compareSemver");
724
+ function isNewerVersion(latest, current) {
725
+ return compareSemver(latest, current) === 1;
726
+ }
727
+ __name(isNewerVersion, "isNewerVersion");
728
+ function formatUpdateSegment(latest, current) {
729
+ if (!latest) return void 0;
730
+ if (!isNewerVersion(latest, current)) return void 0;
731
+ return `\u2B06 v${latest} ${UPDATE_COMMAND}`;
732
+ }
733
+ __name(formatUpdateSegment, "formatUpdateSegment");
734
+
735
+ export {
736
+ ReloadSurvivalError,
737
+ rejectSurvivalForTaskKind,
738
+ deriveCompletionDeliveryGuidance,
739
+ DEFAULT_LOG_BYTES,
740
+ MAX_LOG_BYTES,
741
+ isJsonObject,
742
+ parseJsonText,
743
+ sanitizePathSegment,
744
+ compactWhitespace,
745
+ truncateChars,
746
+ normalizeTaskName,
747
+ deriveTaskNameFromCommand,
748
+ taskDisplayName,
749
+ parseBgCommandArgs,
750
+ formatDuration,
751
+ formatCompactNumber,
752
+ parseAgentActivity,
753
+ formatAgentActivityLine,
754
+ shellQuote,
755
+ shellPolicySnapshot,
756
+ resolveShellPolicy,
757
+ shellInvocationForPolicy,
758
+ normalizeMaxBytes,
759
+ snapshot,
760
+ formatSnapshotList,
761
+ boundedRead,
762
+ escapeXml,
763
+ isNewerVersion,
764
+ formatUpdateSegment
765
+ };