@v11g/agents-rock 1.0.2 → 1.0.4

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 (65) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/plugins/business-analyst/.claude-plugin/plugin.json +9 -0
  4. package/plugins/business-analyst/skills/business-analyst/README.md +23 -0
  5. package/plugins/business-analyst/skills/business-analyst/SKILL.md +73 -0
  6. package/plugins/business-analyst/skills/business-analyst/references/ai-extension.md +37 -0
  7. package/plugins/business-analyst/skills/business-analyst/references/frameworks.md +53 -0
  8. package/plugins/business-analyst/skills/business-analyst/references/interview.md +89 -0
  9. package/plugins/business-analyst/skills/business-analyst/references/review.md +25 -0
  10. package/plugins/business-analyst/skills/business-analyst/references/writing.md +102 -0
  11. package/plugins/business-analyst/skills/business-analyst/scripts/lib/checks.mjs +166 -0
  12. package/plugins/business-analyst/skills/business-analyst/scripts/lib/schema.mjs +78 -0
  13. package/plugins/business-analyst/skills/business-analyst/scripts/test/checks.test.mjs +188 -0
  14. package/plugins/business-analyst/skills/business-analyst/scripts/test/e2e.test.mjs +17 -0
  15. package/plugins/business-analyst/skills/business-analyst/scripts/test/fixtures/requirements-fail.json +205 -0
  16. package/plugins/business-analyst/skills/business-analyst/scripts/test/fixtures/requirements-pass.json +59 -0
  17. package/plugins/business-analyst/skills/business-analyst/scripts/test/fixtures/requirements-pass.md +63 -0
  18. package/plugins/business-analyst/skills/business-analyst/scripts/test/python-parity.test.mjs +50 -0
  19. package/plugins/business-analyst/skills/business-analyst/scripts/test/schema.test.mjs +41 -0
  20. package/plugins/business-analyst/skills/business-analyst/scripts/validate.mjs +20 -0
  21. package/plugins/business-analyst/skills/business-analyst/scripts/validate.py +288 -0
  22. package/plugins/solution-architect/.claude-plugin/plugin.json +1 -1
  23. package/plugins/solution-architect/skills/analyze-requirements/assets/viewer-template.html +4 -2
  24. package/plugins/solution-architect/skills/analyze-requirements/scripts/lib/chrome.mjs +4 -1
  25. package/plugins/solution-architect/skills/analyze-requirements/scripts/test/viewer-template.test.mjs +3 -2
  26. package/plugins/solution-architect/skills/estimate/SKILL.md +13 -5
  27. package/plugins/solution-architect/skills/estimate/assets/estimate-template-agentic.html +917 -0
  28. package/plugins/solution-architect/skills/estimate/assets/estimate-template.html +430 -13
  29. package/plugins/solution-architect/skills/estimate/references/agentic-estimation.md +148 -0
  30. package/plugins/solution-architect/skills/estimate/references/ai-multipliers.md +10 -0
  31. package/plugins/solution-architect/skills/estimate/references/interview.md +20 -1
  32. package/plugins/solution-architect/skills/estimate/references/task-shapes.md +173 -0
  33. package/plugins/solution-architect/skills/estimate/references/writing.md +31 -0
  34. package/plugins/solution-architect/skills/estimate/scripts/compute.mjs +5 -1
  35. package/plugins/solution-architect/skills/estimate/scripts/lib/agentic-checks.mjs +65 -0
  36. package/plugins/solution-architect/skills/estimate/scripts/lib/baselines.mjs +107 -0
  37. package/plugins/solution-architect/skills/estimate/scripts/lib/checks.mjs +16 -7
  38. package/plugins/solution-architect/skills/estimate/scripts/lib/inline.mjs +14 -0
  39. package/plugins/solution-architect/skills/estimate/scripts/lib/measurements.mjs +59 -0
  40. package/plugins/solution-architect/skills/estimate/scripts/lib/redact.mjs +28 -5
  41. package/plugins/solution-architect/skills/estimate/scripts/lib/rollup.mjs +53 -22
  42. package/plugins/solution-architect/skills/estimate/scripts/lib/schema.mjs +52 -7
  43. package/plugins/solution-architect/skills/estimate/scripts/render.mjs +14 -3
  44. package/plugins/solution-architect/skills/estimate/scripts/test/baselines.test.mjs +120 -0
  45. package/plugins/solution-architect/skills/estimate/scripts/test/browser.test.mjs +69 -0
  46. package/plugins/solution-architect/skills/estimate/scripts/test/compute.test.mjs +44 -0
  47. package/plugins/solution-architect/skills/estimate/scripts/test/e2e.test.mjs +28 -1
  48. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-estimation-fail.md +55 -0
  49. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-estimation-pass.md +54 -0
  50. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/agentic-inputs.json +45 -0
  51. package/plugins/solution-architect/skills/estimate/scripts/test/fixtures/measurements.jsonl +20 -0
  52. package/plugins/solution-architect/skills/estimate/scripts/test/measurements.test.mjs +54 -0
  53. package/plugins/solution-architect/skills/estimate/scripts/test/references.test.mjs +25 -1
  54. package/plugins/solution-architect/skills/estimate/scripts/test/render.test.mjs +48 -1
  55. package/plugins/solution-architect/skills/estimate/scripts/test/schema.test.mjs +59 -0
  56. package/plugins/solution-architect/skills/estimate/scripts/test/validate.test.mjs +37 -0
  57. package/plugins/solution-architect/skills/estimate/scripts/test/xlsx-export.test.mjs +168 -0
  58. package/plugins/solution-architect/skills/estimate/scripts/test/zip.mjs +41 -0
  59. package/plugins/solution-architect/skills/new-lead/SKILL.md +15 -10
  60. package/plugins/solution-architect/skills/new-lead/assets/dashboard/detail.html +25 -50
  61. package/plugins/solution-architect/skills/new-lead/assets/dashboard/index.html +20 -40
  62. package/plugins/solution-architect/skills/new-lead/scripts/lib/map-nodes.mjs +12 -4
  63. package/plugins/solution-architect/skills/new-lead/scripts/serve.mjs +8 -3
  64. package/plugins/solution-architect/skills/new-lead/scripts/test/map.test.mjs +4 -0
  65. package/plugins/solution-architect/skills/new-lead/scripts/test/serve.test.mjs +25 -21
