nox-mem 3.0.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 (457) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +179 -0
  3. package/dist/api/answer.d.ts +116 -0
  4. package/dist/api/answer.js +274 -0
  5. package/dist/api/answer.validate-patch.d.ts +72 -0
  6. package/dist/api/answer.validate-patch.js +52 -0
  7. package/dist/api/brief-diversity.d.ts +64 -0
  8. package/dist/api/brief-diversity.js +91 -0
  9. package/dist/api/brief.d.ts +114 -0
  10. package/dist/api/brief.js +524 -0
  11. package/dist/api/conflict.d.ts +33 -0
  12. package/dist/api/conflict.js +143 -0
  13. package/dist/api/cors.d.ts +73 -0
  14. package/dist/api/cors.js +124 -0
  15. package/dist/api/events-stream-limited.d.ts +133 -0
  16. package/dist/api/events-stream-limited.js +217 -0
  17. package/dist/api/events-stream.d.ts +53 -0
  18. package/dist/api/events-stream.js +125 -0
  19. package/dist/api/export.d.ts +42 -0
  20. package/dist/api/export.js +85 -0
  21. package/dist/api/health-confidence-adapter.d.ts +29 -0
  22. package/dist/api/health-confidence-adapter.js +73 -0
  23. package/dist/api/health-confidence.d.ts +36 -0
  24. package/dist/api/health-confidence.js +141 -0
  25. package/dist/api/hooks.d.ts +50 -0
  26. package/dist/api/hooks.js +115 -0
  27. package/dist/api/import.d.ts +38 -0
  28. package/dist/api/import.js +87 -0
  29. package/dist/api/ingest-event.d.ts +65 -0
  30. package/dist/api/ingest-event.js +153 -0
  31. package/dist/api/mark.d.ts +42 -0
  32. package/dist/api/mark.js +127 -0
  33. package/dist/api/server-deps-a2.d.ts +55 -0
  34. package/dist/api/server-deps-a2.js +138 -0
  35. package/dist/api/server-deps-l2-l3.d.ts +68 -0
  36. package/dist/api/server-deps-l2-l3.js +123 -0
  37. package/dist/api/server-deps-p1.d.ts +84 -0
  38. package/dist/api/server-deps-p1.js +156 -0
  39. package/dist/api/server-deps-p2.d.ts +32 -0
  40. package/dist/api/server-deps-p2.js +84 -0
  41. package/dist/api/server-deps-p5.d.ts +66 -0
  42. package/dist/api/server-deps-p5.js +139 -0
  43. package/dist/api/viewer-static.d.ts +30 -0
  44. package/dist/api/viewer-static.js +102 -0
  45. package/dist/api/wire-up.d.ts +54 -0
  46. package/dist/api/wire-up.js +521 -0
  47. package/dist/api-impact.d.ts +30 -0
  48. package/dist/api-impact.js +196 -0
  49. package/dist/api-server.d.ts +2 -0
  50. package/dist/api-server.js +614 -0
  51. package/dist/backfill-fts-anchor.d.ts +15 -0
  52. package/dist/backfill-fts-anchor.js +97 -0
  53. package/dist/backfill-source-type.d.ts +20 -0
  54. package/dist/backfill-source-type.js +182 -0
  55. package/dist/churn.d.ts +31 -0
  56. package/dist/churn.js +98 -0
  57. package/dist/cli/answer.d.ts +66 -0
  58. package/dist/cli/answer.js +287 -0
  59. package/dist/cli/conflict.d.ts +38 -0
  60. package/dist/cli/conflict.js +282 -0
  61. package/dist/cli/export.d.ts +51 -0
  62. package/dist/cli/export.js +280 -0
  63. package/dist/cli/hooks.d.ts +54 -0
  64. package/dist/cli/hooks.js +133 -0
  65. package/dist/cli/import.d.ts +52 -0
  66. package/dist/cli/import.js +274 -0
  67. package/dist/cli/mark.d.ts +33 -0
  68. package/dist/cli/mark.js +130 -0
  69. package/dist/cli/ocr-batch.d.ts +12 -0
  70. package/dist/cli/ocr-batch.js +411 -0
  71. package/dist/cli/snapshot-main.d.ts +30 -0
  72. package/dist/cli/snapshot-main.js +47 -0
  73. package/dist/cli/viewer.d.ts +35 -0
  74. package/dist/cli/viewer.js +71 -0
  75. package/dist/cli-telemetry.d.ts +36 -0
  76. package/dist/cli-telemetry.js +150 -0
  77. package/dist/compact.d.ts +7 -0
  78. package/dist/compact.js +147 -0
  79. package/dist/consolidate.d.ts +18 -0
  80. package/dist/consolidate.js +475 -0
  81. package/dist/consolidation.d.ts +32 -0
  82. package/dist/consolidation.js +212 -0
  83. package/dist/cross-agent-v2.d.ts +45 -0
  84. package/dist/cross-agent-v2.js +271 -0
  85. package/dist/cross-search.d.ts +11 -0
  86. package/dist/cross-search.js +119 -0
  87. package/dist/crystallize.d.ts +43 -0
  88. package/dist/crystallize.js +111 -0
  89. package/dist/db.d.ts +11 -0
  90. package/dist/db.js +388 -0
  91. package/dist/dedup.d.ts +1 -0
  92. package/dist/dedup.js +106 -0
  93. package/dist/detect-changes.d.ts +29 -0
  94. package/dist/detect-changes.js +236 -0
  95. package/dist/digest.d.ts +1 -0
  96. package/dist/digest.js +205 -0
  97. package/dist/doctor.d.ts +1 -0
  98. package/dist/doctor.js +71 -0
  99. package/dist/embed.d.ts +45 -0
  100. package/dist/embed.js +257 -0
  101. package/dist/evals.d.ts +176 -0
  102. package/dist/evals.js +351 -0
  103. package/dist/generate-user-profile.d.ts +18 -0
  104. package/dist/generate-user-profile.js +163 -0
  105. package/dist/graphify-ingest.d.ts +18 -0
  106. package/dist/graphify-ingest.js +158 -0
  107. package/dist/impact.d.ts +39 -0
  108. package/dist/impact.js +143 -0
  109. package/dist/index.d.ts +2 -0
  110. package/dist/index.js +689 -0
  111. package/dist/ingest-entity.d.ts +44 -0
  112. package/dist/ingest-entity.js +197 -0
  113. package/dist/ingest.d.ts +13 -0
  114. package/dist/ingest.js +210 -0
  115. package/dist/kg-llm.d.ts +39 -0
  116. package/dist/kg-llm.js +295 -0
  117. package/dist/knowledge-graph.d.ts +72 -0
  118. package/dist/knowledge-graph.js +507 -0
  119. package/dist/lib/answer/config.d.ts +41 -0
  120. package/dist/lib/answer/config.js +70 -0
  121. package/dist/lib/answer/index.d.ts +47 -0
  122. package/dist/lib/answer/index.js +221 -0
  123. package/dist/lib/answer/prompt.d.ts +37 -0
  124. package/dist/lib/answer/prompt.js +88 -0
  125. package/dist/lib/answer/provider.d.ts +47 -0
  126. package/dist/lib/answer/provider.js +101 -0
  127. package/dist/lib/answer/retrieval.d.ts +36 -0
  128. package/dist/lib/answer/retrieval.js +92 -0
  129. package/dist/lib/answer/telemetry.d.ts +99 -0
  130. package/dist/lib/answer/telemetry.js +154 -0
  131. package/dist/lib/answer/types.d.ts +108 -0
  132. package/dist/lib/answer/types.js +1 -0
  133. package/dist/lib/api/error-leak-fix.d.ts +54 -0
  134. package/dist/lib/api/error-leak-fix.js +55 -0
  135. package/dist/lib/api/safe-error-message.d.ts +70 -0
  136. package/dist/lib/api/safe-error-message.js +122 -0
  137. package/dist/lib/archive/common-passwords.d.ts +37 -0
  138. package/dist/lib/archive/common-passwords.js +753 -0
  139. package/dist/lib/archive/encryption.d.ts +81 -0
  140. package/dist/lib/archive/encryption.js +236 -0
  141. package/dist/lib/archive/enforce-strength.d.ts +54 -0
  142. package/dist/lib/archive/enforce-strength.js +70 -0
  143. package/dist/lib/archive/entropy.d.ts +34 -0
  144. package/dist/lib/archive/entropy.js +180 -0
  145. package/dist/lib/archive/export-locking.d.ts +102 -0
  146. package/dist/lib/archive/export-locking.js +202 -0
  147. package/dist/lib/archive/format.d.ts +20 -0
  148. package/dist/lib/archive/format.js +174 -0
  149. package/dist/lib/archive/index.d.ts +23 -0
  150. package/dist/lib/archive/index.js +17 -0
  151. package/dist/lib/archive/manifest.d.ts +53 -0
  152. package/dist/lib/archive/manifest.js +183 -0
  153. package/dist/lib/archive/migration.d.ts +36 -0
  154. package/dist/lib/archive/migration.js +100 -0
  155. package/dist/lib/archive/migrations/v18_to_v19.d.ts +16 -0
  156. package/dist/lib/archive/migrations/v18_to_v19.js +18 -0
  157. package/dist/lib/archive/orchestrator.d.ts +166 -0
  158. package/dist/lib/archive/orchestrator.js +428 -0
  159. package/dist/lib/archive/serializers/chunks.d.ts +30 -0
  160. package/dist/lib/archive/serializers/chunks.js +113 -0
  161. package/dist/lib/archive/serializers/embeddings.d.ts +36 -0
  162. package/dist/lib/archive/serializers/embeddings.js +115 -0
  163. package/dist/lib/archive/serializers/kg.d.ts +28 -0
  164. package/dist/lib/archive/serializers/kg.js +184 -0
  165. package/dist/lib/archive/serializers/ops_audit.d.ts +21 -0
  166. package/dist/lib/archive/serializers/ops_audit.js +97 -0
  167. package/dist/lib/archive/server-deps.d.ts +131 -0
  168. package/dist/lib/archive/server-deps.js +232 -0
  169. package/dist/lib/archive/strength.d.ts +50 -0
  170. package/dist/lib/archive/strength.js +77 -0
  171. package/dist/lib/archive/types.d.ts +159 -0
  172. package/dist/lib/archive/types.js +45 -0
  173. package/dist/lib/archive/unpack-streaming.d.ts +70 -0
  174. package/dist/lib/archive/unpack-streaming.js +255 -0
  175. package/dist/lib/auth/localhost-guard.d.ts +106 -0
  176. package/dist/lib/auth/localhost-guard.js +164 -0
  177. package/dist/lib/confidence/config.d.ts +37 -0
  178. package/dist/lib/confidence/config.js +107 -0
  179. package/dist/lib/confidence/db-shim-singleton.d.ts +20 -0
  180. package/dist/lib/confidence/db-shim-singleton.js +41 -0
  181. package/dist/lib/confidence/db-shim.d.ts +47 -0
  182. package/dist/lib/confidence/db-shim.js +141 -0
  183. package/dist/lib/confidence/mark.d.ts +58 -0
  184. package/dist/lib/confidence/mark.js +168 -0
  185. package/dist/lib/confidence/ranking.d.ts +69 -0
  186. package/dist/lib/confidence/ranking.js +101 -0
  187. package/dist/lib/confidence/search-filter.d.ts +44 -0
  188. package/dist/lib/confidence/search-filter.js +103 -0
  189. package/dist/lib/confidence/types.d.ts +146 -0
  190. package/dist/lib/confidence/types.js +20 -0
  191. package/dist/lib/confidence/write-hooks.d.ts +50 -0
  192. package/dist/lib/confidence/write-hooks.js +159 -0
  193. package/dist/lib/conflict/audit-fk-check.d.ts +72 -0
  194. package/dist/lib/conflict/audit-fk-check.js +131 -0
  195. package/dist/lib/conflict/audit-writer.d.ts +39 -0
  196. package/dist/lib/conflict/audit-writer.js +133 -0
  197. package/dist/lib/conflict/db-singleton.d.ts +28 -0
  198. package/dist/lib/conflict/db-singleton.js +61 -0
  199. package/dist/lib/conflict/db.d.ts +27 -0
  200. package/dist/lib/conflict/db.js +20 -0
  201. package/dist/lib/conflict/detector-direct.d.ts +21 -0
  202. package/dist/lib/conflict/detector-direct.js +105 -0
  203. package/dist/lib/conflict/evidence.d.ts +24 -0
  204. package/dist/lib/conflict/evidence.js +76 -0
  205. package/dist/lib/conflict/index.d.ts +14 -0
  206. package/dist/lib/conflict/index.js +12 -0
  207. package/dist/lib/conflict/scheduler.d.ts +78 -0
  208. package/dist/lib/conflict/scheduler.js +111 -0
  209. package/dist/lib/conflict/shadow.d.ts +75 -0
  210. package/dist/lib/conflict/shadow.js +161 -0
  211. package/dist/lib/conflict/types.d.ts +133 -0
  212. package/dist/lib/conflict/types.js +19 -0
  213. package/dist/lib/cost-cap.d.ts +94 -0
  214. package/dist/lib/cost-cap.js +129 -0
  215. package/dist/lib/deps/deps-registry.d.ts +111 -0
  216. package/dist/lib/deps/deps-registry.js +209 -0
  217. package/dist/lib/error-sanitizer/middleware.d.ts +43 -0
  218. package/dist/lib/error-sanitizer/middleware.js +100 -0
  219. package/dist/lib/error-sanitizer/sanitize.d.ts +78 -0
  220. package/dist/lib/error-sanitizer/sanitize.js +202 -0
  221. package/dist/lib/eval-batch.d.ts +34 -0
  222. package/dist/lib/eval-batch.js +103 -0
  223. package/dist/lib/eval-metrics.d.ts +36 -0
  224. package/dist/lib/eval-metrics.js +95 -0
  225. package/dist/lib/eval.d.ts +106 -0
  226. package/dist/lib/eval.js +343 -0
  227. package/dist/lib/events/bus.d.ts +135 -0
  228. package/dist/lib/events/bus.js +95 -0
  229. package/dist/lib/fts-anchor.d.ts +1 -0
  230. package/dist/lib/fts-anchor.js +131 -0
  231. package/dist/lib/hooks/classifier.d.ts +47 -0
  232. package/dist/lib/hooks/classifier.js +129 -0
  233. package/dist/lib/hooks/config.d.ts +49 -0
  234. package/dist/lib/hooks/config.js +106 -0
  235. package/dist/lib/hooks/decorators.d.ts +35 -0
  236. package/dist/lib/hooks/decorators.js +59 -0
  237. package/dist/lib/hooks/pipeline.d.ts +76 -0
  238. package/dist/lib/hooks/pipeline.js +213 -0
  239. package/dist/lib/hooks/privacy-filter-adapter.d.ts +55 -0
  240. package/dist/lib/hooks/privacy-filter-adapter.js +84 -0
  241. package/dist/lib/hooks/rate-limit-constant-time.d.ts +57 -0
  242. package/dist/lib/hooks/rate-limit-constant-time.js +69 -0
  243. package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +71 -0
  244. package/dist/lib/hooks/rate-limit-dryrun-fix.js +110 -0
  245. package/dist/lib/hooks/rate-limit.d.ts +54 -0
  246. package/dist/lib/hooks/rate-limit.js +122 -0
  247. package/dist/lib/hooks/server-deps.d.ts +61 -0
  248. package/dist/lib/hooks/server-deps.js +92 -0
  249. package/dist/lib/hooks/source-allowlist.d.ts +26 -0
  250. package/dist/lib/hooks/source-allowlist.js +53 -0
  251. package/dist/lib/hooks/types.d.ts +129 -0
  252. package/dist/lib/hooks/types.js +24 -0
  253. package/dist/lib/hooks/worker.d.ts +56 -0
  254. package/dist/lib/hooks/worker.js +150 -0
  255. package/dist/lib/ingest-router.d.ts +25 -0
  256. package/dist/lib/ingest-router.js +103 -0
  257. package/dist/lib/ocr-detector.d.ts +61 -0
  258. package/dist/lib/ocr-detector.js +138 -0
  259. package/dist/lib/ocr-engine-stub.d.ts +48 -0
  260. package/dist/lib/ocr-engine-stub.js +190 -0
  261. package/dist/lib/ocr-engines/google-doc-ai.d.ts +36 -0
  262. package/dist/lib/ocr-engines/google-doc-ai.js +164 -0
  263. package/dist/lib/ocr-jobs.d.ts +67 -0
  264. package/dist/lib/ocr-jobs.js +129 -0
  265. package/dist/lib/op-audit-extension/ran-at-guard.d.ts +86 -0
  266. package/dist/lib/op-audit-extension/ran-at-guard.js +110 -0
  267. package/dist/lib/op-audit.d.ts +71 -0
  268. package/dist/lib/op-audit.js +777 -0
  269. package/dist/lib/privacy-br/detector.d.ts +42 -0
  270. package/dist/lib/privacy-br/detector.js +130 -0
  271. package/dist/lib/privacy-br/index.d.ts +20 -0
  272. package/dist/lib/privacy-br/index.js +20 -0
  273. package/dist/lib/privacy-br/integration.d.ts +71 -0
  274. package/dist/lib/privacy-br/integration.js +74 -0
  275. package/dist/lib/privacy-br/patterns.d.ts +117 -0
  276. package/dist/lib/privacy-br/patterns.js +434 -0
  277. package/dist/lib/privacy-br/redact.d.ts +42 -0
  278. package/dist/lib/privacy-br/redact.js +103 -0
  279. package/dist/lib/privacy-br/types.d.ts +55 -0
  280. package/dist/lib/privacy-br/types.js +25 -0
  281. package/dist/lib/regex-extract/extractor.d.ts +30 -0
  282. package/dist/lib/regex-extract/extractor.js +91 -0
  283. package/dist/lib/regex-extract/frontmatter.d.ts +44 -0
  284. package/dist/lib/regex-extract/frontmatter.js +169 -0
  285. package/dist/lib/regex-extract/index.d.ts +14 -0
  286. package/dist/lib/regex-extract/index.js +14 -0
  287. package/dist/lib/regex-extract/ingest-router-l4.d.ts +76 -0
  288. package/dist/lib/regex-extract/ingest-router-l4.js +102 -0
  289. package/dist/lib/regex-extract/patterns.d.ts +61 -0
  290. package/dist/lib/regex-extract/patterns.js +91 -0
  291. package/dist/lib/regex-extract/production-wire.d.ts +128 -0
  292. package/dist/lib/regex-extract/production-wire.js +202 -0
  293. package/dist/lib/regex-extract/reconcile.d.ts +162 -0
  294. package/dist/lib/regex-extract/reconcile.js +210 -0
  295. package/dist/lib/regex-extract/strip-code.d.ts +24 -0
  296. package/dist/lib/regex-extract/strip-code.js +52 -0
  297. package/dist/lib/regex-extract/types.d.ts +48 -0
  298. package/dist/lib/regex-extract/types.js +25 -0
  299. package/dist/lib/reranker.d.ts +80 -0
  300. package/dist/lib/reranker.js +324 -0
  301. package/dist/lib/shadow-tracker.d.ts +191 -0
  302. package/dist/lib/shadow-tracker.js +384 -0
  303. package/dist/lib/spo-injection.d.ts +52 -0
  304. package/dist/lib/spo-injection.js +166 -0
  305. package/dist/lib/telemetry-collector.d.ts +158 -0
  306. package/dist/lib/telemetry-collector.js +249 -0
  307. package/dist/lib/temporal-detector.d.ts +27 -0
  308. package/dist/lib/temporal-detector.js +81 -0
  309. package/dist/lib/viewer/auth.d.ts +37 -0
  310. package/dist/lib/viewer/auth.js +70 -0
  311. package/dist/lib/viewer/backpressure.d.ts +59 -0
  312. package/dist/lib/viewer/backpressure.js +100 -0
  313. package/dist/lib/viewer/broadcast-singleton.d.ts +34 -0
  314. package/dist/lib/viewer/broadcast-singleton.js +49 -0
  315. package/dist/lib/viewer/broadcast.d.ts +66 -0
  316. package/dist/lib/viewer/broadcast.js +96 -0
  317. package/dist/lib/viewer/event-types.d.ts +132 -0
  318. package/dist/lib/viewer/event-types.js +74 -0
  319. package/dist/lib/viewer/instrumentation.d.ts +106 -0
  320. package/dist/lib/viewer/instrumentation.js +224 -0
  321. package/dist/lib/viewer/migration.d.ts +23 -0
  322. package/dist/lib/viewer/migration.js +56 -0
  323. package/dist/lib/viewer/redaction.d.ts +44 -0
  324. package/dist/lib/viewer/redaction.js +139 -0
  325. package/dist/lib/viewer/session.d.ts +51 -0
  326. package/dist/lib/viewer/session.js +87 -0
  327. package/dist/mcp/tools/answer.d.ts +94 -0
  328. package/dist/mcp/tools/answer.js +213 -0
  329. package/dist/mcp/tools/archive.d.ts +152 -0
  330. package/dist/mcp/tools/archive.js +170 -0
  331. package/dist/mcp/tools/conflict.d.ts +44 -0
  332. package/dist/mcp/tools/conflict.js +130 -0
  333. package/dist/mcp/tools/hooks.d.ts +29 -0
  334. package/dist/mcp/tools/hooks.js +78 -0
  335. package/dist/mcp/tools/mark.d.ts +38 -0
  336. package/dist/mcp/tools/mark.js +82 -0
  337. package/dist/mcp/tools/viewer.d.ts +58 -0
  338. package/dist/mcp/tools/viewer.js +64 -0
  339. package/dist/mcp-server.d.ts +2 -0
  340. package/dist/mcp-server.js +395 -0
  341. package/dist/metrics.d.ts +3 -0
  342. package/dist/metrics.js +59 -0
  343. package/dist/noise-filter.d.ts +18 -0
  344. package/dist/noise-filter.js +142 -0
  345. package/dist/notion-sync.d.ts +7 -0
  346. package/dist/notion-sync.js +97 -0
  347. package/dist/observability/adapters/a3-adapter.d.ts +63 -0
  348. package/dist/observability/adapters/a3-adapter.js +83 -0
  349. package/dist/observability/adapters/p1-adapter.d.ts +49 -0
  350. package/dist/observability/adapters/p1-adapter.js +63 -0
  351. package/dist/observability/adapters/p5-adapter.d.ts +36 -0
  352. package/dist/observability/adapters/p5-adapter.js +71 -0
  353. package/dist/observability/cardinality.d.ts +61 -0
  354. package/dist/observability/cardinality.js +300 -0
  355. package/dist/observability/collectors/db-stats.collector.d.ts +9 -0
  356. package/dist/observability/collectors/db-stats.collector.js +88 -0
  357. package/dist/observability/collectors/eventbus.collector.d.ts +6 -0
  358. package/dist/observability/collectors/eventbus.collector.js +50 -0
  359. package/dist/observability/collectors/process.collector.d.ts +7 -0
  360. package/dist/observability/collectors/process.collector.js +93 -0
  361. package/dist/observability/collectors/provider-telemetry.collector.d.ts +11 -0
  362. package/dist/observability/collectors/provider-telemetry.collector.js +112 -0
  363. package/dist/observability/collectors/search-telemetry.collector.d.ts +12 -0
  364. package/dist/observability/collectors/search-telemetry.collector.js +76 -0
  365. package/dist/observability/exporter.d.ts +30 -0
  366. package/dist/observability/exporter.js +182 -0
  367. package/dist/observability/index.d.ts +22 -0
  368. package/dist/observability/index.js +21 -0
  369. package/dist/observability/metrics.d.ts +53 -0
  370. package/dist/observability/metrics.js +213 -0
  371. package/dist/observability/privacy-guard.d.ts +32 -0
  372. package/dist/observability/privacy-guard.js +116 -0
  373. package/dist/observability/record.d.ts +83 -0
  374. package/dist/observability/record.js +217 -0
  375. package/dist/observability/registry.d.ts +60 -0
  376. package/dist/observability/registry.js +93 -0
  377. package/dist/observability/types.d.ts +115 -0
  378. package/dist/observability/types.js +235 -0
  379. package/dist/observability.d.ts +131 -0
  380. package/dist/observability.js +234 -0
  381. package/dist/plugins/nox-hooks/index.d.ts +61 -0
  382. package/dist/plugins/nox-hooks/index.js +99 -0
  383. package/dist/primer.d.ts +1 -0
  384. package/dist/primer.js +100 -0
  385. package/dist/privacy/filter.d.ts +27 -0
  386. package/dist/privacy/filter.js +74 -0
  387. package/dist/privacy/patterns.d.ts +29 -0
  388. package/dist/privacy/patterns.js +178 -0
  389. package/dist/privacy/tag-parser.d.ts +24 -0
  390. package/dist/privacy/tag-parser.js +29 -0
  391. package/dist/project-context-gen.d.ts +10 -0
  392. package/dist/project-context-gen.js +106 -0
  393. package/dist/providers/embedding/gemini.d.ts +73 -0
  394. package/dist/providers/embedding/gemini.js +118 -0
  395. package/dist/providers/embedding/openai.d.ts +76 -0
  396. package/dist/providers/embedding/openai.js +123 -0
  397. package/dist/providers/embedding/types.d.ts +39 -0
  398. package/dist/providers/embedding/types.js +1 -0
  399. package/dist/providers/embedding/voyage.d.ts +36 -0
  400. package/dist/providers/embedding/voyage.js +29 -0
  401. package/dist/providers/index.d.ts +116 -0
  402. package/dist/providers/index.js +158 -0
  403. package/dist/providers/llm/anthropic.d.ts +29 -0
  404. package/dist/providers/llm/anthropic.js +28 -0
  405. package/dist/providers/llm/chain.d.ts +99 -0
  406. package/dist/providers/llm/chain.js +213 -0
  407. package/dist/providers/llm/gemini.d.ts +48 -0
  408. package/dist/providers/llm/gemini.js +96 -0
  409. package/dist/providers/llm/openai.d.ts +64 -0
  410. package/dist/providers/llm/openai.js +109 -0
  411. package/dist/providers/llm/types.d.ts +47 -0
  412. package/dist/providers/llm/types.js +1 -0
  413. package/dist/providers/telemetry.d.ts +87 -0
  414. package/dist/providers/telemetry.js +156 -0
  415. package/dist/providers/types.d.ts +42 -0
  416. package/dist/providers/types.js +59 -0
  417. package/dist/query-entity-count.d.ts +54 -0
  418. package/dist/query-entity-count.js +171 -0
  419. package/dist/reflect.d.ts +26 -0
  420. package/dist/reflect.js +290 -0
  421. package/dist/reindex-errors.d.ts +7 -0
  422. package/dist/reindex-errors.js +21 -0
  423. package/dist/reindex.d.ts +16 -0
  424. package/dist/reindex.js +293 -0
  425. package/dist/retention.d.ts +40 -0
  426. package/dist/retention.js +86 -0
  427. package/dist/salience.d.ts +85 -0
  428. package/dist/salience.js +245 -0
  429. package/dist/scripts/migrate-v17-ops-audit.d.ts +17 -0
  430. package/dist/scripts/migrate-v17-ops-audit.js +70 -0
  431. package/dist/search-dedup.d.ts +44 -0
  432. package/dist/search-dedup.js +137 -0
  433. package/dist/search-expansion.d.ts +20 -0
  434. package/dist/search-expansion.js +99 -0
  435. package/dist/search.d.ts +62 -0
  436. package/dist/search.js +582 -0
  437. package/dist/seh-detector.d.ts +31 -0
  438. package/dist/seh-detector.js +201 -0
  439. package/dist/self-improve.d.ts +1 -0
  440. package/dist/self-improve.js +189 -0
  441. package/dist/session-distill.d.ts +29 -0
  442. package/dist/session-distill.js +325 -0
  443. package/dist/session-update.d.ts +1 -0
  444. package/dist/session-update.js +54 -0
  445. package/dist/shared-memory.d.ts +24 -0
  446. package/dist/shared-memory.js +104 -0
  447. package/dist/stats.d.ts +1 -0
  448. package/dist/stats.js +44 -0
  449. package/dist/temporal-retrieval.d.ts +132 -0
  450. package/dist/temporal-retrieval.js +495 -0
  451. package/dist/tier-manager.d.ts +69 -0
  452. package/dist/tier-manager.js +225 -0
  453. package/dist/vectorize.d.ts +16 -0
  454. package/dist/vectorize.js +91 -0
  455. package/dist/watch.d.ts +8 -0
  456. package/dist/watch.js +124 -0
  457. package/package.json +74 -0
