@agent-wiki/mcp 0.19.0 → 0.21.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 (93) hide show
  1. package/dist/cobol/__tests__/call-boundary-lineage.test.js +475 -0
  2. package/dist/cobol/__tests__/call-boundary-lineage.test.js.map +1 -1
  3. package/dist/cobol/__tests__/db2-table-lineage.test.js +453 -3
  4. package/dist/cobol/__tests__/db2-table-lineage.test.js.map +1 -1
  5. package/dist/cobol/__tests__/extractors.test.js +74 -0
  6. package/dist/cobol/__tests__/extractors.test.js.map +1 -1
  7. package/dist/cobol/__tests__/lexer.test.js +42 -0
  8. package/dist/cobol/__tests__/lexer.test.js.map +1 -1
  9. package/dist/cobol/__tests__/variable-tracer.test.js +306 -0
  10. package/dist/cobol/__tests__/variable-tracer.test.js.map +1 -1
  11. package/dist/cobol/call-boundary-lineage.d.ts +28 -2
  12. package/dist/cobol/call-boundary-lineage.d.ts.map +1 -1
  13. package/dist/cobol/call-boundary-lineage.js +147 -9
  14. package/dist/cobol/call-boundary-lineage.js.map +1 -1
  15. package/dist/cobol/db2-table-lineage.d.ts +52 -3
  16. package/dist/cobol/db2-table-lineage.d.ts.map +1 -1
  17. package/dist/cobol/db2-table-lineage.js +143 -6
  18. package/dist/cobol/db2-table-lineage.js.map +1 -1
  19. package/dist/cobol/extractors.d.ts.map +1 -1
  20. package/dist/cobol/extractors.js +24 -10
  21. package/dist/cobol/extractors.js.map +1 -1
  22. package/dist/cobol/field-lineage.d.ts.map +1 -1
  23. package/dist/cobol/field-lineage.js +30 -6
  24. package/dist/cobol/field-lineage.js.map +1 -1
  25. package/dist/cobol/graph.d.ts +8 -0
  26. package/dist/cobol/graph.d.ts.map +1 -1
  27. package/dist/cobol/graph.js +10 -0
  28. package/dist/cobol/graph.js.map +1 -1
  29. package/dist/cobol/lexer.d.ts.map +1 -1
  30. package/dist/cobol/lexer.js +11 -0
  31. package/dist/cobol/lexer.js.map +1 -1
  32. package/dist/cobol/parser.d.ts.map +1 -1
  33. package/dist/cobol/parser.js +6 -0
  34. package/dist/cobol/parser.js.map +1 -1
  35. package/dist/cobol/plugin.d.ts.map +1 -1
  36. package/dist/cobol/plugin.js +7 -2
  37. package/dist/cobol/plugin.js.map +1 -1
  38. package/dist/cobol/types.d.ts +10 -0
  39. package/dist/cobol/types.d.ts.map +1 -1
  40. package/dist/cobol/variable-tracer.d.ts.map +1 -1
  41. package/dist/cobol/variable-tracer.js +100 -10
  42. package/dist/cobol/variable-tracer.js.map +1 -1
  43. package/dist/code-analysis.d.ts +8 -1
  44. package/dist/code-analysis.d.ts.map +1 -1
  45. package/dist/code-analysis.js.map +1 -1
  46. package/dist/evidence-migration.d.ts.map +1 -1
  47. package/dist/evidence-migration.js +15 -3
  48. package/dist/evidence-migration.js.map +1 -1
  49. package/dist/evidence-migration.test.js +4 -0
  50. package/dist/evidence-migration.test.js.map +1 -1
  51. package/dist/evidence-report.d.ts +82 -0
  52. package/dist/evidence-report.d.ts.map +1 -0
  53. package/dist/evidence-report.js +368 -0
  54. package/dist/evidence-report.js.map +1 -0
  55. package/dist/evidence-report.test.d.ts +2 -0
  56. package/dist/evidence-report.test.d.ts.map +1 -0
  57. package/dist/evidence-report.test.js +334 -0
  58. package/dist/evidence-report.test.js.map +1 -0
  59. package/dist/evidence-search-log.d.ts +33 -0
  60. package/dist/evidence-search-log.d.ts.map +1 -0
  61. package/dist/evidence-search-log.js +34 -0
  62. package/dist/evidence-search-log.js.map +1 -0
  63. package/dist/evidence-search-log.test.d.ts +2 -0
  64. package/dist/evidence-search-log.test.d.ts.map +1 -0
  65. package/dist/evidence-search-log.test.js +144 -0
  66. package/dist/evidence-search-log.test.js.map +1 -0
  67. package/dist/evidence-search.d.ts +2 -1
  68. package/dist/evidence-search.d.ts.map +1 -1
  69. package/dist/evidence-search.js +29 -1
  70. package/dist/evidence-search.js.map +1 -1
  71. package/dist/evidence-write-log.d.ts +94 -6
  72. package/dist/evidence-write-log.d.ts.map +1 -1
  73. package/dist/evidence-write-log.js +84 -83
  74. package/dist/evidence-write-log.js.map +1 -1
  75. package/dist/evidence-write-log.test.js +138 -7
  76. package/dist/evidence-write-log.test.js.map +1 -1
  77. package/dist/jsonl-log.d.ts +30 -0
  78. package/dist/jsonl-log.d.ts.map +1 -0
  79. package/dist/jsonl-log.js +97 -0
  80. package/dist/jsonl-log.js.map +1 -0
  81. package/dist/server.d.ts.map +1 -1
  82. package/dist/server.js +39 -11
  83. package/dist/server.js.map +1 -1
  84. package/dist/server.test.js +19 -0
  85. package/dist/server.test.js.map +1 -1
  86. package/dist/wiki.d.ts +47 -0
  87. package/dist/wiki.d.ts.map +1 -1
  88. package/dist/wiki.js +107 -15
  89. package/dist/wiki.js.map +1 -1
  90. package/dist/wiki.test.js +324 -0
  91. package/dist/wiki.test.js.map +1 -1
  92. package/docs/evidence-envelope.md +22 -3
  93. package/package.json +1 -1
