@v11g/agents-rock 1.0.4 → 1.0.6
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/README.md +1 -1
- package/package.json +1 -1
- package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
- package/plugins/solution-architect/skills/estimate/README.md +8 -5
- package/plugins/solution-architect/skills/estimate/SKILL.md +13 -7
- package/plugins/solution-architect/skills/estimate/assets/estimate-template-agentic.html +142 -376
- package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +619 -601
- package/plugins/solution-architect/skills/estimate/assets/scores-review-template.html +363 -0
- package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +5 -9
- package/plugins/solution-architect/skills/estimate/references/interview.md +132 -12
- package/plugins/solution-architect/skills/estimate/references/scoring-guide.md +23 -0
- package/plugins/solution-architect/skills/estimate/references/techniques.md +9 -2
- package/plugins/solution-architect/skills/estimate/references/writing.md +28 -5
- package/plugins/solution-architect/skills/estimate/scripts/lib/agentic-checks.mjs +1 -1
- package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +4 -30
- package/plugins/solution-architect/skills/estimate/scripts/lib/estimate-math.mjs +14 -10
- package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +6 -8
- package/plugins/solution-architect/skills/estimate/scripts/lib/md-tables.mjs +31 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +14 -3
- package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +5 -4
- package/plugins/solution-architect/skills/estimate/scripts/lib/scenario-schema.mjs +39 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +4 -14
- package/plugins/solution-architect/skills/estimate/scripts/lib/score-csv.mjs +58 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/score-diff.mjs +30 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/score-html.mjs +17 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/scoring-checks.mjs +24 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/scoring-schema.mjs +48 -0
- package/plugins/solution-architect/skills/estimate/scripts/lib/scoring.mjs +45 -0
- package/plugins/solution-architect/skills/estimate/scripts/render.mjs +14 -13
- package/plugins/solution-architect/skills/estimate/scripts/score-review.mjs +59 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +403 -316
- package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +25 -1
- package/plugins/solution-architect/skills/estimate/scripts/test/estimate-math.test.mjs +29 -10
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-inputs.json +2 -2
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/booking-inputs.json +21 -3
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-fail.md +1 -1
- package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-pass.md +4 -4
- package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +64 -6
- package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +96 -13
- package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +105 -4
- package/plugins/solution-architect/skills/estimate/scripts/test/score-review.test.mjs +187 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/scoring.test.mjs +49 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/url-state.test.mjs +198 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +38 -0
- package/plugins/solution-architect/skills/estimate/scripts/test/xlsx-export.test.mjs +114 -28
- package/plugins/solution-architect/skills/new-lead/scripts/lib/map-nodes.mjs +1 -1
- package/plugins/solution-architect/skills/proposal/scripts/test/checks-client.test.mjs +2 -2
- package/plugins/solution-architect/skills/proposal/scripts/test/figures.test.mjs +1 -1
|
@@ -14,7 +14,25 @@ top-level `project`, `technique`, `depth`, `calibration`, `overheadPct`,
|
|
|
14
14
|
`verificationPct`, `exposeRatesToClient`, `features` (each with `id`, `name`,
|
|
15
15
|
`provenance`, `tasks`), `risks`, `assumptions`, `scenarios`, and
|
|
16
16
|
`recommendedScenario`. Every task carries `id`, `name`, `category`, `o`,
|
|
17
|
-
`m`, `p`, `confidence`, `assumptions`, `provenance`.
|
|
17
|
+
`m`, `p`, `confidence`, `assumptions`, `provenance`.
|
|
18
|
+
|
|
19
|
+
Add top-level `deliveryMode` — `"agentic"` or `"traditional"` — on every
|
|
20
|
+
estimate you write, even though the field is optional and the booking fixture
|
|
21
|
+
omits it. The interview defaults to agentic (`interview.md` §2b) while an
|
|
22
|
+
absent field still reads as traditional, so leaving it out would record the
|
|
23
|
+
opposite of what was agreed. The fixture keeps its silence on purpose: it is
|
|
24
|
+
the traditional path's regression guard.
|
|
25
|
+
|
|
26
|
+
At `STANDARD`/`DEEP` every feature also carries `scores` — one entry per
|
|
27
|
+
factor `tech`, `size`, `deps`, `unc`, `risk`, each `{ "n": 1–5, "anchor":
|
|
28
|
+
"<the scoring-guide.md sentence for that factor and score, verbatim>",
|
|
29
|
+
"cite": "<the evidence it rests on>" }` — a `scoreNote` (one plain sentence
|
|
30
|
+
for a non-technical reader: no file names, factor names or `§`) and a
|
|
31
|
+
`scoreProvenance` of `stated` or `proposed`. `schema.mjs` checks the anchor
|
|
32
|
+
against the guide byte for byte. At `QUICK` these fields must be absent.
|
|
33
|
+
|
|
34
|
+
Optional top-level `recommendedReason` (non-empty string) says why the
|
|
35
|
+
recommended scenario wins when several are compared. `schema.mjs` is the
|
|
18
36
|
enforced half of this contract (`checkInputs`) — this doc is the readable
|
|
19
37
|
half; if the two ever disagree, the code wins.
|
|
20
38
|
|
|
@@ -53,7 +71,7 @@ sections, in this order:
|
|
|
53
71
|
| --- | --- | --- | --- |
|
|
54
72
|
| <feature name> | S/M/L | <low>–<high> | stated|proposed |
|
|
55
73
|
|
|
56
|
-
Recommended delivery: <team +
|
|
74
|
+
Recommended delivery: <team + AI-assisted summary> — see detail.
|
|
57
75
|
|
|
58
76
|
| Line | Hours |
|
|
59
77
|
| --- | --- |
|
|
@@ -93,9 +111,9 @@ Technique: <technique name> — <one line on why>.
|
|
|
93
111
|
|
|
94
112
|
### Scenario comparison
|
|
95
113
|
|
|
96
|
-
| Scenario | Team |
|
|
114
|
+
| Scenario | Team | AI-assisted | Months | Cost | Notes |
|
|
97
115
|
| --- | --- | --- | --- | --- | --- |
|
|
98
|
-
| <scenario id> | <team summary> |
|
|
116
|
+
| <scenario id> | <team summary> | yes|no | <months> | <cost> | <"recommended" or "—"> |
|
|
99
117
|
|
|
100
118
|
### Calibration
|
|
101
119
|
|
|
@@ -118,7 +136,7 @@ Structure:
|
|
|
118
136
|
4. Summary must contain a line item matching `/buffer/i` (the buffer table
|
|
119
137
|
row above).
|
|
120
138
|
5. Estimation detail must contain a table with a `Scenario` column and at
|
|
121
|
-
least
|
|
139
|
+
least 1 row.
|
|
122
140
|
6. Estimation detail must contain a line matching `/calibration/i`.
|
|
123
141
|
|
|
124
142
|
Row-level, on the task table (found by header, needs `Task`, `Confidence`,
|
|
@@ -138,6 +156,11 @@ column but no `Task` column):
|
|
|
138
156
|
split itself, so it does not carry the full four-word provenance
|
|
139
157
|
vocabulary.
|
|
140
158
|
|
|
159
|
+
11b. At `STANDARD`/`DEEP` the scope table has a `Tier` column and every
|
|
160
|
+
row's Tier must match `computed.features[<id>].tier` (the letter the
|
|
161
|
+
scores produced — `scoring-checks.mjs`). At `QUICK` the Tier cell is
|
|
162
|
+
the agent's own call, unchecked.
|
|
163
|
+
|
|
141
164
|
JSON-side (checked against `estimation.json`, not the prose):
|
|
142
165
|
|
|
143
166
|
12. The `computed` block must equal a fresh recompute of `computed` from
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// masked as measured, invented evidence, missing planning work, and the
|
|
4
4
|
// mandatory "Delivery: agentic" header line. Split out of checks.mjs to stay
|
|
5
5
|
// under the file's function/line quality gates.
|
|
6
|
-
import { heading, tables } from './
|
|
6
|
+
import { heading, tables } from './md-tables.mjs';
|
|
7
7
|
|
|
8
8
|
const VAGUE_PATTERNS = [
|
|
9
9
|
/\b\d+\s*[–—-]\s*\d+\s*(hours?|hrs|minutes?|mins)\b/i,
|
|
@@ -4,39 +4,12 @@
|
|
|
4
4
|
import { computeEstimation } from './rollup.mjs';
|
|
5
5
|
import { loadMeasurements, resolveMeasurementsPath } from './measurements.mjs';
|
|
6
6
|
import { agenticFindings } from './agentic-checks.mjs';
|
|
7
|
+
import { heading, tables } from './md-tables.mjs';
|
|
8
|
+
import { scoringFindings } from './scoring-checks.mjs';
|
|
7
9
|
|
|
8
10
|
const PROVENANCE = ['observed', 'stated', 'researched', 'proposed'];
|
|
9
11
|
const CONFIDENCE = ['HIGH', 'MED', 'LOW'];
|
|
10
12
|
|
|
11
|
-
// Returns the text of the section/subsection starting at heading `name`, up
|
|
12
|
-
// to (not including) the next heading of the same or shallower level.
|
|
13
|
-
export function heading(md, name) {
|
|
14
|
-
const m = new RegExp(`^(#{2,4})\\s*${name}\\b.*$`, 'm').exec(md);
|
|
15
|
-
if (!m) return null;
|
|
16
|
-
const rest = md.slice(m.index + m[0].length);
|
|
17
|
-
const next = rest.search(new RegExp(`^#{1,${m[1].length}}\\s`, 'm'));
|
|
18
|
-
return rest.slice(0, next === -1 ? undefined : next);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function cells(line) {
|
|
22
|
-
return line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((c) => c.trim());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Groups contiguous `| ... |` lines into tables, dropping the `| --- |`
|
|
26
|
-
// separator row, and returns each as { header, rows } of trimmed cells.
|
|
27
|
-
export function tables(text) {
|
|
28
|
-
const groups = [];
|
|
29
|
-
let cur = [];
|
|
30
|
-
for (const line of (text ?? '').split('\n')) {
|
|
31
|
-
if (/^\s*\|/.test(line)) cur.push(line);
|
|
32
|
-
else if (cur.length) { groups.push(cur); cur = []; }
|
|
33
|
-
}
|
|
34
|
-
if (cur.length) groups.push(cur);
|
|
35
|
-
return groups
|
|
36
|
-
.map((g) => g.filter((l) => !/^\s*\|?[\s:|-]+\|?\s*$/.test(l)))
|
|
37
|
-
.map((g) => ({ header: cells(g[0]), rows: g.slice(1).map(cells) }));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
13
|
function checkStructure(md) {
|
|
41
14
|
const out = [];
|
|
42
15
|
const summary = heading(md, 'Summary');
|
|
@@ -48,7 +21,7 @@ function checkStructure(md) {
|
|
|
48
21
|
if (assumptionRows.length < 1) out.push('assumptions register is empty (### Assumptions needs >= 1 row)');
|
|
49
22
|
if (!/\|.*buffer.*\|/i.test(summary ?? '')) out.push('no buffer line item found in Summary (/buffer/i)');
|
|
50
23
|
const scenarioTable = tables(detail ?? '').find((t) => t.header.includes('Scenario'));
|
|
51
|
-
if (!scenarioTable || scenarioTable.rows.length <
|
|
24
|
+
if (!scenarioTable || scenarioTable.rows.length < 1) out.push('scenario comparison table missing or empty');
|
|
52
25
|
if (!/calibration/i.test(detail ?? '')) out.push('no calibration line found in Estimation detail');
|
|
53
26
|
return out;
|
|
54
27
|
}
|
|
@@ -132,6 +105,7 @@ function checkNumbers(estimation) {
|
|
|
132
105
|
export function checkDeliverables({ md, estimation }) {
|
|
133
106
|
const out = [...checkStructure(md), ...checkRows(md, estimation), ...checkNumbers(estimation)];
|
|
134
107
|
checkRoadmap(md, estimation, out);
|
|
108
|
+
out.push(...scoringFindings({ md, estimation }));
|
|
135
109
|
if (estimation.inputs.deliveryMode === 'agentic') out.push(...agenticFindings({ md, estimation }));
|
|
136
110
|
return out;
|
|
137
111
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// Every formula the estimate ships — imported by compute.mjs at build time
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Every formula the estimate ships — imported by compute.mjs at build time.
|
|
2
|
+
// The estimate pages inline nothing: every number they show is committed in
|
|
3
|
+
// estimation.json. The score review page inlines TIER_BREAKS and tierFor
|
|
4
|
+
// alone, so an edited score re-tiers in the browser on the same scale.
|
|
4
5
|
|
|
5
6
|
export const AI_CATEGORIES = {
|
|
6
7
|
boilerplate: { min: 0.5, max: 0.8 },
|
|
@@ -10,9 +11,10 @@ export const AI_CATEGORIES = {
|
|
|
10
11
|
export const SENIORITY_FACTOR = { junior: 1.15, mid: 1.0, senior: 0.85 };
|
|
11
12
|
export const HOURS_PER_MONTH = 140;
|
|
12
13
|
export const COORDINATION_TAX = 0.10;
|
|
13
|
-
|
|
14
|
+
// The team workbook's tier scale (its sheet-1 formula and Tier Reference tab):
|
|
15
|
+
// one scale for the interview, the validator, the page and the xlsx export.
|
|
14
16
|
export const TIER_BREAKS = [
|
|
15
|
-
{ max:
|
|
17
|
+
{ max: 11, tier: 'S' }, { max: 17, tier: 'M' }, { max: 22, tier: 'L' }, { max: Infinity, tier: 'XL' },
|
|
16
18
|
];
|
|
17
19
|
|
|
18
20
|
export function pert({ o, m, p }) {
|
|
@@ -41,9 +43,9 @@ export function aiAdjust({ e, category, verificationPct, scale = 1 }) {
|
|
|
41
43
|
// Seniority scales the base effort on every path; the AI reduction is a
|
|
42
44
|
// property of the task category alone. Scaling the reduction by seniority
|
|
43
45
|
// instead made juniors come out faster than seniors on AI plans.
|
|
44
|
-
export function taskHours({ e, seniority,
|
|
46
|
+
export function taskHours({ e, seniority, aiAssisted, category, verificationPct, scale = 1 }) {
|
|
45
47
|
const base = e * SENIORITY_FACTOR[seniority];
|
|
46
|
-
return
|
|
48
|
+
return aiAssisted ? aiAdjust({ e: base, category, verificationPct, scale }) : base;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
// One seniority drives effort for a whole team: the most common level wins,
|
|
@@ -64,11 +66,13 @@ export function effectiveCapacity(engineers) {
|
|
|
64
66
|
return Math.max(1, engineers * (1 - COORDINATION_TAX * (engineers - 1)));
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
// Tooling is priced per seat per month, vendor-neutral. A null seat cost is
|
|
70
|
+
// a recorded gap (the schema demands an assumption for it) and prices as 0.
|
|
71
|
+
export function scenarioRollup({ hours, team, toolingCostPerSeat }) {
|
|
68
72
|
const months = hours / (effectiveCapacity(team.length) * HOURS_PER_MONTH);
|
|
69
73
|
const laborCost = months * team.reduce((sum, t) => sum + t.rate * HOURS_PER_MONTH, 0);
|
|
70
|
-
const
|
|
71
|
-
return { months, laborCost,
|
|
74
|
+
const toolingCost = months * (toolingCostPerSeat ?? 0) * team.length;
|
|
75
|
+
return { months, laborCost, toolingCost, totalCost: laborCost + toolingCost };
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
// Sequential roadmap: each milestone's band width is its share of total task
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// The math module is written once as ESM and shipped twice: imported by
|
|
2
|
-
// compute.mjs, and inlined
|
|
3
|
-
//
|
|
2
|
+
// compute.mjs, and inlined into a page as a plain script. Only the score
|
|
3
|
+
// review page needs any of it — score-html.mjs extracts TIER_BREAKS and
|
|
4
|
+
// tierFor so the page can re-tier an edited row — so the extraction is
|
|
5
|
+
// by name, never the whole module.
|
|
4
6
|
export function inlineModule(src) {
|
|
5
7
|
return src.replaceAll(/^export /gm, '');
|
|
6
8
|
}
|
|
@@ -9,12 +11,8 @@ export function stripInternal(html) {
|
|
|
9
11
|
return html.replaceAll(/<!-- internal:start -->[\s\S]*?<!-- internal:end -->/g, '');
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
// the agentic page never uses) — inlining the whole file would leak
|
|
15
|
-
// AI_CATEGORIES' category names onto a page that must never show them.
|
|
16
|
-
// Anchors on `export const NAME` / `export function NAME` at line start,
|
|
17
|
-
// same declaration shapes estimate-math.mjs uses throughout.
|
|
14
|
+
// Anchors on `export const NAME` / `export function NAME` at line start, the
|
|
15
|
+
// declaration shapes estimate-math.mjs uses throughout.
|
|
18
16
|
export function extractExports(src, names) {
|
|
19
17
|
const starts = [...src.matchAll(/^export (?:const|function) (\w+)/gm)];
|
|
20
18
|
return starts
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Markdown readers shared by the deliverable checks: find a section by its
|
|
2
|
+
// heading, and read every `| … |` table in a slice of text.
|
|
3
|
+
|
|
4
|
+
// Returns the text of the section/subsection starting at heading `name`, up
|
|
5
|
+
// to (not including) the next heading of the same or shallower level.
|
|
6
|
+
export function heading(md, name) {
|
|
7
|
+
const m = new RegExp(`^(#{2,4})\\s*${name}\\b.*$`, 'm').exec(md);
|
|
8
|
+
if (!m) return null;
|
|
9
|
+
const rest = md.slice(m.index + m[0].length);
|
|
10
|
+
const next = rest.search(new RegExp(`^#{1,${m[1].length}}\\s`, 'm'));
|
|
11
|
+
return rest.slice(0, next === -1 ? undefined : next);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function cells(line) {
|
|
15
|
+
return line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((c) => c.trim());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Groups contiguous `| ... |` lines into tables, dropping the `| --- |`
|
|
19
|
+
// separator row, and returns each as { header, rows } of trimmed cells.
|
|
20
|
+
export function tables(text) {
|
|
21
|
+
const groups = [];
|
|
22
|
+
let cur = [];
|
|
23
|
+
for (const line of (text ?? '').split('\n')) {
|
|
24
|
+
if (/^\s*\|/.test(line)) cur.push(line);
|
|
25
|
+
else if (cur.length) { groups.push(cur); cur = []; }
|
|
26
|
+
}
|
|
27
|
+
if (cur.length) groups.push(cur);
|
|
28
|
+
return groups
|
|
29
|
+
.map((g) => g.filter((l) => !/^\s*\|?[\s:|-]+\|?\s*$/.test(l)))
|
|
30
|
+
.map((g) => ({ header: cells(g[0]), rows: g.slice(1).map(cells) }));
|
|
31
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The --client-only export embeds the full estimation JSON in the page; this
|
|
2
|
-
// strips the internal money detail (rates, labor/
|
|
2
|
+
// strips the internal money detail (rates, labor/tooling cost split, per-task
|
|
3
3
|
// hours per scenario) before it ships, unless the inputs opt out via
|
|
4
4
|
// exposeRatesToClient. Assumptions/risks are left alone — those are
|
|
5
5
|
// client-facing per spec.
|
|
@@ -17,7 +17,7 @@ function redactScenarioTeam(team) {
|
|
|
17
17
|
|
|
18
18
|
function redactComputedScenarios(scenarios) {
|
|
19
19
|
return Object.fromEntries(Object.entries(scenarios).map(([id, s]) => {
|
|
20
|
-
const { laborCost,
|
|
20
|
+
const { laborCost, toolingCost, taskHours, ...rest } = s;
|
|
21
21
|
return [id, rest];
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
@@ -28,6 +28,16 @@ function redactAgenticInputs({ measurementsPath, agentContext, ...rest }) {
|
|
|
28
28
|
return { ...rest, agentContext: clientAgentContext };
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// A score's cite is internal shorthand — the ticket phrase, file name or
|
|
32
|
+
// meeting wording the judgment rests on — so it is blanked unconditionally,
|
|
33
|
+
// like the agentic fields above. The rubric anchor is the sentence the client
|
|
34
|
+
// can read and it stays, so the page still explains every score.
|
|
35
|
+
function blankCites(feature) {
|
|
36
|
+
if (!feature.scores) return feature;
|
|
37
|
+
const scores = Object.entries(feature.scores).map(([k, s]) => [k, { ...s, cite: '' }]);
|
|
38
|
+
return { ...feature, scores: Object.fromEntries(scores) };
|
|
39
|
+
}
|
|
40
|
+
|
|
31
41
|
function redactComputedTasks(tasks) {
|
|
32
42
|
return Object.fromEntries(Object.entries(tasks).map(([id, t]) => [
|
|
33
43
|
id,
|
|
@@ -36,7 +46,8 @@ function redactComputedTasks(tasks) {
|
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
export function redactForClient(estimation) {
|
|
39
|
-
const
|
|
49
|
+
const agentic = redactAgenticInputs(estimation.inputs);
|
|
50
|
+
const inputs = { ...agentic, features: agentic.features.map(blankCites) };
|
|
40
51
|
const computed = { ...estimation.computed, tasks: redactComputedTasks(estimation.computed.tasks) };
|
|
41
52
|
if (estimation.inputs.exposeRatesToClient) return { ...estimation, inputs, computed };
|
|
42
53
|
return {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { roadmapFor } from './roadmap.mjs';
|
|
8
8
|
import { componentHoursFor } from './components.mjs';
|
|
9
9
|
import { agenticTask } from './baselines.mjs';
|
|
10
|
+
import { scoreSummary } from './scoring.mjs';
|
|
10
11
|
|
|
11
12
|
function sortedMap(entries) {
|
|
12
13
|
return Object.fromEntries(entries.sort(([a], [b]) => a.localeCompare(b)));
|
|
@@ -21,7 +22,7 @@ export function taskHoursFor(scenario, tasks) {
|
|
|
21
22
|
const entries = Object.keys(tasks).map((id) => [id, tasks[id].evidence !== undefined
|
|
22
23
|
? tasks[id].e
|
|
23
24
|
: taskHours({
|
|
24
|
-
e: tasks[id].e, seniority,
|
|
25
|
+
e: tasks[id].e, seniority, aiAssisted: scenario.aiAssisted,
|
|
25
26
|
category: tasks[id].category, verificationPct: tasks[id].verificationPct,
|
|
26
27
|
})]);
|
|
27
28
|
return sortedMap(entries);
|
|
@@ -31,7 +32,7 @@ export function scenarioBlock(scenario, ctx) {
|
|
|
31
32
|
const taskHours = taskHoursFor(scenario, ctx.tasks);
|
|
32
33
|
const sumTaskHours = Object.values(taskHours).reduce((a, b) => a + b, 0);
|
|
33
34
|
const hours = sumTaskHours + sumTaskHours * ctx.overheadPct + ctx.spreadBufferHours + ctx.riskBufferHours;
|
|
34
|
-
const rollup = scenarioRollup({ hours, team: scenario.team,
|
|
35
|
+
const rollup = scenarioRollup({ hours, team: scenario.team, toolingCostPerSeat: scenario.toolingCostPerSeat });
|
|
35
36
|
const roadmap = roadmapFor({ features: ctx.features, taskHours, months: rollup.months })
|
|
36
37
|
?.map((b) => ({ ...b, startMonths: round2(b.startMonths), endMonths: round2(b.endMonths) }));
|
|
37
38
|
const notes = [];
|
|
@@ -42,7 +43,7 @@ export function scenarioBlock(scenario, ctx) {
|
|
|
42
43
|
hours: round2(hours),
|
|
43
44
|
months: round2(rollup.months),
|
|
44
45
|
laborCost: round2(rollup.laborCost),
|
|
45
|
-
|
|
46
|
+
toolingCost: round2(rollup.toolingCost),
|
|
46
47
|
totalCost: round2(rollup.totalCost),
|
|
47
48
|
notes,
|
|
48
49
|
...(roadmap ? { roadmap } : {}),
|
|
@@ -99,7 +100,7 @@ function buildFeatures(inputs, tasks) {
|
|
|
99
100
|
const hours = taskIds.reduce((sum, id) => sum + tasks[id].e, 0);
|
|
100
101
|
const low = taskIds.reduce((sum, id) => sum + tasks[id].o, 0);
|
|
101
102
|
const high = taskIds.reduce((sum, id) => sum + tasks[id].p, 0);
|
|
102
|
-
features[feature.id] = { hours: round2(hours), low: round2(low), high: round2(high) };
|
|
103
|
+
features[feature.id] = { hours: round2(hours), low: round2(low), high: round2(high), ...scoreSummary(feature) };
|
|
103
104
|
summaries.push({ hours, taskIds });
|
|
104
105
|
}
|
|
105
106
|
return { features: sortedMap(Object.entries(features)), summaries };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Scenario-shape checks for estimation-inputs.json: team roster, AI
|
|
2
|
+
// assistance, and the per-seat tooling price. Split from schema.mjs so each
|
|
3
|
+
// module stays under the ten-function gate; findings follow the same
|
|
4
|
+
// "scenario <id>: ..." form.
|
|
5
|
+
import { SENIORITY_FACTOR } from './estimate-math.mjs';
|
|
6
|
+
|
|
7
|
+
// A seat price may be skipped (the client may mandate a vendor) but only as
|
|
8
|
+
// a recorded gap: an AI-assisted scenario with a null seat cost needs an
|
|
9
|
+
// assumption that names it, or the total would silently miss a line item.
|
|
10
|
+
const seatCostOk = (v) => v === null || (typeof v === 'number' && v > 0);
|
|
11
|
+
const toolingAssumed = (inputs) => (inputs.assumptions ?? [])
|
|
12
|
+
.some((a) => /tooling/i.test(typeof a === 'string' ? a : a?.text ?? ''));
|
|
13
|
+
|
|
14
|
+
function checkScenarioAi(s, inputs, out) {
|
|
15
|
+
if ('plan' in s) out.push(`scenario ${s.id}: "plan" was removed — use aiAssisted + toolingCostPerSeat`);
|
|
16
|
+
if (typeof s.aiAssisted !== 'boolean') out.push(`scenario ${s.id}: aiAssisted must be true|false`);
|
|
17
|
+
if (!('toolingCostPerSeat' in s) || !seatCostOk(s.toolingCostPerSeat)) {
|
|
18
|
+
out.push(`scenario ${s.id}: toolingCostPerSeat must be a positive number or null`);
|
|
19
|
+
}
|
|
20
|
+
if (s.aiAssisted === true && s.toolingCostPerSeat === null && !toolingAssumed(inputs)) {
|
|
21
|
+
out.push(`scenario ${s.id}: null toolingCostPerSeat needs an assumption naming the tooling cost gap`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function checkScenarios(inputs, out) {
|
|
26
|
+
const ids = (inputs.scenarios ?? []).map((s) => s.id);
|
|
27
|
+
if (!ids.includes(inputs.recommendedScenario)) out.push('recommendedScenario names no scenario');
|
|
28
|
+
if ('recommendedReason' in inputs && !(typeof inputs.recommendedReason === 'string' && inputs.recommendedReason.trim())) {
|
|
29
|
+
out.push('recommendedReason must be a non-empty string when present');
|
|
30
|
+
}
|
|
31
|
+
for (const s of inputs.scenarios ?? []) {
|
|
32
|
+
if (!s.team?.length) out.push(`scenario ${s.id}: empty team`);
|
|
33
|
+
checkScenarioAi(s, inputs, out);
|
|
34
|
+
for (const member of s.team ?? []) {
|
|
35
|
+
if (!Object.hasOwn(SENIORITY_FACTOR, member.seniority)) out.push(`scenario ${s.id}: unknown seniority "${member.seniority}"`);
|
|
36
|
+
if (!(typeof member.rate === 'number' && member.rate > 0)) out.push(`scenario ${s.id}: rate must be a positive number`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Shape checks for estimation-inputs.json — the agent writes that file, so the
|
|
2
2
|
// checks here are the contract that keeps interview output honest before any
|
|
3
3
|
// arithmetic happens. Findings are strings with the offending id in them.
|
|
4
|
-
import { AI_CATEGORIES
|
|
4
|
+
import { AI_CATEGORIES } from './estimate-math.mjs';
|
|
5
|
+
import { checkScenarios } from './scenario-schema.mjs';
|
|
6
|
+
import { checkScoring } from './scoring-schema.mjs';
|
|
5
7
|
import { TASK_SHAPES } from './measurements.mjs';
|
|
6
8
|
|
|
7
9
|
const PROVENANCE = ['observed', 'stated', 'researched', 'proposed'];
|
|
@@ -114,19 +116,6 @@ function checkComponents(inputs, out) {
|
|
|
114
116
|
checkComponentCoverage(inputs.components, features, out);
|
|
115
117
|
}
|
|
116
118
|
|
|
117
|
-
function checkScenarios(inputs, out) {
|
|
118
|
-
const ids = (inputs.scenarios ?? []).map((s) => s.id);
|
|
119
|
-
if (!ids.includes(inputs.recommendedScenario)) out.push('recommendedScenario names no scenario');
|
|
120
|
-
for (const s of inputs.scenarios ?? []) {
|
|
121
|
-
if (!s.team?.length) out.push(`scenario ${s.id}: empty team`);
|
|
122
|
-
if (!Object.hasOwn(PLAN_PRICES, s.plan)) out.push(`scenario ${s.id}: unknown plan "${s.plan}"`);
|
|
123
|
-
for (const member of s.team ?? []) {
|
|
124
|
-
if (!Object.hasOwn(SENIORITY_FACTOR, member.seniority)) out.push(`scenario ${s.id}: unknown seniority "${member.seniority}"`);
|
|
125
|
-
if (!(typeof member.rate === 'number' && member.rate > 0)) out.push(`scenario ${s.id}: rate must be a positive number`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
119
|
// Anything compute.mjs would turn into NaN gets refused here instead: the
|
|
131
120
|
// "computed truth" contract holds only if every operand is a sane number.
|
|
132
121
|
// Risks carry hours in team mode and minutes in agentic mode — the unit the
|
|
@@ -168,6 +157,7 @@ export function checkInputs(inputs) {
|
|
|
168
157
|
checkMilestones(inputs.features ?? [], out);
|
|
169
158
|
checkComponents(inputs, out);
|
|
170
159
|
checkScenarios(inputs, out);
|
|
160
|
+
checkScoring(inputs, out);
|
|
171
161
|
checkGlobals(inputs, out, agentic);
|
|
172
162
|
return out;
|
|
173
163
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Spreadsheet review channel: the agent writes its proposed scores as a CSV
|
|
2
|
+
// the human edits in Sheets/Excel; the numbers, the plain note and a free
|
|
3
|
+
// "note" column come back. Anchors and cites travel beside each score so the
|
|
4
|
+
// reviewer sees the reason without opening anything else.
|
|
5
|
+
import { SCORE_FACTORS, scoreNumbers } from './scoring.mjs';
|
|
6
|
+
import { tierFor } from './estimate-math.mjs';
|
|
7
|
+
|
|
8
|
+
export const CSV_HEADERS = ['id', 'feature',
|
|
9
|
+
...SCORE_FACTORS.flatMap((k) => [k, `${k}_why`, `${k}_cite`]), 'sum', 'tier', 'why_this_tier', 'note'];
|
|
10
|
+
|
|
11
|
+
const quote = (v) => {
|
|
12
|
+
const s = String(v ?? '');
|
|
13
|
+
return /[",\n\r]/.test(s) ? `"${s.replaceAll('"', '""')}"` : s;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function featureRow(f) {
|
|
17
|
+
const { total, tier } = tierFor(scoreNumbers(f.scores));
|
|
18
|
+
return [f.id, f.name, ...SCORE_FACTORS.flatMap((k) => [f.scores[k].n, f.scores[k].anchor, f.scores[k].cite]),
|
|
19
|
+
total, tier, f.scoreNote, ''];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function toCsv(draft) {
|
|
23
|
+
return [CSV_HEADERS, ...draft.features.map(featureRow)].map((r) => r.map(quote).join(',')).join('\n') + '\n';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// RFC 4180: quoted fields may hold commas, newlines and doubled quotes.
|
|
27
|
+
export function parseCsv(text) {
|
|
28
|
+
const rows = [[]];
|
|
29
|
+
let field = '';
|
|
30
|
+
let quoted = false;
|
|
31
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
32
|
+
const c = text[i];
|
|
33
|
+
if (quoted) {
|
|
34
|
+
if (c === '"' && text[i + 1] === '"') { field += '"'; i += 1; } else if (c === '"') quoted = false; else field += c;
|
|
35
|
+
} else if (c === '"') quoted = true;
|
|
36
|
+
else if (c === ',') { rows.at(-1).push(field); field = ''; } else if (c === '\n' || c === '\r') {
|
|
37
|
+
if (c === '\r' && text[i + 1] === '\n') i += 1;
|
|
38
|
+
rows.at(-1).push(field); field = ''; rows.push([]);
|
|
39
|
+
} else field += c;
|
|
40
|
+
}
|
|
41
|
+
if (field !== '' || rows.at(-1).length) rows.at(-1).push(field);
|
|
42
|
+
return rows.filter((r) => r.length && (r.length > 1 || r[0] !== ''));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// A renamed or deleted score column would read back as NaN for every feature
|
|
46
|
+
// and land in the diff as a change the human never made.
|
|
47
|
+
export function fromCsv(text) {
|
|
48
|
+
const [head, ...rows] = parseCsv(text);
|
|
49
|
+
const col = (name) => head.indexOf(name);
|
|
50
|
+
const missing = SCORE_FACTORS.filter((k) => col(k) === -1);
|
|
51
|
+
if (missing.length) throw new Error(`csv is missing score columns: ${missing.join(', ')}`);
|
|
52
|
+
return { features: rows.map((r) => ({
|
|
53
|
+
id: r[col('id')],
|
|
54
|
+
scores: Object.fromEntries(SCORE_FACTORS.map((k) => [k, Number(r[col(k)])])),
|
|
55
|
+
scoreNote: r[col('why_this_tier')],
|
|
56
|
+
note: r[col('note')] ?? '',
|
|
57
|
+
})) };
|
|
58
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// What the human changed, and how to fold it back into the draft. A changed
|
|
2
|
+
// score gets the guide's sentence for its new value (the anchor is a function
|
|
3
|
+
// of factor × score, never free text) and keeps its cite for the agent to
|
|
4
|
+
// revisit; any change flips the feature to `stated`.
|
|
5
|
+
import { SCORE_FACTORS } from './scoring.mjs';
|
|
6
|
+
|
|
7
|
+
export function diffScores(draft, edited) {
|
|
8
|
+
const out = [];
|
|
9
|
+
for (const e of edited.features) {
|
|
10
|
+
const d = draft.features.find((f) => f.id === e.id);
|
|
11
|
+
if (!d) continue;
|
|
12
|
+
for (const k of SCORE_FACTORS) {
|
|
13
|
+
if (e.scores[k] !== d.scores[k].n) out.push({ id: e.id, field: k, from: d.scores[k].n, to: e.scores[k] });
|
|
14
|
+
}
|
|
15
|
+
if (e.scoreNote !== undefined && e.scoreNote !== d.scoreNote) out.push({ id: e.id, field: 'scoreNote', from: d.scoreNote, to: e.scoreNote });
|
|
16
|
+
if (e.note) out.push({ id: e.id, field: 'note', to: e.note });
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function applyOne(feature, change, guide) {
|
|
22
|
+
if (change.field === 'note') return feature;
|
|
23
|
+
if (change.field === 'scoreNote') return { ...feature, scoreNote: change.to, scoreProvenance: 'stated' };
|
|
24
|
+
const score = { ...feature.scores[change.field], n: change.to, anchor: guide[change.field][change.to - 1] };
|
|
25
|
+
return { ...feature, scores: { ...feature.scores, [change.field]: score }, scoreProvenance: 'stated' };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function applyDiff({ draft, diff, guide }) {
|
|
29
|
+
return draft.features.map((f) => diff.filter((c) => c.id === f.id).reduce((acc, c) => applyOne(acc, c, guide), f));
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// HTML review channel: the agent's draft rendered as one editable table,
|
|
2
|
+
// Σ/tier live, the rubric folded underneath, and a feedback block the human
|
|
3
|
+
// copies back. Same slots discipline as the estimate page (embed is strict).
|
|
4
|
+
import { embed } from '../../../analyze-requirements/scripts/lib/embed.mjs';
|
|
5
|
+
import { inlineModule, extractExports } from './inline.mjs';
|
|
6
|
+
|
|
7
|
+
export function toHtml({ draft, template, guideHtml, mathSrc }) {
|
|
8
|
+
return embed({
|
|
9
|
+
template,
|
|
10
|
+
slots: {
|
|
11
|
+
TITLE: draft.project ?? 'Estimate',
|
|
12
|
+
DATA: JSON.stringify(draft).replaceAll('</script', '<\\/script'),
|
|
13
|
+
GUIDE: guideHtml,
|
|
14
|
+
MATH: inlineModule(extractExports(mathSrc, ['TIER_BREAKS', 'tierFor'])),
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// The Summary's feature/tier table typed a Tier letter nobody checked. At
|
|
2
|
+
// STANDARD/DEEP the letter must be the one the scores produced (copied into
|
|
3
|
+
// computed.features by rollup.mjs). QUICK and agentic deliverables are not
|
|
4
|
+
// scored and skip this.
|
|
5
|
+
import { heading, tables } from './md-tables.mjs';
|
|
6
|
+
|
|
7
|
+
const scored = (inputs) => inputs.deliveryMode !== 'agentic' && inputs.depth !== 'QUICK';
|
|
8
|
+
|
|
9
|
+
export function scoringFindings({ md, estimation }) {
|
|
10
|
+
const out = [];
|
|
11
|
+
const { inputs, computed } = estimation;
|
|
12
|
+
if (!scored(inputs)) return out;
|
|
13
|
+
const table = tables(heading(md, 'Summary') ?? '').find((t) => t.header.includes('src') && !t.header.includes('Task'));
|
|
14
|
+
if (!table) return out; // checkScopeRows already reports the missing table
|
|
15
|
+
const tierIdx = table.header.indexOf('Tier');
|
|
16
|
+
if (tierIdx === -1) { out.push('summary scope table needs a Tier column at STANDARD/DEEP depth'); return out; }
|
|
17
|
+
const want = Object.fromEntries(inputs.features.map((f) => [f.name, computed.features[f.id]?.tier]));
|
|
18
|
+
for (const row of table.rows) {
|
|
19
|
+
if (want[row[0]] && row[tierIdx] !== want[row[0]]) {
|
|
20
|
+
out.push(`scope row "${row[0]}": Tier ${row[tierIdx]} does not match scores (${want[row[0]]})`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Score rules for estimation-inputs.json. Scores exist only at STANDARD and
|
|
2
|
+
// DEEP depth (QUICK uses them for a tier and does not persist them), so the
|
|
3
|
+
// rules run by depth. Anchors must be the guide's own sentence for that
|
|
4
|
+
// factor and score, which is what stops a reason from drifting away from
|
|
5
|
+
// the rubric the way derived scores drifted away from the hours.
|
|
6
|
+
import { SCORE_FACTORS, loadGuide } from './scoring.mjs';
|
|
7
|
+
|
|
8
|
+
const DEPTHS = ['QUICK', 'STANDARD', 'DEEP'];
|
|
9
|
+
const SCORE_FIELDS = ['scores', 'scoreNote', 'scoreProvenance'];
|
|
10
|
+
// A client-facing sentence: no factor names, no file names, no section marks.
|
|
11
|
+
const NOTE_BANNED = /\.md\b|§|\b(tech|size|deps|unc|risk)\b/i;
|
|
12
|
+
const nonEmpty = (v) => typeof v === 'string' && v.trim() !== '';
|
|
13
|
+
|
|
14
|
+
function checkScore({ id, key, score, guide }, out) {
|
|
15
|
+
const n = score?.n;
|
|
16
|
+
if (!(Number.isInteger(n) && n >= 1 && n <= 5)) { out.push(`feature ${id}: scores.${key}.n must be an integer 1–5`); return; }
|
|
17
|
+
if (score.anchor !== guide[key][n - 1]) out.push(`feature ${id}: scores.${key}.anchor is not the guide's sentence for ${key} = ${n}`);
|
|
18
|
+
if (!nonEmpty(score.cite)) out.push(`feature ${id}: scores.${key}.cite is required`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function checkScoredFeature(feature, guide, out) {
|
|
22
|
+
const s = feature.scores;
|
|
23
|
+
if (typeof s !== 'object' || s === null) { out.push(`feature ${feature.id}: scores object is required at STANDARD/DEEP depth`); return; }
|
|
24
|
+
if (Object.keys(s).sort().join() !== [...SCORE_FACTORS].sort().join()) {
|
|
25
|
+
out.push(`feature ${feature.id}: scores must have exactly ${SCORE_FACTORS.join(', ')}`);
|
|
26
|
+
}
|
|
27
|
+
for (const key of SCORE_FACTORS) if (s[key] !== undefined) checkScore({ id: feature.id, key, score: s[key], guide }, out);
|
|
28
|
+
if (!nonEmpty(feature.scoreNote) || NOTE_BANNED.test(feature.scoreNote)) {
|
|
29
|
+
out.push(`feature ${feature.id}: scoreNote must be one plain sentence (no file names, factor names or section marks)`);
|
|
30
|
+
}
|
|
31
|
+
if (!['stated', 'proposed'].includes(feature.scoreProvenance)) out.push(`feature ${feature.id}: scoreProvenance must be stated|proposed`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function checkQuickFeature(feature, out) {
|
|
35
|
+
for (const key of SCORE_FIELDS) {
|
|
36
|
+
if (key in feature) out.push(`feature ${feature.id}: ${key} is not persisted at QUICK depth`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function checkScoring(inputs, out) {
|
|
41
|
+
if (!DEPTHS.includes(inputs.depth)) { out.push('depth must be QUICK|STANDARD|DEEP'); return; }
|
|
42
|
+
if (inputs.deliveryMode === 'agentic') return;
|
|
43
|
+
const guide = inputs.depth === 'QUICK' ? null : loadGuide();
|
|
44
|
+
for (const feature of inputs.features ?? []) {
|
|
45
|
+
if (guide) checkScoredFeature(feature, guide, out);
|
|
46
|
+
else checkQuickFeature(feature, out);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Factor scores are human judgments recorded in estimation-inputs.json.
|
|
2
|
+
// This module owns their vocabulary, the rubric loader (references/
|
|
3
|
+
// scoring-guide.md is the single source of anchor text), and the two
|
|
4
|
+
// derived facts compute copies into estimation.json: Σ and tier.
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { escapeHtml } from '../../../analyze-requirements/scripts/lib/md-inline.mjs';
|
|
7
|
+
import { tierFor } from './estimate-math.mjs';
|
|
8
|
+
|
|
9
|
+
export const SCORE_FACTORS = ['tech', 'size', 'deps', 'unc', 'risk'];
|
|
10
|
+
export const FACTOR_LABELS = {
|
|
11
|
+
tech: 'Tech complexity', size: 'Feature size', deps: 'Dependencies', unc: 'Uncertainty', risk: 'Risk',
|
|
12
|
+
};
|
|
13
|
+
const GUIDE_PATH = new URL('../../references/scoring-guide.md', import.meta.url);
|
|
14
|
+
|
|
15
|
+
const cells = (line) => line.split('|').slice(1, -1).map((c) => c.trim());
|
|
16
|
+
|
|
17
|
+
// Returns { tech: [a1..a5], ... } from the guide's one table. Rows are found
|
|
18
|
+
// by their label, so the doc may reorder them; anchors may not contain `|`.
|
|
19
|
+
// A renamed, short or deleted row is named here, not left to surface as an
|
|
20
|
+
// undefined anchor halfway through a render.
|
|
21
|
+
export function loadGuide(path = GUIDE_PATH) {
|
|
22
|
+
const rows = readFileSync(path, 'utf8').split('\n').filter((l) => /^\|/.test(l) && !/^\|\s*-/.test(l));
|
|
23
|
+
const byLabel = Object.fromEntries(rows.map(cells).map((c) => [c[0], c.slice(1)]));
|
|
24
|
+
const guide = Object.fromEntries(SCORE_FACTORS.map((k) => [k, byLabel[FACTOR_LABELS[k]]]));
|
|
25
|
+
const missing = SCORE_FACTORS.filter((k) => !(guide[k]?.length === 5));
|
|
26
|
+
if (missing.length) throw new Error(`scoring-guide.md: no 5-anchor row for ${missing.join(', ')}`);
|
|
27
|
+
return guide;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function guideTableHtml(guide) {
|
|
31
|
+
const head = `<tr><th>Dimension</th>${[1, 2, 3, 4, 5].map((n) => `<th class="score">${n}</th>`).join('')}</tr>`;
|
|
32
|
+
const body = SCORE_FACTORS.map((k) => `<tr><td class="dim">${FACTOR_LABELS[k]}</td>${
|
|
33
|
+
guide[k].map((a) => `<td>${escapeHtml(a)}</td>`).join('')}</tr>`).join('');
|
|
34
|
+
return `<table class="guide-table"><thead>${head}</thead><tbody>${body}</tbody></table>`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const scoreNumbers = (scores) => Object.fromEntries(SCORE_FACTORS.map((k) => [k, scores[k].n]));
|
|
38
|
+
|
|
39
|
+
// Copied into computed.features[id] at STANDARD/DEEP so page, checks and
|
|
40
|
+
// xlsx read one object; QUICK features carry no scores and get nothing.
|
|
41
|
+
export function scoreSummary(feature) {
|
|
42
|
+
if (!feature.scores) return {};
|
|
43
|
+
const { total, tier } = tierFor(scoreNumbers(feature.scores));
|
|
44
|
+
return { scoreTotal: total, tier };
|
|
45
|
+
}
|