@v11g/agents-rock 1.0.2 → 1.0.3

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 (52) hide show
  1. package/package.json +1 -1
  2. package/plugins/business-analyst/.claude-plugin/plugin.json +9 -0
  3. package/plugins/business-analyst/skills/business-analyst/README.md +20 -0
  4. package/plugins/business-analyst/skills/business-analyst/SKILL.md +69 -0
  5. package/plugins/business-analyst/skills/business-analyst/references/ai-extension.md +37 -0
  6. package/plugins/business-analyst/skills/business-analyst/references/frameworks.md +53 -0
  7. package/plugins/business-analyst/skills/business-analyst/references/interview.md +89 -0
  8. package/plugins/business-analyst/skills/business-analyst/references/review.md +25 -0
  9. package/plugins/business-analyst/skills/business-analyst/references/writing.md +102 -0
  10. package/plugins/business-analyst/skills/business-analyst/scripts/lib/checks.mjs +166 -0
  11. package/plugins/business-analyst/skills/business-analyst/scripts/lib/schema.mjs +78 -0
  12. package/plugins/business-analyst/skills/business-analyst/scripts/test/checks.test.mjs +188 -0
  13. package/plugins/business-analyst/skills/business-analyst/scripts/test/e2e.test.mjs +17 -0
  14. package/plugins/business-analyst/skills/business-analyst/scripts/test/fixtures/requirements-fail.json +205 -0
  15. package/plugins/business-analyst/skills/business-analyst/scripts/test/fixtures/requirements-pass.json +59 -0
  16. package/plugins/business-analyst/skills/business-analyst/scripts/test/fixtures/requirements-pass.md +63 -0
  17. package/plugins/business-analyst/skills/business-analyst/scripts/test/schema.test.mjs +41 -0
  18. package/plugins/business-analyst/skills/business-analyst/scripts/validate.mjs +20 -0
  19. package/plugins/solution-architect/skills/estimate/SKILL.md +13 -5
  20. package/plugins/solution-architect/skills/estimate/assets/estimate-template-agentic.html +917 -0
  21. package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +430 -13
  22. package/plugins/solution-architect/skills/estimate/references/agentic-estimation.md +148 -0
  23. package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +10 -0
  24. package/plugins/solution-architect/skills/estimate/references/interview.md +20 -1
  25. package/plugins/solution-architect/skills/estimate/references/task-shapes.md +173 -0
  26. package/plugins/solution-architect/skills/estimate/references/writing.md +31 -0
  27. package/plugins/solution-architect/skills/estimate/scripts/compute.mjs +5 -1
  28. package/plugins/solution-architect/skills/estimate/scripts/lib/agentic-checks.mjs +65 -0
  29. package/plugins/solution-architect/skills/estimate/scripts/lib/baselines.mjs +107 -0
  30. package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +16 -7
  31. package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +14 -0
  32. package/plugins/solution-architect/skills/estimate/scripts/lib/measurements.mjs +59 -0
  33. package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +28 -5
  34. package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +53 -22
  35. package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +52 -7
  36. package/plugins/solution-architect/skills/estimate/scripts/render.mjs +14 -3
  37. package/plugins/solution-architect/skills/estimate/scripts/test/baselines.test.mjs +120 -0
  38. package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +69 -0
  39. package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +44 -0
  40. package/plugins/solution-architect/skills/estimate/scripts/test/e2e.test.mjs +28 -1
  41. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-estimation-fail.md +55 -0
  42. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-estimation-pass.md +54 -0
  43. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-inputs.json +45 -0
  44. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/measurements.jsonl +20 -0
  45. package/plugins/solution-architect/skills/estimate/scripts/test/measurements.test.mjs +54 -0
  46. package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +25 -1
  47. package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +48 -1
  48. package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +59 -0
  49. package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +37 -0
  50. package/plugins/solution-architect/skills/estimate/scripts/test/xlsx-export.test.mjs +168 -0
  51. package/plugins/solution-architect/skills/estimate/scripts/test/zip.mjs +41 -0
  52. package/plugins/solution-architect/skills/new-lead/SKILL.md +15 -10
