@runeditrun/rer 0.2.84 → 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 +156 -50
- package/cli/README.md +78 -2
- 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/bounded.mjs +1 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +151 -0
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +29 -6
- package/cli/business/connect.mjs +20 -8
- 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 +80 -30
- 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 -6
- 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 +97 -32
- 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/container-transfer.mjs +2 -2
- package/cli/contract.mjs +7 -7
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +6 -2
- package/cli/deploy-command.mjs +6 -4
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +58 -0
- package/cli/deploy.mjs +9 -7
- package/cli/door-clauses.mjs +157 -0
- package/cli/errors.mjs +1 -1
- package/cli/export.mjs +16 -4
- package/cli/hosted-output.mjs +17 -7
- package/cli/human-error.mjs +20 -0
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +26 -6
- package/cli/main.mjs +2 -1
- package/cli/managed-data-schema.mjs +127 -0
- package/cli/managed-data-zip.mjs +116 -0
- package/cli/managed-data.mjs +110 -0
- package/cli/managed-server.mjs +25 -14
- package/cli/native-owner-entry.mjs +86 -0
- package/cli/output.mjs +3 -2
- package/cli/parse.mjs +2 -2
- package/cli/portability-empty.mjs +65 -0
- package/cli/portability-migrations.mjs +33 -9
- package/cli/portability-policy.mjs +5 -2
- package/cli/portability-worker.mjs +15 -6
- package/cli/portability.mjs +30 -8
- package/cli/production-auth.mjs +1 -1
- package/cli/production-mail.mjs +8 -2
- package/cli/ready-summary.mjs +9 -0
- package/cli/run-transfers.mjs +37 -0
- package/cli/runtime-front-door.mjs +4 -4
- package/cli/server-proxy.mjs +4 -3
- package/cli/server-registry.mjs +13 -8
- package/cli/site.mjs +6 -1
- package/cli/transfers.mjs +17 -4
- package/edition-authoring/archive-source.mjs +59 -0
- package/edition-authoring/base-copies.mjs +147 -25
- 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 +218 -34
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/foundation/runtime/run-data.d.mts +1 -0
- package/foundation/runtime/run-data.mjs +2 -0
- package/global/CHANGELOG.md +126 -0
- package/global/README.md +156 -50
- package/global/cli/command.mjs +8 -2
- package/global/cli/install.mjs +4 -5
- package/global/cli/path-link.mjs +3 -2
- package/global/cli/repo-command.mjs +3 -7
- package/global/door/command.mjs +3 -1
- package/global/launch/dev.mjs +12 -2
- package/global/launch/facts.mjs +2 -2
- package/global/launch/render.mjs +16 -9
- package/global/launch/state.mjs +4 -4
- package/global/main.mjs +13 -8
- package/install.sh +17 -6
- 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/README.md +6 -1
- package/modules/container/adapters/d1-limits.mjs +286 -0
- package/modules/container/adapters/d1-sqlite.mjs +95 -0
- package/modules/container/adapters/d1-workerd-preload.mjs +19 -0
- package/modules/container/adapters/d1-workerd-setup.mjs +26 -0
- package/modules/container/adapters/d1-workerd.mjs +5 -0
- package/modules/container/adapters/sqlite-worker.mjs +5 -3
- package/modules/container/build.mjs +1 -0
- package/modules/container/image-variables.mjs +14 -3
- package/modules/container/transfer.mjs +14 -4
- package/modules/container/worker-engine.mjs +3 -3
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/build.mjs +1 -0
- package/modules/demo-host/native/prepare.mjs +2 -1
- package/modules/demo-host/native/sql.mjs +7 -2
- 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/deploy-kit/README.md +22 -2
- package/modules/deploy-kit/d1-import-diagnostics.mjs +56 -0
- package/modules/deploy-kit/d1-import.mjs +17 -5
- package/modules/deploy-kit/diagnostics.mjs +29 -3
- package/modules/deploy-kit/owner-cli.mjs +20 -7
- package/modules/deploy-kit/provider-transport.mjs +19 -4
- package/modules/deploy-kit/provider.mjs +57 -22
- package/modules/deploy-kit/readiness-window.mjs +1 -1
- package/modules/deploy-kit/site.mjs +8 -3
- package/modules/deploy-kit/worker.mjs +4 -4
- 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/d1/README.md +23 -4
- package/modules/import-kit/src/d1/atomic-prefix.ts +2 -2
- package/modules/import-kit/src/d1/budget.ts +15 -7
- package/modules/import-kit/src/d1/column-layout.ts +5 -0
- package/modules/import-kit/src/d1/creation.ts +15 -8
- package/modules/import-kit/src/d1/database.ts +3 -3
- package/modules/import-kit/src/d1/erasure-pages.ts +2 -1
- package/modules/import-kit/src/d1/erasure.ts +2 -2
- package/modules/import-kit/src/d1/jobs.ts +10 -6
- package/modules/import-kit/src/d1/plans.ts +14 -8
- package/modules/import-kit/src/d1/retirement.ts +2 -2
- package/modules/import-kit/src/d1/sets.ts +1 -3
- package/modules/import-kit/src/d1/staged-creation.ts +3 -3
- 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/limits.ts +1 -1
- 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 +2 -1
- 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 +138 -9
- package/modules/portability/backfills.mjs +9 -8
- package/modules/portability/bridge.mjs +32 -5
- package/modules/portability/catalogue.mjs +12 -5
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/files.mjs +4 -3
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/http.mjs +3 -3
- package/modules/portability/import.mjs +29 -13
- package/modules/portability/index.d.mts +4 -3
- package/modules/portability/index.mjs +1 -1
- package/modules/portability/ledgers.mjs +3 -2
- package/modules/portability/legacy-safety.mjs +11 -2
- package/modules/portability/migration-history.mjs +2 -2
- package/modules/portability/progress.mjs +1 -0
- package/modules/portability/restore-empty.mjs +12 -0
- package/modules/release/github-verify.mjs +11 -2
- package/onboarding/adapter.mjs +35 -6
- package/onboarding/app-fetch.mjs +6 -4
- package/onboarding/development-runtime.mjs +19 -0
- package/onboarding/local/operation.mjs +45 -27
- package/onboarding/loopback-fetch.mjs +16 -0
- package/onboarding/operator-installer.mjs +2 -4
- package/onboarding/process-diagnostics.mjs +6 -2
- package/onboarding/production-runtime.mjs +4 -2
- package/onboarding/readiness.mjs +1 -0
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/scripts/publish-check/public_hygiene.py +1 -1
- package/cli/business/opt-ins.mjs +0 -33
|
@@ -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,14 +645,15 @@ 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 ?? '';
|
|
485
652
|
const inStatus = headings.some(entry => /^Status\b/i.test(entry.text));
|
|
486
653
|
const cells = !insideFence && text.includes('|') ? covCells(text) : [];
|
|
487
|
-
|
|
488
|
-
|
|
654
|
+
// Every Status table line is out of scope except a clause row's non-empty Gap cell.
|
|
655
|
+
if (file === 'CONTRACT.md' && inStatus && !insideFence && text.trimStart().startsWith('|')) {
|
|
656
|
+
if (cells.length === 6 && covId.test(plainText(cells[0])) && plainText(cells[5]).trim()) entries.push({ file, line, cell: 'gap', text: cells[5], raw, clause: plainText(cells[0]), section, homepage: false });
|
|
489
657
|
continue;
|
|
490
658
|
}
|
|
491
659
|
const intro = !introEnded && !headings.some(entry => entry.level > 1) && !definition;
|
|
@@ -551,7 +719,8 @@ function covPlacement(entry, current, contractEntries) {
|
|
|
551
719
|
if (entry.file === 'ACCEPTANCE.md') {
|
|
552
720
|
const repeated = covRepeated(entry, contractEntries);
|
|
553
721
|
if (repeated) return { to: 'copy', of: repeated.line };
|
|
554
|
-
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] };
|
|
555
724
|
return { to: 'docs', path: 'docs/verify.md' };
|
|
556
725
|
}
|
|
557
726
|
if (entry.file !== 'CONTRACT.md') return { to: 'changelog' };
|
|
@@ -584,7 +753,7 @@ function coverageInit(old) {
|
|
|
584
753
|
function covDestination(destination, fragment, source, context, problems, label) {
|
|
585
754
|
const fail = message => problems.push(`${label}: ${message}`);
|
|
586
755
|
if (!destination || typeof destination !== 'object' || Array.isArray(destination)) { fail('A destination must be an object.'); return; }
|
|
587
|
-
const { current,
|
|
756
|
+
const { current, expected, groups } = context;
|
|
588
757
|
const note = () => { if (typeof destination.note !== 'string' || !destination.note.trim()) fail(`${destination.to} needs a note.`); };
|
|
589
758
|
const ids = known => {
|
|
590
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; }
|
|
@@ -636,6 +805,8 @@ function covDestination(destination, fragment, source, context, problems, label)
|
|
|
636
805
|
}
|
|
637
806
|
}
|
|
638
807
|
function coverageCheck(old) {
|
|
808
|
+
validateOriginalClaims(old);
|
|
809
|
+
validateClaimSource(read('CONTRACT.md'), undefined, old);
|
|
639
810
|
const map = covReadMap(), problems = [], entries = covScope(old), expected = new Map(entries.map(entry => [covKey(entry), entry])), groups = new Map();
|
|
640
811
|
if (map.schema !== 1) problems.push('Coverage schema must be 1.');
|
|
641
812
|
if (map.old?.commit !== old.commit) problems.push(`Coverage old.commit must equal ${old.commit}; found ${JSON.stringify(map.old?.commit)}.`);
|
|
@@ -734,20 +905,33 @@ function coverageRebase(from, onto) {
|
|
|
734
905
|
return { ...map, old: { commit: onto.commit, files: covFiles(onto) }, fragments };
|
|
735
906
|
}
|
|
736
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>]';
|
|
737
918
|
function main(args) {
|
|
738
919
|
const [command, ...rest] = args
|
|
739
|
-
const option = name => {
|
|
920
|
+
const option = (name, description = 'Git reference') => {
|
|
740
921
|
const index = rest.indexOf(name)
|
|
741
|
-
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.`)
|
|
742
924
|
return rest[index + 1]
|
|
743
925
|
}
|
|
744
926
|
if (command === 'write' && !rest.length) generate()
|
|
745
|
-
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)
|
|
746
930
|
else if (command === 'id-map') idMap(snapshot(option('--old')))
|
|
747
931
|
else if (command === 'coverage' && rest[0] === 'init') coverageInit(snapshot(option('--old')))
|
|
748
932
|
else if (command === 'coverage' && rest[0] === 'check') coverageCheck(snapshot(option('--old')))
|
|
749
933
|
else if (command === 'coverage' && rest[0] === 'rebase') coverageRebase(snapshot(option('--from')), snapshot(option('--onto')))
|
|
750
|
-
else if (command === 'convert') convert(snapshot(option('--old')), rest.includes('--old-acceptance') ? snapshot(option('--old-acceptance')) : undefined)
|
|
751
|
-
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)
|
|
752
936
|
}
|
|
753
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const coldRunBudget: string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// One budget for public local-run instructions; estimates vary by app and cache.
|
|
2
|
+
export const coldRunBudget = 'Allow roughly 500 MB–1 GB of downloads and 1–3 GB of disk space for a first run, including Node, rer, the app and its dependencies. The app and your computer can need more; later runs reuse downloads.';
|