@niwa-labs/harness-zcode 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/tools.ts ADDED
@@ -0,0 +1,45 @@
1
+ /** ZCode's own tools, as the common model describes them. */
2
+
3
+ import { z } from "zod";
4
+
5
+ import { shapeOf } from "@niwa-labs/harness";
6
+ import type { Checklist, ToolShape, ToolTable } from "@niwa-labs/harness";
7
+
8
+ /** The built-in tools of ZCode (its `contracts` package names them). */
9
+ export const ZCODE_TOOLS: ToolTable = {
10
+ Bash: { category: "shell", target: ["command"] },
11
+ Read: { category: "read", target: ["file_path"] },
12
+ ReadPdf: { category: "read", target: ["file_path"] },
13
+ Write: { category: "edit", target: ["file_path"] },
14
+ Edit: { category: "edit", target: ["file_path"] },
15
+ ApplyPatch: { category: "edit" },
16
+ Grep: { category: "search", target: ["pattern"] },
17
+ Glob: { category: "search", target: ["pattern"] },
18
+ ToolSearch: { category: "search", target: ["query"] },
19
+ WebFetch: { category: "web", target: ["url"] },
20
+ WebSearch: { category: "web", target: ["query"] },
21
+ TodoWrite: { category: "plan" },
22
+ TodoRead: { category: "plan" },
23
+ Agent: { category: "subagent", target: ["description"] },
24
+ Task: { category: "subagent", target: ["description"] },
25
+ };
26
+
27
+ /** A call of a ZCode tool, in the common model's words. */
28
+ export function zcodeToolShape(name: string, input: unknown): ToolShape {
29
+ return shapeOf(ZCODE_TOOLS, name, input);
30
+ }
31
+
32
+ /** The input of ZCode's `TodoWrite` (its `TodoItemSchema`): the whole list, each item with its state. */
33
+ const TodoWriteInput = z.object({
34
+ todos: z.array(z.object({ content: z.string(), status: z.enum(["pending", "in_progress", "completed"]) })),
35
+ });
36
+
37
+ const TODO_STATES = { pending: "pending", in_progress: "active", completed: "done" } as const;
38
+
39
+ /** The checklist a call leaves, when it is a `TodoWrite` whose input ZCode would accept. */
40
+ export function zcodeChecklist(name: string, input: unknown): Checklist | undefined {
41
+ if (name !== "TodoWrite") return undefined;
42
+ const parsed = TodoWriteInput.safeParse(input);
43
+ if (!parsed.success) return undefined;
44
+ return { items: parsed.data.todos.map((todo) => ({ text: todo.content, state: TODO_STATES[todo.status] })) };
45
+ }
@@ -0,0 +1,29 @@
1
+ // The ZCode reading side passes the conformance suite on its own fixtures.
2
+
3
+ import { expect, test } from "bun:test";
4
+
5
+ import { harnessKind, machineId, readingConformance } from "@niwa-labs/harness";
6
+ import type { Harness } from "@niwa-labs/harness";
7
+
8
+ import { FIXTURE_HARNESS, writeZcodeFixtures } from "../src/fixtures.ts";
9
+ import { ZcodeReading } from "../src/reading.ts";
10
+
11
+ test("zcode passes the reading conformance suite", async () => {
12
+ const report = await readingConformance(
13
+ "zcode",
14
+ (home) => {
15
+ const instance: Harness = {
16
+ id: FIXTURE_HARNESS,
17
+ kind: harnessKind("zcode"),
18
+ machine: machineId("machine-1"),
19
+ home,
20
+ sides: { reading: { list: true, read: true, watch: false } },
21
+ };
22
+ return { instance, reading: new ZcodeReading({ harness: FIXTURE_HARNESS, home }) };
23
+ },
24
+ writeZcodeFixtures,
25
+ )();
26
+ const failed = report.results.filter((result) => !result.passed);
27
+ expect(failed.map((result) => `${result.name}: ${result.detail ?? ""}`)).toEqual([]);
28
+ expect(report.results.length).toBeGreaterThan(40);
29
+ });