@zookanalytics/agent-env 0.9.1 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +474 -270
  2. package/package.json +1 -1
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.1",
60
+ version: "0.10.0",
60
61
  description: "CLI for creating isolated, AI-ready development environments",
61
62
  type: "module",
62
63
  bin: {
@@ -625,7 +626,7 @@ var defaultMergeDeps = {
625
626
  var STATUS_BAR_JSON_FILENAME = "statusBar.json";
626
627
  var LABEL_LIFECYCLE_CMDS = {
627
628
  postCreateCommand: "/usr/local/bin/post-create.sh",
628
- 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"
629
630
  };
630
631
  var COMPOSABLE_LIFECYCLE_CMDS = [
631
632
  "postCreateCommand",
@@ -2863,6 +2864,31 @@ function parseBranches(result) {
2863
2864
  }
2864
2865
 
2865
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
+ }
2866
2892
  async function listInstances(deps, opts) {
2867
2893
  try {
2868
2894
  const container = deps?.container ?? createContainerLifecycle();
@@ -2988,90 +3014,137 @@ var listCommand = new Command5("list").alias("ps").description("List all instanc
2988
3014
  await waitUntilExit();
2989
3015
  });
2990
3016
 
2991
- // src/commands/purpose.ts
3017
+ // src/commands/on.ts
2992
3018
  import { Command as Command6 } from "commander";
2993
- var defaultPurposeCommandDeps = {
2994
- isInsideContainer
2995
- };
2996
- function createPurposeCommand(deps = defaultPurposeCommandDeps) {
2997
- return new Command6("purpose").description(
2998
- "Get or set the purpose/label for an instance. Inside a container: no instance name needed (agent-env purpose [value])"
2999
- ).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) => {
3000
- if (deps.isInsideContainer()) {
3001
- await handleContainerMode(nameOrValue);
3002
- } else {
3003
- 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)));
3004
3051
  }
3005
- });
3006
- }
3007
- var purposeCommand = createPurposeCommand();
3008
- async function handleContainerMode(purposeValue) {
3009
- const deps = createContainerPurposeDefaultDeps();
3010
- if (purposeValue === void 0) {
3011
- const result = await getContainerPurpose(deps);
3012
- handleGetResult(result);
3013
- } else {
3014
- const result = await setContainerPurpose(purposeValue, deps);
3015
- handleSetResult(result);
3016
3052
  }
3017
3053
  }
3018
- async function handleHostMode(name, value, repo) {
3019
- if (!name) {
3054
+ async function launchInstancePicker(deps) {
3055
+ const listResult = await deps.listInstances();
3056
+ if (!listResult.ok) {
3057
+ const { code, message } = listResult.error;
3020
3058
  console.error(
3021
- formatError(
3022
- createError(
3023
- "MISSING_ARGUMENT",
3024
- "Instance name is required when running on the host",
3025
- "Usage: agent-env purpose <name> [value]"
3026
- )
3027
- )
3059
+ formatError(createError(code, message, "Check if ~/.agent-env/workspaces/ is accessible."))
3028
3060
  );
3029
- process.exit(1);
3030
- return;
3061
+ return { kind: "error" };
3031
3062
  }
3032
- const repoSlug = await resolveRepoOrExit({ repo, cwd: process.cwd() });
3033
- const deps = createPurposeDefaultDeps();
3034
- if (value === void 0) {
3035
- const result = await getPurpose(name, deps, repoSlug);
3036
- handleGetResult(result);
3037
- } else {
3038
- const result = await setPurpose(name, value, deps, repoSlug);
3039
- handleSetResult(result);
3063
+ const selected = await deps.renderPicker(listResult.instances);
3064
+ if (selected === null) {
3065
+ return { kind: "cancelled" };
3040
3066
  }
3067
+ return { kind: "selected", name: selected };
3041
3068
  }
3042
- function handleGetResult(result) {
3043
- if (!result.ok) {
3044
- const { code, message, suggestion } = result.error;
3045
- console.error(formatError(createError(code, message, suggestion)));
3046
- process.exit(1);
3047
- }
3048
- if (result.purpose === null) {
3049
- console.log("(no purpose set)");
3050
- } else {
3051
- 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 "?";
3052
3090
  }
3053
3091
  }
3054
- function handleSetResult(result) {
3055
- if (!result.ok) {
3056
- const { code, message, suggestion } = result.error;
3057
- console.error(formatError(createError(code, message, suggestion)));
3058
- process.exit(1);
3059
- }
3060
- if (result.cleared) {
3061
- console.log("Purpose cleared");
3062
- } else {
3063
- console.log("Purpose updated");
3064
- }
3065
- if (result.warning) {
3066
- 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);
3067
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
+ ] });
3068
3146
  }
