@codyswann/lisa 8.0.1 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/all/copy-overwrite/scripts/lib/completion-authorization.mjs +28 -0
- package/all/copy-overwrite/scripts/lib/completion-proof-adapters.mjs +21 -0
- package/all/copy-overwrite/scripts/lib/completion-proof-projection.mjs +25 -41
- package/all/copy-overwrite/scripts/lib/completion-proof-shape.mjs +23 -0
- package/all/copy-overwrite/scripts/lib/npm-update-bun.mjs +8 -3
- package/all/copy-overwrite/scripts/lib/npm-update-cache-seed.mjs +145 -0
- package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +7 -0
- package/all/copy-overwrite/scripts/lib/npm-update-prepare.mjs +34 -6
- package/all/copy-overwrite/scripts/lib/tracker-row-fold.mjs +48 -0
- package/all/copy-overwrite/scripts/lib/work-item-estimate-actual.mjs +131 -0
- package/all/copy-overwrite/scripts/lib/work-item-estimate-calibration.mjs +16 -33
- package/all/copy-overwrite/scripts/lib/work-item-estimate-check.mjs +26 -5
- package/all/copy-overwrite/scripts/lib/work-item-estimate-config.mjs +21 -0
- package/all/copy-overwrite/scripts/lib/work-item-estimate-tally.mjs +272 -0
- package/all/copy-overwrite/scripts/lib/work-item-estimate.mjs +60 -31
- package/all/copy-overwrite/scripts/lisa-estimate.mjs +60 -9
- package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +74 -10
- package/dist/core/lisa-owned-hash-ledger.json +112 -6
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.json +48 -19
- package/dist/utils/usage-accounting-totals.d.ts.map +1 -1
- package/dist/utils/usage-accounting-totals.js +6 -1
- package/dist/utils/usage-accounting-totals.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-tracker-evidence/SKILL.md +1 -0
- package/plugins/lisa/.codex-plugin/skills/lisa-usage-accounting/SKILL.md +2 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-usage-accounting/references/estimate.md +49 -0
- package/plugins/lisa/rules/reference/work-item-definition-of-ready.md +5 -2
- package/plugins/lisa/skills/lisa-tracker-evidence/SKILL.md +1 -0
- package/plugins/lisa/skills/lisa-usage-accounting/SKILL.md +2 -1
- package/plugins/lisa/skills/lisa-usage-accounting/references/estimate.md +49 -0
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-tracker-evidence/SKILL.md +1 -0
- package/plugins/lisa-agy/skills/lisa-usage-accounting/SKILL.md +2 -1
- package/plugins/lisa-agy/skills/lisa-usage-accounting/references/estimate.md +49 -0
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/rules/reference/work-item-definition-of-ready.md +5 -2
- package/plugins/lisa-copilot/skills/lisa-tracker-evidence/SKILL.md +1 -0
- package/plugins/lisa-copilot/skills/lisa-usage-accounting/SKILL.md +2 -1
- package/plugins/lisa-copilot/skills/lisa-usage-accounting/references/estimate.md +49 -0
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/rules/work-item-definition-of-ready-reference.mdc +5 -2
- package/plugins/lisa-cursor/skills/lisa-tracker-evidence/SKILL.md +1 -0
- package/plugins/lisa-cursor/skills/lisa-usage-accounting/SKILL.md +2 -1
- package/plugins/lisa-cursor/skills/lisa-usage-accounting/references/estimate.md +49 -0
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/rules/reference/work-item-definition-of-ready.md +5 -2
- package/plugins/lisa-devin/skills/lisa-tracker-evidence/SKILL.md +1 -0
- package/plugins/lisa-devin/skills/lisa-usage-accounting/SKILL.md +2 -1
- package/plugins/lisa-devin/skills/lisa-usage-accounting/references/estimate.md +49 -0
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/rules/reference/work-item-definition-of-ready.md +5 -2
- package/plugins/src/base/skills/lisa-tracker-evidence/SKILL.md +1 -0
- package/plugins/src/base/skills/lisa-usage-accounting/SKILL.md +2 -1
- package/plugins/src/base/skills/lisa-usage-accounting/references/estimate.md +49 -0
- package/scripts/record-npm-update-dual-lock-seed.mjs +203 -0
- package/scripts/two-channel-couplings.json +1 -1
- package/typescript/copy-overwrite/.prettierignore +4 -0
|
@@ -34,9 +34,32 @@ import {
|
|
|
34
34
|
validateDelivery,
|
|
35
35
|
} from "./completion-proof-source.mjs";
|
|
36
36
|
import { validateConformance } from "./completion-proof-conformance.mjs";
|
|
37
|
+
import { checkEstimate } from "./work-item-estimate-check.mjs";
|
|
37
38
|
|
|
38
39
|
const PENDING_PROOF = "pending-proof";
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* The token-estimate done gate (CodySwannGT/lisa#4956): when
|
|
43
|
+
* `workItem.estimate.required` holds, the item needs a usage-ledger entry and
|
|
44
|
+
* an up-to-date actual tally beside its estimate before it may reach done.
|
|
45
|
+
* `completionContext` always resolves the settings; a hand-built context that
|
|
46
|
+
* carries none has made no claim about them, so there is nothing to check.
|
|
47
|
+
*/
|
|
48
|
+
function validateEstimateTally(body, documents, context) {
|
|
49
|
+
const settings = context.estimate;
|
|
50
|
+
if (!settings) return;
|
|
51
|
+
requireProof(
|
|
52
|
+
!settings.error,
|
|
53
|
+
`workItem.estimate in .lisa.config.json cannot be used: ${settings.error}`
|
|
54
|
+
);
|
|
55
|
+
const result = checkEstimate(body, settings, "done", documents);
|
|
56
|
+
requireProof(
|
|
57
|
+
result.verdict !== "FAIL",
|
|
58
|
+
`The token estimate is not tallied for done. ${result.lines.join(" ")}`,
|
|
59
|
+
PENDING_PROOF
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
40
63
|
/** Stable user-facing next action, without declaring merely pending delivery failed. */
|
|
41
64
|
const NEXT =
|
|
42
65
|
"Run canonical Verify/evidence, publish the accepted completion proof, then retry completion.";
|
|
@@ -245,6 +268,11 @@ export function authorizeCompletion(context) {
|
|
|
245
268
|
chosen.record.obligations.usage.entry_ids,
|
|
246
269
|
context
|
|
247
270
|
);
|
|
271
|
+
validateEstimateTally(
|
|
272
|
+
fresh.body,
|
|
273
|
+
[fresh.body, ...comments.map(row => row.body)],
|
|
274
|
+
context
|
|
275
|
+
);
|
|
248
276
|
requireProof(
|
|
249
277
|
context.hasBacklink(fresh, evaluated.primary.html_url),
|
|
250
278
|
"The primary pull-request backlink changed before the terminal write; restore canonical linkage.",
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
// Do not edit directly — durable changes belong upstream in Lisa.
|
|
3
3
|
|
|
4
4
|
/** Provider-native proof discovery/publication adapters; credentials stay in CLI. */
|
|
5
|
+
import {
|
|
6
|
+
EstimateConfigError,
|
|
7
|
+
resolveEstimateGate,
|
|
8
|
+
} from "./work-item-estimate-config.mjs";
|
|
5
9
|
import {
|
|
6
10
|
CompletionProofError,
|
|
7
11
|
MAX_NATIVE_JSON_BYTES,
|
|
@@ -12,6 +16,22 @@ const READ_ERROR = "read-error";
|
|
|
12
16
|
const WRITE_ERROR = "write-error";
|
|
13
17
|
|
|
14
18
|
/** Construct the same strict authorizer context for supported lifecycle writers. */
|
|
19
|
+
/**
|
|
20
|
+
* The project's token-estimate settings for the done gate
|
|
21
|
+
* (CodySwannGT/lisa#4956). An unusable `workItem.estimate` is carried as an
|
|
22
|
+
* error so completion refuses with the reason instead of crashing, unless the
|
|
23
|
+
* project turned the gate off: then the gate never reads those settings, so
|
|
24
|
+
* they cannot refuse completion either.
|
|
25
|
+
*/
|
|
26
|
+
function estimateSettings(config) {
|
|
27
|
+
try {
|
|
28
|
+
return resolveEstimateGate(config);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (!(error instanceof EstimateConfigError)) throw error;
|
|
31
|
+
return { required: true, error: error.message };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
15
35
|
export function completionContext(options) {
|
|
16
36
|
const { ref, contract, run, declares, hasBacklink } = options;
|
|
17
37
|
const github = contract.provider === "github";
|
|
@@ -164,6 +184,7 @@ export function completionContext(options) {
|
|
|
164
184
|
branch,
|
|
165
185
|
suppliedPrUrl: options.prUrl,
|
|
166
186
|
policy: options.config.verification?.completion ?? {},
|
|
187
|
+
estimate: estimateSettings(options.config),
|
|
167
188
|
run,
|
|
168
189
|
declares,
|
|
169
190
|
readSubject,
|
|
@@ -5,50 +5,20 @@
|
|
|
5
5
|
import { parseLisaUsageSection } from "./usage-ledger.mjs";
|
|
6
6
|
import { isLisaUsageLedgerIntact } from "./usage-ledger-integrity.mjs";
|
|
7
7
|
import { requireProof } from "./completion-proof-errors.mjs";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const normalizedRow = line =>
|
|
11
|
-
line
|
|
12
|
-
.trim()
|
|
13
|
-
.split("|")
|
|
14
|
-
.map(part => part.trim())
|
|
15
|
-
.join("|");
|
|
16
|
-
|
|
17
|
-
const CANONICAL_ALIGNMENT = "|---|---|---|---:|---:|";
|
|
18
|
-
const ALIGNMENT_ROW = /^\|(?::?-+:?\|){5}$/;
|
|
19
|
-
const LEADING_STAR_ITALIC = /^(\|?)\*([^*\r\n]+)\*(?=\||$)/;
|
|
20
|
-
const ESCAPED_PUNCTUATION = /\\([!-/:-@[-`{-~])/g;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Fold Linear's storage normalization back to the canonical writer's form
|
|
24
|
-
* (CodySwannGT/lisa#4690): Linear escapes Markdown punctuation one layer deep
|
|
25
|
-
* (`\_`, `\.`), re-serializes `_…_` as `*…*`, and rewrites any table
|
|
26
|
-
* alignment row as `| -- | … |`. Only the comparison key changes, and known
|
|
27
|
-
* rows pass through the same fold, so a line is dropped solely when its key
|
|
28
|
-
* equals a known canonical row; any other prose or row still reaches the
|
|
29
|
-
* spec digest.
|
|
30
|
-
*
|
|
31
|
-
* Accepted limitation: any 5-cell alignment row folds to the canonical
|
|
32
|
-
* separator, so an extra alignment row inserted into the section is
|
|
33
|
-
* digest-invisible. Such a row carries only dashes and colons, so no
|
|
34
|
-
* specification words can hide that way.
|
|
35
|
-
*/
|
|
36
|
-
function comparisonKey(line) {
|
|
37
|
-
const row = normalizedRow(line.replace(ESCAPED_PUNCTUATION, "$1"));
|
|
38
|
-
return ALIGNMENT_ROW.test(row)
|
|
39
|
-
? CANONICAL_ALIGNMENT
|
|
40
|
-
: row.replace(LEADING_STAR_ITALIC, "$1_$2_");
|
|
41
|
-
}
|
|
8
|
+
import { trackerRowKey as comparisonKey } from "./tracker-row-fold.mjs";
|
|
9
|
+
import { humanLines } from "./work-item-estimate.mjs";
|
|
42
10
|
|
|
43
11
|
/** Match the canonical writer's visible table rows to the already parsed data. */
|
|
44
12
|
function accountingRows(entries) {
|
|
45
|
-
const known = new Set(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
13
|
+
const known = new Set(
|
|
14
|
+
[
|
|
15
|
+
"## Lisa Usage",
|
|
16
|
+
"_This section is managed by Lisa. Rewrites update matching usage entries in place and preserve older rows._",
|
|
17
|
+
"|Flow|Source|Model|Tokens|Cost|",
|
|
18
|
+
"|---|---|---|---:|---:|",
|
|
19
|
+
"|_No direct entries recorded_|||||",
|
|
20
|
+
].map(comparisonKey)
|
|
21
|
+
);
|
|
52
22
|
for (const entry of entries) {
|
|
53
23
|
const tokens =
|
|
54
24
|
entry.totalTokens !== null
|
|
@@ -127,6 +97,20 @@ export function usageSpecRemainder(document) {
|
|
|
127
97
|
.join("");
|
|
128
98
|
}
|
|
129
99
|
|
|
100
|
+
/**
|
|
101
|
+
* A `## Lisa Estimate` section without the lines Lisa wrote
|
|
102
|
+
* (CodySwannGT/lisa#4956). The estimate and its actual tally are rewritten as
|
|
103
|
+
* work is claimed and completed, so they are metadata, like the usage ledger,
|
|
104
|
+
* not requirements: rewriting them must not invalidate an accepted proof. Only
|
|
105
|
+
* the exact lines re-rendering the section's own tokens produces are dropped;
|
|
106
|
+
* every other line, whatever it starts with, is a person's and stays in the
|
|
107
|
+
* spec digest.
|
|
108
|
+
*/
|
|
109
|
+
export function estimateSpecRemainder(document) {
|
|
110
|
+
const human = humanLines(document);
|
|
111
|
+
return human.length ? `${human.join("\n")}\n` : "";
|
|
112
|
+
}
|
|
113
|
+
|
|
130
114
|
/** Only a closed canonical metadata schema can be omitted from the primary spec. */
|
|
131
115
|
export function canonicalCompletionBlock(name, payload) {
|
|
132
116
|
let value;
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "./completion-proof-markdown.mjs";
|
|
10
10
|
import {
|
|
11
11
|
canonicalCompletionBlock,
|
|
12
|
+
estimateSpecRemainder,
|
|
12
13
|
usageSpecRemainder,
|
|
13
14
|
} from "./completion-proof-projection.mjs";
|
|
14
15
|
import {
|
|
@@ -75,6 +76,27 @@ export const isTime = value =>
|
|
|
75
76
|
/(?:Z|\+00:00)$/.test(value) &&
|
|
76
77
|
Number.isFinite(Date.parse(value));
|
|
77
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Drop the machine-written lines of the `## Lisa Estimate` section
|
|
81
|
+
* (CodySwannGT/lisa#4956), keeping any prose a person added there.
|
|
82
|
+
*/
|
|
83
|
+
function withoutEstimateMetadata(body) {
|
|
84
|
+
const headings = topLevelLines(body).filter(row => row.heading);
|
|
85
|
+
const estimate = headings.filter(row => row.text === "## Lisa Estimate");
|
|
86
|
+
requireProof(
|
|
87
|
+
estimate.length <= 1,
|
|
88
|
+
"Duplicate token-estimate sections make the primary specification ambiguous."
|
|
89
|
+
);
|
|
90
|
+
if (!estimate.length) return body;
|
|
91
|
+
const start = estimate[0].start;
|
|
92
|
+
const end = headings.find(row => row.start > start)?.start ?? body.length;
|
|
93
|
+
return (
|
|
94
|
+
body.slice(0, start) +
|
|
95
|
+
estimateSpecRemainder(body.slice(start, end)) +
|
|
96
|
+
body.slice(end)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
78
100
|
/** Remove only exact canonical machine-owned sections, retaining unknown prose. */
|
|
79
101
|
export function primarySpecProjection(body) {
|
|
80
102
|
requireProof(
|
|
@@ -96,6 +118,7 @@ export function primarySpecProjection(body) {
|
|
|
96
118
|
usageSpecRemainder(body.slice(start, end)) +
|
|
97
119
|
body.slice(end);
|
|
98
120
|
}
|
|
121
|
+
result = withoutEstimateMetadata(result);
|
|
99
122
|
for (const name of ["authorization", "postcondition"]) {
|
|
100
123
|
const start = `<!-- lisa:completion-${name}:start -->`;
|
|
101
124
|
const end = `<!-- lisa:completion-${name}:end -->`;
|
|
@@ -103,13 +103,16 @@ function toolIdentity(path) {
|
|
|
103
103
|
* Only the original trusted PATH may select a supported native Bun installation.
|
|
104
104
|
* Each call is capped at `ceiling` (two minutes by default); a whole-root install
|
|
105
105
|
* passes its remaining phase budget instead, as the npm path does.
|
|
106
|
+
*
|
|
107
|
+
* `offline` adds `--offline` to every `bun install`, for a private root given
|
|
108
|
+
* a cache seed (`./npm-update-cache-seed.mjs`); it is never set otherwise.
|
|
106
109
|
* @param {NodeJS.ProcessEnv} env - Trusted environment whose PATH selects Bun.
|
|
107
|
-
* @param {{ executable?: string, deadline?: number, ceiling?: number }} [options] - Explicit executable, phase deadline
|
|
110
|
+
* @param {{ executable?: string, deadline?: number, ceiling?: number, offline?: boolean }} [options] - Explicit executable, phase deadline, per-call ceiling and offline installs.
|
|
108
111
|
* @returns {Promise<(args: string[], options?: Record<string, any>) => Promise<any>>} A bounded Bun invoker.
|
|
109
112
|
*/
|
|
110
113
|
export async function qualifiedBun(
|
|
111
114
|
env,
|
|
112
|
-
{ executable, deadline, ceiling = 120_000 } = {}
|
|
115
|
+
{ executable, deadline, ceiling = 120_000, offline = false } = {}
|
|
113
116
|
) {
|
|
114
117
|
const path =
|
|
115
118
|
executable ??
|
|
@@ -135,7 +138,9 @@ export async function qualifiedBun(
|
|
|
135
138
|
Number.isSafeInteger(timeout) && timeout > 0,
|
|
136
139
|
"original Bun operation deadline expired"
|
|
137
140
|
);
|
|
138
|
-
const
|
|
141
|
+
const installArgs =
|
|
142
|
+
offline && args[0] === "install" ? [...args, "--offline"] : args;
|
|
143
|
+
const result = await runProcess(absolute, installArgs, {
|
|
139
144
|
...options,
|
|
140
145
|
env: { ...env, BUN_FEATURE_FLAG_DISABLE_NATIVE_DEPENDENCY_LINKER: "1" },
|
|
141
146
|
timeout,
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
* @file npm-update-cache-seed.mjs
|
|
6
|
+
* @description A pre-filled npm and Bun cache for one private updater root.
|
|
7
|
+
*
|
|
8
|
+
* Only an explicit `cacheSeed` option on `prepareUpdate` reaches this, never
|
|
9
|
+
* the environment, so a host cannot turn it on: the updater's only production
|
|
10
|
+
* caller passes no such option. The registry stays the hardcoded public one.
|
|
11
|
+
*
|
|
12
|
+
* What a seed can decide, and what bounds it (CodySwannGT/lisa#5092):
|
|
13
|
+
* - npm checks every cached tarball against the lock's integrity, so for a
|
|
14
|
+
* package the host's lock pins, a seed can only supply those bytes or fail.
|
|
15
|
+
* - For the update itself, the seed is the registry: its metadata decides the
|
|
16
|
+
* integrity written into the proposed lock. `prepareUpdate` therefore marks
|
|
17
|
+
* a seeded proposal, and every later phase refuses it.
|
|
18
|
+
* - Bun writes bun.lock from its own cached manifests, and `verifyBunLock`
|
|
19
|
+
* refuses a bun.lock whose identity or integrity differs from npm's lock.
|
|
20
|
+
* - Bun installs its cached, already extracted packages without hashing them
|
|
21
|
+
* again. They land only in the private root, under `--ignore-scripts`, and
|
|
22
|
+
* the updater reads nothing from them but `package.json` versions, then
|
|
23
|
+
* deletes the root; only lock files leave it.
|
|
24
|
+
*
|
|
25
|
+
* The seed is copied into the private root and never written. A seed that is
|
|
26
|
+
* not an owned, plain directory tree is refused before anything is copied,
|
|
27
|
+
* and the copy is checked again where nothing else can change it.
|
|
28
|
+
* @module npm-updater
|
|
29
|
+
*/
|
|
30
|
+
import { cpSync, lstatSync, readdirSync, realpathSync } from "node:fs";
|
|
31
|
+
import { isAbsolute, join } from "node:path";
|
|
32
|
+
import { required } from "./npm-update-contract.mjs";
|
|
33
|
+
|
|
34
|
+
/** The caches a seed may hold, and nothing else. */
|
|
35
|
+
const SEED_KEYS = ["bun", "npm"];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Where Bun keeps its cache inside a private root.
|
|
39
|
+
* @param {string} root - The private root, which is also HOME.
|
|
40
|
+
* @returns {string} The cache folder.
|
|
41
|
+
*/
|
|
42
|
+
export function bunCacheIn(root) {
|
|
43
|
+
return join(root, ".bun", "install", "cache");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Refuse anything in a seed but owned folders and files nobody else can write.
|
|
48
|
+
* @param {string} path - An absolute path inside the seed.
|
|
49
|
+
* @param {number} uid - The updater's user.
|
|
50
|
+
*/
|
|
51
|
+
function requireOwnedTree(path, uid) {
|
|
52
|
+
const entry = lstatSync(path);
|
|
53
|
+
required(
|
|
54
|
+
(entry.isDirectory() || entry.isFile()) && !entry.isSymbolicLink(),
|
|
55
|
+
"cache seed holds something that is not a plain file or folder"
|
|
56
|
+
);
|
|
57
|
+
required(entry.uid === uid, "cache seed is not owned by the updater's user");
|
|
58
|
+
required(
|
|
59
|
+
(entry.mode & 0o022) === 0,
|
|
60
|
+
"cache seed is writable by another user"
|
|
61
|
+
);
|
|
62
|
+
if (entry.isDirectory())
|
|
63
|
+
for (const name of readdirSync(path))
|
|
64
|
+
requireOwnedTree(join(path, name), uid);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check one seed folder before anything is copied from it.
|
|
69
|
+
* @param {unknown} folder - The folder the caller named.
|
|
70
|
+
* @returns {string} The folder, proven absolute, real and owned.
|
|
71
|
+
*/
|
|
72
|
+
function seedFolder(folder) {
|
|
73
|
+
required(
|
|
74
|
+
typeof folder === "string" && isAbsolute(folder),
|
|
75
|
+
"cache seed folder must be an absolute path"
|
|
76
|
+
);
|
|
77
|
+
required(
|
|
78
|
+
realpathSync(folder) === folder,
|
|
79
|
+
"cache seed folder must not pass through a link"
|
|
80
|
+
);
|
|
81
|
+
required(
|
|
82
|
+
lstatSync(folder).isDirectory(),
|
|
83
|
+
"cache seed folder must be a folder"
|
|
84
|
+
);
|
|
85
|
+
requireOwnedTree(folder, process.getuid());
|
|
86
|
+
return folder;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Validate a cache seed. `undefined` is no seed, and changes nothing.
|
|
91
|
+
* @param {unknown} seed - `{ npm, bun? }`, absolute folders, or undefined.
|
|
92
|
+
* @returns {{ npm: string, bun?: string } | undefined} The checked seed.
|
|
93
|
+
*/
|
|
94
|
+
export function validCacheSeed(seed) {
|
|
95
|
+
if (seed === undefined) return undefined;
|
|
96
|
+
required(
|
|
97
|
+
seed !== null && typeof seed === "object" && !Array.isArray(seed),
|
|
98
|
+
"cache seed must be an object"
|
|
99
|
+
);
|
|
100
|
+
const keys = Object.keys(seed).sort();
|
|
101
|
+
required(
|
|
102
|
+
keys.includes("npm") && keys.every(key => SEED_KEYS.includes(key)),
|
|
103
|
+
"cache seed names only an npm folder and, optionally, a Bun folder"
|
|
104
|
+
);
|
|
105
|
+
return {
|
|
106
|
+
npm: seedFolder(seed.npm),
|
|
107
|
+
...(seed.bun === undefined ? {} : { bun: seedFolder(seed.bun) }),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Copy a checked seed into a private root and put npm offline there.
|
|
113
|
+
*
|
|
114
|
+
* Bun is put offline by `prepareUpdate`, which passes `offline` to every Bun
|
|
115
|
+
* install whenever a seed is given, and refuses a seed with no Bun folder for
|
|
116
|
+
* a host that commits bun.lock.
|
|
117
|
+
*
|
|
118
|
+
* Without a seed the environment comes back unchanged, so an updater run that
|
|
119
|
+
* was given none behaves exactly as before.
|
|
120
|
+
* @param {string} root - The private root.
|
|
121
|
+
* @param {NodeJS.ProcessEnv} env - The private root's environment.
|
|
122
|
+
* @param {{ npm: string, bun?: string } | undefined} seed - From {@link validCacheSeed}.
|
|
123
|
+
* @returns {NodeJS.ProcessEnv} The environment npm and Bun run in.
|
|
124
|
+
*/
|
|
125
|
+
export function seedPrivateRoot(root, env, seed) {
|
|
126
|
+
if (seed === undefined) return env;
|
|
127
|
+
const npmCache = env.NPM_CONFIG_CACHE;
|
|
128
|
+
required(
|
|
129
|
+
typeof npmCache === "string" && npmCache.startsWith(`${root}/`),
|
|
130
|
+
"private npm cache is outside the private root"
|
|
131
|
+
);
|
|
132
|
+
const copies = [[seed.npm, npmCache]];
|
|
133
|
+
if (seed.bun !== undefined) copies.push([seed.bun, bunCacheIn(root)]);
|
|
134
|
+
for (const [source, target] of copies) {
|
|
135
|
+
cpSync(source, target, {
|
|
136
|
+
recursive: true,
|
|
137
|
+
errorOnExist: true,
|
|
138
|
+
force: false,
|
|
139
|
+
});
|
|
140
|
+
// The source was checked before this copy and could have changed since;
|
|
141
|
+
// the copy sits in the private root, which only this user can reach.
|
|
142
|
+
requireOwnedTree(target, process.getuid());
|
|
143
|
+
}
|
|
144
|
+
return { ...env, NPM_CONFIG_OFFLINE: "true" };
|
|
145
|
+
}
|
|
@@ -27,10 +27,16 @@ const COMMON = [
|
|
|
27
27
|
"lib/completion-proof-shape.mjs",
|
|
28
28
|
"lib/completion-proof-source.mjs",
|
|
29
29
|
"lib/evidence-release-capacity.mjs",
|
|
30
|
+
"lib/tracker-row-fold.mjs",
|
|
30
31
|
"lib/usage-artifact-ref.mjs",
|
|
31
32
|
"lib/usage-effectiveness.mjs",
|
|
32
33
|
"lib/usage-ledger-integrity.mjs",
|
|
33
34
|
"lib/usage-ledger.mjs",
|
|
35
|
+
"lib/work-item-estimate.mjs",
|
|
36
|
+
"lib/work-item-estimate-actual.mjs",
|
|
37
|
+
"lib/work-item-estimate-check.mjs",
|
|
38
|
+
"lib/work-item-estimate-config.mjs",
|
|
39
|
+
"lib/work-item-estimate-tally.mjs",
|
|
34
40
|
"lib/process-tree-runner.mjs",
|
|
35
41
|
"lib/windows-process-job.mjs",
|
|
36
42
|
"lib/windows-process-job.ps1",
|
|
@@ -70,6 +76,7 @@ const PRODUCER = [
|
|
|
70
76
|
"authorization",
|
|
71
77
|
"broker-client",
|
|
72
78
|
"bun",
|
|
79
|
+
"cache-seed",
|
|
73
80
|
"cancel-origin",
|
|
74
81
|
"cancellation",
|
|
75
82
|
"cancellation-proof",
|
|
@@ -35,6 +35,7 @@ export { qualifyLisaOwner } from "./npm-update-owner.mjs";
|
|
|
35
35
|
import { sha256 } from "./github-attestation-verifier.mjs";
|
|
36
36
|
import { directoryBun, qualifiedBun, frozenBun } from "./npm-update-bun.mjs";
|
|
37
37
|
import { npmPath } from "./automation-provenance-contract.mjs";
|
|
38
|
+
import { seedPrivateRoot, validCacheSeed } from "./npm-update-cache-seed.mjs";
|
|
38
39
|
|
|
39
40
|
const NPM_FLAGS = ["--ignore-scripts", "--no-audit", "--no-fund"];
|
|
40
41
|
|
|
@@ -94,7 +95,7 @@ export async function baseline(
|
|
|
94
95
|
return { parent, files };
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
/** Installed evidence and
|
|
98
|
+
/** Installed evidence and selected registry metadata define the update set; under a cache seed that metadata is the seed's. */
|
|
98
99
|
async function findUpdates(
|
|
99
100
|
before,
|
|
100
101
|
policy,
|
|
@@ -227,12 +228,24 @@ async function preparedProposal({
|
|
|
227
228
|
};
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
/**
|
|
231
|
-
|
|
231
|
+
/**
|
|
232
|
+
* The private resource lifecycle remains outside the prepared proposal's npm checks; the baseline proves the directory before npm reads its config.
|
|
233
|
+
*
|
|
234
|
+
* `cacheSeed` is an explicit option, never read from the environment: it
|
|
235
|
+
* pre-fills the private root's npm (and Bun) cache and puts npm and every Bun
|
|
236
|
+
* install offline, for a caller that serves recorded registry data (see
|
|
237
|
+
* `./npm-update-cache-seed.mjs`). A seed without a Bun folder is refused for
|
|
238
|
+
* a host that commits bun.lock, before any install runs.
|
|
239
|
+
* The production caller passes none, and a seeded proposal is marked so no
|
|
240
|
+
* later phase accepts it.
|
|
241
|
+
*/
|
|
242
|
+
export async function prepareUpdate({ cwd, policy: input, config, cacheSeed }) {
|
|
232
243
|
const policy = validatePolicy(input, config);
|
|
244
|
+
const seed = validCacheSeed(cacheSeed);
|
|
233
245
|
let privatePath;
|
|
234
|
-
const result = await withPrivateRoot(async (root,
|
|
246
|
+
const result = await withPrivateRoot(async (root, privateEnv) => {
|
|
235
247
|
privatePath = root;
|
|
248
|
+
const env = seedPrivateRoot(root, privateEnv, seed);
|
|
236
249
|
const app = join(root, "app");
|
|
237
250
|
mkdirSync(app, { mode: 0o700 });
|
|
238
251
|
required(process.versions.node === "22.23.3", "Node22.23.3 is required");
|
|
@@ -244,6 +257,14 @@ export async function prepareUpdate({ cwd, policy: input, config }) {
|
|
|
244
257
|
"supported npm10.9.9 or11.21.0 is required"
|
|
245
258
|
);
|
|
246
259
|
const original = await baseline(cwd, env, undefined, policy.directory);
|
|
260
|
+
// A seed puts Bun offline too, so a Bun host needs Bun's cache in it: say
|
|
261
|
+
// so here, before any install, rather than as a cache miss later.
|
|
262
|
+
required(
|
|
263
|
+
seed === undefined ||
|
|
264
|
+
seed.bun !== undefined ||
|
|
265
|
+
original.files["bun.lock"] === undefined,
|
|
266
|
+
"cache seed has no Bun folder, and this host commits bun.lock"
|
|
267
|
+
);
|
|
247
268
|
const strict = await effectiveEngineStrict(join(cwd, policy.directory));
|
|
248
269
|
const npmFlags = [...NPM_FLAGS, ...(strict ? ["--engine-strict"] : [])];
|
|
249
270
|
const before = JSON.parse(original.files["package.json"]);
|
|
@@ -260,7 +281,7 @@ export async function prepareUpdate({ cwd, policy: input, config }) {
|
|
|
260
281
|
const bun =
|
|
261
282
|
original.files["bun.lock"] === undefined
|
|
262
283
|
? undefined
|
|
263
|
-
: await qualifiedBun(env);
|
|
284
|
+
: await qualifiedBun(env, { offline: seed !== undefined });
|
|
264
285
|
const npm = (args, allowed = [0]) =>
|
|
265
286
|
runNpm(args, { cwd: app, env, timeout: 120_000, allowed });
|
|
266
287
|
await npm(["ci", ...npmFlags]);
|
|
@@ -296,5 +317,12 @@ export async function prepareUpdate({ cwd, policy: input, config }) {
|
|
|
296
317
|
});
|
|
297
318
|
});
|
|
298
319
|
required(!existsSync(privatePath), "private npm resources remain");
|
|
299
|
-
|
|
320
|
+
// A seed decides the registry metadata, and so the lock integrity, of every
|
|
321
|
+
// package the host's lock does not already pin. `validateProposal` accepts
|
|
322
|
+
// only its exact fields, so every phase after prepare refuses this mark.
|
|
323
|
+
const marked =
|
|
324
|
+
seed !== undefined && "proposal" in result
|
|
325
|
+
? { ...result, proposal: { ...result.proposal, seeded: true } }
|
|
326
|
+
: result;
|
|
327
|
+
return { ...marked, cleanup: { absent: true } };
|
|
300
328
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
* The comparison key that matches a line a tracker stored against the line
|
|
6
|
+
* Lisa's writer rendered (CodySwannGT/lisa#4690, #4956).
|
|
7
|
+
*
|
|
8
|
+
* Linear escapes Markdown punctuation one layer deep (`\_`, `\.`),
|
|
9
|
+
* re-serializes `_…_` as `*…*`, and rewrites any table alignment row as
|
|
10
|
+
* `| -- | … |`, dropping its colons. Only the comparison key changes, and the
|
|
11
|
+
* writer's rows pass through the same fold, so a line counts as Lisa's solely
|
|
12
|
+
* when its key equals a known rendered row; any other prose or row still
|
|
13
|
+
* reaches the spec digest.
|
|
14
|
+
*
|
|
15
|
+
* Accepted limitation: every alignment row with the same number of cells
|
|
16
|
+
* folds to one key, so an extra alignment row inserted next to a managed one
|
|
17
|
+
* is indistinguishable from it. Such a row carries only dashes and colons, so
|
|
18
|
+
* no specification words can hide that way.
|
|
19
|
+
* @module scripts/lib/tracker-row-fold
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const ALIGNMENT_ROW = /^\|(?::?-+:?\|)+$/;
|
|
23
|
+
const LEADING_STAR_ITALIC = /^(\|?)\*([^*\r\n]+)\*(?=\||$)/;
|
|
24
|
+
const ESCAPED_PUNCTUATION = /\\([!-/:-@[-`{-~])/g;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Trim a line and every table cell in it.
|
|
28
|
+
* @param {string} line - Stored or rendered line.
|
|
29
|
+
* @returns {string} The line with cell padding removed.
|
|
30
|
+
*/
|
|
31
|
+
const normalizedRow = line =>
|
|
32
|
+
line
|
|
33
|
+
.trim()
|
|
34
|
+
.split("|")
|
|
35
|
+
.map(part => part.trim())
|
|
36
|
+
.join("|");
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The key two lines share when one is a tracker's rewrite of the other.
|
|
40
|
+
* @param {string} line - Stored or rendered line.
|
|
41
|
+
* @returns {string} The comparison key.
|
|
42
|
+
*/
|
|
43
|
+
export function trackerRowKey(line) {
|
|
44
|
+
const row = normalizedRow(line.replace(ESCAPED_PUNCTUATION, "$1"));
|
|
45
|
+
if (ALIGNMENT_ROW.test(row))
|
|
46
|
+
return `|${"---|".repeat(row.split("|").length - 2)}`;
|
|
47
|
+
return row.replace(LEADING_STAR_ITALIC, "$1_$2_");
|
|
48
|
+
}
|
|
@@ -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
|
+
* The actual-spend lines of the `## Lisa Estimate` section
|
|
6
|
+
* (CodySwannGT/lisa#4956): the `Actual` row, its note and the
|
|
7
|
+
* `<!-- lisa:estimate-actual ... -->` token, rendered and read back.
|
|
8
|
+
*
|
|
9
|
+
* Reading the token back lets the section tell exactly which of its lines
|
|
10
|
+
* Lisa wrote: re-rendering the recorded actual reproduces them, so anything
|
|
11
|
+
* else is a person's text, kept on rewrite and counted in the specification.
|
|
12
|
+
* @module scripts/lib/work-item-estimate-actual
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const ACTUAL_PATTERN = /<!-- lisa:estimate-actual ((?:[a-z_]+=\S*\s+)+)-->/;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {object} Actual
|
|
19
|
+
* @property {number | null} tokens - Complete token total, or null when unknown.
|
|
20
|
+
* @property {number | null} cost - Total cost, or null when unknown.
|
|
21
|
+
* @property {string | null} currency - Cost currency.
|
|
22
|
+
* @property {string[]} sources - Distinct usage `source` values behind the total.
|
|
23
|
+
* @property {number} entries - Usage entries the total covers.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Human-readable token count: 2000000 -> "2M", 1500 -> "1.5k".
|
|
28
|
+
* @param {number} tokens - Token count.
|
|
29
|
+
* @returns {string} Short form.
|
|
30
|
+
*/
|
|
31
|
+
export function formatTokens(tokens) {
|
|
32
|
+
const short = (value, unit) =>
|
|
33
|
+
`${Number(value.toFixed(2)).toString()}${unit}`;
|
|
34
|
+
if (tokens >= 1_000_000) return short(tokens / 1_000_000, "M");
|
|
35
|
+
if (tokens >= 1_000) return short(tokens / 1_000, "k");
|
|
36
|
+
return String(tokens);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Render the actual row, note and token.
|
|
41
|
+
* @param {Actual} actual - Actual spend.
|
|
42
|
+
* @param {{tokensLow: number, tokensHigh: number} | null} estimate - Parsed estimate, if any.
|
|
43
|
+
* @returns {{row: string, note: string, token: string}} Rendered parts.
|
|
44
|
+
*/
|
|
45
|
+
export function renderActual(actual, estimate) {
|
|
46
|
+
const midpoint = estimate
|
|
47
|
+
? (estimate.tokensLow + estimate.tokensHigh) / 2
|
|
48
|
+
: null;
|
|
49
|
+
const ratio =
|
|
50
|
+
actual.tokens !== null && midpoint
|
|
51
|
+
? Number((actual.tokens / midpoint).toFixed(2))
|
|
52
|
+
: null;
|
|
53
|
+
const tokens =
|
|
54
|
+
actual.tokens === null ? "unknown" : formatTokens(actual.tokens);
|
|
55
|
+
const cost =
|
|
56
|
+
actual.cost === null
|
|
57
|
+
? "unknown"
|
|
58
|
+
: `$${actual.cost.toFixed(2)} ${actual.currency ?? ""}`.trim();
|
|
59
|
+
const fields = [
|
|
60
|
+
`tokens=${actual.tokens ?? "null"}`,
|
|
61
|
+
`cost=${actual.cost ?? "null"}`,
|
|
62
|
+
`currency=${actual.currency === null ? "null" : encodeURIComponent(actual.currency)}`,
|
|
63
|
+
`sources=${encodeURIComponent(actual.sources.join(","))}`,
|
|
64
|
+
`entries=${actual.entries}`,
|
|
65
|
+
`ratio=${ratio ?? "null"}`,
|
|
66
|
+
];
|
|
67
|
+
const comparison =
|
|
68
|
+
ratio === null ? "" : `; ${ratio}x the estimate's midpoint`;
|
|
69
|
+
return {
|
|
70
|
+
row: `| Actual | ${tokens} | ${cost} | — |`,
|
|
71
|
+
note: `Actual: the Lisa Usage ledger total over ${actual.entries} usage entr${actual.entries === 1 ? "y" : "ies"} (source: ${actual.sources.join(", ") || "child work items only"})${comparison}.`,
|
|
72
|
+
token: `<!-- lisa:estimate-actual ${fields.join(" ")} -->`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The raw fields of the actual token recorded in a section.
|
|
78
|
+
* @param {string | null} section - Estimate section text.
|
|
79
|
+
* @returns {Record<string, string> | null} Fields as written, or null when there is no token.
|
|
80
|
+
*/
|
|
81
|
+
export function actualTokenFields(section) {
|
|
82
|
+
const match = section ? ACTUAL_PATTERN.exec(section) : null;
|
|
83
|
+
if (!match) return null;
|
|
84
|
+
return Object.fromEntries(
|
|
85
|
+
match[1]
|
|
86
|
+
.trim()
|
|
87
|
+
.split(/\s+/)
|
|
88
|
+
.map(pair => [
|
|
89
|
+
pair.slice(0, pair.indexOf("=")),
|
|
90
|
+
pair.slice(pair.indexOf("=") + 1),
|
|
91
|
+
])
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The actual recorded in a section, read back from its token.
|
|
97
|
+
* @param {string | null} section - Estimate section text.
|
|
98
|
+
* @returns {Actual | null} The recorded actual, or null when none parses.
|
|
99
|
+
*/
|
|
100
|
+
export function parseActualToken(section) {
|
|
101
|
+
const fields = actualTokenFields(section);
|
|
102
|
+
if (!fields) return null;
|
|
103
|
+
const number = value =>
|
|
104
|
+
value === undefined || value === "null" ? null : Number(value);
|
|
105
|
+
const tokens = number(fields.tokens);
|
|
106
|
+
const cost = number(fields.cost);
|
|
107
|
+
const entries = Number(fields.entries);
|
|
108
|
+
if (
|
|
109
|
+
[tokens, cost].some(value => value !== null && !Number.isFinite(value)) ||
|
|
110
|
+
!Number.isSafeInteger(entries)
|
|
111
|
+
)
|
|
112
|
+
return null;
|
|
113
|
+
try {
|
|
114
|
+
return {
|
|
115
|
+
tokens,
|
|
116
|
+
cost,
|
|
117
|
+
currency:
|
|
118
|
+
fields.currency === undefined || fields.currency === "null"
|
|
119
|
+
? null
|
|
120
|
+
: decodeURIComponent(fields.currency),
|
|
121
|
+
sources: decodeURIComponent(fields.sources ?? "")
|
|
122
|
+
.split(",")
|
|
123
|
+
.filter(Boolean),
|
|
124
|
+
entries,
|
|
125
|
+
};
|
|
126
|
+
} catch (error) {
|
|
127
|
+
// A malformed percent escape makes the token unparseable, not the caller.
|
|
128
|
+
if (error instanceof URIError) return null;
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|