@hover-dev/core 0.22.0 → 0.24.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.
package/dist/engine.d.ts CHANGED
@@ -18,6 +18,14 @@ export type { SkillStep } from './specs/specStep.js';
18
18
  export { reRenderSpec } from './specs/writeSpec.js';
19
19
  export { writeApiSpec } from './specs/writeApiSpec.js';
20
20
  export type { ApiCheck, WriteApiSpecOptions, WriteApiSpecResult } from './specs/writeApiSpec.js';
21
+ export { buildOptimizeBrief, saveOptimizedCandidate, OptimizeError } from './specs/optimizeSpec.js';
22
+ export type { OptimizeResult } from './specs/optimizeSpec.js';
23
+ export { appendWikiLog, readWikiLog, wikiLogPath } from './specs/wikiLog.js';
24
+ export type { WikiLogKind, WikiLogEntry } from './specs/wikiLog.js';
25
+ export { lintWiki, parseRunStatuses } from './specs/lintWiki.js';
26
+ export type { LintResult, LintFinding, LintKind, LintSeverity } from './specs/lintWiki.js';
27
+ export { parseBusinessMap } from './specs/businessMap.js';
28
+ export type { BusinessMapGraph, MapNode, MapEdge } from './specs/businessMap.js';
21
29
  export { extractPageObjects, detectExtractableFlows } from './specs/extractPageObjects.js';
22
30
  export type { ExtractResult, ExtractedPage } from './specs/extractPageObjects.js';
23
31
  export type { SharedFlow } from './specs/detectSharedFlows.js';
@@ -27,7 +35,7 @@ export { readSidecar } from './specs/sidecar.js';
27
35
  export type { SpecSidecar } from './specs/sidecar.js';
28
36
  export { launchDebugChrome, closeDebugChrome, findChromeBinary } from './playwright/launchChrome.js';
29
37
  export type { LaunchOptions, LaunchResult } from './playwright/launchChrome.js';
30
- export { loadMemory, formatMemoryForPrompt, writeFact, memoryDir } from './memory/businessMemory.js';
38
+ export { loadMemory, formatMemoryForPrompt, formatMemoryIndex, recallMemory, readFact, formatFact, writeFact, memoryDir } from './memory/businessMemory.js';
31
39
  export type { BusinessFact } from './memory/businessMemory.js';
32
40
  export { QA_INTENSITY, DEFAULT_QA_INTENSITY, asQaIntensity, qaBudgetDirective } from './qa/intensity.js';
33
41
  export type { QaIntensity, QaIntensitySpec } from './qa/intensity.js';
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACzF,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAEjG,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAClF,YAAY,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACjH,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEzG,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrG,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAGhF,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,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AC;AAEjF,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAClF,YAAY,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACjH,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEzG,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrG,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAKhF,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5J,YAAY,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzG,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/engine.js CHANGED
@@ -17,6 +17,14 @@ export { writeSpec } from './specs/writeSpec.js';
17
17
  export { reRenderSpec } from './specs/writeSpec.js';
18
18
  // API-layer crystallizer — observed/replayed requests → *.api-test.spec.ts.
19
19
  export { writeApiSpec } from './specs/writeApiSpec.js';
20
+ // Optimize (F7) — build the improvement brief for the user's own agent, then
21
+ // file its result as a reviewed candidate. No Hover-owned model runs.
22
+ export { buildOptimizeBrief, saveOptimizedCandidate, OptimizeError } from './specs/optimizeSpec.js';
23
+ // LLM-Wiki P3 log — append-only, machine-parseable run history at .hover/log.md.
24
+ export { appendWikiLog, readWikiLog, wikiLogPath } from './specs/wikiLog.js';
25
+ // LLM-Wiki P1 Lint — deterministic health check over .hover/ (map vs specs vs runs).
26
+ export { lintWiki, parseRunStatuses } from './specs/lintWiki.js';
27
+ export { parseBusinessMap } from './specs/businessMap.js';
20
28
  // Page-Object extraction — lift NON-login shared flows into pages/ + fixtures.
21
29
  export { extractPageObjects, detectExtractableFlows } from './specs/extractPageObjects.js';
22
30
  // Creation-verification + self-heal: replay a flow's grounded steps over CDP (no playwright test).
@@ -26,6 +34,8 @@ export { readSidecar } from './specs/sidecar.js';
26
34
  // ── debug-Chrome lifecycle ───────────────────────────────────────────────────
27
35
  export { launchDebugChrome, closeDebugChrome, findChromeBinary } from './playwright/launchChrome.js';
28
36
  // ── business memory (ask → remember loop) ────────────────────────────────────
29
- export { loadMemory, formatMemoryForPrompt, writeFact, memoryDir } from './memory/businessMemory.js';
37
+ // recallMemory = progressive disclosure (full when small, index when large);
38
+ // readFact = the on-demand single-rule fetch behind recall_fact.
39
+ export { loadMemory, formatMemoryForPrompt, formatMemoryIndex, recallMemory, readFact, formatFact, writeFact, memoryDir } from './memory/businessMemory.js';
30
40
  // ── QA intensity (step budget; parked until wired into the workflow) ──────────
