Skip to content

Practical patterns, starters & CLI tools for loop engineering with AI coding agents. Design systems that prompt and orchestrate agents (inspired by Addy Osmani and Boris Cherny). Includes loop-audit, loop-init, loop-cost.

feat(loop-metrics): introduce token burn and ROI dashboard (#441)

THRISHAL DOMA2bd02a913336
diff --git a/package.json b/package.json
index 4299712..b7108a9 100644
--- a/package.json
+++ b/package.json
@@ -16,11 +16,12 @@
"test:loop-sandbox": "cd tools/loop-sandbox && npm test",
"test:loop-swarm": "cd tools/loop-swarm && npm test",
"test:loop": "cd tools/loop && npm test",
+ "test:loop-metrics": "cd tools/loop-metrics && npm test",
"test:goal-init": "cd tools/goal-init && npm test",
"test:readiness-core": "cd tools/readiness-core && npm test",
"test:goal-audit": "cd tools/goal-audit && npm test",
- "test:tools": "npm run test:readiness-core && npm run test:loop-audit && npm run test:loop-init && npm run test:loop-cost && npm run test:loop-sync && npm run test:loop-context && npm run test:loop-gate && npm run test:mcp-server && npm run test:loop-worktree && npm run test:loop-sandbox && npm run test:loop-swarm && npm run test:loop && npm run test:goal-audit && npm run test:goal-init",
- "build:tools": "cd tools/readiness-core && npm run build && cd ../loop-audit && npm run build && cd ../loop-init && npm run build && cd ../loop-cost && npm run build && cd ../loop-sync && npm run build && cd ../loop-context && npm run build && cd ../loop-gate && npm run build && cd ../mcp-server && npm run build && cd ../loop-worktree && npm run build && cd ../loop-sandbox && npm run build && cd ../loop-swarm && npm run build && cd ../loop && npm run build && cd ../goal-audit && npm run build && cd ../goal-init && npm run build",
+ "test:tools": "npm run test:readiness-core && npm run test:loop-audit && npm run test:loop-init && npm run test:loop-cost && npm run test:loop-sync && npm run test:loop-context && npm run test:loop-gate && npm run test:mcp-server && npm run test:loop-worktree && npm run test:loop-sandbox && npm run test:loop-swarm && npm run test:loop && npm run test:loop-metrics && npm run test:goal-audit && npm run test:goal-init",
+ "build:tools": "cd tools/readiness-core && npm run build && cd ../loop-audit && npm run build && cd ../loop-init && npm run build && cd ../loop-cost && npm run build && cd ../loop-sync && npm run build && cd ../loop-context && npm run build && cd ../loop-gate && npm run build && cd ../mcp-server && npm run build && cd ../loop-worktree && npm run build && cd ../loop-sandbox && npm run build && cd ../loop-swarm && npm run build && cd ../loop && npm run build && cd ../loop-metrics && npm run build && cd ../goal-audit && npm run build && cd ../goal-init && npm run build",
"contributors:generate": "node scripts/generate-contributors.mjs",
"contributors:check": "node scripts/generate-contributors.mjs --check"
},
diff --git a/tools/loop-metrics/README.md b/tools/loop-metrics/README.md
new file mode 100644
index 0000000..9a67cb8
--- /dev/null
+++ b/tools/loop-metrics/README.md
@@ -0,0 +1,45 @@
+# loop-metrics
+
+A CLI dashboard for visualizing the token burn, success rate, and ROI of your autonomous loops based on `loop-run-log.md`.
+
+## Installation
+
+This tool runs natively against your loop-engineering repository:
+
+```bash
+npm install -g @cobusgreyling/loop-metrics
+```
+
+*(Or just run it via `npx` from your project root without installing)*
+
+## Usage
+
+Run the dashboard from the root of a project containing a `loop-run-log.md`:
+
+```bash
+npx @cobusgreyling/loop-metrics
+```
+
+### Filtering
+
+You can filter the dashboard by a specific loop pattern or restrict the timeframe to a certain number of days (e.g. `7d` for the last 7 days):
+
+```bash
+# Only show metrics for the daily-triage pattern over the last 30 days
+npx @cobusgreyling/loop-metrics --pattern daily-triage --timeframe 30d
+```
+
+### Options
+
+- `--log <path>`: Path to your loop run log (default: `./loop-run-log.md`)
+- `--pattern <id>`: Calculate metrics only for a specific pattern.
+- `--timeframe <days>`: Limit calculation to runs within the last N days (e.g., `7d`, `30d`).
+- `--help`: Show the help message.
+
+## How ROI is Calculated
+
+`loop-metrics` uses a simple heuristic to calculate ROI:
+- **+10 points** for every `action_taken` (successful fix, triage, or state update).
+- **-5 points** for every `escalation` (tripping a circuit breaker or requiring human intervention).
+
+This gives you an instant, high-level view of whether your autonomous loops are providing net positive value or just generating noise.
diff --git a/tools/loop-metrics/dist/cli.d.ts b/tools/loop-metrics/dist/cli.d.ts
new file mode 100644
index 0000000..b798801
--- /dev/null
+++ b/tools/loop-metrics/dist/cli.d.ts
@@ -0,0 +1,2 @@
+#!/usr/bin/env node
+export {};
diff --git a/tools/loop-metrics/dist/cli.js b/tools/loop-metrics/dist/cli.js
new file mode 100644
index 0000000..422b72f
--- /dev/null
+++ b/tools/loop-metrics/dist/cli.js
@@ -0,0 +1,79 @@
+#!/usr/bin/env node
+import { parseArgs } from 'node:util';
+import path from 'node:path';
+import { parseLogFile, filterEntries, aggregateMetrics } from './metrics.js';
+const { values } = parseArgs({
+ options: {
+ log: { type: 'string', default: 'loop-run-log.md' },
+ pattern: { type: 'string' },
+ timeframe: { type: 'string' },
+ help: { type: 'boolean' }
+ }
+});
+if (values.help) {
+ console.log(`
+Usage: npx @cobusgreyling/loop-metrics [options]
+
+Options:
+ --log <path> Path to loop-run-log.md (default: ./loop-run-log.md)
+ --pattern <name> Filter by pattern (e.g. daily-triage)
+ --timeframe <days> Filter by timeframe (e.g. 7d, 30d)
+ --help Show this help message
+`);
+ process.exit(0);
+}
+// Colors
+const cyan = '\x1b[36m';
+const green = '\x1b[32m';
+const red = '\x1b[31m';
+const yellow = '\x1b[33m';
+const reset = '\x1b[0m';
+const bold = '\x1b[1m';
+async function main() {
+ try {
+ const logPath = path.resolve(process.cwd(), values.log);
+ const entries = await parseLogFile(logPath);
+ let days;
+ if (values.timeframe) {
+ const match = values.timeframe.match(/^(\d+)d$/);
+ if (match) {
+ days = parseInt(match[1], 10);
+ }
+ else {
+ console.error(`${red}Error: Invalid timeframe format. Use e.g., 7d, 30d.${reset}`);
+ process.exit(1);
+ }
+ }
+ const filtered = filterEntries(entries, values.pattern, days);
+ const metrics = aggregateMetrics(filtered);
+ console.log(`\n${bold}${cyan}╔════════════════════════════════════════════════════════╗${reset}`);
+ console.log(`${bold}${cyan}║ Loop Engineering Metrics ║${reset}`);
+ console.log(`${bold}${cyan}╚════════════════════════════════════════════════════════╝${reset}\n`);
+ console.log(` ${bold}Filter:${reset} ${values.pattern || 'All Patterns'}`);
+ console.log(` ${bold}Timeframe:${reset} ${values.timeframe || 'All Time'}`);
+ console.log(` ${bold}Log File:${reset} ${values.log}\n`);
+ console.log(` ${bold}Total Runs:${reset} ${metrics.totalRuns}`);
+ // Format tokens (e.g. 1.2M, 520k)
+ const fmt = (n) => n >= 1_000_000 ? `${(n / 1_000_000).toFixed(1)}M` : n >= 1_000 ? `${Math.round(n / 1_000)}k` : String(n);
+ console.log(` ${bold}Tokens Burned:${reset} ${fmt(metrics.totalTokens)}`);
+ console.log(` ${bold}Avg Duration:${reset} ${metrics.avgDurationS.toFixed(1)}s\n`);
+ console.log(` ${bold}Actions Taken:${reset} ${green}${metrics.totalActionsTaken}${reset}`);
+ const escColor = metrics.totalEscalations > 0 ? red : green;
+ console.log(` ${bold}Escalations:${reset} ${escColor}${metrics.totalEscalations}${reset}`);
+ const succColor = metrics.successRatePct >= 80 ? green : metrics.successRatePct >= 50 ? yellow : red;
+ console.log(` ${bold}Success Rate:${reset} ${succColor}${metrics.successRatePct.toFixed(1)}%${reset}`);
+ const roiColor = metrics.roiScore > 0 ? green : red;
+ console.log(` ${bold}ROI Score:${reset} ${roiColor}${metrics.roiScore}${reset}\n`);
+ }
+ catch (err) {
+ if (err.code === 'ENOENT') {
+ console.error(`${red}Error: Could not find ${values.log}.${reset}`);
+ console.error(`Are you in a repository root with a loop-run-log.md?`);
+ }
+ else {
+ console.error(`${red}Error:${reset}`, err.message);
+ }
+ process.exit(1);
+ }
+}
+main();
diff --git a/tools/loop-metrics/dist/metrics.d.ts b/tools/loop-metrics/dist/metrics.d.ts
new file mode 100644
index 0000000..bcc0717
--- /dev/null
+++ b/tools/loop-metrics/dist/metrics.d.ts
@@ -0,0 +1,23 @@
+export interface RunEntry {
+ run_id: string;
+ pattern: string;
+ duration_s: number;
+ items_found: number;
+ actions_taken: number;
+ escalations: number;
+ tokens_estimate: number;
+ outcome: string;
+}
+export interface MetricsDashboard {
+ totalRuns: number;
+ totalTokens: number;
+ totalDurationS: number;
+ totalActionsTaken: number;
+ totalEscalations: number;
+ successRatePct: number;
+ roiScore: number;
+ avgDurationS: number;
+}
+export declare function parseLogFile(filePath: string): Promise<RunEntry[]>;
+export declare function filterEntries(entries: RunEntry[], pattern?: string, days?: number): RunEntry[];
+export declare function aggregateMetrics(entries: RunEntry[]): MetricsDashboard;
diff --git a/tools/loop-metrics/dist/metrics.js b/tools/loop-metrics/dist/metrics.js
new file mode 100644
index 0000000..3a3c422
--- /dev/null
+++ b/tools/loop-metrics/dist/metrics.js
@@ -0,0 +1,72 @@
+import { readFile } from 'node:fs/promises';
+export async function parseLogFile(filePath) {
+ const content = await readFile(filePath, 'utf8');
+ const lines = content.split('\n');
+ const entries = [];
+ let inLogSection = false;
+ for (const line of lines) {
+ if (line.includes('<!-- Loop appends below this line -->')) {
+ inLogSection = true;
+ continue;
+ }
+ if (!inLogSection || line.trim() === '')
+ continue;
+ try {
+ const entry = JSON.parse(line.trim());
+ if (entry.run_id && entry.pattern) {
+ entries.push(entry);
+ }
+ }
+ catch (e) {
+ // Ignore malformed lines
+ }
+ }
+ return entries;
+}
+export function filterEntries(entries, pattern, days) {
+ let filtered = entries;
+ if (pattern) {
+ filtered = filtered.filter(e => e.pattern === pattern);
+ }
+ if (days && days > 0) {
+ const cutoffDate = new Date();
+ cutoffDate.setDate(cutoffDate.getDate() - days);
+ filtered = filtered.filter(e => {
+ try {
+ const entryDate = new Date(e.run_id);
+ return entryDate >= cutoffDate;
+ }
+ catch {
+ return true;
+ }
+ });
+ }
+ return filtered;
+}
+export function aggregateMetrics(entries) {
+ let totalTokens = 0;
+ let totalDurationS = 0;
+ let totalActionsTaken = 0;
+ let totalEscalations = 0;
+ for (const entry of entries) {
+ totalTokens += entry.tokens_estimate || 0;
+ totalDurationS += entry.duration_s || 0;
+ totalActionsTaken += entry.actions_taken || 0;
+ totalEscalations += entry.escalations || 0;
+ }
+ const totalRuns = entries.length;
+ const successRatePct = totalRuns > 0 ? ((totalRuns - totalEscalations) / totalRuns) * 100 : 0;
+ const avgDurationS = totalRuns > 0 ? totalDurationS / totalRuns : 0;
+ // Simple heuristic: Each successful action is worth +10, each escalation is -5.
+ const roiScore = (totalActionsTaken * 10) - (totalEscalations * 5);
+ return {
+ totalRuns,
+ totalTokens,
+ totalDurationS,
+ totalActionsTaken,
+ totalEscalations,
+ successRatePct,
+ roiScore,
+ avgDurationS
+ };
+}
diff --git a/tools/loop-metrics/package-lock.json b/tools/loop-metrics/package-lock.json
new file mode 100644
index 0000000..f3f328c
--- /dev/null
+++ b/tools/loop-metrics/package-lock.json
@@ -0,0 +1,54 @@
+{
+ "name": "@cobusgreyling/loop-metrics",
+ "version": "1.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "@cobusgreyling/loop-metrics",
+ "version": "1.0.0",
+ "license": "MIT",
+ "bin": {
+ "loop-metrics": "dist/cli.js"
+ },
+ "devDependencies": {
+ "@types/node": "^20.0.0",
+ "typescript": "^5.0.0"
+ },
+ "engines": {
+ "node": ">=18"
+ }
+ },
+ "node_modules/@types/node": {
+ "version": "20.19.43",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.43.tgz",
+ "integrity": "sha512-6oYBAi5ikg4Pl+kGsoYtawUMBT2zZMCvPNF7pVLnHZfd1zf38DRiWn/gT01RYCdUqkv7Fhr+C9ot4/tb+2sVvA==",
+ "dev": true,
+ "license": "MIT",
+ "dependencies": {
+ "undici-types": "~6.21.0"
+ }
+ },
+ "node_modules/typescript": {
+ "version": "5.9.3",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
+ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
+ "dev": true,
+ "license": "Apache-2.0",
+ "bin": {
+ "tsc": "bin/tsc",
+ "tsserver": "bin/tsserver"
+ },
+ "engines": {
+ "node": ">=14.17"
+ }
+ },
+ "node_modules/undici-types": {
+ "version": "6.21.0",
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
+ "dev": true,
+ "license": "MIT"
+ }
+ }
+}
diff --git a/tools/loop-metrics/package.json b/tools/loop-metrics/package.json
new file mode 100644
index 0000000..fb4b52a
--- /dev/null
+++ b/tools/loop-metrics/package.json
@@ -0,0 +1,40 @@
+{
+ "name": "@cobusgreyling/loop-metrics",
+ "version": "1.0.0",
+ "description": "Token and ROI CLI dashboard for loop-engineering.",
+ "type": "module",
+ "bin": {
+ "loop-metrics": "dist/cli.js"
+ },
+ "files": [
+ "dist",
+ "README.md"
+ ],
+ "scripts": {
+ "build": "tsc",
+ "test": "npm run build && node --test test/*.test.mjs",
+ "prepublishOnly": "npm test",
+ "start": "node dist/cli.js"
+ },
+ "engines": {
+ "node": ">=18"
+ },
+ "keywords": [
+ "loop-engineering",
+ "ai-agents",
+ "metrics",
+ "roi",
+ "dashboard"
+ ],
+ "author": "Cobus Greyling",
+ "license": "MIT",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/cobusgreyling/loop-engineering.git",
+ "directory": "tools/loop-metrics"
+ },
+ "devDependencies": {
+ "@types/node": "^20.0.0",
+ "typescript": "^5.0.0"
+ }
+}
diff --git a/tools/loop-metrics/src/cli.ts b/tools/loop-metrics/src/cli.ts
new file mode 100644
index 0000000..e676bcb
--- /dev/null
+++ b/tools/loop-metrics/src/cli.ts
@@ -0,0 +1,93 @@
+#!/usr/bin/env node
+
+import { parseArgs } from 'node:util';
+import path from 'node:path';
+import { parseLogFile, filterEntries, aggregateMetrics } from './metrics.js';
+
+const { values } = parseArgs({
+ options: {
+ log: { type: 'string', default: 'loop-run-log.md' },
+ pattern: { type: 'string' },
+ timeframe: { type: 'string' },
+ help: { type: 'boolean' }
+ }
+});
+
+if (values.help) {
+ console.log(`
+Usage: npx @cobusgreyling/loop-metrics [options]
+
+Options:
+ --log <path> Path to loop-run-log.md (default: ./loop-run-log.md)
+ --pattern <name> Filter by pattern (e.g. daily-triage)
+ --timeframe <days> Filter by timeframe (e.g. 7d, 30d)
+ --help Show this help message
+`);
+ process.exit(0);
+}
+
+// Colors
+const cyan = '\x1b[36m';
+const green = '\x1b[32m';
+const red = '\x1b[31m';
+const yellow = '\x1b[33m';
+const reset = '\x1b[0m';
+const bold = '\x1b[1m';
+
+async function main() {
+ try {
+ const logPath = path.resolve(process.cwd(), values.log as string);
+ const entries = await parseLogFile(logPath);
+
+ let days: number | undefined;
+ if (values.timeframe) {
+ const match = values.timeframe.match(/^(\d+)d$/);
+ if (match) {
+ days = parseInt(match[1], 10);
+ } else {
+ console.error(`${red}Error: Invalid timeframe format. Use e.g., 7d, 30d.${reset}`);
+ process.exit(1);
+ }
+ }
+
+ const filtered = filterEntries(entries, values.pattern, days);
+ const metrics = aggregateMetrics(filtered);
+
+ console.log(`\n${bold}${cyan}╔════════════════════════════════════════════════════════╗${reset}`);
+ console.log(`${bold}${cyan}║ Loop Engineering Metrics ║${reset}`);
+ console.log(`${bold}${cyan}╚════════════════════════════════════════════════════════╝${reset}\n`);
+
+ console.log(` ${bold}Filter:${reset} ${values.pattern || 'All Patterns'}`);
+ console.log(` ${bold}Timeframe:${reset} ${values.timeframe || 'All Time'}`);
+ console.log(` ${bold}Log File:${reset} ${values.log}\n`);
+
+ console.log(` ${bold}Total Runs:${reset} ${metrics.totalRuns}`);
+
+ // Format tokens (e.g. 1.2M, 520k)
+ const fmt = (n: number) => n >= 1_000_000 ? `${(n / 1_000_000).toFixed(1)}M` : n >= 1_000 ? `${Math.round(n / 1_000)}k` : String(n);
+ console.log(` ${bold}Tokens Burned:${reset} ${fmt(metrics.totalTokens)}`);
+ console.log(` ${bold}Avg Duration:${reset} ${metrics.avgDurationS.toFixed(1)}s\n`);
+
+ console.log(` ${bold}Actions Taken:${reset} ${green}${metrics.totalActionsTaken}${reset}`);
+
+ const escColor = metrics.totalEscalations > 0 ? red : green;
+ console.log(` ${bold}Escalations:${reset} ${escColor}${metrics.totalEscalations}${reset}`);
+
+ const succColor = metrics.successRatePct >= 80 ? green : metrics.successRatePct >= 50 ? yellow : red;
+ console.log(` ${bold}Success Rate:${reset} ${succColor}${metrics.successRatePct.toFixed(1)}%${reset}`);
+
+ const roiColor = metrics.roiScore > 0 ? green : red;
+ console.log(` ${bold}ROI Score:${reset} ${roiColor}${metrics.roiScore}${reset}\n`);
+
+ } catch (err: any) {
+ if (err.code === 'ENOENT') {
+ console.error(`${red}Error: Could not find ${values.log}.${reset}`);
+ console.error(`Are you in a repository root with a loop-run-log.md?`);
+ } else {
+ console.error(`${red}Error:${reset}`, err.message);
+ }
+ process.exit(1);
+ }
+}
+
+main();
diff --git a/tools/loop-metrics/src/metrics.ts b/tools/loop-metrics/src/metrics.ts
new file mode 100644
index 0000000..aea4832
--- /dev/null
+++ b/tools/loop-metrics/src/metrics.ts
@@ -0,0 +1,105 @@
+import { readFile } from 'node:fs/promises';
+
+export interface RunEntry {
+ run_id: string;
+ pattern: string;
+ duration_s: number;
+ items_found: number;
+ actions_taken: number;
+ escalations: number;
+ tokens_estimate: number;
+ outcome: string;
+}
+
+export interface MetricsDashboard {
+ totalRuns: number;
+ totalTokens: number;
+ totalDurationS: number;
+ totalActionsTaken: number;
+ totalEscalations: number;
+ successRatePct: number;
+ roiScore: number;
+ avgDurationS: number;
+}
+
+export async function parseLogFile(filePath: string): Promise<RunEntry[]> {
+ const content = await readFile(filePath, 'utf8');
+ const lines = content.split('\n');
+ const entries: RunEntry[] = [];
+ let inLogSection = false;
+
+ for (const line of lines) {
+ if (line.includes('<!-- Loop appends below this line -->')) {
+ inLogSection = true;
+ continue;
+ }
+ if (!inLogSection || line.trim() === '') continue;
+
+ try {
+ const entry = JSON.parse(line.trim());
+ if (entry.run_id && entry.pattern) {
+ entries.push(entry as RunEntry);
+ }
+ } catch (e) {
+ // Ignore malformed lines
+ }
+ }
+
+ return entries;
+}
+
+export function filterEntries(entries: RunEntry[], pattern?: string, days?: number): RunEntry[] {
+ let filtered = entries;
+
+ if (pattern) {
+ filtered = filtered.filter(e => e.pattern === pattern);
+ }
+
+ if (days && days > 0) {
+ const cutoffDate = new Date();
+ cutoffDate.setDate(cutoffDate.getDate() - days);
+
+ filtered = filtered.filter(e => {
+ try {
+ const entryDate = new Date(e.run_id);
+ return entryDate >= cutoffDate;
+ } catch {
+ return true;
+ }
+ });
+ }
+
+ return filtered;
+}
+
+export function aggregateMetrics(entries: RunEntry[]): MetricsDashboard {
+ let totalTokens = 0;
+ let totalDurationS = 0;
+ let totalActionsTaken = 0;
+ let totalEscalations = 0;
+
+ for (const entry of entries) {
+ totalTokens += entry.tokens_estimate || 0;
+ totalDurationS += entry.duration_s || 0;
+ totalActionsTaken += entry.actions_taken || 0;
+ totalEscalations += entry.escalations || 0;
+ }
+
+ const totalRuns = entries.length;
+ const successRatePct = totalRuns > 0 ? ((totalRuns - totalEscalations) / totalRuns) * 100 : 0;
+ const avgDurationS = totalRuns > 0 ? totalDurationS / totalRuns : 0;
+
+ // Simple heuristic: Each successful action is worth +10, each escalation is -5.
+ const roiScore = (totalActionsTaken * 10) - (totalEscalations * 5);
+
+ return {
+ totalRuns,
+ totalTokens,
+ totalDurationS,
+ totalActionsTaken,
+ totalEscalations,
+ successRatePct,
+ roiScore,
+ avgDurationS
+ };
+}
diff --git a/tools/loop-metrics/test/metrics.test.mjs b/tools/loop-metrics/test/metrics.test.mjs
new file mode 100644
index 0000000..f47e554
--- /dev/null
+++ b/tools/loop-metrics/test/metrics.test.mjs
@@ -0,0 +1,20 @@
+import test from 'node:test';
+import assert from 'node:assert';
+import { filterEntries, aggregateMetrics } from '../dist/metrics.js';
+
+test('loop-metrics filters and aggregates', () => {
+ const entries = [
+ { run_id: '2026-07-29T08:53:29Z', pattern: 'daily-triage', duration_s: 8, items_found: 1, actions_taken: 1, escalations: 0, tokens_estimate: 52000, outcome: 'report-only' },
+ { run_id: '2026-07-30T08:50:34Z', pattern: 'daily-triage', duration_s: 5, items_found: 1, actions_taken: 2, escalations: 1, tokens_estimate: 52000, outcome: 'report-only' },
+ ];
+
+ const filtered = filterEntries(entries, 'daily-triage');
+ assert.strictEqual(filtered.length, 2);
+
+ const metrics = aggregateMetrics(filtered);
+ assert.strictEqual(metrics.totalRuns, 2);
+ assert.strictEqual(metrics.totalTokens, 104000);
+ assert.strictEqual(metrics.totalActionsTaken, 3);
+ assert.strictEqual(metrics.totalEscalations, 1);
+ assert.strictEqual(metrics.roiScore, (3 * 10) - (1 * 5)); // 25
+});
diff --git a/tools/loop-metrics/tsconfig.json b/tools/loop-metrics/tsconfig.json
new file mode 100644
index 0000000..524c729
--- /dev/null
+++ b/tools/loop-metrics/tsconfig.json
@@ -0,0 +1,15 @@
+{
+ "compilerOptions": {
+ "target": "ES2022",
+ "module": "NodeNext",
+ "moduleResolution": "NodeNext",
+ "outDir": "./dist",
+ "rootDir": "./src",
+ "strict": true,
+ "esModuleInterop": true,
+ "skipLibCheck": true,
+ "forceConsistentCasingInFileNames": true,
+ "declaration": true
+ },
+ "include": ["src/**/*"]
+}