@codyswann/lisa 7.0.3 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/all/copy-overwrite/scripts/lib/work-item-estimate-calibration.mjs +131 -0
  2. package/all/copy-overwrite/scripts/lib/work-item-estimate-check.mjs +15 -5
  3. package/all/copy-overwrite/scripts/lisa-estimate.mjs +29 -3
  4. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  5. package/dist/core/lisa-owned-hash-ledger.js +18 -0
  6. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  7. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  8. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  9. package/dist/core/upstream-evidence-manifest.js +46 -17
  10. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  11. package/dist/utils/usage-accounting.d.ts.map +1 -1
  12. package/dist/utils/usage-accounting.js +3 -1
  13. package/dist/utils/usage-accounting.js.map +1 -1
  14. package/package.json +4 -4
  15. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  16. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  17. package/plugins/lisa/.codex-plugin/skills/lisa-github-validate-issue/SKILL.md +2 -0
  18. package/plugins/lisa/.codex-plugin/skills/lisa-jira-validate-ticket/SKILL.md +2 -0
  19. package/plugins/lisa/.codex-plugin/skills/lisa-linear-validate-issue/SKILL.md +2 -0
  20. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/SKILL.md +45 -15
  21. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-runtime.mjs +1 -0
  22. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-usage.mjs +10 -3
  23. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/cli-workers.mjs +52 -1
  24. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/orphan-sweep.mjs +2 -20
  25. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/session-manager.mjs +5 -1
  26. package/plugins/lisa/.codex-plugin/skills/lisa-session-manager/scripts/take-check.mjs +110 -0
  27. package/plugins/lisa/.codex-plugin/skills/lisa-track/SKILL.md +11 -1
  28. package/plugins/lisa/.codex-plugin/skills/lisa-tracker-claim/SKILL.md +1 -0
  29. package/plugins/lisa/.codex-plugin/skills/lisa-usage-accounting/references/estimate.md +25 -2
  30. package/plugins/lisa/rules/reference/work-item-definition-of-ready.md +7 -2
  31. package/plugins/lisa/skills/lisa-github-validate-issue/SKILL.md +2 -0
  32. package/plugins/lisa/skills/lisa-jira-validate-ticket/SKILL.md +2 -0
  33. package/plugins/lisa/skills/lisa-linear-validate-issue/SKILL.md +2 -0
  34. package/plugins/lisa/skills/lisa-session-manager/SKILL.md +45 -15
  35. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-runtime.mjs +1 -0
  36. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-usage.mjs +10 -3
  37. package/plugins/lisa/skills/lisa-session-manager/scripts/cli-workers.mjs +52 -1
  38. package/plugins/lisa/skills/lisa-session-manager/scripts/orphan-sweep.mjs +2 -20
  39. package/plugins/lisa/skills/lisa-session-manager/scripts/session-manager.mjs +5 -1
  40. package/plugins/lisa/skills/lisa-session-manager/scripts/take-check.mjs +110 -0
  41. package/plugins/lisa/skills/lisa-track/SKILL.md +11 -1
  42. package/plugins/lisa/skills/lisa-tracker-claim/SKILL.md +1 -0
  43. package/plugins/lisa/skills/lisa-usage-accounting/references/estimate.md +25 -2
  44. package/plugins/lisa-agy/plugin.json +1 -1
  45. package/plugins/lisa-agy/skills/lisa-github-validate-issue/SKILL.md +2 -0
  46. package/plugins/lisa-agy/skills/lisa-jira-validate-ticket/SKILL.md +2 -0
  47. package/plugins/lisa-agy/skills/lisa-linear-validate-issue/SKILL.md +2 -0
  48. package/plugins/lisa-agy/skills/lisa-session-manager/SKILL.md +45 -15
  49. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-runtime.mjs +1 -0
  50. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-usage.mjs +10 -3
  51. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/cli-workers.mjs +52 -1
  52. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/orphan-sweep.mjs +2 -20
  53. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/session-manager.mjs +5 -1
  54. package/plugins/lisa-agy/skills/lisa-session-manager/scripts/take-check.mjs +110 -0
  55. package/plugins/lisa-agy/skills/lisa-track/SKILL.md +11 -1
  56. package/plugins/lisa-agy/skills/lisa-tracker-claim/SKILL.md +1 -0
  57. package/plugins/lisa-agy/skills/lisa-usage-accounting/references/estimate.md +25 -2
  58. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  59. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  60. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  61. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  64. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  65. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  66. package/plugins/lisa-copilot/rules/reference/work-item-definition-of-ready.md +7 -2
  67. package/plugins/lisa-copilot/skills/lisa-github-validate-issue/SKILL.md +2 -0
  68. package/plugins/lisa-copilot/skills/lisa-jira-validate-ticket/SKILL.md +2 -0
  69. package/plugins/lisa-copilot/skills/lisa-linear-validate-issue/SKILL.md +2 -0
  70. package/plugins/lisa-copilot/skills/lisa-session-manager/SKILL.md +45 -15
  71. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-runtime.mjs +1 -0
  72. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-usage.mjs +10 -3
  73. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/cli-workers.mjs +52 -1
  74. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/orphan-sweep.mjs +2 -20
  75. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/session-manager.mjs +5 -1
  76. package/plugins/lisa-copilot/skills/lisa-session-manager/scripts/take-check.mjs +110 -0
  77. package/plugins/lisa-copilot/skills/lisa-track/SKILL.md +11 -1
  78. package/plugins/lisa-copilot/skills/lisa-tracker-claim/SKILL.md +1 -0
  79. package/plugins/lisa-copilot/skills/lisa-usage-accounting/references/estimate.md +25 -2
  80. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  81. package/plugins/lisa-cursor/rules/work-item-definition-of-ready-reference.mdc +7 -2
  82. package/plugins/lisa-cursor/skills/lisa-github-validate-issue/SKILL.md +2 -0
  83. package/plugins/lisa-cursor/skills/lisa-jira-validate-ticket/SKILL.md +2 -0
  84. package/plugins/lisa-cursor/skills/lisa-linear-validate-issue/SKILL.md +2 -0
  85. package/plugins/lisa-cursor/skills/lisa-session-manager/SKILL.md +45 -15
  86. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-runtime.mjs +1 -0
  87. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-usage.mjs +10 -3
  88. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/cli-workers.mjs +52 -1
  89. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/orphan-sweep.mjs +2 -20
  90. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/session-manager.mjs +5 -1
  91. package/plugins/lisa-cursor/skills/lisa-session-manager/scripts/take-check.mjs +110 -0
  92. package/plugins/lisa-cursor/skills/lisa-track/SKILL.md +11 -1
  93. package/plugins/lisa-cursor/skills/lisa-tracker-claim/SKILL.md +1 -0
  94. package/plugins/lisa-cursor/skills/lisa-usage-accounting/references/estimate.md +25 -2
  95. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  96. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  97. package/plugins/lisa-devin/rules/reference/work-item-definition-of-ready.md +7 -2
  98. package/plugins/lisa-devin/skills/lisa-github-validate-issue/SKILL.md +2 -0
  99. package/plugins/lisa-devin/skills/lisa-jira-validate-ticket/SKILL.md +2 -0
  100. package/plugins/lisa-devin/skills/lisa-linear-validate-issue/SKILL.md +2 -0
  101. package/plugins/lisa-devin/skills/lisa-session-manager/SKILL.md +45 -15
  102. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-runtime.mjs +1 -0
  103. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-usage.mjs +10 -3
  104. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/cli-workers.mjs +52 -1
  105. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/orphan-sweep.mjs +2 -20
  106. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/session-manager.mjs +5 -1
  107. package/plugins/lisa-devin/skills/lisa-session-manager/scripts/take-check.mjs +110 -0
  108. package/plugins/lisa-devin/skills/lisa-track/SKILL.md +11 -1
  109. package/plugins/lisa-devin/skills/lisa-tracker-claim/SKILL.md +1 -0
  110. package/plugins/lisa-devin/skills/lisa-usage-accounting/references/estimate.md +25 -2
  111. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  112. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  113. package/plugins/lisa-expo-agy/plugin.json +1 -1
  114. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  115. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  116. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  117. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  118. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  119. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  120. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  121. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  122. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  123. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  124. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  125. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  126. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  127. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  128. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  129. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  130. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  131. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  132. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  133. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  134. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  135. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  136. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  137. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  138. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  139. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  140. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  141. package/plugins/lisa-rails-agy/plugin.json +1 -1
  142. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  143. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  144. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  145. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  146. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  147. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  148. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  149. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  150. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  151. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  152. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  153. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  154. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  155. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  156. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  157. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  158. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  159. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  160. package/plugins/src/base/rules/reference/work-item-definition-of-ready.md +7 -2
  161. package/plugins/src/base/skills/lisa-github-validate-issue/SKILL.md +2 -0
  162. package/plugins/src/base/skills/lisa-jira-validate-ticket/SKILL.md +2 -0
  163. package/plugins/src/base/skills/lisa-linear-validate-issue/SKILL.md +2 -0
  164. package/plugins/src/base/skills/lisa-session-manager/SKILL.md +45 -15
  165. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-runtime.mjs +1 -0
  166. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-usage.mjs +10 -3
  167. package/plugins/src/base/skills/lisa-session-manager/scripts/cli-workers.mjs +52 -1
  168. package/plugins/src/base/skills/lisa-session-manager/scripts/orphan-sweep.mjs +2 -20
  169. package/plugins/src/base/skills/lisa-session-manager/scripts/session-manager.mjs +5 -1
  170. package/plugins/src/base/skills/lisa-session-manager/scripts/take-check.mjs +110 -0
  171. package/plugins/src/base/skills/lisa-track/SKILL.md +11 -1
  172. package/plugins/src/base/skills/lisa-tracker-claim/SKILL.md +1 -0
  173. package/plugins/src/base/skills/lisa-usage-accounting/references/estimate.md +25 -2
  174. package/scripts/two-channel-couplings.json +1 -1
  175. package/typescript/copy-overwrite/.prettierignore +1 -0
