@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,203 +0,0 @@
1
- /**
2
- * P10-TEST-04: Shadow Ledger tests — append-only JSONL intent journal.
3
- */
4
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } 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 { ShadowLedger } from "../tracking/shadow-ledger.js";
9
- let tempDir;
10
- let unerrDir;
11
- beforeEach(() => {
12
- tempDir = join(tmpdir(), `unerr-ledger-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
13
- unerrDir = join(tempDir, ".unerr");
14
- mkdirSync(unerrDir, { recursive: true });
15
- });
16
- afterEach(() => {
17
- try {
18
- rmSync(tempDir, { recursive: true, force: true });
19
- }
20
- catch {
21
- /* ignore */
22
- }
23
- });
24
- describe("ShadowLedger", () => {
25
- it("creates ledger directory and file on first record", () => {
26
- const ledger = new ShadowLedger(unerrDir);
27
- ledger.record("get_function", { key: "abc" }, { found: true }, "main", "deadbeef");
28
- const filePath = join(unerrDir, "ledger", "shadow.jsonl");
29
- expect(existsSync(filePath)).toBe(true);
30
- const content = readFileSync(filePath, "utf-8").trim();
31
- const entry = JSON.parse(content);
32
- expect(entry.tool).toBe("get_function");
33
- expect(entry.branch).toBe("main");
34
- expect(entry.head_sha).toBe("deadbeef");
35
- expect(entry.args_summary).toEqual({ key: "abc" });
36
- expect(entry.result_summary).toEqual({ found: true });
37
- });
38
- it("generates unique 12-char hex IDs", () => {
39
- const ledger = new ShadowLedger(unerrDir);
40
- const e1 = ledger.record("get_function", {}, {}, "main", "aaa");
41
- const e2 = ledger.record("get_class", {}, {}, "main", "aaa");
42
- expect(e1.id).toHaveLength(12);
43
- expect(e2.id).toHaveLength(12);
44
- expect(e1.id).not.toBe(e2.id);
45
- expect(/^[0-9a-f]{12}$/.test(e1.id)).toBe(true);
46
- });
47
- it("assigns session ID consistent across records", () => {
48
- const ledger = new ShadowLedger(unerrDir);
49
- const e1 = ledger.record("get_function", {}, {}, "main", "aaa");
50
- const e2 = ledger.record("get_class", {}, {}, "main", "aaa");
51
- expect(e1.session_id).toBe(e2.session_id);
52
- expect(e1.session_id).toBe(ledger.getSessionId());
53
- });
54
- it("appends entries as JSONL (one JSON per line)", () => {
55
- const ledger = new ShadowLedger(unerrDir);
56
- ledger.record("get_function", { key: "a" }, { found: true }, "main", "aaa");
57
- ledger.record("get_class", { key: "b" }, { found: false }, "main", "bbb");
58
- ledger.record("search_code", { query: "foo" }, { count: 5 }, "main", "ccc");
59
- const filePath = join(unerrDir, "ledger", "shadow.jsonl");
60
- const lines = readFileSync(filePath, "utf-8").trim().split("\n");
61
- expect(lines).toHaveLength(3);
62
- const entries = lines.map((l) => JSON.parse(l));
63
- expect(entries[0]?.tool).toBe("get_function");
64
- expect(entries[1]?.tool).toBe("get_class");
65
- expect(entries[2]?.tool).toBe("search_code");
66
- });
67
- it("correlates entries within 30s window", () => {
68
- const ledger = new ShadowLedger(unerrDir);
69
- const root = ledger.record("get_function", {}, {}, "main", "aaa");
70
- const child = ledger.record("get_callers", {}, {}, "main", "aaa");
71
- // Root has null correlation_id
72
- expect(root.correlation_id).toBeNull();
73
- // Child correlates to root
74
- expect(child.correlation_id).toBe(root.id);
75
- });
76
- it("sync_local_diff always correlates to current root", () => {
77
- const ledger = new ShadowLedger(unerrDir);
78
- const root = ledger.record("get_function", {}, {}, "main", "aaa");
79
- const sync = ledger.record("sync_local_diff", { diff: "..." }, {}, "main", "aaa");
80
- expect(sync.correlation_id).toBe(root.id);
81
- });
82
- it("maintains in-memory buffer of recent entries", () => {
83
- const ledger = new ShadowLedger(unerrDir);
84
- for (let i = 0; i < 5; i++) {
85
- ledger.record(`tool_${i}`, {}, {}, "main", "aaa");
86
- }
87
- const recent = ledger.getRecentEntries(3);
88
- expect(recent).toHaveLength(3);
89
- expect(recent[0]?.tool).toBe("tool_2");
90
- expect(recent[2]?.tool).toBe("tool_4");
91
- });
92
- it("truncates arg values longer than 200 chars", () => {
93
- const ledger = new ShadowLedger(unerrDir);
94
- const longValue = "x".repeat(500);
95
- const entry = ledger.record("get_function", { content: longValue }, {}, "main", "aaa");
96
- const truncated = entry.args_summary.content;
97
- expect(truncated.length).toBeLessThanOrEqual(203); // 200 + "..."
98
- expect(truncated.endsWith("...")).toBe(true);
99
- });
100
- it("recovers from corrupted JSONL on startup", () => {
101
- // Write a file with one valid line and one corrupt line
102
- const ledgerDir = join(unerrDir, "ledger");
103
- mkdirSync(ledgerDir, { recursive: true });
104
- const filePath = join(ledgerDir, "shadow.jsonl");
105
- const validEntry = JSON.stringify({
106
- id: "aabbccddeeff",
107
- ts: new Date().toISOString(),
108
- tool: "get_function",
109
- args_summary: {},
110
- result_summary: {},
111
- branch: "main",
112
- head_sha: "abc",
113
- session_id: "112233445566",
114
- correlation_id: null,
115
- });
116
- writeFileSync(filePath, `${validEntry}\n{broken json\n`, "utf-8");
117
- // Loading should recover — keep valid line, drop corrupt
118
- const ledger = new ShadowLedger(unerrDir);
119
- const content = readFileSync(filePath, "utf-8").trim();
120
- const lines = content.split("\n").filter((l) => l.trim().length > 0);
121
- expect(lines).toHaveLength(1);
122
- // Should still be able to record new entries
123
- const entry = ledger.record("get_class", {}, {}, "main", "def");
124
- expect(entry.tool).toBe("get_class");
125
- });
126
- it("loads recent entries from file into buffer on startup", () => {
127
- // Create a ledger with entries
128
- const ledger1 = new ShadowLedger(unerrDir);
129
- ledger1.record("get_function", {}, {}, "main", "aaa");
130
- ledger1.record("get_class", {}, {}, "main", "bbb");
131
- // Create a new ledger instance — should load entries from file
132
- const ledger2 = new ShadowLedger(unerrDir);
133
- const recent = ledger2.getRecentEntries(10);
134
- expect(recent.length).toBeGreaterThanOrEqual(2);
135
- expect(recent.some((e) => e.tool === "get_function")).toBe(true);
136
- expect(recent.some((e) => e.tool === "get_class")).toBe(true);
137
- });
138
- it("getStats returns correct counts", () => {
139
- const ledger = new ShadowLedger(unerrDir);
140
- ledger.record("get_function", {}, {}, "main", "aaa");
141
- ledger.record("get_class", {}, {}, "main", "bbb");
142
- const stats = ledger.getStats();
143
- expect(stats.totalEntries).toBe(2);
144
- expect(stats.bufferSize).toBe(2);
145
- expect(stats.sessionId).toBe(ledger.getSessionId());
146
- expect(stats.lastEntryAt).toBeTruthy();
147
- });
148
- it("readAllEntries reads full file", () => {
149
- const ledger = new ShadowLedger(unerrDir);
150
- ledger.record("get_function", {}, {}, "main", "aaa");
151
- ledger.record("get_class", {}, {}, "main", "bbb");
152
- const all = ledger.readAllEntries();
153
- expect(all).toHaveLength(2);
154
- expect(all[0]?.tool).toBe("get_function");
155
- expect(all[1]?.tool).toBe("get_class");
156
- });
157
- it("getSessionEntryCount counts current session only", () => {
158
- const ledger = new ShadowLedger(unerrDir);
159
- ledger.record("get_function", {}, {}, "main", "aaa");
160
- ledger.record("get_class", {}, {}, "main", "bbb");
161
- expect(ledger.getSessionEntryCount()).toBe(2);
162
- });
163
- it("handles empty file gracefully", () => {
164
- const ledgerDir = join(unerrDir, "ledger");
165
- mkdirSync(ledgerDir, { recursive: true });
166
- writeFileSync(join(ledgerDir, "shadow.jsonl"), "", "utf-8");
167
- const ledger = new ShadowLedger(unerrDir);
168
- expect(ledger.getRecentEntries()).toHaveLength(0);
169
- expect(ledger.getStats().totalEntries).toBe(0);
170
- });
171
- });
172
- describe("ShadowLedger.getLastSyncTimestamp", () => {
173
- it("returns 0 when no sync_local_diff recorded", () => {
174
- const ledger = new ShadowLedger(unerrDir);
175
- expect(ledger.getLastSyncTimestamp()).toBe(0);
176
- });
177
- it("returns 0 when only non-sync tools recorded", () => {
178
- const ledger = new ShadowLedger(unerrDir);
179
- ledger.record("get_entity", {}, {}, "main", "abc");
180
- ledger.record("search", {}, {}, "main", "abc");
181
- expect(ledger.getLastSyncTimestamp()).toBe(0);
182
- });
183
- it("returns timestamp of most recent sync_local_diff", () => {
184
- const ledger = new ShadowLedger(unerrDir);
185
- const beforeTs = Date.now();
186
- ledger.record("sync_local_diff", {}, {}, "main", "abc");
187
- const afterTs = Date.now();
188
- const syncTs = ledger.getLastSyncTimestamp();
189
- expect(syncTs).toBeGreaterThanOrEqual(beforeTs);
190
- expect(syncTs).toBeLessThanOrEqual(afterTs);
191
- });
192
- it("returns latest sync when multiple syncs recorded", () => {
193
- const ledger = new ShadowLedger(unerrDir);
194
- ledger.record("sync_local_diff", {}, {}, "main", "abc");
195
- ledger.record("get_entity", {}, {}, "main", "abc");
196
- const beforeSecond = Date.now();
197
- ledger.record("sync_local_diff", {}, {}, "main", "def");
198
- const afterSecond = Date.now();
199
- const syncTs = ledger.getLastSyncTimestamp();
200
- expect(syncTs).toBeGreaterThanOrEqual(beforeSecond);
201
- expect(syncTs).toBeLessThanOrEqual(afterSecond);
202
- });
203
- });
@@ -1,151 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { classifyShellOutput, matchCommandHint, normalizeShellCommand, } from "../proxy/shell-classifier.js";
3
- describe("shell-classifier", () => {
4
- it("normalizes whitespace", () => {
5
- expect(normalizeShellCommand(" ps aux ")).toBe("ps aux");
6
- });
7
- it("matches longest command hint", () => {
8
- const m = matchCommandHint("docker ps -a");
9
- expect(m?.category).toBe("tabular");
10
- });
11
- it("classifies ps aux + tabular stdout as high confidence", () => {
12
- const stdout = "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\nroot 1 0.0 0.1 12345 678 ? Ss Jan01 0:01 init";
13
- const r = classifyShellOutput("ps aux", stdout);
14
- expect(r.category).toBe("tabular");
15
- expect(r.confidence).toBeGreaterThanOrEqual(0.82);
16
- });
17
- it("uses command hint for npm test when output is weak", () => {
18
- const r = classifyShellOutput("npm test", "something vague");
19
- expect(r.category).toBe("test_results");
20
- expect(r.hint_source).toBe("command_name");
21
- });
22
- it("detects git diff from content", () => {
23
- const out = "diff --git a/x.ts b/x.ts\n--- a/x.ts\n+++ b/x.ts\n@@ -1 +1 @@\n";
24
- const r = classifyShellOutput("unknown-cmd", out);
25
- expect(r.category).toBe("diff");
26
- });
27
- it("detects tail-like logs from timestamps", () => {
28
- const out = "2024-01-15T10:00:01Z INFO hello\n2024-01-15T10:00:02Z INFO world";
29
- const r = classifyShellOutput("cat server.log", out);
30
- expect(r.category).toBe("log_text");
31
- });
32
- it("detects pytest-style failures", () => {
33
- const out = "FAIL tests/foo.py::test_bar\nAssertionError: expected 1";
34
- const r = classifyShellOutput("pytest", out);
35
- expect(r.category).toBe("test_results");
36
- });
37
- it("detects progress streaming", () => {
38
- const out = "Downloading numpy-2.0.tar.gz\n[████████░░] 80% ETA 0:12";
39
- const r = classifyShellOutput("pip install numpy", out);
40
- expect(r.category).toBe("progress_streaming");
41
- });
42
- it("detects env-style key=value", () => {
43
- const out = "HOME=/Users/x\nPATH=/usr/bin\nSHELL=/bin/zsh\nFOO=bar";
44
- const r = classifyShellOutput("env", out);
45
- expect(r.category).toBe("key_value");
46
- });
47
- it("passthrough commands defer to strong content heuristics", () => {
48
- const rustcOutput = [
49
- "error[E0308]: mismatched types",
50
- " --> src/main.rs:10:5",
51
- " |",
52
- '10 | let x: u32 = "hello";',
53
- " | --- ^^^^^^^ expected `u32`, found `&str`",
54
- ].join("\n");
55
- // cat is passthrough — rustc content (score 0.94) should override
56
- const r = classifyShellOutput("cat /tmp/errors.txt", rustcOutput);
57
- expect(r.category).toBe("error_diagnostic");
58
- expect(r.hint_source).toBe("content_heuristic");
59
- });
60
- it("non-passthrough commands keep their hint even with strong content", () => {
61
- // npm run build is NOT passthrough — hint should win
62
- const gccOutput = "src/main.c:10:5: error: expected ';' after expression";
63
- const r = classifyShellOutput("npm run build", gccOutput);
64
- expect(r.category).toBe("log_text"); // hint wins
65
- expect(r.hint_source).toBe("command_name");
66
- });
67
- it("classifies git blame as log_text (not tabular)", () => {
68
- const r = classifyShellOutput("git blame src/main.ts", "abc123 (author 2024-01-01 10) line");
69
- expect(r.category).toBe("log_text");
70
- });
71
- it("classifies git shortlog as log_text", () => {
72
- const r = classifyShellOutput("git shortlog -sn", "42\tJohn Doe\n10\tJane");
73
- expect(r.category).toBe("log_text");
74
- });
75
- it("classifies pgrep as log_text (not tabular)", () => {
76
- const r = classifyShellOutput("pgrep node", "12345\n67890");
77
- expect(r.category).toBe("log_text");
78
- });
79
- // ── Chain-aware matchCommandHint (Option B + improved #1) ───────────────
80
- it("matchCommandHint: silent leading segment, hinted last segment", () => {
81
- // chmod is silent; ls -la is the actual producer
82
- const m = matchCommandHint("chmod +x foo.sh && ls -la dir/");
83
- expect(m?.category).toBe("tabular");
84
- expect(m?.key).toBe("ls -la");
85
- });
86
- it("matchCommandHint: hinted first segment, silent last (reversed order)", () => {
87
- // The trailing chmod is silent — pass 1 walks back, skips it, finds ls -la
88
- const m = matchCommandHint("ls -la dir/ && chmod +x foo");
89
- expect(m?.category).toBe("tabular");
90
- expect(m?.key).toBe("ls -la");
91
- });
92
- it("matchCommandHint: multiple silent prefixes, hinted trailing", () => {
93
- const m = matchCommandHint("mkdir -p foo && cd foo && ls -lah");
94
- expect(m?.category).toBe("tabular");
95
- expect(m?.key).toBe("ls -lah");
96
- });
97
- it("matchCommandHint: pipeline last consumer wins (grep)", () => {
98
- const m = matchCommandHint("find . -name '*.ts' | grep proxy");
99
- // grep has a known hint (error_diagnostic via shellcheck-style content or log_text)
100
- expect(m).not.toBeNull();
101
- });
102
- it("matchCommandHint: all-silent chain returns null", () => {
103
- expect(matchCommandHint("git add . && git commit -m wip")).toBeNull();
104
- });
105
- it("matchCommandHint: single non-chain command still works", () => {
106
- expect(matchCommandHint("docker ps -a")?.category).toBe("tabular");
107
- });
108
- it("matchCommandHint: strips redirects before matching", () => {
109
- expect(matchCommandHint("ls -la dir/ > out.txt")?.category).toBe("tabular");
110
- expect(matchCommandHint("ls -la dir/ 2>&1")?.category).toBe("tabular");
111
- });
112
- it("matchCommandHint: semicolon-separated chain", () => {
113
- const m = matchCommandHint("echo start; ls -la dir/; echo done");
114
- // echo is not in SILENT_COMMANDS (it produces meaningful output), so pass 1
115
- // walks last→first; trailing `echo done` is non-silent but unhinted; falls
116
- // through to `ls -la` which has a hint.
117
- expect(m?.category).toBe("tabular");
118
- });
119
- // ── Short-output tabular detection (Option B) ───────────────────────────
120
- it("classifies 3-row aligned output as tabular (short-output rule)", () => {
121
- // ls -la of a 3-file directory — 3 aligned rows, would previously fall to
122
- // omni because aligned was < 4. New short-output rule catches it.
123
- // Each row needs ≥2 consecutive spaces somewhere (column padding).
124
- const stdout = [
125
- "total 8",
126
- "drwxr-xr-x 3 user wheel 96 May 12 02:31 .",
127
- "drwxr-xr-x 4 user wheel 128 May 12 02:31 ..",
128
- "-rwxr-xr-x 1 user wheel 1643 May 12 02:31 run-scenario.sh",
129
- ].join("\n");
130
- const r = classifyShellOutput("anything-unhinted-cmd", stdout);
131
- expect(r.category).toBe("tabular");
132
- // Lower confidence (0.72) so command-hint disagreement can still win
133
- expect(r.confidence).toBeGreaterThanOrEqual(0.7);
134
- });
135
- it("does NOT classify random 2-row alignment as tabular", () => {
136
- // Only 2 aligned rows + 1 short — should not trigger the short-output rule
137
- const stdout = "ab\nfoo bar\nbaz qux";
138
- const r = classifyShellOutput("randomcmd", stdout);
139
- expect(r.category).not.toBe("tabular");
140
- });
141
- it("chain-aware classifier: chmod && ls -la routes to tabular", () => {
142
- const stdout = [
143
- "total 8",
144
- "drwxr-xr-x 3 user wheel 96 May 12 02:31 .",
145
- "drwxr-xr-x 4 user wheel 128 May 12 02:31 ..",
146
- "-rwxr-xr-x 1 user wheel 1643 May 12 02:31 script.sh",
147
- ].join("\n");
148
- const r = classifyShellOutput("chmod +x /tmp/x.sh && ls -la /tmp/", stdout);
149
- expect(r.category).toBe("tabular");
150
- });
151
- });
@@ -1,189 +0,0 @@
1
- /**
2
- * R10 — per-classifier ≥60% compression CI gate.
3
- *
4
- * Asserts each strategy compresses its representative fixture by at least
5
- * the per-strategy floor. RTK's rule: filters must justify their existence.
6
- *
7
- * If you add a new strategy, add a fixture + floor here. If a fixture
8
- * regresses below floor, fix the strategy — don't lower the floor.
9
- */
10
- import { describe, expect, it } from "vitest";
11
- import { compressDiff } from "../proxy/shell-strategies/diff.js";
12
- import { compressErrorDiagnostic } from "../proxy/shell-strategies/error-diagnostic.js";
13
- import { compressKeyValue } from "../proxy/shell-strategies/key-value.js";
14
- import { compressLogText } from "../proxy/shell-strategies/log-text.js";
15
- import { compressProgress } from "../proxy/shell-strategies/progress.js";
16
- import { compressStructured } from "../proxy/shell-strategies/structured.js";
17
- import { compressTabular } from "../proxy/shell-strategies/tabular.js";
18
- import { compressTestResults } from "../proxy/shell-strategies/test-results.js";
19
- import { compressTreePaths } from "../proxy/shell-strategies/tree-paths.js";
20
- function ratio(raw, out) {
21
- if (raw.length === 0)
22
- return 0;
23
- return (raw.length - out.length) / raw.length;
24
- }
25
- // Fixture builders — kept self-contained, no I/O
26
- const fxDiff = (() => {
27
- const lines = [
28
- "diff --git a/src/foo.ts b/src/foo.ts",
29
- "index 1234567..abcdef 100644",
30
- "--- a/src/foo.ts",
31
- "+++ b/src/foo.ts",
32
- "@@ -1,400 +1,400 @@",
33
- ];
34
- for (let i = 0; i < 800; i++) {
35
- lines.push(i % 50 === 0
36
- ? `+ const change_${i} = ${i};`
37
- : ` const same_${i} = ${i}; // unchanged context line`);
38
- }
39
- return lines.join("\n");
40
- })();
41
- const fxLog = (() => {
42
- const out = ["BUILD START"];
43
- for (let i = 0; i < 1500; i++) {
44
- out.push(`2026-05-13T14:32:0${i % 10}.123Z INFO compiling module/foo-${i % 8}.ts`);
45
- }
46
- out.push("Finished build in 12.3s");
47
- return out.join("\n");
48
- })();
49
- const fxTree = (() => {
50
- const out = ["."];
51
- const dirs = ["components", "lib", "pages", "hooks", "utils", "tests"];
52
- const exts = [".ts", ".tsx", ".test.ts", ".css"];
53
- for (const d of dirs) {
54
- for (let i = 0; i < 40; i++) {
55
- const ext = exts[i % exts.length];
56
- out.push(`src/${d}/file_${i}${ext}`);
57
- }
58
- }
59
- return out.join("\n");
60
- })();
61
- const fxTabular = (() => {
62
- const out = [
63
- "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND",
64
- ];
65
- for (let i = 0; i < 200; i++) {
66
- out.push(`user${i.toString().padStart(3, "0")} ${(1000 + i).toString().padStart(5)} ${(i % 20).toFixed(1)} ${(i % 8).toFixed(1)} 123456 ${(20000 + i).toString().padStart(6)} ? S 10:00 0:00 some/long/process/name-${i}`);
67
- }
68
- return out.join("\n");
69
- })();
70
- const fxKeyValue = (() => {
71
- const out = [];
72
- for (let i = 0; i < 300; i++) {
73
- out.push(`MY_LONG_ENV_VAR_${i}=value_with_meaningful_content_${i}_padded`);
74
- }
75
- return out.join("\n");
76
- })();
77
- const fxStructured = JSON.stringify({
78
- items: Array.from({ length: 200 }, (_, i) => ({
79
- id: i,
80
- name: `item-${i}`,
81
- tags: ["a", "b", "c"],
82
- meta: { ts: "2026-05-13T14:32:01.123Z", uuid: "abc-123-def-456" },
83
- })),
84
- }, null, 2);
85
- const fxProgress = (() => {
86
- const out = [];
87
- for (let i = 0; i <= 100; i += 2) {
88
- out.push(`[${"#".repeat(i / 2)}${" ".repeat(50 - i / 2)}] ${i}% downloading pkg-name`);
89
- }
90
- out.push("done");
91
- return out.join("\n");
92
- })();
93
- const fxTestResults = (() => {
94
- const out = ["RUNS src/example.test.ts"];
95
- for (let i = 0; i < 80; i++) {
96
- out.push(` ✓ test case ${i} should pass when conditions are met (${i}ms)`);
97
- }
98
- out.push("");
99
- out.push("Test Suites: 1 passed, 1 total");
100
- out.push("Tests: 80 passed, 80 total");
101
- out.push("Snapshots: 0 total");
102
- out.push("Time: 2.345 s");
103
- return out.join("\n");
104
- })();
105
- const fxErrorDiag = (() => {
106
- const out = [];
107
- for (let i = 0; i < 50; i++) {
108
- out.push(`src/file_${i}.ts(${10 + i},${5 + (i % 30)}): error TS2304: Cannot find name 'foo${i}'.`);
109
- out.push(` 10 const x = foo${i}();`);
110
- out.push(" ~~~~~~");
111
- out.push("");
112
- }
113
- return out.join("\n");
114
- })();
115
- const cases = [
116
- {
117
- name: "diff",
118
- // Synthetic fixture: 800 lines, 16 changes — heavy unchanged-context tail
119
- // limits real-world ratios. Real-world README claim is 99% on actual diffs;
120
- // this floor protects against strategy regressing to passthrough.
121
- floor: 0.65,
122
- raw: fxDiff,
123
- run: () => compressDiff(fxDiff, undefined, "git diff"),
124
- },
125
- {
126
- name: "log_text",
127
- floor: 0.6,
128
- raw: fxLog,
129
- run: () => compressLogText(fxLog, "vite build"),
130
- },
131
- {
132
- name: "tree_paths",
133
- floor: 0.6,
134
- raw: fxTree,
135
- run: () => compressTreePaths(fxTree, 3, "tree"),
136
- },
137
- {
138
- name: "tabular",
139
- // Synthetic ps aux fixture has high column-uniqueness; real-world ratios
140
- // (77% per README) come from outputs with more repeated values. Floor
141
- // here protects against the strategy regressing to passthrough.
142
- floor: 0.4,
143
- raw: fxTabular,
144
- run: () => compressTabular(fxTabular, "ps aux"),
145
- },
146
- {
147
- name: "key_value",
148
- floor: 0.4,
149
- raw: fxKeyValue,
150
- run: () => compressKeyValue(fxKeyValue, "env"),
151
- },
152
- {
153
- name: "structured",
154
- floor: 0.6,
155
- raw: fxStructured,
156
- run: () => compressStructured(fxStructured, "curl"),
157
- },
158
- {
159
- name: "progress",
160
- floor: 0.6,
161
- raw: fxProgress,
162
- run: () => compressProgress(fxProgress, "npm install"),
163
- },
164
- {
165
- name: "test_results",
166
- floor: 0.8,
167
- raw: fxTestResults,
168
- run: () => compressTestResults(fxTestResults, "vitest", 0),
169
- },
170
- {
171
- name: "error_diagnostic",
172
- floor: 0.5,
173
- raw: fxErrorDiag,
174
- run: () => compressErrorDiagnostic(fxErrorDiag, "tsc"),
175
- },
176
- ];
177
- describe("R10 — per-classifier compression floor (≥ per-strategy floor)", () => {
178
- for (const c of cases) {
179
- it(`${c.name} compresses by ≥${Math.round(c.floor * 100)}%`, () => {
180
- const out = c.run();
181
- const r = ratio(c.raw, out);
182
- if (r < c.floor) {
183
- // Helpful failure message — what we got vs what's required
184
- throw new Error(`${c.name}: ratio ${(r * 100).toFixed(1)}% < floor ${(c.floor * 100).toFixed(0)}% — raw ${c.raw.length}B, out ${out.length}B`);
185
- }
186
- expect(r).toBeGreaterThanOrEqual(c.floor);
187
- });
188
- }
189
- });