@runeditrun/rer 0.2.85 → 0.2.86
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/README.md +138 -29
- package/cli/README.md +61 -1
- package/cli/agent-door.mjs +149 -0
- package/cli/agent-fixtures.mjs +16 -0
- package/cli/agent-mail.mjs +54 -0
- package/cli/agent-network.mjs +64 -0
- package/cli/agent-reviewers.mjs +110 -0
- package/cli/agent-secrets.mjs +23 -0
- package/cli/agent-sponsors.mjs +43 -0
- package/cli/agent-surface.mjs +34 -0
- package/cli/agent-webhooks.mjs +19 -0
- package/cli/authoring.mjs +2 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +3 -1
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +23 -5
- package/cli/business/connect.mjs +19 -7
- package/cli/business/detector.mjs +4 -1
- package/cli/business/device.mjs +13 -0
- package/cli/business/export-inputs.mjs +69 -0
- package/cli/business/export-task.mjs +17 -0
- package/cli/business/invocation.mjs +8 -1
- package/cli/business/keychain.mjs +8 -1
- package/cli/business/lease.mjs +11 -1
- package/cli/business/local-commands.mjs +79 -31
- package/cli/business/outbound.mjs +9 -4
- package/cli/business/parsers-config.mjs +8 -7
- package/cli/business/parsers-syntax.mjs +7 -3
- package/cli/business/permissions.mjs +2 -0
- package/cli/business/questions.mjs +89 -9
- package/cli/business/setup-command.mjs +49 -0
- package/cli/business/setup-company.json +15 -0
- package/cli/business/setup-demo.mjs +95 -0
- package/cli/business/state.mjs +44 -10
- package/cli/business/supervisor.mjs +94 -35
- package/cli/business/vendor-door.mjs +230 -0
- package/cli/business/vendors/README.md +29 -3
- package/cli/business/vendors/common.mjs +8 -6
- package/cli/business/vendors/index.mjs +22 -11
- package/cli/business/vendors/sorry.mjs +106 -0
- package/cli/contract.mjs +2 -2
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +4 -1
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +58 -0
- package/cli/door-clauses.mjs +157 -0
- package/cli/export.mjs +16 -4
- package/cli/hosted-output.mjs +17 -7
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +3 -1
- package/cli/main.mjs +1 -0
- package/cli/managed-data-schema.mjs +14 -1
- package/cli/portability-empty.mjs +6 -0
- package/cli/portability-migrations.mjs +26 -4
- package/cli/production-auth.mjs +1 -1
- package/cli/production-mail.mjs +8 -2
- package/edition-authoring/archive-source.mjs +59 -0
- package/edition-authoring/base-copies.mjs +92 -18
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/edition-migrations.mjs +7 -3
- package/edition-authoring/module-closure.mjs +2 -16
- package/edition-authoring/workflow-copies.mjs +1 -1
- package/edition-authoring/workflow-scripts.mjs +12 -3
- package/foundation/runtime/contract-docs.mjs +215 -32
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/global/CHANGELOG.md +93 -0
- package/global/README.md +138 -29
- package/global/door/command.mjs +3 -1
- package/global/main.mjs +1 -1
- package/modules/agent-door/CLAUSES.md +215 -0
- package/modules/agent-door/conformance/audit.mjs +66 -0
- package/modules/agent-door/conformance/authority.d.mts +2 -0
- package/modules/agent-door/conformance/authority.mjs +17 -0
- package/modules/agent-door/conformance/crypto.mjs +36 -0
- package/modules/agent-door/conformance/discovery.mjs +61 -0
- package/modules/agent-door/conformance/index.mjs +41 -0
- package/modules/agent-door/conformance/invocation.mjs +32 -0
- package/modules/agent-door/conformance/journey.mjs +112 -0
- package/modules/agent-door/conformance/narrowing.d.mts +1 -0
- package/modules/agent-door/conformance/narrowing.mjs +21 -0
- package/modules/agent-door/conformance/negative.mjs +47 -0
- package/modules/agent-door/conformance/network-modules.mjs +86 -0
- package/modules/agent-door/conformance/network-runtime.mjs +46 -0
- package/modules/agent-door/conformance/policy-phases.mjs +75 -0
- package/modules/agent-door/conformance/protocol.mjs +145 -0
- package/modules/agent-door/conformance/replay.mjs +38 -0
- package/modules/agent-door/conformance/schema.mjs +71 -0
- package/modules/agent-door/conformance/security.mjs +33 -0
- package/modules/agent-door/conformance/sponsors.mjs +68 -0
- package/modules/agent-door/conformance/surface.mjs +89 -0
- package/modules/agent-door/conformance/target.mjs +18 -0
- package/modules/agent-door/conformance/tool-name.d.mts +1 -0
- package/modules/agent-door/conformance/tool-name.mjs +7 -0
- package/modules/agent-door/conformance/webhooks.mjs +30 -0
- package/modules/container/image-variables.mjs +8 -2
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/ownership.mjs +39 -0
- package/modules/demo-host/plan.mjs +2 -1
- package/modules/demo-host/remove.mjs +6 -1
- package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
- package/modules/import-kit/schema/importers.schema.json +107 -0
- package/modules/import-kit/src/door/ADOPTING.md +20 -0
- package/modules/import-kit/src/door/README.md +2 -1
- package/modules/import-kit/src/door/admission.ts +5 -3
- package/modules/import-kit/src/door/archive.ts +5 -2
- package/modules/import-kit/src/door/authority.ts +1 -0
- package/modules/import-kit/src/door/grants.ts +1 -1
- package/modules/import-kit/src/door/handler.ts +14 -8
- package/modules/import-kit/src/door/index.ts +1 -1
- package/modules/import-kit/src/door/jobs.ts +40 -0
- package/modules/import-kit/src/door/operator.ts +3 -3
- package/modules/import-kit/src/door/planning.ts +10 -6
- package/modules/import-kit/src/door/protocol.ts +2 -2
- package/modules/import-kit/src/door/raw.ts +25 -0
- package/modules/import-kit/src/door/refusals.ts +1 -0
- package/modules/import-kit/src/door/types.ts +26 -6
- package/modules/import-kit/src/receipt/encoding.ts +37 -0
- package/modules/import-kit/src/receipt/index.ts +69 -0
- package/modules/import-kit/src/receipt/policy.ts +24 -0
- package/modules/import-kit/src/receipt/types.ts +64 -0
- package/modules/import-kit/src/receipt/uri.ts +45 -0
- package/modules/import-kit/src/receipt/validation.ts +87 -0
- package/modules/import-kit/src/status/encoding.ts +13 -0
- package/modules/import-kit/src/status/evidence.ts +218 -0
- package/modules/import-kit/src/status/index.ts +56 -0
- package/modules/import-kit/src/status/schema.ts +208 -0
- package/modules/import-kit/src/status/types.ts +86 -0
- package/modules/operator-auth/accounts/delegated.mjs +48 -0
- package/modules/operator-auth/index.d.mts +7 -0
- package/modules/operator-auth/service.mjs +2 -0
- package/modules/portability/README.md +32 -11
- package/modules/portability/bridge.mjs +22 -2
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/import.mjs +14 -7
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/cli/business/opt-ins.mjs +0 -37
|
@@ -77,7 +77,7 @@ try {
|
|
|
77
77
|
} else if (command === 'record-base') result = recordCopy(root, options(args.slice(1), 3));
|
|
78
78
|
else if (command === 'adapt-base') result = adaptCopy(root, options(args.slice(1), 1));
|
|
79
79
|
else if (command === 'refresh-base') result = refreshCopies(root, options(args.slice(1), 1));
|
|
80
|
-
else throw Error('Usage: cli.mjs adopt|inspect|lock|check|receipt <sidecar-json>|changes|extract <id|parent> <new-output>|compare <id|parent> <candidate-checkout> [current-parent-checkout]|materialize <new-output>|promote <id>|release <new-local-git-repository>|verify-base [--record <file>] [--base <checkout>] [--offline]|record-base <path> <origin-path> <revision> [--record <file>] [--base <checkout>]|adapt-base <file> [--record <file>]|refresh-base <revision> [--record <file>] [--base <checkout>]');
|
|
80
|
+
else throw Error('Usage: cli.mjs adopt|inspect|lock|check|receipt <sidecar-json>|changes|extract <id|parent> <new-output>|compare <id|parent> <candidate-checkout> [current-parent-checkout]|materialize <new-output>|promote <id>|release <new-local-git-repository>|verify-base [--record <file>] [--base <checkout>] [--offline]|record-base <path> <origin-path> <revision>|--ref <revision> [--record <file>] [--base <checkout>|--base-archive <directory>|--from-api|--offline --base <checkout>]|adapt-base <file> [--record <file>]|refresh-base <revision>|--ref <revision> [--record <file>] [--base <checkout>|--base-archive <directory>]');
|
|
81
81
|
console.log(json(result));
|
|
82
82
|
} catch (error) {
|
|
83
83
|
console.error(error.message);
|
|
@@ -16,7 +16,7 @@ export function editionMigrations(record, {tree, read, revision, base, recordPat
|
|
|
16
16
|
typeof step.guide !== 'string' || !step.guide || typeof step.edit !== 'string' || !step.edit ||
|
|
17
17
|
!Array.isArray(step.deliver) || step.deliver.some(name => typeof name !== 'string')) fail('invalid entry');
|
|
18
18
|
safe(step.origin); safe(step.guide); step.deliver.forEach(safe);
|
|
19
|
-
read.tree(step.introduced);
|
|
19
|
+
if (read.historyAvailable !== false) read.tree(step.introduced);
|
|
20
20
|
for (const name of step.deliver) if (!tree.has(name)) fail(`missing delivery ${name}`);
|
|
21
21
|
ids.add(step.id);
|
|
22
22
|
}
|
|
@@ -25,9 +25,13 @@ export function editionMigrations(record, {tree, read, revision, base, recordPat
|
|
|
25
25
|
}
|
|
26
26
|
for (const id of consent) if (!migrations.some(step => step.id === id)) throw Error(`Unknown edition migration ${id} at Base ${revision}. Use only ids declared in ${dataPath} at that commit; no files were refreshed.`);
|
|
27
27
|
const applicable = migrations.flatMap(step => {
|
|
28
|
+
// No introduction can be crossed by an unrelated copy or a same-pin
|
|
29
|
+
// refresh. Archives can decide those cases without claiming Git ancestry.
|
|
30
|
+
const candidates = record.copies.flatMap(copy => copy.revision === revision ? [] : Object.keys(copy.files).filter(name =>
|
|
31
|
+
!copy.adapted?.[name] && copy.originPath + name.slice(copy.path.length) === step.origin).map(name => ({name, revision: copy.revision})));
|
|
32
|
+
if (!candidates.length) return [];
|
|
28
33
|
if (!read.contains(revision, step.introduced)) return [];
|
|
29
|
-
const copies =
|
|
30
|
-
!copy.adapted?.[name] && copy.originPath + name.slice(copy.path.length) === step.origin && !read.contains(copy.revision, step.introduced)));
|
|
34
|
+
const copies = candidates.filter(copy => !read.contains(copy.revision, step.introduced)).map(copy => copy.name);
|
|
31
35
|
return copies.length ? [{...step, copies}] : [];
|
|
32
36
|
});
|
|
33
37
|
const missing = applicable.filter(step => !consent.includes(step.id));
|
|
@@ -120,7 +120,8 @@ export function completeModuleCopies(root, plans, {tree, read, revision, base, d
|
|
|
120
120
|
const key = (target, request) => JSON.stringify([target, request.kind, request.types, request.specifier]);
|
|
121
121
|
const bootstrap = source => /^(?:edition-authoring|(?:default-seed|export)\/scripts\/base-cli\/edition-authoring)\//.test(source);
|
|
122
122
|
// Snapshot the original unresolved set once, before closure can add a file.
|
|
123
|
-
//
|
|
123
|
+
// Preserve these edges during traversal; required planned files may still
|
|
124
|
+
// complete a sparse historical copy by satisfying them.
|
|
124
125
|
const baseline = new Set();
|
|
125
126
|
for (const {plan, source, target} of queue) {
|
|
126
127
|
if (!Object.hasOwn(plan.copy.files, target) || !disk.has(target) || bootstrap(source)) continue;
|
|
@@ -213,20 +214,5 @@ export function completeModuleCopies(root, plans, {tree, read, revision, base, d
|
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
|
-
const expected = new Set(), unresolved = new Set();
|
|
217
|
-
const removed = new Set(plans.flatMap(plan => plan.removed));
|
|
218
|
-
const final = {has: name => planned.has(name) || !removed.has(name) && disk.has(name), read: view.read};
|
|
219
|
-
for (const {plan, source, target, entry, adapted} of queue) {
|
|
220
|
-
if (!adapted && !plan.sources.some(([name]) => name === source)) continue;
|
|
221
|
-
for (const request of requests(adapted ? local(target) : blob(entry), source, target)) {
|
|
222
|
-
const id = key(target, request);
|
|
223
|
-
if (!baseline.has(id)) continue;
|
|
224
|
-
expected.add(id);
|
|
225
|
-
if (!resolve(final, target, request.specifier, request)) unresolved.add(id);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (expected.size !== unresolved.size || [...expected].some(id => !unresolved.has(id))) {
|
|
229
|
-
refuse('baseline imports', 'a planned file would resolve an edition-owned unresolved edge', '${EDITOR:-vi} base-copies.json');
|
|
230
|
-
}
|
|
231
217
|
return withheld;
|
|
232
218
|
}
|
|
@@ -54,7 +54,7 @@ export function adoptWorkflowTemplates(root, plans, {tree, read, revision, files
|
|
|
54
54
|
if (match) {
|
|
55
55
|
include(plans, target, source, tree.get(source), revision);
|
|
56
56
|
templateAdoptions.push({path: target, originPath: source, from: match.revision});
|
|
57
|
-
} else if (target.endsWith('.yml')) {
|
|
57
|
+
} else if (target.endsWith('.yml') && !file.read().equals(read.blobs([tree.get(source).object]).get(tree.get(source).object))) {
|
|
58
58
|
notices.push(`${target}: preserved seed-owned workflow. The current template pins Ubuntu 24.04 and moves browser and apt caches to the runner temporary directory. To adopt, merge export/${path.posix.basename(source)} from Base ${revision} into ${target}, then run node node_modules/@runeditrun/rer/edition-authoring/cli.mjs record-base ${target} ${source} ${revision} --base <base-checkout> and repeat rer refresh-base --ref ${revision} --base <base-checkout>.`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -95,16 +95,25 @@ export function shellWords(script) {
|
|
|
95
95
|
|
|
96
96
|
export function literalPaths(script) {
|
|
97
97
|
const names = new Set();
|
|
98
|
-
function scan(text, ancestors = new Set()) {
|
|
98
|
+
function scan(text, ancestors = new Set(), words = shellWords(text)) {
|
|
99
99
|
if (ancestors.has(text)) return;
|
|
100
100
|
const nested = new Set([...ancestors, text]);
|
|
101
|
-
for (const {value, dynamic} of
|
|
101
|
+
for (const {value, dynamic} of words) {
|
|
102
102
|
if (dynamic) continue;
|
|
103
103
|
const relative = value.replace(/^\.\//, '');
|
|
104
104
|
if ((value.startsWith('./') || relative.startsWith('scripts/') || !/\s/.test(value) && (relative.includes('/') || /\.[a-z0-9]+$/i.test(relative))) && !relative.startsWith('/')) names.add(relative);
|
|
105
105
|
// A complete quoted path is one word; only script-like quoted content is
|
|
106
106
|
// recursively tokenized, never a path whose filename contains whitespace.
|
|
107
|
-
else if (/\s/.test(value))
|
|
107
|
+
else if (/\s/.test(value)) {
|
|
108
|
+
// Decoded arguments may be prose, not another shell program. A quote
|
|
109
|
+
// that was literal in its enclosing word must not invalidate that
|
|
110
|
+
// workflow. Recurse only when the whole argument is valid shell text;
|
|
111
|
+
// the actual run script and its substitutions are still strict.
|
|
112
|
+
let words;
|
|
113
|
+
try { words = shellWords(value); }
|
|
114
|
+
catch { continue; }
|
|
115
|
+
scan(value, nested, words);
|
|
116
|
+
}
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
119
|
scan(script);
|
|
@@ -4,6 +4,7 @@ import fs from 'node:fs'
|
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { execFileSync } from 'node:child_process'
|
|
6
6
|
import { parseContract, clauseIdSource, plainText } from './seed-contract.mjs'
|
|
7
|
+
import { contractProseFindings, printProseFindings } from './contract-prose.mjs'
|
|
7
8
|
|
|
8
9
|
const marker = '<!-- Generated from CONTRACT.md by contract-docs. Edit CONTRACT.md, then regenerate. -->'
|
|
9
10
|
const idPattern = new RegExp(`^${clauseIdSource}$`)
|
|
@@ -14,6 +15,7 @@ const json = value => JSON.stringify(value, null, 2) + '\n'
|
|
|
14
15
|
const linesOf = text => text.replace(/\r\n?/g, '\n').split('\n')
|
|
15
16
|
const cells = line => line.trim().replace(/^\|/, '').replace(/(?<!\\)\|$/, '').split(/(?<!\\)\|/).map(cell => cell.trim())
|
|
16
17
|
const divider = line => /^\|?(\s*:?-{3,}:?\s*\|)+\s*:?-{0,}:?\s*$/.test(line.trim())
|
|
18
|
+
const tableCell = text => text.replace(/(?<!\\)\|/g, '\\|')
|
|
17
19
|
const idsIn = text => [...text.matchAll(new RegExp(`(?<![A-Za-z0-9.-])(${clauseIdSource})(?![A-Za-z0-9.-])`, 'g'))].map(match => match[1])
|
|
18
20
|
const block = text => text.replace(/^\s*\n|\n\s*$/g, '').trim()
|
|
19
21
|
function outline(text) {
|
|
@@ -130,30 +132,50 @@ function generatedFiles(text) {
|
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
134
|
acceptance.push('## Field proof register', register)
|
|
133
|
-
const
|
|
135
|
+
const rows = claimRows(text), provenance = validateClaimSource(text, rows)
|
|
134
136
|
const claims = [marker, `# ${seed} homepage claims`]
|
|
135
137
|
if (!rows.length) claims.push('No homepage claims are mapped yet.')
|
|
136
138
|
else {
|
|
137
|
-
claims.push('A claim is done when every clause behind it is done, missing when every one is missing, and partial otherwise.')
|
|
139
|
+
claims.push('A product claim is done when every clause behind it is done, missing when every one is missing, and partial otherwise. Explicit source-bound non-product facts are unassessed; their historical status is history, not current proof.')
|
|
138
140
|
const hasSection = rows.some(row => row.header.some(cell => /^Section$/i.test(plainText(cell))))
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
+
const hasNonProduct = provenance?.claims.some(row => row.nonProduct)
|
|
142
|
+
const header = ['#', ...(hasSection ? ['Section'] : []), 'Claim', 'Clauses', ...(hasNonProduct ? ['Basis'] : []), ...(provenance ? ['Historical status'] : []), 'Status']
|
|
143
|
+
const table = [`| ${header.join(' | ')} |`, `| ${header.map(() => '---').join(' | ')} |`], counts = { done: 0, partial: 0, missing: 0, unassessed: 0 }
|
|
141
144
|
for (const [index, row] of rows.entries()) {
|
|
142
|
-
const value = label => row
|
|
145
|
+
const value = label => claimValue(row, label)
|
|
146
|
+
const source = provenance?.claims[index]
|
|
147
|
+
if (source?.nonProduct) {
|
|
148
|
+
counts.unassessed++
|
|
149
|
+
table.push(`| ${[value('#'), ...(hasSection ? [value('Section')] : []), value('Claim'), '', `Non-product: ${source.nonProduct}`, source.status || 'Not recorded', 'unassessed'].map(tableCell).join(' | ')} |`)
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
143
152
|
const ids = idsIn(value('Clauses?')), linked = ids.map(id => clauses.find(clause => clause.id === id))
|
|
144
153
|
if (!ids.length || linked.some(clause => !clause)) throw Error(`CONTRACT.md:${row.line}: Homepage claim needs existing clause ids.`)
|
|
145
154
|
const state = linked.every(clause => clause.status === 'done') ? 'done' : linked.every(clause => clause.status === 'missing') ? 'missing' : 'partial'
|
|
146
155
|
counts[state]++
|
|
147
|
-
table.push(`| ${[value('#') || String(index + 1), ...(hasSection ? [value('Section')] : []), value('Claim'), linked.map(clause => `\`${clause.id}\` ${clause.status}`).join('; '), state].join(' | ')} |`)
|
|
156
|
+
table.push(`| ${[value('#') || String(index + 1), ...(hasSection ? [value('Section')] : []), value('Claim'), linked.map(clause => `\`${clause.id}\` ${clause.status}`).join('; '), ...(hasNonProduct ? ['Product'] : []), ...(provenance ? [source?.status || 'Not recorded'] : []), state].map(tableCell).join(' | ')} |`)
|
|
148
157
|
}
|
|
149
|
-
claims.push(table.join('\n'), `Claims: ${rows.length}; ${counts.done} done, ${counts.partial} partial, ${counts.missing} missing.`)
|
|
158
|
+
claims.push(table.join('\n'), `Claims: ${rows.length}; ${counts.done} done, ${counts.partial} partial, ${counts.missing} missing.${hasNonProduct ? ` Non-product: ${counts.unassessed} unassessed.` : ''}`)
|
|
159
|
+
if (provenance) claims.push(`Historical claim source: \`${provenance.old}\`. Exact source files, lines, text and historical statuses are retained in CONTRACT.md's contract-claim-source record.`)
|
|
150
160
|
}
|
|
151
161
|
return { 'CONTRACT.md': rewritten, 'ACCEPTANCE.md': acceptance.join('\n\n') + '\n', 'docs/CLAIMS.md': claims.join('\n\n') + '\n' }
|
|
152
162
|
}
|
|
153
163
|
function generate(check = false) {
|
|
154
164
|
const text = read('CONTRACT.md')
|
|
155
165
|
if (text === undefined) throw Error('CONTRACT.md does not exist.')
|
|
166
|
+
const coverage = read(covMapPath)
|
|
167
|
+
if (coverage !== undefined) {
|
|
168
|
+
let original
|
|
169
|
+
try { original = snapshot(JSON.parse(coverage).old?.commit) }
|
|
170
|
+
catch (error) { throw Error(`${covMapPath}: original SHA is unavailable: ${error.message}`) }
|
|
171
|
+
validateOriginalClaims(original)
|
|
172
|
+
}
|
|
156
173
|
const files = generatedFiles(text), changed = Object.entries(files).filter(([name, contents]) => read(name) !== contents)
|
|
174
|
+
const provenance = readClaimSource(text)
|
|
175
|
+
if (provenance) for (const { name, original } of [{ name: 'docs/contract/ID-MAP.json', original: map => map.old }, { name: 'docs/contract/COVERAGE.json', original: map => map.old?.commit }]) {
|
|
176
|
+
const source = read(name)
|
|
177
|
+
if (source === undefined || original(JSON.parse(source)) !== provenance.old) throw Error(`${name}: original SHA must equal contract-claim-source old ${provenance.old}.`)
|
|
178
|
+
}
|
|
157
179
|
if (check && changed.length) throw Error(changed.map(([name]) => `${name}: generated content differs; run contract-docs write.`).join('\n'))
|
|
158
180
|
if (!check) for (const [name, contents] of changed) put(name, contents)
|
|
159
181
|
console.log(check ? 'Contract documents are current.' : `Wrote ${changed.length} contract documents.`)
|
|
@@ -238,10 +260,13 @@ function oldClauseBody(text, clause) {
|
|
|
238
260
|
const lines = linesOf(text), start = clause.line - 1, first = lines[start]
|
|
239
261
|
const bold = /^(-\s+)?\*\*[^*]+\*\*\s*/.exec(first)
|
|
240
262
|
const body = [bold ? first.slice(bold[0].length) : '']
|
|
263
|
+
let fence
|
|
241
264
|
for (let index = start + 1; index < lines.length; index++) {
|
|
242
265
|
const line = lines[index]
|
|
243
|
-
|
|
244
|
-
|
|
266
|
+
const insideFence = Boolean(fence), state = covFence(line, fence)
|
|
267
|
+
fence = state.current
|
|
268
|
+
if (!insideFence && !state.marker && (/^#{1,6}\s/.test(line) || new RegExp(`^(?:-\\s+)?\\*\\*${clauseIdSource}\\s+[—–-]\\s+`).test(line))) break
|
|
269
|
+
if (bold?.[1] && line.trim() && !/^[ \t>]/.test(line) && !insideFence && !state.marker) break
|
|
245
270
|
body.push(bold?.[1] ? line.replace(/^ {1,2}/, '') : line)
|
|
246
271
|
}
|
|
247
272
|
return block(body.join('\n'))
|
|
@@ -259,8 +284,20 @@ function acceptanceEntries(text, ids) {
|
|
|
259
284
|
}
|
|
260
285
|
return result
|
|
261
286
|
}
|
|
262
|
-
function requirementAndAcceptance(body, oldAcceptance) {
|
|
263
|
-
|
|
287
|
+
function requirementAndAcceptance(body, oldAcceptance, clause) {
|
|
288
|
+
// Blockquote syntax is presentation, not part of a retained obligation.
|
|
289
|
+
body = withoutQuoteMarkers(body)
|
|
290
|
+
oldAcceptance = oldAcceptance === undefined ? undefined : withoutQuoteMarkers(oldAcceptance)
|
|
291
|
+
const history = []
|
|
292
|
+
// A leading status records the judgment, not the end of the requirement.
|
|
293
|
+
// Keep its complete line in history, then read the prose below it normally.
|
|
294
|
+
const leadingStatus = /^(?:\*{1,2})?Status:(?:\*{1,2})?\s*(done|partial|missing)\b[^\n]*(?:\n|$)/i.exec(body)
|
|
295
|
+
if (leadingStatus) {
|
|
296
|
+
if (leadingStatus[1].toLowerCase() !== clause.status) throw Error(`${clause.id}: the leading Status line disagrees with its Status table.`)
|
|
297
|
+
history.push(block(leadingStatus[0]))
|
|
298
|
+
body = block(body.slice(leadingStatus[0].length))
|
|
299
|
+
}
|
|
300
|
+
const status = /\*{1,2}Status:\*{1,2}\s*(?:done|partial|missing)\b/i.exec(body)
|
|
264
301
|
if (status) { history.push(body.slice(status.index)); body = body.slice(0, status.index).trim() }
|
|
265
302
|
const markerPattern = /(?:\*{1,2}Acceptance(?: evidence)?[:.]\*{1,2}|\*\*Acceptance\*\*[:.]?)/i
|
|
266
303
|
const acceptanceMarker = markerPattern.exec(body)
|
|
@@ -280,21 +317,137 @@ function requirementAndAcceptance(body, oldAcceptance) {
|
|
|
280
317
|
}
|
|
281
318
|
return { text: result.join('\n\n'), history }
|
|
282
319
|
}
|
|
283
|
-
|
|
320
|
+
// Only spellings observed in the launch seeds' immutable homepage tables.
|
|
321
|
+
const claimHeaders = new Set(['claim', 'claims', 'claim on the page', 'what the page claims', 'claim text'])
|
|
322
|
+
function claimHeader(cell) {
|
|
323
|
+
const value = plainText(cell).toLowerCase()
|
|
324
|
+
if (claimHeaders.has(value)) return 'Claim'
|
|
325
|
+
if (['clause', 'clauses', 'clause(s)', 'clause id(s)'].includes(value)) return 'Clauses'
|
|
326
|
+
if (value === 'claim #') return '#'
|
|
327
|
+
return plainText(cell)
|
|
328
|
+
}
|
|
329
|
+
const claimValue = (row, label) => row.cells[row.header.findIndex(cell => new RegExp(`^${label}$`, 'i').test(claimHeader(cell)))] ?? ''
|
|
330
|
+
const claimRows = text => homepageClaims(text).flatMap(table => table.rows.map(row => ({ ...row, header: table.header })))
|
|
331
|
+
function originalClaims(old) {
|
|
284
332
|
const candidates = Object.entries(old.files).filter(([name, text]) => name === 'CONTRACT.md' || /(?:^|\/)CLAIMS\.md$/.test(name) && !text.startsWith('<!-- Generated from CONTRACT.md by contract-docs.')).map(([name, text]) => ({ name, tables: homepageClaims(text) }))
|
|
285
333
|
const winner = candidates.sort((a, b) => b.tables.reduce((n, table) => n + table.rows.length, 0) - a.tables.reduce((n, table) => n + table.rows.length, 0))[0]
|
|
286
|
-
|
|
287
|
-
|
|
334
|
+
const rows = winner?.tables.flatMap(table => table.rows.map(row => ({ ...row, header: table.header }))) ?? []
|
|
335
|
+
return { file: winner?.name, rows }
|
|
336
|
+
}
|
|
337
|
+
function nonProductBasis(source, basis, ids, label) {
|
|
338
|
+
// These are explicit classifications, never a fallback for an unresolved ID.
|
|
339
|
+
const allowed = {
|
|
340
|
+
'license/public-repository ownership': /^["“]?(?:100% free, open source alternative to [^"”\n]+|100% free and open source\. MIT licensed\.|MIT licen[cs](?:e|ed)\.?)["”]?$/i,
|
|
341
|
+
'launcher identity': /^(?:Terminal:\s*)?`npx -y @runeditrun\/rer dev [^`]+` starts [\w -]+\.?$/,
|
|
342
|
+
'hosted-demo action': /^["“]Try the demo["”] opens the hosted demo\.?$/i,
|
|
343
|
+
'boundary': /^Limits:\s*["“]No [^"”\n]+["”]\.?$/i,
|
|
344
|
+
}
|
|
345
|
+
const references = plainText(source.clauses).trim()
|
|
346
|
+
const allowedReferences = basis === 'boundary'
|
|
347
|
+
? /^none needed: a boundary, true of the code\.?$/i.test(references)
|
|
348
|
+
: ['', '—', 'OWN'].includes(references)
|
|
349
|
+
if (!Object.hasOwn(allowed, basis) || !allowed[basis].test(source.claim) ||
|
|
350
|
+
!allowedReferences || idsIn(source.clauses).some(id => ids.has(id)))
|
|
351
|
+
throw Error(`${label}: non-product basis must explicitly describe a license/public-repository ownership, launcher identity, hosted-demo action or boundary with its required original references and no original product clause link; product promises need real clauses.`)
|
|
352
|
+
}
|
|
353
|
+
function sourceClaim(file, row, index) {
|
|
354
|
+
return { file, line: row.line, number: claimValue(row, '#') || String(index + 1), claim: claimValue(row, 'Claim'), status: claimValue(row, 'Status'), clauses: claimValue(row, 'Clauses?'), text: row.raw }
|
|
355
|
+
}
|
|
356
|
+
function readClaimSource(text) {
|
|
357
|
+
const records = [...text.matchAll(/<!-- contract-claim-source\s*\n([\s\S]*?)\n-->/g)]
|
|
358
|
+
if (records.length > 1) throw Error('CONTRACT.md: duplicate contract-claim-source record.')
|
|
359
|
+
if (!records.length) return undefined
|
|
360
|
+
let record
|
|
361
|
+
try { record = JSON.parse(records[0][1]) } catch { throw Error('CONTRACT.md: invalid contract-claim-source JSON.') }
|
|
362
|
+
if (record?.schema !== 1 || !/^[0-9a-f]{40}$/.test(record.old) || !Array.isArray(record.claims)) throw Error('CONTRACT.md: contract-claim-source needs schema 1, a full old SHA and claims.')
|
|
363
|
+
return record
|
|
364
|
+
}
|
|
365
|
+
function validateClaimSource(text, rows = claimRows(text), old) {
|
|
366
|
+
const record = readClaimSource(text)
|
|
367
|
+
if (!record) {
|
|
368
|
+
if (rows.some(row => claimValue(row, 'Basis') && claimValue(row, 'Basis') !== 'Product')) throw Error('CONTRACT.md: non-product claims require a contract-claim-source record.')
|
|
369
|
+
return undefined
|
|
370
|
+
}
|
|
371
|
+
if (old && record.old !== old.commit) throw Error('CONTRACT.md: contract-claim-source old SHA differs from the coverage original.')
|
|
372
|
+
let original
|
|
373
|
+
try { original = old ?? snapshot(record.old) } catch (error) { throw Error(`CONTRACT.md: contract-claim-source old ${record.old}: ${error.message}`) }
|
|
374
|
+
const selected = originalClaims(original), ids = new Set(parseContract(original.files['CONTRACT.md']).clauses.map(clause => clause.id))
|
|
375
|
+
validateOriginalClaims(original, rows)
|
|
376
|
+
if (record.claims.length !== selected.rows.length) throw Error('CONTRACT.md: contract-claim-source must retain every original claim once.')
|
|
377
|
+
for (const [index, source] of record.claims.entries()) {
|
|
378
|
+
const expected = sourceClaim(selected.file, selected.rows[index], index), label = `CONTRACT.md: contract-claim-source claim ${index + 1}`
|
|
379
|
+
if (!source || Object.entries(expected).some(([key, value]) => source[key] !== value)) throw Error(`${label}: source SHA/file/line/number/text/historical status must match the immutable original.`)
|
|
380
|
+
const row = rows[index]
|
|
381
|
+
if (claimValue(row, '#') !== source.number || claimValue(row, 'Claim') !== source.claim) throw Error(`${label}: current claim number/text must match the original.`)
|
|
382
|
+
const basis = claimValue(row, 'Basis')
|
|
383
|
+
if (source.nonProduct !== undefined) {
|
|
384
|
+
nonProductBasis(source, source.nonProduct, ids, label)
|
|
385
|
+
if (basis !== `Non-product: ${source.nonProduct}` || claimValue(row, 'Clauses?')) throw Error(`${label}: explicit non-product basis and empty Clauses cell required.`)
|
|
386
|
+
} else if (basis && basis !== 'Product') throw Error(`${label}: product claim cannot acquire a non-product exemption.`)
|
|
387
|
+
}
|
|
388
|
+
return record
|
|
389
|
+
}
|
|
390
|
+
function validateOriginalClaims(old, rows = claimRows(read('CONTRACT.md'))) {
|
|
391
|
+
const selected = originalClaims(old), remaining = [...rows], problems = []
|
|
392
|
+
for (const [index, row] of selected.rows.entries()) {
|
|
393
|
+
const source = sourceClaim(selected.file, row, index)
|
|
394
|
+
const found = remaining.findIndex(current => claimValue(current, '#') === source.number && claimValue(current, 'Claim') === source.claim)
|
|
395
|
+
if (found < 0) problems.push(`${source.file}:${source.line}: missing original Homepage claim ${source.number}: ${source.claim}; current claim number/text must match the original.`)
|
|
396
|
+
else remaining.splice(found, 1)
|
|
397
|
+
}
|
|
398
|
+
if (remaining.length) problems.push('CONTRACT.md: unexpected or duplicate Homepage claims.')
|
|
399
|
+
if (problems.length) throw Error('CONTRACT.md: must retain every original claim once.\n' + problems.join('\n'))
|
|
400
|
+
}
|
|
401
|
+
function contractClaims(old, ids, claimMapPath) {
|
|
402
|
+
const { file, rows } = originalClaims(old), value = claimValue
|
|
403
|
+
const mapped = new Map()
|
|
404
|
+
if (claimMapPath !== undefined) {
|
|
405
|
+
const source = read(claimMapPath)
|
|
406
|
+
if (source === undefined) throw Error(`${claimMapPath}: claim map does not exist.`)
|
|
407
|
+
let map
|
|
408
|
+
try { map = JSON.parse(source) } catch (error) { throw Error(`${claimMapPath}: invalid claim map JSON: ${error.message}`) }
|
|
409
|
+
if (map?.schema !== 1 || map.old !== old.commit || !Array.isArray(map.claims))
|
|
410
|
+
throw Error(`${claimMapPath}: claim map needs schema 1, old ${old.commit}, and a claims list.`)
|
|
411
|
+
for (const entry of map.claims) {
|
|
412
|
+
if (!entry || entry.file !== file || !Number.isInteger(entry.line) || entry.line < 1)
|
|
413
|
+
throw Error(`${claimMapPath}: each claim mapping needs file ${file ?? 'CONTRACT.md'} and its original positive line number.`)
|
|
414
|
+
const row = rows.find(row => row.line === entry.line)
|
|
415
|
+
const label = `${claimMapPath}: ${entry.file}:${entry.line}`
|
|
416
|
+
if (!row) throw Error(`${label}: not a selected original homepage claim row.`)
|
|
417
|
+
if (mapped.has(entry.line)) throw Error(`${label}: duplicate claim mapping; supply one clauses list per row.`)
|
|
418
|
+
if (entry.claim !== value(row, 'Claim')) throw Error(`${label}: claim must exactly match ${JSON.stringify(value(row, 'Claim'))}.`)
|
|
419
|
+
if (entry.nonProduct !== undefined) {
|
|
420
|
+
if (entry.clauses !== undefined) throw Error(`${label}: non-product mapping cannot also supply clauses.`)
|
|
421
|
+
nonProductBasis(sourceClaim(file, row, rows.indexOf(row)), entry.nonProduct, ids, label)
|
|
422
|
+
mapped.set(entry.line, { nonProduct: entry.nonProduct })
|
|
423
|
+
continue
|
|
424
|
+
}
|
|
425
|
+
if (!Array.isArray(entry.clauses) || !entry.clauses.length || new Set(entry.clauses).size !== entry.clauses.length)
|
|
426
|
+
throw Error(`${label}: clauses must be a non-empty list of distinct existing product clause ids.`)
|
|
427
|
+
for (const id of entry.clauses) if (typeof id !== 'string' || !idPattern.test(id) || !ids.has(id))
|
|
428
|
+
throw Error(`${label}: unknown product clause ${JSON.stringify(id)}; use an id defined in the original contract.`)
|
|
429
|
+
mapped.set(entry.line, { clauses: entry.clauses })
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (!rows.length) return 'No homepage claims are mapped yet.'
|
|
288
433
|
const hasSection = rows.some(row => row.header.some(label => /^section$/i.test(plainText(label))))
|
|
289
|
-
const
|
|
290
|
-
const
|
|
434
|
+
const hasNonProduct = [...mapped.values()].some(entry => entry.nonProduct)
|
|
435
|
+
const header = ['#', ...(hasSection ? ['Section'] : []), 'Claim', 'Clauses', ...(hasNonProduct ? ['Basis'] : [])]
|
|
436
|
+
const table = [`| ${header.join(' | ')} |`, `| ${header.map(() => '---').join(' | ')} |`], problems = []
|
|
291
437
|
for (const [index, row] of rows.entries()) {
|
|
292
|
-
const
|
|
293
|
-
|
|
438
|
+
const mapping = mapped.get(row.line), nonProduct = mapping?.nonProduct
|
|
439
|
+
const references = nonProduct ? '' : mapping?.clauses.join(', ') ?? value(row, 'Clauses?')
|
|
440
|
+
const linked = idsIn(references)
|
|
441
|
+
if (!nonProduct && (!linked.length || linked.some(id => !ids.has(id))))
|
|
442
|
+
problems.push(`${file}:${row.line}: Homepage claim ${JSON.stringify(value(row, 'Claim'))} needs existing product clause ids (found ${JSON.stringify(references)}). Supply --claim-map <file> with schema 1, old ${old.commit}, and claims entries {file, line, claim, clauses}; map only to the actual obligations, never invent a link.`)
|
|
443
|
+
table.push(`| ${[value(row, '#') || String(index + 1), ...(hasSection ? [value(row, 'Section')] : []), value(row, 'Claim'), references, ...(hasNonProduct ? [nonProduct ? `Non-product: ${nonProduct}` : 'Product'] : [])].map(tableCell).join(' | ')} |`)
|
|
294
444
|
}
|
|
445
|
+
if (problems.length) throw Error(problems.join('\n'))
|
|
446
|
+
if (hasNonProduct) table.unshift('Explicit non-product facts have current derived status unassessed. The source record retains historical statuses as history, not current proof.', '')
|
|
447
|
+
table.push('', '<!-- contract-claim-source', json({ schema: 1, old: old.commit, claims: rows.map((row, index) => ({ ...sourceClaim(file, row, index), ...(mapped.get(row.line)?.nonProduct ? { nonProduct: mapped.get(row.line).nonProduct } : {}) })) }).replaceAll('|', '\\u007c').trimEnd(), '-->')
|
|
295
448
|
return table.join('\n')
|
|
296
449
|
}
|
|
297
|
-
function convert(old, acceptanceOld) {
|
|
450
|
+
function convert(old, acceptanceOld, claimMapPath) {
|
|
298
451
|
const text = old.files['CONTRACT.md'], parsed = parseContract(text), lines = linesOf(text), seed = seedName(text), ids = new Set(parsed.clauses.map(clause => clause.id))
|
|
299
452
|
const acceptanceSource = acceptanceOld?.files['ACCEPTANCE.md'] ?? old.files['ACCEPTANCE.md']
|
|
300
453
|
const acceptances = acceptanceEntries(acceptanceSource, ids)
|
|
@@ -316,7 +469,7 @@ function convert(old, acceptanceOld) {
|
|
|
316
469
|
output.push('## Shared duties (Base)', '| Base duty | Duty | Delta clauses | Base journey |\n| --- | --- | --- | --- |')
|
|
317
470
|
const clauseContent = new Map(), extraHistory = []
|
|
318
471
|
for (const clause of parsed.clauses) {
|
|
319
|
-
const converted = requirementAndAcceptance(oldClauseBody(text, clause), acceptances.get(clause.id))
|
|
472
|
+
const converted = requirementAndAcceptance(oldClauseBody(text, clause), acceptances.get(clause.id), clause)
|
|
320
473
|
clauseContent.set(clause.id, converted.text)
|
|
321
474
|
extraHistory.push(...converted.history)
|
|
322
475
|
}
|
|
@@ -341,7 +494,7 @@ function convert(old, acceptanceOld) {
|
|
|
341
494
|
}
|
|
342
495
|
}
|
|
343
496
|
}
|
|
344
|
-
output.push('## Field proof register', 'No field proof is recorded yet.', '## Boundaries', section(text, 'Boundaries') || section(text, 'Honest boundaries') || section(text, 'Honest boundaries and delivery responsibilities') || 'No additional boundaries are recorded.', '## Homepage claims', contractClaims(old))
|
|
497
|
+
output.push('## Field proof register', 'No field proof is recorded yet.', '## Boundaries', section(text, 'Boundaries') || section(text, 'Honest boundaries') || section(text, 'Honest boundaries and delivery responsibilities') || 'No additional boundaries are recorded.', '## Homepage claims', contractClaims(old, ids, claimMapPath))
|
|
345
498
|
const retired = outline(text).filter(entry => entry.level === 2 && /^Retired\b/i.test(entry.title))
|
|
346
499
|
if (retired.length) {
|
|
347
500
|
const contents = retired.map(entry => block(lines.slice(entry.start + 1, entry.end).join('\n'))).join('\n\n')
|
|
@@ -377,7 +530,7 @@ const covHeading = /^(#{1,6})\s+(.+?)\s*#*\s*$/;
|
|
|
377
530
|
const covDefinition = new RegExp(`^(?:#{1,6}\\s+|(?:[-*+]\\s+)?\\*\\*)(${clauseIdSource})\\s+[—–-]\\s+`);
|
|
378
531
|
const covSplit = text => text.replace(/\r\n?/g, '\n').split('\n');
|
|
379
532
|
const covGenerated = text => /^\uFEFF?<!-- Generated from CONTRACT\.md by contract-docs\./.test(covSplit(text)[0]);
|
|
380
|
-
const covNormalize = text => typeof text === 'string' ? text.replace(/^\s*(?:[-*+]\s+|\d+[.)]\s+)/, '').replace(/[`*_]/g, '').replace(/\s+/gu, '') : '';
|
|
533
|
+
const covNormalize = text => typeof text === 'string' ? withoutQuoteMarkers(text).replace(/^\s*(?:[-*+]\s+|\d+[.)]\s+)/, '').replace(/[`*_]/g, '').replace(/\s+/gu, '') : '';
|
|
381
534
|
const covKey = entry => JSON.stringify([entry.file, entry.line, entry.cell ?? '']);
|
|
382
535
|
const covLabel = entry => `${entry.file}:${entry.line}${entry.cell ? ` (${entry.cell})` : ''}`;
|
|
383
536
|
|
|
@@ -416,6 +569,15 @@ function covFence(line, current) {
|
|
|
416
569
|
if (marker[0] === current[0] && marker.length >= current.length) return { current: undefined, marker: true };
|
|
417
570
|
return { current, marker: false };
|
|
418
571
|
}
|
|
572
|
+
function withoutQuoteMarkers(text) {
|
|
573
|
+
let fence;
|
|
574
|
+
return linesOf(text).map(line => {
|
|
575
|
+
const state = covFence(line, fence);
|
|
576
|
+
const value = state.marker || fence ? line : line.replace(/^[ \t]*(?:>[ \t]?)+/, '');
|
|
577
|
+
fence = state.current;
|
|
578
|
+
return value;
|
|
579
|
+
}).join('\n');
|
|
580
|
+
}
|
|
419
581
|
|
|
420
582
|
// A claims heading owns its descendants until a sibling or ancestor ends it.
|
|
421
583
|
// A more specific claims heading, such as Opt-out claims, owns its own tables.
|
|
@@ -438,12 +600,17 @@ function homepageClaims(text) {
|
|
|
438
600
|
if (!owner || !/\bhomepage\s+claims\b/i.test(owner.text) || /\bopt[ -]?out\b/i.test(owner.text)) continue;
|
|
439
601
|
if (!value.includes('|') || !covDivider(lines[i + 1]?.text ?? '')) continue;
|
|
440
602
|
const header = covCells(value);
|
|
441
|
-
if (!header.some(cell =>
|
|
603
|
+
if (!header.some(cell => claimHeader(cell) === 'Claim')) {
|
|
604
|
+
// Handwritten claims files also contain clause-status appendices under
|
|
605
|
+
// their document title. Those are not homepage claim tables.
|
|
606
|
+
if (/^Clause$/i.test(plainText(header[0])) && header.some(cell => /^Status$/i.test(plainText(cell)))) continue;
|
|
607
|
+
throw Error(`Homepage claims:${i + 1}: unrecognized claim heading: ${value}`);
|
|
608
|
+
}
|
|
442
609
|
const rows = [];
|
|
443
610
|
let next = i + 2;
|
|
444
611
|
while (next < lines.length && lines[next].text.trim() && lines[next].text.includes('|') && !covHeading.test(lines[next].text)) {
|
|
445
612
|
const row = lines[next];
|
|
446
|
-
if (covDivider(row.text) || covCells(row.text).length !== header.length)
|
|
613
|
+
if (covDivider(row.text) || covCells(row.text).length !== header.length) throw Error(`Homepage claims:${next + 1}: malformed row: ${row.raw}`);
|
|
447
614
|
rows.push({ line: next + 1, cells: covCells(row.text), raw: row.raw });
|
|
448
615
|
next++;
|
|
449
616
|
}
|
|
@@ -478,7 +645,7 @@ function covScope(old) {
|
|
|
478
645
|
if (level > 1 || introStarted) introEnded = true;
|
|
479
646
|
continue;
|
|
480
647
|
}
|
|
481
|
-
if (!text.trim()) { if (introStarted) introEnded = true; continue; }
|
|
648
|
+
if (!(insideFence ? text : withoutQuoteMarkers(text)).trim()) { if (introStarted) introEnded = true; continue; }
|
|
482
649
|
if (covDivider(text)) continue;
|
|
483
650
|
if (definition) clause = definition[1];
|
|
484
651
|
const section = [...headings].reverse().find(entry => entry.level === 2)?.text ?? '';
|
|
@@ -552,7 +719,8 @@ function covPlacement(entry, current, contractEntries) {
|
|
|
552
719
|
if (entry.file === 'ACCEPTANCE.md') {
|
|
553
720
|
const repeated = covRepeated(entry, contractEntries);
|
|
554
721
|
if (repeated) return { to: 'copy', of: repeated.line };
|
|
555
|
-
if (
|
|
722
|
+
if (covGeneratedStatement(entry.text)) return { to: 'generated', note: 'The contract generator writes this status or count.' };
|
|
723
|
+
if (entry.clause) return { to: 'clause', ids: current.from.get(entry.clause) ?? [entry.clause] };
|
|
556
724
|
return { to: 'docs', path: 'docs/verify.md' };
|
|
557
725
|
}
|
|
558
726
|
if (entry.file !== 'CONTRACT.md') return { to: 'changelog' };
|
|
@@ -585,7 +753,7 @@ function coverageInit(old) {
|
|
|
585
753
|
function covDestination(destination, fragment, source, context, problems, label) {
|
|
586
754
|
const fail = message => problems.push(`${label}: ${message}`);
|
|
587
755
|
if (!destination || typeof destination !== 'object' || Array.isArray(destination)) { fail('A destination must be an object.'); return; }
|
|
588
|
-
const { current,
|
|
756
|
+
const { current, expected, groups } = context;
|
|
589
757
|
const note = () => { if (typeof destination.note !== 'string' || !destination.note.trim()) fail(`${destination.to} needs a note.`); };
|
|
590
758
|
const ids = known => {
|
|
591
759
|
if (!Array.isArray(destination.ids) || !destination.ids.length || destination.ids.some(id => typeof id !== 'string')) { fail(`${destination.to} needs a non-empty ids list.`); return; }
|
|
@@ -637,6 +805,8 @@ function covDestination(destination, fragment, source, context, problems, label)
|
|
|
637
805
|
}
|
|
638
806
|
}
|
|
639
807
|
function coverageCheck(old) {
|
|
808
|
+
validateOriginalClaims(old);
|
|
809
|
+
validateClaimSource(read('CONTRACT.md'), undefined, old);
|
|
640
810
|
const map = covReadMap(), problems = [], entries = covScope(old), expected = new Map(entries.map(entry => [covKey(entry), entry])), groups = new Map();
|
|
641
811
|
if (map.schema !== 1) problems.push('Coverage schema must be 1.');
|
|
642
812
|
if (map.old?.commit !== old.commit) problems.push(`Coverage old.commit must equal ${old.commit}; found ${JSON.stringify(map.old?.commit)}.`);
|
|
@@ -735,20 +905,33 @@ function coverageRebase(from, onto) {
|
|
|
735
905
|
return { ...map, old: { commit: onto.commit, files: covFiles(onto) }, fragments };
|
|
736
906
|
}
|
|
737
907
|
|
|
908
|
+
function checkProse() {
|
|
909
|
+
const text = read('CONTRACT.md');
|
|
910
|
+
if (text === undefined) throw Error('CONTRACT.md does not exist.');
|
|
911
|
+
const coverage = read(covMapPath) === undefined ? undefined : covReadMap();
|
|
912
|
+
const sources = coverage ? covScope(snapshot(coverage.old?.commit)) : [];
|
|
913
|
+
const findings = contractProseFindings({ text, clauses: parseContract(withoutSummary(text)).clauses, coverage, sources, generatedStatement: covGeneratedStatement });
|
|
914
|
+
if (printProseFindings(findings)) process.exitCode = 1;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
const usage = 'Usage: contract-docs.mjs write|check|check-prose|id-map --old <ref>|coverage init|check --old <ref>|coverage rebase --from <ref> --onto <ref>|convert --old <ref> [--old-acceptance <ref>] [--claim-map <file>]';
|
|
738
918
|
function main(args) {
|
|
739
919
|
const [command, ...rest] = args
|
|
740
|
-
const option = name => {
|
|
920
|
+
const option = (name, description = 'Git reference') => {
|
|
741
921
|
const index = rest.indexOf(name)
|
|
742
|
-
if (index < 0 || !rest[index + 1] || rest[index + 1].startsWith('--')) throw Error(`Provide ${name} and its
|
|
922
|
+
if (index < 0 || !rest[index + 1] || rest[index + 1].startsWith('--')) throw Error(`Provide ${name} and its ${description}.`)
|
|
923
|
+
if (rest.lastIndexOf(name) !== index) throw Error(`Provide ${name} only once.`)
|
|
743
924
|
return rest[index + 1]
|
|
744
925
|
}
|
|
745
926
|
if (command === 'write' && !rest.length) generate()
|
|
746
|
-
else if (command === 'check' && !rest.length) generate(true)
|
|
927
|
+
else if (command === 'check' && !rest.length) { checkProse(); generate(true) }
|
|
928
|
+
else if (command === 'check-prose' && !rest.length) checkProse()
|
|
929
|
+
else if (command === '--help' && !rest.length) console.log(usage)
|
|
747
930
|
else if (command === 'id-map') idMap(snapshot(option('--old')))
|
|
748
931
|
else if (command === 'coverage' && rest[0] === 'init') coverageInit(snapshot(option('--old')))
|
|
749
932
|
else if (command === 'coverage' && rest[0] === 'check') coverageCheck(snapshot(option('--old')))
|
|
750
933
|
else if (command === 'coverage' && rest[0] === 'rebase') coverageRebase(snapshot(option('--from')), snapshot(option('--onto')))
|
|
751
|
-
else if (command === 'convert') convert(snapshot(option('--old')), rest.includes('--old-acceptance') ? snapshot(option('--old-acceptance')) : undefined)
|
|
752
|
-
else throw Error(
|
|
934
|
+
else if (command === 'convert') convert(snapshot(option('--old')), rest.includes('--old-acceptance') ? snapshot(option('--old-acceptance')) : undefined, rest.includes('--claim-map') ? option('--claim-map', 'JSON file path') : undefined)
|
|
935
|
+
else throw Error(usage)
|
|
753
936
|
}
|
|
754
937
|
try { main(process.argv.slice(2)) } catch (error) { console.error(error.message); process.exitCode = 1 }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Literal phrases from the 28 October 2026 cleanup judgments. These are
|
|
2
|
+
// review prompts, never evidence that a seed-specific obligation can be cut.
|
|
3
|
+
// Full report paths and the limits of each rule are in CONTRACT-DOCS.md.
|
|
4
|
+
export const prosePatterns = [
|
|
5
|
+
['b', 'Assignment never grants access', 'Orbit d4a8bf1 F5 (line 70)'],
|
|
6
|
+
['b', 'Permission changes apply on the next request', 'Orbit d4a8bf1 F5 (line 70)'],
|
|
7
|
+
['b', 'untrusted source text', 'Strap 819f84b F5 (line 65)'],
|
|
8
|
+
['b', 'authorized job handles', 'Strap 819f84b F5 (line 65)'],
|
|
9
|
+
['d', 'This target-contract round leaves the approved homepage and app interface untouched', 'Orbit d4a8bf1 F8 (line 76)'],
|
|
10
|
+
['d', 'This deliberately replaces the former dedicated hosted-record walkthrough', 'Orbit d4a8bf1 F8 (line 76)'],
|
|
11
|
+
['d', 'Full verification includes the delegation D1, archive and native-browser regressions as well as all retained contract gates.', 'Orbit d4a8bf1 F8 (line 76)'],
|
|
12
|
+
['d', 'Run pnpm test:push', 'Nook bf244ee finding 7 (line 79)'],
|
|
13
|
+
['d', 'ct pattern 1', 'Mango 9d0c381 finding 6 (line 84)'],
|
|
14
|
+
];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { clauseIdSource, plainText } from './seed-contract.mjs'
|
|
2
|
+
import { prosePatterns } from './contract-prose-patterns.mjs'
|
|
3
|
+
|
|
4
|
+
const families = { a: 'acceptance-generated', b: 'base-duty', c: 'tool-class', d: 'record-placement' }
|
|
5
|
+
const classes = /\b(?:standard|external|money|commitment|accounts|gated|access|security|destructive|sensitive|live)\b/i
|
|
6
|
+
const idsIn = text => [...text.matchAll(new RegExp(`(?<![A-Za-z0-9.-])(${clauseIdSource})(?![A-Za-z0-9.-])`, 'g'))].map(match => match[1])
|
|
7
|
+
const cells = line => line.trim().replace(/^\|/, '').replace(/(?<!\\)\|$/, '').split(/(?<!\\)\|/).map(plainText)
|
|
8
|
+
const divider = line => line.includes('|') && cells(line).every(cell => /^:?-{3,}:?$/.test(cell))
|
|
9
|
+
const normalize = text => plainText(text).replace(/\s+/g, ' ').trim()
|
|
10
|
+
|
|
11
|
+
function visibleLines(text) {
|
|
12
|
+
let comment = false, fence
|
|
13
|
+
return text.replace(/\r\n?/g, '\n').split('\n').map(raw => {
|
|
14
|
+
let value = ''
|
|
15
|
+
for (let at = 0; at < raw.length;) {
|
|
16
|
+
const end = raw.indexOf(comment ? '-->' : '<!--', at)
|
|
17
|
+
if (end < 0) { if (!comment) value += raw.slice(at); break }
|
|
18
|
+
if (!comment) value += raw.slice(at, end)
|
|
19
|
+
at = end + (comment ? 3 : 4)
|
|
20
|
+
comment = !comment
|
|
21
|
+
}
|
|
22
|
+
const mark = /^\s*(`{3,}|~{3,})/.exec(value)?.[1]
|
|
23
|
+
if (mark) {
|
|
24
|
+
if (!fence) fence = mark
|
|
25
|
+
else if (mark[0] === fence[0] && mark.length >= fence.length) fence = undefined
|
|
26
|
+
return ''
|
|
27
|
+
}
|
|
28
|
+
return fence ? '' : value
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function contractProseFindings({ text, clauses, coverage, sources, generatedStatement }) {
|
|
33
|
+
const findings = [], lines = visibleLines(text)
|
|
34
|
+
const add = (family, ids, location, message) => {
|
|
35
|
+
for (const id of new Set(ids.length ? ids : ['(no clause id)']))
|
|
36
|
+
findings.push({ family, id, location, message, severity: family === 'a' || family === 'c' ? 'ERROR' : 'WARN' })
|
|
37
|
+
}
|
|
38
|
+
const owners = new Map()
|
|
39
|
+
for (const clause of clauses) {
|
|
40
|
+
const body = []
|
|
41
|
+
for (let index = clause.line; index < lines.length && !/^#{1,6}\s/.test(lines[index]); index++) {
|
|
42
|
+
body.push(lines[index])
|
|
43
|
+
owners.set(index, clause.id)
|
|
44
|
+
}
|
|
45
|
+
const prose = normalize(body.join('\n'))
|
|
46
|
+
const gap = normalize(clause.gap)
|
|
47
|
+
for (const [family, phrase, source] of prosePatterns) {
|
|
48
|
+
for (const [value, line] of [[prose, clause.line], [gap, clause.row]]) {
|
|
49
|
+
const at = value.toLowerCase().indexOf(phrase.toLowerCase())
|
|
50
|
+
if (at >= 0) add(family, [clause.id], `CONTRACT.md:${line}`, `matched ${JSON.stringify(value.slice(at, at + phrase.length))}; source: ${source}`)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (let index = 0; index + 1 < lines.length; index++) {
|
|
56
|
+
if (!lines[index].includes('|') || !divider(lines[index + 1])) continue
|
|
57
|
+
const header = cells(lines[index]), tool = header.findIndex(cell => /^tools?\b/i.test(cell))
|
|
58
|
+
if (tool < 0) continue
|
|
59
|
+
const classColumn = header.findIndex(cell => /\bclass(?:es)?\b/i.test(cell))
|
|
60
|
+
const clauseColumn = header.findIndex(cell => /\bclauses?\b/i.test(cell))
|
|
61
|
+
for (let row = index + 2; row < lines.length && lines[row].trimStart().startsWith('|'); row++) {
|
|
62
|
+
const values = cells(lines[row])
|
|
63
|
+
if (!values[tool] || divider(lines[row])) continue
|
|
64
|
+
if (classColumn >= 0 && classes.test(values[classColumn] ?? '')) continue
|
|
65
|
+
const ids = idsIn(clauseColumn >= 0 ? values[clauseColumn] ?? '' : values.join(' '))
|
|
66
|
+
if (!ids.length && owners.has(row)) ids.push(owners.get(row))
|
|
67
|
+
add('c', ids, `CONTRACT.md:${row + 1}`, `tool ${JSON.stringify(values[tool])} declares no fleet class`)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const [index, fragment] of (coverage?.fragments ?? []).entries()) {
|
|
72
|
+
const destinations = [fragment, ...(fragment.also ?? [])]
|
|
73
|
+
if (!destinations.some(destination => destination.to === 'generated')) continue
|
|
74
|
+
const source = sources.find(entry => entry.file === fragment.file && entry.line === fragment.line && entry.cell === fragment.cell)
|
|
75
|
+
if (!(fragment.file === 'ACCEPTANCE.md' || source?.clause) || generatedStatement(fragment.text)) continue
|
|
76
|
+
const ids = fragment.ids?.length ? fragment.ids : source?.clause ? [source.clause] : idsIn(fragment.text)
|
|
77
|
+
add('a', ids, `docs/contract/COVERAGE.json fragment ${index + 1} (${fragment.file}:${fragment.line})`, `acceptance prose mapped generated: ${JSON.stringify(fragment.text)}`)
|
|
78
|
+
}
|
|
79
|
+
return findings
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function printProseFindings(findings) {
|
|
83
|
+
for (const finding of findings)
|
|
84
|
+
console.log(`${finding.severity} ${finding.id} ${finding.family} ${families[finding.family]} ${finding.location}: ${finding.message}`)
|
|
85
|
+
const errors = findings.filter(finding => finding.severity === 'ERROR').length
|
|
86
|
+
console.log(`Contract prose: ${errors} errors, ${findings.length - errors} warnings.`)
|
|
87
|
+
return errors
|
|
88
|
+
}
|