@vectorize-io/hindsight-coding-agents 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -7
- package/dist/antigravity-hook.js +175 -48
- package/dist/antigravity-statusline.js +127 -80
- package/dist/antigravity-stop-hook.js +233 -88
- package/dist/claude-hook.js +175 -48
- package/dist/claude-sessionstart-hook.js +234 -58
- package/dist/claude-stop-hook.js +233 -88
- package/dist/cline.js +351 -167
- package/dist/codex-hook.js +175 -48
- package/dist/codex-sessionstart-hook.js +234 -58
- package/dist/codex-stop-hook.js +233 -88
- package/dist/copilot-hook.js +175 -48
- package/dist/copilot-sessionstart-hook.js +234 -58
- package/dist/copilot-stop-hook.js +233 -88
- package/dist/cursor-hook.js +175 -48
- package/dist/cursor-sessionstart-hook.js +234 -58
- package/dist/cursor-stop-hook.js +233 -88
- package/dist/daemon-start.js +27 -15
- package/dist/deepen.js +688 -497
- package/dist/devin-hook.js +175 -48
- package/dist/devin-sessionstart-hook.js +234 -58
- package/dist/devin-stop-hook.js +233 -88
- package/dist/grok-hook.js +175 -48
- package/dist/grok-sessionstart-hook.js +234 -58
- package/dist/grok-stop-hook.js +233 -88
- package/dist/hindsight-seed.js +111 -78
- package/dist/index.js +282 -98
- package/dist/installer.js +86 -56
- package/dist/kilo.js +282 -98
- package/dist/mcp-server.js +327 -117
- package/dist/prime-agent.js +16900 -0
- package/dist/status.js +143 -36
- package/package.json +6 -1
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
// src/core/config.ts
|
|
4
4
|
import { readFileSync } from "fs";
|
|
5
|
-
import { homedir } from "os";
|
|
6
|
-
import { join as
|
|
5
|
+
import { homedir as homedir2 } from "os";
|
|
6
|
+
import { join as join3 } from "path";
|
|
7
7
|
|
|
8
8
|
// src/core/seed.ts
|
|
9
9
|
import { spawn as realSpawn } from "child_process";
|
|
@@ -11,8 +11,114 @@ import { dirname, join } from "path";
|
|
|
11
11
|
import { fileURLToPath } from "url";
|
|
12
12
|
var DEFAULT_SEED_LIMIT = 300;
|
|
13
13
|
|
|
14
|
+
// src/core/bank.ts
|
|
15
|
+
import { execFileSync } from "child_process";
|
|
16
|
+
import { existsSync } from "fs";
|
|
17
|
+
import { homedir } from "os";
|
|
18
|
+
import { basename, dirname as dirname2, join as join2, normalize, sep } from "path";
|
|
19
|
+
|
|
20
|
+
// src/core/template.ts
|
|
21
|
+
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
22
|
+
function applyTemplate(template, resolvers, what) {
|
|
23
|
+
return template.replace(PLACEHOLDER, (_, name) => {
|
|
24
|
+
const resolve = resolvers[name];
|
|
25
|
+
if (!resolve) {
|
|
26
|
+
console.error(
|
|
27
|
+
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
28
|
+
);
|
|
29
|
+
return "unknown";
|
|
30
|
+
}
|
|
31
|
+
return resolve();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/core/bank.ts
|
|
36
|
+
var DEFAULT_BANK_NAME = "coding";
|
|
37
|
+
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
38
|
+
function getProjectRootFromGit(directory) {
|
|
39
|
+
if (!directory) return null;
|
|
40
|
+
try {
|
|
41
|
+
const commonDir = execFileSync(
|
|
42
|
+
"git",
|
|
43
|
+
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
44
|
+
{ cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
|
|
45
|
+
).trim();
|
|
46
|
+
if (!commonDir) return null;
|
|
47
|
+
return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
|
|
53
|
+
function nearestExistingDir(directory) {
|
|
54
|
+
let current = directory;
|
|
55
|
+
while (current) {
|
|
56
|
+
if (existsSync(current)) return current;
|
|
57
|
+
const parent = dirname2(current);
|
|
58
|
+
if (parent === current) return "";
|
|
59
|
+
current = parent;
|
|
60
|
+
}
|
|
61
|
+
return "";
|
|
62
|
+
}
|
|
63
|
+
function dirName(directory) {
|
|
64
|
+
return directory && basename(directory) || "unknown";
|
|
65
|
+
}
|
|
66
|
+
function gitProjectName(directory, resolveWorktrees) {
|
|
67
|
+
if (resolveWorktrees) {
|
|
68
|
+
const candidates = [
|
|
69
|
+
nearestExistingDir(directory),
|
|
70
|
+
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
71
|
+
];
|
|
72
|
+
for (const candidate of candidates) {
|
|
73
|
+
const root = candidate ? getProjectRootFromGit(candidate) : null;
|
|
74
|
+
if (root) return basename(root);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return dirName(directory);
|
|
78
|
+
}
|
|
79
|
+
function configuredDir(dir) {
|
|
80
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join2(homedir(), dir.slice(1)) : dir;
|
|
81
|
+
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
82
|
+
}
|
|
83
|
+
function isWithin(directory, configured) {
|
|
84
|
+
return directory === configured || directory.startsWith(configured + sep);
|
|
85
|
+
}
|
|
86
|
+
function mapLookup(map, directory) {
|
|
87
|
+
const cwd = normalize(directory);
|
|
88
|
+
let best;
|
|
89
|
+
for (const [dir, bank] of Object.entries(map)) {
|
|
90
|
+
const p = configuredDir(dir);
|
|
91
|
+
if (isWithin(cwd, p)) {
|
|
92
|
+
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return best?.bank;
|
|
96
|
+
}
|
|
97
|
+
function isOptedIn(config, directory) {
|
|
98
|
+
if (!config.optInOnly) return true;
|
|
99
|
+
if (!directory) return false;
|
|
100
|
+
const cwd = normalize(directory);
|
|
101
|
+
if ((config.optInPaths ?? []).some((dir) => dir && isWithin(cwd, configuredDir(dir))))
|
|
102
|
+
return true;
|
|
103
|
+
return Boolean(config.mapPathToBank && mapLookup(config.mapPathToBank, directory));
|
|
104
|
+
}
|
|
105
|
+
function deriveBankId(config, directory, harness = "coding") {
|
|
106
|
+
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
107
|
+
if (mapped) return mapped;
|
|
108
|
+
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
109
|
+
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
110
|
+
const resolvers = {
|
|
111
|
+
harness: () => harness,
|
|
112
|
+
project: () => dirName(directory),
|
|
113
|
+
gitProject: () => gitProjectName(directory, config.resolveWorktrees ?? true),
|
|
114
|
+
channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
|
|
115
|
+
user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
|
|
116
|
+
};
|
|
117
|
+
return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
118
|
+
}
|
|
119
|
+
|
|
14
120
|
// src/core/config.ts
|
|
15
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
121
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
|
|
16
122
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
17
123
|
var DEFAULT_DAEMON_IDLE_TIMEOUT = 300;
|
|
18
124
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
@@ -36,11 +142,14 @@ function resolveConfig(raw = {}) {
|
|
|
36
142
|
bankIdTemplate: raw.bankIdTemplate,
|
|
37
143
|
mapPathToBank: raw.mapPathToBank,
|
|
38
144
|
resolveWorktrees: raw.resolveWorktrees,
|
|
145
|
+
optInOnly: raw.optInOnly ?? false,
|
|
146
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
147
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
39
148
|
harness: raw.harness ?? "opencode",
|
|
40
149
|
disabled: raw.disabled ?? false,
|
|
41
150
|
retainSessions: raw.retainSessions ?? true,
|
|
42
151
|
// opencode: write back by default (parity with hook-harness Stop)
|
|
43
|
-
|
|
152
|
+
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
44
153
|
reflectTimeoutMs: raw.reflectTimeoutMs || 12e4,
|
|
45
154
|
autoReflect: raw.autoReflect ?? true,
|
|
46
155
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
@@ -96,10 +205,12 @@ var ENV_KEYS = {
|
|
|
96
205
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
97
206
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
98
207
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
208
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
209
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
99
210
|
harness: "HINDSIGHT_HARNESS",
|
|
100
211
|
disabled: "HINDSIGHT_DISABLED",
|
|
101
212
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
102
|
-
|
|
213
|
+
maxParallelRetains: "HINDSIGHT_MAX_PARALLEL_RETAINS",
|
|
103
214
|
reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
|
|
104
215
|
autoReflect: "HINDSIGHT_AUTO_REFLECT",
|
|
105
216
|
pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
|
|
@@ -118,17 +229,18 @@ var ENV_KEYS = {
|
|
|
118
229
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
119
230
|
"dynamicBankId",
|
|
120
231
|
"resolveWorktrees",
|
|
232
|
+
"optInOnly",
|
|
121
233
|
"disabled",
|
|
122
234
|
"retainSessions",
|
|
123
235
|
"autoReflect",
|
|
124
236
|
"autoSeed",
|
|
125
237
|
"codebaseSurvey"
|
|
126
238
|
]);
|
|
127
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
239
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
128
240
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
129
241
|
"apiPort",
|
|
130
242
|
"daemonIdleTimeout",
|
|
131
|
-
"
|
|
243
|
+
"maxParallelRetains",
|
|
132
244
|
"reflectTimeoutMs",
|
|
133
245
|
"pageRefreshEveryTurns",
|
|
134
246
|
"seedLimit",
|
|
@@ -168,9 +280,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
168
280
|
"mapPathToBank",
|
|
169
281
|
"dynamicBankId",
|
|
170
282
|
"resolveWorktrees",
|
|
283
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
284
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
285
|
+
"optInOnly",
|
|
286
|
+
"optInPaths",
|
|
171
287
|
"harness"
|
|
172
288
|
];
|
|
173
|
-
function applyBankConfig(cfg, resolvedId) {
|
|
289
|
+
function applyBankConfig(cfg, resolvedId, directory) {
|
|
290
|
+
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
291
|
+
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
174
292
|
const section = cfg.banks[resolvedId];
|
|
175
293
|
if (!section) return { cfg, bankId: resolvedId };
|
|
176
294
|
const safe = { ...section };
|
|
@@ -190,77 +308,6 @@ function resolvePartial(cfg, patch) {
|
|
|
190
308
|
return out;
|
|
191
309
|
}
|
|
192
310
|
|
|
193
|
-
// src/core/bank.ts
|
|
194
|
-
import { execFileSync } from "child_process";
|
|
195
|
-
import { homedir as homedir2 } from "os";
|
|
196
|
-
import { basename, dirname as dirname2, join as join3, normalize, sep } from "path";
|
|
197
|
-
|
|
198
|
-
// src/core/template.ts
|
|
199
|
-
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
200
|
-
function applyTemplate(template, resolvers, what) {
|
|
201
|
-
return template.replace(PLACEHOLDER, (_, name) => {
|
|
202
|
-
const resolve = resolvers[name];
|
|
203
|
-
if (!resolve) {
|
|
204
|
-
console.error(
|
|
205
|
-
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
206
|
-
);
|
|
207
|
-
return "unknown";
|
|
208
|
-
}
|
|
209
|
-
return resolve();
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// src/core/bank.ts
|
|
214
|
-
var DEFAULT_BANK_NAME = "coding";
|
|
215
|
-
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
216
|
-
function getProjectRootFromGit(directory) {
|
|
217
|
-
if (!directory) return null;
|
|
218
|
-
try {
|
|
219
|
-
const commonDir = execFileSync(
|
|
220
|
-
"git",
|
|
221
|
-
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
222
|
-
{ cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
|
|
223
|
-
).trim();
|
|
224
|
-
if (!commonDir) return null;
|
|
225
|
-
return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
|
|
226
|
-
} catch {
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function gitProjectName(directory, resolveWorktrees) {
|
|
231
|
-
if (resolveWorktrees) {
|
|
232
|
-
const root = getProjectRootFromGit(directory);
|
|
233
|
-
if (root) return basename(root);
|
|
234
|
-
}
|
|
235
|
-
return directory ? basename(directory) : "unknown";
|
|
236
|
-
}
|
|
237
|
-
function mapLookup(map, directory) {
|
|
238
|
-
const cwd = normalize(directory);
|
|
239
|
-
let best;
|
|
240
|
-
for (const [dir, bank] of Object.entries(map)) {
|
|
241
|
-
const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir2(), dir.slice(1)) : dir;
|
|
242
|
-
const p = normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
243
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
244
|
-
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return best?.bank;
|
|
248
|
-
}
|
|
249
|
-
function deriveBankId(config, directory, harness = "coding") {
|
|
250
|
-
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
251
|
-
if (mapped) return mapped;
|
|
252
|
-
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
253
|
-
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
254
|
-
const resolvers = {
|
|
255
|
-
harness: () => harness,
|
|
256
|
-
project: () => directory ? basename(directory) : "unknown",
|
|
257
|
-
gitProject: () => gitProjectName(directory, config.resolveWorktrees ?? true),
|
|
258
|
-
channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
|
|
259
|
-
user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
|
|
260
|
-
};
|
|
261
|
-
return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
262
|
-
}
|
|
263
|
-
|
|
264
311
|
// src/core/brand.ts
|
|
265
312
|
function brandWord() {
|
|
266
313
|
const start = [0, 116, 217];
|
|
@@ -279,7 +326,7 @@ function brandWord() {
|
|
|
279
326
|
function buildAntigravityStatusLine(state, cfg) {
|
|
280
327
|
const cwd = state.cwd || state.workspace?.current_dir;
|
|
281
328
|
if (!cwd) return brandWord();
|
|
282
|
-
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, "antigravity-cli"));
|
|
329
|
+
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, "antigravity-cli"), cwd);
|
|
283
330
|
return resolved.cfg.disabled ? "" : `${brandWord()} \xB7 ${resolved.bankId}`;
|
|
284
331
|
}
|
|
285
332
|
async function main() {
|