@vectorize-io/hindsight-coding-agents 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -9
- package/dist/antigravity-hook.js +424 -81
- package/dist/antigravity-statusline.js +56 -11
- package/dist/antigravity-stop-hook.js +515 -134
- package/dist/claude-hook.js +424 -81
- package/dist/claude-sessionstart-hook.js +392 -98
- package/dist/claude-stop-hook.js +515 -134
- package/dist/cline.js +218 -73
- package/dist/codex-hook.js +424 -81
- package/dist/codex-sessionstart-hook.js +392 -98
- package/dist/codex-stop-hook.js +515 -134
- package/dist/copilot-hook.js +424 -81
- package/dist/copilot-sessionstart-hook.js +392 -98
- package/dist/copilot-stop-hook.js +515 -134
- package/dist/cursor-hook.js +424 -81
- package/dist/cursor-sessionstart-hook.js +392 -98
- package/dist/cursor-stop-hook.js +515 -134
- package/dist/daemon-start.js +50 -9
- package/dist/dcode-hook.js +424 -81
- package/dist/dcode-sessionstart-hook.js +392 -98
- package/dist/dcode-stop-hook.js +515 -134
- package/dist/deepen.js +164 -27
- package/dist/devin-hook.js +424 -81
- package/dist/devin-sessionstart-hook.js +392 -98
- package/dist/devin-stop-hook.js +515 -134
- package/dist/droid-hook.js +2920 -0
- package/dist/droid-sessionstart-hook.js +3487 -0
- package/dist/droid-stop-hook.js +3188 -0
- package/dist/dsh.js +260 -109
- package/dist/grok-hook.js +424 -81
- package/dist/grok-sessionstart-hook.js +392 -98
- package/dist/grok-stop-hook.js +515 -134
- package/dist/hindsight-seed.js +56 -11
- package/dist/index.js +257 -110
- package/dist/installer.js +530 -223
- package/dist/kilo.js +257 -110
- package/dist/mcp-server.js +537 -146
- package/dist/opencode2.js +257 -110
- package/dist/pi.js +256 -109
- package/dist/prime-agent.js +256 -109
- package/dist/qwen-hook.js +424 -81
- package/dist/qwen-sessionstart-hook.js +392 -98
- package/dist/qwen-stop-hook.js +515 -134
- package/dist/status.js +128 -20
- package/dist/zcode-hook.js +2920 -0
- package/dist/zcode-sessionstart-hook.js +3487 -0
- package/dist/zcode-stop-hook.js +3188 -0
- package/package.json +11 -5
- package/plugin.json +1 -1
- package/skill/SKILL.md +42 -8
package/dist/opencode2.js
CHANGED
|
@@ -14843,9 +14843,13 @@ function isOptedIn(config3, directory) {
|
|
|
14843
14843
|
const pathMap = config3.mapPathToBank;
|
|
14844
14844
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
14845
14845
|
}
|
|
14846
|
-
function
|
|
14846
|
+
function mappedBank(config3, directory, sessionRoot) {
|
|
14847
14847
|
const pathMap = config3.mapPathToBank;
|
|
14848
|
-
|
|
14848
|
+
if (!directory || !pathMap) return void 0;
|
|
14849
|
+
return lookupDirectories(config3, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
14850
|
+
}
|
|
14851
|
+
function deriveBankId(config3, directory, harness = "coding", sessionRoot) {
|
|
14852
|
+
const mapped = mappedBank(config3, directory, sessionRoot);
|
|
14849
14853
|
if (mapped) return mapped;
|
|
14850
14854
|
const dynamic = config3.dynamicBankId ?? !config3.bankId;
|
|
14851
14855
|
if (!dynamic) return config3.bankId || DEFAULT_BANK_NAME;
|
|
@@ -14873,6 +14877,7 @@ function deriveBankIdOrSkip(config3, directory, harness = "coding", sessionRoot)
|
|
|
14873
14877
|
}
|
|
14874
14878
|
|
|
14875
14879
|
// src/core/missions.ts
|
|
14880
|
+
import { createHash } from "crypto";
|
|
14876
14881
|
var GIT_MISSION = "You are ingesting a single git commit: its message and its full diff. Extract the concrete technical DECISION and the CAUSE/INVARIANT it encodes, bound to the specific code entities (functions, methods, files) and behaviors it changes. Preserve exact identifiers, paths, and literal values verbatim. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Capture both WHAT changed and WHY. Issue/PR references (#123, GH-123, PROJ-123) are load-bearing: keep them VERBATIM in the fact text and emit each as an ENTITY, so a later question about that issue or PR retrieves this decision.";
|
|
14877
14882
|
var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history, newest first. Extract the project's INITIATIVES, FEATURES, ENHANCEMENTS, and notable changes or THEMES over time \u2014 what the project has been working on and how it has evolved. Do NOT extract per-line code detail (there is no diff to draw it from). Group related commits into a coherent initiative/theme where the messages make that clear; preserve exact identifiers and literal values verbatim when quoting a subject line. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY \u2014 they are how future sessions will ask about this work.";
|
|
14878
14883
|
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.`;
|
|
@@ -14984,17 +14989,77 @@ function pagesFor(project) {
|
|
|
14984
14989
|
var PAGE_MAX_TOKENS = 4096;
|
|
14985
14990
|
var PAGE_TAGS_MATCH = "all";
|
|
14986
14991
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
14992
|
+
var DEFAULT_PAGE_TRIGGER_CRON = "H * * * *";
|
|
14993
|
+
var CRON_FIELD_RANGES = [
|
|
14994
|
+
[0, 59],
|
|
14995
|
+
// minute
|
|
14996
|
+
[0, 23],
|
|
14997
|
+
// hour
|
|
14998
|
+
[1, 31],
|
|
14999
|
+
// day of month
|
|
15000
|
+
[1, 12],
|
|
15001
|
+
// month
|
|
15002
|
+
[0, 6]
|
|
15003
|
+
// day of week
|
|
15004
|
+
];
|
|
15005
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
15006
|
+
function isHashedCron(cron) {
|
|
15007
|
+
return /(^|\s)H/.test(cron);
|
|
15008
|
+
}
|
|
15009
|
+
function parseHashedCron(cron) {
|
|
15010
|
+
const fields = cron.trim().split(/\s+/);
|
|
15011
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
15012
|
+
for (const [i, field] of fields.entries()) {
|
|
15013
|
+
if (!field.startsWith("H")) continue;
|
|
15014
|
+
const m = HASHED_FIELD.exec(field);
|
|
15015
|
+
if (!m) return void 0;
|
|
15016
|
+
if (m[1] === void 0) continue;
|
|
15017
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
15018
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
15019
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
15020
|
+
}
|
|
15021
|
+
return fields;
|
|
15022
|
+
}
|
|
15023
|
+
function hashedValue(seed, field, lo, hi) {
|
|
15024
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
15025
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
15026
|
+
}
|
|
15027
|
+
function expandCronHash(cron, seed) {
|
|
15028
|
+
if (!isHashedCron(cron)) return cron;
|
|
15029
|
+
const fields = parseHashedCron(cron);
|
|
15030
|
+
if (!fields) return cron;
|
|
15031
|
+
return fields.map((field, i) => {
|
|
15032
|
+
const m = HASHED_FIELD.exec(field);
|
|
15033
|
+
if (!m) return field;
|
|
15034
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
15035
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
15036
|
+
}).join(" ");
|
|
15037
|
+
}
|
|
15038
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
15039
|
+
const cron = trigger.refresh_cron;
|
|
15040
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
15041
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
15042
|
+
}
|
|
14987
15043
|
function buildPageTrigger(cfg = {}) {
|
|
14988
15044
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
14989
15045
|
switch (cfg.pageTriggerType) {
|
|
14990
|
-
case "
|
|
14991
|
-
return { ...base,
|
|
15046
|
+
case "auto-refresh":
|
|
15047
|
+
return { ...base, refresh_after_consolidation: true };
|
|
14992
15048
|
case "manual":
|
|
14993
15049
|
return { ...base, refresh_after_consolidation: false };
|
|
15050
|
+
// "cron" and an unset type alike: the default schedule stands in for a missing expression, so
|
|
15051
|
+
// a trigger built from a partial config is never a cron trigger with nothing to fire on.
|
|
14994
15052
|
default:
|
|
14995
|
-
return { ...base,
|
|
15053
|
+
return { ...base, refresh_cron: cfg.pageTriggerCron || DEFAULT_PAGE_TRIGGER_CRON };
|
|
14996
15054
|
}
|
|
14997
15055
|
}
|
|
15056
|
+
function pageTriggerDrifted(current2, desired) {
|
|
15057
|
+
return current2.tags_match !== desired.tags_match || (current2.refresh_cron ?? null) !== (desired.refresh_cron ?? null) || Boolean(current2.refresh_after_consolidation) !== Boolean(desired.refresh_after_consolidation);
|
|
15058
|
+
}
|
|
15059
|
+
function pageTriggerPatch(desired) {
|
|
15060
|
+
if (desired.refresh_after_consolidation === false) return { ...desired, refresh_cron: null };
|
|
15061
|
+
return desired;
|
|
15062
|
+
}
|
|
14998
15063
|
var CODING_BANK_TEMPLATE = {
|
|
14999
15064
|
version: "1",
|
|
15000
15065
|
bank: {
|
|
@@ -15537,7 +15602,9 @@ var HindsightClient = class {
|
|
|
15537
15602
|
source_query: page.source_query,
|
|
15538
15603
|
tags: page.tags,
|
|
15539
15604
|
max_tokens: PAGE_MAX_TOKENS,
|
|
15540
|
-
|
|
15605
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
15606
|
+
// and one trigger is built per session for all of them.
|
|
15607
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
15541
15608
|
};
|
|
15542
15609
|
if (!hit) {
|
|
15543
15610
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -15551,14 +15618,14 @@ var HindsightClient = class {
|
|
|
15551
15618
|
if (r.status !== 409) created++;
|
|
15552
15619
|
} else {
|
|
15553
15620
|
const sourceDrift = hit.description !== page.source_query;
|
|
15554
|
-
const triggerDrift = hit.trigger != null && hit.trigger
|
|
15621
|
+
const triggerDrift = hit.trigger != null && pageTriggerDrifted(hit.trigger, body.trigger);
|
|
15555
15622
|
if (!sourceDrift && !triggerDrift) continue;
|
|
15556
15623
|
const patch = {};
|
|
15557
15624
|
if (sourceDrift) {
|
|
15558
15625
|
patch.source_query = page.source_query;
|
|
15559
15626
|
patch.tags = page.tags;
|
|
15560
15627
|
}
|
|
15561
|
-
if (triggerDrift) patch.trigger =
|
|
15628
|
+
if (triggerDrift) patch.trigger = pageTriggerPatch(body.trigger);
|
|
15562
15629
|
const r = await this.req(
|
|
15563
15630
|
"PATCH",
|
|
15564
15631
|
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(hit.id)}`),
|
|
@@ -15574,10 +15641,42 @@ var HindsightClient = class {
|
|
|
15574
15641
|
updated++;
|
|
15575
15642
|
}
|
|
15576
15643
|
}
|
|
15644
|
+
const initiatives = await this.resyncInitiativeTriggers(roots, pageTrigger);
|
|
15577
15645
|
this.log(
|
|
15578
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
15646
|
+
`[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` : "")
|
|
15579
15647
|
);
|
|
15580
15648
|
}
|
|
15649
|
+
/**
|
|
15650
|
+
* Bring the captured initiative pages onto the same refresh policy as the seeded taxonomy.
|
|
15651
|
+
*
|
|
15652
|
+
* `captureInitiative` stamps this very trigger when it creates a page, so on a bank seeded under
|
|
15653
|
+
* an older default they are the same drift as the taxonomy — and on a real repo they are most of
|
|
15654
|
+
* it: five taxonomy pages against one page per initiative, each an LLM synthesis per
|
|
15655
|
+
* consolidation under the auto-refresh that used to be the default (#3506).
|
|
15656
|
+
*
|
|
15657
|
+
* Only the trigger is touched. Their `name` and `source_query` are written once, from the
|
|
15658
|
+
* initiative's own title, and re-stating either would rebuild a page whose question never
|
|
15659
|
+
* changed. The tree read above is reused rather than re-fetched.
|
|
15660
|
+
*/
|
|
15661
|
+
async resyncInitiativeTriggers(roots, pageTrigger) {
|
|
15662
|
+
const folder = roots.find(
|
|
15663
|
+
(n) => n.kind === "folder" && (n.name || "").toLowerCase() === "initiatives"
|
|
15664
|
+
);
|
|
15665
|
+
let updated = 0;
|
|
15666
|
+
for (const page of folder?.children ?? []) {
|
|
15667
|
+
if (page.kind !== "page" || page.trigger == null) continue;
|
|
15668
|
+
const desired = pageTriggerFor(pageTrigger, this.bank, page.name);
|
|
15669
|
+
if (!pageTriggerDrifted(page.trigger, desired)) continue;
|
|
15670
|
+
const r = await this.req(
|
|
15671
|
+
"PATCH",
|
|
15672
|
+
this.bankUrl(`/knowledge-base/nodes/${encodeURIComponent(page.id)}`),
|
|
15673
|
+
{ trigger: pageTriggerPatch(desired) }
|
|
15674
|
+
);
|
|
15675
|
+
if ([404, 405, 501].includes(r.status)) break;
|
|
15676
|
+
updated++;
|
|
15677
|
+
}
|
|
15678
|
+
return updated;
|
|
15679
|
+
}
|
|
15581
15680
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
15582
15681
|
slugify(s) {
|
|
15583
15682
|
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "initiative";
|
|
@@ -15599,12 +15698,14 @@ var HindsightClient = class {
|
|
|
15599
15698
|
let pageId = args.relatesToPageId;
|
|
15600
15699
|
if (!pageId) {
|
|
15601
15700
|
const folderId = await this.ensureFolder("Initiatives");
|
|
15701
|
+
const subject = this.project ?? this.bank;
|
|
15602
15702
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), {
|
|
15603
15703
|
name: args.title,
|
|
15604
|
-
source_query: `Summarize the "${args.title}" initiative: what is being built or changed and why, and its current state \u2014 drawn from the project's memory
|
|
15704
|
+
source_query: `Summarize the "${args.title}" initiative: what is being built or changed and why, and its current state \u2014 drawn from the project's memory.` + pageScopeRule(subject),
|
|
15605
15705
|
parent_id: folderId,
|
|
15606
15706
|
tags: ["knowledge:feature-work"],
|
|
15607
|
-
|
|
15707
|
+
max_tokens: PAGE_MAX_TOKENS,
|
|
15708
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
15608
15709
|
});
|
|
15609
15710
|
try {
|
|
15610
15711
|
const j = await r.json();
|
|
@@ -15646,16 +15747,22 @@ var HindsightClient = class {
|
|
|
15646
15747
|
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
15647
15748
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
15648
15749
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
15649
|
-
function
|
|
15650
|
-
if (raw.pageTriggerType === "manual") return "manual";
|
|
15651
|
-
if (raw.pageTriggerType === "
|
|
15652
|
-
|
|
15750
|
+
function resolvePageTrigger(raw) {
|
|
15751
|
+
if (raw.pageTriggerType === "manual") return { type: "manual" };
|
|
15752
|
+
if (raw.pageTriggerType === "auto-refresh") return { type: "auto-refresh" };
|
|
15753
|
+
if (raw.pageTriggerType !== void 0 && raw.pageTriggerType !== "cron")
|
|
15653
15754
|
log.warn(
|
|
15654
15755
|
"config",
|
|
15655
|
-
|
|
15756
|
+
`ignoring pageTriggerType=${JSON.stringify(raw.pageTriggerType)} \u2014 expected cron|auto-refresh|manual`
|
|
15656
15757
|
);
|
|
15657
|
-
|
|
15658
|
-
return "
|
|
15758
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
15759
|
+
if (!cron) return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
15760
|
+
if (!isHashedCron(cron) || parseHashedCron(cron)) return { type: "cron", cron };
|
|
15761
|
+
log.warn(
|
|
15762
|
+
"config",
|
|
15763
|
+
`pageTriggerCron ${JSON.stringify(cron)} has a malformed hashed field \u2014 write \`H\` or \`H(<lo>-<hi>)\` within the field's own range, e.g. "H H(0-5) * * *" \u2014 falling back to ${JSON.stringify(DEFAULT_PAGE_TRIGGER_CRON)}`
|
|
15764
|
+
);
|
|
15765
|
+
return { type: "cron", cron: DEFAULT_PAGE_TRIGGER_CRON };
|
|
15659
15766
|
}
|
|
15660
15767
|
var DEFAULT_REFLECT_TOOL_TIMEOUT_MS = 33e4;
|
|
15661
15768
|
var REFLECT_BUDGETS = ["low", "mid", "high"];
|
|
@@ -15687,6 +15794,7 @@ function resolveObservationScopes(raw) {
|
|
|
15687
15794
|
function resolveConfig(raw = {}) {
|
|
15688
15795
|
const serverMode = ["cloud", "self-hosted", "daemon"].includes(raw.serverMode) ? raw.serverMode : "cloud";
|
|
15689
15796
|
const apiPort = raw.apiPort || DEFAULT_DAEMON_PORT;
|
|
15797
|
+
const pageTrigger = resolvePageTrigger(raw);
|
|
15690
15798
|
return {
|
|
15691
15799
|
serverMode,
|
|
15692
15800
|
// Daemon mode resolves the URL HERE rather than at each call site: every entry point already
|
|
@@ -15721,8 +15829,8 @@ function resolveConfig(raw = {}) {
|
|
|
15721
15829
|
reflectBudget: resolveReflectBudget(raw),
|
|
15722
15830
|
autoReflect: raw.autoReflect ?? true,
|
|
15723
15831
|
pageRefreshEveryTurns: raw.pageRefreshEveryTurns || 10,
|
|
15724
|
-
pageTriggerType:
|
|
15725
|
-
pageTriggerCron:
|
|
15832
|
+
pageTriggerType: pageTrigger.type,
|
|
15833
|
+
pageTriggerCron: pageTrigger.cron,
|
|
15726
15834
|
autoSeed: raw.autoSeed ?? true,
|
|
15727
15835
|
seedLimit: raw.seedLimit || DEFAULT_SEED_LIMIT,
|
|
15728
15836
|
codebaseSurvey: raw.codebaseSurvey ?? true,
|
|
@@ -16745,15 +16853,24 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16745
16853
|
}
|
|
16746
16854
|
|
|
16747
16855
|
// src/core/retain-cursor.ts
|
|
16748
|
-
import { createHash } from "crypto";
|
|
16856
|
+
import { createHash as createHash2 } from "crypto";
|
|
16857
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16858
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16859
|
+
function pendingReplayable(cursor, now) {
|
|
16860
|
+
const pending = cursor.pending ?? [];
|
|
16861
|
+
if (!pending.length) return true;
|
|
16862
|
+
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
16863
|
+
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16864
|
+
}
|
|
16749
16865
|
function fingerprintTurns(turns, count) {
|
|
16750
|
-
const h =
|
|
16866
|
+
const h = createHash2("sha1").update(String(count));
|
|
16751
16867
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16752
16868
|
return h.digest("hex");
|
|
16753
16869
|
}
|
|
16754
16870
|
function planRetain(turns, cursor, opts) {
|
|
16755
16871
|
if (!turns.length) return { mode: "skip" };
|
|
16756
16872
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
16873
|
+
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
16757
16874
|
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
16758
16875
|
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
16759
16876
|
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
@@ -16769,13 +16886,13 @@ function memoryCursorStore() {
|
|
|
16769
16886
|
}
|
|
16770
16887
|
|
|
16771
16888
|
// src/core/uuid.ts
|
|
16772
|
-
import { createHash as
|
|
16889
|
+
import { createHash as createHash3 } from "crypto";
|
|
16773
16890
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16774
16891
|
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
16775
16892
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16776
16893
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16777
16894
|
const bytes = Buffer.from(
|
|
16778
|
-
|
|
16895
|
+
createHash3("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
16779
16896
|
);
|
|
16780
16897
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16781
16898
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -16852,61 +16969,83 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness, opt
|
|
|
16852
16969
|
);
|
|
16853
16970
|
}
|
|
16854
16971
|
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
16972
|
+
if (!turns.length) return;
|
|
16855
16973
|
const refId = `conversation:${sessionId}`;
|
|
16856
16974
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
16857
|
-
const
|
|
16858
|
-
|
|
16859
|
-
const
|
|
16975
|
+
const cursor = cursors?.read(sessionId);
|
|
16976
|
+
const plan = planRetain(turns, cursor, { appendSupported, bank: client.bank });
|
|
16977
|
+
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
16978
|
+
if (plan.mode === "skip" && !outbox.length) return;
|
|
16979
|
+
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
16980
|
+
${refId}
|
|
16981
|
+
${mode}
|
|
16982
|
+
${content}`);
|
|
16983
|
+
const submit = (content, operationId, append) => client.retain(
|
|
16984
|
+
content,
|
|
16985
|
+
"coding agent session",
|
|
16986
|
+
refId,
|
|
16987
|
+
// Configured tags first, built-ins last and deduped: `source:chat` and `harness:<id>` are what
|
|
16988
|
+
// the documents list filters and draws its agent logo from, so a template cannot displace them.
|
|
16989
|
+
[
|
|
16990
|
+
.../* @__PURE__ */ new Set([
|
|
16991
|
+
...stamp?.tags ?? [],
|
|
16992
|
+
"source:chat",
|
|
16993
|
+
...harness ? [`harness:${harness}`] : []
|
|
16994
|
+
])
|
|
16995
|
+
],
|
|
16996
|
+
"conversation",
|
|
16997
|
+
{
|
|
16998
|
+
timestamp: startTs,
|
|
16999
|
+
updateMode: append ? "append" : void 0,
|
|
17000
|
+
operationId,
|
|
17001
|
+
metadata: {
|
|
17002
|
+
...stamp?.metadata,
|
|
17003
|
+
// configured first: the built-ins below win on any key collision
|
|
17004
|
+
source: "chat",
|
|
17005
|
+
session_id: sessionId,
|
|
17006
|
+
ref_id: refId,
|
|
17007
|
+
...harness ? { harness } : {}
|
|
17008
|
+
}
|
|
17009
|
+
}
|
|
17010
|
+
);
|
|
16860
17011
|
const next = {
|
|
16861
17012
|
turns: turns.length,
|
|
16862
17013
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
16863
17014
|
bank: client.bank
|
|
16864
17015
|
};
|
|
16865
|
-
|
|
16866
|
-
|
|
16867
|
-
|
|
16868
|
-
|
|
16869
|
-
|
|
16870
|
-
|
|
16871
|
-
|
|
16872
|
-
|
|
16873
|
-
|
|
16874
|
-
|
|
16875
|
-
|
|
16876
|
-
|
|
16877
|
-
|
|
16878
|
-
|
|
16879
|
-
|
|
16880
|
-
|
|
16881
|
-
|
|
16882
|
-
|
|
16883
|
-
|
|
16884
|
-
|
|
16885
|
-
|
|
16886
|
-
|
|
16887
|
-
|
|
16888
|
-
|
|
16889
|
-
|
|
16890
|
-
|
|
16891
|
-
|
|
16892
|
-
|
|
16893
|
-
|
|
16894
|
-
|
|
16895
|
-
|
|
16896
|
-
|
|
16897
|
-
|
|
16898
|
-
}
|
|
16899
|
-
}
|
|
16900
|
-
),
|
|
16901
|
-
// Still ours to retry only while the cursor holds the claim we wrote above.
|
|
16902
|
-
() => {
|
|
16903
|
-
if (!cursors) return true;
|
|
16904
|
-
const now = cursors.read(sessionId);
|
|
16905
|
-
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
16906
|
-
},
|
|
16907
|
-
retryUntil
|
|
16908
|
-
);
|
|
16909
|
-
cursors?.write(sessionId, next);
|
|
17016
|
+
const stillOurs = () => {
|
|
17017
|
+
if (!cursors) return true;
|
|
17018
|
+
const now = cursors.read(sessionId);
|
|
17019
|
+
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17020
|
+
};
|
|
17021
|
+
if (plan.mode === "replace") {
|
|
17022
|
+
const content = renderSessionJsonl(refId, turns, startTs);
|
|
17023
|
+
cursors?.write(sessionId, { ...next, dirty: true });
|
|
17024
|
+
await submitWithRetry(
|
|
17025
|
+
() => submit(content, opId("replace", content), false),
|
|
17026
|
+
stillOurs,
|
|
17027
|
+
retryUntil
|
|
17028
|
+
);
|
|
17029
|
+
cursors?.write(sessionId, next);
|
|
17030
|
+
return;
|
|
17031
|
+
}
|
|
17032
|
+
const queue = [...outbox];
|
|
17033
|
+
if (plan.mode === "append") {
|
|
17034
|
+
const content = turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n");
|
|
17035
|
+
queue.push({ content, operationId: opId("append", content), at: Date.now() });
|
|
17036
|
+
}
|
|
17037
|
+
cursors?.write(sessionId, { ...next, pending: queue });
|
|
17038
|
+
for (let i = 0; i < queue.length; i++) {
|
|
17039
|
+
if (i > 0 && Date.now() + REQUEST_BUDGET_MS > retryUntil) return;
|
|
17040
|
+
const entry = queue[i];
|
|
17041
|
+
await submitWithRetry(
|
|
17042
|
+
() => submit(entry.content, entry.operationId, true),
|
|
17043
|
+
stillOurs,
|
|
17044
|
+
retryUntil
|
|
17045
|
+
);
|
|
17046
|
+
const remaining = queue.slice(i + 1);
|
|
17047
|
+
cursors?.write(sessionId, remaining.length ? { ...next, pending: remaining } : next);
|
|
17048
|
+
}
|
|
16910
17049
|
}
|
|
16911
17050
|
|
|
16912
17051
|
// src/core/retain-stamp.ts
|
|
@@ -17165,7 +17304,7 @@ async function buildSessionStartContext(args) {
|
|
|
17165
17304
|
}
|
|
17166
17305
|
|
|
17167
17306
|
// src/core/hook.ts
|
|
17168
|
-
import { existsSync as existsSync6, readFileSync as
|
|
17307
|
+
import { existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
|
|
17169
17308
|
|
|
17170
17309
|
// src/core/inject.ts
|
|
17171
17310
|
function buildReflectQuery(prompt) {
|
|
@@ -17196,6 +17335,49 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
17196
17335
|
` + memory + "\n</hindsight_memory>";
|
|
17197
17336
|
}
|
|
17198
17337
|
|
|
17338
|
+
// src/core/turn-journal.ts
|
|
17339
|
+
import { appendFileSync as appendFileSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync7, statSync } from "fs";
|
|
17340
|
+
import { tmpdir as tmpdir4 } from "os";
|
|
17341
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
17342
|
+
|
|
17343
|
+
// src/core/transcript-util.ts
|
|
17344
|
+
var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
|
|
17345
|
+
function stripInjectedMemory(s) {
|
|
17346
|
+
return s.replace(MEMORY_TAG_RE, "");
|
|
17347
|
+
}
|
|
17348
|
+
var TARGET_KEYS = [
|
|
17349
|
+
"file_path",
|
|
17350
|
+
"path",
|
|
17351
|
+
"notebook_path",
|
|
17352
|
+
"command",
|
|
17353
|
+
"pattern",
|
|
17354
|
+
"query",
|
|
17355
|
+
"url",
|
|
17356
|
+
"name",
|
|
17357
|
+
"id"
|
|
17358
|
+
];
|
|
17359
|
+
var ACTION_TARGET_CAP = 100;
|
|
17360
|
+
function actionLine(tool2, input) {
|
|
17361
|
+
let target = "";
|
|
17362
|
+
if (input && typeof input === "object") {
|
|
17363
|
+
const rec = input;
|
|
17364
|
+
for (const k of TARGET_KEYS) {
|
|
17365
|
+
const v = rec[k];
|
|
17366
|
+
if (typeof v === "string" && v.trim()) {
|
|
17367
|
+
target = v.trim().split("\n")[0];
|
|
17368
|
+
break;
|
|
17369
|
+
}
|
|
17370
|
+
}
|
|
17371
|
+
} else if (typeof input === "string") {
|
|
17372
|
+
target = input.trim().split("\n")[0];
|
|
17373
|
+
}
|
|
17374
|
+
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
17375
|
+
return target ? `${tool2} ${target}` : tool2;
|
|
17376
|
+
}
|
|
17377
|
+
|
|
17378
|
+
// src/core/turn-journal.ts
|
|
17379
|
+
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
17380
|
+
|
|
17199
17381
|
// src/core/hook.ts
|
|
17200
17382
|
var HOOK_REFLECT_CAP_MS = 25e3;
|
|
17201
17383
|
async function buildHookOutput(args) {
|
|
@@ -17505,41 +17687,6 @@ var RuntimeCore = class {
|
|
|
17505
17687
|
}
|
|
17506
17688
|
};
|
|
17507
17689
|
|
|
17508
|
-
// src/core/transcript-util.ts
|
|
17509
|
-
var MEMORY_TAG_RE = /<(hook_prompt|task-notification|system-reminder|hindsight_memory|hindsight_memories|hindsight_bank|relevant_memories|user_feedback|hindsight_knowledge|hindsight_knowledge_refresh)\b[\s\S]*?<\/\1>/g;
|
|
17510
|
-
function stripInjectedMemory(s) {
|
|
17511
|
-
return s.replace(MEMORY_TAG_RE, "");
|
|
17512
|
-
}
|
|
17513
|
-
var TARGET_KEYS = [
|
|
17514
|
-
"file_path",
|
|
17515
|
-
"path",
|
|
17516
|
-
"notebook_path",
|
|
17517
|
-
"command",
|
|
17518
|
-
"pattern",
|
|
17519
|
-
"query",
|
|
17520
|
-
"url",
|
|
17521
|
-
"name",
|
|
17522
|
-
"id"
|
|
17523
|
-
];
|
|
17524
|
-
var ACTION_TARGET_CAP = 100;
|
|
17525
|
-
function actionLine(tool2, input) {
|
|
17526
|
-
let target = "";
|
|
17527
|
-
if (input && typeof input === "object") {
|
|
17528
|
-
const rec = input;
|
|
17529
|
-
for (const k of TARGET_KEYS) {
|
|
17530
|
-
const v = rec[k];
|
|
17531
|
-
if (typeof v === "string" && v.trim()) {
|
|
17532
|
-
target = v.trim().split("\n")[0];
|
|
17533
|
-
break;
|
|
17534
|
-
}
|
|
17535
|
-
}
|
|
17536
|
-
} else if (typeof input === "string") {
|
|
17537
|
-
target = input.trim().split("\n")[0];
|
|
17538
|
-
}
|
|
17539
|
-
if (target.length > ACTION_TARGET_CAP) target = `${target.slice(0, ACTION_TARGET_CAP)}\u2026`;
|
|
17540
|
-
return target ? `${tool2} ${target}` : tool2;
|
|
17541
|
-
}
|
|
17542
|
-
|
|
17543
17690
|
// src/core/transcript-opencode2.ts
|
|
17544
17691
|
function renderMessage(m) {
|
|
17545
17692
|
const role = m?.type;
|
|
@@ -29991,12 +30138,12 @@ function tool(input) {
|
|
|
29991
30138
|
tool.schema = external_exports2;
|
|
29992
30139
|
|
|
29993
30140
|
// src/harness/registry.ts
|
|
29994
|
-
import { readFileSync as
|
|
30141
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
29995
30142
|
var jsonChatReader = (harness) => ({
|
|
29996
30143
|
describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
|
|
29997
30144
|
async read(opts) {
|
|
29998
30145
|
if (!opts.conversations) return [];
|
|
29999
|
-
return JSON.parse(
|
|
30146
|
+
return JSON.parse(readFileSync9(opts.conversations, "utf8"));
|
|
30000
30147
|
}
|
|
30001
30148
|
});
|
|
30002
30149
|
|