@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.
Files changed (47) hide show
  1. package/README.md +44 -3
  2. package/dist/antigravity-hook.js +142 -9
  3. package/dist/antigravity-statusline.js +42 -4
  4. package/dist/antigravity-stop-hook.js +222 -59
  5. package/dist/claude-hook.js +142 -9
  6. package/dist/claude-sessionstart-hook.js +145 -11
  7. package/dist/claude-stop-hook.js +222 -59
  8. package/dist/cline.js +149 -61
  9. package/dist/codex-hook.js +142 -9
  10. package/dist/codex-sessionstart-hook.js +145 -11
  11. package/dist/codex-stop-hook.js +222 -59
  12. package/dist/copilot-hook.js +142 -9
  13. package/dist/copilot-sessionstart-hook.js +145 -11
  14. package/dist/copilot-stop-hook.js +222 -59
  15. package/dist/cursor-hook.js +142 -9
  16. package/dist/cursor-sessionstart-hook.js +145 -11
  17. package/dist/cursor-stop-hook.js +222 -59
  18. package/dist/daemon-start.js +36 -2
  19. package/dist/dcode-hook.js +142 -9
  20. package/dist/dcode-sessionstart-hook.js +145 -11
  21. package/dist/dcode-stop-hook.js +222 -59
  22. package/dist/deepen.js +97 -14
  23. package/dist/devin-hook.js +142 -9
  24. package/dist/devin-sessionstart-hook.js +145 -11
  25. package/dist/devin-stop-hook.js +222 -59
  26. package/dist/droid-hook.js +2710 -0
  27. package/dist/droid-sessionstart-hook.js +3328 -0
  28. package/dist/droid-stop-hook.js +2970 -0
  29. package/dist/dsh.js +154 -62
  30. package/dist/grok-hook.js +142 -9
  31. package/dist/grok-sessionstart-hook.js +145 -11
  32. package/dist/grok-stop-hook.js +222 -59
  33. package/dist/hindsight-seed.js +42 -4
  34. package/dist/index.js +149 -61
  35. package/dist/installer.js +155 -13
  36. package/dist/kilo.js +149 -61
  37. package/dist/mcp-server.js +474 -133
  38. package/dist/opencode2.js +149 -61
  39. package/dist/pi.js +149 -61
  40. package/dist/prime-agent.js +149 -61
  41. package/dist/qwen-hook.js +142 -9
  42. package/dist/qwen-sessionstart-hook.js +145 -11
  43. package/dist/qwen-stop-hook.js +222 -59
  44. package/dist/status.js +65 -7
  45. package/package.json +6 -3
  46. package/plugin.json +1 -1
  47. package/skill/SKILL.md +26 -2
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Long-term project memory for **coding agents**, backed by [Hindsight](https://vectorize.io/hindsight).
4
4
  One package, several agents: a shared reflect-and-inject core with a thin entry point per agent
5
- (**opencode**, **opencode 2**, **Kilo CLI**, **Cline CLI**, **pi**, **Prime Agent**, **DeepSeek Harness**, **Claude Code**, **Codex CLI**, **DeepAgents Dcode**, **Antigravity CLI**, **Cursor CLI**, **GitHub Copilot CLI**, **Devin CLI**, **Grok Build**). Ingestion is fully
5
+ (**Claude Code**, **Codex CLI**, **DeepAgents Dcode**, **opencode**, **opencode 2**, **Kilo CLI**, **Cursor CLI**, **GitHub Copilot CLI**, **Grok Build**, **Qwen Code**, **Factory Droid**, **Antigravity CLI**, **Devin CLI**, **Cline CLI**, **pi**, **Prime Agent**, **DeepSeek Harness**). Ingestion is fully
6
6
  automatic — there is no setup command: a repo's git history and conversations flow into its memory
7
7
  bank in the background as you work.
8
8
 
@@ -12,6 +12,8 @@ tie-break policy. Those decisions live in git history and past conversations. Th
12
12
  in front of the agent at the moment it starts working, and keeps a curated set of **knowledge pages**
13
13
  (architecture, conventions, in-flight initiatives) that future sessions start from.
14
14
 
15
+ [View Changelog →](https://hindsight.vectorize.io/changelog/integrations/coding-agents)
16
+
15
17
  ## Install
16
18
 
17
19
  <!-- skill:begin title="Install / update" -->
@@ -152,6 +154,21 @@ Native hooks in `~/.qwen/settings.json`, plus MCP and the companion skill.
152
154
  > continuations, so interactive sessions recall once per prompt while headless (`qwen -p`),
153
155
  > `serve`, SDK and ACP sessions seed and retain but do not recall.
154
156
 
157
+ #### <img src="https://hindsight.vectorize.io/img/harness/factory-droid.svg" alt="" width="20" height="20" /> Factory Droid
158
+
159
+ ```bash
160
+ npx @vectorize-io/hindsight-coding-agents install factory-droid
161
+ ```
162
+
163
+ 4 hook registrations in `~/.factory/hooks.json` (user scope), including a cancellation-safe
164
+ `Notification` write-back, plus a stdio MCP registration under
165
+ `mcpServers.hindsight` in `~/.factory/mcp.json`, and the companion skill in `~/.factory/skills`.
166
+ The installer touches only JSON files - no Droid CLI round-trip - and refuses to overwrite a
167
+ user-managed MCP server already named `hindsight`. Droid's hook protocol matches Claude Code's
168
+ (`session_id`/`transcript_path`/`cwd` in, `hookSpecificOutput.additionalContext` out). Recall and
169
+ injection use the same protocol; write-back also handles Droid's cancellation notification because
170
+ Droid does not emit `Stop` after a cancelled turn.
171
+
155
172
  #### <img src="https://hindsight.vectorize.io/img/harness/antigravity-cli.png" alt="" width="20" height="20" /> Antigravity CLI
156
173
 
157
174
  ```bash
@@ -487,14 +504,14 @@ hook by Codex...), so one shared config serves several agents side by side:
487
504
  | `autoReflect` | `true` | inject a one-time reflect synthesis on the session's **first prompt**. `false` = tool-only reflect: nothing is injected; the agent searches knowledge pages first and reflects only when they are too shallow |
488
505
  | `pageRefreshEveryTurns` | `10` | refetch the knowledge pages and re-inject the page roster + tool guide every N user turns |
489
506
  | `pageTriggerType` | `"auto-refresh"` | when NEW knowledge pages refresh, i.e. what keeping them current costs — `"auto-refresh"` after every consolidation that produced new material, `"cron"` on `pageTriggerCron` only, `"manual"` never on their own. Auto-refresh is the most current and the most expensive: one synthesis per page per consolidation. Maps to the page's `trigger.refresh_after_consolidation` in the Hindsight API (`true` for auto-refresh, `false` for manual) |
490
- | `pageTriggerCron` | — | schedule for `pageTriggerType: "cron"` — UTC, standard 5-field cron, e.g. `"0 3 * * *"`. Sets the page's `trigger.refresh_cron`, which the API treats as mutually exclusive with `refresh_after_consolidation`; a scheduled refresh is skipped when nothing changed |
507
+ | `pageTriggerCron` | — | schedule for `pageTriggerType: "cron"` — UTC, standard 5-field cron, e.g. `"0 3 * * *"`. Sets the page's `trigger.refresh_cron`, which the API treats as mutually exclusive with `refresh_after_consolidation`; a scheduled refresh is skipped when nothing changed. Write a field as `H` to give each page its own value there — see **Spreading refreshes with `H`** below |
491
508
  | `autoSeed` | `true` | SessionStart: auto-seed a cold repo's bank from git history |
492
509
  | `seedLimit` | `300` | auto-seed: most-recent-N-commits cap |
493
510
  | `codebaseSurvey` | `true` | SessionStart: headless survey of a cold repo's structure, run under the current harness's own CLI (claude/codex/antigravity/opencode), falling back to any available agent |
494
511
  | `surveyModel` | `haiku` | model for the survey — Claude recipe only (`claude -p --model`); other agents use their configured default |
495
512
  | `surveyBudgetUsd` | `2` | survey spend cap — Claude recipe only (`claude -p --max-budget-usd`); other agents rely on their read-only sandbox |
496
513
  | `surveyRefreshCommits` | `20` | re-run the survey at SessionStart once this many commits have accrued since the last one, so the structural pages track an architecture that keeps moving (`0` = survey a cold repo only, never again) |
497
- | `retainSessions` | `true` | session write-back, honored by every harness: hook harnesses write the transcript on Stop, plugin harnesses (opencode, opencode 2, Kilo) upsert it every turn plus an idle flush that captures the reply the per-turn pass can't see. Set `false` — globally, per harness, or per bank — to stop writing transcripts (the background history import stops with it) while recall, git ingest and the memory tools keep working |
514
+ | `retainSessions` | `true` | session write-back, honored by every harness: hook harnesses write the transcript on Stop, Factory Droid also writes on its cancellation notification, and plugin harnesses (opencode, opencode 2, Kilo) upsert it every turn plus an idle flush that captures the reply the per-turn pass can't see. Set `false` - globally, per harness, or per bank - to stop writing transcripts (the background history import stops with it) while recall, git ingest and the memory tools keep working |
498
515
  | `maxParallelRetains` | `10` | cap on concurrent retain-related requests: drain()'s per-op polls plus deepen's chat/git retain pools. The API rate-limits bursts, not single requests — if you see 429s, lower this rather than raising it |
499
516
  | `logLevel` | `"info"` | plugin-log verbosity (`"debug"` \| `"info"` \| `"warn"` \| `"error"`); `HINDSIGHT_LOG_LEVEL` env overrides |
500
517
  | `autoUpdate` | `true` | keep the installed runtime current by itself: once a day a session start asks npm for the published version and, when it is newer, re-stages `~/.hindsight/coding-agents` in the background. It rewires no host config, so a release adding a **new** hook entry point still needs a manual `install`. Set `false` to pin the installed version; `disabled` stops it too, since an inert plugin should stay inert. Only ever replaces a runtime installed the documented way, via `npx` — a copy installed with `npm i -g`, vendored as a project dependency, or built from a checkout is left to whoever manages it (update those the way you installed them), and it needs `npx` on `PATH` |
@@ -507,6 +524,30 @@ belongs to the server: Hindsight creates a knowledge page with a delta refresh (
507
524
  page instead of rebuilding it) that doesn't reflect over sibling pages, and these settings merge
508
525
  over those defaults rather than replacing them.
509
526
 
527
+ ### Spreading refreshes with `H`
528
+
529
+ One `pageTriggerCron` is shared by every page in every repo you point this plugin at. So a literal
530
+ `"0 3 * * *"` does not schedule _a_ refresh at 03:00 — it schedules **all** of them at 03:00, five
531
+ pages per bank, on the same worker pool that serves retain. A session ingesting at 03:0x queues
532
+ behind the pile, and moving the hour just moves the pile.
533
+
534
+ Write a field as `H` and it is replaced, per page, by a value hashed from the bank id and the page
535
+ name. Each page gets its own slot, the same slot on every run:
536
+
537
+ | `pageTriggerCron` | what each page gets |
538
+ | ------------------ | ------------------------------------------------------ |
539
+ | `"H H * * *"` | once a day, at its own minute and hour |
540
+ | `"H * * * *"` | once an hour, at its own minute |
541
+ | `"H 3 * * *"` | daily at 03:MM — spread inside the hour you chose |
542
+ | `"H H(0-5) * * *"` | daily, spread across 00:00–05:59 only |
543
+ | `"0 3 * * *"` | no `H`, no hashing — exactly what it says, all at once |
544
+
545
+ `H` is [Jenkins' syntax](https://www.jenkins.io/doc/book/pipeline/syntax/#cron-syntax) for the same
546
+ problem. It never reaches the API: the plugin resolves it to an ordinary cron expression
547
+ (`"41 17 * * *"`) when it creates the page, so the schedule you see in the control plane is a plain
548
+ one you can edit. Hashing spreads pages out, it does not partition them — two pages can still land
549
+ on the same minute, just not all of them.
550
+
510
551
  **These settings apply to pages created from here on.** Changing them does not migrate the pages a
511
552
  repo already has: a page keeps the trigger it was created with, so a bank seeded before you set
512
553
  `"manual"` keeps refreshing on every consolidation. To move an existing page, change its trigger
@@ -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 deriveBankId(config, directory, harness = "coding", sessionRoot) {
290
+ function mappedBank(config, directory, sessionRoot) {
291
291
  const pathMap = config.mapPathToBank;
292
- const mapped = directory && pathMap ? lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0) : void 0;
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
- trigger: pageTrigger
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
- if (raw.pageTriggerCron?.trim()) return "cron";
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. "0 3 * * *") \u2014 falling back to "auto-refresh"'
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 createHash2 } from "crypto";
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);
@@ -278,9 +278,13 @@ function isOptedIn(config, directory) {
278
278
  const pathMap = config.mapPathToBank;
279
279
  return Boolean(pathMap && directories.some((candidate) => mapLookup(pathMap, candidate)));
280
280
  }
281
- function deriveBankId(config, directory, harness = "coding", sessionRoot) {
281
+ function mappedBank(config, directory, sessionRoot) {
282
282
  const pathMap = config.mapPathToBank;
283
- const mapped = directory && pathMap ? lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0) : void 0;
283
+ if (!directory || !pathMap) return void 0;
284
+ return lookupDirectories(config, directory, sessionRoot).map((candidate) => mapLookup(pathMap, candidate)).find((bank) => bank !== void 0);
285
+ }
286
+ function deriveBankId(config, directory, harness = "coding", sessionRoot) {
287
+ const mapped = mappedBank(config, directory, sessionRoot);
284
288
  if (mapped) return mapped;
285
289
  const dynamic = config.dynamicBankId ?? !config.bankId;
286
290
  if (!dynamic) return config.bankId || DEFAULT_BANK_NAME;
@@ -307,6 +311,39 @@ function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot)
307
311
  }
308
312
  }
309
313
 
314
+ // src/core/missions.ts
315
+ import { createHash } from "crypto";
316
+ var CRON_FIELD_RANGES = [
317
+ [0, 59],
318
+ // minute
319
+ [0, 23],
320
+ // hour
321
+ [1, 31],
322
+ // day of month
323
+ [1, 12],
324
+ // month
325
+ [0, 6]
326
+ // day of week
327
+ ];
328
+ var HASHED_FIELD = /^H(?:\((\d+)-(\d+)\))?$/;
329
+ function isHashedCron(cron) {
330
+ return /(^|\s)H/.test(cron);
331
+ }
332
+ function parseHashedCron(cron) {
333
+ const fields = cron.trim().split(/\s+/);
334
+ if (fields.length !== CRON_FIELD_RANGES.length) return void 0;
335
+ for (const [i, field] of fields.entries()) {
336
+ if (!field.startsWith("H")) continue;
337
+ const m = HASHED_FIELD.exec(field);
338
+ if (!m) return void 0;
339
+ if (m[1] === void 0) continue;
340
+ const [lo, hi] = [Number(m[1]), Number(m[2])];
341
+ const [min, max] = CRON_FIELD_RANGES[i];
342
+ if (lo > hi || lo < min || hi > max) return void 0;
343
+ }
344
+ return fields;
345
+ }
346
+
310
347
  // src/core/util.ts
311
348
  import { accessSync, constants } from "fs";
312
349
  import { delimiter, join as join5 } from "path";
@@ -323,10 +360,11 @@ var DEFAULT_DAEMON_PROFILE = "coding-agent";
323
360
  function resolvePageTriggerType(raw) {
324
361
  if (raw.pageTriggerType === "manual") return "manual";
325
362
  if (raw.pageTriggerType === "cron") {
326
- if (raw.pageTriggerCron?.trim()) return "cron";
363
+ const cron = raw.pageTriggerCron?.trim();
364
+ if (cron && (!isHashedCron(cron) || parseHashedCron(cron))) return "cron";
327
365
  log.warn(
328
366
  "config",
329
- 'pageTriggerType "cron" needs pageTriggerCron (UTC 5-field, e.g. "0 3 * * *") \u2014 falling back to "auto-refresh"'
367
+ 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"'
330
368
  );
331
369
  }
332
370
  return "auto-refresh";