@automaton-labs/aib 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/README.md +578 -0
  2. package/dist/bin/aib.js +2 -0
  3. package/dist/bin/cli.js +3 -0
  4. package/dist/client/http-client.js +1 -0
  5. package/dist/client/transport-options.js +1 -0
  6. package/dist/client/websocket-client.js +1 -0
  7. package/dist/commands/add-missing-imports-preview-cache.js +2 -0
  8. package/dist/commands/add-missing-imports.js +2 -0
  9. package/dist/commands/apply-module-plan.js +3 -0
  10. package/dist/commands/captured-input.js +2 -0
  11. package/dist/commands/config-command.js +3 -0
  12. package/dist/commands/diagnostics-command.js +3 -0
  13. package/dist/commands/doctor.js +1 -0
  14. package/dist/commands/entity-resolution.js +1 -0
  15. package/dist/commands/execution-command.js +1 -0
  16. package/dist/commands/feedback-command.js +3 -0
  17. package/dist/commands/find-importers.js +1 -0
  18. package/dist/commands/find-unused-imports.js +1 -0
  19. package/dist/commands/generate-docs-command.js +6 -0
  20. package/dist/commands/help-command.js +3 -0
  21. package/dist/commands/imports-command.js +1 -0
  22. package/dist/commands/init-skill-usage.js +3 -0
  23. package/dist/commands/init-workspace.js +3 -0
  24. package/dist/commands/inspect-cycles.js +5 -0
  25. package/dist/commands/inspect-format.js +18 -0
  26. package/dist/commands/inspect-graph.js +9 -0
  27. package/dist/commands/inspect-imports.js +2 -0
  28. package/dist/commands/inspect-symbol-query.js +1 -0
  29. package/dist/commands/inspect-tree.js +5 -0
  30. package/dist/commands/inspect.js +16 -0
  31. package/dist/commands/json-file-input.js +1 -0
  32. package/dist/commands/list-instances.js +1 -0
  33. package/dist/commands/module-plan-cache.js +2 -0
  34. package/dist/commands/module-plan-command.js +1 -0
  35. package/dist/commands/module-plan-timeout.js +1 -0
  36. package/dist/commands/move-command.js +1 -0
  37. package/dist/commands/move-preview-cache.js +2 -0
  38. package/dist/commands/move-to-file.js +2 -0
  39. package/dist/commands/mutation-execution-cache.js +3 -0
  40. package/dist/commands/normalize-imports.js +4 -0
  41. package/dist/commands/observability-command.js +3 -0
  42. package/dist/commands/ping.js +1 -0
  43. package/dist/commands/print-config.js +1 -0
  44. package/dist/commands/quick-read.js +11 -0
  45. package/dist/commands/refactor-batch-builder.js +1 -0
  46. package/dist/commands/refactor-batch-execution-cache.js +1 -0
  47. package/dist/commands/refactor-batch-preview-cache.js +2 -0
  48. package/dist/commands/refactor-batch.js +4 -0
  49. package/dist/commands/refactor-command.js +1 -0
  50. package/dist/commands/rename-command.js +1 -0
  51. package/dist/commands/rename-entities.js +4 -0
  52. package/dist/commands/rename-execution-cache.js +1 -0
  53. package/dist/commands/rename-input.js +1 -0
  54. package/dist/commands/rename-preview-cache.js +2 -0
  55. package/dist/commands/result-view.js +6 -0
  56. package/dist/commands/runtime-command.js +4 -0
  57. package/dist/commands/runtime-info.js +1 -0
  58. package/dist/commands/session-workspace.js +31 -0
  59. package/dist/commands/shared.js +1 -0
  60. package/dist/commands/sync-command.js +2 -0
  61. package/dist/commands/validate-module-plan.js +2 -0
  62. package/dist/commands/workspace-cache.js +1 -0
  63. package/dist/compatibility/policy.js +1 -0
  64. package/dist/config/auto-start-ide.js +1 -0
  65. package/dist/config/defaults.js +1 -0
  66. package/dist/config/env-vars.js +1 -0
  67. package/dist/config/glob-match.js +1 -0
  68. package/dist/config/import-rules.js +1 -0
  69. package/dist/config/local-config.js +3 -0
  70. package/dist/config/mutation-comments.js +1 -0
  71. package/dist/config/path-aliases.js +1 -0
  72. package/dist/config/path-display.js +1 -0
  73. package/dist/config/product-storage.js +1 -0
  74. package/dist/config/resolve-command-alias.js +1 -0
  75. package/dist/config/resolve.js +1 -0
  76. package/dist/config/workspace-root.js +3 -0
  77. package/dist/config/workspace-state.js +1 -0
  78. package/dist/content/content-bundle.js +1 -0
  79. package/dist/diagnostics/module-plan-timeline.js +2 -0
  80. package/dist/diagnostics/readiness-text.js +8 -0
  81. package/dist/discovery/registry.js +1 -0
  82. package/dist/discovery/select-instance.js +1 -0
  83. package/dist/dsl/aib-dsl.js +1 -0
  84. package/dist/help/bootstrap.md +924 -0
  85. package/dist/help/diagnostics/doctor.json +70 -0
  86. package/dist/help/docs/basics.md +14 -0
  87. package/dist/help/docs/dsl.md +25 -0
  88. package/dist/help/docs/help-format.md +12 -0
  89. package/dist/help/docs/imports.normalize.md +36 -0
  90. package/dist/help/docs/inspect.code.md +29 -0
  91. package/dist/help/docs/inspect.deps.md +32 -0
  92. package/dist/help/docs/inspect.duplicates.md +72 -0
  93. package/dist/help/docs/inspect.exports.md +34 -0
  94. package/dist/help/docs/inspect.file.md +32 -0
  95. package/dist/help/docs/inspect.graph.md +112 -0
  96. package/dist/help/docs/inspect.imports.md +15 -0
  97. package/dist/help/docs/inspect.md +71 -0
  98. package/dist/help/docs/inspect.members.md +24 -0
  99. package/dist/help/docs/inspect.tree.md +30 -0
  100. package/dist/help/docs/inspect.usages.md +48 -0
  101. package/dist/help/docs/modulePlan.md +51 -0
  102. package/dist/help/docs/move.md +37 -0
  103. package/dist/help/docs/mutation.md +47 -0
  104. package/dist/help/docs/patterns.md +178 -0
  105. package/dist/help/docs/prefs.md +40 -0
  106. package/dist/help/docs/qr.md +33 -0
  107. package/dist/help/docs/refactor.batch.md +44 -0
  108. package/dist/help/docs/rename.md +39 -0
  109. package/dist/help/docs/selectors.md +23 -0
  110. package/dist/help/docs/session.md +61 -0
  111. package/dist/help/docs/view.md +30 -0
  112. package/dist/help/dsl/bootstrap.md +924 -0
  113. package/dist/help/dsl/docs/basics.md +14 -0
  114. package/dist/help/dsl/docs/dsl.md +25 -0
  115. package/dist/help/dsl/docs/help-format.md +12 -0
  116. package/dist/help/dsl/docs/imports.normalize.md +36 -0
  117. package/dist/help/dsl/docs/inspect.code.md +29 -0
  118. package/dist/help/dsl/docs/inspect.deps.md +32 -0
  119. package/dist/help/dsl/docs/inspect.duplicates.md +72 -0
  120. package/dist/help/dsl/docs/inspect.exports.md +34 -0
  121. package/dist/help/dsl/docs/inspect.file.md +32 -0
  122. package/dist/help/dsl/docs/inspect.graph.md +112 -0
  123. package/dist/help/dsl/docs/inspect.imports.md +15 -0
  124. package/dist/help/dsl/docs/inspect.md +71 -0
  125. package/dist/help/dsl/docs/inspect.members.md +24 -0
  126. package/dist/help/dsl/docs/inspect.tree.md +30 -0
  127. package/dist/help/dsl/docs/inspect.usages.md +48 -0
  128. package/dist/help/dsl/docs/modulePlan.md +51 -0
  129. package/dist/help/dsl/docs/move.md +37 -0
  130. package/dist/help/dsl/docs/mutation.md +47 -0
  131. package/dist/help/dsl/docs/patterns.md +178 -0
  132. package/dist/help/dsl/docs/prefs.md +40 -0
  133. package/dist/help/dsl/docs/qr.md +33 -0
  134. package/dist/help/dsl/docs/refactor.batch.md +44 -0
  135. package/dist/help/dsl/docs/rename.md +39 -0
  136. package/dist/help/dsl/docs/selectors.md +23 -0
  137. package/dist/help/dsl/docs/session.md +61 -0
  138. package/dist/help/dsl/docs/view.md +30 -0
  139. package/dist/help/dsl/full.md +924 -0
  140. package/dist/help/dsl/snippets/agents.md +14 -0
  141. package/dist/help/dsl/topics/basics.md +12 -0
  142. package/dist/help/dsl/topics/dsl.md +23 -0
  143. package/dist/help/dsl/topics/help-format.md +10 -0
  144. package/dist/help/dsl/topics/imports.normalize.md +34 -0
  145. package/dist/help/dsl/topics/inspect.code.md +27 -0
  146. package/dist/help/dsl/topics/inspect.deps.md +30 -0
  147. package/dist/help/dsl/topics/inspect.duplicates.md +43 -0
  148. package/dist/help/dsl/topics/inspect.exports.md +32 -0
  149. package/dist/help/dsl/topics/inspect.file.md +30 -0
  150. package/dist/help/dsl/topics/inspect.graph.md +110 -0
  151. package/dist/help/dsl/topics/inspect.imports.md +13 -0
  152. package/dist/help/dsl/topics/inspect.md +69 -0
  153. package/dist/help/dsl/topics/inspect.members.md +22 -0
  154. package/dist/help/dsl/topics/inspect.tree.md +20 -0
  155. package/dist/help/dsl/topics/inspect.usages.md +46 -0
  156. package/dist/help/dsl/topics/modulePlan.md +38 -0
  157. package/dist/help/dsl/topics/move.md +27 -0
  158. package/dist/help/dsl/topics/mutation.md +45 -0
  159. package/dist/help/dsl/topics/patterns.md +176 -0
  160. package/dist/help/dsl/topics/prefs.md +38 -0
  161. package/dist/help/dsl/topics/qr.md +31 -0
  162. package/dist/help/dsl/topics/refactor.batch.md +33 -0
  163. package/dist/help/dsl/topics/rename.md +25 -0
  164. package/dist/help/dsl/topics/selectors.md +21 -0
  165. package/dist/help/dsl/topics/session.md +59 -0
  166. package/dist/help/dsl/topics/view.md +28 -0
  167. package/dist/help/full.md +924 -0
  168. package/dist/help/help-meta.json +113 -0
  169. package/dist/help/index.md +167 -0
  170. package/dist/help/json/bootstrap.md +1074 -0
  171. package/dist/help/json/docs/basics.md +15 -0
  172. package/dist/help/json/docs/dsl.md +25 -0
  173. package/dist/help/json/docs/help-format.md +12 -0
  174. package/dist/help/json/docs/imports.normalize.md +47 -0
  175. package/dist/help/json/docs/inspect.code.md +41 -0
  176. package/dist/help/json/docs/inspect.deps.md +46 -0
  177. package/dist/help/json/docs/inspect.duplicates.md +65 -0
  178. package/dist/help/json/docs/inspect.exports.md +40 -0
  179. package/dist/help/json/docs/inspect.file.md +38 -0
  180. package/dist/help/json/docs/inspect.graph.md +139 -0
  181. package/dist/help/json/docs/inspect.imports.md +15 -0
  182. package/dist/help/json/docs/inspect.md +87 -0
  183. package/dist/help/json/docs/inspect.members.md +32 -0
  184. package/dist/help/json/docs/inspect.tree.md +30 -0
  185. package/dist/help/json/docs/inspect.usages.md +61 -0
  186. package/dist/help/json/docs/modulePlan.md +70 -0
  187. package/dist/help/json/docs/move.md +53 -0
  188. package/dist/help/json/docs/mutation.md +62 -0
  189. package/dist/help/json/docs/patterns.md +178 -0
  190. package/dist/help/json/docs/prefs.md +40 -0
  191. package/dist/help/json/docs/qr.md +33 -0
  192. package/dist/help/json/docs/refactor.batch.md +72 -0
  193. package/dist/help/json/docs/rename.md +47 -0
  194. package/dist/help/json/docs/selectors.md +23 -0
  195. package/dist/help/json/docs/session.md +77 -0
  196. package/dist/help/json/docs/view.md +30 -0
  197. package/dist/help/json/full.md +1074 -0
  198. package/dist/help/json/snippets/agents.md +14 -0
  199. package/dist/help/json/topics/basics.md +13 -0
  200. package/dist/help/json/topics/dsl.md +23 -0
  201. package/dist/help/json/topics/help-format.md +10 -0
  202. package/dist/help/json/topics/imports.normalize.md +45 -0
  203. package/dist/help/json/topics/inspect.code.md +39 -0
  204. package/dist/help/json/topics/inspect.deps.md +44 -0
  205. package/dist/help/json/topics/inspect.duplicates.md +37 -0
  206. package/dist/help/json/topics/inspect.exports.md +38 -0
  207. package/dist/help/json/topics/inspect.file.md +36 -0
  208. package/dist/help/json/topics/inspect.graph.md +137 -0
  209. package/dist/help/json/topics/inspect.imports.md +13 -0
  210. package/dist/help/json/topics/inspect.md +85 -0
  211. package/dist/help/json/topics/inspect.members.md +30 -0
  212. package/dist/help/json/topics/inspect.tree.md +20 -0
  213. package/dist/help/json/topics/inspect.usages.md +59 -0
  214. package/dist/help/json/topics/modulePlan.md +57 -0
  215. package/dist/help/json/topics/move.md +43 -0
  216. package/dist/help/json/topics/mutation.md +60 -0
  217. package/dist/help/json/topics/patterns.md +176 -0
  218. package/dist/help/json/topics/prefs.md +38 -0
  219. package/dist/help/json/topics/qr.md +31 -0
  220. package/dist/help/json/topics/refactor.batch.md +61 -0
  221. package/dist/help/json/topics/rename.md +42 -0
  222. package/dist/help/json/topics/selectors.md +21 -0
  223. package/dist/help/json/topics/session.md +59 -0
  224. package/dist/help/json/topics/view.md +28 -0
  225. package/dist/help/snippets/agents.md +14 -0
  226. package/dist/help/topics/basics.md +12 -0
  227. package/dist/help/topics/dsl.md +23 -0
  228. package/dist/help/topics/help-format.md +10 -0
  229. package/dist/help/topics/imports.normalize.md +34 -0
  230. package/dist/help/topics/inspect.code.md +27 -0
  231. package/dist/help/topics/inspect.deps.md +30 -0
  232. package/dist/help/topics/inspect.duplicates.md +43 -0
  233. package/dist/help/topics/inspect.exports.md +32 -0
  234. package/dist/help/topics/inspect.file.md +30 -0
  235. package/dist/help/topics/inspect.graph.md +110 -0
  236. package/dist/help/topics/inspect.imports.md +13 -0
  237. package/dist/help/topics/inspect.md +69 -0
  238. package/dist/help/topics/inspect.members.md +22 -0
  239. package/dist/help/topics/inspect.tree.md +20 -0
  240. package/dist/help/topics/inspect.usages.md +46 -0
  241. package/dist/help/topics/modulePlan.md +38 -0
  242. package/dist/help/topics/move.md +27 -0
  243. package/dist/help/topics/mutation.md +45 -0
  244. package/dist/help/topics/patterns.md +176 -0
  245. package/dist/help/topics/prefs.md +38 -0
  246. package/dist/help/topics/qr.md +31 -0
  247. package/dist/help/topics/refactor.batch.md +33 -0
  248. package/dist/help/topics/rename.md +25 -0
  249. package/dist/help/topics/selectors.md +21 -0
  250. package/dist/help/topics/session.md +59 -0
  251. package/dist/help/topics/view.md +28 -0
  252. package/dist/ide-launch/common.cjs +162 -0
  253. package/dist/managed-host/extension-vsix-resolver.js +1 -0
  254. package/dist/managed-host/manage-serve-web-host.cjs +141 -0
  255. package/dist/managed-host/serve-web-autostart.js +1 -0
  256. package/dist/managed-host/serve-web-host.cjs +1790 -0
  257. package/dist/metrics/central-metrics.js +2 -0
  258. package/dist/observability/config.js +1 -0
  259. package/dist/observability/context.js +1 -0
  260. package/dist/observability/failure-snapshot.js +2 -0
  261. package/dist/observability/recent.js +2 -0
  262. package/dist/payloads/read-stdin-json.js +1 -0
  263. package/dist/runtime/bundled-node.js +1 -0
  264. package/dist/runtime/input-source.js +1 -0
  265. package/dist/runtime/managed-runtime-provisioning.js +1 -0
  266. package/dist/runtime/run-command.js +1 -0
  267. package/dist/selectors/parse-entities.js +1 -0
  268. package/dist/session/client.js +1 -0
  269. package/dist/session/paths.js +1 -0
  270. package/dist/session/server.js +6 -0
  271. package/dist/shared/agent-text.js +1 -0
  272. package/dist/shared/diagnostic-catalog.js +1 -0
  273. package/dist/shared/diagnostics.js +1 -0
  274. package/dist/shared/errors.js +28 -0
  275. package/dist/shared/event-loop.js +1 -0
  276. package/dist/shared/hints.js +1 -0
  277. package/dist/shared/metrics.js +1 -0
  278. package/dist/shared/operations.js +1 -0
  279. package/dist/shared/presentation.js +4 -0
  280. package/dist/shared/protocol.js +1 -0
  281. package/dist/shared/routes.js +1 -0
  282. package/dist/shared/stdout.js +2 -0
  283. package/dist/shared/types.js +1 -0
  284. package/dist/tracing/config.js +2 -0
  285. package/dist/tracing/trace.js +3 -0
  286. package/extension/vscode-refactor-bridge-extension.vsix +0 -0
  287. package/package.json +39 -0
  288. package/runtimes/launcher/win-x64/aib.exe +0 -0
  289. package/scripts/install-windows-launcher.cjs +58 -0
  290. package/scripts/postinstall.cjs +28 -0
  291. package/scripts/provision-runtime.cjs +299 -0