@@ -0,0 +1,148 @@
1
+ # Agentic estimation — measurement-based, not multiplier-based
2
+
3
+ Read once the interview's delivery-mode question (`references/interview.md`
4
+ §2b) returns AGENTIC. Defines the whole measurement-based pipeline: where the
5
+ data lives, how a task's baseline is found, how the math turns a baseline
6
+ into an estimate, what decomposition the deliverable requires, and how
7
+ confidence is labeled. This doc describes what `lib/baselines.mjs`,
8
+ `lib/measurements.mjs`, and `lib/agentic-checks.mjs` actually compute — never
9
+ re-derive this arithmetic by hand or in prose; call the code.
10
+
11
+ ## 1. When
12
+
13
+ `deliveryMode: "agentic"` in `estimation-inputs.json` means AI coding agents
14
+ write the code and humans plan and review. In this mode, measurement-based
15
+ estimation **replaces the technique menu entirely** — there is no factor
16
+ scoring, no three-point PERT judgment, no AI-category assignment
17
+ (`references/techniques.md` and `references/ai-multipliers.md`'s category
18
+ table do not apply). Every task instead gets a `shape`
19
+ (`references/task-shapes.md`), a `scope`, and `seedMinutes`; the script does
20
+ the rest.
21
+
22
+ ## 2. Dataset
23
+
24
+ Historical execution data lives in one global, append-only file:
25
+ `~/.agents-rock/measurements.jsonl` (`DEFAULT_MEASUREMENTS_PATH` in
26
+ `lib/measurements.mjs`). One JSON object per completed task, written by the
27
+ (deferred) `record-task` skill. `estimation-inputs.json` may override the
28
+ path via top-level `measurementsPath` (used by tests, and by any project
29
+ that wants a scoped dataset).
30
+
31
+ Each measurement record carries a `repository` field. `agentContext.repository`
32
+ in `estimation-inputs.json` (optional, validated non-empty when set by
33
+ `lib/schema.mjs`) tells the ladder which repository's history this estimate
34
+ targets; when absent, `lib/rollup.mjs` falls back to the top-level `project`
35
+ name. Set it explicitly whenever the project's repo name differs from
36
+ `project` — rung 1 of the ladder (below) can only match on `repository` when
37
+ it means the same string on both sides.
38
+
39
+ A missing file is the cold-start case, not an error: every task renders
40
+ UNCALIBRATED and the estimate still produces a full deliverable — this is
41
+ designed behavior, not a degraded mode. Corrupt lines are skipped with a
42
+ warning, never fatal.
43
+
44
+ ## 3. Ladder
45
+
46
+ Per task, filter measurements to matching `task_shape`, then walk rungs
47
+ top-down and stop at the first rung with enough samples:
48
+
49
+ ```text
50
+ 1. shape + repository + agent + model (>= 3 samples)
51
+ 2. shape + agent (>= 3 samples)
52
+ 3. shape + similar scope (affectedFiles within ±50%) (>= 3 samples)
53
+ 4. shape alone (global) (>= 1 sample)
54
+ 5. no match → UNCALIBRATED (use seedMinutes)
55
+ ```
56
+
57
+ Rungs 1–3 require at least 3 samples before they're trusted; rung 4 accepts
58
+ any evidence over none. A task matches against its own **effective model**:
59
+ the task's own `model` override if it set one, else `agentContext.model` —
60
+ so a plan-with-frontier / code-with-cheaper workflow matches planning tasks
61
+ against the planning model's history and coding tasks against the coding
62
+ model's history, even inside the same estimate.
63
+
64
+ ## 4. Math
65
+
66
+ Three bands, keyed on how many samples the ladder matched (`n`):
67
+
68
+ ```text
69
+ n >= 5:
70
+ σ_log = ln(p95 / p50) / 1.645 # lognormal fit from percentiles
71
+ e = p50 · exp(σ_log² / 2) # lognormal MEAN — means sum, medians don't
72
+ σ_task = e · √(exp(σ_log²) − 1)
73
+
74
+ 1 <= n < 5:
75
+ e = median(matched actual_minutes)
76
+ σ = (seed.p − seed.o) / 6 # spread borrowed from the seed
77
+
78
+ n = 0:
79
+ e, σ from seedMinutes via the existing pert() — UNCALIBRATED
80
+ ```
81
+
82
+ At `n >= 5` there's enough data to fit percentiles into a lognormal
83
+ distribution and take its mean — task expected values are **lognormal
84
+ means**, so they sum correctly across a feature (medians don't sum). Below 5
85
+ samples there isn't enough to fit a distribution, so the matched median
86
+ stands in for `e` and the seed's spread stands in for `σ`. With zero samples
87
+ the task falls back entirely to the agent's own `seedMinutes` judgment
88
+ through the existing PERT formula.
89
+
90
+ No `verificationPct` in agentic mode: `actual_minutes` in a measurement
91
+ record is full-cycle wall clock — AI execution, corrections, tests, **and**
92
+ human review — so the baseline already contains review time. Adding a
93
+ verification percentage on top would double-count it.
94
+
95
+ Risks use the same `risks` array as team mode, but agentic entries carry
96
+ `impactMinutes` (the script converts to hours) instead of `impactHours`, and
97
+ every risk requires a `probability`, an impact, and a `reason` — a generic
98
+ "+30 min contingency" with no reason is refused the same as in team mode.
99
+
100
+ ## 5. Decomposition rule
101
+
102
+ An agentic decomposition must include human-side operations, not just agent
103
+ typing time: **at least one `planning`-shaped task**, or the validator
104
+ refuses the deliverable (`agenticFindings` in `lib/agentic-checks.mjs`).
105
+ Planning captures the human time to design, sequence, and decompose the
106
+ work — real time, and it belongs in the estimate.
107
+
108
+ `seedMinutes` (`o`/`m`/`p`, optimistic/most-likely/pessimistic) is the
109
+ agent's **only** duration judgment call in this mode, and it only surfaces
110
+ in the final number when history is missing (`n = 0`, band 3 above). When a
111
+ baseline exists, the seed is ignored for `e` and used only to borrow spread
112
+ at `1 <= n < 5`.
113
+
114
+ ## 6. Confidence
115
+
116
+ | Samples | Variance | Confidence |
117
+ | --- | --- | --- |
118
+ | ≥ 10 | low (p80/p50 < 2) | HIGH |
119
+ | ≥ 10 | high (p80/p50 ≥ 2) | MED |
120
+ | 3–9 | any | MED |
121
+ | 1–2 | any | LOW |
122
+ | 0 | — | UNCALIBRATED |
123
+
124
+ A large sample count alone doesn't earn HIGH: if the matched history itself
125
+ is unpredictable (p80 is at least double p50), confidence is demoted to MED
126
+ even at 10+ samples — the variance rule catches a shape whose duration
127
+ genuinely varies a lot, where a tight point estimate would be dishonest.
128
+ UNCALIBRATED is never rendered as a measured confidence level, and it ranks
129
+ below LOW project-wide: one uncalibrated task on the critical path stamps the
130
+ whole estimate UNCALIBRATED.
131
+
132
+ ## Sources
133
+
134
+ - Bernhardsson, *Why software projects take longer than you think: a
135
+ statistical model* (erikbern.com, 2019) — lognormal task-duration
136
+ distributions, and why the mean (not the median) is the number that sums
137
+ correctly across a project.
138
+ - Vacanti, *Actionable Agile Metrics for Predictability* — percentile-based
139
+ cycle-time forecasting from historical data, non-normal distributions.
140
+ - Atomic Object (atomicobject.com) — buffer machinery (already the source
141
+ for `projectBuffer`/`√Σσ²` in team-mode estimation; unchanged here).
142
+ - The `1.645` constant is the standard normal 95th-percentile z-score,
143
+ applied in log space to fit a lognormal from `p50`/`p95`.
144
+
145
+ The constants above — `1.645`, the ±50% scope-similarity window, and the
146
+ sample thresholds (3 for rungs 1–3, 5 for the lognormal fit, 10 for HIGH
147
+ confidence) — are documented starting points, not settled science: tune them
148
+ against real measurement data as `measurements.jsonl` grows.
@@ -5,6 +5,16 @@ Read while assigning a `category` to each task and again while choosing
5
5
  how the formula in `estimate-math.mjs` uses it, and the one rule that keeps
6
6
  an agent from inventing a project-wide speedup number.
7
7
 
8
+ **In AGENTIC delivery mode this model is retired from estimation** —
9
+ measurement-based baselines (`references/agentic-estimation.md`) replace
10
+ category scoring and the formula below entirely; agentic tasks carry a
11
+ `shape`, not a `category`, and `schema.mjs` rejects `category` on an agentic
12
+ task outright. This doc's model survives only as intuition for
13
+ `seedMinutes` on an uncalibrated shape — the categories below are a useful
14
+ gut-check for an o/m/p seed guess, nothing more, in that one case. For
15
+ TRADITIONAL scenarios (humans code, with or without AI-assisted plans), the
16
+ categories and formula below are unchanged.
17
+
8
18
  ## 1. Category table
9
19
 
10
20
  | Category | AI speedup range | Example tasks |
@@ -34,6 +34,23 @@ before scope confirmation and before any factor scoring.
34
34
  | STANDARD | task-level three-point PERT | ± moderate |
35
35
  | DEEP | STANDARD plus per-scenario detail (multiple team/plan combinations sized individually) | ± narrower |
36
36
 
37
+ ## 2b. Delivery mode — ask second
38
+
39
+ | Mode | Meaning | Sizing path |
40
+ | --- | --- | --- |
41
+ | TRADITIONAL | humans write the code | technique menu (`techniques.md`) |
42
+ | AGENTIC | AI coding agents write the code, humans plan and review | measurement-based (`agentic-estimation.md`) |
43
+
44
+ AGENTIC replaces the technique question and AI-category scoring entirely.
45
+ Follow-ups it adds: which agent + model executes (calibration context,
46
+ written to `agentContext`; ask whether planning uses a different model —
47
+ per-task `model` override); which repository the work targets (optional
48
+ `agentContext.repository`, matching the `repository` field of measurement
49
+ records — omit it and the script falls back to `project`, but set it when
50
+ the project's repo name differs from `project` so rung 1 of the retrieval
51
+ ladder can match); per task, a shape from `task-shapes.md`, scope
52
+ attributes, and seed minutes (o/m/p) used only when no baseline exists.
53
+
37
54
  ## 3. Clear-vs-assumed gate
38
55
 
39
56
  Before any sizing happens, present two lists side by side:
@@ -62,7 +79,9 @@ Ask one thing at a time, in this order:
62
79
  `stated`, recorded in the deliverable's Roadmap section.
63
80
  3. **Factor scores per feature** — five factors, each scored 1-5: tech
64
81
  complexity, feature size, dependencies, uncertainty, risk. (STANDARD/DEEP
65
- also want task-level O/M/P — see `techniques.md`.)
82
+ also want task-level O/M/P — see `techniques.md`.) TRADITIONAL-only: in
83
+ AGENTIC mode this step is replaced entirely — ask shape + scope + seed
84
+ minutes per task instead (§2b, `task-shapes.md`).
66
85
  4. **Team options + rates + seniority mix** — how many engineers, what they
