@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
package/dist/cline.js
CHANGED
|
@@ -329,9 +329,13 @@ function isOptedIn(config2, directory) {
|
|
|
329
329
|
const pathMap = config2.mapPathToBank;
|
|
330
330
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
331
331
|
}
|
|
332
|
-
function
|
|
332
|
+
function mappedBank(config2, directory, sessionRoot) {
|
|
333
333
|
const pathMap = config2.mapPathToBank;
|
|
334
|
-
|
|
334
|
+
if (!directory || !pathMap) return void 0;
|
|
335
|
+
return lookupDirectories(config2, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
336
|
+
}
|
|
337
|
+
function deriveBankId(config2, directory, harness = "coding", sessionRoot) {
|
|
338
|
+
const mapped = mappedBank(config2, directory, sessionRoot);
|
|
335
339
|
if (mapped) return mapped;
|
|
336
340
|
const dynamic = config2.dynamicBankId ?? !config2.bankId;
|
|
337
341
|
if (!dynamic) return config2.bankId || DEFAULT_BANK_NAME;
|
|
@@ -359,6 +363,7 @@ function deriveBankIdOrSkip(config2, directory, harness = "coding", sessionRoot)
|
|
|
359
363
|
}
|
|
360
364
|
|
|
361
365
|
// src/core/missions.ts
|
|
366
|
+
import { createHash } from "crypto";
|
|
362
367
|
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.";
|
|
363
368
|
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.";
|
|
364
369
|
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.`;
|
|
@@ -470,17 +475,77 @@ function pagesFor(project) {
|
|
|
470
475
|
var PAGE_MAX_TOKENS = 4096;
|
|
471
476
|
var PAGE_TAGS_MATCH = "all";
|
|
472
477
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
478
|
+
var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
|
|
479
|
+
var CRON_FIELD_RANGES = [
|
|
480
|
+
[0, 59],
|
|
481
|
+
// minute
|
|
482
|
+
[0, 23],
|
|
483
|
+
// hour
|
|
484
|
+
[1, 31],
|
|
485
|
+
// day of month
|
|
486
|
+
[1, 12],
|
|
487
|
+
// month
|
|
488
|
+
[0, 6]
|
|
489
|
+
// day of week
|
|
490
|
+
];
|
|
491
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
492
|
+
function isHashedCron(cron) {
|
|
493
|
+
return /(^|\s)H/.test(cron);
|
|
494
|
+
}
|
|
495
|
+
function parseHashedCron(cron) {
|
|
496
|
+
const fields = cron.trim().split(/\s+/);
|
|
497
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
498
|
+
for (const [i, field] of fields.entries()) {
|
|
499
|
+
if (!field.startsWith("H")) continue;
|
|
500
|
+
const m = HASHED_FIELD.exec(field);
|
|
501
|
+
if (!m) return void 0;
|
|
502
|
+
if (m[1] === void 0) continue;
|
|
503
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
504
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
505
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
506
|
+
}
|
|
507
|
+
return fields;
|
|
508
|
+
}
|
|
509
|
+
function hashedValue(seed, field, lo, hi) {
|
|
510
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
511
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
512
|
+
}
|
|
513
|
+
function expandCronHash(cron, seed) {
|
|
514
|
+
if (!isHashedCron(cron)) return cron;
|
|
515
|
+
const fields = parseHashedCron(cron);
|
|
516
|
+
if (!fields) return cron;
|
|
517
|
+
return fields.map((field, i) => {
|
|
518
|
+
const m = HASHED_FIELD.exec(field);
|
|
519
|
+
if (!m) return field;
|
|
520
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
521
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
522
|
+
}).join(" ");
|
|
523
|
+
}
|
|
524
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
525
|
+
const cron = trigger.refresh_cron;
|
|
526
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
527
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
528
|
+
}
|
|
473
529
|
function buildPageTrigger(cfg = {}) {
|
|
474
530
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
475
531
|
switch (cfg.pageTriggerType) {
|
|
476
|
-
case "
|
|
477
|
-
return { ...base,
|
|
532
|
+
case "auto-refresh":
|
|
533
|
+
return { ...base, refresh_after_consolidation: true };
|
|
478
534
|
case "manual":
|
|
479
535
|
return { ...base, refresh_after_consolidation: false };
|
|
536
|
+
// "cron" and an unset type alike: the default schedule stands in for a missing expression, so
|
|
537
|
+
// a trigger built from a partial config is never a cron trigger with nothing to fire on.
|
|
480
538
|
default:
|
|
481
|
-
return { ...base,
|
|
539
|
+
return { ...base, refresh_cron: cfg.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
|
|
482
540
|
}
|
|
483
541
|
}
|
|
542
|
+
function pageTriggerDrifted(current2, desired) {
|
|
543
|
+
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);
|
|
544
|
+
}
|
|
545
|
+
function pageTriggerPatch(desired) {
|
|
546
|
+
if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
|
|
547
|
+
return desired;
|
|
548
|
+
}
|
|
484
549
|
var CODING_BANK_TEMPLATE = {
|
|
485
550
|
version: "1",
|
|
486
551
|
bank: {
|
|
@@ -1023,7 +1088,9 @@ var HindsightClient = class {
|
|
|
1023
1088
|
source_query: page.source_query,
|
|
1024
1089
|
tags: page.tags,
|
|
1025
1090
|
max_tokens: PAGE_MAX_TOKENS,
|
|
1026
|
-
|
|
1091
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
1092
|
+
// and one trigger is built per session for all of them.
|
|
1093
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
1027
1094
|
};
|
|
1028
1095
|
if (!hit) {
|
|
1029
1096
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -1037,14 +1104,14 @@ var HindsightClient = class {
|
|
|
1037
1104
|
if (r.status !== 409) created++;
|
|
1038
1105
|
} else {
|
|
1039
1106
|
const sourceDrift = hit.description !== page.source_query;
|
|
1040
|
-
const triggerDrift = hit.trigger != null && hit.trigger
|
|
1107
|
+
const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
|
|
1041
1108
|
if (!sourceDrift && !triggerDrift) continue;
|
|
1042
1109
|
const patch = {};
|
|
1043
1110
|
if (sourceDrift) {
|
|
1044
1111
|
patch.source_query = page.source_query;
|
|
1045
1112
|
patch.tags = page.tags;
|
|
1046
1113
|
}
|
|
1047
|
-
if (triggerDrift) patch.trigger =
|
|
1114
|
+
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1048
1115
|
const r = await this.req(
|
|
1049
1116
|
"PATCH",
|
|
1050
1117
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
@@ -1060,9 +1127,41 @@ var HindsightClient = class {
|
|
|
1060
1127
|
updated++;
|
|
1061
1128
|
}
|
|
1062
1129
|
}
|
|
1130
|
+
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1063
1131
|
this.log(
|
|
1064
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1132
|
+
`[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` : "")
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
|
|
1137
|
+
*
|
|
1138
|
+
* `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
|
|
1139
|
+
* an older default they are the same drift as the taxonomy — and on a real repo they are most of
|
|
1140
|
+
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
1141
|
+
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
1142
|
+
*
|
|
1143
|
+
* Only the trigger is touched. Their `name` and `source_query` are written once, from the
|
|
1144
|
+
* initiative's own title, and re-stating either would rebuild a page whose question never
|
|
1145
|
+
* changed. The tree read above is reused rather than re-fetched.
|
|
1146
|
+
*/
|
|
1147
|
+
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
1148
|
+
const folder = roots.find(
|
|
1149
|
+
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
1065
1150
|
);
|
|
1151
|
+
let updated = 0;
|
|
1152
|
+
for (const page of folder?.children ?? []) {
|
|
1153
|
+
if (page.kind !== "page" || page.trigger == null) continue;
|
|
1154
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
1155
|
+
if (!pageTriggerDrifted(page.trigger, desired)) continue;
|
|
1156
|
+
const r = await this.req(
|
|
1157
|
+
"PATCH",
|
|
1158
|
+
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1159
|
+
{ trigger: pageTriggerPatch(desired) }
|
|
1160
|
+
);
|
|
1161
|
+
if ([404, 405, 501].includes(r.status)) break;
|
|
1162
|
+
updated++;
|
|
1163
|
+
}
|
|
1164
|
+
return updated;
|
|
1066
1165
|
}
|
|
1067
1166
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
1068
1167
|
slugify(s) {
|
|
@@ -1085,12 +1184,14 @@ var HindsightClient = class {
|
|
|
1085
1184
|
let pageId = args.relatesToPageId;
|
|
1086
1185
|
if (!pageId) {
|
|
1087
1186
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1187
|
+
const subject = this.project ?? this.bank;
|
|
1088
1188
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1089
1189
|
name: args.title,
|
|
1090
|
-
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
|
|
1190
|
+
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),
|
|
1091
1191
|
parent_id: folderId,
|
|
1092
1192
|
tags: ["knowledge:feature-work"],
|
|
1093
|
-
|
|
1193
|
+
max_tokens: PAGE_MAX_TOKENS,
|
|
1194
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1094
1195
|
});
|
|
1095
1196
|
try {
|
|
1096
1197
|
const j = await r.json();
|
|
@@ -1132,16 +1233,22 @@ var HindsightClient = class {
|
|
|
1132
1233
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
1133
1234
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1134
1235
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1135
|
-
function
|
|
1136
|
-
if (raw.pageTriggerType === "manual") return "manual";
|
|
1137
|
-
if (raw.pageTriggerType === "
|
|
1138
|
-
|
|
1236
|
+
function resolvePageTrigger(raw) {
|
|
1237
|
+
if (raw.pageTriggerType === "manual") return { type: "manual" };
|
|
1238
|
+
if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
|
|
1239
|
+
if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
|
|
1139
1240
|
log.warn(
|
|
1140
1241
|
"config",
|
|
1141
|
-
|
|
1242
|
+
`ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
|
|
1142
1243
|
);
|
|
1143
|
-
|
|
1144
|
-
return "
|
|
1244
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1245
|
+
if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1246
|
+
if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
|
|
1247
|
+
log.warn(
|
|
1248
|
+
"config",
|
|
1249
|
+
`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)}`
|
|
1250
|
+
);
|
|
1251
|
+
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1145
1252
|
}
|
|
1146
1253
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1147
1254
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
@@ -1173,6 +1280,7 @@ function resolveObservationScopes(raw) {
|
|
|
1173
1280
|
function resolveConfig(raw = {}) {
|
|
1174
1281
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1175
1282
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
1283
|
+
const pageTrigger = resolvePageTrigger(raw);
|
|
1176
1284
|
return {
|
|
1177
1285
|
serverMode,
|
|
1178
1286
|
// Daemon mode resolves the URL HERE rather than at each call site: every entry point already
|
|
@@ -1207,8 +1315,8 @@ function resolveConfig(raw = {}) {
|
|
|
1207
1315
|
reflectBudget: resolveReflectBudget(raw),
|
|
1208
1316
|
autoReflect: raw.autoReflect ?? true,
|
|
1209
1317
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
1210
|
-
pageTriggerType:
|
|
1211
|
-
pageTriggerCron:
|
|
1318
|
+
pageTriggerType: pageTrigger.type,
|
|
1319
|
+
pageTriggerCron: pageTrigger.cron,
|
|
1212
1320
|
autoSeed: raw.autoSeed ?? true,
|
|
1213
1321
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1214
1322
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -16745,15 +16853,24 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16745
16853
|
}
|
|
16746
16854
|
|
|
16747
16855
|
// src/core/retain-cursor.ts
|
|
16748
|
-
import { createHash } from "crypto";
|
|
16856
|
+
import { createHash as createHash2 } from "crypto";
|
|
16857
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16858
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16859
|
+
function pendingReplayable(cursor, now) {
|
|
16860
|
+
const pending = cursor.pending ?? [];
|
|
16861
|
+
if (!pending.length) return true;
|
|
16862
|
+
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
16863
|
+
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16864
|
+
}
|
|
16749
16865
|
function fingerprintTurns(turns, count) {
|
|
16750
|
-
const h =
|
|
16866
|
+
const h = createHash2("sha1").update(String(count));
|
|
16751
16867
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16752
16868
|
return h.digest("hex");
|
|
16753
16869
|
}
|
|
16754
16870
|
function planRetain(turns, cursor, opts) {
|
|
16755
16871
|
if (!turns.length) return { mode: "skip" };
|
|
16756
16872
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
16873
|
+
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
16757
16874
|
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
16758
16875
|
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
16759
16876
|
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
@@ -16769,13 +16886,13 @@ function memoryCursorStore() {
|
|
|
16769
16886
|
}
|
|
16770
16887
|
|
|
16771
16888
|
// src/core/uuid.ts
|
|
16772
|
-
import { createHash as
|
|
16889
|
+
import { createHash as createHash3 } from "crypto";
|
|
16773
16890
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16774
16891
|
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
16775
16892
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16776
16893
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16777
16894
|
const bytes = Buffer.from(
|
|
16778
|
-
|
|
16895
|
+
createHash3("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
16779
16896
|
);
|
|
16780
16897
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16781
16898
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -16852,61 +16969,83 @@ async function retainLiveSession(client, sessionId2, turns, startTs, harness, op
|
|
|
16852
16969
|
);
|
|
16853
16970
|
}
|
|
16854
16971
|
async function writeSession(client, sessionId2, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
16972
|
+
if (!turns.length) return;
|
|
16855
16973
|
const refId = `conversation:${sessionId2}`;
|
|
16856
16974
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
16857
|
-
const
|
|
16858
|
-
|
|
16859
|
-
const
|
|
16975
|
+
const cursor = cursors?.read(sessionId2);
|
|
16976
|
+
const plan = planRetain(turns, cursor, { appendSupported, bank: client.bank });
|
|
16977
|
+
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
16978
|
+
if (plan.mode === "skip" && !outbox.length) return;
|
|
16979
|
+
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
16980
|
+
${refId}
|
|
16981
|
+
${mode}
|
|
16982
|
+
${content}`);
|
|
16983
|
+
const submit = (content, operationId, append) => client.retain(
|
|
16984
|
+
content,
|
|
16985
|
+
"coding agent session",
|
|
16986
|
+
refId,
|
|
16987
|
+
// Configured tags first, built-ins last and deduped: `source:chat` and `harness:<id>` are what
|
|
16988
|
+
// the documents list filters and draws its agent logo from, so a template cannot displace them.
|
|
16989
|
+
[
|
|
16990
|
+
.../* @__PURE__ */ new Set([
|
|
16991
|
+
...stamp?.tags ?? [],
|
|
16992
|
+
"source:chat",
|
|
16993
|
+
...harness ? [`harness:${harness}`] : []
|
|
16994
|
+
])
|
|
16995
|
+
],
|
|
16996
|
+
"conversation",
|
|
16997
|
+
{
|
|
16998
|
+
timestamp: startTs,
|
|
16999
|
+
updateMode: append ? "append" : void 0,
|
|
17000
|
+
operationId,
|
|
17001
|
+
metadata: {
|
|
17002
|
+
...stamp?.metadata,
|
|
17003
|
+
// configured first: the built-ins below win on any key collision
|
|
17004
|
+
source: "chat",
|
|
17005
|
+
session_id: sessionId2,
|
|
17006
|
+
ref_id: refId,
|
|
17007
|
+
...harness ? { harness } : {}
|
|
17008
|
+
}
|
|
17009
|
+
}
|
|
17010
|
+
);
|
|
16860
17011
|
const next = {
|
|
16861
17012
|
turns: turns.length,
|
|
16862
17013
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
16863
17014
|
bank: client.bank
|
|
16864
17015
|
};
|
|
16865
|
-
|
|
16866
|
-
|
|
16867
|
-
|
|
16868
|
-
|
|
16869
|
-
|
|
16870
|
-
|
|
16871
|
-
|
|
16872
|
-
|
|
16873
|
-
|
|
16874
|
-
|
|
16875
|
-
|
|
16876
|
-
|
|
16877
|
-
|
|
16878
|
-
|
|
16879
|
-
|
|
16880
|
-
|
|
16881
|
-
|
|
16882
|
-
|
|
16883
|
-
|
|
16884
|
-
|
|
16885
|
-
|
|
16886
|
-
|
|
16887
|
-
|
|
16888
|
-
|
|
16889
|
-
|
|
16890
|
-
|
|
16891
|
-
|
|
16892
|
-
|
|
16893
|
-
|
|
16894
|
-
|
|
16895
|
-
|
|
16896
|
-
|
|
16897
|
-
|
|
16898
|
-
}
|
|
16899
|
-
}
|
|
16900
|
-
),
|
|
16901
|
-
// Still ours to retry only while the cursor holds the claim we wrote above.
|
|
16902
|
-
() => {
|
|
16903
|
-
if (!cursors) return true;
|
|
16904
|
-
const now = cursors.read(sessionId2);
|
|
16905
|
-
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
16906
|
-
},
|
|
16907
|
-
retryUntil
|
|
16908
|
-
);
|
|
16909
|
-
cursors?.write(sessionId2, next);
|
|
17016
|
+
const stillOurs = () => {
|
|
17017
|
+
if (!cursors) return true;
|
|
17018
|
+
const now = cursors.read(sessionId2);
|
|
17019
|
+
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17020
|
+
};
|
|
17021
|
+
if (plan.mode === "replace") {
|
|
17022
|
+
const content = renderSessionJsonl(refId, turns, startTs);
|
|
17023
|
+
cursors?.write(sessionId2, { ...next, dirty: true });
|
|
17024
|
+
await submitWithRetry(
|
|
17025
|
+
() => submit(content, opId("replace", content), false),
|
|
17026
|
+
stillOurs,
|
|
17027
|
+
retryUntil
|
|
17028
|
+
);
|
|
17029
|
+
cursors?.write(sessionId2, next);
|
|
17030
|
+
return;
|
|
17031
|
+
}
|
|
17032
|
+
const queue = [...outbox];
|
|
17033
|
+
if (plan.mode === "append") {
|
|
17034
|
+
const content = turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n");
|
|
17035
|
+
queue.push({ content, operationId: opId("append", content), at: Date.now() });
|
|
17036
|
+
}
|
|
17037
|
+
cursors?.write(sessionId2, { ...next, pending: queue });
|
|
17038
|
+
for (let i = 0; i < queue.length; i++) {
|
|
17039
|
+
if (i > 0 && Date.now() + REQUEST_BUDGET_MS > retryUntil) return;
|
|
17040
|
+
const entry = queue[i];
|
|
17041
|
+
await submitWithRetry(
|
|
17042
|
+
() => submit(entry.content, entry.operationId, true),
|
|
17043
|
+
stillOurs,
|
|
17044
|
+
retryUntil
|
|
17045
|
+
);
|
|
17046
|
+
const remaining = queue.slice(i + 1);
|
|
17047
|
+
cursors?.write(sessionId2, remaining.length ? { ...next, pending: remaining } : next);
|
|
17048
|
+
}
|
|
16910
17049
|
}
|
|
16911
17050
|
|
|
16912
17051
|
// src/core/retain-stamp.ts
|
|
@@ -17165,7 +17304,7 @@ async function buildSessionStartContext(args) {
|
|
|
17165
17304
|
}
|
|
17166
17305
|
|
|
17167
17306
|
// src/core/hook.ts
|
|
17168
|
-
import { existsSync as existsSync6, readFileSync as
|
|
17307
|
+
import { existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
|
|
17169
17308
|
|
|
17170
17309
|
// src/core/inject.ts
|
|
17171
17310
|
function buildReflectQuery(prompt) {
|
|
@@ -17196,6 +17335,12 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17196
17335
|
` + memory + "\n</hindsight_memory>";
|
|
17197
17336
|
}
|
|
17198
17337
|
|
|
17338
|
+
// src/core/turn-journal.ts
|
|
17339
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync7, statSync } from "fs";
|
|
17340
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17341
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
17342
|
+
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
17343
|
+
|
|
17199
17344
|
// src/core/hook.ts
|
|
17200
17345
|
var HOOK_REFLECT_CAP_MS = 25e3;
|
|
17201
17346
|
async function buildHookOutput(args) {
|