@wrongstack/tools 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit.d.ts +25 -0
- package/dist/audit.js +209 -0
- package/dist/audit.js.map +1 -0
- package/dist/bash.d.ts +16 -0
- package/dist/bash.js +180 -0
- package/dist/bash.js.map +1 -0
- package/dist/batch-tool-use.d.ts +26 -0
- package/dist/batch-tool-use.js +106 -0
- package/dist/batch-tool-use.js.map +1 -0
- package/dist/builtin.d.ts +5 -0
- package/dist/builtin.js +3735 -0
- package/dist/builtin.js.map +1 -0
- package/dist/diff.d.ts +20 -0
- package/dist/diff.js +142 -0
- package/dist/diff.js.map +1 -0
- package/dist/document.d.ts +27 -0
- package/dist/document.js +148 -0
- package/dist/document.js.map +1 -0
- package/dist/edit.d.ts +22 -0
- package/dist/edit.js +138 -0
- package/dist/edit.js.map +1 -0
- package/dist/exec.d.ts +21 -0
- package/dist/exec.js +159 -0
- package/dist/exec.js.map +1 -0
- package/dist/fetch.d.ts +15 -0
- package/dist/fetch.js +213 -0
- package/dist/fetch.js.map +1 -0
- package/dist/format.d.ts +18 -0
- package/dist/format.js +194 -0
- package/dist/format.js.map +1 -0
- package/dist/git.d.ts +27 -0
- package/dist/git.js +174 -0
- package/dist/git.js.map +1 -0
- package/dist/glob.d.ts +14 -0
- package/dist/glob.js +101 -0
- package/dist/glob.js.map +1 -0
- package/dist/grep.d.ts +20 -0
- package/dist/grep.js +264 -0
- package/dist/grep.js.map +1 -0
- package/dist/index.d.ts +34 -563
- package/dist/index.js +717 -442
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +19 -0
- package/dist/install.js +186 -0
- package/dist/install.js.map +1 -0
- package/dist/json.d.ts +20 -0
- package/dist/json.js +124 -0
- package/dist/json.js.map +1 -0
- package/dist/lint.d.ts +20 -0
- package/dist/lint.js +191 -0
- package/dist/lint.js.map +1 -0
- package/dist/logs.d.ts +27 -0
- package/dist/logs.js +180 -0
- package/dist/logs.js.map +1 -0
- package/dist/memory.d.ts +22 -0
- package/dist/memory.js +53 -0
- package/dist/memory.js.map +1 -0
- package/dist/mode.d.ts +20 -0
- package/dist/mode.js +81 -0
- package/dist/mode.js.map +1 -0
- package/dist/outdated.d.ts +26 -0
- package/dist/outdated.js +138 -0
- package/dist/outdated.js.map +1 -0
- package/dist/patch.d.ts +18 -0
- package/dist/patch.js +101 -0
- package/dist/patch.js.map +1 -0
- package/dist/read.d.ts +16 -0
- package/dist/read.js +81 -0
- package/dist/read.js.map +1 -0
- package/dist/replace.d.ts +23 -0
- package/dist/replace.js +196 -0
- package/dist/replace.js.map +1 -0
- package/dist/scaffold.d.ts +20 -0
- package/dist/scaffold.js +185 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/search.d.ts +20 -0
- package/dist/search.js +212 -0
- package/dist/search.js.map +1 -0
- package/dist/test.d.ts +24 -0
- package/dist/test.js +247 -0
- package/dist/test.js.map +1 -0
- package/dist/todo.d.ts +12 -0
- package/dist/todo.js +53 -0
- package/dist/todo.js.map +1 -0
- package/dist/tool-help.d.ts +23 -0
- package/dist/tool-help.js +122 -0
- package/dist/tool-help.js.map +1 -0
- package/dist/tool-search.d.ts +22 -0
- package/dist/tool-search.js +70 -0
- package/dist/tool-search.js.map +1 -0
- package/dist/tool-use.d.ts +16 -0
- package/dist/tool-use.js +79 -0
- package/dist/tool-use.js.map +1 -0
- package/dist/tree.d.ts +21 -0
- package/dist/tree.js +176 -0
- package/dist/tree.js.map +1 -0
- package/dist/typecheck.d.ts +19 -0
- package/dist/typecheck.js +181 -0
- package/dist/typecheck.js.map +1 -0
- package/dist/write.d.ts +15 -0
- package/dist/write.js +77 -0
- package/dist/write.js.map +1 -0
- package/package.json +137 -4
package/dist/test.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
|
|
4
|
+
// src/test.ts
|
|
5
|
+
function resolvePath(input, ctx) {
|
|
6
|
+
return path.isAbsolute(input) ? path.normalize(input) : path.resolve(ctx.cwd, input);
|
|
7
|
+
}
|
|
8
|
+
function ensureInsideRoot(absPath, ctx) {
|
|
9
|
+
const root = path.resolve(ctx.projectRoot);
|
|
10
|
+
const target = path.resolve(absPath);
|
|
11
|
+
const rel = path.relative(root, target);
|
|
12
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
13
|
+
throw new Error(`Path "${absPath}" is outside project root "${root}"`);
|
|
14
|
+
}
|
|
15
|
+
return target;
|
|
16
|
+
}
|
|
17
|
+
function safeResolve(input, ctx) {
|
|
18
|
+
return ensureInsideRoot(resolvePath(input, ctx), ctx);
|
|
19
|
+
}
|
|
20
|
+
async function* spawnStream(opts) {
|
|
21
|
+
const max = opts.maxBytes;
|
|
22
|
+
const flushAt = opts.flushBytes ?? 4 * 1024;
|
|
23
|
+
let stdout = "";
|
|
24
|
+
let stderr = "";
|
|
25
|
+
let pending = "";
|
|
26
|
+
let error;
|
|
27
|
+
const child = spawn(opts.cmd, opts.args, {
|
|
28
|
+
cwd: opts.cwd,
|
|
29
|
+
signal: opts.signal,
|
|
30
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
31
|
+
});
|
|
32
|
+
const queue = [];
|
|
33
|
+
let waiter;
|
|
34
|
+
const wake = () => {
|
|
35
|
+
if (waiter) {
|
|
36
|
+
const w = waiter;
|
|
37
|
+
waiter = void 0;
|
|
38
|
+
w();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
child.stdout?.on("data", (c) => {
|
|
42
|
+
const s = c.toString();
|
|
43
|
+
if (stdout.length < max) stdout += s;
|
|
44
|
+
queue.push({ kind: "out", data: s });
|
|
45
|
+
wake();
|
|
46
|
+
});
|
|
47
|
+
child.stderr?.on("data", (c) => {
|
|
48
|
+
const s = c.toString();
|
|
49
|
+
if (stderr.length < max) stderr += s;
|
|
50
|
+
queue.push({ kind: "err", data: s });
|
|
51
|
+
wake();
|
|
52
|
+
});
|
|
53
|
+
child.on("error", (e) => {
|
|
54
|
+
error = e.message;
|
|
55
|
+
queue.push({ kind: "error", data: e.message });
|
|
56
|
+
wake();
|
|
57
|
+
});
|
|
58
|
+
child.on("close", (code) => {
|
|
59
|
+
queue.push({ kind: "close", data: "", code: code ?? 0 });
|
|
60
|
+
wake();
|
|
61
|
+
});
|
|
62
|
+
let exitCode = 0;
|
|
63
|
+
let spawnFailed = false;
|
|
64
|
+
for (; ; ) {
|
|
65
|
+
while (queue.length === 0) {
|
|
66
|
+
await new Promise((resolve2) => {
|
|
67
|
+
waiter = resolve2;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const chunk = queue.shift();
|
|
71
|
+
if (chunk.kind === "close") {
|
|
72
|
+
if (!spawnFailed) exitCode = chunk.code ?? 0;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
if (chunk.kind === "error") {
|
|
76
|
+
spawnFailed = true;
|
|
77
|
+
exitCode = 1;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
pending += chunk.data;
|
|
81
|
+
if (pending.length >= flushAt) {
|
|
82
|
+
yield { type: "partial_output", text: pending };
|
|
83
|
+
pending = "";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (pending.length > 0) {
|
|
87
|
+
yield { type: "partial_output", text: pending };
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
stdout,
|
|
91
|
+
stderr,
|
|
92
|
+
exitCode,
|
|
93
|
+
truncated: stdout.length >= max || stderr.length >= max,
|
|
94
|
+
error
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/test.ts
|
|
99
|
+
var testTool = {
|
|
100
|
+
name: "test",
|
|
101
|
+
description: "Run tests with vitest, jest, or mocha. Returns pass/fail counts and output.",
|
|
102
|
+
usageHint: "Set `files` for specific tests. `watch` enables watch mode. `coverage` generates coverage report. `grep` filters by name.",
|
|
103
|
+
permission: "confirm",
|
|
104
|
+
mutating: false,
|
|
105
|
+
timeoutMs: 12e4,
|
|
106
|
+
inputSchema: {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {
|
|
109
|
+
files: {
|
|
110
|
+
type: "string",
|
|
111
|
+
description: 'Test files: single path, comma-separated list, or glob (e.g. "**/*.test.ts")'
|
|
112
|
+
},
|
|
113
|
+
runner: {
|
|
114
|
+
type: "string",
|
|
115
|
+
enum: ["vitest", "jest", "mocha", "auto"],
|
|
116
|
+
description: "Test runner (default: auto-detect)"
|
|
117
|
+
},
|
|
118
|
+
watch: { type: "boolean", description: "Run in watch mode (default: false)" },
|
|
119
|
+
coverage: { type: "boolean", description: "Generate coverage report (default: false)" },
|
|
120
|
+
cwd: { type: "string", description: "Working directory (default: cwd)" },
|
|
121
|
+
grep: { type: "string", description: "Filter tests by name pattern (default: none)" },
|
|
122
|
+
timeout: { type: "integer", description: "Test timeout in ms (default: 30000)" }
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
async execute(input, ctx, opts) {
|
|
126
|
+
let final;
|
|
127
|
+
for await (const ev of testTool.executeStream(input, ctx, opts)) {
|
|
128
|
+
if (ev.type === "final") final = ev.output;
|
|
129
|
+
}
|
|
130
|
+
if (!final) throw new Error("test: stream ended without final event");
|
|
131
|
+
return final;
|
|
132
|
+
},
|
|
133
|
+
async *executeStream(input, ctx, opts) {
|
|
134
|
+
const cwd = input.cwd ? safeResolve(input.cwd, ctx) : ctx.cwd;
|
|
135
|
+
const runner = input.runner ?? "auto";
|
|
136
|
+
const detected = runner === "auto" ? await detectRunner(cwd) : runner;
|
|
137
|
+
if (!detected) {
|
|
138
|
+
yield {
|
|
139
|
+
type: "final",
|
|
140
|
+
output: {
|
|
141
|
+
runner: "none",
|
|
142
|
+
exit_code: 1,
|
|
143
|
+
tests_run: 0,
|
|
144
|
+
passed: 0,
|
|
145
|
+
failed: 0,
|
|
146
|
+
duration_ms: 0,
|
|
147
|
+
output: "No test runner found (vitest.config.ts, jest.config.js, .mocharc.json)",
|
|
148
|
+
truncated: false
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
yield { type: "log", text: `Running ${detected}\u2026`, data: { runner: detected } };
|
|
154
|
+
const start = Date.now();
|
|
155
|
+
const args = buildArgs(detected, input);
|
|
156
|
+
const result = yield* spawnStream({
|
|
157
|
+
cmd: detected,
|
|
158
|
+
args,
|
|
159
|
+
cwd,
|
|
160
|
+
signal: opts.signal,
|
|
161
|
+
maxBytes: 2e5
|
|
162
|
+
});
|
|
163
|
+
const duration = Date.now() - start;
|
|
164
|
+
yield { type: "final", output: parseResult(detected, result, duration) };
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
async function detectRunner(cwd) {
|
|
168
|
+
const { stat } = await import('fs/promises');
|
|
169
|
+
const candidates = ["vitest.config.ts", "jest.config.js", ".mocharc.json"];
|
|
170
|
+
for (const f of candidates) {
|
|
171
|
+
try {
|
|
172
|
+
await stat(path.join(cwd, f));
|
|
173
|
+
if (f.includes("vitest")) return "vitest";
|
|
174
|
+
if (f.includes("jest")) return "jest";
|
|
175
|
+
if (f.includes("mocha")) return "mocha";
|
|
176
|
+
} catch {
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return "vitest";
|
|
180
|
+
}
|
|
181
|
+
function buildArgs(runner, input) {
|
|
182
|
+
const args = [];
|
|
183
|
+
const timeout = input.timeout ?? 3e4;
|
|
184
|
+
switch (runner) {
|
|
185
|
+
case "vitest":
|
|
186
|
+
args.push("run", "--reporter=verbose");
|
|
187
|
+
if (input.watch) {
|
|
188
|
+
args[1] = "";
|
|
189
|
+
args.push("watch");
|
|
190
|
+
}
|
|
191
|
+
if (input.coverage) args.push("--coverage");
|
|
192
|
+
if (input.grep) args.push("--testNamePattern", input.grep);
|
|
193
|
+
args.push("--testTimeout", String(timeout));
|
|
194
|
+
break;
|
|
195
|
+
case "jest":
|
|
196
|
+
args.push("--verbose");
|
|
197
|
+
if (input.watch) args.push("--watch");
|
|
198
|
+
if (input.coverage) args.push("--coverage");
|
|
199
|
+
if (input.grep) args.push("--testPathPattern", input.grep);
|
|
200
|
+
args.push("--testTimeout", String(timeout));
|
|
201
|
+
break;
|
|
202
|
+
case "mocha":
|
|
203
|
+
args.push("--reporter", "spec");
|
|
204
|
+
if (input.grep) args.push("--grep", input.grep);
|
|
205
|
+
args.push("--timeout", String(timeout));
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
if (input.files) {
|
|
209
|
+
const files = Array.isArray(input.files) ? input.files : input.files.split(",");
|
|
210
|
+
args.push("--", ...files.map((f) => f.trim()));
|
|
211
|
+
}
|
|
212
|
+
return args;
|
|
213
|
+
}
|
|
214
|
+
function parseResult(runner, result, duration) {
|
|
215
|
+
const out = result.stdout + result.stderr;
|
|
216
|
+
let tests_run = 0;
|
|
217
|
+
let passed = 0;
|
|
218
|
+
let failed = 0;
|
|
219
|
+
if (runner === "vitest") {
|
|
220
|
+
const passedMatch = out.match(/(\d+) passed/);
|
|
221
|
+
const failedMatch = out.match(/(\d+) failed/);
|
|
222
|
+
if (passedMatch?.[1]) passed = Number.parseInt(passedMatch[1], 10);
|
|
223
|
+
if (failedMatch?.[1]) failed = Number.parseInt(failedMatch[1], 10);
|
|
224
|
+
tests_run = passed + failed;
|
|
225
|
+
} else if (runner === "jest") {
|
|
226
|
+
const suitesMatch = out.match(/Test Suites:\s+(\d+)\s+total/);
|
|
227
|
+
const passedMatch = out.match(/Tests:\s+(\d+)\s+passed/);
|
|
228
|
+
const failedMatch = out.match(/Tests:\s+(\d+)\s+failed/);
|
|
229
|
+
tests_run = Number.parseInt(suitesMatch?.[1] ?? "0", 10);
|
|
230
|
+
passed = Number.parseInt(passedMatch?.[1] ?? "0", 10);
|
|
231
|
+
failed = Number.parseInt(failedMatch?.[1] ?? "0", 10);
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
runner,
|
|
235
|
+
exit_code: result.exitCode,
|
|
236
|
+
tests_run,
|
|
237
|
+
passed,
|
|
238
|
+
failed,
|
|
239
|
+
duration_ms: duration,
|
|
240
|
+
output: result.stdout || result.error || "",
|
|
241
|
+
truncated: result.truncated
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export { testTool };
|
|
246
|
+
//# sourceMappingURL=test.js.map
|
|
247
|
+
//# sourceMappingURL=test.js.map
|
package/dist/test.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/_util.ts","../src/test.ts"],"names":["resolve","path2"],"mappings":";;;;AAIO,SAAS,WAAA,CAAY,OAAe,GAAA,EAAsB;AAC/D,EAAA,OAAY,IAAA,CAAA,UAAA,CAAW,KAAK,CAAA,GAAS,IAAA,CAAA,SAAA,CAAU,KAAK,CAAA,GAAS,IAAA,CAAA,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AACrF;AAEO,SAAS,gBAAA,CAAiB,SAAiB,GAAA,EAAsB;AACtE,EAAA,MAAM,IAAA,GAAY,IAAA,CAAA,OAAA,CAAQ,GAAA,CAAI,WAAW,CAAA;AACzC,EAAA,MAAM,MAAA,GAAc,aAAQ,OAAO,CAAA;AACnC,EAAA,MAAM,GAAA,GAAW,IAAA,CAAA,QAAA,CAAS,IAAA,EAAM,MAAM,CAAA;AACtC,EAAA,IAAI,IAAI,UAAA,CAAW,IAAI,CAAA,IAAU,IAAA,CAAA,UAAA,CAAW,GAAG,CAAA,EAAG;AAChD,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,MAAA,EAAS,OAAO,CAAA,2BAAA,EAA8B,IAAI,CAAA,CAAA,CAAG,CAAA;AAAA,EACvE;AACA,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,WAAA,CAAY,OAAe,GAAA,EAAsB;AAC/D,EAAA,OAAO,gBAAA,CAAiB,WAAA,CAAY,KAAA,EAAO,GAAG,GAAG,GAAG,CAAA;AACtD;AA6CA,gBAAuB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AA,SAAA,GAAY,MAAA,GAAS,MAAA;AAAA,EACvB,CAAA,MAAA,IAAW,WAAW,MAAA,EAAQ;AAC5B,IAAA,MAAM,WAAA,GAAc,GAAA,CAAI,KAAA,CAAM,8BAA8B,CAAA;AAC5D,IAAA,MAAM,WAAA,GAAc,GAAA,CAAI,KAAA,CAAM,yBAAyB,CAAA;AACvD,IAAA,MAAM,WAAA,GAAc,GAAA,CAAI,KAAA,CAAM,yBAAyB,CAAA;AACvD,IAAA,SAAA,GAAY,OAAO,QAAA,CAAS,WAAA,GAAc,CAAC,CAAA,IAAK,KAAK,EAAE,CAAA;AACvD,IAAA,MAAA,GAAS,OAAO,QAAA,CAAS,WAAA,GAAc,CAAC,CAAA,IAAK,KAAK,EAAE,CAAA;AACpD,IAAA,MAAA,GAAS,OAAO,QAAA,CAAS,WAAA,GAAc,CAAC,CAAA,IAAK,KAAK,EAAE,CAAA;AAAA,EACtD;AAEA,EAAA,OAAO;AAAA,IACL,MAAA;AAAA,IACA,WAAW,MAAA,CAAO,QAAA;AAAA,IAClB,SAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,WAAA,EAAa,QAAA;AAAA,IACb,MAAA,EAAQ,MAAA,CAAO,MAAA,IAAU,MAAA,CAAO,KAAA,IAAS,EAAA;AAAA,IACzC,WAAW,MAAA,CAAO;AAAA,GACpB;AACF","file":"test.js","sourcesContent":["import * as path from 'node:path';\r\nimport { spawn } from 'node:child_process';\r\nimport type { Context, ToolProgressEvent } from '@wrongstack/core';\r\n\r\nexport function resolvePath(input: string, ctx: Context): string {\r\n return path.isAbsolute(input) ? path.normalize(input) : path.resolve(ctx.cwd, input);\r\n}\r\n\r\nexport function ensureInsideRoot(absPath: string, ctx: Context): string {\r\n const root = path.resolve(ctx.projectRoot);\r\n const target = path.resolve(absPath);\r\n const rel = path.relative(root, target);\r\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\r\n throw new Error(`Path \"${absPath}\" is outside project root \"${root}\"`);\r\n }\r\n return target;\r\n}\r\n\r\nexport function safeResolve(input: string, ctx: Context): string {\r\n return ensureInsideRoot(resolvePath(input, ctx), ctx);\r\n}\r\n\r\nexport function truncateMiddle(s: string, max: number): string {\r\n if (Buffer.byteLength(s, 'utf8') <= max) return s;\r\n const half = Math.floor(max / 2);\r\n return (\r\n s.slice(0, half) +\r\n `\\n…[truncated ${Buffer.byteLength(s, 'utf8') - max} bytes from middle]…\\n` +\r\n s.slice(-half)\r\n );\r\n}\r\n\r\nexport function isBinaryBuffer(buf: Buffer): boolean {\r\n const len = Math.min(buf.length, 8192);\r\n for (let i = 0; i < len; i++) {\r\n if (buf[i] === 0) return true;\r\n }\r\n return false;\r\n}\r\n\r\nexport interface SpawnStreamResult {\r\n stdout: string;\r\n stderr: string;\r\n exitCode: number;\r\n truncated: boolean;\r\n error?: string;\r\n}\r\n\r\nexport interface SpawnStreamOptions {\r\n cmd: string;\r\n args: string[];\r\n cwd: string;\r\n signal: AbortSignal;\r\n maxBytes?: number;\r\n /** Bytes of new stdout/stderr to accumulate before yielding a `partial_output` event. */\r\n flushBytes?: number;\r\n}\r\n\r\n/**\r\n * Spawn a child process and yield `partial_output` progress events as\r\n * stdout/stderr arrive (batched by byte threshold), then return the full\r\n * buffered result. Shared between install/lint/format/typecheck/test/audit\r\n * so the TUI live tail sees consistent progress regardless of which tool\r\n * is running.\r\n */\r\nexport async function* spawnStream(\r\n opts: SpawnStreamOptions,\r\n): AsyncGenerator<ToolProgressEvent, SpawnStreamResult> {\r\n const max = opts.maxBytes ?? 200_000;\r\n const flushAt = opts.flushBytes ?? 4 * 1024;\r\n let stdout = '';\r\n let stderr = '';\r\n let pending = '';\r\n let error: string | undefined;\r\n\r\n const child = spawn(opts.cmd, opts.args, {\r\n cwd: opts.cwd,\r\n signal: opts.signal,\r\n stdio: ['ignore', 'pipe', 'pipe'],\r\n });\r\n\r\n type Chunk = { kind: 'out' | 'err' | 'close' | 'error'; data: string; code?: number };\r\n const queue: Chunk[] = [];\r\n let waiter: (() => void) | undefined;\r\n const wake = () => {\r\n if (waiter) {\r\n const w = waiter;\r\n waiter = undefined;\r\n w();\r\n }\r\n };\r\n\r\n child.stdout?.on('data', (c) => {\r\n const s = c.toString();\r\n if (stdout.length < max) stdout += s;\r\n queue.push({ kind: 'out', data: s });\r\n wake();\r\n });\r\n child.stderr?.on('data', (c) => {\r\n const s = c.toString();\r\n if (stderr.length < max) stderr += s;\r\n queue.push({ kind: 'err', data: s });\r\n wake();\r\n });\r\n child.on('error', (e) => {\r\n error = e.message;\r\n queue.push({ kind: 'error', data: e.message });\r\n wake();\r\n });\r\n child.on('close', (code) => {\r\n queue.push({ kind: 'close', data: '', code: code ?? 0 });\r\n wake();\r\n });\r\n\r\n let exitCode = 0;\r\n let spawnFailed = false;\r\n for (;;) {\r\n while (queue.length === 0) {\r\n await new Promise<void>((resolve) => {\r\n waiter = resolve;\r\n });\r\n }\r\n const chunk = queue.shift()!;\r\n if (chunk.kind === 'close') {\r\n // If we already saw a spawn error (ENOENT etc.), keep exitCode=1\r\n // rather than the negative platform code Node fabricates.\r\n if (!spawnFailed) exitCode = chunk.code ?? 0;\r\n break;\r\n }\r\n if (chunk.kind === 'error') {\r\n spawnFailed = true;\r\n exitCode = 1;\r\n // close usually follows\r\n continue;\r\n }\r\n pending += chunk.data;\r\n if (pending.length >= flushAt) {\r\n yield { type: 'partial_output', text: pending };\r\n pending = '';\r\n }\r\n }\r\n if (pending.length > 0) {\r\n yield { type: 'partial_output', text: pending };\r\n }\r\n\r\n return {\r\n stdout,\r\n stderr,\r\n exitCode,\r\n truncated: stdout.length >= max || stderr.length >= max,\r\n error,\r\n };\r\n}\r\n","import * as path from 'node:path';\r\nimport type { Tool, ToolStreamEvent } from '@wrongstack/core';\r\nimport { safeResolve, spawnStream } from './_util.js';\r\n\r\ninterface TestInput {\r\n files?: string | string[];\r\n runner?: 'vitest' | 'jest' | 'mocha' | 'auto';\r\n watch?: boolean;\r\n coverage?: boolean;\r\n cwd?: string;\r\n grep?: string;\r\n timeout?: number;\r\n}\r\n\r\ninterface TestOutput {\r\n runner: string;\r\n exit_code: number;\r\n tests_run: number;\r\n passed: number;\r\n failed: number;\r\n duration_ms: number;\r\n output: string;\r\n truncated: boolean;\r\n}\r\n\r\nexport const testTool: Tool<TestInput, TestOutput> = {\r\n name: 'test',\r\n description:\r\n 'Run tests with vitest, jest, or mocha. Returns pass/fail counts and output.',\r\n usageHint:\r\n 'Set `files` for specific tests. `watch` enables watch mode. `coverage` generates coverage report. `grep` filters by name.',\r\n permission: 'confirm',\r\n mutating: false,\r\n timeoutMs: 120_000,\r\n inputSchema: {\r\n type: 'object',\r\n properties: {\r\n files: {\r\n type: 'string',\r\n description: 'Test files: single path, comma-separated list, or glob (e.g. \"**/*.test.ts\")',\r\n },\r\n runner: {\r\n type: 'string',\r\n enum: ['vitest', 'jest', 'mocha', 'auto'],\r\n description: 'Test runner (default: auto-detect)',\r\n },\r\n watch: { type: 'boolean', description: 'Run in watch mode (default: false)' },\r\n coverage: { type: 'boolean', description: 'Generate coverage report (default: false)' },\r\n cwd: { type: 'string', description: 'Working directory (default: cwd)' },\r\n grep: { type: 'string', description: 'Filter tests by name pattern (default: none)' },\r\n timeout: { type: 'integer', description: 'Test timeout in ms (default: 30000)' },\r\n },\r\n },\r\n async execute(input, ctx, opts) {\r\n let final: TestOutput | undefined;\r\n for await (const ev of testTool.executeStream!(input, ctx, opts)) {\r\n if (ev.type === 'final') final = ev.output;\r\n }\r\n if (!final) throw new Error('test: stream ended without final event');\r\n return final;\r\n },\r\n async *executeStream(input, ctx, opts): AsyncGenerator<ToolStreamEvent<TestOutput>> {\r\n const cwd = input.cwd ? safeResolve(input.cwd, ctx) : ctx.cwd;\r\n const runner = input.runner ?? 'auto';\r\n\r\n const detected = runner === 'auto' ? await detectRunner(cwd) : runner;\r\n if (!detected) {\r\n yield {\r\n type: 'final',\r\n output: {\r\n runner: 'none',\r\n exit_code: 1,\r\n tests_run: 0,\r\n passed: 0,\r\n failed: 0,\r\n duration_ms: 0,\r\n output: 'No test runner found (vitest.config.ts, jest.config.js, .mocharc.json)',\r\n truncated: false,\r\n },\r\n };\r\n return;\r\n }\r\n\r\n yield { type: 'log', text: `Running ${detected}…`, data: { runner: detected } };\r\n\r\n const start = Date.now();\r\n const args = buildArgs(detected, input);\r\n\r\n const result = yield* spawnStream({\r\n cmd: detected,\r\n args,\r\n cwd,\r\n signal: opts.signal,\r\n maxBytes: 200_000,\r\n });\r\n const duration = Date.now() - start;\r\n\r\n yield { type: 'final', output: parseResult(detected, result, duration) };\r\n },\r\n};\r\n\r\nasync function detectRunner(cwd: string): Promise<string | null> {\r\n const { stat } = await import('node:fs/promises');\r\n const candidates = ['vitest.config.ts', 'jest.config.js', '.mocharc.json'];\r\n for (const f of candidates) {\r\n try {\r\n await stat(path.join(cwd, f));\r\n if (f.includes('vitest')) return 'vitest';\r\n if (f.includes('jest')) return 'jest';\r\n if (f.includes('mocha')) return 'mocha';\r\n } catch {\r\n // continue\r\n }\r\n }\r\n return 'vitest';\r\n}\r\n\r\nfunction buildArgs(runner: string, input: TestInput): string[] {\r\n const args: string[] = [];\r\n const timeout = input.timeout ?? 30000;\r\n\r\n switch (runner) {\r\n case 'vitest':\r\n args.push('run', '--reporter=verbose');\r\n if (input.watch) { args[1] = ''; args.push('watch'); }\r\n if (input.coverage) args.push('--coverage');\r\n if (input.grep) args.push('--testNamePattern', input.grep);\r\n args.push('--testTimeout', String(timeout));\r\n break;\r\n case 'jest':\r\n args.push('--verbose');\r\n if (input.watch) args.push('--watch');\r\n if (input.coverage) args.push('--coverage');\r\n if (input.grep) args.push('--testPathPattern', input.grep);\r\n args.push('--testTimeout', String(timeout));\r\n break;\r\n case 'mocha':\r\n args.push('--reporter', 'spec');\r\n if (input.grep) args.push('--grep', input.grep);\r\n args.push('--timeout', String(timeout));\r\n break;\r\n }\r\n\r\n if (input.files) {\r\n const files = Array.isArray(input.files) ? input.files : input.files.split(',');\r\n args.push('--', ...files.map((f) => f.trim()));\r\n }\r\n\r\n return args;\r\n}\r\n\r\nfunction parseResult(\r\n runner: string,\r\n result: { stdout: string; stderr: string; exitCode: number; truncated: boolean; error?: string },\r\n duration: number,\r\n): TestOutput {\r\n const out = result.stdout + result.stderr;\r\n\r\n let tests_run = 0;\r\n let passed = 0;\r\n let failed = 0;\r\n\r\n if (runner === 'vitest') {\r\n const passedMatch = out.match(/(\\d+) passed/);\r\n const failedMatch = out.match(/(\\d+) failed/);\r\n if (passedMatch?.[1]) passed = Number.parseInt(passedMatch[1], 10);\r\n if (failedMatch?.[1]) failed = Number.parseInt(failedMatch[1], 10);\r\n tests_run = passed + failed;\r\n } else if (runner === 'jest') {\r\n const suitesMatch = out.match(/Test Suites:\\s+(\\d+)\\s+total/);\r\n const passedMatch = out.match(/Tests:\\s+(\\d+)\\s+passed/);\r\n const failedMatch = out.match(/Tests:\\s+(\\d+)\\s+failed/);\r\n tests_run = Number.parseInt(suitesMatch?.[1] ?? '0', 10);\r\n passed = Number.parseInt(passedMatch?.[1] ?? '0', 10);\r\n failed = Number.parseInt(failedMatch?.[1] ?? '0', 10);\r\n }\r\n\r\n return {\r\n runner,\r\n exit_code: result.exitCode,\r\n tests_run,\r\n passed,\r\n failed,\r\n duration_ms: duration,\r\n output: result.stdout || result.error || '',\r\n truncated: result.truncated,\r\n };\r\n}\r\n"]}
|
package/dist/todo.d.ts
ADDED
package/dist/todo.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/todo.ts
|
|
2
|
+
var todoTool = {
|
|
3
|
+
name: "todo",
|
|
4
|
+
description: "Replace the current todo list with a new set of items.",
|
|
5
|
+
usageHint: "Use for multi-step tasks. Replace the full list on each call. At most ONE task may be in_progress at a time. Items have id, content, status (pending|in_progress|completed), and optional activeForm.",
|
|
6
|
+
permission: "auto",
|
|
7
|
+
mutating: false,
|
|
8
|
+
timeoutMs: 1e3,
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
todos: {
|
|
13
|
+
type: "array",
|
|
14
|
+
items: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {
|
|
17
|
+
id: { type: "string" },
|
|
18
|
+
content: { type: "string" },
|
|
19
|
+
status: { type: "string", enum: ["pending", "in_progress", "completed"] },
|
|
20
|
+
activeForm: { type: "string" }
|
|
21
|
+
},
|
|
22
|
+
required: ["id", "content", "status"]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
required: ["todos"]
|
|
27
|
+
},
|
|
28
|
+
async execute(input, ctx) {
|
|
29
|
+
if (!Array.isArray(input?.todos)) {
|
|
30
|
+
throw new Error("todo: todos must be an array");
|
|
31
|
+
}
|
|
32
|
+
const items = input.todos.filter((t) => Boolean(t?.id && t.content));
|
|
33
|
+
const inProgress = items.filter((t) => t.status === "in_progress");
|
|
34
|
+
if (inProgress.length > 1) {
|
|
35
|
+
let seenInProgress = false;
|
|
36
|
+
for (const item of items) {
|
|
37
|
+
if (item.status === "in_progress") {
|
|
38
|
+
if (seenInProgress) item.status = "pending";
|
|
39
|
+
seenInProgress = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
ctx.todos = items;
|
|
44
|
+
return {
|
|
45
|
+
count: items.length,
|
|
46
|
+
in_progress: items.filter((t) => t.status === "in_progress").length
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { todoTool };
|
|
52
|
+
//# sourceMappingURL=todo.js.map
|
|
53
|
+
//# sourceMappingURL=todo.js.map
|
package/dist/todo.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/todo.ts"],"names":[],"mappings":";AAWO,IAAM,QAAA,GAAwC;AAAA,EACnD,IAAA,EAAM,MAAA;AAAA,EACN,WAAA,EAAa,wDAAA;AAAA,EACb,SAAA,EACE,uMAAA;AAAA,EACF,UAAA,EAAY,MAAA;AAA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;AACxB,QAAA,IAAI,IAAA,CAAK,WAAW,aAAA,EAAe;AACjC,UAAA,IAAI,cAAA,OAAqB,MAAA,GAAS,SAAA;AAClC,UAAA,cAAA,GAAiB,IAAA;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AACA,IAAA,GAAA,CAAI,KAAA,GAAQ,KAAA;AACZ,IAAA,OAAO;AAAA,MACL,OAAO,KAAA,CAAM,MAAA;AAAA,MACb,WAAA,EAAa,MAAM,MAAA,CAAO,CAAC,MAAM,CAAA,CAAE,MAAA,KAAW,aAAa,CAAA,CAAE;AAAA,KAC/D;AAAA,EACF;AACF","file":"todo.js","sourcesContent":["import type { Tool, TodoItem } from '@wrongstack/core';\n\ninterface TodoInput {\n todos: TodoItem[];\n}\n\ninterface TodoOutput {\n count: number;\n in_progress: number;\n}\n\nexport const todoTool: Tool<TodoInput, TodoOutput> = {\n name: 'todo',\n description: 'Replace the current todo list with a new set of items.',\n usageHint:\n 'Use for multi-step tasks. Replace the full list on each call. At most ONE task may be in_progress at a time. Items have id, content, status (pending|in_progress|completed), and optional activeForm.',\n permission: 'auto',\n mutating: false,\n timeoutMs: 1_000,\n inputSchema: {\n type: 'object',\n properties: {\n todos: {\n type: 'array',\n items: {\n type: 'object',\n properties: {\n id: { type: 'string' },\n content: { type: 'string' },\n status: { type: 'string', enum: ['pending', 'in_progress', 'completed'] },\n activeForm: { type: 'string' },\n },\n required: ['id', 'content', 'status'],\n },\n },\n },\n required: ['todos'],\n },\n async execute(input, ctx) {\n if (!Array.isArray(input?.todos)) {\n throw new Error('todo: todos must be an array');\n }\n const items = input.todos.filter((t): t is TodoItem => Boolean(t?.id && t.content));\n const inProgress = items.filter((t) => t.status === 'in_progress');\n if (inProgress.length > 1) {\n // Keep only the first as in_progress, mark rest pending\n let seenInProgress = false;\n for (const item of items) {\n if (item.status === 'in_progress') {\n if (seenInProgress) item.status = 'pending';\n seenInProgress = true;\n }\n }\n }\n ctx.todos = items;\n return {\n count: items.length,\n in_progress: items.filter((t) => t.status === 'in_progress').length,\n };\n },\n};\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Tool } from '@wrongstack/core';
|
|
2
|
+
|
|
3
|
+
interface ToolHelpInput {
|
|
4
|
+
tool?: string;
|
|
5
|
+
format?: 'short' | 'full' | 'markdown';
|
|
6
|
+
include_examples?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface ToolHelpOutput {
|
|
9
|
+
tool?: string;
|
|
10
|
+
help: string;
|
|
11
|
+
tools: {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
usageHint: string;
|
|
15
|
+
inputSchema: unknown;
|
|
16
|
+
permission: string;
|
|
17
|
+
mutating: boolean;
|
|
18
|
+
}[];
|
|
19
|
+
total: number;
|
|
20
|
+
}
|
|
21
|
+
declare const toolHelpTool: Tool<ToolHelpInput, ToolHelpOutput>;
|
|
22
|
+
|
|
23
|
+
export { toolHelpTool };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// src/tool-help.ts
|
|
2
|
+
var toolHelpTool = {
|
|
3
|
+
name: "tool_help",
|
|
4
|
+
description: "Get help and usage information for a specific tool or list all available tools.",
|
|
5
|
+
usageHint: "Set `tool` for specific help. Omit to list all tools. `format`: short (one-liner), full (schema), markdown (formatted).",
|
|
6
|
+
permission: "auto",
|
|
7
|
+
mutating: false,
|
|
8
|
+
timeoutMs: 5e3,
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
tool: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Tool name to get help for (omit for all tools)"
|
|
15
|
+
},
|
|
16
|
+
format: {
|
|
17
|
+
type: "string",
|
|
18
|
+
enum: ["short", "full", "markdown"],
|
|
19
|
+
description: "Output format (default: short)"
|
|
20
|
+
},
|
|
21
|
+
include_examples: {
|
|
22
|
+
type: "boolean",
|
|
23
|
+
description: "Include usage examples in output (default: false)"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
async execute(input, ctx) {
|
|
28
|
+
const format = input.format ?? "short";
|
|
29
|
+
const includeExamples = input.include_examples ?? false;
|
|
30
|
+
if (input.tool) {
|
|
31
|
+
const tool = ctx.tools.find((t) => t.name === input.tool);
|
|
32
|
+
if (!tool) {
|
|
33
|
+
return {
|
|
34
|
+
tool: input.tool,
|
|
35
|
+
help: `No tool found with name "${input.tool}"`,
|
|
36
|
+
tools: [],
|
|
37
|
+
total: 0
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
tool: tool.name,
|
|
42
|
+
help: formatToolHelp(tool, format, includeExamples),
|
|
43
|
+
tools: [{
|
|
44
|
+
name: tool.name,
|
|
45
|
+
description: tool.description,
|
|
46
|
+
usageHint: tool.usageHint ?? "",
|
|
47
|
+
inputSchema: tool.inputSchema,
|
|
48
|
+
permission: tool.permission,
|
|
49
|
+
mutating: tool.mutating
|
|
50
|
+
}],
|
|
51
|
+
total: 1
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const allTools = ctx.tools.map((t) => ({
|
|
55
|
+
name: t.name,
|
|
56
|
+
description: t.description,
|
|
57
|
+
usageHint: t.usageHint ?? "",
|
|
58
|
+
inputSchema: format === "full" ? t.inputSchema : void 0,
|
|
59
|
+
permission: t.permission,
|
|
60
|
+
mutating: t.mutating
|
|
61
|
+
}));
|
|
62
|
+
return {
|
|
63
|
+
help: format === "markdown" ? formatAllToolsMarkdown(allTools) : formatAllToolsShort(allTools),
|
|
64
|
+
tools: allTools,
|
|
65
|
+
total: allTools.length
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
function formatToolHelp(tool, format, includeExamples) {
|
|
70
|
+
const lines = [];
|
|
71
|
+
if (format === "short") {
|
|
72
|
+
lines.push(`${tool.name}: ${tool.description}`);
|
|
73
|
+
if (tool.usageHint) lines.push(`Hint: ${tool.usageHint}`);
|
|
74
|
+
return lines.join("\n");
|
|
75
|
+
}
|
|
76
|
+
if (format === "markdown") {
|
|
77
|
+
lines.push(`## ${tool.name}`);
|
|
78
|
+
lines.push("");
|
|
79
|
+
lines.push(tool.description);
|
|
80
|
+
lines.push("");
|
|
81
|
+
lines.push("**Permission:** " + tool.permission);
|
|
82
|
+
lines.push("**Mutating:** " + (tool.mutating ? "yes" : "no"));
|
|
83
|
+
if (tool.usageHint) {
|
|
84
|
+
lines.push("");
|
|
85
|
+
lines.push("### Usage Hint");
|
|
86
|
+
lines.push(tool.usageHint);
|
|
87
|
+
}
|
|
88
|
+
if (includeExamples && tool.inputSchema) {
|
|
89
|
+
lines.push("");
|
|
90
|
+
lines.push("### Input Schema");
|
|
91
|
+
lines.push("```json");
|
|
92
|
+
lines.push(JSON.stringify(tool.inputSchema, null, 2));
|
|
93
|
+
lines.push("```");
|
|
94
|
+
}
|
|
95
|
+
return lines.join("\n");
|
|
96
|
+
}
|
|
97
|
+
lines.push(`Tool: ${tool.name}`);
|
|
98
|
+
lines.push(`Description: ${tool.description}`);
|
|
99
|
+
lines.push(`Permission: ${tool.permission}`);
|
|
100
|
+
lines.push(`Mutating: ${tool.mutating}`);
|
|
101
|
+
if (tool.usageHint) lines.push(`Usage: ${tool.usageHint}`);
|
|
102
|
+
if (format === "full" && tool.inputSchema) {
|
|
103
|
+
lines.push("Schema: " + JSON.stringify(tool.inputSchema, null, 2));
|
|
104
|
+
}
|
|
105
|
+
return lines.join("\n");
|
|
106
|
+
}
|
|
107
|
+
function formatAllToolsShort(tools) {
|
|
108
|
+
return tools.map((t) => ` ${t.name.padEnd(16)} ${t.description}`).join("\n");
|
|
109
|
+
}
|
|
110
|
+
function formatAllToolsMarkdown(tools) {
|
|
111
|
+
const lines = ["## Available Tools", ""];
|
|
112
|
+
lines.push("| Tool | Description |");
|
|
113
|
+
lines.push("|------|-------------|");
|
|
114
|
+
for (const t of tools) {
|
|
115
|
+
lines.push(`| \`${t.name}\` | ${t.description} |`);
|
|
116
|
+
}
|
|
117
|
+
return lines.join("\n");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { toolHelpTool };
|
|
121
|
+
//# sourceMappingURL=tool-help.js.map
|
|
122
|
+
//# sourceMappingURL=tool-help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tool-help.ts"],"names":[],"mappings":";AAsBO,IAAM,YAAA,GAAoD;AAAA,EAC/D,IAAA,EAAM,WAAA;AAAA,EACN,WAAA,EACE,iFAAA;AAAA,EACF,SAAA,EACE,yHAAA;AAAA,EACF,UAAA,EAAY,MAAA;AAAA,EACZ,QAAA,EAAU,KAAA;AAAA,EACV,SAAA,EAAW,GAAA;AAAA,EACX,WAAA,EAAa;AAAA,IACX,IAAA,EAAM,QAAA;AAAA,IACN,UAAA,EAAY;AAAA,MACV,IAAA,EAAM;AAAA,QACJ,IAAA,EAAM,QAAA;AAAA,QACN,WAAA,EAAa;AAAA,OACf;AAAA,MACA,MAAA,EAAQ;AAAA,QACN,IAAA,EAAM,QAAA;AAAA,QACN,IAAA,EAAM,CAAC,OAAA,EAAS,MAAA,EAAQ,UAAU,CAAA;AAAA,QAClC,WAAA,EAAa;AAAA,OACf;AAAA,MACA,gBAAA,EAAkB;AAAA,QAChB,IAAA,EAAM,SAAA;AAAA,QACN,WAAA,EAAa;AAAA;AACf;AACF,GACF;AAAA,EACA,MAAM,OAAA,CAAQ,KAAA,EAAO,GAAA,EAAK;AACxB,IAAA,MAAM,MAAA,GAAS,MAAM,MAAA,IAAU,OAAA;AAC/B,IAAA,MAAM,eAAA,GAAkB,MAAM,gBAAA,IAAoB,KAAA;AAElD,IAAA,IAAI,MAAM,IAAA,EAAM;AACd,MAAA,MAAM,IAAA,GAAO,IAAI,KAAA,CAAM,IAAA,CAAK,CAAC,CAAA,KAAY,CAAA,CAAE,IAAA,KAAS,KAAA,CAAM,IAAI,CAAA;AAC9D,MAAA,IAAI,CAAC,IAAA,EAAM;AACT,QAAA,OAAO;AAAA,UACL,MA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C,EAAA,KAAA,CAAM,KAAK,wBAAwB,CAAA;AACnC,EAAA,KAAA,MAAW,KAAK,KAAA,EAAO;AACrB,IAAA,KAAA,CAAM,KAAK,CAAA,IAAA,EAAO,CAAA,CAAE,IAAI,CAAA,KAAA,EAAQ,CAAA,CAAE,WAAW,CAAA,EAAA,CAAI,CAAA;AAAA,EACnD;AACA,EAAA,OAAO,KAAA,CAAM,KAAK,IAAI,CAAA;AACxB","file":"tool-help.js","sourcesContent":["import type { Tool } from '@wrongstack/core';\n\ninterface ToolHelpInput {\n tool?: string;\n format?: 'short' | 'full' | 'markdown';\n include_examples?: boolean;\n}\n\ninterface ToolHelpOutput {\n tool?: string;\n help: string;\n tools: {\n name: string;\n description: string;\n usageHint: string;\n inputSchema: unknown;\n permission: string;\n mutating: boolean;\n }[];\n total: number;\n}\n\nexport const toolHelpTool: Tool<ToolHelpInput, ToolHelpOutput> = {\n name: 'tool_help',\n description:\n 'Get help and usage information for a specific tool or list all available tools.',\n usageHint:\n 'Set `tool` for specific help. Omit to list all tools. `format`: short (one-liner), full (schema), markdown (formatted).',\n permission: 'auto',\n mutating: false,\n timeoutMs: 5_000,\n inputSchema: {\n type: 'object',\n properties: {\n tool: {\n type: 'string',\n description: 'Tool name to get help for (omit for all tools)',\n },\n format: {\n type: 'string',\n enum: ['short', 'full', 'markdown'],\n description: 'Output format (default: short)',\n },\n include_examples: {\n type: 'boolean',\n description: 'Include usage examples in output (default: false)',\n },\n },\n },\n async execute(input, ctx) {\n const format = input.format ?? 'short';\n const includeExamples = input.include_examples ?? false;\n\n if (input.tool) {\n const tool = ctx.tools.find((t: Tool) => t.name === input.tool);\n if (!tool) {\n return {\n tool: input.tool,\n help: `No tool found with name \"${input.tool}\"`,\n tools: [],\n total: 0,\n };\n }\n\n return {\n tool: tool.name,\n help: formatToolHelp(tool, format, includeExamples),\n tools: [{\n name: tool.name,\n description: tool.description,\n usageHint: tool.usageHint ?? '',\n inputSchema: tool.inputSchema,\n permission: tool.permission,\n mutating: tool.mutating,\n }],\n total: 1,\n };\n }\n\n const allTools = ctx.tools.map((t: Tool) => ({\n name: t.name,\n description: t.description,\n usageHint: t.usageHint ?? '',\n inputSchema: format === 'full' ? t.inputSchema : undefined,\n permission: t.permission,\n mutating: t.mutating,\n }));\n\n return {\n help: format === 'markdown' ? formatAllToolsMarkdown(allTools) : formatAllToolsShort(allTools),\n tools: allTools,\n total: allTools.length,\n };\n },\n};\n\nfunction formatToolHelp(tool: Tool, format: string, includeExamples: boolean): string {\n const lines: string[] = [];\n\n if (format === 'short') {\n lines.push(`${tool.name}: ${tool.description}`);\n if (tool.usageHint) lines.push(`Hint: ${tool.usageHint}`);\n return lines.join('\\n');\n }\n\n if (format === 'markdown') {\n lines.push(`## ${tool.name}`);\n lines.push('');\n lines.push(tool.description);\n lines.push('');\n lines.push('**Permission:** ' + tool.permission);\n lines.push('**Mutating:** ' + (tool.mutating ? 'yes' : 'no'));\n if (tool.usageHint) {\n lines.push('');\n lines.push('### Usage Hint');\n lines.push(tool.usageHint);\n }\n if (includeExamples && tool.inputSchema) {\n lines.push('');\n lines.push('### Input Schema');\n lines.push('```json');\n lines.push(JSON.stringify(tool.inputSchema, null, 2));\n lines.push('```');\n }\n return lines.join('\\n');\n }\n\n lines.push(`Tool: ${tool.name}`);\n lines.push(`Description: ${tool.description}`);\n lines.push(`Permission: ${tool.permission}`);\n lines.push(`Mutating: ${tool.mutating}`);\n if (tool.usageHint) lines.push(`Usage: ${tool.usageHint}`);\n if (format === 'full' && tool.inputSchema) {\n lines.push('Schema: ' + JSON.stringify(tool.inputSchema, null, 2));\n }\n return lines.join('\\n');\n}\n\nfunction formatAllToolsShort(tools: { name: string; description: string }[]): string {\n return tools\n .map((t) => ` ${t.name.padEnd(16)} ${t.description}`)\n .join('\\n');\n}\n\nfunction formatAllToolsMarkdown(tools: { name: string; description: string; usageHint: string }[]): string {\n const lines: string[] = ['## Available Tools', ''];\n lines.push('| Tool | Description |');\n lines.push('|------|-------------|');\n for (const t of tools) {\n lines.push(`| \\`${t.name}\\` | ${t.description} |`);\n }\n return lines.join('\\n');\n}"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Tool } from '@wrongstack/core';
|
|
2
|
+
|
|
3
|
+
interface ToolSearchInput {
|
|
4
|
+
query?: string;
|
|
5
|
+
tags?: string[];
|
|
6
|
+
permission?: 'auto' | 'confirm' | 'deny';
|
|
7
|
+
mutating?: boolean;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}
|
|
10
|
+
interface ToolSearchOutput {
|
|
11
|
+
tools: {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
permission: string;
|
|
15
|
+
mutating: boolean;
|
|
16
|
+
}[];
|
|
17
|
+
total: number;
|
|
18
|
+
truncated: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare const toolSearchTool: Tool<ToolSearchInput, ToolSearchOutput>;
|
|
21
|
+
|
|
22
|
+
export { toolSearchTool };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/tool-search.ts
|
|
2
|
+
var toolSearchTool = {
|
|
3
|
+
name: "tool_search",
|
|
4
|
+
description: "Search available tools by name, description, tags, permission level, or mutating flag.",
|
|
5
|
+
usageHint: "Set `query` for keyword search. `tags` to filter by category. `permission` to filter by required permission. `mutating` to filter by mutating flag.",
|
|
6
|
+
permission: "auto",
|
|
7
|
+
mutating: false,
|
|
8
|
+
timeoutMs: 1e3,
|
|
9
|
+
inputSchema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
query: {
|
|
13
|
+
type: "string",
|
|
14
|
+
description: "Search query for tool name or description"
|
|
15
|
+
},
|
|
16
|
+
tags: {
|
|
17
|
+
type: "array",
|
|
18
|
+
items: { type: "string" },
|
|
19
|
+
description: 'Filter by tags (e.g. "filesystem", "network", "dev")'
|
|
20
|
+
},
|
|
21
|
+
permission: {
|
|
22
|
+
type: "string",
|
|
23
|
+
enum: ["auto", "confirm", "deny"],
|
|
24
|
+
description: "Filter by required permission level"
|
|
25
|
+
},
|
|
26
|
+
mutating: {
|
|
27
|
+
type: "boolean",
|
|
28
|
+
description: "Filter by mutating flag (true=filters that modify, false=read-only)"
|
|
29
|
+
},
|
|
30
|
+
limit: {
|
|
31
|
+
type: "integer",
|
|
32
|
+
description: "Maximum results to return (default: 20)",
|
|
33
|
+
minimum: 1,
|
|
34
|
+
maximum: 100
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
async execute(input, ctx) {
|
|
39
|
+
const limit = Math.min(input.limit ?? 20, 100);
|
|
40
|
+
const tools = ctx.tools;
|
|
41
|
+
const query = input.query?.toLowerCase() ?? "";
|
|
42
|
+
const filtered = tools.filter((t) => {
|
|
43
|
+
if (query && !t.name.toLowerCase().includes(query) && !t.description.toLowerCase().includes(query)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (input.permission && t.permission !== input.permission) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (typeof input.mutating === "boolean" && t.mutating !== input.mutating) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
54
|
+
const results = filtered.slice(0, limit).map((t) => ({
|
|
55
|
+
name: t.name,
|
|
56
|
+
description: t.description,
|
|
57
|
+
permission: t.permission,
|
|
58
|
+
mutating: t.mutating
|
|
59
|
+
}));
|
|
60
|
+
return {
|
|
61
|
+
tools: results,
|
|
62
|
+
total: filtered.length,
|
|
63
|
+
truncated: filtered.length > limit
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export { toolSearchTool };
|
|
69
|
+
//# sourceMappingURL=tool-search.js.map
|
|
70
|
+
//# sourceMappingURL=tool-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tool-search.ts"],"names":[],"mappings":";AAqBO,IAAM,cAAA,GAA0D;AAAA,EACrE,I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A,CAAE,IAAA,CAAK,WAAA,GAAc,QAAA,CAAS,KAAK,CAAA,IAAK,CAAC,EAAE,WAAA,CAAY,WAAA,EAAY,CAAE,QAAA,CAAS,KAAK,CAAA,EAAG;AAClG,QAAA,OAAO,KAAA;AAAA,MACT;AACA,MAAA,IAAI,KAAA,CAAM,UAAA,IAAc,CAAA,CAAE,UAAA,KAAe,MAAM,UAAA,EAAY;AACzD,QAAA,OAAO,KAAA;AAAA,MACT;AACA,MAAA,IAAI,OAAO,KAAA,CAAM,QAAA,KAAa,aAAa,CAAA,CAAE,QAAA,KAAa,MAAM,QAAA,EAAU;AACxE,QAAA,OAAO,KAAA;AAAA,MACT;AACA,MAAA,OAAO,IAAA;AAAA,IACT,CAAC,CAAA;AAED,IAAA,MAAM,OAAA,GAAU,SAAS,KAAA,CAAM,CAAA,EAAG,KAAK,CAAA,CAAE,GAAA,CAAI,CAAC,CAAA,MAAa;AAAA,MACzD,MAAM,CAAA,CAAE,IAAA;AAAA,MACR,aAAa,CAAA,CAAE,WAAA;AAAA,MACf,YAAY,CAAA,CAAE,UAAA;AAAA,MACd,UAAU,CAAA,CAAE;AAAA,KACd,CAAE,CAAA;AAEF,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,OAAA;AAAA,MACP,OAAO,QAAA,CAAS,MAAA;AAAA,MAChB,SAAA,EAAW,SAAS,MAAA,GAAS;AAAA,KAC/B;AAAA,EACF;AACF","file":"tool-search.js","sourcesContent":["import type { Tool } from '@wrongstack/core';\r\n\r\ninterface ToolSearchInput {\r\n query?: string;\r\n tags?: string[];\r\n permission?: 'auto' | 'confirm' | 'deny';\r\n mutating?: boolean;\r\n limit?: number;\r\n}\r\n\r\ninterface ToolSearchOutput {\r\n tools: {\r\n name: string;\r\n description: string;\r\n permission: string;\r\n mutating: boolean;\r\n }[];\r\n total: number;\r\n truncated: boolean;\r\n}\r\n\r\nexport const toolSearchTool: Tool<ToolSearchInput, ToolSearchOutput> = {\r\n name: 'tool_search',\r\n description:\r\n 'Search available tools by name, description, tags, permission level, or mutating flag.',\r\n usageHint:\r\n 'Set `query` for keyword search. `tags` to filter by category. `permission` to filter by required permission. `mutating` to filter by mutating flag.',\r\n permission: 'auto',\r\n mutating: false,\r\n timeoutMs: 1_000,\r\n inputSchema: {\r\n type: 'object',\r\n properties: {\r\n query: {\r\n type: 'string',\r\n description: 'Search query for tool name or description',\r\n },\r\n tags: {\r\n type: 'array',\r\n items: { type: 'string' },\r\n description: 'Filter by tags (e.g. \"filesystem\", \"network\", \"dev\")',\r\n },\r\n permission: {\r\n type: 'string',\r\n enum: ['auto', 'confirm', 'deny'],\r\n description: 'Filter by required permission level',\r\n },\r\n mutating: {\r\n type: 'boolean',\r\n description: 'Filter by mutating flag (true=filters that modify, false=read-only)',\r\n },\r\n limit: {\r\n type: 'integer',\r\n description: 'Maximum results to return (default: 20)',\r\n minimum: 1,\r\n maximum: 100,\r\n },\r\n },\r\n },\r\n async execute(input, ctx) {\r\n const limit = Math.min(input.limit ?? 20, 100);\r\n const tools = ctx.tools;\r\n const query = input.query?.toLowerCase() ?? '';\r\n\r\n const filtered = tools.filter((t: Tool) => {\r\n if (query && !t.name.toLowerCase().includes(query) && !t.description.toLowerCase().includes(query)) {\r\n return false;\r\n }\r\n if (input.permission && t.permission !== input.permission) {\r\n return false;\r\n }\r\n if (typeof input.mutating === 'boolean' && t.mutating !== input.mutating) {\r\n return false;\r\n }\r\n return true;\r\n });\r\n\r\n const results = filtered.slice(0, limit).map((t: Tool) => ({\r\n name: t.name,\r\n description: t.description,\r\n permission: t.permission,\r\n mutating: t.mutating,\r\n }));\r\n\r\n return {\r\n tools: results,\r\n total: filtered.length,\r\n truncated: filtered.length > limit,\r\n };\r\n },\r\n};"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Tool } from '@wrongstack/core';
|
|
2
|
+
|
|
3
|
+
interface ToolUseInput {
|
|
4
|
+
tool: string;
|
|
5
|
+
input: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface ToolUseOutput {
|
|
8
|
+
tool: string;
|
|
9
|
+
success: boolean;
|
|
10
|
+
result?: unknown;
|
|
11
|
+
error?: string;
|
|
12
|
+
executionMs: number;
|
|
13
|
+
}
|
|
14
|
+
declare const toolUseTool: Tool<ToolUseInput, ToolUseOutput>;
|
|
15
|
+
|
|
16
|
+
export { toolUseTool };
|