3069
3147
 
3070
- // src/commands/rebuild.ts
3071
- import chalk from "chalk";
3072
- import { Command as Command7 } from "commander";
3073
- import { createInterface } from "readline";
3074
-
3075
3148
  // src/lib/rebuild-instance.ts
3076
3149
  import {
3077
3150
  access as access4,
@@ -3341,7 +3414,186 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
3341
3414
  };
3342
3415
  }
3343
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
+
3344
3593
  // src/commands/rebuild.ts
3594
+ import chalk from "chalk";
3595
+ import { Command as Command8 } from "commander";
3596
+ import { createInterface } from "readline";
3345
3597
  function promptForConfirmation(instanceName) {
3346
3598
  return new Promise((resolve2) => {
3347
3599
  const rl = createInterface({
@@ -3363,7 +3615,7 @@ Any active sessions will be lost. Continue? (y/N) `,
3363
3615
  });
3364
3616
  });
3365
3617
  }
3366
- 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(
3367
3619
  async (name, options) => {
3368
3620
  const deps = createRebuildDefaultDeps();
3369
3621
  const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
@@ -3416,7 +3668,7 @@ var rebuildCommand = new Command7("rebuild").description("Rebuild an instance by
3416
3668
 
3417
3669
  // src/commands/remove.ts
3418
3670
  import chalk3 from "chalk";
3419
- import { Command as Command8 } from "commander";
3671
+ import { Command as Command9 } from "commander";
3420
3672
  import { createInterface as createInterface2 } from "readline";
3421
3673
 
3422
3674
  // src/lib/audit-log.ts
@@ -3735,7 +3987,7 @@ async function resolveConfirmation(name, options) {
3735
3987
  }
3736
3988
  return "typed-name";
3737
3989
  }
3738
- 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(
3739
3991
  "--yes",
3740
3992
  "Skip confirmation prompt for --force (DANGEROUS: skips all safety prompts, for scripts only)"
3741
3993
  ).action(async (name, options) => {
@@ -3798,8 +4050,8 @@ var removeCommand = new Command8("remove").description("Remove an instance with
3798
4050
  });
3799
4051
 
3800
4052
  // src/commands/repos.ts
3801
- import { Command as Command9 } from "commander";
3802
- 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) => {
3803
4055
  const result = await listRepos();
3804
4056
  if (!result.ok) {
3805
4057
  const error = createError(
@@ -3850,7 +4102,7 @@ var reposCommand = new Command9("repos").description("List tracked repositories"
3850
4102
  });
3851
4103
 
3852
4104
  // src/commands/setup-audio.ts
3853
- import { Command as Command10 } from "commander";
4105
+ import { Command as Command11 } from "commander";
3854
4106
  import { copyFile, mkdir as mkdir11, readFile as readFile12, writeFile as writeFile10, access as access5 } from "fs/promises";
3855
4107
  import { homedir as homedir9, platform } from "os";
3856
4108
 
@@ -3956,7 +4208,7 @@ function createDefaultSetupAudioDeps() {
3956
4208
  access: (path) => access5(path)
3957
4209
  };
3958
4210
  }
3959
- 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 () => {
3960
4212
  const deps = createDefaultSetupAudioDeps();
3961
4213
  const result = await setupAudio(deps);
3962
4214
  if (!result.ok) {
@@ -3976,7 +4228,7 @@ var setupAudioCommand = new Command10("setup-audio").description("Configure macO
3976
4228
  });
3977
4229
 
3978
4230
  // src/commands/tmux-restore.ts
3979
- import { Command as Command11 } from "commander";
4231
+ import { Command as Command12 } from "commander";
3980
4232
  import { execSync } from "child_process";
3981
4233
  import { join as join12 } from "path";
3982
4234
 
@@ -4096,7 +4348,7 @@ async function executeTmuxRestore() {
4096
4348
  }
4097
4349
  }
4098
4350
  }
4099
- 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 () => {
4100
4352
  try {
4101
4353
  await executeTmuxRestore();
4102
4354
  } catch {
@@ -4104,7 +4356,7 @@ var tmuxRestoreCommand = new Command11("tmux-restore").description("Restore tmux
4104
4356
  });
4105
4357
 
4106
4358
  // src/commands/tmux-save.ts
4107
- import { Command as Command12 } from "commander";
4359
+ import { Command as Command13 } from "commander";
4108
4360
  import { execSync as execSync2 } from "child_process";
4109
4361
  import { unlink as unlink2 } from "fs/promises";
4110
4362
  import { join as join13 } from "path";
@@ -4182,7 +4434,7 @@ async function executeTmuxSave() {
4182
4434
  const pruned = pruneStaleEntries(panesState, activePaneIds);
4183
4435
  await writePanesState(panesPath, pruned);
4184
4436
  }
4185
- 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 () => {
4186
4438
  try {
4187
4439
  await executeTmuxSave();
4188
4440
  } catch {
@@ -4190,7 +4442,7 @@ var tmuxSaveCommand = new Command12("tmux-save").description("Save current tmux
4190
4442
  });
4191
4443
 
4192
4444
  // src/commands/tmux-status.ts
4193
- import { Command as Command13 } from "commander";
4445
+ import { Command as Command14 } from "commander";
4194
4446
 
4195
4447
  // src/lib/tmux-status.ts
4196
4448
  import { readFile as readFile14 } from "fs/promises";
@@ -4231,7 +4483,7 @@ var defaultDeps3 = {
4231
4483
  statePath: CONTAINER_STATE_PATH
4232
4484
  };
4233
4485
  function createTmuxStatusCommand(deps = defaultDeps3) {
4234
- 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 () => {
4235
4487
  if (!deps.isInsideContainer()) {
4236
4488
  console.log("?");
4237
4489
  return;
@@ -4242,179 +4494,103 @@ function createTmuxStatusCommand(deps = defaultDeps3) {
4242
4494
  }
4243
4495
  var tmuxStatusCommand = createTmuxStatusCommand();
4244
4496
 
4245
- // src/components/InteractiveMenu.tsx
4246
- import { Select } from "@inkjs/ui";
4247
- import { Box as Box2, Text as Text3 } from "ink";
4248
- import { useState } from "react";
4249
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
4250
- var COLUMN_PADDING = 2;
4251
- var SELECT_PREFIX_WIDTH = 4;
4252
- function statusSymbol(status) {
4253
- switch (status) {
4254
- case "running":
4255
- return "\u25B6";
4256
- case "stopped":
4257
- return "\u25A0";
4258
- case "orphaned":
4259
- return "\u2717";
4260
- case "unknown":
4261
- return "?";
4262
- case "not-found":
4263
- 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;
4264
4530
  }
4265
4531
  }
4266
- function gitIndicatorString(gitState) {
4267
- const indicators = formatGitIndicators(gitState);
4268
- return indicators.map((ind) => ind.symbol).join(" ");
4269
- }
4270
- function truncatePurpose(purpose, maxLen) {
4271
- if (!purpose) return "";
4272
- if (maxLen <= 3) return "";
4273
- if (purpose.length <= maxLen) return purpose;
4274
- return purpose.slice(0, maxLen - 3) + "...";
4275
- }
4276
- function buildOptionLabel(instance, terminalWidth) {
4277
- const name = instance.name;
4278
- const status = statusSymbol(instance.status);
4279
- const git = gitIndicatorString(instance.gitState);
4280
- const fixedWidth = name.length + COLUMN_PADDING + status.length + COLUMN_PADDING + git.length + COLUMN_PADDING;
4281
- const availableForPurpose = Math.max(0, terminalWidth - fixedWidth - SELECT_PREFIX_WIDTH);
4282
- const purpose = truncatePurpose(instance.purpose, availableForPurpose);
4283
- const parts = [name, status, git];
4284
- if (purpose) {
4285
- parts.push(purpose);
4286
- }
4287
- return parts.join(" ");
4288
- }
4289
- function ActionMenu({
4290
- instanceName,
4291
- onSelectAction
4292
- }) {
4293
- const options = [
4294
- { label: "\u{1F680} Attach to session", value: "attach" },
4295
- { label: "\u{1F6E0} Rebuild container", value: "rebuild" },
4296
- { label: "\u{1F4DD} Show purpose", value: "purpose" },
4297
- { label: "\u{1F5D1} Remove instance", value: "remove" }
4298
- ];
4299
- return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
4300
- /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsxs3(Text3, { children: [
4301
- "Manage",
4302
- " ",
4303
- /* @__PURE__ */ jsx3(Text3, { bold: true, color: "cyan", children: instanceName }),
4304
- ":"
4305
- ] }) }),
4306
- /* @__PURE__ */ jsx3(Select, { options, onChange: onSelectAction })
4307
- ] });
4308
- }
4309
- function InteractiveMenu({
4310
- instances,
4311
- onAction,
4312
- terminalWidth
4313
- }) {
4314
- const [selectedInstance, setSelectedInstance] = useState(null);
4315
- const width = terminalWidth ?? process.stdout.columns ?? 80;
4316
- if (instances.length === 0) {
4317
- return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
4318
- /* @__PURE__ */ jsx3(Text3, { children: "No instances found." }),
4319
- /* @__PURE__ */ jsxs3(Text3, { color: "gray", children: [
4320
- "Create one with: agent-env create ",
4321
- "<name>",
4322
- " --repo ",
4323
- "<url>"
4324
- ] })
4325
- ] });
4326
- }
4327
- if (selectedInstance) {
4328
- return /* @__PURE__ */ jsx3(
4329
- ActionMenu,
4330
- {
4331
- instanceName: selectedInstance,
4332
- onSelectAction: (action) => onAction(action, selectedInstance)
4333
- }
4334
- );
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 {
4335
4537
  }
4336
- const options = instances.map((instance) => ({
4337
- label: buildOptionLabel(instance, width),
4338
- value: instance.name
4339
- }));
4340
- return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
4341
- /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: "Select an instance:" }) }),
4342
- /* @__PURE__ */ jsx3(Select, { options, onChange: setSelectedInstance })
4343
- ] });
4344
4538
  }
4345
-
4346
- // src/lib/interactive-menu.ts
4347
- async function launchInteractiveMenu(deps) {
4348
- const listResult = await deps.listInstances();
4349
- if (!listResult.ok) {
4350
- return {
4351
- ok: false,
4352
- error: {
4353
- code: listResult.error.code,
4354
- message: listResult.error.message,
4355
- suggestion: "Check if ~/.agent-env/workspaces/ is accessible."
4356
- }
4357
- };
4358
- }
4359
- if (listResult.instances.length === 0) {
4360
- deps.renderMenu(listResult.instances, () => {
4361
- });
4362
- return { ok: true, action: "empty" };
4363
- }
4364
- let selectedName;
4365
- let selectedAction;
4366
- const selectionPromise = new Promise((resolve2) => {
4367
- const { waitUntilExit } = deps.renderMenu(
4368
- listResult.instances,
4369
- (action2, name2) => {
4370
- selectedAction = action2;
4371
- selectedName = name2;
4372
- resolve2({ action: action2, name: name2 });
4373
- }
4374
- );
4375
- void waitUntilExit().then(() => {
4376
- if (!selectedName || !selectedAction) {
4377
- resolve2({ action: "attach", name: "" });
4378
- }
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)
4379
4545
  });
4380
- });
4381
- const { action, name } = await selectionPromise;
4382
- if (!name) {
4383
- return { ok: true, action: "empty" };
4384
- }
4385
- switch (action) {
4386
- case "attach": {
4387
- const attachDeps = deps.createAttachDeps();
4388
- const attachResult = await deps.attachInstance(name, attachDeps);
4389
- if (!attachResult.ok) return { ok: false, error: attachResult.error };
4390
- return { ok: true, action: "attached", instanceName: name };
4391
- }
4392
- case "rebuild": {
4393
- const rebuildDeps = deps.createRebuildDeps();
4394
- const rebuildResult = await deps.rebuildInstance(name, rebuildDeps, { force: true });
4395
- if (!rebuildResult.ok) return { ok: false, error: rebuildResult.error };
4396
- return { ok: true, action: "rebuilt", 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;
4397
4549
  }
4398
- case "purpose": {
4399
- const instance = listResult.instances.find((i) => i.name === name);
4400
- if (instance) {
4401
- console.log(`
4402
- Purpose for ${name}:`);
4403
- console.log(instance.purpose || "No purpose set.");
4404
- }
4405
- return { ok: true, action: "purpose-shown", instanceName: name };
4406
- }
4407
- case "remove": {
4408
- const removeDeps = deps.createRemoveDeps();
4409
- const removeResult = await deps.removeInstance(name, removeDeps, false);
4410
- if (!removeResult.ok) return { ok: false, error: removeResult.error };
4411
- 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);
4412
4584
  }
4413
4585
  }
4586
+ if (latestVersion !== null && isNewerVersion(currentVersion, latestVersion)) {
4587
+ return formatUpdateMessage(currentVersion, latestVersion, packageName);
4588
+ }
4589
+ return null;
4414
4590
  }
4415
4591
 
4416
4592
  // src/cli.ts
4417
- var __dirname = dirname4(fileURLToPath2(import.meta.url));
4593
+ var __dirname = dirname5(fileURLToPath2(import.meta.url));
4418
4594
  var isLinked = existsSync(resolve(__dirname, "..", "..", "..", "pnpm-workspace.yaml"));
4419
4595
  var isBakedDev = resolve(__dirname, "..").startsWith("/opt/agent-env-dev");
4420
4596
  var version = package_default.version + (isLinked ? "+local" : isBakedDev ? "+dev" : "");
@@ -4426,6 +4602,7 @@ program.addCommand(codeCommand);
4426
4602
  program.addCommand(rebuildCommand);
4427
4603
  program.addCommand(removeCommand);
4428
4604
  program.addCommand(purposeCommand);
4605
+ program.addCommand(onCommand);
4429
4606
  program.addCommand(reposCommand);
4430
4607
  program.addCommand(tmuxStatusCommand);
4431
4608
  program.addCommand(tmuxSaveCommand);
@@ -4448,29 +4625,56 @@ program.action(async () => {
4448
4625
  program.help();
4449
4626
  return;
4450
4627
  }
4451
- const result = await launchInteractiveMenu({
4628
+ const { Select: Select2 } = await import("@inkjs/ui");
4629
+ const pickerResult = await launchInstancePicker({
4452
4630
  listInstances,
4453
- attachInstance,
4454
- rebuildInstance,
4455
- removeInstance,
4456
- createAttachDeps: createAttachDefaultDeps,
4457
- createRebuildDeps: createRebuildDefaultDeps,
4458
- createRemoveDeps: createRemoveDefaultDeps,
4459
- renderMenu: (instances, onAction) => {
4460
- const { waitUntilExit } = render2(
4461
- React3.createElement(InteractiveMenu, { instances, onAction })
4462
- );
4463
- 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
+ });
4464
4654
  }
4465
4655
  });
4466
- if (!result.ok) {
4467
- const { code, message, suggestion } = result.error;
4468
- console.error(formatError(createError(code, message, suggestion)));
4656
+ if (pickerResult.kind === "error") {
4469
4657
  process.exitCode = 1;
4470
- } else if (result.action === "rebuilt") {
4471
- console.log(`\x1B[32m\u2713\x1B[0m Instance '${result.instanceName}' rebuilt successfully`);
4472
- } else if (result.action === "removed") {
4473
- console.log(`\x1B[32m\u2713\x1B[0m Instance '${result.instanceName}' removed`);
4658
+ return;
4659
+ }
4660
+ if (pickerResult.kind === "cancelled") {
4661
+ return;
4474
4662
  }
4663
+ const menuDeps = buildMenuDeps();
4664
+ await launchActionLoop(pickerResult.name, menuDeps);
4475
4665
  });
4476
- 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.1",
3
+ "version": "0.10.0",
4
4
  "description": "CLI for creating isolated, AI-ready development environments",
5
5
  "type": "module",
6
6
  "bin": {