@getrift/rift 0.1.0-beta.0 → 0.1.0-beta.10

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 (202) hide show
  1. package/README.md +72 -48
  2. package/dist/src/auth/keychain.d.ts +9 -0
  3. package/dist/src/auth/keychain.d.ts.map +1 -1
  4. package/dist/src/auth/keychain.js +37 -0
  5. package/dist/src/auth/keychain.js.map +1 -1
  6. package/dist/src/capture/recover-quarantine.d.ts +221 -0
  7. package/dist/src/capture/recover-quarantine.d.ts.map +1 -0
  8. package/dist/src/capture/recover-quarantine.js +453 -0
  9. package/dist/src/capture/recover-quarantine.js.map +1 -0
  10. package/dist/src/cli/commands/backfill.d.ts.map +1 -1
  11. package/dist/src/cli/commands/backfill.js +5 -2
  12. package/dist/src/cli/commands/backfill.js.map +1 -1
  13. package/dist/src/cli/commands/capture-recover.d.ts +12 -0
  14. package/dist/src/cli/commands/capture-recover.d.ts.map +1 -0
  15. package/dist/src/cli/commands/capture-recover.js +120 -0
  16. package/dist/src/cli/commands/capture-recover.js.map +1 -0
  17. package/dist/src/cli/commands/capture.d.ts.map +1 -1
  18. package/dist/src/cli/commands/capture.js +10 -4
  19. package/dist/src/cli/commands/capture.js.map +1 -1
  20. package/dist/src/cli/commands/feedback.d.ts.map +1 -1
  21. package/dist/src/cli/commands/feedback.js +6 -2
  22. package/dist/src/cli/commands/feedback.js.map +1 -1
  23. package/dist/src/cli/commands/hooks-install.d.ts +19 -0
  24. package/dist/src/cli/commands/hooks-install.d.ts.map +1 -0
  25. package/dist/src/cli/commands/hooks-install.js +103 -0
  26. package/dist/src/cli/commands/hooks-install.js.map +1 -0
  27. package/dist/src/cli/commands/mcp-install.js +5 -2
  28. package/dist/src/cli/commands/mcp-install.js.map +1 -1
  29. package/dist/src/cli/commands/onboard.d.ts +24 -0
  30. package/dist/src/cli/commands/onboard.d.ts.map +1 -1
  31. package/dist/src/cli/commands/onboard.js +200 -21
  32. package/dist/src/cli/commands/onboard.js.map +1 -1
  33. package/dist/src/cli/commands/rebuild.d.ts.map +1 -1
  34. package/dist/src/cli/commands/rebuild.js +6 -3
  35. package/dist/src/cli/commands/rebuild.js.map +1 -1
  36. package/dist/src/cli/commands/review.d.ts.map +1 -1
  37. package/dist/src/cli/commands/review.js +22 -7
  38. package/dist/src/cli/commands/review.js.map +1 -1
  39. package/dist/src/cli/commands/status.d.ts.map +1 -1
  40. package/dist/src/cli/commands/status.js +48 -2
  41. package/dist/src/cli/commands/status.js.map +1 -1
  42. package/dist/src/cli/commands/token-issue.d.ts.map +1 -1
  43. package/dist/src/cli/commands/token-issue.js +9 -1
  44. package/dist/src/cli/commands/token-issue.js.map +1 -1
  45. package/dist/src/cli/commands/triage.d.ts.map +1 -1
  46. package/dist/src/cli/commands/triage.js +7 -5
  47. package/dist/src/cli/commands/triage.js.map +1 -1
  48. package/dist/src/cli/commands/update.d.ts +26 -0
  49. package/dist/src/cli/commands/update.d.ts.map +1 -0
  50. package/dist/src/cli/commands/update.js +130 -0
  51. package/dist/src/cli/commands/update.js.map +1 -0
  52. package/dist/src/cli/default-config-path.d.ts +15 -0
  53. package/dist/src/cli/default-config-path.d.ts.map +1 -0
  54. package/dist/src/cli/default-config-path.js +27 -0
  55. package/dist/src/cli/default-config-path.js.map +1 -0
  56. package/dist/src/cli/hooks-writers/claude-code-policy-script.d.ts +25 -0
  57. package/dist/src/cli/hooks-writers/claude-code-policy-script.d.ts.map +1 -0
  58. package/dist/src/cli/hooks-writers/claude-code-policy-script.js +85 -0
  59. package/dist/src/cli/hooks-writers/claude-code-policy-script.js.map +1 -0
  60. package/dist/src/cli/hooks-writers/claude-code.d.ts +12 -0
  61. package/dist/src/cli/hooks-writers/claude-code.d.ts.map +1 -0
  62. package/dist/src/cli/hooks-writers/claude-code.js +228 -0
  63. package/dist/src/cli/hooks-writers/claude-code.js.map +1 -0
  64. package/dist/src/cli/hooks-writers/errors.d.ts +16 -0
  65. package/dist/src/cli/hooks-writers/errors.d.ts.map +1 -0
  66. package/dist/src/cli/hooks-writers/errors.js +24 -0
  67. package/dist/src/cli/hooks-writers/errors.js.map +1 -0
  68. package/dist/src/cli/hooks-writers/index.d.ts +13 -0
  69. package/dist/src/cli/hooks-writers/index.d.ts.map +1 -0
  70. package/dist/src/cli/hooks-writers/index.js +26 -0
  71. package/dist/src/cli/hooks-writers/index.js.map +1 -0
  72. package/dist/src/cli/hooks-writers/types.d.ts +27 -0
  73. package/dist/src/cli/hooks-writers/types.d.ts.map +1 -0
  74. package/dist/src/cli/hooks-writers/types.js +9 -0
  75. package/dist/src/cli/hooks-writers/types.js.map +1 -0
  76. package/dist/src/cli/http-client.d.ts +56 -1
  77. package/dist/src/cli/http-client.d.ts.map +1 -1
  78. package/dist/src/cli/http-client.js +140 -4
  79. package/dist/src/cli/http-client.js.map +1 -1
  80. package/dist/src/cli/index.d.ts.map +1 -1
  81. package/dist/src/cli/index.js +27 -6
  82. package/dist/src/cli/index.js.map +1 -1
  83. package/dist/src/cli/status/friend-header.d.ts.map +1 -1
  84. package/dist/src/cli/status/friend-header.js +117 -7
  85. package/dist/src/cli/status/friend-header.js.map +1 -1
  86. package/dist/src/ingestion/inbox-core/conversation-key.d.ts +2 -0
  87. package/dist/src/ingestion/inbox-core/conversation-key.d.ts.map +1 -0
  88. package/dist/src/ingestion/inbox-core/conversation-key.js +31 -0
  89. package/dist/src/ingestion/inbox-core/conversation-key.js.map +1 -0
  90. package/dist/src/ingestion/inbox-core/extensions.d.ts +3 -0
  91. package/dist/src/ingestion/inbox-core/extensions.d.ts.map +1 -0
  92. package/dist/src/ingestion/inbox-core/extensions.js +16 -0
  93. package/dist/src/ingestion/inbox-core/extensions.js.map +1 -0
  94. package/dist/src/ingestion/inbox-core/idempotency.d.ts +2 -0
  95. package/dist/src/ingestion/inbox-core/idempotency.d.ts.map +1 -0
  96. package/dist/src/ingestion/inbox-core/idempotency.js +22 -0
  97. package/dist/src/ingestion/inbox-core/idempotency.js.map +1 -0
  98. package/dist/src/ingestion/inbox-core/index.d.ts +19 -0
  99. package/dist/src/ingestion/inbox-core/index.d.ts.map +1 -0
  100. package/dist/src/ingestion/inbox-core/index.js +19 -0
  101. package/dist/src/ingestion/inbox-core/index.js.map +1 -0
  102. package/dist/src/ingestion/inbox-core/source-detection.d.ts +2 -0
  103. package/dist/src/ingestion/inbox-core/source-detection.d.ts.map +1 -0
  104. package/dist/src/ingestion/inbox-core/source-detection.js +23 -0
  105. package/dist/src/ingestion/inbox-core/source-detection.js.map +1 -0
  106. package/dist/src/ingestion/inbox-core/source-sniffer.d.ts +11 -0
  107. package/dist/src/ingestion/inbox-core/source-sniffer.d.ts.map +1 -0
  108. package/dist/src/ingestion/inbox-core/source-sniffer.js +69 -0
  109. package/dist/src/ingestion/inbox-core/source-sniffer.js.map +1 -0
  110. package/dist/src/ingestion/inbox-core/zip-sniffer.d.ts +70 -0
  111. package/dist/src/ingestion/inbox-core/zip-sniffer.d.ts.map +1 -0
  112. package/dist/src/ingestion/inbox-core/zip-sniffer.js +161 -0
  113. package/dist/src/ingestion/inbox-core/zip-sniffer.js.map +1 -0
  114. package/dist/src/ingestion/inbox-watcher.d.ts.map +1 -1
  115. package/dist/src/ingestion/inbox-watcher.js +34 -50
  116. package/dist/src/ingestion/inbox-watcher.js.map +1 -1
  117. package/dist/src/ingestion/indexer.d.ts +7 -0
  118. package/dist/src/ingestion/indexer.d.ts.map +1 -1
  119. package/dist/src/ingestion/indexer.js +36 -2
  120. package/dist/src/ingestion/indexer.js.map +1 -1
  121. package/dist/src/ingestion/metadata-extraction.d.ts +8 -5
  122. package/dist/src/ingestion/metadata-extraction.d.ts.map +1 -1
  123. package/dist/src/ingestion/metadata-extraction.js +24 -5
  124. package/dist/src/ingestion/metadata-extraction.js.map +1 -1
  125. package/dist/src/ingestion/skip-quarantine.d.ts +10 -0
  126. package/dist/src/ingestion/skip-quarantine.d.ts.map +1 -0
  127. package/dist/src/ingestion/skip-quarantine.js +35 -0
  128. package/dist/src/ingestion/skip-quarantine.js.map +1 -0
  129. package/dist/src/jobs/handlers/compact.d.ts.map +1 -1
  130. package/dist/src/jobs/handlers/compact.js +25 -4
  131. package/dist/src/jobs/handlers/compact.js.map +1 -1
  132. package/dist/src/jobs/handlers/ingest.d.ts.map +1 -1
  133. package/dist/src/jobs/handlers/ingest.js +49 -24
  134. package/dist/src/jobs/handlers/ingest.js.map +1 -1
  135. package/dist/src/jobs/handlers/reconcile.d.ts.map +1 -1
  136. package/dist/src/jobs/handlers/reconcile.js +30 -8
  137. package/dist/src/jobs/handlers/reconcile.js.map +1 -1
  138. package/dist/src/jobs/handlers/reindex.d.ts.map +1 -1
  139. package/dist/src/jobs/handlers/reindex.js +12 -2
  140. package/dist/src/jobs/handlers/reindex.js.map +1 -1
  141. package/dist/src/jobs/handlers/save.d.ts.map +1 -1
  142. package/dist/src/jobs/handlers/save.js +9 -2
  143. package/dist/src/jobs/handlers/save.js.map +1 -1
  144. package/dist/src/jobs/queue.d.ts +11 -0
  145. package/dist/src/jobs/queue.d.ts.map +1 -1
  146. package/dist/src/jobs/queue.js +18 -0
  147. package/dist/src/jobs/queue.js.map +1 -1
  148. package/dist/src/jobs/worker-entry.d.ts.map +1 -1
  149. package/dist/src/jobs/worker-entry.js +2 -0
  150. package/dist/src/jobs/worker-entry.js.map +1 -1
  151. package/dist/src/main.js +36 -4
  152. package/dist/src/main.js.map +1 -1
  153. package/dist/src/observability/embedding-events.d.ts +52 -0
  154. package/dist/src/observability/embedding-events.d.ts.map +1 -0
  155. package/dist/src/observability/embedding-events.js +149 -0
  156. package/dist/src/observability/embedding-events.js.map +1 -0
  157. package/dist/src/observability/index-events.d.ts +70 -0
  158. package/dist/src/observability/index-events.d.ts.map +1 -0
  159. package/dist/src/observability/index-events.js +148 -0
  160. package/dist/src/observability/index-events.js.map +1 -0
  161. package/dist/src/observability/tool-usage-stats.d.ts +7 -0
  162. package/dist/src/observability/tool-usage-stats.d.ts.map +1 -1
  163. package/dist/src/observability/tool-usage-stats.js +41 -5
  164. package/dist/src/observability/tool-usage-stats.js.map +1 -1
  165. package/dist/src/observability/tool-usage.d.ts +7 -7
  166. package/dist/src/observability/tool-usage.d.ts.map +1 -1
  167. package/dist/src/observability/tool-usage.js +78 -39
  168. package/dist/src/observability/tool-usage.js.map +1 -1
  169. package/dist/src/observability/version-check.d.ts +70 -0
  170. package/dist/src/observability/version-check.d.ts.map +1 -0
  171. package/dist/src/observability/version-check.js +197 -0
  172. package/dist/src/observability/version-check.js.map +1 -0
  173. package/dist/src/providers/ollama-embed.d.ts +2 -1
  174. package/dist/src/providers/ollama-embed.d.ts.map +1 -1
  175. package/dist/src/providers/ollama-embed.js +1 -0
  176. package/dist/src/providers/ollama-embed.js.map +1 -1
  177. package/dist/src/providers/openai-metadata-extraction.d.ts +3 -3
  178. package/dist/src/providers/openai-metadata-extraction.d.ts.map +1 -1
  179. package/dist/src/providers/openai-metadata-extraction.js +18 -3
  180. package/dist/src/providers/openai-metadata-extraction.js.map +1 -1
  181. package/dist/src/providers/stub.d.ts +2 -0
  182. package/dist/src/providers/stub.d.ts.map +1 -1
  183. package/dist/src/providers/stub.js +2 -0
  184. package/dist/src/providers/stub.js.map +1 -1
  185. package/dist/src/providers/types.d.ts +11 -0
  186. package/dist/src/providers/types.d.ts.map +1 -1
  187. package/dist/src/providers/voyage.d.ts +2 -1
  188. package/dist/src/providers/voyage.d.ts.map +1 -1
  189. package/dist/src/providers/voyage.js +1 -0
  190. package/dist/src/providers/voyage.js.map +1 -1
  191. package/dist/src/server/app.d.ts.map +1 -1
  192. package/dist/src/server/app.js +67 -1
  193. package/dist/src/server/app.js.map +1 -1
  194. package/dist/src/server/routes/friend-status.d.ts +202 -3
  195. package/dist/src/server/routes/friend-status.d.ts.map +1 -1
  196. package/dist/src/server/routes/friend-status.js +290 -7
  197. package/dist/src/server/routes/friend-status.js.map +1 -1
  198. package/dist/src/storage/rebuild.d.ts +14 -1
  199. package/dist/src/storage/rebuild.d.ts.map +1 -1
  200. package/dist/src/storage/rebuild.js +160 -34
  201. package/dist/src/storage/rebuild.js.map +1 -1
  202. package/package.json +1 -1
