@fased/fased 0.1.9 → 0.1.10

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 (160) hide show
  1. package/dist/{agents-C4jz1huI.js → agents-CsxQP5xg.js} +8 -8
  2. package/dist/{attachment-normalize-C-VpVpLd.js → attachment-normalize-CSxeaVcP.js} +1 -1
  3. package/dist/{attachment-normalize-DijgHIHy.js → attachment-normalize-f9lQXrZo.js} +1 -1
  4. package/dist/{audio-preflight-CI7BIPwS.js → audio-preflight-BeJd4YPQ.js} +2 -2
  5. package/dist/{audio-preflight-U5m63Clr.js → audio-preflight-CVU3GLti.js} +2 -2
  6. package/dist/{audio-preflight-oqlL2Kux.js → audio-preflight-C_g_wQAc.js} +1 -1
  7. package/dist/{audio-preflight-C6Lb4XU1.js → audio-preflight-DBtzpOL_.js} +1 -1
  8. package/dist/{audio-preflight-DLGJBu9O.js → audio-preflight-DD1zXhwM.js} +2 -2
  9. package/dist/{audit-DwbVJt3i.js → audit-BB2lDlNb.js} +1 -1
  10. package/dist/{audit-BCtx-_dH.js → audit-CDgqnjys.js} +1 -1
  11. package/dist/{auth-DIBzLQ-S.js → auth-Bfgwy6TQ.js} +5 -5
  12. package/dist/{auth-choice-CEeiz47B.js → auth-choice-DbEAsUsi.js} +1 -1
  13. package/dist/{auth-choice-DOqXUqF_.js → auth-choice-DlcbJgp_.js} +1 -1
  14. package/dist/{auth-choice-prompt-yqlvFI-_.js → auth-choice-prompt-CcOEzXoi.js} +1 -1
  15. package/dist/{auth-choice-prompt-FJDk83bS.js → auth-choice-prompt-DMlwK9kF.js} +1 -1
  16. package/dist/build-info.json +3 -3
  17. package/dist/bundled/boot-md/handler.js +1 -1
  18. package/dist/bundled/session-memory/handler.js +1 -1
  19. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  20. package/dist/{channel-web-CBfPvCCy.js → channel-web-CMZFjZzU.js} +1 -1
  21. package/dist/{channel-web-DaircVlX.js → channel-web-qHKfuCHE.js} +1 -1
  22. package/dist/{channels-BygboZOV.js → channels-BoOF2dAy.js} +6 -6
  23. package/dist/{channels-DgozxTBh.js → channels-DvT6s1kl.js} +6 -6
  24. package/dist/{channels-cli-DNz7gmOI.js → channels-cli-CNhEFKbn.js} +5 -5
  25. package/dist/{channels-cli-CY4n5HcO.js → channels-cli-NoUnbEgC.js} +5 -5
  26. package/dist/cli/daemon-cli.js +1 -1
  27. package/dist/{cli-CFgX3wef.js → cli-CE8pVYeA.js} +2 -2
  28. package/dist/{cli-63C0cETT.js → cli-Ctvy4-cz.js} +2 -2
  29. package/dist/{command-registry-DEiX9EPg.js → command-registry-fqlYdOTI.js} +9 -9
  30. package/dist/{completion-cli-CRwAyWQL.js → completion-cli-Bd9iPo4A.js} +1 -1
  31. package/dist/{completion-cli-BzQetGgr.js → completion-cli-CKzB1lB1.js} +2 -2
  32. package/dist/{config-cli-CPl1vPz0.js → config-cli-CQpqSVFS.js} +1 -1
  33. package/dist/{config-cli-C7vsh8Fg.js → config-cli-DUNkddbL.js} +1 -1
  34. package/dist/{configure-BEI_pe6B.js → configure-B2WT8-lE.js} +12 -12
  35. package/dist/{configure-C8lxNKpB.js → configure-DxDNasaD.js} +12 -12
  36. package/dist/control-ui/assets/app-wpJSg6bV.js.map +1 -1
  37. package/dist/{cron-cli-BqD_ZSEC.js → cron-cli-D3Dznk0V.js} +2 -2
  38. package/dist/{cron-cli-C7i4-Whp.js → cron-cli-DYWW7cv1.js} +2 -2
  39. package/dist/{daemon-cli-DFYzYoB8.js → daemon-cli-DDUjmEow.js} +1 -1
  40. package/dist/{daemon-cli-D0AP3mOg.js → daemon-cli-DFjCvbUo.js} +1 -1
  41. package/dist/daemon-cli.js +1 -1
  42. package/dist/{deps-D9aJvXyD.js → deps-4rCQ5SBd.js} +1 -1
  43. package/dist/{deps-ddWLkZAO.js → deps-CBapZnsi.js} +1 -1
  44. package/dist/entry.js +1 -1
  45. package/dist/extensionAPI.js +2 -2
  46. package/dist/{gateway-cli-D_Yd_yWi.js → gateway-cli-BXl9lmch.js} +27 -27
  47. package/dist/{gateway-cli-BJkYYsGs.js → gateway-cli-CNCA_gcT.js} +27 -27
  48. package/dist/{health-DCFLGVDU.js → health-C_g99tp_.js} +2 -2
  49. package/dist/{health-gyJixAyN.js → health-DTTfLYjl.js} +2 -2
  50. package/dist/{heartbeat-runner-Bn9N5npL.js → heartbeat-runner-D04n14H-.js} +1 -1
  51. package/dist/{heartbeat-runner-BFUvc4Y_.js → heartbeat-runner-DXh84Wuy.js} +1 -1
  52. package/dist/{hooks-cli-CGj2FDai.js → hooks-cli-BDpBNlPV.js} +3 -3
  53. package/dist/{hooks-cli-BGFJQWmK.js → hooks-cli-FhVd5CE-.js} +3 -3
  54. package/dist/index.js +7 -7
  55. package/dist/{ipv4-CjO0_Ry3.js → ipv4-Citn8Cno.js} +2 -2
  56. package/dist/{ipv4-CBSPFYQB.js → ipv4-P47TSJIK.js} +2 -2
  57. package/dist/{lifecycle-DFvIF7r0.js → lifecycle-B4RibYD4.js} +1 -1
  58. package/dist/{lifecycle-BBNnNoX_.js → lifecycle-Bgh3V8Jt.js} +1 -1
  59. package/dist/{list.auth-overview-DySKd1cu.js → list.auth-overview-BQzrIpgk.js} +1 -1
  60. package/dist/{list.auth-overview-CpmtoN2D.js → list.auth-overview-fBVXihg0.js} +1 -1
  61. package/dist/llm-slug-generator.js +1 -1
  62. package/dist/{model-catalog-DfLJlqO8.js → model-catalog-B2mRe6cZ.js} +6 -6
  63. package/dist/{models-BbfLyMBF.js → models-D8MTK6SG.js} +4 -4
  64. package/dist/{models-cli-Bu09lWlb.js → models-cli-Bl8xk6-0.js} +4 -4
  65. package/dist/{models-cli-DpmciZv6.js → models-cli-CXdCnyks.js} +5 -5
  66. package/dist/{node-cli-D6iG4Fev.js → node-cli-Cqh8buCU.js} +2 -2
  67. package/dist/{node-cli-GbiqR_FY.js → node-cli-DkgKrYS1.js} +2 -2
  68. package/dist/{onboard-BgU-rNfl.js → onboard-BD0MOrv7.js} +6 -6
  69. package/dist/{onboard-CViA2g_j.js → onboard-Dz8z4vBi.js} +6 -6
  70. package/dist/{onboard-channels-gHaSwzTd.js → onboard-channels-CPh2EJOi.js} +2 -2
  71. package/dist/{onboard-channels-BeKekf-a.js → onboard-channels-DUa2qkms.js} +2 -2
  72. package/dist/{onboard-search-DkOnHZm9.js → onboard-search-BnHMgV2k.js} +5 -5
  73. package/dist/{onboard-search-COuzKj6_.js → onboard-search-CqiDzWQw.js} +5 -5
  74. package/dist/{onboarding-CowfhJUD.js → onboarding-BC-5Pv9o.js} +7 -7
  75. package/dist/{onboarding-nabyJljA.js → onboarding-DgTB_zq7.js} +7 -7
  76. package/dist/{openresponses-http-D42SXipZ.js → openresponses-http-BQa9rI-N.js} +1 -1
  77. package/dist/{openresponses-http-C66CR36w.js → openresponses-http-BYiaPg-e.js} +2 -2
  78. package/dist/{openresponses-http-CdO4hFg_.js → openresponses-http-BirGBJTm.js} +2 -2
  79. package/dist/{openresponses-http-One5KNo8.js → openresponses-http-BsQmM8zM.js} +1 -1
  80. package/dist/{openresponses-http-BBydvP41.js → openresponses-http-CcawkBY4.js} +2 -2
  81. package/dist/{parent-default-help-82dOtJ5b.js → parent-default-help-CpfuGajV.js} +1 -1
  82. package/dist/{parent-default-help-iR__S_d8.js → parent-default-help-DbMf7NQe.js} +1 -1
  83. package/dist/{paths-Dwg5yVao.js → paths-BxKqczZV.js} +9 -9
  84. package/dist/{pi-embedded-BqhMzKsb.js → pi-embedded-Bapdl5Mb.js} +5 -5
  85. package/dist/{pi-embedded-DLEbV2ey.js → pi-embedded-DlBsi5bC.js} +14 -14
  86. package/dist/{plugin-registry-DgLnDYKc.js → plugin-registry-2aqMgXpl.js} +1 -1
  87. package/dist/{plugin-registry-DgnprUWu.js → plugin-registry-C7oTQytM.js} +1 -1
  88. package/dist/plugin-sdk/{audio-preflight-bl33qm06.js → audio-preflight-BbjERcpR.js} +1 -1
  89. package/dist/plugin-sdk/{audio-preflight-B3yRlgpY.js → audio-preflight-Vg4EuYfg.js} +1 -1
  90. package/dist/plugin-sdk/channel-plugin-common.js +1 -1
  91. package/dist/plugin-sdk/{channel-web-BmhttJUt.js → channel-web-JBsCrpEe.js} +1 -1
  92. package/dist/plugin-sdk/command-status.js +1 -1
  93. package/dist/plugin-sdk/index.js +2 -2
  94. package/dist/plugin-sdk/{openresponses-http-BkfMH5vT.js → openresponses-http-dj-a8V7Z.js} +1 -1
  95. package/dist/plugin-sdk/{openresponses-http-DVsmkLyj.js → openresponses-http-ihpGpya5.js} +1 -1
  96. package/dist/plugin-sdk/{pi-model-discovery-runtime-Cv_H-NDs.js → pi-model-discovery-runtime-CddkbYKA.js} +1 -1
  97. package/dist/plugin-sdk/{registry-Dpq_OloZ.js → registry-BhjWgT6A.js} +8 -8
  98. package/dist/plugin-sdk/{reply-ceu7kXX1.js → reply-CvmqbVx1.js} +5 -5
  99. package/dist/plugin-sdk/src/brand.d.ts +2 -2
  100. package/dist/plugin-sdk/{status-BcZw5R2P.js → status-DsTgMPSP.js} +5 -5
  101. package/dist/plugin-sdk/{web-DE0yQyjF.js → web-CLXmBst6.js} +1 -1
  102. package/dist/plugin-sdk/{web-D_ze88LT.js → web-DHSHEbWK.js} +2 -2
  103. package/dist/{plugins-cli-gUow1y1s.js → plugins-cli-CXa9m7-A.js} +5 -5
  104. package/dist/{plugins-cli-Bw8rkcLm.js → plugins-cli-Dj-p00ob.js} +5 -5
  105. package/dist/{program-D7MpzAVA.js → program-B3cXsVO0.js} +7 -7
  106. package/dist/{program-context-BnMmmcLR.js → program-context-Di7qiwOM.js} +24 -24
  107. package/dist/{prompt-select-styled-CZx9cLwR.js → prompt-select-styled-8KBIPNro.js} +4 -4
  108. package/dist/{prompt-select-styled-DEZExK7l.js → prompt-select-styled-C5o0Ff06.js} +4 -4
  109. package/dist/{pw-ai-Cjyb5RBL.js → pw-ai-BzOzOwqG.js} +1 -1
  110. package/dist/{register.agent-B9A7SDz_.js → register.agent-BYkIkPHf.js} +8 -8
  111. package/dist/{register.agent-DlatKWlA.js → register.agent-ll5ykI9x.js} +9 -9
  112. package/dist/{register.configure-Tez2eNbW.js → register.configure-C0GU1zbA.js} +12 -12
  113. package/dist/{register.configure-yNuOFQX6.js → register.configure-DubkYh7h.js} +12 -12
  114. package/dist/{register.maintenance-Q6YI5mk9.js → register.maintenance-Corgqhj5.js} +8 -8
  115. package/dist/{register.maintenance-BzVw1_e5.js → register.maintenance-Pz6desR4.js} +9 -9
  116. package/dist/{register.message-Cda69Xe6.js → register.message-COK8wYD_.js} +3 -3
  117. package/dist/{register.message-D9LYOvON.js → register.message-oi2ewJpl.js} +3 -3
  118. package/dist/{register.onboard-D1a2rQDh.js → register.onboard-C7ysxMn6.js} +14 -14
  119. package/dist/{register.onboard-BoLP06ui.js → register.onboard-zwRY0Dsh.js} +14 -14
  120. package/dist/{register.setup-DhppZhR2.js → register.setup-B1YGF1bz.js} +14 -14
  121. package/dist/{register.setup-D_qD7Gvk.js → register.setup-J2tUgD6C.js} +14 -14
  122. package/dist/{register.status-health-sessions-Csah3svc.js → register.status-health-sessions-DCazjMZa.js} +6 -6
  123. package/dist/{register.status-health-sessions-C0IsjCxS.js → register.status-health-sessions-DmjjMrJZ.js} +6 -6
  124. package/dist/{register.subclis-C4Dh6aQK.js → register.subclis-Bj8pFyAT.js} +16 -16
  125. package/dist/{reply-C3PsVpeQ.js → reply-DQfPM5ia.js} +6 -6
  126. package/dist/{run-main-XXpwNNGn.js → run-main-Cf6N-U3j.js} +14 -14
  127. package/dist/{runtime-helper-grants-BTCk3CzW.js → runtime-helper-grants-DONSfqWx.js} +1 -1
  128. package/dist/{runtime-helper-grants-C10OJEih.js → runtime-helper-grants-DzP6dgWv.js} +1 -1
  129. package/dist/{sandbox-cli-2MuBwFbv.js → sandbox-cli-CqUHfq55.js} +2 -2
  130. package/dist/{sandbox-cli-Bft002rK.js → sandbox-cli-DHHAXWD8.js} +2 -2
  131. package/dist/{security-cli-6CmGeQ7I.js → security-cli-CAEEYR8C.js} +3 -3
  132. package/dist/{security-cli-DpQep_pt.js → security-cli-DNlCSlQR.js} +3 -3
  133. package/dist/{server-OidOCKoj.js → server-B67PKank.js} +2 -2
  134. package/dist/{server-D62kYBqw.js → server-RYyJ2HTj.js} +2 -2
  135. package/dist/{server-cron-DYKXfeLU.js → server-cron-D7rN6EY6.js} +2 -2
  136. package/dist/{server-cron--g6K0O5V.js → server-cron-V9GBrg1S.js} +2 -2
  137. package/dist/{server-node-events-DSvH0zky.js → server-node-events-CAG2ic6e.js} +3 -3
  138. package/dist/{server-node-events-Csbl1Sw5.js → server-node-events-eh5LuLg6.js} +3 -3
  139. package/dist/{status-CEqTBWFX.js → status-BuGyo-1M.js} +4 -4
  140. package/dist/{status-cY8_nNEN.js → status-CTveTSuF.js} +1 -1
  141. package/dist/{status-DDWMOp5e.js → status-DIkbKBxH.js} +4 -4
  142. package/dist/{status-e52jwOFE.js → status-jb8w0SwX.js} +1 -1
  143. package/dist/{tui-K3OJBQvo.js → tui-Dinku0o-.js} +1 -1
  144. package/dist/{tui-cli-DEHMUby1.js → tui-cli-dq7xafwR.js} +3 -3
  145. package/dist/{tui-cli-CNL0cM4e.js → tui-cli-z5WV3SVg.js} +3 -3
  146. package/dist/{tui-B5xfA4bO.js → tui-lmdDZi6Y.js} +1 -1
  147. package/dist/{update-cli-BqiZ9j4m.js → update-cli-BdQ3mRGs.js} +10 -10
  148. package/dist/{update-cli-Cr7BTqe1.js → update-cli-Cq47v0X_.js} +9 -9
  149. package/dist/{update-runner-CycjY65W.js → update-runner-BnRMhKva.js} +1 -1
  150. package/dist/{update-runner-DcpjVgBR.js → update-runner-C0SU1jGT.js} +1 -1
  151. package/dist/{web-CLOmxVxX.js → web-B9YrSF5u.js} +2 -2
  152. package/dist/{web-6MnkoZyD.js → web-BmjUKJI0.js} +3 -3
  153. package/dist/{web-ChgN9rvX.js → web-D9wmjTDC.js} +3 -3
  154. package/dist/{web-D6CU81WZ.js → web-DaMiLN7K.js} +1 -1
  155. package/dist/{web-DhwWGdvc.js → web-sBExtZCA.js} +1 -1
  156. package/dist/{web-search-providers.runtime-D-uepqZ5.js → web-search-providers.runtime-TGCiBzhv.js} +1 -1
  157. package/dist/{web-search-providers.runtime-u6_OyUd6.js → web-search-providers.runtime-gM-8LIxg.js} +1 -1
  158. package/package.json +3 -1
  159. package/scripts/run-node.mjs +294 -0
  160. package/scripts/start-managed.sh +1528 -0
