@stitchdb/cli 0.7.0 → 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 +90 -5
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -211,8 +211,46 @@ async function cmdWorkspace(args) {
211
211
  saveConfig(cfg);
212
212
  console.log(`Default workspace set: ${id}`);
213
213
  }
214
+ else if (sub === 'rename') {
215
+ const positionals = positional(rest);
216
+ const id = positionals[0];
217
+ const name = positionals.slice(1).join(' ');
218
+ if (!id || !name) {
219
+ console.error('Usage: stitch workspace rename <id> <new-name>');
220
+ process.exit(2);
221
+ }
222
+ const w = await stitch.workspaces.update(id, { name });
223
+ console.log(`Renamed ${w.id} → ${w.name}`);
224
+ }
225
+ else if (sub === 'delete') {
226
+ const id = positional(rest)[0];
227
+ if (!id) {
228
+ console.error('Usage: stitch workspace delete <id> [--yes]');
229
+ process.exit(2);
230
+ }
231
+ if (!hasFlag(rest, ['--yes', '-y'])) {
232
+ // Show what will be lost so the user knows the blast radius.
233
+ try {
234
+ const w = await stitch.workspaces.get(id);
235
+ console.log(`This will permanently delete workspace "${w.name}" (${w.id})`);
236
+ console.log('and ALL its memories, threads, and conversation history.');
237
+ console.log('Re-run with --yes to confirm.');
238
+ }
239
+ catch (e) {
240
+ console.error(`Workspace ${id} not found: ${e?.message || e}`);
241
+ process.exit(1);
242
+ }
243
+ return;
244
+ }
245
+ const ok = await stitch.workspaces.delete(id);
246
+ console.log(ok ? `Deleted ${id}` : `Workspace ${id} not found`);
247
+ if (cfg.defaultWorkspace === id) {
248
+ delete cfg.defaultWorkspace;
249
+ saveConfig(cfg);
250
+ }
251
+ }
214
252
  else {
215
- console.error('Usage: stitch workspace [list|create <name>|use <id>]');
253
+ console.error('Usage: stitch workspace [list | create <name> | use <id> | rename <id> <name> | delete <id> --yes]');
216
254
  process.exit(2);
217
255
  }
218
256
  }
@@ -457,7 +495,14 @@ async function cmdHook(args) {
457
495
  await handlePostReadHook(cfg, event, cwd || process.cwd()).catch(() => { });
458
496
  return;
459
497
  }
460
- // ── 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
+ }
461
506
  // Strategy: prefer distilled memories (dense facts) over raw turns. Only
462
507
  // include raw turns for the last 5 to give the agent immediate continuation.
463
508
  if (eventName === 'SessionStart') {
@@ -919,8 +964,8 @@ async function cmdLink(args) {
919
964
  // Triggered manually (`stitch distill`), and automatically by the Stop hook
920
965
  // when conditions are met (cooldown + new-turn threshold).
921
966
  const DISTILL_STATE_FILE = path.join(CONFIG_DIR, 'distill-state.json');
922
- const DISTILL_COOLDOWN_MS = 30 * 60 * 1000; // don't distill more than once per 30 min
923
- 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
924
969
  const DISTILL_BATCH_SIZE = 30; // turns per distillation pass
925
970
  function loadDistillState() {
926
971
  try {
@@ -1638,6 +1683,46 @@ function mergeHook(existing, entry) {
1638
1683
  filtered.push(entry);
1639
1684
  return filtered;
1640
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
+ }
1641
1726
  const STITCH_CLAUDE_MD_BLOCK = `<!-- stitch:auto -->
1642
1727
  ## Stitch memory
1643
1728
 
@@ -1860,7 +1945,7 @@ function help() {
1860
1945
  stitch thread current Print the auto-derived thread name
1861
1946
  for the current repo / cwd.
1862
1947
 
1863
- stitch workspace [list | create <name> | use <id>]
1948
+ stitch workspace [list | create <name> | use <id> | rename <id> <name> | delete <id> --yes]
1864
1949
 
1865
1950
  stitch agent register <name> Create an agent identity (id only).
1866
1951
  stitch agent list
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stitchdb/cli",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Stitch CLI — manage memory + run agents from your terminal",
5
5
  "type": "module",
6
6
  "bin": {