@stitchdb/cli 0.7.1 → 0.7.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 (2) hide show
  1. package/dist/cli.js +50 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -495,7 +495,14 @@ async function cmdHook(args) {
495
495
  await handlePostReadHook(cfg, event, cwd || process.cwd()).catch(() => { });
496
496
  return;
497
497
  }
498
- // ── SessionStart: inject prior context (token-efficient) ─────────────
498
+ // ── SessionStart: self-heal hook config + inject prior context ─────────
499
+ // Self-heal: a CLI upgrade often introduces new hooks (e.g. PreToolUse on
500
+ // Read in 0.7.0). Without re-running `stitch install`, the old settings.json
501
+ // would silently miss them. Each SessionStart we (re)wire any missing
502
+ // Stitch hook entries — never touching non-Stitch ones.
503
+ if (eventName === 'SessionStart') {
504
+ ensureHooksUpToDate();
505
+ }
499
506
  // Strategy: prefer distilled memories (dense facts) over raw turns. Only
500
507
  // include raw turns for the last 5 to give the agent immediate continuation.
501
508
  if (eventName === 'SessionStart') {
@@ -957,8 +964,8 @@ async function cmdLink(args) {
957
964
  // Triggered manually (`stitch distill`), and automatically by the Stop hook
958
965
  // when conditions are met (cooldown + new-turn threshold).
959
966
  const DISTILL_STATE_FILE = path.join(CONFIG_DIR, 'distill-state.json');
960
- const DISTILL_COOLDOWN_MS = 30 * 60 * 1000; // don't distill more than once per 30 min
961
- const DISTILL_MIN_NEW_TURNS = 10; // need 10 new turns before bothering
967
+ const DISTILL_COOLDOWN_MS = 10 * 60 * 1000; // distill at most once per 10 min per thread
968
+ const DISTILL_MIN_NEW_TURNS = 5; // need 5 new turns before bothering
962
969
  const DISTILL_BATCH_SIZE = 30; // turns per distillation pass
963
970
  function loadDistillState() {
964
971
  try {
@@ -1676,6 +1683,46 @@ function mergeHook(existing, entry) {
1676
1683
  filtered.push(entry);
1677
1684
  return filtered;
1678
1685
  }
1686
+ /**
1687
+ * Idempotent re-wiring of every Stitch hook into ~/.claude/settings.json.
1688
+ * Called on every SessionStart so a CLI upgrade auto-installs any new hooks
1689
+ * (e.g. PreToolUse:Read added in 0.7.0) without the user re-running
1690
+ * `stitch install`. Never touches non-Stitch hook entries.
1691
+ */
1692
+ function ensureHooksUpToDate() {
1693
+ try {
1694
+ const settingsPath = path.join(os.homedir(), '.claude', 'settings.json');
1695
+ if (!fs.existsSync(path.dirname(settingsPath)))
1696
+ return;
1697
+ let existing = {};
1698
+ try {
1699
+ existing = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
1700
+ }
1701
+ catch { /* corrupt — skip */
1702
+ return;
1703
+ }
1704
+ existing.hooks = existing.hooks || {};
1705
+ const expected = [
1706
+ ['SessionStart', STITCH_SESSION_START_HOOK],
1707
+ ['UserPromptSubmit', STITCH_USER_HOOK],
1708
+ ['Stop', STITCH_STOP_HOOK],
1709
+ ['PreToolUse', STITCH_PRE_READ_HOOK],
1710
+ ['PostToolUse', STITCH_POST_READ_HOOK],
1711
+ ];
1712
+ let changed = false;
1713
+ for (const [key, entry] of expected) {
1714
+ const next = mergeHook(existing.hooks[key], entry);
1715
+ if (JSON.stringify(next) !== JSON.stringify(existing.hooks[key])) {
1716
+ existing.hooks[key] = next;
1717
+ changed = true;
1718
+ }
1719
+ }
1720
+ if (changed) {
1721
+ fs.writeFileSync(settingsPath, JSON.stringify(existing, null, 2));
1722
+ }
1723
+ }
1724
+ catch { /* never break a session start */ }
1725
+ }
1679
1726
  const STITCH_CLAUDE_MD_BLOCK = `<!-- stitch:auto -->
1680
1727
  ## Stitch memory
1681
1728
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stitchdb/cli",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Stitch CLI — manage memory + run agents from your terminal",
5
5
  "type": "module",
6
6
  "bin": {