67
86
  cost per hour, and whether each is junior/mid/senior.
68
87
  5. **Claude plan availability** — none / Max 5x / Max 20x, per scenario.
@@ -0,0 +1,173 @@
1
+ # Task shapes — the agentic taxonomy
2
+
3
+ Read while decomposing an agentic feature into tasks (`references/interview.md`
4
+ §2b) and while writing each task's `shape` into `estimation-inputs.json`.
5
+ Shapes classify **operations, not features** — a feature almost always
6
+ decomposes into several shapes (a "password reset" feature is
7
+ `api_integration` + `database_change` + `ui_implementation` + `test_creation`
8
+ + `planning`, not one shape). Classify by what the agent *does* — files
9
+ touched, kind of change — never by business domain. "Add password reset" is
10
+ not a shape; "add a database column and migration" is `database_change`.
11
+
12
+ ## `scaffold`
13
+
14
+ Create a new module, service, or package from nothing — the first commit in
15
+ a new area, not a change to an existing one.
16
+
17
+ - New microservice skeleton with health-check endpoint.
18
+ - New CLI package with entrypoint and empty command router.
19
+ - New frontend app shell (routing, layout, no real screens yet).
20
+
21
+ Scope: `complexity` (how much boilerplate the shape spans — low for a single
22
+ file, higher for a multi-package skeleton).
23
+
24
+ ## `small_implementation`
25
+
26
+ Add isolated business logic inside existing structure — one function or one
27
+ module, no cross-cutting change.
28
+
29
+ - Add a discount-calculation function to an existing pricing module.
30
+ - Add a new validation rule to an existing form handler.
31
+ - Add a single new field with its read path.
32
+
33
+ Scope: `complexity`.
34
+
35
+ ## `cross_file_refactor`
36
+
37
+ Replace a pattern, call, or dependency across multiple existing files without
38
+ changing external behavior.
39
+
40
+ - Replace an old API client with a new SDK across every call site.
41
+ - Rename a widely-used function and update every caller.
42
+ - Extract a repeated block into a shared helper across several modules.
43
+
44
+ Scope: `affectedFiles` (how many files the pattern touches) and `complexity`.
45
+
46
+ ## `test_creation`
47
+
48
+ Add unit or integration tests for existing, already-implemented behavior.
49
+
50
+ - Add unit tests for a function that currently has none.
51
+ - Add an integration test covering a new endpoint's happy path and one error
52
+ case.
53
+ - Backfill test coverage on a module before refactoring it.
54
+
55
+ Scope: `complexity`.
56
+
57
+ ## `bug_fix`
58
+
59
+ Diagnose and correct a known, reported issue — the defect is already
60
+ described; this is not open-ended exploration.
61
+
62
+ - Fix a null-pointer crash reported in a specific handler.
63
+ - Correct an off-by-one error in a pagination calculation.
64
+ - Fix a race condition in a documented flaky test.
65
+
66
+ Scope: `complexity`.
67
+
68
+ ## `configuration`
69
+
70
+ Modify environment variables, config files, feature flags, or deployment
71
+ settings — no application logic changes.
72
+
73
+ - Add a new environment variable and wire it through config loading.
74
+ - Update a CI pipeline's build matrix.
75
+ - Toggle a feature flag's default and adjust its config schema.
76
+
77
+ Scope: `complexity`.
78
+
79
+ ## `api_integration`
80
+
81
+ Add or modify a call to an external API — first-party or third-party service
82
+ boundary.
83
+
84
+ - Add a new outbound call to a payment provider's API.
85
+ - Wire a webhook receiver for an external service's events.
86
+ - Change an existing integration's request/response shape after a provider
87
+ API version bump.
88
+
89
+ Scope: `complexity`.
90
+
91
+ ## `database_change`
92
+
93
+ Modify schema, migrations, or queries.
94
+
95
+ - Add a column and its migration.
96
+ - Add an index to fix a slow query.
97
+ - Rewrite a query to eliminate an N+1.
98
+
99
+ Scope: `affectedFiles` when the change spans multiple migration/query files,
100
+ `complexity` always.
101
+
102
+ ## `documentation`
103
+
104
+ Generate or update technical documentation — no code change.
105
+
106
+ - Write a README section for a new module.
107
+ - Update API docs after a signature change.
108
+ - Write an ADR recording a design decision.
109
+
110
+ Scope: `complexity`.
111
+
112
+ ## `ui_implementation`
113
+
114
+ Create or modify a frontend component.
115
+
116
+ - Build a new form component with validation states.
117
+ - Update an existing list view to add sorting.
118
+ - Restyle a component to match a new design spec.
119
+
120
+ Scope: `complexity`.
121
+
122
+ ## `migration`
123
+
124
+ Replace a technology or implementation pattern project-wide — larger and
125
+ more structural than `cross_file_refactor`: a framework swap, a language
126
+ runtime bump, a persistence-layer replacement.
127
+
128
+ - Migrate from one ORM to another across the codebase.
129
+ - Move a service from REST to gRPC.
130
+ - Upgrade a major framework version with breaking-change fixups.
131
+
132
+ Scope: `affectedFiles` and `complexity`.
133
+
134
+ ## `investigation`
135
+
136
+ Explore unknown system behavior — no code change is guaranteed; the
137
+ deliverable is understanding, not a diff.
138
+
139
+ - Investigate why a production job intermittently times out.
140
+ - Explore an unfamiliar third-party library's undocumented behavior.
141
+ - Trace a data-inconsistency bug to its root cause before fixing it.
142
+
143
+ Scope: none beyond the task description — investigation has no meaningful
144
+ `affectedFiles` or `complexity` axis to score in advance; scope stays `{}`.
145
+
146
+ ## `planning`
147
+
148
+ Produce a plan, design, or decomposition before code — the human-side
149
+ operation that turns a feature into tasks. First-class, not overhead: every
150
+ agentic decomposition needs at least one `planning`-shaped task, or the
151
+ validator refuses the deliverable (`references/agentic-estimation.md` §5).
152
+
153
+ - Write the task breakdown for a feature before implementation starts.
154
+ - Produce a design doc or ADR for an approach with more than one viable
155
+ option.
156
+ - Review and finalize a decomposition after a scope change.
157
+
158
+ Scope: none beyond the task description — like `investigation`, `planning`
159
+ has no `affectedFiles`/`complexity` axis; scope stays `{}`.
160
+
161
+ ## Extensibility
162
+
163
+ The taxonomy is not closed. An unknown `task_shape` in a measurement record
164
+ is a warning, kept — never a fatal error (`lib/measurements.mjs`
165
+ `checkMeasurement`), so a future shape written before this doc catches up
166
+ still calibrates. `estimation-inputs.json`, on the other hand, must use the
167
+ taxonomy above: `schema.mjs` rejects an unknown `shape` on a task, because
168
+ inputs are the agent's own judgment and an unrecognized shape there is a
169
+ typo, not evidence.
170
+
171
+ Extending the taxonomy means adding the new shape to `TASK_SHAPES` in
172
+ `scripts/lib/measurements.mjs` **and** a section to this doc, in the same
173
+ commit — the two must never drift apart.
@@ -158,6 +158,37 @@ Roadmap (mirrors `checkRoadmap` in `scripts/lib/checks.mjs`):
158
158
  `computed.scenarios[recommendedScenario].roadmap` — covered by the
