omics-os 0.0.1 → 1.3.1

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.
Files changed (82) hide show
  1. package/LICENSE +664 -0
  2. package/README.md +384 -4
  3. package/package.json +34 -12
  4. package/packages/cli/dist/index.js +154 -0
  5. package/packages/cloud-client/dist/agents.d.ts +20 -0
  6. package/packages/cloud-client/dist/agents.js +69 -0
  7. package/packages/cloud-client/dist/apiClient.d.ts +44 -0
  8. package/packages/cloud-client/dist/apiClient.js +368 -0
  9. package/packages/cloud-client/dist/auth.d.ts +76 -0
  10. package/packages/cloud-client/dist/auth.js +463 -0
  11. package/packages/cloud-client/dist/biovault/approval.d.ts +40 -0
  12. package/packages/cloud-client/dist/biovault/approval.js +38 -0
  13. package/packages/cloud-client/dist/biovault/assurance.d.ts +10 -0
  14. package/packages/cloud-client/dist/biovault/assurance.js +14 -0
  15. package/packages/cloud-client/dist/biovault/client.d.ts +76 -0
  16. package/packages/cloud-client/dist/biovault/client.js +212 -0
  17. package/packages/cloud-client/dist/biovault/compat.d.ts +29 -0
  18. package/packages/cloud-client/dist/biovault/compat.js +90 -0
  19. package/packages/cloud-client/dist/biovault/entries.d.ts +143 -0
  20. package/packages/cloud-client/dist/biovault/entries.js +359 -0
  21. package/packages/cloud-client/dist/biovault/errors.d.ts +18 -0
  22. package/packages/cloud-client/dist/biovault/errors.js +90 -0
  23. package/packages/cloud-client/dist/biovault/fields.d.ts +7 -0
  24. package/packages/cloud-client/dist/biovault/fields.js +42 -0
  25. package/packages/cloud-client/dist/biovault/identity.d.ts +10 -0
  26. package/packages/cloud-client/dist/biovault/identity.js +43 -0
  27. package/packages/cloud-client/dist/biovault/index.d.ts +15 -0
  28. package/packages/cloud-client/dist/biovault/index.js +16 -0
  29. package/packages/cloud-client/dist/biovault/instructionMatch.d.ts +32 -0
  30. package/packages/cloud-client/dist/biovault/instructionMatch.js +118 -0
  31. package/packages/cloud-client/dist/biovault/pending.d.ts +41 -0
  32. package/packages/cloud-client/dist/biovault/pending.js +208 -0
  33. package/packages/cloud-client/dist/biovault/preCommit.d.ts +10 -0
  34. package/packages/cloud-client/dist/biovault/preCommit.js +10 -0
  35. package/packages/cloud-client/dist/biovault/provenance.d.ts +45 -0
  36. package/packages/cloud-client/dist/biovault/provenance.js +55 -0
  37. package/packages/cloud-client/dist/biovault/vendor/packageDeliveryV1.generated.d.ts +3981 -0
  38. package/packages/cloud-client/dist/biovault/vendor/packageDeliveryV1.generated.js +3632 -0
  39. package/packages/cloud-client/dist/biovault/vendor/runV1.generated.d.ts +2326 -0
  40. package/packages/cloud-client/dist/biovault/vendor/runV1.generated.js +491 -0
  41. package/packages/cloud-client/dist/biovault/wireShape.d.ts +25 -0
  42. package/packages/cloud-client/dist/biovault/wireShape.js +88 -0
  43. package/packages/cloud-client/dist/bootstrap.d.ts +4 -0
  44. package/packages/cloud-client/dist/bootstrap.js +19 -0
  45. package/packages/cloud-client/dist/config.d.ts +44 -0
  46. package/packages/cloud-client/dist/config.js +309 -0
  47. package/packages/cloud-client/dist/credentials.d.ts +96 -0
  48. package/packages/cloud-client/dist/credentials.js +395 -0
  49. package/packages/cloud-client/dist/editor.d.ts +77 -0
  50. package/packages/cloud-client/dist/editor.js +278 -0
  51. package/packages/cloud-client/dist/errors.d.ts +27 -0
  52. package/packages/cloud-client/dist/errors.js +102 -0
  53. package/packages/cloud-client/dist/exports.d.ts +19 -0
  54. package/packages/cloud-client/dist/exports.js +85 -0
  55. package/packages/cloud-client/dist/featureFlags.d.ts +10 -0
  56. package/packages/cloud-client/dist/featureFlags.js +36 -0
  57. package/packages/cloud-client/dist/files.d.ts +35 -0
  58. package/packages/cloud-client/dist/files.js +109 -0
  59. package/packages/cloud-client/dist/index.d.ts +29 -0
  60. package/packages/cloud-client/dist/index.js +22 -0
  61. package/packages/cloud-client/dist/multipartUpload.d.ts +99 -0
  62. package/packages/cloud-client/dist/multipartUpload.js +624 -0
  63. package/packages/cloud-client/dist/projects.d.ts +42 -0
  64. package/packages/cloud-client/dist/projects.js +119 -0
  65. package/packages/cloud-client/dist/resources.d.ts +8 -0
  66. package/packages/cloud-client/dist/resources.js +26 -0
  67. package/packages/cloud-client/dist/sessions.d.ts +67 -0
  68. package/packages/cloud-client/dist/sessions.js +187 -0
  69. package/packages/cloud-client/dist/templates.d.ts +4 -0
  70. package/packages/cloud-client/dist/templates.js +12 -0
  71. package/packages/cloud-client/dist/types.d.ts +431 -0
  72. package/packages/cloud-client/dist/types.js +94 -0
  73. package/packages/cloud-client/dist/uploads.d.ts +93 -0
  74. package/packages/cloud-client/dist/uploads.js +61 -0
  75. package/packages/cloud-client/dist/vault.d.ts +20 -0
  76. package/packages/cloud-client/dist/vault.js +43 -0
  77. package/packages/cloud-client/dist/vectorSearch.d.ts +3 -0
  78. package/packages/cloud-client/dist/vectorSearch.js +12 -0
  79. package/packages/tui/dist/lobster.mjs +273 -0
  80. package/skills/omics-os-cloud/SKILL.md +24 -0
  81. package/skills/omics-os-lobster/SKILL.md +24 -0
  82. package/bin/omics-os.js +0 -5
