kimi-plugin-cc 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +3 -14
- package/README.md +428 -572
- package/assets/logo.svg +6 -0
- package/cordis.patch.yml +18 -0
- package/dist/background-spawn.js +4 -2
- package/dist/cli-client.js +105 -66
- package/dist/commands/ask.js +27 -12
- package/dist/commands/cancel.js +4 -13
- package/dist/commands/cli-helpers.js +1 -1
- package/dist/commands/pursue.js +3 -2
- package/dist/commands/registry.js +7 -26
- package/dist/commands/repair-sessions.js +7 -4
- package/dist/commands/replay.js +4 -3
- package/dist/commands/rescue.js +17 -5
- package/dist/commands/review.js +18 -5
- package/dist/commands/setup.js +277 -262
- package/dist/commands/swarm.js +20 -7
- package/dist/companion.js +142 -18
- package/dist/help.js +11 -7
- package/dist/hook-escape.js +7 -16
- package/dist/hooks/approval-hook.js +1762 -124
- package/dist/hooks/approval-policy.js +15 -10
- package/dist/hooks/config-safety.js +15 -24
- package/dist/hooks/hook-timing.js +1 -1
- package/dist/hooks/install-paths.js +179 -107
- package/dist/hooks/install.js +44 -166
- package/dist/hooks/managed-block.js +44 -95
- package/dist/job-store.js +117 -49
- package/dist/jobs.js +53 -1
- package/dist/kimi-engine.js +68 -92
- package/dist/kimi-errors.js +1 -1
- package/dist/kimi-journal.js +3 -2
- package/dist/kimi-releases.js +28 -49
- package/dist/kimi-timeouts.js +1 -15
- package/dist/kimi-version-probe.js +24 -72
- package/dist/logging.js +12 -7
- package/dist/mcp/binding.js +13 -4
- package/dist/mcp/job-control.js +386 -89
- package/dist/mcp/launcher.js +1 -1
- package/dist/mcp/operations.js +387 -193
- package/dist/mcp/protocol.js +116 -27
- package/dist/mcp/skills.js +130 -0
- package/dist/mcp/stdio.js +15 -2
- package/dist/native-v2-preflight.js +127 -35
- package/dist/parsing.js +45 -11
- package/dist/paths.js +20 -10
- package/dist/plugin-data.js +28 -83
- package/dist/read-scope.js +2 -2
- package/dist/render.js +13 -38
- package/dist/session-references.js +216 -0
- package/dist/session-title.js +1 -1
- package/dist/surface-routing.js +92 -5
- package/dist/swarm-activation.js +26 -137
- package/dist/version.js +1 -1
- package/docs/migration.md +45 -227
- package/docs/models.md +24 -66
- package/docs/safety.md +195 -400
- package/docs/session-visibility.md +24 -14
- package/docs/swarm-recovery.md +26 -20
- package/dsh/index.json +54 -0
- package/mcp_config.json +10 -0
- package/package.json +23 -82
- package/plugin.json +19 -0
- package/plugins/kimi-codex/.codex-plugin/plugin.json +7 -7
- package/plugins/kimi-codex/.mcp.json +2 -3
- package/plugins/kimi-codex/dist/background-spawn.js +4 -2
- package/plugins/kimi-codex/dist/cli-client.js +105 -66
- package/plugins/kimi-codex/dist/commands/ask.js +27 -12
- package/plugins/kimi-codex/dist/commands/cancel.js +4 -13
- package/plugins/kimi-codex/dist/commands/cli-helpers.js +1 -1
- package/plugins/kimi-codex/dist/commands/pursue.js +3 -2
- package/plugins/kimi-codex/dist/commands/registry.js +7 -26
- package/plugins/kimi-codex/dist/commands/repair-sessions.js +7 -4
- package/plugins/kimi-codex/dist/commands/replay.js +4 -3
- package/plugins/kimi-codex/dist/commands/rescue.js +17 -5
- package/plugins/kimi-codex/dist/commands/review.js +18 -5
- package/plugins/kimi-codex/dist/commands/setup.js +277 -262
- package/plugins/kimi-codex/dist/commands/swarm.js +20 -7
- package/plugins/kimi-codex/dist/companion.js +142 -18
- package/plugins/kimi-codex/dist/help.js +11 -7
- package/plugins/kimi-codex/dist/hook-escape.js +7 -16
- package/plugins/kimi-codex/dist/hooks/approval-hook.js +1762 -124
- package/plugins/kimi-codex/dist/hooks/approval-policy.js +15 -10
- package/plugins/kimi-codex/dist/hooks/config-safety.js +15 -24
- package/plugins/kimi-codex/dist/hooks/hook-timing.js +1 -1
- package/plugins/kimi-codex/dist/hooks/install-paths.js +179 -107
- package/plugins/kimi-codex/dist/hooks/install.js +44 -166
- package/plugins/kimi-codex/dist/hooks/managed-block.js +44 -95
- package/plugins/kimi-codex/dist/job-store.js +117 -49
- package/plugins/kimi-codex/dist/jobs.js +53 -1
- package/plugins/kimi-codex/dist/kimi-engine.js +68 -92
- package/plugins/kimi-codex/dist/kimi-errors.js +1 -1
- package/plugins/kimi-codex/dist/kimi-journal.js +3 -2
- package/plugins/kimi-codex/dist/kimi-releases.js +28 -49
- package/plugins/kimi-codex/dist/kimi-timeouts.js +1 -15
- package/plugins/kimi-codex/dist/kimi-version-probe.js +24 -72
- package/plugins/kimi-codex/dist/logging.js +12 -7
- package/plugins/kimi-codex/dist/mcp/binding.js +13 -4
- package/plugins/kimi-codex/dist/mcp/job-control.js +386 -89
- package/plugins/kimi-codex/dist/mcp/launcher.js +1 -1
- package/plugins/kimi-codex/dist/mcp/operations.js +387 -193
- package/plugins/kimi-codex/dist/mcp/protocol.js +116 -27
- package/plugins/kimi-codex/dist/mcp/skills.js +130 -0
- package/plugins/kimi-codex/dist/mcp/stdio.js +15 -2
- package/plugins/kimi-codex/dist/native-v2-preflight.js +127 -35
- package/plugins/kimi-codex/dist/parsing.js +45 -11
- package/plugins/kimi-codex/dist/paths.js +20 -10
- package/plugins/kimi-codex/dist/plugin-data.js +28 -83
- package/plugins/kimi-codex/dist/read-scope.js +2 -2
- package/plugins/kimi-codex/dist/render.js +13 -38
- package/plugins/kimi-codex/dist/session-references.js +216 -0
- package/plugins/kimi-codex/dist/session-title.js +1 -1
- package/plugins/kimi-codex/dist/surface-routing.js +92 -5
- package/plugins/kimi-codex/dist/swarm-activation.js +26 -137
- package/plugins/kimi-codex/dist/version.js +1 -1
- package/plugins/kimi-codex/scripts/companion.sh +4 -15
- package/plugins/kimi-codex/skills/kimi/SKILL.md +77 -0
- package/plugins/kimi-codex/skills/kimi/agents/openai.yaml +6 -0
- package/scripts/companion.sh +4 -15
- package/skills/kimi/SKILL.md +77 -0
- package/skills/kimi/agents/openai.yaml +6 -0
- package/CHANGELOG.md +0 -1402
- package/agents/kimi-pursue.md +0 -93
- package/agents/kimi-review.md +0 -86
- package/agents/kimi-swarm.md +0 -88
- package/agents/kimi-task.md +0 -93
- package/commands/README.md +0 -14
- package/commands/cancel.md +0 -17
- package/commands/pursue.md +0 -41
- package/commands/replay.md +0 -13
- package/commands/result.md +0 -13
- package/commands/review.md +0 -40
- package/commands/setup.md +0 -25
- package/commands/status.md +0 -13
- package/commands/swarm.md +0 -45
- package/commands/task.md +0 -40
- package/dist/commands/review-gate.js +0 -391
- package/dist/config.js +0 -22
- package/dist/dsh/companion.js +0 -177
- package/dist/dsh/index.js +0 -167
- package/dist/hooks/review-gate-stop.js +0 -19
- package/dist/schemas/review-gate-output.js +0 -41
- package/docs/registry-releases.md +0 -228
- package/docs/upstream-2.4.1-certification.md +0 -54
- package/docs/upstream-2.5.0-certification.md +0 -52
- package/docs/upstream-2.5.1-certification.md +0 -47
- package/docs/upstream-2.5.2-certification.md +0 -40
- package/docs/upstream-2.5.3-certification.md +0 -73
- package/docs/upstream-2.6.0-certification.md +0 -65
- package/docs/upstream-2.6.2-certification.md +0 -144
- package/docs/upstream-2.6.3-certification.md +0 -100
- package/docs/upstream-2.7.2-certification.md +0 -113
- package/docs/upstream-2.7.3-certification.md +0 -95
- package/docs/windows-validation.md +0 -39
- package/hooks/README.md +0 -9
- package/hooks/hooks.json +0 -16
- package/plugins/kimi-codex/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-codex/dist/config.js +0 -22
- package/plugins/kimi-codex/dist/dsh/companion.js +0 -177
- package/plugins/kimi-codex/dist/dsh/index.js +0 -167
- package/plugins/kimi-codex/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-codex/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-codex/scripts/review-gate-hook.sh +0 -32
- package/plugins/kimi-codex/skills/kimi-cancel/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-cancel/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-pursue/SKILL.md +0 -32
- package/plugins/kimi-codex/skills/kimi-pursue/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-replay/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-replay/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-result/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-result/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-review/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-review/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-setup/SKILL.md +0 -35
- package/plugins/kimi-codex/skills/kimi-setup/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-status/SKILL.md +0 -25
- package/plugins/kimi-codex/skills/kimi-status/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-swarm/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-swarm/agents/openai.yaml +0 -6
- package/plugins/kimi-codex/skills/kimi-task/SKILL.md +0 -37
- package/plugins/kimi-codex/skills/kimi-task/agents/openai.yaml +0 -6
- package/plugins/kimi-dsh/LICENSE +0 -201
- package/plugins/kimi-dsh/README.md +0 -84
- package/plugins/kimi-dsh/cordis.patch.yml +0 -45
- package/plugins/kimi-dsh/dist/background-spawn.js +0 -209
- package/plugins/kimi-dsh/dist/cli-cancellation.js +0 -43
- package/plugins/kimi-dsh/dist/cli-client.js +0 -1097
- package/plugins/kimi-dsh/dist/commands/ask.js +0 -269
- package/plugins/kimi-dsh/dist/commands/cancel.js +0 -177
- package/plugins/kimi-dsh/dist/commands/cli-helpers.js +0 -302
- package/plugins/kimi-dsh/dist/commands/models.js +0 -139
- package/plugins/kimi-dsh/dist/commands/pursue.js +0 -293
- package/plugins/kimi-dsh/dist/commands/recover-swarm.js +0 -140
- package/plugins/kimi-dsh/dist/commands/registry.js +0 -74
- package/plugins/kimi-dsh/dist/commands/repair-sessions.js +0 -266
- package/plugins/kimi-dsh/dist/commands/replay.js +0 -124
- package/plugins/kimi-dsh/dist/commands/rescue.js +0 -277
- package/plugins/kimi-dsh/dist/commands/result.js +0 -72
- package/plugins/kimi-dsh/dist/commands/review-gate.js +0 -391
- package/plugins/kimi-dsh/dist/commands/review.js +0 -217
- package/plugins/kimi-dsh/dist/commands/setup.js +0 -1465
- package/plugins/kimi-dsh/dist/commands/status.js +0 -27
- package/plugins/kimi-dsh/dist/commands/swarm.js +0 -823
- package/plugins/kimi-dsh/dist/commands/worker.js +0 -24
- package/plugins/kimi-dsh/dist/companion.js +0 -99
- package/plugins/kimi-dsh/dist/config.js +0 -22
- package/plugins/kimi-dsh/dist/dsh/companion.js +0 -177
- package/plugins/kimi-dsh/dist/dsh/index.js +0 -167
- package/plugins/kimi-dsh/dist/errors.js +0 -40
- package/plugins/kimi-dsh/dist/git.js +0 -216
- package/plugins/kimi-dsh/dist/help.js +0 -43
- package/plugins/kimi-dsh/dist/hook-escape.js +0 -71
- package/plugins/kimi-dsh/dist/hooks/approval-hook.js +0 -145
- package/plugins/kimi-dsh/dist/hooks/approval-policy.js +0 -295
- package/plugins/kimi-dsh/dist/hooks/config-safety.js +0 -641
- package/plugins/kimi-dsh/dist/hooks/hook-timing.js +0 -48
- package/plugins/kimi-dsh/dist/hooks/install-paths.js +0 -428
- package/plugins/kimi-dsh/dist/hooks/install.js +0 -405
- package/plugins/kimi-dsh/dist/hooks/managed-block.js +0 -729
- package/plugins/kimi-dsh/dist/hooks/review-gate-stop.js +0 -19
- package/plugins/kimi-dsh/dist/job-id.js +0 -12
- package/plugins/kimi-dsh/dist/job-store.js +0 -631
- package/plugins/kimi-dsh/dist/jobs.js +0 -212
- package/plugins/kimi-dsh/dist/kimi-command.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-engine.js +0 -770
- package/plugins/kimi-dsh/dist/kimi-errors.js +0 -205
- package/plugins/kimi-dsh/dist/kimi-home.js +0 -15
- package/plugins/kimi-dsh/dist/kimi-journal.js +0 -41
- package/plugins/kimi-dsh/dist/kimi-releases.js +0 -144
- package/plugins/kimi-dsh/dist/kimi-timeouts.js +0 -52
- package/plugins/kimi-dsh/dist/kimi-version-probe.js +0 -198
- package/plugins/kimi-dsh/dist/logging.js +0 -22
- package/plugins/kimi-dsh/dist/mcp/binding.js +0 -58
- package/plugins/kimi-dsh/dist/mcp/job-control.js +0 -343
- package/plugins/kimi-dsh/dist/mcp/launcher.js +0 -263
- package/plugins/kimi-dsh/dist/mcp/operations.js +0 -333
- package/plugins/kimi-dsh/dist/mcp/protocol.js +0 -277
- package/plugins/kimi-dsh/dist/mcp/server.js +0 -8
- package/plugins/kimi-dsh/dist/mcp/stdio.js +0 -79
- package/plugins/kimi-dsh/dist/mcp/supervised-child.js +0 -15
- package/plugins/kimi-dsh/dist/mcp/tool-result.js +0 -7
- package/plugins/kimi-dsh/dist/mcp/workspace.js +0 -34
- package/plugins/kimi-dsh/dist/model-command.js +0 -34
- package/plugins/kimi-dsh/dist/native-v2-preflight.js +0 -596
- package/plugins/kimi-dsh/dist/package.json +0 -1
- package/plugins/kimi-dsh/dist/parsing.js +0 -554
- package/plugins/kimi-dsh/dist/paths.js +0 -35
- package/plugins/kimi-dsh/dist/plugin-data.js +0 -98
- package/plugins/kimi-dsh/dist/process-tree.js +0 -597
- package/plugins/kimi-dsh/dist/prompt-size.js +0 -18
- package/plugins/kimi-dsh/dist/read-scope.js +0 -435
- package/plugins/kimi-dsh/dist/render.js +0 -214
- package/plugins/kimi-dsh/dist/rescue-approval.js +0 -1242
- package/plugins/kimi-dsh/dist/schemas/review-gate-output.js +0 -41
- package/plugins/kimi-dsh/dist/session-recovery.js +0 -202
- package/plugins/kimi-dsh/dist/session-title.js +0 -313
- package/plugins/kimi-dsh/dist/stream-json.js +0 -344
- package/plugins/kimi-dsh/dist/surface-routing.js +0 -21
- package/plugins/kimi-dsh/dist/swarm-activation.js +0 -1194
- package/plugins/kimi-dsh/dist/swarm-policy.js +0 -74
- package/plugins/kimi-dsh/dist/swarm-recovery.js +0 -166
- package/plugins/kimi-dsh/dist/swarm-tool-policy.js +0 -146
- package/plugins/kimi-dsh/dist/types.js +0 -1
- package/plugins/kimi-dsh/dist/util.js +0 -28
- package/plugins/kimi-dsh/dist/vendor/shell-quote/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/shell-quote/index.js +0 -1
- package/plugins/kimi-dsh/dist/vendor/shell-quote/parse.js +0 -229
- package/plugins/kimi-dsh/dist/vendor/smol-toml/LICENSE +0 -24
- package/plugins/kimi-dsh/dist/vendor/smol-toml/date.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/error.js +0 -67
- package/plugins/kimi-dsh/dist/vendor/smol-toml/extract.js +0 -293
- package/plugins/kimi-dsh/dist/vendor/smol-toml/parse.js +0 -164
- package/plugins/kimi-dsh/dist/vendor/smol-toml/primitive.js +0 -151
- package/plugins/kimi-dsh/dist/vendor/smol-toml/struct.js +0 -156
- package/plugins/kimi-dsh/dist/vendor/smol-toml/util.js +0 -57
- package/plugins/kimi-dsh/dist/version.js +0 -7
- package/plugins/kimi-dsh/package.json +0 -78
- package/plugins/kimi-dsh/scripts/companion.sh +0 -37
- package/plugins/kimi-dsh/scripts/review-gate-hook.sh +0 -32
- package/scripts/review-gate-hook.sh +0 -32
|
@@ -5,7 +5,11 @@ import { BOUNDED_SWARM_POLICY, evaluateSwarmWaveInput } from "../swarm-policy.js
|
|
|
5
5
|
*
|
|
6
6
|
* Includes kimi-code's own local-read defaults (`Read`, `Grep`, `Glob`)
|
|
7
7
|
* plus a few additional read-safe tools the runtime auto-allows
|
|
8
|
-
* (`ReadMediaFile`, `TaskList`, `TaskOutput`).
|
|
8
|
+
* (`ReadMediaFile`, `TaskList`, `TaskOutput`, `WaitFor`). `WaitFor` waits,
|
|
9
|
+
* up to a schema cap, on background tasks that already exist and can neither
|
|
10
|
+
* start nor stop one; kimi-code's goal guidance tells the model to call it,
|
|
11
|
+
* so denying it cost pursue a wasted call. Only the write labels can have a
|
|
12
|
+
* background task to wait on (docs/invariants.md). Network tools
|
|
9
13
|
* (`WebSearch`, `FetchURL`) are excluded; read-only labels allow them only
|
|
10
14
|
* for a call started with --network, which also confines these reads to the
|
|
11
15
|
* plugin-exported read roots (runtime/read-scope.ts).
|
|
@@ -17,6 +21,7 @@ export const READ_ONLY_TOOLS = new Set([
|
|
|
17
21
|
"ReadMediaFile",
|
|
18
22
|
"TaskList",
|
|
19
23
|
"TaskOutput",
|
|
24
|
+
"WaitFor",
|
|
20
25
|
]);
|
|
21
26
|
/** Web tools: denied unless the plugin exported KIMI_PLUGIN_CC_NETWORK=1 with read roots. */
|
|
22
27
|
const WEB_TOOLS = new Set(["WebSearch", "FetchURL"]);
|
|
@@ -30,13 +35,15 @@ const WEB_TOOLS = new Set(["WebSearch", "FetchURL"]);
|
|
|
30
35
|
*/
|
|
31
36
|
const AGENT_SWARM_TOOL = "AgentSwarm";
|
|
32
37
|
/**
|
|
33
|
-
* agent-core-v2's ONLY chain-breaking final allow is the
|
|
34
|
-
* it fires only while plan mode is ACTIVE. Native v2 is
|
|
35
|
-
* the invariant that plan mode is never armed in a
|
|
36
|
-
* `default_plan_mode` is refused pre-spawn
|
|
37
|
-
* plan-tainted sessions are never resumed,
|
|
38
|
-
* is denied HERE for every label.
|
|
39
|
-
* is explicit rather than a side
|
|
38
|
+
* Through 2.7.3, agent-core-v2's ONLY chain-breaking final allow is the
|
|
39
|
+
* plan-file guard, and it fires only while plan mode is ACTIVE. Native v2 is
|
|
40
|
+
* therefore certified on the invariant that plan mode is never armed in a
|
|
41
|
+
* plugin-managed session: `default_plan_mode` is refused pre-spawn
|
|
42
|
+
* (runtime/native-v2-preflight.ts), plan-tainted sessions are never resumed,
|
|
43
|
+
* and the model-reachable entry tool is denied HERE for every label.
|
|
44
|
+
* ExitPlanMode is denied too so the deny set is explicit rather than a side
|
|
45
|
+
* effect of the read-only allowlists. 2.8.0 runs this hook before the plan
|
|
46
|
+
* guard and has no final allow; the same closures stay on for every release.
|
|
40
47
|
*/
|
|
41
48
|
const PLAN_MODE_TOOLS = new Set(["EnterPlanMode", "ExitPlanMode"]);
|
|
42
49
|
/**
|
|
@@ -48,7 +55,6 @@ const KNOWN_LABELS = new Set([
|
|
|
48
55
|
"ask",
|
|
49
56
|
"review",
|
|
50
57
|
"challenge",
|
|
51
|
-
"review_gate",
|
|
52
58
|
"rescue",
|
|
53
59
|
"swarm",
|
|
54
60
|
"swarm-write",
|
|
@@ -135,7 +141,6 @@ export function decideHookOutcomePure(input, ctx) {
|
|
|
135
141
|
case "ask":
|
|
136
142
|
case "review":
|
|
137
143
|
case "challenge":
|
|
138
|
-
case "review_gate":
|
|
139
144
|
// Read-only narrative surfaces share READ_ONLY_TOOLS. They run as
|
|
140
145
|
// non-interactive subprocesses, so interactive tool prompts cannot
|
|
141
146
|
// substitute for this allowlist.
|
|
@@ -5,7 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import { RuntimeError } from "../errors.js";
|
|
6
6
|
import { selectKimiBinary } from "../kimi-command.js";
|
|
7
7
|
import { kimiReleaseHas } from "../kimi-releases.js";
|
|
8
|
-
import { probeKimiVersion } from "../kimi-version-probe.js";
|
|
8
|
+
import { KIMI_MINIMUM_CERTIFIED_VERSION, probeKimiVersion, } from "../kimi-version-probe.js";
|
|
9
9
|
import { sleep, tomlErrorLocation } from "../util.js";
|
|
10
10
|
import { extractValue } from "../vendor/smol-toml/extract.js";
|
|
11
11
|
import { parse as parseToml } from "../vendor/smol-toml/parse.js";
|
|
@@ -17,8 +17,9 @@ const DEFAULT_LOCK_STALE_MS = 2_000;
|
|
|
17
17
|
const DEFAULT_LOCK_RETRY_MS = 25;
|
|
18
18
|
export const KIMI_CONFIG_LOCK_METADATA_MAX_BYTES = 4_096;
|
|
19
19
|
const HOOK_FIELDS = new Set(["event", "matcher", "command", "timeout"]);
|
|
20
|
-
//
|
|
21
|
-
//
|
|
20
|
+
// Supported hook events for >= 2.8.0. Additive events (`PermissionRequest`,
|
|
21
|
+
// `PermissionResult`, `Interrupt`) still require an exact certified `hook-schema`
|
|
22
|
+
// release row.
|
|
22
23
|
const BASE_HOOK_EVENTS = new Set([
|
|
23
24
|
"PreToolUse",
|
|
24
25
|
"PostToolUse",
|
|
@@ -34,10 +35,10 @@ const BASE_HOOK_EVENTS = new Set([
|
|
|
34
35
|
"PostCompact",
|
|
35
36
|
"Notification",
|
|
36
37
|
]);
|
|
37
|
-
const VERSION_SENSITIVE_HOOK_EVENTS = new
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const VERSION_SENSITIVE_HOOK_EVENTS = new Set([
|
|
39
|
+
"PermissionRequest",
|
|
40
|
+
"PermissionResult",
|
|
41
|
+
"Interrupt",
|
|
41
42
|
]);
|
|
42
43
|
export function kimiConfigLockPath(configPath) {
|
|
43
44
|
return `${configPath}${LOCK_SUFFIX}`;
|
|
@@ -554,14 +555,13 @@ function validateHookEntry(entry, index, line, versionSensitiveEvents) {
|
|
|
554
555
|
return invalidHookSet("missing required field `event`", index, line);
|
|
555
556
|
if (typeof event !== "string")
|
|
556
557
|
return invalidHookSet("`event` must be a string", index, line);
|
|
557
|
-
const
|
|
558
|
-
if (!BASE_HOOK_EVENTS.has(event) &&
|
|
558
|
+
const isVersionSensitive = VERSION_SENSITIVE_HOOK_EVENTS.has(event);
|
|
559
|
+
if (!BASE_HOOK_EVENTS.has(event) && !isVersionSensitive) {
|
|
559
560
|
return invalidHookSet(`unsupported hook event ${JSON.stringify(event)}`, index, line);
|
|
560
561
|
}
|
|
561
|
-
if (
|
|
562
|
+
if (isVersionSensitive) {
|
|
562
563
|
versionSensitiveEvents.push({
|
|
563
564
|
event,
|
|
564
|
-
minimumMinor,
|
|
565
565
|
entry: index,
|
|
566
566
|
line,
|
|
567
567
|
});
|
|
@@ -590,24 +590,15 @@ function validateVersionSensitiveEvents(events, version) {
|
|
|
590
590
|
if (version === undefined) {
|
|
591
591
|
return invalidHookSet(`version-sensitive event ${JSON.stringify(first.event)} requires a verified kimi-code version`, first.entry, first.line);
|
|
592
592
|
}
|
|
593
|
-
//
|
|
594
|
-
//
|
|
595
|
-
// commit). Schema acceptance does not certify operations.
|
|
596
|
-
// Require the full version string AND matching components; no inferred 2.x compatibility.
|
|
593
|
+
// Require the full version string AND matching components against a certified
|
|
594
|
+
// >= 2.8.0 `hook-schema` release row; no inferred compatibility.
|
|
597
595
|
if (version.major === 2 &&
|
|
598
596
|
version.version === `${version.major}.${version.minor}.${version.patch}` &&
|
|
599
597
|
kimiReleaseHas(version.version, "hook-schema")) {
|
|
600
598
|
return { valid: true };
|
|
601
599
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
605
|
-
for (const event of events) {
|
|
606
|
-
if (version.minor < event.minimumMinor) {
|
|
607
|
-
return invalidHookSet(`event ${JSON.stringify(event.event)} requires kimi-code >= 0.${event.minimumMinor}, but the installed version is 0.${version.minor}`, event.entry, event.line);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
return { valid: true };
|
|
600
|
+
const observed = version.version ?? `${version.major}.${version.minor}`;
|
|
601
|
+
return invalidHookSet(`version-sensitive event ${JSON.stringify(first.event)} requires a certified kimi-code >= ${KIMI_MINIMUM_CERTIFIED_VERSION} release (got ${observed})`, first.entry, first.line);
|
|
611
602
|
}
|
|
612
603
|
function invalidHookSet(reason, entry, line, failureKind = "schema") {
|
|
613
604
|
const location = entry > 0 ? `hooks[${entry - 1}] at line ${line}` : `hooks configuration at line ${line}`;
|
|
@@ -15,7 +15,7 @@ export const HOOK_DECISION_DEADLINE_MS = HOOK_TIMEOUT_S * 1000 - 5_000;
|
|
|
15
15
|
/**
|
|
16
16
|
* kimi-code's timeout (seconds) for a [[hooks]] entry with no `timeout` key:
|
|
17
17
|
* `DEFAULT_HOOK_TIMEOUT_SECONDS` in agent-core-v2 `externalHooks/internal/
|
|
18
|
-
* matchHooks.ts`, 30 in every certified source through 2.
|
|
18
|
+
* matchHooks.ts`, 30 in every certified source through 2.8.0. Each compat
|
|
19
19
|
* audit re-verifies it.
|
|
20
20
|
*/
|
|
21
21
|
export const UPSTREAM_DEFAULT_HOOK_TIMEOUT_S = 30;
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
// upstream. The probe executes the same bytes that setup writes.
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import { realpathSync } from "node:fs";
|
|
10
|
+
import { lstat, readFile, realpath } from "node:fs/promises";
|
|
10
11
|
import path from "node:path";
|
|
11
12
|
import { fileURLToPath } from "node:url";
|
|
12
13
|
import { RuntimeError } from "../errors.js";
|
|
14
|
+
import { resolvePluginPaths } from "../paths.js";
|
|
13
15
|
/**
|
|
14
16
|
* Prefer a stable, non-version-stamped path to the SAME Node binary.
|
|
15
17
|
* Version-stamped interpreter paths change on upgrade and invalidate the
|
|
@@ -61,8 +63,7 @@ export function resolveNodeBinary(env) {
|
|
|
61
63
|
* Build the exact shell command string that `/bin/sh -c "<command>"`
|
|
62
64
|
* needs to spawn the hook. Single source of truth for:
|
|
63
65
|
*
|
|
64
|
-
* - what
|
|
65
|
-
* (`command = "..."` inside [[hooks]])
|
|
66
|
+
* - what setup writes into kimi-code's config (`command = "..."` inside [[hooks]])
|
|
66
67
|
* - what the shell probe runs via `spawn("/bin/sh", ["-c", ...])`
|
|
67
68
|
* - what the verifier (`evaluateInstalled`) equality-checks the
|
|
68
69
|
* installed `command = "..."` against on every command spawn
|
|
@@ -84,24 +85,36 @@ export function shellSingleQuote(value) {
|
|
|
84
85
|
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
|
-
*
|
|
88
|
+
* Locate the compiled, self-contained ESM hook artifact bundled with this
|
|
89
|
+
* package (`<packageRoot>/dist/hooks/approval-hook.js`). Setup copies this
|
|
90
|
+
* file into `<pluginRoot>/hook/approval-hook.js`.
|
|
91
|
+
*/
|
|
92
|
+
export function resolveBundledHookSourcePath() {
|
|
93
|
+
const here = fileURLToPath(import.meta.url);
|
|
94
|
+
const parts = here.split(path.sep);
|
|
95
|
+
if (parts.length < 3) {
|
|
96
|
+
throw resolveHookFailure(here);
|
|
97
|
+
}
|
|
98
|
+
const tailParent = parts[parts.length - 2];
|
|
99
|
+
const tailGrandparent = parts[parts.length - 3];
|
|
100
|
+
if (tailParent !== "hooks" || (tailGrandparent !== "runtime" && tailGrandparent !== "dist")) {
|
|
101
|
+
throw resolveHookFailure(here);
|
|
102
|
+
}
|
|
103
|
+
const packageRoot = parts.slice(0, parts.length - 3).join(path.sep) || path.sep;
|
|
104
|
+
return path.join(packageRoot, "dist", "hooks", "approval-hook.js");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Resolve the absolute path to the installed hook script.
|
|
88
108
|
*
|
|
89
109
|
* Resolution order:
|
|
90
|
-
*
|
|
91
110
|
* 1. `KIMI_PLUGIN_CC_HOOK_SCRIPT` override — tests / advanced users.
|
|
92
|
-
* 2.
|
|
93
|
-
*
|
|
94
|
-
* artifact lives at `<root>/dist/hooks/approval-hook.js`. Walk up
|
|
95
|
-
* to `<root>` and append the canonical hook artifact path.
|
|
111
|
+
* 2. Canonical shared plugin hook path: `<pluginRoot>/hook/approval-hook.js`
|
|
112
|
+
* (e.g. `~/.local/share/kimi-plugin-cc/hook/approval-hook.js`).
|
|
96
113
|
*/
|
|
97
114
|
export function resolveHookScriptPath(env) {
|
|
98
115
|
const override = env.KIMI_PLUGIN_CC_HOOK_SCRIPT;
|
|
99
116
|
if (override !== undefined && override.length > 0) {
|
|
100
117
|
if (!path.isAbsolute(override)) {
|
|
101
|
-
// The hook shell's cwd can differ from the companion's. Require an
|
|
102
|
-
// absolute override so installation, verification, and the runtime spawn
|
|
103
|
-
// all refer to the same file rather than blessing a relative path that
|
|
104
|
-
// resolves elsewhere when kimi-code executes it.
|
|
105
118
|
throw new RuntimeError("SETUP_HOOK_SCRIPT_NOT_ABSOLUTE", [
|
|
106
119
|
`KIMI_PLUGIN_CC_HOOK_SCRIPT must be an absolute path; got ${JSON.stringify(override)}.`,
|
|
107
120
|
`kimi-code spawns hooks via /bin/sh -c with a cwd that may differ from the companion's.`,
|
|
@@ -110,21 +123,7 @@ export function resolveHookScriptPath(env) {
|
|
|
110
123
|
}
|
|
111
124
|
return override;
|
|
112
125
|
}
|
|
113
|
-
|
|
114
|
-
const parts = here.split(path.sep);
|
|
115
|
-
// Pin to the canonical suffix `{runtime|dist}/hooks/install-paths.{ts,js}`
|
|
116
|
-
// — anchoring to a specific tail keeps ancestor directories named
|
|
117
|
-
// "runtime" or "dist" from confusing the lookup.
|
|
118
|
-
if (parts.length < 3) {
|
|
119
|
-
throw resolveHookFailure(here);
|
|
120
|
-
}
|
|
121
|
-
const tailParent = parts[parts.length - 2];
|
|
122
|
-
const tailGrandparent = parts[parts.length - 3];
|
|
123
|
-
if (tailParent !== "hooks" || (tailGrandparent !== "runtime" && tailGrandparent !== "dist")) {
|
|
124
|
-
throw resolveHookFailure(here);
|
|
125
|
-
}
|
|
126
|
-
const pluginRoot = parts.slice(0, parts.length - 3).join(path.sep) || path.sep;
|
|
127
|
-
return path.join(pluginRoot, "dist", "hooks", "approval-hook.js");
|
|
126
|
+
return resolvePluginPaths(env).hookScriptPath;
|
|
128
127
|
}
|
|
129
128
|
function resolveHookFailure(here) {
|
|
130
129
|
return new RuntimeError("SETUP_RESOLVE_HOOK_FAILED", `Could not infer plugin root from install-paths module path ${here}. Set KIMI_PLUGIN_CC_HOOK_SCRIPT to the absolute path of dist/hooks/approval-hook.js.`, "setup.resolve-hook", { details: { here } });
|
|
@@ -287,7 +286,7 @@ export function describeHookCommandDrift(installedCommand, expectedCommand, node
|
|
|
287
286
|
parts.push(`Hook script path drift: the installed hook points at ${installed.hookScript}, but this companion's ` +
|
|
288
287
|
`hook is ${expected.hookScript} (likely a plugin update or move — the install path is version-stamped).`);
|
|
289
288
|
}
|
|
290
|
-
parts.push("Run /
|
|
289
|
+
parts.push("Run `kimi_setup` (action \"install\") or `scripts/companion.sh setup` to re-pin the managed block to this companion's current paths.");
|
|
291
290
|
return parts.join(" ");
|
|
292
291
|
}
|
|
293
292
|
/**
|
|
@@ -337,80 +336,17 @@ export function tryBuildExpectedHookCommand(env) {
|
|
|
337
336
|
};
|
|
338
337
|
}
|
|
339
338
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
// The managed block is host-scoped (marker suffix `:<host-id>`) so each host
|
|
349
|
-
// owns and verifies its OWN PreToolUse block without clobbering the other's.
|
|
350
|
-
// The host id must be VERSION-INDEPENDENT so a plugin upgrade REFRESHES the
|
|
351
|
-
// same host's block instead of accumulating one block per version.
|
|
352
|
-
/**
|
|
353
|
-
* Resolve a stable, version-independent host id for the managed-block marker.
|
|
354
|
-
*
|
|
355
|
-
* Order: an explicit `KIMI_PLUGIN_CC_HOST_ID` override (slugified) wins — used
|
|
356
|
-
* by tests and the live-repair path. Otherwise derive from the resolved hook
|
|
357
|
-
* script path. Pass the already-resolved `hookScriptPath` when you have it
|
|
358
|
-
* (the verifier + setup do) so we don't re-resolve and risk a second throw.
|
|
359
|
-
*/
|
|
360
|
-
export function resolveHostId(env, hookScriptPath) {
|
|
361
|
-
const override = env.KIMI_PLUGIN_CC_HOST_ID;
|
|
362
|
-
if (override !== undefined && override.trim().length > 0) {
|
|
363
|
-
return slugifyHostId(override);
|
|
364
|
-
}
|
|
365
|
-
const resolved = hookScriptPath ?? resolveHookScriptPath(env);
|
|
366
|
-
return hostIdFromHookScript(resolved);
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Derive a host id from a hook-script path. `~/.claude/...` → `claude-code`,
|
|
370
|
-
* `~/.codex/...` → `codex` (both literal + version-independent), else a stable
|
|
371
|
-
* `host-<sha1(hookDir)[:16]>` for dev checkouts / unrecognized layouts.
|
|
372
|
-
*/
|
|
373
|
-
export function hostIdFromHookScript(hookScriptPath) {
|
|
374
|
-
const norm = hookScriptPath.split(path.sep).join("/");
|
|
375
|
-
if (norm.includes("/.claude/"))
|
|
376
|
-
return "claude-code";
|
|
377
|
-
if (norm.includes("/.codex/"))
|
|
378
|
-
return "codex";
|
|
379
|
-
// Hashing the hook directory is stable for dev checkouts. Sixteen hex chars
|
|
380
|
-
// avoid the collision risk of a 32-bit prefix, which could make one root
|
|
381
|
-
// treat another root's managed block as its own.
|
|
382
|
-
const digest = createHash("sha1").update(path.dirname(hookScriptPath)).digest("hex");
|
|
383
|
-
return `host-${digest.slice(0, 16)}`;
|
|
384
|
-
}
|
|
339
|
+
const OWNED_APPROVAL_HOOK_PATTERNS = [
|
|
340
|
+
/\/kimi-plugin-cc\/hook\/approval-hook\.js$/,
|
|
341
|
+
/\/kimi-plugin-cc\/(?:dist|runtime)\/hooks\/approval-hook\.js$/,
|
|
342
|
+
/\/plugins\/kimi-codex\/dist\/hooks\/approval-hook\.js$/,
|
|
343
|
+
/\/dsh-kimi-plugin-cc\/dist\/hooks\/approval-hook\.js$/,
|
|
344
|
+
/\/kimi-marketplace\/[^/]+\/[^/]+\/(?:dist|runtime)\/hooks\/approval-hook\.js$/,
|
|
345
|
+
/\/\.gemini\/config\/plugins\/kimi\/(?:dist|runtime)\/hooks\/approval-hook\.js$/,
|
|
346
|
+
];
|
|
385
347
|
/**
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
* always well-formed.
|
|
389
|
-
*/
|
|
390
|
-
export function slugifyHostId(value) {
|
|
391
|
-
const slug = value
|
|
392
|
-
.trim()
|
|
393
|
-
.toLowerCase()
|
|
394
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
395
|
-
.replace(/^-+|-+$/g, "")
|
|
396
|
-
.slice(0, 40);
|
|
397
|
-
return slug.length > 0 ? slug : "host";
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Derive the owning host id from a canonical hook command's script path.
|
|
401
|
-
* Returns `null` for a non-canonical command whose owner cannot be determined;
|
|
402
|
-
* scoped cleanup treats that as ambiguous rather than claiming another host's
|
|
403
|
-
* block.
|
|
404
|
-
*/
|
|
405
|
-
export function hostIdFromHookCommand(command) {
|
|
406
|
-
const parsed = parseHookShellCommand(command);
|
|
407
|
-
if (parsed === null)
|
|
408
|
-
return null;
|
|
409
|
-
return hostIdFromHookScript(parsed.hookScript);
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* True only for a canonical two-single-quoted-token command whose script is
|
|
413
|
-
* `approval-hook.js` under a kimi-plugin-cc/dsh-kimi-plugin-cc/kimi-marketplace install tree.
|
|
348
|
+
* True only for a canonical two-single-quoted-token command whose script
|
|
349
|
+
* matches an exact kimi-plugin-cc install/published approval-hook path.
|
|
414
350
|
* This strict ownership test protects hand-rolled and non-canonical user hooks
|
|
415
351
|
* from orphan pruning.
|
|
416
352
|
*/
|
|
@@ -418,11 +354,147 @@ export function isOurApprovalHookCommand(decodedCommand) {
|
|
|
418
354
|
const parsed = parseHookShellCommand(decodedCommand);
|
|
419
355
|
if (parsed === null)
|
|
420
356
|
return false;
|
|
421
|
-
const script = parsed.hookScript.split(/[\\/]/);
|
|
422
|
-
if (script[script.length - 1] !== "approval-hook.js")
|
|
423
|
-
return false;
|
|
424
357
|
const normalized = parsed.hookScript.replace(/\\/g, "/");
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
358
|
+
return OWNED_APPROVAL_HOOK_PATTERNS.some((pattern) => pattern.test(normalized));
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Verify the managed `<pluginRoot>/hook/approval-hook.js` artifact on disk:
|
|
362
|
+
* - Reject symlinks or non-directory/non-regular files along `pluginRoot`, `hookDir`,
|
|
363
|
+
* and `hookScriptPath`, and require canonical containment under `pluginRoot/hook`.
|
|
364
|
+
* - Require SHA-256 byte equality against the bundled `dist/hooks/approval-hook.js`.
|
|
365
|
+
* Skipped when `KIMI_PLUGIN_CC_HOOK_SCRIPT` explicitly overrides the script path.
|
|
366
|
+
*/
|
|
367
|
+
export async function verifyManagedHookArtifact(env, hookScriptPath) {
|
|
368
|
+
if (env.KIMI_PLUGIN_CC_HOOK_SCRIPT && env.KIMI_PLUGIN_CC_HOOK_SCRIPT.length > 0) {
|
|
369
|
+
return { ok: true };
|
|
370
|
+
}
|
|
371
|
+
const paths = resolvePluginPaths(env);
|
|
372
|
+
let pluginRootReal;
|
|
373
|
+
try {
|
|
374
|
+
const info = await lstat(paths.pluginRoot);
|
|
375
|
+
if (info.isSymbolicLink() || !info.isDirectory()) {
|
|
376
|
+
return {
|
|
377
|
+
ok: false,
|
|
378
|
+
kind: "unsafe-path",
|
|
379
|
+
reason: `plugin data directory ${paths.pluginRoot} is a symlink or not a directory; refusing to trust managed hook`,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
pluginRootReal = await realpath(paths.pluginRoot);
|
|
383
|
+
}
|
|
384
|
+
catch (err) {
|
|
385
|
+
if (err.code === "ENOENT") {
|
|
386
|
+
return {
|
|
387
|
+
ok: false,
|
|
388
|
+
kind: "missing",
|
|
389
|
+
reason: `hook script ${hookScriptPath} is missing or unreadable — run \`kimi_setup\` (action "install") or \`scripts/companion.sh setup\` to reinstall`,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
ok: false,
|
|
394
|
+
kind: "unsafe-path",
|
|
395
|
+
reason: `unable to inspect plugin data directory ${paths.pluginRoot}: ${err.message}`,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
let hookDirReal;
|
|
399
|
+
try {
|
|
400
|
+
const info = await lstat(paths.hookDir);
|
|
401
|
+
if (info.isSymbolicLink() || !info.isDirectory()) {
|
|
402
|
+
return {
|
|
403
|
+
ok: false,
|
|
404
|
+
kind: "unsafe-path",
|
|
405
|
+
reason: `hook directory ${paths.hookDir} is a symlink or not a directory; refusing to trust managed hook`,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
hookDirReal = await realpath(paths.hookDir);
|
|
409
|
+
}
|
|
410
|
+
catch (err) {
|
|
411
|
+
if (err.code === "ENOENT") {
|
|
412
|
+
return {
|
|
413
|
+
ok: false,
|
|
414
|
+
kind: "missing",
|
|
415
|
+
reason: `hook script ${hookScriptPath} is missing or unreadable — run \`kimi_setup\` (action "install") or \`scripts/companion.sh setup\` to reinstall`,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
return {
|
|
419
|
+
ok: false,
|
|
420
|
+
kind: "unsafe-path",
|
|
421
|
+
reason: `unable to inspect hook directory ${paths.hookDir}: ${err.message}`,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
const expectedHookDirReal = path.join(pluginRootReal, "hook");
|
|
425
|
+
if (hookDirReal !== expectedHookDirReal) {
|
|
426
|
+
return {
|
|
427
|
+
ok: false,
|
|
428
|
+
kind: "unsafe-path",
|
|
429
|
+
reason: `hook directory ${paths.hookDir} resolves to ${hookDirReal}, outside ${expectedHookDirReal}; refusing to trust managed hook`,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
try {
|
|
433
|
+
const info = await lstat(hookScriptPath);
|
|
434
|
+
if (info.isSymbolicLink() || !info.isFile()) {
|
|
435
|
+
return {
|
|
436
|
+
ok: false,
|
|
437
|
+
kind: "unsafe-path",
|
|
438
|
+
reason: `hook script ${hookScriptPath} is a symlink or not a regular file; refusing to execute managed hook`,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
const scriptReal = await realpath(hookScriptPath);
|
|
442
|
+
const expectedScriptReal = path.join(hookDirReal, path.basename(hookScriptPath));
|
|
443
|
+
if (scriptReal !== expectedScriptReal) {
|
|
444
|
+
return {
|
|
445
|
+
ok: false,
|
|
446
|
+
kind: "unsafe-path",
|
|
447
|
+
reason: `hook script ${hookScriptPath} resolves to ${scriptReal}, outside ${hookDirReal}; refusing to execute managed hook`,
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
catch (err) {
|
|
452
|
+
if (err.code === "ENOENT") {
|
|
453
|
+
return {
|
|
454
|
+
ok: false,
|
|
455
|
+
kind: "missing",
|
|
456
|
+
reason: `hook script ${hookScriptPath} is missing or unreadable — run \`kimi_setup\` (action "install") or \`scripts/companion.sh setup\` to reinstall`,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
return {
|
|
460
|
+
ok: false,
|
|
461
|
+
kind: "unsafe-path",
|
|
462
|
+
reason: `unable to inspect hook script ${hookScriptPath}: ${err.message}`,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
let installedBytes;
|
|
466
|
+
try {
|
|
467
|
+
installedBytes = await readFile(hookScriptPath);
|
|
468
|
+
}
|
|
469
|
+
catch {
|
|
470
|
+
return {
|
|
471
|
+
ok: false,
|
|
472
|
+
kind: "missing",
|
|
473
|
+
reason: `hook script ${hookScriptPath} is missing or unreadable — run \`kimi_setup\` (action "install") or \`scripts/companion.sh setup\` to reinstall`,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
let sourcePath;
|
|
477
|
+
let bundledBytes;
|
|
478
|
+
try {
|
|
479
|
+
sourcePath = resolveBundledHookSourcePath();
|
|
480
|
+
bundledBytes = await readFile(sourcePath);
|
|
481
|
+
}
|
|
482
|
+
catch (err) {
|
|
483
|
+
return {
|
|
484
|
+
ok: false,
|
|
485
|
+
kind: "bundle-missing",
|
|
486
|
+
reason: `bundled hook source is missing or unreadable (${err.message}); run \`bun run build\` or reinstall the plugin`,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
const installedHash = createHash("sha256").update(installedBytes).digest("hex");
|
|
490
|
+
const bundledHash = createHash("sha256").update(bundledBytes).digest("hex");
|
|
491
|
+
if (installedHash !== bundledHash) {
|
|
492
|
+
return {
|
|
493
|
+
ok: false,
|
|
494
|
+
kind: "sha256-mismatch",
|
|
495
|
+
reason: `installed hook script ${hookScriptPath} does not match the bundled hook artifact (${sourcePath}, SHA-256 mismatch — likely after a plugin update). ` +
|
|
496
|
+
`Run \`kimi_setup\` (action "install") or \`scripts/companion.sh setup\` to republish it.`,
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
return { ok: true };
|
|
428
500
|
}
|