@skill-harness/adapters 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mojo Manyana
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ import type { HarnessAdapter } from "@skill-harness/core";
2
+ import { piAdapter } from "./pi.js";
3
+ export declare function getAdapter(name: string): HarnessAdapter;
4
+ export { piAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import { piAdapter } from "./pi.js";
2
+ /**
3
+ * Registered harnesses. pi is the only one (per project scope). The interface
4
+ * (`HarnessAdapter`) is the extension point — add an entry here to support more.
5
+ */
6
+ const ADAPTERS = {
7
+ pi: piAdapter,
8
+ };
9
+ export function getAdapter(name) {
10
+ const a = ADAPTERS[name];
11
+ if (!a) {
12
+ throw new Error(`unknown harness \`${name}\` (available: ${Object.keys(ADAPTERS).join(", ")})`);
13
+ }
14
+ return a;
15
+ }
16
+ export { piAdapter };
17
+ //# sourceMappingURL=index.js.map
package/dist/pi.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { HarnessAdapter } from "@skill-harness/core";
2
+ export declare const piAdapter: HarnessAdapter;
package/dist/pi.js ADDED
@@ -0,0 +1,102 @@
1
+ import { mkdtempSync, readFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { exec, onPath } from "@skill-harness/core";
5
+ const PI_TIMEOUT_MS = Number(process.env.SKILL_CHECK_PI_TIMEOUT_MS ?? 300_000);
6
+ /** Skill-activation flags for a given run mode. */
7
+ function skillFlags(mode, skillDir) {
8
+ switch (mode) {
9
+ case "red":
10
+ return ["--no-skills"];
11
+ case "green":
12
+ return ["--skill", skillDir];
13
+ case "force": {
14
+ const body = readFileSync(join(skillDir, "SKILL.md"), "utf8");
15
+ return ["--no-skills", "--append-system-prompt", body];
16
+ }
17
+ }
18
+ }
19
+ function header(turnNo, total, text) {
20
+ const label = total === 1 ? "USER" : `USER (turn ${turnNo}/${total})`;
21
+ return `>>> ${label}:\n${text}\n`;
22
+ }
23
+ export const piAdapter = {
24
+ name: "pi",
25
+ available() {
26
+ return Promise.resolve(onPath("pi"));
27
+ },
28
+ /**
29
+ * Run a scenario through pi. Single turn → --no-session -p. Multi turn → a
30
+ * shared --session-dir, -c on every turn after the first. Returns a transcript
31
+ * interleaving user turns with assistant output.
32
+ */
33
+ async run(req) {
34
+ const common = [
35
+ "--no-context-files",
36
+ "--no-extensions",
37
+ "--provider",
38
+ req.model.provider,
39
+ "--model",
40
+ req.model.model,
41
+ ];
42
+ const flags = skillFlags(req.mode, req.skillDir);
43
+ const total = req.turns.length;
44
+ const parts = [];
45
+ if (total === 1) {
46
+ const args = [...flags, ...common, "--no-session", "-p", req.turns[0]];
47
+ const r = await exec("pi", args, { cwd: req.cwd, timeoutMs: PI_TIMEOUT_MS });
48
+ parts.push(header(1, 1, req.turns[0]));
49
+ parts.push(`<<< ASSISTANT:\n${r.stdout.trim()}\n`);
50
+ if (r.code !== 0)
51
+ parts.push(`[pi exited ${r.code}]\n${r.stderr.trim()}\n`);
52
+ return parts.join("\n");
53
+ }
54
+ const session = mkdtempSync(join(tmpdir(), "sc-pi-session-"));
55
+ for (let i = 0; i < total; i++) {
56
+ const turnFlags = i === 0 ? ["--session-dir", session] : ["--session-dir", session, "-c"];
57
+ const args = [...flags, ...common, ...turnFlags, "-p", req.turns[i]];
58
+ const r = await exec("pi", args, { cwd: req.cwd, timeoutMs: PI_TIMEOUT_MS });
59
+ parts.push(header(i + 1, total, req.turns[i]));
60
+ parts.push(`<<< ASSISTANT:\n${r.stdout.trim()}\n`);
61
+ if (r.code !== 0)
62
+ parts.push(`[pi exited ${r.code} on turn ${i + 1}]\n${r.stderr.trim()}\n`);
63
+ }
64
+ return parts.join("\n");
65
+ },
66
+ /**
67
+ * Run the judge: no skills, no context files, no session, single prompt.
68
+ * Judge provider `claude-code` routes to the Claude Code CLI (`claude -p`),
69
+ * which authenticates via the user's Claude subscription (OAuth) instead of
70
+ * a provider API key.
71
+ */
72
+ async judge(req) {
73
+ if (req.model.provider === "claude-code") {
74
+ const args = ["-p", req.prompt, "--model", req.model.model];
75
+ const r = await exec("claude", args, { cwd: req.cwd, timeoutMs: PI_TIMEOUT_MS });
76
+ if (r.stdout.trim().length === 0 && (r.code !== 0 || r.stderr.trim())) {
77
+ return `[judge error: claude exited ${r.code}] ${r.stderr.trim()}`;
78
+ }
79
+ return r.stdout;
80
+ }
81
+ const args = [
82
+ "--no-skills",
83
+ "--no-context-files",
84
+ "--no-extensions",
85
+ "--no-session",
86
+ "--provider",
87
+ req.model.provider,
88
+ "--model",
89
+ req.model.model,
90
+ "-p",
91
+ req.prompt,
92
+ ];
93
+ const r = await exec("pi", args, { cwd: req.cwd, timeoutMs: PI_TIMEOUT_MS });
94
+ // Surface failures: pi writes provider errors (auth, out-of-credits) to stderr
95
+ // and exits non-zero with empty stdout. Pass them through so grading can report.
96
+ if (r.stdout.trim().length === 0 && (r.code !== 0 || r.stderr.trim())) {
97
+ return `[judge error: pi exited ${r.code}] ${r.stderr.trim()}`;
98
+ }
99
+ return r.stdout;
100
+ },
101
+ };
102
+ //# sourceMappingURL=pi.js.map
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@skill-harness/adapters",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": { ".": "./dist/index.js" },
9
+ "files": ["dist/**/*.js", "dist/**/*.d.ts", "LICENSE"],
10
+ "repository": { "type": "git", "url": "git+https://github.com/mojomanyana/skill-harness.git" },
11
+ "publishConfig": { "access": "public" },
12
+ "engines": { "node": ">=20" },
13
+ "scripts": {
14
+ "prepack": "cp ../../LICENSE ./LICENSE"
15
+ },
16
+ "dependencies": { "@skill-harness/core": "0.1.0" }
17
+ }