@thedeck/mcp 0.1.0 → 0.1.2

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 +122 -22
  3. package/dist/index.js +174 -47
  4. package/package.json +38 -38
package/README.md CHANGED
@@ -1,78 +1,78 @@
1
- # @thedeck/mcp
2
-
3
- The Deck's MCP server. It lets your AI agent draft tasks, send blanked example copies, propose tests, check
4
- your tasks and their passing entries, run the pre-check on your entry, and try passing entries on your real
5
- data. It acts as you, with the same rights you have on the site.
6
-
7
- An agent can never save a card, post a task live, accept an entry, pitch in or pay anyone. You do those on
8
- The Deck yourself.
9
-
10
- ## Connect
11
-
12
- Claude Code:
13
-
14
- ```sh
15
- claude mcp add thedeck -- npx @thedeck/mcp
16
- ```
17
-
18
- Codex:
19
-
20
- ```sh
21
- codex mcp add thedeck -- npx @thedeck/mcp
22
- ```
23
-
24
- GitHub Copilot in VS Code:
25
-
26
- ```sh
27
- code --add-mcp '{"name":"thedeck","command":"npx","args":["@thedeck/mcp"]}'
28
- ```
29
-
30
- The first time your agent uses a tool, your browser opens The Deck's consent page. Sign in, check what the
31
- agent may do, and press Allow. The sign-in is saved in `~/.thedeck/credentials.json`; disconnect the agent
32
- any time in Settings › Agent.
33
-
34
- ChatGPT and other clients that only connect to remote servers use `https://thedeck.dev/mcp` instead. That
35
- address has the poster tools and `deck.report_issue` only: nothing there runs on your computer. In Grok, open
36
- Connectors, choose New Connector, then Custom, enter that address and sign in to The Deck when asked.
37
-
38
- ## Tools
39
-
40
- | Tool | For | Runs |
41
- |---|---|---|
42
- | `deck.post_draft` | posters | The Deck |
43
- | `deck.add_example_copy` | posters | checks the copy here, then The Deck |
44
- | `deck.propose_tests` | posters | The Deck |
45
- | `deck.list_quests` | posters and builders | The Deck |
46
- | `deck.get_task_status` | posters | The Deck |
47
- | `deck.get_passing_entries` | posters | The Deck |
48
- | `deck.try_on_real_data` | posters | a sandbox on this computer |
49
- | `deck.run_precheck` | builders | a sandbox on this computer |
50
- | `deck.report_issue` | posters and builders, during the beta, with your yes | The Deck |
51
-
52
- Real files and real data never leave your computer: only blanked copies and scores do.
53
-
54
- ## The local sandbox
55
-
56
- `deck.run_precheck` and `deck.try_on_real_data` run entries the way The Deck's runner does, in a Docker
57
- container with no network. Install Docker and build the sandbox image once from this repository:
58
-
59
- ```sh
60
- docker build -f runner/Dockerfile --target sandbox -t thedeck-sandbox .
61
- ```
62
-
63
- An entry folder needs a `deck.json` naming the command that runs it, for example
64
- `{"run": ["python", "read_invoices.py", "{input}", "{output}"]}`. Without `{output}`, what the program
65
- prints is its answer.
66
-
67
- For `deck.try_on_real_data`, put each real input beside its right answer with the same name, such as
68
- `invoice-01.pdf` and `invoice-01.csv`.
69
-
70
- ## Pre-check from a terminal
71
-
72
- ```sh
73
- npx -p @thedeck/mcp thedeck precheck <quest id> [entry folder]
74
- ```
75
-
76
- ## Settings
77
-
78
- `THEDECK_URL` points the server at another copy of The Deck, for example `http://127.0.0.1:3000` locally.
1
+ # @thedeck/mcp
2
+
3
+ The Deck's MCP server. It lets your AI agent draft tasks, send blanked example copies, propose tests, check
4
+ your tasks and their passing entries, run the pre-check on your entry, and try passing entries on your real
5
+ data. It acts as you, with the same rights you have on the site.
6
+
7
+ An agent can never save a card, post a task live, accept an entry, pitch in or pay anyone. You do those on
8
+ The Deck yourself.
9
+
10
+ ## Connect
11
+
12
+ Claude Code:
13
+
14
+ ```sh
15
+ claude mcp add thedeck -- npx @thedeck/mcp
16
+ ```
17
+
18
+ Codex:
19
+
20
+ ```sh
21
+ codex mcp add thedeck -- npx @thedeck/mcp
22
+ ```
23
+
24
+ GitHub Copilot in VS Code:
25
+
26
+ ```sh
27
+ code --add-mcp '{"name":"thedeck","command":"npx","args":["@thedeck/mcp"]}'
28
+ ```
29
+
30
+ The first time your agent uses a tool, your browser opens The Deck's consent page. Sign in, check what the
31
+ agent may do, and press Allow. The sign-in is saved in `~/.thedeck/credentials.json`; disconnect the agent
32
+ any time in Settings › Agent.
33
+
34
+ ChatGPT and other clients that only connect to remote servers use `https://thedeck.dev/mcp` instead. That
35
+ address has the poster tools and `deck.report_issue` only: nothing there runs on your computer. In Grok, open
36
+ Connectors, choose New Connector, then Custom, enter that address and sign in to The Deck when asked.
37
+
38
+ ## Tools
39
+
40
+ | Tool | For | Runs |
41
+ |---|---|---|
42
+ | `deck.post_draft` | posters | The Deck |
43
+ | `deck.add_example_copy` | posters | checks the copy here, then The Deck; over `/mcp`, after you approve the exact copy in the chat |
44
+ | `deck.propose_tests` | posters | The Deck, after you approve the test plan in the chat |
45
+ | `deck.list_quests` | posters and builders | The Deck |
46
+ | `deck.get_task_status` | posters | The Deck |
47
+ | `deck.get_passing_entries` | posters | The Deck |
48
+ | `deck.try_on_real_data` | posters | a sandbox on this computer |
49
+ | `deck.run_precheck` | builders | a sandbox on this computer |
50
+ | `deck.report_issue` | posters and builders, during the beta, with your yes | The Deck |
51
+
52
+ Real files and real data never leave your computer: only blanked copies and scores do.
53
+
54
+ ## The local sandbox
55
+
56
+ `deck.run_precheck` and `deck.try_on_real_data` run entries the way The Deck's runner does, in a Docker
57
+ container with no network. Install Docker and build the sandbox image once from this repository:
58
+
59
+ ```sh
60
+ docker build -f runner/Dockerfile --target sandbox -t thedeck-sandbox .
61
+ ```
62
+
63
+ An entry folder needs a `deck.json` naming the command that runs it, for example
64
+ `{"run": ["python", "read_invoices.py", "{input}", "{output}"]}`. Without `{output}`, what the program
65
+ prints is its answer.
66
+
67
+ For `deck.try_on_real_data`, put each real input beside its right answer with the same name, such as
68
+ `invoice-01.pdf` and `invoice-01.csv`.
69
+
70
+ ## Pre-check from a terminal
71
+
72
+ ```sh
73
+ npx -p @thedeck/mcp thedeck precheck <quest id> [entry folder]
74
+ ```
75
+
76
+ ## Settings
77
+
78
+ `THEDECK_URL` points the server at another copy of The Deck, for example `http://127.0.0.1:3000` locally.
package/dist/cli.js CHANGED
@@ -52,6 +52,15 @@ var tagLabel = z.object({
52
52
  label: z.string().min(1)
53
53
  }).strict();