@@ -0,0 +1,359 @@
1
+ import { WIRE_SHAPES_RUN_V1 } from './vendor/runV1.generated.js';
2
+ import { WIRE_SHAPES } from './vendor/packageDeliveryV1.generated.js';
3
+ import { nonconformity } from './wireShape.js';
4
+ import { APPROVAL_GENERATION } from './approval.js';
5
+ import { instructionsMatch, instructionHashesMatch } from './instructionMatch.js';
6
+ import { manifestVersionOf, NATIVE_MANIFEST_VERSION, RP1_MANIFEST_VERSION, NATIVE_BUNDLE_VERSION, RP1_BUNDLE_VERSION } from './assurance.js';
7
+ /** Prompt versions the vendored execute contract admits. A re-vendor carries the set; there is no hand list. */
8
+ export const PROMPT_VERSIONS = WIRE_SHAPES_RUN_V1.ExecuteCommand.prompt_version.values;
9
+ export const isPromptVersion = (v) => typeof v === 'string' && PROMPT_VERSIONS.includes(v);
10
+ const object = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
11
+ const nonempty = (v) => typeof v === 'string' && v.length > 0;
12
+ const strings = (v) => Array.isArray(v) && v.every(x => typeof x === 'string');
13
+ const optionalString = (v) => v === undefined || v === null || typeof v === 'string';
14
+ const HEX64 = /^[a-f0-9]{64}$/;
15
+ const DIGEST_KEYS = ['config_sha256', 'prompt_sha256', 'execution_manifest_sha256', 'instruction_bundle_sha256'];
16
+ function envelope(body, path) {
17
+ if (!object(body))
18
+ return `${path}: expected an object`;
19
+ if (typeof body.success !== 'boolean')
20
+ return `${path}.success: expected true or false`;
21
+ if (typeof body.message !== 'string')
22
+ return `${path}.message: expected a string`;
23
+ return null;
24
+ }
25
+ export function featuresNonconformity(body) {
26
+ return object(body) && typeof body.biovault_run_config === 'boolean' ? null : 'Features.biovault_run_config: expected true or false';
27
+ }
28
+ /** R2 requires a nonempty locator; R3–R6 also require the requested id echo. */
29
+ export function draftNonconformity(body, requestedEntryId) {
30
+ const problem = nonconformity('DraftPreview', body, WIRE_SHAPES_RUN_V1);
31
+ if (problem)
32
+ return problem;
33
+ const p = body;
34
+ if (!nonempty(p.entry_id))
35
+ return 'DraftPreview.entry_id: expected a non-empty string';
36
+ if (requestedEntryId !== undefined && p.entry_id !== requestedEntryId)
37
+ return 'DraftPreview.entry_id: requested entry does not match';
38
+ return null;
39
+ }
40
+ /** R7 entry row: no lifecycle inference or approval judgement here. */
41
+ export function entrySummaryNonconformity(entry) {
42
+ if (!object(entry))
43
+ return 'Entry: expected an object';
44
+ for (const key of ['entry_id', 'title', 'status'])
45
+ if (typeof entry[key] !== 'string')
46
+ return `Entry.${key}: expected a string`;
47
+ if (!object(entry.work_plan))
48
+ return 'Entry.work_plan: expected an object';
49
+ if (!strings(entry.job_ids))
50
+ return 'Entry.job_ids: expected a list of strings';
51
+ for (const key of ['created_at', 'updated_at', 'error_message'])
52
+ if (!optionalString(entry[key]))
53
+ return `Entry.${key}: expected a string or null`;
54
+ return null;
55
+ }
56
+ export function entriesNonconformity(body) {
57
+ const problem = envelope(body, 'Entries');
58
+ if (problem)
59
+ return problem;
60
+ const b = body;
61
+ if (!Number.isInteger(b.total))
62
+ return 'Entries.total: expected an integer';
63
+ if (!Array.isArray(b.entries))
64
+ return 'Entries.entries: expected a list';
65
+ for (let i = 0; i < b.entries.length; i++) {
66
+ const issue = entrySummaryNonconformity(b.entries[i]);
67
+ if (issue)
68
+ return `Entries.entries[${i}]: ${issue}`;
69
+ }
70
+ return null;
71
+ }
72
+ /** R8/R9/R10 envelope + locator/plan shape only. Approval identity is a separate
73
+ * guard below; it must run before the unchanged ported judge(), never after it.
74
+ */
75
+ export function entryNonconformity(body, requestedEntryId) {
76
+ const problem = envelope(body, 'EntryResponse');
77
+ if (problem)
78
+ return problem;
79
+ const entry = body.entry;
80
+ const issue = entrySummaryNonconformity(entry);
81
+ if (issue)
82
+ return issue;
83
+ const e = entry;
84
+ if (e.entry_id !== requestedEntryId)
85
+ return 'Entry.entry_id: requested entry does not match';
86
+ if (e.work_plan.preview !== undefined) {
87
+ const previewIssue = draftNonconformity(e.work_plan.preview, requestedEntryId);
88
+ if (previewIssue)
89
+ return `Entry.work_plan.preview: ${previewIssue}`;
90
+ }
91
+ return null;
92
+ }
93
+ /** Legacy rows cannot disguise an unsupported or malformed v1 response. */
94
+ export function legacyJobNonconformity(job) {
95
+ if (!object(job))
96
+ return 'LegacyJob: expected an object';
97
+ if (job.approval_generation !== undefined && job.approval_generation !== null)
98
+ return 'LegacyJob.approval_generation: unsupported generation';
99
+ if ((object(job.run_config) && job.run_config.config_version === '1') || (job.run_approval !== undefined && job.run_approval !== null))
100
+ return 'LegacyJob: v1 markers without supported approval generation';
101
+ if (!nonempty(job.job_id))
102
+ return 'LegacyJob.job_id: expected a non-empty string';
103
+ for (const key of ['status', 'disease', 'control'])
104
+ if (typeof job[key] !== 'string')
105
+ return `LegacyJob.${key}: expected a string`;
106
+ if (!strings(job.genes))
107
+ return 'LegacyJob.genes: expected a list of strings';
108
+ for (const key of ['created_at', 'evidence_id', 'error_message'])
109
+ if (!optionalString(job[key]))
110
+ return `LegacyJob.${key}: expected a string or null`;
111
+ return null;
112
+ }
113
+ export function legacyJobsNonconformity(body) {
114
+ const problem = envelope(body, 'LegacyJobs');
115
+ if (problem)
116
+ return problem;
117
+ const b = body;
118
+ if (!Number.isInteger(b.total))
119
+ return 'LegacyJobs.total: expected an integer';
120
+ if (!Array.isArray(b.jobs))
121
+ return 'LegacyJobs.jobs: expected a list';
122
+ for (let i = 0; i < b.jobs.length; i++) {
123
+ const issue = legacyJobNonconformity(b.jobs[i]);
124
+ if (issue)
125
+ return `LegacyJobs.jobs[${i}]: ${issue}`;
126
+ }
127
+ if (!optionalString(b.next_cursor))
128
+ return 'LegacyJobs.next_cursor: expected a string or null';
129
+ return null;
130
+ }
131
+ /** R12 discriminator, with no legacy downgrade for unknown non-null generations. */
132
+ export function jobNonconformity(body, requestedJobId, shapes = WIRE_SHAPES) {
133
+ const problem = envelope(body, 'JobResponse');
134
+ if (problem)
135
+ return problem;
136
+ const b = body;
137
+ if (!object(b.job))
138
+ return 'JobResponse.job: expected an object';
139
+ const issue = b.job.approval_generation === APPROVAL_GENERATION
140
+ ? nonconformity('JobDetailResponse', body, shapes)
141
+ : legacyJobNonconformity(b.job);
142
+ if (issue)
143
+ return issue;
144
+ return b.job.job_id === requestedJobId ? null : 'JobResponse.job.job_id: requested job does not match';
145
+ }
146
+ /** Delivery R11/R14–R19, plus requested job/path echoes where present. */
147
+ export function deliveryNonconformity(name, body, requestedJobId, requestedPath) {
148
+ const problem = nonconformity(name, body, WIRE_SHAPES);
149
+ if (problem)
150
+ return problem;
151
+ const b = body;
152
+ if (requestedJobId !== undefined && b.job_id !== requestedJobId)
153
+ return `${name}.job_id: requested job does not match`;
154
+ if (requestedPath !== undefined && b.path !== requestedPath)
155
+ return `${name}.path: requested path does not match`;
156
+ return null;
157
+ }
158
+ /** R13 targets the corrected v1 prompt version, not the pin's known "4" bug. */
159
+ export function jobPromptNonconformity(body) {
160
+ if (!object(body))
161
+ return 'JobPrompt: expected an object';
162
+ for (const key of ['success', 'matches_approved'])
163
+ if (typeof body[key] !== 'boolean')
164
+ return `JobPrompt.${key}: expected true or false`;
165
+ for (const key of ['prompt', 'prompt_sha256', 'config_sha256'])
166
+ if (typeof body[key] !== 'string')
167
+ return `JobPrompt.${key}: expected a string`;
168
+ if (body.approved_prompt_sha256 !== null && typeof body.approved_prompt_sha256 !== 'string')
169
+ return 'JobPrompt.approved_prompt_sha256: expected a string or null';
170
+ if (!isPromptVersion(body.prompt_version))
171
+ return 'JobPrompt.prompt_version: unsupported version';
172
+ if (body.approval_generation !== APPROVAL_GENERATION)
173
+ return 'JobPrompt.approval_generation: unsupported generation';
174
+ if (body.instructions !== null) {
175
+ const issue = nonconformity('InstructionPreview', body.instructions, WIRE_SHAPES_RUN_V1);
176
+ if (issue)
177
+ return issue;
178
+ }
179
+ if (!Array.isArray(body.prompt_sections))
180
+ return 'JobPrompt.prompt_sections: expected a list';
181
+ for (const section of body.prompt_sections) {
182
+ const issue = nonconformity('PromptSection', section, WIRE_SHAPES_RUN_V1);
183
+ if (issue)
184
+ return issue;
185
+ }
186
+ return null;
187
+ }
188
+ export function cancelNonconformity(body, requestedJobId) {
189
+ const problem = envelope(body, 'CancelAck');
190
+ if (problem)
191
+ return problem;
192
+ const b = body;
193
+ if (b.success !== true)
194
+ return 'CancelAck.success: expected true';
195
+ if (!object(b.job))
196
+ return 'CancelAck.job: expected an object';
197
+ if (b.job.job_id !== requestedJobId)
198
+ return 'CancelAck.job.job_id: requested job does not match';
199
+ if (b.job.status !== 'cancelled')
200
+ return 'CancelAck.job.status: expected cancelled';
201
+ if (b.job.run_terminal !== true)
202
+ return 'CancelAck.job.run_terminal: expected true';
203
+ return b.job.cancel_cleanup_status === 'pending' || b.job.cancel_cleanup_status === 'complete' ? null : 'CancelAck.job.cancel_cleanup_status: expected pending or complete';
204
+ }
205
+ export function modelSelectionNonconformity(value) {
206
+ if (!object(value))
207
+ return 'model_selection: expected an object';
208
+ if (value.mode === 'inherit')
209
+ return null;
210
+ if (value.mode !== 'explicit')
211
+ return 'model_selection.mode: expected inherit or explicit';
212
+ if (!object(value.model))
213
+ return 'model_selection.model: expected an object';
214
+ if (value.model.provider !== 'bedrock' && value.model.provider !== 'anthropic')
215
+ return 'model_selection.model.provider: unsupported provider';
216
+ return typeof value.model.model_id === 'string' ? null : 'model_selection.model.model_id: expected a string';
217
+ }
218
+ const same = (a, b) => {
219
+ if (a === b)
220
+ return true;
221
+ if (!object(a) || !object(b))
222
+ return false;
223
+ const keys = Object.keys(a);
224
+ return keys.length === Object.keys(b).length && keys.every(k => Object.hasOwn(b, k) && same(a[k], b[k]));
225
+ };
226
+ /** Input 2 is R8's entry summary, NOT the envelope. Diagnostic prefixes are the
227
+ * public caller distinction: "mismatch:" = coherent shapes, stale R3/R8 pair
228
+ * (exit 5); "unreadable:" = malformed/missing shape or selection (exit 1).
229
+ * Both-null instructions permit blocked drafts to be shown/exported. Callers
230
+ * must perform this check before displaying a prompt or doing any write.
231
+ */
232
+ export function snapshotNonconformity(r3Preview, r8Entry) {
233
+ const pIssue = draftNonconformity(r3Preview);
234
+ if (pIssue)
235
+ return `unreadable: ${pIssue}`;
236
+ const eIssue = entrySummaryNonconformity(r8Entry);
237
+ if (eIssue)
238
+ return `unreadable: ${eIssue}`;
239
+ const p = r3Preview, e = r8Entry;
240
+ const q = e.work_plan.preview;
241
+ const qIssue = draftNonconformity(q);
242
+ if (qIssue)
243
+ return `unreadable: Entry.work_plan.preview: ${qIssue}`;
244
+ const stored = q;
245
+ const selectionIssue = modelSelectionNonconformity(e.work_plan.model_selection);
246
+ if (selectionIssue)
247
+ return `unreadable: ${selectionIssue}`;
248
+ for (const key of ['entry_id', 'revision', 'config_sha256', 'prompt_sha256'])
249
+ if (p[key] !== stored[key])
250
+ return `mismatch: DraftPreview.${key} changed between R3 and R8`;
251
+ if (e.entry_id !== p.entry_id)
252
+ return 'mismatch: Entry.entry_id changed between R3 and R8';
253
+ if (p.editing.turn_generation !== stored.editing.turn_generation)
254
+ return 'mismatch: DraftPreview.editing.turn_generation changed between R3 and R8';
255
+ if ((p.instructions === null) !== (stored.instructions === null))
256
+ return 'mismatch: DraftPreview.instructions changed between R3 and R8';
257
+ if (p.instructions && stored.instructions) {
258
+ for (const key of ['execution_manifest_sha256', 'instruction_bundle_sha256'])
259
+ if (p.instructions[key] !== stored.instructions[key])
260
+ return `mismatch: DraftPreview.instructions.${key} changed between R3 and R8`;
261
+ }
262
+ for (const preview of [p, stored]) {
263
+ if (preview.config.llm !== null && !same(preview.config.llm.selection, e.work_plan.model_selection))
264
+ return 'unreadable: model_selection does not match preview.config.llm.selection';
265
+ }
266
+ return null;
267
+ }
268
+ /** Read contract: non-null MUST map to unknown, never different. This guard
269
+ * deliberately does not compare the clicked tuple: judge() owns that verdict.
270
+ * A valid different tuple is evidence only after locator, membership and both
271
+ * live/pending identities have passed this guard.
272
+ */
273
+ export function approvalNonconformity(entry, requestedEntryId, identity, pending) {
274
+ const issue = entrySummaryNonconformity(entry);
275
+ if (issue)
276
+ return issue;
277
+ const e = entry;
278
+ if (e.entry_id !== requestedEntryId)
279
+ return 'Approval.entry_id: requested entry does not match';
280
+ if (!object(identity) || !nonempty(identity.user_id) || !nonempty(identity.org_id))
281
+ return 'Approval.identity: expected non-empty user_id and org_id';
282
+ if (pending !== undefined && (!object(pending) || pending.user_id !== identity.user_id || pending.org_id !== identity.org_id))
283
+ return 'Approval.pending: identity does not match';
284
+ if (!Object.hasOwn(e.work_plan, 'approval'))
285
+ return null;
286
+ const a = e.work_plan.approval;
287
+ if (!object(a))
288
+ return 'Approval: expected an object';
289
+ if (a.approval_generation !== APPROVAL_GENERATION)
290
+ return 'Approval.approval_generation: unsupported generation';
291
+ for (const key of DIGEST_KEYS)
292
+ if (typeof a[key] !== 'string' || !HEX64.test(a[key]))
293
+ return `Approval.${key}: expected a lowercase SHA-256 digest`;
294
+ if (!Number.isInteger(a.expected_revision) || a.expected_revision <= 0)
295
+ return 'Approval.expected_revision: expected a positive integer';
296
+ if (!Number.isInteger(a.expected_turn_generation) || a.expected_turn_generation < 0)
297
+ return 'Approval.expected_turn_generation: expected a non-negative integer';
298
+ if (!isPromptVersion(a.prompt_version))
299
+ return 'Approval.prompt_version: unsupported version';
300
+ if (a.entry_id !== requestedEntryId)
301
+ return 'Approval.entry_id: requested entry does not match';
302
+ if (!nonempty(a.job_id) || !e.job_ids.includes(a.job_id))
303
+ return 'Approval.job_id: expected a non-empty job in entry.job_ids';
304
+ if (!nonempty(a.actor_user_id) || a.actor_user_id !== identity.user_id)
305
+ return 'Approval.actor_user_id: identity does not match';
306
+ if (!nonempty(a.effective_org_id) || a.effective_org_id !== identity.org_id)
307
+ return 'Approval.effective_org_id: identity does not match';
308
+ return null;
309
+ }
310
+ /** Read contract: the first failure in the authorized API order. Preview must first
311
+ * pass draftNonconformity. Unknown versions are fenced before the structural
312
+ * and hash checks; malformed bundle JSON remains instructions_mismatch. No
313
+ * hashing normalizes or reserializes returned config/prompt/bundle strings.
314
+ */
315
+ export async function executeReadiness(preview) {
316
+ if (preview.can_execute !== true)
317
+ return { ok: false, reason: 'not_executable' };
318
+ if (preview.checks.some(check => check.kind === 'blocking'))
319
+ return { ok: false, reason: 'blocking' };
320
+ if (preview.editing.omni !== false)
321
+ return { ok: false, reason: 'omni_editing' };
322
+ if (preview.editing.turn_id !== null)
323
+ return { ok: false, reason: 'turn_active' };
324
+ if (!preview.instructions)
325
+ return { ok: false, reason: 'no_instructions' };
326
+ const manifestVersion = manifestVersionOf(preview.config);
327
+ if (!isPromptVersion(preview.prompt_version) || preview.approval_generation !== APPROVAL_GENERATION ||
328
+ (manifestVersion !== NATIVE_MANIFEST_VERSION && manifestVersion !== RP1_MANIFEST_VERSION))
329
+ return { ok: false, reason: 'unknown_version' };
330
+ let bundle;
331
+ try {
332
+ bundle = JSON.parse(preview.instructions.instruction_bundle_json);
333
+ }
334
+ catch {
335
+ return { ok: false, reason: 'instructions_mismatch' };
336
+ }
337
+ if (!object(bundle))
338
+ return { ok: false, reason: 'instructions_mismatch' };
339
+ if (bundle.bundle_version !== NATIVE_BUNDLE_VERSION && bundle.bundle_version !== RP1_BUNDLE_VERSION)
340
+ return { ok: false, reason: 'unknown_version' };
341
+ if (!instructionsMatch(preview))
342
+ return { ok: false, reason: 'instructions_mismatch' };
343
+ try {
344
+ if (!await instructionHashesMatch(preview))
345
+ return { ok: false, reason: 'hash_mismatch' };
346
+ }
347
+ catch {
348
+ return { ok: false, reason: 'hash_mismatch' }; // unavailable hashing is not proof
349
+ }
350
+ return { ok: true, command: {
351
+ config_sha256: preview.config_sha256,
352
+ prompt_sha256: preview.prompt_sha256,
353
+ execution_manifest_sha256: preview.instructions.execution_manifest_sha256,
354
+ instruction_bundle_sha256: preview.instructions.instruction_bundle_sha256,
355
+ expected_revision: preview.revision,
356
+ expected_turn_generation: preview.editing.turn_generation,
357
+ prompt_version: preview.prompt_version,
358
+ } };
359
+ }
@@ -0,0 +1,18 @@
1
+ /** BioVault error classification: ordered, for vault calls only. Server prose/body presentation
2
+ * fields are never trusted. Transport classes/status/code are the only inputs.
3
+ * Returns the same shared ApiError when possible, or a metadata-preserving wrapper
4
+ * for non-API failures. It sets only locally trusted presentation metadata.
5
+ */
6
+ import { ApiError } from '../types.js';
7
+ export type VaultRoute = 'R1' | 'R2' | 'R3' | 'R4' | 'R5' | 'R6' | 'R7' | 'R8' | 'R9' | 'R10' | 'R11' | 'R12' | 'R13' | 'R14' | 'R15' | 'R16' | 'R17' | 'R18' | 'R19' | 'R20';
8
+ export type VaultErrorKind = 'precommit_refused' | 'busy' | 'unknown_outcome' | 'cancel_cleanup_pending' | 'session' | 'forbidden' | 'unavailable' | 'not_found' | 'stale' | 'not_now' | 'blocked' | 'invalid' | 'integrity' | 'rate_limited' | 'refused' | 'server' | 'unreadable';
9
+ export type ClassifiedVaultError = ApiError & {
10
+ kind: VaultErrorKind;
11
+ publicMessage: string;
12
+ exitCode: number;
13
+ };
14
+ /** Optional third argument = caller's validated requested entry/job id. If absent
15
+ * or unsafe, use a literal <entry>/<job> instruction rather than infer a locator
16
+ * from an untrusted error path. Primary route,error API remains unchanged.
17
+ */
18
+ export declare function classifyVaultError(route: VaultRoute, error: unknown, id?: string): ClassifiedVaultError;
@@ -0,0 +1,90 @@
1
+ /** BioVault error classification: ordered, for vault calls only. Server prose/body presentation
2
+ * fields are never trusted. Transport classes/status/code are the only inputs.
3
+ * Returns the same shared ApiError when possible, or a metadata-preserving wrapper
4
+ * for non-API failures. It sets only locally trusted presentation metadata.
5
+ */
6
+ import { ApiError, NetworkError, StoredCredentialOriginError, UnknownOutcomeError, UnreadableResponseError } from '../types.js';
7
+ import { provesNothingCommitted, provesNothingStartedTryAgain } from './preCommit.js';
8
+ const WRITES = ['R2', 'R4', 'R5', 'R6', 'R9', 'R10', 'R20'];
9
+ const STALE = ['CONFIG_CHANGED', 'DRAFT_EDIT_IN_PROGRESS', 'DRAFT_TURN_INVALID', 'DRAFT_TURN_CONFLICT', 'RECORD_CHANGED', 'LITERATURE_FILE_CHANGED'];
10
+ const NOT_NOW = ['ENTRY_NOT_PLANNING', 'DRAFT_EXPIRED', 'CONFIG_VERSION_REAPPROVAL_REQUIRED', 'PACKAGE_NOT_READY', 'SAMPLES_NOT_READY'];
11
+ const BLOCKED = ['DRAFT_BLOCKED', 'LIMIT_REQUIRED', 'LIMIT_INVALID', 'STORAGE_LIMIT_TOO_SMALL', 'LIMIT_CEILING_EXCEEDED', 'RUN_COST_LIMIT', 'RUN_STORAGE_LIMIT'];
12
+ const INVALID = ['INVALID_REQUEST', 'INVALID_CURSOR', 'CONFIG_TOO_LARGE', 'LITERATURE_FILE_INVALID'];
13
+ const SERVER = 'The server could not complete the request. Try again later.';
14
+ const CANCELLED = 'Cancellation recorded. No evidence will be published for this run.';
15
+ // Only requested ids, independently fenced here; never an error body or path.
16
+ const requestedId = (id, placeholder) => typeof id === 'string' && /^[A-Za-z0-9_-]{1,128}$/.test(id) ? id : placeholder;
17
+ /** Optional third argument = caller's validated requested entry/job id. If absent
18
+ * or unsafe, use a literal <entry>/<job> instruction rather than infer a locator
19
+ * from an untrusted error path. Primary route,error API remains unchanged.
20
+ */
21
+ export function classifyVaultError(route, error, id) {
22
+ const api = error instanceof ApiError ? error : undefined;
23
+ const status = api?.status ?? 0, code = api?.code;
24
+ const write = WRITES.includes(route);
25
+ const entry = requestedId(id, '<entry>'), job = requestedId(id, '<job>');
26
+ const set = (kind, exitCode, publicMessage) => {
27
+ const result = api ?? new ApiError('', 0, '');
28
+ if (!api)
29
+ result.cause = error;
30
+ result.kind = kind;
31
+ result.exitCode = exitCode;
32
+ result.publicMessage = publicMessage;
33
+ return result;
34
+ };
35
+ // Refused before any request was sent, so never an unknown outcome.
36
+ if (error instanceof StoredCredentialOriginError)
37
+ return set('session', 3, error.message);
38
+ // 1–3: every R9 failure is ambiguous except the five proven pre-commit codes.
39
+ if (route === 'R9') {
40
+ if (provesNothingCommitted(code))
41
+ return set('precommit_refused', 6, 'Nothing was started by this attempt. The server could not apply its run policy; try again later.');
42
+ if (provesNothingStartedTryAgain(code))
43
+ return set('busy', 7, 'Nothing was started by this attempt. Run capacity is full; try again later.');
44
+ return set('unknown_outcome', 8, `The start outcome is unknown. Run: omics-os biovault run recover ${entry}`);
45
+ }
46
+ // 4/4b: a durable cleanup acknowledgement takes precedence over 409/unknown.
47
+ if (route === 'R20' && code === 'CANCEL_CLEANUP_INCOMPLETE')
48
+ return set('cancel_cleanup_pending', 7, `${CANCELLED} Cleanup is still pending; run omics-os biovault run cancel ${job} again.`);
49
+ if (route === 'R20' && status === 409)
50
+ return set('not_now', 5, 'This run has already ended.');
51
+ // 5: uncertainty in a dispatched mutation is never a definite refusal. Any
52
+ // 5xx is unknown regardless of code (except R20 cleanup, already matched).
53
+ if (write && (error instanceof NetworkError || error instanceof UnknownOutcomeError || error instanceof UnreadableResponseError ||
54
+ (status >= 300 && status < 400) || status === 408 || status >= 500 || (status >= 200 && status < 300))) {
55
+ const sentence = route === 'R2' ? 'The draft may or may not have been created. Check with: omics-os biovault draft list'
56
+ : route === 'R20' ? `Cancellation could not be confirmed; check omics-os biovault run show ${job}.`
57
+ : `The change may or may not have been saved. Check with: omics-os biovault draft show ${entry}`;
58
+ return set('unknown_outcome', 8, sentence);
59
+ }
60
+ // 6–19: order, including uncoded validation errors, is the frozen contract.
61
+ if (status === 401 || code === 'UNAUTHORIZED')
62
+ return set('session', 3, 'Your session is not valid. Run: omics-os login');
63
+ if (status === 403 || code === 'ACCESS_DENIED')
64
+ return set('forbidden', 3, 'You do not have access to this.');
65
+ if (code === 'PACKAGE_UNAVAILABLE' || code === 'ARCHIVE_UNAVAILABLE')
66
+ return set('unavailable', 4, code === 'ARCHIVE_UNAVAILABLE' ? 'No zip was built for this folder; download the files instead.' : 'This run has no downloadable folder.');
67
+ if (status === 404 || code === 'NOT_FOUND')
68
+ return set('not_found', 4, 'Not found.');
69
+ if (code && STALE.includes(code))
70
+ return set('stale', 5, 'The draft changed since it was read. Export or show it again.');
71
+ if (code && NOT_NOW.includes(code))
72
+ return set('not_now', 5, "This is not possible in the record's current state.");
73
+ if (code && BLOCKED.includes(code))
74
+ return set('blocked', 6, 'The draft is not ready: fix its Blocking checks or limits.');
75
+ if ([422, 413, 400].includes(status) || (code && INVALID.includes(code)))
76
+ return set('invalid', 2, 'The server rejected the configuration or arguments.');
77
+ // Package downloads can use a local ApiError with code PACKAGE_INTEGRITY for size/hash mismatch.
78
+ if (code === 'PACKAGE_INTEGRITY')
79
+ return set('integrity', 9, 'Integrity check failed; the file was not saved.');
80
+ if (status === 429)
81
+ return set('rate_limited', 7, 'Too many requests. Try again shortly.');
82
+ if (status >= 400 && status < 500)
83
+ return set('refused', 6, 'Request refused. Review the command and try again.');
84
+ if (status >= 500 || (status >= 300 && status < 400) || code === 'PACKAGE_STORAGE' || error instanceof NetworkError)
85
+ return set('server', 1, SERVER);
86
+ // Also how a record from a newer server contract arrives: an unlisted enum value fails closed here.
87
+ if (error instanceof UnreadableResponseError)
88
+ return set('unreadable', 1, 'The server sent a response this CLI version could not read. Update the CLI (npm install -g omics-os@latest) and try again.');
89
+ return set('server', 1, SERVER);
90
+ }
@@ -0,0 +1,7 @@
1
+ import type { DraftFieldsV1, DraftPreview } from './vendor/runV1.generated.js';
2
+ /** The paths whose origin the server tracks, and so the paths a person can "keep" as their own choice (`confirm_defaults`). `ORIGIN_PATHS` minus what is not editable. */
3
+ export declare const CONFIRMABLE_PATHS: readonly ["request.question", "request.custom_prompt_addition", "selection.nodes", "cohorts.intent", "cohorts.control_preference", "cohorts.min_samples_per_group", "cohorts.pairing_preference", "cohorts.stratify_by", "cohorts.covariates", "eligibility.include", "eligibility.exclude", "eligibility.preferences", "eligibility.treatment_status.policy", "eligibility.treatment_status.when_missing", "eligibility.sample_types.allow", "eligibility.sample_types.when_missing", "eligibility.sex.use", "eligibility.sex.when_missing", "eligibility.library.type", "eligibility.library.when_missing", "eligibility.donors_under_18", "eligibility.donor_age_when_missing", "datasets.mode", "datasets.include", "datasets.exclude", "datasets.commercially_usable_only", "size.preferred_subjects", "size.preferred_studies", "size.preferred_bytes", "limits.max_cost_usd", "limits.max_storage_bytes", "interaction.stop_on_blocking_problem", "sources.disallowed", "llm.selection"];
4
+ export declare function fieldsOfPreview(preview: DraftPreview): DraftFieldsV1;
5
+ export declare const originOf: (preview: DraftPreview, path: string) => "user" | "omni" | "default" | undefined;
6
+ /** Read a value of the stored config by path. */
7
+ export declare const configValue: (preview: DraftPreview, path: string) => unknown;
@@ -0,0 +1,42 @@
1
+ /** The paths whose origin the server tracks, and so the paths a person can "keep" as their own choice (`confirm_defaults`). `ORIGIN_PATHS` minus what is not editable. */
2
+ export const CONFIRMABLE_PATHS = [
3
+ 'request.question', 'request.custom_prompt_addition', 'selection.nodes', 'cohorts.intent', 'cohorts.control_preference',
4
+ 'cohorts.min_samples_per_group', 'cohorts.pairing_preference', 'cohorts.stratify_by', 'cohorts.covariates', 'eligibility.include',
5
+ 'eligibility.exclude', 'eligibility.preferences', 'eligibility.treatment_status.policy', 'eligibility.treatment_status.when_missing',
6
+ 'eligibility.sample_types.allow', 'eligibility.sample_types.when_missing', 'eligibility.sex.use', 'eligibility.sex.when_missing',
7
+ 'eligibility.library.type', 'eligibility.library.when_missing', 'eligibility.donors_under_18', 'eligibility.donor_age_when_missing',
8
+ 'datasets.mode', 'datasets.include', 'datasets.exclude', 'datasets.commercially_usable_only', 'size.preferred_subjects',
9
+ 'size.preferred_studies', 'size.preferred_bytes', 'limits.max_cost_usd', 'limits.max_storage_bytes', 'interaction.stop_on_blocking_problem',
10
+ 'sources.disallowed', 'llm.selection',
11
+ ];
12
+ const get = (data, path) => path.split('.').reduce((d, k) => (d && typeof d === 'object' ? d[k] : undefined), data);
13
+ const put = (target, path, value) => {
14
+ const keys = path.split('.');
15
+ let t = target;
16
+ for (const k of keys.slice(0, -1))
17
+ t = (t[k] ??= {});
18
+ t[keys[keys.length - 1]] = value;
19
+ };
20
+ export function fieldsOfPreview(preview) {
21
+ const out = {};
22
+ for (const path of CONFIRMABLE_PATHS) {
23
+ if (path === 'llm.selection') {
24
+ // The model choice the server recorded travels with every whole replacement: a replacement without it would reset it to
25
+ // "inherit" (VaultDraftService.build), changing the approved intent without any model-choice action. "inherit" is what an
26
+ // absent selection means, so only a recorded explicit choice is carried.
27
+ const recorded = get(preview.config, 'llm.selection');
28
+ if (recorded?.mode === 'explicit')
29
+ put(out, path, structuredClone(recorded));
30
+ continue;
31
+ }
32
+ let value = structuredClone(get(preview.config, path));
33
+ if (path === 'selection.nodes')
34
+ value = (value ?? []).map(({ id, label, type, role }) => ({ id, label, type, role }));
35
+ if (value !== undefined)
36
+ put(out, path, value);
37
+ }
38
+ return out;
39
+ }
40
+ export const originOf = (preview, path) => get(preview.config, 'provenance.field_origin') ? get(preview.config, 'provenance.field_origin')[path] : undefined;
41
+ /** Read a value of the stored config by path. */
42
+ export const configValue = (preview, path) => get(preview.config, path);
@@ -0,0 +1,10 @@
1
+ import { type AppConfig } from '../types.js';
2
+ export interface BoundIdentity {
3
+ config: AppConfig;
4
+ user_id: string;
5
+ org_id: string;
6
+ auth_mode: string;
7
+ }
8
+ export declare function bindIdentity(config: AppConfig, options?: {
9
+ signal?: AbortSignal;
10
+ }): Promise<BoundIdentity>;
@@ -0,0 +1,43 @@
1
+ /** Bind one verified actor to one command. Credential/profile refresh happens
2
+ * once before capture; all later HTTP uses tokenSource:cli, never the profile.
3
+ */
4
+ import { freshAuthHeaders } from '../config.js';
5
+ import { apiFetch } from '../apiClient.js';
6
+ import { ApiError, AuthError, UnreadableResponseError } from '../types.js';
7
+ import { classifyVaultError } from './errors.js';
8
+ export async function bindIdentity(config, options = {}) {
9
+ const path = '/gateway/auth/verify';
10
+ try {
11
+ options.signal?.throwIfAborted();
12
+ const headers = await freshAuthHeaders(config);
13
+ options.signal?.throwIfAborted();
14
+ const authorization = headers.Authorization;
15
+ if (typeof authorization !== 'string' || !authorization.startsWith('Bearer ') || !authorization.slice(7))
16
+ throw new AuthError(path);
17
+ const captured = { ...config, token: authorization.slice(7), authType: headers['X-API-Key'] ? 'api-key' : 'bearer', tokenSource: 'cli' };
18
+ const body = await apiFetch(captured, path, { signal: options.signal });
19
+ if (body === null || typeof body !== 'object' || Array.isArray(body))
20
+ throw new UnreadableResponseError(path, 200);
21
+ const b = body;
22
+ if (b.authenticated !== true || typeof b.user_id !== 'string' || !b.user_id ||
23
+ (b.org_id !== null && typeof b.org_id !== 'string') || typeof b.auth_mode !== 'string')
24
+ throw new UnreadableResponseError(path, 200);
25
+ if (!b.org_id) {
26
+ const error = new ApiError(path, 0, '');
27
+ error.kind = 'forbidden';
28
+ error.exitCode = 3;
29
+ error.publicMessage = 'BioVault runs need an organisation account.';
30
+ throw error;
31
+ }
32
+ return { config: captured, user_id: b.user_id, org_id: b.org_id, auth_mode: b.auth_mode };
33
+ }
34
+ catch (error) {
35
+ if (options.signal?.aborted)
36
+ throw options.signal.reason;
37
+ if (error instanceof ApiError && error.exitCode !== undefined)
38
+ throw error;
39
+ // A verify GET is not R8 (no vault rollout/not-enabled remapping), and is
40
+ // never R9. R1's read classifier preserves session3 vs exhausted server1.
41
+ throw classifyVaultError('R1', error);
42
+ }
43
+ }
@@ -0,0 +1,15 @@
1
+ export * as runV1 from './vendor/runV1.generated.js';
2
+ export * as deliveryV1 from './vendor/packageDeliveryV1.generated.js';
3
+ export * from './wireShape.js';
4
+ export * from './instructionMatch.js';
5
+ export * from './assurance.js';
6
+ export * from './approval.js';
7
+ export * from './preCommit.js';
8
+ export * from './fields.js';
9
+ export * from './entries.js';
10
+ export * from './errors.js';
11
+ export * from './client.js';
12
+ export * from './compat.js';
13
+ export { BIOVAULT_CONTRACT } from './provenance.js';
14
+ export * from './identity.js';
15
+ export * from './pending.js';
@@ -0,0 +1,16 @@
1
+ // Generated contracts share names (Artifact, Request, etc.): namespace only.
2
+ export * as runV1 from './vendor/runV1.generated.js';
3
+ export * as deliveryV1 from './vendor/packageDeliveryV1.generated.js';
4
+ export * from './wireShape.js';
5
+ export * from './instructionMatch.js';
6
+ export * from './assurance.js';
7
+ export * from './approval.js';
8
+ export * from './preCommit.js';
9
+ export * from './fields.js';
10
+ export * from './entries.js';
11
+ export * from './errors.js';
12
+ export * from './client.js';
13
+ export * from './compat.js';
14
+ export { BIOVAULT_CONTRACT } from './provenance.js';
15
+ export * from './identity.js';
16
+ export * from './pending.js';
@@ -0,0 +1,32 @@
1
+ import type { DraftPreview } from './vendor/runV1.generated.js';
2
+ type Json = null | boolean | number | string | Json[] | {
3
+ [k: string]: Json;
4
+ };
5
+ /** Python's `canonical()`: keys sorted by code point, no spaces, characters outside ASCII written as they are. */
6
+ export declare function canonicalJson(v: Json): string;
7
+ export declare function sha256Hex(text: string): Promise<string>;
8
+ type Input = Pick<DraftPreview, 'prompt' | 'prompt_sha256' | 'config' | 'config_json' | 'config_sha256' | 'instructions'>;
9
+ /**
10
+ * The part that needs no hashing: the bundle, the messages and the manifest are the ones the plan's own config and prompt make. Role and component count,
11
+ * not only the words. A plan with no instruction block has nothing to compare (its readiness is the server's `can_execute`).
12
+ */
13
+ export declare function instructionsMatch(p: Input): boolean;
14
+ /** The four texts the hashes are computed over: nothing else is ever hashed, so nothing else is in the cache key. */
15
+ interface Hashed {
16
+ bundle: string;
17
+ manifest: string;
18
+ config: string;
19
+ prompt: string;
20
+ }
21
+ export interface Digests {
22
+ bundle: string;
23
+ manifest: string;
24
+ config: string;
25
+ prompt: string;
26
+ }
27
+ /** The only asynchronous part: SHA-256 of the four texts. A pure function of those four strings. */
28
+ export declare function digestsOf(h: Hashed): Promise<Digests>;
29
+ /** The hashes: each recomputed from the bytes held and compared to the value that will be sent. */
30
+ export declare function instructionHashesMatch(p: Input): Promise<boolean>;
31
+ export {};
32
+ /** 'none': no block. 'pending': being checked (Execute stays off). 'ok' / 'bad': the verdict for THESE inputs. */