@celljs/ta-agents 4.10.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/extension/index.mjs +166 -139
  2. package/package.json +1 -1
@@ -36,12 +36,136 @@ var Acp;
36
36
 
37
37
  // src/agent-bindings.ts
38
38
  import { realpathSync } from "node:fs";
39
- import { homedir } from "node:os";
40
- import { join, sep } from "node:path";
39
+ import { homedir as homedir2 } from "node:os";
40
+ import { join as join2, sep } from "node:path";
41
41
 
42
42
  // src/acp-agent.ts
43
43
  import { spawn } from "node:child_process";
44
44
 
45
+ // src/agent-catalog.ts
46
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
47
+ import { homedir } from "node:os";
48
+ import { delimiter, dirname, join } from "node:path";
49
+ var PRESETS = [
50
+ {
51
+ id: "codebuddy-code",
52
+ name: "CodeBuddy Code",
53
+ command: "cbc",
54
+ args: ["--acp"],
55
+ programs: ["cbc", "codebuddy"],
56
+ login: "cbc",
57
+ env: { CODEBUDDY_CODE_MODE_ENABLED: "1" },
58
+ clientMeta: { "codebuddy.ai": { mainAgentSupport: true, toolModeSupport: true } },
59
+ options: { mode: "fullAccess" },
60
+ processPerSession: true
61
+ },
62
+ {
63
+ id: "claude-code",
64
+ name: "Claude Code",
65
+ command: "npx",
66
+ args: ["-y", "@agentclientprotocol/claude-agent-acp@0.106.0"],
67
+ programs: ["claude"],
68
+ login: "claude"
69
+ },
70
+ { id: "codex", name: "Codex", command: "npx", args: ["-y", "@agentclientprotocol/codex-acp@2.6.0"], programs: ["codex"], login: "codex login" }
71
+ ];
72
+ var AgentCatalog;
73
+ ((AgentCatalog) => {
74
+ AgentCatalog.DEFAULT_MODEL = "default";
75
+ function agents(settings, find = Programs.find) {
76
+ const configured = settings && typeof settings === "object" ? settings : {};
77
+ const result = [];
78
+ for (const preset of PRESETS) {
79
+ const setting = configured[preset.id];
80
+ if (setting === false) {
81
+ continue;
82
+ }
83
+ const found = preset.programs.find((program) => find(program));
84
+ if (!found && !setting) {
85
+ continue;
86
+ }
87
+ const { programs, ...config } = preset;
88
+ const command = programs.includes(config.command) && found ? found : config.command;
89
+ const own = setting || {};
90
+ result.push({
91
+ ...config,
92
+ command,
93
+ ...own,
94
+ id: preset.id,
95
+ env: config.env || own.env ? { ...config.env, ...own.env } : undefined,
96
+ options: config.options || own.options ? { ...config.options, ...own.options } : undefined
97
+ });
98
+ }
99
+ for (const [id, setting] of Object.entries(configured)) {
100
+ if (setting && typeof setting === "object" && !PRESETS.some((preset) => preset.id === id) && typeof setting.command === "string") {
101
+ result.push({ name: id, args: [], ...setting, id, command: setting.command });
102
+ }
103
+ }
104
+ return result;
105
+ }
106
+ AgentCatalog.agents = agents;
107
+ })(AgentCatalog ||= {});
108
+ var Programs;
109
+ ((Programs) => {
110
+ function find(program, path = process.env.PATH) {
111
+ const extensions = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
112
+ for (const dir of (path ?? "").split(delimiter)) {
113
+ for (const extension of extensions) {
114
+ if (dir && isFile(join(dir, program + extension))) {
115
+ return program;
116
+ }
117
+ }
118
+ }
119
+ return;
120
+ }
121
+ Programs.find = find;
122
+ function isFile(path) {
123
+ try {
124
+ return statSync(path).isFile();
125
+ } catch {
126
+ return false;
127
+ }
128
+ }
129
+ })(Programs ||= {});
130
+
131
+ class ModelCache {
132
+ file;
133
+ entries;
134
+ constructor(file = ModelCache.defaultFile()) {
135
+ this.file = file;
136
+ }
137
+ get(id) {
138
+ return this.read()[id];
139
+ }
140
+ set(id, models) {
141
+ const entries = this.read();
142
+ if (JSON.stringify(entries[id]) === JSON.stringify(models)) {
143
+ return false;
144
+ }
145
+ entries[id] = models;
146
+ try {
147
+ mkdirSync(dirname(this.file), { recursive: true });
148
+ const temp = `${this.file}.${process.pid}.tmp`;
149
+ writeFileSync(temp, JSON.stringify(entries, undefined, 2));
150
+ renameSync(temp, this.file);
151
+ } catch {}
152
+ return true;
153
+ }
154
+ read() {
155
+ if (!this.entries) {
156
+ try {
157
+ this.entries = existsSync(this.file) ? JSON.parse(readFileSync(this.file, "utf8")) : {};
158
+ } catch {
159
+ this.entries = {};
160
+ }
161
+ }
162
+ return this.entries ?? {};
163
+ }
164
+ static defaultFile() {
165
+ return join(process.env.XDG_CACHE_HOME || join(homedir(), ".cache"), "ta-agents", "models.json");
166
+ }
167
+ }
168
+
45
169
  // src/agent-turn.ts
