@miller-tech/uap 1.113.0 → 1.117.0

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 (42) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/cli/model.d.ts.map +1 -1
  3. package/dist/cli/model.js +19 -1
  4. package/dist/cli/model.js.map +1 -1
  5. package/dist/cli/systemd-services.d.ts +11 -0
  6. package/dist/cli/systemd-services.d.ts.map +1 -1
  7. package/dist/cli/systemd-services.js +46 -1
  8. package/dist/cli/systemd-services.js.map +1 -1
  9. package/dist/cli/wizard-config.d.ts.map +1 -1
  10. package/dist/cli/wizard-config.js +19 -1
  11. package/dist/cli/wizard-config.js.map +1 -1
  12. package/dist/dashboard/data-service.d.ts +9 -0
  13. package/dist/dashboard/data-service.d.ts.map +1 -1
  14. package/dist/dashboard/data-service.js +32 -13
  15. package/dist/dashboard/data-service.js.map +1 -1
  16. package/dist/mcp-router/tools/execute.d.ts.map +1 -1
  17. package/dist/mcp-router/tools/execute.js +4 -1
  18. package/dist/mcp-router/tools/execute.js.map +1 -1
  19. package/dist/memory/dynamic-retrieval.d.ts.map +1 -1
  20. package/dist/memory/dynamic-retrieval.js +3 -0
  21. package/dist/memory/dynamic-retrieval.js.map +1 -1
  22. package/dist/memory/embeddings.d.ts.map +1 -1
  23. package/dist/memory/embeddings.js +7 -1
  24. package/dist/memory/embeddings.js.map +1 -1
  25. package/dist/models/executor.d.ts.map +1 -1
  26. package/dist/models/executor.js +4 -1
  27. package/dist/models/executor.js.map +1 -1
  28. package/dist/models/types.d.ts +11 -0
  29. package/dist/models/types.d.ts.map +1 -1
  30. package/dist/models/types.js +14 -0
  31. package/dist/models/types.js.map +1 -1
  32. package/dist/utils/performance-monitor.d.ts +7 -0
  33. package/dist/utils/performance-monitor.d.ts.map +1 -1
  34. package/dist/utils/performance-monitor.js +22 -14
  35. package/dist/utils/performance-monitor.js.map +1 -1
  36. package/dist/utils/telemetry-store.d.ts +35 -0
  37. package/dist/utils/telemetry-store.d.ts.map +1 -0
  38. package/dist/utils/telemetry-store.js +212 -0
  39. package/dist/utils/telemetry-store.js.map +1 -0
  40. package/package.json +1 -1
  41. package/src/policies/enforcers/__pycache__/_common.cpython-312.pyc +0 -0
  42. package/tools/agents/scripts/__pycache__/toolcall_path_normalizer.cpython-312.pyc +0 -0
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Persisted telemetry store for dashboard panels that would otherwise read
3
+ * empty in-process singletons.
4
+ *
5
+ * The compression (`globalSessionStats`) and performance (`getPerformanceMonitor`)
6
+ * singletons are only populated inside the MCP-router / model-executor / memory
7
+ * processes. The `uap dash serve` process is a *separate* process, so it sees
8
+ * empty singletons and renders 0/empty Compression + Performance panels.
9
+ *
10
+ * These functions let the producing processes persist their samples to the
11
+ * shared `telemetry.db` (keyed by project cwd) so the dashboard process can read
12
+ * the real, cross-process values instead of the in-memory singleton.
13
+ *
14
+ * All writes are best-effort and fail open — telemetry must never break a hot
15
+ * path or a tool call.
16
+ */
17
+ import Database from 'better-sqlite3';
18
+ import { existsSync, mkdirSync } from 'node:fs';
19
+ import { dirname, join } from 'node:path';
20
+ import { computePercentiles } from './performance-monitor.js';
21
+ /** Keep at most this many perf samples per metric (mirrors PerformanceMonitor.maxSamples). */
22
+ const PERF_SAMPLES_PER_METRIC = 1000;
23
+ /** Cached DB handles, one per project cwd. Reused across calls to avoid open/close churn on hot paths. */
24
+ const dbCache = new Map();
25
+ let perfInsertCount = 0;
26
+ function telemetryDbPath(cwd) {
27
+ return join(cwd, 'agents', 'data', 'memory', 'telemetry.db');
28
+ }
29
+ /**
30
+ * Open (creating dir + tables) the shared telemetry.db, caching the handle per
31
+ * cwd. Returns null on any failure so callers can fail open.
32
+ */
33
+ function openStore(cwd) {
34
+ const cached = dbCache.get(cwd);
35
+ if (cached)
36
+ return cached;
37
+ try {
38
+ const dbPath = telemetryDbPath(cwd);
39
+ mkdirSync(dirname(dbPath), { recursive: true });
40
+ const db = new Database(dbPath);
41
+ // WAL + NORMAL so hot-path producer writes and the dash-serve reader don't
42
+ // block each other (this DB is written by 3 producer process families and
43
+ // read by the dashboard). Matches every other cross-process store in the
44
+ // repo (coordination/tasks/analytics).
45
+ db.pragma('journal_mode = WAL');
46
+ db.pragma('synchronous = NORMAL');
47
+ db.pragma('busy_timeout = 10000');
48
+ db.exec(`
49
+ CREATE TABLE IF NOT EXISTS compression_stats (
50
+ tool TEXT PRIMARY KEY,
51
+ calls INTEGER NOT NULL DEFAULT 0,
52
+ raw_bytes INTEGER NOT NULL DEFAULT 0,
53
+ context_bytes INTEGER NOT NULL DEFAULT 0,
54
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
55
+ );
56
+ CREATE TABLE IF NOT EXISTS perf_samples (
57
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
58
+ metric TEXT NOT NULL,
59
+ duration_ms REAL NOT NULL,
60
+ ts TEXT NOT NULL DEFAULT (datetime('now'))
61
+ );
62
+ CREATE INDEX IF NOT EXISTS idx_perf_samples_metric ON perf_samples(metric);
63
+ `);
64
+ dbCache.set(cwd, db);
65
+ return db;
66
+ }
67
+ catch {
68
+ return null;
69
+ }
70
+ }
71
+ /**
72
+ * Record a single compression sample (one tool call) as a running per-tool
73
+ * total. Cheap UPSERT — no per-call row growth.
74
+ */
75
+ export function persistCompressionSample(cwd, tool, rawBytes, contextBytes) {
76
+ const db = openStore(cwd);
77
+ if (!db)
78
+ return;
79
+ try {
80
+ db.prepare(`INSERT INTO compression_stats (tool, calls, raw_bytes, context_bytes, updated_at)
81
+ VALUES (?, 1, ?, ?, datetime('now'))
82
+ ON CONFLICT(tool) DO UPDATE SET
83
+ calls = calls + 1,
84
+ raw_bytes = raw_bytes + excluded.raw_bytes,
85
+ context_bytes = context_bytes + excluded.context_bytes,
86
+ updated_at = datetime('now')`).run(tool || 'unknown', Math.max(0, Math.round(rawBytes)), Math.max(0, Math.round(contextBytes)));
87
+ }
88
+ catch {
89
+ /* best-effort */
90
+ }
91
+ }
92
+ /**
93
+ * Read aggregate compression totals across all tools. Returns honest zeros
94
+ * (savings '0%') when nothing has been persisted yet.
95
+ */
96
+ export function readCompressionStats(cwd) {
97
+ const empty = {
98
+ rawBytes: 0,
99
+ contextBytes: 0,
100
+ savingsPercent: '0%',
101
+ totalCalls: 0,
102
+ };
103
+ if (!existsSync(telemetryDbPath(cwd)))
104
+ return empty;
105
+ const db = openStore(cwd);
106
+ if (!db)
107
+ return empty;
108
+ try {
109
+ const row = db
110
+ .prepare(`SELECT COALESCE(SUM(calls),0) AS calls,
111
+ COALESCE(SUM(raw_bytes),0) AS raw,
112
+ COALESCE(SUM(context_bytes),0) AS ctx
113
+ FROM compression_stats`)
114
+ .get();
115
+ const rawBytes = row.raw || 0;
116
+ const contextBytes = row.ctx || 0;
117
+ const savingsPercent = rawBytes > 0 ? `${Math.round((1 - contextBytes / rawBytes) * 100)}%` : '0%';
118
+ return { rawBytes, contextBytes, savingsPercent, totalCalls: row.calls || 0 };
119
+ }
120
+ catch {
121
+ return empty;
122
+ }
123
+ }
124
+ /**
125
+ * Record a single performance sample. Individual samples are retained (bounded
126
+ * to a rolling window per metric) so read-time percentile computation matches
127
+ * the in-memory PerformanceMonitor.
128
+ */
129
+ export function persistPerfSample(cwd, metric, durationMs) {
130
+ if (!metric || !Number.isFinite(durationMs) || durationMs < 0)
131
+ return;
132
+ const db = openStore(cwd);
133
+ if (!db)
134
+ return;
135
+ try {
136
+ db.prepare('INSERT INTO perf_samples (metric, duration_ms) VALUES (?, ?)').run(metric, durationMs);
137
+ // Prune periodically to bound the table (mirror the in-memory rolling window).
138
+ if (++perfInsertCount % 50 === 0) {
139
+ db.prepare(`DELETE FROM perf_samples WHERE id IN (
140
+ SELECT id FROM (
141
+ SELECT id, ROW_NUMBER() OVER (PARTITION BY metric ORDER BY id DESC) AS rn
142
+ FROM perf_samples
143
+ ) WHERE rn > ?
144
+ )`).run(PERF_SAMPLES_PER_METRIC);
145
+ }
146
+ }
147
+ catch {
148
+ /* best-effort */
149
+ }
150
+ }
151
+ /**
152
+ * Read per-metric performance percentiles from the persisted samples. Mirrors
153
+ * `PerformanceMonitor.exportMetrics()` shape/semantics so the dashboard renders
154
+ * identically whether data comes from the store or the in-process singleton.
155
+ */
156
+ export function readPerfMetrics(cwd) {
157
+ const result = {};
158
+ if (!existsSync(telemetryDbPath(cwd)))
159
+ return result;
160
+ const db = openStore(cwd);
161
+ if (!db)
162
+ return result;
163
+ try {
164
+ const rows = db
165
+ .prepare('SELECT metric, duration_ms FROM perf_samples ORDER BY metric, id')
166
+ .all();
167
+ const byMetric = new Map();
168
+ for (const r of rows) {
169
+ const arr = byMetric.get(r.metric) ?? [];
170
+ arr.push(r.duration_ms);
171
+ byMetric.set(r.metric, arr);
172
+ }
173
+ for (const [metric, samples] of byMetric) {
174
+ const stats = computePercentiles(samples);
175
+ if (stats)
176
+ result[metric] = stats;
177
+ }
178
+ return result;
179
+ }
180
+ catch {
181
+ return result;
182
+ }
183
+ }
184
+ /**
185
+ * Close and drop cached DB handles. Test-only cleanup to avoid handle leaks
186
+ * across many temp-dir fixtures.
187
+ */
188
+ export function closeTelemetryStores(cwd) {
189
+ if (cwd) {
190
+ const db = dbCache.get(cwd);
191
+ if (db) {
192
+ try {
193
+ db.close();
194
+ }
195
+ catch {
196
+ /* ignore */
197
+ }
198
+ dbCache.delete(cwd);
199
+ }
200
+ return;
201
+ }
202
+ for (const db of dbCache.values()) {
203
+ try {
204
+ db.close();
205
+ }
206
+ catch {
207
+ /* ignore */
208
+ }
209
+ }
210
+ dbCache.clear();
211
+ }
212
+ //# sourceMappingURL=telemetry-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-store.js","sourceRoot":"","sources":["../../src/utils/telemetry-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS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O,CAAC,KAAK,EAAE,CAAC;AAClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miller-tech/uap",
3
- "version": "1.113.0",
3
+ "version": "1.117.0",
4
4
  "description": "Autonomous AI agent memory system with CLAUDE.md protocol enforcement",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",