@shipd-ai/cli 0.1.3 → 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 +172 -42
- 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 +10 -0
- package/dist/checks-view.js +12 -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 +306 -0
- package/dist/commands/author-checks.js +430 -0
- package/dist/commands/author-content.d.ts +198 -0
- package/dist/commands/author-content.js +102 -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 +196 -0
- package/dist/commands/quests.d.ts +0 -1
- package/dist/commands/quests.js +0 -1
- 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/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 +15 -10
- package/dist/model.d.ts +128 -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/runs.d.ts +36 -0
- package/dist/runs.js +59 -0
- package/dist/usage.d.ts +2 -0
- package/dist/usage.js +16 -0
- package/package.json +3 -2
|
@@ -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/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>;
|