glimmervoid 0.46.2-next.166 → 0.46.2-next.168
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/dist/bin/glimmervoid.js +7 -7
- package/dist/chunks/{adapters-DmzmKIDw.js → adapters-3RuVH2qm.js} +3 -1
- package/dist/chunks/{adapters-d3XIppeP.js → adapters-yHbHeeiD.js} +1 -1
- package/dist/chunks/{agent-setup-cli-C7x4N5U6.js → agent-setup-cli-DHqTFNcZ.js} +3 -68
- package/dist/chunks/grok-DnkhGGf5.js +369 -0
- package/dist/chunks/kimi-BiLAVDKd.js +232 -0
- package/dist/chunks/kimi-CjswbYS5.js +1 -0
- package/dist/chunks/kimi-home-CYJpt82i.js +860 -0
- package/dist/chunks/kimi-home-DyWG81oB.js +1 -0
- package/dist/chunks/{main-Dyx_oiMS.js → main-DZQJiOBQ.js} +24 -161
- package/dist/chunks/spawn-env-BFfAkGlR.js +82 -0
- package/dist/client/assets/{alert-sound-CMw9IYOa.js → alert-sound-Bef4LEZ_.js} +1 -1
- package/dist/client/assets/alert-sound-Bef4LEZ_.js.br +0 -0
- package/dist/client/assets/{benchmark-panel-12iKvivr.js → benchmark-panel-BXkbrZ2r.js} +1 -1
- package/dist/client/assets/benchmark-panel-BXkbrZ2r.js.br +0 -0
- package/dist/client/assets/{celebration-player-CpgG9DUA.js → celebration-player-BC_vrnJd.js} +1 -1
- package/dist/client/assets/celebration-player-BC_vrnJd.js.br +0 -0
- package/dist/client/assets/{dialogs-x_B527bk.js → dialogs-D_bkBkDI.js} +1 -1
- package/dist/client/assets/dialogs-D_bkBkDI.js.br +0 -0
- package/dist/client/assets/{doc-editor-ui-CIhJUO3J.js → doc-editor-ui-WURReoK0.js} +1 -1
- package/dist/client/assets/doc-editor-ui-WURReoK0.js.br +0 -0
- package/dist/client/assets/{feature-hint-MLJvjOT0.js → feature-hint-BsGHHzie.js} +1 -1
- package/dist/client/assets/feature-hint-BsGHHzie.js.br +0 -0
- package/dist/client/assets/{first-run-checklist-s4X-OM4Z.js → first-run-checklist-zfh60jLU.js} +1 -1
- package/dist/client/assets/first-run-checklist-zfh60jLU.js.br +0 -0
- package/dist/client/assets/{hooks-panel-121qcKFE.js → hooks-panel-_QCDTFlk.js} +1 -1
- package/dist/client/assets/hooks-panel-_QCDTFlk.js.br +0 -0
- package/dist/client/assets/{index-BJ8diTZl.js → index-2xbSsu75.js} +5 -5
- package/dist/client/assets/index-2xbSsu75.js.br +0 -0
- package/dist/client/assets/{issues-panel-CMZFcUDT.js → issues-panel-BRvuSbN2.js} +1 -1
- package/dist/client/assets/issues-panel-BRvuSbN2.js.br +0 -0
- package/dist/client/assets/{nyan-cat-BvxG-Hhz.js → nyan-cat-dzC4D1dQ.js} +1 -1
- package/dist/client/assets/nyan-cat-dzC4D1dQ.js.br +0 -0
- package/dist/client/assets/{phone-shell-DtQYi3Yz.js → phone-shell-BCoSY_6R.js} +1 -1
- package/dist/client/assets/phone-shell-BCoSY_6R.js.br +0 -0
- package/dist/client/assets/{plan-face-BfwHo5re.js → plan-face-PeDpLo-L.js} +1 -1
- package/dist/client/assets/plan-face-PeDpLo-L.js.br +0 -0
- package/dist/client/assets/{plan-render-QchOXg1E.js → plan-render-qGWAegR9.js} +1 -1
- package/dist/client/assets/plan-render-qGWAegR9.js.br +0 -0
- package/dist/client/assets/{pr-scope-tabs-BqPN4zAH.js → pr-scope-tabs-Z7CclL2Y.js} +1 -1
- package/dist/client/assets/pr-scope-tabs-Z7CclL2Y.js.br +0 -0
- package/dist/client/assets/{radar-panel-DQCaWDNM.js → radar-panel-CiwRuHcB.js} +1 -1
- package/dist/client/assets/radar-panel-CiwRuHcB.js.br +0 -0
- package/dist/client/assets/{resume-dialog-C_NFnnAx.js → resume-dialog-jMGA0X1R.js} +1 -1
- package/dist/client/assets/resume-dialog-jMGA0X1R.js.br +0 -0
- package/dist/client/assets/{review-queue-panel-DTM1__rk.js → review-queue-panel-yhBG1XCq.js} +1 -1
- package/dist/client/assets/review-queue-panel-yhBG1XCq.js.br +0 -0
- package/dist/client/assets/{settings-panel-k5MM_UFC.js → settings-panel-BbdgDk2F.js} +2 -2
- package/dist/client/assets/settings-panel-BbdgDk2F.js.br +0 -0
- package/dist/client/assets/{shown-lightbox-Bdv2LDYa.js → shown-lightbox-DdkmOdgi.js} +1 -1
- package/dist/client/assets/shown-lightbox-DdkmOdgi.js.br +0 -0
- package/dist/client/assets/{trace-panel-BlczKgbw.js → trace-panel-C8nPGXMh.js} +1 -1
- package/dist/client/assets/trace-panel-C8nPGXMh.js.br +0 -0
- package/dist/client/assets/{usage-panel-DeCYlwfG.js → usage-panel-D08cvZR-.js} +1 -1
- package/dist/client/assets/usage-panel-D08cvZR-.js.br +0 -0
- package/dist/client/assets/{visions-panel-IoBQ4LJF.js → visions-panel-jUraIFz8.js} +1 -1
- package/dist/client/assets/visions-panel-jUraIFz8.js.br +0 -0
- package/dist/client/index.html +1 -1
- package/dist/client/index.html.br +0 -0
- package/dist/server/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/kimi-Be_QndbF.js +0 -1168
- package/dist/client/assets/alert-sound-CMw9IYOa.js.br +0 -0
- package/dist/client/assets/benchmark-panel-12iKvivr.js.br +0 -0
- package/dist/client/assets/celebration-player-CpgG9DUA.js.br +0 -0
- package/dist/client/assets/dialogs-x_B527bk.js.br +0 -0
- package/dist/client/assets/doc-editor-ui-CIhJUO3J.js.br +0 -0
- package/dist/client/assets/feature-hint-MLJvjOT0.js.br +0 -0
- package/dist/client/assets/first-run-checklist-s4X-OM4Z.js.br +0 -0
- package/dist/client/assets/hooks-panel-121qcKFE.js.br +0 -0
- package/dist/client/assets/index-BJ8diTZl.js.br +0 -0
- package/dist/client/assets/issues-panel-CMZFcUDT.js.br +0 -0
- package/dist/client/assets/nyan-cat-BvxG-Hhz.js.br +0 -0
- package/dist/client/assets/phone-shell-DtQYi3Yz.js.br +0 -0
- package/dist/client/assets/plan-face-BfwHo5re.js.br +0 -0
- package/dist/client/assets/plan-render-QchOXg1E.js.br +0 -0
- package/dist/client/assets/pr-scope-tabs-BqPN4zAH.js.br +0 -0
- package/dist/client/assets/radar-panel-DQCaWDNM.js.br +0 -0
- package/dist/client/assets/resume-dialog-C_NFnnAx.js.br +0 -0
- package/dist/client/assets/review-queue-panel-DTM1__rk.js.br +0 -0
- package/dist/client/assets/settings-panel-k5MM_UFC.js.br +0 -0
- package/dist/client/assets/shown-lightbox-Bdv2LDYa.js.br +0 -0
- package/dist/client/assets/trace-panel-BlczKgbw.js.br +0 -0
- package/dist/client/assets/usage-panel-DeCYlwfG.js.br +0 -0
- package/dist/client/assets/visions-panel-IoBQ4LJF.js.br +0 -0
|
@@ -1,1168 +0,0 @@
|
|
|
1
|
-
import { a as isMissingFileError, r as errorMessage } from "./text-DoirglWV.js";
|
|
2
|
-
import { s as relayPath } from "./runtime-paths-ghcH9CeW.js";
|
|
3
|
-
import { n as glimmervoidHomeDir } from "./config-path-core-DUWk0Lui.js";
|
|
4
|
-
import { O as SIGN_URL_ENV, n as AGENT_URL_ENV, r as ASK_USER_QUESTION_TOOL_NAME } from "./session-B2Wieg0a.js";
|
|
5
|
-
import { r as execFileSync } from "./child-process-safe-D4hyVIXj.js";
|
|
6
|
-
import { n as isRecord } from "./coerce-NSst8oRP.js";
|
|
7
|
-
import { n as resolveAgentCommand, t as buildAgentSpawnCommand } from "./spawn-command-Cc40FiZI.js";
|
|
8
|
-
import { t as HOOK_URL_ENV } from "./hook-relay-core-DA_bz2KA.js";
|
|
9
|
-
import { a as KIMI_SANE_YOLO_FLAVOR, o as SANE_YOLO_PATH_ENV, r as RTK_PATH_ENV, s as saneYoloEnv } from "./rtk-hook-core-23_GM8RQ.js";
|
|
10
|
-
import { t as buildHookCommand } from "./hook-command-core-qTNK-xMF.js";
|
|
11
|
-
import { p as writeTextAtomicSync } from "./json-file-BjFK_eSH.js";
|
|
12
|
-
import fs from "node:fs";
|
|
13
|
-
import path from "node:path";
|
|
14
|
-
import os from "node:os";
|
|
15
|
-
import { createHash } from "node:crypto";
|
|
16
|
-
//#region session/core/spawn-env.ts
|
|
17
|
-
var GLIMMERVOID_SCRUB_KEYS = [
|
|
18
|
-
"GLIMMERVOID_PORT",
|
|
19
|
-
"GLIMMERVOID_CONFIG",
|
|
20
|
-
HOOK_URL_ENV,
|
|
21
|
-
AGENT_URL_ENV,
|
|
22
|
-
SIGN_URL_ENV,
|
|
23
|
-
RTK_PATH_ENV,
|
|
24
|
-
SANE_YOLO_PATH_ENV,
|
|
25
|
-
...[
|
|
26
|
-
"GLIMMERVOID_POSTHOG_API_KEY",
|
|
27
|
-
"GLIMMERVOID_TELEGRAM_BOT_TOKEN",
|
|
28
|
-
"GLIMMERVOID_CLAUDE_OAUTH_TOKEN"
|
|
29
|
-
]
|
|
30
|
-
];
|
|
31
|
-
var SANE_YOLO_GUARD_KEYS = [SANE_YOLO_PATH_ENV, ...Object.keys(saneYoloEnv(""))];
|
|
32
|
-
var SAFETY_NET_ENV_PREFIXES = ["CC_SAFETY_NET_", "SAFETY_NET_"];
|
|
33
|
-
var LAUNCHING_TERMINAL_IDENTITY_KEYS = ["TERM_PROGRAM", "TERM_PROGRAM_VERSION"];
|
|
34
|
-
function normalizePathEntry(entry) {
|
|
35
|
-
return entry.replace(/\\/g, "/").toLowerCase();
|
|
36
|
-
}
|
|
37
|
-
function isWindowsDriveColon(value, index, entryStart) {
|
|
38
|
-
if (path.delimiter !== ":") return false;
|
|
39
|
-
if (index !== entryStart + 1) return false;
|
|
40
|
-
if (!/[A-Za-z]/.test(value[index - 1] || "")) return false;
|
|
41
|
-
return value[index + 1] === "\\" || value[index + 1] === "/";
|
|
42
|
-
}
|
|
43
|
-
function splitPathEntries(value) {
|
|
44
|
-
const entries = [];
|
|
45
|
-
let entryStart = 0;
|
|
46
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
47
|
-
if (value[index] !== path.delimiter) continue;
|
|
48
|
-
if (isWindowsDriveColon(value, index, entryStart)) continue;
|
|
49
|
-
entries.push(value.slice(entryStart, index));
|
|
50
|
-
entryStart = index + 1;
|
|
51
|
-
}
|
|
52
|
-
entries.push(value.slice(entryStart));
|
|
53
|
-
return entries.filter(Boolean);
|
|
54
|
-
}
|
|
55
|
-
function prependPathDir(env, prependPathDirValue) {
|
|
56
|
-
if (!prependPathDirValue) return;
|
|
57
|
-
const pathKey = Object.keys(env).find((key) => key.toLowerCase() === "path") || "PATH";
|
|
58
|
-
const existingPath = env[pathKey] || "";
|
|
59
|
-
const pathEntries = splitPathEntries(existingPath);
|
|
60
|
-
const normalizedPrependDir = normalizePathEntry(prependPathDirValue);
|
|
61
|
-
if (pathEntries.some((entry) => normalizePathEntry(entry) === normalizedPrependDir)) return;
|
|
62
|
-
if (!existingPath) {
|
|
63
|
-
env[pathKey] = prependPathDirValue;
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
env[pathKey] = `${prependPathDirValue}${path.delimiter}${existingPath}`;
|
|
67
|
-
}
|
|
68
|
-
function isSafetyNetKey(key) {
|
|
69
|
-
const upperKey = key.toUpperCase();
|
|
70
|
-
return SAFETY_NET_ENV_PREFIXES.some((prefix) => upperKey.startsWith(prefix));
|
|
71
|
-
}
|
|
72
|
-
function isSaneYoloGuarded(extraEnv) {
|
|
73
|
-
if (!extraEnv) return false;
|
|
74
|
-
return SANE_YOLO_GUARD_KEYS.some((key) => extraEnv[key] !== void 0);
|
|
75
|
-
}
|
|
76
|
-
function scrubInheritedSafetyNetEnv(env) {
|
|
77
|
-
for (const key of Object.keys(env)) if (isSafetyNetKey(key)) delete env[key];
|
|
78
|
-
}
|
|
79
|
-
function buildAgentEnv(baseEnv, extraEnv, profile, { prependPathDir: pathDir = null, prependPathDirs = [] } = {}) {
|
|
80
|
-
const env = { ...baseEnv };
|
|
81
|
-
for (const key of profile.scrub || []) delete env[key];
|
|
82
|
-
for (const key of GLIMMERVOID_SCRUB_KEYS) delete env[key];
|
|
83
|
-
for (const key of LAUNCHING_TERMINAL_IDENTITY_KEYS) delete env[key];
|
|
84
|
-
if (isSaneYoloGuarded(extraEnv)) scrubInheritedSafetyNetEnv(env);
|
|
85
|
-
Object.assign(env, extraEnv || {});
|
|
86
|
-
Object.assign(env, profile.set || {});
|
|
87
|
-
prependPathDir(env, pathDir);
|
|
88
|
-
const uniquePathDirs = prependPathDirs.filter((directory, index) => prependPathDirs.findIndex((candidate) => normalizePathEntry(candidate) === normalizePathEntry(directory)) === index);
|
|
89
|
-
for (const directory of uniquePathDirs.reverse()) prependPathDir(env, directory);
|
|
90
|
-
return env;
|
|
91
|
-
}
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region session/core/grok-hooks-file-core.ts
|
|
94
|
-
function hookGroup(command) {
|
|
95
|
-
return [{ hooks: [{
|
|
96
|
-
type: "command",
|
|
97
|
-
command
|
|
98
|
-
}] }];
|
|
99
|
-
}
|
|
100
|
-
function renderGrokHooksFile({ relayPath, events, hookToolRelayPath }) {
|
|
101
|
-
const hooks = {};
|
|
102
|
-
for (const event of events) {
|
|
103
|
-
const command = buildHookCommand(relayPath, event);
|
|
104
|
-
if (!command) return null;
|
|
105
|
-
hooks[event] = hookGroup(command);
|
|
106
|
-
}
|
|
107
|
-
if (hookToolRelayPath) {
|
|
108
|
-
const command = buildHookCommand(hookToolRelayPath, "saneYolo");
|
|
109
|
-
if (!command) return null;
|
|
110
|
-
hooks.PreToolUse = hookGroup(command);
|
|
111
|
-
}
|
|
112
|
-
return `${JSON.stringify({ hooks }, null, 2)}\n`;
|
|
113
|
-
}
|
|
114
|
-
function hasOnlyKeys(value, expectedKeys) {
|
|
115
|
-
if (!isRecord(value)) return false;
|
|
116
|
-
const actualKeys = Object.keys(value).sort();
|
|
117
|
-
const sortedExpectedKeys = [...expectedKeys].sort();
|
|
118
|
-
return actualKeys.length === sortedExpectedKeys.length && actualKeys.every((key, index) => key === sortedExpectedKeys[index]);
|
|
119
|
-
}
|
|
120
|
-
var MANAGED_RELAY_RE = /(?:^|\/)(hook-relay|hook-tool-relay)\.(?:js|ts)$/;
|
|
121
|
-
function isManagedCommand(command, event) {
|
|
122
|
-
if (typeof command !== "string") return false;
|
|
123
|
-
const match = command.match(/^node (?:(?:"([^"\r\n]+)")|([^\s"']+)) ([A-Za-z][A-Za-z0-9_-]{0,63})$/);
|
|
124
|
-
if (!match) return false;
|
|
125
|
-
const relayPath = match[1] || match[2];
|
|
126
|
-
const relayMatch = relayPath.match(MANAGED_RELAY_RE);
|
|
127
|
-
if (!relayMatch) return false;
|
|
128
|
-
const expectedRelay = event === "PreToolUse" ? "hook-tool-relay" : "hook-relay";
|
|
129
|
-
const expectedToken = event === "PreToolUse" ? "saneYolo" : event;
|
|
130
|
-
if (relayMatch[1] !== expectedRelay || match[3] !== expectedToken) return false;
|
|
131
|
-
return buildHookCommand(relayPath, expectedToken) === command;
|
|
132
|
-
}
|
|
133
|
-
function isManagedHookGroup(group, event) {
|
|
134
|
-
if (!Array.isArray(group) || group.length !== 1) return false;
|
|
135
|
-
const matcherGroup = group[0];
|
|
136
|
-
if (!hasOnlyKeys(matcherGroup, ["hooks"])) return false;
|
|
137
|
-
if (!Array.isArray(matcherGroup.hooks) || matcherGroup.hooks.length !== 1) return false;
|
|
138
|
-
const handler = matcherGroup.hooks[0];
|
|
139
|
-
if (!hasOnlyKeys(handler, ["type", "command"])) return false;
|
|
140
|
-
if (handler.type !== "command") return false;
|
|
141
|
-
return isManagedCommand(handler.command, event);
|
|
142
|
-
}
|
|
143
|
-
function classifyGrokHooksFile(contents, { relayPath, events, managedEventSets = [], hookToolRelayPath }) {
|
|
144
|
-
if (contents == null) return "absent";
|
|
145
|
-
if (contents === renderGrokHooksFile({
|
|
146
|
-
relayPath,
|
|
147
|
-
events,
|
|
148
|
-
hookToolRelayPath
|
|
149
|
-
})) return "current";
|
|
150
|
-
if (contents === renderGrokHooksFile({
|
|
151
|
-
relayPath,
|
|
152
|
-
events
|
|
153
|
-
})) return "current";
|
|
154
|
-
let parsed = null;
|
|
155
|
-
try {
|
|
156
|
-
parsed = JSON.parse(contents);
|
|
157
|
-
} catch {
|
|
158
|
-
return "foreign";
|
|
159
|
-
}
|
|
160
|
-
if (!hasOnlyKeys(parsed, ["hooks"])) return "foreign";
|
|
161
|
-
const hooksValue = parsed.hooks;
|
|
162
|
-
if (hooksValue === null || hooksValue === void 0) throw new TypeError("hooks must be an object");
|
|
163
|
-
if (!isRecord(hooksValue)) return "foreign";
|
|
164
|
-
const actualEvents = Object.keys(hooksValue);
|
|
165
|
-
if (!hasOnlyKeys(hooksValue, actualEvents)) return "foreign";
|
|
166
|
-
const hooks = hooksValue;
|
|
167
|
-
if (![events, ...managedEventSets].some((managedEvents) => hasOnlyKeys(hooks, managedEvents) || hasOnlyKeys(hooks, [...managedEvents, "PreToolUse"]))) return "foreign";
|
|
168
|
-
for (const event of actualEvents) if (!isManagedHookGroup(hooks[event], event)) return "foreign";
|
|
169
|
-
return "managed-stale";
|
|
170
|
-
}
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region session/core/title-classifier-core.ts
|
|
173
|
-
var BRAILLE_MIN = 10240;
|
|
174
|
-
var BRAILLE_MAX = 10495;
|
|
175
|
-
var CIRCLE_HALVES_SPINNER_CODEPOINTS = /* @__PURE__ */ new Set([
|
|
176
|
-
9680,
|
|
177
|
-
9681,
|
|
178
|
-
9682,
|
|
179
|
-
9683
|
|
180
|
-
]);
|
|
181
|
-
function isBrailleChar(char) {
|
|
182
|
-
if (!char) return false;
|
|
183
|
-
const codePoint = char.codePointAt(0) ?? 0;
|
|
184
|
-
return codePoint >= BRAILLE_MIN && codePoint <= BRAILLE_MAX;
|
|
185
|
-
}
|
|
186
|
-
function isSpinnerChar(char) {
|
|
187
|
-
if (!char) return false;
|
|
188
|
-
if (isBrailleChar(char)) return true;
|
|
189
|
-
return CIRCLE_HALVES_SPINNER_CODEPOINTS.has(char.codePointAt(0) ?? 0);
|
|
190
|
-
}
|
|
191
|
-
function isPathLikeTitle(title) {
|
|
192
|
-
return title.includes("/") || title.includes("\\");
|
|
193
|
-
}
|
|
194
|
-
function firstCharOfTitle(title) {
|
|
195
|
-
if (title.length === 0) return "";
|
|
196
|
-
return String.fromCodePoint(title.codePointAt(0) ?? 0);
|
|
197
|
-
}
|
|
198
|
-
function classifyAgentTitle(title, { cwdBasename = null }, vocabulary) {
|
|
199
|
-
const trimmedTitle = title.trim();
|
|
200
|
-
if (vocabulary.busyTitle && trimmedTitle === vocabulary.busyTitle) return "working";
|
|
201
|
-
if (vocabulary.idleTitle && trimmedTitle === vocabulary.idleTitle) return "ready";
|
|
202
|
-
if (isPathLikeTitle(title)) return "ignore";
|
|
203
|
-
if (vocabulary.isSpinnerChar(firstCharOfTitle(title))) return "working";
|
|
204
|
-
if (!cwdBasename) return "ignore";
|
|
205
|
-
const cwdAwareClassification = vocabulary.classifyAgainstCwdBasename?.(title, cwdBasename) ?? null;
|
|
206
|
-
if (cwdAwareClassification) return cwdAwareClassification;
|
|
207
|
-
if (trimmedTitle === cwdBasename) return "ready";
|
|
208
|
-
return "unknown";
|
|
209
|
-
}
|
|
210
|
-
//#endregion
|
|
211
|
-
//#region session/adapters/grok.ts
|
|
212
|
-
var ID$1 = "grok";
|
|
213
|
-
var COMMAND_NAME$1 = "grok";
|
|
214
|
-
var RELAY_PATH$1 = relayPath("hook-relay");
|
|
215
|
-
var HOOK_TOOL_RELAY_PATH$1 = relayPath("hook-tool-relay");
|
|
216
|
-
var HOOK_EVENTS$1 = [
|
|
217
|
-
"UserPromptSubmit",
|
|
218
|
-
"Stop",
|
|
219
|
-
"StopFailure",
|
|
220
|
-
"StopCancelled",
|
|
221
|
-
"Notification",
|
|
222
|
-
"SubagentStart",
|
|
223
|
-
"SubagentStop"
|
|
224
|
-
];
|
|
225
|
-
var MANAGED_HOOK_EVENT_SETS = [[
|
|
226
|
-
"UserPromptSubmit",
|
|
227
|
-
"Stop",
|
|
228
|
-
"StopFailure",
|
|
229
|
-
"StopCancelled",
|
|
230
|
-
"Notification"
|
|
231
|
-
]];
|
|
232
|
-
var ACTION_REQUIRED_MARKER = String.fromCodePoint(9888);
|
|
233
|
-
var CLAUDE_COMPAT_HOOKS_ENV = "GROK_CLAUDE_HOOKS_ENABLED";
|
|
234
|
-
var PROJECT_CONFIG_CANDIDATES = Object.freeze([Object.freeze({
|
|
235
|
-
relPath: ".claude/settings.json",
|
|
236
|
-
presenceIsHit: false
|
|
237
|
-
}), Object.freeze({
|
|
238
|
-
relPath: ".claude/settings.local.json",
|
|
239
|
-
presenceIsHit: false
|
|
240
|
-
})]);
|
|
241
|
-
var envProfile$1 = {
|
|
242
|
-
scrub: [],
|
|
243
|
-
set: { [CLAUDE_COMPAT_HOOKS_ENV]: "false" }
|
|
244
|
-
};
|
|
245
|
-
function notificationType(payload) {
|
|
246
|
-
return String(payload?.notificationType || payload?.notification_type || "").toLowerCase();
|
|
247
|
-
}
|
|
248
|
-
function isMainSessionPayload(payload) {
|
|
249
|
-
return !payload?.subagentType && !payload?.subagent_type;
|
|
250
|
-
}
|
|
251
|
-
function mapBackgroundTask(task) {
|
|
252
|
-
if (!isRecord(task)) return task;
|
|
253
|
-
return {
|
|
254
|
-
...task,
|
|
255
|
-
...typeof task.agentType === "string" ? { agent_type: task.agentType } : {}
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
function mapHookPayload$1(_event, payload) {
|
|
259
|
-
if (!isRecord(payload)) return payload;
|
|
260
|
-
return {
|
|
261
|
-
...payload,
|
|
262
|
-
...typeof payload.subagentId === "string" ? { agent_id: payload.subagentId } : {},
|
|
263
|
-
...typeof payload.subagentType === "string" ? { agent_type: payload.subagentType } : {},
|
|
264
|
-
...Array.isArray(payload.backgroundTasks) ? { background_tasks: payload.backgroundTasks.map(mapBackgroundTask) } : {}
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
function mayContributeHooks(configText) {
|
|
268
|
-
if (typeof configText !== "string") return false;
|
|
269
|
-
let settings;
|
|
270
|
-
try {
|
|
271
|
-
settings = JSON.parse(configText);
|
|
272
|
-
} catch {
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
|
-
if (!isRecord(settings)) return false;
|
|
276
|
-
return Object.hasOwn(settings, "hooks");
|
|
277
|
-
}
|
|
278
|
-
function userConfigFolders() {
|
|
279
|
-
return [path.join(os.homedir(), ".claude")];
|
|
280
|
-
}
|
|
281
|
-
function mapHookToSignal$1(event, payload) {
|
|
282
|
-
const normalizedEvent = String(event || "").toLowerCase();
|
|
283
|
-
if (normalizedEvent === "subagentstart") return "subagent-start";
|
|
284
|
-
if (normalizedEvent === "subagentstop") return "subagent-stop";
|
|
285
|
-
if (!isMainSessionPayload(payload)) return null;
|
|
286
|
-
switch (normalizedEvent) {
|
|
287
|
-
case "sessionstart": return "session-start";
|
|
288
|
-
case "sessionend": return "session-end";
|
|
289
|
-
case "userpromptsubmit": return "resume";
|
|
290
|
-
case "stop": return payload?.reason === "end_turn" ? "ready" : null;
|
|
291
|
-
case "stopfailure":
|
|
292
|
-
case "stopcancelled": return "ready";
|
|
293
|
-
case "notification": {
|
|
294
|
-
const type = notificationType(payload);
|
|
295
|
-
if (type === "idle_prompt") return "ready";
|
|
296
|
-
if (type === "permission_prompt" || type === "approval_required") return "awaiting-input";
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
default: return null;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
function mapHookConfidence$1(event, payload) {
|
|
303
|
-
if (String(event || "").toLowerCase() === "notification" && notificationType(payload) === "idle_prompt") return "low";
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
function mapHookPromptKind$1(event, payload) {
|
|
307
|
-
if (String(event || "").toLowerCase() !== "notification") return null;
|
|
308
|
-
const type = notificationType(payload);
|
|
309
|
-
if (type === "permission_prompt" || type === "approval_required") return "permission";
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
function sessionIdOf$1(payload) {
|
|
313
|
-
return payload?.sessionId;
|
|
314
|
-
}
|
|
315
|
-
function classifyTitle$1(title) {
|
|
316
|
-
const normalizedTitle = String(title || "");
|
|
317
|
-
if (isPathLikeTitle(normalizedTitle)) return "ignore";
|
|
318
|
-
if (isBrailleChar(firstCharOfTitle(normalizedTitle))) return "working";
|
|
319
|
-
if (normalizedTitle.startsWith(ACTION_REQUIRED_MARKER)) return "awaiting-input";
|
|
320
|
-
return "unknown";
|
|
321
|
-
}
|
|
322
|
-
var titleProfile$1 = {
|
|
323
|
-
classifyTitle: classifyTitle$1,
|
|
324
|
-
taskTitle: {
|
|
325
|
-
readsTranscriptTitle: false,
|
|
326
|
-
genericTitles: [ID$1],
|
|
327
|
-
agentSuffix: ` - ${ID$1}`
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
function grokHome(env = process.env, homedir = os.homedir(), platform = process.platform) {
|
|
331
|
-
const pathApi = platform === "win32" ? path.win32 : path;
|
|
332
|
-
const configuredHome = typeof env.GROK_HOME === "string" ? env.GROK_HOME.trim() : "";
|
|
333
|
-
if (configuredHome) return pathApi.resolve(configuredHome);
|
|
334
|
-
return pathApi.join(homedir, ".grok");
|
|
335
|
-
}
|
|
336
|
-
function hooksFilePath(env = process.env, homedir = os.homedir()) {
|
|
337
|
-
return path.join(grokHome(env, homedir), "hooks", "glimmervoid.json");
|
|
338
|
-
}
|
|
339
|
-
function nativeBinaryPath({ platform = process.platform, env = process.env, homedir = os.homedir() } = {}) {
|
|
340
|
-
const pathApi = platform === "win32" ? path.win32 : path;
|
|
341
|
-
const binaryName = platform === "win32" ? "grok.exe" : "grok";
|
|
342
|
-
return pathApi.join(grokHome(env, homedir, platform), "bin", binaryName);
|
|
343
|
-
}
|
|
344
|
-
function resolveCommand$1({ platform = process.platform, env = process.env, homedir = os.homedir(), existsSync = fs.existsSync, realpathSync = fs.realpathSync, warn = console.warn } = {}) {
|
|
345
|
-
const candidate = nativeBinaryPath({
|
|
346
|
-
platform,
|
|
347
|
-
env,
|
|
348
|
-
homedir
|
|
349
|
-
});
|
|
350
|
-
try {
|
|
351
|
-
if (existsSync(candidate)) return {
|
|
352
|
-
path: realpathSync(candidate),
|
|
353
|
-
kind: "exe"
|
|
354
|
-
};
|
|
355
|
-
} catch (error) {
|
|
356
|
-
warn(`[glimmervoid] could not resolve the native 'grok' binary at ${candidate}: ${errorMessage(error)}`);
|
|
357
|
-
return {
|
|
358
|
-
path: null,
|
|
359
|
-
kind: "unresolved"
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
warn(`[glimmervoid] could not resolve the native 'grok' binary at ${candidate}`);
|
|
363
|
-
return {
|
|
364
|
-
path: null,
|
|
365
|
-
kind: "unresolved"
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
function buildSpawnCommand$1({ resolved, settingsArgs = [], agentArgs = [] }) {
|
|
369
|
-
if (!resolved?.path) throw new Error("the native grok binary is not resolved");
|
|
370
|
-
return {
|
|
371
|
-
file: resolved.path,
|
|
372
|
-
args: [...settingsArgs, ...agentArgs]
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
function buildEnv$1(baseEnv, extraEnv, options) {
|
|
376
|
-
return buildAgentEnv(baseEnv, extraEnv, envProfile$1, options);
|
|
377
|
-
}
|
|
378
|
-
function buildArgs$1({ dangerouslySkipPermissions = false, resumeSessionId = null, extraArgs = [], initialPrompt = null } = {}) {
|
|
379
|
-
const args = ["--no-auto-update"];
|
|
380
|
-
if (dangerouslySkipPermissions) args.push("--always-approve");
|
|
381
|
-
if (resumeSessionId) args.push("-r", resumeSessionId);
|
|
382
|
-
if (extraArgs.length > 0) args.push(...extraArgs);
|
|
383
|
-
if (initialPrompt != null) args.push(initialPrompt);
|
|
384
|
-
return args;
|
|
385
|
-
}
|
|
386
|
-
var grok = {
|
|
387
|
-
id: ID$1,
|
|
388
|
-
label: "Grok Build",
|
|
389
|
-
usageVendor: "grok",
|
|
390
|
-
commandName: COMMAND_NAME$1,
|
|
391
|
-
envProfile: envProfile$1,
|
|
392
|
-
titleProfile: titleProfile$1,
|
|
393
|
-
hooks: {
|
|
394
|
-
mapSignal: mapHookToSignal$1,
|
|
395
|
-
mapConfidence: mapHookConfidence$1,
|
|
396
|
-
mapPromptKind: mapHookPromptKind$1,
|
|
397
|
-
mapPayload: mapHookPayload$1,
|
|
398
|
-
injection: {
|
|
399
|
-
kind: "home-hooks-file",
|
|
400
|
-
setupCommand: "glimmervoid agent setup grok",
|
|
401
|
-
filePath: hooksFilePath,
|
|
402
|
-
isSaneYoloReady: (contents) => contents === renderGrokHooksFile({
|
|
403
|
-
relayPath: RELAY_PATH$1,
|
|
404
|
-
events: HOOK_EVENTS$1,
|
|
405
|
-
hookToolRelayPath: HOOK_TOOL_RELAY_PATH$1
|
|
406
|
-
}),
|
|
407
|
-
classifyContents: (contents) => classifyGrokHooksFile(contents, {
|
|
408
|
-
relayPath: RELAY_PATH$1,
|
|
409
|
-
events: HOOK_EVENTS$1,
|
|
410
|
-
managedEventSets: MANAGED_HOOK_EVENT_SETS,
|
|
411
|
-
hookToolRelayPath: HOOK_TOOL_RELAY_PATH$1
|
|
412
|
-
}),
|
|
413
|
-
projectConfigCandidates: PROJECT_CONFIG_CANDIDATES,
|
|
414
|
-
userConfigFolders,
|
|
415
|
-
mayContributeHooks
|
|
416
|
-
}
|
|
417
|
-
},
|
|
418
|
-
resolveCommand: resolveCommand$1,
|
|
419
|
-
buildSpawnCommand: buildSpawnCommand$1,
|
|
420
|
-
buildEnv: buildEnv$1,
|
|
421
|
-
buildArgs: buildArgs$1,
|
|
422
|
-
sessionIdOf: sessionIdOf$1,
|
|
423
|
-
mapHookPayload: mapHookPayload$1,
|
|
424
|
-
mapHookToSignal: mapHookToSignal$1,
|
|
425
|
-
mapHookConfidence: mapHookConfidence$1,
|
|
426
|
-
mapHookPromptKind: mapHookPromptKind$1,
|
|
427
|
-
classifyTitle: classifyTitle$1,
|
|
428
|
-
grokHome,
|
|
429
|
-
hooksFilePath,
|
|
430
|
-
nativeBinaryPath,
|
|
431
|
-
mayContributeHooks,
|
|
432
|
-
PROJECT_CONFIG_CANDIDATES,
|
|
433
|
-
CLAUDE_COMPAT_HOOKS_ENV,
|
|
434
|
-
HOOK_TOOL_RELAY_PATH: HOOK_TOOL_RELAY_PATH$1,
|
|
435
|
-
HOOK_EVENTS: HOOK_EVENTS$1,
|
|
436
|
-
MANAGED_HOOK_EVENT_SETS,
|
|
437
|
-
RELAY_PATH: RELAY_PATH$1,
|
|
438
|
-
ACTION_REQUIRED_MARKER,
|
|
439
|
-
capabilities: {
|
|
440
|
-
hooks: true,
|
|
441
|
-
awaitingInput: true,
|
|
442
|
-
backgroundAgents: true,
|
|
443
|
-
resume: true,
|
|
444
|
-
statusLine: false,
|
|
445
|
-
rtk: false,
|
|
446
|
-
saneYolo: true,
|
|
447
|
-
compactQuiet: false,
|
|
448
|
-
skipPermissionsFlag: true,
|
|
449
|
-
headless: true
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
//#endregion
|
|
453
|
-
//#region session/core/kimi-hooks-block-core.ts
|
|
454
|
-
var BLOCK_START = "# >>> glimmervoid hooks (managed, inert outside Glimmervoid) >>>";
|
|
455
|
-
var BLOCK_END = "# <<< glimmervoid hooks <<<";
|
|
456
|
-
var MANAGED_LINE_PATTERNS = Object.freeze([
|
|
457
|
-
/^\[\[hooks\]\]$/,
|
|
458
|
-
/^event = "[A-Za-z][A-Za-z0-9_-]{0,63}"$/,
|
|
459
|
-
/^matcher = '\^[A-Za-z0-9_]+\$'$/,
|
|
460
|
-
/^command = 'node (?:"[^"'\r\n]*\/(?:hook-relay|hook-tool-relay)\.(?:js|ts)"|[^\s"']*\/(?:hook-relay|hook-tool-relay)\.(?:js|ts)) [A-Za-z][A-Za-z0-9_-]{0,63}(?: [A-Za-z0-9_-]+)*'$/
|
|
461
|
-
]);
|
|
462
|
-
function hookTable(event, command, matcher = null) {
|
|
463
|
-
const lines = ["[[hooks]]", `event = "${event}"`];
|
|
464
|
-
if (matcher !== null) lines.push(`matcher = '${matcher}'`);
|
|
465
|
-
lines.push(`command = '${command}'`);
|
|
466
|
-
return lines;
|
|
467
|
-
}
|
|
468
|
-
function renderKimiHooksBlock(options) {
|
|
469
|
-
const lines = [BLOCK_START];
|
|
470
|
-
for (const event of options.events) {
|
|
471
|
-
const command = buildHookCommand(options.relayPath, event);
|
|
472
|
-
if (!command) return null;
|
|
473
|
-
lines.push(...hookTable(event, command));
|
|
474
|
-
}
|
|
475
|
-
for (const event of options.toolEvents) {
|
|
476
|
-
const command = buildHookCommand(options.relayPath, event);
|
|
477
|
-
if (!command) return null;
|
|
478
|
-
for (const toolName of options.matchedToolNames) lines.push(...hookTable(event, command, `^${toolName}$`));
|
|
479
|
-
}
|
|
480
|
-
const saneYoloCommand = buildHookCommand(options.saneYolo.relayPath, "saneYolo", [options.saneYolo.agentFlavor]);
|
|
481
|
-
if (!saneYoloCommand) return null;
|
|
482
|
-
for (const toolName of options.saneYolo.toolNames) lines.push(...hookTable("PreToolUse", saneYoloCommand, `^${toolName}$`));
|
|
483
|
-
lines.push(BLOCK_END);
|
|
484
|
-
return `${lines.join("\n")}\n`;
|
|
485
|
-
}
|
|
486
|
-
function lineEndAfter(configText, index) {
|
|
487
|
-
const newlineIndex = configText.indexOf("\n", index);
|
|
488
|
-
return newlineIndex === -1 ? configText.length : newlineIndex + 1;
|
|
489
|
-
}
|
|
490
|
-
function locateBlock(configText) {
|
|
491
|
-
const lines = configText.split("\n");
|
|
492
|
-
let offset = 0;
|
|
493
|
-
let start = null;
|
|
494
|
-
let end = null;
|
|
495
|
-
for (const rawLine of lines) {
|
|
496
|
-
const line = rawLine.replace(/\r$/, "");
|
|
497
|
-
if (line === "# >>> glimmervoid hooks (managed, inert outside Glimmervoid) >>>") {
|
|
498
|
-
if (start !== null) return "foreign";
|
|
499
|
-
start = offset;
|
|
500
|
-
}
|
|
501
|
-
if (line === "# <<< glimmervoid hooks <<<") {
|
|
502
|
-
if (start === null || end !== null) return "foreign";
|
|
503
|
-
end = lineEndAfter(configText, offset);
|
|
504
|
-
}
|
|
505
|
-
offset += rawLine.length + 1;
|
|
506
|
-
}
|
|
507
|
-
if (start === null && end === null) return "absent";
|
|
508
|
-
if (start === null || end === null) return "foreign";
|
|
509
|
-
return {
|
|
510
|
-
start,
|
|
511
|
-
end
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
function isManagedBlockBody(blockText) {
|
|
515
|
-
return blockText.split("\n").map((line) => line.replace(/\r$/, "")).filter((line) => line !== "").slice(1, -1).every((line) => MANAGED_LINE_PATTERNS.some((pattern) => pattern.test(line)));
|
|
516
|
-
}
|
|
517
|
-
var TABLE_HEADER_PATTERN = /^\s*\[/;
|
|
518
|
-
var HOOKS_TABLE_HEADER_PATTERN = /^\s*\[\s*hooks\s*[\].]/;
|
|
519
|
-
var TOP_LEVEL_HOOKS_KEY_PATTERN = /^\s*hooks\s*[=.]/;
|
|
520
|
-
function definesHooksOutsideArrayTables(operatorText) {
|
|
521
|
-
let isAtTopLevel = true;
|
|
522
|
-
for (const line of operatorText.split("\n")) {
|
|
523
|
-
if (HOOKS_TABLE_HEADER_PATTERN.test(line)) return true;
|
|
524
|
-
if (TABLE_HEADER_PATTERN.test(line)) isAtTopLevel = false;
|
|
525
|
-
if (isAtTopLevel && TOP_LEVEL_HOOKS_KEY_PATTERN.test(line)) return true;
|
|
526
|
-
}
|
|
527
|
-
return false;
|
|
528
|
-
}
|
|
529
|
-
function classifyKimiConfig(configText, expectedBlock) {
|
|
530
|
-
if (configText === null) return "absent";
|
|
531
|
-
const span = locateBlock(configText);
|
|
532
|
-
if (span === "foreign") return span;
|
|
533
|
-
if (definesHooksOutsideArrayTables(span === "absent" ? configText : `${configText.slice(0, span.start)}${configText.slice(span.end)}`)) return "conflicting";
|
|
534
|
-
if (span === "absent") return span;
|
|
535
|
-
const blockText = configText.slice(span.start, span.end);
|
|
536
|
-
if (blockText === expectedBlock) return "current";
|
|
537
|
-
if (isManagedBlockBody(blockText)) return "managed-stale";
|
|
538
|
-
return "foreign";
|
|
539
|
-
}
|
|
540
|
-
function spliceKimiHooksBlock(configText, block) {
|
|
541
|
-
if (configText === null || configText === "") return {
|
|
542
|
-
contents: block,
|
|
543
|
-
changed: true
|
|
544
|
-
};
|
|
545
|
-
const classification = classifyKimiConfig(configText, block);
|
|
546
|
-
if (classification === "current") return {
|
|
547
|
-
contents: configText,
|
|
548
|
-
changed: false
|
|
549
|
-
};
|
|
550
|
-
if (classification === "foreign" || classification === "conflicting") return { refused: classification };
|
|
551
|
-
if (classification === "absent") return {
|
|
552
|
-
contents: `${configText}${configText.endsWith("\n") ? "\n" : "\n\n"}${block}`,
|
|
553
|
-
changed: true
|
|
554
|
-
};
|
|
555
|
-
const span = locateBlock(configText);
|
|
556
|
-
if (span === "absent" || span === "foreign") return { refused: "foreign" };
|
|
557
|
-
return {
|
|
558
|
-
contents: `${configText.slice(0, span.start)}${block}${configText.slice(span.end)}`,
|
|
559
|
-
changed: true
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
var KIMI_CONFIG_NAME = "config.toml";
|
|
563
|
-
var KIMI_SOURCES_NAME = ".glimmervoid-sources.json";
|
|
564
|
-
var KIMI_CONFLICTS_NAME = ".glimmervoid-conflicts";
|
|
565
|
-
var GENERATED_ONLY_NAMES = /* @__PURE__ */ new Set([
|
|
566
|
-
KIMI_CONFIG_NAME,
|
|
567
|
-
KIMI_SOURCES_NAME,
|
|
568
|
-
KIMI_CONFLICTS_NAME
|
|
569
|
-
]);
|
|
570
|
-
var FILE_STAMP_PREFIX = "file:";
|
|
571
|
-
function generatedKimiConfig(realConfigText, hooksBlock) {
|
|
572
|
-
const configText = realConfigText ?? "";
|
|
573
|
-
const span = locateBlock(configText);
|
|
574
|
-
if (span === "foreign") return { refusal: "its Glimmervoid hooks block markers are unbalanced" };
|
|
575
|
-
const operatorText = span === "absent" ? configText : `${configText.slice(0, span.start)}${configText.slice(span.end)}`;
|
|
576
|
-
if (definesHooksOutsideArrayTables(operatorText)) return { refusal: "it defines hooks as a key or [hooks] table, which a [[hooks]] block cannot extend" };
|
|
577
|
-
const spliced = spliceKimiHooksBlock(operatorText, hooksBlock);
|
|
578
|
-
if ("refused" in spliced) return { refusal: `its hooks are ${spliced.refused}` };
|
|
579
|
-
return {
|
|
580
|
-
text: spliced.contents,
|
|
581
|
-
hadBlock: span !== "absent"
|
|
582
|
-
};
|
|
583
|
-
}
|
|
584
|
-
function configSourceStamp(realConfigText, hooksBlock) {
|
|
585
|
-
return createHash("sha256").update(realConfigText ?? "").update("\0").update(hooksBlock).digest("hex");
|
|
586
|
-
}
|
|
587
|
-
function linkKindFor(kind, platform) {
|
|
588
|
-
if (platform !== "win32") return "symlink";
|
|
589
|
-
return kind === "folder" ? "junction" : "hardlink";
|
|
590
|
-
}
|
|
591
|
-
function fileStampKey(name) {
|
|
592
|
-
return `${FILE_STAMP_PREFIX}${name}`;
|
|
593
|
-
}
|
|
594
|
-
function planReplacedFile(real, target, lastFileStamp) {
|
|
595
|
-
if (real.fileStamp !== null && real.fileStamp === lastFileStamp) return {
|
|
596
|
-
kind: "promote",
|
|
597
|
-
name: real.name,
|
|
598
|
-
target
|
|
599
|
-
};
|
|
600
|
-
return {
|
|
601
|
-
kind: "set-aside",
|
|
602
|
-
name: real.name
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
function planPrivateFolder(real, generated, target) {
|
|
606
|
-
const realChildNames = new Set(real.childNames);
|
|
607
|
-
if (generated.childNames.some((childName) => realChildNames.has(childName))) return "private";
|
|
608
|
-
return {
|
|
609
|
-
kind: "adopt",
|
|
610
|
-
name: real.name,
|
|
611
|
-
target,
|
|
612
|
-
childNames: generated.childNames
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
function planEntryLink(real, generated, inputs) {
|
|
616
|
-
const target = path.join(inputs.realHome, real.name);
|
|
617
|
-
const link = {
|
|
618
|
-
kind: "link",
|
|
619
|
-
name: real.name,
|
|
620
|
-
target,
|
|
621
|
-
linkKind: linkKindFor(real.kind, inputs.platform)
|
|
622
|
-
};
|
|
623
|
-
if (!generated) return [link];
|
|
624
|
-
if (generated.kind === "link") return generated.linkTarget === target ? [] : [{
|
|
625
|
-
kind: "unlink",
|
|
626
|
-
name: real.name
|
|
627
|
-
}, link];
|
|
628
|
-
if (generated.kind === "file" && real.kind === "file") return [planReplacedFile(real, target, inputs.sourceStamps[fileStampKey(real.name)]), link];
|
|
629
|
-
if (generated.kind !== "folder" || real.kind !== "folder") return "private";
|
|
630
|
-
const adoption = planPrivateFolder(real, generated, target);
|
|
631
|
-
return adoption === "private" ? adoption : [adoption, link];
|
|
632
|
-
}
|
|
633
|
-
function planKimiHome(inputs) {
|
|
634
|
-
const config = generatedKimiConfig(inputs.realConfigText, inputs.hooksBlock);
|
|
635
|
-
if ("refusal" in config) return {
|
|
636
|
-
kind: "refused",
|
|
637
|
-
reason: `the real ${KIMI_CONFIG_NAME} cannot take the hooks block: ${config.refusal}`
|
|
638
|
-
};
|
|
639
|
-
const steps = [];
|
|
640
|
-
const configStamp = configSourceStamp(inputs.realConfigText, inputs.hooksBlock);
|
|
641
|
-
if (!(inputs.generatedConfigText !== null && inputs.sourceStamps["config.toml"] === configStamp && classifyKimiConfig(inputs.generatedConfigText, inputs.hooksBlock) === "current")) steps.push({
|
|
642
|
-
kind: "write-config",
|
|
643
|
-
text: config.text
|
|
644
|
-
});
|
|
645
|
-
const generatedByName = new Map(inputs.generatedEntries.map((entry) => [entry.name, entry]));
|
|
646
|
-
const realNames = /* @__PURE__ */ new Set();
|
|
647
|
-
const privateNames = [];
|
|
648
|
-
for (const real of inputs.realEntries) {
|
|
649
|
-
if (GENERATED_ONLY_NAMES.has(real.name)) continue;
|
|
650
|
-
realNames.add(real.name);
|
|
651
|
-
const entrySteps = planEntryLink(real, generatedByName.get(real.name), inputs);
|
|
652
|
-
if (entrySteps === "private") {
|
|
653
|
-
privateNames.push(real.name);
|
|
654
|
-
continue;
|
|
655
|
-
}
|
|
656
|
-
steps.push(...entrySteps);
|
|
657
|
-
}
|
|
658
|
-
for (const generated of inputs.generatedEntries) if (generated.kind === "link" && !realNames.has(generated.name)) steps.push({
|
|
659
|
-
kind: "unlink",
|
|
660
|
-
name: generated.name
|
|
661
|
-
});
|
|
662
|
-
return {
|
|
663
|
-
kind: "ready",
|
|
664
|
-
steps,
|
|
665
|
-
sourceStamps: { [KIMI_CONFIG_NAME]: configStamp },
|
|
666
|
-
privateNames,
|
|
667
|
-
hasStaleBlockInRealConfig: config.hadBlock
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
//#endregion
|
|
671
|
-
//#region session/kimi-home.ts
|
|
672
|
-
var GENERATED_HOME_MODE = 448;
|
|
673
|
-
var GENERATED_FILE_MODE = 384;
|
|
674
|
-
function realKimiHome(env = process.env, homeDir = os.homedir()) {
|
|
675
|
-
const configuredHome = typeof env.KIMI_CODE_HOME === "string" ? env.KIMI_CODE_HOME.trim() : "";
|
|
676
|
-
if (configuredHome) return path.resolve(configuredHome);
|
|
677
|
-
return path.join(homeDir, ".kimi-code");
|
|
678
|
-
}
|
|
679
|
-
function generatedKimiHomePath(env = process.env, homeDir = os.homedir()) {
|
|
680
|
-
return path.join(glimmervoidHomeDir(homeDir, env), "agent-homes", "kimi");
|
|
681
|
-
}
|
|
682
|
-
function listFolder(folder) {
|
|
683
|
-
try {
|
|
684
|
-
return fs.readdirSync(folder, { withFileTypes: true });
|
|
685
|
-
} catch (error) {
|
|
686
|
-
if (isMissingFileError(error)) return [];
|
|
687
|
-
throw error;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
function statOrNull(entryPath) {
|
|
691
|
-
try {
|
|
692
|
-
return fs.statSync(entryPath);
|
|
693
|
-
} catch {
|
|
694
|
-
return null;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
function fileStampOf(entryStat) {
|
|
698
|
-
return `${entryStat.size}:${entryStat.mtimeMs}`;
|
|
699
|
-
}
|
|
700
|
-
function childNamesOf(folder) {
|
|
701
|
-
return listFolder(folder).map((dirent) => dirent.name);
|
|
702
|
-
}
|
|
703
|
-
function listRealEntries(realHome, privateFolderNames) {
|
|
704
|
-
const entries = [];
|
|
705
|
-
for (const dirent of listFolder(realHome)) {
|
|
706
|
-
const entryPath = path.join(realHome, dirent.name);
|
|
707
|
-
const entryStat = statOrNull(entryPath);
|
|
708
|
-
if (!entryStat) continue;
|
|
709
|
-
if (entryStat.isDirectory()) {
|
|
710
|
-
const childNames = privateFolderNames.has(dirent.name) ? childNamesOf(entryPath) : [];
|
|
711
|
-
entries.push({
|
|
712
|
-
name: dirent.name,
|
|
713
|
-
kind: "folder",
|
|
714
|
-
fileStamp: null,
|
|
715
|
-
childNames
|
|
716
|
-
});
|
|
717
|
-
continue;
|
|
718
|
-
}
|
|
719
|
-
entries.push({
|
|
720
|
-
name: dirent.name,
|
|
721
|
-
kind: "file",
|
|
722
|
-
fileStamp: fileStampOf(entryStat),
|
|
723
|
-
childNames: []
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
return entries;
|
|
727
|
-
}
|
|
728
|
-
function isSameFile(first, second) {
|
|
729
|
-
return first.dev === second.dev && first.ino === second.ino;
|
|
730
|
-
}
|
|
731
|
-
function hardLinkTarget(entryStat, realHome, name) {
|
|
732
|
-
if (entryStat.nlink < 2) return null;
|
|
733
|
-
const realPath = path.join(realHome, name);
|
|
734
|
-
try {
|
|
735
|
-
return isSameFile(entryStat, fs.statSync(realPath)) ? realPath : null;
|
|
736
|
-
} catch {
|
|
737
|
-
return null;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
function describeGeneratedEntry(generatedHome, realHome, name) {
|
|
741
|
-
const entryPath = path.join(generatedHome, name);
|
|
742
|
-
const entryStat = fs.lstatSync(entryPath);
|
|
743
|
-
if (entryStat.isSymbolicLink()) return {
|
|
744
|
-
name,
|
|
745
|
-
kind: "link",
|
|
746
|
-
linkTarget: path.resolve(generatedHome, fs.readlinkSync(entryPath)),
|
|
747
|
-
childNames: []
|
|
748
|
-
};
|
|
749
|
-
if (entryStat.isDirectory()) return {
|
|
750
|
-
name,
|
|
751
|
-
kind: "folder",
|
|
752
|
-
linkTarget: null,
|
|
753
|
-
childNames: childNamesOf(entryPath)
|
|
754
|
-
};
|
|
755
|
-
const hardLinkedTo = hardLinkTarget(entryStat, realHome, name);
|
|
756
|
-
if (hardLinkedTo) return {
|
|
757
|
-
name,
|
|
758
|
-
kind: "link",
|
|
759
|
-
linkTarget: hardLinkedTo,
|
|
760
|
-
childNames: []
|
|
761
|
-
};
|
|
762
|
-
return {
|
|
763
|
-
name,
|
|
764
|
-
kind: "file",
|
|
765
|
-
linkTarget: null,
|
|
766
|
-
childNames: []
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
function readOptionalText(filePath) {
|
|
770
|
-
try {
|
|
771
|
-
return fs.readFileSync(filePath, "utf8");
|
|
772
|
-
} catch (error) {
|
|
773
|
-
if (isMissingFileError(error)) return null;
|
|
774
|
-
throw error;
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
function readRealConfig(realHome) {
|
|
778
|
-
const configPath = path.join(realHome, KIMI_CONFIG_NAME);
|
|
779
|
-
try {
|
|
780
|
-
return { text: fs.readFileSync(configPath, "utf8") };
|
|
781
|
-
} catch (error) {
|
|
782
|
-
if (isMissingFileError(error)) return { text: null };
|
|
783
|
-
return { refusal: `the real ${configPath} cannot be read: ${errorMessage(error)}` };
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
function readSourceStamps(generatedHome) {
|
|
787
|
-
try {
|
|
788
|
-
const parsed = JSON.parse(fs.readFileSync(path.join(generatedHome, KIMI_SOURCES_NAME), "utf8"));
|
|
789
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
790
|
-
return Object.fromEntries(Object.entries(parsed).filter((entry) => typeof entry[1] === "string"));
|
|
791
|
-
} catch {
|
|
792
|
-
return {};
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
function inspectKimiHome(options) {
|
|
796
|
-
const realHome = realKimiHome(options.env, options.homeDir);
|
|
797
|
-
const generatedHome = generatedKimiHomePath(options.env, options.homeDir);
|
|
798
|
-
try {
|
|
799
|
-
return {
|
|
800
|
-
generatedHome,
|
|
801
|
-
realHome,
|
|
802
|
-
plan: planFromDisk(options, realHome, generatedHome)
|
|
803
|
-
};
|
|
804
|
-
} catch (error) {
|
|
805
|
-
return {
|
|
806
|
-
generatedHome,
|
|
807
|
-
realHome,
|
|
808
|
-
plan: {
|
|
809
|
-
kind: "refused",
|
|
810
|
-
reason: `${realHome} or ${generatedHome} cannot be listed: ${errorMessage(error)}`
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
function planFromDisk({ hooksBlock, platform = process.platform }, realHome, generatedHome) {
|
|
816
|
-
const realConfig = readRealConfig(realHome);
|
|
817
|
-
if ("refusal" in realConfig) return {
|
|
818
|
-
kind: "refused",
|
|
819
|
-
reason: realConfig.refusal
|
|
820
|
-
};
|
|
821
|
-
const generatedEntries = childNamesOf(generatedHome).map((name) => describeGeneratedEntry(generatedHome, realHome, name));
|
|
822
|
-
return planKimiHome({
|
|
823
|
-
realHome,
|
|
824
|
-
realEntries: listRealEntries(realHome, new Set(generatedEntries.filter((entry) => entry.kind === "folder").map((entry) => entry.name))),
|
|
825
|
-
generatedEntries,
|
|
826
|
-
realConfigText: realConfig.text,
|
|
827
|
-
generatedConfigText: readOptionalText(path.join(generatedHome, KIMI_CONFIG_NAME)),
|
|
828
|
-
hooksBlock,
|
|
829
|
-
sourceStamps: readSourceStamps(generatedHome),
|
|
830
|
-
platform
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
function stepEntryPath(generatedHome, step) {
|
|
834
|
-
return path.join(generatedHome, step.kind === "write-config" ? KIMI_CONFIG_NAME : step.name);
|
|
835
|
-
}
|
|
836
|
-
function promoteIntoRealHome(entryPath, target) {
|
|
837
|
-
const resolvedTarget = fs.realpathSync(target);
|
|
838
|
-
const stagedPath = `${resolvedTarget}.glimmervoid-${process.pid}`;
|
|
839
|
-
try {
|
|
840
|
-
fs.copyFileSync(entryPath, stagedPath);
|
|
841
|
-
fs.chmodSync(stagedPath, fs.statSync(resolvedTarget).mode & 511);
|
|
842
|
-
fs.renameSync(stagedPath, resolvedTarget);
|
|
843
|
-
} catch (error) {
|
|
844
|
-
fs.rmSync(stagedPath, { force: true });
|
|
845
|
-
throw error;
|
|
846
|
-
}
|
|
847
|
-
fs.unlinkSync(entryPath);
|
|
848
|
-
}
|
|
849
|
-
function setAside(generatedHome, entryPath, name) {
|
|
850
|
-
const conflictsFolder = path.join(generatedHome, KIMI_CONFLICTS_NAME);
|
|
851
|
-
fs.mkdirSync(conflictsFolder, {
|
|
852
|
-
recursive: true,
|
|
853
|
-
mode: GENERATED_HOME_MODE
|
|
854
|
-
});
|
|
855
|
-
let copyNumber = 1;
|
|
856
|
-
while (fs.existsSync(path.join(conflictsFolder, `${name}.${copyNumber}`))) copyNumber += 1;
|
|
857
|
-
fs.renameSync(entryPath, path.join(conflictsFolder, `${name}.${copyNumber}`));
|
|
858
|
-
}
|
|
859
|
-
function moveAcrossVolumes(source, destination) {
|
|
860
|
-
try {
|
|
861
|
-
fs.renameSync(source, destination);
|
|
862
|
-
} catch (error) {
|
|
863
|
-
if (!(error instanceof Error && "code" in error && error.code === "EXDEV")) throw error;
|
|
864
|
-
fs.cpSync(source, destination, {
|
|
865
|
-
recursive: true,
|
|
866
|
-
errorOnExist: true,
|
|
867
|
-
force: false,
|
|
868
|
-
preserveTimestamps: true
|
|
869
|
-
});
|
|
870
|
-
fs.rmSync(source, { recursive: true });
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
function adoptFolder(entryPath, target, childNames) {
|
|
874
|
-
for (const childName of childNames) moveAcrossVolumes(path.join(entryPath, childName), path.join(target, childName));
|
|
875
|
-
fs.rmdirSync(entryPath);
|
|
876
|
-
}
|
|
877
|
-
function applyStep(generatedHome, step) {
|
|
878
|
-
const entryPath = stepEntryPath(generatedHome, step);
|
|
879
|
-
switch (step.kind) {
|
|
880
|
-
case "write-config":
|
|
881
|
-
writeTextAtomicSync(entryPath, step.text, {
|
|
882
|
-
mode: GENERATED_FILE_MODE,
|
|
883
|
-
enforceMode: true
|
|
884
|
-
});
|
|
885
|
-
return;
|
|
886
|
-
case "unlink":
|
|
887
|
-
fs.unlinkSync(entryPath);
|
|
888
|
-
return;
|
|
889
|
-
case "promote":
|
|
890
|
-
promoteIntoRealHome(entryPath, step.target);
|
|
891
|
-
return;
|
|
892
|
-
case "set-aside":
|
|
893
|
-
setAside(generatedHome, entryPath, step.name);
|
|
894
|
-
return;
|
|
895
|
-
case "adopt":
|
|
896
|
-
adoptFolder(entryPath, step.target, step.childNames);
|
|
897
|
-
return;
|
|
898
|
-
}
|
|
899
|
-
if (step.linkKind === "hardlink") {
|
|
900
|
-
fs.linkSync(step.target, entryPath);
|
|
901
|
-
return;
|
|
902
|
-
}
|
|
903
|
-
fs.symlinkSync(step.target, entryPath, step.linkKind === "junction" ? "junction" : void 0);
|
|
904
|
-
}
|
|
905
|
-
function stepFailure(generatedHome, step, error) {
|
|
906
|
-
const entryPath = stepEntryPath(generatedHome, step);
|
|
907
|
-
if (step.kind === "link") return `${entryPath} cannot be linked to ${step.target}: ${errorMessage(error)}`;
|
|
908
|
-
if (step.kind === "promote") return `${entryPath} cannot be moved into ${step.target}: ${errorMessage(error)}`;
|
|
909
|
-
return `${entryPath} cannot be written: ${errorMessage(error)}`;
|
|
910
|
-
}
|
|
911
|
-
function realFileStamps(realHome) {
|
|
912
|
-
const stamps = {};
|
|
913
|
-
for (const entry of listRealEntries(realHome, /* @__PURE__ */ new Set())) if (entry.fileStamp !== null) stamps[fileStampKey(entry.name)] = entry.fileStamp;
|
|
914
|
-
return stamps;
|
|
915
|
-
}
|
|
916
|
-
function prepareKimiHome(options) {
|
|
917
|
-
const generatedHome = generatedKimiHomePath(options.env, options.homeDir);
|
|
918
|
-
try {
|
|
919
|
-
fs.mkdirSync(generatedHome, {
|
|
920
|
-
recursive: true,
|
|
921
|
-
mode: GENERATED_HOME_MODE
|
|
922
|
-
});
|
|
923
|
-
fs.chmodSync(generatedHome, GENERATED_HOME_MODE);
|
|
924
|
-
} catch (error) {
|
|
925
|
-
return { refusal: `${generatedHome} cannot be created: ${errorMessage(error)}` };
|
|
926
|
-
}
|
|
927
|
-
const { plan } = inspectKimiHome(options);
|
|
928
|
-
if (plan.kind === "refused") return { refusal: plan.reason };
|
|
929
|
-
const keptPrivateNames = /* @__PURE__ */ new Set();
|
|
930
|
-
for (const step of plan.steps) {
|
|
931
|
-
if (step.kind !== "write-config" && keptPrivateNames.has(step.name)) continue;
|
|
932
|
-
try {
|
|
933
|
-
applyStep(generatedHome, step);
|
|
934
|
-
} catch (error) {
|
|
935
|
-
if (step.kind !== "adopt") return { refusal: stepFailure(generatedHome, step, error) };
|
|
936
|
-
keptPrivateNames.add(step.name);
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
const realHome = realKimiHome(options.env, options.homeDir);
|
|
940
|
-
try {
|
|
941
|
-
const sourceStamps = {
|
|
942
|
-
...plan.sourceStamps,
|
|
943
|
-
...realFileStamps(realHome)
|
|
944
|
-
};
|
|
945
|
-
writeTextAtomicSync(path.join(generatedHome, KIMI_SOURCES_NAME), `${JSON.stringify(sourceStamps, null, 2)}\n`, { mode: GENERATED_FILE_MODE });
|
|
946
|
-
} catch (error) {
|
|
947
|
-
return { refusal: `${path.join(generatedHome, KIMI_SOURCES_NAME)} cannot be written: ${errorMessage(error)}` };
|
|
948
|
-
}
|
|
949
|
-
return { home: generatedHome };
|
|
950
|
-
}
|
|
951
|
-
//#endregion
|
|
952
|
-
//#region session/adapters/kimi.ts
|
|
953
|
-
var ID = "kimi";
|
|
954
|
-
var COMMAND_NAME = "kimi";
|
|
955
|
-
var HOME_ENV_NAME = "KIMI_CODE_HOME";
|
|
956
|
-
var RELAY_PATH = relayPath("hook-relay");
|
|
957
|
-
var HOOK_TOOL_RELAY_PATH = relayPath("hook-tool-relay");
|
|
958
|
-
var HOOK_EVENTS = Object.freeze([
|
|
959
|
-
"SessionStart",
|
|
960
|
-
"SessionEnd",
|
|
961
|
-
"UserPromptSubmit",
|
|
962
|
-
"Stop",
|
|
963
|
-
"StopFailure",
|
|
964
|
-
"Interrupt",
|
|
965
|
-
"PermissionRequest",
|
|
966
|
-
"PermissionResult",
|
|
967
|
-
"PreCompact",
|
|
968
|
-
"PostCompact"
|
|
969
|
-
]);
|
|
970
|
-
var TOOL_EVENTS = Object.freeze(["PreToolUse", "PostToolUse"]);
|
|
971
|
-
var SUBAGENT_TOOL_NAME = "Agent";
|
|
972
|
-
var MATCHED_TOOL_NAMES = Object.freeze([ASK_USER_QUESTION_TOOL_NAME, SUBAGENT_TOOL_NAME]);
|
|
973
|
-
var SHELL_TOOL_NAMES = Object.freeze(["Bash"]);
|
|
974
|
-
var envProfile = {
|
|
975
|
-
scrub: [],
|
|
976
|
-
set: { KIMI_CODE_NO_AUTO_UPDATE: "1" }
|
|
977
|
-
};
|
|
978
|
-
function isAskUserQuestion(payload) {
|
|
979
|
-
return payload?.tool_name === ASK_USER_QUESTION_TOOL_NAME;
|
|
980
|
-
}
|
|
981
|
-
function isSubagentToolCall(payload) {
|
|
982
|
-
return payload?.tool_name === SUBAGENT_TOOL_NAME && typeof payload.tool_call_id === "string";
|
|
983
|
-
}
|
|
984
|
-
var TOOL_EVENT_SIGNALS = {
|
|
985
|
-
pretooluse: {
|
|
986
|
-
question: "awaiting-input",
|
|
987
|
-
subagent: "subagent-start"
|
|
988
|
-
},
|
|
989
|
-
posttooluse: {
|
|
990
|
-
question: "working",
|
|
991
|
-
subagent: "subagent-stop"
|
|
992
|
-
}
|
|
993
|
-
};
|
|
994
|
-
function mapToolEventSignal(normalizedEvent, payload) {
|
|
995
|
-
const signals = TOOL_EVENT_SIGNALS[normalizedEvent];
|
|
996
|
-
if (!signals) return null;
|
|
997
|
-
if (isAskUserQuestion(payload)) return signals.question;
|
|
998
|
-
if (isSubagentToolCall(payload)) return signals.subagent;
|
|
999
|
-
return null;
|
|
1000
|
-
}
|
|
1001
|
-
function mapHookPayload(_event, payload) {
|
|
1002
|
-
if (!isSubagentToolCall(payload)) return payload;
|
|
1003
|
-
return {
|
|
1004
|
-
...payload,
|
|
1005
|
-
agent_id: payload.tool_call_id
|
|
1006
|
-
};
|
|
1007
|
-
}
|
|
1008
|
-
function mapHookToSignal(event, payload) {
|
|
1009
|
-
const normalizedEvent = String(event || "").toLowerCase();
|
|
1010
|
-
switch (normalizedEvent) {
|
|
1011
|
-
case "sessionstart": return "session-start";
|
|
1012
|
-
case "sessionend": return "session-end";
|
|
1013
|
-
case "userpromptsubmit": return "resume";
|
|
1014
|
-
case "stop":
|
|
1015
|
-
case "stopfailure":
|
|
1016
|
-
case "interrupt": return "ready";
|
|
1017
|
-
case "permissionrequest": return "awaiting-input";
|
|
1018
|
-
case "permissionresult": return "working";
|
|
1019
|
-
case "pretooluse":
|
|
1020
|
-
case "posttooluse": return mapToolEventSignal(normalizedEvent, payload);
|
|
1021
|
-
case "precompact": return "compaction-start";
|
|
1022
|
-
case "postcompact": return "compaction-end";
|
|
1023
|
-
default: return null;
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
function mapHookConfidence() {
|
|
1027
|
-
return null;
|
|
1028
|
-
}
|
|
1029
|
-
function mapHookPromptKind(event, payload) {
|
|
1030
|
-
const normalizedEvent = String(event || "").toLowerCase();
|
|
1031
|
-
if (normalizedEvent === "permissionrequest") return "permission";
|
|
1032
|
-
if (normalizedEvent === "pretooluse" && isAskUserQuestion(payload)) return "elicitation";
|
|
1033
|
-
return null;
|
|
1034
|
-
}
|
|
1035
|
-
function sessionIdOf(payload) {
|
|
1036
|
-
return payload?.session_id;
|
|
1037
|
-
}
|
|
1038
|
-
function classifyTitle() {
|
|
1039
|
-
return "unknown";
|
|
1040
|
-
}
|
|
1041
|
-
var titleProfile = {
|
|
1042
|
-
classifyTitle,
|
|
1043
|
-
taskTitle: {
|
|
1044
|
-
readsTranscriptTitle: false,
|
|
1045
|
-
genericTitles: [ID, "Kimi Code"],
|
|
1046
|
-
agentSuffix: null
|
|
1047
|
-
}
|
|
1048
|
-
};
|
|
1049
|
-
function configFilePath(env = process.env, homedir) {
|
|
1050
|
-
return path.join(realKimiHome(env, homedir), "config.toml");
|
|
1051
|
-
}
|
|
1052
|
-
function expectedHooksBlock() {
|
|
1053
|
-
return renderKimiHooksBlock({
|
|
1054
|
-
relayPath: RELAY_PATH,
|
|
1055
|
-
events: HOOK_EVENTS,
|
|
1056
|
-
toolEvents: TOOL_EVENTS,
|
|
1057
|
-
matchedToolNames: MATCHED_TOOL_NAMES,
|
|
1058
|
-
saneYolo: {
|
|
1059
|
-
relayPath: HOOK_TOOL_RELAY_PATH,
|
|
1060
|
-
toolNames: SHELL_TOOL_NAMES,
|
|
1061
|
-
agentFlavor: KIMI_SANE_YOLO_FLAVOR
|
|
1062
|
-
}
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
function prepareHome(env) {
|
|
1066
|
-
const hooksBlock = expectedHooksBlock();
|
|
1067
|
-
if (hooksBlock === null) return { refusal: "the hook relay path cannot be written into a kimi hooks block" };
|
|
1068
|
-
return prepareKimiHome({
|
|
1069
|
-
env,
|
|
1070
|
-
hooksBlock
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
var WINDOWS_SHAPED_ROOT = /^(?:[A-Za-z]:\/|\/\/)/;
|
|
1074
|
-
var MAX_WORKSPACE_SLUG_LENGTH = 40;
|
|
1075
|
-
function slugifyWorkspaceName(name) {
|
|
1076
|
-
const slug = name.toLowerCase().replaceAll(/[^a-z0-9._-]+/g, "-").replaceAll(/^-+|-+$/g, "").slice(0, MAX_WORKSPACE_SLUG_LENGTH).replaceAll(/^-+|-+$/g, "");
|
|
1077
|
-
return slug === "" || slug === "." || slug === ".." ? "workspace" : slug;
|
|
1078
|
-
}
|
|
1079
|
-
function workspaceTrustKey(cwd) {
|
|
1080
|
-
const resolved = path.resolve(cwd).replaceAll("\\", "/");
|
|
1081
|
-
const trimmed = resolved.replace(/\/+$/, "");
|
|
1082
|
-
const normalized = ((WINDOWS_SHAPED_ROOT.test(resolved) ? trimmed.toLowerCase() : trimmed) || resolved).replace(/\/+$/, "");
|
|
1083
|
-
return `wd_${slugifyWorkspaceName(normalized.split("/").pop() ?? normalized)}_${createHash("sha256").update(normalized).digest("hex").slice(0, 12)}`;
|
|
1084
|
-
}
|
|
1085
|
-
function physicalPathOf(cwd) {
|
|
1086
|
-
try {
|
|
1087
|
-
return fs.realpathSync(cwd);
|
|
1088
|
-
} catch {
|
|
1089
|
-
return null;
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
function isWorkspaceTrusted(cwd, env = process.env) {
|
|
1093
|
-
const physicalCwd = physicalPathOf(cwd);
|
|
1094
|
-
if (physicalCwd === null) return false;
|
|
1095
|
-
return fs.existsSync(path.join(realKimiHome(env), "workspace-trust", workspaceTrustKey(physicalCwd)));
|
|
1096
|
-
}
|
|
1097
|
-
function resolveCommand({ platform, execFile = execFileSync, pathExists = fs.existsSync } = {}) {
|
|
1098
|
-
return resolveAgentCommand({
|
|
1099
|
-
name: COMMAND_NAME,
|
|
1100
|
-
platform: platform || process.platform,
|
|
1101
|
-
execFile,
|
|
1102
|
-
pathExists
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
function buildSpawnCommand({ platform, resolved, settingsArgs = [], agentArgs = [] }) {
|
|
1106
|
-
return buildAgentSpawnCommand({
|
|
1107
|
-
name: COMMAND_NAME,
|
|
1108
|
-
platform,
|
|
1109
|
-
resolved,
|
|
1110
|
-
argGroups: [settingsArgs, agentArgs]
|
|
1111
|
-
});
|
|
1112
|
-
}
|
|
1113
|
-
function buildEnv(baseEnv, extraEnv, options) {
|
|
1114
|
-
return buildAgentEnv(baseEnv, extraEnv, envProfile, options);
|
|
1115
|
-
}
|
|
1116
|
-
function buildArgs({ dangerouslySkipPermissions = false, resumeSessionId = null, extraArgs = [] } = {}) {
|
|
1117
|
-
const args = dangerouslySkipPermissions ? ["--yolo"] : [];
|
|
1118
|
-
if (resumeSessionId) args.push("-S", resumeSessionId);
|
|
1119
|
-
if (extraArgs.length > 0) args.push(...extraArgs);
|
|
1120
|
-
return args;
|
|
1121
|
-
}
|
|
1122
|
-
var kimi = {
|
|
1123
|
-
id: ID,
|
|
1124
|
-
label: "Kimi Code",
|
|
1125
|
-
usageVendor: "kimi",
|
|
1126
|
-
commandName: COMMAND_NAME,
|
|
1127
|
-
envProfile,
|
|
1128
|
-
titleProfile,
|
|
1129
|
-
hooks: {
|
|
1130
|
-
mapSignal: mapHookToSignal,
|
|
1131
|
-
mapConfidence: mapHookConfidence,
|
|
1132
|
-
mapPromptKind: mapHookPromptKind,
|
|
1133
|
-
mapPayload: mapHookPayload,
|
|
1134
|
-
injection: {
|
|
1135
|
-
kind: "generated-home",
|
|
1136
|
-
homeEnvName: HOME_ENV_NAME,
|
|
1137
|
-
prepareHome
|
|
1138
|
-
}
|
|
1139
|
-
},
|
|
1140
|
-
resolveCommand,
|
|
1141
|
-
buildSpawnCommand,
|
|
1142
|
-
buildEnv,
|
|
1143
|
-
buildArgs,
|
|
1144
|
-
sessionIdOf,
|
|
1145
|
-
isWorkspaceTrusted,
|
|
1146
|
-
workspaceTrustKey,
|
|
1147
|
-
mapHookToSignal,
|
|
1148
|
-
mapHookPayload,
|
|
1149
|
-
configFilePath,
|
|
1150
|
-
expectedHooksBlock,
|
|
1151
|
-
capabilities: {
|
|
1152
|
-
hooks: true,
|
|
1153
|
-
awaitingInput: true,
|
|
1154
|
-
backgroundAgents: true,
|
|
1155
|
-
resume: true,
|
|
1156
|
-
statusLine: false,
|
|
1157
|
-
rtk: false,
|
|
1158
|
-
saneYolo: true,
|
|
1159
|
-
compactQuiet: true,
|
|
1160
|
-
skipPermissionsFlag: true,
|
|
1161
|
-
headless: true,
|
|
1162
|
-
subagentTurnStops: true,
|
|
1163
|
-
ptyInitialPrompt: true,
|
|
1164
|
-
promptContextSupervision: true
|
|
1165
|
-
}
|
|
1166
|
-
};
|
|
1167
|
-
//#endregion
|
|
1168
|
-
export { classifyAgentTitle as a, classifyGrokHooksFile as c, grok as i, renderGrokHooksFile as l, classifyKimiConfig as n, isBrailleChar as o, spliceKimiHooksBlock as r, isSpinnerChar as s, kimi as t, buildAgentEnv as u };
|