54
54
  z.discriminatedUnion("kind", [usernameLabel, tagLabel]);
55
+ // ../shared/src/money.ts
56
+ var MAX_REWARD_CENTS = 2e9;
57
+ // ../shared/src/time.ts
58
+ var zones = null;
59
+ function isTimeZone(value) {
60
+ if (!value) return false;
61
+ zones ??= new Set(Intl.supportedValuesOf("timeZone"));
62
+ return value === "UTC" || zones.has(value);
63
+ }
55
64
  var deliverableSchema = z.enum([
56
65
  "code",
57
66
  "setup_notes",
@@ -126,6 +135,20 @@ z.object({
126
135
  of: z.number().int().positive(),
127
136
  due_at: z.string()
128
137
  });
138
+ // ../shared/src/schemas/testCheck.ts
139
+ var TEST_COMPARES = [
140
+ "exact",
141
+ "unordered_lines",
142
+ "numbers",
143
+ "json"
144
+ ];
145
+ var TEST_OUTCOMES = ["output", "fails_cleanly"];
146
+ var TEST_DEFAULTS = {
147
+ compare: "exact",
148
+ tolerance: 1e-6,
149
+ timeLimitMs: 1e4,
150
+ outcome: "output"
151
+ };
129
152
  // ../shared/src/schemas/mcp.ts
130
153
  var questId = z.uuid();
131
154
  var section = z.string().trim().min(1).max(BRIEF_LIMITS.section);
@@ -161,6 +184,8 @@ var scenario = z.object({
161
184
  expected: z.string().trim().min(1).max(2e3)
162
185
  });
163
186
  var scenarios = z.array(scenario).min(1).max(10);
187
+ var ASK_END_DATE = "Give the last day builders can enter as YYYY-MM-DD, the date the person stated. Ask the person for the end date.";
188
+ var ASK_TIME_ZONE = "Give the person’s IANA time zone, such as America/New_York. Ask the person which time zone they are in, or confirm the one you know; never guess it.";
164
189
  var postDraftInput = z.object({
165
190
  quest_id: questId.optional(),
166
191
  title: z.string().trim().min(1).max(BRIEF_LIMITS.title),
@@ -170,8 +195,11 @@ var postDraftInput = z.object({
170
195
  handover: section,
171
196
  judging_notes: section,
172
197
  deliverables: z.array(deliverableSchema).min(1),
173
- deadline_days: z.number().int().positive().optional(),
174
- 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.")
198
+ 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."),
199
+ 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."),
200
+ 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."),
201
+ 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."),
202
+ 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.")
175
203
  });
176
204
  var postPart = z.enum([
177
205
  "title",
@@ -188,6 +216,7 @@ var postPart = z.enum([
188
216
  var postDraftOutput = z.object({
189
217
  quest_id: questId,
190
218
  review_url: z.url(),
219
+ pay_url: z.url(),
191
220
  missing: z.array(z.object({
192
221
  part: postPart,
193
222
  label: z.string()
@@ -201,28 +230,50 @@ var addExampleCopyInput = z.object({
201
230
  filename: z.string().trim().min(1).max(255),
202
231
  content: z.string(),
203
232
  blanked_summary: z.string().trim().min(1),
204
- 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.")
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."),
234
+ 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.")
205
235
  });
206
236
  var addExampleCopyOutput = z.object({
207
237
  example_id: z.uuid(),
208
- status: z.literal("pending")
238
+ status: z.enum(["pending", "approved"])
239
+ });
240
+ var isJson = (text) => {
241
+ try {
242
+ JSON.parse(text);
243
+ return true;
244
+ } catch {
245
+ return false;
246
+ }
247
+ };
248
+ var proposedTest = z.object({
249
+ name: z.string().trim().min(1),
250
+ kind: z.enum(["sample", "hidden"]),
251
+ input: z.string(),
252
+ expected: z.string().describe("The expected output. For outcome fails_cleanly, a short note of why the input is bad; it is shown to the person, not compared."),
253
+ 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."),
254
+ 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."),
255
+ tolerance: z.number().nonnegative().optional().describe(`Only with compare numbers: how far each number may be from the expected one. Default ${TEST_DEFAULTS.tolerance}.`),
256
+ 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.`),
257
+ 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.")
258
+ }).refine((t) => t.tolerance === void 0 || t.compare === "numbers", {
259
+ path: ["tolerance"],
260
+ error: "tolerance applies only with compare numbers"
261
+ }).refine((t) => t.compare !== "json" || t.outcome === "fails_cleanly" || isJson(t.expected), {
262
+ path: ["expected"],
263
+ error: "with compare json, expected must be valid JSON"
209
264
  });
210
265
  var proposeTestsInput = z.object({
211
266
  quest_id: questId,
212
- tests: z.array(z.object({
213
- name: z.string().trim().min(1),
214
- kind: z.enum(["sample", "hidden"]),
215
- input: z.string(),
216
- expected: z.string(),
217
- category: z.string().trim().min(1).optional()
218
- })).min(1),
219
- suggested_pass_mark: z.number().int().positive()
267
+ 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."),
268
+ suggested_pass_mark: z.number().int().positive(),
269
+ 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.")
220
270
  });
221
271
  var proposeTestsOutput = z.object({
222
272
  quest_id: questId,
223
273
  samples: z.number().int().nonnegative(),
224
274
  hidden: z.number().int().nonnegative(),
225
- pass_mark: z.number().int().nonnegative()
275
+ pass_mark: z.number().int().nonnegative(),
276
+ status: z.enum(["pending", "approved"])
226
277
  });
227
278
  var listQuestsInput = z.object({
228
279
  query: z.string().trim().optional(),
@@ -250,7 +301,7 @@ var getTaskStatusInput = z.object({ quest_id: questId });
250
301
  var getTaskStatusOutput = z.object({
251
302
  entries: z.number().int().nonnegative(),
252
303
  passed: z.number().int().nonnegative(),
253
- days_left: z.number().int().nullable(),
304
+ days_left: z.number().int().nullable().describe("Whole days to the deadline’s day: 0 on the last day, below 0 once it has passed."),
254
305
  discussion: z.object({
255
306
  ends_at: z.string(),
256
307
  revisions_used: z.number().int().nonnegative(),
@@ -299,7 +350,11 @@ var precheckKitOutput = z.object({
299
350
  input_file: z.string().min(1),
300
351
  input: z.base64(),
301
352
  expected_file: z.string().min(1),
302
- expected: z.base64()
353
+ expected: z.base64(),
354
+ compare: z.enum(TEST_COMPARES).optional(),
355
+ tolerance: z.number().nonnegative().nullable().optional(),
356
+ time_limit_ms: z.number().int().positive().optional(),
357
+ outcome: z.enum(TEST_OUTCOMES).optional()
303
358
  }))
304
359
  });
305
360
  var precheckReportInput = z.object({
@@ -358,7 +413,7 @@ var MCP_TOOLS = {
358
413
  "deck.add_example_copy": {
359
414
  input: addExampleCopyInput,
360
415
  output: addExampleCopyOutput,
361
- remote: false
416
+ remote: true
362
417
  },
363
418
  "deck.propose_tests": {
364
419
  input: proposeTestsInput,
@@ -741,6 +796,42 @@ function sameOutput(actual, expected) {
741
796
  const norm = (b) => b.toString("latin1").replaceAll("\r\n", "\n").trimEnd();
742
797
  return norm(actual) === norm(expected);
743
798
  }
799
+ var text = (b) => b.toString("utf8").replaceAll("\r\n", "\n").trimEnd();
800
+ var byCodeUnit = (a, b) => Number(a > b) - Number(a < b);
801
+ function sameLinesAnyOrder(actual, expected) {
802
+ const a = actual.split("\n").sort(byCodeUnit);
803
+ const e = expected.split("\n").sort(byCodeUnit);
804
+ return a.length === e.length && a.every((line, i) => line === e[i]);
805
+ }
806
+ var NUMBER = /-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
807
+ function sameNumbers(actual, expected, tolerance) {
808
+ const a = actual.match(NUMBER) ?? [];
809
+ const e = expected.match(NUMBER) ?? [];
810
+ const around = (s) => JSON.stringify(s.split(NUMBER));
811
+ return around(actual) === around(expected) && a.length === e.length && a.every((n, i) => Math.abs(Number(n) - Number(e[i])) <= tolerance);
812
+ }
813
+ function canonical(value) {
814
+ if (Array.isArray(value)) return value.map(canonical);
815
+ if (value === null || typeof value !== "object") return value;
816
+ const object = value;
817
+ return Object.fromEntries(Object.keys(object).sort(byCodeUnit).map((key) => [key, canonical(object[key])]));
818
+ }
819
+ function sameJson(actual, expected) {
820
+ try {
821
+ return JSON.stringify(canonical(JSON.parse(actual))) === JSON.stringify(canonical(JSON.parse(expected)));
822
+ } catch {
823
+ return false;
824
+ }
825
+ }
826
+ function outputMatches(actual, expected, compare, tolerance) {
827
+ switch (compare) {
828
+ case "exact": return sameOutput(actual, expected);
829
+ case "unordered_lines": return sameLinesAnyOrder(text(actual), text(expected));
830
+ case "numbers": return sameNumbers(text(actual), text(expected), tolerance ?? TEST_DEFAULTS.tolerance);
831
+ case "json": return sameJson(text(actual), text(expected));
832
+ }
833
+ }
834
+ var refusedCleanly = (exitCode) => exitCode > 0 && exitCode < 128;
744
835
  function slotPaths(index, test) {
745
836
  const dir = `${TESTS_DIR}/${index}`;
746
837
  return {
@@ -764,16 +855,20 @@ function groupFailures(failed) {
764
855
  count
765
856
  })).sort((a, b) => b.count - a.count);
766
857
  }
767
- async function runOne(sandbox, command, index, test, timeoutMs) {
858
+ async function runOne(sandbox, command, index, test, left) {
768
859
  const slot = slotPaths(index, test);
769
860
  const argv = command.argv.map((a) => a.replaceAll("{input}", slot.input).replaceAll("{output}", slot.output));
770
861
  const result = await sandbox.exec(argv, {
771
862
  cwd: ENTRY_DIR,
772
- timeoutMs
863
+ timeoutMs: Math.min(test.timeLimitMs, left)
773
864
  });
774
865
  if (result.timedOut) return {
775
866
  passed: false,
776
- timedOut: true
867
+ timedOut: left <= test.timeLimitMs
868
+ };
869
+ if (test.outcome === "fails_cleanly") return {
870
+ passed: refusedCleanly(result.exitCode),
871
+ timedOut: false
777
872
  };
778
873
  if (result.exitCode !== 0) return {
779
874
  passed: false,
@@ -781,7 +876,7 @@ async function runOne(sandbox, command, index, test, timeoutMs) {
781
876
  };
782
877
  const actual = command.outputToFile ? await sandbox.readFile(slot.output, OUTPUT_MAX_BYTES) : Buffer.from(result.stdout, "utf8");
783
878
  return {
784
- passed: actual !== null && sameOutput(actual, await readFile(test.expectedFile)),
879
+ passed: actual !== null && outputMatches(actual, await readFile(test.expectedFile), test.compare, test.tolerance),
785
880
  timedOut: false
786
881
  };
787
882
  }
@@ -22502,6 +22597,7 @@ var E2B_TEMPLATE = process.env.E2B_TEMPLATE ?? "thedeck-sandbox";
22502
22597
  var OUTPUT_CAP = 1048576;
22503
22598
  var DOCKER = process.env.DOCKER_BIN ?? "docker";
22504
22599
  var run = promisify(execFile);
22600
+ var DOCKER_CLOCK_SLACK = .8;
22505
22601
  function exitCodeOf(err) {
22506
22602
  if (!err) return 0;
22507
22603
  return typeof err.code === "number" ? err.code : -1;
@@ -22648,7 +22744,7 @@ var DockerSandbox = class DockerSandbox {
22648
22744
  reject(new Error("docker exec failed", { cause: err }));
22649
22745
  return;
22650
22746
  }
22651
- const timedOut = Boolean(err?.killed) || code === 137 && Date.now() - started >= seconds * 1e3;
22747
+ const timedOut = Boolean(err?.killed) || code === 137 && Date.now() - started >= seconds * 1e3 * DOCKER_CLOCK_SLACK;
22652
22748
  resolve({
22653
22749
  exitCode: code,
22654
22750
  stdout: capped(stdout),
@@ -22930,7 +23026,11 @@ async function stageKit(kit, dir) {
22930
23026
  kind: "sample",
22931
23027
  category: null,
22932
23028
  inputFile,
22933
- expectedFile
23029
+ expectedFile,
23030
+ compare: test.compare ?? TEST_DEFAULTS.compare,
23031
+ tolerance: test.tolerance ?? null,
23032
+ timeLimitMs: test.time_limit_ms ?? TEST_DEFAULTS.timeLimitMs,
23033
+ outcome: test.outcome ?? TEST_DEFAULTS.outcome
22934
23034
  });
22935
23035
  }
22936
23036
  return tests;
package/dist/index.js CHANGED
@@ -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;
@@ -65,6 +66,19 @@ function formatMoney(cents, currency = "USD") {
65
66
  maximumFractionDigits: 2
66
67
  }).format(cents / 100);
67
68
  }
69
+ // ../shared/src/time.ts
70
+ var zones = null;
71
+ function isTimeZone(value) {
72
+ if (!value) return false;
73
+ zones ??= new Set(Intl.supportedValuesOf("timeZone"));
74
+ return value === "UTC" || zones.has(value);
75
+ }
76
+ function daysLeftText(days) {
77
+ if (days === null) return "No deadline";
78
+ if (days < 0) return "Deadline passed";
79
+ if (days === 0) return "Last day";
80
+ return `${days} ${days === 1 ? "day" : "days"} left`;
81
+ }
68
82
  var deliverableSchema = z.enum([
69
83
  "code",
70
84
  "setup_notes",
@@ -139,6 +153,20 @@ z.object({
139
153
  of: z.number().int().positive(),
140
154
  due_at: z.string()
141
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
+ };
142
170
  // ../shared/src/schemas/mcp.ts
143
171
  var questId = z.uuid();
144
172
  var section = z.string().trim().min(1).max(BRIEF_LIMITS.section);
@@ -174,6 +202,8 @@ var scenario = z.object({
174
202
  expected: z.string().trim().min(1).max(2e3)
175
203
  });
176
204
  var scenarios = z.array(scenario).min(1).max(10);
205
+ var ASK_END_DATE = "Give the last day builders can enter as YYYY-MM-DD, the date the person stated. Ask the person for the end date.";
206
+ var ASK_TIME_ZONE = "Give the person’s IANA time zone, such as America/New_York. Ask the person which time zone they are in, or confirm the one you know; never guess it.";
177
207
  var postDraftInput = z.object({
178
208
  quest_id: questId.optional(),
179
209
  title: z.string().trim().min(1).max(BRIEF_LIMITS.title),
@@ -183,8 +213,11 @@ var postDraftInput = z.object({
183
213
  handover: section,
184
214
  judging_notes: section,
185
215
  deliverables: z.array(deliverableSchema).min(1),
186
- deadline_days: z.number().int().positive().optional(),
187
- 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.")
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."),
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."),
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.")
188
221
  });
189
222
  var postPart = z.enum([
190
223
  "title",
@@ -201,6 +234,7 @@ var postPart = z.enum([
201
234
  var postDraftOutput = z.object({
202
235
  quest_id: questId,
203
236
  review_url: z.url(),
237
+ pay_url: z.url(),
204
238
  missing: z.array(z.object({
205
239
  part: postPart,
206
240
  label: z.string()
@@ -214,28 +248,50 @@ var addExampleCopyInput = z.object({
214
248
  filename: z.string().trim().min(1).max(255),
215
249
  content: z.string(),
216
250
  blanked_summary: z.string().trim().min(1),
217
- 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.")
251
+ 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."),
252
+ 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.")
218
253
  });
219
254
  var addExampleCopyOutput = z.object({
220
255
  example_id: z.uuid(),
221
- status: z.literal("pending")
256
+ status: z.enum(["pending", "approved"])
257
+ });
258
+ var isJson = (text) => {
259
+ try {
260
+ JSON.parse(text);
261
+ return true;
262
+ } catch {
263
+ return false;
264
+ }
265
+ };
266
+ var proposedTest = z.object({
267
+ name: z.string().trim().min(1),
268
+ kind: z.enum(["sample", "hidden"]),
269
+ input: z.string(),
270
+ expected: z.string().describe("The expected output. For outcome fails_cleanly, a short note of why the input is bad; it is shown to the person, not compared."),
271
+ 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."),
272
+ 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."),
273
+ tolerance: z.number().nonnegative().optional().describe(`Only with compare numbers: how far each number may be from the expected one. Default ${TEST_DEFAULTS.tolerance}.`),
274
+ 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.`),
275
+ 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.")
276
+ }).refine((t) => t.tolerance === void 0 || t.compare === "numbers", {
277
+ path: ["tolerance"],
278
+ error: "tolerance applies only with compare numbers"
279
+ }).refine((t) => t.compare !== "json" || t.outcome === "fails_cleanly" || isJson(t.expected), {
280
+ path: ["expected"],
281
+ error: "with compare json, expected must be valid JSON"
222
282
  });
223
283
  var proposeTestsInput = z.object({
224
284
  quest_id: questId,
225
- tests: z.array(z.object({
226
- name: z.string().trim().min(1),
227
- kind: z.enum(["sample", "hidden"]),
228
- input: z.string(),
229
- expected: z.string(),
230
- category: z.string().trim().min(1).optional()
231
- })).min(1),
232
- suggested_pass_mark: z.number().int().positive()
285
+ 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."),
286
+ suggested_pass_mark: z.number().int().positive(),
287
+ 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.")
233
288
  });
234
289
  var proposeTestsOutput = z.object({
235
290
  quest_id: questId,
236
291
  samples: z.number().int().nonnegative(),
237
292
  hidden: z.number().int().nonnegative(),
238
- pass_mark: z.number().int().nonnegative()
293
+ pass_mark: z.number().int().nonnegative(),
294
+ status: z.enum(["pending", "approved"])
239
295
  });
240
296
  var listQuestsInput = z.object({
241
297
  query: z.string().trim().optional(),
@@ -263,7 +319,7 @@ var getTaskStatusInput = z.object({ quest_id: questId });
263
319
  var getTaskStatusOutput = z.object({
264
320
  entries: z.number().int().nonnegative(),
265
321
  passed: z.number().int().nonnegative(),
266
- days_left: z.number().int().nullable(),
322
+ days_left: z.number().int().nullable().describe("Whole days to the deadline’s day: 0 on the last day, below 0 once it has passed."),
267
323
  discussion: z.object({
268
324
  ends_at: z.string(),
269
325
  revisions_used: z.number().int().nonnegative(),
@@ -312,7 +368,11 @@ var precheckKitOutput = z.object({
312
368
  input_file: z.string().min(1),
313
369
  input: z.base64(),
314
370
  expected_file: z.string().min(1),
315
- expected: z.base64()
371
+ expected: z.base64(),
372
+ compare: z.enum(TEST_COMPARES).optional(),
373
+ tolerance: z.number().nonnegative().nullable().optional(),
374
+ time_limit_ms: z.number().int().positive().optional(),
375
+ outcome: z.enum(TEST_OUTCOMES).optional()
316
376
  }))
317
377
  });
318
378
  var precheckReportInput = z.object({
@@ -371,7 +431,7 @@ var MCP_TOOLS = {
371
431
  "deck.add_example_copy": {
372
432
  input: addExampleCopyInput,
373
433
  output: addExampleCopyOutput,
374
- remote: false
434
+ remote: true
375
435
  },
376
436
  "deck.propose_tests": {
377
437
  input: proposeTestsInput,
@@ -830,7 +890,6 @@ var SCRIPT = String.raw`
830
890
  const em = (t) => el('span', 'em', t);
831
891
  const mute = (t) => el('span', 'mute', t);
832
892
  const join = (parts) => parts.reduce((acc, x, n) => (n ? acc.concat(' · ', x) : acc.concat(x)), []);
833
- const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
834
893
  const safeUrl = (u) => typeof u === 'string' && /^https?:\/\//i.test(u);
835
894
 
836
895
  function openLink(label, url) {
@@ -851,12 +910,12 @@ var SCRIPT = String.raw`
851
910
  const CARDS = {
852
911
  draft(b, o, i) {
853
912
  if (i.title) b.append(p('ttl', i.title));
854
- b.append(p('', join([em('Draft saved'), i.deadline_days ? 'runs ' + plural(i.deadline_days, 'day', 'days') + ' once posted' : 'no deadline yet', mute('nothing charged')])));
913
+ b.append(p('', join([em('Draft saved'), i.ends_on ? 'ends ' + i.ends_on + ', 23:59 (' + i.time_zone + ')' : 'no deadline yet', mute('nothing charged')])));
855
914
  const scenarios = Array.isArray(o.scenarios) ? o.scenarios : Array.isArray(i.scenarios) ? i.scenarios : [];
856
915
  if (scenarios.length) b.append(el('p', 'lbl', 'Scenarios'), scenarioList(scenarios));
857
916
  const missing = o.missing || [];
858
917
  b.append(missing.length ? p('', [mute('Still needed: '), missing.map((m) => m.label).join('; ')]) : p('', [em('Nothing missing'), ' · ready to post from The Deck']));
859
- 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.')]));
918
+ if (safeUrl(o.review_url)) b.append(el('div', 'acts', [openLink('Review on The Deck', o.review_url), mute('Paying and posting stay yours.')]));
860
919
  },
861
920
  entries(b, o) {
862
921
  const entries = o.entries || [];
@@ -996,25 +1055,29 @@ function registerCard(server, tool) {
996
1055
  };
997
1056
  }
998
1057
  // src/guidance.ts
1058
+ 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. 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.";
999
1059
  var POSTING_STEPS = [
1000
1060
  "To help a person post a task, go through these steps in order, one at a time:",
1001
- "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.",
1061
+ "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.",
1002
1062
  "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.",
1003
- "3. Work out the technical details the post needs: inputs, outputs, formats, what counts as right, and constraints.",
1004
- "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.",
1005
- "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.",
1006
- "6. The person sets the reward and who can see the task, then confirms and pays on The Deck."
1063
+ "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.",
1064
+ "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.",
1065
+ "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. 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. 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.",
1066
+ "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.",
1067
+ "7. When deck.post_draft says nothing is missing, give the person its pay link. They open it and pay the held deposit on Stripe themselves, which posts the task. While something is still missing, the same link opens the review page, which shows what."
1007
1068
  ].join("\n");
1008
- 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.";
1069
+ 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.";
1009
1070
  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.";
1010
1071
  var INSTRUCTIONS = [
1011
1072
  "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.",
1073
+ CONVERSATION,
1012
1074
  POSTING_STEPS,
1013
1075
  NEVER,
1014
1076
  REPORTS
1015
1077
  ].join("\n\n");
1016
1078
  var POST_A_TASK = [
1017
1079
  "Help me post a task on The Deck. Take it one step at a time and wait for my answer at each step.",
1080
+ CONVERSATION,
1018
1081
  POSTING_STEPS,
1019
1082
  NEVER,
1020
1083
  REPORTS
@@ -1022,7 +1085,7 @@ var POST_A_TASK = [
1022
1085
  function registerPostATask(server) {
1023
1086
  server.registerPrompt("post_a_task", {
1024
1087
  title: "Post a task on The Deck",
1025
- description: "Work out a task with the person, from what they need to a draft they post and pay for on The Deck."
1088
+ 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."
1026
1089
  }, () => ({ messages: [{
1027
1090
  role: "user",
1028
1091
  content: {
@@ -1068,6 +1131,7 @@ async function checkBlankedCopy(input, dir) {
1068
1131
  };
1069
1132
  }
1070
1133
  // src/tools/addExampleCopy.ts
1134
+ 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.` : `Blanked copy sent as example ${out.example_id}, status ${out.status}. It waits on the poster’s Examples list for approval.`;
1071
1135
  var addExampleCopy = {
1072
1136
  name: "deck.add_example_copy",
1073
1137
  title: "Send a blanked example copy",
@@ -1079,7 +1143,23 @@ var addExampleCopy = {
1079
1143
  filename: copy.filename
1080
1144
  });
1081
1145
  },
1082
- summary: (out) => `Blanked copy sent as example ${out.example_id}, status ${out.status}. It waits on the poster’s Examples list for approval.`
1146
+ summary
1147
+ };
1148
+ var addExampleCopyRemote = {
1149
+ name: "deck.add_example_copy",
1150
+ title: "Send a blanked example copy",
1151
+ 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. Never send the original.",
1152
+ async run(backend, args) {
1153
+ 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");
1154
+ const size = decodeCopy(args.content).length;
1155
+ if (size === 0) throw new DeckError("BAD_INPUT", "the copy is empty");
1156
+ if (size > 52428800) throw new DeckError("FILE_TOO_LARGE", `the copy is ${size} bytes; the limit is ${COPY_MAX_BYTES}`);
1157
+ return backend.addExampleCopy({
1158
+ ...args,
1159
+ filename: blankedName(args.filename)
1160
+ });
1161
+ },
1162
+ summary
1083
1163
  };
1084
1164
  // src/tools/getPassingEntries.ts
1085
1165
  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)})`;
@@ -1092,11 +1172,6 @@ var getPassingEntries = {
1092
1172
  summary: (out) => [out.entries.length === 1 ? "1 passing, scan-clear entry at its latest version. The link expires in 60 seconds." : `${out.entries.length} passing, scan-clear entries at their latest versions. Links expire in 60 seconds.`, ...out.entries.map(line$1)].join("\n")
1093
1173
  };
1094
1174
  // src/tools/getTaskStatus.ts
1095
- function daysText(days) {
1096
- if (days === null) return "No deadline";
1097
- if (days === 0) return "Deadline passed";
1098
- return `${plural(days, "day", "days")} left`;
1099
- }
1100
1175
  function discussionText(d) {
1101
1176
  return `Discussion open until ${utc(d.ends_at)}, ${plural(d.revisions_used, "revision", "revisions")} used, deposit ${d.deposit_held ? "held" : "not held"}`;
1102
1177
  }
@@ -1109,7 +1184,7 @@ var getTaskStatus = {
1109
1184
  summary: (out) => [
1110
1185
  plural(out.entries, "entry", "entries"),
1111
1186
  `${out.passed} passed`,
1112
- daysText(out.days_left),
1187
+ daysLeftText(out.days_left),
1113
1188
  ...out.discussion ? [discussionText(out.discussion)] : []
1114
1189
  ].join(" · ")
1115
1190
  };
@@ -1140,11 +1215,11 @@ var listQuests = {
1140
1215
  var postDraft = {
1141
1216
  name: "deck.post_draft",
1142
1217
  title: "Draft a task",
1143
- description: "For posters. Saves a task brief on The Deck as a draft, or updates the draft named by quest_id. 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.",
1218
+ 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 on Stripe themselves, which posts the task. An agent never posts a task live and never spends money.",
1144
1219
  run: (backend, args) => backend.postDraft(args),
1145
1220
  summary: (out) => {
1146
- 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.`;
1147
- if (out.missing.length === 0) return `${saved} Nothing is missing: the poster can post it from that page.`;
1221
+ if (out.missing.length === 0) return `Draft saved as quest ${out.quest_id}. Nothing is missing. Give the person this link to pay the held deposit on Stripe themselves, which posts the task: ${out.pay_url}`;
1222
+ const saved = `Draft saved as quest ${out.quest_id}. The poster checks it at ${out.review_url}; paying and posting stay theirs.`;
1148
1223
  const needsTests = out.missing.some((m) => m.part === "tests" || m.part === "examples");
1149
1224
  return [
1150
1225
  saved,
@@ -1157,9 +1232,9 @@ var postDraft = {
1157
1232
  var proposeTests = {
1158
1233
  name: "deck.propose_tests",
1159
1234
  title: "Propose tests",
1160
- 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.",
1235
+ 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. 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.",
1161
1236
  run: (backend, args) => backend.proposeTests(args),
1162
- 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.`
1237
+ 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.")
1163
1238
  };
1164
1239
  // src/tools/reportIssue.ts
1165
1240
  var reportIssue = {
@@ -1183,7 +1258,6 @@ var SERVER_INFO = {
1183
1258
  };
1184
1259
  var SHARED_TOOLS = [
1185
1260
  postDraft,
1186
- addExampleCopy,
1187
1261
  proposeTests,
1188
1262
  listQuests,
1189
1263
  getTaskStatus,
@@ -1240,7 +1314,11 @@ function register(server, tool, backend) {
1240
1314
  function createDeckServer(backend, options = { remote: false }) {
1241
1315
  const server = new McpServer(SERVER_INFO, { instructions: INSTRUCTIONS });
1242
1316
  registerPostATask(server);
1243
- const tools = options.remote ? SHARED_TOOLS : [...SHARED_TOOLS, ...options.localTools ?? []];
1317
+ const tools = options.remote ? [...SHARED_TOOLS, addExampleCopyRemote] : [
1318
+ ...SHARED_TOOLS,
1319
+ addExampleCopy,
1320
+ ...options.localTools ?? []
1321
+ ];
1244
1322
  for (const tool of tools) {
1245
1323
  if (options.remote && !MCP_TOOLS[tool.name].remote) continue;
1246
1324
  register(server, tool, backend);
@@ -1289,6 +1367,42 @@ function sameOutput(actual, expected) {
1289
1367
  const norm = (b) => b.toString("latin1").replaceAll("\r\n", "\n").trimEnd();
1290
1368
  return norm(actual) === norm(expected);
1291
1369
  }
1370
+ var text = (b) => b.toString("utf8").replaceAll("\r\n", "\n").trimEnd();
1371
+ var byCodeUnit = (a, b) => Number(a > b) - Number(a < b);
1372
+ function sameLinesAnyOrder(actual, expected) {
1373
+ const a = actual.split("\n").sort(byCodeUnit);
1374
+ const e = expected.split("\n").sort(byCodeUnit);
1375
+ return a.length === e.length && a.every((line, i) => line === e[i]);
1376
+ }
1377
+ var NUMBER = /-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?/g;
1378
+ function sameNumbers(actual, expected, tolerance) {
1379
+ const a = actual.match(NUMBER) ?? [];
1380
+ const e = expected.match(NUMBER) ?? [];
1381
+ const around = (s) => JSON.stringify(s.split(NUMBER));
1382
+ return around(actual) === around(expected) && a.length === e.length && a.every((n, i) => Math.abs(Number(n) - Number(e[i])) <= tolerance);
1383
+ }
1384
+ function canonical(value) {
1385
+ if (Array.isArray(value)) return value.map(canonical);
1386
+ if (value === null || typeof value !== "object") return value;
1387
+ const object = value;
1388
+ return Object.fromEntries(Object.keys(object).sort(byCodeUnit).map((key) => [key, canonical(object[key])]));
1389
+ }
1390
+ function sameJson(actual, expected) {
1391
+ try {
1392
+ return JSON.stringify(canonical(JSON.parse(actual))) === JSON.stringify(canonical(JSON.parse(expected)));
1393
+ } catch {
1394
+ return false;
1395
+ }
1396
+ }
1397
+ function outputMatches(actual, expected, compare, tolerance) {
1398
+ switch (compare) {
1399
+ case "exact": return sameOutput(actual, expected);
1400
+ case "unordered_lines": return sameLinesAnyOrder(text(actual), text(expected));
1401
+ case "numbers": return sameNumbers(text(actual), text(expected), tolerance ?? TEST_DEFAULTS.tolerance);
1402
+ case "json": return sameJson(text(actual), text(expected));
1403
+ }
1404
+ }
1405
+ var refusedCleanly = (exitCode) => exitCode > 0 && exitCode < 128;
1292
1406
  function slotPaths(index, test) {
1293
1407
  const dir = `${TESTS_DIR}/${index}`;
1294
1408
  return {
@@ -1312,16 +1426,20 @@ function groupFailures(failed) {
1312
1426
  count
1313
1427
  })).sort((a, b) => b.count - a.count);
1314
1428
  }
1315
- async function runOne(sandbox, command, index, test, timeoutMs) {
1429
+ async function runOne(sandbox, command, index, test, left) {
1316
1430
  const slot = slotPaths(index, test);
1317
1431
  const argv = command.argv.map((a) => a.replaceAll("{input}", slot.input).replaceAll("{output}", slot.output));
1318
1432
  const result = await sandbox.exec(argv, {
1319
1433
  cwd: ENTRY_DIR,
1320
- timeoutMs
1434
+ timeoutMs: Math.min(test.timeLimitMs, left)
1321
1435
  });
1322
1436
  if (result.timedOut) return {
1323
1437
  passed: false,
1324
- timedOut: true
1438
+ timedOut: left <= test.timeLimitMs
1439
+ };
1440
+ if (test.outcome === "fails_cleanly") return {
1441
+ passed: refusedCleanly(result.exitCode),
1442
+ timedOut: false
1325
1443
  };
1326
1444
  if (result.exitCode !== 0) return {
1327
1445
  passed: false,
@@ -1329,7 +1447,7 @@ async function runOne(sandbox, command, index, test, timeoutMs) {
1329
1447
  };
1330
1448
  const actual = command.outputToFile ? await sandbox.readFile(slot.output, OUTPUT_MAX_BYTES) : Buffer.from(result.stdout, "utf8");
1331
1449
  return {
1332
- passed: actual !== null && sameOutput(actual, await readFile(test.expectedFile)),
1450
+ passed: actual !== null && outputMatches(actual, await readFile(test.expectedFile), test.compare, test.tolerance),
1333
1451
  timedOut: false
1334
1452
  };
1335
1453
  }
@@ -23050,6 +23168,7 @@ var E2B_TEMPLATE = process.env.E2B_TEMPLATE ?? "thedeck-sandbox";
23050
23168
  var OUTPUT_CAP = 1048576;
23051
23169
  var DOCKER = process.env.DOCKER_BIN ?? "docker";
23052
23170
  var run = promisify(execFile);
23171
+ var DOCKER_CLOCK_SLACK = .8;
23053
23172
  function exitCodeOf(err) {
23054
23173
  if (!err) return 0;
23055
23174
  return typeof err.code === "number" ? err.code : -1;
@@ -23196,7 +23315,7 @@ var DockerSandbox = class DockerSandbox {
23196
23315
  reject(new Error("docker exec failed", { cause: err }));
23197
23316
  return;
23198
23317
  }
23199
- const timedOut = Boolean(err?.killed) || code === 137 && Date.now() - started >= seconds * 1e3;
23318
+ const timedOut = Boolean(err?.killed) || code === 137 && Date.now() - started >= seconds * 1e3 * DOCKER_CLOCK_SLACK;
23200
23319
  resolve({
23201
23320
  exitCode: code,
23202
23321
  stdout: capped(stdout),
@@ -23478,7 +23597,11 @@ async function stageKit(kit, dir) {
23478
23597
  kind: "sample",
23479
23598
  category: null,
23480
23599
  inputFile,
23481
- expectedFile
23600
+ expectedFile,
23601
+ compare: test.compare ?? TEST_DEFAULTS.compare,
23602
+ tolerance: test.tolerance ?? null,
23603
+ timeLimitMs: test.time_limit_ms ?? TEST_DEFAULTS.timeLimitMs,
23604
+ outcome: test.outcome ?? TEST_DEFAULTS.outcome
23482
23605
  });
23483
23606
  }
23484
23607
  return tests;
@@ -24862,7 +24985,11 @@ async function pairRealData(dataDir) {
24862
24985
  kind: "sample",
24863
24986
  category: null,
24864
24987
  inputFile: path.join(dataDir, input),
24865
- expectedFile: path.join(dataDir, answer)
24988
+ expectedFile: path.join(dataDir, answer),
24989
+ compare: "exact",
24990
+ tolerance: null,
24991
+ timeLimitMs: RUN_LIMIT_MS,
24992
+ outcome: "output"
24866
24993
  });
24867
24994
  }
24868
24995
  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`);
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
- {
2
- "name": "@thedeck/mcp",
3
- "version": "0.1.0",
4
- "type": "module",
5
- "bin": {
6
- "mcp": "dist/index.js",
7
- "thedeck-mcp": "dist/index.js",
8
- "thedeck": "dist/cli.js"
9
- },
10
- "exports": {
11
- ".": "./src/server.ts",
12
- "./backend": "./src/backend.ts"
13
- },
14
- "files": [
15
- "dist"
16
- ],
17
- "scripts": {
18
- "build": "vite build --ssr src/index.ts --outDir dist && vite build --ssr src/cli.ts --outDir dist --emptyOutDir false",
19
- "typecheck": "tsc --noEmit",
20
- "lint": "eslint .",
21
- "test": "vitest run"
22
- },
23
- "dependencies": {
24
- "@modelcontextprotocol/sdk": "1.32.1",
25
- "zod": "4.6.7"
26
- },
27
- "devDependencies": {
28
- "@modelcontextprotocol/ext-apps": "1.7.5",
29
- "@thedeck/runner": "workspace:*",
30
- "@thedeck/shared": "workspace:*",
31
- "@types/node": "26.6.5",
32
- "@vitest/coverage-v8": "5.0.5",
33
- "happy-dom": "21.0.4",
34
- "typescript": "6.0.3",
35
- "vite": "8.3.5",
36
- "vitest": "5.0.5"
37
- }
38
- }
1
+ {
2
+ "name": "@thedeck/mcp",
3
+ "version": "0.1.2",
4
+ "type": "module",
5
+ "bin": {
6
+ "mcp": "dist/index.js",
7
+ "thedeck-mcp": "dist/index.js",
8
+ "thedeck": "dist/cli.js"
9
+ },
10
+ "exports": {
11
+ ".": "./src/server.ts",
12
+ "./backend": "./src/backend.ts"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "vite build --ssr src/index.ts --outDir dist && vite build --ssr src/cli.ts --outDir dist --emptyOutDir false",
19
+ "typecheck": "tsc --noEmit",
20
+ "lint": "eslint .",
21
+ "test": "vitest run"
22
+ },
23
+ "dependencies": {
24
+ "@modelcontextprotocol/sdk": "1.32.1",
25
+ "zod": "4.6.7"
26
+ },
27
+ "devDependencies": {
28
+ "@modelcontextprotocol/ext-apps": "1.7.5",
29
+ "@thedeck/runner": "workspace:*",
30
+ "@thedeck/shared": "workspace:*",
31
+ "@types/node": "26.6.5",
32
+ "@vitest/coverage-v8": "5.0.5",
33
+ "happy-dom": "21.0.4",
34
+ "typescript": "6.0.3",
35
+ "vite": "8.3.5",
36
+ "vitest": "5.0.5"
37
+ }
38
+ }