@vectorize-io/hindsight-coding-agents 0.5.1 → 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 +84 -9
- package/dist/antigravity-hook.js +424 -81
- package/dist/antigravity-statusline.js +56 -11
- package/dist/antigravity-stop-hook.js +515 -134
- package/dist/claude-hook.js +424 -81
- package/dist/claude-sessionstart-hook.js +392 -98
- package/dist/claude-stop-hook.js +515 -134
- package/dist/cline.js +218 -73
- package/dist/codex-hook.js +424 -81
- package/dist/codex-sessionstart-hook.js +392 -98
- package/dist/codex-stop-hook.js +515 -134
- package/dist/copilot-hook.js +424 -81
- package/dist/copilot-sessionstart-hook.js +392 -98
- package/dist/copilot-stop-hook.js +515 -134
- package/dist/cursor-hook.js +424 -81
- package/dist/cursor-sessionstart-hook.js +392 -98
- package/dist/cursor-stop-hook.js +515 -134
- package/dist/daemon-start.js +50 -9
- package/dist/dcode-hook.js +424 -81
- package/dist/dcode-sessionstart-hook.js +392 -98
- package/dist/dcode-stop-hook.js +515 -134
- package/dist/deepen.js +164 -27
- package/dist/devin-hook.js +424 -81
- package/dist/devin-sessionstart-hook.js +392 -98
- package/dist/devin-stop-hook.js +515 -134
- package/dist/droid-hook.js +2920 -0
- package/dist/droid-sessionstart-hook.js +3487 -0
- package/dist/droid-stop-hook.js +3188 -0
- package/dist/dsh.js +260 -109
- package/dist/grok-hook.js +424 -81
- package/dist/grok-sessionstart-hook.js +392 -98
- package/dist/grok-stop-hook.js +515 -134
- package/dist/hindsight-seed.js +56 -11
- package/dist/index.js +257 -110
- package/dist/installer.js +530 -223
- package/dist/kilo.js +257 -110
- package/dist/mcp-server.js +537 -146
- package/dist/opencode2.js +257 -110
- package/dist/pi.js +256 -109
- package/dist/prime-agent.js +256 -109
- package/dist/qwen-hook.js +424 -81
- package/dist/qwen-sessionstart-hook.js +392 -98
- package/dist/qwen-stop-hook.js +515 -134
- package/dist/status.js +128 -20
- 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 +11 -5
- package/plugin.json +1 -1
- package/skill/SKILL.md +42 -8
|
@@ -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";
|
|
@@ -276,9 +276,13 @@ function isOptedIn(config, directory) {
|
|
|
276
276
|
const pathMap = config.mapPathToBank;
|
|
277
277
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
278
278
|
}
|
|
279
|
-
function
|
|
279
|
+
function mappedBank(config, directory, sessionRoot) {
|
|
280
280
|
const pathMap = config.mapPathToBank;
|
|
281
|
-
|
|
281
|
+
if (!directory || !pathMap) return void 0;
|
|
282
|
+
return lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
283
|
+
}
|
|
284
|
+
function deriveBankId(config, directory, harness = "coding", sessionRoot) {
|
|
285
|
+
const mapped = mappedBank(config, directory, sessionRoot);
|
|
282
286
|
if (mapped) return mapped;
|
|
283
287
|
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
284
288
|
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
@@ -344,6 +348,7 @@ function startBackgroundSeed(repoDir, opts = {}) {
|
|
|
344
348
|
}
|
|
345
349
|
|
|
346
350
|
// src/core/missions.ts
|
|
351
|
+
import { createHash } from "crypto";
|
|
347
352
|
var GIT_MISSION = "You are ingesting a single git commit: its message and its full diff. Extract the concrete technical DECISION and the CAUSE/INVARIANT it encodes, bound to the specific code entities (functions, methods, files) and behaviors it changes. Preserve exact identifiers, paths, and literal values verbatim. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Capture both WHAT changed and WHY. Issue/PR references (#123, GH-123, PROJ-123) are load-bearing: keep them VERBATIM in the fact text and emit each as an ENTITY, so a later question about that issue or PR retrieves this decision.";
|
|
348
353
|
var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history, newest first. Extract the project's INITIATIVES, FEATURES, ENHANCEMENTS, and notable changes or THEMES over time \u2014 what the project has been working on and how it has evolved. Do NOT extract per-line code detail (there is no diff to draw it from). Group related commits into a coherent initiative/theme where the messages make that clear; preserve exact identifiers and literal values verbatim when quoting a subject line. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY \u2014 they are how future sessions will ask about this work.";
|
|
349
354
|
var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSONL transcript (one {role, content} turn per line): the user's requests, the assistant's narration, and compact 'action' turns naming each tool use and its target (e.g. "Edit boltons/strutils.py") with no arguments or outputs. It may be a SHORT decision chat or a LONG working session \u2014 scale the facts to the substance, never to the message count. Extract the FEWEST facts that capture the OUTCOME: the settled DECISIONS and their exact rules/values (quote literals VERBATIM); concrete CHANGES to specific code entities; problems and how they were resolved; conventions or invariants established; at most one fact for a notable REJECTED alternative ('initially proposed X, changed to Y because Z'). A short decision chat usually yields 1-2 facts; a substantial working session several. CRITICAL: a conversation REVISES itself \u2014 record ONLY the FINAL state as what is in effect; a superseded proposal appears ONLY inside the rejected fact, NEVER as its own 'decided' fact; if the same setting changes several times keep only the LAST, and make unmistakably clear which choice WON. Do NOT emit one fact per message, per intermediate proposal, or per action turn. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Do not invent; capture only what was actually settled.`;
|
|
@@ -455,17 +460,77 @@ function pagesFor(project) {
|
|
|
455
460
|
var PAGE_MAX_TOKENS = 4096;
|
|
456
461
|
var PAGE_TAGS_MATCH = "all";
|
|
457
462
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
463
|
+
var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
|
|
464
|
+
var CRON_FIELD_RANGES = [
|
|
465
|
+
[0, 59],
|
|
466
|
+
// minute
|
|
467
|
+
[0, 23],
|
|
468
|
+
// hour
|
|
469
|
+
[1, 31],
|
|
470
|
+
// day of month
|
|
471
|
+
[1, 12],
|
|
472
|
+
// month
|
|
473
|
+
[0, 6]
|
|
474
|
+
// day of week
|
|
475
|
+
];
|
|
476
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
477
|
+
function isHashedCron(cron) {
|
|
478
|
+
return /(^|\s)H/.test(cron);
|
|
479
|
+
}
|
|
480
|
+
function parseHashedCron(cron) {
|
|
481
|
+
const fields = cron.trim().split(/\s+/);
|
|
482
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
483
|
+
for (const [i, field] of fields.entries()) {
|
|
484
|
+
if (!field.startsWith("H")) continue;
|
|
485
|
+
const m = HASHED_FIELD.exec(field);
|
|
486
|
+
if (!m) return void 0;
|
|
487
|
+
if (m[1] === void 0) continue;
|
|
488
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
489
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
490
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
491
|
+
}
|
|
492
|
+
return fields;
|
|
493
|
+
}
|
|
494
|
+
function hashedValue(seed, field, lo, hi) {
|
|
495
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
496
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
497
|
+
}
|
|
498
|
+
function expandCronHash(cron, seed) {
|
|
499
|
+
if (!isHashedCron(cron)) return cron;
|
|
500
|
+
const fields = parseHashedCron(cron);
|
|
501
|
+
if (!fields) return cron;
|
|
502
|
+
return fields.map((field, i) => {
|
|
503
|
+
const m = HASHED_FIELD.exec(field);
|
|
504
|
+
if (!m) return field;
|
|
505
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
506
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
507
|
+
}).join(" ");
|
|
508
|
+
}
|
|
509
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
510
|
+
const cron = trigger.refresh_cron;
|
|
511
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
512
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
513
|
+
}
|
|
458
514
|
function buildPageTrigger(cfg = {}) {
|
|
459
515
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
460
516
|
switch (cfg.pageTriggerType) {
|
|
461
|
-
case "
|
|
462
|
-
return { ...base,
|
|
517
|
+
case "auto-refresh":
|
|
518
|
+
return { ...base, refresh_after_consolidation: true };
|
|
463
519
|
case "manual":
|
|
464
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.
|
|
465
523
|
default:
|
|
466
|
-
return { ...base,
|
|
524
|
+
return { ...base, refresh_cron: cfg.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
|
|
467
525
|
}
|
|
468
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
|
+
}
|
|
469
534
|
var CODING_BANK_TEMPLATE = {
|
|
470
535
|
version: "1",
|
|
471
536
|
bank: {
|
|
@@ -1008,7 +1073,9 @@ var HindsightClient = class {
|
|
|
1008
1073
|
source_query: page.source_query,
|
|
1009
1074
|
tags: page.tags,
|
|
1010
1075
|
max_tokens: PAGE_MAX_TOKENS,
|
|
1011
|
-
|
|
1076
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
1077
|
+
// and one trigger is built per session for all of them.
|
|
1078
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
1012
1079
|
};
|
|
1013
1080
|
if (!hit) {
|
|
1014
1081
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -1022,14 +1089,14 @@ var HindsightClient = class {
|
|
|
1022
1089
|
if (r.status !== 409) created++;
|
|
1023
1090
|
} else {
|
|
1024
1091
|
const sourceDrift = hit.description !== page.source_query;
|
|
1025
|
-
const triggerDrift = hit.trigger != null && hit.trigger
|
|
1092
|
+
const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
|
|
1026
1093
|
if (!sourceDrift && !triggerDrift) continue;
|
|
1027
1094
|
const patch = {};
|
|
1028
1095
|
if (sourceDrift) {
|
|
1029
1096
|
patch.source_query = page.source_query;
|
|
1030
1097
|
patch.tags = page.tags;
|
|
1031
1098
|
}
|
|
1032
|
-
if (triggerDrift) patch.trigger =
|
|
1099
|
+
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1033
1100
|
const r = await this.req(
|
|
1034
1101
|
"PATCH",
|
|
1035
1102
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
@@ -1045,9 +1112,41 @@ var HindsightClient = class {
|
|
|
1045
1112
|
updated++;
|
|
1046
1113
|
}
|
|
1047
1114
|
}
|
|
1115
|
+
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1048
1116
|
this.log(
|
|
1049
|
-
`[bank] knowledge pages seeded on ${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"
|
|
1050
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;
|
|
1051
1150
|
}
|
|
1052
1151
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
1053
1152
|
slugify(s) {
|
|
@@ -1070,12 +1169,14 @@ var HindsightClient = class {
|
|
|
1070
1169
|
let pageId = args.relatesToPageId;
|
|
1071
1170
|
if (!pageId) {
|
|
1072
1171
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1172
|
+
const subject = this.project ?? this.bank;
|
|
1073
1173
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1074
1174
|
name: args.title,
|
|
1075
|
-
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),
|
|
1076
1176
|
parent_id: folderId,
|
|
1077
1177
|
tags: ["knowledge:feature-work"],
|
|
1078
|
-
|
|
1178
|
+
max_tokens: PAGE_MAX_TOKENS,
|
|
1179
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1079
1180
|
});
|
|
1080
1181
|
try {
|
|
1081
1182
|
const j = await r.json();
|
|
@@ -1117,16 +1218,22 @@ var HindsightClient = class {
|
|
|
1117
1218
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
1118
1219
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1119
1220
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1120
|
-
function
|
|
1121
|
-
if (raw.pageTriggerType === "manual") return "manual";
|
|
1122
|
-
if (raw.pageTriggerType === "
|
|
1123
|
-
|
|
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")
|
|
1124
1225
|
log.warn(
|
|
1125
1226
|
"config",
|
|
1126
|
-
|
|
1227
|
+
`ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
|
|
1127
1228
|
);
|
|
1128
|
-
|
|
1129
|
-
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 };
|
|
1130
1237
|
}
|
|
1131
1238
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1132
1239
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
@@ -1158,6 +1265,7 @@ function resolveObservationScopes(raw) {
|
|
|
1158
1265
|
function resolveConfig(raw = {}) {
|
|
1159
1266
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1160
1267
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
1268
|
+
const pageTrigger = resolvePageTrigger(raw);
|
|
1161
1269
|
return {
|
|
1162
1270
|
serverMode,
|
|
1163
1271
|
// Daemon mode resolves the URL HERE rather than at each call site: every entry point already
|
|
@@ -1192,8 +1300,8 @@ function resolveConfig(raw = {}) {
|
|
|
1192
1300
|
reflectBudget: resolveReflectBudget(raw),
|
|
1193
1301
|
autoReflect: raw.autoReflect ?? true,
|
|
1194
1302
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
1195
|
-
pageTriggerType:
|
|
1196
|
-
pageTriggerCron:
|
|
1303
|
+
pageTriggerType: pageTrigger.type,
|
|
1304
|
+
pageTriggerCron: pageTrigger.cron,
|
|
1197
1305
|
autoSeed: raw.autoSeed ?? true,
|
|
1198
1306
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1199
1307
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -1458,18 +1566,63 @@ function sessionRootDir(harness, sessionId, cwd) {
|
|
|
1458
1566
|
return cwd;
|
|
1459
1567
|
}
|
|
1460
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
|
+
|
|
1461
1612
|
// src/core/retain-hook.ts
|
|
1462
|
-
import { readFileSync as
|
|
1613
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
1463
1614
|
|
|
1464
1615
|
// src/core/retain-cursor.ts
|
|
1465
|
-
import { createHash } from "crypto";
|
|
1616
|
+
import { createHash as createHash2 } from "crypto";
|
|
1617
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
1618
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
1466
1619
|
|
|
1467
1620
|
// src/core/uuid.ts
|
|
1468
|
-
import { createHash as
|
|
1621
|
+
import { createHash as createHash3 } from "crypto";
|
|
1469
1622
|
|
|
1470
1623
|
// src/core/daemon.ts
|
|
1471
1624
|
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
1472
|
-
import { dirname as
|
|
1625
|
+
import { dirname as dirname7, join as join9 } from "path";
|
|
1473
1626
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1474
1627
|
var DAEMON_WAIT_SESSION_START_MS = 12e3;
|
|
1475
1628
|
async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
@@ -1543,7 +1696,7 @@ function onPath(bin) {
|
|
|
1543
1696
|
}
|
|
1544
1697
|
function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
|
|
1545
1698
|
try {
|
|
1546
|
-
const starter =
|
|
1699
|
+
const starter = join9(dirname7(fileURLToPath2(import.meta.url)), "daemon-start.js");
|
|
1547
1700
|
const child = spawnFn("node", [starter, "--harness", harness], {
|
|
1548
1701
|
detached: true,
|
|
1549
1702
|
stdio: "ignore",
|
|
@@ -1644,7 +1797,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
1644
1797
|
}
|
|
1645
1798
|
|
|
1646
1799
|
// src/core/jsonl.ts
|
|
1647
|
-
import { closeSync, openSync, readSync, statSync } from "fs";
|
|
1800
|
+
import { closeSync, openSync, readSync, statSync as statSync2 } from "fs";
|
|
1648
1801
|
import { StringDecoder } from "string_decoder";
|
|
1649
1802
|
var CHUNK_BYTES = 64 * 1024;
|
|
1650
1803
|
var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
|
|
@@ -1652,7 +1805,7 @@ function readJsonlTail(path, opts) {
|
|
|
1652
1805
|
const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
|
|
1653
1806
|
let size;
|
|
1654
1807
|
try {
|
|
1655
|
-
size =
|
|
1808
|
+
size = statSync2(path).size;
|
|
1656
1809
|
} catch {
|
|
1657
1810
|
return { lines: emptyLines(), skippedBytes: 0 };
|
|
1658
1811
|
}
|
|
@@ -1704,43 +1857,8 @@ function* streamLines(path, start) {
|
|
|
1704
1857
|
}
|
|
1705
1858
|
}
|
|
1706
1859
|
|
|
1707
|
-
// src/core/transcript-util.ts
|
|
1708
|
-
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;
|
|
1709
|
-
function stripInjectedMemory(s) {
|
|
1710
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
1711
|
-
}
|
|
1712
|
-
var TARGET_KEYS = [
|
|
1713
|
-
"file_path",
|
|
1714
|
-
"path",
|
|
1715
|
-
"notebook_path",
|
|
1716
|
-
"command",
|
|
1717
|
-
"pattern",
|
|
1718
|
-
"query",
|
|
1719
|
-
"url",
|
|
1720
|
-
"name",
|
|
1721
|
-
"id"
|
|
1722
|
-
];
|
|
1723
|
-
var ACTION_TARGET_CAP = 100;
|
|
1724
|
-
function actionLine(tool, input) {
|
|
1725
|
-
let target = "";
|
|
1726
|
-
if (input && typeof input === "object") {
|
|
1727
|
-
const rec = input;
|
|
1728
|
-
for (const k of TARGET_KEYS) {
|
|
1729
|
-
const v = rec[k];
|
|
1730
|
-
if (typeof v === "string" && v.trim()) {
|
|
1731
|
-
target = v.trim().split("\n")[0];
|
|
1732
|
-
break;
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
} else if (typeof input === "string") {
|
|
1736
|
-
target = input.trim().split("\n")[0];
|
|
1737
|
-
}
|
|
1738
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
1739
|
-
return target ? `${tool} ${target}` : tool;
|
|
1740
|
-
}
|
|
1741
|
-
|
|
1742
1860
|
// src/core/session-start.ts
|
|
1743
|
-
import { readFileSync as
|
|
1861
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
1744
1862
|
|
|
1745
1863
|
// src/core/git.ts
|
|
1746
1864
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -1785,7 +1903,7 @@ import { execFileSync as execFileSync3 } from "child_process";
|
|
|
1785
1903
|
import { spawn as realSpawn3 } from "child_process";
|
|
1786
1904
|
import { existsSync as existsSync3 } from "fs";
|
|
1787
1905
|
import { homedir as homedir3 } from "os";
|
|
1788
|
-
import { dirname as
|
|
1906
|
+
import { dirname as dirname8, join as join10 } from "path";
|
|
1789
1907
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1790
1908
|
var SURVEY_DOC_IDS = [
|
|
1791
1909
|
"repository-component-map",
|
|
@@ -1796,7 +1914,7 @@ var SURVEY_DOC_IDS = [
|
|
|
1796
1914
|
function resolveClaudeBin(explicit) {
|
|
1797
1915
|
if (explicit) return explicit;
|
|
1798
1916
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
1799
|
-
const nativeInstallPath =
|
|
1917
|
+
const nativeInstallPath = join10(homedir3(), ".claude", "local", "claude");
|
|
1800
1918
|
try {
|
|
1801
1919
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
1802
1920
|
} catch {
|
|
@@ -1914,7 +2032,7 @@ function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
1914
2032
|
try {
|
|
1915
2033
|
const spawnFn = opts.spawn ?? realSpawn3;
|
|
1916
2034
|
const exists = opts.exists ?? binOnPath;
|
|
1917
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
2035
|
+
const mcpServerPath = opts.mcpServerPath ?? join10(dirname8(fileURLToPath3(import.meta.url)), "mcp-server.js");
|
|
1918
2036
|
const preferred = opts.harness ?? "claude-code";
|
|
1919
2037
|
const order = [
|
|
1920
2038
|
preferred,
|
|
@@ -1957,26 +2075,26 @@ var DEEPEN_DIFF_TARGET = 300;
|
|
|
1957
2075
|
import { spawn as realSpawn4 } from "child_process";
|
|
1958
2076
|
import {
|
|
1959
2077
|
existsSync as existsSync4,
|
|
1960
|
-
mkdirSync as
|
|
1961
|
-
readFileSync as
|
|
2078
|
+
mkdirSync as mkdirSync4,
|
|
2079
|
+
readFileSync as readFileSync7,
|
|
1962
2080
|
realpathSync as realpathSync2,
|
|
1963
2081
|
unlinkSync,
|
|
1964
2082
|
writeFileSync as writeFileSync2
|
|
1965
2083
|
} from "fs";
|
|
1966
|
-
import { homedir as homedir4, tmpdir as
|
|
1967
|
-
import { dirname as
|
|
2084
|
+
import { homedir as homedir4, tmpdir as tmpdir4 } from "os";
|
|
2085
|
+
import { dirname as dirname9, join as join11 } from "path";
|
|
1968
2086
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1969
2087
|
var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
1970
2088
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
1971
2089
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
1972
2090
|
function stateFile(runtimeDir) {
|
|
1973
|
-
return
|
|
2091
|
+
return join11(runtimeDir, ".update-check.json");
|
|
1974
2092
|
}
|
|
1975
2093
|
function packageRoot() {
|
|
1976
|
-
return
|
|
2094
|
+
return join11(dirname9(fileURLToPath4(import.meta.url)), "..");
|
|
1977
2095
|
}
|
|
1978
2096
|
function stagedRuntimeDir() {
|
|
1979
|
-
return
|
|
2097
|
+
return join11(homedir4(), ".hindsight", "coding-agents");
|
|
1980
2098
|
}
|
|
1981
2099
|
function sameDir(a, b) {
|
|
1982
2100
|
try {
|
|
@@ -1987,7 +2105,7 @@ function sameDir(a, b) {
|
|
|
1987
2105
|
}
|
|
1988
2106
|
function stagedVersion(pkgRoot) {
|
|
1989
2107
|
try {
|
|
1990
|
-
const pkg = JSON.parse(
|
|
2108
|
+
const pkg = JSON.parse(readFileSync7(join11(pkgRoot, "package.json"), "utf8"));
|
|
1991
2109
|
return typeof pkg.version === "string" ? pkg.version : "";
|
|
1992
2110
|
} catch {
|
|
1993
2111
|
return "";
|
|
@@ -2012,7 +2130,7 @@ function isNewer(candidate, current2) {
|
|
|
2012
2130
|
}
|
|
2013
2131
|
function dueForCheck(file, now) {
|
|
2014
2132
|
try {
|
|
2015
|
-
const state = JSON.parse(
|
|
2133
|
+
const state = JSON.parse(readFileSync7(file, "utf8"));
|
|
2016
2134
|
return typeof state.lastCheck !== "number" || now - state.lastCheck >= CHECK_INTERVAL_MS;
|
|
2017
2135
|
} catch {
|
|
2018
2136
|
return true;
|
|
@@ -2021,7 +2139,7 @@ function dueForCheck(file, now) {
|
|
|
2021
2139
|
var ORIGIN_FILE = ".install-origin.json";
|
|
2022
2140
|
function selfUpdatable(runtimeDir) {
|
|
2023
2141
|
try {
|
|
2024
|
-
const origin = JSON.parse(
|
|
2142
|
+
const origin = JSON.parse(readFileSync7(join11(runtimeDir, ORIGIN_FILE), "utf8"));
|
|
2025
2143
|
if (typeof origin.source !== "string" || !origin.source) return false;
|
|
2026
2144
|
return origin.source.split(/[\\/]/).includes("_npx");
|
|
2027
2145
|
} catch {
|
|
@@ -2030,11 +2148,11 @@ function selfUpdatable(runtimeDir) {
|
|
|
2030
2148
|
}
|
|
2031
2149
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2032
2150
|
function lockFile() {
|
|
2033
|
-
return
|
|
2151
|
+
return join11(tmpdir4(), "hindsight-coding-agent", "auto-update.lock");
|
|
2034
2152
|
}
|
|
2035
2153
|
function acquireUpdateLock(file, now) {
|
|
2036
2154
|
try {
|
|
2037
|
-
const held = JSON.parse(
|
|
2155
|
+
const held = JSON.parse(readFileSync7(file, "utf8"));
|
|
2038
2156
|
if (held.ts && now - held.ts < LOCK_STALE_MS) {
|
|
2039
2157
|
let holderAlive = false;
|
|
2040
2158
|
if (held.pid) {
|
|
@@ -2049,7 +2167,7 @@ function acquireUpdateLock(file, now) {
|
|
|
2049
2167
|
} catch {
|
|
2050
2168
|
}
|
|
2051
2169
|
try {
|
|
2052
|
-
|
|
2170
|
+
mkdirSync4(dirname9(file), { recursive: true });
|
|
2053
2171
|
writeFileSync2(file, JSON.stringify({ pid: process.pid, ts: now }));
|
|
2054
2172
|
return true;
|
|
2055
2173
|
} catch {
|
|
@@ -2146,9 +2264,9 @@ async function maybeAutoUpdate(cfg, opts = {}) {
|
|
|
2146
2264
|
}
|
|
2147
2265
|
|
|
2148
2266
|
// src/core/skill-sync.ts
|
|
2149
|
-
import { cpSync, existsSync as existsSync5, readFileSync as
|
|
2267
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
2150
2268
|
import { homedir as homedir5 } from "os";
|
|
2151
|
-
import { dirname as
|
|
2269
|
+
import { dirname as dirname10, join as join12 } from "path";
|
|
2152
2270
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2153
2271
|
|
|
2154
2272
|
// src/core/skill-dirs.ts
|
|
@@ -2164,6 +2282,13 @@ var SKILL_DIRS = {
|
|
|
2164
2282
|
"cline-cli": [".cline", "data", "settings", "skills"],
|
|
2165
2283
|
"qwen-code": [".qwen", "skills"],
|
|
2166
2284
|
// Qwen's user-level skills root (Storage.getUserSkillsDirs)
|
|
2285
|
+
"factory-droid": [".factory", "skills"],
|
|
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"],
|
|
2167
2292
|
// The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
|
|
2168
2293
|
// by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
|
|
2169
2294
|
// and dsh's copy with it.
|
|
@@ -2173,19 +2298,19 @@ var SKILL_DIRS = {
|
|
|
2173
2298
|
|
|
2174
2299
|
// src/core/skill-sync.ts
|
|
2175
2300
|
function packagedSkillDir() {
|
|
2176
|
-
return
|
|
2301
|
+
return join12(dirname10(fileURLToPath5(import.meta.url)), "..", "skill");
|
|
2177
2302
|
}
|
|
2178
2303
|
function syncCompanionSkill(harness, opts = {}) {
|
|
2179
2304
|
try {
|
|
2180
2305
|
const parts = SKILL_DIRS[harness];
|
|
2181
2306
|
if (!parts) return;
|
|
2182
2307
|
const src = opts.srcDir ?? packagedSkillDir();
|
|
2183
|
-
const srcMd =
|
|
2308
|
+
const srcMd = join12(src, "SKILL.md");
|
|
2184
2309
|
if (!existsSync5(srcMd)) return;
|
|
2185
|
-
const dst =
|
|
2186
|
-
const dstMd =
|
|
2310
|
+
const dst = join12(opts.home ?? homedir5(), ...parts, "hindsight-coding-agent");
|
|
2311
|
+
const dstMd = join12(dst, "SKILL.md");
|
|
2187
2312
|
if (!existsSync5(dstMd)) return;
|
|
2188
|
-
if (
|
|
2313
|
+
if (readFileSync8(srcMd, "utf8") !== readFileSync8(dstMd, "utf8")) {
|
|
2189
2314
|
cpSync(src, dst, { recursive: true });
|
|
2190
2315
|
}
|
|
2191
2316
|
} catch {
|
|
@@ -2346,7 +2471,7 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
|
|
|
2346
2471
|
try {
|
|
2347
2472
|
let ev = {};
|
|
2348
2473
|
try {
|
|
2349
|
-
ev = JSON.parse(
|
|
2474
|
+
ev = JSON.parse(readFileSync9(0, "utf8"));
|
|
2350
2475
|
} catch {
|
|
2351
2476
|
return;
|
|
2352
2477
|
}
|
|
@@ -2515,19 +2640,19 @@ function readCopilotTranscript(path) {
|
|
|
2515
2640
|
}
|
|
2516
2641
|
|
|
2517
2642
|
// src/core/transcript-grok.ts
|
|
2518
|
-
import { existsSync as existsSync6, readFileSync as
|
|
2643
|
+
import { existsSync as existsSync6, readFileSync as readFileSync10, readdirSync } from "fs";
|
|
2519
2644
|
import { homedir as homedir6 } from "os";
|
|
2520
|
-
import { join as
|
|
2645
|
+
import { join as join13 } from "path";
|
|
2521
2646
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2522
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2523
|
-
const sessionsDir =
|
|
2524
|
-
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);
|
|
2525
2650
|
if (existsSync6(direct)) return direct;
|
|
2526
2651
|
try {
|
|
2527
2652
|
for (const candidate of readdirSync(sessionsDir)) {
|
|
2528
|
-
const directory =
|
|
2529
|
-
if (
|
|
2530
|
-
return
|
|
2653
|
+
const directory = join13(sessionsDir, candidate);
|
|
2654
|
+
if (readFileSync10(join13(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2655
|
+
return join13(directory, sessionId, CHAT_HISTORY);
|
|
2531
2656
|
}
|
|
2532
2657
|
}
|
|
2533
2658
|
} catch {
|
|
@@ -2565,9 +2690,9 @@ function readGrokTranscript(path) {
|
|
|
2565
2690
|
import { existsSync as existsSync7 } from "fs";
|
|
2566
2691
|
import { createRequire } from "module";
|
|
2567
2692
|
import { homedir as homedir7 } from "os";
|
|
2568
|
-
import { join as
|
|
2693
|
+
import { join as join14 } from "path";
|
|
2569
2694
|
function devinSessionDb(home = homedir7()) {
|
|
2570
|
-
return
|
|
2695
|
+
return join14(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2571
2696
|
}
|
|
2572
2697
|
function parseDevinMessages(nodes) {
|
|
2573
2698
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2832,6 +2957,95 @@ function collectQwenTurns(path, turns) {
|
|
|
2832
2957
|
}
|
|
2833
2958
|
}
|
|
2834
2959
|
|
|
2960
|
+
// src/core/transcript-droid.ts
|
|
2961
|
+
function renderContent(content, role) {
|
|
2962
|
+
if (!Array.isArray(content)) return [];
|
|
2963
|
+
const texts = [];
|
|
2964
|
+
const actions = [];
|
|
2965
|
+
for (const block of content) {
|
|
2966
|
+
if (!block || typeof block !== "object") continue;
|
|
2967
|
+
const b = block;
|
|
2968
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
2969
|
+
const text = stripInjectedMemory(b.text).trim();
|
|
2970
|
+
if (text) texts.push(text);
|
|
2971
|
+
} else if (b.type === "tool_use" && typeof b.name === "string") {
|
|
2972
|
+
actions.push({ role: "action", content: actionLine(b.name, b.input) });
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
const out = [];
|
|
2976
|
+
const joined = texts.join("\n").trim();
|
|
2977
|
+
if (joined) out.push({ role, content: joined });
|
|
2978
|
+
out.push(...actions);
|
|
2979
|
+
return out;
|
|
2980
|
+
}
|
|
2981
|
+
function readDroidTranscript(path) {
|
|
2982
|
+
const turns = [];
|
|
2983
|
+
for (const rawLine of readJsonlTail(path, { scope: "factory-droid" }).lines) {
|
|
2984
|
+
if (!rawLine.trim()) continue;
|
|
2985
|
+
let parsed;
|
|
2986
|
+
try {
|
|
2987
|
+
parsed = JSON.parse(rawLine);
|
|
2988
|
+
} catch {
|
|
2989
|
+
continue;
|
|
2990
|
+
}
|
|
2991
|
+
if (!parsed || typeof parsed !== "object") continue;
|
|
2992
|
+
const line = parsed;
|
|
2993
|
+
if (line.type !== "message" || !line.message || typeof line.message !== "object") continue;
|
|
2994
|
+
const message = line.message;
|
|
2995
|
+
const role = message.role;
|
|
2996
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
2997
|
+
if (message.visibility === "user_only" || message.visibility === "llm_only") continue;
|
|
2998
|
+
const stamp = typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
|
|
2999
|
+
turns.push(...renderContent(message.content, role).map((turn) => ({ ...turn, ...stamp })));
|
|
3000
|
+
}
|
|
3001
|
+
return turns;
|
|
3002
|
+
}
|
|
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
|
+
|
|
2835
3049
|
// src/harness/hook-lifecycle.ts
|
|
2836
3050
|
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
2837
3051
|
var claudePrompt = {
|
|
@@ -2859,6 +3073,10 @@ var dcodePrompt = {
|
|
|
2859
3073
|
...claudePrompt,
|
|
2860
3074
|
harness: "dcode"
|
|
2861
3075
|
};
|
|
3076
|
+
var droidPrompt = {
|
|
3077
|
+
...claudePrompt,
|
|
3078
|
+
harness: "factory-droid"
|
|
3079
|
+
};
|
|
2862
3080
|
var qwenPrompt = {
|
|
2863
3081
|
...claudePrompt,
|
|
2864
3082
|
harness: "qwen-code",
|
|
@@ -2868,6 +3086,7 @@ var qwenPrompt = {
|
|
|
2868
3086
|
sessionId: ev.session_id
|
|
2869
3087
|
})
|
|
2870
3088
|
};
|
|
3089
|
+
var zcodeSessionId = (ev) => ev.session_id ?? ev.sessionId;
|
|
2871
3090
|
var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
|
|
2872
3091
|
var antigravityPrompt = {
|
|
2873
3092
|
harness: "antigravity-cli",
|
|
@@ -3185,6 +3404,81 @@ var HOOK_HARNESSES = {
|
|
|
3185
3404
|
}),
|
|
3186
3405
|
readTranscript: readQwenTranscript
|
|
3187
3406
|
}
|
|
3407
|
+
},
|
|
3408
|
+
"factory-droid": {
|
|
3409
|
+
configStyle: "nested",
|
|
3410
|
+
install: {
|
|
3411
|
+
sessionStart: { event: "SessionStart", entry: "droid-sessionstart-hook.js", timeout: 30 },
|
|
3412
|
+
prompt: { event: "UserPromptSubmit", entry: "droid-hook.js", timeout: 30 },
|
|
3413
|
+
stop: { event: "Stop", entry: "droid-stop-hook.js", timeout: 60 }
|
|
3414
|
+
},
|
|
3415
|
+
// Droid emits Notification(idle_prompt), not Stop, after user cancellation. Reusing the
|
|
3416
|
+
// idempotent retain entry point captures that final partial turn; its event gate ignores every
|
|
3417
|
+
// other notification type before config or daemon work begins.
|
|
3418
|
+
additionalHooks: [{ event: "Notification", entry: "droid-stop-hook.js", timeout: 60 }],
|
|
3419
|
+
sessionStart: standardSessionStart("factory-droid"),
|
|
3420
|
+
prompt: droidPrompt,
|
|
3421
|
+
retain: {
|
|
3422
|
+
hostTimeoutSec: 60,
|
|
3423
|
+
harness: "factory-droid",
|
|
3424
|
+
accept: (ev) => ev.hook_event_name === "Stop" || ev.hook_event_name === "Notification" && ev.notification_type === "idle_prompt",
|
|
3425
|
+
parse: (ev) => ({
|
|
3426
|
+
sessionId: ev.session_id,
|
|
3427
|
+
transcriptPath: ev.transcript_path,
|
|
3428
|
+
cwd: ev.cwd
|
|
3429
|
+
}),
|
|
3430
|
+
readTranscript: readDroidTranscript
|
|
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
|
+
}
|
|
3188
3482
|
}
|
|
3189
3483
|
};
|
|
3190
3484
|
var runHarnessSessionStart = (harness) => runSessionStartHook(HOOK_HARNESSES[harness].sessionStart);
|