@vectorize-io/hindsight-coding-agents 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -7
- package/dist/antigravity-hook.js +175 -48
- package/dist/antigravity-statusline.js +127 -80
- package/dist/antigravity-stop-hook.js +233 -88
- package/dist/claude-hook.js +175 -48
- package/dist/claude-sessionstart-hook.js +234 -58
- package/dist/claude-stop-hook.js +233 -88
- package/dist/cline.js +351 -167
- package/dist/codex-hook.js +175 -48
- package/dist/codex-sessionstart-hook.js +234 -58
- package/dist/codex-stop-hook.js +233 -88
- package/dist/copilot-hook.js +175 -48
- package/dist/copilot-sessionstart-hook.js +234 -58
- package/dist/copilot-stop-hook.js +233 -88
- package/dist/cursor-hook.js +175 -48
- package/dist/cursor-sessionstart-hook.js +234 -58
- package/dist/cursor-stop-hook.js +233 -88
- package/dist/daemon-start.js +27 -15
- package/dist/deepen.js +688 -497
- package/dist/devin-hook.js +175 -48
- package/dist/devin-sessionstart-hook.js +234 -58
- package/dist/devin-stop-hook.js +233 -88
- package/dist/grok-hook.js +175 -48
- package/dist/grok-sessionstart-hook.js +234 -58
- package/dist/grok-stop-hook.js +233 -88
- package/dist/hindsight-seed.js +111 -78
- package/dist/index.js +282 -98
- package/dist/installer.js +86 -56
- package/dist/kilo.js +282 -98
- package/dist/mcp-server.js +327 -117
- package/dist/prime-agent.js +16900 -0
- package/dist/status.js +143 -36
- package/package.json +6 -1
package/dist/status.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/core/bank.ts
|
|
4
4
|
import { execFileSync } from "child_process";
|
|
5
|
+
import { existsSync } from "fs";
|
|
5
6
|
import { homedir } from "os";
|
|
6
7
|
import { basename, dirname, join, normalize, sep } from "path";
|
|
7
8
|
|
|
@@ -40,25 +41,59 @@ function getProjectRootFromGit(directory) {
|
|
|
40
41
|
function projectNameOf(directory) {
|
|
41
42
|
return gitProjectName(directory, true);
|
|
42
43
|
}
|
|
44
|
+
var PROJECT_ROOT_ENV = ["CLAUDE_PROJECT_DIR"];
|
|
45
|
+
function nearestExistingDir(directory) {
|
|
46
|
+
let current = directory;
|
|
47
|
+
while (current) {
|
|
48
|
+
if (existsSync(current)) return current;
|
|
49
|
+
const parent = dirname(current);
|
|
50
|
+
if (parent === current) return "";
|
|
51
|
+
current = parent;
|
|
52
|
+
}
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
function dirName(directory) {
|
|
56
|
+
return directory && basename(directory) || "unknown";
|
|
57
|
+
}
|
|
43
58
|
function gitProjectName(directory, resolveWorktrees) {
|
|
44
59
|
if (resolveWorktrees) {
|
|
45
|
-
const
|
|
46
|
-
|
|
60
|
+
const candidates = [
|
|
61
|
+
nearestExistingDir(directory),
|
|
62
|
+
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
63
|
+
];
|
|
64
|
+
for (const candidate of candidates) {
|
|
65
|
+
const root = candidate ? getProjectRootFromGit(candidate) : null;
|
|
66
|
+
if (root) return basename(root);
|
|
67
|
+
}
|
|
47
68
|
}
|
|
48
|
-
return
|
|
69
|
+
return dirName(directory);
|
|
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);
|
|
49
77
|
}
|
|
50
78
|
function mapLookup(map, directory) {
|
|
51
79
|
const cwd = normalize(directory);
|
|
52
80
|
let best;
|
|
53
81
|
for (const [dir, bank] of Object.entries(map)) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
if (cwd === p || cwd.startsWith(p + sep)) {
|
|
82
|
+
const p = configuredDir(dir);
|
|
83
|
+
if (isWithin(cwd, p)) {
|
|
57
84
|
if (!best || p.length > best.len) best = { len: p.length, bank };
|
|
58
85
|
}
|
|
59
86
|
}
|
|
60
87
|
return best?.bank;
|
|
61
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
|
+
}
|
|
62
97
|
function deriveBankId(config, directory, harness = "coding") {
|
|
63
98
|
const mapped = directory && config.mapPathToBank ? mapLookup(config.mapPathToBank, directory) : void 0;
|
|
64
99
|
if (mapped) return mapped;
|
|
@@ -66,7 +101,7 @@ function deriveBankId(config, directory, harness = "coding") {
|
|
|
66
101
|
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
67
102
|
const resolvers = {
|
|
68
103
|
harness: () => harness,
|
|
69
|
-
project: () =>
|
|
104
|
+
project: () => dirName(directory),
|
|
70
105
|
gitProject: () => gitProjectName(directory, config.resolveWorktrees ?? true),
|
|
71
106
|
channel: () => process.env.HINDSIGHT_CHANNEL_ID || "default",
|
|
72
107
|
user: () => process.env.HINDSIGHT_USER_ID || "anonymous"
|
|
@@ -110,11 +145,14 @@ function resolveConfig(raw = {}) {
|
|
|
110
145
|
bankIdTemplate: raw.bankIdTemplate,
|
|
111
146
|
mapPathToBank: raw.mapPathToBank,
|
|
112
147
|
resolveWorktrees: raw.resolveWorktrees,
|
|
148
|
+
optInOnly: raw.optInOnly ?? false,
|
|
149
|
+
// Same shape as retainTags: a config typo must not become a path that silently approves nothing.
|
|
150
|
+
optInPaths: Array.isArray(raw.optInPaths) ? raw.optInPaths.filter((p) => typeof p === "string" && p.trim() !== "") : [],
|
|
113
151
|
harness: raw.harness ?? "opencode",
|
|
114
152
|
disabled: raw.disabled ?? false,
|
|
115
153
|
retainSessions: raw.retainSessions ?? true,
|
|
116
154
|
// opencode: write back by default (parity with hook-harness Stop)
|
|
117
|
-
|
|
155
|
+
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
118
156
|
reflectTimeoutMs: raw.reflectTimeoutMs || 12e4,
|
|
119
157
|
autoReflect: raw.autoReflect ?? true,
|
|
120
158
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
@@ -170,10 +208,12 @@ var ENV_KEYS = {
|
|
|
170
208
|
dynamicBankId: "HINDSIGHT_DYNAMIC_BANK_ID",
|
|
171
209
|
bankIdTemplate: "HINDSIGHT_BANK_ID_TEMPLATE",
|
|
172
210
|
resolveWorktrees: "HINDSIGHT_RESOLVE_WORKTREES",
|
|
211
|
+
optInOnly: "HINDSIGHT_OPT_IN_ONLY",
|
|
212
|
+
optInPaths: "HINDSIGHT_OPT_IN_PATHS",
|
|
173
213
|
harness: "HINDSIGHT_HARNESS",
|
|
174
214
|
disabled: "HINDSIGHT_DISABLED",
|
|
175
215
|
retainSessions: "HINDSIGHT_RETAIN_SESSIONS",
|
|
176
|
-
|
|
216
|
+
maxParallelRetains: "HINDSIGHT_MAX_PARALLEL_RETAINS",
|
|
177
217
|
reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
|
|
178
218
|
autoReflect: "HINDSIGHT_AUTO_REFLECT",
|
|
179
219
|
pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
|
|
@@ -192,17 +232,18 @@ var ENV_KEYS = {
|
|
|
192
232
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
193
233
|
"dynamicBankId",
|
|
194
234
|
"resolveWorktrees",
|
|
235
|
+
"optInOnly",
|
|
195
236
|
"disabled",
|
|
196
237
|
"retainSessions",
|
|
197
238
|
"autoReflect",
|
|
198
239
|
"autoSeed",
|
|
199
240
|
"codebaseSurvey"
|
|
200
241
|
]);
|
|
201
|
-
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags"]);
|
|
242
|
+
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
202
243
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
203
244
|
"apiPort",
|
|
204
245
|
"daemonIdleTimeout",
|
|
205
|
-
"
|
|
246
|
+
"maxParallelRetains",
|
|
206
247
|
"reflectTimeoutMs",
|
|
207
248
|
"pageRefreshEveryTurns",
|
|
208
249
|
"seedLimit",
|
|
@@ -242,9 +283,15 @@ var BANK_OVERRIDE_EXCLUDED = [
|
|
|
242
283
|
"mapPathToBank",
|
|
243
284
|
"dynamicBankId",
|
|
244
285
|
"resolveWorktrees",
|
|
286
|
+
// Approval is decided BEFORE the bank is resolved, so a `banks.<id>` section naming these could
|
|
287
|
+
// only ever arrive too late to matter — strip them rather than let them read as effective.
|
|
288
|
+
"optInOnly",
|
|
289
|
+
"optInPaths",
|
|
245
290
|
"harness"
|
|
246
291
|
];
|
|
247
|
-
function applyBankConfig(cfg2, resolvedId) {
|
|
292
|
+
function applyBankConfig(cfg2, resolvedId, directory) {
|
|
293
|
+
if (directory !== void 0 && !isOptedIn(cfg2, directory))
|
|
294
|
+
return { cfg: { ...cfg2, disabled: true }, bankId: resolvedId };
|
|
248
295
|
const section = cfg2.banks[resolvedId];
|
|
249
296
|
if (!section) return { cfg: cfg2, bankId: resolvedId };
|
|
250
297
|
const safe = { ...section };
|
|
@@ -408,9 +455,40 @@ function semverGte(version, min) {
|
|
|
408
455
|
}
|
|
409
456
|
return true;
|
|
410
457
|
}
|
|
458
|
+
async function pool(items, n, fn, onError, onProgress) {
|
|
459
|
+
let i = 0, done = 0;
|
|
460
|
+
async function worker() {
|
|
461
|
+
while (i < items.length) {
|
|
462
|
+
const idx = i++;
|
|
463
|
+
try {
|
|
464
|
+
await fn(items[idx], idx);
|
|
465
|
+
} catch (e) {
|
|
466
|
+
onError?.(idx, e);
|
|
467
|
+
}
|
|
468
|
+
onProgress?.(++done, items.length);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, worker));
|
|
472
|
+
}
|
|
411
473
|
|
|
412
474
|
// src/core/hindsight.ts
|
|
413
475
|
var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
|
|
476
|
+
var RateLimitedError = class extends Error {
|
|
477
|
+
constructor(retryAfterMs2) {
|
|
478
|
+
super(`rate limited; retry after ${Math.round(retryAfterMs2 / 1e3)}s`);
|
|
479
|
+
this.retryAfterMs = retryAfterMs2;
|
|
480
|
+
this.name = "RateLimitedError";
|
|
481
|
+
}
|
|
482
|
+
retryAfterMs;
|
|
483
|
+
code = "rate_limited";
|
|
484
|
+
};
|
|
485
|
+
function retryAfterMs(header) {
|
|
486
|
+
if (!header) return 0;
|
|
487
|
+
const secs = Number(header.trim());
|
|
488
|
+
if (Number.isFinite(secs) && secs >= 0) return secs * 1e3;
|
|
489
|
+
const at = Date.parse(header);
|
|
490
|
+
return Number.isNaN(at) ? 0 : Math.max(0, at - Date.now());
|
|
491
|
+
}
|
|
414
492
|
var KnowledgePagesUnavailableError = class extends Error {
|
|
415
493
|
code = "knowledge_pages_unavailable";
|
|
416
494
|
constructor() {
|
|
@@ -419,6 +497,10 @@ var KnowledgePagesUnavailableError = class extends Error {
|
|
|
419
497
|
}
|
|
420
498
|
};
|
|
421
499
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
500
|
+
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
501
|
+
var POLL_CYCLE_MS = 5e3;
|
|
502
|
+
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
503
|
+
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
422
504
|
var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
|
|
423
505
|
var HindsightClient = class {
|
|
424
506
|
apiUrl;
|
|
@@ -431,12 +513,14 @@ var HindsightClient = class {
|
|
|
431
513
|
/** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
|
|
432
514
|
idempotentRetain;
|
|
433
515
|
log;
|
|
516
|
+
maxParallelRetains;
|
|
434
517
|
constructor(o) {
|
|
435
518
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
436
519
|
this.apiToken = o.apiToken;
|
|
437
520
|
this.bank = o.bank;
|
|
438
521
|
this.log = o.log ?? (() => {
|
|
439
522
|
});
|
|
523
|
+
this.maxParallelRetains = o.maxParallelRetains || DEFAULT_MAX_PARALLEL_RETAINS;
|
|
440
524
|
}
|
|
441
525
|
headers() {
|
|
442
526
|
const h = { "Content-Type": "application/json" };
|
|
@@ -454,6 +538,8 @@ var HindsightClient = class {
|
|
|
454
538
|
body: body ? JSON.stringify(body) : void 0,
|
|
455
539
|
signal: AbortSignal.timeout(15e3)
|
|
456
540
|
});
|
|
541
|
+
if (r.status === 429 && !tolerate.includes(429))
|
|
542
|
+
throw new RateLimitedError(retryAfterMs(r.headers.get("retry-after")));
|
|
457
543
|
if (!r.ok && r.status !== 404 && !tolerate.includes(r.status))
|
|
458
544
|
throw new Error(`${method} ${url} -> ${r.status} ${await r.text()}`);
|
|
459
545
|
return r;
|
|
@@ -585,7 +671,14 @@ var HindsightClient = class {
|
|
|
585
671
|
return 0;
|
|
586
672
|
}
|
|
587
673
|
}
|
|
588
|
-
/**
|
|
674
|
+
/**
|
|
675
|
+
* Poll each enqueued operation by id until terminal. LIST only shows active ops, so per-id GET is reliable.
|
|
676
|
+
*
|
|
677
|
+
* Concurrency is capped at `maxParallelRetains` (the API rate-limits bursts, not single
|
|
678
|
+
* requests — a 200 to a lone GET with 429s under `Promise.all` over every pending op). A 429
|
|
679
|
+
* leaves the op pending and backs the next cycle off by its `Retry-After` (10s floor) instead
|
|
680
|
+
* of hammering the next cycle 5s later.
|
|
681
|
+
*/
|
|
589
682
|
async drain(ids, label, maxMs = 60 * 60 * 1e3) {
|
|
590
683
|
if (!ids.length) return;
|
|
591
684
|
this.log(`[wait] draining ${ids.length} ${label} operations \u2026`);
|
|
@@ -593,23 +686,29 @@ var HindsightClient = class {
|
|
|
593
686
|
const pending = new Set(ids);
|
|
594
687
|
let failed = 0;
|
|
595
688
|
while (pending.size && Date.now() - start < maxMs) {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
} catch {
|
|
689
|
+
let backoffMs = POLL_CYCLE_MS;
|
|
690
|
+
await pool([...pending], this.maxParallelRetains, async (id) => {
|
|
691
|
+
try {
|
|
692
|
+
const r = await fetch(this.bankUrl(`/operations/${id}`), { headers: this.headers() });
|
|
693
|
+
if (r.status === 429) {
|
|
694
|
+
backoffMs = Math.min(
|
|
695
|
+
RETRY_AFTER_CEILING_MS,
|
|
696
|
+
Math.max(backoffMs, RETRY_AFTER_FLOOR_MS, retryAfterMs(r.headers.get("retry-after")))
|
|
697
|
+
);
|
|
698
|
+
return;
|
|
607
699
|
}
|
|
608
|
-
|
|
609
|
-
|
|
700
|
+
if (!r.ok) return;
|
|
701
|
+
const st = ((await r.json()).status || "").toLowerCase();
|
|
702
|
+
if (TERMINAL.has(st)) {
|
|
703
|
+
pending.delete(id);
|
|
704
|
+
if (st !== "completed") failed++;
|
|
705
|
+
}
|
|
706
|
+
} catch {
|
|
707
|
+
}
|
|
708
|
+
});
|
|
610
709
|
if (pending.size) {
|
|
611
710
|
this.log(` \u2026 ${pending.size}/${ids.length} ${label} ops pending`);
|
|
612
|
-
await sleep(
|
|
711
|
+
await sleep(backoffMs);
|
|
613
712
|
}
|
|
614
713
|
}
|
|
615
714
|
this.log(
|
|
@@ -809,13 +908,20 @@ var HindsightClient = class {
|
|
|
809
908
|
const verb = args.relatesToPageId ? "Enhancement to an existing initiative" : "New initiative";
|
|
810
909
|
const content = `${verb}: ${args.title}. ${args.summary}`;
|
|
811
910
|
const markerId = `initiative-marker-${this.slugify(args.title)}-${Date.now()}`;
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
911
|
+
const tags = [
|
|
912
|
+
.../* @__PURE__ */ new Set([
|
|
913
|
+
...args.stamp?.tags ?? [],
|
|
914
|
+
"knowledge:feature-work",
|
|
915
|
+
`relatedPageId:${pageId}`
|
|
916
|
+
])
|
|
917
|
+
];
|
|
918
|
+
if (Object.keys(args.stamp?.metadata ?? {}).length) {
|
|
919
|
+
await this.retain(content, "initiative marker", markerId, tags, "document", {
|
|
920
|
+
metadata: args.stamp?.metadata
|
|
921
|
+
});
|
|
922
|
+
} else {
|
|
923
|
+
await this.retain(content, "initiative marker", markerId, tags, "document");
|
|
924
|
+
}
|
|
819
925
|
return { page_id: pageId };
|
|
820
926
|
}
|
|
821
927
|
/** Find a root folder by name (case-insensitive) or create it; returns its id. Fail-open to undefined. */
|
|
@@ -873,7 +979,7 @@ function parsePageList(raw) {
|
|
|
873
979
|
|
|
874
980
|
// src/core/survey.ts
|
|
875
981
|
import { spawn as realSpawn2 } from "child_process";
|
|
876
|
-
import { accessSync, constants, existsSync } from "fs";
|
|
982
|
+
import { accessSync, constants, existsSync as existsSync2 } from "fs";
|
|
877
983
|
import { homedir as homedir3 } from "os";
|
|
878
984
|
import { delimiter, dirname as dirname3, join as join4 } from "path";
|
|
879
985
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
@@ -962,7 +1068,8 @@ var FINAL_BANK = resolved0.bankId ?? BANK;
|
|
|
962
1068
|
var client = new HindsightClient({
|
|
963
1069
|
apiUrl: arg("api-url") ?? cfg.apiUrl,
|
|
964
1070
|
apiToken: arg("api-token") ?? cfg.apiToken,
|
|
965
|
-
bank: FINAL_BANK
|
|
1071
|
+
bank: FINAL_BANK,
|
|
1072
|
+
maxParallelRetains: cfg.maxParallelRetains
|
|
966
1073
|
});
|
|
967
1074
|
syncStatus(client, FINAL_BANK, REPO).then((s) => console.log(JSON.stringify(s))).catch((e) => {
|
|
968
1075
|
console.error("status failed:", e.message || e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorize-io/hindsight-coding-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/vectorize-io/hindsight.git",
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
}
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
|
+
"pi": {
|
|
47
|
+
"extensions": [
|
|
48
|
+
"./dist/prime-agent.js"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
46
51
|
"scripts": {
|
|
47
52
|
"build": "tsup",
|
|
48
53
|
"clean": "rm -rf dist",
|