kimi-plugin-cc 3.0.0 → 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 -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 +277 -262
- 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 +179 -107
- package/dist/hooks/install.js +44 -166
- package/dist/hooks/managed-block.js +44 -95
- 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 +45 -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 +277 -262
- 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 +179 -107
- package/plugins/kimi-codex/dist/hooks/install.js +44 -166
- package/plugins/kimi-codex/dist/hooks/managed-block.js +44 -95
- package/plugins/kimi-codex/dist/job-store.js +117 -49
- package/plugins/kimi-codex/dist/jobs.js +53 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
- package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
- package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
- package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
- package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
- package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
- package/plugins/kimi-codex/dist/logging.js +12 -7
- package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
- package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
- package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
- package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
- package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
- package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
- package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
- package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
- package/plugins/kimi-codex/dist/parsing.js +45 -11
- package/plugins/kimi-codex/dist/paths.js +20 -10
- package/plugins/kimi-codex/dist/plugin-data.js +28 -83
- package/plugins/kimi-codex/dist/read-scope.js +2 -2
- package/plugins/kimi-codex/dist/render.js +13 -38
- package/plugins/kimi-codex/dist/session-references.js +216 -0
- package/plugins/kimi-codex/dist/session-title.js +1 -1
- package/plugins/kimi-codex/dist/surface-routing.js +92 -5
- package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/scripts/companion.sh +4 -15
- package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
- package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
- package/scripts/companion.sh +4 -15
- package/skills/kimi/SKILL.md +77 -0
- package/skills/kimi/agents/openai.yaml +6 -0
- package/CHANGELOG.md +0 -1402
- package/agents/kimi-pursue.md +0 -93
- package/agents/kimi-review.md +0 -86
- package/agents/kimi-swarm.md +0 -88
- package/agents/kimi-task.md +0 -93
- package/commands/README.md +0 -14
- package/commands/cancel.md +0 -17
- package/commands/pursue.md +0 -41
- package/commands/replay.md +0 -13
- package/commands/result.md +0 -13
- package/commands/review.md +0 -40
- package/commands/setup.md +0 -25
- package/commands/status.md +0 -13
- package/commands/swarm.md +0 -45
- package/commands/task.md +0 -40
- package/dist/commands/review-gate.js +0 -391
- package/dist/config.js +0 -22
- package/dist/dsh/companion.js +0 -177
- package/dist/dsh/index.js +0 -167
- package/dist/hooks/review-gate-stop.js +0 -19
- package/dist/schemas/review-gate-output.js +0 -41
- package/docs/registry-releases.md +0 -228
- package/docs/upstream-2.4.1-certification.md +0 -54
- package/docs/upstream-2.5.0-certification.md +0 -52
- package/docs/upstream-2.5.1-certification.md +0 -47
- package/docs/upstream-2.5.2-certification.md +0 -40
- package/docs/upstream-2.5.3-certification.md +0 -73
- package/docs/upstream-2.6.0-certification.md +0 -65
- package/docs/upstream-2.6.2-certification.md +0 -144
- package/docs/upstream-2.6.3-certification.md +0 -100
- package/docs/upstream-2.7.2-certification.md +0 -113
- package/docs/upstream-2.7.3-certification.md +0 -95
- package/docs/windows-validation.md +0 -39
- package/hooks/README.md +0 -9
- package/hooks/hooks.json +0 -16
- package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-codex/dist/config.js +0 -22
- package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
- package/plugins/kimi-codex/dist/dsh/index.js +0 -167
- package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
- package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
- package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/LICENSE +0 -201
- package/plugins/kimi-dsh/README.md +0 -84
- package/plugins/kimi-dsh/cordis.patch.yml +0 -45
- package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
- package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
- package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
- package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
- package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
- package/plugins/kimi-dsh/dist/commands/models.js +0 -139
- package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
- package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
- package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
- package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
- package/plugins/kimi-dsh/dist/commands/result.js +0 -72
- package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-dsh/dist/commands/review.js +0 -217
- package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
- package/plugins/kimi-dsh/dist/commands/status.js +0 -27
- package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
- package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
- package/plugins/kimi-dsh/dist/companion.js +0 -99
- package/plugins/kimi-dsh/dist/config.js +0 -22
- package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
- package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
- package/plugins/kimi-dsh/dist/errors.js +0 -40
- package/plugins/kimi-dsh/dist/git.js +0 -216
- package/plugins/kimi-dsh/dist/help.js +0 -43
- package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
- package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
- package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
- package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-dsh/dist/job-id.js +0 -12
- package/plugins/kimi-dsh/dist/job-store.js +0 -631
- package/plugins/kimi-dsh/dist/jobs.js +0 -212
- package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
- package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
- package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
- package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
- package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
- package/plugins/kimi-dsh/dist/logging.js +0 -22
- package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
- package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
- package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
- package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
- package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
- package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
- package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
- package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
- package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
- package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
- package/plugins/kimi-dsh/dist/model-command.js +0 -34
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
- package/plugins/kimi-dsh/dist/package.json +0 -1
- package/plugins/kimi-dsh/dist/parsing.js +0 -554
- package/plugins/kimi-dsh/dist/paths.js +0 -35
- package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
- package/plugins/kimi-dsh/dist/process-tree.js +0 -597
- package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
- package/plugins/kimi-dsh/dist/read-scope.js +0 -435
- package/plugins/kimi-dsh/dist/render.js +0 -214
- package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
- package/plugins/kimi-dsh/dist/session-title.js +0 -313
- package/plugins/kimi-dsh/dist/stream-json.js +0 -344
- package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
- package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
- package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
- package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
- package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
- package/plugins/kimi-dsh/dist/types.js +0 -1
- package/plugins/kimi-dsh/dist/util.js +0 -28
- package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
- package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
- package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
- package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
- package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
- package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
- package/plugins/kimi-dsh/dist/version.js +0 -7
- package/plugins/kimi-dsh/package.json +0 -78
- package/plugins/kimi-dsh/scripts/companion.sh +0 -37
- package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
- package/scripts/review-gate-hook.sh +0 -32
package/assets/logo.svg
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128" fill="none" role="img" aria-label="Kimi">
|
|
2
|
+
<rect x="14" y="14" width="100" height="100" rx="24" fill="#0F766E" stroke="#2DD4BF" stroke-width="3"/>
|
|
3
|
+
<path d="M44 38V90" stroke="#FFFFFF" stroke-width="11" stroke-linecap="round"/>
|
|
4
|
+
<path d="M84 38L52 64L85 90" stroke="#FFFFFF" stroke-width="11" stroke-linecap="round" stroke-linejoin="round"/>
|
|
5
|
+
<circle cx="88" cy="36" r="5" fill="#5EEAD4"/>
|
|
6
|
+
</svg>
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
- insert:
|
|
2
|
+
- id: kimi-mcp
|
|
3
|
+
name: '@deepseek-ai/dsh-mcp-client'
|
|
4
|
+
config:
|
|
5
|
+
serverName: kimi
|
|
6
|
+
transport: stdio
|
|
7
|
+
command: !!js "(ctx.get('pluginPackages')?.packageOf('kimi-plugin-cc', ctx.baseUrl)?.dir ?? (ctx.get('profileContext')?.dir + '/node_modules/kimi-plugin-cc')) + '/scripts/companion.sh'"
|
|
8
|
+
args:
|
|
9
|
+
- mcp
|
|
10
|
+
cwd: !!js "ctx.get('profileContext')?.cwd ?? process.cwd()"
|
|
11
|
+
toolCallTimeoutMs: 86400000
|
|
12
|
+
- id: kimi-skill
|
|
13
|
+
name: '@deepseek-ai/dsh-skill-filesystem'
|
|
14
|
+
config:
|
|
15
|
+
providerName: kimi-plugin-cc
|
|
16
|
+
includeDefaultRoots: false
|
|
17
|
+
bundledSkillDir: !!js "(ctx.get('pluginPackages')?.packageOf('kimi-plugin-cc', ctx.baseUrl)?.dir ?? (ctx.get('profileContext')?.dir + '/node_modules/kimi-plugin-cc')) + '/skills'"
|
|
18
|
+
watch: false
|
package/dist/background-spawn.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { RuntimeError, formatError } from "./errors.js";
|
|
6
6
|
import { preferStableNodePath } from "./hooks/install-paths.js";
|
|
7
|
-
import { markJobFailed, waitForTerminalJob } from "./jobs.js";
|
|
7
|
+
import { markJobFailed, serializedProcessIdentity, waitForTerminalJob } from "./jobs.js";
|
|
8
8
|
import { JobStore } from "./job-store.js";
|
|
9
9
|
import { readArtifact } from "./render.js";
|
|
10
10
|
import { sleep } from "./util.js";
|
|
@@ -64,7 +64,7 @@ export async function startBackgroundJob(job, prompt, context, paths, options) {
|
|
|
64
64
|
KIMI_PLUGIN_CC_WORKSPACE_CWD: context.cwd,
|
|
65
65
|
[`KIMI_PLUGIN_CC_${stem}_PROMPT_B64`]: b64,
|
|
66
66
|
// A worker must reopen the exact store its parent selected, regardless of cwd.
|
|
67
|
-
KIMI_PLUGIN_CC_DATA: path.resolve(paths.
|
|
67
|
+
KIMI_PLUGIN_CC_DATA: path.resolve(paths.dataRoot),
|
|
68
68
|
},
|
|
69
69
|
});
|
|
70
70
|
let spawnReportedFailure = false;
|
|
@@ -104,10 +104,12 @@ export async function startBackgroundJob(job, prompt, context, paths, options) {
|
|
|
104
104
|
await persistBackgroundFailure(paths, job.job_id, spawnError, options.failedSummary, "spawn-failed");
|
|
105
105
|
throw spawnError;
|
|
106
106
|
}
|
|
107
|
+
const companionIdentity = child.pid !== undefined ? await serializedProcessIdentity(child.pid) : null;
|
|
107
108
|
const store = new JobStore(paths);
|
|
108
109
|
try {
|
|
109
110
|
store.updateRunningJob(job.job_id, {
|
|
110
111
|
pid: child.pid ?? null,
|
|
112
|
+
...(companionIdentity ? { companion_identity: companionIdentity } : {}),
|
|
111
113
|
phase: "worker-spawned",
|
|
112
114
|
});
|
|
113
115
|
}
|
package/dist/cli-client.js
CHANGED
|
@@ -21,7 +21,7 @@ import { parseVersionLine } from "./kimi-version-probe.js";
|
|
|
21
21
|
import { assertScopeSupported, NETWORK_ENV, READ_ROOTS_ENV, READ_SCOPE_LABELS, readScopeEnvironment, SCOPE_FLAGS_WRITE_MESSAGE, } from "./read-scope.js";
|
|
22
22
|
import { sleep } from "./util.js";
|
|
23
23
|
import { BOUNDED_SWARM_POLICY, SWARM_CHILD_TIMEOUT_MS, SWARM_POLICY_ENV, SWARM_WAVE_SIZE_ENV, usesBoundedSwarmPolicy, } from "./swarm-policy.js";
|
|
24
|
-
import { StreamJsonParser,
|
|
24
|
+
import { StreamJsonParser, } from "./stream-json.js";
|
|
25
25
|
import { collectDescendantIdentities, collectDescendantIdentitiesForRoots, raceValueWithTimeout, revalidateProcessIdentities, waitForProcessTreeExit, } from "./process-tree.js";
|
|
26
26
|
/** Bytes of stderr retained for diagnostics on completion. Rolling buffer. */
|
|
27
27
|
const STDERR_TAIL_BYTES = 8192;
|
|
@@ -59,9 +59,9 @@ export async function runCliPrompt(opts) {
|
|
|
59
59
|
if (opts.commandLabel === "rescue" || opts.commandLabel === "swarm-write") {
|
|
60
60
|
assertWorkspaceSpellable(opts.commandLabel, [opts.cwd, opts.trustedWorkspaceRoot], "cli-client.pre-spawn");
|
|
61
61
|
}
|
|
62
|
-
// The master experimental flag enables v2-only features
|
|
63
|
-
//
|
|
64
|
-
//
|
|
62
|
+
// The master experimental flag enables v2-only features outside the
|
|
63
|
+
// reviewed profile. A legacy-v1 plan refuses it at the final boundary too;
|
|
64
|
+
// native-v2 children never get it.
|
|
65
65
|
assertNoUnsafeExperimentalSelector(opts.env, "cli-client.pre-spawn", opts.executionPlan);
|
|
66
66
|
// Validate the ACTUAL prefix argv used for this spawn — not only the
|
|
67
67
|
// env-resolved value — so a forged/corrupt persisted plan cannot smuggle a
|
|
@@ -86,7 +86,7 @@ export async function runCliPrompt(opts) {
|
|
|
86
86
|
const env = buildKimiCliEnvironment(opts);
|
|
87
87
|
const boundedSwarm = usesBoundedSwarmPolicy(opts.executionPlan);
|
|
88
88
|
if (opts.logPath !== undefined) {
|
|
89
|
-
await mkdir(path.dirname(opts.logPath), { recursive: true }).catch(() => {
|
|
89
|
+
await mkdir(path.dirname(opts.logPath), { recursive: true, mode: 0o700 }).catch(() => {
|
|
90
90
|
// Best-effort; if mkdir fails the appendFile below will error and be
|
|
91
91
|
// swallowed by the log chain (diagnostics are non-blocking).
|
|
92
92
|
});
|
|
@@ -138,7 +138,7 @@ export async function runCliPrompt(opts) {
|
|
|
138
138
|
const hookMonitor = createHookEscapeMonitor({ commandLabel: opts.commandLabel,
|
|
139
139
|
operationKind: opts.executionPlan.operationKind, trustedWorkspaceRoot: opts.trustedWorkspaceRoot, cwd: opts.cwd,
|
|
140
140
|
swarmPolicy: env[SWARM_POLICY_ENV], swarmWaveSize: env[SWARM_WAVE_SIZE_ENV],
|
|
141
|
-
readRoots: env[READ_ROOTS_ENV], network: env[NETWORK_ENV] });
|
|
141
|
+
readRoots: env[READ_ROOTS_ENV], network: env[NETWORK_ENV], kimiVersion: opts.executionPlan.kimiVersion });
|
|
142
142
|
const hookEscapes = [];
|
|
143
143
|
const noteHookEscape = (escape) => {
|
|
144
144
|
hookEscapes.push(escape);
|
|
@@ -156,7 +156,7 @@ export async function runCliPrompt(opts) {
|
|
|
156
156
|
if (opts.logPath === undefined)
|
|
157
157
|
return;
|
|
158
158
|
const line = `${JSON.stringify({ ts: new Date().toISOString(), ...payload })}\n`;
|
|
159
|
-
logChain = logChain.then(() => appendFile(opts.logPath, line, "utf8").catch(() => {
|
|
159
|
+
logChain = logChain.then(() => appendFile(opts.logPath, line, { encoding: "utf8", mode: 0o600 }).catch(() => {
|
|
160
160
|
// Diagnostics best-effort; never crash on log failure.
|
|
161
161
|
}));
|
|
162
162
|
};
|
|
@@ -172,7 +172,6 @@ export async function runCliPrompt(opts) {
|
|
|
172
172
|
plan_certification: opts.executionPlan.certification,
|
|
173
173
|
safety_profile: opts.executionPlan.safetyProfile,
|
|
174
174
|
swarm_max_concurrency: opts.swarmMaxConcurrency ?? null,
|
|
175
|
-
legacy_v1_forced: env.KIMI_CODE_LEGACY_FLAG === KIMI_LEGACY_FORCED_VALUE,
|
|
176
175
|
});
|
|
177
176
|
const invokeOnRecord = (record) => {
|
|
178
177
|
if (opts.onRecord === undefined)
|
|
@@ -185,9 +184,11 @@ export async function runCliPrompt(opts) {
|
|
|
185
184
|
}
|
|
186
185
|
};
|
|
187
186
|
// A native-v2 plan must see agent-core-v2's pre-tool system.version marker
|
|
188
|
-
// before any consumer-facing output
|
|
187
|
+
// before any consumer-facing output. Generic test-bypass plans without an
|
|
188
|
+
// explicit safety profile let mock scripts omit the marker line.
|
|
189
|
+
const bypassMarkerCheck = opts.executionPlan.certification === "test-bypass" && opts.executionPlan.safetyProfile === null;
|
|
189
190
|
const requireMarkerBeforeOutput = (what) => {
|
|
190
|
-
if (plannedEngine !== "native-v2" || announcedSystemVersion !== undefined)
|
|
191
|
+
if (bypassMarkerCheck || plannedEngine !== "native-v2" || announcedSystemVersion !== undefined)
|
|
191
192
|
return false;
|
|
192
193
|
handleEngineMismatch?.({
|
|
193
194
|
observedEngine: null,
|
|
@@ -727,6 +728,55 @@ export async function runCliPrompt(opts) {
|
|
|
727
728
|
if (opts.signal?.aborted === true) {
|
|
728
729
|
onAbort();
|
|
729
730
|
}
|
|
731
|
+
// Attach stdout/stderr buffering, close capture, and stdin.end() BEFORE
|
|
732
|
+
// awaiting opts.onSpawn so a fast child cannot emit data or close while an
|
|
733
|
+
// async onSpawn (e.g., process-identity lookup) is pending. Buffer chunks
|
|
734
|
+
// until onSpawn succeeds so onSpawn still completes before any onRecord or
|
|
735
|
+
// settlement, and an onSpawn failure tears down without delivering output.
|
|
736
|
+
let streamListenersReady = false;
|
|
737
|
+
const earlyStdout = [];
|
|
738
|
+
let earlyStderrTail = "";
|
|
739
|
+
let earlyClose;
|
|
740
|
+
let earlyStreamSetupError;
|
|
741
|
+
let handleClose;
|
|
742
|
+
child.on("close", (exitCode, signal) => {
|
|
743
|
+
if (streamListenersReady && handleClose) {
|
|
744
|
+
void handleClose(exitCode, signal);
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
earlyClose = { exitCode, signal };
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
// Stdin: kimi -p reads from argv, not stdin. End it immediately so the
|
|
751
|
+
// child never blocks. Stream method calls on a failed-spawn child can
|
|
752
|
+
// throw synchronously — capture and surface after early error handling.
|
|
753
|
+
try {
|
|
754
|
+
child.stdout.setEncoding("utf8");
|
|
755
|
+
child.stderr.setEncoding("utf8");
|
|
756
|
+
child.stdout.on("data", (chunk) => {
|
|
757
|
+
if (streamListenersReady) {
|
|
758
|
+
consumeOutcomes(parser.push(chunk));
|
|
759
|
+
}
|
|
760
|
+
else {
|
|
761
|
+
earlyStdout.push(chunk);
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
child.stderr.on("data", (chunk) => {
|
|
765
|
+
if (streamListenersReady) {
|
|
766
|
+
stderrTail = appendToTail(stderrTail, chunk, STDERR_TAIL_BYTES);
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
earlyStderrTail = appendToTail(earlyStderrTail, chunk, STDERR_TAIL_BYTES);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
child.stdin.on("error", () => {
|
|
773
|
+
// Ignore EPIPE/ENOENT on stdin; child 'error' or 'close' reports the cause.
|
|
774
|
+
});
|
|
775
|
+
child.stdin.end();
|
|
776
|
+
}
|
|
777
|
+
catch (err) {
|
|
778
|
+
earlyStreamSetupError = err;
|
|
779
|
+
}
|
|
730
780
|
if (child.pid !== undefined && opts.onSpawn) {
|
|
731
781
|
try {
|
|
732
782
|
await opts.onSpawn(child.pid);
|
|
@@ -761,8 +811,13 @@ export async function runCliPrompt(opts) {
|
|
|
761
811
|
});
|
|
762
812
|
settle("reject", processError("kimi subprocess error", "cli-client.process", captured));
|
|
763
813
|
});
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
if (earlyStreamSetupError !== undefined) {
|
|
817
|
+
settle("reject", processError("kimi subprocess stream setup failed", "cli-client.streams", earlyStreamSetupError));
|
|
818
|
+
return;
|
|
764
819
|
}
|
|
765
|
-
|
|
820
|
+
handleClose = async (exitCode, signal) => {
|
|
766
821
|
consumeOutcomes(parser.flush());
|
|
767
822
|
if (!engineMismatchDetected &&
|
|
768
823
|
exitCode === 0 &&
|
|
@@ -770,12 +825,7 @@ export async function runCliPrompt(opts) {
|
|
|
770
825
|
requireMarkerBeforeOutput("a clean exit")) {
|
|
771
826
|
return;
|
|
772
827
|
}
|
|
773
|
-
|
|
774
|
-
// only for legacy-v1 plans; a native-v2 plan pins a session id from the
|
|
775
|
-
// stdout meta record alone (after the marker), so stderr can never pin
|
|
776
|
-
// an id ahead of, or different from, the provenance-checked stream.
|
|
777
|
-
const sessionId = announcedSessionId ??
|
|
778
|
-
(plannedEngine === "legacy-v1" ? extractSessionIdFromStderr(stderrTail) : undefined);
|
|
828
|
+
const sessionId = announcedSessionId;
|
|
779
829
|
appendLogLine({
|
|
780
830
|
event: "exit",
|
|
781
831
|
exit_code: exitCode,
|
|
@@ -795,15 +845,7 @@ export async function runCliPrompt(opts) {
|
|
|
795
845
|
goalSummary: announcedGoalSummary,
|
|
796
846
|
cliError: announcedCliError,
|
|
797
847
|
systemVersion: announcedSystemVersion,
|
|
798
|
-
observedEngine: announcedSystemVersion !== undefined
|
|
799
|
-
? "native-v2"
|
|
800
|
-
: plannedEngine === "legacy-v1" &&
|
|
801
|
-
(exitCode === 0 ||
|
|
802
|
-
records.length > 0 ||
|
|
803
|
-
sessionId !== undefined ||
|
|
804
|
-
announcedGoalSummary !== undefined)
|
|
805
|
-
? "legacy-v1"
|
|
806
|
-
: null,
|
|
848
|
+
observedEngine: announcedSystemVersion !== undefined ? "native-v2" : null,
|
|
807
849
|
records,
|
|
808
850
|
malformed,
|
|
809
851
|
stderrTail,
|
|
@@ -811,35 +853,20 @@ export async function runCliPrompt(opts) {
|
|
|
811
853
|
signal,
|
|
812
854
|
aborted,
|
|
813
855
|
});
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
856
|
+
};
|
|
857
|
+
streamListenersReady = true;
|
|
858
|
+
if (earlyStderrTail.length > 0) {
|
|
859
|
+
stderrTail = appendToTail(stderrTail, earlyStderrTail, STDERR_TAIL_BYTES);
|
|
860
|
+
earlyStderrTail = "";
|
|
861
|
+
}
|
|
862
|
+
if (earlyStdout.length > 0) {
|
|
863
|
+
for (const chunk of earlyStdout) {
|
|
822
864
|
consumeOutcomes(parser.push(chunk));
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
// First-announce-wins across both channels: once a session id is
|
|
826
|
-
// pinned (from the stdout meta record or an earlier stderr line),
|
|
827
|
-
// never let a later stderr line overwrite it. The stderr channel is
|
|
828
|
-
// the 0.1.x fallback and is consulted ONLY for legacy-v1 plans — on a
|
|
829
|
-
// native-v2 plan a stderr line could otherwise pin a session id before
|
|
830
|
-
// (or different from) the provenance-checked stdout stream.
|
|
831
|
-
if (plannedEngine === "legacy-v1" && announcedSessionId === undefined) {
|
|
832
|
-
const nextSessionId = extractSessionIdFromStderr(stderrTail + chunk);
|
|
833
|
-
if (nextSessionId !== undefined) {
|
|
834
|
-
announcedSessionId = nextSessionId;
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
stderrTail = appendToTail(stderrTail, chunk, STDERR_TAIL_BYTES);
|
|
838
|
-
});
|
|
839
|
-
child.stdin.end();
|
|
865
|
+
}
|
|
866
|
+
earlyStdout.length = 0;
|
|
840
867
|
}
|
|
841
|
-
|
|
842
|
-
|
|
868
|
+
if (earlyClose !== undefined && !settlementStarted) {
|
|
869
|
+
void handleClose(earlyClose.exitCode, earlyClose.signal);
|
|
843
870
|
}
|
|
844
871
|
});
|
|
845
872
|
}
|
|
@@ -972,8 +999,6 @@ function parseExactVersionToken(value) {
|
|
|
972
999
|
return undefined;
|
|
973
1000
|
return parseVersionLine(value)?.raw;
|
|
974
1001
|
}
|
|
975
|
-
const KIMI_LEGACY_ENV = "KIMI_CODE_LEGACY_FLAG";
|
|
976
|
-
const KIMI_LEGACY_FORCED_VALUE = "1";
|
|
977
1002
|
function buildArgs(opts) {
|
|
978
1003
|
const args = [...(opts.prefixArgs ?? [])];
|
|
979
1004
|
args.push("--output-format", "stream-json");
|
|
@@ -1001,8 +1026,28 @@ function buildArgs(opts) {
|
|
|
1001
1026
|
args.push("-p", opts.prompt);
|
|
1002
1027
|
return args;
|
|
1003
1028
|
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Windows environment names are case-insensitive, so `kimi_code_experimental_flag`
|
|
1031
|
+
* reaches a child exactly like the upper-case name. Re-key every KIMI_* name to
|
|
1032
|
+
* upper case, so the exact-name deletes and overrides below decide it. Where
|
|
1033
|
+
* both spellings exist the upper-case one wins, as it does in Windows itself.
|
|
1034
|
+
*/
|
|
1035
|
+
export function copyChildEnvironment(source, platform = process.platform) {
|
|
1036
|
+
const env = { ...source };
|
|
1037
|
+
if (platform !== "win32")
|
|
1038
|
+
return env;
|
|
1039
|
+
for (const key of Object.keys(env)) {
|
|
1040
|
+
const upper = key.toUpperCase();
|
|
1041
|
+
if (upper === key || !upper.startsWith("KIMI_"))
|
|
1042
|
+
continue;
|
|
1043
|
+
if (env[upper] === undefined)
|
|
1044
|
+
env[upper] = env[key];
|
|
1045
|
+
delete env[key];
|
|
1046
|
+
}
|
|
1047
|
+
return env;
|
|
1048
|
+
}
|
|
1004
1049
|
export function buildKimiCliEnvironment(opts) {
|
|
1005
|
-
const env =
|
|
1050
|
+
const env = copyChildEnvironment(opts.env);
|
|
1006
1051
|
// A previous host/job cannot opt another operation into a swarm policy or
|
|
1007
1052
|
// choose its bound. Only this immutable execution plan grants the policy.
|
|
1008
1053
|
delete env[SWARM_POLICY_ENV];
|
|
@@ -1020,22 +1065,16 @@ export function buildKimiCliEnvironment(opts) {
|
|
|
1020
1065
|
env.KIMI_MODEL_THINKING_EFFORT = opts.thinkingEffort;
|
|
1021
1066
|
// Ambient workspace trust starts project MCP stdio servers outside PreToolUse.
|
|
1022
1067
|
delete env.KIMI_CODE_TRUST_WORKSPACE;
|
|
1023
|
-
// Legacy-v1 plans use this flag on releases whose unflagged -p default can
|
|
1024
|
-
// route to native-v2. Always overwrite ambient false values; older releases
|
|
1025
|
-
// ignore it. The engine choice stays plugin-owned, while certified native-v2
|
|
1026
|
-
// plans use the no-plan construction rather than a legacy pin.
|
|
1027
|
-
if (opts.executionPlan.intendedEngine === "legacy-v1") {
|
|
1028
|
-
env[KIMI_LEGACY_ENV] = KIMI_LEGACY_FORCED_VALUE;
|
|
1029
|
-
}
|
|
1030
1068
|
// Suppress passive update checks on the `-p` path. Manually staged native
|
|
1031
1069
|
// swaps remain an upstream exception, so the exact probe and first-line
|
|
1032
1070
|
// version marker must still prove the spawned artifact's identity.
|
|
1033
1071
|
env.KIMI_CODE_NO_AUTO_UPDATE = "1";
|
|
1034
1072
|
// Plugin-owned web lifecycles must not inherit ambient idle-session reclamation.
|
|
1035
1073
|
env.KIMI_CODE_SESSION_IDLE_RECLAIM_MS = "0";
|
|
1036
|
-
//
|
|
1037
|
-
// [experimental] config and the master flag upstream
|
|
1038
|
-
// "0" parses as false there, so these force both off
|
|
1074
|
+
// Plugin tasks run without tower and subagent fork. A per-flag env value
|
|
1075
|
+
// outranks [experimental] config and the master flag upstream
|
|
1076
|
+
// (0.42.0-2.8.0), and "0" parses as false there, so these force both off
|
|
1077
|
+
// for print and web. 2.8.0 removed subagent fork and ignores its variable.
|
|
1039
1078
|
env.KIMI_CODE_EXPERIMENTAL_TOWER = "0";
|
|
1040
1079
|
env.KIMI_CODE_EXPERIMENTAL_SUBAGENT_FORK = "0";
|
|
1041
1080
|
// The master flag is read only from the child's own environment, so a
|
package/dist/commands/ask.js
CHANGED
|
@@ -7,7 +7,7 @@ import { assertPersistedResumeLineage, executionPlanFromPersisted, observedExecu
|
|
|
7
7
|
import { getManagedCommandConfig } from "./registry.js";
|
|
8
8
|
import { RuntimeError } from "../errors.js";
|
|
9
9
|
import { resolveRepoIdentity } from "../git.js";
|
|
10
|
-
import { digestPrompt, markJobCancelled, markJobFailed, sweepStaleJobs } from "../jobs.js";
|
|
10
|
+
import { digestPrompt, markJobCancelled, markJobFailed, recordKimiSpawnIdentity, serializedProcessIdentity, sweepStaleJobs, } from "../jobs.js";
|
|
11
11
|
import { JobStore } from "../job-store.js";
|
|
12
12
|
import { KIMI_ASK_PROMPT_TIMEOUT_MS } from "../kimi-timeouts.js";
|
|
13
13
|
import { writeInvocationLogHeader } from "../logging.js";
|
|
@@ -19,6 +19,7 @@ import { classifyManagedCommandFailure } from "../kimi-errors.js";
|
|
|
19
19
|
import { startBackgroundJob } from "../background-spawn.js";
|
|
20
20
|
import { warnInheritedBudget, captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes, resolveResumeSession, assertNetworkResumeConfined, resumeBudget, hookRefusal } from "./cli-helpers.js";
|
|
21
21
|
import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
|
|
22
|
+
import { appendSessionReferences, resolveSessionReferences, stripSessionReferences, withReferenceReadRoots } from "../session-references.js";
|
|
22
23
|
import { shorten } from "../util.js";
|
|
23
24
|
const ASK_SUMMARY_MAX = 120;
|
|
24
25
|
const ASK_AGENT_PROFILE_PLACEHOLDER = "<cli-client>";
|
|
@@ -47,7 +48,7 @@ export async function runAsk(argv, context) {
|
|
|
47
48
|
if (parsed.help)
|
|
48
49
|
return companionHelp(["ask", ...argv]);
|
|
49
50
|
// Scope always comes from this invocation, never from a resumed job.
|
|
50
|
-
const
|
|
51
|
+
const callerScope = parsed.readRoots === undefined && parsed.network === undefined ? undefined
|
|
51
52
|
: await resolveReadScope(parsed.readRoots, parsed.network, "ask.parse");
|
|
52
53
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
|
|
53
54
|
await requireAskHookInstalled(context);
|
|
@@ -61,10 +62,7 @@ export async function runAsk(argv, context) {
|
|
|
61
62
|
await sweepStaleJobs(store, paths);
|
|
62
63
|
const jobId = allocateJobId(context);
|
|
63
64
|
const sessionResolution = await resolveResumeSession(store, "ask", repoIdentity.repoId, parsed);
|
|
64
|
-
|
|
65
|
-
assertNetworkResumeConfined(store, "ask", sessionResolution, effectiveReadRoots(readScope, context.cwd));
|
|
66
|
-
}
|
|
67
|
-
const askPrompt = buildAskPrompt(parsed.prompt, sessionResolution.reusedSession);
|
|
65
|
+
const basePrompt = buildAskPrompt(parsed.prompt, sessionResolution.reusedSession);
|
|
68
66
|
const executionPlan = await prepareKimiExecutionPlan({
|
|
69
67
|
operationKind: "ask",
|
|
70
68
|
cwd: context.cwd,
|
|
@@ -74,7 +72,17 @@ export async function runAsk(argv, context) {
|
|
|
74
72
|
resumeSessionId: sessionResolution.kimiSessionId ?? undefined,
|
|
75
73
|
resumeSource: sessionResolution.sourceJob,
|
|
76
74
|
});
|
|
77
|
-
assertScopeSupported(
|
|
75
|
+
assertScopeSupported(callerScope, executionPlan.certification, "INVALID_ARGS", "ask.parse");
|
|
76
|
+
const references = await resolveSessionReferences(parsed.referenceSessions, {
|
|
77
|
+
store, env: context.env, spawnCwd: context.cwd, plan: executionPlan,
|
|
78
|
+
resumeSessionId: sessionResolution.kimiSessionId, stage: "ask.reference-session",
|
|
79
|
+
});
|
|
80
|
+
// A named session is a root this call grants, so the resume rule judges the widened roots.
|
|
81
|
+
const readScope = withReferenceReadRoots(callerScope, references);
|
|
82
|
+
if (readScope?.network === true) {
|
|
83
|
+
assertNetworkResumeConfined(store, "ask", sessionResolution, effectiveReadRoots(readScope, context.cwd));
|
|
84
|
+
}
|
|
85
|
+
const askPrompt = appendSessionReferences(basePrompt, references);
|
|
78
86
|
const logPath = path.join(paths.logsDir, `ask-${jobId}.jsonl`);
|
|
79
87
|
const job = store.createJob({
|
|
80
88
|
job_id: jobId,
|
|
@@ -89,6 +97,7 @@ export async function runAsk(argv, context) {
|
|
|
89
97
|
...resumeBudget("ask", parsed.budgetMs, sessionResolution.sourceJob),
|
|
90
98
|
pid: parsed.background ? null : process.pid,
|
|
91
99
|
kimi_pid: null,
|
|
100
|
+
companion_identity: parsed.background ? null : await serializedProcessIdentity(process.pid),
|
|
92
101
|
status: "running",
|
|
93
102
|
kimi_session_id: sessionResolution.kimiSessionId,
|
|
94
103
|
kimi_session_id_source: sessionResolution.sourceJob?.kimi_session_id_source ?? null,
|
|
@@ -161,7 +170,12 @@ export async function executeAskJob(jobId, prompt, context, options) {
|
|
|
161
170
|
await assertPersistedResumeLineage(store, executionPlan, job.kimi_session_id, "ask");
|
|
162
171
|
}
|
|
163
172
|
if (options?.workerPid) {
|
|
164
|
-
|
|
173
|
+
const workerIdentity = await serializedProcessIdentity(options.workerPid);
|
|
174
|
+
store.updateRunningJob(job.job_id, {
|
|
175
|
+
pid: options.workerPid,
|
|
176
|
+
...(workerIdentity ? { companion_identity: workerIdentity } : {}),
|
|
177
|
+
phase: "worker-running",
|
|
178
|
+
});
|
|
165
179
|
}
|
|
166
180
|
const result = await runCliPromptWithBudget({
|
|
167
181
|
cwd: job.cwd,
|
|
@@ -176,7 +190,7 @@ export async function executeAskJob(jobId, prompt, context, options) {
|
|
|
176
190
|
readScope,
|
|
177
191
|
resumeSessionId: job.kimi_session_id ?? undefined,
|
|
178
192
|
logPath: job.stream_log_path,
|
|
179
|
-
onSpawn: (pid) => { store
|
|
193
|
+
onSpawn: async (pid) => { await recordKimiSpawnIdentity(store, job.job_id, pid); },
|
|
180
194
|
signal: handlers.signal,
|
|
181
195
|
}, job.budget_ms ?? KIMI_ASK_PROMPT_TIMEOUT_MS, "ask.prompt");
|
|
182
196
|
store.updateRunningJob(job.job_id, observedExecutionFields(result));
|
|
@@ -263,7 +277,8 @@ function buildAskPrompt(question, reusedSession) {
|
|
|
263
277
|
throw new RuntimeError("INVALID_ARGS", "ask requires a question after the flags.", "ask.parse");
|
|
264
278
|
}
|
|
265
279
|
export function askPromptSubject(prompt) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
280
|
+
const body = stripSessionReferences(prompt);
|
|
281
|
+
if (body.startsWith(ASK_PROMPT_PREFIX))
|
|
282
|
+
return body.slice(ASK_PROMPT_PREFIX.length);
|
|
283
|
+
return body === ASK_RESUME_PROMPT ? ASK_CONTINUE_TASK : body;
|
|
269
284
|
}
|
package/dist/commands/cancel.js
CHANGED
|
@@ -5,7 +5,6 @@ import { JobStore, withJobStore } from "../job-store.js";
|
|
|
5
5
|
import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
|
|
6
6
|
import { parseJobLookupArgs } from "../parsing.js";
|
|
7
7
|
import { revalidateProcessIdentities } from "../process-tree.js";
|
|
8
|
-
import { getManagedCommandConfig } from "./registry.js";
|
|
9
8
|
import { sleep } from "../util.js";
|
|
10
9
|
export async function runCancel(argv, context) {
|
|
11
10
|
const parsed = parseJobLookupArgs(argv);
|
|
@@ -14,7 +13,8 @@ export async function runCancel(argv, context) {
|
|
|
14
13
|
const repoIdentity = await resolveRepoIdentity(context.cwd);
|
|
15
14
|
const store = new JobStore(paths);
|
|
16
15
|
try {
|
|
17
|
-
|
|
16
|
+
const isMcpCancel = context.mcpCompanionIdentity !== undefined || context.mcpKimiIdentity !== undefined;
|
|
17
|
+
await sweepStaleJobs(store, paths, isMcpCancel ? { repoId: repoIdentity.repoId, workspaceCwd: context.cwd } : undefined);
|
|
18
18
|
const job = parsed.jobId
|
|
19
19
|
? store.getJob(parsed.jobId)
|
|
20
20
|
: store.findLatestJob({
|
|
@@ -34,7 +34,7 @@ export async function runCancel(argv, context) {
|
|
|
34
34
|
}
|
|
35
35
|
if (store.getMcpTask(job.job_id) &&
|
|
36
36
|
(context.mcpCompanionIdentity === undefined || context.mcpKimiIdentity === undefined)) {
|
|
37
|
-
throw new RuntimeError("MCP_CANCEL_REQUIRES_BINDING", `MCP job ${job.job_id} requires MCP job-control cancellation with recorded identities; use tasks/cancel or
|
|
37
|
+
throw new RuntimeError("MCP_CANCEL_REQUIRES_BINDING", `MCP job ${job.job_id} requires MCP job-control cancellation with recorded identities; use tasks/cancel or kimi_job (action: "cancel").`, "mcp.cancel");
|
|
38
38
|
}
|
|
39
39
|
const recovery = store.getSwarmRecovery(job.job_id)?.record;
|
|
40
40
|
if (recovery) {
|
|
@@ -47,20 +47,11 @@ export async function runCancel(argv, context) {
|
|
|
47
47
|
if (job.pid === null && job.kimi_pid === null) {
|
|
48
48
|
throw new RuntimeError("CANCEL_NOT_SUPPORTED", `Job ${job.job_id} does not have a recorded process id to cancel.`, "cancel.runtime");
|
|
49
49
|
}
|
|
50
|
-
// review_gate runs in a Stop hook. Pre-mark the row as cancelled before
|
|
51
|
-
// signaling so the subprocess close/result path cannot persist a failure
|
|
52
|
-
// over the user's intent; later updates are no-ops on a terminal row.
|
|
53
|
-
//
|
|
54
|
-
// The terminal row also makes waitForCancellation return before its own
|
|
55
|
-
// escalation, so this path always attempts SIGTERM after the pre-mark
|
|
56
|
-
// attempt, waits 1s, and sends SIGKILL only if a recorded process remains
|
|
57
|
-
// live. A pre-mark failure is rethrown only after termination is attempted.
|
|
58
50
|
if (job.command_type === "review_gate") {
|
|
59
51
|
let preMarkError;
|
|
60
52
|
try {
|
|
61
53
|
await withJobStore(paths, async (preMarkStore) => {
|
|
62
|
-
|
|
63
|
-
await markJobCancelled(preMarkStore, paths, job, reviewGateCancel.cancelledSummary, new RuntimeError(reviewGateCancel.errorCodes.cancelled, reviewGateCancel.cancelMessages.default, "cancel.runtime"));
|
|
54
|
+
await markJobCancelled(preMarkStore, paths, job, "review_gate cancelled by user request.", new RuntimeError("REVIEW_GATE_CANCELLED", "review_gate cancelled by user request.", "cancel.runtime"));
|
|
64
55
|
});
|
|
65
56
|
}
|
|
66
57
|
catch (error) {
|
|
@@ -277,7 +277,7 @@ export function assertNetworkResumeConfined(store, kind, resolution, currentRoot
|
|
|
277
277
|
jobId = job?.resumed_from_job_id;
|
|
278
278
|
}
|
|
279
279
|
if (!confined) {
|
|
280
|
-
throw new RuntimeError("INVALID_ARGS", `${kind} --network cannot resume session ${sessionId ?? "<unknown>"}: an earlier turn in it ran without confined reads, or could read outside this call's workspace
|
|
280
|
+
throw new RuntimeError("INVALID_ARGS", `${kind} --network cannot resume session ${sessionId ?? "<unknown>"}: an earlier turn in it ran without confined reads, or could read outside this call's workspace, --read-root directories and referenced sessions (or its history is not recorded), so those reads could be sent out. ` +
|
|
281
281
|
`Start a fresh session instead: ${kind} --fresh --network [--read-root <dir>] <prompt>.`, `${kind}.resume`);
|
|
282
282
|
}
|
|
283
283
|
}
|
package/dist/commands/pursue.js
CHANGED
|
@@ -5,7 +5,7 @@ import { runCliPromptWithBudget } from "../cli-client.js";
|
|
|
5
5
|
import { executionPlanFromPersisted, observedExecutionFields, persistedExecutionPlanFields, prepareKimiExecutionPlan, } from "../kimi-engine.js";
|
|
6
6
|
import { RuntimeError } from "../errors.js";
|
|
7
7
|
import { resolveRepoIdentity } from "../git.js";
|
|
8
|
-
import { digestPrompt, markJobCancelled, markJobFailed, sweepStaleJobs } from "../jobs.js";
|
|
8
|
+
import { digestPrompt, markJobCancelled, markJobFailed, recordKimiSpawnIdentity, serializedProcessIdentity, sweepStaleJobs, } from "../jobs.js";
|
|
9
9
|
import { JobStore } from "../job-store.js";
|
|
10
10
|
import { classifyManagedCommandFailure } from "../kimi-errors.js";
|
|
11
11
|
import { KIMI_PURSUE_DEFAULT_BUDGET_MS } from "../kimi-timeouts.js";
|
|
@@ -139,6 +139,7 @@ export async function runPursue(argv, context) {
|
|
|
139
139
|
budget_source: parsed.budgetMs !== undefined ? "explicit" : "default",
|
|
140
140
|
pid: process.pid,
|
|
141
141
|
kimi_pid: null,
|
|
142
|
+
companion_identity: await serializedProcessIdentity(process.pid),
|
|
142
143
|
status: "running",
|
|
143
144
|
kimi_session_id: null,
|
|
144
145
|
...persistedExecutionPlanFields(executionPlan),
|
|
@@ -219,7 +220,7 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
|
|
|
219
220
|
model: job.model ?? undefined,
|
|
220
221
|
thinkingEffort: job.thinking_effort ?? undefined,
|
|
221
222
|
logPath: job.stream_log_path,
|
|
222
|
-
onSpawn: (pid) => { store
|
|
223
|
+
onSpawn: async (pid) => { await recordKimiSpawnIdentity(store, job.job_id, pid); },
|
|
223
224
|
signal: handlers.signal,
|
|
224
225
|
}, budgetMs, "pursue.prompt");
|
|
225
226
|
store.updateRunningJob(job.job_id, observedExecutionFields(result));
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { RuntimeError } from "../errors.js";
|
|
2
2
|
const passthroughOutput = "passthrough";
|
|
3
|
-
const parsedOutput = "parsed";
|
|
4
3
|
const DEFAULT_ESCALATION_MS = 1_500;
|
|
5
|
-
/**
|
|
6
|
-
* Build cancellation config from the display name used verbatim in messages
|
|
7
|
-
* and the uppercase stem used in error codes.
|
|
8
|
-
*/
|
|
9
4
|
function makeCancellationConfig(prefix) {
|
|
10
5
|
const { displayName, errorCodeStem } = prefix;
|
|
11
6
|
return {
|
|
@@ -24,13 +19,6 @@ function makeCancellationConfig(prefix) {
|
|
|
24
19
|
failedSummary: `${displayName} failed.`,
|
|
25
20
|
};
|
|
26
21
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Single source of truth for per-command behavior. Only commands using the
|
|
29
|
-
* managed-cancellation flow participate; `setup` and `task` do not.
|
|
30
|
-
*
|
|
31
|
-
* Display-name casing is part of the user-visible contract: `Ask` and `Rescue`
|
|
32
|
-
* are title-cased, while `review`, `challenge`, and `review_gate` are lowercase.
|
|
33
|
-
*/
|
|
34
22
|
export const COMMAND_REGISTRY = {
|
|
35
23
|
ask: {
|
|
36
24
|
outputMode: passthroughOutput,
|
|
@@ -48,22 +36,15 @@ export const COMMAND_REGISTRY = {
|
|
|
48
36
|
outputMode: passthroughOutput,
|
|
49
37
|
cancellation: makeCancellationConfig({ displayName: "Rescue", errorCodeStem: "RESCUE" }),
|
|
50
38
|
},
|
|
51
|
-
review_gate: {
|
|
52
|
-
outputMode: parsedOutput,
|
|
53
|
-
cancellation: makeCancellationConfig({ displayName: "review_gate", errorCodeStem: "REVIEW_GATE" }),
|
|
54
|
-
},
|
|
55
39
|
};
|
|
56
40
|
/**
|
|
57
|
-
* Convenience accessor for managed commands (review/challenge/rescue
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* destructure call site. Throwing a classified `RuntimeError` here
|
|
65
|
-
* keeps the failure path within the command-layer error model so
|
|
66
|
-
* /kimi:status and /kimi:result render it correctly.
|
|
41
|
+
* Convenience accessor for managed commands (ask/review/challenge/rescue).
|
|
42
|
+
* Identical to direct lookup, with a defensive runtime guard: TypeScript
|
|
43
|
+
* narrows `commandType` to `ManagedCommandType`, but a stale SQLite row,
|
|
44
|
+
* corrupted job artifact, or future command type added without a registry
|
|
45
|
+
* entry could still reach here at runtime. Throwing a classified `RuntimeError`
|
|
46
|
+
* keeps the failure path within the command-layer error model so `job status`
|
|
47
|
+
* and `job result` render it correctly.
|
|
67
48
|
*/
|
|
68
49
|
export function getManagedCommandConfig(commandType) {
|
|
69
50
|
const config = COMMAND_REGISTRY[commandType];
|
|
@@ -8,6 +8,7 @@ import { resolveRepoIdentity } from "../git.js";
|
|
|
8
8
|
import { digestPrompt } from "../jobs.js";
|
|
9
9
|
import { resolvePluginPaths } from "../paths.js";
|
|
10
10
|
import { syncKimiSessionTitle } from "../session-title.js";
|
|
11
|
+
import { stripSessionReferences } from "../session-references.js";
|
|
11
12
|
import { askPromptSubject } from "./ask.js";
|
|
12
13
|
import { buildGoalPrompt } from "./pursue.js";
|
|
13
14
|
import { stripRescuePromptPrefix } from "./rescue.js";
|
|
@@ -185,7 +186,8 @@ const TASK_SLOT = "\u0000kimi-plugin-cc-task\u0000";
|
|
|
185
186
|
/**
|
|
186
187
|
* Recover the raw task text a live run previews from its verified submitted
|
|
187
188
|
* prompt. Derivations are exact or absent: prompts from other plugin releases,
|
|
188
|
-
* ambiguous parameter choices and unknown operations return undefined.
|
|
189
|
+
* ambiguous parameter choices and unknown operations return undefined. A
|
|
190
|
+
* trailing referenced-sessions block is not task text; pursue never carries one.
|
|
189
191
|
*/
|
|
190
192
|
export function rawTaskTextFromSubmittedPrompt(operationKind, prompt) {
|
|
191
193
|
switch (operationKind) {
|
|
@@ -201,17 +203,18 @@ export function rawTaskTextFromSubmittedPrompt(operationKind, prompt) {
|
|
|
201
203
|
const build = operationKind === "swarm" ? buildSwarmPrompt : buildSwarmWritePrompt;
|
|
202
204
|
const caps = [undefined, ...numbersAfter(prompt, /at most (\d+) subagents/g)];
|
|
203
205
|
const waves = [undefined, 1, ...numbersAfter(prompt, /at most (\d+) entries/g)];
|
|
204
|
-
return uniqueInversion(prompt, caps.flatMap((cap) => waves.map((wave) => (task) => build(task, cap, wave))));
|
|
206
|
+
return uniqueInversion(stripSessionReferences(prompt), caps.flatMap((cap) => waves.map((wave) => (task) => build(task, cap, wave))));
|
|
205
207
|
}
|
|
206
208
|
case "review":
|
|
207
209
|
case "challenge":
|
|
208
|
-
return reviewTaskText(prompt);
|
|
210
|
+
return reviewTaskText(stripSessionReferences(prompt));
|
|
209
211
|
default:
|
|
210
212
|
return undefined;
|
|
211
213
|
}
|
|
212
214
|
}
|
|
215
|
+
/** The plugin prefix must have been removed, not merely a referenced-sessions block. */
|
|
213
216
|
function strippedOrUndefined(prompt, stripped) {
|
|
214
|
-
return stripped !== prompt && stripped.trim() ? stripped : undefined;
|
|
217
|
+
return stripped !== stripSessionReferences(prompt) && stripped.trim() ? stripped : undefined;
|
|
215
218
|
}
|
|
216
219
|
function numbersAfter(prompt, pattern) {
|
|
217
220
|
return [...new Set([...prompt.matchAll(pattern)].map((match) => Number(match[1])))];
|