@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/dsh.js
CHANGED
|
@@ -332,9 +332,13 @@ function isOptedIn(config2, directory) {
|
|
|
332
332
|
const pathMap = config2.mapPathToBank;
|
|
333
333
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
334
334
|
}
|
|
335
|
-
function
|
|
335
|
+
function mappedBank(config2, directory, sessionRoot) {
|
|
336
336
|
const pathMap = config2.mapPathToBank;
|
|
337
|
-
|
|
337
|
+
if (!directory || !pathMap) return void 0;
|
|
338
|
+
return lookupDirectories(config2, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
339
|
+
}
|
|
340
|
+
function deriveBankId(config2, directory, harness = "coding", sessionRoot) {
|
|
341
|
+
const mapped = mappedBank(config2, directory, sessionRoot);
|
|
338
342
|
if (mapped) return mapped;
|
|
339
343
|
const dynamic = config2.dynamicBankId ?? !config2.bankId;
|
|
340
344
|
if (!dynamic) return config2.bankId || DEFAULT_BANK_NAME;
|
|
@@ -362,6 +366,7 @@ function deriveBankIdOrSkip(config2, 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,9 +1130,41 @@ 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` : "")
|
|
1136
|
+
);
|
|
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"
|
|
1068
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;
|
|
1069
1168
|
}
|
|
1070
1169
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
1071
1170
|
slugify(s) {
|
|
@@ -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,
|
|
@@ -16748,15 +16856,24 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16748
16856
|
}
|
|
16749
16857
|
|
|
16750
16858
|
// src/core/retain-cursor.ts
|
|
16751
|
-
import { createHash } from "crypto";
|
|
16859
|
+
import { createHash as createHash2 } from "crypto";
|
|
16860
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16861
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16862
|
+
function pendingReplayable(cursor, now) {
|
|
16863
|
+
const pending = cursor.pending ?? [];
|
|
16864
|
+
if (!pending.length) return true;
|
|
16865
|
+
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
16866
|
+
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16867
|
+
}
|
|
16752
16868
|
function fingerprintTurns(turns, count) {
|
|
16753
|
-
const h =
|
|
16869
|
+
const h = createHash2("sha1").update(String(count));
|
|
16754
16870
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16755
16871
|
return h.digest("hex");
|
|
16756
16872
|
}
|
|
16757
16873
|
function planRetain(turns, cursor, opts) {
|
|
16758
16874
|
if (!turns.length) return { mode: "skip" };
|
|
16759
16875
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
16876
|
+
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
16760
16877
|
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
16761
16878
|
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
16762
16879
|
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
@@ -16772,13 +16889,13 @@ function memoryCursorStore() {
|
|
|
16772
16889
|
}
|
|
16773
16890
|
|
|
16774
16891
|
// src/core/uuid.ts
|
|
16775
|
-
import { createHash as
|
|
16892
|
+
import { createHash as createHash3 } from "crypto";
|
|
16776
16893
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16777
16894
|
function uuidV5(name2, namespace = HINDSIGHT_NAMESPACE) {
|
|
16778
16895
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16779
16896
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16780
16897
|
const bytes = Buffer.from(
|
|
16781
|
-
|
|
16898
|
+
createHash3("sha1").update(ns).update(Buffer.from(name2, "utf8")).digest().subarray(0, 16)
|
|
16782
16899
|
);
|
|
16783
16900
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16784
16901
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -16855,61 +16972,83 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness, opt
|
|
|
16855
16972
|
);
|
|
16856
16973
|
}
|
|
16857
16974
|
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
16975
|
+
if (!turns.length) return;
|
|
16858
16976
|
const refId = `conversation:${sessionId}`;
|
|
16859
16977
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
16860
|
-
const
|
|
16861
|
-
|
|
16862
|
-
const
|
|
16978
|
+
const cursor = cursors?.read(sessionId);
|
|
16979
|
+
const plan = planRetain(turns, cursor, { appendSupported, bank: client.bank });
|
|
16980
|
+
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
16981
|
+
if (plan.mode === "skip" && !outbox.length) return;
|
|
16982
|
+
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
16983
|
+
${refId}
|
|
16984
|
+
${mode}
|
|
16985
|
+
${content}`);
|
|
16986
|
+
const submit = (content, operationId, append) => client.retain(
|
|
16987
|
+
content,
|
|
16988
|
+
"coding agent session",
|
|
16989
|
+
refId,
|
|
16990
|
+
// Configured tags first, built-ins last and deduped: `source:chat` and `harness:<id>` are what
|
|
16991
|
+
// the documents list filters and draws its agent logo from, so a template cannot displace them.
|
|
16992
|
+
[
|
|
16993
|
+
.../* @__PURE__ */ new Set([
|
|
16994
|
+
...stamp?.tags ?? [],
|
|
16995
|
+
"source:chat",
|
|
16996
|
+
...harness ? [`harness:${harness}`] : []
|
|
16997
|
+
])
|
|
16998
|
+
],
|
|
16999
|
+
"conversation",
|
|
17000
|
+
{
|
|
17001
|
+
timestamp: startTs,
|
|
17002
|
+
updateMode: append ? "append" : void 0,
|
|
17003
|
+
operationId,
|
|
17004
|
+
metadata: {
|
|
17005
|
+
...stamp?.metadata,
|
|
17006
|
+
// configured first: the built-ins below win on any key collision
|
|
17007
|
+
source: "chat",
|
|
17008
|
+
session_id: sessionId,
|
|
17009
|
+
ref_id: refId,
|
|
17010
|
+
...harness ? { harness } : {}
|
|
17011
|
+
}
|
|
17012
|
+
}
|
|
17013
|
+
);
|
|
16863
17014
|
const next = {
|
|
16864
17015
|
turns: turns.length,
|
|
16865
17016
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
16866
17017
|
bank: client.bank
|
|
16867
17018
|
};
|
|
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
|
-
}
|
|
16902
|
-
}
|
|
16903
|
-
),
|
|
16904
|
-
// Still ours to retry only while the cursor holds the claim we wrote above.
|
|
16905
|
-
() => {
|
|
16906
|
-
if (!cursors) return true;
|
|
16907
|
-
const now = cursors.read(sessionId);
|
|
16908
|
-
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
16909
|
-
},
|
|
16910
|
-
retryUntil
|
|
16911
|
-
);
|
|
16912
|
-
cursors?.write(sessionId, next);
|
|
17019
|
+
const stillOurs = () => {
|
|
17020
|
+
if (!cursors) return true;
|
|
17021
|
+
const now = cursors.read(sessionId);
|
|
17022
|
+
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17023
|
+
};
|
|
17024
|
+
if (plan.mode === "replace") {
|
|
17025
|
+
const content = renderSessionJsonl(refId, turns, startTs);
|
|
17026
|
+
cursors?.write(sessionId, { ...next, dirty: true });
|
|
17027
|
+
await submitWithRetry(
|
|
17028
|
+
() => submit(content, opId("replace", content), false),
|
|
17029
|
+
stillOurs,
|
|
17030
|
+
retryUntil
|
|
17031
|
+
);
|
|
17032
|
+
cursors?.write(sessionId, next);
|
|
17033
|
+
return;
|
|
17034
|
+
}
|
|
17035
|
+
const queue = [...outbox];
|
|
17036
|
+
if (plan.mode === "append") {
|
|
17037
|
+
const content = turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n");
|
|
17038
|
+
queue.push({ content, operationId: opId("append", content), at: Date.now() });
|
|
17039
|
+
}
|
|
17040
|
+
cursors?.write(sessionId, { ...next, pending: queue });
|
|
17041
|
+
for (let i = 0; i < queue.length; i++) {
|
|
17042
|
+
if (i > 0 && Date.now() + REQUEST_BUDGET_MS > retryUntil) return;
|
|
17043
|
+
const entry = queue[i];
|
|
17044
|
+
await submitWithRetry(
|
|
17045
|
+
() => submit(entry.content, entry.operationId, true),
|
|
17046
|
+
stillOurs,
|
|
17047
|
+
retryUntil
|
|
17048
|
+
);
|
|
17049
|
+
const remaining = queue.slice(i + 1);
|
|
17050
|
+
cursors?.write(sessionId, remaining.length ? { ...next, pending: remaining } : next);
|
|
17051
|
+
}
|
|
16913
17052
|
}
|
|
16914
17053
|
|
|
16915
17054
|
// src/core/retain-stamp.ts
|
|
@@ -17168,7 +17307,7 @@ async function buildSessionStartContext(args) {
|
|
|
17168
17307
|
}
|
|
17169
17308
|
|
|
17170
17309
|
// src/core/hook.ts
|
|
17171
|
-
import { existsSync as existsSync6, readFileSync as
|
|
17310
|
+
import { existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
|
|
17172
17311
|
|
|
17173
17312
|
// src/core/inject.ts
|
|
17174
17313
|
function buildReflectQuery(prompt) {
|
|
@@ -17199,6 +17338,49 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17199
17338
|
` + memory + "\n</hindsight_memory>";
|
|
17200
17339
|
}
|
|
17201
17340
|
|
|
17341
|
+
// src/core/turn-journal.ts
|
|
17342
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync7, statSync } from "fs";
|
|
17343
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17344
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
17345
|
+
|
|
17346
|
+
// src/core/transcript-util.ts
|
|
17347
|
+
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;
|
|
17348
|
+
function stripInjectedMemory(s) {
|
|
17349
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
17350
|
+
}
|
|
17351
|
+
var TARGET_KEYS = [
|
|
17352
|
+
"file_path",
|
|
17353
|
+
"path",
|
|
17354
|
+
"notebook_path",
|
|
17355
|
+
"command",
|
|
17356
|
+
"pattern",
|
|
17357
|
+
"query",
|
|
17358
|
+
"url",
|
|
17359
|
+
"name",
|
|
17360
|
+
"id"
|
|
17361
|
+
];
|
|
17362
|
+
var ACTION_TARGET_CAP = 100;
|
|
17363
|
+
function actionLine(tool, input) {
|
|
17364
|
+
let target = "";
|
|
17365
|
+
if (input && typeof input === "object") {
|
|
17366
|
+
const rec = input;
|
|
17367
|
+
for (const k of TARGET_KEYS) {
|
|
17368
|
+
const v = rec[k];
|
|
17369
|
+
if (typeof v === "string" && v.trim()) {
|
|
17370
|
+
target = v.trim().split("\n")[0];
|
|
17371
|
+
break;
|
|
17372
|
+
}
|
|
17373
|
+
}
|
|
17374
|
+
} else if (typeof input === "string") {
|
|
17375
|
+
target = input.trim().split("\n")[0];
|
|
17376
|
+
}
|
|
17377
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
17378
|
+
return target ? `${tool} ${target}` : tool;
|
|
17379
|
+
}
|
|
17380
|
+
|
|
17381
|
+
// src/core/turn-journal.ts
|
|
17382
|
+
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
17383
|
+
|
|
17202
17384
|
// src/core/hook.ts
|
|
17203
17385
|
var HOOK_REFLECT_CAP_MS = 25e3;
|
|
17204
17386
|
async function buildHookOutput(args) {
|
|
@@ -17508,41 +17690,6 @@ var RuntimeCore = class {
|
|
|
17508
17690
|
}
|
|
17509
17691
|
};
|
|
17510
17692
|
|
|
17511
|
-
// src/core/transcript-util.ts
|
|
17512
|
-
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;
|
|
17513
|
-
function stripInjectedMemory(s) {
|
|
17514
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
17515
|
-
}
|
|
17516
|
-
var TARGET_KEYS = [
|
|
17517
|
-
"file_path",
|
|
17518
|
-
"path",
|
|
17519
|
-
"notebook_path",
|
|
17520
|
-
"command",
|
|
17521
|
-
"pattern",
|
|
17522
|
-
"query",
|
|
17523
|
-
"url",
|
|
17524
|
-
"name",
|
|
17525
|
-
"id"
|
|
17526
|
-
];
|
|
17527
|
-
var ACTION_TARGET_CAP = 100;
|
|
17528
|
-
function actionLine(tool, input) {
|
|
17529
|
-
let target = "";
|
|
17530
|
-
if (input && typeof input === "object") {
|
|
17531
|
-
const rec = input;
|
|
17532
|
-
for (const k of TARGET_KEYS) {
|
|
17533
|
-
const v = rec[k];
|
|
17534
|
-
if (typeof v === "string" && v.trim()) {
|
|
17535
|
-
target = v.trim().split("\n")[0];
|
|
17536
|
-
break;
|
|
17537
|
-
}
|
|
17538
|
-
}
|
|
17539
|
-
} else if (typeof input === "string") {
|
|
17540
|
-
target = input.trim().split("\n")[0];
|
|
17541
|
-
}
|
|
17542
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
17543
|
-
return target ? `${tool} ${target}` : tool;
|
|
17544
|
-
}
|
|
17545
|
-
|
|
17546
17693
|
// src/core/transcript-dsh.ts
|
|
17547
17694
|
var HINDSIGHT_PLUGIN = "hindsight";
|
|
17548
17695
|
function textOf(message) {
|
|
@@ -17593,6 +17740,9 @@ var name = HINDSIGHT_PLUGIN;
|
|
|
17593
17740
|
var inject = ["agents"];
|
|
17594
17741
|
var workspaces = /* @__PURE__ */ new Map();
|
|
17595
17742
|
var liveAgents = /* @__PURE__ */ new Map();
|
|
17743
|
+
function dshSessionEvents(session) {
|
|
17744
|
+
return session.snapshotEvents?.() ?? session.events ?? [];
|
|
17745
|
+
}
|
|
17596
17746
|
function workspaceRoot(agent) {
|
|
17597
17747
|
return agent.session.header.cwd || process.cwd();
|
|
17598
17748
|
}
|
|
@@ -17607,7 +17757,7 @@ function workspaceFor(root) {
|
|
|
17607
17757
|
const core = new RuntimeCore(client, bankId, cfg, HARNESS2, root);
|
|
17608
17758
|
core.setTranscriptSource(async (sessionId) => {
|
|
17609
17759
|
const agent = liveAgents.get(sessionId);
|
|
17610
|
-
return agent ? readDshEvents(agent.session
|
|
17760
|
+
return agent ? readDshEvents(dshSessionEvents(agent.session)) : [];
|
|
17611
17761
|
});
|
|
17612
17762
|
const workspace = { core, root };
|
|
17613
17763
|
workspaces.set(root, workspace);
|
|
@@ -17742,6 +17892,7 @@ export {
|
|
|
17742
17892
|
apply,
|
|
17743
17893
|
createDshHooks,
|
|
17744
17894
|
dsh_default as default,
|
|
17895
|
+
dshSessionEvents,
|
|
17745
17896
|
inject,
|
|
17746
17897
|
name,
|
|
17747
17898
|
toDshParameters
|