@chipschat/acp 1.0.4 → 1.0.8

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
@@ -13,11 +13,11 @@ the Chips repo with `pnpm release:sdk`.
13
13
 
14
14
  ## From Chips's gallery
15
15
 
16
- The card's line is `chips connect claude-code '<link>'` or `chips connect codex '<link>'` (Chips ADR 0218). It downloads this bridge as the npm package
16
+ The card's line is `CHIPS_JOIN_LINK='<link>' chips connect claude-code` or `CHIPS_JOIN_LINK='<link>' chips connect codex` (Chips ADR 0218). It downloads this bridge as the npm package
17
17
  `@chipschat/acp`, the newest 1.x, checks it against the registry's checksum, and runs it on the Node
18
18
  that Chips carries, so the machine needs no Node or npm of its own. The bridge checks the agent's ACP adapter and its sign-in,
19
19
  joins, and keeps itself running from login. `chips disconnect claude-code` or `chips disconnect codex` stops it. Claude Code and Codex share this one package: their cards hand it `~/.chips-acp/claude-code.json` or `codex.json`, and the file's name picks the kind. On another computer,
20
- `curl -fsSL https://chipschat.ai/install | sh -s -- connect claude-code '<link>'` installs Chips there
20
+ `curl -fsSL https://chipschat.ai/install | CHIPS_JOIN_LINK='<link>' sh -s -- connect claude-code` installs Chips there
21
21
  first. The steps below run the bridge from this checkout instead, to work on it.
22
22
 
23
23
  ## Run it
@@ -31,7 +31,7 @@ CHIPS_JOIN_LINK='<a join link made in Chips>' npm run keep ~/.chips-acp/claude-c
31
31
  `npm run keep` joins, then keeps the bridge running from login ("Keep it running", below);
32
32
  `npm start` is the same in the terminal only.
33
33
 
34
- The link comes from Chips's gallery (Add an agent → Claude Code, or Codex), whose card gives this
34
+ The link comes from Chips's gallery (Agents → Connect a harness → Claude Code, or Codex), whose card gives this
35
35
  line with the link in it (`codex.json` for Codex) and starts the link with what it needs on:
36
36
  `agents`, `new_spaces`, `new_agents`, `forks` and `restarts`. `claude-code.json` and `codex.json`
