@hover-dev/core 0.22.0 → 0.23.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 +7 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +9 -1
- package/dist/memory/businessMemory.d.ts +20 -0
- package/dist/memory/businessMemory.d.ts.map +1 -1
- package/dist/memory/businessMemory.js +47 -0
- package/dist/specs/businessMap.d.ts +26 -0
- package/dist/specs/businessMap.d.ts.map +1 -0
- package/dist/specs/businessMap.js +87 -0
- package/dist/specs/lintWiki.d.ts +33 -0
- package/dist/specs/lintWiki.d.ts.map +1 -0
- package/dist/specs/lintWiki.js +163 -0
- package/dist/specs/optimizeSpec.d.ts +26 -1
- package/dist/specs/optimizeSpec.d.ts.map +1 -1
- package/dist/specs/optimizeSpec.js +39 -9
- package/package.json +1 -1
package/dist/engine.d.ts
CHANGED
|
@@ -18,6 +18,12 @@ 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 { lintWiki, parseRunStatuses } from './specs/lintWiki.js';
|
|
24
|
+
export type { LintResult, LintFinding, LintKind, LintSeverity } from './specs/lintWiki.js';
|
|
25
|
+
export { parseBusinessMap } from './specs/businessMap.js';
|
|
26
|
+
export type { BusinessMapGraph, MapNode, MapEdge } from './specs/businessMap.js';
|
|
21
27
|
export { extractPageObjects, detectExtractableFlows } from './specs/extractPageObjects.js';
|
|
22
28
|
export type { ExtractResult, ExtractedPage } from './specs/extractPageObjects.js';
|
|
23
29
|
export type { SharedFlow } from './specs/detectSharedFlows.js';
|
|
@@ -27,7 +33,7 @@ export { readSidecar } from './specs/sidecar.js';
|
|
|
27
33
|
export type { SpecSidecar } from './specs/sidecar.js';
|
|
28
34
|
export { launchDebugChrome, closeDebugChrome, findChromeBinary } from './playwright/launchChrome.js';
|
|
29
35
|
export type { LaunchOptions, LaunchResult } from './playwright/launchChrome.js';
|
|
30
|
-
export { loadMemory, formatMemoryForPrompt, writeFact, memoryDir } from './memory/businessMemory.js';
|
|
36
|
+
export { loadMemory, formatMemoryForPrompt, formatMemoryIndex, recallMemory, readFact, formatFact, writeFact, memoryDir } from './memory/businessMemory.js';
|
|
31
37
|
export type { BusinessFact } from './memory/businessMemory.js';
|
|
32
38
|
export { QA_INTENSITY, DEFAULT_QA_INTENSITY, asQaIntensity, qaBudgetDirective } from './qa/intensity.js';
|
|
33
39
|
export type { QaIntensity, QaIntensitySpec } from './qa/intensity.js';
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACj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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,12 @@ 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 P1 Lint — deterministic health check over .hover/ (map vs specs vs runs).
|
|
24
|
+
export { lintWiki, parseRunStatuses } from './specs/lintWiki.js';
|
|
25
|
+
export { parseBusinessMap } from './specs/businessMap.js';
|
|
20
26
|
// Page-Object extraction — lift NON-login shared flows into pages/ + fixtures.
|
|
21
27
|
export { extractPageObjects, detectExtractableFlows } from './specs/extractPageObjects.js';
|
|
22
28
|
// Creation-verification + self-heal: replay a flow's grounded steps over CDP (no playwright test).
|
|
@@ -26,6 +32,8 @@ export { readSidecar } from './specs/sidecar.js';
|
|
|
26
32
|
// ── debug-Chrome lifecycle ───────────────────────────────────────────────────
|
|
27
33
|
export { launchDebugChrome, closeDebugChrome, findChromeBinary } from './playwright/launchChrome.js';
|
|
28
34
|
// ── business memory (ask → remember loop) ────────────────────────────────────
|
|
29
|
-
|
|
35
|
+
// recallMemory = progressive disclosure (full when small, index when large);
|
|
36
|
+
// readFact = the on-demand single-rule fetch behind recall_fact.
|
|
37
|
+
export { loadMemory, formatMemoryForPrompt, formatMemoryIndex, recallMemory, readFact, formatFact, writeFact, memoryDir } from './memory/businessMemory.js';
|
|
30
38
|
// ── QA intensity (step budget; parked until wired into the workflow) ──────────
|
|
31
39
|
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,GAAG,MAAM,CAMzC;AAsBD;6EAC6E;AAC7E,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAkBzE;AAED;+EAC+E;AAC/E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAQnE;AAED;;0EAE0E;AAC1E,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,YAAY,GACjB,OA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W1F;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,26 @@
|
|
|
1
|
+
export type MapNodeKind = 'app' | 'area' | 'line' | 'spec';
|
|
2
|
+
export type CoverageStatus = 'covered' | 'uncovered';
|
|
3
|
+
export interface MapNode {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
kind: MapNodeKind;
|
|
7
|
+
status?: CoverageStatus;
|
|
8
|
+
route?: string;
|
|
9
|
+
spec?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface MapEdge {
|
|
12
|
+
source: string;
|
|
13
|
+
target: string;
|
|
14
|
+
}
|
|
15
|
+
export interface BusinessMapGraph {
|
|
16
|
+
app: string;
|
|
17
|
+
nodes: MapNode[];
|
|
18
|
+
edges: MapEdge[];
|
|
19
|
+
stats: {
|
|
20
|
+
lines: number;
|
|
21
|
+
covered: number;
|
|
22
|
+
areas: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function parseBusinessMap(md: string, fallbackApp?: string): BusinessMapGraph;
|
|
26
|
+
//# 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;AAErD,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,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1D;AA4BD,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,SAAQ,GAAG,gBAAgB,CAuDlF"}
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
function slug(s) {
|
|
12
|
+
return (s
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
15
|
+
.replace(/^-+|-+$/g, '') || 'x');
|
|
16
|
+
}
|
|
17
|
+
const SPEC_RE = /\.spec\.tsx?$/;
|
|
18
|
+
function splitItem(rest) {
|
|
19
|
+
const parts = rest
|
|
20
|
+
.split(/\s+[—–-]\s+/)
|
|
21
|
+
.map((p) => p.trim())
|
|
22
|
+
.filter(Boolean);
|
|
23
|
+
const name = parts.shift() ?? rest.trim();
|
|
24
|
+
let route;
|
|
25
|
+
let spec;
|
|
26
|
+
for (const p of parts) {
|
|
27
|
+
if (SPEC_RE.test(p))
|
|
28
|
+
spec = p;
|
|
29
|
+
else if (p.startsWith('/'))
|
|
30
|
+
route = p;
|
|
31
|
+
}
|
|
32
|
+
return { name, route, spec };
|
|
33
|
+
}
|
|
34
|
+
export function parseBusinessMap(md, fallbackApp = 'app') {
|
|
35
|
+
const nodes = [];
|
|
36
|
+
const edges = [];
|
|
37
|
+
const seen = new Set();
|
|
38
|
+
const add = (n) => {
|
|
39
|
+
if (seen.has(n.id))
|
|
40
|
+
return;
|
|
41
|
+
seen.add(n.id);
|
|
42
|
+
nodes.push(n);
|
|
43
|
+
};
|
|
44
|
+
let app = fallbackApp;
|
|
45
|
+
const title = md.match(/^#\s+(.+)$/m);
|
|
46
|
+
if (title) {
|
|
47
|
+
const t = title[1].trim();
|
|
48
|
+
const m = t.match(/business\s*map\s*[—–-]\s*(.+)$/i);
|
|
49
|
+
app = (m ? m[1] : t).trim() || fallbackApp;
|
|
50
|
+
}
|
|
51
|
+
add({ id: 'app', label: app, kind: 'app' });
|
|
52
|
+
let area = null;
|
|
53
|
+
let covered = 0;
|
|
54
|
+
let lineCount = 0;
|
|
55
|
+
let areaCount = 0;
|
|
56
|
+
for (const raw of md.split('\n')) {
|
|
57
|
+
const line = raw.trimEnd();
|
|
58
|
+
const areaM = line.match(/^##\s+(.+)$/);
|
|
59
|
+
if (areaM) {
|
|
60
|
+
const label = areaM[1].trim();
|
|
61
|
+
const id = `area:${slug(label)}`;
|
|
62
|
+
area = { id };
|
|
63
|
+
add({ id, label, kind: 'area' });
|
|
64
|
+
edges.push({ source: 'app', target: id });
|
|
65
|
+
areaCount++;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const itemM = line.match(/^\s*-\s*\[([ xX])\]\s+(.+)$/);
|
|
69
|
+
if (itemM) {
|
|
70
|
+
const status = itemM[1].toLowerCase() === 'x' ? 'covered' : 'uncovered';
|
|
71
|
+
const { name, route, spec } = splitItem(itemM[2]);
|
|
72
|
+
const parentId = area?.id ?? 'app';
|
|
73
|
+
const lineId = `line:${slug(area ? area.id.slice(5) : 'top')}/${slug(name)}`;
|
|
74
|
+
add({ id: lineId, label: name, kind: 'line', status, route, spec });
|
|
75
|
+
edges.push({ source: parentId, target: lineId });
|
|
76
|
+
lineCount++;
|
|
77
|
+
if (status === 'covered')
|
|
78
|
+
covered++;
|
|
79
|
+
if (spec) {
|
|
80
|
+
const specId = `spec:${spec}`;
|
|
81
|
+
add({ id: specId, label: spec, kind: 'spec', spec });
|
|
82
|
+
edges.push({ source: lineId, target: specId });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { app, nodes, edges, stats: { lines: lineCount, covered, areas: areaCount } };
|
|
87
|
+
}
|
|
@@ -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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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
|
-
|
|
68
|
-
|
|
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
|
-
//
|
|
74
|
-
//
|
|
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
|
|
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
|
-
|
|
142
|
-
`no explanation.`,
|
|
172
|
+
outputInstruction,
|
|
143
173
|
``,
|
|
144
174
|
`=== CURRENT SPEC ===`,
|
|
145
175
|
draft,
|