kimi-plugin-cc 2.7.2 → 3.0.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +3 -5
- package/CHANGELOG.md +78 -1
- package/README.md +505 -448
- package/agents/kimi-pursue.md +6 -6
- package/agents/kimi-review.md +22 -22
- package/agents/kimi-swarm.md +25 -23
- package/agents/{kimi-ask.md → kimi-task.md} +34 -30
- package/commands/README.md +4 -6
- package/commands/pursue.md +1 -1
- package/commands/review.md +8 -3
- package/commands/setup.md +4 -2
- package/commands/swarm.md +6 -5
- package/commands/{rescue.md → task.md} +13 -11
- package/dist/background-spawn.js +10 -17
- package/dist/cli-client.js +65 -46
- package/dist/commands/ask.js +22 -89
- package/dist/commands/cancel.js +7 -46
- package/dist/commands/cli-helpers.js +102 -1
- package/dist/commands/models.js +2 -3
- package/dist/commands/pursue.js +5 -19
- package/dist/commands/repair-sessions.js +118 -12
- package/dist/commands/rescue.js +12 -82
- package/dist/commands/result.js +7 -1
- package/dist/commands/review-gate.js +1 -0
- package/dist/commands/review.js +12 -15
- package/dist/commands/setup.js +606 -270
- package/dist/commands/status.js +2 -2
- package/dist/commands/swarm.js +93 -119
- package/dist/commands/worker.js +1 -2
- package/dist/companion.js +3 -1
- package/dist/dsh/index.js +15 -17
- package/dist/git.js +1 -9
- package/dist/help.js +3 -3
- package/dist/hooks/approval-hook.js +41 -0
- package/dist/hooks/approval-policy.js +72 -10
- package/dist/hooks/config-safety.js +19 -42
- package/dist/hooks/hook-timing.js +48 -0
- package/dist/hooks/install.js +206 -11
- package/dist/hooks/managed-block.js +78 -33
- package/dist/job-store.js +100 -128
- package/dist/jobs.js +14 -19
- package/dist/kimi-command.js +74 -1
- package/dist/kimi-engine.js +170 -74
- package/dist/kimi-errors.js +14 -69
- package/dist/kimi-home.js +6 -0
- package/dist/kimi-journal.js +41 -0
- package/dist/kimi-releases.js +144 -0
- package/dist/kimi-timeouts.js +1 -1
- package/dist/kimi-version-probe.js +12 -48
- package/dist/mcp/job-control.js +4 -6
- package/dist/mcp/launcher.js +12 -6
- package/dist/mcp/operations.js +50 -18
- package/dist/mcp/protocol.js +16 -14
- package/dist/mcp/stdio.js +3 -2
- package/dist/model-command.js +5 -3
- package/dist/native-v2-preflight.js +139 -68
- package/dist/parsing.js +171 -237
- package/dist/paths.js +8 -0
- package/dist/process-tree.js +35 -24
- package/dist/read-scope.js +435 -0
- package/dist/render.js +46 -9
- package/dist/rescue-approval.js +461 -84
- package/dist/schemas/review-gate-output.js +3 -5
- package/dist/session-title.js +25 -5
- package/dist/stream-json.js +1 -3
- package/dist/surface-routing.js +21 -0
- package/dist/swarm-activation.js +74 -77
- package/dist/swarm-policy.js +2 -1
- package/dist/swarm-recovery.js +2 -1
- package/dist/util.js +28 -0
- package/dist/version.js +1 -1
- package/docs/migration.md +27 -6
- package/docs/models.md +2 -2
- package/docs/registry-releases.md +3 -1
- package/docs/safety.md +131 -81
- package/docs/session-visibility.md +5 -3
- package/docs/swarm-recovery.md +4 -4
- package/docs/upstream-2.7.2-certification.md +16 -2
- package/docs/upstream-2.7.3-certification.md +95 -0
- package/package.json +2 -1
- package/plugins/kimi-codex/.codex-plugin/plugin.json +3 -3
- package/plugins/kimi-codex/.mcp.json +1 -0
- package/plugins/kimi-codex/dist/background-spawn.js +10 -17
- package/plugins/kimi-codex/dist/cli-client.js +65 -46
- package/plugins/kimi-codex/dist/commands/ask.js +22 -89
- package/plugins/kimi-codex/dist/commands/cancel.js +7 -46
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
- package/plugins/kimi-codex/dist/commands/models.js +2 -3
- package/plugins/kimi-codex/dist/commands/pursue.js +5 -19
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +118 -12
- package/plugins/kimi-codex/dist/commands/rescue.js +12 -82
- package/plugins/kimi-codex/dist/commands/result.js +7 -1
- package/plugins/kimi-codex/dist/commands/review-gate.js +1 -0
- package/plugins/kimi-codex/dist/commands/review.js +12 -15
- package/plugins/kimi-codex/dist/commands/setup.js +606 -270
- package/plugins/kimi-codex/dist/commands/status.js +2 -2
- package/plugins/kimi-codex/dist/commands/swarm.js +93 -119
- package/plugins/kimi-codex/dist/commands/worker.js +1 -2
- package/plugins/kimi-codex/dist/companion.js +3 -1
- package/plugins/kimi-codex/dist/dsh/index.js +15 -17
- package/plugins/kimi-codex/dist/git.js +1 -9
- package/plugins/kimi-codex/dist/help.js +3 -3
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +41 -0
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +72 -10
- package/plugins/kimi-codex/dist/hooks/config-safety.js +19 -42
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-codex/dist/hooks/install.js +206 -11
- package/plugins/kimi-codex/dist/hooks/managed-block.js +78 -33
- package/plugins/kimi-codex/dist/job-store.js +100 -128
- package/plugins/kimi-codex/dist/jobs.js +14 -19
- package/plugins/kimi-codex/dist/kimi-command.js +74 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +170 -74
- package/plugins/kimi-codex/dist/kimi-errors.js +14 -69
- package/plugins/kimi-codex/dist/kimi-home.js +6 -0
- package/plugins/kimi-codex/dist/kimi-journal.js +41 -0
- package/plugins/kimi-codex/dist/kimi-releases.js +144 -0
- package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -1
- package/plugins/kimi-codex/dist/kimi-version-probe.js +12 -48
- package/plugins/kimi-codex/dist/mcp/job-control.js +4 -6
- package/plugins/kimi-codex/dist/mcp/launcher.js +12 -6
- package/plugins/kimi-codex/dist/mcp/operations.js +50 -18
- package/plugins/kimi-codex/dist/mcp/protocol.js +16 -14
- package/plugins/kimi-codex/dist/mcp/stdio.js +3 -2
- package/plugins/kimi-codex/dist/model-command.js +5 -3
- package/plugins/kimi-codex/dist/native-v2-preflight.js +139 -68
- package/plugins/kimi-codex/dist/parsing.js +171 -237
- package/plugins/kimi-codex/dist/paths.js +8 -0
- package/plugins/kimi-codex/dist/process-tree.js +35 -24
- package/plugins/kimi-codex/dist/read-scope.js +435 -0
- package/plugins/kimi-codex/dist/render.js +46 -9
- package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +3 -5
- package/plugins/kimi-codex/dist/session-title.js +25 -5
- package/plugins/kimi-codex/dist/stream-json.js +1 -3
- package/plugins/kimi-codex/dist/surface-routing.js +21 -0
- package/plugins/kimi-codex/dist/swarm-activation.js +74 -77
- package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
- package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
- package/plugins/kimi-codex/dist/util.js +28 -0
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +1 -1
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +8 -7
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +1 -1
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +2 -1
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +8 -6
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +1 -1
- package/plugins/kimi-codex/skills/{kimi-ask → kimi-task}/SKILL.md +11 -9
- package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +6 -0
- package/plugins/kimi-dsh/README.md +3 -2
- package/plugins/kimi-dsh/dist/background-spawn.js +10 -17
- package/plugins/kimi-dsh/dist/cli-client.js +65 -46
- package/plugins/kimi-dsh/dist/commands/ask.js +22 -89
- package/plugins/kimi-dsh/dist/commands/cancel.js +7 -46
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +102 -1
- package/plugins/kimi-dsh/dist/commands/models.js +2 -3
- package/plugins/kimi-dsh/dist/commands/pursue.js +5 -19
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +118 -12
- package/plugins/kimi-dsh/dist/commands/rescue.js +12 -82
- package/plugins/kimi-dsh/dist/commands/result.js +7 -1
- package/plugins/kimi-dsh/dist/commands/review-gate.js +1 -0
- package/plugins/kimi-dsh/dist/commands/review.js +12 -15
- package/plugins/kimi-dsh/dist/commands/setup.js +606 -270
- package/plugins/kimi-dsh/dist/commands/status.js +2 -2
- package/plugins/kimi-dsh/dist/commands/swarm.js +93 -119
- package/plugins/kimi-dsh/dist/commands/worker.js +1 -2
- package/plugins/kimi-dsh/dist/companion.js +3 -1
- package/plugins/kimi-dsh/dist/dsh/index.js +15 -17
- package/plugins/kimi-dsh/dist/git.js +1 -9
- package/plugins/kimi-dsh/dist/help.js +3 -3
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +41 -0
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +72 -10
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +19 -42
- package/plugins/kimi-dsh/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-dsh/dist/hooks/install.js +206 -11
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +78 -33
- package/plugins/kimi-dsh/dist/job-store.js +100 -128
- package/plugins/kimi-dsh/dist/jobs.js +14 -19
- package/plugins/kimi-dsh/dist/kimi-command.js +74 -1
- package/plugins/kimi-dsh/dist/kimi-engine.js +170 -74
- package/plugins/kimi-dsh/dist/kimi-errors.js +14 -69
- package/plugins/kimi-dsh/dist/kimi-home.js +6 -0
- package/plugins/kimi-dsh/dist/kimi-journal.js +41 -0
- package/plugins/kimi-dsh/dist/kimi-releases.js +144 -0
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +1 -1
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +12 -48
- package/plugins/kimi-dsh/dist/mcp/job-control.js +4 -6
- package/plugins/kimi-dsh/dist/mcp/launcher.js +12 -6
- package/plugins/kimi-dsh/dist/mcp/operations.js +50 -18
- package/plugins/kimi-dsh/dist/mcp/protocol.js +16 -14
- package/plugins/kimi-dsh/dist/mcp/stdio.js +3 -2
- package/plugins/kimi-dsh/dist/model-command.js +5 -3
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +139 -68
- package/plugins/kimi-dsh/dist/parsing.js +171 -237
- package/plugins/kimi-dsh/dist/paths.js +8 -0
- package/plugins/kimi-dsh/dist/process-tree.js +35 -24
- package/plugins/kimi-dsh/dist/read-scope.js +435 -0
- package/plugins/kimi-dsh/dist/render.js +46 -9
- package/plugins/kimi-dsh/dist/rescue-approval.js +461 -84
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +3 -5
- package/plugins/kimi-dsh/dist/session-title.js +25 -5
- package/plugins/kimi-dsh/dist/stream-json.js +1 -3
- package/plugins/kimi-dsh/dist/surface-routing.js +21 -0
- package/plugins/kimi-dsh/dist/swarm-activation.js +74 -77
- package/plugins/kimi-dsh/dist/swarm-policy.js +2 -1
- package/plugins/kimi-dsh/dist/swarm-recovery.js +2 -1
- package/plugins/kimi-dsh/dist/util.js +28 -0
- package/plugins/kimi-dsh/dist/version.js +1 -1
- package/plugins/kimi-dsh/package.json +1 -1
- package/agents/kimi-challenge.md +0 -86
- package/agents/kimi-rescue.md +0 -92
- package/agents/kimi-swarm-write.md +0 -96
- package/commands/ask.md +0 -38
- package/commands/challenge.md +0 -35
- package/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
- package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
// B. the EnterPlanMode tool (already hook-denied for every label);
|
|
14
14
|
// C. resuming a session whose agent wire journal holds a durable
|
|
15
15
|
// `plan_mode.enter` record (restore() folds ONLY agents/*/wire.jsonl).
|
|
16
|
-
// This module closes A and C before any process is spawned
|
|
17
|
-
//
|
|
18
|
-
//
|
|
16
|
+
// This module closes A and C before any process is spawned and requires
|
|
17
|
+
// local execution for configured and resumed sessions. The v2-only
|
|
18
|
+
// experimental features (tower, subagent fork) are forced off for every
|
|
19
|
+
// child by per-flag env in cli-client.ts; only an uncertified release, whose
|
|
20
|
+
// flag names are unreviewed, still refuses an enabled selector here.
|
|
19
21
|
// B stays in runtime/hooks/approval-policy.ts.
|
|
20
22
|
//
|
|
21
23
|
// Contract:
|
|
@@ -29,8 +31,11 @@
|
|
|
29
31
|
import { constants as fsConstants } from "node:fs";
|
|
30
32
|
import { open, readdir } from "node:fs/promises";
|
|
31
33
|
import path from "node:path";
|
|
32
|
-
import { createInterface } from "node:readline";
|
|
33
34
|
import { RuntimeError } from "./errors.js";
|
|
35
|
+
import { kimiCodeConfigPath } from "./kimi-home.js";
|
|
36
|
+
import { kimiJournalRecords, UNPARSEABLE_JOURNAL_LINE } from "./kimi-journal.js";
|
|
37
|
+
import { kimiCertifiedReleaseHas } from "./kimi-releases.js";
|
|
38
|
+
import { tomlErrorLocation } from "./util.js";
|
|
34
39
|
import { parse as parseToml } from "./vendor/smol-toml/parse.js";
|
|
35
40
|
/** `<kimiHome>/config.toml` is small hand-edited config, never a data file. */
|
|
36
41
|
const CONFIG_MAX_BYTES = 1 * 1024 * 1024;
|
|
@@ -91,7 +96,7 @@ async function readSmallFileSafe(filePath, maxBytes) {
|
|
|
91
96
|
/** Read+parse `<kimiHome>/config.toml`. `config: null` means the file is
|
|
92
97
|
* absent (upstream default applies); any read/parse failure fails closed. */
|
|
93
98
|
async function readParsedConfig(kimiHome) {
|
|
94
|
-
const configPath =
|
|
99
|
+
const configPath = kimiCodeConfigPath(kimiHome);
|
|
95
100
|
const read = await readSmallFileSafe(configPath, CONFIG_MAX_BYTES);
|
|
96
101
|
if (read.kind === "absent")
|
|
97
102
|
return { kind: "ok", config: null };
|
|
@@ -104,7 +109,7 @@ async function readParsedConfig(kimiHome) {
|
|
|
104
109
|
catch (error) {
|
|
105
110
|
return {
|
|
106
111
|
kind: "unreadable",
|
|
107
|
-
reason: `${configPath} could not be parsed as TOML: ${error
|
|
112
|
+
reason: `${configPath} could not be parsed as TOML: ${tomlErrorLocation(error)}`,
|
|
108
113
|
};
|
|
109
114
|
}
|
|
110
115
|
}
|
|
@@ -149,14 +154,23 @@ export async function inspectPlanModeConfig(kimiHome) {
|
|
|
149
154
|
const offending = matching.filter(([, value]) => value !== false).map(([rawKey]) => rawKey);
|
|
150
155
|
if (offending.length === 0)
|
|
151
156
|
return { kind: "ok", setting: "false" };
|
|
152
|
-
const configPath =
|
|
157
|
+
const configPath = kimiCodeConfigPath(kimiHome);
|
|
153
158
|
return {
|
|
154
159
|
kind: "refuse",
|
|
155
160
|
refusalKind: "v2-plan-mode-configured",
|
|
156
161
|
reason: `\`${offending.join("`, `")}\` (upstream setting \`default_plan_mode\`) is set in ${configPath} and is not \`false\`.`,
|
|
157
162
|
};
|
|
158
163
|
}
|
|
159
|
-
|
|
164
|
+
/**
|
|
165
|
+
* `allowDefaultEnvironment`: upstream reads `environments.default` only in
|
|
166
|
+
* sessionManagerService.openCreation, i.e. when a session is created. A fresh
|
|
167
|
+
* print on a certified row passes `--environment local`, which skips the
|
|
168
|
+
* declarations; a resume goes through doResume, which applies the session's
|
|
169
|
+
* stored binding (state.json) and never consults the default (2.5.0-2.7.3).
|
|
170
|
+
* The stored binding is checked separately by scanSessionJournalsForPlan, so
|
|
171
|
+
* that one key stops refusing. A non-table section still refuses.
|
|
172
|
+
*/
|
|
173
|
+
export async function inspectEnvironmentConfig(kimiHome, options = {}) {
|
|
160
174
|
const parsed = await readParsedConfig(kimiHome);
|
|
161
175
|
if (parsed.kind === "unreadable") {
|
|
162
176
|
return { kind: "refuse", refusalKind: "v2-config-unreadable", reason: parsed.reason };
|
|
@@ -170,7 +184,7 @@ export async function inspectEnvironmentConfig(kimiHome) {
|
|
|
170
184
|
reason: "The [environments] section is not a table, so the execution environment cannot be verified as local.",
|
|
171
185
|
};
|
|
172
186
|
}
|
|
173
|
-
if (section["default"] !== undefined) {
|
|
187
|
+
if (options.allowDefaultEnvironment !== true && section["default"] !== undefined) {
|
|
174
188
|
return {
|
|
175
189
|
kind: "refuse",
|
|
176
190
|
refusalKind: "v2-environment-configured",
|
|
@@ -187,17 +201,24 @@ export async function inspectEnvironmentConfig(kimiHome) {
|
|
|
187
201
|
reason: "The [workspace] section is not a table, so project trust requirements cannot be verified.",
|
|
188
202
|
};
|
|
189
203
|
}
|
|
190
|
-
const
|
|
191
|
-
|
|
204
|
+
const trustValues = Object.entries(workspace)
|
|
205
|
+
.filter(([key]) => upstreamSnakeToCamel(key) === "requireTrust")
|
|
206
|
+
.map(([, value]) => value);
|
|
207
|
+
// Literal false is the user's own choice and becomes a warning; any other
|
|
208
|
+
// non-true value is malformed and still refuses.
|
|
209
|
+
if (trustValues.some((value) => value !== true && value !== false)) {
|
|
192
210
|
return {
|
|
193
211
|
kind: "refuse",
|
|
194
212
|
refusalKind: "v2-workspace-trust-disabled",
|
|
195
|
-
reason: "
|
|
213
|
+
reason: "[workspace] require_trust is not a boolean, so project trust requirements cannot be verified.",
|
|
196
214
|
};
|
|
197
215
|
}
|
|
216
|
+
if (trustValues.includes(false))
|
|
217
|
+
return { kind: "ok", trustDisabled: true };
|
|
198
218
|
}
|
|
199
219
|
return { kind: "ok" };
|
|
200
220
|
}
|
|
221
|
+
export const WORKSPACE_TRUST_DISABLED_WARNING = "Workspace trust is disabled in kimi-code's config: MCP servers configured by this repository can start outside the plugin's hook.";
|
|
201
222
|
/**
|
|
202
223
|
* Refuse v2-only experimental features this plugin does not certify.
|
|
203
224
|
* Sources (per-flag precedence upstream is env → [experimental] config →
|
|
@@ -282,46 +303,80 @@ async function openJournalSafely(journalPath, maxBytes) {
|
|
|
282
303
|
}
|
|
283
304
|
return { kind: "ok", handle };
|
|
284
305
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
306
|
+
/** Records that mean the session already did work: a turn, prompt, tool, model or delegated task. */
|
|
307
|
+
const ACTIVITY_RECORD = /^(turn\.|prompt\.|tool\.|llm\.|shell\.|subagent\.|task\.|assistant\.|context\.append_message$|context\.append_loop_event$)/;
|
|
308
|
+
/** Records that make replay non-linear (branch switch or undo), so a fold could differ. */
|
|
309
|
+
const REWIND_RECORD = /^(agent\.switched$|context\.undo$|context\.undone$)/;
|
|
310
|
+
async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelledDefaultEnter = false) {
|
|
311
|
+
// G2: a print-created session's main journal holds the create-time
|
|
312
|
+
// `default_plan_mode` enter immediately followed by print's id-less cancel,
|
|
313
|
+
// before any work. On a linear journal that pair folds to inactive, so it
|
|
314
|
+
// alone is tolerated; every other plan record, or that pair anywhere else,
|
|
315
|
+
// still taints.
|
|
316
|
+
// Replay stops at the first corrupt line, so records after it may add
|
|
317
|
+
// taints (seeing more is conservative) but never start or complete a fold.
|
|
318
|
+
let sawActivity = false;
|
|
319
|
+
let sawRewind = false;
|
|
320
|
+
let sawCorrupt = false;
|
|
321
|
+
let pendingEnter = null;
|
|
322
|
+
let toleratedPair = false;
|
|
323
|
+
const taintEnter = { kind: "tainted", recordType: "plan_mode.enter" };
|
|
324
|
+
for await (const framed of kimiJournalRecords(handle.createReadStream())) {
|
|
325
|
+
const { line, parsed } = framed;
|
|
326
|
+
if (parsed === UNPARSEABLE_JOURNAL_LINE) {
|
|
327
|
+
if (framed.terminated)
|
|
328
|
+
sawCorrupt = true;
|
|
329
|
+
if (pendingEnter !== null)
|
|
330
|
+
return taintEnter;
|
|
331
|
+
if (line.includes('"plan_mode.') || line.includes('"plan.')) {
|
|
332
|
+
return { kind: "tainted", recordType: "<unparseable>" };
|
|
333
|
+
}
|
|
334
|
+
if (line.includes('"environment.set_binding')) {
|
|
335
|
+
return { kind: "environment", recordType: "<unparseable-environment-binding>" };
|
|
295
336
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const record = parsed;
|
|
340
|
+
const type = record?.["type"];
|
|
341
|
+
if (pendingEnter !== null) {
|
|
342
|
+
const cancelId = record?.["id"];
|
|
343
|
+
const cancels = type === "plan_mode.cancel" && record?.["agentId"] === "main" &&
|
|
344
|
+
(cancelId === undefined || cancelId === pendingEnter.id);
|
|
345
|
+
if (!cancels)
|
|
346
|
+
return taintEnter;
|
|
347
|
+
pendingEnter = null;
|
|
348
|
+
toleratedPair = true;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (typeof type === "string" && REWIND_RECORD.test(type)) {
|
|
352
|
+
if (toleratedPair)
|
|
353
|
+
return taintEnter;
|
|
354
|
+
sawRewind = true;
|
|
355
|
+
}
|
|
356
|
+
if (typeof type === "string" && ACTIVITY_RECORD.test(type))
|
|
357
|
+
sawActivity = true;
|
|
358
|
+
if (typeof type === "string" && (type.startsWith("plan_mode.") || type.startsWith("plan."))) {
|
|
359
|
+
if (tolerateCancelledDefaultEnter && type === "plan_mode.enter" && !toleratedPair &&
|
|
360
|
+
!sawActivity && !sawRewind && !sawCorrupt && record?.["agentId"] === "main" && typeof record?.["id"] === "string") {
|
|
361
|
+
pendingEnter = { id: record["id"] };
|
|
303
362
|
continue;
|
|
304
363
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
364
|
+
return { kind: "tainted", recordType: type };
|
|
365
|
+
}
|
|
366
|
+
if (type === "environment.set_binding") {
|
|
367
|
+
if (record?.["environmentId"] !== "local") {
|
|
368
|
+
return { kind: "environment", recordType: type };
|
|
309
369
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
const cwd = record?.["cwd"];
|
|
315
|
-
if (expectedExecutionRoot !== undefined && cwd !== undefined && cwd !== expectedExecutionRoot) {
|
|
316
|
-
return { kind: "environment", recordType: "environment.set_binding.cwd" };
|
|
317
|
-
}
|
|
370
|
+
const cwd = record?.["cwd"];
|
|
371
|
+
if (expectedExecutionRoot !== undefined && cwd !== undefined && cwd !== expectedExecutionRoot) {
|
|
372
|
+
return { kind: "environment", recordType: "environment.set_binding.cwd" };
|
|
318
373
|
}
|
|
319
374
|
}
|
|
320
|
-
return null;
|
|
321
|
-
}
|
|
322
|
-
finally {
|
|
323
|
-
rl.close();
|
|
324
375
|
}
|
|
376
|
+
// An enter as the last record was never cancelled.
|
|
377
|
+
if (pendingEnter !== null)
|
|
378
|
+
return taintEnter;
|
|
379
|
+
return null;
|
|
325
380
|
}
|
|
326
381
|
async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoot) {
|
|
327
382
|
const read = await readSmallFileSafe(statePath, CONFIG_MAX_BYTES);
|
|
@@ -364,7 +419,7 @@ async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoo
|
|
|
364
419
|
* name `environmentId:"local"`. No session dir, no journal, unreadable metadata,
|
|
365
420
|
* or any single journal above the size cap → unavailable. Never modifies files.
|
|
366
421
|
*/
|
|
367
|
-
export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedExecutionRoot) {
|
|
422
|
+
export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedExecutionRoot, options = {}) {
|
|
368
423
|
const sessionsDir = path.join(kimiHome, "sessions");
|
|
369
424
|
const workspaceEntries = await boundedReaddir(sessionsDir, DIR_ENUM_CAP);
|
|
370
425
|
if (workspaceEntries.kind === "absent") {
|
|
@@ -413,19 +468,19 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
413
468
|
}
|
|
414
469
|
if (!agentEntry.isDirectory())
|
|
415
470
|
continue;
|
|
416
|
-
journalPaths.push(path.join(agentsDir, agentEntry.name, "wire.jsonl"));
|
|
471
|
+
journalPaths.push({ path: path.join(agentsDir, agentEntry.name, "wire.jsonl"), main: agentEntry.name === "main" });
|
|
417
472
|
}
|
|
418
473
|
}
|
|
419
474
|
if (journalPaths.length === 0) {
|
|
420
475
|
return { kind: "unavailable", reason: `no agent wire journals found for session ${sessionId}` };
|
|
421
476
|
}
|
|
422
|
-
for (const journalPath of journalPaths) {
|
|
477
|
+
for (const { path: journalPath, main } of journalPaths) {
|
|
423
478
|
const opened = await openJournalSafely(journalPath, JOURNAL_MAX_BYTES);
|
|
424
479
|
if (opened.kind === "unavailable") {
|
|
425
480
|
return { kind: "unavailable", reason: `${journalPath}: ${opened.reason}` };
|
|
426
481
|
}
|
|
427
482
|
try {
|
|
428
|
-
const finding = await scanJournalLines(opened.handle, expectedExecutionRoot);
|
|
483
|
+
const finding = await scanJournalLines(opened.handle, expectedExecutionRoot, main && options.tolerateCancelledDefaultEnter === true);
|
|
429
484
|
if (finding?.kind === "tainted") {
|
|
430
485
|
return { kind: "tainted", journal: journalPath, recordType: finding.recordType };
|
|
431
486
|
}
|
|
@@ -437,26 +492,32 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
437
492
|
await opened.handle.close().catch(() => undefined);
|
|
438
493
|
}
|
|
439
494
|
}
|
|
440
|
-
return { kind: "clean", journals: journalPaths };
|
|
495
|
+
return { kind: "clean", journals: journalPaths.map((journal) => journal.path) };
|
|
496
|
+
}
|
|
497
|
+
/** A non-swarm launch of an exactly certified row that has the capability. */
|
|
498
|
+
function certifiedPrintLaunchHas(options, capability) {
|
|
499
|
+
const release = options.release;
|
|
500
|
+
return release !== undefined &&
|
|
501
|
+
release.certification === "certified" &&
|
|
502
|
+
release.operationKind !== "swarm" &&
|
|
503
|
+
release.operationKind !== "swarm-write" &&
|
|
504
|
+
kimiCertifiedReleaseHas(release.kimiVersion, capability);
|
|
441
505
|
}
|
|
442
|
-
/**
|
|
443
|
-
* Run every inspection and throw a RuntimeError on the first refusal:
|
|
444
|
-
* CLI_V2_PLAN_MODE_CONFIGURED details.refusal_kind = "v2-plan-mode-configured"
|
|
445
|
-
* CLI_V2_CONFIG_UNREADABLE details.refusal_kind = "v2-config-unreadable"
|
|
446
|
-
* CLI_V2_EXPERIMENTAL_UNSAFE details.refusal_kind = "v2-experimental-unsafe", details.selectors
|
|
447
|
-
* CLI_V2_ENVIRONMENT_UNSAFE / CLI_V2_WORKSPACE_TRUST_UNSAFE for unsafe config
|
|
448
|
-
* KIMI_SESSION_ENVIRONMENT_UNSAFE details.refusal_kind = "session-environment-unsafe"
|
|
449
|
-
* KIMI_SESSION_PLAN_TAINTED details.refusal_kind = "session-plan-tainted", details.record_type
|
|
450
|
-
* KIMI_SESSION_JOURNAL_UNAVAILABLE details.refusal_kind = "session-journal-unavailable"
|
|
451
|
-
* Every message carries a truthful remedy (edit the named setting / start a
|
|
452
|
-
* fresh session) and MUST NOT mention /kimi:setup or hook drift.
|
|
453
|
-
* Every details object also carries `retryable_after_setup: false`.
|
|
454
|
-
*/
|
|
455
506
|
export async function assertNativeV2Preflight(options) {
|
|
507
|
+
const warnings = [];
|
|
456
508
|
const stage = options.stage ?? "native-v2.preflight";
|
|
457
|
-
const configPath =
|
|
509
|
+
const configPath = kimiCodeConfigPath(options.kimiHome);
|
|
510
|
+
// On a print-cancels-plan row the setting is read only inside
|
|
511
|
+
// sessionLifecycleService.create(): a fresh print cancels that enter before
|
|
512
|
+
// any turn (run-v2-print.ts), and `-r` on an existing session goes through
|
|
513
|
+
// doResume, which never consults it (a missing id fails, never creates).
|
|
514
|
+
// So the setting no longer refuses there; for a resume the journal scan
|
|
515
|
+
// below remains the gate. An unreadable config still refuses.
|
|
458
516
|
const planMode = await inspectPlanModeConfig(options.kimiHome);
|
|
459
|
-
|
|
517
|
+
const printCancelsPlan = planMode.kind === "refuse" &&
|
|
518
|
+
planMode.refusalKind === "v2-plan-mode-configured" &&
|
|
519
|
+
certifiedPrintLaunchHas(options, "print-cancels-plan");
|
|
520
|
+
if (planMode.kind === "refuse" && !printCancelsPlan) {
|
|
460
521
|
const code = planMode.refusalKind === "v2-plan-mode-configured"
|
|
461
522
|
? "CLI_V2_PLAN_MODE_CONFIGURED"
|
|
462
523
|
: "CLI_V2_CONFIG_UNREADABLE";
|
|
@@ -467,7 +528,9 @@ export async function assertNativeV2Preflight(options) {
|
|
|
467
528
|
details: { refusal_kind: planMode.refusalKind, retryable_after_setup: false },
|
|
468
529
|
});
|
|
469
530
|
}
|
|
470
|
-
const environment = await inspectEnvironmentConfig(options.kimiHome
|
|
531
|
+
const environment = await inspectEnvironmentConfig(options.kimiHome, {
|
|
532
|
+
allowDefaultEnvironment: certifiedPrintLaunchHas(options, "local-environment"),
|
|
533
|
+
});
|
|
471
534
|
if (environment.kind === "refuse") {
|
|
472
535
|
const code = environment.refusalKind === "v2-environment-configured"
|
|
473
536
|
? "CLI_V2_ENVIRONMENT_UNSAFE"
|
|
@@ -483,7 +546,14 @@ export async function assertNativeV2Preflight(options) {
|
|
|
483
546
|
details: { refusal_kind: environment.refusalKind, retryable_after_setup: false },
|
|
484
547
|
});
|
|
485
548
|
}
|
|
486
|
-
|
|
549
|
+
if (environment.trustDisabled === true)
|
|
550
|
+
warnings.push(WORKSPACE_TRUST_DISABLED_WARNING);
|
|
551
|
+
// Certified and test-bypass children run with tower and subagent fork forced
|
|
552
|
+
// off by per-flag env, which outranks config and the master flag on every
|
|
553
|
+
// reviewed release. An uncertified release's flag names are unreviewed.
|
|
554
|
+
const experimental = options.release === undefined || options.release.certification === "uncertified"
|
|
555
|
+
? await inspectExperimentalSelectors(options.kimiHome, options.env)
|
|
556
|
+
: { kind: "ok" };
|
|
487
557
|
if (experimental.kind === "refuse") {
|
|
488
558
|
throw new RuntimeError("CLI_V2_EXPERIMENTAL_UNSAFE", `${experimental.reason} Unset the listed selector(s) before retrying.`, stage, {
|
|
489
559
|
details: {
|
|
@@ -494,7 +564,7 @@ export async function assertNativeV2Preflight(options) {
|
|
|
494
564
|
});
|
|
495
565
|
}
|
|
496
566
|
if (options.resumeSessionId !== undefined) {
|
|
497
|
-
const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot);
|
|
567
|
+
const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot, { tolerateCancelledDefaultEnter: certifiedPrintLaunchHas(options, "print-cancels-plan") });
|
|
498
568
|
if (journalScan.kind === "environment") {
|
|
499
569
|
throw new RuntimeError("KIMI_SESSION_ENVIRONMENT_UNSAFE", `Saved session ${options.resumeSessionId} has an unsafe execution environment binding (${journalScan.recordType} in ${journalScan.journal}). Start a fresh local session; saved session state was not modified.`, stage, {
|
|
500
570
|
details: {
|
|
@@ -522,4 +592,5 @@ export async function assertNativeV2Preflight(options) {
|
|
|
522
592
|
});
|
|
523
593
|
}
|
|
524
594
|
}
|
|
595
|
+
return { warnings };
|
|
525
596
|
}
|