@victframework/runtime 0.1.0
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/dist/agent-governance.d.ts +285 -0
- package/dist/agent-governance.js +438 -0
- package/dist/agent-governance.js.map +1 -0
- package/dist/agent-registry.d.ts +103 -0
- package/dist/agent-registry.js +758 -0
- package/dist/agent-registry.js.map +1 -0
- package/dist/agent-types.d.ts +433 -0
- package/dist/agent-types.js +480 -0
- package/dist/agent-types.js.map +1 -0
- package/dist/authority.d.ts +83 -0
- package/dist/authority.js +170 -0
- package/dist/authority.js.map +1 -0
- package/dist/boundary-conformance.d.ts +51 -0
- package/dist/boundary-conformance.js +364 -0
- package/dist/boundary-conformance.js.map +1 -0
- package/dist/control-conformance.d.ts +68 -0
- package/dist/control-conformance.js +1131 -0
- package/dist/control-conformance.js.map +1 -0
- package/dist/control-in-memory.d.ts +257 -0
- package/dist/control-in-memory.js +886 -0
- package/dist/control-in-memory.js.map +1 -0
- package/dist/control-types.d.ts +1017 -0
- package/dist/control-types.js +779 -0
- package/dist/control-types.js.map +1 -0
- package/dist/durable-run.d.ts +73 -0
- package/dist/durable-run.js +262 -0
- package/dist/durable-run.js.map +1 -0
- package/dist/effect-policy.d.ts +22 -0
- package/dist/effect-policy.js +45 -0
- package/dist/effect-policy.js.map +1 -0
- package/dist/errors.d.ts +36 -0
- package/dist/errors.js +71 -0
- package/dist/errors.js.map +1 -0
- package/dist/in-memory-stores.d.ts +16 -0
- package/dist/in-memory-stores.js +522 -0
- package/dist/in-memory-stores.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/operator-config.d.ts +141 -0
- package/dist/operator-config.js +289 -0
- package/dist/operator-config.js.map +1 -0
- package/dist/orchestration-activation.d.ts +116 -0
- package/dist/orchestration-activation.js +223 -0
- package/dist/orchestration-activation.js.map +1 -0
- package/dist/orchestration-canary-conformance.d.ts +10 -0
- package/dist/orchestration-canary-conformance.js +726 -0
- package/dist/orchestration-canary-conformance.js.map +1 -0
- package/dist/orchestration-commands.d.ts +47 -0
- package/dist/orchestration-commands.js +538 -0
- package/dist/orchestration-commands.js.map +1 -0
- package/dist/orchestration-conformance.d.ts +59 -0
- package/dist/orchestration-conformance.js +594 -0
- package/dist/orchestration-conformance.js.map +1 -0
- package/dist/orchestration-driver-types.d.ts +163 -0
- package/dist/orchestration-driver-types.js +21 -0
- package/dist/orchestration-driver-types.js.map +1 -0
- package/dist/orchestration-driver.d.ts +48 -0
- package/dist/orchestration-driver.js +1030 -0
- package/dist/orchestration-driver.js.map +1 -0
- package/dist/orchestration-in-memory.d.ts +18 -0
- package/dist/orchestration-in-memory.js +1313 -0
- package/dist/orchestration-in-memory.js.map +1 -0
- package/dist/orchestration-join-conformance.d.ts +20 -0
- package/dist/orchestration-join-conformance.js +542 -0
- package/dist/orchestration-join-conformance.js.map +1 -0
- package/dist/orchestration-plan.d.ts +52 -0
- package/dist/orchestration-plan.js +265 -0
- package/dist/orchestration-plan.js.map +1 -0
- package/dist/orchestration-race-conformance.d.ts +35 -0
- package/dist/orchestration-race-conformance.js +1265 -0
- package/dist/orchestration-race-conformance.js.map +1 -0
- package/dist/orchestration-remediation-conformance.d.ts +54 -0
- package/dist/orchestration-remediation-conformance.js +632 -0
- package/dist/orchestration-remediation-conformance.js.map +1 -0
- package/dist/orchestration-store-types.d.ts +568 -0
- package/dist/orchestration-store-types.js +2 -0
- package/dist/orchestration-store-types.js.map +1 -0
- package/dist/pack-conformance.d.ts +59 -0
- package/dist/pack-conformance.js +222 -0
- package/dist/pack-conformance.js.map +1 -0
- package/dist/pack-install.d.ts +44 -0
- package/dist/pack-install.js +126 -0
- package/dist/pack-install.js.map +1 -0
- package/dist/registry.d.ts +107 -0
- package/dist/registry.js +481 -0
- package/dist/registry.js.map +1 -0
- package/dist/runtime.d.ts +158 -0
- package/dist/runtime.js +1341 -0
- package/dist/runtime.js.map +1 -0
- package/dist/serialization.d.ts +26 -0
- package/dist/serialization.js +162 -0
- package/dist/serialization.js.map +1 -0
- package/dist/store-conformance.d.ts +45 -0
- package/dist/store-conformance.js +876 -0
- package/dist/store-conformance.js.map +1 -0
- package/dist/store-errors.d.ts +49 -0
- package/dist/store-errors.js +48 -0
- package/dist/store-errors.js.map +1 -0
- package/dist/store-types.d.ts +331 -0
- package/dist/store-types.js +14 -0
- package/dist/store-types.js.map +1 -0
- package/dist/store-validation.d.ts +63 -0
- package/dist/store-validation.js +164 -0
- package/dist/store-validation.js.map +1 -0
- package/dist/stream-hub.d.ts +151 -0
- package/dist/stream-hub.js +402 -0
- package/dist/stream-hub.js.map +1 -0
- package/dist/testing.d.ts +25 -0
- package/dist/testing.js +19 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +221 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { canonicalJson } from '@victframework/kernel';
|
|
3
|
+
/**
|
|
4
|
+
* Neutral product-agent runtime boundary (Stage 06A).
|
|
5
|
+
*
|
|
6
|
+
* This module defines the activation/turn/governance vocabulary of the
|
|
7
|
+
* ProductAgent boundary. It is deliberately the agent framework-free (AI-002): no the agent framework
|
|
8
|
+
* type, package name, chunk type, or error type may appear here. The
|
|
9
|
+
* the adapter-backed implementation lives in the optional adapter package
|
|
10
|
+
* adapter, which implements `ProductAgentPort` against these neutral types.
|
|
11
|
+
*
|
|
12
|
+
* Snapshot discipline (AI-004, amendment §6.4):
|
|
13
|
+
* - activation resolves and deep-captures EVERY revisioned profile
|
|
14
|
+
* component into an immutable VICT-owned snapshot;
|
|
15
|
+
* - required function references (helper-tool executes, processor
|
|
16
|
+
* transforms, guardrail checks) are bound by reference and are never
|
|
17
|
+
* hashed or serialized;
|
|
18
|
+
* - an in-flight turn receives ONLY the frozen snapshot — it cannot retain
|
|
19
|
+
* or consult a live mutable registry, agent, processor list, model
|
|
20
|
+
* profile, or tool map;
|
|
21
|
+
* - changed definitions apply only after explicit re-activation.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Versioned marker of the agent-activation identity schema.
|
|
25
|
+
*
|
|
26
|
+
* `@2` records the normative corrective change of the canonical activation
|
|
27
|
+
* manifest: it now covers the complete resolved executable activation —
|
|
28
|
+
* every artifact binding (including a declared structured-output contract)
|
|
29
|
+
* AND the adapter compatibility metadata (id, revision, and every pinned
|
|
30
|
+
* runtime package version). `@1` records cannot be accepted under `@2`
|
|
31
|
+
* because their stored manifest bytes cannot match the reconstructed
|
|
32
|
+
* activation; restoration fails closed instead of substituting.
|
|
33
|
+
*
|
|
34
|
+
* `@3` records the further normative boundary-remediation correction: the
|
|
35
|
+
* manifest now ALSO carries the RESOLVED identity of every referenced
|
|
36
|
+
* sub-agent profile (`subagents: [{id, revision, agentProfileVersion}]`,
|
|
37
|
+
* canonically sorted). A stored activation therefore pins not only WHICH
|
|
38
|
+
* sub-agent revision it referenced but WHAT that resolved child profile
|
|
39
|
+
* identity was at activation time; restoration under a changed child
|
|
40
|
+
* profile rejects the record instead of accepting a silently different
|
|
41
|
+
* resolved executable activation. `@2` records cannot be accepted under
|
|
42
|
+
* `@3` (their stored manifest bytes cannot match the reconstructed
|
|
43
|
+
* activation); restoration and persistence both fail closed.
|
|
44
|
+
*/
|
|
45
|
+
export const AGENT_ACTIVATION_IDENTITY_SCHEMA = 'vict.agent-activation@3';
|
|
46
|
+
/** Versioned marker of persisted agent-activation records. */
|
|
47
|
+
export const AGENT_ACTIVATION_RECORD_SCHEMA = 'vict.agent-activation-record@1';
|
|
48
|
+
/**
|
|
49
|
+
* The closed field set of a persisted activation record. Any additional
|
|
50
|
+
* member — including a smuggled secret-bearing field — fails validation.
|
|
51
|
+
*/
|
|
52
|
+
const ACTIVATION_RECORD_FIELDS = new Set([
|
|
53
|
+
'recordSchema',
|
|
54
|
+
'activationVersion',
|
|
55
|
+
'agentProfileVersion',
|
|
56
|
+
'agentId',
|
|
57
|
+
'agentRevision',
|
|
58
|
+
'canonicalManifest',
|
|
59
|
+
'artifacts',
|
|
60
|
+
'createdAt',
|
|
61
|
+
]);
|
|
62
|
+
const ACTIVATION_ARTIFACT_ENTRY_FIELDS = new Set(['kind', 'id', 'revision']);
|
|
63
|
+
/** The closed field set of the canonical activation manifest (identity @3). */
|
|
64
|
+
const ACTIVATION_MANIFEST_FIELDS = new Set([
|
|
65
|
+
'schema',
|
|
66
|
+
'agentProfileVersion',
|
|
67
|
+
'adapter',
|
|
68
|
+
'artifacts',
|
|
69
|
+
'subagents',
|
|
70
|
+
]);
|
|
71
|
+
/** The closed field set of the manifest adapter-compatibility entry. */
|
|
72
|
+
const ACTIVATION_MANIFEST_ADAPTER_FIELDS = new Set([
|
|
73
|
+
'id',
|
|
74
|
+
'revision',
|
|
75
|
+
'runtimePackages',
|
|
76
|
+
]);
|
|
77
|
+
/** The closed field set of one manifest subagent-identity entry. */
|
|
78
|
+
const ACTIVATION_MANIFEST_SUBAGENT_FIELDS = new Set([
|
|
79
|
+
'id',
|
|
80
|
+
'revision',
|
|
81
|
+
'agentProfileVersion',
|
|
82
|
+
]);
|
|
83
|
+
const VERSION_STRING_PATTERN = /^v1_[0-9a-f]{64}$/;
|
|
84
|
+
/** Canonical order of activation-manifest artifact entries (mirror of the registry order). */
|
|
85
|
+
function compareManifestArtifactEntries(a, b) {
|
|
86
|
+
if (a.kind !== b.kind) {
|
|
87
|
+
return a.kind < b.kind ? -1 : 1;
|
|
88
|
+
}
|
|
89
|
+
if (a.id !== b.id) {
|
|
90
|
+
return a.id < b.id ? -1 : 1;
|
|
91
|
+
}
|
|
92
|
+
if (a.revision === b.revision) {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
return a.revision < b.revision ? -1 : 1;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Validate a persisted activation record at the durable boundary (shared by
|
|
99
|
+
* restoration AND by every store adapter before persistence).
|
|
100
|
+
*
|
|
101
|
+
* STRUCTURAL validation: closed field sets, exact schema marker, canonical
|
|
102
|
+
* version forms, well-formed artifact entries with known kinds.
|
|
103
|
+
*
|
|
104
|
+
* CONTENT validation (the persistence-time gate): the canonical manifest is
|
|
105
|
+
* PARSED and validated against its closed schema; the manifest is recomputed
|
|
106
|
+
* into canonical form and compared byte-for-byte with the stored text; the
|
|
107
|
+
* activation identity is RECOMPUTED from the manifest bytes and cross-checked
|
|
108
|
+
* against the record's `activationVersion`; the manifest's profile version
|
|
109
|
+
* and artifact list are cross-checked against the record's own fields. A
|
|
110
|
+
* record with fabricated hashes, a fabricated or non-canonical manifest,
|
|
111
|
+
* contradictory identity fields, unknown manifest content, or hostile
|
|
112
|
+
* property access is rejected BEFORE storage — with stable, non-echoing
|
|
113
|
+
* diagnostics (no raw exceptions, no payload-derived text in reasons).
|
|
114
|
+
*
|
|
115
|
+
* This is structural/hash validation only: it does NOT resolve executable
|
|
116
|
+
* artifacts — that remains restoration's exclusive job (re-resolution plus
|
|
117
|
+
* byte-exact reconstruction comparison).
|
|
118
|
+
*/
|
|
119
|
+
export function validateAgentActivationRecord(record) {
|
|
120
|
+
try {
|
|
121
|
+
return validateActivationRecordShape(record);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Hostile getters/proxies must never escape as raw exceptions, and no
|
|
125
|
+
// payload-derived text ever reaches the diagnostic.
|
|
126
|
+
return {
|
|
127
|
+
ok: false,
|
|
128
|
+
reason: 'The activation record could not be validated safely; hostile input is rejected.',
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function validateActivationRecordShape(record) {
|
|
133
|
+
if (typeof record !== 'object' || record === null || Array.isArray(record)) {
|
|
134
|
+
return { ok: false, reason: 'The activation record must be a plain object.' };
|
|
135
|
+
}
|
|
136
|
+
const candidate = record;
|
|
137
|
+
for (const key of Object.keys(candidate)) {
|
|
138
|
+
if (!ACTIVATION_RECORD_FIELDS.has(key)) {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
reason: 'The activation record declares unknown fields; the record schema is closed.',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (candidate.recordSchema !== 'vict.agent-activation-record@1') {
|
|
146
|
+
return { ok: false, reason: 'The activation record schema marker is not recognized.' };
|
|
147
|
+
}
|
|
148
|
+
for (const key of ['activationVersion', 'agentProfileVersion']) {
|
|
149
|
+
const value = candidate[key];
|
|
150
|
+
if (typeof value !== 'string' || !VERSION_STRING_PATTERN.test(value)) {
|
|
151
|
+
return {
|
|
152
|
+
ok: false,
|
|
153
|
+
reason: `The activation record '${key}' is not a canonical version string.`,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (const key of ['agentId', 'agentRevision']) {
|
|
158
|
+
const value = candidate[key];
|
|
159
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > 128) {
|
|
160
|
+
return { ok: false, reason: `The activation record '${key}' is missing or malformed.` };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (typeof candidate.canonicalManifest !== 'string' || candidate.canonicalManifest.length === 0) {
|
|
164
|
+
return { ok: false, reason: 'The activation record canonical manifest is missing.' };
|
|
165
|
+
}
|
|
166
|
+
if (typeof candidate.createdAt !== 'number' ||
|
|
167
|
+
!Number.isFinite(candidate.createdAt) ||
|
|
168
|
+
candidate.createdAt < 0) {
|
|
169
|
+
return {
|
|
170
|
+
ok: false,
|
|
171
|
+
reason: 'The activation record createdAt is not a finite epoch-ms number.',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (!Array.isArray(candidate.artifacts)) {
|
|
175
|
+
return { ok: false, reason: 'The activation record artifact list must be an array.' };
|
|
176
|
+
}
|
|
177
|
+
for (const entry of candidate.artifacts) {
|
|
178
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
179
|
+
return { ok: false, reason: 'The activation record artifact entries must be plain objects.' };
|
|
180
|
+
}
|
|
181
|
+
const artifact = entry;
|
|
182
|
+
for (const key of Object.keys(artifact)) {
|
|
183
|
+
if (!ACTIVATION_ARTIFACT_ENTRY_FIELDS.has(key)) {
|
|
184
|
+
return {
|
|
185
|
+
ok: false,
|
|
186
|
+
reason: 'The activation record artifact entry declares unknown fields.',
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (typeof artifact.kind !== 'string' || !VALID_RECORD_ARTIFACT_KINDS.has(artifact.kind)) {
|
|
191
|
+
return { ok: false, reason: 'The activation record artifact entry has an unknown kind.' };
|
|
192
|
+
}
|
|
193
|
+
for (const key of ['id', 'revision']) {
|
|
194
|
+
const value = artifact[key];
|
|
195
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > 128) {
|
|
196
|
+
return {
|
|
197
|
+
ok: false,
|
|
198
|
+
reason: `The activation record artifact entry '${key}' is missing or malformed.`,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return validateActivationManifestContent(candidate, candidate.canonicalManifest);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Content validation of the canonical manifest: closed schema, canonical
|
|
207
|
+
* bytes, recomputed identity, and record/manifest cross-checks. The input
|
|
208
|
+
* is plain parsed JSON (and the record's own validated fields), so no
|
|
209
|
+
* getter can run here; the caller's try/catch still bounds every access.
|
|
210
|
+
*/
|
|
211
|
+
function validateActivationManifestContent(candidate, manifestText) {
|
|
212
|
+
let parsed;
|
|
213
|
+
try {
|
|
214
|
+
parsed = JSON.parse(manifestText);
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return { ok: false, reason: 'The activation record canonical manifest is not valid JSON.' };
|
|
218
|
+
}
|
|
219
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
220
|
+
return {
|
|
221
|
+
ok: false,
|
|
222
|
+
reason: 'The activation record canonical manifest must be a JSON object.',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
const manifest = parsed;
|
|
226
|
+
for (const key of Object.keys(manifest)) {
|
|
227
|
+
if (!ACTIVATION_MANIFEST_FIELDS.has(key)) {
|
|
228
|
+
return {
|
|
229
|
+
ok: false,
|
|
230
|
+
reason: 'The activation manifest declares unknown fields; the manifest schema is closed.',
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (manifest.schema !== AGENT_ACTIVATION_IDENTITY_SCHEMA) {
|
|
235
|
+
return { ok: false, reason: 'The activation manifest schema marker is not recognized.' };
|
|
236
|
+
}
|
|
237
|
+
if (typeof manifest.agentProfileVersion !== 'string' ||
|
|
238
|
+
!VERSION_STRING_PATTERN.test(manifest.agentProfileVersion)) {
|
|
239
|
+
return {
|
|
240
|
+
ok: false,
|
|
241
|
+
reason: 'The activation manifest profile version is not a canonical version string.',
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
if (manifest.agentProfileVersion !== candidate.agentProfileVersion) {
|
|
245
|
+
return {
|
|
246
|
+
ok: false,
|
|
247
|
+
reason: 'The activation manifest profile version contradicts the record profile version.',
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const adapterValidation = validateManifestAdapterEntry(manifest.adapter);
|
|
251
|
+
if (!adapterValidation.ok) {
|
|
252
|
+
return adapterValidation;
|
|
253
|
+
}
|
|
254
|
+
const artifactsValidation = validateManifestArtifacts(manifest.artifacts, candidate.artifacts);
|
|
255
|
+
if (!artifactsValidation.ok) {
|
|
256
|
+
return artifactsValidation;
|
|
257
|
+
}
|
|
258
|
+
const subagentsValidation = validateManifestSubagents(manifest.subagents);
|
|
259
|
+
if (!subagentsValidation.ok) {
|
|
260
|
+
return subagentsValidation;
|
|
261
|
+
}
|
|
262
|
+
// Canonical bytes: the stored manifest text must be EXACTLY the canonical
|
|
263
|
+
// serialization of its own parsed content.
|
|
264
|
+
let reserialized;
|
|
265
|
+
try {
|
|
266
|
+
reserialized = canonicalJson(parsed);
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
return {
|
|
270
|
+
ok: false,
|
|
271
|
+
reason: 'The activation record canonical manifest is not canonical data.',
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (reserialized !== manifestText) {
|
|
275
|
+
return {
|
|
276
|
+
ok: false,
|
|
277
|
+
reason: 'The activation record canonical manifest is not in canonical form.',
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
// Identity recompute: the record version must be the canonical hash of
|
|
281
|
+
// the manifest bytes.
|
|
282
|
+
const recomputed = `v1_${createHash('sha256').update(manifestText, 'utf8').digest('hex')}`;
|
|
283
|
+
if (recomputed !== candidate.activationVersion) {
|
|
284
|
+
return {
|
|
285
|
+
ok: false,
|
|
286
|
+
reason: 'The activation record version does not match the recomputed activation identity.',
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return { ok: true };
|
|
290
|
+
}
|
|
291
|
+
function validateManifestAdapterEntry(adapter) {
|
|
292
|
+
if (typeof adapter !== 'object' || adapter === null || Array.isArray(adapter)) {
|
|
293
|
+
return {
|
|
294
|
+
ok: false,
|
|
295
|
+
reason: 'The activation manifest adapter entry must be a plain object.',
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
const adapterRecord = adapter;
|
|
299
|
+
for (const key of Object.keys(adapterRecord)) {
|
|
300
|
+
if (!ACTIVATION_MANIFEST_ADAPTER_FIELDS.has(key)) {
|
|
301
|
+
return {
|
|
302
|
+
ok: false,
|
|
303
|
+
reason: 'The activation manifest adapter entry declares unknown fields.',
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
for (const key of ['id', 'revision']) {
|
|
308
|
+
const value = adapterRecord[key];
|
|
309
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > 128) {
|
|
310
|
+
return {
|
|
311
|
+
ok: false,
|
|
312
|
+
reason: `The activation manifest adapter '${key}' is missing or malformed.`,
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const runtimePackages = adapterRecord.runtimePackages;
|
|
317
|
+
if (typeof runtimePackages !== 'object' ||
|
|
318
|
+
runtimePackages === null ||
|
|
319
|
+
Array.isArray(runtimePackages)) {
|
|
320
|
+
return {
|
|
321
|
+
ok: false,
|
|
322
|
+
reason: 'The activation manifest adapter runtime packages must be a plain object.',
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
for (const key of Object.keys(runtimePackages)) {
|
|
326
|
+
const value = runtimePackages[key];
|
|
327
|
+
if (key.length === 0 ||
|
|
328
|
+
key.length > 128 ||
|
|
329
|
+
typeof value !== 'string' ||
|
|
330
|
+
value.length === 0 ||
|
|
331
|
+
value.length > 128) {
|
|
332
|
+
return {
|
|
333
|
+
ok: false,
|
|
334
|
+
reason: 'The activation manifest adapter runtime package entries are malformed.',
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return { ok: true };
|
|
339
|
+
}
|
|
340
|
+
function validateManifestArtifacts(manifestArtifacts, recordArtifacts) {
|
|
341
|
+
if (!Array.isArray(manifestArtifacts)) {
|
|
342
|
+
return { ok: false, reason: 'The activation manifest artifact list must be an array.' };
|
|
343
|
+
}
|
|
344
|
+
if (!Array.isArray(recordArtifacts)) {
|
|
345
|
+
return { ok: false, reason: 'The activation record artifact list must be an array.' };
|
|
346
|
+
}
|
|
347
|
+
if (manifestArtifacts.length !== recordArtifacts.length) {
|
|
348
|
+
return {
|
|
349
|
+
ok: false,
|
|
350
|
+
reason: 'The activation manifest artifact list contradicts the record artifact list.',
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
for (let index = 0; index < manifestArtifacts.length; index += 1) {
|
|
354
|
+
const entry = manifestArtifacts[index];
|
|
355
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
356
|
+
return {
|
|
357
|
+
ok: false,
|
|
358
|
+
reason: 'The activation manifest artifact entries must be plain objects.',
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
const artifact = entry;
|
|
362
|
+
for (const key of Object.keys(artifact)) {
|
|
363
|
+
if (!ACTIVATION_ARTIFACT_ENTRY_FIELDS.has(key)) {
|
|
364
|
+
return {
|
|
365
|
+
ok: false,
|
|
366
|
+
reason: 'The activation manifest artifact entry declares unknown fields.',
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (typeof artifact.kind !== 'string' || !VALID_RECORD_ARTIFACT_KINDS.has(artifact.kind)) {
|
|
371
|
+
return { ok: false, reason: 'The activation manifest artifact entry has an unknown kind.' };
|
|
372
|
+
}
|
|
373
|
+
for (const key of ['id', 'revision']) {
|
|
374
|
+
const value = artifact[key];
|
|
375
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > 128) {
|
|
376
|
+
return {
|
|
377
|
+
ok: false,
|
|
378
|
+
reason: `The activation manifest artifact entry '${key}' is missing or malformed.`,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const recordEntry = recordArtifacts[index];
|
|
383
|
+
if (artifact.kind !== recordEntry.kind ||
|
|
384
|
+
artifact.id !== recordEntry.id ||
|
|
385
|
+
artifact.revision !== recordEntry.revision) {
|
|
386
|
+
return {
|
|
387
|
+
ok: false,
|
|
388
|
+
reason: 'The activation manifest artifact list contradicts the record artifact list.',
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
if (index > 0 &&
|
|
392
|
+
compareManifestArtifactEntries(manifestArtifacts[index - 1], artifact) > 0) {
|
|
393
|
+
return {
|
|
394
|
+
ok: false,
|
|
395
|
+
reason: 'The activation manifest artifact list is not in canonical order.',
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return { ok: true };
|
|
400
|
+
}
|
|
401
|
+
function validateManifestSubagents(subagents) {
|
|
402
|
+
// Resolved subagent identities: every referenced sub-agent's RESOLVED
|
|
403
|
+
// profile identity is part of the authoritative binding (closed fields,
|
|
404
|
+
// canonical versions, canonically sorted by id then revision).
|
|
405
|
+
if (!Array.isArray(subagents)) {
|
|
406
|
+
return { ok: false, reason: 'The activation manifest subagent list must be an array.' };
|
|
407
|
+
}
|
|
408
|
+
for (let index = 0; index < subagents.length; index += 1) {
|
|
409
|
+
const entry = subagents[index];
|
|
410
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
411
|
+
return {
|
|
412
|
+
ok: false,
|
|
413
|
+
reason: 'The activation manifest subagent entries must be plain objects.',
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
const subagent = entry;
|
|
417
|
+
for (const key of Object.keys(subagent)) {
|
|
418
|
+
if (!ACTIVATION_MANIFEST_SUBAGENT_FIELDS.has(key)) {
|
|
419
|
+
return {
|
|
420
|
+
ok: false,
|
|
421
|
+
reason: 'The activation manifest subagent entry declares unknown fields.',
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
for (const key of ['id', 'revision']) {
|
|
426
|
+
const value = subagent[key];
|
|
427
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > 128) {
|
|
428
|
+
return {
|
|
429
|
+
ok: false,
|
|
430
|
+
reason: `The activation manifest subagent entry '${key}' is missing or malformed.`,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (typeof subagent.agentProfileVersion !== 'string' ||
|
|
435
|
+
!VERSION_STRING_PATTERN.test(subagent.agentProfileVersion)) {
|
|
436
|
+
return {
|
|
437
|
+
ok: false,
|
|
438
|
+
reason: 'The activation manifest subagent resolved identity is not a canonical version string.',
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
if (index > 0 &&
|
|
442
|
+
compareManifestArtifactEntries(subagents[index - 1], subagent) > 0) {
|
|
443
|
+
return {
|
|
444
|
+
ok: false,
|
|
445
|
+
reason: 'The activation manifest subagent list is not in canonical order.',
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return { ok: true };
|
|
450
|
+
}
|
|
451
|
+
/** Artifact kinds that may appear inside a persisted activation record. */
|
|
452
|
+
const VALID_RECORD_ARTIFACT_KINDS = new Set([
|
|
453
|
+
'instructions',
|
|
454
|
+
'memory-policy',
|
|
455
|
+
'helper-tool',
|
|
456
|
+
'processor',
|
|
457
|
+
'guardrail',
|
|
458
|
+
'structured-output-contract',
|
|
459
|
+
'workflow',
|
|
460
|
+
'subagent',
|
|
461
|
+
'capability',
|
|
462
|
+
]);
|
|
463
|
+
/**
|
|
464
|
+
* Pin a ProductAgent port to one immutable activation snapshot. The runner
|
|
465
|
+
* captures the snapshot now: post-pin registry mutation or re-activation
|
|
466
|
+
* cannot affect turns it starts, and the port is refused when it is bound
|
|
467
|
+
* to a different profile identity (fail closed, never substitute).
|
|
468
|
+
*/
|
|
469
|
+
export function pinAgentTurnRunner(port, activation) {
|
|
470
|
+
if (port.agentProfileVersion !== activation.agentProfileVersion) {
|
|
471
|
+
throw new Error('VICT_AGENT_PORT_MISMATCH: the ProductAgent port is bound to a different agentProfileVersion than the pinned activation; refusing to substitute.');
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
activation,
|
|
475
|
+
runTurn(request, context = {}) {
|
|
476
|
+
return port.runTurn(request, { ...context, activation });
|
|
477
|
+
},
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
//# sourceMappingURL=agent-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-types.js","sourceRoot":"","sources":["../src/agent-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAKtD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,yBAAyB,CAAC;AAE1E,8DAA8D;AAC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O,EAAE,OAAO,GAAG,EAAE;YAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { CapabilityDefinition } from '@victframework/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Stage 04 least-authority boundary for capability packs.
|
|
4
|
+
*
|
|
5
|
+
* A capability NEVER receives a service locator, a store, a registry, or
|
|
6
|
+
* unrestricted mutation. It receives:
|
|
7
|
+
* - permission enforcement BEFORE invocation (declared grants must be
|
|
8
|
+
* explicitly granted to the runtime);
|
|
9
|
+
* - eager resolution of required configuration/secret names BEFORE
|
|
10
|
+
* invocation (a missing required value fails the invocation, never the
|
|
11
|
+
* handler);
|
|
12
|
+
* - SCOPED, name-checked readers for declared configuration/secret names.
|
|
13
|
+
* Undeclared names are unavailable: access throws a structured authority
|
|
14
|
+
* error instead of silently returning empty.
|
|
15
|
+
*
|
|
16
|
+
* Audit remediation (HIGH-04-C / LOW-04-H):
|
|
17
|
+
* - The gate closes over COPIED + FROZEN declaration snapshots, never the
|
|
18
|
+
* caller's arrays. Mutating a raw definition's `permissions` array after
|
|
19
|
+
* registration (or after activation) cannot change enforcement.
|
|
20
|
+
* - Every configuration/secret name is resolved AT MOST ONCE per
|
|
21
|
+
* invocation. Required names are resolved eagerly into the invocation's
|
|
22
|
+
* own cache; optional declared names resolve lazily once per name and
|
|
23
|
+
* are then cached for the REMAINDER OF THAT INVOCATION ONLY. The
|
|
24
|
+
* handler's scoped reader returns the SAME checked value — the check and
|
|
25
|
+
* the use are one consistent read.
|
|
26
|
+
* - The value caches and their resolver functions live INSIDE the
|
|
27
|
+
* per-invocation execution boundary (HIGH-04-D remediation): every
|
|
28
|
+
* invocation creates fresh private caches, so rotated configuration and
|
|
29
|
+
* secret values are re-read on the next invocation, a rejected provider
|
|
30
|
+
* promise can never poison a later invocation, and concurrent
|
|
31
|
+
* invocations never share cached values or promises.
|
|
32
|
+
* - Provider exceptions are converted into sanitized, stable authority
|
|
33
|
+
* failures; the provider's message never propagates.
|
|
34
|
+
* - Resolved values never enter events, traces, history, or activation
|
|
35
|
+
* identity (they never leave this gate except through the handler's
|
|
36
|
+
* scoped reader).
|
|
37
|
+
*/
|
|
38
|
+
/** Runtime port resolving declared configuration values. */
|
|
39
|
+
export interface ConfigurationPort {
|
|
40
|
+
get(name: string): unknown;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Runtime port resolving declared secret references just in time. Values
|
|
44
|
+
* never enter manifests, events, or retained history; they are handed only
|
|
45
|
+
* to the declaring capability through the scoped reader.
|
|
46
|
+
*/
|
|
47
|
+
export interface SecretResolutionPort {
|
|
48
|
+
get(name: string): Promise<string | undefined>;
|
|
49
|
+
}
|
|
50
|
+
/** The authority granted to one runtime. */
|
|
51
|
+
export interface CapabilityAuthority {
|
|
52
|
+
/** Explicitly granted permission ids. Absent means nothing is granted. */
|
|
53
|
+
readonly grants?: readonly string[];
|
|
54
|
+
readonly configuration?: ConfigurationPort;
|
|
55
|
+
readonly secrets?: SecretResolutionPort;
|
|
56
|
+
}
|
|
57
|
+
/** Immutable snapshot of the declared authority names of one capability. */
|
|
58
|
+
export interface PinnedAuthorityDeclarations {
|
|
59
|
+
readonly permissions: readonly string[];
|
|
60
|
+
readonly configuration: readonly string[];
|
|
61
|
+
readonly requiredConfiguration: readonly string[];
|
|
62
|
+
readonly secrets: readonly string[];
|
|
63
|
+
readonly requiredSecrets: readonly string[];
|
|
64
|
+
}
|
|
65
|
+
/** The authority-name fields of a capability definition, in declaration order. */
|
|
66
|
+
declare const AUTHORITY_FIELDS: readonly ["permissions", "configuration", "requiredConfiguration", "secrets", "requiredSecrets"];
|
|
67
|
+
export type AuthorityFieldName = (typeof AUTHORITY_FIELDS)[number];
|
|
68
|
+
/**
|
|
69
|
+
* Validate and PIN the authority declarations of a capability definition:
|
|
70
|
+
* every entry must be a non-empty, non-whitespace string; duplicates are
|
|
71
|
+
* rejected. Returns fresh frozen copies — the caller's arrays are never
|
|
72
|
+
* retained by reference.
|
|
73
|
+
*/
|
|
74
|
+
export declare function pinAuthorityDeclarations(definition: CapabilityDefinition): PinnedAuthorityDeclarations;
|
|
75
|
+
/**
|
|
76
|
+
* Wrap a capability's invoke with the least-authority gate. The WRAPPED
|
|
77
|
+
* invoke is what the registry stores and what activations capture, so the
|
|
78
|
+
* gate is enforced identically by the sequential and the durable engines.
|
|
79
|
+
* The gate closes over the PINNED declaration snapshot and the runtime's
|
|
80
|
+
* grants — never over the caller's definition object.
|
|
81
|
+
*/
|
|
82
|
+
export declare function gateCapabilityInvoke(definition: CapabilityDefinition, authority?: CapabilityAuthority): CapabilityDefinition['invoke'];
|
|
83
|
+
export {};
|