orizu 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifact-pull.js +157 -0
- package/dist/help.js +12 -0
- package/dist/index.js +9 -9
- package/package.json +1 -1
- package/src/artifact-pull.ts +203 -0
- package/src/help.ts +12 -0
- package/src/index.ts +9 -10
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner/optimizer artifact pull (symmetric with `runners push` /
|
|
3
|
+
* `optimizers push`): resolve the artifact by id or name, download the
|
|
4
|
+
* content-addressed zip from storage, and extract it into --out. Version
|
|
5
|
+
* metadata is written to .orizu/pull.json — .orizu/ is excluded from artifact
|
|
6
|
+
* zips (see artifact-archive.ts), so a pulled directory re-pushes with an
|
|
7
|
+
* identical content hash.
|
|
8
|
+
*
|
|
9
|
+
* Lives outside index.ts per the CLI index line ratchet (ALI-976): this module
|
|
10
|
+
* owns its own argument parsing and printing via injected io.
|
|
11
|
+
*/
|
|
12
|
+
import { spawnSync } from 'child_process';
|
|
13
|
+
import { createHash } from 'crypto';
|
|
14
|
+
import { mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'fs';
|
|
15
|
+
import { tmpdir } from 'os';
|
|
16
|
+
import { dirname, join } from 'path';
|
|
17
|
+
import { authedFetch } from './http.js';
|
|
18
|
+
// Shared with the runners exec download path in index.ts.
|
|
19
|
+
export const ARTIFACT_MAX_BYTES = 25 * 1024 * 1024;
|
|
20
|
+
function sanitizeTerminalText(value) {
|
|
21
|
+
return String(value).replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, '');
|
|
22
|
+
}
|
|
23
|
+
function expandHomePath(path) {
|
|
24
|
+
if (path.startsWith('~/')) {
|
|
25
|
+
const home = process.env.HOME || '';
|
|
26
|
+
return `${home}/${path.slice(2)}`;
|
|
27
|
+
}
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
function argValue(args, flag) {
|
|
31
|
+
const index = args.indexOf(flag);
|
|
32
|
+
if (index === -1 || index + 1 >= args.length || args[index + 1].startsWith('--')) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return args[index + 1];
|
|
36
|
+
}
|
|
37
|
+
async function parseJsonPayload(response, context) {
|
|
38
|
+
const contentType = response.headers.get('content-type') || '';
|
|
39
|
+
const rawBody = await response.text();
|
|
40
|
+
if (!contentType.includes('application/json')) {
|
|
41
|
+
throw new Error(`${context} returned non-JSON response (status ${response.status}). ` +
|
|
42
|
+
`Body preview: ${sanitizeTerminalText(rawBody.slice(0, 180))}`);
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(rawBody);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
throw new Error(`${context} returned invalid JSON (status ${response.status}). ` +
|
|
49
|
+
`Body preview: ${sanitizeTerminalText(rawBody.slice(0, 180))}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function pullArtifactCommand(args, io) {
|
|
53
|
+
const kind = args[0] === 'runners' ? 'runner' : 'optimizer';
|
|
54
|
+
const fetcher = io.fetcher || authedFetch;
|
|
55
|
+
const positionalRef = args[2];
|
|
56
|
+
const artifactRef = positionalRef && !positionalRef.startsWith('--') ? positionalRef : null;
|
|
57
|
+
const outDir = argValue(args, '--out');
|
|
58
|
+
const label = argValue(args, '--label');
|
|
59
|
+
const version = argValue(args, '--version');
|
|
60
|
+
// Argument errors surface before project resolution, which may prompt
|
|
61
|
+
// interactively when --project is omitted.
|
|
62
|
+
const plural = kind === 'runner' ? 'runners' : 'optimizers';
|
|
63
|
+
if (!artifactRef || !outDir) {
|
|
64
|
+
throw new Error(`Usage: orizu ${plural} pull <${kind}-id-or-name> --project <team/project> --out <dir> [--label <label> | --version <version-id>] [--json]`);
|
|
65
|
+
}
|
|
66
|
+
if (label && version) {
|
|
67
|
+
throw new Error('Use either --label or --version, not both');
|
|
68
|
+
}
|
|
69
|
+
const project = argValue(args, '--project') || await io.resolveProjectSlug(null);
|
|
70
|
+
const params = new URLSearchParams({ project });
|
|
71
|
+
if (label)
|
|
72
|
+
params.set('label', label);
|
|
73
|
+
if (version)
|
|
74
|
+
params.set('version', version);
|
|
75
|
+
const response = await fetcher(`/api/cli/${plural}/${encodeURIComponent(artifactRef)}?${params.toString()}`);
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
throw new Error(`Failed to pull ${kind}: ${await response.text()}`);
|
|
78
|
+
}
|
|
79
|
+
const data = await parseJsonPayload(response, `${kind} pull`);
|
|
80
|
+
const artifact = kind === 'runner' ? data.runner : data.optimizer;
|
|
81
|
+
if (!artifact) {
|
|
82
|
+
throw new Error(`Failed to pull ${kind}: malformed response`);
|
|
83
|
+
}
|
|
84
|
+
// Every stored version is content-addressed; a missing hash would silently
|
|
85
|
+
// void the integrity check and the pull.json anchor, so fail instead.
|
|
86
|
+
if (!data.version.contentSha256) {
|
|
87
|
+
throw new Error(`Failed to pull ${kind}: version ${data.version.id} has no content hash`);
|
|
88
|
+
}
|
|
89
|
+
const downloadResponse = await fetcher(`/api/cli/${kind}-versions/${encodeURIComponent(data.version.id)}/download`);
|
|
90
|
+
if (!downloadResponse.ok) {
|
|
91
|
+
throw new Error(`Failed to download ${kind} artifact: ${await downloadResponse.text()}`);
|
|
92
|
+
}
|
|
93
|
+
const zipBytes = new Uint8Array(await downloadResponse.arrayBuffer());
|
|
94
|
+
if (zipBytes.byteLength > ARTIFACT_MAX_BYTES) {
|
|
95
|
+
throw new Error(`${kind} artifact exceeds ${ARTIFACT_MAX_BYTES} bytes`);
|
|
96
|
+
}
|
|
97
|
+
// Versions are content-addressed by zip SHA256 (see the push routes), so a
|
|
98
|
+
// corrupted or mismatched download is detectable before anything is written.
|
|
99
|
+
const actualSha256 = createHash('sha256').update(zipBytes).digest('hex');
|
|
100
|
+
if (actualSha256 !== data.version.contentSha256.toLowerCase()) {
|
|
101
|
+
throw new Error(`${kind} artifact hash mismatch: expected ${data.version.contentSha256}, got ${actualSha256}`);
|
|
102
|
+
}
|
|
103
|
+
// Extraction is additive, so a dirty directory would mix files from other
|
|
104
|
+
// versions and break the pull -> identical re-push hash guarantee.
|
|
105
|
+
const targetDir = expandHomePath(outDir);
|
|
106
|
+
mkdirSync(targetDir, { recursive: true });
|
|
107
|
+
if (readdirSync(targetDir).length > 0) {
|
|
108
|
+
throw new Error(`Output directory is not empty: ${targetDir}`);
|
|
109
|
+
}
|
|
110
|
+
const tempDir = mkdtempSync(join(tmpdir(), `orizu-${kind}-pull-`));
|
|
111
|
+
try {
|
|
112
|
+
const zipPath = join(tempDir, 'artifact.zip');
|
|
113
|
+
writeFileSync(zipPath, zipBytes);
|
|
114
|
+
// Artifacts are self-authored, hash-verified above, and served only to
|
|
115
|
+
// authenticated project members; Info-ZIP additionally strips ../ path
|
|
116
|
+
// components on extraction (same trust model as materializeRunnerVersion).
|
|
117
|
+
const result = spawnSync('unzip', ['-q', zipPath, '-d', targetDir], {
|
|
118
|
+
encoding: 'utf8',
|
|
119
|
+
});
|
|
120
|
+
if (result.error || result.status !== 0) {
|
|
121
|
+
// targetDir was verified empty above, so everything in it came from
|
|
122
|
+
// this extraction — clear it so a re-pull isn't rejected as non-empty.
|
|
123
|
+
for (const entry of readdirSync(targetDir)) {
|
|
124
|
+
rmSync(join(targetDir, entry), { recursive: true, force: true });
|
|
125
|
+
}
|
|
126
|
+
if (result.error) {
|
|
127
|
+
throw result.error;
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`unzip failed: ${sanitizeTerminalText(result.stderr || result.stdout || '')}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
134
|
+
}
|
|
135
|
+
const versionLabels = (data.labels || [])
|
|
136
|
+
.filter(item => (kind === 'runner' ? item.runnerVersionId : item.optimizerVersionId) === data.version.id)
|
|
137
|
+
.map(item => item.label);
|
|
138
|
+
const pullMetadataPath = join(targetDir, '.orizu', 'pull.json');
|
|
139
|
+
mkdirSync(dirname(pullMetadataPath), { recursive: true });
|
|
140
|
+
writeFileSync(pullMetadataPath, `${JSON.stringify({
|
|
141
|
+
schema_version: `orizu.${kind}-pull.v1`,
|
|
142
|
+
name: artifact.name,
|
|
143
|
+
[`${kind}_id`]: artifact.id,
|
|
144
|
+
version_id: data.version.id,
|
|
145
|
+
content_sha256: data.version.contentSha256,
|
|
146
|
+
labels: versionLabels,
|
|
147
|
+
}, null, 2)}\n`);
|
|
148
|
+
if (io.json) {
|
|
149
|
+
io.print(JSON.stringify({
|
|
150
|
+
[`${kind}_id`]: artifact.id,
|
|
151
|
+
[`${kind}_version_id`]: data.version.id,
|
|
152
|
+
path: targetDir,
|
|
153
|
+
}));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
io.print(`Pulled ${kind} ${sanitizeTerminalText(artifact.name)} to ${sanitizeTerminalText(targetDir)}`);
|
|
157
|
+
}
|
package/dist/help.js
CHANGED
|
@@ -344,6 +344,12 @@ export const COMMAND_DOCS = [
|
|
|
344
344
|
summary: 'Push a local runner artifact directory.',
|
|
345
345
|
group: 'Scorers and runners',
|
|
346
346
|
},
|
|
347
|
+
{
|
|
348
|
+
path: ['runners', 'pull'],
|
|
349
|
+
usage: 'orizu runners pull <runner-id-or-name> --project <team/project> --out <dir> [--label <label> | --version <version-id>] [--json]',
|
|
350
|
+
summary: 'Pull a runner artifact version to a local directory.',
|
|
351
|
+
group: 'Scorers and runners',
|
|
352
|
+
},
|
|
347
353
|
{
|
|
348
354
|
path: ['runners', 'exec'],
|
|
349
355
|
usage: 'orizu runners exec (--prompt <prompt-version-id> | --prompt-version <id> --runner-version <id> | --scorer-version <id>) --dataset-version <id> --split-set <id-or-name> --split <name> [--runner-dir <dir>] --out <results.jsonl|results.jsonl.gz>',
|
|
@@ -356,6 +362,12 @@ export const COMMAND_DOCS = [
|
|
|
356
362
|
summary: 'Push a local optimizer artifact directory.',
|
|
357
363
|
group: 'Optimizations',
|
|
358
364
|
},
|
|
365
|
+
{
|
|
366
|
+
path: ['optimizers', 'pull'],
|
|
367
|
+
usage: 'orizu optimizers pull <optimizer-id-or-name> --project <team/project> --out <dir> [--label <label> | --version <version-id>] [--json]',
|
|
368
|
+
summary: 'Pull an optimizer artifact version to a local directory.',
|
|
369
|
+
group: 'Optimizations',
|
|
370
|
+
},
|
|
359
371
|
{
|
|
360
372
|
path: ['runs', 'submit'],
|
|
361
373
|
usage: 'orizu runs submit <results.jsonl|results.jsonl.gz> --prompt-version <id> --runner-version <id> --dataset-version <id> --split-set <id> --split <name> [--project <team/project>]',
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { formatTaskCreateError } from './task-create-error.js';
|
|
|
27
27
|
import { renderAgentSetupPrompt } from './setup-prompt.js';
|
|
28
28
|
import { getWorkspaceRoot, initOrizuWorkspace, workspaceExists, } from './workspace.js';
|
|
29
29
|
import { connectorsCommand } from './connectors-cli.js';
|
|
30
|
+
import { ARTIFACT_MAX_BYTES, pullArtifactCommand } from './artifact-pull.js';
|
|
30
31
|
import { killSwitchCommand } from './kill-switch-cli.js';
|
|
31
32
|
import { egressAllowlistCommand } from './egress-allowlist-cli.js';
|
|
32
33
|
import { manifestsCommand } from './manifests-cli.js';
|
|
@@ -4595,7 +4596,6 @@ function readRunnerManifest(runnerDir) {
|
|
|
4595
4596
|
}
|
|
4596
4597
|
const RUNNER_TIMEOUT_MS = 120_000;
|
|
4597
4598
|
const RUNNER_OUTPUT_MAX_BYTES = 2 * 1024 * 1024;
|
|
4598
|
-
const RUNNER_ARTIFACT_MAX_BYTES = 25 * 1024 * 1024;
|
|
4599
4599
|
const RUNNER_ENV_ALLOWLIST = new Set([
|
|
4600
4600
|
'PATH',
|
|
4601
4601
|
'SystemRoot',
|
|
@@ -4643,9 +4643,9 @@ async function materializeRunnerVersion(runnerVersionId) {
|
|
|
4643
4643
|
const zipPath = join(tempDir, 'runner.zip');
|
|
4644
4644
|
const runnerDir = join(tempDir, 'runner');
|
|
4645
4645
|
const zipBytes = new Uint8Array(await response.arrayBuffer());
|
|
4646
|
-
if (zipBytes.byteLength >
|
|
4646
|
+
if (zipBytes.byteLength > ARTIFACT_MAX_BYTES) {
|
|
4647
4647
|
rmSync(tempDir, { recursive: true, force: true });
|
|
4648
|
-
throw new Error(`Runner artifact exceeds ${
|
|
4648
|
+
throw new Error(`Runner artifact exceeds ${ARTIFACT_MAX_BYTES} bytes`);
|
|
4649
4649
|
}
|
|
4650
4650
|
writeFileSync(zipPath, zipBytes);
|
|
4651
4651
|
const result = spawnSync('unzip', ['-q', zipPath, '-d', runnerDir], {
|
|
@@ -4997,16 +4997,16 @@ export async function main(rawArgs = process.argv.slice(2)) {
|
|
|
4997
4997
|
await execScorer();
|
|
4998
4998
|
return;
|
|
4999
4999
|
}
|
|
5000
|
-
if (command === 'runners' && subcommand === 'push') {
|
|
5001
|
-
await pushRunnerArtifact('runner');
|
|
5000
|
+
if ((command === 'runners' || command === 'optimizers') && subcommand === 'push') {
|
|
5001
|
+
await pushRunnerArtifact(command === 'runners' ? 'runner' : 'optimizer');
|
|
5002
5002
|
return;
|
|
5003
5003
|
}
|
|
5004
|
-
if (command === 'runners' && subcommand === '
|
|
5005
|
-
await
|
|
5004
|
+
if ((command === 'runners' || command === 'optimizers') && subcommand === 'pull') {
|
|
5005
|
+
await pullArtifactCommand(cliArgs, { json: hasJsonFlag(), print: printLine, resolveProjectSlug });
|
|
5006
5006
|
return;
|
|
5007
5007
|
}
|
|
5008
|
-
if (command === '
|
|
5009
|
-
await
|
|
5008
|
+
if (command === 'runners' && subcommand === 'exec') {
|
|
5009
|
+
await runnersExec();
|
|
5010
5010
|
return;
|
|
5011
5011
|
}
|
|
5012
5012
|
if (command === 'runs' && subcommand === 'submit') {
|
package/package.json
CHANGED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runner/optimizer artifact pull (symmetric with `runners push` /
|
|
3
|
+
* `optimizers push`): resolve the artifact by id or name, download the
|
|
4
|
+
* content-addressed zip from storage, and extract it into --out. Version
|
|
5
|
+
* metadata is written to .orizu/pull.json — .orizu/ is excluded from artifact
|
|
6
|
+
* zips (see artifact-archive.ts), so a pulled directory re-pushes with an
|
|
7
|
+
* identical content hash.
|
|
8
|
+
*
|
|
9
|
+
* Lives outside index.ts per the CLI index line ratchet (ALI-976): this module
|
|
10
|
+
* owns its own argument parsing and printing via injected io.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { spawnSync } from 'child_process'
|
|
14
|
+
import { createHash } from 'crypto'
|
|
15
|
+
import { mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'fs'
|
|
16
|
+
import { tmpdir } from 'os'
|
|
17
|
+
import { dirname, join } from 'path'
|
|
18
|
+
|
|
19
|
+
import { authedFetch } from './http.js'
|
|
20
|
+
|
|
21
|
+
export type PullableArtifactKind = 'runner' | 'optimizer'
|
|
22
|
+
|
|
23
|
+
export interface PullArtifactIo {
|
|
24
|
+
json: boolean
|
|
25
|
+
print: (line: string) => void
|
|
26
|
+
resolveProjectSlug: (projectArg: string | null) => Promise<string>
|
|
27
|
+
fetcher?: (path: string, init?: RequestInit) => Promise<Response>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Shared with the runners exec download path in index.ts.
|
|
31
|
+
export const ARTIFACT_MAX_BYTES = 25 * 1024 * 1024
|
|
32
|
+
|
|
33
|
+
function sanitizeTerminalText(value: unknown): string {
|
|
34
|
+
return String(value).replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, '')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function expandHomePath(path: string): string {
|
|
38
|
+
if (path.startsWith('~/')) {
|
|
39
|
+
const home = process.env.HOME || ''
|
|
40
|
+
return `${home}/${path.slice(2)}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return path
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function argValue(args: string[], flag: string): string | null {
|
|
47
|
+
const index = args.indexOf(flag)
|
|
48
|
+
if (index === -1 || index + 1 >= args.length || args[index + 1].startsWith('--')) {
|
|
49
|
+
return null
|
|
50
|
+
}
|
|
51
|
+
return args[index + 1]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function parseJsonPayload<T>(response: Response, context: string): Promise<T> {
|
|
55
|
+
const contentType = response.headers.get('content-type') || ''
|
|
56
|
+
const rawBody = await response.text()
|
|
57
|
+
|
|
58
|
+
if (!contentType.includes('application/json')) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`${context} returned non-JSON response (status ${response.status}). ` +
|
|
61
|
+
`Body preview: ${sanitizeTerminalText(rawBody.slice(0, 180))}`
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(rawBody) as T
|
|
67
|
+
} catch {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`${context} returned invalid JSON (status ${response.status}). ` +
|
|
70
|
+
`Body preview: ${sanitizeTerminalText(rawBody.slice(0, 180))}`
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface PullArtifactResponse {
|
|
76
|
+
runner?: { id: string; name: string }
|
|
77
|
+
optimizer?: { id: string; name: string }
|
|
78
|
+
version: {
|
|
79
|
+
id: string
|
|
80
|
+
contentSha256?: string
|
|
81
|
+
manifest?: Record<string, unknown>
|
|
82
|
+
uploadedAt?: string
|
|
83
|
+
}
|
|
84
|
+
labels?: Array<{ label: string; runnerVersionId?: string; optimizerVersionId?: string }>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function pullArtifactCommand(args: string[], io: PullArtifactIo) {
|
|
88
|
+
const kind: PullableArtifactKind = args[0] === 'runners' ? 'runner' : 'optimizer'
|
|
89
|
+
const fetcher = io.fetcher || authedFetch
|
|
90
|
+
const positionalRef = args[2]
|
|
91
|
+
const artifactRef = positionalRef && !positionalRef.startsWith('--') ? positionalRef : null
|
|
92
|
+
const outDir = argValue(args, '--out')
|
|
93
|
+
const label = argValue(args, '--label')
|
|
94
|
+
const version = argValue(args, '--version')
|
|
95
|
+
|
|
96
|
+
// Argument errors surface before project resolution, which may prompt
|
|
97
|
+
// interactively when --project is omitted.
|
|
98
|
+
const plural = kind === 'runner' ? 'runners' : 'optimizers'
|
|
99
|
+
if (!artifactRef || !outDir) {
|
|
100
|
+
throw new Error(`Usage: orizu ${plural} pull <${kind}-id-or-name> --project <team/project> --out <dir> [--label <label> | --version <version-id>] [--json]`)
|
|
101
|
+
}
|
|
102
|
+
if (label && version) {
|
|
103
|
+
throw new Error('Use either --label or --version, not both')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const project = argValue(args, '--project') || await io.resolveProjectSlug(null)
|
|
107
|
+
|
|
108
|
+
const params = new URLSearchParams({ project })
|
|
109
|
+
if (label) params.set('label', label)
|
|
110
|
+
if (version) params.set('version', version)
|
|
111
|
+
|
|
112
|
+
const response = await fetcher(`/api/cli/${plural}/${encodeURIComponent(artifactRef)}?${params.toString()}`)
|
|
113
|
+
if (!response.ok) {
|
|
114
|
+
throw new Error(`Failed to pull ${kind}: ${await response.text()}`)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const data = await parseJsonPayload<PullArtifactResponse>(response, `${kind} pull`)
|
|
118
|
+
const artifact = kind === 'runner' ? data.runner : data.optimizer
|
|
119
|
+
if (!artifact) {
|
|
120
|
+
throw new Error(`Failed to pull ${kind}: malformed response`)
|
|
121
|
+
}
|
|
122
|
+
// Every stored version is content-addressed; a missing hash would silently
|
|
123
|
+
// void the integrity check and the pull.json anchor, so fail instead.
|
|
124
|
+
if (!data.version.contentSha256) {
|
|
125
|
+
throw new Error(`Failed to pull ${kind}: version ${data.version.id} has no content hash`)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const downloadResponse = await fetcher(`/api/cli/${kind}-versions/${encodeURIComponent(data.version.id)}/download`)
|
|
129
|
+
if (!downloadResponse.ok) {
|
|
130
|
+
throw new Error(`Failed to download ${kind} artifact: ${await downloadResponse.text()}`)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const zipBytes = new Uint8Array(await downloadResponse.arrayBuffer())
|
|
134
|
+
if (zipBytes.byteLength > ARTIFACT_MAX_BYTES) {
|
|
135
|
+
throw new Error(`${kind} artifact exceeds ${ARTIFACT_MAX_BYTES} bytes`)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Versions are content-addressed by zip SHA256 (see the push routes), so a
|
|
139
|
+
// corrupted or mismatched download is detectable before anything is written.
|
|
140
|
+
const actualSha256 = createHash('sha256').update(zipBytes).digest('hex')
|
|
141
|
+
if (actualSha256 !== data.version.contentSha256.toLowerCase()) {
|
|
142
|
+
throw new Error(`${kind} artifact hash mismatch: expected ${data.version.contentSha256}, got ${actualSha256}`)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Extraction is additive, so a dirty directory would mix files from other
|
|
146
|
+
// versions and break the pull -> identical re-push hash guarantee.
|
|
147
|
+
const targetDir = expandHomePath(outDir)
|
|
148
|
+
mkdirSync(targetDir, { recursive: true })
|
|
149
|
+
if (readdirSync(targetDir).length > 0) {
|
|
150
|
+
throw new Error(`Output directory is not empty: ${targetDir}`)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const tempDir = mkdtempSync(join(tmpdir(), `orizu-${kind}-pull-`))
|
|
154
|
+
try {
|
|
155
|
+
const zipPath = join(tempDir, 'artifact.zip')
|
|
156
|
+
writeFileSync(zipPath, zipBytes)
|
|
157
|
+
// Artifacts are self-authored, hash-verified above, and served only to
|
|
158
|
+
// authenticated project members; Info-ZIP additionally strips ../ path
|
|
159
|
+
// components on extraction (same trust model as materializeRunnerVersion).
|
|
160
|
+
const result = spawnSync('unzip', ['-q', zipPath, '-d', targetDir], {
|
|
161
|
+
encoding: 'utf8',
|
|
162
|
+
})
|
|
163
|
+
if (result.error || result.status !== 0) {
|
|
164
|
+
// targetDir was verified empty above, so everything in it came from
|
|
165
|
+
// this extraction — clear it so a re-pull isn't rejected as non-empty.
|
|
166
|
+
for (const entry of readdirSync(targetDir)) {
|
|
167
|
+
rmSync(join(targetDir, entry), { recursive: true, force: true })
|
|
168
|
+
}
|
|
169
|
+
if (result.error) {
|
|
170
|
+
throw result.error
|
|
171
|
+
}
|
|
172
|
+
throw new Error(`unzip failed: ${sanitizeTerminalText(result.stderr || result.stdout || '')}`)
|
|
173
|
+
}
|
|
174
|
+
} finally {
|
|
175
|
+
rmSync(tempDir, { recursive: true, force: true })
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const versionLabels = (data.labels || [])
|
|
179
|
+
.filter(item => (kind === 'runner' ? item.runnerVersionId : item.optimizerVersionId) === data.version.id)
|
|
180
|
+
.map(item => item.label)
|
|
181
|
+
|
|
182
|
+
const pullMetadataPath = join(targetDir, '.orizu', 'pull.json')
|
|
183
|
+
mkdirSync(dirname(pullMetadataPath), { recursive: true })
|
|
184
|
+
writeFileSync(pullMetadataPath, `${JSON.stringify({
|
|
185
|
+
schema_version: `orizu.${kind}-pull.v1`,
|
|
186
|
+
name: artifact.name,
|
|
187
|
+
[`${kind}_id`]: artifact.id,
|
|
188
|
+
version_id: data.version.id,
|
|
189
|
+
content_sha256: data.version.contentSha256,
|
|
190
|
+
labels: versionLabels,
|
|
191
|
+
}, null, 2)}\n`)
|
|
192
|
+
|
|
193
|
+
if (io.json) {
|
|
194
|
+
io.print(JSON.stringify({
|
|
195
|
+
[`${kind}_id`]: artifact.id,
|
|
196
|
+
[`${kind}_version_id`]: data.version.id,
|
|
197
|
+
path: targetDir,
|
|
198
|
+
}))
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
io.print(`Pulled ${kind} ${sanitizeTerminalText(artifact.name)} to ${sanitizeTerminalText(targetDir)}`)
|
|
203
|
+
}
|
package/src/help.ts
CHANGED
|
@@ -369,6 +369,12 @@ export const COMMAND_DOCS: CliCommandDoc[] = [
|
|
|
369
369
|
summary: 'Push a local runner artifact directory.',
|
|
370
370
|
group: 'Scorers and runners',
|
|
371
371
|
},
|
|
372
|
+
{
|
|
373
|
+
path: ['runners', 'pull'],
|
|
374
|
+
usage: 'orizu runners pull <runner-id-or-name> --project <team/project> --out <dir> [--label <label> | --version <version-id>] [--json]',
|
|
375
|
+
summary: 'Pull a runner artifact version to a local directory.',
|
|
376
|
+
group: 'Scorers and runners',
|
|
377
|
+
},
|
|
372
378
|
{
|
|
373
379
|
path: ['runners', 'exec'],
|
|
374
380
|
usage: 'orizu runners exec (--prompt <prompt-version-id> | --prompt-version <id> --runner-version <id> | --scorer-version <id>) --dataset-version <id> --split-set <id-or-name> --split <name> [--runner-dir <dir>] --out <results.jsonl|results.jsonl.gz>',
|
|
@@ -381,6 +387,12 @@ export const COMMAND_DOCS: CliCommandDoc[] = [
|
|
|
381
387
|
summary: 'Push a local optimizer artifact directory.',
|
|
382
388
|
group: 'Optimizations',
|
|
383
389
|
},
|
|
390
|
+
{
|
|
391
|
+
path: ['optimizers', 'pull'],
|
|
392
|
+
usage: 'orizu optimizers pull <optimizer-id-or-name> --project <team/project> --out <dir> [--label <label> | --version <version-id>] [--json]',
|
|
393
|
+
summary: 'Pull an optimizer artifact version to a local directory.',
|
|
394
|
+
group: 'Optimizations',
|
|
395
|
+
},
|
|
384
396
|
{
|
|
385
397
|
path: ['runs', 'submit'],
|
|
386
398
|
usage: 'orizu runs submit <results.jsonl|results.jsonl.gz> --prompt-version <id> --runner-version <id> --dataset-version <id> --split-set <id> --split <name> [--project <team/project>]',
|
package/src/index.ts
CHANGED
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
workspaceExists,
|
|
60
60
|
} from './workspace.js'
|
|
61
61
|
import { connectorsCommand } from './connectors-cli.js'
|
|
62
|
+
import { ARTIFACT_MAX_BYTES, pullArtifactCommand } from './artifact-pull.js'
|
|
62
63
|
import { killSwitchCommand } from './kill-switch-cli.js'
|
|
63
64
|
import { egressAllowlistCommand } from './egress-allowlist-cli.js'
|
|
64
65
|
import { manifestsCommand } from './manifests-cli.js'
|
|
@@ -5994,7 +5995,6 @@ function readRunnerManifest(runnerDir: string): { command: string[]; supports_bo
|
|
|
5994
5995
|
|
|
5995
5996
|
const RUNNER_TIMEOUT_MS = 120_000
|
|
5996
5997
|
const RUNNER_OUTPUT_MAX_BYTES = 2 * 1024 * 1024
|
|
5997
|
-
const RUNNER_ARTIFACT_MAX_BYTES = 25 * 1024 * 1024
|
|
5998
5998
|
const RUNNER_ENV_ALLOWLIST = new Set([
|
|
5999
5999
|
'PATH',
|
|
6000
6000
|
'SystemRoot',
|
|
@@ -6045,9 +6045,9 @@ async function materializeRunnerVersion(runnerVersionId: string): Promise<{ runn
|
|
|
6045
6045
|
const zipPath = join(tempDir, 'runner.zip')
|
|
6046
6046
|
const runnerDir = join(tempDir, 'runner')
|
|
6047
6047
|
const zipBytes = new Uint8Array(await response.arrayBuffer())
|
|
6048
|
-
if (zipBytes.byteLength >
|
|
6048
|
+
if (zipBytes.byteLength > ARTIFACT_MAX_BYTES) {
|
|
6049
6049
|
rmSync(tempDir, { recursive: true, force: true })
|
|
6050
|
-
throw new Error(`Runner artifact exceeds ${
|
|
6050
|
+
throw new Error(`Runner artifact exceeds ${ARTIFACT_MAX_BYTES} bytes`)
|
|
6051
6051
|
}
|
|
6052
6052
|
writeFileSync(zipPath, zipBytes)
|
|
6053
6053
|
|
|
@@ -6462,18 +6462,17 @@ export async function main(rawArgs = process.argv.slice(2)) {
|
|
|
6462
6462
|
return
|
|
6463
6463
|
}
|
|
6464
6464
|
|
|
6465
|
-
if (command === 'runners' && subcommand === 'push') {
|
|
6466
|
-
await pushRunnerArtifact('runner')
|
|
6465
|
+
if ((command === 'runners' || command === 'optimizers') && subcommand === 'push') {
|
|
6466
|
+
await pushRunnerArtifact(command === 'runners' ? 'runner' : 'optimizer')
|
|
6467
6467
|
return
|
|
6468
6468
|
}
|
|
6469
6469
|
|
|
6470
|
-
if (command === 'runners' && subcommand === '
|
|
6471
|
-
await
|
|
6472
|
-
return
|
|
6470
|
+
if ((command === 'runners' || command === 'optimizers') && subcommand === 'pull') {
|
|
6471
|
+
await pullArtifactCommand(cliArgs, { json: hasJsonFlag(), print: printLine, resolveProjectSlug }); return
|
|
6473
6472
|
}
|
|
6474
6473
|
|
|
6475
|
-
if (command === '
|
|
6476
|
-
await
|
|
6474
|
+
if (command === 'runners' && subcommand === 'exec') {
|
|
6475
|
+
await runnersExec()
|
|
6477
6476
|
return
|
|
6478
6477
|
}
|
|
6479
6478
|
|