@@ -0,0 +1,294 @@
1
+ #!/usr/bin/env node
2
+ import { spawn, spawnSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import process from "node:process";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+
8
+ const compiler = "tsdown";
9
+ const compilerArgs = ["exec", compiler, "--no-clean"];
10
+
11
+ export const runNodeWatchedPaths = ["src", "extensions", "tsconfig.json", "package.json"];
12
+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
13
+ const defaultRunnerCwd = path.resolve(scriptDir, "..");
14
+
15
+ const statMtime = (filePath, fsImpl = fs) => {
16
+ try {
17
+ return fsImpl.statSync(filePath).mtimeMs;
18
+ } catch {
19
+ return null;
20
+ }
21
+ };
22
+
23
+ const isExcludedSource = (filePath, srcRoot) => {
24
+ const relativePath = path.relative(srcRoot, filePath);
25
+ if (relativePath.startsWith("..")) {
26
+ return false;
27
+ }
28
+ return (
29
+ relativePath.endsWith(".test.ts") ||
30
+ relativePath.endsWith(".test.tsx") ||
31
+ relativePath.endsWith(`test-helpers.ts`)
32
+ );
33
+ };
34
+
35
+ const findLatestMtime = (dirPath, shouldSkip, deps) => {
36
+ let latest = null;
37
+ const queue = [dirPath];
38
+ while (queue.length > 0) {
39
+ const current = queue.pop();
40
+ if (!current) {
41
+ continue;
42
+ }
43
+ let entries = [];
44
+ try {
45
+ entries = deps.fs.readdirSync(current, { withFileTypes: true });
46
+ } catch {
47
+ continue;
48
+ }
49
+ for (const entry of entries) {
50
+ const fullPath = path.join(current, entry.name);
51
+ if (entry.isDirectory()) {
52
+ queue.push(fullPath);
53
+ continue;
54
+ }
55
+ if (!entry.isFile()) {
56
+ continue;
57
+ }
58
+ if (shouldSkip?.(fullPath)) {
59
+ continue;
60
+ }
61
+ const mtime = statMtime(fullPath, deps.fs);
62
+ if (mtime == null) {
63
+ continue;
64
+ }
65
+ if (latest == null || mtime > latest) {
66
+ latest = mtime;
67
+ }
68
+ }
69
+ }
70
+ return latest;
71
+ };
72
+
73
+ const runGit = (gitArgs, deps) => {
74
+ try {
75
+ const result = deps.spawnSync("git", gitArgs, {
76
+ cwd: deps.cwd,
77
+ encoding: "utf8",
78
+ stdio: ["ignore", "pipe", "ignore"],
79
+ });
80
+ if (result.status !== 0) {
81
+ return null;
82
+ }
83
+ return (result.stdout ?? "").trim();
84
+ } catch {
85
+ return null;
86
+ }
87
+ };
88
+
89
+ const resolveGitHead = (deps) => {
90
+ const head = runGit(["rev-parse", "HEAD"], deps);
91
+ return head || null;
92
+ };
93
+
94
+ const hasDirtySourceTree = (deps) => {
95
+ const output = runGit(
96
+ ["status", "--porcelain", "--untracked-files=normal", "--", ...runNodeWatchedPaths],
97
+ deps,
98
+ );
99
+ if (output === null) {
100
+ return null;
101
+ }
102
+ return output.length > 0;
103
+ };
104
+
105
+ const readBuildStamp = (deps) => {
106
+ const mtime = statMtime(deps.buildStampPath, deps.fs);
107
+ if (mtime == null) {
108
+ return { mtime: null, head: null };
109
+ }
110
+ try {
111
+ const raw = deps.fs.readFileSync(deps.buildStampPath, "utf8").trim();
112
+ if (!raw.startsWith("{")) {
113
+ return { mtime, head: null };
114
+ }
115
+ const parsed = JSON.parse(raw);
116
+ const head = typeof parsed?.head === "string" && parsed.head.trim() ? parsed.head.trim() : null;
117
+ return { mtime, head };
118
+ } catch {
119
+ return { mtime, head: null };
120
+ }
121
+ };
122
+
123
+ const findLatestWatchedMtime = (deps) => {
124
+ let latest = null;
125
+ for (const watchedPath of runNodeWatchedPaths) {
126
+ const fullPath = path.join(deps.cwd, watchedPath);
127
+ let stat = null;
128
+ try {
129
+ stat = deps.fs.statSync(fullPath);
130
+ } catch {
131
+ continue;
132
+ }
133
+ const mtime = stat.isDirectory()
134
+ ? findLatestMtime(fullPath, (candidate) => isExcludedSource(candidate, fullPath), deps)
135
+ : stat.mtimeMs;
136
+ if (mtime == null) {
137
+ continue;
138
+ }
139
+ if (latest == null || mtime > latest) {
140
+ latest = mtime;
141
+ }
142
+ }
143
+ return latest;
144
+ };
145
+
146
+ const hasWatchedMtimeChanged = (stampMtime, deps) => {
147
+ const watchedMtime = findLatestWatchedMtime(deps);
148
+ return watchedMtime != null && watchedMtime > stampMtime;
149
+ };
150
+
151
+ const shouldBuild = (deps) => {
152
+ if (deps.env.FASED_SKIP_BUILD === "1") {
153
+ return false;
154
+ }
155
+ if (deps.env.FASED_FORCE_BUILD === "1") {
156
+ return true;
157
+ }
158
+ const stamp = readBuildStamp(deps);
159
+ if (stamp.mtime == null) {
160
+ return true;
161
+ }
162
+ if (statMtime(deps.distEntry, deps.fs) == null) {
163
+ return true;
164
+ }
165
+
166
+ for (const filePath of deps.configFiles) {
167
+ const mtime = statMtime(filePath, deps.fs);
168
+ if (mtime != null && mtime > stamp.mtime) {
169
+ return true;
170
+ }
171
+ }
172
+
173
+ const currentHead = resolveGitHead(deps);
174
+ if (currentHead && !stamp.head) {
175
+ return hasWatchedMtimeChanged(stamp.mtime, deps);
176
+ }
177
+ if (currentHead && stamp.head && currentHead !== stamp.head) {
178
+ return hasWatchedMtimeChanged(stamp.mtime, deps);
179
+ }
180
+ if (currentHead) {
181
+ const dirty = hasDirtySourceTree(deps);
182
+ if (dirty === true) {
183
+ return hasWatchedMtimeChanged(stamp.mtime, deps);
184
+ }
185
+ if (dirty === false) {
186
+ return false;
187
+ }
188
+ }
189
+
190
+ if (hasWatchedMtimeChanged(stamp.mtime, deps)) {
191
+ return true;
192
+ }
193
+ return false;
194
+ };
195
+
196
+ const logRunner = (message, deps) => {
197
+ if (deps.env.FASED_RUNNER_LOG === "0") {
198
+ return;
199
+ }
200
+ deps.stderr.write(`[fased] ${message}\n`);
201
+ };
202
+
203
+ const shouldUseJsonOnlyOutput = (args) => args.includes("--json");
204
+
205
+ const runFasedAgent = async (deps) => {
206
+ const nodeProcess = deps.spawn(deps.execPath, ["fased.mjs", ...deps.args], {
207
+ cwd: deps.cwd,
208
+ env: deps.env,
209
+ stdio: "inherit",
210
+ });
211
+ const res = await new Promise((resolve) => {
212
+ nodeProcess.on("exit", (exitCode, exitSignal) => {
213
+ resolve({ exitCode, exitSignal });
214
+ });
215
+ });
216
+ if (res.exitSignal) {
217
+ return 1;
218
+ }
219
+ return res.exitCode ?? 1;
220
+ };
221
+
222
+ const writeBuildStamp = (deps) => {
223
+ try {
224
+ deps.fs.mkdirSync(deps.distRoot, { recursive: true });
225
+ const stamp = {
226
+ builtAt: Date.now(),
227
+ head: resolveGitHead(deps),
228
+ };
229
+ deps.fs.writeFileSync(deps.buildStampPath, `${JSON.stringify(stamp)}\n`);
230
+ } catch (error) {
231
+ // Best-effort stamp; still allow the runner to start.
232
+ logRunner(`Failed to write build stamp: ${error?.message ?? "unknown error"}`, deps);
233
+ }
234
+ };
235
+
236
+ export async function runNodeMain(params = {}) {
237
+ const deps = {
238
+ spawn: params.spawn ?? spawn,
239
+ spawnSync: params.spawnSync ?? spawnSync,
240
+ fs: params.fs ?? fs,
241
+ stderr: params.stderr ?? process.stderr,
242
+ execPath: params.execPath ?? process.execPath,
243
+ cwd: params.cwd ?? defaultRunnerCwd,
244
+ args: params.args ?? process.argv.slice(2),
245
+ env: params.env ? { ...params.env } : { ...process.env },
246
+ platform: params.platform ?? process.platform,
247
+ };
248
+
249
+ deps.distRoot = path.join(deps.cwd, "dist");
250
+ deps.distEntry = path.join(deps.distRoot, "/entry.js");
251
+ deps.buildStampPath = path.join(deps.distRoot, ".buildstamp");
252
+ deps.srcRoot = path.join(deps.cwd, "src");
253
+ deps.configFiles = [path.join(deps.cwd, "tsconfig.json"), path.join(deps.cwd, "package.json")];
254
+
255
+ if (!shouldBuild(deps)) {
256
+ return await runFasedAgent(deps);
257
+ }
258
+
259
+ logRunner("Building TypeScript (dist is stale).", deps);
260
+ const buildCmd = deps.platform === "win32" ? "cmd.exe" : "pnpm";
261
+ const buildArgs =
262
+ deps.platform === "win32" ? ["/d", "/s", "/c", "pnpm", ...compilerArgs] : compilerArgs;
263
+ const buildStdio = shouldUseJsonOnlyOutput(deps.args) ? ["ignore", "pipe", "pipe"] : "inherit";
264
+ const build = deps.spawn(buildCmd, buildArgs, {
265
+ cwd: deps.cwd,
266
+ env: deps.env,
267
+ stdio: buildStdio,
268
+ });
269
+ if (buildStdio !== "inherit") {
270
+ build.stdout?.on("data", (chunk) => deps.stderr.write(chunk));
271
+ build.stderr?.on("data", (chunk) => deps.stderr.write(chunk));
272
+ }
273
+
274
+ const buildRes = await new Promise((resolve) => {
275
+ build.on("exit", (exitCode, exitSignal) => resolve({ exitCode, exitSignal }));
276
+ });
277
+ if (buildRes.exitSignal) {
278
+ return 1;
279
+ }
280
+ if (buildRes.exitCode !== 0 && buildRes.exitCode !== null) {
281
+ return buildRes.exitCode;
282
+ }
283
+ writeBuildStamp(deps);
284
+ return await runFasedAgent(deps);
285
+ }
286
+
287
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
288
+ void runNodeMain()
289
+ .then((code) => process.exit(code))
290
+ .catch((err) => {
291
+ console.error(err);
292
+ process.exit(1);
293
+ });
294
+ }