@sys9/chord-cli 0.1.116 → 0.1.117-darwin-arm64

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/package.json CHANGED
@@ -1,30 +1,22 @@
1
1
  {
2
2
  "name": "@sys9/chord-cli",
3
- "version": "0.1.116",
3
+ "version": "0.1.117-darwin-arm64",
4
4
  "description": "Chord CLI package used by @sys9/cli",
5
5
  "license": "UNLICENSED",
6
+ "os": [
7
+ "darwin"
8
+ ],
9
+ "cpu": [
10
+ "arm64"
11
+ ],
12
+ "files": [
13
+ "vendor"
14
+ ],
6
15
  "repository": {
7
16
  "type": "git",
8
17
  "url": "git+https://github.com/sys9-ai/chord.git"
9
18
  },
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "bin": {
14
- "chord": "bin/chord"
15
- },
16
- "files": [
17
- "README.md",
18
- "bin",
19
- "lib"
20
- ],
21
19
  "engines": {
22
20
  "node": ">=16"
23
- },
24
- "optionalDependencies": {
25
- "@sys9/chord-cli-linux-x64": "npm:@sys9/chord-cli@0.1.116-linux-x64",
26
- "@sys9/chord-cli-linux-arm64": "npm:@sys9/chord-cli@0.1.116-linux-arm64",
27
- "@sys9/chord-cli-darwin-x64": "npm:@sys9/chord-cli@0.1.116-darwin-x64",
28
- "@sys9/chord-cli-darwin-arm64": "npm:@sys9/chord-cli@0.1.116-darwin-arm64"
29
21
  }
30
22
  }
