@coda-console/kimi 1.4.4 → 1.5.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 CHANGED
@@ -3,3 +3,5 @@
3
3
  Kimi Code Agent:Coda 的入口在运行机的 kimi acp 与 Coda 之间转发,读 Kimi 的会话文件报出后台命令与子 Agent;资源页的「Kimi」显示账号与额度,可从 Coda 安装和登录。
4
4
 
5
5
  不声明 `systemPrompt`;会话指令由 Coda 后端在新会话第一次非斜杠命令的用户输入前送入单独的文本块,恢复会话不再送,插件不用处理。
6
+
7
+ 压缩上下文(自动,或用户的 `/compact`):Kimi 的 ACP 只用一段文字说,所以读主 Agent 的 wire(`agents/main/wire.jsonl`)里的 `full_compaction.begin`、`full_compaction.complete`、`full_compaction.cancel`,按 ACP `compaction_update` 报给 Coda:开始 `in_progress`,完成 `completed`,取消 `failed`,同一次压缩用同一个 `compactionId`。和其余会话文件观察一样,只认核对过的 Kimi 版本;本进程启动前就开始的压缩只报结束。子 Agent 的压缩不报。
package/agent/observe.mjs CHANGED
@@ -76,7 +76,7 @@ export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0,
76
76
  // the schedule config that count uses (`schedule`), and what its subagents said since the last look, to `emit` as their
77
77
  // own sessions' updates. `main` is what the main wire added since the last look, in its order, for turns.mjs: the goal
78
78
  // as it changes, each main turn as it begins and ends (with the error a failed one ended with), and what is said in a
79
- // goal's or Coda's prompt's turn (as ACP updates); it opens with the goal and the turns still going as of the last look. A cron's prompt and a goal's objective
79
+ // goal's or Coda's prompt's turn (as ACP updates), and each compaction of its context as it begins and ends; it opens with the goal and the turns still going as of the last look. A cron's prompt and a goal's objective
80
80
  // do not leave here, only a short title cut from the first line. Null when the files are not this session's, or not laid
81
81
  // out as understood; a read that fails (a file being written) throws. A cron or goal event that is not the shape
82
82
  // understood is skipped, so one of them cannot hide the tasks.
@@ -175,6 +175,8 @@ export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0,
175
175
  for (const cron of crons.values()) if (cron.fireTurn === event.turnId) cron.fireEnded = true;
176
176
  if (span.turn?.turnId === event.turnId) span.turn = null;
177
177
  if (fresh) main.push({ type: 'ended', turnId: event.turnId, reason: event.reason, ...(object(event.error) ? { error: event.error } : {}) });
178
+ } else if (COMPACTION[event.type]) {
179
+ if (fresh && event.agentId === 'main') main.push({ type: 'compaction', phase: COMPACTION[event.type], time: event.time });
178
180
  } else if (event.type === 'goal.create' || event.type === 'goal.update' || event.type === 'goal.clear') {
179
181
  const next = noteGoal(goal, event);
180
182
  if (next === goal) continue;
@@ -196,6 +198,8 @@ export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0,
196
198
  } };
197
199
  }
198
200
 
201
+ // How the main wire tells its context being compacted (`full_compaction.begin` of an auto or a manual one, then one of the others).
202
+ const COMPACTION = { 'full_compaction.begin': 'begin', 'full_compaction.complete': 'complete', 'full_compaction.cancel': 'cancel' };
199
203
  // Who began a main turn: Coda's prompt (`user`), the goal (`goal`), or something else Kimi took up.
200
204
  function turnKind(origin) {
201
205
  if (origin?.kind === 'user') return 'user';
package/agent/turns.mjs CHANGED
@@ -19,6 +19,8 @@ export class KimiTurns {
19
19
  // The goal as told ({ id, active, state, turn, failure }) and as the wire last left it. Main turns going, those whose content is
20
20
  // told, the last Coda prompt's turn seen, and the prompts held.
21
21
  this.goal = null; this.latest = null; this.going = new Set(); this.telling = new Set(); this.user = null; this.held = [];
22
+ // The id of the compaction going, told as `compaction_update` (docs/agent-protocol.md): Kimi's ACP says it in text only.
23
+ this.compaction = null;
22
24
  }
23
25
  // Holds `answer`, Kimi's answer to the prompt sent at `sentAt`, when Kimi did not run that prompt yet: no turn of Coda's
24
26
  // prompts began since, or the one that did is still going, while some turn is. False when it is to be passed on now.
@@ -36,10 +38,19 @@ export class KimiTurns {
36
38
  if (entry.type === 'goal') this.noteGoal(entry, told);
37
39
  else if (entry.type === 'turn') this.begin(entry, told);
38
40
  else if (entry.type === 'ended') this.end(entry, told);
41
+ else if (entry.type === 'compaction') this.compact(entry, told);
39
42
  else if (entry.type === 'update' && this.telling.has(entry.turnId)) told.push(update(this.sessionId, entry.update));
40
43
  }
41
44
  return told;
42
45
  }
46
+ // The main agent's context is being compacted, auto or at Coda's `/compact`: told when it begins and when it ends, under one
47
+ // id. One that began before this process is told only at its end.
48
+ compact({ phase, time }, told) {
49
+ this.compaction ??= `${this.sessionId}:${time}`;
50
+ told.push(update(this.sessionId, { sessionUpdate: 'compaction_update', compactionId: this.compaction,
51
+ status: { begin: 'in_progress', complete: 'completed', cancel: 'failed' }[phase], error: phase === 'cancel' ? '压缩已取消' : null }));
52
+ if (phase !== 'begin') this.compaction = null;
53
+ }
43
54
  // The goal as the wire now leaves it. The one told goes on while it is this one and active; otherwise it ends, once its
44
55
  // turn did, and this one is told if active.
45
56
  noteGoal(entry, told) {
@@ -118,6 +129,7 @@ export class KimiTurns {
118
129
  // The files no longer read as understood: the goal ends, and held answers are passed on as Kimi gave them.
119
130
  lost() {
120
131
  const told = [];
132
+ if (this.compaction) this.compact({ phase: 'cancel' }, told);
121
133
  if (open(this.goal)) { this.goal.turn = undefined; this.say(told, 'failed'); }
122
134
  this.going.clear(); this.telling.clear(); this.user = null;
123
135
  return [...told, ...this.held.splice(0).map(held => held.answer)];
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "id": "kimi",
4
4
  "displayName": "Kimi Code",
5
5
  "description": "用 Kimi Code 跑会话",
6
- "version": "1.4.4",
6
+ "version": "1.5.0",
7
7
  "categories": [
8
8
  "Agent"
9
9
  ],