@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,235 +0,0 @@
1
- /**
2
- * ST-4: IntentDetector — Jaccard + marker-anchored stitch, dormant transitions,
3
- * IO orchestrator (runIntentStitch).
4
- */
5
- import { mkdirSync, rmSync } from "node:fs";
6
- import { tmpdir } from "node:os";
7
- import { join } from "node:path";
8
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
9
- import { buildSessionSummaries, jaccard, runIntentStitch, stitchIntents, } from "../timeline/intent-detector.js";
10
- import { CozoTimelineStore, } from "../timeline/timeline-store.js";
11
- function summary(session_id, files, started_at, last_active_at, intent_text) {
12
- return {
13
- session_id,
14
- started_at,
15
- last_active_at: last_active_at ?? started_at,
16
- files: new Set(files),
17
- intent_text,
18
- };
19
- }
20
- describe("jaccard", () => {
21
- it("returns 0 for empty sets", () => {
22
- expect(jaccard(new Set(), new Set())).toBe(0);
23
- });
24
- it("returns 1 for identical non-empty sets", () => {
25
- expect(jaccard(new Set(["a", "b"]), new Set(["b", "a"]))).toBe(1);
26
- });
27
- it("computes overlap correctly", () => {
28
- expect(jaccard(new Set(["a", "b", "c"]), new Set(["b", "c", "d"]))).toBeCloseTo(2 / 4);
29
- });
30
- });
31
- describe("stitchIntents (pure)", () => {
32
- it("creates a fresh intent for the first session", () => {
33
- const sessions = [summary("s1", ["a.ts", "b.ts"], 1000)];
34
- const result = stitchIntents(sessions, [], [], { nowMs: 2000 });
35
- expect(result.intents).toHaveLength(1);
36
- expect(result.intents[0]?.status).toBe("active");
37
- expect(result.attachments).toEqual([
38
- { intent_id: result.intents[0]?.intent_id, session_id: "s1" },
39
- ]);
40
- });
41
- it("attaches a new session via file-set Jaccard when overlap > threshold", () => {
42
- const sessions = [
43
- summary("s1", ["a.ts", "b.ts", "c.ts"], 1_000, 1_500),
44
- summary("s2", ["a.ts", "b.ts", "c.ts", "d.ts"], 2_000, 2_500),
45
- ];
46
- const result = stitchIntents(sessions, [], [], { nowMs: 3000 });
47
- expect(result.intents).toHaveLength(1);
48
- expect(result.attachments.map((a) => a.session_id).sort()).toEqual([
49
- "s1",
50
- "s2",
51
- ]);
52
- });
53
- it("creates a new intent when overlap < threshold", () => {
54
- const sessions = [
55
- summary("s1", ["a.ts", "b.ts"], 1_000, 1_500),
56
- summary("s2", ["x.ts", "y.ts"], 2_000, 2_500),
57
- ];
58
- const result = stitchIntents(sessions, [], [], { nowMs: 3_000 });
59
- expect(result.intents).toHaveLength(2);
60
- });
61
- it("creates a new intent when overlap is fresh but text marker differs", () => {
62
- const sessions = [
63
- summary("s1", ["a.ts", "b.ts", "c.ts"], 1_000, 1_500, "auth refactor"),
64
- summary("s2", ["a.ts", "b.ts", "c.ts"], 2_000, 2_500, "payments cleanup"),
65
- ];
66
- const result = stitchIntents(sessions, [], [], { nowMs: 3_000 });
67
- expect(result.intents).toHaveLength(2);
68
- const titles = result.intents.map((i) => i.title).sort();
69
- expect(titles).toEqual(["auth refactor", "payments cleanup"]);
70
- });
71
- it("transitions intents to dormant after inactivity", () => {
72
- const day = 24 * 60 * 60_000;
73
- const sessions = [summary("s1", ["a.ts"], 0, 1_000)];
74
- const r1 = stitchIntents(sessions, [], [], { nowMs: 30 * day });
75
- expect(r1.intents[0]?.status).toBe("dormant");
76
- expect(r1.dormantTransitions).toEqual([r1.intents[0]?.intent_id]);
77
- });
78
- it("does not re-attach a session that's already attached", () => {
79
- const sessions = [summary("s1", ["a.ts", "b.ts"], 1_000, 1_500)];
80
- const existing = {
81
- intent_id: "i1",
82
- title: "auth",
83
- started_at: 1_000,
84
- last_active_at: 1_500,
85
- file_set: JSON.stringify(["a.ts", "b.ts"]),
86
- file_set_hash: "h",
87
- status: "active",
88
- confidence: 0.5,
89
- source: "file_jaccard",
90
- };
91
- const result = stitchIntents(sessions, [existing], [{ intent_id: "i1", session_id: "s1" }], { nowMs: 2_000 });
92
- expect(result.attachments).toEqual([]);
93
- });
94
- it("respects the freshness window — stale intents don't absorb new sessions", () => {
95
- const day = 24 * 60 * 60_000;
96
- const sessions = [
97
- summary("s1", ["a.ts", "b.ts", "c.ts"], 30 * day, 30 * day + 1_000),
98
- ];
99
- const existing = {
100
- intent_id: "i1",
101
- title: "old work",
102
- started_at: 0,
103
- last_active_at: 1_000,
104
- file_set: JSON.stringify(["a.ts", "b.ts", "c.ts"]),
105
- file_set_hash: "h",
106
- status: "active",
107
- confidence: 0.5,
108
- source: "file_jaccard",
109
- };
110
- const result = stitchIntents(sessions, [existing], [], {
111
- nowMs: 31 * day,
112
- freshnessMs: 14 * day,
113
- });
114
- expect(result.attachments).toHaveLength(1);
115
- expect(result.attachments[0]?.intent_id).not.toBe("i1");
116
- });
117
- });
118
- describe("buildSessionSummaries", () => {
119
- it("groups turns by session and picks first mark_intent", () => {
120
- const turns = [
121
- {
122
- turn_id: "t1",
123
- session_id: "s1",
124
- started_at: 1_000,
125
- ended_at: 1_500,
126
- opened_by: "first_call",
127
- closed_reason: "session_end",
128
- tool_count: 3,
129
- file_count: 2,
130
- edit_count: 0,
131
- title: "",
132
- outcome: "unknown",
133
- },
134
- {
135
- turn_id: "t2",
136
- session_id: "s1",
137
- started_at: 2_000,
138
- ended_at: 2_500,
139
- opened_by: "idle_gap",
140
- closed_reason: "idle_gap",
141
- tool_count: 4,
142
- file_count: 1,
143
- edit_count: 1,
144
- title: "",
145
- outcome: "unknown",
146
- },
147
- ];
148
- const markers = [
149
- {
150
- marker_id: "m1",
151
- type: "mark_intent",
152
- text: "harden auth",
153
- session_id: "s1",
154
- turn_id: "t1",
155
- ts: 1_100,
156
- blocker_ref: "",
157
- file_path: "",
158
- },
159
- ];
160
- const summaries = buildSessionSummaries(turns, markers, new Map([["s1", new Set(["a.ts", "b.ts"])]]));
161
- expect(summaries).toHaveLength(1);
162
- expect(summaries[0]?.intent_text).toBe("harden auth");
163
- expect(summaries[0]?.started_at).toBe(1_000);
164
- expect(summaries[0]?.last_active_at).toBe(2_500);
165
- });
166
- });
167
- describe("runIntentStitch (IO)", () => {
168
- let tempDir;
169
- let store;
170
- beforeEach(async () => {
171
- tempDir = join(tmpdir(), `unerr-istitch-${Date.now()}-${Math.random().toString(36).slice(2)}`);
172
- mkdirSync(join(tempDir, ".unerr"), { recursive: true });
173
- store = await CozoTimelineStore.create(tempDir);
174
- });
175
- afterEach(() => {
176
- try {
177
- store.close();
178
- }
179
- catch {
180
- /* ignore */
181
- }
182
- try {
183
- rmSync(tempDir, { recursive: true, force: true });
184
- }
185
- catch {
186
- /* ignore */
187
- }
188
- });
189
- it("attaches two sessions touching the same files to one intent", async () => {
190
- const baseTs = Date.now();
191
- for (const sid of ["s1", "s2"]) {
192
- await store.upsertTurn({
193
- turn_id: `t-${sid}`,
194
- session_id: sid,
195
- started_at: baseTs,
196
- ended_at: baseTs + 1_000,
197
- opened_by: "first_call",
198
- closed_reason: "session_end",
199
- tool_count: 4,
200
- file_count: 3,
201
- edit_count: 1,
202
- title: "",
203
- outcome: "unknown",
204
- });
205
- await store.recordSessionFiles(sid, ["a.ts", "b.ts", "c.ts"]);
206
- }
207
- const r1 = await runIntentStitch(store);
208
- expect(r1.attached).toBe(2);
209
- const intents = await store.listIntents();
210
- expect(intents).toHaveLength(1);
211
- const sessions = await store.listIntentSessions(intents[0].intent_id);
212
- expect(sessions.sort()).toEqual(["s1", "s2"]);
213
- });
214
- it("is idempotent — re-running does not re-attach sessions", async () => {
215
- const baseTs = Date.now();
216
- await store.upsertTurn({
217
- turn_id: "tt",
218
- session_id: "s1",
219
- started_at: baseTs,
220
- ended_at: baseTs + 1_000,
221
- opened_by: "first_call",
222
- closed_reason: "session_end",
223
- tool_count: 1,
224
- file_count: 1,
225
- edit_count: 0,
226
- title: "",
227
- outcome: "unknown",
228
- });
229
- await store.recordSessionFiles("s1", ["a.ts"]);
230
- const r1 = await runIntentStitch(store);
231
- expect(r1.attached).toBe(1);
232
- const r2 = await runIntentStitch(store);
233
- expect(r2.attached).toBe(0);
234
- });
235
- });
@@ -1,167 +0,0 @@
1
- /**
2
- * Tests for git notes intent encoding (Task 8.1).
3
- */
4
- import { execSync } from "node:child_process";
5
- import { mkdirSync, rmSync } from "node:fs";
6
- import { tmpdir } from "node:os";
7
- import { join } from "node:path";
8
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
9
- import { encodeIntentAsNote } from "../tracking/intent-encoder.js";
10
- describe("Intent Encoder — Git Notes", () => {
11
- let repoDir;
12
- beforeEach(() => {
13
- repoDir = join(tmpdir(), `unerr-test-notes-${Date.now()}`);
14
- mkdirSync(repoDir, { recursive: true });
15
- // Init a git repo with an initial commit
16
- execSync("git init", { cwd: repoDir, stdio: "pipe" });
17
- execSync("git config user.email 'test@test.com'", {
18
- cwd: repoDir,
19
- stdio: "pipe",
20
- });
21
- execSync("git config user.name 'Test'", { cwd: repoDir, stdio: "pipe" });
22
- execSync("echo 'hello' > test.txt", { cwd: repoDir, stdio: "pipe" });
23
- execSync("git add test.txt", { cwd: repoDir, stdio: "pipe" });
24
- execSync("git commit -m 'initial'", { cwd: repoDir, stdio: "pipe" });
25
- });
26
- afterEach(() => {
27
- rmSync(repoDir, { recursive: true, force: true });
28
- });
29
- function getHeadSha() {
30
- return execSync("git rev-parse HEAD", {
31
- cwd: repoDir,
32
- encoding: "utf-8",
33
- }).trim();
34
- }
35
- function makeCorrelation(overrides = {}) {
36
- return {
37
- rootIntentId: "intent-001",
38
- prompt: "Add error handling to payment flow",
39
- files: ["src/billing.ts"],
40
- entities: ["processPayment"],
41
- toolChain: ["get_function", "check_rules", "sync_local_diff"],
42
- createdAt: new Date().toISOString(),
43
- commitSha: getHeadSha(),
44
- ...overrides,
45
- };
46
- }
47
- it("writes a note to refs/notes/unerr", async () => {
48
- const sha = getHeadSha();
49
- const ok = await encodeIntentAsNote(sha, [makeCorrelation()], "session-abc123", {
50
- currentBranch: "main",
51
- baseBranch: "main",
52
- headSha: sha,
53
- commitsAhead: 0,
54
- commitsBehind: 0,
55
- baseCommit: "",
56
- computedAt: new Date().toISOString(),
57
- }, { added: 1, modified: 2, deleted: 0 }, repoDir);
58
- expect(ok).toBe(true);
59
- // Read the note back
60
- const noteContent = execSync(`git notes --ref=unerr show ${sha}`, {
61
- cwd: repoDir,
62
- encoding: "utf-8",
63
- }).trim();
64
- const note = JSON.parse(noteContent);
65
- expect(note.v).toBe(1);
66
- expect(note.intents).toHaveLength(1);
67
- expect(note.intents[0].id).toBe("intent-001");
68
- expect(note.intents[0].prompt).toBe("Add error handling to payment flow");
69
- expect(note.intents[0].tools).toEqual([
70
- "get_function",
71
- "check_rules",
72
- "sync_local_diff",
73
- ]);
74
- expect(note.drift).toEqual({ a: 1, m: 2, d: 0 });
75
- expect(note.sid).toBe("session-abc1");
76
- expect(note.br).toBe("main");
77
- });
78
- it("returns false for empty correlations", async () => {
79
- const ok = await encodeIntentAsNote(getHeadSha(), [], "session-xyz", null, { added: 0, modified: 0, deleted: 0 }, repoDir);
80
- expect(ok).toBe(false);
81
- });
82
- it("truncates long prompts to 200 chars", async () => {
83
- const sha = getHeadSha();
84
- const longPrompt = "x".repeat(300);
85
- await encodeIntentAsNote(sha, [makeCorrelation({ prompt: longPrompt })], "sess-123", null, { added: 0, modified: 0, deleted: 0 }, repoDir);
86
- const noteContent = execSync(`git notes --ref=unerr show ${sha}`, {
87
- cwd: repoDir,
88
- encoding: "utf-8",
89
- }).trim();
90
- const note = JSON.parse(noteContent);
91
- expect(note.intents[0].prompt.length).toBe(200);
92
- });
93
- it("handles multiple intents per commit", async () => {
94
- const sha = getHeadSha();
95
- await encodeIntentAsNote(sha, [
96
- makeCorrelation({ rootIntentId: "i1", prompt: "First change" }),
97
- makeCorrelation({ rootIntentId: "i2", prompt: "Second change" }),
98
- makeCorrelation({ rootIntentId: "i3", prompt: "Third change" }),
99
- ], "sess-multi", {
100
- currentBranch: "feature/test",
101
- baseBranch: "main",
102
- headSha: sha,
103
- commitsAhead: 3,
104
- commitsBehind: 0,
105
- baseCommit: "",
106
- computedAt: new Date().toISOString(),
107
- }, { added: 0, modified: 0, deleted: 0 }, repoDir);
108
- const noteContent = execSync(`git notes --ref=unerr show ${sha}`, {
109
- cwd: repoDir,
110
- encoding: "utf-8",
111
- }).trim();
112
- const note = JSON.parse(noteContent);
113
- expect(note.intents).toHaveLength(3);
114
- expect(note.br).toBe("feature/test");
115
- });
116
- it("note is invisible in regular git log", async () => {
117
- const sha = getHeadSha();
118
- await encodeIntentAsNote(sha, [makeCorrelation()], "sess-invisible", null, { added: 0, modified: 0, deleted: 0 }, repoDir);
119
- // Regular git log should NOT show the note
120
- const log = execSync("git log --oneline -1", {
121
- cwd: repoDir,
122
- encoding: "utf-8",
123
- });
124
- expect(log).not.toContain("intent-001");
125
- // But --notes=unerr should
126
- const logWithNotes = execSync("git log --notes=unerr -1", {
127
- cwd: repoDir,
128
- encoding: "utf-8",
129
- });
130
- expect(logWithNotes).toContain("intent-001");
131
- });
132
- it("payload stays under 2KB for typical commit", async () => {
133
- const sha = getHeadSha();
134
- const correlations = Array.from({ length: 5 }, (_, i) => makeCorrelation({
135
- rootIntentId: `intent-${i}`,
136
- prompt: `Typical coding task ${i}`,
137
- files: [`src/file${i}.ts`],
138
- entities: [`entity${i}`],
139
- toolChain: ["get_function", "sync_local_diff"],
140
- }));
141
- await encodeIntentAsNote(sha, correlations, "sess-budget", {
142
- currentBranch: "main",
143
- baseBranch: "main",
144
- headSha: sha,
145
- commitsAhead: 0,
146
- commitsBehind: 0,
147
- baseCommit: "",
148
- computedAt: new Date().toISOString(),
149
- }, { added: 2, modified: 3, deleted: 1 }, repoDir);
150
- const noteContent = execSync(`git notes --ref=unerr show ${sha}`, {
151
- cwd: repoDir,
152
- encoding: "utf-8",
153
- }).trim();
154
- expect(noteContent.length).toBeLessThan(2048);
155
- });
156
- it("returns false for non-git directory", async () => {
157
- const nonGitDir = join(tmpdir(), `unerr-test-nongit-${Date.now()}`);
158
- mkdirSync(nonGitDir, { recursive: true });
159
- try {
160
- const ok = await encodeIntentAsNote("abc1234", [makeCorrelation()], "sess-bad", null, { added: 0, modified: 0, deleted: 0 }, nonGitDir);
161
- expect(ok).toBe(false);
162
- }
163
- finally {
164
- rmSync(nonGitDir, { recursive: true, force: true });
165
- }
166
- });
167
- });
@@ -1,174 +0,0 @@
1
- /**
2
- * Tests for the deterministic Java build-tool detection heuristic (DM-1 Task 10).
3
- *
4
- * Uses temp dirs with fixture build files to verify each branch of chooseBuildTool.
5
- */
6
- import { mkdirSync, writeFileSync } from "node:fs";
7
- import { tmpdir } from "node:os";
8
- import { join } from "node:path";
9
- import { afterEach, beforeEach, describe, expect, it } from "vitest";
10
- import { chooseBuildTool, detectJavaBuildTools, } from "../intelligence/indexer/scip/orchestrator.js";
11
- let root;
12
- let testCounter = 0;
13
- beforeEach(() => {
14
- testCounter++;
15
- root = join(tmpdir(), `unerr-java-test-${process.pid}-${Date.now()}-${testCounter}`);
16
- mkdirSync(root, { recursive: true });
17
- });
18
- afterEach(() => {
19
- // Temp dirs are cleaned up by OS
20
- });
21
- function touch(relPath, content = "") {
22
- writeFileSync(join(root, relPath), content);
23
- }
24
- function touchWithMtime(relPath, mtime) {
25
- const fs = require("node:fs");
26
- const p = join(root, relPath);
27
- writeFileSync(p, "");
28
- fs.utimesSync(p, mtime, mtime);
29
- }
30
- // ── Detection ────────────────────────────────────────────────────
31
- describe("detectJavaBuildTools", () => {
32
- it("detects Maven from pom.xml", () => {
33
- touch("pom.xml");
34
- expect(detectJavaBuildTools(root)).toEqual(["Maven"]);
35
- });
36
- it("detects Gradle from build.gradle", () => {
37
- touch("build.gradle");
38
- expect(detectJavaBuildTools(root)).toEqual(["Gradle"]);
39
- });
40
- it("detects Gradle from build.gradle.kts", () => {
41
- touch("build.gradle.kts");
42
- expect(detectJavaBuildTools(root)).toEqual(["Gradle"]);
43
- });
44
- it("detects Bazel from BUILD.bazel", () => {
45
- touch("BUILD.bazel");
46
- expect(detectJavaBuildTools(root)).toEqual(["Bazel"]);
47
- });
48
- it("detects Sbt from build.sbt", () => {
49
- touch("build.sbt");
50
- expect(detectJavaBuildTools(root)).toEqual(["Sbt"]);
51
- });
52
- it("detects multiple tools", () => {
53
- touch("pom.xml");
54
- touch("build.gradle");
55
- const detected = detectJavaBuildTools(root);
56
- expect(detected).toContain("Maven");
57
- expect(detected).toContain("Gradle");
58
- });
59
- it("returns empty for no build files", () => {
60
- expect(detectJavaBuildTools(root)).toEqual([]);
61
- });
62
- });
63
- // ── Chooser heuristic ────────────────────────────────────────────
64
- describe("chooseBuildTool", () => {
65
- it("returns null when no tools detected", () => {
66
- expect(chooseBuildTool([], root)).toBeNull();
67
- });
68
- it("returns sole tool without ambiguity", () => {
69
- touch("pom.xml");
70
- const choice = chooseBuildTool(["Maven"], root);
71
- expect(choice).not.toBeNull();
72
- expect(choice.tool).toBe("Maven");
73
- expect(choice.ambiguous).toBe(false);
74
- expect(choice.alternatives).toEqual([]);
75
- });
76
- describe("Bazel precedence", () => {
77
- it("prefers Bazel over Maven + Gradle", () => {
78
- touch("pom.xml");
79
- touch("build.gradle");
80
- touch("BUILD.bazel");
81
- const choice = chooseBuildTool(["Maven", "Gradle", "Bazel"], root);
82
- expect(choice.tool).toBe("Bazel");
83
- expect(choice.ambiguous).toBe(true);
84
- expect(choice.alternatives).toContain("Maven");
85
- expect(choice.alternatives).toContain("Gradle");
86
- });
87
- });
88
- describe("Sbt precedence", () => {
89
- it("prefers Sbt over Maven", () => {
90
- touch("pom.xml");
91
- touch("build.sbt");
92
- const choice = chooseBuildTool(["Maven", "Sbt"], root);
93
- expect(choice.tool).toBe("Sbt");
94
- expect(choice.ambiguous).toBe(true);
95
- });
96
- it("prefers Sbt over Gradle", () => {
97
- touch("build.gradle");
98
- touch("build.sbt");
99
- const choice = chooseBuildTool(["Gradle", "Sbt"], root);
100
- expect(choice.tool).toBe("Sbt");
101
- });
102
- });
103
- describe("Maven + Gradle with wrappers", () => {
104
- it("prefers Gradle when gradlew present", () => {
105
- touch("pom.xml");
106
- touch("build.gradle");
107
- touch("gradlew");
108
- const choice = chooseBuildTool(["Maven", "Gradle"], root);
109
- expect(choice.tool).toBe("Gradle");
110
- expect(choice.reason).toContain("gradlew");
111
- expect(choice.alternatives).toEqual(["Maven"]);
112
- });
113
- it("prefers Gradle when gradlew.bat present (Windows)", () => {
114
- touch("pom.xml");
115
- touch("build.gradle");
116
- touch("gradlew.bat");
117
- const choice = chooseBuildTool(["Maven", "Gradle"], root);
118
- expect(choice.tool).toBe("Gradle");
119
- });
120
- it("prefers Maven when mvnw present and no gradlew", () => {
121
- touch("pom.xml");
122
- touch("build.gradle");
123
- touch("mvnw");
124
- const choice = chooseBuildTool(["Maven", "Gradle"], root);
125
- expect(choice.tool).toBe("Maven");
126
- expect(choice.reason).toContain("mvnw");
127
- expect(choice.alternatives).toEqual(["Gradle"]);
128
- });
129
- it("falls to mtime tiebreaker when both wrappers present", () => {
130
- touch("pom.xml");
131
- touch("build.gradle");
132
- touch("gradlew");
133
- touch("mvnw");
134
- // Both wrappers → mtime tiebreaker. Since we just created them, one
135
- // will have a slightly later mtime or they'll be equal. The important
136
- // thing is the function returns deterministically without crashing.
137
- const choice = chooseBuildTool(["Maven", "Gradle"], root);
138
- expect(choice).not.toBeNull();
139
- expect(["Maven", "Gradle"]).toContain(choice.tool);
140
- expect(choice.ambiguous).toBe(true);
141
- });
142
- it("falls to mtime tiebreaker when no wrappers present", () => {
143
- touch("pom.xml");
144
- touch("build.gradle");
145
- const choice = chooseBuildTool(["Maven", "Gradle"], root);
146
- expect(choice).not.toBeNull();
147
- expect(choice.ambiguous).toBe(true);
148
- });
149
- });
150
- describe("Mtime tiebreaker", () => {
151
- it("picks tool with most recently modified build file", () => {
152
- const old = new Date(2020, 0, 1);
153
- const recent = new Date(2026, 0, 1);
154
- touchWithMtime("pom.xml", old);
155
- touchWithMtime("build.gradle", recent);
156
- const choice = chooseBuildTool(["Maven", "Gradle"], root);
157
- expect(choice.tool).toBe("Gradle");
158
- });
159
- });
160
- });
161
- // ── Invariant: no process.stdin.isTTY ────────────────────────────
162
- describe("No interactive prompts in indexer", () => {
163
- it("orchestrator.ts does not reference process.stdin.isTTY in code", () => {
164
- const { readFileSync } = require("node:fs");
165
- const { resolve } = require("node:path");
166
- const content = readFileSync(resolve(__dirname, "../intelligence/indexer/scip/orchestrator.ts"), "utf-8");
167
- // Only allow the string in comments (lines starting with * or //)
168
- const codeLines = content
169
- .split("\n")
170
- .filter((line) => !line.trim().startsWith("*") && !line.trim().startsWith("//"));
171
- const joined = codeLines.join("\n");
172
- expect(joined).not.toContain("process.stdin.isTTY");
173
- });
174
- });