@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/grok-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/hindsight-seed.js
CHANGED
|
@@ -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";
|
|
@@ -47,8 +47,106 @@ function seedControl(command2, args) {
|
|
|
47
47
|
return { ok: false, message: "usage: hindsight-seed seed --repo <dir>" };
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// src/core/bank.ts
|
|
51
|
+
import { execFileSync } from "child_process";
|
|
52
|
+
import { existsSync } from "fs";
|
|
53
|
+
import { homedir } from "os";
|
|
54
|
+
import { basename, dirname as dirname2, join as join2, normalize, sep } from "path";
|
|
55
|
+
|
|
56
|
+
// src/core/template.ts
|
|
57
|
+
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
58
|
+
function applyTemplate(template, resolvers, what) {
|
|
59
|
+
return template.replace(PLACEHOLDER, (_, name) => {
|
|
60
|
+
const resolve = resolvers[name];
|
|
61
|
+
if (!resolve) {
|
|
62
|
+
console.error(
|
|
63
|
+
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
64
|
+
);
|
|
65
|
+
return "unknown";
|
|
66
|
+
}
|
|
67
|
+
return resolve();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/core/bank.ts
|
|
72
|
+
var DEFAULT_BANK_NAME = "coding";
|
|
73
|
+
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
74
|
+
function getProjectRootFromGit(directory) {
|
|
75
|
+
if (!directory) return null;
|
|
76
|
+
try {
|
|
77
|
+
const commonDir = execFileSync(
|
|
78
|
+
"git",
|
|
79
|
+
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
80
|
+
{ cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
|
|
81
|
+
).trim();
|
|
82
|
+
if (!commonDir) return null;
|
|
83
|
+
return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
|
|
89
|
+
function nearestExistingDir(directory) {
|
|
90
|
+
let current = directory;
|
|
91
|
+
while (current) {
|
|
92
|
+
if (existsSync(current)) return current;
|
|
93
|
+
const parent = dirname2(current);
|
|
94
|
+
if (parent === current) return "";
|
|
95
|
+
current = parent;
|
|
96
|
+
}
|
|
97
|
+
return "";
|
|
98
|
+
}
|
|
99
|
+
function dirName(directory) {
|
|
100
|
+
return directory && basename(directory) || "unknown";
|
|
101
|
+
}
|
|
102
|
+
function gitProjectName(directory, resolveWorktrees) {
|
|
103
|
+
if (resolveWorktrees) {
|
|
104
|
+
const candidates = [
|
|
105
|
+
nearestExistingDir(directory),
|
|
106
|
+
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
107
|
+
];
|
|
108
|
+
for (const candidate of candidates) {
|
|
109
|
+
const root = candidate ? getProjectRootFromGit(candidate) : null;
|
|
110
|
+
if (root) return basename(root);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return dirName(directory);
|
|
114
|
+
}
|
|
115
|
+
function configuredDir(dir) {
|
|
116
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join2(homedir(), dir.slice(1)) : dir;
|
|
117
|
+
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
118
|
+
}
|
|
119
|
+
function isWithin(directory, configured) {
|
|
120
|
+
return directory === configured || directory.startsWith(configured + sep);
|
|
121
|
+
}
|
|
122
|
+
function mapLookup(map, directory) {
|
|
123
|
+
const cwd = normalize(directory);
|
|
124
|
+
let best;
|
|
125
|
+
for (const [dir, bank] of Object.entries(map)) {
|
|
126
|
+
const p = configuredDir(dir);
|
|
127
|
+
if (isWithin(cwd, p)) {
|
|
128
|
+
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return best?.bank;
|
|
132
|
+
}
|
|
133
|
+
function deriveBankId(config, directory, harness = "coding") {
|
|
134
|
+
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
135
|
+
if (mapped) return mapped;
|
|
136
|
+
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
137
|
+
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
138
|
+
const resolvers = {
|
|
139
|
+
harness: () => harness,
|
|
140
|
+
project: () => dirName(directory),
|
|
141
|
+
gitProject: () => gitProjectName(directory, config.resolveWorktrees ?? true),
|
|
142
|
+
channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
|
|
143
|
+
user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
|
|
144
|
+
};
|
|
145
|
+
return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
146
|
+
}
|
|
147
|
+
|
|
50
148
|
// src/core/config.ts
|
|
51
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
149
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join3(homedir2(), ".hindsight", "coding-agent.json");
|
|
52
150
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
53
151
|
var DEFAULT_DAEMON_IDLE_TIMEOUT = 300;
|
|
54
152
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
@@ -72,6 +170,9 @@ function resolveConfig(raw = {}) {
|
|
|
72
170
|
bankIdTemplate: raw.bankIdTemplate,
|
|
73
171
|
mapPathToBank: raw.mapPathToBank,
|
|
74
172
|
resolveWorktrees: raw.resolveWorktrees,
|
|
173
|
+
optInOnly: raw.optInOnly ?? false,
|
|
174
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
175
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
75
176
|
harness: raw.harness ?? "opencode",
|
|
76
177
|
disabled: raw.disabled ?? false,
|
|
77
178
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -132,6 +233,8 @@ var ENV_KEYS = {
|
|
|
132
233
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
133
234
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
134
235
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
236
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
237
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
135
238
|
harness: "HINDSIGHT_HARNESS",
|
|
136
239
|
disabled: "HINDSIGHT_DISABLED",
|
|
137
240
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -154,13 +257,14 @@ var ENV_KEYS = {
|
|
|
154
257
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
155
258
|
"dynamicBankId",
|
|
156
259
|
"resolveWorktrees",
|
|
260
|
+
"optInOnly",
|
|
157
261
|
"disabled",
|
|
158
262
|
"retainSessions",
|
|
159
263
|
"autoReflect",
|
|
160
264
|
"autoSeed",
|
|
161
265
|
"codebaseSurvey"
|
|
162
266
|
]);
|
|
163
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
267
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
164
268
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
165
269
|
"apiPort",
|
|
166
270
|
"daemonIdleTimeout",
|
|
@@ -199,98 +303,6 @@ function loadConfig(opts = {}) {
|
|
|
199
303
|
return resolveConfig(raw);
|
|
200
304
|
}
|
|
201
305
|
|
|
202
|
-
// src/core/bank.ts
|
|
203
|
-
import { execFileSync } from "child_process";
|
|
204
|
-
import { existsSync } from "fs";
|
|
205
|
-
import { homedir as homedir2 } from "os";
|
|
206
|
-
import { basename, dirname as dirname2, join as join3, normalize, sep } from "path";
|
|
207
|
-
|
|
208
|
-
// src/core/template.ts
|
|
209
|
-
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
210
|
-
function applyTemplate(template, resolvers, what) {
|
|
211
|
-
return template.replace(PLACEHOLDER, (_, name) => {
|
|
212
|
-
const resolve = resolvers[name];
|
|
213
|
-
if (!resolve) {
|
|
214
|
-
console.error(
|
|
215
|
-
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
216
|
-
);
|
|
217
|
-
return "unknown";
|
|
218
|
-
}
|
|
219
|
-
return resolve();
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// src/core/bank.ts
|
|
224
|
-
var DEFAULT_BANK_NAME = "coding";
|
|
225
|
-
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
226
|
-
function getProjectRootFromGit(directory) {
|
|
227
|
-
if (!directory) return null;
|
|
228
|
-
try {
|
|
229
|
-
const commonDir = execFileSync(
|
|
230
|
-
"git",
|
|
231
|
-
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
232
|
-
{ cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
|
|
233
|
-
).trim();
|
|
234
|
-
if (!commonDir) return null;
|
|
235
|
-
return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
|
|
236
|
-
} catch {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
|
|
241
|
-
function nearestExistingDir(directory) {
|
|
242
|
-
let current = directory;
|
|
243
|
-
while (current) {
|
|
244
|
-
if (existsSync(current)) return current;
|
|
245
|
-
const parent = dirname2(current);
|
|
246
|
-
if (parent === current) return "";
|
|
247
|
-
current = parent;
|
|
248
|
-
}
|
|
249
|
-
return "";
|
|
250
|
-
}
|
|
251
|
-
function dirName(directory) {
|
|
252
|
-
return directory && basename(directory) || "unknown";
|
|
253
|
-
}
|
|
254
|
-
function gitProjectName(directory, resolveWorktrees) {
|
|
255
|
-
if (resolveWorktrees) {
|
|
256
|
-
const candidates = [
|
|
257
|
-
nearestExistingDir(directory),
|
|
258
|
-
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
259
|
-
];
|
|
260
|
-
for (const candidate of candidates) {
|
|
261
|
-
const root = candidate ? getProjectRootFromGit(candidate) : null;
|
|
262
|
-
if (root) return basename(root);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return dirName(directory);
|
|
266
|
-
}
|
|
267
|
-
function mapLookup(map, directory) {
|
|
268
|
-
const cwd = normalize(directory);
|
|
269
|
-
let best;
|
|
270
|
-
for (const [dir, bank] of Object.entries(map)) {
|
|
271
|
-
const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir2(), dir.slice(1)) : dir;
|
|
272
|
-
const p = normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
273
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
274
|
-
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return best?.bank;
|
|
278
|
-
}
|
|
279
|
-
function deriveBankId(config, directory, harness = "coding") {
|
|
280
|
-
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
281
|
-
if (mapped) return mapped;
|
|
282
|
-
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
283
|
-
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
284
|
-
const resolvers = {
|
|
285
|
-
harness: () => harness,
|
|
286
|
-
project: () => dirName(directory),
|
|
287
|
-
gitProject: () => gitProjectName(directory, config.resolveWorktrees ?? true),
|
|
288
|
-
channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
|
|
289
|
-
user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
|
|
290
|
-
};
|
|
291
|
-
return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
292
|
-
}
|
|
293
|
-
|
|
294
306
|
// src/hindsight-seed.ts
|
|
295
307
|
function arg(name) {
|
|
296
308
|
const i = process.argv.indexOf(`--${name}`);
|
package/dist/index.js
CHANGED
|
@@ -75,18 +75,32 @@ function gitProjectName(directory, resolveWorktrees) {
|
|
|
75
75
|
}
|
|
76
76
|
return dirName(directory);
|
|
77
77
|
}
|
|
78
|
+
function configuredDir(dir) {
|
|
79
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join(homedir(), dir.slice(1)) : dir;
|
|
80
|
+
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
81
|
+
}
|
|
82
|
+
function isWithin(directory, configured) {
|
|
83
|
+
return directory === configured || directory.startsWith(configured + sep);
|
|
84
|
+
}
|
|
78
85
|
function mapLookup(map3, directory) {
|
|
79
86
|
const cwd = normalize(directory);
|
|
80
87
|
let best;
|
|
81
88
|
for (const [dir, bank] of Object.entries(map3)) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
89
|
+
const p = configuredDir(dir);
|
|
90
|
+
if (isWithin(cwd, p)) {
|
|
85
91
|
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
return best?.bank;
|
|
89
95
|
}
|
|
96
|
+
function isOptedIn(config3, directory) {
|
|
97
|
+
if (!config3.optInOnly) return true;
|
|
98
|
+
if (!directory) return false;
|
|
99
|
+
const cwd = normalize(directory);
|
|
100
|
+
if ((config3.optInPaths ?? []).some((dir) => dir && isWithin(cwd, configuredDir(dir))))
|
|
101
|
+
return true;
|
|
102
|
+
return Boolean(config3.mapPathToBank && mapLookup(config3.mapPathToBank, directory));
|
|
103
|
+
}
|
|
90
104
|
function deriveBankId(config3, directory, harness = "coding") {
|
|
91
105
|
const mapped = directory && config3.mapPathToBank ? mapLookup(config3.mapPathToBank, directory) : void 0;
|
|
92
106
|
if (mapped) return mapped;
|
|
@@ -164,6 +178,9 @@ function resolveConfig(raw = {}) {
|
|
|
164
178
|
bankIdTemplate: raw.bankIdTemplate,
|
|
165
179
|
mapPathToBank: raw.mapPathToBank,
|
|
166
180
|
resolveWorktrees: raw.resolveWorktrees,
|
|
181
|
+
optInOnly: raw.optInOnly ?? false,
|
|
182
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
183
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
167
184
|
harness: raw.harness ?? "opencode",
|
|
168
185
|
disabled: raw.disabled ?? false,
|
|
169
186
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -224,6 +241,8 @@ var ENV_KEYS = {
|
|
|
224
241
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
225
242
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
226
243
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
244
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
245
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
227
246
|
harness: "HINDSIGHT_HARNESS",
|
|
228
247
|
disabled: "HINDSIGHT_DISABLED",
|
|
229
248
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -246,13 +265,14 @@ var ENV_KEYS = {
|
|
|
246
265
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
247
266
|
"dynamicBankId",
|
|
248
267
|
"resolveWorktrees",
|
|
268
|
+
"optInOnly",
|
|
249
269
|
"disabled",
|
|
250
270
|
"retainSessions",
|
|
251
271
|
"autoReflect",
|
|
252
272
|
"autoSeed",
|
|
253
273
|
"codebaseSurvey"
|
|
254
274
|
]);
|
|
255
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
275
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
256
276
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
257
277
|
"apiPort",
|
|
258
278
|
"daemonIdleTimeout",
|
|
@@ -296,9 +316,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
296
316
|
"mapPathToBank",
|
|
297
317
|
"dynamicBankId",
|
|
298
318
|
"resolveWorktrees",
|
|
319
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
320
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
321
|
+
"optInOnly",
|
|
322
|
+
"optInPaths",
|
|
299
323
|
"harness"
|
|
300
324
|
];
|
|
301
|
-
function applyBankConfig(cfg, resolvedId) {
|
|
325
|
+
function applyBankConfig(cfg, resolvedId, directory) {
|
|
326
|
+
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
327
|
+
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
302
328
|
const section = cfg.banks[resolvedId];
|
|
303
329
|
if (!section) return { cfg, bankId: resolvedId };
|
|
304
330
|
const safe = { ...section };
|
|
@@ -29306,7 +29332,11 @@ function createPluginEntry(harness) {
|
|
|
29306
29332
|
const projectDir = resolveProjectDirectory(input);
|
|
29307
29333
|
let cfg = loadConfig({ harness });
|
|
29308
29334
|
if (cfg.disabled) return {};
|
|
29309
|
-
const resolved = applyBankConfig(
|
|
29335
|
+
const resolved = applyBankConfig(
|
|
29336
|
+
cfg,
|
|
29337
|
+
deriveBankId(cfg, projectDir || process.cwd(), harness),
|
|
29338
|
+
projectDir || process.cwd()
|
|
29339
|
+
);
|
|
29310
29340
|
cfg = resolved.cfg;
|
|
29311
29341
|
const bankId = resolved.bankId;
|
|
29312
29342
|
if (cfg.disabled) return {};
|
package/dist/kilo.js
CHANGED
|
@@ -75,18 +75,32 @@ function gitProjectName(directory, resolveWorktrees) {
|
|
|
75
75
|
}
|
|
76
76
|
return dirName(directory);
|
|
77
77
|
}
|
|
78
|
+
function configuredDir(dir) {
|
|
79
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join(homedir(), dir.slice(1)) : dir;
|
|
80
|
+
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
81
|
+
}
|
|
82
|
+
function isWithin(directory, configured) {
|
|
83
|
+
return directory === configured || directory.startsWith(configured + sep);
|
|
84
|
+
}
|
|
78
85
|
function mapLookup(map3, directory) {
|
|
79
86
|
const cwd = normalize(directory);
|
|
80
87
|
let best;
|
|
81
88
|
for (const [dir, bank] of Object.entries(map3)) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
89
|
+
const p = configuredDir(dir);
|
|
90
|
+
if (isWithin(cwd, p)) {
|
|
85
91
|
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
return best?.bank;
|
|
89
95
|
}
|
|
96
|
+
function isOptedIn(config3, directory) {
|
|
97
|
+
if (!config3.optInOnly) return true;
|
|
98
|
+
if (!directory) return false;
|
|
99
|
+
const cwd = normalize(directory);
|
|
100
|
+
if ((config3.optInPaths ?? []).some((dir) => dir && isWithin(cwd, configuredDir(dir))))
|
|
101
|
+
return true;
|
|
102
|
+
return Boolean(config3.mapPathToBank && mapLookup(config3.mapPathToBank, directory));
|
|
103
|
+
}
|
|
90
104
|
function deriveBankId(config3, directory, harness = "coding") {
|
|
91
105
|
const mapped = directory && config3.mapPathToBank ? mapLookup(config3.mapPathToBank, directory) : void 0;
|
|
92
106
|
if (mapped) return mapped;
|
|
@@ -164,6 +178,9 @@ function resolveConfig(raw = {}) {
|
|
|
164
178
|
bankIdTemplate: raw.bankIdTemplate,
|
|
165
179
|
mapPathToBank: raw.mapPathToBank,
|
|
166
180
|
resolveWorktrees: raw.resolveWorktrees,
|
|
181
|
+
optInOnly: raw.optInOnly ?? false,
|
|
182
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
183
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
167
184
|
harness: raw.harness ?? "opencode",
|
|
168
185
|
disabled: raw.disabled ?? false,
|
|
169
186
|
retainSessions: raw.retainSessions ?? true,
|
|
@@ -224,6 +241,8 @@ var ENV_KEYS = {
|
|
|
224
241
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
225
242
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
226
243
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
244
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
245
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
227
246
|
harness: "HINDSIGHT_HARNESS",
|
|
228
247
|
disabled: "HINDSIGHT_DISABLED",
|
|
229
248
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
@@ -246,13 +265,14 @@ var ENV_KEYS = {
|
|
|
246
265
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
247
266
|
"dynamicBankId",
|
|
248
267
|
"resolveWorktrees",
|
|
268
|
+
"optInOnly",
|
|
249
269
|
"disabled",
|
|
250
270
|
"retainSessions",
|
|
251
271
|
"autoReflect",
|
|
252
272
|
"autoSeed",
|
|
253
273
|
"codebaseSurvey"
|
|
254
274
|
]);
|
|
255
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
275
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
256
276
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
257
277
|
"apiPort",
|
|
258
278
|
"daemonIdleTimeout",
|
|
@@ -296,9 +316,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
296
316
|
"mapPathToBank",
|
|
297
317
|
"dynamicBankId",
|
|
298
318
|
"resolveWorktrees",
|
|
319
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
320
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
321
|
+
"optInOnly",
|
|
322
|
+
"optInPaths",
|
|
299
323
|
"harness"
|
|
300
324
|
];
|
|
301
|
-
function applyBankConfig(cfg, resolvedId) {
|
|
325
|
+
function applyBankConfig(cfg, resolvedId, directory) {
|
|
326
|
+
if (directory !== void 0 && !isOptedIn(cfg, directory))
|
|
327
|
+
return { cfg: { ...cfg, disabled: true }, bankId: resolvedId };
|
|
302
328
|
const section = cfg.banks[resolvedId];
|
|
303
329
|
if (!section) return { cfg, bankId: resolvedId };
|
|
304
330
|
const safe = { ...section };
|
|
@@ -29306,7 +29332,11 @@ function createPluginEntry(harness) {
|
|
|
29306
29332
|
const projectDir = resolveProjectDirectory(input);
|
|
29307
29333
|
let cfg = loadConfig({ harness });
|
|
29308
29334
|
if (cfg.disabled) return {};
|
|
29309
|
-
const resolved = applyBankConfig(
|
|
29335
|
+
const resolved = applyBankConfig(
|
|
29336
|
+
cfg,
|
|
29337
|
+
deriveBankId(cfg, projectDir || process.cwd(), harness),
|
|
29338
|
+
projectDir || process.cwd()
|
|
29339
|
+
);
|
|
29310
29340
|
cfg = resolved.cfg;
|
|
29311
29341
|
const bankId = resolved.bankId;
|
|
29312
29342
|
if (cfg.disabled) return {};
|