@chipschat/acp 1.0.19 → 1.0.21

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
@@ -146,6 +146,9 @@ minutes and loaded again with its memory. Fourteen runs, none failed, $0.35, all
146
146
  | Chips | ACP |
147
147
  |---|---|
148
148
  | A message for an agent | `session/prompt` with the room note and who said it (`promptFor`), files saved under `<folder>/chips-files/` |
149
+ | What waited for an agent (Chips ADR 0294) | one prompt once the agent is free, not one each: under the newest message's note, each message that waited said in full, oldest first, then what was said in the room after, to others. A message Chips handed over, and a Not right?, are a prompt of their own. An idle agent starts 150 ms after the first words, so all it is sent at once, as when the bridge comes back, is one prompt |
150
+ | What was said before an agent joined (Chips ADR 0088) | the room's last lines from before the agent was put in it (`agent.attached`'s `catch_up`), said once, at its first prompt there, under "Said in this space before you joined:", ahead of the lines since |
151
+ | A message Chips held (Chips ADR 0097) | when Chips answers what an agent said with `held` (the agents in the room have sent each other the workspace's hold, or a person paused them), the agent's next prompt in the room opens by saying so: the agents it named do not have the message yet, so it tells the person what is done and what is blocked rather than asking them again. Said once |
149
152
  | The room | a session in the agent's folder: `session/new` the first time, `session/load` after a restart or an idle close where the agent offers it |
150
153
  | A room from the + | `claimSpace` under a new key; Chips makes its agent; the first words are its first prompt |
151
154
  | A new agent (Add) | a record and a folder, registered with `madeFor` and the room |
@@ -1,6 +1,6 @@
1
1
  # Third-party notices
2
2
 
3
- `dist/main.js` in @chipschat/acp 1.0.19 carries these packages, bundled in. Each one's
3
+ `dist/main.js` in @chipschat/acp 1.0.21 carries these packages, bundled in. Each one's
4
4
  licence follows.
5
5
 
6
6
  ## @chipschat/harness 1.0.4 (Apache-2.0)
package/dist/main.js CHANGED
@@ -20676,6 +20676,7 @@ var MONTHS = [
20676
20676
  ];
20677
20677
 
20678
20678
  // node_modules/@chipschat/protocol/dist/src/context.js
20679
+ var CONTEXT_BUDGET = { lines: 40, chars: 16e3 };
20679
20680
  var CONTEXT_CEILING = { lines: 200, chars: 32e3 };
20680
20681
  var CONTEXT_HEADING = "Said in this space since you last spoke:";
20681
20682
  var contextBudget = external_exports.object({
@@ -26992,6 +26993,103 @@ var ContextFiles = class {
26992
26993
  }
26993
26994
  };
26994
26995
 
26996
+ // src/fold.ts
26997
+ var GATHER_MS = 150;
26998
+ function heldWords(answer) {
26999
+ if (answer?.held !== true) return void 0;
27000
+ const count = answer.exchange?.count;
27001
+ const since = typeof count === "number" && count > 0 ? ` (they have sent each other ${count} since a person last acted)` : "";
27002
+ return `Your last message in this space was held, so the agents it named do not have it yet: messages between the agents here are held${since} until a person acts. Until then, tell the person what is done and what is blocked, rather than asking the agents again.`;
27003
+ }
27004
+ var BEFORE_HEADING = "Said in this space before you joined:";
27005
+ function beforeOf(message, earlier, before) {
27006
+ const said = /* @__PURE__ */ new Set([message.message_id, ...earlier.map((each) => each.message_id)]);
27007
+ const lines2 = (before?.lines ?? []).filter((line) => line.message_id === void 0 || !said.has(line.message_id));
27008
+ return lines2.length === 0 ? void 0 : [BEFORE_HEADING, ...lines2.map(renderLine)].join("\n");
27009
+ }
27010
+ function folds(message) {
27011
+ return message.handed !== true;
27012
+ }
27013
+ function keepAnswered(answered, messages) {
27014
+ answered.push(...messages.map((each) => each.message_id));
27015
+ answered.splice(0, Math.max(0, answered.length - CONTEXT_BUDGET.lines));
27016
+ }
27017
+ function keepHeard(since, heard) {
27018
+ since.push(heard);
27019
+ if (since.length > CONTEXT_BUDGET.lines) since.shift();
27020
+ }
27021
+ function lineOfHeard(heard) {
27022
+ const files = heard.attachments ?? [];
27023
+ const said = files.flatMap((file3) => file3.transcript === void 0 ? [] : [file3.transcript]);
27024
+ return {
27025
+ seq: 1,
27026
+ at: "",
27027
+ kind: "said",
27028
+ from: {
27029
+ id: heard.from.participant_id,
27030
+ kind: heard.from.kind,
27031
+ name: heard.from.display_name,
27032
+ ...heard.from.workspace_role === void 0 ? {} : { workspace_role: heard.from.workspace_role }
27033
+ },
27034
+ text: heard.text,
27035
+ ...said.length === 0 ? {} : { transcript: said.join(" ") },
27036
+ ...files.length === 0 ? {} : { files: files.map((file3) => file3.filename) },
27037
+ ...heard.held === true ? { held: true } : {}
27038
+ };
27039
+ }
27040
+ function sinceOf(since, earlier) {
27041
+ const newest = since.slice(-CONTEXT_BUDGET.lines);
27042
+ if (newest.length === 0) return void 0;
27043
+ const those = earlier.length === 0 ? "that message" : "those messages";
27044
+ return [`Said in this space after ${those}, to others:`, ...newest.map((each) => renderLine(lineOfHeard(each)))].join("\n");
27045
+ }
27046
+ function waitedWords(count) {
27047
+ return `${count} messages for you waited while you were working or away. They follow, oldest first. Answer them together in one reply, and where a later one changes or settles an earlier one, go by the later.`;
27048
+ }
27049
+ function saidOf(message, options, taker) {
27050
+ const who2 = options.sayWho === false ? "" : `${withRole(message.from.display_name, message.from)}: `;
27051
+ const files = (message.attachments ?? []).map(renderAttachment);
27052
+ const replying = renderReplyingTo(message.replying_to, {
27053
+ sender: {
27054
+ id: message.from.participant_id,
27055
+ name: message.from.display_name,
27056
+ kind: message.from.kind,
27057
+ workspace_role: message.from.workspace_role
27058
+ },
27059
+ taker,
27060
+ at: message.ts,
27061
+ zone: options.zone
27062
+ });
27063
+ return [replying, [`${who2}${message.text}`, ...files].join("\n")];
27064
+ }
27065
+ function contextOf(message, earlier, answered) {
27066
+ const { context } = message;
27067
+ const waited = /* @__PURE__ */ new Set([...earlier.map((each) => each.message_id), ...answered]);
27068
+ if (context === void 0 || waited.size === 0) return context;
27069
+ return { ...context, lines: context.lines.filter((line) => line.message_id === void 0 || !waited.has(line.message_id)) };
27070
+ }
27071
+ function promptForAll(message, options = {}) {
27072
+ const { earlier = [], since = [], answered = [], before, heldPost, ...rest } = options;
27073
+ const held = heldWords(heldPost);
27074
+ const joinedBefore = beforeOf(message, earlier, before);
27075
+ if (earlier.length === 0 && since.length === 0 && answered.length === 0 && held === void 0 && joinedBefore === void 0) {
27076
+ return promptFor(message, rest);
27077
+ }
27078
+ const taker = rest.taker ?? (message.for?.length === 1 ? message.for[0] : void 0);
27079
+ const text = [
27080
+ joinedBefore,
27081
+ renderContext(contextOf(message, earlier, answered)),
27082
+ earlier.length === 0 ? void 0 : waitedWords(earlier.length + 1),
27083
+ ...earlier.flatMap((each) => saidOf(each, rest, taker)),
27084
+ ...saidOf(message, rest, taker),
27085
+ sinceOf(since, earlier)
27086
+ ].filter((part) => part !== void 0 && part !== "").join("\n\n");
27087
+ const { attachments: _files, replying_to: _reply, context: _lines, exchange, ...bare } = message;
27088
+ const chips2 = [held, exchange?.note].filter((part) => part !== void 0 && part !== "").join("\n\n");
27089
+ const one = { ...bare, text, ...chips2 === "" ? {} : { exchange: { ...exchange, note: chips2 } } };
27090
+ return promptFor(one, { ...rest, sayWho: false });
27091
+ }
27092
+
26995
27093
  // src/models.ts
26996
27094
  var SETTINGS_LEVEL = "default";
26997
27095
  var LEVEL_WORDS = { xhigh: "Extra high" };
@@ -27180,6 +27278,20 @@ var IDLE_MS = 30 * 6e4;
27180
27278
  var ANSWERED = 500;
27181
27279
  var QUOTED = 1500;
27182
27280
  var CARRY_ON = "You were paused partway through this. Carry on from where you stopped. Nothing you wrote before the pause reached the room, so write your whole reply.";
27281
+ function shares(asked) {
27282
+ return asked.again === void 0 && folds(asked.message);
27283
+ }
27284
+ function nextTurn(queue) {
27285
+ const first = queue.shift();
27286
+ if (first === void 0) return [];
27287
+ const taken = [first];
27288
+ if (!shares(first)) return taken;
27289
+ while (queue[0] !== void 0 && shares(queue[0]) && queue[0].speakerId === first.speakerId) {
27290
+ taken.push(queue.shift());
27291
+ }
27292
+ return taken;
27293
+ }
27294
+ var CAUGHT_UP_MOST = 200;
27183
27295
  var Bridge = class {
27184
27296
  constructor(options) {
27185
27297
  this.options = options;
@@ -27201,6 +27313,13 @@ var Bridge = class {
27201
27313
  /** What Chips asks waits for the agents to be known: they are read at start. */
27202
27314
  known;
27203
27315
  knew = () => void 0;
27316
+ /** What is said in the rooms is taken in the order it came: a message, then what was overheard after it. */
27317
+ arriving = Promise.resolve();
27318
+ /**
27319
+ * What was said in a room before one of its agents joined it (Chips ADR 0088), by the agent and
27320
+ * the room: said at the agent's first turn there, and kept no longer.
27321
+ */
27322
+ caughtUp = /* @__PURE__ */ new Map();
27204
27323
  /** Records are made one at a time, so two never take the same folder. */
27205
27324
  making = Promise.resolve();
27206
27325
  /** The feedback already answered, oldest first. */
@@ -27234,7 +27353,12 @@ var Bridge = class {
27234
27353
  const after = (what, then) => {
27235
27354
  void this.known.then(then).catch((error62) => this.log(`${what} went wrong: ${messageOf(error62)}`));
27236
27355
  };
27237
- chips2.on("message.new", (message) => after("a message", () => this.hear(message)));
27356
+ const inOrder = (what, then) => {
27357
+ this.arriving = this.arriving.then(() => this.known).then(then).catch((error62) => this.log(`${what} went wrong: ${messageOf(error62)}`));
27358
+ };
27359
+ chips2.on("message.new", (message) => inOrder("a message", () => this.hear(message)));
27360
+ chips2.on("message.overheard", (message) => inOrder("words overheard", async () => this.overheard(message)));
27361
+ chips2.on("agent.attached", (attached) => this.attached(attached));
27238
27362
  chips2.on("agent.asked", (asked) => after("a new agent", () => this.make(asked)));
27239
27363
  chips2.on("agent.fork", (fork) => after("a copy", () => this.copy(fork)));
27240
27364
  chips2.on("feedback", (feedback2) => after("a second look", () => this.lookAgain(feedback2)));
@@ -27263,6 +27387,7 @@ var Bridge = class {
27263
27387
  this.process.stopping = true;
27264
27388
  this.process.client?.close();
27265
27389
  clearInterval(this.sweeper);
27390
+ for (const room of this.rooms.values()) clearTimeout(room.gathering);
27266
27391
  for (const timer of this.windowTimers.values()) clearTimeout(timer);
27267
27392
  this.windowTimers.clear();
27268
27393
  }
@@ -27490,8 +27615,8 @@ var Bridge = class {
27490
27615
  for: [agent.agentId]
27491
27616
  };
27492
27617
  const room = this.roomOf(record2, spaceId);
27493
- room.queue.push({ message, speakerId: agent.agentId });
27494
- void this.pump(room);
27618
+ room.queue.push({ message, speakerId: agent.agentId, since: [] });
27619
+ this.soon(room);
27495
27620
  }
27496
27621
  /** Who said a room's first words, from the room's lines. */
27497
27622
  async whoSaid(asked) {
@@ -27659,18 +27784,65 @@ var Bridge = class {
27659
27784
  }
27660
27785
  }
27661
27786
  // ------------------------------------------------------------------ what is said to it
27662
- /** A message for some of its agents: each takes a turn in its room, one after another there. */
27787
+ /**
27788
+ * A message for some of its agents: each takes it in its room, one turn at a time there. It waits
27789
+ * while a turn is going, and is in the next with whatever else waits (Chips ADR 0294).
27790
+ */
27663
27791
  async hear(message, again2) {
27664
27792
  const spaceId = message.space_id;
27665
27793
  if (spaceId === void 0) return;
27666
27794
  const harnessId = this.options.chips.harnessId;
27795
+ const takes = /* @__PURE__ */ new Set();
27667
27796
  for (const taker of message.for ?? [harnessId]) {
27668
27797
  const record2 = taker === harnessId ? await this.inRoom(spaceId) : await this.recordOf(taker);
27669
27798
  if (record2 === void 0) continue;
27670
27799
  const room = this.roomOf(record2, spaceId);
27671
- room.queue.push({ message, speakerId: taker === harnessId ? void 0 : taker, again: again2 });
27672
- void this.pump(room);
27800
+ takes.add(room);
27801
+ room.queue.push({ message, speakerId: taker === harnessId ? void 0 : taker, again: again2, since: [] });
27802
+ this.soon(room);
27673
27803
  }
27804
+ if (again2 === void 0) this.saidToOthers(spaceId, message, takes);
27805
+ }
27806
+ /**
27807
+ * One of its agents put in a room (Chips ADR 0088): the room's last lines before it joined come
27808
+ * with the news, and are kept for the agent's first turn there, which says them once.
27809
+ */
27810
+ attached(attached) {
27811
+ const { agent_id: agentId2, space_id: spaceId, catch_up: before } = attached;
27812
+ if (spaceId === void 0 || before === void 0 || before.lines.length === 0) return;
27813
+ this.caughtUp.set(`${agentId2}|${spaceId}`, before);
27814
+ for (const oldest of this.caughtUp.keys()) {
27815
+ if (this.caughtUp.size <= CAUGHT_UP_MOST) break;
27816
+ this.caughtUp.delete(oldest);
27817
+ }
27818
+ }
27819
+ /**
27820
+ * Words said in a room to others (Chips ADR 0294): kept where a message waits for one of its
27821
+ * agents there, as said after the newest of them, and told to the turn that takes it. Chips
27822
+ * hands a turn what was said before its message; this is what is said while the message waits.
27823
+ */
27824
+ overheard(message) {
27825
+ if (message.space_id !== void 0) this.saidToOthers(message.space_id, message, /* @__PURE__ */ new Set());
27826
+ }
27827
+ /** Kept by each of its agents in the room with a message waiting, but those it is for, and the one who said it. */
27828
+ saidToOthers(spaceId, said, takes) {
27829
+ for (const room of this.rooms.values()) {
27830
+ const newest = room.queue.at(-1);
27831
+ if (newest === void 0 || room.spaceId !== spaceId || takes.has(room)) continue;
27832
+ if (said.from.participant_id === room.record.agentId) continue;
27833
+ keepHeard(newest.since, { from: said.from, text: said.text, attachments: said.attachments, held: said.held });
27834
+ }
27835
+ }
27836
+ /**
27837
+ * An idle agent starts in a moment, not at once (Chips ADR 0294): a bridge that comes back is
27838
+ * sent all it missed together, and what waits when a turn starts is one turn.
27839
+ */
27840
+ soon(room) {
27841
+ if (room.busy || room.gathering !== void 0) return;
27842
+ room.gathering = setTimeout(() => {
27843
+ room.gathering = void 0;
27844
+ void this.pump(room);
27845
+ }, this.options.gatherMs ?? GATHER_MS);
27674
27846
  }
27675
27847
  /**
27676
27848
  * A person said a reply of one of its agents wasn't right (Chips ADR 0200): a correction, or an
@@ -27713,7 +27885,7 @@ var Bridge = class {
27713
27885
  const id2 = `${record2.key}|${spaceId}`;
27714
27886
  let room = this.rooms.get(id2);
27715
27887
  if (room === void 0) {
27716
- room = { record: record2, spaceId, queue: [], busy: false, usedAt: Date.now() };
27888
+ room = { record: record2, spaceId, queue: [], busy: false, usedAt: Date.now(), answered: [] };
27717
27889
  this.rooms.set(id2, room);
27718
27890
  }
27719
27891
  return room;
@@ -27736,11 +27908,11 @@ var Bridge = class {
27736
27908
  }
27737
27909
  return;
27738
27910
  }
27739
- const asked = room.queue.shift();
27740
- if (asked === void 0) return;
27911
+ const waiting = nextTurn(room.queue);
27912
+ if (waiting.length === 0) return;
27741
27913
  room.busy = true;
27742
27914
  try {
27743
- await this.turn(room, asked);
27915
+ await this.turn(room, waiting);
27744
27916
  } catch (error62) {
27745
27917
  this.log(`a turn of ${room.record.name} went wrong: ${String(error62)}`);
27746
27918
  } finally {
@@ -27752,7 +27924,13 @@ var Bridge = class {
27752
27924
  void this.pump(room);
27753
27925
  }
27754
27926
  }
27755
- async turn(room, { message, speakerId, again: again2 }) {
27927
+ /**
27928
+ * One turn on what waited (Chips ADR 0294): the newest message's, whose note and lines it is
27929
+ * handed, with those that waited ahead of it said in full, and what was said after to others.
27930
+ */
27931
+ async turn(room, waiting) {
27932
+ const { message, speakerId, again: again2, since } = waiting.at(-1);
27933
+ const earlier = waiting.slice(0, -1).map((each) => each.message);
27756
27934
  const { record: record2, spaceId } = room;
27757
27935
  const { kind: kind2 } = this.options;
27758
27936
  const speaker = speakerId === void 0 ? this.options.chips : this.options.chips.as(speakerId);
@@ -27821,11 +27999,22 @@ var Bridge = class {
27821
27999
  project
27822
28000
  };
27823
28001
  const rules = rulesFor(message, asked);
27824
- let words4 = promptFor(message, { ...asked, rulesHeld: this.rules.holds(sessionId, rules) });
27825
- const files = await this.filesFor(record2, message);
28002
+ const joined2 = `${speakerId ?? record2.agentId}|${spaceId}`;
28003
+ let words4 = promptForAll(message, {
28004
+ ...asked,
28005
+ rulesHeld: this.rules.holds(sessionId, rules),
28006
+ earlier,
28007
+ since,
28008
+ answered: room.answered,
28009
+ before: this.caughtUp.get(joined2),
28010
+ heldPost: room.heldPost
28011
+ });
28012
+ const files = [];
28013
+ for (const each of [...earlier, message]) files.push(...await this.filesFor(record2, each));
27826
28014
  if (files.length > 0) words4 = `${words4}
27827
28015
 
27828
28016
  ${files.join("\n")}`;
28017
+ if (earlier.length > 0) this.log(`${record2.name} takes ${waiting.length} messages that waited in ${spaceId} as one turn`);
27829
28018
  if (!await this.unpaused(turn)) return;
27830
28019
  this.rules.told(sessionId, rules);
27831
28020
  let stop2 = "end_turn";
@@ -27843,6 +28032,11 @@ ${files.join("\n")}`;
27843
28032
  return;
27844
28033
  }
27845
28034
  turn.prompting = false;
28035
+ if (prompt === words4) {
28036
+ keepAnswered(room.answered, [...earlier, message]);
28037
+ this.caughtUp.delete(joined2);
28038
+ room.heldPost = void 0;
28039
+ }
27846
28040
  if (turn.cancelled) return;
27847
28041
  const paused = turn.pausing;
27848
28042
  turn.pausing = false;
@@ -27985,7 +28179,11 @@ ${files.join("\n")}`;
27985
28179
  const post = await sendAnswer(words4, { folders: [room.record.folder], upload: (input2) => chips2.upload(input2) });
27986
28180
  const reply = post.text;
27987
28181
  if (reply !== "" || post.uploadIds.length > 0) {
27988
- await turn.speaker.post({ spaceId: room.spaceId, runId: run2.id, text: reply, uploadIds: post.uploadIds, change });
28182
+ const taken = await turn.speaker.post({ spaceId: room.spaceId, runId: run2.id, text: reply, uploadIds: post.uploadIds, change });
28183
+ if (taken.held === true) {
28184
+ room.heldPost = { held: true, ...taken.exchange === void 0 ? {} : { exchange: taken.exchange } };
28185
+ this.log(`Chips held what ${room.record.name} said in ${room.spaceId} from the agents it named`);
28186
+ }
27989
28187
  }
27990
28188
  const cut2 = stop2 === "max_tokens" || stop2 === "max_turn_requests";
27991
28189
  const said = post.summary;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chipschat/acp",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
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
  "repository": {