46
170
  var OUTPUT_CHARS = 8000;
47
171
  var WRITING_KINDS = new Set(["edit", "delete", "move"]);
@@ -361,6 +485,7 @@ class AgentSession {
361
485
  callbacks = { permission: async (request) => AgentSession.allow(request), activity: () => {
362
486
  return;
363
487
  } };
488
+ told = new Set;
364
489
  queued = [];
365
490
  quietTimer;
366
491
  abandoned;
@@ -718,6 +843,8 @@ function text(key, ...args) {
718
843
 
719
844
  // src/acp-agent.ts
720
845
  var STDERR_CHARS = 2000;
846
+ var LIFELINE = '(read _ <&3; kill $$) </dev/null >/dev/null 2>&1 & exec "$@" 3<&-';
847
+ var NOT_FOUND = 127;
721
848
  function agentEnv(extra) {
722
849
  const env = {};
723
850
  for (const [key, value] of Object.entries(process.env)) {
@@ -810,7 +937,7 @@ class AcpAgent {
810
937
  }
811
938
  reference(on) {
812
939
  const child = this.child;
813
- for (const handle of [child, child?.stdin, child?.stdout, child?.stderr]) {
940
+ for (const handle of [child, child?.stdin, child?.stdout, child?.stderr, child?.stdio[3]]) {
814
941
  if (on) {
815
942
  handle?.ref?.();
816
943
  } else {
@@ -837,13 +964,14 @@ class AcpAgent {
837
964
  async launch() {
838
965
  this.stop();
839
966
  this.stderr = "";
840
- const child = spawn(this.program.command, this.program.args, {
841
- cwd: this.program.cwd,
842
- env: agentEnv(this.program.env),
843
- stdio: ["pipe", "pipe", "pipe"],
844
- shell: process.platform === "win32",
845
- windowsHide: true
846
- });
967
+ const posix = process.platform !== "win32";
968
+ const { command, args, cwd } = this.program;
969
+ const env = agentEnv(this.program.env);
970
+ const notFound = () => new Error(text("notFound", this.name, command));
971
+ if (posix && !command.includes("/") && !Programs.find(command, env.PATH)) {
972
+ throw notFound();
973
+ }
974
+ const child = posix ? spawn("/bin/sh", ["-c", LIFELINE, "sh", command, ...args], { cwd, env, stdio: ["pipe", "pipe", "pipe", "pipe"] }) : spawn(command, args, { cwd, env, stdio: ["pipe", "pipe", "pipe"], shell: true, windowsHide: true });
847
975
  this.child = child;
848
976
  const { stdin, stdout } = child;
849
977
  if (!stdin || !stdout) {
@@ -853,8 +981,11 @@ class AcpAgent {
853
981
  this.connection = connection;
854
982
  child.stderr?.setEncoding("utf8");
855
983
  child.stderr?.on("data", (chunk) => this.stderr = (this.stderr + chunk).slice(-STDERR_CHARS));
856
- child.on("error", (error) => connection.close(error.code === "ENOENT" ? new Error(text("notFound", this.name, this.program.command)) : error));
857
- child.on("exit", (code) => connection.close(new Error(text("exited", this.name, String(code ?? "signal"), this.lastError()))));
984
+ child.on("error", (error) => connection.close(error.code === "ENOENT" ? notFound() : error));
985
+ child.on("exit", (code) => {
986
+ child.stdio[3]?.destroy();
987
+ connection.close(posix && code === NOT_FOUND ? notFound() : new Error(text("exited", this.name, String(code ?? "signal"), this.lastError())));
988
+ });
858
989
  connection.onNotification = (method, params) => this.notified(method, params);
859
990
  connection.onRequest = (method, params) => this.requested(method, params);
860
991
  connection.onClose = (error) => {
@@ -1042,132 +1173,8 @@ class AgentBindings {
1042
1173
  }
1043
1174
  }
1044
1175
  static isRemote(cwd) {
1045
- const agentDir = process.env.TA_CODING_AGENT_DIR ?? join(homedir(), ".ta", "agent");
1046
- return cwd.startsWith(join(agentDir, "remote") + sep);
1047
- }
1048
- }
1049
-
1050
- // src/agent-catalog.ts
1051
- import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
1052
- import { homedir as homedir2 } from "node:os";
1053
- import { delimiter, dirname, join as join2 } from "node:path";
1054
- var PRESETS = [
1055
- {
1056
- id: "codebuddy-code",
1057
- name: "CodeBuddy Code",
1058
- command: "cbc",
1059
- args: ["--acp"],
1060
- programs: ["cbc", "codebuddy"],
1061
- login: "cbc",
1062
- env: { CODEBUDDY_CODE_MODE_ENABLED: "1" },
1063
- clientMeta: { "codebuddy.ai": { mainAgentSupport: true, toolModeSupport: true } },
1064
- options: { mode: "fullAccess" },
1065
- processPerSession: true
1066
- },
1067
- {
1068
- id: "claude-code",
1069
- name: "Claude Code",
1070
- command: "npx",
1071
- args: ["-y", "@agentclientprotocol/claude-agent-acp@0.106.0"],
1072
- programs: ["claude"],
1073
- login: "claude"
1074
- },
1075
- { id: "codex", name: "Codex", command: "npx", args: ["-y", "@agentclientprotocol/codex-acp@2.6.0"], programs: ["codex"], login: "codex login" }
1076
- ];
1077
- var AgentCatalog;
1078
- ((AgentCatalog) => {
1079
- AgentCatalog.DEFAULT_MODEL = "default";
1080
- function agents(settings, find = Programs.find) {
1081
- const configured = settings && typeof settings === "object" ? settings : {};
1082
- const result = [];
1083
- for (const preset of PRESETS) {
1084
- const setting = configured[preset.id];
1085
- if (setting === false) {
1086
- continue;
1087
- }
1088
- const found = preset.programs.find((program) => find(program));
1089
- if (!found && !setting) {
1090
- continue;
1091
- }
1092
- const { programs, ...config } = preset;
1093
- const command = programs.includes(config.command) && found ? found : config.command;
1094
- const own = setting || {};
1095
- result.push({
1096
- ...config,
1097
- command,
1098
- ...own,
1099
- id: preset.id,
1100
- env: config.env || own.env ? { ...config.env, ...own.env } : undefined,
1101
- options: config.options || own.options ? { ...config.options, ...own.options } : undefined
1102
- });
1103
- }
1104
- for (const [id, setting] of Object.entries(configured)) {
1105
- if (setting && typeof setting === "object" && !PRESETS.some((preset) => preset.id === id) && typeof setting.command === "string") {
1106
- result.push({ name: id, args: [], ...setting, id, command: setting.command });
1107
- }
1108
- }
1109
- return result;
1110
- }
1111
- AgentCatalog.agents = agents;
1112
- })(AgentCatalog ||= {});
1113
- var Programs;
1114
- ((Programs) => {
1115
- function find(program) {
1116
- const extensions = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
1117
- for (const dir of (process.env.PATH ?? "").split(delimiter)) {
1118
- for (const extension of extensions) {
1119
- if (dir && isFile(join2(dir, program + extension))) {
1120
- return program;
1121
- }
1122
- }
1123
- }
1124
- return;
1125
- }
1126
- Programs.find = find;
1127
- function isFile(path) {
1128
- try {
1129
- return statSync(path).isFile();
1130
- } catch {
1131
- return false;
1132
- }
1133
- }
1134
- })(Programs ||= {});
1135
-
1136
- class ModelCache {
1137
- file;
1138
- entries;
1139
- constructor(file = ModelCache.defaultFile()) {
1140
- this.file = file;
1141
- }
1142
- get(id) {
1143
- return this.read()[id];
1144
- }
1145
- set(id, models) {
1146
- const entries = this.read();
1147
- if (JSON.stringify(entries[id]) === JSON.stringify(models)) {
1148
- return false;
1149
- }
1150
- entries[id] = models;
1151
- try {
1152
- mkdirSync(dirname(this.file), { recursive: true });
1153
- const temp = `${this.file}.${process.pid}.tmp`;
1154
- writeFileSync(temp, JSON.stringify(entries, undefined, 2));
1155
- renameSync(temp, this.file);
1156
- } catch {}
1157
- return true;
1158
- }
1159
- read() {
1160
- if (!this.entries) {
1161
- try {
1162
- this.entries = existsSync(this.file) ? JSON.parse(readFileSync(this.file, "utf8")) : {};
1163
- } catch {
1164
- this.entries = {};
1165
- }
1166
- }
1167
- return this.entries ?? {};
1168
- }
1169
- static defaultFile() {
1170
- return join2(process.env.XDG_CACHE_HOME || join2(homedir2(), ".cache"), "ta-agents", "models.json");
1176
+ const agentDir = process.env.TA_CODING_AGENT_DIR ?? join2(homedir2(), ".ta", "agent");
1177
+ return cwd.startsWith(join2(agentDir, "remote") + sep);
1171
1178
  }
1172
1179
  }
1173
1180
 
@@ -1239,6 +1246,17 @@ ${kept}
1239
1246
  </earlier_conversation>`;
1240
1247
  }
1241
1248
  AgentPrompt.transcript = transcript;
1249
+ function notes(messages) {
1250
+ const system = messages.filter((message) => message.role === "system").map((message) => [text2(message), ...sections(message)].join(`
1251
+ `)).join(`
1252
+ `);
1253
+ return [...system.matchAll(/<(ta-[\w-]+)>[\s\S]*?<\/\1>/g)].map((match) => match[0]);
1254
+ }
1255
+ AgentPrompt.notes = notes;
1256
+ function sections(message) {
1257
+ const parts = message.sections ?? {};
1258
+ return Object.values(parts).filter((part) => typeof part === "string");
1259
+ }
1242
1260
  function text2(message) {
1243
1261
  if (message.role === "user" || message.role === "system") {
1244
1262
  return typeof message.content === "string" ? message.content : message.content.map((part) => part.type === "text" ? part.text : "").join("");
@@ -1283,7 +1301,7 @@ var AgentTool;
1283
1301
  target = str2(input.url) ?? str2(input.query);
1284
1302
  break;
1285
1303
  }
1286
- target ??= str2(input.description);
1304
+ target ??= ["description", "subject", "skill", "image_path", "file_path", "path", "url", "query"].map((key) => str2(input[key])).find(Boolean);
1287
1305
  return { title, kind: run.kind, target: relative(target ?? title, cwd), ...run.name ? { tool: run.name } : {} };
1288
1306
  }
1289
1307
  AgentTool.args = args;
@@ -1499,6 +1517,15 @@ class AgentStreamer {
1499
1517
  if (earlier) {
1500
1518
  prompt = [{ type: "text", text: earlier }, ...prompt];
1501
1519
  }
1520
+ const notes = AgentPrompt.notes(context.messages).filter((note) => !session.told.has(note));
1521
+ if (notes.length) {
1522
+ for (const note of notes) {
1523
+ session.told.add(note);
1524
+ }
1525
+ prompt = [{ type: "text", text: notes.join(`
1526
+
1527
+ `) }, ...prompt];
1528
+ }
1502
1529
  await session.idle();
1503
1530
  await this.configure(session, model, options, signal);
1504
1531
  turn = session.prompt(prompt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-agents",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
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"