@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,174 +0,0 @@
1
- /**
2
- * Layer 3 Sprint U: Persistent Intelligence (Cross-Session) tests.
3
- */
4
- import { describe, expect, it } from "vitest";
5
- import { evaluateForPromotion, shouldPromote, } from "../intelligence/rule-generator.js";
6
- import { createContextRotDetector } from "../proxy/context-rot-detector.js";
7
- import { createDurabilityTracker } from "../tracking/durability-tracker.js";
8
- describe("Auto-Rule Generation (U.6)", () => {
9
- it("promotes corrections with high confidence + occurrences", () => {
10
- const corrections = [
11
- {
12
- entityKey: "src/auth.ts::login",
13
- pattern: "rename",
14
- description: "Use 'authenticate' instead of 'login'",
15
- occurrences: 4,
16
- confidence: 0.95,
17
- },
18
- ];
19
- const rules = evaluateForPromotion(corrections);
20
- expect(rules).toHaveLength(1);
21
- expect(rules[0]?.severity).toBe("warn");
22
- expect(rules[0]?.source).toBe("correction-auto");
23
- });
24
- it("does not promote low-confidence corrections", () => {
25
- const corrections = [
26
- {
27
- entityKey: "src/a.ts::fn",
28
- pattern: "rename",
29
- description: "test",
30
- occurrences: 5,
31
- confidence: 0.6,
32
- },
33
- ];
34
- expect(evaluateForPromotion(corrections)).toHaveLength(0);
35
- });
36
- it("does not promote low-occurrence corrections", () => {
37
- const corrections = [
38
- {
39
- entityKey: "src/b.ts::fn",
40
- pattern: "rename",
41
- description: "test",
42
- occurrences: 1,
43
- confidence: 0.95,
44
- },
45
- ];
46
- expect(evaluateForPromotion(corrections)).toHaveLength(0);
47
- });
48
- it("shouldPromote checks thresholds", () => {
49
- expect(shouldPromote({
50
- entityKey: "x",
51
- pattern: "p",
52
- description: "d",
53
- occurrences: 3,
54
- confidence: 0.9,
55
- })).toBe(true);
56
- expect(shouldPromote({
57
- entityKey: "x",
58
- pattern: "p",
59
- description: "d",
60
- occurrences: 2,
61
- confidence: 0.9,
62
- })).toBe(false);
63
- });
64
- });
65
- describe("Durability Tracker (U.7-U.8)", () => {
66
- it("records modifications and computes score", () => {
67
- const tracker = createDurabilityTracker();
68
- tracker.recordModification("entity-a", "session-1", "hash1");
69
- tracker.recordModification("entity-a", "session-2", "hash2");
70
- const result = tracker.getScore("entity-a");
71
- expect(result).not.toBeNull();
72
- expect(result?.totalModifications).toBe(2);
73
- expect(result?.pending).toBe(2);
74
- });
75
- it("evaluates survival correctly", () => {
76
- const tracker = createDurabilityTracker();
77
- tracker.recordModification("entity-b", "s1", "hashOriginal");
78
- const mods = tracker.records ?? new Map();
79
- tracker.evaluateSurvival("entity-b", "hashOriginal");
80
- });
81
- it("returns null for unknown entities", () => {
82
- const tracker = createDurabilityTracker();
83
- expect(tracker.getScore("nonexistent")).toBeNull();
84
- });
85
- it("getLowDurabilityEntities filters below threshold", () => {
86
- const tracker = createDurabilityTracker();
87
- tracker.recordModification("fragile", "s1", "h1");
88
- tracker.recordModification("fragile", "s2", "h2");
89
- const low = tracker.getLowDurabilityEntities(0.5);
90
- expect(low.length).toBeGreaterThanOrEqual(0);
91
- });
92
- it("getAllScores returns map", () => {
93
- const tracker = createDurabilityTracker();
94
- tracker.recordModification("e1", "s1", "h1");
95
- tracker.recordModification("e2", "s1", "h2");
96
- const scores = tracker.getAllScores();
97
- expect(scores.size).toBe(2);
98
- });
99
- });
100
- describe("Context Rot Detector (U.14-U.15)", () => {
101
- it("starts with zero rot", () => {
102
- const detector = createContextRotDetector();
103
- const signal = detector.evaluate();
104
- expect(signal.rotConfidence).toBe(0);
105
- expect(signal.action).toBe("none");
106
- });
107
- it("detects depth threshold warning", () => {
108
- const detector = createContextRotDetector();
109
- detector.recordToolCallTokens(250_000);
110
- const signal = detector.evaluate();
111
- expect(signal.rotConfidence).toBeGreaterThan(0);
112
- expect(signal.signals.some((s) => s.type === "depth_threshold")).toBe(true);
113
- });
114
- it("detects critical depth", () => {
115
- const detector = createContextRotDetector();
116
- detector.recordToolCallTokens(350_000);
117
- const signal = detector.evaluate();
118
- expect(signal.rotConfidence).toBeGreaterThanOrEqual(0.4);
119
- });
120
- it("detects repeated exploration", () => {
121
- const detector = createContextRotDetector();
122
- for (let i = 0; i < 5; i++) {
123
- detector.recordRepeatedQuery("entity-x");
124
- }
125
- const signal = detector.evaluate();
126
- expect(signal.signals.some((s) => s.type === "repeated_exploration")).toBe(true);
127
- });
128
- it("triggers inject_refresh at moderate rot", () => {
129
- const detector = createContextRotDetector();
130
- detector.recordToolCallTokens(250_000);
131
- for (let i = 0; i < 4; i++)
132
- detector.recordRepeatedQuery("entity-y");
133
- detector.recordError();
134
- detector.recordError();
135
- detector.recordError();
136
- detector.recordError();
137
- detector.recordError();
138
- const signal = detector.evaluate();
139
- expect(["inject_refresh", "suggest_new_session"]).toContain(signal.action);
140
- });
141
- it("triggers suggest_new_session at severe rot", () => {
142
- const detector = createContextRotDetector();
143
- detector.recordToolCallTokens(350_000);
144
- for (let i = 0; i < 5; i++)
145
- detector.recordRepeatedQuery(`ent-${i}`);
146
- for (let i = 0; i < 6; i++)
147
- detector.recordError();
148
- detector.recordForgottenContext("blast_radius", Date.now() - 60000);
149
- detector.recordConventionViolationAfterDelivery("camelCase");
150
- const signal = detector.evaluate();
151
- expect(signal.rotConfidence).toBeGreaterThan(0.7);
152
- expect(signal.action).toBe("suggest_new_session");
153
- });
154
- it("provides refresh context when triggered", () => {
155
- const detector = createContextRotDetector();
156
- detector.recordToolCallTokens(250_000);
157
- for (let i = 0; i < 4; i++)
158
- detector.recordRepeatedQuery("stale-entity");
159
- detector.evaluate();
160
- const ctx = detector.getRefreshContext();
161
- if (ctx) {
162
- expect(ctx.reason).toBeTruthy();
163
- expect(ctx.estimated_depth).toBeGreaterThan(0);
164
- }
165
- });
166
- it("resets cleanly", () => {
167
- const detector = createContextRotDetector();
168
- detector.recordToolCallTokens(500_000);
169
- detector.reset();
170
- const signal = detector.evaluate();
171
- expect(signal.estimatedDepth).toBe(0);
172
- expect(signal.rotConfidence).toBe(0);
173
- });
174
- });
@@ -1,354 +0,0 @@
1
- /**
2
- * Sprint BA-2: Quality Compound tests.
3
- *
4
- * Tests for:
5
- * BA-2.1 — Incomplete Work Detection
6
- * BA-2.2 — Convention Drift Prevention
7
- * BA-2.3 — Auto-Documentation Generation
8
- */
9
- import { mkdirSync } from "node:fs";
10
- import { tmpdir } from "node:os";
11
- import { join } from "node:path";
12
- import { beforeEach, describe, expect, it } from "vitest";
13
- import { AutoDocBehavior } from "../behaviors/auto-doc.js";
14
- import { ConventionDriftPrevention } from "../behaviors/convention-drift.js";
15
- import { IncompleteWorkDetector } from "../behaviors/incomplete-work.js";
16
- import { ShadowLedger } from "../tracking/shadow-ledger.js";
17
- function makeTmpDir() {
18
- const dir = join(tmpdir(), `unerr-test-ba2-${Date.now()}-${Math.random().toString(36).slice(2)}`);
19
- mkdirSync(dir, { recursive: true });
20
- return dir;
21
- }
22
- function makeCtx(overrides = {}) {
23
- return {
24
- toolName: "edit_file",
25
- args: {},
26
- sessionId: "test-session",
27
- ...overrides,
28
- };
29
- }
30
- // ── BA-2.1: Incomplete Work Detection ───────────────────────────
31
- describe("Incomplete Work Detection (BA-2.1)", () => {
32
- let tmpDir;
33
- beforeEach(() => {
34
- tmpDir = makeTmpDir();
35
- });
36
- describe("Behavior Identity", () => {
37
- it("has correct id and hooks", () => {
38
- const detector = new IncompleteWorkDetector();
39
- expect(detector.id).toBe("incomplete_work");
40
- expect(detector.hooks).toContain("session_end");
41
- expect(detector.defaultLevel).toBe("suggestion");
42
- });
43
- });
44
- describe("Orphaned Import Detection", () => {
45
- it("detects imports from deleted files", async () => {
46
- const ledger = new ShadowLedger(tmpDir);
47
- ledger.record("delete_file", { path: "src/utils/removed-module.ts" }, { success: true }, "main", "abc123");
48
- const detector = new IncompleteWorkDetector();
49
- detector.attachLedger(ledger);
50
- detector.setUnerrDir(tmpDir);
51
- const output = await detector.onSessionEnd(makeCtx());
52
- if (output) {
53
- const items = output._context?.incomplete_items;
54
- if (items) {
55
- const orphans = items.filter((i) => i.type === "orphaned_import");
56
- for (const orphan of orphans) {
57
- expect(orphan.severity).toBe("medium");
58
- }
59
- }
60
- }
61
- });
62
- });
63
- describe("Persistence", () => {
64
- it("persists incomplete items to disk for next session", async () => {
65
- const ledger = new ShadowLedger(tmpDir);
66
- ledger.record("delete_file", { path: "src/deleted.ts" }, { success: true }, "main", "abc123");
67
- const detector = new IncompleteWorkDetector();
68
- detector.attachLedger(ledger);
69
- detector.setUnerrDir(tmpDir);
70
- await detector.onSessionEnd(makeCtx());
71
- const persisted = IncompleteWorkDetector.readPersistedItems(tmpDir);
72
- expect(Array.isArray(persisted)).toBe(true);
73
- });
74
- it("readPersistedItems returns empty array when no file exists", () => {
75
- const items = IncompleteWorkDetector.readPersistedItems(join(tmpDir, "nonexistent"));
76
- expect(items).toEqual([]);
77
- });
78
- });
79
- describe("Empty Session", () => {
80
- it("returns null when no issues found", async () => {
81
- const ledger = new ShadowLedger(tmpDir);
82
- ledger.record("get_entity", { key: "src/safe.ts::func" }, { found: true }, "main", "abc123");
83
- const detector = new IncompleteWorkDetector();
84
- detector.attachLedger(ledger);
85
- detector.setUnerrDir(tmpDir);
86
- const output = await detector.onSessionEnd(makeCtx());
87
- expect(output).toBeNull();
88
- });
89
- });
90
- describe("Severity Ordering", () => {
91
- it("sorts items by severity: high first, low last", async () => {
92
- const detector = new IncompleteWorkDetector();
93
- const output = await detector.onSessionEnd(makeCtx());
94
- if (output) {
95
- const items = output._context?.incomplete_items;
96
- if (items && items.length > 1) {
97
- const severityOrder = items.map((i) => i.severity);
98
- const highIdx = severityOrder.indexOf("high");
99
- const lowIdx = severityOrder.indexOf("low");
100
- if (highIdx >= 0 && lowIdx >= 0) {
101
- expect(highIdx).toBeLessThan(lowIdx);
102
- }
103
- }
104
- }
105
- });
106
- });
107
- });
108
- // ── BA-2.2: Convention Drift Prevention ─────────────────────────
109
- describe("Convention Drift Prevention (BA-2.2)", () => {
110
- describe("Behavior Identity", () => {
111
- it("has correct id and hooks", () => {
112
- const behavior = new ConventionDriftPrevention();
113
- expect(behavior.id).toBe("convention_drift");
114
- expect(behavior.hooks).toContain("post_tool_use");
115
- expect(behavior.defaultLevel).toBe("suggestion");
116
- });
117
- });
118
- describe("Naming Convention Detection", () => {
119
- it("detects snake_case in a camelCase codebase", async () => {
120
- const behavior = new ConventionDriftPrevention();
121
- const ctx = makeCtx({
122
- toolName: "edit_file",
123
- filePath: "src/payment.ts",
124
- args: {
125
- path: "src/payment.ts",
126
- new_str: "export function process_payment(amount: number) { return amount; }",
127
- },
128
- });
129
- const output = await behavior.onPostToolUse(ctx);
130
- // Without a graph attached, it can't detect conventions — this is expected
131
- // The behavior degrades gracefully
132
- expect(output).toBeNull();
133
- });
134
- it("returns null for non-edit tools", async () => {
135
- const behavior = new ConventionDriftPrevention();
136
- const ctx = makeCtx({
137
- toolName: "get_entity",
138
- filePath: "src/payment.ts",
139
- args: { key: "src/payment.ts::processPayment" },
140
- });
141
- const output = await behavior.onPostToolUse(ctx);
142
- expect(output).toBeNull();
143
- });
144
- it("returns null for non-code files", async () => {
145
- const behavior = new ConventionDriftPrevention();
146
- const ctx = makeCtx({
147
- toolName: "edit_file",
148
- filePath: "docs/README.md",
149
- args: {
150
- path: "docs/README.md",
151
- new_str: "# Updated readme",
152
- },
153
- });
154
- const output = await behavior.onPostToolUse(ctx);
155
- expect(output).toBeNull();
156
- });
157
- it("returns null when no new content is provided", async () => {
158
- const behavior = new ConventionDriftPrevention();
159
- const ctx = makeCtx({
160
- toolName: "edit_file",
161
- filePath: "src/payment.ts",
162
- args: { path: "src/payment.ts" },
163
- });
164
- const output = await behavior.onPostToolUse(ctx);
165
- expect(output).toBeNull();
166
- });
167
- });
168
- describe("Auto-Fix Threshold", () => {
169
- it("auto-fix threshold is 0.9 by default", () => {
170
- const behavior = new ConventionDriftPrevention();
171
- expect(behavior.getSessionStats().autoFixes).toBe(0);
172
- });
173
- it("accepts custom confidence threshold", () => {
174
- const behavior = new ConventionDriftPrevention({
175
- confidenceThreshold: 0.95,
176
- });
177
- expect(behavior.enabled).toBe(true);
178
- });
179
- });
180
- describe("Session Stats", () => {
181
- it("starts with zero violations", () => {
182
- const behavior = new ConventionDriftPrevention();
183
- const stats = behavior.getSessionStats();
184
- expect(stats.violationsDetected).toBe(0);
185
- expect(stats.autoFixes).toBe(0);
186
- });
187
- });
188
- describe("Learning Loop", () => {
189
- it("tracks feedback correctly", () => {
190
- const behavior = new ConventionDriftPrevention();
191
- behavior.recordFeedback("accepted");
192
- behavior.recordFeedback("accepted");
193
- behavior.recordFeedback("dismissed");
194
- const stats = behavior.getLearningStats();
195
- expect(stats.accepted).toBe(2);
196
- expect(stats.dismissed).toBe(1);
197
- expect(stats.confidence).toBeCloseTo(2 / 3, 2);
198
- });
199
- });
200
- });
201
- // ── BA-2.3: Auto-Documentation Generation ───────────────────────
202
- describe("Auto-Documentation Generation (BA-2.3)", () => {
203
- describe("Behavior Identity", () => {
204
- it("has correct id and hooks", () => {
205
- const behavior = new AutoDocBehavior();
206
- expect(behavior.id).toBe("auto_doc");
207
- expect(behavior.hooks).toContain("post_tool_use");
208
- expect(behavior.defaultLevel).toBe("invisible");
209
- });
210
- });
211
- describe("JSDoc Generation", () => {
212
- it("detects exported function without docs", async () => {
213
- const behavior = new AutoDocBehavior();
214
- const ctx = makeCtx({
215
- toolName: "edit_file",
216
- filePath: "src/payment.ts",
217
- args: {
218
- path: "src/payment.ts",
219
- new_str: `export function processPayment(amount: number, currency: string): Promise<Receipt> {
220
- return gateway.charge(amount, currency);
221
- }`,
222
- },
223
- });
224
- const output = await behavior.onPostToolUse(ctx);
225
- expect(output).not.toBeNull();
226
- expect(output?._meta?.behavior).toBe("auto_doc");
227
- expect(output?._meta?.docs_updated).toBeGreaterThanOrEqual(1);
228
- const actions = output?._context?.doc_actions;
229
- expect(actions).toBeDefined();
230
- expect(actions.some((a) => a.entity === "processPayment")).toBe(true);
231
- });
232
- it("does not flag functions with existing JSDoc", async () => {
233
- const behavior = new AutoDocBehavior();
234
- const ctx = makeCtx({
235
- toolName: "edit_file",
236
- filePath: "src/payment.ts",
237
- args: {
238
- path: "src/payment.ts",
239
- new_str: `/**
240
- * Process a payment transaction.
241
- * @param amount The payment amount
242
- */
243
- export function processPayment(amount: number) {
244
- return amount;
245
- }`,
246
- },
247
- });
248
- const output = await behavior.onPostToolUse(ctx);
249
- // Should be null since JSDoc already exists and no graph to compare signatures
250
- expect(output).toBeNull();
251
- });
252
- it("returns null for non-edit tools", async () => {
253
- const behavior = new AutoDocBehavior();
254
- const ctx = makeCtx({
255
- toolName: "get_entity",
256
- filePath: "src/payment.ts",
257
- });
258
- const output = await behavior.onPostToolUse(ctx);
259
- expect(output).toBeNull();
260
- });
261
- it("returns null for non-code files", async () => {
262
- const behavior = new AutoDocBehavior();
263
- const ctx = makeCtx({
264
- toolName: "edit_file",
265
- filePath: "README.md",
266
- args: { path: "README.md", content: "# README" },
267
- });
268
- const output = await behavior.onPostToolUse(ctx);
269
- expect(output).toBeNull();
270
- });
271
- });
272
- describe("Agent-as-LLM Prompt", () => {
273
- it("includes agent prompt when useAgentAsLlm is enabled", async () => {
274
- const behavior = new AutoDocBehavior({ useAgentAsLlm: true });
275
- const ctx = makeCtx({
276
- toolName: "edit_file",
277
- filePath: "src/api.ts",
278
- args: {
279
- path: "src/api.ts",
280
- new_str: `export function fetchUsers(limit: number, offset: number): Promise<User[]> {
281
- return db.query('SELECT * FROM users LIMIT ? OFFSET ?', [limit, offset]);
282
- }`,
283
- },
284
- });
285
- const output = await behavior.onPostToolUse(ctx);
286
- expect(output).not.toBeNull();
287
- const agentPrompt = output?._context?.agent_prompt;
288
- expect(agentPrompt).toBeDefined();
289
- expect(typeof agentPrompt).toBe("string");
290
- expect(agentPrompt.length).toBeGreaterThan(0);
291
- });
292
- it("does NOT include agent prompt when useAgentAsLlm is disabled", async () => {
293
- const behavior = new AutoDocBehavior({ useAgentAsLlm: false });
294
- const ctx = makeCtx({
295
- toolName: "edit_file",
296
- filePath: "src/api.ts",
297
- args: {
298
- path: "src/api.ts",
299
- new_str: `export function fetchUsers(limit: number, offset: number): Promise<User[]> {
300
- return db.query('SELECT * FROM users LIMIT ? OFFSET ?', [limit, offset]);
301
- }`,
302
- },
303
- });
304
- const output = await behavior.onPostToolUse(ctx);
305
- expect(output).not.toBeNull();
306
- const agentPrompt = output?._context?.agent_prompt;
307
- expect(agentPrompt).toBeUndefined();
308
- });
309
- });
310
- describe("Session Stats", () => {
311
- it("tracks docs generated across calls", async () => {
312
- const behavior = new AutoDocBehavior();
313
- const ctx = makeCtx({
314
- toolName: "edit_file",
315
- filePath: "src/utils.ts",
316
- args: {
317
- path: "src/utils.ts",
318
- new_str: `export function formatDate(date: Date, locale: string): string {
319
- return date.toLocaleDateString(locale);
320
- }`,
321
- },
322
- });
323
- await behavior.onPostToolUse(ctx);
324
- const stats = behavior.getSessionStats();
325
- expect(stats.docsGenerated).toBeGreaterThanOrEqual(1);
326
- });
327
- });
328
- describe("Multiple Functions", () => {
329
- it("detects multiple undocumented functions", async () => {
330
- const behavior = new AutoDocBehavior();
331
- const ctx = makeCtx({
332
- toolName: "write_file",
333
- filePath: "src/math.ts",
334
- args: {
335
- path: "src/math.ts",
336
- content: `export function add(a: number, b: number): number {
337
- return a + b;
338
- }
339
-
340
- export function multiply(x: number, y: number): number {
341
- return x * y;
342
- }`,
343
- },
344
- });
345
- const output = await behavior.onPostToolUse(ctx);
346
- expect(output).not.toBeNull();
347
- const actions = output?._context?.doc_actions;
348
- expect(actions.length).toBeGreaterThanOrEqual(2);
349
- const names = actions.map((a) => a.entity);
350
- expect(names).toContain("add");
351
- expect(names).toContain("multiply");
352
- });
353
- });
354
- });
@@ -1,84 +0,0 @@
1
- /**
2
- * Sprint BA-4 — Output Token Efficiency tests.
3
- * BA-4.1: token-efficient skill enhancements
4
- * BA-4.2: context_complete flag
5
- * BA-4.3: output format legend
6
- */
7
- import { describe, expect, it } from "vitest";
8
- import { formatToolOutput, } from "../proxy/format-encoder.js";
9
- import { OUTPUT_FORMAT_LEGEND, createSessionLegendTracker, } from "../proxy/session-legend.js";
10
- import { TOKEN_EFFICIENT_SKILL } from "../skills/local-pack.js";
11
- describe("BA-4.1: token-efficient skill", () => {
12
- it("version is 1.1.0", () => {
13
- expect(TOKEN_EFFICIENT_SKILL.version).toBe("1.1.0");
14
- });
15
- it("includes unified diff rule", () => {
16
- expect(TOKEN_EFFICIENT_SKILL.instructions).toContain("unified diff format");
17
- expect(TOKEN_EFFICIENT_SKILL.instructions).toContain("---/+++");
18
- });
19
- it("includes ur|ctx rule", () => {
20
- expect(TOKEN_EFFICIENT_SKILL.instructions).toContain("ur|ctx");
21
- expect(TOKEN_EFFICIENT_SKILL.instructions).toContain("proceed directly to the action");
22
- });
23
- it("has 9 instruction rules", () => {
24
- const rules = TOKEN_EFFICIENT_SKILL.instructions.split("\n");
25
- expect(rules).toHaveLength(9);
26
- });
27
- });
28
- describe("BA-4.3: output format legend", () => {
29
- it("consumeOutputFormatLegend fires once per session", () => {
30
- const L = createSessionLegendTracker();
31
- expect(L.consumeOutputFormatLegend()).toBe(true);
32
- expect(L.consumeOutputFormatLegend()).toBe(false);
33
- });
34
- it("invalidateAll resets output format legend", () => {
35
- const L = createSessionLegendTracker();
36
- expect(L.consumeOutputFormatLegend()).toBe(true);
37
- L.invalidateAll();
38
- expect(L.consumeOutputFormatLegend()).toBe(true);
39
- });
40
- it("columnar and output format legends are independent", () => {
41
- const L = createSessionLegendTracker();
42
- expect(L.consumeColumnarLegend()).toBe(true);
43
- expect(L.consumeOutputFormatLegend()).toBe(true);
44
- // Both consumed — neither fires again
45
- expect(L.consumeColumnarLegend()).toBe(false);
46
- expect(L.consumeOutputFormatLegend()).toBe(false);
47
- });
48
- it("OUTPUT_FORMAT_LEGEND mentions ur|ctx and diff", () => {
49
- expect(OUTPUT_FORMAT_LEGEND).toContain("ur|ctx");
50
- expect(OUTPUT_FORMAT_LEGEND).toContain("unified diff");
51
- });
52
- it("formatToolOutput attaches output_format_legend on first call", () => {
53
- const legend = createSessionLegendTracker();
54
- const meta = {};
55
- formatToolOutput("get_callers", [{ k: "a", v: 1 }], meta, {
56
- legend,
57
- tier: "columnar",
58
- });
59
- expect(meta.output_format_legend).toBe(OUTPUT_FORMAT_LEGEND);
60
- // Second call — no legend
61
- const meta2 = {};
62
- formatToolOutput("get_callers", [{ k: "b", v: 2 }], meta2, {
63
- legend,
64
- tier: "columnar",
65
- });
66
- expect(meta2.output_format_legend).toBeUndefined();
67
- });
68
- it("formatToolOutput re-attaches legend after invalidation", () => {
69
- const legend = createSessionLegendTracker();
70
- const meta1 = {};
71
- formatToolOutput("get_callers", [{ k: "a", v: 1 }], meta1, {
72
- legend,
73
- tier: "columnar",
74
- });
75
- expect(meta1.output_format_legend).toBe(OUTPUT_FORMAT_LEGEND);
76
- legend.invalidateAll();
77
- const meta2 = {};
78
- formatToolOutput("get_callers", [{ k: "b", v: 2 }], meta2, {
79
- legend,
80
- tier: "columnar",
81
- });
82
- expect(meta2.output_format_legend).toBe(OUTPUT_FORMAT_LEGEND);
83
- });
84
- });