Binary file
package/bin/chord DELETED
@@ -1,197 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- "use strict";
4
-
5
- const { spawn } = require("node:child_process");
6
- const { existsSync } = require("node:fs");
7
- const path = require("node:path");
8
-
9
- const packageJSON = require("../package.json");
10
- const {
11
- resolvePackagedBinaryPath,
12
- resolvePlatformPackageName,
13
- } = require("../lib/platform");
14
-
15
- function detectPackageManager() {
16
- const userAgent = process.env.npm_config_user_agent || "";
17
- if (/\bbun\//.test(userAgent)) {
18
- return "bun";
19
- }
20
-
21
- const execPath = process.env.npm_execpath || "";
22
- if (execPath.includes("bun")) {
23
- return "bun";
24
- }
25
-
26
- if (
27
- __dirname.includes(".bun/install/global") ||
28
- __dirname.includes(".bun\\install\\global")
29
- ) {
30
- return "bun";
31
- }
32
-
33
- return "npm";
34
- }
35
-
36
- function resolveBinaryPath() {
37
- const platformPackage = resolvePlatformPackageName(packageJSON.name);
38
- try {
39
- const packageJSONPath = require.resolve(platformPackage + "/package.json");
40
- return {
41
- binaryPath: resolvePackagedBinaryPath(path.dirname(packageJSONPath)),
42
- platformPackage,
43
- };
44
- } catch {
45
- return {
46
- binaryPath: resolvePackagedBinaryPath(path.join(__dirname, "..")),
47
- platformPackage,
48
- };
49
- }
50
- }
51
-
52
- const updateRequiredExitCode = 75;
53
- const updateFDEnv = "CHORD_CLI_UPDATE_FD";
54
- const updateVersionEnv = "CHORD_CLI_AUTO_UPDATE_VERSION";
55
- const maxUpdateInstructionBytes = 4096;
56
- let child = null;
57
- let receivedSignal = null;
58
-
59
- const forwardSignal = (signal) => {
60
- receivedSignal = signal;
61
- if (!child || child.killed) {
62
- return;
63
- }
64
- try {
65
- child.kill(signal);
66
- } catch {
67
- // Ignore failures while the child is already exiting.
68
- }
69
- };
70
-
71
- ["SIGINT", "SIGTERM", "SIGHUP"].forEach((signal) => {
72
- process.on(signal, () => forwardSignal(signal));
73
- });
74
-
75
- function runChild(command, args, options) {
76
- return new Promise((resolve) => {
77
- let updateInstruction = "";
78
- let settled = false;
79
- const finish = (result) => {
80
- if (settled) {
81
- return;
82
- }
83
- settled = true;
84
- child = null;
85
- resolve(result);
86
- };
87
- child = spawn(command, args, options);
88
- if (child.stdio[3]) {
89
- child.stdio[3].setEncoding("utf8");
90
- child.stdio[3].on("data", (chunk) => {
91
- if (updateInstruction.length <= maxUpdateInstructionBytes) {
92
- updateInstruction += chunk;
93
- }
94
- });
95
- }
96
- child.on("error", (error) => {
97
- finish({ code: 1, signal: null, updateInstruction: "", error });
98
- });
99
- child.on("exit", (code, signal) => {
100
- // A daemon descendant may temporarily retain the update pipe. Once the
101
- // direct child exits after a signal, waiting for every inherited file
102
- // descriptor would keep service shutdown stuck for that descendant's
103
- // lifetime.
104
- if (signal || receivedSignal) {
105
- finish({ code: code ?? 1, signal, updateInstruction, error: null });
106
- }
107
- });
108
- child.on("close", (code, signal) => {
109
- finish({ code: code ?? 1, signal, updateInstruction, error: null });
110
- });
111
- });
112
- }
113
-
114
- function parseUpdateInstruction(raw) {
115
- if (!raw || raw.length > maxUpdateInstructionBytes) {
116
- return null;
117
- }
118
- try {
119
- const instruction = JSON.parse(raw);
120
- const version = instruction && instruction.cli_version;
121
- if (typeof version !== "string" || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(version)) {
122
- return null;
123
- }
124
- return { cliVersion: version };
125
- } catch {
126
- return null;
127
- }
128
- }
129
-
130
- function updateCommand(packageManager, cliVersion, daemonArgs) {
131
- const packageSpec = packageJSON.name + "@" + cliVersion;
132
- if (packageManager === "bun") {
133
- return { command: "bunx", args: [packageSpec, ...daemonArgs] };
134
- }
135
- return { command: "npx", args: ["--yes", packageSpec, ...daemonArgs] };
136
- }
137
-
138
- async function main() {
139
- const { binaryPath, platformPackage } = resolveBinaryPath();
140
- if (!existsSync(binaryPath)) {
141
- const packageManager = detectPackageManager();
142
- const update =
143
- packageManager === "bun"
144
- ? "bun add -g @sys9/chord-cli@latest"
145
- : "npm install -g @sys9/chord-cli@latest";
146
- throw new Error(
147
- "Missing optional dependency " + platformPackage + ". Reinstall chord: " + update,
148
- );
149
- }
150
-
151
- const daemonArgs = process.argv.slice(2);
152
- const result = await runChild(binaryPath, daemonArgs, {
153
- stdio: ["inherit", "inherit", "inherit", "pipe"],
154
- env: { ...process.env, [updateFDEnv]: "3" },
155
- });
156
- if (result.error) {
157
- console.error(result.error);
158
- return result;
159
- }
160
- if (result.signal || receivedSignal) {
161
- return { ...result, signal: result.signal || receivedSignal };
162
- }
163
- if (result.code !== updateRequiredExitCode) {
164
- return result;
165
- }
166
-
167
- const instruction = parseUpdateInstruction(result.updateInstruction);
168
- if (!instruction) {
169
- console.error("Chord daemon requires an update, but the server did not provide a valid CLI version.");
170
- return result;
171
- }
172
- if (process.env[updateVersionEnv] === instruction.cliVersion) {
173
- console.error("Chord daemon automatic update to " + instruction.cliVersion + " was already attempted; update @sys9/chord-cli manually.");
174
- return result;
175
- }
176
-
177
- const packageManager = detectPackageManager();
178
- const update = updateCommand(packageManager, instruction.cliVersion, daemonArgs);
179
- console.error("Chord daemon protocol changed; restarting with @sys9/chord-cli@" + instruction.cliVersion + ".");
180
- const updated = await runChild(update.command, update.args, {
181
- stdio: "inherit",
182
- env: { ...process.env, [updateVersionEnv]: instruction.cliVersion },
183
- });
184
- return { ...updated, signal: updated.signal || receivedSignal };
185
- }
186
-
187
- main().then((result) => {
188
- if (result.signal) {
189
- process.removeAllListeners(result.signal);
190
- process.kill(process.pid, result.signal);
191
- return;
192
- }
193
- process.exit(result.code);
194
- }).catch((error) => {
195
- console.error(error);
196
- process.exit(1);
197
- });
package/lib/platform.js DELETED
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- const path = require("node:path");
4
-
5
- const SUPPORTED_TARGETS = [
6
- {
7
- slug: "linux-x64",
8
- os: "linux",
9
- cpu: "x64",
10
- vendorDir: "linux_amd64",
11
- targetTriple: "x86_64-unknown-linux-musl",
12
- },
13
- {
14
- slug: "linux-arm64",
15
- os: "linux",
16
- cpu: "arm64",
17
- vendorDir: "linux_arm64",
18
- targetTriple: "aarch64-unknown-linux-musl",
19
- },
20
- {
21
- slug: "darwin-x64",
22
- os: "darwin",
23
- cpu: "x64",
24
- vendorDir: "darwin_amd64",
25
- targetTriple: "x86_64-apple-darwin",
26
- },
27
- {
28
- slug: "darwin-arm64",
29
- os: "darwin",
30
- cpu: "arm64",
31
- vendorDir: "darwin_arm64",
32
- targetTriple: "aarch64-apple-darwin",
33
- }
34
- ];
35
-
36
- function resolveSupportedTarget(platform = process.platform, arch = process.arch) {
37
- for (const target of SUPPORTED_TARGETS) {
38
- if (target.os === platform && target.cpu === arch) {
39
- return target;
40
- }
41
- }
42
- throw new Error("unsupported platform: " + platform + " (" + arch + ")");
43
- }
44
-
45
- function resolvePackagedBinaryPath(rootDir, platform = process.platform, arch = process.arch) {
46
- const target = resolveSupportedTarget(platform, arch);
47
- return path.join(rootDir, "vendor", target.vendorDir, "chord");
48
- }
49
-
50
- function resolvePlatformPackageName(rootPackageName, platform = process.platform, arch = process.arch) {
51
- const target = resolveSupportedTarget(platform, arch);
52
- return rootPackageName + "-" + target.slug;
53
- }
54
-
55
- module.exports = {
56
- SUPPORTED_TARGETS,
57
- resolvePackagedBinaryPath,
58
- resolvePlatformPackageName,
59
- resolveSupportedTarget,
60
- };