@vectorize-io/hindsight-coding-agents 0.3.0 → 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 +28 -0
- package/dist/antigravity-hook.js +32 -6
- package/dist/antigravity-statusline.js +124 -98
- package/dist/antigravity-stop-hook.js +32 -6
- package/dist/claude-hook.js +32 -6
- package/dist/claude-sessionstart-hook.js +32 -6
- package/dist/claude-stop-hook.js +32 -6
- package/dist/cline.js +131 -101
- package/dist/codex-hook.js +32 -6
- package/dist/codex-sessionstart-hook.js +32 -6
- package/dist/codex-stop-hook.js +32 -6
- package/dist/copilot-hook.js +32 -6
- package/dist/copilot-sessionstart-hook.js +32 -6
- package/dist/copilot-stop-hook.js +32 -6
- package/dist/cursor-hook.js +32 -6
- package/dist/cursor-sessionstart-hook.js +32 -6
- package/dist/cursor-stop-hook.js +32 -6
- package/dist/daemon-start.js +24 -12
- package/dist/deepen.js +32 -6
- package/dist/devin-hook.js +32 -6
- package/dist/devin-sessionstart-hook.js +32 -6
- package/dist/devin-stop-hook.js +32 -6
- package/dist/grok-hook.js +32 -6
- package/dist/grok-sessionstart-hook.js +32 -6
- package/dist/grok-stop-hook.js +32 -6
- package/dist/hindsight-seed.js +108 -96
- package/dist/index.js +36 -6
- package/dist/kilo.js +36 -6
- package/dist/mcp-server.js +127 -101
- package/dist/prime-agent.js +32 -6
- package/dist/status.js +31 -5
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -160,6 +174,9 @@ function resolveConfig(raw = {}) {
|
|
|
160
174
|
bankIdTemplate: raw.bankIdTemplate,
|
|
161
175
|
mapPathToBank: raw.mapPathToBank,
|
|
162
176
|
resolveWorktrees: raw.resolveWorktrees,
|
|
177
|
+
optInOnly: raw.optInOnly ?? false,
|
|
178
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
179
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
163
180
|
harness: raw.harness ?? "opencode",
|
|
164
181
|
disabled: raw.disabled ?? false,
|
|
165
182
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -220,6 +237,8 @@ var ENV_KEYS = {
|
|
|
220
237
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
221
238
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
222
239
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
240
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
241
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
223
242
|
harness: "HINDSIGHT_HARNESS",
|
|
224
243
|
disabled: "HINDSIGHT_DISABLED",
|
|
225
244
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -242,13 +261,14 @@ var ENV_KEYS = {
|
|
|
242
261
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
243
262
|
"dynamicBankId",
|
|
244
263
|
"resolveWorktrees",
|
|
264
|
+
"optInOnly",
|
|
245
265
|
"disabled",
|
|
246
266
|
"retainSessions",
|
|
247
267
|
"autoReflect",
|
|
248
268
|
"autoSeed",
|
|
249
269
|
"codebaseSurvey"
|
|
250
270
|
]);
|
|
251
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
271
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
252
272
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
253
273
|
"apiPort",
|
|
254
274
|
"daemonIdleTimeout",
|
|
@@ -292,9 +312,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
292
312
|
"mapPathToBank",
|
|
293
313
|
"dynamicBankId",
|
|
294
314
|
"resolveWorktrees",
|
|
315
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
316
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
317
|
+
"optInOnly",
|
|
318
|
+
"optInPaths",
|
|
295
319
|
"harness"
|
|
296
320
|
];
|
|
297
|
-
function applyBankConfig(cfg, resolvedId) {
|
|
321
|
+
function applyBankConfig(cfg, resolvedId, directory) {
|
|
322
|
+
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
323
|
+
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
298
324
|
const section = cfg.banks[resolvedId];
|
|
299
325
|
if (!section) return { cfg, bankId: resolvedId };
|
|
300
326
|
const safe = { ...section };
|
|
@@ -1759,7 +1785,7 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
|
|
|
1759
1785
|
setLogLevel(cfg.logLevel);
|
|
1760
1786
|
syncCompanionSkill(harness);
|
|
1761
1787
|
if (cfg.disabled) return;
|
|
1762
|
-
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, harness));
|
|
1788
|
+
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, harness), cwd);
|
|
1763
1789
|
cfg = resolved.cfg;
|
|
1764
1790
|
const bankId = resolved.bankId;
|
|
1765
1791
|
if (cfg.disabled) return;
|
package/dist/claude-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 };
|
|
@@ -1507,7 +1533,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1507
1533
|
setLogLevel(cfg.logLevel);
|
|
1508
1534
|
if (cfg.disabled) return;
|
|
1509
1535
|
if (!transcriptPath) return;
|
|
1510
|
-
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, spec.harness));
|
|
1536
|
+
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, spec.harness), cwd);
|
|
1511
1537
|
cfg = resolved.cfg;
|
|
1512
1538
|
const bankId = resolved.bankId;
|
|
1513
1539
|
if (cfg.disabled) return;
|
package/dist/cline.js
CHANGED
|
@@ -6,8 +6,8 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/core/config.ts
|
|
8
8
|
import { readFileSync } from "fs";
|
|
9
|
-
import { homedir } from "os";
|
|
10
|
-
import { join as
|
|
9
|
+
import { homedir as homedir2 } from "os";
|
|
10
|
+
import { join as join3 } from "path";
|
|
11
11
|
|
|
12
12
|
// src/core/seed.ts
|
|
13
13
|
import { spawn as realSpawn } from "child_process";
|
|
@@ -41,8 +41,117 @@ function startBackgroundSeed(repoDir, opts = {}) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// src/core/bank.ts
|
|
45
|
+
import { execFileSync } from "child_process";
|
|
46
|
+
import { existsSync } from "fs";
|
|
47
|
+
import { homedir } from "os";
|
|
48
|
+
import { basename, dirname as dirname2, join as join2, normalize, sep } from "path";
|
|
49
|
+
|
|
50
|
+
// src/core/template.ts
|
|
51
|
+
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
52
|
+
function applyTemplate(template, resolvers, what) {
|
|
53
|
+
return template.replace(PLACEHOLDER, (_, name) => {
|
|
54
|
+
const resolve2 = resolvers[name];
|
|
55
|
+
if (!resolve2) {
|
|
56
|
+
console.error(
|
|
57
|
+
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
58
|
+
);
|
|
59
|
+
return "unknown";
|
|
60
|
+
}
|
|
61
|
+
return resolve2();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/core/bank.ts
|
|
66
|
+
var DEFAULT_BANK_NAME = "coding";
|
|
67
|
+
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
68
|
+
function getProjectRootFromGit(directory) {
|
|
69
|
+
if (!directory) return null;
|
|
70
|
+
try {
|
|
71
|
+
const commonDir = execFileSync(
|
|
72
|
+
"git",
|
|
73
|
+
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
74
|
+
{ cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
|
|
75
|
+
).trim();
|
|
76
|
+
if (!commonDir) return null;
|
|
77
|
+
return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function projectNameOf(directory) {
|
|
83
|
+
return gitProjectName(directory, true);
|
|
84
|
+
}
|
|
85
|
+
var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
|
|
86
|
+
function nearestExistingDir(directory) {
|
|
87
|
+
let current2 = directory;
|
|
88
|
+
while (current2) {
|
|
89
|
+
if (existsSync(current2)) return current2;
|
|
90
|
+
const parent = dirname2(current2);
|
|
91
|
+
if (parent === current2) return "";
|
|
92
|
+
current2 = parent;
|
|
93
|
+
}
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
function dirName(directory) {
|
|
97
|
+
return directory && basename(directory) || "unknown";
|
|
98
|
+
}
|
|
99
|
+
function gitProjectName(directory, resolveWorktrees) {
|
|
100
|
+
if (resolveWorktrees) {
|
|
101
|
+
const candidates = [
|
|
102
|
+
nearestExistingDir(directory),
|
|
103
|
+
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
104
|
+
];
|
|
105
|
+
for (const candidate of candidates) {
|
|
106
|
+
const root = candidate ? getProjectRootFromGit(candidate) : null;
|
|
107
|
+
if (root) return basename(root);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return dirName(directory);
|
|
111
|
+
}
|
|
112
|
+
function configuredDir(dir) {
|
|
113
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join2(homedir(), dir.slice(1)) : dir;
|
|
114
|
+
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
115
|
+
}
|
|
116
|
+
function isWithin(directory, configured) {
|
|
117
|
+
return directory === configured || directory.startsWith(configured + sep);
|
|
118
|
+
}
|
|
119
|
+
function mapLookup(map2, directory) {
|
|
120
|
+
const cwd = normalize(directory);
|
|
121
|
+
let best;
|
|
122
|
+
for (const [dir, bank] of Object.entries(map2)) {
|
|
123
|
+
const p = configuredDir(dir);
|
|
124
|
+
if (isWithin(cwd, p)) {
|
|
125
|
+
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return best?.bank;
|
|
129
|
+
}
|
|
130
|
+
function isOptedIn(config2, directory) {
|
|
131
|
+
if (!config2.optInOnly) return true;
|
|
132
|
+
if (!directory) return false;
|
|
133
|
+
const cwd = normalize(directory);
|
|
134
|
+
if ((config2.optInPaths ?? []).some((dir) => dir && isWithin(cwd, configuredDir(dir))))
|
|
135
|
+
return true;
|
|
136
|
+
return Boolean(config2.mapPathToBank && mapLookup(config2.mapPathToBank, directory));
|
|
137
|
+
}
|
|
138
|
+
function deriveBankId(config2, directory, harness = "coding") {
|
|
139
|
+
const mapped = directory && config2.mapPathToBank ? mapLookup(config2.mapPathToBank, directory) : void 0;
|
|
140
|
+
if (mapped) return mapped;
|
|
141
|
+
const dynamic = config2.dynamicBankId ?? !config2.bankId;
|
|
142
|
+
if (!dynamic) return config2.bankId || DEFAULT_BANK_NAME;
|
|
143
|
+
const resolvers = {
|
|
144
|
+
harness: () => harness,
|
|
145
|
+
project: () => dirName(directory),
|
|
146
|
+
gitProject: () => gitProjectName(directory, config2.resolveWorktrees ?? true),
|
|
147
|
+
channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
|
|
148
|
+
user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
|
|
149
|
+
};
|
|
150
|
+
return applyTemplate(config2.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
151
|
+
}
|
|
152
|
+
|
|
44
153
|
// src/core/config.ts
|
|
45
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
154
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
|
|
46
155
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
47
156
|
var DEFAULT_DAEMON_IDLE_TIMEOUT = 300;
|
|
48
157
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
@@ -66,6 +175,9 @@ function resolveConfig(raw = {}) {
|
|
|
66
175
|
bankIdTemplate: raw.bankIdTemplate,
|
|
67
176
|
mapPathToBank: raw.mapPathToBank,
|
|
68
177
|
resolveWorktrees: raw.resolveWorktrees,
|
|
178
|
+
optInOnly: raw.optInOnly ?? false,
|
|
179
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
180
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
69
181
|
harness: raw.harness ?? "opencode",
|
|
70
182
|
disabled: raw.disabled ?? false,
|
|
71
183
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -126,6 +238,8 @@ var ENV_KEYS = {
|
|
|
126
238
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
127
239
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
128
240
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
241
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
242
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
129
243
|
harness: "HINDSIGHT_HARNESS",
|
|
130
244
|
disabled: "HINDSIGHT_DISABLED",
|
|
131
245
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -148,13 +262,14 @@ var ENV_KEYS = {
|
|
|
148
262
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
149
263
|
"dynamicBankId",
|
|
150
264
|
"resolveWorktrees",
|
|
265
|
+
"optInOnly",
|
|
151
266
|
"disabled",
|
|
152
267
|
"retainSessions",
|
|
153
268
|
"autoReflect",
|
|
154
269
|
"autoSeed",
|
|
155
270
|
"codebaseSurvey"
|
|
156
271
|
]);
|
|
157
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
272
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
158
273
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
159
274
|
"apiPort",
|
|
160
275
|
"daemonIdleTimeout",
|
|
@@ -198,9 +313,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
198
313
|
"mapPathToBank",
|
|
199
314
|
"dynamicBankId",
|
|
200
315
|
"resolveWorktrees",
|
|
316
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
317
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
318
|
+
"optInOnly",
|
|
319
|
+
"optInPaths",
|
|
201
320
|
"harness"
|
|
202
321
|
];
|
|
203
|
-
function applyBankConfig(cfg, resolvedId) {
|
|
322
|
+
function applyBankConfig(cfg, resolvedId, directory) {
|
|
323
|
+
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
324
|
+
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
204
325
|
const section = cfg.banks[resolvedId];
|
|
205
326
|
if (!section) return { cfg, bankId: resolvedId };
|
|
206
327
|
const safe = { ...section };
|
|
@@ -220,101 +341,6 @@ function resolvePartial(cfg, patch) {
|
|
|
220
341
|
return out;
|
|
221
342
|
}
|
|
222
343
|
|
|
223
|
-
// src/core/bank.ts
|
|
224
|
-
import { execFileSync } from "child_process";
|
|
225
|
-
import { existsSync } from "fs";
|
|
226
|
-
import { homedir as homedir2 } from "os";
|
|
227
|
-
import { basename, dirname as dirname2, join as join3, normalize, sep } from "path";
|
|
228
|
-
|
|
229
|
-
// src/core/template.ts
|
|
230
|
-
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
231
|
-
function applyTemplate(template, resolvers, what) {
|
|
232
|
-
return template.replace(PLACEHOLDER, (_, name) => {
|
|
233
|
-
const resolve2 = resolvers[name];
|
|
234
|
-
if (!resolve2) {
|
|
235
|
-
console.error(
|
|
236
|
-
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
237
|
-
);
|
|
238
|
-
return "unknown";
|
|
239
|
-
}
|
|
240
|
-
return resolve2();
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// src/core/bank.ts
|
|
245
|
-
var DEFAULT_BANK_NAME = "coding";
|
|
246
|
-
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
247
|
-
function getProjectRootFromGit(directory) {
|
|
248
|
-
if (!directory) return null;
|
|
249
|
-
try {
|
|
250
|
-
const commonDir = execFileSync(
|
|
251
|
-
"git",
|
|
252
|
-
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
253
|
-
{ cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
|
|
254
|
-
).trim();
|
|
255
|
-
if (!commonDir) return null;
|
|
256
|
-
return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
|
|
257
|
-
} catch {
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function projectNameOf(directory) {
|
|
262
|
-
return gitProjectName(directory, true);
|
|
263
|
-
}
|
|
264
|
-
var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
|
|
265
|
-
function nearestExistingDir(directory) {
|
|
266
|
-
let current2 = directory;
|
|
267
|
-
while (current2) {
|
|
268
|
-
if (existsSync(current2)) return current2;
|
|
269
|
-
const parent = dirname2(current2);
|
|
270
|
-
if (parent === current2) return "";
|
|
271
|
-
current2 = parent;
|
|
272
|
-
}
|
|
273
|
-
return "";
|
|
274
|
-
}
|
|
275
|
-
function dirName(directory) {
|
|
276
|
-
return directory && basename(directory) || "unknown";
|
|
277
|
-
}
|
|
278
|
-
function gitProjectName(directory, resolveWorktrees) {
|
|
279
|
-
if (resolveWorktrees) {
|
|
280
|
-
const candidates = [
|
|
281
|
-
nearestExistingDir(directory),
|
|
282
|
-
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
283
|
-
];
|
|
284
|
-
for (const candidate of candidates) {
|
|
285
|
-
const root = candidate ? getProjectRootFromGit(candidate) : null;
|
|
286
|
-
if (root) return basename(root);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return dirName(directory);
|
|
290
|
-
}
|
|
291
|
-
function mapLookup(map2, directory) {
|
|
292
|
-
const cwd = normalize(directory);
|
|
293
|
-
let best;
|
|
294
|
-
for (const [dir, bank] of Object.entries(map2)) {
|
|
295
|
-
const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir2(), dir.slice(1)) : dir;
|
|
296
|
-
const p = normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
297
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
298
|
-
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return best?.bank;
|
|
302
|
-
}
|
|
303
|
-
function deriveBankId(config2, directory, harness = "coding") {
|
|
304
|
-
const mapped = directory && config2.mapPathToBank ? mapLookup(config2.mapPathToBank, directory) : void 0;
|
|
305
|
-
if (mapped) return mapped;
|
|
306
|
-
const dynamic = config2.dynamicBankId ?? !config2.bankId;
|
|
307
|
-
if (!dynamic) return config2.bankId || DEFAULT_BANK_NAME;
|
|
308
|
-
const resolvers = {
|
|
309
|
-
harness: () => harness,
|
|
310
|
-
project: () => dirName(directory),
|
|
311
|
-
gitProject: () => gitProjectName(directory, config2.resolveWorktrees ?? true),
|
|
312
|
-
channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
|
|
313
|
-
user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
|
|
314
|
-
};
|
|
315
|
-
return applyTemplate(config2.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
316
|
-
}
|
|
317
|
-
|
|
318
344
|
// src/core/missions.ts
|
|
319
345
|
var GIT_MISSION = "You are ingesting a single git commit: its message and its full diff. Extract the concrete technical DECISION and the CAUSE/INVARIANT it encodes, bound to the specific code entities (functions, methods, files) and behaviors it changes. Preserve exact identifiers, paths, and literal values verbatim. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Capture both WHAT changed and WHY. Issue/PR references (#123, GH-123, PROJ-123) are load-bearing: keep them VERBATIM in the fact text and emit each as an ENTITY, so a later question about that issue or PR retrieves this decision.";
|
|
320
346
|
var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history, newest first. Extract the project's INITIATIVES, FEATURES, ENHANCEMENTS, and notable changes or THEMES over time \u2014 what the project has been working on and how it has evolved. Do NOT extract per-line code detail (there is no diff to draw it from). Group related commits into a coherent initiative/theme where the messages make that clear; preserve exact identifiers and literal values verbatim when quoting a subject line. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY \u2014 they are how future sessions will ask about this work.";
|
|
@@ -16827,7 +16853,11 @@ function createClineHooks(core, configuredSessionId, sessionStart) {
|
|
|
16827
16853
|
function createRuntime(workspaceRoot) {
|
|
16828
16854
|
let cfg = loadConfig({ harness: HARNESS2 });
|
|
16829
16855
|
if (cfg.disabled) return void 0;
|
|
16830
|
-
const resolved = applyBankConfig(
|
|
16856
|
+
const resolved = applyBankConfig(
|
|
16857
|
+
cfg,
|
|
16858
|
+
deriveBankId(cfg, workspaceRoot || process.cwd(), HARNESS2),
|
|
16859
|
+
workspaceRoot || process.cwd()
|
|
16860
|
+
);
|
|
16831
16861
|
cfg = resolved.cfg;
|
|
16832
16862
|
if (cfg.disabled) return void 0;
|
|
16833
16863
|
const client = new HindsightClient({
|
package/dist/codex-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) {
|
|
@@ -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;
|
|
@@ -160,6 +174,9 @@ function resolveConfig(raw = {}) {
|
|
|
160
174
|
bankIdTemplate: raw.bankIdTemplate,
|
|
161
175
|
mapPathToBank: raw.mapPathToBank,
|
|
162
176
|
resolveWorktrees: raw.resolveWorktrees,
|
|
177
|
+
optInOnly: raw.optInOnly ?? false,
|
|
178
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
179
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
163
180
|
harness: raw.harness ?? "opencode",
|
|
164
181
|
disabled: raw.disabled ?? false,
|
|
165
182
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -220,6 +237,8 @@ var ENV_KEYS = {
|
|
|
220
237
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
221
238
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
222
239
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
240
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
241
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
223
242
|
harness: "HINDSIGHT_HARNESS",
|
|
224
243
|
disabled: "HINDSIGHT_DISABLED",
|
|
225
244
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -242,13 +261,14 @@ var ENV_KEYS = {
|
|
|
242
261
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
243
262
|
"dynamicBankId",
|
|
244
263
|
"resolveWorktrees",
|
|
264
|
+
"optInOnly",
|
|
245
265
|
"disabled",
|
|
246
266
|
"retainSessions",
|
|
247
267
|
"autoReflect",
|
|
248
268
|
"autoSeed",
|
|
249
269
|
"codebaseSurvey"
|
|
250
270
|
]);
|
|
251
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
271
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
252
272
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
253
273
|
"apiPort",
|
|
254
274
|
"daemonIdleTimeout",
|
|
@@ -292,9 +312,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
292
312
|
"mapPathToBank",
|
|
293
313
|
"dynamicBankId",
|
|
294
314
|
"resolveWorktrees",
|
|
315
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
316
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
317
|
+
"optInOnly",
|
|
318
|
+
"optInPaths",
|
|
295
319
|
"harness"
|
|
296
320
|
];
|
|
297
|
-
function applyBankConfig(cfg, resolvedId) {
|
|
321
|
+
function applyBankConfig(cfg, resolvedId, directory) {
|
|
322
|
+
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
323
|
+
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
298
324
|
const section = cfg.banks[resolvedId];
|
|
299
325
|
if (!section) return { cfg, bankId: resolvedId };
|
|
300
326
|
const safe = { ...section };
|
|
@@ -1759,7 +1785,7 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
|
|
|
1759
1785
|
setLogLevel(cfg.logLevel);
|
|
1760
1786
|
syncCompanionSkill(harness);
|
|
1761
1787
|
if (cfg.disabled) return;
|
|
1762
|
-
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, harness));
|
|
1788
|
+
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, harness), cwd);
|
|
1763
1789
|
cfg = resolved.cfg;
|
|
1764
1790
|
const bankId = resolved.bankId;
|
|
1765
1791
|
if (cfg.disabled) return;
|