@vectorize-io/hindsight-coding-agents 0.3.0 → 0.3.2
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 +28 -0
- package/dist/antigravity-hook.js +39 -6
- package/dist/antigravity-statusline.js +124 -98
- package/dist/antigravity-stop-hook.js +63 -16
- package/dist/claude-hook.js +39 -6
- package/dist/claude-sessionstart-hook.js +39 -6
- package/dist/claude-stop-hook.js +63 -16
- package/dist/cline.js +150 -110
- package/dist/codex-hook.js +39 -6
- package/dist/codex-sessionstart-hook.js +39 -6
- package/dist/codex-stop-hook.js +63 -16
- package/dist/copilot-hook.js +39 -6
- package/dist/copilot-sessionstart-hook.js +39 -6
- package/dist/copilot-stop-hook.js +63 -16
- package/dist/cursor-hook.js +39 -6
- package/dist/cursor-sessionstart-hook.js +39 -6
- package/dist/cursor-stop-hook.js +63 -16
- package/dist/daemon-start.js +24 -12
- package/dist/deepen.js +32 -6
- package/dist/devin-hook.js +39 -6
- package/dist/devin-sessionstart-hook.js +39 -6
- package/dist/devin-stop-hook.js +63 -16
- package/dist/grok-hook.js +39 -6
- package/dist/grok-sessionstart-hook.js +39 -6
- package/dist/grok-stop-hook.js +63 -16
- package/dist/hindsight-seed.js +108 -96
- package/dist/index.js +55 -15
- package/dist/installer.js +7 -0
- package/dist/kilo.js +55 -15
- package/dist/mcp-server.js +127 -101
- package/dist/prime-agent.js +51 -15
- package/dist/status.js +31 -5
- package/package.json +1 -1
package/dist/cursor-stop-hook.js
CHANGED
|
@@ -71,18 +71,32 @@ function gitProjectName(directory, resolveWorktrees) {
|
|
|
71
71
|
}
|
|
72
72
|
return dirName(directory);
|
|
73
73
|
}
|
|
74
|
+
function configuredDir(dir) {
|
|
75
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join(homedir(), dir.slice(1)) : dir;
|
|
76
|
+
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
77
|
+
}
|
|
78
|
+
function isWithin(directory, configured) {
|
|
79
|
+
return directory === configured || directory.startsWith(configured + sep);
|
|
80
|
+
}
|
|
74
81
|
function mapLookup(map, directory) {
|
|
75
82
|
const cwd = normalize(directory);
|
|
76
83
|
let best;
|
|
77
84
|
for (const [dir, bank] of Object.entries(map)) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
85
|
+
const p = configuredDir(dir);
|
|
86
|
+
if (isWithin(cwd, p)) {
|
|
81
87
|
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
return best?.bank;
|
|
85
91
|
}
|
|
92
|
+
function isOptedIn(config, directory) {
|
|
93
|
+
if (!config.optInOnly) return true;
|
|
94
|
+
if (!directory) return false;
|
|
95
|
+
const cwd = normalize(directory);
|
|
96
|
+
if ((config.optInPaths ?? []).some((dir) => dir && isWithin(cwd, configuredDir(dir))))
|
|
97
|
+
return true;
|
|
98
|
+
return Boolean(config.mapPathToBank && mapLookup(config.mapPathToBank, directory));
|
|
99
|
+
}
|
|
86
100
|
function deriveBankId(config, directory, harness = "coding") {
|
|
87
101
|
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
88
102
|
if (mapped) return mapped;
|
|
@@ -134,6 +148,9 @@ function resolveConfig(raw = {}) {
|
|
|
134
148
|
bankIdTemplate: raw.bankIdTemplate,
|
|
135
149
|
mapPathToBank: raw.mapPathToBank,
|
|
136
150
|
resolveWorktrees: raw.resolveWorktrees,
|
|
151
|
+
optInOnly: raw.optInOnly ?? false,
|
|
152
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
153
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
137
154
|
harness: raw.harness ?? "opencode",
|
|
138
155
|
disabled: raw.disabled ?? false,
|
|
139
156
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -194,6 +211,8 @@ var ENV_KEYS = {
|
|
|
194
211
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
195
212
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
196
213
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
214
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
215
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
197
216
|
harness: "HINDSIGHT_HARNESS",
|
|
198
217
|
disabled: "HINDSIGHT_DISABLED",
|
|
199
218
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -216,13 +235,14 @@ var ENV_KEYS = {
|
|
|
216
235
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
217
236
|
"dynamicBankId",
|
|
218
237
|
"resolveWorktrees",
|
|
238
|
+
"optInOnly",
|
|
219
239
|
"disabled",
|
|
220
240
|
"retainSessions",
|
|
221
241
|
"autoReflect",
|
|
222
242
|
"autoSeed",
|
|
223
243
|
"codebaseSurvey"
|
|
224
244
|
]);
|
|
225
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
245
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
226
246
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
227
247
|
"apiPort",
|
|
228
248
|
"daemonIdleTimeout",
|
|
@@ -266,9 +286,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
266
286
|
"mapPathToBank",
|
|
267
287
|
"dynamicBankId",
|
|
268
288
|
"resolveWorktrees",
|
|
289
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
290
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
291
|
+
"optInOnly",
|
|
292
|
+
"optInPaths",
|
|
269
293
|
"harness"
|
|
270
294
|
];
|
|
271
|
-
function applyBankConfig(cfg, resolvedId) {
|
|
295
|
+
function applyBankConfig(cfg, resolvedId, directory) {
|
|
296
|
+
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
297
|
+
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
272
298
|
const section = cfg.banks[resolvedId];
|
|
273
299
|
if (!section) return { cfg, bankId: resolvedId };
|
|
274
300
|
const safe = { ...section };
|
|
@@ -1062,10 +1088,10 @@ async function supportsAppend(client) {
|
|
|
1062
1088
|
return false;
|
|
1063
1089
|
}
|
|
1064
1090
|
}
|
|
1091
|
+
var DEFAULT_RETRY_WINDOW_MS = 6e4;
|
|
1065
1092
|
var RETAIN_RETRY_ATTEMPTS = 2;
|
|
1066
|
-
var
|
|
1067
|
-
async function submitWithRetry(send, isStillNewest) {
|
|
1068
|
-
let spent = 0;
|
|
1093
|
+
var REQUEST_BUDGET_MS = 15e3;
|
|
1094
|
+
async function submitWithRetry(send, isStillNewest, retryUntil) {
|
|
1069
1095
|
for (let attempt = 0; ; attempt++) {
|
|
1070
1096
|
try {
|
|
1071
1097
|
return await send();
|
|
@@ -1073,8 +1099,7 @@ async function submitWithRetry(send, isStillNewest) {
|
|
|
1073
1099
|
const limited = e instanceof RateLimitedError;
|
|
1074
1100
|
if (!limited || attempt >= RETAIN_RETRY_ATTEMPTS || !isStillNewest()) throw e;
|
|
1075
1101
|
const wait = e.retryAfterMs || 1e3;
|
|
1076
|
-
if (wait
|
|
1077
|
-
spent += wait;
|
|
1102
|
+
if (Date.now() + wait + REQUEST_BUDGET_MS > retryUntil) throw e;
|
|
1078
1103
|
await sleep(wait);
|
|
1079
1104
|
}
|
|
1080
1105
|
}
|
|
@@ -1094,14 +1119,24 @@ function serialize(cursors, sessionId, write2) {
|
|
|
1094
1119
|
}
|
|
1095
1120
|
async function retainLiveSession(client, sessionId, turns, startTs, harness, opts = {}) {
|
|
1096
1121
|
const cursors = opts.cursors;
|
|
1097
|
-
if (!cursors)
|
|
1122
|
+
if (!cursors)
|
|
1123
|
+
return writeSession(
|
|
1124
|
+
client,
|
|
1125
|
+
sessionId,
|
|
1126
|
+
turns,
|
|
1127
|
+
startTs,
|
|
1128
|
+
harness,
|
|
1129
|
+
opts.stamp,
|
|
1130
|
+
void 0,
|
|
1131
|
+
opts.retryUntil
|
|
1132
|
+
);
|
|
1098
1133
|
return serialize(
|
|
1099
1134
|
cursors,
|
|
1100
1135
|
sessionId,
|
|
1101
|
-
() => writeSession(client, sessionId, turns, startTs, harness, opts.stamp, cursors)
|
|
1136
|
+
() => writeSession(client, sessionId, turns, startTs, harness, opts.stamp, cursors, opts.retryUntil)
|
|
1102
1137
|
);
|
|
1103
1138
|
}
|
|
1104
|
-
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors) {
|
|
1139
|
+
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
1105
1140
|
const refId = `conversation:${sessionId}`;
|
|
1106
1141
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
1107
1142
|
const plan = planRetain(turns, cursors?.read(sessionId), { appendSupported, bank: client.bank });
|
|
@@ -1153,7 +1188,8 @@ ${content}`),
|
|
|
1153
1188
|
if (!cursors) return true;
|
|
1154
1189
|
const now = cursors.read(sessionId);
|
|
1155
1190
|
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
1156
|
-
}
|
|
1191
|
+
},
|
|
1192
|
+
retryUntil
|
|
1157
1193
|
);
|
|
1158
1194
|
cursors?.write(sessionId, next);
|
|
1159
1195
|
}
|
|
@@ -1469,6 +1505,7 @@ function readClaudeTranscript(path) {
|
|
|
1469
1505
|
}
|
|
1470
1506
|
|
|
1471
1507
|
// src/core/retain-hook.ts
|
|
1508
|
+
var HOST_DEADLINE_MARGIN_MS = 2e3;
|
|
1472
1509
|
async function buildRetain(args) {
|
|
1473
1510
|
const { harness, sessionId, transcriptPath, client } = args;
|
|
1474
1511
|
const readTranscript = args.readTranscript ?? readClaudeTranscript;
|
|
@@ -1479,7 +1516,8 @@ async function buildRetain(args) {
|
|
|
1479
1516
|
try {
|
|
1480
1517
|
await retainLiveSession(client, sessionId, turns, startTs, harness, {
|
|
1481
1518
|
cursors: args.cursors ?? fileCursorStore(harness),
|
|
1482
|
-
stamp: args.stamp
|
|
1519
|
+
stamp: args.stamp,
|
|
1520
|
+
retryUntil: args.retryUntil
|
|
1483
1521
|
});
|
|
1484
1522
|
diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
|
|
1485
1523
|
} catch (e) {
|
|
@@ -1495,6 +1533,7 @@ async function buildRetain(args) {
|
|
|
1495
1533
|
}
|
|
1496
1534
|
async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
1497
1535
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
1536
|
+
const hostDeadline = Date.now() + spec.hostTimeoutSec * 1e3 - HOST_DEADLINE_MARGIN_MS;
|
|
1498
1537
|
let ev = {};
|
|
1499
1538
|
try {
|
|
1500
1539
|
ev = JSON.parse(readFileSync4(0, "utf8"));
|
|
@@ -1507,7 +1546,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1507
1546
|
setLogLevel(cfg.logLevel);
|
|
1508
1547
|
if (cfg.disabled) return;
|
|
1509
1548
|
if (!transcriptPath) return;
|
|
1510
|
-
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, spec.harness));
|
|
1549
|
+
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, spec.harness), cwd);
|
|
1511
1550
|
cfg = resolved.cfg;
|
|
1512
1551
|
const bankId = resolved.bankId;
|
|
1513
1552
|
if (cfg.disabled) return;
|
|
@@ -1524,6 +1563,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1524
1563
|
transcriptPath,
|
|
1525
1564
|
client,
|
|
1526
1565
|
readTranscript: spec.readTranscript,
|
|
1566
|
+
retryUntil: hostDeadline,
|
|
1527
1567
|
stamp: buildRetainStamp(cfg, {
|
|
1528
1568
|
directory: cwd,
|
|
1529
1569
|
harness: spec.harness,
|
|
@@ -1895,6 +1935,7 @@ var HOOK_HARNESSES = {
|
|
|
1895
1935
|
sessionStart: standardSessionStart("claude-code"),
|
|
1896
1936
|
prompt: claudePrompt,
|
|
1897
1937
|
retain: {
|
|
1938
|
+
hostTimeoutSec: 60,
|
|
1898
1939
|
harness: "claude-code",
|
|
1899
1940
|
parse: (ev) => ({
|
|
1900
1941
|
sessionId: ev.session_id,
|
|
@@ -1913,6 +1954,7 @@ var HOOK_HARNESSES = {
|
|
|
1913
1954
|
sessionStart: standardSessionStart("codex"),
|
|
1914
1955
|
prompt: codexPrompt,
|
|
1915
1956
|
retain: {
|
|
1957
|
+
hostTimeoutSec: 60,
|
|
1916
1958
|
harness: "codex",
|
|
1917
1959
|
parse: (ev) => ({
|
|
1918
1960
|
sessionId: ev.session_id,
|
|
@@ -1941,6 +1983,7 @@ var HOOK_HARNESSES = {
|
|
|
1941
1983
|
},
|
|
1942
1984
|
prompt: antigravityPrompt,
|
|
1943
1985
|
retain: {
|
|
1986
|
+
hostTimeoutSec: 30,
|
|
1944
1987
|
harness: "antigravity-cli",
|
|
1945
1988
|
parse: (ev) => ({
|
|
1946
1989
|
sessionId: ev.conversationId,
|
|
@@ -1969,6 +2012,7 @@ var HOOK_HARNESSES = {
|
|
|
1969
2012
|
},
|
|
1970
2013
|
prompt: cursorPrompt,
|
|
1971
2014
|
retain: {
|
|
2015
|
+
hostTimeoutSec: 30,
|
|
1972
2016
|
harness: "cursor-cli",
|
|
1973
2017
|
parse: (ev) => ({
|
|
1974
2018
|
sessionId: ev.conversation_id ?? ev.session_id,
|
|
@@ -2002,6 +2046,7 @@ var HOOK_HARNESSES = {
|
|
|
2002
2046
|
},
|
|
2003
2047
|
prompt: copilotPrompt,
|
|
2004
2048
|
retain: {
|
|
2049
|
+
hostTimeoutSec: 60,
|
|
2005
2050
|
harness: "copilot-cli",
|
|
2006
2051
|
parse: (ev) => ({
|
|
2007
2052
|
sessionId: ev.sessionId,
|
|
@@ -2030,6 +2075,7 @@ var HOOK_HARNESSES = {
|
|
|
2030
2075
|
},
|
|
2031
2076
|
prompt: devinPrompt,
|
|
2032
2077
|
retain: {
|
|
2078
|
+
hostTimeoutSec: 60,
|
|
2033
2079
|
harness: "devin-cli",
|
|
2034
2080
|
parse: (ev) => {
|
|
2035
2081
|
const sessionId = ev.session_id;
|
|
@@ -2069,6 +2115,7 @@ var HOOK_HARNESSES = {
|
|
|
2069
2115
|
})
|
|
2070
2116
|
},
|
|
2071
2117
|
retain: {
|
|
2118
|
+
hostTimeoutSec: 60,
|
|
2072
2119
|
harness: "grok-build",
|
|
2073
2120
|
parse: (ev) => ({
|
|
2074
2121
|
sessionId: ev.sessionId,
|
package/dist/daemon-start.js
CHANGED
|
@@ -296,8 +296,8 @@ var init_dist = __esm({
|
|
|
296
296
|
|
|
297
297
|
// src/core/config.ts
|
|
298
298
|
import { readFileSync } from "fs";
|
|
299
|
-
import { homedir } from "os";
|
|
300
|
-
import { join as
|
|
299
|
+
import { homedir as homedir2 } from "os";
|
|
300
|
+
import { join as join3 } from "path";
|
|
301
301
|
|
|
302
302
|
// src/core/seed.ts
|
|
303
303
|
import { spawn as realSpawn } from "child_process";
|
|
@@ -305,8 +305,14 @@ import { dirname, join } from "path";
|
|
|
305
305
|
import { fileURLToPath } from "url";
|
|
306
306
|
var DEFAULT_SEED_LIMIT = 300;
|
|
307
307
|
|
|
308
|
+
// src/core/bank.ts
|
|
309
|
+
import { execFileSync } from "child_process";
|
|
310
|
+
import { existsSync } from "fs";
|
|
311
|
+
import { homedir } from "os";
|
|
312
|
+
import { basename, dirname as dirname2, join as join2, normalize, sep } from "path";
|
|
313
|
+
|
|
308
314
|
// src/core/config.ts
|
|
309
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
315
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
|
|
310
316
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
311
317
|
var DEFAULT_DAEMON_IDLE_TIMEOUT = 300;
|
|
312
318
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
@@ -330,6 +336,9 @@ function resolveConfig(raw = {}) {
|
|
|
330
336
|
bankIdTemplate: raw.bankIdTemplate,
|
|
331
337
|
mapPathToBank: raw.mapPathToBank,
|
|
332
338
|
resolveWorktrees: raw.resolveWorktrees,
|
|
339
|
+
optInOnly: raw.optInOnly ?? false,
|
|
340
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
341
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
333
342
|
harness: raw.harness ?? "opencode",
|
|
334
343
|
disabled: raw.disabled ?? false,
|
|
335
344
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -390,6 +399,8 @@ var ENV_KEYS = {
|
|
|
390
399
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
391
400
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
392
401
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
402
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
403
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
393
404
|
harness: "HINDSIGHT_HARNESS",
|
|
394
405
|
disabled: "HINDSIGHT_DISABLED",
|
|
395
406
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -412,13 +423,14 @@ var ENV_KEYS = {
|
|
|
412
423
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
413
424
|
"dynamicBankId",
|
|
414
425
|
"resolveWorktrees",
|
|
426
|
+
"optInOnly",
|
|
415
427
|
"disabled",
|
|
416
428
|
"retainSessions",
|
|
417
429
|
"autoReflect",
|
|
418
430
|
"autoSeed",
|
|
419
431
|
"codebaseSurvey"
|
|
420
432
|
]);
|
|
421
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
433
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
422
434
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
423
435
|
"apiPort",
|
|
424
436
|
"daemonIdleTimeout",
|
|
@@ -458,8 +470,8 @@ function loadConfig(opts = {}) {
|
|
|
458
470
|
}
|
|
459
471
|
|
|
460
472
|
// src/core/daemon.ts
|
|
461
|
-
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
462
|
-
import { dirname as
|
|
473
|
+
import { execFileSync as execFileSync2, spawn as realSpawn2 } from "child_process";
|
|
474
|
+
import { dirname as dirname4, join as join5 } from "path";
|
|
463
475
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
464
476
|
|
|
465
477
|
// src/core/diag.ts
|
|
@@ -468,7 +480,7 @@ import { appendFileSync as appendFileSync2 } from "fs";
|
|
|
468
480
|
// src/core/log.ts
|
|
469
481
|
import { appendFileSync, mkdirSync } from "fs";
|
|
470
482
|
import { tmpdir } from "os";
|
|
471
|
-
import { dirname as
|
|
483
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
472
484
|
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
473
485
|
var current = ["debug", "info", "warn", "error"].find(
|
|
474
486
|
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
@@ -477,13 +489,13 @@ function setLogLevel(level) {
|
|
|
477
489
|
if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
|
|
478
490
|
}
|
|
479
491
|
function logFilePath() {
|
|
480
|
-
return process.env.HINDSIGHT_LOG_FILE ||
|
|
492
|
+
return process.env.HINDSIGHT_LOG_FILE || join4(tmpdir(), "hindsight-coding-agent", "plugin.log");
|
|
481
493
|
}
|
|
482
494
|
function write(level, scope, msg, extra) {
|
|
483
495
|
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
484
496
|
try {
|
|
485
497
|
const file = logFilePath();
|
|
486
|
-
mkdirSync(
|
|
498
|
+
mkdirSync(dirname3(file), { recursive: true });
|
|
487
499
|
appendFileSync(
|
|
488
500
|
file,
|
|
489
501
|
`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
|
|
@@ -522,7 +534,7 @@ async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
|
522
534
|
function hasRustToolchain() {
|
|
523
535
|
if (process.platform !== "darwin") return true;
|
|
524
536
|
try {
|
|
525
|
-
|
|
537
|
+
execFileSync2("cargo", ["--version"], { stdio: "pipe", timeout: 1e4 });
|
|
526
538
|
return true;
|
|
527
539
|
} catch {
|
|
528
540
|
return false;
|
|
@@ -530,7 +542,7 @@ function hasRustToolchain() {
|
|
|
530
542
|
}
|
|
531
543
|
function hasUvx() {
|
|
532
544
|
try {
|
|
533
|
-
|
|
545
|
+
execFileSync2("uvx", ["--version"], { stdio: "pipe", timeout: 1e4 });
|
|
534
546
|
return true;
|
|
535
547
|
} catch {
|
|
536
548
|
return false;
|
|
@@ -562,7 +574,7 @@ function detectLlm(env = process.env) {
|
|
|
562
574
|
}
|
|
563
575
|
function onPath(bin) {
|
|
564
576
|
try {
|
|
565
|
-
|
|
577
|
+
execFileSync2("which", [bin], { stdio: "pipe", timeout: 5e3 });
|
|
566
578
|
return true;
|
|
567
579
|
} catch {
|
|
568
580
|
return false;
|
package/dist/deepen.js
CHANGED
|
@@ -74,18 +74,32 @@ function gitProjectName(directory, resolveWorktrees) {
|
|
|
74
74
|
}
|
|
75
75
|
return dirName(directory);
|
|
76
76
|
}
|
|
77
|
+
function configuredDir(dir) {
|
|
78
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join(homedir(), dir.slice(1)) : dir;
|
|
79
|
+
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
80
|
+
}
|
|
81
|
+
function isWithin(directory, configured) {
|
|
82
|
+
return directory === configured || directory.startsWith(configured + sep);
|
|
83
|
+
}
|
|
77
84
|
function mapLookup(map, directory) {
|
|
78
85
|
const cwd = normalize(directory);
|
|
79
86
|
let best;
|
|
80
87
|
for (const [dir, bank] of Object.entries(map)) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
88
|
+
const p = configuredDir(dir);
|
|
89
|
+
if (isWithin(cwd, p)) {
|
|
84
90
|
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
85
91
|
}
|
|
86
92
|
}
|
|
87
93
|
return best?.bank;
|
|
88
94
|
}
|
|
95
|
+
function isOptedIn(config, directory) {
|
|
96
|
+
if (!config.optInOnly) return true;
|
|
97
|
+
if (!directory) return false;
|
|
98
|
+
const cwd = normalize(directory);
|
|
99
|
+
if ((config.optInPaths ?? []).some((dir) => dir && isWithin(cwd, configuredDir(dir))))
|
|
100
|
+
return true;
|
|
101
|
+
return Boolean(config.mapPathToBank && mapLookup(config.mapPathToBank, directory));
|
|
102
|
+
}
|
|
89
103
|
function deriveBankId(config, directory, harness = "coding") {
|
|
90
104
|
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
91
105
|
if (mapped) return mapped;
|
|
@@ -832,6 +846,9 @@ function resolveConfig(raw = {}) {
|
|
|
832
846
|
bankIdTemplate: raw.bankIdTemplate,
|
|
833
847
|
mapPathToBank: raw.mapPathToBank,
|
|
834
848
|
resolveWorktrees: raw.resolveWorktrees,
|
|
849
|
+
optInOnly: raw.optInOnly ?? false,
|
|
850
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
851
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
835
852
|
harness: raw.harness ?? "opencode",
|
|
836
853
|
disabled: raw.disabled ?? false,
|
|
837
854
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -892,6 +909,8 @@ var ENV_KEYS = {
|
|
|
892
909
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
893
910
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
894
911
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
912
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
913
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
895
914
|
harness: "HINDSIGHT_HARNESS",
|
|
896
915
|
disabled: "HINDSIGHT_DISABLED",
|
|
897
916
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -914,13 +933,14 @@ var ENV_KEYS = {
|
|
|
914
933
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
915
934
|
"dynamicBankId",
|
|
916
935
|
"resolveWorktrees",
|
|
936
|
+
"optInOnly",
|
|
917
937
|
"disabled",
|
|
918
938
|
"retainSessions",
|
|
919
939
|
"autoReflect",
|
|
920
940
|
"autoSeed",
|
|
921
941
|
"codebaseSurvey"
|
|
922
942
|
]);
|
|
923
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
943
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
924
944
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
925
945
|
"apiPort",
|
|
926
946
|
"daemonIdleTimeout",
|
|
@@ -964,9 +984,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
964
984
|
"mapPathToBank",
|
|
965
985
|
"dynamicBankId",
|
|
966
986
|
"resolveWorktrees",
|
|
987
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
988
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
989
|
+
"optInOnly",
|
|
990
|
+
"optInPaths",
|
|
967
991
|
"harness"
|
|
968
992
|
];
|
|
969
|
-
function applyBankConfig(cfg2, resolvedId) {
|
|
993
|
+
function applyBankConfig(cfg2, resolvedId, directory) {
|
|
994
|
+
if (directory !== void 0 && !isOptedIn(cfg2, directory))
|
|
995
|
+
return { cfg: { ...cfg2, disabled: true }, bankId: resolvedId };
|
|
970
996
|
const section = cfg2.banks[resolvedId];
|
|
971
997
|
if (!section) return { cfg: cfg2, bankId: resolvedId };
|
|
972
998
|
const safe = { ...section };
|
|
@@ -1309,7 +1335,7 @@ function arg(name, def) {
|
|
|
1309
1335
|
var REPO = arg("repo");
|
|
1310
1336
|
var cfg0 = loadConfig({ harness: arg("harness") ?? void 0, path: arg("config") });
|
|
1311
1337
|
var BANK = arg("bank") ?? (REPO ? deriveBankId(cfg0, REPO, arg("harness") ?? cfg0.harness) : cfg0.bankId);
|
|
1312
|
-
var resolved0 = BANK ? applyBankConfig(cfg0, BANK) : { cfg: cfg0, bankId: BANK };
|
|
1338
|
+
var resolved0 = BANK ? applyBankConfig(cfg0, BANK, REPO ?? void 0) : { cfg: cfg0, bankId: BANK };
|
|
1313
1339
|
var cfg = resolved0.cfg;
|
|
1314
1340
|
var FINAL_BANK = resolved0.bankId ?? BANK;
|
|
1315
1341
|
if (cfg.disabled) {
|
package/dist/devin-hook.js
CHANGED
|
@@ -68,18 +68,32 @@ function gitProjectName(directory, resolveWorktrees) {
|
|
|
68
68
|
}
|
|
69
69
|
return dirName(directory);
|
|
70
70
|
}
|
|
71
|
+
function configuredDir(dir) {
|
|
72
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join(homedir(), dir.slice(1)) : dir;
|
|
73
|
+
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
74
|
+
}
|
|
75
|
+
function isWithin(directory, configured) {
|
|
76
|
+
return directory === configured || directory.startsWith(configured + sep);
|
|
77
|
+
}
|
|
71
78
|
function mapLookup(map, directory) {
|
|
72
79
|
const cwd = normalize(directory);
|
|
73
80
|
let best;
|
|
74
81
|
for (const [dir, bank] of Object.entries(map)) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
82
|
+
const p = configuredDir(dir);
|
|
83
|
+
if (isWithin(cwd, p)) {
|
|
78
84
|
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
return best?.bank;
|
|
82
88
|
}
|
|
89
|
+
function isOptedIn(config, directory) {
|
|
90
|
+
if (!config.optInOnly) return true;
|
|
91
|
+
if (!directory) return false;
|
|
92
|
+
const cwd = normalize(directory);
|
|
93
|
+
if ((config.optInPaths ?? []).some((dir) => dir && isWithin(cwd, configuredDir(dir))))
|
|
94
|
+
return true;
|
|
95
|
+
return Boolean(config.mapPathToBank && mapLookup(config.mapPathToBank, directory));
|
|
96
|
+
}
|
|
83
97
|
function deriveBankId(config, directory, harness = "coding") {
|
|
84
98
|
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
85
99
|
if (mapped) return mapped;
|
|
@@ -157,6 +171,9 @@ function resolveConfig(raw = {}) {
|
|
|
157
171
|
bankIdTemplate: raw.bankIdTemplate,
|
|
158
172
|
mapPathToBank: raw.mapPathToBank,
|
|
159
173
|
resolveWorktrees: raw.resolveWorktrees,
|
|
174
|
+
optInOnly: raw.optInOnly ?? false,
|
|
175
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
176
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
160
177
|
harness: raw.harness ?? "opencode",
|
|
161
178
|
disabled: raw.disabled ?? false,
|
|
162
179
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -217,6 +234,8 @@ var ENV_KEYS = {
|
|
|
217
234
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
218
235
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
219
236
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
237
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
238
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
220
239
|
harness: "HINDSIGHT_HARNESS",
|
|
221
240
|
disabled: "HINDSIGHT_DISABLED",
|
|
222
241
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -239,13 +258,14 @@ var ENV_KEYS = {
|
|
|
239
258
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
240
259
|
"dynamicBankId",
|
|
241
260
|
"resolveWorktrees",
|
|
261
|
+
"optInOnly",
|
|
242
262
|
"disabled",
|
|
243
263
|
"retainSessions",
|
|
244
264
|
"autoReflect",
|
|
245
265
|
"autoSeed",
|
|
246
266
|
"codebaseSurvey"
|
|
247
267
|
]);
|
|
248
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
268
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
249
269
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
250
270
|
"apiPort",
|
|
251
271
|
"daemonIdleTimeout",
|
|
@@ -289,9 +309,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
289
309
|
"mapPathToBank",
|
|
290
310
|
"dynamicBankId",
|
|
291
311
|
"resolveWorktrees",
|
|
312
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
313
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
314
|
+
"optInOnly",
|
|
315
|
+
"optInPaths",
|
|
292
316
|
"harness"
|
|
293
317
|
];
|
|
294
|
-
function applyBankConfig(cfg, resolvedId) {
|
|
318
|
+
function applyBankConfig(cfg, resolvedId, directory) {
|
|
319
|
+
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
320
|
+
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
295
321
|
const section = cfg.banks[resolvedId];
|
|
296
322
|
if (!section) return { cfg, bankId: resolvedId };
|
|
297
323
|
const safe = { ...section };
|
|
@@ -1204,7 +1230,7 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1204
1230
|
return;
|
|
1205
1231
|
}
|
|
1206
1232
|
const out = (context, notice) => process.stdout.write(JSON.stringify(spec.emit(context ?? "", notice, ev)));
|
|
1207
|
-
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, spec.harness));
|
|
1233
|
+
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, spec.harness), cwd);
|
|
1208
1234
|
cfg = resolved.cfg;
|
|
1209
1235
|
const bankId = resolved.bankId;
|
|
1210
1236
|
if (cfg.disabled) {
|
|
@@ -1703,6 +1729,7 @@ var HOOK_HARNESSES = {
|
|
|
1703
1729
|
sessionStart: standardSessionStart("claude-code"),
|
|
1704
1730
|
prompt: claudePrompt,
|
|
1705
1731
|
retain: {
|
|
1732
|
+
hostTimeoutSec: 60,
|
|
1706
1733
|
harness: "claude-code",
|
|
1707
1734
|
parse: (ev) => ({
|
|
1708
1735
|
sessionId: ev.session_id,
|
|
@@ -1721,6 +1748,7 @@ var HOOK_HARNESSES = {
|
|
|
1721
1748
|
sessionStart: standardSessionStart("codex"),
|
|
1722
1749
|
prompt: codexPrompt,
|
|
1723
1750
|
retain: {
|
|
1751
|
+
hostTimeoutSec: 60,
|
|
1724
1752
|
harness: "codex",
|
|
1725
1753
|
parse: (ev) => ({
|
|
1726
1754
|
sessionId: ev.session_id,
|
|
@@ -1749,6 +1777,7 @@ var HOOK_HARNESSES = {
|
|
|
1749
1777
|
},
|
|
1750
1778
|
prompt: antigravityPrompt,
|
|
1751
1779
|
retain: {
|
|
1780
|
+
hostTimeoutSec: 30,
|
|
1752
1781
|
harness: "antigravity-cli",
|
|
1753
1782
|
parse: (ev) => ({
|
|
1754
1783
|
sessionId: ev.conversationId,
|
|
@@ -1777,6 +1806,7 @@ var HOOK_HARNESSES = {
|
|
|
1777
1806
|
},
|
|
1778
1807
|
prompt: cursorPrompt,
|
|
1779
1808
|
retain: {
|
|
1809
|
+
hostTimeoutSec: 30,
|
|
1780
1810
|
harness: "cursor-cli",
|
|
1781
1811
|
parse: (ev) => ({
|
|
1782
1812
|
sessionId: ev.conversation_id ?? ev.session_id,
|
|
@@ -1810,6 +1840,7 @@ var HOOK_HARNESSES = {
|
|
|
1810
1840
|
},
|
|
1811
1841
|
prompt: copilotPrompt,
|
|
1812
1842
|
retain: {
|
|
1843
|
+
hostTimeoutSec: 60,
|
|
1813
1844
|
harness: "copilot-cli",
|
|
1814
1845
|
parse: (ev) => ({
|
|
1815
1846
|
sessionId: ev.sessionId,
|
|
@@ -1838,6 +1869,7 @@ var HOOK_HARNESSES = {
|
|
|
1838
1869
|
},
|
|
1839
1870
|
prompt: devinPrompt,
|
|
1840
1871
|
retain: {
|
|
1872
|
+
hostTimeoutSec: 60,
|
|
1841
1873
|
harness: "devin-cli",
|
|
1842
1874
|
parse: (ev) => {
|
|
1843
1875
|
const sessionId = ev.session_id;
|
|
@@ -1877,6 +1909,7 @@ var HOOK_HARNESSES = {
|
|
|
1877
1909
|
})
|
|
1878
1910
|
},
|
|
1879
1911
|
retain: {
|
|
1912
|
+
hostTimeoutSec: 60,
|
|
1880
1913
|
harness: "grok-build",
|
|
1881
1914
|
parse: (ev) => ({
|
|
1882
1915
|
sessionId: ev.sessionId,
|