htchry 0.0.2 → 0.0.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/README.md +10 -0
- package/dist/cli.js +275 -126
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,16 @@ cd my-task
|
|
|
22
22
|
|
|
23
23
|
`init` creates a task with instructions, an environment, a reference solution, and a verifier.
|
|
24
24
|
|
|
25
|
+
## Run locally or on Hatchery
|
|
26
|
+
|
|
27
|
+
`hatchery run --path . --agent oracle` runs the task locally. Add `--remote` to push the task and run that exact revision on Hatchery using your selected project:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
hatchery run --path . --agent oracle --remote --project your-project-id
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The command waits for the remote job. The job continues if you close the terminal. Use named project secrets with `--secret NAME` when the agent needs credentials.
|
|
34
|
+
|
|
25
35
|
## Pull project tasks
|
|
26
36
|
|
|
27
37
|
Download every task's latest revision into an empty working directory:
|
package/dist/cli.js
CHANGED
|
@@ -14131,9 +14131,17 @@ var parseCommand = (spec, argv) => {
|
|
|
14131
14131
|
const ordered = [];
|
|
14132
14132
|
let rest = false;
|
|
14133
14133
|
for (let index = 0;index < argv.length; index += 1) {
|
|
14134
|
-
const
|
|
14135
|
-
if (
|
|
14134
|
+
const raw = argv[index];
|
|
14135
|
+
if (raw === undefined)
|
|
14136
14136
|
continue;
|
|
14137
|
+
let argument = raw;
|
|
14138
|
+
if (!rest && /^-[^-]$/.test(raw)) {
|
|
14139
|
+
const short = raw.slice(1);
|
|
14140
|
+
const name = spec.shortOptions?.[short];
|
|
14141
|
+
if (name === undefined)
|
|
14142
|
+
throw new UsageError(`unknown option -${short}`, spec.name);
|
|
14143
|
+
argument = `--${name}`;
|
|
14144
|
+
}
|
|
14137
14145
|
if (rest || !argument.startsWith("--")) {
|
|
14138
14146
|
positional.push(argument);
|
|
14139
14147
|
continue;
|
|
@@ -15025,6 +15033,12 @@ var runBridge = async (command, request, options) => {
|
|
|
15025
15033
|
child.stdin.end(JSON.stringify(request));
|
|
15026
15034
|
});
|
|
15027
15035
|
};
|
|
15036
|
+
async function filterHarborPackageNames(names, taskNames, excludeTaskNames, options) {
|
|
15037
|
+
const response = object(await runBridge("filter-tasks", { names, task_names: taskNames, exclude_task_names: excludeTaskNames }, options), "Harbor task filter response");
|
|
15038
|
+
if (response.harborVersion !== HARBOR_VERSION || !Array.isArray(response.names) || response.names.some((name) => typeof name !== "string"))
|
|
15039
|
+
throw new Error("Harbor task filter response is invalid");
|
|
15040
|
+
return response.names;
|
|
15041
|
+
}
|
|
15028
15042
|
var object = (value, label) => {
|
|
15029
15043
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
15030
15044
|
throw new Error(`${label} must be a JSON object`);
|
|
@@ -15355,7 +15369,7 @@ function configuredTaskBinding(binding, parsed) {
|
|
|
15355
15369
|
|
|
15356
15370
|
// apps/cli/src/harbor-runtime.ts
|
|
15357
15371
|
import { rmSync as rmSync2 } from "fs";
|
|
15358
|
-
import { chmod as chmod4, lstat as lstat7, mkdtemp as mkdtemp4, readdir as readdir6, rename as rename4, rm as rm5, writeFile as writeFile6 } from "fs/promises";
|
|
15372
|
+
import { chmod as chmod4, lstat as lstat7, mkdtemp as mkdtemp4, readFile as readFile14, readdir as readdir6, rename as rename4, rm as rm5, writeFile as writeFile6 } from "fs/promises";
|
|
15359
15373
|
import { tmpdir as tmpdir3 } from "os";
|
|
15360
15374
|
import { join as join20, resolve as resolve15 } from "path";
|
|
15361
15375
|
|
|
@@ -16440,7 +16454,7 @@ var materializeTask = async (context, project, root, id, revision, expectedDiges
|
|
|
16440
16454
|
throw new Error(`${label} names ${file.path} as ${file.digest} with ${file.size} bytes, and the repository returned ${actual} with ${size} bytes.`);
|
|
16441
16455
|
bytes += size;
|
|
16442
16456
|
}
|
|
16443
|
-
return { source: { kind: "task", id, revision, digest: stored.digest },
|
|
16457
|
+
return { source: { kind: "task", id, revision, digest: stored.digest }, directory, name, files: files.length, bytes };
|
|
16444
16458
|
};
|
|
16445
16459
|
var materializeRevision = async (context, project, kind, id, revision, root, expectedDigest) => {
|
|
16446
16460
|
if (kind === "task") {
|
|
@@ -51890,6 +51904,9 @@ var harborRunOptions = {
|
|
|
51890
51904
|
dataset: "value",
|
|
51891
51905
|
revision: "value",
|
|
51892
51906
|
"revision-digest": "value",
|
|
51907
|
+
"include-task-name": "list",
|
|
51908
|
+
"exclude-task-name": "list",
|
|
51909
|
+
"task-names-file": "value",
|
|
51893
51910
|
env: "value",
|
|
51894
51911
|
agent: "value",
|
|
51895
51912
|
model: "value",
|
|
@@ -51900,6 +51917,8 @@ var harborRunOptions = {
|
|
|
51900
51917
|
"idempotency-key": "value",
|
|
51901
51918
|
wait: "flag",
|
|
51902
51919
|
"wait-poll-ms": "value",
|
|
51920
|
+
remote: "flag",
|
|
51921
|
+
secret: "list",
|
|
51903
51922
|
python: "value",
|
|
51904
51923
|
"bridge-module": "value",
|
|
51905
51924
|
"bridge-output-bytes": "value",
|
|
@@ -52002,7 +52021,7 @@ var storedTasks = async (context, parsed) => {
|
|
|
52002
52021
|
try {
|
|
52003
52022
|
const stored = await materializeRevision(context, project, kind, id, revision, root, expectedDigest);
|
|
52004
52023
|
context.io.err(`${selector === "latest" ? "Resolved latest to" : "Materialized"} ${kind} ${id} revision ${stored.source.revision} ${stored.source.digest} from project ${project}: ${stored.taskPaths.length} tasks, ${stored.files} files, ${stored.bytes} bytes verified`);
|
|
52005
|
-
return { source: stored.source, taskPaths: stored.taskPaths, close };
|
|
52024
|
+
return { source: stored.source, taskPaths: stored.taskPaths, taskNames: stored.taskNames, close };
|
|
52006
52025
|
} catch (cause) {
|
|
52007
52026
|
await close();
|
|
52008
52027
|
throw cause;
|
|
@@ -52013,6 +52032,14 @@ var HARBOR_ENVIRONMENT_ALIASES = Object.freeze({
|
|
|
52013
52032
|
"managed-sandbox": "hatchery_harbor.sandbox:ManagedSandboxEnvironment"
|
|
52014
52033
|
});
|
|
52015
52034
|
var nonempty = (value) => Array.isArray(value) ? value.length > 0 : value !== undefined && value !== null;
|
|
52035
|
+
var taskFilters = async (context, parsed) => {
|
|
52036
|
+
const included = [...parsed.lists["include-task-name"] ?? []];
|
|
52037
|
+
if (parsed.values["task-names-file"] !== undefined) {
|
|
52038
|
+
const contents = await readFile14(resolve15(context.cwd, parsed.values["task-names-file"]), "utf8");
|
|
52039
|
+
included.push(...contents.split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== ""));
|
|
52040
|
+
}
|
|
52041
|
+
return { included, excluded: [...parsed.lists["exclude-task-name"] ?? []] };
|
|
52042
|
+
};
|
|
52016
52043
|
var harborJobConfig = async (context, parsed, stored) => {
|
|
52017
52044
|
if (parsed.values.path && parsed.values.config)
|
|
52018
52045
|
throw new UsageError("Choose --path or --config", "run");
|
|
@@ -52043,6 +52070,14 @@ var harborJobConfig = async (context, parsed, stored) => {
|
|
|
52043
52070
|
config = { tasks: taskPaths.map((path) => ({ path })) };
|
|
52044
52071
|
} else
|
|
52045
52072
|
throw new UsageError("run needs --path Harbor task, --task or --dataset with --revision, or --config Harbor job.json", "run");
|
|
52073
|
+
const filters = await taskFilters(context, parsed);
|
|
52074
|
+
if (filters.included.length > 0 || filters.excluded.length > 0) {
|
|
52075
|
+
if (!stored || stored.source.kind !== "dataset")
|
|
52076
|
+
throw new UsageError("Task name filters require a stored --dataset revision", "run");
|
|
52077
|
+
const names = stored.taskNames;
|
|
52078
|
+
const selected = new Set(await filterHarborPackageNames(names, filters.included, filters.excluded, harborProcessOptions(context, parsed)));
|
|
52079
|
+
config.tasks = stored.taskPaths.filter((_, index) => selected.has(names[index])).map((path) => ({ path }));
|
|
52080
|
+
}
|
|
52046
52081
|
if (parsed.values.agent !== undefined || parsed.values.model !== undefined) {
|
|
52047
52082
|
if (!parsed.values.agent)
|
|
52048
52083
|
throw new UsageError("--model requires --agent", "run");
|
|
@@ -52623,9 +52658,223 @@ var pullCommand = {
|
|
|
52623
52658
|
};
|
|
52624
52659
|
|
|
52625
52660
|
// apps/cli/src/commands/run.ts
|
|
52661
|
+
import { resolve as resolve20 } from "path";
|
|
52662
|
+
import { lstat as lstat9 } from "fs/promises";
|
|
52663
|
+
|
|
52664
|
+
// apps/cli/src/commands/hosted.ts
|
|
52665
|
+
import { readFile as readFile15 } from "fs/promises";
|
|
52666
|
+
import { resolve as resolve19 } from "path";
|
|
52667
|
+
var DEFAULT_HOSTED_POLL_MS = 5000;
|
|
52668
|
+
var TERMINAL = new Set(["succeeded", "failed", "cancelled"]);
|
|
52669
|
+
var positive5 = (raw, what) => {
|
|
52670
|
+
const value = integerFrom(raw, what);
|
|
52671
|
+
if (value === 0)
|
|
52672
|
+
throw new UsageError(`${what} must be positive`, "hosted");
|
|
52673
|
+
return value;
|
|
52674
|
+
};
|
|
52675
|
+
var summary = (job) => [
|
|
52676
|
+
`hosted job ${job.id}: ${job.status}`,
|
|
52677
|
+
job.source ? `source: ${job.source.kind} ${job.source.id} r${job.source.revision}${job.source.digest ? ` ${job.source.digest}` : ""}` : "source: Harbor API JobConfig",
|
|
52678
|
+
...job.agent ? [`agent: ${job.agent}${job.model ? ` (${job.model})` : ""}`] : [],
|
|
52679
|
+
...job.task_names?.length ? [`include tasks: ${job.task_names.join(", ")}`] : [],
|
|
52680
|
+
...job.exclude_task_names?.length ? [`exclude tasks: ${job.exclude_task_names.join(", ")}`] : [],
|
|
52681
|
+
...job.exitCode === undefined ? [] : [`exit code: ${job.exitCode}`],
|
|
52682
|
+
...job.harborJobId ? [`harbor job: ${job.harborJobId}`] : [],
|
|
52683
|
+
...job.failure === undefined ? [] : [`failure: ${typeof job.failure === "string" ? job.failure : JSON.stringify(job.failure)}`]
|
|
52684
|
+
].join(`
|
|
52685
|
+
`);
|
|
52686
|
+
var show = (context, job) => context.io.out(context.json ? JSON.stringify({ job }) : summary(job));
|
|
52687
|
+
var sleep5 = (ms, signal) => new Promise((resolve, reject) => {
|
|
52688
|
+
if (signal?.aborted)
|
|
52689
|
+
return reject(signal.reason);
|
|
52690
|
+
const timer = setTimeout(() => {
|
|
52691
|
+
signal?.removeEventListener("abort", abort);
|
|
52692
|
+
resolve();
|
|
52693
|
+
}, ms);
|
|
52694
|
+
const abort = () => {
|
|
52695
|
+
clearTimeout(timer);
|
|
52696
|
+
reject(signal?.reason);
|
|
52697
|
+
};
|
|
52698
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
52699
|
+
});
|
|
52700
|
+
var hostedCommand = {
|
|
52701
|
+
spec: {
|
|
52702
|
+
name: "hosted",
|
|
52703
|
+
operands: ["action", "id?"],
|
|
52704
|
+
options: { task: "value", dataset: "value", revision: "value", agent: "value", model: "value", "n-attempts": "value", concurrency: "value", "include-task-name": "list", "exclude-task-name": "list", "task-names-file": "value", secret: "list", config: "value", wait: "flag", "poll-ms": "value" },
|
|
52705
|
+
shortOptions: { i: "include-task-name", x: "exclude-task-name" },
|
|
52706
|
+
summary: "Start, read, and cancel hosted Harbor jobs",
|
|
52707
|
+
usage: `hatchery hosted start (--task id | --dataset id) --revision n [-i glob | --include-task-name glob ...] [-x glob | --exclude-task-name glob ...] [--task-names-file path] [--agent a] [--model m] [--n-attempts n] [--concurrency n] [--secret NAME ...] [--config job.json] [--wait] [--poll-ms n, default ${DEFAULT_HOSTED_POLL_MS}] [--project id] [--json]
|
|
52708
|
+
hatchery hosted status <id> [--project id] [--json]
|
|
52709
|
+
hatchery hosted cancel <id> [--project id] [--json]`,
|
|
52710
|
+
namespaced: false
|
|
52711
|
+
},
|
|
52712
|
+
run: async (context, parsed) => {
|
|
52713
|
+
const action = parsed.operands.action;
|
|
52714
|
+
if (action !== "start" && action !== "status" && action !== "cancel")
|
|
52715
|
+
throw new UsageError("hosted accepts start, status, or cancel", "hosted");
|
|
52716
|
+
const signal = context.signal ? { signal: context.signal } : {};
|
|
52717
|
+
const id = parsed.operands.id;
|
|
52718
|
+
if (action !== "start") {
|
|
52719
|
+
if (!id)
|
|
52720
|
+
throw new UsageError(`hosted ${action} needs <id>`, "hosted");
|
|
52721
|
+
const path = `/v1/projects/${encodeURIComponent(await projectFrom(context, parsed))}/hosted-jobs/${encodeURIComponent(id)}`;
|
|
52722
|
+
if (action === "cancel") {
|
|
52723
|
+
const body = await context.client.platformJson("POST", `${path}/cancel`, signal);
|
|
52724
|
+
context.io.out(context.json ? JSON.stringify(body ?? { id, cancelRequested: true }) : `cancel requested for hosted job ${id}`);
|
|
52725
|
+
return;
|
|
52726
|
+
}
|
|
52727
|
+
const read = await context.client.platformJson("GET", path, signal);
|
|
52728
|
+
if (!read?.job)
|
|
52729
|
+
throw new Error("the service returned no hosted job");
|
|
52730
|
+
show(context, read.job);
|
|
52731
|
+
return;
|
|
52732
|
+
}
|
|
52733
|
+
if (id)
|
|
52734
|
+
throw new UsageError("hosted start takes no operand", "hosted");
|
|
52735
|
+
const { task, dataset, revision, agent, model, config } = parsed.values;
|
|
52736
|
+
if (task === undefined === (dataset === undefined))
|
|
52737
|
+
throw new UsageError("hosted start needs exactly one of --task or --dataset", "hosted");
|
|
52738
|
+
if (revision === undefined)
|
|
52739
|
+
throw new UsageError("hosted start needs --revision n", "hosted");
|
|
52740
|
+
const pollMs = parsed.values["poll-ms"] === undefined ? DEFAULT_HOSTED_POLL_MS : positive5(parsed.values["poll-ms"], "--poll-ms");
|
|
52741
|
+
const attempts = parsed.values["n-attempts"] === undefined ? undefined : positive5(parsed.values["n-attempts"], "--n-attempts");
|
|
52742
|
+
const concurrency = parsed.values.concurrency === undefined ? undefined : positive5(parsed.values.concurrency, "--concurrency");
|
|
52743
|
+
const secrets = parsed.lists.secret ?? [];
|
|
52744
|
+
const taskNames = [...parsed.lists["include-task-name"] ?? []];
|
|
52745
|
+
if (parsed.values["task-names-file"] !== undefined) {
|
|
52746
|
+
const names = await readFile15(resolve19(context.cwd, parsed.values["task-names-file"]), "utf8");
|
|
52747
|
+
taskNames.push(...names.split(/\r?\n/).map((line) => line.trim()).filter((line) => line !== ""));
|
|
52748
|
+
}
|
|
52749
|
+
const excludeTaskNames = [...parsed.lists["exclude-task-name"] ?? []];
|
|
52750
|
+
if (task !== undefined && (taskNames.length > 0 || excludeTaskNames.length > 0))
|
|
52751
|
+
throw new UsageError("Task name filters require --dataset", "hosted");
|
|
52752
|
+
const body = {
|
|
52753
|
+
source: { kind: task === undefined ? "dataset" : "task", id: task ?? dataset, revision: positive5(revision, "--revision") },
|
|
52754
|
+
...agent ? { agent } : {},
|
|
52755
|
+
...model ? { model } : {},
|
|
52756
|
+
...attempts === undefined ? {} : { attempts },
|
|
52757
|
+
...concurrency === undefined ? {} : { concurrency },
|
|
52758
|
+
...secrets.length ? { secrets } : {},
|
|
52759
|
+
...taskNames.length ? { task_names: taskNames } : {},
|
|
52760
|
+
...excludeTaskNames.length ? { exclude_task_names: excludeTaskNames } : {},
|
|
52761
|
+
...config ? { config: await jsonFile(context.cwd, config) } : {}
|
|
52762
|
+
};
|
|
52763
|
+
const base = `/v1/projects/${encodeURIComponent(await projectFrom(context, parsed))}/hosted-jobs`;
|
|
52764
|
+
const created = await context.client.platformJson("POST", base, { body, headers: { "Hatchery-Agent": "hatchery-cli" }, ...signal });
|
|
52765
|
+
if (!created?.job)
|
|
52766
|
+
throw new Error("hosted job creation returned no job");
|
|
52767
|
+
let job = created.job;
|
|
52768
|
+
if (!parsed.flags.has("wait")) {
|
|
52769
|
+
show(context, job);
|
|
52770
|
+
return;
|
|
52771
|
+
}
|
|
52772
|
+
context.io.err(`hatchery: waiting for hosted job ${job.id}, reading its status every ${pollMs} ms`);
|
|
52773
|
+
while (!TERMINAL.has(job.status)) {
|
|
52774
|
+
await sleep5(pollMs, context.signal);
|
|
52775
|
+
const read = await context.client.platformJson("GET", `${base}/${encodeURIComponent(job.id)}`, signal);
|
|
52776
|
+
if (!read?.job)
|
|
52777
|
+
throw new Error("the service returned no hosted job");
|
|
52778
|
+
job = read.job;
|
|
52779
|
+
}
|
|
52780
|
+
show(context, job);
|
|
52781
|
+
if (job.status === "succeeded")
|
|
52782
|
+
return 0;
|
|
52783
|
+
if (job.logTail)
|
|
52784
|
+
context.io.err(job.logTail);
|
|
52785
|
+
return 1;
|
|
52786
|
+
}
|
|
52787
|
+
};
|
|
52788
|
+
|
|
52789
|
+
// apps/cli/src/commands/run.ts
|
|
52790
|
+
var remoteLocalValues2 = ["config", "revision-digest", "env", "output", "python", "bridge-module", "bridge-output-bytes", "storage", "trial-port", "trial-listen", "trial-base-url", "trial-idle-timeout-seconds", "job-id", "max-invalid-retries", "participant-timeout-ms", "terminal-timeout-ms", "token-refresh-ms", "tdg-account", "tdg-actor", "tdg-url", "tdg-credential-file"];
|
|
52791
|
+
var remoteLocalFlags = ["dry-run", "no-upload", "trusted-local", "yes"];
|
|
52792
|
+
var remotePositive = (raw, option) => {
|
|
52793
|
+
if (raw === undefined)
|
|
52794
|
+
return;
|
|
52795
|
+
const value = integerFrom(raw, option);
|
|
52796
|
+
if (value < 1 || !Number.isSafeInteger(value))
|
|
52797
|
+
throw new UsageError(`${option} must be a positive safe integer`, "run");
|
|
52798
|
+
};
|
|
52799
|
+
var exists2 = async (path) => {
|
|
52800
|
+
try {
|
|
52801
|
+
await lstat9(path);
|
|
52802
|
+
return true;
|
|
52803
|
+
} catch (cause) {
|
|
52804
|
+
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
|
|
52805
|
+
return false;
|
|
52806
|
+
throw cause;
|
|
52807
|
+
}
|
|
52808
|
+
};
|
|
52809
|
+
var remoteRun = async (context, parsed) => {
|
|
52810
|
+
if (parsed.values.server !== undefined || context.env.HARBOR_SERVER_URL)
|
|
52811
|
+
throw new UsageError("--remote cannot be combined with --server or HARBOR_SERVER_URL", "run");
|
|
52812
|
+
for (const name of remoteLocalValues2)
|
|
52813
|
+
if (parsed.values[name] !== undefined)
|
|
52814
|
+
throw new UsageError(`--${name} is not supported by run --remote`, "run");
|
|
52815
|
+
for (const name of remoteLocalFlags)
|
|
52816
|
+
if (parsed.flags.has(name))
|
|
52817
|
+
throw new UsageError(`--${name} is not supported by run --remote`, "run");
|
|
52818
|
+
for (const name of ["role", "agent-kwarg", "ak"])
|
|
52819
|
+
if ((parsed.lists[name]?.length ?? 0) > 0)
|
|
52820
|
+
throw new UsageError(`--${name} is not supported by run --remote`, "run");
|
|
52821
|
+
if (parsed.values["idempotency-key"] !== undefined || parsed.values["wait-poll-ms"] !== undefined)
|
|
52822
|
+
throw new UsageError("Harbor API server options are not supported by run --remote", "run");
|
|
52823
|
+
const { path, task, dataset } = parsed.values;
|
|
52824
|
+
if ([path, task, dataset].filter((value) => value !== undefined).length !== 1)
|
|
52825
|
+
throw new UsageError("run --remote needs exactly one of --path, --task, or --dataset", "run");
|
|
52826
|
+
const hasTaskFilters = (parsed.lists["include-task-name"]?.length ?? 0) > 0 || (parsed.lists["exclude-task-name"]?.length ?? 0) > 0 || parsed.values["task-names-file"] !== undefined;
|
|
52827
|
+
if (hasTaskFilters && dataset === undefined)
|
|
52828
|
+
throw new UsageError("Task name filters require a stored --dataset revision", "run");
|
|
52829
|
+
if (path !== undefined && parsed.values.revision !== undefined)
|
|
52830
|
+
throw new UsageError("--revision requires a stored --task or --dataset", "run");
|
|
52831
|
+
if (parsed.values.model !== undefined && parsed.values.agent === undefined)
|
|
52832
|
+
throw new UsageError("--model requires --agent", "run");
|
|
52833
|
+
remotePositive(parsed.values["n-attempts"], "--n-attempts");
|
|
52834
|
+
remotePositive(parsed.values.concurrency, "--concurrency");
|
|
52835
|
+
remotePositive(parsed.values["poll-ms"], "--poll-ms");
|
|
52836
|
+
const directory = path === undefined ? undefined : resolve20(context.cwd, path);
|
|
52837
|
+
if (directory !== undefined && await exists2(resolve20(directory, "hatchery.toml")))
|
|
52838
|
+
throw new UsageError("run --remote does not yet support role tasks with hatchery.toml; use the local cast or swarm workflow", "run");
|
|
52839
|
+
const project = await projectFrom(context, parsed);
|
|
52840
|
+
let kind;
|
|
52841
|
+
let id;
|
|
52842
|
+
let revision;
|
|
52843
|
+
if (path !== undefined) {
|
|
52844
|
+
if (!await hasHarborTask(directory))
|
|
52845
|
+
throw new UsageError("run --remote --path currently supports one Harbor task directory", "run");
|
|
52846
|
+
const items = await pushHarbor(context, project, directory);
|
|
52847
|
+
const item = items.find((candidate) => candidate.kind === "task");
|
|
52848
|
+
if (!item)
|
|
52849
|
+
throw new Error("Pushing the remote task returned no task revision.");
|
|
52850
|
+
kind = "task";
|
|
52851
|
+
id = item.id;
|
|
52852
|
+
revision = item.revision;
|
|
52853
|
+
context.io.err(`Pushed ${item.name} as task ${id} revision ${revision} ${item.digest}${item.unchanged ? " unchanged" : ""}`);
|
|
52854
|
+
} else {
|
|
52855
|
+
kind = task !== undefined ? "task" : "dataset";
|
|
52856
|
+
id = task ?? dataset;
|
|
52857
|
+
const selector = parsed.values.revision;
|
|
52858
|
+
if (selector === undefined)
|
|
52859
|
+
throw new UsageError(`--${kind} requires --revision with an exact number or latest`, "run");
|
|
52860
|
+
if (selector !== "latest" && !/^[1-9]\d{0,14}$/.test(selector))
|
|
52861
|
+
throw new UsageError("--revision must be a positive integer or latest", "run");
|
|
52862
|
+
revision = selector === "latest" ? await latestRevision(context, project, kind, id) : Number(selector);
|
|
52863
|
+
if (selector === "latest")
|
|
52864
|
+
context.io.err(`Resolved latest to ${kind} ${id} revision ${revision} in project ${project}`);
|
|
52865
|
+
}
|
|
52866
|
+
const values = { project, [kind]: id, revision: String(revision), ...parsed.values.agent ? { agent: parsed.values.agent } : {}, ...parsed.values.model ? { model: parsed.values.model } : {}, ...parsed.values["n-attempts"] ? { "n-attempts": parsed.values["n-attempts"] } : {}, ...parsed.values.concurrency ? { concurrency: parsed.values.concurrency } : {}, ...parsed.values["poll-ms"] ? { "poll-ms": parsed.values["poll-ms"] } : {}, ...parsed.values["task-names-file"] ? { "task-names-file": parsed.values["task-names-file"] } : {} };
|
|
52867
|
+
const hosted = { name: "hosted", operands: { action: "start" }, values, flags: new Set(["wait"]), lists: { ...parsed.lists.secret ? { secret: parsed.lists.secret } : {}, ...parsed.lists["include-task-name"] ? { "include-task-name": parsed.lists["include-task-name"] } : {}, ...parsed.lists["exclude-task-name"] ? { "exclude-task-name": parsed.lists["exclude-task-name"] } : {} }, pairs: {}, ordered: [] };
|
|
52868
|
+
return hostedCommand.run(context, hosted);
|
|
52869
|
+
};
|
|
52626
52870
|
var runCommand = {
|
|
52627
|
-
spec: { name: "run", operands: [], options: harborRunOptions, summary: "Run a Harbor task
|
|
52871
|
+
spec: { name: "run", operands: [], options: harborRunOptions, shortOptions: { i: "include-task-name", x: "exclude-task-name" }, summary: "Run a Harbor task locally or remotely", usage: `hatchery run (--path task | (--task id | --dataset id) --revision (n | latest) [--revision-digest sha256:hex] | --config job.json) [-i glob | --include-task-name glob ...] [-x glob | --exclude-task-name glob ...] [--task-names-file path] [--server url [--idempotency-key key] [--wait [--wait-poll-ms ms]]] [--agent name --model name] [--env provider] [--n-attempts n] [--project id] [--python path] [--yes] [--token-refresh-ms ms] [--dry-run]
|
|
52872
|
+
hatchery run (--path task | (--task id | --dataset id) --revision (n | latest)) --remote [-i glob | -x glob | --task-names-file path] [--agent name --model name] [--n-attempts n] [--concurrency n] [--secret NAME] [--poll-ms n] [--project id] (waits by default; task filters require --dataset)`, namespaced: false },
|
|
52628
52873
|
run: async (context, parsed) => {
|
|
52874
|
+
if (parsed.flags.has("remote"))
|
|
52875
|
+
return remoteRun(context, parsed);
|
|
52876
|
+
if ((parsed.lists.secret?.length ?? 0) > 0)
|
|
52877
|
+
throw new UsageError("--secret requires --remote", "run");
|
|
52629
52878
|
return executeHarborCommand(context, parsed);
|
|
52630
52879
|
}
|
|
52631
52880
|
};
|
|
@@ -52675,11 +52924,21 @@ var runnerArguments = (env, configPath) => {
|
|
|
52675
52924
|
throw new UsageError("HATCHERY_RUN_ALLOW_HOST_ENV must be true or false");
|
|
52676
52925
|
const hosted = set4(env, "HATCHERY_HOSTED_JOB_ID") !== undefined;
|
|
52677
52926
|
const valueOf = (option, value) => option === "env" && hosted && Object.hasOwn(HOSTED_ENVIRONMENT_ALIASES, value) ? HOSTED_ENVIRONMENT_ALIASES[value] : value;
|
|
52927
|
+
const patterns = (name, option) => {
|
|
52928
|
+
if (!set4(env, name))
|
|
52929
|
+
return [];
|
|
52930
|
+
const values = JSON.parse(set4(env, name));
|
|
52931
|
+
if (!Array.isArray(values) || values.some((value) => typeof value !== "string" || value === ""))
|
|
52932
|
+
throw new UsageError(`${name} must hold a nonempty string array`);
|
|
52933
|
+
return values.flatMap((value) => [`--${option}`, value]);
|
|
52934
|
+
};
|
|
52678
52935
|
return [
|
|
52679
52936
|
...task ? ["--task", task] : [],
|
|
52680
52937
|
...dataset ? ["--dataset", dataset] : [],
|
|
52681
52938
|
...configPath === undefined ? [] : ["--config", configPath],
|
|
52682
52939
|
...RUNNER_VALUES.flatMap(([name, option]) => set4(env, name) ? [`--${option}`, valueOf(option, set4(env, name))] : []),
|
|
52940
|
+
...patterns("HATCHERY_RUN_TASK_NAMES", "include-task-name"),
|
|
52941
|
+
...patterns("HATCHERY_RUN_EXCLUDE_TASK_NAMES", "exclude-task-name"),
|
|
52683
52942
|
...consent === "true" ? ["--yes"] : []
|
|
52684
52943
|
];
|
|
52685
52944
|
};
|
|
@@ -53004,13 +53263,13 @@ var runnerCommand = {
|
|
|
53004
53263
|
};
|
|
53005
53264
|
|
|
53006
53265
|
// apps/cli/src/commands/regrade.ts
|
|
53007
|
-
import { resolve as
|
|
53266
|
+
import { resolve as resolve21 } from "path";
|
|
53008
53267
|
var regradeCommand = {
|
|
53009
53268
|
spec: { name: "regrade", operands: ["run"], options: { path: "value", python: "value", "bridge-module": "value", "no-upload": "flag", "token-refresh-ms": "value", yes: "flag" }, summary: "Regrade a retained Harbor job with its separate verifier", usage: "hatchery regrade <job-directory> --path task [--python path] [--project id] [--yes]", namespaced: false },
|
|
53010
53269
|
run: async (context, parsed) => {
|
|
53011
53270
|
if (parsed.values.path) {
|
|
53012
53271
|
const upload = await harborUpload(context, parsed);
|
|
53013
|
-
const result = await runHarborRegrade({ ...harborProcessOptions(context, parsed), sourceJobDirectory:
|
|
53272
|
+
const result = await runHarborRegrade({ ...harborProcessOptions(context, parsed), sourceJobDirectory: resolve21(context.cwd, parsed.operands.run ?? ""), taskDirectory: resolve21(context.cwd, parsed.values.path), plugins: upload.plugins, confirmHostEnvAccess: parsed.flags.has("yes") }).finally(upload.close);
|
|
53014
53273
|
context.io.out(context.json ? JSON.stringify(result) : `Regraded ${result.result.trial_results.length} Harbor trials in ${result.directory}`);
|
|
53015
53274
|
return;
|
|
53016
53275
|
}
|
|
@@ -53032,8 +53291,8 @@ var openCommand = {
|
|
|
53032
53291
|
};
|
|
53033
53292
|
|
|
53034
53293
|
// apps/cli/src/commands/page.ts
|
|
53035
|
-
import { readFile as
|
|
53036
|
-
import { resolve as
|
|
53294
|
+
import { readFile as readFile17, writeFile as writeFile9 } from "fs/promises";
|
|
53295
|
+
import { resolve as resolve23 } from "path";
|
|
53037
53296
|
|
|
53038
53297
|
// packages/pages/src/types.ts
|
|
53039
53298
|
var PAGE_MERMAID_RENDER_OPTIONS = { links: false, images: false, autoDirection: false };
|
|
@@ -94189,8 +94448,8 @@ var liftStandaloneComponents = (node) => {
|
|
|
94189
94448
|
return { ...node, children };
|
|
94190
94449
|
};
|
|
94191
94450
|
// apps/cli/src/page-assets.ts
|
|
94192
|
-
import { readFile as
|
|
94193
|
-
import { dirname as dirname11, extname, resolve as
|
|
94451
|
+
import { readFile as readFile16 } from "fs/promises";
|
|
94452
|
+
import { dirname as dirname11, extname, resolve as resolve22 } from "path";
|
|
94194
94453
|
var DEFAULT_PAGE_ASSET_LIMITS = {
|
|
94195
94454
|
pageAssets: 24,
|
|
94196
94455
|
pageAssetBytes: 2097152
|
|
@@ -94227,7 +94486,7 @@ var localPageAssets = async (pageFile, paths, limits = DEFAULT_PAGE_ASSET_LIMITS
|
|
|
94227
94486
|
return problem(`Image asset ${path} must use a .png, .jpg, .jpeg, or .webp extension.`);
|
|
94228
94487
|
let bytes;
|
|
94229
94488
|
try {
|
|
94230
|
-
bytes = await
|
|
94489
|
+
bytes = await readFile16(resolve22(root, path));
|
|
94231
94490
|
} catch {
|
|
94232
94491
|
return problem(`Image asset ${path} could not be read relative to ${pageFile}.`);
|
|
94233
94492
|
}
|
|
@@ -94297,8 +94556,8 @@ var reportProblems = (context, file, problems) => {
|
|
|
94297
94556
|
context.io.err(`${file}:${problem.line}:${problem.column} ${problem.message}`);
|
|
94298
94557
|
};
|
|
94299
94558
|
var checkedPage = async (context, file) => {
|
|
94300
|
-
const pageFile =
|
|
94301
|
-
const source = await
|
|
94559
|
+
const pageFile = resolve23(context.cwd, file);
|
|
94560
|
+
const source = await readFile17(pageFile, "utf8");
|
|
94302
94561
|
const parsed = parsePage(source, PAGE_CHECK_LIMITS);
|
|
94303
94562
|
if (!parsed.ok)
|
|
94304
94563
|
return { source, problems: parsed.problems };
|
|
@@ -94331,7 +94590,7 @@ var pageCommand = {
|
|
|
94331
94590
|
const action = parsed.operands.action;
|
|
94332
94591
|
if (action === "init") {
|
|
94333
94592
|
const file = parsed.operands.target ?? "page.mdx";
|
|
94334
|
-
const target =
|
|
94593
|
+
const target = resolve23(context.cwd, file);
|
|
94335
94594
|
await writeFile9(target, PAGE_TEMPLATE, { encoding: "utf8", flag: "wx", mode: 420 });
|
|
94336
94595
|
context.io.out(`Created ${target}`);
|
|
94337
94596
|
return;
|
|
@@ -94612,116 +94871,6 @@ var secretsCommandWith = (terminal) => ({
|
|
|
94612
94871
|
});
|
|
94613
94872
|
var secretsCommand = secretsCommandWith(() => process.stdin.isTTY === true);
|
|
94614
94873
|
|
|
94615
|
-
// apps/cli/src/commands/hosted.ts
|
|
94616
|
-
var DEFAULT_HOSTED_POLL_MS = 5000;
|
|
94617
|
-
var TERMINAL = new Set(["succeeded", "failed", "cancelled"]);
|
|
94618
|
-
var positive5 = (raw, what) => {
|
|
94619
|
-
const value = integerFrom(raw, what);
|
|
94620
|
-
if (value === 0)
|
|
94621
|
-
throw new UsageError(`${what} must be positive`, "hosted");
|
|
94622
|
-
return value;
|
|
94623
|
-
};
|
|
94624
|
-
var summary = (job) => [
|
|
94625
|
-
`hosted job ${job.id}: ${job.status}`,
|
|
94626
|
-
job.source ? `source: ${job.source.kind} ${job.source.id} r${job.source.revision}${job.source.digest ? ` ${job.source.digest}` : ""}` : "source: Harbor API JobConfig",
|
|
94627
|
-
...job.agent ? [`agent: ${job.agent}${job.model ? ` (${job.model})` : ""}`] : [],
|
|
94628
|
-
...job.exitCode === undefined ? [] : [`exit code: ${job.exitCode}`],
|
|
94629
|
-
...job.harborJobId ? [`harbor job: ${job.harborJobId}`] : [],
|
|
94630
|
-
...job.failure === undefined ? [] : [`failure: ${typeof job.failure === "string" ? job.failure : JSON.stringify(job.failure)}`]
|
|
94631
|
-
].join(`
|
|
94632
|
-
`);
|
|
94633
|
-
var show = (context, job) => context.io.out(context.json ? JSON.stringify({ job }) : summary(job));
|
|
94634
|
-
var sleep5 = (ms, signal) => new Promise((resolve, reject) => {
|
|
94635
|
-
if (signal?.aborted)
|
|
94636
|
-
return reject(signal.reason);
|
|
94637
|
-
const timer = setTimeout(() => {
|
|
94638
|
-
signal?.removeEventListener("abort", abort);
|
|
94639
|
-
resolve();
|
|
94640
|
-
}, ms);
|
|
94641
|
-
const abort = () => {
|
|
94642
|
-
clearTimeout(timer);
|
|
94643
|
-
reject(signal?.reason);
|
|
94644
|
-
};
|
|
94645
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
94646
|
-
});
|
|
94647
|
-
var hostedCommand = {
|
|
94648
|
-
spec: {
|
|
94649
|
-
name: "hosted",
|
|
94650
|
-
operands: ["action", "id?"],
|
|
94651
|
-
options: { task: "value", dataset: "value", revision: "value", agent: "value", model: "value", "n-attempts": "value", concurrency: "value", secret: "list", config: "value", wait: "flag", "poll-ms": "value" },
|
|
94652
|
-
summary: "Start, read, and cancel hosted Harbor jobs",
|
|
94653
|
-
usage: `hatchery hosted start (--task id | --dataset id) --revision n [--agent a] [--model m] [--n-attempts n] [--concurrency n] [--secret NAME ...] [--config job.json] [--wait] [--poll-ms n, default ${DEFAULT_HOSTED_POLL_MS}] [--project id] [--json]
|
|
94654
|
-
hatchery hosted status <id> [--project id] [--json]
|
|
94655
|
-
hatchery hosted cancel <id> [--project id] [--json]`,
|
|
94656
|
-
namespaced: false
|
|
94657
|
-
},
|
|
94658
|
-
run: async (context, parsed) => {
|
|
94659
|
-
const action = parsed.operands.action;
|
|
94660
|
-
if (action !== "start" && action !== "status" && action !== "cancel")
|
|
94661
|
-
throw new UsageError("hosted accepts start, status, or cancel", "hosted");
|
|
94662
|
-
const signal = context.signal ? { signal: context.signal } : {};
|
|
94663
|
-
const id = parsed.operands.id;
|
|
94664
|
-
if (action !== "start") {
|
|
94665
|
-
if (!id)
|
|
94666
|
-
throw new UsageError(`hosted ${action} needs <id>`, "hosted");
|
|
94667
|
-
const path = `/v1/projects/${encodeURIComponent(await projectFrom(context, parsed))}/hosted-jobs/${encodeURIComponent(id)}`;
|
|
94668
|
-
if (action === "cancel") {
|
|
94669
|
-
const body = await context.client.platformJson("POST", `${path}/cancel`, signal);
|
|
94670
|
-
context.io.out(context.json ? JSON.stringify(body ?? { id, cancelRequested: true }) : `cancel requested for hosted job ${id}`);
|
|
94671
|
-
return;
|
|
94672
|
-
}
|
|
94673
|
-
const read = await context.client.platformJson("GET", path, signal);
|
|
94674
|
-
if (!read?.job)
|
|
94675
|
-
throw new Error("the service returned no hosted job");
|
|
94676
|
-
show(context, read.job);
|
|
94677
|
-
return;
|
|
94678
|
-
}
|
|
94679
|
-
if (id)
|
|
94680
|
-
throw new UsageError("hosted start takes no operand", "hosted");
|
|
94681
|
-
const { task, dataset, revision, agent, model, config } = parsed.values;
|
|
94682
|
-
if (task === undefined === (dataset === undefined))
|
|
94683
|
-
throw new UsageError("hosted start needs exactly one of --task or --dataset", "hosted");
|
|
94684
|
-
if (revision === undefined)
|
|
94685
|
-
throw new UsageError("hosted start needs --revision n", "hosted");
|
|
94686
|
-
const pollMs = parsed.values["poll-ms"] === undefined ? DEFAULT_HOSTED_POLL_MS : positive5(parsed.values["poll-ms"], "--poll-ms");
|
|
94687
|
-
const attempts = parsed.values["n-attempts"] === undefined ? undefined : positive5(parsed.values["n-attempts"], "--n-attempts");
|
|
94688
|
-
const concurrency = parsed.values.concurrency === undefined ? undefined : positive5(parsed.values.concurrency, "--concurrency");
|
|
94689
|
-
const secrets = parsed.lists.secret ?? [];
|
|
94690
|
-
const body = {
|
|
94691
|
-
source: { kind: task === undefined ? "dataset" : "task", id: task ?? dataset, revision: positive5(revision, "--revision") },
|
|
94692
|
-
...agent ? { agent } : {},
|
|
94693
|
-
...model ? { model } : {},
|
|
94694
|
-
...attempts === undefined ? {} : { attempts },
|
|
94695
|
-
...concurrency === undefined ? {} : { concurrency },
|
|
94696
|
-
...secrets.length ? { secrets } : {},
|
|
94697
|
-
...config ? { config: await jsonFile(context.cwd, config) } : {}
|
|
94698
|
-
};
|
|
94699
|
-
const base = `/v1/projects/${encodeURIComponent(await projectFrom(context, parsed))}/hosted-jobs`;
|
|
94700
|
-
const created = await context.client.platformJson("POST", base, { body, headers: { "Hatchery-Agent": "hatchery-cli" }, ...signal });
|
|
94701
|
-
if (!created?.job)
|
|
94702
|
-
throw new Error("hosted job creation returned no job");
|
|
94703
|
-
let job = created.job;
|
|
94704
|
-
if (!parsed.flags.has("wait")) {
|
|
94705
|
-
show(context, job);
|
|
94706
|
-
return;
|
|
94707
|
-
}
|
|
94708
|
-
context.io.err(`hatchery: waiting for hosted job ${job.id}, reading its status every ${pollMs} ms`);
|
|
94709
|
-
while (!TERMINAL.has(job.status)) {
|
|
94710
|
-
await sleep5(pollMs, context.signal);
|
|
94711
|
-
const read = await context.client.platformJson("GET", `${base}/${encodeURIComponent(job.id)}`, signal);
|
|
94712
|
-
if (!read?.job)
|
|
94713
|
-
throw new Error("the service returned no hosted job");
|
|
94714
|
-
job = read.job;
|
|
94715
|
-
}
|
|
94716
|
-
show(context, job);
|
|
94717
|
-
if (job.status === "succeeded")
|
|
94718
|
-
return 0;
|
|
94719
|
-
if (job.logTail)
|
|
94720
|
-
context.io.err(job.logTail);
|
|
94721
|
-
return 1;
|
|
94722
|
-
}
|
|
94723
|
-
};
|
|
94724
|
-
|
|
94725
94874
|
// apps/cli/src/commands/projects.ts
|
|
94726
94875
|
var projectsCommand = {
|
|
94727
94876
|
spec: { name: "projects", operands: ["action", "name?"], options: {}, summary: "List and create the projects of your organization", usage: "hatchery projects list|create <name> [--json] (create derives the project id from the name and prints it)", namespaced: false },
|