@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/kilo.js
CHANGED
|
@@ -332,9 +332,13 @@ function isOptedIn(config3, directory) {
|
|
|
332
332
|
const pathMap = config3.mapPathToBank;
|
|
333
333
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
334
334
|
}
|
|
335
|
-
function
|
|
335
|
+
function mappedBank(config3, directory, sessionRoot) {
|
|
336
336
|
const pathMap = config3.mapPathToBank;
|
|
337
|
-
|
|
337
|
+
if (!directory || !pathMap) return void 0;
|
|
338
|
+
return lookupDirectories(config3, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
339
|
+
}
|
|
340
|
+
function deriveBankId(config3, directory, harness = "coding", sessionRoot) {
|
|
341
|
+
const mapped = mappedBank(config3, directory, sessionRoot);
|
|
338
342
|
if (mapped) return mapped;
|
|
339
343
|
const dynamic = config3.dynamicBankId ?? !config3.bankId;
|
|
340
344
|
if (!dynamic) return config3.bankId || DEFAULT_BANK_NAME;
|
|
@@ -362,6 +366,7 @@ function deriveBankIdOrSkip(config3, directory, harness = "coding", sessionRoot)
|
|
|
362
366
|
}
|
|
363
367
|
|
|
364
368
|
// src/core/missions.ts
|
|
369
|
+
import { createHash } from "crypto";
|
|
365
370
|
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.";
|
|
366
371
|
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.";
|
|
367
372
|
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.`;
|
|
@@ -473,17 +478,77 @@ function pagesFor(project) {
|
|
|
473
478
|
var PAGE_MAX_TOKENS = 4096;
|
|
474
479
|
var PAGE_TAGS_MATCH = "all";
|
|
475
480
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
481
|
+
var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
|
|
482
|
+
var CRON_FIELD_RANGES = [
|
|
483
|
+
[0, 59],
|
|
484
|
+
// minute
|
|
485
|
+
[0, 23],
|
|
486
|
+
// hour
|
|
487
|
+
[1, 31],
|
|
488
|
+
// day of month
|
|
489
|
+
[1, 12],
|
|
490
|
+
// month
|
|
491
|
+
[0, 6]
|
|
492
|
+
// day of week
|
|
493
|
+
];
|
|
494
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
495
|
+
function isHashedCron(cron) {
|
|
496
|
+
return /(^|\s)H/.test(cron);
|
|
497
|
+
}
|
|
498
|
+
function parseHashedCron(cron) {
|
|
499
|
+
const fields = cron.trim().split(/\s+/);
|
|
500
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
501
|
+
for (const [i, field] of fields.entries()) {
|
|
502
|
+
if (!field.startsWith("H")) continue;
|
|
503
|
+
const m = HASHED_FIELD.exec(field);
|
|
504
|
+
if (!m) return void 0;
|
|
505
|
+
if (m[1] === void 0) continue;
|
|
506
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
507
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
508
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
509
|
+
}
|
|
510
|
+
return fields;
|
|
511
|
+
}
|
|
512
|
+
function hashedValue(seed, field, lo, hi) {
|
|
513
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
514
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
515
|
+
}
|
|
516
|
+
function expandCronHash(cron, seed) {
|
|
517
|
+
if (!isHashedCron(cron)) return cron;
|
|
518
|
+
const fields = parseHashedCron(cron);
|
|
519
|
+
if (!fields) return cron;
|
|
520
|
+
return fields.map((field, i) => {
|
|
521
|
+
const m = HASHED_FIELD.exec(field);
|
|
522
|
+
if (!m) return field;
|
|
523
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
524
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
525
|
+
}).join(" ");
|
|
526
|
+
}
|
|
527
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
528
|
+
const cron = trigger.refresh_cron;
|
|
529
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
530
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
531
|
+
}
|
|
476
532
|
function buildPageTrigger(cfg = {}) {
|
|
477
533
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
478
534
|
switch (cfg.pageTriggerType) {
|
|
479
|
-
case "
|
|
480
|
-
return { ...base,
|
|
535
|
+
case "auto-refresh":
|
|
536
|
+
return { ...base, refresh_after_consolidation: true };
|
|
481
537
|
case "manual":
|
|
482
538
|
return { ...base, refresh_after_consolidation: false };
|
|
539
|
+
// "cron" and an unset type alike: the default schedule stands in for a missing expression, so
|
|
540
|
+
// a trigger built from a partial config is never a cron trigger with nothing to fire on.
|
|
483
541
|
default:
|
|
484
|
-
return { ...base,
|
|
542
|
+
return { ...base, refresh_cron: cfg.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
|
|
485
543
|
}
|
|
486
544
|
}
|
|
545
|
+
function pageTriggerDrifted(current2, desired) {
|
|
546
|
+
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);
|
|
547
|
+
}
|
|
548
|
+
function pageTriggerPatch(desired) {
|
|
549
|
+
if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
|
|
550
|
+
return desired;
|
|
551
|
+
}
|
|
487
552
|
var CODING_BANK_TEMPLATE = {
|
|
488
553
|
version: "1",
|
|
489
554
|
bank: {
|
|
@@ -1026,7 +1091,9 @@ var HindsightClient = class {
|
|
|
1026
1091
|
source_query: page.source_query,
|
|
1027
1092
|
tags: page.tags,
|
|
1028
1093
|
max_tokens: PAGE_MAX_TOKENS,
|
|
1029
|
-
|
|
1094
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
1095
|
+
// and one trigger is built per session for all of them.
|
|
1096
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
1030
1097
|
};
|
|
1031
1098
|
if (!hit) {
|
|
1032
1099
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -1040,14 +1107,14 @@ var HindsightClient = class {
|
|
|
1040
1107
|
if (r.status !== 409) created++;
|
|
1041
1108
|
} else {
|
|
1042
1109
|
const sourceDrift = hit.description !== page.source_query;
|
|
1043
|
-
const triggerDrift = hit.trigger != null && hit.trigger
|
|
1110
|
+
const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
|
|
1044
1111
|
if (!sourceDrift && !triggerDrift) continue;
|
|
1045
1112
|
const patch = {};
|
|
1046
1113
|
if (sourceDrift) {
|
|
1047
1114
|
patch.source_query = page.source_query;
|
|
1048
1115
|
patch.tags = page.tags;
|
|
1049
1116
|
}
|
|
1050
|
-
if (triggerDrift) patch.trigger =
|
|
1117
|
+
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1051
1118
|
const r = await this.req(
|
|
1052
1119
|
"PATCH",
|
|
1053
1120
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
@@ -1063,10 +1130,42 @@ var HindsightClient = class {
|
|
|
1063
1130
|
updated++;
|
|
1064
1131
|
}
|
|
1065
1132
|
}
|
|
1133
|
+
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1066
1134
|
this.log(
|
|
1067
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1135
|
+
`[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` : "")
|
|
1068
1136
|
);
|
|
1069
1137
|
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
|
|
1140
|
+
*
|
|
1141
|
+
* `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
|
|
1142
|
+
* an older default they are the same drift as the taxonomy — and on a real repo they are most of
|
|
1143
|
+
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
1144
|
+
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
1145
|
+
*
|
|
1146
|
+
* Only the trigger is touched. Their `name` and `source_query` are written once, from the
|
|
1147
|
+
* initiative's own title, and re-stating either would rebuild a page whose question never
|
|
1148
|
+
* changed. The tree read above is reused rather than re-fetched.
|
|
1149
|
+
*/
|
|
1150
|
+
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
1151
|
+
const folder = roots.find(
|
|
1152
|
+
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
1153
|
+
);
|
|
1154
|
+
let updated = 0;
|
|
1155
|
+
for (const page of folder?.children ?? []) {
|
|
1156
|
+
if (page.kind !== "page" || page.trigger == null) continue;
|
|
1157
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
1158
|
+
if (!pageTriggerDrifted(page.trigger, desired)) continue;
|
|
1159
|
+
const r = await this.req(
|
|
1160
|
+
"PATCH",
|
|
1161
|
+
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1162
|
+
{ trigger: pageTriggerPatch(desired) }
|
|
1163
|
+
);
|
|
1164
|
+
if ([404, 405, 501].includes(r.status)) break;
|
|
1165
|
+
updated++;
|
|
1166
|
+
}
|
|
1167
|
+
return updated;
|
|
1168
|
+
}
|
|
1070
1169
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
1071
1170
|
slugify(s) {
|
|
1072
1171
|
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
|
|
@@ -1088,12 +1187,14 @@ var HindsightClient = class {
|
|
|
1088
1187
|
let pageId = args.relatesToPageId;
|
|
1089
1188
|
if (!pageId) {
|
|
1090
1189
|
const folderId = await this.ensureFolder("Initiatives");
|
|
1190
|
+
const subject = this.project ?? this.bank;
|
|
1091
1191
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
1092
1192
|
name: args.title,
|
|
1093
|
-
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
|
|
1193
|
+
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),
|
|
1094
1194
|
parent_id: folderId,
|
|
1095
1195
|
tags: ["knowledge:feature-work"],
|
|
1096
|
-
|
|
1196
|
+
max_tokens: PAGE_MAX_TOKENS,
|
|
1197
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1097
1198
|
});
|
|
1098
1199
|
try {
|
|
1099
1200
|
const j = await r.json();
|
|
@@ -1135,16 +1236,22 @@ var HindsightClient = class {
|
|
|
1135
1236
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
1136
1237
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
1137
1238
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
1138
|
-
function
|
|
1139
|
-
if (raw.pageTriggerType === "manual") return "manual";
|
|
1140
|
-
if (raw.pageTriggerType === "
|
|
1141
|
-
|
|
1239
|
+
function resolvePageTrigger(raw) {
|
|
1240
|
+
if (raw.pageTriggerType === "manual") return { type: "manual" };
|
|
1241
|
+
if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
|
|
1242
|
+
if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
|
|
1142
1243
|
log.warn(
|
|
1143
1244
|
"config",
|
|
1144
|
-
|
|
1245
|
+
`ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
|
|
1145
1246
|
);
|
|
1146
|
-
|
|
1147
|
-
return "
|
|
1247
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1248
|
+
if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1249
|
+
if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
|
|
1250
|
+
log.warn(
|
|
1251
|
+
"config",
|
|
1252
|
+
`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)}`
|
|
1253
|
+
);
|
|
1254
|
+
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1148
1255
|
}
|
|
1149
1256
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1150
1257
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
@@ -1176,6 +1283,7 @@ function resolveObservationScopes(raw) {
|
|
|
1176
1283
|
function resolveConfig(raw = {}) {
|
|
1177
1284
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1178
1285
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
1286
|
+
const pageTrigger = resolvePageTrigger(raw);
|
|
1179
1287
|
return {
|
|
1180
1288
|
serverMode,
|
|
1181
1289
|
// Daemon mode resolves the URL HERE rather than at each call site: every entry point already
|
|
@@ -1210,8 +1318,8 @@ function resolveConfig(raw = {}) {
|
|
|
1210
1318
|
reflectBudget: resolveReflectBudget(raw),
|
|
1211
1319
|
autoReflect: raw.autoReflect ?? true,
|
|
1212
1320
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
1213
|
-
pageTriggerType:
|
|
1214
|
-
pageTriggerCron:
|
|
1321
|
+
pageTriggerType: pageTrigger.type,
|
|
1322
|
+
pageTriggerCron: pageTrigger.cron,
|
|
1215
1323
|
autoSeed: raw.autoSeed ?? true,
|
|
1216
1324
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1217
1325
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -16759,15 +16867,24 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16759
16867
|
}
|
|
16760
16868
|
|
|
16761
16869
|
// src/core/retain-cursor.ts
|
|
16762
|
-
import { createHash } from "crypto";
|
|
16870
|
+
import { createHash as createHash2 } from "crypto";
|
|
16871
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16872
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16873
|
+
function pendingReplayable(cursor, now) {
|
|
16874
|
+
const pending = cursor.pending ?? [];
|
|
16875
|
+
if (!pending.length) return true;
|
|
16876
|
+
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
16877
|
+
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16878
|
+
}
|
|
16763
16879
|
function fingerprintTurns(turns, count) {
|
|
16764
|
-
const h =
|
|
16880
|
+
const h = createHash2("sha1").update(String(count));
|
|
16765
16881
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16766
16882
|
return h.digest("hex");
|
|
16767
16883
|
}
|
|
16768
16884
|
function planRetain(turns, cursor, opts) {
|
|
16769
16885
|
if (!turns.length) return { mode: "skip" };
|
|
16770
16886
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
16887
|
+
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
16771
16888
|
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
16772
16889
|
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
16773
16890
|
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
@@ -16783,13 +16900,13 @@ function memoryCursorStore() {
|
|
|
16783
16900
|
}
|
|
16784
16901
|
|
|
16785
16902
|
// src/core/uuid.ts
|
|
16786
|
-
import { createHash as
|
|
16903
|
+
import { createHash as createHash3 } from "crypto";
|
|
16787
16904
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16788
16905
|
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
16789
16906
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16790
16907
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16791
16908
|
const bytes = Buffer.from(
|
|
16792
|
-
|
|
16909
|
+
createHash3("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
16793
16910
|
);
|
|
16794
16911
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16795
16912
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -16866,61 +16983,83 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness, opt
|
|
|
16866
16983
|
);
|
|
16867
16984
|
}
|
|
16868
16985
|
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
16986
|
+
if (!turns.length) return;
|
|
16869
16987
|
const refId = `conversation:${sessionId}`;
|
|
16870
16988
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
16871
|
-
const
|
|
16872
|
-
|
|
16873
|
-
const
|
|
16989
|
+
const cursor = cursors?.read(sessionId);
|
|
16990
|
+
const plan = planRetain(turns, cursor, { appendSupported, bank: client.bank });
|
|
16991
|
+
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
16992
|
+
if (plan.mode === "skip" && !outbox.length) return;
|
|
16993
|
+
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
16994
|
+
${refId}
|
|
16995
|
+
${mode}
|
|
16996
|
+
${content}`);
|
|
16997
|
+
const submit = (content, operationId, append) => client.retain(
|
|
16998
|
+
content,
|
|
16999
|
+
"coding agent session",
|
|
17000
|
+
refId,
|
|
17001
|
+
// Configured tags first, built-ins last and deduped: `source:chat` and `harness:<id>` are what
|
|
17002
|
+
// the documents list filters and draws its agent logo from, so a template cannot displace them.
|
|
17003
|
+
[
|
|
17004
|
+
.../* @__PURE__ */ new Set([
|
|
17005
|
+
...stamp?.tags ?? [],
|
|
17006
|
+
"source:chat",
|
|
17007
|
+
...harness ? [`harness:${harness}`] : []
|
|
17008
|
+
])
|
|
17009
|
+
],
|
|
17010
|
+
"conversation",
|
|
17011
|
+
{
|
|
17012
|
+
timestamp: startTs,
|
|
17013
|
+
updateMode: append ? "append" : void 0,
|
|
17014
|
+
operationId,
|
|
17015
|
+
metadata: {
|
|
17016
|
+
...stamp?.metadata,
|
|
17017
|
+
// configured first: the built-ins below win on any key collision
|
|
17018
|
+
source: "chat",
|
|
17019
|
+
session_id: sessionId,
|
|
17020
|
+
ref_id: refId,
|
|
17021
|
+
...harness ? { harness } : {}
|
|
17022
|
+
}
|
|
17023
|
+
}
|
|
17024
|
+
);
|
|
16874
17025
|
const next = {
|
|
16875
17026
|
turns: turns.length,
|
|
16876
17027
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
16877
17028
|
bank: client.bank
|
|
16878
17029
|
};
|
|
16879
|
-
|
|
16880
|
-
|
|
16881
|
-
|
|
16882
|
-
|
|
16883
|
-
|
|
16884
|
-
|
|
16885
|
-
|
|
16886
|
-
|
|
16887
|
-
|
|
16888
|
-
|
|
16889
|
-
|
|
16890
|
-
|
|
16891
|
-
|
|
16892
|
-
|
|
16893
|
-
|
|
16894
|
-
|
|
16895
|
-
|
|
16896
|
-
|
|
16897
|
-
|
|
16898
|
-
|
|
16899
|
-
|
|
16900
|
-
|
|
16901
|
-
|
|
16902
|
-
|
|
16903
|
-
|
|
16904
|
-
|
|
16905
|
-
|
|
16906
|
-
|
|
16907
|
-
|
|
16908
|
-
|
|
16909
|
-
|
|
16910
|
-
|
|
16911
|
-
|
|
16912
|
-
}
|
|
16913
|
-
}
|
|
16914
|
-
),
|
|
16915
|
-
// Still ours to retry only while the cursor holds the claim we wrote above.
|
|
16916
|
-
() => {
|
|
16917
|
-
if (!cursors) return true;
|
|
16918
|
-
const now = cursors.read(sessionId);
|
|
16919
|
-
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
16920
|
-
},
|
|
16921
|
-
retryUntil
|
|
16922
|
-
);
|
|
16923
|
-
cursors?.write(sessionId, next);
|
|
17030
|
+
const stillOurs = () => {
|
|
17031
|
+
if (!cursors) return true;
|
|
17032
|
+
const now = cursors.read(sessionId);
|
|
17033
|
+
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17034
|
+
};
|
|
17035
|
+
if (plan.mode === "replace") {
|
|
17036
|
+
const content = renderSessionJsonl(refId, turns, startTs);
|
|
17037
|
+
cursors?.write(sessionId, { ...next, dirty: true });
|
|
17038
|
+
await submitWithRetry(
|
|
17039
|
+
() => submit(content, opId("replace", content), false),
|
|
17040
|
+
stillOurs,
|
|
17041
|
+
retryUntil
|
|
17042
|
+
);
|
|
17043
|
+
cursors?.write(sessionId, next);
|
|
17044
|
+
return;
|
|
17045
|
+
}
|
|
17046
|
+
const queue = [...outbox];
|
|
17047
|
+
if (plan.mode === "append") {
|
|
17048
|
+
const content = turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n");
|
|
17049
|
+
queue.push({ content, operationId: opId("append", content), at: Date.now() });
|
|
17050
|
+
}
|
|
17051
|
+
cursors?.write(sessionId, { ...next, pending: queue });
|
|
17052
|
+
for (let i = 0; i < queue.length; i++) {
|
|
17053
|
+
if (i > 0 && Date.now() + REQUEST_BUDGET_MS > retryUntil) return;
|
|
17054
|
+
const entry = queue[i];
|
|
17055
|
+
await submitWithRetry(
|
|
17056
|
+
() => submit(entry.content, entry.operationId, true),
|
|
17057
|
+
stillOurs,
|
|
17058
|
+
retryUntil
|
|
17059
|
+
);
|
|
17060
|
+
const remaining = queue.slice(i + 1);
|
|
17061
|
+
cursors?.write(sessionId, remaining.length ? { ...next, pending: remaining } : next);
|
|
17062
|
+
}
|
|
16924
17063
|
}
|
|
16925
17064
|
|
|
16926
17065
|
// src/core/retain-stamp.ts
|
|
@@ -17179,7 +17318,7 @@ async function buildSessionStartContext(args) {
|
|
|
17179
17318
|
}
|
|
17180
17319
|
|
|
17181
17320
|
// src/core/hook.ts
|
|
17182
|
-
import { existsSync as existsSync6, readFileSync as
|
|
17321
|
+
import { existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
|
|
17183
17322
|
|
|
17184
17323
|
// src/core/inject.ts
|
|
17185
17324
|
function buildReflectQuery(prompt) {
|
|
@@ -17210,6 +17349,49 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17210
17349
|
` + memory + "\n</hindsight_memory>";
|
|
17211
17350
|
}
|
|
17212
17351
|
|
|
17352
|
+
// src/core/turn-journal.ts
|
|
17353
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync7, statSync } from "fs";
|
|
17354
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17355
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
17356
|
+
|
|
17357
|
+
// src/core/transcript-util.ts
|
|
17358
|
+
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;
|
|
17359
|
+
function stripInjectedMemory(s) {
|
|
17360
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
17361
|
+
}
|
|
17362
|
+
var TARGET_KEYS = [
|
|
17363
|
+
"file_path",
|
|
17364
|
+
"path",
|
|
17365
|
+
"notebook_path",
|
|
17366
|
+
"command",
|
|
17367
|
+
"pattern",
|
|
17368
|
+
"query",
|
|
17369
|
+
"url",
|
|
17370
|
+
"name",
|
|
17371
|
+
"id"
|
|
17372
|
+
];
|
|
17373
|
+
var ACTION_TARGET_CAP = 100;
|
|
17374
|
+
function actionLine(tool2, input) {
|
|
17375
|
+
let target = "";
|
|
17376
|
+
if (input && typeof input === "object") {
|
|
17377
|
+
const rec = input;
|
|
17378
|
+
for (const k of TARGET_KEYS) {
|
|
17379
|
+
const v = rec[k];
|
|
17380
|
+
if (typeof v === "string" && v.trim()) {
|
|
17381
|
+
target = v.trim().split("\n")[0];
|
|
17382
|
+
break;
|
|
17383
|
+
}
|
|
17384
|
+
}
|
|
17385
|
+
} else if (typeof input === "string") {
|
|
17386
|
+
target = input.trim().split("\n")[0];
|
|
17387
|
+
}
|
|
17388
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
17389
|
+
return target ? `${tool2} ${target}` : tool2;
|
|
17390
|
+
}
|
|
17391
|
+
|
|
17392
|
+
// src/core/turn-journal.ts
|
|
17393
|
+
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
17394
|
+
|
|
17213
17395
|
// src/core/hook.ts
|
|
17214
17396
|
var HOOK_REFLECT_CAP_MS = 25e3;
|
|
17215
17397
|
async function buildHookOutput(args) {
|
|
@@ -17519,41 +17701,6 @@ var RuntimeCore = class {
|
|
|
17519
17701
|
}
|
|
17520
17702
|
};
|
|
17521
17703
|
|
|
17522
|
-
// src/core/transcript-util.ts
|
|
17523
|
-
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;
|
|
17524
|
-
function stripInjectedMemory(s) {
|
|
17525
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
17526
|
-
}
|
|
17527
|
-
var TARGET_KEYS = [
|
|
17528
|
-
"file_path",
|
|
17529
|
-
"path",
|
|
17530
|
-
"notebook_path",
|
|
17531
|
-
"command",
|
|
17532
|
-
"pattern",
|
|
17533
|
-
"query",
|
|
17534
|
-
"url",
|
|
17535
|
-
"name",
|
|
17536
|
-
"id"
|
|
17537
|
-
];
|
|
17538
|
-
var ACTION_TARGET_CAP = 100;
|
|
17539
|
-
function actionLine(tool2, input) {
|
|
17540
|
-
let target = "";
|
|
17541
|
-
if (input && typeof input === "object") {
|
|
17542
|
-
const rec = input;
|
|
17543
|
-
for (const k of TARGET_KEYS) {
|
|
17544
|
-
const v = rec[k];
|
|
17545
|
-
if (typeof v === "string" && v.trim()) {
|
|
17546
|
-
target = v.trim().split("\n")[0];
|
|
17547
|
-
break;
|
|
17548
|
-
}
|
|
17549
|
-
}
|
|
17550
|
-
} else if (typeof input === "string") {
|
|
17551
|
-
target = input.trim().split("\n")[0];
|
|
17552
|
-
}
|
|
17553
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
17554
|
-
return target ? `${tool2} ${target}` : tool2;
|
|
17555
|
-
}
|
|
17556
|
-
|
|
17557
17704
|
// src/core/transcript-opencode.ts
|
|
17558
17705
|
function renderMessage(m) {
|
|
17559
17706
|
const role = m.info?.role;
|
|
@@ -30007,12 +30154,12 @@ function tool(input) {
|
|
|
30007
30154
|
tool.schema = external_exports2;
|
|
30008
30155
|
|
|
30009
30156
|
// src/harness/registry.ts
|
|
30010
|
-
import { readFileSync as
|
|
30157
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
30011
30158
|
var jsonChatReader = (harness) => ({
|
|
30012
30159
|
describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
|
|
30013
30160
|
async read(opts) {
|
|
30014
30161
|
if (!opts.conversations) return [];
|
|
30015
|
-
return JSON.parse(
|
|
30162
|
+
return JSON.parse(readFileSync9(opts.conversations, "utf8"));
|
|
30016
30163
|
}
|
|
30017
30164
|
});
|
|
30018
30165
|
|