@vectorize-io/hindsight-coding-agents 0.5.2 → 0.5.4
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 +42 -8
- package/dist/antigravity-hook.js +335 -91
- package/dist/antigravity-statusline.js +17 -10
- package/dist/antigravity-stop-hook.js +340 -92
- package/dist/claude-hook.js +335 -91
- package/dist/claude-sessionstart-hook.js +459 -132
- package/dist/claude-stop-hook.js +340 -92
- package/dist/cline.js +283 -64
- package/dist/codex-hook.js +335 -91
- package/dist/codex-sessionstart-hook.js +459 -132
- package/dist/codex-stop-hook.js +340 -92
- package/dist/copilot-hook.js +335 -91
- package/dist/copilot-sessionstart-hook.js +459 -132
- package/dist/copilot-stop-hook.js +340 -92
- package/dist/cursor-hook.js +335 -91
- package/dist/cursor-sessionstart-hook.js +459 -132
- package/dist/cursor-stop-hook.js +340 -92
- package/dist/daemon-start.js +17 -10
- package/dist/dcode-hook.js +335 -91
- package/dist/dcode-sessionstart-hook.js +459 -132
- package/dist/dcode-stop-hook.js +340 -92
- package/dist/deepen.js +113 -32
- package/dist/devin-hook.js +335 -91
- package/dist/devin-sessionstart-hook.js +459 -132
- package/dist/devin-stop-hook.js +340 -92
- package/dist/droid-hook.js +335 -91
- package/dist/droid-sessionstart-hook.js +459 -132
- package/dist/droid-stop-hook.js +340 -92
- package/dist/dsh.js +322 -101
- package/dist/grok-hook.js +335 -91
- package/dist/grok-sessionstart-hook.js +459 -132
- package/dist/grok-stop-hook.js +340 -92
- package/dist/hindsight-seed.js +17 -10
- package/dist/index.js +322 -101
- package/dist/installer.js +1252 -325
- package/dist/kilo.js +322 -101
- package/dist/mcp-server.js +100 -23
- package/dist/opencode2.js +322 -101
- package/dist/pi.js +321 -100
- package/dist/prime-agent.js +321 -100
- package/dist/qwen-hook.js +335 -91
- package/dist/qwen-sessionstart-hook.js +459 -132
- package/dist/qwen-stop-hook.js +340 -92
- package/dist/status.js +98 -21
- package/dist/survey-supervisor.js +81 -0
- package/dist/zcode-hook.js +2954 -0
- package/dist/zcode-sessionstart-hook.js +3655 -0
- package/dist/zcode-stop-hook.js +3218 -0
- package/package.json +7 -3
- package/plugin.json +1 -1
- package/skill/SKILL.md +17 -7
package/dist/status.js
CHANGED
|
@@ -427,6 +427,7 @@ function pagesFor(project) {
|
|
|
427
427
|
var PAGE_MAX_TOKENS = 4096;
|
|
428
428
|
var PAGE_TAGS_MATCH = "all";
|
|
429
429
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
430
|
+
var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
|
|
430
431
|
var CRON_FIELD_RANGES = [
|
|
431
432
|
[0, 59],
|
|
432
433
|
// minute
|
|
@@ -480,14 +481,23 @@ function pageTriggerFor(trigger, bank, page) {
|
|
|
480
481
|
function buildPageTrigger(cfg2 = {}) {
|
|
481
482
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
482
483
|
switch (cfg2.pageTriggerType) {
|
|
483
|
-
case "
|
|
484
|
-
return { ...base,
|
|
484
|
+
case "auto-refresh":
|
|
485
|
+
return { ...base, refresh_after_consolidation: true };
|
|
485
486
|
case "manual":
|
|
486
487
|
return { ...base, refresh_after_consolidation: false };
|
|
488
|
+
// "cron" and an unset type alike: the default schedule stands in for a missing expression, so
|
|
489
|
+
// a trigger built from a partial config is never a cron trigger with nothing to fire on.
|
|
487
490
|
default:
|
|
488
|
-
return { ...base,
|
|
491
|
+
return { ...base, refresh_cron: cfg2.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
|
|
489
492
|
}
|
|
490
493
|
}
|
|
494
|
+
function pageTriggerDrifted(current2, desired) {
|
|
495
|
+
return current2.tags_match !== desired.tags_match || (current2.refresh_cron ?? null) !== (desired.refresh_cron ?? null) || Boolean(current2.refresh_after_consolidation) !== Boolean(desired.refresh_after_consolidation);
|
|
496
|
+
}
|
|
497
|
+
function pageTriggerPatch(desired) {
|
|
498
|
+
if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
|
|
499
|
+
return desired;
|
|
500
|
+
}
|
|
491
501
|
var CODING_BANK_TEMPLATE = {
|
|
492
502
|
version: "1",
|
|
493
503
|
bank: {
|
|
@@ -892,9 +902,16 @@ var HindsightClient = class {
|
|
|
892
902
|
body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
|
|
893
903
|
signal: ctrl.signal
|
|
894
904
|
});
|
|
895
|
-
if (!resp.ok)
|
|
905
|
+
if (!resp.ok)
|
|
906
|
+
throw new Error(
|
|
907
|
+
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
|
|
908
|
+
);
|
|
896
909
|
const data = await resp.json();
|
|
897
910
|
return (data.text || "").trim();
|
|
911
|
+
} catch (e) {
|
|
912
|
+
if (ctrl.signal.aborted)
|
|
913
|
+
throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
|
|
914
|
+
throw e;
|
|
898
915
|
} finally {
|
|
899
916
|
clearTimeout(timer);
|
|
900
917
|
}
|
|
@@ -1027,14 +1044,14 @@ var HindsightClient = class {
|
|
|
1027
1044
|
if (r.status !== 409) created++;
|
|
1028
1045
|
} else {
|
|
1029
1046
|
const sourceDrift = hit.description !== page.source_query;
|
|
1030
|
-
const triggerDrift = hit.trigger != null && hit.trigger
|
|
1047
|
+
const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
|
|
1031
1048
|
if (!sourceDrift && !triggerDrift) continue;
|
|
1032
1049
|
const patch = {};
|
|
1033
1050
|
if (sourceDrift) {
|
|
1034
1051
|
patch.source_query = page.source_query;
|
|
1035
1052
|
patch.tags = page.tags;
|
|
1036
1053
|
}
|
|
1037
|
-
if (triggerDrift) patch.trigger =
|
|
1054
|
+
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1038
1055
|
const r = await this.req(
|
|
1039
1056
|
"PATCH",
|
|
1040
1057
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
@@ -1050,10 +1067,42 @@ var HindsightClient = class {
|
|
|
1050
1067
|
updated++;
|
|
1051
1068
|
}
|
|
1052
1069
|
}
|
|
1070
|
+
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1053
1071
|
this.log(
|
|
1054
|
-
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1072
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged` + (initiatives ? `, ${initiatives} initiative pages re-synced` : "")
|
|
1055
1073
|
);
|
|
1056
1074
|
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
|
|
1077
|
+
*
|
|
1078
|
+
* `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
|
|
1079
|
+
* an older default they are the same drift as the taxonomy — and on a real repo they are most of
|
|
1080
|
+
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
1081
|
+
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
1082
|
+
*
|
|
1083
|
+
* Only the trigger is touched. Their `name` and `source_query` are written once, from the
|
|
1084
|
+
* initiative's own title, and re-stating either would rebuild a page whose question never
|
|
1085
|
+
* changed. The tree read above is reused rather than re-fetched.
|
|
1086
|
+
*/
|
|
1087
|
+
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
1088
|
+
const folder = roots.find(
|
|
1089
|
+
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
1090
|
+
);
|
|
1091
|
+
let updated = 0;
|
|
1092
|
+
for (const page of folder?.children ?? []) {
|
|
1093
|
+
if (page.kind !== "page" || page.trigger == null) continue;
|
|
1094
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
1095
|
+
if (!pageTriggerDrifted(page.trigger, desired)) continue;
|
|
1096
|
+
const r = await this.req(
|
|
1097
|
+
"PATCH",
|
|
1098
|
+
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1099
|
+
{ trigger: pageTriggerPatch(desired) }
|
|
1100
|
+
);
|
|
1101
|
+
if ([404, 405, 501].includes(r.status)) break;
|
|
1102
|
+
updated++;
|
|
1103
|
+
}
|
|
1104
|
+
return updated;
|
|
1105
|
+
}
|
|
1057
1106
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
1058
1107
|
slugify(s) {
|
|
1059
1108
|
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
|
|
@@ -1075,11 +1124,13 @@ var HindsightClient = class {
|
|
|
1075
1124
|
let pageId = args.relatesToPageId;
|
|
1076
1125
|
if (!pageId) {
|
|
1077
1126
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1127
|
+
const subject = this.project ?? this.bank;
|
|
1078
1128
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1079
1129
|
name: args.title,
|
|
1080
|
-
source_query: `Summarize the "${args.title}" initiative: what is being built or changed and why, and its current state \u2014 drawn from the project's memory
|
|
1130
|
+
source_query: `Summarize the "${args.title}" initiative: what is being built or changed and why, and its current state \u2014 drawn from the project's memory.` + pageScopeRule(subject),
|
|
1081
1131
|
parent_id: folderId,
|
|
1082
1132
|
tags: ["knowledge:feature-work"],
|
|
1133
|
+
max_tokens: PAGE_MAX_TOKENS,
|
|
1083
1134
|
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1084
1135
|
});
|
|
1085
1136
|
try {
|
|
@@ -1122,17 +1173,22 @@ var HindsightClient = class {
|
|
|
1122
1173
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
1123
1174
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1124
1175
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1125
|
-
function
|
|
1126
|
-
if (raw.pageTriggerType === "manual") return "manual";
|
|
1127
|
-
if (raw.pageTriggerType === "
|
|
1128
|
-
|
|
1129
|
-
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
1176
|
+
function resolvePageTrigger(raw) {
|
|
1177
|
+
if (raw.pageTriggerType === "manual") return { type: "manual" };
|
|
1178
|
+
if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
|
|
1179
|
+
if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
|
|
1130
1180
|
log.warn(
|
|
1131
1181
|
"config",
|
|
1132
|
-
|
|
1182
|
+
`ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
|
|
1133
1183
|
);
|
|
1134
|
-
|
|
1135
|
-
return "
|
|
1184
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1185
|
+
if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1186
|
+
if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
|
|
1187
|
+
log.warn(
|
|
1188
|
+
"config",
|
|
1189
|
+
`pageTriggerCron ${JSON.stringify(cron)} has a malformed hashed field \u2014 write \`H\` or \`H(<lo>-<hi>)\` within the field's own range, e.g. "H H(0-5) * * *" \u2014 falling back to ${JSON.stringify(DEFAULT_PAGE_TRIGGER_CRON)}`
|
|
1190
|
+
);
|
|
1191
|
+
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1136
1192
|
}
|
|
1137
1193
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1138
1194
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
@@ -1164,6 +1220,7 @@ function resolveObservationScopes(raw) {
|
|
|
1164
1220
|
function resolveConfig(raw = {}) {
|
|
1165
1221
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1166
1222
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
1223
|
+
const pageTrigger = resolvePageTrigger(raw);
|
|
1167
1224
|
return {
|
|
1168
1225
|
serverMode,
|
|
1169
1226
|
// Daemon mode resolves the URL HERE rather than at each call site: every entry point already
|
|
@@ -1198,8 +1255,8 @@ function resolveConfig(raw = {}) {
|
|
|
1198
1255
|
reflectBudget: resolveReflectBudget(raw),
|
|
1199
1256
|
autoReflect: raw.autoReflect ?? true,
|
|
1200
1257
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
1201
|
-
pageTriggerType:
|
|
1202
|
-
pageTriggerCron:
|
|
1258
|
+
pageTriggerType: pageTrigger.type,
|
|
1259
|
+
pageTriggerCron: pageTrigger.cron,
|
|
1203
1260
|
autoSeed: raw.autoSeed ?? true,
|
|
1204
1261
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1205
1262
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -1408,11 +1465,31 @@ function parsePageList(raw) {
|
|
|
1408
1465
|
}
|
|
1409
1466
|
|
|
1410
1467
|
// src/core/survey.ts
|
|
1411
|
-
import { spawn as
|
|
1468
|
+
import { spawn as realSpawn3 } from "child_process";
|
|
1469
|
+
import { createHash as createHash2 } from "crypto";
|
|
1412
1470
|
import { existsSync as existsSync2 } from "fs";
|
|
1413
|
-
import { homedir as homedir3 } from "os";
|
|
1414
|
-
import { dirname as dirname5, join as
|
|
1471
|
+
import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
|
|
1472
|
+
import { dirname as dirname5, join as join8 } from "path";
|
|
1415
1473
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1474
|
+
|
|
1475
|
+
// src/core/survey-lease.ts
|
|
1476
|
+
import { spawn as realSpawn2 } from "child_process";
|
|
1477
|
+
import { randomUUID } from "crypto";
|
|
1478
|
+
import {
|
|
1479
|
+
mkdirSync as mkdirSync2,
|
|
1480
|
+
mkdtempSync,
|
|
1481
|
+
readdirSync,
|
|
1482
|
+
renameSync,
|
|
1483
|
+
rmdirSync,
|
|
1484
|
+
rmSync,
|
|
1485
|
+
statSync,
|
|
1486
|
+
unlinkSync,
|
|
1487
|
+
utimesSync,
|
|
1488
|
+
writeFileSync
|
|
1489
|
+
} from "fs";
|
|
1490
|
+
import { join as join7 } from "path";
|
|
1491
|
+
|
|
1492
|
+
// src/core/survey.ts
|
|
1416
1493
|
var SURVEY_DOC_IDS = [
|
|
1417
1494
|
"repository-component-map",
|
|
1418
1495
|
"repository-core-concepts",
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/survey-lease.ts
|
|
4
|
+
import { spawn as realSpawn } from "child_process";
|
|
5
|
+
import { randomUUID } from "crypto";
|
|
6
|
+
import {
|
|
7
|
+
mkdirSync,
|
|
8
|
+
mkdtempSync,
|
|
9
|
+
readdirSync,
|
|
10
|
+
renameSync,
|
|
11
|
+
rmdirSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
statSync,
|
|
14
|
+
unlinkSync,
|
|
15
|
+
utimesSync,
|
|
16
|
+
writeFileSync
|
|
17
|
+
} from "fs";
|
|
18
|
+
import { join } from "path";
|
|
19
|
+
var LEASE_HEARTBEAT_MS = 5e3;
|
|
20
|
+
var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
|
|
21
|
+
function releaseLease(lease) {
|
|
22
|
+
try {
|
|
23
|
+
unlinkSync(join(lease.directory, lease.owner));
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
rmdirSync(lease.directory);
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function heartbeatLease(lease) {
|
|
33
|
+
try {
|
|
34
|
+
const now = /* @__PURE__ */ new Date();
|
|
35
|
+
utimesSync(join(lease.directory, lease.owner), now, now);
|
|
36
|
+
return true;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return error.code !== "ENOENT";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function superviseSurvey(spec2, spawnFn = realSpawn) {
|
|
42
|
+
let stop = () => {
|
|
43
|
+
};
|
|
44
|
+
const done = new Promise((resolve) => {
|
|
45
|
+
if (!heartbeatLease(spec2.lease)) return resolve();
|
|
46
|
+
let child;
|
|
47
|
+
try {
|
|
48
|
+
child = spawnFn(spec2.bin, spec2.args, { stdio: "ignore", windowsHide: true });
|
|
49
|
+
} catch {
|
|
50
|
+
releaseLease(spec2.lease);
|
|
51
|
+
return resolve();
|
|
52
|
+
}
|
|
53
|
+
let finished = false;
|
|
54
|
+
const finish = (release) => {
|
|
55
|
+
if (finished) return;
|
|
56
|
+
finished = true;
|
|
57
|
+
clearInterval(timer);
|
|
58
|
+
if (release) releaseLease(spec2.lease);
|
|
59
|
+
resolve();
|
|
60
|
+
};
|
|
61
|
+
const timer = setInterval(() => {
|
|
62
|
+
if (heartbeatLease(spec2.lease)) return;
|
|
63
|
+
child.kill();
|
|
64
|
+
finish(false);
|
|
65
|
+
}, spec2.heartbeatMs ?? LEASE_HEARTBEAT_MS);
|
|
66
|
+
child.on("error", () => finish(true));
|
|
67
|
+
child.once("exit", () => finish(true));
|
|
68
|
+
stop = () => {
|
|
69
|
+
child.kill();
|
|
70
|
+
finish(true);
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
return { done, stop: () => stop() };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/survey-supervisor.ts
|
|
77
|
+
var spec = JSON.parse(process.env[SURVEY_SPEC_ENV] ?? "");
|
|
78
|
+
delete process.env[SURVEY_SPEC_ENV];
|
|
79
|
+
var run = superviseSurvey(spec);
|
|
80
|
+
for (const signal of ["SIGTERM", "SIGINT", "SIGHUP"]) process.once(signal, run.stop);
|
|
81
|
+
void run.done;
|