@cabane/companion 0.6.159 → 0.6.160

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/dist/launch.js CHANGED
@@ -6,23 +6,13 @@ import { pathToFileURL } from "url";
6
6
  // src/cabane-command.ts
7
7
  import { accessSync, constants, realpathSync as realpathSync2 } from "fs";
8
8
  import { homedir as homedir3 } from "os";
9
- import { delimiter, join as join2, sep as sep2 } from "path";
9
+ import { basename, delimiter, dirname as dirname2, join as join2, sep as sep2 } from "path";
10
10
 
11
- // src/bundled-binaries.ts
12
- import { realpathSync, statSync } from "fs";
13
- import { createRequire } from "module";
11
+ // src/install-kind.ts
12
+ import { realpathSync } from "fs";
14
13
  import { homedir } from "os";
15
14
  import { dirname, join, sep } from "path";
16
15
  import { fileURLToPath } from "url";
17
- var CODEX_CLI = "@openai/codex";
18
- var CODEX_PACKAGE_BY_TRIPLE = {
19
- "x86_64-unknown-linux-musl": `${CODEX_CLI}-linux-x64`,
20
- "aarch64-unknown-linux-musl": `${CODEX_CLI}-linux-arm64`,
21
- "x86_64-apple-darwin": `${CODEX_CLI}-darwin-x64`,
22
- "aarch64-apple-darwin": `${CODEX_CLI}-darwin-arm64`,
23
- "x86_64-pc-windows-msvc": `${CODEX_CLI}-win32-x64`,
24
- "aarch64-pc-windows-msvc": `${CODEX_CLI}-win32-arm64`
25
- };
26
16
 
27
17
  // src/cli-entry.ts
28
18
  import { existsSync } from "fs";
@@ -33,6 +23,9 @@ import { createInterface } from "readline";
33
23
  import { homedir as homedir2 } from "os";
34
24
  import pc from "picocolors";
35
25
 
26
+ // src/cabane-command.ts
27
+ var VERSIONS_SEGMENT = `${sep2}.cabane${sep2}versions${sep2}`;
28
+
36
29
  // src/config.ts
