agentcage 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # agentcage
2
2
 
3
- Isolated dev containers for AI coding agents. Each project gets its own Linux container ("box"). **The project source lives
4
- in a Docker volume, not in a folder mounted from your laptop**, so agents in the box can't see your other files. Each box can
3
+ Isolated dev containers for AI coding agents. Each project gets its own Linux container. **The project source lives
4
+ in a Docker volume, not in a folder mounted from your laptop**, so agents in the container can't see your other files. Each container can
5
5
  run an **OpenCode server** that the OpenCode Desktop app on your laptop connects to. The app is only the UI: every agent tool
6
- call (bash, read, edit) runs in the box. Claude Code can be installed in the box too.
6
+ call (bash, read, edit) runs in the container. Claude Code can be installed in the container too.
7
7
 
8
8
  Works on Windows, macOS and Linux, in any terminal (PowerShell, Terminal, bash).
9
9
 
@@ -13,25 +13,25 @@ You need **Docker** (Docker Desktop on Windows/macOS, Docker Engine on Linux), *
13
13
  **OpenCode Desktop** (open it once so its settings exist).
14
14
 
15
15
  ```bash
16
- npm install -g agentcage
16
+ npm install -g agentcage # also updates to the latest version
17
17
  agentcage doctor # checks everything above
18
18
  ```
19
19
 
20
- ## Create a box
20
+ ## Create a container
21
21
 
22
22
  Run `agentcage` and follow the dialog. It asks for:
23
23
 
24
24
  1. **Where the project is:** a folder on this computer (copied once, including untracked files such as `.env.local`)
25
25
  or a git URL (cloned).
