kimi-plugin-cc 3.0.0 → 3.1.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +3 -14
- package/README.md +428 -572
- package/assets/logo.svg +6 -0
- package/cordis.patch.yml +18 -0
- package/dist/background-spawn.js +4 -2
- package/dist/cli-client.js +105 -66
- package/dist/commands/ask.js +27 -12
- package/dist/commands/cancel.js +4 -13
- package/dist/commands/cli-helpers.js +1 -1
- package/dist/commands/pursue.js +3 -2
- package/dist/commands/registry.js +7 -26
- package/dist/commands/repair-sessions.js +7 -4
- package/dist/commands/replay.js +4 -3
- package/dist/commands/rescue.js +17 -5
- package/dist/commands/review.js +18 -5
- package/dist/commands/setup.js +283 -265
- package/dist/commands/swarm.js +20 -7
- package/dist/companion.js +142 -18
- package/dist/help.js +11 -7
- package/dist/hook-escape.js +7 -16
- package/dist/hooks/approval-hook.js +1762 -124
- package/dist/hooks/approval-policy.js +15 -10
- package/dist/hooks/config-safety.js +15 -24
- package/dist/hooks/hook-timing.js +1 -1
- package/dist/hooks/install-paths.js +224 -112
- package/dist/hooks/install.js +64 -169
- package/dist/hooks/managed-block.js +52 -101
- package/dist/job-store.js +117 -49
- package/dist/jobs.js +53 -1
- package/dist/kimi-engine.js +68 -92
- package/dist/kimi-errors.js +1 -1
- package/dist/kimi-journal.js +3 -2
- package/dist/kimi-releases.js +28 -49
- package/dist/kimi-timeouts.js +1 -15
- package/dist/kimi-version-probe.js +24 -72
- package/dist/logging.js +12 -7
- package/dist/mcp/binding.js +13 -4
- package/dist/mcp/job-control.js +386 -89
- package/dist/mcp/launcher.js +1 -1
- package/dist/mcp/operations.js +387 -193
- package/dist/mcp/protocol.js +116 -27
- package/dist/mcp/skills.js +130 -0
- package/dist/mcp/stdio.js +15 -2
- package/dist/native-v2-preflight.js +127 -35
- package/dist/parsing.js +45 -11
- package/dist/paths.js +20 -10
- package/dist/plugin-data.js +28 -83
- package/dist/read-scope.js +2 -2
- package/dist/render.js +13 -38
- package/dist/session-references.js +216 -0
- package/dist/session-title.js +1 -1
- package/dist/surface-routing.js +92 -5
- package/dist/swarm-activation.js +26 -137
- package/dist/version.js +1 -1
- package/docs/migration.md +46 -227
- package/docs/models.md +24 -66
- package/docs/safety.md +195 -400
- package/docs/session-visibility.md +24 -14
- package/docs/swarm-recovery.md +26 -20
- package/dsh/index.json +54 -0
- package/mcp_config.json +10 -0
- package/package.json +23 -82
- package/plugin.json +19 -0
- package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
- package/plugins/kimi-codex/.mcp.json +2 -3
- package/plugins/kimi-codex/dist/background-spawn.js +4 -2
- package/plugins/kimi-codex/dist/cli-client.js +105 -66
- package/plugins/kimi-codex/dist/commands/ask.js +27 -12
- package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
- package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
- package/plugins/kimi-codex/dist/commands/registry.js +7 -26
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
- package/plugins/kimi-codex/dist/commands/replay.js +4 -3
- package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
- package/plugins/kimi-codex/dist/commands/review.js +18 -5
- package/plugins/kimi-codex/dist/commands/setup.js +283 -265
- package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
- package/plugins/kimi-codex/dist/companion.js +142 -18
- package/plugins/kimi-codex/dist/help.js +11 -7
- package/plugins/kimi-codex/dist/hook-escape.js +7 -16
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
- package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
- package/plugins/kimi-codex/dist/hooks/install-paths.js +224 -112
- package/plugins/kimi-codex/dist/hooks/install.js +64 -169
- package/plugins/kimi-codex/dist/hooks/managed-block.js +52 -101
- package/plugins/kimi-codex/dist/job-store.js +117 -49
- package/plugins/kimi-codex/dist/jobs.js +53 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
- package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
- package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
- package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
- package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
- package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
- package/plugins/kimi-codex/dist/logging.js +12 -7
- package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
- package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
- package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
- package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
- package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
- package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
- package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
- package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
- package/plugins/kimi-codex/dist/parsing.js +45 -11
- package/plugins/kimi-codex/dist/paths.js +20 -10
- package/plugins/kimi-codex/dist/plugin-data.js +28 -83
- package/plugins/kimi-codex/dist/read-scope.js +2 -2
- package/plugins/kimi-codex/dist/render.js +13 -38
- package/plugins/kimi-codex/dist/session-references.js +216 -0
- package/plugins/kimi-codex/dist/session-title.js +1 -1
- package/plugins/kimi-codex/dist/surface-routing.js +92 -5
- package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/scripts/companion.sh +4 -15
- package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
- package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
- package/scripts/companion.sh +4 -15
- package/skills/kimi/SKILL.md +77 -0
- package/skills/kimi/agents/openai.yaml +6 -0
- package/CHANGELOG.md +0 -1402
- package/agents/kimi-pursue.md +0 -93
- package/agents/kimi-review.md +0 -86
- package/agents/kimi-swarm.md +0 -88
- package/agents/kimi-task.md +0 -93
- package/commands/README.md +0 -14
- package/commands/cancel.md +0 -17
- package/commands/pursue.md +0 -41
- package/commands/replay.md +0 -13
- package/commands/result.md +0 -13
- package/commands/review.md +0 -40
- package/commands/setup.md +0 -25
- package/commands/status.md +0 -13
- package/commands/swarm.md +0 -45
- package/commands/task.md +0 -40
- package/dist/commands/review-gate.js +0 -391
- package/dist/config.js +0 -22
- package/dist/dsh/companion.js +0 -177
- package/dist/dsh/index.js +0 -167
- package/dist/hooks/review-gate-stop.js +0 -19
- package/dist/schemas/review-gate-output.js +0 -41
- package/docs/registry-releases.md +0 -228
- package/docs/upstream-2.4.1-certification.md +0 -54
- package/docs/upstream-2.5.0-certification.md +0 -52
- package/docs/upstream-2.5.1-certification.md +0 -47
- package/docs/upstream-2.5.2-certification.md +0 -40
- package/docs/upstream-2.5.3-certification.md +0 -73
- package/docs/upstream-2.6.0-certification.md +0 -65
- package/docs/upstream-2.6.2-certification.md +0 -144
- package/docs/upstream-2.6.3-certification.md +0 -100
- package/docs/upstream-2.7.2-certification.md +0 -113
- package/docs/upstream-2.7.3-certification.md +0 -95
- package/docs/windows-validation.md +0 -39
- package/hooks/README.md +0 -9
- package/hooks/hooks.json +0 -16
- package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-codex/dist/config.js +0 -22
- package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
- package/plugins/kimi-codex/dist/dsh/index.js +0 -167
- package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
- package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
- package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/LICENSE +0 -201
- package/plugins/kimi-dsh/README.md +0 -84
- package/plugins/kimi-dsh/cordis.patch.yml +0 -45
- package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
- package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
- package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
- package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
- package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
- package/plugins/kimi-dsh/dist/commands/models.js +0 -139
- package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
- package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
- package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
- package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
- package/plugins/kimi-dsh/dist/commands/result.js +0 -72
- package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-dsh/dist/commands/review.js +0 -217
- package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
- package/plugins/kimi-dsh/dist/commands/status.js +0 -27
- package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
- package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
- package/plugins/kimi-dsh/dist/companion.js +0 -99
- package/plugins/kimi-dsh/dist/config.js +0 -22
- package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
- package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
- package/plugins/kimi-dsh/dist/errors.js +0 -40
- package/plugins/kimi-dsh/dist/git.js +0 -216
- package/plugins/kimi-dsh/dist/help.js +0 -43
- package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
- package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
- package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
- package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-dsh/dist/job-id.js +0 -12
- package/plugins/kimi-dsh/dist/job-store.js +0 -631
- package/plugins/kimi-dsh/dist/jobs.js +0 -212
- package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
- package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
- package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
- package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
- package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
- package/plugins/kimi-dsh/dist/logging.js +0 -22
- package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
- package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
- package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
- package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
- package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
- package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
- package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
- package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
- package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
- package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
- package/plugins/kimi-dsh/dist/model-command.js +0 -34
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
- package/plugins/kimi-dsh/dist/package.json +0 -1
- package/plugins/kimi-dsh/dist/parsing.js +0 -554
- package/plugins/kimi-dsh/dist/paths.js +0 -35
- package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
- package/plugins/kimi-dsh/dist/process-tree.js +0 -597
- package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
- package/plugins/kimi-dsh/dist/read-scope.js +0 -435
- package/plugins/kimi-dsh/dist/render.js +0 -214
- package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
- package/plugins/kimi-dsh/dist/session-title.js +0 -313
- package/plugins/kimi-dsh/dist/stream-json.js +0 -344
- package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
- package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
- package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
- package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
- package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
- package/plugins/kimi-dsh/dist/types.js +0 -1
- package/plugins/kimi-dsh/dist/util.js +0 -28
- package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
- package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
- package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
- package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
- package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
- package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
- package/plugins/kimi-dsh/dist/version.js +0 -7
- package/plugins/kimi-dsh/package.json +0 -78
- package/plugins/kimi-dsh/scripts/companion.sh +0 -37
- package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
- package/scripts/review-gate-hook.sh +0 -32
package/dist/job-store.js
CHANGED
|
@@ -1,38 +1,47 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { RuntimeError, formatError } from "./errors.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// example, would otherwise leak the handle because the constructor
|
|
10
|
-
// exits via throw before any caller reference exists for cleanup.
|
|
3
|
+
const JOB_STORE_SCHEMA_VERSION = 310;
|
|
4
|
+
const BUSY_OPEN_WAIT = new Int32Array(new SharedArrayBuffer(4));
|
|
5
|
+
function openAndInitializeJobStore(paths) {
|
|
6
|
+
// Retry transient SQLITE_BUSY / SQLITE_PROTOCOL contention during concurrent
|
|
7
|
+
// process open/WAL setup because PRAGMA journal_mode = WAL ignores busy_timeout.
|
|
8
|
+
for (let attempt = 0; attempt < 8; attempt += 1) {
|
|
11
9
|
let db;
|
|
12
10
|
try {
|
|
13
11
|
db = createSqliteAdapter(paths.stateDbPath);
|
|
14
|
-
// busy_timeout FIRST: switching the journal mode takes a
|
|
15
|
-
// and a second opener (status/result racing a worker) otherwise fails
|
|
16
|
-
// immediately with SQLITE_BUSY instead of waiting (seen 2026-10-14).
|
|
12
|
+
// busy_timeout FIRST: switching the journal mode or migrating schema takes a write lock.
|
|
17
13
|
db.pragma("busy_timeout = 5000");
|
|
18
|
-
db.
|
|
14
|
+
const mode = db.all("PRAGMA journal_mode")[0]?.journal_mode?.toLowerCase();
|
|
15
|
+
if (mode !== "wal") {
|
|
16
|
+
db.pragma("journal_mode = WAL");
|
|
17
|
+
}
|
|
18
|
+
const userVersion = db.all("PRAGMA user_version")[0]?.user_version ?? 0;
|
|
19
|
+
if (userVersion < JOB_STORE_SCHEMA_VERSION) {
|
|
20
|
+
initializeJobStoreSchema(db);
|
|
21
|
+
db.pragma(`user_version = ${JOB_STORE_SCHEMA_VERSION}`);
|
|
22
|
+
}
|
|
23
|
+
return db;
|
|
19
24
|
}
|
|
20
25
|
catch (error) {
|
|
26
|
+
// Release the OS handle before backoff or propagation; swallow close errors
|
|
27
|
+
// so the original SQLite failure takes priority.
|
|
21
28
|
try {
|
|
22
29
|
db?.close();
|
|
23
30
|
}
|
|
24
31
|
catch {
|
|
25
|
-
//
|
|
32
|
+
// intentionally swallow — original error takes priority
|
|
33
|
+
}
|
|
34
|
+
if (attempt < 7 && isSqliteBusyError(error)) {
|
|
35
|
+
Atomics.wait(BUSY_OPEN_WAIT, 0, 0, 25 * (attempt + 1));
|
|
36
|
+
continue;
|
|
26
37
|
}
|
|
27
38
|
throw translateSqliteError(error);
|
|
28
39
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
this.db.exec(`
|
|
40
|
+
}
|
|
41
|
+
throw translateSqliteError(new Error("database is locked"));
|
|
42
|
+
}
|
|
43
|
+
function initializeJobStoreSchema(db) {
|
|
44
|
+
db.exec(`
|
|
36
45
|
CREATE TABLE IF NOT EXISTS jobs (
|
|
37
46
|
job_id TEXT PRIMARY KEY,
|
|
38
47
|
repo_id TEXT NOT NULL,
|
|
@@ -67,13 +76,13 @@ export class JobStore {
|
|
|
67
76
|
error TEXT
|
|
68
77
|
);
|
|
69
78
|
`);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
for (const [column, type] of ADDED_JOB_COLUMNS) {
|
|
80
|
+
// Re-read per column: another process may be migrating the same store.
|
|
81
|
+
if (!existingColumns(db, "jobs").has(column)) {
|
|
82
|
+
db.exec(`ALTER TABLE jobs ADD COLUMN ${column} ${type};`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
db.exec(`
|
|
77
86
|
CREATE TABLE IF NOT EXISTS mcp_tasks (
|
|
78
87
|
task_id TEXT PRIMARY KEY,
|
|
79
88
|
operation_kind TEXT NOT NULL,
|
|
@@ -146,22 +155,14 @@ export class JobStore {
|
|
|
146
155
|
-- 0.1.6 migration: rename adversarial_review to challenge
|
|
147
156
|
UPDATE jobs SET command_type = 'challenge' WHERE command_type = 'adversarial_review';
|
|
148
157
|
`);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
this.db.close();
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
// intentionally swallow — original error takes priority
|
|
162
|
-
}
|
|
163
|
-
throw translateSqliteError(error);
|
|
164
|
-
}
|
|
158
|
+
if (!existingColumns(db, "mcp_tasks").has("kimi_identity")) {
|
|
159
|
+
db.exec("ALTER TABLE mcp_tasks ADD COLUMN kimi_identity TEXT;");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
export class JobStore {
|
|
163
|
+
db;
|
|
164
|
+
constructor(paths) {
|
|
165
|
+
this.db = openAndInitializeJobStore(paths);
|
|
165
166
|
}
|
|
166
167
|
getSwarmRecovery(jobId) {
|
|
167
168
|
const row = this.db.get("SELECT payload, recovery_owner FROM swarm_recovery WHERE job_id = ?", jobId);
|
|
@@ -229,6 +230,48 @@ export class JobStore {
|
|
|
229
230
|
const row = this.db.get(`SELECT * FROM jobs WHERE ${conditions.join(" AND ")} ORDER BY updated_at DESC LIMIT 1`, params);
|
|
230
231
|
return row ? hydrateRow(row) : null;
|
|
231
232
|
}
|
|
233
|
+
listJobs(options) {
|
|
234
|
+
const conditions = ["repo_id = @repo_id"];
|
|
235
|
+
const params = {
|
|
236
|
+
repo_id: options.repoId,
|
|
237
|
+
};
|
|
238
|
+
if (options.status) {
|
|
239
|
+
conditions.push("status = @status");
|
|
240
|
+
params.status = options.status;
|
|
241
|
+
}
|
|
242
|
+
if (options.operationKind) {
|
|
243
|
+
conditions.push("operation_kind = @operation_kind");
|
|
244
|
+
params.operation_kind = options.operationKind;
|
|
245
|
+
}
|
|
246
|
+
if (options.limit === null) {
|
|
247
|
+
return this.db
|
|
248
|
+
.all(`SELECT * FROM jobs WHERE ${conditions.join(" AND ")} ORDER BY created_at DESC, rowid DESC`, params)
|
|
249
|
+
.map(hydrateRow);
|
|
250
|
+
}
|
|
251
|
+
params.limit = Math.max(1, Math.min(100, Math.trunc(options.limit ?? 20)));
|
|
252
|
+
return this.db
|
|
253
|
+
.all(`SELECT * FROM jobs WHERE ${conditions.join(" AND ")} ORDER BY created_at DESC, rowid DESC LIMIT @limit`, params)
|
|
254
|
+
.map(hydrateRow);
|
|
255
|
+
}
|
|
256
|
+
listJobsByUpdated(options) {
|
|
257
|
+
const conditions = ["repo_id = @repo_id"];
|
|
258
|
+
const params = {
|
|
259
|
+
repo_id: options.repoId,
|
|
260
|
+
};
|
|
261
|
+
if (options.commandType) {
|
|
262
|
+
conditions.push("command_type = @command_type");
|
|
263
|
+
params.command_type = options.commandType;
|
|
264
|
+
}
|
|
265
|
+
if (options.terminalOnly) {
|
|
266
|
+
conditions.push("status IN ('completed', 'failed', 'cancelled')");
|
|
267
|
+
}
|
|
268
|
+
if (options.runningOnly) {
|
|
269
|
+
conditions.push("status = 'running'");
|
|
270
|
+
}
|
|
271
|
+
return this.db
|
|
272
|
+
.all(`SELECT * FROM jobs WHERE ${conditions.join(" AND ")} ORDER BY updated_at DESC, rowid DESC`, params)
|
|
273
|
+
.map(hydrateRow);
|
|
274
|
+
}
|
|
232
275
|
listRunningJobsWithProcessHints() {
|
|
233
276
|
const rows = this.db.all(`SELECT * FROM jobs WHERE status = 'running' AND (pid IS NOT NULL OR kimi_pid IS NOT NULL)`);
|
|
234
277
|
return rows.map(hydrateRow);
|
|
@@ -341,13 +384,34 @@ export class JobStore {
|
|
|
341
384
|
return this.getJob(jobId);
|
|
342
385
|
}
|
|
343
386
|
markCompleted(jobId, patch) {
|
|
344
|
-
return this.updateRunningJob(jobId, {
|
|
387
|
+
return this.updateRunningJob(jobId, {
|
|
388
|
+
...patch,
|
|
389
|
+
status: "completed",
|
|
390
|
+
pid: null,
|
|
391
|
+
kimi_pid: null,
|
|
392
|
+
companion_identity: null,
|
|
393
|
+
kimi_identity: null,
|
|
394
|
+
});
|
|
345
395
|
}
|
|
346
396
|
markFailed(jobId, patch) {
|
|
347
|
-
return this.updateRunningJob(jobId, {
|
|
397
|
+
return this.updateRunningJob(jobId, {
|
|
398
|
+
...patch,
|
|
399
|
+
status: "failed",
|
|
400
|
+
pid: null,
|
|
401
|
+
kimi_pid: null,
|
|
402
|
+
companion_identity: null,
|
|
403
|
+
kimi_identity: null,
|
|
404
|
+
});
|
|
348
405
|
}
|
|
349
406
|
markCancelled(jobId, patch) {
|
|
350
|
-
return this.updateRunningJob(jobId, {
|
|
407
|
+
return this.updateRunningJob(jobId, {
|
|
408
|
+
...patch,
|
|
409
|
+
status: "cancelled",
|
|
410
|
+
pid: null,
|
|
411
|
+
kimi_pid: null,
|
|
412
|
+
companion_identity: null,
|
|
413
|
+
kimi_identity: null,
|
|
414
|
+
});
|
|
351
415
|
}
|
|
352
416
|
}
|
|
353
417
|
/** Columns added after the first schema, in the order older stores receive them. */
|
|
@@ -373,11 +437,13 @@ const ADDED_JOB_COLUMNS = [
|
|
|
373
437
|
["safety_profile", "TEXT"],
|
|
374
438
|
["warnings", "TEXT"],
|
|
375
439
|
["read_scope", "TEXT"],
|
|
440
|
+
["companion_identity", "TEXT"],
|
|
441
|
+
["kimi_identity", "TEXT"],
|
|
376
442
|
];
|
|
377
443
|
/** Columns createJob writes, in INSERT order. hook_escapes is written only by updates. */
|
|
378
444
|
const INSERT_JOB_COLUMNS = [
|
|
379
445
|
"job_id", "repo_id", "command_type", "created_at", "updated_at", "cwd", "model", "thinking", "thinking_effort",
|
|
380
|
-
"background", "pid", "kimi_pid", "status", "kimi_session_id", "kimi_session_id_source", "budget_source",
|
|
446
|
+
"background", "pid", "kimi_pid", "companion_identity", "kimi_identity", "status", "kimi_session_id", "kimi_session_id_source", "budget_source",
|
|
381
447
|
"operation_kind", "intended_engine", "observed_engine", "kimi_version", "system_version",
|
|
382
448
|
"kimi_command", "kimi_prefix_args", "plan_certification", "resumed_from_job_id", "safety_profile", "warnings",
|
|
383
449
|
"read_scope", "agent_profile", "prompt_digest", "summary", "phase", "budget_ms", "final_output_path", "stream_log_path", "error",
|
|
@@ -391,11 +457,13 @@ const UPDATABLE_JOB_COLUMNS = new Set([
|
|
|
391
457
|
function hydrateRow(row) {
|
|
392
458
|
// A warning-free row keeps its historical shape, so every JSON surface that
|
|
393
459
|
// spreads a JobRecord stays byte-identical.
|
|
394
|
-
const { warnings, read_scope, ...rest } = row;
|
|
460
|
+
const { warnings, read_scope, companion_identity, kimi_identity, ...rest } = row;
|
|
395
461
|
return {
|
|
396
462
|
...rest,
|
|
397
463
|
...(warnings !== null && warnings !== undefined ? { warnings } : {}),
|
|
398
464
|
...(read_scope !== null && read_scope !== undefined ? { read_scope } : {}),
|
|
465
|
+
...(companion_identity !== null && companion_identity !== undefined ? { companion_identity } : {}),
|
|
466
|
+
...(kimi_identity !== null && kimi_identity !== undefined ? { kimi_identity } : {}),
|
|
399
467
|
thinking: row.thinking === null ? null : Boolean(row.thinking),
|
|
400
468
|
background: Boolean(row.background),
|
|
401
469
|
error: row.error ? JSON.parse(row.error) : null,
|
|
@@ -573,7 +641,7 @@ function isSqliteConstraintError(error) {
|
|
|
573
641
|
}
|
|
574
642
|
function isSqliteBusyError(error) {
|
|
575
643
|
const message = formatError(error).toLowerCase();
|
|
576
|
-
return message.includes("database is locked") || message.includes("busy");
|
|
644
|
+
return message.includes("database is locked") || message.includes("busy") || message.includes("locking protocol");
|
|
577
645
|
}
|
|
578
646
|
function translateSqliteError(error) {
|
|
579
647
|
if (isSqliteBusyError(error)) {
|
package/dist/jobs.js
CHANGED
|
@@ -1,7 +1,51 @@
|
|
|
1
|
+
import { realpath } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import { RuntimeError } from "./errors.js";
|
|
4
|
+
import { readProcessIdentity } from "./process-tree.js";
|
|
2
5
|
import { capitalize, formatBudgetDuration, renderTerminalJobArtifact, writeArtifact } from "./render.js";
|
|
3
6
|
import { sleep } from "./util.js";
|
|
4
7
|
export { sha256 as digestPrompt } from "./git.js";
|
|
8
|
+
export async function serializedProcessIdentity(pid) {
|
|
9
|
+
const identity = await readProcessIdentity(pid);
|
|
10
|
+
return identity ? JSON.stringify(identity) : null;
|
|
11
|
+
}
|
|
12
|
+
export async function recordKimiSpawnIdentity(store, jobId, pid) {
|
|
13
|
+
store.updateRunningJob(jobId, { kimi_pid: pid });
|
|
14
|
+
const identity = await serializedProcessIdentity(pid);
|
|
15
|
+
if (identity) {
|
|
16
|
+
store.updateRunningJob(jobId, { kimi_identity: identity });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function canonicalizeMaybeDeletedPath(target) {
|
|
20
|
+
if (!path.isAbsolute(target))
|
|
21
|
+
return null;
|
|
22
|
+
let current = path.resolve(target);
|
|
23
|
+
const tail = [];
|
|
24
|
+
for (;;) {
|
|
25
|
+
try {
|
|
26
|
+
const resolved = await realpath(current);
|
|
27
|
+
return tail.length === 0 ? resolved : path.join(resolved, ...tail.reverse());
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const code = error.code;
|
|
31
|
+
if (code !== "ENOENT" && code !== "ENOTDIR")
|
|
32
|
+
return null;
|
|
33
|
+
const parent = path.dirname(current);
|
|
34
|
+
if (parent === current)
|
|
35
|
+
return null;
|
|
36
|
+
tail.push(path.basename(current));
|
|
37
|
+
current = parent;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function isPathWithinCanonicalRoot(canonicalRoot, canonicalCandidate) {
|
|
42
|
+
const relative = path.relative(canonicalRoot, canonicalCandidate);
|
|
43
|
+
return relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
|
|
44
|
+
}
|
|
45
|
+
export async function isCwdWithinWorkspace(candidateCwd, canonicalWorkspaceCwd) {
|
|
46
|
+
const resolved = await canonicalizeMaybeDeletedPath(candidateCwd);
|
|
47
|
+
return resolved !== null && isPathWithinCanonicalRoot(canonicalWorkspaceCwd, resolved);
|
|
48
|
+
}
|
|
5
49
|
export function normalizeJobError(error) {
|
|
6
50
|
if (error instanceof RuntimeError) {
|
|
7
51
|
const normalized = {
|
|
@@ -78,8 +122,16 @@ export async function markJobCancelled(store, paths, job, summary, error, option
|
|
|
78
122
|
...(phase !== undefined ? { phase } : {}),
|
|
79
123
|
}) ?? artifactJob);
|
|
80
124
|
}
|
|
81
|
-
export async function sweepStaleJobs(store, paths) {
|
|
125
|
+
export async function sweepStaleJobs(store, paths, scope) {
|
|
126
|
+
const canonicalScopeCwd = scope?.workspaceCwd
|
|
127
|
+
? await canonicalizeMaybeDeletedPath(scope.workspaceCwd)
|
|
128
|
+
: null;
|
|
82
129
|
for (const job of store.listRunningJobsWithProcessHints()) {
|
|
130
|
+
if (scope?.repoId !== undefined && job.repo_id !== scope.repoId)
|
|
131
|
+
continue;
|
|
132
|
+
if (canonicalScopeCwd !== null && !(await isCwdWithinWorkspace(job.cwd, canonicalScopeCwd))) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
83
135
|
if (store.getMcpTask(job.job_id))
|
|
84
136
|
continue;
|
|
85
137
|
// Recovery owns orphaned swarm resources; PID-only sweeping must not signal replacements.
|
package/dist/kimi-engine.js
CHANGED
|
@@ -7,21 +7,20 @@ import { resolveKimiHome } from "./kimi-home.js";
|
|
|
7
7
|
import { formatVersionChoice, kimiVersionsInScope, kimiVersionsWith, resolveKimiRelease } from "./kimi-releases.js";
|
|
8
8
|
import { hookGateRefusal, verifyHookInstalled } from "./hooks/install.js";
|
|
9
9
|
import { assertNativeV2Preflight } from "./native-v2-preflight.js";
|
|
10
|
-
import {
|
|
10
|
+
import { KIMI_MINIMUM_CERTIFIED_VERSION, parseVersionLine, probeKimiVersion, } from "./kimi-version-probe.js";
|
|
11
11
|
import { isRecord } from "./util.js";
|
|
12
12
|
/**
|
|
13
13
|
* The user-visible operation actually being performed. This is deliberately
|
|
14
14
|
* separate from JobRecord.command_type: pursue and swarm-write reuse the
|
|
15
15
|
* rescue job lineage, while read-only swarm reuses review.
|
|
16
16
|
*/
|
|
17
|
-
const NON_SWARM_OPERATION_KINDS = ["review", "challenge", "ask", "rescue", "
|
|
17
|
+
const NON_SWARM_OPERATION_KINDS = ["review", "challenge", "ask", "rescue", "pursue"];
|
|
18
18
|
const OPERATION_KINDS = [...NON_SWARM_OPERATION_KINDS, "swarm", "swarm-write"];
|
|
19
|
-
/** Operations that may run on an uncertified release. Every write or swarm operation stays exact. */
|
|
19
|
+
/** Operations that may run on an uncertified release (> 2.8.0). Every write or swarm operation stays exact. */
|
|
20
20
|
const UNCERTIFIED_READ_ONLY_OPERATIONS = new Set([
|
|
21
21
|
"ask",
|
|
22
22
|
"review",
|
|
23
23
|
"challenge",
|
|
24
|
-
"review_gate",
|
|
25
24
|
]);
|
|
26
25
|
/** Restores exact-version refusal for every operation. */
|
|
27
26
|
export const STRICT_VERSIONS_ENV = "KIMI_PLUGIN_CC_STRICT_VERSIONS";
|
|
@@ -45,35 +44,19 @@ export function resolveNativeV2Certification(operationKind, version, env) {
|
|
|
45
44
|
return resolved !== null && !resolved.certified ? "uncertified" : null;
|
|
46
45
|
}
|
|
47
46
|
export const NATIVE_V2_SAFETY_PROFILE = "native-v2-no-plan/1";
|
|
48
|
-
/**
|
|
49
|
-
* Minimum legacy-v1 version that actually contains each operation. The upper
|
|
50
|
-
* boundary is KIMI_TESTED_MINORS, enforced by probe.inTestedRange.
|
|
51
|
-
*/
|
|
52
|
-
const LEGACY_V1_MINIMUMS = {
|
|
53
|
-
review: { major: 0, minor: 1 },
|
|
54
|
-
challenge: { major: 0, minor: 1 },
|
|
55
|
-
ask: { major: 0, minor: 1 },
|
|
56
|
-
rescue: { major: 0, minor: 1 },
|
|
57
|
-
review_gate: { major: 0, minor: 1 },
|
|
58
|
-
pursue: { major: 0, minor: 8 },
|
|
59
|
-
swarm: { major: 0, minor: 12 },
|
|
60
|
-
"swarm-write": { major: 0, minor: 18 },
|
|
61
|
-
};
|
|
62
47
|
/**
|
|
63
48
|
* Exact kimi-code releases certified for native v2 under
|
|
64
49
|
* NATIVE_V2_SAFETY_PROFILE. Exact, not minor-ranged: upstream ships
|
|
65
50
|
* behavioural changes in patch releases, and the no-plan construction must be
|
|
66
51
|
* re-proven (mechanized tag scan + real-binary smoke) per tag before a row is
|
|
67
52
|
* added to KIMI_V2_RELEASES in kimi-releases.ts with scope "all". Each entry
|
|
68
|
-
* has its own row in tests/audit/v2-tag-scan.test.ts and
|
|
69
|
-
*
|
|
53
|
+
* has its own row in tests/audit/v2-tag-scan.test.ts and an active
|
|
54
|
+
* certification record in docs/upstream-<version>-certification.md.
|
|
70
55
|
*/
|
|
71
56
|
export const NATIVE_V2_CERTIFIED_VERSIONS = Object.freeze([...kimiVersionsInScope("all")]);
|
|
72
57
|
/**
|
|
73
|
-
* Exact releases certified only for
|
|
74
|
-
*
|
|
75
|
-
* configured maximum, and these releases lack a certified plugin admission
|
|
76
|
-
* construction, so both swarm operations refuse before model spawn.
|
|
58
|
+
* Exact releases certified only for non-swarm operations. Empty in the 2.8.0+
|
|
59
|
+
* rolling window, kept exported so callers/diagnostics checking scope compile cleanly.
|
|
77
60
|
*/
|
|
78
61
|
export const NATIVE_V2_NON_SWARM_VERSIONS = Object.freeze([...kimiVersionsInScope("non-swarm")]);
|
|
79
62
|
/**
|
|
@@ -91,7 +74,6 @@ export const NATIVE_V2_CERTIFIED = new Map([
|
|
|
91
74
|
["challenge", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
92
75
|
["ask", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
93
76
|
["rescue", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
94
|
-
["review_gate", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
95
77
|
["pursue", NATIVE_V2_ANY_OPERATION_VERSIONS],
|
|
96
78
|
["swarm", NATIVE_V2_CERTIFIED_VERSIONS],
|
|
97
79
|
["swarm-write", NATIVE_V2_CERTIFIED_VERSIONS],
|
|
@@ -104,9 +86,6 @@ export function isNativeV2Certified(operationKind, version) {
|
|
|
104
86
|
}
|
|
105
87
|
/**
|
|
106
88
|
* True when this exact version is certified for native v2 for ANY operation.
|
|
107
|
-
* Used by setup to phrase its version notice: a v2-certified version is NOT an
|
|
108
|
-
* "out of tested range, will refuse" case even though it is outside the legacy
|
|
109
|
-
* `KIMI_TESTED_MINORS` table (that table intentionally never gains 0.42).
|
|
110
89
|
*/
|
|
111
90
|
export function isNativeV2CertifiedVersion(version) {
|
|
112
91
|
const normalized = parseVersionLine(version)?.raw;
|
|
@@ -115,35 +94,30 @@ export function isNativeV2CertifiedVersion(version) {
|
|
|
115
94
|
return NATIVE_V2_ANY_OPERATION_VERSIONS.includes(normalized);
|
|
116
95
|
}
|
|
117
96
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* at 0.42.0), so its refusal names the native-v2 set.
|
|
97
|
+
* All kimi-code releases >= 2.8.0 use native agent-core-v2. Legacy-v1
|
|
98
|
+
* (0.1–0.41) and < 2.8.0 shims are no longer supported; assertCertifiedCapability
|
|
99
|
+
* enforces the exact 2.8.0+ window.
|
|
122
100
|
*/
|
|
123
|
-
export function selectIntendedEngine(
|
|
124
|
-
|
|
125
|
-
return "native-v2";
|
|
126
|
-
}
|
|
127
|
-
const parsed = parseVersionLine(probe.version);
|
|
128
|
-
return parsed !== undefined && parsed.major >= 2 ? "native-v2" : "legacy-v1";
|
|
101
|
+
export function selectIntendedEngine(_operationKind, _probe) {
|
|
102
|
+
return "native-v2";
|
|
129
103
|
}
|
|
130
104
|
const UNSAFE_EXPERIMENTAL_VALUES = new Set(["1", "true", "yes", "on"]);
|
|
131
105
|
/**
|
|
132
|
-
* Refuse the
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
* this at the final spawn boundary in
|
|
138
|
-
* creation.
|
|
106
|
+
* Refuse the master experimental flag for legacy-v1 and plan-less launches.
|
|
107
|
+
* A native-v2 plan is exempt, certified or not: upstream reads the master flag
|
|
108
|
+
* only from the child's own environment (flagService via bootstrap.getEnv,
|
|
109
|
+
* 0.42.0-2.8.0), and buildKimiCliEnvironment deletes it from every native-v2
|
|
110
|
+
* child. An uncertified plan gets a launch warning from the preflight instead.
|
|
111
|
+
* cli-client and swarm activation repeat this at the final spawn boundary in
|
|
112
|
+
* case the environment changed after plan creation.
|
|
139
113
|
*/
|
|
140
114
|
export function assertNoUnsafeExperimentalSelector(env, stage = "kimi-engine.plan", plan) {
|
|
141
115
|
const enabled = UNSAFE_EXPERIMENTAL_VALUES.has((env.KIMI_CODE_EXPERIMENTAL_FLAG ?? "").trim().toLowerCase());
|
|
142
116
|
if (!enabled)
|
|
143
117
|
return;
|
|
144
|
-
if (plan?.intendedEngine === "native-v2"
|
|
118
|
+
if (plan?.intendedEngine === "native-v2")
|
|
145
119
|
return;
|
|
146
|
-
throw new RuntimeError("CLI_V2_HOOK_ORDER_UNSAFE", "Refusing kimi-code experimental features: the master KIMI_CODE_EXPERIMENTAL_FLAG
|
|
120
|
+
throw new RuntimeError("CLI_V2_HOOK_ORDER_UNSAFE", "Refusing kimi-code experimental features: the master KIMI_CODE_EXPERIMENTAL_FLAG is set and this launch is not a native-v2 plan, so kimi-plugin-cc cannot keep it from the Kimi process. Unset KIMI_CODE_EXPERIMENTAL_FLAG and retry.", stage, {
|
|
147
121
|
details: {
|
|
148
122
|
refusal_kind: "v2-hook-order-unsafe",
|
|
149
123
|
retryable_after_setup: false,
|
|
@@ -158,12 +132,18 @@ export function assertNoUnsafeExperimentalSelector(env, stage = "kimi-engine.pla
|
|
|
158
132
|
* alternate route between dispatch and execution.
|
|
159
133
|
*/
|
|
160
134
|
export async function prepareKimiExecutionPlan(options) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
135
|
+
if (options.intendedEngine === "legacy-v1") {
|
|
136
|
+
throw new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${options.operationKind}: legacy-v1 is unsupported in 3.1.0+; use kimi-code >= ${KIMI_MINIMUM_CERTIFIED_VERSION}.`, "kimi-engine.plan", {
|
|
137
|
+
details: {
|
|
138
|
+
refusal_kind: "legacy-v1-unsupported",
|
|
139
|
+
retryable_after_setup: false,
|
|
140
|
+
operation_kind: options.operationKind,
|
|
141
|
+
intended_engine: "legacy-v1",
|
|
142
|
+
minimum_version: KIMI_MINIMUM_CERTIFIED_VERSION,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (!NATIVE_V2_CERTIFIED.has(options.operationKind)) {
|
|
167
147
|
throw nativeV2NotCertified(options.operationKind, null);
|
|
168
148
|
}
|
|
169
149
|
const kimi = resolveKimiCliCommand(options.env);
|
|
@@ -187,9 +167,9 @@ export async function prepareKimiExecutionPlan(options) {
|
|
|
187
167
|
warnings.push(...preflight.warnings);
|
|
188
168
|
};
|
|
189
169
|
if (options.env.KIMI_PLUGIN_CC_SKIP_VERSION_PROBE === "1") {
|
|
190
|
-
const intendedEngine =
|
|
191
|
-
const safetyProfile = intendedEngine === "native-v2" ? NATIVE_V2_SAFETY_PROFILE : null;
|
|
192
|
-
assertNoUnsafeExperimentalSelector(options.env, "kimi-engine.plan", { intendedEngine
|
|
170
|
+
const intendedEngine = "native-v2";
|
|
171
|
+
const safetyProfile = options.intendedEngine === "native-v2" ? NATIVE_V2_SAFETY_PROFILE : null;
|
|
172
|
+
assertNoUnsafeExperimentalSelector(options.env, "kimi-engine.plan", { intendedEngine });
|
|
193
173
|
await runPreflight(intendedEngine, { kimiVersion: null, certification: "test-bypass" });
|
|
194
174
|
warnings.push(...await planHookCheck(options.operationKind, options.env, options.stderr));
|
|
195
175
|
return finishPlan({
|
|
@@ -211,7 +191,7 @@ export async function prepareKimiExecutionPlan(options) {
|
|
|
211
191
|
env: withoutExperimentalMasterFlag(options.env),
|
|
212
192
|
});
|
|
213
193
|
if (probe.kind !== "ok") {
|
|
214
|
-
throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because the exact command/version plan could not be established: ${probe.reason}. Run
|
|
194
|
+
throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because the exact command/version plan could not be established: ${probe.reason}. Run \`kimi_setup\` (or \`scripts/companion.sh setup\`) to verify the active binary, or correct KIMI_PLUGIN_CC_KIMI_BIN / KIMI_PLUGIN_CC_KIMI_PREFIX_ARGS and retry.`, "kimi-engine.plan", {
|
|
215
195
|
details: {
|
|
216
196
|
operation_kind: options.operationKind,
|
|
217
197
|
intended_engine: options.intendedEngine ?? null,
|
|
@@ -223,7 +203,7 @@ export async function prepareKimiExecutionPlan(options) {
|
|
|
223
203
|
const intendedEngine = options.intendedEngine ?? selectIntendedEngine(options.operationKind, probe);
|
|
224
204
|
const safetyProfile = intendedEngine === "native-v2" ? NATIVE_V2_SAFETY_PROFILE : null;
|
|
225
205
|
const certification = assertCertifiedCapability(intendedEngine, options.operationKind, probe, options.env);
|
|
226
|
-
assertNoUnsafeExperimentalSelector(options.env, "kimi-engine.plan", { intendedEngine
|
|
206
|
+
assertNoUnsafeExperimentalSelector(options.env, "kimi-engine.plan", { intendedEngine });
|
|
227
207
|
if (certification === "uncertified") {
|
|
228
208
|
const borrowed = resolveKimiRelease(probe.version).release.version;
|
|
229
209
|
warnings.push(`kimi-code ${probe.version} is not certified by this plugin release; running ${options.operationKind} read-only with ${borrowed} mechanics.`);
|
|
@@ -552,47 +532,42 @@ export function classifyHistoricalEngineProvenance(contents) {
|
|
|
552
532
|
conflict,
|
|
553
533
|
};
|
|
554
534
|
}
|
|
535
|
+
function isBelowMinimumVersion(probe) {
|
|
536
|
+
const min = parseVersionLine(KIMI_MINIMUM_CERTIFIED_VERSION);
|
|
537
|
+
if (min === undefined)
|
|
538
|
+
return false;
|
|
539
|
+
if (probe.major !== min.major)
|
|
540
|
+
return probe.major < min.major;
|
|
541
|
+
if (probe.minor !== min.minor)
|
|
542
|
+
return probe.minor < min.minor;
|
|
543
|
+
return probe.patch < min.patch;
|
|
544
|
+
}
|
|
555
545
|
function assertCertifiedCapability(engine, operationKind, probe, env) {
|
|
556
|
-
if (engine
|
|
557
|
-
|
|
558
|
-
if (certification === null)
|
|
559
|
-
throw nativeV2NotCertified(operationKind, probe.version, env);
|
|
560
|
-
return certification;
|
|
561
|
-
}
|
|
562
|
-
const minimum = LEGACY_V1_MINIMUMS[operationKind];
|
|
563
|
-
const meetsMinimum = probe.major > minimum.major ||
|
|
564
|
-
(probe.major === minimum.major && probe.minor >= minimum.minor);
|
|
565
|
-
if (!probe.inTestedRange || !meetsMinimum) {
|
|
566
|
-
const remedy = !probe.inTestedRange
|
|
567
|
-
? "Update kimi-plugin-cc to a release that certifies this kimi-code minor, or point KIMI_PLUGIN_CC_KIMI_BIN at a certified binary."
|
|
568
|
-
: `Upgrade kimi-code to at least ${minimum.major}.${minimum.minor}.0 within a certified minor.`;
|
|
569
|
-
throw new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${probe.version} is not in this operation's certified legacy-v1 range. ${remedy} KIMI_PLUGIN_CC_SKIP_VERSION_PROBE is a test/smoke seam, not a production repair path.`, "kimi-engine.capability", {
|
|
546
|
+
if (engine !== "native-v2" || isBelowMinimumVersion(probe)) {
|
|
547
|
+
throw new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${probe.version} is below the >= ${KIMI_MINIMUM_CERTIFIED_VERSION} rolling window supported by 3.1.0+. Run \`kimi_setup\` with action "install_kimi" (or \`setup --install-kimi\`) or point KIMI_PLUGIN_CC_KIMI_BIN at kimi-code >= ${KIMI_MINIMUM_CERTIFIED_VERSION}.`, "kimi-engine.capability", {
|
|
570
548
|
details: {
|
|
571
|
-
refusal_kind: "v1-
|
|
549
|
+
refusal_kind: "legacy-v1-unsupported",
|
|
572
550
|
retryable_after_setup: false,
|
|
573
551
|
operation_kind: operationKind,
|
|
574
552
|
intended_engine: engine,
|
|
575
553
|
kimi_version: probe.version,
|
|
576
|
-
minimum_version:
|
|
577
|
-
tested_minor: probe.inTestedRange,
|
|
554
|
+
minimum_version: KIMI_MINIMUM_CERTIFIED_VERSION,
|
|
578
555
|
},
|
|
579
556
|
});
|
|
580
557
|
}
|
|
581
|
-
|
|
558
|
+
const certification = resolveNativeV2Certification(operationKind, probe.version, env);
|
|
559
|
+
if (certification === null)
|
|
560
|
+
throw nativeV2NotCertified(operationKind, probe.version, env);
|
|
561
|
+
return certification;
|
|
582
562
|
}
|
|
583
563
|
/**
|
|
584
564
|
* Revalidate the persisted certification at the final subprocess boundary.
|
|
585
565
|
* This keeps a corrupt/forged SQLite row from converting a once-certified plan
|
|
586
|
-
* into an untested-version or
|
|
566
|
+
* into an untested-version or legacy spawn.
|
|
587
567
|
*/
|
|
588
568
|
function assertPlanCertification(plan, env) {
|
|
589
|
-
if (plan.intendedEngine
|
|
590
|
-
|
|
591
|
-
// was certified under.
|
|
592
|
-
throw invalidPersistedPlan("native-v2 plans require the native-v2-no-plan safety profile");
|
|
593
|
-
}
|
|
594
|
-
if (plan.intendedEngine === "legacy-v1" && plan.safetyProfile !== null) {
|
|
595
|
-
throw invalidPersistedPlan("legacy-v1 plans must not carry a safety profile");
|
|
569
|
+
if (plan.intendedEngine !== "native-v2") {
|
|
570
|
+
throw invalidPersistedPlan("only native-v2 plans are supported at the spawn boundary");
|
|
596
571
|
}
|
|
597
572
|
if (plan.certification === "test-bypass") {
|
|
598
573
|
if (plan.kimiVersion !== null) {
|
|
@@ -603,6 +578,11 @@ function assertPlanCertification(plan, env) {
|
|
|
603
578
|
}
|
|
604
579
|
return;
|
|
605
580
|
}
|
|
581
|
+
if (plan.safetyProfile !== NATIVE_V2_SAFETY_PROFILE) {
|
|
582
|
+
// A forged/deserialized v2 row cannot reach spawn without the profile it
|
|
583
|
+
// was certified under.
|
|
584
|
+
throw invalidPersistedPlan("native-v2 plans require the native-v2-no-plan safety profile");
|
|
585
|
+
}
|
|
606
586
|
if (plan.kimiVersion === null) {
|
|
607
587
|
throw invalidPersistedPlan(`${plan.certification} plans require kimi_version`);
|
|
608
588
|
}
|
|
@@ -610,9 +590,6 @@ function assertPlanCertification(plan, env) {
|
|
|
610
590
|
if (parsed === undefined) {
|
|
611
591
|
throw invalidPersistedPlan("kimi_version is not a parseable semantic version");
|
|
612
592
|
}
|
|
613
|
-
if (plan.certification === "uncertified" && plan.intendedEngine !== "native-v2") {
|
|
614
|
-
throw invalidPersistedPlan("uncertified plans must use native-v2");
|
|
615
|
-
}
|
|
616
593
|
// Recompute from the release table and the current environment: a strict
|
|
617
594
|
// environment, a write operation, or a row that has since been added all
|
|
618
595
|
// refuse a plan whose recorded certification no longer matches.
|
|
@@ -622,7 +599,6 @@ function assertPlanCertification(plan, env) {
|
|
|
622
599
|
major: parsed.major,
|
|
623
600
|
minor: parsed.minor,
|
|
624
601
|
patch: parsed.patch,
|
|
625
|
-
inTestedRange: isInTestedRange(parsed.major, parsed.minor),
|
|
626
602
|
}, env);
|
|
627
603
|
if (certification !== plan.certification) {
|
|
628
604
|
// A plan claiming exact certification for an uncertified release keeps the
|
|
@@ -671,7 +647,7 @@ function nativeV2NotCertified(operationKind, version, env = {}) {
|
|
|
671
647
|
if (normalized !== undefined &&
|
|
672
648
|
NATIVE_V2_NON_SWARM_VERSIONS.includes(normalized) &&
|
|
673
649
|
(operationKind === "swarm" || operationKind === "swarm-write")) {
|
|
674
|
-
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${normalized} is certified only for non-swarm operations (review, challenge, ask, rescue,
|
|
650
|
+
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind}: kimi-code ${normalized} is certified only for non-swarm operations (review, challenge, ask, rescue, pursue). Its native rate-limit recovery can exceed AgentSwarm's configured maximum, so this exact release refuses swarm before model spawn. Select exact kimi-code ${formatVersionChoice(kimiVersionsWith("bounded-swarm"))} for this plugin's certified bounded waves and single-worker path, or use a non-swarm operation on ${normalized}.`, "kimi-engine.capability", {
|
|
675
651
|
details: {
|
|
676
652
|
refusal_kind: "v2-swarm-not-certified",
|
|
677
653
|
certification_scope: "non-swarm",
|
|
@@ -690,8 +666,8 @@ function nativeV2NotCertified(operationKind, version, env = {}) {
|
|
|
690
666
|
? ""
|
|
691
667
|
: strictVersions(env)
|
|
692
668
|
? ` ${STRICT_VERSIONS_ENV}=1 is set, so read-only operations on this uncertified release also refuse.`
|
|
693
|
-
: " Read-only operations (ask, review, challenge
|
|
694
|
-
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind} on native v2: ${observed} is not in this operation's exactly certified set [${certified.join(", ")}].${readOnlyNote} Run setup --install-kimi to
|
|
669
|
+
: " Read-only operations (ask, review, challenge) still run on this uncertified release with a warning; write and swarm operations need an exact certified release.";
|
|
670
|
+
return new RuntimeError("KIMI_CAPABILITY_NOT_CERTIFIED", `Refusing ${operationKind} on native v2: ${observed} is not in this operation's exactly certified set [${certified.join(", ")}] (rolling window >= ${KIMI_MINIMUM_CERTIFIED_VERSION}).${readOnlyNote} Run \`kimi_setup\` with action "install_kimi" (or \`setup --install-kimi\`) to install the newest certified kimi-code, update kimi-plugin-cc, or point KIMI_PLUGIN_CC_KIMI_BIN at a certified binary.`, "kimi-engine.capability", {
|
|
695
671
|
details: {
|
|
696
672
|
refusal_kind: "v2-version-not-certified",
|
|
697
673
|
retryable_after_setup: false,
|
|
@@ -733,7 +709,7 @@ async function resolveExactExecutable(command, cwd, env) {
|
|
|
733
709
|
catch {
|
|
734
710
|
}
|
|
735
711
|
}
|
|
736
|
-
throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because executable ${JSON.stringify(command)} could not be resolved to an exact runnable path. Run
|
|
712
|
+
throw new RuntimeError("KIMI_EXECUTION_PLAN_UNRESOLVED", `Refusing to spawn kimi because executable ${JSON.stringify(command)} could not be resolved to an exact runnable path. Run \`kimi_setup\` (or \`scripts/companion.sh setup\`) to verify the active binary, or correct KIMI_PLUGIN_CC_KIMI_BIN and retry.`, "kimi-engine.plan", { details: { command, cwd } });
|
|
737
713
|
}
|
|
738
714
|
function parseProtocolVersion(value) {
|
|
739
715
|
const match = value.match(/^(\d+)\.(\d+)(?:\.\d+)?$/);
|
package/dist/kimi-errors.js
CHANGED
|
@@ -24,7 +24,7 @@ export function classifyManagedCommandFailure(error, commandType, jobId, options
|
|
|
24
24
|
if (!classification) {
|
|
25
25
|
return error instanceof Error ? error : new Error(String(error));
|
|
26
26
|
}
|
|
27
|
-
if (classification.kind === "response_timeout" &&
|
|
27
|
+
if (classification.kind === "response_timeout" && options?.background !== undefined) {
|
|
28
28
|
const foregroundAdvice = !options?.background && (commandType === "ask" || commandType === "rescue")
|
|
29
29
|
? " Or run with --background so the caller's shell timeout is not the limit."
|
|
30
30
|
: "";
|