159
159
  recompute rule 12, same as every other number.
160
160
 
161
+ ## 3b. Agentic deliverable additions
162
+
163
+ When `deliveryMode: "agentic"`, `estimation.md` follows the same two-part
164
+ skeleton with these additions (mirror
165
+ `scripts/test/fixtures/agentic-estimation-pass.md` exactly):
166
+
167
+ - **Summary header line** — immediately under `## Summary`, before the
168
+ feature table: `Delivery: agentic (<agent> + <model>) · Baselines: <N>
169
+ measurements, <K> shapes matched`. `agenticFindings` in
170
+ `lib/agentic-checks.mjs` refuses a deliverable missing this line.
171
+ - **Estimation detail task table** — agentic columns replace the
172
+ traditional PERT columns: `Task | Baseline (min) | Samples | Match |
173
+ Confidence | Assumptions | src`. A zero-sample task writes **"not
174
+ estimated"** in the Baseline column and `UNCALIBRATED` in Confidence — a
175
+ zero-sample row rendered with any other confidence label is refused.
176
+ - **`### Evidence` section** — a table of `Id | Task | Actual (min)` rows,
177
+ one per matched historical measurement actually cited. Every row's id AND
178
+ Actual (min) value must match `estimation.json`'s
179
+ `computed.tasks[*].evidence` — the validator refuses an evidence row whose
180
+ id isn't script-matched, or whose minutes cell doesn't match the matched
181
+ record, so never invent, hand-add, or alter a history row.
182
+ - **Risks table** — same section as team mode, but the Impact column is in
183
+ minutes with an added Reason column: `Risk | Probability | Impact (min) |
184
+ Reason`. Every risk row needs all four cells; a generic buffer with no
185
+ reason is refused the same as in team mode.
186
+ - **Calibration nudge** — when any task is UNCALIBRATED or low-sample, the
187
+ detail section's calibration line should point at recording actuals to
188
+ close the loop (see `docs/requirements/record-task.md` — the capture
189
+ skill that will fill the dataset is designed but not yet built; do not
190
+ describe it as available functionality).
191
+
161
192
  ## 4. File placement
