@sma1lboy/kobe 0.8.186 → 0.8.189

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/cli/kobe.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import{join as l}from"node:path";import{createInterface as s}from"node:readline/promises";import{pathToFileURL as r}from"node:url";import{spawnSync as w}from"node:child_process";import{constants as N,accessSync as f}from"node:fs";import{homedir as S}from"node:os";import{basename as y,delimiter as _,dirname as v,join as $}from"node:path";import{fileURLToPath as x}from"node:url";var W="rove",Y="kobe";var A="ROVE_INVOKED_AS";function V(z=process.env){return z[A]===W?W:Y}var U="ROVE_BUN",p="ROVE_NO_BUN_BOOTSTRAP",E=(z)=>{try{return f(z,N.X_OK),!0}catch{return!1}},m=(z)=>z==="win32"?"bun.exe":"bun";function d(z={}){let H=z.env??process.env,J=z.platform??process.platform,Z=z.home??H.HOME??H.USERPROFILE??S(),Q=m(J),X=[],G=H[U]?.trim();if(G)X.push(G);for(let L of(H.PATH??H.Path??"").split(_))if(L)X.push($(L,Q));let j=H.BUN_INSTALL?.trim();if(j)X.push($(j,"bin",Q));if(Z)X.push($(Z,".bun","bin",Q));let q=z.launcherDir;if(q)X.push($(q,"..","..","node_modules","bun","bin",Q)),X.push($(q,"..","..","..","bun","bin",Q));return X}function F(z={}){let H=z.isExecutable??E;return d(z).find((J)=>H(J))??null}function b(z){return v(x(z))}function B(z){return y(x(z)).replace(/\.[cm]?[jt]s$/,"")}function c(z=process.platform){return z==="win32"?["powershell","-NoProfile","-Command","irm bun.sh/install.ps1 | iex"]:["bash","-c","curl -fsSL https://bun.sh/install | bash"]}function D(z=V(),H=process.platform){let J=H==="win32"?'powershell -c "irm bun.sh/install.ps1 | iex"':"curl -fsSL https://bun.sh/install | bash";return[`${z}: Rove runs on the Bun runtime, and no Bun was found on this machine.`,"","Install Bun, then run this command again:",` ${J}`," npm install -g bun # any platform, if you already have npm","","Or install Bun and Rove together in one step:"," curl -fsSL https://rove.sma1lboy.me/install.sh | sh","",`Already have Bun somewhere unusual? Point Rove at it: ${U}=/path/to/bun`,""].join(`
3
- `)}function M(z=process.env,H=process.stdin,J=process.stdout){if(z[p]==="1")return!1;if(z.CI==="true"||z.CI==="1")return!1;return Boolean(H.isTTY&&J.isTTY)}function k(z={},H=w){let J=z.platform??process.platform,[Z,...Q]=c(J);if(!Z)return null;let X=H(Z,Q,{stdio:"inherit"});if(X.error||X.status!==0)return null;return F(z)}function u(z){if(typeof z.status==="number")return z.status;if(z.signal)return 128+(Object.hasOwn(K,z.signal)?K[z.signal]:0);return 1}var K={SIGINT:2,SIGQUIT:3,SIGKILL:9,SIGTERM:15};function C(z,H,J,Z=w){let Q=Z(z,[H,...J],{stdio:"inherit"});if(Q.error)return process.stderr.write(`rove: could not start Bun at ${z}: ${Q.error.message}
4
- `),1;return u(Q)}var T=b(import.meta.url),P=B(import.meta.url),g=l(T,`${P}-run.js`);async function i(z){let H=s({input:process.stdin,output:process.stdout});try{let J=(await H.question(z)).trim().toLowerCase();return J===""||J==="y"||J==="yes"}finally{H.close()}}async function o(){let z={launcherDir:T},H=F(z);if(H)return H;if(!M())return null;let J=`${P}: Rove runs on the Bun runtime, and none is installed. Install Bun now? [Y/n] `;if(!await i(J))return null;return k(z)}if(typeof globalThis.Bun<"u")await import(r(g).href);else{let z=await o();if(!z)process.stderr.write(D(P)),process.exit(1);process.exit(C(z,g,process.argv.slice(2)))}
2
+ import{join as l}from"node:path";import{createInterface as s}from"node:readline/promises";import{pathToFileURL as o}from"node:url";import{spawnSync as U}from"node:child_process";import{constants as f,accessSync as A}from"node:fs";import{homedir as y}from"node:os";import{basename as S,delimiter as _,dirname as p,join as $}from"node:path";import{fileURLToPath as w}from"node:url";var W="rove",Y="kobe";var N="ROVE_INVOKED_AS";function K(z=process.env){return z[N]===W?W:Y}var x="ROVE_BUN",v="ROVE_NO_BUN_BOOTSTRAP",E=(z)=>{try{return A(z,f.X_OK),!0}catch{return!1}},d=(z)=>z==="win32"?"bun.exe":"bun";function m(z={}){let H=z.env??process.env,J=z.platform??process.platform,Z=z.home??H.HOME??H.USERPROFILE??y(),Q=d(J),X=[],G=H[x]?.trim();if(G)X.push(G);for(let L of(H.PATH??H.Path??"").split(_))if(L)X.push($(L,Q));let V=H.BUN_INSTALL?.trim();if(V)X.push($(V,"bin",Q));if(Z)X.push($(Z,".bun","bin",Q));let q=z.launcherDir;if(q)X.push($(q,"..","..","node_modules","bun","bin",Q)),X.push($(q,"..","..","..","bun","bin",Q));return X}function F(z={}){let H=z.isExecutable??E;return m(z).find((J)=>H(J))??null}function b(z){return p(w(z))}function B(z){return S(w(z)).replace(/\.[cm]?[jt]s$/,"")}function c(z=process.platform){return z==="win32"?["powershell","-NoProfile","-Command","irm bun.sh/install.ps1 | iex"]:["bash","-c","curl -fsSL https://bun.sh/install | bash"]}function D(z=K(),H=process.platform){let J=H==="win32"?'powershell -c "irm bun.sh/install.ps1 | iex"':"curl -fsSL https://bun.sh/install | bash";return[`${z}: Rove runs on the Bun runtime, and no Bun was found on this machine.`,"","Install Bun, then run this command again:",` ${J}`," npm install -g bun # any platform, if you already have npm","","Or install Bun and Rove together in one step:"," curl -fsSL https://rove.sma1lboy.me/install.sh | sh","",`Already have Bun somewhere unusual? Point Rove at it: ${x}=/path/to/bun`,""].join(`
3
+ `)}function k(z=process.env,H=process.stdin,J=process.stdout){if(z[v]==="1")return!1;if(z.CI==="true"||z.CI==="1")return!1;return Boolean(H.isTTY&&J.isTTY)}function C(z={},H=U){let J=z.platform??process.platform,[Z,...Q]=c(J);if(!Z)return null;let X=H(Z,Q,{stdio:"inherit"});if(X.error||X.status!==0)return null;return F(z)}function u(z){if(typeof z.status==="number")return z.status;if(z.signal)return 128+(Object.hasOwn(j,z.signal)?j[z.signal]:0);return 1}var j={SIGINT:2,SIGQUIT:3,SIGKILL:9,SIGTERM:15};function M(z,H,J,Z=U){let Q=Z(z,[H,...J],{stdio:"inherit"});if(Q.error)return process.stderr.write(`rove: could not start Bun at ${z}: ${Q.error.message}
4
+ `),1;return u(Q)}var O=b(import.meta.url),P=B(import.meta.url),T=l(O,`${P}-run.js`);async function i(z){let H=s({input:process.stdin,output:process.stdout});try{let J=(await H.question(z)).trim().toLowerCase();return J===""||J==="y"||J==="yes"}finally{H.close()}}async function a(){let z={launcherDir:O},H=F(z);if(H)return H;if(!k())return null;let J=`${P}: Rove runs on the Bun runtime, and none is installed. Install Bun now? [Y/n] `;if(!await i(J))return null;return C(z)}if(typeof globalThis.Bun<"u")await import(o(T).href);else{let z=await a();if(!z)process.stderr.write(D(P)),process.exit(1);process.exit(M(z,T,process.argv.slice(2)))}
@@ -191,18 +191,52 @@ function requireString(payload, key) {
191
191
 
192
192
  // ../kobe-daemon/src/daemon/paths.ts
193
193
  import { createHash } from "node:crypto";
194
+ import { existsSync, readFileSync } from "node:fs";
194
195
  import { homedir, tmpdir } from "node:os";
195
196
  import { join } from "node:path";
196
197
 
197
198
  // ../kobe-daemon/src/compat-env.ts
198
199
  var ROVE_ENV_PREFIX = "ROVE_";
199
200
  var LEGACY_KOBE_ENV_PREFIX = "KOBE_";
201
+ var ROVE_STATE_DIR_BASENAME = ".rove";
200
202
  var COMPAT_STATE_DIR_BASENAME = ".kobe";
201
203
  function readRoveEnv(suffix, env = process.env) {
202
204
  return env[`${ROVE_ENV_PREFIX}${suffix}`] ?? env[`${LEGACY_KOBE_ENV_PREFIX}${suffix}`];
203
205
  }
204
206
 
205
207
  // ../kobe-daemon/src/daemon/paths.ts
208
+ function stateDirs(homeDir) {
209
+ return { canonical: join(homeDir, ROVE_STATE_DIR_BASENAME), legacy: join(homeDir, COMPAT_STATE_DIR_BASENAME) };
210
+ }
211
+ function pidIsLive(pidPath) {
212
+ try {
213
+ const pid = Number.parseInt(readFileSync(pidPath, "utf8").trim(), 10);
214
+ if (!Number.isInteger(pid) || pid <= 1)
215
+ return false;
216
+ process.kill(pid, 0);
217
+ return true;
218
+ } catch {
219
+ return false;
220
+ }
221
+ }
222
+ function runtimePath(homeDir, name, pidName) {
223
+ const { canonical, legacy } = stateDirs(homeDir);
224
+ const canonicalPath = join(canonical, name);
225
+ if (existsSync(canonicalPath))
226
+ return canonicalPath;
227
+ const legacyPath = join(legacy, name);
228
+ if (existsSync(legacyPath) && pidIsLive(join(legacy, pidName)))
229
+ return legacyPath;
230
+ return canonicalPath;
231
+ }
232
+ function runtimeDataPath(homeDir, name) {
233
+ const { canonical, legacy } = stateDirs(homeDir);
234
+ const canonicalPath = join(canonical, name);
235
+ if (existsSync(canonicalPath))
236
+ return canonicalPath;
237
+ const legacyPath = join(legacy, name);
238
+ return existsSync(legacyPath) ? legacyPath : canonicalPath;
239
+ }
206
240
  var SOCKET_PATH_SAFETY_LIMIT = 100;
207
241
  function shortHomeTag(homeDir) {
208
242
  return createHash("sha1").update(homeDir).digest("hex").slice(0, 8);
@@ -231,26 +265,26 @@ function defaultPtyHostSocketPath(homeDir, platform = process.platform) {
231
265
  if (platform === "win32")
232
266
  return windowsPipePath(explicit || homedir(), "pty");
233
267
  if (explicit && explicit.length > 0) {
234
- return fitSocketPath(join(explicit, COMPAT_STATE_DIR_BASENAME, "pty.sock"), explicit, "pty");
268
+ return fitSocketPath(runtimePath(explicit, "pty.sock", "pty.pid"), explicit, "pty");
235
269
  }
236
270
  const runtimeDir = process.env.XDG_RUNTIME_DIR;
237
271
  if (runtimeDir && runtimeDir.length > 0) {
238
272
  return fitSocketPath(join(runtimeDir, "kobe-pty.sock"), runtimeDir, "pty");
239
273
  }
240
274
  const home = homedir();
241
- return fitSocketPath(join(home, COMPAT_STATE_DIR_BASENAME, "pty.sock"), home, "pty");
275
+ return fitSocketPath(runtimePath(home, "pty.sock", "pty.pid"), home, "pty");
242
276
  }
243
277
  function defaultPtyHostPidPath(homeDir = readRoveEnv("HOME_DIR") ?? homedir()) {
244
278
  const override = readRoveEnv("PTY_PID_PATH");
245
279
  if (override && override.length > 0)
246
280
  return override;
247
- return join(homeDir, COMPAT_STATE_DIR_BASENAME, "pty.pid");
281
+ return runtimePath(homeDir, "pty.pid", "pty.pid");
248
282
  }
249
283
  function defaultPtyExitsPath(homeDir = readRoveEnv("HOME_DIR") ?? homedir()) {
250
- return join(homeDir, COMPAT_STATE_DIR_BASENAME, "pty-exits.json");
284
+ return runtimeDataPath(homeDir, "pty-exits.json");
251
285
  }
252
286
  function defaultPtyFreezeDir(homeDir = readRoveEnv("HOME_DIR") ?? homedir()) {
253
- return join(homeDir, COMPAT_STATE_DIR_BASENAME, "pty-sessions");
287
+ return runtimeDataPath(homeDir, "pty-sessions");
254
288
  }
255
289
  // ../kobe-plugin-sdk/dist/contract.js
256
290
  var DAEMON_CHANNELS = [
@@ -286,7 +320,7 @@ function frameToLine(frame) {
286
320
  }
287
321
 
288
322
  // ../kobe-daemon/src/daemon/pty-exit-store.ts
289
- import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
323
+ import { mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
290
324
  import { dirname } from "node:path";
291
325
  var MAX_RECORDS = 50;
292
326
  var TAIL_LINES = 40;
@@ -303,7 +337,7 @@ function plainTail(raw) {
303
337
  }
304
338
  function readPtyExitRecords(path = defaultPtyExitsPath()) {
305
339
  try {
306
- const parsed = JSON.parse(readFileSync(path, "utf8"));
340
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
307
341
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
308
342
  return {};
309
343
  return parsed;
@@ -331,7 +365,7 @@ function recordPtyExit(info, path = defaultPtyExitsPath()) {
331
365
  }
332
366
 
333
367
  // ../kobe-daemon/src/daemon/pty-freeze-store.ts
334
- import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync, renameSync, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
368
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, readdirSync, renameSync, rmSync, writeFileSync as writeFileSync2 } from "node:fs";
335
369
  import { join as join2 } from "node:path";
336
370
  import { StringDecoder } from "node:string_decoder";
337
371
  var FREEZE_VERSION = 1;
@@ -419,7 +453,7 @@ function loadFrozenSessions(dir = defaultPtyFreezeDir()) {
419
453
  if (!name.endsWith(".json"))
420
454
  continue;
421
455
  try {
422
- const record = parseRecord(readFileSync2(join2(dir, name), "utf8"));
456
+ const record = parseRecord(readFileSync3(join2(dir, name), "utf8"));
423
457
  if (record)
424
458
  out.push(record);
425
459
  } catch {}
@@ -451,7 +485,7 @@ function clearFrozenSessions(dir = defaultPtyFreezeDir()) {
451
485
  }
452
486
 
453
487
  // ../kobe-daemon/src/daemon/platform-shell.js
454
- import { existsSync } from "node:fs";
488
+ import { existsSync as existsSync2 } from "node:fs";
455
489
  function windowsBashCandidates(env) {
456
490
  const roots = [env.ProgramFiles, env["ProgramFiles(x86)"], env.LOCALAPPDATA && `${env.LOCALAPPDATA}\\Programs`];
457
491
  return roots.filter(Boolean).map((root) => `${root}\\Git\\bin\\bash.exe`);
@@ -465,7 +499,7 @@ function resolveLoginShell(options = {}) {
465
499
  const fallback = options.fallback ?? "/bin/bash";
466
500
  const platform = options.platform ?? process.platform;
467
501
  const env = options.env ?? process.env;
468
- const exists = options.exists ?? existsSync;
502
+ const exists = options.exists ?? existsSync2;
469
503
  const cacheable = platform === process.platform && env === process.env && options.exists === undefined;
470
504
  if (cacheable) {
471
505
  const hit = cache.get(fallback);