omics-os 0.0.1 → 1.3.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/LICENSE +664 -0
- package/README.md +384 -4
- package/package.json +34 -12
- package/packages/cli/dist/index.js +154 -0
- package/packages/cloud-client/dist/agents.d.ts +20 -0
- package/packages/cloud-client/dist/agents.js +69 -0
- package/packages/cloud-client/dist/apiClient.d.ts +44 -0
- package/packages/cloud-client/dist/apiClient.js +368 -0
- package/packages/cloud-client/dist/auth.d.ts +76 -0
- package/packages/cloud-client/dist/auth.js +462 -0
- package/packages/cloud-client/dist/biovault/approval.d.ts +40 -0
- package/packages/cloud-client/dist/biovault/approval.js +38 -0
- package/packages/cloud-client/dist/biovault/assurance.d.ts +10 -0
- package/packages/cloud-client/dist/biovault/assurance.js +14 -0
- package/packages/cloud-client/dist/biovault/client.d.ts +76 -0
- package/packages/cloud-client/dist/biovault/client.js +212 -0
- package/packages/cloud-client/dist/biovault/compat.d.ts +29 -0
- package/packages/cloud-client/dist/biovault/compat.js +90 -0
- package/packages/cloud-client/dist/biovault/entries.d.ts +143 -0
- package/packages/cloud-client/dist/biovault/entries.js +359 -0
- package/packages/cloud-client/dist/biovault/errors.d.ts +18 -0
- package/packages/cloud-client/dist/biovault/errors.js +90 -0
- package/packages/cloud-client/dist/biovault/fields.d.ts +7 -0
- package/packages/cloud-client/dist/biovault/fields.js +42 -0
- package/packages/cloud-client/dist/biovault/identity.d.ts +10 -0
- package/packages/cloud-client/dist/biovault/identity.js +43 -0
- package/packages/cloud-client/dist/biovault/index.d.ts +15 -0
- package/packages/cloud-client/dist/biovault/index.js +16 -0
- package/packages/cloud-client/dist/biovault/instructionMatch.d.ts +32 -0
- package/packages/cloud-client/dist/biovault/instructionMatch.js +118 -0
- package/packages/cloud-client/dist/biovault/pending.d.ts +41 -0
- package/packages/cloud-client/dist/biovault/pending.js +208 -0
- package/packages/cloud-client/dist/biovault/preCommit.d.ts +10 -0
- package/packages/cloud-client/dist/biovault/preCommit.js +10 -0
- package/packages/cloud-client/dist/biovault/provenance.d.ts +45 -0
- package/packages/cloud-client/dist/biovault/provenance.js +55 -0
- package/packages/cloud-client/dist/biovault/vendor/packageDeliveryV1.generated.d.ts +3981 -0
- package/packages/cloud-client/dist/biovault/vendor/packageDeliveryV1.generated.js +3632 -0
- package/packages/cloud-client/dist/biovault/vendor/runV1.generated.d.ts +2326 -0
- package/packages/cloud-client/dist/biovault/vendor/runV1.generated.js +491 -0
- package/packages/cloud-client/dist/biovault/wireShape.d.ts +25 -0
- package/packages/cloud-client/dist/biovault/wireShape.js +88 -0
- package/packages/cloud-client/dist/bootstrap.d.ts +4 -0
- package/packages/cloud-client/dist/bootstrap.js +19 -0
- package/packages/cloud-client/dist/config.d.ts +44 -0
- package/packages/cloud-client/dist/config.js +309 -0
- package/packages/cloud-client/dist/credentials.d.ts +96 -0
- package/packages/cloud-client/dist/credentials.js +395 -0
- package/packages/cloud-client/dist/editor.d.ts +77 -0
- package/packages/cloud-client/dist/editor.js +278 -0
- package/packages/cloud-client/dist/errors.d.ts +27 -0
- package/packages/cloud-client/dist/errors.js +102 -0
- package/packages/cloud-client/dist/exports.d.ts +19 -0
- package/packages/cloud-client/dist/exports.js +85 -0
- package/packages/cloud-client/dist/featureFlags.d.ts +10 -0
- package/packages/cloud-client/dist/featureFlags.js +36 -0
- package/packages/cloud-client/dist/files.d.ts +35 -0
- package/packages/cloud-client/dist/files.js +109 -0
- package/packages/cloud-client/dist/index.d.ts +29 -0
- package/packages/cloud-client/dist/index.js +22 -0
- package/packages/cloud-client/dist/multipartUpload.d.ts +99 -0
- package/packages/cloud-client/dist/multipartUpload.js +624 -0
- package/packages/cloud-client/dist/projects.d.ts +42 -0
- package/packages/cloud-client/dist/projects.js +119 -0
- package/packages/cloud-client/dist/resources.d.ts +8 -0
- package/packages/cloud-client/dist/resources.js +26 -0
- package/packages/cloud-client/dist/sessions.d.ts +67 -0
- package/packages/cloud-client/dist/sessions.js +187 -0
- package/packages/cloud-client/dist/templates.d.ts +4 -0
- package/packages/cloud-client/dist/templates.js +12 -0
- package/packages/cloud-client/dist/types.d.ts +431 -0
- package/packages/cloud-client/dist/types.js +94 -0
- package/packages/cloud-client/dist/uploads.d.ts +93 -0
- package/packages/cloud-client/dist/uploads.js +61 -0
- package/packages/cloud-client/dist/vault.d.ts +20 -0
- package/packages/cloud-client/dist/vault.js +43 -0
- package/packages/cloud-client/dist/vectorSearch.d.ts +3 -0
- package/packages/cloud-client/dist/vectorSearch.js +12 -0
- package/packages/tui/dist/lobster.mjs +273 -0
- package/skills/omics-os-cloud/SKILL.md +24 -0
- package/skills/omics-os-lobster/SKILL.md +24 -0
- package/bin/omics-os.js +0 -5
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { NATIVE_BUNDLE_VERSION, NATIVE_MANIFEST_VERSION, NATIVE_SCOPE, RP1_BUNDLE_VERSION, RP1_MANIFEST_VERSION, RP1_SCOPE } from './assurance.js';
|
|
2
|
+
const byCodePoint = (a, b) => {
|
|
3
|
+
const x = Array.from(a);
|
|
4
|
+
const y = Array.from(b);
|
|
5
|
+
for (let i = 0; i < Math.min(x.length, y.length); i++) {
|
|
6
|
+
const d = x[i].codePointAt(0) - y[i].codePointAt(0);
|
|
7
|
+
if (d !== 0)
|
|
8
|
+
return d;
|
|
9
|
+
}
|
|
10
|
+
return x.length - y.length;
|
|
11
|
+
};
|
|
12
|
+
/** Python's `canonical()`: keys sorted by code point, no spaces, characters outside ASCII written as they are. */
|
|
13
|
+
export function canonicalJson(v) {
|
|
14
|
+
const sorted = (x) => {
|
|
15
|
+
if (Array.isArray(x))
|
|
16
|
+
return x.map(sorted);
|
|
17
|
+
if (x && typeof x === 'object')
|
|
18
|
+
return Object.fromEntries(Object.keys(x).sort(byCodePoint).map((k) => [k, sorted(x[k])]));
|
|
19
|
+
return x;
|
|
20
|
+
};
|
|
21
|
+
return JSON.stringify(sorted(v));
|
|
22
|
+
}
|
|
23
|
+
export async function sha256Hex(text) {
|
|
24
|
+
const d = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text));
|
|
25
|
+
return Array.from(new Uint8Array(d), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
26
|
+
}
|
|
27
|
+
const same = (a, b) => {
|
|
28
|
+
if (a === b)
|
|
29
|
+
return true;
|
|
30
|
+
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null)
|
|
31
|
+
return false;
|
|
32
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
33
|
+
return false;
|
|
34
|
+
const ka = Object.keys(a);
|
|
35
|
+
const kb = Object.keys(b);
|
|
36
|
+
return ka.length === kb.length && ka.every((k) => Object.prototype.hasOwnProperty.call(b, k) && same(a[k], b[k]));
|
|
37
|
+
};
|
|
38
|
+
const contractOf = (p) => {
|
|
39
|
+
const c = p.config.execution_contract;
|
|
40
|
+
return c && typeof c.manifest_sha256 === 'string' && c.manifest && typeof c.manifest === 'object' ? c : null;
|
|
41
|
+
};
|
|
42
|
+
/** Known profile ids are readable; approval needs that profile's own bundle facts. */
|
|
43
|
+
const PROFILE_BUNDLE_FACTS = {
|
|
44
|
+
'geo-counts-tools-v1': { bundle_version: RP1_BUNDLE_VERSION, assurance: RP1_SCOPE },
|
|
45
|
+
// Engine 1.2.0 activation: the bundle facts do not depend on the profile bytes (the server picks bundle_version by
|
|
46
|
+
// manifest_version, assurance is a profile-independent constant); the profile id/sha enter only via manifest.restricted_profile.
|
|
47
|
+
'geo-counts-tools-v2': { bundle_version: RP1_BUNDLE_VERSION, assurance: RP1_SCOPE },
|
|
48
|
+
};
|
|
49
|
+
const HEX64 = /^[0-9a-f]{64}$/;
|
|
50
|
+
/**
|
|
51
|
+
* What the engine's first request holds, as the server prepares it from the plan's own contract and prompt (null: this manifest is not one the page can rebuild,
|
|
52
|
+
* so nothing it shows can be bound to it). The manifest's version selects the shape; the shape is never taken from the bundle being checked.
|
|
53
|
+
*/
|
|
54
|
+
const expectedBundle = (c, prompt) => {
|
|
55
|
+
const m = c.manifest;
|
|
56
|
+
const common = {
|
|
57
|
+
stage: 'installed_inventory_only',
|
|
58
|
+
manifest: c.manifest,
|
|
59
|
+
initial_messages: [{ component: 'supervisor', role: 'user', content: prompt }],
|
|
60
|
+
pinned_sources: m.assets ?? null,
|
|
61
|
+
native_request_verified: false,
|
|
62
|
+
};
|
|
63
|
+
if (m.manifest_version === NATIVE_MANIFEST_VERSION)
|
|
64
|
+
return 'restricted_profile' in m ? null : { bundle_version: NATIVE_BUNDLE_VERSION, ...common };
|
|
65
|
+
if (m.manifest_version === RP1_MANIFEST_VERSION) {
|
|
66
|
+
const rp = m.restricted_profile;
|
|
67
|
+
if (!rp || typeof rp !== 'object' || Object.keys(rp).sort().join() !== 'profile_id,sha256' || typeof rp.profile_id !== 'string' || typeof rp.sha256 !== 'string' || !HEX64.test(rp.sha256))
|
|
68
|
+
return null;
|
|
69
|
+
const facts = Object.prototype.hasOwnProperty.call(PROFILE_BUNDLE_FACTS, rp.profile_id) ? PROFILE_BUNDLE_FACTS[rp.profile_id] : null;
|
|
70
|
+
if (!facts)
|
|
71
|
+
return null;
|
|
72
|
+
return { ...facts, restricted_profile: rp, ...common };
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
const scopeOf = (c) => (c.manifest.manifest_version === RP1_MANIFEST_VERSION ? RP1_SCOPE : c.manifest.manifest_version === NATIVE_MANIFEST_VERSION ? NATIVE_SCOPE : null);
|
|
77
|
+
/**
|
|
78
|
+
* 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,
|
|
79
|
+
* not only the words. A plan with no instruction block has nothing to compare (its readiness is the server's `can_execute`).
|
|
80
|
+
*/
|
|
81
|
+
export function instructionsMatch(p) {
|
|
82
|
+
const inst = p.instructions;
|
|
83
|
+
if (!inst)
|
|
84
|
+
return true;
|
|
85
|
+
const c = contractOf(p);
|
|
86
|
+
if (!c || inst.execution_manifest_sha256 !== c.manifest_sha256)
|
|
87
|
+
return false;
|
|
88
|
+
try {
|
|
89
|
+
if (!same(JSON.parse(p.config_json), p.config))
|
|
90
|
+
return false; // the config on screen is the bytes that are hashed
|
|
91
|
+
const want = expectedBundle(c, p.prompt);
|
|
92
|
+
if (want === null || inst.verification_scope !== scopeOf(c))
|
|
93
|
+
return false; // the declared scope is part of what is bound
|
|
94
|
+
if (!same(inst.initial_messages, want.initial_messages))
|
|
95
|
+
return false;
|
|
96
|
+
return same(JSON.parse(inst.instruction_bundle_json), want);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const hashedOf = (p) => {
|
|
103
|
+
const c = contractOf(p);
|
|
104
|
+
return p.instructions && c ? { bundle: p.instructions.instruction_bundle_json, manifest: canonicalJson(c.manifest), config: p.config_json, prompt: p.prompt } : null;
|
|
105
|
+
};
|
|
106
|
+
/** The only asynchronous part: SHA-256 of the four texts. A pure function of those four strings. */
|
|
107
|
+
export async function digestsOf(h) {
|
|
108
|
+
const [bundle, manifest, config, prompt] = await Promise.all([sha256Hex(h.bundle), sha256Hex(h.manifest), sha256Hex(h.config), sha256Hex(h.prompt)]);
|
|
109
|
+
return { bundle, manifest, config, prompt };
|
|
110
|
+
}
|
|
111
|
+
/** Digests compared to the values the page will SEND (and to the contract's): synchronous, so it can never be stale. */
|
|
112
|
+
const digestsAgree = (p, d) => d.bundle === p.instructions.instruction_bundle_sha256 && d.manifest === contractOf(p).manifest_sha256 && d.config === p.config_sha256 && d.prompt === p.prompt_sha256;
|
|
113
|
+
/** The hashes: each recomputed from the bytes held and compared to the value that will be sent. */
|
|
114
|
+
export async function instructionHashesMatch(p) {
|
|
115
|
+
const h = hashedOf(p);
|
|
116
|
+
return h !== null && digestsAgree(p, await digestsOf(h));
|
|
117
|
+
}
|
|
118
|
+
/** 'none': no block. 'pending': being checked (Execute stays off). 'ok' / 'bad': the verdict for THESE inputs. */
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ExecuteCommand } from './vendor/runV1.generated.js';
|
|
2
|
+
export interface PendingContext {
|
|
3
|
+
key: string;
|
|
4
|
+
api_url: string;
|
|
5
|
+
user_id: string;
|
|
6
|
+
org_id: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PendingRecord {
|
|
9
|
+
version: 1;
|
|
10
|
+
entry_id: string;
|
|
11
|
+
attempt_id: string;
|
|
12
|
+
tuple: ExecuteCommand;
|
|
13
|
+
api_url: string;
|
|
14
|
+
user_id: string;
|
|
15
|
+
org_id: string;
|
|
16
|
+
created_at: string;
|
|
17
|
+
}
|
|
18
|
+
export type PendingObservation = {
|
|
19
|
+
kind: 'valid';
|
|
20
|
+
record: PendingRecord;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'malformed';
|
|
23
|
+
bytes: Buffer | null;
|
|
24
|
+
identityMismatch: boolean;
|
|
25
|
+
unsafeReason?: 'oversize' | 'nonregular';
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'absent';
|
|
28
|
+
};
|
|
29
|
+
export declare function validExecuteTuple(v: unknown): v is ExecuteCommand;
|
|
30
|
+
export declare function contextKey(apiUrl: string, userId: string, orgId: string): string;
|
|
31
|
+
export declare function pendingContext(apiUrl: string, userId: string, orgId: string): PendingContext;
|
|
32
|
+
export declare function pendingPath(ctx: PendingContext, entryId: string): string;
|
|
33
|
+
export declare function pendingLockPath(ctx: PendingContext, entryId: string): string;
|
|
34
|
+
/** Capture bounded malformed bytes BEFORE confirmation; never reconstruct them
|
|
35
|
+
* after. Unsafe files cannot be automatically forgotten: inspect them manually.
|
|
36
|
+
*/
|
|
37
|
+
export declare function observe(ctx: PendingContext, entryId: string): Promise<PendingObservation>;
|
|
38
|
+
export declare function read(ctx: PendingContext, entryId: string): Promise<PendingRecord | 'malformed' | null>;
|
|
39
|
+
export declare function claim(ctx: PendingContext, record: PendingRecord): Promise<'claimed' | 'exists' | 'locked'>;
|
|
40
|
+
export declare function release(ctx: PendingContext, entryId: string, tuple: ExecuteCommand, attemptId: string): Promise<'released' | 'kept' | 'locked'>;
|
|
41
|
+
export declare function forget(ctx: PendingContext, entryId: string, observed: PendingObservation): Promise<'forgotten' | 'changed' | 'locked'>;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/** Durable local no-resend ledger. No credentials. Each transition uses an
|
|
2
|
+
* exclusive mkdir mutex; never steal/expire/wait on another process's lock.
|
|
3
|
+
* Threat scope is the user's own non-hostile processes, not hostile same-user
|
|
4
|
+
* writers. A lock spans local I/O only, never HTTP or user confirmation.
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'node:fs/promises';
|
|
7
|
+
import { constants } from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { sameTuple } from './approval.js';
|
|
12
|
+
import { isPromptVersion } from './entries.js';
|
|
13
|
+
const KEYS = ['version', 'entry_id', 'attempt_id', 'tuple', 'api_url', 'user_id', 'org_id', 'created_at'];
|
|
14
|
+
const TUPLE_KEYS = ['config_sha256', 'prompt_sha256', 'execution_manifest_sha256', 'instruction_bundle_sha256', 'expected_revision', 'expected_turn_generation', 'prompt_version'];
|
|
15
|
+
const object = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
16
|
+
const code = (error, value) => object(error) && error.code === value;
|
|
17
|
+
const nonempty = (v) => typeof v === 'string' && v.length > 0;
|
|
18
|
+
function exact(v, keys) { return Object.keys(v).length === keys.length && keys.every(k => Object.hasOwn(v, k)); }
|
|
19
|
+
export function validExecuteTuple(v) {
|
|
20
|
+
return object(v) && exact(v, TUPLE_KEYS) && TUPLE_KEYS.slice(0, 4).every(k => typeof v[k] === 'string' && /^[a-f0-9]{64}$/.test(v[k])) &&
|
|
21
|
+
Number.isInteger(v.expected_revision) && v.expected_revision > 0 && Number.isInteger(v.expected_turn_generation) && v.expected_turn_generation >= 0 && isPromptVersion(v.prompt_version);
|
|
22
|
+
}
|
|
23
|
+
function validRecord(v, entry) {
|
|
24
|
+
return object(v) && exact(v, KEYS) && v.version === 1 && v.entry_id === entry &&
|
|
25
|
+
typeof v.attempt_id === 'string' && /^[a-f0-9]{32}$/.test(v.attempt_id) && validExecuteTuple(v.tuple) &&
|
|
26
|
+
nonempty(v.api_url) && nonempty(v.user_id) && nonempty(v.org_id) && typeof v.created_at === 'string' && Number.isFinite(Date.parse(v.created_at));
|
|
27
|
+
}
|
|
28
|
+
function sameIdentity(v, ctx) { return v.api_url === ctx.api_url && v.user_id === ctx.user_id && v.org_id === ctx.org_id; }
|
|
29
|
+
export function contextKey(apiUrl, userId, orgId) { return createHash('sha256').update([apiUrl, userId, orgId].join('\n'), 'utf8').digest('hex').slice(0, 16); }
|
|
30
|
+
export function pendingContext(apiUrl, userId, orgId) { return { key: contextKey(apiUrl, userId, orgId), api_url: apiUrl, user_id: userId, org_id: orgId }; }
|
|
31
|
+
function validate(ctx, entryId) {
|
|
32
|
+
if (!/^[A-Za-z0-9_-]{1,128}$/.test(entryId))
|
|
33
|
+
throw new Error('Unsafe pending entry locator.');
|
|
34
|
+
if (!ctx || !nonempty(ctx.api_url) || !nonempty(ctx.user_id) || !nonempty(ctx.org_id) || ctx.key !== contextKey(ctx.api_url, ctx.user_id, ctx.org_id))
|
|
35
|
+
throw new Error('Invalid pending account context.');
|
|
36
|
+
}
|
|
37
|
+
export function pendingPath(ctx, entryId) { validate(ctx, entryId); return path.join(os.homedir(), '.config', 'omics-os', 'biovault', 'pending', ctx.key, entryId + '.json'); }
|
|
38
|
+
export function pendingLockPath(ctx, entryId) { return pendingPath(ctx, entryId) + '.lock'; }
|
|
39
|
+
/** Inspect each managed component even for reads; no symlink traversal. */
|
|
40
|
+
async function directories(ctx, create) {
|
|
41
|
+
const parent = path.join(os.homedir(), '.config', 'omics-os');
|
|
42
|
+
if (create)
|
|
43
|
+
await fs.mkdir(parent, { recursive: true, mode: 0o700 });
|
|
44
|
+
for (const name of ['biovault', 'biovault/pending', `biovault/pending/${ctx.key}`]) {
|
|
45
|
+
const dir = path.join(parent, name);
|
|
46
|
+
if (create)
|
|
47
|
+
try {
|
|
48
|
+
await fs.mkdir(dir, { mode: 0o700 });
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
if (!code(e, 'EEXIST'))
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
let stat;
|
|
55
|
+
try {
|
|
56
|
+
stat = await fs.lstat(dir);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (!create && code(e, 'ENOENT'))
|
|
60
|
+
return false;
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
64
|
+
throw new Error('The local start directory is not a real directory.');
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
async function raw(ctx, entry) {
|
|
69
|
+
const file = pendingPath(ctx, entry);
|
|
70
|
+
if (!await directories(ctx, false))
|
|
71
|
+
return null;
|
|
72
|
+
let stat;
|
|
73
|
+
try {
|
|
74
|
+
stat = await fs.lstat(file);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
if (code(e, 'ENOENT'))
|
|
78
|
+
return null;
|
|
79
|
+
throw e;
|
|
80
|
+
}
|
|
81
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
82
|
+
return 'nonregular';
|
|
83
|
+
const limit = 16 * 1024;
|
|
84
|
+
if (stat.size > limit)
|
|
85
|
+
return 'oversize';
|
|
86
|
+
// Re-check the opened inode, and bound the actual read even if it grows after
|
|
87
|
+
// lstat/fstat. Never follow a swapped symlink or capture arbitrary-size bytes.
|
|
88
|
+
let handle;
|
|
89
|
+
try {
|
|
90
|
+
handle = await fs.open(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
if (code(e, 'ELOOP'))
|
|
94
|
+
return 'nonregular';
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const opened = await handle.stat();
|
|
99
|
+
if (!opened.isFile())
|
|
100
|
+
return 'nonregular';
|
|
101
|
+
if (opened.size > limit)
|
|
102
|
+
return 'oversize';
|
|
103
|
+
const buffer = Buffer.alloc(limit + 1);
|
|
104
|
+
let length = 0;
|
|
105
|
+
while (length < buffer.length) {
|
|
106
|
+
const { bytesRead } = await handle.read(buffer, length, buffer.length - length, length);
|
|
107
|
+
if (!bytesRead)
|
|
108
|
+
break;
|
|
109
|
+
length += bytesRead;
|
|
110
|
+
}
|
|
111
|
+
return length > limit ? 'oversize' : buffer.subarray(0, length);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
await handle.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Capture bounded malformed bytes BEFORE confirmation; never reconstruct them
|
|
118
|
+
* after. Unsafe files cannot be automatically forgotten: inspect them manually.
|
|
119
|
+
*/
|
|
120
|
+
export async function observe(ctx, entryId) {
|
|
121
|
+
const bytes = await raw(ctx, entryId);
|
|
122
|
+
if (bytes === null)
|
|
123
|
+
return { kind: 'absent' };
|
|
124
|
+
if (typeof bytes === 'string')
|
|
125
|
+
return { kind: 'malformed', bytes: null, identityMismatch: false, unsafeReason: bytes };
|
|
126
|
+
let value;
|
|
127
|
+
try {
|
|
128
|
+
value = JSON.parse(bytes.toString('utf8'));
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return { kind: 'malformed', bytes, identityMismatch: false };
|
|
132
|
+
}
|
|
133
|
+
// Explicit foreign identity is protected even if other fields are malformed.
|
|
134
|
+
const mismatch = object(value) && ['api_url', 'user_id', 'org_id'].some(key => Object.hasOwn(value, key) && typeof value[key] === 'string' && value[key] !== ctx[key]);
|
|
135
|
+
if (!validRecord(value, entryId) || mismatch)
|
|
136
|
+
return { kind: 'malformed', bytes, identityMismatch: mismatch };
|
|
137
|
+
return { kind: 'valid', record: value };
|
|
138
|
+
}
|
|
139
|
+
export async function read(ctx, entryId) {
|
|
140
|
+
const observed = await observe(ctx, entryId);
|
|
141
|
+
return observed.kind === 'valid' ? observed.record : observed.kind === 'absent' ? null : 'malformed';
|
|
142
|
+
}
|
|
143
|
+
async function mutex(ctx, entryId, operation) {
|
|
144
|
+
const lock = pendingLockPath(ctx, entryId);
|
|
145
|
+
await directories(ctx, true);
|
|
146
|
+
try {
|
|
147
|
+
await fs.mkdir(lock, { mode: 0o700 });
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
if (code(e, 'EEXIST'))
|
|
151
|
+
return 'locked';
|
|
152
|
+
throw e;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return await operation();
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
await fs.rmdir(lock);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export async function claim(ctx, record) {
|
|
162
|
+
validate(ctx, record.entry_id);
|
|
163
|
+
if (!validRecord(record, record.entry_id) || !sameIdentity(record, ctx))
|
|
164
|
+
throw new Error('Invalid local start record.');
|
|
165
|
+
return mutex(ctx, record.entry_id, async () => {
|
|
166
|
+
const file = pendingPath(ctx, record.entry_id);
|
|
167
|
+
let handle;
|
|
168
|
+
try {
|
|
169
|
+
handle = await fs.open(file, 'wx', 0o600);
|
|
170
|
+
}
|
|
171
|
+
catch (e) {
|
|
172
|
+
if (code(e, 'EEXIST'))
|
|
173
|
+
return 'exists';
|
|
174
|
+
throw e;
|
|
175
|
+
}
|
|
176
|
+
// Never remove a partial file on write/fsync/close failure: it blocks resend.
|
|
177
|
+
try {
|
|
178
|
+
await handle.writeFile(JSON.stringify(record) + '\n');
|
|
179
|
+
await handle.sync();
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
await handle.close();
|
|
183
|
+
}
|
|
184
|
+
return 'claimed';
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
export async function release(ctx, entryId, tuple, attemptId) {
|
|
188
|
+
validate(ctx, entryId);
|
|
189
|
+
return mutex(ctx, entryId, async () => {
|
|
190
|
+
const now = await observe(ctx, entryId);
|
|
191
|
+
if (now.kind !== 'valid' || now.record.entry_id !== entryId || now.record.attempt_id !== attemptId || !sameTuple(now.record.tuple, tuple))
|
|
192
|
+
return 'kept';
|
|
193
|
+
await fs.unlink(pendingPath(ctx, entryId));
|
|
194
|
+
return 'released';
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
export async function forget(ctx, entryId, observed) {
|
|
198
|
+
validate(ctx, entryId);
|
|
199
|
+
return mutex(ctx, entryId, async () => {
|
|
200
|
+
const now = await observe(ctx, entryId);
|
|
201
|
+
const same = observed.kind === 'valid' && now.kind === 'valid' && sameIdentity(observed.record, ctx) && observed.record.entry_id === now.record.entry_id && observed.record.attempt_id === now.record.attempt_id && sameTuple(observed.record.tuple, now.record.tuple) ||
|
|
202
|
+
observed.kind === 'malformed' && now.kind === 'malformed' && !observed.identityMismatch && !now.identityMismatch && observed.bytes !== null && now.bytes !== null && observed.bytes.equals(now.bytes);
|
|
203
|
+
if (!same)
|
|
204
|
+
return 'changed';
|
|
205
|
+
await fs.unlink(pendingPath(ctx, entryId));
|
|
206
|
+
return 'forgotten';
|
|
207
|
+
});
|
|
208
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const PRE_COMMIT_REFUSALS: readonly string[];
|
|
2
|
+
export declare const provesNothingCommitted: (code: string | null | undefined) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* For these refusals a re-read of the plan cannot help, because GET returns the STORED preview unchanged (vault_draft_service.py:507) and the refusal is about that
|
|
5
|
+
* stored preview's frozen ceiling revision (vault_approval_v1.py:269). Only a SAVE rebuilds it (vault_draft_service.py:680). The page offers "Save plan again" instead of "Check again".
|
|
6
|
+
*/
|
|
7
|
+
export declare const resavesCeiling: (code: string | null | undefined) => boolean;
|
|
8
|
+
/** Proved raised before the approval was persisted, and fine to press again: the tuple is retired but Execute is NOT turned off. Pinned by tests/unit/preCommitRefusals.test.ts. */
|
|
9
|
+
export declare const PRE_COMMIT_TRY_AGAIN: readonly string[];
|
|
10
|
+
export declare const provesNothingStartedTryAgain: (code: string | null | undefined) => boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const PRE_COMMIT_REFUSALS = ['CEILING_POLICY_UNAVAILABLE', 'INSTRUCTION_MANIFEST_UNAVAILABLE', 'MODEL_POLICY_UNAVAILABLE'];
|
|
2
|
+
export const provesNothingCommitted = (code) => !!code && PRE_COMMIT_REFUSALS.includes(code);
|
|
3
|
+
/**
|
|
4
|
+
* For these refusals a re-read of the plan cannot help, because GET returns the STORED preview unchanged (vault_draft_service.py:507) and the refusal is about that
|
|
5
|
+
* stored preview's frozen ceiling revision (vault_approval_v1.py:269). Only a SAVE rebuilds it (vault_draft_service.py:680). The page offers "Save plan again" instead of "Check again".
|
|
6
|
+
*/
|
|
7
|
+
export const resavesCeiling = (code) => code === 'CEILING_POLICY_UNAVAILABLE';
|
|
8
|
+
/** Proved raised before the approval was persisted, and fine to press again: the tuple is retired but Execute is NOT turned off. Pinned by tests/unit/preCommitRefusals.test.ts. */
|
|
9
|
+
export const PRE_COMMIT_TRY_AGAIN = ['RUN_CAPACITY_REACHED', 'RUN_CAPACITY_UNAVAILABLE'];
|
|
10
|
+
export const provesNothingStartedTryAgain = (code) => !!code && PRE_COMMIT_TRY_AGAIN.includes(code);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const BIOVAULT_CONTRACT: {
|
|
2
|
+
readonly repo: "the-omics-os/lobster-cloud";
|
|
3
|
+
readonly sha: "da3f40ab161bce91ba80d72ddd94015f4a2f448f";
|
|
4
|
+
readonly files: readonly [{
|
|
5
|
+
readonly source: "biovault/src/types/runV1.generated.ts";
|
|
6
|
+
readonly source_sha256: "28247bec0b411a7c3ad9de0e2dd2a3a481fbf6ee02926d9094e28e63346cef3f";
|
|
7
|
+
readonly emitted: "vendor/runV1.generated.ts";
|
|
8
|
+
readonly emitted_sha256: "476f322d92a918818746ed13994b9602aef528f00bf48f32c3970048da035f53";
|
|
9
|
+
}, {
|
|
10
|
+
readonly source: "biovault/src/types/packageDeliveryV1.generated.ts";
|
|
11
|
+
readonly source_sha256: "a9be4e9c7bff519028346f9000f067f7f82bd4e98f5216c7c7e9a90208d5a9c2";
|
|
12
|
+
readonly emitted: "vendor/packageDeliveryV1.generated.ts";
|
|
13
|
+
readonly emitted_sha256: "1635f3ea5a489ee8d67bbf8e16aa348a67374040b6eb87d722abf6dca6c92632";
|
|
14
|
+
}, {
|
|
15
|
+
readonly source: "biovault/src/api/wireShape.ts";
|
|
16
|
+
readonly source_sha256: "1a65b086dbf5a8dc5f0c33d1a1870c845c1a3ad51cc0363d1871e31fa9f4d108";
|
|
17
|
+
readonly emitted: "wireShape.ts";
|
|
18
|
+
readonly emitted_sha256: "997a020cb18f7a80499e946612e328346b6b0e8b6e3c086a3b47340a8d9ba89a";
|
|
19
|
+
}, {
|
|
20
|
+
readonly source: "biovault/src/plan/instructionMatch.ts";
|
|
21
|
+
readonly source_sha256: "2e08e134a195aa825118c267058baaeb3b51ffbe51371d3d019008fcf8ac67fb";
|
|
22
|
+
readonly emitted: "instructionMatch.ts";
|
|
23
|
+
readonly emitted_sha256: "67eba90d6db12fe0c3c8090f7ba8729ccf089abf75b4b3619627bbe4c0bfe102";
|
|
24
|
+
}, {
|
|
25
|
+
readonly source: "biovault/src/plan/assurance.ts";
|
|
26
|
+
readonly source_sha256: "831c6a9edbee17045c60f8650e8a46ea6241ac2a375471d5641b72f57886310a";
|
|
27
|
+
readonly emitted: "assurance.ts";
|
|
28
|
+
readonly emitted_sha256: "11e5450859b587e32a1b81a6f7266c04443324078138caea3d9e7b63089f0948";
|
|
29
|
+
}, {
|
|
30
|
+
readonly source: "biovault/src/plan/approval.ts";
|
|
31
|
+
readonly source_sha256: "c952f166a3e34410df3bbeec52270a72ceb6863e65939bdb2710a9776cef045d";
|
|
32
|
+
readonly emitted: "approval.ts";
|
|
33
|
+
readonly emitted_sha256: "056355bb599b9790e51930296962a09089ff7bbd86b053d89dfa10b3452b3ae8";
|
|
34
|
+
}, {
|
|
35
|
+
readonly source: "biovault/src/plan/preCommit.ts";
|
|
36
|
+
readonly source_sha256: "0861a303484405bd16900e7f547092def27f1c0ee4b5425628093e018b7d760c";
|
|
37
|
+
readonly emitted: "preCommit.ts";
|
|
38
|
+
readonly emitted_sha256: "17f210e7a161ad5e4bf4b2a04815cb2adc5d233f25018b4f8f7dc09a8d5a7056";
|
|
39
|
+
}, {
|
|
40
|
+
readonly source: "biovault/src/plan/fields.ts";
|
|
41
|
+
readonly source_sha256: "9ed12aa918de93eff196ce62a1b684747204c9773f4449dfe134f950ebfe497e";
|
|
42
|
+
readonly emitted: "fields.ts";
|
|
43
|
+
readonly emitted_sha256: "253af9096a18ca059baf8eedba4c357d30edff54e462079235af771106a7c161";
|
|
44
|
+
}];
|
|
45
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Generated by scripts/sync-biovault.mjs. Committed source and emitted-port byte hashes.
|
|
2
|
+
export const BIOVAULT_CONTRACT = {
|
|
3
|
+
"repo": "the-omics-os/lobster-cloud",
|
|
4
|
+
"sha": "da3f40ab161bce91ba80d72ddd94015f4a2f448f",
|
|
5
|
+
"files": [
|
|
6
|
+
{
|
|
7
|
+
"source": "biovault/src/types/runV1.generated.ts",
|
|
8
|
+
"source_sha256": "28247bec0b411a7c3ad9de0e2dd2a3a481fbf6ee02926d9094e28e63346cef3f",
|
|
9
|
+
"emitted": "vendor/runV1.generated.ts",
|
|
10
|
+
"emitted_sha256": "476f322d92a918818746ed13994b9602aef528f00bf48f32c3970048da035f53"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"source": "biovault/src/types/packageDeliveryV1.generated.ts",
|
|
14
|
+
"source_sha256": "a9be4e9c7bff519028346f9000f067f7f82bd4e98f5216c7c7e9a90208d5a9c2",
|
|
15
|
+
"emitted": "vendor/packageDeliveryV1.generated.ts",
|
|
16
|
+
"emitted_sha256": "1635f3ea5a489ee8d67bbf8e16aa348a67374040b6eb87d722abf6dca6c92632"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"source": "biovault/src/api/wireShape.ts",
|
|
20
|
+
"source_sha256": "1a65b086dbf5a8dc5f0c33d1a1870c845c1a3ad51cc0363d1871e31fa9f4d108",
|
|
21
|
+
"emitted": "wireShape.ts",
|
|
22
|
+
"emitted_sha256": "997a020cb18f7a80499e946612e328346b6b0e8b6e3c086a3b47340a8d9ba89a"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"source": "biovault/src/plan/instructionMatch.ts",
|
|
26
|
+
"source_sha256": "2e08e134a195aa825118c267058baaeb3b51ffbe51371d3d019008fcf8ac67fb",
|
|
27
|
+
"emitted": "instructionMatch.ts",
|
|
28
|
+
"emitted_sha256": "67eba90d6db12fe0c3c8090f7ba8729ccf089abf75b4b3619627bbe4c0bfe102"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"source": "biovault/src/plan/assurance.ts",
|
|
32
|
+
"source_sha256": "831c6a9edbee17045c60f8650e8a46ea6241ac2a375471d5641b72f57886310a",
|
|
33
|
+
"emitted": "assurance.ts",
|
|
34
|
+
"emitted_sha256": "11e5450859b587e32a1b81a6f7266c04443324078138caea3d9e7b63089f0948"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"source": "biovault/src/plan/approval.ts",
|
|
38
|
+
"source_sha256": "c952f166a3e34410df3bbeec52270a72ceb6863e65939bdb2710a9776cef045d",
|
|
39
|
+
"emitted": "approval.ts",
|
|
40
|
+
"emitted_sha256": "056355bb599b9790e51930296962a09089ff7bbd86b053d89dfa10b3452b3ae8"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"source": "biovault/src/plan/preCommit.ts",
|
|
44
|
+
"source_sha256": "0861a303484405bd16900e7f547092def27f1c0ee4b5425628093e018b7d760c",
|
|
45
|
+
"emitted": "preCommit.ts",
|
|
46
|
+
"emitted_sha256": "17f210e7a161ad5e4bf4b2a04815cb2adc5d233f25018b4f8f7dc09a8d5a7056"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"source": "biovault/src/plan/fields.ts",
|
|
50
|
+
"source_sha256": "9ed12aa918de93eff196ce62a1b684747204c9773f4449dfe134f950ebfe497e",
|
|
51
|
+
"emitted": "fields.ts",
|
|
52
|
+
"emitted_sha256": "253af9096a18ca059baf8eedba4c357d30edff54e462079235af771106a7c161"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
};
|