162
193
 
163
194
  Two modes:
@@ -2,6 +2,7 @@ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
2
2
  import { dirname } from 'node:path';
3
3
  import { checkInputs } from './lib/schema.mjs';
4
4
  import { computeEstimation } from './lib/rollup.mjs';
5
+ import { loadMeasurements, resolveMeasurementsPath } from './lib/measurements.mjs';
5
6
 
6
7
  function parseArgs(argv) {
7
8
  const args = {};
@@ -19,5 +20,8 @@ if (findings.length) {
19
20
  process.exit(1);
20
21
  }
21
22
  mkdirSync(dirname(args.out), { recursive: true });
22
- writeFileSync(args.out, `${JSON.stringify(computeEstimation(inputs), null, 2)}\n`);
23
+ const measurements = inputs.deliveryMode === 'agentic'
24
+ ? loadMeasurements(resolveMeasurementsPath(inputs)).records
25
+ : undefined;
26
+ writeFileSync(args.out, `${JSON.stringify(computeEstimation(inputs, measurements), null, 2)}\n`);
23
27
  console.log(args.out);
@@ -0,0 +1,65 @@
1
+ // Agentic-mode deliverable checks (PRD §18): measurement honesty rules that
2
+ // only apply when deliveryMode === 'agentic' — vague language, UNCALIBRATED
3
+ // masked as measured, invented evidence, missing planning work, and the
4
+ // mandatory "Delivery: agentic" header line. Split out of checks.mjs to stay
5
+ // under the file's function/line quality gates.
6
+ import { heading, tables } from './checks.mjs';
7
+
8
+ const VAGUE_PATTERNS = [
9
+ /\b\d+\s*[–—-]\s*\d+\s*(hours?|hrs|minutes?|mins)\b/i,
10
+ /\bhalf a day\b/i,
11
+ /\ba few (hours|days|minutes)\b/i,
12
+ /\bdepending on complexity\b/i,
13
+ ];
14
+
15
+ function checkVagueness(md, out) {
16
+ for (const re of VAGUE_PATTERNS) {
17
+ const m = re.exec(md);
18
+ if (m) out.push(`vague estimate language: "${m[0]}" — one number plus explicit risks`);
19
+ }
20
+ }
21
+
22
+ // The md may only cite history the script actually matched: every Evidence
23
+ // row's id AND minutes must match computed.tasks[*].evidence (spec §4:
24
+ // "ids, minutes") — a real id with a fabricated Actual (min) cell is just as
25
+ // dishonest as an invented id.
26
+ function checkEvidence(md, estimation, out) {
27
+ const section = heading(md, 'Evidence');
28
+ if (section === null) { out.push('missing ### Evidence section'); return; }
29
+ const known = new Map(
30
+ Object.values(estimation.computed.tasks).flatMap((t) => (t.evidence ?? []).map((e) => [e.id, e.minutes])));
31
+ for (const row of tables(section).flatMap((t) => t.rows)) {
32
+ if (!known.has(row[0])) { out.push(`evidence row "${row[0]}": not among script-matched measurements`); continue; }
33
+ if (Number(row[2]) !== known.get(row[0])) {
34
+ out.push(`evidence row "${row[0]}": Actual (min) "${row[2]}" does not match matched minutes ${known.get(row[0])}`);
35
+ }
36
+ }
37
+ }
38
+
39
+ function checkAgenticRows(detail, out) {
40
+ const table = tables(detail).find((t) => ['Task', 'Samples', 'Confidence'].every((h) => t.header.includes(h)));
41
+ if (!table) { out.push('agentic task table not found (need Task, Samples, Confidence headers)'); return; }
42
+ const confIdx = table.header.indexOf('Confidence');
43
+ const samplesIdx = table.header.indexOf('Samples');
44
+ for (const row of table.rows) {
45
+ if (!['HIGH', 'MED', 'LOW', 'UNCALIBRATED'].includes(row[confIdx])) out.push(`task row "${row[0]}": bad confidence cell`);
46
+ if (row[samplesIdx] === '0' && row[confIdx] !== 'UNCALIBRATED') {
47
+ out.push(`task row "${row[0]}": zero samples must render UNCALIBRATED, never a measured confidence`);
48
+ }
49
+ }
50
+ }
51
+
52
+ function checkPlanningPresence(estimation, out) {
53
+ const shapes = estimation.inputs.features.flatMap((f) => f.tasks).map((t) => t.shape);
54
+ if (!shapes.includes('planning')) out.push('agentic decomposition needs >= 1 planning-shaped task (human-side work is work)');
55
+ }
56
+
57
+ export function agenticFindings({ md, estimation }) {
58
+ const out = [];
59
+ checkVagueness(md, out);
60
+ checkEvidence(md, estimation, out);
61
+ checkAgenticRows(heading(md, 'Estimation detail') ?? '', out);
62
+ checkPlanningPresence(estimation, out);
63
+ if (!/Delivery:\s*agentic/.test(md)) out.push('missing "Delivery: agentic" header line');
64
+ return out;
65
+ }
@@ -0,0 +1,107 @@
1
+ // Baseline retrieval and statistics for agentic estimation. Pure functions:
2
+ // records in, numbers out. The agent never touches this math — compute.mjs
3
+ // calls it, and the deliverable's Evidence section is built from what this
4
+ // module actually matched, so cited history can never be invented.
5
+ import { pert } from './estimate-math.mjs';
6
+
7
+ const Z95 = 1.645; // standard normal 95th-percentile z, applied in log space
8
+
9
+ export function percentile(values, q) {
10
+ const s = [...values].sort((a, b) => a - b);
11
+ const pos = (s.length - 1) * q;
12
+ const lo = Math.floor(pos);
13
+ const hi = Math.ceil(pos);
14
+ return s[lo] + (s[hi] - s[lo]) * (pos - lo);
15
+ }
16
+
17
+ const effectiveModel = (task, ctx) => task.model ?? ctx.model;
18
+
19
+ function similarScope(rec, task) {
20
+ const mine = task.scope?.affectedFiles;
21
+ if (typeof mine !== 'number' || typeof rec.affected_files !== 'number' || mine <= 0) return false;
22
+ return Math.abs(rec.affected_files - mine) / mine <= 0.5;
23
+ }
24
+
25
+ // Spec §2 ladder: stop at the first rung with enough samples. Rungs 1-3 need
26
+ // >= 3; the global rung accepts any evidence over none.
27
+ const RUNGS = [
28
+ { level: 1, min: 3, hit: (r, t, c) => r.repository === c.repository && r.agent === c.agent && r.model === effectiveModel(t, c) },
29
+ { level: 2, min: 3, hit: (r, t, c) => r.agent === c.agent },
30
+ { level: 3, min: 3, hit: (r, t) => similarScope(r, t) },
31
+ { level: 4, min: 1, hit: () => true },
32
+ ];
33
+
34
+ function summarize(hits, level) {
35
+ const mins = hits.map((r) => r.actual_minutes);
36
+ return {
37
+ p50: percentile(mins, 0.5),
38
+ p80: percentile(mins, 0.8),
39
+ p95: percentile(mins, 0.95),
40
+ minM: percentile(mins, 0),
41
+ maxM: percentile(mins, 1),
42
+ samples: hits.length,
43
+ matchLevel: level,
44
+ evidence: hits.map((r) => ({ id: r.task_id, description: r.task_description, minutes: r.actual_minutes })),
45
+ };
46
+ }
47
+
48
+ export function matchBaseline(task, ctx) {
49
+ const shaped = ctx.records.filter((r) => r.task_shape === task.shape);
50
+ for (const rung of RUNGS) {
51
+ const hits = shaped.filter((r) => rung.hit(r, task, ctx.agentContext));
52
+ if (hits.length >= rung.min) return summarize(hits, rung.level);
53
+ }
54
+ return { samples: 0, matchLevel: 0, evidence: [] };
55
+ }
56
+
57
+ // Spec confidence table: sample count sets the tier, variance can demote
58
+ // a would-be HIGH (p80/p50 >= 2 means the history itself is unpredictable).
59
+ export function confidenceFor(stats) {
60
+ if (stats.samples === 0) return 'UNCALIBRATED';
61
+ if (stats.samples < 3) return 'LOW';
62
+ if (stats.samples < 10) return 'MED';
63
+ return stats.p80 / stats.p50 < 2 ? 'HIGH' : 'MED';
64
+ }
65
+
66
+ function lognormalFit(stats) {
67
+ const sigmaLog = Math.log(stats.p95 / stats.p50) / Z95;
68
+ const mean = stats.p50 * Math.exp((sigmaLog ** 2) / 2);
69
+ return { e: mean / 60, sigma: (mean * Math.sqrt(Math.exp(sigmaLog ** 2) - 1)) / 60 };
70
+ }
71
+
72
+ // Spec §3 bands: >=5 samples fit a lognormal (means sum; medians do not);
73
+ // 1-4 samples trust the matched median but take spread from the seed; zero
74
+ // samples fall back to the seed entirely.
75
+ function fitHours(stats, seed) {
76
+ if (stats.samples >= 5) return lognormalFit(stats);
77
+ if (stats.samples >= 1) return { e: stats.p50 / 60, sigma: (seed.p - seed.o) / 6 / 60 };
78
+ const { e, sigma } = pert(seed);
79
+ return { e: e / 60, sigma: sigma / 60 };
80
+ }
81
+
82
+ // Bounds per band: a lognormal fit reports p50..p95; with 1-4 samples the
83
+ // only honest bounds are the extremes actually observed (and p50 == e there,
84
+ // which would violate the low < hours < high deliverable rule); no samples
85
+ // falls back to the seed range.
86
+ function bounds(stats, seed) {
87
+ if (stats.samples >= 5) return { lowH: stats.p50 / 60, highH: stats.p95 / 60 };
88
+ if (stats.samples >= 1) return { lowH: stats.minM / 60, highH: stats.maxM / 60 };
89
+ return { lowH: seed.o / 60, highH: seed.p / 60 };
90
+ }
91
+
92
+ export function agenticTask(task, ctx) {
93
+ const stats = matchBaseline(task, ctx);
94
+ const calibrated = stats.samples > 0;
95
+ const { e, sigma } = fitHours(stats, task.seedMinutes);
96
+ return {
97
+ e,
98
+ sigma,
99
+ ...bounds(stats, task.seedMinutes),
100
+ minutes: calibrated ? stats.p50 : null,
101
+ samples: stats.samples,
102
+ matchLevel: stats.matchLevel,
103
+ confidence: confidenceFor(stats),
104
+ evidence: stats.evidence,
105
+ calibrated,
106
+ };
107
+ }
@@ -2,13 +2,15 @@
2
2
  // estimation.json a machine computed. Rules 1-4/9 check structure, 5-6 check
3
3
  // table rows, 7-8 cross-check the JSON against a fresh recompute.
4
4
  import { computeEstimation } from './rollup.mjs';
5
+ import { loadMeasurements, resolveMeasurementsPath } from './measurements.mjs';
6
+ import { agenticFindings } from './agentic-checks.mjs';
5
7
 
6
8
  const PROVENANCE = ['observed', 'stated', 'researched', 'proposed'];
7
9
  const CONFIDENCE = ['HIGH', 'MED', 'LOW'];
8
10
 
9
11
  // Returns the text of the section/subsection starting at heading `name`, up
10
12
  // to (not including) the next heading of the same or shallower level.
11
- function heading(md, name) {
13
+ export function heading(md, name) {
12
14
  const m = new RegExp(`^(#{2,4})\\s*${name}\\b.*$`, 'm').exec(md);
13
15
  if (!m) return null;
14
16
  const rest = md.slice(m.index + m[0].length);
@@ -22,7 +24,7 @@ function cells(line) {
22
24
 
23
25
  // Groups contiguous `| ... |` lines into tables, dropping the `| --- |`
24
26
  // separator row, and returns each as { header, rows } of trimmed cells.
25
- function tables(text) {
27
+ export function tables(text) {
26
28
  const groups = [];
27
29
  let cur = [];
28
30
  for (const line of (text ?? '').split('\n')) {
@@ -95,9 +97,12 @@ function checkRoadmap(md, estimation, out) {
95
97
  }
96
98
  }
97
99
 
98
- function checkRows(md) {
100
+ // Team-mode task rows require HIGH|MED|LOW confidence; agentic rows carry
101
+ // UNCALIBRATED and are checked separately (agentic-checks.mjs), so the two
102
+ // modes never run the same row rule against the same table.
103
+ function checkRows(md, estimation) {
99
104
  const out = [];
100
- checkTaskRows(heading(md, 'Estimation detail') ?? '', out);
105
+ if (estimation.inputs.deliveryMode !== 'agentic') checkTaskRows(heading(md, 'Estimation detail') ?? '', out);
101
106
  checkScopeRows(heading(md, 'Summary') ?? '', out);
102
107
  return out;
103
108
  }
@@ -105,10 +110,13 @@ function checkRows(md) {
105
110
  // Rules 7-8: the JSON side. A fresh recompute from the same inputs must
106
111
  // deep-equal the stored computed block (catches hand-edits), and every
107
112
  // feature's low/hours/high must be strictly ordered (or all equal, for the
108
- // degenerate zero-spread case).
113
+ // degenerate zero-spread case). Agentic recompute needs the measurements the
114
+ // original run used, loaded fresh — never trusted from the stored computed.
109
115
  function checkNumbers(estimation) {
110
116
  const out = [];
111
- const recomputed = computeEstimation(estimation.inputs).computed;
117
+ const agentic = estimation.inputs.deliveryMode === 'agentic';
118
+ const measurements = agentic ? loadMeasurements(resolveMeasurementsPath(estimation.inputs)).records : undefined;
119
+ const recomputed = computeEstimation(estimation.inputs, measurements).computed;
112
120
  if (JSON.stringify(recomputed) !== JSON.stringify(estimation.computed)) {
113
121
  out.push('computed block does not match recomputed totals (hand-edited JSON?)');
114
122
  }
@@ -122,7 +130,8 @@ function checkNumbers(estimation) {
122
130
  }
123
131
 
124
132
  export function checkDeliverables({ md, estimation }) {
125
- const out = [...checkStructure(md), ...checkRows(md), ...checkNumbers(estimation)];
133
+ const out = [...checkStructure(md), ...checkRows(md, estimation), ...checkNumbers(estimation)];
126
134
  checkRoadmap(md, estimation, out);
135
+ if (estimation.inputs.deliveryMode === 'agentic') out.push(...agenticFindings({ md, estimation }));
127
136
  return out;
128
137
  }