@unerr-ai/unerr 0.1.6 → 0.1.7

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 (218) hide show
  1. package/README.md +70 -194
  2. package/dist/cli.js +39149 -36991
  3. package/package.json +9 -2
  4. package/dist/__tests__/architecture-guard.test.js +0 -122
  5. package/dist/__tests__/arg-validator.test.js +0 -205
  6. package/dist/__tests__/ast-extractor.test.js +0 -203
  7. package/dist/__tests__/auto-bootstrap.test.js +0 -280
  8. package/dist/__tests__/background-indexer.test.js +0 -228
  9. package/dist/__tests__/blast-radius-engine.test.js +0 -200
  10. package/dist/__tests__/bridge-isolation.test.js +0 -37
  11. package/dist/__tests__/budget-enforcer.test.js +0 -53
  12. package/dist/__tests__/cfg-test-detection-perf.test.js +0 -82
  13. package/dist/__tests__/change-narrative.test.js +0 -190
  14. package/dist/__tests__/check-commit.test.js +0 -258
  15. package/dist/__tests__/checksum.test.js +0 -34
  16. package/dist/__tests__/commit-watcher.test.js +0 -154
  17. package/dist/__tests__/community-detection.test.js +0 -179
  18. package/dist/__tests__/community-tools.test.js +0 -299
  19. package/dist/__tests__/components.test.js +0 -449
  20. package/dist/__tests__/compression-log.test.js +0 -174
  21. package/dist/__tests__/compression-quality-monitor.test.js +0 -40
  22. package/dist/__tests__/config-healer.test.js +0 -165
  23. package/dist/__tests__/context-ledger.test.js +0 -58
  24. package/dist/__tests__/convention-detector.test.js +0 -99
  25. package/dist/__tests__/convention-learner.test.js +0 -86
  26. package/dist/__tests__/correction-detector.test.js +0 -330
  27. package/dist/__tests__/daemon-autostart-install.test.js +0 -283
  28. package/dist/__tests__/daemon-bridge.test.js +0 -222
  29. package/dist/__tests__/daemon-dashboard.test.js +0 -202
  30. package/dist/__tests__/daemon-registry.test.js +0 -240
  31. package/dist/__tests__/daemon-supervisor.test.js +0 -318
  32. package/dist/__tests__/daemon-version-check.test.js +0 -275
  33. package/dist/__tests__/decision-point-detector.test.js +0 -98
  34. package/dist/__tests__/deep-link.test.js +0 -143
  35. package/dist/__tests__/disallowed-tools.test.js +0 -115
  36. package/dist/__tests__/drift-tracker.test.js +0 -582
  37. package/dist/__tests__/durability-scorer.test.js +0 -152
  38. package/dist/__tests__/efficiency-tracker.test.js +0 -65
  39. package/dist/__tests__/enrich.test.js +0 -144
  40. package/dist/__tests__/entity-rewind.test.js +0 -248
  41. package/dist/__tests__/ephemeral.test.js +0 -111
  42. package/dist/__tests__/exploration-cost.test.js +0 -93
  43. package/dist/__tests__/fact-generator.test.js +0 -197
  44. package/dist/__tests__/file-l0-graph.test.js +0 -244
  45. package/dist/__tests__/file-logger.test.js +0 -82
  46. package/dist/__tests__/file-outline.test.js +0 -141
  47. package/dist/__tests__/file-read-protocol.test.js +0 -188
  48. package/dist/__tests__/format-encoder.test.js +0 -233
  49. package/dist/__tests__/git-attribution.test.js +0 -259
  50. package/dist/__tests__/graph-temporal-joiner.test.js +0 -219
  51. package/dist/__tests__/health-grade-enhanced.test.js +0 -138
  52. package/dist/__tests__/health-map-data.test.js +0 -173
  53. package/dist/__tests__/helpers/mcp-harness.js +0 -45
  54. package/dist/__tests__/helpers/mcp-harness.test.js +0 -68
  55. package/dist/__tests__/hook-dedup.test.js +0 -112
  56. package/dist/__tests__/hook-runner.test.js +0 -253
  57. package/dist/__tests__/indexer-cfg.test.js +0 -185
  58. package/dist/__tests__/indexer-cross-file.test.js +0 -172
  59. package/dist/__tests__/indexer-extraction.test.js +0 -245
  60. package/dist/__tests__/indexer-incremental.test.js +0 -232
  61. package/dist/__tests__/indexer-language-expansion.test.js +0 -165
  62. package/dist/__tests__/init-push.test.js +0 -131
  63. package/dist/__tests__/instruction-writer.test.js +0 -179
  64. package/dist/__tests__/intelligence-integration.test.js +0 -217
  65. package/dist/__tests__/intent-correlator.test.js +0 -175
  66. package/dist/__tests__/intent-detector.test.js +0 -235
  67. package/dist/__tests__/intent-encoder.test.js +0 -167
  68. package/dist/__tests__/java-build-tool-detection.test.js +0 -174
  69. package/dist/__tests__/layer3-sprint-q.test.js +0 -160
  70. package/dist/__tests__/layer3-sprint-r.test.js +0 -91
  71. package/dist/__tests__/layer3-sprint-s.test.js +0 -183
  72. package/dist/__tests__/layer3-sprint-t.test.js +0 -201
  73. package/dist/__tests__/layer3-sprint-u.test.js +0 -174
  74. package/dist/__tests__/layer4-sprint-ba2.test.js +0 -354
  75. package/dist/__tests__/layer4-sprint-ba4.test.js +0 -84
  76. package/dist/__tests__/layer4-sprint-vs.test.js +0 -105
  77. package/dist/__tests__/ledger-chains.test.js +0 -162
  78. package/dist/__tests__/lifecycle-machine.test.js +0 -226
  79. package/dist/__tests__/local-chat-provider.test.js +0 -170
  80. package/dist/__tests__/local-convention-detector.test.js +0 -308
  81. package/dist/__tests__/local-embeddings.test.js +0 -422
  82. package/dist/__tests__/local-graph.test.js +0 -540
  83. package/dist/__tests__/local-indexer.test.js +0 -228
  84. package/dist/__tests__/local-intelligence-l3.test.js +0 -332
  85. package/dist/__tests__/local-llm.test.js +0 -253
  86. package/dist/__tests__/local-mode-offline.test.js +0 -187
  87. package/dist/__tests__/local-mode-stats.test.js +0 -273
  88. package/dist/__tests__/local-mode-tui.test.js +0 -343
  89. package/dist/__tests__/local-parse.test.js +0 -199
  90. package/dist/__tests__/log-tailer.test.js +0 -208
  91. package/dist/__tests__/loop-breaker.test.js +0 -276
  92. package/dist/__tests__/loop-miner.test.js +0 -226
  93. package/dist/__tests__/mcp-config.test.js +0 -126
  94. package/dist/__tests__/mcp-content-json.test.js +0 -10
  95. package/dist/__tests__/mcp-envelope.test.js +0 -124
  96. package/dist/__tests__/metrics-store.test.js +0 -223
  97. package/dist/__tests__/native-watcher.test.js +0 -191
  98. package/dist/__tests__/navigation-hooks-agent-aware.test.js +0 -145
  99. package/dist/__tests__/negative-knowledge.test.js +0 -116
  100. package/dist/__tests__/network-boundary.test.js +0 -190
  101. package/dist/__tests__/network-firewall.test.js +0 -112
  102. package/dist/__tests__/nudge-invariants.test.js +0 -160
  103. package/dist/__tests__/nudge-v2.test.js +0 -225
  104. package/dist/__tests__/offline-rewind.test.js +0 -251
  105. package/dist/__tests__/open-threads.test.js +0 -89
  106. package/dist/__tests__/output-compressor.test.js +0 -93
  107. package/dist/__tests__/pending-violations.test.js +0 -112
  108. package/dist/__tests__/persistence-effectiveness.test.js +0 -143
  109. package/dist/__tests__/provider-factory.test.js +0 -42
  110. package/dist/__tests__/providers.test.js +0 -24
  111. package/dist/__tests__/proxy.test.js +0 -314
  112. package/dist/__tests__/query-router.test.js +0 -1018
  113. package/dist/__tests__/reasoning-quality-route.test.js +0 -138
  114. package/dist/__tests__/redactor.test.js +0 -120
  115. package/dist/__tests__/resource-monitor.test.js +0 -57
  116. package/dist/__tests__/response-envelope.test.js +0 -100
  117. package/dist/__tests__/risk-classifier.test.js +0 -101
  118. package/dist/__tests__/risk-signal-scope.test.js +0 -75
  119. package/dist/__tests__/rule-evaluator.test.js +0 -280
  120. package/dist/__tests__/scip-decoder.test.js +0 -49
  121. package/dist/__tests__/scip-downloader.test.js +0 -201
  122. package/dist/__tests__/scip-merger.test.js +0 -103
  123. package/dist/__tests__/search-index.test.js +0 -422
  124. package/dist/__tests__/semantic-enrichment.test.js +0 -360
  125. package/dist/__tests__/session-brief-builder.test.js +0 -187
  126. package/dist/__tests__/session-context.test.js +0 -221
  127. package/dist/__tests__/session-continuity.test.js +0 -144
  128. package/dist/__tests__/session-dedup.test.js +0 -74
  129. package/dist/__tests__/session-event-wiring.test.js +0 -206
  130. package/dist/__tests__/session-events.test.js +0 -149
  131. package/dist/__tests__/session-legend.test.js +0 -20
  132. package/dist/__tests__/session-persistence.test.js +0 -131
  133. package/dist/__tests__/session-resume-block.test.js +0 -107
  134. package/dist/__tests__/session-resume.test.js +0 -97
  135. package/dist/__tests__/session-summary-writer.test.js +0 -134
  136. package/dist/__tests__/shadow-ledger.test.js +0 -203
  137. package/dist/__tests__/shell-classifier.test.js +0 -151
  138. package/dist/__tests__/shell-compression-floor.test.js +0 -189
  139. package/dist/__tests__/shell-compression-v2.test.js +0 -339
  140. package/dist/__tests__/shell-compressor.test.js +0 -35
  141. package/dist/__tests__/shell-hooks.test.js +0 -128
  142. package/dist/__tests__/shell-strategies.test.js +0 -644
  143. package/dist/__tests__/shell-tee.test.js +0 -133
  144. package/dist/__tests__/signal-dedup.test.js +0 -158
  145. package/dist/__tests__/signal-reinforcer.test.js +0 -77
  146. package/dist/__tests__/signal-scorer.test.js +0 -251
  147. package/dist/__tests__/signal-show-store.test.js +0 -108
  148. package/dist/__tests__/smart-truncate.test.js +0 -215
  149. package/dist/__tests__/snapshot-v2.test.js +0 -113
  150. package/dist/__tests__/sprint-l1-local-mode.test.js +0 -130
  151. package/dist/__tests__/sprint-l10-boot.test.js +0 -220
  152. package/dist/__tests__/sprint-l9-offline-commands.test.js +0 -189
  153. package/dist/__tests__/sprint-q-persistent-context.test.js +0 -198
  154. package/dist/__tests__/sprint-s1-wiring.test.js +0 -215
  155. package/dist/__tests__/sprint-s2-wiring.test.js +0 -256
  156. package/dist/__tests__/sprint-s3-wiring.test.js +0 -195
  157. package/dist/__tests__/sprint-s4-wiring.test.js +0 -213
  158. package/dist/__tests__/sprint-s6-hooks.test.js +0 -222
  159. package/dist/__tests__/sprint-s7-persistent.test.js +0 -263
  160. package/dist/__tests__/sprint-s8-value.test.js +0 -167
  161. package/dist/__tests__/sprint-s9-behavioral.test.js +0 -179
  162. package/dist/__tests__/sprint3-intelligence.test.js +0 -297
  163. package/dist/__tests__/sprint5-mcp-server.test.js +0 -136
  164. package/dist/__tests__/startup-display.test.js +0 -302
  165. package/dist/__tests__/startup-log-file.test.js +0 -97
  166. package/dist/__tests__/stash-manager.test.js +0 -229
  167. package/dist/__tests__/state-detector.test.js +0 -92
  168. package/dist/__tests__/status-dashboard.test.js +0 -142
  169. package/dist/__tests__/temporal-facts.test.js +0 -292
  170. package/dist/__tests__/temporal-routes.test.js +0 -142
  171. package/dist/__tests__/test-detector.test.js +0 -174
  172. package/dist/__tests__/theme.test.js +0 -72
  173. package/dist/__tests__/timeline-agents.test.js +0 -122
  174. package/dist/__tests__/timeline-bootstrap.test.js +0 -176
  175. package/dist/__tests__/timeline-filters.test.js +0 -193
  176. package/dist/__tests__/timeline-markers.test.js +0 -151
  177. package/dist/__tests__/timeline-routes.test.js +0 -156
  178. package/dist/__tests__/timeline-store.test.js +0 -171
  179. package/dist/__tests__/token-counter.test.js +0 -86
  180. package/dist/__tests__/token-estimator.test.js +0 -96
  181. package/dist/__tests__/token-flow-api.test.js +0 -239
  182. package/dist/__tests__/token-flow-instrumentation.test.js +0 -437
  183. package/dist/__tests__/token-flow-persistence.test.js +0 -356
  184. package/dist/__tests__/token-flow-routes.test.js +0 -199
  185. package/dist/__tests__/token-flow.test.js +0 -695
  186. package/dist/__tests__/tool-clusters.test.js +0 -177
  187. package/dist/__tests__/transport-mux.test.js +0 -283
  188. package/dist/__tests__/turn-segmenter.test.js +0 -166
  189. package/dist/__tests__/uninstall.test.js +0 -141
  190. package/dist/__tests__/warm-start-policy.test.js +0 -271
  191. package/dist/__tests__/wire-cap-nudge.test.js +0 -77
  192. package/dist/__tests__/worker-pool.test.js +0 -101
  193. package/dist/ui/assets/index-7gl3mIuY.css +0 -1
  194. package/dist/ui/assets/index-CX4FCWGT.js +0 -10
  195. package/dist/ui/assets/rolldown-runtime-S-ySWqyJ.js +0 -1
  196. package/dist/ui/assets/vis-network-NIJHUFI3.js +0 -908
  197. package/dist/ui/fonts/jetbrains-mono-latin-400-normal.woff +0 -0
  198. package/dist/ui/icon-wordmark.png +0 -0
  199. package/dist/ui/icon-wordmark.svg +0 -30
  200. package/dist/ui/icon.png +0 -0
  201. package/dist/ui/icon.svg +0 -25
  202. package/dist/ui/index.html +0 -15
  203. package/dist/ui/prototype-sandbox/index.html +0 -257
  204. package/dist/ui/screenshots/activity.png +0 -0
  205. package/dist/ui/screenshots/code-base-intelligence.png +0 -0
  206. package/dist/ui/screenshots/dashboard.png +0 -0
  207. package/dist/ui/screenshots/project-memory.png +0 -0
  208. package/dist/ui/screenshots/reasoning-quality.png +0 -0
  209. package/dist/ui/screenshots/reasoning-session.png +0 -0
  210. package/dist/ui/screenshots/token-session.png +0 -0
  211. package/dist/ui/screenshots/token-trace-main.png +0 -0
  212. package/dist/ui/screenshots/token-turn.png +0 -0
  213. package/dist/ui/unerr-wordmark.png +0 -0
  214. package/dist/ui/unerr-wordmark.svg +0 -9
  215. package/dist/ui/unerr.png +0 -0
  216. package/dist/ui/unerr.svg +0 -25
  217. package/dist/ui/web-app-manifest-192x192.png +0 -0
  218. package/dist/ui/web-app-manifest-512x512.png +0 -0
