@coda-console/grok 1.7.0 → 1.8.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.
- package/README.md +2 -0
- package/agent/entry.mjs +12 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,4 +4,6 @@ Grok Agent:适配运行机上 Grok CLI 的 ACP 与审批模式;资源页的
|
|
|
4
4
|
|
|
5
5
|
不声明 `systemPrompt`;会话指令由 Coda 后端在新会话第一次非斜杠命令的用户输入前送入单独的文本块,恢复会话不再送,插件不用处理。
|
|
6
6
|
|
|
7
|
+
压缩上下文(自动,或用户的 `/compact`):入口把 Grok 的 `_x.ai/session_notification` 里的 `auto_compact_started`、`auto_compact_completed`、`auto_compact_failed`、`auto_compact_cancelled`(只取主会话的)原样转发后,另按 ACP `compaction_update` 报给 Coda:开始 `in_progress`,完成 `completed`,同一次压缩用同一个 `compactionId`;`/compact` 不报开始,只报完成。失败、取消两条在 Grok 1.0.77 上只在二进制里见到名字,没有实测,按 `failed` 报。
|
|
8
|
+
|
|
7
9
|
入口声明 ACP 的 `session/delete`:Grok 原生没有,入口自己拦下,改跑官方命令 `grok sessions delete <id>`(15 秒超时)。命令对不存在的会话也退出 0,所以以它的输出为准:`Deleted session` 回 `{}`,`No session found` 回 -32002,其他回 -32603 并带原因。会话还开在 Grok 里时可以直接删,之后 `session/close` 和结束进程都不会把它写回来(1.0.77 实测)。这样 Coda 探测模型和模式留下的空会话能被清掉;`sessions delete` 核对于 1.0.77,更旧的 CLI 没有它时回错误,不抬高最低版本(审批模式通知只核对过 1.0.52)。
|
package/agent/entry.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// Grok (checked on 1.0.52) reports no ACP modes. Translate set_mode to the notification its own UI sends; everything else passes
|
|
2
2
|
// through. No selected mode (the empty currentModeId) leaves the machine's configuration in charge, as before.
|
|
3
3
|
// Grok's questions are asked of Coda as ACP forms (questions.mjs). Grok gives one up (its timeout, a cancelled turn)
|
|
4
|
-
// by ending the tool call alone, so that end withdraws the form.
|
|
4
|
+
// by ending the tool call alone, so that end withdraws the form. Its context compactions, auto or a /compact of the user's, are
|
|
5
|
+
// told as `_x.ai/session_notification` updates, which are also told to Coda as `compaction_update` (docs/agent-protocol.md).
|
|
5
6
|
// Grok's ACP has no session/delete, so the entry declares it and answers it with `grok sessions delete`
|
|
6
7
|
// (delete.mjs; checked on 1.0.77): Coda's probes (session/new, then gone) leave no empty sessions in Grok's history.
|
|
7
8
|
import { spawn } from 'node:child_process';
|
|
9
|
+
import { randomUUID } from 'node:crypto';
|
|
8
10
|
import { grokBinary } from '../scripts/ask.mjs';
|
|
9
11
|
import { deleteSession } from './delete.mjs';
|
|
10
12
|
import { ASK, questionForm } from './questions.mjs';
|
|
@@ -16,6 +18,9 @@ const grok = spawn(binary, ['agent', '--no-leader', 'stdio'], { stdio: ['pipe',
|
|
|
16
18
|
const send = (stream, message) => stream.write(`${JSON.stringify(message)}\n`);
|
|
17
19
|
const say = message => send(process.stdout, { jsonrpc: '2.0', ...message });
|
|
18
20
|
const pending = new Map();
|
|
21
|
+
// What Grok says of a compaction of the main session, as Coda takes it. A /compact says its end only.
|
|
22
|
+
const COMPACTION = { auto_compact_started: 'in_progress', auto_compact_completed: 'completed', auto_compact_failed: 'failed', auto_compact_cancelled: 'failed' };
|
|
23
|
+
let compaction = null;
|
|
19
24
|
// The deletes under way, by session: Coda closes a probe's session once its delete has had its few seconds, and a close
|
|
20
25
|
// reaching Grok while `sessions delete` still runs could write the session back.
|
|
21
26
|
const deleting = new Map();
|
|
@@ -93,6 +98,12 @@ read(grok.stdout, message => {
|
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
say(message);
|
|
101
|
+
const status = message.method === '_x.ai/session_notification' && message.params?.sessionId === sessionId ? COMPACTION[message.params.update?.sessionUpdate] : null;
|
|
102
|
+
if (status) {
|
|
103
|
+
compaction ??= randomUUID();
|
|
104
|
+
say({ method: 'session/update', params: { sessionId, update: { sessionUpdate: 'compaction_update', compactionId: compaction, status, error: null } } });
|
|
105
|
+
if (status !== 'in_progress') compaction = null;
|
|
106
|
+
}
|
|
96
107
|
});
|
|
97
108
|
const stop = () => {
|
|
98
109
|
if (stopping) return;
|