@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/codex-hook.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/core/hook.ts
|
|
4
|
-
import { existsSync as existsSync2, readFileSync as
|
|
4
|
+
import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
|
|
5
5
|
|
|
6
6
|
// src/core/bank.ts
|
|
7
7
|
import { existsSync } from "fs";
|
|
@@ -471,6 +471,7 @@ function pagesFor(project) {
|
|
|
471
471
|
var PAGE_MAX_TOKENS = 4096;
|
|
472
472
|
var PAGE_TAGS_MATCH = "all";
|
|
473
473
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
474
|
+
var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
|
|
474
475
|
var CRON_FIELD_RANGES = [
|
|
475
476
|
[0, 59],
|
|
476
477
|
// minute
|
|
@@ -524,14 +525,23 @@ function pageTriggerFor(trigger, bank, page) {
|
|
|
524
525
|
function buildPageTrigger(cfg = {}) {
|
|
525
526
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
526
527
|
switch (cfg.pageTriggerType) {
|
|
527
|
-
case "
|
|
528
|
-
return { ...base,
|
|
528
|
+
case "auto-refresh":
|
|
529
|
+
return { ...base, refresh_after_consolidation: true };
|
|
529
530
|
case "manual":
|
|
530
531
|
return { ...base, refresh_after_consolidation: false };
|
|
532
|
+
// "cron" and an unset type alike: the default schedule stands in for a missing expression, so
|
|
533
|
+
// a trigger built from a partial config is never a cron trigger with nothing to fire on.
|
|
531
534
|
default:
|
|
532
|
-
return { ...base,
|
|
535
|
+
return { ...base, refresh_cron: cfg.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
|
|
533
536
|
}
|
|
534
537
|
}
|
|
538
|
+
function pageTriggerDrifted(current2, desired) {
|
|
539
|
+
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);
|
|
540
|
+
}
|
|
541
|
+
function pageTriggerPatch(desired) {
|
|
542
|
+
if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
|
|
543
|
+
return desired;
|
|
544
|
+
}
|
|
535
545
|
var CODING_BANK_TEMPLATE = {
|
|
536
546
|
version: "1",
|
|
537
547
|
bank: {
|
|
@@ -936,9 +946,16 @@ var HindsightClient = class {
|
|
|
936
946
|
body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
|
|
937
947
|
signal: ctrl.signal
|
|
938
948
|
});
|
|
939
|
-
if (!resp.ok)
|
|
949
|
+
if (!resp.ok)
|
|
950
|
+
throw new Error(
|
|
951
|
+
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
|
|
952
|
+
);
|
|
940
953
|
const data = await resp.json();
|
|
941
954
|
return (data.text || "").trim();
|
|
955
|
+
} catch (e) {
|
|
956
|
+
if (ctrl.signal.aborted)
|
|
957
|
+
throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
|
|
958
|
+
throw e;
|
|
942
959
|
} finally {
|
|
943
960
|
clearTimeout(timer);
|
|
944
961
|
}
|
|
@@ -1071,14 +1088,14 @@ var HindsightClient = class {
|
|
|
1071
1088
|
if (r.status !== 409) created++;
|
|
1072
1089
|
} else {
|
|
1073
1090
|
const sourceDrift = hit.description !== page.source_query;
|
|
1074
|
-
const triggerDrift = hit.trigger != null && hit.trigger
|
|
1091
|
+
const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
|
|
1075
1092
|
if (!sourceDrift && !triggerDrift) continue;
|
|
1076
1093
|
const patch = {};
|
|
1077
1094
|
if (sourceDrift) {
|
|
1078
1095
|
patch.source_query = page.source_query;
|
|
1079
1096
|
patch.tags = page.tags;
|
|
1080
1097
|
}
|
|
1081
|
-
if (triggerDrift) patch.trigger =
|
|
1098
|
+
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1082
1099
|
const r = await this.req(
|
|
1083
1100
|
"PATCH",
|
|
1084
1101
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
@@ -1094,10 +1111,42 @@ var HindsightClient = class {
|
|
|
1094
1111
|
updated++;
|
|
1095
1112
|
}
|
|
1096
1113
|
}
|
|
1114
|
+
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1097
1115
|
this.log(
|
|
1098
|
-
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1116
|
+
`[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` : "")
|
|
1099
1117
|
);
|
|
1100
1118
|
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
|
|
1121
|
+
*
|
|
1122
|
+
* `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
|
|
1123
|
+
* an older default they are the same drift as the taxonomy — and on a real repo they are most of
|
|
1124
|
+
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
1125
|
+
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
1126
|
+
*
|
|
1127
|
+
* Only the trigger is touched. Their `name` and `source_query` are written once, from the
|
|
1128
|
+
* initiative's own title, and re-stating either would rebuild a page whose question never
|
|
1129
|
+
* changed. The tree read above is reused rather than re-fetched.
|
|
1130
|
+
*/
|
|
1131
|
+
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
1132
|
+
const folder = roots.find(
|
|
1133
|
+
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
1134
|
+
);
|
|
1135
|
+
let updated = 0;
|
|
1136
|
+
for (const page of folder?.children ?? []) {
|
|
1137
|
+
if (page.kind !== "page" || page.trigger == null) continue;
|
|
1138
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
1139
|
+
if (!pageTriggerDrifted(page.trigger, desired)) continue;
|
|
1140
|
+
const r = await this.req(
|
|
1141
|
+
"PATCH",
|
|
1142
|
+
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1143
|
+
{ trigger: pageTriggerPatch(desired) }
|
|
1144
|
+
);
|
|
1145
|
+
if ([404, 405, 501].includes(r.status)) break;
|
|
1146
|
+
updated++;
|
|
1147
|
+
}
|
|
1148
|
+
return updated;
|
|
1149
|
+
}
|
|
1101
1150
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
1102
1151
|
slugify(s) {
|
|
1103
1152
|
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
|
|
@@ -1119,11 +1168,13 @@ var HindsightClient = class {
|
|
|
1119
1168
|
let pageId = args.relatesToPageId;
|
|
1120
1169
|
if (!pageId) {
|
|
1121
1170
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1171
|
+
const subject = this.project ?? this.bank;
|
|
1122
1172
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1123
1173
|
name: args.title,
|
|
1124
|
-
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
|
|
1174
|
+
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),
|
|
1125
1175
|
parent_id: folderId,
|
|
1126
1176
|
tags: ["knowledge:feature-work"],
|
|
1177
|
+
max_tokens: PAGE_MAX_TOKENS,
|
|
1127
1178
|
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1128
1179
|
});
|
|
1129
1180
|
try {
|
|
@@ -1166,17 +1217,22 @@ var HindsightClient = class {
|
|
|
1166
1217
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
1167
1218
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1168
1219
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1169
|
-
function
|
|
1170
|
-
if (raw.pageTriggerType === "manual") return "manual";
|
|
1171
|
-
if (raw.pageTriggerType === "
|
|
1172
|
-
|
|
1173
|
-
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
1220
|
+
function resolvePageTrigger(raw) {
|
|
1221
|
+
if (raw.pageTriggerType === "manual") return { type: "manual" };
|
|
1222
|
+
if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
|
|
1223
|
+
if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
|
|
1174
1224
|
log.warn(
|
|
1175
1225
|
"config",
|
|
1176
|
-
|
|
1226
|
+
`ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
|
|
1177
1227
|
);
|
|
1178
|
-
|
|
1179
|
-
return "
|
|
1228
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1229
|
+
if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1230
|
+
if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
|
|
1231
|
+
log.warn(
|
|
1232
|
+
"config",
|
|
1233
|
+
`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)}`
|
|
1234
|
+
);
|
|
1235
|
+
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1180
1236
|
}
|
|
1181
1237
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1182
1238
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
@@ -1208,6 +1264,7 @@ function resolveObservationScopes(raw) {
|
|
|
1208
1264
|
function resolveConfig(raw = {}) {
|
|
1209
1265
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1210
1266
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
1267
|
+
const pageTrigger = resolvePageTrigger(raw);
|
|
1211
1268
|
return {
|
|
1212
1269
|
serverMode,
|
|
1213
1270
|
// Daemon mode resolves the URL HERE rather than at each call site: every entry point already
|
|
@@ -1242,8 +1299,8 @@ function resolveConfig(raw = {}) {
|
|
|
1242
1299
|
reflectBudget: resolveReflectBudget(raw),
|
|
1243
1300
|
autoReflect: raw.autoReflect ?? true,
|
|
1244
1301
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
1245
|
-
pageTriggerType:
|
|
1246
|
-
pageTriggerCron:
|
|
1302
|
+
pageTriggerType: pageTrigger.type,
|
|
1303
|
+
pageTriggerCron: pageTrigger.cron,
|
|
1247
1304
|
autoSeed: raw.autoSeed ?? true,
|
|
1248
1305
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1249
1306
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -1541,6 +1598,102 @@ function sessionRootDir(harness, sessionId, cwd) {
|
|
|
1541
1598
|
return cwd;
|
|
1542
1599
|
}
|
|
1543
1600
|
|
|
1601
|
+
// src/core/turn-journal.ts
|
|
1602
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync } from "fs";
|
|
1603
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
1604
|
+
import { dirname as dirname6, join as join8 } from "path";
|
|
1605
|
+
|
|
1606
|
+
// src/core/transcript-util.ts
|
|
1607
|
+
var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
|
|
1608
|
+
function stripInjectedMemory(s) {
|
|
1609
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
1610
|
+
}
|
|
1611
|
+
var TARGET_KEYS = [
|
|
1612
|
+
"file_path",
|
|
1613
|
+
"path",
|
|
1614
|
+
"notebook_path",
|
|
1615
|
+
"command",
|
|
1616
|
+
"pattern",
|
|
1617
|
+
"query",
|
|
1618
|
+
"url",
|
|
1619
|
+
"name",
|
|
1620
|
+
"id"
|
|
1621
|
+
];
|
|
1622
|
+
var ACTION_TARGET_CAP = 100;
|
|
1623
|
+
function actionLine(tool, input) {
|
|
1624
|
+
let target = "";
|
|
1625
|
+
if (input && typeof input === "object") {
|
|
1626
|
+
const rec = input;
|
|
1627
|
+
for (const k of TARGET_KEYS) {
|
|
1628
|
+
const v = rec[k];
|
|
1629
|
+
if (typeof v === "string" && v.trim()) {
|
|
1630
|
+
target = v.trim().split("\n")[0];
|
|
1631
|
+
break;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
} else if (typeof input === "string") {
|
|
1635
|
+
target = input.trim().split("\n")[0];
|
|
1636
|
+
}
|
|
1637
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
1638
|
+
return target ? `${tool} ${target}` : tool;
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
// src/core/turn-journal.ts
|
|
1642
|
+
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
1643
|
+
function journalPath(harness, sessionId) {
|
|
1644
|
+
return join8(tmpdir3(), `hindsight-${harness}`, `${sessionId || "no-session"}.journal.jsonl`);
|
|
1645
|
+
}
|
|
1646
|
+
function appendJournalTurn(path, turn) {
|
|
1647
|
+
const content = stripInjectedMemory(turn.content ?? "").trim();
|
|
1648
|
+
if (!content) return;
|
|
1649
|
+
try {
|
|
1650
|
+
if (statSync(path).size >= JOURNAL_MAX_BYTES) return;
|
|
1651
|
+
} catch {
|
|
1652
|
+
}
|
|
1653
|
+
const last = readJournalTranscript(path).at(-1);
|
|
1654
|
+
if (last && last.role === turn.role && last.content === content) return;
|
|
1655
|
+
try {
|
|
1656
|
+
mkdirSync3(dirname6(path), { recursive: true });
|
|
1657
|
+
appendFileSync3(
|
|
1658
|
+
path,
|
|
1659
|
+
JSON.stringify({
|
|
1660
|
+
role: turn.role,
|
|
1661
|
+
content,
|
|
1662
|
+
timestamp: turn.timestamp ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
1663
|
+
}) + "\n"
|
|
1664
|
+
);
|
|
1665
|
+
} catch {
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
function readJournalTranscript(path) {
|
|
1669
|
+
let body;
|
|
1670
|
+
try {
|
|
1671
|
+
body = readFileSync4(path, "utf8");
|
|
1672
|
+
} catch {
|
|
1673
|
+
return [];
|
|
1674
|
+
}
|
|
1675
|
+
const turns = [];
|
|
1676
|
+
for (const line of body.split("\n")) {
|
|
1677
|
+
const trimmed = line.trim();
|
|
1678
|
+
if (!trimmed) continue;
|
|
1679
|
+
let parsed;
|
|
1680
|
+
try {
|
|
1681
|
+
parsed = JSON.parse(trimmed);
|
|
1682
|
+
} catch {
|
|
1683
|
+
continue;
|
|
1684
|
+
}
|
|
1685
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
1686
|
+
const { role, content, timestamp } = parsed;
|
|
1687
|
+
if (typeof role !== "string" || typeof content !== "string" || !content) continue;
|
|
1688
|
+
turns.push({
|
|
1689
|
+
role,
|
|
1690
|
+
content,
|
|
1691
|
+
...typeof timestamp === "string" ? { timestamp } : {}
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
return turns;
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1544
1697
|
// src/core/hook.ts
|
|
1545
1698
|
var HOOK_REFLECT_CAP_MS = 25e3;
|
|
1546
1699
|
async function buildHookOutput(args) {
|
|
@@ -1556,13 +1709,14 @@ async function buildHookOutput(args) {
|
|
|
1556
1709
|
} else if (cfg.autoReflect && reflectAnswer === void 0) {
|
|
1557
1710
|
reflectRanThisTurn = true;
|
|
1558
1711
|
const t0 = Date.now();
|
|
1712
|
+
const timeoutMs = Math.min(cfg.reflectTimeoutMs, HOOK_REFLECT_CAP_MS);
|
|
1559
1713
|
try {
|
|
1560
1714
|
reflectAnswer = await client.reflect(buildReflectQuery(prompt), {
|
|
1561
1715
|
// Automatic reflection runs inside a hard 25s hook window. Hindsight's low budget is the
|
|
1562
1716
|
// supported default for bounded reflect calls; callers that explicitly invoke the MCP
|
|
1563
1717
|
// tool still get the deeper high-budget path.
|
|
1564
1718
|
budget: "low",
|
|
1565
|
-
timeoutMs
|
|
1719
|
+
timeoutMs
|
|
1566
1720
|
});
|
|
1567
1721
|
diag(harness, reflectAnswer ? "reflect_ok" : "reflect_empty", {
|
|
1568
1722
|
ms: Date.now() - t0,
|
|
@@ -1580,7 +1734,10 @@ async function buildHookOutput(args) {
|
|
|
1580
1734
|
});
|
|
1581
1735
|
diag(harness, "reflect_failed", {
|
|
1582
1736
|
ms: Date.now() - t0,
|
|
1583
|
-
|
|
1737
|
+
bank: client.bank,
|
|
1738
|
+
timeoutMs,
|
|
1739
|
+
// Wider than describeError's default: the server's error body is the useful part.
|
|
1740
|
+
error: describeError(e, 1500),
|
|
1584
1741
|
query: prompt.slice(0, 80)
|
|
1585
1742
|
});
|
|
1586
1743
|
}
|
|
@@ -1631,7 +1788,7 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1631
1788
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
1632
1789
|
let ev = {};
|
|
1633
1790
|
try {
|
|
1634
|
-
ev = JSON.parse(
|
|
1791
|
+
ev = JSON.parse(readFileSync5(0, "utf8"));
|
|
1635
1792
|
} catch {
|
|
1636
1793
|
return;
|
|
1637
1794
|
}
|
|
@@ -1646,6 +1803,9 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1646
1803
|
log.debug(spec.harness, "hook skipped: disabled");
|
|
1647
1804
|
return;
|
|
1648
1805
|
}
|
|
1806
|
+
if (spec.journalPrompt) {
|
|
1807
|
+
appendJournalTurn(journalPath(spec.harness, sessionId), { role: "user", content: prompt });
|
|
1808
|
+
}
|
|
1649
1809
|
const out = (context, notice) => process.stdout.write(JSON.stringify(spec.emit(context ?? "", notice, ev)));
|
|
1650
1810
|
const sessionRoot = sessionRootDir(spec.harness, sessionId, cwd);
|
|
1651
1811
|
const derived = deriveBankIdOrSkip(cfg, cwd, spec.harness, sessionRoot);
|
|
@@ -1676,7 +1836,7 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1676
1836
|
}
|
|
1677
1837
|
|
|
1678
1838
|
// src/core/retain-hook.ts
|
|
1679
|
-
import { readFileSync as
|
|
1839
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
1680
1840
|
|
|
1681
1841
|
// src/core/retain-cursor.ts
|
|
1682
1842
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -1688,14 +1848,14 @@ import { createHash as createHash3 } from "crypto";
|
|
|
1688
1848
|
|
|
1689
1849
|
// src/core/daemon.ts
|
|
1690
1850
|
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
1691
|
-
import { dirname as
|
|
1851
|
+
import { dirname as dirname7, join as join9 } from "path";
|
|
1692
1852
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1693
1853
|
|
|
1694
1854
|
// src/core/retain-stamp.ts
|
|
1695
1855
|
import { basename as basename2 } from "path";
|
|
1696
1856
|
|
|
1697
1857
|
// src/core/jsonl.ts
|
|
1698
|
-
import { closeSync, openSync, readSync, statSync } from "fs";
|
|
1858
|
+
import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
|
|
1699
1859
|
import { StringDecoder } from "string_decoder";
|
|
1700
1860
|
var CHUNK_BYTES = 64 * 1024;
|
|
1701
1861
|
var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
|
|
@@ -1703,7 +1863,7 @@ function readJsonlTail(path, opts) {
|
|
|
1703
1863
|
const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
|
|
1704
1864
|
let size;
|
|
1705
1865
|
try {
|
|
1706
|
-
size =
|
|
1866
|
+
size = statSync2(path).size;
|
|
1707
1867
|
} catch {
|
|
1708
1868
|
return { lines: emptyLines(), skippedBytes: 0 };
|
|
1709
1869
|
}
|
|
@@ -1755,43 +1915,8 @@ function* streamLines(path, start) {
|
|
|
1755
1915
|
}
|
|
1756
1916
|
}
|
|
1757
1917
|
|
|
1758
|
-
// src/core/transcript-util.ts
|
|
1759
|
-
var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
|
|
1760
|
-
function stripInjectedMemory(s) {
|
|
1761
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
1762
|
-
}
|
|
1763
|
-
var TARGET_KEYS = [
|
|
1764
|
-
"file_path",
|
|
1765
|
-
"path",
|
|
1766
|
-
"notebook_path",
|
|
1767
|
-
"command",
|
|
1768
|
-
"pattern",
|
|
1769
|
-
"query",
|
|
1770
|
-
"url",
|
|
1771
|
-
"name",
|
|
1772
|
-
"id"
|
|
1773
|
-
];
|
|
1774
|
-
var ACTION_TARGET_CAP = 100;
|
|
1775
|
-
function actionLine(tool, input) {
|
|
1776
|
-
let target = "";
|
|
1777
|
-
if (input && typeof input === "object") {
|
|
1778
|
-
const rec = input;
|
|
1779
|
-
for (const k of TARGET_KEYS) {
|
|
1780
|
-
const v = rec[k];
|
|
1781
|
-
if (typeof v === "string" && v.trim()) {
|
|
1782
|
-
target = v.trim().split("\n")[0];
|
|
1783
|
-
break;
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
} else if (typeof input === "string") {
|
|
1787
|
-
target = input.trim().split("\n")[0];
|
|
1788
|
-
}
|
|
1789
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
1790
|
-
return target ? `${tool} ${target}` : tool;
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
1918
|
// src/core/session-start.ts
|
|
1794
|
-
import { readFileSync as
|
|
1919
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
1795
1920
|
|
|
1796
1921
|
// src/core/git.ts
|
|
1797
1922
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -1801,34 +1926,57 @@ import { resolve as resolve2 } from "path";
|
|
|
1801
1926
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
1802
1927
|
|
|
1803
1928
|
// src/core/survey.ts
|
|
1804
|
-
import { spawn as
|
|
1929
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
1930
|
+
import { createHash as createHash4 } from "crypto";
|
|
1805
1931
|
import { existsSync as existsSync3 } from "fs";
|
|
1806
|
-
import { homedir as homedir3 } from "os";
|
|
1807
|
-
import { dirname as
|
|
1932
|
+
import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
|
|
1933
|
+
import { dirname as dirname8, join as join11 } from "path";
|
|
1808
1934
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1809
1935
|
|
|
1936
|
+
// src/core/survey-lease.ts
|
|
1937
|
+
import { spawn as realSpawn3 } from "child_process";
|
|
1938
|
+
import { randomUUID } from "crypto";
|
|
1939
|
+
import {
|
|
1940
|
+
mkdirSync as mkdirSync4,
|
|
1941
|
+
mkdtempSync,
|
|
1942
|
+
readdirSync,
|
|
1943
|
+
renameSync as renameSync2,
|
|
1944
|
+
rmdirSync,
|
|
1945
|
+
rmSync as rmSync2,
|
|
1946
|
+
statSync as statSync3,
|
|
1947
|
+
unlinkSync,
|
|
1948
|
+
utimesSync,
|
|
1949
|
+
writeFileSync as writeFileSync2
|
|
1950
|
+
} from "fs";
|
|
1951
|
+
import { join as join10 } from "path";
|
|
1952
|
+
|
|
1810
1953
|
// src/core/auto-update.ts
|
|
1811
|
-
import { spawn as
|
|
1954
|
+
import { spawn as realSpawn5 } from "child_process";
|
|
1812
1955
|
import {
|
|
1813
1956
|
existsSync as existsSync4,
|
|
1814
|
-
mkdirSync as
|
|
1815
|
-
readFileSync as
|
|
1957
|
+
mkdirSync as mkdirSync5,
|
|
1958
|
+
readFileSync as readFileSync7,
|
|
1816
1959
|
realpathSync as realpathSync2,
|
|
1817
|
-
unlinkSync,
|
|
1818
|
-
writeFileSync as
|
|
1960
|
+
unlinkSync as unlinkSync2,
|
|
1961
|
+
writeFileSync as writeFileSync3
|
|
1819
1962
|
} from "fs";
|
|
1820
|
-
import { homedir as homedir4, tmpdir as
|
|
1821
|
-
import { dirname as
|
|
1963
|
+
import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
|
|
1964
|
+
import { dirname as dirname9, join as join12 } from "path";
|
|
1822
1965
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1823
1966
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
1824
1967
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
1825
1968
|
|
|
1826
1969
|
// src/core/skill-sync.ts
|
|
1827
|
-
import { cpSync, existsSync as existsSync5, readFileSync as
|
|
1970
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
1828
1971
|
import { homedir as homedir5 } from "os";
|
|
1829
|
-
import { dirname as
|
|
1972
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
1830
1973
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
1831
1974
|
|
|
1975
|
+
// src/core/legacy.ts
|
|
1976
|
+
import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
|
|
1977
|
+
import { homedir as homedir6 } from "os";
|
|
1978
|
+
import { join as join14, relative, isAbsolute as isAbsolute2 } from "path";
|
|
1979
|
+
|
|
1832
1980
|
// src/core/transcript-codex.ts
|
|
1833
1981
|
function isSyntheticUserText(text) {
|
|
1834
1982
|
const s = text.trimStart();
|
|
@@ -1959,19 +2107,19 @@ function readCopilotTranscript(path) {
|
|
|
1959
2107
|
}
|
|
1960
2108
|
|
|
1961
2109
|
// src/core/transcript-grok.ts
|
|
1962
|
-
import { existsSync as
|
|
1963
|
-
import { homedir as
|
|
1964
|
-
import { join as
|
|
2110
|
+
import { existsSync as existsSync7, readFileSync as readFileSync11, readdirSync as readdirSync2 } from "fs";
|
|
2111
|
+
import { homedir as homedir7 } from "os";
|
|
2112
|
+
import { join as join15 } from "path";
|
|
1965
2113
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
1966
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
1967
|
-
const sessionsDir =
|
|
1968
|
-
const direct =
|
|
1969
|
-
if (
|
|
2114
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join15(homedir7(), ".grok")) {
|
|
2115
|
+
const sessionsDir = join15(grokHome, "sessions");
|
|
2116
|
+
const direct = join15(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
2117
|
+
if (existsSync7(direct)) return direct;
|
|
1970
2118
|
try {
|
|
1971
|
-
for (const candidate of
|
|
1972
|
-
const directory =
|
|
1973
|
-
if (
|
|
1974
|
-
return
|
|
2119
|
+
for (const candidate of readdirSync2(sessionsDir)) {
|
|
2120
|
+
const directory = join15(sessionsDir, candidate);
|
|
2121
|
+
if (readFileSync11(join15(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2122
|
+
return join15(directory, sessionId, CHAT_HISTORY);
|
|
1975
2123
|
}
|
|
1976
2124
|
}
|
|
1977
2125
|
} catch {
|
|
@@ -2006,12 +2154,12 @@ function readGrokTranscript(path) {
|
|
|
2006
2154
|
}
|
|
2007
2155
|
|
|
2008
2156
|
// src/core/transcript-devin.ts
|
|
2009
|
-
import { existsSync as
|
|
2157
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2010
2158
|
import { createRequire } from "module";
|
|
2011
|
-
import { homedir as
|
|
2012
|
-
import { join as
|
|
2013
|
-
function devinSessionDb(home =
|
|
2014
|
-
return
|
|
2159
|
+
import { homedir as homedir8 } from "os";
|
|
2160
|
+
import { join as join16 } from "path";
|
|
2161
|
+
function devinSessionDb(home = homedir8()) {
|
|
2162
|
+
return join16(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2015
2163
|
}
|
|
2016
2164
|
function parseDevinMessages(nodes) {
|
|
2017
2165
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2048,7 +2196,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2048
2196
|
diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
|
|
2049
2197
|
return [];
|
|
2050
2198
|
}
|
|
2051
|
-
if (!
|
|
2199
|
+
if (!existsSync8(dbPath)) {
|
|
2052
2200
|
diag("devin-cli", "session_db_missing", { dbPath });
|
|
2053
2201
|
return [];
|
|
2054
2202
|
}
|
|
@@ -2320,6 +2468,51 @@ function readDroidTranscript(path) {
|
|
|
2320
2468
|
return turns;
|
|
2321
2469
|
}
|
|
2322
2470
|
|
|
2471
|
+
// src/core/transcript-zcode.ts
|
|
2472
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
2473
|
+
function messageText2(content) {
|
|
2474
|
+
if (typeof content === "string") return content.trim();
|
|
2475
|
+
if (!Array.isArray(content)) return "";
|
|
2476
|
+
return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
|
|
2477
|
+
}
|
|
2478
|
+
function readZcodeTranscript(path) {
|
|
2479
|
+
if (!path) return [];
|
|
2480
|
+
let body;
|
|
2481
|
+
try {
|
|
2482
|
+
body = readFileSync12(path, "utf8");
|
|
2483
|
+
} catch {
|
|
2484
|
+
return [];
|
|
2485
|
+
}
|
|
2486
|
+
const turns = [];
|
|
2487
|
+
for (const line of body.split("\n")) {
|
|
2488
|
+
const trimmed = line.trim();
|
|
2489
|
+
if (!trimmed) continue;
|
|
2490
|
+
let parsed;
|
|
2491
|
+
try {
|
|
2492
|
+
parsed = JSON.parse(trimmed);
|
|
2493
|
+
} catch {
|
|
2494
|
+
continue;
|
|
2495
|
+
}
|
|
2496
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
2497
|
+
const record = parsed;
|
|
2498
|
+
const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
|
|
2499
|
+
const role = typeof message?.role === "string" ? message.role : record.type;
|
|
2500
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
2501
|
+
const content = stripInjectedMemory(messageText2(message?.content)).trim();
|
|
2502
|
+
if (!content) continue;
|
|
2503
|
+
turns.push({
|
|
2504
|
+
role,
|
|
2505
|
+
content,
|
|
2506
|
+
...typeof record.timestamp === "string" ? { timestamp: record.timestamp } : {}
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
return turns;
|
|
2510
|
+
}
|
|
2511
|
+
function zcodeAssistantText(path) {
|
|
2512
|
+
if (!path) return "";
|
|
2513
|
+
return readZcodeTranscript(path).filter((turn) => turn.role === "assistant").at(-1)?.content ?? "";
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2323
2516
|
// src/harness/hook-lifecycle.ts
|
|
2324
2517
|
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
2325
2518
|
var claudePrompt = {
|
|
@@ -2360,6 +2553,7 @@ var qwenPrompt = {
|
|
|
2360
2553
|
sessionId: ev.session_id
|
|
2361
2554
|
})
|
|
2362
2555
|
};
|
|
2556
|
+
var zcodeSessionId = (ev) => ev.session_id ?? ev.sessionId;
|
|
2363
2557
|
var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
|
|
2364
2558
|
var antigravityPrompt = {
|
|
2365
2559
|
harness: "antigravity-cli",
|
|
@@ -2702,6 +2896,56 @@ var HOOK_HARNESSES = {
|
|
|
2702
2896
|
}),
|
|
2703
2897
|
readTranscript: readDroidTranscript
|
|
2704
2898
|
}
|
|
2899
|
+
},
|
|
2900
|
+
/**
|
|
2901
|
+
* ZCode (Z.ai's GLM coding agent) embeds the Claude Code agent runtime, so its hook PROTOCOL is
|
|
2902
|
+
* Claude's — `prompt`/`cwd` in, `hookSpecificOutput.additionalContext` + `systemMessage` out —
|
|
2903
|
+
* with `sessionId` accepted alongside `session_id`, which its Stop payload sends instead.
|
|
2904
|
+
*
|
|
2905
|
+
* What is not Claude's is the TRANSCRIPT, and that is the whole of the difference here. ZCode
|
|
2906
|
+
* keeps no durable session file: `Stop` carries the reply in `responseText` plus a temp,
|
|
2907
|
+
* assistant-only transcript it deletes as soon as the hook returns, and no user prompt at all.
|
|
2908
|
+
* So this is the one harness that retains from the plugin's own journal (core/turn-journal.ts) —
|
|
2909
|
+
* the prompt hook appends the user turn, `journal.assistantText` closes it with the reply — and
|
|
2910
|
+
* everything downstream (cursor, append, stamping) sees the same full conversation as any host
|
|
2911
|
+
* transcript.
|
|
2912
|
+
*/
|
|
2913
|
+
zcode: {
|
|
2914
|
+
configStyle: "process",
|
|
2915
|
+
// ZCode's `timeoutMs`, so MILLISECONDS — see the qwen-code note above for the same trap. The
|
|
2916
|
+
// prompt budget must stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
|
|
2917
|
+
timeoutUnit: "milliseconds",
|
|
2918
|
+
install: {
|
|
2919
|
+
sessionStart: { event: "SessionStart", entry: "zcode-sessionstart-hook.js", timeout: 3e4 },
|
|
2920
|
+
prompt: { event: "UserPromptSubmit", entry: "zcode-hook.js", timeout: 3e4 },
|
|
2921
|
+
stop: { event: "Stop", entry: "zcode-stop-hook.js", timeout: 6e4 }
|
|
2922
|
+
},
|
|
2923
|
+
sessionStart: {
|
|
2924
|
+
...standardSessionStart("zcode"),
|
|
2925
|
+
parse: (ev) => ({ cwd: ev.cwd, sessionId: zcodeSessionId(ev) })
|
|
2926
|
+
},
|
|
2927
|
+
prompt: {
|
|
2928
|
+
...claudePrompt,
|
|
2929
|
+
harness: "zcode",
|
|
2930
|
+
journalPrompt: true,
|
|
2931
|
+
parse: (ev) => ({
|
|
2932
|
+
prompt: ev.prompt ?? ev.user_prompt,
|
|
2933
|
+
cwd: ev.cwd,
|
|
2934
|
+
sessionId: zcodeSessionId(ev)
|
|
2935
|
+
})
|
|
2936
|
+
},
|
|
2937
|
+
retain: {
|
|
2938
|
+
hostTimeoutSec: 60,
|
|
2939
|
+
harness: "zcode",
|
|
2940
|
+
// No transcriptPath: the journal supplies it (see `journal` below).
|
|
2941
|
+
parse: (ev) => ({ sessionId: zcodeSessionId(ev), cwd: ev.cwd }),
|
|
2942
|
+
journal: {
|
|
2943
|
+
// `responseText` is the full reply and is what ZCode sends in practice. The ephemeral
|
|
2944
|
+
// transcript is the fallback when it is absent, and `responsePreview` — which is
|
|
2945
|
+
// TRUNCATED — is the last resort, preferred only over losing the turn entirely.
|
|
2946
|
+
assistantText: (ev) => (ev.responseText || zcodeAssistantText(ev.transcript_path) || ev.responsePreview || "").trim()
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2705
2949
|
}
|
|
2706
2950
|
};
|
|
2707
2951
|
var runHarnessPrompt = (harness) => runHook(HOOK_HARNESSES[harness].prompt);
|