@@ -8,3 +8,17 @@ export function inlineModule(src) {
8
8
  export function stripInternal(html) {
9
9
  return html.replaceAll(/<!-- internal:start -->[\s\S]*?<!-- internal:end -->/g, '');
10
10
  }
11
+
12
+ // The agentic what-if rail only needs a handful of the math module's
13
+ // exports (team/plan capacity and cost, not the AI-category/PERT machinery
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.
18
+ export function extractExports(src, names) {
19
+ const starts = [...src.matchAll(/^export (?:const|function) (\w+)/gm)];
20
+ return starts
21
+ .map((m, i) => src.slice(m.index, starts[i + 1]?.index ?? src.length).trimEnd())
22
+ .filter((block, i) => names.includes(starts[i][1]))
23
+ .join('\n\n');
24
+ }
@@ -0,0 +1,59 @@
1
+ // The measurements.jsonl data contract — the one module that knows what a
2
+ // measurement record looks like. The estimate skill reads through here; the
3
+ // future record-task skill will write through here. Append-only by design:
4
+ // nothing in this module mutates the file.
5
+ import { readFileSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ import { homedir } from 'node:os';
8
+
9
+ export const TASK_SHAPES = [
10
+ 'scaffold', 'small_implementation', 'cross_file_refactor', 'test_creation',
11
+ 'bug_fix', 'configuration', 'api_integration', 'database_change',
12
+ 'documentation', 'ui_implementation', 'migration', 'investigation', 'planning',
13
+ ];
14
+
15
+ export const DEFAULT_MEASUREMENTS_PATH = '~/.agents-rock/measurements.jsonl';
16
+
17
+ export function expandHome(path) {
18
+ return path.startsWith('~/') ? join(homedir(), path.slice(2)) : path;
19
+ }
20
+
21
+ export function resolveMeasurementsPath(inputs) {
22
+ return expandHome(inputs.measurementsPath ?? DEFAULT_MEASUREMENTS_PATH);
23
+ }
24
+
25
+ // Unknown shapes are warnings, not errors: the taxonomy is extensible and a
26
+ // record written under a future shape must not be silently discarded.
27
+ export function checkMeasurement(rec) {
28
+ const errors = [];
29
+ const warnings = [];
30
+ for (const key of ['task_shape', 'repository', 'agent', 'model']) {
31
+ if (!(typeof rec[key] === 'string' && rec[key].trim())) errors.push(`${key} must be a non-empty string`);
32
+ }
33
+ if (!(typeof rec.actual_minutes === 'number' && rec.actual_minutes > 0)) {
34
+ errors.push('actual_minutes must be a positive number');
35
+ }
36
+ if (typeof rec.task_shape === 'string' && rec.task_shape.trim() && !TASK_SHAPES.includes(rec.task_shape)) {
37
+ warnings.push(`unknown task_shape "${rec.task_shape}" (kept)`);
38
+ }
39
+ return { errors, warnings };
40
+ }
41
+
42
+ function parseLine(line, lineNo, out) {
43
+ let rec;
44
+ try { rec = JSON.parse(line); } catch { out.warnings.push(`line ${lineNo}: unparseable JSON, skipped`); return; }
45
+ const { errors, warnings } = checkMeasurement(rec);
46
+ if (errors.length) { out.warnings.push(`line ${lineNo}: ${errors.join('; ')} — skipped`); return; }
47
+ out.warnings.push(...warnings.map((w) => `line ${lineNo}: ${w}`));
48
+ out.records.push(rec);
49
+ }
50
+
51
+ // A missing file is the cold-start case, not an error: zero records means
52
+ // every estimate renders Uncalibrated, which is the designed behavior.
53
+ export function loadMeasurements(path) {
54
+ let text;
55
+ try { text = readFileSync(path, 'utf8'); } catch { return { records: [], warnings: [] }; }
56
+ const out = { records: [], warnings: [] };
57
+ text.split('\n').forEach((line, i) => { if (line.trim()) parseLine(line, i + 1, out); });
58
+ return out;
59
+ }
@@ -3,6 +3,14 @@
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.
6
+ //
7
+ // Agentic-only fields are stripped unconditionally (not gated on
8
+ // exposeRatesToClient, which is a pricing-transparency opt-out, not a
9
+ // privacy one): the local measurements dataset path (absolute, carries the
10
+ // operator's username), the operator's repository name, and evidence task
11
+ // descriptions (the global measurements store can carry other projects'
12
+ // task descriptions). These fields don't exist in team-mode estimations, so
13
+ // team-mode output is unaffected.
6
14
  function redactScenarioTeam(team) {
7
15
  return team.map(({ rate, ...rest }) => rest);
8
16
  }
@@ -14,17 +22,32 @@ function redactComputedScenarios(scenarios) {
14
22
  }));
15
23
  }
16
24
 
25
+ function redactAgenticInputs({ measurementsPath, agentContext, ...rest }) {
26
+ if (!agentContext) return rest;
27
+ const { repository, ...clientAgentContext } = agentContext;
28
+ return { ...rest, agentContext: clientAgentContext };
29
+ }
30
+
31
+ function redactComputedTasks(tasks) {
32
+ return Object.fromEntries(Object.entries(tasks).map(([id, t]) => [
33
+ id,
34
+ t.evidence ? { ...t, evidence: t.evidence.map(({ description, ...rest }) => rest) } : t,
35
+ ]));
36
+ }
37
+
17
38
  export function redactForClient(estimation) {
18
- if (estimation.inputs.exposeRatesToClient) return estimation;
39
+ const inputs = redactAgenticInputs(estimation.inputs);
40
+ const computed = { ...estimation.computed, tasks: redactComputedTasks(estimation.computed.tasks) };
41
+ if (estimation.inputs.exposeRatesToClient) return { ...estimation, inputs, computed };
19
42
  return {
20
43
  ...estimation,
21
44
  inputs: {
22
- ...estimation.inputs,
23
- scenarios: estimation.inputs.scenarios.map((s) => ({ ...s, team: redactScenarioTeam(s.team) })),
45
+ ...inputs,
46
+ scenarios: inputs.scenarios.map((s) => ({ ...s, team: redactScenarioTeam(s.team) })),
24
47
  },
25
48
  computed: {
26
- ...estimation.computed,
27
- scenarios: redactComputedScenarios(estimation.computed.scenarios),
49
+ ...computed,
50
+ scenarios: redactComputedScenarios(computed.scenarios),
28
51
  },
29
52
  };
30
53
  }
