@v11g/agents-rock 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
  4. package/plugins/solution-architect/skills/estimate/README.md +8 -5
  5. package/plugins/solution-architect/skills/estimate/SKILL.md +9 -5
  6. package/plugins/solution-architect/skills/estimate/assets/estimate-template-agentic.html +142 -376
  7. package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +610 -601
  8. package/plugins/solution-architect/skills/estimate/assets/scores-review-template.html +118 -0
  9. package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +5 -9
  10. package/plugins/solution-architect/skills/estimate/references/interview.md +121 -10
  11. package/plugins/solution-architect/skills/estimate/references/scoring-guide.md +23 -0
  12. package/plugins/solution-architect/skills/estimate/references/techniques.md +9 -2
  13. package/plugins/solution-architect/skills/estimate/references/writing.md +21 -5
  14. package/plugins/solution-architect/skills/estimate/scripts/lib/agentic-checks.mjs +1 -1
  15. package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +4 -30
  16. package/plugins/solution-architect/skills/estimate/scripts/lib/estimate-math.mjs +14 -10
  17. package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +6 -8
  18. package/plugins/solution-architect/skills/estimate/scripts/lib/md-tables.mjs +31 -0
  19. package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +14 -3
  20. package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +5 -4
  21. package/plugins/solution-architect/skills/estimate/scripts/lib/scenario-schema.mjs +39 -0
  22. package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +4 -14
  23. package/plugins/solution-architect/skills/estimate/scripts/lib/score-csv.mjs +58 -0
  24. package/plugins/solution-architect/skills/estimate/scripts/lib/score-diff.mjs +30 -0
  25. package/plugins/solution-architect/skills/estimate/scripts/lib/score-html.mjs +17 -0
  26. package/plugins/solution-architect/skills/estimate/scripts/lib/scoring-checks.mjs +24 -0
  27. package/plugins/solution-architect/skills/estimate/scripts/lib/scoring-schema.mjs +48 -0
  28. package/plugins/solution-architect/skills/estimate/scripts/lib/scoring.mjs +45 -0
  29. package/plugins/solution-architect/skills/estimate/scripts/render.mjs +14 -13
  30. package/plugins/solution-architect/skills/estimate/scripts/score-review.mjs +59 -0
  31. package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +403 -316
  32. package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +25 -1
  33. package/plugins/solution-architect/skills/estimate/scripts/test/estimate-math.test.mjs +29 -10
  34. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-inputs.json +2 -2
  35. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/booking-inputs.json +21 -3
  36. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-fail.md +1 -1
  37. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/estimation-pass.md +4 -4
  38. package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +61 -6
  39. package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +96 -13
  40. package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +105 -4
  41. package/plugins/solution-architect/skills/estimate/scripts/test/score-review.test.mjs +187 -0
  42. package/plugins/solution-architect/skills/estimate/scripts/test/scoring.test.mjs +49 -0
  43. package/plugins/solution-architect/skills/estimate/scripts/test/url-state.test.mjs +198 -0
  44. package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +38 -0
  45. package/plugins/solution-architect/skills/estimate/scripts/test/xlsx-export.test.mjs +93 -28
  46. package/plugins/solution-architect/skills/new-lead/scripts/lib/map-nodes.mjs +1 -1
  47. package/plugins/solution-architect/skills/proposal/scripts/test/checks-client.test.mjs +2 -2
  48. package/plugins/solution-architect/skills/proposal/scripts/test/figures.test.mjs +1 -1
@@ -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, plan: scenario.plan,
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, plan: scenario.plan });
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
- planCost: round2(rollup.planCost),
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, SENIORITY_FACTOR, PLAN_PRICES } from './estimate-math.mjs';
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
+ }
@@ -4,16 +4,9 @@ import { embed } from '../../analyze-requirements/scripts/lib/embed.mjs';
4
4
  import { buildFontFaces } from '../../analyze-requirements/scripts/lib/fonts.mjs';
5
5
  import { escapeHtml } from '../../analyze-requirements/scripts/lib/md-inline.mjs';
6
6
  import { checkDeliverables } from './lib/checks.mjs';
7
- import { inlineModule, stripInternal, extractExports } from './lib/inline.mjs';
7
+ import { stripInternal } from './lib/inline.mjs';
8
8
  import { redactForClient } from './lib/redact.mjs';
9
-
10
- // The agentic template's what-if rail only prices team/plan capacity —
11
- // task hours are constants from the estimation data, not recomputed from
12
- // PERT/AI-category inputs — so it needs only these exports inlined.
13
- const AGENTIC_MATH_EXPORTS = [
14
- 'HOURS_PER_MONTH', 'COORDINATION_TAX', 'PLAN_PRICES', 'SENIORITY_FACTOR',
15
- 'effectiveCapacity', 'scenarioRollup',
16
- ];
9
+ import { loadGuide, guideTableHtml } from './lib/scoring.mjs';
17
10
 
