@vectorize-io/hindsight-coding-agents 0.5.2 → 0.5.3
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 +286 -76
- package/dist/antigravity-statusline.js +17 -10
- package/dist/antigravity-stop-hook.js +297 -79
- package/dist/claude-hook.js +286 -76
- package/dist/claude-sessionstart-hook.js +252 -93
- package/dist/claude-stop-hook.js +297 -79
- package/dist/cline.js +74 -18
- package/dist/codex-hook.js +286 -76
- package/dist/codex-sessionstart-hook.js +252 -93
- package/dist/codex-stop-hook.js +297 -79
- package/dist/copilot-hook.js +286 -76
- package/dist/copilot-sessionstart-hook.js +252 -93
- package/dist/copilot-stop-hook.js +297 -79
- package/dist/cursor-hook.js +286 -76
- package/dist/cursor-sessionstart-hook.js +252 -93
- package/dist/cursor-stop-hook.js +297 -79
- package/dist/daemon-start.js +17 -10
- package/dist/dcode-hook.js +286 -76
- package/dist/dcode-sessionstart-hook.js +252 -93
- package/dist/dcode-stop-hook.js +297 -79
- package/dist/deepen.js +73 -19
- package/dist/devin-hook.js +286 -76
- package/dist/devin-sessionstart-hook.js +252 -93
- package/dist/devin-stop-hook.js +297 -79
- package/dist/droid-hook.js +286 -76
- package/dist/droid-sessionstart-hook.js +252 -93
- package/dist/droid-stop-hook.js +297 -79
- package/dist/dsh.js +111 -53
- package/dist/grok-hook.js +286 -76
- package/dist/grok-sessionstart-hook.js +252 -93
- package/dist/grok-stop-hook.js +297 -79
- package/dist/hindsight-seed.js +17 -10
- package/dist/index.js +113 -55
- package/dist/installer.js +383 -218
- package/dist/kilo.js +113 -55
- package/dist/mcp-server.js +67 -17
- package/dist/opencode2.js +113 -55
- package/dist/pi.js +112 -54
- package/dist/prime-agent.js +112 -54
- package/dist/qwen-hook.js +286 -76
- package/dist/qwen-sessionstart-hook.js +252 -93
- package/dist/qwen-stop-hook.js +297 -79
- package/dist/status.js +67 -17
- package/dist/zcode-hook.js +2920 -0
- package/dist/zcode-sessionstart-hook.js +3487 -0
- package/dist/zcode-stop-hook.js +3188 -0
- package/package.json +6 -3
- package/plugin.json +1 -1
- package/skill/SKILL.md +17 -7
|
@@ -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";
|
|
@@ -460,6 +460,7 @@ function pagesFor(project) {
|
|
|
460
460
|
var PAGE_MAX_TOKENS = 4096;
|
|
461
461
|
var PAGE_TAGS_MATCH = "all";
|
|
462
462
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
463
|
+
var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
|
|
463
464
|
var CRON_FIELD_RANGES = [
|
|
464
465
|
[0, 59],
|
|
465
466
|
// minute
|
|
@@ -513,14 +514,23 @@ function pageTriggerFor(trigger, bank, page) {
|
|
|
513
514
|
function buildPageTrigger(cfg = {}) {
|
|
514
515
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
515
516
|
switch (cfg.pageTriggerType) {
|
|
516
|
-
case "
|
|
517
|
-
return { ...base,
|
|
517
|
+
case "auto-refresh":
|
|
518
|
+
return { ...base, refresh_after_consolidation: true };
|
|
518
519
|
case "manual":
|
|
519
520
|
return { ...base, refresh_after_consolidation: false };
|
|
521
|
+
// "cron" and an unset type alike: the default schedule stands in for a missing expression, so
|
|
522
|
+
// a trigger built from a partial config is never a cron trigger with nothing to fire on.
|
|
520
523
|
default:
|
|
521
|
-
return { ...base,
|
|
524
|
+
return { ...base, refresh_cron: cfg.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
|
|
522
525
|
}
|
|
523
526
|
}
|
|
527
|
+
function pageTriggerDrifted(current2, desired) {
|
|
528
|
+
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);
|
|
529
|
+
}
|
|
530
|
+
function pageTriggerPatch(desired) {
|
|
531
|
+
if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
|
|
532
|
+
return desired;
|
|
533
|
+
}
|
|
524
534
|
var CODING_BANK_TEMPLATE = {
|
|
525
535
|
version: "1",
|
|
526
536
|
bank: {
|
|
@@ -1079,14 +1089,14 @@ var HindsightClient = class {
|
|
|
1079
1089
|
if (r.status !== 409) created++;
|
|
1080
1090
|
} else {
|
|
1081
1091
|
const sourceDrift = hit.description !== page.source_query;
|
|
1082
|
-
const triggerDrift = hit.trigger != null && hit.trigger
|
|
1092
|
+
const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
|
|
1083
1093
|
if (!sourceDrift && !triggerDrift) continue;
|
|
1084
1094
|
const patch = {};
|
|
1085
1095
|
if (sourceDrift) {
|
|
1086
1096
|
patch.source_query = page.source_query;
|
|
1087
1097
|
patch.tags = page.tags;
|
|
1088
1098
|
}
|
|
1089
|
-
if (triggerDrift) patch.trigger =
|
|
1099
|
+
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1090
1100
|
const r = await this.req(
|
|
1091
1101
|
"PATCH",
|
|
1092
1102
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
@@ -1102,9 +1112,41 @@ var HindsightClient = class {
|
|
|
1102
1112
|
updated++;
|
|
1103
1113
|
}
|
|
1104
1114
|
}
|
|
1115
|
+
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1105
1116
|
this.log(
|
|
1106
|
-
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1117
|
+
`[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` : "")
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
|
|
1122
|
+
*
|
|
1123
|
+
* `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
|
|
1124
|
+
* an older default they are the same drift as the taxonomy — and on a real repo they are most of
|
|
1125
|
+
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
1126
|
+
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
1127
|
+
*
|
|
1128
|
+
* Only the trigger is touched. Their `name` and `source_query` are written once, from the
|
|
1129
|
+
* initiative's own title, and re-stating either would rebuild a page whose question never
|
|
1130
|
+
* changed. The tree read above is reused rather than re-fetched.
|
|
1131
|
+
*/
|
|
1132
|
+
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
1133
|
+
const folder = roots.find(
|
|
1134
|
+
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
1107
1135
|
);
|
|
1136
|
+
let updated = 0;
|
|
1137
|
+
for (const page of folder?.children ?? []) {
|
|
1138
|
+
if (page.kind !== "page" || page.trigger == null) continue;
|
|
1139
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
1140
|
+
if (!pageTriggerDrifted(page.trigger, desired)) continue;
|
|
1141
|
+
const r = await this.req(
|
|
1142
|
+
"PATCH",
|
|
1143
|
+
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1144
|
+
{ trigger: pageTriggerPatch(desired) }
|
|
1145
|
+
);
|
|
1146
|
+
if ([404, 405, 501].includes(r.status)) break;
|
|
1147
|
+
updated++;
|
|
1148
|
+
}
|
|
1149
|
+
return updated;
|
|
1108
1150
|
}
|
|
1109
1151
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
1110
1152
|
slugify(s) {
|
|
@@ -1127,11 +1169,13 @@ var HindsightClient = class {
|
|
|
1127
1169
|
let pageId = args.relatesToPageId;
|
|
1128
1170
|
if (!pageId) {
|
|
1129
1171
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1172
|
+
const subject = this.project ?? this.bank;
|
|
1130
1173
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1131
1174
|
name: args.title,
|
|
1132
|
-
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
|
|
1175
|
+
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),
|
|
1133
1176
|
parent_id: folderId,
|
|
1134
1177
|
tags: ["knowledge:feature-work"],
|
|
1178
|
+
max_tokens: PAGE_MAX_TOKENS,
|
|
1135
1179
|
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1136
1180
|
});
|
|
1137
1181
|
try {
|
|
@@ -1174,17 +1218,22 @@ var HindsightClient = class {
|
|
|
1174
1218
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
1175
1219
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1176
1220
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1177
|
-
function
|
|
1178
|
-
if (raw.pageTriggerType === "manual") return "manual";
|
|
1179
|
-
if (raw.pageTriggerType === "
|
|
1180
|
-
|
|
1181
|
-
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
1221
|
+
function resolvePageTrigger(raw) {
|
|
1222
|
+
if (raw.pageTriggerType === "manual") return { type: "manual" };
|
|
1223
|
+
if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
|
|
1224
|
+
if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
|
|
1182
1225
|
log.warn(
|
|
1183
1226
|
"config",
|
|
1184
|
-
|
|
1227
|
+
`ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
|
|
1185
1228
|
);
|
|
1186
|
-
|
|
1187
|
-
return "
|
|
1229
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1230
|
+
if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1231
|
+
if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
|
|
1232
|
+
log.warn(
|
|
1233
|
+
"config",
|
|
1234
|
+
`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)}`
|
|
1235
|
+
);
|
|
1236
|
+
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1188
1237
|
}
|
|
1189
1238
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1190
1239
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
@@ -1216,6 +1265,7 @@ function resolveObservationScopes(raw) {
|
|
|
1216
1265
|
function resolveConfig(raw = {}) {
|
|
1217
1266
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1218
1267
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
1268
|
+
const pageTrigger = resolvePageTrigger(raw);
|
|
1219
1269
|
return {
|
|
1220
1270
|
serverMode,
|
|
1221
1271
|
// Daemon mode resolves the URL HERE rather than at each call site: every entry point already
|
|
@@ -1250,8 +1300,8 @@ function resolveConfig(raw = {}) {
|
|
|
1250
1300
|
reflectBudget: resolveReflectBudget(raw),
|
|
1251
1301
|
autoReflect: raw.autoReflect ?? true,
|
|
1252
1302
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
1253
|
-
pageTriggerType:
|
|
1254
|
-
pageTriggerCron:
|
|
1303
|
+
pageTriggerType: pageTrigger.type,
|
|
1304
|
+
pageTriggerCron: pageTrigger.cron,
|
|
1255
1305
|
autoSeed: raw.autoSeed ?? true,
|
|
1256
1306
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1257
1307
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -1516,8 +1566,51 @@ function sessionRootDir(harness, sessionId, cwd) {
|
|
|
1516
1566
|
return cwd;
|
|
1517
1567
|
}
|
|
1518
1568
|
|
|
1569
|
+
// src/core/turn-journal.ts
|
|
1570
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, statSync } from "fs";
|
|
1571
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
1572
|
+
import { dirname as dirname6, join as join8 } from "path";
|
|
1573
|
+
|
|
1574
|
+
// src/core/transcript-util.ts
|
|
1575
|
+
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;
|
|
1576
|
+
function stripInjectedMemory(s) {
|
|
1577
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
1578
|
+
}
|
|
1579
|
+
var TARGET_KEYS = [
|
|
1580
|
+
"file_path",
|
|
1581
|
+
"path",
|
|
1582
|
+
"notebook_path",
|
|
1583
|
+
"command",
|
|
1584
|
+
"pattern",
|
|
1585
|
+
"query",
|
|
1586
|
+
"url",
|
|
1587
|
+
"name",
|
|
1588
|
+
"id"
|
|
1589
|
+
];
|
|
1590
|
+
var ACTION_TARGET_CAP = 100;
|
|
1591
|
+
function actionLine(tool, input) {
|
|
1592
|
+
let target = "";
|
|
1593
|
+
if (input && typeof input === "object") {
|
|
1594
|
+
const rec = input;
|
|
1595
|
+
for (const k of TARGET_KEYS) {
|
|
1596
|
+
const v = rec[k];
|
|
1597
|
+
if (typeof v === "string" && v.trim()) {
|
|
1598
|
+
target = v.trim().split("\n")[0];
|
|
1599
|
+
break;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
} else if (typeof input === "string") {
|
|
1603
|
+
target = input.trim().split("\n")[0];
|
|
1604
|
+
}
|
|
1605
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
1606
|
+
return target ? `${tool} ${target}` : tool;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
// src/core/turn-journal.ts
|
|
1610
|
+
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
1611
|
+
|
|
1519
1612
|
// src/core/retain-hook.ts
|
|
1520
|
-
import { readFileSync as
|
|
1613
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
1521
1614
|
|
|
1522
1615
|
// src/core/retain-cursor.ts
|
|
1523
1616
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -1529,7 +1622,7 @@ import { createHash as createHash3 } from "crypto";
|
|
|
1529
1622
|
|
|
1530
1623
|
// src/core/daemon.ts
|
|
1531
1624
|
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
1532
|
-
import { dirname as
|
|
1625
|
+
import { dirname as dirname7, join as join9 } from "path";
|
|
1533
1626
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1534
1627
|
var DAEMON_WAIT_SESSION_START_MS = 12e3;
|
|
1535
1628
|
async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
@@ -1603,7 +1696,7 @@ function onPath(bin) {
|
|
|
1603
1696
|
}
|
|
1604
1697
|
function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
|
|
1605
1698
|
try {
|
|
1606
|
-
const starter =
|
|
1699
|
+
const starter = join9(dirname7(fileURLToPath2(import.meta.url)), "daemon-start.js");
|
|
1607
1700
|
const child = spawnFn("node", [starter, "--harness", harness], {
|
|
1608
1701
|
detached: true,
|
|
1609
1702
|
stdio: "ignore",
|
|
@@ -1704,7 +1797,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
1704
1797
|
}
|
|
1705
1798
|
|
|
1706
1799
|
// src/core/jsonl.ts
|
|
1707
|
-
import { closeSync, openSync, readSync, statSync } from "fs";
|
|
1800
|
+
import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
|
|
1708
1801
|
import { StringDecoder } from "string_decoder";
|
|
1709
1802
|
var CHUNK_BYTES = 64 * 1024;
|
|
1710
1803
|
var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
|
|
@@ -1712,7 +1805,7 @@ function readJsonlTail(path, opts) {
|
|
|
1712
1805
|
const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
|
|
1713
1806
|
let size;
|
|
1714
1807
|
try {
|
|
1715
|
-
size =
|
|
1808
|
+
size = statSync2(path).size;
|
|
1716
1809
|
} catch {
|
|
1717
1810
|
return { lines: emptyLines(), skippedBytes: 0 };
|
|
1718
1811
|
}
|
|
@@ -1764,43 +1857,8 @@ function* streamLines(path, start) {
|
|
|
1764
1857
|
}
|
|
1765
1858
|
}
|
|
1766
1859
|
|
|
1767
|
-
// src/core/transcript-util.ts
|
|
1768
|
-
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;
|
|
1769
|
-
function stripInjectedMemory(s) {
|
|
1770
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
1771
|
-
}
|
|
1772
|
-
var TARGET_KEYS = [
|
|
1773
|
-
"file_path",
|
|
1774
|
-
"path",
|
|
1775
|
-
"notebook_path",
|
|
1776
|
-
"command",
|
|
1777
|
-
"pattern",
|
|
1778
|
-
"query",
|
|
1779
|
-
"url",
|
|
1780
|
-
"name",
|
|
1781
|
-
"id"
|
|
1782
|
-
];
|
|
1783
|
-
var ACTION_TARGET_CAP = 100;
|
|
1784
|
-
function actionLine(tool, input) {
|
|
1785
|
-
let target = "";
|
|
1786
|
-
if (input && typeof input === "object") {
|
|
1787
|
-
const rec = input;
|
|
1788
|
-
for (const k of TARGET_KEYS) {
|
|
1789
|
-
const v = rec[k];
|
|
1790
|
-
if (typeof v === "string" && v.trim()) {
|
|
1791
|
-
target = v.trim().split("\n")[0];
|
|
1792
|
-
break;
|
|
1793
|
-
}
|
|
1794
|
-
}
|
|
1795
|
-
} else if (typeof input === "string") {
|
|
1796
|
-
target = input.trim().split("\n")[0];
|
|
1797
|
-
}
|
|
1798
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
1799
|
-
return target ? `${tool} ${target}` : tool;
|
|
1800
|
-
}
|
|
1801
|
-
|
|
1802
1860
|
// src/core/session-start.ts
|
|
1803
|
-
import { readFileSync as
|
|
1861
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
1804
1862
|
|
|
1805
1863
|
// src/core/git.ts
|
|
1806
1864
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -1845,7 +1903,7 @@ import { execFileSync as execFileSync3 } from "child_process";
|
|
|
1845
1903
|
import { spawn as realSpawn3 } from "child_process";
|
|
1846
1904
|
import { existsSync as existsSync3 } from "fs";
|
|
1847
1905
|
import { homedir as homedir3 } from "os";
|
|
1848
|
-
import { dirname as
|
|
1906
|
+
import { dirname as dirname8, join as join10 } from "path";
|
|
1849
1907
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1850
1908
|
var SURVEY_DOC_IDS = [
|
|
1851
1909
|
"repository-component-map",
|
|
@@ -1856,7 +1914,7 @@ var SURVEY_DOC_IDS = [
|
|
|
1856
1914
|
function resolveClaudeBin(explicit) {
|
|
1857
1915
|
if (explicit) return explicit;
|
|
1858
1916
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
1859
|
-
const nativeInstallPath =
|
|
1917
|
+
const nativeInstallPath = join10(homedir3(), ".claude", "local", "claude");
|
|
1860
1918
|
try {
|
|
1861
1919
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
1862
1920
|
} catch {
|
|
@@ -1974,7 +2032,7 @@ function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
1974
2032
|
try {
|
|
1975
2033
|
const spawnFn = opts.spawn ?? realSpawn3;
|
|
1976
2034
|
const exists = opts.exists ?? binOnPath;
|
|
1977
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
2035
|
+
const mcpServerPath = opts.mcpServerPath ?? join10(dirname8(fileURLToPath3(import.meta.url)), "mcp-server.js");
|
|
1978
2036
|
const preferred = opts.harness ?? "claude-code";
|
|
1979
2037
|
const order = [
|
|
1980
2038
|
preferred,
|
|
@@ -2017,26 +2075,26 @@ var DEEPEN_DIFF_TARGET = 300;
|
|
|
2017
2075
|
import { spawn as realSpawn4 } from "child_process";
|
|
2018
2076
|
import {
|
|
2019
2077
|
existsSync as existsSync4,
|
|
2020
|
-
mkdirSync as
|
|
2021
|
-
readFileSync as
|
|
2078
|
+
mkdirSync as mkdirSync4,
|
|
2079
|
+
readFileSync as readFileSync7,
|
|
2022
2080
|
realpathSync as realpathSync2,
|
|
2023
2081
|
unlinkSync,
|
|
2024
2082
|
writeFileSync as writeFileSync2
|
|
2025
2083
|
} from "fs";
|
|
2026
|
-
import { homedir as homedir4, tmpdir as
|
|
2027
|
-
import { dirname as
|
|
2084
|
+
import { homedir as homedir4, tmpdir as tmpdir4 } from "os";
|
|
2085
|
+
import { dirname as dirname9, join as join11 } from "path";
|
|
2028
2086
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2029
2087
|
var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
2030
2088
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2031
2089
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
2032
2090
|
function stateFile(runtimeDir) {
|
|
2033
|
-
return
|
|
2091
|
+
return join11(runtimeDir, ".update-check.json");
|
|
2034
2092
|
}
|
|
2035
2093
|
function packageRoot() {
|
|
2036
|
-
return
|
|
2094
|
+
return join11(dirname9(fileURLToPath4(import.meta.url)), "..");
|
|
2037
2095
|
}
|
|
2038
2096
|
function stagedRuntimeDir() {
|
|
2039
|
-
return
|
|
2097
|
+
return join11(homedir4(), ".hindsight", "coding-agents");
|
|
2040
2098
|
}
|
|
2041
2099
|
function sameDir(a, b) {
|
|
2042
2100
|
try {
|
|
@@ -2047,7 +2105,7 @@ function sameDir(a, b) {
|
|
|
2047
2105
|
}
|
|
2048
2106
|
function stagedVersion(pkgRoot) {
|
|
2049
2107
|
try {
|
|
2050
|
-
const pkg = JSON.parse(
|
|
2108
|
+
const pkg = JSON.parse(readFileSync7(join11(pkgRoot, "package.json"), "utf8"));
|
|
2051
2109
|
return typeof pkg.version === "string" ? pkg.version : "";
|
|
2052
2110
|
} catch {
|
|
2053
2111
|
return "";
|
|
@@ -2072,7 +2130,7 @@ function isNewer(candidate, current2) {
|
|
|
2072
2130
|
}
|
|
2073
2131
|
function dueForCheck(file, now) {
|
|
2074
2132
|
try {
|
|
2075
|
-
const state = JSON.parse(
|
|
2133
|
+
const state = JSON.parse(readFileSync7(file, "utf8"));
|
|
2076
2134
|
return typeof state.lastCheck !== "number" || now - state.lastCheck >= CHECK_INTERVAL_MS;
|
|
2077
2135
|
} catch {
|
|
2078
2136
|
return true;
|
|
@@ -2081,7 +2139,7 @@ function dueForCheck(file, now) {
|
|
|
2081
2139
|
var ORIGIN_FILE = ".install-origin.json";
|
|
2082
2140
|
function selfUpdatable(runtimeDir) {
|
|
2083
2141
|
try {
|
|
2084
|
-
const origin = JSON.parse(
|
|
2142
|
+
const origin = JSON.parse(readFileSync7(join11(runtimeDir, ORIGIN_FILE), "utf8"));
|
|
2085
2143
|
if (typeof origin.source !== "string" || !origin.source) return false;
|
|
2086
2144
|
return origin.source.split(/[\\/]/).includes("_npx");
|
|
2087
2145
|
} catch {
|
|
@@ -2090,11 +2148,11 @@ function selfUpdatable(runtimeDir) {
|
|
|
2090
2148
|
}
|
|
2091
2149
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2092
2150
|
function lockFile() {
|
|
2093
|
-
return
|
|
2151
|
+
return join11(tmpdir4(), "hindsight-coding-agent", "auto-update.lock");
|
|
2094
2152
|
}
|
|
2095
2153
|
function acquireUpdateLock(file, now) {
|
|
2096
2154
|
try {
|
|
2097
|
-
const held = JSON.parse(
|
|
2155
|
+
const held = JSON.parse(readFileSync7(file, "utf8"));
|
|
2098
2156
|
if (held.ts && now - held.ts < LOCK_STALE_MS) {
|
|
2099
2157
|
let holderAlive = false;
|
|
2100
2158
|
if (held.pid) {
|
|
@@ -2109,7 +2167,7 @@ function acquireUpdateLock(file, now) {
|
|
|
2109
2167
|
} catch {
|
|
2110
2168
|
}
|
|
2111
2169
|
try {
|
|
2112
|
-
|
|
2170
|
+
mkdirSync4(dirname9(file), { recursive: true });
|
|
2113
2171
|
writeFileSync2(file, JSON.stringify({ pid: process.pid, ts: now }));
|
|
2114
2172
|
return true;
|
|
2115
2173
|
} catch {
|
|
@@ -2206,9 +2264,9 @@ async function maybeAutoUpdate(cfg, opts = {}) {
|
|
|
2206
2264
|
}
|
|
2207
2265
|
|
|
2208
2266
|
// src/core/skill-sync.ts
|
|
2209
|
-
import { cpSync, existsSync as existsSync5, readFileSync as
|
|
2267
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
2210
2268
|
import { homedir as homedir5 } from "os";
|
|
2211
|
-
import { dirname as
|
|
2269
|
+
import { dirname as dirname10, join as join12 } from "path";
|
|
2212
2270
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2213
2271
|
|
|
2214
2272
|
// src/core/skill-dirs.ts
|
|
@@ -2226,6 +2284,11 @@ var SKILL_DIRS = {
|
|
|
2226
2284
|
// Qwen's user-level skills root (Storage.getUserSkillsDirs)
|
|
2227
2285
|
"factory-droid": [".factory", "skills"],
|
|
2228
2286
|
// Droid's user-level skills root
|
|
2287
|
+
// ZCode scans TWO user roots by default (its resolveDefaultSkillRoots): `~/.zcode/skills` and the
|
|
2288
|
+
// shared agentskills `~/.agents/skills`. Write its OWN, for the same reason the pi family does —
|
|
2289
|
+
// skill removal is by fixed directory name, so installing into the shared root would make
|
|
2290
|
+
// `uninstall zcode` take Codex's and dsh's copy with it.
|
|
2291
|
+
zcode: [".zcode", "skills"],
|
|
2229
2292
|
// The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
|
|
2230
2293
|
// by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
|
|
2231
2294
|
// and dsh's copy with it.
|
|
@@ -2235,19 +2298,19 @@ var SKILL_DIRS = {
|
|
|
2235
2298
|
|
|
2236
2299
|
// src/core/skill-sync.ts
|
|
2237
2300
|
function packagedSkillDir() {
|
|
2238
|
-
return
|
|
2301
|
+
return join12(dirname10(fileURLToPath5(import.meta.url)), "..", "skill");
|
|
2239
2302
|
}
|
|
2240
2303
|
function syncCompanionSkill(harness, opts = {}) {
|
|
2241
2304
|
try {
|
|
2242
2305
|
const parts = SKILL_DIRS[harness];
|
|
2243
2306
|
if (!parts) return;
|
|
2244
2307
|
const src = opts.srcDir ?? packagedSkillDir();
|
|
2245
|
-
const srcMd =
|
|
2308
|
+
const srcMd = join12(src, "SKILL.md");
|
|
2246
2309
|
if (!existsSync5(srcMd)) return;
|
|
2247
|
-
const dst =
|
|
2248
|
-
const dstMd =
|
|
2310
|
+
const dst = join12(opts.home ?? homedir5(), ...parts, "hindsight-coding-agent");
|
|
2311
|
+
const dstMd = join12(dst, "SKILL.md");
|
|
2249
2312
|
if (!existsSync5(dstMd)) return;
|
|
2250
|
-
if (
|
|
2313
|
+
if (readFileSync8(srcMd, "utf8") !== readFileSync8(dstMd, "utf8")) {
|
|
2251
2314
|
cpSync(src, dst, { recursive: true });
|
|
2252
2315
|
}
|
|
2253
2316
|
} catch {
|
|
@@ -2408,7 +2471,7 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
|
|
|
2408
2471
|
try {
|
|
2409
2472
|
let ev = {};
|
|
2410
2473
|
try {
|
|
2411
|
-
ev = JSON.parse(
|
|
2474
|
+
ev = JSON.parse(readFileSync9(0, "utf8"));
|
|
2412
2475
|
} catch {
|
|
2413
2476
|
return;
|
|
2414
2477
|
}
|
|
@@ -2577,19 +2640,19 @@ function readCopilotTranscript(path) {
|
|
|
2577
2640
|
}
|
|
2578
2641
|
|
|
2579
2642
|
// src/core/transcript-grok.ts
|
|
2580
|
-
import { existsSync as existsSync6, readFileSync as
|
|
2643
|
+
import { existsSync as existsSync6, readFileSync as readFileSync10, readdirSync } from "fs";
|
|
2581
2644
|
import { homedir as homedir6 } from "os";
|
|
2582
|
-
import { join as
|
|
2645
|
+
import { join as join13 } from "path";
|
|
2583
2646
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2584
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2585
|
-
const sessionsDir =
|
|
2586
|
-
const direct =
|
|
2647
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join13(homedir6(), ".grok")) {
|
|
2648
|
+
const sessionsDir = join13(grokHome, "sessions");
|
|
2649
|
+
const direct = join13(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
2587
2650
|
if (existsSync6(direct)) return direct;
|
|
2588
2651
|
try {
|
|
2589
2652
|
for (const candidate of readdirSync(sessionsDir)) {
|
|
2590
|
-
const directory =
|
|
2591
|
-
if (
|
|
2592
|
-
return
|
|
2653
|
+
const directory = join13(sessionsDir, candidate);
|
|
2654
|
+
if (readFileSync10(join13(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2655
|
+
return join13(directory, sessionId, CHAT_HISTORY);
|
|
2593
2656
|
}
|
|
2594
2657
|
}
|
|
2595
2658
|
} catch {
|
|
@@ -2627,9 +2690,9 @@ function readGrokTranscript(path) {
|
|
|
2627
2690
|
import { existsSync as existsSync7 } from "fs";
|
|
2628
2691
|
import { createRequire } from "module";
|
|
2629
2692
|
import { homedir as homedir7 } from "os";
|
|
2630
|
-
import { join as
|
|
2693
|
+
import { join as join14 } from "path";
|
|
2631
2694
|
function devinSessionDb(home = homedir7()) {
|
|
2632
|
-
return
|
|
2695
|
+
return join14(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2633
2696
|
}
|
|
2634
2697
|
function parseDevinMessages(nodes) {
|
|
2635
2698
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2938,6 +3001,51 @@ function readDroidTranscript(path) {
|
|
|
2938
3001
|
return turns;
|
|
2939
3002
|
}
|
|
2940
3003
|
|
|
3004
|
+
// src/core/transcript-zcode.ts
|
|
3005
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
3006
|
+
function messageText2(content) {
|
|
3007
|
+
if (typeof content === "string") return content.trim();
|
|
3008
|
+
if (!Array.isArray(content)) return "";
|
|
3009
|
+
return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
|
|
3010
|
+
}
|
|
3011
|
+
function readZcodeTranscript(path) {
|
|
3012
|
+
if (!path) return [];
|
|
3013
|
+
let body;
|
|
3014
|
+
try {
|
|
3015
|
+
body = readFileSync11(path, "utf8");
|
|
3016
|
+
} catch {
|
|
3017
|
+
return [];
|
|
3018
|
+
}
|
|
3019
|
+
const turns = [];
|
|
3020
|
+
for (const line of body.split("\n")) {
|
|
3021
|
+
const trimmed = line.trim();
|
|
3022
|
+
if (!trimmed) continue;
|
|
3023
|
+
let parsed;
|
|
3024
|
+
try {
|
|
3025
|
+
parsed = JSON.parse(trimmed);
|
|
3026
|
+
} catch {
|
|
3027
|
+
continue;
|
|
3028
|
+
}
|
|
3029
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
3030
|
+
const record = parsed;
|
|
3031
|
+
const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
|
|
3032
|
+
const role = typeof message?.role === "string" ? message.role : record.type;
|
|
3033
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
3034
|
+
const content = stripInjectedMemory(messageText2(message?.content)).trim();
|
|
3035
|
+
if (!content) continue;
|
|
3036
|
+
turns.push({
|
|
3037
|
+
role,
|
|
3038
|
+
content,
|
|
3039
|
+
...typeof record.timestamp === "string" ? { timestamp: record.timestamp } : {}
|
|
3040
|
+
});
|
|
3041
|
+
}
|
|
3042
|
+
return turns;
|
|
3043
|
+
}
|
|
3044
|
+
function zcodeAssistantText(path) {
|
|
3045
|
+
if (!path) return "";
|
|
3046
|
+
return readZcodeTranscript(path).filter((turn) => turn.role === "assistant").at(-1)?.content ?? "";
|
|
3047
|
+
}
|
|
3048
|
+
|
|
2941
3049
|
// src/harness/hook-lifecycle.ts
|
|
2942
3050
|
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
2943
3051
|
var claudePrompt = {
|
|
@@ -2978,6 +3086,7 @@ var qwenPrompt = {
|
|
|
2978
3086
|
sessionId: ev.session_id
|
|
2979
3087
|
})
|
|
2980
3088
|
};
|
|
3089
|
+
var zcodeSessionId = (ev) => ev.session_id ?? ev.sessionId;
|
|
2981
3090
|
var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
|
|
2982
3091
|
var antigravityPrompt = {
|
|
2983
3092
|
harness: "antigravity-cli",
|
|
@@ -3320,6 +3429,56 @@ var HOOK_HARNESSES = {
|
|
|
3320
3429
|
}),
|
|
3321
3430
|
readTranscript: readDroidTranscript
|
|
3322
3431
|
}
|
|
3432
|
+
},
|
|
3433
|
+
/**
|
|
3434
|
+
* ZCode (Z.ai's GLM coding agent) embeds the Claude Code agent runtime, so its hook PROTOCOL is
|
|
3435
|
+
* Claude's — `prompt`/`cwd` in, `hookSpecificOutput.additionalContext` + `systemMessage` out —
|
|
3436
|
+
* with `sessionId` accepted alongside `session_id`, which its Stop payload sends instead.
|
|
3437
|
+
*
|
|
3438
|
+
* What is not Claude's is the TRANSCRIPT, and that is the whole of the difference here. ZCode
|
|
3439
|
+
* keeps no durable session file: `Stop` carries the reply in `responseText` plus a temp,
|
|
3440
|
+
* assistant-only transcript it deletes as soon as the hook returns, and no user prompt at all.
|
|
3441
|
+
* So this is the one harness that retains from the plugin's own journal (core/turn-journal.ts) —
|
|
3442
|
+
* the prompt hook appends the user turn, `journal.assistantText` closes it with the reply — and
|
|
3443
|
+
* everything downstream (cursor, append, stamping) sees the same full conversation as any host
|
|
3444
|
+
* transcript.
|
|
3445
|
+
*/
|
|
3446
|
+
zcode: {
|
|
3447
|
+
configStyle: "process",
|
|
3448
|
+
// ZCode's `timeoutMs`, so MILLISECONDS — see the qwen-code note above for the same trap. The
|
|
3449
|
+
// prompt budget must stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
|
|
3450
|
+
timeoutUnit: "milliseconds",
|
|
3451
|
+
install: {
|
|
3452
|
+
sessionStart: { event: "SessionStart", entry: "zcode-sessionstart-hook.js", timeout: 3e4 },
|
|
3453
|
+
prompt: { event: "UserPromptSubmit", entry: "zcode-hook.js", timeout: 3e4 },
|
|
3454
|
+
stop: { event: "Stop", entry: "zcode-stop-hook.js", timeout: 6e4 }
|
|
3455
|
+
},
|
|
3456
|
+
sessionStart: {
|
|
3457
|
+
...standardSessionStart("zcode"),
|
|
3458
|
+
parse: (ev) => ({ cwd: ev.cwd, sessionId: zcodeSessionId(ev) })
|
|
3459
|
+
},
|
|
3460
|
+
prompt: {
|
|
3461
|
+
...claudePrompt,
|
|
3462
|
+
harness: "zcode",
|
|
3463
|
+
journalPrompt: true,
|
|
3464
|
+
parse: (ev) => ({
|
|
3465
|
+
prompt: ev.prompt ?? ev.user_prompt,
|
|
3466
|
+
cwd: ev.cwd,
|
|
3467
|
+
sessionId: zcodeSessionId(ev)
|
|
3468
|
+
})
|
|
3469
|
+
},
|
|
3470
|
+
retain: {
|
|
3471
|
+
hostTimeoutSec: 60,
|
|
3472
|
+
harness: "zcode",
|
|
3473
|
+
// No transcriptPath: the journal supplies it (see `journal` below).
|
|
3474
|
+
parse: (ev) => ({ sessionId: zcodeSessionId(ev), cwd: ev.cwd }),
|
|
3475
|
+
journal: {
|
|
3476
|
+
// `responseText` is the full reply and is what ZCode sends in practice. The ephemeral
|
|
3477
|
+
// transcript is the fallback when it is absent, and `responsePreview` — which is
|
|
3478
|
+
// TRUNCATED — is the last resort, preferred only over losing the turn entirely.
|
|
3479
|
+
assistantText: (ev) => (ev.responseText || zcodeAssistantText(ev.transcript_path) || ev.responsePreview || "").trim()
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3323
3482
|
}
|
|
3324
3483
|
};
|
|
3325
3484
|
var runHarnessSessionStart = (harness) => runSessionStartHook(HOOK_HARNESSES[harness].sessionStart);
|