@vectorize-io/hindsight-coding-agents 0.1.1 → 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/dist/antigravity-hook.js +125 -57
- package/dist/antigravity-stop-hook.js +237 -69
- package/dist/claude-hook.js +125 -57
- package/dist/claude-sessionstart-hook.js +128 -61
- package/dist/claude-stop-hook.js +237 -69
- package/dist/cline.js +150 -18
- package/dist/codex-hook.js +125 -57
- package/dist/codex-sessionstart-hook.js +128 -61
- package/dist/codex-stop-hook.js +237 -69
- package/dist/copilot-hook.js +125 -57
- package/dist/copilot-sessionstart-hook.js +128 -61
- package/dist/copilot-stop-hook.js +237 -69
- package/dist/cursor-hook.js +125 -57
- package/dist/cursor-sessionstart-hook.js +128 -61
- package/dist/cursor-stop-hook.js +237 -69
- package/dist/deepen.js +57 -15
- package/dist/devin-hook.js +125 -57
- package/dist/devin-sessionstart-hook.js +128 -61
- package/dist/devin-stop-hook.js +237 -69
- package/dist/grok-hook.js +125 -57
- package/dist/grok-sessionstart-hook.js +128 -61
- package/dist/grok-stop-hook.js +237 -69
- package/dist/index.js +161 -19
- package/dist/installer.js +103 -79
- package/dist/kilo.js +161 -19
- package/dist/mcp-server.js +50 -12
- package/dist/status.js +49 -11
- package/package.json +1 -1
package/dist/cline.js
CHANGED
|
@@ -398,8 +398,22 @@ var CODING_BANK_TEMPLATE = {
|
|
|
398
398
|
|
|
399
399
|
// src/core/util.ts
|
|
400
400
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
401
|
+
function semverGte(version2, min) {
|
|
402
|
+
const parts = (v) => {
|
|
403
|
+
const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
404
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
|
|
405
|
+
};
|
|
406
|
+
const a = version2 ? parts(version2) : void 0;
|
|
407
|
+
const b = parts(min);
|
|
408
|
+
if (!a || !b) return false;
|
|
409
|
+
for (let i = 0; i < 3; i++) {
|
|
410
|
+
if (a[i] !== b[i]) return a[i] > b[i];
|
|
411
|
+
}
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
401
414
|
|
|
402
415
|
// src/core/hindsight.ts
|
|
416
|
+
var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
|
|
403
417
|
var KnowledgePagesUnavailableError = class extends Error {
|
|
404
418
|
code = "knowledge_pages_unavailable";
|
|
405
419
|
constructor() {
|
|
@@ -416,6 +430,8 @@ var HindsightClient = class {
|
|
|
416
430
|
// async operation ids collected by retain(), for drain()
|
|
417
431
|
/** Tri-state capability probe: unknown until the first page request, then cached. */
|
|
418
432
|
knowledgePagesSupported;
|
|
433
|
+
/** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
|
|
434
|
+
idempotentRetain;
|
|
419
435
|
log;
|
|
420
436
|
constructor(o) {
|
|
421
437
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
@@ -444,7 +460,8 @@ var HindsightClient = class {
|
|
|
444
460
|
throw new Error(`${method} ${url2} -> ${r.status} ${await r.text()}`);
|
|
445
461
|
return r;
|
|
446
462
|
}
|
|
447
|
-
/** Retain one memory.
|
|
463
|
+
/** Retain one memory. ALWAYS async: enqueue extraction server-side and collect its op-id for
|
|
464
|
+
* drain(). Nothing in this plugin can afford to block a coding agent's hook on extraction. */
|
|
448
465
|
async retain(content, context, documentId, tags, strategy, opts = {}) {
|
|
449
466
|
const item = {
|
|
450
467
|
content,
|
|
@@ -455,14 +472,36 @@ var HindsightClient = class {
|
|
|
455
472
|
};
|
|
456
473
|
if (opts.timestamp) item.timestamp = opts.timestamp;
|
|
457
474
|
if (opts.metadata) item.metadata = opts.metadata;
|
|
458
|
-
|
|
459
|
-
const
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
475
|
+
if (opts.updateMode) item.update_mode = opts.updateMode;
|
|
476
|
+
const body = { items: [item], async: true };
|
|
477
|
+
if (opts.operationId) body.operation_id = opts.operationId;
|
|
478
|
+
const r = await this.req("POST", this.bankUrl("/memories"), body);
|
|
479
|
+
try {
|
|
480
|
+
const j = await r.json();
|
|
481
|
+
if (j.operation_id) this.opIds.push(j.operation_id);
|
|
482
|
+
} catch {
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Whether this server honours `operation_id` on an async retain, and can therefore be appended to
|
|
487
|
+
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via GET /version; anything
|
|
488
|
+
* unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
|
|
489
|
+
*/
|
|
490
|
+
async supportsIdempotentRetain() {
|
|
491
|
+
if (this.idempotentRetain === void 0) {
|
|
492
|
+
this.idempotentRetain = await this.probeIdempotentRetain();
|
|
493
|
+
this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
|
|
494
|
+
}
|
|
495
|
+
return this.idempotentRetain;
|
|
496
|
+
}
|
|
497
|
+
async probeIdempotentRetain() {
|
|
498
|
+
try {
|
|
499
|
+
const r = await this.req("GET", `${this.apiUrl}/version`);
|
|
500
|
+
if (!r.ok) return false;
|
|
501
|
+
const j = await r.json();
|
|
502
|
+
return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
|
|
503
|
+
} catch {
|
|
504
|
+
return false;
|
|
466
505
|
}
|
|
467
506
|
}
|
|
468
507
|
/**
|
|
@@ -750,8 +789,7 @@ var HindsightClient = class {
|
|
|
750
789
|
"initiative marker",
|
|
751
790
|
markerId,
|
|
752
791
|
["knowledge:feature-work", `relatedPageId:${pageId}`],
|
|
753
|
-
"document"
|
|
754
|
-
{ async: true }
|
|
792
|
+
"document"
|
|
755
793
|
);
|
|
756
794
|
return { page_id: pageId };
|
|
757
795
|
}
|
|
@@ -15791,7 +15829,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
15791
15829
|
docId,
|
|
15792
15830
|
["source:upload", ...opts.harness ? [`harness:${opts.harness}`] : []],
|
|
15793
15831
|
"document",
|
|
15794
|
-
{
|
|
15832
|
+
{ metadata: opts.harness ? { harness: opts.harness } : void 0 }
|
|
15795
15833
|
);
|
|
15796
15834
|
return { ok: true, doc_id: docId };
|
|
15797
15835
|
})
|
|
@@ -15799,6 +15837,51 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
15799
15837
|
];
|
|
15800
15838
|
}
|
|
15801
15839
|
|
|
15840
|
+
// src/core/retain-cursor.ts
|
|
15841
|
+
import { createHash } from "crypto";
|
|
15842
|
+
function fingerprintTurns(turns, count) {
|
|
15843
|
+
const h = createHash("sha1").update(String(count));
|
|
15844
|
+
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
15845
|
+
return h.digest("hex");
|
|
15846
|
+
}
|
|
15847
|
+
function planRetain(turns, cursor, opts) {
|
|
15848
|
+
if (!turns.length) return { mode: "skip" };
|
|
15849
|
+
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
15850
|
+
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
15851
|
+
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
15852
|
+
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
15853
|
+
if (cursor.turns === turns.length) return { mode: "skip" };
|
|
15854
|
+
return { mode: "append", fromTurn: cursor.turns };
|
|
15855
|
+
}
|
|
15856
|
+
function memoryCursorStore() {
|
|
15857
|
+
const cursors = /* @__PURE__ */ new Map();
|
|
15858
|
+
return {
|
|
15859
|
+
read: (sessionId2) => cursors.get(sessionId2),
|
|
15860
|
+
write: (sessionId2, cursor) => void cursors.set(sessionId2, cursor)
|
|
15861
|
+
};
|
|
15862
|
+
}
|
|
15863
|
+
|
|
15864
|
+
// src/core/uuid.ts
|
|
15865
|
+
import { createHash as createHash2 } from "crypto";
|
|
15866
|
+
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
15867
|
+
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
15868
|
+
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
15869
|
+
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
15870
|
+
const bytes = Buffer.from(
|
|
15871
|
+
createHash2("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
15872
|
+
);
|
|
15873
|
+
bytes[6] = bytes[6] & 15 | 80;
|
|
15874
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
15875
|
+
const hex3 = bytes.toString("hex");
|
|
15876
|
+
return [
|
|
15877
|
+
hex3.slice(0, 8),
|
|
15878
|
+
hex3.slice(8, 12),
|
|
15879
|
+
hex3.slice(12, 16),
|
|
15880
|
+
hex3.slice(16, 20),
|
|
15881
|
+
hex3.slice(20)
|
|
15882
|
+
].join("-");
|
|
15883
|
+
}
|
|
15884
|
+
|
|
15802
15885
|
// src/core/chat.ts
|
|
15803
15886
|
function withRefId(refId, turns, baseTs) {
|
|
15804
15887
|
return [{ role: "system", content: `REF-ID: ${refId}`, timestamp: baseTs }, ...turns];
|
|
@@ -15806,17 +15889,62 @@ function withRefId(refId, turns, baseTs) {
|
|
|
15806
15889
|
function renderSessionJsonl(refId, turns, baseTs) {
|
|
15807
15890
|
return withRefId(refId, turns, baseTs).map((t) => JSON.stringify(t)).join("\n");
|
|
15808
15891
|
}
|
|
15809
|
-
async function
|
|
15892
|
+
async function supportsAppend(client) {
|
|
15893
|
+
try {
|
|
15894
|
+
return await client.supportsIdempotentRetain();
|
|
15895
|
+
} catch {
|
|
15896
|
+
return false;
|
|
15897
|
+
}
|
|
15898
|
+
}
|
|
15899
|
+
var writeBacks = /* @__PURE__ */ new WeakMap();
|
|
15900
|
+
function serialize(cursors, sessionId2, write2) {
|
|
15901
|
+
const perSession = writeBacks.get(cursors) ?? /* @__PURE__ */ new Map();
|
|
15902
|
+
writeBacks.set(cursors, perSession);
|
|
15903
|
+
const next = (perSession.get(sessionId2) ?? Promise.resolve()).then(write2, write2);
|
|
15904
|
+
const tail = next.catch(() => {
|
|
15905
|
+
});
|
|
15906
|
+
perSession.set(sessionId2, tail);
|
|
15907
|
+
void tail.then(() => {
|
|
15908
|
+
if (perSession.get(sessionId2) === tail) perSession.delete(sessionId2);
|
|
15909
|
+
});
|
|
15910
|
+
return next;
|
|
15911
|
+
}
|
|
15912
|
+
async function retainLiveSession(client, sessionId2, turns, startTs, harness, opts = {}) {
|
|
15913
|
+
const cursors = opts.cursors;
|
|
15914
|
+
if (!cursors) return writeSession(client, sessionId2, turns, startTs, harness);
|
|
15915
|
+
return serialize(
|
|
15916
|
+
cursors,
|
|
15917
|
+
sessionId2,
|
|
15918
|
+
() => writeSession(client, sessionId2, turns, startTs, harness, cursors)
|
|
15919
|
+
);
|
|
15920
|
+
}
|
|
15921
|
+
async function writeSession(client, sessionId2, turns, startTs, harness, cursors) {
|
|
15810
15922
|
const refId = `conversation:${sessionId2}`;
|
|
15923
|
+
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
15924
|
+
const plan = planRetain(turns, cursors?.read(sessionId2), { appendSupported, bank: client.bank });
|
|
15925
|
+
if (plan.mode === "skip") return;
|
|
15926
|
+
const content = plan.mode === "append" ? turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n") : renderSessionJsonl(refId, turns, startTs);
|
|
15927
|
+
const next = {
|
|
15928
|
+
turns: turns.length,
|
|
15929
|
+
fingerprint: fingerprintTurns(turns, turns.length),
|
|
15930
|
+
bank: client.bank
|
|
15931
|
+
};
|
|
15932
|
+
cursors?.write(sessionId2, { ...next, dirty: true });
|
|
15811
15933
|
await client.retain(
|
|
15812
|
-
|
|
15934
|
+
content,
|
|
15813
15935
|
"coding agent session",
|
|
15814
15936
|
refId,
|
|
15815
15937
|
["source:chat", ...harness ? [`harness:${harness}`] : []],
|
|
15816
15938
|
"conversation",
|
|
15817
15939
|
{
|
|
15818
15940
|
timestamp: startTs,
|
|
15819
|
-
|
|
15941
|
+
updateMode: plan.mode === "append" ? "append" : void 0,
|
|
15942
|
+
// Identity of THIS payload: a resubmission of the same bytes is collapsed server-side into
|
|
15943
|
+
// the original operation instead of extracting (or appending) twice.
|
|
15944
|
+
operationId: uuidV5(`${client.bank}
|
|
15945
|
+
${refId}
|
|
15946
|
+
${plan.mode}
|
|
15947
|
+
${content}`),
|
|
15820
15948
|
metadata: {
|
|
15821
15949
|
source: "chat",
|
|
15822
15950
|
session_id: sessionId2,
|
|
@@ -15825,6 +15953,7 @@ async function retainLiveSession(client, sessionId2, turns, startTs, harness) {
|
|
|
15825
15953
|
}
|
|
15826
15954
|
}
|
|
15827
15955
|
);
|
|
15956
|
+
cursors?.write(sessionId2, next);
|
|
15828
15957
|
}
|
|
15829
15958
|
|
|
15830
15959
|
// src/core/session-start.ts
|
|
@@ -15926,8 +16055,7 @@ async function buildSessionStartContext(args) {
|
|
|
15926
16055
|
"hindsight codebase-survey baseline",
|
|
15927
16056
|
`${SURVEY_BASELINE_PREFIX}${sha}`,
|
|
15928
16057
|
[SURVEY_BASELINE_TAG],
|
|
15929
|
-
"survey"
|
|
15930
|
-
{ async: true }
|
|
16058
|
+
"survey"
|
|
15931
16059
|
)
|
|
15932
16060
|
).catch(() => {
|
|
15933
16061
|
});
|
|
@@ -16152,6 +16280,8 @@ var RuntimeCore = class {
|
|
|
16152
16280
|
turnCount = /* @__PURE__ */ new Map();
|
|
16153
16281
|
// sessionId -> user-turn counter (cadence)
|
|
16154
16282
|
sessionState = /* @__PURE__ */ new Map();
|
|
16283
|
+
/** Live write-back cursors. In memory, unlike the hook harnesses': this host outlives the session. */
|
|
16284
|
+
cursors = memoryCursorStore();
|
|
16155
16285
|
/** Pulls a session's CURRENT transcript from the host (set by the adapter); see onSessionIdle. */
|
|
16156
16286
|
fetchTranscript;
|
|
16157
16287
|
lastInjection = "";
|
|
@@ -16307,7 +16437,9 @@ var RuntimeCore = class {
|
|
|
16307
16437
|
/** Fire-and-forget upsert of the session transcript; never throws into the host. */
|
|
16308
16438
|
retain(sessionId2, turns, startTs, trigger = "turn") {
|
|
16309
16439
|
const t0 = Date.now();
|
|
16310
|
-
void retainLiveSession(this.client, sessionId2, turns, startTs, this.harness
|
|
16440
|
+
void retainLiveSession(this.client, sessionId2, turns, startTs, this.harness, {
|
|
16441
|
+
cursors: this.cursors
|
|
16442
|
+
}).then(
|
|
16311
16443
|
() => diag(this.harness, "retain_ok", {
|
|
16312
16444
|
ms: Date.now() - t0,
|
|
16313
16445
|
turns: turns.length,
|
package/dist/codex-hook.js
CHANGED
|
@@ -442,8 +442,22 @@ var CODING_BANK_TEMPLATE = {
|
|
|
442
442
|
|
|
443
443
|
// src/core/util.ts
|
|
444
444
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
445
|
+
function semverGte(version, min) {
|
|
446
|
+
const parts = (v) => {
|
|
447
|
+
const m = v.trim().match(/^(\d+)\.(\d+)(?:\.(\d+))?/);
|
|
448
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)] : void 0;
|
|
449
|
+
};
|
|
450
|
+
const a = version ? parts(version) : void 0;
|
|
451
|
+
const b = parts(min);
|
|
452
|
+
if (!a || !b) return false;
|
|
453
|
+
for (let i = 0; i < 3; i++) {
|
|
454
|
+
if (a[i] !== b[i]) return a[i] > b[i];
|
|
455
|
+
}
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
445
458
|
|
|
446
459
|
// src/core/hindsight.ts
|
|
460
|
+
var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
|
|
447
461
|
var KnowledgePagesUnavailableError = class extends Error {
|
|
448
462
|
code = "knowledge_pages_unavailable";
|
|
449
463
|
constructor() {
|
|
@@ -460,6 +474,8 @@ var HindsightClient = class {
|
|
|
460
474
|
// async operation ids collected by retain(), for drain()
|
|
461
475
|
/** Tri-state capability probe: unknown until the first page request, then cached. */
|
|
462
476
|
knowledgePagesSupported;
|
|
477
|
+
/** Tri-state capability probe: unknown until the first append-mode retain, then cached. */
|
|
478
|
+
idempotentRetain;
|
|
463
479
|
log;
|
|
464
480
|
constructor(o) {
|
|
465
481
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
@@ -488,7 +504,8 @@ var HindsightClient = class {
|
|
|
488
504
|
throw new Error(`${method} ${url} -> ${r.status} ${await r.text()}`);
|
|
489
505
|
return r;
|
|
490
506
|
}
|
|
491
|
-
/** Retain one memory.
|
|
507
|
+
/** Retain one memory. ALWAYS async: enqueue extraction server-side and collect its op-id for
|
|
508
|
+
* drain(). Nothing in this plugin can afford to block a coding agent's hook on extraction. */
|
|
492
509
|
async retain(content, context, documentId, tags, strategy, opts = {}) {
|
|
493
510
|
const item = {
|
|
494
511
|
content,
|
|
@@ -499,14 +516,36 @@ var HindsightClient = class {
|
|
|
499
516
|
};
|
|
500
517
|
if (opts.timestamp) item.timestamp = opts.timestamp;
|
|
501
518
|
if (opts.metadata) item.metadata = opts.metadata;
|
|
502
|
-
|
|
503
|
-
const
|
|
504
|
-
if (
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
519
|
+
if (opts.updateMode) item.update_mode = opts.updateMode;
|
|
520
|
+
const body = { items: [item], async: true };
|
|
521
|
+
if (opts.operationId) body.operation_id = opts.operationId;
|
|
522
|
+
const r = await this.req("POST", this.bankUrl("/memories"), body);
|
|
523
|
+
try {
|
|
524
|
+
const j = await r.json();
|
|
525
|
+
if (j.operation_id) this.opIds.push(j.operation_id);
|
|
526
|
+
} catch {
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Whether this server honours `operation_id` on an async retain, and can therefore be appended to
|
|
531
|
+
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via GET /version; anything
|
|
532
|
+
* unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
|
|
533
|
+
*/
|
|
534
|
+
async supportsIdempotentRetain() {
|
|
535
|
+
if (this.idempotentRetain === void 0) {
|
|
536
|
+
this.idempotentRetain = await this.probeIdempotentRetain();
|
|
537
|
+
this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
|
|
538
|
+
}
|
|
539
|
+
return this.idempotentRetain;
|
|
540
|
+
}
|
|
541
|
+
async probeIdempotentRetain() {
|
|
542
|
+
try {
|
|
543
|
+
const r = await this.req("GET", `${this.apiUrl}/version`);
|
|
544
|
+
if (!r.ok) return false;
|
|
545
|
+
const j = await r.json();
|
|
546
|
+
return semverGte(j.api_version, MIN_IDEMPOTENT_RETAIN_VERSION);
|
|
547
|
+
} catch {
|
|
548
|
+
return false;
|
|
510
549
|
}
|
|
511
550
|
}
|
|
512
551
|
/**
|
|
@@ -794,8 +833,7 @@ var HindsightClient = class {
|
|
|
794
833
|
"initiative marker",
|
|
795
834
|
markerId,
|
|
796
835
|
["knowledge:feature-work", `relatedPageId:${pageId}`],
|
|
797
|
-
"document"
|
|
798
|
-
{ async: true }
|
|
836
|
+
"document"
|
|
799
837
|
);
|
|
800
838
|
return { page_id: pageId };
|
|
801
839
|
}
|
|
@@ -1035,15 +1073,79 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1035
1073
|
}
|
|
1036
1074
|
|
|
1037
1075
|
// src/core/retain-hook.ts
|
|
1038
|
-
import { readFileSync as
|
|
1076
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
1077
|
+
|
|
1078
|
+
// src/core/retain-cursor.ts
|
|
1079
|
+
import { createHash } from "crypto";
|
|
1080
|
+
|
|
1081
|
+
// src/core/uuid.ts
|
|
1082
|
+
import { createHash as createHash2 } from "crypto";
|
|
1039
1083
|
|
|
1040
1084
|
// src/core/daemon.ts
|
|
1041
1085
|
import { execFileSync as execFileSync2, spawn as realSpawn2 } from "child_process";
|
|
1042
1086
|
import { dirname as dirname5, join as join6 } from "path";
|
|
1043
1087
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1044
1088
|
|
|
1045
|
-
// src/core/
|
|
1046
|
-
import {
|
|
1089
|
+
// src/core/jsonl.ts
|
|
1090
|
+
import { closeSync, openSync, readSync, statSync } from "fs";
|
|
1091
|
+
import { StringDecoder } from "string_decoder";
|
|
1092
|
+
var CHUNK_BYTES = 64 * 1024;
|
|
1093
|
+
var MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024;
|
|
1094
|
+
function readJsonlTail(path, opts) {
|
|
1095
|
+
const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
|
|
1096
|
+
let size;
|
|
1097
|
+
try {
|
|
1098
|
+
size = statSync(path).size;
|
|
1099
|
+
} catch {
|
|
1100
|
+
return { lines: emptyLines(), skippedBytes: 0 };
|
|
1101
|
+
}
|
|
1102
|
+
const skippedBytes = size > maxBytes ? size - maxBytes : 0;
|
|
1103
|
+
if (skippedBytes > 0) {
|
|
1104
|
+
log.warn(opts.scope, "transcript too large \u2014 retaining the most recent portion only", {
|
|
1105
|
+
path,
|
|
1106
|
+
sizeBytes: size,
|
|
1107
|
+
skippedBytes
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
return { lines: streamLines(path, skippedBytes), skippedBytes };
|
|
1111
|
+
}
|
|
1112
|
+
function* emptyLines() {
|
|
1113
|
+
}
|
|
1114
|
+
function* streamLines(path, start) {
|
|
1115
|
+
let fd;
|
|
1116
|
+
try {
|
|
1117
|
+
fd = openSync(path, "r");
|
|
1118
|
+
} catch {
|
|
1119
|
+
return;
|
|
1120
|
+
}
|
|
1121
|
+
try {
|
|
1122
|
+
const buffer = Buffer.allocUnsafe(CHUNK_BYTES);
|
|
1123
|
+
const decoder = new StringDecoder("utf8");
|
|
1124
|
+
let pending = "";
|
|
1125
|
+
let position = start > 0 ? start - 1 : 0;
|
|
1126
|
+
let dropPartial = start > 0;
|
|
1127
|
+
for (; ; ) {
|
|
1128
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, position);
|
|
1129
|
+
if (bytesRead <= 0) break;
|
|
1130
|
+
position += bytesRead;
|
|
1131
|
+
pending += decoder.write(buffer.subarray(0, bytesRead));
|
|
1132
|
+
let newline;
|
|
1133
|
+
while ((newline = pending.indexOf("\n")) !== -1) {
|
|
1134
|
+
const line = pending.slice(0, newline);
|
|
1135
|
+
pending = pending.slice(newline + 1);
|
|
1136
|
+
if (dropPartial) {
|
|
1137
|
+
dropPartial = false;
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
yield line;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
pending += decoder.end();
|
|
1144
|
+
if (pending && !dropPartial) yield pending;
|
|
1145
|
+
} finally {
|
|
1146
|
+
closeSync(fd);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1047
1149
|
|
|
1048
1150
|
// src/core/transcript-util.ts
|
|
1049
1151
|
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;
|
|
@@ -1081,7 +1183,7 @@ function actionLine(tool, input) {
|
|
|
1081
1183
|
}
|
|
1082
1184
|
|
|
1083
1185
|
// src/core/session-start.ts
|
|
1084
|
-
import { readFileSync as
|
|
1186
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
1085
1187
|
|
|
1086
1188
|
// src/core/git.ts
|
|
1087
1189
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
@@ -1098,13 +1200,12 @@ import { delimiter, dirname as dirname6, join as join7 } from "path";
|
|
|
1098
1200
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1099
1201
|
|
|
1100
1202
|
// src/core/skill-sync.ts
|
|
1101
|
-
import { cpSync, existsSync as existsSync3, readFileSync as
|
|
1203
|
+
import { cpSync, existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
1102
1204
|
import { homedir as homedir4 } from "os";
|
|
1103
1205
|
import { dirname as dirname7, join as join8 } from "path";
|
|
1104
1206
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1105
1207
|
|
|
1106
1208
|
// src/core/transcript-codex.ts
|
|
1107
|
-
import { readFileSync as readFileSync8 } from "fs";
|
|
1108
1209
|
function isSyntheticUserText(text) {
|
|
1109
1210
|
const s = text.trimStart();
|
|
1110
1211
|
return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
|
|
@@ -1113,14 +1214,8 @@ function messageText(payload) {
|
|
|
1113
1214
|
return (payload.content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
1114
1215
|
}
|
|
1115
1216
|
function readCodexTranscript(path) {
|
|
1116
|
-
let raw;
|
|
1117
|
-
try {
|
|
1118
|
-
raw = readFileSync8(path, "utf8");
|
|
1119
|
-
} catch {
|
|
1120
|
-
return [];
|
|
1121
|
-
}
|
|
1122
1217
|
const turns = [];
|
|
1123
|
-
for (const rawLine of
|
|
1218
|
+
for (const rawLine of readJsonlTail(path, { scope: "codex" }).lines) {
|
|
1124
1219
|
const trimmed = rawLine.trim();
|
|
1125
1220
|
if (!trimmed) continue;
|
|
1126
1221
|
let parsed;
|
|
@@ -1154,7 +1249,6 @@ function readCodexTranscript(path) {
|
|
|
1154
1249
|
}
|
|
1155
1250
|
|
|
1156
1251
|
// src/core/transcript-cursor.ts
|
|
1157
|
-
import { readFileSync as readFileSync9 } from "fs";
|
|
1158
1252
|
function withTimestamp(turn, timestamp) {
|
|
1159
1253
|
return timestamp ? { ...turn, timestamp } : turn;
|
|
1160
1254
|
}
|
|
@@ -1164,14 +1258,8 @@ function textFrom(content) {
|
|
|
1164
1258
|
return content.filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n");
|
|
1165
1259
|
}
|
|
1166
1260
|
function readCursorTranscript(path) {
|
|
1167
|
-
let raw;
|
|
1168
|
-
try {
|
|
1169
|
-
raw = readFileSync9(path, "utf8");
|
|
1170
|
-
} catch {
|
|
1171
|
-
return [];
|
|
1172
|
-
}
|
|
1173
1261
|
const turns = [];
|
|
1174
|
-
for (const rawLine of
|
|
1262
|
+
for (const rawLine of readJsonlTail(path, { scope: "cursor-cli" }).lines) {
|
|
1175
1263
|
let parsed;
|
|
1176
1264
|
try {
|
|
1177
1265
|
parsed = JSON.parse(rawLine);
|
|
@@ -1207,17 +1295,10 @@ function readCursorTranscript(path) {
|
|
|
1207
1295
|
}
|
|
1208
1296
|
|
|
1209
1297
|
// src/core/transcript-antigravity.ts
|
|
1210
|
-
import { readFileSync as readFileSync10 } from "fs";
|
|
1211
1298
|
function readAntigravityTranscript(path) {
|
|
1212
1299
|
if (!path) return [];
|
|
1213
|
-
let raw;
|
|
1214
|
-
try {
|
|
1215
|
-
raw = readFileSync10(path, "utf8");
|
|
1216
|
-
} catch {
|
|
1217
|
-
return [];
|
|
1218
|
-
}
|
|
1219
1300
|
const turns = [];
|
|
1220
|
-
for (const line of
|
|
1301
|
+
for (const line of readJsonlTail(path, { scope: "antigravity-cli" }).lines) {
|
|
1221
1302
|
try {
|
|
1222
1303
|
const event = JSON.parse(line);
|
|
1223
1304
|
const role = event.role ?? event.message?.role ?? event.type;
|
|
@@ -1238,16 +1319,9 @@ function readAntigravityTranscript(path) {
|
|
|
1238
1319
|
}
|
|
1239
1320
|
|
|
1240
1321
|
// src/core/transcript-copilot.ts
|
|
1241
|
-
import { readFileSync as readFileSync11 } from "fs";
|
|
1242
1322
|
function readCopilotTranscript(path) {
|
|
1243
|
-
let raw;
|
|
1244
|
-
try {
|
|
1245
|
-
raw = readFileSync11(path, "utf8");
|
|
1246
|
-
} catch {
|
|
1247
|
-
return [];
|
|
1248
|
-
}
|
|
1249
1323
|
const turns = [];
|
|
1250
|
-
for (const rawLine of
|
|
1324
|
+
for (const rawLine of readJsonlTail(path, { scope: "copilot-cli" }).lines) {
|
|
1251
1325
|
try {
|
|
1252
1326
|
const event = JSON.parse(rawLine);
|
|
1253
1327
|
const role = event.type === "user.message" ? "user" : event.type === "assistant.message" ? "assistant" : void 0;
|
|
@@ -1261,7 +1335,7 @@ function readCopilotTranscript(path) {
|
|
|
1261
1335
|
}
|
|
1262
1336
|
|
|
1263
1337
|
// src/core/transcript-grok.ts
|
|
1264
|
-
import { existsSync as existsSync4, readFileSync as
|
|
1338
|
+
import { existsSync as existsSync4, readFileSync as readFileSync7, readdirSync } from "fs";
|
|
1265
1339
|
import { homedir as homedir5 } from "os";
|
|
1266
1340
|
import { join as join9 } from "path";
|
|
1267
1341
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
@@ -1272,7 +1346,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
|
1272
1346
|
try {
|
|
1273
1347
|
for (const candidate of readdirSync(sessionsDir)) {
|
|
1274
1348
|
const directory = join9(sessionsDir, candidate);
|
|
1275
|
-
if (
|
|
1349
|
+
if (readFileSync7(join9(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
1276
1350
|
return join9(directory, sessionId, CHAT_HISTORY);
|
|
1277
1351
|
}
|
|
1278
1352
|
}
|
|
@@ -1281,14 +1355,8 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
|
1281
1355
|
return direct;
|
|
1282
1356
|
}
|
|
1283
1357
|
function readGrokTranscript(path) {
|
|
1284
|
-
let raw;
|
|
1285
|
-
try {
|
|
1286
|
-
raw = readFileSync12(path, "utf8");
|
|
1287
|
-
} catch {
|
|
1288
|
-
return [];
|
|
1289
|
-
}
|
|
1290
1358
|
const turns = [];
|
|
1291
|
-
for (const rawLine of
|
|
1359
|
+
for (const rawLine of readJsonlTail(path, { scope: "grok-build" }).lines) {
|
|
1292
1360
|
try {
|
|
1293
1361
|
const event = JSON.parse(rawLine);
|
|
1294
1362
|
if (event.type !== "user" && event.type !== "assistant") continue;
|