@@ -2,6 +2,13 @@ import { getBuildInfo } from "../build-info.js";
2
2
  import { readAutoCaptureRunSummary, } from "../../capture/observability.js";
3
3
  import { loadFeedbackConfig } from "../../cli/feedback/feedback-config.js";
4
4
  import { sanitizeProjectLabel } from "../../runtime/legacy-name-guard.js";
5
+ import { readEmbeddingEvents, } from "../../observability/embedding-events.js";
6
+ import { readIndexEvents, } from "../../observability/index-events.js";
7
+ import { compareBetaVersions, readVersionCheck, } from "../../observability/version-check.js";
8
+ const VOYAGE_ERROR_LOOKBACK_MS = 24 * 60 * 60 * 1000;
9
+ const INDEX_ERROR_LOOKBACK_MS = 24 * 60 * 60 * 1000;
10
+ const INBOX_ERROR_LOOKBACK_MS = 24 * 60 * 60 * 1000;
11
+ const INBOX_IDEMPOTENCY_PREFIX = "inbox:";
5
12
  export function buildFriendStatusPayload(deps) {
6
13
  const build = getBuildInfo();
7
14
  const voyageKey = process.env["VOYAGE_API_KEY"];
@@ -24,12 +31,9 @@ export function buildFriendStatusPayload(deps) {
24
31
  captureTotals.quarantined += counts.quarantined ?? 0;
25
32
  }
26
33
  }
