embedlabs 0.1.0-alpha.11 → 0.1.0-alpha.110
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 +2 -2
- package/bin/install-progress.js +163 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# embedlabs
|
|
2
2
|
|
|
3
|
-
Experimental npm alias for
|
|
3
|
+
Experimental npm alias for EmbedLabs CLI.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm install -g embedlabs@alpha
|
|
7
7
|
embedlabs --help
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
This package forwards to `@kvell007/embed-labs-cli@0.1.0-alpha.
|
|
10
|
+
This package forwards to `@kvell007/embed-labs-cli@0.1.0-alpha.110`.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { arch, platform } from "node:os";
|
|
5
|
+
import { basename, dirname, join } from "node:path";
|
|
6
|
+
|
|
7
|
+
const phase = process.argv[2] ?? "postinstall";
|
|
8
|
+
const target = `${platform()}-${arch()}`;
|
|
9
|
+
if (phase === "preinstall") {
|
|
10
|
+
cleanupWindowsInstallState();
|
|
11
|
+
} else {
|
|
12
|
+
installCommandShim();
|
|
13
|
+
}
|
|
14
|
+
const steps = phase === "preinstall"
|
|
15
|
+
? [
|
|
16
|
+
[5, `install: initializing (${target})`],
|
|
17
|
+
[10, "install: checking platform"],
|
|
18
|
+
[15, "install: resolving packages"],
|
|
19
|
+
[20, "install: preparing dependency graph"],
|
|
20
|
+
[25, "install: downloading packages"],
|
|
21
|
+
[30, "install: downloading packages"],
|
|
22
|
+
[35, "install: extracting packages"],
|
|
23
|
+
[40, "install: extracting packages"],
|
|
24
|
+
[45, "install: preparing CLI"],
|
|
25
|
+
[50, "install: preparing CLI"],
|
|
26
|
+
[55, "install: preparing native bridge"],
|
|
27
|
+
[60, "install: preparing native bridge"],
|
|
28
|
+
[65, "install: preparing command links"],
|
|
29
|
+
[70, "install: preparing command links"],
|
|
30
|
+
[75, "install: waiting for npm"],
|
|
31
|
+
[80, "install: waiting for npm"],
|
|
32
|
+
[84, "install: waiting for npm"]
|
|
33
|
+
]
|
|
34
|
+
: [
|
|
35
|
+
[88, "install: verifying commands"],
|
|
36
|
+
[94, "install: finalizing installation"],
|
|
37
|
+
[100, "install: complete"]
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
for (const [percent, message] of steps) {
|
|
41
|
+
writeProgress(percent, message);
|
|
42
|
+
await sleep(1000);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function writeProgress(percent, message) {
|
|
46
|
+
const line = `[EmbedLabs] ${String(percent).padStart(3, " ")}% ${message}\n`;
|
|
47
|
+
if (process.stdout.isTTY || process.env.EMBEDLABS_INSTALL_NO_TTY === "1") {
|
|
48
|
+
process.stdout.write(line);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
writeFileSync(platform() === "win32" ? "\\\\.\\CONOUT$" : "/dev/tty", line, { flag: "a" });
|
|
53
|
+
} catch {
|
|
54
|
+
process.stdout.write(line);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function cleanupWindowsInstallState() {
|
|
59
|
+
stopOldBridgeProcess();
|
|
60
|
+
deleteLegacyBridgeScheduledTask();
|
|
61
|
+
cleanupOldCommandShims();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function stopOldBridgeProcess() {
|
|
65
|
+
if (platform() !== "win32") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const imageName of ["embed-local-bridge.exe", "embed-local-bridge-fixed.exe"]) {
|
|
69
|
+
spawnSync("taskkill.exe", ["/IM", imageName, "/F"], { stdio: "ignore" });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function deleteLegacyBridgeScheduledTask() {
|
|
74
|
+
if (platform() !== "win32") {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
spawnSync("schtasks.exe", ["/Delete", "/TN", "EmbedLabsLocalBridge", "/F"], { stdio: "ignore" });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function cleanupOldCommandShims() {
|
|
81
|
+
const prefix = process.env.npm_config_prefix;
|
|
82
|
+
if (!prefix) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
for (const candidate of commandShimCandidates(prefix)) {
|
|
86
|
+
const filePath = join(prefix, candidate);
|
|
87
|
+
if (!existsSync(filePath) || !isEmbedLabsShim(filePath)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
rmSync(filePath, { force: true });
|
|
92
|
+
writeProgress(3, `install: removed stale command shim (${basename(filePath)})`);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95
|
+
throw new Error(`stale EmbedLabs command shim is locked: ${filePath}; close running terminals or processes and retry npm install. ${message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function commandShimCandidates(prefix) {
|
|
101
|
+
if (platform() === "win32") {
|
|
102
|
+
return ["embedlabs", "embedlabs.cmd", "embedlabs.ps1", "embedlabs.bat"];
|
|
103
|
+
}
|
|
104
|
+
return [join("bin", "embedlabs")];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isEmbedLabsShim(filePath) {
|
|
108
|
+
try {
|
|
109
|
+
const body = readFileSync(filePath, "utf8").toLowerCase();
|
|
110
|
+
return body.includes("embedlabs")
|
|
111
|
+
&& (
|
|
112
|
+
body.includes("@kvell007\\embed-labs-cli")
|
|
113
|
+
|| body.includes("@kvell007/embed-labs-cli")
|
|
114
|
+
|| body.includes("node_modules\\embedlabs")
|
|
115
|
+
|| body.includes("node_modules/embedlabs")
|
|
116
|
+
|| body.includes("embed-labs-cli")
|
|
117
|
+
);
|
|
118
|
+
} catch {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function installCommandShim() {
|
|
124
|
+
const prefix = process.env.npm_config_prefix;
|
|
125
|
+
if (!prefix) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
cleanupOldCommandShims();
|
|
129
|
+
if (platform() === "win32") {
|
|
130
|
+
const target = join(prefix, "embedlabs.cmd");
|
|
131
|
+
writeFileSync(target, windowsCmdShim(), "utf8");
|
|
132
|
+
writeProgress(90, "install: command ready (embedlabs.cmd)");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const target = join(prefix, "bin", "embedlabs");
|
|
136
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
137
|
+
writeFileSync(target, unixShellShim(), "utf8");
|
|
138
|
+
chmodSync(target, 0o755);
|
|
139
|
+
writeProgress(90, "install: command ready (embedlabs)");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function windowsCmdShim() {
|
|
143
|
+
return [
|
|
144
|
+
"@ECHO off",
|
|
145
|
+
"SETLOCAL",
|
|
146
|
+
"SET \"EMBEDLABS_ALIAS_DIR=%~dp0\"",
|
|
147
|
+
"node \"%EMBEDLABS_ALIAS_DIR%node_modules\\embedlabs\\bin\\embedlabs.js\" %*",
|
|
148
|
+
""
|
|
149
|
+
].join("\r\n");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function unixShellShim() {
|
|
153
|
+
return [
|
|
154
|
+
"#!/bin/sh",
|
|
155
|
+
"basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")",
|
|
156
|
+
"exec node \"$basedir/../lib/node_modules/embedlabs/bin/embedlabs.js\" \"$@\"",
|
|
157
|
+
""
|
|
158
|
+
].join("\n");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function sleep(ms) {
|
|
162
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
163
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "embedlabs",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.110",
|
|
4
|
+
"description": "EmbedLabs CLI alias package for local-first embedded agent testing.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"scripts": {
|
|
8
|
+
"preinstall": "node bin/install-progress.js preinstall",
|
|
9
|
+
"postinstall": "node bin/install-progress.js postinstall"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"bin",
|
|
12
13
|
"README.md"
|
|
13
14
|
],
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"@kvell007/embed-labs-cli": "0.1.0-alpha.
|
|
16
|
+
"@kvell007/embed-labs-cli": "0.1.0-alpha.110"
|
|
16
17
|
},
|
|
17
18
|
"publishConfig": {
|
|
18
19
|
"access": "public",
|