kimi-plugin-cc 2.7.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +3 -16
- package/README.md +428 -515
- package/assets/logo.svg +6 -0
- package/cordis.patch.yml +18 -0
- package/dist/background-spawn.js +14 -19
- package/dist/cli-client.js +163 -105
- package/dist/commands/ask.js +44 -96
- package/dist/commands/cancel.js +11 -59
- package/dist/commands/cli-helpers.js +102 -1
- package/dist/commands/models.js +2 -3
- package/dist/commands/pursue.js +8 -21
- package/dist/commands/registry.js +7 -26
- package/dist/commands/repair-sessions.js +121 -12
- package/dist/commands/replay.js +4 -3
- package/dist/commands/rescue.js +29 -87
- package/dist/commands/result.js +7 -1
- package/dist/commands/review.js +28 -18
- package/dist/commands/setup.js +813 -462
- package/dist/commands/status.js +2 -2
- package/dist/commands/swarm.js +112 -125
- package/dist/commands/worker.js +1 -2
- package/dist/companion.js +145 -19
- package/dist/git.js +1 -9
- package/dist/help.js +13 -9
- package/dist/hook-escape.js +7 -16
- package/dist/hooks/approval-hook.js +1766 -87
- package/dist/hooks/approval-policy.js +86 -19
- package/dist/hooks/config-safety.js +31 -64
- package/dist/hooks/hook-timing.js +48 -0
- package/dist/hooks/install-paths.js +179 -107
- package/dist/hooks/install.js +126 -53
- package/dist/hooks/managed-block.js +121 -127
- package/dist/job-store.js +206 -166
- package/dist/jobs.js +66 -19
- package/dist/kimi-command.js +74 -1
- package/dist/kimi-engine.js +198 -127
- package/dist/kimi-errors.js +15 -70
- package/dist/kimi-home.js +6 -0
- package/dist/kimi-journal.js +42 -0
- package/dist/kimi-releases.js +123 -0
- package/dist/kimi-timeouts.js +2 -16
- package/dist/kimi-version-probe.js +24 -108
- package/dist/logging.js +12 -7
- package/dist/mcp/binding.js +13 -4
- package/dist/mcp/job-control.js +390 -95
- package/dist/mcp/launcher.js +13 -7
- package/dist/mcp/operations.js +405 -179
- package/dist/mcp/protocol.js +124 -33
- package/dist/mcp/skills.js +130 -0
- package/dist/mcp/stdio.js +18 -4
- package/dist/model-command.js +5 -3
- package/dist/native-v2-preflight.js +243 -80
- package/dist/parsing.js +211 -243
- package/dist/paths.js +28 -10
- package/dist/plugin-data.js +28 -83
- package/dist/process-tree.js +35 -24
- package/dist/read-scope.js +435 -0
- package/dist/render.js +58 -46
- package/dist/rescue-approval.js +461 -84
- package/dist/session-references.js +216 -0
- package/dist/session-title.js +26 -6
- package/dist/stream-json.js +1 -3
- package/dist/surface-routing.js +108 -0
- package/dist/swarm-activation.js +74 -188
- package/dist/swarm-policy.js +2 -1
- package/dist/swarm-recovery.js +2 -1
- package/dist/util.js +28 -0
- package/dist/version.js +1 -1
- package/docs/migration.md +45 -206
- package/docs/models.md +24 -66
- package/docs/safety.md +198 -353
- package/docs/session-visibility.md +25 -13
- package/docs/swarm-recovery.md +26 -20
- package/dsh/index.json +54 -0
- package/mcp_config.json +10 -0
- package/package.json +23 -82
- package/plugin.json +19 -0
- package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
- package/plugins/kimi-codex/.mcp.json +3 -3
- package/plugins/kimi-codex/dist/background-spawn.js +14 -19
- package/plugins/kimi-codex/dist/cli-client.js +163 -105
- package/plugins/kimi-codex/dist/commands/ask.js +44 -96
- package/plugins/kimi-codex/dist/commands/cancel.js +11 -59
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
- package/plugins/kimi-codex/dist/commands/models.js +2 -3
- package/plugins/kimi-codex/dist/commands/pursue.js +8 -21
- package/plugins/kimi-codex/dist/commands/registry.js +7 -26
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +121 -12
- package/plugins/kimi-codex/dist/commands/replay.js +4 -3
- package/plugins/kimi-codex/dist/commands/rescue.js +29 -87
- package/plugins/kimi-codex/dist/commands/result.js +7 -1
- package/plugins/kimi-codex/dist/commands/review.js +28 -18
- package/plugins/kimi-codex/dist/commands/setup.js +813 -462
- package/plugins/kimi-codex/dist/commands/status.js +2 -2
- package/plugins/kimi-codex/dist/commands/swarm.js +112 -125
- package/plugins/kimi-codex/dist/commands/worker.js +1 -2
- package/plugins/kimi-codex/dist/companion.js +145 -19
- package/plugins/kimi-codex/dist/git.js +1 -9
- package/plugins/kimi-codex/dist/help.js +13 -9
- package/plugins/kimi-codex/dist/hook-escape.js +7 -16
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +1766 -87
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +86 -19
- package/plugins/kimi-codex/dist/hooks/config-safety.js +31 -64
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
- package/plugins/kimi-codex/dist/hooks/install.js +126 -53
- package/plugins/kimi-codex/dist/hooks/managed-block.js +121 -127
- package/plugins/kimi-codex/dist/job-store.js +206 -166
- package/plugins/kimi-codex/dist/jobs.js +66 -19
- package/plugins/kimi-codex/dist/kimi-command.js +74 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +198 -127
- package/plugins/kimi-codex/dist/kimi-errors.js +15 -70
- package/plugins/kimi-codex/dist/kimi-home.js +6 -0
- package/plugins/kimi-codex/dist/kimi-journal.js +42 -0
- package/plugins/kimi-codex/dist/kimi-releases.js +123 -0
- package/plugins/kimi-codex/dist/kimi-timeouts.js +2 -16
- package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -108
- package/plugins/kimi-codex/dist/logging.js +12 -7
- package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
- package/plugins/kimi-codex/dist/mcp/job-control.js +390 -95
- package/plugins/kimi-codex/dist/mcp/launcher.js +13 -7
- package/plugins/kimi-codex/dist/mcp/operations.js +405 -179
- package/plugins/kimi-codex/dist/mcp/protocol.js +124 -33
- package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
- package/plugins/kimi-codex/dist/mcp/stdio.js +18 -4
- package/plugins/kimi-codex/dist/model-command.js +5 -3
- package/plugins/kimi-codex/dist/native-v2-preflight.js +243 -80
- package/plugins/kimi-codex/dist/parsing.js +211 -243
- package/plugins/kimi-codex/dist/paths.js +28 -10
- package/plugins/kimi-codex/dist/plugin-data.js +28 -83
- package/plugins/kimi-codex/dist/process-tree.js +35 -24
- package/plugins/kimi-codex/dist/read-scope.js +435 -0
- package/plugins/kimi-codex/dist/render.js +58 -46
- package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
- package/plugins/kimi-codex/dist/session-references.js +216 -0
- package/plugins/kimi-codex/dist/session-title.js +26 -6
- package/plugins/kimi-codex/dist/stream-json.js +1 -3
- package/plugins/kimi-codex/dist/surface-routing.js +108 -0
- package/plugins/kimi-codex/dist/swarm-activation.js +74 -188
- package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
- package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
- package/plugins/kimi-codex/dist/util.js +28 -0
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/scripts/companion.sh +4 -15
- package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
- package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
- package/scripts/companion.sh +4 -15
- package/skills/kimi/SKILL.md +77 -0
- package/skills/kimi/agents/openai.yaml +6 -0
- package/CHANGELOG.md +0 -1333
- package/agents/kimi-ask.md +0 -89
- package/agents/kimi-challenge.md +0 -86
- package/agents/kimi-pursue.md +0 -93
- package/agents/kimi-rescue.md +0 -92
- package/agents/kimi-review.md +0 -86
- package/agents/kimi-swarm-write.md +0 -96
- package/agents/kimi-swarm.md +0 -86
- package/commands/README.md +0 -16
- package/commands/ask.md +0 -38
- package/commands/cancel.md +0 -17
- package/commands/challenge.md +0 -35
- package/commands/pursue.md +0 -41
- package/commands/replay.md +0 -13
- package/commands/rescue.md +0 -38
- package/commands/result.md +0 -13
- package/commands/review.md +0 -35
- package/commands/setup.md +0 -23
- package/commands/status.md +0 -13
- package/commands/swarm.md +0 -44
- package/dist/commands/not-implemented.js +0 -4
- package/dist/commands/review-gate.js +0 -390
- package/dist/config.js +0 -22
- package/dist/dsh/companion.js +0 -177
- package/dist/dsh/index.js +0 -169
- package/dist/hooks/review-gate-stop.js +0 -19
- package/dist/schemas/review-gate-output.js +0 -43
- package/docs/registry-releases.md +0 -228
- package/docs/upstream-2.4.1-certification.md +0 -54
- package/docs/upstream-2.5.0-certification.md +0 -52
- package/docs/upstream-2.5.1-certification.md +0 -47
- package/docs/upstream-2.5.2-certification.md +0 -40
- package/docs/upstream-2.5.3-certification.md +0 -73
- package/docs/upstream-2.6.0-certification.md +0 -65
- package/docs/upstream-2.6.2-certification.md +0 -144
- package/docs/upstream-2.6.3-certification.md +0 -100
- package/docs/upstream-2.7.2-certification.md +0 -113
- package/docs/upstream-2.7.3-certification.md +0 -83
- package/docs/windows-validation.md +0 -39
- package/hooks/README.md +0 -9
- package/hooks/hooks.json +0 -16
- package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-codex/dist/commands/review-gate.js +0 -390
- package/plugins/kimi-codex/dist/config.js +0 -22
- package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
- package/plugins/kimi-codex/dist/dsh/index.js +0 -169
- package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -43
- package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
- package/plugins/kimi-codex/skills/kimi-ask/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
- package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
- package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/LICENSE +0 -201
- package/plugins/kimi-dsh/README.md +0 -83
- package/plugins/kimi-dsh/cordis.patch.yml +0 -45
- package/plugins/kimi-dsh/dist/background-spawn.js +0 -216
- package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
- package/plugins/kimi-dsh/dist/cli-client.js +0 -1078
- package/plugins/kimi-dsh/dist/commands/ask.js +0 -336
- package/plugins/kimi-dsh/dist/commands/cancel.js +0 -216
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -201
- package/plugins/kimi-dsh/dist/commands/models.js +0 -140
- package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-dsh/dist/commands/pursue.js +0 -307
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
- package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -160
- package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
- package/plugins/kimi-dsh/dist/commands/rescue.js +0 -347
- package/plugins/kimi-dsh/dist/commands/result.js +0 -66
- package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -390
- package/plugins/kimi-dsh/dist/commands/review.js +0 -220
- package/plugins/kimi-dsh/dist/commands/setup.js +0 -1129
- package/plugins/kimi-dsh/dist/commands/status.js +0 -27
- package/plugins/kimi-dsh/dist/commands/swarm.js +0 -849
- package/plugins/kimi-dsh/dist/commands/worker.js +0 -25
- package/plugins/kimi-dsh/dist/companion.js +0 -97
- package/plugins/kimi-dsh/dist/config.js +0 -22
- package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
- package/plugins/kimi-dsh/dist/dsh/index.js +0 -169
- package/plugins/kimi-dsh/dist/errors.js +0 -40
- package/plugins/kimi-dsh/dist/git.js +0 -224
- package/plugins/kimi-dsh/dist/help.js +0 -43
- package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -104
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -233
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -665
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
- package/plugins/kimi-dsh/dist/hooks/install.js +0 -210
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -684
- package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-dsh/dist/job-id.js +0 -12
- package/plugins/kimi-dsh/dist/job-store.js +0 -659
- package/plugins/kimi-dsh/dist/jobs.js +0 -217
- package/plugins/kimi-dsh/dist/kimi-command.js +0 -71
- package/plugins/kimi-dsh/dist/kimi-engine.js +0 -675
- package/plugins/kimi-dsh/dist/kimi-errors.js +0 -260
- package/plugins/kimi-dsh/dist/kimi-home.js +0 -9
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -234
- package/plugins/kimi-dsh/dist/logging.js +0 -22
- package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
- package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -345
- package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -257
- package/plugins/kimi-dsh/dist/mcp/operations.js +0 -301
- package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -275
- package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
- package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -78
- package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
- package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
- package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
- package/plugins/kimi-dsh/dist/model-command.js +0 -32
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -525
- package/plugins/kimi-dsh/dist/package.json +0 -1
- package/plugins/kimi-dsh/dist/parsing.js +0 -620
- package/plugins/kimi-dsh/dist/paths.js +0 -27
- package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
- package/plugins/kimi-dsh/dist/process-tree.js +0 -586
- package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
- package/plugins/kimi-dsh/dist/render.js +0 -177
- package/plugins/kimi-dsh/dist/rescue-approval.js +0 -865
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -43
- package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
- package/plugins/kimi-dsh/dist/session-title.js +0 -293
- package/plugins/kimi-dsh/dist/stream-json.js +0 -346
- package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1197
- package/plugins/kimi-dsh/dist/swarm-policy.js +0 -73
- package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -165
- package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
- package/plugins/kimi-dsh/dist/types.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
- package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
- package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
- package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
- package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
- package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
- package/plugins/kimi-dsh/dist/version.js +0 -7
- package/plugins/kimi-dsh/package.json +0 -78
- package/plugins/kimi-dsh/scripts/companion.sh +0 -37
- package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
- package/scripts/review-gate-hook.sh +0 -32
package/dist/commands/ask.js
CHANGED
|
@@ -3,22 +3,24 @@ import { allocateJobId } from "../job-id.js";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { createCliCancellationHandlers } from "../cli-cancellation.js";
|
|
5
5
|
import { runCliPromptWithBudget } from "../cli-client.js";
|
|
6
|
-
import { assertPersistedResumeLineage, executionPlanFromPersisted, observedExecutionFields, persistedExecutionPlanFields, prepareKimiExecutionPlan,
|
|
6
|
+
import { assertPersistedResumeLineage, executionPlanFromPersisted, observedExecutionFields, persistedExecutionPlanFields, prepareKimiExecutionPlan, } from "../kimi-engine.js";
|
|
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";
|
|
14
14
|
import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
|
|
15
15
|
import { parseAskArgs } from "../parsing.js";
|
|
16
|
+
import { assertScopeSupported, effectiveReadRoots, parseJobReadScope, resolveReadScope, serializeReadScope } from "../read-scope.js";
|
|
16
17
|
import { readArtifact, renderManagedJobOutput, writeArtifact } from "../render.js";
|
|
17
18
|
import { classifyManagedCommandFailure } from "../kimi-errors.js";
|
|
18
19
|
import { startBackgroundJob } from "../background-spawn.js";
|
|
19
|
-
import {
|
|
20
|
-
import { warnInheritedBudget, captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes } from "./cli-helpers.js";
|
|
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";
|
|
23
|
+
import { shorten } from "../util.js";
|
|
22
24
|
const ASK_SUMMARY_MAX = 120;
|
|
23
25
|
const ASK_AGENT_PROFILE_PLACEHOLDER = "<cli-client>";
|
|
24
26
|
const ASK_PROMPT_CONTRACT = [
|
|
@@ -45,6 +47,9 @@ export async function runAsk(argv, context) {
|
|
|
45
47
|
const parsed = parseAskArgs(argv);
|
|
46
48
|
if (parsed.help)
|
|
47
49
|
return companionHelp(["ask", ...argv]);
|
|
50
|
+
// Scope always comes from this invocation, never from a resumed job.
|
|
51
|
+
const callerScope = parsed.readRoots === undefined && parsed.network === undefined ? undefined
|
|
52
|
+
: await resolveReadScope(parsed.readRoots, parsed.network, "ask.parse");
|
|
48
53
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
|
|
49
54
|
await requireAskHookInstalled(context);
|
|
50
55
|
}
|
|
@@ -56,16 +61,28 @@ export async function runAsk(argv, context) {
|
|
|
56
61
|
try {
|
|
57
62
|
await sweepStaleJobs(store, paths);
|
|
58
63
|
const jobId = allocateJobId(context);
|
|
59
|
-
const sessionResolution = await
|
|
60
|
-
const
|
|
64
|
+
const sessionResolution = await resolveResumeSession(store, "ask", repoIdentity.repoId, parsed);
|
|
65
|
+
const basePrompt = buildAskPrompt(parsed.prompt, sessionResolution.reusedSession);
|
|
61
66
|
const executionPlan = await prepareKimiExecutionPlan({
|
|
62
67
|
operationKind: "ask",
|
|
63
68
|
cwd: context.cwd,
|
|
64
69
|
env: context.env,
|
|
70
|
+
stderr: context.stderr,
|
|
65
71
|
resumedFromJobId: sessionResolution.resumedFromJobId,
|
|
66
72
|
resumeSessionId: sessionResolution.kimiSessionId ?? undefined,
|
|
67
73
|
resumeSource: sessionResolution.sourceJob,
|
|
68
74
|
});
|
|
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);
|
|
69
86
|
const logPath = path.join(paths.logsDir, `ask-${jobId}.jsonl`);
|
|
70
87
|
const job = store.createJob({
|
|
71
88
|
job_id: jobId,
|
|
@@ -75,12 +92,12 @@ export async function runAsk(argv, context) {
|
|
|
75
92
|
model: parsed.model ?? null,
|
|
76
93
|
thinking: null,
|
|
77
94
|
thinking_effort: parsed.thinkingEffort ?? null,
|
|
95
|
+
read_scope: serializeReadScope(readScope),
|
|
78
96
|
background: parsed.background,
|
|
79
|
-
|
|
80
|
-
budget_source: parsed.budgetMs !== undefined ? "explicit"
|
|
81
|
-
: sessionResolution.sourceJob?.operation_kind === "ask" && sessionResolution.sourceJob.budget_ms !== null ? "inherited" : "default",
|
|
97
|
+
...resumeBudget("ask", parsed.budgetMs, sessionResolution.sourceJob),
|
|
82
98
|
pid: parsed.background ? null : process.pid,
|
|
83
99
|
kimi_pid: null,
|
|
100
|
+
companion_identity: parsed.background ? null : await serializedProcessIdentity(process.pid),
|
|
84
101
|
status: "running",
|
|
85
102
|
kimi_session_id: sessionResolution.kimiSessionId,
|
|
86
103
|
kimi_session_id_source: sessionResolution.sourceJob?.kimi_session_id_source ?? null,
|
|
@@ -110,16 +127,7 @@ export async function runAsk(argv, context) {
|
|
|
110
127
|
return startBackgroundJob(job, askPrompt, context, paths, {
|
|
111
128
|
workerKind: "ask",
|
|
112
129
|
wait: parsed.wait,
|
|
113
|
-
promptEnvVar: "KIMI_PLUGIN_CC_ASK_PROMPT_B64",
|
|
114
|
-
reusedSessionEnvVar: "KIMI_PLUGIN_CC_ASK_REUSED_SESSION",
|
|
115
|
-
reusedSession: sessionResolution.reusedSession,
|
|
116
130
|
failedSummary: askConfig.cancellation.failedSummary,
|
|
117
|
-
missingResultErrorCode: "ASK_RESULT_MISSING",
|
|
118
|
-
spawnFailedErrorCode: "ASK_WORKER_SPAWN_FAILED",
|
|
119
|
-
earlyExitErrorCode: "ASK_WORKER_EXITED_EARLY",
|
|
120
|
-
nodeBinInvalidErrorCode: "ASK_NODE_BIN_INVALID",
|
|
121
|
-
waitStage: "ask.wait",
|
|
122
|
-
spawnStage: "ask.worker.spawn",
|
|
123
131
|
});
|
|
124
132
|
}
|
|
125
133
|
const completed = await executeAskJob(job.job_id, askPrompt, context);
|
|
@@ -152,6 +160,7 @@ export async function executeAskJob(jobId, prompt, context, options) {
|
|
|
152
160
|
}
|
|
153
161
|
handlers = createCliCancellationHandlers();
|
|
154
162
|
const executionPlan = executionPlanFromPersisted(job);
|
|
163
|
+
const readScope = parseJobReadScope(job.read_scope);
|
|
155
164
|
store.updateRunningJob(job.job_id, { phase: "turn-running" });
|
|
156
165
|
// Re-validate resume lineage from the store before spawning: a detached
|
|
157
166
|
// worker (or a forged queued row) reloads the persisted plan and would
|
|
@@ -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,
|
|
@@ -173,9 +187,10 @@ export async function executeAskJob(jobId, prompt, context, options) {
|
|
|
173
187
|
commandLabel: "ask",
|
|
174
188
|
model: job.model ?? undefined,
|
|
175
189
|
thinkingEffort: job.thinking_effort ?? undefined,
|
|
190
|
+
readScope,
|
|
176
191
|
resumeSessionId: job.kimi_session_id ?? undefined,
|
|
177
192
|
logPath: job.stream_log_path,
|
|
178
|
-
onSpawn: (pid) => { store
|
|
193
|
+
onSpawn: async (pid) => { await recordKimiSpawnIdentity(store, job.job_id, pid); },
|
|
179
194
|
signal: handlers.signal,
|
|
180
195
|
}, job.budget_ms ?? KIMI_ASK_PROMPT_TIMEOUT_MS, "ask.prompt");
|
|
181
196
|
store.updateRunningJob(job.job_id, observedExecutionFields(result));
|
|
@@ -194,7 +209,7 @@ export async function executeAskJob(jobId, prompt, context, options) {
|
|
|
194
209
|
store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
|
|
195
210
|
}
|
|
196
211
|
await syncKimiSessionTitle({
|
|
197
|
-
promptText: prompt,
|
|
212
|
+
promptText: askPromptSubject(prompt),
|
|
198
213
|
env: context.env,
|
|
199
214
|
cwd: job.cwd,
|
|
200
215
|
sessionId: result.sessionId ?? job.kimi_session_id,
|
|
@@ -248,70 +263,9 @@ async function requireAskHookInstalled(context) {
|
|
|
248
263
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK === "1") {
|
|
249
264
|
return;
|
|
250
265
|
}
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
maybeWarnHookMissing(installStatus, "ask", context.stderr);
|
|
256
|
-
throw new RuntimeError("ASK_HOOK_NOT_INSTALLED", [
|
|
257
|
-
"ask refuses to run without the canonical kimi-plugin-cc PreToolUse hook.",
|
|
258
|
-
`Hook check failed: ${installStatus.reason ?? "unknown"}.`,
|
|
259
|
-
"Run /kimi:setup or $kimi-setup to install or repair this host's managed block.",
|
|
260
|
-
"Set KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 only if you intentionally accept un-enforced execution.",
|
|
261
|
-
hookRefusalRetryProtocol(context.env),
|
|
262
|
-
].join(" "), "ask.hook-check", { details: hookRefusalDetails(installStatus) });
|
|
263
|
-
}
|
|
264
|
-
async function resolveAskSession(store, repoId, fresh, resume, resumeTarget) {
|
|
265
|
-
if (fresh) {
|
|
266
|
-
return { kimiSessionId: null, reusedSession: false, resumedFromJobId: null, sourceJob: null };
|
|
267
|
-
}
|
|
268
|
-
if (resumeTarget) {
|
|
269
|
-
const byJob = store.getJob(resumeTarget);
|
|
270
|
-
const scoped = byJob?.repo_id === repoId && byJob.command_type === "ask" ? byJob : null;
|
|
271
|
-
const exact = scoped ?? store.findAskJobBySession(repoId, resumeTarget);
|
|
272
|
-
if (!exact) {
|
|
273
|
-
throw new RuntimeError("ASK_RESUME_NOT_FOUND", `No ask job or session matched ${resumeTarget}.`, "ask.resume");
|
|
274
|
-
}
|
|
275
|
-
// Order matters: surface ASK_ALREADY_RUNNING before complaining that
|
|
276
|
-
// the session id is missing. In v1.0 a running ask row carries
|
|
277
|
-
// kimi_session_id=NULL (kimi-code assigns the id post-call), so the
|
|
278
|
-
// legacy "no session id → not found" check would mask the more
|
|
279
|
-
// accurate "already running" error.
|
|
280
|
-
const source = await reconcileHistoricalJobProvenance(store, exact);
|
|
281
|
-
ensureAskSessionIsNotRunning(source);
|
|
282
|
-
if (!source.kimi_session_id) {
|
|
283
|
-
throw new RuntimeError("ASK_RESUME_NOT_FOUND", `No ask job or session matched ${resumeTarget}.`, "ask.resume");
|
|
284
|
-
}
|
|
285
|
-
return {
|
|
286
|
-
kimiSessionId: source.kimi_session_id,
|
|
287
|
-
reusedSession: true,
|
|
288
|
-
resumedFromJobId: source.job_id,
|
|
289
|
-
sourceJob: source,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
if (resume) {
|
|
293
|
-
const latest = store.findLatestJob({ repoId, commandType: "ask" });
|
|
294
|
-
if (!latest) {
|
|
295
|
-
throw new RuntimeError("ASK_RESUME_NOT_FOUND", "No prior ask session exists for this repository.", "ask.resume");
|
|
296
|
-
}
|
|
297
|
-
const source = await reconcileHistoricalJobProvenance(store, latest);
|
|
298
|
-
ensureAskSessionIsNotRunning(source);
|
|
299
|
-
if (!source.kimi_session_id) {
|
|
300
|
-
throw new RuntimeError("ASK_RESUME_NOT_FOUND", "No prior ask session exists for this repository.", "ask.resume");
|
|
301
|
-
}
|
|
302
|
-
return {
|
|
303
|
-
kimiSessionId: source.kimi_session_id,
|
|
304
|
-
reusedSession: true,
|
|
305
|
-
resumedFromJobId: source.job_id,
|
|
306
|
-
sourceJob: source,
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
return { kimiSessionId: null, reusedSession: false, resumedFromJobId: null, sourceJob: null };
|
|
310
|
-
}
|
|
311
|
-
function ensureAskSessionIsNotRunning(job) {
|
|
312
|
-
if (job.status === "running") {
|
|
313
|
-
throw new RuntimeError("ASK_ALREADY_RUNNING", `Ask session ${job.kimi_session_id ?? "<unknown>"} is already active under job ${job.job_id}.`, "ask.resume");
|
|
314
|
-
}
|
|
266
|
+
const refusal = await hookRefusal(context, "ask");
|
|
267
|
+
if (refusal)
|
|
268
|
+
throw refusal;
|
|
315
269
|
}
|
|
316
270
|
function buildAskPrompt(question, reusedSession) {
|
|
317
271
|
if (question?.trim()) {
|
|
@@ -322,15 +276,9 @@ function buildAskPrompt(question, reusedSession) {
|
|
|
322
276
|
}
|
|
323
277
|
throw new RuntimeError("INVALID_ARGS", "ask requires a question after the flags.", "ask.parse");
|
|
324
278
|
}
|
|
325
|
-
function askPromptSubject(prompt) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
function shorten(text, max) {
|
|
331
|
-
const normalized = text.replace(/\s+/g, " ").trim();
|
|
332
|
-
if (normalized.length <= max) {
|
|
333
|
-
return normalized;
|
|
334
|
-
}
|
|
335
|
-
return `${normalized.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
|
|
279
|
+
export function askPromptSubject(prompt) {
|
|
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;
|
|
336
284
|
}
|
package/dist/commands/cancel.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
1
|
import { RuntimeError } from "../errors.js";
|
|
3
2
|
import { resolveRepoIdentity } from "../git.js";
|
|
4
|
-
import { markJobCancelled, sweepStaleJobs } from "../jobs.js";
|
|
3
|
+
import { isPidAlive, killPid, lineagePhase, markJobCancelled, sweepStaleJobs } from "../jobs.js";
|
|
5
4
|
import { JobStore, withJobStore } from "../job-store.js";
|
|
6
5
|
import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
|
|
7
6
|
import { parseJobLookupArgs } from "../parsing.js";
|
|
8
7
|
import { revalidateProcessIdentities } from "../process-tree.js";
|
|
9
|
-
import {
|
|
8
|
+
import { sleep } from "../util.js";
|
|
10
9
|
export async function runCancel(argv, context) {
|
|
11
10
|
const parsed = parseJobLookupArgs(argv);
|
|
12
11
|
const paths = resolvePluginPaths(context.env);
|
|
@@ -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) {
|
|
@@ -103,7 +94,7 @@ export async function runCancel(argv, context) {
|
|
|
103
94
|
await withJobStore(paths, async (forcedStore) => {
|
|
104
95
|
const current = forcedStore.getJob(job.job_id);
|
|
105
96
|
if (current?.status === "running") {
|
|
106
|
-
await markJobCancelled(forcedStore, paths, current, "Job was force-cancelled after recorded process termination.", undefined, current
|
|
97
|
+
await markJobCancelled(forcedStore, paths, current, "Job was force-cancelled after recorded process termination.", undefined, lineagePhase(current, "cancelled"));
|
|
107
98
|
}
|
|
108
99
|
});
|
|
109
100
|
return `${JSON.stringify({
|
|
@@ -149,25 +140,8 @@ function signalJobProcesses(job, signal, include = { companion: true, kimi: true
|
|
|
149
140
|
pids.add(job.pid);
|
|
150
141
|
if (include.kimi && job.kimi_pid !== null)
|
|
151
142
|
pids.add(job.kimi_pid);
|
|
152
|
-
for (const pid of pids)
|
|
153
|
-
|
|
154
|
-
process.kill(pid, signal);
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
const code = error.code;
|
|
158
|
-
// ESRCH: process already gone. EPERM: pid was likely reused by an
|
|
159
|
-
// unrelated process we don't own — silently skip rather than surface a
|
|
160
|
-
// confusing "operation not permitted" to the user.
|
|
161
|
-
if (code !== "ESRCH" && code !== "EPERM") {
|
|
162
|
-
throw error;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function sleep(ms) {
|
|
168
|
-
return new Promise((resolve) => {
|
|
169
|
-
setTimeout(resolve, ms);
|
|
170
|
-
});
|
|
143
|
+
for (const pid of pids)
|
|
144
|
+
killPid(pid, signal);
|
|
171
145
|
}
|
|
172
146
|
async function waitForCancellation(paths, jobId) {
|
|
173
147
|
const deadline = Date.now() + 4_000;
|
|
@@ -185,32 +159,10 @@ async function waitForCancellation(paths, jobId) {
|
|
|
185
159
|
finally {
|
|
186
160
|
store.close();
|
|
187
161
|
}
|
|
188
|
-
await
|
|
189
|
-
setTimeout(resolve, 200);
|
|
190
|
-
});
|
|
162
|
+
await sleep(200);
|
|
191
163
|
}
|
|
192
164
|
return null;
|
|
193
165
|
}
|
|
194
166
|
function hasLiveRecordedProcess(job) {
|
|
195
|
-
|
|
196
|
-
if (job.pid !== null)
|
|
197
|
-
pids.add(job.pid);
|
|
198
|
-
if (job.kimi_pid !== null)
|
|
199
|
-
pids.add(job.kimi_pid);
|
|
200
|
-
for (const pid of pids) {
|
|
201
|
-
try {
|
|
202
|
-
process.kill(pid, 0);
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
catch (error) {
|
|
206
|
-
const code = error.code;
|
|
207
|
-
// ESRCH: definitively dead. EPERM: pid likely reused by an
|
|
208
|
-
// unrelated process — treat as dead for our purposes (consistent
|
|
209
|
-
// with isPidAlive in jobs.ts and signalJobProcesses above).
|
|
210
|
-
if (code !== "ESRCH" && code !== "EPERM") {
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return false;
|
|
167
|
+
return (job.pid !== null && isPidAlive(job.pid)) || (job.kimi_pid !== null && job.kimi_pid !== job.pid && isPidAlive(job.kimi_pid));
|
|
216
168
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { RuntimeError } from "../errors.js";
|
|
2
2
|
import { ResponseTimeoutError } from "../cli-client.js";
|
|
3
|
-
import { observedExecutionFields } from "../kimi-engine.js";
|
|
3
|
+
import { observedExecutionFields, reconcileHistoricalJobProvenance } from "../kimi-engine.js";
|
|
4
|
+
import { capitalize } from "../render.js";
|
|
4
5
|
import { resolveKimiHome } from "../kimi-home.js";
|
|
5
6
|
import { recoverSessionIdFromStore } from "../session-recovery.js";
|
|
7
|
+
import { effectiveReadRoots, parseJobReadScope, rootsWithin } from "../read-scope.js";
|
|
8
|
+
import { hookGateRefusal, verifyHookInstalled } from "../hooks/install.js";
|
|
6
9
|
import { formatBudgetDuration } from "../render.js";
|
|
7
10
|
/**
|
|
8
11
|
* Reassemble prose final text from cli-client records.
|
|
@@ -199,3 +202,101 @@ export function warnInheritedBudget(job, stderr) {
|
|
|
199
202
|
stderr.write(`[${job.command_type}] budget ${formatBudgetDuration(job.budget_ms)} inherited from job ${job.resumed_from_job_id}; pass --budget to override\n`);
|
|
200
203
|
}
|
|
201
204
|
}
|
|
205
|
+
/** Resolve `--resume <job-or-session>` or `-r` for ask and rescue; fresh otherwise. */
|
|
206
|
+
export async function resolveResumeSession(store, kind, repoId, options) {
|
|
207
|
+
if (options.fresh || (!options.resumeTarget && !options.resume)) {
|
|
208
|
+
return { kimiSessionId: null, reusedSession: false, resumedFromJobId: null, sourceJob: null };
|
|
209
|
+
}
|
|
210
|
+
const stem = kind.toUpperCase();
|
|
211
|
+
let candidate;
|
|
212
|
+
let notFoundMessage;
|
|
213
|
+
if (options.resumeTarget) {
|
|
214
|
+
const byJob = store.getJob(options.resumeTarget);
|
|
215
|
+
const scoped = byJob?.repo_id === repoId && byJob.command_type === kind ? byJob : null;
|
|
216
|
+
candidate = scoped ?? (kind === "ask"
|
|
217
|
+
? store.findAskJobBySession(repoId, options.resumeTarget)
|
|
218
|
+
: store.findRescueJobBySession(repoId, options.resumeTarget));
|
|
219
|
+
notFoundMessage = `No ${kind} job or session matched ${options.resumeTarget}.`;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
candidate = store.findLatestJob({ repoId, commandType: kind });
|
|
223
|
+
notFoundMessage = `No prior ${kind} session exists for this repository.`;
|
|
224
|
+
}
|
|
225
|
+
if (!candidate) {
|
|
226
|
+
throw new RuntimeError(`${stem}_RESUME_NOT_FOUND`, notFoundMessage, `${kind}.resume`);
|
|
227
|
+
}
|
|
228
|
+
// Report ALREADY_RUNNING before a missing session id: a running row can
|
|
229
|
+
// still have kimi_session_id = NULL because kimi-code assigns it later.
|
|
230
|
+
const source = await reconcileHistoricalJobProvenance(store, candidate);
|
|
231
|
+
if (source.status === "running") {
|
|
232
|
+
throw new RuntimeError(`${stem}_ALREADY_RUNNING`, `${capitalize(kind)} session ${source.kimi_session_id ?? "<unknown>"} is already active under job ${source.job_id}.`, `${kind}.resume`);
|
|
233
|
+
}
|
|
234
|
+
if (!source.kimi_session_id) {
|
|
235
|
+
throw new RuntimeError(`${stem}_RESUME_NOT_FOUND`, notFoundMessage, `${kind}.resume`);
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
kimiSessionId: source.kimi_session_id,
|
|
239
|
+
reusedSession: true,
|
|
240
|
+
resumedFromJobId: source.job_id,
|
|
241
|
+
sourceJob: source,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* --network on a resumed session must not send out what an earlier turn
|
|
246
|
+
* read. Every job recorded for the session, and every job on the source's
|
|
247
|
+
* resume chain, must have run confined to roots inside `currentRoots`.
|
|
248
|
+
* No recorded history, a broken chain or an unreadable scope counts as
|
|
249
|
+
* unconfined.
|
|
250
|
+
*/
|
|
251
|
+
export function assertNetworkResumeConfined(store, kind, resolution, currentRoots) {
|
|
252
|
+
if (!resolution.reusedSession)
|
|
253
|
+
return;
|
|
254
|
+
const sessionId = resolution.kimiSessionId;
|
|
255
|
+
// Each earlier turn's reads stay in the conversation, so each earlier
|
|
256
|
+
// turn's roots must lie inside this call's roots.
|
|
257
|
+
const confinedWithin = (job) => {
|
|
258
|
+
if (job === null || job.read_scope == null)
|
|
259
|
+
return false;
|
|
260
|
+
try {
|
|
261
|
+
const scope = parseJobReadScope(job.read_scope);
|
|
262
|
+
return scope !== undefined && rootsWithin(effectiveReadRoots(scope, job.cwd), currentRoots);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const history = sessionId ? store.listJobsBySessionId(sessionId) : [];
|
|
269
|
+
let confined = history.length > 0 && history.every(confinedWithin);
|
|
270
|
+
const seen = new Set();
|
|
271
|
+
for (let jobId = resolution.sourceJob?.job_id; confined && jobId;) {
|
|
272
|
+
if (seen.has(jobId))
|
|
273
|
+
break;
|
|
274
|
+
seen.add(jobId);
|
|
275
|
+
const job = store.getJob(jobId);
|
|
276
|
+
confined = confinedWithin(job);
|
|
277
|
+
jobId = job?.resumed_from_job_id;
|
|
278
|
+
}
|
|
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, --read-root directories and referenced sessions (or its history is not recorded), so those reads could be sent out. ` +
|
|
281
|
+
`Start a fresh session instead: ${kind} --fresh --network [--read-root <dir>] <prompt>.`, `${kind}.resume`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/** An explicit budget wins; otherwise a resume inherits its same-operation source's budget. */
|
|
285
|
+
export function resumeBudget(kind, explicitMs, source) {
|
|
286
|
+
const inherited = source?.operation_kind === kind ? source.budget_ms : null;
|
|
287
|
+
return {
|
|
288
|
+
budget_ms: explicitMs ?? inherited ?? null,
|
|
289
|
+
budget_source: explicitMs !== undefined ? "explicit" : inherited !== null ? "inherited" : "default",
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
export { READ_ONLY_HOOK_REPAIR, WRITE_HOOK_REPAIR } from "../hooks/install.js";
|
|
293
|
+
/**
|
|
294
|
+
* Verify the managed PreToolUse hook. Returns null when it is installed;
|
|
295
|
+
* otherwise warns once on stderr and returns `operation`'s gate refusal.
|
|
296
|
+
*/
|
|
297
|
+
export async function hookRefusal(context, operation) {
|
|
298
|
+
const installStatus = await verifyHookInstalled(context.env);
|
|
299
|
+
if (installStatus.installed)
|
|
300
|
+
return null;
|
|
301
|
+
return hookGateRefusal(operation, installStatus, context.env, context.stderr);
|
|
302
|
+
}
|
package/dist/commands/models.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { constants } from "node:fs";
|
|
2
2
|
import { open } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
3
|
import { RuntimeError } from "../errors.js";
|
|
5
|
-
import {
|
|
4
|
+
import { resolveKimiCodeConfigPath } from "../kimi-home.js";
|
|
6
5
|
import { upstreamSnakeToCamel } from "../native-v2-preflight.js";
|
|
7
6
|
import { parse as parseToml } from "../vendor/smol-toml/parse.js";
|
|
8
7
|
export async function runModelInventory(argv, context) {
|
|
9
8
|
if (argv.length > 1 || (argv.length === 1 && argv[0] !== "--json")) {
|
|
10
9
|
throw new RuntimeError("INVALID_ARGS", "Use setup --models [--json] without other setup flags.", "setup.models");
|
|
11
10
|
}
|
|
12
|
-
const configPath =
|
|
11
|
+
const configPath = resolveKimiCodeConfigPath(context.env, context.cwd);
|
|
13
12
|
let config = {};
|
|
14
13
|
let configPresent = true;
|
|
15
14
|
try {
|
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";
|
|
@@ -13,9 +13,9 @@ import { writeInvocationLogHeader } from "../logging.js";
|
|
|
13
13
|
import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
|
|
14
14
|
import { parsePursueArgs } from "../parsing.js";
|
|
15
15
|
import { readArtifact, renderManagedJobOutput, writeArtifact } from "../render.js";
|
|
16
|
-
import {
|
|
17
|
-
import { assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes } from "./cli-helpers.js";
|
|
16
|
+
import { assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes, hookRefusal } from "./cli-helpers.js";
|
|
18
17
|
import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
|
|
18
|
+
import { shorten } from "../util.js";
|
|
19
19
|
// /kimi:pursue — experimental autonomous goal mode (kimi-code 0.8.0+).
|
|
20
20
|
// Runtime-foreground-only, with a mandatory finite wall-clock budget. No resume:
|
|
21
21
|
// goalId is distinct from sessionId. Rescue lineage and the "rescue" hook label
|
|
@@ -120,6 +120,7 @@ export async function runPursue(argv, context) {
|
|
|
120
120
|
operationKind: "pursue",
|
|
121
121
|
cwd: context.cwd,
|
|
122
122
|
env: context.env,
|
|
123
|
+
stderr: context.stderr,
|
|
123
124
|
});
|
|
124
125
|
const prompt = buildGoalPrompt(objective, parsed.turns);
|
|
125
126
|
const jobId = allocateJobId(context);
|
|
@@ -138,6 +139,7 @@ export async function runPursue(argv, context) {
|
|
|
138
139
|
budget_source: parsed.budgetMs !== undefined ? "explicit" : "default",
|
|
139
140
|
pid: process.pid,
|
|
140
141
|
kimi_pid: null,
|
|
142
|
+
companion_identity: await serializedProcessIdentity(process.pid),
|
|
141
143
|
status: "running",
|
|
142
144
|
kimi_session_id: null,
|
|
143
145
|
...persistedExecutionPlanFields(executionPlan),
|
|
@@ -184,16 +186,8 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
|
|
|
184
186
|
// exactly like rescue. The hook gates every tool call in every goal
|
|
185
187
|
// continuation turn; without it, kimi -p auto-approves destructive ops.
|
|
186
188
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
|
|
187
|
-
const
|
|
188
|
-
if (
|
|
189
|
-
maybeWarnHookMissing(installStatus, "rescue", context.stderr);
|
|
190
|
-
const classified = new RuntimeError("PURSUE_HOOK_NOT_INSTALLED", [
|
|
191
|
-
"/kimi:pursue refuses to run without the kimi-plugin-cc PreToolUse hook.",
|
|
192
|
-
`Hook check failed: ${installStatus.reason ?? "unknown"}.`,
|
|
193
|
-
"Repair by running Claude Code /kimi:setup or Codex $kimi-setup, then retry.",
|
|
194
|
-
"KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 is only for deliberate tests or diagnostics.",
|
|
195
|
-
hookRefusalRetryProtocol(context.env),
|
|
196
|
-
].join(" "), "pursue.hook-check", { details: hookRefusalDetails(installStatus) });
|
|
189
|
+
const classified = await hookRefusal(context, "pursue");
|
|
190
|
+
if (classified) {
|
|
197
191
|
try {
|
|
198
192
|
return await markJobFailed(store, paths, job, classified, "Pursue failed.", { phase: "failed" });
|
|
199
193
|
}
|
|
@@ -226,7 +220,7 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
|
|
|
226
220
|
model: job.model ?? undefined,
|
|
227
221
|
thinkingEffort: job.thinking_effort ?? undefined,
|
|
228
222
|
logPath: job.stream_log_path,
|
|
229
|
-
onSpawn: (pid) => { store
|
|
223
|
+
onSpawn: async (pid) => { await recordKimiSpawnIdentity(store, job.job_id, pid); },
|
|
230
224
|
signal: handlers.signal,
|
|
231
225
|
}, budgetMs, "pursue.prompt");
|
|
232
226
|
store.updateRunningJob(job.job_id, observedExecutionFields(result));
|
|
@@ -298,10 +292,3 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
|
|
|
298
292
|
store.close();
|
|
299
293
|
}
|
|
300
294
|
}
|
|
301
|
-
function shorten(text, max) {
|
|
302
|
-
const normalized = text.replace(/\s+/g, " ").trim();
|
|
303
|
-
if (normalized.length <= max) {
|
|
304
|
-
return normalized;
|
|
305
|
-
}
|
|
306
|
-
return `${normalized.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
|
|
307
|
-
}
|
|
@@ -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];
|