18
11
  function parseArgs(argv) {
19
12
  const args = {};
@@ -29,7 +22,6 @@ function parseArgs(argv) {
29
22
  }
30
23
 
31
24
  const archFontsDir = new URL('../../analyze-requirements/assets/fonts/', import.meta.url).pathname;
32
- const mathPath = new URL('./lib/estimate-math.mjs', import.meta.url).pathname;
33
25
  const assetsDir = new URL('../assets/', import.meta.url).pathname;
34
26
 
35
27
  const args = parseArgs(process.argv.slice(2));
@@ -46,7 +38,12 @@ if (findings.length) {
46
38
  process.exit(1);
47
39
  }
48
40
 
49
- const dataForEmbed = args['client-only'] ? redactForClient(estimation) : estimation;
41
+ // --figures: the proposal's client-facing range (proposal-figures.json), when
42
+ // the proposal exists. Client-safe by definition — it is what the client is
43
+ // quoted — so it rides along in both renders.
44
+ const figures = typeof args.figures === 'string' ? JSON.parse(readFileSync(args.figures, 'utf8')) : null;
45
+ const base = args['client-only'] ? redactForClient(estimation) : estimation;
46
+ const dataForEmbed = figures ? { ...base, figures: { cost: figures.cost, months: figures.months } } : base;
50
47
  // Companion mode: --viewer carries the caller-known path back to the analyze-requirements
51
48
  // viewer. It sits in the header's internal range, so the client render (which
52
49
  // must not point at an internal document set) strips it with everything else.
@@ -54,7 +51,6 @@ const viewerSlot = typeof args.viewer === 'string'
54
51
  ? `<a id="viewer-link" data-internal href="${escapeHtml(args.viewer)}">architecture docs</a>`
55
52
  : '';
56
53
  const template = readFileSync(templatePath, 'utf8');
57
- const mathSrc = readFileSync(mathPath, 'utf8');
58
54
  const html = embed({
59
55
  template,
60
56
  slots: {
@@ -62,8 +58,13 @@ const html = embed({
62
58
  FONTS: buildFontFaces(archFontsDir),
63
59
  // Escaped so a literal </script in the JSON can't close the data tag early.
64
60
  DATA: JSON.stringify(dataForEmbed).replaceAll('</script', '<\\/script'),
65
- MATH: inlineModule(isAgentic ? extractExports(mathSrc, AGENTIC_MATH_EXPORTS) : mathSrc),
66
61
  VIEWER: viewerSlot,
62
+ // The team page computes nothing — every number it shows is committed in
63
+ // estimation.json; the agentic page reads measured numbers only. The team
64
+ // page's one extra slot is the rubric, which lives in
65
+ // references/scoring-guide.md: the page shows the same sentences the
66
+ // interviewer read, so a score means one thing.
67
+ ...(isAgentic ? {} : { GUIDE: guideTableHtml(loadGuide()) }),
67
68
  },
68
69
  });
69
70
 
@@ -0,0 +1,59 @@
1
+ // Score review round-trip. --write turns the agent's draft into a CSV or an
2
+ // HTML review page; --read takes the edited CSV (or the page's feedback
3
+ // JSON) and prints the diff plus the re-anchored features for the agent to
4
+ // write into estimation-inputs.json. It scores nothing itself.
5
+ import { readFileSync, writeFileSync } from 'node:fs';
6
+ import { toCsv, fromCsv } from './lib/score-csv.mjs';
7
+ import { diffScores, applyDiff } from './lib/score-diff.mjs';
8
+ import { toHtml } from './lib/score-html.mjs';
9
+ import { loadGuide, guideTableHtml, SCORE_FACTORS } from './lib/scoring.mjs';
10
+
11
+ function parseArgs(argv) {
12
+ const args = {};
13
+ for (let i = 0; i < argv.length; i += 1) {
14
+ if (argv[i].startsWith('--')) args[argv[i].slice(2)] = argv[++i];
15
+ }
16
+ return args;
17
+ }
18
+
19
+ const templatePath = new URL('../assets/scores-review-template.html', import.meta.url).pathname;
20
+ const mathPath = new URL('./lib/estimate-math.mjs', import.meta.url).pathname;
21
+ const json = (path) => JSON.parse(readFileSync(path, 'utf8'));
22
+
23
+ function write(args) {
24
+ const draft = json(args.write);
25
+ const out = args.format === 'html'
26
+ ? toHtml({ draft, template: readFileSync(templatePath, 'utf8'), guideHtml: guideTableHtml(loadGuide()), mathSrc: readFileSync(mathPath, 'utf8') })
27
+ : toCsv(draft);
28
+ writeFileSync(args.out, out);
29
+ console.log(args.out);
30
+ }
31
+
32
+ function read(args) {
33
+ const draft = json(args.draft);
34
+ const edited = args.read.endsWith('.json') ? json(args.read) : fromCsv(readFileSync(args.read, 'utf8'));
35
+ const diff = diffScores(draft, edited);
36
+ const features = applyDiff({ draft, diff, guide: loadGuide() });
37
+ // Every changed score is a question the agent owes the reviewer ("what
38
+ // makes it a 4?"); the old cite is the evidence the answer argues against.
39
+ // A rewritten plain note is the reviewer's own words and needs no reason.
40
+ const needsReason = diff.filter((c) => SCORE_FACTORS.includes(c.field))
41
+ .map((c) => ({ ...c, oldCite: draft.features.find((f) => f.id === c.id).scores[c.field].cite }));
42
+ console.log(JSON.stringify({ diff, needsReason, features }, null, 2));
43
+ }
44
+
45
+ function usage() {
46
+ console.error('usage: score-review.mjs --write draft.json --format csv|html --out <file>\n score-review.mjs --read <csv|feedback.json> --draft draft.json');
47
+ process.exit(1);
48
+ }
49
+
50
+ // A missing --out or --draft would otherwise fail somewhere inside fs, and an
51
+ // unknown --format would silently write a CSV under the asked-for name.
52
+ const args = parseArgs(process.argv.slice(2));
53
+ if (args.write) {
54
+ if (!args.out || (args.format && !['csv', 'html'].includes(args.format))) usage();
55
+ write(args);
56
+ } else if (args.read) {
57
+ if (!args.draft) usage();
58
+ read(args);
59
+ } else usage();