@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.
- package/README.md +70 -194
- package/dist/cli.js +39149 -36991
- package/package.json +9 -2
- package/dist/__tests__/architecture-guard.test.js +0 -122
- package/dist/__tests__/arg-validator.test.js +0 -205
- package/dist/__tests__/ast-extractor.test.js +0 -203
- package/dist/__tests__/auto-bootstrap.test.js +0 -280
- package/dist/__tests__/background-indexer.test.js +0 -228
- package/dist/__tests__/blast-radius-engine.test.js +0 -200
- package/dist/__tests__/bridge-isolation.test.js +0 -37
- package/dist/__tests__/budget-enforcer.test.js +0 -53
- package/dist/__tests__/cfg-test-detection-perf.test.js +0 -82
- package/dist/__tests__/change-narrative.test.js +0 -190
- package/dist/__tests__/check-commit.test.js +0 -258
- package/dist/__tests__/checksum.test.js +0 -34
- package/dist/__tests__/commit-watcher.test.js +0 -154
- package/dist/__tests__/community-detection.test.js +0 -179
- package/dist/__tests__/community-tools.test.js +0 -299
- package/dist/__tests__/components.test.js +0 -449
- package/dist/__tests__/compression-log.test.js +0 -174
- package/dist/__tests__/compression-quality-monitor.test.js +0 -40
- package/dist/__tests__/config-healer.test.js +0 -165
- package/dist/__tests__/context-ledger.test.js +0 -58
- package/dist/__tests__/convention-detector.test.js +0 -99
- package/dist/__tests__/convention-learner.test.js +0 -86
- package/dist/__tests__/correction-detector.test.js +0 -330
- package/dist/__tests__/daemon-autostart-install.test.js +0 -283
- package/dist/__tests__/daemon-bridge.test.js +0 -222
- package/dist/__tests__/daemon-dashboard.test.js +0 -202
- package/dist/__tests__/daemon-registry.test.js +0 -240
- package/dist/__tests__/daemon-supervisor.test.js +0 -318
- package/dist/__tests__/daemon-version-check.test.js +0 -275
- package/dist/__tests__/decision-point-detector.test.js +0 -98
- package/dist/__tests__/deep-link.test.js +0 -143
- package/dist/__tests__/disallowed-tools.test.js +0 -115
- package/dist/__tests__/drift-tracker.test.js +0 -582
- package/dist/__tests__/durability-scorer.test.js +0 -152
- package/dist/__tests__/efficiency-tracker.test.js +0 -65
- package/dist/__tests__/enrich.test.js +0 -144
- package/dist/__tests__/entity-rewind.test.js +0 -248
- package/dist/__tests__/ephemeral.test.js +0 -111
- package/dist/__tests__/exploration-cost.test.js +0 -93
- package/dist/__tests__/fact-generator.test.js +0 -197
- package/dist/__tests__/file-l0-graph.test.js +0 -244
- package/dist/__tests__/file-logger.test.js +0 -82
- package/dist/__tests__/file-outline.test.js +0 -141
- package/dist/__tests__/file-read-protocol.test.js +0 -188
- package/dist/__tests__/format-encoder.test.js +0 -233
- package/dist/__tests__/git-attribution.test.js +0 -259
- package/dist/__tests__/graph-temporal-joiner.test.js +0 -219
- package/dist/__tests__/health-grade-enhanced.test.js +0 -138
- package/dist/__tests__/health-map-data.test.js +0 -173
- package/dist/__tests__/helpers/mcp-harness.js +0 -45
- package/dist/__tests__/helpers/mcp-harness.test.js +0 -68
- package/dist/__tests__/hook-dedup.test.js +0 -112
- package/dist/__tests__/hook-runner.test.js +0 -253
- package/dist/__tests__/indexer-cfg.test.js +0 -185
- package/dist/__tests__/indexer-cross-file.test.js +0 -172
- package/dist/__tests__/indexer-extraction.test.js +0 -245
- package/dist/__tests__/indexer-incremental.test.js +0 -232
- package/dist/__tests__/indexer-language-expansion.test.js +0 -165
- package/dist/__tests__/init-push.test.js +0 -131
- package/dist/__tests__/instruction-writer.test.js +0 -179
- package/dist/__tests__/intelligence-integration.test.js +0 -217
- package/dist/__tests__/intent-correlator.test.js +0 -175
- package/dist/__tests__/intent-detector.test.js +0 -235
- package/dist/__tests__/intent-encoder.test.js +0 -167
- package/dist/__tests__/java-build-tool-detection.test.js +0 -174
- package/dist/__tests__/layer3-sprint-q.test.js +0 -160
- package/dist/__tests__/layer3-sprint-r.test.js +0 -91
- package/dist/__tests__/layer3-sprint-s.test.js +0 -183
- package/dist/__tests__/layer3-sprint-t.test.js +0 -201
- package/dist/__tests__/layer3-sprint-u.test.js +0 -174
- package/dist/__tests__/layer4-sprint-ba2.test.js +0 -354
- package/dist/__tests__/layer4-sprint-ba4.test.js +0 -84
- package/dist/__tests__/layer4-sprint-vs.test.js +0 -105
- package/dist/__tests__/ledger-chains.test.js +0 -162
- package/dist/__tests__/lifecycle-machine.test.js +0 -226
- package/dist/__tests__/local-chat-provider.test.js +0 -170
- package/dist/__tests__/local-convention-detector.test.js +0 -308
- package/dist/__tests__/local-embeddings.test.js +0 -422
- package/dist/__tests__/local-graph.test.js +0 -540
- package/dist/__tests__/local-indexer.test.js +0 -228
- package/dist/__tests__/local-intelligence-l3.test.js +0 -332
- package/dist/__tests__/local-llm.test.js +0 -253
- package/dist/__tests__/local-mode-offline.test.js +0 -187
- package/dist/__tests__/local-mode-stats.test.js +0 -273
- package/dist/__tests__/local-mode-tui.test.js +0 -343
- package/dist/__tests__/local-parse.test.js +0 -199
- package/dist/__tests__/log-tailer.test.js +0 -208
- package/dist/__tests__/loop-breaker.test.js +0 -276
- package/dist/__tests__/loop-miner.test.js +0 -226
- package/dist/__tests__/mcp-config.test.js +0 -126
- package/dist/__tests__/mcp-content-json.test.js +0 -10
- package/dist/__tests__/mcp-envelope.test.js +0 -124
- package/dist/__tests__/metrics-store.test.js +0 -223
- package/dist/__tests__/native-watcher.test.js +0 -191
- package/dist/__tests__/navigation-hooks-agent-aware.test.js +0 -145
- package/dist/__tests__/negative-knowledge.test.js +0 -116
- package/dist/__tests__/network-boundary.test.js +0 -190
- package/dist/__tests__/network-firewall.test.js +0 -112
- package/dist/__tests__/nudge-invariants.test.js +0 -160
- package/dist/__tests__/nudge-v2.test.js +0 -225
- package/dist/__tests__/offline-rewind.test.js +0 -251
- package/dist/__tests__/open-threads.test.js +0 -89
- package/dist/__tests__/output-compressor.test.js +0 -93
- package/dist/__tests__/pending-violations.test.js +0 -112
- package/dist/__tests__/persistence-effectiveness.test.js +0 -143
- package/dist/__tests__/provider-factory.test.js +0 -42
- package/dist/__tests__/providers.test.js +0 -24
- package/dist/__tests__/proxy.test.js +0 -314
- package/dist/__tests__/query-router.test.js +0 -1018
- package/dist/__tests__/reasoning-quality-route.test.js +0 -138
- package/dist/__tests__/redactor.test.js +0 -120
- package/dist/__tests__/resource-monitor.test.js +0 -57
- package/dist/__tests__/response-envelope.test.js +0 -100
- package/dist/__tests__/risk-classifier.test.js +0 -101
- package/dist/__tests__/risk-signal-scope.test.js +0 -75
- package/dist/__tests__/rule-evaluator.test.js +0 -280
- package/dist/__tests__/scip-decoder.test.js +0 -49
- package/dist/__tests__/scip-downloader.test.js +0 -201
- package/dist/__tests__/scip-merger.test.js +0 -103
- package/dist/__tests__/search-index.test.js +0 -422
- package/dist/__tests__/semantic-enrichment.test.js +0 -360
- package/dist/__tests__/session-brief-builder.test.js +0 -187
- package/dist/__tests__/session-context.test.js +0 -221
- package/dist/__tests__/session-continuity.test.js +0 -144
- package/dist/__tests__/session-dedup.test.js +0 -74
- package/dist/__tests__/session-event-wiring.test.js +0 -206
- package/dist/__tests__/session-events.test.js +0 -149
- package/dist/__tests__/session-legend.test.js +0 -20
- package/dist/__tests__/session-persistence.test.js +0 -131
- package/dist/__tests__/session-resume-block.test.js +0 -107
- package/dist/__tests__/session-resume.test.js +0 -97
- package/dist/__tests__/session-summary-writer.test.js +0 -134
- package/dist/__tests__/shadow-ledger.test.js +0 -203
- package/dist/__tests__/shell-classifier.test.js +0 -151
- package/dist/__tests__/shell-compression-floor.test.js +0 -189
- package/dist/__tests__/shell-compression-v2.test.js +0 -339
- package/dist/__tests__/shell-compressor.test.js +0 -35
- package/dist/__tests__/shell-hooks.test.js +0 -128
- package/dist/__tests__/shell-strategies.test.js +0 -644
- package/dist/__tests__/shell-tee.test.js +0 -133
- package/dist/__tests__/signal-dedup.test.js +0 -158
- package/dist/__tests__/signal-reinforcer.test.js +0 -77
- package/dist/__tests__/signal-scorer.test.js +0 -251
- package/dist/__tests__/signal-show-store.test.js +0 -108
- package/dist/__tests__/smart-truncate.test.js +0 -215
- package/dist/__tests__/snapshot-v2.test.js +0 -113
- package/dist/__tests__/sprint-l1-local-mode.test.js +0 -130
- package/dist/__tests__/sprint-l10-boot.test.js +0 -220
- package/dist/__tests__/sprint-l9-offline-commands.test.js +0 -189
- package/dist/__tests__/sprint-q-persistent-context.test.js +0 -198
- package/dist/__tests__/sprint-s1-wiring.test.js +0 -215
- package/dist/__tests__/sprint-s2-wiring.test.js +0 -256
- package/dist/__tests__/sprint-s3-wiring.test.js +0 -195
- package/dist/__tests__/sprint-s4-wiring.test.js +0 -213
- package/dist/__tests__/sprint-s6-hooks.test.js +0 -222
- package/dist/__tests__/sprint-s7-persistent.test.js +0 -263
- package/dist/__tests__/sprint-s8-value.test.js +0 -167
- package/dist/__tests__/sprint-s9-behavioral.test.js +0 -179
- package/dist/__tests__/sprint3-intelligence.test.js +0 -297
- package/dist/__tests__/sprint5-mcp-server.test.js +0 -136
- package/dist/__tests__/startup-display.test.js +0 -302
- package/dist/__tests__/startup-log-file.test.js +0 -97
- package/dist/__tests__/stash-manager.test.js +0 -229
- package/dist/__tests__/state-detector.test.js +0 -92
- package/dist/__tests__/status-dashboard.test.js +0 -142
- package/dist/__tests__/temporal-facts.test.js +0 -292
- package/dist/__tests__/temporal-routes.test.js +0 -142
- package/dist/__tests__/test-detector.test.js +0 -174
- package/dist/__tests__/theme.test.js +0 -72
- package/dist/__tests__/timeline-agents.test.js +0 -122
- package/dist/__tests__/timeline-bootstrap.test.js +0 -176
- package/dist/__tests__/timeline-filters.test.js +0 -193
- package/dist/__tests__/timeline-markers.test.js +0 -151
- package/dist/__tests__/timeline-routes.test.js +0 -156
- package/dist/__tests__/timeline-store.test.js +0 -171
- package/dist/__tests__/token-counter.test.js +0 -86
- package/dist/__tests__/token-estimator.test.js +0 -96
- package/dist/__tests__/token-flow-api.test.js +0 -239
- package/dist/__tests__/token-flow-instrumentation.test.js +0 -437
- package/dist/__tests__/token-flow-persistence.test.js +0 -356
- package/dist/__tests__/token-flow-routes.test.js +0 -199
- package/dist/__tests__/token-flow.test.js +0 -695
- package/dist/__tests__/tool-clusters.test.js +0 -177
- package/dist/__tests__/transport-mux.test.js +0 -283
- package/dist/__tests__/turn-segmenter.test.js +0 -166
- package/dist/__tests__/uninstall.test.js +0 -141
- package/dist/__tests__/warm-start-policy.test.js +0 -271
- package/dist/__tests__/wire-cap-nudge.test.js +0 -77
- package/dist/__tests__/worker-pool.test.js +0 -101
- package/dist/ui/assets/index-7gl3mIuY.css +0 -1
- package/dist/ui/assets/index-CX4FCWGT.js +0 -10
- package/dist/ui/assets/rolldown-runtime-S-ySWqyJ.js +0 -1
- package/dist/ui/assets/vis-network-NIJHUFI3.js +0 -908
- package/dist/ui/fonts/jetbrains-mono-latin-400-normal.woff +0 -0
- package/dist/ui/icon-wordmark.png +0 -0
- package/dist/ui/icon-wordmark.svg +0 -30
- package/dist/ui/icon.png +0 -0
- package/dist/ui/icon.svg +0 -25
- package/dist/ui/index.html +0 -15
- package/dist/ui/prototype-sandbox/index.html +0 -257
- package/dist/ui/screenshots/activity.png +0 -0
- package/dist/ui/screenshots/code-base-intelligence.png +0 -0
- package/dist/ui/screenshots/dashboard.png +0 -0
- package/dist/ui/screenshots/project-memory.png +0 -0
- package/dist/ui/screenshots/reasoning-quality.png +0 -0
- package/dist/ui/screenshots/reasoning-session.png +0 -0
- package/dist/ui/screenshots/token-session.png +0 -0
- package/dist/ui/screenshots/token-trace-main.png +0 -0
- package/dist/ui/screenshots/token-turn.png +0 -0
- package/dist/ui/unerr-wordmark.png +0 -0
- package/dist/ui/unerr-wordmark.svg +0 -9
- package/dist/ui/unerr.png +0 -0
- package/dist/ui/unerr.svg +0 -25
- package/dist/ui/web-app-manifest-192x192.png +0 -0
- package/dist/ui/web-app-manifest-512x512.png +0 -0
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, rmSync } from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { createEfficiencyTracker, } from "../proxy/efficiency-tracker.js";
|
|
6
|
-
import { TokenFlowWriter, aggregateSession, } from "../tracking/token-flow.js";
|
|
7
|
-
describe("token-flow-instrumentation", () => {
|
|
8
|
-
let tmpDir;
|
|
9
|
-
let unerrDir;
|
|
10
|
-
let writer;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
tmpDir = join(os.tmpdir(), `unerr-tfi-test-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`);
|
|
13
|
-
unerrDir = join(tmpDir, ".unerr");
|
|
14
|
-
mkdirSync(unerrDir, { recursive: true });
|
|
15
|
-
writer = new TokenFlowWriter(unerrDir, "test-session");
|
|
16
|
-
});
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
19
|
-
});
|
|
20
|
-
// ── TF-B.1: Graph Query Instrumentation ─────────────────────────
|
|
21
|
-
describe("graph_query mechanism", () => {
|
|
22
|
-
it("records savings from graph query vs file exploration counterfactual", () => {
|
|
23
|
-
writer.record({
|
|
24
|
-
session_id: "test-session",
|
|
25
|
-
turn: 1,
|
|
26
|
-
mechanism: "graph_query",
|
|
27
|
-
tool: "get_callers",
|
|
28
|
-
tokens_without: 5000,
|
|
29
|
-
tokens_with: 1800,
|
|
30
|
-
tokens_saved: 3200,
|
|
31
|
-
detail: { counterfactual: "file_read" },
|
|
32
|
-
});
|
|
33
|
-
const events = writer.getSessionEvents();
|
|
34
|
-
expect(events).toHaveLength(1);
|
|
35
|
-
expect(events[0].mechanism).toBe("graph_query");
|
|
36
|
-
expect(events[0].tokens_saved).toBe(3200);
|
|
37
|
-
expect(events[0].detail?.counterfactual).toBe("file_read");
|
|
38
|
-
});
|
|
39
|
-
it("graph_query dominates typical session savings", () => {
|
|
40
|
-
writer.record({
|
|
41
|
-
session_id: "test-session",
|
|
42
|
-
turn: 1,
|
|
43
|
-
mechanism: "graph_query",
|
|
44
|
-
tool: "search_code",
|
|
45
|
-
tokens_without: 5000,
|
|
46
|
-
tokens_with: 1800,
|
|
47
|
-
tokens_saved: 3200,
|
|
48
|
-
});
|
|
49
|
-
writer.record({
|
|
50
|
-
session_id: "test-session",
|
|
51
|
-
turn: 2,
|
|
52
|
-
mechanism: "graph_query",
|
|
53
|
-
tool: "get_entity",
|
|
54
|
-
tokens_without: 3000,
|
|
55
|
-
tokens_with: 2400,
|
|
56
|
-
tokens_saved: 600,
|
|
57
|
-
});
|
|
58
|
-
writer.record({
|
|
59
|
-
session_id: "test-session",
|
|
60
|
-
turn: 3,
|
|
61
|
-
mechanism: "graph_query",
|
|
62
|
-
tool: "get_callers",
|
|
63
|
-
tokens_without: 6800,
|
|
64
|
-
tokens_with: 2000,
|
|
65
|
-
tokens_saved: 4800,
|
|
66
|
-
});
|
|
67
|
-
const summary = aggregateSession(writer.getSessionEvents(), "test-session");
|
|
68
|
-
expect(summary.by_mechanism.graph_query.tokens_saved).toBe(8600);
|
|
69
|
-
expect(summary.by_mechanism.graph_query.pct_of_total).toBe(100);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
// ── TF-B.2: Session Dedup Instrumentation ───────────────────────
|
|
73
|
-
describe("session_dedup mechanism", () => {
|
|
74
|
-
it("records deduped context keys as savings", () => {
|
|
75
|
-
writer.record({
|
|
76
|
-
session_id: "test-session",
|
|
77
|
-
turn: 5,
|
|
78
|
-
mechanism: "session_dedup",
|
|
79
|
-
tool: "get_entity",
|
|
80
|
-
tokens_without: 480,
|
|
81
|
-
tokens_with: 0,
|
|
82
|
-
tokens_saved: 480,
|
|
83
|
-
detail: { keys_deduped: 3 },
|
|
84
|
-
});
|
|
85
|
-
const events = writer.getSessionEvents();
|
|
86
|
-
expect(events).toHaveLength(1);
|
|
87
|
-
expect(events[0].mechanism).toBe("session_dedup");
|
|
88
|
-
expect(events[0].tokens_with).toBe(0);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
// ── TF-B.3: Format Encoding Instrumentation ────────────────────
|
|
92
|
-
describe("format_encoding mechanism", () => {
|
|
93
|
-
it("records columnar encoding savings", () => {
|
|
94
|
-
writer.record({
|
|
95
|
-
session_id: "test-session",
|
|
96
|
-
turn: 3,
|
|
97
|
-
mechanism: "format_encoding",
|
|
98
|
-
tool: "get_callers",
|
|
99
|
-
tokens_without: 2000,
|
|
100
|
-
tokens_with: 1680,
|
|
101
|
-
tokens_saved: 320,
|
|
102
|
-
detail: { format: "columnar" },
|
|
103
|
-
});
|
|
104
|
-
const events = writer.getSessionEvents();
|
|
105
|
-
expect(events).toHaveLength(1);
|
|
106
|
-
expect(events[0].mechanism).toBe("format_encoding");
|
|
107
|
-
expect(events[0].detail?.format).toBe("columnar");
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
// ── TF-B.4: Shell Compression Instrumentation ──────────────────
|
|
111
|
-
describe("shell_compression mechanism", () => {
|
|
112
|
-
it("records shell compression with null tool and turn 0", () => {
|
|
113
|
-
writer.record({
|
|
114
|
-
session_id: "test-session",
|
|
115
|
-
turn: 0,
|
|
116
|
-
mechanism: "shell_compression",
|
|
117
|
-
tool: null,
|
|
118
|
-
tokens_without: 3400,
|
|
119
|
-
tokens_with: 800,
|
|
120
|
-
tokens_saved: 2600,
|
|
121
|
-
detail: { command: "ps aux", category: "tabular", strategy: "tabular" },
|
|
122
|
-
});
|
|
123
|
-
const events = writer.getSessionEvents();
|
|
124
|
-
expect(events).toHaveLength(1);
|
|
125
|
-
expect(events[0].tool).toBeNull();
|
|
126
|
-
expect(events[0].turn).toBe(0);
|
|
127
|
-
expect(events[0].mechanism).toBe("shell_compression");
|
|
128
|
-
});
|
|
129
|
-
it("shell compression savings aggregate into session totals", () => {
|
|
130
|
-
writer.record({
|
|
131
|
-
session_id: "test-session",
|
|
132
|
-
turn: 0,
|
|
133
|
-
mechanism: "shell_compression",
|
|
134
|
-
tool: null,
|
|
135
|
-
tokens_without: 3400,
|
|
136
|
-
tokens_with: 800,
|
|
137
|
-
tokens_saved: 2600,
|
|
138
|
-
});
|
|
139
|
-
writer.record({
|
|
140
|
-
session_id: "test-session",
|
|
141
|
-
turn: 0,
|
|
142
|
-
mechanism: "shell_compression",
|
|
143
|
-
tool: null,
|
|
144
|
-
tokens_without: 2100,
|
|
145
|
-
tokens_with: 600,
|
|
146
|
-
tokens_saved: 1500,
|
|
147
|
-
});
|
|
148
|
-
expect(writer.getSessionTokensSaved()).toBe(4100);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
// ── TF-B.5: Smart Truncation Instrumentation ───────────────────
|
|
152
|
-
describe("smart_truncation mechanism", () => {
|
|
153
|
-
it("records entity truncation savings", () => {
|
|
154
|
-
writer.record({
|
|
155
|
-
session_id: "test-session",
|
|
156
|
-
turn: 4,
|
|
157
|
-
mechanism: "smart_truncation",
|
|
158
|
-
tool: "get_entity",
|
|
159
|
-
tokens_without: 5000,
|
|
160
|
-
tokens_with: 2000,
|
|
161
|
-
tokens_saved: 3000,
|
|
162
|
-
detail: { level: "signatures_and_bodies" },
|
|
163
|
-
});
|
|
164
|
-
const events = writer.getSessionEvents();
|
|
165
|
-
expect(events).toHaveLength(1);
|
|
166
|
-
expect(events[0].mechanism).toBe("smart_truncation");
|
|
167
|
-
expect(events[0].detail?.level).toBe("signatures_and_bodies");
|
|
168
|
-
});
|
|
169
|
-
it("records list truncation savings", () => {
|
|
170
|
-
writer.record({
|
|
171
|
-
session_id: "test-session",
|
|
172
|
-
turn: 2,
|
|
173
|
-
mechanism: "smart_truncation",
|
|
174
|
-
tool: "get_callers",
|
|
175
|
-
tokens_without: 8000,
|
|
176
|
-
tokens_with: 2000,
|
|
177
|
-
tokens_saved: 6000,
|
|
178
|
-
detail: { type: "list", total: 50, returned: 12 },
|
|
179
|
-
});
|
|
180
|
-
const events = writer.getSessionEvents();
|
|
181
|
-
expect(events[0].detail?.type).toBe("list");
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
// ── TF-B.6: File Read Optimization Instrumentation ─────────────
|
|
185
|
-
describe("file_read mechanism", () => {
|
|
186
|
-
it("records file read windowing savings", () => {
|
|
187
|
-
writer.record({
|
|
188
|
-
session_id: "test-session",
|
|
189
|
-
turn: 6,
|
|
190
|
-
mechanism: "file_read",
|
|
191
|
-
tool: "file_read",
|
|
192
|
-
tokens_without: 10000,
|
|
193
|
-
tokens_with: 600,
|
|
194
|
-
tokens_saved: 9400,
|
|
195
|
-
detail: {
|
|
196
|
-
optimization: "file_read window lines 45-55 · entity",
|
|
197
|
-
total_lines: 500,
|
|
198
|
-
},
|
|
199
|
-
});
|
|
200
|
-
const events = writer.getSessionEvents();
|
|
201
|
-
expect(events).toHaveLength(1);
|
|
202
|
-
expect(events[0].mechanism).toBe("file_read");
|
|
203
|
-
expect(events[0].tokens_saved).toBe(9400);
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
// ── TF-B.7: Behavior Automation Instrumentation ────────────────
|
|
207
|
-
describe("behavior_automation mechanism", () => {
|
|
208
|
-
it("records halted tool call as savings", () => {
|
|
209
|
-
writer.record({
|
|
210
|
-
session_id: "test-session",
|
|
211
|
-
turn: 7,
|
|
212
|
-
mechanism: "behavior_automation",
|
|
213
|
-
tool: "get_entity",
|
|
214
|
-
tokens_without: 3200,
|
|
215
|
-
tokens_with: 400,
|
|
216
|
-
tokens_saved: 2800,
|
|
217
|
-
detail: { behavior: "cascade_guard", action: "halted" },
|
|
218
|
-
});
|
|
219
|
-
const events = writer.getSessionEvents();
|
|
220
|
-
expect(events).toHaveLength(1);
|
|
221
|
-
expect(events[0].mechanism).toBe("behavior_automation");
|
|
222
|
-
expect(events[0].detail?.behavior).toBe("cascade_guard");
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
// ── TF-B.8: _meta Enrichment ───────────────────────────────────
|
|
226
|
-
describe("session-level _meta enrichment", () => {
|
|
227
|
-
it("getSessionTokensSaved tracks running total", () => {
|
|
228
|
-
writer.record({
|
|
229
|
-
session_id: "test-session",
|
|
230
|
-
turn: 1,
|
|
231
|
-
mechanism: "graph_query",
|
|
232
|
-
tool: "t",
|
|
233
|
-
tokens_without: 5000,
|
|
234
|
-
tokens_with: 1800,
|
|
235
|
-
tokens_saved: 3200,
|
|
236
|
-
});
|
|
237
|
-
writer.record({
|
|
238
|
-
session_id: "test-session",
|
|
239
|
-
turn: 2,
|
|
240
|
-
mechanism: "format_encoding",
|
|
241
|
-
tool: "t",
|
|
242
|
-
tokens_without: 1800,
|
|
243
|
-
tokens_with: 1480,
|
|
244
|
-
tokens_saved: 320,
|
|
245
|
-
});
|
|
246
|
-
expect(writer.getSessionTokensSaved()).toBe(3520);
|
|
247
|
-
});
|
|
248
|
-
it("getSessionEfficiency computes percentage from all events", () => {
|
|
249
|
-
writer.record({
|
|
250
|
-
session_id: "test-session",
|
|
251
|
-
turn: 1,
|
|
252
|
-
mechanism: "graph_query",
|
|
253
|
-
tool: "t",
|
|
254
|
-
tokens_without: 10000,
|
|
255
|
-
tokens_with: 4000,
|
|
256
|
-
tokens_saved: 6000,
|
|
257
|
-
});
|
|
258
|
-
expect(writer.getSessionEfficiency()).toBe(60);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
// ── TF-B.9: EfficiencyTracker Supersession ─────────────────────
|
|
262
|
-
describe("EfficiencyTracker backed by TokenFlow", () => {
|
|
263
|
-
it("getSnapshot derives from token flow events", () => {
|
|
264
|
-
writer.record({
|
|
265
|
-
session_id: "test-session",
|
|
266
|
-
turn: 1,
|
|
267
|
-
mechanism: "graph_query",
|
|
268
|
-
tool: "get_callers",
|
|
269
|
-
tokens_without: 5000,
|
|
270
|
-
tokens_with: 1800,
|
|
271
|
-
tokens_saved: 3200,
|
|
272
|
-
});
|
|
273
|
-
writer.record({
|
|
274
|
-
session_id: "test-session",
|
|
275
|
-
turn: 2,
|
|
276
|
-
mechanism: "shell_compression",
|
|
277
|
-
tool: null,
|
|
278
|
-
tokens_without: 2000,
|
|
279
|
-
tokens_with: 800,
|
|
280
|
-
tokens_saved: 1200,
|
|
281
|
-
});
|
|
282
|
-
const tracker = createEfficiencyTracker(writer);
|
|
283
|
-
const snap = tracker.getSnapshot();
|
|
284
|
-
expect(snap.totalCalls).toBe(2);
|
|
285
|
-
expect(snap.originalTokens).toBe(7000);
|
|
286
|
-
expect(snap.deliveredTokens).toBe(2600);
|
|
287
|
-
expect(snap.savedTokens).toBe(4400);
|
|
288
|
-
expect(snap.efficiency).toBe(63);
|
|
289
|
-
expect(snap.avgSavingsPerCall).toBe(2200);
|
|
290
|
-
});
|
|
291
|
-
it("record() is a no-op when backed by TokenFlow", () => {
|
|
292
|
-
const tracker = createEfficiencyTracker(writer);
|
|
293
|
-
// Record should not affect TokenFlow-backed tracker
|
|
294
|
-
tracker.record(9999, 1111);
|
|
295
|
-
const snap = tracker.getSnapshot();
|
|
296
|
-
expect(snap.totalCalls).toBe(0);
|
|
297
|
-
expect(snap.savedTokens).toBe(0);
|
|
298
|
-
});
|
|
299
|
-
it("getEfficiency delegates to TokenFlow", () => {
|
|
300
|
-
writer.record({
|
|
301
|
-
session_id: "test-session",
|
|
302
|
-
turn: 1,
|
|
303
|
-
mechanism: "graph_query",
|
|
304
|
-
tool: "t",
|
|
305
|
-
tokens_without: 10000,
|
|
306
|
-
tokens_with: 3000,
|
|
307
|
-
tokens_saved: 7000,
|
|
308
|
-
});
|
|
309
|
-
const tracker = createEfficiencyTracker(writer);
|
|
310
|
-
expect(tracker.getEfficiency()).toBe(70);
|
|
311
|
-
});
|
|
312
|
-
it("getSavedTokens delegates to TokenFlow", () => {
|
|
313
|
-
writer.record({
|
|
314
|
-
session_id: "test-session",
|
|
315
|
-
turn: 1,
|
|
316
|
-
mechanism: "graph_query",
|
|
317
|
-
tool: "t",
|
|
318
|
-
tokens_without: 5000,
|
|
319
|
-
tokens_with: 2000,
|
|
320
|
-
tokens_saved: 3000,
|
|
321
|
-
});
|
|
322
|
-
const tracker = createEfficiencyTracker(writer);
|
|
323
|
-
expect(tracker.getSavedTokens()).toBe(3000);
|
|
324
|
-
});
|
|
325
|
-
it("fallback mode works without TokenFlow", () => {
|
|
326
|
-
const tracker = createEfficiencyTracker();
|
|
327
|
-
tracker.record(5000, 2000);
|
|
328
|
-
tracker.record(3000, 1000);
|
|
329
|
-
const snap = tracker.getSnapshot();
|
|
330
|
-
expect(snap.totalCalls).toBe(2);
|
|
331
|
-
expect(snap.originalTokens).toBe(8000);
|
|
332
|
-
expect(snap.deliveredTokens).toBe(3000);
|
|
333
|
-
expect(snap.savedTokens).toBe(5000);
|
|
334
|
-
expect(snap.efficiency).toBe(63);
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
// ── Multi-Mechanism Session ────────────────────────────────────
|
|
338
|
-
describe("multi-mechanism session scenario", () => {
|
|
339
|
-
it("aggregates 7 mechanism types with correct attribution", () => {
|
|
340
|
-
const events = [
|
|
341
|
-
{
|
|
342
|
-
mechanism: "graph_query",
|
|
343
|
-
saved: 38400,
|
|
344
|
-
without: 52000,
|
|
345
|
-
with_: 13600,
|
|
346
|
-
},
|
|
347
|
-
{
|
|
348
|
-
mechanism: "shell_compression",
|
|
349
|
-
saved: 4200,
|
|
350
|
-
without: 6200,
|
|
351
|
-
with_: 2000,
|
|
352
|
-
},
|
|
353
|
-
{
|
|
354
|
-
mechanism: "behavior_automation",
|
|
355
|
-
saved: 2400,
|
|
356
|
-
without: 2400,
|
|
357
|
-
with_: 0,
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
mechanism: "smart_truncation",
|
|
361
|
-
saved: 2100,
|
|
362
|
-
without: 3500,
|
|
363
|
-
with_: 1400,
|
|
364
|
-
},
|
|
365
|
-
{ mechanism: "file_read", saved: 1800, without: 2400, with_: 600 },
|
|
366
|
-
{
|
|
367
|
-
mechanism: "format_encoding",
|
|
368
|
-
saved: 1600,
|
|
369
|
-
without: 5600,
|
|
370
|
-
with_: 4000,
|
|
371
|
-
},
|
|
372
|
-
{ mechanism: "session_dedup", saved: 1100, without: 1100, with_: 0 },
|
|
373
|
-
];
|
|
374
|
-
for (const [i, e] of events.entries()) {
|
|
375
|
-
writer.record({
|
|
376
|
-
session_id: "test-session",
|
|
377
|
-
turn: i + 1,
|
|
378
|
-
mechanism: e.mechanism,
|
|
379
|
-
tool: i === 1 ? null : `tool_${i}`,
|
|
380
|
-
tokens_without: e.without,
|
|
381
|
-
tokens_with: e.with_,
|
|
382
|
-
tokens_saved: e.saved,
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
const summary = aggregateSession(writer.getSessionEvents(), "test-session");
|
|
386
|
-
expect(summary.total_turns).toBe(7);
|
|
387
|
-
expect(summary.total_tokens_saved).toBe(51600);
|
|
388
|
-
expect(summary.total_tokens_with).toBe(21600);
|
|
389
|
-
expect(summary.total_tokens_without).toBe(73200);
|
|
390
|
-
// graph_query should be the top mechanism
|
|
391
|
-
expect(summary.by_mechanism.graph_query.pct_of_total).toBeGreaterThan(70);
|
|
392
|
-
// All 7 mechanisms present
|
|
393
|
-
expect(Object.keys(summary.by_mechanism)).toHaveLength(7);
|
|
394
|
-
// Top turn should be graph_query
|
|
395
|
-
expect(summary.top_turns[0].primary_mechanism).toBe("graph_query");
|
|
396
|
-
// Efficiency matches the doc scenario (~70%)
|
|
397
|
-
expect(summary.efficiency_pct).toBeGreaterThan(60);
|
|
398
|
-
expect(summary.efficiency_pct).toBeLessThan(80);
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
// ── Cross-Process Shell Compression ────────────────────────────
|
|
402
|
-
describe("cross-process shell compression", () => {
|
|
403
|
-
it("shell compression events from exec processes include session_id from env", () => {
|
|
404
|
-
const sessionId = "cross-process-session-123";
|
|
405
|
-
writer.record({
|
|
406
|
-
session_id: sessionId,
|
|
407
|
-
turn: 0,
|
|
408
|
-
mechanism: "shell_compression",
|
|
409
|
-
tool: null,
|
|
410
|
-
tokens_without: 3400,
|
|
411
|
-
tokens_with: 800,
|
|
412
|
-
tokens_saved: 2600,
|
|
413
|
-
detail: { command: "ps aux", category: "tabular" },
|
|
414
|
-
});
|
|
415
|
-
const events = writer.getSessionEvents();
|
|
416
|
-
expect(events[0].session_id).toBe(sessionId);
|
|
417
|
-
expect(events[0].turn).toBe(0);
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
// ── Zero-Savings Edge Case ────────────────────────────────────
|
|
421
|
-
describe("zero-savings edge cases", () => {
|
|
422
|
-
it("zero-savings events are valid and aggregated", () => {
|
|
423
|
-
writer.record({
|
|
424
|
-
session_id: "test-session",
|
|
425
|
-
turn: 1,
|
|
426
|
-
mechanism: "format_encoding",
|
|
427
|
-
tool: "get_entity",
|
|
428
|
-
tokens_without: 500,
|
|
429
|
-
tokens_with: 500,
|
|
430
|
-
tokens_saved: 0,
|
|
431
|
-
});
|
|
432
|
-
const summary = aggregateSession(writer.getSessionEvents(), "test-session");
|
|
433
|
-
expect(summary.total_tokens_saved).toBe(0);
|
|
434
|
-
expect(summary.efficiency_pct).toBe(0);
|
|
435
|
-
});
|
|
436
|
-
});
|
|
437
|
-
});
|