37
37
  need not be there: without them the bridge runs Claude Code or Codex, in the mode that asks (see
@@ -147,7 +147,7 @@ minutes and loaded again with its memory. Fourteen runs, none failed, $0.35, all
147
147
  | Context gauge, cost | `usage_update` (`used`/`size`; `cost` in USD, the turn's share) |
148
148
  | The reply | `agent_message_chunk`s gathered into one message; `NO_REPLY` alone is the turn passed |
149
149
  | Files in the reply | each `MEDIA:<path>` line of the reply sent as an upload with its words, only from the agent's folder (`sendAnswer`); the post says why one could not go |
150
- | Approval card | `session/request_permission`; allowed always picks `allow_always`, no picks `reject_once`; Stop answers `cancelled`; the card hears how the call went |
150
+ | Approval card | `session/request_permission`; allowed always picks `allow_always`, except for a command, which picks `allow_once` since Chips remembers it by how each part starts (Chips ADR 0239); no picks `reject_once`; Stop answers `cancelled`; the card hears how the call went |
151
151
  | Question card | `elicitation/create` form of up to four choice or yes/no fields; anything else is declined |
152
152
  | Stop | `session/cancel` |
153
153
  | Steer | the next prompt of the same run, after `session/cancel` when it interrupts |
@@ -160,9 +160,9 @@ permissions, and each permission it asks for is an approval card.
160
160
 
161
161
  ### What Chips shows on an agent's page
162
162
 
163
- The bridge says `context` (Claude Code and Codex) and `context_windows` (every kind) in its hello,
164
- and sends each agent's copies when it starts and as they change. Chips draws them where the
165
- harness is granted `context_files` and `context_windows`.
163
+ The bridge says `context` and `models` (Claude Code and Codex) and `context_windows` (every kind)
164
+ in its hello, and sends each agent's copies when it starts and as they change. Chips draws them
165
+ where the harness is granted `context_files`, `models` and `context_windows`.
166
166
 
167
167
  | Chips | Claude Code | Codex | Another kind |
168
168
  |---|---|---|---|
@@ -172,6 +172,9 @@ harness is granted `context_files` and `context_windows`.
172
172
  | Context window | `usage_update` of the agent's session that said last; the window from the update that ends a turn (it carries the cost), as one before may be a default | `usage_update` | `usage_update` |
173
173
  | Compact now | `/compact` said to that session as a turn of its own, after any turn going there; its words go nowhere; from and to from its tool call's `rawOutput` | the same; to from the `usage_update` it sends as it finishes | where it lists `compact` among its commands |
174
174
  | Its limit | its own from `autoCompactWindow` in its settings (`modelSettings` per model), about 33,000 tokens short of it; a pick from Chips goes in each session's `_meta.claudeCode.options.settings`, never in a file; `CLAUDE_CODE_AUTO_COMPACT_WINDOW` beats both, and the limit can't be changed then | the bridge's: after a turn that ends at or past it, the bridge compacts that session; off unless picked | as Codex, where it has `compact` |
175
+ | Model | the models its adapter offers for a session (the `model` option), each with its levels (`effort`, without its `default`), by the adapter's own names (its `xhigh` is Extra high); Same as "Claude Code's default" is what a new session starts on: `model` in its settings, or its own `default` | the same, with `reasoning_effort`; the default from Codex's config, which may be a model its list leaves out, with no levels | none |
176
+ | Where it learns them | each time the bridge starts the agent, a session opened in the harness's folder and put on each model in turn, then closed, with nothing said to it; a model it won't be put on isn't offered | the same | |
177
+ | A pick | set on each of the agent's sessions with `session/set_config_option`, now and as each opens after, never in a file; kept with the agent, and a copy from Fork starts with its original's. Same as again puts each back on the default, and its level on Claude Code's `default`, which follows its settings | the same; a session Codex won't put back on a model its list leaves out is let go and loaded again before its next turn | |
175
178
 
176
179
  An edit is saved only if the file is still what the person read; otherwise it is refused as changed.
177
180
  The bridge's own Codex adapter runs with `project_doc_max_bytes` at 64 KiB in `CODEX_CONFIG`, laid
@@ -180,8 +183,8 @@ write (32 KiB unless set).
180
183
 
181
184
  ## Not built yet
182
185
 
183
- From the plan's Phase 4: agents over WebSocket (`goose serve`); `follows_rooms`; models and effort
184
- from `configOptions`; the bridge's own MCP server (reminders, ask a person) and heartbeats; sub-agents as lanes; free-text form fields; approval scopes limited to the
186
+ From the plan's Phase 4: agents over WebSocket (`goose serve`); `follows_rooms`; models for any
187
+ other kind; the bridge's own MCP server (reminders, ask a person) and heartbeats; sub-agents as lanes; free-text form fields; approval scopes limited to the
185
188
  agent's options (a wire change, Phase 6).
186
189
 
187
190
  ## Tests
@@ -194,9 +197,10 @@ A scripted ACP agent (`test/fake-agent.ts`), in process and as a child process,
194
197
  conformance kit's fake Chips, which checks every event against the protocol's schemas; and the kit's
195
198
  golden scenario with the +, Add and Fork, which
196
199
  `chips conformance custom --capabilities agents,new_spaces,new_agents,forks,restarts` runs live:
197
- Lives in Chips 5 of 6. Run as Claude Code with `context_files` and `context_windows` besides, the
198
- kit's settings checks pass: Managed from Chips 2 of 5. `test/settings.test.ts` plays the files and
199
- the windows of each kind, from a home of its own.
200
+ Lives in Chips 5 of 6. Run as Claude Code with `context_files`, `context_windows` and `models`
201
+ besides, the kit's settings checks pass: Managed from Chips 3 of 5. `test/settings.test.ts` plays the
202
+ files, the windows and the models of each kind, from a home of its own; its models are the ones
203
+ Claude Code's adapter 0.90.0 and Codex's 2.2.2 offered on 28 October 2026.
200
204
 
201
205
  ```bash
202
206
  npm run e2e
@@ -1,6 +1,6 @@
1
1
  # Third-party notices
2
2
 
3
- `dist/main.js` in @chipschat/acp 1.0.4 carries these packages, bundled in. Each one's
3
+ `dist/main.js` in @chipschat/acp 1.0.8 carries these packages, bundled in. Each one's
4
4
  licence follows.
5
5
 
6
6
  ## @chipschat/harness 0.0.0 (Apache-2.0)
package/dist/main.js CHANGED
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
  };
9
9
 
10
10
  // src/main.ts
11
- import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync8, writeFileSync as writeFileSync4 } from "node:fs";
11
+ import { existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync4 } from "node:fs";
12
12
  import { homedir as homedir7 } from "node:os";
13
13
  import { basename as basename5, dirname as dirname5, join as join10, resolve as resolve4 } from "node:path";
14
14
 
@@ -19943,8 +19943,9 @@ var policyRule = external_exports.object({
19943
19943
  external: external_exports.boolean().optional(),
19944
19944
  irreversible: external_exports.boolean().optional(),
19945
19945
  money_usd_over: external_exports.number().nonnegative().optional(),
19946
- risk: external_exports.array(riskClass).max(8).optional()
19947
- }).optional().describe("Extra conditions on the action's flags."),
19946
+ risk: external_exports.array(riskClass).max(8).optional(),
19947
+ starts_with: external_exports.array(external_exports.string().min(1).max(400)).min(1).max(8).optional().describe("For an action that carries a command (ADR 0239): the words a part of it starts with. A command goes ahead on such rules only when every part starts with one that allows it.")
19948
+ }).optional().describe("Extra conditions on the action's flags, and for a command, how its parts start."),
19948
19949
  decision: external_exports.enum(["allow", "ask", "deny"]).describe("What to do when the rule matches."),
19949
19950
  approvers: external_exports.array(approverRef).max(16).optional().describe("Who may answer, when the decision is `ask`."),
19950
19951
  reason: external_exports.string().max(400).optional().describe("Shown to the harness, and recorded in the audit log."),
@@ -20462,9 +20463,17 @@ var roomIdle = external_exports.object({
20462
20463
  var roomNote = external_exports.object({
20463
20464
  members: external_exports.array(roomMember).max(500).describe("The room's people, then its agents, each by name, anybody removed left out."),
20464
20465
  notes: external_exports.record(external_exports.string().max(120), external_exports.string().max(64e3)).describe("The note for each who takes the turn (`for`), by their id: who is here, with handles, and that only those @-mentioned act. A harness puts it at the top of the turn."),
20466
+ rules: external_exports.record(external_exports.string().max(120), external_exports.string().max(4e3)).optional().describe("How the space works, for each who takes the turn, by their id: the words its note ends with (ADR 0250), that everyone here reads what it writes and, beside other agents, what an @ does and when to answer NO_REPLY. They stay the same while the space's agents do, so a harness whose session keeps its earlier turns may say them once, and the note without them after."),
20465
20467
  working: external_exports.array(roomWork).max(500).optional().describe("The room's agents with a turn going as Chips sends this one (ADR 0104), the takers' own included. A turn nothing has been heard from for ten minutes is not counted."),
20466
20468
  idle: external_exports.array(roomIdle).max(500).optional().describe("The room's other agents that have had a turn here: how long since the last one ended (ADR 0104).")
20467
20469
  });
20470
+ function noteWithoutRules(room, taker) {
20471
+ const note = room?.notes[taker];
20472
+ const rules = room?.rules?.[taker];
20473
+ if (note === void 0 || rules === void 0 || !note.endsWith(rules))
20474
+ return note;
20475
+ return note.slice(0, note.length - rules.length).trimEnd();
20476
+ }
20468
20477
  var MONTHS = [
20469
20478
  "January",
20470
20479
  "February",
@@ -20484,8 +20493,8 @@ var MONTHS = [
20484
20493
  var CONTEXT_CEILING = { lines: 200, chars: 32e3 };
20485
20494
  var CONTEXT_HEADING = "Said in this space since you last spoke:";
20486
20495
  var contextBudget = external_exports.object({
20487
- lines: external_exports.int().nonnegative().optional().describe("The most lines to be handed, 20 when absent. Chips hands over 200 at most, and none when this is 0."),
20488
- chars: external_exports.int().nonnegative().optional().describe("The most characters those lines may run to, as `Name: words` one per line, 4,000 when absent. Chips hands over 32,000 at most.")
20496
+ lines: external_exports.int().nonnegative().optional().describe("The most lines to be handed, 40 when absent. Chips hands over 200 at most, and none when this is 0."),
20497
+ chars: external_exports.int().nonnegative().optional().describe("The most characters those lines may run to, as `Name: words` one per line, 16,000 when absent. Chips hands over 32,000 at most.")
20489
20498
  }).describe("How much of the room a harness is handed with a message for it (ADR 0088). Its own to say: a budget promises nothing to anybody else.");
20490
20499
  var contextLine = external_exports.object({
20491
20500
  seq: external_exports.int().positive().describe("Where in the log it happened."),
@@ -20865,7 +20874,7 @@ var messageNew = defineEvent({
20865
20874
  summary: "Someone said something, with any attachments as signed URLs the harness can fetch.",
20866
20875
  requiresRun: false,
20867
20876
  payload: deliveredMessage.extend({
20868
- context: roomContext.optional().describe("What was said in the room since this harness last spoke there, or since it joined when it has not, up to this message and without it (ADR 0088). From when the turn that said its last words began, so what was said while it worked is here, and its own words are not (ADR 0105). Worked out from the log, so a replay hands over the same lines. As many as the budget the harness gave in its `hello`: 20 lines and 4,000 characters when it gave none, and none when it asked for 0. When older lines were left out, the taker's room note says so."),
20877
+ context: roomContext.optional().describe("What was said in the room since this harness last spoke there, or since it joined when it has not, up to this message and without it (ADR 0088). From when the turn that said its last words began, so what was said while it worked is here, and its own words are not (ADR 0105). Worked out from the log, so a replay hands over the same lines. As many as the budget the harness gave in its `hello`: 40 lines and 16,000 characters when it gave none, and none when it asked for 0. When older lines were left out, the taker's room note says so."),
20869
20878
  room: roomNote.optional().describe("Who is in the room, with the handle that reaches each, and a note for each who takes the turn saying so and what an @ does (ADR 0092). A harness puts `notes[<taker>]` at the top of that turn. Absent on a message in no room."),
20870
20879
  exchange: deliveredExchange.optional().describe("How the agents' talk in the room stands, once it is worth a word (ADR 0097): from eight messages between agents since a person last acted or an agent last made something new. A harness puts `note` at the top of the turn, as Chips's, ahead of the room's note. Absent below that, and worked out from the log, so a replay hands over the same facts."),
20871
20880
  handed: external_exports.literal(true).optional().describe("Chips held this message when it was said and hands it over now a person has acted (ADR 0097): the newest of an agent's held messages, once; or, with `lead`, hands it to the room's lead. Its seq and id are the hand-over's, its `message_id` the message's own."),
@@ -20915,6 +20924,7 @@ var approvalResolved = defineEvent({
20915
20924
  approval_id: id("approval"),
20916
20925
  decision: external_exports.enum(["approved", "edited", "denied", "expired"]).describe("`expired` means nobody answered and the fallback applied."),
20917
20926
  scope: external_exports.enum(["once", "session", "always"]).default("once").describe("How far the answer reaches. `always` becomes a policy rule."),
20927
+ everywhere: external_exports.boolean().optional().describe("With `always`: the rule is the harness's in every space, not only this one (ADR 0239). An owner or an admin only."),
20918
20928
  updated_input: external_exports.unknown().optional().describe("The edited action input, when the decision is `edited`."),
20919
20929
  reason: external_exports.string().max(4e3).optional().describe("Why. The harness gets to read this."),
20920
20930
  resolved_by: external_exports.string().min(1).max(120).describe("The participant who answered, or `system` on expiry \u2014 a harness when it settles its own ask, answered in its own tools. Filled in by Chips from the credential that sent it; a value the sender writes is replaced."),
@@ -21179,6 +21189,10 @@ function namesInWords(names) {
21179
21189
  return `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
21180
21190
  }
21181
21191
  function renderProjectNote(facts, options) {
21192
+ return `${renderProjectFacts(facts)}
21193
+ ${renderProjectAsks(facts, options)}`;
21194
+ }
21195
+ function renderProjectFacts(facts) {
21182
21196
  const files = `${facts.files} file${facts.files === 1 ? "" : "s"}`;
21183
21197
  const lines2 = [
21184
21198
  `The space's project is a git repository. Your copy is ${facts.folder} (${files}), ${facts.trouble === void 0 ? "brought up to date just now" : "not brought up to date"}.`
@@ -21196,9 +21210,9 @@ function renderProjectNote(facts, options) {
21196
21210
  for (const key of facts.keys) {
21197
21211
  lines2.push(`${key.path} holds what looks like ${key.what}, so your last change wasn't sent: take it out and read it from outside the project.`);
21198
21212
  }
21199
- return [...lines2, ...asks(facts, options)].join("\n");
21213
+ return lines2.join("\n");
21200
21214
  }
21201
- function asks(facts, options) {
21215
+ function renderProjectAsks(facts, options) {
21202
21216
  const lines2 = [
21203
21217
  "Work on the project in that folder and leave git to Chips: when your turn ends, what you changed is committed under your name and sent to everyone here. Keep scratch work outside it.",
21204
21218
  // Sent with the answer too, a project's file became a room file of its own, with versions of
@@ -21219,7 +21233,7 @@ function asks(facts, options) {
21219
21233
  if (facts.pages === true) {
21220
21234
  lines2.push("A page opens in Chips as one document: name every file it needs in its tags and imports (<link>, <script src>, <img src>, import), since it can't fetch files while it runs.");
21221
21235
  }
21222
- return lines2;
21236
+ return lines2.join("\n");
21223
21237
  }
21224
21238
 
21225
21239
  // node_modules/@chipschat/protocol/dist/src/events/harness-to-chips.js
@@ -21871,7 +21885,7 @@ var membershipRemoved = defineEvent({
21871
21885
  payload: external_exports.object({
21872
21886
  participant_id: external_exports.string().min(1).max(120).describe("Who left."),
21873
21887
  removed_by: external_exports.string().min(1).max(120).optional().describe("Who removed them, if not themselves."),
21874
- reason: external_exports.enum([...RELEASE_REASONS, "person_removed"]).optional().describe("For an agent (ADR 0087): why it left, as `agent.released` says. For a person, `person_removed`: they were removed from the workspace (ADR 0160). Written by Chips; absent, a person took them out or they left."),
21888
+ reason: external_exports.enum([...RELEASE_REASONS, "person_removed", "person_left"]).optional().describe("For an agent (ADR 0087): why it left, as `agent.released` says. For a person, `person_removed`: they were removed from the workspace (ADR 0160); `person_left`: they deleted their account and left it (ADR 0243). Written by Chips; absent, a person took them out or they left the room."),
21875
21889
  moved_to: id("space").optional().describe("For an agent moved away: the room it went to, so this room can say so.")
21876
21890
  })
21877
21891
  });
@@ -22180,14 +22194,14 @@ var personRemoved = defineEvent({
22180
22194
  type: "person.removed",
22181
22195
  direction: "workspace",
22182
22196
  sender: "chips",
22183
- summary: "A person was removed from the workspace: signed out everywhere, out of every room, and the harnesses they owned handed to whoever removed them. What they said stays, under their name.",
22197
+ summary: "A person was removed from the workspace, or deleted their account: signed out everywhere, out of every room, and the harnesses they owned handed on. What they said stays, under their name.",
22184
22198
  requiresRun: false,
22185
22199
  payload: external_exports.object({
22186
22200
  participant_id: id("person").describe("Who was removed."),
22187
22201
  display_name: external_exports.string().min(1).max(120).describe("What they were called when they were removed, so the audit needs no lookup."),
22188
- removed_by: id("person").describe("The owner or admin who removed them."),
22202
+ removed_by: id("person").describe("The owner or admin who removed them, or they themselves when they deleted their account (ADR 0243)."),
22189
22203
  spaces: external_exports.array(id("space")).max(1e3).optional().describe("The rooms they were taken out of, each with its own `membership.removed`."),
22190
- harnesses: external_exports.array(id("harness")).max(1e3).optional().describe("The harnesses they owned, handed to `removed_by` by `harness.transferred`.")
22204
+ harnesses: external_exports.array(id("harness")).max(1e3).optional().describe("The harnesses they owned, each handed on by `harness.transferred`: to `removed_by`, or, for an account deleted, to an owner.")
22191
22205
  })
22192
22206
  });
22193
22207
  var joinWho = {
@@ -22533,7 +22547,7 @@ var clientHelloFrame = external_exports.object({
22533
22547
  })).max(64).optional().describe("Not read by Chips: a connection is its token's, and the server's `hello` names the token's harness and its agents (ADR 0087). Absent for a person's client."),
22534
22548
  since: external_exports.int().nonnegative().optional().describe("Not read by Chips: a stream resumes from `subscribe`'s `since`."),
22535
22549
  accepts: external_exports.array(external_exports.string().min(1).max(40)).max(32).optional().describe("Server frames beyond the base set this client understands, by the names in `SERVER_EXTENSIONS`. A name the server does not know is ignored rather than refused, so a client may name a frame a newer server sends and still be answered by an older one (ADR 0211, Phase 3). A client that says `events` is sent its replay in pages rather than one frame per event; one that says `presence` is sent an agent's state as it changes (ADR 0083); a harness's socket that says `restart` is sent `restart` when a person asks it to restart (ADR 0094); an owner's or admin's that says `join` is sent each join request as it changes (ADR 0122); a harness's that says `context` is sent `context.edit` when a person changes one of its context files (ADR 0134); a harness's that says `models` is sent `model.change` when a person changes an agent's model or effort (ADR 0140); a harness's that says `heartbeats` is sent `heartbeat.change` when a person switches an agent's heartbeat or changes how often it beats (ADR 0143); a harness's that says `context_windows` is sent `context_window.compact` and `context_window.change` when a person asks an agent to compact now or changes the limit it compacts itself at (ADR 0146); a person's that says `folders` is sent `folder.open` when they ask, from another of their devices, for a room's folder to be opened in Finder (ADR 0225), and `folder.run` when they ask for its project to be run or stopped there (ADR 0226); a person's that says `folder_runs` is sent `folder.run_state` when their Mac says how a run of theirs stands (ADR 0226); one that says nothing is sent what it was always sent, since an unknown frame is dropped in silence."),
22536
- context: contextBudget.optional().describe("How much of a room a harness is handed with each message for it (ADR 0088): 20 lines and 4,000 characters when absent, 200 and 32,000 at most. For this connection. A person's client is handed none.")
22550
+ context: contextBudget.optional().describe("How much of a room a harness is handed with each message for it (ADR 0088): 40 lines and 16,000 characters when absent, 200 and 32,000 at most. For this connection. A person's client is handed none.")
22537
22551
  }).describe("The first frame a client sends.");
22538
22552
  var subscribeFrame = external_exports.object({
22539
22553
  frame: external_exports.literal("subscribe"),
@@ -25095,8 +25109,19 @@ async function redeem(url2, secret, options, send, machine) {
25095
25109
  throw await refused(answered);
25096
25110
  return await answered.json();
25097
25111
  }
25112
+ function reaching(send, url2) {
25113
+ return async (input2, init) => {
25114
+ try {
25115
+ return await send(input2, init);
25116
+ } catch (error62) {
25117
+ if (error62 instanceof Error && error62.name === "AbortError")
25118
+ throw error62;
25119
+ throw new JoinError("unreachable", `Can't reach Chips at ${url2} from this computer. It has to be on the same network as Chips, on its tailnet, or Chips has to be at an address this computer can reach.`);
25120
+ }
25121
+ };
25122
+ }
25098
25123
  function askOrRedeem(server, options) {
25099
- const send = options.fetch ?? fetch;
25124
+ const send = reaching(options.fetch ?? fetch, server.url);
25100
25125
  const machine = options.machine ?? hostname3();
25101
25126
  return server.secret === void 0 ? ask(server.url, options, send, machine) : redeem(server.url, server.secret, options, send, machine);
25102
25127
  }
@@ -25256,14 +25281,31 @@ async function sendAnswer(answer, options) {
25256
25281
  }
25257
25282
 
25258
25283
  // node_modules/@chipschat/harness/dist/prompt.js
25284
+ function takerOf(message, options) {
25285
+ return options.taker ?? (message.for?.length === 1 ? message.for[0] : void 0);
25286
+ }
25287
+ function othersBeside(message, taker) {
25288
+ return (message.room?.members ?? []).some((member) => member.kind === "agent" && member.participant_id !== taker);
25289
+ }
25290
+ function rulesFor(message, options = {}) {
25291
+ const taker = takerOf(message, options);
25292
+ const { project } = options;
25293
+ const rules = message.room?.rules ?? {};
25294
+ return [
25295
+ taker === void 0 ? void 0 : rules[taker],
25296
+ project === void 0 ? void 0 : renderProjectAsks(project, { othersInRoom: othersBeside(message, taker) }),
25297
+ options.sendsFiles === true ? sendingFiles({ project: project !== void 0 }) : void 0
25298
+ ].filter((part) => part !== void 0 && part !== "").join("\n\n");
25299
+ }
25259
25300
  function promptFor(message, options = {}) {
25260
- const taker = options.taker ?? (message.for?.length === 1 ? message.for[0] : void 0);
25301
+ const taker = takerOf(message, options);
25302
+ const held = options.rulesHeld === true;
25261
25303
  const notes = message.room?.notes ?? {};
25262
- const note = taker === void 0 ? void 0 : notes[taker];
25304
+ const note = taker === void 0 ? void 0 : held ? noteWithoutRules(message.room, taker) : notes[taker];
25263
25305
  const who = options.sayWho === false ? "" : `${withRole(message.from.display_name, message.from)}: `;
25264
25306
  const files = (message.attachments ?? []).map(renderAttachment);
25265
25307
  const words4 = [`${who}${message.text}`, ...files].join("\n");
25266
- const sending = options.sendsFiles === true ? sendingFiles({ project: options.project !== void 0 }) : void 0;
25308
+ const sending = options.sendsFiles === true && !held ? sendingFiles({ project: options.project !== void 0 }) : void 0;
25267
25309
  const replying = renderReplyingTo(message.replying_to, {
25268
25310
  sender: {
25269
25311
  id: message.from.participant_id,
@@ -25275,8 +25317,7 @@ function promptFor(message, options = {}) {
25275
25317
  at: message.ts,
25276
25318
  zone: options.zone
25277
25319
  });
25278
- const others = (message.room?.members ?? []).some((member) => member.kind === "agent" && member.participant_id !== taker);
25279
- const project = options.project === void 0 ? void 0 : renderProjectNote(options.project, { othersInRoom: others });
25320
+ const project = options.project === void 0 ? void 0 : held ? renderProjectFacts(options.project) : renderProjectNote(options.project, { othersInRoom: othersBeside(message, taker) });
25280
25321
  return [
25281
25322
  message.exchange?.note,
25282
25323
  note,
@@ -25288,6 +25329,24 @@ function promptFor(message, options = {}) {
25288
25329
  ].filter((part) => part !== void 0 && part !== "").join("\n\n");
25289
25330
  }
25290
25331
 
25332
+ // node_modules/@chipschat/harness/dist/rules.js
25333
+ var SessionRules = class {
25334
+ held = /* @__PURE__ */ new Map();
25335
+ /** Whether `session` holds these rules: told them word for word, or there are none to hold. */
25336
+ holds(session, rules) {
25337
+ return rules === "" || this.held.get(session) === rules;
25338
+ }
25339
+ /** That `session` was told these rules: its turn that said them was given to it. */
25340
+ told(session, rules) {
25341
+ if (rules !== "")
25342
+ this.held.set(session, rules);
25343
+ }
25344
+ /** That `session` no longer holds what it was told: it compacted, or it is gone. */
25345
+ forget(session) {
25346
+ this.held.delete(session);
25347
+ }
25348
+ };
25349
+
25291
25350
  // node_modules/@chipschat/harness/dist/service.js
25292
25351
  import { execFileSync as execFileSync2 } from "node:child_process";
25293
25352
  import { accessSync, chmodSync as chmodSync2, constants, existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
@@ -25463,7 +25522,10 @@ function nodeOnPath(env2 = process.env) {
25463
25522
  }
25464
25523
  var pause = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
25465
25524
  var LOAD_TRIES = 40;
25466
- var runOf = (options) => options.run ?? ((command) => void execFileSync2(command[0], command.slice(1), { stdio: "ignore" }));
25525
+ var runOf = (options) => options.run ?? ((command) => execFileSync2(command[0], command.slice(1), {
25526
+ encoding: "utf8",
25527
+ stdio: ["ignore", "pipe", "ignore"]
25528
+ }));
25467
25529
  var ours = (path) => !existsSync3(path) || readFileSync3(path, "utf8").includes(MARK);
25468
25530
  function runOne(command, run2, retryMs) {
25469
25531
  const tries = command[0] === "launchctl" && command[1] === "bootstrap" ? LOAD_TRIES : 1;
@@ -25486,6 +25548,24 @@ function runAll(commands, options) {
25486
25548
  runOne(command, run2, options.retryMs ?? 250);
25487
25549
  }
25488
25550
  var uidOf = (options) => options.uid ?? process.getuid?.() ?? 0;
25551
+ function lingers(options) {
25552
+ const run2 = runOf(options);
25553
+ const uid = String(uidOf(options));
25554
+ try {
25555
+ const on = run2(["loginctl", "show-user", uid, "--property=Linger", "--value"]);
25556
+ if (typeof on === "string" && on.trim() === "yes")
25557
+ return true;
25558
+ } catch {
25559
+ }
25560
+ try {
25561
+ run2(["loginctl", "enable-linger", uid]);
25562
+ return true;
25563
+ } catch {
25564
+ return false;
25565
+ }
25566
+ }
25567
+ var sayOf = (options) => options.say ?? ((line) => void process.stderr.write(`${line}
25568
+ `));
25489
25569
  function keepRunning(spec, options = {}) {
25490
25570
  if (machineOf(options.machine).env["CHIPS_KEEP"] === "off")
25491
25571
  return { state: "off" };
@@ -25500,6 +25580,9 @@ function keepRunning(spec, options = {}) {
25500
25580
  writeFileSync2(file3.path, file3.contents, { mode: 384 });
25501
25581
  chmodSync2(file3.path, 384);
25502
25582
  runAll(startCommands(file3.kind, spec.label, file3.path, uidOf(options)), options);
25583
+ if (file3.kind === "systemd" && !lingers(options)) {
25584
+ sayOf(options)("It stops when you log out. To keep it running on a machine nobody logs in to, run this once: sudo loginctl enable-linger $USER");
25585
+ }
25503
25586
  return { state: "kept", path: file3.path, logFile: file3.logFile };
25504
25587
  }
25505
25588
  function stopKeeping(label2, options = {}) {
@@ -25642,11 +25725,14 @@ var AcpClient = class {
25642
25725
  const answer = await this.call("session/load", { sessionId, cwd, mcpServers, ...metaOf(meta3) });
25643
25726
  return { configOptions: configOptionsOf(answer ?? {}) };
25644
25727
  }
25645
- /** A copy of a session, remembering everything it does, working in `cwd`. Answers with the copy's id. */
25728
+ /**
25729
+ * A copy of a session, remembering everything it does, working in `cwd`. Answers with the copy's
25730
+ * id and anything it said the copy can be set to.
25731
+ */
25646
25732
  async forkSession(sessionId, cwd, mcpServers = [], meta3) {
25647
25733
  const answer = await this.call("session/fork", { sessionId, cwd, mcpServers, ...metaOf(meta3) });
25648
25734
  if (typeof answer["sessionId"] !== "string") throw new AcpError("the agent copied the session and named no copy", -32e3);
25649
- return answer["sessionId"];
25735
+ return { sessionId: answer["sessionId"], configOptions: configOptionsOf(answer) };
25650
25736
  }
25651
25737
  /** Let a session go: the agent keeps it, and `session/load` brings it back. */
25652
25738
  async closeSession(sessionId) {
@@ -25755,10 +25841,8 @@ function configOptionsOf(answer) {
25755
25841
  name: typeof option["name"] === "string" ? option["name"] : option["id"],
25756
25842
  ...typeof option["category"] === "string" ? { category: option["category"] } : {},
25757
25843
  currentValue: String(option["currentValue"] ?? ""),
25758
- options: option["options"].map((value) => ({
25759
- value: String(value["value"]),
25760
- name: String(value["name"] ?? value["value"])
25761
- }))
25844
+ // A select's values, or its groups' (`{ group, name, options }`), in order.
25845
+ options: option["options"].flatMap((value) => Array.isArray(value["options"]) ? value["options"] : [value]).filter((value) => typeof value["value"] === "string").map((value) => ({ value: String(value["value"]), name: String(value["name"] ?? value["value"]) }))
25762
25846
  }
25763
25847
  ];
25764
25848
  });
@@ -26228,6 +26312,98 @@ function signedOutStop(kind2) {
26228
26312
  };
26229
26313
  }
26230
26314
 
26315
+ // src/version.ts
26316
+ import { readFileSync as readFileSync7 } from "node:fs";
26317
+ var VERSION = JSON.parse(readFileSync7(new URL("../package.json", import.meta.url), "utf8")).version;
26318
+
26319
+ // src/models.ts
26320
+ var SETTINGS_LEVEL = "default";
26321
+ var LEVEL_WORDS = { xhigh: "Extra high" };
26322
+ function modelOption(options) {
26323
+ return options.find((option) => option.category === "model");
26324
+ }
26325
+ function effortOption(options) {
26326
+ return options.find((option) => option.category === "thought_level");
26327
+ }
26328
+ function offers(option, value) {
26329
+ return option?.options.some((each) => each.value === value) === true;
26330
+ }
26331
+ function levelsOf(option) {
26332
+ const levels = (option?.options ?? []).filter((each) => each.value !== SETTINGS_LEVEL);
26333
+ return levels.slice(-EFFORT_LEVELS_MAX).map((each) => ({
26334
+ id: each.value,
26335
+ label: (LEVEL_WORDS[each.value] ?? (each.name.trim() || each.value)).slice(0, 40)
26336
+ }));
26337
+ }
26338
+ function levelOf(option) {
26339
+ const at = option?.currentValue;
26340
+ return at === void 0 || at === "" || at === SETTINGS_LEVEL ? void 0 : at;
26341
+ }
26342
+ function pickOf(options) {
26343
+ const model = modelOption(options)?.currentValue;
26344
+ if (model === void 0 || model === "") return void 0;
26345
+ const effort = levelOf(effortOption(options));
26346
+ return { model, ...effort === void 0 ? {} : { effort } };
26347
+ }
26348
+ async function lookAt(options, set2) {
26349
+ const model = modelOption(options);
26350
+ const fallback = pickOf(options);
26351
+ if (model === void 0 || fallback === void 0) return { refused: [] };
26352
+ const listed = model.options.some((each) => each.value === fallback.model) ? model.options : [{ value: fallback.model, name: fallback.model }, ...model.options];
26353
+ let others = MODEL_CHOICES_MAX - 1;
26354
+ const offered = listed.filter((each) => each.value === fallback.model || others-- > 0);
26355
+ const choices = [];
26356
+ const refused3 = [];
26357
+ for (const each of offered) {
26358
+ let levels = levelsOf(effortOption(options));
26359
+ if (each.value !== fallback.model) {
26360
+ try {
26361
+ const now = await set2(model.id, each.value);
26362
+ if (modelOption(now)?.currentValue !== each.value) throw new Error("it stayed where it was");
26363
+ levels = levelsOf(effortOption(now));
26364
+ } catch (error62) {
26365
+ refused3.push({ model: each.value, why: error62 instanceof Error ? error62.message : String(error62) });
26366
+ continue;
26367
+ }
26368
+ }
26369
+ choices.push({ id: each.value, label: (each.name.trim() || each.value).slice(0, 80), efforts: levels });
26370
+ }
26371
+ return { catalog: { choices, default: fallback, asOf: (/* @__PURE__ */ new Date()).toISOString() }, refused: refused3 };
26372
+ }
26373
+ function choiceOf(catalog, model) {
26374
+ return catalog.choices.find((choice) => choice.id === model);
26375
+ }
26376
+ function pickIn(catalog, pick2) {
26377
+ const choice = pick2 === void 0 ? void 0 : choiceOf(catalog, pick2.model);
26378
+ if (pick2 === void 0 || choice === void 0) return void 0;
26379
+ const effort = choice.efforts.some((level) => level.id === pick2.effort) ? pick2.effort : void 0;
26380
+ return { model: pick2.model, ...effort === void 0 ? {} : { effort } };
26381
+ }
26382
+ function pickFrom(catalog, change) {
26383
+ if (change.model === null) return null;
26384
+ const choice = choiceOf(catalog, change.model);
26385
+ if (choice === void 0) return void 0;
26386
+ if (change.effort === null) return { model: change.model };
26387
+ return choice.efforts.some((level) => level.id === change.effort) ? { model: change.model, effort: change.effort } : void 0;
26388
+ }
26389
+ function modelCopy(catalog, pick2, harness) {
26390
+ const own2 = pickIn(catalog, pick2);
26391
+ const fallback = pickIn(catalog, catalog.default) ?? catalog.default;
26392
+ const runs = own2 ?? fallback;
26393
+ return {
26394
+ model: runs.model,
26395
+ ...runs.effort === void 0 ? {} : { effort: runs.effort },
26396
+ own: own2 !== void 0,
26397
+ default: {
26398
+ label: `${harness}'s default`.slice(0, 80),
26399
+ model: fallback.model,
26400
+ ...fallback.effort === void 0 ? {} : { effort: fallback.effort }
26401
+ },
26402
+ choices: [...catalog.choices],
26403
+ editable: true
26404
+ };
26405
+ }
26406
+
26231
26407
  // src/windows.ts
26232
26408
  var LIMITS = [50, 60, 70, 80, 90];
26233
26409
  var HEADROOM = 33e3;
@@ -26321,7 +26497,6 @@ function compactionFacts(update) {
26321
26497
  }
26322
26498
 
26323
26499
  // src/bridge.ts
26324
- var VERSION = "1.0.0";
26325
26500
  var QUIET_MS = 1500;
26326
26501
  var WAIT_FOR_AGENT_MS = 15e3;
26327
26502
  var MOST_RESPAWN_MS = 6e4;
@@ -26365,6 +26540,8 @@ var Bridge = class {
26365
26540
  offersCompact = false;
26366
26541
  /** Each session's last `used`, for where a compaction began. */
26367
26542
  sessionUsed = /* @__PURE__ */ new Map();
26543
+ /** The room's rules each session holds (Chips ADR 0250): said once, and again after it compacts. */
26544
+ rules = new SessionRules();
26368
26545
  compactions = /* @__PURE__ */ new Map();
26369
26546
  /** The bridge's own `/compact` turns, by session. */
26370
26547
  compactRuns = /* @__PURE__ */ new Map();
@@ -26372,6 +26549,8 @@ var Bridge = class {
26372
26549
  compacting = /* @__PURE__ */ new Map();
26373
26550
  /** A window copy to send in a moment, by agent key: readings come in bursts. */
26374
26551
  windowTimers = /* @__PURE__ */ new Map();
26552
+ /** Each live session's options as the agent last said them: its model and effort among them. */
26553
+ sessionOptions = /* @__PURE__ */ new Map();
26375
26554
  /** Hear what Chips asks, learn the agents Chips has, run the agent, and close idle sessions. */
26376
26555
  async start() {
26377
26556
  const { chips: chips2 } = this.options;
@@ -26388,6 +26567,7 @@ var Bridge = class {
26388
26567
  this.knew();
26389
26568
  await this.sendContexts();
26390
26569
  for (const record2 of this.records()) await this.sendWindow(record2);
26570
+ await this.sendModels();
26391
26571
  await this.run();
26392
26572
  const idleMs = this.options.idleMs ?? IDLE_MS;
26393
26573
  this.sweeper = setInterval(() => void this.sweep(idleMs), Math.max(10, Math.min(6e4, idleMs / 2)));
@@ -26447,13 +26627,14 @@ var Bridge = class {
26447
26627
  agentId: agent.agentId,
26448
26628
  name: agent.name,
26449
26629
  folder: original?.folder ?? await this.folderFor(agent.name),
26450
- ...forkedFrom === void 0 ? {} : { forkedFrom }
26630
+ ...forkedFrom === void 0 ? {} : { forkedFrom },
26631
+ ...original?.model === void 0 ? {} : { model: original.model }
26451
26632
  };
26452
26633
  changed = true;
26453
26634
  }
26454
26635
  if (changed) {
26455
26636
  this.save();
26456
- this.contextsChanged();
26637
+ this.agentsChanged();
26457
26638
  }
26458
26639
  });
26459
26640
  if (!forget) return;
@@ -26472,7 +26653,8 @@ var Bridge = class {
26472
26653
  name,
26473
26654
  folder: more.folder ?? await this.folderFor(name),
26474
26655
  answers: more.answers,
26475
- ...more.forkedFrom === void 0 ? {} : { forkedFrom: more.forkedFrom }
26656
+ ...more.forkedFrom === void 0 ? {} : { forkedFrom: more.forkedFrom },
26657
+ ...more.model === void 0 ? {} : { model: more.model }
26476
26658
  };
26477
26659
  this.options.state.agents[record2.key] = record2;
26478
26660
  this.save();
@@ -26511,7 +26693,7 @@ var Bridge = class {
26511
26693
  record2.agentId = agent.agentId;
26512
26694
  record2.name = agent.name;
26513
26695
  this.save();
26514
- this.contextsChanged();
26696
+ this.agentsChanged();
26515
26697
  }
26516
26698
  /**
26517
26699
  * A person asked for a new agent in a room (ADR 0108): a record and a folder of its own, then
@@ -26540,7 +26722,8 @@ var Bridge = class {
26540
26722
  * A person asked for a copy of an agent in a room (ADR 0087, Fork): the agent's session in the
26541
26723
  * room it is in, copied with `session/fork` in the same folder, is the copy's session in the room
26542
26724
  * asked; the copy is registered for it. One that never spoke there is copied as a new agent in
26543
- * the same folder. A session that won't copy makes no copy: Chips tells the person.
26725
+ * the same folder. A session that won't copy makes no copy: Chips tells the person. The copy
26726
+ * starts with its original's pick of a model.
26544
26727
  */
26545
26728
  async copy(fork) {
26546
26729
  const { chips: chips2, state: state2 } = this.options;
@@ -26558,18 +26741,22 @@ var Bridge = class {
26558
26741
  this.log(`${original.name} can't be copied: ${client === void 0 ? "the agent isn't running" : "the agent doesn't copy sessions"}`);
26559
26742
  return;
26560
26743
  }
26561
- copied = await client.forkSession(from, original.folder);
26562
- this.process.live.add(copied);
26563
- await this.moded(client, copied);
26744
+ const forked = await client.forkSession(from, original.folder);
26745
+ copied = { client, sessionId: forked.sessionId };
26746
+ this.process.live.add(forked.sessionId);
26747
+ this.sessionOptions.set(forked.sessionId, forked.configOptions);
26748
+ await this.moded(client, forked.sessionId);
26564
26749
  }
26565
26750
  record2 = await this.made(forkName(original.name), {
26566
26751
  answers: fork.id,
26567
26752
  folder: original.folder,
26568
- forkedFrom: original.agentId
26753
+ forkedFrom: original.agentId,
26754
+ model: original.model
26569
26755
  });
26570
26756
  if (copied !== void 0) {
26571
- state2.sessions[`${record2.key}|${spaceId}`] = copied;
26757
+ state2.sessions[`${record2.key}|${spaceId}`] = copied.sessionId;
26572
26758
  this.save();
26759
+ await this.modelled(copied.client, record2, copied.sessionId);
26573
26760
  }
26574
26761
  }
26575
26762
  const agent = await chips2.agents.register({
@@ -26613,7 +26800,7 @@ var Bridge = class {
26613
26800
  };
26614
26801
  this.options.state.agents[key] = made;
26615
26802
  this.save();
26616
- this.contextsChanged();
26803
+ this.agentsChanged();
26617
26804
  return made;
26618
26805
  });
26619
26806
  this.log(`${agent.name} claimed ${spaceId}, in ${record2.folder}`);
@@ -26672,12 +26859,13 @@ var Bridge = class {
26672
26859
  for (const [id2, sessionId] of Object.entries(state2.sessions)) {
26673
26860
  if (!id2.startsWith(`${key}|`)) continue;
26674
26861
  delete state2.sessions[id2];
26862
+ this.sessionOptions.delete(sessionId);
26675
26863
  if (this.process.live.delete(sessionId) && this.process.info?.closeSession === true) {
26676
26864
  await this.process.client?.closeSession(sessionId).catch(() => void 0);
26677
26865
  }
26678
26866
  }
26679
26867
  this.save();
26680
- this.contextsChanged();
26868
+ this.agentsChanged();
26681
26869
  this.log(`${record2.name} deleted; its folder stays, ${record2.folder}`);
26682
26870
  }
26683
26871
  // ------------------------------------------------------------------ the agent's process
@@ -26687,6 +26875,7 @@ var Bridge = class {
26687
26875
  proc.live.clear();
26688
26876
  proc.stale.clear();
26689
26877
  proc.info = void 0;
26878
+ this.sessionOptions.clear();
26690
26879
  let wire;
26691
26880
  try {
26692
26881
  wire = this.options.wire();
@@ -26705,6 +26894,7 @@ var Bridge = class {
26705
26894
  proc.info = await client.initialize({ name: "chips-acp", version: VERSION });
26706
26895
  proc.failures = 0;
26707
26896
  this.log(`${name} is running${proc.info.name === void 0 ? "" : ` (${proc.info.name})`}`);
26897
+ if (this.options.models === true) void this.look(client);
26708
26898
  } catch (error62) {
26709
26899
  this.log(`${name} didn't say hello: ${String(error62)}`);
26710
26900
  client.close();
@@ -26781,6 +26971,7 @@ var Bridge = class {
26781
26971
  await client.closeSession(sessionId);
26782
26972
  live.delete(sessionId);
26783
26973
  this.process.stale.delete(sessionId);
26974
+ this.sessionOptions.delete(sessionId);
26784
26975
  this.log(`${room.record.name}'s session in ${room.spaceId} closed, quiet ${Math.round(idleMs / 6e4)} min`);
26785
26976
  } catch (error62) {
26786
26977
  this.log(`${room.record.name}'s session in ${room.spaceId} stays open: ${messageOf(error62)}`);
@@ -26929,22 +27120,26 @@ var Bridge = class {
26929
27120
  const { sessionId } = turn;
26930
27121
  turn.costAtStart = this.costs.get(sessionId);
26931
27122
  const project = await this.projectFor(turn, record2, spaceId, speakerId ?? record2.agentId);
26932
- let words4 = promptFor(message, {
27123
+ const asked = {
26933
27124
  ...speakerId === void 0 ? {} : { taker: speakerId },
26934
27125
  ...again2 === void 0 ? {} : { sayWho: false },
26935
27126
  sendsFiles: true,
26936
27127
  project
26937
- });
27128
+ };
27129
+ const rules = rulesFor(message, asked);
27130
+ let words4 = promptFor(message, { ...asked, rulesHeld: this.rules.holds(sessionId, rules) });
26938
27131
  const files = await this.filesFor(record2, message);
26939
27132
  if (files.length > 0) words4 = `${words4}
26940
27133
 
26941
27134
  ${files.join("\n")}`;
26942
27135
  if (turn.cancelled) return;
27136
+ this.rules.told(sessionId, rules);
26943
27137
  let stop2 = "end_turn";
26944
27138
  for (let prompt = words4; prompt !== void 0; prompt = turn.next.shift()) {
26945
27139
  try {
26946
27140
  stop2 = await client.prompt(sessionId, [{ type: "text", text: prompt }]);
26947
27141
  } catch (error62) {
27142
+ this.rules.forget(sessionId);
26948
27143
  if (!run2.over) await run2.fail({ error: this.failure(record2, error62), retryable: true });
26949
27144
  return;
26950
27145
  }
@@ -26955,8 +27150,9 @@ ${files.join("\n")}`;
26955
27150
  await this.finish(room, turn, stop2);
26956
27151
  }
26957
27152
  /**
26958
- * The room's session: the one it had, loaded once, or a new one, in the agent's folder. One a
26959
- * change from Chips made stale is closed and loaded again first, so the agent reads what changed.
27153
+ * The room's session: the one it had, loaded once, or a new one, in the agent's folder, put on
27154
+ * the agent's model. One a change from Chips made stale is closed and loaded again first, so the
27155
+ * agent reads what changed.
26960
27156
  */
26961
27157
  async sessionFor(record2, client, spaceId) {
26962
27158
  const { state: state2 } = this.options;
@@ -26967,9 +27163,11 @@ ${files.join("\n")}`;
26967
27163
  if (kept2 !== void 0 && live.has(kept2)) return kept2;
26968
27164
  if (kept2 !== void 0 && info?.loadSession === true) {
26969
27165
  try {
26970
- await client.loadSession(kept2, record2.folder, [], this.sessionMeta(record2));
27166
+ const loaded = await client.loadSession(kept2, record2.folder, [], this.sessionMeta(record2));
26971
27167
  live.add(kept2);
27168
+ this.sessionOptions.set(kept2, loaded.configOptions);
26972
27169
  await this.moded(client, kept2);
27170
+ await this.modelled(client, record2, kept2);
26973
27171
  return kept2;
26974
27172
  } catch (error62) {
26975
27173
  this.log(`${record2.name} couldn't load ${kept2}: ${messageOf(error62)}; starting afresh`);
@@ -26977,7 +27175,9 @@ ${files.join("\n")}`;
26977
27175
  }
26978
27176
  const made = await client.newSession(record2.folder, [], this.sessionMeta(record2));
26979
27177
  live.add(made.sessionId);
27178
+ this.sessionOptions.set(made.sessionId, made.configOptions);
26980
27179
  await this.moded(client, made.sessionId);
27180
+ await this.modelled(client, record2, made.sessionId);
26981
27181
  state2.sessions[key] = made.sessionId;
26982
27182
  this.save();
26983
27183
  return made.sessionId;
@@ -26993,6 +27193,7 @@ ${files.join("\n")}`;
26993
27193
  try {
26994
27194
  await client.closeSession(sessionId);
26995
27195
  live.delete(sessionId);
27196
+ this.sessionOptions.delete(sessionId);
26996
27197
  this.log(`${record2.name}'s session ${sessionId} closed, to start again with what changed`);
26997
27198
  } catch (error62) {
26998
27199
  this.log(`${record2.name}'s session ${sessionId} stays open: ${messageOf(error62)}`);
@@ -27220,8 +27421,9 @@ ${files.join("\n")}`;
27220
27421
  return this.records().filter((record2) => record2.agentId !== "").map((record2) => record2.folder);
27221
27422
  }
27222
27423
  /** The agents came or went: the copies sent again where they changed (Chips takes the same copy once). */
27223
- contextsChanged() {
27424
+ agentsChanged() {
27224
27425
  if (this.files !== void 0) void this.sendContexts();
27426
+ void this.sendModels();
27225
27427
  }
27226
27428
  /** The harness's own set and each agent's files, as they are on disk now. */
27227
27429
  async sendContexts() {
@@ -27340,6 +27542,11 @@ ${files.join("\n")}`;
27340
27542
  if (text.trim() === CODEX_COMPACTED) this.saidCompacted(sessionId);
27341
27543
  return;
27342
27544
  }
27545
+ case "config_option_update": {
27546
+ const options = configOptionsOf(update);
27547
+ if (this.sessionOptions.has(sessionId) && options.length > 0) this.sessionOptions.set(sessionId, options);
27548
+ return;
27549
+ }
27343
27550
  case "available_commands_update": {
27344
27551
  const commands = update["availableCommands"];
27345
27552
  if (Array.isArray(commands) && commands.some((each) => each?.name === "compact")) {
@@ -27404,6 +27611,7 @@ ${files.join("\n")}`;
27404
27611
  if (update.sessionUpdate !== "tool_call" || !isCompaction(update)) return;
27405
27612
  compaction = { id: id2, from: this.sessionUsed.get(sessionId), done: false };
27406
27613
  this.compactions.set(sessionId, compaction);
27614
+ this.rules.forget(sessionId);
27407
27615
  }
27408
27616
  const facts = compactionFacts(update);
27409
27617
  if (facts.from !== void 0) compaction.from = facts.from;
@@ -27430,6 +27638,7 @@ ${files.join("\n")}`;
27430
27638
  const lately = last?.finished !== void 0 && Date.now() - Date.parse(last.finished.at) < 5e3;
27431
27639
  if (last !== void 0 && (last.finished === void 0 || lately)) return;
27432
27640
  this.compactions.set(sessionId, { id: `said-${Date.now()}`, from: this.sessionUsed.get(sessionId), done: true });
27641
+ this.rules.forget(sessionId);
27433
27642
  }
27434
27643
  /** A compaction done: its agent's last, counted in the turn it was in, and the copy sent. */
27435
27644
  compacted(sessionId, compaction) {
@@ -27586,6 +27795,127 @@ ${files.join("\n")}`;
27586
27795
  this.compacting.delete(record2.key);
27587
27796
  await this.sendWindow(record2);
27588
27797
  }
27798
+ // ------------------------------------------------------------------ what each agent runs on (Chips ADRs 0140, 0241)
27799
+ /**
27800
+ * What the agent offers to run on, looked at each time it starts (`models.ts`): a session opened
27801
+ * in the harness's folder, put on each of its models in turn for that model's levels, and let go,
27802
+ * with nothing said to it. Kept with the bridge's agents, and each agent's copy sent from it.
27803
+ */
27804
+ async look(client) {
27805
+ const { kind: kind2 } = this.options;
27806
+ let sessionId;
27807
+ try {
27808
+ const made = await client.newSession(kind2.folder ?? kind2.folders);
27809
+ sessionId = made.sessionId;
27810
+ const { catalog, refused: refused3 } = await lookAt(
27811
+ made.configOptions,
27812
+ (configId, value) => client.setConfigOption(made.sessionId, configId, value)
27813
+ );
27814
+ for (const each of refused3) this.log(`${kind2.name} won't be put on ${each.model}, so it isn't offered: ${each.why}`);
27815
+ if (catalog === void 0) {
27816
+ this.log(`${kind2.name} offers no model to pick`);
27817
+ return;
27818
+ }
27819
+ this.options.state.models = catalog;
27820
+ this.save();
27821
+ this.log(`${kind2.name} offers ${catalog.choices.map((choice) => choice.id).join(", ")}; a new session runs on ${catalog.default.model}`);
27822
+ await this.sendModels();
27823
+ } catch (error62) {
27824
+ this.log(`${kind2.name}'s models not looked at: ${messageOf(error62)}`);
27825
+ } finally {
27826
+ if (sessionId !== void 0 && this.process.info?.closeSession === true) {
27827
+ await client.closeSession(sessionId).catch(() => void 0);
27828
+ }
27829
+ }
27830
+ }
27831
+ /** Each agent's copy, from what the agent offered when the bridge last looked: none before it has. */
27832
+ async sendModels() {
27833
+ for (const record2 of this.records()) await this.sendModel(record2);
27834
+ }
27835
+ async sendModel(record2) {
27836
+ const catalog = this.options.state.models;
27837
+ if (this.options.models !== true || catalog === void 0 || record2.agentId === "") return;
27838
+ await this.options.chips.settings.model(record2.agentId, modelCopy(catalog, record2.model, this.options.kind.name)).catch((error62) => this.log(`${record2.name}'s model not sent: ${messageOf(error62)}`));
27839
+ }
27840
+ /** A session just opened, put on its agent's model; where the agent won't, left as it is, and said so. */
27841
+ async modelled(client, record2, sessionId) {
27842
+ await this.putOnModel(client, record2, sessionId).catch(
27843
+ (error62) => this.log(`${record2.name}'s session ${sessionId} stays on what ${this.options.kind.name} opened it on: ${messageOf(error62)}`)
27844
+ );
27845
+ }
27846
+ /**
27847
+ * A session on its agent's model and effort: its pick, else the default. The model is set where
27848
+ * the session is on another, and a picked level always, so the agent's settings don't move it.
27849
+ * With no pick the level is left as the agent puts it, unless the pick was just dropped (`back`):
27850
+ * then it goes back too, to Claude Code's own `default`, or else the default's. Throws the agent's
27851
+ * refusal.
27852
+ */
27853
+ async putOnModel(client, record2, sessionId, back = false) {
27854
+ const catalog = this.options.state.models;
27855
+ let now = this.sessionOptions.get(sessionId);
27856
+ if (this.options.models !== true || catalog === void 0 || now === void 0) return;
27857
+ const pick2 = pickIn(catalog, record2.model);
27858
+ const target = pick2 ?? catalog.default;
27859
+ const set2 = async (option, value) => {
27860
+ const answered = await client.setConfigOption(sessionId, option.id, value);
27861
+ const before = now ?? [];
27862
+ now = answered.length > 0 ? answered : before.map((each) => each.id === option.id ? { ...each, currentValue: value } : each);
27863
+ this.sessionOptions.set(sessionId, now);
27864
+ };
27865
+ const model = modelOption(now);
27866
+ if (model !== void 0 && model.currentValue !== target.model) await set2(model, target.model);
27867
+ const effort = effortOption(now);
27868
+ const level = pick2 !== void 0 ? pick2.effort : back ? offers(effort, SETTINGS_LEVEL) ? SETTINGS_LEVEL : target.effort : void 0;
27869
+ if (effort !== void 0 && level !== void 0 && offers(effort, level)) await set2(effort, level);
27870
+ }
27871
+ /**
27872
+ * Each of an agent's live sessions on its model now. Put back on the default (`back`), a session
27873
+ * the agent won't move (Codex, off a model it doesn't list) is let go before its next turn and
27874
+ * loaded again; any other refusal is thrown.
27875
+ */
27876
+ async putSessionsOnModel(record2, back) {
27877
+ const client = this.process.client;
27878
+ if (client === void 0 || client.gone) return;
27879
+ for (const [id2, sessionId] of Object.entries(this.options.state.sessions)) {
27880
+ if (!id2.startsWith(`${record2.key}|`) || !this.process.live.has(sessionId)) continue;
27881
+ try {
27882
+ await this.putOnModel(client, record2, sessionId, back);
27883
+ } catch (error62) {
27884
+ if (!back) throw error62;
27885
+ this.process.stale.add(sessionId);
27886
+ this.log(`${record2.name}'s session ${sessionId} starts again before its next turn: ${messageOf(error62)}`);
27887
+ }
27888
+ }
27889
+ }
27890
+ /**
27891
+ * A person's pick of an agent's model and effort from Chips (Chips ADR 0241), or `null` for the
27892
+ * default: kept with the agent and set on each of its live sessions now, and on each it opens
27893
+ * after. One the agent refuses is refused with its words, and the sessions go back to what they
27894
+ * were on. A pick applies to that agent only.
27895
+ */
27896
+ async modelChange(change) {
27897
+ await this.known;
27898
+ const { kind: kind2 } = this.options;
27899
+ const catalog = this.options.state.models;
27900
+ if (this.options.models !== true || catalog === void 0) throw new Refuse(`${kind2.name} hasn't said what it runs on yet.`);
27901
+ const record2 = await this.recordOf(change.agent_id);
27902
+ if (record2 === void 0) throw new Refuse("This harness has no such agent.");
27903
+ const pick2 = pickFrom(catalog, change);
27904
+ if (pick2 === void 0) throw new Refuse(`${kind2.name} doesn't offer that.`, modelCopy(catalog, record2.model, kind2.name));
27905
+ const before = record2.model;
27906
+ record2.model = pick2 ?? void 0;
27907
+ try {
27908
+ await this.putSessionsOnModel(record2, pick2 === null);
27909
+ } catch (error62) {
27910
+ record2.model = before;
27911
+ await this.putSessionsOnModel(record2, before === void 0).catch(() => void 0);
27912
+ throw new Refuse(`${kind2.name} refused: ${messageOf(error62)}`, modelCopy(catalog, before, kind2.name));
27913
+ }
27914
+ this.save();
27915
+ const now = pick2 === null ? `${kind2.name}'s default` : `${pick2.model}${pick2.effort === void 0 ? "" : ` at ${pick2.effort}`}`;
27916
+ this.log(`${record2.name} runs on ${now}, from Chips`);
27917
+ return modelCopy(catalog, record2.model, kind2.name);
27918
+ }
27589
27919
  // ------------------------------------------------------------------ what the agent asks
27590
27920
  async asked(request) {
27591
27921
  switch (request.method) {
@@ -27617,7 +27947,7 @@ ${files.join("\n")}`;
27617
27947
  const stopped2 = new Promise((resolve5) => turn.run.on("cancel", () => resolve5(void 0)));
27618
27948
  const decision = await Promise.race([asked, stopped2]);
27619
27949
  if (decision === void 0) return { outcome: { outcome: "cancelled" } };
27620
- const chosen = optionFor(decision, options);
27950
+ const chosen = optionFor(decision, options, carriesCommand(input2));
27621
27951
  if (decision.allowed && chosen !== void 0 && call["toolCallId"] !== void 0) {
27622
27952
  turn.allowed.set(String(call["toolCallId"]), decision.approvalId);
27623
27953
  }
@@ -27653,7 +27983,10 @@ function settingsFor(kind2, bridge2) {
27653
27983
  return running;
27654
27984
  };
27655
27985
  return {
27656
- ...knownIdOf(kind2) === void 0 ? {} : { context: (edit) => active().contextEdited(edit) },
27986
+ ...knownIdOf(kind2) === void 0 ? {} : {
27987
+ context: (edit) => active().contextEdited(edit),
27988
+ models: (change) => active().modelChange(change)
27989
+ },
27657
27990
  contextWindows: {
27658
27991
  compact: (ask2) => active().windowCompact(ask2),
27659
27992
  change: (ask2) => active().windowChange(ask2)
@@ -27727,12 +28060,17 @@ function riskOf(kind2) {
27727
28060
  if (kind2 === "fetch") return ["external"];
27728
28061
  return [];
27729
28062
  }
27730
- function optionFor(decision, options) {
28063
+ function optionFor(decision, options, command) {
27731
28064
  const find = (kind2) => options.find((option) => option.kind === kind2)?.optionId;
27732
28065
  if (!decision.allowed) return find("reject_once") ?? find("reject_always");
27733
- if (decision.scope === "always") return find("allow_always") ?? find("allow_once");
28066
+ if (decision.scope === "always" && !command) return find("allow_always") ?? find("allow_once");
27734
28067
  return find("allow_once") ?? find("allow_always");
27735
28068
  }
28069
+ function carriesCommand(input2) {
28070
+ if (typeof input2 !== "object" || input2 === null) return false;
28071
+ const command = input2["command"];
28072
+ return typeof command === "string" || Array.isArray(command);
28073
+ }
27736
28074
  function questionOf(id2, field, message) {
27737
28075
  const prompt = String(field["title"] ?? field["description"] ?? message ?? id2).slice(0, 500);
27738
28076
  if (field["type"] === "boolean") {
@@ -27809,7 +28147,7 @@ function keepIfAsked(label2, url2, names, log2, before = () => void 0) {
27809
28147
  }
27810
28148
 
27811
28149
  // src/setup.ts
27812
- import { accessSync as accessSync2, constants as constants2, existsSync as existsSync7, readFileSync as readFileSync7 } from "node:fs";
28150
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
27813
28151
  import { homedir as homedir6 } from "node:os";
27814
28152
  import { basename as basename4, delimiter as delimiter2, isAbsolute as isAbsolute2, join as join9, resolve as resolve3 } from "node:path";
27815
28153
  var SetupError = class extends Error {
@@ -27830,7 +28168,7 @@ function readConfig(path) {
27830
28168
  `There is no config at ${path}. Write ${EXAMPLE} there, or name claude-code.json or codex.json, which need none. ${STILL_GOOD}`
27831
28169
  );
27832
28170
  }
27833
- const raw = existsSync7(path) ? JSON.parse(readFileSync7(path, "utf8")) : known;
28171
+ const raw = existsSync7(path) ? JSON.parse(readFileSync8(path, "utf8")) : known;
27834
28172
  const name = raw["name"];
27835
28173
  const command = raw["command"];
27836
28174
  if (typeof name !== "string" || name.trim() === "" || !Array.isArray(command) || command.length === 0) {
@@ -27896,7 +28234,7 @@ async function checkSignIn(kind2, wire, cwd, options = {}) {
27896
28234
  try {
27897
28235
  let info;
27898
28236
  try {
27899
- info = await within2(client.initialize({ name: "chips-acp", version: "1.0.0" }), MINUTE, "it didn't answer within a minute");
28237
+ info = await within2(client.initialize({ name: "chips-acp", version: VERSION }), MINUTE, "it didn't answer within a minute");
27900
28238
  } catch (error62) {
27901
28239
  const last = options.stderr?.().slice(-3).join(" ") ?? "";
27902
28240
  throw new SetupError(`${kind2.name} didn't start: ${wordsOf2(error62)}.${last === "" ? "" : ` It said: ${last}`} ${STILL_GOOD}`, {
@@ -27964,34 +28302,40 @@ var joined = await join3({
27964
28302
  link,
27965
28303
  url: process.env["CHIPS_URL"],
27966
28304
  name: kind.name,
27967
- software: "chips-acp 1.0.0",
28305
+ software: `chips-acp ${VERSION}`,
27968
28306
  wants: [
27969
28307
  "agents",
27970
28308
  "new_spaces",
27971
28309
  "new_agents",
27972
28310
  "forks",
27973
28311
  "restarts",
27974
- // Each agent's files, for the kinds whose files the bridge knows, and every agent's context window.
27975
- ...knownIdOf(kind) === void 0 ? [] : ["context_files"],
28312
+ // Each agent's files and its model, for the kinds whose files and models the bridge knows, and
28313
+ // every agent's context window.
28314
+ ...knownIdOf(kind) === void 0 ? [] : ["context_files", "models"],
27976
28315
  "context_windows"
27977
28316
  ],
27978
28317
  onCode: (code) => log(`Allow this harness in Chips: ${code}`)
27979
28318
  }).catch(refused2);
27980
28319
  keepIfAsked(LABEL, joined.url, ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "CODEX_HOME", "CLAUDE_CONFIG_DIR"], log);
27981
- var kept = existsSync8(statePath) ? JSON.parse(readFileSync8(statePath, "utf8")) : {};
27982
- var state = { sessions: kept.sessions ?? {}, agents: kept.agents ?? {}, windows: kept.windows ?? {} };
28320
+ var kept = existsSync8(statePath) ? JSON.parse(readFileSync9(statePath, "utf8")) : {};
28321
+ var state = {
28322
+ sessions: kept.sessions ?? {},
28323
+ agents: kept.agents ?? {},
28324
+ windows: kept.windows ?? {},
28325
+ ...kept.models === void 0 ? {} : { models: kept.models }
28326
+ };
27983
28327
  var env = adapterEnv(kind, { ...process.env, ...kind.env });
27984
28328
  var bridge;
27985
28329
  var chips = await connect({
27986
28330
  url: joined.url,
27987
28331
  token: joined.token,
27988
- client: { name: "chips-acp", version: "1.0.0" },
28332
+ client: { name: "chips-acp", version: VERSION },
27989
28333
  store: fileStore(join10(folder, "chips-state.json")),
27990
28334
  onRestart: async () => {
27991
28335
  log("a person asked for a restart");
27992
28336
  await bridge?.restart();
27993
28337
  },
27994
- // An agent's files and its context window, changed from its page (Chips ADRs 0134, 0146).
28338
+ // An agent's files, its context window and its model, changed from its page (Chips ADRs 0134, 0146, 0241).
27995
28339
  settings: settingsFor(kind, () => bridge)
27996
28340
  });
27997
28341
  var git = await checkGit();
@@ -28000,6 +28344,8 @@ bridge = new Bridge({
28000
28344
  chips,
28001
28345
  kind,
28002
28346
  projects: git.ok,
28347
+ // Claude Code's and Codex's adapters offer their models as session options (Chips ADR 0241).
28348
+ models: knownIdOf(kind) !== void 0,
28003
28349
  state,
28004
28350
  saveState: (next) => writeFileSync4(statePath, `${JSON.stringify(next, null, 2)}
28005
28351
  `, { mode: 384 }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chipschat/acp",
3
- "version": "1.0.4",
3
+ "version": "1.0.8",
4
4
  "description": "An agent that speaks the Agent Client Protocol, as a Chips harness of its kind: agents made from Chips, each in a folder of its own, each room a session.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",