@@ -0,0 +1,131 @@
1
+ // This file is managed by Lisa and IS replaced on each `lisa` run.
2
+ // Do not edit directly — durable changes belong upstream in Lisa.
3
+
4
+ /**
5
+ * Calibrate a new token estimate against finished work (CodySwannGT/lisa#4955).
6
+ *
7
+ * For each comparable finished item that carries both an estimate and a
8
+ * complete actual, the ratio is the actual token total (the item's
9
+ * `## Lisa Usage` rollup, the same ledger the completion tally reads) over the
10
+ * estimate's midpoint. The median ratio scales the new range. Items whose
11
+ * actual is unknown or partial (no ledger, or any run with `unavailable`
12
+ * telemetry or a measured subset) are skipped, never counted as zero or as the
13
+ * sum of only the known runs. With no usable history the range is
14
+ * returned unchanged and the basis says so.
15
+ * @module scripts/lib/work-item-estimate-calibration
16
+ */
17
+ import { parseLisaUsageSection } from "./usage-ledger.mjs";
18
+ import { EstimateConfigError } from "./work-item-estimate-config.mjs";
19
+ import { parseEstimateSection } from "./work-item-estimate.mjs";
20
+
21
+ /**
22
+ * Whether a parsed token count is a usable positive number (NaN is not).
23
+ * @param {number} value - Parsed count.
24
+ * @returns {boolean} True for a finite count above zero.
25
+ */
26
+ const isPositive = value => Number.isFinite(value) && value > 0;
27
+
28
+ /**
29
+ * Whether a usage entry lacks a full token count: `unavailable` telemetry or
30
+ * a measured subset of the run.
31
+ * @param {{totalTokens: number | null, source: string, measuredSubsetTokens?: number | null}} entry - Parsed usage entry.
32
+ * @returns {boolean} True when the run's tokens are unknown or partial.
33
+ */
34
+ const isPartialRun = entry =>
35
+ entry.totalTokens === null ||
36
+ entry.source === "measured-subset" ||
37
+ (entry.measuredSubsetTokens ?? null) !== null;
38
+
39
+ /**
40
+ * The actual-to-estimate ratio one finished item shows, if it shows one.
41
+ * @param {string} body - Finished item body.
42
+ * @returns {number | null} Ratio, or null when the item cannot calibrate.
43
+ */
44
+ export function itemRatio(body) {
45
+ const { estimate } = parseEstimateSection(body);
46
+ if (
47
+ !estimate ||
48
+ !isPositive(estimate.tokensLow) ||
49
+ !isPositive(estimate.tokensHigh)
50
+ )
51
+ return null;
52
+ let ledger;
53
+ try {
54
+ ledger = parseLisaUsageSection(body);
55
+ } catch {
56
+ return null;
57
+ }
58
+ const { entries, rollup } = ledger;
59
+ const actual = rollup?.totalTokens;
60
+ // The rollup adds up only the runs it knows, so one run without a full
61
+ // token count makes its total a partial sum, not the actual.
62
+ if (
63
+ entries.some(isPartialRun) ||
64
+ rollup?.childTokensIncomplete ||
65
+ !Number.isFinite(actual) ||
66
+ actual <= 0
67
+ )
68
+ return null;
69
+ return actual / ((estimate.tokensLow + estimate.tokensHigh) / 2);
70
+ }
71
+
72
+ /**
73
+ * Median of a non-empty list of numbers.
74
+ * @param {number[]} values - Values.
75
+ * @returns {number} Median.
76
+ */
77
+ function median(values) {
78
+ const sorted = [...values].sort((a, b) => a - b);
79
+ const middle = Math.floor(sorted.length / 2);
80
+ return sorted.length % 2
81
+ ? sorted[middle]
82
+ : (sorted[middle - 1] + sorted[middle]) / 2;
83
+ }
84
+
85
+ /**
86
+ * Calibrate a proposed range against comparable finished items.
87
+ * @param {{tokensLow: number, tokensHigh: number}} proposed - The agent's first estimate.
88
+ * @param {string[]} bodies - Bodies of comparable finished items.
89
+ * @returns {{comparable: number, ratio: number | null, tokensLow: number, tokensHigh: number, basis: string}} Calibrated range.
90
+ */
91
+ export function calibrateEstimate(proposed, bodies) {
92
+ if (proposed.tokensLow > proposed.tokensHigh)
93
+ throw new EstimateConfigError(
94
+ `The low end (${proposed.tokensLow}) is above the high end (${proposed.tokensHigh}).`
95
+ );
96
+ const ratios = bodies.map(itemRatio).filter(ratio => ratio !== null);
97
+ if (ratios.length === 0)
98
+ return {
99
+ comparable: 0,
100
+ ratio: null,
101
+ tokensLow: proposed.tokensLow,
102
+ tokensHigh: proposed.tokensHigh,
103
+ basis: `no calibration history (${bodies.length} item(s) read, none with both an estimate and a complete actual)`,
104
+ };
105
+ const ratio = median(ratios);
106
+ const rounded = Number(ratio.toFixed(2));
107
+ return {
108
+ comparable: ratios.length,
109
+ ratio: rounded,
110
+ tokensLow: Math.max(1, Math.round(proposed.tokensLow * ratio)),
111
+ tokensHigh: Math.max(1, Math.round(proposed.tokensHigh * ratio)),
112
+ basis: `calibrated x${rounded} (median actual/estimate) from ${ratios.length} comparable finished item(s)`,
113
+ };
114
+ }
115
+
116
+ /**
117
+ * Item bodies from a history file: a JSON array of strings, or of objects with
118
+ * a `body` (the shape `gh issue list --json body` prints).
119
+ * @param {unknown} history - Parsed JSON.
120
+ * @returns {string[]} Bodies.
121
+ */
122
+ export function historyBodies(history) {
123
+ if (!Array.isArray(history))
124
+ throw new SyntaxError(
125
+ "The history file must hold a JSON array of item bodies or of objects with a body."
126
+ );
127
+ return history.flatMap(item => {
128
+ if (typeof item === "string") return [item];
129
+ return typeof item?.body === "string" ? [item.body] : [];
130
+ });
131
+ }
@@ -4,20 +4,22 @@
4
4
  /**
5
5
  * The work-item estimate gate (CodySwannGT/lisa#4954): validator gate S21.
6
6
  *
7
- * It runs at ready time. An estimate is not required when an item is created
7
+ * It runs at ready time and again at claim time (CodySwannGT/lisa#4955).
8
+ * An estimate is not required when an item is created
8
9
  * or made ready, because deterministic sources (Sentry, New Relic, monitors)
9
10
  * cannot produce one; the claim step writes it before work begins. What this
10
11
  * gate refuses is an estimate that is present but wrong: unparseable, an
11
12
  * inverted range, a model the project does not allow, a dollar range that is
12
13
  * not a sound range of its own, or one that disagrees with the price table it
13
14
  * names. When `workItem.estimate.required`
14
- * is false the gate is `N/A` and blocks nothing.
15
+ * is false the gate is `N/A` and blocks nothing. At claim time a missing
16
+ * estimate is a FAIL: the claiming agent must write one before any work.
15
17
  * @module scripts/lib/work-item-estimate-check
16
18
  */
