@vectorize-io/hindsight-coding-agents 0.0.1
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/README.md +334 -0
- package/dist/antigravity-hook.js +1556 -0
- package/dist/antigravity-statusline.js +194 -0
- package/dist/antigravity-stop-hook.js +1453 -0
- package/dist/claude-hook.js +1556 -0
- package/dist/claude-sessionstart-hook.js +1814 -0
- package/dist/claude-stop-hook.js +1453 -0
- package/dist/cline.js +16373 -0
- package/dist/codex-hook.js +1556 -0
- package/dist/codex-sessionstart-hook.js +1814 -0
- package/dist/codex-stop-hook.js +1453 -0
- package/dist/copilot-hook.js +1556 -0
- package/dist/copilot-sessionstart-hook.js +1814 -0
- package/dist/copilot-stop-hook.js +1453 -0
- package/dist/cursor-hook.js +1556 -0
- package/dist/cursor-sessionstart-hook.js +1814 -0
- package/dist/cursor-stop-hook.js +1453 -0
- package/dist/deepen.js +1175 -0
- package/dist/devin-hook.js +1556 -0
- package/dist/devin-sessionstart-hook.js +1814 -0
- package/dist/devin-stop-hook.js +1453 -0
- package/dist/grok-hook.js +1556 -0
- package/dist/grok-sessionstart-hook.js +1814 -0
- package/dist/grok-stop-hook.js +1453 -0
- package/dist/hindsight-seed.js +180 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +28853 -0
- package/dist/installer.js +1313 -0
- package/dist/kilo.js +28853 -0
- package/dist/mcp-server.js +31888 -0
- package/dist/status.js +793 -0
- package/package.json +65 -0
- package/skill/SKILL.md +122 -0
|
@@ -0,0 +1,1313 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/installer.ts
|
|
4
|
+
import { execFileSync as execFileSync5 } from "child_process";
|
|
5
|
+
import {
|
|
6
|
+
copyFileSync,
|
|
7
|
+
cpSync as cpSync2,
|
|
8
|
+
existsSync as existsSync5,
|
|
9
|
+
mkdirSync as mkdirSync3,
|
|
10
|
+
readFileSync as readFileSync13,
|
|
11
|
+
realpathSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
writeFileSync as writeFileSync2
|
|
14
|
+
} from "fs";
|
|
15
|
+
import { homedir as homedir7 } from "os";
|
|
16
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
17
|
+
import { fileURLToPath as fileURLToPath4, pathToFileURL } from "url";
|
|
18
|
+
|
|
19
|
+
// src/core/hook.ts
|
|
20
|
+
import { existsSync, readFileSync as readFileSync3 } from "fs";
|
|
21
|
+
|
|
22
|
+
// src/core/bank.ts
|
|
23
|
+
import { execFileSync } from "child_process";
|
|
24
|
+
import { homedir } from "os";
|
|
25
|
+
import { basename, dirname, join, normalize, sep } from "path";
|
|
26
|
+
|
|
27
|
+
// src/core/config.ts
|
|
28
|
+
import { readFileSync } from "fs";
|
|
29
|
+
import { homedir as homedir2 } from "os";
|
|
30
|
+
import { join as join3 } from "path";
|
|
31
|
+
|
|
32
|
+
// src/core/seed.ts
|
|
33
|
+
import { spawn as realSpawn } from "child_process";
|
|
34
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
35
|
+
import { fileURLToPath } from "url";
|
|
36
|
+
|
|
37
|
+
// src/core/config.ts
|
|
38
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
|
|
39
|
+
|
|
40
|
+
// src/core/diag.ts
|
|
41
|
+
import { appendFileSync as appendFileSync2 } from "fs";
|
|
42
|
+
|
|
43
|
+
// src/core/log.ts
|
|
44
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
45
|
+
import { tmpdir } from "os";
|
|
46
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
47
|
+
var current = ["debug", "info", "warn", "error"].find(
|
|
48
|
+
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
49
|
+
) ?? "info";
|
|
50
|
+
|
|
51
|
+
// src/core/session-cache.ts
|
|
52
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
53
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
54
|
+
import { dirname as dirname4, join as join5 } from "path";
|
|
55
|
+
|
|
56
|
+
// src/core/retain-hook.ts
|
|
57
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
58
|
+
|
|
59
|
+
// src/core/transcript.ts
|
|
60
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
61
|
+
|
|
62
|
+
// src/core/transcript-util.ts
|
|
63
|
+
var MEMORY_TAG_RE = /<(hook_prompt|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
|
|
64
|
+
function stripInjectedMemory(s) {
|
|
65
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
66
|
+
}
|
|
67
|
+
var TARGET_KEYS = [
|
|
68
|
+
"file_path",
|
|
69
|
+
"path",
|
|
70
|
+
"notebook_path",
|
|
71
|
+
"command",
|
|
72
|
+
"pattern",
|
|
73
|
+
"query",
|
|
74
|
+
"url",
|
|
75
|
+
"name",
|
|
76
|
+
"id"
|
|
77
|
+
];
|
|
78
|
+
var ACTION_TARGET_CAP = 100;
|
|
79
|
+
function actionLine(tool, input) {
|
|
80
|
+
let target = "";
|
|
81
|
+
if (input && typeof input === "object") {
|
|
82
|
+
const rec = input;
|
|
83
|
+
for (const k of TARGET_KEYS) {
|
|
84
|
+
const v = rec[k];
|
|
85
|
+
if (typeof v === "string" && v.trim()) {
|
|
86
|
+
target = v.trim().split("\n")[0];
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} else if (typeof input === "string") {
|
|
91
|
+
target = input.trim().split("\n")[0];
|
|
92
|
+
}
|
|
93
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
94
|
+
return target ? `${tool} ${target}` : tool;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/core/session-start.ts
|
|
98
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
99
|
+
|
|
100
|
+
// src/core/git.ts
|
|
101
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
102
|
+
import { resolve } from "path";
|
|
103
|
+
|
|
104
|
+
// src/core/status.ts
|
|
105
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
106
|
+
|
|
107
|
+
// src/core/survey.ts
|
|
108
|
+
import { spawn as realSpawn2 } from "child_process";
|
|
109
|
+
import { accessSync, constants, existsSync as existsSync2 } from "fs";
|
|
110
|
+
import { homedir as homedir3 } from "os";
|
|
111
|
+
import { delimiter, dirname as dirname5, join as join6 } from "path";
|
|
112
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
113
|
+
|
|
114
|
+
// src/core/skill-sync.ts
|
|
115
|
+
import { cpSync, existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
|
|
116
|
+
import { homedir as homedir4 } from "os";
|
|
117
|
+
import { dirname as dirname6, join as join7 } from "path";
|
|
118
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
119
|
+
|
|
120
|
+
// src/core/transcript-codex.ts
|
|
121
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
122
|
+
function isSyntheticUserText(text) {
|
|
123
|
+
const s = text.trimStart();
|
|
124
|
+
return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
|
|
125
|
+
}
|
|
126
|
+
function messageText(payload) {
|
|
127
|
+
return (payload.content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
128
|
+
}
|
|
129
|
+
function readCodexTranscript(path) {
|
|
130
|
+
let raw;
|
|
131
|
+
try {
|
|
132
|
+
raw = readFileSync8(path, "utf8");
|
|
133
|
+
} catch {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
const turns = [];
|
|
137
|
+
for (const rawLine of raw.split("\n")) {
|
|
138
|
+
const trimmed = rawLine.trim();
|
|
139
|
+
if (!trimmed) continue;
|
|
140
|
+
let parsed;
|
|
141
|
+
try {
|
|
142
|
+
parsed = JSON.parse(trimmed);
|
|
143
|
+
} catch {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
147
|
+
const line = parsed;
|
|
148
|
+
if (line.type !== "response_item") continue;
|
|
149
|
+
const p = line.payload;
|
|
150
|
+
if (!p || typeof p !== "object") continue;
|
|
151
|
+
if (p.type === "message") {
|
|
152
|
+
if (p.role !== "user" && p.role !== "assistant") continue;
|
|
153
|
+
const text = stripInjectedMemory(messageText(p)).trim();
|
|
154
|
+
if (!text) continue;
|
|
155
|
+
if (p.role === "user" && isSyntheticUserText(text)) continue;
|
|
156
|
+
turns.push({ role: p.role, content: text });
|
|
157
|
+
} else if (p.type === "function_call" && typeof p.name === "string") {
|
|
158
|
+
let input;
|
|
159
|
+
try {
|
|
160
|
+
input = JSON.parse(p.arguments || "");
|
|
161
|
+
} catch {
|
|
162
|
+
input = void 0;
|
|
163
|
+
}
|
|
164
|
+
turns.push({ role: "action", content: actionLine(p.name, input) });
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return turns;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/core/transcript-cursor.ts
|
|
171
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
172
|
+
function withTimestamp(turn, timestamp) {
|
|
173
|
+
return timestamp ? { ...turn, timestamp } : turn;
|
|
174
|
+
}
|
|
175
|
+
function textFrom(content) {
|
|
176
|
+
if (typeof content === "string") return content;
|
|
177
|
+
if (!Array.isArray(content)) return "";
|
|
178
|
+
return content.filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n");
|
|
179
|
+
}
|
|
180
|
+
function readCursorTranscript(path) {
|
|
181
|
+
let raw;
|
|
182
|
+
try {
|
|
183
|
+
raw = readFileSync9(path, "utf8");
|
|
184
|
+
} catch {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
const turns = [];
|
|
188
|
+
for (const rawLine of raw.split("\n")) {
|
|
189
|
+
let parsed;
|
|
190
|
+
try {
|
|
191
|
+
parsed = JSON.parse(rawLine);
|
|
192
|
+
} catch {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
196
|
+
const line = parsed;
|
|
197
|
+
const role = line.message?.role ?? line.role ?? (line.type === "user" || line.type === "assistant" ? line.type : void 0);
|
|
198
|
+
const content = line.message?.content ?? line.content;
|
|
199
|
+
if (role === "user" || role === "assistant") {
|
|
200
|
+
const text = stripInjectedMemory(textFrom(content)).trim();
|
|
201
|
+
if (text) turns.push(withTimestamp({ role, content: text }, line.timestamp));
|
|
202
|
+
if (role === "assistant" && Array.isArray(content)) {
|
|
203
|
+
for (const block of content) {
|
|
204
|
+
if (block?.type === "tool_use" && typeof block.name === "string") {
|
|
205
|
+
turns.push(
|
|
206
|
+
withTimestamp(
|
|
207
|
+
{ role: "action", content: actionLine(block.name, block.input) },
|
|
208
|
+
line.timestamp
|
|
209
|
+
)
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} else if (line.type === "tool_call" && typeof line.name === "string") {
|
|
215
|
+
turns.push(
|
|
216
|
+
withTimestamp({ role: "action", content: actionLine(line.name, line.args) }, line.timestamp)
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return turns;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// src/core/transcript-antigravity.ts
|
|
224
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
225
|
+
function readAntigravityTranscript(path) {
|
|
226
|
+
if (!path) return [];
|
|
227
|
+
let raw;
|
|
228
|
+
try {
|
|
229
|
+
raw = readFileSync10(path, "utf8");
|
|
230
|
+
} catch {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
const turns = [];
|
|
234
|
+
for (const line of raw.split("\n")) {
|
|
235
|
+
try {
|
|
236
|
+
const event = JSON.parse(line);
|
|
237
|
+
const role = event.role ?? event.message?.role ?? event.type;
|
|
238
|
+
const normalizedRole = role === "user" || role === "USER_INPUT" ? "user" : role === "assistant" || role === "model" || role === "PLANNER_RESPONSE" ? "assistant" : void 0;
|
|
239
|
+
const content = event.content ?? event.text ?? event.message?.content ?? event.message?.text;
|
|
240
|
+
const clean = typeof content === "string" ? stripInjectedMemory(content).trim() : "";
|
|
241
|
+
if (normalizedRole && clean) {
|
|
242
|
+
turns.push({
|
|
243
|
+
role: normalizedRole,
|
|
244
|
+
content: clean,
|
|
245
|
+
...event.timestamp ? { timestamp: event.timestamp } : {}
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
} catch {
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return turns;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/core/transcript-copilot.ts
|
|
255
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
256
|
+
function readCopilotTranscript(path) {
|
|
257
|
+
let raw;
|
|
258
|
+
try {
|
|
259
|
+
raw = readFileSync11(path, "utf8");
|
|
260
|
+
} catch {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
const turns = [];
|
|
264
|
+
for (const rawLine of raw.split("\n")) {
|
|
265
|
+
try {
|
|
266
|
+
const event = JSON.parse(rawLine);
|
|
267
|
+
const role = event.type === "user.message" ? "user" : event.type === "assistant.message" ? "assistant" : void 0;
|
|
268
|
+
const content = typeof event.data?.content === "string" ? stripInjectedMemory(event.data.content).trim() : "";
|
|
269
|
+
if (!role || !content) continue;
|
|
270
|
+
turns.push({ role, content, ...event.timestamp ? { timestamp: event.timestamp } : {} });
|
|
271
|
+
} catch {
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return turns;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/core/transcript-grok.ts
|
|
278
|
+
import { existsSync as existsSync4, readFileSync as readFileSync12, readdirSync } from "fs";
|
|
279
|
+
import { homedir as homedir5 } from "os";
|
|
280
|
+
import { join as join8 } from "path";
|
|
281
|
+
var CHAT_HISTORY = "chat_history.jsonl";
|
|
282
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join8(homedir5(), ".grok")) {
|
|
283
|
+
const sessionsDir = join8(grokHome, "sessions");
|
|
284
|
+
const direct = join8(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
285
|
+
if (existsSync4(direct)) return direct;
|
|
286
|
+
try {
|
|
287
|
+
for (const candidate of readdirSync(sessionsDir)) {
|
|
288
|
+
const directory = join8(sessionsDir, candidate);
|
|
289
|
+
if (readFileSync12(join8(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
290
|
+
return join8(directory, sessionId, CHAT_HISTORY);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} catch {
|
|
294
|
+
}
|
|
295
|
+
return direct;
|
|
296
|
+
}
|
|
297
|
+
function readGrokTranscript(path) {
|
|
298
|
+
let raw;
|
|
299
|
+
try {
|
|
300
|
+
raw = readFileSync12(path, "utf8");
|
|
301
|
+
} catch {
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
const turns = [];
|
|
305
|
+
for (const rawLine of raw.split("\n")) {
|
|
306
|
+
try {
|
|
307
|
+
const event = JSON.parse(rawLine);
|
|
308
|
+
if (event.type !== "user" && event.type !== "assistant") continue;
|
|
309
|
+
if (event.type === "user" && typeof event.prompt_index !== "number") continue;
|
|
310
|
+
const content = typeof event.content === "string" ? event.content : Array.isArray(event.content) ? event.content.filter((part) => part.type === "text").map((part) => part.text ?? "").join("\n") : "";
|
|
311
|
+
const clean = stripInjectedMemory(content).trim();
|
|
312
|
+
if (clean) turns.push({ role: event.type, content: clean });
|
|
313
|
+
for (const toolCall of event.tool_calls ?? []) {
|
|
314
|
+
if (!toolCall.name) continue;
|
|
315
|
+
let input = toolCall.arguments;
|
|
316
|
+
if (typeof input === "string") {
|
|
317
|
+
try {
|
|
318
|
+
input = JSON.parse(input);
|
|
319
|
+
} catch {
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
turns.push({ role: "action", content: actionLine(toolCall.name, input) });
|
|
323
|
+
}
|
|
324
|
+
} catch {
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return turns;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// src/core/transcript-devin.ts
|
|
331
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
332
|
+
import { homedir as homedir6 } from "os";
|
|
333
|
+
import { join as join9 } from "path";
|
|
334
|
+
var sessionDb = join9(homedir6(), ".local", "share", "devin", "cli", "sessions.db");
|
|
335
|
+
function parseDevinMessages(nodes) {
|
|
336
|
+
const messages = /* @__PURE__ */ new Map();
|
|
337
|
+
for (const node of nodes) {
|
|
338
|
+
try {
|
|
339
|
+
const message = JSON.parse(node.chat_message);
|
|
340
|
+
if (message.role !== "user" && message.role !== "assistant" || !message.content?.trim())
|
|
341
|
+
continue;
|
|
342
|
+
const content = stripInjectedMemory(message.content).trim();
|
|
343
|
+
if (!content) continue;
|
|
344
|
+
const id = message.message_id || `node:${node.node_id}`;
|
|
345
|
+
messages.set(id, {
|
|
346
|
+
index: messages.get(id)?.index ?? node.node_id,
|
|
347
|
+
role: message.role,
|
|
348
|
+
content
|
|
349
|
+
});
|
|
350
|
+
} catch {
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return [...messages.values()].sort((a, b) => a.index - b.index).map(({ role, content }) => ({ role, content }));
|
|
354
|
+
}
|
|
355
|
+
function readDevinTranscript(sessionId) {
|
|
356
|
+
if (!sessionId) return [];
|
|
357
|
+
try {
|
|
358
|
+
const quotedId = sessionId.replace(/'/g, "''");
|
|
359
|
+
const raw = execFileSync4(
|
|
360
|
+
"sqlite3",
|
|
361
|
+
[
|
|
362
|
+
"-json",
|
|
363
|
+
sessionDb,
|
|
364
|
+
`SELECT node_id, chat_message FROM message_nodes WHERE session_id = '${quotedId}' ORDER BY node_id`
|
|
365
|
+
],
|
|
366
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 2e3 }
|
|
367
|
+
);
|
|
368
|
+
return parseDevinMessages(JSON.parse(raw));
|
|
369
|
+
} catch {
|
|
370
|
+
return [];
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// src/harness/hook-lifecycle.ts
|
|
375
|
+
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
376
|
+
var claudePrompt = {
|
|
377
|
+
harness: "claude-code",
|
|
378
|
+
parse: (ev) => ({
|
|
379
|
+
prompt: ev.prompt,
|
|
380
|
+
cwd: ev.cwd,
|
|
381
|
+
sessionId: ev.session_id
|
|
382
|
+
}),
|
|
383
|
+
emit: (context, notice) => ({
|
|
384
|
+
...notice ? { systemMessage: notice } : {},
|
|
385
|
+
hookSpecificOutput: { hookEventName: "UserPromptSubmit", additionalContext: context }
|
|
386
|
+
})
|
|
387
|
+
};
|
|
388
|
+
var codexPrompt = {
|
|
389
|
+
...claudePrompt,
|
|
390
|
+
harness: "codex",
|
|
391
|
+
parse: (ev) => ({
|
|
392
|
+
prompt: ev.prompt ?? ev.user_prompt,
|
|
393
|
+
cwd: ev.cwd,
|
|
394
|
+
sessionId: ev.session_id
|
|
395
|
+
})
|
|
396
|
+
};
|
|
397
|
+
var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
|
|
398
|
+
var antigravityPrompt = {
|
|
399
|
+
harness: "antigravity-cli",
|
|
400
|
+
requireCwd: true,
|
|
401
|
+
parse: (ev) => ({
|
|
402
|
+
// Antigravity's PreInvocation payload deliberately omits the prompt. Its transcript is already
|
|
403
|
+
// persisted at that point, so recover the latest real user turn from the supplied JSONL path.
|
|
404
|
+
prompt: readAntigravityTranscript(ev.transcriptPath).filter((turn) => turn.role === "user").at(-1)?.content,
|
|
405
|
+
cwd: antigravityCwd(ev),
|
|
406
|
+
sessionId: ev.conversationId
|
|
407
|
+
}),
|
|
408
|
+
emit: (context) => ({ injectSteps: context ? [{ ephemeralMessage: context }] : [] })
|
|
409
|
+
};
|
|
410
|
+
var cursorPrompt = {
|
|
411
|
+
harness: "cursor-cli",
|
|
412
|
+
parse: (ev) => ({
|
|
413
|
+
prompt: ev.prompt ?? ev.user_prompt,
|
|
414
|
+
cwd: cursorCwd(ev),
|
|
415
|
+
sessionId: ev.conversation_id ?? ev.session_id
|
|
416
|
+
}),
|
|
417
|
+
emit: (context) => ({ continue: true, additional_context: context })
|
|
418
|
+
};
|
|
419
|
+
var copilotPrompt = {
|
|
420
|
+
harness: "copilot-cli",
|
|
421
|
+
parse: (ev) => ({
|
|
422
|
+
prompt: ev.prompt,
|
|
423
|
+
cwd: ev.cwd,
|
|
424
|
+
sessionId: ev.sessionId
|
|
425
|
+
}),
|
|
426
|
+
emit: (context, _notice, ev) => ({
|
|
427
|
+
// Copilot's userPromptTransformed hook replaces model-facing content rather than appending
|
|
428
|
+
// hook context. Preserve its transformed prompt and add the shared Hindsight injection.
|
|
429
|
+
modifiedTransformedPrompt: `${ev?.transformedPrompt ?? ""}
|
|
430
|
+
|
|
431
|
+
${context}`.trim()
|
|
432
|
+
})
|
|
433
|
+
};
|
|
434
|
+
var devinCwd = () => process.env.DEVIN_PROJECT_DIR;
|
|
435
|
+
var devinPrompt = {
|
|
436
|
+
harness: "devin-cli",
|
|
437
|
+
requireCwd: true,
|
|
438
|
+
parse: (ev) => ({
|
|
439
|
+
prompt: ev.prompt,
|
|
440
|
+
cwd: devinCwd(),
|
|
441
|
+
sessionId: ev.session_id
|
|
442
|
+
}),
|
|
443
|
+
emit: (context) => ({
|
|
444
|
+
hookSpecificOutput: { hookEventName: "UserPromptSubmit", additionalContext: context }
|
|
445
|
+
})
|
|
446
|
+
};
|
|
447
|
+
var standardSessionStart = (harness) => ({
|
|
448
|
+
harness,
|
|
449
|
+
parse: (ev) => ({
|
|
450
|
+
cwd: ev.cwd,
|
|
451
|
+
sessionId: ev.session_id
|
|
452
|
+
}),
|
|
453
|
+
emit: (out) => ({
|
|
454
|
+
...out.systemMessage ? { systemMessage: out.systemMessage } : {},
|
|
455
|
+
hookSpecificOutput: {
|
|
456
|
+
hookEventName: "SessionStart",
|
|
457
|
+
...out.additionalContext ? { additionalContext: out.additionalContext } : {}
|
|
458
|
+
}
|
|
459
|
+
})
|
|
460
|
+
});
|
|
461
|
+
var HOOK_HARNESSES = {
|
|
462
|
+
"claude-code": {
|
|
463
|
+
configStyle: "nested",
|
|
464
|
+
install: {
|
|
465
|
+
sessionStart: { event: "SessionStart", entry: "claude-sessionstart-hook.js", timeout: 30 },
|
|
466
|
+
prompt: { event: "UserPromptSubmit", entry: "claude-hook.js", timeout: 30 },
|
|
467
|
+
stop: { event: "Stop", entry: "claude-stop-hook.js", timeout: 60 }
|
|
468
|
+
},
|
|
469
|
+
sessionStart: standardSessionStart("claude-code"),
|
|
470
|
+
prompt: claudePrompt,
|
|
471
|
+
retain: {
|
|
472
|
+
harness: "claude-code",
|
|
473
|
+
parse: (ev) => ({
|
|
474
|
+
sessionId: ev.session_id,
|
|
475
|
+
transcriptPath: ev.transcript_path,
|
|
476
|
+
cwd: ev.cwd
|
|
477
|
+
})
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
codex: {
|
|
481
|
+
configStyle: "nested",
|
|
482
|
+
install: {
|
|
483
|
+
sessionStart: { event: "SessionStart", entry: "codex-sessionstart-hook.js", timeout: 30 },
|
|
484
|
+
prompt: { event: "UserPromptSubmit", entry: "codex-hook.js", timeout: 30 },
|
|
485
|
+
stop: { event: "Stop", entry: "codex-stop-hook.js", timeout: 60 }
|
|
486
|
+
},
|
|
487
|
+
sessionStart: standardSessionStart("codex"),
|
|
488
|
+
prompt: codexPrompt,
|
|
489
|
+
retain: {
|
|
490
|
+
harness: "codex",
|
|
491
|
+
parse: (ev) => ({
|
|
492
|
+
sessionId: ev.session_id,
|
|
493
|
+
transcriptPath: ev.transcript_path,
|
|
494
|
+
cwd: ev.cwd
|
|
495
|
+
}),
|
|
496
|
+
readTranscript: readCodexTranscript
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
"antigravity-cli": {
|
|
500
|
+
configStyle: "flat",
|
|
501
|
+
install: {
|
|
502
|
+
// PreInvocation is Antigravity's only lifecycle point that can inject context. Its first
|
|
503
|
+
// invocation also performs the SessionStart responsibilities through runHook's seed guard.
|
|
504
|
+
sessionStart: { event: "PreInvocation", entry: "antigravity-hook.js", timeout: 30 },
|
|
505
|
+
prompt: { event: "PreInvocation", entry: "antigravity-hook.js", timeout: 30 },
|
|
506
|
+
stop: { event: "Stop", entry: "antigravity-stop-hook.js", timeout: 30 }
|
|
507
|
+
},
|
|
508
|
+
sessionStart: {
|
|
509
|
+
harness: "antigravity-cli",
|
|
510
|
+
parse: (ev) => ({
|
|
511
|
+
cwd: antigravityCwd(ev),
|
|
512
|
+
sessionId: ev.conversationId
|
|
513
|
+
}),
|
|
514
|
+
emit: () => ({})
|
|
515
|
+
},
|
|
516
|
+
prompt: antigravityPrompt,
|
|
517
|
+
retain: {
|
|
518
|
+
harness: "antigravity-cli",
|
|
519
|
+
parse: (ev) => ({
|
|
520
|
+
sessionId: ev.conversationId,
|
|
521
|
+
transcriptPath: ev.transcriptPath,
|
|
522
|
+
cwd: antigravityCwd(ev)
|
|
523
|
+
}),
|
|
524
|
+
readTranscript: readAntigravityTranscript
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
"cursor-cli": {
|
|
528
|
+
configStyle: "flat",
|
|
529
|
+
install: {
|
|
530
|
+
sessionStart: { event: "sessionStart", entry: "cursor-sessionstart-hook.js", timeout: 30 },
|
|
531
|
+
prompt: { event: "beforeSubmitPrompt", entry: "cursor-hook.js" },
|
|
532
|
+
stop: { event: "stop", entry: "cursor-stop-hook.js", timeout: 30 }
|
|
533
|
+
},
|
|
534
|
+
sessionStart: {
|
|
535
|
+
harness: "cursor-cli",
|
|
536
|
+
parse: (ev) => ({
|
|
537
|
+
cwd: cursorCwd(ev),
|
|
538
|
+
sessionId: ev.conversation_id ?? ev.session_id
|
|
539
|
+
}),
|
|
540
|
+
emit: (out) => ({
|
|
541
|
+
...out.additionalContext ? { additional_context: out.additionalContext } : {}
|
|
542
|
+
})
|
|
543
|
+
},
|
|
544
|
+
prompt: cursorPrompt,
|
|
545
|
+
retain: {
|
|
546
|
+
harness: "cursor-cli",
|
|
547
|
+
parse: (ev) => ({
|
|
548
|
+
sessionId: ev.conversation_id ?? ev.session_id,
|
|
549
|
+
transcriptPath: ev.transcript_path,
|
|
550
|
+
cwd: cursorCwd(ev)
|
|
551
|
+
}),
|
|
552
|
+
readTranscript: readCursorTranscript
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
"copilot-cli": {
|
|
556
|
+
configStyle: "flat",
|
|
557
|
+
install: {
|
|
558
|
+
sessionStart: { event: "sessionStart", entry: "copilot-sessionstart-hook.js", timeout: 30 },
|
|
559
|
+
prompt: { event: "userPromptTransformed", entry: "copilot-hook.js", timeout: 30 },
|
|
560
|
+
stop: { event: "agentStop", entry: "copilot-stop-hook.js", timeout: 60 }
|
|
561
|
+
},
|
|
562
|
+
sessionStart: {
|
|
563
|
+
harness: "copilot-cli",
|
|
564
|
+
parse: (ev) => ({
|
|
565
|
+
cwd: ev.cwd,
|
|
566
|
+
sessionId: ev.sessionId
|
|
567
|
+
}),
|
|
568
|
+
// Copilot CLI's SessionStart response only has model-facing `additionalContext`; unlike
|
|
569
|
+
// Claude/Cursor it has no supported in-TUI system-message/banner channel. Keep memory
|
|
570
|
+
// quiet rather than auto-submitting a synthetic prompt or showing an OS notification. When
|
|
571
|
+
// Copilot exposes a real TUI extension point, add the banner there without changing this
|
|
572
|
+
// shared lifecycle output.
|
|
573
|
+
emit: (out) => ({
|
|
574
|
+
...out.additionalContext ? { additionalContext: out.additionalContext } : {}
|
|
575
|
+
})
|
|
576
|
+
},
|
|
577
|
+
prompt: copilotPrompt,
|
|
578
|
+
retain: {
|
|
579
|
+
harness: "copilot-cli",
|
|
580
|
+
parse: (ev) => ({
|
|
581
|
+
sessionId: ev.sessionId,
|
|
582
|
+
transcriptPath: ev.transcriptPath,
|
|
583
|
+
cwd: ev.cwd
|
|
584
|
+
}),
|
|
585
|
+
readTranscript: readCopilotTranscript
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
"devin-cli": {
|
|
589
|
+
configStyle: "nested",
|
|
590
|
+
install: {
|
|
591
|
+
sessionStart: { event: "SessionStart", entry: "devin-sessionstart-hook.js", timeout: 30 },
|
|
592
|
+
prompt: { event: "UserPromptSubmit", entry: "devin-hook.js", timeout: 30 },
|
|
593
|
+
stop: { event: "Stop", entry: "devin-stop-hook.js", timeout: 60 }
|
|
594
|
+
},
|
|
595
|
+
sessionStart: {
|
|
596
|
+
harness: "devin-cli",
|
|
597
|
+
parse: (ev) => ({ cwd: devinCwd(), sessionId: ev.session_id }),
|
|
598
|
+
emit: (out) => ({
|
|
599
|
+
hookSpecificOutput: {
|
|
600
|
+
hookEventName: "SessionStart",
|
|
601
|
+
...out.additionalContext ? { additionalContext: out.additionalContext } : {}
|
|
602
|
+
}
|
|
603
|
+
})
|
|
604
|
+
},
|
|
605
|
+
prompt: devinPrompt,
|
|
606
|
+
retain: {
|
|
607
|
+
harness: "devin-cli",
|
|
608
|
+
parse: (ev) => {
|
|
609
|
+
const sessionId = ev.session_id;
|
|
610
|
+
return {
|
|
611
|
+
sessionId,
|
|
612
|
+
// RetainHook calls the supplied reader with transcriptPath; Devin's reader uses its
|
|
613
|
+
// session id because the CLI persists conversations in sessions.db rather than a file.
|
|
614
|
+
transcriptPath: sessionId,
|
|
615
|
+
cwd: devinCwd()
|
|
616
|
+
};
|
|
617
|
+
},
|
|
618
|
+
readTranscript: readDevinTranscript
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
"grok-build": {
|
|
622
|
+
configStyle: "nested",
|
|
623
|
+
install: {
|
|
624
|
+
sessionStart: { event: "SessionStart", entry: "grok-sessionstart-hook.js", timeout: 30 },
|
|
625
|
+
prompt: { event: "UserPromptSubmit", entry: "grok-hook.js", timeout: 30 },
|
|
626
|
+
stop: { event: "Stop", entry: "grok-stop-hook.js", timeout: 60 }
|
|
627
|
+
},
|
|
628
|
+
sessionStart: {
|
|
629
|
+
...standardSessionStart("grok-build"),
|
|
630
|
+
// Grok's wire envelope is camelCase, unlike Claude's similarly named hook events.
|
|
631
|
+
parse: (ev) => ({
|
|
632
|
+
cwd: ev.cwd,
|
|
633
|
+
sessionId: ev.sessionId
|
|
634
|
+
})
|
|
635
|
+
},
|
|
636
|
+
prompt: {
|
|
637
|
+
...claudePrompt,
|
|
638
|
+
harness: "grok-build",
|
|
639
|
+
parse: (ev) => ({
|
|
640
|
+
prompt: ev.prompt,
|
|
641
|
+
cwd: ev.cwd,
|
|
642
|
+
sessionId: ev.sessionId
|
|
643
|
+
})
|
|
644
|
+
},
|
|
645
|
+
retain: {
|
|
646
|
+
harness: "grok-build",
|
|
647
|
+
parse: (ev) => ({
|
|
648
|
+
sessionId: ev.sessionId,
|
|
649
|
+
transcriptPath: typeof ev.cwd === "string" && typeof ev.sessionId === "string" ? grokTranscriptPath(ev.cwd, ev.sessionId) : void 0,
|
|
650
|
+
cwd: ev.cwd
|
|
651
|
+
}),
|
|
652
|
+
readTranscript: readGrokTranscript
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
// src/installer.ts
|
|
658
|
+
var MARKER = "coding-agents";
|
|
659
|
+
function readJson(path) {
|
|
660
|
+
try {
|
|
661
|
+
return JSON.parse(readFileSync13(path, "utf8"));
|
|
662
|
+
} catch {
|
|
663
|
+
return {};
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function parseJsonc(text) {
|
|
667
|
+
const stripped = text.replace(/"(?:\\.|[^"\\])*"|\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, (m) => m[0] === '"' ? m : "").replace(/,(\s*[}\]])/g, "$1");
|
|
668
|
+
try {
|
|
669
|
+
const v = JSON.parse(stripped);
|
|
670
|
+
return v && typeof v === "object" ? v : null;
|
|
671
|
+
} catch {
|
|
672
|
+
return null;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
function writeJson(path, value) {
|
|
676
|
+
mkdirSync3(dirname7(path), { recursive: true });
|
|
677
|
+
if (existsSync5(path) && !existsSync5(`${path}.hindsight-backup`)) {
|
|
678
|
+
copyFileSync(path, `${path}.hindsight-backup`);
|
|
679
|
+
}
|
|
680
|
+
writeFileSync2(path, JSON.stringify(value, null, 2) + "\n");
|
|
681
|
+
}
|
|
682
|
+
function mergeHookEvent(existing, entry) {
|
|
683
|
+
const kept = (existing ?? []).filter((e) => !JSON.stringify(e).includes(MARKER));
|
|
684
|
+
return [...kept, entry];
|
|
685
|
+
}
|
|
686
|
+
function stripOurs(existing) {
|
|
687
|
+
return (existing ?? []).filter((e) => !JSON.stringify(e).includes(MARKER));
|
|
688
|
+
}
|
|
689
|
+
function setOrDelete(obj, key, arr) {
|
|
690
|
+
if (arr.length) obj[key] = arr;
|
|
691
|
+
else delete obj[key];
|
|
692
|
+
}
|
|
693
|
+
var cmdHook = (dist, file, timeout) => ({
|
|
694
|
+
hooks: [{ type: "command", command: `node "${join10(dist, file)}"`, timeout }]
|
|
695
|
+
});
|
|
696
|
+
function mergeHarnessHooks(hooks, harness, dist) {
|
|
697
|
+
const spec = HOOK_HARNESSES[harness];
|
|
698
|
+
const installedEvents = /* @__PURE__ */ new Set();
|
|
699
|
+
for (const hook of Object.values(spec.install)) {
|
|
700
|
+
if (installedEvents.has(hook.event)) continue;
|
|
701
|
+
installedEvents.add(hook.event);
|
|
702
|
+
const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : {
|
|
703
|
+
command: `node "${join10(dist, hook.entry)}"`,
|
|
704
|
+
...hook.timeout ? { timeout: hook.timeout } : {}
|
|
705
|
+
};
|
|
706
|
+
hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
function stripHarnessHooks(hooks, harness) {
|
|
710
|
+
const strippedEvents = /* @__PURE__ */ new Set();
|
|
711
|
+
for (const hook of Object.values(HOOK_HARNESSES[harness].install)) {
|
|
712
|
+
if (strippedEvents.has(hook.event)) continue;
|
|
713
|
+
strippedEvents.add(hook.event);
|
|
714
|
+
setOrDelete(hooks, hook.event, stripOurs(hooks[hook.event]));
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
function installSkill(c, skillsBase) {
|
|
718
|
+
const src = join10(c.pkgRoot, "skill");
|
|
719
|
+
if (!existsSync5(join10(src, "SKILL.md"))) return;
|
|
720
|
+
const dst = join10(skillsBase, "hindsight-coding-agent");
|
|
721
|
+
mkdirSync3(skillsBase, { recursive: true });
|
|
722
|
+
cpSync2(src, dst, { recursive: true });
|
|
723
|
+
c.log?.(`skill installed at ${dst}`);
|
|
724
|
+
}
|
|
725
|
+
function uninstallSkill(c, skillsBase) {
|
|
726
|
+
rmSync(join10(skillsBase, "hindsight-coding-agent"), { recursive: true, force: true });
|
|
727
|
+
}
|
|
728
|
+
function onPath(bin) {
|
|
729
|
+
try {
|
|
730
|
+
execFileSync5("which", [bin], { stdio: "pipe" });
|
|
731
|
+
return true;
|
|
732
|
+
} catch {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function runClinePlugin(args) {
|
|
737
|
+
try {
|
|
738
|
+
execFileSync5("cline", args, { stdio: "pipe" });
|
|
739
|
+
return true;
|
|
740
|
+
} catch {
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
var opencode = {
|
|
745
|
+
name: "opencode",
|
|
746
|
+
detect: (c) => onPath("opencode") || existsSync5(join10(c.home, ".config", "opencode")),
|
|
747
|
+
install(c) {
|
|
748
|
+
const path = join10(c.home, ".config", "opencode", "opencode.json");
|
|
749
|
+
const cfg = readJson(path);
|
|
750
|
+
const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
|
|
751
|
+
cfg.plugin = [...plugins.filter((p) => !String(p).includes(MARKER)), c.pkgRoot];
|
|
752
|
+
writeJson(path, cfg);
|
|
753
|
+
c.log?.(`opencode: plugin registered in ${path}`);
|
|
754
|
+
},
|
|
755
|
+
uninstall(c) {
|
|
756
|
+
const path = join10(c.home, ".config", "opencode", "opencode.json");
|
|
757
|
+
if (!existsSync5(path)) return;
|
|
758
|
+
const cfg = readJson(path);
|
|
759
|
+
if (Array.isArray(cfg.plugin)) {
|
|
760
|
+
cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
761
|
+
if (!cfg.plugin.length) delete cfg.plugin;
|
|
762
|
+
writeJson(path, cfg);
|
|
763
|
+
}
|
|
764
|
+
c.log?.("opencode: plugin entry removed");
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
|
|
768
|
+
function kiloConfigPath(c) {
|
|
769
|
+
const dir = join10(c.home, ".config", "kilo");
|
|
770
|
+
const existing = KILO_CONFIG_CANDIDATES.map((f) => join10(dir, f)).find((p) => existsSync5(p));
|
|
771
|
+
return existing ?? join10(dir, "kilo.json");
|
|
772
|
+
}
|
|
773
|
+
var kilo = {
|
|
774
|
+
name: "kilo",
|
|
775
|
+
detect: (c) => onPath("kilo") || existsSync5(join10(c.home, ".config", "kilo")),
|
|
776
|
+
install(c) {
|
|
777
|
+
const path = kiloConfigPath(c);
|
|
778
|
+
let cfg = {};
|
|
779
|
+
if (existsSync5(path)) {
|
|
780
|
+
const parsed = parseJsonc(readFileSync13(path, "utf8"));
|
|
781
|
+
if (!parsed) {
|
|
782
|
+
c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
cfg = parsed;
|
|
786
|
+
}
|
|
787
|
+
const entry = pathToFileURL(join10(c.dist, "kilo.js")).href;
|
|
788
|
+
const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
|
|
789
|
+
cfg.plugin = [...plugins.filter((p) => !String(p).includes(MARKER)), entry];
|
|
790
|
+
writeJson(path, cfg);
|
|
791
|
+
c.log?.(`kilo: plugin registered in ${path}`);
|
|
792
|
+
},
|
|
793
|
+
uninstall(c) {
|
|
794
|
+
const path = kiloConfigPath(c);
|
|
795
|
+
if (!existsSync5(path)) return;
|
|
796
|
+
const cfg = parseJsonc(readFileSync13(path, "utf8"));
|
|
797
|
+
if (!cfg || !Array.isArray(cfg.plugin)) return;
|
|
798
|
+
cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
799
|
+
if (!cfg.plugin.length) delete cfg.plugin;
|
|
800
|
+
writeJson(path, cfg);
|
|
801
|
+
c.log?.("kilo: plugin entry removed");
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
var claudeCode = {
|
|
805
|
+
name: "claude-code",
|
|
806
|
+
detect: (c) => onPath("claude") || existsSync5(join10(c.home, ".claude")),
|
|
807
|
+
install(c) {
|
|
808
|
+
const path = join10(c.home, ".claude", "settings.json");
|
|
809
|
+
const settings = readJson(path);
|
|
810
|
+
settings.hooks = settings.hooks ?? {};
|
|
811
|
+
mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
|
|
812
|
+
writeJson(path, settings);
|
|
813
|
+
c.log?.(`claude-code: hooks merged into ${path}`);
|
|
814
|
+
installSkill(c, join10(c.home, ".claude", "skills"));
|
|
815
|
+
const mcp = c.claudeMcp ?? defaultClaudeMcp;
|
|
816
|
+
if (mcp([
|
|
817
|
+
"mcp",
|
|
818
|
+
"add",
|
|
819
|
+
"--scope",
|
|
820
|
+
"user",
|
|
821
|
+
"hindsight",
|
|
822
|
+
"--",
|
|
823
|
+
"node",
|
|
824
|
+
join10(c.dist, "mcp-server.js")
|
|
825
|
+
])) {
|
|
826
|
+
c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
|
|
827
|
+
} else {
|
|
828
|
+
c.log?.(
|
|
829
|
+
`claude-code: could not run \`claude mcp add\` \u2014 register the tools manually:
|
|
830
|
+
claude mcp add --scope user hindsight -- node "${join10(c.dist, "mcp-server.js")}"`
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
},
|
|
834
|
+
uninstall(c) {
|
|
835
|
+
const path = join10(c.home, ".claude", "settings.json");
|
|
836
|
+
if (existsSync5(path)) {
|
|
837
|
+
const settings = readJson(path);
|
|
838
|
+
if (settings.hooks) {
|
|
839
|
+
stripHarnessHooks(settings.hooks, "claude-code");
|
|
840
|
+
if (!Object.keys(settings.hooks).length) delete settings.hooks;
|
|
841
|
+
writeJson(path, settings);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const mcp = c.claudeMcp ?? defaultClaudeMcp;
|
|
845
|
+
mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
|
|
846
|
+
uninstallSkill(c, join10(c.home, ".claude", "skills"));
|
|
847
|
+
c.log?.("claude-code: hooks + MCP registration + skill removed");
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
function defaultClaudeMcp(args) {
|
|
851
|
+
try {
|
|
852
|
+
execFileSync5("claude", args, { stdio: "pipe" });
|
|
853
|
+
return true;
|
|
854
|
+
} catch {
|
|
855
|
+
return false;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
var codex = {
|
|
859
|
+
name: "codex",
|
|
860
|
+
detect: (c) => onPath("codex") || existsSync5(join10(c.home, ".codex")),
|
|
861
|
+
install(c) {
|
|
862
|
+
const hooksPath = join10(c.home, ".codex", "hooks.json");
|
|
863
|
+
const cfg = readJson(hooksPath);
|
|
864
|
+
cfg.hooks = cfg.hooks ?? {};
|
|
865
|
+
mergeHarnessHooks(cfg.hooks, "codex", c.dist);
|
|
866
|
+
writeJson(hooksPath, cfg);
|
|
867
|
+
c.log?.(`codex: hooks merged into ${hooksPath}`);
|
|
868
|
+
const tomlPath = join10(c.home, ".codex", "config.toml");
|
|
869
|
+
let toml = existsSync5(tomlPath) ? readFileSync13(tomlPath, "utf8") : "";
|
|
870
|
+
const additions = [];
|
|
871
|
+
if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
|
|
872
|
+
if (/^\[features\]/m.test(toml)) {
|
|
873
|
+
c.log?.(
|
|
874
|
+
"codex: add `hooks = true` under your existing [features] section in ~/.codex/config.toml"
|
|
875
|
+
);
|
|
876
|
+
} else {
|
|
877
|
+
additions.push("[features]\nhooks = true");
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
if (!toml.includes("[mcp_servers.hindsight]")) {
|
|
881
|
+
additions.push(
|
|
882
|
+
`[mcp_servers.hindsight]
|
|
883
|
+
command = "node"
|
|
884
|
+
args = ["${join10(c.dist, "mcp-server.js")}"]`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
if (additions.length) {
|
|
888
|
+
if (existsSync5(tomlPath) && !existsSync5(`${tomlPath}.hindsight-backup`)) {
|
|
889
|
+
copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
|
|
890
|
+
}
|
|
891
|
+
mkdirSync3(dirname7(tomlPath), { recursive: true });
|
|
892
|
+
writeFileSync2(tomlPath, `${toml.replace(/\n*$/, "\n\n")}${additions.join("\n\n")}
|
|
893
|
+
`);
|
|
894
|
+
c.log?.(`codex: appended ${additions.length} section(s) to ${tomlPath}`);
|
|
895
|
+
}
|
|
896
|
+
installSkill(c, join10(c.home, ".agents", "skills"));
|
|
897
|
+
},
|
|
898
|
+
uninstall(c) {
|
|
899
|
+
const hooksPath = join10(c.home, ".codex", "hooks.json");
|
|
900
|
+
if (existsSync5(hooksPath)) {
|
|
901
|
+
const cfg = readJson(hooksPath);
|
|
902
|
+
if (cfg.hooks) {
|
|
903
|
+
stripHarnessHooks(cfg.hooks, "codex");
|
|
904
|
+
writeJson(hooksPath, cfg);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
uninstallSkill(c, join10(c.home, ".agents", "skills"));
|
|
908
|
+
const tomlPath = join10(c.home, ".codex", "config.toml");
|
|
909
|
+
if (existsSync5(tomlPath)) {
|
|
910
|
+
const toml = readFileSync13(tomlPath, "utf8");
|
|
911
|
+
const cleaned = toml.replace(
|
|
912
|
+
/\n?\[mcp_servers\.hindsight\]\ncommand = "node"\nargs = \[[^\]]*\]\n?/g,
|
|
913
|
+
"\n"
|
|
914
|
+
);
|
|
915
|
+
if (cleaned !== toml) writeFileSync2(tomlPath, cleaned);
|
|
916
|
+
}
|
|
917
|
+
c.log?.(
|
|
918
|
+
"codex: hooks + MCP section + skill removed ([features] hooks flag left as-is \u2014 other hooks may use it)"
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
var antigravity = {
|
|
923
|
+
name: "antigravity-cli",
|
|
924
|
+
// `agy` is the supported Antigravity CLI executable. Do not infer support from the
|
|
925
|
+
// legacy Gemini CLI's ~/.gemini state: both clients may leave files there, but only agy
|
|
926
|
+
// can consume this integration.
|
|
927
|
+
detect: (c) => onPath("agy"),
|
|
928
|
+
install(c) {
|
|
929
|
+
const hooksPath = join10(c.home, ".gemini", "config", "hooks.json");
|
|
930
|
+
const hooks = readJson(hooksPath);
|
|
931
|
+
hooks[MARKER] = hooks[MARKER] ?? {};
|
|
932
|
+
mergeHarnessHooks(hooks[MARKER], "antigravity-cli", c.dist);
|
|
933
|
+
for (const event of ["PreInvocation", "Stop"]) {
|
|
934
|
+
setOrDelete(hooks, event, stripOurs(hooks[event]));
|
|
935
|
+
}
|
|
936
|
+
writeJson(hooksPath, hooks);
|
|
937
|
+
const mcpPath = join10(c.home, ".gemini", "config", "mcp_config.json");
|
|
938
|
+
const mcp = readJson(mcpPath);
|
|
939
|
+
mcp.mcpServers = {
|
|
940
|
+
...mcp.mcpServers ?? {},
|
|
941
|
+
hindsight: {
|
|
942
|
+
command: "node",
|
|
943
|
+
args: [join10(c.dist, "mcp-server.js")],
|
|
944
|
+
env: { HINDSIGHT_MCP_HARNESS: "antigravity-cli" }
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
writeJson(mcpPath, mcp);
|
|
948
|
+
const settingsPath = join10(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
949
|
+
const settings = readJson(settingsPath);
|
|
950
|
+
if (!settings.statusLine) {
|
|
951
|
+
settings.statusLine = {
|
|
952
|
+
type: "command",
|
|
953
|
+
command: `node "${join10(c.dist, "antigravity-statusline.js")}"`
|
|
954
|
+
};
|
|
955
|
+
writeJson(settingsPath, settings);
|
|
956
|
+
c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
|
|
957
|
+
} else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
|
|
958
|
+
settings.statusLine = {
|
|
959
|
+
type: "command",
|
|
960
|
+
command: `node "${join10(c.dist, "antigravity-statusline.js")}"`
|
|
961
|
+
};
|
|
962
|
+
writeJson(settingsPath, settings);
|
|
963
|
+
} else {
|
|
964
|
+
c.log?.(
|
|
965
|
+
"antigravity-cli: existing custom status line preserved (Hindsight indicator not added)"
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
c.log?.(`antigravity-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
|
|
969
|
+
installSkill(c, join10(c.home, ".gemini", "config", "skills"));
|
|
970
|
+
},
|
|
971
|
+
uninstall(c) {
|
|
972
|
+
const hooksPath = join10(c.home, ".gemini", "config", "hooks.json");
|
|
973
|
+
if (existsSync5(hooksPath)) {
|
|
974
|
+
const hooks = readJson(hooksPath);
|
|
975
|
+
if (hooks[MARKER]) {
|
|
976
|
+
stripHarnessHooks(hooks[MARKER], "antigravity-cli");
|
|
977
|
+
if (!Object.keys(hooks[MARKER]).length) delete hooks[MARKER];
|
|
978
|
+
}
|
|
979
|
+
for (const event of ["PreInvocation", "Stop"]) {
|
|
980
|
+
setOrDelete(hooks, event, stripOurs(hooks[event]));
|
|
981
|
+
}
|
|
982
|
+
writeJson(hooksPath, hooks);
|
|
983
|
+
}
|
|
984
|
+
const mcpPath = join10(c.home, ".gemini", "config", "mcp_config.json");
|
|
985
|
+
if (existsSync5(mcpPath)) {
|
|
986
|
+
const mcp = readJson(mcpPath);
|
|
987
|
+
if (mcp.mcpServers?.hindsight) {
|
|
988
|
+
delete mcp.mcpServers.hindsight;
|
|
989
|
+
writeJson(mcpPath, mcp);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
const settingsPath = join10(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
993
|
+
if (existsSync5(settingsPath)) {
|
|
994
|
+
const settings = readJson(settingsPath);
|
|
995
|
+
if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
|
|
996
|
+
delete settings.statusLine;
|
|
997
|
+
writeJson(settingsPath, settings);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
uninstallSkill(c, join10(c.home, ".gemini", "config", "skills"));
|
|
1001
|
+
c.log?.("antigravity-cli: hooks + MCP entry + status line + skill removed");
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
var devin = {
|
|
1005
|
+
name: "devin-cli",
|
|
1006
|
+
detect: (c) => onPath("devin") || existsSync5(join10(c.home, ".config", "devin")),
|
|
1007
|
+
install(c) {
|
|
1008
|
+
const configPath = join10(c.home, ".config", "devin", "config.json");
|
|
1009
|
+
const config = readJson(configPath);
|
|
1010
|
+
config.hooks = config.hooks ?? {};
|
|
1011
|
+
mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
|
|
1012
|
+
writeJson(configPath, config);
|
|
1013
|
+
const mcpPath = join10(c.home, ".config", "devin", "mcp_config.json");
|
|
1014
|
+
const mcp = readJson(mcpPath);
|
|
1015
|
+
mcp.mcpServers = {
|
|
1016
|
+
...mcp.mcpServers ?? {},
|
|
1017
|
+
hindsight: {
|
|
1018
|
+
command: "node",
|
|
1019
|
+
args: [join10(c.dist, "mcp-server.js")],
|
|
1020
|
+
env: { HINDSIGHT_MCP_HARNESS: "devin-cli" }
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
writeJson(mcpPath, mcp);
|
|
1024
|
+
c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
|
|
1025
|
+
},
|
|
1026
|
+
uninstall(c) {
|
|
1027
|
+
const configPath = join10(c.home, ".config", "devin", "config.json");
|
|
1028
|
+
if (existsSync5(configPath)) {
|
|
1029
|
+
const config = readJson(configPath);
|
|
1030
|
+
if (config.hooks) {
|
|
1031
|
+
stripHarnessHooks(config.hooks, "devin-cli");
|
|
1032
|
+
if (!Object.keys(config.hooks).length) delete config.hooks;
|
|
1033
|
+
writeJson(configPath, config);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
const mcpPath = join10(c.home, ".config", "devin", "mcp_config.json");
|
|
1037
|
+
if (existsSync5(mcpPath)) {
|
|
1038
|
+
const mcp = readJson(mcpPath);
|
|
1039
|
+
if (mcp.mcpServers?.hindsight) {
|
|
1040
|
+
delete mcp.mcpServers.hindsight;
|
|
1041
|
+
writeJson(mcpPath, mcp);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
c.log?.("devin-cli: hooks + MCP entry removed");
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
var cursor = {
|
|
1048
|
+
name: "cursor-cli",
|
|
1049
|
+
detect: (c) => onPath("cursor-agent") || existsSync5(join10(c.home, ".cursor")),
|
|
1050
|
+
install(c) {
|
|
1051
|
+
const hooksPath = join10(c.home, ".cursor", "hooks.json");
|
|
1052
|
+
const cfg = readJson(hooksPath);
|
|
1053
|
+
cfg.hooks = cfg.hooks ?? {};
|
|
1054
|
+
mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
|
|
1055
|
+
writeJson(hooksPath, cfg);
|
|
1056
|
+
const mcpPath = join10(c.home, ".cursor", "mcp.json");
|
|
1057
|
+
const mcp = readJson(mcpPath);
|
|
1058
|
+
mcp.mcpServers = {
|
|
1059
|
+
...mcp.mcpServers ?? {},
|
|
1060
|
+
hindsight: { command: "node", args: [join10(c.dist, "mcp-server.js")] }
|
|
1061
|
+
};
|
|
1062
|
+
writeJson(mcpPath, mcp);
|
|
1063
|
+
c.log?.(`cursor-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
|
|
1064
|
+
installSkill(c, join10(c.home, ".cursor", "skills"));
|
|
1065
|
+
},
|
|
1066
|
+
uninstall(c) {
|
|
1067
|
+
const hooksPath = join10(c.home, ".cursor", "hooks.json");
|
|
1068
|
+
if (existsSync5(hooksPath)) {
|
|
1069
|
+
const cfg = readJson(hooksPath);
|
|
1070
|
+
if (cfg.hooks) {
|
|
1071
|
+
stripHarnessHooks(cfg.hooks, "cursor-cli");
|
|
1072
|
+
if (!Object.keys(cfg.hooks).length) delete cfg.hooks;
|
|
1073
|
+
writeJson(hooksPath, cfg);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
const mcpPath = join10(c.home, ".cursor", "mcp.json");
|
|
1077
|
+
if (existsSync5(mcpPath)) {
|
|
1078
|
+
const mcp = readJson(mcpPath);
|
|
1079
|
+
if (mcp.mcpServers?.hindsight) {
|
|
1080
|
+
delete mcp.mcpServers.hindsight;
|
|
1081
|
+
writeJson(mcpPath, mcp);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
uninstallSkill(c, join10(c.home, ".cursor", "skills"));
|
|
1085
|
+
c.log?.("cursor-cli: hooks + MCP entry + skill removed");
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
var copilot = {
|
|
1089
|
+
name: "copilot-cli",
|
|
1090
|
+
detect: (c) => onPath("copilot") || existsSync5(join10(c.home, ".copilot")),
|
|
1091
|
+
install(c) {
|
|
1092
|
+
const hooksPath = join10(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
|
|
1093
|
+
const hooks = {};
|
|
1094
|
+
mergeHarnessHooks(hooks, "copilot-cli", c.dist);
|
|
1095
|
+
writeJson(hooksPath, { version: 1, hooks });
|
|
1096
|
+
const mcpPath = join10(c.home, ".copilot", "mcp-config.json");
|
|
1097
|
+
const mcp = readJson(mcpPath);
|
|
1098
|
+
mcp.mcpServers = {
|
|
1099
|
+
...mcp.mcpServers ?? {},
|
|
1100
|
+
hindsight: { command: "node", args: [join10(c.dist, "mcp-server.js")] }
|
|
1101
|
+
};
|
|
1102
|
+
writeJson(mcpPath, mcp);
|
|
1103
|
+
installSkill(c, join10(c.home, ".copilot", "skills"));
|
|
1104
|
+
c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
|
|
1105
|
+
},
|
|
1106
|
+
uninstall(c) {
|
|
1107
|
+
rmSync(join10(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
|
|
1108
|
+
force: true
|
|
1109
|
+
});
|
|
1110
|
+
const mcpPath = join10(c.home, ".copilot", "mcp-config.json");
|
|
1111
|
+
if (existsSync5(mcpPath)) {
|
|
1112
|
+
const mcp = readJson(mcpPath);
|
|
1113
|
+
if (mcp.mcpServers?.hindsight) {
|
|
1114
|
+
delete mcp.mcpServers.hindsight;
|
|
1115
|
+
writeJson(mcpPath, mcp);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
uninstallSkill(c, join10(c.home, ".copilot", "skills"));
|
|
1119
|
+
c.log?.("copilot-cli: hooks + MCP entry + skill removed");
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
var GROK_MARKER_START = "# HINDSIGHT_CODING_AGENTS_GROK_START";
|
|
1123
|
+
var GROK_MARKER_END = "# HINDSIGHT_CODING_AGENTS_GROK_END";
|
|
1124
|
+
var GROK_BLOCK_RE = new RegExp(`\\n?${GROK_MARKER_START}[\\s\\S]*?${GROK_MARKER_END}\\n?`);
|
|
1125
|
+
var grok = {
|
|
1126
|
+
name: "grok-build",
|
|
1127
|
+
detect: (c) => onPath("grok") || existsSync5(join10(c.home, ".grok")),
|
|
1128
|
+
install(c) {
|
|
1129
|
+
const path = join10(c.home, ".grok", "config.toml");
|
|
1130
|
+
const existing = existsSync5(path) ? readFileSync13(path, "utf8") : "";
|
|
1131
|
+
const withoutOurs = existing.replace(GROK_BLOCK_RE, "\n");
|
|
1132
|
+
const command = (entry) => JSON.stringify(`node "${join10(c.dist, entry)}"`);
|
|
1133
|
+
const tomlString = (value) => JSON.stringify(value);
|
|
1134
|
+
const block = `
|
|
1135
|
+
${GROK_MARKER_START}
|
|
1136
|
+
[[hooks.SessionStart]]
|
|
1137
|
+
[[hooks.SessionStart.hooks]]
|
|
1138
|
+
type = "command"
|
|
1139
|
+
command = ${command("grok-sessionstart-hook.js")}
|
|
1140
|
+
timeout = 30
|
|
1141
|
+
|
|
1142
|
+
[[hooks.UserPromptSubmit]]
|
|
1143
|
+
[[hooks.UserPromptSubmit.hooks]]
|
|
1144
|
+
type = "command"
|
|
1145
|
+
command = ${command("grok-hook.js")}
|
|
1146
|
+
timeout = 30
|
|
1147
|
+
|
|
1148
|
+
[[hooks.Stop]]
|
|
1149
|
+
[[hooks.Stop.hooks]]
|
|
1150
|
+
type = "command"
|
|
1151
|
+
command = ${command("grok-stop-hook.js")}
|
|
1152
|
+
timeout = 60
|
|
1153
|
+
|
|
1154
|
+
[mcp_servers.hindsight]
|
|
1155
|
+
command = "node"
|
|
1156
|
+
args = [${tomlString(join10(c.dist, "mcp-server.js"))}]
|
|
1157
|
+
${GROK_MARKER_END}
|
|
1158
|
+
`;
|
|
1159
|
+
if (existsSync5(path) && !existsSync5(`${path}.hindsight-backup`))
|
|
1160
|
+
copyFileSync(path, `${path}.hindsight-backup`);
|
|
1161
|
+
mkdirSync3(dirname7(path), { recursive: true });
|
|
1162
|
+
writeFileSync2(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
|
|
1163
|
+
installSkill(c, join10(c.home, ".grok", "skills"));
|
|
1164
|
+
c.log?.(`grok-build: native hooks + MCP installed in ${path}`);
|
|
1165
|
+
},
|
|
1166
|
+
uninstall(c) {
|
|
1167
|
+
const path = join10(c.home, ".grok", "config.toml");
|
|
1168
|
+
if (existsSync5(path)) {
|
|
1169
|
+
const existing = readFileSync13(path, "utf8");
|
|
1170
|
+
const cleaned = existing.replace(GROK_BLOCK_RE, "\n");
|
|
1171
|
+
if (cleaned !== existing) writeFileSync2(path, cleaned);
|
|
1172
|
+
}
|
|
1173
|
+
uninstallSkill(c, join10(c.home, ".grok", "skills"));
|
|
1174
|
+
c.log?.("grok-build: native hooks + MCP + skill removed");
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
|
|
1178
|
+
var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
|
|
1179
|
+
var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
1180
|
+
function removeLegacyClineHooks(c) {
|
|
1181
|
+
const hooksDir = join10(c.home, "Documents", "Cline", "Hooks");
|
|
1182
|
+
for (const event of CLINE_OLD_HOOK_EVENTS) {
|
|
1183
|
+
const path = join10(hooksDir, event);
|
|
1184
|
+
if (existsSync5(path) && readFileSync13(path, "utf8").includes(CLINE_HOOK_MARKER)) {
|
|
1185
|
+
rmSync(path, { force: true });
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
var cline = {
|
|
1190
|
+
name: "cline-cli",
|
|
1191
|
+
detect: (c) => onPath("cline") || existsSync5(join10(c.home, ".cline")),
|
|
1192
|
+
install(c) {
|
|
1193
|
+
removeLegacyClineHooks(c);
|
|
1194
|
+
const installed = (c.clinePlugin ?? runClinePlugin)([
|
|
1195
|
+
"plugin",
|
|
1196
|
+
"install",
|
|
1197
|
+
"--force",
|
|
1198
|
+
c.pkgRoot
|
|
1199
|
+
]);
|
|
1200
|
+
const mcpPath = join10(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
1201
|
+
const mcp = readJson(mcpPath);
|
|
1202
|
+
mcp.mcpServers = {
|
|
1203
|
+
...mcp.mcpServers ?? {},
|
|
1204
|
+
hindsight: {
|
|
1205
|
+
command: "node",
|
|
1206
|
+
args: [join10(c.dist, "mcp-server.js")],
|
|
1207
|
+
env: { HINDSIGHT_MCP_HARNESS: "cline-cli" }
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
writeJson(mcpPath, mcp);
|
|
1211
|
+
installSkill(c, join10(c.home, ".cline", "data", "settings", "skills"));
|
|
1212
|
+
c.log?.(
|
|
1213
|
+
installed ? "cline-cli: native plugin + MCP + skill installed" : `cline-cli: MCP + skill installed; run: cline plugin install --force "${c.pkgRoot}"`
|
|
1214
|
+
);
|
|
1215
|
+
},
|
|
1216
|
+
uninstall(c) {
|
|
1217
|
+
removeLegacyClineHooks(c);
|
|
1218
|
+
(c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
|
|
1219
|
+
const mcpPath = join10(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
1220
|
+
if (existsSync5(mcpPath)) {
|
|
1221
|
+
const mcp = readJson(mcpPath);
|
|
1222
|
+
if (mcp.mcpServers?.hindsight) {
|
|
1223
|
+
delete mcp.mcpServers.hindsight;
|
|
1224
|
+
writeJson(mcpPath, mcp);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
uninstallSkill(c, join10(c.home, ".cline", "data", "settings", "skills"));
|
|
1228
|
+
c.log?.("cline-cli: native plugin + MCP + skill removed");
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
var INSTALLERS = [
|
|
1232
|
+
opencode,
|
|
1233
|
+
kilo,
|
|
1234
|
+
claudeCode,
|
|
1235
|
+
codex,
|
|
1236
|
+
antigravity,
|
|
1237
|
+
devin,
|
|
1238
|
+
cursor,
|
|
1239
|
+
copilot,
|
|
1240
|
+
grok,
|
|
1241
|
+
cline
|
|
1242
|
+
];
|
|
1243
|
+
var HARNESS_ALIASES = { agy: "antigravity-cli" };
|
|
1244
|
+
function run(argv, ctx) {
|
|
1245
|
+
const [command, ...names] = argv;
|
|
1246
|
+
if (command === "install" && /\/(_npx|\.npm\/_npx|dlx-)\/|\/_cacache\//.test(ctx.pkgRoot)) {
|
|
1247
|
+
ctx.log?.(
|
|
1248
|
+
"refusing to install from an npx/dlx cache: the hook wiring would point into a cache npm can evict, silently breaking every session.\nInstall the package permanently, then re-run:\n npm install -g hindsight-coding-agents && hindsight-coding-agents install"
|
|
1249
|
+
);
|
|
1250
|
+
return 1;
|
|
1251
|
+
}
|
|
1252
|
+
if (command !== "install" && command !== "uninstall") {
|
|
1253
|
+
ctx.log?.(
|
|
1254
|
+
`usage: hindsight-coding-agents <install|uninstall> [harness...]
|
|
1255
|
+
harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy is an alias for antigravity-cli; default: every one detected on this machine)`
|
|
1256
|
+
);
|
|
1257
|
+
return command ? 1 : 0;
|
|
1258
|
+
}
|
|
1259
|
+
let targets;
|
|
1260
|
+
if (names.length) {
|
|
1261
|
+
targets = [];
|
|
1262
|
+
for (const n of names) {
|
|
1263
|
+
const hit = INSTALLERS.find((i) => i.name === (HARNESS_ALIASES[n] ?? n));
|
|
1264
|
+
if (!hit) {
|
|
1265
|
+
ctx.log?.(
|
|
1266
|
+
`unknown harness "${n}" \u2014 expected one of: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)`
|
|
1267
|
+
);
|
|
1268
|
+
return 1;
|
|
1269
|
+
}
|
|
1270
|
+
targets.push(hit);
|
|
1271
|
+
}
|
|
1272
|
+
} else {
|
|
1273
|
+
targets = INSTALLERS.filter((i) => i.detect(ctx));
|
|
1274
|
+
if (!targets.length) {
|
|
1275
|
+
ctx.log?.("no supported coding agents detected \u2014 pass harness names explicitly");
|
|
1276
|
+
return 1;
|
|
1277
|
+
}
|
|
1278
|
+
ctx.log?.(`detected: ${targets.map((t) => t.name).join(", ")}`);
|
|
1279
|
+
}
|
|
1280
|
+
for (const t of targets) t[command](ctx);
|
|
1281
|
+
ctx.log?.(
|
|
1282
|
+
command === "install" ? `
|
|
1283
|
+
\u2705 installed. Configure the server in ~/.hindsight/coding-agent.json (apiUrl/apiToken) and start a session.` : `
|
|
1284
|
+
\u2705 uninstalled.`
|
|
1285
|
+
);
|
|
1286
|
+
return 0;
|
|
1287
|
+
}
|
|
1288
|
+
var mainPath = process.argv[1] ? (() => {
|
|
1289
|
+
try {
|
|
1290
|
+
return realpathSync(process.argv[1]);
|
|
1291
|
+
} catch {
|
|
1292
|
+
return process.argv[1];
|
|
1293
|
+
}
|
|
1294
|
+
})() : void 0;
|
|
1295
|
+
var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
|
|
1296
|
+
if (isMain || mainPath?.endsWith("installer.js")) {
|
|
1297
|
+
const dist = dirname7(fileURLToPath4(import.meta.url));
|
|
1298
|
+
process.exit(
|
|
1299
|
+
run(process.argv.slice(2), {
|
|
1300
|
+
home: homedir7(),
|
|
1301
|
+
pkgRoot: dirname7(dist),
|
|
1302
|
+
dist,
|
|
1303
|
+
log: (m) => console.log(m)
|
|
1304
|
+
})
|
|
1305
|
+
);
|
|
1306
|
+
}
|
|
1307
|
+
export {
|
|
1308
|
+
INSTALLERS,
|
|
1309
|
+
KILO_CONFIG_CANDIDATES,
|
|
1310
|
+
MARKER,
|
|
1311
|
+
parseJsonc,
|
|
1312
|
+
run
|
|
1313
|
+
};
|