27
- let lastEmbedAt = null;
28
- for (const success of Object.values(summary.last_success_by_source)) {
29
- if (success && (!lastEmbedAt || success.timestamp > lastEmbedAt)) {
30
- lastEmbedAt = success.timestamp;
31
- }
32
- }
34
+ const voyageHealth = computeVoyageHealth(dataDir, Date.now());
35
+ const indexHealth = computeIndexHealth(dataDir, Date.now());
36
+ const inboxHealth = computeInboxHealth(deps.jobQueue, Date.now());
33
37
  let relayEnabled = false;
34
38
  try {
35
39
  relayEnabled = loadFeedbackConfig(dataDir).enabled === true;
@@ -43,11 +47,20 @@ export function buildFriendStatusPayload(deps) {
43
47
  uptime_seconds: Math.floor((Date.now() - deps.startTime) / 1000),
44
48
  port: deps.config.server.port,
45
49
  voyage_key_present: typeof voyageKey === "string" && voyageKey.length > 0,
50
+ data_dir: dataDir,
46
51
  },
47
52
  voyage: {
48
53
  project_label: sanitizeProjectLabel(deps.config.voyage?.project_label),
49
- last_embed_at: lastEmbedAt,
54
+ last_embed_at: voyageHealth.last_embed_at,
55
+ last_error_at: voyageHealth.last_error_at,
56
+ last_error_reason: voyageHealth.last_error_reason,
57
+ },
58
+ index: {
59
+ last_update_at: indexHealth.last_update_at,
60
+ last_error_at: indexHealth.last_error_at,
61
+ last_error_reason: indexHealth.last_error_reason,
50
62
  },
63
+ inbox: inboxHealth,
51
64
  codex: {
52
65
  last_preflight_at: last?.timestamp ?? null,
53
66
  last_preflight_ok: last ? last.preflight_ok : null,
@@ -59,10 +72,280 @@ export function buildFriendStatusPayload(deps) {
59
72
  last_review: captureTotals.review,
60
73
  last_errors: last?.errors.length ?? 0,
61
74
  last_quarantined: captureTotals.quarantined,
75
+ next_run_at: computeNextCaptureRunAt({
76
+ captureEnabled: deps.config.capture.enabled,
77
+ intervalSeconds: deps.config.capture.interval_seconds,
78
+ startTime: deps.startTime,
79
+ now: Date.now(),
80
+ }),
62
81
  },
63
82
  feedback: { relay_enabled: relayEnabled },
83
+ update: computeUpdateProjection(dataDir, build.version),
84
+ };
85
+ }
86
+ /**
87
+ * Project the version-check snapshot to the three fields the renderer
88
+ * needs. A missing snapshot, a failed probe, or an up-to-date install
89
+ * all return `available: false` — the renderer prints nothing in those
90
+ * cases, so an unreachable npm registry can never make Rift look broken.
91
+ *
92
+ * Exported for tests.
93
+ */
94
+ export function computeUpdateProjection(dataDir, installedVersion) {
95
+ const snapshot = readVersionCheck(dataDir);
96
+ if (!snapshot || snapshot.latest_beta === null) {
97
+ return {
98
+ available: false,
99
+ installed: installedVersion,
100
+ latest_beta: snapshot?.latest_beta ?? null,
101
+ checked_at: snapshot?.checked_at ?? null,
102
+ };
103
+ }
104
+ // Use the installedVersion from the live build, not the snapshot, so a
105
+ // post-update daemon restart immediately reports `available: false`
106
+ // even before the next probe writes a fresh snapshot.
107
+ const available = compareBetaVersions(installedVersion, snapshot.latest_beta) < 0;
108
+ return {
109
+ available,
110
+ installed: installedVersion,
111
+ latest_beta: snapshot.latest_beta,
112
+ checked_at: snapshot.checked_at,
113
+ };
114
+ }
115
+ /**
116
+ * Compute the next auto-capture tick.
117
+ *
118
+ * The daemon registers `setInterval(runCapture, intervalMs)` at startup
119
+ * (`src/main.ts`), so ticks land at `startTime + N * intervalMs` for
120
+ * N ≥ 1 (N = 0 is the eager startup call). We deliberately anchor to
121
+ * `startTime` rather than `last_run_at` because:
122
+ * - `setInterval` does, so this matches what will actually fire.
123
+ * - `last_run_at` lags by hundreds of ms (save-job wait), and could
124
+ * be stale from a prior daemon process for the first interval after
125
+ * a restart.
126
+ *
127
+ * Returns null when auto-capture is disabled in config.
128
+ *
129
+ * Exported for tests.
130
+ */
131
+ export function computeNextCaptureRunAt(opts) {
132
+ if (!opts.captureEnabled)
133
+ return null;
134
+ if (opts.intervalSeconds <= 0)
135
+ return null;
136
+ const intervalMs = opts.intervalSeconds * 1000;
137
+ const elapsed = Math.max(0, opts.now - opts.startTime);
138
+ const ticksElapsed = Math.floor(elapsed / intervalMs);
139
+ return new Date(opts.startTime + (ticksElapsed + 1) * intervalMs).toISOString();
140
+ }
141
+ /**
142
+ * Reduce the embedding-events lane to the three voyage health fields the
143
+ * friend-status route needs.
144
+ *
145
+ * Exported for tests so we can verify the pipeline-filter and 24h-window
146
+ * logic without booting Fastify or stubbing the route layer.
147
+ */
148
+ export function computeVoyageHealth(dataDir, now) {
149
+ let events;
150
+ try {
151
+ events = readEmbeddingEvents(dataDir);
152
+ }
153
+ catch {
154
+ events = [];
155
+ }
156
+ let lastSuccessTs = null;
157
+ let lastErrorTs = null;
158
+ let lastErrorReason = null;
159
+ const errorCutoff = now - VOYAGE_ERROR_LOOKBACK_MS;
160
+ for (const event of events) {
161
+ // The `voyage.*` projection must reflect Voyage health only. The lane
162
+ // itself is provider-agnostic so a future Ollama-only install reuses
163
+ // the same writer, but on a mixed cloud+local install an Ollama
164
+ // success would otherwise refresh `voyage.last_embed_at` and mask a
165
+ // Voyage outage. Filter at projection time, not write time.
166
+ if (event.provider !== "voyage")
167
+ continue;
168
+ if (event.outcome === "success") {
169
+ if (!lastSuccessTs || event.ts > lastSuccessTs) {
170
+ lastSuccessTs = event.ts;
171
+ }
172
+ continue;
173
+ }
174
+ // outcome === "error"
175
+ const eventTime = Date.parse(event.ts);
176
+ if (Number.isNaN(eventTime) || eventTime < errorCutoff)
177
+ continue;
178
+ if (!lastErrorTs || event.ts > lastErrorTs) {
179
+ lastErrorTs = event.ts;
180
+ lastErrorReason = event.error_class ?? "unknown";
181
+ }
182
+ }
183
+ return {
184
+ last_embed_at: lastSuccessTs,
185
+ last_error_at: lastErrorTs,
186
+ last_error_reason: lastErrorReason,
64
187
  };
65
188
  }
