@celljs/ta-agents 4.15.0 → 4.15.2

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.en.md CHANGED
@@ -14,7 +14,7 @@ The agents are reached over the [Agent Client Protocol](https://agentclientproto
14
14
  | Claude Code | `claude` is installed | `npx -y @agentclientprotocol/claude-agent-acp` (the ACP project's adapter, with Claude Code's own login) |
15
15
  | Codex | `codex` is installed | `npx -y @agentclientprotocol/codex-acp` (likewise, with Codex's own login) |
16
16
 
17
- CodeBuddy Code works as in its own terminal: in PTC (code mode, its tools called through REPL; it declares `mainAgentSupport` / `toolModeSupport` and sets `CODEBUDDY_CODE_MODE_ENABLED=1`, without which ACP clients get the standard mode only), and a new session has full access (`options.mode`, which the settings change). npx fetches an adapter the first time it is used; the versions are pinned in the package. Each agent keeps its own login: when it is not signed in, the conversation says which command to run in a terminal (`cbc`, `claude`, `codex login`).
17
+ CodeBuddy Code works as in its own terminal: in PTC (code mode, its tools called through REPL; it declares `mainAgentSupport` / `toolModeSupport` and sets `CODEBUDDY_CODE_MODE_ENABLED=1`, without which ACP clients get the standard mode only), and a new session has full access (`options.mode`, which the settings change). npx fetches an adapter the first time it is used; the versions are pinned in the package. Each agent keeps its own login. When it offers ways to sign in over ACP (CodeBuddy Code), a message sent while it is signed out asks first which way to sign in with; the agent opens its page in the browser of this computer, a notice of Ta Web has an Open button for it (for a phone or another device), and the turn goes on once signed in. Otherwise, or without a UI (`pi -p`), the conversation says which command to run in a terminal (`cbc`, `claude`, `codex login`).
18
18
 
19
19
  ## Use
20
20
 
@@ -50,7 +50,7 @@ Fields: `name`, `command`, `args`, `env`, `login` (the sign-in command to tell t
50
50
  - **Sessions**: a pi session uses one session of each agent; its id is kept in the pi session (the custom entry `ta-agents.session`), and reopening the conversation loads it again (`session/load`). A fork, or going back to an earlier message in pi (`/tree`), starts a new session of the agent on the next turn and hands it the conversation so far as text; so does switching to an agent in the middle of a conversation (30,000 characters at most).
51
51
  - **Processes**: the sessions of one agent in one directory share a process; by directory, because CodeBuddy Code runs commands where it was started rather than in the directory of the session. CodeBuddy Code itself runs a process for each conversation (about 650 MB), stopped when the conversation closes: a process of it answers only the session it opened or loaded last, and a prompt of another one waits forever, or ends at once with nothing while that one works. A process stops after 10 minutes without a turn, and starts again, loading its sessions, when it is needed. It keeps pi's process alive only while a request waits for its answer, so `pi -p` exits once it answered.
52
52
  - **When the agent goes on by itself**: after a background task, an agent may start a turn on its own (CodeBuddy Code starts it with `unsolicitedTurn` in a `session_info_update` and ends it with `session_end`; other agents give no end, and the turn ends after 3 quiet seconds). The extension sends pi a message that is not shown, which starts a pi turn that shows it.
53
- - **When the user talks while the agent works**: ACP has no way to steer a turn, so it is kept and sent as the next turn as soon as this one ends. Stopping sends `session/cancel`; the next turn waits for the agent to end the cancelled one (5 seconds at most).
53
+ - **When the user talks while the agent works**: once pi gives it to the turn, the extension puts it into the turn the agent runs with `session/steer` (an extension method of CodeBuddy Code), which the agent reads before it asks its model again. To an agent without it (`-32601`), it is kept and sent as the next turn as soon as this one ends; what is kept is named in a `ta-agents.queued` entry of the session, so that after a restart of Ta the next turn sends it first. Stopping sends `session/cancel`; the next turn waits for the agent to end the cancelled one (5 seconds at most).
54
54
  - **Permissions**: as in pi, nothing is held back: a permission request of the agent is answered "allow once". With `permissions: "ask"` the user picks in the UI. The agent's own permission mode (CodeBuddy Code's settings, for example) still applies.
55
55
  - **Compaction**: the agent manages its context. pi's automatic compaction is cancelled for conversations with an agent; compacting by hand (Compact in the + menu, or `/compact`) sends `/compact` to the agent, which compacts with its own command.
56
56
  - **Title**: when the agent names its session (`session_info_update`) and the conversation has no name yet, it becomes the conversation's name, also when the title comes late.
package/README.md CHANGED
@@ -14,7 +14,7 @@ pi install npm:@celljs/ta-agents
14
14
  | Claude Code | 装了 `claude` | `npx -y @agentclientprotocol/claude-agent-acp`(ACP 官方适配器,用 Claude Code 自己的登录) |
15
15
  | Codex | 装了 `codex` | `npx -y @agentclientprotocol/codex-acp`(同上,用 Codex 自己的登录) |
16
16
 
17
- CodeBuddy Code 和在它自己的终端里一样:用 PTC(代码模式,工具都经 REPL 调用;启动时声明 `mainAgentSupport` / `toolModeSupport` 并设 `CODEBUDDY_CODE_MODE_ENABLED=1`,不声明的 ACP 客户端只能用标准模式),新会话的权限模式是 Full Access(`options.mode`,可在设置里改)。适配器第一次用到时由 npx 下载,版本固定在包里。登录由各 Agent 自己管:没登录时,对话里会提示要在终端执行的命令(`cbc`、`claude`、`codex login`)。
17
+ CodeBuddy Code 和在它自己的终端里一样:用 PTC(代码模式,工具都经 REPL 调用;启动时声明 `mainAgentSupport` / `toolModeSupport` 并设 `CODEBUDDY_CODE_MODE_ENABLED=1`,不声明的 ACP 客户端只能用标准模式),新会话的权限模式是 Full Access(`options.mode`,可在设置里改)。适配器第一次用到时由 npx 下载,版本固定在包里。登录由各 Agent 自己管。Agent 在 ACP 里提供登录方式时(CodeBuddy Code),没登录就发消息会先问用哪种方式登录,Agent 在这台电脑的浏览器里打开登录页,Ta Web 的通知里也有“打开”按钮(给手机等别的设备用),登录好这一轮接着做;不提供、或没有界面(`pi -p`)时,对话里提示要在终端执行的命令(`cbc`、`claude`、`codex login`)。
18
18
 
19
19
  ## 用法
20
20
 
@@ -50,7 +50,7 @@ CodeBuddy Code 和在它自己的终端里一样:用 PTC(代码模式,工
50
50
  - **会话**:一个 pi 会话对一个 Agent 用一个 Agent 会话,它的 id 记在 pi 会话里(自定义条目 `ta-agents.session`),重新打开对话时用 `session/load` 接上。分叉,或在 pi 里回退到之前的消息(`/tree`),都会让下一轮新开一个 Agent 会话,并把到此为止的对话作为文字交给它;中途换到 Agent 时也一样(最多 3 万字)。
51
51
  - **进程**:同一个 Agent 在同一个目录下的所有会话共用一个进程;按目录分开,是因为 CodeBuddy Code 在启动目录里执行命令,不看会话的目录。CodeBuddy Code 例外,每个对话单独一个进程(约 650 MB),对话关闭时停掉:它的一个进程只回答最后新建或加载的会话,其他会话发消息会一直等不到回复,或在那个会话忙时立刻空着结束。10 分钟没有任何一轮就停掉进程,下次用时再启动并加载会话。只在有请求等待回复时保持 pi 进程不退出,所以 `pi -p` 回答完就退出。
52
52
  - **Agent 自己继续时**:后台任务结束后,Agent 可能自己开始一轮(CodeBuddy Code 用 `session_info_update` 的 `unsolicitedTurn` 开始、`session_end` 收尾;其他 Agent 没有明确的结束标志,就在 3 秒没有消息后收尾)。扩展发一条不显示的消息让 pi 开一轮,把这一轮显示出来。
53
- - **用户在 Agent 干活时说话**:ACP 没有“插话”,所以先存下,这一轮结束后马上作为下一轮发出。停止(中止)会发 `session/cancel`,下一轮会等 Agent 把被取消的这轮收尾(最多 5 秒)。
53
+ - **用户在 Agent 干活时说话**:pi 把插话交给这一轮后,扩展用 `session/steer`(CodeBuddy Code 的扩展方法)把它放进 Agent 正在跑的这一轮,Agent 下次请求模型前就会读到。不支持它的 Agent(回 `-32601`)就先存下,这一轮结束后马上作为下一轮发出;存着的消息记在会话的 `ta-agents.queued` 条目里,Ta 中途重启后,下一轮会先补发它们。停止(中止)会发 `session/cancel`,下一轮会等 Agent 把被取消的这轮收尾(最多 5 秒)。
54
54
  - **权限**:和 pi 一样默认不拦:Agent 请求权限时选“允许一次”。设置 `permissions: "ask"` 后,改为在界面上让用户选。Agent 自己的权限模式(例如 CodeBuddy Code 的配置)照常生效。
55
55
  - **压缩**:Agent 自己管理上下文。pi 的自动压缩对 Agent 对话一律取消;手动压缩(+ 菜单里的“压缩”或 `/compact`)改为把 `/compact` 发给 Agent,由它用自己的命令压缩。
56
56
  - **标题**:Agent 给会话起了标题(`session_info_update`)而对话还没有名字时,用它作对话名,标题晚到也会补上。
@@ -8,6 +8,8 @@ var Acp;
8
8
  ((Acp) => {
9
9
  Acp.PROTOCOL_VERSION = 1;
10
10
  Acp.AUTH_REQUIRED = -32000;
11
+ Acp.METHOD_NOT_FOUND = -32601;
12
+ Acp.AUTH_URL = "_codebuddy.ai/authUrl";
11
13
  function text(block) {
12
14
  if (Array.isArray(block)) {
13
15
  return block.map((item) => text(item)).join("");
@@ -533,6 +535,8 @@ class AgentSession {
533
535
  told = new Set;
534
536
  context;
535
537
  queued = [];
538
+ queuedAt = [];
539
+ steers = true;
536
540
  quietTimer;
537
541
  abandoned;
538
542
  answer;
@@ -636,13 +640,31 @@ class AgentSession {
636
640
  this.answer = answer;
637
641
  return turn;
638
642
  }
639
- queue(prompt) {
643
+ async steer(prompt) {
644
+ if (!this.steers || !this.turn) {
645
+ return false;
646
+ }
647
+ try {
648
+ const answer = await this.host.request("session/steer", { sessionId: this.id, contentBlocks: prompt });
649
+ return answer?.steered === true;
650
+ } catch (error) {
651
+ if (error.code === Acp.METHOD_NOT_FOUND) {
652
+ this.steers = false;
653
+ }
654
+ return false;
655
+ }
656
+ }
657
+ queue(prompt, at = []) {
640
658
  this.queued.push(prompt);
659
+ this.queuedAt.push(...at);
660
+ this.callbacks.queued?.([...this.queuedAt]);
641
661
  }
642
662
  takeQueued() {
643
663
  if (!this.queued.length) {
644
664
  return;
645
665
  }
666
+ this.queuedAt = [];
667
+ this.callbacks.queued?.([]);
646
668
  return this.queued.splice(0).flat();
647
669
  }
648
670
  abandon(turn) {
@@ -976,6 +998,9 @@ class JsonRpcConnection {
976
998
  }
977
999
 
978
1000
  // src/texts.ts
1001
+ function spaced(word) {
1002
+ return /^[\x20-\x7e]+$/.test(word) ? ` ${word} ` : word;
1003
+ }
979
1004
  var TEXTS = {
980
1005
  remote: {
981
1006
  "en-US": (agent) => `${agent} works in directories of this computer; it cannot work in a remote directory yet.`,
@@ -989,6 +1014,48 @@ var TEXTS = {
989
1014
  "zh-TW": (agent, command) => `${agent} 還沒有登入。請在終端機裡執行 \`${command}\` 登入後再試。`,
990
1015
  "ja-JP": (agent, command) => `${agent} はサインインしていません。ターミナルで \`${command}\` を実行してサインインしてから、もう一度試してください。`
991
1016
  },
1017
+ signInPick: {
1018
+ "en-US": (agent) => `${agent} is not signed in yet. Sign in to go on:`,
1019
+ "zh-CN": (agent) => `${agent} 还没有登录,登录后接着做:`,
1020
+ "zh-TW": (agent) => `${agent} 還沒有登入,登入後接著做:`,
1021
+ "ja-JP": (agent) => `${agent} はまだサインインしていません。サインインして続けます:`
1022
+ },
1023
+ signInWith: {
1024
+ "en-US": (way) => `Sign in with ${way}`,
1025
+ "zh-CN": (way) => `用${spaced(way)}登录`,
1026
+ "zh-TW": (way) => `用${spaced(way)}登入`,
1027
+ "ja-JP": (way) => `${way} でサインイン`
1028
+ },
1029
+ signInMethod: {
1030
+ "en-US": (id) => ({ iOA: "iOA", external: "Google / GitHub", internal: "WeChat", selfhosted: "an enterprise domain" })[id] ?? "",
1031
+ "zh-CN": (id) => ({ iOA: "iOA", external: "Google / GitHub", internal: "微信", selfhosted: "企业域名" })[id] ?? "",
1032
+ "zh-TW": (id) => ({ iOA: "iOA", external: "Google / GitHub", internal: "微信", selfhosted: "企業網域" })[id] ?? "",
1033
+ "ja-JP": (id) => ({ iOA: "iOA", external: "Google / GitHub", internal: "WeChat", selfhosted: "企業ドメイン" })[id] ?? ""
1034
+ },
1035
+ signingIn: {
1036
+ "en-US": (agent) => `Waiting for you to sign in to ${agent} in the browser…`,
1037
+ "zh-CN": (agent) => `等你在浏览器里登录 ${agent}…`,
1038
+ "zh-TW": (agent) => `等你在瀏覽器裡登入 ${agent}…`,
1039
+ "ja-JP": (agent) => `ブラウザで ${agent} にサインインするのを待っています…`
1040
+ },
1041
+ signInPage: {
1042
+ "en-US": (agent, url) => `Sign in to ${agent} in the browser: ${url}`,
1043
+ "zh-CN": (agent, url) => `在浏览器里登录 ${agent}:${url}`,
1044
+ "zh-TW": (agent, url) => `在瀏覽器裡登入 ${agent}:${url}`,
1045
+ "ja-JP": (agent, url) => `ブラウザで ${agent} にサインインしてください:${url}`
1046
+ },
1047
+ signInFailed: {
1048
+ "en-US": (agent) => `Could not sign in to ${agent}.`,
1049
+ "zh-CN": (agent) => `没能登录 ${agent}。`,
1050
+ "zh-TW": (agent) => `沒能登入 ${agent}。`,
1051
+ "ja-JP": (agent) => `${agent} にサインインできませんでした。`
1052
+ },
1053
+ signedIn: {
1054
+ "en-US": (agent) => `Signed in to ${agent}`,
1055
+ "zh-CN": (agent) => `已登录 ${agent}`,
1056
+ "zh-TW": (agent) => `已登入 ${agent}`,
1057
+ "ja-JP": (agent) => `${agent} にサインインしました`
1058
+ },
992
1059
  notFound: {
993
1060
  "en-US": (agent, command) => `${agent}: \`${command}\` was not found. Install it, or set its command in \`agents\` of settings.json.`,
994
1061
  "zh-CN": (agent, command) => `${agent}:找不到命令 \`${command}\`。请先安装,或在 settings.json 的 \`agents\` 里指定它的命令。`,
@@ -1080,6 +1147,7 @@ class AcpAgent {
1080
1147
  starting;
1081
1148
  stderr = "";
1082
1149
  idleTimer;
1150
+ signInPage;
1083
1151
  constructor(name, program, idleMs = 10 * 60000) {
1084
1152
  this.name = name;
1085
1153
  this.program = program;
@@ -1123,6 +1191,15 @@ class AcpAgent {
1123
1191
  throw error;
1124
1192
  }
1125
1193
  }
1194
+ async authenticate(methodId, page, signal) {
1195
+ await this.start();
1196
+ this.signInPage = page;
1197
+ try {
1198
+ await this.request("authenticate", { methodId }, signal);
1199
+ } finally {
1200
+ this.signInPage = undefined;
1201
+ }
1202
+ }
1126
1203
  request(method, params, signal) {
1127
1204
  this.touch();
1128
1205
  if (!this.connection || this.connection.isClosed) {
@@ -1223,6 +1300,13 @@ class AcpAgent {
1223
1300
  }
1224
1301
  notified(method, params) {
1225
1302
  this.touch();
1303
+ if (method === Acp.AUTH_URL) {
1304
+ const url = params?.authUrl;
1305
+ if (typeof url === "string" && /^https?:\/\//.test(url)) {
1306
+ this.signInPage?.(url);
1307
+ }
1308
+ return;
1309
+ }
1226
1310
  if (method !== "session/update") {
1227
1311
  return;
1228
1312
  }
@@ -1255,6 +1339,7 @@ class AcpAgent {
1255
1339
 
1256
1340
  // src/agent-bindings.ts
1257
1341
  var BINDING_ENTRY = "ta-agents.session";
1342
+ var QUEUE_ENTRY = "ta-agents.queued";
1258
1343
  var POOL = Symbol.for("ta-agents.pool");
1259
1344
  var AgentPool;
1260
1345
  ((AgentPool) => {
@@ -1307,6 +1392,7 @@ class AgentBindings {
1307
1392
  cwd = process.cwd();
1308
1393
  owner;
1309
1394
  ids = new Map;
1395
+ waiting = new Map;
1310
1396
  opened = new Map;
1311
1397
  used = new Map;
1312
1398
  constructor(save, prepare, agentOf = AgentPool.of, release = AgentPool.release) {
@@ -1318,23 +1404,33 @@ class AgentBindings {
1318
1404
  restore(entries, fork) {
1319
1405
  this.ids.clear();
1320
1406
  this.opened.clear();
1407
+ this.waiting.clear();
1321
1408
  if (fork) {
1322
1409
  return;
1323
1410
  }
1324
1411
  for (const entry of entries) {
1325
1412
  const { type, customType, data } = entry ?? {};
1326
- if (type === "custom" && customType === BINDING_ENTRY && typeof data?.agent === "string" && typeof data.session === "string") {
1413
+ if (type !== "custom" || typeof data?.agent !== "string" || typeof data.session !== "string") {
1414
+ continue;
1415
+ }
1416
+ if (customType === BINDING_ENTRY) {
1327
1417
  this.ids.set(data.agent, data.session);
1418
+ } else if (customType === QUEUE_ENTRY && Array.isArray(data.at)) {
1419
+ this.waiting.set(data.agent, { agent: data.agent, session: data.session, at: data.at.filter((at) => typeof at === "number") });
1328
1420
  }
1329
1421
  }
1330
1422
  }
1331
1423
  forget() {
1332
1424
  this.ids.clear();
1333
1425
  this.opened.clear();
1426
+ this.waiting.clear();
1334
1427
  }
1335
1428
  sessionId(agent) {
1336
1429
  return this.ids.get(agent);
1337
1430
  }
1431
+ agent(config) {
1432
+ return this.agentOf(config, this.cwd, this.owner);
1433
+ }
1338
1434
  ready(config) {
1339
1435
  return this.opened.has(config.id) && this.agentOf(config, this.cwd, this.owner).running;
1340
1436
  }
@@ -1343,7 +1439,7 @@ class AgentBindings {
1343
1439
  const agent = this.agentOf(config, this.cwd, this.owner);
1344
1440
  let opened = this.opened.get(config.id);
1345
1441
  if (opened) {
1346
- opened = opened.then((value) => agent.running && agent.sessions.get(value.session.id) === value.session ? { ...value, fresh: false } : this.connect(config, agent, signal));
1442
+ opened = opened.then((value) => agent.running && agent.sessions.get(value.session.id) === value.session ? { ...value, fresh: false, missed: undefined } : this.connect(config, agent, signal));
1347
1443
  } else {
1348
1444
  opened = this.connect(config, agent, signal);
1349
1445
  }
@@ -1376,7 +1472,10 @@ class AgentBindings {
1376
1472
  this.save({ agent: config.id, session: session.id });
1377
1473
  }
1378
1474
  this.prepare(config, session);
1379
- return { session, fresh, images: !!agent.initialized?.agentCapabilities?.promptCapabilities?.image, dirs: AgentBindings.dirs(this.cwd) };
1475
+ const waiting = this.waiting.get(config.id);
1476
+ this.waiting.delete(config.id);
1477
+ const missed = waiting?.session === session.id && waiting.at.length ? waiting.at : undefined;
1478
+ return { session, fresh, images: !!agent.initialized?.agentCapabilities?.promptCapabilities?.image, dirs: AgentBindings.dirs(this.cwd), missed };
1380
1479
  }
1381
1480
  static dirs(cwd) {
1382
1481
  try {
@@ -1414,6 +1513,10 @@ var AgentPrompt;
1414
1513
  return result;
1415
1514
  }
1416
1515
  AgentPrompt.pending = pending;
1516
+ function written(messages, at) {
1517
+ return messages.filter((message) => message.role === "user" && at.includes(message.timestamp ?? -1));
1518
+ }
1519
+ AgentPrompt.written = written;
1417
1520
  function resume(error) {
1418
1521
  return `Your last turn stopped with an error before it finished: ${error}
1419
1522
  Continue where you left off.`;
@@ -1488,6 +1591,55 @@ ${kept}
1488
1591
  AgentPrompt.text = text2;
1489
1592
  })(AgentPrompt ||= {});
1490
1593
 
1594
+ // src/agent-sign-in.ts
1595
+ class AgentSignIn {
1596
+ config;
1597
+ agent;
1598
+ ui;
1599
+ constructor(config, agent, ui) {
1600
+ this.config = config;
1601
+ this.agent = agent;
1602
+ this.ui = ui;
1603
+ }
1604
+ static required(error) {
1605
+ return error?.code === Acp.AUTH_REQUIRED;
1606
+ }
1607
+ static label(method) {
1608
+ const known = text("signInMethod", method.id);
1609
+ if (known) {
1610
+ return text("signInWith", known);
1611
+ }
1612
+ const named = /^(?:log ?in|sign ?in) (?:with|via) (.+)$/i.exec(method.name.trim());
1613
+ return named ? text("signInWith", named[1]) : method.name;
1614
+ }
1615
+ async run(signal) {
1616
+ const methods = this.agent.initialized?.authMethods ?? [];
1617
+ if (!methods.length) {
1618
+ return false;
1619
+ }
1620
+ const labels = methods.map((method2) => AgentSignIn.label(method2));
1621
+ const chosen = await this.ui.select(text("signInPick", this.config.name), labels, { signal });
1622
+ const method = chosen === undefined ? undefined : methods[labels.indexOf(chosen)];
1623
+ if (!method || signal?.aborted) {
1624
+ return false;
1625
+ }
1626
+ this.ui.setWorkingMessage(text("signingIn", this.config.name));
1627
+ try {
1628
+ await this.agent.authenticate(method.id, (url) => this.ui.notify(text("signInPage", this.config.name, url)), signal);
1629
+ } catch (error) {
1630
+ if (signal?.aborted) {
1631
+ throw error;
1632
+ }
1633
+ this.ui.notify(text("signInFailed", this.config.name), "warning");
1634
+ return false;
1635
+ } finally {
1636
+ this.ui.setWorkingMessage();
1637
+ }
1638
+ this.ui.notify(text("signedIn", this.config.name));
1639
+ return true;
1640
+ }
1641
+ }
1642
+
1491
1643
  // src/agent-tool.ts
1492
1644
  var INPUT_CHARS = 8000;
1493
1645
  function relative(path, dirs) {
@@ -1755,17 +1907,41 @@ class AgentStreamer {
1755
1907
  }
1756
1908
  async run(config, model, context, options, builder) {
1757
1909
  const signal = options?.signal;
1758
- const { session, fresh, images, dirs } = await this.host.open(config, signal);
1910
+ let signedIn = false;
1911
+ const signIn = async (error) => {
1912
+ if (signedIn || !AgentSignIn.required(error) || !await this.host.signIn?.(config, signal)) {
1913
+ return false;
1914
+ }
1915
+ signedIn = true;
1916
+ return true;
1917
+ };
1918
+ const { session, fresh, images, dirs, missed } = await this.host.open(config, signal).catch(async (error) => {
1919
+ if (await signIn(error)) {
1920
+ return this.host.open(config, signal);
1921
+ }
1922
+ throw error;
1923
+ });
1759
1924
  let pending = AgentPrompt.pending(context.messages);
1760
1925
  if (session.failure !== undefined) {
1761
1926
  pending = pending.filter((message) => !(message.timestamp <= session.delivered));
1762
1927
  }
1763
1928
  let turn = session.turn;
1929
+ let sent;
1764
1930
  if (turn) {
1765
1931
  if (pending.length) {
1766
- session.queue(AgentPrompt.blocks(pending, images));
1932
+ const blocks = AgentPrompt.blocks(pending, images);
1933
+ const at = pending.map((message) => message.timestamp ?? 0);
1934
+ if (await session.steer(blocks)) {
1935
+ session.delivered = Math.max(session.delivered, ...at);
1936
+ } else {
1937
+ session.queue(blocks, at);
1938
+ }
1767
1939
  }
1768
1940
  } else {
1941
+ if (missed?.length) {
1942
+ pending = [...AgentPrompt.written(context.messages, missed).filter((message) => !pending.includes(message)), ...pending];
1943
+ session.callbacks.queued?.([]);
1944
+ }
1769
1945
  let prompt = pending.length ? AgentPrompt.blocks(pending, images) : session.takeQueued();
1770
1946
  if (!prompt?.length && session.failure !== undefined) {
1771
1947
  prompt = [{ type: "text", text: AgentPrompt.resume(session.failure) }];
@@ -1791,6 +1967,7 @@ class AgentStreamer {
1791
1967
  await session.idle();
1792
1968
  await this.configure(session, model, options, signal);
1793
1969
  turn = session.prompt(prompt);
1970
+ sent = prompt;
1794
1971
  }
1795
1972
  for (;; ) {
1796
1973
  const item = await turn.next(signal);
@@ -1813,6 +1990,7 @@ class AgentStreamer {
1813
1990
  const queued = session.takeQueued();
1814
1991
  if (queued) {
1815
1992
  turn = session.prompt(queued);
1993
+ sent = queued;
1816
1994
  break;
1817
1995
  }
1818
1996
  if (item.reason === "cancelled" && signal?.aborted) {
@@ -1830,6 +2008,10 @@ class AgentStreamer {
1830
2008
  }
1831
2009
  case "error":
1832
2010
  session.finished(turn);
2011
+ if (sent && !turn.produced && await signIn(item)) {
2012
+ turn = session.prompt(sent);
2013
+ break;
2014
+ }
1833
2015
  session.failure = AgentStreamer.describe(config, item);
1834
2016
  builder.error("error", session.failure);
1835
2017
  return;
@@ -2016,6 +2198,12 @@ function activate(pi, options = {}) {
2016
2198
  }
2017
2199
  const file = { path: resolve(context?.cwd ?? bindings.cwd, path), ...before !== undefined ? { before } : {} };
2018
2200
  pi.events.emit(TA_FILE_WRITE_EVENT, file);
2201
+ },
2202
+ queued: (at) => {
2203
+ if (context) {
2204
+ const entry = { agent: config.id, session: session.id, at };
2205
+ pi.appendEntry(QUEUE_ENTRY, entry);
2206
+ }
2019
2207
  }
2020
2208
  };
2021
2209
  learn(config, session);
@@ -2034,6 +2222,10 @@ function activate(pi, options = {}) {
2034
2222
  }
2035
2223
  },
2036
2224
  calls,
2225
+ signIn: (config, signal) => {
2226
+ const ui = context?.hasUI ? context.ui : undefined;
2227
+ return ui ? new AgentSignIn(config, bindings.agent(config), ui).run(signal) : Promise.resolve(false);
2228
+ },
2037
2229
  ended: (config, session) => {
2038
2230
  if (session.title && !pi.getSessionName()) {
2039
2231
  pi.setSessionName(session.title);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-agents",
3
- "version": "4.15.0",
3
+ "version": "4.15.2",
4
4
  "description": "A pi package for Ta: other coding agents (CodeBuddy Code, Claude Code, Codex and any agent that speaks ACP) as models to pick, each running a conversation on its own harness",
5
5
  "keywords": [
6
6
  "pi-package"