@coda-console/kimi 1.4.0 → 1.4.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/agent/errors.mjs +13 -0
- package/agent/observe.mjs +20 -17
- package/agent/relay.mjs +26 -5
- package/agent/turns.mjs +31 -12
- package/package.json +2 -2
- package/scripts/install.sh +2 -1
- package/scripts/setup.mjs +8 -5
package/agent/errors.mjs
CHANGED
|
@@ -14,3 +14,16 @@ export function classifyKimiError(message) {
|
|
|
14
14
|
message: reason,
|
|
15
15
|
data: { ...data, _meta: { ...meta, coda: { ...coda, failure: { kind: 'quota_exhausted' } } } } } };
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
// Kimi 2.1.1's ACP answers a prompt whose turn failed with `end_turn`, the error kept to the `turn.ended` of its main wire
|
|
19
|
+
// (observe.mjs). What failed so, read from that end: the provider's reason, and whether Kimi itself classified it as quota
|
|
20
|
+
// exhaustion (APIProviderQuotaExhaustedError, from the provider's own quota response). Null for a turn that did not fail,
|
|
21
|
+
// or whose filtered response Kimi answers as `refusal`.
|
|
22
|
+
export function turnFailure(reason, error) {
|
|
23
|
+
if (reason !== 'failed' || error?.code === 'provider.filtered') return null;
|
|
24
|
+
const message = typeof error?.message === 'string' && error.message.trim() ? error.message : 'Kimi 这一轮执行失败';
|
|
25
|
+
return { message, quota: error?.name === 'APIProviderQuotaExhaustedError' };
|
|
26
|
+
}
|
|
27
|
+
// The answer to a prompt whose turn failed so, as the execution failure it was (docs/agent-protocol.md「执行失败」).
|
|
28
|
+
export const failedAnswer = (answer, failure) => ({ jsonrpc: answer.jsonrpc ?? '2.0', id: answer.id, error: { code: -32603, message: failure.message,
|
|
29
|
+
...(failure.quota ? { data: { _meta: { coda: { failure: { kind: 'quota_exhausted' } } } } } : {}) } });
|
package/agent/observe.mjs
CHANGED
|
@@ -6,12 +6,12 @@ import { KimiSubagentBridge, loopUpdate } from './subagents.mjs';
|
|
|
6
6
|
|
|
7
7
|
const object = value => value && typeof value === 'object' && !Array.isArray(value);
|
|
8
8
|
const identifier = value => typeof value === 'string' && /^[\w-]+$/.test(value);
|
|
9
|
-
const unread = () => null;
|
|
10
9
|
|
|
11
10
|
// What Kimi keeps of a session in its own files (KIMI_CODE_HOME): its tasks, its main agent's turns, the crons it scheduled
|
|
12
11
|
// (`cron.add` / `cron.delete` / `cron.cursor` on the main wire) and its subagents' own conversations, which its ACP does
|
|
13
12
|
// not tell. These files are an implementation detail, not an ACP contract. Accept only the layout inspected in 2.1.1; a
|
|
14
|
-
// new version simply loses this observation.
|
|
13
|
+
// new version simply loses this observation, and says which way its files are not as understood (`unread`, relay.mjs).
|
|
14
|
+
// The one place the version checked is written: setup installs it (scripts/setup.mjs).
|
|
15
15
|
export const SUPPORTED = '2.1.1';
|
|
16
16
|
// Bounded ordinary-file reads also prevent a broken index/FIFO from holding up
|
|
17
17
|
// the entry. No paths, prompts, task output or credentials leave this module.
|
|
@@ -40,8 +40,9 @@ async function contained(root, path) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// The session `sessionId` that Kimi keeps for `cwd`. `startedAt`: when this agent process started; a subagent's run from
|
|
43
|
-
// before it is another process's, whose conversation is not told again.
|
|
44
|
-
export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0 }) {
|
|
43
|
+
// before it is another process's, whose conversation is not told again. `unread`: why a look found nothing, each time.
|
|
44
|
+
export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0, unread: told = () => {} }) {
|
|
45
|
+
const unread = reason => { told(reason); return null; };
|
|
45
46
|
const home = env.KIMI_CODE_HOME || join(env.HOME || homedir(), '.kimi-code');
|
|
46
47
|
let directory;
|
|
47
48
|
let subagents;
|
|
@@ -74,13 +75,13 @@ export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0 }
|
|
|
74
75
|
// `waiting`, `handling`, `done` or `cancelled`, with the created time and fire cursor its next fire is counted from) and
|
|
75
76
|
// the schedule config that count uses (`schedule`), and what its subagents said since the last look, to `emit` as their
|
|
76
77
|
// own sessions' updates. `main` is what the main wire added since the last look, in its order, for turns.mjs: the goal
|
|
77
|
-
// as it changes, each main turn as it begins and ends, and what is said in a
|
|
78
|
-
// 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
|
|
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
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
|
|
80
81
|
// out as understood; a read that fails (a file being written) throws. A cron or goal event that is not the shape
|
|
81
82
|
// understood is skipped, so one of them cannot hide the tasks.
|
|
82
83
|
async observe({ signal, emit = () => {} }) {
|
|
83
|
-
if (version !== SUPPORTED) return unread('
|
|
84
|
+
if (version !== SUPPORTED) return unread('files:version');
|
|
84
85
|
if (!identifier(sessionId) || !isAbsolute(home ?? '') || !isAbsolute(cwd ?? '')) return unread('unbound_session');
|
|
85
86
|
const root = await realpath(join(home, 'sessions')), workspace = await realpath(cwd);
|
|
86
87
|
if (!directory) {
|
|
@@ -98,10 +99,11 @@ export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0 }
|
|
|
98
99
|
}
|
|
99
100
|
const session = await contained(root, directory);
|
|
100
101
|
const state = JSON.parse(await read(join(session, 'state.json'), 1024 * 1024, signal));
|
|
101
|
-
if (state.version !== 2
|
|
102
|
-
|
|
102
|
+
if (state.version !== 2) return unread('files:state.version');
|
|
103
|
+
if (state.id !== sessionId || typeof state.cwd !== 'string' ||
|
|
104
|
+
await realpath(state.cwd) !== workspace || !object(state.agents) || !object(state.agents.main)) return unread('files:layout');
|
|
103
105
|
const agents = Object.keys(state.agents);
|
|
104
|
-
if (agents.length > 256 || !agents.every(identifier)) return unread('
|
|
106
|
+
if (agents.length > 256 || !agents.every(identifier)) return unread('files:layout');
|
|
105
107
|
|
|
106
108
|
const records = [];
|
|
107
109
|
for (const id of agents) {
|
|
@@ -110,16 +112,16 @@ export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0 }
|
|
|
110
112
|
try { tasks = await contained(agent, join(agent, 'tasks')); }
|
|
111
113
|
catch (error) { if (error.code === 'ENOENT') continue; throw error; }
|
|
112
114
|
const files = await readdir(tasks, { withFileTypes: true });
|
|
113
|
-
if (files.length > 4096) return unread('
|
|
115
|
+
if (files.length > 4096) return unread('files:layout');
|
|
114
116
|
for (const file of files) {
|
|
115
117
|
signal.throwIfAborted();
|
|
116
118
|
if (!file.name.endsWith('.json')) continue;
|
|
117
|
-
if (!file.isFile()) return unread('
|
|
119
|
+
if (!file.isFile()) return unread('files:layout');
|
|
118
120
|
const task = JSON.parse(await read(join(tasks, file.name), 1024 * 1024, signal));
|
|
119
121
|
if (!object(task) || !identifier(task.taskId) || file.name !== `${task.taskId}.json` ||
|
|
120
|
-
!['agent', 'process'].includes(task.kind) || typeof task.status !== 'string') return unread('
|
|
122
|
+
!['agent', 'process'].includes(task.kind) || typeof task.status !== 'string') return unread('files:layout');
|
|
121
123
|
if (task.status !== 'running' && (!['completed', 'failed', 'killed', 'lost', 'timed_out'].includes(task.status) ||
|
|
122
|
-
!Number.isSafeInteger(task.endedAt) || task.endedAt <= 0)) return unread('
|
|
124
|
+
!Number.isSafeInteger(task.endedAt) || task.endedAt <= 0)) return unread('files:layout');
|
|
123
125
|
records.push(task);
|
|
124
126
|
}
|
|
125
127
|
}
|
|
@@ -132,7 +134,8 @@ export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0 }
|
|
|
132
134
|
const wire = await read(join(session, 'agents/main/wire.jsonl'), 32 * 1024 * 1024, signal);
|
|
133
135
|
const lines = wire.trimEnd().split('\n');
|
|
134
136
|
const metadata = JSON.parse(lines.shift());
|
|
135
|
-
if (metadata.type !== 'metadata'
|
|
137
|
+
if (metadata.type !== 'metadata') return unread('files:layout');
|
|
138
|
+
if (metadata.protocol_version !== '1.5') return unread('files:wire.protocol_version');
|
|
136
139
|
// `cron.delete` is written when a fire is delivered and when CronDelete removes a job during a turn that is not that
|
|
137
140
|
// fire. Which one it was is kept with the job: the open `cron_job` turn, that turn once it ended, or the delete that
|
|
138
141
|
// landed inside some other turn already going. A delete before any such turn is not a cancel: the fire's turn.prompt
|
|
@@ -166,12 +169,12 @@ export function kimiSession({ sessionId, cwd, env = {}, version, startedAt = 0 }
|
|
|
166
169
|
}
|
|
167
170
|
} else if (event.type === 'turn.ended') {
|
|
168
171
|
if (event.agentId !== 'main' || !going.has(event.turnId) || !['completed', 'cancelled', 'failed', 'blocked'].includes(event.reason) ||
|
|
169
|
-
!Number.isSafeInteger(event.time) || event.time <= 0) return unread('
|
|
172
|
+
!Number.isSafeInteger(event.time) || event.time <= 0) return unread('files:layout');
|
|
170
173
|
going.delete(event.turnId);
|
|
171
174
|
turnEndedAt = event.time;
|
|
172
175
|
for (const cron of crons.values()) if (cron.fireTurn === event.turnId) cron.fireEnded = true;
|
|
173
176
|
if (span.turn?.turnId === event.turnId) span.turn = null;
|
|
174
|
-
if (fresh) main.push({ type: 'ended', turnId: event.turnId, reason: event.reason });
|
|
177
|
+
if (fresh) main.push({ type: 'ended', turnId: event.turnId, reason: event.reason, ...(object(event.error) ? { error: event.error } : {}) });
|
|
175
178
|
} else if (event.type === 'goal.create' || event.type === 'goal.update' || event.type === 'goal.clear') {
|
|
176
179
|
const next = noteGoal(goal, event);
|
|
177
180
|
if (next === goal) continue;
|
package/agent/relay.mjs
CHANGED
|
@@ -9,9 +9,12 @@ import { kimiDisplayNames } from './display.mjs';
|
|
|
9
9
|
// has not run the prompt yet.
|
|
10
10
|
// Nothing waits on a look longer than `hold`. CODA_DISABLE_RUNTIME_PATCHES=kimi leaves a plain relay, but for Coda's session
|
|
11
11
|
// instructions, which go in front of a new session's first prompt either way (instructions.mjs). A known quota error in
|
|
12
|
-
// a prompt's answer is classified at this boundary (errors.mjs), without retrying or changing other errors
|
|
12
|
+
// a prompt's answer is classified at this boundary (errors.mjs), without retrying or changing other errors; an `end_turn`
|
|
13
|
+
// Kimi gave to a prompt whose turn its files say failed is passed on as that failure. A Kimi whose files are not as understood
|
|
14
|
+
// (another version, another layout) is relayed as it would be anyway, but said so once a session and way, to a Coda that takes
|
|
15
|
+
// it (`_coda/unrecognized`, docs/agent-protocol.md「没适配的东西」): the user is told what goes unseen.
|
|
13
16
|
import { SessionInstructions } from './instructions.mjs';
|
|
14
|
-
import { classifyKimiError } from './errors.mjs';
|
|
17
|
+
import { classifyKimiError, failedAnswer } from './errors.mjs';
|
|
15
18
|
import { SUPPORTED, kimiSession } from './observe.mjs';
|
|
16
19
|
import { KimiWaits } from './waits.mjs';
|
|
17
20
|
import { KimiTurns } from './turns.mjs';
|
|
@@ -19,6 +22,9 @@ import { KimiTurns } from './turns.mjs';
|
|
|
19
22
|
const record = value => value && typeof value === 'object' && !Array.isArray(value);
|
|
20
23
|
// What Kimi says in a turn, as opposed to what it says of the session.
|
|
21
24
|
const SAID = new Set(['agent_message_chunk', 'agent_thought_chunk', 'tool_call', 'tool_call_update', 'plan']);
|
|
25
|
+
// Each way Kimi's files are not as understood (observe.mjs), by the name it is told by.
|
|
26
|
+
const UNREAD = { 'files:version': '这个版本的 Kimi 没有核对过', 'files:state.version': '会话的 state.json 版本对不上',
|
|
27
|
+
'files:wire.protocol_version': '主 Agent 的 wire 协议版本对不上', 'files:layout': '会话文件的布局对不上' };
|
|
22
28
|
|
|
23
29
|
export class KimiRelay {
|
|
24
30
|
// `say`: a message to Coda; `tell`: one to Kimi.
|
|
@@ -28,6 +34,8 @@ export class KimiRelay {
|
|
|
28
34
|
// Coda's requests whose answers are read here, by id; the prompts going, each with when it was sent and whether Kimi
|
|
29
35
|
// said nothing in it yet.
|
|
30
36
|
this.asked = new Map(); this.prompts = new Set(); this.sent = new Map();
|
|
37
|
+
// Whether Coda takes what is not understood, and what it was told, by session and name.
|
|
38
|
+
this.taken = false; this.told = new Set();
|
|
31
39
|
this.version = null; this.session = null; this.waits = null; this.turns = null; this.content = []; this.instructions = new SessionInstructions();
|
|
32
40
|
// What Kimi said, passed on in order behind any message that waits for a look.
|
|
33
41
|
this.queue = Promise.resolve();
|
|
@@ -38,8 +46,10 @@ export class KimiRelay {
|
|
|
38
46
|
if (coda) { this.queue = this.queue.then(() => this.say(coda)); return; }
|
|
39
47
|
message = agent;
|
|
40
48
|
if (!this.plain && 'id' in message && typeof message.method === 'string') {
|
|
41
|
-
if (message.method === 'initialize')
|
|
42
|
-
|
|
49
|
+
if (message.method === 'initialize') {
|
|
50
|
+
this.asked.set(message.id, { initialize: true });
|
|
51
|
+
this.taken = record(message.params?.clientCapabilities?._meta?.coda?.unrecognized);
|
|
52
|
+
} else if (['session/new', 'session/load'].includes(message.method)) this.asked.set(message.id, { cwd: message.params?.cwd, sessionId: message.params?.sessionId });
|
|
43
53
|
else if (message.method === 'session/prompt') {
|
|
44
54
|
this.asked.set(message.id, { prompt: true }); this.prompts.add(message.id); this.sent.set(message.id, { at: Date.now(), quiet: true });
|
|
45
55
|
}
|
|
@@ -71,6 +81,8 @@ export class KimiRelay {
|
|
|
71
81
|
this.queue = this.queue.then(async () => {
|
|
72
82
|
if (waiting) await this.look({ fresh: !!asked?.prompt });
|
|
73
83
|
if (sent?.quiet && message.result?.stopReason === 'end_turn' && this.turns?.hold(sent.at, message)) { this.prompts.add(message.id); return; }
|
|
84
|
+
const failure = sent && message.result?.stopReason === 'end_turn' ? this.turns?.failure(sent.at) : null;
|
|
85
|
+
if (failure) message = failedAnswer(message, failure);
|
|
74
86
|
this.say(message);
|
|
75
87
|
const sessionId = asked && !('error' in message) ? message.result?.sessionId ?? asked.sessionId : undefined;
|
|
76
88
|
if (typeof sessionId === 'string') this.begin(sessionId, asked.cwd);
|
|
@@ -78,11 +90,20 @@ export class KimiRelay {
|
|
|
78
90
|
}
|
|
79
91
|
begin(sessionId, cwd) {
|
|
80
92
|
this.unfollow();
|
|
81
|
-
this.session = this.makeSession({ sessionId, cwd, env: this.env, version: this.version, startedAt: this.startedAt
|
|
93
|
+
this.session = this.makeSession({ sessionId, cwd, env: this.env, version: this.version, startedAt: this.startedAt,
|
|
94
|
+
unread: reason => this.unread(sessionId, reason) });
|
|
82
95
|
this.waits = new KimiWaits({ sessionId, startedAt: this.startedAt });
|
|
83
96
|
this.turns = new KimiTurns({ sessionId, startedAt: this.startedAt });
|
|
84
97
|
this.observe();
|
|
85
98
|
}
|
|
99
|
+
// A look at the session's files that found them not as understood (`name`, observe.mjs), told once.
|
|
100
|
+
unread(sessionId, name) {
|
|
101
|
+
const key = `${sessionId}\n${name}`;
|
|
102
|
+
if (!Object.hasOwn(UNREAD, name) || !this.taken || this.told.has(key)) return;
|
|
103
|
+
this.told.add(key);
|
|
104
|
+
this.say({ jsonrpc: '2.0', method: '_coda/unrecognized', params: { sessionId, kind: 'output', name, lost: true,
|
|
105
|
+
detail: `Kimi ${this.version ?? '(版本未知)'}:${UNREAD[name]}(核对过的是 ${SUPPORTED}),后台任务、子 Agent、定时看不见,失败的一轮可能显示成成功` } });
|
|
106
|
+
}
|
|
86
107
|
// Waits, at most `hold`, for a look at the files: one begun after this, when `fresh`.
|
|
87
108
|
look({ fresh = false } = {}) {
|
|
88
109
|
if (!this.session) return;
|
package/agent/turns.mjs
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
// reaches it while such a turn is going is queued, and its ACP answers it at once though it runs later.
|
|
4
4
|
// So the goal is told as a timer that fires again after each turn (docs/agent-protocol.md「_coda/wait」): `handling` through
|
|
5
5
|
// each of its turns, which Coda takes up as turns of their own, `waiting` between them, `done` once the goal is no longer
|
|
6
|
-
// active. A Coda prompt Kimi answered at once without running it is held: its answer waits for the turn that runs it, the
|
|
7
|
-
// first of Coda's prompts' turns that began after it was sent.
|
|
6
|
+
// active, `failed` with the reason when the last main turn before that failed (Kimi pauses its goal after a turn fails). A Coda prompt Kimi answered at once without running it is held: its answer waits for the turn that runs it, the
|
|
7
|
+
// first of Coda's prompts' turns that began after it was sent. A prompt whose turn failed is answered with that failure
|
|
8
|
+
// (errors.mjs), which Kimi's ACP answers as `end_turn`. What is said in a goal's turn or a held prompt's is told as
|
|
8
9
|
// this session's updates; a turn from before this agent process (`startedAt`) is another process's and is not told.
|
|
10
|
+
import { failedAnswer, turnFailure } from './errors.mjs';
|
|
11
|
+
|
|
9
12
|
const CONTINUES = '目标未完成前,每轮结束后自动继续';
|
|
10
13
|
// How Kimi's ACP answers a turn that ended so.
|
|
11
14
|
const STOPPED = { cancelled: 'cancelled', blocked: 'refusal' };
|
|
@@ -13,7 +16,7 @@ const STOPPED = { cancelled: 'cancelled', blocked: 'refusal' };
|
|
|
13
16
|
export class KimiTurns {
|
|
14
17
|
constructor({ sessionId, startedAt = 0 }) {
|
|
15
18
|
this.sessionId = sessionId; this.startedAt = startedAt;
|
|
16
|
-
// The goal as told ({ id, active, state, turn }) and as the wire last left it. Main turns going, those whose content is
|
|
19
|
+
// The goal as told ({ id, active, state, turn, failure }) and as the wire last left it. Main turns going, those whose content is
|
|
17
20
|
// told, the last Coda prompt's turn seen, and the prompts held.
|
|
18
21
|
this.goal = null; this.latest = null; this.going = new Set(); this.telling = new Set(); this.user = null; this.held = [];
|
|
19
22
|
}
|
|
@@ -45,14 +48,14 @@ export class KimiTurns {
|
|
|
45
48
|
if (open(goal)) {
|
|
46
49
|
goal.active = goal.id === entry.id && entry.active;
|
|
47
50
|
if (goal.active || goal.turn !== undefined) return;
|
|
48
|
-
this.
|
|
51
|
+
this.finish(told);
|
|
49
52
|
}
|
|
50
53
|
this.start(told);
|
|
51
54
|
}
|
|
52
55
|
start(told) {
|
|
53
56
|
const latest = this.latest;
|
|
54
57
|
if (!latest?.active || this.goal?.id === latest.id) return;
|
|
55
|
-
this.goal = { id: latest.id, active: true, state: 'waiting', turn: undefined };
|
|
58
|
+
this.goal = { id: latest.id, active: true, state: 'waiting', turn: undefined, failure: null };
|
|
56
59
|
told.push(wait({ sessionId: this.sessionId, waitId: latest.id, state: 'waiting', kind: 'timer', title: latest.title || 'Kimi 目标',
|
|
57
60
|
detail: CONTINUES, recurring: true, stoppable: false }));
|
|
58
61
|
}
|
|
@@ -67,28 +70,44 @@ export class KimiTurns {
|
|
|
67
70
|
this.telling.add(turnId);
|
|
68
71
|
this.say(told, 'handling');
|
|
69
72
|
} else if (kind === 'user') {
|
|
70
|
-
this.user = { turnId, time, ended: false, claimed: false };
|
|
73
|
+
this.user = { turnId, time, ended: false, claimed: false, failure: null };
|
|
71
74
|
const held = this.held.find(h => h.turnId === undefined && h.sentAt <= time);
|
|
72
75
|
if (held) { held.turnId = turnId; this.user.claimed = true; this.telling.add(turnId); }
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
end({ turnId, reason }, told) {
|
|
78
|
+
end({ turnId, reason, error }, told) {
|
|
76
79
|
if (!this.going.delete(turnId)) return;
|
|
77
80
|
this.telling.delete(turnId);
|
|
78
|
-
|
|
81
|
+
const failure = turnFailure(reason, error);
|
|
82
|
+
if (this.user?.turnId === turnId) { this.user.ended = true; this.user.failure = failure; }
|
|
83
|
+
if (open(this.goal)) this.goal.failure = failure;
|
|
79
84
|
if (this.goal?.turn === turnId) this.settle(told);
|
|
80
85
|
const i = this.held.findIndex(h => h.turnId === turnId);
|
|
81
|
-
if (i >= 0)
|
|
86
|
+
if (i >= 0) {
|
|
87
|
+
const { answer } = this.held.splice(i, 1)[0];
|
|
88
|
+
told.push(failure ? failedAnswer(answer, failure) : answered(answer, STOPPED[reason] ?? 'end_turn'));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// How the turn of the prompt sent at `sentAt` failed, once it ended so; null otherwise. For an answer not held.
|
|
92
|
+
failure(sentAt) {
|
|
93
|
+
const user = this.user;
|
|
94
|
+
return user && !user.claimed && user.ended && user.time >= sentAt ? user.failure : null;
|
|
82
95
|
}
|
|
83
96
|
// The goal's turn is over: it waits for the next, or ends, and the goal that replaced it is told.
|
|
84
97
|
settle(told) {
|
|
85
98
|
this.goal.turn = undefined;
|
|
86
|
-
|
|
99
|
+
if (this.goal.active) this.say(told, 'waiting'); else this.finish(told);
|
|
87
100
|
this.start(told);
|
|
88
101
|
}
|
|
89
|
-
|
|
102
|
+
// The goal is no longer active: done, or failed as the last main turn did.
|
|
103
|
+
finish(told) {
|
|
104
|
+
const failure = this.goal.failure;
|
|
105
|
+
if (!failure) { this.say(told, 'done'); return; }
|
|
106
|
+
this.say(told, 'failed', { ...(failure.quota ? { title: '额度不足' } : {}), detail: failure.message.slice(0, 4000) });
|
|
107
|
+
}
|
|
108
|
+
say(told, state, more = {}) {
|
|
90
109
|
this.goal.state = state;
|
|
91
|
-
told.push(wait({ sessionId: this.sessionId, waitId: this.goal.id, state }));
|
|
110
|
+
told.push(wait({ sessionId: this.sessionId, waitId: this.goal.id, state, ...more }));
|
|
92
111
|
}
|
|
93
112
|
// Coda stopped: Kimi's ACP cannot stop a turn it does not drive, so a held prompt is answered as stopped now, and what its
|
|
94
113
|
// turn says if it still runs is not told.
|
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.
|
|
6
|
+
"version": "1.4.2",
|
|
7
7
|
"categories": [
|
|
8
8
|
"Agent"
|
|
9
9
|
],
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"signIn": {
|
|
40
40
|
"command": "exec sh \"$CODA_PLUGIN_PATH/scripts/login.sh\"",
|
|
41
41
|
"installed": "test -x \"$HOME/.kimi-code/bin/kimi\" || command -v kimi >/dev/null",
|
|
42
|
-
"install": "exec
|
|
42
|
+
"install": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/scripts/setup.mjs\"",
|
|
43
43
|
"note": "登录保存在这台机器的 Kimi CLI 里,由它自己续期。"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/scripts/install.sh
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
2
|
# The Kimi CLI's own installer, as https://www.kimi.com/code gives it. It puts the CLI in ~/.kimi-code/bin, where Coda looks
|
|
3
3
|
# first, and would add that to the shell's configuration and rename an older Python `kimi` it finds on the PATH: told not to
|
|
4
|
-
# touch the configuration, with that directory not on the PATH, it leaves both alone.
|
|
4
|
+
# touch the configuration, with that directory not on the PATH, it leaves both alone. It installs KIMI_VERSION, which setup.mjs
|
|
5
|
+
# sets to the version the relay was checked against; the latest without it.
|
|
5
6
|
PATH=$(printf '%s' "$PATH" | tr ':' '\n' | grep -vx "$HOME/.kimi-code/bin" | paste -sd: -)
|
|
6
7
|
KIMI_NO_MODIFY_PATH=1 PATH="$PATH" exec bash -c 'set -o pipefail; curl -fsSL https://code.kimi.com/kimi-code/install.sh | bash'
|
package/scripts/setup.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// The plugin's setup (`contributes.setup`), which Coda runs on each machine when the user installs or updates the plugin: it
|
|
2
|
-
// ends well once the machine can run the agent. Without a Kimi CLI that runs, or
|
|
3
|
-
// the relay reads, agent/observe.mjs), Kimi's own installer (install.sh) puts
|
|
4
|
-
// looks first; a newer one is kept. Why the machine is not ready
|
|
2
|
+
// ends well once the machine can run the agent; the「Kimi」resource type's install runs it too. Without a Kimi CLI that runs, or
|
|
3
|
+
// with one older than MINIMUM (the file layout the relay reads, agent/observe.mjs), Kimi's own installer (install.sh) puts that
|
|
4
|
+
// version (KIMI_VERSION) in ~/.kimi-code/bin, where the agent looks first; a newer one is kept. Why the machine is not ready
|
|
5
|
+
// is said in one line on standard error.
|
|
5
6
|
import { spawnSync } from 'node:child_process';
|
|
6
7
|
import { realpathSync } from 'node:fs';
|
|
7
8
|
import { fileURLToPath } from 'node:url';
|
|
8
9
|
import { kimiBinary } from '../agent/binary.mjs';
|
|
10
|
+
import { SUPPORTED } from '../agent/observe.mjs';
|
|
9
11
|
|
|
10
|
-
export const MINIMUM =
|
|
12
|
+
export const MINIMUM = SUPPORTED;
|
|
11
13
|
// The first x.y.z a version command prints; whether one is older than another.
|
|
12
14
|
export const versionIn = text => /(\d+)\.(\d+)\.(\d+)/.exec(text ?? '')?.slice(1).join('.') ?? null;
|
|
13
15
|
export function older(version, than) {
|
|
@@ -32,7 +34,8 @@ if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToP
|
|
|
32
34
|
const before = needed(kimiBinary());
|
|
33
35
|
if (before.action !== 'none') {
|
|
34
36
|
// What the installer prints goes to standard error with the rest of its story.
|
|
35
|
-
const installed = spawnSync('sh', [fileURLToPath(new URL('./install.sh', import.meta.url))], { stdio: ['ignore', 2, 2]
|
|
37
|
+
const installed = spawnSync('sh', [fileURLToPath(new URL('./install.sh', import.meta.url))], { stdio: ['ignore', 2, 2],
|
|
38
|
+
env: { ...process.env, KIMI_VERSION: MINIMUM } });
|
|
36
39
|
if (installed.status !== 0) { console.error(`${before.reason},安装失败(退出码 ${installed.status ?? installed.signal})`); process.exit(1); }
|
|
37
40
|
}
|
|
38
41
|
const after = needed(kimiBinary());
|