@inventarch/runtime 0.0.0-stage → 1.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/LANGUAGE.md +56 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +11 -2
- package/SPEC.md +77 -0
- package/dist/authoring/index.d.ts +159 -0
- package/dist/authoring/index.d.ts.map +1 -0
- package/dist/authoring/index.js +416 -0
- package/dist/authoring/index.js.map +1 -0
- package/dist/authoring-execution/execution.d.ts +12 -0
- package/dist/authoring-execution/execution.d.ts.map +1 -0
- package/dist/authoring-execution/execution.js +73 -0
- package/dist/authoring-execution/execution.js.map +1 -0
- package/dist/authoring-execution/index.d.ts +6 -0
- package/dist/authoring-execution/index.d.ts.map +1 -0
- package/dist/authoring-execution/index.js +6 -0
- package/dist/authoring-execution/index.js.map +1 -0
- package/dist/authoring-execution/inventory.d.ts +5 -0
- package/dist/authoring-execution/inventory.d.ts.map +1 -0
- package/dist/authoring-execution/inventory.js +46 -0
- package/dist/authoring-execution/inventory.js.map +1 -0
- package/dist/authoring-execution/shared.d.ts +22 -0
- package/dist/authoring-execution/shared.d.ts.map +1 -0
- package/dist/authoring-execution/shared.js +101 -0
- package/dist/authoring-execution/shared.js.map +1 -0
- package/dist/authoring-execution/types.d.ts +43 -0
- package/dist/authoring-execution/types.d.ts.map +1 -0
- package/dist/authoring-execution/types.js +21 -0
- package/dist/authoring-execution/types.js.map +1 -0
- package/dist/candidate.d.ts +49 -0
- package/dist/candidate.d.ts.map +1 -0
- package/dist/candidate.js +158 -0
- package/dist/candidate.js.map +1 -0
- package/dist/classify.d.ts +12 -0
- package/dist/classify.d.ts.map +1 -0
- package/dist/classify.js +21 -0
- package/dist/classify.js.map +1 -0
- package/dist/collect.d.ts +16 -0
- package/dist/collect.d.ts.map +1 -0
- package/dist/collect.js +133 -0
- package/dist/collect.js.map +1 -0
- package/dist/context.d.ts +5 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +124 -0
- package/dist/context.js.map +1 -0
- package/dist/coordinate.d.ts +21 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +40 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/door.d.ts +17 -0
- package/dist/door.d.ts.map +1 -0
- package/dist/door.js +217 -0
- package/dist/door.js.map +1 -0
- package/dist/editor/index.d.ts +5 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +4 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/types.d.ts +226 -0
- package/dist/editor/types.d.ts.map +1 -0
- package/dist/editor/types.js +2 -0
- package/dist/editor/types.js.map +1 -0
- package/dist/editor/workspace.d.ts +46 -0
- package/dist/editor/workspace.d.ts.map +1 -0
- package/dist/editor/workspace.js +903 -0
- package/dist/editor/workspace.js.map +1 -0
- package/dist/entry.d.ts +9 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +26 -0
- package/dist/entry.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/machine-protocol.d.ts +33 -0
- package/dist/machine-protocol.d.ts.map +1 -0
- package/dist/machine-protocol.js +339 -0
- package/dist/machine-protocol.js.map +1 -0
- package/dist/mentions.d.ts +20 -0
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +79 -0
- package/dist/mentions.js.map +1 -0
- package/dist/publication.d.ts +22 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/publication.js +275 -0
- package/dist/publication.js.map +1 -0
- package/dist/render.d.ts +9 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +78 -0
- package/dist/render.js.map +1 -0
- package/dist/select.d.ts +16 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +55 -0
- package/dist/select.js.map +1 -0
- package/dist/steward.d.ts +22 -0
- package/dist/steward.d.ts.map +1 -0
- package/dist/steward.js +45 -0
- package/dist/steward.js.map +1 -0
- package/dist/types.d.ts +97 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +162 -3
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { stableSerialize } from '@inventarch/graph';
|
|
3
|
+
export const AUTHORING_PROTOCOL = 1;
|
|
4
|
+
export const AUTHORING_LIMITS = Object.freeze({
|
|
5
|
+
contextFiles: 20,
|
|
6
|
+
contextBytes: 512 * 1024,
|
|
7
|
+
outputFiles: 10,
|
|
8
|
+
outputFileBytes: 256 * 1024,
|
|
9
|
+
outputBytes: 1024 * 1024,
|
|
10
|
+
});
|
|
11
|
+
export const CHAT_LIMITS = Object.freeze({
|
|
12
|
+
turns: 20,
|
|
13
|
+
messageBytes: 8192,
|
|
14
|
+
replyBytes: 16384,
|
|
15
|
+
historyBytes: 512 * 1024,
|
|
16
|
+
});
|
|
17
|
+
export class AuthoringError extends Error {
|
|
18
|
+
code;
|
|
19
|
+
status;
|
|
20
|
+
constructor(code, message, status = 400) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.status = status;
|
|
24
|
+
this.name = 'AuthoringError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export const digestText = (text) => createHash('sha256').update(text).digest('hex');
|
|
28
|
+
export const digestValue = (value) => digestText(stableSerialize(value));
|
|
29
|
+
export const manifestDigest = (context) => digestValue(context.map(({ path, digest }) => ({ path, digest })).sort((a, b) => a.path.localeCompare(b.path)));
|
|
30
|
+
export function sourcePath(path) {
|
|
31
|
+
return (path.startsWith('.ia/src/') &&
|
|
32
|
+
path.endsWith('.ia') &&
|
|
33
|
+
path
|
|
34
|
+
.split('/')
|
|
35
|
+
.every((part) => part !== '' &&
|
|
36
|
+
part !== '.' &&
|
|
37
|
+
part !== '..' &&
|
|
38
|
+
!/[\\\u0000-\u001f<>:"|?*]|[. ]$/.test(part) &&
|
|
39
|
+
!/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\.|$)/i.test(part)));
|
|
40
|
+
}
|
|
41
|
+
function object(value, keys) {
|
|
42
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
43
|
+
throw new AuthoringError('invalid-schema', 'Expected an object');
|
|
44
|
+
const result = value;
|
|
45
|
+
if (keys !== undefined && Object.keys(result).some((k) => !keys.includes(k)))
|
|
46
|
+
throw new AuthoringError('invalid-schema', 'Unexpected object field');
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
function text(value, max = 8192) {
|
|
50
|
+
if (typeof value !== 'string' ||
|
|
51
|
+
value.length === 0 ||
|
|
52
|
+
Buffer.byteLength(value) > max ||
|
|
53
|
+
Buffer.from(value).toString('utf8') !== value)
|
|
54
|
+
throw new AuthoringError('invalid-schema', 'Invalid text field');
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
function array(value, max) {
|
|
58
|
+
if (!Array.isArray(value) || value.length > max)
|
|
59
|
+
throw new AuthoringError('invalid-schema', 'Invalid or oversized array');
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
function sha(value) {
|
|
63
|
+
const result = text(value, 64);
|
|
64
|
+
if (!/^[a-f0-9]{64}$/.test(result))
|
|
65
|
+
throw new AuthoringError('invalid-digest', 'Expected SHA-256 hex digest');
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function word(value) {
|
|
69
|
+
const result = text(value, 100);
|
|
70
|
+
if (!/^[a-z][a-z0-9-]*$/.test(result))
|
|
71
|
+
throw new AuthoringError('invalid-schema', 'Expected a canonical IA word');
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
function path(value) {
|
|
75
|
+
const result = text(value, 500);
|
|
76
|
+
if (!sourcePath(result))
|
|
77
|
+
throw new AuthoringError('unsafe-path', 'Expected a canonical IA source path');
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
function uniquePaths(paths) {
|
|
81
|
+
if (new Set(paths.map((p) => p.toLowerCase())).size !== paths.length)
|
|
82
|
+
throw new AuthoringError('aliased-path', 'Duplicate or case-aliased paths are refused');
|
|
83
|
+
}
|
|
84
|
+
function disclosure(baseValue, contextValue) {
|
|
85
|
+
const base = object(baseValue, ['viewRevision', 'manifestDigest']);
|
|
86
|
+
const context = array(contextValue, AUTHORING_LIMITS.contextFiles).map((entry) => {
|
|
87
|
+
const item = object(entry, ['path', 'digest', 'text', 'citations']), content = text(item['text'], AUTHORING_LIMITS.contextBytes), digest = sha(item['digest']);
|
|
88
|
+
if (digestText(content) !== digest)
|
|
89
|
+
throw new AuthoringError('digest-mismatch', 'Context bytes do not match the disclosure digest');
|
|
90
|
+
return {
|
|
91
|
+
path: path(item['path']),
|
|
92
|
+
digest,
|
|
93
|
+
text: content,
|
|
94
|
+
citations: array(item['citations'], 100).map((c) => text(c, 500)),
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
uniquePaths(context.map((f) => f.path));
|
|
98
|
+
if (context.reduce((n, f) => n + Buffer.byteLength(f.text), 0) > AUTHORING_LIMITS.contextBytes)
|
|
99
|
+
throw new AuthoringError('context-too-large', 'Disclosed context exceeds 512 KiB');
|
|
100
|
+
const manifest = sha(base['manifestDigest']);
|
|
101
|
+
if (manifestDigest(context) !== manifest)
|
|
102
|
+
throw new AuthoringError('digest-mismatch', 'Context manifest does not match disclosed files');
|
|
103
|
+
return { base: { viewRevision: sha(base['viewRevision']), manifestDigest: manifest }, context };
|
|
104
|
+
}
|
|
105
|
+
export function parseAuthoringRequest(value) {
|
|
106
|
+
const input = object(value, [
|
|
107
|
+
'protocol',
|
|
108
|
+
'idempotencyKey',
|
|
109
|
+
'languageVersion',
|
|
110
|
+
'intent',
|
|
111
|
+
'target',
|
|
112
|
+
'expectedSteward',
|
|
113
|
+
'base',
|
|
114
|
+
'context',
|
|
115
|
+
]);
|
|
116
|
+
if (input['protocol'] !== 1 || input['languageVersion'] !== '1.0')
|
|
117
|
+
throw new AuthoringError('unsupported-protocol', 'Expected authoring protocol 1 and IA 1.0');
|
|
118
|
+
const target = object(input['target'], ['system', 'discriminator', 'paths']);
|
|
119
|
+
const system = word(target['system']), discriminator = word(target['discriminator']), paths = array(target['paths'], AUTHORING_LIMITS.outputFiles).map(path);
|
|
120
|
+
if (paths.length === 0 ||
|
|
121
|
+
paths.some((p) => !p.startsWith(`.ia/src/systems/${system}/`) ||
|
|
122
|
+
p.endsWith('/system.ia') ||
|
|
123
|
+
p.endsWith('/steward.ia') ||
|
|
124
|
+
p.includes('/schemas/')) ||
|
|
125
|
+
['system', 'schema'].includes(discriminator))
|
|
126
|
+
throw new AuthoringError('authority-change', 'Only new instances in the target system may be proposed');
|
|
127
|
+
uniquePaths(paths);
|
|
128
|
+
const expectedSteward = text(input['expectedSteward'], 300);
|
|
129
|
+
if (!/^[a-z][a-z0-9-]*\/binding\/agent\/[a-z][a-z0-9-]*$/.test(expectedSteward))
|
|
130
|
+
throw new AuthoringError('invalid-steward', 'Expected an admitted agent identity');
|
|
131
|
+
return {
|
|
132
|
+
protocol: 1,
|
|
133
|
+
languageVersion: '1.0',
|
|
134
|
+
idempotencyKey: text(input['idempotencyKey'], 100),
|
|
135
|
+
intent: text(input['intent']),
|
|
136
|
+
target: { system, discriminator, paths },
|
|
137
|
+
expectedSteward,
|
|
138
|
+
...disclosure(input['base'], input['context']),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function uuid(value) {
|
|
142
|
+
const result = text(value, 36);
|
|
143
|
+
if (!/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/.test(result))
|
|
144
|
+
throw new AuthoringError('invalid-id', 'Expected a UUID');
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
export function parseChatTurn(value) {
|
|
148
|
+
const v = object(value, [
|
|
149
|
+
'protocol',
|
|
150
|
+
'kind',
|
|
151
|
+
'languageVersion',
|
|
152
|
+
'idempotencyKey',
|
|
153
|
+
'conversationId',
|
|
154
|
+
'parentRunId',
|
|
155
|
+
'message',
|
|
156
|
+
'base',
|
|
157
|
+
'context',
|
|
158
|
+
]);
|
|
159
|
+
if (v['protocol'] !== 1 || v['kind'] !== 'chat' || v['languageVersion'] !== '1.0')
|
|
160
|
+
throw new AuthoringError('unsupported-protocol', 'Expected chat protocol 1 and IA 1.0');
|
|
161
|
+
const message = text(v['message'], CHAT_LIMITS.messageBytes);
|
|
162
|
+
if (!message.trim())
|
|
163
|
+
throw new AuthoringError('invalid-message', 'Enter a message');
|
|
164
|
+
return {
|
|
165
|
+
protocol: 1,
|
|
166
|
+
kind: 'chat',
|
|
167
|
+
languageVersion: '1.0',
|
|
168
|
+
idempotencyKey: text(v['idempotencyKey'], 100),
|
|
169
|
+
conversationId: uuid(v['conversationId']),
|
|
170
|
+
parentRunId: v['parentRunId'] === null ? null : uuid(v['parentRunId']),
|
|
171
|
+
message,
|
|
172
|
+
...disclosure(v['base'], v['context']),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export function parseChatReply(value, request, runId, expectedAgent) {
|
|
176
|
+
const v = object(value, ['protocol', 'conversationId', 'runId', 'requestDigest', 'agent', 'message', 'proposal']), agent = object(v['agent'], ['id', 'version']);
|
|
177
|
+
if (v['protocol'] !== 1 ||
|
|
178
|
+
v['conversationId'] !== request.conversationId ||
|
|
179
|
+
v['runId'] !== runId ||
|
|
180
|
+
v['requestDigest'] !== digestValue(request) ||
|
|
181
|
+
agent['id'] !== expectedAgent.id ||
|
|
182
|
+
agent['version'] !== expectedAgent.version)
|
|
183
|
+
throw new AuthoringError('attestation-mismatch', 'Chat reply does not match the authenticated conversation, turn or agent');
|
|
184
|
+
let proposal = null;
|
|
185
|
+
if (v['proposal'] !== null) {
|
|
186
|
+
const nested = object(v['proposal'], ['request', 'proposal']), targetRequest = parseAuthoringRequest(nested['request']);
|
|
187
|
+
if (targetRequest.intent !== request.message ||
|
|
188
|
+
targetRequest.idempotencyKey !== request.idempotencyKey ||
|
|
189
|
+
digestValue(targetRequest.base) !== digestValue(request.base) ||
|
|
190
|
+
digestValue(targetRequest.context) !== digestValue(request.context))
|
|
191
|
+
throw new AuthoringError('disclosure-mismatch', 'The agent cannot change the disclosed turn');
|
|
192
|
+
proposal = {
|
|
193
|
+
request: targetRequest,
|
|
194
|
+
proposal: parseAuthoringProposal(nested['proposal'], targetRequest, runId, expectedAgent),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
protocol: 1,
|
|
199
|
+
conversationId: request.conversationId,
|
|
200
|
+
runId,
|
|
201
|
+
requestDigest: digestValue(request),
|
|
202
|
+
agent: expectedAgent,
|
|
203
|
+
message: text(v['message'], CHAT_LIMITS.replyBytes),
|
|
204
|
+
proposal,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
export function parseConversation(value, id) {
|
|
208
|
+
const v = object(value, ['protocol', 'id', 'expiresAt', 'turns']);
|
|
209
|
+
if (v['protocol'] !== 1 ||
|
|
210
|
+
uuid(v['id']) !== id ||
|
|
211
|
+
typeof v['expiresAt'] !== 'string' ||
|
|
212
|
+
!Number.isFinite(Date.parse(v['expiresAt'])))
|
|
213
|
+
throw new AuthoringError('invalid-conversation', 'Conversation identity or expiry is invalid');
|
|
214
|
+
let parent = null;
|
|
215
|
+
const seen = new Set();
|
|
216
|
+
const turns = array(v['turns'], CHAT_LIMITS.turns).map((entry) => {
|
|
217
|
+
const row = object(entry, ['receipt', 'parentRunId', 'userMessage', 'assistantMessage', 'hasProposal']), receipt = parseReceipt(row['receipt']);
|
|
218
|
+
if (row['parentRunId'] !== parent ||
|
|
219
|
+
seen.has(receipt.runId) ||
|
|
220
|
+
typeof row['hasProposal'] !== 'boolean' ||
|
|
221
|
+
(receipt.state !== 'completed' && (row['assistantMessage'] !== null || row['hasProposal'])))
|
|
222
|
+
throw new AuthoringError('invalid-conversation', 'Conversation turns are out of order');
|
|
223
|
+
parent = receipt.runId;
|
|
224
|
+
seen.add(parent);
|
|
225
|
+
return {
|
|
226
|
+
receipt,
|
|
227
|
+
parentRunId: row['parentRunId'],
|
|
228
|
+
userMessage: text(row['userMessage'], CHAT_LIMITS.messageBytes),
|
|
229
|
+
assistantMessage: row['assistantMessage'] === null ? null : text(row['assistantMessage'], CHAT_LIMITS.replyBytes),
|
|
230
|
+
hasProposal: row['hasProposal'],
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
return { protocol: 1, id, expiresAt: v['expiresAt'], turns };
|
|
234
|
+
}
|
|
235
|
+
export function parseAuthoringProposal(value, request, runId, agent) {
|
|
236
|
+
const input = object(value, ['protocol', 'runId', 'requestDigest', 'agent', 'files', 'summary', 'citations']), attestation = object(input['agent'], ['id', 'version', 'steward']);
|
|
237
|
+
if (input['protocol'] !== 1 ||
|
|
238
|
+
input['runId'] !== runId ||
|
|
239
|
+
input['requestDigest'] !== digestValue(request) ||
|
|
240
|
+
attestation['id'] !== agent.id ||
|
|
241
|
+
attestation['version'] !== agent.version ||
|
|
242
|
+
attestation['steward'] !== request.expectedSteward)
|
|
243
|
+
throw new AuthoringError('attestation-mismatch', 'Proposal does not match the authenticated run, request or agent');
|
|
244
|
+
const files = array(input['files'], AUTHORING_LIMITS.outputFiles).map((entry) => {
|
|
245
|
+
const item = object(entry, ['path', 'operation', 'content', 'digest']), target = path(item['path']), content = text(item['content'], AUTHORING_LIMITS.outputFileBytes), digest = sha(item['digest']);
|
|
246
|
+
if (item['operation'] !== 'create' || !request.target.paths.includes(target) || digestText(content) !== digest)
|
|
247
|
+
throw new AuthoringError('proposal-mismatch', 'Only reviewed create-only targets with matching bytes are accepted');
|
|
248
|
+
return { path: target, operation: 'create', content, digest };
|
|
249
|
+
});
|
|
250
|
+
uniquePaths(files.map((f) => f.path));
|
|
251
|
+
if (files.length === 0 || files.reduce((n, f) => n + Buffer.byteLength(f.content), 0) > AUTHORING_LIMITS.outputBytes)
|
|
252
|
+
throw new AuthoringError('proposal-too-large', 'Empty or oversized proposal');
|
|
253
|
+
const citations = array(input['citations'], 200).map((entry) => {
|
|
254
|
+
const item = object(entry, ['path', 'digest', 'line', 'endLine']), target = path(item['path']), digest = sha(item['digest']), source = request.context.find((c) => c.path === target && c.digest === digest);
|
|
255
|
+
const line = item['line'], endLine = item['endLine'];
|
|
256
|
+
if (source === undefined ||
|
|
257
|
+
typeof line !== 'number' ||
|
|
258
|
+
typeof endLine !== 'number' ||
|
|
259
|
+
!Number.isInteger(line) ||
|
|
260
|
+
!Number.isInteger(endLine) ||
|
|
261
|
+
line < 1 ||
|
|
262
|
+
endLine < line ||
|
|
263
|
+
endLine > source.text.split('\n').length)
|
|
264
|
+
throw new AuthoringError('citation-invalid', 'Citations must address disclosed source bytes');
|
|
265
|
+
return { path: target, digest, line, endLine };
|
|
266
|
+
});
|
|
267
|
+
return {
|
|
268
|
+
protocol: 1,
|
|
269
|
+
runId,
|
|
270
|
+
requestDigest: digestValue(request),
|
|
271
|
+
agent: { ...agent, steward: request.expectedSteward },
|
|
272
|
+
files,
|
|
273
|
+
summary: text(input['summary']),
|
|
274
|
+
citations,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
export function parseCapabilities(value) {
|
|
278
|
+
const v = object(value), account = object(v['account']), agent = object(v['agent']), limits = object(v['limits']);
|
|
279
|
+
if (v['protocol'] !== 1 ||
|
|
280
|
+
!array(v['languageVersions'], 10).includes('1.0') ||
|
|
281
|
+
!['enabled', 'disabled'].includes(String(v['entitlement'])) ||
|
|
282
|
+
typeof v['authoringAvailable'] !== 'boolean' ||
|
|
283
|
+
typeof v['retentionDays'] !== 'number' ||
|
|
284
|
+
!Number.isInteger(v['retentionDays']) ||
|
|
285
|
+
v['retentionDays'] < 0)
|
|
286
|
+
throw new AuthoringError('capabilities-invalid', 'Service capability contract is incompatible');
|
|
287
|
+
for (const key of Object.keys(AUTHORING_LIMITS))
|
|
288
|
+
if (typeof limits[key] !== 'number' || !Number.isSafeInteger(limits[key]) || limits[key] <= 0)
|
|
289
|
+
throw new AuthoringError('capabilities-invalid', 'Invalid service limit');
|
|
290
|
+
return {
|
|
291
|
+
protocol: 1,
|
|
292
|
+
languageVersions: ['1.0'],
|
|
293
|
+
account: { id: text(account['id'], 200), label: text(account['label'], 320) },
|
|
294
|
+
agent: { id: text(agent['id'], 300), version: text(agent['version'], 100) },
|
|
295
|
+
entitlement: v['entitlement'],
|
|
296
|
+
authoringAvailable: v['authoringAvailable'],
|
|
297
|
+
retentionDays: v['retentionDays'],
|
|
298
|
+
limits: limits,
|
|
299
|
+
chatAvailable: v['chatAvailable'] === true,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
export function parseReceipt(value, expectedDigest) {
|
|
303
|
+
const v = object(value), usage = object(v['usage']);
|
|
304
|
+
const runId = text(v['runId'], 36), requestDigest = sha(v['requestDigest']);
|
|
305
|
+
if (!/^[a-f0-9-]{36}$/.test(runId) ||
|
|
306
|
+
(expectedDigest !== undefined && requestDigest !== expectedDigest) ||
|
|
307
|
+
!['queued', 'running', 'cancel-requested', 'completed', 'cancelled', 'failed'].includes(String(v['state'])) ||
|
|
308
|
+
!Number.isSafeInteger(v['cursor']) ||
|
|
309
|
+
v['cursor'] < 0 ||
|
|
310
|
+
!['reported', 'unknown'].includes(String(usage['state'])))
|
|
311
|
+
throw new AuthoringError('invalid-receipt', 'Service returned an incompatible run receipt');
|
|
312
|
+
for (const key of ['inputTokens', 'outputTokens'])
|
|
313
|
+
if (usage[key] !== null && (!Number.isSafeInteger(usage[key]) || usage[key] < 0))
|
|
314
|
+
throw new AuthoringError('invalid-receipt', 'Invalid usage');
|
|
315
|
+
const createdAt = text(v['createdAt'], 100), expiresAt = text(v['expiresAt'], 100);
|
|
316
|
+
if (!Number.isFinite(Date.parse(createdAt)) || !Number.isFinite(Date.parse(expiresAt)))
|
|
317
|
+
throw new AuthoringError('invalid-receipt', 'Invalid run dates');
|
|
318
|
+
return {
|
|
319
|
+
runId,
|
|
320
|
+
requestDigest,
|
|
321
|
+
state: v['state'],
|
|
322
|
+
cursor: v['cursor'],
|
|
323
|
+
createdAt,
|
|
324
|
+
expiresAt,
|
|
325
|
+
usage: {
|
|
326
|
+
inputTokens: usage['inputTokens'],
|
|
327
|
+
outputTokens: usage['outputTokens'],
|
|
328
|
+
state: usage['state'],
|
|
329
|
+
},
|
|
330
|
+
...(v['error'] === undefined ? {} : { error: text(v['error'], 8192) }),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
export function parseEvents(value, runId, digest, after) {
|
|
334
|
+
const v = object(value), receipt = parseReceipt(v['receipt'], digest);
|
|
335
|
+
if (receipt.runId !== runId)
|
|
336
|
+
throw new AuthoringError('invalid-events', 'Run ownership mismatch');
|
|
337
|
+
let cursor = after;
|
|
338
|
+
const events = array(v['events'], 100).map((entry) => {
|
|
339
|
+
const e = object(entry);
|
|
340
|
+
if (e['runId'] !== runId ||
|
|
341
|
+
e['sequence'] !== cursor + 1 ||
|
|
342
|
+
!['status', 'usage', 'completed', 'cancelled', 'failed'].includes(String(e['type'])) ||
|
|
343
|
+
!['queued', 'running', 'cancel-requested', 'completed', 'cancelled', 'failed'].includes(String(e['state'])))
|
|
344
|
+
throw new AuthoringError('invalid-events', 'Events must be ordered and bound to this run');
|
|
345
|
+
cursor++;
|
|
346
|
+
return {
|
|
347
|
+
runId,
|
|
348
|
+
sequence: cursor,
|
|
349
|
+
type: e['type'],
|
|
350
|
+
state: e['state'],
|
|
351
|
+
message: text(e['message']),
|
|
352
|
+
at: text(e['at'], 100),
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
if (cursor > receipt.cursor)
|
|
356
|
+
throw new AuthoringError('invalid-events', 'Receipt cursor precedes its events');
|
|
357
|
+
return { receipt, events };
|
|
358
|
+
}
|
|
359
|
+
export function serviceOrigin(value) {
|
|
360
|
+
const url = new URL(value);
|
|
361
|
+
if (url.username ||
|
|
362
|
+
url.password ||
|
|
363
|
+
url.search ||
|
|
364
|
+
url.hash ||
|
|
365
|
+
(url.protocol !== 'https:' &&
|
|
366
|
+
!(url.protocol === 'http:' && ['127.0.0.1', 'localhost', '[::1]'].includes(url.hostname))))
|
|
367
|
+
throw new AuthoringError('unsafe-origin', 'Service requires HTTPS or loopback development HTTP');
|
|
368
|
+
return url;
|
|
369
|
+
}
|
|
370
|
+
/** Bounded, non-redirecting transport. Access tokens remain in the host supplying this client. */
|
|
371
|
+
export async function serviceJson(base, route, init = {}) {
|
|
372
|
+
const origin = serviceOrigin(base), url = new URL(route, origin);
|
|
373
|
+
if (url.origin !== origin.origin)
|
|
374
|
+
throw new AuthoringError('unsafe-origin', 'Service request escaped its configured origin');
|
|
375
|
+
const headers = new Headers(init.headers);
|
|
376
|
+
if (!headers.has('accept'))
|
|
377
|
+
headers.set('accept', 'application/json');
|
|
378
|
+
const response = await fetch(url, {
|
|
379
|
+
...init,
|
|
380
|
+
redirect: 'error',
|
|
381
|
+
signal: init.signal ? AbortSignal.any([init.signal, AbortSignal.timeout(30000)]) : AbortSignal.timeout(30000),
|
|
382
|
+
headers,
|
|
383
|
+
});
|
|
384
|
+
const reader = response.body?.getReader();
|
|
385
|
+
let size = 0;
|
|
386
|
+
const parts = [];
|
|
387
|
+
if (reader !== undefined)
|
|
388
|
+
for (;;) {
|
|
389
|
+
const item = await reader.read();
|
|
390
|
+
if (item.done)
|
|
391
|
+
break;
|
|
392
|
+
size += item.value.byteLength;
|
|
393
|
+
if (size > 2 * 1024 * 1024) {
|
|
394
|
+
await reader.cancel();
|
|
395
|
+
throw new AuthoringError('response-too-large', 'Service response exceeded the client limit');
|
|
396
|
+
}
|
|
397
|
+
parts.push(item.value);
|
|
398
|
+
}
|
|
399
|
+
let value;
|
|
400
|
+
try {
|
|
401
|
+
value = JSON.parse(Buffer.concat(parts).toString('utf8'));
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
throw new AuthoringError('invalid-response', 'Service did not return JSON', response.status);
|
|
405
|
+
}
|
|
406
|
+
if (!response.ok) {
|
|
407
|
+
const error = object(value);
|
|
408
|
+
throw new AuthoringError(typeof error['code'] === 'string'
|
|
409
|
+
? error['code']
|
|
410
|
+
: typeof error['error'] === 'string'
|
|
411
|
+
? error['error']
|
|
412
|
+
: 'service-error', typeof error['message'] === 'string' ? error['message'].slice(0, 500) : `Service returned ${response.status}`, response.status);
|
|
413
|
+
}
|
|
414
|
+
return value;
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authoring/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAU,CAAC;AAC7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,YAAY,EAAE,EAAE;IAChB,YAAY,EAAE,GAAG,GAAG,IAAI;IACxB,WAAW,EAAE,EAAE;IACf,eAAe,EAAE,GAAG,GAAG,IAAI;IAC3B,WAAW,EAAE,IAAI,GAAG,IAAI;CACzB,CAAC,CAAC;AAsEH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACvC,KAAK,EAAE,EAAE;IACT,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,GAAG,GAAG,IAAI;CACzB,CAAC,CAAC;AAiCH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAE5B;IAEA;IAHX,YACW,IAAY,EACrB,OAAe,EACN,SAAS,GAAG;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAM;QAGr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zB,CAAC;IACH,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,cAAc,CAAC,kBAAkB,EAAE,6BAA6B,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,MAAM,IAAI,cAAc,CACtB,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ;YAC/B,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;YACf,CAAC,CAAC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,QAAQ;gBAClC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;gBAChB,CAAC,CAAC,eAAe,EACrB,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,oBAAoB,QAAQ,CAAC,MAAM,EAAE,EAC7G,QAAQ,CAAC,MAAM,CAChB,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Result, Context, Handler, Success } from './types.js';
|
|
2
|
+
/** Trusted implementation catalog, never decoded from operation input. */
|
|
3
|
+
export type ExecutionCatalog = Readonly<Record<string, {
|
|
4
|
+
owner: string;
|
|
5
|
+
handler: string;
|
|
6
|
+
effects: 'read-only' | 'draft-only';
|
|
7
|
+
run: Handler;
|
|
8
|
+
}>>;
|
|
9
|
+
export declare function executeOwned(context: Context, name: string, input: unknown, catalog: ExecutionCatalog): Success;
|
|
10
|
+
export declare function executeCatalog(root: string, name: string, input: unknown, catalog: ExecutionCatalog): Result;
|
|
11
|
+
export declare function refusal(error: unknown): Result;
|
|
12
|
+
//# sourceMappingURL=execution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/authoring-execution/execution.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGpE,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CACrC,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,GAAG,YAAY,CAAC;IAAC,GAAG,EAAE,OAAO,CAAA;CAAE,CAAC,CACtG,CAAC;AACF,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CA+C/G;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAc5G;AACD,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAS9C"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { evaluateSteward } from '../steward.js';
|
|
2
|
+
import { ExecutionError } from './types.js';
|
|
3
|
+
import { open } from '@inventarch/db';
|
|
4
|
+
import { field, id, portablePath, text } from './shared.js';
|
|
5
|
+
export function executeOwned(context, name, input, catalog) {
|
|
6
|
+
id(name);
|
|
7
|
+
const candidates = context.records.filter((r) => r.discriminator === 'operation' && r.name === name);
|
|
8
|
+
if (candidates.length !== 1)
|
|
9
|
+
throw new ExecutionError('IA-EXEC-OPERATION-UNAVAILABLE', `No unique admitted @operation ${name}`);
|
|
10
|
+
const operation = candidates[0], binding = Object.hasOwn(catalog, name) ? catalog[name] : undefined;
|
|
11
|
+
if (!binding ||
|
|
12
|
+
operation.identity !== `authoring-system/binding/operation/${name}` ||
|
|
13
|
+
operation.source.path !== `.ia/src/systems/${binding.owner}/operations/${name}.ia` ||
|
|
14
|
+
text(field(operation, 'execution', 'handler')) !== binding.handler ||
|
|
15
|
+
text(field(operation, 'execution', 'effects')) !== binding.effects ||
|
|
16
|
+
text(field(operation, 'execution', 'input')) !== 'json' ||
|
|
17
|
+
text(field(operation, 'execution', 'output')) !== 'operation-result')
|
|
18
|
+
throw new ExecutionError('IA-EXEC-BINDING-MISMATCH', `Native binding differs from the fixed implementation catalog: ${name}`);
|
|
19
|
+
const owner = evaluateSteward(context.records, binding.owner, { kind: 'operator' });
|
|
20
|
+
if (!owner.allowed || !owner.steward)
|
|
21
|
+
throw new ExecutionError('IA-EXEC-BINDING-MISMATCH', owner.message);
|
|
22
|
+
const baseRevision = context.db.revision, product = binding.run(context, input), seen = new Set();
|
|
23
|
+
for (const artifact of product.artifacts) {
|
|
24
|
+
const path = portablePath(artifact.path), key = path.toLowerCase();
|
|
25
|
+
if (seen.has(key))
|
|
26
|
+
throw new ExecutionError('IA-EXEC-OUTPUT-UNSAFE', `Artifact paths collide: ${path}`);
|
|
27
|
+
seen.add(key);
|
|
28
|
+
}
|
|
29
|
+
if (binding.effects === 'read-only' && product.artifacts.length)
|
|
30
|
+
throw new ExecutionError('IA-EXEC-BINDING-MISMATCH', 'Read-only handler returned draft effects');
|
|
31
|
+
if (context.db.refresh().revision !== baseRevision)
|
|
32
|
+
throw new ExecutionError('IA-EXEC-SOURCE-CHANGED', 'Native inputs changed during execution');
|
|
33
|
+
const candidateRevision = product.preview?.revision ?? product.candidateRevision;
|
|
34
|
+
return {
|
|
35
|
+
ok: true,
|
|
36
|
+
operation: operation.identity,
|
|
37
|
+
owner: binding.owner,
|
|
38
|
+
steward: owner.steward.identity,
|
|
39
|
+
baseRevision,
|
|
40
|
+
...(candidateRevision === undefined ? {} : { candidateRevision }),
|
|
41
|
+
effects: binding.effects,
|
|
42
|
+
artifacts: product.artifacts,
|
|
43
|
+
evidence: product.evidence,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function executeCatalog(root, name, input, catalog) {
|
|
47
|
+
try {
|
|
48
|
+
const db = open(root, { cache: false });
|
|
49
|
+
try {
|
|
50
|
+
const errors = db.report.findings.filter((f) => f.severity === 'error');
|
|
51
|
+
if (errors.length)
|
|
52
|
+
throw new ExecutionError('IA-EXEC-VALIDATION-FAILED', 'Base corpus has admission errors', errors);
|
|
53
|
+
return executeOwned({ db, records: db.records() }, name, input, catalog);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
db.close();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return refusal(error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function refusal(error) {
|
|
64
|
+
return error instanceof ExecutionError
|
|
65
|
+
? { ok: false, code: error.code, message: error.message, diagnostics: error.diagnostics }
|
|
66
|
+
: {
|
|
67
|
+
ok: false,
|
|
68
|
+
code: 'IA-EXEC-VALIDATION-FAILED',
|
|
69
|
+
message: error instanceof Error ? error.message : String(error),
|
|
70
|
+
diagnostics: [],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/authoring-execution/execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,KAAK,EA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E,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE;QACzF,CAAC,CAAC;YACE,EAAE,EAAE,KAAK;YACT,IAAI,EAAE,2BAA2B;YACjC,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC/D,WAAW,EAAE,EAAE;SAChB,CAAC;AACR,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Neutral trusted-host execution mechanics; no operation catalog or private policy. */
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export * from './shared.js';
|
|
4
|
+
export * from './execution.js';
|
|
5
|
+
export { gitFiles, ownerOf } from './inventory.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authoring-execution/index.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Neutral trusted-host execution mechanics; no operation catalog or private policy. */
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export * from './shared.js';
|
|
4
|
+
export * from './execution.js';
|
|
5
|
+
export { gitFiles, ownerOf } from './inventory.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authoring-execution/index.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Fixed local inventory operation, bounded to ten seconds and 16 MiB; no caller command or arguments. */
|
|
2
|
+
export declare function gitFiles(directory: string): string[];
|
|
3
|
+
/** Neutral repository layout ownership; no catalogue, task selection or policy decision. */
|
|
4
|
+
export declare function ownerOf(path: string): string | undefined;
|
|
5
|
+
//# sourceMappingURL=inventory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../src/authoring-execution/inventory.ts"],"names":[],"mappings":"AAEA,0GAA0G;AAC1G,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAepD;AAaD,4FAA4F;AAC5F,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUxD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
/** Fixed local inventory operation, bounded to ten seconds and 16 MiB; no caller command or arguments. */
|
|
3
|
+
export function gitFiles(directory) {
|
|
4
|
+
return [
|
|
5
|
+
...new Set(execFileSync('git', ['ls-files', '--cached', '--others', '--exclude-standard', '-z'], {
|
|
6
|
+
cwd: directory,
|
|
7
|
+
encoding: 'utf8',
|
|
8
|
+
stdio: 'pipe',
|
|
9
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
10
|
+
timeout: 10000,
|
|
11
|
+
windowsHide: true,
|
|
12
|
+
})
|
|
13
|
+
.split('\0')
|
|
14
|
+
.filter(Boolean)),
|
|
15
|
+
].sort();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Top-level directories whose files belong to the repository root: documentation and the hidden tooling directories,
|
|
19
|
+
* named by stem. Runtime only classifies these paths and never reads any of them, so it carries no path literal for
|
|
20
|
+
* the CI-configuration directory: a source that names it is, by the cache-safety invariant in tools/testing, a CI
|
|
21
|
+
* configuration reader, and only tools tasks may be one.
|
|
22
|
+
*/
|
|
23
|
+
const ROOT_OWNED = new Set([
|
|
24
|
+
'docs',
|
|
25
|
+
'ia-docs',
|
|
26
|
+
'releases',
|
|
27
|
+
...['agents', 'claude', 'github'].map((stem) => `.${stem}`),
|
|
28
|
+
]);
|
|
29
|
+
/** Neutral repository layout ownership; no catalogue, task selection or policy decision. */
|
|
30
|
+
export function ownerOf(path) {
|
|
31
|
+
const parts = path.split('/');
|
|
32
|
+
if (parts.length === 1 || ROOT_OWNED.has(parts[0]))
|
|
33
|
+
return '.';
|
|
34
|
+
if (['packages', 'apps', 'tools', 'examples', 'distributions'].includes(parts[0]) && parts.length >= 3)
|
|
35
|
+
return parts.slice(0, 2).join('/');
|
|
36
|
+
if (path.startsWith('.ia/learning/'))
|
|
37
|
+
return '.ia/learning';
|
|
38
|
+
if (path.startsWith('.ia/src/floor/'))
|
|
39
|
+
return '.ia/src/floor';
|
|
40
|
+
if (path.startsWith('.ia/src/systems/') && parts.length >= 5)
|
|
41
|
+
return parts.slice(0, 4).join('/');
|
|
42
|
+
if (parts[0] === '.ia' && (parts.length === 2 || (parts.length === 3 && parts[1] === 'src')))
|
|
43
|
+
return '.';
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=inventory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.js","sourceRoot":"","sources":["../../src/authoring-execution/inventory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,0GAA0G;AAC1G,MAAM,UAAU,QAAQ,CAAC,SAAiB;IACxC,OAAO;QACL,GAAG,IAAI,GAAG,CACR,YAAY,CAAC,KAAK,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,IAAI,CAAC,EAAE;YACpF,GAA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