@celljs/ta-agents 4.9.0 → 4.9.1
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 +2 -2
- package/README.md +2 -2
- package/extension/index.mjs +50 -12
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -32,7 +32,7 @@ Pick one in the model list of the + on the left of the input box, an agent's mod
|
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Fields: `name`, `command`, `args`, `env`, `login` (the sign-in command to tell the user), `permissions`, `options` (the agent's settings of a new session, by the id or category of the option, such as `{ "mode": "default" }`), `clientMeta` (`_meta` of the client's capabilities in `initialize`). `env` and `options` of a built-in agent merge with those of the settings. `false` turns a built-in agent off. A built-in agent named in the settings is offered even when its program is not found, so it can run another one: the adapters read `CLAUDE_CODE_EXECUTABLE` (Claude Code's executable) and `CODEX_PATH` (the `codex` command), for example for wrappers built on the same code:
|
|
35
|
+
Fields: `name`, `command`, `args`, `env`, `login` (the sign-in command to tell the user), `permissions`, `options` (the agent's settings of a new session, by the id or category of the option, such as `{ "mode": "default" }`), `clientMeta` (`_meta` of the client's capabilities in `initialize`), `processPerSession` (a process for each pi session, for an agent whose process serves one session). `env` and `options` of a built-in agent merge with those of the settings. `false` turns a built-in agent off. A built-in agent named in the settings is offered even when its program is not found, so it can run another one: the adapters read `CLAUDE_CODE_EXECUTABLE` (Claude Code's executable) and `CODEX_PATH` (the `codex` command), for example for wrappers built on the same code:
|
|
36
36
|
|
|
37
37
|
```json
|
|
38
38
|
{
|
|
@@ -48,7 +48,7 @@ Fields: `name`, `command`, `args`, `env`, `login` (the sign-in command to tell t
|
|
|
48
48
|
- **A turn**: each time pi asks the model, only what the user said since the agent last answered goes to the agent (`session/prompt`), since the agent keeps its own history. The agent's text and thinking stream as pi's message.
|
|
49
49
|
- **Tool calls**: the agent uses its own tools; each call is recorded in pi as a call of `agent_tool` (its arguments are a title, a kind and a target, such as `{ kind: "execute", target: "npm test" }`), so Ta shows it as a line like its own tools, with the agent's output as the result. As soon as a call of kind edit, delete or move names the file it changes (`locations`, or `file_path` and the like in its arguments), or brings an ACP diff, the extension emits `ta:file-write` on `pi.events` (`{ path, before? }`, `TA_FILE_WRITE_EVENT` of ta-protocol), so that ta-changes keeps the file as it was before the agent writes it. When the agent starts a call, the assistant message ends (`toolUse`); pi "running" `agent_tool` only waits for the agent to finish the call, and pi's next request goes on with the same turn. some agents (CodeBuddy Code) stream the arguments first, so a call shows once the agent says they are complete (`toolArgumentsComplete` in `_meta`, or announcing the call again as `pending` with them); without such a sign, 1.5 seconds without news of the call, or the agent saying something else, will do; calls started together go in one message and show in parallel. `agent_tool` is active only while the model is an agent.
|
|
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
|
-
- **Processes**: the sessions of one agent in one directory share a process
|
|
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
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).
|
|
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.
|
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ CodeBuddy Code 和在它自己的终端里一样:用 PTC(代码模式,工
|
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
字段:`name`、`command`、`args`、`env`、`login`(提示用户执行的登录命令)、`permissions`、`options`(新会话的 Agent 设置,按选项的 id 或类别,如 `{ "mode": "default" }`)、`clientMeta`(`initialize` 里客户端能力的 `_meta
|
|
35
|
+
字段:`name`、`command`、`args`、`env`、`login`(提示用户执行的登录命令)、`permissions`、`options`(新会话的 Agent 设置,按选项的 id 或类别,如 `{ "mode": "default" }`)、`clientMeta`(`initialize` 里客户端能力的 `_meta`)、`processPerSession`(每个 pi 会话单独一个进程,用于一个进程只服务一个会话的 Agent)。内置 Agent 的 `env`、`options` 与设置里的合并。`false` 关掉一个内置 Agent。设置里写了某个内置 Agent,即使没找到它的程序也会提供,适合改用别的程序:适配器认环境变量 `CLAUDE_CODE_EXECUTABLE`(Claude Code 的可执行文件)和 `CODEX_PATH`(`codex` 命令),比如用同源的包装版:
|
|
36
36
|
|
|
37
37
|
```json
|
|
38
38
|
{
|
|
@@ -48,7 +48,7 @@ CodeBuddy Code 和在它自己的终端里一样:用 PTC(代码模式,工
|
|
|
48
48
|
- **一轮怎么走**:pi 每次请求模型时,只把用户自上次回答以来说的话发给 Agent(`session/prompt`),因为 Agent 自己保存历史。Agent 的文字和思考按流式转成 pi 的消息。
|
|
49
49
|
- **工具调用**:Agent 用自己的工具,每次调用在 pi 里记成一次 `agent_tool` 工具调用(参数是标题、种类和对象,例如 `{ kind: "execute", target: "npm test" }`),所以 Ta 显示成和自己的工具一样的一行,结果就是 Agent 工具的输出。种类是 edit、delete、move 的调用一说出要改的文件(`locations` 或参数里的 `file_path` 等),或者带来 ACP diff,扩展就经 `pi.events` 发 `ta:file-write`(`{ path, before? }`,见 ta-protocol 的 `TA_FILE_WRITE_EVENT`),让 ta-changes 在 Agent 动手前留下文件原样。具体做法:Agent 开始一次调用时,结束当前这条 assistant 消息(`toolUse`);pi “执行”`agent_tool` 时只是等 Agent 把这次调用做完;pi 下一次请求时接着流同一轮。有的 Agent(CodeBuddy Code)先流式发参数,等它说参数齐了(`_meta` 的 `toolArgumentsComplete`,或带着参数以 `pending` 再报一次这次调用)才显示;没有这类信号时,1.5 秒没有新消息或 Agent 开始说别的,也算齐了;同时开始的几次调用放进同一条消息,并行显示。`agent_tool` 只在当前模型是 Agent 时启用。
|
|
50
50
|
- **会话**:一个 pi 会话对一个 Agent 用一个 Agent 会话,它的 id 记在 pi 会话里(自定义条目 `ta-agents.session`),重新打开对话时用 `session/load` 接上。分叉,或在 pi 里回退到之前的消息(`/tree`),都会让下一轮新开一个 Agent 会话,并把到此为止的对话作为文字交给它;中途换到 Agent 时也一样(最多 3 万字)。
|
|
51
|
-
- **进程**:同一个 Agent
|
|
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
53
|
- **用户在 Agent 干活时说话**:ACP 没有“插话”,所以先存下,这一轮结束后马上作为下一轮发出。停止(中止)会发 `session/cancel`,下一轮会等 Agent 把被取消的这轮收尾(最多 5 秒)。
|
|
54
54
|
- **权限**:和 pi 一样默认不拦:Agent 请求权限时选“允许一次”。设置 `permissions: "ask"` 后,改为在界面上让用户选。Agent 自己的权限模式(例如 CodeBuddy Code 的配置)照常生效。
|
package/extension/index.mjs
CHANGED
|
@@ -657,7 +657,11 @@ class JsonRpcConnection {
|
|
|
657
657
|
}
|
|
658
658
|
}
|
|
659
659
|
} else if (message.id === undefined || message.id === null) {
|
|
660
|
-
|
|
660
|
+
try {
|
|
661
|
+
this.onNotification(message.method, message.params);
|
|
662
|
+
} catch (error) {
|
|
663
|
+
console.error(error);
|
|
664
|
+
}
|
|
661
665
|
} else {
|
|
662
666
|
this.answer(message.id, message.method, message.params);
|
|
663
667
|
}
|
|
@@ -905,11 +909,9 @@ var BINDING_ENTRY = "ta-agents.session";
|
|
|
905
909
|
var POOL = Symbol.for("ta-agents.pool");
|
|
906
910
|
var AgentPool;
|
|
907
911
|
((AgentPool) => {
|
|
908
|
-
function of(config, cwd) {
|
|
909
|
-
const
|
|
910
|
-
const
|
|
911
|
-
global[POOL] = pool;
|
|
912
|
-
const key = JSON.stringify([config.command, config.args, config.env ?? {}, config.clientMeta ?? {}, cwd]);
|
|
912
|
+
function of(config, cwd, owner) {
|
|
913
|
+
const pool = all();
|
|
914
|
+
const key = keyOf(config, cwd, owner);
|
|
913
915
|
let agent = pool.get(key);
|
|
914
916
|
if (!agent) {
|
|
915
917
|
agent = new AcpAgent(config.name, { command: config.command, args: config.args, env: config.env, clientMeta: config.clientMeta, cwd });
|
|
@@ -918,6 +920,25 @@ var AgentPool;
|
|
|
918
920
|
return agent;
|
|
919
921
|
}
|
|
920
922
|
AgentPool.of = of;
|
|
923
|
+
function release(config, cwd, owner) {
|
|
924
|
+
if (!config.processPerSession) {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
const pool = all();
|
|
928
|
+
const key = keyOf(config, cwd, owner);
|
|
929
|
+
pool.get(key)?.stop();
|
|
930
|
+
pool.delete(key);
|
|
931
|
+
}
|
|
932
|
+
AgentPool.release = release;
|
|
933
|
+
function keyOf(config, cwd, owner) {
|
|
934
|
+
return JSON.stringify([config.command, config.args, config.env ?? {}, config.clientMeta ?? {}, cwd, config.processPerSession ? owner ?? "" : ""]);
|
|
935
|
+
}
|
|
936
|
+
function all() {
|
|
937
|
+
const global = globalThis;
|
|
938
|
+
const pool = global[POOL] ?? create();
|
|
939
|
+
global[POOL] = pool;
|
|
940
|
+
return pool;
|
|
941
|
+
}
|
|
921
942
|
function create() {
|
|
922
943
|
const pool = new Map;
|
|
923
944
|
process.once("exit", () => {
|
|
@@ -933,13 +954,17 @@ class AgentBindings {
|
|
|
933
954
|
save;
|
|
934
955
|
prepare;
|
|
935
956
|
agentOf;
|
|
957
|
+
release;
|
|
936
958
|
cwd = process.cwd();
|
|
959
|
+
owner;
|
|
937
960
|
ids = new Map;
|
|
938
961
|
opened = new Map;
|
|
939
|
-
|
|
962
|
+
used = new Map;
|
|
963
|
+
constructor(save, prepare, agentOf = AgentPool.of, release = AgentPool.release) {
|
|
940
964
|
this.save = save;
|
|
941
965
|
this.prepare = prepare;
|
|
942
966
|
this.agentOf = agentOf;
|
|
967
|
+
this.release = release;
|
|
943
968
|
}
|
|
944
969
|
restore(entries, fork) {
|
|
945
970
|
this.ids.clear();
|
|
@@ -962,7 +987,8 @@ class AgentBindings {
|
|
|
962
987
|
return this.ids.get(agent);
|
|
963
988
|
}
|
|
964
989
|
open(config, signal) {
|
|
965
|
-
|
|
990
|
+
this.used.set(JSON.stringify([config.id, this.cwd, this.owner]), { config, cwd: this.cwd, owner: this.owner });
|
|
991
|
+
const agent = this.agentOf(config, this.cwd, this.owner);
|
|
966
992
|
let opened = this.opened.get(config.id);
|
|
967
993
|
if (opened) {
|
|
968
994
|
opened = opened.then((value) => agent.running && agent.sessions.get(value.session.id) === value.session ? { ...value, fresh: false } : this.connect(config, agent, signal));
|
|
@@ -975,6 +1001,10 @@ class AgentBindings {
|
|
|
975
1001
|
}
|
|
976
1002
|
close() {
|
|
977
1003
|
this.opened.clear();
|
|
1004
|
+
for (const { config, cwd, owner } of this.used.values()) {
|
|
1005
|
+
this.release(config, cwd, owner);
|
|
1006
|
+
}
|
|
1007
|
+
this.used.clear();
|
|
978
1008
|
}
|
|
979
1009
|
async connect(config, agent, signal) {
|
|
980
1010
|
if (AgentBindings.isRemote(this.cwd)) {
|
|
@@ -1024,7 +1054,8 @@ var PRESETS = [
|
|
|
1024
1054
|
login: "cbc",
|
|
1025
1055
|
env: { CODEBUDDY_CODE_MODE_ENABLED: "1" },
|
|
1026
1056
|
clientMeta: { "codebuddy.ai": { mainAgentSupport: true, toolModeSupport: true } },
|
|
1027
|
-
options: { mode: "fullAccess" }
|
|
1057
|
+
options: { mode: "fullAccess" },
|
|
1058
|
+
processPerSession: true
|
|
1028
1059
|
},
|
|
1029
1060
|
{
|
|
1030
1061
|
id: "claude-code",
|
|
@@ -1666,22 +1697,25 @@ function activate(pi, options = {}) {
|
|
|
1666
1697
|
return option ? { outcome: "selected", optionId: option.optionId } : { outcome: "cancelled" };
|
|
1667
1698
|
},
|
|
1668
1699
|
title: (title) => {
|
|
1669
|
-
if (!pi.getSessionName()) {
|
|
1700
|
+
if (context && !pi.getSessionName()) {
|
|
1670
1701
|
pi.setSessionName(title);
|
|
1671
1702
|
}
|
|
1672
1703
|
},
|
|
1673
1704
|
activity: () => {
|
|
1674
|
-
if (context
|
|
1705
|
+
if (context && context.model?.provider === config.id) {
|
|
1675
1706
|
pi.sendMessage({ customType: ACTIVITY_ENTRY, content: ACTIVITY_TEXT, display: false }, { triggerTurn: true });
|
|
1676
1707
|
}
|
|
1677
1708
|
},
|
|
1678
1709
|
write: (path, before) => {
|
|
1710
|
+
if (!context) {
|
|
1711
|
+
return;
|
|
1712
|
+
}
|
|
1679
1713
|
const file = { path: resolve(context?.cwd ?? bindings.cwd, path), ...before !== undefined ? { before } : {} };
|
|
1680
1714
|
pi.events.emit(TA_FILE_WRITE_EVENT, file);
|
|
1681
1715
|
}
|
|
1682
1716
|
};
|
|
1683
1717
|
learn(config, session);
|
|
1684
|
-
}, options.agentOf);
|
|
1718
|
+
}, options.agentOf, options.release);
|
|
1685
1719
|
const streamer = new AgentStreamer({
|
|
1686
1720
|
open: (config, signal) => bindings.open(config, signal),
|
|
1687
1721
|
calls,
|
|
@@ -1706,6 +1740,10 @@ function activate(pi, options = {}) {
|
|
|
1706
1740
|
}
|
|
1707
1741
|
sessionId = ctx.sessionManager.getSessionId();
|
|
1708
1742
|
Sessions.set(sessionId, self);
|
|
1743
|
+
if (bindings.owner !== sessionId) {
|
|
1744
|
+
bindings.close();
|
|
1745
|
+
bindings.owner = sessionId;
|
|
1746
|
+
}
|
|
1709
1747
|
bindings.cwd = ctx.cwd;
|
|
1710
1748
|
bindings.restore(ctx.sessionManager.getBranch(), event.reason === "fork");
|
|
1711
1749
|
const settings = pi.getSettings().agents;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-agents",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.1",
|
|
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"
|