@mizchi/vlmkit-core 0.7.0 → 0.8.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/run-ledger.ts +39 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mizchi/vlmkit-core",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "VRT diff engine + shared types — pure image / DOM / a11y / visual comparison primitives.",
5
5
  "license": "MIT",
6
6
  "author": "mizchi",
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Append-only run ledger for agent-loop tools.
3
+ *
4
+ * Every measurement invocation (`build page`, the dynamic gates,
5
+ * `verify markup`) appends one JSONL line to `.vlmkit/run-ledger.jsonl`
6
+ * under the working directory. This turns the "rounds" KPI from an agent
7
+ * self-report into an auditable record: a verifier can check that the
8
+ * agent actually re-measured after each fix, and how the headline numbers
9
+ * moved round by round (see docs/knowledge.md "Markup Agent KPI" — round
10
+ * counts were self-reported and unreliable in 5/5 S5 runs).
11
+ *
12
+ * Writes are best-effort: a ledger failure must never break the tool run.
13
+ * Opt out with VLMKIT_NO_LEDGER=1 (e.g. CI bulk runs).
14
+ */
15
+ import { appendFileSync, mkdirSync } from "node:fs";
16
+ import { join } from "node:path";
17
+
18
+ export interface RunLedgerEntry {
19
+ /** Tool name, e.g. "build-page", "check-breakpoints", "verify-markup". */
20
+ tool: string;
21
+ /** Primary input (attempt HTML or URL). */
22
+ source: string;
23
+ /** Secondary input (target PNG, manifest, ...) when applicable. */
24
+ target?: string;
25
+ /** Headline numbers, tool-specific but flat (matched/missing/extra/status/diffRatio...). */
26
+ headline: Record<string, string | number | boolean | null>;
27
+ }
28
+
29
+ export function appendRunLedger(entry: RunLedgerEntry, cwd = process.cwd()): void {
30
+ if (process.env.VLMKIT_NO_LEDGER === "1") return;
31
+ try {
32
+ const dir = join(cwd, ".vlmkit");
33
+ mkdirSync(dir, { recursive: true });
34
+ const line = JSON.stringify({ ts: new Date().toISOString(), ...entry });
35
+ appendFileSync(join(dir, "run-ledger.jsonl"), line + "\n");
36
+ } catch {
37
+ // Best-effort by design.
38
+ }
39
+ }