Skip to content

A self-organizing Obsidian vault that gives AI coding agents persistent memory.

feat: injection-size meter for the SessionStart eager layer (#120)

Brenno Ferraricebe8ac6e2ea
diff --git a/.claude/scripts/lib/session-start.ts b/.claude/scripts/lib/session-start.ts
index 8987969..6ab67e0 100644
--- a/.claude/scripts/lib/session-start.ts
+++ b/.claude/scripts/lib/session-start.ts
@@ -10,6 +10,16 @@ export function take(stdout: string, n: number): string {
return stdout.split("\n").slice(0, n).join("\n");
}
+/**
+ * Injection-size meter line: eager-layer bloat becomes visible the day it
+ * starts. kB = 1000 bytes, one decimal. Negative/NaN guard to 0.0kB — the
+ * meter must never be the thing that breaks the hook.
+ */
+export function formatInjectionSize(bytes: number): string {
+ const safe = Number.isFinite(bytes) && bytes > 0 ? bytes : 0;
+ return `_context injected: ${(safe / 1000).toFixed(1)}kB_`;
+}
+
/**
* Local-time date header matching `date +%Y-%m-%d` followed by the weekday
* name. Separate from `new Date()` so tests can pass a fixed date.
diff --git a/.claude/scripts/session-start.ts b/.claude/scripts/session-start.ts
index d1ca3f0..8ba816e 100644
--- a/.claude/scripts/session-start.ts
+++ b/.claude/scripts/session-start.ts
@@ -22,6 +22,7 @@ import { join } from "node:path";
import {
take,
formatDateHeader,
+ formatInjectionSize,
formatActiveWork,
formatRecentChanges,
isSkippedPath,
@@ -287,4 +288,7 @@ const sections = [
listMd().join("\n"),
];
-process.stdout.write(sections.join("\n") + "\n");
+const body = sections.join("\n") + "\n";
+process.stdout.write(
+ body + "\n" + formatInjectionSize(Buffer.byteLength(body, "utf-8")) + "\n",
+);
diff --git a/.claude/scripts/tests/session-start.test.ts b/.claude/scripts/tests/session-start.test.ts
index ccfa9a3..3556468 100644
--- a/.claude/scripts/tests/session-start.test.ts
+++ b/.claude/scripts/tests/session-start.test.ts
@@ -10,6 +10,7 @@ import assert from "node:assert/strict";
import {
take,
formatDateHeader,
+ formatInjectionSize,
formatActiveWork,
formatRecentChanges,
isSkippedPath,
@@ -581,3 +582,20 @@ describe("formatBrainIndex", () => {
assert.equal(out, "(none)");
});
});
+
+describe("formatInjectionSize", () => {
+ const cases: ReadonlyArray<readonly [number, string]> = [
+ [0, "_context injected: 0.0kB_"],
+ [999, "_context injected: 1.0kB_"], // toFixed rounds
+ [300, "_context injected: 0.3kB_"],
+ [58_400, "_context injected: 58.4kB_"],
+ [1_048_576, "_context injected: 1048.6kB_"],
+ [-5, "_context injected: 0.0kB_"],
+ [Number.NaN, "_context injected: 0.0kB_"],
+ ];
+ for (const [bytes, expected] of cases) {
+ test(`${bytes} → ${expected}`, () => {
+ assert.equal(formatInjectionSize(bytes), expected);
+ });
+ }
+});