@chipschat/acp 1.0.6 → 1.0.9

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`, 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 |
150
+ | Approval card | `session/request_permission`, asked in the agent's own words where the call has a `description` (Claude Code's commands: "Syntax-check game.js? `node --check game.js`"), else "Allow it to" and the call's title; 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 |
@@ -216,7 +216,10 @@ it kept. The scratch Chips, the link and the run come from Chips's `tools/connec
216
216
  ## Release
217
217
 
218
218
  `npm run release` builds `dist/main.js`, one file with the SDK and everything else bundled in, and
219
- `dist/THIRD-PARTY-NOTICES.md` beside it; runs the tests; and packs `chipschat-acp-<version>.tgz`. `npm publish`
220
- publishes it. A version's major is the Chips protocol it speaks, and Chips's card names that major
219
+ `dist/THIRD-PARTY-NOTICES.md` beside it; runs the tests; and packs `chipschat-acp-<version>.tgz`. To
220
+ publish, put the new version in `package.json` (`npm version <version> --no-git-tag-version`), commit
221
+ it and push to `main`: GitHub's Publish workflow (`.github/workflows/publish.yml`) tests it and
222
+ publishes it to npm, which trusts that workflow, so nobody signs in. Don't also run `npm publish`:
223
+ the two race. A version's major is the Chips protocol it speaks, and Chips's card names that major
221
224
  (Chips ADR 0218): a fix is a minor or a patch, and reaches every card of its major the day it is
222
225
  published.
@@ -1,6 +1,6 @@
1
1
  # Third-party notices
2
2
 
3
- `dist/main.js` in @chipschat/acp 1.0.6 carries these packages, bundled in. Each one's
3
+ `dist/main.js` in @chipschat/acp 1.0.9 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 = {}) {
@@ -26229,6 +26312,10 @@ function signedOutStop(kind2) {
26229
26312
  };
26230
26313
  }
26231
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
+
26232
26319
  // src/models.ts
26233
26320
  var SETTINGS_LEVEL = "default";
26234
26321
  var LEVEL_WORDS = { xhigh: "Extra high" };
@@ -26410,7 +26497,6 @@ function compactionFacts(update) {
26410
26497
  }
26411
26498
 
26412
26499
  // src/bridge.ts
26413
- var VERSION = "1.0.0";
26414
26500
  var QUIET_MS = 1500;
26415
26501
  var WAIT_FOR_AGENT_MS = 15e3;
26416
26502
  var MOST_RESPAWN_MS = 6e4;
