skilld-harness 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -1
- package/dist/_chunks/skills.mjs +35 -18
- package/dist/_chunks/skills.mjs.map +1 -1
- package/dist/index.d.mts +56 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +285 -55
- package/dist/index.mjs.map +1 -1
- package/dist/sandbox-local.d.mts +33 -0
- package/dist/sandbox-local.d.mts.map +1 -0
- package/dist/sandbox-local.mjs +240 -0
- package/dist/sandbox-local.mjs.map +1 -0
- package/dist/skills/generate-package-skill/SKILL.md +110 -47
- package/dist/skills/generate-package-skill/assets/harness-request.md +3 -0
- package/dist/skills/generate-package-skill/scripts/serve-fixture.mjs +233 -0
- package/dist/skills/generate-project-skill/SKILL.md +21 -6
- package/dist/skills/review-skill/SKILL.md +4 -2
- package/dist/skills/skilld/SKILL.md +117 -2
- package/dist/skills.d.mts +8 -3
- package/dist/skills.d.mts.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import { createServer } from "node:net";
|
|
6
|
+
import { constants, tmpdir } from "node:os";
|
|
7
|
+
const inheritedVariables = [
|
|
8
|
+
"PATH",
|
|
9
|
+
"LANG",
|
|
10
|
+
"LC_ALL",
|
|
11
|
+
"LC_CTYPE",
|
|
12
|
+
"TZ",
|
|
13
|
+
"TERM",
|
|
14
|
+
"USER",
|
|
15
|
+
"LOGNAME",
|
|
16
|
+
"SHELL",
|
|
17
|
+
"HTTP_PROXY",
|
|
18
|
+
"HTTPS_PROXY",
|
|
19
|
+
"NO_PROXY",
|
|
20
|
+
"http_proxy",
|
|
21
|
+
"https_proxy",
|
|
22
|
+
"no_proxy",
|
|
23
|
+
"NODE_EXTRA_CA_CERTS",
|
|
24
|
+
"SSL_CERT_FILE",
|
|
25
|
+
"SSL_CERT_DIR"
|
|
26
|
+
];
|
|
27
|
+
function sessionDirectories(root) {
|
|
28
|
+
return {
|
|
29
|
+
home: join(root, ".home"),
|
|
30
|
+
tmp: join(root, ".tmp")
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function sessionEnvironment(directories, caller, extra) {
|
|
34
|
+
const { home, tmp } = directories;
|
|
35
|
+
return {
|
|
36
|
+
...Object.fromEntries(inheritedVariables.flatMap((name) => caller[name] === void 0 ? [] : [[name, caller[name]]])),
|
|
37
|
+
HOME: home,
|
|
38
|
+
XDG_CONFIG_HOME: join(home, ".config"),
|
|
39
|
+
XDG_DATA_HOME: join(home, ".local/share"),
|
|
40
|
+
XDG_CACHE_HOME: join(home, ".cache"),
|
|
41
|
+
XDG_STATE_HOME: join(home, ".local/state"),
|
|
42
|
+
TMPDIR: tmp,
|
|
43
|
+
...extra
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const { signals } = constants;
|
|
47
|
+
function killProcessGroup(pid) {
|
|
48
|
+
try {
|
|
49
|
+
process.kill(-pid, "SIGTERM");
|
|
50
|
+
} catch (cause) {
|
|
51
|
+
if (errorCode(cause) !== "ESRCH") throw cause;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function killChild(child) {
|
|
55
|
+
if (child.pid === void 0) return;
|
|
56
|
+
try {
|
|
57
|
+
killProcessGroup(child.pid);
|
|
58
|
+
} catch {
|
|
59
|
+
if (child.exitCode === null) child.kill("SIGTERM");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function errorCode(cause) {
|
|
63
|
+
return cause?.code;
|
|
64
|
+
}
|
|
65
|
+
async function freePort() {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
67
|
+
const server = createServer();
|
|
68
|
+
server.once("error", reject);
|
|
69
|
+
server.listen(0, "127.0.0.1", () => {
|
|
70
|
+
const address = server.address();
|
|
71
|
+
if (address === null || typeof address === "string") {
|
|
72
|
+
server.close(() => reject(/* @__PURE__ */ new Error("The operating system did not report a free port.")));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
server.close(() => resolve(address.port));
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async function readStream(stream) {
|
|
80
|
+
const reader = stream.getReader();
|
|
81
|
+
const chunks = [];
|
|
82
|
+
while (true) {
|
|
83
|
+
const result = await reader.read();
|
|
84
|
+
if (result.done) break;
|
|
85
|
+
chunks.push(result.value);
|
|
86
|
+
}
|
|
87
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
88
|
+
}
|
|
89
|
+
function watchAbort(child, abortSignal) {
|
|
90
|
+
return new Promise((_, reject) => {
|
|
91
|
+
const onAbort = () => {
|
|
92
|
+
killChild(child);
|
|
93
|
+
reject(abortSignal.reason ?? /* @__PURE__ */ new Error("The sandbox process was aborted."));
|
|
94
|
+
};
|
|
95
|
+
if (abortSignal.aborted) {
|
|
96
|
+
onAbort();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
100
|
+
child.once("close", () => abortSignal.removeEventListener("abort", onAbort));
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function startProcess(options, root, environment, processes) {
|
|
104
|
+
const child = spawn("/bin/sh", ["-c", options.command], {
|
|
105
|
+
cwd: options.workingDirectory ?? root,
|
|
106
|
+
env: {
|
|
107
|
+
...environment,
|
|
108
|
+
...options.env
|
|
109
|
+
},
|
|
110
|
+
detached: true
|
|
111
|
+
});
|
|
112
|
+
processes.live.add(child);
|
|
113
|
+
if (child.pid !== void 0) processes.groups.add(child.pid);
|
|
114
|
+
const exited = new Promise((resolve) => {
|
|
115
|
+
child.once("close", (code, signal) => {
|
|
116
|
+
processes.live.delete(child);
|
|
117
|
+
resolve({ exitCode: code ?? (signal === null ? 1 : 128 + (signals[signal] ?? 0)) });
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
const kill = async () => {
|
|
121
|
+
killChild(child);
|
|
122
|
+
await exited;
|
|
123
|
+
};
|
|
124
|
+
const aborted = options.abortSignal === void 0 ? void 0 : watchAbort(child, options.abortSignal);
|
|
125
|
+
aborted?.catch(() => {});
|
|
126
|
+
return {
|
|
127
|
+
exited,
|
|
128
|
+
handle: {
|
|
129
|
+
pid: child.pid,
|
|
130
|
+
stdout: Readable.toWeb(child.stdout),
|
|
131
|
+
stderr: Readable.toWeb(child.stderr),
|
|
132
|
+
wait: () => aborted === void 0 ? exited : Promise.race([exited, aborted]),
|
|
133
|
+
kill
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function createSandboxSession(root, environment, processes) {
|
|
138
|
+
const readBinaryFile = async ({ path }) => readFile(path).then((value) => Uint8Array.from(value), (cause) => errorCode(cause) === "ENOENT" ? null : Promise.reject(cause));
|
|
139
|
+
return {
|
|
140
|
+
description: `Local sandbox rooted at ${root}. POSIX sh, real processes, a session home directory, no process isolation.`,
|
|
141
|
+
readBinaryFile,
|
|
142
|
+
async readFile({ path }) {
|
|
143
|
+
const content = await readBinaryFile({ path });
|
|
144
|
+
if (content === null) return null;
|
|
145
|
+
return new ReadableStream({ start(controller) {
|
|
146
|
+
controller.enqueue(content);
|
|
147
|
+
controller.close();
|
|
148
|
+
} });
|
|
149
|
+
},
|
|
150
|
+
async readTextFile({ path, encoding = "utf8", startLine, endLine }) {
|
|
151
|
+
const content = await readFile(path, { encoding }).catch((cause) => errorCode(cause) === "ENOENT" ? null : Promise.reject(cause));
|
|
152
|
+
if (content === null || startLine === void 0 && endLine === void 0) return content;
|
|
153
|
+
const lines = content.split("\n");
|
|
154
|
+
return lines.slice((startLine ?? 1) - 1, endLine ?? lines.length).join("\n");
|
|
155
|
+
},
|
|
156
|
+
async writeFile({ path, content }) {
|
|
157
|
+
await mkdir(dirname(path), { recursive: true });
|
|
158
|
+
await writeFile(path, Buffer.from(await readStream(content), "utf8"));
|
|
159
|
+
},
|
|
160
|
+
async writeBinaryFile({ path, content }) {
|
|
161
|
+
await mkdir(dirname(path), { recursive: true });
|
|
162
|
+
await writeFile(path, content);
|
|
163
|
+
},
|
|
164
|
+
async writeTextFile({ path, content, encoding = "utf8" }) {
|
|
165
|
+
await mkdir(dirname(path), { recursive: true });
|
|
166
|
+
await writeFile(path, content, { encoding });
|
|
167
|
+
},
|
|
168
|
+
async spawn(options) {
|
|
169
|
+
return startProcess(options, root, environment, processes).handle;
|
|
170
|
+
},
|
|
171
|
+
async run(options) {
|
|
172
|
+
const { handle, exited } = startProcess(options, root, environment, processes);
|
|
173
|
+
const [stdout, stderr, exit] = await Promise.all([
|
|
174
|
+
readStream(handle.stdout),
|
|
175
|
+
readStream(handle.stderr),
|
|
176
|
+
exited
|
|
177
|
+
]);
|
|
178
|
+
return {
|
|
179
|
+
exitCode: exit.exitCode,
|
|
180
|
+
stdout,
|
|
181
|
+
stderr
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function createLocalSandbox(options = {}) {
|
|
187
|
+
return {
|
|
188
|
+
specificationVersion: "harness-sandbox-v1",
|
|
189
|
+
providerId: "skilld-local",
|
|
190
|
+
async createSession() {
|
|
191
|
+
const root = options.root ?? await mkdtemp(join(tmpdir(), "skilld-local-sandbox-"));
|
|
192
|
+
await mkdir(root, { recursive: true });
|
|
193
|
+
const directories = sessionDirectories(root);
|
|
194
|
+
await mkdir(directories.home, { recursive: true });
|
|
195
|
+
await mkdir(directories.tmp, { recursive: true });
|
|
196
|
+
const environment = sessionEnvironment(directories, process.env, options.env ?? {});
|
|
197
|
+
const processes = {
|
|
198
|
+
live: /* @__PURE__ */ new Set(),
|
|
199
|
+
groups: /* @__PURE__ */ new Set()
|
|
200
|
+
};
|
|
201
|
+
const session = createSandboxSession(root, environment, processes);
|
|
202
|
+
let ports = [options.port ?? await freePort()];
|
|
203
|
+
const stop = async () => {
|
|
204
|
+
for (const pid of processes.groups) killProcessGroup(pid);
|
|
205
|
+
processes.groups.clear();
|
|
206
|
+
processes.live.clear();
|
|
207
|
+
};
|
|
208
|
+
const endpoint = ({ port, protocol = "http" }) => ({ url: `${protocol}://127.0.0.1:${port}` });
|
|
209
|
+
return {
|
|
210
|
+
...session,
|
|
211
|
+
id: root,
|
|
212
|
+
defaultWorkingDirectory: root,
|
|
213
|
+
get ports() {
|
|
214
|
+
return ports;
|
|
215
|
+
},
|
|
216
|
+
async getPortEndpoint(request) {
|
|
217
|
+
return endpoint(request);
|
|
218
|
+
},
|
|
219
|
+
async getPortUrl(request) {
|
|
220
|
+
return endpoint(request).url;
|
|
221
|
+
},
|
|
222
|
+
async setPorts(next) {
|
|
223
|
+
ports = [...next];
|
|
224
|
+
},
|
|
225
|
+
stop,
|
|
226
|
+
async destroy() {
|
|
227
|
+
await stop();
|
|
228
|
+
if (options.keepRoot !== true) await rm(root, {
|
|
229
|
+
recursive: true,
|
|
230
|
+
force: true
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
restricted: () => session
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
export { createLocalSandbox };
|
|
239
|
+
|
|
240
|
+
//# sourceMappingURL=sandbox-local.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-local.mjs","names":["spawnChildProcess"],"sources":["../src/sandbox-local.ts"],"sourcesContent":["import type { HarnessV1NetworkSandboxSession, HarnessV1PortEndpoint, HarnessV1SandboxProvider } from '@ai-sdk/harness'\nimport type { ChildProcessWithoutNullStreams } from 'node:child_process'\nimport { spawn as spawnChildProcess } from 'node:child_process'\nimport { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'\nimport { createServer } from 'node:net'\nimport { constants, tmpdir } from 'node:os'\nimport { dirname, join } from 'node:path'\nimport { Readable } from 'node:stream'\n\n/**\n * The local sandbox runs real processes on this computer.\n * It gives each session its own home directory and a minimal environment.\n * It is not a security boundary: every process can still read the whole computer.\n * Use a hosted sandbox provider when the Harness must contain what it runs.\n */\nexport interface CreateLocalSandboxOptions {\n /** Session root directory. The default is a new temporary directory. */\n readonly root?: string\n /** Bridge port. The default asks the operating system for a free port. */\n readonly port?: number\n /** Keep the session root after `destroy`. The default removes it. */\n readonly keepRoot?: boolean\n /**\n * More environment variables for every process in the session, such as a\n * registry URL or proxy settings. Harness adapters pass their own credentials,\n * so the session does not need the caller's API keys.\n */\n readonly env?: Readonly<Record<string, string>>\n}\n\n/**\n * Variables the session copies from the caller. Everything else stays out, so\n * that a process cannot read the caller's secrets or agent configuration.\n */\nconst inheritedVariables = [\n 'PATH',\n 'LANG',\n 'LC_ALL',\n 'LC_CTYPE',\n 'TZ',\n 'TERM',\n 'USER',\n 'LOGNAME',\n 'SHELL',\n 'HTTP_PROXY',\n 'HTTPS_PROXY',\n 'NO_PROXY',\n 'http_proxy',\n 'https_proxy',\n 'no_proxy',\n 'NODE_EXTRA_CA_CERTS',\n 'SSL_CERT_FILE',\n 'SSL_CERT_DIR',\n] as const\n\ninterface SessionDirectories {\n /** HOME for every process. Harness state and installed Skills land here. */\n readonly home: string\n /** TMPDIR for every process. */\n readonly tmp: string\n}\n\nfunction sessionDirectories(root: string): SessionDirectories {\n return { home: join(root, '.home'), tmp: join(root, '.tmp') }\n}\n\n/**\n * The environment every process in a session starts from.\n * Home, XDG, and temporary directories point inside the session root, so that\n * Harness state, installed Skills, and agent configuration never reach the\n * caller's home directory, and `destroy` removes all of them.\n */\nfunction sessionEnvironment(\n directories: SessionDirectories,\n caller: NodeJS.ProcessEnv,\n extra: Readonly<Record<string, string>>,\n): Record<string, string> {\n const { home, tmp } = directories\n const inherited = Object.fromEntries(\n inheritedVariables.flatMap(name => caller[name] === undefined ? [] : [[name, caller[name]]]),\n )\n return {\n ...inherited,\n HOME: home,\n XDG_CONFIG_HOME: join(home, '.config'),\n XDG_DATA_HOME: join(home, '.local/share'),\n XDG_CACHE_HOME: join(home, '.cache'),\n XDG_STATE_HOME: join(home, '.local/state'),\n TMPDIR: tmp,\n ...extra,\n }\n}\n\n/** The file and process surface the Harness hands to Skill code. */\ntype SandboxSession = ReturnType<HarnessV1NetworkSandboxSession['restricted']>\ntype SandboxProcessOptions = Parameters<SandboxSession['run']>[0]\ntype SandboxProcess = Awaited<ReturnType<SandboxSession['spawn']>>\n\nconst { signals } = constants\n\n/** The processes one session started, so that `stop` can reach all of them. */\ninterface SessionProcesses {\n /** Processes that have not closed yet. */\n readonly live: Set<ChildProcessWithoutNullStreams>\n /**\n * Group identifiers, kept after the leader exits. A command like\n * `agent &` leaves the shell dead and the agent alive in the same group.\n */\n readonly groups: Set<number>\n}\n\n/**\n * Terminate every process in a group.\n * A detached child leads a process group that shares its identifier.\n * The kernel holds the identifier while the group has a member, so it stays\n * ours to signal even after the leader exits.\n */\nfunction killProcessGroup(pid: number): void {\n try {\n process.kill(-pid, 'SIGTERM')\n }\n catch (cause) {\n // ESRCH means the group already exited. Anything else is unexpected.\n if (errorCode(cause) !== 'ESRCH')\n throw cause\n }\n}\n\n/** Terminate a child's group, and the child alone if it leads no group. */\nfunction killChild(child: ChildProcessWithoutNullStreams): void {\n if (child.pid === undefined)\n return\n try {\n killProcessGroup(child.pid)\n }\n catch {\n if (child.exitCode === null)\n child.kill('SIGTERM')\n }\n}\n\nfunction errorCode(cause: unknown): string | undefined {\n return (cause as NodeJS.ErrnoException | undefined)?.code\n}\n\nasync function freePort(): Promise<number> {\n return new Promise((resolve, reject) => {\n const server = createServer()\n server.once('error', reject)\n server.listen(0, '127.0.0.1', () => {\n const address = server.address()\n if (address === null || typeof address === 'string') {\n server.close(() => reject(new Error('The operating system did not report a free port.')))\n return\n }\n server.close(() => resolve(address.port))\n })\n })\n}\n\nasync function readStream(stream: ReadableStream<Uint8Array>): Promise<string> {\n const reader = stream.getReader()\n const chunks: Uint8Array[] = []\n while (true) {\n const result = await reader.read()\n if (result.done)\n break\n chunks.push(result.value)\n }\n return Buffer.concat(chunks).toString('utf8')\n}\n\ninterface StartedProcess {\n readonly handle: SandboxProcess\n /** Resolves with the exit code even when the caller aborted the process. */\n readonly exited: Promise<{ exitCode: number }>\n}\n\n/**\n * Kill the process when the caller aborts, and reject the returned promise.\n * The listener is removed on close so that a shared signal does not collect\n * one listener for every process the session runs.\n */\nfunction watchAbort(child: ChildProcessWithoutNullStreams, abortSignal: AbortSignal): Promise<never> {\n return new Promise<never>((_, reject) => {\n const onAbort = (): void => {\n killChild(child)\n reject(abortSignal.reason ?? new Error('The sandbox process was aborted.'))\n }\n if (abortSignal.aborted) {\n onAbort()\n return\n }\n abortSignal.addEventListener('abort', onAbort, { once: true })\n child.once('close', () => abortSignal.removeEventListener('abort', onAbort))\n })\n}\n\nfunction startProcess(\n options: SandboxProcessOptions,\n root: string,\n environment: Readonly<Record<string, string>>,\n processes: SessionProcesses,\n): StartedProcess {\n // The process leads its own group so that killing it also kills what it\n // started. The OpenCode bridge starts OpenCode, which starts more processes.\n const child = spawnChildProcess('/bin/sh', ['-c', options.command], {\n cwd: options.workingDirectory ?? root,\n env: { ...environment, ...options.env },\n detached: true,\n })\n processes.live.add(child)\n if (child.pid !== undefined)\n processes.groups.add(child.pid)\n\n const exited = new Promise<{ exitCode: number }>((resolve) => {\n child.once('close', (code, signal) => {\n processes.live.delete(child)\n resolve({ exitCode: code ?? (signal === null ? 1 : 128 + (signals[signal] ?? 0)) })\n })\n })\n\n const kill = async (): Promise<void> => {\n killChild(child)\n await exited\n }\n\n const aborted = options.abortSignal === undefined\n ? undefined\n : watchAbort(child, options.abortSignal)\n // The abort rejection is reported through `wait`. Nothing else observes it.\n aborted?.catch(() => {})\n\n return {\n exited,\n handle: {\n pid: child.pid,\n stdout: Readable.toWeb(child.stdout) as ReadableStream<Uint8Array>,\n stderr: Readable.toWeb(child.stderr) as ReadableStream<Uint8Array>,\n wait: () => aborted === undefined ? exited : Promise.race([exited, aborted]),\n kill,\n },\n }\n}\n\nfunction createSandboxSession(root: string, environment: Readonly<Record<string, string>>, processes: SessionProcesses): SandboxSession {\n const readBinaryFile = async ({ path }: { path: string }): Promise<Uint8Array | null> =>\n readFile(path).then(\n value => Uint8Array.from(value),\n cause => errorCode(cause) === 'ENOENT' ? null : Promise.reject(cause),\n )\n\n return {\n description: `Local sandbox rooted at ${root}. POSIX sh, real processes, a session home directory, no process isolation.`,\n readBinaryFile,\n\n async readFile({ path }) {\n const content = await readBinaryFile({ path })\n if (content === null)\n return null\n return new ReadableStream<Uint8Array>({\n start(controller) {\n controller.enqueue(content)\n controller.close()\n },\n })\n },\n\n async readTextFile({ path, encoding = 'utf8', startLine, endLine }) {\n const content = await readFile(path, { encoding: encoding as BufferEncoding })\n .catch(cause => errorCode(cause) === 'ENOENT' ? null : Promise.reject(cause))\n if (content === null || (startLine === undefined && endLine === undefined))\n return content\n const lines = content.split('\\n')\n return lines.slice((startLine ?? 1) - 1, endLine ?? lines.length).join('\\n')\n },\n\n async writeFile({ path, content }) {\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, Buffer.from(await readStream(content), 'utf8'))\n },\n\n async writeBinaryFile({ path, content }) {\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, content)\n },\n\n async writeTextFile({ path, content, encoding = 'utf8' }) {\n await mkdir(dirname(path), { recursive: true })\n await writeFile(path, content, { encoding: encoding as BufferEncoding })\n },\n\n async spawn(options) {\n return startProcess(options, root, environment, processes).handle\n },\n\n async run(options) {\n // An aborted `run` reports the exit code of the killed process.\n // Only `spawn` rejects its wait, because its caller holds the handle.\n const { handle, exited } = startProcess(options, root, environment, processes)\n const [stdout, stderr, exit] = await Promise.all([\n readStream(handle.stdout),\n readStream(handle.stderr),\n exited,\n ])\n return { exitCode: exit.exitCode, stdout, stderr }\n },\n }\n}\n\n/**\n * Create a sandbox provider that runs Harness sessions on this computer.\n *\n * The session needs POSIX `sh` at `/bin/sh` and GNU `find`, because the Harness\n * inventories output with `find -printf`. It runs on Linux, and not on macOS or\n * Windows. It exposes one port on `127.0.0.1` for bridge-backed Harness\n * adapters. Each session gets its own home directory under the session root and\n * a minimal environment, and `destroy` removes both. It applies no process\n * isolation: every process can still read and write the whole computer.\n */\nexport function createLocalSandbox(options: CreateLocalSandboxOptions = {}): HarnessV1SandboxProvider {\n return {\n specificationVersion: 'harness-sandbox-v1',\n providerId: 'skilld-local',\n\n async createSession(): Promise<HarnessV1NetworkSandboxSession> {\n const root = options.root ?? await mkdtemp(join(tmpdir(), 'skilld-local-sandbox-'))\n await mkdir(root, { recursive: true })\n const directories = sessionDirectories(root)\n await mkdir(directories.home, { recursive: true })\n await mkdir(directories.tmp, { recursive: true })\n const environment = sessionEnvironment(directories, process.env, options.env ?? {})\n const processes: SessionProcesses = { live: new Set(), groups: new Set() }\n const session = createSandboxSession(root, environment, processes)\n let ports: ReadonlyArray<number> = [options.port ?? await freePort()]\n\n const stop = async (): Promise<void> => {\n // Groups, not live children: a backgrounded process outlives its shell.\n for (const pid of processes.groups)\n killProcessGroup(pid)\n processes.groups.clear()\n processes.live.clear()\n }\n\n const endpoint = ({ port, protocol = 'http' }: { port: number, protocol?: 'http' | 'https' | 'ws' }): HarnessV1PortEndpoint =>\n ({ url: `${protocol}://127.0.0.1:${port}` })\n\n return {\n ...session,\n id: root,\n defaultWorkingDirectory: root,\n get ports() {\n return ports\n },\n async getPortEndpoint(request) {\n return endpoint(request)\n },\n async getPortUrl(request) {\n return endpoint(request).url\n },\n async setPorts(next) {\n ports = [...next]\n },\n stop,\n async destroy() {\n await stop()\n if (options.keepRoot !== true)\n await rm(root, { recursive: true, force: true })\n },\n restricted: () => session,\n }\n },\n }\n}\n"],"mappings":";;;;;;;;;CAkCA;CACE;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACA;AACA,SAAA,mBAAA,MAAA;CACA,OAAA;EACF,MAAA,KAAA,MAAA,OAAA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,OAAM;IACN,UAAM,KAAU;IAClB;IAEA;GACE;EACA;CACF;AAEA;AAEA,SAAA,mBAAA,UAAA,CAAA,GAAA;CAEA,OAAM;EAGJ,sBAAgB;EAChB,YAAO;EACL,MAAA,gBAAkB;GAClB,MAAA,OAAW,QAAO,QAAM,MAAA,QAAA,KAAA,OAAA,GAAA,uBAAA,CAAA;GACxB,MAAA,MAAA,MAAA,EAAA,WAAA,KAAA,CAAA;GACF,MAAC,cAAA,mBAAA,IAAA;GACD,MAAA,MAAO,YAAA,MAAA,EAAA,WAAA,KAAA,CAAA;GAAE,MAAA,MAAU,YAAK,KAAA,EAAA,WAAA,KAAA,CAAA;GAAU,MAAA,cAAA,mBAAA,aAAA,QAAA,KAAA,QAAA,OAAA,CAAA,CAAA;GAAQ,MAAA,YAAA;IAAO,sBAAA,IAAA,IAAA;IACnD,wBAAA,IAAA,IAAA;GACF;GACF,MAAA,UAAA,qBAAA,MAAA,aAAA,SAAA;;;;;;;;;;;IAYA,yBAAmC;IACjC,IAAO,QAAA;KACL,OAAA;IACA;IAEA,MAAM,gBAAyD,SAAA;KAC7D,OAAM,SAAO,OAAQ;IACrB;IACA,MAAM,WAAA,SAAc;KACpB,OAAM,SAAM,OAAY,CAAA,CAAA;IACxB;IACA,MAAM,SAAA,MAAc;KACpB,QAAM,CAAA,GAAA,IAA8B;IAAE;IAAiB;IAAkB,MAAA,UAAA;KACzE,MAAM,KAAA;KACN,IAAI,QAAgC,aAAQ,MAAQ,MAAM,GAAA,MAAU;MAEpE,WAAa;MAEX,OAAK;KAEL,CAAA;IACA;IACF,kBAAA;GAEA;EAGA;CACE;AACA;AAEA,SAAI"}
|
|
@@ -1,65 +1,128 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: generate-package-skill
|
|
3
|
-
description: Generate or update an Agent Skill
|
|
3
|
+
description: Generate or update an Agent Skill that teaches consumers one npm or local package the user maintains, including framework modules and wrappers. Tests each example against the installed version. Use when a maintainer asks for a package Skill, a SKILL.md for their library, or a Skill update after a release.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Generate a package Skill
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
Write a short Skill that stops an Agent from misusing one package version.
|
|
9
|
+
The reader knows the language, the framework, and the domain. Write only what it would get wrong.
|
|
10
10
|
|
|
11
11
|
## Inputs
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
Take a package name, directory, or prepared source. Ask for the destination only when it is missing.
|
|
14
|
+
In a monorepo, put the Skill in the published package directory.
|
|
15
|
+
Write one Skill per installed package, unless a second package has distinct users.
|
|
16
|
+
`assets/` holds the Harness request. A direct run ignores it.
|
|
15
17
|
|
|
16
|
-
## Research
|
|
18
|
+
## 1. Research
|
|
17
19
|
|
|
18
|
-
1. Record the exact
|
|
19
|
-
2. Read the
|
|
20
|
-
3.
|
|
21
|
-
4.
|
|
22
|
-
5.
|
|
23
|
-
6. Prefer public exports over internal files.
|
|
24
|
-
7. Record advice only when the prepared source or official documentation proves it.
|
|
20
|
+
1. Record the exact package version.
|
|
21
|
+
2. Read the manifest, every exported entry point, and the public types.
|
|
22
|
+
3. For a framework module, read what setup registers: auto-imports, components, the config key and defaults, hooks, server routes.
|
|
23
|
+
4. If the package wraps, re-exports, or peers on another package, read the types or tagged source of the version the consumer gets, never a default branch.
|
|
24
|
+
5. Read the current official docs and examples, and release notes only for breaking changes and removed APIs.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
Use current official documentation when the prepared source lacks required details.
|
|
28
|
-
For each version-specific rule, cite the source path or official documentation URL.
|
|
29
|
-
Use `path:line` citations for prepared source when line numbers add value.
|
|
26
|
+
Test an existing Skill's claims; do not copy its layout.
|
|
30
27
|
|
|
31
|
-
##
|
|
28
|
+
## 2. Test the examples
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
The directory must contain `SKILL.md`.
|
|
35
|
-
Put detailed or conditional material in `references/`.
|
|
36
|
-
Put reusable commands or code in `scripts/` when execution adds value.
|
|
30
|
+
Observed behaviour beats documentation.
|
|
37
31
|
|
|
38
|
-
|
|
32
|
+
1. Create a minimal consumer fixture outside the package source. Install the recorded version, or link the local build.
|
|
33
|
+
Before packing, build the package and its native code (NAPI, WASM); `prepack` can need them.
|
|
34
|
+
Pack with the repository's package manager: `npm pack` leaves pnpm `catalog:` versions.
|
|
35
|
+
Install only the package and documented peers. A resolution error is a finding.
|
|
36
|
+
2. Use consumer defaults. The package repository's config and fixtures can turn them off.
|
|
37
|
+
In Nuxt, keep test modules out of `modules/`; Nuxt registers every module there.
|
|
38
|
+
One fixture page can exercise many examples.
|
|
39
|
+
3. Run each example you include. Compare output with the claim: HTML, return values, type errors, build logs, exit codes, report files.
|
|
40
|
+
Test each mode: framework modes, export conditions (`node`, `workerd`, `edge-light`, `browser`, CDN or IIFE build), and each CLI binary with a config file and with flags.
|
|
41
|
+
Wrap every run in `timeout 120`.
|
|
42
|
+
Grep the package for agent and CI detection, such as `CLAUDECODE` or `CI`; unset each variable it reads with `env -u VAR`.
|
|
43
|
+
Read dev warnings in the dev log, prerender results in build output, and runtime results from the production server.
|
|
44
|
+
If a trap says nothing happens, run it and confirm the silence.
|
|
45
|
+
To fetch from a server, run [scripts/serve-fixture.mjs](scripts/serve-fixture.mjs) in the fixture: `node SKILL_DIR/scripts/serve-fixture.mjs --fetch / -- node .output/server/index.mjs`.
|
|
46
|
+
For a binary, use `--fetch-raw PATH --out DIR`. `DIR/responses.json` lists each status and content type.
|
|
47
|
+
Without `--fetch`, it holds the server until SIGTERM. Background it with your tool's option; `&` and `nohup` die with the shell call.
|
|
48
|
+
Never kill by port or with `pkill -f`: another Agent can own that process.
|
|
49
|
+
In a browser, set a desktop user agent; a package can treat `HeadlessChrome` as a bot.
|
|
50
|
+
4. If documentation and behaviour disagree, write the behaviour and report the mismatch.
|
|
51
|
+
5. Keep an unrunnable example only when the types prove it; report it untested.
|
|
39
52
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
53
|
+
Do not fix the package or its docs in the Skill change.
|
|
54
|
+
|
|
55
|
+
## 3. Write
|
|
56
|
+
|
|
57
|
+
Include:
|
|
58
|
+
|
|
59
|
+
- Setup that differs from the framework default, such as a required config key.
|
|
60
|
+
- What the package does automatically, and how to turn it off.
|
|
61
|
+
- Traps: silent failures, plausible wrong calls, documentation mismatches, version limits.
|
|
62
|
+
- One small example per common task the types do not make obvious.
|
|
63
|
+
- Breaking changes an Agent trained on an older version would repeat: old call, new call.
|
|
64
|
+
- A deploy section, such as CI cache or Cloudflare, when most traps live there.
|
|
65
|
+
|
|
66
|
+
Cut:
|
|
67
|
+
|
|
68
|
+
- Self-explanatory config options; link the config reference. Keep a table when values are the API, such as priorities.
|
|
69
|
+
- Internals the consumer cannot act on, such as tree shaking.
|
|
70
|
+
- Changelog paraphrase, fixed bugs, release history.
|
|
71
|
+
- Generic debug advice, such as "view source" or public validators.
|
|
72
|
+
- `path:line` citations. Put evidence in the report.
|
|
73
|
+
- Any second copy of content, such as a list repeating inline reference links.
|
|
74
|
+
|
|
75
|
+
Shape:
|
|
76
|
+
|
|
77
|
+
- Name the package and tested version in the first paragraph, not the frontmatter.
|
|
78
|
+
- Order, dropping empty sections: setup, automatic behaviour, common tasks, integrations, traps, version limits, config, debug.
|
|
79
|
+
- A config example that is a common task goes there; the config section only lists options.
|
|
80
|
+
- Write each code block as a complete module with imports. ESLint can lint fenced code.
|
|
81
|
+
- A trap detailed in a reference gets one linking line in traps.
|
|
82
|
+
- Aim for 150 lines and about 2,000 tokens in `SKILL.md`. Never exceed 500 lines.
|
|
83
|
+
- Keep one file. Move a topic to `references/<topic>.md` only past about 40 lines and when under a third of tasks need it.
|
|
84
|
+
- Link each reference from `SKILL.md`, one level deep. A reference over 100 lines starts with contents.
|
|
85
|
+
- Write at most eight reference files. Add `scripts/` only when running code beats reading it.
|
|
86
|
+
- Never include credentials, caches, build output, or dependency directories.
|
|
87
|
+
|
|
88
|
+
The frontmatter contains only `name` and `description`.
|
|
89
|
+
The name uses lowercase letters, numbers, and single hyphens, at most 64 characters, and matches the directory.
|
|
90
|
+
For a scoped package, drop the `@` and replace `/` with a hyphen: `@nuxtjs/seo` becomes `nuxtjs-seo`.
|
|
91
|
+
The description, at most 1024 characters in third person, says what the Skill does, then when to use it, in the words a user types: package name, main exports, config key, error symptoms.
|
|
92
|
+
Good: `Add and debug Schema.org JSON-LD in Nuxt with nuxt-schema-org. Use when a task mentions structured data, rich results, useSchemaOrg, defineArticle, or the schemaOrg config key.`
|
|
93
|
+
|
|
94
|
+
## 4. Check and report
|
|
95
|
+
|
|
96
|
+
Before finishing, confirm:
|
|
97
|
+
|
|
98
|
+
- Each example ran against the recorded version, or is reported untested.
|
|
99
|
+
- Each reference is linked. Delete stale files from an earlier Skill.
|
|
100
|
+
- The frontmatter follows the rules above.
|
|
101
|
+
|
|
102
|
+
Report to the user:
|
|
103
|
+
|
|
104
|
+
- The files and the tested version.
|
|
105
|
+
- Each untested example, and each mismatch: example, documented result, observed result. These are package bugs.
|
|
106
|
+
- The source path or documentation URL behind each version-specific rule.
|
|
107
|
+
- If the package ships the Skill, add its directory to `files` in `package.json`. After one build, list packed files with `npm pack --dry-run --ignore-scripts`; `pnpm pack` rejects that flag.
|
|
108
|
+
- Replace any README or docs `skilld add <package>` tip in place with the tip below. Add the badge after the others.
|
|
109
|
+
Replace `OWNER`, `REPOSITORY`, and `PACKAGE`. If the Repository has several Skills, add `/SKILL` to the page and badge paths. The skilld.dev indexer skips `SKILL.md` under test and fixture folders. The README omits the run command; the page shows it.
|
|
110
|
+
|
|
111
|
+
```html
|
|
112
|
+
<a href="https://skilld.dev/gh/OWNER/REPOSITORY">
|
|
113
|
+
<picture>
|
|
114
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://skilld.dev/b/OWNER/REPOSITORY?theme=dark">
|
|
115
|
+
<source media="(prefers-color-scheme: light)" srcset="https://skilld.dev/b/OWNER/REPOSITORY?theme=light">
|
|
116
|
+
<img alt="Skill repository on skilld.dev" src="https://skilld.dev/b/OWNER/REPOSITORY?theme=light">
|
|
117
|
+
</picture>
|
|
118
|
+
</a>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```md
|
|
122
|
+
> [!TIP]
|
|
123
|
+
> Using an AI agent? Get the PACKAGE Skill on [skilld.dev/gh/OWNER/REPOSITORY](https://skilld.dev/gh/OWNER/REPOSITORY).
|
|
45
124
|
```
|
|
46
125
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
## Quality checks
|
|
52
|
-
|
|
53
|
-
- Keep instructions specific to the package.
|
|
54
|
-
- Use current APIs and package vocabulary.
|
|
55
|
-
- Include small examples for common tasks.
|
|
56
|
-
- State environment or version limits.
|
|
57
|
-
- Cite public APIs, version limits, and migration advice.
|
|
58
|
-
- Link each reference from `SKILL.md`.
|
|
59
|
-
- Remove generated filler and repeated prose.
|
|
60
|
-
- Do not copy large documentation sections.
|
|
61
|
-
- Do not include credentials, caches, build output, or dependency directories.
|
|
62
|
-
|
|
63
|
-
For a direct run, show the generated files for user review.
|
|
64
|
-
Replace an existing Skill only after the user approves the files.
|
|
65
|
-
Do not claim that the Skill passed Harness checks.
|
|
126
|
+
For a direct run, show the files for review, or open a pull request if asked.
|
|
127
|
+
Replace an existing Skill only with user approval.
|
|
128
|
+
A direct run has no Harness checks; never claim it passed them.
|
|
@@ -7,5 +7,8 @@ The Skill directory name must be `{{SKILL_NAME}}`.
|
|
|
7
7
|
|
|
8
8
|
Read this Skill fully before writing files.
|
|
9
9
|
Use only the visible prepared source and cited official documentation.
|
|
10
|
+
Pin external documentation to the dependency versions in the prepared manifest.
|
|
11
|
+
If the session cannot run an example, list it as untested in your final message.
|
|
12
|
+
List each documentation and behaviour mismatch in your final message.
|
|
10
13
|
Write no files outside `{{OUTPUT_PATH}}`.
|
|
11
14
|
Finish only after checking every output rule in this Skill.
|