@vectorize-io/hindsight-coding-agents 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -3
- package/dist/antigravity-hook.js +142 -9
- package/dist/antigravity-statusline.js +42 -4
- package/dist/antigravity-stop-hook.js +222 -59
- package/dist/claude-hook.js +142 -9
- package/dist/claude-sessionstart-hook.js +145 -11
- package/dist/claude-stop-hook.js +222 -59
- package/dist/cline.js +149 -61
- package/dist/codex-hook.js +142 -9
- package/dist/codex-sessionstart-hook.js +145 -11
- package/dist/codex-stop-hook.js +222 -59
- package/dist/copilot-hook.js +142 -9
- package/dist/copilot-sessionstart-hook.js +145 -11
- package/dist/copilot-stop-hook.js +222 -59
- package/dist/cursor-hook.js +142 -9
- package/dist/cursor-sessionstart-hook.js +145 -11
- package/dist/cursor-stop-hook.js +222 -59
- package/dist/daemon-start.js +36 -2
- package/dist/dcode-hook.js +142 -9
- package/dist/dcode-sessionstart-hook.js +145 -11
- package/dist/dcode-stop-hook.js +222 -59
- package/dist/deepen.js +97 -14
- package/dist/devin-hook.js +142 -9
- package/dist/devin-sessionstart-hook.js +145 -11
- package/dist/devin-stop-hook.js +222 -59
- package/dist/droid-hook.js +2710 -0
- package/dist/droid-sessionstart-hook.js +3328 -0
- package/dist/droid-stop-hook.js +2970 -0
- package/dist/dsh.js +154 -62
- package/dist/grok-hook.js +142 -9
- package/dist/grok-sessionstart-hook.js +145 -11
- package/dist/grok-stop-hook.js +222 -59
- package/dist/hindsight-seed.js +42 -4
- package/dist/index.js +149 -61
- package/dist/installer.js +155 -13
- package/dist/kilo.js +149 -61
- package/dist/mcp-server.js +474 -133
- package/dist/opencode2.js +149 -61
- package/dist/pi.js +149 -61
- package/dist/prime-agent.js +149 -61
- package/dist/qwen-hook.js +142 -9
- package/dist/qwen-sessionstart-hook.js +145 -11
- package/dist/qwen-stop-hook.js +222 -59
- package/dist/status.js +65 -7
- package/package.json +6 -3
- package/plugin.json +1 -1
- package/skill/SKILL.md +26 -2
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,6 +14989,56 @@ 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 CRON_FIELD_RANGES = [
|
|
14993
|
+
[0, 59],
|
|
14994
|
+
// minute
|
|
14995
|
+
[0, 23],
|
|
14996
|
+
// hour
|
|
14997
|
+
[1, 31],
|
|
14998
|
+
// day of month
|
|
14999
|
+
[1, 12],
|
|
15000
|
+
// month
|
|
15001
|
+
[0, 6]
|
|
15002
|
+
// day of week
|
|
15003
|
+
];
|
|
15004
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
15005
|
+
function isHashedCron(cron) {
|
|
15006
|
+
return /(^|\s)H/.test(cron);
|
|
15007
|
+
}
|
|
15008
|
+
function parseHashedCron(cron) {
|
|
15009
|
+
const fields = cron.trim().split(/\s+/);
|
|
15010
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
15011
|
+
for (const [i, field] of fields.entries()) {
|
|
15012
|
+
if (!field.startsWith("H")) continue;
|
|
15013
|
+
const m = HASHED_FIELD.exec(field);
|
|
15014
|
+
if (!m) return void 0;
|
|
15015
|
+
if (m[1] === void 0) continue;
|
|
15016
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
15017
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
15018
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
15019
|
+
}
|
|
15020
|
+
return fields;
|
|
15021
|
+
}
|
|
15022
|
+
function hashedValue(seed, field, lo, hi) {
|
|
15023
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
15024
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
15025
|
+
}
|
|
15026
|
+
function expandCronHash(cron, seed) {
|
|
15027
|
+
if (!isHashedCron(cron)) return cron;
|
|
15028
|
+
const fields = parseHashedCron(cron);
|
|
15029
|
+
if (!fields) return cron;
|
|
15030
|
+
return fields.map((field, i) => {
|
|
15031
|
+
const m = HASHED_FIELD.exec(field);
|
|
15032
|
+
if (!m) return field;
|
|
15033
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
15034
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
15035
|
+
}).join(" ");
|
|
15036
|
+
}
|
|
15037
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
15038
|
+
const cron = trigger.refresh_cron;
|
|
15039
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
15040
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
15041
|
+
}
|
|
14987
15042
|
function buildPageTrigger(cfg = {}) {
|
|
14988
15043
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
14989
15044
|
switch (cfg.pageTriggerType) {
|
|
@@ -15537,7 +15592,9 @@ var HindsightClient = class {
|
|
|
15537
15592
|
source_query: page.source_query,
|
|
15538
15593
|
tags: page.tags,
|
|
15539
15594
|
max_tokens: PAGE_MAX_TOKENS,
|
|
15540
|
-
|
|
15595
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
15596
|
+
// and one trigger is built per session for all of them.
|
|
15597
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
15541
15598
|
};
|
|
15542
15599
|
if (!hit) {
|
|
15543
15600
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -15575,7 +15632,7 @@ var HindsightClient = class {
|
|
|
15575
15632
|
}
|
|
15576
15633
|
}
|
|
15577
15634
|
this.log(
|
|
15578
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
15635
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
15579
15636
|
);
|
|
15580
15637
|
}
|
|
15581
15638
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
@@ -15604,7 +15661,7 @@ var HindsightClient = class {
|
|
|
15604
15661
|
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.`,
|
|
15605
15662
|
parent_id: folderId,
|
|
15606
15663
|
tags: ["knowledge:feature-work"],
|
|
15607
|
-
trigger: args.pageTrigger ?? buildPageTrigger()
|
|
15664
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
15608
15665
|
});
|
|
15609
15666
|
try {
|
|
15610
15667
|
const j = await r.json();
|
|
@@ -15649,10 +15706,11 @@ var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
|
15649
15706
|
function resolvePageTriggerType(raw) {
|
|
15650
15707
|
if (raw.pageTriggerType === "manual") return "manual";
|
|
15651
15708
|
if (raw.pageTriggerType === "cron") {
|
|
15652
|
-
|
|
15709
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
15710
|
+
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
15653
15711
|
log.warn(
|
|
15654
15712
|
"config",
|
|
15655
|
-
'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "
|
|
15713
|
+
cron ? `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 "auto-refresh"` : 'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "H H * * *") \u2014 falling back to "auto-refresh"'
|
|
15656
15714
|
);
|
|
15657
15715
|
}
|
|
15658
15716
|
return "auto-refresh";
|
|
@@ -16045,8 +16103,7 @@ function stampCheck(file3, now, latest) {
|
|
|
16045
16103
|
async function latestVersion(fetchImpl) {
|
|
16046
16104
|
try {
|
|
16047
16105
|
const r = await fetchImpl(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
|
|
16048
|
-
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
16049
|
-
headers: { accept: "application/vnd.npm.install-v1+json" }
|
|
16106
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
16050
16107
|
});
|
|
16051
16108
|
if (!r.ok) return "";
|
|
16052
16109
|
const body = await r.json();
|
|
@@ -16746,15 +16803,24 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16746
16803
|
}
|
|
16747
16804
|
|
|
16748
16805
|
// src/core/retain-cursor.ts
|
|
16749
|
-
import { createHash } from "crypto";
|
|
16806
|
+
import { createHash as createHash2 } from "crypto";
|
|
16807
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16808
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16809
|
+
function pendingReplayable(cursor, now) {
|
|
16810
|
+
const pending = cursor.pending ?? [];
|
|
16811
|
+
if (!pending.length) return true;
|
|
16812
|
+
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
16813
|
+
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16814
|
+
}
|
|
16750
16815
|
function fingerprintTurns(turns, count) {
|
|
16751
|
-
const h =
|
|
16816
|
+
const h = createHash2("sha1").update(String(count));
|
|
16752
16817
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16753
16818
|
return h.digest("hex");
|
|
16754
16819
|
}
|
|
16755
16820
|
function planRetain(turns, cursor, opts) {
|
|
16756
16821
|
if (!turns.length) return { mode: "skip" };
|
|
16757
16822
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
16823
|
+
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
16758
16824
|
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
16759
16825
|
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
16760
16826
|
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
@@ -16770,13 +16836,13 @@ function memoryCursorStore() {
|
|
|
16770
16836
|
}
|
|
16771
16837
|
|
|
16772
16838
|
// src/core/uuid.ts
|
|
16773
|
-
import { createHash as
|
|
16839
|
+
import { createHash as createHash3 } from "crypto";
|
|
16774
16840
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16775
16841
|
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
16776
16842
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16777
16843
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16778
16844
|
const bytes = Buffer.from(
|
|
16779
|
-
|
|
16845
|
+
createHash3("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
16780
16846
|
);
|
|
16781
16847
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16782
16848
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -16853,61 +16919,83 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness, opt
|
|
|
16853
16919
|
);
|
|
16854
16920
|
}
|
|
16855
16921
|
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
16922
|
+
if (!turns.length) return;
|
|
16856
16923
|
const refId = `conversation:${sessionId}`;
|
|
16857
16924
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
16858
|
-
const
|
|
16859
|
-
|
|
16860
|
-
const
|
|
16925
|
+
const cursor = cursors?.read(sessionId);
|
|
16926
|
+
const plan = planRetain(turns, cursor, { appendSupported, bank: client.bank });
|
|
16927
|
+
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
16928
|
+
if (plan.mode === "skip" && !outbox.length) return;
|
|
16929
|
+
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
16930
|
+
${refId}
|
|
16931
|
+
${mode}
|
|
16932
|
+
${content}`);
|
|
16933
|
+
const submit = (content, operationId, append) => client.retain(
|
|
16934
|
+
content,
|
|
16935
|
+
"coding agent session",
|
|
16936
|
+
refId,
|
|
16937
|
+
// Configured tags first, built-ins last and deduped: `source:chat` and `harness:<id>` are what
|
|
16938
|
+
// the documents list filters and draws its agent logo from, so a template cannot displace them.
|
|
16939
|
+
[
|
|
16940
|
+
.../* @__PURE__ */ new Set([
|
|
16941
|
+
...stamp?.tags ?? [],
|
|
16942
|
+
"source:chat",
|
|
16943
|
+
...harness ? [`harness:${harness}`] : []
|
|
16944
|
+
])
|
|
16945
|
+
],
|
|
16946
|
+
"conversation",
|
|
16947
|
+
{
|
|
16948
|
+
timestamp: startTs,
|
|
16949
|
+
updateMode: append ? "append" : void 0,
|
|
16950
|
+
operationId,
|
|
16951
|
+
metadata: {
|
|
16952
|
+
...stamp?.metadata,
|
|
16953
|
+
// configured first: the built-ins below win on any key collision
|
|
16954
|
+
source: "chat",
|
|
16955
|
+
session_id: sessionId,
|
|
16956
|
+
ref_id: refId,
|
|
16957
|
+
...harness ? { harness } : {}
|
|
16958
|
+
}
|
|
16959
|
+
}
|
|
16960
|
+
);
|
|
16861
16961
|
const next = {
|
|
16862
16962
|
turns: turns.length,
|
|
16863
16963
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
16864
16964
|
bank: client.bank
|
|
16865
16965
|
};
|
|
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
|
-
),
|
|
16902
|
-
// Still ours to retry only while the cursor holds the claim we wrote above.
|
|
16903
|
-
() => {
|
|
16904
|
-
if (!cursors) return true;
|
|
16905
|
-
const now = cursors.read(sessionId);
|
|
16906
|
-
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
16907
|
-
},
|
|
16908
|
-
retryUntil
|
|
16909
|
-
);
|
|
16910
|
-
cursors?.write(sessionId, next);
|
|
16966
|
+
const stillOurs = () => {
|
|
16967
|
+
if (!cursors) return true;
|
|
16968
|
+
const now = cursors.read(sessionId);
|
|
16969
|
+
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
16970
|
+
};
|
|
16971
|
+
if (plan.mode === "replace") {
|
|
16972
|
+
const content = renderSessionJsonl(refId, turns, startTs);
|
|
16973
|
+
cursors?.write(sessionId, { ...next, dirty: true });
|
|
16974
|
+
await submitWithRetry(
|
|
16975
|
+
() => submit(content, opId("replace", content), false),
|
|
16976
|
+
stillOurs,
|
|
16977
|
+
retryUntil
|
|
16978
|
+
);
|
|
16979
|
+
cursors?.write(sessionId, next);
|
|
16980
|
+
return;
|
|
16981
|
+
}
|
|
16982
|
+
const queue = [...outbox];
|
|
16983
|
+
if (plan.mode === "append") {
|
|
16984
|
+
const content = turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n");
|
|
16985
|
+
queue.push({ content, operationId: opId("append", content), at: Date.now() });
|
|
16986
|
+
}
|
|
16987
|
+
cursors?.write(sessionId, { ...next, pending: queue });
|
|
16988
|
+
for (let i = 0; i < queue.length; i++) {
|
|
16989
|
+
if (i > 0 && Date.now() + REQUEST_BUDGET_MS > retryUntil) return;
|
|
16990
|
+
const entry = queue[i];
|
|
16991
|
+
await submitWithRetry(
|
|
16992
|
+
() => submit(entry.content, entry.operationId, true),
|
|
16993
|
+
stillOurs,
|
|
16994
|
+
retryUntil
|
|
16995
|
+
);
|
|
16996
|
+
const remaining = queue.slice(i + 1);
|
|
16997
|
+
cursors?.write(sessionId, remaining.length ? { ...next, pending: remaining } : next);
|
|
16998
|
+
}
|
|
16911
16999
|
}
|
|
16912
17000
|
|
|
16913
17001
|
// src/core/retain-stamp.ts
|
package/dist/pi.js
CHANGED
|
@@ -14843,9 +14843,13 @@ function isOptedIn(config2, directory) {
|
|
|
14843
14843
|
const pathMap = config2.mapPathToBank;
|
|
14844
14844
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
14845
14845
|
}
|
|
14846
|
-
function
|
|
14846
|
+
function mappedBank(config2, directory, sessionRoot) {
|
|
14847
14847
|
const pathMap = config2.mapPathToBank;
|
|
14848
|
-
|
|
14848
|
+
if (!directory || !pathMap) return void 0;
|
|
14849
|
+
return lookupDirectories(config2, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
14850
|
+
}
|
|
14851
|
+
function deriveBankId(config2, directory, harness = "coding", sessionRoot) {
|
|
14852
|
+
const mapped = mappedBank(config2, directory, sessionRoot);
|
|
14849
14853
|
if (mapped) return mapped;
|
|
14850
14854
|
const dynamic = config2.dynamicBankId ?? !config2.bankId;
|
|
14851
14855
|
if (!dynamic) return config2.bankId || DEFAULT_BANK_NAME;
|
|
@@ -14873,6 +14877,7 @@ function deriveBankIdOrSkip(config2, 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,6 +14989,56 @@ 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 CRON_FIELD_RANGES = [
|
|
14993
|
+
[0, 59],
|
|
14994
|
+
// minute
|
|
14995
|
+
[0, 23],
|
|
14996
|
+
// hour
|
|
14997
|
+
[1, 31],
|
|
14998
|
+
// day of month
|
|
14999
|
+
[1, 12],
|
|
15000
|
+
// month
|
|
15001
|
+
[0, 6]
|
|
15002
|
+
// day of week
|
|
15003
|
+
];
|
|
15004
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
15005
|
+
function isHashedCron(cron) {
|
|
15006
|
+
return /(^|\s)H/.test(cron);
|
|
15007
|
+
}
|
|
15008
|
+
function parseHashedCron(cron) {
|
|
15009
|
+
const fields = cron.trim().split(/\s+/);
|
|
15010
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
15011
|
+
for (const [i, field] of fields.entries()) {
|
|
15012
|
+
if (!field.startsWith("H")) continue;
|
|
15013
|
+
const m = HASHED_FIELD.exec(field);
|
|
15014
|
+
if (!m) return void 0;
|
|
15015
|
+
if (m[1] === void 0) continue;
|
|
15016
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
15017
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
15018
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
15019
|
+
}
|
|
15020
|
+
return fields;
|
|
15021
|
+
}
|
|
15022
|
+
function hashedValue(seed, field, lo, hi) {
|
|
15023
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
15024
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
15025
|
+
}
|
|
15026
|
+
function expandCronHash(cron, seed) {
|
|
15027
|
+
if (!isHashedCron(cron)) return cron;
|
|
15028
|
+
const fields = parseHashedCron(cron);
|
|
15029
|
+
if (!fields) return cron;
|
|
15030
|
+
return fields.map((field, i) => {
|
|
15031
|
+
const m = HASHED_FIELD.exec(field);
|
|
15032
|
+
if (!m) return field;
|
|
15033
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
15034
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
15035
|
+
}).join(" ");
|
|
15036
|
+
}
|
|
15037
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
15038
|
+
const cron = trigger.refresh_cron;
|
|
15039
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
15040
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
15041
|
+
}
|
|
14987
15042
|
function buildPageTrigger(cfg = {}) {
|
|
14988
15043
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
14989
15044
|
switch (cfg.pageTriggerType) {
|
|
@@ -15537,7 +15592,9 @@ var HindsightClient = class {
|
|
|
15537
15592
|
source_query: page.source_query,
|
|
15538
15593
|
tags: page.tags,
|
|
15539
15594
|
max_tokens: PAGE_MAX_TOKENS,
|
|
15540
|
-
|
|
15595
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
15596
|
+
// and one trigger is built per session for all of them.
|
|
15597
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
15541
15598
|
};
|
|
15542
15599
|
if (!hit) {
|
|
15543
15600
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -15575,7 +15632,7 @@ var HindsightClient = class {
|
|
|
15575
15632
|
}
|
|
15576
15633
|
}
|
|
15577
15634
|
this.log(
|
|
15578
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
15635
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
15579
15636
|
);
|
|
15580
15637
|
}
|
|
15581
15638
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
@@ -15604,7 +15661,7 @@ var HindsightClient = class {
|
|
|
15604
15661
|
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.`,
|
|
15605
15662
|
parent_id: folderId,
|
|
15606
15663
|
tags: ["knowledge:feature-work"],
|
|
15607
|
-
trigger: args.pageTrigger ?? buildPageTrigger()
|
|
15664
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
15608
15665
|
});
|
|
15609
15666
|
try {
|
|
15610
15667
|
const j = await r.json();
|
|
@@ -15649,10 +15706,11 @@ var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
|
15649
15706
|
function resolvePageTriggerType(raw) {
|
|
15650
15707
|
if (raw.pageTriggerType === "manual") return "manual";
|
|
15651
15708
|
if (raw.pageTriggerType === "cron") {
|
|
15652
|
-
|
|
15709
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
15710
|
+
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
15653
15711
|
log.warn(
|
|
15654
15712
|
"config",
|
|
15655
|
-
'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "
|
|
15713
|
+
cron ? `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 "auto-refresh"` : 'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "H H * * *") \u2014 falling back to "auto-refresh"'
|
|
15656
15714
|
);
|
|
15657
15715
|
}
|
|
15658
15716
|
return "auto-refresh";
|
|
@@ -16045,8 +16103,7 @@ function stampCheck(file2, now, latest) {
|
|
|
16045
16103
|
async function latestVersion(fetchImpl) {
|
|
16046
16104
|
try {
|
|
16047
16105
|
const r = await fetchImpl(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
|
|
16048
|
-
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
16049
|
-
headers: { accept: "application/vnd.npm.install-v1+json" }
|
|
16106
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
16050
16107
|
});
|
|
16051
16108
|
if (!r.ok) return "";
|
|
16052
16109
|
const body = await r.json();
|
|
@@ -16746,15 +16803,24 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16746
16803
|
}
|
|
16747
16804
|
|
|
16748
16805
|
// src/core/retain-cursor.ts
|
|
16749
|
-
import { createHash } from "crypto";
|
|
16806
|
+
import { createHash as createHash2 } from "crypto";
|
|
16807
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
16808
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
16809
|
+
function pendingReplayable(cursor, now) {
|
|
16810
|
+
const pending = cursor.pending ?? [];
|
|
16811
|
+
if (!pending.length) return true;
|
|
16812
|
+
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
16813
|
+
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
16814
|
+
}
|
|
16750
16815
|
function fingerprintTurns(turns, count) {
|
|
16751
|
-
const h =
|
|
16816
|
+
const h = createHash2("sha1").update(String(count));
|
|
16752
16817
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
16753
16818
|
return h.digest("hex");
|
|
16754
16819
|
}
|
|
16755
16820
|
function planRetain(turns, cursor, opts) {
|
|
16756
16821
|
if (!turns.length) return { mode: "skip" };
|
|
16757
16822
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
16823
|
+
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
16758
16824
|
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
16759
16825
|
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
16760
16826
|
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
@@ -16770,13 +16836,13 @@ function memoryCursorStore() {
|
|
|
16770
16836
|
}
|
|
16771
16837
|
|
|
16772
16838
|
// src/core/uuid.ts
|
|
16773
|
-
import { createHash as
|
|
16839
|
+
import { createHash as createHash3 } from "crypto";
|
|
16774
16840
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16775
16841
|
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
16776
16842
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16777
16843
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16778
16844
|
const bytes = Buffer.from(
|
|
16779
|
-
|
|
16845
|
+
createHash3("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
16780
16846
|
);
|
|
16781
16847
|
bytes[6] = bytes[6] & 15 | 80;
|
|
16782
16848
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -16853,61 +16919,83 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness, opt
|
|
|
16853
16919
|
);
|
|
16854
16920
|
}
|
|
16855
16921
|
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
16922
|
+
if (!turns.length) return;
|
|
16856
16923
|
const refId = `conversation:${sessionId}`;
|
|
16857
16924
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
16858
|
-
const
|
|
16859
|
-
|
|
16860
|
-
const
|
|
16925
|
+
const cursor = cursors?.read(sessionId);
|
|
16926
|
+
const plan = planRetain(turns, cursor, { appendSupported, bank: client.bank });
|
|
16927
|
+
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
16928
|
+
if (plan.mode === "skip" && !outbox.length) return;
|
|
16929
|
+
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
16930
|
+
${refId}
|
|
16931
|
+
${mode}
|
|
16932
|
+
${content}`);
|
|
16933
|
+
const submit = (content, operationId, append) => client.retain(
|
|
16934
|
+
content,
|
|
16935
|
+
"coding agent session",
|
|
16936
|
+
refId,
|
|
16937
|
+
// Configured tags first, built-ins last and deduped: `source:chat` and `harness:<id>` are what
|
|
16938
|
+
// the documents list filters and draws its agent logo from, so a template cannot displace them.
|
|
16939
|
+
[
|
|
16940
|
+
.../* @__PURE__ */ new Set([
|
|
16941
|
+
...stamp?.tags ?? [],
|
|
16942
|
+
"source:chat",
|
|
16943
|
+
...harness ? [`harness:${harness}`] : []
|
|
16944
|
+
])
|
|
16945
|
+
],
|
|
16946
|
+
"conversation",
|
|
16947
|
+
{
|
|
16948
|
+
timestamp: startTs,
|
|
16949
|
+
updateMode: append ? "append" : void 0,
|
|
16950
|
+
operationId,
|
|
16951
|
+
metadata: {
|
|
16952
|
+
...stamp?.metadata,
|
|
16953
|
+
// configured first: the built-ins below win on any key collision
|
|
16954
|
+
source: "chat",
|
|
16955
|
+
session_id: sessionId,
|
|
16956
|
+
ref_id: refId,
|
|
16957
|
+
...harness ? { harness } : {}
|
|
16958
|
+
}
|
|
16959
|
+
}
|
|
16960
|
+
);
|
|
16861
16961
|
const next = {
|
|
16862
16962
|
turns: turns.length,
|
|
16863
16963
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
16864
16964
|
bank: client.bank
|
|
16865
16965
|
};
|
|
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
|
-
),
|
|
16902
|
-
// Still ours to retry only while the cursor holds the claim we wrote above.
|
|
16903
|
-
() => {
|
|
16904
|
-
if (!cursors) return true;
|
|
16905
|
-
const now = cursors.read(sessionId);
|
|
16906
|
-
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
16907
|
-
},
|
|
16908
|
-
retryUntil
|
|
16909
|
-
);
|
|
16910
|
-
cursors?.write(sessionId, next);
|
|
16966
|
+
const stillOurs = () => {
|
|
16967
|
+
if (!cursors) return true;
|
|
16968
|
+
const now = cursors.read(sessionId);
|
|
16969
|
+
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
16970
|
+
};
|
|
16971
|
+
if (plan.mode === "replace") {
|
|
16972
|
+
const content = renderSessionJsonl(refId, turns, startTs);
|
|
16973
|
+
cursors?.write(sessionId, { ...next, dirty: true });
|
|
16974
|
+
await submitWithRetry(
|
|
16975
|
+
() => submit(content, opId("replace", content), false),
|
|
16976
|
+
stillOurs,
|
|
16977
|
+
retryUntil
|
|
16978
|
+
);
|
|
16979
|
+
cursors?.write(sessionId, next);
|
|
16980
|
+
return;
|
|
16981
|
+
}
|
|
16982
|
+
const queue = [...outbox];
|
|
16983
|
+
if (plan.mode === "append") {
|
|
16984
|
+
const content = turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n");
|
|
16985
|
+
queue.push({ content, operationId: opId("append", content), at: Date.now() });
|
|
16986
|
+
}
|
|
16987
|
+
cursors?.write(sessionId, { ...next, pending: queue });
|
|
16988
|
+
for (let i = 0; i < queue.length; i++) {
|
|
16989
|
+
if (i > 0 && Date.now() + REQUEST_BUDGET_MS > retryUntil) return;
|
|
16990
|
+
const entry = queue[i];
|
|
16991
|
+
await submitWithRetry(
|
|
16992
|
+
() => submit(entry.content, entry.operationId, true),
|
|
16993
|
+
stillOurs,
|
|
16994
|
+
retryUntil
|
|
16995
|
+
);
|
|
16996
|
+
const remaining = queue.slice(i + 1);
|
|
16997
|
+
cursors?.write(sessionId, remaining.length ? { ...next, pending: remaining } : next);
|
|
16998
|
+
}
|
|
16911
16999
|
}
|
|
16912
17000
|
|
|
16913
17001
|
// src/core/retain-stamp.ts
|