31
41
  export { QA_INTENSITY, DEFAULT_QA_INTENSITY, asQaIntensity, qaBudgetDirective } from './qa/intensity.js';
@@ -18,6 +18,26 @@ export declare function loadMemory(devRoot: string): Promise<BusinessFact[]>;
18
18
  /** Format loaded facts as a system-prompt block, or '' when there are none (so
19
19
  * the caller appends nothing). Grouped nothing-fancy: one bullet per fact. */
20
20
  export declare function formatMemoryForPrompt(facts: BusinessFact[]): string;
21
+ /** Above this many chars of formatted-full memory, recall returns the INDEX
22
+ * (title — description per rule) instead of every rule's body, and the agent
23
+ * pulls a specific rule with `recall_fact` on demand — Claude-Code-style
24
+ * progressive disclosure. Below it, inlining everything is cheaper than making
25
+ * the agent round-trip for five rules, so recall stays full. */
26
+ export declare const RECALL_INLINE_BUDGET = 2000;
27
+ /** The INDEX block: one `title — description (type)` line per rule, no bodies.
28
+ * This is the always-cheap tier; a rule's body is fetched by `readFact`. */
29
+ export declare function formatMemoryIndex(facts: BusinessFact[]): string;
30
+ /** Recall memory with progressive disclosure: full bodies when the set is small
31
+ * (≤ RECALL_INLINE_BUDGET chars formatted), the index alone when it's large.
32
+ * '' when there are no facts. This is what `recall_business_knowledge` returns. */
33
+ export declare function recallMemory(devRoot: string): Promise<string>;
34
+ /** Format one fact's FULL text (body verbatim, not whitespace-collapsed) for an
35
+ * on-demand `recall_fact`. */
36
+ export declare function formatFact(fact: BusinessFact): string;
37
+ /** Load ONE fact by name/slug for on-demand recall. Match order: exact slug →
38
+ * slugified-name equality → prefix → substring. Returns null if nothing matches
39
+ * (or the memory dir is empty). Total: never throws. */
40
+ export declare function readFact(devRoot: string, name: string): Promise<BusinessFact | null>;
21
41
  /** Write (or overwrite) a fact file + refresh the MEMORY.md index line. NEVER
22
42
  * throws — returns the path or an error string for the caller to log. Business
23
43
  * RULES only; the caller must never pass secrets / PII / credentials. */
@@ -1 +1 @@
1
- {"version":3,"file":"businessMemory.d.ts","sourceRoot":"","sources":["../../src/memory/businessMemory.ts"],"names":[],"mappings":"AAwBA,wDAAwD;AACxD,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,IAAI,EAAE,eAAe,GAAG,mBAAmB,GAAG,YAAY,GAAG,eAAe,CAAC;IAC7E,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,oDAAoD;AACpD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM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;;oFAEoF;AACpF,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKnE;AAED;+BAC+B;AAC/B,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAErD;AAED;;yDAEyD;AACzD,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAW1F;AAED;;0EAE0E;AAC1E,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAc/C"}
@@ -87,6 +87,53 @@ export function formatMemoryForPrompt(facts) {
87
87
  'ground truth; do NOT re-ask what these already answer):\n' +
88
88
  lines.join('\n'));
89
89
  }
90
+ /** Above this many chars of formatted-full memory, recall returns the INDEX
91
+ * (title — description per rule) instead of every rule's body, and the agent
92
+ * pulls a specific rule with `recall_fact` on demand — Claude-Code-style
93
+ * progressive disclosure. Below it, inlining everything is cheaper than making
94
+ * the agent round-trip for five rules, so recall stays full. */
95
+ export const RECALL_INLINE_BUDGET = 2000;
96
+ /** The INDEX block: one `title — description (type)` line per rule, no bodies.
97
+ * This is the always-cheap tier; a rule's body is fetched by `readFact`. */
98
+ export function formatMemoryIndex(facts) {
99
+ if (!facts.length)
100
+ return '';
101
+ const lines = facts.map((f) => `- ${f.name}${f.description ? ` — ${f.description}` : ''} (${f.type})`);
102
+ return (`KNOWN BUSINESS KNOWLEDGE FOR THIS APP — ${facts.length} rules learned from earlier ` +
103
+ `runs (treat as ground truth; do NOT re-ask what these answer). This is the INDEX; ` +
104
+ `call recall_fact("<name>") to read a rule's full text when it's relevant to what ` +
105
+ `you're testing:\n` +
106
+ lines.join('\n'));
107
+ }
108
+ /** Recall memory with progressive disclosure: full bodies when the set is small
109
+ * (≤ RECALL_INLINE_BUDGET chars formatted), the index alone when it's large.
110
+ * '' when there are no facts. This is what `recall_business_knowledge` returns. */
111
+ export async function recallMemory(devRoot) {
112
+ const facts = await loadMemory(devRoot);
113
+ if (!facts.length)
114
+ return '';
115
+ const full = formatMemoryForPrompt(facts);
116
+ return full.length <= RECALL_INLINE_BUDGET ? full : formatMemoryIndex(facts);
117
+ }
118
+ /** Format one fact's FULL text (body verbatim, not whitespace-collapsed) for an
119
+ * on-demand `recall_fact`. */
120
+ export function formatFact(fact) {
121
+ return `${fact.name}${fact.description ? ` — ${fact.description}` : ''} (${fact.type}):\n${fact.body.trim()}`;
122
+ }
123
+ /** Load ONE fact by name/slug for on-demand recall. Match order: exact slug →
124
+ * slugified-name equality → prefix → substring. Returns null if nothing matches
125
+ * (or the memory dir is empty). Total: never throws. */
126
+ export async function readFact(devRoot, name) {
127
+ const facts = await loadMemory(devRoot);
128
+ if (!facts.length)
129
+ return null;
130
+ const q = slugify(name);
131
+ return (facts.find((f) => f.name === q) ??
132
+ facts.find((f) => slugify(f.name) === q) ??
133
+ facts.find((f) => f.name.startsWith(q) || slugify(f.name).startsWith(q)) ??
134
+ facts.find((f) => f.name.includes(q) || slugify(f.name).includes(q)) ??
135
+ null);
136
+ }
90
137
  /** Write (or overwrite) a fact file + refresh the MEMORY.md index line. NEVER
91
138
  * throws — returns the path or an error string for the caller to log. Business
92
139
  * RULES only; the caller must never pass secrets / PII / credentials. */
