@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/README.md
CHANGED
|
@@ -277,6 +277,32 @@ The map-valued settings (`mapPathToBank`, `harnesses`, `banks`, `retainMetadata`
|
|
|
277
277
|
per-key branching doesn't survive flattening into one variable. `maxParallelRetains` is available
|
|
278
278
|
as `HINDSIGHT_MAX_PARALLEL_RETAINS` for containers and CI.
|
|
279
279
|
|
|
280
|
+
### Opt-in only
|
|
281
|
+
|
|
282
|
+
By default every project gets memory — that is what makes the plugin zero-setup. If you would
|
|
283
|
+
rather nothing be remembered until you say so, turn memory off everywhere and name the projects
|
|
284
|
+
that may use it:
|
|
285
|
+
|
|
286
|
+
```jsonc
|
|
287
|
+
{
|
|
288
|
+
"optInOnly": true,
|
|
289
|
+
"optInPaths": ["~/work/client-x", "~/oss"],
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Anything outside those paths is **inert**: no bank is created, nothing is retained, no seed runs,
|
|
294
|
+
and the agent behaves exactly as it would without the plugin. Approving costs nothing else —
|
|
295
|
+
`optInPaths` says _which projects_, not _which bank_, so an approved repo keeps its usual
|
|
296
|
+
`coding-agent::{gitProject}` name. Paths are prefixes, so approving `~/work` approves every repo
|
|
297
|
+
under it while each still gets its own bank.
|
|
298
|
+
|
|
299
|
+
A `mapPathToBank` entry counts as opted in too, since routing a path to a named bank already
|
|
300
|
+
declares that project. A bare `bankId` does not: it names a bank rather than a project, so it
|
|
301
|
+
cannot say which work may be remembered, and a privacy switch has to fail closed.
|
|
302
|
+
|
|
303
|
+
There is no per-repo opt-in file, for the same reason there is no repo-carried config at all: a
|
|
304
|
+
cloned repository must not be able to turn memory on.
|
|
305
|
+
|
|
280
306
|
There is deliberately no repo-carried config file — per-repo bank routing is `mapPathToBank`,
|
|
281
307
|
per-agent differences are `harnesses.<name>`.
|
|
282
308
|
|
|
@@ -303,6 +329,8 @@ hook by Codex...), so one shared config serves several agents side by side:
|
|
|
303
329
|
| `dynamicBankId` | dynamic iff no `bankId` | force dynamic (`true`) or static (`false`) resolution |
|
|
304
330
|
| `bankIdTemplate` | `"coding-agent::{gitProject}"` | dynamic bank id format; the default makes every agent share one bank per repo |
|
|
305
331
|
| `mapPathToBank` | — | absolute path → bank; **longest prefix wins**; overrides everything |
|
|
332
|
+
| `optInOnly` | `false` | run memory ONLY in opted-in projects — everything else is inert, with no bank created; see [Opt-in only](#opt-in-only) |
|
|
333
|
+
| `optInPaths` | — | directories opted in, matched as prefixes with `~` expanded; each repo beneath keeps its own dynamic bank |
|
|
306
334
|
| `resolveWorktrees` | `true` | `{gitProject}`: linked worktrees share the main repo's bank |
|
|
307
335
|
| `retainTags` | — | extra tags on every document written by the integration, e.g. `["project:{gitProject}"]` — see **Recording where a memory came from** below |
|
|
308
336
|
| `retainMetadata` | — | extra metadata on every document written by the integration, e.g. `{"repo": "{gitProject}"}` |
|
package/dist/antigravity-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,
|
|
@@ -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,6 +142,9 @@ 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,
|
|
@@ -96,6 +205,8 @@ 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",
|
|
@@ -118,13 +229,14 @@ 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",
|
|
@@ -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,98 +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 { existsSync } from "fs";
|
|
196
|
-
import { homedir as homedir2 } from "os";
|
|
197
|
-
import { basename, dirname as dirname2, join as join3, normalize, sep } from "path";
|
|
198
|
-
|
|
199
|
-
// src/core/template.ts
|
|
200
|
-
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
201
|
-
function applyTemplate(template, resolvers, what) {
|
|
202
|
-
return template.replace(PLACEHOLDER, (_, name) => {
|
|
203
|
-
const resolve = resolvers[name];
|
|
204
|
-
if (!resolve) {
|
|
205
|
-
console.error(
|
|
206
|
-
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
207
|
-
);
|
|
208
|
-
return "unknown";
|
|
209
|
-
}
|
|
210
|
-
return resolve();
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// src/core/bank.ts
|
|
215
|
-
var DEFAULT_BANK_NAME = "coding";
|
|
216
|
-
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
217
|
-
function getProjectRootFromGit(directory) {
|
|
218
|
-
if (!directory) return null;
|
|
219
|
-
try {
|
|
220
|
-
const commonDir = execFileSync(
|
|
221
|
-
"git",
|
|
222
|
-
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
223
|
-
{ cwd: directory, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], timeout: 1e3 }
|
|
224
|
-
).trim();
|
|
225
|
-
if (!commonDir) return null;
|
|
226
|
-
return basename(commonDir) === ".git" ? dirname2(commonDir) : commonDir;
|
|
227
|
-
} catch {
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
|
|
232
|
-
function nearestExistingDir(directory) {
|
|
233
|
-
let current = directory;
|
|
234
|
-
while (current) {
|
|
235
|
-
if (existsSync(current)) return current;
|
|
236
|
-
const parent = dirname2(current);
|
|
237
|
-
if (parent === current) return "";
|
|
238
|
-
current = parent;
|
|
239
|
-
}
|
|
240
|
-
return "";
|
|
241
|
-
}
|
|
242
|
-
function dirName(directory) {
|
|
243
|
-
return directory && basename(directory) || "unknown";
|
|
244
|
-
}
|
|
245
|
-
function gitProjectName(directory, resolveWorktrees) {
|
|
246
|
-
if (resolveWorktrees) {
|
|
247
|
-
const candidates = [
|
|
248
|
-
nearestExistingDir(directory),
|
|
249
|
-
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
250
|
-
];
|
|
251
|
-
for (const candidate of candidates) {
|
|
252
|
-
const root = candidate ? getProjectRootFromGit(candidate) : null;
|
|
253
|
-
if (root) return basename(root);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return dirName(directory);
|
|
257
|
-
}
|
|
258
|
-
function mapLookup(map, directory) {
|
|
259
|
-
const cwd = normalize(directory);
|
|
260
|
-
let best;
|
|
261
|
-
for (const [dir, bank] of Object.entries(map)) {
|
|
262
|
-
const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir2(), dir.slice(1)) : dir;
|
|
263
|
-
const p = normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
264
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
265
|
-
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return best?.bank;
|
|
269
|
-
}
|
|
270
|
-
function deriveBankId(config, directory, harness = "coding") {
|
|
271
|
-
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
272
|
-
if (mapped) return mapped;
|
|
273
|
-
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
274
|
-
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
275
|
-
const resolvers = {
|
|
276
|
-
harness: () => harness,
|
|
277
|
-
project: () => dirName(directory),
|
|
278
|
-
gitProject: () => gitProjectName(directory, config.resolveWorktrees ?? true),
|
|
279
|
-
channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
|
|
280
|
-
user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
|
|
281
|
-
};
|
|
282
|
-
return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
283
|
-
}
|
|
284
|
-
|
|
285
311
|
// src/core/brand.ts
|
|
286
312
|
function brandWord() {
|
|
287
313
|
const start = [0, 116, 217];
|
|
@@ -300,7 +326,7 @@ function brandWord() {
|
|
|
300
326
|
function buildAntigravityStatusLine(state, cfg) {
|
|
301
327
|
const cwd = state.cwd || state.workspace?.current_dir;
|
|
302
328
|
if (!cwd) return brandWord();
|
|
303
|
-
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, "antigravity-cli"));
|
|
329
|
+
const resolved = applyBankConfig(cfg, deriveBankId(cfg, cwd, "antigravity-cli"), cwd);
|
|
304
330
|
return resolved.cfg.disabled ? "" : `${brandWord()} \xB7 ${resolved.bankId}`;
|
|
305
331
|
}
|
|
306
332
|
async function main() {
|