@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/daemon-start.js
CHANGED
|
@@ -370,6 +370,39 @@ function diag(harness, event, extra = {}) {
|
|
|
370
370
|
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
371
371
|
import { dirname as dirname3, isAbsolute, join as join3, resolve } from "path";
|
|
372
372
|
|
|
373
|
+
// src/core/missions.ts
|
|
374
|
+
import { createHash } from "crypto";
|
|
375
|
+
var CRON_FIELD_RANGES = [
|
|
376
|
+
[0, 59],
|
|
377
|
+
// minute
|
|
378
|
+
[0, 23],
|
|
379
|
+
// hour
|
|
380
|
+
[1, 31],
|
|
381
|
+
// day of month
|
|
382
|
+
[1, 12],
|
|
383
|
+
// month
|
|
384
|
+
[0, 6]
|
|
385
|
+
// day of week
|
|
386
|
+
];
|
|
387
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
388
|
+
function isHashedCron(cron) {
|
|
389
|
+
return /(^|\s)H/.test(cron);
|
|
390
|
+
}
|
|
391
|
+
function parseHashedCron(cron) {
|
|
392
|
+
const fields = cron.trim().split(/\s+/);
|
|
393
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
394
|
+
for (const [i, field] of fields.entries()) {
|
|
395
|
+
if (!field.startsWith("H")) continue;
|
|
396
|
+
const m = HASHED_FIELD.exec(field);
|
|
397
|
+
if (!m) return void 0;
|
|
398
|
+
if (m[1] === void 0) continue;
|
|
399
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
400
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
401
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
402
|
+
}
|
|
403
|
+
return fields;
|
|
404
|
+
}
|
|
405
|
+
|
|
373
406
|
// src/core/util.ts
|
|
374
407
|
import { accessSync, constants } from "fs";
|
|
375
408
|
import { delimiter, join as join5 } from "path";
|
|
@@ -386,10 +419,11 @@ var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
|
386
419
|
function resolvePageTriggerType(raw) {
|
|
387
420
|
if (raw.pageTriggerType === "manual") return "manual";
|
|
388
421
|
if (raw.pageTriggerType === "cron") {
|
|
389
|
-
|
|
422
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
423
|
+
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
390
424
|
log.warn(
|
|
391
425
|
"config",
|
|
392
|
-
'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "
|
|
426
|
+
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"'
|
|
393
427
|
);
|
|
394
428
|
}
|
|
395
429
|
return "auto-refresh";
|
package/dist/dcode-hook.js
CHANGED
|
@@ -287,9 +287,13 @@ function isOptedIn(config, directory) {
|
|
|
287
287
|
const pathMap = config.mapPathToBank;
|
|
288
288
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
289
289
|
}
|
|
290
|
-
function
|
|
290
|
+
function mappedBank(config, directory, sessionRoot) {
|
|
291
291
|
const pathMap = config.mapPathToBank;
|
|
292
|
-
|
|
292
|
+
if (!directory || !pathMap) return void 0;
|
|
293
|
+
return lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
294
|
+
}
|
|
295
|
+
function deriveBankId(config, directory, harness = "coding", sessionRoot) {
|
|
296
|
+
const mapped = mappedBank(config, directory, sessionRoot);
|
|
293
297
|
if (mapped) return mapped;
|
|
294
298
|
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
295
299
|
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
@@ -355,6 +359,7 @@ function startBackgroundSeed(repoDir, opts = {}) {
|
|
|
355
359
|
}
|
|
356
360
|
|
|
357
361
|
// src/core/missions.ts
|
|
362
|
+
import { createHash } from "crypto";
|
|
358
363
|
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.";
|
|
359
364
|
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.";
|
|
360
365
|
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.`;
|
|
@@ -466,6 +471,56 @@ function pagesFor(project) {
|
|
|
466
471
|
var PAGE_MAX_TOKENS = 4096;
|
|
467
472
|
var PAGE_TAGS_MATCH = "all";
|
|
468
473
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
474
|
+
var CRON_FIELD_RANGES = [
|
|
475
|
+
[0, 59],
|
|
476
|
+
// minute
|
|
477
|
+
[0, 23],
|
|
478
|
+
// hour
|
|
479
|
+
[1, 31],
|
|
480
|
+
// day of month
|
|
481
|
+
[1, 12],
|
|
482
|
+
// month
|
|
483
|
+
[0, 6]
|
|
484
|
+
// day of week
|
|
485
|
+
];
|
|
486
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
487
|
+
function isHashedCron(cron) {
|
|
488
|
+
return /(^|\s)H/.test(cron);
|
|
489
|
+
}
|
|
490
|
+
function parseHashedCron(cron) {
|
|
491
|
+
const fields = cron.trim().split(/\s+/);
|
|
492
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
493
|
+
for (const [i, field] of fields.entries()) {
|
|
494
|
+
if (!field.startsWith("H")) continue;
|
|
495
|
+
const m = HASHED_FIELD.exec(field);
|
|
496
|
+
if (!m) return void 0;
|
|
497
|
+
if (m[1] === void 0) continue;
|
|
498
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
499
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
500
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
501
|
+
}
|
|
502
|
+
return fields;
|
|
503
|
+
}
|
|
504
|
+
function hashedValue(seed, field, lo, hi) {
|
|
505
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
506
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
507
|
+
}
|
|
508
|
+
function expandCronHash(cron, seed) {
|
|
509
|
+
if (!isHashedCron(cron)) return cron;
|
|
510
|
+
const fields = parseHashedCron(cron);
|
|
511
|
+
if (!fields) return cron;
|
|
512
|
+
return fields.map((field, i) => {
|
|
513
|
+
const m = HASHED_FIELD.exec(field);
|
|
514
|
+
if (!m) return field;
|
|
515
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
516
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
517
|
+
}).join(" ");
|
|
518
|
+
}
|
|
519
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
520
|
+
const cron = trigger.refresh_cron;
|
|
521
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
522
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
523
|
+
}
|
|
469
524
|
function buildPageTrigger(cfg = {}) {
|
|
470
525
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
471
526
|
switch (cfg.pageTriggerType) {
|
|
@@ -1000,7 +1055,9 @@ var HindsightClient = class {
|
|
|
1000
1055
|
source_query: page.source_query,
|
|
1001
1056
|
tags: page.tags,
|
|
1002
1057
|
max_tokens: PAGE_MAX_TOKENS,
|
|
1003
|
-
|
|
1058
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
1059
|
+
// and one trigger is built per session for all of them.
|
|
1060
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
1004
1061
|
};
|
|
1005
1062
|
if (!hit) {
|
|
1006
1063
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -1038,7 +1095,7 @@ var HindsightClient = class {
|
|
|
1038
1095
|
}
|
|
1039
1096
|
}
|
|
1040
1097
|
this.log(
|
|
1041
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1098
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1042
1099
|
);
|
|
1043
1100
|
}
|
|
1044
1101
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
@@ -1067,7 +1124,7 @@ var HindsightClient = class {
|
|
|
1067
1124
|
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.`,
|
|
1068
1125
|
parent_id: folderId,
|
|
1069
1126
|
tags: ["knowledge:feature-work"],
|
|
1070
|
-
trigger: args.pageTrigger ?? buildPageTrigger()
|
|
1127
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1071
1128
|
});
|
|
1072
1129
|
try {
|
|
1073
1130
|
const j = await r.json();
|
|
@@ -1112,10 +1169,11 @@ var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
|
1112
1169
|
function resolvePageTriggerType(raw) {
|
|
1113
1170
|
if (raw.pageTriggerType === "manual") return "manual";
|
|
1114
1171
|
if (raw.pageTriggerType === "cron") {
|
|
1115
|
-
|
|
1172
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1173
|
+
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
1116
1174
|
log.warn(
|
|
1117
1175
|
"config",
|
|
1118
|
-
'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "
|
|
1176
|
+
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"'
|
|
1119
1177
|
);
|
|
1120
1178
|
}
|
|
1121
1179
|
return "auto-refresh";
|
|
@@ -1621,10 +1679,12 @@ async function runHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1621
1679
|
import { readFileSync as readFileSync5 } from "fs";
|
|
1622
1680
|
|
|
1623
1681
|
// src/core/retain-cursor.ts
|
|
1624
|
-
import { createHash } from "crypto";
|
|
1682
|
+
import { createHash as createHash2 } from "crypto";
|
|
1683
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
1684
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
1625
1685
|
|
|
1626
1686
|
// src/core/uuid.ts
|
|
1627
|
-
import { createHash as
|
|
1687
|
+
import { createHash as createHash3 } from "crypto";
|
|
1628
1688
|
|
|
1629
1689
|
// src/core/daemon.ts
|
|
1630
1690
|
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
@@ -2216,6 +2276,50 @@ function collectQwenTurns(path, turns) {
|
|
|
2216
2276
|
}
|
|
2217
2277
|
}
|
|
2218
2278
|
|
|
2279
|
+
// src/core/transcript-droid.ts
|
|
2280
|
+
function renderContent(content, role) {
|
|
2281
|
+
if (!Array.isArray(content)) return [];
|
|
2282
|
+
const texts = [];
|
|
2283
|
+
const actions = [];
|
|
2284
|
+
for (const block of content) {
|
|
2285
|
+
if (!block || typeof block !== "object") continue;
|
|
2286
|
+
const b = block;
|
|
2287
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
2288
|
+
const text = stripInjectedMemory(b.text).trim();
|
|
2289
|
+
if (text) texts.push(text);
|
|
2290
|
+
} else if (b.type === "tool_use" && typeof b.name === "string") {
|
|
2291
|
+
actions.push({ role: "action", content: actionLine(b.name, b.input) });
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
const out = [];
|
|
2295
|
+
const joined = texts.join("\n").trim();
|
|
2296
|
+
if (joined) out.push({ role, content: joined });
|
|
2297
|
+
out.push(...actions);
|
|
2298
|
+
return out;
|
|
2299
|
+
}
|
|
2300
|
+
function readDroidTranscript(path) {
|
|
2301
|
+
const turns = [];
|
|
2302
|
+
for (const rawLine of readJsonlTail(path, { scope: "factory-droid" }).lines) {
|
|
2303
|
+
if (!rawLine.trim()) continue;
|
|
2304
|
+
let parsed;
|
|
2305
|
+
try {
|
|
2306
|
+
parsed = JSON.parse(rawLine);
|
|
2307
|
+
} catch {
|
|
2308
|
+
continue;
|
|
2309
|
+
}
|
|
2310
|
+
if (!parsed || typeof parsed !== "object") continue;
|
|
2311
|
+
const line = parsed;
|
|
2312
|
+
if (line.type !== "message" || !line.message || typeof line.message !== "object") continue;
|
|
2313
|
+
const message = line.message;
|
|
2314
|
+
const role = message.role;
|
|
2315
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
2316
|
+
if (message.visibility === "user_only" || message.visibility === "llm_only") continue;
|
|
2317
|
+
const stamp = typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
|
|
2318
|
+
turns.push(...renderContent(message.content, role).map((turn) => ({ ...turn, ...stamp })));
|
|
2319
|
+
}
|
|
2320
|
+
return turns;
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2219
2323
|
// src/harness/hook-lifecycle.ts
|
|
2220
2324
|
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
2221
2325
|
var claudePrompt = {
|
|
@@ -2243,6 +2347,10 @@ var dcodePrompt = {
|
|
|
2243
2347
|
...claudePrompt,
|
|
2244
2348
|
harness: "dcode"
|
|
2245
2349
|
};
|
|
2350
|
+
var droidPrompt = {
|
|
2351
|
+
...claudePrompt,
|
|
2352
|
+
harness: "factory-droid"
|
|
2353
|
+
};
|
|
2246
2354
|
var qwenPrompt = {
|
|
2247
2355
|
...claudePrompt,
|
|
2248
2356
|
harness: "qwen-code",
|
|
@@ -2569,6 +2677,31 @@ var HOOK_HARNESSES = {
|
|
|
2569
2677
|
}),
|
|
2570
2678
|
readTranscript: readQwenTranscript
|
|
2571
2679
|
}
|
|
2680
|
+
},
|
|
2681
|
+
"factory-droid": {
|
|
2682
|
+
configStyle: "nested",
|
|
2683
|
+
install: {
|
|
2684
|
+
sessionStart: { event: "SessionStart", entry: "droid-sessionstart-hook.js", timeout: 30 },
|
|
2685
|
+
prompt: { event: "UserPromptSubmit", entry: "droid-hook.js", timeout: 30 },
|
|
2686
|
+
stop: { event: "Stop", entry: "droid-stop-hook.js", timeout: 60 }
|
|
2687
|
+
},
|
|
2688
|
+
// Droid emits Notification(idle_prompt), not Stop, after user cancellation. Reusing the
|
|
2689
|
+
// idempotent retain entry point captures that final partial turn; its event gate ignores every
|
|
2690
|
+
// other notification type before config or daemon work begins.
|
|
2691
|
+
additionalHooks: [{ event: "Notification", entry: "droid-stop-hook.js", timeout: 60 }],
|
|
2692
|
+
sessionStart: standardSessionStart("factory-droid"),
|
|
2693
|
+
prompt: droidPrompt,
|
|
2694
|
+
retain: {
|
|
2695
|
+
hostTimeoutSec: 60,
|
|
2696
|
+
harness: "factory-droid",
|
|
2697
|
+
accept: (ev) => ev.hook_event_name === "Stop" || ev.hook_event_name === "Notification" && ev.notification_type === "idle_prompt",
|
|
2698
|
+
parse: (ev) => ({
|
|
2699
|
+
sessionId: ev.session_id,
|
|
2700
|
+
transcriptPath: ev.transcript_path,
|
|
2701
|
+
cwd: ev.cwd
|
|
2702
|
+
}),
|
|
2703
|
+
readTranscript: readDroidTranscript
|
|
2704
|
+
}
|
|
2572
2705
|
}
|
|
2573
2706
|
};
|
|
2574
2707
|
var runHarnessPrompt = (harness) => runHook(HOOK_HARNESSES[harness].prompt);
|
|
@@ -276,9 +276,13 @@ function isOptedIn(config, directory) {
|
|
|
276
276
|
const pathMap = config.mapPathToBank;
|
|
277
277
|
return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
|
|
278
278
|
}
|
|
279
|
-
function
|
|
279
|
+
function mappedBank(config, directory, sessionRoot) {
|
|
280
280
|
const pathMap = config.mapPathToBank;
|
|
281
|
-
|
|
281
|
+
if (!directory || !pathMap) return void 0;
|
|
282
|
+
return lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
|
|
283
|
+
}
|
|
284
|
+
function deriveBankId(config, directory, harness = "coding", sessionRoot) {
|
|
285
|
+
const mapped = mappedBank(config, directory, sessionRoot);
|
|
282
286
|
if (mapped) return mapped;
|
|
283
287
|
const dynamic = config.dynamicBankId ?? !config.bankId;
|
|
284
288
|
if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
|
|
@@ -344,6 +348,7 @@ function startBackgroundSeed(repoDir, opts = {}) {
|
|
|
344
348
|
}
|
|
345
349
|
|
|
346
350
|
// src/core/missions.ts
|
|
351
|
+
import { createHash } from "crypto";
|
|
347
352
|
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.";
|
|
348
353
|
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.";
|
|
349
354
|
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.`;
|
|
@@ -455,6 +460,56 @@ function pagesFor(project) {
|
|
|
455
460
|
var PAGE_MAX_TOKENS = 4096;
|
|
456
461
|
var PAGE_TAGS_MATCH = "all";
|
|
457
462
|
var PAGE_FACT_TYPES = ["world", "experience", "observation"];
|
|
463
|
+
var CRON_FIELD_RANGES = [
|
|
464
|
+
[0, 59],
|
|
465
|
+
// minute
|
|
466
|
+
[0, 23],
|
|
467
|
+
// hour
|
|
468
|
+
[1, 31],
|
|
469
|
+
// day of month
|
|
470
|
+
[1, 12],
|
|
471
|
+
// month
|
|
472
|
+
[0, 6]
|
|
473
|
+
// day of week
|
|
474
|
+
];
|
|
475
|
+
var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
|
|
476
|
+
function isHashedCron(cron) {
|
|
477
|
+
return /(^|\s)H/.test(cron);
|
|
478
|
+
}
|
|
479
|
+
function parseHashedCron(cron) {
|
|
480
|
+
const fields = cron.trim().split(/\s+/);
|
|
481
|
+
if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
|
|
482
|
+
for (const [i, field] of fields.entries()) {
|
|
483
|
+
if (!field.startsWith("H")) continue;
|
|
484
|
+
const m = HASHED_FIELD.exec(field);
|
|
485
|
+
if (!m) return void 0;
|
|
486
|
+
if (m[1] === void 0) continue;
|
|
487
|
+
const [lo, hi] = [Number(m[1]), Number(m[2])];
|
|
488
|
+
const [min, max] = CRON_FIELD_RANGES[i];
|
|
489
|
+
if (lo > hi || lo < min || hi > max) return void 0;
|
|
490
|
+
}
|
|
491
|
+
return fields;
|
|
492
|
+
}
|
|
493
|
+
function hashedValue(seed, field, lo, hi) {
|
|
494
|
+
const digest = createHash("sha256").update(`${seed}\0${field}`).digest();
|
|
495
|
+
return lo + digest.readUInt32BE(0) % (hi - lo + 1);
|
|
496
|
+
}
|
|
497
|
+
function expandCronHash(cron, seed) {
|
|
498
|
+
if (!isHashedCron(cron)) return cron;
|
|
499
|
+
const fields = parseHashedCron(cron);
|
|
500
|
+
if (!fields) return cron;
|
|
501
|
+
return fields.map((field, i) => {
|
|
502
|
+
const m = HASHED_FIELD.exec(field);
|
|
503
|
+
if (!m) return field;
|
|
504
|
+
const [lo, hi] = m[1] === void 0 ? CRON_FIELD_RANGES[i] : [Number(m[1]), Number(m[2])];
|
|
505
|
+
return String(hashedValue(seed, i, lo, hi));
|
|
506
|
+
}).join(" ");
|
|
507
|
+
}
|
|
508
|
+
function pageTriggerFor(trigger, bank, page) {
|
|
509
|
+
const cron = trigger.refresh_cron;
|
|
510
|
+
if (!cron || !isHashedCron(cron)) return trigger;
|
|
511
|
+
return { ...trigger, refresh_cron: expandCronHash(cron, `${bank}\0${page}`) };
|
|
512
|
+
}
|
|
458
513
|
function buildPageTrigger(cfg = {}) {
|
|
459
514
|
const base = { fact_types: PAGE_FACT_TYPES, tags_match: PAGE_TAGS_MATCH };
|
|
460
515
|
switch (cfg.pageTriggerType) {
|
|
@@ -1008,7 +1063,9 @@ var HindsightClient = class {
|
|
|
1008
1063
|
source_query: page.source_query,
|
|
1009
1064
|
tags: page.tags,
|
|
1010
1065
|
max_tokens: PAGE_MAX_TOKENS,
|
|
1011
|
-
|
|
1066
|
+
// Resolved HERE, not in `buildPageTrigger`: a hashed cron (`H`) needs the page's identity,
|
|
1067
|
+
// and one trigger is built per session for all of them.
|
|
1068
|
+
trigger: pageTriggerFor(pageTrigger, this.bank, page.name)
|
|
1012
1069
|
};
|
|
1013
1070
|
if (!hit) {
|
|
1014
1071
|
const r = await this.req("POST", this.bankUrl("/knowledge-base/pages"), body, [409]);
|
|
@@ -1046,7 +1103,7 @@ var HindsightClient = class {
|
|
|
1046
1103
|
}
|
|
1047
1104
|
}
|
|
1048
1105
|
this.log(
|
|
1049
|
-
`[bank] knowledge pages seeded on ${this.bank}: ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1106
|
+
`[bank] knowledge pages seeded on ${this.bank} (scoped to ${this.project ?? this.bank}): ${created} created, ${updated} re-synced, ${pages.length - created - updated} unchanged`
|
|
1050
1107
|
);
|
|
1051
1108
|
}
|
|
1052
1109
|
/** URL/id-safe slug: lowercase, non-alphanumerics → "-", trim dashes, cap length; fallback "initiative". */
|
|
@@ -1075,7 +1132,7 @@ var HindsightClient = class {
|
|
|
1075
1132
|
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.`,
|
|
1076
1133
|
parent_id: folderId,
|
|
1077
1134
|
tags: ["knowledge:feature-work"],
|
|
1078
|
-
trigger: args.pageTrigger ?? buildPageTrigger()
|
|
1135
|
+
trigger: pageTriggerFor(args.pageTrigger ?? buildPageTrigger(), this.bank, args.title)
|
|
1079
1136
|
});
|
|
1080
1137
|
try {
|
|
1081
1138
|
const j = await r.json();
|
|
@@ -1120,10 +1177,11 @@ var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
|
1120
1177
|
function resolvePageTriggerType(raw) {
|
|
1121
1178
|
if (raw.pageTriggerType === "manual") return "manual";
|
|
1122
1179
|
if (raw.pageTriggerType === "cron") {
|
|
1123
|
-
|
|
1180
|
+
const cron = raw.pageTriggerCron?.trim();
|
|
1181
|
+
if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
|
|
1124
1182
|
log.warn(
|
|
1125
1183
|
"config",
|
|
1126
|
-
'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "
|
|
1184
|
+
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"'
|
|
1127
1185
|
);
|
|
1128
1186
|
}
|
|
1129
1187
|
return "auto-refresh";
|
|
@@ -1462,10 +1520,12 @@ function sessionRootDir(harness, sessionId, cwd) {
|
|
|
1462
1520
|
import { readFileSync as readFileSync5 } from "fs";
|
|
1463
1521
|
|
|
1464
1522
|
// src/core/retain-cursor.ts
|
|
1465
|
-
import { createHash } from "crypto";
|
|
1523
|
+
import { createHash as createHash2 } from "crypto";
|
|
1524
|
+
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
1525
|
+
var PENDING_MAX_BYTES = 256 * 1024;
|
|
1466
1526
|
|
|
1467
1527
|
// src/core/uuid.ts
|
|
1468
|
-
import { createHash as
|
|
1528
|
+
import { createHash as createHash3 } from "crypto";
|
|
1469
1529
|
|
|
1470
1530
|
// src/core/daemon.ts
|
|
1471
1531
|
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
@@ -2078,8 +2138,7 @@ function stampCheck(file, now, latest) {
|
|
|
2078
2138
|
async function latestVersion(fetchImpl) {
|
|
2079
2139
|
try {
|
|
2080
2140
|
const r = await fetchImpl(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
|
|
2081
|
-
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
2082
|
-
headers: { accept: "application/vnd.npm.install-v1+json" }
|
|
2141
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
2083
2142
|
});
|
|
2084
2143
|
if (!r.ok) return "";
|
|
2085
2144
|
const body = await r.json();
|
|
@@ -2165,6 +2224,8 @@ var SKILL_DIRS = {
|
|
|
2165
2224
|
"cline-cli": [".cline", "data", "settings", "skills"],
|
|
2166
2225
|
"qwen-code": [".qwen", "skills"],
|
|
2167
2226
|
// Qwen's user-level skills root (Storage.getUserSkillsDirs)
|
|
2227
|
+
"factory-droid": [".factory", "skills"],
|
|
2228
|
+
// Droid's user-level skills root
|
|
2168
2229
|
// The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
|
|
2169
2230
|
// by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
|
|
2170
2231
|
// and dsh's copy with it.
|
|
@@ -2833,6 +2894,50 @@ function collectQwenTurns(path, turns) {
|
|
|
2833
2894
|
}
|
|
2834
2895
|
}
|
|
2835
2896
|
|
|
2897
|
+
// src/core/transcript-droid.ts
|
|
2898
|
+
function renderContent(content, role) {
|
|
2899
|
+
if (!Array.isArray(content)) return [];
|
|
2900
|
+
const texts = [];
|
|
2901
|
+
const actions = [];
|
|
2902
|
+
for (const block of content) {
|
|
2903
|
+
if (!block || typeof block !== "object") continue;
|
|
2904
|
+
const b = block;
|
|
2905
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
2906
|
+
const text = stripInjectedMemory(b.text).trim();
|
|
2907
|
+
if (text) texts.push(text);
|
|
2908
|
+
} else if (b.type === "tool_use" && typeof b.name === "string") {
|
|
2909
|
+
actions.push({ role: "action", content: actionLine(b.name, b.input) });
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
const out = [];
|
|
2913
|
+
const joined = texts.join("\n").trim();
|
|
2914
|
+
if (joined) out.push({ role, content: joined });
|
|
2915
|
+
out.push(...actions);
|
|
2916
|
+
return out;
|
|
2917
|
+
}
|
|
2918
|
+
function readDroidTranscript(path) {
|
|
2919
|
+
const turns = [];
|
|
2920
|
+
for (const rawLine of readJsonlTail(path, { scope: "factory-droid" }).lines) {
|
|
2921
|
+
if (!rawLine.trim()) continue;
|
|
2922
|
+
let parsed;
|
|
2923
|
+
try {
|
|
2924
|
+
parsed = JSON.parse(rawLine);
|
|
2925
|
+
} catch {
|
|
2926
|
+
continue;
|
|
2927
|
+
}
|
|
2928
|
+
if (!parsed || typeof parsed !== "object") continue;
|
|
2929
|
+
const line = parsed;
|
|
2930
|
+
if (line.type !== "message" || !line.message || typeof line.message !== "object") continue;
|
|
2931
|
+
const message = line.message;
|
|
2932
|
+
const role = message.role;
|
|
2933
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
2934
|
+
if (message.visibility === "user_only" || message.visibility === "llm_only") continue;
|
|
2935
|
+
const stamp = typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
|
|
2936
|
+
turns.push(...renderContent(message.content, role).map((turn) => ({ ...turn, ...stamp })));
|
|
2937
|
+
}
|
|
2938
|
+
return turns;
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2836
2941
|
// src/harness/hook-lifecycle.ts
|
|
2837
2942
|
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
2838
2943
|
var claudePrompt = {
|
|
@@ -2860,6 +2965,10 @@ var dcodePrompt = {
|
|
|
2860
2965
|
...claudePrompt,
|
|
2861
2966
|
harness: "dcode"
|
|
2862
2967
|
};
|
|
2968
|
+
var droidPrompt = {
|
|
2969
|
+
...claudePrompt,
|
|
2970
|
+
harness: "factory-droid"
|
|
2971
|
+
};
|
|
2863
2972
|
var qwenPrompt = {
|
|
2864
2973
|
...claudePrompt,
|
|
2865
2974
|
harness: "qwen-code",
|
|
@@ -3186,6 +3295,31 @@ var HOOK_HARNESSES = {
|
|
|
3186
3295
|
}),
|
|
3187
3296
|
readTranscript: readQwenTranscript
|
|
3188
3297
|
}
|
|
3298
|
+
},
|
|
3299
|
+
"factory-droid": {
|
|
3300
|
+
configStyle: "nested",
|
|
3301
|
+
install: {
|
|
3302
|
+
sessionStart: { event: "SessionStart", entry: "droid-sessionstart-hook.js", timeout: 30 },
|
|
3303
|
+
prompt: { event: "UserPromptSubmit", entry: "droid-hook.js", timeout: 30 },
|
|
3304
|
+
stop: { event: "Stop", entry: "droid-stop-hook.js", timeout: 60 }
|
|
3305
|
+
},
|
|
3306
|
+
// Droid emits Notification(idle_prompt), not Stop, after user cancellation. Reusing the
|
|
3307
|
+
// idempotent retain entry point captures that final partial turn; its event gate ignores every
|
|
3308
|
+
// other notification type before config or daemon work begins.
|
|
3309
|
+
additionalHooks: [{ event: "Notification", entry: "droid-stop-hook.js", timeout: 60 }],
|
|
3310
|
+
sessionStart: standardSessionStart("factory-droid"),
|
|
3311
|
+
prompt: droidPrompt,
|
|
3312
|
+
retain: {
|
|
3313
|
+
hostTimeoutSec: 60,
|
|
3314
|
+
harness: "factory-droid",
|
|
3315
|
+
accept: (ev) => ev.hook_event_name === "Stop" || ev.hook_event_name === "Notification" && ev.notification_type === "idle_prompt",
|
|
3316
|
+
parse: (ev) => ({
|
|
3317
|
+
sessionId: ev.session_id,
|
|
3318
|
+
transcriptPath: ev.transcript_path,
|
|
3319
|
+
cwd: ev.cwd
|
|
3320
|
+
}),
|
|
3321
|
+
readTranscript: readDroidTranscript
|
|
3322
|
+
}
|
|
3189
3323
|
}
|
|
3190
3324
|
};
|
|
3191
3325
|
var runHarnessSessionStart = (harness) => runSessionStartHook(HOOK_HARNESSES[harness].sessionStart);
|