26
- 2. **A name** for the box.
26
+ 2. **A name** for the container.
27
27
  3. **Git push access** (if the project has a remote). See [Git push access](#git-push-access).
28
28
  4. **AI agents:** OpenCode (on by default) and/or Claude Code.
29
29
  5. **Extra dev tools:** Python, GitHub CLI, pnpm. Node 24 and uv are always included.
30
30
  6. **Model providers for OpenCode** (Anthropic, OpenAI, OpenRouter, Google, Groq). After the build, OpenCode asks for each
31
31
  API key in your terminal.
32
- 7. **An IDE** to open the box in when it's ready (Cursor, VS Code, Antigravity).
32
+ 7. **An IDE** to open the container in when it's ready (Cursor, VS Code, Antigravity).
33
33
 
34
- Then it builds the box, adds it to OpenCode Desktop as server **agentcage: <name>** with the project
34
+ Then it builds the container, adds it to OpenCode Desktop as server **ac-<name>** with the project
35
35
  `/workspaces/<name>` already open, and opens the IDE.
36
36
 
37
37
  The same works without the dialog:
@@ -44,53 +44,54 @@ AGENTCAGE_GIT_TOKEN=github_pat_... agentcage new https://github.com/me/repo.git
44
44
  ## Commands
45
45
 
46
46
  ```bash
47
- agentcage # menu: create a box, or start/open/shell/upgrade/remove an existing one
48
- agentcage list # boxes, state, port, OpenCode version
47
+ agentcage # menu: create a container, or start/open/shell/upgrade/remove an existing one
48
+ agentcage list # containers, state, port, OpenCode version
49
49
  agentcage start <name> # start after a reboot, print the OpenCode server URL and password
50
- agentcage shell <name> # shell in the box (opencode, claude, git ... work here)
51
- agentcage open <name> [ide] # Cursor (default), VS Code, or another VS Code-based IDE attached to the box
52
- agentcage provider <name> # add model provider API keys to OpenCode in the box
53
- agentcage connect <name> # (re)register the box in OpenCode Desktop
50
+ agentcage shell <name> # shell in the container (opencode, claude, git ... work here)
51
+ agentcage open <name> [ide] # Cursor (default), VS Code, or another VS Code-based IDE attached to the container
52
+ agentcage provider <name> # add model provider API keys to OpenCode in the container
53
+ agentcage connect <name> # (re)register the container in OpenCode Desktop
54
54
  agentcage upgrade <name> # rebuild with the Desktop app's OpenCode version (volumes kept)
55
55
  agentcage stop <name>
56
56
  agentcage remove <name> # delete container, volumes and config
57
+ agentcage version # installed version and the latest on npm
57
58
  agentcage doctor
58
- agentcage adopt <name> # import a box made by the old bash scripts in legacy/
59
+ agentcage adopt <name> # import a container made by the old bash scripts in legacy/
59
60
  ```
60
61
 
61
- Box config lives in `~/.agentcage/<name>/` (`box.json` and the generated `.devcontainer/`). `node_modules`, `.venv` and
62
- `.next` are not copied. Instead the box runs `npm ci` / `uv sync` for every lockfile it finds.
62
+ Container config lives in `~/.agentcage/<name>/` (`container.json` and the generated `.devcontainer/`). `node_modules`, `.venv` and
63
+ `.next` are not copied. Instead the container runs `npm ci` / `uv sync` for every lockfile it finds.
63
64
 
64
65
  ## Git push access
65
66
 
66
- The copy in the box is separate from your laptop's, so changes leave the box via **git push**. The dialog offers two ways:
67
+ The copy in the container is separate from your laptop's, so changes leave the container via **git push**. The dialog offers two ways:
67
68
 
68
69
  - **A token for this repo only (recommended).** The dialog shows how to create one: a fine-grained GitHub token limited to
69
70
  the repo with *Contents: read and write*, a GitLab project access token, or a Bitbucket repository access token. The token
70
- is stored with git's credential store in the box's home volume and used for this repo only. The repo's git config clears
71
+ is stored with git's credential store in the container's home volume and used for this repo only. The repo's git config clears
71
72
  any other credential helper, including the one an attached IDE forwards.
72
73
  Cursor and VS Code still forward your **SSH agent**. To close that path too, set
73
74
  `"dev.containers.copyGitConfig": false` and `"dev.containers.gitCredentialHelperConfigLocation": "none"` in the IDE's
74
75
  settings and turn off SSH agent forwarding.
75
76
  - **Skip: use your IDE's forwarded credentials.** While Cursor or VS Code is attached, your laptop's git credentials and
76
- SSH agent are forwarded into the box, so pushing from the IDE just works. **While the IDE is attached, any agent in the
77
- box can use them to push to every repository you have access to.** When no IDE is attached, the box can't push at all.
77
+ SSH agent are forwarded into the container, so pushing from the IDE just works. **While the IDE is attached, any agent in the
78
+ container can use them to push to every repository you have access to.** When no IDE is attached, the container can't push at all.
78
79
 
79
80
  For a git URL, token mode clones inside a throwaway container with the token. Forward mode clones on your laptop with your
80
- own git credentials, then copies the repo in. Both work with private repos. Your git name and email are copied into the box.
81
+ own git credentials, then copies the repo in. Both work with private repos. Your git name and email are copied into the container.
81
82
 
82
83
  ## OpenCode Desktop
83
84
 
84
85
  agentcage reads the Desktop app's version (from `opencode-cli.version` in its install folder) and installs the same OpenCode
85
- version in the box, because Desktop only talks to matching servers. `list`, `start` and `doctor` warn when the app has
86
- updated since; `agentcage upgrade <name>` rebuilds the box with the new version and keeps your code, logins and sessions.
86
+ version in the container, because Desktop only talks to matching servers. `list`, `start` and `doctor` warn when the app has
87
+ updated since; `agentcage upgrade <name>` rebuilds the container with the new version and keeps your code, logins and sessions.
87
88
 
88
89
  Desktop has no API or deep link for adding a server, so agentcage writes the app's own state DB (`drafts.sqlite` in the
89
90
  app's data folder, backed up as `drafts.sqlite.agentcage-backup`). **The app must be closed for this.** The dialog asks you
90
91
  to close it. This relies on the app's internal storage format (written against Desktop 2.0.23), so a future app update may
91
92
  break it. `agentcage start <name>` always prints the URL, username and password for adding the server by hand.
92
93
 
93
- Provider API keys are typed into OpenCode's own prompt inside the box. They are stored only in the box's home volume,
94
+ Provider API keys are typed into OpenCode's own prompt inside the container. They are stored only in the container's home volume,
94
95
  never on your laptop, and survive rebuilds.
95
96
 
96
97
  ⚠️ Only sessions on the **agentcage server** are isolated. Sessions on the app's built-in **Local** server run on your laptop.
@@ -99,11 +100,11 @@ never on your laptop, and survive rebuilds.
99
100
 
100
101
  - ✅ No host folders mounted, no Docker socket, not privileged. The OpenCode server is published only on `127.0.0.1` and
101
102
  requires a random password.
102
- - ⚠️ The box has internet access and can reach services on your laptop via `host.docker.internal`.
103
+ - ⚠️ The container has internet access and can reach services on your laptop via `host.docker.internal`.
103
104
  - ⚠️ Secrets you copy in (for example `.env.local`) and provider keys can be read by agents. Use dev and test keys.
104
105
  - ⚠️ An attached IDE forwards your SSH agent, and in forward mode your git credentials (see above).
105
- - ⚠️ Use the IDE for editing, diffs and git. Its built-in AI agent runs outside the box's isolation, so run agents through
106
- OpenCode or Claude Code in the box.
106
+ - ⚠️ Use the IDE for editing, diffs and git. Its built-in AI agent runs outside the container's isolation, so run agents through
107
+ OpenCode or Claude Code in the container.
107
108
 
108
109
  ## Platform notes
109
110
 
@@ -144,11 +145,11 @@ The setup dialog should let the user choose the backend: **plain Docker containe
144
145
  Windows 11 with Hypervisor Platform.
145
146
  6. OpenCode API keys: `opencode auth login` only accepts keys interactively, but with `sbx secret` this is not needed.
146
147
 
147
- **Plan:** add a `backend: docker | sbx` choice to the dialog and `box.json`. The `sbx` backend maps our steps to
148
+ **Plan:** add a `backend: docker | sbx` choice to the dialog and `container.json`. The `sbx` backend maps our steps to
148
149
  `sbx create --clone -p 127.0.0.1:<port>:4096 opencode <repo>`, `sbx secret set <provider|github> --sandbox <name>`, and
149
150
  an OpenCode kit that pins the Desktop version and starts `opencode serve` at boot. The wizard, version detection and Desktop
150
151
  registration stay the same.
151
152
 
152
153
  ## Legacy
153
154
 
154
- `legacy/` holds the original bash scripts this tool replaces. `agentcage adopt <name>` takes over a box they created.
155
+ `legacy/` holds the original bash scripts this tool replaces. `agentcage adopt <name>` takes over a container they created.
package/bin/agentcage.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
2
3
  import { parseArgs } from 'node:util';
3
4
  import * as p from '@clack/prompts';
4
- import { adoptBox, listBoxes, loadBox, removeBox, saveBox, state, up, writeDevcontainer, openIde, ws } from '../src/box.js';
5
+ import { adoptContainer, listContainers, loadContainer, removeContainer, saveContainer, state, up, writeDevcontainer, openIde, ws } from '../src/container.js';
5
6
  import { ask, connectionInfo, newWizard, providerFlow, registerFlow } from '../src/wizard.js';
6
7
  import { detectDesktop, latestVersion } from '../src/opencode.js';
7
8
  import { ok, run } from '../src/run.js';
@@ -10,35 +11,36 @@ process.removeAllListeners('warning'); // hide node:sqlite ExperimentalWarning
10
11
 
11
12
  const HELP = `agentcage: isolated dev containers for AI coding agents
12
13
 
13
- agentcage interactive menu (create or manage boxes)
14
- agentcage new [folder|git-url] create a box [--name x] [--tools opencode,claude-code,python,gh,pnpm]
14
+ agentcage interactive menu (create or manage containers)
15
+ agentcage new [folder|git-url] create a container [--name x] [--tools opencode,claude-code,python,gh,pnpm]
15
16
  [--git token|forward] [--providers anthropic,...] [--ide cursor|code|none] [--yes]
16
- agentcage list boxes, state, port, OpenCode version
17
- agentcage start <name> start a box and print OpenCode connection details
17
+ agentcage list containers, state, port, OpenCode version
18
+ agentcage start <name> start a container and print OpenCode connection details
18
19
  agentcage stop <name>
19
- agentcage shell <name> shell in the box (run opencode, claude, git ... here)
20
- agentcage open <name> [ide] open Cursor (default), VS Code or another VS Code-based IDE attached to the box
21
- agentcage connect <name> (re)register the box in OpenCode Desktop (app must be closed)
22
- agentcage provider <name> add model provider API keys to OpenCode in the box
20
+ agentcage shell <name> shell in the container (run opencode, claude, git ... here)
21
+ agentcage open <name> [ide] open Cursor (default), VS Code or another VS Code-based IDE attached to the container
22
+ agentcage connect <name> (re)register the container in OpenCode Desktop (app must be closed)
23
+ agentcage provider <name> add model provider API keys to OpenCode in the container
23
24
  agentcage upgrade <name> rebuild with the Desktop app's OpenCode version (volumes kept)
24
25
  agentcage remove <name> delete container, volumes and config
26
+ agentcage version installed version, and the latest on npm (update: npm i -g agentcage@latest)
25
27
  agentcage doctor check Docker, Node and OpenCode Desktop
26
- agentcage adopt <name> import a box made by the old devbox bash scripts
28
+ agentcage adopt <name> import a container made by the old devbox bash scripts
27
29
 
28
30
  In token mode, a token can also be passed in the AGENTCAGE_GIT_TOKEN environment variable.`;
29
31
 
30
32
  let { values: f, positionals: [cmd, arg, arg2] } = parseArgs({
31
33
  allowPositionals: true,
32
34
  options: { name: { type: 'string' }, tools: { type: 'string' }, git: { type: 'string' }, providers: { type: 'string' },
33
- ide: { type: 'string' }, yes: { type: 'boolean', short: 'y' }, help: { type: 'boolean', short: 'h' } },
35
+ ide: { type: 'string' }, yes: { type: 'boolean', short: 'y' }, help: { type: 'boolean', short: 'h' }, version: { type: 'boolean', short: 'v' } },
34
36
  });
