@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.
- package/README.md +578 -0
- package/dist/bin/aib.js +2 -0
- package/dist/bin/cli.js +3 -0
- package/dist/client/http-client.js +1 -0
- package/dist/client/transport-options.js +1 -0
- package/dist/client/websocket-client.js +1 -0
- package/dist/commands/add-missing-imports-preview-cache.js +2 -0
- package/dist/commands/add-missing-imports.js +2 -0
- package/dist/commands/apply-module-plan.js +3 -0
- package/dist/commands/captured-input.js +2 -0
- package/dist/commands/config-command.js +3 -0
- package/dist/commands/diagnostics-command.js +3 -0
- package/dist/commands/doctor.js +1 -0
- package/dist/commands/entity-resolution.js +1 -0
- package/dist/commands/execution-command.js +1 -0
- package/dist/commands/feedback-command.js +3 -0
- package/dist/commands/find-importers.js +1 -0
- package/dist/commands/find-unused-imports.js +1 -0
- package/dist/commands/generate-docs-command.js +6 -0
- package/dist/commands/help-command.js +3 -0
- package/dist/commands/imports-command.js +1 -0
- package/dist/commands/init-skill-usage.js +3 -0
- package/dist/commands/init-workspace.js +3 -0
- package/dist/commands/inspect-cycles.js +5 -0
- package/dist/commands/inspect-format.js +18 -0
- package/dist/commands/inspect-graph.js +9 -0
- package/dist/commands/inspect-imports.js +2 -0
- package/dist/commands/inspect-symbol-query.js +1 -0
- package/dist/commands/inspect-tree.js +5 -0
- package/dist/commands/inspect.js +16 -0
- package/dist/commands/json-file-input.js +1 -0
- package/dist/commands/list-instances.js +1 -0
- package/dist/commands/module-plan-cache.js +2 -0
- package/dist/commands/module-plan-command.js +1 -0
- package/dist/commands/module-plan-timeout.js +1 -0
- package/dist/commands/move-command.js +1 -0
- package/dist/commands/move-preview-cache.js +2 -0
- package/dist/commands/move-to-file.js +2 -0
- package/dist/commands/mutation-execution-cache.js +3 -0
- package/dist/commands/normalize-imports.js +4 -0
- package/dist/commands/observability-command.js +3 -0
- package/dist/commands/ping.js +1 -0
- package/dist/commands/print-config.js +1 -0
- package/dist/commands/quick-read.js +11 -0
- package/dist/commands/refactor-batch-builder.js +1 -0
- package/dist/commands/refactor-batch-execution-cache.js +1 -0
- package/dist/commands/refactor-batch-preview-cache.js +2 -0
- package/dist/commands/refactor-batch.js +4 -0
- package/dist/commands/refactor-command.js +1 -0
- package/dist/commands/rename-command.js +1 -0
- package/dist/commands/rename-entities.js +4 -0
- package/dist/commands/rename-execution-cache.js +1 -0
- package/dist/commands/rename-input.js +1 -0
- package/dist/commands/rename-preview-cache.js +2 -0
- package/dist/commands/result-view.js +6 -0
- package/dist/commands/runtime-command.js +4 -0
- package/dist/commands/runtime-info.js +1 -0
- package/dist/commands/session-workspace.js +31 -0
- package/dist/commands/shared.js +1 -0
- package/dist/commands/sync-command.js +2 -0
- package/dist/commands/validate-module-plan.js +2 -0
- package/dist/commands/workspace-cache.js +1 -0
- package/dist/compatibility/policy.js +1 -0
- package/dist/config/auto-start-ide.js +1 -0
- package/dist/config/defaults.js +1 -0
- package/dist/config/env-vars.js +1 -0
- package/dist/config/glob-match.js +1 -0
- package/dist/config/import-rules.js +1 -0
- package/dist/config/local-config.js +3 -0
- package/dist/config/mutation-comments.js +1 -0
- package/dist/config/path-aliases.js +1 -0
- package/dist/config/path-display.js +1 -0
- package/dist/config/product-storage.js +1 -0
- package/dist/config/resolve-command-alias.js +1 -0
- package/dist/config/resolve.js +1 -0
- package/dist/config/workspace-root.js +3 -0
- package/dist/config/workspace-state.js +1 -0
- package/dist/content/content-bundle.js +1 -0
- package/dist/diagnostics/module-plan-timeline.js +2 -0
- package/dist/diagnostics/readiness-text.js +8 -0
- package/dist/discovery/registry.js +1 -0
- package/dist/discovery/select-instance.js +1 -0
- package/dist/dsl/aib-dsl.js +1 -0
- package/dist/help/bootstrap.md +924 -0
- package/dist/help/diagnostics/doctor.json +70 -0
- package/dist/help/docs/basics.md +14 -0
- package/dist/help/docs/dsl.md +25 -0
- package/dist/help/docs/help-format.md +12 -0
- package/dist/help/docs/imports.normalize.md +36 -0
- package/dist/help/docs/inspect.code.md +29 -0
- package/dist/help/docs/inspect.deps.md +32 -0
- package/dist/help/docs/inspect.duplicates.md +72 -0
- package/dist/help/docs/inspect.exports.md +34 -0
- package/dist/help/docs/inspect.file.md +32 -0
- package/dist/help/docs/inspect.graph.md +112 -0
- package/dist/help/docs/inspect.imports.md +15 -0
- package/dist/help/docs/inspect.md +71 -0
- package/dist/help/docs/inspect.members.md +24 -0
- package/dist/help/docs/inspect.tree.md +30 -0
- package/dist/help/docs/inspect.usages.md +48 -0
- package/dist/help/docs/modulePlan.md +51 -0
- package/dist/help/docs/move.md +37 -0
- package/dist/help/docs/mutation.md +47 -0
- package/dist/help/docs/patterns.md +178 -0
- package/dist/help/docs/prefs.md +40 -0
- package/dist/help/docs/qr.md +33 -0
- package/dist/help/docs/refactor.batch.md +44 -0
- package/dist/help/docs/rename.md +39 -0
- package/dist/help/docs/selectors.md +23 -0
- package/dist/help/docs/session.md +61 -0
- package/dist/help/docs/view.md +30 -0
- package/dist/help/dsl/bootstrap.md +924 -0
- package/dist/help/dsl/docs/basics.md +14 -0
- package/dist/help/dsl/docs/dsl.md +25 -0
- package/dist/help/dsl/docs/help-format.md +12 -0
- package/dist/help/dsl/docs/imports.normalize.md +36 -0
- package/dist/help/dsl/docs/inspect.code.md +29 -0
- package/dist/help/dsl/docs/inspect.deps.md +32 -0
- package/dist/help/dsl/docs/inspect.duplicates.md +72 -0
- package/dist/help/dsl/docs/inspect.exports.md +34 -0
- package/dist/help/dsl/docs/inspect.file.md +32 -0
- package/dist/help/dsl/docs/inspect.graph.md +112 -0
- package/dist/help/dsl/docs/inspect.imports.md +15 -0
- package/dist/help/dsl/docs/inspect.md +71 -0
- package/dist/help/dsl/docs/inspect.members.md +24 -0
- package/dist/help/dsl/docs/inspect.tree.md +30 -0
- package/dist/help/dsl/docs/inspect.usages.md +48 -0
- package/dist/help/dsl/docs/modulePlan.md +51 -0
- package/dist/help/dsl/docs/move.md +37 -0
- package/dist/help/dsl/docs/mutation.md +47 -0
- package/dist/help/dsl/docs/patterns.md +178 -0
- package/dist/help/dsl/docs/prefs.md +40 -0
- package/dist/help/dsl/docs/qr.md +33 -0
- package/dist/help/dsl/docs/refactor.batch.md +44 -0
- package/dist/help/dsl/docs/rename.md +39 -0
- package/dist/help/dsl/docs/selectors.md +23 -0
- package/dist/help/dsl/docs/session.md +61 -0
- package/dist/help/dsl/docs/view.md +30 -0
- package/dist/help/dsl/full.md +924 -0
- package/dist/help/dsl/snippets/agents.md +14 -0
- package/dist/help/dsl/topics/basics.md +12 -0
- package/dist/help/dsl/topics/dsl.md +23 -0
- package/dist/help/dsl/topics/help-format.md +10 -0
- package/dist/help/dsl/topics/imports.normalize.md +34 -0
- package/dist/help/dsl/topics/inspect.code.md +27 -0
- package/dist/help/dsl/topics/inspect.deps.md +30 -0
- package/dist/help/dsl/topics/inspect.duplicates.md +43 -0
- package/dist/help/dsl/topics/inspect.exports.md +32 -0
- package/dist/help/dsl/topics/inspect.file.md +30 -0
- package/dist/help/dsl/topics/inspect.graph.md +110 -0
- package/dist/help/dsl/topics/inspect.imports.md +13 -0
- package/dist/help/dsl/topics/inspect.md +69 -0
- package/dist/help/dsl/topics/inspect.members.md +22 -0
- package/dist/help/dsl/topics/inspect.tree.md +20 -0
- package/dist/help/dsl/topics/inspect.usages.md +46 -0
- package/dist/help/dsl/topics/modulePlan.md +38 -0
- package/dist/help/dsl/topics/move.md +27 -0
- package/dist/help/dsl/topics/mutation.md +45 -0
- package/dist/help/dsl/topics/patterns.md +176 -0
- package/dist/help/dsl/topics/prefs.md +38 -0
- package/dist/help/dsl/topics/qr.md +31 -0
- package/dist/help/dsl/topics/refactor.batch.md +33 -0
- package/dist/help/dsl/topics/rename.md +25 -0
- package/dist/help/dsl/topics/selectors.md +21 -0
- package/dist/help/dsl/topics/session.md +59 -0
- package/dist/help/dsl/topics/view.md +28 -0
- package/dist/help/full.md +924 -0
- package/dist/help/help-meta.json +113 -0
- package/dist/help/index.md +167 -0
- package/dist/help/json/bootstrap.md +1074 -0
- package/dist/help/json/docs/basics.md +15 -0
- package/dist/help/json/docs/dsl.md +25 -0
- package/dist/help/json/docs/help-format.md +12 -0
- package/dist/help/json/docs/imports.normalize.md +47 -0
- package/dist/help/json/docs/inspect.code.md +41 -0
- package/dist/help/json/docs/inspect.deps.md +46 -0
- package/dist/help/json/docs/inspect.duplicates.md +65 -0
- package/dist/help/json/docs/inspect.exports.md +40 -0
- package/dist/help/json/docs/inspect.file.md +38 -0
- package/dist/help/json/docs/inspect.graph.md +139 -0
- package/dist/help/json/docs/inspect.imports.md +15 -0
- package/dist/help/json/docs/inspect.md +87 -0
- package/dist/help/json/docs/inspect.members.md +32 -0
- package/dist/help/json/docs/inspect.tree.md +30 -0
- package/dist/help/json/docs/inspect.usages.md +61 -0
- package/dist/help/json/docs/modulePlan.md +70 -0
- package/dist/help/json/docs/move.md +53 -0
- package/dist/help/json/docs/mutation.md +62 -0
- package/dist/help/json/docs/patterns.md +178 -0
- package/dist/help/json/docs/prefs.md +40 -0
- package/dist/help/json/docs/qr.md +33 -0
- package/dist/help/json/docs/refactor.batch.md +72 -0
- package/dist/help/json/docs/rename.md +47 -0
- package/dist/help/json/docs/selectors.md +23 -0
- package/dist/help/json/docs/session.md +77 -0
- package/dist/help/json/docs/view.md +30 -0
- package/dist/help/json/full.md +1074 -0
- package/dist/help/json/snippets/agents.md +14 -0
- package/dist/help/json/topics/basics.md +13 -0
- package/dist/help/json/topics/dsl.md +23 -0
- package/dist/help/json/topics/help-format.md +10 -0
- package/dist/help/json/topics/imports.normalize.md +45 -0
- package/dist/help/json/topics/inspect.code.md +39 -0
- package/dist/help/json/topics/inspect.deps.md +44 -0
- package/dist/help/json/topics/inspect.duplicates.md +37 -0
- package/dist/help/json/topics/inspect.exports.md +38 -0
- package/dist/help/json/topics/inspect.file.md +36 -0
- package/dist/help/json/topics/inspect.graph.md +137 -0
- package/dist/help/json/topics/inspect.imports.md +13 -0
- package/dist/help/json/topics/inspect.md +85 -0
- package/dist/help/json/topics/inspect.members.md +30 -0
- package/dist/help/json/topics/inspect.tree.md +20 -0
- package/dist/help/json/topics/inspect.usages.md +59 -0
- package/dist/help/json/topics/modulePlan.md +57 -0
- package/dist/help/json/topics/move.md +43 -0
- package/dist/help/json/topics/mutation.md +60 -0
- package/dist/help/json/topics/patterns.md +176 -0
- package/dist/help/json/topics/prefs.md +38 -0
- package/dist/help/json/topics/qr.md +31 -0
- package/dist/help/json/topics/refactor.batch.md +61 -0
- package/dist/help/json/topics/rename.md +42 -0
- package/dist/help/json/topics/selectors.md +21 -0
- package/dist/help/json/topics/session.md +59 -0
- package/dist/help/json/topics/view.md +28 -0
- package/dist/help/snippets/agents.md +14 -0
- package/dist/help/topics/basics.md +12 -0
- package/dist/help/topics/dsl.md +23 -0
- package/dist/help/topics/help-format.md +10 -0
- package/dist/help/topics/imports.normalize.md +34 -0
- package/dist/help/topics/inspect.code.md +27 -0
- package/dist/help/topics/inspect.deps.md +30 -0
- package/dist/help/topics/inspect.duplicates.md +43 -0
- package/dist/help/topics/inspect.exports.md +32 -0
- package/dist/help/topics/inspect.file.md +30 -0
- package/dist/help/topics/inspect.graph.md +110 -0
- package/dist/help/topics/inspect.imports.md +13 -0
- package/dist/help/topics/inspect.md +69 -0
- package/dist/help/topics/inspect.members.md +22 -0
- package/dist/help/topics/inspect.tree.md +20 -0
- package/dist/help/topics/inspect.usages.md +46 -0
- package/dist/help/topics/modulePlan.md +38 -0
- package/dist/help/topics/move.md +27 -0
- package/dist/help/topics/mutation.md +45 -0
- package/dist/help/topics/patterns.md +176 -0
- package/dist/help/topics/prefs.md +38 -0
- package/dist/help/topics/qr.md +31 -0
- package/dist/help/topics/refactor.batch.md +33 -0
- package/dist/help/topics/rename.md +25 -0
- package/dist/help/topics/selectors.md +21 -0
- package/dist/help/topics/session.md +59 -0
- package/dist/help/topics/view.md +28 -0
- package/dist/ide-launch/common.cjs +162 -0
- package/dist/managed-host/extension-vsix-resolver.js +1 -0
- package/dist/managed-host/manage-serve-web-host.cjs +141 -0
- package/dist/managed-host/serve-web-autostart.js +1 -0
- package/dist/managed-host/serve-web-host.cjs +1790 -0
- package/dist/metrics/central-metrics.js +2 -0
- package/dist/observability/config.js +1 -0
- package/dist/observability/context.js +1 -0
- package/dist/observability/failure-snapshot.js +2 -0
- package/dist/observability/recent.js +2 -0
- package/dist/payloads/read-stdin-json.js +1 -0
- package/dist/runtime/bundled-node.js +1 -0
- package/dist/runtime/input-source.js +1 -0
- package/dist/runtime/managed-runtime-provisioning.js +1 -0
- package/dist/runtime/run-command.js +1 -0
- package/dist/selectors/parse-entities.js +1 -0
- package/dist/session/client.js +1 -0
- package/dist/session/paths.js +1 -0
- package/dist/session/server.js +6 -0
- package/dist/shared/agent-text.js +1 -0
- package/dist/shared/diagnostic-catalog.js +1 -0
- package/dist/shared/diagnostics.js +1 -0
- package/dist/shared/errors.js +28 -0
- package/dist/shared/event-loop.js +1 -0
- package/dist/shared/hints.js +1 -0
- package/dist/shared/metrics.js +1 -0
- package/dist/shared/operations.js +1 -0
- package/dist/shared/presentation.js +4 -0
- package/dist/shared/protocol.js +1 -0
- package/dist/shared/routes.js +1 -0
- package/dist/shared/stdout.js +2 -0
- package/dist/shared/types.js +1 -0
- package/dist/tracing/config.js +2 -0
- package/dist/tracing/trace.js +3 -0
- package/extension/vscode-refactor-bridge-extension.vsix +0 -0
- package/package.json +39 -0
- package/runtimes/launcher/win-x64/aib.exe +0 -0
- package/scripts/install-windows-launcher.cjs +58 -0
- package/scripts/postinstall.cjs +28 -0
- 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
|
+
}
|