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
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
// - Refusals here are NOT /kimi:setup-recoverable and must never be
|
|
30
30
|
// described as hook drift.
|
|
31
31
|
import { constants as fsConstants } from "node:fs";
|
|
32
|
-
import { open, readdir } from "node:fs/promises";
|
|
32
|
+
import { lstat, open, readdir } from "node:fs/promises";
|
|
33
33
|
import path from "node:path";
|
|
34
34
|
import { RuntimeError } from "./errors.js";
|
|
35
35
|
import { kimiCodeConfigPath } from "./kimi-home.js";
|
|
@@ -44,7 +44,7 @@ const CONFIG_MAX_BYTES = 1 * 1024 * 1024;
|
|
|
44
44
|
const JOURNAL_MAX_BYTES = 64 * 1024 * 1024;
|
|
45
45
|
/** Bounded directory enumeration so a pathological sessions/ tree refuses
|
|
46
46
|
* instead of scanning forever. */
|
|
47
|
-
const DIR_ENUM_CAP = 4096;
|
|
47
|
+
export const DIR_ENUM_CAP = 4096;
|
|
48
48
|
const TRUTHY_STRINGS = new Set(["1", "true", "yes", "on"]);
|
|
49
49
|
function isTruthySelectorValue(value) {
|
|
50
50
|
if (value === true)
|
|
@@ -58,7 +58,7 @@ function isTruthySelectorValue(value) {
|
|
|
58
58
|
* config lock reader in runtime/hooks/config-safety.ts. Never partial-reads:
|
|
59
59
|
* an oversized file refuses rather than being silently truncated.
|
|
60
60
|
*/
|
|
61
|
-
async function readSmallFileSafe(filePath, maxBytes) {
|
|
61
|
+
export async function readSmallFileSafe(filePath, maxBytes) {
|
|
62
62
|
let handle;
|
|
63
63
|
try {
|
|
64
64
|
handle = await open(filePath, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0));
|
|
@@ -166,7 +166,7 @@ export async function inspectPlanModeConfig(kimiHome) {
|
|
|
166
166
|
* sessionManagerService.openCreation, i.e. when a session is created. A fresh
|
|
167
167
|
* print on a certified row passes `--environment local`, which skips the
|
|
168
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.
|
|
169
|
+
* stored binding (state.json) and never consults the default (2.5.0-2.8.0).
|
|
170
170
|
* The stored binding is checked separately by scanSessionJournalsForPlan, so
|
|
171
171
|
* that one key stops refusing. A non-table section still refuses.
|
|
172
172
|
*/
|
|
@@ -219,8 +219,13 @@ export async function inspectEnvironmentConfig(kimiHome, options = {}) {
|
|
|
219
219
|
return { kind: "ok" };
|
|
220
220
|
}
|
|
221
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
|
+
}
|
|
222
226
|
/**
|
|
223
|
-
*
|
|
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.
|
|
224
229
|
* Sources (per-flag precedence upstream is env → [experimental] config →
|
|
225
230
|
* master flag → default): the `[experimental]` table keys `tower` and
|
|
226
231
|
* `subagent_fork` in `<kimiHome>/config.toml`, and the per-flag env vars
|
|
@@ -231,11 +236,22 @@ export const WORKSPACE_TRUST_DISABLED_WARNING = "Workspace trust is disabled in
|
|
|
231
236
|
* Config read errors follow inspectPlanModeConfig's fail-closed rules.
|
|
232
237
|
*/
|
|
233
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) {
|
|
234
249
|
const parsed = await readParsedConfig(kimiHome);
|
|
235
250
|
if (parsed.kind === "unreadable") {
|
|
236
|
-
return { kind: "refuse", selectors: [], reason: parsed.reason };
|
|
251
|
+
return { inspection: { kind: "refuse", selectors: [], reason: parsed.reason }, switchedOn: [] };
|
|
237
252
|
}
|
|
238
253
|
const selectors = [];
|
|
254
|
+
const switchedOn = [];
|
|
239
255
|
const experimental = parsed.config?.["experimental"];
|
|
240
256
|
if (experimental !== null && typeof experimental === "object" && !Array.isArray(experimental)) {
|
|
241
257
|
const table = experimental;
|
|
@@ -244,6 +260,10 @@ export async function inspectExperimentalSelectors(kimiHome, env) {
|
|
|
244
260
|
if (isTruthySelectorValue(table["subagent_fork"])) {
|
|
245
261
|
selectors.push("config:[experimental].subagent_fork");
|
|
246
262
|
}
|
|
263
|
+
for (const [key, value] of Object.entries(table)) {
|
|
264
|
+
if (isTruthySelectorValue(value))
|
|
265
|
+
switchedOn.push(`config:[experimental].${key}`);
|
|
266
|
+
}
|
|
247
267
|
}
|
|
248
268
|
if (isTruthySelectorValue(env.KIMI_CODE_EXPERIMENTAL_TOWER)) {
|
|
249
269
|
selectors.push("env:KIMI_CODE_EXPERIMENTAL_TOWER");
|
|
@@ -251,15 +271,34 @@ export async function inspectExperimentalSelectors(kimiHome, env) {
|
|
|
251
271
|
if (isTruthySelectorValue(env.KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK)) {
|
|
252
272
|
selectors.push("env:KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK");
|
|
253
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
|
+
}
|
|
254
280
|
if (selectors.length === 0)
|
|
255
|
-
return { kind: "ok" };
|
|
281
|
+
return { inspection: { kind: "ok" }, switchedOn };
|
|
256
282
|
return {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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,
|
|
260
289
|
};
|
|
261
290
|
}
|
|
262
|
-
|
|
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) {
|
|
263
302
|
let entries;
|
|
264
303
|
try {
|
|
265
304
|
entries = await readdir(dirPath, { withFileTypes: true });
|
|
@@ -276,7 +315,8 @@ async function boundedReaddir(dirPath, cap) {
|
|
|
276
315
|
return { kind: "cap-exceeded" };
|
|
277
316
|
return { kind: "ok", entries };
|
|
278
317
|
}
|
|
279
|
-
|
|
318
|
+
/** `maxBytes` omitted: no size cap (the caller never reads the content). */
|
|
319
|
+
export async function openJournalSafely(journalPath, maxBytes) {
|
|
280
320
|
let handle;
|
|
281
321
|
try {
|
|
282
322
|
// O_NONBLOCK so a FIFO planted at the journal path (no writer) does not
|
|
@@ -297,7 +337,7 @@ async function openJournalSafely(journalPath, maxBytes) {
|
|
|
297
337
|
await handle.close().catch(() => undefined);
|
|
298
338
|
return { kind: "unavailable", reason: "journal is not a regular file" };
|
|
299
339
|
}
|
|
300
|
-
if (stats.size > BigInt(maxBytes)) {
|
|
340
|
+
if (maxBytes !== undefined && stats.size > BigInt(maxBytes)) {
|
|
301
341
|
await handle.close().catch(() => undefined);
|
|
302
342
|
return { kind: "unavailable", reason: `journal exceeds ${maxBytes} byte cap` };
|
|
303
343
|
}
|
|
@@ -305,14 +345,25 @@ async function openJournalSafely(journalPath, maxBytes) {
|
|
|
305
345
|
}
|
|
306
346
|
/** Records that mean the session already did work: a turn, prompt, tool, model or delegated task. */
|
|
307
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
|
+
]);
|
|
308
358
|
/** Records that make replay non-linear (branch switch or undo), so a fold could differ. */
|
|
309
359
|
const REWIND_RECORD = /^(agent\.switched$|context\.undo$|context\.undone$)/;
|
|
310
|
-
async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelledDefaultEnter = false) {
|
|
360
|
+
async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelledDefaultEnter = false, main = false) {
|
|
311
361
|
// G2: a print-created session's main journal holds the create-time
|
|
312
|
-
// `default_plan_mode` enter
|
|
313
|
-
//
|
|
314
|
-
//
|
|
315
|
-
//
|
|
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.
|
|
316
367
|
// Replay stops at the first corrupt line, so records after it may add
|
|
317
368
|
// taints (seeing more is conservative) but never start or complete a fold.
|
|
318
369
|
let sawActivity = false;
|
|
@@ -320,10 +371,17 @@ async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelled
|
|
|
320
371
|
let sawCorrupt = false;
|
|
321
372
|
let pendingEnter = null;
|
|
322
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;
|
|
323
380
|
const taintEnter = { kind: "tainted", recordType: "plan_mode.enter" };
|
|
324
381
|
for await (const framed of kimiJournalRecords(handle.createReadStream())) {
|
|
325
382
|
const { line, parsed } = framed;
|
|
326
383
|
if (parsed === UNPARSEABLE_JOURNAL_LINE) {
|
|
384
|
+
const firstCorrupt = framed.terminated && !sawCorrupt;
|
|
327
385
|
if (framed.terminated)
|
|
328
386
|
sawCorrupt = true;
|
|
329
387
|
if (pendingEnter !== null)
|
|
@@ -334,28 +392,44 @@ async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelled
|
|
|
334
392
|
if (line.includes('"environment.set_binding')) {
|
|
335
393
|
return { kind: "environment", recordType: "<unparseable-environment-binding>" };
|
|
336
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;
|
|
337
399
|
continue;
|
|
338
400
|
}
|
|
339
401
|
const record = parsed;
|
|
340
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);
|
|
341
413
|
if (pendingEnter !== null) {
|
|
342
414
|
const cancelId = record?.["id"];
|
|
343
415
|
const cancels = type === "plan_mode.cancel" && record?.["agentId"] === "main" &&
|
|
344
416
|
(cancelId === undefined || cancelId === pendingEnter.id);
|
|
345
|
-
if (
|
|
417
|
+
if (cancels) {
|
|
418
|
+
pendingEnter = null;
|
|
419
|
+
toleratedPair = true;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (typeof type !== "string" || !PLAN_PAIR_BOOKKEEPING.has(type))
|
|
346
423
|
return taintEnter;
|
|
347
|
-
pendingEnter = null;
|
|
348
|
-
toleratedPair = true;
|
|
349
|
-
continue;
|
|
350
424
|
}
|
|
351
|
-
if (
|
|
425
|
+
if (isRewind) {
|
|
352
426
|
if (toleratedPair)
|
|
353
427
|
return taintEnter;
|
|
354
428
|
sawRewind = true;
|
|
355
429
|
}
|
|
356
|
-
if (
|
|
430
|
+
if (isActivity)
|
|
357
431
|
sawActivity = true;
|
|
358
|
-
if (
|
|
432
|
+
if (isPlanRecord) {
|
|
359
433
|
if (tolerateCancelledDefaultEnter && type === "plan_mode.enter" && !toleratedPair &&
|
|
360
434
|
!sawActivity && !sawRewind && !sawCorrupt && record?.["agentId"] === "main" && typeof record?.["id"] === "string") {
|
|
361
435
|
pendingEnter = { id: record["id"] };
|
|
@@ -376,7 +450,7 @@ async function scanJournalLines(handle, expectedExecutionRoot, tolerateCancelled
|
|
|
376
450
|
// An enter as the last record was never cancelled.
|
|
377
451
|
if (pendingEnter !== null)
|
|
378
452
|
return taintEnter;
|
|
379
|
-
return null;
|
|
453
|
+
return towerActive ? { kind: "tower" } : null;
|
|
380
454
|
}
|
|
381
455
|
async function inspectSessionMetadataEnvironment(statePath, expectedExecutionRoot) {
|
|
382
456
|
const read = await readSmallFileSafe(statePath, CONFIG_MAX_BYTES);
|
|
@@ -459,6 +533,10 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
459
533
|
if (agentEntries.kind === "unreadable") {
|
|
460
534
|
return { kind: "unavailable", reason: `could not enumerate agent journals: ${agentEntries.reason}` };
|
|
461
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"));
|
|
462
540
|
for (const agentEntry of agentEntries.entries) {
|
|
463
541
|
if (agentEntry.isSymbolicLink()) {
|
|
464
542
|
return {
|
|
@@ -468,7 +546,10 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
468
546
|
}
|
|
469
547
|
if (!agentEntry.isDirectory())
|
|
470
548
|
continue;
|
|
471
|
-
|
|
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 });
|
|
472
553
|
}
|
|
473
554
|
}
|
|
474
555
|
if (journalPaths.length === 0) {
|
|
@@ -480,13 +561,15 @@ export async function scanSessionJournalsForPlan(kimiHome, sessionId, expectedEx
|
|
|
480
561
|
return { kind: "unavailable", reason: `${journalPath}: ${opened.reason}` };
|
|
481
562
|
}
|
|
482
563
|
try {
|
|
483
|
-
const finding = await scanJournalLines(opened.handle, expectedExecutionRoot, main && options.tolerateCancelledDefaultEnter === true);
|
|
564
|
+
const finding = await scanJournalLines(opened.handle, expectedExecutionRoot, main && options.tolerateCancelledDefaultEnter === true, main);
|
|
484
565
|
if (finding?.kind === "tainted") {
|
|
485
566
|
return { kind: "tainted", journal: journalPath, recordType: finding.recordType };
|
|
486
567
|
}
|
|
487
568
|
if (finding?.kind === "environment") {
|
|
488
569
|
return { kind: "environment", journal: journalPath, recordType: finding.recordType };
|
|
489
570
|
}
|
|
571
|
+
if (finding?.kind === "tower")
|
|
572
|
+
return { kind: "tower", journal: journalPath };
|
|
490
573
|
}
|
|
491
574
|
finally {
|
|
492
575
|
await opened.handle.close().catch(() => undefined);
|
|
@@ -548,13 +631,16 @@ export async function assertNativeV2Preflight(options) {
|
|
|
548
631
|
}
|
|
549
632
|
if (environment.trustDisabled === true)
|
|
550
633
|
warnings.push(WORKSPACE_TRUST_DISABLED_WARNING);
|
|
551
|
-
//
|
|
552
|
-
//
|
|
553
|
-
//
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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)) {
|
|
558
644
|
throw new RuntimeError("CLI_V2_EXPERIMENTAL_UNSAFE", `${experimental.reason} Unset the listed selector(s) before retrying.`, stage, {
|
|
559
645
|
details: {
|
|
560
646
|
refusal_kind: "v2-experimental-unsafe",
|
|
@@ -563,6 +649,9 @@ export async function assertNativeV2Preflight(options) {
|
|
|
563
649
|
},
|
|
564
650
|
});
|
|
565
651
|
}
|
|
652
|
+
if (uncertified && experimentalConfig.switchedOn.length > 0) {
|
|
653
|
+
warnings.push(experimentalSelectorsWarning(experimentalConfig.switchedOn));
|
|
654
|
+
}
|
|
566
655
|
if (options.resumeSessionId !== undefined) {
|
|
567
656
|
const journalScan = await scanSessionJournalsForPlan(options.kimiHome, options.resumeSessionId, options.expectedExecutionRoot, { tolerateCancelledDefaultEnter: certifiedPrintLaunchHas(options, "print-cancels-plan") });
|
|
568
657
|
if (journalScan.kind === "environment") {
|
|
@@ -583,6 +672,9 @@ export async function assertNativeV2Preflight(options) {
|
|
|
583
672
|
},
|
|
584
673
|
});
|
|
585
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
|
+
}
|
|
586
678
|
if (journalScan.kind === "unavailable") {
|
|
587
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, {
|
|
588
680
|
details: {
|
|
@@ -4,7 +4,7 @@ import { SCOPE_FLAGS_WRITE_MESSAGE } from "./read-scope.js";
|
|
|
4
4
|
* Unknown flag-shaped tokens hard-fail instead of being absorbed into prose.
|
|
5
5
|
* Parsing still switches to prose at the first non-flag token or after `--`.
|
|
6
6
|
*/
|
|
7
|
-
function looksLikeFlag(token) {
|
|
7
|
+
export function looksLikeFlag(token) {
|
|
8
8
|
if (!token.startsWith("-")) {
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
@@ -15,11 +15,14 @@ function looksLikeFlag(token) {
|
|
|
15
15
|
return /^-[a-zA-Z]$/.test(token);
|
|
16
16
|
}
|
|
17
17
|
const SCOPE_SUPPORTED_FLAGS = "--read-root <absolute-dir> (repeatable), --network";
|
|
18
|
-
export const
|
|
18
|
+
export const MAX_SESSION_REFERENCES = 8;
|
|
19
|
+
export const SESSION_REFERENCE_ID_MAX = 128;
|
|
20
|
+
const REFERENCE_SUPPORTED_FLAG = `--reference-session <job-id|session-id> (repeatable, at most ${MAX_SESSION_REFERENCES})`;
|
|
21
|
+
export const RESCUE_SUPPORTED_FLAGS = `-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --background, --wait, --fresh, -r, --resume <job-id|session-id>, ${REFERENCE_SUPPORTED_FLAG}`;
|
|
19
22
|
export const ASK_SUPPORTED_FLAGS = `${RESCUE_SUPPORTED_FLAGS}, ${SCOPE_SUPPORTED_FLAGS}`;
|
|
20
|
-
export const REVIEW_SUPPORTED_FLAGS = `--base <ref>, -m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, ${SCOPE_SUPPORTED_FLAGS}`;
|
|
21
|
-
export const JOB_LOOKUP_SUPPORTED_FLAGS = "--type <review|challenge|rescue|
|
|
22
|
-
export const SETUP_SUPPORTED_FLAGS = "--check, --uninstall, --
|
|
23
|
+
export const REVIEW_SUPPORTED_FLAGS = `--base <ref>, -m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, ${SCOPE_SUPPORTED_FLAGS}, ${REFERENCE_SUPPORTED_FLAG}`;
|
|
24
|
+
export const JOB_LOOKUP_SUPPORTED_FLAGS = "--type <review|challenge|rescue|ask>, --json";
|
|
25
|
+
export const SETUP_SUPPORTED_FLAGS = "--check, --uninstall, --models [--json] (without other setup flags), --install-kimi [--json] (without other setup flags), --repair-sessions [--apply] [--all] (without other setup flags)";
|
|
23
26
|
export const RECOVER_SWARM_SUPPORTED_FLAGS = "--apply";
|
|
24
27
|
export const REPAIR_SESSIONS_SUPPORTED_FLAGS = "--apply, --all";
|
|
25
28
|
export const REPLAY_SUPPORTED_FLAGS = "none (one job-id required)";
|
|
@@ -32,7 +35,7 @@ export function validateThinkingEffort(value, stage = "args.parse", lowercase =
|
|
|
32
35
|
return effort;
|
|
33
36
|
}
|
|
34
37
|
export const PURSUE_SUPPORTED_FLAGS = "-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --turns <N>";
|
|
35
|
-
export const SWARM_SUPPORTED_FLAGS = `-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --cap <N>, --max-concurrency <N>, --write, ${SCOPE_SUPPORTED_FLAGS} (read-only swarm only)`;
|
|
38
|
+
export const SWARM_SUPPORTED_FLAGS = `-m/--model <name>, --thinking <off|low|medium|high>, --budget <30m|1h|90s>, --cap <N>, --max-concurrency <N>, --write, ${SCOPE_SUPPORTED_FLAGS} (read-only swarm only), ${REFERENCE_SUPPORTED_FLAG}`;
|
|
36
39
|
/**
|
|
37
40
|
* Parser for /kimi:swarm. Foreground-only: no --background/--fresh/--resume.
|
|
38
41
|
* Trailing tokens are the objective.
|
|
@@ -46,6 +49,7 @@ export function parseSwarmArgs(argv) {
|
|
|
46
49
|
let write = false;
|
|
47
50
|
const readRoots = [];
|
|
48
51
|
let network = false;
|
|
52
|
+
const references = [];
|
|
49
53
|
let trailingTokens;
|
|
50
54
|
for (let index = 0; index < argv.length; index += 1) {
|
|
51
55
|
const token = argv[index];
|
|
@@ -67,6 +71,9 @@ export function parseSwarmArgs(argv) {
|
|
|
67
71
|
case "--model":
|
|
68
72
|
model = readModel(token, argv[++index], "swarm.parse");
|
|
69
73
|
break;
|
|
74
|
+
case "--reference-session":
|
|
75
|
+
references.push(referenceSessionValue(argv[++index], "swarm.parse"));
|
|
76
|
+
break;
|
|
70
77
|
case "--write":
|
|
71
78
|
write = true;
|
|
72
79
|
break;
|
|
@@ -105,9 +112,26 @@ export function parseSwarmArgs(argv) {
|
|
|
105
112
|
model,
|
|
106
113
|
thinkingEffort,
|
|
107
114
|
...scopeFields(readRoots, network),
|
|
115
|
+
...referenceSessionsField(references, "swarm.parse"),
|
|
108
116
|
objective: trailingTokens?.join(" "),
|
|
109
117
|
};
|
|
110
118
|
}
|
|
119
|
+
function referenceSessionValue(value, stage) {
|
|
120
|
+
if (!value || value.startsWith("-")) {
|
|
121
|
+
throw new RuntimeError("INVALID_ARGS", "--reference-session requires a job id or Kimi session id.", stage);
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
/** Omitted when absent so parsed shapes stay unchanged; refuses more than the cap. */
|
|
126
|
+
function referenceSessionsField(values, stage) {
|
|
127
|
+
if (values.length === 0)
|
|
128
|
+
return {};
|
|
129
|
+
const unique = [...new Set(values)];
|
|
130
|
+
if (unique.length > MAX_SESSION_REFERENCES) {
|
|
131
|
+
throw new RuntimeError("INVALID_ARGS", `--reference-session accepts at most ${MAX_SESSION_REFERENCES} distinct sessions; got ${unique.length}.`, stage);
|
|
132
|
+
}
|
|
133
|
+
return { referenceSessions: unique };
|
|
134
|
+
}
|
|
111
135
|
/** Omit default-scope fields so parsed shapes stay unchanged without the flags. */
|
|
112
136
|
function scopeFields(readRoots, network) {
|
|
113
137
|
return {
|
|
@@ -262,7 +286,7 @@ export function parsePursueArgs(argv) {
|
|
|
262
286
|
objective: trailingTokens?.join(" "),
|
|
263
287
|
};
|
|
264
288
|
}
|
|
265
|
-
const VALUE_TAKING_FLAGS = new Set(["--thinking", "-m", "--model", "--budget", "--resume", "--base", "--cap", "--max-concurrency", "--turns", "--type", "--read-root"]);
|
|
289
|
+
const VALUE_TAKING_FLAGS = new Set(["--mode", "--thinking", "-m", "--model", "--budget", "--resume", "--base", "--cap", "--max-concurrency", "--turns", "--type", "--read-root", "--reference-session"]);
|
|
266
290
|
/**
|
|
267
291
|
* `--help` / `-h` counts only inside the leading flag region: before `--`
|
|
268
292
|
* and before the first prose token. The value of a value-taking flag is
|
|
@@ -278,7 +302,7 @@ export function hasHelpFlag(argv) {
|
|
|
278
302
|
return false;
|
|
279
303
|
if (token === "--help" || token === "-h")
|
|
280
304
|
return true;
|
|
281
|
-
if (!token
|
|
305
|
+
if (!looksLikeFlag(token))
|
|
282
306
|
return false;
|
|
283
307
|
if (VALUE_TAKING_FLAGS.has(token)) {
|
|
284
308
|
const value = argv[index + 1];
|
|
@@ -337,6 +361,7 @@ function parsePromptArgs(argv, kind) {
|
|
|
337
361
|
let explicitResumeTarget = false;
|
|
338
362
|
const readRoots = [];
|
|
339
363
|
let network = false;
|
|
364
|
+
const references = [];
|
|
340
365
|
let trailingTokens;
|
|
341
366
|
for (let index = 0; index < argv.length; index += 1) {
|
|
342
367
|
const token = argv[index];
|
|
@@ -357,6 +382,9 @@ function parsePromptArgs(argv, kind) {
|
|
|
357
382
|
case "--budget":
|
|
358
383
|
budgetMs = readBudget(argv[++index], `${kind}.parse`, "response");
|
|
359
384
|
break;
|
|
385
|
+
case "--reference-session":
|
|
386
|
+
references.push(referenceSessionValue(argv[++index], `${kind}.parse`));
|
|
387
|
+
break;
|
|
360
388
|
case "-m":
|
|
361
389
|
case "--model":
|
|
362
390
|
model = readModel(token, argv[++index], "args.parse");
|
|
@@ -419,11 +447,12 @@ function parsePromptArgs(argv, kind) {
|
|
|
419
447
|
model,
|
|
420
448
|
thinkingEffort,
|
|
421
449
|
...scopeFields(readRoots, network),
|
|
450
|
+
...referenceSessionsField(references, `${kind}.parse`),
|
|
422
451
|
prompt: trailingTokens?.join(" "),
|
|
423
452
|
};
|
|
424
453
|
}
|
|
425
454
|
export function parseReviewArgs(argv, commandName = "review") {
|
|
426
|
-
const parsed = parseKnownFlags(argv, new Set(["--budget", "--base", "--background", "--wait", "-m", "--model", "--read-root", "--network"]), commandName);
|
|
455
|
+
const parsed = parseKnownFlags(argv, new Set(["--budget", "--base", "--background", "--wait", "-m", "--model", "--read-root", "--network", "--reference-session"]), commandName);
|
|
427
456
|
return {
|
|
428
457
|
budgetMs: parsed.budgetMs,
|
|
429
458
|
base: parsed.base,
|
|
@@ -432,6 +461,7 @@ export function parseReviewArgs(argv, commandName = "review") {
|
|
|
432
461
|
model: parsed.model,
|
|
433
462
|
thinkingEffort: parsed.thinkingEffort,
|
|
434
463
|
...scopeFields(parsed.readRoots, parsed.network),
|
|
464
|
+
...referenceSessionsField(parsed.references, `${commandName}.parse`),
|
|
435
465
|
focus: parsed.trailingText,
|
|
436
466
|
};
|
|
437
467
|
}
|
|
@@ -444,7 +474,7 @@ export function parseJobLookupArgs(argv) {
|
|
|
444
474
|
if (token === "--type") {
|
|
445
475
|
const value = argv[index + 1];
|
|
446
476
|
if (!value || !isManagedCommandType(value)) {
|
|
447
|
-
throw new RuntimeError("INVALID_ARGS", "--type requires one of review, challenge, rescue,
|
|
477
|
+
throw new RuntimeError("INVALID_ARGS", "--type requires one of review, challenge, rescue, ask.", "args.parse");
|
|
448
478
|
}
|
|
449
479
|
type = value;
|
|
450
480
|
index += 1;
|
|
@@ -472,7 +502,6 @@ function isManagedCommandType(value) {
|
|
|
472
502
|
return (value === "review" ||
|
|
473
503
|
value === "challenge" ||
|
|
474
504
|
value === "rescue" ||
|
|
475
|
-
value === "review_gate" ||
|
|
476
505
|
value === "ask");
|
|
477
506
|
}
|
|
478
507
|
function parseKnownFlags(argv, knownFlags, commandName) {
|
|
@@ -484,6 +513,7 @@ function parseKnownFlags(argv, knownFlags, commandName) {
|
|
|
484
513
|
let wait = false;
|
|
485
514
|
const readRoots = [];
|
|
486
515
|
let network = false;
|
|
516
|
+
const references = [];
|
|
487
517
|
let trailingTokens;
|
|
488
518
|
for (let index = 0; index < argv.length; index += 1) {
|
|
489
519
|
const token = argv[index];
|
|
@@ -535,6 +565,9 @@ function parseKnownFlags(argv, knownFlags, commandName) {
|
|
|
535
565
|
case "--network":
|
|
536
566
|
network = true;
|
|
537
567
|
break;
|
|
568
|
+
case "--reference-session":
|
|
569
|
+
references.push(referenceSessionValue(argv[++index], `${commandName}.parse`));
|
|
570
|
+
break;
|
|
538
571
|
// The early `if (!knownFlags.has(token))` gate above means we only
|
|
539
572
|
// reach this switch with tokens that ARE in knownFlags, and every
|
|
540
573
|
// member is handled above. A `default` arm would be unreachable.
|
|
@@ -547,6 +580,7 @@ function parseKnownFlags(argv, knownFlags, commandName) {
|
|
|
547
580
|
wait,
|
|
548
581
|
readRoots,
|
|
549
582
|
network,
|
|
583
|
+
references,
|
|
550
584
|
model,
|
|
551
585
|
thinkingEffort,
|
|
552
586
|
trailingText: trailingTokens?.join(" "),
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { constants } from "node:fs";
|
|
2
|
-
import { access, mkdir } from "node:fs/promises";
|
|
2
|
+
import { access, chmod, lstat, mkdir } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { resolvePluginDataRoot } from "./plugin-data.js";
|
|
5
5
|
export function resolvePluginPaths(env) {
|
|
6
|
-
const
|
|
7
|
-
const pluginRoot = path.join(
|
|
6
|
+
const dataRoot = resolvePluginDataRoot(env);
|
|
7
|
+
const pluginRoot = path.join(dataRoot, "kimi-plugin-cc");
|
|
8
|
+
const hookDir = path.join(pluginRoot, "hook");
|
|
8
9
|
return {
|
|
9
|
-
|
|
10
|
+
dataRoot,
|
|
11
|
+
claudePluginData: dataRoot,
|
|
10
12
|
pluginRoot,
|
|
11
13
|
stateDbPath: path.join(pluginRoot, "state.db"),
|
|
12
14
|
logsDir: path.join(pluginRoot, "logs"),
|
|
13
15
|
artifactsDir: path.join(pluginRoot, "artifacts"),
|
|
16
|
+
hookDir,
|
|
17
|
+
hookScriptPath: path.join(hookDir, "approval-hook.js"),
|
|
14
18
|
worktreesDir: path.join(pluginRoot, "worktrees"),
|
|
15
19
|
configPath: path.join(pluginRoot, "config.json"),
|
|
16
20
|
};
|
|
@@ -24,12 +28,18 @@ export function resolveKimiBinDir(env) {
|
|
|
24
28
|
return path.join(resolvePluginPaths(env).pluginRoot, "kimi-bin");
|
|
25
29
|
}
|
|
26
30
|
export async function ensurePluginPaths(paths) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// Never chmod paths.dataRoot (often shared ~/.local/share or a user directory),
|
|
32
|
+
// and never follow a symlink when tightening permissions on plugin directories.
|
|
33
|
+
for (const dir of [paths.pluginRoot, paths.logsDir, paths.artifactsDir]) {
|
|
34
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
35
|
+
if (process.platform !== "win32") {
|
|
36
|
+
const info = await lstat(dir);
|
|
37
|
+
if (!info.isSymbolicLink()) {
|
|
38
|
+
await chmod(dir, 0o700);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
await access(dir, constants.R_OK | constants.W_OK);
|
|
42
|
+
}
|
|
33
43
|
// worktreesDir is created lazily by the write-swarm path (not every command
|
|
34
44
|
// needs it), so it is intentionally NOT required here.
|
|
35
45
|
}
|