kimi-plugin-cc 2.7.3 → 3.1.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 +2 -2
- package/.claude-plugin/plugin.json +3 -16
- package/README.md +428 -515
- package/assets/logo.svg +6 -0
- package/cordis.patch.yml +18 -0
- package/dist/background-spawn.js +14 -19
- package/dist/cli-client.js +163 -105
- package/dist/commands/ask.js +44 -96
- package/dist/commands/cancel.js +11 -59
- package/dist/commands/cli-helpers.js +102 -1
- package/dist/commands/models.js +2 -3
- package/dist/commands/pursue.js +8 -21
- package/dist/commands/registry.js +7 -26
- package/dist/commands/repair-sessions.js +121 -12
- package/dist/commands/replay.js +4 -3
- package/dist/commands/rescue.js +29 -87
- package/dist/commands/result.js +7 -1
- package/dist/commands/review.js +28 -18
- package/dist/commands/setup.js +813 -462
- package/dist/commands/status.js +2 -2
- package/dist/commands/swarm.js +112 -125
- package/dist/commands/worker.js +1 -2
- package/dist/companion.js +145 -19
- package/dist/git.js +1 -9
- package/dist/help.js +13 -9
- package/dist/hook-escape.js +7 -16
- package/dist/hooks/approval-hook.js +1766 -87
- package/dist/hooks/approval-policy.js +86 -19
- package/dist/hooks/config-safety.js +31 -64
- package/dist/hooks/hook-timing.js +48 -0
- package/dist/hooks/install-paths.js +179 -107
- package/dist/hooks/install.js +126 -53
- package/dist/hooks/managed-block.js +121 -127
- package/dist/job-store.js +206 -166
- package/dist/jobs.js +66 -19
- package/dist/kimi-command.js +74 -1
- package/dist/kimi-engine.js +198 -127
- package/dist/kimi-errors.js +15 -70
- package/dist/kimi-home.js +6 -0
- package/dist/kimi-journal.js +42 -0
- package/dist/kimi-releases.js +123 -0
- package/dist/kimi-timeouts.js +2 -16
- package/dist/kimi-version-probe.js +24 -108
- package/dist/logging.js +12 -7
- package/dist/mcp/binding.js +13 -4
- package/dist/mcp/job-control.js +390 -95
- package/dist/mcp/launcher.js +13 -7
- package/dist/mcp/operations.js +405 -179
- package/dist/mcp/protocol.js +124 -33
- package/dist/mcp/skills.js +130 -0
- package/dist/mcp/stdio.js +18 -4
- package/dist/model-command.js +5 -3
- package/dist/native-v2-preflight.js +243 -80
- package/dist/parsing.js +211 -243
- package/dist/paths.js +28 -10
- package/dist/plugin-data.js +28 -83
- package/dist/process-tree.js +35 -24
- package/dist/read-scope.js +435 -0
- package/dist/render.js +58 -46
- package/dist/rescue-approval.js +461 -84
- package/dist/session-references.js +216 -0
- package/dist/session-title.js +26 -6
- package/dist/stream-json.js +1 -3
- package/dist/surface-routing.js +108 -0
- package/dist/swarm-activation.js +74 -188
- 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 +45 -206
- package/docs/models.md +24 -66
- package/docs/safety.md +198 -353
- package/docs/session-visibility.md +25 -13
- 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 +3 -3
- package/plugins/kimi-codex/dist/background-spawn.js +14 -19
- package/plugins/kimi-codex/dist/cli-client.js +163 -105
- package/plugins/kimi-codex/dist/commands/ask.js +44 -96
- package/plugins/kimi-codex/dist/commands/cancel.js +11 -59
- 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 +8 -21
- package/plugins/kimi-codex/dist/commands/registry.js +7 -26
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +121 -12
- package/plugins/kimi-codex/dist/commands/replay.js +4 -3
- package/plugins/kimi-codex/dist/commands/rescue.js +29 -87
- package/plugins/kimi-codex/dist/commands/result.js +7 -1
- package/plugins/kimi-codex/dist/commands/review.js +28 -18
- package/plugins/kimi-codex/dist/commands/setup.js +813 -462
- package/plugins/kimi-codex/dist/commands/status.js +2 -2
- package/plugins/kimi-codex/dist/commands/swarm.js +112 -125
- package/plugins/kimi-codex/dist/commands/worker.js +1 -2
- package/plugins/kimi-codex/dist/companion.js +145 -19
- package/plugins/kimi-codex/dist/git.js +1 -9
- package/plugins/kimi-codex/dist/help.js +13 -9
- package/plugins/kimi-codex/dist/hook-escape.js +7 -16
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +1766 -87
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +86 -19
- package/plugins/kimi-codex/dist/hooks/config-safety.js +31 -64
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
- package/plugins/kimi-codex/dist/hooks/install.js +126 -53
- package/plugins/kimi-codex/dist/hooks/managed-block.js +121 -127
- package/plugins/kimi-codex/dist/job-store.js +206 -166
- package/plugins/kimi-codex/dist/jobs.js +66 -19
- package/plugins/kimi-codex/dist/kimi-command.js +74 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +198 -127
- package/plugins/kimi-codex/dist/kimi-errors.js +15 -70
- package/plugins/kimi-codex/dist/kimi-home.js +6 -0
- package/plugins/kimi-codex/dist/kimi-journal.js +42 -0
- package/plugins/kimi-codex/dist/kimi-releases.js +123 -0
- package/plugins/kimi-codex/dist/kimi-timeouts.js +2 -16
- package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -108
- 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 +390 -95
- package/plugins/kimi-codex/dist/mcp/launcher.js +13 -7
- package/plugins/kimi-codex/dist/mcp/operations.js +405 -179
- package/plugins/kimi-codex/dist/mcp/protocol.js +124 -33
- package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
- package/plugins/kimi-codex/dist/mcp/stdio.js +18 -4
- package/plugins/kimi-codex/dist/model-command.js +5 -3
- package/plugins/kimi-codex/dist/native-v2-preflight.js +243 -80
- package/plugins/kimi-codex/dist/parsing.js +211 -243
- package/plugins/kimi-codex/dist/paths.js +28 -10
- package/plugins/kimi-codex/dist/plugin-data.js +28 -83
- 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 +58 -46
- package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
- package/plugins/kimi-codex/dist/session-references.js +216 -0
- package/plugins/kimi-codex/dist/session-title.js +26 -6
- package/plugins/kimi-codex/dist/stream-json.js +1 -3
- package/plugins/kimi-codex/dist/surface-routing.js +108 -0
- package/plugins/kimi-codex/dist/swarm-activation.js +74 -188
- 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/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 -1333
- package/agents/kimi-ask.md +0 -89
- package/agents/kimi-challenge.md +0 -86
- package/agents/kimi-pursue.md +0 -93
- package/agents/kimi-rescue.md +0 -92
- package/agents/kimi-review.md +0 -86
- package/agents/kimi-swarm-write.md +0 -96
- package/agents/kimi-swarm.md +0 -86
- package/commands/README.md +0 -16
- package/commands/ask.md +0 -38
- package/commands/cancel.md +0 -17
- package/commands/challenge.md +0 -35
- package/commands/pursue.md +0 -41
- package/commands/replay.md +0 -13
- package/commands/rescue.md +0 -38
- package/commands/result.md +0 -13
- package/commands/review.md +0 -35
- package/commands/setup.md +0 -23
- package/commands/status.md +0 -13
- package/commands/swarm.md +0 -44
- package/dist/commands/not-implemented.js +0 -4
- package/dist/commands/review-gate.js +0 -390
- package/dist/config.js +0 -22
- package/dist/dsh/companion.js +0 -177
- package/dist/dsh/index.js +0 -169
- package/dist/hooks/review-gate-stop.js +0 -19
- package/dist/schemas/review-gate-output.js +0 -43
- 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 -83
- 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/not-implemented.js +0 -4
- package/plugins/kimi-codex/dist/commands/review-gate.js +0 -390
- 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 -169
- package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -43
- package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
- package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
- 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-challenge/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-challenge/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-rescue/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-rescue/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 -34
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -34
- 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 -35
- package/plugins/kimi-codex/skills/kimi-swarm/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/LICENSE +0 -201
- package/plugins/kimi-dsh/README.md +0 -83
- package/plugins/kimi-dsh/cordis.patch.yml +0 -45
- package/plugins/kimi-dsh/dist/background-spawn.js +0 -216
- package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
- package/plugins/kimi-dsh/dist/cli-client.js +0 -1078
- package/plugins/kimi-dsh/dist/commands/ask.js +0 -336
- package/plugins/kimi-dsh/dist/commands/cancel.js +0 -216
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -201
- package/plugins/kimi-dsh/dist/commands/models.js +0 -140
- package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-dsh/dist/commands/pursue.js +0 -307
- 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 -160
- package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
- package/plugins/kimi-dsh/dist/commands/rescue.js +0 -347
- package/plugins/kimi-dsh/dist/commands/result.js +0 -66
- package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -390
- package/plugins/kimi-dsh/dist/commands/review.js +0 -220
- package/plugins/kimi-dsh/dist/commands/setup.js +0 -1129
- package/plugins/kimi-dsh/dist/commands/status.js +0 -27
- package/plugins/kimi-dsh/dist/commands/swarm.js +0 -849
- package/plugins/kimi-dsh/dist/commands/worker.js +0 -25
- package/plugins/kimi-dsh/dist/companion.js +0 -97
- 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 -169
- package/plugins/kimi-dsh/dist/errors.js +0 -40
- package/plugins/kimi-dsh/dist/git.js +0 -224
- 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 -104
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -233
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -665
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
- package/plugins/kimi-dsh/dist/hooks/install.js +0 -210
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -684
- 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 -659
- package/plugins/kimi-dsh/dist/jobs.js +0 -217
- package/plugins/kimi-dsh/dist/kimi-command.js +0 -71
- package/plugins/kimi-dsh/dist/kimi-engine.js +0 -675
- package/plugins/kimi-dsh/dist/kimi-errors.js +0 -260
- package/plugins/kimi-dsh/dist/kimi-home.js +0 -9
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -234
- 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 -345
- package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -257
- package/plugins/kimi-dsh/dist/mcp/operations.js +0 -301
- package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -275
- package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
- package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -78
- 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 -32
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -525
- package/plugins/kimi-dsh/dist/package.json +0 -1
- package/plugins/kimi-dsh/dist/parsing.js +0 -620
- package/plugins/kimi-dsh/dist/paths.js +0 -27
- package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
- package/plugins/kimi-dsh/dist/process-tree.js +0 -586
- package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
- package/plugins/kimi-dsh/dist/render.js +0 -177
- package/plugins/kimi-dsh/dist/rescue-approval.js +0 -865
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -43
- package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
- package/plugins/kimi-dsh/dist/session-title.js +0 -293
- package/plugins/kimi-dsh/dist/stream-json.js +0 -346
- package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1197
- package/plugins/kimi-dsh/dist/swarm-policy.js +0 -73
- package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -165
- 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/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
|
@@ -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:
|
|
@@ -27,10 +29,13 @@
|
|
|
27
29
|
// - Refusals here are NOT /kimi:setup-recoverable and must never be
|
|
28
30
|
// described as hook drift.
|
|
29
31
|
import { constants as fsConstants } from "node:fs";
|
|
30
|
-
import { open, readdir } from "node:fs/promises";
|
|
32
|
+
import { lstat, 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;
|
|
@@ -39,7 +44,7 @@ const CONFIG_MAX_BYTES = 1 * 1024 * 1024;
|
|
|
39
44
|
const JOURNAL_MAX_BYTES = 64 * 1024 * 1024;
|
|
40
45
|
/** Bounded directory enumeration so a pathological sessions/ tree refuses
|
|
41
46
|
* instead of scanning forever. */
|
|
42
|
-
const DIR_ENUM_CAP = 4096;
|
|
47
|
+
export const DIR_ENUM_CAP = 4096;
|
|
43
48
|
const TRUTHY_STRINGS = new Set(["1", "true", "yes", "on"]);
|
|
44
49
|
function isTruthySelectorValue(value) {
|
|
45
50
|
if (value === true)
|
|
@@ -53,7 +58,7 @@ function isTruthySelectorValue(value) {
|
|
|
53
58
|
* config lock reader in runtime/hooks/config-safety.ts. Never partial-reads:
|
|
54
59
|
* an oversized file refuses rather than being silently truncated.
|
|
55
60
|
*/
|
|
56
|
-
async function readSmallFileSafe(filePath, maxBytes) {
|
|
61
|
+
export async function readSmallFileSafe(filePath, maxBytes) {
|
|
57
62
|
let handle;
|
|
58
63
|
try {
|
|
59
64
|
handle = await open(filePath, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0));
|
|
@@ -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.8.0).
|
|
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,19 +201,31 @@ 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.";
|
|
222
|
+
/** Launch warning for an uncertified release with experimental selectors switched on. */
|
|
223
|
+
export function experimentalSelectorsWarning(selectors) {
|
|
224
|
+
return `kimi-code experimental features are switched on (${selectors.join(", ")}) and this kimi-code release is not certified by the plugin. The plugin starts Kimi with KIMI_CODE_EXPERIMENTAL_TOWER=0 and without KIMI_CODE_EXPERIMENTAL_FLAG; how this release reads them has not been reviewed.`;
|
|
225
|
+
}
|
|
201
226
|
/**
|
|
202
|
-
*
|
|
227
|
+
* Find v2-only experimental features this plugin runs its tasks without.
|
|
228
|
+
* A plan-less launch refuses on them; an uncertified release only warns.
|
|
203
229
|
* Sources (per-flag precedence upstream is env → [experimental] config →
|
|
204
230
|
* master flag → default): the `[experimental]` table keys `tower` and
|
|
205
231
|
* `subagent_fork` in `<kimiHome>/config.toml`, and the per-flag env vars
|
|
@@ -210,11 +236,22 @@ export async function inspectEnvironmentConfig(kimiHome) {
|
|
|
210
236
|
* Config read errors follow inspectPlanModeConfig's fail-closed rules.
|
|
211
237
|
*/
|
|
212
238
|
export async function inspectExperimentalSelectors(kimiHome, env) {
|
|
239
|
+
return (await inspectExperimentalConfig(kimiHome, env)).inspection;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* One read of the config for both answers: the two selectors a plan-less
|
|
243
|
+
* launch refuses on, and every selector the user switched on (truthy
|
|
244
|
+
* `[experimental]` keys and truthy `KIMI_CODE_EXPERIMENTAL_*` variables, the
|
|
245
|
+
* master flag included). An uncertified release's flag set is unreviewed, so
|
|
246
|
+
* its warning names them all, not only the two the plugin forces off.
|
|
247
|
+
*/
|
|
248
|
+
async function inspectExperimentalConfig(kimiHome, env) {
|
|
213
249
|
const parsed = await readParsedConfig(kimiHome);
|
|
214
250
|
if (parsed.kind === "unreadable") {
|
|
215
|
-
return { kind: "refuse", selectors: [], reason: parsed.reason };
|
|
251
|
+
return { inspection: { kind: "refuse", selectors: [], reason: parsed.reason }, switchedOn: [] };
|
|
216
252
|
}
|
|
217
253
|
const selectors = [];
|
|
254
|
+
const switchedOn = [];
|
|
218
255
|
const experimental = parsed.config?.["experimental"];
|
|
219
256
|
if (experimental !== null && typeof experimental === "object" && !Array.isArray(experimental)) {
|
|
220
257
|
const table = experimental;
|
|
@@ -223,6 +260,10 @@ export async function inspectExperimentalSelectors(kimiHome, env) {
|
|
|
223
260
|
if (isTruthySelectorValue(table["subagent_fork"])) {
|
|
224
261
|
selectors.push("config:[experimental].subagent_fork");
|
|
225
262
|
}
|
|
263
|
+
for (const [key, value] of Object.entries(table)) {
|
|
264
|
+
if (isTruthySelectorValue(value))
|
|
265
|
+
switchedOn.push(`config:[experimental].${key}`);
|
|
266
|
+
}
|
|
226
267
|
}
|
|
227
268
|
if (isTruthySelectorValue(env.KIMI_CODE_EXPERIMENTAL_TOWER)) {
|
|
228
269
|
selectors.push("env:KIMI_CODE_EXPERIMENTAL_TOWER");
|
|
@@ -230,15 +271,34 @@ export async function inspectExperimentalSelectors(kimiHome, env) {
|
|
|
230
271
|
if (isTruthySelectorValue(env.KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK)) {
|
|
231
272
|
selectors.push("env:KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK");
|
|
232
273
|
}
|
|
274
|
+
// Environment names are case-sensitive except on Windows, where Kimi reads any spelling.
|
|
275
|
+
const selectorName = (name) => (process.platform === "win32" ? name.toUpperCase() : name);
|
|
276
|
+
for (const [name, value] of Object.entries(env)) {
|
|
277
|
+
if (selectorName(name).startsWith("KIMI_CODE_EXPERIMENTAL_") && isTruthySelectorValue(value))
|
|
278
|
+
switchedOn.push(`env:${name}`);
|
|
279
|
+
}
|
|
233
280
|
if (selectors.length === 0)
|
|
234
|
-
return { kind: "ok" };
|
|
281
|
+
return { inspection: { kind: "ok" }, switchedOn };
|
|
235
282
|
return {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
283
|
+
inspection: {
|
|
284
|
+
kind: "refuse",
|
|
285
|
+
selectors,
|
|
286
|
+
reason: `Refusing v2-only experimental feature(s) not certified by kimi-plugin-cc: ${selectors.join(", ")}.`,
|
|
287
|
+
},
|
|
288
|
+
switchedOn,
|
|
239
289
|
};
|
|
240
290
|
}
|
|
241
|
-
|
|
291
|
+
/** Device and inode of a directory, without following a final link; undefined when it cannot be read. */
|
|
292
|
+
async function directoryIdentity(directory) {
|
|
293
|
+
try {
|
|
294
|
+
const info = await lstat(directory, { bigint: true });
|
|
295
|
+
return info.isDirectory() ? `${info.dev}:${info.ino}` : undefined;
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
export async function boundedReaddir(dirPath, cap) {
|
|
242
302
|
let entries;
|
|
243
303
|
try {
|
|
244
304
|
entries = await readdir(dirPath, { withFileTypes: true });
|
|
@@ -255,7 +315,8 @@ async function boundedReaddir(dirPath, cap) {
|
|
|
255
315
|
return { kind: "cap-exceeded" };
|
|
256
316
|
return { kind: "ok", entries };
|
|
257
317
|
}
|
|
258
|
-
|
|
318
|
+
/** `maxBytes` omitted: no size cap (the caller never reads the content). */
|
|
319
|
+
export async function openJournalSafely(journalPath, maxBytes) {
|
|
259
320
|
let handle;
|
|
260
321
|
try {
|
|
261
322
|
// O_NONBLOCK so a FIFO planted at the journal path (no writer) does not
|
|
@@ -276,52 +337,120 @@ async function openJournalSafely(journalPath, maxBytes) {
|
|
|
276
337
|
await handle.close().catch(() => undefined);
|
|
277
338
|
return { kind: "unavailable", reason: "journal is not a regular file" };
|
|
278
339
|
}
|
|
279
|
-
if (stats.size > BigInt(maxBytes)) {
|
|
340
|
+
if (maxBytes !== undefined && stats.size > BigInt(maxBytes)) {
|
|
280
341
|
await handle.close().catch(() => undefined);
|
|
281
342
|
return { kind: "unavailable", reason: `journal exceeds ${maxBytes} byte cap` };
|
|
282
343
|
}
|
|
283
344
|
return { kind: "ok", handle };
|
|
284
345
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
346
|
+
/** Records that mean the session already did work: a turn, prompt, tool, model or delegated task. */
|
|
347
|
+
const ACTIVITY_RECORD = /^(turn\.|prompt\.|tool\.|llm\.|shell\.|subagent\.|task\.|assistant\.|context\.append_message$|context\.append_loop_event$)/;
|
|
348
|
+
/**
|
|
349
|
+
* Records kimi may write between the create-time `plan_mode.enter` and print's
|
|
350
|
+
* `plan_mode.cancel` without doing work. These are kimi's three durable MCP
|
|
351
|
+
* events (2.8.0): its MCP service writes them on its own clock while servers
|
|
352
|
+
* connect, and each folds only into MCP discovery or failure state. Discovery
|
|
353
|
+
* was observed there on 2.8.0. Anything else between the two taints.
|
|
354
|
+
*/
|
|
355
|
+
export const PLAN_PAIR_BOOKKEEPING = new Set([
|
|
356
|
+
"mcp.tools_discovered", "mcp.server_failed", "mcp.server_failure_resolved",
|
|
357
|
+
]);
|
|
358
|
+
/** Records that make replay non-linear (branch switch or undo), so a fold could differ. */
|
|
359
|
+
const REWIND_RECORD = /^(agent\.switched$|context\.undo$|context\.undone$)/;
|
|
360
|
+
async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelledDefaultEnter = false, main = false) {
|
|
361
|
+
// G2: a print-created session's main journal holds the create-time
|
|
362
|
+
// `default_plan_mode` enter followed by print's id-less cancel, before any
|
|
363
|
+
// work. On a linear journal that pair folds to inactive, so it alone is
|
|
364
|
+
// tolerated; every other plan record, or that pair anywhere else, still
|
|
365
|
+
// taints. Bookkeeping records may sit between the two (2.8.0 journals MCP
|
|
366
|
+
// discovery there); work, a rewind or another plan record may not.
|
|
367
|
+
// Replay stops at the first corrupt line, so records after it may add
|
|
368
|
+
// taints (seeing more is conservative) but never start or complete a fold.
|
|
369
|
+
let sawActivity = false;
|
|
370
|
+
let sawRewind = false;
|
|
371
|
+
let sawCorrupt = false;
|
|
372
|
+
let pendingEnter = null;
|
|
373
|
+
let toleratedPair = false;
|
|
374
|
+
// Restoring a session left in tower mode lets kimi adopt the workspace's
|
|
375
|
+
// `.tower` state without a tool call, whatever the tower flag says. Kimi
|
|
376
|
+
// folds tower state from the main journal only, takes a record with no
|
|
377
|
+
// agentId as the journal's own, ignores another agent's, and stops at the
|
|
378
|
+
// first corrupt line: an exit it will not replay must not clear the state.
|
|
379
|
+
let towerActive = false;
|
|
380
|
+
const taintEnter = { kind: "tainted", recordType: "plan_mode.enter" };
|
|
381
|
+
for await (const framed of kimiJournalRecords(handle.createReadStream())) {
|
|
382
|
+
const { line, parsed } = framed;
|
|
383
|
+
if (parsed === UNPARSEABLE_JOURNAL_LINE) {
|
|
384
|
+
const firstCorrupt = framed.terminated && !sawCorrupt;
|
|
385
|
+
if (framed.terminated)
|
|
386
|
+
sawCorrupt = true;
|
|
387
|
+
if (pendingEnter !== null)
|
|
388
|
+
return taintEnter;
|
|
389
|
+
if (line.includes('"plan_mode.') || line.includes('"plan.')) {
|
|
390
|
+
return { kind: "tainted", recordType: "<unparseable>" };
|
|
391
|
+
}
|
|
392
|
+
if (line.includes('"environment.set_binding')) {
|
|
393
|
+
return { kind: "environment", recordType: "<unparseable-environment-binding>" };
|
|
394
|
+
}
|
|
395
|
+
// Kimi drops a torn final line and stops replaying at the first complete
|
|
396
|
+
// corrupt one; that one line is read conservatively as an enter.
|
|
397
|
+
if (main && firstCorrupt && line.includes('"tower_mode.'))
|
|
398
|
+
towerActive = true;
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
const record = parsed;
|
|
402
|
+
const type = record?.["type"];
|
|
403
|
+
// Kimi stops replaying at the first complete corrupt line, so nothing after it changes tower state.
|
|
404
|
+
if (main && !sawCorrupt && (record?.["agentId"] === undefined || record["agentId"] === "main")) {
|
|
405
|
+
if (type === "tower_mode.enter")
|
|
406
|
+
towerActive = true;
|
|
407
|
+
else if (type === "tower_mode.exit")
|
|
408
|
+
towerActive = false;
|
|
409
|
+
}
|
|
410
|
+
const isPlanRecord = typeof type === "string" && (type.startsWith("plan_mode.") || type.startsWith("plan."));
|
|
411
|
+
const isRewind = typeof type === "string" && REWIND_RECORD.test(type);
|
|
412
|
+
const isActivity = typeof type === "string" && ACTIVITY_RECORD.test(type);
|
|
413
|
+
if (pendingEnter !== null) {
|
|
414
|
+
const cancelId = record?.["id"];
|
|
415
|
+
const cancels = type === "plan_mode.cancel" && record?.["agentId"] === "main" &&
|
|
416
|
+
(cancelId === undefined || cancelId === pendingEnter.id);
|
|
417
|
+
if (cancels) {
|
|
418
|
+
pendingEnter = null;
|
|
419
|
+
toleratedPair = true;
|
|
291
420
|
continue;
|
|
292
|
-
let parsed;
|
|
293
|
-
try {
|
|
294
|
-
parsed = JSON.parse(line);
|
|
295
421
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
422
|
+
if (typeof type !== "string" || !PLAN_PAIR_BOOKKEEPING.has(type))
|
|
423
|
+
return taintEnter;
|
|
424
|
+
}
|
|
425
|
+
if (isRewind) {
|
|
426
|
+
if (toleratedPair)
|
|
427
|
+
return taintEnter;
|
|
428
|
+
sawRewind = true;
|
|
429
|
+
}
|
|
430
|
+
if (isActivity)
|
|
431
|
+
sawActivity = true;
|
|
432
|
+
if (isPlanRecord) {
|
|
433
|
+
if (tolerateCancelledDefaultEnter && type === "plan_mode.enter" && !toleratedPair &&
|
|
434
|
+
!sawActivity && !sawRewind && !sawCorrupt && record?.["agentId"] === "main" && typeof record?.["id"] === "string") {
|
|
435
|
+
pendingEnter = { id: record["id"] };
|
|
303
436
|
continue;
|
|
304
437
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
438
|
+
return { kind: "tainted", recordType: type };
|
|
439
|
+
}
|
|
440
|
+
if (type === "environment.set_binding") {
|
|
441
|
+
if (record?.["environmentId"] !== "local") {
|
|
442
|
+
return { kind: "environment", recordType: type };
|
|
309
443
|
}
|
|
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
|
-
}
|
|
444
|
+
const cwd = record?.["cwd"];
|
|
445
|
+
if (expectedExecutionRoot !== undefined && cwd !== undefined && cwd !== expectedExecutionRoot) {
|
|
446
|
+
return { kind: "environment", recordType: "environment.set_binding.cwd" };
|
|
318
447
|
}
|
|
319
448
|
}
|
|
320
|
-
return null;
|
|
321
|
-
}
|
|
322
|
-
finally {
|
|
323
|
-
rl.close();
|
|
324
449
|
}
|
|
450
|
+
// An enter as the last record was never cancelled.
|
|
451
|
+
if (pendingEnter !== null)
|
|
452
|
+
return taintEnter;
|
|
453
|
+
return towerActive ? { kind: "tower" } : null;
|
|
325
454
|
}
|
|
326
455
|
async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoot) {
|
|
327
456
|
const read = await readSmallFileSafe(statePath, CONFIG_MAX_BYTES);
|
|
@@ -364,7 +493,7 @@ async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoo
|
|
|
364
493
|
* name `environmentId:"local"`. No session dir, no journal, unreadable metadata,
|
|
365
494
|
* or any single journal above the size cap → unavailable. Never modifies files.
|
|
366
495
|
*/
|
|
367
|
-
export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedExecutionRoot) {
|
|
496
|
+
export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedExecutionRoot, options = {}) {
|
|
368
497
|
const sessionsDir = path.join(kimiHome, "sessions");
|
|
369
498
|
const workspaceEntries = await boundedReaddir(sessionsDir, DIR_ENUM_CAP);
|
|
370
499
|
if (workspaceEntries.kind === "absent") {
|
|
@@ -404,6 +533,10 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
404
533
|
if (agentEntries.kind === "unreadable") {
|
|
405
534
|
return { kind: "unavailable", reason: `could not enumerate agent journals: ${agentEntries.reason}` };
|
|
406
535
|
}
|
|
536
|
+
// Kimi opens `agents/main` by that spelling. On a case-insensitive volume
|
|
537
|
+
// a directory stored as `Main` answers to it, so the main journal is
|
|
538
|
+
// identified by what that lookup reaches, not by the stored name.
|
|
539
|
+
const mainIdentity = await directoryIdentity(path.join(agentsDir, "main"));
|
|
407
540
|
for (const agentEntry of agentEntries.entries) {
|
|
408
541
|
if (agentEntry.isSymbolicLink()) {
|
|
409
542
|
return {
|
|
@@ -413,50 +546,61 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
413
546
|
}
|
|
414
547
|
if (!agentEntry.isDirectory())
|
|
415
548
|
continue;
|
|
416
|
-
|
|
549
|
+
const agentDir = path.join(agentsDir, agentEntry.name);
|
|
550
|
+
const main = agentEntry.name === "main" ||
|
|
551
|
+
(mainIdentity !== undefined && (await directoryIdentity(agentDir)) === mainIdentity);
|
|
552
|
+
journalPaths.push({ path: path.join(agentDir, "wire.jsonl"), main });
|
|
417
553
|
}
|
|
418
554
|
}
|
|
419
555
|
if (journalPaths.length === 0) {
|
|
420
556
|
return { kind: "unavailable", reason: `no agent wire journals found for session ${sessionId}` };
|
|
421
557
|
}
|
|
422
|
-
for (const journalPath of journalPaths) {
|
|
558
|
+
for (const { path: journalPath, main } of journalPaths) {
|
|
423
559
|
const opened = await openJournalSafely(journalPath, JOURNAL_MAX_BYTES);
|
|
424
560
|
if (opened.kind === "unavailable") {
|
|
425
561
|
return { kind: "unavailable", reason: `${journalPath}: ${opened.reason}` };
|
|
426
562
|
}
|
|
427
563
|
try {
|
|
428
|
-
const finding = await scanJournalLines(opened.handle, expectedExecutionRoot);
|
|
564
|
+
const finding = await scanJournalLines(opened.handle, expectedExecutionRoot, main && options.tolerateCancelledDefaultEnter === true, main);
|
|
429
565
|
if (finding?.kind === "tainted") {
|
|
430
566
|
return { kind: "tainted", journal: journalPath, recordType: finding.recordType };
|
|
431
567
|
}
|
|
432
568
|
if (finding?.kind === "environment") {
|
|
433
569
|
return { kind: "environment", journal: journalPath, recordType: finding.recordType };
|
|
434
570
|
}
|
|
571
|
+
if (finding?.kind === "tower")
|
|
572
|
+
return { kind: "tower", journal: journalPath };
|
|
435
573
|
}
|
|
436
574
|
finally {
|
|
437
575
|
await opened.handle.close().catch(() => undefined);
|
|
438
576
|
}
|
|
439
577
|
}
|
|
440
|
-
return { kind: "clean", journals: journalPaths };
|
|
578
|
+
return { kind: "clean", journals: journalPaths.map((journal) => journal.path) };
|
|
579
|
+
}
|
|
580
|
+
/** A non-swarm launch of an exactly certified row that has the capability. */
|
|
581
|
+
function certifiedPrintLaunchHas(options, capability) {
|
|
582
|
+
const release = options.release;
|
|
583
|
+
return release !== undefined &&
|
|
584
|
+
release.certification === "certified" &&
|
|
585
|
+
release.operationKind !== "swarm" &&
|
|
586
|
+
release.operationKind !== "swarm-write" &&
|
|
587
|
+
kimiCertifiedReleaseHas(release.kimiVersion, capability);
|
|
441
588
|
}
|
|
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
589
|
export async function assertNativeV2Preflight(options) {
|
|
590
|
+
const warnings = [];
|
|
456
591
|
const stage = options.stage ?? "native-v2.preflight";
|
|
457
|
-
const configPath =
|
|
592
|
+
const configPath = kimiCodeConfigPath(options.kimiHome);
|
|
593
|
+
// On a print-cancels-plan row the setting is read only inside
|
|
594
|
+
// sessionLifecycleService.create(): a fresh print cancels that enter before
|
|
595
|
+
// any turn (run-v2-print.ts), and `-r` on an existing session goes through
|
|
596
|
+
// doResume, which never consults it (a missing id fails, never creates).
|
|
597
|
+
// So the setting no longer refuses there; for a resume the journal scan
|
|
598
|
+
// below remains the gate. An unreadable config still refuses.
|
|
458
599
|
const planMode = await inspectPlanModeConfig(options.kimiHome);
|
|
459
|
-
|
|
600
|
+
const printCancelsPlan = planMode.kind === "refuse" &&
|
|
601
|
+
planMode.refusalKind === "v2-plan-mode-configured" &&
|
|
602
|
+
certifiedPrintLaunchHas(options, "print-cancels-plan");
|
|
603
|
+
if (planMode.kind === "refuse" && !printCancelsPlan) {
|
|
460
604
|
const code = planMode.refusalKind === "v2-plan-mode-configured"
|
|
461
605
|
? "CLI_V2_PLAN_MODE_CONFIGURED"
|
|
462
606
|
: "CLI_V2_CONFIG_UNREADABLE";
|
|
@@ -467,7 +611,9 @@ export async function assertNativeV2Preflight(options) {
|
|
|
467
611
|
details: { refusal_kind: planMode.refusalKind, retryable_after_setup: false },
|
|
468
612
|
});
|
|
469
613
|
}
|
|
470
|
-
const environment = await inspectEnvironmentConfig(options.kimiHome
|
|
614
|
+
const environment = await inspectEnvironmentConfig(options.kimiHome, {
|
|
615
|
+
allowDefaultEnvironment: certifiedPrintLaunchHas(options, "local-environment"),
|
|
616
|
+
});
|
|
471
617
|
if (environment.kind === "refuse") {
|
|
472
618
|
const code = environment.refusalKind === "v2-environment-configured"
|
|
473
619
|
? "CLI_V2_ENVIRONMENT_UNSAFE"
|
|
@@ -483,8 +629,18 @@ export async function assertNativeV2Preflight(options) {
|
|
|
483
629
|
details: { refusal_kind: environment.refusalKind, retryable_after_setup: false },
|
|
484
630
|
});
|
|
485
631
|
}
|
|
486
|
-
|
|
487
|
-
|
|
632
|
+
if (environment.trustDisabled === true)
|
|
633
|
+
warnings.push(WORKSPACE_TRUST_DISABLED_WARNING);
|
|
634
|
+
// Every native-v2 child runs with tower and subagent fork forced off by
|
|
635
|
+
// per-flag env and without the master flag. On a reviewed release that is
|
|
636
|
+
// proven to win; an uncertified release's flag handling is unreviewed, so
|
|
637
|
+
// the caller is told what is switched on. Only a launch with no plan refuses.
|
|
638
|
+
const uncertified = options.release?.certification === "uncertified";
|
|
639
|
+
const experimentalConfig = options.release === undefined || uncertified
|
|
640
|
+
? await inspectExperimentalConfig(options.kimiHome, options.env)
|
|
641
|
+
: { inspection: { kind: "ok" }, switchedOn: [] };
|
|
642
|
+
const experimental = experimentalConfig.inspection;
|
|
643
|
+
if (experimental.kind === "refuse" && !(uncertified && experimental.selectors.length > 0)) {
|
|
488
644
|
throw new RuntimeError("CLI_V2_EXPERIMENTAL_UNSAFE", `${experimental.reason} Unset the listed selector(s) before retrying.`, stage, {
|
|
489
645
|
details: {
|
|
490
646
|
refusal_kind: "v2-experimental-unsafe",
|
|
@@ -493,8 +649,11 @@ export async function assertNativeV2Preflight(options) {
|
|
|
493
649
|
},
|
|
494
650
|
});
|
|
495
651
|
}
|
|
652
|
+
if (uncertified && experimentalConfig.switchedOn.length > 0) {
|
|
653
|
+
warnings.push(experimentalSelectorsWarning(experimentalConfig.switchedOn));
|
|
654
|
+
}
|
|
496
655
|
if (options.resumeSessionId !== undefined) {
|
|
497
|
-
const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot);
|
|
656
|
+
const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot, { tolerateCancelledDefaultEnter: certifiedPrintLaunchHas(options, "print-cancels-plan") });
|
|
498
657
|
if (journalScan.kind === "environment") {
|
|
499
658
|
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
659
|
details: {
|
|
@@ -513,6 +672,9 @@ export async function assertNativeV2Preflight(options) {
|
|
|
513
672
|
},
|
|
514
673
|
});
|
|
515
674
|
}
|
|
675
|
+
if (journalScan.kind === "tower") {
|
|
676
|
+
throw new RuntimeError("KIMI_SESSION_TOWER_ACTIVE", `Saved session ${options.resumeSessionId} is in tower mode (${journalScan.journal}). Resuming it lets Kimi update this workspace's .tower state outside the plugin's hook. Turn tower mode off in that session with /tower, or start a fresh session; saved session state was not modified.`, stage, { details: { refusal_kind: "session-tower-active", retryable_after_setup: false } });
|
|
677
|
+
}
|
|
516
678
|
if (journalScan.kind === "unavailable") {
|
|
517
679
|
throw new RuntimeError("KIMI_SESSION_JOURNAL_UNAVAILABLE", `Could not verify saved session ${options.resumeSessionId} is free of plan-mode state (${journalScan.reason}). Start a fresh session; saved session state was not modified.`, stage, {
|
|
518
680
|
details: {
|
|
@@ -522,4 +684,5 @@ export async function assertNativeV2Preflight(options) {
|
|
|
522
684
|
});
|
|
523
685
|
}
|
|
524
686
|
}
|
|
687
|
+
return { warnings };
|
|
525
688
|
}
|