@zookanalytics/agent-env 0.12.3 → 0.14.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.
Files changed (2) hide show
  1. package/dist/cli.js +583 -230
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -48,16 +48,16 @@ var execute = createExecutor();
48
48
  // src/cli.ts
49
49
  import { program } from "commander";
50
50
  import { render as render3 } from "ink";
51
- import { existsSync } from "fs";
52
- import { homedir as homedir11 } from "os";
53
- import { dirname as dirname5, join as join14, resolve } from "path";
51
+ import { existsSync as existsSync2 } from "fs";
52
+ import { homedir as homedir13 } from "os";
53
+ import { dirname as dirname5, join as join16, resolve } from "path";
54
54
  import { fileURLToPath as fileURLToPath2 } from "url";
55
- import React4 from "react";
55
+ import React5 from "react";
56
56
 
57
57
  // package.json
58
58
  var package_default = {
59
59
  name: "@zookanalytics/agent-env",
60
- version: "0.12.3",
60
+ version: "0.14.0",
61
61
  description: "CLI for creating isolated, AI-ready development environments",
62
62
  type: "module",
63
63
  bin: {
@@ -119,8 +119,8 @@ import { Command } from "commander";
119
119
 
120
120
  // src/lib/attach-instance.ts
121
121
  import { appendFile as appendFile4, mkdir as mkdir6, readdir as readdir5, readFile as readFile8, rename as rename5, stat as stat5, writeFile as writeFile7 } from "fs/promises";
122
- import { homedir as homedir4 } from "os";
123
- import { join as join7 } from "path";
122
+ import { homedir as homedir5 } from "os";
123
+ import { join as join8 } from "path";
124
124
 
125
125
  // src/lib/container.ts
126
126
  var DEVCONTAINER_UP_TIMEOUT = 3e5;
@@ -435,8 +435,8 @@ import {
435
435
  stat as stat4,
436
436
  writeFile as writeFile6
437
437
  } from "fs/promises";
438
- import { homedir as homedir3 } from "os";
439
- import { dirname as dirname2, join as join6 } from "path";
438
+ import { homedir as homedir4 } from "os";
439
+ import { dirname as dirname2, join as join7 } from "path";
440
440
 
441
441
  // src/lib/devcontainer-merge.ts
442
442
  import { parse as parseJsonc2 } from "jsonc-parser";
@@ -465,6 +465,7 @@ import { fileURLToPath } from "url";
465
465
  // src/lib/types.ts
466
466
  var AGENT_ENV_DIR = ".agent-env";
467
467
  var WORKSPACES_DIR = "workspaces";
468
+ var REPOS_DIR = "repos";
468
469
  var STATE_FILE = "state.json";
469
470
  var STATE_FILE_TMP = "state.json.tmp";
470
471
  var CONTAINER_PREFIX = "ae-";
@@ -1526,6 +1527,79 @@ async function setContainerPurpose(value, deps) {
1526
1527
  return { ok: true, cleared, warning };
1527
1528
  }
1528
1529
 
1530
+ // src/lib/repo-env.ts
1531
+ import { copyFile as fsCopyFile, readFile as fsReadFile } from "fs/promises";
1532
+ import { homedir as homedir3 } from "os";
1533
+ import { join as join6 } from "path";
1534
+ var defaultDeps2 = {
1535
+ readFile: fsReadFile,
1536
+ copyFile: fsCopyFile,
1537
+ homedir: homedir3
1538
+ };
1539
+ var VALID_SLUG_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
1540
+ function validateRepoSlug(slug) {
1541
+ if (!slug || !VALID_SLUG_PATTERN.test(slug)) {
1542
+ throw new Error(
1543
+ `Invalid repo slug: "${slug}". Only alphanumeric, dash, dot, and underscore are allowed (must start with alphanumeric).`
1544
+ );
1545
+ }
1546
+ }
1547
+ function getRepoEnvDir(repoSlug, deps = defaultDeps2) {
1548
+ validateRepoSlug(repoSlug);
1549
+ return join6(deps.homedir(), AGENT_ENV_DIR, REPOS_DIR, repoSlug);
1550
+ }
1551
+ function parseEnvFile(content) {
1552
+ const result = {};
1553
+ for (const rawLine of content.split("\n")) {
1554
+ const line = rawLine.trim();
1555
+ if (!line || line.startsWith("#")) continue;
1556
+ const eqIndex = line.indexOf("=");
1557
+ if (eqIndex === -1) continue;
1558
+ const key = line.slice(0, eqIndex).trim();
1559
+ if (!key) continue;
1560
+ let value = line.slice(eqIndex + 1).trim();
1561
+ if (value.length >= 2 && (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'"))) {
1562
+ value = value.slice(1, -1);
1563
+ }
1564
+ result[key] = value;
1565
+ }
1566
+ return result;
1567
+ }
1568
+ async function loadRepoEnv(repoSlug, deps = defaultDeps2) {
1569
+ const dir = getRepoEnvDir(repoSlug, deps);
1570
+ const result = {};
1571
+ for (const filename of [".env", ".env.local"]) {
1572
+ const filePath = join6(dir, filename);
1573
+ try {
1574
+ const content = await deps.readFile(filePath, "utf-8");
1575
+ Object.assign(result, parseEnvFile(content));
1576
+ } catch (error) {
1577
+ if (error.code !== "ENOENT") {
1578
+ throw error;
1579
+ }
1580
+ }
1581
+ }
1582
+ return result;
1583
+ }
1584
+ var ENV_FILES = [".env", ".env.local"];
1585
+ async function copyRepoEnvFiles(repoSlug, destDir, deps = defaultDeps2) {
1586
+ const srcDir = getRepoEnvDir(repoSlug, deps);
1587
+ const copied = [];
1588
+ for (const filename of ENV_FILES) {
1589
+ const src = join6(srcDir, filename);
1590
+ const dest = join6(destDir, filename);
1591
+ try {
1592
+ await deps.copyFile(src, dest);
1593
+ copied.push(filename);
1594
+ } catch (error) {
1595
+ if (error.code !== "ENOENT") {
1596
+ throw error;
1597
+ }
1598
+ }
1599
+ }
1600
+ return copied;
1601
+ }
1602
+
1529
1603
  // src/lib/create-instance.ts
1530
1604
  var VALID_INSTANCE_NAME_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
1531
1605
  function validateCreateInputs(instanceName, purposeText) {
@@ -1611,7 +1685,7 @@ function createDefaultDeps() {
1611
1685
  return {
1612
1686
  executor,
1613
1687
  container: createContainerLifecycle(executor),
1614
- workspaceFsDeps: { mkdir: mkdir5, readdir: readdir4, stat: stat4, homedir: homedir3 },
1688
+ workspaceFsDeps: { mkdir: mkdir5, readdir: readdir4, stat: stat4, homedir: homedir4 },
1615
1689
  stateFsDeps: { readFile: readFile7, writeFile: writeFile6, rename: rename4, mkdir: mkdir5, appendFile: appendFile3 },
1616
1690
  devcontainerFsDeps: { cp: cp2, mkdir: mkdir5, readFile: readFile7, stat: stat4, writeFile: writeFile6 },
1617
1691
  mergeDeps: { readFile: readFile7, writeFile: writeFile6, rename: rename4, access: access3 },
@@ -1631,13 +1705,14 @@ async function setupMergedConfig(wsPath, containerName, repoName, purposeText, d
1631
1705
  repoSlug: repoName,
1632
1706
  purpose: purposeText
1633
1707
  });
1708
+ await copyRepoEnvFiles(repoName, wsPath.root);
1634
1709
  const repoConfig = await readRepoConfig(wsPath.root, deps.mergeDeps, deps.logger);
1635
1710
  if (repoConfig) {
1636
1711
  validateRepoConfig(repoConfig, defaults.image, deps.logger);
1637
1712
  }
1638
1713
  const merged = mergeDevcontainerConfigs(managed, repoConfig);
1639
1714
  await copyManagedAssets(wsPath.root, deps.devcontainerFsDeps);
1640
- const configPath = join6(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
1715
+ const configPath = join7(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
1641
1716
  await writeGeneratedConfig(configPath, merged, deps.mergeDeps);
1642
1717
  return { ok: true, repoConfigDetected: repoConfig !== void 0 };
1643
1718
  } catch (err) {
@@ -1756,7 +1831,7 @@ async function createInstance(instanceName, repoUrl, deps, options) {
1756
1831
  }
1757
1832
  };
1758
1833
  }
1759
- const configPath = join6(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
1834
+ const configPath = join7(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
1760
1835
  const containerResult = await deps.container.devcontainerUp(wsPath.root, containerName, {
1761
1836
  remoteEnv: {
1762
1837
  AGENT_INSTANCE: wsPath.name,
@@ -1853,7 +1928,7 @@ function createAttachDefaultDeps() {
1853
1928
  return {
1854
1929
  executor,
1855
1930
  container: createContainerLifecycle(executor),
1856
- workspaceFsDeps: { mkdir: mkdir6, readdir: readdir5, stat: stat5, homedir: homedir4 },
1931
+ workspaceFsDeps: { mkdir: mkdir6, readdir: readdir5, stat: stat5, homedir: homedir5 },
1857
1932
  stateFsDeps: { readFile: readFile8, writeFile: writeFile7, rename: rename5, mkdir: mkdir6, appendFile: appendFile4 }
1858
1933
  };
1859
1934
  }
@@ -1891,7 +1966,7 @@ async function attachInstance(instanceName, deps, onContainerStarting, onAttachi
1891
1966
  }
1892
1967
  if (statusResult.status === "stopped" || statusResult.status === "not-found") {
1893
1968
  onContainerStarting?.();
1894
- const configPath = join7(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
1969
+ const configPath = join8(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
1895
1970
  const startResult = await deps.container.devcontainerUp(wsPath.root, containerName, {
1896
1971
  remoteEnv: { AGENT_INSTANCE: wsPath.name },
1897
1972
  configPath,
@@ -1996,22 +2071,22 @@ import {
1996
2071
  unlink,
1997
2072
  writeFile as writeFile8
1998
2073
  } from "fs/promises";
1999
- import { homedir as homedir5 } from "os";
2000
- import { join as join8 } from "path";
2074
+ import { homedir as homedir6 } from "os";
2075
+ import { join as join9 } from "path";
2001
2076
  function createCodeDefaultDeps() {
2002
2077
  const executor = createExecutor();
2003
2078
  return {
2004
2079
  executor,
2005
2080
  container: createContainerLifecycle(executor),
2006
- workspaceFsDeps: { mkdir: mkdir7, readdir: readdir6, stat: stat6, homedir: homedir5 },
2081
+ workspaceFsDeps: { mkdir: mkdir7, readdir: readdir6, stat: stat6, homedir: homedir6 },
2007
2082
  stateFsDeps: { readFile: readFile9, writeFile: writeFile8, rename: rename6, mkdir: mkdir7, appendFile: appendFile5 },
2008
2083
  codeFsDeps: { lstat: lstat2, symlink, readlink: readlink2, unlink }
2009
2084
  };
2010
2085
  }
2011
2086
  var DEVCONTAINER_OPEN_TIMEOUT = 3e4;
2012
2087
  async function ensureConfigSymlink(wsRoot, deps) {
2013
- const symlinkPath = join8(wsRoot, ".devcontainer.json");
2014
- const target = join8(AGENT_ENV_DIR, "devcontainer.json");
2088
+ const symlinkPath = join9(wsRoot, ".devcontainer.json");
2089
+ const target = join9(AGENT_ENV_DIR, "devcontainer.json");
2015
2090
  try {
2016
2091
  const linkStat = await deps.lstat(symlinkPath);
2017
2092
  if (linkStat.isSymbolicLink()) {
@@ -2027,7 +2102,7 @@ async function ensureConfigSymlink(wsRoot, deps) {
2027
2102
  await deps.symlink(target, symlinkPath);
2028
2103
  }
2029
2104
  async function removeConfigSymlink(wsRoot, deps) {
2030
- const symlinkPath = join8(wsRoot, ".devcontainer.json");
2105
+ const symlinkPath = join9(wsRoot, ".devcontainer.json");
2031
2106
  try {
2032
2107
  const linkStat = await deps.lstat(symlinkPath);
2033
2108
  if (!linkStat.isSymbolicLink()) return;
@@ -2067,7 +2142,7 @@ async function codeInstance(instanceName, deps, onContainerStarting, onOpening,
2067
2142
  }
2068
2143
  };
2069
2144
  }
2070
- const configPath = join8(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
2145
+ const configPath = join9(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
2071
2146
  if (statusResult.status === "stopped" || statusResult.status === "not-found") {
2072
2147
  onContainerStarting?.();
2073
2148
  const startResult = await deps.container.devcontainerUp(wsPath.root, containerName, {
@@ -2660,8 +2735,50 @@ var createCommand = new Command4("create").description("Create a new isolated de
2660
2735
  }
2661
2736
  });
2662
2737
 
2663
- // src/commands/list.ts
2738
+ // src/commands/env.ts
2664
2739
  import { Command as Command5 } from "commander";
2740
+ import { spawnSync } from "child_process";
2741
+ import { existsSync, mkdirSync } from "fs";
2742
+ var envCommand = new Command5("env").description("Manage repo-level env files copied into workspaces").argument("<repo-slug>", "Repo slug (from `agent-env repos`)").option("--edit", "Open .env in $EDITOR").option("--edit-local", "Open .env.local in $EDITOR").option("--path", "Print path to repo env directory").action(
2743
+ async (repoSlug, options) => {
2744
+ const dir = getRepoEnvDir(repoSlug);
2745
+ if (options.path) {
2746
+ console.log(dir);
2747
+ return;
2748
+ }
2749
+ if (options.edit || options.editLocal) {
2750
+ const editor = process.env.EDITOR || process.env.VISUAL || "vi";
2751
+ const filename = options.editLocal ? ".env.local" : ".env";
2752
+ const filePath = `${dir}/${filename}`;
2753
+ if (!existsSync(dir)) {
2754
+ mkdirSync(dir, { recursive: true });
2755
+ }
2756
+ const result = spawnSync(editor, [filePath], { stdio: "inherit" });
2757
+ if (result.status !== 0) {
2758
+ console.error(
2759
+ formatError(createError("EDITOR_ERROR", `Failed to open ${filename} in ${editor}.`))
2760
+ );
2761
+ process.exitCode = 1;
2762
+ }
2763
+ return;
2764
+ }
2765
+ const env = await loadRepoEnv(repoSlug);
2766
+ const keys = Object.keys(env);
2767
+ if (keys.length === 0) {
2768
+ console.log(`No env files found for repo "${repoSlug}".`);
2769
+ console.log(`Create one at: ${dir}/.env`);
2770
+ return;
2771
+ }
2772
+ console.log(`Repo env vars for "${repoSlug}" (${dir}):
2773
+ `);
2774
+ for (const [key, value] of Object.entries(env)) {
2775
+ console.log(` ${key}=${value}`);
2776
+ }
2777
+ }
2778
+ );
2779
+
2780
+ // src/commands/list.ts
2781
+ import { Command as Command6 } from "commander";
2665
2782
  import { render } from "ink";
2666
2783
  import React from "react";
2667
2784
 
@@ -3033,7 +3150,7 @@ async function listInstances(deps, opts) {
3033
3150
  }
3034
3151
 
3035
3152
  // src/commands/list.ts
3036
- var listCommand = new Command5("list").alias("ps").description("List all instances with status").option("--json", "Output in JSON format").option("--repo <slug>", "Filter instances by repo slug").action(async (options) => {
3153
+ var listCommand = new Command6("list").alias("ps").description("List all instances with status").option("--json", "Output in JSON format").option("--repo <slug>", "Filter instances by repo slug").action(async (options) => {
3037
3154
  const result = await listInstances(void 0, {
3038
3155
  repoFilter: options.repo
3039
3156
  });
@@ -3085,7 +3202,196 @@ var listCommand = new Command5("list").alias("ps").description("List all instanc
3085
3202
  });
3086
3203
 
3087
3204
  // src/commands/on.ts
3088
- import { Command as Command6 } from "commander";
3205
+ import { Command as Command7 } from "commander";
3206
+
3207
+ // src/lib/version-drift.ts
3208
+ import { spawnSync as spawnSync2 } from "child_process";
3209
+ import { access as access4, constants as constants2 } from "fs/promises";
3210
+ import { homedir as homedir7 } from "os";
3211
+ import { join as join10 } from "path";
3212
+
3213
+ // src/lib/update-check.ts
3214
+ import chalk from "chalk";
3215
+ import * as fs from "fs/promises";
3216
+ import { dirname as dirname3 } from "path";
3217
+ function normaliseVersion(version2) {
3218
+ const withoutBuild = version2.split("+")[0];
3219
+ const withoutPre = withoutBuild.split("-")[0];
3220
+ return withoutPre;
3221
+ }
3222
+ function isNewerVersion(current, registry) {
3223
+ const normCurrent = normaliseVersion(current);
3224
+ const normRegistry = normaliseVersion(registry);
3225
+ const currentParts = normCurrent.split(".").map(Number);
3226
+ const registryParts = normRegistry.split(".").map(Number);
3227
+ const len = Math.max(currentParts.length, registryParts.length);
3228
+ for (let i = 0; i < len; i++) {
3229
+ const c = currentParts[i] ?? 0;
3230
+ const r = registryParts[i] ?? 0;
3231
+ if (r > c) return true;
3232
+ if (r < c) return false;
3233
+ }
3234
+ return false;
3235
+ }
3236
+ async function readCache(cachePath, readFileFn) {
3237
+ try {
3238
+ const raw = await readFileFn(cachePath, "utf-8");
3239
+ const parsed = JSON.parse(raw);
3240
+ if (parsed !== null && typeof parsed === "object" && "lastCheck" in parsed && "latestVersion" in parsed && typeof parsed.lastCheck === "number" && typeof parsed.latestVersion === "string") {
3241
+ return parsed;
3242
+ }
3243
+ return null;
3244
+ } catch {
3245
+ return null;
3246
+ }
3247
+ }
3248
+ async function writeCache(cachePath, data, mkdirFn, writeFileFn) {
3249
+ try {
3250
+ await mkdirFn(dirname3(cachePath), { recursive: true });
3251
+ await writeFileFn(cachePath, JSON.stringify(data), "utf-8");
3252
+ } catch {
3253
+ }
3254
+ }
3255
+ async function fetchLatestVersion(packageName, fetchFn) {
3256
+ try {
3257
+ const url = `https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`;
3258
+ const response = await fetchFn(url, {
3259
+ headers: { Accept: "application/json" },
3260
+ signal: AbortSignal.timeout(5e3)
3261
+ });
3262
+ const json = await response.json();
3263
+ if (json !== null && typeof json === "object" && "version" in json && typeof json.version === "string") {
3264
+ return json.version;
3265
+ }
3266
+ return null;
3267
+ } catch {
3268
+ return null;
3269
+ }
3270
+ }
3271
+ function formatUpdateMessage(currentVersion, latestVersion, packageName) {
3272
+ const normCurrent = normaliseVersion(currentVersion);
3273
+ const line1 = chalk.yellow(`Update available: ${normCurrent} -> ${latestVersion}`);
3274
+ const line2 = chalk.cyan(`Run: pnpm add -g ${packageName}`);
3275
+ return `${line1}
3276
+ ${line2}`;
3277
+ }
3278
+ async function checkForUpdate(opts) {
3279
+ const {
3280
+ currentVersion,
3281
+ packageName,
3282
+ cachePath,
3283
+ cacheTtlMs,
3284
+ fetchFn = fetch,
3285
+ readFile: readFile17 = (p, enc) => fs.readFile(p, enc),
3286
+ writeFile: writeFile14 = (p, d, enc) => fs.writeFile(p, d, enc),
3287
+ mkdir: mkdir15 = (p, o) => fs.mkdir(p, o),
3288
+ now = () => Date.now()
3289
+ } = opts;
3290
+ const currentTime = now();
3291
+ const cache = await readCache(cachePath, readFile17);
3292
+ let latestVersion = null;
3293
+ const isCacheFresh = cache !== null && currentTime - cache.lastCheck < cacheTtlMs;
3294
+ if (isCacheFresh) {
3295
+ latestVersion = cache.latestVersion;
3296
+ } else {
3297
+ latestVersion = await fetchLatestVersion(packageName, fetchFn);
3298
+ if (latestVersion !== null) {
3299
+ await writeCache(cachePath, { lastCheck: currentTime, latestVersion }, mkdir15, writeFile14);
3300
+ }
3301
+ }
3302
+ if (latestVersion !== null && isNewerVersion(currentVersion, latestVersion)) {
3303
+ return formatUpdateMessage(currentVersion, latestVersion, packageName);
3304
+ }
3305
+ return null;
3306
+ }
3307
+
3308
+ // src/lib/version-drift.ts
3309
+ function normaliseVersion2(version2) {
3310
+ return version2.split("+")[0].split("-")[0];
3311
+ }
3312
+ function isNewerVersion2(running, installed) {
3313
+ const r = normaliseVersion2(running).split(".").map(Number);
3314
+ const i = normaliseVersion2(installed).split(".").map(Number);
3315
+ const len = Math.max(r.length, i.length);
3316
+ for (let j = 0; j < len; j++) {
3317
+ const rv = r[j] ?? 0;
3318
+ const iv = i[j] ?? 0;
3319
+ if (iv > rv) return true;
3320
+ if (iv < rv) return false;
3321
+ }
3322
+ return false;
3323
+ }
3324
+ function getInstalledVersion(deps = {}) {
3325
+ const spawn = deps.spawn ?? spawnSync2;
3326
+ try {
3327
+ const result = spawn("agent-env", ["--version"], {
3328
+ encoding: "utf-8",
3329
+ timeout: 5e3,
3330
+ stdio: ["ignore", "pipe", "ignore"]
3331
+ });
3332
+ if (result.status !== 0 || typeof result.stdout !== "string") {
3333
+ return null;
3334
+ }
3335
+ const version2 = result.stdout.trim();
3336
+ return /^\d+\.\d+\.\d+/.test(version2) ? version2 : null;
3337
+ } catch {
3338
+ return null;
3339
+ }
3340
+ }
3341
+ async function isPackagePathStale(deps = {}) {
3342
+ const { access: accessFn = access4, getBaselinePath = getBaselineConfigPath } = deps;
3343
+ try {
3344
+ await accessFn(join10(getBaselinePath(), "devcontainer.json"), constants2.F_OK);
3345
+ return false;
3346
+ } catch {
3347
+ return true;
3348
+ }
3349
+ }
3350
+ var UPDATE_CHECK_CACHE_PATH = join10(homedir7(), ".agent-env", "update-check.json");
3351
+ var UPDATE_CHECK_CACHE_TTL_MS = 36e5;
3352
+ async function fetchUpdateMessageFromRegistry(force = false) {
3353
+ try {
3354
+ return await checkForUpdate({
3355
+ currentVersion: package_default.version,
3356
+ packageName: package_default.name,
3357
+ cachePath: UPDATE_CHECK_CACHE_PATH,
3358
+ cacheTtlMs: force ? 0 : UPDATE_CHECK_CACHE_TTL_MS
3359
+ });
3360
+ } catch {
3361
+ return null;
3362
+ }
3363
+ }
3364
+ async function detectDriftState(deps = {}, options = {}) {
3365
+ const {
3366
+ isPackagePathStale: probe = isPackagePathStale,
3367
+ fetchUpdateMessage = (force) => fetchUpdateMessageFromRegistry(force),
3368
+ getInstalledVersion: resolveInstalled = getInstalledVersion
3369
+ } = deps;
3370
+ const installedVersion = resolveInstalled();
3371
+ const [packageMoved, updateMessage] = await Promise.all([
3372
+ probe(),
3373
+ fetchUpdateMessage(options.forceRefresh ?? false)
3374
+ ]);
3375
+ return {
3376
+ packageMoved,
3377
+ updateMessage,
3378
+ installedVersion,
3379
+ currentVersion: package_default.version
3380
+ };
3381
+ }
3382
+ function getCurrentVersion() {
3383
+ return package_default.version;
3384
+ }
3385
+ function restartMenu({ workspaceName, repoSlug }, deps = {}) {
3386
+ const spawn = deps.spawn ?? spawnSync2;
3387
+ const exit = deps.exit ?? ((code) => process.exit(code));
3388
+ const args = ["on", workspaceName];
3389
+ if (repoSlug) {
3390
+ args.push("--repo", repoSlug);
3391
+ }
3392
+ const result = spawn("agent-env", args, { stdio: "inherit" });
3393
+ exit(result.status ?? 1);
3394
+ }
3089
3395
 
3090
3396
  // src/lib/interactive-menu.ts
3091
3397
  async function launchActionLoop(workspaceName, deps, repoSlug) {
@@ -3096,6 +3402,10 @@ async function launchActionLoop(workspaceName, deps, repoSlug) {
3096
3402
  if (action === "exit") {
3097
3403
  break;
3098
3404
  }
3405
+ if (action === "restart") {
3406
+ restartMenu({ workspaceName, repoSlug });
3407
+ continue;
3408
+ }
3099
3409
  if (action === "shutdown") {
3100
3410
  const shutdownResult = await deps.shutdownInstance(workspaceName, repoSlug);
3101
3411
  if (!shutdownResult.ok) {
@@ -3121,6 +3431,9 @@ async function launchActionLoop(workspaceName, deps, repoSlug) {
3121
3431
  case "set-purpose":
3122
3432
  result = await deps.setPurpose(workspaceName, purposeValue ?? "", repoSlug);
3123
3433
  break;
3434
+ case "check-updates":
3435
+ result = await deps.checkForUpdates();
3436
+ break;
3124
3437
  }
3125
3438
  if (!result.ok && result.error) {
3126
3439
  const { code, message, suggestion } = result.error;
@@ -3150,7 +3463,10 @@ async function launchInstancePicker(deps) {
3150
3463
 
3151
3464
  // src/lib/menu-deps.ts
3152
3465
  import { render as render2 } from "ink";
3153
- import React3 from "react";
3466
+ import React4 from "react";
3467
+
3468
+ // src/components/MenuContainer.tsx
3469
+ import { useEffect, useState as useState2 } from "react";
3154
3470
 
3155
3471
  // src/components/InteractiveMenu.tsx
3156
3472
  import { Select, TextInput } from "@inkjs/ui";
@@ -3188,18 +3504,66 @@ function PurposeInput({
3188
3504
  /* @__PURE__ */ jsx3(TextInput, { placeholder: "Enter purpose...", onSubmit })
3189
3505
  ] });
3190
3506
  }
3191
- var ACTION_OPTIONS = [
3507
+ var BASE_ACTION_OPTIONS = [
3192
3508
  { label: "\u{1F680} Attach to session", value: "attach" },
3193
3509
  { label: "\u{1F4BB} Open in VS Code", value: "code" },
3194
3510
  { label: "\u{1F6E0} Rebuild container", value: "rebuild" },
3195
3511
  { label: "\u23F9 Shutdown container", value: "shutdown" },
3196
- { label: "\u{1F4DD} Set Purpose", value: "set-purpose" },
3197
- { label: "\u{1F6AA} Exit", value: "exit" }
3512
+ { label: "\u{1F4DD} Set Purpose", value: "set-purpose" }
3198
3513
  ];
3514
+ var EXIT_OPTION = { label: "\u{1F6AA} Exit", value: "exit" };
3515
+ var RESTART_REQUIRED_OPTION = {
3516
+ label: "\u267B\uFE0F Restart menu (required \u2014 agent-env was upgraded)",
3517
+ value: "restart"
3518
+ };
3519
+ var CHECK_FOR_UPDATES_OPTION = {
3520
+ label: "\u{1F504} Check for updates",
3521
+ value: "check-updates"
3522
+ };
3523
+ function hasNewerInstall(driftState) {
3524
+ if (!driftState?.installedVersion) return false;
3525
+ return isNewerVersion2(driftState.currentVersion, driftState.installedVersion);
3526
+ }
3527
+ function buildActionOptions(driftState) {
3528
+ if (driftState?.packageMoved) {
3529
+ return [RESTART_REQUIRED_OPTION, ...BASE_ACTION_OPTIONS, EXIT_OPTION];
3530
+ }
3531
+ if (driftState && hasNewerInstall(driftState)) {
3532
+ const label = `\u267B\uFE0F Restart menu (v${driftState.installedVersion} installed)`;
3533
+ return [{ label, value: "restart" }, ...BASE_ACTION_OPTIONS, EXIT_OPTION];
3534
+ }
3535
+ if (driftState?.updateMessage) {
3536
+ return [...BASE_ACTION_OPTIONS, CHECK_FOR_UPDATES_OPTION, EXIT_OPTION];
3537
+ }
3538
+ if (driftState) {
3539
+ return [...BASE_ACTION_OPTIONS, CHECK_FOR_UPDATES_OPTION, EXIT_OPTION];
3540
+ }
3541
+ return [...BASE_ACTION_OPTIONS, EXIT_OPTION];
3542
+ }
3543
+ function DriftBanner({ driftState }) {
3544
+ if (driftState.packageMoved) {
3545
+ return /* @__PURE__ */ jsxs3(Box2, { marginBottom: 1, flexDirection: "column", children: [
3546
+ /* @__PURE__ */ jsx3(Text3, { color: "red", bold: true, children: "\u26A0 agent-env was upgraded since this menu started." }),
3547
+ /* @__PURE__ */ jsx3(Text3, { color: "red", children: "Rebuild and other commands will fail until you restart the menu." })
3548
+ ] });
3549
+ }
3550
+ if (hasNewerInstall(driftState)) {
3551
+ return /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsxs3(Text3, { color: "yellow", children: [
3552
+ "agent-env v",
3553
+ driftState.installedVersion,
3554
+ " is installed \u2014 restart to use it"
3555
+ ] }) });
3556
+ }
3557
+ if (driftState.updateMessage) {
3558
+ return /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, flexDirection: "column", children: /* @__PURE__ */ jsx3(Text3, { color: "yellow", children: driftState.updateMessage }) });
3559
+ }
3560
+ return null;
3561
+ }
3199
3562
  function InteractiveMenu({
3200
3563
  instanceInfo,
3201
3564
  onAction,
3202
- onSetPurpose
3565
+ onSetPurpose,
3566
+ driftState
3203
3567
  }) {
3204
3568
  const [mode, setMode] = useState("actions");
3205
3569
  const { name, status, repoSlug, purpose } = instanceInfo;
@@ -3221,34 +3585,89 @@ function InteractiveMenu({
3221
3585
  if (purpose !== null) {
3222
3586
  headerParts.push(purpose);
3223
3587
  }
3588
+ const actionOptions = buildActionOptions(driftState);
3224
3589
  return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
3590
+ driftState ? /* @__PURE__ */ jsx3(DriftBanner, { driftState }) : null,
3225
3591
  /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: headerParts.join(" \xB7 ") }) }),
3226
3592
  mode === "actions" ? /* @__PURE__ */ jsx3(
3227
3593
  Select,
3228
3594
  {
3229
- options: ACTION_OPTIONS,
3595
+ options: actionOptions,
3230
3596
  onChange: handleActionChange,
3231
- visibleOptionCount: ACTION_OPTIONS.length
3597
+ visibleOptionCount: actionOptions.length
3232
3598
  }
3233
3599
  ) : /* @__PURE__ */ jsx3(PurposeInput, { onSubmit: handlePurposeSubmit, onCancel: handlePurposeCancel })
3234
3600
  ] });
3235
3601
  }
3236
3602
 
3603
+ // src/components/MenuContainer.tsx
3604
+ import { jsx as jsx4 } from "react/jsx-runtime";
3605
+ var DRIFT_POLL_INTERVAL_MS = 10 * 60 * 1e3;
3606
+ function makeNeutralDriftState() {
3607
+ return {
3608
+ packageMoved: false,
3609
+ updateMessage: null,
3610
+ installedVersion: null,
3611
+ currentVersion: getCurrentVersion()
3612
+ };
3613
+ }
3614
+ function MenuContainer({
3615
+ instanceInfo,
3616
+ onAction,
3617
+ onSetPurpose,
3618
+ initialDriftState,
3619
+ detectDriftStateFn = detectDriftState,
3620
+ pollIntervalMs = DRIFT_POLL_INTERVAL_MS
3621
+ }) {
3622
+ const [driftState, setDriftState] = useState2(
3623
+ initialDriftState ?? makeNeutralDriftState()
3624
+ );
3625
+ useEffect(() => {
3626
+ let cancelled = false;
3627
+ const runProbe = async () => {
3628
+ try {
3629
+ const next = await detectDriftStateFn();
3630
+ if (!cancelled) {
3631
+ setDriftState(next);
3632
+ }
3633
+ } catch {
3634
+ }
3635
+ };
3636
+ void runProbe();
3637
+ const handle = setInterval(() => {
3638
+ void runProbe();
3639
+ }, pollIntervalMs);
3640
+ return () => {
3641
+ cancelled = true;
3642
+ clearInterval(handle);
3643
+ };
3644
+ }, [detectDriftStateFn, pollIntervalMs]);
3645
+ return /* @__PURE__ */ jsx4(
3646
+ InteractiveMenu,
3647
+ {
3648
+ instanceInfo,
3649
+ onAction,
3650
+ onSetPurpose,
3651
+ driftState
3652
+ }
3653
+ );
3654
+ }
3655
+
3237
3656
  // src/lib/rebuild-instance.ts
3238
3657
  import {
3239
- access as access4,
3658
+ access as access5,
3240
3659
  cp as cp3,
3241
- mkdir as mkdir8,
3660
+ mkdir as mkdir9,
3242
3661
  readdir as readdir7,
3243
- readFile as readFile10,
3662
+ readFile as readFile11,
3244
3663
  rename as rename7,
3245
3664
  rm as rm3,
3246
3665
  stat as stat7,
3247
- writeFile as writeFile9,
3666
+ writeFile as writeFile10,
3248
3667
  appendFile as appendFile6
3249
3668
  } from "fs/promises";
3250
- import { homedir as homedir6 } from "os";
3251
- import { join as join9 } from "path";
3669
+ import { homedir as homedir8 } from "os";
3670
+ import { join as join11 } from "path";
3252
3671
 
3253
3672
  // src/lib/tmux-utils.ts
3254
3673
  async function saveTmuxState(containerName, deps) {
@@ -3277,10 +3696,10 @@ function createRebuildDefaultDeps() {
3277
3696
  return {
3278
3697
  executor,
3279
3698
  container: createContainerLifecycle(executor),
3280
- workspaceFsDeps: { mkdir: mkdir8, readdir: readdir7, stat: stat7, homedir: homedir6 },
3281
- stateFsDeps: { readFile: readFile10, writeFile: writeFile9, rename: rename7, mkdir: mkdir8, appendFile: appendFile6 },
3282
- devcontainerFsDeps: { cp: cp3, mkdir: mkdir8, readdir: readdir7, readFile: readFile10, stat: stat7, writeFile: writeFile9 },
3283
- mergeDeps: { readFile: readFile10, writeFile: writeFile9, rename: rename7, access: access4 },
3699
+ workspaceFsDeps: { mkdir: mkdir9, readdir: readdir7, stat: stat7, homedir: homedir8 },
3700
+ stateFsDeps: { readFile: readFile11, writeFile: writeFile10, rename: rename7, mkdir: mkdir9, appendFile: appendFile6 },
3701
+ devcontainerFsDeps: { cp: cp3, mkdir: mkdir9, readdir: readdir7, readFile: readFile11, stat: stat7, writeFile: writeFile10 },
3702
+ mergeDeps: { readFile: readFile11, writeFile: writeFile10, rename: rename7, access: access5 },
3284
3703
  rm: rm3,
3285
3704
  rename: rename7,
3286
3705
  logger: { warn: (msg) => console.warn(msg), info: (msg) => console.info(msg) }
@@ -3295,6 +3714,7 @@ async function refreshMergedConfig(wsRoot, containerName, wsName, repoSlug, purp
3295
3714
  repoSlug,
3296
3715
  purpose
3297
3716
  });
3717
+ await copyRepoEnvFiles(repoSlug, wsRoot);
3298
3718
  const repoConfig = await readRepoConfig(wsRoot, deps.mergeDeps, deps.logger);
3299
3719
  if (repoConfigExpected && !repoConfig) {
3300
3720
  return {
@@ -3311,7 +3731,7 @@ async function refreshMergedConfig(wsRoot, containerName, wsName, repoSlug, purp
3311
3731
  }
3312
3732
  const merged = mergeDevcontainerConfigs(managed, repoConfig);
3313
3733
  await copyManagedAssets(wsRoot, deps.devcontainerFsDeps);
3314
- const configPath = join9(wsRoot, AGENT_ENV_DIR, "devcontainer.json");
3734
+ const configPath = join11(wsRoot, AGENT_ENV_DIR, "devcontainer.json");
3315
3735
  await writeGeneratedConfig(configPath, merged, deps.mergeDeps);
3316
3736
  return { ok: true, repoConfigDetected: repoConfig !== void 0 };
3317
3737
  } catch (err) {
@@ -3411,7 +3831,7 @@ async function teardownContainer(containerName, container, statusResult) {
3411
3831
  return { ok: true };
3412
3832
  }
3413
3833
  async function startAndDiscoverContainer(wsPath, containerName, purpose, buildNoCache, container, onProgress) {
3414
- const configPath = join9(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
3834
+ const configPath = join11(wsPath.root, AGENT_ENV_DIR, "devcontainer.json");
3415
3835
  const containerResult = await container.devcontainerUp(wsPath.root, containerName, {
3416
3836
  buildNoCache,
3417
3837
  remoteEnv: { AGENT_INSTANCE: wsPath.name, AGENT_ENV_PURPOSE: purpose },
@@ -3514,15 +3934,15 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
3514
3934
  }
3515
3935
 
3516
3936
  // src/lib/shutdown-instance.ts
3517
- import { appendFile as appendFile7, mkdir as mkdir9, readdir as readdir8, readFile as readFile11, rename as rename8, stat as stat8, writeFile as writeFile10 } from "fs/promises";
3518
- import { homedir as homedir7 } from "os";
3937
+ import { appendFile as appendFile7, mkdir as mkdir10, readdir as readdir8, readFile as readFile12, rename as rename8, stat as stat8, writeFile as writeFile11 } from "fs/promises";
3938
+ import { homedir as homedir9 } from "os";
3519
3939
  function createShutdownDefaultDeps() {
3520
3940
  const executor = createExecutor();
3521
3941
  return {
3522
3942
  executor,
3523
3943
  container: createContainerLifecycle(executor),
3524
- workspaceFsDeps: { mkdir: mkdir9, readdir: readdir8, stat: stat8, homedir: homedir7 },
3525
- stateFsDeps: { readFile: readFile11, writeFile: writeFile10, rename: rename8, mkdir: mkdir9, appendFile: appendFile7 },
3944
+ workspaceFsDeps: { mkdir: mkdir10, readdir: readdir8, stat: stat8, homedir: homedir9 },
3945
+ stateFsDeps: { readFile: readFile12, writeFile: writeFile11, rename: rename8, mkdir: mkdir10, appendFile: appendFile7 },
3526
3946
  logger: { warn: (msg) => console.warn(msg), info: (msg) => console.info(msg) }
3527
3947
  };
3528
3948
  }
@@ -3596,22 +4016,30 @@ function buildMenuDeps() {
3596
4016
  slug
3597
4017
  );
3598
4018
  },
3599
- rebuildInstance: (wsName, slug) => {
4019
+ rebuildInstance: async (wsName, slug) => {
4020
+ if (await isPackagePathStale()) {
4021
+ return {
4022
+ ok: false,
4023
+ error: {
4024
+ code: "VERSION_DRIFT",
4025
+ message: "agent-env was upgraded since this menu started.",
4026
+ suggestion: 'Pick "Restart menu" from the menu to reload with the new version.'
4027
+ }
4028
+ };
4029
+ }
3600
4030
  const rebuildDeps = createRebuildDefaultDeps();
3601
4031
  const progress = createProgressLine();
3602
4032
  console.log(`Rebuilding instance '${wsName}'...`);
3603
- return rebuildInstance(
3604
- wsName,
3605
- rebuildDeps,
3606
- { force: true, onProgress: progress.update },
3607
- slug
3608
- ).then((result) => {
3609
- progress.clear();
3610
- return result;
3611
- }).catch((err) => {
4033
+ try {
4034
+ return await rebuildInstance(
4035
+ wsName,
4036
+ rebuildDeps,
4037
+ { force: true, onProgress: progress.update },
4038
+ slug
4039
+ );
4040
+ } finally {
3612
4041
  progress.clear();
3613
- throw err;
3614
- });
4042
+ }
3615
4043
  },
3616
4044
  shutdownInstance: (wsName, slug) => {
3617
4045
  const deps = createShutdownDefaultDeps();
@@ -3627,11 +4055,30 @@ function buildMenuDeps() {
3627
4055
  const deps = createPurposeDefaultDeps();
3628
4056
  return setPurpose(wsName, value, deps, slug);
3629
4057
  },
4058
+ checkForUpdates: async () => {
4059
+ console.log("Checking for updates...");
4060
+ const state = await detectDriftState({}, { forceRefresh: true });
4061
+ const current = getCurrentVersion();
4062
+ if (state.packageMoved) {
4063
+ console.log(
4064
+ '\x1B[31m\u26A0 agent-env was upgraded since this menu started \u2014 pick "Restart menu" to reload.\x1B[0m'
4065
+ );
4066
+ } else if (state.installedVersion && isNewerVersion2(current, state.installedVersion)) {
4067
+ console.log(
4068
+ `\x1B[33magent-env v${state.installedVersion} is installed \u2014 pick "Restart menu" to use it.\x1B[0m`
4069
+ );
4070
+ } else if (state.updateMessage) {
4071
+ console.log(state.updateMessage);
4072
+ } else {
4073
+ console.log(`\x1B[32m\u2713\x1B[0m agent-env ${current} is up to date`);
4074
+ }
4075
+ return { ok: true };
4076
+ },
3630
4077
  getInstanceInfo: (wsName) => getInstanceInfo(wsName),
3631
4078
  renderMenu: (instanceInfo) => {
3632
4079
  return new Promise((resolve2) => {
3633
4080
  const { unmount, waitUntilExit } = render2(
3634
- React3.createElement(InteractiveMenu, {
4081
+ React4.createElement(MenuContainer, {
3635
4082
  instanceInfo,
3636
4083
  onAction: (action) => {
3637
4084
  unmount();
@@ -3650,7 +4097,7 @@ function buildMenuDeps() {
3650
4097
  }
3651
4098
 
3652
4099
  // src/commands/on.ts
3653
- var onCommand = new Command6("on").description("Open the interactive menu for an instance").argument("<name>", "Instance name").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
4100
+ var onCommand = new Command7("on").description("Open the interactive menu for an instance").argument("<name>", "Instance name").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
3654
4101
  if (!process.stdin.isTTY) {
3655
4102
  console.error(
3656
4103
  formatError(
@@ -3678,8 +4125,8 @@ var onCommand = new Command6("on").description("Open the interactive menu for an
3678
4125
  });
3679
4126
 
3680
4127
  // src/commands/path.ts
3681
- import { Command as Command7 } from "commander";
3682
- var pathCommand = new Command7("path").description("Print the host directory path for an instance").argument("<name>", "Instance name").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
4128
+ import { Command as Command8 } from "commander";
4129
+ var pathCommand = new Command8("path").description("Print the host directory path for an instance").argument("<name>", "Instance name").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
3683
4130
  const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
3684
4131
  const result = await resolveInstance(name, repoSlug);
3685
4132
  if (!result.found) {
@@ -3693,12 +4140,12 @@ var pathCommand = new Command7("path").description("Print the host directory pat
3693
4140
  });
3694
4141
 
3695
4142
  // src/commands/purpose.ts
3696
- import { Command as Command8 } from "commander";
4143
+ import { Command as Command9 } from "commander";
3697
4144
  var defaultPurposeCommandDeps = {
3698
4145
  isInsideContainer
3699
4146
  };
3700
4147
  function createPurposeCommand(deps = defaultPurposeCommandDeps) {
3701
- return new Command8("purpose").description(
4148
+ return new Command9("purpose").description(
3702
4149
  "Get or set the purpose/label for an instance. Inside a container: no instance name needed (agent-env purpose [value])"
3703
4150
  ).argument("[nameOrValue]", "Instance name (host) or purpose value (container)").argument("[value]", "New purpose value (omit to get current, empty string to clear)").option("--repo <slug>", "Repo slug or URL to scope instance lookup (host mode only)").action(async (nameOrValue, value, options) => {
3704
4151
  if (deps.isInsideContainer()) {
@@ -3772,9 +4219,9 @@ function handleSetResult(result) {
3772
4219
  }
3773
4220
 
3774
4221
  // src/commands/rebuild.ts
3775
- import chalk from "chalk";
3776
- import { Command as Command9 } from "commander";
3777
- var rebuildCommand = new Command9("rebuild").description("Rebuild an instance by recreating its container").argument("<name>", "Instance name to rebuild").option("--force", "Rebuild even if the container is currently running").option("--yes", "Skip confirmation prompt").option("--no-pull", "Skip pulling fresh base images").option("--use-cache", "Allow Docker build layer cache reuse").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(
4222
+ import chalk2 from "chalk";
4223
+ import { Command as Command10 } from "commander";
4224
+ var rebuildCommand = new Command10("rebuild").description("Rebuild an instance by recreating its container").argument("<name>", "Instance name to rebuild").option("--force", "Rebuild even if the container is currently running").option("--yes", "Skip confirmation prompt").option("--no-pull", "Skip pulling fresh base images").option("--use-cache", "Allow Docker build layer cache reuse").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(
3778
4225
  async (name, options) => {
3779
4226
  const deps = createRebuildDefaultDeps();
3780
4227
  const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
@@ -3782,7 +4229,7 @@ var rebuildCommand = new Command9("rebuild").description("Rebuild an instance by
3782
4229
  if (!options.yes && !options.force && process.stdin.isTTY) {
3783
4230
  confirmed = await promptForConfirmation(
3784
4231
  `
3785
- ${chalk.yellow("Warning:")} Rebuilding '${name}' will destroy the current container and create a new one.
4232
+ ${chalk2.yellow("Warning:")} Rebuilding '${name}' will destroy the current container and create a new one.
3786
4233
  Any active sessions will be lost. Continue? (y/N) `
3787
4234
  );
3788
4235
  if (!confirmed) {
@@ -3810,10 +4257,10 @@ Any active sessions will be lost. Continue? (y/N) `
3810
4257
  if (result.error.code === "CONTAINER_RUNNING") {
3811
4258
  console.error("");
3812
4259
  console.error(
3813
- chalk.yellow("Container is currently running.") + " Active sessions will be terminated during rebuild."
4260
+ chalk2.yellow("Container is currently running.") + " Active sessions will be terminated during rebuild."
3814
4261
  );
3815
4262
  console.error("");
3816
- console.error(`Use ${chalk.bold("--force")} to rebuild anyway.`);
4263
+ console.error(`Use ${chalk2.bold("--force")} to rebuild anyway.`);
3817
4264
  } else {
3818
4265
  const { code, message, suggestion } = result.error;
3819
4266
  console.error(formatError(createError(code, message, suggestion)));
@@ -3830,23 +4277,23 @@ Any active sessions will be lost. Continue? (y/N) `
3830
4277
  );
3831
4278
 
3832
4279
  // src/commands/remove.ts
3833
- import chalk3 from "chalk";
3834
- import { Command as Command10 } from "commander";
4280
+ import chalk4 from "chalk";
4281
+ import { Command as Command11 } from "commander";
3835
4282
  import { createInterface as createInterface2 } from "readline";
3836
4283
 
3837
4284
  // src/lib/audit-log.ts
3838
- import { appendFile as appendFile8, mkdir as mkdir10 } from "fs/promises";
3839
- import { homedir as homedir8 } from "os";
3840
- import { join as join10 } from "path";
4285
+ import { appendFile as appendFile8, mkdir as mkdir11 } from "fs/promises";
4286
+ import { homedir as homedir10 } from "os";
4287
+ import { join as join12 } from "path";
3841
4288
  function createAuditLogDefaultDeps() {
3842
- return { appendFile: appendFile8, mkdir: mkdir10, homedir: homedir8 };
4289
+ return { appendFile: appendFile8, mkdir: mkdir11, homedir: homedir10 };
3843
4290
  }
3844
4291
  function getAuditLogPath(deps) {
3845
- return join10(deps.homedir(), AGENT_ENV_DIR, "audit.log");
4292
+ return join12(deps.homedir(), AGENT_ENV_DIR, "audit.log");
3846
4293
  }
3847
4294
  async function writeAuditLogEntry(entry, deps = createAuditLogDefaultDeps()) {
3848
4295
  const logPath = getAuditLogPath(deps);
3849
- await deps.mkdir(join10(deps.homedir(), AGENT_ENV_DIR), { recursive: true });
4296
+ await deps.mkdir(join12(deps.homedir(), AGENT_ENV_DIR), { recursive: true });
3850
4297
  const line = JSON.stringify(entry) + "\n";
3851
4298
  await deps.appendFile(logPath, line, "utf-8");
3852
4299
  }
@@ -3861,16 +4308,16 @@ function createAuditEntry(instanceName, gitState, confirmationMethod) {
3861
4308
  }
3862
4309
 
3863
4310
  // src/lib/remove-instance.ts
3864
- import { mkdir as mkdir11, readdir as readdir9, readFile as readFile12, rm as rm4, stat as stat9 } from "fs/promises";
3865
- import { homedir as homedir9 } from "os";
4311
+ import { mkdir as mkdir12, readdir as readdir9, readFile as readFile13, rm as rm4, stat as stat9 } from "fs/promises";
4312
+ import { homedir as homedir11 } from "os";
3866
4313
  function createRemoveDefaultDeps() {
3867
4314
  const executor = createExecutor();
3868
4315
  return {
3869
4316
  executor,
3870
4317
  container: createContainerLifecycle(executor),
3871
4318
  gitDetector: createGitStateDetector(executor),
3872
- workspaceFsDeps: { mkdir: mkdir11, readdir: readdir9, stat: stat9, homedir: homedir9 },
3873
- stateFsDeps: { readFile: readFile12 },
4319
+ workspaceFsDeps: { mkdir: mkdir12, readdir: readdir9, stat: stat9, homedir: homedir11 },
4320
+ stateFsDeps: { readFile: readFile13 },
3874
4321
  deleteFsDeps: { rm: rm4 }
3875
4322
  };
3876
4323
  }
@@ -4017,7 +4464,7 @@ async function removeInstance(instanceName, deps, force = false, repoSlug) {
4017
4464
  }
4018
4465
 
4019
4466
  // src/lib/safety-report.ts
4020
- import chalk2 from "chalk";
4467
+ import chalk3 from "chalk";
4021
4468
  var BLOCKER_NEVER_PUSHED = "never pushed";
4022
4469
  var BLOCKER_DETACHED_HEAD = "detached HEAD";
4023
4470
  function classifyBlocker(blocker) {
@@ -4070,19 +4517,19 @@ function formatSafetyReport(instanceName, blockers, gitState) {
4070
4517
  message: blocker
4071
4518
  }));
4072
4519
  for (const item of items) {
4073
- const prefix = item.severity === "Danger" ? chalk2.red("[Danger]") : chalk2.yellow("[Warning]");
4520
+ const prefix = item.severity === "Danger" ? chalk3.red("[Danger]") : chalk3.yellow("[Warning]");
4074
4521
  lines.push(` ${prefix} ${item.message}`);
4075
4522
  }
4076
4523
  const suggestions = getSuggestions(gitState);
4077
4524
  if (suggestions.length > 0) {
4078
4525
  lines.push("");
4079
- lines.push(chalk2.bold("Suggestions:"));
4526
+ lines.push(chalk3.bold("Suggestions:"));
4080
4527
  for (const suggestion of suggestions) {
4081
4528
  lines.push(` - ${suggestion}`);
4082
4529
  }
4083
4530
  }
4084
4531
  lines.push("");
4085
- lines.push(chalk2.gray("Or use --force to bypass safety checks (data loss is permanent)."));
4532
+ lines.push(chalk3.gray("Or use --force to bypass safety checks (data loss is permanent)."));
4086
4533
  return lines.join("\n");
4087
4534
  }
4088
4535
 
@@ -4121,12 +4568,12 @@ async function writeAuditLog(name, gitState, confirmationMethod) {
4121
4568
  }
4122
4569
  function showForceWarning(name, blockers, gitState) {
4123
4570
  console.error("");
4124
- console.error(chalk3.red.bold("\u26A0\uFE0F WARNING: Force removing with unsaved work"));
4571
+ console.error(chalk4.red.bold("\u26A0\uFE0F WARNING: Force removing with unsaved work"));
4125
4572
  console.error("");
4126
4573
  console.error(
4127
4574
  formatSafetyReport(name, blockers, gitState).replace(
4128
4575
  /Or use --force.*/,
4129
- chalk3.red("This data will be PERMANENTLY DELETED.")
4576
+ chalk4.red("This data will be PERMANENTLY DELETED.")
4130
4577
  )
4131
4578
  );
4132
4579
  }
@@ -4137,7 +4584,7 @@ async function resolveConfirmation(name, options) {
4137
4584
  if (!process.stdin.isTTY) {
4138
4585
  console.error("");
4139
4586
  console.error(
4140
- chalk3.red(
4587
+ chalk4.red(
4141
4588
  "Cannot prompt for confirmation in non-interactive mode. Use --yes to skip confirmation."
4142
4589
  )
4143
4590
  );
@@ -4150,7 +4597,7 @@ async function resolveConfirmation(name, options) {
4150
4597
  }
4151
4598
  return "typed-name";
4152
4599
  }
4153
- var removeCommand = new Command10("remove").description("Remove an instance with safety checks").argument("<name>", "Instance name to remove").option("--repo <slug>", "Repo slug or URL to scope instance lookup").option("--force", "Force removal, bypassing safety checks").option(
4600
+ var removeCommand = new Command11("remove").description("Remove an instance with safety checks").argument("<name>", "Instance name to remove").option("--repo <slug>", "Repo slug or URL to scope instance lookup").option("--force", "Force removal, bypassing safety checks").option(
4154
4601
  "--yes",
4155
4602
  "Skip confirmation prompt for --force (DANGEROUS: skips all safety prompts, for scripts only)"
4156
4603
  ).action(async (name, options) => {
@@ -4213,8 +4660,8 @@ var removeCommand = new Command10("remove").description("Remove an instance with
4213
4660
  });
4214
4661
 
4215
4662
  // src/commands/repos.ts
4216
- import { Command as Command11 } from "commander";
4217
- var reposCommand = new Command11("repos").description("List tracked repositories").option("--json", "Output in JSON format").action(async (options) => {
4663
+ import { Command as Command12 } from "commander";
4664
+ var reposCommand = new Command12("repos").description("List tracked repositories").option("--json", "Output in JSON format").action(async (options) => {
4218
4665
  const result = await listRepos();
4219
4666
  if (!result.ok) {
4220
4667
  const error = createError(
@@ -4265,9 +4712,9 @@ var reposCommand = new Command11("repos").description("List tracked repositories
4265
4712
  });
4266
4713
 
4267
4714
  // src/commands/setup-audio.ts
4268
- import { Command as Command12 } from "commander";
4269
- import { copyFile, mkdir as mkdir12, readFile as readFile13, writeFile as writeFile11, access as access5 } from "fs/promises";
4270
- import { homedir as homedir10, platform } from "os";
4715
+ import { Command as Command13 } from "commander";
4716
+ import { copyFile, mkdir as mkdir13, readFile as readFile14, writeFile as writeFile12, access as access6 } from "fs/promises";
4717
+ import { homedir as homedir12, platform } from "os";
4271
4718
 
4272
4719
  // src/lib/setup-audio.ts
4273
4720
  async function setupAudio(deps) {
@@ -4362,16 +4809,16 @@ function createDefaultSetupAudioDeps() {
4362
4809
  const exec = createExecutor();
4363
4810
  return {
4364
4811
  platform: platform(),
4365
- homeDir: homedir10(),
4812
+ homeDir: homedir12(),
4366
4813
  execute: exec,
4367
- readFile: (path, encoding) => readFile13(path, encoding),
4368
- writeFile: (path, content, encoding) => writeFile11(path, content, encoding),
4814
+ readFile: (path, encoding) => readFile14(path, encoding),
4815
+ writeFile: (path, content, encoding) => writeFile12(path, content, encoding),
4369
4816
  copyFile,
4370
- mkdir: (path, opts) => mkdir12(path, opts),
4371
- access: (path) => access5(path)
4817
+ mkdir: (path, opts) => mkdir13(path, opts),
4818
+ access: (path) => access6(path)
4372
4819
  };
4373
4820
  }
4374
- var setupAudioCommand = new Command12("setup-audio").description("Configure macOS PulseAudio for audio passthrough to containers").action(async () => {
4821
+ var setupAudioCommand = new Command13("setup-audio").description("Configure macOS PulseAudio for audio passthrough to containers").action(async () => {
4375
4822
  const deps = createDefaultSetupAudioDeps();
4376
4823
  const result = await setupAudio(deps);
4377
4824
  if (!result.ok) {
@@ -4391,9 +4838,9 @@ var setupAudioCommand = new Command12("setup-audio").description("Configure macO
4391
4838
  });
4392
4839
 
4393
4840
  // src/commands/shutdown.ts
4394
- import chalk4 from "chalk";
4395
- import { Command as Command13 } from "commander";
4396
- var shutdownCommand = new Command13("shutdown").description("Gracefully shut down an instance (save tmux state, stop container)").argument("<name>", "Instance name to shut down").option("--yes", "Skip confirmation prompt").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
4841
+ import chalk5 from "chalk";
4842
+ import { Command as Command14 } from "commander";
4843
+ var shutdownCommand = new Command14("shutdown").description("Gracefully shut down an instance (save tmux state, stop container)").argument("<name>", "Instance name to shut down").option("--yes", "Skip confirmation prompt").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
4397
4844
  const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
4398
4845
  if (!options.yes && process.stdin.isTTY) {
4399
4846
  const confirmed = await promptForConfirmation(
@@ -4415,7 +4862,7 @@ Shutdown '${name}'? This will stop the container. (y/N) `
4415
4862
  process.exit(1);
4416
4863
  return;
4417
4864
  }
4418
- console.log(`${chalk4.green("\u2713")} Instance '${name}' shut down`);
4865
+ console.log(`${chalk5.green("\u2713")} Instance '${name}' shut down`);
4419
4866
  if (result.tmuxSaved) {
4420
4867
  console.log(" Tmux session state saved");
4421
4868
  }
@@ -4427,16 +4874,16 @@ Shutdown '${name}'? This will stop the container. (y/N) `
4427
4874
  });
4428
4875
 
4429
4876
  // src/commands/tmux-restore.ts
4430
- import { Command as Command14 } from "commander";
4877
+ import { Command as Command15 } from "commander";
4431
4878
  import { execSync } from "child_process";
4432
- import { join as join12 } from "path";
4879
+ import { join as join14 } from "path";
4433
4880
 
4434
4881
  // src/lib/tmux-session.ts
4435
- import { readFile as readFile14, writeFile as writeFile12, rename as rename9, mkdir as mkdir13 } from "fs/promises";
4436
- import { dirname as dirname3, join as join11 } from "path";
4882
+ import { readFile as readFile15, writeFile as writeFile13, rename as rename9, mkdir as mkdir14 } from "fs/promises";
4883
+ import { dirname as dirname4, join as join13 } from "path";
4437
4884
  async function readPanesState(path) {
4438
4885
  try {
4439
- const content = await readFile14(path, "utf-8");
4886
+ const content = await readFile15(path, "utf-8");
4440
4887
  const parsed = JSON.parse(content);
4441
4888
  if (typeof parsed === "object" && parsed !== null && parsed.version === 1) {
4442
4889
  return parsed;
@@ -4447,14 +4894,14 @@ async function readPanesState(path) {
4447
4894
  }
4448
4895
  }
4449
4896
  async function writePanesState(path, state) {
4450
- await mkdir13(dirname3(path), { recursive: true });
4897
+ await mkdir14(dirname4(path), { recursive: true });
4451
4898
  const tmpPath = path + ".tmp";
4452
- await writeFile12(tmpPath, JSON.stringify(state), "utf-8");
4899
+ await writeFile13(tmpPath, JSON.stringify(state), "utf-8");
4453
4900
  await rename9(tmpPath, path);
4454
4901
  }
4455
4902
  async function readSessionState(path) {
4456
4903
  try {
4457
- const content = await readFile14(path, "utf-8");
4904
+ const content = await readFile15(path, "utf-8");
4458
4905
  const parsed = JSON.parse(content);
4459
4906
  if (typeof parsed === "object" && parsed !== null && parsed.version === 1 && Array.isArray(parsed.windows)) {
4460
4907
  return parsed;
@@ -4465,9 +4912,9 @@ async function readSessionState(path) {
4465
4912
  }
4466
4913
  }
4467
4914
  async function writeSessionState(path, state) {
4468
- await mkdir13(dirname3(path), { recursive: true });
4915
+ await mkdir14(dirname4(path), { recursive: true });
4469
4916
  const tmpPath = path + ".tmp";
4470
- await writeFile12(tmpPath, JSON.stringify(state, null, 2), "utf-8");
4917
+ await writeFile13(tmpPath, JSON.stringify(state, null, 2), "utf-8");
4471
4918
  await rename9(tmpPath, path);
4472
4919
  }
4473
4920
  function pruneStaleEntries(state, activePaneIds) {
@@ -4484,7 +4931,7 @@ function pruneStaleEntries(state, activePaneIds) {
4484
4931
  function resolveTmuxStateDir(agentInstance) {
4485
4932
  const instance = agentInstance || process.env.AGENT_INSTANCE;
4486
4933
  if (!instance) return null;
4487
- return join11("/shared-data/instance", instance, "tmux");
4934
+ return join13("/shared-data/instance", instance, "tmux");
4488
4935
  }
4489
4936
 
4490
4937
  // src/commands/tmux-restore.ts
@@ -4520,7 +4967,7 @@ function ensureTmuxSession(savedName) {
4520
4967
  async function executeTmuxRestore() {
4521
4968
  const stateDir = resolveTmuxStateDir();
4522
4969
  if (!stateDir) return;
4523
- const sessionState = await readSessionState(join12(stateDir, "session.json"));
4970
+ const sessionState = await readSessionState(join14(stateDir, "session.json"));
4524
4971
  if (!sessionState) return;
4525
4972
  const sessionName = ensureTmuxSession(sessionState.tmux_session);
4526
4973
  const quotedSession = shellQuote(sessionName);
@@ -4547,7 +4994,7 @@ async function executeTmuxRestore() {
4547
4994
  }
4548
4995
  }
4549
4996
  }
4550
- var tmuxRestoreCommand = new Command14("tmux-restore").description("Restore tmux session state from saved state (container only)").action(async () => {
4997
+ var tmuxRestoreCommand = new Command15("tmux-restore").description("Restore tmux session state from saved state (container only)").action(async () => {
4551
4998
  try {
4552
4999
  await executeTmuxRestore();
4553
5000
  } catch {
@@ -4555,14 +5002,14 @@ var tmuxRestoreCommand = new Command14("tmux-restore").description("Restore tmux
4555
5002
  });
4556
5003
 
4557
5004
  // src/commands/tmux-save.ts
4558
- import { Command as Command15 } from "commander";
5005
+ import { Command as Command16 } from "commander";
4559
5006
  import { execSync as execSync2 } from "child_process";
4560
5007
  import { unlink as unlink2 } from "fs/promises";
4561
- import { join as join13 } from "path";
5008
+ import { join as join15 } from "path";
4562
5009
  async function executeTmuxSave() {
4563
5010
  const stateDir = resolveTmuxStateDir();
4564
5011
  if (!stateDir) return;
4565
- const sessionPath = join13(stateDir, "session.json");
5012
+ const sessionPath = join15(stateDir, "session.json");
4566
5013
  let tmuxOutput;
4567
5014
  try {
4568
5015
  tmuxOutput = execSync2(
@@ -4590,7 +5037,7 @@ async function executeTmuxSave() {
4590
5037
  });
4591
5038
  return;
4592
5039
  }
4593
- const panesPath = join13(stateDir, "claude-sessions.json");
5040
+ const panesPath = join15(stateDir, "claude-sessions.json");
4594
5041
  const panesState = await readPanesState(panesPath);
4595
5042
  let activeWindow = 1;
4596
5043
  try {
@@ -4633,7 +5080,7 @@ async function executeTmuxSave() {
4633
5080
  const pruned = pruneStaleEntries(panesState, activePaneIds);
4634
5081
  await writePanesState(panesPath, pruned);
4635
5082
  }
4636
- var tmuxSaveCommand = new Command15("tmux-save").description("Save current tmux session state for persistence across rebuilds (container only)").action(async () => {
5083
+ var tmuxSaveCommand = new Command16("tmux-save").description("Save current tmux session state for persistence across rebuilds (container only)").action(async () => {
4637
5084
  try {
4638
5085
  await executeTmuxSave();
4639
5086
  } catch {
@@ -4641,12 +5088,12 @@ var tmuxSaveCommand = new Command15("tmux-save").description("Save current tmux
4641
5088
  });
4642
5089
 
4643
5090
  // src/commands/tmux-status.ts
4644
- import { Command as Command16 } from "commander";
5091
+ import { Command as Command17 } from "commander";
4645
5092
 
4646
5093
  // src/lib/tmux-status.ts
4647
- import { readFile as readFile15 } from "fs/promises";
5094
+ import { readFile as readFile16 } from "fs/promises";
4648
5095
  var MAX_PURPOSE_DISPLAY_LEN = 40;
4649
- var defaultDeps2 = { readFile: readFile15 };
5096
+ var defaultDeps3 = { readFile: readFile16 };
4650
5097
  function formatTmuxStatus(instance, purpose) {
4651
5098
  if (!instance) return "?";
4652
5099
  if (!purpose) return instance;
@@ -4655,7 +5102,7 @@ function formatTmuxStatus(instance, purpose) {
4655
5102
  }
4656
5103
  return `${instance} | ${purpose}`;
4657
5104
  }
4658
- async function getTmuxStatus(statePath, deps = defaultDeps2) {
5105
+ async function getTmuxStatus(statePath, deps = defaultDeps3) {
4659
5106
  let content;
4660
5107
  try {
4661
5108
  content = await deps.readFile(statePath, "utf-8");
@@ -4676,13 +5123,13 @@ async function getTmuxStatus(statePath, deps = defaultDeps2) {
4676
5123
  }
4677
5124
 
4678
5125
  // src/commands/tmux-status.ts
4679
- var defaultDeps3 = {
5126
+ var defaultDeps4 = {
4680
5127
  isInsideContainer,
4681
5128
  getTmuxStatus,
4682
5129
  statePath: CONTAINER_STATE_PATH
4683
5130
  };
4684
- function createTmuxStatusCommand(deps = defaultDeps3) {
4685
- return new Command16("tmux-status").description("Output formatted instance status for tmux status bar (container only)").action(async () => {
5131
+ function createTmuxStatusCommand(deps = defaultDeps4) {
5132
+ return new Command17("tmux-status").description("Output formatted instance status for tmux status bar (container only)").action(async () => {
4686
5133
  if (!deps.isInsideContainer()) {
4687
5134
  console.log("?");
4688
5135
  return;
@@ -4693,108 +5140,14 @@ function createTmuxStatusCommand(deps = defaultDeps3) {
4693
5140
  }
4694
5141
  var tmuxStatusCommand = createTmuxStatusCommand();
4695
5142
 
4696
- // src/lib/update-check.ts
4697
- import chalk5 from "chalk";
4698
- import * as fs from "fs/promises";
4699
- import { dirname as dirname4 } from "path";
4700
- function normaliseVersion(version2) {
4701
- const withoutBuild = version2.split("+")[0];
4702
- const withoutPre = withoutBuild.split("-")[0];
4703
- return withoutPre;
4704
- }
4705
- function isNewerVersion(current, registry) {
4706
- const normCurrent = normaliseVersion(current);
4707
- const normRegistry = normaliseVersion(registry);
4708
- const currentParts = normCurrent.split(".").map(Number);
4709
- const registryParts = normRegistry.split(".").map(Number);
4710
- const len = Math.max(currentParts.length, registryParts.length);
4711
- for (let i = 0; i < len; i++) {
4712
- const c = currentParts[i] ?? 0;
4713
- const r = registryParts[i] ?? 0;
4714
- if (r > c) return true;
4715
- if (r < c) return false;
4716
- }
4717
- return false;
4718
- }
4719
- async function readCache(cachePath, readFileFn) {
4720
- try {
4721
- const raw = await readFileFn(cachePath, "utf-8");
4722
- const parsed = JSON.parse(raw);
4723
- if (parsed !== null && typeof parsed === "object" && "lastCheck" in parsed && "latestVersion" in parsed && typeof parsed.lastCheck === "number" && typeof parsed.latestVersion === "string") {
4724
- return parsed;
4725
- }
4726
- return null;
4727
- } catch {
4728
- return null;
4729
- }
4730
- }
4731
- async function writeCache(cachePath, data, mkdirFn, writeFileFn) {
4732
- try {
4733
- await mkdirFn(dirname4(cachePath), { recursive: true });
4734
- await writeFileFn(cachePath, JSON.stringify(data), "utf-8");
4735
- } catch {
4736
- }
4737
- }
4738
- async function fetchLatestVersion(packageName, fetchFn) {
4739
- try {
4740
- const url = `https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`;
4741
- const response = await fetchFn(url, {
4742
- headers: { Accept: "application/json" },
4743
- signal: AbortSignal.timeout(5e3)
4744
- });
4745
- const json = await response.json();
4746
- if (json !== null && typeof json === "object" && "version" in json && typeof json.version === "string") {
4747
- return json.version;
4748
- }
4749
- return null;
4750
- } catch {
4751
- return null;
4752
- }
4753
- }
4754
- function formatUpdateMessage(currentVersion, latestVersion, packageName) {
4755
- const normCurrent = normaliseVersion(currentVersion);
4756
- const line1 = chalk5.yellow(`Update available: ${normCurrent} -> ${latestVersion}`);
4757
- const line2 = chalk5.cyan(`Run: pnpm add -g ${packageName}`);
4758
- return `${line1}
4759
- ${line2}`;
4760
- }
4761
- async function checkForUpdate(opts) {
4762
- const {
4763
- currentVersion,
4764
- packageName,
4765
- cachePath,
4766
- cacheTtlMs,
4767
- fetchFn = fetch,
4768
- readFile: readFile17 = (p, enc) => fs.readFile(p, enc),
4769
- writeFile: writeFile14 = (p, d, enc) => fs.writeFile(p, d, enc),
4770
- mkdir: mkdir15 = (p, o) => fs.mkdir(p, o),
4771
- now = () => Date.now()
4772
- } = opts;
4773
- const currentTime = now();
4774
- const cache = await readCache(cachePath, readFile17);
4775
- let latestVersion = null;
4776
- const isCacheFresh = cache !== null && currentTime - cache.lastCheck < cacheTtlMs;
4777
- if (isCacheFresh) {
4778
- latestVersion = cache.latestVersion;
4779
- } else {
4780
- latestVersion = await fetchLatestVersion(packageName, fetchFn);
4781
- if (latestVersion !== null) {
4782
- await writeCache(cachePath, { lastCheck: currentTime, latestVersion }, mkdir15, writeFile14);
4783
- }
4784
- }
4785
- if (latestVersion !== null && isNewerVersion(currentVersion, latestVersion)) {
4786
- return formatUpdateMessage(currentVersion, latestVersion, packageName);
4787
- }
4788
- return null;
4789
- }
4790
-
4791
5143
  // src/cli.ts
4792
5144
  var __dirname = dirname5(fileURLToPath2(import.meta.url));
4793
- var isLinked = existsSync(resolve(__dirname, "..", "..", "..", "pnpm-workspace.yaml"));
5145
+ var isLinked = existsSync2(resolve(__dirname, "..", "..", "..", "pnpm-workspace.yaml"));
4794
5146
  var isBakedDev = resolve(__dirname, "..").startsWith("/opt/agent-env-dev");
4795
5147
  var version = package_default.version + (isLinked ? "+local" : isBakedDev ? "+dev" : "");
4796
5148
  program.name("agent-env").description("CLI for creating isolated, AI-ready development environments").version(version).allowExcessArguments(true);
4797
5149
  program.addCommand(createCommand);
5150
+ program.addCommand(envCommand);
4798
5151
  program.addCommand(listCommand);
4799
5152
  program.addCommand(attachCommand);
4800
5153
  program.addCommand(pathCommand);
@@ -4841,8 +5194,8 @@ program.action(async () => {
4841
5194
  value: inst.name
4842
5195
  }));
4843
5196
  const { unmount } = render3(
4844
- React4.createElement(() => {
4845
- return React4.createElement(Select2, {
5197
+ React5.createElement(() => {
5198
+ return React5.createElement(Select2, {
4846
5199
  options,
4847
5200
  onChange: (value) => {
4848
5201
  unmount();
@@ -4868,7 +5221,7 @@ var shouldCheck = !!process.stderr.isTTY && !isInsideContainer() && !isLinked &&
4868
5221
  var updateCheckPromise = shouldCheck ? checkForUpdate({
4869
5222
  currentVersion: package_default.version,
4870
5223
  packageName: package_default.name,
4871
- cachePath: join14(homedir11(), ".agent-env", "update-check.json"),
5224
+ cachePath: join16(homedir13(), ".agent-env", "update-check.json"),
4872
5225
  cacheTtlMs: 36e5
4873
5226
  }) : Promise.resolve(null);
4874
5227
  async function main() {