17
19
  import { costCents, priceFor } from "./work-item-estimate-config.mjs";
18
20
  import { parseEstimateSection } from "./work-item-estimate.mjs";
19
21
 
20
- const PHASES = new Set(["ready"]);
22
+ const PHASES = new Set(["ready", "claim"]);
21
23
 
22
24
  /**
23
25
  * Problems with a parsed estimate's own fields.
@@ -113,13 +115,13 @@ function pricingProblems(estimate, settings) {
113
115
  * Run the estimate gate on an item body.
114
116
  * @param {string} body - Item body as stored.
115
117
  * @param {object} settings - Result of `resolveEstimateConfig`.
116
- * @param {string} [phase] - Lifecycle moment; only `ready` exists so far.
118
+ * @param {string} [phase] - Lifecycle moment: `ready` (default) or `claim`.
117
119
  * @returns {{verdict: "PASS" | "FAIL" | "N/A", lines: string[]}} Gate result.
118
120
  */
119
121
  export function checkEstimate(body, settings, phase = "ready") {
120
122
  if (!PHASES.has(phase))
121
123
  throw new RangeError(
122
- `Unknown phase ${JSON.stringify(phase)}; expected ready.`
124
+ `Unknown phase ${JSON.stringify(phase)}; expected ready or claim.`
123
125
  );
124
126
  const warnings = settings.warnings ?? [];
125
127
  if (!settings.required)
@@ -136,6 +138,14 @@ export function checkEstimate(body, settings, phase = "ready") {
136
138
  `The body has ${count} Lisa Estimate sections; keep exactly one.`,
137
139
  ],
138
140
  };