@@ -0,0 +1,299 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("node:fs");
4
+ const os = require("node:os");
5
+ const path = require("node:path");
6
+ const crypto = require("node:crypto");
7
+ const http = require("node:http");
8
+ const https = require("node:https");
9
+ const { spawnSync } = require("node:child_process");
10
+
11
+ const packageRoot = path.resolve(__dirname, "..");
12
+ const runtimesDir = path.join(packageRoot, "runtimes");
13
+ const packageJson = JSON.parse(fs.readFileSync(path.join(packageRoot, "package.json"), "utf8"));
14
+ const platformKey = `${process.platform}-${process.arch}`;
15
+
16
+ const options = parseArgs(process.argv.slice(2));
17
+
18
+ main().catch((error) => {
19
+ if (!options.quiet) {
20
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
21
+ }
22
+ process.exitCode = 1;
23
+ });
24
+
25
+ async function main() {
26
+ if (runtimeComplete()) {
27
+ if (!options.quiet) {
28
+ process.stdout.write(`runtime ready: ${path.relative(process.cwd(), runtimesDir) || runtimesDir}\n`);
29
+ }
30
+ return;
31
+ }
32
+
33
+ const source = options.archive
34
+ ?? process.env.AIB_RUNTIME_ARCHIVE
35
+ ?? process.env.npm_config_aib_runtime_archive
36
+ ?? null;
37
+ const url = options.url
38
+ ?? process.env.AIB_RUNTIME_URL
39
+ ?? process.env.npm_config_aib_runtime_url
40
+ ?? null;
41
+ const manifestSource = options.manifest
42
+ ?? process.env.AIB_RUNTIME_MANIFEST
43
+ ?? process.env.npm_config_aib_runtime_manifest
44
+ ?? null;
45
+ const manifestUrl = options.manifestUrl
46
+ ?? process.env.AIB_RUNTIME_MANIFEST_URL
47
+ ?? process.env.npm_config_aib_runtime_manifest_url
48
+ ?? defaultManifestUrl();
49
+
50
+ if (!source && !url && !manifestSource && !manifestUrl) {
51
+ if (!options.quiet) {
52
+ process.stdout.write("runtime not provisioned: set AIB_RUNTIME_ARCHIVE, AIB_RUNTIME_URL, AIB_RUNTIME_MANIFEST, or AIB_RUNTIME_MANIFEST_URL\n");
53
+ }
54
+ return;
55
+ }
56
+
57
+ const resolution = source || url
58
+ ? { archivePath: source ? path.resolve(source) : await downloadRuntimeArchive(url), expectedSha256: options.sha256 ?? process.env.AIB_RUNTIME_SHA256 ?? null }
59
+ : await resolveFromManifest(manifestSource, manifestUrl);
60
+ const archivePath = resolution.archivePath;
61
+ if (!fs.existsSync(archivePath)) {
62
+ throw new Error(`Runtime archive not found: ${archivePath}`);
63
+ }
64
+ if (resolution.expectedSha256) {
65
+ assertSha256(archivePath, resolution.expectedSha256);
66
+ }
67
+
68
+ fs.mkdirSync(runtimesDir, { recursive: true });
69
+ extractRuntimeArchive(archivePath);
70
+
71
+ if (!runtimeComplete()) {
72
+ throw new Error(`Runtime archive did not provision a complete runtime under ${runtimesDir}`);
73
+ }
74
+
75
+ if (!options.quiet) {
76
+ process.stdout.write(`runtime provisioned: ${path.relative(process.cwd(), runtimesDir) || runtimesDir}\n`);
77
+ }
78
+ }
79
+
80
+ function parseArgs(argv) {
81
+ const parsed = {
82
+ archive: null,
83
+ url: null,
84
+ manifest: null,
85
+ manifestUrl: null,
86
+ sha256: null,
87
+ quiet: false
88
+ };
89
+ for (let index = 0; index < argv.length; index += 1) {
90
+ const current = argv[index];
91
+ const next = argv[index + 1];
92
+ if (current === "--archive" && next) {
93
+ parsed.archive = next;
94
+ index += 1;
95
+ continue;
96
+ }
97
+ if (current === "--url" && next) {
98
+ parsed.url = next;
99
+ index += 1;
100
+ continue;
101
+ }
102
+ if (current === "--manifest" && next) {
103
+ parsed.manifest = next;
104
+ index += 1;
105
+ continue;
106
+ }
107
+ if (current === "--manifest-url" && next) {
108
+ parsed.manifestUrl = next;
109
+ index += 1;
110
+ continue;
111
+ }
112
+ if (current === "--sha256" && next) {
113
+ parsed.sha256 = next;
114
+ index += 1;
115
+ continue;
116
+ }
117
+ if (current === "--quiet") {
118
+ parsed.quiet = true;
119
+ continue;
120
+ }
121
+ throw new Error(`Unknown argument: ${current}`);
122
+ }
123
+ return parsed;
124
+ }
125
+
126
+ async function resolveFromManifest(manifestSource, manifestUrl) {
127
+ const manifest = manifestSource
128
+ ? JSON.parse(fs.readFileSync(path.resolve(manifestSource), "utf8"))
129
+ : await downloadJson(manifestUrl);
130
+ const artifact = manifest?.artifacts?.[platformKey];
131
+ if (!artifact || typeof artifact !== "object") {
132
+ throw new Error(`Runtime manifest does not contain an artifact for ${platformKey}`);
133
+ }
134
+ const archivePath = artifact.file && manifestSource
135
+ ? path.resolve(path.dirname(path.resolve(manifestSource)), String(artifact.file))
136
+ : artifact.url
137
+ ? await downloadRuntimeArchive(String(artifact.url))
138
+ : null;
139
+ if (!archivePath) {
140
+ throw new Error(`Runtime manifest artifact for ${platformKey} has no url or local file.`);
141
+ }
142
+ return {
143
+ archivePath,
144
+ expectedSha256: typeof artifact.sha256 === "string" ? artifact.sha256 : null
145
+ };
146
+ }
147
+
148
+ async function downloadJson(url) {
149
+ const filePath = await downloadRuntimeArchive(url);
150
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
151
+ }
152
+
153
+ function defaultManifestUrl() {
154
+ const version = packageJson.version;
155
+ if (!version) {
156
+ return null;
157
+ }
158
+ return `https://github.com/ratiomark/aib-runtime/releases/download/v${version}/aib-runtime-manifest.json`;
159
+ }
160
+
161
+ function runtimeComplete() {
162
+ return fs.existsSync(path.join(runtimesDir, "code-server", "node_modules", "code-server", "out", "node", "entry.js"))
163
+ && Boolean(findPackagedBrowserRuntime())
164
+ && Boolean(findPackagedNodeRuntime());
165
+ }
166
+
167
+ function findPackagedNodeRuntime() {
168
+ const platformDir = nodeRuntimePlatformDir();
169
+ if (!platformDir) {
170
+ return null;
171
+ }
172
+ const candidate = process.platform === "win32"
173
+ ? path.join(runtimesDir, "node", platformDir, "node.exe")
174
+ : path.join(runtimesDir, "node", platformDir, "bin", "node");
175
+ return fs.existsSync(candidate) ? candidate : null;
176
+ }
177
+
178
+ function nodeRuntimePlatformDir() {
179
+ if (process.platform === "win32" && process.arch === "x64") {
180
+ return "win-x64";
181
+ }
182
+ if (process.platform === "linux" && process.arch === "x64") {
183
+ return "linux-x64";
184
+ }
185
+ if (process.platform === "linux" && process.arch === "arm64") {
186
+ return "linux-arm64";
187
+ }
188
+ if (process.platform === "darwin" && process.arch === "x64") {
189
+ return "darwin-x64";
190
+ }
191
+ if (process.platform === "darwin" && process.arch === "arm64") {
192
+ return "darwin-arm64";
193
+ }
194
+ return null;
195
+ }
196
+
197
+ function findPackagedBrowserRuntime() {
198
+ const roots = [
199
+ path.join(runtimesDir, "browser"),
200
+ path.join(runtimesDir, "chrome"),
201
+ path.join(runtimesDir, "chromium")
202
+ ];
203
+ const executableNames = process.platform === "win32"
204
+ ? new Set(["chrome.exe", "chromium.exe", "msedge.exe"])
205
+ : new Set(["chrome", "chromium"]);
206
+ for (const root of roots) {
207
+ const found = findFirstExecutable(root, executableNames, 5);
208
+ if (found) {
209
+ return found;
210
+ }
211
+ }
212
+ return null;
213
+ }
214
+
215
+ function findFirstExecutable(root, executableNames, maxDepth) {
216
+ if (!fs.existsSync(root) || maxDepth < 0) {
217
+ return null;
218
+ }
219
+ let entries;
220
+ try {
221
+ entries = fs.readdirSync(root, { withFileTypes: true });
222
+ } catch {
223
+ return null;
224
+ }
225
+ for (const entry of entries) {
226
+ const entryPath = path.join(root, entry.name);
227
+ if (entry.isFile() && executableNames.has(entry.name)) {
228
+ return entryPath;
229
+ }
230
+ }
231
+ for (const entry of entries) {
232
+ if (!entry.isDirectory()) {
233
+ continue;
234
+ }
235
+ const found = findFirstExecutable(path.join(root, entry.name), executableNames, maxDepth - 1);
236
+ if (found) {
237
+ return found;
238
+ }
239
+ }
240
+ return null;
241
+ }
242
+
243
+ function extractRuntimeArchive(archivePath) {
244
+ const result = spawnSync("tar", ["-xzf", archivePath, "-C", packageRoot], {
245
+ cwd: packageRoot,
246
+ encoding: "utf8",
247
+ stdio: ["ignore", "pipe", "pipe"],
248
+ windowsHide: true,
249
+ timeout: 600_000
250
+ });
251
+ if (result.status !== 0) {
252
+ throw new Error(`Failed to extract runtime archive: ${result.stderr || result.stdout || result.error?.message || `status ${result.status}`}`);
253
+ }
254
+ }
255
+
256
+ function assertSha256(filePath, expectedSha256) {
257
+ const hash = crypto.createHash("sha256");
258
+ hash.update(fs.readFileSync(filePath));
259
+ const actual = hash.digest("hex");
260
+ if (actual.toLowerCase() !== String(expectedSha256).toLowerCase()) {
261
+ throw new Error(`Runtime archive checksum mismatch: expected ${expectedSha256}, got ${actual}`);
262
+ }
263
+ }
264
+
265
+ function downloadRuntimeArchive(url) {
266
+ return new Promise((resolve, reject) => {
267
+ if (!url) {
268
+ reject(new Error("Runtime URL is empty."));
269
+ return;
270
+ }
271
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "aib-runtime-"));
272
+ const targetPath = path.join(tempDir, path.basename(new URL(url).pathname) || "runtime.tgz");
273
+ const file = fs.createWriteStream(targetPath);
274
+ const client = url.startsWith("https:") ? https : http;
275
+ const request = client.get(url, (response) => {
276
+ if (response.statusCode && response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
277
+ file.close();
278
+ fs.rmSync(targetPath, { force: true });
279
+ downloadRuntimeArchive(new URL(response.headers.location, url).toString()).then(resolve, reject);
280
+ return;
281
+ }
282
+ if (response.statusCode !== 200) {
283
+ file.close();
284
+ fs.rmSync(targetPath, { force: true });
285
+ reject(new Error(`Runtime download failed with HTTP ${response.statusCode}: ${url}`));
286
+ return;
287
+ }
288
+ response.pipe(file);
289
+ file.on("finish", () => {
290
+ file.close(() => resolve(targetPath));
291
+ });
292
+ });
293
+ request.on("error", (error) => {
294
+ file.close();
295
+ fs.rmSync(targetPath, { force: true });
296
+ reject(error);
297
+ });
298
+ });
299
+ }