@@ -25,8 +25,22 @@ export const ABSOLUTE_FLOOR = 2.0;
25
25
  const TOP1_OVER_TOP2_STRONG = 2.0;
26
26
  /** Provenance fan-out — top N pages cited in the envelope on a non-abstain match. */
27
27
  const PROVENANCE_LIMIT = 3;
28
- export function buildSearchEnvelope(results, query) {
28
+ export function buildSearchEnvelope(results, query, onEvent) {
29
+ // Telemetry is optional. Server call sites pass a closure that appends to
30
+ // the search log; tests and non-server callers omit it. Keeps this module
31
+ // free of filesystem knowledge.
32
+ const log = (event) => {
33
+ if (!onEvent)
34
+ return;
35
+ onEvent({ ...event, timestamp: new Date().toISOString() });
36
+ };
29
37
  if (results.length === 0) {
38
+ log({
39
+ abstainReason: "no-results",
40
+ top1Score: null,
41
+ top1Top2Ratio: null,
42
+ confidence: "absent",
43
+ });
30
44
  return {
31
45
  provenance: [],
32
46
  confidence: "absent",
@@ -41,6 +55,12 @@ export function buildSearchEnvelope(results, query) {
41
55
  // the weak hits as supporting evidence. Mention the top hits in the
42
56
  // rationale so a debugger can still see what the engine returned.
43
57
  const sample = results.slice(0, PROVENANCE_LIMIT).map((r) => r.path).join(", ");
58
+ log({
59
+ abstainReason: "below-floor",
60
+ top1Score: top1,
61
+ top1Top2Ratio: null,
62
+ confidence: "absent",
63
+ });
44
64
  return {
45
65
  provenance: [],
46
66
  confidence: "absent",
@@ -57,6 +77,14 @@ export function buildSearchEnvelope(results, query) {
57
77
  ? `Top match clearly dominates (${top1.toFixed(2)} vs ${top2.toFixed(2)}).`
58
78
  : `Top matches are close in score (${top1.toFixed(2)} vs ${top2.toFixed(2)}); ` +
59
79
  `multiple plausible answers — read several before relying on the top result.`;
80
+ log({
81
+ abstainReason: null,
82
+ top1Score: top1,
83
+ // Infinity is not JSON-serializable; record null when there's only one
84
+ // result (top2 == 0). The dashboard treats null as "single-result match".
85
+ top1Top2Ratio: top2 > 0 ? ratio : null,
86
+ confidence,
87
+ });
60
88
  return {
61
89
  provenance: results.slice(0, PROVENANCE_LIMIT).map((r) => ({ wikiPage: `wiki/${r.path}` })),
62
90
  confidence,
@@ -1 +1 @@
1
- {"version":3,"file":"evidence-search.js","sourceRoot":"","sources":["../src/evidence-search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,kFAAkF;AAClF,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC,wDAAwD;AACxD,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAElC,qFAAqF;AACrF,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,MAAM,UAAU,mBAAmB,CACjC,OAAuB,EACvB,KAAa;IAEb,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO;YACL,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,QAAQ;YACpB,KAAK,EAAE,aAAa;YACpB,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,mBAAmB,KAAK,IAAI;SACxC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC,KAA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Q,CAAC,CAAC,YAAY;IAC/B,CAAC;IAED,sEAAsE;IACtE,2DAA2D;IAC3D,MAAM,UAAU,GAAG,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;IAEtE,OAAO;QACL,GAAG,QAAQ;QACX,UAAU;QACV,UAAU;QACV,OAAO,EAAE,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO;QAC1D,SAAS,EACP,OAAO,CAAC,MAAM,GAAG,CAAC;YAChB,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,gBAAgB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,EAAE;YACxE,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,GAAG,SAAS,EAAE;KAC1C,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,CAAqB;IACrC,IAAI,CAAC,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,CAAC,KAAK,MAAM;QAAE,OAAO,QAAQ,CAAC;IAClC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -30,12 +30,57 @@ export interface UnsupportedWriteEvent {
30
30
  hadSynthesisFlag: boolean;
31
31
  /** Length of `sources: [...]` at write time. Always 0 for unsupported. */
32
32
  rawSourcesCount: number;
33
+ /**
34
+ * Phase 2b: `true` when the write was blocked by hard-reject mode.
35
+ * Absent on Phase 2a soft-warn writes. Lets the dashboard distinguish
36
+ * "stamped" from "blocked" and shows how often agents hit the rail.
37
+ *
38
+ * Note: unlike Phase 2a stamped events (which dedupe via the on-disk
39
+ * `unsupported: true` flag — the page transitions in once and stays),
40
+ * reject events fire on EVERY blocked attempt. A retry loop will
41
+ * generate one event per attempt. Dashboards should count distinct
42
+ * (page, day) pairs rather than raw event counts when comparing
43
+ * blocked-rate against stamped-rate.
44
+ */
45
+ rejected?: boolean;
46
+ /**
47
+ * Phase 2b: classifies why the reject path fired. `"fresh"` = page had
48
+ * neither sources nor synthesis on a first-time submission; `"legacy"`
49
+ * = page was already tagged `legacyUnsupported` and the new write
50
+ * didn't transition into grounded or synthesis. Absent on non-rejected
51
+ * (Phase 2a stamped) events.
52
+ */
53
+ rejectReason?: "fresh" | "legacy";
33
54
  }
34
55
  export declare function evidenceDir(workspace: string): string;
35
56
  export declare function writeLogPath(workspace: string): string;
57
+ export declare function counterLogPath(workspace: string): string;
36
58
  export declare function migrationMarkerPath(workspace: string): string;
59
+ /**
60
+ * Classification kinds for the per-write counter. Mirrors the branches in
61
+ * `wiki.ts` evidence classification — every classified write emits exactly
62
+ * one event, regardless of whether it transitions in/out of unsupported.
63
+ *
64
+ * - `grounded` — page has non-empty `sources: [...]`
65
+ * - `synthesis` — page has `synthesis: true` or `type: synthesis`
66
+ * - `unsupported`— page has neither, soft-warn mode (Phase 2a)
67
+ * - `rejected` — page has neither, hard-reject mode (Phase 2b)
68
+ * - `legacy` — page is tagged `legacyUnsupported`, soft-warn (skipped in unsupported log)
69
+ */
70
+ export type WriteEventKind = "grounded" | "synthesis" | "unsupported" | "rejected" | "legacy";
71
+ export interface WriteEvent {
72
+ timestamp: string;
73
+ kind: WriteEventKind;
74
+ }
37
75
  /** Append a single unsupported-write event. Best-effort — never throws. */
38
76
  export declare function appendUnsupportedWriteEvent(workspace: string, event: UnsupportedWriteEvent): void;
77
+ /**
78
+ * Append a per-write counter event — fired on every evidence-classified
79
+ * write so the dashboard can compute (unsupported / total) ratios. Unlike
80
+ * `appendUnsupportedWriteEvent` (which dedupes on the unsupported transition),
81
+ * this fires on every classified write attempt. Best-effort — never throws.
82
+ */
83
+ export declare function appendWriteEvent(workspace: string, kind: WriteEventKind, timestamp: string): void;
39
84
  /**
40
85
  * Read the log and return entries within the rotation window. Entries
41
86
  * outside the time window are silently dropped from the returned list
@@ -44,21 +89,64 @@ export declare function appendUnsupportedWriteEvent(workspace: string, event: Un
44
89
  */
45
90
  export declare function readWriteLog(workspace: string, now?: Date): UnsupportedWriteEvent[];
46
91
  /**
47
- * Truncate the log file in-place to rotation policy: drop entries older
48
- * than 30 days, then if the result still exceeds 10 MB drop oldest
49
- * entries until it fits. Called from `wiki_admin lint`.
92
+ * Read the per-write counter log within the 30-day rotation window. Same
93
+ * filtering rules as `readWriteLog`.
94
+ */
95
+ export declare function readWriteCounter(workspace: string, now?: Date): WriteEvent[];
96
+ /**
97
+ * Truncate both evidence log files (the unsupported-only log and the
98
+ * per-write counter) to rotation policy: drop entries older than 30 days,
99
+ * then if the result still exceeds 10 MB drop oldest entries until it
100
+ * fits. Called from `wiki_admin lint`.
101
+ *
102
+ * Returns combined counts across both files for the legacy single-file
103
+ * shape; per-file detail is available via `counter` / `unsupported`.
50
104
  */
51
105
  export declare function rotateEventLog(workspace: string, now?: Date): {
52
106
  entriesBefore: number;
53
107
  entriesAfter: number;
54
108
  bytesAfter: number;
109
+ unsupported: {
110
+ entriesBefore: number;
111
+ entriesAfter: number;
112
+ bytesAfter: number;
113
+ };
114
+ counter: {
115
+ entriesBefore: number;
116
+ entriesAfter: number;
117
+ bytesAfter: number;
118
+ };
55
119
  };
56
120
  /**
57
121
  * Count writes in the last 7 days, broken down for a one-line summary
58
- * the rebuild step appends to wiki/log.md. Phase 4 will replace this
59
- * with a richer dashboard.
122
+ * the rebuild step appends to wiki/log.md. Coexists with the Phase 4
123
+ * `wiki_admin --action evidence-report` dashboard: this stays as the
124
+ * cheap inline glance during rebuild; the dashboard is the full report
125
+ * when the operator asks for one.
126
+ *
127
+ * Returned numerators answer different questions:
128
+ *
129
+ * - `unsupportedTransitions` — distinct pages that *became* unsupported
130
+ * (from `evidence-write-log.jsonl`, deduped on transition). Answers:
131
+ * "how many new unsupported pages did agents introduce?"
132
+ *
133
+ * - `unsupportedWrites` — every write that ended up unsupported in
134
+ * warn mode, including re-edits (counter `kind: "unsupported"`).
135
+ *
136
+ * - `rejectedWrites` — every write blocked under Phase 2b reject mode
137
+ * (counter `kind: "rejected"`).
138
+ *
139
+ * `wouldRejectRatio` = `(unsupportedWrites + rejectedWrites) / totalWrites`.
140
+ * Mode-invariant: in warn mode, `rejectedWrites = 0` and the ratio
141
+ * reflects what 2b would block; in reject mode, `unsupportedWrites = 0`
142
+ * and the ratio reflects what 2b is currently blocking. `null` when
143
+ * `totalWrites === 0` to avoid a misleading 0% on early deployments.
60
144
  */
61
145
  export declare function summarizeLastWeek(workspace: string, now?: Date): {
62
- unsupportedCount: number;
146
+ unsupportedTransitions: number;
147
+ unsupportedWrites: number;
148
+ rejectedWrites: number;
149
+ totalWrites: number;
150
+ wouldRejectRatio: number | null;
63
151
  };
64
152
  //# sourceMappingURL=evidence-write-log.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"evidence-write-log.d.ts","sourceRoot":"","sources":["../src/evidence-write-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAYH,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,SAAS,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAC1B,0EAA0E;IAC1E,eAAe,EAAE,MAAM,CAAC;CACzB;AAUD,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAErD;AACD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtD;AACD,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,2EAA2E;AAC3E,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,qBAAqB,GAC3B,IAAI,CAQN;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,GAAG,GAAE,IAAiB,GACrB,qBA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E,MAAM,GAAG,IAAI,CAAC;CACjC,CAiCA"}
@@ -15,13 +15,12 @@
15
15
  *
16
16
  * See docs/evidence-envelope.md ("Unsupported-write telemetry").
17
17
  */
18
- import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync, } from "node:fs";
19
- import { dirname, join } from "node:path";
20
- const ROTATION_MAX_BYTES = 10 * 1024 * 1024; // 10 MB
21
- const ROTATION_MAX_AGE_DAYS = 30;
18
+ import { join } from "node:path";
19
+ import { appendJsonlEvent, readJsonlInWindow, rotateJsonlFile, } from "./jsonl-log.js";
22
20
  /** Path conventions, relative to a workspace root. */
23
21
  const EVIDENCE_DIR = ".agent-wiki";
24
22
  const WRITE_LOG_FILE = "evidence-write-log.jsonl";
23
+ const COUNTER_LOG_FILE = "evidence-write-counter.jsonl";
25
24
  const MIGRATION_MARKER_FILE = "evidence-migrated";
26
25
  export function evidenceDir(workspace) {
27
26
  return join(workspace, EVIDENCE_DIR);
@@ -29,19 +28,24 @@ export function evidenceDir(workspace) {
29
28
  export function writeLogPath(workspace) {
30
29
  return join(workspace, EVIDENCE_DIR, WRITE_LOG_FILE);
31
30
  }
31
+ export function counterLogPath(workspace) {
32
+ return join(workspace, EVIDENCE_DIR, COUNTER_LOG_FILE);
33
+ }
32
34
  export function migrationMarkerPath(workspace) {
33
35
  return join(workspace, EVIDENCE_DIR, MIGRATION_MARKER_FILE);
34
36
  }
35
37
  /** Append a single unsupported-write event. Best-effort — never throws. */
36
38
  export function appendUnsupportedWriteEvent(workspace, event) {
37
- try {
38
- const path = writeLogPath(workspace);
39
- mkdirSync(dirname(path), { recursive: true });
40
- appendFileSync(path, JSON.stringify(event) + "\n");
41
- }
42
- catch {
43
- // Telemetry must never break the write itself.
44
- }
39
+ appendJsonlEvent(writeLogPath(workspace), event);
40
+ }
41
+ /**
42
+ * Append a per-write counter event — fired on every evidence-classified
43
+ * write so the dashboard can compute (unsupported / total) ratios. Unlike
44
+ * `appendUnsupportedWriteEvent` (which dedupes on the unsupported transition),
45
+ * this fires on every classified write attempt. Best-effort — never throws.
46
+ */
47
+ export function appendWriteEvent(workspace, kind, timestamp) {
48
+ appendJsonlEvent(counterLogPath(workspace), { timestamp, kind });
45
49
  }
46
50
  /**
47
51
  * Read the log and return entries within the rotation window. Entries
@@ -50,90 +54,87 @@ export function appendUnsupportedWriteEvent(workspace, event) {
50
54
  * malformed lines are skipped.
51
55
  */
52
56
  export function readWriteLog(workspace, now = new Date()) {
53
- const path = writeLogPath(workspace);
54
- if (!existsSync(path))
55
- return [];
56
- try {
57
- const cutoffMs = now.getTime() - ROTATION_MAX_AGE_DAYS * 24 * 60 * 60 * 1000;
58
- const lines = readFileSync(path, "utf-8").split("\n");
59
- const events = [];
60
- for (const line of lines) {
61
- const trimmed = line.trim();
62
- if (!trimmed)
63
- continue;
64
- try {
65
- const entry = JSON.parse(trimmed);
66
- if (!entry.timestamp)
67
- continue;
68
- const t = new Date(entry.timestamp).getTime();
69
- if (Number.isFinite(t) && t >= cutoffMs)
70
- events.push(entry);
71
- }
72
- catch {
73
- // skip malformed line
74
- }
75
- }
76
- return events;
77
- }
78
- catch {
79
- return [];
80
- }
57
+ return readJsonlInWindow(writeLogPath(workspace), now);
81
58
  }
82
59
  /**
83
- * Truncate the log file in-place to rotation policy: drop entries older
84
- * than 30 days, then if the result still exceeds 10 MB drop oldest
85
- * entries until it fits. Called from `wiki_admin lint`.
60
+ * Read the per-write counter log within the 30-day rotation window. Same
61
+ * filtering rules as `readWriteLog`.
62
+ */
63
+ export function readWriteCounter(workspace, now = new Date()) {
64
+ return readJsonlInWindow(counterLogPath(workspace), now);
65
+ }
66
+ /**
67
+ * Truncate both evidence log files (the unsupported-only log and the
68
+ * per-write counter) to rotation policy: drop entries older than 30 days,
69
+ * then if the result still exceeds 10 MB drop oldest entries until it
70
+ * fits. Called from `wiki_admin lint`.
71
+ *
72
+ * Returns combined counts across both files for the legacy single-file
73
+ * shape; per-file detail is available via `counter` / `unsupported`.
86
74
  */
87
75
  export function rotateEventLog(workspace, now = new Date()) {
88
- const path = writeLogPath(workspace);
89
- if (!existsSync(path)) {
90
- return { entriesBefore: 0, entriesAfter: 0, bytesAfter: 0 };
91
- }
92
- const cutoffMs = now.getTime() - ROTATION_MAX_AGE_DAYS * 24 * 60 * 60 * 1000;
93
- const lines = readFileSync(path, "utf-8").split("\n").filter((l) => l.trim());
94
- const entriesBefore = lines.length;
95
- // First pass: drop entries older than the time window.
96
- const kept = [];
97
- for (const line of lines) {
98
- try {
99
- const entry = JSON.parse(line);
100
- const t = entry.timestamp ? new Date(entry.timestamp).getTime() : NaN;
101
- if (Number.isFinite(t) && t >= cutoffMs) {
102
- kept.push({ line, ts: t });
103
- }
104
- }
105
- catch {
106
- // malformed — drop
107
- }
108
- }
109
- // Second pass: if still over size cap, drop oldest entries.
110
- kept.sort((a, b) => a.ts - b.ts);
111
- let totalBytes = kept.reduce((acc, { line }) => acc + Buffer.byteLength(line) + 1, 0);
112
- while (totalBytes > ROTATION_MAX_BYTES && kept.length > 0) {
113
- const dropped = kept.shift();
114
- totalBytes -= Buffer.byteLength(dropped.line) + 1;
115
- }
116
- const newContent = kept.length === 0 ? "" : kept.map((k) => k.line).join("\n") + "\n";
117
- writeFileSync(path, newContent);
76
+ const unsupported = rotateJsonlFile(writeLogPath(workspace), now);
77
+ const counter = rotateJsonlFile(counterLogPath(workspace), now);
118
78
  return {
119
- entriesBefore,
120
- entriesAfter: kept.length,
121
- bytesAfter: Buffer.byteLength(newContent),
79
+ entriesBefore: unsupported.entriesBefore + counter.entriesBefore,
80
+ entriesAfter: unsupported.entriesAfter + counter.entriesAfter,
81
+ bytesAfter: unsupported.bytesAfter + counter.bytesAfter,
82
+ unsupported,
83
+ counter,
122
84
  };
123
85
  }
124
86
  /**
125
87
  * Count writes in the last 7 days, broken down for a one-line summary
126
- * the rebuild step appends to wiki/log.md. Phase 4 will replace this
127
- * with a richer dashboard.
88
+ * the rebuild step appends to wiki/log.md. Coexists with the Phase 4
89
+ * `wiki_admin --action evidence-report` dashboard: this stays as the
90
+ * cheap inline glance during rebuild; the dashboard is the full report
91
+ * when the operator asks for one.
92
+ *
93
+ * Returned numerators answer different questions:
94
+ *
95
+ * - `unsupportedTransitions` — distinct pages that *became* unsupported
96
+ * (from `evidence-write-log.jsonl`, deduped on transition). Answers:
97
+ * "how many new unsupported pages did agents introduce?"
98
+ *
99
+ * - `unsupportedWrites` — every write that ended up unsupported in
100
+ * warn mode, including re-edits (counter `kind: "unsupported"`).
101
+ *
102
+ * - `rejectedWrites` — every write blocked under Phase 2b reject mode
103
+ * (counter `kind: "rejected"`).
104
+ *
105
+ * `wouldRejectRatio` = `(unsupportedWrites + rejectedWrites) / totalWrites`.
106
+ * Mode-invariant: in warn mode, `rejectedWrites = 0` and the ratio
107
+ * reflects what 2b would block; in reject mode, `unsupportedWrites = 0`
108
+ * and the ratio reflects what 2b is currently blocking. `null` when
109
+ * `totalWrites === 0` to avoid a misleading 0% on early deployments.
128
110
  */
129
111
  export function summarizeLastWeek(workspace, now = new Date()) {
130
112
  const sevenDaysMs = 7 * 24 * 60 * 60 * 1000;
131
113
  const cutoff = now.getTime() - sevenDaysMs;
132
- const events = readWriteLog(workspace, now);
133
- const recent = events.filter((e) => {
134
- const t = new Date(e.timestamp).getTime();
114
+ const within = (ts) => {
115
+ const t = new Date(ts).getTime();
135
116
  return Number.isFinite(t) && t >= cutoff;
136
- });
137
- return { unsupportedCount: recent.length };
117
+ };
118
+ // Exclude `rejected: true` entries: the unsupported log carries BOTH
119
+ // warn-mode transitions (deduped) AND reject-mode attempts (one per
120
+ // blocked retry). Only the former are real "new unsupported pages".
121
+ const unsupportedTransitions = readWriteLog(workspace, now)
122
+ .filter((e) => within(e.timestamp) && !e.rejected)
123
+ .length;
124
+ const recentCounter = readWriteCounter(workspace, now)
125
+ .filter((e) => within(e.timestamp));
126
+ const totalWrites = recentCounter.length;
127
+ const unsupportedWrites = recentCounter.filter((e) => e.kind === "unsupported").length;
128
+ const rejectedWrites = recentCounter.filter((e) => e.kind === "rejected").length;
129
+ const wouldRejectRatio = totalWrites === 0
130
+ ? null
131
+ : (unsupportedWrites + rejectedWrites) / totalWrites;
132
+ return {
133
+ unsupportedTransitions,
134
+ unsupportedWrites,
135
+ rejectedWrites,
136
+ totalWrites,
137
+ wouldRejectRatio,
138
+ };
138
139
  }
139
140
  //# sourceMappingURL=evidence-write-log.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"evidence-write-log.js","sourceRoot":"","sources":["../src/evidence-write-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,YAAY,EAEZ,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAmB1C,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,QAAQ;AACrD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,sDAAsD;AACtD,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAClD,MAAM,qBAAqB,GAAG,mBAAmB,CAAC;AAElD,MAAM,UAAU,WAAW,CAAC,SAAiB;IAC3C,OAAO,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AACvC,CAAC;AACD,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,OAAO,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;AACvD,CAAC;AACD,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,OAAO,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,qBAAqB,CAAC,CAAC;AAC9D,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,2BAA2B,CACzC,SAAiB,EACjB,KAA4B;IAE5B,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,YAAY,CAAC,SAAS,CAA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C,MAAM,CACzC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAC7B,CAAC,MAAM,CAAC;IACT,MAAM,gBAAgB,GACpB,WAAW,KAAK,CAAC;QACf,CAAC,CAAC,IAAI;QACN,CAAC,CAAC,CAAC,iBAAiB,GAAG,cAAc,CAAC,GAAG,WAAW,CAAC;IACzD,OAAO;QACL,sBAAsB;QACtB,iBAAiB;QACjB,cAAc;QACd,WAAW;QACX,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
2
  import { mkdtempSync, rmSync, readFileSync, writeFileSync, existsSync, mkdirSync, statSync } from "node:fs";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
- import { appendUnsupportedWriteEvent, readWriteLog, rotateEventLog, summarizeLastWeek, writeLogPath, evidenceDir, } from "./evidence-write-log.js";
5
+ import { appendUnsupportedWriteEvent, appendWriteEvent, counterLogPath, readWriteCounter, readWriteLog, rotateEventLog, summarizeLastWeek, writeLogPath, evidenceDir, } from "./evidence-write-log.js";
6
6
  let workspace;
7
7
  beforeEach(() => {
8
8
  workspace = mkdtempSync(join(tmpdir(), "evidence-log-"));
@@ -88,9 +88,13 @@ describe("rotateEventLog", () => {
88
88
  expect(remaining).toContain("new.md");
89
89
  expect(remaining).not.toContain("old.md");
90
90
  });
91
- it("returns zero counts when no log file exists", () => {
91
+ it("returns zero counts when no log files exist", () => {
92
92
  const result = rotateEventLog(workspace);
93
- expect(result).toEqual({ entriesBefore: 0, entriesAfter: 0, bytesAfter: 0 });
93
+ expect(result.entriesBefore).toBe(0);
94
+ expect(result.entriesAfter).toBe(0);
95
+ expect(result.bytesAfter).toBe(0);
96
+ expect(result.unsupported).toEqual({ entriesBefore: 0, entriesAfter: 0, bytesAfter: 0 });
97
+ expect(result.counter).toEqual({ entriesBefore: 0, entriesAfter: 0, bytesAfter: 0 });
94
98
  });
95
99
  it("drops oldest entries when total exceeds size cap", () => {
96
100
  // Synthetic: write a 12 MB log — well over the 10 MB cap.
@@ -121,7 +125,7 @@ describe("rotateEventLog", () => {
121
125
  });
122
126
  });
123
127
  describe("summarizeLastWeek", () => {
124
- it("counts only events within the past 7 days", () => {
128
+ it("counts unsupported transitions only within the past 7 days", () => {
125
129
  const now = new Date("2026-05-06T00:00:00.000Z");
126
130
  appendUnsupportedWriteEvent(workspace, {
127
131
  page: "in.md", timestamp: "2026-05-04T00:00:00.000Z",
@@ -131,10 +135,137 @@ describe("summarizeLastWeek", () => {
131
135
  page: "out.md", timestamp: "2026-04-20T00:00:00.000Z",
132
136
  hadSynthesisFlag: false, rawSourcesCount: 0,
133
137
  });
134
- expect(summarizeLastWeek(workspace, now).unsupportedCount).toBe(1);
138
+ expect(summarizeLastWeek(workspace, now).unsupportedTransitions).toBe(1);
135
139
  });
136
- it("returns zero when no log file exists", () => {
137
- expect(summarizeLastWeek(workspace).unsupportedCount).toBe(0);
140
+ it("returns zero counts and null ratio when no log files exist", () => {
141
+ expect(summarizeLastWeek(workspace)).toEqual({
142
+ unsupportedTransitions: 0,
143
+ unsupportedWrites: 0,
144
+ rejectedWrites: 0,
145
+ totalWrites: 0,
146
+ wouldRejectRatio: null,
147
+ });
148
+ });
149
+ it("computes ratio as (unsupported + rejected) / total (mode-invariant)", () => {
150
+ const now = new Date("2026-05-06T00:00:00.000Z");
151
+ // Counter: 5 total — 2 grounded, 1 synthesis, 1 unsupported, 1 rejected.
152
+ // Numerator (would-reject) = unsupported + rejected = 2.
153
+ appendWriteEvent(workspace, "grounded", "2026-05-04T00:00:00.000Z");
154
+ appendWriteEvent(workspace, "grounded", "2026-05-04T00:01:00.000Z");
155
+ appendWriteEvent(workspace, "synthesis", "2026-05-05T00:00:00.000Z");
156
+ appendWriteEvent(workspace, "unsupported", "2026-05-04T00:00:00.000Z");
157
+ appendWriteEvent(workspace, "rejected", "2026-05-05T01:00:00.000Z");
158
+ const result = summarizeLastWeek(workspace, now);
159
+ expect(result.unsupportedWrites).toBe(1);
160
+ expect(result.rejectedWrites).toBe(1);
161
+ expect(result.totalWrites).toBe(5);
162
+ expect(result.wouldRejectRatio).toBeCloseTo(0.4);
163
+ });
164
+ it("ratio stays meaningful in reject mode (rejectedWrites carries the signal)", () => {
165
+ const now = new Date("2026-05-06T00:00:00.000Z");
166
+ // Phase 2b enabled — wiki.write never produces kind="unsupported";
167
+ // the equivalent writes show up as kind="rejected" instead.
168
+ appendWriteEvent(workspace, "grounded", "2026-05-04T00:00:00.000Z");
169
+ appendWriteEvent(workspace, "rejected", "2026-05-04T01:00:00.000Z");
170
+ appendWriteEvent(workspace, "rejected", "2026-05-04T02:00:00.000Z");
171
+ const result = summarizeLastWeek(workspace, now);
172
+ expect(result.unsupportedWrites).toBe(0);
173
+ expect(result.rejectedWrites).toBe(2);
174
+ expect(result.totalWrites).toBe(3);
175
+ // 2/3 ≈ 0.667 — the ratio still reflects "fraction of writes 2b blocks",
176
+ // even though all unsupported attempts went through the rejected path.
177
+ expect(result.wouldRejectRatio).toBeCloseTo(2 / 3);
178
+ });
179
+ it("reports transitions and unsupportedWrites independently when re-edits inflate the latter", () => {
180
+ const now = new Date("2026-05-06T00:00:00.000Z");
181
+ // 1 transition (page first becomes unsupported), 3 unsupported writes
182
+ // (the transition + 2 re-edits while still unsupported), plus 1 grounded
183
+ // — 4 total writes, 3 of which would be rejected by 2b.
184
+ appendUnsupportedWriteEvent(workspace, {
185
+ page: "p.md", timestamp: "2026-05-04T00:00:00.000Z",
186
+ hadSynthesisFlag: false, rawSourcesCount: 0,
187
+ });
188
+ appendWriteEvent(workspace, "unsupported", "2026-05-04T00:00:00.000Z");
189
+ appendWriteEvent(workspace, "unsupported", "2026-05-04T01:00:00.000Z");
190
+ appendWriteEvent(workspace, "unsupported", "2026-05-04T02:00:00.000Z");
191
+ appendWriteEvent(workspace, "grounded", "2026-05-05T00:00:00.000Z");
192
+ const result = summarizeLastWeek(workspace, now);
193
+ expect(result.unsupportedTransitions).toBe(1);
194
+ expect(result.unsupportedWrites).toBe(3);
195
+ expect(result.totalWrites).toBe(4);
196
+ expect(result.wouldRejectRatio).toBeCloseTo(0.75);
197
+ });
198
+ it("excludes counter events outside the 7-day window from the denominator", () => {
199
+ const now = new Date("2026-05-06T00:00:00.000Z");
200
+ appendWriteEvent(workspace, "grounded", "2026-05-04T00:00:00.000Z"); // in
201
+ appendWriteEvent(workspace, "grounded", "2026-04-20T00:00:00.000Z"); // out of 7d (still in 30d)
202
+ const result = summarizeLastWeek(workspace, now);
203
+ expect(result.totalWrites).toBe(1);
204
+ expect(result.wouldRejectRatio).toBe(0);
205
+ });
206
+ it("excludes rejected entries from unsupportedTransitions (Phase 2b log noise)", () => {
207
+ const now = new Date("2026-05-06T00:00:00.000Z");
208
+ // The unsupported log carries TWO event shapes: warn-mode transitions
209
+ // (no `rejected` flag) and reject-mode attempts (`rejected: true`,
210
+ // emitted once per retry). Only the former count as transitions —
211
+ // otherwise a retry loop in reject mode would balloon the count.
212
+ appendUnsupportedWriteEvent(workspace, {
213
+ page: "real-transition.md", timestamp: "2026-05-04T00:00:00.000Z",
214
+ hadSynthesisFlag: false, rawSourcesCount: 0,
215
+ });
216
+ appendUnsupportedWriteEvent(workspace, {
217
+ page: "blocked.md", timestamp: "2026-05-04T01:00:00.000Z",
218
+ hadSynthesisFlag: false, rawSourcesCount: 0,
219
+ rejected: true, rejectReason: "fresh",
220
+ });
221
+ appendUnsupportedWriteEvent(workspace, {
222
+ page: "blocked.md", timestamp: "2026-05-04T01:01:00.000Z",
223
+ hadSynthesisFlag: false, rawSourcesCount: 0,
224
+ rejected: true, rejectReason: "fresh",
225
+ });
226
+ const result = summarizeLastWeek(workspace, now);
227
+ expect(result.unsupportedTransitions).toBe(1);
228
+ });
229
+ });
230
+ describe("appendWriteEvent / readWriteCounter", () => {
231
+ it("appends classified writes to the counter file", () => {
232
+ appendWriteEvent(workspace, "grounded", "2026-05-06T10:00:00.000Z");
233
+ appendWriteEvent(workspace, "synthesis", "2026-05-06T10:01:00.000Z");
234
+ appendWriteEvent(workspace, "unsupported", "2026-05-06T10:02:00.000Z");
235
+ appendWriteEvent(workspace, "rejected", "2026-05-06T10:03:00.000Z");
236
+ appendWriteEvent(workspace, "legacy", "2026-05-06T10:04:00.000Z");
237
+ const events = readWriteCounter(workspace, new Date("2026-05-07T00:00:00.000Z"));
238
+ expect(events.map((e) => e.kind)).toEqual([
239
+ "grounded", "synthesis", "unsupported", "rejected", "legacy",
240
+ ]);
241
+ });
242
+ it("filters counter entries older than 30 days on read", () => {
243
+ appendWriteEvent(workspace, "grounded", "2026-01-01T00:00:00.000Z");
244
+ appendWriteEvent(workspace, "grounded", "2026-05-05T00:00:00.000Z");
245
+ const events = readWriteCounter(workspace, new Date("2026-05-06T00:00:00.000Z"));
246
+ expect(events).toHaveLength(1);
247
+ });
248
+ it("does not throw when the counter directory is unwritable", () => {
249
+ const nonexistent = join(workspace, "blocked", "path");
250
+ writeFileSync(join(workspace, "blocked"), "not a dir");
251
+ expect(() => appendWriteEvent(nonexistent, "grounded", "2026-05-06T10:00:00.000Z")).not.toThrow();
252
+ });
253
+ });
254
+ describe("rotateEventLog (counter file)", () => {
255
+ it("rotates the counter file alongside the unsupported log", () => {
256
+ appendWriteEvent(workspace, "grounded", "2025-01-01T00:00:00.000Z"); // old
257
+ appendWriteEvent(workspace, "grounded", "2026-05-05T00:00:00.000Z"); // new
258
+ appendUnsupportedWriteEvent(workspace, {
259
+ page: "u.md", timestamp: "2026-05-05T00:00:00.000Z",
260
+ hadSynthesisFlag: false, rawSourcesCount: 0,
261
+ });
262
+ const result = rotateEventLog(workspace, new Date("2026-05-06T00:00:00.000Z"));
263
+ expect(result.counter.entriesBefore).toBe(2);
264
+ expect(result.counter.entriesAfter).toBe(1);
265
+ expect(result.unsupported.entriesAfter).toBe(1);
266
+ const remaining = readFileSync(counterLogPath(workspace), "utf-8");
267
+ expect(remaining).not.toContain("2025-01-01");
268
+ expect(remaining).toContain("2026-05-05");
138
269
  });
139
270
  });
140
271
  //# sourceMappingURL=evidence-write-log.test.js.map