claude-db 0.12.4 → 0.13.0

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 (100) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/capture/cursors.d.ts +8 -0
  3. package/dist/capture/cursors.js +99 -0
  4. package/dist/capture/flush-lock.d.ts +11 -0
  5. package/dist/capture/flush-lock.js +108 -0
  6. package/dist/capture/flush.d.ts +4 -4
  7. package/dist/capture/flush.js +19 -80
  8. package/dist/capture/index.d.ts +3 -3
  9. package/dist/capture/index.js +3 -3
  10. package/dist/capture/reingest.d.ts +1 -0
  11. package/dist/capture/reingest.js +4 -1
  12. package/dist/capture/scrub.d.ts +1 -0
  13. package/dist/capture/scrub.js +4 -1
  14. package/dist/capture/vectors.js +2 -1
  15. package/dist/cli/commands/daemon.d.ts +1 -0
  16. package/dist/cli/commands/daemon.js +29 -0
  17. package/dist/cli/commands/distill.js +2 -1
  18. package/dist/cli/commands/graph.js +2 -1
  19. package/dist/cli/commands/maintain.js +3 -1
  20. package/dist/cli/index.js +4 -0
  21. package/dist/cli/usage.js +1 -0
  22. package/dist/config/schema.d.ts +4 -0
  23. package/dist/config/schema.js +6 -0
  24. package/dist/context.d.ts +1 -0
  25. package/dist/context.js +21 -6
  26. package/dist/daemon/client.d.ts +12 -0
  27. package/dist/daemon/client.js +88 -0
  28. package/dist/daemon/paths.d.ts +16 -0
  29. package/dist/daemon/paths.js +19 -0
  30. package/dist/daemon/server.d.ts +2 -0
  31. package/dist/daemon/server.js +225 -0
  32. package/dist/facts/budget.d.ts +1 -0
  33. package/dist/facts/budget.js +4 -0
  34. package/dist/facts/claude-memory.js +1 -1
  35. package/dist/facts/distill.js +2 -2
  36. package/dist/facts/known.js +1 -1
  37. package/dist/facts/model.d.ts +1 -1
  38. package/dist/facts/model.js +18 -7
  39. package/dist/facts/start.js +1 -1
  40. package/dist/graph/query/refresh.js +5 -1
  41. package/dist/graph/scan/cache.d.ts +1 -0
  42. package/dist/graph/scan/cache.js +1 -1
  43. package/dist/graph/scan/persist.js +12 -16
  44. package/dist/hooks/compact.d.ts +2 -1
  45. package/dist/hooks/compact.js +2 -2
  46. package/dist/hooks/detached.d.ts +1 -0
  47. package/dist/hooks/detached.js +6 -0
  48. package/dist/hooks/graph-presence.d.ts +3 -0
  49. package/dist/hooks/graph-presence.js +42 -0
  50. package/dist/hooks/handlers/prefer-usages.d.ts +2 -0
  51. package/dist/hooks/handlers/prefer-usages.js +113 -0
  52. package/dist/hooks/handlers/session-end.d.ts +2 -0
  53. package/dist/hooks/handlers/session-end.js +62 -0
  54. package/dist/hooks/handlers/session-start.d.ts +2 -0
  55. package/dist/hooks/handlers/session-start.js +104 -0
  56. package/dist/hooks/handlers/turn-end.d.ts +2 -0
  57. package/dist/hooks/handlers/turn-end.js +31 -0
  58. package/dist/hooks/handlers/user-prompt.d.ts +2 -0
  59. package/dist/hooks/handlers/user-prompt.js +55 -0
  60. package/dist/hooks/local.d.ts +2 -0
  61. package/dist/hooks/local.js +23 -0
  62. package/dist/hooks/payload.d.ts +9 -4
  63. package/dist/hooks/payload.js +26 -17
  64. package/dist/hooks/prefer-usages.js +2 -118
  65. package/dist/hooks/route.d.ts +2 -0
  66. package/dist/hooks/route.js +28 -0
  67. package/dist/hooks/run.d.ts +14 -0
  68. package/dist/hooks/run.js +12 -0
  69. package/dist/hooks/save-turn.d.ts +2 -0
  70. package/dist/hooks/save-turn.js +11 -0
  71. package/dist/hooks/session-end.js +2 -63
  72. package/dist/hooks/session-start.js +2 -90
  73. package/dist/hooks/turn-end.js +2 -25
  74. package/dist/hooks/turn-save.js +10 -15
  75. package/dist/hooks/user-prompt.js +2 -58
  76. package/dist/search/service.d.ts +1 -0
  77. package/dist/search/service.js +16 -6
  78. package/dist/store/adapter.d.ts +7 -5
  79. package/dist/store/mongo/index.d.ts +3 -6
  80. package/dist/store/mongo/index.js +5 -0
  81. package/dist/store/mongo/observations.js +13 -1
  82. package/dist/store/postgres/driver.d.ts +10 -3
  83. package/dist/store/postgres/driver.js +12 -0
  84. package/dist/store/postgres/graph.d.ts +3 -5
  85. package/dist/store/postgres/graph.js +56 -50
  86. package/dist/store/postgres/index.d.ts +3 -6
  87. package/dist/store/postgres/index.js +5 -4
  88. package/dist/store/postgres/insert.js +98 -50
  89. package/dist/store/project-resolver.d.ts +3 -0
  90. package/dist/store/project-resolver.js +34 -23
  91. package/dist/store/scoped-store.js +1 -1
  92. package/dist/store/sqlite/graph.d.ts +3 -5
  93. package/dist/store/sqlite/graph.js +42 -33
  94. package/dist/store/sqlite/index.d.ts +3 -6
  95. package/dist/store/sqlite/index.js +3 -0
  96. package/dist/store/sqlite/observations.js +6 -2
  97. package/dist/util/job-lock.d.ts +1 -0
  98. package/dist/util/job-lock.js +50 -10
  99. package/docs/setup-guide.md +5 -0
  100. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- import { mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
1
+ import { mkdirSync, readFileSync, rmSync, statSync, utimesSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { CONFIG_DIR } from '../config/index.js';
4
4
  import { scopeToken } from './scope.js';
@@ -20,22 +20,62 @@ export function jobMark(job, key) {
20
20
  return 0;
21
21
  }
22
22
  }
23
+ const BREAKER_STALE_MS = 30_000;
24
+ const KEEP_EVERY_MS = 60_000;
25
+ function ageOf(path, now) {
26
+ try {
27
+ return now - statSync(path).mtimeMs;
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ }
33
+ function breakStaleLock(lock, now) {
34
+ const breaker = `${lock}.break`;
35
+ if (!tryLock(breaker, now)) {
36
+ const age = ageOf(breaker, now);
37
+ if (age === null || age < BREAKER_STALE_MS)
38
+ return false;
39
+ rmSync(breaker, { force: true });
40
+ if (!tryLock(breaker, now))
41
+ return false;
42
+ }
43
+ try {
44
+ const age = ageOf(lock, now);
45
+ if (age !== null && age < STALE_LOCK_MS)
46
+ return false;
47
+ rmSync(lock, { force: true });
48
+ return tryLock(lock, now);
49
+ }
50
+ finally {
51
+ rmSync(breaker, { force: true });
52
+ }
53
+ }
23
54
  export function claimJob(job, key, now = Date.now()) {
24
55
  const lock = lockPath(job, key);
25
56
  mkdirSync(jobDir(job), { recursive: true });
26
57
  if (tryLock(lock, now))
27
58
  return true;
28
- let lockedAt;
29
- try {
30
- lockedAt = statSync(lock).mtimeMs;
31
- }
32
- catch {
59
+ const age = ageOf(lock, now);
60
+ if (age === null)
33
61
  return tryLock(lock, now);
34
- }
35
- if (now - lockedAt < STALE_LOCK_MS)
62
+ if (age < STALE_LOCK_MS)
36
63
  return false;
37
- rmSync(lock, { force: true });
38
- return tryLock(lock, now);
64
+ return breakStaleLock(lock, now);
65
+ }
66
+ export function keepJob(job, key) {
67
+ const lock = lockPath(job, key);
68
+ const timer = setInterval(() => {
69
+ try {
70
+ const at = new Date();
71
+ utimesSync(lock, at, at);
72
+ }
73
+ catch {
74
+ clearInterval(timer);
75
+ }
76
+ }, KEEP_EVERY_MS);
77
+ timer.unref();
78
+ return () => clearInterval(timer);
39
79
  }
40
80
  export function finishJob(job, key, mark) {
41
81
  mkdirSync(jobDir(job), { recursive: true });
@@ -76,6 +76,11 @@ claude-db use "postgres://user:pass@host:5432/memory"
76
76
  For MongoDB, install `mongodb` and use a `mongodb+srv://` address. Clones of one repository share
77
77
  memory by git remote, so every machine must run 0.11.0 or newer.
78
78
 
79
+ On a remote database each hook pays to start node, open a connection and load the embedding model before
80
+ it does any work, about a second in all. `claude-db daemon on` keeps one process warm that the hooks hand
81
+ their work to, so the next hooks skip that cost. It stops after 15 idle minutes (`daemon.idleMinutes`)
82
+ and starts again with the next hook. `claude-db daemon off` turns it off.
83
+
79
84
  ## Upgrading
80
85
 
81
86
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-db",
3
- "version": "0.12.4",
3
+ "version": "0.13.0",
4
4
  "description": "Free, open-source memory for Claude Code. Remembers why decisions were made and maps your code. Your own database (SQLite, Postgres or MongoDB), no cloud, no subscription.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -128,10 +128,10 @@
128
128
  "access": "public"
129
129
  },
130
130
  "optionalDependencies": {
131
- "claude-db-grammars-linux-x64": "0.12.4",
132
- "claude-db-grammars-linux-arm64": "0.12.4",
133
- "claude-db-grammars-darwin-x64": "0.12.4",
134
- "claude-db-grammars-darwin-arm64": "0.12.4",
135
- "claude-db-grammars-win32-x64": "0.12.4"
131
+ "claude-db-grammars-linux-x64": "0.13.0",
132
+ "claude-db-grammars-linux-arm64": "0.13.0",
133
+ "claude-db-grammars-darwin-x64": "0.13.0",
134
+ "claude-db-grammars-darwin-arm64": "0.13.0",
135
+ "claude-db-grammars-win32-x64": "0.13.0"
136
136
  }
137
137
  }