@vectorize-io/hindsight-coding-agents 0.6.1 → 0.7.0
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 +179 -40
- package/dist/antigravity-hook.js +343 -158
- package/dist/antigravity-statusline.js +117 -4
- package/dist/antigravity-stop-hook.js +262 -113
- package/dist/claude-hook.js +343 -158
- package/dist/claude-sessionstart-hook.js +348 -136
- package/dist/claude-stop-hook.js +262 -113
- package/dist/cline.js +493 -173
- package/dist/codex-hook.js +343 -158
- package/dist/codex-sessionstart-hook.js +348 -136
- package/dist/codex-stop-hook.js +262 -113
- package/dist/copilot-hook.js +343 -158
- package/dist/copilot-sessionstart-hook.js +348 -136
- package/dist/copilot-stop-hook.js +262 -113
- package/dist/cursor-hook.js +343 -158
- package/dist/cursor-sessionstart-hook.js +348 -136
- package/dist/cursor-stop-hook.js +262 -113
- package/dist/daemon-start.js +116 -4
- package/dist/dcode-hook.js +343 -158
- package/dist/dcode-sessionstart-hook.js +348 -136
- package/dist/dcode-stop-hook.js +262 -113
- package/dist/deepen.js +204 -47
- package/dist/devin-hook.js +343 -158
- package/dist/devin-sessionstart-hook.js +348 -136
- package/dist/devin-stop-hook.js +262 -113
- package/dist/droid-hook.js +343 -158
- package/dist/droid-sessionstart-hook.js +348 -136
- package/dist/droid-stop-hook.js +262 -113
- package/dist/dsh.js +493 -173
- package/dist/grok-hook.js +343 -158
- package/dist/grok-sessionstart-hook.js +348 -136
- package/dist/grok-stop-hook.js +262 -113
- package/dist/hindsight-seed.js +116 -4
- package/dist/index.js +493 -173
- package/dist/installer.js +92 -70
- package/dist/kilo.js +493 -173
- package/dist/mcp-server.js +230 -57
- package/dist/opencode2.js +520 -173
- package/dist/pi.js +494 -175
- package/dist/prime-agent.js +494 -175
- package/dist/qwen-hook.js +343 -158
- package/dist/qwen-sessionstart-hook.js +348 -136
- package/dist/qwen-stop-hook.js +262 -113
- package/dist/status.js +203 -47
- package/dist/zcode-hook.js +343 -158
- package/dist/zcode-sessionstart-hook.js +348 -136
- package/dist/zcode-stop-hook.js +262 -113
- package/package.json +2 -2
- package/plugin.json +1 -1
- package/skill/SKILL.md +173 -39
package/dist/zcode-stop-hook.js
CHANGED
|
@@ -352,13 +352,15 @@ var CONVERSATION_MISSION = `You are ingesting a developer conversation as a JSON
|
|
|
352
352
|
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.";
|
|
353
353
|
var DOCUMENT_MISSION = "You are ingesting a standalone document (notes, docs, or structural findings). Extract the concrete facts, concepts, and structure it describes.";
|
|
354
354
|
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.";
|
|
355
|
+
var RETAIN_EXTRACTION_MODES = ["concise", "verbose", "verbatim", "chunks"];
|
|
356
|
+
var DEFAULT_RETAIN_EXTRACTION_MODE = "concise";
|
|
355
357
|
var RETAIN_STRATEGIES = {
|
|
356
|
-
git: { retain_mission: GIT_MISSION, retain_extraction_mode:
|
|
358
|
+
git: { retain_mission: GIT_MISSION, retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE },
|
|
357
359
|
// ONE big aggregated document (last N commit messages, no diffs) -> a larger chunk size so it stays
|
|
358
360
|
// in as few chunks as possible and the extractor sees the whole history arc at once.
|
|
359
361
|
gitlog: {
|
|
360
362
|
retain_mission: GITLOG_MISSION,
|
|
361
|
-
retain_extraction_mode:
|
|
363
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
362
364
|
retain_chunk_size: 12e3
|
|
363
365
|
},
|
|
364
366
|
// ONE strategy for ALL developer conversations — backfilled decision chats and live working
|
|
@@ -369,15 +371,15 @@ var RETAIN_STRATEGIES = {
|
|
|
369
371
|
// the consolidation layer.
|
|
370
372
|
conversation: {
|
|
371
373
|
retain_mission: CONVERSATION_MISSION,
|
|
372
|
-
retain_extraction_mode:
|
|
374
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
373
375
|
retain_chunk_size: 12e3
|
|
374
376
|
},
|
|
375
377
|
// Structural documents (e.g. the codebase survey's ingested findings) aren't dialogue — the
|
|
376
|
-
// chat strategy's "final decision vs rejected proposal" extraction doesn't apply.
|
|
377
|
-
//
|
|
378
|
+
// chat strategy's "final decision vs rejected proposal" extraction doesn't apply. A bigger chunk
|
|
379
|
+
// size (documents can run long) keeps the concrete facts/structure together instead.
|
|
378
380
|
document: {
|
|
379
381
|
retain_mission: DOCUMENT_MISSION,
|
|
380
|
-
retain_extraction_mode:
|
|
382
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
381
383
|
retain_chunk_size: 12e3
|
|
382
384
|
},
|
|
383
385
|
// Codebase-SURVEY lifecycle documents, ONE strategy with conditional rules: the survey's
|
|
@@ -450,9 +452,22 @@ var PAGE_TAXONOMY = [
|
|
|
450
452
|
tags: ["knowledge:feature-work"]
|
|
451
453
|
}
|
|
452
454
|
];
|
|
453
|
-
|
|
455
|
+
var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
|
|
456
|
+
function pagesFor(project, pages = {}, customPages = {}) {
|
|
454
457
|
const scope = pageScopeRule(project);
|
|
455
|
-
|
|
458
|
+
const byName = new Map(
|
|
459
|
+
Object.entries(pages).map(([name, override]) => [name.trim().toLowerCase(), override])
|
|
460
|
+
);
|
|
461
|
+
const out = [];
|
|
462
|
+
for (const page of PAGE_TAXONOMY) {
|
|
463
|
+
const override = byName.get(page.name.toLowerCase());
|
|
464
|
+
if (override === false) continue;
|
|
465
|
+
out.push({ ...page, source_query: (override?.source_query || page.source_query) + scope });
|
|
466
|
+
}
|
|
467
|
+
for (const [name, page] of Object.entries(customPages)) {
|
|
468
|
+
out.push({ name: name.trim(), source_query: page.source_query + scope, tags: page.tags ?? [] });
|
|
469
|
+
}
|
|
470
|
+
return out;
|
|
456
471
|
}
|
|
457
472
|
var PAGE_MAX_TOKENS = 4096;
|
|
458
473
|
var PAGE_TAGS_MATCH = "all";
|
|
@@ -535,7 +550,7 @@ var CODING_BANK_TEMPLATE = {
|
|
|
535
550
|
enable_observations: true,
|
|
536
551
|
observations_mission: OBSERVATIONS_MISSION,
|
|
537
552
|
retain_mission: GIT_MISSION,
|
|
538
|
-
retain_extraction_mode:
|
|
553
|
+
retain_extraction_mode: DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
539
554
|
retain_default_strategy: "git",
|
|
540
555
|
retain_strategies: RETAIN_STRATEGIES,
|
|
541
556
|
entity_labels: [KNOWLEDGE_LABELS],
|
|
@@ -548,7 +563,7 @@ function isSet(v) {
|
|
|
548
563
|
if (typeof v === "string") return v.trim() !== "";
|
|
549
564
|
return true;
|
|
550
565
|
}
|
|
551
|
-
function codingBankManifest(overrides) {
|
|
566
|
+
function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE) {
|
|
552
567
|
const current2 = overrides ?? {};
|
|
553
568
|
const template = CODING_BANK_TEMPLATE.bank;
|
|
554
569
|
const bank = {};
|
|
@@ -557,16 +572,22 @@ function codingBankManifest(overrides) {
|
|
|
557
572
|
bank.enable_observations = template.enable_observations;
|
|
558
573
|
bank.observations_mission = template.observations_mission;
|
|
559
574
|
bank.retain_mission = template.retain_mission;
|
|
560
|
-
bank.retain_extraction_mode =
|
|
575
|
+
bank.retain_extraction_mode = mode;
|
|
561
576
|
}
|
|
562
577
|
if (!isSet(current2.retain_default_strategy))
|
|
563
578
|
bank.retain_default_strategy = template.retain_default_strategy;
|
|
564
579
|
if (!isSet(current2.entities_allow_free_form))
|
|
565
580
|
bank.entities_allow_free_form = template.entities_allow_free_form;
|
|
566
581
|
const strategies = current2.retain_strategies && typeof current2.retain_strategies === "object" ? current2.retain_strategies : {};
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
582
|
+
const updates = {};
|
|
583
|
+
for (const [name, def] of Object.entries(template.retain_strategies)) {
|
|
584
|
+
const synced = def.retain_extraction_mode === "custom" ? {} : { retain_extraction_mode: mode };
|
|
585
|
+
const have = strategies[name];
|
|
586
|
+
if (!have || typeof have !== "object") updates[name] = { ...def, ...synced };
|
|
587
|
+
else if ("retain_extraction_mode" in synced && have.retain_extraction_mode !== mode)
|
|
588
|
+
updates[name] = { ...have, ...synced };
|
|
589
|
+
}
|
|
590
|
+
if (Object.keys(updates).length > 0) bank.retain_strategies = { ...strategies, ...updates };
|
|
570
591
|
const labels = Array.isArray(current2.entity_labels) ? current2.entity_labels : [];
|
|
571
592
|
const [knowledgeGroup] = template.entity_labels;
|
|
572
593
|
if (!labels.some((g) => g?.key === knowledgeGroup.key))
|
|
@@ -638,6 +659,14 @@ var KnowledgePagesUnavailableError = class extends Error {
|
|
|
638
659
|
this.name = "KnowledgePagesUnavailableError";
|
|
639
660
|
}
|
|
640
661
|
};
|
|
662
|
+
async function isEndpointMissing(r) {
|
|
663
|
+
try {
|
|
664
|
+
const j = await r.json();
|
|
665
|
+
return String(j?.detail ?? "").trim().toLowerCase() === "not found";
|
|
666
|
+
} catch {
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
641
670
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
642
671
|
var ReflectError = class extends Error {
|
|
643
672
|
constructor(message, status, timedOut, options) {
|
|
@@ -656,6 +685,13 @@ var ReflectError = class extends Error {
|
|
|
656
685
|
}
|
|
657
686
|
};
|
|
658
687
|
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
688
|
+
var DEFAULT_PAGE_SEARCH_LIMIT = 10;
|
|
689
|
+
var DEFAULT_RECALL_OPTIONS = {
|
|
690
|
+
types: ["observation"],
|
|
691
|
+
budget: "low",
|
|
692
|
+
max_tokens: 2e3,
|
|
693
|
+
include: { entities: null }
|
|
694
|
+
};
|
|
659
695
|
var POLL_CYCLE_MS = 5e3;
|
|
660
696
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
661
697
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
@@ -676,6 +712,8 @@ var HindsightClient = class {
|
|
|
676
712
|
log;
|
|
677
713
|
maxParallelRetains;
|
|
678
714
|
observationScopes;
|
|
715
|
+
pageSearchLimit;
|
|
716
|
+
recallOptions;
|
|
679
717
|
constructor(o) {
|
|
680
718
|
this.apiUrl = o.apiUrl.replace(/\/$/, "");
|
|
681
719
|
this.token = o.apiToken;
|
|
@@ -686,6 +724,8 @@ var HindsightClient = class {
|
|
|
686
724
|
});
|
|
687
725
|
this.maxParallelRetains = o.maxParallelRetains || DEFAULT_MAX_PARALLEL_RETAINS;
|
|
688
726
|
this.observationScopes = o.observationScopes ?? DEFAULT_OBSERVATION_SCOPES;
|
|
727
|
+
this.pageSearchLimit = o.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT;
|
|
728
|
+
this.recallOptions = { ...DEFAULT_RECALL_OPTIONS, ...o.recallOptions };
|
|
689
729
|
}
|
|
690
730
|
/** The credential in use, for diagnostics. Never log or report the VALUE — booleans only. */
|
|
691
731
|
get apiToken() {
|
|
@@ -827,7 +867,8 @@ var HindsightClient = class {
|
|
|
827
867
|
}
|
|
828
868
|
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
829
869
|
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
830
|
-
* idempotent and
|
|
870
|
+
* idempotent and ADDITIVE — nothing the bank already says is overwritten (#3927), bar the
|
|
871
|
+
* extraction mode of the plugin's own strategies, which follows its config (#4560) — so
|
|
831
872
|
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
832
873
|
* continue with the template-only path.
|
|
833
874
|
*
|
|
@@ -843,7 +884,10 @@ var HindsightClient = class {
|
|
|
843
884
|
if (opts.manage === false) {
|
|
844
885
|
this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
|
|
845
886
|
} else {
|
|
846
|
-
const manifest = codingBankManifest(
|
|
887
|
+
const manifest = codingBankManifest(
|
|
888
|
+
opts.reset ? void 0 : await this.readBankOverrides(),
|
|
889
|
+
opts.extractionMode
|
|
890
|
+
);
|
|
847
891
|
if (!manifest) {
|
|
848
892
|
this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
|
|
849
893
|
} else {
|
|
@@ -851,7 +895,7 @@ var HindsightClient = class {
|
|
|
851
895
|
this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
|
|
852
896
|
}
|
|
853
897
|
}
|
|
854
|
-
await this.seedPages(opts.pageTrigger);
|
|
898
|
+
await this.seedPages(opts.pageTrigger, opts.pages, opts.customPages);
|
|
855
899
|
}
|
|
856
900
|
/**
|
|
857
901
|
* This bank's own config OVERRIDES, or undefined when there are none to read.
|
|
@@ -967,20 +1011,22 @@ var HindsightClient = class {
|
|
|
967
1011
|
}
|
|
968
1012
|
}
|
|
969
1013
|
/**
|
|
970
|
-
* Raw recall
|
|
971
|
-
*
|
|
1014
|
+
* Raw recall with no LLM in the loop, so it still answers when reflect's synthesis times out or
|
|
1015
|
+
* 5xxs. The body is `recallOptions` (consolidated observations by default) — a bank that grows
|
|
1016
|
+
* no observations widens it rather than getting nothing back. Returns the texts in rank order.
|
|
1017
|
+
*
|
|
1018
|
+
* The name predates `recallOptions` (the observation type used to be hardcoded here) and is
|
|
1019
|
+
* kept deliberately: this is the client's published surface, so renaming it would break
|
|
1020
|
+
* importers for a cosmetic gain. The doc above is the contract, not the name.
|
|
972
1021
|
*/
|
|
973
1022
|
async recallObservations(query, opts) {
|
|
974
1023
|
const r = await this.req(
|
|
975
1024
|
"POST",
|
|
976
1025
|
this.bankUrl("/memories/recall"),
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
max_tokens: opts.maxTokens,
|
|
982
|
-
include: { entities: null }
|
|
983
|
-
},
|
|
1026
|
+
// `query` is applied AFTER the spread: everything else is the caller's to override, but a
|
|
1027
|
+
// config that could replace the goal with a fixed string would silently recall for the
|
|
1028
|
+
// wrong question on every turn.
|
|
1029
|
+
{ ...this.recallOptions, query },
|
|
984
1030
|
[],
|
|
985
1031
|
opts.timeoutMs
|
|
986
1032
|
);
|
|
@@ -988,6 +1034,19 @@ var HindsightClient = class {
|
|
|
988
1034
|
const j = await r.json();
|
|
989
1035
|
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
990
1036
|
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Latch `knowledgePagesSupported = false` iff this response really means the endpoint is absent.
|
|
1039
|
+
* Returns whether it latched. A bank-not-found 404 is NOT a capability verdict — it is the
|
|
1040
|
+
* expected answer before the bank's first retain — so it must never cache a negative (#4607).
|
|
1041
|
+
*
|
|
1042
|
+
* Only 404 is tested: `req` throws on every other non-ok status it was not told to tolerate, so
|
|
1043
|
+
* the 405/501 this used to check for never reach a caller in the first place.
|
|
1044
|
+
*/
|
|
1045
|
+
async pagesUnsupported(r) {
|
|
1046
|
+
if (r.status !== 404 || !await isEndpointMissing(r)) return false;
|
|
1047
|
+
this.knowledgePagesSupported = false;
|
|
1048
|
+
return true;
|
|
1049
|
+
}
|
|
991
1050
|
/**
|
|
992
1051
|
* The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
|
|
993
1052
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
@@ -995,10 +1054,8 @@ var HindsightClient = class {
|
|
|
995
1054
|
async tree() {
|
|
996
1055
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
997
1056
|
const r = await this.req("GET", this.bankUrl("/knowledge-base/tree"));
|
|
998
|
-
if (
|
|
999
|
-
|
|
1000
|
-
throw new KnowledgePagesUnavailableError();
|
|
1001
|
-
}
|
|
1057
|
+
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1058
|
+
if (r.status === 404) return [];
|
|
1002
1059
|
this.knowledgePagesSupported = true;
|
|
1003
1060
|
try {
|
|
1004
1061
|
return (await r.json()).roots ?? [];
|
|
@@ -1052,16 +1109,18 @@ var HindsightClient = class {
|
|
|
1052
1109
|
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
|
|
1053
1110
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1054
1111
|
* hindsight_search_knowledge_pages. */
|
|
1055
|
-
async searchKnowledgePages(query,
|
|
1112
|
+
async searchKnowledgePages(query, opts = {}) {
|
|
1056
1113
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
1057
|
-
const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
1114
|
+
const q = `?q=${encodeURIComponent(query)}&limit=${opts.limit ?? this.pageSearchLimit}`;
|
|
1058
1115
|
const r = await this.req(
|
|
1059
1116
|
"GET",
|
|
1060
1117
|
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1061
1118
|
void 0,
|
|
1062
1119
|
[],
|
|
1063
|
-
timeoutMs
|
|
1120
|
+
opts.timeoutMs
|
|
1064
1121
|
);
|
|
1122
|
+
if (await this.pagesUnsupported(r)) throw new KnowledgePagesUnavailableError();
|
|
1123
|
+
if (r.status === 404) return [];
|
|
1065
1124
|
const j = await r.json();
|
|
1066
1125
|
return (j.results ?? []).map((x) => ({
|
|
1067
1126
|
id: x.id,
|
|
@@ -1081,8 +1140,8 @@ var HindsightClient = class {
|
|
|
1081
1140
|
* `source_query` re-syncs onto the live page instead of orphaning its synthesized content —
|
|
1082
1141
|
* which is how `pageScopeRule`'s repo name reaches banks seeded by an earlier version.
|
|
1083
1142
|
*/
|
|
1084
|
-
async seedPages(pageTrigger = buildPageTrigger()) {
|
|
1085
|
-
const pages = pagesFor(this.project ?? this.bank);
|
|
1143
|
+
async seedPages(pageTrigger = buildPageTrigger(), pagesConfig = {}, customPages = {}) {
|
|
1144
|
+
const pages = pagesFor(this.project ?? this.bank, pagesConfig, customPages);
|
|
1086
1145
|
const existing = /* @__PURE__ */ new Map();
|
|
1087
1146
|
let roots;
|
|
1088
1147
|
try {
|
|
@@ -1099,6 +1158,7 @@ var HindsightClient = class {
|
|
|
1099
1158
|
}
|
|
1100
1159
|
let created = 0;
|
|
1101
1160
|
let updated = 0;
|
|
1161
|
+
let vanished = 0;
|
|
1102
1162
|
for (const page of pages) {
|
|
1103
1163
|
const hit = existing.get(page.name.toLowerCase());
|
|
1104
1164
|
const body = {
|
|
@@ -1112,13 +1172,16 @@ var HindsightClient = class {
|
|
|
1112
1172
|
};
|
|
1113
1173
|
if (!hit) {
|
|
1114
1174
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
1115
|
-
if (
|
|
1116
|
-
this.knowledgePagesSupported = false;
|
|
1175
|
+
if (await this.pagesUnsupported(r)) {
|
|
1117
1176
|
this.log(
|
|
1118
1177
|
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1119
1178
|
);
|
|
1120
1179
|
return;
|
|
1121
1180
|
}
|
|
1181
|
+
if (r.status === 404) {
|
|
1182
|
+
this.log(`[bank] ${this.bank} does not exist yet; pages seed on the next session`);
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1122
1185
|
if (r.status !== 409) created++;
|
|
1123
1186
|
} else {
|
|
1124
1187
|
const sourceDrift = hit.description !== page.source_query;
|
|
@@ -1128,6 +1191,9 @@ var HindsightClient = class {
|
|
|
1128
1191
|
if (sourceDrift) {
|
|
1129
1192
|
patch.source_query = page.source_query;
|
|
1130
1193
|
patch.tags = page.tags;
|
|
1194
|
+
this.log(
|
|
1195
|
+
`[bank] re-syncing "${page.name}" to its configured source_query \u2014 set pages[${JSON.stringify(page.name)}].source_query to keep your own wording`
|
|
1196
|
+
);
|
|
1131
1197
|
}
|
|
1132
1198
|
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
1133
1199
|
const r = await this.req(
|
|
@@ -1135,19 +1201,22 @@ var HindsightClient = class {
|
|
|
1135
1201
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
1136
1202
|
patch
|
|
1137
1203
|
);
|
|
1138
|
-
if (
|
|
1139
|
-
this.knowledgePagesSupported = false;
|
|
1204
|
+
if (await this.pagesUnsupported(r)) {
|
|
1140
1205
|
this.log(
|
|
1141
1206
|
`[bank] knowledge pages unavailable on ${this.apiUrl}; continuing without pages`
|
|
1142
1207
|
);
|
|
1143
1208
|
return;
|
|
1144
1209
|
}
|
|
1210
|
+
if (r.status === 404) {
|
|
1211
|
+
vanished++;
|
|
1212
|
+
continue;
|
|
1213
|
+
}
|
|
1145
1214
|
updated++;
|
|
1146
1215
|
}
|
|
1147
1216
|
}
|
|
1148
1217
|
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
1149
1218
|
this.log(
|
|
1150
|
-
`[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` : "")
|
|
1219
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated - vanished} unchanged` + (vanished ? `, ${vanished} deleted under us` : "") + (initiatives ? `, ${initiatives} initiative pages re-synced` : "")
|
|
1151
1220
|
);
|
|
1152
1221
|
}
|
|
1153
1222
|
/**
|
|
@@ -1176,7 +1245,7 @@ var HindsightClient = class {
|
|
|
1176
1245
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
1177
1246
|
{ trigger: pageTriggerPatch(desired) }
|
|
1178
1247
|
);
|
|
1179
|
-
if (
|
|
1248
|
+
if (r.status === 404) continue;
|
|
1180
1249
|
updated++;
|
|
1181
1250
|
}
|
|
1182
1251
|
return updated;
|
|
@@ -1268,6 +1337,63 @@ function resolvePageTrigger(raw) {
|
|
|
1268
1337
|
);
|
|
1269
1338
|
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
1270
1339
|
}
|
|
1340
|
+
function resolvePages(raw) {
|
|
1341
|
+
const value = raw;
|
|
1342
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1343
|
+
const out = {};
|
|
1344
|
+
for (const [name, entry] of Object.entries(value)) {
|
|
1345
|
+
if (!PAGE_NAMES.some((known) => known.toLowerCase() === name.trim().toLowerCase())) {
|
|
1346
|
+
log.warn(
|
|
1347
|
+
"config",
|
|
1348
|
+
`ignoring pages[${JSON.stringify(name)}] \u2014 no seeded page has that name; expected one of: ${PAGE_NAMES.join(", ")}`
|
|
1349
|
+
);
|
|
1350
|
+
continue;
|
|
1351
|
+
}
|
|
1352
|
+
if (entry === false) {
|
|
1353
|
+
out[name] = false;
|
|
1354
|
+
continue;
|
|
1355
|
+
}
|
|
1356
|
+
const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
|
|
1357
|
+
if (typeof query === "string" && query.trim()) {
|
|
1358
|
+
out[name] = { source_query: query };
|
|
1359
|
+
continue;
|
|
1360
|
+
}
|
|
1361
|
+
log.warn(
|
|
1362
|
+
"config",
|
|
1363
|
+
`ignoring pages[${JSON.stringify(name)}]=${JSON.stringify(entry)} \u2014 expected false, or {"source_query": "<your question>"}`
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
return out;
|
|
1367
|
+
}
|
|
1368
|
+
function resolveCustomPages(raw) {
|
|
1369
|
+
const value = raw;
|
|
1370
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1371
|
+
const out = {};
|
|
1372
|
+
for (const [rawName, entry] of Object.entries(value)) {
|
|
1373
|
+
const name = rawName.trim();
|
|
1374
|
+
if (!name) continue;
|
|
1375
|
+
if (PAGE_NAMES.some((known) => known.toLowerCase() === name.toLowerCase())) {
|
|
1376
|
+
log.warn(
|
|
1377
|
+
"config",
|
|
1378
|
+
`ignoring customPages[${JSON.stringify(rawName)}] \u2014 that is a seeded page; reword it under \`pages\` instead`
|
|
1379
|
+
);
|
|
1380
|
+
continue;
|
|
1381
|
+
}
|
|
1382
|
+
const query = entry && typeof entry === "object" && !Array.isArray(entry) ? entry.source_query : void 0;
|
|
1383
|
+
if (typeof query !== "string" || !query.trim()) {
|
|
1384
|
+
log.warn(
|
|
1385
|
+
"config",
|
|
1386
|
+
`ignoring customPages[${JSON.stringify(rawName)}]=${JSON.stringify(entry)} \u2014 expected {"source_query": "<your question>"}`
|
|
1387
|
+
);
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1390
|
+
const rawTags = entry.tags;
|
|
1391
|
+
const tags = Array.isArray(rawTags) ? rawTags.filter((t) => typeof t === "string" && t.trim() !== "") : [];
|
|
1392
|
+
out[name] = tags.length ? { source_query: query, tags } : { source_query: query };
|
|
1393
|
+
}
|
|
1394
|
+
return out;
|
|
1395
|
+
}
|
|
1396
|
+
var DEFAULT_REFLECT_TIMEOUT_MS = 2e4;
|
|
1271
1397
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
1272
1398
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
1273
1399
|
function resolveReflectBudget(raw) {
|
|
@@ -1295,6 +1421,15 @@ function resolveObservationScopes(raw) {
|
|
|
1295
1421
|
}
|
|
1296
1422
|
return DEFAULT_OBSERVATION_SCOPES;
|
|
1297
1423
|
}
|
|
1424
|
+
var AUTO_INJECT_MODES = ["reflect", "pages", "recall", "none"];
|
|
1425
|
+
function resolveAutoInject(raw) {
|
|
1426
|
+
if (raw.autoReflect !== void 0) {
|
|
1427
|
+
const replacement = raw.autoReflect === false ? "none" : "reflect";
|
|
1428
|
+
log.warn("config", `autoReflect is deprecated \u2014 use autoInject: "${replacement}" instead`);
|
|
1429
|
+
}
|
|
1430
|
+
if (AUTO_INJECT_MODES.includes(raw.autoInject)) return raw.autoInject;
|
|
1431
|
+
return raw.autoReflect === false ? "none" : "reflect";
|
|
1432
|
+
}
|
|
1298
1433
|
function resolveConfig(raw = {}) {
|
|
1299
1434
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
1300
1435
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
@@ -1324,17 +1459,28 @@ function resolveConfig(raw = {}) {
|
|
|
1324
1459
|
retainSessions: raw.retainSessions ?? true,
|
|
1325
1460
|
// write sessions back by default, every harness
|
|
1326
1461
|
manageBankConfig: raw.manageBankConfig ?? true,
|
|
1462
|
+
retainExtractionMode: RETAIN_EXTRACTION_MODES.includes(raw.retainExtractionMode) ? raw.retainExtractionMode : DEFAULT_RETAIN_EXTRACTION_MODE,
|
|
1327
1463
|
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
1328
|
-
reflectTimeoutMs: raw.reflectTimeoutMs ||
|
|
1464
|
+
reflectTimeoutMs: raw.reflectTimeoutMs || DEFAULT_REFLECT_TIMEOUT_MS,
|
|
1329
1465
|
// Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
|
|
1330
1466
|
// reflect already set), but never let it LOWER the tool below the default — a short window is
|
|
1331
1467
|
// set to bound the automatic hook, not to cut off a call the agent is waiting on.
|
|
1332
1468
|
reflectToolTimeoutMs: raw.reflectToolTimeoutMs || Math.max(raw.reflectTimeoutMs || 0, DEFAULT_REFLECT_TOOL_TIMEOUT_MS),
|
|
1333
1469
|
reflectBudget: resolveReflectBudget(raw),
|
|
1334
|
-
|
|
1335
|
-
|
|
1470
|
+
autoInject: resolveAutoInject(raw),
|
|
1471
|
+
pageSearchLimit: raw.pageSearchLimit || DEFAULT_PAGE_SEARCH_LIMIT,
|
|
1472
|
+
// Same shape as retainMetadata: an object, or nothing. An array would spread into numeric
|
|
1473
|
+
// keys and reach the API as garbage, so it is rejected like any other non-object.
|
|
1474
|
+
recallOptions: raw.recallOptions && typeof raw.recallOptions === "object" && !Array.isArray(raw.recallOptions) ? { ...raw.recallOptions } : {},
|
|
1475
|
+
// Every turn, not every tenth. The guide is what tells the agent WHEN to reach for memory, and
|
|
1476
|
+
// at a cadence of 10 a normal session is told once, on turn 1, and never again. Measured over
|
|
1477
|
+
// 40 real Claude Code turns, moving this from 10 to 1 took searches from 15% of turns to 32.5%
|
|
1478
|
+
// with no wording change at all. The cost is the guide's ~2KB re-sent per turn, which caches.
|
|
1479
|
+
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 1,
|
|
1336
1480
|
pageTriggerType: pageTrigger.type,
|
|
1337
1481
|
pageTriggerCron: pageTrigger.cron,
|
|
1482
|
+
pages: resolvePages(raw.pages),
|
|
1483
|
+
customPages: resolveCustomPages(raw.customPages),
|
|
1338
1484
|
autoSeed: raw.autoSeed ?? true,
|
|
1339
1485
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
1340
1486
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -1398,6 +1544,8 @@ var ENV_KEYS = {
|
|
|
1398
1544
|
reflectTimeoutMs: "HINDSIGHT_REFLECT_TIMEOUT_MS",
|
|
1399
1545
|
reflectToolTimeoutMs: "HINDSIGHT_REFLECT_TOOL_TIMEOUT_MS",
|
|
1400
1546
|
reflectBudget: "HINDSIGHT_REFLECT_BUDGET",
|
|
1547
|
+
autoInject: "HINDSIGHT_AUTO_INJECT",
|
|
1548
|
+
pageSearchLimit: "HINDSIGHT_PAGE_SEARCH_LIMIT",
|
|
1401
1549
|
autoReflect: "HINDSIGHT_AUTO_REFLECT",
|
|
1402
1550
|
pageRefreshEveryTurns: "HINDSIGHT_PAGE_REFRESH_EVERY_TURNS",
|
|
1403
1551
|
pageTriggerType: "HINDSIGHT_PAGE_TRIGGER_TYPE",
|
|
@@ -1417,7 +1565,8 @@ var ENV_KEYS = {
|
|
|
1417
1565
|
// Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
|
|
1418
1566
|
// a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
|
|
1419
1567
|
retainTags: "HINDSIGHT_RETAIN_TAGS",
|
|
1420
|
-
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
|
|
1568
|
+
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG",
|
|
1569
|
+
retainExtractionMode: "HINDSIGHT_RETAIN_EXTRACTION_MODE"
|
|
1421
1570
|
};
|
|
1422
1571
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
1423
1572
|
"dynamicBankId",
|
|
@@ -1438,6 +1587,7 @@ var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
|
1438
1587
|
"maxParallelRetains",
|
|
1439
1588
|
"reflectTimeoutMs",
|
|
1440
1589
|
"reflectToolTimeoutMs",
|
|
1590
|
+
"pageSearchLimit",
|
|
1441
1591
|
"pageRefreshEveryTurns",
|
|
1442
1592
|
"seedLimit",
|
|
1443
1593
|
"surveyBudgetUsd",
|
|
@@ -1501,6 +1651,7 @@ function resolvePartial(cfg, patch) {
|
|
|
1501
1651
|
if (key in full)
|
|
1502
1652
|
out[key] = full[key];
|
|
1503
1653
|
}
|
|
1654
|
+
if ("autoReflect" in patch && !("autoInject" in patch)) out.autoInject = full.autoInject;
|
|
1504
1655
|
return out;
|
|
1505
1656
|
}
|
|
1506
1657
|
|
|
@@ -1790,8 +1941,8 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness, opt
|
|
|
1790
1941
|
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
1791
1942
|
if (!turns.length) return;
|
|
1792
1943
|
const refId = `conversation:${sessionId}`;
|
|
1793
|
-
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
1794
1944
|
const cursor = cursors?.read(sessionId);
|
|
1945
|
+
const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
|
|
1795
1946
|
const plan = planRetain(turns, cursor, { appendSupported, bank: client.bank });
|
|
1796
1947
|
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
1797
1948
|
if (plan.mode === "skip" && !outbox.length) return;
|
|
@@ -1830,7 +1981,8 @@ ${content}`);
|
|
|
1830
1981
|
const next = {
|
|
1831
1982
|
turns: turns.length,
|
|
1832
1983
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
1833
|
-
bank: client.bank
|
|
1984
|
+
bank: client.bank,
|
|
1985
|
+
...appendSupported ? { appendSupported: true } : {}
|
|
1834
1986
|
};
|
|
1835
1987
|
const stillOurs = () => {
|
|
1836
1988
|
if (!cursors) return true;
|
|
@@ -2044,31 +2196,10 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
2044
2196
|
}
|
|
2045
2197
|
|
|
2046
2198
|
// src/core/jsonl.ts
|
|
2047
|
-
import { closeSync, openSync, readSync
|
|
2199
|
+
import { closeSync, openSync, readSync } from "fs";
|
|
2048
2200
|
import { StringDecoder } from "string_decoder";
|
|
2049
2201
|
var CHUNK_BYTES = 64 * 1024;
|
|
2050
|
-
|
|
2051
|
-
function readJsonlTail(path, opts) {
|
|
2052
|
-
const maxBytes = opts.maxBytes ?? MAX_TRANSCRIPT_BYTES;
|
|
2053
|
-
let size;
|
|
2054
|
-
try {
|
|
2055
|
-
size = statSync3(path).size;
|
|
2056
|
-
} catch {
|
|
2057
|
-
return { lines: emptyLines(), skippedBytes: 0 };
|
|
2058
|
-
}
|
|
2059
|
-
const skippedBytes = size > maxBytes ? size - maxBytes : 0;
|
|
2060
|
-
if (skippedBytes > 0) {
|
|
2061
|
-
log.warn(opts.scope, "transcript too large \u2014 retaining the most recent portion only", {
|
|
2062
|
-
path,
|
|
2063
|
-
sizeBytes: size,
|
|
2064
|
-
skippedBytes
|
|
2065
|
-
});
|
|
2066
|
-
}
|
|
2067
|
-
return { lines: streamLines(path, skippedBytes), skippedBytes };
|
|
2068
|
-
}
|
|
2069
|
-
function* emptyLines() {
|
|
2070
|
-
}
|
|
2071
|
-
function* streamLines(path, start) {
|
|
2202
|
+
function* readJsonl(path) {
|
|
2072
2203
|
let fd;
|
|
2073
2204
|
try {
|
|
2074
2205
|
fd = openSync(path, "r");
|
|
@@ -2079,8 +2210,7 @@ function* streamLines(path, start) {
|
|
|
2079
2210
|
const buffer = Buffer.allocUnsafe(CHUNK_BYTES);
|
|
2080
2211
|
const decoder = new StringDecoder("utf8");
|
|
2081
2212
|
let pending = "";
|
|
2082
|
-
let position =
|
|
2083
|
-
let dropPartial = start > 0;
|
|
2213
|
+
let position = 0;
|
|
2084
2214
|
for (; ; ) {
|
|
2085
2215
|
const bytesRead = readSync(fd, buffer, 0, buffer.length, position);
|
|
2086
2216
|
if (bytesRead <= 0) break;
|
|
@@ -2088,17 +2218,12 @@ function* streamLines(path, start) {
|
|
|
2088
2218
|
pending += decoder.write(buffer.subarray(0, bytesRead));
|
|
2089
2219
|
let newline;
|
|
2090
2220
|
while ((newline = pending.indexOf("\n")) !== -1) {
|
|
2091
|
-
|
|
2221
|
+
yield pending.slice(0, newline);
|
|
2092
2222
|
pending = pending.slice(newline + 1);
|
|
2093
|
-
if (dropPartial) {
|
|
2094
|
-
dropPartial = false;
|
|
2095
|
-
continue;
|
|
2096
|
-
}
|
|
2097
|
-
yield line;
|
|
2098
2223
|
}
|
|
2099
2224
|
}
|
|
2100
2225
|
pending += decoder.end();
|
|
2101
|
-
if (pending
|
|
2226
|
+
if (pending) yield pending;
|
|
2102
2227
|
} finally {
|
|
2103
2228
|
closeSync(fd);
|
|
2104
2229
|
}
|
|
@@ -2130,7 +2255,7 @@ function renderLine(content, type) {
|
|
|
2130
2255
|
}
|
|
2131
2256
|
function readClaudeTranscript(path) {
|
|
2132
2257
|
const turns = [];
|
|
2133
|
-
for (const rawLine of
|
|
2258
|
+
for (const rawLine of readJsonl(path)) {
|
|
2134
2259
|
const trimmed = rawLine.trim();
|
|
2135
2260
|
if (!trimmed) continue;
|
|
2136
2261
|
let parsed;
|
|
@@ -2185,7 +2310,8 @@ function summarizeTurns(turns) {
|
|
|
2185
2310
|
function recordUsage(args) {
|
|
2186
2311
|
const summary = summarizeTurns(args.turns);
|
|
2187
2312
|
const finished = args.lastTurnComplete ? summary : summary.slice(0, -1);
|
|
2188
|
-
const
|
|
2313
|
+
const recorded = args.cursors.read(args.sessionId) ?? 0;
|
|
2314
|
+
const from = args.reviseLastTurn ? Math.max(0, recorded - 1) : recorded;
|
|
2189
2315
|
if (finished.length <= from) return;
|
|
2190
2316
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
2191
2317
|
const lines = finished.slice(from).map(
|
|
@@ -2228,7 +2354,11 @@ async function buildRetain(args) {
|
|
|
2228
2354
|
bankId: args.bankId ?? "",
|
|
2229
2355
|
turns,
|
|
2230
2356
|
cursors: args.usageCursors ?? fileUsageCursorStore(harness),
|
|
2231
|
-
lastTurnComplete: true
|
|
2357
|
+
lastTurnComplete: true,
|
|
2358
|
+
// The host has usually not flushed this turn's final reply yet — and that is
|
|
2359
|
+
// the message carrying the credit line. Re-emit the previous turn so the next
|
|
2360
|
+
// Stop, reading a complete transcript, corrects it. See recordUsage.
|
|
2361
|
+
reviseLastTurn: true
|
|
2232
2362
|
});
|
|
2233
2363
|
const startTs = turns[0]?.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
2234
2364
|
const t0 = Date.now();
|
|
@@ -2344,7 +2474,7 @@ import {
|
|
|
2344
2474
|
renameSync as renameSync3,
|
|
2345
2475
|
rmdirSync,
|
|
2346
2476
|
rmSync as rmSync2,
|
|
2347
|
-
statSync as
|
|
2477
|
+
statSync as statSync3,
|
|
2348
2478
|
unlinkSync,
|
|
2349
2479
|
utimesSync,
|
|
2350
2480
|
writeFileSync as writeFileSync2
|
|
@@ -2365,6 +2495,8 @@ import { homedir as homedir5, tmpdir as tmpdir4 } from "os";
|
|
|
2365
2495
|
import { dirname as dirname9, join as join14 } from "path";
|
|
2366
2496
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2367
2497
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2498
|
+
var NPM_VIEW_TIMEOUT_MS = 5e3;
|
|
2499
|
+
var NPM_VIEW_HARD_DEADLINE_MS = NPM_VIEW_TIMEOUT_MS + 1e3;
|
|
2368
2500
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2369
2501
|
|
|
2370
2502
|
// src/core/skill-sync.ts
|
|
@@ -2379,43 +2511,60 @@ import { homedir as homedir7 } from "os";
|
|
|
2379
2511
|
import { join as join16, relative, isAbsolute as isAbsolute2 } from "path";
|
|
2380
2512
|
|
|
2381
2513
|
// src/core/transcript-codex.ts
|
|
2514
|
+
function stampOf(line) {
|
|
2515
|
+
return typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
|
|
2516
|
+
}
|
|
2382
2517
|
function isSyntheticUserText(text) {
|
|
2383
2518
|
const s = text.trimStart();
|
|
2384
2519
|
return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
|
|
2385
2520
|
}
|
|
2386
|
-
function
|
|
2387
|
-
return (
|
|
2521
|
+
function contentText(content) {
|
|
2522
|
+
return (content || []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
2523
|
+
}
|
|
2524
|
+
function isUserMessageEvent(line) {
|
|
2525
|
+
return line.type === "event_msg" && line.payload?.type === "item_completed" && line.payload.item?.type === "UserMessage";
|
|
2388
2526
|
}
|
|
2389
2527
|
function readCodexTranscript(path) {
|
|
2390
|
-
const
|
|
2391
|
-
for (const rawLine of
|
|
2528
|
+
const lines = [];
|
|
2529
|
+
for (const rawLine of readJsonl(path)) {
|
|
2392
2530
|
const trimmed = rawLine.trim();
|
|
2393
2531
|
if (!trimmed) continue;
|
|
2394
|
-
let parsed;
|
|
2395
2532
|
try {
|
|
2396
|
-
parsed = JSON.parse(trimmed);
|
|
2533
|
+
const parsed = JSON.parse(trimmed);
|
|
2534
|
+
if (typeof parsed === "object" && parsed !== null) lines.push(parsed);
|
|
2397
2535
|
} catch {
|
|
2398
2536
|
continue;
|
|
2399
2537
|
}
|
|
2400
|
-
|
|
2401
|
-
|
|
2538
|
+
}
|
|
2539
|
+
const userFromEvents = lines.some(isUserMessageEvent);
|
|
2540
|
+
const turns = [];
|
|
2541
|
+
const push = (role, raw, stamp = {}) => {
|
|
2542
|
+
const text = stripInjectedMemory(raw).trim();
|
|
2543
|
+
if (text) turns.push({ role, content: text, ...stamp });
|
|
2544
|
+
};
|
|
2545
|
+
for (const line of lines) {
|
|
2546
|
+
if (isUserMessageEvent(line)) {
|
|
2547
|
+
push("user", contentText(line.payload?.item?.content), stampOf(line));
|
|
2548
|
+
continue;
|
|
2549
|
+
}
|
|
2402
2550
|
if (line.type !== "response_item") continue;
|
|
2403
2551
|
const p = line.payload;
|
|
2404
2552
|
if (!p || typeof p !== "object") continue;
|
|
2405
2553
|
if (p.type === "message") {
|
|
2406
|
-
if (p.role
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
} else if (p.type === "function_call" && typeof p.name === "string") {
|
|
2554
|
+
if (p.role === "assistant") push("assistant", contentText(p.content), stampOf(line));
|
|
2555
|
+
else if (p.role === "user" && !userFromEvents) {
|
|
2556
|
+
const text = contentText(p.content);
|
|
2557
|
+
if (!isSyntheticUserText(stripInjectedMemory(text))) push("user", text, stampOf(line));
|
|
2558
|
+
}
|
|
2559
|
+
} else if ((p.type === "function_call" || p.type === "custom_tool_call") && typeof p.name === "string") {
|
|
2560
|
+
const rawInput = p.type === "function_call" ? p.arguments : p.input;
|
|
2412
2561
|
let input;
|
|
2413
2562
|
try {
|
|
2414
|
-
input = JSON.parse(
|
|
2563
|
+
input = JSON.parse(rawInput || "");
|
|
2415
2564
|
} catch {
|
|
2416
2565
|
input = void 0;
|
|
2417
2566
|
}
|
|
2418
|
-
turns.push({ role: "action", content: actionLine(p.name, input) });
|
|
2567
|
+
turns.push({ role: "action", content: actionLine(p.name, input), ...stampOf(line) });
|
|
2419
2568
|
}
|
|
2420
2569
|
}
|
|
2421
2570
|
return turns;
|
|
@@ -2432,7 +2581,7 @@ function textFrom(content) {
|
|
|
2432
2581
|
}
|
|
2433
2582
|
function readCursorTranscript(path) {
|
|
2434
2583
|
const turns = [];
|
|
2435
|
-
for (const rawLine of
|
|
2584
|
+
for (const rawLine of readJsonl(path)) {
|
|
2436
2585
|
let parsed;
|
|
2437
2586
|
try {
|
|
2438
2587
|
parsed = JSON.parse(rawLine);
|
|
@@ -2471,7 +2620,7 @@ function readCursorTranscript(path) {
|
|
|
2471
2620
|
function readAntigravityTranscript(path) {
|
|
2472
2621
|
if (!path) return [];
|
|
2473
2622
|
const turns = [];
|
|
2474
|
-
for (const line of
|
|
2623
|
+
for (const line of readJsonl(path)) {
|
|
2475
2624
|
try {
|
|
2476
2625
|
const event = JSON.parse(line);
|
|
2477
2626
|
const role = event.role ?? event.message?.role ?? event.type;
|
|
@@ -2494,7 +2643,7 @@ function readAntigravityTranscript(path) {
|
|
|
2494
2643
|
// src/core/transcript-copilot.ts
|
|
2495
2644
|
function readCopilotTranscript(path) {
|
|
2496
2645
|
const turns = [];
|
|
2497
|
-
for (const rawLine of
|
|
2646
|
+
for (const rawLine of readJsonl(path)) {
|
|
2498
2647
|
try {
|
|
2499
2648
|
const event = JSON.parse(rawLine);
|
|
2500
2649
|
const role = event.type === "user.message" ? "user" : event.type === "assistant.message" ? "assistant" : void 0;
|
|
@@ -2529,7 +2678,7 @@ function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
|
2529
2678
|
}
|
|
2530
2679
|
function readGrokTranscript(path) {
|
|
2531
2680
|
const turns = [];
|
|
2532
|
-
for (const rawLine of
|
|
2681
|
+
for (const rawLine of readJsonl(path)) {
|
|
2533
2682
|
try {
|
|
2534
2683
|
const event = JSON.parse(rawLine);
|
|
2535
2684
|
if (event.type !== "user" && event.type !== "assistant") continue;
|
|
@@ -2621,7 +2770,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2621
2770
|
|
|
2622
2771
|
// src/core/transcript-dcode.ts
|
|
2623
2772
|
var BLOCK_JOIN = "\n";
|
|
2624
|
-
function
|
|
2773
|
+
function contentText2(content) {
|
|
2625
2774
|
if (typeof content === "string") return content;
|
|
2626
2775
|
if (!Array.isArray(content)) return "";
|
|
2627
2776
|
return content.flatMap((block) => {
|
|
@@ -2714,11 +2863,11 @@ function dcodeAssistantText(raw) {
|
|
|
2714
2863
|
const parsed = readPyValue(trimmed, 0);
|
|
2715
2864
|
if (!parsed || readPyValue(trimmed, parsed.end) !== null) return "";
|
|
2716
2865
|
if (!Array.isArray(parsed.value)) return "";
|
|
2717
|
-
return
|
|
2866
|
+
return contentText2(parsed.value);
|
|
2718
2867
|
}
|
|
2719
2868
|
function readDcodeTranscript(path) {
|
|
2720
2869
|
const turns = [];
|
|
2721
|
-
for (const rawLine of
|
|
2870
|
+
for (const rawLine of readJsonl(path)) {
|
|
2722
2871
|
if (!rawLine.trim()) continue;
|
|
2723
2872
|
let parsed;
|
|
2724
2873
|
try {
|
|
@@ -2732,7 +2881,7 @@ function readDcodeTranscript(path) {
|
|
|
2732
2881
|
const role = record.role;
|
|
2733
2882
|
const stamp = typeof record.timestamp === "string" && record.timestamp ? { timestamp: record.timestamp } : {};
|
|
2734
2883
|
if (role === "user" || role === "assistant") {
|
|
2735
|
-
const text = stripInjectedMemory(
|
|
2884
|
+
const text = stripInjectedMemory(contentText2(record.content)).trim();
|
|
2736
2885
|
if (text) turns.push({ role, content: text, ...stamp });
|
|
2737
2886
|
} else if (role === "tool" && typeof record.name === "string" && record.name.trim()) {
|
|
2738
2887
|
turns.push({ role: "action", content: actionLine(record.name, record.content), ...stamp });
|
|
@@ -2793,7 +2942,7 @@ function readQwenTranscript(path) {
|
|
|
2793
2942
|
return turns;
|
|
2794
2943
|
}
|
|
2795
2944
|
function collectQwenTurns(path, turns) {
|
|
2796
|
-
for (const rawLine of
|
|
2945
|
+
for (const rawLine of readJsonl(path)) {
|
|
2797
2946
|
const trimmed = rawLine.trim();
|
|
2798
2947
|
if (!trimmed) continue;
|
|
2799
2948
|
let parsed;
|
|
@@ -2848,7 +2997,7 @@ function renderContent(content, role) {
|
|
|
2848
2997
|
}
|
|
2849
2998
|
function readDroidTranscript(path) {
|
|
2850
2999
|
const turns = [];
|
|
2851
|
-
for (const rawLine of
|
|
3000
|
+
for (const rawLine of readJsonl(path)) {
|
|
2852
3001
|
if (!rawLine.trim()) continue;
|
|
2853
3002
|
let parsed;
|
|
2854
3003
|
try {
|
|
@@ -2871,7 +3020,7 @@ function readDroidTranscript(path) {
|
|
|
2871
3020
|
|
|
2872
3021
|
// src/core/transcript-zcode.ts
|
|
2873
3022
|
import { readFileSync as readFileSync13 } from "fs";
|
|
2874
|
-
function
|
|
3023
|
+
function messageText(content) {
|
|
2875
3024
|
if (typeof content === "string") return content.trim();
|
|
2876
3025
|
if (!Array.isArray(content)) return "";
|
|
2877
3026
|
return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
|
|
@@ -2899,7 +3048,7 @@ function readZcodeTranscript(path) {
|
|
|
2899
3048
|
const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
|
|
2900
3049
|
const role = typeof message?.role === "string" ? message.role : record.type;
|
|
2901
3050
|
if (role !== "user" && role !== "assistant") continue;
|
|
2902
|
-
const content = stripInjectedMemory(
|
|
3051
|
+
const content = stripInjectedMemory(messageText(message?.content)).trim();
|
|
2903
3052
|
if (!content) continue;
|
|
2904
3053
|
turns.push({
|
|
2905
3054
|
role,
|
|
@@ -3252,7 +3401,7 @@ var HOOK_HARNESSES = {
|
|
|
3252
3401
|
// `detached` and terminates the whole process TREE on timeout, so the retain is genuinely lost
|
|
3253
3402
|
// rather than merely orphaned. `retain.hostTimeoutSec` below stays SECONDS, as its name says;
|
|
3254
3403
|
// these two numbers are the same budget in different units for this harness alone.
|
|
3255
|
-
// The prompt timeout must also stay above core/
|
|
3404
|
+
// The prompt timeout must also stay above core/config.ts's DEFAULT_REFLECT_TIMEOUT_MS.
|
|
3256
3405
|
install: {
|
|
3257
3406
|
sessionStart: { event: "SessionStart", entry: "qwen-sessionstart-hook.js", timeout: 3e4 },
|
|
3258
3407
|
prompt: { event: "UserPromptSubmit", entry: "qwen-hook.js", timeout: 3e4 },
|
|
@@ -3314,7 +3463,7 @@ var HOOK_HARNESSES = {
|
|
|
3314
3463
|
zcode: {
|
|
3315
3464
|
configStyle: "process",
|
|
3316
3465
|
// ZCode's `timeoutMs`, so MILLISECONDS — see the qwen-code note above for the same trap. The
|
|
3317
|
-
// prompt budget must stay above core/
|
|
3466
|
+
// prompt budget must stay above core/config.ts's DEFAULT_REFLECT_TIMEOUT_MS.
|
|
3318
3467
|
timeoutUnit: "milliseconds",
|
|
3319
3468
|
install: {
|
|
3320
3469
|
sessionStart: { event: "SessionStart", entry: "zcode-sessionstart-hook.js", timeout: 3e4 },
|