@zookanalytics/agent-env 0.9.0 → 0.10.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.
@@ -14,18 +14,29 @@ if [ ! -f "$GITCONFIG" ]; then
14
14
  touch "$GITCONFIG"
15
15
  fi
16
16
 
17
- # Stage only SSH public keys for container mount (never expose private keys)
17
+ # Stage only SSH public keys for container mount (never expose private keys).
18
+ # Non-fatal — SSH agent socket provides auth; pub keys are only for sshd authorized_keys.
18
19
  SSH_PUB_DIR="$HOME/.agent-env/ssh-pub-keys"
19
20
  mkdir -p "$SSH_PUB_DIR"
20
- rm -f "$SSH_PUB_DIR"/*.pub 2>/dev/null || true
21
21
  if ls "$HOME/.ssh/"*.pub &>/dev/null; then
22
- cp -p "$HOME/.ssh/"*.pub "$SSH_PUB_DIR/"
23
- echo "agent-env: Staged SSH public keys:"
24
- for f in "$SSH_PUB_DIR"/*.pub; do
25
- echo " - $(basename "$f")"
26
- done
22
+ # Atomic replace: copy to temp dir, then swap
23
+ STAGING_TMP="$SSH_PUB_DIR/.staging.$$"
24
+ mkdir -p "$STAGING_TMP"
25
+ if cp -p "$HOME/.ssh/"*.pub "$STAGING_TMP/" 2>/dev/null; then
26
+ rm -f "$SSH_PUB_DIR"/*.pub 2>/dev/null || true
27
+ mv "$STAGING_TMP"/*.pub "$SSH_PUB_DIR/" 2>/dev/null || true
28
+ echo "agent-env: Staged SSH public keys:"
29
+ for f in "$SSH_PUB_DIR"/*.pub; do
30
+ [ -f "$f" ] && echo " - $(basename "$f")"
31
+ done
32
+ else
33
+ rm -f "$SSH_PUB_DIR"/*.pub 2>/dev/null || true
34
+ echo "agent-env: Warning: Failed to stage SSH public keys — cleared stale keys (non-fatal)"
35
+ fi
36
+ rm -rf "$STAGING_TMP" 2>/dev/null || true
27
37
  else
28
- echo "agent-env: Warning: No SSH public keys found in ~/.ssh. SSH access will require manual setup."
38
+ rm -f "$SSH_PUB_DIR"/*.pub 2>/dev/null || true
39
+ echo "agent-env: Warning: No SSH public keys found in ~/.ssh — cleared stale keys. SSH access will require manual setup."
29
40
  fi
30
41
 
31
42
  # Stage PulseAudio cookie for audio passthrough (if setup-audio was run)
package/dist/cli.js CHANGED
@@ -47,16 +47,17 @@ var execute = createExecutor();
47
47
 
48
48
  // src/cli.ts
49
49
  import { program } from "commander";
50
- import { render as render2 } from "ink";
50
+ import { render as render3 } from "ink";
51
51
  import { existsSync } from "fs";
52
- import { dirname as dirname4, resolve } from "path";
52
+ import { homedir as homedir10 } from "os";
53
+ import { dirname as dirname5, join as join14, resolve } from "path";
53
54
  import { fileURLToPath as fileURLToPath2 } from "url";
54
- import React3 from "react";
55
+ import React4 from "react";
55
56
 
56
57
  // package.json
57
58
  var package_default = {
58
59
  name: "@zookanalytics/agent-env",
59
- version: "0.9.0",
60
+ version: "0.10.0",
60
61
  description: "CLI for creating isolated, AI-ready development environments",
61
62
  type: "module",
62
63
  bin: {
@@ -438,7 +439,7 @@ import { dirname as dirname2, join as join6 } from "path";
438
439
  // src/lib/devcontainer-merge.ts
439
440
  import { parse as parseJsonc2 } from "jsonc-parser";
440
441
  import { constants } from "fs";
441
- import { access as access2, readFile as readFile2, rename, writeFile as writeFile2 } from "fs/promises";
442
+ import { access as access2, lstat, readFile as readFile2, readlink, rename, writeFile as writeFile2 } from "fs/promises";
442
443
  import { createRequire } from "module";
443
444
  import { join as join2 } from "path";
444
445
 
@@ -614,11 +615,18 @@ function parseDockerfileImages(content, logger) {
614
615
  }
615
616
 
616
617
  // src/lib/devcontainer-merge.ts
617
- var defaultMergeDeps = { readFile: readFile2, writeFile: writeFile2, rename, access: access2 };
618
+ var defaultMergeDeps = {
619
+ readFile: readFile2,
620
+ writeFile: writeFile2,
621
+ rename,
622
+ access: access2,
623
+ lstat,
624
+ readlink
625
+ };
618
626
  var STATUS_BAR_JSON_FILENAME = "statusBar.json";
619
627
  var LABEL_LIFECYCLE_CMDS = {
620
628
  postCreateCommand: "/usr/local/bin/post-create.sh",
621
- postStartCommand: "sudo /usr/local/bin/start-sshd.sh; tmux new-session -d -s agent-env 2>/dev/null || true; agent-env tmux-restore 2>/dev/null || true; : > /tmp/install-shared-skills.log; /usr/local/bin/install-shared-skills.sh >> /tmp/install-shared-skills.log 2>&1 || true"
629
+ postStartCommand: "sudo /usr/local/bin/start-sshd.sh; /home/node/.local/bin/tmux-session --detached || true; : > /tmp/install-shared-skills.log; /usr/local/bin/install-shared-skills.sh >> /tmp/install-shared-skills.log 2>&1 || true"
622
630
  };
623
631
  var COMPOSABLE_LIFECYCLE_CMDS = [
624
632
  "postCreateCommand",
@@ -635,6 +643,21 @@ async function readRepoConfig(workspacePath, deps = defaultMergeDeps, logger) {
635
643
  join2(workspacePath, ".devcontainer.json")
636
644
  ];
637
645
  for (const candidate of candidates) {
646
+ if (deps.lstat && deps.readlink) {
647
+ try {
648
+ const linkStat = await deps.lstat(candidate);
649
+ if (linkStat.isSymbolicLink()) {
650
+ const target = await deps.readlink(candidate);
651
+ if (target.includes(AGENT_ENV_DIR)) {
652
+ logger?.warn(
653
+ `Skipping symlink to agent-env config at ${candidate} \u2014 not a repo config`
654
+ );
655
+ continue;
656
+ }
657
+ }
658
+ } catch {
659
+ }
660
+ }
638
661
  let content;
639
662
  try {
640
663
  await deps.access(candidate, constants.F_OK);
@@ -1941,11 +1964,11 @@ import { Command as Command2 } from "commander";
1941
1964
  // src/lib/code-instance.ts
1942
1965
  import {
1943
1966
  appendFile as appendFile5,
1944
- lstat,
1967
+ lstat as lstat2,
1945
1968
  mkdir as mkdir7,
1946
1969
  readdir as readdir6,
1947
1970
  readFile as readFile9,
1948
- readlink,
1971
+ readlink as readlink2,
1949
1972
  rename as rename6,
1950
1973
  stat as stat6,
1951
1974
  symlink,
@@ -1953,7 +1976,7 @@ import {
1953
1976
  writeFile as writeFile8
1954
1977
  } from "fs/promises";
1955
1978
  import { homedir as homedir5 } from "os";
1956
- import { join as join8, relative } from "path";
1979
+ import { join as join8 } from "path";
1957
1980
  function createCodeDefaultDeps() {
1958
1981
  const executor = createExecutor();
1959
1982
  return {
@@ -1961,14 +1984,13 @@ function createCodeDefaultDeps() {
1961
1984
  container: createContainerLifecycle(executor),
1962
1985
  workspaceFsDeps: { mkdir: mkdir7, readdir: readdir6, stat: stat6, homedir: homedir5 },
1963
1986
  stateFsDeps: { readFile: readFile9, writeFile: writeFile8, rename: rename6, mkdir: mkdir7, appendFile: appendFile5 },
1964
- codeFsDeps: { mkdir: mkdir7, lstat, symlink, readlink, unlink }
1987
+ codeFsDeps: { lstat: lstat2, symlink, readlink: readlink2, unlink }
1965
1988
  };
1966
1989
  }
1967
1990
  var DEVCONTAINER_OPEN_TIMEOUT = 3e4;
1968
- async function ensureDevcontainerSymlink(wsRoot, deps) {
1969
- const devcontainerDir = join8(wsRoot, ".devcontainer");
1970
- const symlinkPath = join8(devcontainerDir, "devcontainer.json");
1971
- const target = relative(devcontainerDir, join8(wsRoot, AGENT_ENV_DIR, "devcontainer.json"));
1991
+ async function ensureConfigSymlink(wsRoot, deps) {
1992
+ const symlinkPath = join8(wsRoot, ".devcontainer.json");
1993
+ const target = join8(AGENT_ENV_DIR, "devcontainer.json");
1972
1994
  try {
1973
1995
  const linkStat = await deps.lstat(symlinkPath);
1974
1996
  if (linkStat.isSymbolicLink()) {
@@ -1981,9 +2003,17 @@ async function ensureDevcontainerSymlink(wsRoot, deps) {
1981
2003
  } catch (err) {
1982
2004
  if (err.code !== "ENOENT") throw err;
1983
2005
  }
1984
- await deps.mkdir(devcontainerDir, { recursive: true });
1985
2006
  await deps.symlink(target, symlinkPath);
1986
2007
  }
2008
+ async function removeConfigSymlink(wsRoot, deps) {
2009
+ const symlinkPath = join8(wsRoot, ".devcontainer.json");
2010
+ try {
2011
+ const linkStat = await deps.lstat(symlinkPath);
2012
+ if (!linkStat.isSymbolicLink()) return;
2013
+ await deps.unlink(symlinkPath);
2014
+ } catch {
2015
+ }
2016
+ }
1987
2017
  async function codeInstance(instanceName, deps, onContainerStarting, onOpening, repoSlug) {
1988
2018
  const lookup = await resolveInstance(instanceName, repoSlug, {
1989
2019
  fsDeps: deps.workspaceFsDeps,
@@ -2034,9 +2064,10 @@ async function codeInstance(instanceName, deps, onContainerStarting, onOpening,
2034
2064
  };
2035
2065
  }
2036
2066
  }
2037
- if (!state.repoConfigDetected) {
2067
+ const needsSymlink = !state.repoConfigDetected;
2068
+ if (needsSymlink) {
2038
2069
  try {
2039
- await ensureDevcontainerSymlink(wsPath.root, deps.codeFsDeps);
2070
+ await ensureConfigSymlink(wsPath.root, deps.codeFsDeps);
2040
2071
  } catch (err) {
2041
2072
  const detail = err instanceof Error ? err.message : String(err);
2042
2073
  return {
@@ -2049,12 +2080,19 @@ async function codeInstance(instanceName, deps, onContainerStarting, onOpening,
2049
2080
  };
2050
2081
  }
2051
2082
  }
2052
- onOpening?.();
2053
- const openResult = await deps.executor(
2054
- "devcontainer",
2055
- ["open", wsPath.root, "--config", configPath],
2056
- { stdio: "inherit", timeout: DEVCONTAINER_OPEN_TIMEOUT }
2057
- );
2083
+ let openResult;
2084
+ try {
2085
+ onOpening?.();
2086
+ openResult = await deps.executor(
2087
+ "devcontainer",
2088
+ ["open", wsPath.root, "--config", configPath],
2089
+ { stdio: "inherit", timeout: DEVCONTAINER_OPEN_TIMEOUT }
2090
+ );
2091
+ } finally {
2092
+ if (needsSymlink) {
2093
+ await removeConfigSymlink(wsPath.root, deps.codeFsDeps);
2094
+ }
2095
+ }
2058
2096
  if (!openResult.ok) {
2059
2097
  return {
2060
2098
  ok: false,
@@ -2826,6 +2864,31 @@ function parseBranches(result) {
2826
2864
  }
2827
2865
 
2828
2866
  // src/lib/list-instances.ts
2867
+ async function getInstanceInfo(workspaceName, deps) {
2868
+ const container = deps?.container ?? createContainerLifecycle();
2869
+ const wsFsDeps = deps?.workspaceFsDeps;
2870
+ const stateFsDeps = deps?.stateFsDeps;
2871
+ const wsPath = getWorkspacePathByName(workspaceName, wsFsDeps);
2872
+ const state = await readState(wsPath, stateFsDeps);
2873
+ const dockerAvailable = await container.isDockerAvailable();
2874
+ const containerResult = dockerAvailable ? await container.containerStatus(state.containerName) : null;
2875
+ let status;
2876
+ if (!dockerAvailable || containerResult === null) {
2877
+ status = "unknown";
2878
+ } else if (!containerResult.ok) {
2879
+ status = "unknown";
2880
+ } else if (containerResult.status === "not-found") {
2881
+ status = "orphaned";
2882
+ } else {
2883
+ status = containerResult.status;
2884
+ }
2885
+ return {
2886
+ name: workspaceName,
2887
+ repoSlug: state.repoSlug,
2888
+ purpose: state.purpose,
2889
+ status
2890
+ };
2891
+ }
2829
2892
  async function listInstances(deps, opts) {
2830
2893
  try {
2831
2894
  const container = deps?.container ?? createContainerLifecycle();
@@ -2951,90 +3014,137 @@ var listCommand = new Command5("list").alias("ps").description("List all instanc
2951
3014
  await waitUntilExit();
2952
3015
  });
2953
3016
 
2954
- // src/commands/purpose.ts
3017
+ // src/commands/on.ts
2955
3018
  import { Command as Command6 } from "commander";
2956
- var defaultPurposeCommandDeps = {
2957
- isInsideContainer
2958
- };
2959
- function createPurposeCommand(deps = defaultPurposeCommandDeps) {
2960
- return new Command6("purpose").description(
2961
- "Get or set the purpose/label for an instance. Inside a container: no instance name needed (agent-env purpose [value])"
2962
- ).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) => {
2963
- if (deps.isInsideContainer()) {
2964
- await handleContainerMode(nameOrValue);
2965
- } else {
2966
- await handleHostMode(nameOrValue, value, options?.repo);
3019
+
3020
+ // src/lib/interactive-menu.ts
3021
+ async function launchActionLoop(workspaceName, deps, repoSlug) {
3022
+ while (true) {
3023
+ try {
3024
+ const instanceInfo = await deps.getInstanceInfo(workspaceName);
3025
+ const { action, purposeValue } = await deps.renderMenu(instanceInfo);
3026
+ if (action === "exit") {
3027
+ break;
3028
+ }
3029
+ let result;
3030
+ switch (action) {
3031
+ case "attach":
3032
+ result = await deps.attachInstance(workspaceName, repoSlug);
3033
+ break;
3034
+ case "code":
3035
+ result = await deps.codeInstance(workspaceName, repoSlug);
3036
+ break;
3037
+ case "rebuild":
3038
+ result = await deps.rebuildInstance(workspaceName, repoSlug);
3039
+ break;
3040
+ case "set-purpose":
3041
+ result = await deps.setPurpose(workspaceName, purposeValue ?? "", repoSlug);
3042
+ break;
3043
+ }
3044
+ if (!result.ok && result.error) {
3045
+ const { code, message, suggestion } = result.error;
3046
+ console.error(formatError(createError(code, message, suggestion)));
3047
+ }
3048
+ } catch (err) {
3049
+ const message = err instanceof Error ? err.message : String(err);
3050
+ console.error(formatError(createError("ACTION_ERROR", message)));
2967
3051
  }
2968
- });
2969
- }
2970
- var purposeCommand = createPurposeCommand();
2971
- async function handleContainerMode(purposeValue) {
2972
- const deps = createContainerPurposeDefaultDeps();
2973
- if (purposeValue === void 0) {
2974
- const result = await getContainerPurpose(deps);
2975
- handleGetResult(result);
2976
- } else {
2977
- const result = await setContainerPurpose(purposeValue, deps);
2978
- handleSetResult(result);
2979
3052
  }
2980
3053
  }
2981
- async function handleHostMode(name, value, repo) {
2982
- if (!name) {
3054
+ async function launchInstancePicker(deps) {
3055
+ const listResult = await deps.listInstances();
3056
+ if (!listResult.ok) {
3057
+ const { code, message } = listResult.error;
2983
3058
  console.error(
2984
- formatError(
2985
- createError(
2986
- "MISSING_ARGUMENT",
2987
- "Instance name is required when running on the host",
2988
- "Usage: agent-env purpose <name> [value]"
2989
- )
2990
- )
3059
+ formatError(createError(code, message, "Check if ~/.agent-env/workspaces/ is accessible."))
2991
3060
  );
2992
- process.exit(1);
2993
- return;
3061
+ return { kind: "error" };
2994
3062
  }
2995
- const repoSlug = await resolveRepoOrExit({ repo, cwd: process.cwd() });
2996
- const deps = createPurposeDefaultDeps();
2997
- if (value === void 0) {
2998
- const result = await getPurpose(name, deps, repoSlug);
2999
- handleGetResult(result);
3000
- } else {
3001
- const result = await setPurpose(name, value, deps, repoSlug);
3002
- handleSetResult(result);
3063
+ const selected = await deps.renderPicker(listResult.instances);
3064
+ if (selected === null) {
3065
+ return { kind: "cancelled" };
3003
3066
  }
3067
+ return { kind: "selected", name: selected };
3004
3068
  }
3005
- function handleGetResult(result) {
3006
- if (!result.ok) {
3007
- const { code, message, suggestion } = result.error;
3008
- console.error(formatError(createError(code, message, suggestion)));
3009
- process.exit(1);
3010
- }
3011
- if (result.purpose === null) {
3012
- console.log("(no purpose set)");
3013
- } else {
3014
- console.log(result.purpose);
3069
+
3070
+ // src/lib/menu-deps.ts
3071
+ import { render as render2 } from "ink";
3072
+ import React3 from "react";
3073
+
3074
+ // src/components/InteractiveMenu.tsx
3075
+ import { Select, TextInput } from "@inkjs/ui";
3076
+ import { Box as Box2, Text as Text3, useInput } from "ink";
3077
+ import { useState } from "react";
3078
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
3079
+ function statusSymbol(status) {
3080
+ switch (status) {
3081
+ case "running":
3082
+ return "\u25B6";
3083
+ case "stopped":
3084
+ return "\u25A0";
3085
+ case "orphaned":
3086
+ case "not-found":
3087
+ return "\u2717";
3088
+ case "unknown":
3089
+ return "?";
3015
3090
  }
3016
3091
  }
3017
- function handleSetResult(result) {
3018
- if (!result.ok) {
3019
- const { code, message, suggestion } = result.error;
3020
- console.error(formatError(createError(code, message, suggestion)));
3021
- process.exit(1);
3022
- }
3023
- if (result.cleared) {
3024
- console.log("Purpose cleared");
3025
- } else {
3026
- console.log("Purpose updated");
3027
- }
3028
- if (result.warning) {
3029
- console.warn(`\x1B[33m\u26A0\x1B[0m ${result.warning}`);
3092
+ function PurposeInput({
3093
+ onSubmit,
3094
+ onCancel
3095
+ }) {
3096
+ useInput((_input, key) => {
3097
+ if (key.escape) {
3098
+ onCancel();
3099
+ }
3100
+ });
3101
+ return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
3102
+ /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsxs3(Text3, { children: [
3103
+ /* @__PURE__ */ jsx3(Text3, { bold: true, children: "Purpose:" }),
3104
+ " ",
3105
+ /* @__PURE__ */ jsx3(Text3, { color: "gray", children: "(Escape to cancel)" })
3106
+ ] }) }),
3107
+ /* @__PURE__ */ jsx3(TextInput, { placeholder: "Enter purpose...", onSubmit })
3108
+ ] });
3109
+ }
3110
+ var ACTION_OPTIONS = [
3111
+ { label: "\u{1F680} Attach to session", value: "attach" },
3112
+ { label: "\u{1F4BB} Open in VS Code", value: "code" },
3113
+ { label: "\u{1F6E0} Rebuild container", value: "rebuild" },
3114
+ { label: "\u{1F4DD} Set Purpose", value: "set-purpose" },
3115
+ { label: "\u{1F6AA} Exit", value: "exit" }
3116
+ ];
3117
+ function InteractiveMenu({
3118
+ instanceInfo,
3119
+ onAction,
3120
+ onSetPurpose
3121
+ }) {
3122
+ const [mode, setMode] = useState("actions");
3123
+ const { name, status, repoSlug, purpose } = instanceInfo;
3124
+ const symbol = statusSymbol(status);
3125
+ const handleActionChange = (value) => {
3126
+ if (value === "set-purpose") {
3127
+ setMode("set-purpose");
3128
+ return;
3129
+ }
3130
+ onAction(value);
3131
+ };
3132
+ const handlePurposeSubmit = (value) => {
3133
+ onSetPurpose(value);
3134
+ };
3135
+ const handlePurposeCancel = () => {
3136
+ setMode("actions");
3137
+ };
3138
+ const headerParts = [name, symbol, repoSlug];
3139
+ if (purpose !== null) {
3140
+ headerParts.push(purpose);
3030
3141
  }
3142
+ return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
3143
+ /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: headerParts.join(" \xB7 ") }) }),
3144
+ mode === "actions" ? /* @__PURE__ */ jsx3(Select, { options: ACTION_OPTIONS, onChange: handleActionChange }) : /* @__PURE__ */ jsx3(PurposeInput, { onSubmit: handlePurposeSubmit, onCancel: handlePurposeCancel })
3145
+ ] });
3031
3146
  }