@@ -26454,6 +26540,8 @@ var Bridge = class {
26454
26540
  offersCompact = false;
26455
26541
  /** Each session's last `used`, for where a compaction began. */
26456
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();
26457
26545
  compactions = /* @__PURE__ */ new Map();
26458
26546
  /** The bridge's own `/compact` turns, by session. */
26459
26547
  compactRuns = /* @__PURE__ */ new Map();
@@ -27032,22 +27120,26 @@ var Bridge = class {
27032
27120
  const { sessionId } = turn;
27033
27121
  turn.costAtStart = this.costs.get(sessionId);
27034
27122
  const project = await this.projectFor(turn, record2, spaceId, speakerId ?? record2.agentId);
27035
- let words4 = promptFor(message, {
27123
+ const asked = {
27036
27124
  ...speakerId === void 0 ? {} : { taker: speakerId },
27037
27125
  ...again2 === void 0 ? {} : { sayWho: false },
27038
27126
  sendsFiles: true,
27039
27127
  project
27040
- });
27128
+ };
27129
+ const rules = rulesFor(message, asked);
27130
+ let words4 = promptFor(message, { ...asked, rulesHeld: this.rules.holds(sessionId, rules) });
27041
27131
  const files = await this.filesFor(record2, message);
27042
27132
  if (files.length > 0) words4 = `${words4}
27043
27133
 
27044
27134
  ${files.join("\n")}`;
27045
27135
  if (turn.cancelled) return;
27136
+ this.rules.told(sessionId, rules);
27046
27137
  let stop2 = "end_turn";
27047
27138
  for (let prompt = words4; prompt !== void 0; prompt = turn.next.shift()) {
27048
27139
  try {
27049
27140
  stop2 = await client.prompt(sessionId, [{ type: "text", text: prompt }]);
27050
27141
  } catch (error62) {
27142
+ this.rules.forget(sessionId);
27051
27143
  if (!run2.over) await run2.fail({ error: this.failure(record2, error62), retryable: true });
27052
27144
  return;
27053
27145
  }
@@ -27519,6 +27611,7 @@ ${files.join("\n")}`;
27519
27611
  if (update.sessionUpdate !== "tool_call" || !isCompaction(update)) return;
27520
27612
  compaction = { id: id2, from: this.sessionUsed.get(sessionId), done: false };
27521
27613
  this.compactions.set(sessionId, compaction);
27614
+ this.rules.forget(sessionId);
27522
27615
  }
27523
27616
  const facts = compactionFacts(update);
27524
27617
  if (facts.from !== void 0) compaction.from = facts.from;
@@ -27545,6 +27638,7 @@ ${files.join("\n")}`;
27545
27638
  const lately = last?.finished !== void 0 && Date.now() - Date.parse(last.finished.at) < 5e3;
27546
27639
  if (last !== void 0 && (last.finished === void 0 || lately)) return;
27547
27640
  this.compactions.set(sessionId, { id: `said-${Date.now()}`, from: this.sessionUsed.get(sessionId), done: true });
27641
+ this.rules.forget(sessionId);
27548
27642
  }
27549
27643
  /** A compaction done: its agent's last, counted in the turn it was in, and the copy sent. */
27550
27644
  compacted(sessionId, compaction) {
@@ -27844,7 +27938,7 @@ ${files.join("\n")}`;
27844
27938
  const input2 = call["rawInput"];
27845
27939
  const asked = turn.run.approval({
27846
27940
  action: { kind: `acp.${slugOf(kind2)}`, input: input2 ?? {} },
27847
- question: `Allow it to ${lowerFirst(title2)}?`.slice(0, 300),
27941
+ question: questionFor(title2, input2),
27848
27942
  lasts: "once",
27849
27943
  risk: riskOf(kind2),
27850
27944
  ...input2 === void 0 ? {} : { preview: { format: "json", body: JSON.stringify(input2, null, 2).slice(0, 2e5) } },
@@ -27961,6 +28055,24 @@ function slugOf(word) {
27961
28055
  function lowerFirst(text) {
27962
28056
  return text.length === 0 ? text : `${text[0]?.toLowerCase() ?? ""}${text.slice(1)}`;
27963
28057
  }
28058
+ var QUESTION_MAX = 300;
28059
+ function questionFor(title2, input2) {
28060
+ const fields = typeof input2 === "object" && input2 !== null ? input2 : {};
28061
+ const said = oneLine(fields["description"])?.replace(/[\s.?!:;,]+$/, "");
28062
+ if (said === void 0 || said === "") return `Allow it to ${lowerFirst(title2)}?`.slice(0, QUESTION_MAX);
28063
+ const asked = `${clip(said, QUESTION_MAX - 1)}?`;
28064
+ const command = oneLine(Array.isArray(fields["command"]) ? fields["command"].join(" ") : fields["command"]);
28065
+ const room = QUESTION_MAX - asked.length - 3;
28066
+ if (command === void 0 || command.includes("`") || room < 12) return asked;
28067
+ return `${asked} \`${clip(command, room)}\``;
28068
+ }
28069
+ function oneLine(value) {
28070
+ const line = typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
28071
+ return line === "" ? void 0 : line;
28072
+ }
28073
+ function clip(text, max) {
28074
+ return text.length <= max ? text : `${text.slice(0, max - 1)}\u2026`;
28075
+ }
27964
28076
  function riskOf(kind2) {
27965
28077
  if (kind2 === "delete") return ["destructive"];
27966
28078
  if (kind2 === "fetch") return ["external"];
@@ -28053,7 +28165,7 @@ function keepIfAsked(label2, url2, names, log2, before = () => void 0) {
28053
28165
  }
28054
28166
 
28055
28167
  // src/setup.ts
28056
- import { accessSync as accessSync2, constants as constants2, existsSync as existsSync7, readFileSync as readFileSync7 } from "node:fs";
28168
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync7, readFileSync as readFileSync8 } from "node:fs";
28057
28169
  import { homedir as homedir6 } from "node:os";
28058
28170
  import { basename as basename4, delimiter as delimiter2, isAbsolute as isAbsolute2, join as join9, resolve as resolve3 } from "node:path";
28059
28171
  var SetupError = class extends Error {
@@ -28074,7 +28186,7 @@ function readConfig(path) {
28074
28186
  `There is no config at ${path}. Write ${EXAMPLE} there, or name claude-code.json or codex.json, which need none. ${STILL_GOOD}`
28075
28187
  );
28076
28188
  }
28077
- const raw = existsSync7(path) ? JSON.parse(readFileSync7(path, "utf8")) : known;
28189
+ const raw = existsSync7(path) ? JSON.parse(readFileSync8(path, "utf8")) : known;
28078
28190
  const name = raw["name"];
28079
28191
  const command = raw["command"];
28080
28192
  if (typeof name !== "string" || name.trim() === "" || !Array.isArray(command) || command.length === 0) {
@@ -28140,7 +28252,7 @@ async function checkSignIn(kind2, wire, cwd, options = {}) {
28140
28252
  try {
28141
28253
  let info;
28142
28254
  try {
28143
- info = await within2(client.initialize({ name: "chips-acp", version: "1.0.0" }), MINUTE, "it didn't answer within a minute");
28255
+ info = await within2(client.initialize({ name: "chips-acp", version: VERSION }), MINUTE, "it didn't answer within a minute");
28144
28256
  } catch (error62) {
28145
28257
  const last = options.stderr?.().slice(-3).join(" ") ?? "";
28146
28258
  throw new SetupError(`${kind2.name} didn't start: ${wordsOf2(error62)}.${last === "" ? "" : ` It said: ${last}`} ${STILL_GOOD}`, {
@@ -28208,7 +28320,7 @@ var joined = await join3({
28208
28320
  link,
28209
28321
  url: process.env["CHIPS_URL"],
28210
28322
  name: kind.name,
28211
- software: "chips-acp 1.0.0",
28323
+ software: `chips-acp ${VERSION}`,
28212
28324
  wants: [
28213
28325
  "agents",
28214
28326
  "new_spaces",
@@ -28223,7 +28335,7 @@ var joined = await join3({
28223
28335
  onCode: (code) => log(`Allow this harness in Chips: ${code}`)
28224
28336
  }).catch(refused2);
28225
28337
  keepIfAsked(LABEL, joined.url, ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "CODEX_HOME", "CLAUDE_CONFIG_DIR"], log);
28226
- var kept = existsSync8(statePath) ? JSON.parse(readFileSync8(statePath, "utf8")) : {};
28338
+ var kept = existsSync8(statePath) ? JSON.parse(readFileSync9(statePath, "utf8")) : {};
28227
28339
  var state = {
28228
28340
  sessions: kept.sessions ?? {},
28229
28341
  agents: kept.agents ?? {},
@@ -28235,7 +28347,7 @@ var bridge;
28235
28347
  var chips = await connect({
28236
28348
  url: joined.url,
28237
28349
  token: joined.token,
28238
- client: { name: "chips-acp", version: "1.0.0" },
28350
+ client: { name: "chips-acp", version: VERSION },
28239
28351
  store: fileStore(join10(folder, "chips-state.json")),
28240
28352
  onRestart: async () => {
28241
28353
  log("a person asked for a restart");
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@chipschat/acp",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
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
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/arjungupta99/chips-acp.git"
9
+ },
6
10
  "type": "module",
7
11
  "engines": {
8
12
  "node": ">=22.19.0"