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
|
@@ -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
|
+
}
|
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
|
@@ -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
|
+
}
|
package/dist/commands/rescue.js
CHANGED
|
@@ -16,10 +16,9 @@ import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
|
|
|
16
16
|
import { parseRescueArgs } from "../parsing.js";
|
|
17
17
|
import { readArtifact, renderManagedJobOutput, writeArtifact } from "../render.js";
|
|
18
18
|
import { startBackgroundJob } from "../background-spawn.js";
|
|
19
|
-
import {
|
|
20
|
-
import { warnInheritedBudget, captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes } from "./cli-helpers.js";
|
|
19
|
+
import { warnInheritedBudget, captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes, resolveResumeSession, resumeBudget, hookRefusal } from "./cli-helpers.js";
|
|
21
20
|
import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
|
|
22
|
-
|
|
21
|
+
import { shorten } from "../util.js";
|
|
23
22
|
// "Continue working on the bug" verbs that auto-attach to the latest
|
|
24
23
|
// rescue session. Documented UX trap: a prompt matching this pattern
|
|
25
24
|
// will resume the most recent rescue session regardless of whether
|
|
@@ -51,12 +50,13 @@ export async function runRescue(argv, context) {
|
|
|
51
50
|
const store = new JobStore(paths);
|
|
52
51
|
try {
|
|
53
52
|
await sweepStaleJobs(store, paths);
|
|
54
|
-
const sessionResolution = await resolveRescueSession(store, repoIdentity.repoId, parsed
|
|
53
|
+
const sessionResolution = await resolveRescueSession(store, repoIdentity.repoId, parsed);
|
|
55
54
|
const prompt = buildRescuePrompt(parsed.prompt, sessionResolution.reusedSession);
|
|
56
55
|
const executionPlan = await prepareKimiExecutionPlan({
|
|
57
56
|
operationKind: "rescue",
|
|
58
57
|
cwd: context.cwd,
|
|
59
58
|
env: context.env,
|
|
59
|
+
stderr: context.stderr,
|
|
60
60
|
resumedFromJobId: sessionResolution.resumedFromJobId,
|
|
61
61
|
resumeSessionId: sessionResolution.kimiSessionId ?? undefined,
|
|
62
62
|
resumeSource: sessionResolution.sourceJob,
|
|
@@ -72,9 +72,7 @@ export async function runRescue(argv, context) {
|
|
|
72
72
|
thinking: null,
|
|
73
73
|
thinking_effort: parsed.thinkingEffort ?? null,
|
|
74
74
|
background: parsed.background,
|
|
75
|
-
|
|
76
|
-
budget_source: parsed.budgetMs !== undefined ? "explicit"
|
|
77
|
-
: sessionResolution.sourceJob?.operation_kind === "rescue" && sessionResolution.sourceJob.budget_ms !== null ? "inherited" : "default",
|
|
75
|
+
...resumeBudget("rescue", parsed.budgetMs, sessionResolution.sourceJob),
|
|
78
76
|
pid: parsed.background ? null : process.pid,
|
|
79
77
|
kimi_pid: null,
|
|
80
78
|
status: "running",
|
|
@@ -106,16 +104,7 @@ export async function runRescue(argv, context) {
|
|
|
106
104
|
return startBackgroundJob(job, prompt, context, paths, {
|
|
107
105
|
workerKind: "rescue",
|
|
108
106
|
wait: parsed.wait,
|
|
109
|
-
promptEnvVar: "KIMI_PLUGIN_CC_RESCUE_PROMPT_B64",
|
|
110
|
-
reusedSessionEnvVar: "KIMI_PLUGIN_CC_RESCUE_REUSED_SESSION",
|
|
111
|
-
reusedSession: sessionResolution.reusedSession,
|
|
112
107
|
failedSummary: rescueConfig.cancellation.failedSummary,
|
|
113
|
-
missingResultErrorCode: "RESCUE_RESULT_MISSING",
|
|
114
|
-
spawnFailedErrorCode: "RESCUE_WORKER_SPAWN_FAILED",
|
|
115
|
-
earlyExitErrorCode: "RESCUE_WORKER_EXITED_EARLY",
|
|
116
|
-
nodeBinInvalidErrorCode: "RESCUE_NODE_BIN_INVALID",
|
|
117
|
-
waitStage: "rescue.wait",
|
|
118
|
-
spawnStage: "rescue.worker.spawn",
|
|
119
108
|
});
|
|
120
109
|
}
|
|
121
110
|
const completed = await executeRescueJob(job.job_id, prompt, context);
|
|
@@ -147,16 +136,8 @@ export async function executeRescueJob(jobId, prompt, context, options) {
|
|
|
147
136
|
// an early return doesn't leak SIGTERM/SIGINT listeners. Tests /
|
|
148
137
|
// setup probes / intentional bypass: KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1.
|
|
149
138
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
maybeWarnHookMissing(installStatus, "rescue", context.stderr);
|
|
153
|
-
const classified = new RuntimeError("RESCUE_HOOK_NOT_INSTALLED", [
|
|
154
|
-
"rescue refuses to run without the kimi-plugin-cc PreToolUse hook.",
|
|
155
|
-
`Hook check failed: ${installStatus.reason ?? "unknown"}.`,
|
|
156
|
-
"Repair by running Claude Code /kimi:setup or Codex $kimi-setup, then retry.",
|
|
157
|
-
"KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 is only for deliberate tests or diagnostics.",
|
|
158
|
-
hookRefusalRetryProtocol(context.env),
|
|
159
|
-
].join(" "), "rescue.hook-check", { details: hookRefusalDetails(installStatus) });
|
|
139
|
+
const classified = await hookRefusal(context, "rescue");
|
|
140
|
+
if (classified) {
|
|
160
141
|
try {
|
|
161
142
|
return await markJobFailed(store, paths, job, classified, cancel.failedSummary, { phase: "failed" });
|
|
162
143
|
}
|
|
@@ -207,7 +188,7 @@ export async function executeRescueJob(jobId, prompt, context, options) {
|
|
|
207
188
|
store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
|
|
208
189
|
}
|
|
209
190
|
await syncKimiSessionTitle({
|
|
210
|
-
promptText: prompt,
|
|
191
|
+
promptText: stripRescuePromptPrefix(prompt),
|
|
211
192
|
env: context.env,
|
|
212
193
|
cwd: job.cwd,
|
|
213
194
|
sessionId: result.sessionId ?? job.kimi_session_id,
|
|
@@ -276,50 +257,11 @@ function buildRescuePrompt(prompt, reusedSession) {
|
|
|
276
257
|
}
|
|
277
258
|
throw new RuntimeError("INVALID_ARGS", "rescue requires a task description.", "rescue.parse");
|
|
278
259
|
}
|
|
279
|
-
function stripRescuePromptPrefix(prompt) {
|
|
260
|
+
export function stripRescuePromptPrefix(prompt) {
|
|
280
261
|
return prompt.startsWith(RESCUE_PROMPT_PREFIX) ? prompt.slice(RESCUE_PROMPT_PREFIX.length) : prompt;
|
|
281
262
|
}
|
|
282
|
-
async function resolveRescueSession(store, repoId,
|
|
283
|
-
if (fresh) {
|
|
284
|
-
return { kimiSessionId: null, reusedSession: false, resumedFromJobId: null, sourceJob: null };
|
|
285
|
-
}
|
|
286
|
-
if (resumeTarget) {
|
|
287
|
-
const byJob = store.getJob(resumeTarget);
|
|
288
|
-
const scoped = byJob?.repo_id === repoId && byJob.command_type === "rescue" ? byJob : null;
|
|
289
|
-
const exact = scoped ?? store.findRescueJobBySession(repoId, resumeTarget);
|
|
290
|
-
if (!exact) {
|
|
291
|
-
throw new RuntimeError("RESCUE_RESUME_NOT_FOUND", `No rescue job or session matched ${resumeTarget}.`, "rescue.resume");
|
|
292
|
-
}
|
|
293
|
-
const source = await reconcileHistoricalJobProvenance(store, exact);
|
|
294
|
-
ensureSessionIsNotRunning(source);
|
|
295
|
-
if (!source.kimi_session_id) {
|
|
296
|
-
throw new RuntimeError("RESCUE_RESUME_NOT_FOUND", `No rescue job or session matched ${resumeTarget}.`, "rescue.resume");
|
|
297
|
-
}
|
|
298
|
-
return {
|
|
299
|
-
kimiSessionId: source.kimi_session_id,
|
|
300
|
-
reusedSession: true,
|
|
301
|
-
resumedFromJobId: source.job_id,
|
|
302
|
-
sourceJob: source,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
if (resume) {
|
|
306
|
-
const latest = store.findLatestJob({ repoId, commandType: "rescue" });
|
|
307
|
-
if (!latest) {
|
|
308
|
-
throw new RuntimeError("RESCUE_RESUME_NOT_FOUND", "No prior rescue session exists for this repository.", "rescue.resume");
|
|
309
|
-
}
|
|
310
|
-
const source = await reconcileHistoricalJobProvenance(store, latest);
|
|
311
|
-
ensureSessionIsNotRunning(source);
|
|
312
|
-
if (!source.kimi_session_id) {
|
|
313
|
-
throw new RuntimeError("RESCUE_RESUME_NOT_FOUND", "No prior rescue session exists for this repository.", "rescue.resume");
|
|
314
|
-
}
|
|
315
|
-
return {
|
|
316
|
-
kimiSessionId: source.kimi_session_id,
|
|
317
|
-
reusedSession: true,
|
|
318
|
-
resumedFromJobId: source.job_id,
|
|
319
|
-
sourceJob: source,
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
if (prompt && AUTO_RESUME_PATTERN.test(prompt)) {
|
|
263
|
+
async function resolveRescueSession(store, repoId, parsed) {
|
|
264
|
+
if (!parsed.fresh && !parsed.resumeTarget && !parsed.resume && parsed.prompt && AUTO_RESUME_PATTERN.test(parsed.prompt)) {
|
|
323
265
|
const latest = store.findLatestJob({ repoId, commandType: "rescue" });
|
|
324
266
|
if (latest?.kimi_session_id && latest.status !== "running") {
|
|
325
267
|
const source = await reconcileHistoricalJobProvenance(store, latest);
|
|
@@ -331,17 +273,5 @@ async function resolveRescueSession(store, repoId, prompt, fresh, resume, resume
|
|
|
331
273
|
};
|
|
332
274
|
}
|
|
333
275
|
}
|
|
334
|
-
return
|
|
335
|
-
}
|
|
336
|
-
function ensureSessionIsNotRunning(job) {
|
|
337
|
-
if (job.status === "running") {
|
|
338
|
-
throw new RuntimeError("RESCUE_ALREADY_RUNNING", `Rescue session ${job.kimi_session_id ?? "<unknown>"} is already active under job ${job.job_id}.`, "rescue.resume");
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
function shorten(text, max) {
|
|
342
|
-
const normalized = text.replace(/\s+/g, " ").trim();
|
|
343
|
-
if (normalized.length <= max) {
|
|
344
|
-
return normalized;
|
|
345
|
-
}
|
|
346
|
-
return `${normalized.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
|
|
276
|
+
return resolveResumeSession(store, "rescue", repoId, parsed);
|
|
347
277
|
}
|
package/dist/commands/result.js
CHANGED
|
@@ -2,7 +2,7 @@ import { RuntimeError } from "../errors.js";
|
|
|
2
2
|
import { resolveRepoIdentity } from "../git.js";
|
|
3
3
|
import { sweepStaleJobs } from "../jobs.js";
|
|
4
4
|
import { reconcileHistoricalJobProvenance } from "../kimi-engine.js";
|
|
5
|
-
import { renderBudgetSource, withJobStore, parseHookEscapes } from "../job-store.js";
|
|
5
|
+
import { parseJobWarnings, renderBudgetSource, withJobStore, parseHookEscapes } from "../job-store.js";
|
|
6
6
|
import { ensurePluginPaths, resolvePluginPaths } from "../paths.js";
|
|
7
7
|
import { parseJobLookupArgs } from "../parsing.js";
|
|
8
8
|
import { readArtifact, renderTerminalJobArtifact } from "../render.js";
|
|
@@ -62,5 +62,11 @@ function renderResultEnvelope(job, artifactPath, body) {
|
|
|
62
62
|
kimi_version: job.kimi_version,
|
|
63
63
|
system_version: job.system_version,
|
|
64
64
|
resumed_from_job_id: job.resumed_from_job_id,
|
|
65
|
+
...warningsField(job),
|
|
65
66
|
}, null, 2)}\n`;
|
|
66
67
|
}
|
|
68
|
+
/** Present only when the job carries warnings, so warning-free envelopes are unchanged. */
|
|
69
|
+
function warningsField(job) {
|
|
70
|
+
const warnings = parseJobWarnings(job.warnings);
|
|
71
|
+
return warnings.length > 0 ? { warnings } : {};
|
|
72
|
+
}
|
|
@@ -127,6 +127,7 @@ async function executeReviewGate(payload, assistantMessage, context) {
|
|
|
127
127
|
operationKind: "review_gate",
|
|
128
128
|
cwd: payload.cwd,
|
|
129
129
|
env: context.env,
|
|
130
|
+
stderr: context.stderr,
|
|
130
131
|
});
|
|
131
132
|
// Header-before-job-row mirrors v0.4's reordering (the comment
|
|
132
133
|
// chain there explains why). If the disk-bound writeInvocationLogHeader
|
package/dist/commands/review.js
CHANGED
|
@@ -13,11 +13,11 @@ import { KIMI_REVIEW_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 { parseReviewArgs } from "../parsing.js";
|
|
16
|
+
import { assertScopeSupported, resolveReadScope, serializeReadScope } from "../read-scope.js";
|
|
16
17
|
import { renderManagedJobOutput, writeArtifact } from "../render.js";
|
|
17
18
|
import { RuntimeError } from "../errors.js";
|
|
18
19
|
import { resolveRepoIdentity } from "../git.js";
|
|
19
|
-
import {
|
|
20
|
-
import { captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes } from "./cli-helpers.js";
|
|
20
|
+
import { captureTimeoutPartialOutput, assertCliResultSuccess, reassembleProseFromRecords, warnIfSessionIdMissing, warnHookEscapes, hookRefusal } from "./cli-helpers.js";
|
|
21
21
|
import { buildKimiSessionTitle, syncKimiSessionTitle } from "../session-title.js";
|
|
22
22
|
const REVIEW_AGENT_PROFILE_PLACEHOLDER = "<cli-client>";
|
|
23
23
|
export async function runReview(argv, context, commandType) {
|
|
@@ -25,6 +25,8 @@ export async function runReview(argv, context, commandType) {
|
|
|
25
25
|
if (parsed.background || parsed.wait) {
|
|
26
26
|
throw new RuntimeError("INVALID_FLAGS", `${commandType} does not support --background or --wait in v1; review runs foreground-synchronously.`, `${commandType}.parse`);
|
|
27
27
|
}
|
|
28
|
+
const readScope = parsed.readRoots === undefined && parsed.network === undefined ? undefined
|
|
29
|
+
: await resolveReadScope(parsed.readRoots, parsed.network, `${commandType}.parse`);
|
|
28
30
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK !== "1") {
|
|
29
31
|
await requireReadOnlyHookInstalled(context, commandType);
|
|
30
32
|
}
|
|
@@ -36,7 +38,9 @@ export async function runReview(argv, context, commandType) {
|
|
|
36
38
|
operationKind: commandType,
|
|
37
39
|
cwd: context.cwd,
|
|
38
40
|
env: context.env,
|
|
41
|
+
stderr: context.stderr,
|
|
39
42
|
});
|
|
43
|
+
assertScopeSupported(readScope, executionPlan.certification, "INVALID_ARGS", `${commandType}.parse`);
|
|
40
44
|
const store = new JobStore(paths);
|
|
41
45
|
const jobId = allocateJobId(context);
|
|
42
46
|
// Leave kimi_session_id NULL until kimi announces an actual ID; never invent
|
|
@@ -52,6 +56,7 @@ export async function runReview(argv, context, commandType) {
|
|
|
52
56
|
model: parsed.model ?? null,
|
|
53
57
|
thinking: null,
|
|
54
58
|
thinking_effort: parsed.thinkingEffort ?? null,
|
|
59
|
+
read_scope: serializeReadScope(readScope),
|
|
55
60
|
background: false,
|
|
56
61
|
budget_ms: parsed.budgetMs ?? null,
|
|
57
62
|
budget_source: parsed.budgetMs !== undefined ? "explicit" : "default",
|
|
@@ -87,6 +92,7 @@ export async function runReview(argv, context, commandType) {
|
|
|
87
92
|
commandLabel: commandType,
|
|
88
93
|
model: parsed.model,
|
|
89
94
|
thinkingEffort: parsed.thinkingEffort,
|
|
95
|
+
readScope,
|
|
90
96
|
logPath,
|
|
91
97
|
onSpawn: (pid) => { store.updateRunningJob(job.job_id, { kimi_pid: pid }); },
|
|
92
98
|
signal: handlers.signal,
|
|
@@ -105,7 +111,7 @@ export async function runReview(argv, context, commandType) {
|
|
|
105
111
|
store.updateRunningJob(job.job_id, { kimi_session_id_source: "announced", kimi_session_id: result.sessionId });
|
|
106
112
|
}
|
|
107
113
|
await syncKimiSessionTitle({
|
|
108
|
-
promptText:
|
|
114
|
+
promptText: `Review target: ${reviewContext.targetDescription}${parsed.focus ? `. Focus: ${parsed.focus}` : ""}`,
|
|
109
115
|
env: context.env,
|
|
110
116
|
cwd: job.cwd,
|
|
111
117
|
sessionId: result.sessionId ?? job.kimi_session_id,
|
|
@@ -152,18 +158,9 @@ async function requireReadOnlyHookInstalled(context, commandType) {
|
|
|
152
158
|
if (context.env.KIMI_PLUGIN_CC_SKIP_HOOK_CHECK === "1") {
|
|
153
159
|
return;
|
|
154
160
|
}
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
maybeWarnHookMissing(installStatus, commandType, context.stderr);
|
|
160
|
-
throw new RuntimeError(`${commandType.toUpperCase()}_HOOK_NOT_INSTALLED`, [
|
|
161
|
-
`${commandType} refuses to run without the canonical kimi-plugin-cc PreToolUse hook.`,
|
|
162
|
-
`Hook check failed: ${installStatus.reason ?? "unknown"}.`,
|
|
163
|
-
"Run /kimi:setup or $kimi-setup to install or repair this host's managed block.",
|
|
164
|
-
"Set KIMI_PLUGIN_CC_SKIP_HOOK_CHECK=1 only if you intentionally accept un-enforced execution.",
|
|
165
|
-
hookRefusalRetryProtocol(context.env),
|
|
166
|
-
].join(" "), `${commandType}.hook-check`, { details: hookRefusalDetails(installStatus) });
|
|
161
|
+
const refusal = await hookRefusal(context, commandType);
|
|
162
|
+
if (refusal)
|
|
163
|
+
throw refusal;
|
|
167
164
|
}
|
|
168
165
|
function buildReviewPrompt(commandType, reviewContext, focus) {
|
|
169
166
|
const modeInstructions = commandType === "challenge"
|