3032
3147
 
3033
- // src/commands/rebuild.ts
3034
- import chalk from "chalk";
3035
- import { Command as Command7 } from "commander";
3036
- import { createInterface } from "readline";
3037
-
3038
3148
  // src/lib/rebuild-instance.ts
3039
3149
  import {
3040
3150
  access as access4,
@@ -3304,7 +3414,186 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
3304
3414
  };
3305
3415
  }
3306
3416
 
3417
+ // src/lib/menu-deps.ts
3418
+ function buildMenuDeps() {
3419
+ return {
3420
+ attachInstance: (wsName, slug) => {
3421
+ const deps = createAttachDefaultDeps();
3422
+ return attachInstance(
3423
+ wsName,
3424
+ deps,
3425
+ () => console.log("Starting container..."),
3426
+ () => {
3427
+ console.log();
3428
+ console.log("Attaching to tmux session...");
3429
+ },
3430
+ slug
3431
+ );
3432
+ },
3433
+ codeInstance: (wsName, slug) => {
3434
+ const deps = createCodeDefaultDeps();
3435
+ return codeInstance(
3436
+ wsName,
3437
+ deps,
3438
+ () => console.log("Starting container..."),
3439
+ () => console.log("Opening VS Code..."),
3440
+ slug
3441
+ );
3442
+ },
3443
+ rebuildInstance: (wsName, slug) => {
3444
+ const rebuildDeps = createRebuildDefaultDeps();
3445
+ const progress = createProgressLine();
3446
+ console.log(`Rebuilding instance '${wsName}'...`);
3447
+ return rebuildInstance(
3448
+ wsName,
3449
+ rebuildDeps,
3450
+ { force: true, onProgress: progress.update },
3451
+ slug
3452
+ ).then((result) => {
3453
+ progress.clear();
3454
+ return result;
3455
+ }).catch((err) => {
3456
+ progress.clear();
3457
+ throw err;
3458
+ });
3459
+ },
3460
+ setPurpose: (wsName, value, slug) => {
3461
+ const deps = createPurposeDefaultDeps();
3462
+ return setPurpose(wsName, value, deps, slug);
3463
+ },
3464
+ getInstanceInfo: (wsName) => getInstanceInfo(wsName),
3465
+ renderMenu: (instanceInfo) => {
3466
+ return new Promise((resolve2) => {
3467
+ const { unmount, waitUntilExit } = render2(
3468
+ React3.createElement(InteractiveMenu, {
3469
+ instanceInfo,
3470
+ onAction: (action) => {
3471
+ unmount();
3472
+ resolve2({ action });
3473
+ },
3474
+ onSetPurpose: (value) => {
3475
+ unmount();
3476
+ resolve2({ action: "set-purpose", purposeValue: value });
3477
+ }
3478
+ })
3479
+ );
3480
+ void waitUntilExit();
3481
+ });
3482
+ }
3483
+ };
3484
+ }
3485
+
3486
+ // src/commands/on.ts
3487
+ 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) => {
3488
+ if (!process.stdin.isTTY) {
3489
+ console.error(
3490
+ formatError(
3491
+ createError(
3492
+ "TTY_REQUIRED",
3493
+ "The interactive menu requires a terminal (TTY).",
3494
+ "Run this command in an interactive terminal session."
3495
+ )
3496
+ )
3497
+ );
3498
+ process.exit(1);
3499
+ return;
3500
+ }
3501
+ const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
3502
+ const lookup = await resolveInstance(name, repoSlug);
3503
+ if (!lookup.found) {
3504
+ const { code, message, suggestion } = lookup.error;
3505
+ console.error(formatError(createError(code, message, suggestion)));
3506
+ process.exit(1);
3507
+ return;
3508
+ }
3509
+ const { workspaceName } = lookup;
3510
+ const menuDeps = buildMenuDeps();
3511
+ await launchActionLoop(workspaceName, menuDeps, repoSlug);
3512
+ });
3513
+
3514
+ // src/commands/purpose.ts
3515
+ import { Command as Command7 } from "commander";
3516
+ var defaultPurposeCommandDeps = {
3517
+ isInsideContainer
3518
+ };
3519
+ function createPurposeCommand(deps = defaultPurposeCommandDeps) {
3520
+ return new Command7("purpose").description(
3521
+ "Get or set the purpose/label for an instance. Inside a container: no instance name needed (agent-env purpose [value])"
3522
+ ).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) => {
3523
+ if (deps.isInsideContainer()) {
3524
+ await handleContainerMode(nameOrValue);
3525
+ } else {
3526
+ await handleHostMode(nameOrValue, value, options?.repo);
3527
+ }
3528
+ });
3529
+ }
3530
+ var purposeCommand = createPurposeCommand();
3531
+ async function handleContainerMode(purposeValue) {
3532
+ const deps = createContainerPurposeDefaultDeps();
3533
+ if (purposeValue === void 0) {
3534
+ const result = await getContainerPurpose(deps);
3535
+ handleGetResult(result);
3536
+ } else {
3537
+ const result = await setContainerPurpose(purposeValue, deps);
3538
+ handleSetResult(result);
3539
+ }
3540
+ }
3541
+ async function handleHostMode(name, value, repo) {
3542
+ if (!name) {
3543
+ console.error(
3544
+ formatError(
3545
+ createError(
3546
+ "MISSING_ARGUMENT",
3547
+ "Instance name is required when running on the host",
3548
+ "Usage: agent-env purpose <name> [value]"
3549
+ )
3550
+ )
3551
+ );
3552
+ process.exit(1);
3553
+ return;
3554
+ }
3555
+ const repoSlug = await resolveRepoOrExit({ repo, cwd: process.cwd() });
3556
+ const deps = createPurposeDefaultDeps();
3557
+ if (value === void 0) {
3558
+ const result = await getPurpose(name, deps, repoSlug);
3559
+ handleGetResult(result);
3560
+ } else {
3561
+ const result = await setPurpose(name, value, deps, repoSlug);
3562
+ handleSetResult(result);
3563
+ }
3564
+ }
3565
+ function handleGetResult(result) {
3566
+ if (!result.ok) {
3567
+ const { code, message, suggestion } = result.error;
3568
+ console.error(formatError(createError(code, message, suggestion)));
3569
+ process.exit(1);
3570
+ }
3571
+ if (result.purpose === null) {
3572
+ console.log("(no purpose set)");
3573
+ } else {
3574
+ console.log(result.purpose);
3575
+ }
3576
+ }
3577
+ function handleSetResult(result) {
3578
+ if (!result.ok) {
3579
+ const { code, message, suggestion } = result.error;
3580
+ console.error(formatError(createError(code, message, suggestion)));
3581
+ process.exit(1);
3582
+ }
3583
+ if (result.cleared) {
3584
+ console.log("Purpose cleared");
3585
+ } else {
3586
+ console.log("Purpose updated");
3587
+ }
3588
+ if (result.warning) {
3589
+ console.warn(`\x1B[33m\u26A0\x1B[0m ${result.warning}`);
3590
+ }
3591
+ }
3592
+
3307
3593
  // src/commands/rebuild.ts
