@taco-ai/cli 0.1.1 → 0.2.0
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 +39 -12
- package/dist/taco.mjs +34 -32
- package/lib/installHelpers.ts +66 -30
- package/lib/installId.ts +27 -2
- package/lib/sidecarLauncher.ts +41 -6
- package/lib/start.ts +148 -69
- package/lib/status.ts +5 -57
- package/lib/stop.ts +9 -64
- package/lib/upgradePlatform.ts +21 -0
- package/package.json +4 -3
package/lib/stop.ts
CHANGED
|
@@ -9,75 +9,18 @@
|
|
|
9
9
|
* packages/sidecar/src/index.ts). If it lingers past the deadline, we
|
|
10
10
|
* report that the daemon accepted shutdown but the cleanup is taking longer
|
|
11
11
|
* than expected — operator-visible rather than silently broken.
|
|
12
|
+
*
|
|
13
|
+
* Wire format + retry behaviour live in `@taco-ai/shared/controlNode` so
|
|
14
|
+
* `taco status` and any future control-socket client share a single impl.
|
|
12
15
|
*/
|
|
13
16
|
|
|
14
|
-
import {
|
|
17
|
+
import { existsSync } from "node:fs";
|
|
18
|
+
import { controlRequest } from "@taco-ai/shared/controlNode";
|
|
15
19
|
import { controlSocketPath } from "./paths.ts";
|
|
16
20
|
|
|
17
21
|
const SHUTDOWN_ACK_TIMEOUT_MS = 3_000;
|
|
18
22
|
const SOCKET_GONE_TIMEOUT_MS = 3_000;
|
|
19
23
|
|
|
20
|
-
interface ControlReplyOk {
|
|
21
|
-
result: unknown;
|
|
22
|
-
id: number;
|
|
23
|
-
}
|
|
24
|
-
interface ControlReplyErr {
|
|
25
|
-
error: { code: string; message: string };
|
|
26
|
-
id: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function sendControlRequest(socketPath: string, method: string): Promise<unknown> {
|
|
30
|
-
return new Promise((resolve, reject) => {
|
|
31
|
-
const sock: Socket = connect(socketPath);
|
|
32
|
-
let buf = "";
|
|
33
|
-
let done = false;
|
|
34
|
-
const finish = (fn: () => void) => {
|
|
35
|
-
if (done) return;
|
|
36
|
-
done = true;
|
|
37
|
-
sock.destroy();
|
|
38
|
-
fn();
|
|
39
|
-
};
|
|
40
|
-
const timer = setTimeout(() => {
|
|
41
|
-
finish(() =>
|
|
42
|
-
reject(new Error(`${method} timed out after ${SHUTDOWN_ACK_TIMEOUT_MS}ms`)),
|
|
43
|
-
);
|
|
44
|
-
}, SHUTDOWN_ACK_TIMEOUT_MS);
|
|
45
|
-
|
|
46
|
-
sock.once("error", (err) => {
|
|
47
|
-
clearTimeout(timer);
|
|
48
|
-
finish(() => reject(new Error(`${method}: ${err.message}`)));
|
|
49
|
-
});
|
|
50
|
-
sock.once("connect", () => {
|
|
51
|
-
sock.write(`${JSON.stringify({ method, id: 1 })}\n`);
|
|
52
|
-
});
|
|
53
|
-
sock.on("data", (chunk) => {
|
|
54
|
-
buf += chunk.toString("utf8");
|
|
55
|
-
const nl = buf.indexOf("\n");
|
|
56
|
-
if (nl < 0) return;
|
|
57
|
-
const line = buf.slice(0, nl);
|
|
58
|
-
clearTimeout(timer);
|
|
59
|
-
try {
|
|
60
|
-
const reply = JSON.parse(line) as ControlReplyOk | ControlReplyErr;
|
|
61
|
-
if ("error" in reply) {
|
|
62
|
-
finish(() =>
|
|
63
|
-
reject(new Error(`${method}: ${reply.error.code} ${reply.error.message}`)),
|
|
64
|
-
);
|
|
65
|
-
} else {
|
|
66
|
-
finish(() => resolve(reply.result));
|
|
67
|
-
}
|
|
68
|
-
} catch (err) {
|
|
69
|
-
finish(() => reject(new Error(`${method}: malformed reply: ${String(err)}`)));
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
sock.on("close", () => {
|
|
73
|
-
clearTimeout(timer);
|
|
74
|
-
if (!done) {
|
|
75
|
-
finish(() => reject(new Error(`${method}: socket closed before reply`)));
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
24
|
async function waitForSocketGone(path: string): Promise<void> {
|
|
82
25
|
const start = Date.now();
|
|
83
26
|
while (Date.now() - start < SOCKET_GONE_TIMEOUT_MS) {
|
|
@@ -88,7 +31,7 @@ async function waitForSocketGone(path: string): Promise<void> {
|
|
|
88
31
|
// the listener has shut down so subsequent connect attempts will fail.
|
|
89
32
|
let exists = true;
|
|
90
33
|
try {
|
|
91
|
-
exists =
|
|
34
|
+
exists = existsSync(path);
|
|
92
35
|
} catch {
|
|
93
36
|
exists = false;
|
|
94
37
|
}
|
|
@@ -100,7 +43,9 @@ async function waitForSocketGone(path: string): Promise<void> {
|
|
|
100
43
|
|
|
101
44
|
export async function stopCommand(): Promise<void> {
|
|
102
45
|
const control = controlSocketPath();
|
|
103
|
-
const result = await
|
|
46
|
+
const result = await controlRequest(control, "control.shutdown", {
|
|
47
|
+
timeoutMs: SHUTDOWN_ACK_TIMEOUT_MS,
|
|
48
|
+
});
|
|
104
49
|
// Daemon flushes the reply, then unlinks + exits. Give it a moment to
|
|
105
50
|
// actually disappear from the filesystem before declaring success.
|
|
106
51
|
await waitForSocketGone(control);
|
package/lib/upgradePlatform.ts
CHANGED
|
@@ -16,6 +16,21 @@ export const PLATFORM_KEYS = [
|
|
|
16
16
|
|
|
17
17
|
export type PlatformKey = (typeof PLATFORM_KEYS)[number];
|
|
18
18
|
|
|
19
|
+
/** Node platform-arch key → Rust target triple, naming the `dist/runtime/<triple>/`
|
|
20
|
+
* directory `buildRuntime.mjs` emits. Mirrors `FROM_PROCESS` in
|
|
21
|
+
* `packages/sidecar/scripts/triple.mjs`; duplicated rather than imported because
|
|
22
|
+
* the CLI must not reach into the sidecar's scripts/ dir. The `Record<PlatformKey, …>`
|
|
23
|
+
* type is load-bearing: adding a platform to PLATFORM_KEYS without a triple here
|
|
24
|
+
* becomes a compile error instead of a runtime `undefined` path. */
|
|
25
|
+
const TRIPLE_BY_KEY: Record<PlatformKey, string> = {
|
|
26
|
+
"darwin-arm64": "aarch64-apple-darwin",
|
|
27
|
+
"darwin-x64": "x86_64-apple-darwin",
|
|
28
|
+
"linux-x64": "x86_64-unknown-linux-gnu",
|
|
29
|
+
"linux-arm64": "aarch64-unknown-linux-gnu",
|
|
30
|
+
"win32-x64": "x86_64-pc-windows-msvc",
|
|
31
|
+
"win32-arm64": "aarch64-pc-windows-msvc",
|
|
32
|
+
};
|
|
33
|
+
|
|
19
34
|
export const PLATFORM_PKG_PREFIX = "@taco-ai/sidecar-";
|
|
20
35
|
|
|
21
36
|
/** npm package name for the current platform, e.g. `@taco-ai/sidecar-darwin-arm64`. */
|
|
@@ -24,6 +39,12 @@ export function currentPlatformPkg(): { key: PlatformKey; pkg: string } {
|
|
|
24
39
|
return { key, pkg: `${PLATFORM_PKG_PREFIX}${key}` };
|
|
25
40
|
}
|
|
26
41
|
|
|
42
|
+
/** Rust target triple for the current host, e.g. `aarch64-apple-darwin`. Names the
|
|
43
|
+
* `packages/sidecar/dist/runtime/<triple>/` tree a dev checkout builds. */
|
|
44
|
+
export function currentTriple(): string {
|
|
45
|
+
return TRIPLE_BY_KEY[currentPlatformKey()];
|
|
46
|
+
}
|
|
47
|
+
|
|
27
48
|
export function currentPlatformKey(): PlatformKey {
|
|
28
49
|
const platform = process.platform;
|
|
29
50
|
const arch = process.arch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taco-ai/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Taco CLI — launcher + daemon supervisor for the sidecar. Wraps @taco-ai/sidecar with user-facing subcommands (start, status, install, upgrade).",
|
|
6
6
|
"type": "module",
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
"node": ">=22"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"tar": "^7.
|
|
25
|
-
"@taco-ai/
|
|
24
|
+
"tar": "^7.5.22",
|
|
25
|
+
"@taco-ai/shared": "0.2.0",
|
|
26
|
+
"@taco-ai/sidecar": "0.2.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/node": "^22.7.0",
|