@vectorize-io/hindsight-coding-agents 0.1.0 → 0.1.2
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 +93 -28
- package/dist/antigravity-hook.js +129 -59
- package/dist/antigravity-statusline.js +3 -1
- package/dist/antigravity-stop-hook.js +241 -71
- package/dist/claude-hook.js +129 -59
- package/dist/claude-sessionstart-hook.js +133 -64
- package/dist/claude-stop-hook.js +241 -71
- package/dist/cline.js +155 -21
- package/dist/codex-hook.js +129 -59
- package/dist/codex-sessionstart-hook.js +133 -64
- package/dist/codex-stop-hook.js +241 -71
- package/dist/copilot-hook.js +129 -59
- package/dist/copilot-sessionstart-hook.js +133 -64
- package/dist/copilot-stop-hook.js +241 -71
- package/dist/cursor-hook.js +129 -59
- package/dist/cursor-sessionstart-hook.js +133 -64
- package/dist/cursor-stop-hook.js +241 -71
- package/dist/daemon-start.js +3 -1
- package/dist/deepen.js +61 -17
- package/dist/devin-hook.js +129 -59
- package/dist/devin-sessionstart-hook.js +133 -64
- package/dist/devin-stop-hook.js +241 -71
- package/dist/grok-hook.js +129 -59
- package/dist/grok-sessionstart-hook.js +133 -64
- package/dist/grok-stop-hook.js +241 -71
- package/dist/hindsight-seed.js +3 -1
- package/dist/index.js +166 -22
- package/dist/installer.js +103 -79
- package/dist/kilo.js +166 -22
- package/dist/mcp-server.js +54 -14
- package/dist/status.js +53 -13
- package/package.json +1 -1
- package/skill/SKILL.md +4 -4
package/dist/codex-stop-hook.js
CHANGED
|
@@ -212,7 +212,9 @@ function readEnvConfig(env = process.env) {
|
|
|
212
212
|
function loadConfig(opts = {}) {
|
|
213
213
|
const o = typeof opts === "string" ? { path: opts } : opts;
|
|
214
214
|
const withEnv = applyLayer({}, readEnvConfig(), o.harness);
|
|
215
|
-
|
|
215
|
+
const raw = applyLayer(withEnv, readRaw(o.path ?? CONFIG_PATH), o.harness);
|
|
216
|
+
if (!raw.harness && o.harness) raw.harness = o.harness;
|
|
217
|
+
return resolveConfig(raw);
|
|
216
218
|
}
|
|
217
219
|
var BANK_OVERRIDE_EXCLUDED = [
|
|
218
220
|
"bankId",
|
|
@@ -296,7 +298,7 @@ var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAG
|
|
|
296
298
|
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.`;
|
|
297
299
|
var REFLECT_MISSION = "You are a debugging assistant with the project's past decisions in memory (git rationale and developer chats). Given a bug's SYMPTOM, find the past decision whose rationale explains the ROOT CAUSE \u2014 not one that merely shares vocabulary. Answer with the PRECISE fix: state the EXACT rule and the LITERAL values, identifiers, strings, numbers, or set members that were decided \u2014 quote them VERBATIM, never paraphrase, generalize, or omit them (give the actual decided value, not 'the project standard'). If memories CONFLICT on the same rule, the LATEST decision wins \u2014 prefer facts that explicitly amend or supersede an earlier one, state the superseded rule as no longer in effect, and never present it as the fix. Name the function/file to change and cite the REF-ID(s). If NOTHING in memory genuinely explains THIS symptom, say exactly that in one short sentence \u2014 a wrong-but-confident nearest match is worse than an honest miss; never stretch an unrelated decision to fit.";
|
|
298
300
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
299
|
-
var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details.";
|
|
301
|
+
var OBSERVATIONS_MISSION = "Consolidate durable knowledge about THIS codebase \u2014 recurring patterns, conventions, module responsibilities, and how components relate \u2014 from the ingested commits and conversations. Favor stable structural understanding over one-off details. When a new fact contradicts or supersedes an existing observation, UPDATE that observation to reflect the current state rather than creating a sibling alongside it; note that the rule was revised and when, so the superseded version is visible as history rather than as a competing claim.";
|
|
300
302
|
var RETAIN_STRATEGIES = {
|
|
301
303
|
git: { retain_mission: GIT_MISSION, retain_extraction_mode: "verbose" },
|
|
302
304
|
// ONE big aggregated document (last N commit messages, no diffs) -> a larger chunk size so it stays
|
|
@@ -414,8 +416,22 @@ var CODING_BANK_TEMPLATE = {
|
|
|
414
416
|
|
|
415
417
|
// src/core/util.ts
|
|
416
418
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
419
|
+
function semverGte(version, min) {
|
|
420
|
+
const parts = (v) => {
|
|
421
|
+
const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
422
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
|
|
423
|
+
};
|
|
424
|
+
const a = version ? parts(version) : void 0;
|
|
425
|
+
const b = parts(min);
|
|
426
|
+
if (!a || !b) return false;
|
|
427
|
+
for (let i = 0; i < 3; i++) {
|
|
428
|
+
if (a[i] !== b[i]) return a[i] > b[i];
|
|
429
|
+
}
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
417
432
|
|
|
418
433
|
// src/core/hindsight.ts
|
|
434
|
+
var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
|
|
419
435
|
var KnowledgePagesUnavailableError = class extends Error {
|
|
420
436
|
code = "knowledge_pages_unavailable";
|
|
421
437
|
constructor() {
|
|
@@ -432,6 +448,8 @@ var HindsightClient = class {
|
|
|
432
448
|
// async operation ids collected by retain(), for drain()
|
|
433
449
|
/** Tri-state capability probe: unknown until the first page request, then cached. */
|
|
434
450
|
knowledgePagesSupported;
|
|
451
|
+
/** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
|
|
452
|
+
idempotentRetain;
|
|
435
453
|
log;
|
|
436
454
|
constructor(o) {
|
|
437
455
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
@@ -460,7 +478,8 @@ var HindsightClient = class {
|
|
|
460
478
|
throw new Error(`${method} ${url} -> ${r.status} ${await r.text()}`);
|
|
461
479
|
return r;
|
|
462
480
|
}
|
|
463
|
-
/** Retain one memory.
|
|
481
|
+
/** Retain one memory. ALWAYS async: enqueue extraction server-side and collect its op-id for
|
|
482
|
+
* drain(). Nothing in this plugin can afford to block a coding agent's hook on extraction. */
|
|
464
483
|
async retain(content, context, documentId, tags, strategy, opts = {}) {
|
|
465
484
|
const item = {
|
|
466
485
|
content,
|
|
@@ -471,14 +490,36 @@ var HindsightClient = class {
|
|
|
471
490
|
};
|
|
472
491
|
if (opts.timestamp) item.timestamp = opts.timestamp;
|
|
473
492
|
if (opts.metadata) item.metadata = opts.metadata;
|
|
474
|
-
|
|
475
|
-
const
|
|
476
|
-
if (
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
493
|
+
if (opts.updateMode) item.update_mode = opts.updateMode;
|
|
494
|
+
const body = { items: [item], async: true };
|
|
495
|
+
if (opts.operationId) body.operation_id = opts.operationId;
|
|
496
|
+
const r = await this.req("POST", this.bankUrl("/memories"), body);
|
|
497
|
+
try {
|
|
498
|
+
const j = await r.json();
|
|
499
|
+
if (j.operation_id) this.opIds.push(j.operation_id);
|
|
500
|
+
} catch {
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Whether this server honours `operation_id` on an async retain, and can therefore be appended to
|
|
505
|
+
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via GET /version; anything
|
|
506
|
+
* unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
|
|
507
|
+
*/
|
|
508
|
+
async supportsIdempotentRetain() {
|
|
509
|
+
if (this.idempotentRetain === void 0) {
|
|
510
|
+
this.idempotentRetain = await this.probeIdempotentRetain();
|
|
511
|
+
this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
|
|
512
|
+
}
|
|
513
|
+
return this.idempotentRetain;
|
|
514
|
+
}
|
|
515
|
+
async probeIdempotentRetain() {
|
|
516
|
+
try {
|
|
517
|
+
const r = await this.req("GET", `${this.apiUrl}/version`);
|
|
518
|
+
if (!r.ok) return false;
|
|
519
|
+
const j = await r.json();
|
|
520
|
+
return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
|
|
521
|
+
} catch {
|
|
522
|
+
return false;
|
|
482
523
|
}
|
|
483
524
|
}
|
|
484
525
|
/**
|
|
@@ -766,8 +807,7 @@ var HindsightClient = class {
|
|
|
766
807
|
"initiative marker",
|
|
767
808
|
markerId,
|
|
768
809
|
["knowledge:feature-work", `relatedPageId:${pageId}`],
|
|
769
|
-
"document"
|
|
770
|
-
{ async: true }
|
|
810
|
+
"document"
|
|
771
811
|
);
|
|
772
812
|
return { page_id: pageId };
|
|
773
813
|
}
|
|
@@ -794,9 +834,73 @@ var HindsightClient = class {
|
|
|
794
834
|
import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
795
835
|
import { tmpdir as tmpdir2 } from "os";
|
|
796
836
|
import { dirname as dirname4, join as join5 } from "path";
|
|
837
|
+
function sessionCacheFile(harness, sessionId) {
|
|
838
|
+
return join5(tmpdir2(), `hindsight-${harness}`, `${sessionId}.json`);
|
|
839
|
+
}
|
|
840
|
+
function readSessionCache(cacheFile) {
|
|
841
|
+
try {
|
|
842
|
+
return JSON.parse(readFileSync2(cacheFile, "utf8"));
|
|
843
|
+
} catch {
|
|
844
|
+
return {};
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
function writeSessionCache(cacheFile, cache) {
|
|
848
|
+
try {
|
|
849
|
+
mkdirSync2(dirname4(cacheFile), { recursive: true });
|
|
850
|
+
writeFileSync(cacheFile, JSON.stringify(cache));
|
|
851
|
+
} catch {
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
function fileCursorStore(harness) {
|
|
855
|
+
return {
|
|
856
|
+
read: (sessionId) => readSessionCache(sessionCacheFile(harness, sessionId)).retain,
|
|
857
|
+
write: (sessionId, cursor) => {
|
|
858
|
+
const file = sessionCacheFile(harness, sessionId);
|
|
859
|
+
writeSessionCache(file, { ...readSessionCache(file), retain: cursor });
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
}
|
|
797
863
|
|
|
798
864
|
// src/core/retain-hook.ts
|
|
799
|
-
import { readFileSync as
|
|
865
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
866
|
+
|
|
867
|
+
// src/core/retain-cursor.ts
|
|
868
|
+
import { createHash } from "crypto";
|
|
869
|
+
function fingerprintTurns(turns, count) {
|
|
870
|
+
const h = createHash("sha1").update(String(count));
|
|
871
|
+
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
872
|
+
return h.digest("hex");
|
|
873
|
+
}
|
|
874
|
+
function planRetain(turns, cursor, opts) {
|
|
875
|
+
if (!turns.length) return { mode: "skip" };
|
|
876
|
+
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
877
|
+
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
878
|
+
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
879
|
+
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
880
|
+
if (cursor.turns === turns.length) return { mode: "skip" };
|
|
881
|
+
return { mode: "append", fromTurn: cursor.turns };
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// src/core/uuid.ts
|
|
885
|
+
import { createHash as createHash2 } from "crypto";
|
|
886
|
+
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
887
|
+
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
888
|
+
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
889
|
+
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
890
|
+
const bytes = Buffer.from(
|
|
891
|
+
createHash2("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
892
|
+
);
|
|
893
|
+
bytes[6] = bytes[6] & 15 | 80;
|
|
894
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
895
|
+
const hex = bytes.toString("hex");
|
|
896
|
+
return [
|
|
897
|
+
hex.slice(0, 8),
|
|
898
|
+
hex.slice(8, 12),
|
|
899
|
+
hex.slice(12, 16),
|
|
900
|
+
hex.slice(16, 20),
|
|
901
|
+
hex.slice(20)
|
|
902
|
+
].join("-");
|
|
903
|
+
}
|
|
800
904
|
|
|
801
905
|
// src/core/chat.ts
|
|
802
906
|
function withRefId(refId, turns, baseTs) {
|
|
@@ -805,17 +909,62 @@ function withRefId(refId, turns, baseTs) {
|
|
|
805
909
|
function renderSessionJsonl(refId, turns, baseTs) {
|
|
806
910
|
return withRefId(refId, turns, baseTs).map((t) => JSON.stringify(t)).join("\n");
|
|
807
911
|
}
|
|
808
|
-
async function
|
|
912
|
+
async function supportsAppend(client) {
|
|
913
|
+
try {
|
|
914
|
+
return await client.supportsIdempotentRetain();
|
|
915
|
+
} catch {
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
var writeBacks = /* @__PURE__ */ new WeakMap();
|
|
920
|
+
function serialize(cursors, sessionId, write2) {
|
|
921
|
+
const perSession = writeBacks.get(cursors) ?? /* @__PURE__ */ new Map();
|
|
922
|
+
writeBacks.set(cursors, perSession);
|
|
923
|
+
const next = (perSession.get(sessionId) ?? Promise.resolve()).then(write2, write2);
|
|
924
|
+
const tail = next.catch(() => {
|
|
925
|
+
});
|
|
926
|
+
perSession.set(sessionId, tail);
|
|
927
|
+
void tail.then(() => {
|
|
928
|
+
if (perSession.get(sessionId) === tail) perSession.delete(sessionId);
|
|
929
|
+
});
|
|
930
|
+
return next;
|
|
931
|
+
}
|
|
932
|
+
async function retainLiveSession(client, sessionId, turns, startTs, harness, opts = {}) {
|
|
933
|
+
const cursors = opts.cursors;
|
|
934
|
+
if (!cursors) return writeSession(client, sessionId, turns, startTs, harness);
|
|
935
|
+
return serialize(
|
|
936
|
+
cursors,
|
|
937
|
+
sessionId,
|
|
938
|
+
() => writeSession(client, sessionId, turns, startTs, harness, cursors)
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
async function writeSession(client, sessionId, turns, startTs, harness, cursors) {
|
|
809
942
|
const refId = `conversation:${sessionId}`;
|
|
943
|
+
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
944
|
+
const plan = planRetain(turns, cursors?.read(sessionId), { appendSupported, bank: client.bank });
|
|
945
|
+
if (plan.mode === "skip") return;
|
|
946
|
+
const content = plan.mode === "append" ? turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n") : renderSessionJsonl(refId, turns, startTs);
|
|
947
|
+
const next = {
|
|
948
|
+
turns: turns.length,
|
|
949
|
+
fingerprint: fingerprintTurns(turns, turns.length),
|
|
950
|
+
bank: client.bank
|
|
951
|
+
};
|
|
952
|
+
cursors?.write(sessionId, { ...next, dirty: true });
|
|
810
953
|
await client.retain(
|
|
811
|
-
|
|
954
|
+
content,
|
|
812
955
|
"coding agent session",
|
|
813
956
|
refId,
|
|
814
957
|
["source:chat", ...harness ? [`harness:${harness}`] : []],
|
|
815
958
|
"conversation",
|
|
816
959
|
{
|
|
817
960
|
timestamp: startTs,
|
|
818
|
-
|
|
961
|
+
updateMode: plan.mode === "append" ? "append" : void 0,
|
|
962
|
+
// Identity of THIS payload: a resubmission of the same bytes is collapsed server-side into
|
|
963
|
+
// the original operation instead of extracting (or appending) twice.
|
|
964
|
+
operationId: uuidV5(`${client.bank}
|
|
965
|
+
${refId}
|
|
966
|
+
${plan.mode}
|
|
967
|
+
${content}`),
|
|
819
968
|
metadata: {
|
|
820
969
|
source: "chat",
|
|
821
970
|
session_id: sessionId,
|
|
@@ -824,6 +973,7 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness) {
|
|
|
824
973
|
}
|
|
825
974
|
}
|
|
826
975
|
);
|
|
976
|
+
cursors?.write(sessionId, next);
|
|
827
977
|
}
|
|
828
978
|
|
|
829
979
|
// src/core/daemon.ts
|
|
@@ -942,8 +1092,66 @@ function preflightDaemon(cfg, harness) {
|
|
|
942
1092
|
return true;
|
|
943
1093
|
}
|
|
944
1094
|
|
|
945
|
-
// src/core/
|
|
946
|
-
import {
|
|
1095
|
+
// src/core/jsonl.ts
|
|
1096
|
+
import { closeSync, openSync, readSync, statSync } from "fs";
|
|
1097
|
+
import { StringDecoder } from "string_decoder";
|
|
1098
|
+
var CHUNK_BYTES = 64 * 1024;
|
|
1099
|
+
var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
|
|
1100
|
+
function readJsonlTail(path, opts) {
|
|
1101
|
+
const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
|
|
1102
|
+
let size;
|
|
1103
|
+
try {
|
|
1104
|
+
size = statSync(path).size;
|
|
1105
|
+
} catch {
|
|
1106
|
+
return { lines: emptyLines(), skippedBytes: 0 };
|
|
1107
|
+
}
|
|
1108
|
+
const skippedBytes = size > maxBytes ? size - maxBytes : 0;
|
|
1109
|
+
if (skippedBytes > 0) {
|
|
1110
|
+
log.warn(opts.scope, "transcript too large \u2014 retaining the most recent portion only", {
|
|
1111
|
+
path,
|
|
1112
|
+
sizeBytes: size,
|
|
1113
|
+
skippedBytes
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
return { lines: streamLines(path, skippedBytes), skippedBytes };
|
|
1117
|
+
}
|
|
1118
|
+
function* emptyLines() {
|
|
1119
|
+
}
|
|
1120
|
+
function* streamLines(path, start) {
|
|
1121
|
+
let fd;
|
|
1122
|
+
try {
|
|
1123
|
+
fd = openSync(path, "r");
|
|
1124
|
+
} catch {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
try {
|
|
1128
|
+
const buffer = Buffer.allocUnsafe(CHUNK_BYTES);
|
|
1129
|
+
const decoder = new StringDecoder("utf8");
|
|
1130
|
+
let pending = "";
|
|
1131
|
+
let position = start > 0 ? start - 1 : 0;
|
|
1132
|
+
let dropPartial = start > 0;
|
|
1133
|
+
for (; ; ) {
|
|
1134
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, position);
|
|
1135
|
+
if (bytesRead <= 0) break;
|
|
1136
|
+
position += bytesRead;
|
|
1137
|
+
pending += decoder.write(buffer.subarray(0, bytesRead));
|
|
1138
|
+
let newline;
|
|
1139
|
+
while ((newline = pending.indexOf("\n")) !== -1) {
|
|
1140
|
+
const line = pending.slice(0, newline);
|
|
1141
|
+
pending = pending.slice(newline + 1);
|
|
1142
|
+
if (dropPartial) {
|
|
1143
|
+
dropPartial = false;
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
1146
|
+
yield line;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
pending += decoder.end();
|
|
1150
|
+
if (pending && !dropPartial) yield pending;
|
|
1151
|
+
} finally {
|
|
1152
|
+
closeSync(fd);
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
947
1155
|
|
|
948
1156
|
// src/core/transcript-util.ts
|
|
949
1157
|
var MEMORY_TAG_RE = /<(hook_prompt|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
|
|
@@ -1005,14 +1213,8 @@ function renderLine(content, type) {
|
|
|
1005
1213
|
return out;
|
|
1006
1214
|
}
|
|
1007
1215
|
function readClaudeTranscript(path) {
|
|
1008
|
-
let raw;
|
|
1009
|
-
try {
|
|
1010
|
-
raw = readFileSync4(path, "utf8");
|
|
1011
|
-
} catch {
|
|
1012
|
-
return [];
|
|
1013
|
-
}
|
|
1014
1216
|
const turns = [];
|
|
1015
|
-
for (const rawLine of
|
|
1217
|
+
for (const rawLine of readJsonlTail(path, { scope: "claude-code" }).lines) {
|
|
1016
1218
|
const trimmed = rawLine.trim();
|
|
1017
1219
|
if (!trimmed) continue;
|
|
1018
1220
|
let parsed;
|
|
@@ -1045,7 +1247,9 @@ async function buildRetain(args) {
|
|
|
1045
1247
|
const startTs = turns[0]?.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1046
1248
|
const t0 = Date.now();
|
|
1047
1249
|
try {
|
|
1048
|
-
await retainLiveSession(client, sessionId, turns, startTs, harness
|
|
1250
|
+
await retainLiveSession(client, sessionId, turns, startTs, harness, {
|
|
1251
|
+
cursors: args.cursors ?? fileCursorStore(harness)
|
|
1252
|
+
});
|
|
1049
1253
|
diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
|
|
1050
1254
|
} catch (e) {
|
|
1051
1255
|
log.warn(harness, "session write-back failed", {
|
|
@@ -1062,7 +1266,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1062
1266
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
1063
1267
|
let ev = {};
|
|
1064
1268
|
try {
|
|
1065
|
-
ev = JSON.parse(
|
|
1269
|
+
ev = JSON.parse(readFileSync4(0, "utf8"));
|
|
1066
1270
|
} catch {
|
|
1067
1271
|
return;
|
|
1068
1272
|
}
|
|
@@ -1088,7 +1292,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1088
1292
|
}
|
|
1089
1293
|
|
|
1090
1294
|
// src/core/session-start.ts
|
|
1091
|
-
import { readFileSync as
|
|
1295
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
1092
1296
|
|
|
1093
1297
|
// src/core/git.ts
|
|
1094
1298
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
@@ -1105,13 +1309,12 @@ import { delimiter, dirname as dirname6, join as join7 } from "path";
|
|
|
1105
1309
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1106
1310
|
|
|
1107
1311
|
// src/core/skill-sync.ts
|
|
1108
|
-
import { cpSync, existsSync as existsSync3, readFileSync as
|
|
1312
|
+
import { cpSync, existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
1109
1313
|
import { homedir as homedir4 } from "os";
|
|
1110
1314
|
import { dirname as dirname7, join as join8 } from "path";
|
|
1111
1315
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1112
1316
|
|
|
1113
1317
|
// src/core/transcript-codex.ts
|
|
1114
|
-
import { readFileSync as readFileSync8 } from "fs";
|
|
1115
1318
|
function isSyntheticUserText(text) {
|
|
1116
1319
|
const s = text.trimStart();
|
|
1117
1320
|
return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
|
|
@@ -1120,14 +1323,8 @@ function messageText(payload) {
|
|
|
1120
1323
|
return (payload.content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
1121
1324
|
}
|
|
1122
1325
|
function readCodexTranscript(path) {
|
|
1123
|
-
let raw;
|
|
1124
|
-
try {
|
|
1125
|
-
raw = readFileSync8(path, "utf8");
|
|
1126
|
-
} catch {
|
|
1127
|
-
return [];
|
|
1128
|
-
}
|
|
1129
1326
|
const turns = [];
|
|
1130
|
-
for (const rawLine of
|
|
1327
|
+
for (const rawLine of readJsonlTail(path, { scope: "codex" }).lines) {
|
|
1131
1328
|
const trimmed = rawLine.trim();
|
|
1132
1329
|
if (!trimmed) continue;
|
|
1133
1330
|
let parsed;
|
|
@@ -1161,7 +1358,6 @@ function readCodexTranscript(path) {
|
|
|
1161
1358
|
}
|
|
1162
1359
|
|
|
1163
1360
|
// src/core/transcript-cursor.ts
|
|
1164
|
-
import { readFileSync as readFileSync9 } from "fs";
|
|
1165
1361
|
function withTimestamp(turn, timestamp) {
|
|
1166
1362
|
return timestamp ? { ...turn, timestamp } : turn;
|
|
1167
1363
|
}
|
|
@@ -1171,14 +1367,8 @@ function textFrom(content) {
|
|
|
1171
1367
|
return content.filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n");
|
|
1172
1368
|
}
|
|
1173
1369
|
function readCursorTranscript(path) {
|
|
1174
|
-
let raw;
|
|
1175
|
-
try {
|
|
1176
|
-
raw = readFileSync9(path, "utf8");
|
|
1177
|
-
} catch {
|
|
1178
|
-
return [];
|
|
1179
|
-
}
|
|
1180
1370
|
const turns = [];
|
|
1181
|
-
for (const rawLine of
|
|
1371
|
+
for (const rawLine of readJsonlTail(path, { scope: "cursor-cli" }).lines) {
|
|
1182
1372
|
let parsed;
|
|
1183
1373
|
try {
|
|
1184
1374
|
parsed = JSON.parse(rawLine);
|
|
@@ -1214,17 +1404,10 @@ function readCursorTranscript(path) {
|
|
|
1214
1404
|
}
|
|
1215
1405
|
|
|
1216
1406
|
// src/core/transcript-antigravity.ts
|
|
1217
|
-
import { readFileSync as readFileSync10 } from "fs";
|
|
1218
1407
|
function readAntigravityTranscript(path) {
|
|
1219
1408
|
if (!path) return [];
|
|
1220
|
-
let raw;
|
|
1221
|
-
try {
|
|
1222
|
-
raw = readFileSync10(path, "utf8");
|
|
1223
|
-
} catch {
|
|
1224
|
-
return [];
|
|
1225
|
-
}
|
|
1226
1409
|
const turns = [];
|
|
1227
|
-
for (const line of
|
|
1410
|
+
for (const line of readJsonlTail(path, { scope: "antigravity-cli" }).lines) {
|
|
1228
1411
|
try {
|
|
1229
1412
|
const event = JSON.parse(line);
|
|
1230
1413
|
const role = event.role ?? event.message?.role ?? event.type;
|
|
@@ -1245,16 +1428,9 @@ function readAntigravityTranscript(path) {
|
|
|
1245
1428
|
}
|
|
1246
1429
|
|
|
1247
1430
|
// src/core/transcript-copilot.ts
|
|
1248
|
-
import { readFileSync as readFileSync11 } from "fs";
|
|
1249
1431
|
function readCopilotTranscript(path) {
|
|
1250
|
-
let raw;
|
|
1251
|
-
try {
|
|
1252
|
-
raw = readFileSync11(path, "utf8");
|
|
1253
|
-
} catch {
|
|
1254
|
-
return [];
|
|
1255
|
-
}
|
|
1256
1432
|
const turns = [];
|
|
1257
|
-
for (const rawLine of
|
|
1433
|
+
for (const rawLine of readJsonlTail(path, { scope: "copilot-cli" }).lines) {
|
|
1258
1434
|
try {
|
|
1259
1435
|
const event = JSON.parse(rawLine);
|
|
1260
1436
|
const role = event.type === "user.message" ? "user" : event.type === "assistant.message" ? "assistant" : void 0;
|
|
@@ -1268,7 +1444,7 @@ function readCopilotTranscript(path) {
|
|
|
1268
1444
|
}
|
|
1269
1445
|
|
|
1270
1446
|
// src/core/transcript-grok.ts
|
|
1271
|
-
import { existsSync as existsSync4, readFileSync as
|
|
1447
|
+
import { existsSync as existsSync4, readFileSync as readFileSync7, readdirSync } from "fs";
|
|
1272
1448
|
import { homedir as homedir5 } from "os";
|
|
1273
1449
|
import { join as join9 } from "path";
|
|
1274
1450
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
@@ -1279,7 +1455,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
|
1279
1455
|
try {
|
|
1280
1456
|
for (const candidate of readdirSync(sessionsDir)) {
|
|
1281
1457
|
const directory = join9(sessionsDir, candidate);
|
|
1282
|
-
if (
|
|
1458
|
+
if (readFileSync7(join9(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
1283
1459
|
return join9(directory, sessionId, CHAT_HISTORY);
|
|
1284
1460
|
}
|
|
1285
1461
|
}
|
|
@@ -1288,14 +1464,8 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
|
1288
1464
|
return direct;
|
|
1289
1465
|
}
|
|
1290
1466
|
function readGrokTranscript(path) {
|
|
1291
|
-
let raw;
|
|
1292
|
-
try {
|
|
1293
|
-
raw = readFileSync12(path, "utf8");
|
|
1294
|
-
} catch {
|
|
1295
|
-
return [];
|
|
1296
|
-
}
|
|
1297
1467
|
const turns = [];
|
|
1298
|
-
for (const rawLine of
|
|
1468
|
+
for (const rawLine of readJsonlTail(path, { scope: "grok-build" }).lines) {
|
|
1299
1469
|
try {
|
|
1300
1470
|
const event = JSON.parse(rawLine);
|
|
1301
1471
|
if (event.type !== "user" && event.type !== "assistant") continue;
|