@@ -1,133 +0,0 @@
1
- import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync, } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, describe, expect, it } from "vitest";
5
- import { cleanupOldTees, teeShellOutput } from "../proxy/shell-tee.js";
6
- function makeTempDir() {
7
- const dir = join(tmpdir(), `shell-tee-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
8
- mkdirSync(dir, { recursive: true });
9
- return dir;
10
- }
11
- describe("teeShellOutput", () => {
12
- const dirs = [];
13
- afterEach(() => {
14
- for (const d of dirs) {
15
- try {
16
- rmSync(d, { recursive: true, force: true });
17
- }
18
- catch {
19
- /* ignore */
20
- }
21
- }
22
- dirs.length = 0;
23
- });
24
- it("saves output when ratio > 30% and raw > 1KB", () => {
25
- const cwd = makeTempDir();
26
- dirs.push(cwd);
27
- const raw = "x".repeat(2000);
28
- const compressed = "x".repeat(500); // 75% ratio
29
- const result = teeShellOutput(cwd, "pnpm test", raw, compressed);
30
- expect(result).not.toBeNull();
31
- expect(result.filePath).toContain(".unerr/tee/");
32
- expect(result.filePath).toContain("pnpm-test");
33
- expect(result.sizeBytes).toBeGreaterThan(raw.length);
34
- const content = readFileSync(result.filePath, "utf8");
35
- expect(content).toContain("# command: pnpm test");
36
- expect(content).toContain("# raw_bytes: 2000");
37
- expect(content).toContain("ratio: 75.0%");
38
- expect(content).toContain(raw);
39
- });
40
- it("returns null when raw is too small (< 1KB)", () => {
41
- const cwd = makeTempDir();
42
- dirs.push(cwd);
43
- const raw = "x".repeat(500);
44
- const compressed = "y".repeat(100);
45
- expect(teeShellOutput(cwd, "echo hi", raw, compressed)).toBeNull();
46
- });
47
- it("returns null when compression ratio < 30%", () => {
48
- const cwd = makeTempDir();
49
- dirs.push(cwd);
50
- const raw = "x".repeat(2000);
51
- const compressed = "x".repeat(1800); // only 10% ratio
52
- expect(teeShellOutput(cwd, "ls", raw, compressed)).toBeNull();
53
- });
54
- it("generates sanitized slug from command", () => {
55
- const cwd = makeTempDir();
56
- dirs.push(cwd);
57
- const raw = "x".repeat(2000);
58
- const compressed = "x".repeat(500);
59
- const result = teeShellOutput(cwd, "kubectl describe pod/my-app", raw, compressed);
60
- expect(result).not.toBeNull();
61
- expect(result.filePath).toContain("kubectl-describe");
62
- });
63
- it("includes metadata header in tee file", () => {
64
- const cwd = makeTempDir();
65
- dirs.push(cwd);
66
- const raw = "line\n".repeat(500);
67
- const compressed = "summary";
68
- const result = teeShellOutput(cwd, "git log --stat", raw, compressed);
69
- expect(result).not.toBeNull();
70
- const content = readFileSync(result.filePath, "utf8");
71
- expect(content).toMatch(/^# unerr tee/);
72
- expect(content).toContain("# command: git log --stat");
73
- expect(content).toContain("# captured:");
74
- expect(content).toContain("# raw_bytes:");
75
- expect(content).toContain("# ---");
76
- });
77
- });
78
- describe("cleanupOldTees", () => {
79
- const dirs = [];
80
- afterEach(() => {
81
- for (const d of dirs) {
82
- try {
83
- rmSync(d, { recursive: true, force: true });
84
- }
85
- catch {
86
- /* ignore */
87
- }
88
- }
89
- dirs.length = 0;
90
- });
91
- it("deletes files older than maxAge", () => {
92
- const teeDir = makeTempDir();
93
- dirs.push(teeDir);
94
- // Create an "old" file with mtime in the past
95
- const oldFile = join(teeDir, "old-file.txt");
96
- writeFileSync(oldFile, "old content");
97
- // Set mtime to 48h ago
98
- const fs = require("node:fs");
99
- const past = new Date(Date.now() - 48 * 60 * 60 * 1000);
100
- fs.utimesSync(oldFile, past, past);
101
- // Create a "new" file
102
- writeFileSync(join(teeDir, "new-file.txt"), "new content");
103
- const deleted = cleanupOldTees(teeDir, 24 * 60 * 60 * 1000);
104
- expect(deleted).toBe(1);
105
- const remaining = readdirSync(teeDir).filter((f) => f.endsWith(".txt"));
106
- expect(remaining).toHaveLength(1);
107
- expect(remaining[0]).toBe("new-file.txt");
108
- });
109
- it("enforces MAX_TEE_FILES limit (keeps newest)", () => {
110
- const teeDir = makeTempDir();
111
- dirs.push(teeDir);
112
- // Create 55 files with staggered mtimes
113
- const fs = require("node:fs");
114
- for (let i = 0; i < 55; i++) {
115
- const f = join(teeDir, `file-${String(i).padStart(3, "0")}.txt`);
116
- writeFileSync(f, `content ${i}`);
117
- const t = new Date(Date.now() - (55 - i) * 1000); // newer files have higher i
118
- fs.utimesSync(f, t, t);
119
- }
120
- const deleted = cleanupOldTees(teeDir, 24 * 60 * 60 * 1000);
121
- expect(deleted).toBe(5); // 55 - 50 = 5
122
- const remaining = readdirSync(teeDir).filter((f) => f.endsWith(".txt"));
123
- expect(remaining).toHaveLength(50);
124
- });
125
- it("returns 0 for empty directory", () => {
126
- const teeDir = makeTempDir();
127
- dirs.push(teeDir);
128
- expect(cleanupOldTees(teeDir)).toBe(0);
129
- });
130
- it("returns 0 for nonexistent directory", () => {
131
- expect(cleanupOldTees("/tmp/nonexistent-tee-dir-12345")).toBe(0);
132
- });
133
- });
@@ -1,158 +0,0 @@
1
- /**
2
- * Signal dedup — policy matrix coverage for shouldEmit + wouldEmit.
3
- *
4
- * Three policies under test:
5
- * - always: every call emits (hlt/dft/hth)
6
- * - on_change: first call emits, repeats with same content suppress, content
7
- * change re-emits (rsk/fct/hnt/...)
8
- * - once_per_session: first call emits, all subsequent calls suppress (wrn)
9
- * - drop: never emits (ctx)
10
- *
11
- * wouldEmit is the non-mutating peek used by upstream rankers. It MUST return
12
- * the same boolean as shouldEmit would, without recording the emission.
13
- */
14
- import { describe, expect, it } from "vitest";
15
- import { DEFAULT_POLICY, createSignalDedup } from "../proxy/signal-dedup.js";
16
- describe("signal-dedup", () => {
17
- describe("shouldEmit", () => {
18
- it("always-policy tags emit every call", () => {
19
- const d = createSignalDedup();
20
- for (const tag of ["hlt", "dft", "hth"]) {
21
- expect(d.shouldEmit(tag, "e", "msg")).toBe(true);
22
- expect(d.shouldEmit(tag, "e", "msg")).toBe(true);
23
- expect(d.shouldEmit(tag, "e", "msg")).toBe(true);
24
- }
25
- });
26
- it("on_change emits first, suppresses repeats, re-emits on content change", () => {
27
- const d = createSignalDedup();
28
- expect(d.shouldEmit("rsk", "fn", "fan_in=24")).toBe(true);
29
- expect(d.shouldEmit("rsk", "fn", "fan_in=24")).toBe(false);
30
- expect(d.shouldEmit("rsk", "fn", "fan_in=24")).toBe(false);
31
- expect(d.shouldEmit("rsk", "fn", "fan_in=30")).toBe(true);
32
- expect(d.shouldEmit("rsk", "fn", "fan_in=30")).toBe(false);
33
- });
34
- it("on_change scopes by entity — different entities are independent", () => {
35
- const d = createSignalDedup();
36
- expect(d.shouldEmit("rsk", "a", "msg")).toBe(true);
37
- expect(d.shouldEmit("rsk", "b", "msg")).toBe(true);
38
- expect(d.shouldEmit("rsk", "a", "msg")).toBe(false);
39
- expect(d.shouldEmit("rsk", "b", "msg")).toBe(false);
40
- });
41
- it("on_change with null entity uses 'global' scope", () => {
42
- const d = createSignalDedup();
43
- expect(d.shouldEmit("fct", null, "x")).toBe(true);
44
- expect(d.shouldEmit("fct", null, "x")).toBe(false);
45
- });
46
- it("wrn uses on_change — same content suppressed, different content/scope re-emits", () => {
47
- const d = createSignalDedup();
48
- // Same (scope, content) — suppressed.
49
- expect(d.shouldEmit("wrn", "e", "anti-pattern")).toBe(true);
50
- expect(d.shouldEmit("wrn", "e", "anti-pattern")).toBe(false);
51
- // Different content on same scope — emits.
52
- expect(d.shouldEmit("wrn", "e", "different message")).toBe(true);
53
- // Different scope, same content — emits.
54
- expect(d.shouldEmit("wrn", "other", "anti-pattern")).toBe(true);
55
- });
56
- it("once_per_session via policy override suppresses regardless of content", () => {
57
- const d = createSignalDedup({ wrn: "once_per_session" });
58
- expect(d.shouldEmit("wrn", "e", "anti-pattern")).toBe(true);
59
- expect(d.shouldEmit("wrn", "e", "anti-pattern")).toBe(false);
60
- expect(d.shouldEmit("wrn", "e", "different message")).toBe(false);
61
- });
62
- it("drop policy never emits (ctx)", () => {
63
- const d = createSignalDedup();
64
- expect(d.shouldEmit("ctx", "e", "context")).toBe(false);
65
- expect(d.shouldEmit("ctx", null, "context")).toBe(false);
66
- });
67
- it("unknown tags default to on_change", () => {
68
- const d = createSignalDedup();
69
- expect(d.shouldEmit("xyz", "e", "msg")).toBe(true);
70
- expect(d.shouldEmit("xyz", "e", "msg")).toBe(false);
71
- expect(d.shouldEmit("xyz", "e", "msg2")).toBe(true);
72
- });
73
- it("policy override changes behavior per-tag", () => {
74
- const d = createSignalDedup({ rsk: "always" });
75
- expect(d.shouldEmit("rsk", "e", "msg")).toBe(true);
76
- expect(d.shouldEmit("rsk", "e", "msg")).toBe(true);
77
- expect(d.shouldEmit("rsk", "e", "msg")).toBe(true);
78
- });
79
- });
80
- describe("wouldEmit (non-mutating peek)", () => {
81
- it("returns same boolean as shouldEmit on fresh state", () => {
82
- const d = createSignalDedup();
83
- expect(d.wouldEmit("rsk", "e", "x")).toBe(true);
84
- expect(d.wouldEmit("wrn", "e", "x")).toBe(true);
85
- expect(d.wouldEmit("ctx", "e", "x")).toBe(false);
86
- expect(d.wouldEmit("hlt", "e", "x")).toBe(true);
87
- });
88
- it("does NOT record emission — multiple peeks still return true", () => {
89
- const d = createSignalDedup();
90
- expect(d.wouldEmit("rsk", "e", "x")).toBe(true);
91
- expect(d.wouldEmit("rsk", "e", "x")).toBe(true);
92
- expect(d.wouldEmit("rsk", "e", "x")).toBe(true);
93
- // And the subsequent real emit still succeeds — proves no mutation.
94
- expect(d.shouldEmit("rsk", "e", "x")).toBe(true);
95
- });
96
- it("reflects on_change state after shouldEmit recorded it", () => {
97
- const d = createSignalDedup();
98
- d.shouldEmit("rsk", "e", "x");
99
- expect(d.wouldEmit("rsk", "e", "x")).toBe(false);
100
- expect(d.wouldEmit("rsk", "e", "y")).toBe(true);
101
- });
102
- it("reflects on_change state for wrn after shouldEmit recorded it", () => {
103
- const d = createSignalDedup();
104
- d.shouldEmit("wrn", "e", "x");
105
- expect(d.wouldEmit("wrn", "e", "x")).toBe(false); // same content — suppressed
106
- expect(d.wouldEmit("wrn", "e", "y")).toBe(true); // different content — emits
107
- });
108
- it("reflects once_per_session state via policy override", () => {
109
- const d = createSignalDedup({ wrn: "once_per_session" });
110
- d.shouldEmit("wrn", "e", "x");
111
- expect(d.wouldEmit("wrn", "e", "x")).toBe(false);
112
- expect(d.wouldEmit("wrn", "e", "y")).toBe(false);
113
- });
114
- it("always-policy tags always peek true regardless of state", () => {
115
- const d = createSignalDedup();
116
- d.shouldEmit("hlt", "e", "x");
117
- d.shouldEmit("hlt", "e", "x");
118
- expect(d.wouldEmit("hlt", "e", "x")).toBe(true);
119
- });
120
- it("drop-policy tags always peek false", () => {
121
- const d = createSignalDedup();
122
- expect(d.wouldEmit("ctx", "e", "x")).toBe(false);
123
- d.shouldEmit("ctx", "e", "x");
124
- expect(d.wouldEmit("ctx", "e", "x")).toBe(false);
125
- });
126
- });
127
- describe("reset and size", () => {
128
- it("size grows with on_change emissions, reset clears", () => {
129
- const d = createSignalDedup();
130
- expect(d.size()).toBe(0);
131
- d.shouldEmit("rsk", "a", "x");
132
- d.shouldEmit("rsk", "b", "x");
133
- expect(d.size()).toBe(2);
134
- d.reset();
135
- expect(d.size()).toBe(0);
136
- // After reset, re-emission is allowed.
137
- expect(d.shouldEmit("rsk", "a", "x")).toBe(true);
138
- });
139
- it("always-policy emissions do not grow the table", () => {
140
- const d = createSignalDedup();
141
- d.shouldEmit("hlt", "a", "x");
142
- d.shouldEmit("hlt", "b", "y");
143
- expect(d.size()).toBe(0);
144
- });
145
- });
146
- describe("DEFAULT_POLICY snapshot", () => {
147
- it("matches expected per-tag policies", () => {
148
- expect(DEFAULT_POLICY.hlt).toBe("always");
149
- expect(DEFAULT_POLICY.dft).toBe("always");
150
- expect(DEFAULT_POLICY.hth).toBe("always");
151
- expect(DEFAULT_POLICY.rsk).toBe("on_change");
152
- expect(DEFAULT_POLICY.fct).toBe("on_change");
153
- expect(DEFAULT_POLICY.hnt).toBe("on_change");
154
- expect(DEFAULT_POLICY.wrn).toBe("on_change");
155
- expect(DEFAULT_POLICY.ctx).toBe("drop");
156
- });
157
- });
158
- });
@@ -1,77 +0,0 @@
1
- /**
2
- * ST-5: Signal reinforcement + decay. Confirms facts.db is NEVER touched.
3
- */
4
- import { existsSync, mkdirSync, rmSync } from "node:fs";
5
- import { tmpdir } from "node:os";
6
- import { join } from "node:path";
7
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
8
- import { pruneStaleSignals, reinforceSignal, } from "../timeline/signal-reinforcer.js";
9
- import { CozoTimelineStore } from "../timeline/timeline-store.js";
10
- let tempDir;
11
- let store;
12
- beforeEach(async () => {
13
- tempDir = join(tmpdir(), `unerr-sr-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
14
- mkdirSync(join(tempDir, ".unerr"), { recursive: true });
15
- store = await CozoTimelineStore.create(tempDir);
16
- });
17
- afterEach(() => {
18
- try {
19
- store.close();
20
- }
21
- catch {
22
- /* ignore */
23
- }
24
- try {
25
- rmSync(tempDir, { recursive: true, force: true });
26
- }
27
- catch {
28
- /* ignore */
29
- }
30
- });
31
- describe("reinforceSignal", () => {
32
- it("creates a signal on first call and writes a reinforcement event", async () => {
33
- const sig = await reinforceSignal(store, { type: "hot_file", scope: "src/auth.ts" }, 0.2, "loop_miner", { nowMs: 1_000 });
34
- expect(sig.signal_id).toBeTruthy();
35
- expect(sig.confidence).toBeCloseTo(0.7);
36
- const history = await store.getReinforcementHistory(sig.signal_id);
37
- expect(history).toHaveLength(1);
38
- expect(history[0]?.delta).toBe(0.2);
39
- expect(history[0]?.source).toBe("loop_miner");
40
- });
41
- it("reinforces an existing signal — confidence clamps to [0, 1]", async () => {
42
- const a = await reinforceSignal(store, { type: "hot_file", scope: "src/auth.ts" }, 0.3, "src", { nowMs: 1_000 });
43
- const b = await reinforceSignal(store, { type: "hot_file", scope: "src/auth.ts" }, 0.6, "src", { nowMs: 2_000 });
44
- expect(b.signal_id).toBe(a.signal_id);
45
- expect(b.confidence).toBeLessThanOrEqual(1);
46
- expect(b.confidence).toBeCloseTo(1); // 0.8 + 0.6 → clamped to 1
47
- const c = await reinforceSignal(store, { type: "hot_file", scope: "src/auth.ts" }, -0.7, "contradiction", { nowMs: 3_000 });
48
- expect(c.confidence).toBeCloseTo(0.3);
49
- const history = await store.getReinforcementHistory(c.signal_id);
50
- expect(history).toHaveLength(3);
51
- });
52
- it("does not write to facts.db", async () => {
53
- await reinforceSignal(store, { type: "hot_file", scope: "src/auth.ts" }, 0.1, "src", { nowMs: 1_000 });
54
- // facts.db must not have been created by anything in the reinforcer path.
55
- expect(existsSync(join(tempDir, ".unerr", "facts.db"))).toBe(false);
56
- });
57
- });
58
- describe("pruneStaleSignals", () => {
59
- it("removes signals last seen before the cutoff", async () => {
60
- await reinforceSignal(store, { type: "hot_file", scope: "src/old.ts" }, 0.2, "src", { nowMs: 1_000 });
61
- await reinforceSignal(store, { type: "hot_file", scope: "src/new.ts" }, 0.2, "src", { nowMs: 30 * 24 * 60 * 60_000 });
62
- const removed = await pruneStaleSignals(store, {
63
- staleAfterMs: 14 * 24 * 60 * 60_000,
64
- nowMs: 30 * 24 * 60 * 60_000 + 1_000,
65
- });
66
- expect(removed).toBe(1);
67
- const remaining = await store.listSignals();
68
- expect(remaining).toHaveLength(1);
69
- expect(remaining[0]?.scope).toBe("src/new.ts");
70
- });
71
- it("returns 0 when nothing is stale", async () => {
72
- const now = Date.now();
73
- await reinforceSignal(store, { type: "loop", scope: "src/x.ts" }, 0.1, "src", { nowMs: now });
74
- const removed = await pruneStaleSignals(store, { nowMs: now });
75
- expect(removed).toBe(0);
76
- });
77
- });
@@ -1,251 +0,0 @@
1
- // @ts-nocheck — test file, array index access is intentional
2
- /**
3
- * Signal Scorer tests — scoring formula, ranking, burst multipliers, convention signals.
4
- */
5
- import { describe, expect, it } from "vitest";
6
- import { SignalScorer, getSignalScorer, } from "../intelligence/signal-scorer.js";
7
- describe("SignalScorer", () => {
8
- const scorer = new SignalScorer();
9
- describe("contextToSignals", () => {
10
- it("converts blast_radius to warning signal", () => {
11
- const raw = {
12
- blast_radius: "5 direct callers, 3 callees",
13
- };
14
- const signals = scorer.contextToSignals(raw, "get_entity", {});
15
- expect(signals).toHaveLength(1);
16
- expect(signals[0].type).toBe("warning");
17
- expect(signals[0].content).toContain("5 direct callers");
18
- expect(signals[0].actionability).toBe(0.9);
19
- expect(signals[0].source).toBe("graph");
20
- expect(signals[0].action).toBeDefined();
21
- });
22
- it("converts pending_violations to warning signals (max 3)", () => {
23
- const raw = {
24
- pending_violations: [
25
- { file: "a.ts", rule: "naming", message: "bad name", line: 10 },
26
- { file: "b.ts", rule: "style", message: "wrong indent" },
27
- { file: "c.ts", rule: "error", message: "missing catch", line: 5 },
28
- { file: "d.ts", rule: "extra", message: "should be capped" },
29
- ],
30
- };
31
- const signals = scorer.contextToSignals(raw, "get_entity", {});
32
- expect(signals).toHaveLength(3); // capped at 3
33
- expect(signals.every((s) => s.type === "warning")).toBe(true);
34
- expect(signals[0].content).toContain("a.ts");
35
- expect(signals[0].action).toContain("naming");
36
- expect(signals[0].action).toContain("line 10");
37
- // Second violation has no line
38
- expect(signals[1].action).toBe("Fix: style");
39
- });
40
- it("converts conventions to guidance signals (max 3)", () => {
41
- const raw = {
42
- conventions: [
43
- "Error handler: wrap in try/catch (90% adherence)",
44
- "Naming: camelCase (85% adherence)",
45
- ],
46
- };
47
- const signals = scorer.contextToSignals(raw, "get_entity", {});
48
- expect(signals).toHaveLength(2);
49
- expect(signals.every((s) => s.type === "guidance")).toBe(true);
50
- expect(signals[0].actionability).toBe(0.7);
51
- expect(signals[0].source).toBe("graph");
52
- });
53
- it("converts relevant_facts with episodic prefix to history signal", () => {
54
- const raw = {
55
- relevant_facts: ["[episodic] Modified doStuff to add error handling"],
56
- };
57
- const signals = scorer.contextToSignals(raw, "get_entity", {});
58
- expect(signals).toHaveLength(1);
59
- expect(signals[0].type).toBe("history");
60
- expect(signals[0].actionability).toBe(0.7);
61
- // Episodic fact action now names the concrete tool call to make
62
- // divergence visible in the timeline.
63
- expect(signals[0].action).toContain("mark_decision");
64
- });
65
- it("converts relevant_facts with negative prefix to warning signal", () => {
66
- const raw = {
67
- relevant_facts: ["[negative] This pattern caused bugs before"],
68
- };
69
- const signals = scorer.contextToSignals(raw, "get_entity", {});
70
- expect(signals).toHaveLength(1);
71
- expect(signals[0].type).toBe("warning");
72
- // Negative facts boosted to 0.85 (Issue #4 fix — anti-pattern facts must
73
- // outrank co-change hnt even at low decision level cap=2).
74
- expect(signals[0].actionability).toBe(0.85);
75
- });
76
- it("converts drift_alert to warning signal", () => {
77
- const raw = {
78
- drift_alert: "WARNING: entity modified since last index",
79
- };
80
- const signals = scorer.contextToSignals(raw, "get_entity", {});
81
- expect(signals).toHaveLength(1);
82
- expect(signals[0].type).toBe("warning");
83
- expect(signals[0].source).toBe("graph");
84
- });
85
- it("converts community to context signal", () => {
86
- const raw = {
87
- community: "Part of auth module (12 entities)",
88
- };
89
- const signals = scorer.contextToSignals(raw, "get_entity", {});
90
- expect(signals).toHaveLength(1);
91
- expect(signals[0].type).toBe("context");
92
- expect(signals[0].actionability).toBe(0.4);
93
- });
94
- it("handles empty raw context", () => {
95
- const signals = scorer.contextToSignals({}, "get_entity", {});
96
- expect(signals).toHaveLength(0);
97
- });
98
- it("handles all fields simultaneously", () => {
99
- const raw = {
100
- blast_radius: "3 callers",
101
- conventions: ["naming: camelCase"],
102
- drift_alert: "WARNING: drift",
103
- corrections: ["fix this"],
104
- community: "auth module",
105
- reminder: "previously queried",
106
- history: ["changed last session"],
107
- };
108
- const signals = scorer.contextToSignals(raw, "get_entity", {});
109
- // blast_radius(1) + conventions(1) + drift(1) + corrections(1) + community(1) + reminder(1) + history(1) = 7
110
- expect(signals.length).toBe(7);
111
- });
112
- });
113
- describe("composite score formula", () => {
114
- it("computes actionability^1.5 * relevance * confidence", () => {
115
- const raw = {
116
- blast_radius: "test",
117
- };
118
- const signals = scorer.contextToSignals(raw, "get_entity", {});
119
- const s = signals[0];
120
- const expected = s.actionability ** 1.5 * s.relevance * s.confidence;
121
- expect(s.composite_score).toBeCloseTo(expected, 10);
122
- });
123
- it("higher actionability gives disproportionately higher score", () => {
124
- // Warning (actionability 0.9) vs context (actionability 0.4)
125
- const raw = {
126
- blast_radius: "test",
127
- community: "test",
128
- };
129
- const signals = scorer.contextToSignals(raw, "get_entity", {});
130
- const warning = signals.find((s) => s.type === "warning");
131
- const context = signals.find((s) => s.type === "context");
132
- // Ratio should be > 0.9/0.4 due to exponent
133
- expect(warning.composite_score).toBeGreaterThan(context.composite_score * 2);
134
- });
135
- });
136
- describe("rank", () => {
137
- it("returns top N signals by composite score", () => {
138
- const raw = {
139
- blast_radius: "3 callers",
140
- conventions: ["naming: camelCase", "style: semicolons"],
141
- community: "auth module",
142
- reminder: "previously queried",
143
- history: ["session 1", "session 2"],
144
- };
145
- const signals = scorer.contextToSignals(raw, "get_entity", {});
146
- const ranked = scorer.rank(signals, 3);
147
- expect(ranked).toHaveLength(3);
148
- // Should be sorted descending by composite_score
149
- expect(ranked[0].composite_score).toBeGreaterThanOrEqual(ranked[1].composite_score);
150
- expect(ranked[1].composite_score).toBeGreaterThanOrEqual(ranked[2].composite_score);
151
- });
152
- it("returns empty array for empty input", () => {
153
- expect(scorer.rank([], 3)).toHaveLength(0);
154
- });
155
- it("returns all signals when fewer than maxSignals", () => {
156
- const raw = { blast_radius: "test" };
157
- const signals = scorer.contextToSignals(raw, "get_entity", {});
158
- const ranked = scorer.rank(signals, 5);
159
- expect(ranked).toHaveLength(1);
160
- });
161
- it("defaults to max 3 signals", () => {
162
- const raw = {
163
- blast_radius: "test",
164
- drift_alert: "test",
165
- conventions: ["a", "b", "c"],
166
- community: "test",
167
- };
168
- const signals = scorer.contextToSignals(raw, "get_entity", {});
169
- const ranked = scorer.rank(signals);
170
- expect(ranked).toHaveLength(3);
171
- });
172
- });
173
- describe("applyBurstMultipliers", () => {
174
- it("does not modify signals for non-high decision level", () => {
175
- const raw = { blast_radius: "test" };
176
- const signals = scorer.contextToSignals(raw, "get_entity", {});
177
- const original = signals[0].composite_score;
178
- const boosted = scorer.applyBurstMultipliers(signals, "medium");
179
- expect(boosted[0].composite_score).toBe(original);
180
- });
181
- it("boosts warning relevance at high decision level", () => {
182
- const raw = { blast_radius: "test" };
183
- const signals = scorer.contextToSignals(raw, "get_entity", {});
184
- const original = signals[0].composite_score;
185
- const boosted = scorer.applyBurstMultipliers(signals, "high");
186
- expect(boosted[0].composite_score).toBeGreaterThan(original);
187
- expect(boosted[0].relevance).toBeGreaterThan(signals[0].relevance);
188
- });
189
- it("boosts history signals more than warnings at high decision level", () => {
190
- const raw = {
191
- blast_radius: "test",
192
- history: ["changed last session"],
193
- };
194
- const signals = scorer.contextToSignals(raw, "get_entity", {});
195
- const warning = signals.find((s) => s.type === "warning");
196
- const history = signals.find((s) => s.type === "history");
197
- const boosted = scorer.applyBurstMultipliers(signals, "high");
198
- const boostedWarning = boosted.find((s) => s.type === "warning");
199
- const boostedHistory = boosted.find((s) => s.type === "history");
200
- // History gets 1.5x, warning gets 1.3x
201
- const warningBoostRatio = boostedWarning.relevance / warning.relevance;
202
- const historyBoostRatio = boostedHistory.relevance / history.relevance;
203
- expect(historyBoostRatio).toBeGreaterThan(warningBoostRatio);
204
- });
205
- it("caps boosted relevance at 1.0", () => {
206
- const raw = {
207
- pending_violations: [{ file: "a.ts", rule: "r", message: "m" }],
208
- };
209
- const signals = scorer.contextToSignals(raw, "get_entity", {});
210
- // pending_violations have relevance 0.95, * 1.3 = 1.235 → capped at 1.0
211
- const boosted = scorer.applyBurstMultipliers(signals, "high");
212
- expect(boosted[0].relevance).toBeLessThanOrEqual(1.0);
213
- });
214
- });
215
- describe("conventionToSignal", () => {
216
- const convention = {
217
- name: "camelCase naming",
218
- rule: "Use camelCase for functions",
219
- adherence_pct: 87,
220
- kind: "function",
221
- };
222
- it("generates prescriptive signal for entity tools", () => {
223
- const signal = scorer.conventionToSignal(convention, "get_entity");
224
- expect(signal.type).toBe("guidance");
225
- expect(signal.content).toContain("Follow");
226
- expect(signal.content).toContain("87%");
227
- expect(signal.action).toContain("Apply pattern");
228
- expect(signal.actionability).toBe(0.8);
229
- });
230
- it("generates descriptive signal for get_conventions", () => {
231
- const signal = scorer.conventionToSignal(convention, "get_conventions");
232
- expect(signal.type).toBe("guidance");
233
- expect(signal.content).toContain("camelCase naming");
234
- expect(signal.content).toContain("87%");
235
- expect(signal.action).toBeUndefined();
236
- expect(signal.actionability).toBe(0.5);
237
- });
238
- it("uses adherence_pct for relevance and confidence", () => {
239
- const signal = scorer.conventionToSignal(convention, "get_entity");
240
- expect(signal.relevance).toBe(0.87);
241
- expect(signal.confidence).toBe(0.87);
242
- });
243
- });
244
- describe("getSignalScorer singleton", () => {
245
- it("returns same instance", () => {
246
- const a = getSignalScorer();
247
- const b = getSignalScorer();
248
- expect(a).toBe(b);
249
- });
250
- });
251
- });