@zookanalytics/agent-env 0.11.0 → 0.12.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 +251 -115
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -49,7 +49,7 @@ var execute = createExecutor();
49
49
  import { program } from "commander";
50
50
  import { render as render3 } from "ink";
51
51
  import { existsSync } from "fs";
52
- import { homedir as homedir10 } from "os";
52
+ import { homedir as homedir11 } from "os";
53
53
  import { dirname as dirname5, join as join14, resolve } from "path";
54
54
  import { fileURLToPath as fileURLToPath2 } from "url";
55
55
  import React4 from "react";
@@ -57,7 +57,7 @@ import React4 from "react";
57
57
  // package.json
58
58
  var package_default = {
59
59
  name: "@zookanalytics/agent-env",
60
- version: "0.11.0",
60
+ version: "0.12.0",
61
61
  description: "CLI for creating isolated, AI-ready development environments",
62
62
  type: "module",
63
63
  bin: {
@@ -1918,6 +1918,7 @@ async function attachInstance(instanceName, deps, onContainerStarting, onAttachi
1918
1918
  }
1919
1919
 
1920
1920
  // src/lib/command-helpers.ts
1921
+ import { createInterface } from "readline";
1921
1922
  async function resolveRepoOrExit(opts) {
1922
1923
  const executor = createExecutor();
1923
1924
  const repoResult = await resolveRepo(opts, executor);
@@ -1934,6 +1935,22 @@ async function resolveRepoOrExit(opts) {
1934
1935
  }
1935
1936
  return void 0;
1936
1937
  }
1938
+ function promptForConfirmation(message) {
1939
+ return new Promise((resolve2) => {
1940
+ const rl = createInterface({
1941
+ input: process.stdin,
1942
+ output: process.stderr
1943
+ });
1944
+ rl.question(message, (answer) => {
1945
+ rl.close();
1946
+ resolve2(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
1947
+ });
1948
+ rl.on("SIGINT", () => {
1949
+ rl.close();
1950
+ resolve2(false);
1951
+ });
1952
+ });
1953
+ }
1937
1954
 
1938
1955
  // src/commands/attach.ts
1939
1956
  var attachCommand = new Command("attach").description("Attach to an instance's tmux session").argument("<name>", "Instance name to attach to").option("--repo <slug>", "Repo slug or URL to scope instance lookup").action(async (name, options) => {
@@ -2137,25 +2154,20 @@ var codeCommand = new Command2("code").description("Open an instance in VS Code
2137
2154
  import { Command as Command3 } from "commander";
2138
2155
 
2139
2156
  // src/lib/completion.ts
2140
- var COMMANDS = [
2141
- "create",
2142
- "list",
2143
- "ps",
2144
- "attach",
2145
- "path",
2146
- "rebuild",
2147
- "remove",
2148
- "repos",
2149
- "purpose",
2150
- "tmux-status",
2151
- "completion"
2152
- ];
2153
- function generateCompletionScript(shell) {
2157
+ var COMPLETION_EXCLUDED_COMMANDS = /* @__PURE__ */ new Set(["tmux-save", "tmux-restore", "setup-audio"]);
2158
+ function extractCompletionCommands(program2, excluded = COMPLETION_EXCLUDED_COMMANDS) {
2159
+ return program2.commands.filter((cmd) => !excluded.has(cmd.name())).map((cmd) => ({
2160
+ name: cmd.name(),
2161
+ description: cmd.description().split("\n")[0],
2162
+ aliases: cmd.aliases()
2163
+ }));
2164
+ }
2165
+ function generateCompletionScript(shell, commands) {
2154
2166
  switch (shell) {
2155
2167
  case "bash":
2156
- return generateBashCompletion();
2168
+ return generateBashCompletion(commands);
2157
2169
  case "zsh":
2158
- return generateZshCompletion();
2170
+ return generateZshCompletion(commands);
2159
2171
  }
2160
2172
  }
2161
2173
  function isValidShell(shell) {
@@ -2178,8 +2190,9 @@ function getInstallInstructions() {
2178
2190
  # Or save to a file (ensure fpath includes the directory):
2179
2191
  agent-env completion zsh > ~/.zsh/completions/_agent-env`;
2180
2192
  }
2181
- function generateBashCompletion() {
2182
- const commandList = COMMANDS.join(" ");
2193
+ function generateBashCompletion(commands) {
2194
+ const allNames = commands.flatMap((c) => [c.name, ...c.aliases]);
2195
+ const commandList = allNames.join(" ");
2183
2196
  return `#!/usr/bin/env bash
2184
2197
  # agent-env bash completion script
2185
2198
  # Install: eval "$(agent-env completion bash)"
@@ -2225,7 +2238,7 @@ _agent_env_completions() {
2225
2238
 
2226
2239
  # Complete based on command
2227
2240
  case "\${prev}" in
2228
- attach|path|purpose)
2241
+ on|code|attach|path|purpose)
2229
2242
  local instances
2230
2243
  instances="$(_agent_env_instances)"
2231
2244
  COMPREPLY=($(compgen -W "--repo \${instances}" -- "\${cur}"))
@@ -2245,6 +2258,12 @@ _agent_env_completions() {
2245
2258
  COMPREPLY=($(compgen -W "--force --yes --no-pull --use-cache --repo \${instances}" -- "\${cur}"))
2246
2259
  return 0
2247
2260
  ;;
2261
+ shutdown)
2262
+ local instances
2263
+ instances="$(_agent_env_instances)"
2264
+ COMPREPLY=($(compgen -W "--yes --repo \${instances}" -- "\${cur}"))
2265
+ return 0
2266
+ ;;
2248
2267
  remove)
2249
2268
  local instances
2250
2269
  instances="$(_agent_env_instances)"
@@ -2299,20 +2318,16 @@ _aecd_completions() {
2299
2318
 
2300
2319
  complete -F _aecd_completions aecd`;
2301
2320
  }
2302
- function generateZshCompletion() {
2303
- const commandDescriptions = [
2304
- "create:Create a new instance",
2305
- "list:List all instances",
2306
- "ps:List all instances (alias)",
2307
- "attach:Attach to an instance tmux session",
2308
- "path:Print host directory path for an instance",
2309
- "rebuild:Rebuild an instance container",
2310
- "remove:Remove an instance",
2311
- "repos:List tracked repositories",
2312
- "purpose:Get or set instance purpose",
2313
- "tmux-status:Show tmux status bar info",
2314
- "completion:Generate shell completion script"
2315
- ];
2321
+ function generateZshCompletion(commands) {
2322
+ const zshEscape = (s) => s.replace(/'/g, "'\\''");
2323
+ const commandDescriptions = commands.flatMap((cmd) => {
2324
+ const desc = zshEscape(cmd.description);
2325
+ const entries = [`${cmd.name}:${desc}`];
2326
+ for (const alias of cmd.aliases) {
2327
+ entries.push(`${alias}:${desc} (alias)`);
2328
+ }
2329
+ return entries;
2330
+ });
2316
2331
  return `#compdef agent-env
2317
2332
  # agent-env zsh completion script
2318
2333
  # Install: eval "$(agent-env completion zsh)"
@@ -2368,7 +2383,7 @@ ${commandDescriptions.map((desc) => ` '${desc}'`).join("\n")}
2368
2383
  ;;
2369
2384
  args)
2370
2385
  case $words[1] in
2371
- attach|path|purpose)
2386
+ on|code|attach|path|purpose)
2372
2387
  _arguments \\
2373
2388
  '--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \\
2374
2389
  '1:instance:_agent_env_instances'
@@ -2393,6 +2408,12 @@ ${commandDescriptions.map((desc) => ` '${desc}'`).join("\n")}
2393
2408
  '--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \\
2394
2409
  '1:instance:_agent_env_instances'
2395
2410
  ;;
2411
+ shutdown)
2412
+ _arguments \\
2413
+ '--yes[Skip confirmation prompt]' \\
2414
+ '--repo[Repo slug to scope lookup]:slug:_agent_env_repos' \\
2415
+ '1:instance:_agent_env_instances'
2416
+ ;;
2396
2417
  remove)
2397
2418
  _arguments \\
2398
2419
  '--force[Force removal]' \\
@@ -2435,7 +2456,7 @@ compdef _aecd aecd`;
2435
2456
  // src/commands/completion.ts
2436
2457
  var completionCommand = new Command3("completion").description(`Generate shell completion script for bash or zsh
2437
2458
 
2438
- ${getInstallInstructions()}`).argument("<shell>", "Shell type (bash or zsh)").action((shell) => {
2459
+ ${getInstallInstructions()}`).argument("<shell>", "Shell type (bash or zsh)").action(function(shell) {
2439
2460
  if (!isValidShell(shell)) {
2440
2461
  const error = createError(
2441
2462
  "UNSUPPORTED_SHELL",
@@ -2445,7 +2466,8 @@ ${getInstallInstructions()}`).argument("<shell>", "Shell type (bash or zsh)").ac
2445
2466
  console.error(formatError(error));
2446
2467
  process.exit(1);
2447
2468
  }
2448
- const script = generateCompletionScript(shell);
2469
+ const commands = this.parent ? extractCompletionCommands(this.parent) : [];
2470
+ const script = generateCompletionScript(shell, commands);
2449
2471
  console.log(script);
2450
2472
  });
2451
2473
 
@@ -3069,6 +3091,17 @@ async function launchActionLoop(workspaceName, deps, repoSlug) {
3069
3091
  if (action === "exit") {
3070
3092
  break;
3071
3093
  }
3094
+ if (action === "shutdown") {
3095
+ const shutdownResult = await deps.shutdownInstance(workspaceName, repoSlug);
3096
+ if (!shutdownResult.ok) {
3097
+ if (shutdownResult.error) {
3098
+ const { code, message, suggestion } = shutdownResult.error;
3099
+ console.error(formatError(createError(code, message, suggestion)));
3100
+ }
3101
+ continue;
3102
+ }
3103
+ break;
3104
+ }
3072
3105
  let result;
3073
3106
  switch (action) {
3074
3107
  case "attach":
@@ -3154,6 +3187,7 @@ var ACTION_OPTIONS = [
3154
3187
  { label: "\u{1F680} Attach to session", value: "attach" },
3155
3188
  { label: "\u{1F4BB} Open in VS Code", value: "code" },
3156
3189
  { label: "\u{1F6E0} Rebuild container", value: "rebuild" },
3190
+ { label: "\u23F9 Shutdown container", value: "shutdown" },
3157
3191
  { label: "\u{1F4DD} Set Purpose", value: "set-purpose" },
3158
3192
  { label: "\u{1F6AA} Exit", value: "exit" }
3159
3193
  ];
@@ -3184,7 +3218,14 @@ function InteractiveMenu({
3184
3218
  }
3185
3219
  return /* @__PURE__ */ jsxs3(Box2, { flexDirection: "column", children: [
3186
3220
  /* @__PURE__ */ jsx3(Box2, { marginBottom: 1, children: /* @__PURE__ */ jsx3(Text3, { bold: true, children: headerParts.join(" \xB7 ") }) }),
3187
- mode === "actions" ? /* @__PURE__ */ jsx3(Select, { options: ACTION_OPTIONS, onChange: handleActionChange }) : /* @__PURE__ */ jsx3(PurposeInput, { onSubmit: handlePurposeSubmit, onCancel: handlePurposeCancel })
3221
+ mode === "actions" ? /* @__PURE__ */ jsx3(
3222
+ Select,
3223
+ {
3224
+ options: ACTION_OPTIONS,
3225
+ onChange: handleActionChange,
3226
+ visibleOptionCount: ACTION_OPTIONS.length
3227
+ }
3228
+ ) : /* @__PURE__ */ jsx3(PurposeInput, { onSubmit: handlePurposeSubmit, onCancel: handlePurposeCancel })
3188
3229
  ] });
3189
3230
  }
3190
3231
 
@@ -3203,6 +3244,29 @@ import {
3203
3244
  } from "fs/promises";
3204
3245
  import { homedir as homedir6 } from "os";
3205
3246
  import { join as join9 } from "path";
3247
+
3248
+ // src/lib/tmux-utils.ts
3249
+ async function saveTmuxState(containerName, deps) {
3250
+ try {
3251
+ const result = await deps.executor(
3252
+ "docker",
3253
+ ["exec", containerName, "bash", "-lc", "agent-env tmux-save"],
3254
+ { timeout: 3e4 }
3255
+ );
3256
+ if (result.ok) {
3257
+ deps.logger?.info("Saved tmux session state");
3258
+ return true;
3259
+ } else {
3260
+ deps.logger?.warn("Could not save tmux session state (non-fatal)");
3261
+ return false;
3262
+ }
3263
+ } catch {
3264
+ deps.logger?.warn("Could not save tmux session state (non-fatal)");
3265
+ return false;
3266
+ }
3267
+ }
3268
+
3269
+ // src/lib/rebuild-instance.ts
3206
3270
  function createRebuildDefaultDeps() {
3207
3271
  const executor = createExecutor();
3208
3272
  return {
@@ -3327,20 +3391,6 @@ async function executePullStep(wsRoot, pull, deps) {
3327
3391
  }
3328
3392
  return { ok: true, hasDockerfile };
3329
3393
  }
3330
- async function saveTmuxState(containerName, deps) {
3331
- const result = await deps.executor("docker", [
3332
- "exec",
3333
- containerName,
3334
- "bash",
3335
- "-lc",
3336
- "agent-env tmux-save"
3337
- ]);
3338
- if (result.ok) {
3339
- deps.logger?.info("Saved tmux session state");
3340
- } else {
3341
- deps.logger?.warn("Could not save tmux session state (non-fatal)");
3342
- }
3343
- }
3344
3394
  async function teardownContainer(containerName, container, statusResult) {
3345
3395
  if (!statusResult.ok || statusResult.status === "not-found") {
3346
3396
  return { ok: true };
@@ -3457,6 +3507,63 @@ async function rebuildInstance(instanceName, deps, options, repoSlug) {
3457
3507
  };
3458
3508
  }
3459
3509
 
3510
+ // src/lib/shutdown-instance.ts
3511
+ 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";
3512
+ import { homedir as homedir7 } from "os";
3513
+ function createShutdownDefaultDeps() {
3514
+ const executor = createExecutor();
3515
+ return {
3516
+ executor,
3517
+ container: createContainerLifecycle(executor),
3518
+ workspaceFsDeps: { mkdir: mkdir9, readdir: readdir8, stat: stat8, homedir: homedir7 },
3519
+ stateFsDeps: { readFile: readFile11, writeFile: writeFile10, rename: rename8, mkdir: mkdir9, appendFile: appendFile7 },
3520
+ logger: { warn: (msg) => console.warn(msg), info: (msg) => console.info(msg) }
3521
+ };
3522
+ }
3523
+ async function shutdownInstance(instanceName, deps, repoSlug) {
3524
+ const lookup = await resolveInstance(instanceName, repoSlug, {
3525
+ fsDeps: deps.workspaceFsDeps,
3526
+ readFile: deps.stateFsDeps.readFile
3527
+ });
3528
+ if (!lookup.found) {
3529
+ return { ok: false, error: lookup.error };
3530
+ }
3531
+ const wsPath = getWorkspacePathByName(lookup.workspaceName, deps.workspaceFsDeps);
3532
+ const state = await readState(wsPath, deps.stateFsDeps);
3533
+ const containerName = state.containerName;
3534
+ const dockerAvailable = await deps.container.isDockerAvailable();
3535
+ if (!dockerAvailable) {
3536
+ return {
3537
+ ok: false,
3538
+ error: {
3539
+ code: "ORBSTACK_REQUIRED",
3540
+ message: "Docker is not available. OrbStack or Docker Desktop must be running.",
3541
+ suggestion: "Start OrbStack or Docker Desktop, then try again."
3542
+ }
3543
+ };
3544
+ }
3545
+ const statusResult = await deps.container.containerStatus(containerName);
3546
+ if (!statusResult.ok) {
3547
+ return { ok: false, error: statusResult.error };
3548
+ }
3549
+ if (statusResult.status !== "running") {
3550
+ return {
3551
+ ok: false,
3552
+ error: {
3553
+ code: "CONTAINER_NOT_RUNNING",
3554
+ message: `Container '${containerName}' is not running`,
3555
+ suggestion: "The instance is already stopped."
3556
+ }
3557
+ };
3558
+ }
3559
+ const tmuxSaved = await saveTmuxState(containerName, deps);
3560
+ const stopResult = await deps.container.containerStop(containerName);
3561
+ if (!stopResult.ok) {
3562
+ return { ok: false, error: stopResult.error };
3563
+ }
3564
+ return { ok: true, containerName, tmuxSaved };
3565
+ }
3566
+
3460
3567
  // src/lib/menu-deps.ts
3461
3568
  function buildMenuDeps() {
3462
3569
  return {
@@ -3500,6 +3607,16 @@ function buildMenuDeps() {
3500
3607
  throw err;
3501
3608
  });
3502
3609
  },
3610
+ shutdownInstance: (wsName, slug) => {
3611
+ const deps = createShutdownDefaultDeps();
3612
+ console.log(`Shutting down instance '${wsName}'...`);
3613
+ return shutdownInstance(wsName, deps, slug).then((result) => {
3614
+ if (result.ok) {
3615
+ console.log(`\x1B[32m\u2713\x1B[0m Instance '${wsName}' shut down`);
3616
+ }
3617
+ return result;
3618
+ });
3619
+ },
3503
3620
  setPurpose: (wsName, value, slug) => {
3504
3621
  const deps = createPurposeDefaultDeps();
3505
3622
  return setPurpose(wsName, value, deps, slug);
@@ -3651,35 +3768,17 @@ function handleSetResult(result) {
3651
3768
  // src/commands/rebuild.ts
3652
3769
  import chalk from "chalk";
3653
3770
  import { Command as Command9 } from "commander";
3654
- import { createInterface } from "readline";
3655
- function promptForConfirmation(instanceName) {
3656
- return new Promise((resolve2) => {
3657
- const rl = createInterface({
3658
- input: process.stdin,
3659
- output: process.stderr
3660
- });
3661
- rl.question(
3662
- `
3663
- ${chalk.yellow("Warning:")} Rebuilding '${instanceName}' will destroy the current container and create a new one.
3664
- Any active sessions will be lost. Continue? (y/N) `,
3665
- (answer) => {
3666
- rl.close();
3667
- resolve2(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
3668
- }
3669
- );
3670
- rl.on("SIGINT", () => {
3671
- rl.close();
3672
- resolve2(false);
3673
- });
3674
- });
3675
- }
3676
3771
  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(
3677
3772
  async (name, options) => {
3678
3773
  const deps = createRebuildDefaultDeps();
3679
3774
  const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
3680
3775
  let confirmed = false;
3681
3776
  if (!options.yes && !options.force && process.stdin.isTTY) {
3682
- confirmed = await promptForConfirmation(name);
3777
+ confirmed = await promptForConfirmation(
3778
+ `
3779
+ ${chalk.yellow("Warning:")} Rebuilding '${name}' will destroy the current container and create a new one.
3780
+ Any active sessions will be lost. Continue? (y/N) `
3781
+ );
3683
3782
  if (!confirmed) {
3684
3783
  console.log("Rebuild cancelled");
3685
3784
  return;
@@ -3730,11 +3829,11 @@ import { Command as Command10 } from "commander";
3730
3829
  import { createInterface as createInterface2 } from "readline";
3731
3830
 
3732
3831
  // src/lib/audit-log.ts
3733
- import { appendFile as appendFile7, mkdir as mkdir9 } from "fs/promises";
3734
- import { homedir as homedir7 } from "os";
3832
+ import { appendFile as appendFile8, mkdir as mkdir10 } from "fs/promises";
3833
+ import { homedir as homedir8 } from "os";
3735
3834
  import { join as join10 } from "path";
3736
3835
  function createAuditLogDefaultDeps() {
3737
- return { appendFile: appendFile7, mkdir: mkdir9, homedir: homedir7 };
3836
+ return { appendFile: appendFile8, mkdir: mkdir10, homedir: homedir8 };
3738
3837
  }
3739
3838
  function getAuditLogPath(deps) {
3740
3839
  return join10(deps.homedir(), AGENT_ENV_DIR, "audit.log");
@@ -3756,16 +3855,16 @@ function createAuditEntry(instanceName, gitState, confirmationMethod) {
3756
3855
  }
3757
3856
 
3758
3857
  // src/lib/remove-instance.ts
3759
- import { mkdir as mkdir10, readdir as readdir8, readFile as readFile11, rm as rm4, stat as stat8 } from "fs/promises";
3760
- import { homedir as homedir8 } from "os";
3858
+ import { mkdir as mkdir11, readdir as readdir9, readFile as readFile12, rm as rm4, stat as stat9 } from "fs/promises";
3859
+ import { homedir as homedir9 } from "os";
3761
3860
  function createRemoveDefaultDeps() {
3762
3861
  const executor = createExecutor();
3763
3862
  return {
3764
3863
  executor,
3765
3864
  container: createContainerLifecycle(executor),
3766
3865
  gitDetector: createGitStateDetector(executor),
3767
- workspaceFsDeps: { mkdir: mkdir10, readdir: readdir8, stat: stat8, homedir: homedir8 },
3768
- stateFsDeps: { readFile: readFile11 },
3866
+ workspaceFsDeps: { mkdir: mkdir11, readdir: readdir9, stat: stat9, homedir: homedir9 },
3867
+ stateFsDeps: { readFile: readFile12 },
3769
3868
  deleteFsDeps: { rm: rm4 }
3770
3869
  };
3771
3870
  }
@@ -4161,8 +4260,8 @@ var reposCommand = new Command11("repos").description("List tracked repositories
4161
4260
 
4162
4261
  // src/commands/setup-audio.ts
4163
4262
  import { Command as Command12 } from "commander";
4164
- import { copyFile, mkdir as mkdir11, readFile as readFile12, writeFile as writeFile10, access as access5 } from "fs/promises";
4165
- import { homedir as homedir9, platform } from "os";
4263
+ import { copyFile, mkdir as mkdir12, readFile as readFile13, writeFile as writeFile11, access as access5 } from "fs/promises";
4264
+ import { homedir as homedir10, platform } from "os";
4166
4265
 
4167
4266
  // src/lib/setup-audio.ts
4168
4267
  async function setupAudio(deps) {
@@ -4257,12 +4356,12 @@ function createDefaultSetupAudioDeps() {
4257
4356
  const exec = createExecutor();
4258
4357
  return {
4259
4358
  platform: platform(),
4260
- homeDir: homedir9(),
4359
+ homeDir: homedir10(),
4261
4360
  execute: exec,
4262
- readFile: (path, encoding) => readFile12(path, encoding),
4263
- writeFile: (path, content, encoding) => writeFile10(path, content, encoding),
4361
+ readFile: (path, encoding) => readFile13(path, encoding),
4362
+ writeFile: (path, content, encoding) => writeFile11(path, content, encoding),
4264
4363
  copyFile,
4265
- mkdir: (path, opts) => mkdir11(path, opts),
4364
+ mkdir: (path, opts) => mkdir12(path, opts),
4266
4365
  access: (path) => access5(path)
4267
4366
  };
4268
4367
  }
@@ -4285,17 +4384,53 @@ var setupAudioCommand = new Command12("setup-audio").description("Configure macO
4285
4384
  );
4286
4385
  });
4287
4386
 
4288
- // src/commands/tmux-restore.ts
4387
+ // src/commands/shutdown.ts
4388
+ import chalk4 from "chalk";
4289
4389
  import { Command as Command13 } from "commander";
4390
+ 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) => {
4391
+ const repoSlug = await resolveRepoOrExit({ repo: options.repo, cwd: process.cwd() });
4392
+ if (!options.yes && process.stdin.isTTY) {
4393
+ const confirmed = await promptForConfirmation(
4394
+ `
4395
+ Shutdown '${name}'? This will stop the container. (y/N) `
4396
+ );
4397
+ if (!confirmed) {
4398
+ console.log("Shutdown cancelled");
4399
+ return;
4400
+ }
4401
+ }
4402
+ console.log(`Shutting down instance '${name}'...`);
4403
+ const deps = createShutdownDefaultDeps();
4404
+ try {
4405
+ const result = await shutdownInstance(name, deps, repoSlug);
4406
+ if (!result.ok) {
4407
+ const { code, message, suggestion } = result.error;
4408
+ console.error(formatError(createError(code, message, suggestion)));
4409
+ process.exit(1);
4410
+ return;
4411
+ }
4412
+ console.log(`${chalk4.green("\u2713")} Instance '${name}' shut down`);
4413
+ if (result.tmuxSaved) {
4414
+ console.log(" Tmux session state saved");
4415
+ }
4416
+ } catch (err) {
4417
+ const message = err instanceof Error ? err.message : String(err);
4418
+ console.error(formatError(createError("SHUTDOWN_ERROR", message)));
4419
+ process.exit(1);
4420
+ }
4421
+ });
4422
+
4423
+ // src/commands/tmux-restore.ts
4424
+ import { Command as Command14 } from "commander";
4290
4425
  import { execSync } from "child_process";
4291
4426
  import { join as join12 } from "path";
4292
4427
 
4293
4428
  // src/lib/tmux-session.ts
4294
- import { readFile as readFile13, writeFile as writeFile11, rename as rename8, mkdir as mkdir12 } from "fs/promises";
4429
+ import { readFile as readFile14, writeFile as writeFile12, rename as rename9, mkdir as mkdir13 } from "fs/promises";
4295
4430
  import { dirname as dirname3, join as join11 } from "path";
4296
4431
  async function readPanesState(path) {
4297
4432
  try {
4298
- const content = await readFile13(path, "utf-8");
4433
+ const content = await readFile14(path, "utf-8");
4299
4434
  const parsed = JSON.parse(content);
4300
4435
  if (typeof parsed === "object" && parsed !== null && parsed.version === 1) {
4301
4436
  return parsed;
@@ -4306,14 +4441,14 @@ async function readPanesState(path) {
4306
4441
  }
4307
4442
  }
4308
4443
  async function writePanesState(path, state) {
4309
- await mkdir12(dirname3(path), { recursive: true });
4444
+ await mkdir13(dirname3(path), { recursive: true });
4310
4445
  const tmpPath = path + ".tmp";
4311
- await writeFile11(tmpPath, JSON.stringify(state), "utf-8");
4312
- await rename8(tmpPath, path);
4446
+ await writeFile12(tmpPath, JSON.stringify(state), "utf-8");
4447
+ await rename9(tmpPath, path);
4313
4448
  }
4314
4449
  async function readSessionState(path) {
4315
4450
  try {
4316
- const content = await readFile13(path, "utf-8");
4451
+ const content = await readFile14(path, "utf-8");
4317
4452
  const parsed = JSON.parse(content);
4318
4453
  if (typeof parsed === "object" && parsed !== null && parsed.version === 1 && Array.isArray(parsed.windows)) {
4319
4454
  return parsed;
@@ -4324,10 +4459,10 @@ async function readSessionState(path) {
4324
4459
  }
4325
4460
  }
4326
4461
  async function writeSessionState(path, state) {
4327
- await mkdir12(dirname3(path), { recursive: true });
4462
+ await mkdir13(dirname3(path), { recursive: true });
4328
4463
  const tmpPath = path + ".tmp";
4329
- await writeFile11(tmpPath, JSON.stringify(state, null, 2), "utf-8");
4330
- await rename8(tmpPath, path);
4464
+ await writeFile12(tmpPath, JSON.stringify(state, null, 2), "utf-8");
4465
+ await rename9(tmpPath, path);
4331
4466
  }
4332
4467
  function pruneStaleEntries(state, activePaneIds) {
4333
4468
  const pruned = { version: 1 };
@@ -4406,7 +4541,7 @@ async function executeTmuxRestore() {
4406
4541
  }
4407
4542
  }
4408
4543
  }
4409
- var tmuxRestoreCommand = new Command13("tmux-restore").description("Restore tmux session state from saved state (container only)").action(async () => {
4544
+ var tmuxRestoreCommand = new Command14("tmux-restore").description("Restore tmux session state from saved state (container only)").action(async () => {
4410
4545
  try {
4411
4546
  await executeTmuxRestore();
4412
4547
  } catch {
@@ -4414,7 +4549,7 @@ var tmuxRestoreCommand = new Command13("tmux-restore").description("Restore tmux
4414
4549
  });
4415
4550
 
4416
4551
  // src/commands/tmux-save.ts
4417
- import { Command as Command14 } from "commander";
4552
+ import { Command as Command15 } from "commander";
4418
4553
  import { execSync as execSync2 } from "child_process";
4419
4554
  import { unlink as unlink2 } from "fs/promises";
4420
4555
  import { join as join13 } from "path";
@@ -4492,7 +4627,7 @@ async function executeTmuxSave() {
4492
4627
  const pruned = pruneStaleEntries(panesState, activePaneIds);
4493
4628
  await writePanesState(panesPath, pruned);
4494
4629
  }
4495
- var tmuxSaveCommand = new Command14("tmux-save").description("Save current tmux session state for persistence across rebuilds (container only)").action(async () => {
4630
+ var tmuxSaveCommand = new Command15("tmux-save").description("Save current tmux session state for persistence across rebuilds (container only)").action(async () => {
4496
4631
  try {
4497
4632
  await executeTmuxSave();
4498
4633
  } catch {
@@ -4500,12 +4635,12 @@ var tmuxSaveCommand = new Command14("tmux-save").description("Save current tmux
4500
4635
  });
4501
4636
 
4502
4637
  // src/commands/tmux-status.ts
4503
- import { Command as Command15 } from "commander";
4638
+ import { Command as Command16 } from "commander";
4504
4639
 
4505
4640
  // src/lib/tmux-status.ts
4506
- import { readFile as readFile14 } from "fs/promises";
4641
+ import { readFile as readFile15 } from "fs/promises";
4507
4642
  var MAX_PURPOSE_DISPLAY_LEN = 40;
4508
- var defaultDeps2 = { readFile: readFile14 };
4643
+ var defaultDeps2 = { readFile: readFile15 };
4509
4644
  function formatTmuxStatus(instance, purpose) {
4510
4645
  if (!instance) return "?";
4511
4646
  if (!purpose) return instance;
@@ -4541,7 +4676,7 @@ var defaultDeps3 = {
4541
4676
  statePath: CONTAINER_STATE_PATH
4542
4677
  };
4543
4678
  function createTmuxStatusCommand(deps = defaultDeps3) {
4544
- return new Command15("tmux-status").description("Output formatted instance status for tmux status bar (container only)").action(async () => {
4679
+ return new Command16("tmux-status").description("Output formatted instance status for tmux status bar (container only)").action(async () => {
4545
4680
  if (!deps.isInsideContainer()) {
4546
4681
  console.log("?");
4547
4682
  return;
@@ -4553,7 +4688,7 @@ function createTmuxStatusCommand(deps = defaultDeps3) {
4553
4688
  var tmuxStatusCommand = createTmuxStatusCommand();
4554
4689
 
4555
4690
  // src/lib/update-check.ts
4556
- import chalk4 from "chalk";
4691
+ import chalk5 from "chalk";
4557
4692
  import * as fs from "fs/promises";
4558
4693
  import { dirname as dirname4 } from "path";
4559
4694
  function normaliseVersion(version2) {
@@ -4612,8 +4747,8 @@ async function fetchLatestVersion(packageName, fetchFn) {
4612
4747
  }
4613
4748
  function formatUpdateMessage(currentVersion, latestVersion, packageName) {
4614
4749
  const normCurrent = normaliseVersion(currentVersion);
4615
- const line1 = chalk4.yellow(`Update available: ${normCurrent} -> ${latestVersion}`);
4616
- const line2 = chalk4.cyan(`Run: pnpm add -g ${packageName}`);
4750
+ const line1 = chalk5.yellow(`Update available: ${normCurrent} -> ${latestVersion}`);
4751
+ const line2 = chalk5.cyan(`Run: pnpm add -g ${packageName}`);
4617
4752
  return `${line1}
4618
4753
  ${line2}`;
4619
4754
  }
@@ -4624,13 +4759,13 @@ async function checkForUpdate(opts) {
4624
4759
  cachePath,
4625
4760
  cacheTtlMs,
4626
4761
  fetchFn = fetch,
4627
- readFile: readFile16 = (p, enc) => fs.readFile(p, enc),
4628
- writeFile: writeFile13 = (p, d, enc) => fs.writeFile(p, d, enc),
4629
- mkdir: mkdir14 = (p, o) => fs.mkdir(p, o),
4762
+ readFile: readFile17 = (p, enc) => fs.readFile(p, enc),
4763
+ writeFile: writeFile14 = (p, d, enc) => fs.writeFile(p, d, enc),
4764
+ mkdir: mkdir15 = (p, o) => fs.mkdir(p, o),
4630
4765
  now = () => Date.now()
4631
4766
  } = opts;
4632
4767
  const currentTime = now();
4633
- const cache = await readCache(cachePath, readFile16);
4768
+ const cache = await readCache(cachePath, readFile17);
4634
4769
  let latestVersion = null;
4635
4770
  const isCacheFresh = cache !== null && currentTime - cache.lastCheck < cacheTtlMs;
4636
4771
  if (isCacheFresh) {
@@ -4638,7 +4773,7 @@ async function checkForUpdate(opts) {
4638
4773
  } else {
4639
4774
  latestVersion = await fetchLatestVersion(packageName, fetchFn);
4640
4775
  if (latestVersion !== null) {
4641
- await writeCache(cachePath, { lastCheck: currentTime, latestVersion }, mkdir14, writeFile13);
4776
+ await writeCache(cachePath, { lastCheck: currentTime, latestVersion }, mkdir15, writeFile14);
4642
4777
  }
4643
4778
  }
4644
4779
  if (latestVersion !== null && isNewerVersion(currentVersion, latestVersion)) {
@@ -4659,6 +4794,7 @@ program.addCommand(attachCommand);
4659
4794
  program.addCommand(pathCommand);
4660
4795
  program.addCommand(codeCommand);
4661
4796
  program.addCommand(rebuildCommand);
4797
+ program.addCommand(shutdownCommand);
4662
4798
  program.addCommand(removeCommand);
4663
4799
  program.addCommand(purposeCommand);
4664
4800
  program.addCommand(onCommand);
@@ -4726,7 +4862,7 @@ var shouldCheck = !!process.stderr.isTTY && !isInsideContainer() && !isLinked &&
4726
4862
  var updateCheckPromise = shouldCheck ? checkForUpdate({
4727
4863
  currentVersion: package_default.version,
4728
4864
  packageName: package_default.name,
4729
- cachePath: join14(homedir10(), ".agent-env", "update-check.json"),
4865
+ cachePath: join14(homedir11(), ".agent-env", "update-check.json"),
4730
4866
  cacheTtlMs: 36e5
4731
4867
  }) : Promise.resolve(null);
4732
4868
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zookanalytics/agent-env",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "CLI for creating isolated, AI-ready development environments",
5
5
  "type": "module",
6
6
  "bin": {