@@ -0,0 +1,37 @@
1
+ export type MapNodeKind = 'app' | 'area' | 'line' | 'spec';
2
+ export type CoverageStatus = 'covered' | 'uncovered';
3
+ /** Inter-line relationship kinds recorded in the map's `## Relationships` block
4
+ * (LLM-Wiki P2) — the graph edges that aren't the app→area→line→spec hierarchy. */
5
+ export type RelationKind = 'depends-on' | 'shares-state' | 'navigates-to';
6
+ export interface MapNode {
7
+ id: string;
8
+ label: string;
9
+ kind: MapNodeKind;
10
+ status?: CoverageStatus;
11
+ route?: string;
12
+ spec?: string;
13
+ }
14
+ export interface MapEdge {
15
+ source: string;
16
+ target: string;
17
+ }
18
+ /** A resolved inter-line edge: source/target are `line:` node ids. */
19
+ export interface MapRelation {
20
+ source: string;
21
+ target: string;
22
+ kind: RelationKind;
23
+ }
24
+ export interface BusinessMapGraph {
25
+ app: string;
26
+ nodes: MapNode[];
27
+ edges: MapEdge[];
28
+ /** Inter-line relationships from the `## Relationships` block (may be empty). */
29
+ relations: MapRelation[];
30
+ stats: {
31
+ lines: number;
32
+ covered: number;
33
+ areas: number;
34
+ };
35
+ }
36
+ export declare function parseBusinessMap(md: string, fallbackApp?: string): BusinessMapGraph;
37
+ //# sourceMappingURL=businessMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"businessMap.d.ts","sourceRoot":"","sources":["../../src/specs/businessMap.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAC3D,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,CAAC;AACrD;oFACoF;AACpF,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,cAAc,GAAG,cAAc,CAAC;AAE1E,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AACD,MAAM,WAAW,OAAO;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,YAAY,CAAC;CACpB;AACD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,iFAAiF;IACjF,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1D;AA+BD,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,SAAQ,GAAG,gBAAgB,CAmFlF"}
@@ -0,0 +1,119 @@
1
+ /*
2
+ * Canonical parser for the `.hover/hover-map.md` business map the agent
3
+ * maintains — the overview page of the app's living test wiki. Turns the
4
+ * markdown checklist into a graph model (app → area → business line → spec,
5
+ * with coverage).
6
+ *
7
+ * This is the unit-tested source of truth. The cockpit keeps an in-extension
8
+ * copy (packages/vscode-ext/src/businessMap.ts) on purpose — a read-only view
9
+ * must not depend on the engine — so keep the two in sync if the format changes.
10
+ */
11
+ const RELATION_KINDS = ['depends-on', 'shares-state', 'navigates-to'];
12
+ const RELATION_RE = new RegExp(`^\\s*-\\s+(.+?)\\s+(${RELATION_KINDS.join('|')})\\s+(.+?)\\s*$`);
13
+ function slug(s) {
14
+ return (s
15
+ .toLowerCase()
16
+ .replace(/[^a-z0-9]+/g, '-')
17
+ .replace(/^-+|-+$/g, '') || 'x');
18
+ }
19
+ const SPEC_RE = /\.spec\.tsx?$/;
20
+ function splitItem(rest) {
21
+ const parts = rest
22
+ .split(/\s+[—–-]\s+/)
23
+ .map((p) => p.trim())
24
+ .filter(Boolean);
25
+ const name = parts.shift() ?? rest.trim();
26
+ let route;
27
+ let spec;
28
+ for (const p of parts) {
29
+ if (SPEC_RE.test(p))
30
+ spec = p;
31
+ else if (p.startsWith('/'))
32
+ route = p;
33
+ }
34
+ return { name, route, spec };
35
+ }
36
+ export function parseBusinessMap(md, fallbackApp = 'app') {
37
+ const nodes = [];
38
+ const edges = [];
39
+ const seen = new Set();
40
+ const add = (n) => {
41
+ if (seen.has(n.id))
42
+ return;
43
+ seen.add(n.id);
44
+ nodes.push(n);
45
+ };
46
+ let app = fallbackApp;
47
+ const title = md.match(/^#\s+(.+)$/m);
48
+ if (title) {
49
+ const t = title[1].trim();
50
+ const m = t.match(/business\s*map\s*[—–-]\s*(.+)$/i);
51
+ app = (m ? m[1] : t).trim() || fallbackApp;
52
+ }
53
+ add({ id: 'app', label: app, kind: 'app' });
54
+ let area = null;
55
+ let inRelationships = false;
56
+ let covered = 0;
57
+ let lineCount = 0;
58
+ let areaCount = 0;
59
+ // name-slug → line node id, so the `## Relationships` block can resolve a line
60
+ // by its label regardless of which area it sits under. First-defined wins.
61
+ const lineBySlug = new Map();
62
+ const rawRelations = [];
63
+ for (const raw of md.split('\n')) {
64
+ const line = raw.trimEnd();
65
+ const areaM = line.match(/^##\s+(.+)$/);
66
+ if (areaM) {
67
+ const label = areaM[1].trim();
68
+ // The Relationships block is metadata, not an area — don't node it; its
69
+ // items are edges (parsed below), not business lines.
70
+ if (slug(label) === 'relationships') {
71
+ inRelationships = true;
72
+ area = null;
73
+ continue;
74
+ }
75
+ inRelationships = false;
76
+ const id = `area:${slug(label)}`;
77
+ area = { id };
78
+ add({ id, label, kind: 'area' });
79
+ edges.push({ source: 'app', target: id });
80
+ areaCount++;
81
+ continue;
82
+ }
83
+ if (inRelationships) {
84
+ const relM = line.match(RELATION_RE);
85
+ if (relM)
86
+ rawRelations.push({ source: relM[1].trim(), kind: relM[2], target: relM[3].trim() });
87
+ continue;
88
+ }
89
+ const itemM = line.match(/^\s*-\s*\[([ xX])\]\s+(.+)$/);
90
+ if (itemM) {
91
+ const status = itemM[1].toLowerCase() === 'x' ? 'covered' : 'uncovered';
92
+ const { name, route, spec } = splitItem(itemM[2]);
93
+ const parentId = area?.id ?? 'app';
94
+ const lineId = `line:${slug(area ? area.id.slice(5) : 'top')}/${slug(name)}`;
95
+ add({ id: lineId, label: name, kind: 'line', status, route, spec });
96
+ if (!lineBySlug.has(slug(name)))
97
+ lineBySlug.set(slug(name), lineId);
98
+ edges.push({ source: parentId, target: lineId });
99
+ lineCount++;
100
+ if (status === 'covered')
101
+ covered++;
102
+ if (spec) {
103
+ const specId = `spec:${spec}`;
104
+ add({ id: specId, label: spec, kind: 'spec', spec });
105
+ edges.push({ source: lineId, target: specId });
106
+ }
107
+ }
108
+ }
109
+ // Resolve relationships against the lines now that all are known; an edge whose
110
+ // endpoints don't both name a known line is dropped (a stale/typo'd reference).
111
+ const relations = [];
112
+ for (const r of rawRelations) {
113
+ const source = lineBySlug.get(slug(r.source));
114
+ const target = lineBySlug.get(slug(r.target));
115
+ if (source && target && source !== target)
116
+ relations.push({ source, target, kind: r.kind });
117
+ }
118
+ return { app, nodes, edges, relations, stats: { lines: lineCount, covered, areas: areaCount } };
119
+ }
@@ -0,0 +1,33 @@
1
+ export type LintSeverity = 'error' | 'warn' | 'info';
2
+ export type LintKind = 'deleted-spec' | 'regressed-coverage' | 'orphan-spec';
3
+ export interface LintFinding {
4
+ kind: LintKind;
5
+ severity: LintSeverity;
6
+ /** One-line human-readable finding. */
7
+ message: string;
8
+ /** The business line involved (map label), if any. */
9
+ line?: string;
10
+ /** The spec basename involved, if any. */
11
+ spec?: string;
12
+ /** A suggested next action for the agent (e.g. heal, map, remove the ref). */
13
+ fix?: string;
14
+ }
15
+ export interface LintResult {
16
+ /** No error/warn findings (info-only still counts as ok). */
17
+ ok: boolean;
18
+ hasMap: boolean;
19
+ findings: LintFinding[];
20
+ summary: {
21
+ areas: number;
22
+ lines: number;
23
+ covered: number;
24
+ specs: number;
25
+ };
26
+ }
27
+ type RunStatus = 'pass' | 'fail' | 'flaky';
28
+ /** Parse a Playwright JSON report into { specBasename → worst status }. Mirrors
29
+ * the cockpit's parser; an unexpected shape yields no entries. */
30
+ export declare function parseRunStatuses(json: unknown): Record<string, RunStatus>;
31
+ export declare function lintWiki(devRoot: string): Promise<LintResult>;
32
+ export {};
33
+ //# sourceMappingURL=lintWiki.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lintWiki.d.ts","sourceRoot":"","sources":["../../src/specs/lintWiki.ts"],"names":[],"mappings":"AAoBA,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AACrD,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,oBAAoB,GAAG,aAAa,CAAC;AAE7E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,YAAY,CAAC;IACvB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,UAAU;IACzB,6DAA6D;IAC7D,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3E;AAED,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAG3C;mEACmE;AACnE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAmBzE;AAgDD,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAyEnE"}
@@ -0,0 +1,163 @@
1
+ /*
2
+ * LLM-Wiki P1 — Lint: a deterministic health check over `.hover/` (the app's
3
+ * living test wiki). It cross-checks the business map against the real spec
4
+ * files and the run ledger and reports drift:
5
+ *
6
+ * - deleted-spec a covered line points at a *.spec.ts that no longer exists
7
+ * - regressed-coverage a covered line's spec last ran fail/flaky (→ candidate for heal)
8
+ * - orphan-spec a *.spec.ts exists but no line references it (a gap in the map)
9
+ *
10
+ * These are the CHEAP, mechanical checks — no LLM, no network. The LLM-judged
11
+ * half (contradictory memory rules, routes in code missing from the map) is the
12
+ * agent's job, driven by the `/mcp__hover__lint` prompt on top of this result.
13
+ *
14
+ * Pure-ish: reads the FS, never writes; a missing map / bad JSON degrades to a
15
+ * partial (or empty) result, never throws.
16
+ */
17
+ import { readFile, readdir } from 'node:fs/promises';
18
+ import { join } from 'node:path';
19
+ import { parseBusinessMap } from './businessMap.js';
20
+ const RUN_RANK = { pass: 0, flaky: 1, fail: 2 };
21
+ /** Parse a Playwright JSON report into { specBasename → worst status }. Mirrors
22
+ * the cockpit's parser; an unexpected shape yields no entries. */
23
+ export function parseRunStatuses(json) {
24
+ const out = {};
25
+ const worse = (a, b) => !a ? b : RUN_RANK[b] > RUN_RANK[a] ? b : a;
26
+ const visit = (suite, inherited) => {
27
+ const file = suite.file ?? inherited;
28
+ for (const raw of suite.specs ?? []) {
29
+ const spec = raw;
30
+ const key = (file ?? spec.file ?? 'unknown').split(/[\\/]/).pop() ?? 'unknown';
31
+ let status = spec.ok ? 'pass' : 'fail';
32
+ if (spec.ok && (spec.tests ?? []).some((t) => t.status === 'flaky'))
33
+ status = 'flaky';
34
+ out[key] = worse(out[key], status);
35
+ }
36
+ for (const child of suite.suites ?? [])
37
+ visit(child, file);
38
+ };
39
+ if (json && typeof json === 'object') {
40
+ for (const s of json.suites ?? [])
41
+ visit(s);
42
+ }
43
+ return out;
44
+ }
45
+ /** Recursively collect *.spec.ts basenames under __vibe_tests__/. */
46
+ async function collectSpecs(dir) {
47
+ const out = [];
48
+ const walk = async (d) => {
49
+ let entries;
50
+ try {
51
+ entries = await readdir(d, { withFileTypes: true });
52
+ }
53
+ catch {
54
+ return; // no __vibe_tests__ yet
55
+ }
56
+ for (const e of entries) {
57
+ const p = join(d, e.name);
58
+ if (e.isDirectory()) {
59
+ if (e.name === 'pages' || e.name === '.hover' || e.name === 'node_modules')
60
+ continue;
61
+ await walk(p);
62
+ }
63
+ else if (/\.spec\.tsx?$/.test(e.name)) {
64
+ out.push(e.name);
65
+ }
66
+ }
67
+ };
68
+ await walk(dir);
69
+ return out;
70
+ }
71
+ /** Latest run status per spec basename, merged newest-wins across `.hover/runs/*.json`
72
+ * (filename is the ISO stamp → lexical sort is chronological). */
73
+ async function latestRunStatuses(runsDir) {
74
+ let files;
75
+ try {
76
+ files = (await readdir(runsDir)).filter((f) => f.endsWith('.json')).sort();
77
+ }
78
+ catch {
79
+ return {};
80
+ }
81
+ const merged = {};
82
+ for (const f of files) {
83
+ // later files overwrite earlier → the latest run wins per spec
84
+ try {
85
+ const json = JSON.parse(await readFile(join(runsDir, f), 'utf-8'));
86
+ Object.assign(merged, parseRunStatuses(json));
87
+ }
88
+ catch {
89
+ /* skip a bad run file */
90
+ }
91
+ }
92
+ return merged;
93
+ }
94
+ export async function lintWiki(devRoot) {
95
+ const hoverDir = join(devRoot, '.hover');
96
+ const vibeDir = join(devRoot, '__vibe_tests__');
97
+ let md = '';
98
+ try {
99
+ md = await readFile(join(hoverDir, 'hover-map.md'), 'utf-8');
100
+ }
101
+ catch {
102
+ /* no map yet */
103
+ }
104
+ const hasMap = md.trim().length > 0;
105
+ const graph = parseBusinessMap(md);
106
+ const specFiles = await collectSpecs(vibeDir);
107
+ const specSet = new Set(specFiles);
108
+ const runs = await latestRunStatuses(join(hoverDir, 'runs'));
109
+ const findings = [];
110
+ const lines = graph.nodes.filter((n) => n.kind === 'line');
111
+ const referenced = new Set();
112
+ for (const line of lines) {
113
+ if (line.spec) {
114
+ referenced.add(line.spec);
115
+ // deleted-spec: a line points at a spec file that isn't on disk.
116
+ if (!specSet.has(line.spec)) {
117
+ findings.push({
118
+ kind: 'deleted-spec',
119
+ severity: 'error',
120
+ line: line.label,
121
+ spec: line.spec,
122
+ message: `"${line.label}" points at ${line.spec}, which no longer exists in __vibe_tests__/.`,
123
+ fix: `Re-crystallize the flow, or drop the stale spec reference from .hover/hover-map.md.`,
124
+ });
125
+ continue; // no point checking its run status
126
+ }
127
+ // regressed-coverage: a covered line whose spec last ran fail/flaky.
128
+ const run = runs[line.spec];
129
+ if (line.status === 'covered' && (run === 'fail' || run === 'flaky')) {
130
+ findings.push({
131
+ kind: 'regressed-coverage',
132
+ severity: 'warn',
133
+ line: line.label,
134
+ spec: line.spec,
135
+ message: `"${line.label}" is marked covered but ${line.spec} last ran ${run}.`,
136
+ fix: `Heal it: /mcp__hover__heal ${line.spec.replace(/\.spec\.tsx?$/, '')}`,
137
+ });
138
+ }
139
+ }
140
+ }
141
+ // orphan-spec: a UI spec on disk that no business line references (a map gap).
142
+ // API specs (*.api-test.spec.ts) are siblings of a line, not lines → skip.
143
+ for (const spec of specFiles) {
144
+ if (spec.endsWith('.api-test.spec.ts'))
145
+ continue;
146
+ if (!referenced.has(spec)) {
147
+ findings.push({
148
+ kind: 'orphan-spec',
149
+ severity: 'info',
150
+ spec,
151
+ message: `${spec} exists but no line in the business map references it.`,
152
+ fix: `Add its business line to .hover/hover-map.md (mark it [x] with the spec).`,
153
+ });
154
+ }
155
+ }
156
+ const ok = !findings.some((f) => f.severity === 'error' || f.severity === 'warn');
157
+ return {
158
+ ok,
159
+ hasMap,
160
+ findings,
161
+ summary: { areas: graph.stats.areas, lines: graph.stats.lines, covered: graph.stats.covered, specs: specFiles.length },
162
+ };
163
+ }
@@ -29,12 +29,37 @@ export interface OptimizeResult {
29
29
  original: string;
30
30
  }
31
31
  export declare function optimizeSpec(devRoot: string, slug: string, runCodegen: RunCodegen): Promise<OptimizeResult>;
32
+ /**
33
+ * MCP-first optimize (F7) without a Hover-owned model: build the improvement
34
+ * brief for a spec, hand it to the USER's own agent (which IS the intelligence),
35
+ * and let it write the improved file back through `saveOptimizedCandidate`.
36
+ *
37
+ * Returns the prompt the agent works from (the same improvement rules the
38
+ * legacy in-engine `optimizeSpec` used) + the original spec, so a caller can
39
+ * diff. Throws OptimizeError if the spec doesn't exist. No LLM runs here.
40
+ */
41
+ export declare function buildOptimizeBrief(devRoot: string, slug: string): Promise<{
42
+ prompt: string;
43
+ original: string;
44
+ }>;
45
+ /**
46
+ * Deterministic finishing + write for an optimized spec the agent produced:
47
+ * validate the LLM's code against the same guardrails the deterministic path
48
+ * keeps, soft-batch the trailing independent assertions, and write it as a
49
+ * CANDIDATE (`.hover/cache/optimized/<slug>.spec.ts.draft`) — never the original.
50
+ * Throws OptimizeError if the code fails validation (the caller surfaces it so
51
+ * the agent can retry). No LLM runs here.
52
+ */
53
+ export declare function saveOptimizedCandidate(devRoot: string, slug: string, llmCode: string): Promise<{
54
+ candidatePath: string;
55
+ code: string;
56
+ }>;
32
57
  /**
33
58
  * Build the codegen prompt: the current spec + the observed session, plus the
34
59
  * same rules the deterministic path enforces (semantic selectors, no XPath, no
35
60
  * waitForTimeout, keep the test.step shape).
36
61
  */
37
- export declare function buildOptimizePrompt(draft: string, sidecar: SpecSidecar | null, seeds?: SeedRule[], suite?: SuiteContext): string;
62
+ export declare function buildOptimizePrompt(draft: string, sidecar: SpecSidecar | null, seeds?: SeedRule[], suite?: SuiteContext, outputInstruction?: string): string;
38
63
  /** Strip a ```ts fence if the model wrapped its output in one. */
39
64
  export declare function extractCode(raw: string): string;
40
65
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"optimizeSpec.d.ts","sourceRoot":"","sources":["../../src/specs/optimizeSpec.ts"],"names":[],"mappings":"AAeA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAgC,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGzE,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED,wEAAwE;AACxE,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK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EAAO,EACtB,KAAK,GAAE,YAA4B,EACnC,iBAAiB,SAA+F,GAC/G,MAAM,CAiFR;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAWhF"}
@@ -49,6 +49,21 @@ export async function gatherSuiteContext(devRoot) {
49
49
  return { conventions, pages };
50
50
  }
51
51
  export async function optimizeSpec(devRoot, slug, runCodegen) {
52
+ const { prompt, original } = await buildOptimizeBrief(devRoot, slug);
53
+ const raw = await runCodegen(prompt);
54
+ const { candidatePath, code } = await saveOptimizedCandidate(devRoot, slug, extractCode(raw));
55
+ return { candidatePath, code, original };
56
+ }
57
+ /**
58
+ * MCP-first optimize (F7) without a Hover-owned model: build the improvement
59
+ * brief for a spec, hand it to the USER's own agent (which IS the intelligence),
60
+ * and let it write the improved file back through `saveOptimizedCandidate`.
61
+ *
62
+ * Returns the prompt the agent works from (the same improvement rules the
63
+ * legacy in-engine `optimizeSpec` used) + the original spec, so a caller can
64
+ * diff. Throws OptimizeError if the spec doesn't exist. No LLM runs here.
65
+ */
66
+ export async function buildOptimizeBrief(devRoot, slug) {
52
67
  const specPath = join(devRoot, '__vibe_tests__', `${slug}.spec.ts`);
53
68
  let draft;
54
69
  try {
@@ -64,15 +79,31 @@ export async function optimizeSpec(devRoot, slug, runCodegen) {
64
79
  .map(s => s.tool));
65
80
  const seeds = relevantSeeds(BUILTIN_SEEDS, specTools);
66
81
  const suite = await gatherSuiteContext(devRoot);
67
- const raw = await runCodegen(buildOptimizePrompt(draft, sidecar, seeds, suite));
68
- const llmCode = extractCode(raw);
82
+ // The agent path ends by CALLING a tool (not by emitting raw text), so swap
83
+ // the legacy "output ONLY the file" footer for a save_optimized_spec directive.
84
+ const outputInstruction = `When done, call \`save_optimized_spec\` with slug "${slug}" and the COMPLETE improved ` +
85
+ `.ts file as \`code\`. Hover validates it (semantic selectors, no waitForTimeout/XPath), ` +
86
+ `soft-batches trailing assertions, and files it as a REVIEW CANDIDATE at ` +
87
+ `.hover/cache/optimized/${slug}.spec.ts.draft — it does NOT touch your spec. If it comes ` +
88
+ `back with a ✗ (a rejected check), fix that and call it again. Then tell the user the ` +
89
+ `candidate path so they can diff it against __vibe_tests__/${slug}.spec.ts and promote it.`;
90
+ return { prompt: buildOptimizePrompt(draft, sidecar, seeds, suite, outputInstruction), original: draft };
91
+ }
92
+ /**
93
+ * Deterministic finishing + write for an optimized spec the agent produced:
94
+ * validate the LLM's code against the same guardrails the deterministic path
95
+ * keeps, soft-batch the trailing independent assertions, and write it as a
96
+ * CANDIDATE (`.hover/cache/optimized/<slug>.spec.ts.draft`) — never the original.
97
+ * Throws OptimizeError if the code fails validation (the caller surfaces it so
98
+ * the agent can retry). No LLM runs here.
99
+ */
100
+ export async function saveOptimizedCandidate(devRoot, slug, llmCode) {
69
101
  const check = validateSpecCode(llmCode);
70
102
  if (!check.ok) {
71
103
  throw new OptimizeError(`optimization rejected — ${check.errors.join('; ')}`);
72
104
  }
73
- // Deterministic finishing step: the LLM decided WHAT to assert; soft-batch
74
- // applies the safe mechanical rewrite (trailing run of independent assertions
75
- // → expect.soft) surgically on its output. See softBatch.ts for the guard.
105
+ // Soft-batch applies the safe mechanical rewrite (a trailing run of
106
+ // independent assertions expect.soft) surgically. See softBatch.ts.
76
107
  const code = softBatch(llmCode).code;
77
108
  // Candidates are disposable derived artifacts → `.hover/cache/` (always
78
109
  // gitignored). Losing one costs a re-run of the optimization, nothing more.
@@ -82,14 +113,14 @@ export async function optimizeSpec(devRoot, slug, runCodegen) {
82
113
  // candidate before a human reviews it.
83
114
  const candidatePath = join(dir, `${slug}.spec.ts.draft`);
84
115
  await writeFile(candidatePath, code.endsWith('\n') ? code : `${code}\n`, 'utf-8');
85
- return { candidatePath, code, original: draft };
116
+ return { candidatePath, code };
86
117
  }
87
118
  /**
88
119
  * Build the codegen prompt: the current spec + the observed session, plus the
89
120
  * same rules the deterministic path enforces (semantic selectors, no XPath, no
90
121
  * waitForTimeout, keep the test.step shape).
91
122
  */
92
- export function buildOptimizePrompt(draft, sidecar, seeds = [], suite = { pages: [] }) {
123
+ export function buildOptimizePrompt(draft, sidecar, seeds = [], suite = { pages: [] }, outputInstruction = 'Output ONLY the complete .ts file contents — no markdown fences, no prose, no explanation.') {
93
124
  const done = sidecar?.steps.find(s => s.kind === 'done');
94
125
  const stepsJson = sidecar
95
126
  ? JSON.stringify(sidecar.steps.filter(s => s.kind === 'step'), null, 2)
@@ -138,8 +169,7 @@ export function buildOptimizePrompt(draft, sidecar, seeds = [], suite = { pages:
138
169
  ` human can find it and so the test breaks loudly once the app is fixed.`,
139
170
  ` Never silently lock buggy behavior into a normal-looking assertion.`,
140
171
  ``,
141
- `Output ONLY the complete .ts file contents — no markdown fences, no prose,`,
142
- `no explanation.`,
172
+ outputInstruction,
143
173
  ``,
144
174
  `=== CURRENT SPEC ===`,
145
175
  draft,
@@ -0,0 +1,14 @@
1
+ export type WikiLogKind = 'crystallize' | 'api' | 'extract' | 'heal' | 'note';
2
+ export interface WikiLogEntry {
3
+ /** ISO-8601 timestamp. */
4
+ iso: string;
5
+ kind: string;
6
+ summary: string;
7
+ }
8
+ export declare function wikiLogPath(devRoot: string): string;
9
+ /** Append one event line. Best-effort — never throws. */
10
+ export declare function appendWikiLog(devRoot: string, kind: WikiLogKind, summary: string): Promise<void>;
11
+ /** Read the log's most recent entries (oldest→newest), parsed. Total: a missing
12
+ * or malformed file yields []. */
13
+ export declare function readWikiLog(devRoot: string, limit?: number): Promise<WikiLogEntry[]>;
14
+ //# sourceMappingURL=wikiLog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wikiLog.d.ts","sourceRoot":"","sources":["../../src/specs/wikiLog.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAE9E,MAAM,WAAW,YAAY;IAC3B,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAOD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,yDAAyD;AACzD,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtG;AAED;mCACmC;AACnC,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAYvF"}
@@ -0,0 +1,58 @@
1
+ /*
2
+ * LLM-Wiki P3 — `.hover/log.md`: an append-only, machine-parseable run history
3
+ * for the app's test wiki. One event per line:
4
+ *
5
+ * - <ISO timestamp> · <kind> · <summary>
6
+ *
7
+ * Hover writes it deterministically as it MUTATES the wiki (a spec crystallized,
8
+ * an API spec locked, Page Objects extracted) — no dependence on the agent
9
+ * remembering to log, and no prompt churn. It powers an auditable timeline (and
10
+ * a future cockpit history view). Best-effort by contract: a log failure must
11
+ * NEVER break a crystallize / extract — same rule as the memory + run ledger.
12
+ */
13
+ import { appendFile, mkdir, readFile } from 'node:fs/promises';
14
+ import { join } from 'node:path';
15
+ import { hoverDir } from './sidecar.js';
16
+ const HEADER = '# Hover log\n\n' +
17
+ "Append-only run history for this app's test wiki. One event per line: " +
18
+ '`- <ISO> · <kind> · <summary>`.\n\n';
19
+ export function wikiLogPath(devRoot) {
20
+ return join(hoverDir(devRoot), 'log.md');
21
+ }
22
+ /** Append one event line. Best-effort — never throws. */
23
+ export async function appendWikiLog(devRoot, kind, summary) {
24
+ try {
25
+ await mkdir(hoverDir(devRoot), { recursive: true });
26
+ const path = wikiLogPath(devRoot);
27
+ let existing = '';
28
+ try {
29
+ existing = await readFile(path, 'utf-8');
30
+ }
31
+ catch {
32
+ /* new file → write the header first */
33
+ }
34
+ const iso = new Date().toISOString();
35
+ const line = `- ${iso} · ${kind} · ${summary.replace(/\s+/g, ' ').trim()}\n`;
36
+ await appendFile(path, `${existing ? '' : HEADER}${line}`, 'utf-8');
37
+ }
38
+ catch {
39
+ /* best-effort: a wiki-log failure must not break the write that triggered it */
40
+ }
41
+ }
42
+ /** Read the log's most recent entries (oldest→newest), parsed. Total: a missing
43
+ * or malformed file yields []. */
44
+ export async function readWikiLog(devRoot, limit = 200) {
45
+ try {
46
+ const raw = await readFile(wikiLogPath(devRoot), 'utf-8');
47
+ const entries = [];
48
+ for (const l of raw.split('\n')) {
49
+ const m = l.match(/^-\s+(\S+)\s+·\s+(\w+)\s+·\s+(.+)$/);
50
+ if (m)
51
+ entries.push({ iso: m[1], kind: m[2], summary: m[3].trim() });
52
+ }
53
+ return entries.slice(-limit);
54
+ }
55
+ catch {
56
+ return [];
57
+ }
58
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hover-dev/core",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "Hover's local Node service: agent invocation, Playwright CDP preflight, WebSocket bridge.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Hyperyond",