@thedeck/mcp 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +78 -78
  2. package/dist/cli.js +1423 -31
  3. package/dist/index.js +313 -158
  4. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { createRequire } from "node:module";
3
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
4
  import { execFile, spawn } from "node:child_process";
5
5
  import crypto$1, { randomBytes } from "node:crypto";
6
- import { copyFile, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
6
+ import { cp, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
7
7
  import { createServer } from "node:http";
8
8
  import os, { homedir, tmpdir } from "node:os";
9
9
  import path from "node:path";
@@ -55,6 +55,7 @@ var tagLabel = z.object({
55
55
  }).strict();
56
56
  z.discriminatedUnion("kind", [usernameLabel, tagLabel]);
57
57
  // ../shared/src/money.ts
58
+ var MAX_REWARD_CENTS = 2e9;
58
59
  function formatMoney(cents, currency = "USD") {
59
60
  if (!Number.isSafeInteger(cents)) throw new RangeError(`expected whole cents, got ${cents}`);
60
61
  const whole = cents % 100 === 0;
@@ -152,6 +153,20 @@ z.object({
152
153
  of: z.number().int().positive(),
153
154
  due_at: z.string()
154
155
  });
156
+ // ../shared/src/schemas/testCheck.ts
157
+ var TEST_COMPARES = [
158
+ "exact",
159
+ "unordered_lines",
160
+ "numbers",
161
+ "json"
162
+ ];
163
+ var TEST_OUTCOMES = ["output", "fails_cleanly"];
164
+ var TEST_DEFAULTS = {
165
+ compare: "exact",
166
+ tolerance: 1e-6,
167
+ timeLimitMs: 1e4,
168
+ outcome: "output"
169
+ };
155
170
  // ../shared/src/schemas/mcp.ts
156
171
  var questId = z.uuid();
157
172
  var section = z.string().trim().min(1).max(BRIEF_LIMITS.section);
@@ -200,7 +215,9 @@ var postDraftInput = z.object({
200
215
  deliverables: z.array(deliverableSchema).min(1),
201
216
  ends_on: z.iso.date({ error: ASK_END_DATE }).describe("The last day builders can enter (YYYY-MM-DD), as the person stated it, 5 to 60 days from their today. Entries close at 23:59 that day in time_zone."),
202
217
  time_zone: z.string({ error: ASK_TIME_ZONE }).refine(isTimeZone, { error: ASK_TIME_ZONE }).describe("The person’s IANA time zone, such as America/New_York, as they confirmed it. The deadline is 23:59 on ends_on in this zone."),
203
- scenarios: scenarios.describe("The scenarios the person confirmed: each situation that comes in and what should happen then, as you described them back and they agreed.")
218
+ scenarios: scenarios.describe("The scenarios the person confirmed: each situation that comes in and what should happen then, as you described them back and they agreed."),
219
+ reward_cents: z.number().int().positive().max(MAX_REWARD_CENTS).optional().describe("The reward the person agreed to pay for the accepted submission, in US cents. Leave it out until they have said it; never suggest it as settled."),
220
+ visibility: z.enum(["public", "private"]).optional().describe("Who can see the task, as the person chose: public for anyone on The Deck, private for only the builders they invite. Leave it out until they have chosen.")
204
221
  });
205
222
  var postPart = z.enum([
206
223
  "title",
@@ -217,6 +234,9 @@ var postPart = z.enum([
217
234
  var postDraftOutput = z.object({
218
235
  quest_id: questId,
219
236
  review_url: z.url(),
237
+ pay_url: z.url(),
238
+ reward_cents: z.number().int().nonnegative(),
239
+ deposit_cents: z.number().int().nonnegative().describe("What the pay link charges now: the held deposit, 30% of the reward. The rest is charged when the person accepts a submission."),
220
240
  missing: z.array(z.object({
221
241
  part: postPart,
222
242
  label: z.string()
@@ -226,32 +246,58 @@ var postDraftOutput = z.object({
226
246
  var addExampleCopyInput = z.object({
227
247
  quest_id: questId,
228
248
  pair: z.number().int().positive(),
229
- role: z.enum(["input", "expected"]),
230
- filename: z.string().trim().min(1).max(255),
249
+ role: z.enum(["input", "expected"]).describe("input: a file the program reads. An example’s input can be several files: send each with the same pair and role input. expected: the one answer file of that pair."),
250
+ filename: z.string().trim().min(1).max(255).describe("A file sent again under the same name, pair and role replaces the one sent before."),
231
251
  content: z.string(),
232
252
  blanked_summary: z.string().trim().min(1),
233
- shown_to_builders: z.boolean().optional().describe("True when the person chose to show this example to builders. Leave it out to keep it hidden for judging, like a hidden test.")
253
+ shown_to_builders: z.boolean().optional().describe("True when the person chose to show this example to builders. Leave it out to keep it hidden for judging, like a hidden test."),
254
+ person_approved: z.literal(true).optional().describe("true only when you showed the person this exact blanked copy and they said yes to sending it. The copy then needs no second approval on The Deck.")
234
255
  });
235
256
  var addExampleCopyOutput = z.object({
236
257
  example_id: z.uuid(),
237
- status: z.literal("pending")
258
+ status: z.enum(["pending", "approved"])
259
+ });
260
+ var isJson = (text) => {
261
+ try {
262
+ JSON.parse(text);
263
+ return true;
264
+ } catch {
265
+ return false;
266
+ }
267
+ };
268
+ var exampleCopyRef = z.object({
269
+ pair: z.number().int().positive(),
270
+ role: z.enum(["input", "expected"])
271
+ }).describe("An example copy already sent with deck.add_example_copy, named by its pair and role, in place of inline text.");
272
+ var proposedTest = z.object({
273
+ name: z.string().trim().min(1),
274
+ kind: z.enum(["sample", "hidden"]),
275
+ input: z.union([z.string(), exampleCopyRef]).describe("The input as text, or an example copy by its pair and role. For a large input, send the file once with deck.add_example_copy (hidden unless the person shows it) and name it here instead of writing it out. When that example’s input is several files, the program gets a folder holding them."),
276
+ expected: z.union([z.string(), exampleCopyRef]).describe("The expected output as text, or an example copy by its pair and role. For outcome fails_cleanly, a short note of why the input is bad; it is shown to the person, not compared."),
277
+ category: z.string().trim().min(1).optional().describe("The part of the test plan this test covers: the confirmed scenario it checks, or an edge case such as empty input, malformed input, large input or boundary values. Builders see how many hidden tests failed in each category."),
278
+ compare: z.enum(TEST_COMPARES).optional().describe("How the output is checked against expected. exact (the default): the same text, ignoring line endings and trailing space. unordered_lines: the same lines in any order, for rows whose order does not matter. numbers: every number within tolerance and the text around them the same. json: the same JSON value, whatever the key order and spacing."),
279
+ tolerance: z.number().nonnegative().optional().describe(`Only with compare numbers: how far each number may be from the expected one. Default ${TEST_DEFAULTS.tolerance}.`),
280
+ time_limit_seconds: z.number().int().min(1).max(120).optional().describe(`How long the program may run on this test before it fails. Default ${TEST_DEFAULTS.timeLimitMs / 1e3}; raise it for a large input.`),
281
+ outcome: z.enum(TEST_OUTCOMES).optional().describe("output (the default): the program must exit normally with the expected output. fails_cleanly: the program must refuse the input with an error exit, neither crashing nor hanging; use it for malformed input.")
282
+ }).refine((t) => t.tolerance === void 0 || t.compare === "numbers", {
283
+ path: ["tolerance"],
284
+ error: "tolerance applies only with compare numbers"
285
+ }).refine((t) => t.compare !== "json" || t.outcome === "fails_cleanly" || typeof t.expected !== "string" || isJson(t.expected), {
286
+ path: ["expected"],
287
+ error: "with compare json, expected must be valid JSON"
238
288
  });
239
289
  var proposeTestsInput = z.object({
240
290
  quest_id: questId,
241
- tests: z.array(z.object({
242
- name: z.string().trim().min(1),
243
- kind: z.enum(["sample", "hidden"]),
244
- input: z.string(),
245
- expected: z.string(),
246
- category: z.string().trim().min(1).optional()
247
- })).min(1),
248
- suggested_pass_mark: z.number().int().positive()
291
+ tests: z.array(proposedTest).min(1).describe("A test plan, not only the examples: at least one test for every confirmed scenario, plus edge cases you write yourself (empty input, malformed input with outcome fails_cleanly, large input, boundary values). Give each test the category it covers."),
292
+ suggested_pass_mark: z.number().int().positive(),
293
+ person_approved: z.literal(true, { error: "show the person the test plan in plain words (what each test checks, which ones builders see, the pass mark) and send it only after they say yes, with person_approved true" }).describe("true only when you showed the person this test plan in plain words (what each test checks, which ones builders see, the pass mark) and they said yes. The tests then need no second approval on The Deck.")
249
294
  });
250
295
  var proposeTestsOutput = z.object({
251
296
  quest_id: questId,
252
297
  samples: z.number().int().nonnegative(),
253
298
  hidden: z.number().int().nonnegative(),
254
- pass_mark: z.number().int().nonnegative()
299
+ pass_mark: z.number().int().nonnegative(),
300
+ status: z.enum(["pending", "approved"])
255
301
  });
256
302
  var listQuestsInput = z.object({
257
303
  query: z.string().trim().optional(),
@@ -327,8 +373,13 @@ var precheckKitOutput = z.object({
327
373
  name: z.string(),
328
374
  input_file: z.string().min(1),
329
375
  input: z.base64(),
376
+ input_folder: z.boolean().optional().describe("true when input is a zip of several files, unpacked into a folder that is passed as {input}."),
330
377
  expected_file: z.string().min(1),
331
- expected: z.base64()
378
+ expected: z.base64(),
379
+ compare: z.enum(TEST_COMPARES).optional(),
380
+ tolerance: z.number().nonnegative().nullable().optional(),
381
+ time_limit_ms: z.number().int().positive().optional(),
382
+ outcome: z.enum(TEST_OUTCOMES).optional()
332
383
  }))
333
384
  });
334
385
  var precheckReportInput = z.object({
@@ -344,7 +395,8 @@ var realDataReportInput = z.object({
344
395
  total: z.number().int().positive()
345
396
  });
346
397
  var reportedOutput = z.object({ reported: z.literal(true) });
347
- var reportIssueInput = z.object({
398
+ var reportFields = z.object({
399
+ kind: z.enum(["problem", "workflow_change"]).optional().describe("problem (the default): the person struggled or was held up. workflow_change: the person went through the steps their own way, which shows how people prefer to work with an agent."),
348
400
  side: z.enum(["poster", "builder"]),
349
401
  step: z.enum([
350
402
  "understanding_the_deck",
@@ -369,15 +421,21 @@ var reportIssueInput = z.object({
369
421
  "blocker",
370
422
  "annoying",
371
423
  "minor"
372
- ]),
424
+ ]).optional().describe("How much the problem held the person up. Needed for a problem; leave it out for a workflow change."),
373
425
  quest_id: questId.optional(),
374
426
  person_agreed: z.literal(true).describe("true only when you showed the person this exact text and they said yes to sending it.")
375
427
  });
428
+ var hasSeverity = (r) => r.kind === "workflow_change" || r.severity !== void 0;
429
+ var NEEDS_SEVERITY = {
430
+ path: ["severity"],
431
+ error: "a problem needs its severity: blocker, annoying or minor"
432
+ };
433
+ var reportIssueInput = reportFields.refine(hasSeverity, NEEDS_SEVERITY);
376
434
  var reportIssueOutput = z.object({
377
435
  report_id: z.uuid(),
378
436
  received_at: z.string()
379
437
  });
380
- var betaReportInput = reportIssueInput.extend({ agent_client: z.string().trim().min(1).max(200).nullable().optional() });
438
+ var betaReportInput = reportFields.extend({ agent_client: z.string().trim().min(1).max(200).nullable().optional() }).refine(hasSeverity, NEEDS_SEVERITY);
381
439
  var MCP_TOOLS = {
382
440
  "deck.post_draft": {
383
441
  input: postDraftInput,
@@ -387,7 +445,7 @@ var MCP_TOOLS = {
387
445
  "deck.add_example_copy": {
388
446
  input: addExampleCopyInput,
389
447
  output: addExampleCopyOutput,
390
- remote: false
448
+ remote: true
391
449
  },
392
450
  "deck.propose_tests": {
393
451
  input: proposeTestsInput,
@@ -444,10 +502,12 @@ var DECK_ERROR_CODES = [
444
502
  var isDeckErrorCode = (code) => DECK_ERROR_CODES.includes(code);
445
503
  var DeckError = class extends Error {
446
504
  code;
505
+ waitsOnPerson;
447
506
  constructor(code, message, options) {
448
507
  super(message ?? code, options);
449
508
  this.name = "DeckError";
450
509
  this.code = code;
510
+ this.waitsOnPerson = options?.waitsOnPerson === true;
451
511
  }
452
512
  };
453
513
  var toolCall = (name) => ({
@@ -871,7 +931,7 @@ var SCRIPT = String.raw`
871
931
  if (scenarios.length) b.append(el('p', 'lbl', 'Scenarios'), scenarioList(scenarios));
872
932
  const missing = o.missing || [];
873
933
  b.append(missing.length ? p('', [mute('Still needed: '), missing.map((m) => m.label).join('; ')]) : p('', [em('Nothing missing'), ' · ready to post from The Deck']));
874
- if (safeUrl(o.review_url)) b.append(el('div', 'acts', [openLink('Review on The Deck', o.review_url), mute('The reward and posting stay yours.')]));
934
+ if (safeUrl(o.review_url)) b.append(el('div', 'acts', [openLink('Review on The Deck', o.review_url), mute('Paying and posting stay yours.')]));
875
935
  },
876
936
  entries(b, o) {
877
937
  const entries = o.entries || [];
@@ -1011,25 +1071,30 @@ function registerCard(server, tool) {
1011
1071
  };
1012
1072
  }
1013
1073
  // src/guidance.ts
1074
+ var ONE_QUESTION = "Ask the person one short question per message, never a list, and wait for their answer. If they leave a question unanswered, ask it again briefly; never decide it for them.";
1075
+ var CONVERSATION = "Keep it a conversation, not a form. Ask one short question per message, in plain, friendly words, and wait for their answer. Never send a list of questions. If the person leaves a question unanswered, ask it again briefly; never decide it for them. After each answer, say back in a sentence what you heard, ask a brief follow-up if anything is unclear, then go on to the next question.";
1014
1076
  var POSTING_STEPS = [
1015
1077
  "To help a person post a task, go through these steps in order, one at a time:",
1016
- "1. Ask what they need. If they don’t know what to build, suggest ideas from what you already know of them, from this conversation and earlier ones. This brainstorming stays between you and them: nothing goes to The Deck except the post they approve.",
1078
+ "1. Ask them to describe the problem in their own words. If they don’t know what to build, suggest ideas from what you already know of them, from this conversation and earlier ones. This brainstorming stays between you and them: nothing goes to The Deck except the post they approve.",
1017
1079
  "2. Describe concrete scenarios back to them (\"when X comes in, it should do Y\") and ask whether that is what they want. Revise until they confirm.",
1018
- "3. Work out the technical details the post needs: inputs, outputs, formats, what counts as right, and constraints. Ask for the end date: the last day builders can enter, 5 to 60 days from today. Confirm the person’s time zone with them; never assume it. Entries close at 23:59 on that date in their time zone.",
1019
- "4. Ask for real example data. Blank names, numbers and anything sensitive in a copy on their computer before anything is sent. The confirmed scenarios are the basis for the examples and tests. Suggest which one or two examples builders should see; the person decides, and the rest stay hidden for judging.",
1020
- "5. Save the draft with deck.post_draft, with the confirmed scenarios. Send each blanked copy with deck.add_example_copy, marking the ones the person chose to show builders (without that tool, the person adds the copies on The Deck), then propose tests with deck.propose_tests.",
1021
- "6. The person sets the reward and who can see the task, then confirms and pays on The Deck."
1080
+ "3. Go through the details one question at a time: what comes in, what should come out, the file formats, what counts as right, and any constraints.",
1081
+ "4. Ask for the end date: the last day builders can enter, 5 to 60 days from today. Confirm the person’s time zone with them; never assume it. Entries close at 23:59 on that date in their time zone. Then save the draft with deck.post_draft, with the confirmed scenarios.",
1082
+ "5. Ask for real example data. If they attach a file in this chat, make the blanked copy yourself: replace names, numbers and anything sensitive, show them the exact blanked copy, and send it with deck.add_example_copy only after they say yes. An example’s input can be several files, like a PDF and a CSV: send each with the same pair, never zipped together. On their own computer, blank names, numbers and anything sensitive in a copy on their computer before anything is sent. The confirmed scenarios are the basis for the examples and tests. Suggest which one or two examples builders should see; the person decides, and the rest stay hidden for judging. Then propose tests with deck.propose_tests. Propose a test plan, not copies of the examples: at least one test for every confirmed scenario, plus edge cases you write yourself (empty input, malformed input with outcome fails_cleanly, large input, boundary values), each with its category. Pick how each test is compared and raise its time limit only for large inputs. For a large input or a hidden test file, send it once with deck.add_example_copy (hidden from builders unless they choose to show it) and name it in the test by its pair and role instead of writing it out. Show them the plan in plain words: what each test checks, which ones builders see, and the pass mark. Send it with person_approved true only after they say yes.",
1083
+ "6. Ask what reward they will pay for the accepted submission, then who can see the task: anyone on The Deck, or only builders they invite. Save both on the draft with deck.post_draft.",
1084
+ "7. When deck.post_draft says nothing is missing, give the person its pay link. They open it and pay the held deposit, 30% of the reward, on Stripe themselves, which posts the task; the rest is charged only when they accept a submission. Tell them the exact amounts deck.post_draft gives. While something is still missing, the same link opens the review page, which shows what."
1022
1085
  ].join("\n");
1023
- var NEVER = "You can never save a card, post a task live, accept an entry, pitch in or pay anyone: the person does those on The Deck.";
1024
- var REPORTS = "During the beta, when the person is noticeably struggling or inconvenienced at any step, posting or building, write a short report of what went wrong, show them the exact text and send it with deck.report_issue only if they say yes. Do the same whenever they say \"report this\". Ask at most once per problem. Never put example data, file contents, secrets or other people’s details in a report.";
1086
+ var NEVER = "You can never save a card, post a task live, accept an entry, pitch in or pay anyone: the person pays the deposit themselves on Stripe, through the pay link, and accepts entries on The Deck.";
1087
+ var REPORTS = "During the beta, when the person is noticeably struggling or inconvenienced at any step, posting or building, write a short report of what went wrong, show them the exact text and send it with deck.report_issue only if they say yes. Do the same whenever they say \"report this\". Offer a report with kind workflow_change, the same way, when the person changes how they go through the steps: answers in a different order, skips or merges steps, does a step on the website instead of in the chat, writes the post themselves, or turns down a suggested approach and does it their own way; it shows how people prefer to work with an agent. Ask whether to send it in one short question, at most once per problem or change. Never put example data, file contents, secrets or other people’s details in a report.";
1025
1088
  var INSTRUCTIONS = [
1026
1089
  "The Deck is a board where posters put up tasks with a reward and builders enter solutions that are tested automatically. These tools act as the person who connected you.",
1090
+ CONVERSATION,
1027
1091
  POSTING_STEPS,
1028
1092
  NEVER,
1029
1093
  REPORTS
1030
1094
  ].join("\n\n");
1031
1095
  var POST_A_TASK = [
1032
1096
  "Help me post a task on The Deck. Take it one step at a time and wait for my answer at each step.",
1097
+ CONVERSATION,
1033
1098
  POSTING_STEPS,
1034
1099
  NEVER,
1035
1100
  REPORTS
@@ -1037,7 +1102,7 @@ var POST_A_TASK = [
1037
1102
  function registerPostATask(server) {
1038
1103
  server.registerPrompt("post_a_task", {
1039
1104
  title: "Post a task on The Deck",
1040
- description: "Work out a task with the person, from what they need to a draft they post and pay for on The Deck."
1105
+ description: "Work out a task with the person, one question at a time, from what they need to the one link they open to pay and post it."
1041
1106
  }, () => ({ messages: [{
1042
1107
  role: "user",
1043
1108
  content: {
@@ -1076,17 +1141,19 @@ async function checkBlankedCopy(input, dir) {
1076
1141
  const bytes = decodeCopy(input.content);
1077
1142
  if (bytes.length === 0) throw new DeckError("BAD_INPUT", "the copy is empty");
1078
1143
  if (bytes.length > 52428800) throw new DeckError("FILE_TOO_LARGE", `the copy is ${bytes.length} bytes; the limit is ${COPY_MAX_BYTES}`);
1079
- for (const name of originalNames(input.filename)) if ((await readIfThere(path.join(dir, name)))?.equals(bytes)) throw new DeckError("NOT_BLANKED", `${name} is unchanged: blank the names and numbers in a copy before sending it`);
1144
+ for (const name of originalNames(input.filename)) if ((await readIfThere(path.join(dir, name)))?.equals(bytes)) throw new DeckError("NOT_BLANKED", `${name} is unchanged: blank the names and numbers in a copy before sending it`, { waitsOnPerson: true });
1080
1145
  return {
1081
1146
  filename: blankedName(input.filename),
1082
1147
  size: bytes.length
1083
1148
  };
1084
1149
  }
1085
1150
  // src/tools/addExampleCopy.ts
1151
+ var SEVERAL_FILES = "An example’s input can be several files, like a PDF and a CSV: send each with the same pair and role input; never zip them together.";
1152
+ var summary = (out) => out.status === "approved" ? `Blanked copy sent as example ${out.example_id}, status approved: the person approved this exact copy in the chat. ${ONE_QUESTION}` : `Blanked copy sent as example ${out.example_id}, status ${out.status}. It waits on the poster’s Examples list for approval. ${ONE_QUESTION}`;
1086
1153
  var addExampleCopy = {
1087
1154
  name: "deck.add_example_copy",
1088
1155
  title: "Send a blanked example copy",
1089
- description: "For posters, on this computer. Sends one example file to a draft task after you have blanked its names and numbers in a copy: content is the copy as text, or as a data URL (data:<type>;base64,...) for binary files. The original never leaves this computer; the copy waits for the poster to approve it.",
1156
+ description: `For posters, on this computer. Sends one example file to a draft task after you have blanked its names and numbers in a copy: content is the copy as text, or as a data URL (data:<type>;base64,...) for binary files. ${SEVERAL_FILES} The original never leaves this computer; the copy waits for the poster to approve it. ${ONE_QUESTION}`,
1090
1157
  async run(backend, args) {
1091
1158
  const copy = await checkBlankedCopy(args, process.cwd());
1092
1159
  return backend.addExampleCopy({
@@ -1094,7 +1161,23 @@ var addExampleCopy = {
1094
1161
  filename: copy.filename
1095
1162
  });
1096
1163
  },
1097
- summary: (out) => `Blanked copy sent as example ${out.example_id}, status ${out.status}. It waits on the poster’s Examples list for approval.`
1164
+ summary
1165
+ };
1166
+ var addExampleCopyRemote = {
1167
+ name: "deck.add_example_copy",
1168
+ title: "Send a blanked example copy",
1169
+ description: `For posters. Sends one example file the person attached in this chat to a draft task, as a copy you blanked: replace names, numbers and anything sensitive, show the person the exact blanked copy, and send it only after they say yes, with person_approved true. content is the copy as text, or as a data URL (data:<type>;base64,...) for binary files. ${SEVERAL_FILES} Never send the original. ${ONE_QUESTION}`,
1170
+ async run(backend, args) {
1171
+ if (args.person_approved !== true) throw new DeckError("BAD_INPUT", "show the person the exact blanked copy and send it only after they say yes, with person_approved true", { waitsOnPerson: true });
1172
+ const size = decodeCopy(args.content).length;
1173
+ if (size === 0) throw new DeckError("BAD_INPUT", "the copy is empty");
1174
+ if (size > 52428800) throw new DeckError("FILE_TOO_LARGE", `the copy is ${size} bytes; the limit is ${COPY_MAX_BYTES}`);
1175
+ return backend.addExampleCopy({
1176
+ ...args,
1177
+ filename: blankedName(args.filename)
1178
+ });
1179
+ },
1180
+ summary
1098
1181
  };
1099
1182
  // src/tools/getPassingEntries.ts
1100
1183
  var line$1 = (e, i) => `${i + 1}. ${e.identity.label} · entry ${e.entry_id} · version ${e.version} · samples ${e.sample.passed} of ${e.sample.total} · hidden ${e.hidden.passed} of ${e.hidden.total} · download ${e.download_url} (expires ${utc(e.expires_at)})`;
@@ -1147,19 +1230,35 @@ var listQuests = {
1147
1230
  summary: (out) => out.quests.length === 0 ? "No quests found." : [`${plural(out.quests.length, "quest", "quests")} found:`, ...out.quests.map(line)].join("\n")
1148
1231
  };
1149
1232
  // src/tools/postDraft.ts
1233
+ var ASK_ABOUT_IT = "Ask the person about it, then save the draft again with deck.post_draft.";
1234
+ var NEXT = {
1235
+ title: ASK_ABOUT_IT,
1236
+ problem: ASK_ABOUT_IT,
1237
+ looking_for: ASK_ABOUT_IT,
1238
+ rules: ASK_ABOUT_IT,
1239
+ handover: ASK_ABOUT_IT,
1240
+ examples: "Ask the person for one real example file, then blank it and send it with deck.add_example_copy.",
1241
+ tests: "Propose a test plan with deck.propose_tests: show it to the person in plain words and ask whether it is right.",
1242
+ reward: "Ask the person what reward they will pay for the accepted submission.",
1243
+ deadline: "Ask the person for an end date 5 to 60 days from their today.",
1244
+ visibility: "Ask the person who can see the task: anyone on The Deck, or only builders they invite."
1245
+ };
1246
+ function payNote(out) {
1247
+ const rest = out.reward_cents - out.deposit_cents;
1248
+ return `The pay link charges ${formatMoney(out.deposit_cents)} now, the held deposit, 30% of the ${formatMoney(out.reward_cents)} reward; the other ${formatMoney(rest)} is charged only when they accept a submission, and the deposit comes back in full if no entry passes. Say these exact amounts.`;
1249
+ }
1150
1250
  var postDraft = {
1151
1251
  name: "deck.post_draft",
1152
1252
  title: "Draft a task",
1153
- description: "For posters. Saves a task brief on The Deck as a draft, or updates the draft named by quest_id. The deadline is the person’s: send the end date they gave you and the time zone they confirmed, never ones you chose. The poster sets the reward and who can see it, then confirms and pays on The Deck: an agent never posts a task live and never spends money.",
1253
+ description: `For posters. Saves a task brief on The Deck as a draft, or updates the draft named by quest_id. The deadline, the reward and who can see it are the person’s: send only the end date, time zone, reward and visibility they gave you, never ones you chose, and leave the reward and visibility out until they have said them. When nothing is missing, give the person pay_url: they pay the held deposit, 30% of the reward, on Stripe themselves, which posts the task; the rest is charged when they accept a submission. An agent never posts a task live and never spends money. ${ONE_QUESTION}`,
1154
1254
  run: (backend, args) => backend.postDraft(args),
1155
1255
  summary: (out) => {
1156
- const saved = `Draft saved as quest ${out.quest_id}. The poster checks it at ${out.review_url}; the reward, who can see it and posting stay theirs.`;
1157
- if (out.missing.length === 0) return `${saved} Nothing is missing: the poster can post it from that page.`;
1158
- const needsTests = out.missing.some((m) => m.part === "tests" || m.part === "examples");
1256
+ if (out.missing.length === 0) return `Draft saved as quest ${out.quest_id}. Nothing is missing. ${payNote(out)} Give the person this link to pay the held deposit on Stripe themselves, which posts the task: ${out.pay_url}`;
1257
+ const [next] = out.missing;
1159
1258
  return [
1160
- saved,
1161
- `Still needed before it can be posted: ${out.missing.map((m) => m.label).join("; ")}.`,
1162
- ...needsTests ? ["Propose tests with deck.propose_tests if it has none yet; the poster approves the tests and examples."] : []
1259
+ `Draft saved as quest ${out.quest_id}. The poster checks it at ${out.review_url}; paying and posting stay theirs.`,
1260
+ ...next ? [`Next: ${next.label}. ${NEXT[next.part]}`] : [],
1261
+ ONE_QUESTION
1163
1262
  ].join(" ");
1164
1263
  }
1165
1264
  };
@@ -1167,17 +1266,17 @@ var postDraft = {
1167
1266
  var proposeTests = {
1168
1267
  name: "deck.propose_tests",
1169
1268
  title: "Propose tests",
1170
- description: "For posters. Adds tests to a draft task: sample tests builders can see and hidden tests they cannot, each an input and its expected answer, with a suggested pass mark out of the hidden tests. The poster approves the tests on The Deck.",
1269
+ description: `For posters. Adds tests to a draft task: sample tests builders can see and hidden tests they cannot, each an input and its expected answer, with a suggested pass mark out of the hidden tests. Propose a test plan, like a graded coding assignment, not only copies of the examples: at least one test for every confirmed scenario, plus edge cases you write yourself (empty input, malformed input the program should refuse, large input, boundary values), each with the category it covers. Choose per test how the output is compared (exact, any line order, numbers within a tolerance, or JSON), a time limit if the default 10 seconds does not fit, and outcome fails_cleanly where the program should reject the input. For a large input, or a hidden test file, send the file once with deck.add_example_copy and name it here by its pair and role instead of writing it out; when that example’s input is several files, the program gets a folder holding them. Show the person the test plan in plain words: what each test checks, which ones builders see, and the pass mark. Send it only after they say yes, with person_approved true; without it nothing is sent. Then it needs no second approval on The Deck. ${ONE_QUESTION}`,
1171
1270
  run: (backend, args) => backend.proposeTests(args),
1172
- summary: (out) => `${out.samples + out.hidden} tests on draft quest ${out.quest_id}: ${out.samples} visible to builders, ${out.hidden} hidden, pass mark ${out.pass_mark} of ${out.hidden}. The poster approves them.`
1271
+ summary: (out) => `${out.samples + out.hidden} tests on draft quest ${out.quest_id}: ${out.samples} visible to builders, ${out.hidden} hidden, pass mark ${out.pass_mark} of ${out.hidden}. ` + (out.status === "approved" ? "Approved in the chat: the person said yes to this test plan, so it needs no second approval on The Deck." : "The poster approves them.") + ` Next, save the draft again with deck.post_draft; its answer names the one thing still to ask. ${ONE_QUESTION}`
1173
1272
  };
1174
1273
  // src/tools/reportIssue.ts
1175
1274
  var reportIssue = {
1176
1275
  name: "deck.report_issue",
1177
- title: "Report a problem with The Deck",
1178
- description: "For posters and builders, during the beta. Sends The Deck team a short report when the person struggled or was held up at a step, or asked you to report something. Write the report, show the person the exact text, and send it only if they say yes; ask at most once per problem. Never put example data, file contents, secrets or other people’s details in a report.",
1276
+ title: "Report a problem or a workflow change",
1277
+ description: `For posters and builders, during the beta. Saves a short report for The Deck team: kind problem (the default) when the person struggled or was held up at a step, or asked you to report something; kind workflow_change, with no severity, when they went through the steps their own way: another order, a step skipped or merged, a step done on the website instead of in the chat, the post written themselves, or a suggested approach turned down for their own. Write the report, show the person the exact text, and send it only if they say yes; ask at most once per problem. Never put example data, file contents, secrets or other people’s details in a report. ${ONE_QUESTION}`,
1179
1278
  run: (backend, args) => backend.reportIssue(args),
1180
- summary: (out) => `Thank you: report ${out.report_id} reached The Deck team at ${utc(out.received_at)}. The team reads every report.`
1279
+ summary: (out) => `Thank you: report ${out.report_id} was saved for The Deck team at ${utc(out.received_at)}.`
1181
1280
  };
1182
1281
  // src/server.ts
1183
1282
  function plural(n, one, many) {
@@ -1193,19 +1292,20 @@ var SERVER_INFO = {
1193
1292
  };
1194
1293
  var SHARED_TOOLS = [
1195
1294
  postDraft,
1196
- addExampleCopy,
1197
1295
  proposeTests,
1198
1296
  listQuests,
1199
1297
  getTaskStatus,
1200
1298
  getPassingEntries,
1201
1299
  reportIssue
1202
1300
  ];
1203
- function toolError(err) {
1301
+ var REPORT_OFFER = "If this held the person up, write a short report, show them the exact text and send it with deck.report_issue only if they say yes; ask at most once per problem.";
1302
+ function toolError(err, tool) {
1303
+ const offer = tool === "deck.report_issue" ? "" : ` ${REPORT_OFFER}`;
1204
1304
  if (err instanceof DeckError) return {
1205
1305
  isError: true,
1206
1306
  content: [{
1207
1307
  type: "text",
1208
- text: `${err.code}: ${err.message}`
1308
+ text: `${err.code}: ${err.message}${err.waitsOnPerson ? "" : offer}`
1209
1309
  }]
1210
1310
  };
1211
1311
  console.error("[thedeck-mcp] a tool failed", err);
@@ -1213,7 +1313,7 @@ function toolError(err) {
1213
1313
  isError: true,
1214
1314
  content: [{
1215
1315
  type: "text",
1216
- text: "UNAVAILABLE: The Deck could not finish this. Try again in a moment."
1316
+ text: `UNAVAILABLE: The Deck could not finish this. Try again in a moment.${offer}`
1217
1317
  }]
1218
1318
  };
1219
1319
  }
@@ -1228,7 +1328,7 @@ async function callTool(tool, backend, args) {
1228
1328
  structuredContent: out
1229
1329
  };
1230
1330
  } catch (err) {
1231
- return toolError(err);
1331
+ return toolError(err, tool.name);
1232
1332
  }
1233
1333
  }
1234
1334
  function register(server, tool, backend) {
@@ -1250,7 +1350,11 @@ function register(server, tool, backend) {
1250
1350
  function createDeckServer(backend, options = { remote: false }) {
1251
1351
  const server = new McpServer(SERVER_INFO, { instructions: INSTRUCTIONS });
1252
1352
  registerPostATask(server);
1253
- const tools = options.remote ? SHARED_TOOLS : [...SHARED_TOOLS, ...options.localTools ?? []];
1353
+ const tools = options.remote ? [...SHARED_TOOLS, addExampleCopyRemote] : [
1354
+ ...SHARED_TOOLS,
1355
+ addExampleCopy,
1356
+ ...options.localTools ?? []
1357
+ ];
1254
1358
  for (const tool of tools) {
1255
1359
  if (options.remote && !MCP_TOOLS[tool.name].remote) continue;
1256
1360
  register(server, tool, backend);
@@ -1299,6 +1403,42 @@ function sameOutput(actual, expected) {
1299
1403
  const norm = (b) => b.toString("latin1").replaceAll("\r\n", "\n").trimEnd();
1300
1404
  return norm(actual) === norm(expected);
1301
1405
  }
1406
+ var text = (b) => b.toString("utf8").replaceAll("\r\n", "\n").trimEnd();
1407
+ var byCodeUnit = (a, b) => Number(a > b) - Number(a < b);
1408
+ function sameLinesAnyOrder(actual, expected) {
1409
+ const a = actual.split("\n").sort(byCodeUnit);
1410
+ const e = expected.split("\n").sort(byCodeUnit);
1411
+ return a.length === e.length && a.every((line, i) => line === e[i]);
1412
+ }
1413
+ var NUMBER = /-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
1414
+ function sameNumbers(actual, expected, tolerance) {
1415
+ const a = actual.match(NUMBER) ?? [];
1416
+ const e = expected.match(NUMBER) ?? [];
1417
+ const around = (s) => JSON.stringify(s.split(NUMBER));
1418
+ return around(actual) === around(expected) && a.length === e.length && a.every((n, i) => Math.abs(Number(n) - Number(e[i])) <= tolerance);
1419
+ }
1420
+ function canonical(value) {
1421
+ if (Array.isArray(value)) return value.map(canonical);
1422
+ if (value === null || typeof value !== "object") return value;
1423
+ const object = value;
1424
+ return Object.fromEntries(Object.keys(object).sort(byCodeUnit).map((key) => [key, canonical(object[key])]));
1425
+ }
1426
+ function sameJson(actual, expected) {
1427
+ try {
1428
+ return JSON.stringify(canonical(JSON.parse(actual))) === JSON.stringify(canonical(JSON.parse(expected)));
1429
+ } catch {
1430
+ return false;
1431
+ }
1432
+ }
1433
+ function outputMatches(actual, expected, compare, tolerance) {
1434
+ switch (compare) {
1435
+ case "exact": return sameOutput(actual, expected);
1436
+ case "unordered_lines": return sameLinesAnyOrder(text(actual), text(expected));
1437
+ case "numbers": return sameNumbers(text(actual), text(expected), tolerance ?? TEST_DEFAULTS.tolerance);
1438
+ case "json": return sameJson(text(actual), text(expected));
1439
+ }
1440
+ }
1441
+ var refusedCleanly = (exitCode) => exitCode > 0 && exitCode < 128;
1302
1442
  function slotPaths(index, test) {
1303
1443
  const dir = `${TESTS_DIR}/${index}`;
1304
1444
  return {
@@ -1310,7 +1450,7 @@ async function stageInputs(tests) {
1310
1450
  const dir = await mkdtemp(path.join(tmpdir(), "deck-inputs-"));
1311
1451
  await Promise.all(tests.map(async (test, i) => {
1312
1452
  await mkdir(path.join(dir, String(i)));
1313
- await copyFile(test.inputFile, path.join(dir, String(i), `input${path.extname(test.inputFile)}`));
1453
+ await cp(test.inputFile, path.join(dir, String(i), `input${path.extname(test.inputFile)}`), { recursive: true });
1314
1454
  }));
1315
1455
  return dir;
1316
1456
  }
@@ -1322,16 +1462,20 @@ function groupFailures(failed) {
1322
1462
  count
1323
1463
  })).sort((a, b) => b.count - a.count);
1324
1464
  }
1325
- async function runOne(sandbox, command, index, test, timeoutMs) {
1465
+ async function runOne(sandbox, command, index, test, left) {
1326
1466
  const slot = slotPaths(index, test);
1327
1467
  const argv = command.argv.map((a) => a.replaceAll("{input}", slot.input).replaceAll("{output}", slot.output));
1328
1468
  const result = await sandbox.exec(argv, {
1329
1469
  cwd: ENTRY_DIR,
1330
- timeoutMs
1470
+ timeoutMs: Math.min(test.timeLimitMs, left)
1331
1471
  });
1332
1472
  if (result.timedOut) return {
1333
1473
  passed: false,
1334
- timedOut: true
1474
+ timedOut: left <= test.timeLimitMs
1475
+ };
1476
+ if (test.outcome === "fails_cleanly") return {
1477
+ passed: refusedCleanly(result.exitCode),
1478
+ timedOut: false
1335
1479
  };
1336
1480
  if (result.exitCode !== 0) return {
1337
1481
  passed: false,
@@ -1339,7 +1483,7 @@ async function runOne(sandbox, command, index, test, timeoutMs) {
1339
1483
  };
1340
1484
  const actual = command.outputToFile ? await sandbox.readFile(slot.output, OUTPUT_MAX_BYTES) : Buffer.from(result.stdout, "utf8");
1341
1485
  return {
1342
- passed: actual !== null && sameOutput(actual, await readFile(test.expectedFile)),
1486
+ passed: actual !== null && outputMatches(actual, await readFile(test.expectedFile), test.compare, test.tolerance),
1343
1487
  timedOut: false
1344
1488
  };
1345
1489
  }
@@ -23060,6 +23204,7 @@ var E2B_TEMPLATE = process.env.E2B_TEMPLATE ?? "thedeck-sandbox";
23060
23204
  var OUTPUT_CAP = 1048576;
23061
23205
  var DOCKER = process.env.DOCKER_BIN ?? "docker";
23062
23206
  var run = promisify(execFile);
23207
+ var DOCKER_CLOCK_SLACK = .8;
23063
23208
  function exitCodeOf(err) {
23064
23209
  if (!err) return 0;
23065
23210
  return typeof err.code === "number" ? err.code : -1;
@@ -23206,7 +23351,7 @@ var DockerSandbox = class DockerSandbox {
23206
23351
  reject(new Error("docker exec failed", { cause: err }));
23207
23352
  return;
23208
23353
  }
23209
- const timedOut = Boolean(err?.killed) || code === 137 && Date.now() - started >= seconds * 1e3;
23354
+ const timedOut = Boolean(err?.killed) || code === 137 && Date.now() - started >= seconds * 1e3 * DOCKER_CLOCK_SLACK;
23210
23355
  resolve({
23211
23356
  exitCode: code,
23212
23357
  stdout: capped(stdout),
@@ -23464,107 +23609,6 @@ async function scan(options) {
23464
23609
  summary
23465
23610
  };
23466
23611
  }
23467
- // src/local/precheck.ts
23468
- var RUN_LIMIT_MS = 6e5;
23469
- var noStep = () => void 0;
23470
- var safeName = (name) => path.basename(name).replaceAll(/[^\w.-]/g, "_") || "file";
23471
- async function open(openBox) {
23472
- try {
23473
- return await openBox();
23474
- } catch (err) {
23475
- throw new DeckError("SANDBOX_FAILED", "the local sandbox could not start; the pre-check and real-data runs need Docker and the thedeck-sandbox image", { cause: err });
23476
- }
23477
- }
23478
- async function stageKit(kit, dir) {
23479
- const tests = [];
23480
- for (const [i, test] of kit.tests.entries()) {
23481
- const slot = path.join(dir, String(i));
23482
- await mkdir(slot, { recursive: true });
23483
- const inputFile = path.join(slot, `input-${safeName(test.input_file)}`);
23484
- const expectedFile = path.join(slot, `expected-${safeName(test.expected_file)}`);
23485
- await writeFile(inputFile, Buffer.from(test.input, "base64"));
23486
- await writeFile(expectedFile, Buffer.from(test.expected, "base64"));
23487
- tests.push({
23488
- kind: "sample",
23489
- category: null,
23490
- inputFile,
23491
- expectedFile
23492
- });
23493
- }
23494
- return tests;
23495
- }
23496
- async function runInSandbox(options, openBox = openSandbox) {
23497
- let root;
23498
- try {
23499
- root = await findEntryRoot(options.entryDir);
23500
- } catch (err) {
23501
- if (err instanceof EntryError) throw new DeckError("BAD_INPUT", err.message, { cause: err });
23502
- throw new DeckError("BAD_INPUT", `${options.entryDir} could not be read`, { cause: err });
23503
- }
23504
- const sandbox = await open(openBox);
23505
- try {
23506
- const report = await runTests({
23507
- sandbox,
23508
- entryDir: root,
23509
- tests: options.tests,
23510
- deadline: Date.now() + RUN_LIMIT_MS,
23511
- onStep: noStep
23512
- });
23513
- const scanned = options.withScan ? await scan({
23514
- sandbox,
23515
- entryRoot: root,
23516
- onStep: noStep
23517
- }) : null;
23518
- return {
23519
- report,
23520
- scanClear: scanned ? scanned.status === "clear" : null
23521
- };
23522
- } catch (err) {
23523
- if (err instanceof EntryError) throw new DeckError("BAD_INPUT", err.message, { cause: err });
23524
- throw new DeckError("SANDBOX_FAILED", "the run stopped in the local sandbox", { cause: err });
23525
- } finally {
23526
- await sandbox.close();
23527
- }
23528
- }
23529
- async function precheckLocally(kit, entryDir, openBox = openSandbox) {
23530
- if (kit.tests.length === 0) throw new DeckError("NOT_FOUND", "this quest has no sample tests yet");
23531
- const staged = await mkdtemp(path.join(tmpdir(), "deck-precheck-"));
23532
- try {
23533
- const { report, scanClear } = await runInSandbox({
23534
- entryDir,
23535
- tests: await stageKit(kit, staged),
23536
- withScan: true
23537
- }, openBox);
23538
- return {
23539
- passed: report.samplePassed,
23540
- total: report.sampleTotal,
23541
- scan_clear: scanClear === true
23542
- };
23543
- } finally {
23544
- await rm(staged, {
23545
- recursive: true,
23546
- force: true
23547
- });
23548
- }
23549
- }
23550
- // src/tools/runPrecheck.ts
23551
- var runPrecheck = {
23552
- name: "deck.run_precheck",
23553
- title: "Run the pre-check",
23554
- description: "For builders, on this computer. Runs a quest’s sample tests and the security scan on your entry folder in a local sandbox (Docker), then tells The Deck the result. The hidden tests are never sent; it costs nothing. The folder needs a deck.json naming the command, like {\"run\": [\"python\", \"main.py\", \"{input}\"]}.",
23555
- async run(backend, args) {
23556
- const result = await precheckLocally(await backend.getPrecheckKit({ quest_id: args.quest_id }), args.entry_dir);
23557
- await backend.reportPrecheck({
23558
- quest_id: args.quest_id,
23559
- ...result
23560
- });
23561
- return result;
23562
- },
23563
- summary: (out) => {
23564
- const failed = out.passed < out.total ? `, ${out.total - out.passed} failed` : "";
23565
- return `${out.passed} of ${out.total} sample tests passed${failed}, scan ${out.scan_clear ? "clear" : "flagged"}. It ran on your computer and cost nothing.`;
23566
- }
23567
- };
23568
23612
  // ../node_modules/.pnpm/pend@1.2.0/node_modules/pend/index.js
23569
23613
  var require_pend = /* @__PURE__ */ __commonJSMin(((exports, module) => {
23570
23614
  module.exports = Pend;
@@ -24849,6 +24893,113 @@ async function unpack(zipPath, destDir, limits = UNPACK_LIMITS) {
24849
24893
  zip.close();
24850
24894
  }
24851
24895
  }
24896
+ // src/local/precheck.ts
24897
+ var RUN_LIMIT_MS = 6e5;
24898
+ var noStep = () => void 0;
24899
+ var safeName = (name) => path.basename(name).replaceAll(/[^\w.-]/g, "_") || "file";
24900
+ async function open(openBox) {
24901
+ try {
24902
+ return await openBox();
24903
+ } catch (err) {
24904
+ throw new DeckError("SANDBOX_FAILED", "the local sandbox could not start; the pre-check and real-data runs need Docker and the thedeck-sandbox image", { cause: err });
24905
+ }
24906
+ }
24907
+ async function stageKit(kit, dir) {
24908
+ const tests = [];
24909
+ for (const [i, test] of kit.tests.entries()) {
24910
+ const slot = path.join(dir, String(i));
24911
+ await mkdir(slot, { recursive: true });
24912
+ const given = path.join(slot, `input-${safeName(test.input_file)}`);
24913
+ const expectedFile = path.join(slot, `expected-${safeName(test.expected_file)}`);
24914
+ await writeFile(given, Buffer.from(test.input, "base64"));
24915
+ const inputFile = test.input_folder ? path.join(slot, "input") : given;
24916
+ if (test.input_folder) await unpack(given, inputFile);
24917
+ await writeFile(expectedFile, Buffer.from(test.expected, "base64"));
24918
+ tests.push({
24919
+ kind: "sample",
24920
+ category: null,
24921
+ inputFile,
24922
+ expectedFile,
24923
+ compare: test.compare ?? TEST_DEFAULTS.compare,
24924
+ tolerance: test.tolerance ?? null,
24925
+ timeLimitMs: test.time_limit_ms ?? TEST_DEFAULTS.timeLimitMs,
24926
+ outcome: test.outcome ?? TEST_DEFAULTS.outcome
24927
+ });
24928
+ }
24929
+ return tests;
24930
+ }
24931
+ async function runInSandbox(options, openBox = openSandbox) {
24932
+ let root;
24933
+ try {
24934
+ root = await findEntryRoot(options.entryDir);
24935
+ } catch (err) {
24936
+ if (err instanceof EntryError) throw new DeckError("BAD_INPUT", err.message, { cause: err });
24937
+ throw new DeckError("BAD_INPUT", `${options.entryDir} could not be read`, { cause: err });
24938
+ }
24939
+ const sandbox = await open(openBox);
24940
+ try {
24941
+ const report = await runTests({
24942
+ sandbox,
24943
+ entryDir: root,
24944
+ tests: options.tests,
24945
+ deadline: Date.now() + RUN_LIMIT_MS,
24946
+ onStep: noStep
24947
+ });
24948
+ const scanned = options.withScan ? await scan({
24949
+ sandbox,
24950
+ entryRoot: root,
24951
+ onStep: noStep
24952
+ }) : null;
24953
+ return {
24954
+ report,
24955
+ scanClear: scanned ? scanned.status === "clear" : null
24956
+ };
24957
+ } catch (err) {
24958
+ if (err instanceof EntryError) throw new DeckError("BAD_INPUT", err.message, { cause: err });
24959
+ throw new DeckError("SANDBOX_FAILED", "the run stopped in the local sandbox", { cause: err });
24960
+ } finally {
24961
+ await sandbox.close();
24962
+ }
24963
+ }
24964
+ async function precheckLocally(kit, entryDir, openBox = openSandbox) {
24965
+ if (kit.tests.length === 0) throw new DeckError("NOT_FOUND", "this quest has no sample tests yet");
24966
+ const staged = await mkdtemp(path.join(tmpdir(), "deck-precheck-"));
24967
+ try {
24968
+ const { report, scanClear } = await runInSandbox({
24969
+ entryDir,
24970
+ tests: await stageKit(kit, staged),
24971
+ withScan: true
24972
+ }, openBox);
24973
+ return {
24974
+ passed: report.samplePassed,
24975
+ total: report.sampleTotal,
24976
+ scan_clear: scanClear === true
24977
+ };
24978
+ } finally {
24979
+ await rm(staged, {
24980
+ recursive: true,
24981
+ force: true
24982
+ });
24983
+ }
24984
+ }
24985
+ // src/tools/runPrecheck.ts
24986
+ var runPrecheck = {
24987
+ name: "deck.run_precheck",
24988
+ title: "Run the pre-check",
24989
+ description: "For builders, on this computer. Runs a quest’s sample tests and the security scan on your entry folder in a local sandbox (Docker), then tells The Deck the result. The hidden tests are never sent; it costs nothing. The folder needs a deck.json naming the command, like {\"run\": [\"python\", \"main.py\", \"{input}\"]}. When a test’s input is several files, {input} is a folder holding them.",
24990
+ async run(backend, args) {
24991
+ const result = await precheckLocally(await backend.getPrecheckKit({ quest_id: args.quest_id }), args.entry_dir);
24992
+ await backend.reportPrecheck({
24993
+ quest_id: args.quest_id,
24994
+ ...result
24995
+ });
24996
+ return result;
24997
+ },
24998
+ summary: (out) => {
24999
+ const failed = out.passed < out.total ? `, ${out.total - out.passed} failed` : "";
25000
+ return `${out.passed} of ${out.total} sample tests passed${failed}, scan ${out.scan_clear ? "clear" : "flagged"}. It ran on your computer and cost nothing.`;
25001
+ }
25002
+ };
24852
25003
  // src/local/realData.ts
24853
25004
  var RESULT_EXT = /\.(csv|json|xlsx?|txt|md|xml)$/i;
24854
25005
  var ENTRY_MAX_BYTES = 104857600;
@@ -24872,7 +25023,11 @@ async function pairRealData(dataDir) {
24872
25023
  kind: "sample",
24873
25024
  category: null,
24874
25025
  inputFile: path.join(dataDir, input),
24875
- expectedFile: path.join(dataDir, answer)
25026
+ expectedFile: path.join(dataDir, answer),
25027
+ compare: "exact",
25028
+ tolerance: null,
25029
+ timeLimitMs: RUN_LIMIT_MS,
25030
+ outcome: "output"
24876
25031
  });
24877
25032
  }
24878
25033
  if (tests.length === 0) throw new DeckError("BAD_INPUT", `${dataDir} has no pairs: put each real input beside its right answer with the same name, like invoice-01.pdf and invoice-01.csv`);