agent86-web 0.2.0 → 0.4.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
@@ -38,23 +38,25 @@ agent86-web --root ~/code
38
38
 
39
39
  ## Options
40
40
 
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>` | any free port | The port to listen on |
45
- | `--host <addr>` | `127.0.0.1` | A loopback address: `127.0.0.1`, `::1`, or `localhost` |
46
- | `--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. |
47
- | `--agent-arg=<arg>` | — | An argument for agent86, placed before `acp`. Repeatable, e.g. `--agent-arg=--model --agent-arg=openrouter:<model>` |
48
- | `--max-agents <n>` | `8` | The most agent86 processes running at once |
49
- | `--idle-timeout <d>` | `15m` | Stop an agent86 that has no open tab and no running turn after this long (`90s`, `15m`, `1h`) |
50
- | `--no-open` | — | Print the link without opening the browser |
51
- | `--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`) |
52
53
 
53
54
  ## Things to know
54
55
 
55
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.
56
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).
57
- - **The approval mode new threads start in.** Choose it under _Settings & about_; it applies once, when a thread is first opened in that browser. 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.
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.
58
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.
59
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.
60
62
  - **Using it from another device.** agent86-web listens only on loopback. Forward the port over SSH:
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");
@@ -126,19 +155,31 @@ async function main() {
126
155
  process.once("SIGTERM", () => resolve("signal"));
127
156
  stopRequested = () => resolve("browser");
128
157
  });
129
- const bridge = await startBridge({
130
- roots,
131
- host: values.host,
132
- port,
133
- agent86: { command: values.agent86, version, args: values["agent-arg"] ?? [] },
134
- publicDir,
135
- devOrigin: values["dev-origin"],
136
- maxAgents,
137
- idleTimeoutMs,
138
- updateCheck: !values["no-update-check"] && !updateCheckDisabled() && !values["dev-origin"],
139
- onShutdownRequested: () => stopRequested(),
140
- log: (line) => process.stderr.write(`${line}\n`),
141
- });
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
+ }
142
183
  process.stdout.write(`agent86-web ${BRIDGE_VERSION} (agent86 ${version})\n` +
143
184
  `Workspaces: ${roots.join(", ")}\n` +
144
185
  `Open: ${bridge.url}\n` +
package/dist/policy.js CHANGED
@@ -19,6 +19,28 @@ export const FORCED_CLIENT_CAPABILITIES = {
19
19
  fs: { readTextFile: false, writeTextFile: false },
20
20
  terminal: false,
21
21
  };
22
+ /** agent86's state events (agent86 docs/ACP.md): an opt-in that only adds notifications. */
23
+ export const STATE_EXTENSION = "com.maetek.agent86/state";
24
+ /**
25
+ * The browser's capabilities as agent86 will see them: files and terminal forced off, plus the
26
+ * opt-ins that only change how agent86 reports (never what it can do), copied when present:
27
+ * `session.compaction` (ACP `compaction_update`) and agent86's state events. Anything else the
28
+ * browser claims is dropped.
29
+ */
30
+ export function clientCapabilities(claimed) {
31
+ const caps = { ...FORCED_CLIENT_CAPABILITIES };
32
+ if (!isObject(claimed))
33
+ return caps;
34
+ if (isObject(claimed.session) && isObject(claimed.session.compaction)) {
35
+ caps.session = { compaction: {} };
36
+ }
37
+ if (isObject(claimed._meta)) {
38
+ const state = claimed._meta[STATE_EXTENSION];
39
+ if (state === true || isObject(state))
40
+ caps._meta = { [STATE_EXTENSION]: true };
41
+ }
42
+ return caps;
43
+ }
22
44
  const INVALID_REQUEST = -32600;
23
45
  const METHOD_NOT_FOUND = -32601;
24
46
  const INVALID_PARAMS = -32602;
@@ -75,7 +97,10 @@ export function filterClientMessage(raw, ctx) {
75
97
  }
76
98
  switch (method) {
77
99
  case "initialize": {
78
- const next = { ...params, clientCapabilities: FORCED_CLIENT_CAPABILITIES };
100
+ const next = {
101
+ ...params,
102
+ clientCapabilities: clientCapabilities(params?.clientCapabilities),
103
+ };
79
104
  return { action: "forward", message: { ...message, params: next } };
80
105
  }
81
106
  case "session/new":