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,478 @@
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
+ __name
4
+ } from "./c-CN77DCGF.mjs";
5
+
6
+ // node_modules/pi-background-tasks/src/core/pi-launch.ts?ext=pi-background-tasks
7
+ import { accessSync, constants, readFileSync, realpathSync, statSync } from "node:fs";
8
+ import { createRequire } from "node:module";
9
+ import {
10
+ basename,
11
+ delimiter,
12
+ dirname,
13
+ extname,
14
+ isAbsolute,
15
+ join,
16
+ relative,
17
+ resolve,
18
+ sep,
19
+ win32 as win32Path
20
+ } from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+ var __pvMetaUrl = __pvUrl("../node_modules/pi-background-tasks/src/core/pi-launch.ts");
23
+ var PiLaunchResolutionError = class extends Error {
24
+ static {
25
+ __name(this, "PiLaunchResolutionError");
26
+ }
27
+ code = "pi_executable_resolution_failed";
28
+ constructor(message) {
29
+ super(`pi_executable_resolution_failed: ${message}`);
30
+ this.name = "PiLaunchResolutionError";
31
+ }
32
+ };
33
+ var PiCommandLineLimitError = class extends Error {
34
+ static {
35
+ __name(this, "PiCommandLineLimitError");
36
+ }
37
+ code = "pi_command_line_too_long";
38
+ stage;
39
+ measuredLength;
40
+ limit;
41
+ constructor(stage, measuredLength, limit) {
42
+ super(
43
+ `pi_command_line_too_long: ${stage} measured UTF-16 command line length ${String(measuredLength)} exceeds limit ${String(limit)}`
44
+ );
45
+ this.name = "PiCommandLineLimitError";
46
+ this.stage = stage;
47
+ this.measuredLength = measuredLength;
48
+ this.limit = limit;
49
+ }
50
+ };
51
+ var PI_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
52
+ var PI_PACKAGE_MANIFEST = `${PI_PACKAGE_NAME}/package.json`;
53
+ var WINDOWS_COMMAND_LINE_LIMIT = 32767;
54
+ var JAVASCRIPT_EXTENSIONS = /* @__PURE__ */ new Set([".js", ".cjs", ".mjs"]);
55
+ var WINDOWS_NATIVE_EXTENSIONS = /* @__PURE__ */ new Set([".exe", ".com"]);
56
+ var HostIsNotPiError = class extends Error {
57
+ static {
58
+ __name(this, "HostIsNotPiError");
59
+ }
60
+ constructor(message) {
61
+ super(message);
62
+ this.name = "HostIsNotPiError";
63
+ }
64
+ };
65
+ var LaunchPathOperationError = class extends Error {
66
+ static {
67
+ __name(this, "LaunchPathOperationError");
68
+ }
69
+ operation;
70
+ path;
71
+ pathCause;
72
+ constructor(operation, path, cause) {
73
+ super(`${operation} failed for ${path}: ${errorMessage(cause)}`, { cause });
74
+ this.name = "LaunchPathOperationError";
75
+ this.operation = operation;
76
+ this.path = path;
77
+ this.pathCause = cause;
78
+ }
79
+ };
80
+ var nodeLaunchIo = {
81
+ readFile: /* @__PURE__ */ __name((path) => readFileSync(path), "readFile"),
82
+ realpath: /* @__PURE__ */ __name((path) => realpathSync(path), "realpath"),
83
+ stat: /* @__PURE__ */ __name((path) => statSync(path), "stat"),
84
+ access: /* @__PURE__ */ __name((path, mode) => accessSync(path, mode), "access")
85
+ };
86
+ function launchIo(deps) {
87
+ return {
88
+ readFile: deps.readFile ?? nodeLaunchIo.readFile,
89
+ realpath: deps.realpath ?? nodeLaunchIo.realpath,
90
+ stat: deps.stat ?? nodeLaunchIo.stat,
91
+ access: deps.access ?? nodeLaunchIo.access
92
+ };
93
+ }
94
+ __name(launchIo, "launchIo");
95
+ function failResolution(message) {
96
+ throw new PiLaunchResolutionError(message);
97
+ }
98
+ __name(failResolution, "failResolution");
99
+ function errorMessage(error) {
100
+ return error instanceof Error ? error.message : String(error);
101
+ }
102
+ __name(errorMessage, "errorMessage");
103
+ function pathOperation(label, path, action) {
104
+ try {
105
+ return action();
106
+ } catch (error) {
107
+ throw new LaunchPathOperationError(label, path, error);
108
+ }
109
+ }
110
+ __name(pathOperation, "pathOperation");
111
+ function isMissingPathError(error) {
112
+ if (typeof error !== "object" || error === null) return false;
113
+ const code = Reflect.get(error, "code");
114
+ return code === "ENOENT" || code === "ENOTDIR";
115
+ }
116
+ __name(isMissingPathError, "isMissingPathError");
117
+ function isJsonRecord(value) {
118
+ return typeof value === "object" && value !== null && !Array.isArray(value);
119
+ }
120
+ __name(isJsonRecord, "isJsonRecord");
121
+ function parseManifest(raw, manifestPath) {
122
+ let parsed;
123
+ try {
124
+ parsed = JSON.parse(Buffer.isBuffer(raw) ? raw.toString("utf8") : raw);
125
+ } catch (error) {
126
+ throw new Error(`manifest JSON is invalid at ${manifestPath}: ${errorMessage(error)}`);
127
+ }
128
+ if (!isJsonRecord(parsed)) throw new Error(`manifest is not an object at ${manifestPath}`);
129
+ return parsed;
130
+ }
131
+ __name(parseManifest, "parseManifest");
132
+ function packageName(manifest, manifestPath) {
133
+ const name = manifest["name"];
134
+ if (name === void 0) return void 0;
135
+ if (typeof name !== "string" || name.trim().length === 0) {
136
+ throw new Error(`manifest name is malformed at ${manifestPath}`);
137
+ }
138
+ return name;
139
+ }
140
+ __name(packageName, "packageName");
141
+ function requirePiPackageName(manifest, manifestPath) {
142
+ const name = packageName(manifest, manifestPath);
143
+ if (name !== PI_PACKAGE_NAME) {
144
+ throw new Error(
145
+ `manifest package name must be ${PI_PACKAGE_NAME} at ${manifestPath}; received ${name === void 0 ? "<missing>" : name}`
146
+ );
147
+ }
148
+ }
149
+ __name(requirePiPackageName, "requirePiPackageName");
150
+ function readPiBin(manifest, manifestPath) {
151
+ const bin = manifest["bin"];
152
+ if (typeof bin === "string" && bin.trim().length > 0) return bin;
153
+ if (isJsonRecord(bin)) {
154
+ const pi = bin["pi"];
155
+ if (typeof pi === "string" && pi.trim().length > 0) return pi;
156
+ }
157
+ throw new Error(`manifest bin.pi is missing or malformed at ${manifestPath}`);
158
+ }
159
+ __name(readPiBin, "readPiBin");
160
+ function pathInside(parent, child) {
161
+ const rel = relative(parent, child);
162
+ return rel === "" || !isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`);
163
+ }
164
+ __name(pathInside, "pathInside");
165
+ function findNearestNamedManifest(sourcePath, io) {
166
+ const sourceReal = pathOperation("source realpath", sourcePath, () => io.realpath(sourcePath));
167
+ let dir = dirname(sourceReal);
168
+ for (; ; ) {
169
+ const candidate = join(dir, "package.json");
170
+ let candidateStat;
171
+ try {
172
+ candidateStat = io.stat(candidate);
173
+ } catch (error) {
174
+ if (!isMissingPathError(error)) {
175
+ throw new Error(`manifest stat failed for ${candidate}: ${errorMessage(error)}`);
176
+ }
177
+ const parent2 = dirname(dir);
178
+ if (parent2 === dir) {
179
+ throw new HostIsNotPiError(`no named package manifest above ${sourceReal}`);
180
+ }
181
+ dir = parent2;
182
+ continue;
183
+ }
184
+ if (!candidateStat.isFile()) {
185
+ throw new Error(`package boundary manifest is not a regular file at ${candidate}`);
186
+ }
187
+ const manifest = parseManifest(
188
+ pathOperation("manifest read", candidate, () => io.readFile(candidate)),
189
+ candidate
190
+ );
191
+ const name = packageName(manifest, candidate);
192
+ if (name !== void 0) return { manifestPath: candidate, sourceReal, name };
193
+ const parent = dirname(dir);
194
+ if (parent === dir) {
195
+ throw new HostIsNotPiError(`no named package manifest above ${sourceReal}`);
196
+ }
197
+ dir = parent;
198
+ }
199
+ }
200
+ __name(findNearestNamedManifest, "findNearestNamedManifest");
201
+ function findPiManifestFromHostScript(hostScript, io) {
202
+ if (!hostScript) throw new HostIsNotPiError("host script path is unavailable");
203
+ let found;
204
+ try {
205
+ found = findNearestNamedManifest(hostScript, io);
206
+ } catch (error) {
207
+ if (error instanceof HostIsNotPiError) throw error;
208
+ if (error instanceof LaunchPathOperationError && error.operation === "source realpath" && isMissingPathError(error.pathCause)) {
209
+ throw new HostIsNotPiError(error.message);
210
+ }
211
+ throw error;
212
+ }
213
+ if (found.name !== PI_PACKAGE_NAME) {
214
+ throw new HostIsNotPiError(
215
+ `nearest named manifest above host script belongs to ${found.name}: ${found.manifestPath}`
216
+ );
217
+ }
218
+ return found;
219
+ }
220
+ __name(findPiManifestFromHostScript, "findPiManifestFromHostScript");
221
+ function normalizeResolvedModulePath(pathOrUrl) {
222
+ return pathOrUrl.startsWith("file:") ? fileURLToPath(pathOrUrl) : pathOrUrl;
223
+ }
224
+ __name(normalizeResolvedModulePath, "normalizeResolvedModulePath");
225
+ function defaultResolveModule(specifier) {
226
+ if (specifier === PI_PACKAGE_MANIFEST) {
227
+ return createRequire(__pvMetaUrl).resolve(specifier);
228
+ }
229
+ return normalizeResolvedModulePath(import.meta.resolve(specifier));
230
+ }
231
+ __name(defaultResolveModule, "defaultResolveModule");
232
+ function resolvePiManifestFromModules(deps, io) {
233
+ if (deps.resolvePackageJson) {
234
+ return normalizeResolvedModulePath(deps.resolvePackageJson(PI_PACKAGE_MANIFEST));
235
+ }
236
+ const resolveModule = deps.resolveModule ?? defaultResolveModule;
237
+ let manifestError;
238
+ try {
239
+ return normalizeResolvedModulePath(resolveModule(PI_PACKAGE_MANIFEST));
240
+ } catch (error) {
241
+ manifestError = error;
242
+ }
243
+ let packageEntry;
244
+ try {
245
+ packageEntry = normalizeResolvedModulePath(resolveModule(PI_PACKAGE_NAME));
246
+ } catch (entryError) {
247
+ throw new Error(
248
+ `package manifest resolve failed for ${PI_PACKAGE_MANIFEST}: ${errorMessage(manifestError)}; package entry resolve failed: ${errorMessage(entryError)}`
249
+ );
250
+ }
251
+ let found;
252
+ try {
253
+ found = findNearestNamedManifest(packageEntry, io);
254
+ } catch (searchError) {
255
+ throw new Error(
256
+ `package manifest resolve failed for ${PI_PACKAGE_MANIFEST}: ${errorMessage(manifestError)}; package entry manifest search failed: ${errorMessage(searchError)}`
257
+ );
258
+ }
259
+ if (found.name !== PI_PACKAGE_NAME) {
260
+ throw new Error(
261
+ `package entry nearest named manifest belongs to ${found.name}: ${found.manifestPath}`
262
+ );
263
+ }
264
+ return found.manifestPath;
265
+ }
266
+ __name(resolvePiManifestFromModules, "resolvePiManifestFromModules");
267
+ function executableBasename(execPath, platform) {
268
+ return platform === "win32" ? win32Path.basename(execPath) : basename(execPath);
269
+ }
270
+ __name(executableBasename, "executableBasename");
271
+ function isGenericJavaScriptRuntime(execPath, platform) {
272
+ return /^(?:node|nodejs|bun)(?:\.exe)?$/i.test(executableBasename(execPath, platform));
273
+ }
274
+ __name(isGenericJavaScriptRuntime, "isGenericJavaScriptRuntime");
275
+ function resolveCompiledHostLaunch(deps, io, platform) {
276
+ const execPath = deps.execPath ?? process.execPath;
277
+ const executableName = executableBasename(execPath, platform);
278
+ const isNamedPiExecutable = platform === "win32" ? /^pi\.(?:exe|com)$/i.test(executableName) : executableName === "pi";
279
+ if (isGenericJavaScriptRuntime(execPath, platform) || !isNamedPiExecutable) return void 0;
280
+ const executableReal = pathOperation("compiled host realpath", execPath, () => io.realpath(execPath));
281
+ const executableStat = pathOperation(
282
+ "compiled host stat",
283
+ executableReal,
284
+ () => io.stat(executableReal)
285
+ );
286
+ if (!executableStat.isFile()) throw new Error("compiled Pi host is not a regular file");
287
+ if (platform === "win32") {
288
+ if (!WINDOWS_NATIVE_EXTENSIONS.has(extname(executableReal).toLowerCase())) {
289
+ throw new Error("compiled Windows Pi host must be an .exe or .com file");
290
+ }
291
+ } else {
292
+ pathOperation(
293
+ "compiled host execute access",
294
+ executableReal,
295
+ () => io.access(executableReal, constants.X_OK)
296
+ );
297
+ }
298
+ return { executable: executableReal, argvPrefix: [], kind: "compiled-host" };
299
+ }
300
+ __name(resolveCompiledHostLaunch, "resolveCompiledHostLaunch");
301
+ function resolvePackageLaunch(manifestPath, deps, io, platform, expectedHostReal) {
302
+ const manifestReal = pathOperation("manifest realpath", manifestPath, () => io.realpath(manifestPath));
303
+ if (basename(manifestReal).toLowerCase() !== "package.json") {
304
+ throw new Error(`resolved Pi manifest is not package.json: ${manifestReal}`);
305
+ }
306
+ const manifestStat = pathOperation("manifest stat", manifestReal, () => io.stat(manifestReal));
307
+ if (!manifestStat.isFile()) throw new Error(`Pi package manifest is not a regular file: ${manifestReal}`);
308
+ const manifest = parseManifest(
309
+ pathOperation("manifest read", manifestReal, () => io.readFile(manifestReal)),
310
+ manifestReal
311
+ );
312
+ requirePiPackageName(manifest, manifestReal);
313
+ const packageRootReal = pathOperation(
314
+ "package root realpath",
315
+ dirname(manifestReal),
316
+ () => io.realpath(dirname(manifestReal))
317
+ );
318
+ if (!pathInside(packageRootReal, manifestReal)) {
319
+ throw new Error("Pi package manifest resolves outside the package root");
320
+ }
321
+ const bin = readPiBin(manifest, manifestReal);
322
+ if (isAbsolute(bin) || platform === "win32" && (win32Path.isAbsolute(bin) || /^[a-z]:/i.test(bin)))
323
+ throw new Error("Pi package bin target must not be absolute; it must be relative to the package root");
324
+ const targetCandidate = resolve(packageRootReal, bin);
325
+ if (!pathInside(packageRootReal, targetCandidate)) {
326
+ throw new Error("Pi package bin target path escapes the package root");
327
+ }
328
+ const targetReal = pathOperation(
329
+ "bin target realpath",
330
+ targetCandidate,
331
+ () => io.realpath(targetCandidate)
332
+ );
333
+ if (!pathInside(packageRootReal, targetReal)) {
334
+ throw new Error("Pi package bin target resolves outside the package root");
335
+ }
336
+ const targetStat = pathOperation("bin target stat", targetReal, () => io.stat(targetReal));
337
+ if (!targetStat.isFile()) throw new Error("Pi package bin target is not a regular file");
338
+ if (expectedHostReal !== void 0 && targetReal !== expectedHostReal) {
339
+ throw new Error(
340
+ `running host script does not match manifest bin.pi: host ${expectedHostReal}; bin ${targetReal}`
341
+ );
342
+ }
343
+ const extension = extname(targetReal).toLowerCase();
344
+ if (JAVASCRIPT_EXTENSIONS.has(extension)) {
345
+ const execPath = deps.execPath ?? process.execPath;
346
+ if (!isGenericJavaScriptRuntime(execPath, platform)) {
347
+ throw new Error(
348
+ `Pi package JavaScript bin cannot launch through a non-generic JavaScript runtime: ${execPath}`
349
+ );
350
+ }
351
+ return { executable: execPath, argvPrefix: [targetReal], kind: "package-node-cli" };
352
+ }
353
+ if (platform === "win32" && WINDOWS_NATIVE_EXTENSIONS.has(extension)) {
354
+ return { executable: targetReal, argvPrefix: [], kind: "package-node-cli" };
355
+ }
356
+ throw new Error(`Pi package bin target extension is unsupported: ${extension || "<none>"}`);
357
+ }
358
+ __name(resolvePackageLaunch, "resolvePackageLaunch");
359
+ function resolveExecutableOnPosixPath(deps, io) {
360
+ const rawPath = deps.path ?? process.env["PATH"] ?? "";
361
+ const diagnostics = [];
362
+ if (rawPath.length === 0) diagnostics.push("PATH is empty");
363
+ for (const entry of rawPath.split(delimiter)) {
364
+ const directory = entry.length === 0 ? process.cwd() : entry;
365
+ const candidate = resolve(directory, "pi");
366
+ let candidateReal;
367
+ try {
368
+ candidateReal = io.realpath(candidate);
369
+ } catch (error) {
370
+ diagnostics.push(`${candidate}: ${errorMessage(error)}`);
371
+ continue;
372
+ }
373
+ try {
374
+ if (!io.stat(candidateReal).isFile()) {
375
+ diagnostics.push(`${candidateReal} is not a regular file`);
376
+ continue;
377
+ }
378
+ io.access(candidateReal, constants.X_OK);
379
+ } catch (error) {
380
+ diagnostics.push(`${candidateReal} is not executable: ${errorMessage(error)}`);
381
+ continue;
382
+ }
383
+ return {
384
+ // Bind the launch plan to the exact canonical executable admitted above.
385
+ // A later cwd or environment/PATH change must not trigger a second lookup.
386
+ launch: { executable: candidateReal, argvPrefix: [], kind: "path" },
387
+ diagnostics
388
+ };
389
+ }
390
+ return { diagnostics };
391
+ }
392
+ __name(resolveExecutableOnPosixPath, "resolveExecutableOnPosixPath");
393
+ function resolvePiLaunch(deps = {}) {
394
+ const platform = deps.platform ?? process.platform;
395
+ const io = launchIo(deps);
396
+ try {
397
+ const compiled = resolveCompiledHostLaunch(deps, io, platform);
398
+ if (compiled) return compiled;
399
+ } catch (error) {
400
+ failResolution(errorMessage(error));
401
+ }
402
+ const hostScript = deps.hostScript ?? process.argv[1];
403
+ let pathDiagnostic;
404
+ if (platform !== "win32") {
405
+ const pathResult = resolveExecutableOnPosixPath(deps, io);
406
+ if (pathResult.launch) return pathResult.launch;
407
+ pathDiagnostic = `no executable pi on PATH (${pathResult.diagnostics.join("; ") || "no candidates"})`;
408
+ }
409
+ let hostDiagnostic = "host script was not inspected";
410
+ try {
411
+ const host = findPiManifestFromHostScript(hostScript, io);
412
+ return resolvePackageLaunch(host.manifestPath, deps, io, platform, host.sourceReal);
413
+ } catch (error) {
414
+ if (!(error instanceof HostIsNotPiError)) failResolution(errorMessage(error));
415
+ hostDiagnostic = errorMessage(error);
416
+ }
417
+ let manifestPath;
418
+ try {
419
+ manifestPath = resolvePiManifestFromModules(deps, io);
420
+ } catch (error) {
421
+ const prefix = pathDiagnostic === void 0 ? "" : `${pathDiagnostic}; `;
422
+ failResolution(`${prefix}${errorMessage(error)}; running host lookup: ${hostDiagnostic}`);
423
+ }
424
+ try {
425
+ return resolvePackageLaunch(manifestPath, deps, io, platform);
426
+ } catch (error) {
427
+ failResolution(errorMessage(error));
428
+ }
429
+ }
430
+ __name(resolvePiLaunch, "resolvePiLaunch");
431
+ function piLaunchArgv(launch, piArgs) {
432
+ return [...launch.argvPrefix, ...piArgs];
433
+ }
434
+ __name(piLaunchArgv, "piLaunchArgv");
435
+ function renderWindowsArgument(value) {
436
+ if (value.length > 0 && !/[ \t"]/.test(value)) return value;
437
+ let rendered = '"';
438
+ let backslashes = 0;
439
+ for (const char of value) {
440
+ if (char === "\\") {
441
+ backslashes += 1;
442
+ continue;
443
+ }
444
+ if (char === '"') {
445
+ rendered += "\\".repeat(backslashes * 2 + 1);
446
+ rendered += '"';
447
+ backslashes = 0;
448
+ continue;
449
+ }
450
+ if (backslashes > 0) {
451
+ rendered += "\\".repeat(backslashes);
452
+ backslashes = 0;
453
+ }
454
+ rendered += char;
455
+ }
456
+ if (backslashes > 0) rendered += "\\".repeat(backslashes * 2);
457
+ rendered += '"';
458
+ return rendered;
459
+ }
460
+ __name(renderWindowsArgument, "renderWindowsArgument");
461
+ function renderWindowsCommandLine(parts) {
462
+ return parts.map(renderWindowsArgument).join(" ");
463
+ }
464
+ __name(renderWindowsCommandLine, "renderWindowsCommandLine");
465
+ function assertWindowsCommandLineWithinLimit(launch, piArgs, platform, stage) {
466
+ if (platform !== "win32") return;
467
+ const measuredLength = renderWindowsCommandLine([launch.executable, ...launch.argvPrefix, ...piArgs]).length + 1;
468
+ if (measuredLength > WINDOWS_COMMAND_LINE_LIMIT) {
469
+ throw new PiCommandLineLimitError(stage, measuredLength, WINDOWS_COMMAND_LINE_LIMIT);
470
+ }
471
+ }
472
+ __name(assertWindowsCommandLineWithinLimit, "assertWindowsCommandLineWithinLimit");
473
+
474
+ export {
475
+ resolvePiLaunch,
476
+ piLaunchArgv,
477
+ assertWindowsCommandLineWithinLimit
478
+ };
@@ -0,0 +1,28 @@
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
+ __name
4
+ } from "./c-CN77DCGF.mjs";
5
+
6
+ // node_modules/pi-background-tasks/src/core/canonical-json.ts?ext=pi-background-tasks
7
+ import { createHash } from "node:crypto";
8
+ function canonicalJson(value) {
9
+ return JSON.stringify(sortJson(value));
10
+ }
11
+ __name(canonicalJson, "canonicalJson");
12
+ function sha256Buffer(buffer) {
13
+ return `sha256:${createHash("sha256").update(buffer).digest("hex")}`;
14
+ }
15
+ __name(sha256Buffer, "sha256Buffer");
16
+ function sortJson(value) {
17
+ if (Array.isArray(value)) return value.map(sortJson);
18
+ if (typeof value !== "object" || value === null) return value;
19
+ return Object.fromEntries(
20
+ Object.keys(value).sort().map((key) => [key, sortJson(Reflect.get(value, key))])
21
+ );
22
+ }
23
+ __name(sortJson, "sortJson");
24
+
25
+ export {
26
+ canonicalJson,
27
+ sha256Buffer
28
+ };