@shipd-ai/cli 0.1.3 → 0.2.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/README.md +118 -43
- package/dist/auth.d.ts +9 -5
- package/dist/auth.js +43 -10
- package/dist/author.d.ts +11 -0
- package/dist/author.js +43 -0
- package/dist/backend.d.ts +4 -0
- package/dist/backend.js +51 -0
- package/dist/checks-view.d.ts +9 -0
- package/dist/checks-view.js +11 -0
- package/dist/client.d.ts +0 -8
- package/dist/client.js +0 -7
- package/dist/commands/auth.d.ts +9 -4
- package/dist/commands/auth.js +29 -41
- package/dist/commands/author-checks.d.ts +265 -0
- package/dist/commands/author-checks.js +365 -0
- package/dist/commands/checks.d.ts +0 -2
- package/dist/commands/checks.js +21 -17
- package/dist/commands/problems.d.ts +1 -0
- package/dist/commands/problems.js +189 -0
- package/dist/commands/quests.d.ts +0 -1
- package/dist/commands/quests.js +0 -1
- package/dist/contract.d.ts +0 -1
- package/dist/contract.js +0 -7
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +6 -5
- package/dist/format.d.ts +2 -4
- package/dist/format.js +29 -7
- package/dist/harbor.d.ts +0 -8
- package/dist/harbor.js +0 -11
- package/dist/index-gate.d.ts +1 -0
- package/dist/index-gate.js +5 -0
- package/dist/index.js +14 -10
- package/dist/model.d.ts +94 -0
- package/dist/model.js +68 -0
- package/dist/plan.d.ts +0 -15
- package/dist/plan.js +0 -21
- package/dist/prompt.d.ts +5 -0
- package/dist/prompt.js +26 -0
- package/dist/quests.d.ts +2 -10
- package/dist/quests.js +51 -34
- package/dist/report.d.ts +0 -9
- package/dist/report.js +1 -7
- package/dist/usage.d.ts +2 -0
- package/dist/usage.js +16 -0
- package/package.json +3 -2
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { api, backend, connectAuthor } from "../author.js";
|
|
3
|
+
import { UsageError } from "../errors.js";
|
|
4
|
+
import { dim, paint, printJson, printKeyValue, printTable, statusBadge, text, truncate, } from "../format.js";
|
|
5
|
+
import { DEFAULT_QUEST } from "../quests.js";
|
|
6
|
+
import { printPrechecks, printQualityChecks, printReadiness, printTrialQa, questArg, } from "./author-checks.js";
|
|
7
|
+
const DEFAULT_LIMIT = 30;
|
|
8
|
+
const color = () => Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
9
|
+
function field(value) {
|
|
10
|
+
if (value === undefined || value === null || value === "")
|
|
11
|
+
return undefined;
|
|
12
|
+
return text(value);
|
|
13
|
+
}
|
|
14
|
+
function printRunCriteria(criteria, c) {
|
|
15
|
+
const criteriaList = criteria?.criteria;
|
|
16
|
+
if (!criteriaList || criteriaList.length === 0)
|
|
17
|
+
return;
|
|
18
|
+
console.log("\n Rollout Criteria:");
|
|
19
|
+
for (const criterion of criteriaList) {
|
|
20
|
+
const detail = criterion.detail ? ` ${text(criterion.detail)}` : "";
|
|
21
|
+
const preview = criterion.preview ? ` ${dim("(preview)", c)}` : "";
|
|
22
|
+
console.log(` ${statusBadge(criterion.status, c)} ${text(criterion.label)}${detail}${preview}`);
|
|
23
|
+
if (criterion.description) {
|
|
24
|
+
console.log(` ${dim(`Target: ${text(criterion.description)}`, c)}`);
|
|
25
|
+
}
|
|
26
|
+
if (criterion.guidance) {
|
|
27
|
+
console.log(` ${paint("yellow", truncate(text(criterion.guidance), 100), c)}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const list = defineCommand({
|
|
32
|
+
meta: { name: "list", description: "List your challenges" },
|
|
33
|
+
args: {
|
|
34
|
+
...questArg,
|
|
35
|
+
status: { type: "string", description: "Filter by status" },
|
|
36
|
+
limit: { type: "string", description: `Max results (default ${DEFAULT_LIMIT})` },
|
|
37
|
+
json: { type: "boolean", description: "Output as JSON" },
|
|
38
|
+
},
|
|
39
|
+
run: async ({ args }) => {
|
|
40
|
+
const client = await connectAuthor(args.quest);
|
|
41
|
+
const limit = Number.parseInt(args.limit ?? "", 10) || DEFAULT_LIMIT;
|
|
42
|
+
const queryArgs = {};
|
|
43
|
+
if (args.status)
|
|
44
|
+
queryArgs.status = args.status;
|
|
45
|
+
const problems = (await backend(() => client.query(api.problems.listByUser, queryArgs)));
|
|
46
|
+
if (!problems || problems.length === 0) {
|
|
47
|
+
if (args.json)
|
|
48
|
+
printJson([]);
|
|
49
|
+
else
|
|
50
|
+
console.log(" No challenges found.");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
problems.sort((a, b) => (b._creationTime ?? 0) - (a._creationTime ?? 0));
|
|
54
|
+
const display = problems.slice(0, limit);
|
|
55
|
+
if (args.json) {
|
|
56
|
+
printJson(display);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const c = color();
|
|
60
|
+
printTable(display.map((problem) => ({
|
|
61
|
+
id: String(problem._id),
|
|
62
|
+
title: truncate(text(problem.title ?? ""), 50),
|
|
63
|
+
status: statusBadge(problem.status ?? "unknown", c),
|
|
64
|
+
lang: text(problem.language ?? ""),
|
|
65
|
+
diff: text(problem.difficulty ?? ""),
|
|
66
|
+
})), [
|
|
67
|
+
{ key: "id", label: "ID" },
|
|
68
|
+
{ key: "title", label: "Title", width: 52 },
|
|
69
|
+
{ key: "status", label: "Status", width: 24 },
|
|
70
|
+
{ key: "lang", label: "Lang", width: 12 },
|
|
71
|
+
{ key: "diff", label: "Diff", width: 8 },
|
|
72
|
+
]);
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const view = defineCommand({
|
|
76
|
+
meta: {
|
|
77
|
+
name: "view",
|
|
78
|
+
description: "View a challenge: its latest version, checks and readiness",
|
|
79
|
+
},
|
|
80
|
+
args: {
|
|
81
|
+
id: { type: "positional", description: "Challenge ID", required: true },
|
|
82
|
+
...questArg,
|
|
83
|
+
json: { type: "boolean", description: "Output as JSON" },
|
|
84
|
+
},
|
|
85
|
+
run: async ({ args }) => {
|
|
86
|
+
const client = await connectAuthor(args.quest);
|
|
87
|
+
const problemId = args.id;
|
|
88
|
+
const data = (await backend(() => client.query(api.problems.getWithLatestVersion, { problemId })));
|
|
89
|
+
if (!data) {
|
|
90
|
+
throw new UsageError(`Challenge not found: ${text(problemId)}`);
|
|
91
|
+
}
|
|
92
|
+
const latestVersion = data.latestVersion;
|
|
93
|
+
const [stages, dynamicChecks, trialQa, criteria, readiness] = latestVersion
|
|
94
|
+
? await backend(() => Promise.all([
|
|
95
|
+
client.query(api.stages.getValidationResults, {
|
|
96
|
+
itemId: problemId,
|
|
97
|
+
versionId: latestVersion._id,
|
|
98
|
+
}),
|
|
99
|
+
client.query(api.runDynamicChecks.getDynamicChecks, { versionId: latestVersion._id }),
|
|
100
|
+
client.query(api.fpReview.getFpCheckForVersion, { versionId: latestVersion._id }),
|
|
101
|
+
client.query(api.runAgentRuns.getAgentRunCriteria, { versionId: latestVersion._id }),
|
|
102
|
+
client.query(api.submissionReadiness.getSubmissionReadiness, { problemId }),
|
|
103
|
+
]))
|
|
104
|
+
: [[], null, null, null, null];
|
|
105
|
+
if (args.json) {
|
|
106
|
+
printJson({
|
|
107
|
+
...data,
|
|
108
|
+
checks: { stages, dynamicChecks, trialQa, readiness },
|
|
109
|
+
rolloutCriteria: criteria,
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const c = color();
|
|
114
|
+
console.log("");
|
|
115
|
+
printKeyValue([
|
|
116
|
+
["ID", String(data._id)],
|
|
117
|
+
["Title", field(data.title)],
|
|
118
|
+
["Status", statusBadge(data.status ?? "unknown", c)],
|
|
119
|
+
[
|
|
120
|
+
"Version",
|
|
121
|
+
latestVersion
|
|
122
|
+
? `v${latestVersion.version}${latestVersion.isLocked ? " (locked)" : " (unlocked)"}`
|
|
123
|
+
: "none",
|
|
124
|
+
],
|
|
125
|
+
["Language", field(latestVersion?.language ?? data.language)],
|
|
126
|
+
["Difficulty", field(latestVersion?.difficulty ?? data.difficulty)],
|
|
127
|
+
["Category", field(latestVersion?.category ?? data.category)],
|
|
128
|
+
["Repo", field(latestVersion?.githubRepoUrl)],
|
|
129
|
+
["Commit", field(latestVersion?.githubCommitHash?.slice(0, 8))],
|
|
130
|
+
["Test Patch", latestVersion?.testPatch ? "yes" : "no"],
|
|
131
|
+
["Solution", latestVersion?.solutionPatch ? "yes" : "no"],
|
|
132
|
+
["Dockerfile", latestVersion?.dockerfile ? "yes" : "no"],
|
|
133
|
+
]);
|
|
134
|
+
if (latestVersion?.description) {
|
|
135
|
+
const description = text(latestVersion.description)
|
|
136
|
+
.split("\n")
|
|
137
|
+
.map((line) => ` ${line}`)
|
|
138
|
+
.join("\n");
|
|
139
|
+
console.log(`\n Description:\n${description}`);
|
|
140
|
+
}
|
|
141
|
+
printReadiness(readiness, c);
|
|
142
|
+
console.log("");
|
|
143
|
+
printPrechecks(stages, c, false);
|
|
144
|
+
printQualityChecks(dynamicChecks, c, false);
|
|
145
|
+
printTrialQa(trialQa, c);
|
|
146
|
+
printRunCriteria(criteria, c);
|
|
147
|
+
const questFlag = args.quest === DEFAULT_QUEST ? "" : ` --quest ${args.quest}`;
|
|
148
|
+
console.log("\n Commands:");
|
|
149
|
+
console.log(` shipd checks view ${problemId}${questFlag} Checks + readiness detail`);
|
|
150
|
+
console.log(` shipd checks run-prechecks ${problemId}${questFlag} Run the prechecks`);
|
|
151
|
+
console.log(` shipd checks run-all ${problemId}${questFlag} Run the quality checks`);
|
|
152
|
+
console.log(` shipd checks run-trial-qa ${problemId}${questFlag} Run Trial QA`);
|
|
153
|
+
console.log(` shipd problems versions ${problemId}${questFlag} List all versions`);
|
|
154
|
+
console.log("");
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
const versions = defineCommand({
|
|
158
|
+
meta: { name: "versions", description: "List all versions of a challenge" },
|
|
159
|
+
args: {
|
|
160
|
+
id: { type: "positional", description: "Challenge ID", required: true },
|
|
161
|
+
...questArg,
|
|
162
|
+
json: { type: "boolean", description: "Output as JSON" },
|
|
163
|
+
},
|
|
164
|
+
run: async ({ args }) => {
|
|
165
|
+
const client = await connectAuthor(args.quest);
|
|
166
|
+
const versions = (await backend(() => client.query(api.problems.listVersions, { problemId: args.id })));
|
|
167
|
+
if (args.json) {
|
|
168
|
+
printJson(versions ?? []);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const list = Array.isArray(versions) ? versions : [];
|
|
172
|
+
if (list.length === 0) {
|
|
173
|
+
console.log(" No versions found.");
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const c = color();
|
|
177
|
+
console.log("");
|
|
178
|
+
for (const item of list) {
|
|
179
|
+
const locked = item.isLocked ? ` ${paint("yellow", "(locked)", c)}` : "";
|
|
180
|
+
const date = new Date(item._creationTime ?? 0).toLocaleDateString();
|
|
181
|
+
console.log(` v${item.version}${locked} ${date}`);
|
|
182
|
+
}
|
|
183
|
+
console.log("");
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
export const problems = defineCommand({
|
|
187
|
+
meta: { name: "problems", description: "Your challenges (author and admin editions)" },
|
|
188
|
+
subCommands: { list, view, versions },
|
|
189
|
+
});
|
|
@@ -3,7 +3,6 @@ export type QuestRow = {
|
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
default: boolean;
|
|
5
5
|
};
|
|
6
|
-
/** The quests this CLI knows how to talk to, with their resolved base URLs. */
|
|
7
6
|
export declare function listQuests(): QuestRow[];
|
|
8
7
|
export declare const quests: import("citty").CommandDef<{
|
|
9
8
|
readonly json: {
|
package/dist/commands/quests.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { defineCommand } from "citty";
|
|
2
2
|
import { printJson, printTable } from "../format.js";
|
|
3
3
|
import { DEFAULT_QUEST, knownQuests, questBaseUrl } from "../quests.js";
|
|
4
|
-
/** The quests this CLI knows how to talk to, with their resolved base URLs. */
|
|
5
4
|
export function listQuests() {
|
|
6
5
|
return knownQuests().map((quest) => ({
|
|
7
6
|
quest,
|
package/dist/contract.d.ts
CHANGED
package/dist/contract.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// Shared shapes of the quest contract. Every quest that supports the CLI
|
|
2
|
-
// exposes `adhocChecks:*` Convex functions with these argument and return
|
|
3
|
-
// types; the quest mirrors them with Convex validators. The CLI never imports
|
|
4
|
-
// quest source, so this file is the only place the two sides meet.
|
|
5
|
-
// The seven files read from a Harbor task directory. `key` is the wire
|
|
6
|
-
// field (Convex object validators only accept identifier keys); `path` is
|
|
7
|
-
// the on-disk location.
|
|
8
1
|
export const HARBOR_FILES = [
|
|
9
2
|
{ key: "taskToml", path: "task.toml" },
|
|
10
3
|
{ key: "instructionMd", path: "instruction.md" },
|
package/dist/errors.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare class AuthError extends CliError {
|
|
|
15
15
|
export declare class BundleError extends CliError {
|
|
16
16
|
constructor(message: string);
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
export declare class RefusedError extends CliError {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
19
21
|
export declare function exitCodeForError(error: unknown): number;
|
|
20
22
|
export declare function errorMessage(error: unknown): string;
|
package/dist/errors.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// Exit codes: 0 every run check passed or warned; 1 a check failed or errored;
|
|
2
|
-
// 2 usage, auth, or bundle error; 3 cancelled.
|
|
3
1
|
export const EXIT_OK = 0;
|
|
4
2
|
export const EXIT_CHECK_FAILED = 1;
|
|
5
3
|
export const EXIT_USAGE = 2;
|
|
@@ -30,13 +28,16 @@ export class BundleError extends CliError {
|
|
|
30
28
|
this.name = "BundleError";
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
|
-
|
|
31
|
+
export class RefusedError extends CliError {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super(message, EXIT_CHECK_FAILED);
|
|
34
|
+
this.name = "RefusedError";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
34
37
|
export function exitCodeForError(error) {
|
|
35
38
|
if (error instanceof CliError)
|
|
36
39
|
return error.exitCode;
|
|
37
40
|
const message = error instanceof Error ? error.message : String(error);
|
|
38
|
-
// Quest-side auth failures (Convex `Unauthorized` / `Forbidden: admin role
|
|
39
|
-
// required`) are usage errors from the CLI's point of view.
|
|
40
41
|
if (/\b(unauthorized|unauthenticated|forbidden|not authenticated)\b/i.test(message)) {
|
|
41
42
|
return EXIT_USAGE;
|
|
42
43
|
}
|
package/dist/format.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
export declare function stripAnsi(str: string): string;
|
|
2
|
+
export declare function text(value: unknown): string;
|
|
2
3
|
export type TableColumn = {
|
|
3
4
|
key: string;
|
|
4
5
|
label: string;
|
|
5
6
|
width?: number;
|
|
6
7
|
};
|
|
7
8
|
export type TableRow = Record<string, string | number | boolean | null | undefined>;
|
|
8
|
-
/** Render rows as an aligned text table (two-space indent, same look as the Olympus CLI). */
|
|
9
9
|
export declare function formatTable(rows: TableRow[], columns: TableColumn[]): string[];
|
|
10
10
|
export declare function printTable(rows: TableRow[], columns: TableColumn[]): void;
|
|
11
11
|
export declare function printJson(data: unknown): void;
|
|
12
12
|
export declare function printKeyValue(pairs: [string, string | undefined | null][]): void;
|
|
13
|
-
/** Status badge for terminal output; colors only when asked for. */
|
|
14
13
|
export declare function statusBadge(status: string, color?: boolean): string;
|
|
15
14
|
export declare function dim(text: string, color?: boolean): string;
|
|
16
|
-
|
|
15
|
+
export declare function paint(colorName: "yellow" | "red" | "green" | "blue", str: string, color?: boolean): string;
|
|
17
16
|
export declare function truncate(str: string, max: number): string;
|
|
18
|
-
/** Compact human duration: 850ms, 5s, 2m10s, 3h, 1h05m. */
|
|
19
17
|
export declare function formatDuration(ms: number): string;
|
package/dist/format.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
// Minimal output formatting helpers. Every command also supports --json.
|
|
2
1
|
const ESC = String.fromCharCode(27);
|
|
3
2
|
const ANSI_RE = new RegExp(`${ESC}\\[[0-9;]*m`, "g");
|
|
4
3
|
export function stripAnsi(str) {
|
|
5
4
|
return str.replace(ANSI_RE, "");
|
|
6
5
|
}
|
|
6
|
+
const TERMINAL_SEQUENCE_RE = new RegExp([
|
|
7
|
+
"\\x1b\\[[\\x30-\\x3f]*[\\x20-\\x2f]*[\\x40-\\x7e]",
|
|
8
|
+
"\\x1b\\][^\\x07\\x1b]*(?:\\x07|\\x1b\\\\)?",
|
|
9
|
+
"\\x1bP[^\\x1b]*(?:\\x1b\\\\)?",
|
|
10
|
+
"\\x1b[\\x20-\\x2f]*[\\x30-\\x7e]",
|
|
11
|
+
"\\x9b[\\x30-\\x3f]*[\\x20-\\x2f]*[\\x40-\\x7e]",
|
|
12
|
+
"\\x9d[^\\x07\\x9c]*(?:\\x07|\\x9c)?",
|
|
13
|
+
].join("|"), "g");
|
|
14
|
+
const CONTROL_RE = /[\x00-\x08\x0b-\x1f\x7f\x80-\x9f]/g;
|
|
15
|
+
export function text(value) {
|
|
16
|
+
if (value === undefined || value === null)
|
|
17
|
+
return "";
|
|
18
|
+
return String(value).replace(TERMINAL_SEQUENCE_RE, "").replace(CONTROL_RE, "");
|
|
19
|
+
}
|
|
7
20
|
function padVisible(str, width) {
|
|
8
21
|
const needed = width - stripAnsi(str).length;
|
|
9
22
|
return needed > 0 ? str + " ".repeat(needed) : str;
|
|
10
23
|
}
|
|
11
|
-
/** Render rows as an aligned text table (two-space indent, same look as the Olympus CLI). */
|
|
12
24
|
export function formatTable(rows, columns) {
|
|
13
25
|
if (rows.length === 0)
|
|
14
26
|
return [" (no results)"];
|
|
@@ -59,24 +71,34 @@ const BADGES = {
|
|
|
59
71
|
skipped: { icon: "-", color: "gray" },
|
|
60
72
|
cancelled: { icon: "-", color: "gray" },
|
|
61
73
|
missing_fields: { icon: "○", color: "yellow" },
|
|
74
|
+
not_run: { icon: "○", color: "gray" },
|
|
75
|
+
draft: { icon: "○", color: "gray" },
|
|
76
|
+
pending_solution: { icon: "○", color: "yellow" },
|
|
77
|
+
pending_review: { icon: "○", color: "blue" },
|
|
78
|
+
finalizing_review: { icon: "⟳", color: "blue" },
|
|
79
|
+
revision_requested: { icon: "!", color: "yellow" },
|
|
80
|
+
accepted: { icon: "✓", color: "green" },
|
|
81
|
+
approved: { icon: "✓", color: "green" },
|
|
82
|
+
rejected: { icon: "✗", color: "red" },
|
|
62
83
|
};
|
|
63
|
-
/** Status badge for terminal output; colors only when asked for. */
|
|
64
84
|
export function statusBadge(status, color = false) {
|
|
65
|
-
const
|
|
85
|
+
const safe = text(status);
|
|
86
|
+
const badge = BADGES[safe] ?? { icon: "?", color: "gray" };
|
|
66
87
|
const icon = color ? `${COLORS[badge.color]}${badge.icon}${RESET}` : badge.icon;
|
|
67
|
-
return `${icon} ${
|
|
88
|
+
return `${icon} ${safe}`;
|
|
68
89
|
}
|
|
69
90
|
export function dim(text, color = false) {
|
|
70
91
|
return color ? `${COLORS.gray}${text}${RESET}` : text;
|
|
71
92
|
}
|
|
72
|
-
|
|
93
|
+
export function paint(colorName, str, color = false) {
|
|
94
|
+
return color ? `${COLORS[colorName]}${str}${RESET}` : str;
|
|
95
|
+
}
|
|
73
96
|
export function truncate(str, max) {
|
|
74
97
|
const oneLine = str.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
|
|
75
98
|
if (oneLine.length <= max)
|
|
76
99
|
return oneLine;
|
|
77
100
|
return `${oneLine.slice(0, max - 3)}...`;
|
|
78
101
|
}
|
|
79
|
-
/** Compact human duration: 850ms, 5s, 2m10s, 3h, 1h05m. */
|
|
80
102
|
export function formatDuration(ms) {
|
|
81
103
|
if (ms < 1000)
|
|
82
104
|
return `${Math.round(ms)}ms`;
|
package/dist/harbor.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type HarborBundle, type HarborMetadata } from "./contract.js";
|
|
2
|
-
/** Total text the CLI will send to a quest. Well under Convex's argument limit. */
|
|
3
2
|
export declare const MAX_BUNDLE_BYTES: number;
|
|
4
|
-
/** Command-line overrides that win over `task.toml`. */
|
|
5
3
|
export type MetadataOverrides = {
|
|
6
4
|
repo?: string;
|
|
7
5
|
commit?: string;
|
|
@@ -13,13 +11,7 @@ export type MetadataOverrides = {
|
|
|
13
11
|
export type HarborBundleWithHash = HarborBundle & {
|
|
14
12
|
inputHash: string;
|
|
15
13
|
};
|
|
16
|
-
/** Map `task.toml` tables onto `HarborMetadata`; overrides win. */
|
|
17
14
|
export declare function metadataFromToml(toml: Record<string, unknown>, overrides?: MetadataOverrides): HarborMetadata;
|
|
18
|
-
/** JSON with object keys sorted at every level, so equal content hashes equal. */
|
|
19
15
|
export declare function canonicalJson(value: unknown): string;
|
|
20
16
|
export declare function bundleInputHash(bundle: HarborBundle): string;
|
|
21
|
-
/**
|
|
22
|
-
* Read a Harbor task directory. Only the seven known paths are read; anything
|
|
23
|
-
* else in the directory is ignored. `task.toml` must exist and parse.
|
|
24
|
-
*/
|
|
25
17
|
export declare function readHarborBundle(dir: string, overrides?: MetadataOverrides): Promise<HarborBundleWithHash>;
|
package/dist/harbor.js
CHANGED
|
@@ -4,7 +4,6 @@ import { resolve } from "node:path";
|
|
|
4
4
|
import { parse as parseToml } from "smol-toml";
|
|
5
5
|
import { HARBOR_FILE_PATHS, HARBOR_FILES, } from "./contract.js";
|
|
6
6
|
import { BundleError } from "./errors.js";
|
|
7
|
-
/** Total text the CLI will send to a quest. Well under Convex's argument limit. */
|
|
8
7
|
export const MAX_BUNDLE_BYTES = 4 * 1024 * 1024;
|
|
9
8
|
function isRecord(value) {
|
|
10
9
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
@@ -20,7 +19,6 @@ function num(table, key) {
|
|
|
20
19
|
function nonEmpty(value) {
|
|
21
20
|
return value && value.trim().length > 0 ? value : undefined;
|
|
22
21
|
}
|
|
23
|
-
/** Map `task.toml` tables onto `HarborMetadata`; overrides win. */
|
|
24
22
|
export function metadataFromToml(toml, overrides = {}) {
|
|
25
23
|
const metadata = isRecord(toml.metadata) ? toml.metadata : undefined;
|
|
26
24
|
const environment = isRecord(toml.environment) ? toml.environment : undefined;
|
|
@@ -35,14 +33,12 @@ export function metadataFromToml(toml, overrides = {}) {
|
|
|
35
33
|
dockerImage: str(environment, "docker_image"),
|
|
36
34
|
verifierTimeoutSec: num(verifier, "timeout_sec"),
|
|
37
35
|
};
|
|
38
|
-
// Drop undefined keys so the wire payload and the hash only carry set fields.
|
|
39
36
|
for (const key of Object.keys(out)) {
|
|
40
37
|
if (out[key] === undefined)
|
|
41
38
|
delete out[key];
|
|
42
39
|
}
|
|
43
40
|
return out;
|
|
44
41
|
}
|
|
45
|
-
/** JSON with object keys sorted at every level, so equal content hashes equal. */
|
|
46
42
|
export function canonicalJson(value) {
|
|
47
43
|
return JSON.stringify(sortKeys(value));
|
|
48
44
|
}
|
|
@@ -71,9 +67,6 @@ function formatMiB(bytes) {
|
|
|
71
67
|
}
|
|
72
68
|
async function fileSize(path) {
|
|
73
69
|
try {
|
|
74
|
-
// lstat, not stat: a bundle from an untrusted source could point a
|
|
75
|
-
// whitelisted name at any readable file via a symlink and have its
|
|
76
|
-
// contents sent to the quest.
|
|
77
70
|
const info = await lstat(path);
|
|
78
71
|
if (info.isSymbolicLink()) {
|
|
79
72
|
throw new BundleError(`${path} is a symlink; symlinked bundle files are not read.`);
|
|
@@ -88,10 +81,6 @@ async function fileSize(path) {
|
|
|
88
81
|
throw new BundleError(`Could not read ${path}: ${error.message}`);
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Read a Harbor task directory. Only the seven known paths are read; anything
|
|
93
|
-
* else in the directory is ignored. `task.toml` must exist and parse.
|
|
94
|
-
*/
|
|
95
84
|
export async function readHarborBundle(dir, overrides = {}) {
|
|
96
85
|
const root = resolve(dir);
|
|
97
86
|
try {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isAdminOnlyCommand(rawArgs: string[]): boolean;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const ADMIN_ONLY_CHECKS = new Set(["list", "run", "status", "cancel"]);
|
|
2
|
+
export function isAdminOnlyCommand(rawArgs) {
|
|
3
|
+
const words = rawArgs.filter((arg) => !arg.startsWith("-"));
|
|
4
|
+
return words[0] === "checks" && words.length > 1 && ADMIN_ONLY_CHECKS.has(words[1]);
|
|
5
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
|
-
import { defineCommand, runCommand
|
|
3
|
+
import { defineCommand, runCommand } from "citty";
|
|
4
|
+
import { requireAdminEdition } from "./auth.js";
|
|
4
5
|
import { login, logout, whoami } from "./commands/auth.js";
|
|
5
6
|
import checks from "./commands/checks.js";
|
|
7
|
+
import { problems } from "./commands/problems.js";
|
|
6
8
|
import { quests } from "./commands/quests.js";
|
|
7
9
|
import { EXIT_USAGE, errorMessage, exitCodeForError } from "./errors.js";
|
|
10
|
+
import { text } from "./format.js";
|
|
11
|
+
import { isAdminOnlyCommand } from "./index-gate.js";
|
|
8
12
|
import { checkVersion, PACKAGE_NAME, VERSION } from "./quests.js";
|
|
13
|
+
import { createShowUsage } from "./usage.js";
|
|
9
14
|
const update = defineCommand({
|
|
10
15
|
meta: { name: "update", description: "Update the CLI to the latest published version" },
|
|
11
16
|
args: {
|
|
@@ -34,10 +39,11 @@ const main = defineCommand({
|
|
|
34
39
|
meta: {
|
|
35
40
|
name: "shipd",
|
|
36
41
|
version: VERSION,
|
|
37
|
-
description: "Shipd
|
|
42
|
+
description: "Shipd CLI: your quest challenges and their checks (author edition); ad-hoc quest checks on Harbor tasks or existing tasks (admin edition)",
|
|
38
43
|
},
|
|
39
|
-
subCommands: { login, logout, whoami, quests, checks, update, version },
|
|
44
|
+
subCommands: { login, logout, whoami, quests, problems, checks, update, version },
|
|
40
45
|
});
|
|
46
|
+
const showUsage = createShowUsage(main, { problems, checks });
|
|
41
47
|
async function run() {
|
|
42
48
|
const rawArgs = process.argv.slice(2);
|
|
43
49
|
if (rawArgs.length === 0 || rawArgs.includes("--help") || rawArgs.includes("-h")) {
|
|
@@ -48,21 +54,21 @@ async function run() {
|
|
|
48
54
|
console.log(VERSION);
|
|
49
55
|
return;
|
|
50
56
|
}
|
|
51
|
-
// Warn about an outdated CLI without blocking the command.
|
|
52
|
-
void checkVersion(questFromArgs(rawArgs)).catch(() => { });
|
|
53
57
|
try {
|
|
58
|
+
if (isAdminOnlyCommand(rawArgs))
|
|
59
|
+
requireAdminEdition();
|
|
60
|
+
void checkVersion(questFromArgs(rawArgs)).catch(() => { });
|
|
54
61
|
await runCommand(main, { rawArgs });
|
|
55
62
|
}
|
|
56
63
|
catch (error) {
|
|
57
64
|
const name = error instanceof Error ? error.name : "";
|
|
58
65
|
if (name === "CLIError") {
|
|
59
|
-
// citty's own usage errors (unknown command, missing argument).
|
|
60
66
|
await showUsageFor(rawArgs);
|
|
61
|
-
console.error(`\n Error: ${errorMessage(error)}\n`);
|
|
67
|
+
console.error(`\n Error: ${text(errorMessage(error))}\n`);
|
|
62
68
|
process.exitCode = EXIT_USAGE;
|
|
63
69
|
return;
|
|
64
70
|
}
|
|
65
|
-
console.error(`\n Error: ${errorMessage(error)}\n`);
|
|
71
|
+
console.error(`\n Error: ${text(errorMessage(error))}\n`);
|
|
66
72
|
process.exitCode = exitCodeForError(error);
|
|
67
73
|
}
|
|
68
74
|
}
|
|
@@ -77,8 +83,6 @@ function questFromArgs(rawArgs) {
|
|
|
77
83
|
return undefined;
|
|
78
84
|
}
|
|
79
85
|
async function showUsageFor(rawArgs) {
|
|
80
|
-
// Resolve the deepest sub-command named on the command line so `shipd checks run --help`
|
|
81
|
-
// prints the right usage.
|
|
82
86
|
let cmd = main;
|
|
83
87
|
let parent;
|
|
84
88
|
for (const arg of rawArgs) {
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export type ProblemSummary = {
|
|
2
|
+
_id: string;
|
|
3
|
+
_creationTime?: number;
|
|
4
|
+
title?: string;
|
|
5
|
+
status?: string;
|
|
6
|
+
language?: string;
|
|
7
|
+
category?: string;
|
|
8
|
+
difficulty?: string;
|
|
9
|
+
githubRepoUrl?: string;
|
|
10
|
+
githubCommitHash?: string;
|
|
11
|
+
};
|
|
12
|
+
export type VersionSummary = {
|
|
13
|
+
_id: string;
|
|
14
|
+
_creationTime?: number;
|
|
15
|
+
version: number;
|
|
16
|
+
isLocked?: boolean;
|
|
17
|
+
title?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
language?: string;
|
|
20
|
+
category?: string;
|
|
21
|
+
difficulty?: string;
|
|
22
|
+
githubRepoUrl?: string;
|
|
23
|
+
githubCommitHash?: string;
|
|
24
|
+
dockerfile?: string;
|
|
25
|
+
testPatch?: string;
|
|
26
|
+
solutionPatch?: string;
|
|
27
|
+
};
|
|
28
|
+
export type ProblemWithLatestVersion = ProblemSummary & {
|
|
29
|
+
latestVersion?: VersionSummary | null;
|
|
30
|
+
};
|
|
31
|
+
export type PrecheckCheck = {
|
|
32
|
+
id?: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
status?: string;
|
|
35
|
+
message?: string;
|
|
36
|
+
};
|
|
37
|
+
export type PrecheckStage = {
|
|
38
|
+
id?: string;
|
|
39
|
+
name?: string;
|
|
40
|
+
status?: string;
|
|
41
|
+
stale?: boolean;
|
|
42
|
+
missingFields?: string[];
|
|
43
|
+
checks?: PrecheckCheck[];
|
|
44
|
+
};
|
|
45
|
+
export declare function precheckStages(results: unknown): PrecheckStage[];
|
|
46
|
+
export type SubmissionReadiness = {
|
|
47
|
+
criteria: Array<{
|
|
48
|
+
id: string;
|
|
49
|
+
label: string;
|
|
50
|
+
status: string;
|
|
51
|
+
detail?: string;
|
|
52
|
+
stale?: boolean;
|
|
53
|
+
}>;
|
|
54
|
+
canSubmit: boolean;
|
|
55
|
+
};
|
|
56
|
+
export type AgentRunCriteria = {
|
|
57
|
+
criteria?: Array<{
|
|
58
|
+
id: string;
|
|
59
|
+
label: string;
|
|
60
|
+
status: string;
|
|
61
|
+
detail?: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
guidance?: string;
|
|
64
|
+
preview?: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
export type TrialQaStatus = {
|
|
68
|
+
state: string;
|
|
69
|
+
canRun: boolean;
|
|
70
|
+
hasEligibleRuns: boolean;
|
|
71
|
+
runsChangedSinceCheck?: boolean;
|
|
72
|
+
runRuleWaitsOn?: string | null;
|
|
73
|
+
tokenCost?: number;
|
|
74
|
+
currentStep?: string;
|
|
75
|
+
warnings?: string[];
|
|
76
|
+
};
|
|
77
|
+
export type DynamicCheckRecord = Record<string, {
|
|
78
|
+
jobId?: string;
|
|
79
|
+
status: string;
|
|
80
|
+
progress?: number;
|
|
81
|
+
currentStep?: string;
|
|
82
|
+
error?: string;
|
|
83
|
+
output?: Record<string, unknown>;
|
|
84
|
+
createdAt?: number;
|
|
85
|
+
completedAt?: number;
|
|
86
|
+
stale?: boolean;
|
|
87
|
+
}>;
|
|
88
|
+
export type DynamicCheckEntry = DynamicCheckRecord[string] & {
|
|
89
|
+
key: string;
|
|
90
|
+
overridden?: boolean;
|
|
91
|
+
};
|
|
92
|
+
export declare function normalizeDynamicChecks(dynamicChecks: unknown): DynamicCheckRecord;
|
|
93
|
+
export declare function getDynamicCheckEntries(dynamicChecks: unknown): DynamicCheckEntry[];
|
|
94
|
+
export declare function formatDynamicCheckLabel(key: string): string;
|
package/dist/model.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const DYNAMIC_CHECK_ORDER = [
|
|
2
|
+
"verifyBuild",
|
|
3
|
+
"verifyTests",
|
|
4
|
+
"verifySolution",
|
|
5
|
+
"verifyFlakiness",
|
|
6
|
+
"descriptionQuality",
|
|
7
|
+
"solutionQuality",
|
|
8
|
+
"rewardHacking",
|
|
9
|
+
"verifyFairness",
|
|
10
|
+
"crossRunAnalysis",
|
|
11
|
+
"rolloutCoach",
|
|
12
|
+
];
|
|
13
|
+
const DYNAMIC_CHECK_LABELS = {
|
|
14
|
+
verifyBuild: "Verify Build",
|
|
15
|
+
verifyTests: "Verify Tests",
|
|
16
|
+
verifySolution: "Verify Solution",
|
|
17
|
+
verifyFlakiness: "Verify Flakiness",
|
|
18
|
+
descriptionQuality: "Task Prompt Quality",
|
|
19
|
+
solutionQuality: "Solution Quality",
|
|
20
|
+
rewardHacking: "Reward Hacking",
|
|
21
|
+
verifyFairness: "Test Quality",
|
|
22
|
+
crossRunAnalysis: "Holistic Check",
|
|
23
|
+
rolloutCoach: "Rollout Coach",
|
|
24
|
+
};
|
|
25
|
+
export function precheckStages(results) {
|
|
26
|
+
if (Array.isArray(results))
|
|
27
|
+
return results;
|
|
28
|
+
if (!results || typeof results !== "object")
|
|
29
|
+
return [];
|
|
30
|
+
return Object.values(results);
|
|
31
|
+
}
|
|
32
|
+
function orderIndex(order, value) {
|
|
33
|
+
const index = order.indexOf(value);
|
|
34
|
+
return index === -1 ? Number.MAX_SAFE_INTEGER : index;
|
|
35
|
+
}
|
|
36
|
+
export function normalizeDynamicChecks(dynamicChecks) {
|
|
37
|
+
if (!dynamicChecks || typeof dynamicChecks !== "object" || Array.isArray(dynamicChecks)) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
return Object.fromEntries(Object.entries(dynamicChecks).filter(([key, value]) => {
|
|
41
|
+
return (!key.startsWith("_") &&
|
|
42
|
+
!!value &&
|
|
43
|
+
typeof value === "object" &&
|
|
44
|
+
!Array.isArray(value) &&
|
|
45
|
+
"status" in value);
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
export function getDynamicCheckEntries(dynamicChecks) {
|
|
49
|
+
const record = normalizeDynamicChecks(dynamicChecks);
|
|
50
|
+
const flags = dynamicChecks && typeof dynamicChecks === "object" && !Array.isArray(dynamicChecks)
|
|
51
|
+
? dynamicChecks
|
|
52
|
+
: {};
|
|
53
|
+
return Object.entries(record)
|
|
54
|
+
.map(([key, value]) => ({
|
|
55
|
+
key,
|
|
56
|
+
...value,
|
|
57
|
+
overridden: flags[`_${key}Overridden`] != null ? true : undefined,
|
|
58
|
+
}))
|
|
59
|
+
.sort((a, b) => {
|
|
60
|
+
const orderDelta = orderIndex(DYNAMIC_CHECK_ORDER, a.key) - orderIndex(DYNAMIC_CHECK_ORDER, b.key);
|
|
61
|
+
if (orderDelta !== 0)
|
|
62
|
+
return orderDelta;
|
|
63
|
+
return a.key.localeCompare(b.key);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function formatDynamicCheckLabel(key) {
|
|
67
|
+
return DYNAMIC_CHECK_LABELS[key] ?? key;
|
|
68
|
+
}
|