35
37
  const csv = s => s?.split(',').map(x => x.trim()).filter(Boolean);
36
- const box = () => loadBox(arg ?? (() => { throw new Error(`Usage: agentcage ${cmd} <name>`); })());
38
+ const container = () => loadContainer(arg ?? (() => { throw new Error(`Usage: agentcage ${cmd} <name>`); })());
37
39
 
38
40
  function versionWarning(b) {
39
41
  const v = detectDesktop().version;
40
42
  if (b.tools.includes('opencode') && v && b.opencodeVersion !== v)
41
- p.log.warn(`OpenCode Desktop is ${v}, box '${b.name}' has ${b.opencodeVersion}. If Desktop can't connect: agentcage upgrade ${b.name}`);
43
+ p.log.warn(`OpenCode Desktop is ${v}, container '${b.name}' has ${b.opencodeVersion}. If Desktop can't connect: agentcage upgrade ${b.name}`);
42
44
  }
43
45
  async function start(b) {
44
46
  // devcontainer up (not docker start) so postStartCommand starts the OpenCode server
@@ -47,35 +49,40 @@ async function start(b) {
47
49
  }
48
50
 
49
51
  const commands = {
52
+ async version() {
53
+ const v = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
54
+ const latest = await fetch('https://registry.npmjs.org/agentcage/latest').then(r => r.json()).then(j => j.version, () => undefined);
55
+ console.log(`agentcage ${v}${!latest ? '' : latest === v ? ' (latest)' : `\nNewer version ${latest} on npm. Update with: npm i -g agentcage@latest`}`);
56
+ },
50
57
  async new() { await newWizard({ src: arg, name: f.name, tools: csv(f.tools), git: f.git, providers: csv(f.providers), ide: f.ide, yes: f.yes }); },
51
58
  list() {
52
- const rows = listBoxes().map(b => [b.name, state(b), b.tools.includes('opencode') ? String(b.port) : '-', b.opencodeVersion ?? '-', b.git]);
53
- if (!rows.length) return console.log('No boxes yet. Create one with: agentcage new');
59
+ const rows = listContainers().map(b => [b.name, state(b), b.tools.includes('opencode') ? String(b.port) : '-', b.opencodeVersion ?? '-', b.git]);
60
+ if (!rows.length) return console.log('No containers yet. Create one with: agentcage new');
54
61
  const all = [['NAME', 'STATE', 'PORT', 'OPENCODE', 'GIT'], ...rows], w = all[0].map((_, i) => Math.max(...all.map(r => r[i].length)));
55
62
  console.log(all.map(r => r.map((c, i) => c.padEnd(w[i])).join(' ')).join('\n'));
56
63
  const v = detectDesktop().version;
57
64
  if (v) console.log(`\nOpenCode Desktop: ${v}`);
58
65
  },
59
- async start() { const b = box(); await start(b); console.log(`Box '${b.name}' is running.\n${b.tools.includes('opencode') ? connectionInfo(b) : ''}`); },
60
- async stop() { await run('docker', ['stop', box().container]); },
61
- async shell() { const b = box(); await start(b); await run('docker', ['exec', '-it', '-u', 'node', '-w', ws(b), b.container, 'bash', '-l'], { tty: true }).catch(() => {}); },
66
+ async start() { const b = container(); await start(b); console.log(`Container '${b.name}' is running.\n${b.tools.includes('opencode') ? connectionInfo(b) : ''}`); },
67
+ async stop() { await run('docker', ['stop', container().container]); },
68
+ async shell() { const b = container(); await start(b); await run('docker', ['exec', '-it', '-u', 'node', '-w', ws(b), b.container, 'bash', '-l'], { tty: true }).catch(() => {}); },
62
69
  async open() {
63
- const b = box(); await start(b); openIde(b, arg2 ?? f.ide ?? 'cursor');
64
- if (b.git === 'token') p.log.warn('The IDE forwards your SSH agent into the box. Turn it off in the IDE settings to keep pushes limited to the repo token (see README).');
70
+ const b = container(); await start(b); openIde(b, arg2 ?? f.ide ?? 'cursor');
71
+ if (b.git === 'token') p.log.warn('The IDE forwards your SSH agent into the container. Turn it off in the IDE settings to keep pushes limited to the repo token (see README).');
65
72
  },
66
- async connect() { await registerFlow(box()); },
67
- async provider() { const b = box(); await start(b); await providerFlow(b, csv(f.providers)); },
73
+ async connect() { await registerFlow(container()); },
74
+ async provider() { const b = container(); await start(b); await providerFlow(b, csv(f.providers)); },
68
75
  async upgrade() {
69
- const b = box(), v = detectDesktop().version ?? await latestVersion();
76
+ const b = container(), v = detectDesktop().version ?? await latestVersion();
70
77
  const s = p.spinner(); s.start(`Rebuilding '${b.name}' with OpenCode ${v} (volumes are kept)`);
71
78
  b.opencodeVersion = v; writeDevcontainer(b);
72
79
  await up(b, true).then(() => s.stop(`Rebuilt with OpenCode ${v}`), e => { s.error('Rebuild failed'); throw e; });
73
- saveBox(b);
80
+ saveContainer(b);
74
81
  },
75
82
  async remove() {
76
- const b = box();
77
- if (!f.yes && !(await ask(p.confirm({ message: `Delete box '${b.name}' with its volumes? Unpushed work in the box is lost.`, initialValue: false })))) return;
78
- await removeBox(b); console.log(`Removed '${b.name}'.`);
83
+ const b = container();
84
+ if (!f.yes && !(await ask(p.confirm({ message: `Delete container '${b.name}' with its volumes? Unpushed work in the container is lost.`, initialValue: false })))) return;
85
+ await removeContainer(b); console.log(`Removed '${b.name}'.`);
79
86
  },
80
87
  doctor() {
81
88
  const d = detectDesktop(), [maj, min] = process.versions.node.split('.').map(Number);
@@ -84,19 +91,19 @@ const commands = {
84
91
  [ok('docker', ['info']), 'Docker is running', 'Install/start Docker Desktop (Windows, macOS) or Docker Engine (Linux)'],
85
92
  [ok('git', ['--version']), 'git installed', 'Install git'],
86
93
  [d.hasDb, `OpenCode Desktop data: ${d.dataDir}`, 'Install OpenCode Desktop and open it once (or add servers by hand)'],
87
- [!!d.version, `OpenCode Desktop version: ${d.version ?? 'unknown'}${d.from ? ` (from ${d.from})` : ''}`, 'Version not found: boxes use the newest OpenCode'],
94
+ [!!d.version, `OpenCode Desktop version: ${d.version ?? 'unknown'}${d.from ? ` (from ${d.from})` : ''}`, 'Version not found: containers use the newest OpenCode'],
88
95
  ];
89
96
  for (const [good, msg, fix] of checks) good ? p.log.success(msg) : p.log.warn(`${msg}\n${fix}`);
90
- for (const b of listBoxes()) if (b.tools.includes('opencode') && d.version && b.opencodeVersion !== d.version) p.log.warn(`Box '${b.name}' has OpenCode ${b.opencodeVersion}: agentcage upgrade ${b.name}`);
97
+ for (const b of listContainers()) if (b.tools.includes('opencode') && d.version && b.opencodeVersion !== d.version) p.log.warn(`Container '${b.name}' has OpenCode ${b.opencodeVersion}: agentcage upgrade ${b.name}`);
91
98
  },
92
- adopt() { const b = adoptBox(arg); console.log(`Adopted '${b.name}' (${b.container}).`); },
99
+ adopt() { const b = adoptContainer(arg); console.log(`Adopted '${b.name}' (${b.container}).`); },
93
100
 
94
101
  // No command: menu
95
102
  async menu() {
96
- const boxes = listBoxes();
97
- if (!boxes.length) return newWizard();
103
+ const containers = listContainers();
104
+ if (!containers.length) return newWizard();
98
105
  p.intro('agentcage');
99
- const pick = await ask(p.select({ message: 'What do you want to do?', options: [{ value: '', label: 'Create a new box' }, ...boxes.map(b => ({ value: b.name, label: b.name, hint: state(b) }))] }));
106
+ const pick = await ask(p.select({ message: 'What do you want to do?', options: [{ value: '', label: 'Create a new container' }, ...containers.map(b => ({ value: b.name, label: b.name, hint: state(b) }))] }));
100
107
  if (!pick) return newWizard();
101
108
  const action = await ask(p.select({ message: pick, options: [
102
109
  { value: 'start', label: 'Start and show connection details' }, { value: 'open', label: 'Open in IDE' },
@@ -109,6 +116,7 @@ const commands = {
109
116
  },
110
117
  };
111
118
 
119
+ if (f.version) cmd = 'version';
112
120
  if (f.help || cmd === 'help') console.log(HELP);
113
121
  else if (cmd && !commands[cmd]) { console.error(`Unknown command '${cmd}'.\n\n${HELP}`); process.exit(1); }
114
122
  else await Promise.resolve().then(() => commands[cmd ?? 'menu']()).catch(e => { p.log.error(e.message); process.exit(1); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentcage",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Isolated dev containers for AI coding agents (OpenCode, Claude Code), connected to OpenCode Desktop",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,5 +1,5 @@
1
- // Box state (~/.agentcage/<name>/box.json), devcontainer.json generation and the box lifecycle.
2
- import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
1
+ // Container state (~/.agentcage/<name>/container.json), devcontainer.json generation and the container lifecycle.
2
+ import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
4
  import { join, resolve } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
@@ -11,29 +11,34 @@ import { copyIdentity, isGitUrl, parseRemote, seed, setupToken } from './git.js'
11
11
 
12
12
  export const ROOT = join(homedir(), '.agentcage');
13
13
  const TEMPLATE = fileURLToPath(new URL('../template/', import.meta.url));
14
- const boxFile = name => join(ROOT, name, 'box.json');
14
+ // Configs from before the box -> container rename are moved to container.json on first access
15
+ const cfgFile = name => {
16
+ const f = join(ROOT, name, 'container.json'), old = join(ROOT, name, 'box.json');
17
+ if (!existsSync(f) && existsSync(old)) renameSync(old, f);
18
+ return f;
19
+ };
15
20
  export const ws = b => `/workspaces/${b.name}`;
16
21
 
17
- export const hasBox = name => existsSync(boxFile(name));
18
- export function loadBox(name) {
19
- if (!hasBox(name)) throw new Error(`No box named '${name}'. See: agentcage list`);
20
- return JSON.parse(readFileSync(boxFile(name), 'utf8'));
22
+ export const hasContainer = name => existsSync(cfgFile(name));
23
+ export function loadContainer(name) {
24
+ if (!hasContainer(name)) throw new Error(`No container named '${name}'. See: agentcage list`);
25
+ return JSON.parse(readFileSync(cfgFile(name), 'utf8'));
21
26
  }
22
- export function saveBox(b) {
27
+ export function saveContainer(b) {
23
28
  mkdirSync(join(ROOT, b.name), { recursive: true });
24
- writeFileSync(boxFile(b.name), JSON.stringify(b, null, 2));
29
+ writeFileSync(cfgFile(b.name), JSON.stringify(b, null, 2));
25
30
  }
26
- export const listBoxes = () => (existsSync(ROOT) ? readdirSync(ROOT).filter(hasBox).map(loadBox) : []);
31
+ export const listContainers = () => (existsSync(ROOT) ? readdirSync(ROOT).filter(hasContainer).map(loadContainer) : []);
27
32
 
28
33
  export const cleanName = s => s.replace(/\.git\/?$/, '').replace(/[\\/:]+$/, '').replace(/.*[:\\/]/, '')
29
34
  .toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/^-+|-+$/g, '');
30
- export const nameTaken = n => hasBox(n) || ok('docker', ['volume', 'inspect', `agentcage-${n}-src`]);
35
+ export const nameTaken = n => hasContainer(n) || ok('docker', ['inspect', `ac-${n}`]) || ok('docker', ['volume', 'inspect', `ac-${n}-src`]);
31
36
 
32
37
  const bindable = port => new Promise(r => {
33
38
  const s = createServer().once('error', () => r(false)).listen(port, '127.0.0.1', () => s.close(() => r(true)));
34
39
  });
35
40
  async function freePort() {
36
- const used = new Set(listBoxes().map(b => b.port));
41
+ const used = new Set(listContainers().map(b => b.port));
37
42
  for (const m of runSync('docker', ['ps', '-a', '--format', '{{.Ports}}']).matchAll(/:(\d+)->/g)) used.add(+m[1]);
38
43
  for (let p = 4100; ; p++) if (!used.has(p) && (await bindable(p))) return p;
39
44
  }
@@ -66,18 +71,18 @@ export const up = (b, rebuild) => devcontainer(['up', '--workspace-folder', b.di
66
71
  export const state = b => runSync('docker', ['inspect', '-f', '{{.State.Status}}', b.container]) || 'missing';
67
72
 
68
73
  // o: { src, name, tools, git: 'token'|'forward'|'none', token, opencodeVersion }. step(label, fn) shows progress.
69
- export async function createBox(o, step = (_, f) => f()) {
74
+ export async function createContainer(o, step = (_, f) => f()) {
70
75
  const { name } = o, src = isGitUrl(o.src) ? o.src : resolve(o.src);
71
76
  const b = {
72
- name, dir: join(ROOT, name), container: `agentcage-${name}`,
73
- volumes: { src: `agentcage-${name}-src`, home: `agentcage-${name}-home` },
77
+ name, dir: join(ROOT, name), container: `ac-${name}`,
78
+ volumes: { src: `ac-${name}-src`, home: `ac-${name}-home` },
74
79
  port: await freePort(), password: randomBytes(16).toString('hex'),
75
80
  source: src, git: o.git, tools: o.tools, opencodeVersion: o.opencodeVersion, created: new Date().toISOString(),
76
81
  };
77
- saveBox(b);
82
+ saveContainer(b);
78
83
  writeDevcontainer(b);
79
84
  await run('docker', ['volume', 'create', b.volumes.src]);
80
- await step('Copying the source into the box', () => seed(b.volumes.src, { ...o, src }));
85
+ await step('Copying the source into the container', () => seed(b.volumes.src, { ...o, src }));
81
86
  await step('Building and starting the container (the first build takes a few minutes)', () => up(b));
82
87
  await step('Setting up git', async () => {
83
88
  await copyIdentity(b.container);
@@ -86,7 +91,7 @@ export async function createBox(o, step = (_, f) => f()) {
86
91
  return b;
87
92
  }
88
93
 
89
- export async function removeBox(b) {
94
+ export async function removeContainer(b) {
90
95
  await run('docker', ['rm', '-f', b.container]).catch(() => {});
91
96
  for (const v of Object.values(b.volumes)) await run('docker', ['volume', 'rm', v]).catch(() => {});
92
97
  rmSync(b.dir, { recursive: true, force: true });
@@ -99,10 +104,10 @@ export function openIde(b, ide) {
99
104
  launch(ide, ['--folder-uri', `vscode-remote://attached-container+${hex}${ws(b)}`]);
100
105
  }
101
106
 
102
- // Import a box made by the old bash kit (~/devboxes/<name>, devbox-<name> container and volumes)
103
- export function adoptBox(name) {
107
+ // Import a container made by the old bash kit (~/devboxes/<name>, devbox-<name> container and volumes)
108
+ export function adoptContainer(name) {
104
109
  const dir = join(homedir(), 'devboxes', name), cfg = join(dir, '.devcontainer', 'devcontainer.json');
105
- if (!existsSync(cfg)) throw new Error(`No legacy box at ${dir}`);
110
+ if (!existsSync(cfg)) throw new Error(`No legacy container at ${dir}`);
106
111
  const text = readFileSync(cfg, 'utf8'), docker = readFileSync(join(dir, '.devcontainer', 'Dockerfile'), 'utf8');
107
112
  const b = {
108
113
  name, dir, container: `devbox-${name}`, volumes: { src: `devbox-${name}-src`, home: `devbox-${name}-home` },
@@ -110,6 +115,6 @@ export function adoptBox(name) {
110
115
  source: 'legacy devbox', git: 'forward', tools: ['opencode'], opencodeVersion: docker.match(/OPENCODE_VERSION=(\S+)/)?.[1],
111
116
  created: new Date().toISOString(), legacy: true,
112
117
  };
113
- saveBox(b);
118
+ saveContainer(b);
114
119
  return b;
115
120
  }
package/src/git.js CHANGED
@@ -1,4 +1,4 @@
1
- // Getting the source into the box, and git push credentials inside it.
1
+ // Getting the source into the container, and git push credentials inside it.
2
2
  import { mkdtempSync, rmSync } from 'node:fs';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
@@ -43,7 +43,7 @@ export async function copyIdentity(container) {
43
43
  }
44
44
  }
45
45
 
46
- // Repo-scoped token: stored with git's credential store in the box's home volume, used for this repo only.
46
+ // Repo-scoped token: stored with git's credential store in the container's home volume, used for this repo only.
47
47
  // The empty credential.helper entry clears helpers set earlier (such as the one an attached IDE forwards).
48
48
  const TOKEN_SETUP = `IFS= read -r T; umask 077
49
49
  printf 'https://%s:%s@%s/%s.git\\n' "$1" "$T" "$2" "$3" > ~/.git-credentials
package/src/opencode.js CHANGED
@@ -1,4 +1,4 @@
1
- // OpenCode Desktop on the host: where it lives, its version, whether it runs, and registering boxes in it.
1
+ // OpenCode Desktop on the host: where it lives, its version, whether it runs, and registering containers in it.
2
2
  import { copyFileSync, existsSync, readFileSync, readdirSync } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
4
  import { join } from 'node:path';
@@ -33,17 +33,17 @@ export const desktopRunning = () => P === 'win32'
33
33
  export const latestVersion = async () => (await (await fetch('https://registry.npmjs.org/@opencode/cli/latest')).json()).version;
34
34
 
35
35
  // Desktop has no API or deep link for adding a server, so write its state DB (app must be closed). A backup is kept.
36
- export async function connectDesktop(box) {
36
+ export async function connectDesktop(container) {
37
37
  const { db, hasDb } = detectDesktop();
38
38
  if (!hasDb) throw new Error(`OpenCode Desktop state not found at ${db}. Open the app once first.`);
39
39
  if (desktopRunning()) throw new Error('OpenCode Desktop is running. Close it first.');
40
40
  copyFileSync(db, db + '.agentcage-backup');
41
41
  const { DatabaseSync } = await import('node:sqlite');
42
- const d = new DatabaseSync(db), url = `http://127.0.0.1:${box.port}`, dir = `/workspaces/${box.name}`;
42
+ const d = new DatabaseSync(db), url = `http://127.0.0.1:${container.port}`, dir = `/workspaces/${container.name}`;
43
43
  const row = d.prepare("select value from state where name='opencode.global.dat' and key='server'").get();
44
44
  const s = { list: [], hidden: {}, projects: {}, lastProject: {}, recentlyClosed: {}, ...(row && JSON.parse(row.value)) };
45
45
  const urlOf = x => (typeof x === 'string' ? x : x.http?.url ?? x.url);
46
- s.list = s.list.filter(x => urlOf(x) !== url).concat({ type: 'http', http: { url, password: box.password }, displayName: `agentcage: ${box.name}` });
46
+ s.list = s.list.filter(x => urlOf(x) !== url).concat({ type: 'http', http: { url, password: container.password }, displayName: `ac-${container.name}` });
47
47
  s.projects[url] = [{ worktree: dir, expanded: true }];
48
48
  s.lastProject[url] = dir;
49
49
  d.prepare(`insert into state(name, key, value, updated_at) values ('opencode.global.dat', 'server', ?, ?)
@@ -51,7 +51,7 @@ export async function connectDesktop(box) {
51
51
  d.close();
52
52
  }
53
53
 
54
- // OpenCode only reads API keys from an interactive terminal, so hand the terminal to its own prompt inside the box.
55
- // The key goes straight into the box's home volume and never passes through agentcage or the host.
56
- export const loginProvider = (box, provider) =>
57
- run('docker', ['exec', '-it', '-u', 'node', '-w', '/tmp', box.container, 'opencode', 'auth', 'login', provider, '--method', 'key'], { tty: true });
54
+ // OpenCode only reads API keys from an interactive terminal, so hand the terminal to its own prompt inside the container.
55
+ // The key goes straight into the container's home volume and never passes through agentcage or the host.
56
+ export const loginProvider = (container, provider) =>
57
+ run('docker', ['exec', '-it', '-u', 'node', '-w', '/tmp', container.container, 'opencode', 'auth', 'login', provider, '--method', 'key'], { tty: true });
package/src/wizard.js CHANGED
@@ -1,9 +1,9 @@
1
- // Interactive dialogs (@clack/prompts) on top of the box functions. Flags pre-fill answers; --yes takes defaults.
1
+ // Interactive dialogs (@clack/prompts) on top of the container functions. Flags pre-fill answers; --yes takes defaults.
2
2
  import * as p from '@clack/prompts';
3
3
  import { existsSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { AGENTS, DEV_TOOLS, PROVIDERS, hostInfo } from './catalog.js';
6
- import { cleanName, createBox, nameTaken, openIde, ws } from './box.js';
6
+ import { cleanName, createContainer, nameTaken, openIde, ws } from './container.js';
7
7
  import { isGitUrl, localRemote, parseRemote } from './git.js';
8
8
  import { connectDesktop, desktopRunning, detectDesktop, latestVersion, loginProvider } from './opencode.js';
9
9
  import { ok, runSync } from './run.js';
@@ -22,10 +22,10 @@ const step = async (label, fn) => {
22
22
  export const connectionInfo = b =>
23
23
  `Server http://127.0.0.1:${b.port}\nUsername opencode\nPassword ${b.password}\nDirectory ${ws(b)}`;
24
24
 
25
- const FORWARD_WARNING = `While Cursor or VS Code is attached to the box, your laptop's git credentials
26
- and SSH agent are forwarded into the container. Any agent running in the box at
25
+ const FORWARD_WARNING = `While Cursor or VS Code is attached to the container, your laptop's git credentials
26
+ and SSH agent are forwarded into the container. Any agent running in the container at
27
27
  that time can use them to push to EVERY repository you have access to, not only
28
- this one. When no IDE is attached, the box cannot push at all.`;
28
+ this one. When no IDE is attached, the container cannot push at all.`;
29
29
 
30
30
  // IDEs that can attach to a container, found on PATH or in their usual install folder
31
31
  function findIdes() {
@@ -42,21 +42,21 @@ async function waitForDocker() {
42
42
  }
43
43
  }
44
44
 
45
- // Registers the box in OpenCode Desktop, asking the user to close the app if needed
45
+ // Registers the container in OpenCode Desktop, asking the user to close the app if needed
46
46
  export async function registerFlow(b, interactive = true) {
47
47
  if (!detectDesktop().hasDb) return p.note(connectionInfo(b), 'OpenCode Desktop not found. Add this server by hand');
48
48
  while (desktopRunning()) {
49
49
  if (!interactive) return p.log.warn(`OpenCode Desktop is open. Close it, then run: agentcage connect ${b.name}`);
50
- const go = await ask(p.confirm({ message: 'Close OpenCode Desktop so the box can be added to it.', active: 'It is closed now', inactive: 'Skip for now' }));
50
+ const go = await ask(p.confirm({ message: 'Close OpenCode Desktop so the container can be added to it.', active: 'It is closed now', inactive: 'Skip for now' }));
51
51
  if (!go) return p.log.info(`Later: agentcage connect ${b.name}`);
52
52
  }
53
53
  await connectDesktop(b);
54
- p.log.success(`OpenCode Desktop: added server "agentcage: ${b.name}" with project ${ws(b)}`);
54
+ p.log.success(`OpenCode Desktop: added server "ac-${b.name}" with project ${ws(b)}`);
55
55
  }
56
56
 
57
57
  // Hands the terminal to OpenCode's own key prompt for each provider
58
58
  export async function providerFlow(b, ids) {
59
- ids ??= await ask(p.multiselect({ message: 'Which providers should OpenCode use in this box?', options: PROVIDERS.map(x => ({ value: x.id, label: x.label, hint: x.hint })) }));
59
+ ids ??= await ask(p.multiselect({ message: 'Which providers should OpenCode use in this container?', options: PROVIDERS.map(x => ({ value: x.id, label: x.label, hint: x.hint })) }));
60
60
  for (const id of ids) {
61
61
  const pr = PROVIDERS.find(x => x.id === id);
62
62
  p.log.step(`${pr.label}: paste your API key when OpenCode asks for it (get one at ${pr.hint}).`);
@@ -66,7 +66,7 @@ export async function providerFlow(b, ids) {
66
66
 
67
67
  export async function newWizard(f = {}) {
68
68
  const pick = (flag, def, prompt) => (flag !== undefined ? flag : f.yes ? def : prompt());
69
- p.intro('agentcage · new box');
69
+ p.intro('agentcage · new container');
70
70
  await waitForDocker();
71
71
 
72
72
  const src = f.src ?? await ask((await ask(p.select({ message: 'Where is the project?', options: [
@@ -77,15 +77,15 @@ export async function newWizard(f = {}) {
77
77
  : p.text({ message: 'Repository URL', placeholder: 'https://github.com/owner/repo.git', validate: v => (isGitUrl(v ?? '') ? undefined : 'Enter an https:// or git@ URL') }));
78
78
  if (!isGitUrl(src) && !existsSync(src)) throw new Error(`Folder not found: ${src}`);
79
79
 
80
- const nameOk = v => (!/^[a-z0-9][a-z0-9-]*$/.test(v ?? '') ? 'Use lowercase letters, digits and -' : nameTaken(v) ? `A box named '${v}' already exists` : undefined);
81
- const name = await pick(f.name, cleanName(src), () => ask(p.text({ message: 'Box name', initialValue: cleanName(src), validate: nameOk })));
80
+ const nameOk = v => (!/^[a-z0-9][a-z0-9-]*$/.test(v ?? '') ? 'Use lowercase letters, digits and -' : nameTaken(v) ? `A container named '${v}' already exists` : undefined);
81
+ const name = await pick(f.name, cleanName(src), () => ask(p.text({ message: 'Container name (the Docker container and the OpenCode server get the prefix "ac-")', initialValue: cleanName(src), validate: nameOk })));
82
82
  if (nameOk(name)) throw new Error(nameOk(name));
83
83
 
84
84
  // Git push access
85
85
  const remoteUrl = isGitUrl(src) ? src : localRemote(src), remote = parseRemote(remoteUrl);
86
86
  let git = 'none', token;
87
87
  if (remote) {
88
- git = await pick(f.git, 'forward', () => ask(p.select({ message: `How should the box push to ${remote.host}/${remote.path}?`, options: [
88
+ git = await pick(f.git, 'forward', () => ask(p.select({ message: `How should the container push to ${remote.host}/${remote.path}?`, options: [
89
89
  { value: 'token', label: 'A token for this repo only', hint: 'recommended: agents can only push here' },
90
90
  { value: 'forward', label: "Skip: use my IDE's forwarded credentials", hint: 'access to all your repos while the IDE is attached' },
91
91
  ] })));
@@ -107,13 +107,13 @@ export async function newWizard(f = {}) {
107
107
  let opencodeVersion, providers = [];
108
108
  if (oc) {
109
109
  const d = detectDesktop();
110
- opencodeVersion = d.version ?? await pick(undefined, await latestVersion(), async () => ask(p.text({ message: 'OpenCode Desktop not found. OpenCode version for the box', initialValue: await latestVersion() })));
110
+ opencodeVersion = d.version ?? await pick(undefined, await latestVersion(), async () => ask(p.text({ message: 'OpenCode Desktop not found. OpenCode version for the container', initialValue: await latestVersion() })));
111
111
  if (d.version) p.log.info(`OpenCode ${d.version} (matches your Desktop app)`);
112
- providers = await pick(f.providers, [], () => ask(p.multiselect({ message: 'Model providers to connect (you paste each API key after the build)', options: PROVIDERS.map(x => ({ value: x.id, label: x.label, hint: x.hint })), required: false })));
112
+ providers = await pick(f.providers, [], () => ask(p.multiselect({ message: 'Additional OpenCode model providers to connect (you paste each API key after the build)', options: PROVIDERS.map(x => ({ value: x.id, label: x.label, hint: x.hint })), required: false })));
113
113
  }
114
114
 
115
115
  const ides = findIdes();
116
- const ide = await pick(f.ide, 'none', () => ides.length ? ask(p.select({ message: 'Open the box in an IDE when done?', options: [...ides, { value: 'none', label: 'No' }] })) : 'none');
116
+ const ide = await pick(f.ide, 'none', () => ides.length ? ask(p.select({ message: 'Open the container in an IDE when done?', options: [...ides, { value: 'none', label: 'No' }] })) : 'none');
117
117
 
118
118
  p.note([
119
119
  `Source ${src}`, `Name ${name}`,
@@ -121,22 +121,22 @@ export async function newWizard(f = {}) {
121
121
  `Tools ${tools.join(', ') || 'none'}${oc ? ` (OpenCode ${opencodeVersion})` : ''}`,
122
122
  ...(providers.length ? [`Providers ${providers.join(', ')}`] : []),
123
123
  ].join('\n'), 'Summary');
124
- if (!f.yes && !(await ask(p.confirm({ message: 'Create the box?' })))) return p.cancel('Nothing created.');
124
+ if (!f.yes && !(await ask(p.confirm({ message: 'Create the container?' })))) return p.cancel('Nothing created.');
125
125
 
126
126
  let b;
127
127
  try {
128
- b = await createBox({ src, name, tools, git, token, remote: remoteUrl, opencodeVersion }, step);
128
+ b = await createContainer({ src, name, tools, git, token, remote: remoteUrl, opencodeVersion }, step);
129
129
  } catch (e) {
130
130
  p.log.error(e.message);
131
- p.outro(`Box creation failed. Fix the problem, then clean up with: agentcage remove ${name}`);
131
+ p.outro(`Container creation failed. Fix the problem, then clean up with: agentcage remove ${name}`);
132
132
  process.exit(1);
133
133
  }
134
134
  if (providers.length) await providerFlow(b, providers);
135
135
  if (oc) await registerFlow(b, !f.yes);
136
- if (ide !== 'none') { openIde(b, ide); p.log.success('Opening the IDE attached to the box'); }
136
+ if (ide !== 'none') { openIde(b, ide); p.log.success('Opening the IDE attached to the container'); }
137
137
  p.outro([
138
- `Box '${name}' is ready.`,
139
- oc && `OpenCode Desktop: select "agentcage: ${name}" and start a session. Only sessions on that server are isolated.`,
138
+ `Container '${name}' is ready.`,
139
+ oc && `OpenCode Desktop: select "ac-${name}" and start a session. Only sessions on that server are isolated.`,
140
140
  tools.includes('claude-code') && `Claude Code: agentcage shell ${name}, then run claude to log in.`,
141
141
  `Shell: agentcage shell ${name} IDE: agentcage open ${name}`,
142
142
  ].filter(Boolean).join('\n'));