3594
+ import chalk from "chalk";
3595
+ import { Command as Command8 } from "commander";
3596
+ import { createInterface } from "readline";
3308
3597
  function promptForConfirmation(instanceName) {
3309
3598
  return new Promise((resolve2) => {
3310
3599
  const rl = createInterface({
@@ -3326,7 +3615,7 @@ Any active sessions will be lost. Continue? (y/N) `,
3326
3615
  });
3327
3616
  });
3328
3617
  }
3329
- var rebuildCommand = new Command7("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(
3618
+ var rebuildCommand = new Command8("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(
3330
3619
  async (name, options) => {
3331
3620
  const deps = createRebuildDefaultDeps();
3332
3621
  const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
@@ -3379,7 +3668,7 @@ var rebuildCommand = new Command7("rebuild").description("Rebuild an instance by
3379
3668
 
3380
3669
  // src/commands/remove.ts
3381
3670
  import chalk3 from "chalk";
3382
- import { Command as Command8 } from "commander";
3671
+ import { Command as Command9 } from "commander";
3383
3672
  import { createInterface as createInterface2 } from "readline";
3384
3673
 
3385
3674
  // src/lib/audit-log.ts
@@ -3698,7 +3987,7 @@ async function resolveConfirmation(name, options) {
3698
3987
  }
3699
3988
  return "typed-name";
3700
3989
  }
3701
- var removeCommand = new Command8("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(
3990
+ var removeCommand = new Command9("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(
3702
3991
  "--yes",
3703
3992
  "Skip confirmation prompt for --force (DANGEROUS: skips all safety prompts, for scripts only)"
3704
3993
  ).action(async (name, options) => {
@@ -3761,8 +4050,8 @@ var removeCommand = new Command8("remove").description("Remove an instance with
3761
4050
  });
3762
4051
 
3763
4052
  // src/commands/repos.ts
3764
- import { Command as Command9 } from "commander";
3765
- var reposCommand = new Command9("repos").description("List tracked repositories").option("--json", "Output in JSON format").action(async (options) => {
4053
+ import { Command as Command10 } from "commander";
4054
+ var reposCommand = new Command10("repos").description("List tracked repositories").option("--json", "Output in JSON format").action(async (options) => {
3766
4055
  const result = await listRepos();
3767
4056
  if (!result.ok) {
3768
4057
  const error = createError(
@@ -3813,7 +4102,7 @@ var reposCommand = new Command9("repos").description("List tracked repositories"
3813
4102
  });
3814
4103
 
3815
4104
  // src/commands/setup-audio.ts
3816
- import { Command as Command10 } from "commander";
4105
+ import { Command as Command11 } from "commander";
3817
4106
  import { copyFile, mkdir as mkdir11, readFile as readFile12, writeFile as writeFile10, access as access5 } from "fs/promises";
3818
4107
  import { homedir as homedir9, platform } from "os";
3819
4108
 
@@ -3919,7 +4208,7 @@ function createDefaultSetupAudioDeps() {
3919
4208
  access: (path) => access5(path)
3920
4209
  };
3921
4210
  }
3922
- var setupAudioCommand = new Command10("setup-audio").description("Configure macOS PulseAudio for audio passthrough to containers").action(async () => {
4211
+ var setupAudioCommand = new Command11("setup-audio").description("Configure macOS PulseAudio for audio passthrough to containers").action(async () => {
3923
4212
  const deps = createDefaultSetupAudioDeps();
3924
4213
  const result = await setupAudio(deps);
3925
4214
  if (!result.ok) {
@@ -3939,7 +4228,7 @@ var setupAudioCommand = new Command10("setup-audio").description("Configure macO
3939
4228
  });
3940
4229
 
3941
4230
  // src/commands/tmux-restore.ts
3942
- import { Command as Command11 } from "commander";
4231
+ import { Command as Command12 } from "commander";
3943
4232
  import { execSync } from "child_process";
3944
4233
  import { join as join12 } from "path";
3945
4234
 
@@ -4059,7 +4348,7 @@ async function executeTmuxRestore() {
4059
4348
  }
4060
4349
  }
4061
4350
  }
4062
- var tmuxRestoreCommand = new Command11("tmux-restore").description("Restore tmux session state from saved state (container only)").action(async () => {
4351
+ var tmuxRestoreCommand = new Command12("tmux-restore").description("Restore tmux session state from saved state (container only)").action(async () => {
4063
4352
  try {
4064
4353
  await executeTmuxRestore();
4065
4354
  } catch {
@@ -4067,7 +4356,7 @@ var tmuxRestoreCommand = new Command11("tmux-restore").description("Restore tmux
4067
4356
  });
4068
4357
 
4069
4358
  // src/commands/tmux-save.ts
4070
- import { Command as Command12 } from "commander";
4359
+ import { Command as Command13 } from "commander";
4071
4360
  import { execSync as execSync2 } from "child_process";
4072
4361
  import { unlink as unlink2 } from "fs/promises";
4073
4362
  import { join as join13 } from "path";
@@ -4145,7 +4434,7 @@ async function executeTmuxSave() {
4145
4434
  const pruned = pruneStaleEntries(panesState, activePaneIds);
4146
4435
  await writePanesState(panesPath, pruned);
4147
4436
  }
4148
- var tmuxSaveCommand = new Command12("tmux-save").description("Save current tmux session state for persistence across rebuilds (container only)").action(async () => {
4437
+ var tmuxSaveCommand = new Command13("tmux-save").description("Save current tmux session state for persistence across rebuilds (container only)").action(async () => {
4149
4438
  try {
4150
4439
  await executeTmuxSave();
4151
4440
  } catch {
@@ -4153,7 +4442,7 @@ var tmuxSaveCommand = new Command12("tmux-save").description("Save current tmux
4153
4442
  });
4154
4443
 
4155
4444
  // src/commands/tmux-status.ts
4156
- import { Command as Command13 } from "commander";
4445
+ import { Command as Command14 } from "commander";
4157
4446
 
4158
4447
  // src/lib/tmux-status.ts
4159
4448
  import { readFile as readFile14 } from "fs/promises";
@@ -4194,7 +4483,7 @@ var defaultDeps3 = {
4194
4483
  statePath: CONTAINER_STATE_PATH
4195
4484
  };
4196
4485
  function createTmuxStatusCommand(deps = defaultDeps3) {
4197
- return new Command13("tmux-status").description("Output formatted instance status for tmux status bar (container only)").action(async () => {
4486
+ return new Command14("tmux-status").description("Output formatted instance status for tmux status bar (container only)").action(async () => {
4198
4487
  if (!deps.isInsideContainer()) {
4199
4488
  console.log("?");
4200
4489
  return;
@@ -4205,179 +4494,103 @@ function createTmuxStatusCommand(deps = defaultDeps3) {
4205
4494
  }
4206
4495
  var tmuxStatusCommand = createTmuxStatusCommand();
4207
4496
 
4208
- // src/components/InteractiveMenu.tsx
4209
- import { Select } from "@inkjs/ui";
4210
- import { Box as Box2, Text as Text3 } from "ink";
4211
- import { useState } from "react";
4212
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
4213
- var COLUMN_PADDING = 2;
4214
- var SELECT_PREFIX_WIDTH = 4;
4215
- function statusSymbol(status) {
4216
- switch (status) {
4217
- case "running":
4218
- return "\u25B6";
4219
- case "stopped":
4220
- return "\u25A0";
4221
- case "orphaned":
4222
- return "\u2717";
4223
- case "unknown":
4224
- return "?";
4225
- case "not-found":
4226
- return "\u2717";
4497
+ // src/lib/update-check.ts
4498
+ import chalk4 from "chalk";
4499
+ import * as fs from "fs/promises";
4500
+ import { dirname as dirname4 } from "path";
4501
+ function normaliseVersion(version2) {
4502
+ const withoutBuild = version2.split("+")[0];
4503
+ const withoutPre = withoutBuild.split("-")[0];
4504
+ return withoutPre;
4505
+ }
4506
+ function isNewerVersion(current, registry) {
4507
+ const normCurrent = normaliseVersion(current);
4508
+ const normRegistry = normaliseVersion(registry);
4509
+ const currentParts = normCurrent.split(".").map(Number);
4510
+ const registryParts = normRegistry.split(".").map(Number);
4511
+ const len = Math.max(currentParts.length, registryParts.length);
4512
+ for (let i = 0; i < len; i++) {
4513
+ const c = currentParts[i] ?? 0;
4514
+ const r = registryParts[i] ?? 0;
4515
+ if (r > c) return true;
4516
+ if (r < c) return false;
4517
+ }
4518
+ return false;
4519
+ }
4520
+ async function readCache(cachePath, readFileFn) {
4521
+ try {
4522
+ const raw = await readFileFn(cachePath, "utf-8");
4523
+ const parsed = JSON.parse(raw);
4524
+ if (parsed !== null && typeof parsed === "object" && "lastCheck" in parsed && "latestVersion" in parsed && typeof parsed.lastCheck === "number" && typeof parsed.latestVersion === "string") {
4525
+ return parsed;
4526
+ }
4527
+ return null;
4528
+ } catch {
4529
+ return null;
4227
4530
  }
4228
4531
  }
4229
- function gitIndicatorString(gitState) {
4230
- const indicators = formatGitIndicators(gitState);
4231
- return indicators.map((ind) => ind.symbol).join(" ");
4232
- }
4233
- function truncatePurpose(purpose, maxLen) {
4234
- if (!purpose) return "";
4235
- if (maxLen <= 3) return "";
4236
- if (purpose.length <= maxLen) return purpose;
4237
- return purpose.slice(0, maxLen - 3) + "...";
4238
- }
4239
- function buildOptionLabel(instance, terminalWidth) {
4240
- const name = instance.name;
4241
- const status = statusSymbol(instance.status);
4242
- const git = gitIndicatorString(instance.gitState);
4243
- const fixedWidth = name.length + COLUMN_PADDING + status.length + COLUMN_PADDING + git.length + COLUMN_PADDING;
4244
- const availableForPurpose = Math.max(0, terminalWidth - fixedWidth - SELECT_PREFIX_WIDTH);
4245
- const purpose = truncatePurpose(instance.purpose, availableForPurpose);
4246
- const parts = [name, status, git];
4247
- if (purpose) {
4248
- parts.push(purpose);
4249
- }
4250
- return parts.join(" ");
4251
- }
4252
- function ActionMenu({
4253
- instanceName,
4254
- onSelectAction
4255
- }) {
4256
- const options = [
4257
- { label: "\u{1F680} Attach to session", value: "attach" },
4258
- { label: "\u{1F6E0} Rebuild container", value: "rebuild" },
4259
- { label: "\u{1F4DD} Show purpose", value: "purpose" },
4260
- { label: "\u{1F5D1} Remove instance", value: "remove" }
4261
- ];
4262
- return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
4263
- /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsxs3(Text3, { children: [
4264
- "Manage",
4265
- " ",
4266
- /* @__PURE__ */ jsx3(Text3, { bold: true, color: "cyan", children: instanceName }),
4267
- ":"
4268
- ] }) }),
4269
- /* @__PURE__ */ jsx3(Select, { options, onChange: onSelectAction })
4270
- ] });
4271
- }
4272
- function InteractiveMenu({
4273
- instances,
4274
- onAction,
4275
- terminalWidth
4276
- }) {
4277
- const [selectedInstance, setSelectedInstance] = useState(null);
4278
- const width = terminalWidth ?? process.stdout.columns ?? 80;
4279
- if (instances.length === 0) {
4280
- return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
4281
- /* @__PURE__ */ jsx3(Text3, { children: "No instances found." }),
4282
- /* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
4283
- "Create one with: agent-env create ",
4284
- "<name>",
4285
- " --repo ",
4286
- "<url>"
4287
- ] })
4288
- ] });
4289
- }
4290
- if (selectedInstance) {
4291
- return /* @__PURE__ */ jsx3(
4292
- ActionMenu,
4293
- {
4294
- instanceName: selectedInstance,
4295
- onSelectAction: (action) => onAction(action, selectedInstance)
4296
- }
4297
- );
4532
+ async function writeCache(cachePath, data, mkdirFn, writeFileFn) {
4533
+ try {
4534
+ await mkdirFn(dirname4(cachePath), { recursive: true });
4535
+ await writeFileFn(cachePath, JSON.stringify(data), "utf-8");
4536
+ } catch {
4298
4537
  }
4299
- const options = instances.map((instance) => ({
4300
- label: buildOptionLabel(instance, width),
4301
- value: instance.name
4302
- }));
4303
- return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
4304
- /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: "Select an instance:" }) }),
4305
- /* @__PURE__ */ jsx3(Select, { options, onChange: setSelectedInstance })
4306
- ] });
4307
4538
  }
4308
-
4309
- // src/lib/interactive-menu.ts
4310
- async function launchInteractiveMenu(deps) {
4311
- const listResult = await deps.listInstances();
4312
- if (!listResult.ok) {
4313
- return {
4314
- ok: false,
4315
- error: {
4316
- code: listResult.error.code,
4317
- message: listResult.error.message,
4318
- suggestion: "Check if ~/.agent-env/workspaces/ is accessible."
4319
- }
4320
- };
4321
- }
4322
- if (listResult.instances.length === 0) {
4323
- deps.renderMenu(listResult.instances, () => {
4324
- });
4325
- return { ok: true, action: "empty" };
4326
- }
4327
- let selectedName;
4328
- let selectedAction;
4329
- const selectionPromise = new Promise((resolve2) => {
4330
- const { waitUntilExit } = deps.renderMenu(
4331
- listResult.instances,
4332
- (action2, name2) => {
4333
- selectedAction = action2;
4334
- selectedName = name2;
4335
- resolve2({ action: action2, name: name2 });
4336
- }
4337
- );
4338
- void waitUntilExit().then(() => {
4339
- if (!selectedName || !selectedAction) {
4340
- resolve2({ action: "attach", name: "" });
4341
- }
4539
+ async function fetchLatestVersion(packageName, fetchFn) {
4540
+ try {
4541
+ const url = `https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`;
4542
+ const response = await fetchFn(url, {
4543
+ headers: { Accept: "application/json" },
4544
+ signal: AbortSignal.timeout(5e3)
4342
4545
  });
4343
- });
4344
- const { action, name } = await selectionPromise;
4345
- if (!name) {
4346
- return { ok: true, action: "empty" };
4347
- }
4348
- switch (action) {
4349
- case "attach": {
4350
- const attachDeps = deps.createAttachDeps();
4351
- const attachResult = await deps.attachInstance(name, attachDeps);
4352
- if (!attachResult.ok) return { ok: false, error: attachResult.error };
4353
- return { ok: true, action: "attached", instanceName: name };
4546
+ const json = await response.json();
4547
+ if (json !== null && typeof json === "object" && "version" in json && typeof json.version === "string") {
4548
+ return json.version;
4354
4549
  }
4355
- case "rebuild": {
4356
- const rebuildDeps = deps.createRebuildDeps();
4357
- const rebuildResult = await deps.rebuildInstance(name, rebuildDeps, { force: true });
4358
- if (!rebuildResult.ok) return { ok: false, error: rebuildResult.error };
4359
- return { ok: true, action: "rebuilt", instanceName: name };
4360
- }
4361
- case "purpose": {
4362
- const instance = listResult.instances.find((i) => i.name === name);
4363
- if (instance) {
4364
- console.log(`
4365
- Purpose for ${name}:`);
4366
- console.log(instance.purpose || "No purpose set.");
4367
- }
4368
- return { ok: true, action: "purpose-shown", instanceName: name };
4369
- }
4370
- case "remove": {
4371
- const removeDeps = deps.createRemoveDeps();
4372
- const removeResult = await deps.removeInstance(name, removeDeps, false);
4373
- if (!removeResult.ok) return { ok: false, error: removeResult.error };
4374
- return { ok: true, action: "removed", instanceName: name };
4550
+ return null;
4551
+ } catch {
4552
+ return null;
4553
+ }
4554
+ }
4555
+ function formatUpdateMessage(currentVersion, latestVersion, packageName) {
4556
+ const normCurrent = normaliseVersion(currentVersion);
4557
+ const line1 = chalk4.yellow(`Update available: ${normCurrent} -> ${latestVersion}`);
4558
+ const line2 = chalk4.cyan(`Run: pnpm add -g ${packageName}`);
4559
+ return `${line1}
4560
+ ${line2}`;
4561
+ }
4562
+ async function checkForUpdate(opts) {
4563
+ const {
4564
+ currentVersion,
4565
+ packageName,
4566
+ cachePath,
4567
+ cacheTtlMs,
4568
+ fetchFn = fetch,
4569
+ readFile: readFile16 = (p, enc) => fs.readFile(p, enc),
4570
+ writeFile: writeFile13 = (p, d, enc) => fs.writeFile(p, d, enc),
4571
+ mkdir: mkdir14 = (p, o) => fs.mkdir(p, o),
4572
+ now = () => Date.now()
4573
+ } = opts;
4574
+ const currentTime = now();
4575
+ const cache = await readCache(cachePath, readFile16);
4576
+ let latestVersion = null;
4577
+ const isCacheFresh = cache !== null && currentTime - cache.lastCheck < cacheTtlMs;
4578
+ if (isCacheFresh) {
4579
+ latestVersion = cache.latestVersion;
4580
+ } else {
4581
+ latestVersion = await fetchLatestVersion(packageName, fetchFn);
4582
+ if (latestVersion !== null) {
4583
+ await writeCache(cachePath, { lastCheck: currentTime, latestVersion }, mkdir14, writeFile13);
4375
4584
  }
4376
4585
  }
4586
+ if (latestVersion !== null && isNewerVersion(currentVersion, latestVersion)) {
4587
+ return formatUpdateMessage(currentVersion, latestVersion, packageName);
4588
+ }
4589
+ return null;
4377
4590
  }
4378
4591
 
4379
4592
  // src/cli.ts
4380
- var __dirname = dirname4(fileURLToPath2(import.meta.url));
4593
+ var __dirname = dirname5(fileURLToPath2(import.meta.url));
4381
4594
  var isLinked = existsSync(resolve(__dirname, "..", "..", "..", "pnpm-workspace.yaml"));
4382
4595
  var isBakedDev = resolve(__dirname, "..").startsWith("/opt/agent-env-dev");
4383
4596
  var version = package_default.version + (isLinked ? "+local" : isBakedDev ? "+dev" : "");
@@ -4389,6 +4602,7 @@ program.addCommand(codeCommand);
4389
4602
  program.addCommand(rebuildCommand);
4390
4603
  program.addCommand(removeCommand);
4391
4604
  program.addCommand(purposeCommand);
4605
+ program.addCommand(onCommand);
4392
4606
  program.addCommand(reposCommand);
4393
4607
  program.addCommand(tmuxStatusCommand);
4394
4608
  program.addCommand(tmuxSaveCommand);
@@ -4411,29 +4625,56 @@ program.action(async () => {
4411
4625
  program.help();
4412
4626
  return;
4413
4627
  }
4414
- const result = await launchInteractiveMenu({
4628
+ const { Select: Select2 } = await import("@inkjs/ui");
4629
+ const pickerResult = await launchInstancePicker({
4415
4630
  listInstances,
4416
- attachInstance,
4417
- rebuildInstance,
4418
- removeInstance,
4419
- createAttachDeps: createAttachDefaultDeps,
4420
- createRebuildDeps: createRebuildDefaultDeps,
4421
- createRemoveDeps: createRemoveDefaultDeps,
4422
- renderMenu: (instances, onAction) => {
4423
- const { waitUntilExit } = render2(
4424
- React3.createElement(InteractiveMenu, { instances, onAction })
4425
- );
4426
- return { waitUntilExit };
4631
+ renderPicker: (instances) => {
4632
+ if (instances.length === 0) {
4633
+ console.log("No instances found.");
4634
+ console.log("Create one with: agent-env create <name> --repo <url>");
4635
+ return Promise.resolve(null);
4636
+ }
4637
+ return new Promise((resolve2) => {
4638
+ const options = instances.map((inst) => ({
4639
+ label: inst.name,
4640
+ value: inst.name
4641
+ }));
4642
+ const { unmount } = render3(
4643
+ React4.createElement(() => {
4644
+ return React4.createElement(Select2, {
4645
+ options,
4646
+ onChange: (value) => {
4647
+ unmount();
4648
+ resolve2(value);
4649
+ }
4650
+ });
4651
+ })
4652
+ );
4653
+ });
4427
4654
  }
4428
4655
  });
4429
- if (!result.ok) {
4430
- const { code, message, suggestion } = result.error;
4431
- console.error(formatError(createError(code, message, suggestion)));
4656
+ if (pickerResult.kind === "error") {
4432
4657
  process.exitCode = 1;
4433
- } else if (result.action === "rebuilt") {
4434
- console.log(`\x1B[32m\u2713\x1B[0m Instance '${result.instanceName}' rebuilt successfully`);
4435
- } else if (result.action === "removed") {
4436
- console.log(`\x1B[32m\u2713\x1B[0m Instance '${result.instanceName}' removed`);
4658
+ return;
4659
+ }
4660
+ if (pickerResult.kind === "cancelled") {
4661
+ return;
4437
4662
  }
4663
+ const menuDeps = buildMenuDeps();
4664
+ await launchActionLoop(pickerResult.name, menuDeps);
4438
4665
  });
4439
- program.parse();
4666
+ var shouldCheck = !!process.stderr.isTTY && !isInsideContainer() && !isLinked && !isBakedDev;
4667
+ var updateCheckPromise = shouldCheck ? checkForUpdate({
4668
+ currentVersion: package_default.version,
4669
+ packageName: package_default.name,
4670
+ cachePath: join14(homedir10(), ".agent-env", "update-check.json"),
4671
+ cacheTtlMs: 36e5
4672
+ }) : Promise.resolve(null);
4673
+ async function main() {
4674
+ await program.parseAsync();
4675
+ const updateMessage = await updateCheckPromise;
4676
+ if (updateMessage) {
4677
+ process.stderr.write(updateMessage + "\n");
4678
+ }
4679
+ }
4680
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zookanalytics/agent-env",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "CLI for creating isolated, AI-ready development environments",
5
5
  "type": "module",
6
6
  "bin": {