@@ -6,6 +6,7 @@ import {
6
6
  } from './estimate-math.mjs';
7
7
  import { roadmapFor } from './roadmap.mjs';
8
8
  import { componentHoursFor } from './components.mjs';
9
+ import { agenticTask } from './baselines.mjs';
9
10
 
10
11
  function sortedMap(entries) {
11
12
  return Object.fromEntries(entries.sort(([a], [b]) => a.localeCompare(b)));
@@ -17,13 +18,12 @@ export function round2(n) {
17
18
 
18
19
  export function taskHoursFor(scenario, tasks) {
19
20
  const seniority = dominantSeniority(scenario.team);
20
- const entries = Object.keys(tasks).map((id) => [
21
- id,
22
- taskHours({
21
+ const entries = Object.keys(tasks).map((id) => [id, tasks[id].evidence !== undefined
22
+ ? tasks[id].e
23
+ : taskHours({
23
24
  e: tasks[id].e, seniority, plan: scenario.plan,
24
25
  category: tasks[id].category, verificationPct: tasks[id].verificationPct,
25
- }),
26
- ]);
26
+ })]);
27
27
  return sortedMap(entries);
28
28
  }
29
29
 
@@ -49,7 +49,7 @@ export function scenarioBlock(scenario, ctx) {
49
49
  };
50
50
  }
51
51
 
52
- const CONFIDENCE_RANK = { HIGH: 0, MED: 1, LOW: 2 };
52
+ const CONFIDENCE_RANK = { HIGH: 0, MED: 1, LOW: 2, UNCALIBRATED: 3 };
53
53
 
54
54
  export function criticalConfidence(features, tasks) {
55
55
  let critical = null;
@@ -78,14 +78,27 @@ function buildTasks(inputs) {
78
78
  return tasks;
79
79
  }
80
80
 
81
+ function buildAgenticTasks(inputs, measurements) {
82
+ const agentContext = { ...inputs.agentContext, repository: inputs.agentContext.repository ?? inputs.project };
83
+ const ctx = { records: measurements ?? [], agentContext };
84
+ const tasks = {};
85
+ for (const feature of inputs.features) {
86
+ for (const task of feature.tasks) {
87
+ const a = agenticTask(task, ctx);
88
+ tasks[task.id] = { ...a, o: a.lowH, p: a.highH };
89
+ }
90
+ }
91
+ return tasks;
92
+ }
93
+
81
94
  function buildFeatures(inputs, tasks) {
82
95
  const features = {};
83
96
  const summaries = [];
84
97
  for (const feature of inputs.features) {
85
98
  const taskIds = feature.tasks.map((t) => t.id);
86
99
  const hours = taskIds.reduce((sum, id) => sum + tasks[id].e, 0);
87
- const low = feature.tasks.reduce((sum, t) => sum + t.o, 0);
88
- const high = feature.tasks.reduce((sum, t) => sum + t.p, 0);
100
+ const low = taskIds.reduce((sum, id) => sum + tasks[id].o, 0);
101
+ const high = taskIds.reduce((sum, id) => sum + tasks[id].p, 0);
89
102
  features[feature.id] = { hours: round2(hours), low: round2(low), high: round2(high) };
90
103
  summaries.push({ hours, taskIds });
91
104
  }
@@ -98,25 +111,43 @@ function globalBuffers(tasks, risks) {
98
111
  return { devHours, spreadBufferHours, riskBufferHours: riskBufferHours(risks) };
99
112
  }
100
113
 
101
- export function computeEstimation(inputs) {
102
- const tasks = buildTasks(inputs);
114
+ const isAgentic = (inputs) => inputs.deliveryMode === 'agentic';
115
+
116
+ const normalizeRisks = (inputs) => (isAgentic(inputs)
117
+ ? inputs.risks.map((r) => ({ ...r, impactHours: r.impactMinutes / 60 }))
118
+ : inputs.risks);
119
+
120
+ const taskSummary = (t) => (t.evidence !== undefined
121
+ ? {
122
+ e: round2(t.e), sigma: round2(t.sigma), minutes: t.minutes, samples: t.samples,
123
+ matchLevel: t.matchLevel, confidence: t.confidence, calibrated: t.calibrated, evidence: t.evidence,
124
+ }
125
+ : { e: round2(t.e), sigma: round2(t.sigma) });
126
+
127
+ const computedBlock = (ctx) => ({
128
+ tasks: sortedMap(Object.entries(ctx.tasks).map(([id, t]) => [id, taskSummary(t)])),
129
+ features: ctx.features,
130
+ ...(ctx.components ? { components: ctx.components } : {}),
131
+ devHours: round2(ctx.buffers.devHours),
132
+ overheadHours: round2(ctx.buffers.devHours * ctx.overheadPct),
133
+ spreadBufferHours: round2(ctx.buffers.spreadBufferHours),
134
+ riskBufferHours: round2(ctx.buffers.riskBufferHours),
135
+ scenarios: ctx.scenarios,
136
+ projectConfidence: criticalConfidence(ctx.summaries, ctx.tasks),
137
+ });
138
+
139
+ export function computeEstimation(inputs, measurements) {
140
+ const risks = normalizeRisks(inputs);
141
+ const tasks = isAgentic(inputs) ? buildAgenticTasks(inputs, measurements) : buildTasks(inputs);
103
142
  const { features, summaries } = buildFeatures(inputs, tasks);
104
- const buffers = globalBuffers(tasks, inputs.risks);
143
+ const buffers = globalBuffers(tasks, risks);
105
144
  const ctx = { tasks, features: inputs.features, overheadPct: inputs.overheadPct, ...buffers };
106
145
  const scenarios = sortedMap(inputs.scenarios.map((s) => [s.id, scenarioBlock(s, ctx)]));
107
146
  const components = componentHoursFor(inputs, features);
108
147
  return {
109
148
  inputs,
110
- computed: {
111
- tasks: sortedMap(Object.entries(tasks).map(([id, t]) => [id, { e: round2(t.e), sigma: round2(t.sigma) }])),
112
- features,
113
- ...(components ? { components } : {}),
114
- devHours: round2(buffers.devHours),
115
- overheadHours: round2(buffers.devHours * inputs.overheadPct),
116
- spreadBufferHours: round2(buffers.spreadBufferHours),
117
- riskBufferHours: round2(buffers.riskBufferHours),
118
- scenarios,
119
- projectConfidence: criticalConfidence(summaries, tasks),
120
- },
149
+ computed: computedBlock({
150
+ tasks, features, components, buffers, overheadPct: inputs.overheadPct, scenarios, summaries,
151
+ }),
121
152
  };
122
153
  }
@@ -2,10 +2,34 @@
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
4
  import { AI_CATEGORIES, SENIORITY_FACTOR, PLAN_PRICES } from './estimate-math.mjs';
5
+ import { TASK_SHAPES } from './measurements.mjs';
5
6
 
6
7
  const PROVENANCE = ['observed', 'stated', 'researched', 'proposed'];
7
8
  const CONFIDENCE = ['HIGH', 'MED', 'LOW'];
9
+ const DELIVERY_MODES = ['traditional', 'agentic'];
8
10
  const pct = (v) => typeof v === 'number' && v >= 0 && v < 1;
11
+ const isAgentic = (inputs) => inputs.deliveryMode === 'agentic';
12
+
13
+ // Durations and confidence are script-owned in agentic mode: their absence
14
+ // from inputs is the structural guarantee the agent never invents them.
15
+ const AGENTIC_BANNED = ['category', 'confidence', 'o', 'm', 'p'];
16
+
17
+ function checkAgenticTask(task, out) {
18
+ if (!TASK_SHAPES.includes(task.shape)) out.push(`task ${task.id}: unknown shape "${task.shape}"`);
19
+ const s = task.seedMinutes ?? {};
20
+ if (!['o', 'm', 'p'].every((k) => typeof s[k] === 'number' && s[k] > 0)) {
21
+ out.push(`task ${task.id}: seedMinutes o, m, p must be positive numbers`);
22
+ } else if (!(s.o <= s.m && s.m <= s.p)) out.push(`task ${task.id}: seedMinutes expected o <= m <= p`);
23
+ if (typeof task.scope !== 'object' || task.scope === null) out.push(`task ${task.id}: scope object is required`);
24
+ for (const key of AGENTIC_BANNED) {
25
+ if (Object.hasOwn(task, key)) out.push(`task ${task.id}: "${key}" is not an agentic input — the script computes it`);
26
+ }
27
+ if (task.model !== undefined && !(typeof task.model === 'string' && task.model.trim())) {
28
+ out.push(`task ${task.id}: model must be a non-empty string`);
29
+ }
30
+ if (!Array.isArray(task.assumptions)) out.push(`task ${task.id}: assumptions array is required`);
31
+ if (!PROVENANCE.includes(task.provenance)) out.push(`task ${task.id}: provenance not in vocabulary`);
32
+ }
9
33
 
10
34
  function checkTask(task, out) {
11
35
  if (!['o', 'm', 'p'].every((k) => typeof task[k] === 'number')) out.push(`task ${task.id}: o, m, p must be numbers`);
@@ -19,14 +43,14 @@ function checkTask(task, out) {
19
43
  if (!PROVENANCE.includes(task.provenance)) out.push(`task ${task.id}: provenance not in vocabulary`);
20
44
  }
21
45
 
22
- function checkFeature(feature, out) {
46
+ function checkFeature(feature, out, agentic) {
23
47
  // Scope items are the clear-vs-assumed split itself: only stated|proposed.
24
48
  // (Task rows keep the full four-word vocabulary for their src column.)
25
49
  if (!['stated', 'proposed'].includes(feature.provenance)) {
26
50
  out.push(`feature ${feature.id}: scope provenance must be stated|proposed`);
27
51
  }
28
52
  if (!(feature.tasks?.length > 0)) out.push(`feature ${feature.id}: must have at least one task`);
29
- for (const task of feature.tasks ?? []) checkTask(task, out);
53
+ for (const task of feature.tasks ?? []) (agentic ? checkAgenticTask(task, out) : checkTask(task, out));
30
54
  }
31
55
 
32
56
  // Roadmap is all-or-nothing: a half-labeled feature list would render a
@@ -105,24 +129,45 @@ function checkScenarios(inputs, out) {
105
129
 
106
130
  // Anything compute.mjs would turn into NaN gets refused here instead: the
107
131
  // "computed truth" contract holds only if every operand is a sane number.
108
- function checkGlobals(inputs, out) {
132
+ // Risks carry hours in team mode and minutes in agentic mode — the unit the
133
+ // rest of that mode's math already runs on. `agentContext.repository` is
134
+ // optional (rollup.mjs falls back to `project`) but must be a real value
135
+ // when set — rung 1 of the retrieval ladder needs it to mean something.
136
+ function checkGlobals(inputs, out, agentic) {
109
137
  if (!pct(inputs.overheadPct)) out.push('overheadPct must be a number in [0, 1)');
110
- if (!pct(inputs.verificationPct)) out.push('verificationPct must be a number in [0, 1)');
138
+ if (!agentic && !pct(inputs.verificationPct)) out.push('verificationPct must be a number in [0, 1)');
139
+ const ctx = inputs.agentContext;
140
+ if (agentic && typeof ctx === 'object' && ctx !== null && 'repository' in ctx
141
+ && !(typeof ctx.repository === 'string' && ctx.repository.trim())) {
142
+ out.push('agentContext.repository must be a non-empty string when present');
143
+ }
111
144
  for (const r of inputs.risks ?? []) {
112
145
  if (!(typeof r.probability === 'number' && r.probability >= 0 && r.probability <= 1)) out.push(`risk "${r.name}": probability must be in [0, 1]`);
113
- if (!(typeof r.impactHours === 'number' && r.impactHours > 0)) out.push(`risk "${r.name}": impactHours must be positive`);
146
+ if (agentic) {
147
+ if (!(typeof r.impactMinutes === 'number' && r.impactMinutes > 0)) out.push(`risk "${r.name}": impactMinutes must be positive`);
148
+ if (!(typeof r.reason === 'string' && r.reason.trim())) out.push(`risk "${r.name}": reason is required`);
149
+ } else if (!(typeof r.impactHours === 'number' && r.impactHours > 0)) out.push(`risk "${r.name}": impactHours must be positive`);
114
150
  }
115
151
  }
116
152
 
117
153
  export function checkInputs(inputs) {
118
154
  const out = [];
155
+ const agentic = isAgentic(inputs);
156
+ if (inputs.deliveryMode !== undefined && !DELIVERY_MODES.includes(inputs.deliveryMode)) out.push('deliveryMode must be traditional|agentic');
119
157
  for (const key of ['project', 'technique', 'features', 'risks', 'assumptions', 'scenarios']) {
120
158
  if (!(key in inputs)) out.push(`missing top-level "${key}"`);
121
159
  }
122
- for (const feature of inputs.features ?? []) checkFeature(feature, out);
160
+ if (agentic) {
161
+ const ctx = inputs.agentContext;
162
+ if (typeof ctx !== 'object' || ctx === null) out.push('agentic mode requires top-level agentContext');
163
+ else for (const key of ['agent', 'model']) {
164
+ if (!(typeof ctx[key] === 'string' && ctx[key].trim())) out.push(`agentContext.${key} must be a non-empty string`);
165
+ }
166
+ }
167
+ for (const feature of inputs.features ?? []) checkFeature(feature, out, agentic);
123
168
  checkMilestones(inputs.features ?? [], out);
124
169
  checkComponents(inputs, out);
125
170
  checkScenarios(inputs, out);
126
- checkGlobals(inputs, out);
171
+ checkGlobals(inputs, out, agentic);
127
172
  return out;
128
173
  }
@@ -4,9 +4,17 @@ 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 } from './lib/inline.mjs';
7
+ import { inlineModule, stripInternal, extractExports } from './lib/inline.mjs';
8
8
  import { redactForClient } from './lib/redact.mjs';
9
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
+ ];
17
+
10
18
  function parseArgs(argv) {
11
19
  const args = {};
12
20
  for (let i = 0; i < argv.length; i += 1) {
@@ -22,11 +30,13 @@ function parseArgs(argv) {
22
30
 
23
31
  const archFontsDir = new URL('../../analyze-requirements/assets/fonts/', import.meta.url).pathname;
24
32
  const mathPath = new URL('./lib/estimate-math.mjs', import.meta.url).pathname;
25
- const templatePath = new URL('../assets/estimate-template.html', import.meta.url).pathname;
33
+ const assetsDir = new URL('../assets/', import.meta.url).pathname;
26
34
 
27
35
  const args = parseArgs(process.argv.slice(2));
28
36
  const estimation = JSON.parse(readFileSync(args.json, 'utf8'));
29
37
  const md = readFileSync(args.md, 'utf8');
38
+ const isAgentic = estimation.inputs.deliveryMode === 'agentic';
39
+ const templatePath = join(assetsDir, isAgentic ? 'estimate-template-agentic.html' : 'estimate-template.html');
30
40
 
31
41
  // Validation blocks rendering: this is the hard rule enforced in code, not
32
42
  // just in SKILL.md prose. No skip flag exists.
@@ -44,6 +54,7 @@ const viewerSlot = typeof args.viewer === 'string'
44
54
  ? `<a id="viewer-link" data-internal href="${escapeHtml(args.viewer)}">architecture docs</a>`
45
55
  : '';
46
56
  const template = readFileSync(templatePath, 'utf8');
57
+ const mathSrc = readFileSync(mathPath, 'utf8');
47
58
  const html = embed({
48
59
  template,
49
60
  slots: {
@@ -51,7 +62,7 @@ const html = embed({
51
62
  FONTS: buildFontFaces(archFontsDir),
52
63
  // Escaped so a literal </script in the JSON can't close the data tag early.
53
64
  DATA: JSON.stringify(dataForEmbed).replaceAll('</script', '<\\/script'),
54
- MATH: inlineModule(readFileSync(mathPath, 'utf8')),
65
+ MATH: inlineModule(isAgentic ? extractExports(mathSrc, AGENTIC_MATH_EXPORTS) : mathSrc),
55
66
  VIEWER: viewerSlot,
56
67
  },
57
68
  });
@@ -0,0 +1,120 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { loadMeasurements } from '../lib/measurements.mjs';
4
+ import { percentile, matchBaseline, confidenceFor } from '../lib/baselines.mjs';
5
+
6
+ const fixturePath = new URL('./fixtures/measurements.jsonl', import.meta.url).pathname;
7
+ const records = () => loadMeasurements(fixturePath).records;
8
+ const CTX = { agent: 'claude-code', model: 'sonnet', repository: 'project-a' };
9
+ const near = (a, b) => assert.ok(Math.abs(a - b) < 0.01, `${a} !~ ${b}`);
10
+
11
+ test('percentile interpolates linearly', () => {
12
+ const v = [6, 8, 9, 11, 12, 19, 34];
13
+ near(percentile(v, 0.5), 11);
14
+ near(percentile(v, 0.8), 17.6); // pos 4.8 → 12 + 0.8·(19−12)
15
+ near(percentile(v, 0.95), 29.5); // pos 5.7 → 19 + 0.7·(34−19)
16
+ });
17
+
18
+ test('rung 1: exact repo+agent+model match wins', () => {
19
+ const stats = matchBaseline(
20
+ { shape: 'cross_file_refactor', scope: { affectedFiles: 8 } },
21
+ { records: records(), agentContext: CTX },
22
+ );
23
+ assert.equal(stats.matchLevel, 1);
24
+ assert.equal(stats.samples, 7);
25
+ near(stats.p50, 11);
26
+ assert.equal(stats.evidence.length, 7);
27
+ assert.deepEqual(stats.evidence[0], { id: 'm01', description: 'Refactor A', minutes: 6 });
28
+ });
29
+
30
+ test('rung 2: different repo falls through to shape+agent', () => {
31
+ const stats = matchBaseline(
32
+ { shape: 'cross_file_refactor', scope: { affectedFiles: 8 } },
33
+ { records: records(), agentContext: { ...CTX, repository: 'other-repo' } },
34
+ );
35
+ assert.equal(stats.matchLevel, 2);
36
+ assert.equal(stats.samples, 7);
37
+ });
38
+
39
+ test('per-task model override matches its own history', () => {
40
+ const stats = matchBaseline(
41
+ { shape: 'planning', scope: {}, model: 'opus' },
42
+ { records: records(), agentContext: { agent: 'claude-code', model: 'sonnet', repository: 'project-b' } },
43
+ );
44
+ assert.equal(stats.samples, 2); // rung 4: only 2 planning records exist
45
+ assert.equal(stats.matchLevel, 4);
46
+ });
47
+
48
+ test('rung 3: similar scope (±50% affected files) when agent differs', () => {
49
+ const stats = matchBaseline(
50
+ { shape: 'configuration', scope: { affectedFiles: 1 } },
51
+ { records: [...records(), ...records(), ...records()].filter((r) => r.task_shape === 'configuration'),
52
+ agentContext: { agent: 'claude-code', model: 'sonnet', repository: 'project-a' } },
53
+ );
54
+ // 3 copies of the cursor config record: rung 2 fails (agent cursor), rung 3 matches on scope
55
+ assert.equal(stats.matchLevel, 3);
56
+ assert.equal(stats.samples, 3);
57
+ });
58
+
59
+ test('no match at any rung is UNCALIBRATED', () => {
60
+ const stats = matchBaseline(
61
+ { shape: 'database_change', scope: { affectedFiles: 2 } },
62
+ { records: records(), agentContext: CTX },
63
+ );
64
+ assert.deepEqual(stats, { samples: 0, matchLevel: 0, evidence: [] });
65
+ assert.equal(confidenceFor(stats), 'UNCALIBRATED');
66
+ });
67
+
68
+ test('confidence tiers follow the spec table', () => {
69
+ assert.equal(confidenceFor({ samples: 0 }), 'UNCALIBRATED');
70
+ assert.equal(confidenceFor({ samples: 2, p50: 10, p80: 11 }), 'LOW');
71
+ assert.equal(confidenceFor({ samples: 7, p50: 11, p80: 17.6 }), 'MED');
72
+ assert.equal(confidenceFor({ samples: 10, p50: 10, p80: 11.2 }), 'HIGH');
73
+ assert.equal(confidenceFor({ samples: 10, p50: 10, p80: 25 }), 'MED'); // high variance demotes
74
+ });
75
+
76
+ // Task 3 appends: duration math.
77
+ import { agenticTask } from '../lib/baselines.mjs';
78
+
79
+ test('n>=5: lognormal fit — mean above median, spread from log-space z', () => {
80
+ const a = agenticTask(
81
+ { shape: 'cross_file_refactor', scope: { affectedFiles: 8 }, seedMinutes: { o: 10, m: 20, p: 45 } },
82
+ { records: records(), agentContext: CTX },
83
+ );
84
+ // p50=11, p95=29.5 → σ_log=ln(29.5/11)/1.645≈0.5997
85
+ // e = 11·exp(σ_log²/2) ≈ 13.17 min; σ = e·√(exp(σ_log²)−1) ≈ 8.66 min
86
+ near(a.e, 13.17 / 60);
87
+ near(a.sigma, 8.66 / 60);
88
+ near(a.lowH, 11 / 60);
89
+ near(a.highH, 29.5 / 60);
90
+ assert.equal(a.calibrated, true);
91
+ assert.equal(a.confidence, 'MED');
92
+ near(a.minutes, 11);
93
+ });
94
+
95
+ test('1<=n<5: median of matches + seed-derived sigma', () => {
96
+ const a = agenticTask(
97
+ { shape: 'planning', scope: {}, model: 'opus', seedMinutes: { o: 20, m: 40, p: 80 } },
98
+ { records: records(), agentContext: { agent: 'claude-code', model: 'sonnet', repository: 'project-b' } },
99
+ );
100
+ near(a.e, 47.5 / 60); // median of [40, 55]
101
+ near(a.sigma, (80 - 20) / 6 / 60);
102
+ near(a.lowH, 40 / 60); // small samples: bounds are min/max of matches
103
+ near(a.highH, 55 / 60);
104
+ assert.equal(a.confidence, 'LOW');
105
+ assert.equal(a.calibrated, true);
106
+ });
107
+
108
+ test('n=0: seed pert, uncalibrated', () => {
109
+ const a = agenticTask(
110
+ { shape: 'database_change', scope: {}, seedMinutes: { o: 10, m: 20, p: 40 } },
111
+ { records: records(), agentContext: CTX },
112
+ );
113
+ near(a.e, ((10 + 80 + 40) / 6) / 60); // pert e = 21.67 min
114
+ near(a.sigma, (30 / 6) / 60);
115
+ near(a.lowH, 10 / 60);
116
+ near(a.highH, 40 / 60);
117
+ assert.equal(a.calibrated, false);
118
+ assert.equal(a.confidence, 'UNCALIBRATED');
119
+ assert.equal(a.minutes, null);
120
+ });
@@ -621,3 +621,72 @@ test('no milestones → the roadmap section is absent, no placeholder', skip, as
621
621
  assert.deepEqual(page.errors, []);
622
622
  } finally { page.close(); }
623
623
  });
624
+
625
+ // --- breakdown scoring mode: the workbook's five scores rendered in-page ---
626
+
627
+ const HEADS = `[...document.querySelectorAll('#feature-table th')].map((h) => h.textContent.trim())`;
628
+ const enterScoring = (page) => page.eval(`document.querySelector('#feature-table [data-mode="scores"]').click()`);
629
+
630
+ test('a columns pill swaps the breakdown to workbook scores and back', skip, async () => {
631
+ const page = await openPage(buildPage());
632
+ try {
633
+ assert.ok((await page.eval(HEADS)).includes('Range'), 'estimate columns by default');
634
+ await enterScoring(page);
635
+ const heads = await page.eval(HEADS);
636
+ for (const h of ['Tech', 'Size', 'Deps', 'Unc', 'Risk', 'Σ', 'Tier']) {
637
+ assert.ok(heads.includes(h), `scoring header ${h} missing: ${heads}`);
638
+ }
639
+ assert.ok(!heads.includes('Range'), 'estimate columns must swap out');
640
+ const booking = await page.eval(
641
+ `[...document.querySelectorAll('#feature-table tr.feat-row')[0].querySelectorAll('td.score')].map((c) => c.textContent.trim())`);
642
+ assert.deepEqual(booking, ['2', '4', '2', '4', '3', '15', 'M']);
643
+ await page.eval(`document.querySelector('#feature-table [data-mode="estimate"]').click()`);
644
+ assert.ok((await page.eval(HEADS)).includes('Range'), 'estimate pill must swap back');
645
+ assert.deepEqual(page.errors, []);
646
+ } finally { page.close(); }
647
+ });
648
+
649
+ test('scoring-mode task rows show each task\'s input to every score', skip, async () => {
650
+ const page = await openPage(buildPage());
651
+ try {
652
+ await enterScoring(page);
653
+ await page.eval(`document.querySelector('#feature-table tr.feat-row .expand').click()`);
654
+ const rows = await page.eval(
655
+ `[...document.querySelectorAll('#feature-table tr.task-row')].map((r) => r.textContent.replace(/\\s+/g, ' ').trim())`);
656
+ assert.equal(rows.length, 2);
657
+ assert.match(rows[0], /boilerplate ×1\.5/);
658
+ assert.match(rows[0], /25\.3h/);
659
+ assert.match(rows[1], /logic ×3/);
660
+ assert.match(rows[1], /44(\.0)?h/);
661
+ } finally { page.close(); }
662
+ });
663
+
664
+ test('the scoring guide fold explains the anchors in the workbook\'s words', skip, async () => {
665
+ const page = await openPage(buildPage());
666
+ try {
667
+ assert.equal(await page.eval(`document.querySelector('#feature-table details.guide')`), null,
668
+ 'no guide fold in estimate mode');
669
+ await enterScoring(page);
670
+ assert.ok(await page.eval(`document.querySelector('#feature-table details.guide').open`),
671
+ 'guide must open on first switch');
672
+ const text = await page.eval(`document.querySelector('#feature-table details.guide').textContent`);
673
+ for (const anchor of ['Standard CRUD, well-documented library usage',
674
+ 'Epic-scale feature', 'Deep cross-system dependencies', 'Highly experimental',
675
+ 'Core infrastructure, compliance requirements']) {
676
+ assert.ok(text.includes(anchor), `guide missing workbook anchor: ${anchor}`);
677
+ }
678
+ assert.match(text, /hours-weighted/); // each dimension states its derivation
679
+ } finally { page.close(); }
680
+ });
681
+
682
+ test('scoring mode is internal-only: client view resets and hides the pill', skip, async () => {
683
+ const page = await openPage(buildPage());
684
+ try {
685
+ await enterScoring(page);
686
+ await page.eval(`document.getElementById('view-toggle').click()`);
687
+ assert.ok((await page.eval(HEADS)).includes('Range'), 'client view must reset to estimate columns');
688
+ assert.equal(await page.eval(
689
+ `getComputedStyle(document.querySelector('#feature-table [data-mode="scores"]').closest('.bd-filter-group')).display`),
690
+ 'none');
691
+ } finally { page.close(); }
692
+ });
@@ -86,3 +86,47 @@ test('no milestones → no roadmap key at all', () => {
86
86
  assert.ok(!('roadmap' in s), 'roadmap key must be absent, not empty');
87
87
  }
88
88
  });
89
+
90
+ // Agentic-mode rollup.
91
+ import { loadMeasurements } from '../lib/measurements.mjs';
92
+
93
+ const agenticInputsPath = new URL('./fixtures/agentic-inputs.json', import.meta.url).pathname;
94
+ const measurementsFixture = new URL('./fixtures/measurements.jsonl', import.meta.url).pathname;
95
+ function agenticInputs() {
96
+ const inputs = JSON.parse(readFileSync(agenticInputsPath, 'utf8'));
97
+ inputs.measurementsPath = measurementsFixture;
98
+ return inputs;
99
+ }
100
+ const measurements = () => loadMeasurements(measurementsFixture).records;
101
+
102
+ test('agentic tasks are baseline-driven and scenario-independent', () => {
103
+ const { computed } = computeEstimation(agenticInputs(), measurements());
104
+ const swap = computed.tasks['swap-refactor'];
105
+ assert.equal(swap.samples, 7);
106
+ assert.equal(swap.matchLevel, 1);
107
+ assert.equal(swap.confidence, 'MED');
108
+ assert.equal(swap.calibrated, true);
109
+ assert.equal(swap.minutes, 11);
110
+ assert.ok(Math.abs(swap.e - 13.17 / 60) < 0.01);
111
+ const db = computed.tasks['swap-db'];
112
+ assert.equal(db.confidence, 'UNCALIBRATED');
113
+ assert.equal(db.calibrated, false);
114
+ // measured durations do not vary by team or plan
115
+ assert.deepEqual(computed.scenarios.solo.taskHours, computed.scenarios.pair.taskHours);
116
+ });
117
+
118
+ test('agentic risks convert minutes to hours; uncalibrated task taints project confidence', () => {
119
+ const { computed } = computeEstimation(agenticInputs(), measurements());
120
+ assert.equal(computed.riskBufferHours, Math.round((0.3 * 30 / 60) * 100) / 100);
121
+ assert.equal(computed.projectConfidence, 'UNCALIBRATED'); // swap-db sits on the largest feature
122
+ });
123
+
124
+ test('compute.mjs CLI resolves measurementsPath itself', () => {
125
+ const dir = mkdtempSync(join(tmpdir(), 'agentic-'));
126
+ const inPath = join(dir, 'inputs.json');
127
+ const outPath = join(dir, 'estimation.json');
128
+ writeFileSync(inPath, JSON.stringify(agenticInputs()));
129
+ execFileSync('node', [cli, '--inputs', inPath, '--out', outPath]);
130
+ const estimation = JSON.parse(readFileSync(outPath, 'utf8'));
131
+ assert.equal(estimation.computed.tasks['swap-refactor'].samples, 7);
132
+ });