189
+ /**
190
+ * Reduce the index-events lane to the three index health fields the
191
+ * friend-status route needs. Provider-agnostic and table-agnostic: an
192
+ * embed can succeed but the subsequent `table.add(...)` can fail, and
193
+ * `index.*` is what makes that visible. No 24h filter on `last_update_at`
194
+ * (a daemon that has not indexed in 7 days should still surface the
195
+ * stale timestamp); errors are filtered to the 24h window so old
196
+ * resolved incidents don't sit on the dashboard forever.
197
+ */
198
+ export function computeIndexHealth(dataDir, now) {
199
+ let events;
200
+ try {
201
+ events = readIndexEvents(dataDir);
202
+ }
203
+ catch {
204
+ events = [];
205
+ }
206
+ let lastSuccessTs = null;
207
+ let lastErrorTs = null;
208
+ let lastErrorReason = null;
209
+ const errorCutoff = now - INDEX_ERROR_LOOKBACK_MS;
210
+ for (const event of events) {
211
+ if (event.outcome === "success") {
212
+ // Shadow-phase successes do NOT credit `last_update_at`: a row
213
+ // written to a shadow table is "prepared", not "searchable",
214
+ // until `commitAllSwaps` runs. If the swap rolls back, those
215
+ // rows stay invisible — so claiming a fresh index from them
216
+ // would lie. The post-commit "live" event is what credits the
217
+ // real update timestamp.
218
+ const phase = event.phase ?? "live";
219
+ if (phase !== "live")
220
+ continue;
221
+ if (!lastSuccessTs || event.ts > lastSuccessTs) {
222
+ lastSuccessTs = event.ts;
223
+ }
224
+ continue;
225
+ }
226
+ // Errors at any phase (including shadow) count toward
227
+ // `last_error_at` — a per-row LanceDB write failure during shadow
228
+ // population is a real failure regardless of the eventual swap.
229
+ const eventTime = Date.parse(event.ts);
230
+ if (Number.isNaN(eventTime) || eventTime < errorCutoff)
231
+ continue;
232
+ if (!lastErrorTs || event.ts > lastErrorTs) {
233
+ lastErrorTs = event.ts;
234
+ lastErrorReason = event.error_class ?? "unknown";
235
+ }
236
+ }
237
+ return {
238
+ last_update_at: lastSuccessTs,
239
+ last_error_at: lastErrorTs,
240
+ last_error_reason: lastErrorReason,
241
+ };
242
+ }
243
+ /**
244
+ * Reduce the inbox-keyed job set to the four fields the friend-status
245
+ * route needs. Pure over the queue's snapshot (no I/O), so tests can
246
+ * pass an in-memory `JobQueue` without booting Fastify.
247
+ *
248
+ * When the queue isn't wired up (deps.jobQueue undefined), this
249
+ * returns the empty / idle shape — the renderer treats it the same
250
+ * as "nothing dropped yet."
251
+ *
252
+ * Exported for tests.
253
+ */
254
+ export function computeInboxHealth(queue, now) {
255
+ if (!queue) {
256
+ return {
257
+ last_import_at: null,
258
+ last_error_at: null,
259
+ last_error_reason: null,
260
+ pending: 0,
261
+ };
262
+ }
263
+ const jobs = queue.listByIdempotencyPrefix(INBOX_IDEMPOTENCY_PREFIX);
264
+ let lastImportTs = null;
265
+ let lastErrorTs = null;
266
+ let lastErrorReason = null;
267
+ let pending = 0;
268
+ const errorCutoff = now - INBOX_ERROR_LOOKBACK_MS;
269
+ for (const job of jobs) {
270
+ // Skip superseded jobs — the queue chains a retry by setting
271
+ // `retried_by` on the failed/completed parent and creating a fresh
272
+ // job with the same idempotency key. Counting both would let a
273
+ // long-resolved failure keep the "Inbox import errors" hint live
274
+ // for 24h after the retry already succeeded; the leaf is the only
275
+ // entry that reflects current state. (Same invariant the queue
276
+ // itself enforces in `findByIdempotencyKey`.)
277
+ if (job.retried_by !== undefined)
278
+ continue;
279
+ if (job.status === "queued" || job.status === "running") {
280
+ pending++;
281
+ continue;
282
+ }
283
+ if (job.status === "completed") {
284
+ if (!lastImportTs || job.updated_at > lastImportTs) {
285
+ lastImportTs = job.updated_at;
286
+ }
287
+ continue;
288
+ }
289
+ if (job.status === "failed") {
290
+ const eventTime = Date.parse(job.updated_at);
291
+ if (Number.isNaN(eventTime) || eventTime < errorCutoff)
292
+ continue;
293
+ if (!lastErrorTs || job.updated_at > lastErrorTs) {
294
+ lastErrorTs = job.updated_at;
295
+ lastErrorReason = classifyJobError(job);
296
+ }
297
+ }
298
+ // cancelled / interrupted: ignore — neither a successful import
299
+ // nor a real error the user can act on. A retry will be either
300
+ // queued (counted as pending) or completed/failed (counted above).
301
+ }
302
+ return {
303
+ last_import_at: lastImportTs,
304
+ last_error_at: lastErrorTs,
305
+ last_error_reason: lastErrorReason,
306
+ pending,
307
+ };
308
+ }
309
+ /**
310
+ * Best-effort short label for a failed inbox job's error. The queue
311
+ * stores the raw error message (`job.error`); we collapse it into a
312
+ * compact class keyword by substring match against the parser errors
313
+ * we know about, then fall back to a truncated form of the original
314
+ * message. Lower-cased for stability under capitalization drift.
315
+ *
316
+ * Exported for tests.
317
+ */
318
+ export function classifyJobError(job) {
319
+ const raw = (job.error ?? "").trim();
320
+ if (!raw)
321
+ return "unknown";
322
+ const lower = raw.toLowerCase();
323
+ if (lower.includes("zip slip") || lower.includes("path traversal")) {
324
+ return "unsafe_archive";
325
+ }
326
+ if (lower.includes("too large") || lower.includes("max size")) {
327
+ return "size_limit";
328
+ }
329
+ if (lower.includes("unsupported source"))
330
+ return "unsupported_source";
331
+ if (lower.includes("no conversations"))
332
+ return "empty_export";
333
+ if (lower.includes("invalid json") || lower.includes("unexpected token")) {
334
+ return "invalid_json";
335
+ }
336
+ // ADM-ZIP throws strings like "ADM-ZIP: Invalid or unsupported zip
337
+ // format" when adm-zip can't open the archive at all (corrupt header,
338
+ // truncated CD). Distinct from `unsafe_archive` (security-blocked) —
339
+ // this is "the ZIP itself is broken before we can even look inside."
340
+ if (lower.includes("adm-zip") || lower.includes("invalid or unsupported zip")) {
341
+ return "invalid_archive";
342
+ }
343
+ if (lower.includes("parser"))
344
+ return "parser_error";
345
+ // Fallback: first ≤40 chars of the raw message, single-lined.
346
+ const snippet = raw.replace(/\s+/g, " ").slice(0, 40);
347
+ return snippet || "unknown";
348
+ }
66
349
  export function registerFriendStatusRoute(server, deps) {
67
350
  server.get("/status/friend", async (_request, reply) => {
68
351
  return reply.send(buildFriendStatusPayload(deps));
@@ -1 +1 @@
1
- {"version":3,"file":"friend-status.js","sourceRoot":"","sources":["../../../../src/server/routes/friend-status.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EACL,yBAAyB,GAE1B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AA2D1E,MAAM,UAAU,wBAAwB,CACtC,IAAsB;IAEtB,MAAM,KAAK,GAAG,YAAY,EAAE,CAAC;IAC7B,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC;IAEhD,IAAI,OAAO,CAAC;IACZ,IAAI,CAAC;QACH,OAAO,GAAG,yBAAyB,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5E,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,sBAAsB,EAAE,EAAE,EAAE,CAAC;IAC3D,CAAC;IACD,MAAM,IAAI,GAAgC,OAAO,CAAC,QAAQ,CAAC;IAE3D,IAAI,aAAa,GAAG,EAAE,KAAK,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D,mEAAmE;IACnE,sEAAsE;IACtE,qEAAqE;IACrE,qEAAqE;IACrE,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,4BAA4B,CAAC,EAAE,CAAC;QAC9E,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,cAAc,CAAC;IACpD,8DAA8D;IAC9D,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACtD,OAAO,OAAO,IAAI,SAAS,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,MAAuB,EACvB,IAAsB;IAEtB,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;QACrD,OAAO,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -26,7 +26,20 @@ export interface ReembedOptions {
26
26
  config?: Config;
27
27
  localEmbeddingProvider?: EmbeddingProvider;
28
28
  }
29
- export declare function reembed(embeddingProvider: EmbeddingProvider, scope: ReindexScope, config?: Config, localEmbeddingProvider?: EmbeddingProvider): Promise<number>;
29
+ export declare function reembed(embeddingProvider: EmbeddingProvider, scope: ReindexScope, dataDir: string, config?: Config, localEmbeddingProvider?: EmbeddingProvider): Promise<number>;
30
+ /**
31
+ * Remove structured-doc rows whose source file no longer exists on disk.
32
+ * Scoped to filesystem-sourced rows (watched + scheduled_scan).
33
+ *
34
+ * Why: deletions between scheduled scans (or while a watcher is offline)
35
+ * leave ghost rows in the index, so search can return content that no
36
+ * longer exists. This pass closes that gap.
37
+ *
38
+ * Safety: skips rows whose owning source root is unreachable, so an
39
+ * unmounted drive cannot trigger mass deletion. If `config` is omitted
40
+ * the function still runs, but without the unmounted-root guard.
41
+ */
42
+ export declare function removeStructuredDocOrphans(dataDir: string, config?: Config): Promise<number>;
30
43
  export declare function extractIdFromFilename(filename: string): string | undefined;
31
44
  /**
32
45
  * Extract the ISO timestamp from a raw conversation filename.
@@ -1 +1 @@
1
- {"version":3,"file":"rebuild.d.ts","sourceRoot":"","sources":["../../../src/storage/rebuild.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAM/D,OAAO,KAAK,EAIV,SAAS,EACV,MAAM,aAAa,CAAC;AAMrB,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,sBAAsB,CAAC,EAAE,iBAAiB,CAAC;CAC5C;AAED,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,SAAS,EAAE,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAoB3E;AAuMD,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,eAAe,GAAG,WAAW,GAAG,iBAAiB,CAAC;AAErF,MAAM,WAAW,cAAc;IAC7B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,KAAK,EAAE,YAAY,CAAC;IACpB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sBAAsB,CAAC,EAAE,iBAAiB,CAAC;CAC5C;AAED,wBAAsB,OAAO,CAC3B,iBAAiB,EAAE,iBAAiB,EACpC,KAAK,EAAE,YAAY,EACnB,MAAM,CAAC,EAAE,MAAM,EACf,sBAAsB,CAAC,EAAE,iBAAiB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