141
+ if (count === 0 && phase === "claim")
142
+ return {
143
+ verdict: "FAIL",
144
+ lines: [
145
+ ...warnings,
146
+ "This claimed item has no estimate. Before any work, estimate it (lisa-estimate calibrate, then render) and write the Lisa Estimate section to the item. Never ask a person for it.",
147
+ ],
148
+ };
139
149
  if (count === 0)
140
150
  return {
141
151
  verdict: "PASS",
@@ -15,7 +15,13 @@
15
15
  * node scripts/lisa-estimate.mjs config
16
16
  * node scripts/lisa-estimate.mjs render --tokens-low 2M --tokens-high 4M
17
17
  * --model claude-opus-5-5 [--basis <text>] [--body-file <path>]
18
- * node scripts/lisa-estimate.mjs check [--phase ready] [--body-file <path>]
18
+ * node scripts/lisa-estimate.mjs calibrate --tokens-low 1M --tokens-high 2M
19
+ * --history-file <comparable-items.json>
20
+ * node scripts/lisa-estimate.mjs check [--phase ready|claim] [--body-file <path>]
21
+ *
22
+ * `calibrate` scales a first estimate by how comparable finished items
23
+ * actually ran (their `## Lisa Usage` totals against their estimates) and
24
+ * prints the calibrated range and a basis line to pass to `render`.
19
25
  *
20
26
  * `check` exits 0 on PASS or N/A and 1 on FAIL; any usage or config error
21
27
  * exits 2. Without `--body-file`, the body is read from standard input.
@@ -36,6 +42,10 @@ import {
36
42
  renderEstimateSection,
37
43
  upsertEstimateSection,
38
44
  } from "./lib/work-item-estimate.mjs";
45
+ import {
46
+ calibrateEstimate,
47
+ historyBodies,
48
+ } from "./lib/work-item-estimate-calibration.mjs";
39
49
  import { checkEstimate } from "./lib/work-item-estimate-check.mjs";
40
50
 
41
51
  const VALUE_FLAGS = new Set([
@@ -45,6 +55,7 @@ const VALUE_FLAGS = new Set([
45
55
  "--basis",
46
56
  "--body-file",
47
57
  "--phase",
58
+ "--history-file",
48
59
  "--cwd",
49
60
  ]);
50
61
 
@@ -124,6 +135,20 @@ const COMMANDS = {
124
135
  code: 0,
125
136
  };
126
137
  },
138
+ calibrate: flags => {
139
+ if (flags["history-file"] === undefined)
140
+ throw new EstimateConfigError(
141
+ "calibrate needs --history-file: a JSON array of comparable finished items (gh issue list --json body prints one)."
142
+ );
143
+ const result = calibrateEstimate(
144
+ {
145
+ tokensLow: parseTokenCount(flags["tokens-low"] ?? ""),
146
+ tokensHigh: parseTokenCount(flags["tokens-high"] ?? ""),
147
+ },
148
+ historyBodies(JSON.parse(readFileSync(flags["history-file"], "utf8")))
149
+ );
150
+ return { out: `${JSON.stringify(result, null, 2)}\n`, code: 0 };
151
+ },
127
152
  check: (flags, settings) => {
128
153
  const result = checkEstimate(readBody(flags), settings, flags.phase);
129
154
  const lines = [`S21 token estimate: ${result.verdict}`, ...result.lines];
@@ -135,7 +160,7 @@ const COMMANDS = {
135
160
  };
136
161
 
137
162
  const USAGE =
138
- "Usage: lisa-estimate.mjs config | render --tokens-low <n> --tokens-high <n> --model <id> [--basis <text>] [--body-file <path>] | check [--phase ready] [--body-file <path>]\n";
163
+ "Usage: lisa-estimate.mjs config | render --tokens-low <n> --tokens-high <n> --model <id> [--basis <text>] [--body-file <path>] | calibrate --tokens-low <n> --tokens-high <n> --history-file <path> | check [--phase ready|claim] [--body-file <path>]\n";
139
164
 
140
165
  /**
141
166
  * Run the CLI.
@@ -166,7 +191,8 @@ export function runCli(argv = process.argv.slice(2), io = process) {
166
191
  !(
167
192
  error instanceof EstimateConfigError ||
168
193
  error instanceof RangeError ||
169
- error instanceof SyntaxError
194
+ error instanceof SyntaxError ||
195
+ error?.code === "ENOENT"
170
196
  )
171
197
  )
172
198
  throw error;
@@ -1 +1 @@
1
- {"version":3,"file":"lisa-owned-hash-ledger.d.ts","sourceRoot":"","sources":["../../src/core/lisa-owned-hash-ledger.ts"],"names":[],"mappings":"AACA,6EAA6E;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CA6+FjC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CACpD,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAg5FjC,CAAC"}
1
+ {"version":3,"file":"lisa-owned-hash-ledger.d.ts","sourceRoot":"","sources":["../../src/core/lisa-owned-hash-ledger.ts"],"names":[],"mappings":"AACA,6EAA6E;AAE7E;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAs/FjC,CAAC;AAEH;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CACpD,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAy5FjC,CAAC"}
@@ -1542,9 +1542,16 @@ export const LISA_OWNED_HASH_LEDGER = Object.freeze({
1542
1542
  "5b978f201be9a035001f0cc4a7e8da76a67f26e6f99da91907747c4d65d58f1b",
1543
1543
  "d73b15152703d7f195d1e06f7d7cee5437373237fcd74fe68afbd79fccebc1ba",
1544
1544
  ]),
1545
+ "scripts/lib/work-item-estimate-calibration.mjs": Object.freeze([
1546
+ "1f8b96f438995da18a2e8cab7160c6dfc38c597550839ca4e1694b47e3314893",
1547
+ "a14dad0b6c2a9a6235ee334b07290f0850bd4495f8863f0b0c8ae7fc5b17fa89",
1548
+ "f46576760d27e71b29742fb25a3f9faf5f1c43032f7d2815bc968d0e5c9c15d2",
1549
+ ]),
1545
1550
  "scripts/lib/work-item-estimate-check.mjs": Object.freeze([
1546
1551
  "445732d190b31aec81594bd5fb5a82bc5b1ed16d3a6ff6fa0fe5fb287706a878",
1547
1552
  "4dcea21ae9fe5114964abda7dbadeb5365241893e7e96d83411c27e1b777f5b9",
1553
+ "8335b3f9d15243dff3e6eb74a5352c9ef8e8f3c667cc81996452855274a9ca73",
1554
+ "8b1ff4f4a49ee11358b8717d48628f83bad023273163118b459824f95349a4c4",
1548
1555
  "94e67b413ed4ec852bfa2d594a89deedf776f94d7fffde049a9fd6f2d4365bad",
1549
1556
  ]),
1550
1557
  "scripts/lib/work-item-estimate-config.d.mts": Object.freeze([
@@ -1695,7 +1702,9 @@ export const LISA_OWNED_HASH_LEDGER = Object.freeze({
1695
1702
  "f936bc8a038a7901ade1ba58cc52e5f5a8b8b2a52a9f0c1516567cc80eb02ccb",
1696
1703
  ]),
1697
1704
  "scripts/lisa-estimate.mjs": Object.freeze([
1705
+ "205e859724157edd928095623de95f70fe7b7e5d192ab386282df8ba2644d1de",
1698
1706
  "3e154026f7308947f1d33305d9563d6fdd951ccbfc7f4372f4e48211092bc119",
1707
+ "aecdd8d09dd8d553d68fe85d62280bdfefb7e84a3b6e76940570505e76ec09f4",
1699
1708
  "f5bcb51089ae8c0fb5f0a3e880a532f19ca7f9c5f0f7eadddb9c47cfccbf0965",
1700
1709
  ]),
1701
1710
  "scripts/lisa-evidence-prune.mjs": Object.freeze([
@@ -4589,9 +4598,16 @@ export const LISA_OWNED_HASH_HISTORY_DERIVED = Object.freeze({
4589
4598
  "5b978f201be9a035001f0cc4a7e8da76a67f26e6f99da91907747c4d65d58f1b",
4590
4599
  "d73b15152703d7f195d1e06f7d7cee5437373237fcd74fe68afbd79fccebc1ba",
4591
4600
  ]),
4601
+ "scripts/lib/work-item-estimate-calibration.mjs": Object.freeze([
4602
+ "1f8b96f438995da18a2e8cab7160c6dfc38c597550839ca4e1694b47e3314893",
4603
+ "a14dad0b6c2a9a6235ee334b07290f0850bd4495f8863f0b0c8ae7fc5b17fa89",
4604
+ "f46576760d27e71b29742fb25a3f9faf5f1c43032f7d2815bc968d0e5c9c15d2",
4605
+ ]),
4592
4606
  "scripts/lib/work-item-estimate-check.mjs": Object.freeze([
4593
4607
  "445732d190b31aec81594bd5fb5a82bc5b1ed16d3a6ff6fa0fe5fb287706a878",
4594
4608
  "4dcea21ae9fe5114964abda7dbadeb5365241893e7e96d83411c27e1b777f5b9",
4609
+ "8335b3f9d15243dff3e6eb74a5352c9ef8e8f3c667cc81996452855274a9ca73",
4610
+ "8b1ff4f4a49ee11358b8717d48628f83bad023273163118b459824f95349a4c4",
4595
4611
  "94e67b413ed4ec852bfa2d594a89deedf776f94d7fffde049a9fd6f2d4365bad",
4596
4612
  ]),
4597
4613
  "scripts/lib/work-item-estimate-config.d.mts": Object.freeze([
@@ -4741,7 +4757,9 @@ export const LISA_OWNED_HASH_HISTORY_DERIVED = Object.freeze({
4741
4757
  "f936bc8a038a7901ade1ba58cc52e5f5a8b8b2a52a9f0c1516567cc80eb02ccb",
4742
4758
  ]),
4743
4759
  "scripts/lisa-estimate.mjs": Object.freeze([
4760
+ "205e859724157edd928095623de95f70fe7b7e5d192ab386282df8ba2644d1de",
4744
4761
  "3e154026f7308947f1d33305d9563d6fdd951ccbfc7f4372f4e48211092bc119",
4762
+ "aecdd8d09dd8d553d68fe85d62280bdfefb7e84a3b6e76940570505e76ec09f4",
4745
4763
  "f5bcb51089ae8c0fb5f0a3e880a532f19ca7f9c5f0f7eadddb9c47cfccbf0965",
4746
4764
  ]),
4747
4765
  "scripts/lisa-evidence-prune.mjs": Object.freeze([