@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/dcode-stop-hook.js
CHANGED
|
@@ -290,9 +290,13 @@ function isOptedIn(config, directory) {
|
|
|
290
290
|
const pathMap = config.mapPathToBank;
|
|
291
291
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
292
292
|
}
|
|
293
|
-
function
|
|
293
|
+
function mappedBank(config, directory, sessionRoot) {
|
|
294
294
|
const pathMap = config.mapPathToBank;
|
|
295
|
-
|
|
295
|
+
if (!directory || !pathMap) return void 0;
|
|
296
|
+
return lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
297
|
+
}
|
|
298
|
+
function deriveBankId(config, directory, harness = "coding", sessionRoot) {
|
|
299
|
+
const mapped = mappedBank(config, directory, sessionRoot);
|
|
296
300
|
if (mapped) return mapped;
|
|
297
301
|
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
298
302
|
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
@@ -331,6 +335,7 @@ import { fileURLToPath } from "url";
|
|
|
331
335
|
var DEFAULT_SEED_LIMIT = 300;
|
|
332
336
|
|
|
333
337
|
// src/core/missions.ts
|
|
338
|
+
import { createHash } from "crypto";
|
|
334
339
|
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.";
|
|
335
340
|
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.";
|
|
336
341
|
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.`;
|
|
@@ -442,6 +447,56 @@ function pagesFor(project) {
|
|
|
442
447
|
var PAGE_MAX_TOKENS = 4096;
|
|
443
448
|
var PAGE_TAGS_MATCH = "all";
|
|
444
449
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
450
|
+
var CRON_FIELD_RANGES = [
|
|
451
|
+
[0, 59],
|
|
452
|
+
// minute
|
|
453
|
+
[0, 23],
|
|
454
|
+
// hour
|
|
455
|
+
[1, 31],
|
|
456
|
+
// day of month
|
|
457
|
+
[1, 12],
|
|
458
|
+
// month
|
|
459
|
+
[0, 6]
|
|
460
|
+
// day of week
|
|
461
|
+
];
|
|
462
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
463
|
+
function isHashedCron(cron) {
|
|
464
|
+
return /(^|\s)H/.test(cron);
|
|
465
|
+
}
|
|
466
|
+
function parseHashedCron(cron) {
|
|
467
|
+
const fields = cron.trim().split(/\s+/);
|
|
468
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
469
|
+
for (const [i, field] of fields.entries()) {
|
|
470
|
+
if (!field.startsWith("H")) continue;
|
|
471
|
+
const m = HASHED_FIELD.exec(field);
|
|
472
|
+
if (!m) return void 0;
|
|
473
|
+
if (m[1] === void 0) continue;
|
|
474
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
475
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
476
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
477
|
+
}
|
|
478
|
+
return fields;
|
|
479
|
+
}
|
|
480
|
+
function hashedValue(seed, field, lo, hi) {
|
|
481
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
482
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
483
|
+
}
|
|
484
|
+
function expandCronHash(cron, seed) {
|
|
485
|
+
if (!isHashedCron(cron)) return cron;
|
|
486
|
+
const fields = parseHashedCron(cron);
|
|
487
|
+
if (!fields) return cron;
|
|
488
|
+
return fields.map((field, i) => {
|
|
489
|
+
const m = HASHED_FIELD.exec(field);
|
|
490
|
+
if (!m) return field;
|
|
491
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
492
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
493
|
+
}).join(" ");
|
|
494
|
+
}
|
|
495
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
496
|
+
const cron = trigger.refresh_cron;
|
|
497
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
498
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
499
|
+
}
|
|
445
500
|
function buildPageTrigger(cfg = {}) {
|
|
446
501
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
447
502
|
switch (cfg.pageTriggerType) {
|
|
@@ -976,7 +1031,9 @@ var HindsightClient = class {
|
|
|
976
1031
|
source_query: page.source_query,
|
|
977
1032
|
tags: page.tags,
|
|
978
1033
|
max_tokens: PAGE_MAX_TOKENS,
|
|
979
|
-
|
|
1034
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
1035
|
+
// and one trigger is built per session for all of them.
|
|
1036
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
980
1037
|
};
|
|
981
1038
|
if (!hit) {
|
|
982
1039
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -1014,7 +1071,7 @@ var HindsightClient = class {
|
|
|
1014
1071
|
}
|
|
1015
1072
|
}
|
|
1016
1073
|
this.log(
|
|
1017
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1074
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1018
1075
|
);
|
|
1019
1076
|
}
|
|
1020
1077
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
@@ -1043,7 +1100,7 @@ var HindsightClient = class {
|
|
|
1043
1100
|
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.`,
|
|
1044
1101
|
parent_id: folderId,
|
|
1045
1102
|
tags: ["knowledge:feature-work"],
|
|
1046
|
-
trigger: args.pageTrigger ?? buildPageTrigger()
|
|
1103
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1047
1104
|
});
|
|
1048
1105
|
try {
|
|
1049
1106
|
const j = await r.json();
|
|
@@ -1088,10 +1145,11 @@ var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
|
1088
1145
|
function resolvePageTriggerType(raw) {
|
|
1089
1146
|
if (raw.pageTriggerType === "manual") return "manual";
|
|
1090
1147
|
if (raw.pageTriggerType === "cron") {
|
|
1091
|
-
|
|
1148
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1149
|
+
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
1092
1150
|
log.warn(
|
|
1093
1151
|
"config",
|
|
1094
|
-
'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "
|
|
1152
|
+
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"'
|
|
1095
1153
|
);
|
|
1096
1154
|
}
|
|
1097
1155
|
return "auto-refresh";
|
|
@@ -1391,15 +1449,24 @@ function fileCursorStore(harness) {
|
|
|
1391
1449
|
import { readFileSync as readFileSync5 } from "fs";
|
|
1392
1450
|
|
|
1393
1451
|
// src/core/retain-cursor.ts
|
|
1394
|
-
import { createHash } from "crypto";
|
|
1452
|
+
import { createHash as createHash2 } from "crypto";
|
|
1453
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
1454
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
1455
|
+
function pendingReplayable(cursor, now) {
|
|
1456
|
+
const pending = cursor.pending ?? [];
|
|
1457
|
+
if (!pending.length) return true;
|
|
1458
|
+
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
1459
|
+
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
1460
|
+
}
|
|
1395
1461
|
function fingerprintTurns(turns, count) {
|
|
1396
|
-
const h =
|
|
1462
|
+
const h = createHash2("sha1").update(String(count));
|
|
1397
1463
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
1398
1464
|
return h.digest("hex");
|
|
1399
1465
|
}
|
|
1400
1466
|
function planRetain(turns, cursor, opts) {
|
|
1401
1467
|
if (!turns.length) return { mode: "skip" };
|
|
1402
1468
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
1469
|
+
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
1403
1470
|
if (cursor.bank !== opts.bank) return { mode: "replace" };
|
|
1404
1471
|
if (cursor.turns > turns.length) return { mode: "replace" };
|
|
1405
1472
|
if (fingerprintTurns(turns, cursor.turns) !== cursor.fingerprint) return { mode: "replace" };
|
|
@@ -1408,13 +1475,13 @@ function planRetain(turns, cursor, opts) {
|
|
|
1408
1475
|
}
|
|
1409
1476
|
|
|
1410
1477
|
// src/core/uuid.ts
|
|
1411
|
-
import { createHash as
|
|
1478
|
+
import { createHash as createHash3 } from "crypto";
|
|
1412
1479
|
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
1413
1480
|
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
1414
1481
|
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
1415
1482
|
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
1416
1483
|
const bytes = Buffer.from(
|
|
1417
|
-
|
|
1484
|
+
createHash3("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
1418
1485
|
);
|
|
1419
1486
|
bytes[6] = bytes[6] & 15 | 80;
|
|
1420
1487
|
bytes[8] = bytes[8] & 63 | 128;
|
|
@@ -1491,61 +1558,83 @@ async function retainLiveSession(client, sessionId, turns, startTs, harness, opt
|
|
|
1491
1558
|
);
|
|
1492
1559
|
}
|
|
1493
1560
|
async function writeSession(client, sessionId, turns, startTs, harness, stamp, cursors, retryUntil = Date.now() + DEFAULT_RETRY_WINDOW_MS) {
|
|
1561
|
+
if (!turns.length) return;
|
|
1494
1562
|
const refId = `conversation:${sessionId}`;
|
|
1495
1563
|
const appendSupported = Boolean(cursors) && await supportsAppend(client);
|
|
1496
|
-
const
|
|
1497
|
-
|
|
1498
|
-
const
|
|
1564
|
+
const cursor = cursors?.read(sessionId);
|
|
1565
|
+
const plan = planRetain(turns, cursor, { appendSupported, bank: client.bank });
|
|
1566
|
+
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
1567
|
+
if (plan.mode === "skip" && !outbox.length) return;
|
|
1568
|
+
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
1569
|
+
${refId}
|
|
1570
|
+
${mode}
|
|
1571
|
+
${content}`);
|
|
1572
|
+
const submit = (content, operationId, append) => client.retain(
|
|
1573
|
+
content,
|
|
1574
|
+
"coding agent session",
|
|
1575
|
+
refId,
|
|
1576
|
+
// Configured tags first, built-ins last and deduped: `source:chat` and `harness:<id>` are what
|
|
1577
|
+
// the documents list filters and draws its agent logo from, so a template cannot displace them.
|
|
1578
|
+
[
|
|
1579
|
+
.../* @__PURE__ */ new Set([
|
|
1580
|
+
...stamp?.tags ?? [],
|
|
1581
|
+
"source:chat",
|
|
1582
|
+
...harness ? [`harness:${harness}`] : []
|
|
1583
|
+
])
|
|
1584
|
+
],
|
|
1585
|
+
"conversation",
|
|
1586
|
+
{
|
|
1587
|
+
timestamp: startTs,
|
|
1588
|
+
updateMode: append ? "append" : void 0,
|
|
1589
|
+
operationId,
|
|
1590
|
+
metadata: {
|
|
1591
|
+
...stamp?.metadata,
|
|
1592
|
+
// configured first: the built-ins below win on any key collision
|
|
1593
|
+
source: "chat",
|
|
1594
|
+
session_id: sessionId,
|
|
1595
|
+
ref_id: refId,
|
|
1596
|
+
...harness ? { harness } : {}
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
);
|
|
1499
1600
|
const next = {
|
|
1500
1601
|
turns: turns.length,
|
|
1501
1602
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
1502
1603
|
bank: client.bank
|
|
1503
1604
|
};
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
),
|
|
1540
|
-
// Still ours to retry only while the cursor holds the claim we wrote above.
|
|
1541
|
-
() => {
|
|
1542
|
-
if (!cursors) return true;
|
|
1543
|
-
const now = cursors.read(sessionId);
|
|
1544
|
-
return now?.turns === claimed.turns && now?.fingerprint === claimed.fingerprint;
|
|
1545
|
-
},
|
|
1546
|
-
retryUntil
|
|
1547
|
-
);
|
|
1548
|
-
cursors?.write(sessionId, next);
|
|
1605
|
+
const stillOurs = () => {
|
|
1606
|
+
if (!cursors) return true;
|
|
1607
|
+
const now = cursors.read(sessionId);
|
|
1608
|
+
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
1609
|
+
};
|
|
1610
|
+
if (plan.mode === "replace") {
|
|
1611
|
+
const content = renderSessionJsonl(refId, turns, startTs);
|
|
1612
|
+
cursors?.write(sessionId, { ...next, dirty: true });
|
|
1613
|
+
await submitWithRetry(
|
|
1614
|
+
() => submit(content, opId("replace", content), false),
|
|
1615
|
+
stillOurs,
|
|
1616
|
+
retryUntil
|
|
1617
|
+
);
|
|
1618
|
+
cursors?.write(sessionId, next);
|
|
1619
|
+
return;
|
|
1620
|
+
}
|
|
1621
|
+
const queue = [...outbox];
|
|
1622
|
+
if (plan.mode === "append") {
|
|
1623
|
+
const content = turns.slice(plan.fromTurn).map((t) => JSON.stringify(t)).join("\n");
|
|
1624
|
+
queue.push({ content, operationId: opId("append", content), at: Date.now() });
|
|
1625
|
+
}
|
|
1626
|
+
cursors?.write(sessionId, { ...next, pending: queue });
|
|
1627
|
+
for (let i = 0; i < queue.length; i++) {
|
|
1628
|
+
if (i > 0 && Date.now() + REQUEST_BUDGET_MS > retryUntil) return;
|
|
1629
|
+
const entry = queue[i];
|
|
1630
|
+
await submitWithRetry(
|
|
1631
|
+
() => submit(entry.content, entry.operationId, true),
|
|
1632
|
+
stillOurs,
|
|
1633
|
+
retryUntil
|
|
1634
|
+
);
|
|
1635
|
+
const remaining = queue.slice(i + 1);
|
|
1636
|
+
cursors?.write(sessionId, remaining.length ? { ...next, pending: remaining } : next);
|
|
1637
|
+
}
|
|
1549
1638
|
}
|
|
1550
1639
|
|
|
1551
1640
|
// src/core/daemon.ts
|
|
@@ -1916,6 +2005,7 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1916
2005
|
} catch {
|
|
1917
2006
|
return;
|
|
1918
2007
|
}
|
|
2008
|
+
if (spec.accept && !spec.accept(ev)) return;
|
|
1919
2009
|
const { sessionId, transcriptPath, cwd: rawCwd, lastAssistantMessage } = spec.parse(ev);
|
|
1920
2010
|
const cwd = rawCwd || process.cwd();
|
|
1921
2011
|
let cfg = loadConfig({ harness: spec.harness });
|
|
@@ -2446,6 +2536,50 @@ function collectQwenTurns(path, turns) {
|
|
|
2446
2536
|
}
|
|
2447
2537
|
}
|
|
2448
2538
|
|
|
2539
|
+
// src/core/transcript-droid.ts
|
|
2540
|
+
function renderContent(content, role) {
|
|
2541
|
+
if (!Array.isArray(content)) return [];
|
|
2542
|
+
const texts = [];
|
|
2543
|
+
const actions = [];
|
|
2544
|
+
for (const block of content) {
|
|
2545
|
+
if (!block || typeof block !== "object") continue;
|
|
2546
|
+
const b = block;
|
|
2547
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
2548
|
+
const text = stripInjectedMemory(b.text).trim();
|
|
2549
|
+
if (text) texts.push(text);
|
|
2550
|
+
} else if (b.type === "tool_use" && typeof b.name === "string") {
|
|
2551
|
+
actions.push({ role: "action", content: actionLine(b.name, b.input) });
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
const out = [];
|
|
2555
|
+
const joined = texts.join("\n").trim();
|
|
2556
|
+
if (joined) out.push({ role, content: joined });
|
|
2557
|
+
out.push(...actions);
|
|
2558
|
+
return out;
|
|
2559
|
+
}
|
|
2560
|
+
function readDroidTranscript(path) {
|
|
2561
|
+
const turns = [];
|
|
2562
|
+
for (const rawLine of readJsonlTail(path, { scope: "factory-droid" }).lines) {
|
|
2563
|
+
if (!rawLine.trim()) continue;
|
|
2564
|
+
let parsed;
|
|
2565
|
+
try {
|
|
2566
|
+
parsed = JSON.parse(rawLine);
|
|
2567
|
+
} catch {
|
|
2568
|
+
continue;
|
|
2569
|
+
}
|
|
2570
|
+
if (!parsed || typeof parsed !== "object") continue;
|
|
2571
|
+
const line = parsed;
|
|
2572
|
+
if (line.type !== "message" || !line.message || typeof line.message !== "object") continue;
|
|
2573
|
+
const message = line.message;
|
|
2574
|
+
const role = message.role;
|
|
2575
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
2576
|
+
if (message.visibility === "user_only" || message.visibility === "llm_only") continue;
|
|
2577
|
+
const stamp = typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
|
|
2578
|
+
turns.push(...renderContent(message.content, role).map((turn) => ({ ...turn, ...stamp })));
|
|
2579
|
+
}
|
|
2580
|
+
return turns;
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2449
2583
|
// src/harness/hook-lifecycle.ts
|
|
2450
2584
|
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
2451
2585
|
var claudePrompt = {
|
|
@@ -2473,6 +2607,10 @@ var dcodePrompt = {
|
|
|
2473
2607
|
...claudePrompt,
|
|
2474
2608
|
harness: "dcode"
|
|
2475
2609
|
};
|
|
2610
|
+
var droidPrompt = {
|
|
2611
|
+
...claudePrompt,
|
|
2612
|
+
harness: "factory-droid"
|
|
2613
|
+
};
|
|
2476
2614
|
var qwenPrompt = {
|
|
2477
2615
|
...claudePrompt,
|
|
2478
2616
|
harness: "qwen-code",
|
|
@@ -2799,6 +2937,31 @@ var HOOK_HARNESSES = {
|
|
|
2799
2937
|
}),
|
|
2800
2938
|
readTranscript: readQwenTranscript
|
|
2801
2939
|
}
|
|
2940
|
+
},
|
|
2941
|
+
"factory-droid": {
|
|
2942
|
+
configStyle: "nested",
|
|
2943
|
+
install: {
|
|
2944
|
+
sessionStart: { event: "SessionStart", entry: "droid-sessionstart-hook.js", timeout: 30 },
|
|
2945
|
+
prompt: { event: "UserPromptSubmit", entry: "droid-hook.js", timeout: 30 },
|
|
2946
|
+
stop: { event: "Stop", entry: "droid-stop-hook.js", timeout: 60 }
|
|
2947
|
+
},
|
|
2948
|
+
// Droid emits Notification(idle_prompt), not Stop, after user cancellation. Reusing the
|
|
2949
|
+
// idempotent retain entry point captures that final partial turn; its event gate ignores every
|
|
2950
|
+
// other notification type before config or daemon work begins.
|
|
2951
|
+
additionalHooks: [{ event: "Notification", entry: "droid-stop-hook.js", timeout: 60 }],
|
|
2952
|
+
sessionStart: standardSessionStart("factory-droid"),
|
|
2953
|
+
prompt: droidPrompt,
|
|
2954
|
+
retain: {
|
|
2955
|
+
hostTimeoutSec: 60,
|
|
2956
|
+
harness: "factory-droid",
|
|
2957
|
+
accept: (ev) => ev.hook_event_name === "Stop" || ev.hook_event_name === "Notification" && ev.notification_type === "idle_prompt",
|
|
2958
|
+
parse: (ev) => ({
|
|
2959
|
+
sessionId: ev.session_id,
|
|
2960
|
+
transcriptPath: ev.transcript_path,
|
|
2961
|
+
cwd: ev.cwd
|
|
2962
|
+
}),
|
|
2963
|
+
readTranscript: readDroidTranscript
|
|
2964
|
+
}
|
|
2802
2965
|
}
|
|
2803
2966
|
};
|
|
2804
2967
|
var runHarnessRetain = (harness) => runRetainHook(HOOK_HARNESSES[harness].retain);
|
package/dist/deepen.js
CHANGED
|
@@ -293,9 +293,13 @@ function isOptedIn(config, directory) {
|
|
|
293
293
|
const pathMap = config.mapPathToBank;
|
|
294
294
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
295
295
|
}
|
|
296
|
-
function
|
|
296
|
+
function mappedBank(config, directory, sessionRoot) {
|
|
297
297
|
const pathMap = config.mapPathToBank;
|
|
298
|
-
|
|
298
|
+
if (!directory || !pathMap) return void 0;
|
|
299
|
+
return lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
300
|
+
}
|
|
301
|
+
function deriveBankId(config, directory, harness = "coding", sessionRoot) {
|
|
302
|
+
const mapped = mappedBank(config, directory, sessionRoot);
|
|
299
303
|
if (mapped) return mapped;
|
|
300
304
|
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
301
305
|
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
@@ -308,6 +312,19 @@ function deriveBankId(config, directory, harness = "coding", sessionRoot) {
|
|
|
308
312
|
};
|
|
309
313
|
return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
310
314
|
}
|
|
315
|
+
function bankProjectName(config, directory, sessionRoot) {
|
|
316
|
+
if (mappedBank(config, directory, sessionRoot)) return void 0;
|
|
317
|
+
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
318
|
+
if (!dynamic) return void 0;
|
|
319
|
+
const template = config.bankIdTemplate || DEFAULT_TEMPLATE;
|
|
320
|
+
if (!template.includes("{gitProject}")) return void 0;
|
|
321
|
+
try {
|
|
322
|
+
return gitProjectName(directory, config.resolveWorktrees ?? true, sessionRoot);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (error instanceof BankResolutionError) return void 0;
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
311
328
|
function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot) {
|
|
312
329
|
try {
|
|
313
330
|
return deriveBankId(config, directory, harness, sessionRoot);
|
|
@@ -323,6 +340,7 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
|
|
|
323
340
|
}
|
|
324
341
|
|
|
325
342
|
// src/core/missions.ts
|
|
343
|
+
import { createHash } from "crypto";
|
|
326
344
|
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.";
|
|
327
345
|
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.";
|
|
328
346
|
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.`;
|
|
@@ -434,6 +452,56 @@ function pagesFor(project) {
|
|
|
434
452
|
var PAGE_MAX_TOKENS = 4096;
|
|
435
453
|
var PAGE_TAGS_MATCH = "all";
|
|
436
454
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
455
|
+
var CRON_FIELD_RANGES = [
|
|
456
|
+
[0, 59],
|
|
457
|
+
// minute
|
|
458
|
+
[0, 23],
|
|
459
|
+
// hour
|
|
460
|
+
[1, 31],
|
|
461
|
+
// day of month
|
|
462
|
+
[1, 12],
|
|
463
|
+
// month
|
|
464
|
+
[0, 6]
|
|
465
|
+
// day of week
|
|
466
|
+
];
|
|
467
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
468
|
+
function isHashedCron(cron) {
|
|
469
|
+
return /(^|\s)H/.test(cron);
|
|
470
|
+
}
|
|
471
|
+
function parseHashedCron(cron) {
|
|
472
|
+
const fields = cron.trim().split(/\s+/);
|
|
473
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
474
|
+
for (const [i, field] of fields.entries()) {
|
|
475
|
+
if (!field.startsWith("H")) continue;
|
|
476
|
+
const m = HASHED_FIELD.exec(field);
|
|
477
|
+
if (!m) return void 0;
|
|
478
|
+
if (m[1] === void 0) continue;
|
|
479
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
480
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
481
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
482
|
+
}
|
|
483
|
+
return fields;
|
|
484
|
+
}
|
|
485
|
+
function hashedValue(seed, field, lo, hi) {
|
|
486
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
487
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
488
|
+
}
|
|
489
|
+
function expandCronHash(cron, seed) {
|
|
490
|
+
if (!isHashedCron(cron)) return cron;
|
|
491
|
+
const fields = parseHashedCron(cron);
|
|
492
|
+
if (!fields) return cron;
|
|
493
|
+
return fields.map((field, i) => {
|
|
494
|
+
const m = HASHED_FIELD.exec(field);
|
|
495
|
+
if (!m) return field;
|
|
496
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
497
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
498
|
+
}).join(" ");
|
|
499
|
+
}
|
|
500
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
501
|
+
const cron = trigger.refresh_cron;
|
|
502
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
503
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
504
|
+
}
|
|
437
505
|
function buildPageTrigger(cfg2 = {}) {
|
|
438
506
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
439
507
|
switch (cfg2.pageTriggerType) {
|
|
@@ -968,7 +1036,9 @@ var HindsightClient = class {
|
|
|
968
1036
|
source_query: page.source_query,
|
|
969
1037
|
tags: page.tags,
|
|
970
1038
|
max_tokens: PAGE_MAX_TOKENS,
|
|
971
|
-
|
|
1039
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
1040
|
+
// and one trigger is built per session for all of them.
|
|
1041
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
972
1042
|
};
|
|
973
1043
|
if (!hit) {
|
|
974
1044
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -1006,7 +1076,7 @@ var HindsightClient = class {
|
|
|
1006
1076
|
}
|
|
1007
1077
|
}
|
|
1008
1078
|
this.log(
|
|
1009
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1079
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1010
1080
|
);
|
|
1011
1081
|
}
|
|
1012
1082
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
@@ -1035,7 +1105,7 @@ var HindsightClient = class {
|
|
|
1035
1105
|
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.`,
|
|
1036
1106
|
parent_id: folderId,
|
|
1037
1107
|
tags: ["knowledge:feature-work"],
|
|
1038
|
-
trigger: args.pageTrigger ?? buildPageTrigger()
|
|
1108
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1039
1109
|
});
|
|
1040
1110
|
try {
|
|
1041
1111
|
const j = await r.json();
|
|
@@ -1074,10 +1144,12 @@ var HindsightClient = class {
|
|
|
1074
1144
|
};
|
|
1075
1145
|
|
|
1076
1146
|
// src/core/retain-cursor.ts
|
|
1077
|
-
import { createHash } from "crypto";
|
|
1147
|
+
import { createHash as createHash2 } from "crypto";
|
|
1148
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
1149
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
1078
1150
|
|
|
1079
1151
|
// src/core/uuid.ts
|
|
1080
|
-
import { createHash as
|
|
1152
|
+
import { createHash as createHash3 } from "crypto";
|
|
1081
1153
|
|
|
1082
1154
|
// src/core/chat.ts
|
|
1083
1155
|
function withRefId(refId, turns, baseTs) {
|
|
@@ -1154,10 +1226,11 @@ var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
|
1154
1226
|
function resolvePageTriggerType(raw) {
|
|
1155
1227
|
if (raw.pageTriggerType === "manual") return "manual";
|
|
1156
1228
|
if (raw.pageTriggerType === "cron") {
|
|
1157
|
-
|
|
1229
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1230
|
+
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
1158
1231
|
log.warn(
|
|
1159
1232
|
"config",
|
|
1160
|
-
'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "
|
|
1233
|
+
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"'
|
|
1161
1234
|
);
|
|
1162
1235
|
}
|
|
1163
1236
|
return "auto-refresh";
|
|
@@ -1615,7 +1688,10 @@ var HARNESS_NAMES = [
|
|
|
1615
1688
|
"devin-cli",
|
|
1616
1689
|
"copilot-cli",
|
|
1617
1690
|
"grok-build",
|
|
1618
|
-
"qwen-code"
|
|
1691
|
+
"qwen-code",
|
|
1692
|
+
// Factory Droid is a per-prompt HOOK host: the installer wires ~/.factory/hooks.json and the
|
|
1693
|
+
// stdio MCP registration in ~/.factory/mcp.json (see src/installer.ts).
|
|
1694
|
+
"factory-droid"
|
|
1619
1695
|
];
|
|
1620
1696
|
var HOOK_BINS = {
|
|
1621
1697
|
"claude-code": "hindsight-claude-hook",
|
|
@@ -1626,7 +1702,8 @@ var HOOK_BINS = {
|
|
|
1626
1702
|
"devin-cli": "hindsight-devin-hook",
|
|
1627
1703
|
"copilot-cli": "hindsight-copilot-hook",
|
|
1628
1704
|
"grok-build": "hindsight-grok-hook",
|
|
1629
|
-
"qwen-code": "hindsight-qwen-hook"
|
|
1705
|
+
"qwen-code": "hindsight-qwen-hook",
|
|
1706
|
+
"factory-droid": "hindsight-droid-hook"
|
|
1630
1707
|
// more hook harnesses: add a HookSpec entry point (see src/cursor-hook.ts) + a registration here.
|
|
1631
1708
|
};
|
|
1632
1709
|
var PLUGIN_ENTRYPOINTS = {
|
|
@@ -1722,6 +1799,7 @@ if (cfg.disabled) {
|
|
|
1722
1799
|
process.exit(0);
|
|
1723
1800
|
}
|
|
1724
1801
|
var HARNESS = arg("harness") ?? cfg0.harness;
|
|
1802
|
+
var PAGE_PROJECT = REPO && resolved0.bankId === BANK ? bankProjectName(cfg, REPO) : void 0;
|
|
1725
1803
|
var API_URL = arg("api-url") ?? cfg.apiUrl;
|
|
1726
1804
|
var API_TOKEN = arg("api-token") ?? cfg.apiToken;
|
|
1727
1805
|
var CONV = arg("conversations");
|
|
@@ -1779,9 +1857,14 @@ async function main() {
|
|
|
1779
1857
|
apiToken: API_TOKEN,
|
|
1780
1858
|
bank: FINAL_BANK,
|
|
1781
1859
|
// Names the repository in every seeded page's query, so page synthesis can tell this
|
|
1782
|
-
// project's decisions from those of a dependency it merely discusses (#3476).
|
|
1783
|
-
//
|
|
1784
|
-
|
|
1860
|
+
// project's decisions from those of a dependency it merely discusses (#3476).
|
|
1861
|
+
//
|
|
1862
|
+
// A property of the BANK, not of this run's cwd: the query is PATCHed onto pages that
|
|
1863
|
+
// outlive the session, so a bank several repos share must not be told it is whichever one
|
|
1864
|
+
// ran last (#4146). `bankProjectName` answers only when the bank IS this repo's; the
|
|
1865
|
+
// `banks.<id>.bank` rename below it can point many repos at one destination, so a renamed
|
|
1866
|
+
// bank is not this repo's either. Undefined leaves the client to fall back to the bank id.
|
|
1867
|
+
project: PAGE_PROJECT,
|
|
1785
1868
|
maxParallelRetains: cfg.maxParallelRetains,
|
|
1786
1869
|
observationScopes: cfg.observationScopes,
|
|
1787
1870
|
log: log2
|