@runeditrun/rer 0.2.87 → 0.2.89
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/cli/agent-door.mjs +1 -0
- package/cli/export.mjs +1 -1
- package/cli/hosted-output.mjs +5 -1
- package/edition-authoring/base-acknowledgements.mjs +7 -4
- package/edition-authoring/base-copies.mjs +1 -1
- package/edition-authoring/module-closure.mjs +12 -2
- package/global/CHANGELOG.md +20 -0
- package/modules/agent-door/capabilities.d.mts +6 -0
- package/modules/agent-door/capabilities.mjs +12 -0
- package/modules/agent-door/conformance/audit.mjs +2 -0
- package/modules/agent-door/conformance/discovery.mjs +2 -0
- package/modules/agent-door/conformance/index.mjs +8 -1
- package/modules/agent-door/conformance/journey.mjs +2 -1
- package/modules/agent-door/conformance/negative.mjs +2 -1
- package/modules/agent-door/conformance/subscription.mjs +39 -0
- package/modules/agent-door/conformance/subset.mjs +40 -0
- package/modules/agent-door/conformance/surface.mjs +7 -1
- package/modules/import-kit/src/door/ADOPTING.md +9 -0
- package/modules/portability/README.md +13 -3
- package/modules/portability/bridge.mjs +7 -6
- package/modules/portability/import.mjs +4 -3
- package/package.json +1 -1
- package/scripts/publish-check/README.md +9 -0
- package/scripts/publish-check/lockfile_metadata.mjs +141 -0
- package/scripts/publish-check/lockfile_metadata.py +30 -0
- package/scripts/publish-check/public_hygiene.py +3 -1
package/cli/agent-door.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import { verificationBindings } from './agent-bindings.mjs';
|
|
|
18
18
|
import { journeyFixtures } from './agent-journey-fixtures.mjs';
|
|
19
19
|
|
|
20
20
|
function finish(result, report) {
|
|
21
|
+
if (result.capabilities) report(`Agent capabilities (${result.capabilities.mode}): declared=${result.capabilities.declared.join(',')}; refused=${result.capabilities.refused.join(',')}; unscoped=${result.capabilities.unscoped.join(',')}.`);
|
|
21
22
|
for (const point of result.points) report(`${point.ok ? 'PASS' : 'FAIL'} ${point.id}${point.ok || !point.detail ? '' : `: ${point.detail}`}`);
|
|
22
23
|
const failed = result.points.filter(point => !point.ok).map(point => point.id);
|
|
23
24
|
report(`Agent door conformance: ${result.points.length - failed.length}/${result.points.length} points passed.`);
|
package/cli/export.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
8
8
|
// Copy whole maintained source/tooling directories. Python publication scans
|
|
9
9
|
// load sibling modules and data dynamically; they belong in the inventory too.
|
|
10
10
|
export const sourceRoots = ['default-seed/public/rer-theme.css', 'default-seed/public/brand/mark.svg', 'default-seed/public/fonts/outfit', 'bin/rer.mjs', 'cli', 'modules/delivery-producer/declarations.mjs', 'modules/delivery-producer/bindings.mjs', 'modules/delivery-producer/migrations.mjs', 'modules/delivery-producer/mail.mjs', 'modules/job-queue', 'modules/release', 'modules/deploy-kit', 'modules/site', 'modules/container', 'modules/demo-host', 'modules/demo', 'modules/integrations/core', 'modules/mail', 'modules/ai', 'modules/portability', 'modules/d1-transport', 'modules/import-kit/src/receipt', 'modules/import-kit/src/status', 'modules/import-kit/schema', 'modules/import-kit/src/d1', 'modules/import-kit/src/door', 'modules/import-kit/src/readers', 'modules/import-kit/src/provenance/numeric-credentials.ts', 'modules/import-kit/src/types.ts', 'modules/import-kit/src/plan', 'modules/import-kit/src/provenance/canonical-hash.ts', 'modules/import-kit/src/provenance/canonical-stream.ts', 'modules/import-kit/src/provenance/credential-names.ts', 'modules/import-kit/src/provenance/credentials.ts', 'modules/import-kit/src/provenance/identity.ts', 'modules/import-kit/src/provenance/json-snapshot.ts', 'modules/import-kit/src/provenance/resumable-sha256.ts', 'modules/import-kit/src/provenance/validate-json.ts', 'modules/import-kit/src/journal/authority.ts', 'modules/import-kit/src/storage/originals.ts', 'modules/import-kit/src/storage/provenance.ts', 'modules/import-kit/src/storage/schema.ts', 'modules/erasure', 'modules/dependencies', 'modules/operator-auth', 'modules/owner-claim', 'operations', 'scripts/publish-check', 'scripts/publish-check.mjs', 'composition/git-source.mjs', 'edition-authoring/adopt.mjs', 'edition-authoring/base-acknowledgements.mjs', 'edition-authoring/base-copies.mjs', 'edition-authoring/module-closure.mjs', 'edition-authoring/edition-migrations.mjs', 'edition-authoring/cli.mjs', 'edition-authoring/copy-checkout.mjs', 'edition-authoring/files.mjs', 'edition-authoring/lock.mjs', 'edition-authoring/manifest.mjs', 'edition-authoring/offline-git.mjs', 'edition-authoring/parent-comparison.mjs', 'edition-authoring/projection-lock.mjs', 'edition-authoring/release.mjs', 'edition-authoring/runtime-dependencies.mjs', 'edition-authoring/module-resolution.mjs', 'edition-authoring/package-target.mjs', 'edition-authoring/module-syntax.mjs', 'edition-authoring/module-edges.mjs', 'edition-authoring/vendor/babel-parser', 'edition-authoring/workflow-copies.mjs', 'edition-authoring/workflow-scripts.mjs', 'edition-authoring/vendor/yaml', 'edition-authoring/sources.mjs', 'edition-authoring/updates.mjs', 'foundation/runtime/seed-contract.mjs', 'foundation/runtime/run-data.mjs', 'foundation/runtime/run-data.d.mts', 'foundation/runtime/contract-docs.mjs'];
|
|
11
|
-
sourceRoots.push('modules/agent-door/conformance', 'modules/agent-door/CLAUSES.md');
|
|
11
|
+
sourceRoots.push('modules/agent-door/capabilities.mjs', 'modules/agent-door/capabilities.d.mts', 'modules/agent-door/conformance', 'modules/agent-door/CLAUSES.md');
|
|
12
12
|
sourceRoots.push('edition-authoring/archive-source.mjs');
|
|
13
13
|
sourceRoots.push('edition-authoring/copy-namespaces.mjs');
|
|
14
14
|
sourceRoots.push('foundation/runtime/contract-prose.mjs', 'foundation/runtime/contract-prose-patterns.mjs');
|
package/cli/hosted-output.mjs
CHANGED
|
@@ -62,7 +62,11 @@ export async function serveHosted(root, { declaration: declarationPath = 'deploy
|
|
|
62
62
|
const nativeBindings = Object.fromEntries(Object.entries(nativeWorkers).map(([entrypoint, binding]) => [binding, { name: 'app', entrypoint }]));
|
|
63
63
|
const modules = [entry, ...(await files(build)).map(path => join(build, path)).filter(path => path !== entry && moduleTypes[extname(path)])].map(path => ({ type: moduleTypes[extname(path)], path }));
|
|
64
64
|
const identity = { sourceSha: createHash('sha1').update(randomBytes(16)).digest('hex'), fingerprint: createHash('sha256').update(randomBytes(16)).digest('hex'), versionId: crypto.randomUUID() };
|
|
65
|
-
|
|
65
|
+
// Optional integrations stay unconfigured unless verification opts in. Invented
|
|
66
|
+
// endpoint/certificate values can enable an invalid native auth configuration.
|
|
67
|
+
const secrets = Object.fromEntries((declaration.secrets ?? [])
|
|
68
|
+
.filter(item => item.optional !== true || typeof item.verifyStandIn === 'string' && item.verifyStandIn)
|
|
69
|
+
.map(item => [item.binding, standIn(item, manifest.fields?.find(field => field.name === item.binding))]));
|
|
66
70
|
for (const binding of await hostedMailCredentials(root)) {
|
|
67
71
|
if (!Object.hasOwn(secrets, binding)) secrets[binding] = standIn({}, manifest.fields?.find(field => field.name === binding));
|
|
68
72
|
}
|
|
@@ -7,13 +7,16 @@ const quote = value => /^[a-zA-Z0-9_./:-]+$/.test(value) ? value : `'${value.rep
|
|
|
7
7
|
|
|
8
8
|
export const snapshot = file => ({sha256: hash(file.read()), mode: file.executable ? '100755' : '100644'});
|
|
9
9
|
|
|
10
|
+
export function acknowledgementCommand(root, name, recordPath) {
|
|
11
|
+
const relative = path.relative(root, cli);
|
|
12
|
+
return ['node', relative.startsWith('..') ? cli : relative, 'adapt-base', name,
|
|
13
|
+
...(recordPath === 'base-copies.json' ? [] : ['--record', recordPath])].map(quote).join(' ');
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
// Keep the upstream baseline separate from the local bytes the owner accepted.
|
|
11
17
|
// Legacy declarations remain readable, but cannot silently acknowledge new bytes.
|
|
12
18
|
export function acknowledgementDrift(root, copy, name, file, recordPath) {
|
|
13
|
-
const
|
|
14
|
-
const command = ['node', relative.startsWith('..') ? cli : relative, 'adapt-base', name,
|
|
15
|
-
...(recordPath === 'base-copies.json' ? [] : ['--record', recordPath])].map(quote).join(' ');
|
|
16
|
-
const detail = {path: name, copy: copy.path, acknowledge: command};
|
|
19
|
+
const detail = {path: name, copy: copy.path, acknowledge: acknowledgementCommand(root, name, recordPath)};
|
|
17
20
|
const expected = copy.acknowledged?.[name];
|
|
18
21
|
if (!expected) return [{kind: 'adaptation-unacknowledged', ...detail}];
|
|
19
22
|
const actual = snapshot(file);
|
|
@@ -534,7 +534,7 @@ export function refreshCopies(root, {positional: [revision], record: recordPath,
|
|
|
534
534
|
notices = templates.notices;
|
|
535
535
|
completeWorkflowHelpers(root, plans, {tree: next, read, revision});
|
|
536
536
|
const relocations = new Map();
|
|
537
|
-
const withheld = completeModuleCopies(root, plans, {tree: next, read, revision, base: origin.repository, ownerSources, relocations,
|
|
537
|
+
const withheld = completeModuleCopies(root, plans, {tree: next, read, revision, base: origin.repository, baseArchive, recordPath, ownerSources, relocations,
|
|
538
538
|
deliveries: migrations.flatMap(step => step.deliver.map(source => ({source, origin: step.origin, importers: step.copies})))});
|
|
539
539
|
// Closure may add individually recorded siblings when the seed originally
|
|
540
540
|
// selected runtime files one at a time instead of copying the directory.
|
|
@@ -5,12 +5,13 @@ import {raw, safe, requirePhysical, testSource, freedEntries, toolFile} from './
|
|
|
5
5
|
import {dependencies, resolve, external, bindings, lexicalExports} from './runtime-dependencies.mjs';
|
|
6
6
|
import {relocateDependencies} from './module-edges.mjs';
|
|
7
7
|
import {sharedNamespaces} from './copy-namespaces.mjs';
|
|
8
|
+
import {acknowledgementCommand} from './base-acknowledgements.mjs';
|
|
8
9
|
const code = name => /\.(?:[cm]?[jt]s|[jt]sx)$/.test(name) && !testSource(name);
|
|
9
10
|
const inside = (name, prefix) => prefix === '.' ? !name.startsWith('../') && !path.posix.isAbsolute(name) : name === prefix || name.startsWith(prefix + '/');
|
|
10
11
|
const mapped = (source, copy) => copy.path + source.slice(copy.originPath.length);
|
|
11
12
|
const quote = value => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
12
13
|
|
|
13
|
-
export function completeModuleCopies(root, plans, {tree, read, revision, base, deliveries = [], ownerSources = new Map(), relocations = new Map()}) {
|
|
14
|
+
export function completeModuleCopies(root, plans, {tree, read, revision, base, baseArchive, recordPath, deliveries = [], ownerSources = new Map(), relocations = new Map()}) {
|
|
14
15
|
const index = new Set(raw(root, 'ls-files', '-z').toString('utf8').split('\0').filter(Boolean));
|
|
15
16
|
const required = new Set();
|
|
16
17
|
const mappings = plans.filter(plan => !plan.retired).map(({copy}) => ({copy, ...namespace(copy)})).filter(mapping => mapping.from);
|
|
@@ -252,7 +253,16 @@ export function completeModuleCopies(root, plans, {tree, read, revision, base, d
|
|
|
252
253
|
for (const [types, current, previous] of [[false, imports, oldBindings], [true, typeImports, oldTypes]]) {
|
|
253
254
|
const exported = exportsAt(destination, types);
|
|
254
255
|
for (const name of current.get(specifier) ?? []) if (exported && !exported.has(name) && !previous.get(specifier)?.has(name)) {
|
|
255
|
-
|
|
256
|
+
const comparison = destination + '.base';
|
|
257
|
+
const extract = baseArchive ? `cp ${quote(path.join(baseArchive, dependency))} ${quote(comparison)}` :
|
|
258
|
+
`git -C ${quote(base)} show ${quote(revision + ':' + dependency)} > ${quote(comparison)}`;
|
|
259
|
+
throw Error([
|
|
260
|
+
`Cannot refresh module ${target}: ${destination} does not export ${name} required by Base ${dependency} at ${revision}. No files were refreshed.`,
|
|
261
|
+
'Save the incoming dependency for comparison:', extract,
|
|
262
|
+
`Merge the required exports from ${quote(comparison)} into ${quote(destination)}, preserving seed edits.`,
|
|
263
|
+
...(owner?.copy.adapted?.[destination] ? ['Review the reconciled bytes and mode, then acknowledge this adaptation:', acknowledgementCommand(root, destination, recordPath)] : []),
|
|
264
|
+
`Remove ${quote(comparison)} after reconciliation, then repeat refresh-base.`,
|
|
265
|
+
].join('\n'));
|
|
256
266
|
}
|
|
257
267
|
}
|
|
258
268
|
}
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.89
|
|
4
|
+
|
|
5
|
+
- Publication email hygiene recognizes parsed dependency package contact metadata and registry deprecation notices in pnpm, npm and Yarn lockfiles. Comments, custom keys, repository author fields, source files and secret checks retain their findings; no address allowlist is needed. This scanner source update can be adopted independently of a launcher package release.
|
|
6
|
+
|
|
7
|
+
- Re-execute completed read-only approval replays under current native grants, so aggregate reads cannot disclose rows retained before client revocation. Native empty results and refusals replace cached payloads; unchanged visibility retains the result and approval receipt. Mutation replays still execute their effect once.
|
|
8
|
+
|
|
9
|
+
- Leave optional deploy secrets unconfigured during hosted output and agent-door verification unless they declare a nonempty `verifyStandIn`. This prevents invented SSO endpoints from causing HTTP 500 before signed owner bootstrap. Required and explicitly selected stand-ins remain; public-door coverage retains invalid-signature and replay refusals. See `ADOPTING.md`.
|
|
10
|
+
|
|
11
|
+
- Verify legacy v2 backups at their recorded migration schema before applying the additive bridge or a declared row upgrade. Missing or unknown history, schema drift and altered archive digests remain refused before staging.
|
|
12
|
+
|
|
13
|
+
- Reconstruct excluded-table objects omitted by older v2 inventories only when recorded replay proves that historical inventory and the complete live destination. Unrecorded excluded objects remain refused.
|
|
14
|
+
|
|
15
|
+
## 0.2.88
|
|
16
|
+
|
|
17
|
+
- Agent doors can declare the mandatory tools/policy/pause/audit/idempotency core plus events, resources, prompts and subscriptions. Discovery and conformance report declared, refused and unscoped families; omitted supported capabilities are hidden and return typed refusals. Core authorization and security checks remain mandatory, and absent declarations retain the legacy full requirements. Other lifecycle families remain explicitly unscoped with their existing checks intact.
|
|
18
|
+
|
|
19
|
+
- `rer refresh-base` now gives complete recovery steps when refreshed import-kit
|
|
20
|
+
|
|
21
|
+
- Refuse resource subscriptions when resources are undeclared, retaining native visibility readers for declared event filtering. Preserve unknown journey tools for validation and return typed tool_not_found errors for unknown calls. Mandatory core authorization, policy, pause, audit and idempotency remain unconditional.
|
|
22
|
+
|
|
3
23
|
## 0.2.87
|
|
4
24
|
|
|
5
25
|
- Connect declared, contained agent verifier drivers to named native Worker RPC entrypoints, and run built queue consumers alongside producers. Public-door fixtures prove real queued effects, execution-time consent revocation and retained audits without a served test route.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type Capability = 'tools' | 'policy' | 'pause' | 'audit' | 'idempotency' | 'events' | 'resources' | 'prompts' | 'subscriptions';
|
|
2
|
+
export const CORE_CAPABILITIES: Capability[];
|
|
3
|
+
export const OPTIONAL_CAPABILITIES: Capability[];
|
|
4
|
+
export const UNSCOPED_CAPABILITIES: string[];
|
|
5
|
+
export function capabilitySet(declaration?: readonly Capability[]): { mode: string; declared: Capability[]; refused: Capability[]; unscoped: string[] };
|
|
6
|
+
export function offers(declaration: readonly Capability[] | undefined, capability: Capability): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Security duties are indivisible. Undefined preserves the legacy full door. */
|
|
2
|
+
export const CORE_CAPABILITIES = ['tools', 'policy', 'pause', 'audit', 'idempotency'];
|
|
3
|
+
export const OPTIONAL_CAPABILITIES = ['events', 'resources', 'prompts', 'subscriptions'];
|
|
4
|
+
export const UNSCOPED_CAPABILITIES = ['multiSponsor', 'mailEdges', 'resourceRefresh', 'timedLifecycle', 'dualHost', 'queuedLifecycle', 'ownerNativeApi'];
|
|
5
|
+
export function capabilitySet(declaration) {
|
|
6
|
+
const all = [...CORE_CAPABILITIES, ...OPTIONAL_CAPABILITIES];
|
|
7
|
+
if (declaration === undefined) return { mode: 'legacy', declared: all, refused: [], unscoped: [...UNSCOPED_CAPABILITIES] };
|
|
8
|
+
if (!Array.isArray(declaration) || new Set(declaration).size !== declaration.length || declaration.some(name => !all.includes(name)) || CORE_CAPABILITIES.some(name => !declaration.includes(name))) throw new TypeError(`Agent capabilities must be a unique list containing ${CORE_CAPABILITIES.join(', ')}; optional: ${OPTIONAL_CAPABILITIES.join(', ')}. Other lifecycle families cannot yet be scoped.`);
|
|
9
|
+
if (declaration.includes('subscriptions') && !declaration.includes('events')) throw new TypeError('subscriptions requires events');
|
|
10
|
+
return { mode: 'declared', declared: [...declaration], refused: OPTIONAL_CAPABILITIES.filter(name => !declaration.includes(name)), unscoped: [...UNSCOPED_CAPABILITIES] };
|
|
11
|
+
}
|
|
12
|
+
export const offers = (declaration, capability) => declaration === undefined || declaration.includes(capability);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { offers } from '../capabilities.mjs';
|
|
1
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import { classIds } from './protocol.mjs';
|
|
3
4
|
import { AGENT_CLASSES } from './surface.mjs';
|
|
@@ -34,6 +35,7 @@ export async function auditPhase(c) {
|
|
|
34
35
|
c.add('BASE-AGENT-007.7.differs-from-policy', differs === 0, `Audit evidence has ${differs} decisions that differ from the policy in force.`);
|
|
35
36
|
// Audit is read before the events tool: its own call is audited as well, but
|
|
36
37
|
// cannot occur in a snapshot taken before it was made.
|
|
38
|
+
if (!offers(c.surface.capabilities, 'events')) return;
|
|
37
39
|
const events = []; let after;
|
|
38
40
|
for (let page = 0; page < 100; page++) {
|
|
39
41
|
const result = await c.tool(`${c.surface.seed}.events.list`, { ...(after ? { after } : {}), limit: 200 });
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { offers } from '../capabilities.mjs';
|
|
1
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import { accessToken } from './crypto.mjs';
|
|
3
4
|
import { narrowingContract } from './narrowing.mjs';
|
|
@@ -53,6 +54,7 @@ export async function listedDoor(c) {
|
|
|
53
54
|
c.add('BASE-AGENT-003.1', isDeepStrictEqual((templates.result?.resourceTemplates ?? []).map(item => item.uriTemplate).sort(), [...c.surface.resources].sort()), 'resources/templates/list must match the Agent surface.');
|
|
54
55
|
const prompts = await c.mcp('prompts/list');
|
|
55
56
|
c.add('BASE-AGENT-013.5.prompts', Array.isArray(prompts.result?.prompts), 'prompts/list must list the declared specialist prompts.');
|
|
57
|
+
if (c.surface.capabilities !== undefined && offers(c.surface.capabilities, 'prompts')) c.add('BASE-AGENT-subset.prompts.offered', prompts.result?.prompts?.length > 0, 'Declared prompts must offer a specialist prompt.');
|
|
56
58
|
if (prompts.result?.prompts?.length) {
|
|
57
59
|
const prompt = await c.mcp('prompts/get', { name: prompts.result.prompts[0].name });
|
|
58
60
|
c.add('BASE-AGENT-001.1.prompts', Array.isArray(prompt.result?.messages) && prompt.result.messages.length > 0, 'A specialist prompt must be retrievable with Mcp-Name.');
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { capabilitySet, offers } from '../capabilities.mjs';
|
|
2
|
+
import { scopedSurface, refusalPhase } from './subset.mjs';
|
|
3
|
+
import { subscriptionPhase } from './subscription.mjs';
|
|
1
4
|
import { randomUUID } from 'node:crypto';
|
|
2
5
|
import { validateAgentSurface } from './surface.mjs';
|
|
3
6
|
import { createProtocol } from './protocol.mjs';
|
|
@@ -19,6 +22,8 @@ export { validateAgentSurface } from './surface.mjs';
|
|
|
19
22
|
export async function runAgentDoorConformance({ fetch, invoke, origin, surface, signer, person, sponsors = [person], webhooks, business = 'rer-agent-conformance', consent = randomUUID(), now, prove, nativeJourney, nativeStep, prepare }) {
|
|
20
23
|
const validation = validateAgentSurface(surface), points = [...validation.points];
|
|
21
24
|
if (!validation.ok) return { ok: false, points };
|
|
25
|
+
const capabilities = capabilitySet(surface.capabilities);
|
|
26
|
+
surface = scopedSurface(surface);
|
|
22
27
|
if (typeof fetch !== 'function' || !signer?.privateKey || !signer.issuer || !signer.installationId || !signer.kid || !person?.email || !person.cookie || typeof person.sub !== 'string' || !person.sub.trim() || typeof consent !== 'string' || !consent.trim() || new URL(origin).origin !== origin) throw new TypeError('Conformance requires fetch, canonical origin, signer, consent and signed-in person {email,cookie,sub}');
|
|
23
28
|
const c = createProtocol({ fetch, origin, surface, signer, person, business, consent, now, prove, nativeStep, prepare, points, agentId: `rer-conformance-${randomUUID()}`, seq: 0, revision: 0, listed: new Map() });
|
|
24
29
|
await c.phase('BASE-AGENT-001.transport', () => discoverDoor(c));
|
|
@@ -35,7 +40,9 @@ export async function runAgentDoorConformance({ fetch, invoke, origin, surface,
|
|
|
35
40
|
if (surface.tools.some(tool => tool.authority === 'none')) await c.phase('BASE-AGENT-005.no-subject', () => recordSecurityPhase(c));
|
|
36
41
|
if (surface.verification?.replayAdmission) await c.phase('BASE-AGENT-012.replay', () => replayAdmissionPhase(c, surface.verification.replayAdmission));
|
|
37
42
|
if (webhooks) await c.phase('BASE-AGENT-006.webhook', () => webhookPhase(c, webhooks));
|
|
43
|
+
await c.phase('BASE-AGENT-subset.refusals', () => refusalPhase(c));
|
|
44
|
+
if (capabilities.mode === 'declared' && offers(surface.capabilities, 'subscriptions')) await c.phase('BASE-AGENT-subset.subscriptions', () => subscriptionPhase(c));
|
|
38
45
|
await c.phase('BASE-AGENT-009.phase7', () => auditPhase(c));
|
|
39
46
|
if (sponsors.length > 1) await c.phase('BASE-AGENT-004.cross-sponsor', () => crossSponsorPhase(c, sponsors));
|
|
40
|
-
return { ok: points.every(point => point.ok), points };
|
|
47
|
+
return { ok: points.every(point => point.ok), points, capabilities };
|
|
41
48
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { offers } from '../capabilities.mjs';
|
|
1
2
|
import { randomUUID } from 'node:crypto';
|
|
2
3
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
4
|
import { classIds, subset, errorCode, APPROVAL } from './protocol.mjs';
|
|
@@ -87,7 +88,7 @@ export async function runJourney(c, phase, { held = false, injections = false, r
|
|
|
87
88
|
const smuggled = await c.stepTool(step, { ...args, idempotency_key: randomUUID(), grant_to_add: 'admin' });
|
|
88
89
|
c.add(`BASE-AGENT-005.narrowing.${step.tool}.undeclared`, errorCode(smuggled) === 'invalid_arguments' && isDeepStrictEqual(beforeInjection, await c.witness()), `${step.tool} must refuse an undeclared widening argument without an effect.`);
|
|
89
90
|
}
|
|
90
|
-
if (!c.surface.tools.find(tool => tool.name === step.tool)?.readOnly) {
|
|
91
|
+
if (offers(c.surface.capabilities, 'events') && !c.surface.tools.find(tool => tool.name === step.tool)?.readOnly) {
|
|
91
92
|
const snapshot = await c.tool(`${c.surface.seed}.events.list`, { limit: 200 }, { client: step.client });
|
|
92
93
|
if (!Array.isArray(snapshot.result?.structuredContent?.events)) throw new Error('Post-effect events.list must return events');
|
|
93
94
|
(c.effectEvents ??= []).push(...snapshot.result.structuredContent.events);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { offers } from '../capabilities.mjs';
|
|
1
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
3
|
import { webcrypto } from 'node:crypto';
|
|
3
4
|
import { accessToken, autonomousPolicy, policyEnvelope, seconds, signJws } from './crypto.mjs';
|
|
@@ -8,7 +9,7 @@ export async function negativePhase(c) {
|
|
|
8
9
|
await c.prepare('negative');
|
|
9
10
|
const before = await c.witness(), iat = seconds(c.now);
|
|
10
11
|
const unavailable = await c.mcp('resources/read', { uri: `unregistered://${crypto.randomUUID()}` });
|
|
11
|
-
c.add('BASE-AGENT-003.refusal-code', unavailable.message?.error?.data?.code === 'tool_not_found' && unavailable.result === undefined, 'An unregistered resource must refuse with JSON-RPC error.data.code and no content.');
|
|
12
|
+
c.add('BASE-AGENT-003.refusal-code', unavailable.message?.error?.data?.code === (offers(c.surface.capabilities, 'resources') ? 'tool_not_found' : 'capability_not_declared') && unavailable.result === undefined, 'An unregistered resource must refuse with JSON-RPC error.data.code and no content.');
|
|
12
13
|
const noToken = await c.mcp('tools/list', {}, { token: null });
|
|
13
14
|
c.add('BASE-AGENT-004.1.challenge', noToken.status === 401 && /resource_metadata=/.test(noToken.headers.get('www-authenticate') ?? ''), 'An unauthenticated call must return 401 and a resource_metadata challenge.');
|
|
14
15
|
for (const [name, overrides] of [
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { accessToken, autonomousPolicy } from './crypto.mjs';
|
|
2
|
+
import { VERSION } from './protocol.mjs';
|
|
3
|
+
|
|
4
|
+
/** Exercise the stream itself; ordinary JSON/SSE MCP replies still use protocol. */
|
|
5
|
+
export async function subscriptionPhase(c) {
|
|
6
|
+
await c.adopt(autonomousPolicy());
|
|
7
|
+
const abort = new AbortController();
|
|
8
|
+
const response = await c.request('/mcp', { method: 'POST', signal: abort.signal, headers: {
|
|
9
|
+
Origin: c.origin, Authorization: `Bearer ${await accessToken(c)}`, 'Content-Type': 'application/json',
|
|
10
|
+
'MCP-Protocol-Version': VERSION, 'Mcp-Method': 'subscriptions/listen',
|
|
11
|
+
}, body: JSON.stringify({ jsonrpc: '2.0', id: 'subset-subscription', method: 'subscriptions/listen', params: {
|
|
12
|
+
notifications: { toolsListChanged: true }, _meta: { 'io.modelcontextprotocol/protocolVersion': VERSION },
|
|
13
|
+
} }) });
|
|
14
|
+
const reader = response.body.getReader(), decoder = new TextDecoder();
|
|
15
|
+
let buffer = '';
|
|
16
|
+
async function next() {
|
|
17
|
+
for (;;) {
|
|
18
|
+
const boundary = buffer.indexOf('\n\n');
|
|
19
|
+
if (boundary >= 0) {
|
|
20
|
+
const block = buffer.slice(0, boundary); buffer = buffer.slice(boundary + 2);
|
|
21
|
+
const data = block.split('\n').filter(line => line.startsWith('data:')).map(line => line.slice(5).trimStart()).join('\n');
|
|
22
|
+
if (data) return JSON.parse(data);
|
|
23
|
+
}
|
|
24
|
+
const chunk = await reader.read();
|
|
25
|
+
if (chunk.done) return null;
|
|
26
|
+
buffer += decoder.decode(chunk.value, { stream: true });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const timeout = setTimeout(() => abort.abort(), 10000);
|
|
30
|
+
try {
|
|
31
|
+
const ack = await next();
|
|
32
|
+
c.add('BASE-AGENT-subset.subscriptions.ack', response.ok && response.headers.get('content-type')?.includes('text/event-stream') && ack?.method === 'notifications/subscriptions/acknowledged' && ack.params?.notifications?.toolsListChanged === true && ack.params?._meta?.['io.modelcontextprotocol/subscriptionId'] === 'subset-subscription', 'Declared subscriptions must acknowledge their requested notifications and subscription identity.');
|
|
33
|
+
await c.adopt(autonomousPolicy(), { paused: true });
|
|
34
|
+
const final = await next();
|
|
35
|
+
c.add('BASE-AGENT-subset.subscriptions.pause', final?.id === 'subset-subscription' && final.result?.resultType === 'complete', 'Pause must terminate the live subscription.');
|
|
36
|
+
} finally {
|
|
37
|
+
clearTimeout(timeout); await reader.cancel().catch(() => {}); abort.abort(); await c.adopt(autonomousPolicy());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { capabilitySet, offers } from '../capabilities.mjs';
|
|
3
|
+
import { errorCode } from './protocol.mjs';
|
|
4
|
+
|
|
5
|
+
export function scopedSurface(surface) {
|
|
6
|
+
if (!surface || typeof surface !== 'object') return surface;
|
|
7
|
+
const set = capabilitySet(surface.capabilities);
|
|
8
|
+
if (set.mode === 'legacy' || !surface || typeof surface !== 'object') return surface;
|
|
9
|
+
// Only the built-in event tool is optional here. Native tools, authorization,
|
|
10
|
+
// proofs, provider isolation and all declared native journeys remain intact.
|
|
11
|
+
const enabled = tool => tool.name !== `${surface.seed}.events.list` || offers(surface.capabilities, 'events');
|
|
12
|
+
const tools = surface.tools?.filter(enabled);
|
|
13
|
+
return { ...surface, tools, journey: surface.journey?.filter(step => step?.tool !== `${surface.seed}.events.list` || offers(surface.capabilities, 'events')),
|
|
14
|
+
resources: offers(surface.capabilities, 'resources') ? surface.resources : [] };
|
|
15
|
+
}
|
|
16
|
+
export async function refusalPhase(c) {
|
|
17
|
+
const set = capabilitySet(c.surface.capabilities);
|
|
18
|
+
if (set.mode === 'legacy') return;
|
|
19
|
+
const discovery = await c.mcp('server/discover');
|
|
20
|
+
c.add('BASE-AGENT-subset.discovery', isDeepStrictEqual(discovery.result?._meta?.['com.runeditrun/capabilities'], set), 'Discovery must identify the exact declared, refused and unscoped capabilities.');
|
|
21
|
+
const witness = await c.witness();
|
|
22
|
+
for (const capability of set.refused) {
|
|
23
|
+
if (['resources', 'prompts'].includes(capability)) {
|
|
24
|
+
c.add(`BASE-AGENT-subset.discovery.${capability}`, !Object.hasOwn(discovery.result?.capabilities ?? {}, capability), `${capability} must be absent from discovery.`);
|
|
25
|
+
const listing = await c.mcp(capability === 'resources' ? 'resources/templates/list' : 'prompts/list');
|
|
26
|
+
c.add(`BASE-AGENT-subset.list.${capability}`, isDeepStrictEqual(listing.result?.[capability === 'resources' ? 'resourceTemplates' : 'prompts'], []), `${capability} must list no undeclared items.`);
|
|
27
|
+
}
|
|
28
|
+
if (capability === 'events') {
|
|
29
|
+
const listing = await c.mcp('tools/list');
|
|
30
|
+
c.add('BASE-AGENT-subset.list.events', !listing.result?.tools?.some(tool => tool.name === `${c.surface.seed}.events.list`), 'Undeclared events must not appear in tools/list.');
|
|
31
|
+
}
|
|
32
|
+
if (capability === 'subscriptions') c.add('BASE-AGENT-subset.discovery.subscriptions', discovery.result?.capabilities?.tools?.listChanged === false && !discovery.result?.capabilities?.resources?.subscribe, 'Undeclared subscriptions must not be advertised.');
|
|
33
|
+
const answer = capability === 'events' ? await c.tool(`${c.surface.seed}.events.list`, { limit: 1 })
|
|
34
|
+
: capability === 'resources' ? await c.mcp('resources/read', { uri: `${c.surface.seed}://undeclared/${crypto.randomUUID()}` })
|
|
35
|
+
: capability === 'prompts' ? await c.mcp('prompts/get', { name: 'undeclared' })
|
|
36
|
+
: await c.mcp('subscriptions/listen', { notifications: { toolsListChanged: true } });
|
|
37
|
+
c.add(`BASE-AGENT-subset.refused.${capability}`, errorCode(answer) === 'capability_not_declared' && (answer.result?._meta?.['com.runeditrun/error']?.capability ?? answer.body?.error?.data?.capability) === capability && !answer.result?.structuredContent && !answer.result?.contents, `${capability} must return typed capability_not_declared with no content.`);
|
|
38
|
+
}
|
|
39
|
+
c.add('BASE-AGENT-subset.refusal-no-effect', isDeepStrictEqual(witness, await c.witness()), 'Undeclared capability calls changed native state.');
|
|
40
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { offers, capabilitySet } from '../capabilities.mjs';
|
|
2
|
+
import { scopedSurface } from './subset.mjs';
|
|
1
3
|
import { recordOnlyAuthority } from './authority.mjs';
|
|
2
4
|
import { narrowingContract, narrowingTargets } from './narrowing.mjs';
|
|
3
5
|
import { validToolName } from './tool-name.mjs';
|
|
@@ -9,6 +11,9 @@ const text = value => typeof value === 'string' && value.trim().length > 0;
|
|
|
9
11
|
|
|
10
12
|
/** Validate the edition's static declaration without loading application code. */
|
|
11
13
|
export function validateAgentSurface(surface, { contract } = {}) {
|
|
14
|
+
let set;
|
|
15
|
+
try { set = capabilitySet(surface?.capabilities); surface = scopedSurface(surface); }
|
|
16
|
+
catch (error) { return { ok: false, points: [{ id: 'BASE-AGENT-subset.declaration', ok: false, detail: error.message }] }; }
|
|
12
17
|
const points = [], add = (id, ok, detail) => points.push({ id: `BASE-AGENT-013.surface.${id}`, ok: Boolean(ok), ...(!ok ? { detail } : {}) });
|
|
13
18
|
add('schema', object(surface) && surface.schema === 'rer-agent-surface/1', 'Agent surface must use schema rer-agent-surface/1.');
|
|
14
19
|
if (!object(surface)) return { ok: false, points };
|
|
@@ -85,7 +90,8 @@ export function validateAgentSurface(surface, { contract } = {}) {
|
|
|
85
90
|
}
|
|
86
91
|
for (const [name, tool] of tools) if (Array.isArray(tool?.classes) && tool.classes.some(cls => ['access', 'security'].includes(cls))) escalation(`${name}.coverage`, tool.authority === 'none' && recordOnlyAuthority(tool) || (tool.widens === false ? narrowingTools.has(name) : tool.sponsorEscalation === false || escalationTools.has(name)), `${name} has no ${tool.widens === false ? 'narrowing check' : 'sponsor escalation fixture'}.`);
|
|
87
92
|
for (const [name, tool] of tools) for (const cls of Array.isArray(tool?.classes) ? tool.classes : []) add(`${name}.coverage.${cls}`, coverage.get(name).has(cls), `${name} has no journey fixture for declared class ${cls}.`);
|
|
88
|
-
add('events', tools.has(`${surface.seed}.events.list`), `Declare built-in ${surface.seed}.events.list in the Agent surface.`);
|
|
93
|
+
if (offers(surface.capabilities, 'events')) add('events', tools.has(`${surface.seed}.events.list`), `Declare built-in ${surface.seed}.events.list in the Agent surface.`);
|
|
94
|
+
if (set.mode === 'declared' && offers(surface.capabilities, 'resources')) add('resources.offered', surface.resources.length > 0, 'Declared resources must offer at least one resource template.');
|
|
89
95
|
add('witness', object(surface.witness) && tools.get(surface.witness.tool)?.readOnly === true && object(surface.witness.args), 'witness must name a declared readOnly tool and arguments.');
|
|
90
96
|
checkReferences(surface.witness?.args, 'witness', new Set());
|
|
91
97
|
return { ok: points.every(point => point.ok), points };
|
|
@@ -27,6 +27,15 @@ Owner history and undo must include jobs from either authority.
|
|
|
27
27
|
`modules/import-kit/schema`, and sibling `./modules/d1-transport` with relative
|
|
28
28
|
paths intact; record copies using the
|
|
29
29
|
seed's existing Base provenance workflow. Never rename applied migrations.
|
|
30
|
+
Refresh the recorded kit copies together with `rer refresh-base`. For example,
|
|
31
|
+
`atomic-prefix.ts` and `budget.ts` must agree on the `batchExecutions` export.
|
|
32
|
+
Unadapted recorded dependencies advance together. If a dependency is marked
|
|
33
|
+
adapted or is unrecorded seed source, refresh preserves it and refuses before
|
|
34
|
+
writing when an incoming module needs an export it lacks. Use the printed
|
|
35
|
+
comparison command, merge the required exports while preserving seed edits,
|
|
36
|
+
and remove the comparison file. For a recorded adaptation, run the printed
|
|
37
|
+
`adapt-base` acknowledgement after the merge, then repeat refresh. Acknowledging
|
|
38
|
+
the old bytes alone does not resolve a missing export.
|
|
30
39
|
Apply these in new numbered seed migrations, in this order,
|
|
31
40
|
skipping any the seed already applied:
|
|
32
41
|
- the D1 kit schemas, in the order `initializeD1ImportStorage` in
|
|
@@ -481,14 +481,24 @@ is available. Current archives carry the complete schema inventory and restore
|
|
|
481
481
|
without any acknowledgment. Version 2 backups written by rer 0.2.79 or earlier
|
|
482
482
|
can lack `schemaObjects`. Ordinary import verifies such a backup without an
|
|
483
483
|
acknowledgment when its nonempty recorded migration history, resolved against the
|
|
484
|
-
destination's own applied files in order,
|
|
485
|
-
|
|
486
|
-
|
|
484
|
+
destination's own applied files in order, reproduces the archive's table
|
|
485
|
+
definitions. Replay reconstructs that recorded schema's complete identity,
|
|
486
|
+
including indexes, views and triggers, before the ordinary additive bridge checks
|
|
487
|
+
later migrations. A seed's explicit `acceptedSchemas` row upgrade remains
|
|
488
|
+
available for its declared archive identity. The complete applied replay must
|
|
489
|
+
also match the live destination. The archive's ledger, when present,
|
|
487
490
|
must agree with its recorded names, and available hashes must match. Missing
|
|
488
491
|
history, failed replay, table drift or a different complete destination identity
|
|
489
492
|
still refuses `schema_mismatch:legacy_schema` before staging. Source SQL is never
|
|
490
493
|
installed. This verified path records no `schemaUnverified` receipt.
|
|
491
494
|
|
|
495
|
+
Some later v2 writers carried `schemaObjects` but omitted indexes and triggers
|
|
496
|
+
attached to excluded tables. Their historical table/object projection must match
|
|
497
|
+
the recorded replay exactly before its complete identity can be used for bridge
|
|
498
|
+
placement. An excluded-table object absent from the destination's migration
|
|
499
|
+
replay still refuses before staging. Original archive bytes and digests remain
|
|
500
|
+
unchanged in both paths.
|
|
501
|
+
|
|
492
502
|
When that proof is unavailable, the owner can explicitly accept that its schema
|
|
493
503
|
objects are unverified:
|
|
494
504
|
|
|
@@ -70,9 +70,10 @@ async function placement(db,manifest,cat,replay,ledger,history,legacyRecovery,un
|
|
|
70
70
|
return {applied,earlier,replays,rebuilt};
|
|
71
71
|
}
|
|
72
72
|
// Old v2 writers recorded tables and applied migration names, but no behavioral
|
|
73
|
-
// object inventory
|
|
74
|
-
// the
|
|
75
|
-
//
|
|
73
|
+
// object inventory (later writers omitted objects attached to excluded tables).
|
|
74
|
+
// Verify the archive's historical projection and the complete live replay, then
|
|
75
|
+
// return the recorded schema's complete identity for ordinary bridge placement.
|
|
76
|
+
// Never guess an unrecorded prefix or install source SQL to fill missing evidence.
|
|
76
77
|
export async function verifiedLegacySchema(db,manifest,cat,migrations,history) {
|
|
77
78
|
if(!migrations)return false;
|
|
78
79
|
const replay=await migrations(),ledger=await destinationLedger(db)??[];
|
|
@@ -84,9 +85,9 @@ export async function verifiedLegacySchema(db,manifest,cat,migrations,history) {
|
|
|
84
85
|
if(!recorded.length || canonicalJson(applied)!==canonicalJson(replay.names)
|
|
85
86
|
|| !recorded.every((name,i)=>applied.indexOf(name)>(i?applied.indexOf(recorded[i-1]):-1)))return false;
|
|
86
87
|
if(archived && manifest.migrations && canonicalJson(matchMigrationLedger(archived,files,replay))!==canonicalJson(recorded))return false;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
if(await replay.schemaAfter(applied)!==cat.identity
|
|
89
|
+
|| await replay.schemaAfter(recorded,manifest.schemaObjects===undefined?{tablesOnly:true}:{legacyExcludedObjects:true})!==manifest.schema)return false;
|
|
90
|
+
return await replay.schemaAfter(recorded);
|
|
90
91
|
}catch{return false;} // Unknown history or a failed replay is not verification.
|
|
91
92
|
}
|
|
92
93
|
// An archive with the destination's schema identity can still predate later
|
|
@@ -31,13 +31,14 @@ export async function createImport(context,manifest,actor='direct',legacyRecover
|
|
|
31
31
|
const cat=await catalogue(db,config),upgrade=config.acceptedSchemas[original.schema];
|
|
32
32
|
const legacy=original.version===2 && manifest.schemaObjects===undefined;
|
|
33
33
|
// An explicit acknowledgment keeps its existing recovery semantics. Without
|
|
34
|
-
// it, legacy v2 needs positive replay evidence for
|
|
34
|
+
// it, legacy v2 needs positive replay evidence for its recorded schema and
|
|
35
|
+
// the complete destination. The ordinary bridge then checks later migrations.
|
|
35
36
|
const unverified=legacy && acknowledgeUnverifiedSchemaObjects===true;
|
|
36
37
|
const verifyingLegacy=legacy && !unverified && !legacyRecovery;
|
|
37
38
|
const history=()=>archivedHistory(original,ledgers,{allowOlderShape:unverified || verifyingLegacy});
|
|
38
|
-
const verified=verifyingLegacy && await verifiedLegacySchema(db,manifest,cat,context.migrations,history);
|
|
39
|
+
const verified=(verifyingLegacy || (!legacy && manifest.schema!==cat.identity)) && await verifiedLegacySchema(db,manifest,cat,context.migrations,history);
|
|
39
40
|
insist(!legacy || legacyRecovery || unverified || verified,'schema_mismatch:legacy_schema',409);
|
|
40
|
-
if(verified)manifest={...manifest,schema:
|
|
41
|
+
if(verified)manifest={...manifest,schema:verified};
|
|
41
42
|
if(unverified)for(const table of manifest.tables) {
|
|
42
43
|
const target=cat.tables.find(t=>t.name===table.name);
|
|
43
44
|
insist(target,'schema_mismatch:table:'+table.name,409);
|
package/package.json
CHANGED
|
@@ -61,6 +61,15 @@ bounded public coauthor address rule described in the command guide; a file name
|
|
|
61
61
|
masks only the accepted address for email inspection, leaving names, other
|
|
62
62
|
addresses and every other rule intact.
|
|
63
63
|
|
|
64
|
+
`lockfile_metadata.py` uses `lockfile_metadata.mjs` and the maintained vendored
|
|
65
|
+
YAML parser to identify dependency package contact and deprecation scalar spans
|
|
66
|
+
in pnpm, npm (lock versions 1–3) and Yarn Berry locks. A bounded Yarn v1 parser
|
|
67
|
+
handles its colon-free scalar members and grouped selectors. Only email
|
|
68
|
+
inspection masks these spans; JSON/YAML duplicates, aliases, tags, malformed
|
|
69
|
+
input and unrecognized shapes grant no exception. Comments and custom fields
|
|
70
|
+
retain their own locations, even beside an accepted value on a minified line.
|
|
71
|
+
Repository package metadata, including npm's empty package key, stays inspected.
|
|
72
|
+
|
|
64
73
|
`png_text.py` separates the fields of framed PNG `tEXt` and uncompressed `iTXt`
|
|
65
74
|
chunks before text hygiene inspection. Container length, type and CRC bytes
|
|
66
75
|
cannot extend a mailbox, and these explicit text fields do not use the binary
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Return only scalar value locations in dependency package contact metadata.
|
|
2
|
+
// Use the maintained YAML parser; no package installation or lockfile execution.
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { isMap, isScalar, isSeq, parseDocument, visit } from '../../edition-authoring/vendor/yaml/index.mjs';
|
|
5
|
+
|
|
6
|
+
const personFields = new Set(['name', 'email', 'url']);
|
|
7
|
+
const single = new Set(['author', 'maintainer']);
|
|
8
|
+
const multiple = new Set(['maintainers', 'contributors']);
|
|
9
|
+
const packageName = /^(?:@[^\s/@]+\/)?[^\s/@]+$/;
|
|
10
|
+
const selector = /^(?:@[^\s/@]+\/)?[^\s/@]+@[^\s]+$/;
|
|
11
|
+
const pnpmSelector = /^(?:\/?(?:@[^\s/@]+\/)?[^\s/@]+)(?:@|\/)[^\s]+$/;
|
|
12
|
+
const key = node => isScalar(node) && typeof node.value === 'string' ? node.value : null;
|
|
13
|
+
const field = (node, name) => isMap(node) ? node.items.find(pair => key(pair.key) === name)?.value : undefined;
|
|
14
|
+
const string = node => isScalar(node) && typeof node.value === 'string';
|
|
15
|
+
|
|
16
|
+
function metadata(node, spans) {
|
|
17
|
+
if (!isMap(node)) return;
|
|
18
|
+
const scalar = value => { if (string(value)) spans.push(value.range.slice(0, 2)); };
|
|
19
|
+
const person = value => {
|
|
20
|
+
if (string(value)) scalar(value);
|
|
21
|
+
else if (isMap(value) && value.items.every(pair => personFields.has(key(pair.key)) && string(pair.value))) {
|
|
22
|
+
for (const pair of value.items) scalar(pair.value);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
for (const pair of node.items) {
|
|
26
|
+
const name = key(pair.key), value = pair.value;
|
|
27
|
+
if (single.has(name)) person(value);
|
|
28
|
+
else if (multiple.has(name) && isSeq(value)) for (const entry of value.items) person(entry);
|
|
29
|
+
// npm's deprecation advisory is registry-supplied package metadata too.
|
|
30
|
+
else if (name === 'email' || name === 'deprecated') scalar(value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function structured(text, filename) {
|
|
35
|
+
if (filename === 'package-lock.json') JSON.parse(text);
|
|
36
|
+
const document = parseDocument(text, { uniqueKeys: true, strict: true });
|
|
37
|
+
if (document.errors.length || !isMap(document.contents)) return [];
|
|
38
|
+
let ambiguous = false;
|
|
39
|
+
visit(document, { Node(_, node) { if (node.tag || node.anchor || node.constructor.name === 'Alias') ambiguous = true; } });
|
|
40
|
+
if (ambiguous) return [];
|
|
41
|
+
const root = document.contents, spans = [];
|
|
42
|
+
if (filename === 'pnpm-lock.yaml') {
|
|
43
|
+
if (!/^(?:[1-9]\d*)(?:\.\d+)?$/.test(String(field(root, 'lockfileVersion')?.value ?? ''))) return [];
|
|
44
|
+
const packages = field(root, 'packages');
|
|
45
|
+
if (isMap(packages)) for (const pair of packages.items) {
|
|
46
|
+
if (pnpmSelector.test(key(pair.key) ?? '')) metadata(pair.value, spans);
|
|
47
|
+
}
|
|
48
|
+
} else if (filename === 'package-lock.json') {
|
|
49
|
+
const version = field(root, 'lockfileVersion')?.value;
|
|
50
|
+
if (![1, 2, 3].includes(version)) return [];
|
|
51
|
+
const packages = field(root, 'packages');
|
|
52
|
+
if (version >= 2 && isMap(packages)) for (const pair of packages.items) {
|
|
53
|
+
// The empty key is the repository's own package, never a dependency.
|
|
54
|
+
if (/(?:^|\/)node_modules\/(?:@[^/\s]+\/)?[^/\s]+$/.test(key(pair.key) ?? '') &&
|
|
55
|
+
string(field(pair.value, 'version'))) metadata(pair.value, spans);
|
|
56
|
+
}
|
|
57
|
+
const dependencies = node => {
|
|
58
|
+
if (!isMap(node)) return;
|
|
59
|
+
for (const pair of node.items) if (packageName.test(key(pair.key) ?? '') && isMap(pair.value)) {
|
|
60
|
+
if (string(field(pair.value, 'version'))) metadata(pair.value, spans);
|
|
61
|
+
dependencies(field(pair.value, 'dependencies'));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (version <= 2) dependencies(field(root, 'dependencies'));
|
|
65
|
+
} else {
|
|
66
|
+
if (!isMap(field(root, '__metadata')) || !field(field(root, '__metadata'), 'version')) return [];
|
|
67
|
+
for (const pair of root.items) {
|
|
68
|
+
if ((key(pair.key) ?? '').split(/,\s*/).every(name => selector.test(name))) metadata(pair.value, spans);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return spans;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function classic(text) {
|
|
75
|
+
// Yarn v1 is not YAML: scalar members omit the colon and selectors can be
|
|
76
|
+
// grouped. Parse its indentation and JSON-quoted strings before classifying.
|
|
77
|
+
if (!/^# yarn lockfile v1\r?$/m.test(text)) return [];
|
|
78
|
+
const spans = [], stack = [], records = [], selectors = new Set();
|
|
79
|
+
let offset = 0, current = null;
|
|
80
|
+
for (const line of text.split(/(?<=\n)/)) {
|
|
81
|
+
const raw = line.replace(/\r?\n$/, '');
|
|
82
|
+
const start = offset;
|
|
83
|
+
offset += line.length;
|
|
84
|
+
if (/^\s*(?:#.*)?$/.test(raw)) continue;
|
|
85
|
+
if (!raw.startsWith(' ')) {
|
|
86
|
+
const header = raw.match(/^((?:"(?:[^"\\]|\\.)*"|[^\s",]+)(?:,\s*(?:"(?:[^"\\]|\\.)*"|[^\s",]+))*):$/);
|
|
87
|
+
if (!header) return [];
|
|
88
|
+
const names = header[1].match(/"(?:[^"\\]|\\.)*"|[^\s,]+/g).map(value => value.startsWith('"') ? JSON.parse(value) : value);
|
|
89
|
+
if (!names.every(name => selector.test(name) && !selectors.has(name))) return [];
|
|
90
|
+
for (const name of names) selectors.add(name);
|
|
91
|
+
current = { items: [], keys: new Set() };
|
|
92
|
+
records.push(current);
|
|
93
|
+
stack.splice(0, stack.length, { indent: 0, node: current });
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!current) return [];
|
|
97
|
+
const member = raw.match(/^( +)("(?:[^"\\]|\\.)*"|[A-Za-z][A-Za-z0-9_-]*)(?::|[ \t]+((?:"(?:[^"\\]|\\.)*"|[^\s"#]+)))([ \t]*(?:#.*)?)$/);
|
|
98
|
+
if (!member) return [];
|
|
99
|
+
const indent = member[1].length;
|
|
100
|
+
while (stack.length && stack.at(-1).indent >= indent) stack.pop();
|
|
101
|
+
const parent = stack.at(-1);
|
|
102
|
+
if (!parent || indent !== parent.indent + 2) return [];
|
|
103
|
+
const name = member[2].startsWith('"') ? JSON.parse(member[2]) : member[2];
|
|
104
|
+
if (parent.node.keys.has(name)) return [];
|
|
105
|
+
parent.node.keys.add(name);
|
|
106
|
+
let value;
|
|
107
|
+
if (member[3] === undefined) {
|
|
108
|
+
value = { items: [], keys: new Set() };
|
|
109
|
+
stack.push({ indent, node: value });
|
|
110
|
+
} else {
|
|
111
|
+
const at = start + member[1].length + member[2].length + raw.slice(member[1].length + member[2].length).search(/\S/);
|
|
112
|
+
const decoded = member[3].startsWith('"') ? JSON.parse(member[3]) : member[3];
|
|
113
|
+
value = { value: decoded, range: [at, at + member[3].length] };
|
|
114
|
+
}
|
|
115
|
+
parent.node.items.push({ name, value });
|
|
116
|
+
}
|
|
117
|
+
// Only direct package metadata and documented person members qualify.
|
|
118
|
+
const person = value => {
|
|
119
|
+
if (typeof value.value === 'string') spans.push(value.range);
|
|
120
|
+
else if (value.items.every(pair => personFields.has(pair.name) && typeof pair.value.value === 'string')) {
|
|
121
|
+
for (const pair of value.items) spans.push(pair.value.range);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
for (const record of records) {
|
|
125
|
+
for (const pair of record.items) {
|
|
126
|
+
if (single.has(pair.name)) person(pair.value);
|
|
127
|
+
else if (['email', 'deprecated'].includes(pair.name) && typeof pair.value.value === 'string') spans.push(pair.value.range);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return spans;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const text = readFileSync(0, 'utf8');
|
|
135
|
+
const filename = process.argv[2];
|
|
136
|
+
const spans = filename === 'yarn.lock' && /^# yarn lockfile v1\r?$/m.test(text) ? classic(text) : structured(text, filename);
|
|
137
|
+
process.stdout.write(JSON.stringify(spans.map(([a, b]) => [Buffer.byteLength(text.slice(0, a)), Buffer.byteLength(text.slice(0, b))])));
|
|
138
|
+
} catch {
|
|
139
|
+
// Malformed/unsupported input grants no metadata exception.
|
|
140
|
+
process.stdout.write('[]');
|
|
141
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Exact dependency metadata scalar spans; parser failure keeps email findings."""
|
|
2
|
+
from functools import lru_cache
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import subprocess
|
|
6
|
+
|
|
7
|
+
PARSER = Path(__file__).with_suffix('.mjs')
|
|
8
|
+
LOCKFILES = {'pnpm-lock.yaml', 'package-lock.json', 'yarn.lock'}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@lru_cache(maxsize=32)
|
|
12
|
+
def without_package_contacts(data, filename):
|
|
13
|
+
if filename not in LOCKFILES:
|
|
14
|
+
return data
|
|
15
|
+
try:
|
|
16
|
+
data.decode('utf-8')
|
|
17
|
+
result = subprocess.run(['node', str(PARSER), filename], input=data, capture_output=True, timeout=10)
|
|
18
|
+
if result.returncode:
|
|
19
|
+
return data
|
|
20
|
+
spans = json.loads(result.stdout)
|
|
21
|
+
if any(not isinstance(a, int) or not isinstance(b, int) or not 0 <= a <= b <= len(data) for a, b in spans):
|
|
22
|
+
return data
|
|
23
|
+
except (OSError, ValueError, UnicodeError, subprocess.TimeoutExpired):
|
|
24
|
+
return data
|
|
25
|
+
output, offset = [], 0
|
|
26
|
+
for start, end in sorted(spans):
|
|
27
|
+
output.extend((data[offset:start], b' '))
|
|
28
|
+
offset = max(offset, end)
|
|
29
|
+
output.append(data[offset:])
|
|
30
|
+
return b''.join(output)
|
|
@@ -11,6 +11,7 @@ from trust_bundle import anchor_values
|
|
|
11
11
|
from png_text import text_chunks
|
|
12
12
|
from media import sample_spans
|
|
13
13
|
from c2pa import certificate_spans
|
|
14
|
+
from lockfile_metadata import without_package_contacts
|
|
14
15
|
URI_AUTHORITY = re.compile(r'''//(?P<authority>[^/?#\s<>"']+)''')
|
|
15
16
|
ACTION_REFERENCE = re.compile(r'''uses:\s*["']?[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+@[^\s"']+''')
|
|
16
17
|
SCHEME_CHARACTERS = frozenset('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+.-')
|
|
@@ -188,7 +189,8 @@ def inspect_text(data, path, config, *, commit_message=False, binary_content=Non
|
|
|
188
189
|
if any(pattern.search(text) for pattern in config['internalReferencePatterns']):
|
|
189
190
|
rules.add('hygiene.internal-reference')
|
|
190
191
|
if '@' in text:
|
|
191
|
-
|
|
192
|
+
email_data = without_public_coauthor_addresses(data) if commit_message else without_package_contacts(data, path.rsplit('/', 1)[-1])
|
|
193
|
+
email_text = decoded_text(email_data)
|
|
192
194
|
emails = private_emails(email_text, config)
|
|
193
195
|
bundle = config.get('trustBundles', {}).get(path)
|
|
194
196
|
if emails and not (bundle and certificate_metadata(data, bundle, emails, config)):
|