package/dist/evals.js ADDED
@@ -0,0 +1,351 @@
1
+ /**
2
+ * evals.ts — F10 Phase B endpoint (Eval Dashboard)
3
+ *
4
+ * Adds one read-only endpoint under `/api/observability/*`:
5
+ *
6
+ * GET /api/observability/evals?db_source=<filter>&limit=<n>
7
+ * Returns the historical ablation/gate runs aggregated from `audits/data-G*`
8
+ * directories on disk. Each row carries enough metric breadth to drive the
9
+ * dashboard (nDCG@10, MRR, recall@10), the DB it ran against (for the post-G6
10
+ * fiasco filter — see [[g6-ablation-results-2026-05-20]]), and a list of gate
11
+ * annotations that match its run date.
12
+ *
13
+ * Source data layer
14
+ * -----------------
15
+ * The audits directory is heterogeneous:
16
+ *
17
+ * audits/data-g10b/*.json → {summary, per_category} per run (a8 mutex active/disabled)
18
+ * audits/data-g10c/*.json → derived aggregate: {aggregate.active, aggregate.disabled,
19
+ * per_style_active, per_style_disabled}
20
+ * audits/data-g10d/*.json → {summary, per_category} per t-threshold (a8d_t1/t2/baseline/control)
21
+ * audits/data-g10e/*.json → derived per-query diff array (NOT a run aggregate — skipped)
22
+ *
23
+ * Each "summary" block has:
24
+ * { label, toggles, n_queries, fixture_dir, endpoint, ndcg_at_10, mrr,
25
+ * recall_at_10, precision_at_5, mean_latency_ms, p95_latency_ms,
26
+ * n_valid_queries, wallclock_s }
27
+ *
28
+ * Adapter strategy:
29
+ * - Walk `audits/data-<X>/` directories.
30
+ * - For each .json file, sniff the shape:
31
+ * (a) `{ summary, per_category, ... }` → emit one row from summary
32
+ * (b) `{ aggregate: { active, disabled }, ... }` → emit two rows (one per agg key)
33
+ * (c) anything else (e.g. per-query derived array) → skip with a warn to stderr
34
+ * - `ran_at` = file mtime (UTC ISO), since aggregate JSONs don't carry a wall-clock.
35
+ * - `db_source` = parsed from `summary.fixture_dir` (last path component → e.g.
36
+ * "g9-g5db-2026-05-20" → "g5.db"; the convention is documented in
37
+ * [[g6-ablation-results-2026-05-20]] and [[g10-mutex-validated-2026-05-20]]).
38
+ * - `config_id` = `summary.label` (already unique per run).
39
+ * - `run_id` = `<G-bucket>::<label>` for stability across reads.
40
+ *
41
+ * Annotations:
42
+ * - Loaded from `public/observability/gate-annotations.json` once per process.
43
+ * - A row gets every annotation whose date falls on the same UTC calendar day.
44
+ *
45
+ * Caching:
46
+ * - 5-minute in-memory TTL (spec allows). Single-process server, no infra.
47
+ * - Test harness exposes `_resetEvalsCache()` to clear state between cases.
48
+ *
49
+ * Spec: specs/2026-05-01-F10-observability-dashboard.md §"P1 EVAL DASHBOARD"
50
+ * Status: Phase B implementation-ready
51
+ */
52
+ import { readdirSync, readFileSync, statSync } from "fs";
53
+ import { join } from "path";
54
+ // ── DB-source heuristic ───────────────────────────────────────────────────────
55
+ /**
56
+ * Maps the fixture_dir leaf to the canonical DB filename, the way the team
57
+ * tracks DBs in audits. The convention (per [[g6-ablation-results-2026-05-20]]
58
+ * and follow-ups) is that a fixture directory contains a substring naming the
59
+ * DB the eval was actually run against.
60
+ *
61
+ * Examples seen on disk:
62
+ * /path/to/workspace/eval-data/g9-g5db-2026-05-20 → "g5.db"
63
+ * /…/eval-data/entity-eval-v2 → "entity-eval-v2.db"
64
+ * /…/eval-data/entity-eval → "entity-eval.db"
65
+ * /…/eval-data/g9 → "g9.db"
66
+ *
67
+ * Returns "unknown.db" if no match. Tests must cover the unknown fallback.
68
+ */
69
+ export function inferDbSource(fixtureDir) {
70
+ if (!fixtureDir)
71
+ return "unknown.db";
72
+ const leaf = fixtureDir.split("/").filter((s) => s.length > 0).pop() ?? "";
73
+ const lower = leaf.toLowerCase();
74
+ // Specific names first (longest-prefix wins)
75
+ if (lower.includes("entity-eval-v2"))
76
+ return "entity-eval-v2.db";
77
+ if (lower.includes("entity-eval"))
78
+ return "entity-eval.db";
79
+ if (lower.includes("g5db") || lower.includes("g5-db") || lower.includes("g5.db"))
80
+ return "g5.db";
81
+ if (lower.includes("g9-g5db"))
82
+ return "g5.db";
83
+ if (lower.includes("g9"))
84
+ return "g9.db";
85
+ if (lower.includes("g10"))
86
+ return "g10.db";
87
+ return "unknown.db";
88
+ }
89
+ /**
90
+ * Bucket key derived from the data-Gxx directory name. Used for stable run_ids
91
+ * and as a fallback config grouping in the UI.
92
+ */
93
+ export function gateBucketFromDir(dir) {
94
+ // dir like "data-g10b" → "g10b"
95
+ const leaf = dir.split("/").filter((s) => s.length > 0).pop() ?? "";
96
+ const m = /^data-([A-Za-z0-9._-]+)$/.exec(leaf);
97
+ return m && m[1] ? m[1] : leaf;
98
+ }
99
+ // ── Number coercion ───────────────────────────────────────────────────────────
100
+ function toNumOrNull(v) {
101
+ if (typeof v === "number" && Number.isFinite(v))
102
+ return v;
103
+ return null;
104
+ }
105
+ function toStringOrNull(v) {
106
+ return typeof v === "string" ? v : null;
107
+ }
108
+ // ── Annotation matching ───────────────────────────────────────────────────────
109
+ /**
110
+ * Returns the YYYY-MM-DD UTC calendar string for an ms timestamp. ISO substring
111
+ * is intentional — keeps the implementation portable across Node versions and
112
+ * avoids a Date locale dependency.
113
+ */
114
+ export function isoDay(ms) {
115
+ return new Date(ms).toISOString().slice(0, 10);
116
+ }
117
+ /**
118
+ * Picks every annotation whose `date` matches the run's UTC calendar day.
119
+ * Returns label strings (not the full object) — the UI only needs the labels
120
+ * to overlay vertical lines + tooltips, and richer data lives in the gate file.
121
+ */
122
+ export function matchAnnotations(ranAtMs, annotations) {
123
+ const day = isoDay(ranAtMs);
124
+ const out = [];
125
+ for (const a of annotations) {
126
+ if (a.date === day)
127
+ out.push(a.label);
128
+ }
129
+ return out;
130
+ }
131
+ // ── Adapter: parse one JSON file → 0..N rows ──────────────────────────────────
132
+ /**
133
+ * Parses one audit JSON file into a list of normalized EvalRow.
134
+ *
135
+ * Returns `[]` (with stderr warning) when the file is unreadable, malformed,
136
+ * or carries a shape we explicitly do not aggregate (e.g. per-query diff arrays).
137
+ * Never throws — endpoint hardening per spec.
138
+ */
139
+ export function parseAuditFile(filePath, fileMtimeMs, bucket, annotations) {
140
+ let raw;
141
+ try {
142
+ raw = readFileSync(filePath, "utf-8");
143
+ }
144
+ catch (err) {
145
+ process.stderr.write(`[evals] read failed: ${filePath}: ${String(err)}\n`);
146
+ return [];
147
+ }
148
+ let parsed;
149
+ try {
150
+ parsed = JSON.parse(raw);
151
+ }
152
+ catch (err) {
153
+ process.stderr.write(`[evals] JSON parse failed: ${filePath}: ${String(err)}\n`);
154
+ return [];
155
+ }
156
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
157
+ // Per-query derived arrays (g10e) or other non-object shapes → skip silently.
158
+ return [];
159
+ }
160
+ const obj = parsed;
161
+ const ranAtMs = fileMtimeMs;
162
+ const ranAt = new Date(ranAtMs).toISOString();
163
+ const matched = matchAnnotations(ranAtMs, annotations);
164
+ // Shape (b): derived aggregate { aggregate: { active, disabled }, ... }
165
+ if (obj["aggregate"] && typeof obj["aggregate"] === "object" && !Array.isArray(obj["aggregate"])) {
166
+ const agg = obj["aggregate"];
167
+ const rows = [];
168
+ for (const key of Object.keys(agg)) {
169
+ const sub = agg[key];
170
+ if (sub && typeof sub === "object" && !Array.isArray(sub)) {
171
+ const row = rowFromSummary(sub, filePath, bucket, ranAt, ranAtMs, matched, `${key}`);
172
+ if (row)
173
+ rows.push(row);
174
+ }
175
+ }
176
+ return rows;
177
+ }
178
+ // Shape (a): { summary, per_category, ... }
179
+ if (obj["summary"] && typeof obj["summary"] === "object" && !Array.isArray(obj["summary"])) {
180
+ const row = rowFromSummary(obj["summary"], filePath, bucket, ranAt, ranAtMs, matched, null);
181
+ return row ? [row] : [];
182
+ }
183
+ // Unknown shape → skip silently.
184
+ return [];
185
+ }
186
+ function rowFromSummary(s, filePath, bucket, ranAt, ranAtMs, annotations, configSuffix) {
187
+ const label = toStringOrNull(s.label);
188
+ const configIdBase = label ?? "unknown";
189
+ const configId = configSuffix ? `${configIdBase}::${configSuffix}` : configIdBase;
190
+ const fixtureDir = toStringOrNull(s.fixture_dir);
191
+ const dbSource = inferDbSource(fixtureDir);
192
+ const nQueries = toNumOrNull(s.n_queries) ?? toNumOrNull(s.n_valid_queries);
193
+ return {
194
+ run_id: `${bucket}::${configId}`,
195
+ config_id: configId,
196
+ db_source: dbSource,
197
+ ndcg_at_10: toNumOrNull(s.ndcg_at_10),
198
+ mrr: toNumOrNull(s.mrr),
199
+ recall_at_10: toNumOrNull(s.recall_at_10),
200
+ precision_at_5: toNumOrNull(s.precision_at_5),
201
+ mean_latency_ms: toNumOrNull(s.mean_latency_ms),
202
+ p95_latency_ms: toNumOrNull(s.p95_latency_ms),
203
+ n_queries: nQueries,
204
+ ran_at: ranAt,
205
+ ran_at_ms: ranAtMs,
206
+ source_path: filePath,
207
+ annotations,
208
+ };
209
+ }
210
+ // ── Directory walker ──────────────────────────────────────────────────────────
211
+ /**
212
+ * Returns the sorted absolute paths of `audits/data-*` JSON files under the
213
+ * given root. Best-effort: directories that disappear mid-walk are skipped.
214
+ */
215
+ export function collectAuditFiles(auditsRoot) {
216
+ const out = [];
217
+ let entries;
218
+ try {
219
+ entries = readdirSync(auditsRoot);
220
+ }
221
+ catch {
222
+ return out;
223
+ }
224
+ for (const name of entries) {
225
+ if (!name.startsWith("data-"))
226
+ continue;
227
+ const dir = join(auditsRoot, name);
228
+ let st;
229
+ try {
230
+ st = statSync(dir);
231
+ }
232
+ catch {
233
+ continue;
234
+ }
235
+ if (!st.isDirectory())
236
+ continue;
237
+ const bucket = gateBucketFromDir(dir);
238
+ let files;
239
+ try {
240
+ files = readdirSync(dir);
241
+ }
242
+ catch {
243
+ continue;
244
+ }
245
+ for (const f of files) {
246
+ if (!f.endsWith(".json"))
247
+ continue;
248
+ const fp = join(dir, f);
249
+ let fst;
250
+ try {
251
+ fst = statSync(fp);
252
+ }
253
+ catch {
254
+ continue;
255
+ }
256
+ if (!fst.isFile())
257
+ continue;
258
+ out.push({ file: fp, bucket, mtimeMs: fst.mtimeMs });
259
+ }
260
+ }
261
+ return out;
262
+ }
263
+ // ── Annotations loader ────────────────────────────────────────────────────────
264
+ /**
265
+ * Best-effort load of the gate-annotations.json file. Returns `[]` on missing
266
+ * file, parse error, or wrong shape — callers tolerate empty annotation list.
267
+ */
268
+ export function loadAnnotations(filePath) {
269
+ let raw;
270
+ try {
271
+ raw = readFileSync(filePath, "utf-8");
272
+ }
273
+ catch {
274
+ return [];
275
+ }
276
+ let parsed;
277
+ try {
278
+ parsed = JSON.parse(raw);
279
+ }
280
+ catch (err) {
281
+ process.stderr.write(`[evals] annotations JSON parse failed: ${String(err)}\n`);
282
+ return [];
283
+ }
284
+ if (!Array.isArray(parsed))
285
+ return [];
286
+ const out = [];
287
+ for (const item of parsed) {
288
+ if (!item || typeof item !== "object" || Array.isArray(item))
289
+ continue;
290
+ const rec = item;
291
+ const date = toStringOrNull(rec["date"]);
292
+ const label = toStringOrNull(rec["label"]);
293
+ if (!date || !label)
294
+ continue;
295
+ const description = toStringOrNull(rec["description"]) ?? undefined;
296
+ const ann = description !== undefined
297
+ ? { date, label, description }
298
+ : { date, label };
299
+ out.push(ann);
300
+ }
301
+ return out;
302
+ }
303
+ const DEFAULT_TTL_MS = 5 * 60 * 1000;
304
+ let cached = null;
305
+ /** Exposed for tests. */
306
+ export function _resetEvalsCache() {
307
+ cached = null;
308
+ }
309
+ /**
310
+ * Build the row list from disk (no cache). Useful for tests.
311
+ */
312
+ export function buildEvalRows(opts = {}) {
313
+ const auditsRoot = opts.auditsRoot ?? join(process.cwd(), "..", "audits");
314
+ const annotationsPath = opts.annotationsPath
315
+ ?? join(process.cwd(), "public", "observability", "gate-annotations.json");
316
+ const annotations = loadAnnotations(annotationsPath);
317
+ const files = collectAuditFiles(auditsRoot);
318
+ const rows = [];
319
+ for (const f of files) {
320
+ const parsed = parseAuditFile(f.file, f.mtimeMs, f.bucket, annotations);
321
+ for (const r of parsed)
322
+ rows.push(r);
323
+ }
324
+ rows.sort((a, b) => a.ran_at_ms - b.ran_at_ms);
325
+ return rows;
326
+ }
327
+ /**
328
+ * Endpoint handler. Returns an array of EvalRow already sorted by ran_at ASC,
329
+ * filtered by db_source if requested, and capped to `limit`.
330
+ */
331
+ export function handleObsEvals(query = {}, opts = {}) {
332
+ const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS;
333
+ const now = opts.now ? opts.now() : Date.now();
334
+ const fresh = cached && !query.force && now - cached.generatedAtMs < ttlMs;
335
+ if (!fresh) {
336
+ const rows = buildEvalRows(opts);
337
+ cached = { generatedAtMs: now, rows };
338
+ }
339
+ const rows = cached.rows;
340
+ const dbFilter = query.dbSource && query.dbSource !== "all" ? query.dbSource : null;
341
+ const limit = Math.max(1, Math.min(2000, Math.floor(query.limit ?? 500)));
342
+ const filtered = dbFilter ? rows.filter((r) => r.db_source === dbFilter) : rows;
343
+ return filtered.slice(0, limit);
344
+ }
345
+ // ── _internals for tests ──────────────────────────────────────────────────────
346
+ export const _internals = {
347
+ DEFAULT_TTL_MS,
348
+ toNumOrNull,
349
+ toStringOrNull,
350
+ rowFromSummary,
351
+ };
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * generate-user-profile.ts — Fase 1.7a
4
+ *
5
+ * Generates `shared/USER-PROFILE.md` from KG + chunks. Agents read this file
6
+ * at boot to have rich context without a search round-trip each turn.
7
+ *
8
+ * Sections:
9
+ * 1. Top 20 entities (by mention_count) with relevant attributes
10
+ * 2. Active projects (status != closed)
11
+ * 3. Decisions in the last 30 days
12
+ * 4. Declared preferences (chunks of type lesson/preference)
13
+ *
14
+ * Run: node dist/generate-user-profile.js
15
+ * NOX_PROFILE_OUTPUT: optional absolute path for the output file.
16
+ * Defaults to $OPENCLAW_WORKSPACE/shared/USER-PROFILE.md (or ./USER-PROFILE.md).
17
+ */
18
+ export declare function generateUserProfile(): string;
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * generate-user-profile.ts — Fase 1.7a
4
+ *
5
+ * Generates `shared/USER-PROFILE.md` from KG + chunks. Agents read this file
6
+ * at boot to have rich context without a search round-trip each turn.
7
+ *
8
+ * Sections:
9
+ * 1. Top 20 entities (by mention_count) with relevant attributes
10
+ * 2. Active projects (status != closed)
11
+ * 3. Decisions in the last 30 days
12
+ * 4. Declared preferences (chunks of type lesson/preference)
13
+ *
14
+ * Run: node dist/generate-user-profile.js
15
+ * NOX_PROFILE_OUTPUT: optional absolute path for the output file.
16
+ * Defaults to $OPENCLAW_WORKSPACE/shared/USER-PROFILE.md (or ./USER-PROFILE.md).
17
+ */
18
+ import { getDb, closeDb } from "./db.js";
19
+ import { writeFileSync, mkdirSync } from "fs";
20
+ import { resolve, dirname } from "path";
21
+ function parseAttrs(json) {
22
+ if (!json)
23
+ return {};
24
+ try {
25
+ return JSON.parse(json);
26
+ }
27
+ catch {
28
+ return {};
29
+ }
30
+ }
31
+ function formatAttrs(attrs, keys) {
32
+ const parts = [];
33
+ for (const k of keys) {
34
+ const v = attrs[k];
35
+ if (v !== undefined && v !== null && v !== "")
36
+ parts.push(`${k}: ${String(v)}`);
37
+ }
38
+ return parts.join(" · ");
39
+ }
40
+ function section(title, body) {
41
+ return `## ${title}\n\n${body}\n`;
42
+ }
43
+ export function generateUserProfile() {
44
+ const db = getDb();
45
+ const nowIso = new Date().toISOString().split("T")[0];
46
+ // ─── Top 20 entidades ────────────────────────────────────────────────
47
+ const topEntities = db.prepare(`
48
+ SELECT id, name, entity_type, mention_count, attributes, last_seen
49
+ FROM kg_entities
50
+ ORDER BY mention_count DESC
51
+ LIMIT 20
52
+ `).all();
53
+ const topByType = {};
54
+ for (const e of topEntities) {
55
+ if (!topByType[e.entity_type])
56
+ topByType[e.entity_type] = [];
57
+ topByType[e.entity_type].push(e);
58
+ }
59
+ const topFmt = Object.entries(topByType)
60
+ .map(([type, ents]) => {
61
+ const lines = ents.map((e) => {
62
+ const a = parseAttrs(e.attributes);
63
+ const attrKeys = type === "person"
64
+ ? ["role", "organization", "email", "whatsapp_number"]
65
+ : type === "project"
66
+ ? ["status", "stage", "value_brl", "value_usd", "key_person", "industry"]
67
+ : type === "organization"
68
+ ? ["type", "country", "sector"]
69
+ : type === "document"
70
+ ? ["doc_type", "date", "parties"]
71
+ : ["category", "domain"];
72
+ const details = formatAttrs(a, attrKeys);
73
+ return `- **${e.name}** (${e.mention_count} mentions)${details ? " — " + details : ""}`;
74
+ }).join("\n");
75
+ return `### ${type}s\n${lines}`;
76
+ })
77
+ .join("\n\n");
78
+ // ─── Projects ativos ─────────────────────────────────────────────────
79
+ const activeProjects = db.prepare(`
80
+ SELECT id, name, entity_type, mention_count, attributes, last_seen
81
+ FROM kg_entities
82
+ WHERE entity_type = 'project'
83
+ ORDER BY mention_count DESC
84
+ LIMIT 30
85
+ `).all();
86
+ const activeFiltered = activeProjects.filter((p) => {
87
+ const a = parseAttrs(p.attributes);
88
+ return a.status !== "closed" && a.status !== "completed";
89
+ });
90
+ const projectsFmt = activeFiltered.length > 0
91
+ ? activeFiltered.slice(0, 15).map((p) => {
92
+ const a = parseAttrs(p.attributes);
93
+ const details = formatAttrs(a, ["status", "stage", "value_brl", "value_usd", "key_person", "industry", "ebitda_multiple"]);
94
+ return `- **${p.name}** (${p.mention_count}m)${details ? " — " + details : ""}`;
95
+ }).join("\n")
96
+ : "_(nenhum project com status explícito — rodar kg-build pra enriquecer)_";
97
+ // ─── Decisões últimos 30 dias ────────────────────────────────────────
98
+ const decisions = db.prepare(`
99
+ SELECT id, chunk_text, chunk_type, source_date, source_file
100
+ FROM chunks
101
+ WHERE chunk_type = 'decision'
102
+ AND source_date >= date('now', '-30 days')
103
+ ORDER BY source_date DESC
104
+ LIMIT 15
105
+ `).all();
106
+ const decisionsFmt = decisions.length > 0
107
+ ? decisions.map((d) => {
108
+ const summary = d.chunk_text.substring(0, 150).replace(/\n/g, " ");
109
+ return `- [${d.source_date}] ${summary}${d.chunk_text.length > 150 ? "..." : ""}`;
110
+ }).join("\n")
111
+ : "_(nenhuma decisão registrada nos últimos 30 dias)_";
112
+ // ─── Preferências declaradas ─────────────────────────────────────────
113
+ const prefs = db.prepare(`
114
+ SELECT id, chunk_text, chunk_type, source_date, source_file
115
+ FROM chunks
116
+ WHERE chunk_type IN ('lesson', 'preference', 'pattern')
117
+ ORDER BY source_date DESC
118
+ LIMIT 20
119
+ `).all();
120
+ const prefsFmt = prefs.length > 0
121
+ ? prefs.map((p) => {
122
+ const summary = p.chunk_text.substring(0, 200).replace(/\n/g, " ");
123
+ return `- [${p.chunk_type}] ${summary}${p.chunk_text.length > 200 ? "..." : ""}`;
124
+ }).join("\n")
125
+ : "_(nenhuma preferência/lição registrada)_";
126
+ // ─── Monta documento ─────────────────────────────────────────────────
127
+ const stats = db.prepare(`
128
+ SELECT COUNT(*) as total FROM kg_entities
129
+ `).get();
130
+ const md = `# USER-PROFILE.md (auto-generated ${nowIso})
131
+
132
+ > Generated by \`generate-user-profile.ts\`. Do not edit manually — next run overwrites.
133
+ > KG: ${stats.total} entities.
134
+
135
+ ${section("Top 20 entities by mention count", topFmt)}
136
+ ${section("Active projects", projectsFmt)}
137
+ ${section("Decisions (last 30 days)", decisionsFmt)}
138
+ ${section("Preferences / declared lessons", prefsFmt)}
139
+
140
+ ---
141
+
142
+ _End of USER-PROFILE. Regenerates weekly via cron._
143
+ `;
144
+ return md;
145
+ }
146
+ // CLI
147
+ // NOX_PROFILE_OUTPUT: explicit output path (takes precedence).
148
+ // Falls back to $OPENCLAW_WORKSPACE/shared/USER-PROFILE.md, then ./USER-PROFILE.md.
149
+ const _ws = process.env.OPENCLAW_WORKSPACE;
150
+ const outputPath = process.env.NOX_PROFILE_OUTPUT
151
+ ?? (_ws ? resolve(_ws, "shared", "USER-PROFILE.md") : resolve(process.cwd(), "USER-PROFILE.md"));
152
+ try {
153
+ mkdirSync(dirname(outputPath), { recursive: true });
154
+ const md = generateUserProfile();
155
+ writeFileSync(outputPath, md, "utf-8");
156
+ console.log(`[USER-PROFILE] Generated: ${outputPath} (${md.length} bytes)`);
157
+ closeDb();
158
+ }
159
+ catch (err) {
160
+ console.error(`[USER-PROFILE] Failed: ${err.message}`);
161
+ closeDb();
162
+ process.exit(1);
163
+ }
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * graphify-ingest.ts — Fase 2: ingest graphify output into nox-mem
4
+ *
5
+ * Converte graph.json (graphify) em chunks no nox-mem com rate-limit.
6
+ * Cada node graphify vira 1 chunk com chunk_type='graph_node', source_type='external',
7
+ * is_compiled=1. Edges são embutidas no chunk_text como "Links: rel → target".
8
+ *
9
+ * Rate-limit: batch 500 chunks, pause 5min (300s) entre batches.
10
+ * Janela proibida: 22:30-01:30 BRT (não concorre com nightly-maintenance).
11
+ *
12
+ * Usage:
13
+ * node dist/graphify-ingest.js <graph.json path> <repo-name>
14
+ *
15
+ * Example:
16
+ * node dist/graphify-ingest.js /path/to/your/graphify-out/graph.json YourProject
17
+ */
18
+ export {};