@runeditrun/rer 0.2.86 → 0.2.87
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-bindings.mjs +25 -0
- package/cli/agent-door.mjs +9 -13
- package/cli/agent-journey-fixtures.mjs +17 -0
- package/cli/agent-reviewers.mjs +1 -1
- package/cli/agent-rpc.mjs +23 -0
- package/cli/agent-sponsors.mjs +2 -2
- package/cli/agent-verifier.mjs +31 -0
- package/cli/deploy-variables.mjs +48 -17
- package/cli/export.mjs +1 -0
- package/cli/hosted-output.mjs +15 -2
- package/cli/managed-data.mjs +8 -4
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +1 -0
- package/cli/production-auth.mjs +1 -1
- package/cli/production-mail.mjs +11 -1
- package/cli/server-registry.mjs +2 -0
- package/edition-authoring/archive-source.mjs +7 -1
- package/edition-authoring/base-copies.mjs +17 -4
- package/edition-authoring/copy-namespaces.mjs +28 -0
- package/edition-authoring/files.mjs +2 -1
- package/edition-authoring/module-closure.mjs +56 -11
- package/edition-authoring/module-edges.mjs +13 -2
- package/foundation/runtime/contract-docs.mjs +5 -0
- package/global/CHANGELOG.md +58 -0
- package/modules/agent-door/conformance/audit-pages.mjs +11 -0
- package/modules/agent-door/conformance/audit-rows.mjs +20 -0
- package/modules/agent-door/conformance/audit.mjs +10 -13
- package/modules/agent-door/conformance/fixtures.mjs +41 -0
- package/modules/agent-door/conformance/index.mjs +4 -4
- package/modules/agent-door/conformance/injection.mjs +24 -0
- package/modules/agent-door/conformance/invocation.mjs +1 -0
- package/modules/agent-door/conformance/journey.mjs +19 -14
- package/modules/agent-door/conformance/narrowing.d.mts +1 -0
- package/modules/agent-door/conformance/narrowing.mjs +15 -7
- package/modules/agent-door/conformance/negative.mjs +1 -0
- package/modules/agent-door/conformance/network-modules.mjs +4 -4
- package/modules/agent-door/conformance/policy-phases.mjs +12 -4
- package/modules/agent-door/conformance/protocol.mjs +22 -14
- package/modules/agent-door/conformance/replay.mjs +7 -6
- package/modules/agent-door/conformance/security.mjs +3 -2
- package/modules/agent-door/conformance/step-hooks.mjs +4 -0
- package/modules/agent-door/conformance/surface.mjs +7 -4
- package/modules/agent-door/conformance/target.mjs +2 -1
- package/modules/agent-door/conformance/webhooks.mjs +2 -1
- package/modules/delivery-producer/mail.mjs +20 -0
- package/modules/portability/README.md +5 -2
- package/modules/portability/catalogue.mjs +12 -2
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
2
|
import { autonomousPolicy } from './crypto.mjs';
|
|
3
3
|
import { errorCode } from './protocol.mjs';
|
|
4
|
+
import { nativeStepHook } from './step-hooks.mjs';
|
|
4
5
|
|
|
5
6
|
export async function unsetPolicy(c, initial = false) {
|
|
6
7
|
const listed = await c.mcp('tools/list');
|
|
@@ -11,16 +12,18 @@ export async function unsetPolicy(c, initial = false) {
|
|
|
11
12
|
c.add('BASE-AGENT-004.6.sponsor', typeof sponsor?.id === 'string' && sponsor.id.length > 0, 'The native person agents inventory must identify the authenticated agent sponsor.');
|
|
12
13
|
if (!sponsor?.id) throw new Error('Cannot resolve native sponsor ID from the person agents door');
|
|
13
14
|
c.sponsor.id = sponsor.id;
|
|
15
|
+
await c.prepare('initial');
|
|
14
16
|
}
|
|
15
17
|
for (const step of c.surface.journey) {
|
|
16
18
|
// No prior result exists here; unresolved references cannot identify native
|
|
17
19
|
// records. Resolvable calls still retain their computed classification.
|
|
18
|
-
const answer = await c.
|
|
20
|
+
const answer = await c.stepTool(step, c.args(step, new Map(), { unresolved: true }));
|
|
19
21
|
c.add(`BASE-AGENT-007.2.${initial ? 'initial' : 'removed'}.${step.id}`, errorCode(answer) === 'policy_unset', `${step.tool} must refuse with policy_unset before setup.`);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
export async function removalPhase(c) {
|
|
23
25
|
await c.adopt(autonomousPolicy());
|
|
26
|
+
await c.prepare('removed');
|
|
24
27
|
const before = await c.witness();
|
|
25
28
|
await c.adopt(null);
|
|
26
29
|
await unsetPolicy(c);
|
|
@@ -31,30 +34,34 @@ export async function blockedPhases(c) {
|
|
|
31
34
|
const nonstandard = [...new Set(c.surface.tools.flatMap(tool => tool.classes))].filter(cls => cls !== 'standard');
|
|
32
35
|
for (const cls of nonstandard) {
|
|
33
36
|
await c.adopt(autonomousPolicy());
|
|
37
|
+
await c.prepare(`blocked:${cls}`);
|
|
34
38
|
const outputs = new Map();
|
|
35
39
|
for (const step of c.surface.journey) {
|
|
36
40
|
const args = c.args(step, outputs);
|
|
41
|
+
await nativeStepHook(c, 'beforeStep', `blocked:${cls}`, step, args, outputs);
|
|
37
42
|
if (step.expect.some(item => item.class === cls)) {
|
|
38
43
|
const policy = autonomousPolicy(); policy.rules.push({ id: `block-${cls}`, class: cls, do: 'blocked' });
|
|
39
44
|
await c.adopt(policy);
|
|
40
|
-
const before = await c.witness(), refused = await c.
|
|
45
|
+
const before = await c.witness(), refused = await c.stepTool(step, args), after = await c.witness();
|
|
41
46
|
c.add(`BASE-AGENT-007.1.blocked.${cls}.${step.id}`, errorCode(refused) === 'policy_blocked' && refused.decision?.disposition === 'blocked' && refused.decision.revision === c.revision && refused.decision.classes.some(item => item.class === cls && item.do === 'blocked'), `${step.tool} must be blocked by ${cls}.`);
|
|
42
47
|
c.add(`BASE-AGENT-007.1.blocked-no-effect.${cls}.${step.id}`, isDeepStrictEqual(before, after), `${step.tool} changed native state while ${cls} was blocked.`);
|
|
43
48
|
await c.adopt(autonomousPolicy());
|
|
44
49
|
}
|
|
45
|
-
const completed = await c.
|
|
50
|
+
const completed = await c.stepTool(step, args, await c.proof(step.tool, args, undefined, step.client));
|
|
46
51
|
if (completed.result?.isError || completed.result?.structuredContent === undefined) throw new Error(`Could not prepare ${step.id} for the ${cls} blocked variant (${errorCode(completed) ?? completed.status})`);
|
|
47
52
|
outputs.set(step.id, completed.result.structuredContent);
|
|
53
|
+
await nativeStepHook(c, 'afterStep', `blocked:${cls}`, step, args, outputs, completed.result.structuredContent);
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
export async function pausePhase(c) {
|
|
52
58
|
await c.adopt(autonomousPolicy());
|
|
59
|
+
await c.prepare('paused');
|
|
53
60
|
const before = await c.witness();
|
|
54
61
|
await c.adopt(autonomousPolicy(), { paused: true });
|
|
55
62
|
for (const tool of c.surface.tools) {
|
|
56
63
|
const step = c.surface.journey.find(item => item.tool === tool.name);
|
|
57
|
-
const paused = await c.
|
|
64
|
+
const paused = await c.stepTool(step, c.args(step, new Map(), { unresolved: true }));
|
|
58
65
|
c.add(`BASE-AGENT-011.6.pause.${tool.name}`, errorCode(paused) === 'agents_paused', `${tool.name} ran while Business Pause was set.`);
|
|
59
66
|
}
|
|
60
67
|
const state = await c.personJson('/agents/api/state');
|
|
@@ -65,6 +72,7 @@ export async function pausePhase(c) {
|
|
|
65
72
|
|
|
66
73
|
export async function consentRevocationPhase(c) {
|
|
67
74
|
await c.adopt(autonomousPolicy());
|
|
75
|
+
await c.prepare('consent');
|
|
68
76
|
const before = await c.witness();
|
|
69
77
|
await c.adopt(autonomousPolicy(), { revoked: { agents: [], consents: [c.consent] } });
|
|
70
78
|
const step = c.surface.journey[0];
|
|
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { isDeepStrictEqual } from 'node:util';
|
|
3
3
|
import { accessToken, policyEnvelope } from './crypto.mjs';
|
|
4
4
|
import { AGENT_CLASSES } from './surface.mjs';
|
|
5
|
+
import { phaseFixtures } from './fixtures.mjs';
|
|
5
6
|
|
|
6
7
|
export const VERSION = '2026-07-28';
|
|
7
8
|
export const DECISION = 'com.runeditrun/decision';
|
|
@@ -15,25 +16,28 @@ export function errorCode(answer) {
|
|
|
15
16
|
const error = answer.result?._meta?.[ERROR] ?? answer.message?.error?.data?._meta?.[ERROR] ?? answer.message?.error?.data ?? answer.message?.error;
|
|
16
17
|
return typeof error === 'string' ? error : error?.code ?? answer.body?.code ?? null;
|
|
17
18
|
}
|
|
18
|
-
export function resolveArgs(value, outputs, { unresolved = false, sponsor } = {}) {
|
|
19
|
-
if (Array.isArray(value)) return value.map(item => resolveArgs(item, outputs, { unresolved, sponsor }));
|
|
19
|
+
export function resolveArgs(value, outputs, { unresolved = false, sponsor, fixtures = {} } = {}) {
|
|
20
|
+
if (Array.isArray(value)) return value.map(item => resolveArgs(item, outputs, { unresolved, sponsor, fixtures }));
|
|
20
21
|
if (value && typeof value === 'object') {
|
|
21
22
|
if ('$sponsor' in value) {
|
|
22
23
|
const result = sponsor?.[value.$sponsor];
|
|
23
24
|
if (!['id', 'email'].includes(value.$sponsor) || typeof result !== 'string' || !result) throw new Error(`Sponsor reference ${value.$sponsor} is unavailable`);
|
|
24
25
|
return result;
|
|
25
26
|
}
|
|
26
|
-
if ('$from' in value) {
|
|
27
|
-
|
|
27
|
+
if ('$from' in value || '$fixture' in value) {
|
|
28
|
+
const key = value.$fixture ?? value.$from, values = '$fixture' in value ? new Map(Object.entries(fixtures)) : outputs;
|
|
29
|
+
if (!values.has(key)) {
|
|
30
|
+
if ('$fixture' in value && unresolved) return `unresolved-fixture-${key}`;
|
|
31
|
+
if ('$fixture' in value) throw new Error('A required native phase fixture is unavailable');
|
|
28
32
|
if (unresolved) return `unresolved-${value.$from}`;
|
|
29
33
|
throw new Error(`Reference ${value.$from} has no structuredContent in this phase`);
|
|
30
34
|
}
|
|
31
|
-
let result =
|
|
35
|
+
let result = values.get(key);
|
|
32
36
|
for (const part of value.pointer.split('/').slice(1)) result = result?.[part.replace(/~1/g, '/').replace(/~0/g, '~')];
|
|
33
|
-
if (result === undefined) throw new Error(
|
|
37
|
+
if (result === undefined) throw new Error('A journey reference is missing');
|
|
34
38
|
return structuredClone(result);
|
|
35
39
|
}
|
|
36
|
-
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, resolveArgs(item, outputs, { unresolved, sponsor })]));
|
|
40
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, resolveArgs(item, outputs, { unresolved, sponsor, fixtures })]));
|
|
37
41
|
}
|
|
38
42
|
return value;
|
|
39
43
|
}
|
|
@@ -78,12 +82,15 @@ export function createProtocol(context) {
|
|
|
78
82
|
const response = await context.personRequest(`${path}/${action}`, { method: 'POST', body: JSON.stringify({ revision: approval.revision, summary_sha256: approval.summary_sha256 }) });
|
|
79
83
|
const body = await responseBody(response);
|
|
80
84
|
if (response.ok && action === 'approve' && body.approval?.state === 'executed') context.calls.push({
|
|
81
|
-
kind: 'approval/execute', name: approval.tool, decision: structuredClone(pending.decision), approvalId: handle.id,
|
|
85
|
+
kind: 'approval/execute', name: approval.tool, decision: structuredClone(pending.decision), approvalId: handle.id, principal: pending.principal,
|
|
82
86
|
});
|
|
83
87
|
return { ok: response.ok, status: response.status, body };
|
|
84
88
|
};
|
|
85
89
|
context.mcp = async (method, params = {}, options = {}) => {
|
|
86
|
-
const
|
|
90
|
+
const client = options.client === undefined ? undefined : context.clients.get(options.client);
|
|
91
|
+
if (options.client !== undefined && !client) throw new Error('A required native client fixture is unavailable');
|
|
92
|
+
const { token = client?.token ?? await accessToken(context), version = VERSION, headers = {}, track = true } = options;
|
|
93
|
+
const principal = client && options.token === undefined ? { agent: client.agent, clientId: client.clientId, consent: null, sponsor: context.sponsor.id } : undefined;
|
|
87
94
|
const id = ++requestId, name = method === 'resources/read' ? params.uri : params.name;
|
|
88
95
|
const response = await context.request('/mcp', { method: 'POST', headers: {
|
|
89
96
|
Accept: 'application/json, text/event-stream', 'Content-Type': 'application/json', Origin: context.origin,
|
|
@@ -92,21 +99,21 @@ export function createProtocol(context) {
|
|
|
92
99
|
...(token ? { Authorization: `Bearer ${token}` } : {}), ...headers,
|
|
93
100
|
}, body: JSON.stringify({ jsonrpc: '2.0', id, method, params: version === '2025-11-25' ? params : { ...params, _meta: { 'io.modelcontextprotocol/protocolVersion': version, 'io.modelcontextprotocol/clientCapabilities': { elicitation: { url: {} } }, 'io.modelcontextprotocol/clientInfo': { name: 'rer-agent-conformance', version: '1' }, ...params._meta } } }) });
|
|
94
101
|
const body = await responseBody(response), result = body.result, decision = result?._meta?.[DECISION] ?? body.error?.data?._meta?.[DECISION];
|
|
95
|
-
const answer = { status: response.status, headers: response.headers, body, message: body, result, decision };
|
|
102
|
+
const answer = { status: response.status, headers: response.headers, body, message: body, result, decision, principal };
|
|
96
103
|
if (['tools/call', 'resources/read'].includes(method) && track && (response.status !== 401 || typeof body.error?.data?.code === 'string')) context.calls.push({
|
|
97
104
|
kind: method, name: method === 'resources/read' ? 'resources/read' : params.name,
|
|
98
105
|
args: structuredClone(method === 'resources/read' ? { uri: params.uri } : params.arguments ?? {}),
|
|
99
|
-
decision: structuredClone(decision ?? null), code: errorCode(answer), result: structuredClone(result),
|
|
106
|
+
decision: structuredClone(decision ?? null), code: errorCode(answer), result: structuredClone(result), principal,
|
|
100
107
|
approval: structuredClone(result?._meta?.[APPROVAL] ?? body.error?.data?.approval ?? null),
|
|
101
108
|
pending: result?.resultType === 'input_required' || method === 'resources/read' && errorCode(answer) === 'approval_required',
|
|
102
109
|
});
|
|
103
110
|
return answer;
|
|
104
111
|
};
|
|
105
|
-
context.proof = async (name, args, handoff) => {
|
|
112
|
+
context.proof = async (name, args, handoff, clientLabel) => {
|
|
106
113
|
const tool = context.surface.tools.find(tool => tool.name === name);
|
|
107
114
|
if (!tool?.proof) return {};
|
|
108
115
|
if (typeof context.prove !== 'function') throw new Error(`${name} requires the seed-declared verification.proof module`);
|
|
109
|
-
const reference = await context.prove({ tool: name, args, kind: tool.proofKind, handoff, origin: context.origin, agentId: context.agentId, request: (path, init) => {
|
|
116
|
+
const reference = await context.prove({ tool: name, args, kind: tool.proofKind, handoff, origin: context.origin, agentId: clientLabel === undefined ? context.agentId : context.clients.get(clientLabel)?.agent.id, request: (path, init) => {
|
|
110
117
|
const url = new URL(path, context.origin);
|
|
111
118
|
if (url.origin !== context.origin) throw new Error('Native proof test request must use the fresh installation origin');
|
|
112
119
|
return context.personRequest(url.href, init);
|
|
@@ -115,7 +122,7 @@ export function createProtocol(context) {
|
|
|
115
122
|
return { proofReference: reference };
|
|
116
123
|
};
|
|
117
124
|
context.tool = (name, args, options) => context.mcp('tools/call', { name, arguments: args, ...(options?.proofReference ? { _meta: { 'com.runeditrun/native-proof': options.proofReference } } : {}), ...(options?.requestState === undefined ? {} : { requestState: options.requestState }) }, options);
|
|
118
|
-
context.resolve = (value, outputs = new Map(), options = {}) => resolveArgs(value, outputs, { ...options, sponsor: context.sponsor });
|
|
125
|
+
context.resolve = (value, outputs = new Map(), options = {}) => resolveArgs(value, outputs, { ...options, sponsor: context.sponsor, fixtures: context.fixtureValues });
|
|
119
126
|
context.args = (step, outputs, options) => {
|
|
120
127
|
const args = context.resolve(step.args, outputs, options);
|
|
121
128
|
if (!context.surface.tools.find(tool => tool.name === step.tool)?.readOnly) args.idempotency_key = randomUUID();
|
|
@@ -141,5 +148,6 @@ export function createProtocol(context) {
|
|
|
141
148
|
context.add(`BASE-AGENT-007.7.adopt.${context.seq}`, Object.keys(body).sort().join(',') === 'adopted,door' && isDeepStrictEqual(body.adopted, { seq: context.seq, revision: context.revision }) && validClasses, 'Policy answer must contain exactly adopted {seq,revision} and catalogue classes with the exact declared tool mappings; resource-only classes have no tools.');
|
|
142
149
|
return signed;
|
|
143
150
|
};
|
|
151
|
+
phaseFixtures(context, context.prepare);
|
|
144
152
|
return context;
|
|
145
153
|
}
|
|
@@ -6,30 +6,31 @@ import { errorCode } from './protocol.mjs';
|
|
|
6
6
|
export async function replayAdmissionPhase(c, declaration) {
|
|
7
7
|
if (!Array.isArray(declaration.prepare) || !declaration.prepare.length) throw new Error('replayAdmission.prepare must name preparation journey steps ending in a write.');
|
|
8
8
|
await c.adopt(autonomousPolicy());
|
|
9
|
+
await c.prepare('replay');
|
|
9
10
|
const outputs = new Map(); let call;
|
|
10
11
|
for (const id of declaration.prepare) {
|
|
11
12
|
const step = c.surface.journey.find(step => step.id === id);
|
|
12
13
|
if (!step) throw new Error('Unknown replay preparation step.');
|
|
13
|
-
const args = c.args(step, outputs), answer = await c.
|
|
14
|
+
const args = c.args(step, outputs), answer = await c.stepTool(step, args);
|
|
14
15
|
if (answer.result?.isError || answer.result?.structuredContent === undefined) throw new Error('Could not prepare a successful idempotent call.');
|
|
15
16
|
outputs.set(id, answer.result.structuredContent); call = { step, args, answer };
|
|
16
17
|
}
|
|
17
18
|
if (!call.args.idempotency_key) throw new Error('Replay admission must finish preparation with a mutating tool.');
|
|
18
|
-
const before = await c.witness(), repeated = await c.
|
|
19
|
+
const before = await c.witness(), repeated = await c.stepTool(call.step, call.args);
|
|
19
20
|
c.add('BASE-AGENT-012.replay.current', !repeated.result?.isError && isDeepStrictEqual(repeated.result?.structuredContent, call.answer.result.structuredContent) && isDeepStrictEqual(before, await c.witness()), 'An admitted replay must return the saved result without another native effect.');
|
|
20
21
|
await c.adopt(autonomousPolicy(), { paused: true });
|
|
21
|
-
const paused = await c.
|
|
22
|
+
const paused = await c.stepTool(call.step, call.args);
|
|
22
23
|
c.add('BASE-AGENT-012.replay.paused', errorCode(paused) === 'agents_paused' && paused.result?.structuredContent === undefined, 'A previously successful key must not expose cached content while agents are paused.');
|
|
23
24
|
const rows = await auditRows(c);
|
|
24
25
|
const row = rows.rows?.findLast(row => row.idempotency_key === call.args.idempotency_key);
|
|
25
|
-
c.add('BASE-AGENT-012.replay.audit', row?.code === 'agents_paused' && row.outcome === 'refused' && row.agent?.id === c.agentId && row.sponsor?.id === c.sponsor.id && row.tool === call.step.tool && row.decision === 'paused' && row.revision === c.revision && Number.isFinite(Date.parse(row.at)), 'The refused replay needs its own complete audit with current attribution and policy revision.');
|
|
26
|
+
c.add('BASE-AGENT-012.replay.audit', row?.code === 'agents_paused' && row.outcome === 'refused' && row.agent?.id === (call.answer.principal?.agent.id ?? c.agentId) && row.sponsor?.id === c.sponsor.id && row.tool === call.step.tool && row.decision === 'paused' && row.revision === c.revision && Number.isFinite(Date.parse(row.at)), 'The refused replay needs its own complete audit with current attribution and policy revision.');
|
|
26
27
|
const blocked = autonomousPolicy(); blocked.rules = [{ id: 'all', class: '*', do: 'blocked' }];
|
|
27
28
|
await c.adopt(blocked);
|
|
28
|
-
const refused = await c.
|
|
29
|
+
const refused = await c.stepTool(call.step, call.args);
|
|
29
30
|
c.add('BASE-AGENT-012.replay.policy', errorCode(refused) === 'policy_blocked' && refused.result?.structuredContent === undefined, 'Current per-tool policy must run before replay lookup.');
|
|
30
31
|
const held = autonomousPolicy(); held.rules = [{ id: 'all', class: '*', do: 'approval', approver: ['sponsor'], wait: 'PT1H' }];
|
|
31
32
|
await c.adopt(held);
|
|
32
|
-
const approval = await c.
|
|
33
|
+
const approval = await c.stepTool(call.step, call.args);
|
|
33
34
|
c.add('BASE-AGENT-012.replay.approval', errorCode(approval) === 'approval_required' && approval.result?.structuredContent === undefined, 'A newly required approval cannot be satisfied by an older autonomous result.');
|
|
34
35
|
await c.adopt(autonomousPolicy());
|
|
35
36
|
const missing = await c.tool(call.step.tool, call.args, { token: await accessToken(c, { scope: 'events:read' }) });
|
|
@@ -10,16 +10,17 @@ export async function recordSecurityPhase(c) {
|
|
|
10
10
|
const tools = c.surface.tools.filter(tool => tool.authority === 'none');
|
|
11
11
|
if (!tools.length) return;
|
|
12
12
|
await c.adopt(autonomousPolicy());
|
|
13
|
+
await c.prepare('no-subject');
|
|
13
14
|
const outputs = new Map();
|
|
14
15
|
for (const step of c.surface.journey) {
|
|
15
16
|
const prepared = c.args(step, outputs);
|
|
16
|
-
const answer = await c.
|
|
17
|
+
const answer = await c.stepTool(step, prepared, await c.proof(step.tool, prepared, undefined, step.client));
|
|
17
18
|
if (answer.result?.isError || answer.result?.structuredContent === undefined) throw new Error('Could not prepare no-subject security journey.');
|
|
18
19
|
outputs.set(step.id, answer.result.structuredContent);
|
|
19
20
|
if (!tools.some(tool => tool.name === step.tool)) continue;
|
|
20
21
|
const prefix = `BASE-AGENT-005.no-subject.${step.id}`;
|
|
21
22
|
const before = await c.witness(), args = { ...c.args(step, outputs), role: 'owner', scopes: ['*'], person_id: c.sponsor.id };
|
|
22
|
-
const refused = await c.
|
|
23
|
+
const refused = await c.stepTool(step, args);
|
|
23
24
|
c.add(`${prefix}.undeclared`, errorCode(refused) === 'undeclared_arguments' && refused.result?.structuredContent === undefined, 'A no-subject tool must refuse undeclared widening arguments.');
|
|
24
25
|
c.add(`${prefix}.unchanged`, isDeepStrictEqual(before, await c.witness()), 'An undeclared authority argument changed native state.');
|
|
25
26
|
const rows = await auditRows(c);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export async function nativeStepHook(c, stage, phase, step, args, outputs, result) {
|
|
2
|
+
if (!c.nativeStep) return;
|
|
3
|
+
await c.nativeStep({ stage, phase, step: structuredClone(step), args: structuredClone(args), outputs: structuredClone(Object.fromEntries(outputs)), ...(result === undefined ? {} : { result: structuredClone(result) }), tool: c.tool });
|
|
4
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { recordOnlyAuthority } from './authority.mjs';
|
|
2
|
-
import { narrowingContract } from './narrowing.mjs';
|
|
2
|
+
import { narrowingContract, narrowingTargets } from './narrowing.mjs';
|
|
3
3
|
import { validToolName } from './tool-name.mjs';
|
|
4
4
|
|
|
5
5
|
export const AGENT_CLASSES = Object.freeze(['standard', 'external', 'money', 'commitment', 'accounts', 'gated', 'access', 'security', 'destructive', 'sensitive', 'live']);
|
|
@@ -43,10 +43,11 @@ export function validateAgentSurface(surface, { contract } = {}) {
|
|
|
43
43
|
}
|
|
44
44
|
const references = (value, visit) => {
|
|
45
45
|
if (Array.isArray(value)) value.forEach(item => references(item, visit));
|
|
46
|
-
else if (object(value)) { if ('$from' in value || '$sponsor' in value) visit(value); else Object.values(value).forEach(item => references(item, visit)); }
|
|
46
|
+
else if (object(value)) { if ('$from' in value || '$sponsor' in value || '$fixture' in value) visit(value); else Object.values(value).forEach(item => references(item, visit)); }
|
|
47
47
|
};
|
|
48
48
|
const checkReferences = (value, label, available, addPoint = add) => references(value, ref => {
|
|
49
49
|
if ('$sponsor' in ref) addPoint(`${label}.sponsor`, Object.keys(ref).length === 1 && ['id', 'email'].includes(ref.$sponsor), `${label} must reference the sponsor as {$sponsor:'id'} or {$sponsor:'email'}.`);
|
|
50
|
+
else if ('$fixture' in ref) addPoint(`${label}.fixture`, text(surface.verification?.fixtures?.module) && text(ref.$fixture) && Object.keys(ref).sort().join(',') === '$fixture,pointer' && typeof ref.pointer === 'string' && (ref.pointer === '' || ref.pointer.startsWith('/')), `${label} requires verification.fixtures and a named fixture with a JSON pointer.`);
|
|
50
51
|
else addPoint(`${label}.ref.${ref.$from}`, available.has(ref.$from) && typeof ref.pointer === 'string' && (ref.pointer === '' || ref.pointer.startsWith('/')), `${label} references ${ref.$from} before its structuredContent is available, or has an invalid JSON pointer.`);
|
|
51
52
|
});
|
|
52
53
|
for (const [i, step] of (Array.isArray(surface.journey) ? surface.journey : []).entries()) {
|
|
@@ -54,11 +55,12 @@ export function validateAgentSurface(surface, { contract } = {}) {
|
|
|
54
55
|
add(`journey.${id}`, object(step) && text(step.id) && !steps.has(step.id) && Boolean(tool) && object(step.args) && Array.isArray(step.expect) && step.expect.length > 0, `Invalid or duplicate journey step ${id}, tool ${JSON.stringify(step?.tool)}.`);
|
|
55
56
|
const expect = Array.isArray(step?.expect) ? step.expect : [];
|
|
56
57
|
add(`journey.${id}.classes`, new Set(expect.map(item => item?.class)).size === expect.length && expect.every(item => object(item) && Array.isArray(tool?.classes) && tool.classes.includes(item.class) && (item.facts === undefined || object(item.facts))), `${id} expects duplicate, undeclared or malformed classes.`);
|
|
58
|
+
if (step?.client !== undefined) add(`journey.${id}.client`, text(step.client) && text(surface.verification?.fixtures?.module), `${id} requires a named native client and verification.fixtures.`);
|
|
57
59
|
for (const item of expect) coverage.get(step?.tool)?.add(item?.class);
|
|
58
60
|
checkReferences(step?.args, `journey.${id}`, steps);
|
|
59
61
|
if (step?.target !== undefined) {
|
|
60
62
|
const target = step.target;
|
|
61
|
-
add(`journey.${id}.target`, object(target) && Object.keys(target).sort().join(',') === 'id,kind' && text(target.kind) && (text(target.id) || object(target.id) && ('$from' in target.id || '$sponsor' in target.id)), `${id}.target must contain only a nonempty kind and an id string or journey reference.`);
|
|
63
|
+
add(`journey.${id}.target`, object(target) && Object.keys(target).sort().join(',') === 'id,kind' && text(target.kind) && (text(target.id) || object(target.id) && ('$from' in target.id || '$sponsor' in target.id || '$fixture' in target.id)), `${id}.target must contain only a nonempty kind and an id string or journey reference.`);
|
|
62
64
|
checkReferences(target, `journey.${id}.target`, steps);
|
|
63
65
|
}
|
|
64
66
|
if (step?.inject !== undefined) add(`journey.${id}.inject`, object(step.inject), `${id}.inject must be an object of additional arguments.`);
|
|
@@ -76,7 +78,8 @@ export function validateAgentSurface(surface, { contract } = {}) {
|
|
|
76
78
|
const narrowingTools = new Set();
|
|
77
79
|
for (const [i, fixture] of (Array.isArray(surface.narrowings) ? surface.narrowings : []).entries()) {
|
|
78
80
|
const tool = tools.get(fixture?.tool), witness = fixture?.witness;
|
|
79
|
-
|
|
81
|
+
const targets = narrowingTargets(tool);
|
|
82
|
+
escalation(`narrowing.${i}`, tool?.widens === false && !narrowingTools.has(fixture.tool) && steps.has(fixture.step) && surface.journey.some(step => step.id === fixture.step && step.tool === fixture.tool) && tools.get(witness?.tool)?.readOnly === true && object(witness?.args) && targets.length > 0 && targets.every(target => Object.hasOwn(witness.args, target)) && typeof witness?.pointer === 'string' && (witness.pointer === '' || witness.pointer.startsWith('/')), 'Narrowing fixture must name its journey step and a native grant-set witness with every target identifier.');
|
|
80
83
|
checkReferences(witness?.args, `narrowing.${i}.witness`, steps, escalation);
|
|
81
84
|
narrowingTools.add(fixture?.tool);
|
|
82
85
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { auditRows } from './audit-rows.mjs';
|
|
2
3
|
import { APPROVAL } from './protocol.mjs';
|
|
3
4
|
|
|
4
5
|
export const targetIdentity = value => value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
@@ -7,7 +8,7 @@ export const targetIdentity = value => value !== null && typeof value === 'objec
|
|
|
7
8
|
/** A journey expectation comes from native fixture state, never tool arguments alone. */
|
|
8
9
|
export async function checkTarget(c, step, outputs, answer, phase, execution = false) {
|
|
9
10
|
if (!step.target) return;
|
|
10
|
-
const expected = c.resolve(step.target, outputs), { rows } = await
|
|
11
|
+
const expected = c.resolve(step.target, outputs), { rows } = await auditRows(c);
|
|
11
12
|
const row = execution ? rows.findLast(row => row.decision_id === answer.decision?.id) : rows.find(row => row.id === answer.decision?.id);
|
|
12
13
|
c.add(`BASE-AGENT-009.target.${phase}.${step.id}${execution ? '.execution' : ''}`, targetIdentity(expected) && isDeepStrictEqual(row?.resource, expected), `${step.tool} must audit its resolved native kind and id: ${JSON.stringify(row?.resource)} != ${JSON.stringify(expected)}.`);
|
|
13
14
|
const approval = answer.result?._meta?.[APPROVAL];
|
|
@@ -3,11 +3,12 @@ import { autonomousPolicy } from './crypto.mjs';
|
|
|
3
3
|
|
|
4
4
|
export async function webhookPhase(c, webhooks) {
|
|
5
5
|
await c.adopt(autonomousPolicy());
|
|
6
|
+
await c.prepare('webhook');
|
|
6
7
|
const outputs = new Map();
|
|
7
8
|
for (const id of webhooks.prepare) {
|
|
8
9
|
const step = c.surface.journey.find(step => step.id === id);
|
|
9
10
|
if (!step) throw new Error('Webhook preparation must name existing journey steps.');
|
|
10
|
-
const answer = await c.
|
|
11
|
+
const answer = await c.stepTool(step, c.args(step, outputs));
|
|
11
12
|
if (answer.result?.isError || answer.result?.structuredContent === undefined) throw new Error('Could not prepare native webhook records.');
|
|
12
13
|
outputs.set(id, answer.result.structuredContent);
|
|
13
14
|
}
|
|
@@ -3,6 +3,25 @@ import {keys, strings} from './bindings.mjs';
|
|
|
3
3
|
const publicNames = ['MAIL_PROVIDER', 'MAIL_FROM', 'MAIL_RELAY_URL'];
|
|
4
4
|
const providerLabels = {rer: 'RER managed mail', resend: 'Resend', sendgrid: 'SendGrid', cloudflare: 'Cloudflare Email Sending'};
|
|
5
5
|
|
|
6
|
+
/** Empty defaults leave the single MAIL_FROM input unconfigured. Never choose between senders. */
|
|
7
|
+
export function validateMailSenders(sources) {
|
|
8
|
+
let sender;
|
|
9
|
+
for (const source of sources) {
|
|
10
|
+
if (typeof source.value !== 'string' || !source.value.trim()) continue;
|
|
11
|
+
if (sender && sender.value !== source.value) {
|
|
12
|
+
throw Object.assign(Error(`Conflicting MAIL_FROM senders: ${sender.source} (${JSON.stringify(sender.value)}) and ${source.source} (${JSON.stringify(source.value)}). Declare one sender consistently.`), {code:'mail_sender_conflict'});
|
|
13
|
+
}
|
|
14
|
+
sender = source;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The delivery policy owns classification; a deploy input may supply this same public binding. */
|
|
19
|
+
export function publicMailSender(spec) {
|
|
20
|
+
if (!usesManagedMail(spec.mail)) return false;
|
|
21
|
+
const names = spec.publicVariableNames ?? Object.keys(spec.publicVariables ?? {});
|
|
22
|
+
return names.includes('MAIL_FROM') && ![...(spec.secretNames ?? []), ...(spec.optionalSecretNames ?? [])].includes('MAIL_FROM');
|
|
23
|
+
}
|
|
24
|
+
|
|
6
25
|
/** Managed mail is an explicit capability, independent of direct provider adapters. */
|
|
7
26
|
export function usesManagedMail(mail) {
|
|
8
27
|
if (mail === undefined) return false;
|
|
@@ -35,6 +54,7 @@ export function generateMailSetupFields(mail) {
|
|
|
35
54
|
|
|
36
55
|
export function validateMailSpec(spec) {
|
|
37
56
|
if (!usesManagedMail(spec.mail)) return;
|
|
57
|
+
if (!publicMailSender(spec)) throw Error('Managed mail requires one public MAIL_FROM sender, not a secret MAIL_FROM');
|
|
38
58
|
for (const name of publicNames) {
|
|
39
59
|
if (!Object.hasOwn(spec.publicVariables, name)) throw Error(`Managed mail requires public ${name}`);
|
|
40
60
|
}
|
|
@@ -67,8 +67,11 @@ belong to the current runtime or environment and never travel:
|
|
|
67
67
|
| `rer_erasure_blobs`, `rer_erasure_guard`, `rer_erasure_scope`, `rer_erasure_rates` | Erasure work queues, transaction guards, working scope and local rate limits. |
|
|
68
68
|
| `rer_demo` | Local demo setup markers. |
|
|
69
69
|
|
|
70
|
-
`excludedTables` combines this list with the
|
|
71
|
-
|
|
70
|
+
`excludedTables` combines this list with `oa_%` and the exact Base owner-claim
|
|
71
|
+
identities `oc_owner_claims` and `oc_idp_grants`. Other `oc_` names must be
|
|
72
|
+
explicitly declared in `includeTables` or `excludeTables`; transfers refuse
|
|
73
|
+
`identity_table_undeclared:<name>` rather than silently dropping product rows.
|
|
74
|
+
Policy may override identity exclusions through `includeTables`,
|
|
72
75
|
but naming a mandatory platform table there refuses construction with
|
|
73
76
|
`platform_table:<name>` and a message identifying the table.
|
|
74
77
|
`excludedTable(name, policy)` always returns true for mandatory platform tables,
|
|
@@ -3,7 +3,7 @@ import { canonicalJson, base64, unbase64, utf8 } from './hash.mjs';
|
|
|
3
3
|
import { schemaIdentityOf } from './schema-identity.mjs';
|
|
4
4
|
import { platformTables, platformTable, identifier, matches } from './bookkeeping.mjs';
|
|
5
5
|
/** Platform bookkeeping is mandatory; operator identity remains a seed choice. */
|
|
6
|
-
export const excludedTables=Object.freeze([...platformTables,'oa_%','
|
|
6
|
+
export const excludedTables=Object.freeze([...platformTables,'oa_%','oc_owner_claims','oc_idp_grants']);
|
|
7
7
|
const fields=['product','excludeTables','includeTables','derivedTables','secretColumns','exportRow','importSafety','importRow','replaceableTables','requiredConfiguration','validateStaged','acceptedSchemas','buckets','extraPayloads','partBytes'];
|
|
8
8
|
const name=value=>typeof value==='string' && value.length>0 && value.length<=512 && !/[\x00-\x1f]/.test(value);
|
|
9
9
|
const names=value=>Array.isArray(value) && value.every(name) && new Set(value).size===value.length;
|
|
@@ -51,7 +51,17 @@ export function policy(input) {
|
|
|
51
51
|
return {...result,excludeTables:[...excludedTables,...result.excludeTables]};
|
|
52
52
|
}
|
|
53
53
|
/** Platform tables are always excluded; explicit includes override only optional exclusions. */
|
|
54
|
-
export
|
|
54
|
+
export function excludedTable(table,input={}) {
|
|
55
|
+
if(platformTable(table))return true;
|
|
56
|
+
if((input.includeTables??[]).includes(table))return false;
|
|
57
|
+
if([...excludedTables,...(input.excludeTables??[])].some(pattern=>matches(table,pattern)))return true;
|
|
58
|
+
if(matches(table,'oc_%')) {
|
|
59
|
+
const error=new PortabilityError('identity_table_undeclared:'+table,409);
|
|
60
|
+
error.message='Table "'+table+'" shares the owner-claim prefix. Declare it in includeTables to transfer its rows or excludeTables to omit them.';
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
55
65
|
async function archived(db,config) {
|
|
56
66
|
const objects=await all(db,"SELECT name,sql,type,tbl_name FROM sqlite_master WHERE sql IS NOT NULL AND substr(lower(name),1,7) <> 'sqlite_' AND substr(lower(name),1,4) <> '_cf_' ORDER BY name");
|
|
57
67
|
const kinds=await all(db,'PRAGMA table_list');
|