agent86-web 0.1.0 → 0.3.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.
package/README.md CHANGED
@@ -9,11 +9,12 @@ agent86-web runs a small server on your machine (loopback only) and opens a page
9
9
  - **Saved sessions**, including ones started at a terminal (and `agent86 --resume <id>` continues a browser session at a terminal).
10
10
  - **Several threads at once.**
11
11
  - **Model and approval-mode pickers**, `/` commands, and `@` file mentions.
12
+ - **Thread names** you choose (saved in agent86 with 1.0.17 or newer), a resizable sessions panel, and a **Quit** button.
12
13
 
13
14
  ## Requirements
14
15
 
15
16
  - Node.js 20.19 or newer
16
- - [agent86](https://github.com/Maetek-Technologies/agent86) 1.0.15 or newer on your `PATH`, with a model it can use:
17
+ - [agent86](https://github.com/Maetek-Technologies/agent86) 1.0.15 or newer on your `PATH` (1.0.17 or newer recommended: it keeps thread names you give in the browser and lists each workspace's own sessions), with a model it can use:
17
18
 
18
19
  ```sh
19
20
  npm install -g agent86
@@ -37,22 +38,26 @@ agent86-web --root ~/code
37
38
 
38
39
  ## Options
39
40
 
40
- | Option | Default | Meaning |
41
- | -------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------- |
42
- | `--root <dir>` | the current directory | A folder that threads may run in, or in folders under it. Repeat for more. |
43
- | `--port <n>` | any free port | The port to listen on |
44
- | `--host <addr>` | `127.0.0.1` | A loopback address: `127.0.0.1`, `::1`, or `localhost` |
45
- | `--agent86 <path>` | `agent86` on `PATH` | The agent86 to run. Pointing at the native binary instead of npm's launcher saves about 45 MB per thread. |
46
- | `--agent-arg=<arg>` | — | An argument for agent86, placed before `acp`. Repeatable, e.g. `--agent-arg=--model --agent-arg=openrouter:<model>` |
47
- | `--max-agents <n>` | `8` | The most agent86 processes running at once |
48
- | `--idle-timeout <d>` | `15m` | Stop an agent86 that has no open tab and no running turn after this long (`90s`, `15m`, `1h`) |
49
- | `--no-open` | — | Print the link without opening the browser |
50
- | `--no-update-check` | — | Don't check npm for newer agent86 or agent86-web releases (also `AGENT86_WEB_NO_UPDATE_CHECK=1`) |
41
+ | Option | Default | Meaning |
42
+ | -------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
43
+ | `--root <dir>` | the current directory | A folder that threads may run in, or in folders under it. Repeat for more. |
44
+ | `--port <n>` | the saved port, else any free port | The port to listen on. `0` means any free port. Also `AGENT86_WEB_PORT`. |
45
+ | `--save-port` | — | Remember `--port` for later starts (`--port 0 --save-port` forgets it) |
46
+ | `--host <addr>` | `127.0.0.1` | A loopback address: `127.0.0.1`, `::1`, or `localhost` |
47
+ | `--agent86 <path>` | `agent86` on `PATH` | The agent86 to run. Pointing at the native binary instead of npm's launcher saves about 45 MB per thread. |
48
+ | `--agent-arg=<arg>` | — | An argument for agent86, placed before `acp`. Repeatable, e.g. `--agent-arg=--model --agent-arg=openrouter:<model>` |
49
+ | `--max-agents <n>` | `8` | The most agent86 processes running at once |
50
+ | `--idle-timeout <d>` | `15m` | Stop an agent86 that has no open tab and no running turn after this long (`90s`, `15m`, `1h`) |
51
+ | `--no-open` | — | Print the link without opening the browser |
52
+ | `--no-update-check` | — | Don't check npm for newer agent86 or agent86-web releases (also `AGENT86_WEB_NO_UPDATE_CHECK=1`) |
51
53
 
52
54
  ## Things to know
53
55
 
54
56
  - **Workspaces.** A thread runs in one folder under a `--root`. Pick it with _Open a workspace…_. To work in another folder, open a new thread there.
55
- - **Project settings need trust.** agent86 ignores the riskier settings in a project's `.agent86/config.toml`, such as MCP servers, providers, and approvals, until you trust the file. When it does, the thread shows a banner. _Review and trust_ shows the whole file. agent86-web remembers your decision for that exact file in `~/.agent86-web/trusted-projects.json`, and asks again if the file changes. Revoke it under _About_.
57
+ - **Project settings need trust.** agent86 ignores the riskier settings in a project's `.agent86/config.toml`, such as MCP servers, providers, and approvals, until you trust the file. When it does, the thread shows a banner. _Review and trust_ shows the whole file. agent86-web remembers your decision for that exact file in `~/.agent86-web/trusted-projects.json`, and asks again if the file changes. Revoke it under _Settings & about_ (the agent86 version button in the top bar).
58
+ - **The approval mode new threads start in.** Choose it under _Settings & about_, or with _make default_ next to a thread's mode. agent86-web keeps it in `~/.agent86-web/settings.json`, so it holds in every browser and across restarts. Each thread keeps its own mode and model, even after a reload or a restart. To change agent86's own default everywhere, terminal included, set `approval = "auto"` (or `ask`, `deny`) under `[guardrails]` in `~/.agent86/config.toml`, or start agent86-web with `AGENT86_APPROVAL=auto` in its environment.
59
+ - **The same port every time.** `agent86-web --port 8686 --save-port` saves the port in `~/.agent86-web/settings.json`; later starts use it, and the browser keeps your open threads and prompt history across restarts. If the port is in use, agent86-web says so and stops. `--port` and `AGENT86_WEB_PORT` override it for one run.
60
+ - **Stopping.** Press Ctrl+C in the terminal, or use ⏻ (Quit) in the top bar. Either way, every agent86 it started stops; sessions are saved.
56
61
  - **Model setup and secrets stay at the terminal.** Add keys with `agent86 keys set <provider>` or `/config model`, and enter secrets with `/secret NAME` in `agent86`, choosing to remember them for the project. Browser threads then use them. The protocol agent86-web speaks does not allow asking for secrets in a form.
57
62
  - **Using it from another device.** agent86-web listens only on loopback. Forward the port over SSH:
58
63
  ```sh
package/dist/cli.js CHANGED
@@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url";
6
6
  import { parseArgs } from "node:util";
7
7
  import { Agent86Error, detectAgent86 } from "./agent86.js";
8
8
  import { parseDuration } from "./duration.js";
9
+ import { portProblem, resolvePort, SettingsStore } from "./settings.js";
9
10
  import { updateCheckDisabled } from "./updates.js";
10
11
  import { BRIDGE_VERSION, startBridge } from "./server.js";
11
12
  import { realpath } from "./workspaces.js";
@@ -15,7 +16,9 @@ Usage: agent86-web [options]
15
16
 
16
17
  Options:
17
18
  --root <dir> A directory threads may run in (repeatable; default: the current directory)
18
- --port <n> Port to listen on (default: any free port)
19
+ --port <n> Port to listen on (default: AGENT86_WEB_PORT, else the saved port,
20
+ else any free port; 0 means any free port)
21
+ --save-port Remember --port for every later start (--port 0 forgets it)
19
22
  --host <addr> Loopback address to bind: 127.0.0.1 (default), ::1, or localhost
20
23
  --agent86 <path> The agent86 command (default: agent86 on PATH)
21
24
  --agent-arg=<arg> An argument for agent86, placed before \`acp\` (repeatable),
@@ -53,6 +56,7 @@ async function main() {
53
56
  options: {
54
57
  root: { type: "string", multiple: true },
55
58
  port: { type: "string" },
59
+ "save-port": { type: "boolean", default: false },
56
60
  host: { type: "string", default: "127.0.0.1" },
57
61
  agent86: { type: "string", default: "agent86" },
58
62
  "agent-arg": { type: "string", multiple: true },
@@ -82,11 +86,36 @@ async function main() {
82
86
  process.stdout.write(`agent86-web ${BRIDGE_VERSION}\n`);
83
87
  return 0;
84
88
  }
85
- const port = values.port === undefined ? 0 : Number(values.port);
86
- if (!Number.isInteger(port) || port < 0 || port > 65535) {
87
- process.stderr.write(`agent86-web: --port must be a number from 0 to 65535\n`);
89
+ // The bridge's own state (settings, trusted projects); AGENT86_WEB_STATE_DIR moves it (tests).
90
+ const stateDir = process.env.AGENT86_WEB_STATE_DIR || undefined;
91
+ const settings = new SettingsStore(stateDir);
92
+ if (values["save-port"]) {
93
+ if (values.port === undefined) {
94
+ process.stderr.write("agent86-web: --save-port needs --port <n>\n");
95
+ return 2;
96
+ }
97
+ const chosen = resolvePort(values.port, undefined, undefined);
98
+ if ("error" in chosen) {
99
+ process.stderr.write(`agent86-web: ${chosen.error}\n`);
100
+ return 2;
101
+ }
102
+ try {
103
+ settings.update({ port: chosen.port === 0 ? null : chosen.port });
104
+ }
105
+ catch (error) {
106
+ process.stderr.write(`agent86-web: could not save the port in ${settings.file}: ${error.message}\n`);
107
+ return 1;
108
+ }
109
+ process.stdout.write(chosen.port === 0
110
+ ? "Forgot the saved port; agent86-web will use any free port.\n"
111
+ : `Saved port ${chosen.port} in ${settings.file}.\n`);
112
+ }
113
+ const chosen = resolvePort(values.port, process.env.AGENT86_WEB_PORT, settings.read().port);
114
+ if ("error" in chosen) {
115
+ process.stderr.write(`agent86-web: ${chosen.error}\n`);
88
116
  return 2;
89
117
  }
118
+ const { port, source } = chosen;
90
119
  const maxAgents = values["max-agents"] === undefined ? undefined : Number(values["max-agents"]);
91
120
  if (maxAgents !== undefined && (!Number.isInteger(maxAgents) || maxAgents < 1)) {
92
121
  process.stderr.write("agent86-web: --max-agents must be a whole number of at least 1\n");
@@ -120,29 +149,45 @@ async function main() {
120
149
  }
121
150
  const here = dirname(fileURLToPath(import.meta.url));
122
151
  const publicDir = values.static ?? join(here, "public");
123
- const bridge = await startBridge({
124
- roots,
125
- host: values.host,
126
- port,
127
- agent86: { command: values.agent86, version, args: values["agent-arg"] ?? [] },
128
- publicDir,
129
- devOrigin: values["dev-origin"],
130
- maxAgents,
131
- idleTimeoutMs,
132
- updateCheck: !values["no-update-check"] && !updateCheckDisabled() && !values["dev-origin"],
133
- log: (line) => process.stderr.write(`${line}\n`),
152
+ let stopRequested = () => undefined;
153
+ const stopped = new Promise((resolve) => {
154
+ process.once("SIGINT", () => resolve("signal"));
155
+ process.once("SIGTERM", () => resolve("signal"));
156
+ stopRequested = () => resolve("browser");
134
157
  });
158
+ let bridge;
159
+ try {
160
+ bridge = await startBridge({
161
+ roots,
162
+ host: values.host,
163
+ port,
164
+ agent86: { command: values.agent86, version, args: values["agent-arg"] ?? [] },
165
+ publicDir,
166
+ stateDir,
167
+ devOrigin: values["dev-origin"],
168
+ maxAgents,
169
+ idleTimeoutMs,
170
+ updateCheck: !values["no-update-check"] && !updateCheckDisabled() && !values["dev-origin"],
171
+ onShutdownRequested: () => stopRequested(),
172
+ log: (line) => process.stderr.write(`${line}\n`),
173
+ });
174
+ }
175
+ catch (error) {
176
+ const code = error.code;
177
+ if (code === "EADDRINUSE" || code === "EACCES") {
178
+ process.stderr.write(`agent86-web: ${portProblem(port, source, code, settings.file)}\n`);
179
+ return 1;
180
+ }
181
+ throw error;
182
+ }
135
183
  process.stdout.write(`agent86-web ${BRIDGE_VERSION} (agent86 ${version})\n` +
136
184
  `Workspaces: ${roots.join(", ")}\n` +
137
185
  `Open: ${bridge.url}\n` +
138
- `The link works once and expires in 5 minutes. Press Ctrl+C to stop.\n`);
186
+ `The link works once and expires in 5 minutes. Press Ctrl+C (or Quit in the page) to stop.\n`);
139
187
  if (!values["no-open"])
140
188
  openBrowser(bridge.url);
141
- await new Promise((resolve) => {
142
- const stop = () => resolve();
143
- process.once("SIGINT", stop);
144
- process.once("SIGTERM", stop);
145
- });
189
+ if ((await stopped) === "browser")
190
+ process.stdout.write("Stopped from the browser.\n");
146
191
  await bridge.close();
147
192
  return 0;
148
193
  }