37
30
  import {
38
31
  chmodSync,
@@ -44,7 +37,7 @@ import {
44
37
  existsSync as existsSync2
45
38
  } from "fs";
46
39
  import { homedir as homedir4, userInfo } from "os";
47
- import { dirname as dirname2, join as join3 } from "path";
40
+ import { dirname as dirname3, join as join3 } from "path";
48
41
  import { z as z2 } from "zod";
49
42
 
50
43
  // src/pairing.ts
@@ -287,13 +280,13 @@ import {
287
280
  rmSync as rmSync2,
288
281
  symlinkSync
289
282
  } from "fs";
290
- import { dirname as dirname3, join as join4 } from "path";
283
+ import { dirname as dirname4, join as join4 } from "path";
291
284
  import { fileURLToPath as fileURLToPath3 } from "url";
292
285
  function currentLink() {
293
286
  return join4(cabaneDir(), "current");
294
287
  }
295
288
  function ownPackageRoot(moduleUrl = import.meta.url) {
296
- return dirname3(dirname3(fileURLToPath3(moduleUrl)));
289
+ return dirname4(dirname4(fileURLToPath3(moduleUrl)));
297
290
  }
298
291
  function packageVersion(root) {
299
292
  try {
@@ -313,7 +306,7 @@ function currentRoot() {
313
306
  }
314
307
  function pointCurrentAt(root) {
315
308
  const link = currentLink();
316
- mkdirSync2(dirname3(link), { recursive: true });
309
+ mkdirSync2(dirname4(link), { recursive: true });
317
310
  const fresh = `${link}.${process.pid}.${Date.now()}`;
318
311
  symlinkSync(root, fresh);
319
312
  try {
@@ -1,23 +1,13 @@
1
1
  // src/cabane-command.ts
2
2
  import { accessSync, constants, realpathSync as realpathSync2 } from "fs";
3
3
  import { homedir as homedir3 } from "os";
4
- import { delimiter, join as join2, sep as sep2 } from "path";
4
+ import { basename, delimiter, dirname as dirname2, join as join2, sep as sep2 } from "path";
5
5
 
6
- // src/bundled-binaries.ts
7
- import { realpathSync, statSync } from "fs";
8
- import { createRequire } from "module";
6
+ // src/install-kind.ts
7
+ import { realpathSync } from "fs";
9
8
  import { homedir } from "os";
10
9
  import { dirname, join, sep } from "path";
11
10
  import { fileURLToPath } from "url";
12
- var CODEX_CLI = "@openai/codex";
13
- var CODEX_PACKAGE_BY_TRIPLE = {
14
- "x86_64-unknown-linux-musl": `${CODEX_CLI}-linux-x64`,
15
- "aarch64-unknown-linux-musl": `${CODEX_CLI}-linux-arm64`,
16
- "x86_64-apple-darwin": `${CODEX_CLI}-darwin-x64`,
17
- "aarch64-apple-darwin": `${CODEX_CLI}-darwin-arm64`,
18
- "x86_64-pc-windows-msvc": `${CODEX_CLI}-win32-x64`,
19
- "aarch64-pc-windows-msvc": `${CODEX_CLI}-win32-arm64`
20
- };
21
11
  function companionInstall(execPath = process.execPath, home = homedir()) {
22
12
  const real = (path) => {
23
13
  try {
@@ -55,15 +45,27 @@ function tildePath(path, home = homedir2()) {
55
45
  }
56
46
 
57
47
  // src/cabane-command.ts
48
+ var INVOKED_COMMAND_ENV = "CABANE_INVOKED_COMMAND";
49
+ var VERSIONS_SEGMENT = `${sep2}.cabane${sep2}versions${sep2}`;
58
50
  function installedCommandPath(deps = {}) {
59
51
  const install = deps.install ?? companionInstall();
60
52
  const home = deps.home ?? homedir3();
61
53
  if (install === "script") return join2(home, ".cabane", "bin", "cabane");
62
54
  const entry = deps.cliEntry ?? companionCliEntry();
55
+ const own = npmBinFor(entry);
56
+ if (own) return own;
57
+ if (!entry.includes(VERSIONS_SEGMENT)) return null;
58
+ const isExecutable = deps.isExecutable ?? executable;
59
+ const invoked = "invoked" in deps ? deps.invoked : process.env[INVOKED_COMMAND_ENV];
60
+ if (invoked && isExecutable(invoked)) return invoked;
61
+ const besideNode = join2(dirname2(dirname2(deps.execPath ?? process.execPath)), "bin", "cabane");
62
+ return isExecutable(besideNode) ? besideNode : null;
63
+ }
64
+ function npmBinFor(path) {
63
65
  const marker = `${sep2}lib${sep2}node_modules${sep2}@cabane${sep2}companion${sep2}`;
64
- const at = entry.indexOf(marker);
66
+ const at = path.indexOf(marker);
65
67
  if (at < 0) return null;
66
- return join2(entry.slice(0, at), "bin", "cabane");
68
+ return join2(path.slice(0, at), "bin", "cabane");
67
69
  }
68
70
  function cabaneCommand(deps = {}) {
69
71
  const own = installedCommandPath(deps);
@@ -114,7 +116,7 @@ import {
114
116
  existsSync as existsSync2
115
117
  } from "fs";
116
118
  import { homedir as homedir4, userInfo } from "os";
117
- import { dirname as dirname2, join as join3 } from "path";
119
+ import { dirname as dirname3, join as join3 } from "path";
118
120
  import { z as z2 } from "zod";
119
121
 
120
122
  // src/errors.ts
@@ -488,7 +490,7 @@ function loadConfigTolerant() {
488
490
  }
489
491
  function saveConfig(cfg) {
490
492
  const path = configPath();
491
- mkdirSync(dirname2(path), { recursive: true });
493
+ mkdirSync(dirname3(path), { recursive: true });
492
494
  try {
493
495
  chmodSync(cabaneDir(), 448);
494
496
  } catch {
@@ -1,14 +1,134 @@
1
1
  // src/bundled-binaries.ts
2
- import { realpathSync, statSync } from "fs";
2
+ import { realpathSync as realpathSync3, statSync } from "fs";
3
3
  import { createRequire } from "module";
4
+ import { dirname as dirname3, join as join3 } from "path";
5
+ import { fileURLToPath as fileURLToPath3 } from "url";
6
+
7
+ // src/cabane-command.ts
8
+ import { accessSync, constants, realpathSync as realpathSync2 } from "fs";
9
+ import { homedir as homedir3 } from "os";
10
+ import { basename, delimiter, dirname as dirname2, join as join2, sep as sep2 } from "path";
11
+
12
+ // src/install-kind.ts
13
+ import { realpathSync } from "fs";
4
14
  import { homedir } from "os";
5
15
  import { dirname, join, sep } from "path";
6
16
  import { fileURLToPath } from "url";
17
+ var INSTALL_SCRIPT_COMMAND = "curl -fsSL https://cabane.ai/install.sh | bash";
18
+ function companionInstall(execPath = process.execPath, home = homedir()) {
19
+ const real = (path) => {
20
+ try {
21
+ return realpathSync(path);
22
+ } catch {
23
+ return path;
24
+ }
25
+ };
26
+ const scriptNode = join(real(home), ".cabane", "node") + sep;
27
+ return real(execPath).startsWith(scriptNode) ? "script" : "npm";
28
+ }
29
+ function repairRoute(packageRoot = ownRoot(), install = companionInstall()) {
30
+ let root = packageRoot;
31
+ try {
32
+ root = realpathSync(packageRoot);
33
+ } catch {
34
+ }
35
+ return root.includes(`${sep}.cabane${sep}versions${sep}`) ? "managed" : install;
36
+ }
37
+ function ownRoot() {
38
+ return dirname(dirname(fileURLToPath(import.meta.url)));
39
+ }
40
+
41
+ // src/cli-entry.ts
42
+ import { existsSync } from "fs";
43
+ import { fileURLToPath as fileURLToPath2 } from "url";
44
+ var RELATIVE_CANDIDATES = ["./cli.js", "../dist/cli.js", "../cli.js"];
45
+ function companionCliEntry(deps = {}) {
46
+ const exists = deps.exists ?? existsSync;
47
+ const candidates = deps.candidates ?? RELATIVE_CANDIDATES.map((rel) => fileURLToPath2(new URL(rel, import.meta.url)));
48
+ for (const candidate of candidates) {
49
+ if (exists(candidate)) return candidate;
50
+ }
51
+ const argv1 = "argv1" in deps ? deps.argv1 : process.argv[1];
52
+ if (argv1 && exists(argv1)) return argv1;
53
+ return candidates[0] ?? "";
54
+ }
55
+
56
+ // src/term.ts
57
+ import { createInterface } from "readline";
58
+ import { homedir as homedir2 } from "os";
59
+ import pc from "picocolors";
60
+ function tildePath(path, home = homedir2()) {
61
+ if (home && path.startsWith(home + "/")) return `~${path.slice(home.length)}`;
62
+ return path;
63
+ }
64
+
65
+ // src/cabane-command.ts
66
+ var INVOKED_COMMAND_ENV = "CABANE_INVOKED_COMMAND";
67
+ var VERSIONS_SEGMENT = `${sep2}.cabane${sep2}versions${sep2}`;
68
+ function installedCommandPath(deps = {}) {
69
+ const install = deps.install ?? companionInstall();
70
+ const home = deps.home ?? homedir3();
71
+ if (install === "script") return join2(home, ".cabane", "bin", "cabane");
72
+ const entry = deps.cliEntry ?? companionCliEntry();
73
+ const own = npmBinFor(entry);
74
+ if (own) return own;
75
+ if (!entry.includes(VERSIONS_SEGMENT)) return null;
76
+ const isExecutable = deps.isExecutable ?? executable;
77
+ const invoked = "invoked" in deps ? deps.invoked : process.env[INVOKED_COMMAND_ENV];
78
+ if (invoked && isExecutable(invoked)) return invoked;
79
+ const besideNode = join2(dirname2(dirname2(deps.execPath ?? process.execPath)), "bin", "cabane");
80
+ return isExecutable(besideNode) ? besideNode : null;
81
+ }
82
+ function npmBinFor(path) {
83
+ const marker = `${sep2}lib${sep2}node_modules${sep2}@cabane${sep2}companion${sep2}`;
84
+ const at = path.indexOf(marker);
85
+ if (at < 0) return null;
86
+ return join2(path.slice(0, at), "bin", "cabane");
87
+ }
88
+ function cabaneCommand(deps = {}) {
89
+ const own = installedCommandPath(deps);
90
+ if (!own) return "cabane";
91
+ const realpath = deps.realpath ?? safeRealpath;
92
+ const isExecutable = deps.isExecutable ?? executable;
93
+ const ownReal = realpath(own);
94
+ if (!ownReal) return "cabane";
95
+ const onPath = firstOnPath("cabane", "path" in deps ? deps.path : process.env.PATH, isExecutable);
96
+ if (onPath && realpath(onPath) === ownReal) return "cabane";
97
+ return tildePath(own, deps.home);
98
+ }
99
+ function cabane(rest, deps) {
100
+ return `${cabaneCommand(deps)} ${rest}`;
101
+ }
102
+ function firstOnPath(name, path, isExecutable = executable) {
103
+ for (const dir of (path ?? "").split(delimiter)) {
104
+ if (!dir) continue;
105
+ const candidate = join2(dir, name);
106
+ if (isExecutable(candidate)) return candidate;
107
+ }
108
+ return null;
109
+ }
110
+ function executable(path) {
111
+ try {
112
+ accessSync(path, constants.X_OK);
113
+ return true;
114
+ } catch {
115
+ return false;
116
+ }
117
+ }
118
+ function safeRealpath(path) {
119
+ try {
120
+ return realpathSync2(path);
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
125
+
126
+ // src/bundled-binaries.ts
7
127
  function nodeResolveSelf(specifier) {
8
- const here = fileURLToPath(import.meta.url);
128
+ const here = fileURLToPath3(import.meta.url);
9
129
  if (typeof import.meta.resolve === "function") {
10
130
  try {
11
- return fileURLToPath(import.meta.resolve(specifier));
131
+ return fileURLToPath3(import.meta.resolve(specifier));
12
132
  } catch {
13
133
  }
14
134
  }
@@ -19,17 +139,17 @@ function nodeResolveSelf(specifier) {
19
139
  return walkNodeModules(specifier, here);
20
140
  }
21
141
  function walkNodeModules(pkg, fromPath) {
22
- let dir = dirname(fromPath);
142
+ let dir = dirname3(fromPath);
23
143
  for (; ; ) {
24
- const manifest = join(dir, "node_modules", pkg, "package.json");
144
+ const manifest = join3(dir, "node_modules", pkg, "package.json");
25
145
  if (nodeIsFile(manifest)) {
26
146
  try {
27
- return realpathSync(manifest);
147
+ return realpathSync3(manifest);
28
148
  } catch {
29
149
  return manifest;
30
150
  }
31
151
  }
32
- const parent = dirname(dir);
152
+ const parent = dirname3(dir);
33
153
  if (parent === dir) return null;
34
154
  dir = parent;
35
155
  }
@@ -91,7 +211,7 @@ function resolveClaude(env) {
91
211
  const manifest = env.resolve(`${pkg}/package.json`, sdkEntry);
92
212
  if (!manifest) continue;
93
213
  sawPackage ??= pkg;
94
- const exe = join(dirname(manifest), env.platform === "win32" ? "claude.exe" : "claude");
214
+ const exe = join3(dirname3(manifest), env.platform === "win32" ? "claude.exe" : "claude");
95
215
  if (env.isFile(exe)) {
96
216
  return { ...base, packageName: pkg, status: "present", path: exe };
97
217
  }
@@ -142,13 +262,13 @@ function resolveCodex(env) {
142
262
  if (!cliManifest) return { ...base, status: "platform_package_missing", path: null };
143
263
  const platformManifest = env.resolve(`${pkg}/package.json`, cliManifest);
144
264
  if (!platformManifest) return { ...base, status: "platform_package_missing", path: null };
145
- const packageRoot = join(dirname(platformManifest), "vendor", triple);
265
+ const packageRoot = join3(dirname3(platformManifest), "vendor", triple);
146
266
  const exeName = env.platform === "win32" ? "codex.exe" : "codex";
147
- const current = join(packageRoot, "bin", exeName);
148
- if (env.isFile(current) && env.isFile(join(packageRoot, "codex-package.json"))) {
267
+ const current = join3(packageRoot, "bin", exeName);
268
+ if (env.isFile(current) && env.isFile(join3(packageRoot, "codex-package.json"))) {
149
269
  return { ...base, status: "present", path: current };
150
270
  }
151
- const legacy = join(packageRoot, "codex", exeName);
271
+ const legacy = join3(packageRoot, "codex", exeName);
152
272
  if (env.isFile(legacy)) return { ...base, status: "present", path: legacy };
153
273
  return { ...base, status: "executable_missing", path: null };
154
274
  }
@@ -179,24 +299,17 @@ var HARNESS_LABEL = {
179
299
  function missingNoun(status) {
180
300
  return status === "executable_missing" ? "executable" : "platform package";
181
301
  }
182
- var INSTALL_SCRIPT_COMMAND = "curl -fsSL https://cabane.ai/install.sh | bash";
183
- function companionInstall(execPath = process.execPath, home = homedir()) {
184
- const real = (path) => {
185
- try {
186
- return realpathSync(path);
187
- } catch {
188
- return path;
189
- }
190
- };
191
- const scriptNode = join(real(home), ".cabane", "node") + sep;
192
- return real(execPath).startsWith(scriptNode) ? "script" : "npm";
193
- }
194
- function repairCommands(install = companionInstall()) {
195
- return install === "script" ? [INSTALL_SCRIPT_COMMAND] : ["npm i -g @cabane/companion --include=optional"];
302
+ function repairCommands(route = repairRoute(), spell = cabane) {
303
+ if (route === "managed") return [spell("stop"), spell("update")];
304
+ if (route === "script") return [spell("stop"), INSTALL_SCRIPT_COMMAND];
305
+ return ["npm i -g @cabane/companion --include=optional"];
196
306
  }
197
- function repairAction(install = companionInstall()) {
198
- return `Reinstall with \`${repairCommands(install)[0]}\`.`;
307
+ function repairAction(route = repairRoute(), spell = cabane) {
308
+ const [first, ...rest] = repairCommands(route, spell);
309
+ if (rest.length === 0) return `Reinstall with \`${first}\`.`;
310
+ return `Run \`${first}\`, then \`${rest.join("`, then `")}\`. ${STOP_WARNING}`;
199
311
  }
312
+ var STOP_WARNING = "Stopping ends any turn in progress.";
200
313
  function installWarning(r) {
201
314
  return `warning: @cabane/companion is incomplete: its bundled ${HARNESS_LABEL[r.runtime]} ${missingNoun(r.status)} for ${r.platform}-${r.arch} is missing. ${repairAction()}`;
202
315
  }