@shipd-ai/cli 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -7
- package/dist/checks-view.d.ts +2 -1
- package/dist/checks-view.js +3 -2
- package/dist/commands/author-checks.d.ts +42 -1
- package/dist/commands/author-checks.js +71 -6
- package/dist/commands/author-content.d.ts +198 -0
- package/dist/commands/author-content.js +102 -0
- package/dist/commands/checks.js +1 -1
- package/dist/commands/problems.js +9 -2
- package/dist/commands/runs.d.ts +54 -0
- package/dist/commands/runs.js +143 -0
- package/dist/content.d.ts +105 -0
- package/dist/content.js +240 -0
- package/dist/index.js +4 -3
- package/dist/model.d.ts +34 -0
- package/dist/runs.d.ts +36 -0
- package/dist/runs.js +59 -0
- package/package.json +2 -2
package/dist/commands/checks.js
CHANGED
|
@@ -667,7 +667,7 @@ const cancel = defineCommand({
|
|
|
667
667
|
export default defineCommand({
|
|
668
668
|
meta: {
|
|
669
669
|
name: "checks",
|
|
670
|
-
description: "Your challenges' checks (view, run-check, run-all, run-prechecks, run-trial-qa, wait); ad-hoc quest checks for admins (list, run, status, cancel)",
|
|
670
|
+
description: "Your challenges' checks (view, run-check, run-all, run-prechecks, run-scope-gate, run-trial-qa, wait); ad-hoc quest checks for admins (list, run, status, cancel)",
|
|
671
671
|
},
|
|
672
672
|
subCommands: { ...authorChecks, list, run, status, cancel },
|
|
673
673
|
});
|
|
@@ -4,6 +4,7 @@ import { UsageError } from "../errors.js";
|
|
|
4
4
|
import { dim, paint, printJson, printKeyValue, printTable, statusBadge, text, truncate, } from "../format.js";
|
|
5
5
|
import { DEFAULT_QUEST } from "../quests.js";
|
|
6
6
|
import { printPrechecks, printQualityChecks, printReadiness, printTrialQa, questArg, } from "./author-checks.js";
|
|
7
|
+
import { create, pull, push } from "./author-content.js";
|
|
7
8
|
const DEFAULT_LIMIT = 30;
|
|
8
9
|
const color = () => Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
9
10
|
function field(value) {
|
|
@@ -151,6 +152,9 @@ const view = defineCommand({
|
|
|
151
152
|
console.log(` shipd checks run-all ${problemId}${questFlag} Run the quality checks`);
|
|
152
153
|
console.log(` shipd checks run-trial-qa ${problemId}${questFlag} Run Trial QA`);
|
|
153
154
|
console.log(` shipd problems versions ${problemId}${questFlag} List all versions`);
|
|
155
|
+
console.log(` shipd problems pull ${problemId} -d <dir>${questFlag} Write the content as files`);
|
|
156
|
+
console.log(` shipd problems push ${problemId} -d <dir>${questFlag} Save edited files`);
|
|
157
|
+
console.log(` shipd runs list ${problemId}${questFlag} Agent runs (download their files)`);
|
|
154
158
|
console.log("");
|
|
155
159
|
},
|
|
156
160
|
});
|
|
@@ -184,6 +188,9 @@ const versions = defineCommand({
|
|
|
184
188
|
},
|
|
185
189
|
});
|
|
186
190
|
export const problems = defineCommand({
|
|
187
|
-
meta: {
|
|
188
|
-
|
|
191
|
+
meta: {
|
|
192
|
+
name: "problems",
|
|
193
|
+
description: "Your challenges: list, view, versions; create, pull and push their content",
|
|
194
|
+
},
|
|
195
|
+
subCommands: { list, view, versions, create, pull, push },
|
|
189
196
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const list: import("citty").CommandDef<{
|
|
2
|
+
readonly json: {
|
|
3
|
+
readonly type: "boolean";
|
|
4
|
+
readonly description: "Output as JSON";
|
|
5
|
+
};
|
|
6
|
+
readonly quest: {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly description: "Quest to talk to (default: olympus)";
|
|
9
|
+
readonly default: "olympus";
|
|
10
|
+
};
|
|
11
|
+
readonly id: {
|
|
12
|
+
readonly type: "positional";
|
|
13
|
+
readonly description: "Challenge ID";
|
|
14
|
+
readonly required: true;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
export declare const download: import("citty").CommandDef<{
|
|
18
|
+
readonly json: {
|
|
19
|
+
readonly type: "boolean";
|
|
20
|
+
readonly description: "Output the saved paths as JSON";
|
|
21
|
+
};
|
|
22
|
+
readonly quest: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
readonly description: "Quest to talk to (default: olympus)";
|
|
25
|
+
readonly default: "olympus";
|
|
26
|
+
};
|
|
27
|
+
readonly id: {
|
|
28
|
+
readonly type: "positional";
|
|
29
|
+
readonly description: "Challenge ID";
|
|
30
|
+
readonly required: true;
|
|
31
|
+
};
|
|
32
|
+
readonly run: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
readonly description: "Run id (from `runs list`)";
|
|
35
|
+
};
|
|
36
|
+
readonly all: {
|
|
37
|
+
readonly type: "boolean";
|
|
38
|
+
readonly description: "Every run on the latest version";
|
|
39
|
+
};
|
|
40
|
+
readonly artifact: {
|
|
41
|
+
readonly type: "string";
|
|
42
|
+
readonly description: `Comma-separated files: ${string} (default: all)`;
|
|
43
|
+
};
|
|
44
|
+
readonly "all-artifacts": {
|
|
45
|
+
readonly type: "boolean";
|
|
46
|
+
readonly description: "Every file the run detail offers";
|
|
47
|
+
};
|
|
48
|
+
readonly dir: {
|
|
49
|
+
readonly type: "string";
|
|
50
|
+
readonly alias: "d";
|
|
51
|
+
readonly description: "Directory to write into (default: runs)";
|
|
52
|
+
};
|
|
53
|
+
}>;
|
|
54
|
+
export declare const runs: import("citty").CommandDef<import("citty").ArgsDef>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { defineCommand } from "citty";
|
|
2
|
+
import { api, backend, connectAuthor, requireProblemVersion } from "../author.js";
|
|
3
|
+
import { errorMessage, RefusedError } from "../errors.js";
|
|
4
|
+
import { paint, printJson, printTable, statusBadge, text, truncate } from "../format.js";
|
|
5
|
+
import { artifactPath, downloadArtifact, parseArtifactKeys, RUN_ARTIFACT_KEYS, runLabel, selectRuns, } from "../runs.js";
|
|
6
|
+
import { questArg } from "./author-checks.js";
|
|
7
|
+
const color = () => Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
8
|
+
async function loadRuns(quest, problemId) {
|
|
9
|
+
const client = await connectAuthor(quest);
|
|
10
|
+
const { version } = await requireProblemVersion(client, problemId);
|
|
11
|
+
const runs = (await backend(() => client.query(api.runAgentRuns.getAgentRuns, { versionId: version._id })));
|
|
12
|
+
return { client, version, runs: Array.isArray(runs) ? runs : [] };
|
|
13
|
+
}
|
|
14
|
+
function when(ms) {
|
|
15
|
+
return ms ? new Date(ms).toISOString().replace("T", " ").slice(0, 16) : "";
|
|
16
|
+
}
|
|
17
|
+
export const list = defineCommand({
|
|
18
|
+
meta: { name: "list", description: "List a challenge's agent runs on its latest version" },
|
|
19
|
+
args: {
|
|
20
|
+
id: { type: "positional", description: "Challenge ID", required: true },
|
|
21
|
+
...questArg,
|
|
22
|
+
json: { type: "boolean", description: "Output as JSON" },
|
|
23
|
+
},
|
|
24
|
+
run: async ({ args }) => {
|
|
25
|
+
const { version, runs } = await loadRuns(args.quest, args.id);
|
|
26
|
+
if (args.json) {
|
|
27
|
+
printJson(runs);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (runs.length === 0) {
|
|
31
|
+
console.log(` No agent runs on v${version.version}.`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const c = color();
|
|
35
|
+
console.log(`\n Agent runs on v${version.version}\n`);
|
|
36
|
+
printTable(runs.map((run) => ({
|
|
37
|
+
id: text(run.id),
|
|
38
|
+
agent: text(runLabel(run)),
|
|
39
|
+
status: statusBadge(text(run.status ?? "unknown"), c),
|
|
40
|
+
verdict: text(run.verdict ?? ""),
|
|
41
|
+
flags: [
|
|
42
|
+
run.hinted ? "hinted" : "",
|
|
43
|
+
run.stale ? "stale" : "",
|
|
44
|
+
run.scratched ? "scratched" : "",
|
|
45
|
+
run.legacy ? "legacy" : "",
|
|
46
|
+
]
|
|
47
|
+
.filter(Boolean)
|
|
48
|
+
.join(","),
|
|
49
|
+
started: when(run.createdAt),
|
|
50
|
+
finished: when(run.completedAt),
|
|
51
|
+
})), [
|
|
52
|
+
{ key: "id", label: "Run" },
|
|
53
|
+
{ key: "agent", label: "Agent", width: 10 },
|
|
54
|
+
{ key: "status", label: "Status", width: 20 },
|
|
55
|
+
{ key: "verdict", label: "Verdict", width: 30 },
|
|
56
|
+
{ key: "flags", label: "Flags", width: 16 },
|
|
57
|
+
{ key: "started", label: "Started", width: 17 },
|
|
58
|
+
{ key: "finished", label: "Finished", width: 17 },
|
|
59
|
+
]);
|
|
60
|
+
for (const run of runs) {
|
|
61
|
+
if (run.error) {
|
|
62
|
+
console.log(` ${paint("red", `${text(run.id)}: ${truncate(text(run.error), 90)}`, c)}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
console.log(`\n Download: shipd runs download ${text(args.id)} --run <Run> [--artifact ${RUN_ARTIFACT_KEYS.join("|")}] -d <dir>\n`);
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
export const download = defineCommand({
|
|
69
|
+
meta: { name: "download", description: "Download a run's files (trajectory, diffs, logs)" },
|
|
70
|
+
args: {
|
|
71
|
+
id: { type: "positional", description: "Challenge ID", required: true },
|
|
72
|
+
run: { type: "string", description: "Run id (from `runs list`)" },
|
|
73
|
+
all: { type: "boolean", description: "Every run on the latest version" },
|
|
74
|
+
artifact: {
|
|
75
|
+
type: "string",
|
|
76
|
+
description: `Comma-separated files: ${RUN_ARTIFACT_KEYS.join(", ")} (default: all)`,
|
|
77
|
+
},
|
|
78
|
+
"all-artifacts": { type: "boolean", description: "Every file the run detail offers" },
|
|
79
|
+
dir: { type: "string", alias: "d", description: "Directory to write into (default: runs)" },
|
|
80
|
+
...questArg,
|
|
81
|
+
json: { type: "boolean", description: "Output the saved paths as JSON" },
|
|
82
|
+
},
|
|
83
|
+
run: async ({ args }) => {
|
|
84
|
+
const keys = parseArtifactKeys(args.artifact, args["all-artifacts"]);
|
|
85
|
+
const { client, version, runs } = await loadRuns(args.quest, args.id);
|
|
86
|
+
const selected = selectRuns(runs, args.run, args.all);
|
|
87
|
+
const dir = args.dir ?? "runs";
|
|
88
|
+
const saved = [];
|
|
89
|
+
const skipped = [];
|
|
90
|
+
for (const run of selected) {
|
|
91
|
+
if (!run.jobId) {
|
|
92
|
+
skipped.push({ run: run.id, artifact: "*", reason: "no job recorded for this run" });
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const jobId = run.jobId;
|
|
96
|
+
for (const key of keys) {
|
|
97
|
+
let url;
|
|
98
|
+
try {
|
|
99
|
+
url = (await backend(() => client.action(api.artifactProxy.fetchArtifact, {
|
|
100
|
+
jobId,
|
|
101
|
+
artifactKey: key,
|
|
102
|
+
versionId: version._id,
|
|
103
|
+
})));
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
skipped.push({ run: run.id, artifact: key, reason: errorMessage(error) });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!url) {
|
|
110
|
+
skipped.push({ run: run.id, artifact: key, reason: "not available" });
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const dest = artifactPath(dir, run.id, key);
|
|
114
|
+
try {
|
|
115
|
+
const bytes = await downloadArtifact(url, dest);
|
|
116
|
+
saved.push({ run: run.id, artifact: key, path: dest, bytes });
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
skipped.push({ run: run.id, artifact: key, reason: errorMessage(error) });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (args.json) {
|
|
124
|
+
printJson({ saved, skipped });
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.log("");
|
|
128
|
+
for (const item of saved)
|
|
129
|
+
console.log(` saved ${item.path} (${item.bytes} bytes)`);
|
|
130
|
+
for (const item of skipped) {
|
|
131
|
+
console.log(` skipped ${text(item.run)} ${item.artifact}: ${item.reason}`);
|
|
132
|
+
}
|
|
133
|
+
console.log("");
|
|
134
|
+
}
|
|
135
|
+
if (saved.length === 0) {
|
|
136
|
+
throw new RefusedError("Nothing downloaded.");
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
export const runs = defineCommand({
|
|
141
|
+
meta: { name: "runs", description: "Your challenges' agent runs and their files" },
|
|
142
|
+
subCommands: { list, download },
|
|
143
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ProblemWithLatestVersion, VersionSummary } from "./model.js";
|
|
2
|
+
export declare const CONTENT_FILES: {
|
|
3
|
+
readonly description: "description.md";
|
|
4
|
+
readonly dockerfile: "Dockerfile";
|
|
5
|
+
readonly testPatch: "test.patch";
|
|
6
|
+
readonly solutionPatch: "solution.patch";
|
|
7
|
+
readonly solutionApproach: "approach.md";
|
|
8
|
+
readonly environmentDescription: "environment.md";
|
|
9
|
+
readonly hintText: "hint.md";
|
|
10
|
+
readonly hintJustification: "hint-justification.md";
|
|
11
|
+
};
|
|
12
|
+
export type ContentFileField = keyof typeof CONTENT_FILES;
|
|
13
|
+
export declare const TASK_JSON_FIELDS: readonly ["title", "language", "category", "difficulty", "githubRepoUrl", "githubCommitHash", "githubIssueUrl", "testOutputMode", "estimatedLOC"];
|
|
14
|
+
export type TaskJsonField = (typeof TASK_JSON_FIELDS)[number];
|
|
15
|
+
export declare const TASK_JSON = "task.json";
|
|
16
|
+
export declare const TEST_OUTPUT_MODES: readonly ["exit_code", "junit_xml"];
|
|
17
|
+
export type DraftUpdates = Partial<Record<ContentFileField | Exclude<TaskJsonField, "estimatedLOC">, string> & {
|
|
18
|
+
estimatedLOC: number;
|
|
19
|
+
}>;
|
|
20
|
+
export type DraftContent = {
|
|
21
|
+
task: Partial<Record<TaskJsonField, string | number>>;
|
|
22
|
+
files: Partial<Record<ContentFileField, string>>;
|
|
23
|
+
};
|
|
24
|
+
export declare function contentFromChallenge(problem: ProblemWithLatestVersion, version: VersionSummary | null | undefined): DraftContent;
|
|
25
|
+
export declare function writeContentDir(dir: string, content: DraftContent): {
|
|
26
|
+
written: string[];
|
|
27
|
+
removed: string[];
|
|
28
|
+
};
|
|
29
|
+
export declare function readContentDir(dir: string): DraftUpdates;
|
|
30
|
+
export declare function parseEstimatedLoc(value: string): number;
|
|
31
|
+
export declare function parseTestOutputMode(value: string): string;
|
|
32
|
+
export declare const FIELD_FLAGS: {
|
|
33
|
+
readonly title: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
readonly description: "Title";
|
|
36
|
+
};
|
|
37
|
+
readonly language: {
|
|
38
|
+
readonly type: "string";
|
|
39
|
+
readonly description: "Language (as the page lists it)";
|
|
40
|
+
};
|
|
41
|
+
readonly category: {
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
readonly description: "Category (as the page lists it)";
|
|
44
|
+
};
|
|
45
|
+
readonly difficulty: {
|
|
46
|
+
readonly type: "string";
|
|
47
|
+
readonly description: "Difficulty (as the page lists it)";
|
|
48
|
+
};
|
|
49
|
+
readonly repo: {
|
|
50
|
+
readonly type: "string";
|
|
51
|
+
readonly description: "GitHub repository URL";
|
|
52
|
+
};
|
|
53
|
+
readonly commit: {
|
|
54
|
+
readonly type: "string";
|
|
55
|
+
readonly description: "Commit hash";
|
|
56
|
+
};
|
|
57
|
+
readonly issue: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
readonly description: "GitHub issue URL";
|
|
60
|
+
};
|
|
61
|
+
readonly "test-output-mode": {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
readonly description: `Test output mode: ${string}`;
|
|
64
|
+
};
|
|
65
|
+
readonly "estimated-loc": {
|
|
66
|
+
readonly type: "string";
|
|
67
|
+
readonly description: "Estimated lines of code (whole number)";
|
|
68
|
+
};
|
|
69
|
+
readonly "description-file": {
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
readonly description: "File holding the description (- = stdin)";
|
|
72
|
+
};
|
|
73
|
+
readonly "dockerfile-file": {
|
|
74
|
+
readonly type: "string";
|
|
75
|
+
readonly description: "File holding the Dockerfile (- = stdin)";
|
|
76
|
+
};
|
|
77
|
+
readonly "test-patch-file": {
|
|
78
|
+
readonly type: "string";
|
|
79
|
+
readonly description: "File holding the test patch (- = stdin)";
|
|
80
|
+
};
|
|
81
|
+
readonly "solution-patch-file": {
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
readonly description: "File holding the solution patch (- = stdin)";
|
|
84
|
+
};
|
|
85
|
+
readonly "approach-file": {
|
|
86
|
+
readonly type: "string";
|
|
87
|
+
readonly description: "File holding the solution approach (- = stdin)";
|
|
88
|
+
};
|
|
89
|
+
readonly "env-file": {
|
|
90
|
+
readonly type: "string";
|
|
91
|
+
readonly description: "File holding the environment description (- = stdin)";
|
|
92
|
+
};
|
|
93
|
+
readonly "hint-file": {
|
|
94
|
+
readonly type: "string";
|
|
95
|
+
readonly description: "File holding the hint (- = stdin)";
|
|
96
|
+
};
|
|
97
|
+
readonly "hint-justification-file": {
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
readonly description: "File holding the hint justification (- = stdin)";
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
export type FieldFlagValues = Partial<Record<keyof typeof FIELD_FLAGS, string | undefined>>;
|
|
103
|
+
export declare function updatesFromFlags(flags: FieldFlagValues, base?: DraftUpdates, readStdin?: () => string): DraftUpdates;
|
|
104
|
+
export declare function applyClears(updates: DraftUpdates, clear: string | undefined): DraftUpdates;
|
|
105
|
+
export declare function countFields(updates: DraftUpdates): number;
|
package/dist/content.js
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { UsageError } from "./errors.js";
|
|
4
|
+
export const CONTENT_FILES = {
|
|
5
|
+
description: "description.md",
|
|
6
|
+
dockerfile: "Dockerfile",
|
|
7
|
+
testPatch: "test.patch",
|
|
8
|
+
solutionPatch: "solution.patch",
|
|
9
|
+
solutionApproach: "approach.md",
|
|
10
|
+
environmentDescription: "environment.md",
|
|
11
|
+
hintText: "hint.md",
|
|
12
|
+
hintJustification: "hint-justification.md",
|
|
13
|
+
};
|
|
14
|
+
export const TASK_JSON_FIELDS = [
|
|
15
|
+
"title",
|
|
16
|
+
"language",
|
|
17
|
+
"category",
|
|
18
|
+
"difficulty",
|
|
19
|
+
"githubRepoUrl",
|
|
20
|
+
"githubCommitHash",
|
|
21
|
+
"githubIssueUrl",
|
|
22
|
+
"testOutputMode",
|
|
23
|
+
"estimatedLOC",
|
|
24
|
+
];
|
|
25
|
+
export const TASK_JSON = "task.json";
|
|
26
|
+
export const TEST_OUTPUT_MODES = ["exit_code", "junit_xml"];
|
|
27
|
+
export function contentFromChallenge(problem, version) {
|
|
28
|
+
const task = {};
|
|
29
|
+
const source = { ...problem, ...(version ?? {}) };
|
|
30
|
+
if (typeof problem.title === "string")
|
|
31
|
+
task.title = problem.title;
|
|
32
|
+
for (const field of TASK_JSON_FIELDS) {
|
|
33
|
+
if (field === "title")
|
|
34
|
+
continue;
|
|
35
|
+
const value = source[field];
|
|
36
|
+
if (field === "estimatedLOC") {
|
|
37
|
+
if (typeof value === "number")
|
|
38
|
+
task.estimatedLOC = value;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === "string" && value.length > 0)
|
|
42
|
+
task[field] = value;
|
|
43
|
+
}
|
|
44
|
+
const files = {};
|
|
45
|
+
for (const field of Object.keys(CONTENT_FILES)) {
|
|
46
|
+
const value = version?.[field];
|
|
47
|
+
if (typeof value === "string" && value.length > 0)
|
|
48
|
+
files[field] = value;
|
|
49
|
+
}
|
|
50
|
+
return { task, files };
|
|
51
|
+
}
|
|
52
|
+
export function writeContentDir(dir, content) {
|
|
53
|
+
mkdirSync(dir, { recursive: true });
|
|
54
|
+
const written = [];
|
|
55
|
+
const removed = [];
|
|
56
|
+
const taskPath = join(dir, TASK_JSON);
|
|
57
|
+
writeFileSync(taskPath, `${JSON.stringify(content.task, null, 2)}\n`);
|
|
58
|
+
written.push(taskPath);
|
|
59
|
+
for (const [field, filename] of Object.entries(CONTENT_FILES)) {
|
|
60
|
+
const value = content.files[field];
|
|
61
|
+
const path = join(dir, filename);
|
|
62
|
+
if (value === undefined) {
|
|
63
|
+
if (existsSync(path)) {
|
|
64
|
+
rmSync(path);
|
|
65
|
+
removed.push(path);
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
writeFileSync(path, value);
|
|
70
|
+
written.push(path);
|
|
71
|
+
}
|
|
72
|
+
return { written, removed };
|
|
73
|
+
}
|
|
74
|
+
function parseTaskJson(path) {
|
|
75
|
+
let parsed;
|
|
76
|
+
try {
|
|
77
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
throw new UsageError(`${path} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
81
|
+
}
|
|
82
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
83
|
+
throw new UsageError(`${path} must hold a JSON object.`);
|
|
84
|
+
}
|
|
85
|
+
const updates = {};
|
|
86
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
87
|
+
if (!TASK_JSON_FIELDS.includes(key)) {
|
|
88
|
+
throw new UsageError(`${path}: unknown field "${key}". Fields: ${TASK_JSON_FIELDS.join(", ")}.`);
|
|
89
|
+
}
|
|
90
|
+
if (value === null || value === undefined)
|
|
91
|
+
continue;
|
|
92
|
+
if (key === "estimatedLOC") {
|
|
93
|
+
updates.estimatedLOC = parseEstimatedLoc(String(value));
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (typeof value !== "string") {
|
|
97
|
+
throw new UsageError(`${path}: "${key}" must be a string.`);
|
|
98
|
+
}
|
|
99
|
+
if (key === "testOutputMode") {
|
|
100
|
+
updates.testOutputMode = parseTestOutputMode(value);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
updates[key] = value;
|
|
104
|
+
}
|
|
105
|
+
return updates;
|
|
106
|
+
}
|
|
107
|
+
export function readContentDir(dir) {
|
|
108
|
+
if (!existsSync(dir))
|
|
109
|
+
throw new UsageError(`Directory not found: ${dir}`);
|
|
110
|
+
const updates = {};
|
|
111
|
+
const taskPath = join(dir, TASK_JSON);
|
|
112
|
+
if (existsSync(taskPath))
|
|
113
|
+
Object.assign(updates, parseTaskJson(taskPath));
|
|
114
|
+
for (const [field, filename] of Object.entries(CONTENT_FILES)) {
|
|
115
|
+
const path = join(dir, filename);
|
|
116
|
+
if (existsSync(path))
|
|
117
|
+
updates[field] = readFileSync(path, "utf8");
|
|
118
|
+
}
|
|
119
|
+
return updates;
|
|
120
|
+
}
|
|
121
|
+
export function parseEstimatedLoc(value) {
|
|
122
|
+
const n = Number.parseInt(value, 10);
|
|
123
|
+
if (!Number.isFinite(n) || n < 0 || String(n) !== value.trim()) {
|
|
124
|
+
throw new UsageError(`estimatedLOC must be a whole number, got "${value}".`);
|
|
125
|
+
}
|
|
126
|
+
return n;
|
|
127
|
+
}
|
|
128
|
+
export function parseTestOutputMode(value) {
|
|
129
|
+
if (!TEST_OUTPUT_MODES.includes(value)) {
|
|
130
|
+
throw new UsageError(`testOutputMode must be one of ${TEST_OUTPUT_MODES.join(", ")}.`);
|
|
131
|
+
}
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
export const FIELD_FLAGS = {
|
|
135
|
+
title: { type: "string", description: "Title" },
|
|
136
|
+
language: { type: "string", description: "Language (as the page lists it)" },
|
|
137
|
+
category: { type: "string", description: "Category (as the page lists it)" },
|
|
138
|
+
difficulty: { type: "string", description: "Difficulty (as the page lists it)" },
|
|
139
|
+
repo: { type: "string", description: "GitHub repository URL" },
|
|
140
|
+
commit: { type: "string", description: "Commit hash" },
|
|
141
|
+
issue: { type: "string", description: "GitHub issue URL" },
|
|
142
|
+
"test-output-mode": {
|
|
143
|
+
type: "string",
|
|
144
|
+
description: `Test output mode: ${TEST_OUTPUT_MODES.join(" | ")}`,
|
|
145
|
+
},
|
|
146
|
+
"estimated-loc": { type: "string", description: "Estimated lines of code (whole number)" },
|
|
147
|
+
"description-file": { type: "string", description: "File holding the description (- = stdin)" },
|
|
148
|
+
"dockerfile-file": { type: "string", description: "File holding the Dockerfile (- = stdin)" },
|
|
149
|
+
"test-patch-file": { type: "string", description: "File holding the test patch (- = stdin)" },
|
|
150
|
+
"solution-patch-file": {
|
|
151
|
+
type: "string",
|
|
152
|
+
description: "File holding the solution patch (- = stdin)",
|
|
153
|
+
},
|
|
154
|
+
"approach-file": {
|
|
155
|
+
type: "string",
|
|
156
|
+
description: "File holding the solution approach (- = stdin)",
|
|
157
|
+
},
|
|
158
|
+
"env-file": {
|
|
159
|
+
type: "string",
|
|
160
|
+
description: "File holding the environment description (- = stdin)",
|
|
161
|
+
},
|
|
162
|
+
"hint-file": { type: "string", description: "File holding the hint (- = stdin)" },
|
|
163
|
+
"hint-justification-file": {
|
|
164
|
+
type: "string",
|
|
165
|
+
description: "File holding the hint justification (- = stdin)",
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
const VALUE_FLAGS = {
|
|
169
|
+
title: "title",
|
|
170
|
+
language: "language",
|
|
171
|
+
category: "category",
|
|
172
|
+
difficulty: "difficulty",
|
|
173
|
+
repo: "githubRepoUrl",
|
|
174
|
+
commit: "githubCommitHash",
|
|
175
|
+
issue: "githubIssueUrl",
|
|
176
|
+
};
|
|
177
|
+
const FILE_FLAGS = {
|
|
178
|
+
"description-file": "description",
|
|
179
|
+
"dockerfile-file": "dockerfile",
|
|
180
|
+
"test-patch-file": "testPatch",
|
|
181
|
+
"solution-patch-file": "solutionPatch",
|
|
182
|
+
"approach-file": "solutionApproach",
|
|
183
|
+
"env-file": "environmentDescription",
|
|
184
|
+
"hint-file": "hintText",
|
|
185
|
+
"hint-justification-file": "hintJustification",
|
|
186
|
+
};
|
|
187
|
+
export function updatesFromFlags(flags, base = {}, readStdin = () => readFileSync(0, "utf8")) {
|
|
188
|
+
const updates = { ...base };
|
|
189
|
+
for (const [flag, field] of Object.entries(VALUE_FLAGS)) {
|
|
190
|
+
const value = flags[flag];
|
|
191
|
+
if (value !== undefined)
|
|
192
|
+
updates[field] = value;
|
|
193
|
+
}
|
|
194
|
+
if (flags["test-output-mode"] !== undefined) {
|
|
195
|
+
updates.testOutputMode = parseTestOutputMode(flags["test-output-mode"]);
|
|
196
|
+
}
|
|
197
|
+
if (flags["estimated-loc"] !== undefined) {
|
|
198
|
+
updates.estimatedLOC = parseEstimatedLoc(flags["estimated-loc"]);
|
|
199
|
+
}
|
|
200
|
+
let stdinUsed = false;
|
|
201
|
+
for (const [flag, field] of Object.entries(FILE_FLAGS)) {
|
|
202
|
+
const path = flags[flag];
|
|
203
|
+
if (path === undefined)
|
|
204
|
+
continue;
|
|
205
|
+
if (path === "-") {
|
|
206
|
+
if (stdinUsed)
|
|
207
|
+
throw new UsageError("Only one file flag may read from stdin (-).");
|
|
208
|
+
stdinUsed = true;
|
|
209
|
+
updates[field] = readStdin();
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (!existsSync(path))
|
|
213
|
+
throw new UsageError(`File not found: ${path}`);
|
|
214
|
+
updates[field] = readFileSync(path, "utf8");
|
|
215
|
+
}
|
|
216
|
+
return updates;
|
|
217
|
+
}
|
|
218
|
+
const CLEARABLE = new Set([
|
|
219
|
+
...Object.keys(CONTENT_FILES),
|
|
220
|
+
"githubCommitHash",
|
|
221
|
+
"githubIssueUrl",
|
|
222
|
+
]);
|
|
223
|
+
export function applyClears(updates, clear) {
|
|
224
|
+
if (!clear)
|
|
225
|
+
return updates;
|
|
226
|
+
const out = { ...updates };
|
|
227
|
+
for (const raw of clear.split(",")) {
|
|
228
|
+
const field = raw.trim();
|
|
229
|
+
if (field.length === 0)
|
|
230
|
+
continue;
|
|
231
|
+
if (!CLEARABLE.has(field)) {
|
|
232
|
+
throw new UsageError(`"${field}" cannot be cleared. Clearable: ${[...CLEARABLE].sort().join(", ")}.`);
|
|
233
|
+
}
|
|
234
|
+
out[field] = "";
|
|
235
|
+
}
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
238
|
+
export function countFields(updates) {
|
|
239
|
+
return Object.values(updates).filter((value) => value !== undefined).length;
|
|
240
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { login, logout, whoami } from "./commands/auth.js";
|
|
|
6
6
|
import checks from "./commands/checks.js";
|
|
7
7
|
import { problems } from "./commands/problems.js";
|
|
8
8
|
import { quests } from "./commands/quests.js";
|
|
9
|
+
import { runs } from "./commands/runs.js";
|
|
9
10
|
import { EXIT_USAGE, errorMessage, exitCodeForError } from "./errors.js";
|
|
10
11
|
import { text } from "./format.js";
|
|
11
12
|
import { isAdminOnlyCommand } from "./index-gate.js";
|
|
@@ -39,11 +40,11 @@ const main = defineCommand({
|
|
|
39
40
|
meta: {
|
|
40
41
|
name: "shipd",
|
|
41
42
|
version: VERSION,
|
|
42
|
-
description: "Shipd CLI: your quest challenges
|
|
43
|
+
description: "Shipd CLI: your quest challenges, their content, checks and agent runs (author edition); ad-hoc quest checks on Harbor tasks or existing tasks (admin edition)",
|
|
43
44
|
},
|
|
44
|
-
subCommands: { login, logout, whoami, quests, problems, checks, update, version },
|
|
45
|
+
subCommands: { login, logout, whoami, quests, problems, checks, runs, update, version },
|
|
45
46
|
});
|
|
46
|
-
const showUsage = createShowUsage(main, { problems, checks });
|
|
47
|
+
const showUsage = createShowUsage(main, { problems, checks, runs });
|
|
47
48
|
async function run() {
|
|
48
49
|
const rawArgs = process.argv.slice(2);
|
|
49
50
|
if (rawArgs.length === 0 || rawArgs.includes("--help") || rawArgs.includes("-h")) {
|
package/dist/model.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type ProblemSummary = {
|
|
|
8
8
|
difficulty?: string;
|
|
9
9
|
githubRepoUrl?: string;
|
|
10
10
|
githubCommitHash?: string;
|
|
11
|
+
estimatedLOC?: number;
|
|
11
12
|
};
|
|
12
13
|
export type VersionSummary = {
|
|
13
14
|
_id: string;
|
|
@@ -24,6 +25,13 @@ export type VersionSummary = {
|
|
|
24
25
|
dockerfile?: string;
|
|
25
26
|
testPatch?: string;
|
|
26
27
|
solutionPatch?: string;
|
|
28
|
+
githubIssueUrl?: string;
|
|
29
|
+
solutionApproach?: string;
|
|
30
|
+
environmentDescription?: string;
|
|
31
|
+
hintText?: string;
|
|
32
|
+
hintJustification?: string;
|
|
33
|
+
testOutputMode?: string;
|
|
34
|
+
estimatedLOC?: number;
|
|
27
35
|
};
|
|
28
36
|
export type ProblemWithLatestVersion = ProblemSummary & {
|
|
29
37
|
latestVersion?: VersionSummary | null;
|
|
@@ -64,6 +72,32 @@ export type AgentRunCriteria = {
|
|
|
64
72
|
preview?: boolean;
|
|
65
73
|
}>;
|
|
66
74
|
};
|
|
75
|
+
export type ScopeGateStatus = {
|
|
76
|
+
latestVerdict: "pass" | "drop" | null;
|
|
77
|
+
fresh: boolean;
|
|
78
|
+
staleReason?: "content" | "series" | null;
|
|
79
|
+
inFlight: boolean;
|
|
80
|
+
canRunDynamicChecks?: boolean;
|
|
81
|
+
current?: {
|
|
82
|
+
jobId?: string;
|
|
83
|
+
status?: string;
|
|
84
|
+
error?: string;
|
|
85
|
+
} | null;
|
|
86
|
+
verdictRun?: {
|
|
87
|
+
jobId?: string;
|
|
88
|
+
status?: string;
|
|
89
|
+
output?: {
|
|
90
|
+
verdict?: string | null;
|
|
91
|
+
reasoning?: string;
|
|
92
|
+
findings?: Array<{
|
|
93
|
+
category?: string;
|
|
94
|
+
severity?: string;
|
|
95
|
+
summary?: string;
|
|
96
|
+
}>;
|
|
97
|
+
} | null;
|
|
98
|
+
error?: string;
|
|
99
|
+
} | null;
|
|
100
|
+
};
|
|
67
101
|
export type TrialQaStatus = {
|
|
68
102
|
state: string;
|
|
69
103
|
canRun: boolean;
|