kimi-plugin-cc 2.7.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +3 -5
- package/CHANGELOG.md +78 -1
- package/README.md +505 -448
- package/agents/kimi-pursue.md +6 -6
- package/agents/kimi-review.md +22 -22
- package/agents/kimi-swarm.md +25 -23
- package/agents/{kimi-ask.md → kimi-task.md} +34 -30
- package/commands/README.md +4 -6
- package/commands/pursue.md +1 -1
- package/commands/review.md +8 -3
- package/commands/setup.md +4 -2
- package/commands/swarm.md +6 -5
- package/commands/{rescue.md → task.md} +13 -11
- package/dist/background-spawn.js +10 -17
- package/dist/cli-client.js +65 -46
- package/dist/commands/ask.js +22 -89
- package/dist/commands/cancel.js +7 -46
- package/dist/commands/cli-helpers.js +102 -1
- package/dist/commands/models.js +2 -3
- package/dist/commands/pursue.js +5 -19
- package/dist/commands/repair-sessions.js +118 -12
- package/dist/commands/rescue.js +12 -82
- package/dist/commands/result.js +7 -1
- package/dist/commands/review-gate.js +1 -0
- package/dist/commands/review.js +12 -15
- package/dist/commands/setup.js +606 -270
- package/dist/commands/status.js +2 -2
- package/dist/commands/swarm.js +93 -119
- package/dist/commands/worker.js +1 -2
- package/dist/companion.js +3 -1
- package/dist/dsh/index.js +15 -17
- package/dist/git.js +1 -9
- package/dist/help.js +3 -3
- package/dist/hooks/approval-hook.js +41 -0
- package/dist/hooks/approval-policy.js +72 -10
- package/dist/hooks/config-safety.js +19 -42
- package/dist/hooks/hook-timing.js +48 -0
- package/dist/hooks/install.js +206 -11
- package/dist/hooks/managed-block.js +78 -33
- package/dist/job-store.js +100 -128
- package/dist/jobs.js +14 -19
- package/dist/kimi-command.js +74 -1
- package/dist/kimi-engine.js +170 -74
- package/dist/kimi-errors.js +14 -69
- package/dist/kimi-home.js +6 -0
- package/dist/kimi-journal.js +41 -0
- package/dist/kimi-releases.js +144 -0
- package/dist/kimi-timeouts.js +1 -1
- package/dist/kimi-version-probe.js +12 -48
- package/dist/mcp/job-control.js +4 -6
- package/dist/mcp/launcher.js +12 -6
- package/dist/mcp/operations.js +50 -18
- package/dist/mcp/protocol.js +16 -14
- package/dist/mcp/stdio.js +3 -2
- package/dist/model-command.js +5 -3
- package/dist/native-v2-preflight.js +139 -68
- package/dist/parsing.js +171 -237
- package/dist/paths.js +8 -0
- package/dist/process-tree.js +35 -24
- package/dist/read-scope.js +435 -0
- package/dist/render.js +46 -9
- package/dist/rescue-approval.js +461 -84
- package/dist/schemas/review-gate-output.js +3 -5
- package/dist/session-title.js +25 -5
- package/dist/stream-json.js +1 -3
- package/dist/surface-routing.js +21 -0
- package/dist/swarm-activation.js +74 -77
- package/dist/swarm-policy.js +2 -1
- package/dist/swarm-recovery.js +2 -1
- package/dist/util.js +28 -0
- package/dist/version.js +1 -1
- package/docs/migration.md +27 -6
- package/docs/models.md +2 -2
- package/docs/registry-releases.md +3 -1
- package/docs/safety.md +131 -81
- package/docs/session-visibility.md +5 -3
- package/docs/swarm-recovery.md +4 -4
- package/docs/upstream-2.7.2-certification.md +16 -2
- package/docs/upstream-2.7.3-certification.md +95 -0
- package/package.json +2 -1
- package/plugins/kimi-codex/.codex-plugin/plugin.json +3 -3
- package/plugins/kimi-codex/.mcp.json +1 -0
- package/plugins/kimi-codex/dist/background-spawn.js +10 -17
- package/plugins/kimi-codex/dist/cli-client.js +65 -46
- package/plugins/kimi-codex/dist/commands/ask.js +22 -89
- package/plugins/kimi-codex/dist/commands/cancel.js +7 -46
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +102 -1
- package/plugins/kimi-codex/dist/commands/models.js +2 -3
- package/plugins/kimi-codex/dist/commands/pursue.js +5 -19
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +118 -12
- package/plugins/kimi-codex/dist/commands/rescue.js +12 -82
- package/plugins/kimi-codex/dist/commands/result.js +7 -1
- package/plugins/kimi-codex/dist/commands/review-gate.js +1 -0
- package/plugins/kimi-codex/dist/commands/review.js +12 -15
- package/plugins/kimi-codex/dist/commands/setup.js +606 -270
- package/plugins/kimi-codex/dist/commands/status.js +2 -2
- package/plugins/kimi-codex/dist/commands/swarm.js +93 -119
- package/plugins/kimi-codex/dist/commands/worker.js +1 -2
- package/plugins/kimi-codex/dist/companion.js +3 -1
- package/plugins/kimi-codex/dist/dsh/index.js +15 -17
- package/plugins/kimi-codex/dist/git.js +1 -9
- package/plugins/kimi-codex/dist/help.js +3 -3
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +41 -0
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +72 -10
- package/plugins/kimi-codex/dist/hooks/config-safety.js +19 -42
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-codex/dist/hooks/install.js +206 -11
- package/plugins/kimi-codex/dist/hooks/managed-block.js +78 -33
- package/plugins/kimi-codex/dist/job-store.js +100 -128
- package/plugins/kimi-codex/dist/jobs.js +14 -19
- package/plugins/kimi-codex/dist/kimi-command.js +74 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +170 -74
- package/plugins/kimi-codex/dist/kimi-errors.js +14 -69
- package/plugins/kimi-codex/dist/kimi-home.js +6 -0
- package/plugins/kimi-codex/dist/kimi-journal.js +41 -0
- package/plugins/kimi-codex/dist/kimi-releases.js +144 -0
- package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -1
- package/plugins/kimi-codex/dist/kimi-version-probe.js +12 -48
- package/plugins/kimi-codex/dist/mcp/job-control.js +4 -6
- package/plugins/kimi-codex/dist/mcp/launcher.js +12 -6
- package/plugins/kimi-codex/dist/mcp/operations.js +50 -18
- package/plugins/kimi-codex/dist/mcp/protocol.js +16 -14
- package/plugins/kimi-codex/dist/mcp/stdio.js +3 -2
- package/plugins/kimi-codex/dist/model-command.js +5 -3
- package/plugins/kimi-codex/dist/native-v2-preflight.js +139 -68
- package/plugins/kimi-codex/dist/parsing.js +171 -237
- package/plugins/kimi-codex/dist/paths.js +8 -0
- package/plugins/kimi-codex/dist/process-tree.js +35 -24
- package/plugins/kimi-codex/dist/read-scope.js +435 -0
- package/plugins/kimi-codex/dist/render.js +46 -9
- package/plugins/kimi-codex/dist/rescue-approval.js +461 -84
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +3 -5
- package/plugins/kimi-codex/dist/session-title.js +25 -5
- package/plugins/kimi-codex/dist/stream-json.js +1 -3
- package/plugins/kimi-codex/dist/surface-routing.js +21 -0
- package/plugins/kimi-codex/dist/swarm-activation.js +74 -77
- package/plugins/kimi-codex/dist/swarm-policy.js +2 -1
- package/plugins/kimi-codex/dist/swarm-recovery.js +2 -1
- package/plugins/kimi-codex/dist/util.js +28 -0
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +1 -1
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +8 -7
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +1 -1
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +2 -1
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +8 -6
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +1 -1
- package/plugins/kimi-codex/skills/{kimi-ask → kimi-task}/SKILL.md +11 -9
- package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +6 -0
- package/plugins/kimi-dsh/README.md +3 -2
- package/plugins/kimi-dsh/dist/background-spawn.js +10 -17
- package/plugins/kimi-dsh/dist/cli-client.js +65 -46
- package/plugins/kimi-dsh/dist/commands/ask.js +22 -89
- package/plugins/kimi-dsh/dist/commands/cancel.js +7 -46
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +102 -1
- package/plugins/kimi-dsh/dist/commands/models.js +2 -3
- package/plugins/kimi-dsh/dist/commands/pursue.js +5 -19
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +118 -12
- package/plugins/kimi-dsh/dist/commands/rescue.js +12 -82
- package/plugins/kimi-dsh/dist/commands/result.js +7 -1
- package/plugins/kimi-dsh/dist/commands/review-gate.js +1 -0
- package/plugins/kimi-dsh/dist/commands/review.js +12 -15
- package/plugins/kimi-dsh/dist/commands/setup.js +606 -270
- package/plugins/kimi-dsh/dist/commands/status.js +2 -2
- package/plugins/kimi-dsh/dist/commands/swarm.js +93 -119
- package/plugins/kimi-dsh/dist/commands/worker.js +1 -2
- package/plugins/kimi-dsh/dist/companion.js +3 -1
- package/plugins/kimi-dsh/dist/dsh/index.js +15 -17
- package/plugins/kimi-dsh/dist/git.js +1 -9
- package/plugins/kimi-dsh/dist/help.js +3 -3
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +41 -0
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +72 -10
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +19 -42
- package/plugins/kimi-dsh/dist/hooks/hook-timing.js +48 -0
- package/plugins/kimi-dsh/dist/hooks/install.js +206 -11
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +78 -33
- package/plugins/kimi-dsh/dist/job-store.js +100 -128
- package/plugins/kimi-dsh/dist/jobs.js +14 -19
- package/plugins/kimi-dsh/dist/kimi-command.js +74 -1
- package/plugins/kimi-dsh/dist/kimi-engine.js +170 -74
- package/plugins/kimi-dsh/dist/kimi-errors.js +14 -69
- package/plugins/kimi-dsh/dist/kimi-home.js +6 -0
- package/plugins/kimi-dsh/dist/kimi-journal.js +41 -0
- package/plugins/kimi-dsh/dist/kimi-releases.js +144 -0
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +1 -1
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +12 -48
- package/plugins/kimi-dsh/dist/mcp/job-control.js +4 -6
- package/plugins/kimi-dsh/dist/mcp/launcher.js +12 -6
- package/plugins/kimi-dsh/dist/mcp/operations.js +50 -18
- package/plugins/kimi-dsh/dist/mcp/protocol.js +16 -14
- package/plugins/kimi-dsh/dist/mcp/stdio.js +3 -2
- package/plugins/kimi-dsh/dist/model-command.js +5 -3
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +139 -68
- package/plugins/kimi-dsh/dist/parsing.js +171 -237
- package/plugins/kimi-dsh/dist/paths.js +8 -0
- package/plugins/kimi-dsh/dist/process-tree.js +35 -24
- package/plugins/kimi-dsh/dist/read-scope.js +435 -0
- package/plugins/kimi-dsh/dist/render.js +46 -9
- package/plugins/kimi-dsh/dist/rescue-approval.js +461 -84
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +3 -5
- package/plugins/kimi-dsh/dist/session-title.js +25 -5
- package/plugins/kimi-dsh/dist/stream-json.js +1 -3
- package/plugins/kimi-dsh/dist/surface-routing.js +21 -0
- package/plugins/kimi-dsh/dist/swarm-activation.js +74 -77
- package/plugins/kimi-dsh/dist/swarm-policy.js +2 -1
- package/plugins/kimi-dsh/dist/swarm-recovery.js +2 -1
- package/plugins/kimi-dsh/dist/util.js +28 -0
- package/plugins/kimi-dsh/dist/version.js +1 -1
- package/plugins/kimi-dsh/package.json +1 -1
- package/agents/kimi-challenge.md +0 -86
- package/agents/kimi-rescue.md +0 -92
- package/agents/kimi-swarm-write.md +0 -96
- package/commands/ask.md +0 -38
- package/commands/challenge.md +0 -35
- package/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-codex/dist/commands/not-implemented.js +0 -4
- package/plugins/kimi-codex/skills/kimi-ask/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-challenge/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-challenge/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-rescue/SKILL.md +0 -34
- package/plugins/kimi-codex/skills/kimi-rescue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm-write/SKILL.md +0 -36
- package/plugins/kimi-codex/skills/kimi-swarm-write/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/dist/commands/not-implemented.js +0 -4
|
@@ -3,7 +3,7 @@ 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";
|
|
@@ -13,12 +13,13 @@ 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 { shorten } from "../util.js";
|
|
22
23
|
const ASK_SUMMARY_MAX = 120;
|
|
23
24
|
const ASK_AGENT_PROFILE_PLACEHOLDER = "<cli-client>";
|
|
24
25
|
const ASK_PROMPT_CONTRACT = [
|
|
@@ -45,6 +46,9 @@ export async function runAsk(argv, context) {
|
|
|
45
46
|
const parsed = parseAskArgs(argv);
|
|
46
47
|
if (parsed.help)
|
|
47
48
|
return companionHelp(["ask", ...argv]);
|
|
49
|
+
// Scope always comes from this invocation, never from a resumed job.
|
|
50
|
+
const readScope = parsed.readRoots === undefined && parsed.network === undefined ? undefined
|
|
51
|
+
: await resolveReadScope(parsed.readRoots, parsed.network, "ask.parse");
|
|
48
52
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
|
|
49
53
|
await requireAskHookInstalled(context);
|
|
50
54
|
}
|
|
@@ -56,16 +60,21 @@ export async function runAsk(argv, context) {
|
|
|
56
60
|
try {
|
|
57
61
|
await sweepStaleJobs(store, paths);
|
|
58
62
|
const jobId = allocateJobId(context);
|
|
59
|
-
const sessionResolution = await
|
|
63
|
+
const sessionResolution = await resolveResumeSession(store, "ask", repoIdentity.repoId, parsed);
|
|
64
|
+
if (readScope?.network === true) {
|
|
65
|
+
assertNetworkResumeConfined(store, "ask", sessionResolution, effectiveReadRoots(readScope, context.cwd));
|
|
66
|
+
}
|
|
60
67
|
const askPrompt = buildAskPrompt(parsed.prompt, sessionResolution.reusedSession);
|
|
61
68
|
const executionPlan = await prepareKimiExecutionPlan({
|
|
62
69
|
operationKind: "ask",
|
|
63
70
|
cwd: context.cwd,
|
|
64
71
|
env: context.env,
|
|
72
|
+
stderr: context.stderr,
|
|
65
73
|
resumedFromJobId: sessionResolution.resumedFromJobId,
|
|
66
74
|
resumeSessionId: sessionResolution.kimiSessionId ?? undefined,
|
|
67
75
|
resumeSource: sessionResolution.sourceJob,
|
|
68
76
|
});
|
|
77
|
+
assertScopeSupported(readScope, executionPlan.certification, "INVALID_ARGS", "ask.parse");
|
|
69
78
|
const logPath = path.join(paths.logsDir, `ask-${jobId}.jsonl`);
|
|
70
79
|
const job = store.createJob({
|
|
71
80
|
job_id: jobId,
|
|
@@ -75,10 +84,9 @@ export async function runAsk(argv, context) {
|
|
|
75
84
|
model: parsed.model ?? null,
|
|
76
85
|
thinking: null,
|
|
77
86
|
thinking_effort: parsed.thinkingEffort ?? null,
|
|
87
|
+
read_scope: serializeReadScope(readScope),
|
|
78
88
|
background: parsed.background,
|
|
79
|
-
|
|
80
|
-
budget_source: parsed.budgetMs !== undefined ? "explicit"
|
|
81
|
-
: sessionResolution.sourceJob?.operation_kind === "ask" && sessionResolution.sourceJob.budget_ms !== null ? "inherited" : "default",
|
|
89
|
+
...resumeBudget("ask", parsed.budgetMs, sessionResolution.sourceJob),
|
|
82
90
|
pid: parsed.background ? null : process.pid,
|
|
83
91
|
kimi_pid: null,
|
|
84
92
|
status: "running",
|
|
@@ -110,16 +118,7 @@ export async function runAsk(argv, context) {
|
|
|
110
118
|
return startBackgroundJob(job, askPrompt, context, paths, {
|
|
111
119
|
workerKind: "ask",
|
|
112
120
|
wait: parsed.wait,
|
|
113
|
-
promptEnvVar: "KIMI_PLUGIN_CC_ASK_PROMPT_B64",
|
|
114
|
-
reusedSessionEnvVar: "KIMI_PLUGIN_CC_ASK_REUSED_SESSION",
|
|
115
|
-
reusedSession: sessionResolution.reusedSession,
|
|
116
121
|
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
122
|
});
|
|
124
123
|
}
|
|
125
124
|
const completed = await executeAskJob(job.job_id, askPrompt, context);
|
|
@@ -152,6 +151,7 @@ export async function executeAskJob(jobId, prompt, context, options) {
|
|
|
152
151
|
}
|
|
153
152
|
handlers = createCliCancellationHandlers();
|
|
154
153
|
const executionPlan = executionPlanFromPersisted(job);
|
|
154
|
+
const readScope = parseJobReadScope(job.read_scope);
|
|
155
155
|
store.updateRunningJob(job.job_id, { phase: "turn-running" });
|
|
156
156
|
// Re-validate resume lineage from the store before spawning: a detached
|
|
157
157
|
// worker (or a forged queued row) reloads the persisted plan and would
|
|
@@ -173,6 +173,7 @@ export async function executeAskJob(jobId, prompt, context, options) {
|
|
|
173
173
|
commandLabel: "ask",
|
|
174
174
|
model: job.model ?? undefined,
|
|
175
175
|
thinkingEffort: job.thinking_effort ?? undefined,
|
|
176
|
+
readScope,
|
|
176
177
|
resumeSessionId: job.kimi_session_id ?? undefined,
|
|
177
178
|
logPath: job.stream_log_path,
|
|
178
179
|
onSpawn: (pid) => { store.updateRunningJob(job.job_id, { kimi_pid: pid }); },
|
|
@@ -194,7 +195,7 @@ export async function executeAskJob(jobId, prompt, context, options) {
|
|
|
194
195
|
store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
|
|
195
196
|
}
|
|
196
197
|
await syncKimiSessionTitle({
|
|
197
|
-
promptText: prompt,
|
|
198
|
+
promptText: askPromptSubject(prompt),
|
|
198
199
|
env: context.env,
|
|
199
200
|
cwd: job.cwd,
|
|
200
201
|
sessionId: result.sessionId ?? job.kimi_session_id,
|
|
@@ -248,70 +249,9 @@ async function requireAskHookInstalled(context) {
|
|
|
248
249
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK === "1") {
|
|
249
250
|
return;
|
|
250
251
|
}
|
|
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
|
-
}
|
|
252
|
+
const refusal = await hookRefusal(context, "ask");
|
|
253
|
+
if (refusal)
|
|
254
|
+
throw refusal;
|
|
315
255
|
}
|
|
316
256
|
function buildAskPrompt(question, reusedSession) {
|
|
317
257
|
if (question?.trim()) {
|
|
@@ -322,15 +262,8 @@ function buildAskPrompt(question, reusedSession) {
|
|
|
322
262
|
}
|
|
323
263
|
throw new RuntimeError("INVALID_ARGS", "ask requires a question after the flags.", "ask.parse");
|
|
324
264
|
}
|
|
325
|
-
function askPromptSubject(prompt) {
|
|
265
|
+
export function askPromptSubject(prompt) {
|
|
326
266
|
if (prompt.startsWith(ASK_PROMPT_PREFIX))
|
|
327
267
|
return prompt.slice(ASK_PROMPT_PREFIX.length);
|
|
328
268
|
return prompt === ASK_RESUME_PROMPT ? ASK_CONTINUE_TASK : prompt;
|
|
329
269
|
}
|
|
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()}…`;
|
|
336
|
-
}
|
|
@@ -1,12 +1,12 @@
|
|
|
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
8
|
import { getManagedCommandConfig } from "./registry.js";
|
|
9
|
+
import { sleep } from "../util.js";
|
|
10
10
|
export async function runCancel(argv, context) {
|
|
11
11
|
const parsed = parseJobLookupArgs(argv);
|
|
12
12
|
const paths = resolvePluginPaths(context.env);
|
|
@@ -103,7 +103,7 @@ export async function runCancel(argv, context) {
|
|
|
103
103
|
await withJobStore(paths, async (forcedStore) => {
|
|
104
104
|
const current = forcedStore.getJob(job.job_id);
|
|
105
105
|
if (current?.status === "running") {
|
|
106
|
-
await markJobCancelled(forcedStore, paths, current, "Job was force-cancelled after recorded process termination.", undefined, current
|
|
106
|
+
await markJobCancelled(forcedStore, paths, current, "Job was force-cancelled after recorded process termination.", undefined, lineagePhase(current, "cancelled"));
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
109
|
return `${JSON.stringify({
|
|
@@ -149,25 +149,8 @@ function signalJobProcesses(job, signal, include = { companion: true, kimi: true
|
|
|
149
149
|
pids.add(job.pid);
|
|
150
150
|
if (include.kimi && job.kimi_pid !== null)
|
|
151
151
|
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
|
-
});
|
|
152
|
+
for (const pid of pids)
|
|
153
|
+
killPid(pid, signal);
|
|
171
154
|
}
|
|
172
155
|
async function waitForCancellation(paths, jobId) {
|
|
173
156
|
const deadline = Date.now() + 4_000;
|
|
@@ -185,32 +168,10 @@ async function waitForCancellation(paths, jobId) {
|
|
|
185
168
|
finally {
|
|
186
169
|
store.close();
|
|
187
170
|
}
|
|
188
|
-
await
|
|
189
|
-
setTimeout(resolve, 200);
|
|
190
|
-
});
|
|
171
|
+
await sleep(200);
|
|
191
172
|
}
|
|
192
173
|
return null;
|
|
193
174
|
}
|
|
194
175
|
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;
|
|
176
|
+
return (job.pid !== null && isPidAlive(job.pid)) || (job.kimi_pid !== null && job.kimi_pid !== job.pid && isPidAlive(job.kimi_pid));
|
|
216
177
|
}
|
|
@@ -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 and --read-root directories (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
|
+
}
|
|
@@ -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 {
|
|
@@ -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);
|
|
@@ -184,16 +185,8 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
|
|
|
184
185
|
// exactly like rescue. The hook gates every tool call in every goal
|
|
185
186
|
// continuation turn; without it, kimi -p auto-approves destructive ops.
|
|
186
187
|
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) });
|
|
188
|
+
const classified = await hookRefusal(context, "pursue");
|
|
189
|
+
if (classified) {
|
|
197
190
|
try {
|
|
198
191
|
return await markJobFailed(store, paths, job, classified, "Pursue failed.", { phase: "failed" });
|
|
199
192
|
}
|
|
@@ -298,10 +291,3 @@ async function executePursueJob(jobId, prompt, objective, budgetMs, context) {
|
|
|
298
291
|
store.close();
|
|
299
292
|
}
|
|
300
293
|
}
|
|
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
|
-
}
|
|
@@ -8,6 +8,10 @@ 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 { askPromptSubject } from "./ask.js";
|
|
12
|
+
import { buildGoalPrompt } from "./pursue.js";
|
|
13
|
+
import { stripRescuePromptPrefix } from "./rescue.js";
|
|
14
|
+
import { buildSwarmPrompt, buildSwarmWritePrompt } from "./swarm.js";
|
|
11
15
|
// Repair is deliberately finite and local. Stream logs may be very large, but
|
|
12
16
|
// the spawn record follows the invocation header: read only a bounded prefix.
|
|
13
17
|
const MAX_JOBS = 1000;
|
|
@@ -25,27 +29,46 @@ export async function runRepairSessions(argv, context) {
|
|
|
25
29
|
const paths = resolvePluginPaths(context.env);
|
|
26
30
|
const repoId = all ? undefined : (await resolveRepoIdentity(context.cwd)).repoId;
|
|
27
31
|
const jobs = await readRepairJobs(paths.stateDbPath, repoId);
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
// Newest job first per session: it supplies the preview, while every
|
|
33
|
+
// verified prompt of the session counts as the plugin's own.
|
|
34
|
+
const sessions = new Map();
|
|
30
35
|
for (const job of jobs) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const sessionJobs = sessions.get(job.kimi_session_id);
|
|
37
|
+
if (sessionJobs)
|
|
38
|
+
sessionJobs.push(job);
|
|
39
|
+
else
|
|
40
|
+
sessions.set(job.kimi_session_id, [job]);
|
|
41
|
+
}
|
|
42
|
+
const results = [];
|
|
43
|
+
for (const [sessionId, [job, ...earlier]] of sessions) {
|
|
44
|
+
const prompt = await readVerifiedPrompt(job, paths.logsDir, paths.worktreesDir);
|
|
45
|
+
let status = "unavailable-verified-prompt";
|
|
46
|
+
if (prompt !== undefined) {
|
|
47
|
+
const raw = rawTaskTextFromSubmittedPrompt(job.operation_kind, prompt);
|
|
48
|
+
const own = [prompt];
|
|
49
|
+
if (raw !== undefined) {
|
|
50
|
+
for (const other of earlier) {
|
|
51
|
+
const otherPrompt = await readVerifiedPrompt(other, paths.logsDir, paths.worktreesDir);
|
|
52
|
+
if (otherPrompt !== undefined)
|
|
53
|
+
own.push(otherPrompt);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
status = await syncKimiSessionTitle({
|
|
38
57
|
env: context.env,
|
|
39
58
|
cwd: job.cwd,
|
|
40
|
-
sessionId
|
|
59
|
+
sessionId,
|
|
41
60
|
title: "",
|
|
42
|
-
|
|
61
|
+
// Without an exact raw-text derivation, only a missing preview is
|
|
62
|
+
// filled, with the verified prompt itself.
|
|
63
|
+
promptText: raw ?? prompt,
|
|
64
|
+
ownPrompts: raw === undefined ? [] : own,
|
|
43
65
|
dryRun: !apply,
|
|
44
66
|
preserveTitle: true,
|
|
45
67
|
requireNativeV2: true,
|
|
46
68
|
stderr: context.stderr,
|
|
47
69
|
});
|
|
48
|
-
|
|
70
|
+
}
|
|
71
|
+
results.push({ job_id: job.job_id, session_id: sessionId, status });
|
|
49
72
|
}
|
|
50
73
|
const counts = {};
|
|
51
74
|
for (const { status } of results)
|
|
@@ -158,3 +181,86 @@ async function readVerifiedPrompt(job, logsDir, worktreesDir) {
|
|
|
158
181
|
return undefined;
|
|
159
182
|
}
|
|
160
183
|
}
|
|
184
|
+
const TASK_SLOT = "\u0000kimi-plugin-cc-task\u0000";
|
|
185
|
+
/**
|
|
186
|
+
* Recover the raw task text a live run previews from its verified submitted
|
|
187
|
+
* prompt. Derivations are exact or absent: prompts from other plugin releases,
|
|
188
|
+
* ambiguous parameter choices and unknown operations return undefined.
|
|
189
|
+
*/
|
|
190
|
+
export function rawTaskTextFromSubmittedPrompt(operationKind, prompt) {
|
|
191
|
+
switch (operationKind) {
|
|
192
|
+
case "ask":
|
|
193
|
+
return strippedOrUndefined(prompt, askPromptSubject(prompt));
|
|
194
|
+
case "rescue":
|
|
195
|
+
return strippedOrUndefined(prompt, stripRescuePromptPrefix(prompt));
|
|
196
|
+
case "pursue":
|
|
197
|
+
return uniqueInversion(prompt, [undefined, ...numbersAfter(prompt, /at most (\d+) turns/g)]
|
|
198
|
+
.map((turns) => (task) => buildGoalPrompt(task, turns)));
|
|
199
|
+
case "swarm":
|
|
200
|
+
case "swarm-write": {
|
|
201
|
+
const build = operationKind === "swarm" ? buildSwarmPrompt : buildSwarmWritePrompt;
|
|
202
|
+
const caps = [undefined, ...numbersAfter(prompt, /at most (\d+) subagents/g)];
|
|
203
|
+
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))));
|
|
205
|
+
}
|
|
206
|
+
case "review":
|
|
207
|
+
case "challenge":
|
|
208
|
+
return reviewTaskText(prompt);
|
|
209
|
+
default:
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function strippedOrUndefined(prompt, stripped) {
|
|
214
|
+
return stripped !== prompt && stripped.trim() ? stripped : undefined;
|
|
215
|
+
}
|
|
216
|
+
function numbersAfter(prompt, pattern) {
|
|
217
|
+
return [...new Set([...prompt.matchAll(pattern)].map((match) => Number(match[1])))];
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Split each candidate template around the task slot and require an exact
|
|
221
|
+
* rebuild. The template explaining the most prompt text wins (without --turns
|
|
222
|
+
* the turn guidance would otherwise read as objective); a tie is ambiguous.
|
|
223
|
+
*/
|
|
224
|
+
function uniqueInversion(prompt, builders) {
|
|
225
|
+
let found = new Set();
|
|
226
|
+
let bestTemplate = -1;
|
|
227
|
+
for (const build of builders) {
|
|
228
|
+
try {
|
|
229
|
+
const template = build(TASK_SLOT);
|
|
230
|
+
const at = template.indexOf(TASK_SLOT);
|
|
231
|
+
if (at < 0)
|
|
232
|
+
continue;
|
|
233
|
+
const head = template.slice(0, at);
|
|
234
|
+
const tail = template.slice(at + TASK_SLOT.length);
|
|
235
|
+
if (prompt.length < head.length + tail.length || !prompt.startsWith(head) || !prompt.endsWith(tail))
|
|
236
|
+
continue;
|
|
237
|
+
const task = prompt.slice(head.length, prompt.length - tail.length);
|
|
238
|
+
if (!task.trim() || build(task) !== prompt || head.length + tail.length < bestTemplate)
|
|
239
|
+
continue;
|
|
240
|
+
if (head.length + tail.length > bestTemplate)
|
|
241
|
+
found = new Set();
|
|
242
|
+
bestTemplate = head.length + tail.length;
|
|
243
|
+
found.add(task);
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return found.size === 1 ? [...found][0] : undefined;
|
|
250
|
+
}
|
|
251
|
+
// Mirrors the review/challenge preview built at the review.ts sync call; the
|
|
252
|
+
// review command tests pin the two against real submitted prompts.
|
|
253
|
+
const REVIEW_PROMPT_START = "Perform a read-only code review of the supplied repository changes.\n";
|
|
254
|
+
const REVIEW_TARGET_LINES = /\n\nTarget: (current working tree changes|branch diff against [^\n]+)\nScope: (?:branch diff only; all working-tree changes are out of scope|current working tree, including tracked and untracked changes)\nRepository root: /;
|
|
255
|
+
const REVIEW_FOCUS_LINE = "\nReview focus: ";
|
|
256
|
+
function reviewTaskText(prompt) {
|
|
257
|
+
if (!prompt.startsWith(REVIEW_PROMPT_START))
|
|
258
|
+
return undefined;
|
|
259
|
+
const target = REVIEW_TARGET_LINES.exec(prompt);
|
|
260
|
+
if (!target)
|
|
261
|
+
return undefined;
|
|
262
|
+
const header = prompt.slice(0, target.index);
|
|
263
|
+
const focusAt = header.indexOf(REVIEW_FOCUS_LINE);
|
|
264
|
+
const focus = focusAt < 0 ? undefined : header.slice(focusAt + REVIEW_FOCUS_LINE.length);
|
|
265
|
+
return `Review target: ${target[1]}${focus ? `. Focus: ${focus}` : ""}`;
|
|
266
|
+
}
|