@vectorize-io/hindsight-coding-agents 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -79
- package/dist/antigravity-hook.js +46 -17
- package/dist/antigravity-statusline.js +25 -1
- package/dist/antigravity-stop-hook.js +158 -17
- package/dist/claude-hook.js +46 -17
- package/dist/claude-sessionstart-hook.js +169 -28
- package/dist/claude-stop-hook.js +158 -17
- package/dist/cline.js +35 -6
- package/dist/codex-hook.js +46 -17
- package/dist/codex-sessionstart-hook.js +169 -28
- package/dist/codex-stop-hook.js +158 -17
- package/dist/copilot-hook.js +46 -17
- package/dist/copilot-sessionstart-hook.js +169 -28
- package/dist/copilot-stop-hook.js +158 -17
- package/dist/cursor-hook.js +46 -17
- package/dist/cursor-sessionstart-hook.js +169 -28
- package/dist/cursor-stop-hook.js +158 -17
- package/dist/daemon-start.js +626 -0
- package/dist/deepen.js +25 -1
- package/dist/devin-hook.js +46 -17
- package/dist/devin-sessionstart-hook.js +169 -28
- package/dist/devin-stop-hook.js +158 -17
- package/dist/grok-hook.js +46 -17
- package/dist/grok-sessionstart-hook.js +169 -28
- package/dist/grok-stop-hook.js +158 -17
- package/dist/hindsight-seed.js +25 -1
- package/dist/index.js +35 -6
- package/dist/installer.js +717 -173
- package/dist/kilo.js +35 -6
- package/dist/mcp-server.js +25 -1
- package/dist/status.js +25 -1
- package/package.json +2 -1
package/dist/installer.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/installer.ts
|
|
4
|
-
import { execFileSync as
|
|
4
|
+
import { execFileSync as execFileSync6 } from "child_process";
|
|
5
5
|
import {
|
|
6
6
|
copyFileSync,
|
|
7
7
|
cpSync as cpSync2,
|
|
8
|
-
existsSync as
|
|
8
|
+
existsSync as existsSync8,
|
|
9
9
|
mkdirSync as mkdirSync3,
|
|
10
10
|
mkdtempSync,
|
|
11
|
-
readFileSync as
|
|
11
|
+
readFileSync as readFileSync15,
|
|
12
|
+
readSync as readSync3,
|
|
12
13
|
realpathSync,
|
|
13
14
|
rmSync,
|
|
14
15
|
writeFileSync as writeFileSync2
|
|
15
16
|
} from "fs";
|
|
16
|
-
import { homedir as
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { homedir as homedir9, tmpdir as tmpdir3 } from "os";
|
|
18
|
+
import { isatty } from "tty";
|
|
19
|
+
import { dirname as dirname8, join as join13 } from "path";
|
|
20
|
+
import { fileURLToPath as fileURLToPath5, pathToFileURL } from "url";
|
|
19
21
|
|
|
20
22
|
// src/core/hook.ts
|
|
21
23
|
import { existsSync, readFileSync as readFileSync3 } from "fs";
|
|
@@ -37,6 +39,7 @@ import { fileURLToPath } from "url";
|
|
|
37
39
|
|
|
38
40
|
// src/core/config.ts
|
|
39
41
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
|
|
42
|
+
var DEFAULT_DAEMON_PORT = 9077;
|
|
40
43
|
|
|
41
44
|
// src/core/diag.ts
|
|
42
45
|
import { appendFileSync as appendFileSync2 } from "fs";
|
|
@@ -83,6 +86,20 @@ function diag(harness, event, extra = {}) {
|
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
|
|
89
|
+
// src/core/brand.ts
|
|
90
|
+
function brandWord() {
|
|
91
|
+
const start = [0, 116, 217];
|
|
92
|
+
const end = [0, 146, 150];
|
|
93
|
+
const word = "Hindsight";
|
|
94
|
+
let out = "";
|
|
95
|
+
for (let i = 0; i < word.length; i++) {
|
|
96
|
+
const t = i / (word.length - 1);
|
|
97
|
+
const [r, g, b] = start.map((s, k) => Math.round(s + (end[k] - s) * t));
|
|
98
|
+
out += `\x1B[38;2;${r};${g};${b}m${word[i]}`;
|
|
99
|
+
}
|
|
100
|
+
return `${out}\x1B[0m`;
|
|
101
|
+
}
|
|
102
|
+
|
|
86
103
|
// src/core/session-cache.ts
|
|
87
104
|
import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
88
105
|
import { tmpdir as tmpdir2 } from "os";
|
|
@@ -91,6 +108,60 @@ import { dirname as dirname4, join as join5 } from "path";
|
|
|
91
108
|
// src/core/retain-hook.ts
|
|
92
109
|
import { readFileSync as readFileSync5 } from "fs";
|
|
93
110
|
|
|
111
|
+
// src/core/daemon.ts
|
|
112
|
+
import { execFileSync as execFileSync2, spawn as realSpawn2 } from "child_process";
|
|
113
|
+
import { dirname as dirname5, join as join6 } from "path";
|
|
114
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
115
|
+
function hasRustToolchain() {
|
|
116
|
+
if (process.platform !== "darwin") return true;
|
|
117
|
+
try {
|
|
118
|
+
execFileSync2("cargo", ["--version"], { stdio: "pipe", timeout: 1e4 });
|
|
119
|
+
return true;
|
|
120
|
+
} catch {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function hasUvx() {
|
|
125
|
+
try {
|
|
126
|
+
execFileSync2("uvx", ["--version"], { stdio: "pipe", timeout: 1e4 });
|
|
127
|
+
return true;
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
var PROVIDER_PROBES = [
|
|
133
|
+
{ provider: "openai", keyEnv: "OPENAI_API_KEY" },
|
|
134
|
+
{ provider: "anthropic", keyEnv: "ANTHROPIC_API_KEY" },
|
|
135
|
+
{ provider: "gemini", keyEnv: "GEMINI_API_KEY" },
|
|
136
|
+
{ provider: "groq", keyEnv: "GROQ_API_KEY" }
|
|
137
|
+
];
|
|
138
|
+
function detectLlm(env = process.env) {
|
|
139
|
+
const explicit = env.HINDSIGHT_API_LLM_PROVIDER?.trim();
|
|
140
|
+
if (explicit) {
|
|
141
|
+
return {
|
|
142
|
+
provider: explicit,
|
|
143
|
+
apiKey: env.HINDSIGHT_API_LLM_API_KEY?.trim() || void 0,
|
|
144
|
+
source: "HINDSIGHT_API_LLM_PROVIDER"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
for (const probe of PROVIDER_PROBES) {
|
|
148
|
+
const key = env[probe.keyEnv]?.trim();
|
|
149
|
+
if (key) return { provider: probe.provider, apiKey: key, source: probe.keyEnv };
|
|
150
|
+
}
|
|
151
|
+
if (onPath("claude")) {
|
|
152
|
+
return { provider: "claude-code", source: "the Claude Code CLI on PATH (no API key needed)" };
|
|
153
|
+
}
|
|
154
|
+
return void 0;
|
|
155
|
+
}
|
|
156
|
+
function onPath(bin) {
|
|
157
|
+
try {
|
|
158
|
+
execFileSync2("which", [bin], { stdio: "pipe", timeout: 5e3 });
|
|
159
|
+
return true;
|
|
160
|
+
} catch {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
94
165
|
// src/core/transcript.ts
|
|
95
166
|
import { readFileSync as readFileSync4 } from "fs";
|
|
96
167
|
|
|
@@ -189,24 +260,24 @@ function readClaudeTranscript(path) {
|
|
|
189
260
|
import { readFileSync as readFileSync7 } from "fs";
|
|
190
261
|
|
|
191
262
|
// src/core/git.ts
|
|
192
|
-
import { execFileSync as
|
|
263
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
193
264
|
import { resolve } from "path";
|
|
194
265
|
|
|
195
266
|
// src/core/status.ts
|
|
196
|
-
import { execFileSync as
|
|
267
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
197
268
|
|
|
198
269
|
// src/core/survey.ts
|
|
199
|
-
import { spawn as
|
|
270
|
+
import { spawn as realSpawn3 } from "child_process";
|
|
200
271
|
import { accessSync, constants, existsSync as existsSync2 } from "fs";
|
|
201
272
|
import { homedir as homedir3 } from "os";
|
|
202
|
-
import { delimiter, dirname as
|
|
203
|
-
import { fileURLToPath as
|
|
273
|
+
import { delimiter, dirname as dirname6, join as join7 } from "path";
|
|
274
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
204
275
|
|
|
205
276
|
// src/core/skill-sync.ts
|
|
206
277
|
import { cpSync, existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
|
|
207
278
|
import { homedir as homedir4 } from "os";
|
|
208
|
-
import { dirname as
|
|
209
|
-
import { fileURLToPath as
|
|
279
|
+
import { dirname as dirname7, join as join8 } from "path";
|
|
280
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
210
281
|
|
|
211
282
|
// src/core/transcript-codex.ts
|
|
212
283
|
import { readFileSync as readFileSync8 } from "fs";
|
|
@@ -368,17 +439,17 @@ function readCopilotTranscript(path) {
|
|
|
368
439
|
// src/core/transcript-grok.ts
|
|
369
440
|
import { existsSync as existsSync4, readFileSync as readFileSync12, readdirSync } from "fs";
|
|
370
441
|
import { homedir as homedir5 } from "os";
|
|
371
|
-
import { join as
|
|
442
|
+
import { join as join9 } from "path";
|
|
372
443
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
373
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
374
|
-
const sessionsDir =
|
|
375
|
-
const direct =
|
|
444
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join9(homedir5(), ".grok")) {
|
|
445
|
+
const sessionsDir = join9(grokHome, "sessions");
|
|
446
|
+
const direct = join9(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
376
447
|
if (existsSync4(direct)) return direct;
|
|
377
448
|
try {
|
|
378
449
|
for (const candidate of readdirSync(sessionsDir)) {
|
|
379
|
-
const directory =
|
|
380
|
-
if (readFileSync12(
|
|
381
|
-
return
|
|
450
|
+
const directory = join9(sessionsDir, candidate);
|
|
451
|
+
if (readFileSync12(join9(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
452
|
+
return join9(directory, sessionId, CHAT_HISTORY);
|
|
382
453
|
}
|
|
383
454
|
}
|
|
384
455
|
} catch {
|
|
@@ -422,9 +493,9 @@ function readGrokTranscript(path) {
|
|
|
422
493
|
import { existsSync as existsSync5 } from "fs";
|
|
423
494
|
import { createRequire } from "module";
|
|
424
495
|
import { homedir as homedir6 } from "os";
|
|
425
|
-
import { join as
|
|
496
|
+
import { join as join10 } from "path";
|
|
426
497
|
function devinSessionDb(home = homedir6()) {
|
|
427
|
-
return
|
|
498
|
+
return join10(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
428
499
|
}
|
|
429
500
|
function parseDevinMessages(nodes) {
|
|
430
501
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -777,9 +848,9 @@ import {
|
|
|
777
848
|
statSync
|
|
778
849
|
} from "fs";
|
|
779
850
|
import { homedir as homedir7 } from "os";
|
|
780
|
-
import { join as
|
|
851
|
+
import { join as join11 } from "path";
|
|
781
852
|
function claudeProjectDir(repoDir, home = homedir7()) {
|
|
782
|
-
return
|
|
853
|
+
return join11(home, ".claude", "projects", repoDir.replace(/[/.]/g, "-"));
|
|
783
854
|
}
|
|
784
855
|
function withinRepo(dir, repoDir) {
|
|
785
856
|
return !!dir && (dir === repoDir || dir.startsWith(repoDir.endsWith("/") ? repoDir : repoDir + "/"));
|
|
@@ -822,13 +893,13 @@ function firstLine(path, cap = 1e6) {
|
|
|
822
893
|
}
|
|
823
894
|
function jsonlFiles(dir) {
|
|
824
895
|
if (!existsSync6(dir)) return [];
|
|
825
|
-
return readdirSync2(dir).filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
896
|
+
return readdirSync2(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join11(dir, f));
|
|
826
897
|
}
|
|
827
898
|
function claudeHistory(repoDir, home) {
|
|
828
|
-
const root =
|
|
899
|
+
const root = join11(home, ".claude", "projects");
|
|
829
900
|
const exact = claudeProjectDir(repoDir, home);
|
|
830
901
|
const prefix = exact + "-";
|
|
831
|
-
const dirs = existsSync6(root) ? readdirSync2(root).map((d) =>
|
|
902
|
+
const dirs = existsSync6(root) ? readdirSync2(root).map((d) => join11(root, d)).filter((d) => d === exact || d.startsWith(prefix)) : [];
|
|
832
903
|
const sessions = [];
|
|
833
904
|
let unattributed = 0;
|
|
834
905
|
for (const file of dirs.flatMap(jsonlFiles)) {
|
|
@@ -848,12 +919,12 @@ function claudeHistory(repoDir, home) {
|
|
|
848
919
|
return { supported: true, sessions, unattributed };
|
|
849
920
|
}
|
|
850
921
|
function codexHistory(repoDir, home) {
|
|
851
|
-
const root =
|
|
922
|
+
const root = join11(home, ".codex", "sessions");
|
|
852
923
|
if (!existsSync6(root)) return { supported: true, sessions: [] };
|
|
853
924
|
const files = [];
|
|
854
925
|
const walk = (dir) => {
|
|
855
926
|
for (const entry of readdirSync2(dir)) {
|
|
856
|
-
const p =
|
|
927
|
+
const p = join11(dir, entry);
|
|
857
928
|
if (statSync(p).isDirectory()) walk(p);
|
|
858
929
|
else if (entry.endsWith(".jsonl")) files.push(p);
|
|
859
930
|
}
|
|
@@ -896,11 +967,262 @@ function importLocalHistory(harness, repoDir, home = homedir7()) {
|
|
|
896
967
|
}
|
|
897
968
|
}
|
|
898
969
|
|
|
970
|
+
// src/core/legacy.ts
|
|
971
|
+
import { existsSync as existsSync7, readFileSync as readFileSync14 } from "fs";
|
|
972
|
+
import { homedir as homedir8 } from "os";
|
|
973
|
+
import { join as join12 } from "path";
|
|
974
|
+
var LEGACY_CONFIG_FILES = {
|
|
975
|
+
"claude-code": "claude-code.json",
|
|
976
|
+
codex: "codex.json"
|
|
977
|
+
};
|
|
978
|
+
function legacyConfigPath(harness, home = homedir8()) {
|
|
979
|
+
return join12(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
|
|
980
|
+
}
|
|
981
|
+
var CLOUD_URL = "https://api.hindsight.vectorize.io";
|
|
982
|
+
function readLegacyEndpoint(home = homedir8(), prefer = []) {
|
|
983
|
+
const order = [...prefer, ...Object.keys(LEGACY_CONFIG_FILES)].filter(
|
|
984
|
+
(h, i, all) => h in LEGACY_CONFIG_FILES && all.indexOf(h) === i
|
|
985
|
+
);
|
|
986
|
+
for (const harness of order) {
|
|
987
|
+
const found = readOne(harness, home);
|
|
988
|
+
if (found) return found;
|
|
989
|
+
}
|
|
990
|
+
return void 0;
|
|
991
|
+
}
|
|
992
|
+
function readOne(harness, home) {
|
|
993
|
+
const source = legacyConfigPath(harness, home);
|
|
994
|
+
if (!existsSync7(source)) return void 0;
|
|
995
|
+
let raw;
|
|
996
|
+
try {
|
|
997
|
+
raw = JSON.parse(readFileSync14(source, "utf8"));
|
|
998
|
+
} catch {
|
|
999
|
+
return void 0;
|
|
1000
|
+
}
|
|
1001
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
1002
|
+
const apiToken = typeof raw.hindsightApiToken === "string" ? raw.hindsightApiToken : void 0;
|
|
1003
|
+
const url = typeof raw.hindsightApiUrl === "string" ? raw.hindsightApiUrl.trim() : "";
|
|
1004
|
+
if (url) {
|
|
1005
|
+
return {
|
|
1006
|
+
harness,
|
|
1007
|
+
serverMode: url.replace(/\/+$/, "") === CLOUD_URL ? "cloud" : "self-hosted",
|
|
1008
|
+
apiUrl: url,
|
|
1009
|
+
...apiToken ? { apiToken } : {},
|
|
1010
|
+
source
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
const port = typeof raw.apiPort === "number" ? raw.apiPort : void 0;
|
|
1014
|
+
return {
|
|
1015
|
+
harness,
|
|
1016
|
+
serverMode: "daemon",
|
|
1017
|
+
...apiToken ? { apiToken } : {},
|
|
1018
|
+
...port && port !== DEFAULT_DAEMON_PORT ? { apiPort: port } : {},
|
|
1019
|
+
source
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
// src/install-ui.ts
|
|
1024
|
+
import { execFileSync as execFileSync5 } from "child_process";
|
|
1025
|
+
import { readSync as readSync2 } from "fs";
|
|
1026
|
+
function fitSelectRow(label, hint, width) {
|
|
1027
|
+
const room = Math.max(10, width - 6);
|
|
1028
|
+
let hintText = hint ? ` \u2014 ${hint}` : "";
|
|
1029
|
+
if (label.length > room) return { label: `${label.slice(0, room - 1)}\u2026`, hint: "" };
|
|
1030
|
+
if (label.length + hintText.length > room) {
|
|
1031
|
+
hintText = `${hintText.slice(0, room - label.length - 1)}\u2026`;
|
|
1032
|
+
}
|
|
1033
|
+
return { label, hint: hintText };
|
|
1034
|
+
}
|
|
1035
|
+
function splitKeys(chunk) {
|
|
1036
|
+
const keys = [];
|
|
1037
|
+
for (let i = 0; i < chunk.length; ) {
|
|
1038
|
+
if (chunk[i] === "\x1B" && chunk[i + 1] === "[") {
|
|
1039
|
+
let j = i + 2;
|
|
1040
|
+
while (j < chunk.length && !(chunk[j] >= "@" && chunk[j] <= "~")) j++;
|
|
1041
|
+
keys.push(chunk.slice(i, Math.min(j + 1, chunk.length)));
|
|
1042
|
+
i = j + 1;
|
|
1043
|
+
} else {
|
|
1044
|
+
keys.push(chunk[i]);
|
|
1045
|
+
i += 1;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return keys;
|
|
1049
|
+
}
|
|
1050
|
+
function selectKeyAction(key, index, count) {
|
|
1051
|
+
if (key === "\x1B[A" || key === "k") return { kind: "move", index: (index + count - 1) % count };
|
|
1052
|
+
if (key === "\x1B[B" || key === "j") return { kind: "move", index: (index + 1) % count };
|
|
1053
|
+
if (key === "\r" || key === "\n") return { kind: "submit", index };
|
|
1054
|
+
if (key === "" || key === "\x1B" || key === "q") return { kind: "cancel", index };
|
|
1055
|
+
const digit = Number.parseInt(key, 10);
|
|
1056
|
+
if (digit >= 1 && digit <= count) return { kind: "submit", index: digit - 1 };
|
|
1057
|
+
return { kind: "none", index };
|
|
1058
|
+
}
|
|
1059
|
+
var WARN_RE = /\bskipped\b|could not|manually|preserved|did not finish|unrecognised|add `hooks = true`/i;
|
|
1060
|
+
var ERROR_RE = /unknown harness|no supported coding agents|name a harness/;
|
|
1061
|
+
var INFO_RE = /^usage:|^detected: |\?$/;
|
|
1062
|
+
var EMOJI_KIND = {
|
|
1063
|
+
"\u2705": "ok",
|
|
1064
|
+
"\u26A0\uFE0F": "warn",
|
|
1065
|
+
"\u274C": "error"
|
|
1066
|
+
};
|
|
1067
|
+
function createInstallerUi(o) {
|
|
1068
|
+
const sink = o.write ?? ((line) => console.log(line));
|
|
1069
|
+
let lastLine = "";
|
|
1070
|
+
const write2 = (line) => {
|
|
1071
|
+
lastLine = line;
|
|
1072
|
+
sink(line);
|
|
1073
|
+
};
|
|
1074
|
+
const colors = o.colors ?? (process.stdout.isTTY === true && process.env.NO_COLOR === void 0 && process.env.TERM !== "dumb");
|
|
1075
|
+
const now = o.now ?? Date.now;
|
|
1076
|
+
const paint = (code, s) => colors ? `\x1B[${code}m${s}\x1B[0m` : s;
|
|
1077
|
+
const dim = (s) => paint("2", s);
|
|
1078
|
+
const bold = (s) => paint("1", s);
|
|
1079
|
+
const green = (s) => paint("32", s);
|
|
1080
|
+
const yellow = (s) => paint("33", s);
|
|
1081
|
+
const red = (s) => paint("31", s);
|
|
1082
|
+
const cyan = (s) => paint("36", s);
|
|
1083
|
+
const bar = dim("\u2502");
|
|
1084
|
+
const symbol = { ok: green("\u2713"), warn: yellow("\u25B2"), error: red("\u2716"), info: dim("\u25CB") };
|
|
1085
|
+
const tidy = (s) => s.replaceAll(o.home, "~");
|
|
1086
|
+
const dimPaths = (s) => s.replace(/(?<![:\w/])~?\/[^\s"',)]+/g, (m) => dim(m));
|
|
1087
|
+
const prefixRe = new RegExp(`^(${[...o.harnessNames, ...o.auxNames ?? []].join("|")}): `);
|
|
1088
|
+
const startedAt = now();
|
|
1089
|
+
let group = null;
|
|
1090
|
+
let groups = 0;
|
|
1091
|
+
function classify(line) {
|
|
1092
|
+
if (INFO_RE.test(line)) return "info";
|
|
1093
|
+
if (ERROR_RE.test(line)) return "error";
|
|
1094
|
+
if (WARN_RE.test(line)) return "warn";
|
|
1095
|
+
return "ok";
|
|
1096
|
+
}
|
|
1097
|
+
const spacer = () => {
|
|
1098
|
+
if (lastLine !== bar) write2(bar);
|
|
1099
|
+
};
|
|
1100
|
+
function openGroup(name) {
|
|
1101
|
+
spacer();
|
|
1102
|
+
write2(`${cyan("\u25C7")} ${bold(name)}`);
|
|
1103
|
+
group = name;
|
|
1104
|
+
if (o.harnessNames.includes(name)) groups++;
|
|
1105
|
+
}
|
|
1106
|
+
return {
|
|
1107
|
+
intro() {
|
|
1108
|
+
write2("");
|
|
1109
|
+
write2(
|
|
1110
|
+
`${dim("\u250C")} ${colors ? brandWord() : "Hindsight"} ${bold("coding agents")}` + (o.version ? ` ${dim(`v${o.version}`)}` : "")
|
|
1111
|
+
);
|
|
1112
|
+
write2(bar);
|
|
1113
|
+
},
|
|
1114
|
+
/** Style an interactive question so readline prompts sit on the rail like log lines. */
|
|
1115
|
+
prompt(question) {
|
|
1116
|
+
return `${bar} ${question}`;
|
|
1117
|
+
},
|
|
1118
|
+
select(question, options, defaultIndex) {
|
|
1119
|
+
const stty = (args) => execFileSync5("stty", args, { stdio: ["inherit", "pipe", "pipe"], encoding: "utf8" }).trim();
|
|
1120
|
+
let savedTty;
|
|
1121
|
+
try {
|
|
1122
|
+
savedTty = stty(["-g"]);
|
|
1123
|
+
stty(["raw", "-echo"]);
|
|
1124
|
+
} catch {
|
|
1125
|
+
return void 0;
|
|
1126
|
+
}
|
|
1127
|
+
const render = (index2, redraw) => {
|
|
1128
|
+
const width = process.stdout.columns || 80;
|
|
1129
|
+
const rows = options.map((opt, i) => {
|
|
1130
|
+
const on = i === index2;
|
|
1131
|
+
const pointer = on ? cyan("\u276F") : " ";
|
|
1132
|
+
const fitted = fitSelectRow(opt.label, opt.hint, width);
|
|
1133
|
+
const label = on ? bold(fitted.label) : fitted.label;
|
|
1134
|
+
return `\x1B[2K${bar} ${pointer} ${label}${fitted.hint ? dim(fitted.hint) : ""}`;
|
|
1135
|
+
});
|
|
1136
|
+
if (redraw) process.stdout.write(`\x1B[${options.length}A`);
|
|
1137
|
+
process.stdout.write(rows.map((r) => `\r${r}\r
|
|
1138
|
+
`).join(""));
|
|
1139
|
+
};
|
|
1140
|
+
lastLine = "select";
|
|
1141
|
+
process.stdout.write("\x1B[?7l");
|
|
1142
|
+
process.stdout.write(`${bar} ${symbol.info} ${dim(question)} ${dim("(\u2191/\u2193, Enter)")}\r
|
|
1143
|
+
`);
|
|
1144
|
+
let index = Math.min(Math.max(defaultIndex, 0), options.length - 1);
|
|
1145
|
+
render(index, false);
|
|
1146
|
+
const buf = Buffer.alloc(16);
|
|
1147
|
+
try {
|
|
1148
|
+
for (; ; ) {
|
|
1149
|
+
let n;
|
|
1150
|
+
try {
|
|
1151
|
+
n = readSync2(0, buf, 0, buf.length, null);
|
|
1152
|
+
} catch (e) {
|
|
1153
|
+
if (e.code !== "EAGAIN") return null;
|
|
1154
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 25);
|
|
1155
|
+
continue;
|
|
1156
|
+
}
|
|
1157
|
+
if (n === 0) return null;
|
|
1158
|
+
for (const key of splitKeys(buf.subarray(0, n).toString("latin1"))) {
|
|
1159
|
+
const action = selectKeyAction(key, index, options.length);
|
|
1160
|
+
index = action.index;
|
|
1161
|
+
if (action.kind === "move") render(index, true);
|
|
1162
|
+
else if (action.kind === "submit") {
|
|
1163
|
+
render(index, true);
|
|
1164
|
+
return index;
|
|
1165
|
+
} else if (action.kind === "cancel") return null;
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
} finally {
|
|
1169
|
+
process.stdout.write("\x1B[?7h");
|
|
1170
|
+
try {
|
|
1171
|
+
stty([savedTty]);
|
|
1172
|
+
} catch {
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
},
|
|
1176
|
+
log(message) {
|
|
1177
|
+
const text = tidy(message).replace(/^\n+|\n+$/g, "");
|
|
1178
|
+
if (!text) return;
|
|
1179
|
+
const lines = text.split("\n");
|
|
1180
|
+
if (/^\s/.test(lines[0])) {
|
|
1181
|
+
for (const l of lines) write2(`${bar} ${dim(l.trim())}`);
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
const emoji = lines[0].match(/^(✅|❌|⚠️)\s*/u);
|
|
1185
|
+
if (emoji) lines[0] = lines[0].slice(emoji[0].length);
|
|
1186
|
+
const prefixed = lines[0].match(prefixRe);
|
|
1187
|
+
if (prefixed) {
|
|
1188
|
+
if (prefixed[1] !== group) openGroup(prefixed[1]);
|
|
1189
|
+
lines[0] = lines[0].slice(prefixed[0].length);
|
|
1190
|
+
}
|
|
1191
|
+
const kind = emoji ? EMOJI_KIND[emoji[1]] : classify(lines[0]);
|
|
1192
|
+
write2(`${bar} ${symbol[kind]} ${kind === "info" ? dim(lines[0]) : dimPaths(lines[0])}`);
|
|
1193
|
+
for (const rest of lines.slice(1)) write2(`${bar} ${dim(rest.trim())}`);
|
|
1194
|
+
},
|
|
1195
|
+
outro(exitCode) {
|
|
1196
|
+
spacer();
|
|
1197
|
+
if (exitCode !== 0) {
|
|
1198
|
+
write2(
|
|
1199
|
+
`${dim("\u2514")} ${red("\u2716")} ${groups ? "Completed with errors \u2014 see above." : "Aborted \u2014 nothing was changed."}`
|
|
1200
|
+
);
|
|
1201
|
+
} else if (o.command === "install" || o.command === "uninstall") {
|
|
1202
|
+
const secs = ((now() - startedAt) / 1e3).toFixed(1);
|
|
1203
|
+
const agents = `${groups} agent${groups === 1 ? "" : "s"}`;
|
|
1204
|
+
if (o.command === "install") {
|
|
1205
|
+
const settings = o.configPath ? tidy(o.configPath) : "~/.hindsight/coding-agent.json";
|
|
1206
|
+
write2(`${dim("\u2514")} ${green("\u2713")} Installed ${agents} in ${secs}s`);
|
|
1207
|
+
write2(` ${dim(`Start a session \u2014 settings live in ${settings}.`)}`);
|
|
1208
|
+
} else {
|
|
1209
|
+
write2(
|
|
1210
|
+
`${dim("\u2514")} ${green("\u2713")} Uninstalled ${agents} in ${secs}s \u2014 Hindsight entries removed, *.hindsight-backup files left in place.`
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
} else {
|
|
1214
|
+
write2(dim("\u2514"));
|
|
1215
|
+
}
|
|
1216
|
+
write2("");
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
|
|
899
1221
|
// src/installer.ts
|
|
900
1222
|
var MARKER = "coding-agents";
|
|
901
1223
|
function readJson(path) {
|
|
902
1224
|
try {
|
|
903
|
-
return JSON.parse(
|
|
1225
|
+
return JSON.parse(readFileSync15(path, "utf8"));
|
|
904
1226
|
} catch {
|
|
905
1227
|
return {};
|
|
906
1228
|
}
|
|
@@ -915,8 +1237,8 @@ function parseJsonc(text) {
|
|
|
915
1237
|
}
|
|
916
1238
|
}
|
|
917
1239
|
function writeJson(path, value) {
|
|
918
|
-
mkdirSync3(
|
|
919
|
-
if (
|
|
1240
|
+
mkdirSync3(dirname8(path), { recursive: true });
|
|
1241
|
+
if (existsSync8(path) && !existsSync8(`${path}.hindsight-backup`)) {
|
|
920
1242
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
921
1243
|
}
|
|
922
1244
|
writeFileSync2(path, JSON.stringify(value, null, 2) + "\n");
|
|
@@ -933,7 +1255,7 @@ function setOrDelete(obj, key, arr) {
|
|
|
933
1255
|
else delete obj[key];
|
|
934
1256
|
}
|
|
935
1257
|
var cmdHook = (dist, file, timeout) => ({
|
|
936
|
-
hooks: [{ type: "command", command: `node "${
|
|
1258
|
+
hooks: [{ type: "command", command: `node "${join13(dist, file)}"`, timeout }]
|
|
937
1259
|
});
|
|
938
1260
|
function mergeHarnessHooks(hooks, harness, dist) {
|
|
939
1261
|
const spec = HOOK_HARNESSES[harness];
|
|
@@ -942,7 +1264,7 @@ function mergeHarnessHooks(hooks, harness, dist) {
|
|
|
942
1264
|
if (installedEvents.has(hook.event)) continue;
|
|
943
1265
|
installedEvents.add(hook.event);
|
|
944
1266
|
const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : {
|
|
945
|
-
command: `node "${
|
|
1267
|
+
command: `node "${join13(dist, hook.entry)}"`,
|
|
946
1268
|
...hook.timeout ? { timeout: hook.timeout } : {}
|
|
947
1269
|
};
|
|
948
1270
|
hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
|
|
@@ -956,20 +1278,20 @@ function stripHarnessHooks(hooks, harness) {
|
|
|
956
1278
|
setOrDelete(hooks, hook.event, stripOurs(hooks[hook.event]));
|
|
957
1279
|
}
|
|
958
1280
|
}
|
|
959
|
-
function installSkill(c, skillsBase) {
|
|
960
|
-
const src =
|
|
961
|
-
if (!
|
|
962
|
-
const dst =
|
|
1281
|
+
function installSkill(c, harness, skillsBase) {
|
|
1282
|
+
const src = join13(c.pkgRoot, "skill");
|
|
1283
|
+
if (!existsSync8(join13(src, "SKILL.md"))) return;
|
|
1284
|
+
const dst = join13(skillsBase, "hindsight-coding-agent");
|
|
963
1285
|
mkdirSync3(skillsBase, { recursive: true });
|
|
964
1286
|
cpSync2(src, dst, { recursive: true });
|
|
965
|
-
c.log?.(
|
|
1287
|
+
c.log?.(`${harness}: skill installed at ${dst}`);
|
|
966
1288
|
}
|
|
967
1289
|
function uninstallSkill(c, skillsBase) {
|
|
968
|
-
rmSync(
|
|
1290
|
+
rmSync(join13(skillsBase, "hindsight-coding-agent"), { recursive: true, force: true });
|
|
969
1291
|
}
|
|
970
|
-
function
|
|
1292
|
+
function onPath2(bin) {
|
|
971
1293
|
try {
|
|
972
|
-
|
|
1294
|
+
execFileSync6("which", [bin], { stdio: "pipe" });
|
|
973
1295
|
return true;
|
|
974
1296
|
} catch {
|
|
975
1297
|
return false;
|
|
@@ -977,7 +1299,7 @@ function onPath(bin) {
|
|
|
977
1299
|
}
|
|
978
1300
|
function runClinePlugin(args) {
|
|
979
1301
|
try {
|
|
980
|
-
|
|
1302
|
+
execFileSync6("cline", args, { stdio: "pipe" });
|
|
981
1303
|
return true;
|
|
982
1304
|
} catch {
|
|
983
1305
|
return false;
|
|
@@ -985,9 +1307,9 @@ function runClinePlugin(args) {
|
|
|
985
1307
|
}
|
|
986
1308
|
var opencode = {
|
|
987
1309
|
name: "opencode",
|
|
988
|
-
detect: (c) =>
|
|
1310
|
+
detect: (c) => onPath2("opencode") || existsSync8(join13(c.home, ".config", "opencode")),
|
|
989
1311
|
install(c) {
|
|
990
|
-
const path =
|
|
1312
|
+
const path = join13(c.home, ".config", "opencode", "opencode.json");
|
|
991
1313
|
const cfg = readJson(path);
|
|
992
1314
|
const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
|
|
993
1315
|
cfg.plugin = [...plugins.filter((p) => !String(p).includes(MARKER)), c.pkgRoot];
|
|
@@ -995,8 +1317,8 @@ var opencode = {
|
|
|
995
1317
|
c.log?.(`opencode: plugin registered in ${path}`);
|
|
996
1318
|
},
|
|
997
1319
|
uninstall(c) {
|
|
998
|
-
const path =
|
|
999
|
-
if (!
|
|
1320
|
+
const path = join13(c.home, ".config", "opencode", "opencode.json");
|
|
1321
|
+
if (!existsSync8(path)) return;
|
|
1000
1322
|
const cfg = readJson(path);
|
|
1001
1323
|
if (Array.isArray(cfg.plugin)) {
|
|
1002
1324
|
cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
@@ -1008,25 +1330,25 @@ var opencode = {
|
|
|
1008
1330
|
};
|
|
1009
1331
|
var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
|
|
1010
1332
|
function kiloConfigPath(c) {
|
|
1011
|
-
const dir =
|
|
1012
|
-
const existing = KILO_CONFIG_CANDIDATES.map((f) =>
|
|
1013
|
-
return existing ??
|
|
1333
|
+
const dir = join13(c.home, ".config", "kilo");
|
|
1334
|
+
const existing = KILO_CONFIG_CANDIDATES.map((f) => join13(dir, f)).find((p) => existsSync8(p));
|
|
1335
|
+
return existing ?? join13(dir, "kilo.json");
|
|
1014
1336
|
}
|
|
1015
1337
|
var kilo = {
|
|
1016
1338
|
name: "kilo",
|
|
1017
|
-
detect: (c) =>
|
|
1339
|
+
detect: (c) => onPath2("kilo") || existsSync8(join13(c.home, ".config", "kilo")),
|
|
1018
1340
|
install(c) {
|
|
1019
1341
|
const path = kiloConfigPath(c);
|
|
1020
1342
|
let cfg = {};
|
|
1021
|
-
if (
|
|
1022
|
-
const parsed = parseJsonc(
|
|
1343
|
+
if (existsSync8(path)) {
|
|
1344
|
+
const parsed = parseJsonc(readFileSync15(path, "utf8"));
|
|
1023
1345
|
if (!parsed) {
|
|
1024
1346
|
c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
|
|
1025
1347
|
return;
|
|
1026
1348
|
}
|
|
1027
1349
|
cfg = parsed;
|
|
1028
1350
|
}
|
|
1029
|
-
const entry = pathToFileURL(
|
|
1351
|
+
const entry = pathToFileURL(join13(c.dist, "kilo.js")).href;
|
|
1030
1352
|
const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
|
|
1031
1353
|
cfg.plugin = [...plugins.filter((p) => !String(p).includes(MARKER)), entry];
|
|
1032
1354
|
writeJson(path, cfg);
|
|
@@ -1034,8 +1356,8 @@ var kilo = {
|
|
|
1034
1356
|
},
|
|
1035
1357
|
uninstall(c) {
|
|
1036
1358
|
const path = kiloConfigPath(c);
|
|
1037
|
-
if (!
|
|
1038
|
-
const cfg = parseJsonc(
|
|
1359
|
+
if (!existsSync8(path)) return;
|
|
1360
|
+
const cfg = parseJsonc(readFileSync15(path, "utf8"));
|
|
1039
1361
|
if (!cfg || !Array.isArray(cfg.plugin)) return;
|
|
1040
1362
|
cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
1041
1363
|
if (!cfg.plugin.length) delete cfg.plugin;
|
|
@@ -1045,15 +1367,15 @@ var kilo = {
|
|
|
1045
1367
|
};
|
|
1046
1368
|
var claudeCode = {
|
|
1047
1369
|
name: "claude-code",
|
|
1048
|
-
detect: (c) =>
|
|
1370
|
+
detect: (c) => onPath2("claude") || existsSync8(join13(c.home, ".claude")),
|
|
1049
1371
|
install(c) {
|
|
1050
|
-
const path =
|
|
1372
|
+
const path = join13(c.home, ".claude", "settings.json");
|
|
1051
1373
|
const settings = readJson(path);
|
|
1052
1374
|
settings.hooks = settings.hooks ?? {};
|
|
1053
1375
|
mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
|
|
1054
1376
|
writeJson(path, settings);
|
|
1055
1377
|
c.log?.(`claude-code: hooks merged into ${path}`);
|
|
1056
|
-
installSkill(c,
|
|
1378
|
+
installSkill(c, "claude-code", join13(c.home, ".claude", "skills"));
|
|
1057
1379
|
const mcp = c.claudeMcp ?? defaultClaudeMcp;
|
|
1058
1380
|
mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
|
|
1059
1381
|
if (mcp([
|
|
@@ -1064,19 +1386,19 @@ var claudeCode = {
|
|
|
1064
1386
|
"hindsight",
|
|
1065
1387
|
"--",
|
|
1066
1388
|
"node",
|
|
1067
|
-
|
|
1389
|
+
join13(c.dist, "mcp-server.js")
|
|
1068
1390
|
])) {
|
|
1069
1391
|
c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
|
|
1070
1392
|
} else {
|
|
1071
1393
|
c.log?.(
|
|
1072
1394
|
`claude-code: could not run \`claude mcp add\` \u2014 register the tools manually:
|
|
1073
|
-
claude mcp add --scope user hindsight -- node "${
|
|
1395
|
+
claude mcp add --scope user hindsight -- node "${join13(c.dist, "mcp-server.js")}"`
|
|
1074
1396
|
);
|
|
1075
1397
|
}
|
|
1076
1398
|
},
|
|
1077
1399
|
uninstall(c) {
|
|
1078
|
-
const path =
|
|
1079
|
-
if (
|
|
1400
|
+
const path = join13(c.home, ".claude", "settings.json");
|
|
1401
|
+
if (existsSync8(path)) {
|
|
1080
1402
|
const settings = readJson(path);
|
|
1081
1403
|
if (settings.hooks) {
|
|
1082
1404
|
stripHarnessHooks(settings.hooks, "claude-code");
|
|
@@ -1086,13 +1408,13 @@ var claudeCode = {
|
|
|
1086
1408
|
}
|
|
1087
1409
|
const mcp = c.claudeMcp ?? defaultClaudeMcp;
|
|
1088
1410
|
mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
|
|
1089
|
-
uninstallSkill(c,
|
|
1411
|
+
uninstallSkill(c, join13(c.home, ".claude", "skills"));
|
|
1090
1412
|
c.log?.("claude-code: hooks + MCP registration + skill removed");
|
|
1091
1413
|
}
|
|
1092
1414
|
};
|
|
1093
1415
|
function defaultClaudeMcp(args) {
|
|
1094
1416
|
try {
|
|
1095
|
-
|
|
1417
|
+
execFileSync6("claude", args, { stdio: "pipe" });
|
|
1096
1418
|
return true;
|
|
1097
1419
|
} catch {
|
|
1098
1420
|
return false;
|
|
@@ -1100,16 +1422,16 @@ function defaultClaudeMcp(args) {
|
|
|
1100
1422
|
}
|
|
1101
1423
|
var codex = {
|
|
1102
1424
|
name: "codex",
|
|
1103
|
-
detect: (c) =>
|
|
1425
|
+
detect: (c) => onPath2("codex") || existsSync8(join13(c.home, ".codex")),
|
|
1104
1426
|
install(c) {
|
|
1105
|
-
const hooksPath =
|
|
1427
|
+
const hooksPath = join13(c.home, ".codex", "hooks.json");
|
|
1106
1428
|
const cfg = readJson(hooksPath);
|
|
1107
1429
|
cfg.hooks = cfg.hooks ?? {};
|
|
1108
1430
|
mergeHarnessHooks(cfg.hooks, "codex", c.dist);
|
|
1109
1431
|
writeJson(hooksPath, cfg);
|
|
1110
1432
|
c.log?.(`codex: hooks merged into ${hooksPath}`);
|
|
1111
|
-
const tomlPath =
|
|
1112
|
-
let toml =
|
|
1433
|
+
const tomlPath = join13(c.home, ".codex", "config.toml");
|
|
1434
|
+
let toml = existsSync8(tomlPath) ? readFileSync15(tomlPath, "utf8") : "";
|
|
1113
1435
|
const additions = [];
|
|
1114
1436
|
if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
|
|
1115
1437
|
if (/^\[features\]/m.test(toml)) {
|
|
@@ -1124,33 +1446,33 @@ var codex = {
|
|
|
1124
1446
|
additions.push(
|
|
1125
1447
|
`[mcp_servers.hindsight]
|
|
1126
1448
|
command = "node"
|
|
1127
|
-
args = ["${
|
|
1449
|
+
args = ["${join13(c.dist, "mcp-server.js")}"]`
|
|
1128
1450
|
);
|
|
1129
1451
|
}
|
|
1130
1452
|
if (additions.length) {
|
|
1131
|
-
if (
|
|
1453
|
+
if (existsSync8(tomlPath) && !existsSync8(`${tomlPath}.hindsight-backup`)) {
|
|
1132
1454
|
copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
|
|
1133
1455
|
}
|
|
1134
|
-
mkdirSync3(
|
|
1456
|
+
mkdirSync3(dirname8(tomlPath), { recursive: true });
|
|
1135
1457
|
writeFileSync2(tomlPath, `${toml.replace(/\n*$/, "\n\n")}${additions.join("\n\n")}
|
|
1136
1458
|
`);
|
|
1137
1459
|
c.log?.(`codex: appended ${additions.length} section(s) to ${tomlPath}`);
|
|
1138
1460
|
}
|
|
1139
|
-
installSkill(c,
|
|
1461
|
+
installSkill(c, "codex", join13(c.home, ".agents", "skills"));
|
|
1140
1462
|
},
|
|
1141
1463
|
uninstall(c) {
|
|
1142
|
-
const hooksPath =
|
|
1143
|
-
if (
|
|
1464
|
+
const hooksPath = join13(c.home, ".codex", "hooks.json");
|
|
1465
|
+
if (existsSync8(hooksPath)) {
|
|
1144
1466
|
const cfg = readJson(hooksPath);
|
|
1145
1467
|
if (cfg.hooks) {
|
|
1146
1468
|
stripHarnessHooks(cfg.hooks, "codex");
|
|
1147
1469
|
writeJson(hooksPath, cfg);
|
|
1148
1470
|
}
|
|
1149
1471
|
}
|
|
1150
|
-
uninstallSkill(c,
|
|
1151
|
-
const tomlPath =
|
|
1152
|
-
if (
|
|
1153
|
-
const toml =
|
|
1472
|
+
uninstallSkill(c, join13(c.home, ".agents", "skills"));
|
|
1473
|
+
const tomlPath = join13(c.home, ".codex", "config.toml");
|
|
1474
|
+
if (existsSync8(tomlPath)) {
|
|
1475
|
+
const toml = readFileSync15(tomlPath, "utf8");
|
|
1154
1476
|
const cleaned = toml.replace(
|
|
1155
1477
|
/\n?\[mcp_servers\.hindsight\]\ncommand = "node"\nargs = \[[^\]]*\]\n?/g,
|
|
1156
1478
|
"\n"
|
|
@@ -1167,9 +1489,9 @@ var antigravity = {
|
|
|
1167
1489
|
// `agy` is the supported Antigravity CLI executable. Do not infer support from the
|
|
1168
1490
|
// legacy Gemini CLI's ~/.gemini state: both clients may leave files there, but only agy
|
|
1169
1491
|
// can consume this integration.
|
|
1170
|
-
detect: (c) =>
|
|
1492
|
+
detect: (c) => onPath2("agy"),
|
|
1171
1493
|
install(c) {
|
|
1172
|
-
const hooksPath =
|
|
1494
|
+
const hooksPath = join13(c.home, ".gemini", "config", "hooks.json");
|
|
1173
1495
|
const hooks = readJson(hooksPath);
|
|
1174
1496
|
for (const key of Object.keys(hooks)) {
|
|
1175
1497
|
if (key !== MARKER && key.includes(MARKER)) delete hooks[key];
|
|
@@ -1180,30 +1502,30 @@ var antigravity = {
|
|
|
1180
1502
|
setOrDelete(hooks, event, stripOurs(hooks[event]));
|
|
1181
1503
|
}
|
|
1182
1504
|
writeJson(hooksPath, hooks);
|
|
1183
|
-
const mcpPath =
|
|
1505
|
+
const mcpPath = join13(c.home, ".gemini", "config", "mcp_config.json");
|
|
1184
1506
|
const mcp = readJson(mcpPath);
|
|
1185
1507
|
mcp.mcpServers = {
|
|
1186
1508
|
...mcp.mcpServers ?? {},
|
|
1187
1509
|
hindsight: {
|
|
1188
1510
|
command: "node",
|
|
1189
|
-
args: [
|
|
1511
|
+
args: [join13(c.dist, "mcp-server.js")],
|
|
1190
1512
|
env: { HINDSIGHT_MCP_HARNESS: "antigravity-cli" }
|
|
1191
1513
|
}
|
|
1192
1514
|
};
|
|
1193
1515
|
writeJson(mcpPath, mcp);
|
|
1194
|
-
const settingsPath =
|
|
1516
|
+
const settingsPath = join13(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
1195
1517
|
const settings = readJson(settingsPath);
|
|
1196
1518
|
if (!settings.statusLine) {
|
|
1197
1519
|
settings.statusLine = {
|
|
1198
1520
|
type: "command",
|
|
1199
|
-
command: `node "${
|
|
1521
|
+
command: `node "${join13(c.dist, "antigravity-statusline.js")}"`
|
|
1200
1522
|
};
|
|
1201
1523
|
writeJson(settingsPath, settings);
|
|
1202
1524
|
c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
|
|
1203
1525
|
} else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
|
|
1204
1526
|
settings.statusLine = {
|
|
1205
1527
|
type: "command",
|
|
1206
|
-
command: `node "${
|
|
1528
|
+
command: `node "${join13(c.dist, "antigravity-statusline.js")}"`
|
|
1207
1529
|
};
|
|
1208
1530
|
writeJson(settingsPath, settings);
|
|
1209
1531
|
} else {
|
|
@@ -1212,11 +1534,11 @@ var antigravity = {
|
|
|
1212
1534
|
);
|
|
1213
1535
|
}
|
|
1214
1536
|
c.log?.(`antigravity-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
|
|
1215
|
-
installSkill(c,
|
|
1537
|
+
installSkill(c, "antigravity-cli", join13(c.home, ".gemini", "config", "skills"));
|
|
1216
1538
|
},
|
|
1217
1539
|
uninstall(c) {
|
|
1218
|
-
const hooksPath =
|
|
1219
|
-
if (
|
|
1540
|
+
const hooksPath = join13(c.home, ".gemini", "config", "hooks.json");
|
|
1541
|
+
if (existsSync8(hooksPath)) {
|
|
1220
1542
|
const hooks = readJson(hooksPath);
|
|
1221
1543
|
if (hooks[MARKER]) {
|
|
1222
1544
|
stripHarnessHooks(hooks[MARKER], "antigravity-cli");
|
|
@@ -1227,29 +1549,29 @@ var antigravity = {
|
|
|
1227
1549
|
}
|
|
1228
1550
|
writeJson(hooksPath, hooks);
|
|
1229
1551
|
}
|
|
1230
|
-
const mcpPath =
|
|
1231
|
-
if (
|
|
1552
|
+
const mcpPath = join13(c.home, ".gemini", "config", "mcp_config.json");
|
|
1553
|
+
if (existsSync8(mcpPath)) {
|
|
1232
1554
|
const mcp = readJson(mcpPath);
|
|
1233
1555
|
if (mcp.mcpServers?.hindsight) {
|
|
1234
1556
|
delete mcp.mcpServers.hindsight;
|
|
1235
1557
|
writeJson(mcpPath, mcp);
|
|
1236
1558
|
}
|
|
1237
1559
|
}
|
|
1238
|
-
const settingsPath =
|
|
1239
|
-
if (
|
|
1560
|
+
const settingsPath = join13(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
1561
|
+
if (existsSync8(settingsPath)) {
|
|
1240
1562
|
const settings = readJson(settingsPath);
|
|
1241
1563
|
if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
|
|
1242
1564
|
delete settings.statusLine;
|
|
1243
1565
|
writeJson(settingsPath, settings);
|
|
1244
1566
|
}
|
|
1245
1567
|
}
|
|
1246
|
-
uninstallSkill(c,
|
|
1568
|
+
uninstallSkill(c, join13(c.home, ".gemini", "config", "skills"));
|
|
1247
1569
|
c.log?.("antigravity-cli: hooks + MCP entry + status line + skill removed");
|
|
1248
1570
|
}
|
|
1249
1571
|
};
|
|
1250
1572
|
function pathNodeHasSqlite() {
|
|
1251
1573
|
try {
|
|
1252
|
-
|
|
1574
|
+
execFileSync6("node", ["-e", "require('node:sqlite')"], { stdio: "pipe", timeout: 1e4 });
|
|
1253
1575
|
return true;
|
|
1254
1576
|
} catch {
|
|
1255
1577
|
return false;
|
|
@@ -1257,14 +1579,209 @@ function pathNodeHasSqlite() {
|
|
|
1257
1579
|
}
|
|
1258
1580
|
function pathNodeVersion() {
|
|
1259
1581
|
try {
|
|
1260
|
-
return
|
|
1582
|
+
return execFileSync6("node", ["-v"], { encoding: "utf8", stdio: "pipe" }).trim();
|
|
1261
1583
|
} catch {
|
|
1262
1584
|
return "not found";
|
|
1263
1585
|
}
|
|
1264
1586
|
}
|
|
1587
|
+
function runtimeDir(home) {
|
|
1588
|
+
return join13(home, ".hindsight", "coding-agents");
|
|
1589
|
+
}
|
|
1590
|
+
function stageRuntime(c) {
|
|
1591
|
+
const target = runtimeDir(c.home);
|
|
1592
|
+
const same = (a, b) => {
|
|
1593
|
+
try {
|
|
1594
|
+
return realpathSync(a) === realpathSync(b);
|
|
1595
|
+
} catch {
|
|
1596
|
+
return a === b;
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
if (same(c.pkgRoot, target)) return c;
|
|
1600
|
+
if (!existsSync8(join13(c.dist, "installer.js"))) return c;
|
|
1601
|
+
try {
|
|
1602
|
+
rmSync(join13(target, "dist"), { recursive: true, force: true });
|
|
1603
|
+
mkdirSync3(target, { recursive: true });
|
|
1604
|
+
cpSync2(c.dist, join13(target, "dist"), { recursive: true });
|
|
1605
|
+
const skill = join13(c.pkgRoot, "skill");
|
|
1606
|
+
if (existsSync8(skill)) cpSync2(skill, join13(target, "skill"), { recursive: true });
|
|
1607
|
+
const pkgJson = join13(c.pkgRoot, "package.json");
|
|
1608
|
+
if (existsSync8(pkgJson)) copyFileSync(pkgJson, join13(target, "package.json"));
|
|
1609
|
+
c.log?.(`runtime staged at ${target}`);
|
|
1610
|
+
return { ...c, pkgRoot: target, dist: join13(target, "dist") };
|
|
1611
|
+
} catch (error) {
|
|
1612
|
+
c.log?.(`could not stage the runtime at ${target}: ${String(error)}`);
|
|
1613
|
+
return c;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
var SERVER_MODES = ["cloud", "self-hosted", "daemon"];
|
|
1617
|
+
function flagValue(args, name) {
|
|
1618
|
+
const inline = args.find((a) => a.startsWith(`--${name}=`));
|
|
1619
|
+
if (inline) return inline.slice(name.length + 3);
|
|
1620
|
+
const i = args.indexOf(`--${name}`);
|
|
1621
|
+
return i >= 0 ? args[i + 1] : void 0;
|
|
1622
|
+
}
|
|
1623
|
+
function flagValueArgs(args, names) {
|
|
1624
|
+
const taken = /* @__PURE__ */ new Set();
|
|
1625
|
+
for (const name of names) {
|
|
1626
|
+
const i = args.indexOf(`--${name}`);
|
|
1627
|
+
if (i >= 0 && args[i + 1] && !args[i + 1].startsWith("--")) taken.add(args[i + 1]);
|
|
1628
|
+
}
|
|
1629
|
+
return taken;
|
|
1630
|
+
}
|
|
1631
|
+
var CONFIG_RELATIVE = [".hindsight", "coding-agent.json"];
|
|
1632
|
+
var SERVER_CHOICES = [
|
|
1633
|
+
{ mode: "cloud", label: "Hindsight Cloud", hint: "hosted, needs an API token" },
|
|
1634
|
+
{ mode: "self-hosted", label: "Self-hosted server", hint: "a Hindsight server you already run" },
|
|
1635
|
+
{
|
|
1636
|
+
mode: "daemon",
|
|
1637
|
+
label: "Local daemon (on-device)",
|
|
1638
|
+
hint: "runs hindsight-embed here; no account, needs uv + an LLM key"
|
|
1639
|
+
}
|
|
1640
|
+
];
|
|
1641
|
+
function promptServerMode(c) {
|
|
1642
|
+
if (c.selectPrompt) {
|
|
1643
|
+
const picked = c.selectPrompt(
|
|
1644
|
+
"Where should memory live?",
|
|
1645
|
+
SERVER_CHOICES.map(({ label, hint }) => ({ label, hint })),
|
|
1646
|
+
0
|
|
1647
|
+
);
|
|
1648
|
+
if (picked === null) {
|
|
1649
|
+
c.log?.("no server chosen \u2014 leaving the server config unchanged");
|
|
1650
|
+
return void 0;
|
|
1651
|
+
}
|
|
1652
|
+
if (picked !== void 0) return SERVER_CHOICES[picked].mode;
|
|
1653
|
+
}
|
|
1654
|
+
c.log?.(
|
|
1655
|
+
`
|
|
1656
|
+
Where should memory live?
|
|
1657
|
+
` + SERVER_CHOICES.map((o, i) => ` ${i + 1}) ${o.label.padEnd(28)}\u2014 ${o.hint}`).join("\n") + `
|
|
1658
|
+
`
|
|
1659
|
+
);
|
|
1660
|
+
const answer = readLineSync(c, "Choose [1-3] (default 1): ").trim();
|
|
1661
|
+
if (answer === "") return "cloud";
|
|
1662
|
+
const digit = Number.parseInt(answer, 10);
|
|
1663
|
+
if (digit >= 1 && digit <= SERVER_CHOICES.length) return SERVER_CHOICES[digit - 1].mode;
|
|
1664
|
+
c.log?.(`unrecognised choice "${answer}" \u2014 leaving the server config unchanged`);
|
|
1665
|
+
return void 0;
|
|
1666
|
+
}
|
|
1667
|
+
function readLineSync(c, prompt) {
|
|
1668
|
+
process.stdout.write((c.promptStyle ?? ((s) => s))(prompt));
|
|
1669
|
+
const buf = Buffer.alloc(1024);
|
|
1670
|
+
for (; ; ) {
|
|
1671
|
+
try {
|
|
1672
|
+
const n = readSync3(0, buf, 0, buf.length, null);
|
|
1673
|
+
return buf.subarray(0, n).toString("utf8");
|
|
1674
|
+
} catch (e) {
|
|
1675
|
+
if (e.code !== "EAGAIN") {
|
|
1676
|
+
return "";
|
|
1677
|
+
}
|
|
1678
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
function configureServer(c, args, installing) {
|
|
1683
|
+
const explicit = flagValue(args, "server");
|
|
1684
|
+
if (explicit && !SERVER_MODES.includes(explicit)) {
|
|
1685
|
+
c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
|
|
1686
|
+
return false;
|
|
1687
|
+
}
|
|
1688
|
+
const configPath = process.env.HINDSIGHT_CONFIG || join13(c.home, ...CONFIG_RELATIVE);
|
|
1689
|
+
const existing = readJson(configPath);
|
|
1690
|
+
const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
|
|
1691
|
+
let mode = explicit;
|
|
1692
|
+
if (!mode) {
|
|
1693
|
+
if (alreadyConfigured) return true;
|
|
1694
|
+
const legacy = (c.readLegacy ?? readLegacyEndpoint)(c.home, installing);
|
|
1695
|
+
if (legacy) {
|
|
1696
|
+
const carried = { ...existing, serverMode: legacy.serverMode };
|
|
1697
|
+
if (legacy.apiUrl) carried.apiUrl = legacy.apiUrl;
|
|
1698
|
+
if (legacy.apiToken) carried.apiToken = legacy.apiToken;
|
|
1699
|
+
if (legacy.apiPort) carried.apiPort = legacy.apiPort;
|
|
1700
|
+
writeJson(configPath, carried);
|
|
1701
|
+
c.log?.(
|
|
1702
|
+
`server: ${legacy.serverMode}${legacy.apiUrl ? ` (${legacy.apiUrl})` : ""} \u2014 carried over from the ${legacy.harness} plugin (${legacy.source})
|
|
1703
|
+
Only the endpoint moves; conversations do not. To bring this repo's history
|
|
1704
|
+
across, re-run here with --import-conversations.`
|
|
1705
|
+
);
|
|
1706
|
+
if (legacy.serverMode === "daemon") reportDaemonPrereqs(c);
|
|
1707
|
+
return true;
|
|
1708
|
+
}
|
|
1709
|
+
if (!c.interactive) {
|
|
1710
|
+
c.log?.(
|
|
1711
|
+
`
|
|
1712
|
+
server: defaulting to Hindsight Cloud. Re-run with --server self-hosted|daemon to change,
|
|
1713
|
+
or edit ${configPath}.`
|
|
1714
|
+
);
|
|
1715
|
+
return true;
|
|
1716
|
+
}
|
|
1717
|
+
mode = promptServerMode(c);
|
|
1718
|
+
if (!mode) return true;
|
|
1719
|
+
}
|
|
1720
|
+
const next = { ...existing, serverMode: mode };
|
|
1721
|
+
if (mode === "cloud") {
|
|
1722
|
+
delete next.apiUrl;
|
|
1723
|
+
const token = flagValue(args, "api-token") ?? (c.interactive ? askToken(c) : void 0);
|
|
1724
|
+
if (!token) {
|
|
1725
|
+
c.log?.(
|
|
1726
|
+
`\u274C Hindsight Cloud needs an API token \u2014 pass --api-token <token> (or set apiToken in ${configPath}).`
|
|
1727
|
+
);
|
|
1728
|
+
return false;
|
|
1729
|
+
}
|
|
1730
|
+
next.apiToken = token;
|
|
1731
|
+
} else if (mode === "self-hosted") {
|
|
1732
|
+
const url = flagValue(args, "api-url") ?? (c.interactive ? readLineSync(c, "Server URL (e.g. http://localhost:8888): ").trim() : void 0);
|
|
1733
|
+
if (!url) {
|
|
1734
|
+
c.log?.(
|
|
1735
|
+
`\u274C self-hosted mode needs a server URL \u2014 pass --api-url <url> (or set apiUrl in ${configPath}).`
|
|
1736
|
+
);
|
|
1737
|
+
return false;
|
|
1738
|
+
}
|
|
1739
|
+
next.apiUrl = url;
|
|
1740
|
+
const token = flagValue(args, "api-token");
|
|
1741
|
+
if (token) next.apiToken = token;
|
|
1742
|
+
} else {
|
|
1743
|
+
delete next.apiUrl;
|
|
1744
|
+
reportDaemonPrereqs(c);
|
|
1745
|
+
}
|
|
1746
|
+
writeJson(configPath, next);
|
|
1747
|
+
c.log?.(`server: ${mode} (${configPath})`);
|
|
1748
|
+
return true;
|
|
1749
|
+
}
|
|
1750
|
+
function askToken(c) {
|
|
1751
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
1752
|
+
const token = readLineSync(c, "API token (required for Hindsight Cloud): ").trim();
|
|
1753
|
+
if (token) return token;
|
|
1754
|
+
c.log?.(" a token is required \u2014 find yours in the Hindsight Cloud dashboard");
|
|
1755
|
+
}
|
|
1756
|
+
return void 0;
|
|
1757
|
+
}
|
|
1758
|
+
function reportDaemonPrereqs(c) {
|
|
1759
|
+
if (!(c.hasUvx ?? hasUvx)()) {
|
|
1760
|
+
c.log?.(
|
|
1761
|
+
`\u26A0\uFE0F \`uv\` is not on PATH. The daemon is fetched and run with it, so memory stays inert
|
|
1762
|
+
until you install it: https://docs.astral.sh/uv/`
|
|
1763
|
+
);
|
|
1764
|
+
}
|
|
1765
|
+
if (!(c.hasRust ?? hasRustToolchain)()) {
|
|
1766
|
+
c.log?.(
|
|
1767
|
+
`\u26A0\uFE0F macOS needs a current Rust toolchain to build the daemon's dependencies (litellm
|
|
1768
|
+
publishes no macOS wheel). Install from https://rustup.rs, then
|
|
1769
|
+
\`rustup default stable && rustup update\` \u2014 an OUT-OF-DATE toolchain fails too.`
|
|
1770
|
+
);
|
|
1771
|
+
}
|
|
1772
|
+
const llm = (c.detectLlm ?? detectLlm)();
|
|
1773
|
+
if (llm) {
|
|
1774
|
+
c.log?.(` local extraction will use ${llm.provider} (from ${llm.source})`);
|
|
1775
|
+
} else {
|
|
1776
|
+
c.log?.(
|
|
1777
|
+
`\u26A0\uFE0F No LLM available for local fact extraction. Set OPENAI_API_KEY, ANTHROPIC_API_KEY or
|
|
1778
|
+
GEMINI_API_KEY (or install the Claude Code CLI, which needs no key).`
|
|
1779
|
+
);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1265
1782
|
var devin = {
|
|
1266
1783
|
name: "devin-cli",
|
|
1267
|
-
detect: (c) =>
|
|
1784
|
+
detect: (c) => onPath2("devin") || existsSync8(join13(c.home, ".config", "devin")),
|
|
1268
1785
|
// Devin is the ONLY harness whose hooks never hand over a transcript: they carry a session id and
|
|
1269
1786
|
// nothing else, so retain can only work by reading the CLI's own sessions.db. That makes SQLite
|
|
1270
1787
|
// support a hard prerequisite here — and one worth checking now, because the alternative is an
|
|
@@ -1277,18 +1794,18 @@ var devin = {
|
|
|
1277
1794
|
Upgrade to Node 22.5 or newer (24 LTS recommended) and re-run this command.`;
|
|
1278
1795
|
},
|
|
1279
1796
|
install(c) {
|
|
1280
|
-
const configPath =
|
|
1797
|
+
const configPath = join13(c.home, ".config", "devin", "config.json");
|
|
1281
1798
|
const config = readJson(configPath);
|
|
1282
1799
|
config.hooks = config.hooks ?? {};
|
|
1283
1800
|
mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
|
|
1284
1801
|
writeJson(configPath, config);
|
|
1285
|
-
const mcpPath =
|
|
1802
|
+
const mcpPath = join13(c.home, ".config", "devin", "mcp_config.json");
|
|
1286
1803
|
const mcp = readJson(mcpPath);
|
|
1287
1804
|
mcp.mcpServers = {
|
|
1288
1805
|
...mcp.mcpServers ?? {},
|
|
1289
1806
|
hindsight: {
|
|
1290
1807
|
command: "node",
|
|
1291
|
-
args: [
|
|
1808
|
+
args: [join13(c.dist, "mcp-server.js")],
|
|
1292
1809
|
env: { HINDSIGHT_MCP_HARNESS: "devin-cli" }
|
|
1293
1810
|
}
|
|
1294
1811
|
};
|
|
@@ -1296,8 +1813,8 @@ var devin = {
|
|
|
1296
1813
|
c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
|
|
1297
1814
|
},
|
|
1298
1815
|
uninstall(c) {
|
|
1299
|
-
const configPath =
|
|
1300
|
-
if (
|
|
1816
|
+
const configPath = join13(c.home, ".config", "devin", "config.json");
|
|
1817
|
+
if (existsSync8(configPath)) {
|
|
1301
1818
|
const config = readJson(configPath);
|
|
1302
1819
|
if (config.hooks) {
|
|
1303
1820
|
stripHarnessHooks(config.hooks, "devin-cli");
|
|
@@ -1305,8 +1822,8 @@ var devin = {
|
|
|
1305
1822
|
writeJson(configPath, config);
|
|
1306
1823
|
}
|
|
1307
1824
|
}
|
|
1308
|
-
const mcpPath =
|
|
1309
|
-
if (
|
|
1825
|
+
const mcpPath = join13(c.home, ".config", "devin", "mcp_config.json");
|
|
1826
|
+
if (existsSync8(mcpPath)) {
|
|
1310
1827
|
const mcp = readJson(mcpPath);
|
|
1311
1828
|
if (mcp.mcpServers?.hindsight) {
|
|
1312
1829
|
delete mcp.mcpServers.hindsight;
|
|
@@ -1318,26 +1835,26 @@ var devin = {
|
|
|
1318
1835
|
};
|
|
1319
1836
|
var cursor = {
|
|
1320
1837
|
name: "cursor-cli",
|
|
1321
|
-
detect: (c) =>
|
|
1838
|
+
detect: (c) => onPath2("cursor-agent") || existsSync8(join13(c.home, ".cursor")),
|
|
1322
1839
|
install(c) {
|
|
1323
|
-
const hooksPath =
|
|
1840
|
+
const hooksPath = join13(c.home, ".cursor", "hooks.json");
|
|
1324
1841
|
const cfg = readJson(hooksPath);
|
|
1325
1842
|
cfg.hooks = cfg.hooks ?? {};
|
|
1326
1843
|
mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
|
|
1327
1844
|
writeJson(hooksPath, cfg);
|
|
1328
|
-
const mcpPath =
|
|
1845
|
+
const mcpPath = join13(c.home, ".cursor", "mcp.json");
|
|
1329
1846
|
const mcp = readJson(mcpPath);
|
|
1330
1847
|
mcp.mcpServers = {
|
|
1331
1848
|
...mcp.mcpServers ?? {},
|
|
1332
|
-
hindsight: { command: "node", args: [
|
|
1849
|
+
hindsight: { command: "node", args: [join13(c.dist, "mcp-server.js")] }
|
|
1333
1850
|
};
|
|
1334
1851
|
writeJson(mcpPath, mcp);
|
|
1335
1852
|
c.log?.(`cursor-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
|
|
1336
|
-
installSkill(c,
|
|
1853
|
+
installSkill(c, "cursor-cli", join13(c.home, ".cursor", "skills"));
|
|
1337
1854
|
},
|
|
1338
1855
|
uninstall(c) {
|
|
1339
|
-
const hooksPath =
|
|
1340
|
-
if (
|
|
1856
|
+
const hooksPath = join13(c.home, ".cursor", "hooks.json");
|
|
1857
|
+
if (existsSync8(hooksPath)) {
|
|
1341
1858
|
const cfg = readJson(hooksPath);
|
|
1342
1859
|
if (cfg.hooks) {
|
|
1343
1860
|
stripHarnessHooks(cfg.hooks, "cursor-cli");
|
|
@@ -1345,49 +1862,49 @@ var cursor = {
|
|
|
1345
1862
|
writeJson(hooksPath, cfg);
|
|
1346
1863
|
}
|
|
1347
1864
|
}
|
|
1348
|
-
const mcpPath =
|
|
1349
|
-
if (
|
|
1865
|
+
const mcpPath = join13(c.home, ".cursor", "mcp.json");
|
|
1866
|
+
if (existsSync8(mcpPath)) {
|
|
1350
1867
|
const mcp = readJson(mcpPath);
|
|
1351
1868
|
if (mcp.mcpServers?.hindsight) {
|
|
1352
1869
|
delete mcp.mcpServers.hindsight;
|
|
1353
1870
|
writeJson(mcpPath, mcp);
|
|
1354
1871
|
}
|
|
1355
1872
|
}
|
|
1356
|
-
uninstallSkill(c,
|
|
1873
|
+
uninstallSkill(c, join13(c.home, ".cursor", "skills"));
|
|
1357
1874
|
c.log?.("cursor-cli: hooks + MCP entry + skill removed");
|
|
1358
1875
|
}
|
|
1359
1876
|
};
|
|
1360
1877
|
var copilot = {
|
|
1361
1878
|
name: "copilot-cli",
|
|
1362
|
-
detect: (c) =>
|
|
1879
|
+
detect: (c) => onPath2("copilot") || existsSync8(join13(c.home, ".copilot")),
|
|
1363
1880
|
install(c) {
|
|
1364
|
-
const hooksPath =
|
|
1881
|
+
const hooksPath = join13(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
|
|
1365
1882
|
const hooks = {};
|
|
1366
1883
|
mergeHarnessHooks(hooks, "copilot-cli", c.dist);
|
|
1367
1884
|
writeJson(hooksPath, { version: 1, hooks });
|
|
1368
|
-
const mcpPath =
|
|
1885
|
+
const mcpPath = join13(c.home, ".copilot", "mcp-config.json");
|
|
1369
1886
|
const mcp = readJson(mcpPath);
|
|
1370
1887
|
mcp.mcpServers = {
|
|
1371
1888
|
...mcp.mcpServers ?? {},
|
|
1372
|
-
hindsight: { command: "node", args: [
|
|
1889
|
+
hindsight: { command: "node", args: [join13(c.dist, "mcp-server.js")] }
|
|
1373
1890
|
};
|
|
1374
1891
|
writeJson(mcpPath, mcp);
|
|
1375
|
-
installSkill(c,
|
|
1892
|
+
installSkill(c, "copilot-cli", join13(c.home, ".copilot", "skills"));
|
|
1376
1893
|
c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
|
|
1377
1894
|
},
|
|
1378
1895
|
uninstall(c) {
|
|
1379
|
-
rmSync(
|
|
1896
|
+
rmSync(join13(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
|
|
1380
1897
|
force: true
|
|
1381
1898
|
});
|
|
1382
|
-
const mcpPath =
|
|
1383
|
-
if (
|
|
1899
|
+
const mcpPath = join13(c.home, ".copilot", "mcp-config.json");
|
|
1900
|
+
if (existsSync8(mcpPath)) {
|
|
1384
1901
|
const mcp = readJson(mcpPath);
|
|
1385
1902
|
if (mcp.mcpServers?.hindsight) {
|
|
1386
1903
|
delete mcp.mcpServers.hindsight;
|
|
1387
1904
|
writeJson(mcpPath, mcp);
|
|
1388
1905
|
}
|
|
1389
1906
|
}
|
|
1390
|
-
uninstallSkill(c,
|
|
1907
|
+
uninstallSkill(c, join13(c.home, ".copilot", "skills"));
|
|
1391
1908
|
c.log?.("copilot-cli: hooks + MCP entry + skill removed");
|
|
1392
1909
|
}
|
|
1393
1910
|
};
|
|
@@ -1396,12 +1913,12 @@ var GROK_MARKER_END = "# HINDSIGHT_CODING_AGENTS_GROK_END";
|
|
|
1396
1913
|
var GROK_BLOCK_RE = new RegExp(`\\n?${GROK_MARKER_START}[\\s\\S]*?${GROK_MARKER_END}\\n?`);
|
|
1397
1914
|
var grok = {
|
|
1398
1915
|
name: "grok-build",
|
|
1399
|
-
detect: (c) =>
|
|
1916
|
+
detect: (c) => onPath2("grok") || existsSync8(join13(c.home, ".grok")),
|
|
1400
1917
|
install(c) {
|
|
1401
|
-
const path =
|
|
1402
|
-
const existing =
|
|
1918
|
+
const path = join13(c.home, ".grok", "config.toml");
|
|
1919
|
+
const existing = existsSync8(path) ? readFileSync15(path, "utf8") : "";
|
|
1403
1920
|
const withoutOurs = existing.replace(GROK_BLOCK_RE, "\n");
|
|
1404
|
-
const command = (entry) => JSON.stringify(`node "${
|
|
1921
|
+
const command = (entry) => JSON.stringify(`node "${join13(c.dist, entry)}"`);
|
|
1405
1922
|
const tomlString = (value) => JSON.stringify(value);
|
|
1406
1923
|
const block = `
|
|
1407
1924
|
${GROK_MARKER_START}
|
|
@@ -1425,24 +1942,24 @@ ${GROK_MARKER_START}
|
|
|
1425
1942
|
|
|
1426
1943
|
[mcp_servers.hindsight]
|
|
1427
1944
|
command = "node"
|
|
1428
|
-
args = [${tomlString(
|
|
1945
|
+
args = [${tomlString(join13(c.dist, "mcp-server.js"))}]
|
|
1429
1946
|
${GROK_MARKER_END}
|
|
1430
1947
|
`;
|
|
1431
|
-
if (
|
|
1948
|
+
if (existsSync8(path) && !existsSync8(`${path}.hindsight-backup`))
|
|
1432
1949
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
1433
|
-
mkdirSync3(
|
|
1950
|
+
mkdirSync3(dirname8(path), { recursive: true });
|
|
1434
1951
|
writeFileSync2(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
|
|
1435
|
-
installSkill(c,
|
|
1952
|
+
installSkill(c, "grok-build", join13(c.home, ".grok", "skills"));
|
|
1436
1953
|
c.log?.(`grok-build: native hooks + MCP installed in ${path}`);
|
|
1437
1954
|
},
|
|
1438
1955
|
uninstall(c) {
|
|
1439
|
-
const path =
|
|
1440
|
-
if (
|
|
1441
|
-
const existing =
|
|
1956
|
+
const path = join13(c.home, ".grok", "config.toml");
|
|
1957
|
+
if (existsSync8(path)) {
|
|
1958
|
+
const existing = readFileSync15(path, "utf8");
|
|
1442
1959
|
const cleaned = existing.replace(GROK_BLOCK_RE, "\n");
|
|
1443
1960
|
if (cleaned !== existing) writeFileSync2(path, cleaned);
|
|
1444
1961
|
}
|
|
1445
|
-
uninstallSkill(c,
|
|
1962
|
+
uninstallSkill(c, join13(c.home, ".grok", "skills"));
|
|
1446
1963
|
c.log?.("grok-build: native hooks + MCP + skill removed");
|
|
1447
1964
|
}
|
|
1448
1965
|
};
|
|
@@ -1450,17 +1967,17 @@ var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
|
|
|
1450
1967
|
var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
|
|
1451
1968
|
var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
1452
1969
|
function removeLegacyClineHooks(c) {
|
|
1453
|
-
const hooksDir =
|
|
1970
|
+
const hooksDir = join13(c.home, "Documents", "Cline", "Hooks");
|
|
1454
1971
|
for (const event of CLINE_OLD_HOOK_EVENTS) {
|
|
1455
|
-
const path =
|
|
1456
|
-
if (
|
|
1972
|
+
const path = join13(hooksDir, event);
|
|
1973
|
+
if (existsSync8(path) && readFileSync15(path, "utf8").includes(CLINE_HOOK_MARKER)) {
|
|
1457
1974
|
rmSync(path, { force: true });
|
|
1458
1975
|
}
|
|
1459
1976
|
}
|
|
1460
1977
|
}
|
|
1461
1978
|
var cline = {
|
|
1462
1979
|
name: "cline-cli",
|
|
1463
|
-
detect: (c) =>
|
|
1980
|
+
detect: (c) => onPath2("cline") || existsSync8(join13(c.home, ".cline")),
|
|
1464
1981
|
install(c) {
|
|
1465
1982
|
removeLegacyClineHooks(c);
|
|
1466
1983
|
const installed = (c.clinePlugin ?? runClinePlugin)([
|
|
@@ -1469,18 +1986,18 @@ var cline = {
|
|
|
1469
1986
|
"--force",
|
|
1470
1987
|
c.pkgRoot
|
|
1471
1988
|
]);
|
|
1472
|
-
const mcpPath =
|
|
1989
|
+
const mcpPath = join13(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
1473
1990
|
const mcp = readJson(mcpPath);
|
|
1474
1991
|
mcp.mcpServers = {
|
|
1475
1992
|
...mcp.mcpServers ?? {},
|
|
1476
1993
|
hindsight: {
|
|
1477
1994
|
command: "node",
|
|
1478
|
-
args: [
|
|
1995
|
+
args: [join13(c.dist, "mcp-server.js")],
|
|
1479
1996
|
env: { HINDSIGHT_MCP_HARNESS: "cline-cli" }
|
|
1480
1997
|
}
|
|
1481
1998
|
};
|
|
1482
1999
|
writeJson(mcpPath, mcp);
|
|
1483
|
-
installSkill(c,
|
|
2000
|
+
installSkill(c, "cline-cli", join13(c.home, ".cline", "data", "settings", "skills"));
|
|
1484
2001
|
c.log?.(
|
|
1485
2002
|
installed ? "cline-cli: native plugin + MCP + skill installed" : `cline-cli: MCP + skill installed; run: cline plugin install --force "${c.pkgRoot}"`
|
|
1486
2003
|
);
|
|
@@ -1488,15 +2005,15 @@ var cline = {
|
|
|
1488
2005
|
uninstall(c) {
|
|
1489
2006
|
removeLegacyClineHooks(c);
|
|
1490
2007
|
(c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
|
|
1491
|
-
const mcpPath =
|
|
1492
|
-
if (
|
|
2008
|
+
const mcpPath = join13(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
2009
|
+
if (existsSync8(mcpPath)) {
|
|
1493
2010
|
const mcp = readJson(mcpPath);
|
|
1494
2011
|
if (mcp.mcpServers?.hindsight) {
|
|
1495
2012
|
delete mcp.mcpServers.hindsight;
|
|
1496
2013
|
writeJson(mcpPath, mcp);
|
|
1497
2014
|
}
|
|
1498
2015
|
}
|
|
1499
|
-
uninstallSkill(c,
|
|
2016
|
+
uninstallSkill(c, join13(c.home, ".cline", "data", "settings", "skills"));
|
|
1500
2017
|
c.log?.("cline-cli: native plugin + MCP + skill removed");
|
|
1501
2018
|
}
|
|
1502
2019
|
};
|
|
@@ -1530,35 +2047,35 @@ function importConversations(harness, ctx) {
|
|
|
1530
2047
|
return;
|
|
1531
2048
|
}
|
|
1532
2049
|
const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
|
|
1533
|
-
const file =
|
|
2050
|
+
const file = join13(mkdtempSync(join13(tmpdir3(), "hindsight-import-")), "conversations.json");
|
|
1534
2051
|
writeFileSync2(file, JSON.stringify(found.sessions));
|
|
1535
2052
|
ctx.log?.(
|
|
1536
2053
|
`${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
|
|
1537
2054
|
);
|
|
1538
2055
|
try {
|
|
1539
|
-
|
|
2056
|
+
execFileSync6("node", [join13(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
|
|
1540
2057
|
stdio: "inherit"
|
|
1541
2058
|
});
|
|
1542
2059
|
} catch {
|
|
1543
2060
|
ctx.log?.(`${harness}: conversation import did not finish \u2014 re-run it any time with:`);
|
|
1544
|
-
ctx.log?.(` node "${
|
|
2061
|
+
ctx.log?.(` node "${join13(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
|
|
1545
2062
|
}
|
|
1546
2063
|
}
|
|
1547
|
-
function run(argv,
|
|
2064
|
+
function run(argv, ctxIn) {
|
|
2065
|
+
let ctx = ctxIn;
|
|
1548
2066
|
const [command, ...rawArgs] = argv;
|
|
1549
2067
|
const importHistory = rawArgs.includes("--import-conversations");
|
|
1550
|
-
const
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
"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 @vectorize-io/hindsight-coding-agents\n hindsight-coding-agents install all"
|
|
1554
|
-
);
|
|
1555
|
-
return 1;
|
|
1556
|
-
}
|
|
2068
|
+
const valueArgs = flagValueArgs(rawArgs, ["server", "api-url", "api-token"]);
|
|
2069
|
+
const names = rawArgs.filter((a) => !a.startsWith("--") && !valueArgs.has(a));
|
|
2070
|
+
if (command === "install") ctx = stageRuntime(ctx);
|
|
1557
2071
|
if (command !== "install" && command !== "uninstall") {
|
|
1558
2072
|
ctx.log?.(
|
|
1559
|
-
`usage: hindsight-coding-agents <install|uninstall> <all|harness...>
|
|
2073
|
+
`usage: hindsight-coding-agents <install|uninstall> <all|harness...>
|
|
2074
|
+
[--server cloud|self-hosted|daemon] [--api-url <url>] [--api-token <token>]
|
|
2075
|
+
[--import-conversations]
|
|
1560
2076
|
all every agent detected on this machine
|
|
1561
|
-
harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)
|
|
2077
|
+
harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)
|
|
2078
|
+
agents/CI: without a TTY nothing ever prompts \u2014 pass --server (and --api-url/--api-token) to choose`
|
|
1562
2079
|
);
|
|
1563
2080
|
return command ? 1 : 0;
|
|
1564
2081
|
}
|
|
@@ -1591,6 +2108,12 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
|
|
|
1591
2108
|
);
|
|
1592
2109
|
return 1;
|
|
1593
2110
|
}
|
|
2111
|
+
if (command === "install" && !configureServer(
|
|
2112
|
+
ctx,
|
|
2113
|
+
rawArgs,
|
|
2114
|
+
targets.map((t) => t.name)
|
|
2115
|
+
))
|
|
2116
|
+
return 1;
|
|
1594
2117
|
const blocked = /* @__PURE__ */ new Set();
|
|
1595
2118
|
if (command === "install") {
|
|
1596
2119
|
for (const t of targets) {
|
|
@@ -1613,11 +2136,6 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
|
|
|
1613
2136
|
);
|
|
1614
2137
|
return 1;
|
|
1615
2138
|
}
|
|
1616
|
-
ctx.log?.(
|
|
1617
|
-
command === "install" ? `
|
|
1618
|
-
\u2705 installed. Configure the server in ~/.hindsight/coding-agent.json (apiUrl/apiToken) and start a session.` : `
|
|
1619
|
-
\u2705 uninstalled.`
|
|
1620
|
-
);
|
|
1621
2139
|
return 0;
|
|
1622
2140
|
}
|
|
1623
2141
|
var mainPath = process.argv[1] ? (() => {
|
|
@@ -1629,20 +2147,46 @@ var mainPath = process.argv[1] ? (() => {
|
|
|
1629
2147
|
})() : void 0;
|
|
1630
2148
|
var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
|
|
1631
2149
|
if (isMain || mainPath?.endsWith("installer.js")) {
|
|
1632
|
-
const dist =
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
2150
|
+
const dist = dirname8(fileURLToPath5(import.meta.url));
|
|
2151
|
+
const pkgRoot = dirname8(dist);
|
|
2152
|
+
let version;
|
|
2153
|
+
try {
|
|
2154
|
+
version = JSON.parse(readFileSync15(join13(pkgRoot, "package.json"), "utf8")).version;
|
|
2155
|
+
} catch {
|
|
2156
|
+
version = void 0;
|
|
2157
|
+
}
|
|
2158
|
+
const ui = createInstallerUi({
|
|
2159
|
+
home: homedir9(),
|
|
2160
|
+
command: process.argv[2],
|
|
2161
|
+
version,
|
|
2162
|
+
harnessNames: INSTALLERS.map((i) => i.name),
|
|
2163
|
+
// configureServer's messages render as their own "server" group, but don't count as an agent.
|
|
2164
|
+
auxNames: ["server"],
|
|
2165
|
+
configPath: process.env.HINDSIGHT_CONFIG || void 0
|
|
2166
|
+
});
|
|
2167
|
+
ui.intro();
|
|
2168
|
+
const code = run(process.argv.slice(2), {
|
|
2169
|
+
home: homedir9(),
|
|
2170
|
+
pkgRoot,
|
|
2171
|
+
dist,
|
|
2172
|
+
// Only a real terminal gets prompted; piped/CI installs take the documented default.
|
|
2173
|
+
// tty.isatty, NOT process.stdin.isTTY: the process.stdin getter initializes the stdin TTY
|
|
2174
|
+
// stream, which puts fd 0 in non-blocking mode and breaks readLineSync (see there).
|
|
2175
|
+
interactive: Boolean(isatty(0) && isatty(1)),
|
|
2176
|
+
log: ui.log,
|
|
2177
|
+
promptStyle: ui.prompt,
|
|
2178
|
+
selectPrompt: ui.select
|
|
2179
|
+
});
|
|
2180
|
+
ui.outro(code);
|
|
2181
|
+
process.exit(code);
|
|
1641
2182
|
}
|
|
1642
2183
|
export {
|
|
1643
2184
|
INSTALLERS,
|
|
1644
2185
|
KILO_CONFIG_CANDIDATES,
|
|
1645
2186
|
MARKER,
|
|
2187
|
+
flagValue,
|
|
2188
|
+
flagValueArgs,
|
|
1646
2189
|
parseJsonc,
|
|
1647
|
-
run
|
|
2190
|
+
run,
|
|
2191
|
+
runtimeDir
|
|
1648
2192
|
};
|