@wrongstack/tools 0.313.0 → 0.313.1
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.js +10 -4055
- package/dist/bash.js +9 -2308
- package/dist/batch-tool-use.js +2 -187
- package/dist/browser/index.js +25 -1339
- package/dist/builtin.js +69 -33949
- package/dist/chunk-2CTB3UK5.js +197 -0
- package/dist/chunk-2ME7ZWDD.js +1272 -0
- package/dist/chunk-2TFQDEPU.js +113 -0
- package/dist/chunk-2ZCJNKFE.js +315 -0
- package/dist/chunk-3PVYQFRQ.js +472 -0
- package/dist/chunk-3QMQBO5Z.js +89 -0
- package/dist/chunk-42AKKX7O.js +385 -0
- package/dist/chunk-42SKEETB.js +113 -0
- package/dist/chunk-4BHUSMNL.js +104 -0
- package/dist/chunk-4I4LWFOO.js +431 -0
- package/dist/chunk-553IQUMO.js +478 -0
- package/dist/chunk-55KF77OK.js +1944 -0
- package/dist/chunk-6HLZK37X.js +359 -0
- package/dist/chunk-6RNIFLG4.js +305 -0
- package/dist/chunk-A6BRWIXN.js +317 -0
- package/dist/chunk-AHHDWNXC.js +200 -0
- package/dist/chunk-B2CIOKWP.js +899 -0
- package/dist/chunk-BTSFTGIL.js +7 -0
- package/dist/chunk-D33S4RQG.js +222 -0
- package/dist/chunk-DIJKHSUO.js +134 -0
- package/dist/chunk-DPL47QGS.js +3515 -0
- package/dist/chunk-EMRGN4KM.js +170 -0
- package/dist/chunk-FGOABE4Z.js +955 -0
- package/dist/chunk-FW65TP4G.js +520 -0
- package/dist/chunk-GOIZNNOA.js +221 -0
- package/dist/chunk-H5MJUAA6.js +295 -0
- package/dist/chunk-H5OHH6F4.js +223 -0
- package/dist/chunk-HC5RM4WY.js +199 -0
- package/dist/chunk-HEQFMLZ7.js +190 -0
- package/dist/chunk-HFXSNKCV.js +196 -0
- package/dist/chunk-HXSBQ2SE.js +1723 -0
- package/dist/chunk-ILESNGNM.js +163 -0
- package/dist/chunk-INF5CGAO.js +137 -0
- package/dist/chunk-IWDFZ6XR.js +337 -0
- package/dist/chunk-IXMNTNW5.js +238 -0
- package/dist/chunk-J4SRJKBW.js +428 -0
- package/dist/chunk-J5SKD6LN.js +235 -0
- package/dist/chunk-JRJJX3L5.js +424 -0
- package/dist/chunk-KXNDHMUB.js +366 -0
- package/dist/chunk-LIJQMYYX.js +59 -0
- package/dist/chunk-MAN26PZ5.js +260 -0
- package/dist/chunk-MKRQMLZA.js +474 -0
- package/dist/chunk-NBDZMMG2.js +169 -0
- package/dist/chunk-NHA6BEIH.js +101 -0
- package/dist/chunk-OA6YJIWL.js +4412 -0
- package/dist/chunk-OZC255IC.js +2830 -0
- package/dist/chunk-PUR6WU2B.js +154 -0
- package/dist/chunk-Q5JPPCZC.js +12 -0
- package/dist/chunk-QBV725YG.js +128 -0
- package/dist/chunk-QHVW4AAM.js +892 -0
- package/dist/chunk-QNJ7AQ4B.js +1000 -0
- package/dist/chunk-RGISBZBD.js +231 -0
- package/dist/chunk-RJZQWEMS.js +84 -0
- package/dist/chunk-RP2ZA47V.js +15 -0
- package/dist/chunk-RXISBFR5.js +315 -0
- package/dist/chunk-S5CCLZL3.js +99 -0
- package/dist/chunk-TVTCSBJF.js +122 -0
- package/dist/chunk-U4D5S3VQ.js +21 -0
- package/dist/chunk-U4VAATKP.js +193 -0
- package/dist/chunk-UKU2ZX4C.js +203 -0
- package/dist/chunk-UNSKG6DC.js +159 -0
- package/dist/chunk-URFKEIHM.js +1091 -0
- package/dist/chunk-UTV7YAW7.js +178 -0
- package/dist/chunk-V43EQ6VR.js +68 -0
- package/dist/chunk-VB3MJGCV.js +610 -0
- package/dist/chunk-WHIIIREL.js +223 -0
- package/dist/chunk-XMIFYKUT.js +1371 -0
- package/dist/chunk-YF2RSV34.js +54 -0
- package/dist/chunk-Z6DAKQ3U.js +1 -0
- package/dist/chunk-ZIGAZFWE.js +522 -0
- package/dist/circuit-breaker.js +3 -191
- package/dist/codebase-index/index.js +84 -13688
- package/dist/codebase-index/parser-worker-script.js +8 -3995
- package/dist/codebase-index/project-server.js +60 -8548
- package/dist/codebase-index/worker.js +20 -8416
- package/dist/design.js +2 -299
- package/dist/diff.js +4 -256
- package/dist/document.js +4 -222
- package/dist/e2e.js +5 -476
- package/dist/edit.js +14 -10200
- package/dist/exec.js +16 -3131
- package/dist/fetch.js +8 -398
- package/dist/format.js +10 -3750
- package/dist/generic-parser-VUXDIAOZ.js +13 -0
- package/dist/git.js +4 -380
- package/dist/glob.js +6 -280
- package/dist/go-parser-6CA77WZ4.js +469 -0
- package/dist/grep.js +7 -604
- package/dist/index.js +318 -35387
- package/dist/install.js +10 -4091
- package/dist/json-parser-7YMDJSBJ.js +213 -0
- package/dist/json.js +4 -665
- package/dist/kanban.js +3 -2096
- package/dist/languages/index.js +23 -4664
- package/dist/legacy-bridge-7UKZT46G.js +18 -0
- package/dist/lint.js +10 -3706
- package/dist/logs.js +4 -287
- package/dist/memory.js +6 -215
- package/dist/mode.js +3 -99
- package/dist/outdated.js +4 -5170
- package/dist/pack.js +65 -33897
- package/dist/parser-dispatch-VPOFDO2U.js +14 -0
- package/dist/patch.js +13 -9935
- package/dist/plan.js +5 -3286
- package/dist/process-registry.js +8 -651
- package/dist/ps-slash.js +12 -1439
- package/dist/py-parser-GPM5VYRG.js +16 -0
- package/dist/read.js +13 -9816
- package/dist/replace.js +15 -10014
- package/dist/rs-parser-WVQ4KYCX.js +81 -0
- package/dist/scaffold.js +4 -253
- package/dist/search.js +5 -585
- package/dist/session-kanban.js +30 -972
- package/dist/skill.js +2 -215
- package/dist/task.js +5 -3410
- package/dist/test.js +10 -3773
- package/dist/todo.js +4 -2891
- package/dist/tool-help.js +3 -123
- package/dist/tool-search.js +3 -79
- package/dist/tool-tier.js +68 -33984
- package/dist/tool-use.js +2 -93
- package/dist/tree-sitter-parser-YCILHGZD.js +17 -0
- package/dist/tree.js +4 -288
- package/dist/ts-parser-YH4ZMWMH.js +232 -0
- package/dist/typecheck.js +10 -3753
- package/dist/win32.js +6 -60
- package/dist/write.js +14 -9882
- package/dist/yaml-parser-GFAOKV53.js +157 -0
- package/package.json +5 -5
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
compileUserRegex
|
|
3
|
+
} from "./chunk-Q5JPPCZC.js";
|
|
4
|
+
import {
|
|
5
|
+
safeResolveReal
|
|
6
|
+
} from "./chunk-D33S4RQG.js";
|
|
7
|
+
|
|
8
|
+
// src/logs.ts
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { buildChildEnv } from "@wrongstack/core/utils";
|
|
11
|
+
var logsTool = {
|
|
12
|
+
name: "logs",
|
|
13
|
+
category: "Logs",
|
|
14
|
+
description: "Read logs from files or Docker containers. Useful for debugging running applications.",
|
|
15
|
+
usageHint: "DEBUGGING TOOL \u2014 USE CAREFULLY IN AUTONOMOUS MODE:\n\n- Prefer `path` for local files or `service` for Docker containers.\n- Always use `filter` (regex) when possible to reduce noise and token usage.\n- `since` narrows Docker logs to a recent window.",
|
|
16
|
+
permission: "confirm",
|
|
17
|
+
mutating: false,
|
|
18
|
+
timeoutMs: 3e4,
|
|
19
|
+
maxOutputBytes: 262144,
|
|
20
|
+
capabilities: ["shell.restricted"],
|
|
21
|
+
icon: "logs",
|
|
22
|
+
inputSchema: {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
service: {
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Docker container name (passed to `docker logs`)"
|
|
28
|
+
},
|
|
29
|
+
path: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Path to log file (alternative to service)"
|
|
32
|
+
},
|
|
33
|
+
lines: {
|
|
34
|
+
type: "integer",
|
|
35
|
+
description: "Number of log lines to fetch (default: 100, 0 for all)",
|
|
36
|
+
minimum: 0,
|
|
37
|
+
maximum: 1e4
|
|
38
|
+
},
|
|
39
|
+
filter: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "Regex pattern to filter log lines"
|
|
42
|
+
},
|
|
43
|
+
since: {
|
|
44
|
+
type: "string",
|
|
45
|
+
enum: ["1h", "6h", "24h", "all"],
|
|
46
|
+
description: 'Only show Docker logs since duration (ignored for files; "all" = no limit)'
|
|
47
|
+
},
|
|
48
|
+
cwd: { type: "string", description: "Working directory (default: cwd)" }
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
async execute(input, ctx, opts) {
|
|
52
|
+
const cwd = input.cwd ? await safeResolveReal(input.cwd, ctx) : ctx.cwd;
|
|
53
|
+
const lines = input.lines ?? 100;
|
|
54
|
+
let filterRe = null;
|
|
55
|
+
if (input.filter) {
|
|
56
|
+
const compiled = compileUserRegex(input.filter, "i");
|
|
57
|
+
if (!compiled.ok) {
|
|
58
|
+
throw new Error(`logs: ${compiled.reason}`);
|
|
59
|
+
}
|
|
60
|
+
filterRe = compiled.regex;
|
|
61
|
+
}
|
|
62
|
+
if (input.service) {
|
|
63
|
+
return await dockerLogs(input.service, lines, filterRe, cwd, opts.signal, input.since);
|
|
64
|
+
}
|
|
65
|
+
if (input.path) {
|
|
66
|
+
return await fileLogs(await safeResolveReal(input.path, ctx), lines, filterRe);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
source: "none",
|
|
70
|
+
entries: [],
|
|
71
|
+
total: 0,
|
|
72
|
+
truncated: false,
|
|
73
|
+
stream_mode: false
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
async function dockerLogs(service, lines, filterRe, cwd, signal, since) {
|
|
78
|
+
const args = ["logs"];
|
|
79
|
+
if (lines > 0) args.push("--tail", String(lines));
|
|
80
|
+
if (since && since !== "all") {
|
|
81
|
+
const sinceMap = { "1h": "1h", "6h": "6h", "24h": "24h" };
|
|
82
|
+
args.push("--since", sinceMap[since] ?? "1h");
|
|
83
|
+
}
|
|
84
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:-]+$/.test(service)) {
|
|
85
|
+
return {
|
|
86
|
+
source: `docker:${service}`,
|
|
87
|
+
entries: [],
|
|
88
|
+
total: 0,
|
|
89
|
+
truncated: false,
|
|
90
|
+
stream_mode: false
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
args.push("--timestamps", service);
|
|
94
|
+
return new Promise((resolve) => {
|
|
95
|
+
let stdout = "";
|
|
96
|
+
let stderr = "";
|
|
97
|
+
const MAX = 2e5;
|
|
98
|
+
let settled = false;
|
|
99
|
+
const empty = () => ({
|
|
100
|
+
source: `docker:${service}`,
|
|
101
|
+
entries: [],
|
|
102
|
+
total: 0,
|
|
103
|
+
truncated: false,
|
|
104
|
+
stream_mode: false
|
|
105
|
+
});
|
|
106
|
+
const finish = (result) => {
|
|
107
|
+
if (settled) return;
|
|
108
|
+
settled = true;
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
resolve(result);
|
|
111
|
+
};
|
|
112
|
+
const child = spawn("docker", args, {
|
|
113
|
+
cwd,
|
|
114
|
+
signal,
|
|
115
|
+
env: buildChildEnv(),
|
|
116
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
117
|
+
windowsHide: true
|
|
118
|
+
});
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
child.kill("SIGTERM");
|
|
121
|
+
finish(empty());
|
|
122
|
+
}, DOCKER_LOGS_TIMEOUT_MS);
|
|
123
|
+
child.stdout?.on("data", (c) => {
|
|
124
|
+
if (stdout.length < MAX) stdout += c.toString();
|
|
125
|
+
});
|
|
126
|
+
child.stderr?.on("data", (c) => {
|
|
127
|
+
if (stderr.length < MAX) stderr += c.toString();
|
|
128
|
+
});
|
|
129
|
+
child.stdout?.on("error", (e) => {
|
|
130
|
+
console.log(
|
|
131
|
+
JSON.stringify({ level: "debug", event: "pipe_error", stream: "stdout", error: e.message })
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
child.stderr?.on("error", (e) => {
|
|
135
|
+
console.log(
|
|
136
|
+
JSON.stringify({ level: "debug", event: "pipe_error", stream: "stderr", error: e.message })
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
child.on("close", () => {
|
|
140
|
+
const output = stdout + stderr;
|
|
141
|
+
const entries = parseLogLines(output, filterRe);
|
|
142
|
+
finish({
|
|
143
|
+
source: `docker:${service}`,
|
|
144
|
+
entries,
|
|
145
|
+
total: entries.length,
|
|
146
|
+
truncated: output.length >= MAX,
|
|
147
|
+
stream_mode: false
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
child.on("error", () => finish(empty()));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
var DOCKER_LOGS_TIMEOUT_MS = 3e3;
|
|
154
|
+
var MAX_TAIL_LINES = 1e5;
|
|
155
|
+
async function fileLogs(path, lines, filterRe) {
|
|
156
|
+
const { createInterface } = await import("node:readline");
|
|
157
|
+
const { createReadStream } = await import("node:fs");
|
|
158
|
+
const entries = [];
|
|
159
|
+
const effLines = lines > 0 ? Math.min(lines, MAX_TAIL_LINES) : MAX_TAIL_LINES;
|
|
160
|
+
const window = new Array(effLines);
|
|
161
|
+
let writeIdx = 0;
|
|
162
|
+
let totalLines = 0;
|
|
163
|
+
const rl = createInterface({
|
|
164
|
+
input: createReadStream(path),
|
|
165
|
+
crlfDelay: Number.POSITIVE_INFINITY
|
|
166
|
+
});
|
|
167
|
+
for await (const line of rl) {
|
|
168
|
+
if (filterRe && !filterRe.test(line)) continue;
|
|
169
|
+
window[writeIdx] = line;
|
|
170
|
+
writeIdx = (writeIdx + 1) % effLines;
|
|
171
|
+
totalLines++;
|
|
172
|
+
}
|
|
173
|
+
const ordered = [];
|
|
174
|
+
const start = totalLines >= effLines ? writeIdx : 0;
|
|
175
|
+
const count = Math.min(totalLines, effLines);
|
|
176
|
+
for (let i = 0; i < count; i++) {
|
|
177
|
+
const v = window[(start + i) % effLines];
|
|
178
|
+
if (v !== void 0) ordered.push(v);
|
|
179
|
+
}
|
|
180
|
+
for (const line of ordered) {
|
|
181
|
+
const parsed = parseLine(line);
|
|
182
|
+
if (parsed) entries.push(parsed);
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
source: path,
|
|
186
|
+
entries,
|
|
187
|
+
total: entries.length,
|
|
188
|
+
truncated: totalLines > effLines,
|
|
189
|
+
stream_mode: false
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function parseLogLines(output, filterRe) {
|
|
193
|
+
const lines = output.split("\n").filter(Boolean);
|
|
194
|
+
const entries = [];
|
|
195
|
+
for (const line of lines) {
|
|
196
|
+
if (filterRe && !filterRe.test(line)) continue;
|
|
197
|
+
const parsed = parseLine(line);
|
|
198
|
+
if (parsed) entries.push(parsed);
|
|
199
|
+
}
|
|
200
|
+
return entries;
|
|
201
|
+
}
|
|
202
|
+
function parseLine(line) {
|
|
203
|
+
const tsRe = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?)\s+(?:\[?(\w+)\]?)\s*(.*)/;
|
|
204
|
+
const match = tsRe.exec(line);
|
|
205
|
+
if (match) {
|
|
206
|
+
return {
|
|
207
|
+
timestamp: match[1] ?? "",
|
|
208
|
+
level: match[2]?.toLowerCase() ?? "info",
|
|
209
|
+
message: match[3] ?? ""
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const levelRe = /(ERROR|WARN|INFO|DEBUG|TRACE)\s+(.*)/i;
|
|
213
|
+
const levelMatch = levelRe.exec(line);
|
|
214
|
+
if (levelMatch) {
|
|
215
|
+
return {
|
|
216
|
+
timestamp: "",
|
|
217
|
+
level: levelMatch[1]?.toLowerCase() ?? "info",
|
|
218
|
+
message: levelMatch[2] ?? line
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
timestamp: "",
|
|
223
|
+
level: "info",
|
|
224
|
+
message: line
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export {
|
|
229
|
+
logsTool
|
|
230
|
+
};
|
|
231
|
+
//# sourceMappingURL=chunk-RGISBZBD.js.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// src/tool-search.ts
|
|
2
|
+
var toolSearchTool = {
|
|
3
|
+
name: "tool_search",
|
|
4
|
+
category: "Meta",
|
|
5
|
+
description: "Search the catalog of available tools by name or description. Use this to discover which tool to use for a task. For the full schema and usage details of a specific tool, use `tool_help` instead.",
|
|
6
|
+
usageHint: "SELF-DISCOVERY TOOL:\n\n- Use when you need to find the right tool for a job.\n- `query` searches names and descriptions.\n- You can filter by `tags` (category), `permission`, or `mutating`.\n- Once you find the right tool name, use `tool_help` with that name for full schema details.\nCall this before guessing tool names. It helps you discover the best tool for the current situation.",
|
|
7
|
+
permission: "auto",
|
|
8
|
+
mutating: false,
|
|
9
|
+
timeoutMs: 1e3,
|
|
10
|
+
capabilities: ["tool.meta"],
|
|
11
|
+
icon: "meta",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
query: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Search query for tool name or description"
|
|
18
|
+
},
|
|
19
|
+
tags: {
|
|
20
|
+
type: "array",
|
|
21
|
+
items: { type: "string" },
|
|
22
|
+
description: 'Filter by tags (e.g. "filesystem", "network", "dev")'
|
|
23
|
+
},
|
|
24
|
+
permission: {
|
|
25
|
+
type: "string",
|
|
26
|
+
enum: ["auto", "confirm", "deny"],
|
|
27
|
+
description: "Filter by required permission level"
|
|
28
|
+
},
|
|
29
|
+
mutating: {
|
|
30
|
+
type: "boolean",
|
|
31
|
+
description: "Filter by mutating flag (true=filters that modify, false=read-only)"
|
|
32
|
+
},
|
|
33
|
+
limit: {
|
|
34
|
+
type: "integer",
|
|
35
|
+
description: "Maximum results to return (default: 20)",
|
|
36
|
+
minimum: 1,
|
|
37
|
+
maximum: 100
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
async execute(input, ctx) {
|
|
42
|
+
const limit = Math.min(input.limit ?? 20, 100);
|
|
43
|
+
const tools = ctx.catalogTools ?? ctx.tools;
|
|
44
|
+
const query = input.query?.toLowerCase() ?? "";
|
|
45
|
+
const filtered = tools.filter((t) => {
|
|
46
|
+
if (query && !t.name.toLowerCase().includes(query) && !t.description.toLowerCase().includes(query)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (input.tags && input.tags.length > 0) {
|
|
50
|
+
const toolCat = (t.category ?? "").toLowerCase();
|
|
51
|
+
if (!input.tags.some((tag) => toolCat.includes(tag.toLowerCase()))) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (input.permission && t.permission !== input.permission) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
if (typeof input.mutating === "boolean" && t.mutating !== input.mutating) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
});
|
|
63
|
+
const results = filtered.slice(0, limit).map((t) => ({
|
|
64
|
+
name: t.name,
|
|
65
|
+
description: t.description,
|
|
66
|
+
permission: t.permission,
|
|
67
|
+
mutating: t.mutating
|
|
68
|
+
}));
|
|
69
|
+
const totalAvailable = tools.length;
|
|
70
|
+
const hint = results.length === 0 && query ? `No tools matched "${input.query}". Use tool-help (without arguments) to see all ${totalAvailable} available tools.` : void 0;
|
|
71
|
+
return {
|
|
72
|
+
tools: results,
|
|
73
|
+
total: filtered.length,
|
|
74
|
+
truncated: filtered.length > limit,
|
|
75
|
+
...hint ? { hint } : {},
|
|
76
|
+
_available: totalAvailable
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
toolSearchTool
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=chunk-RJZQWEMS.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
builtinTools
|
|
3
|
+
} from "./chunk-URFKEIHM.js";
|
|
4
|
+
|
|
5
|
+
// src/pack.ts
|
|
6
|
+
var builtinToolsPack = {
|
|
7
|
+
name: "builtin-tools",
|
|
8
|
+
description: "The complete set of built-in tools that ship with WrongStack. Covers filesystem, execution, first-party browser automation, read-only E2E planning, networking, code quality, planning, and meta tools.",
|
|
9
|
+
tools: builtinTools
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
builtinToolsPack
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-RP2ZA47V.js.map
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COMMAND_OUTPUT_MAX_BYTES,
|
|
3
|
+
normalizeCommandOutput
|
|
4
|
+
} from "./chunk-D33S4RQG.js";
|
|
5
|
+
|
|
6
|
+
// src/git.ts
|
|
7
|
+
import { spawn } from "node:child_process";
|
|
8
|
+
import { statSync } from "node:fs";
|
|
9
|
+
import { dirname, resolve, sep } from "node:path";
|
|
10
|
+
import { assessCommitSafety } from "@wrongstack/core/coordination";
|
|
11
|
+
import { buildChildEnv } from "@wrongstack/core/utils";
|
|
12
|
+
var TIMEOUT_MS = 3e4;
|
|
13
|
+
var MAX_OUTPUT = 1e5;
|
|
14
|
+
var gitTool = {
|
|
15
|
+
name: "git",
|
|
16
|
+
category: "Git",
|
|
17
|
+
description: "Safe wrapper around common git operations. Supports status, log, diff, commit, branch, checkout, stash, push, pull, fetch, reset, worktree, etc. This is the preferred way to interact with git instead of using the raw `bash` or `exec` tools.",
|
|
18
|
+
usageHint: "ALWAYS prefer this tool over raw shell git commands.\n\nKey fields:\n- `command`: one of the supported subcommands (status, log, diff, commit, etc.)\n- Use `message` only for commit operations.\n- Use `files` array for operations that take paths (status, diff, add, etc.).\n- Non-mutating commands (status, log, diff, branch, fetch) are still permission:confirm for safety.\n- For `commit` in a possibly-shared working tree, pass an explicit `files` list scoped to what YOU changed. A bare commit (no `files`) includes ALL staged changes and may capture another agent's half-done work. Heed the `warning` field on the result.\nNever pass raw git flags through `args` for dangerous operations \u2014 use the structured fields.",
|
|
19
|
+
permission: "confirm",
|
|
20
|
+
icon: "git",
|
|
21
|
+
// Conservative: any of these may mutate. The non-mutating commands
|
|
22
|
+
// (status/log/diff/branch/fetch) are still gated on `permission: 'confirm'`
|
|
23
|
+
// and `MUTATING_SUBCOMMANDS` is consulted at runtime for per-call checks.
|
|
24
|
+
// WS-046: gives permission decisions something to key on.
|
|
25
|
+
// The git subcommand (status/commit/push) is what a trust rule needs to
|
|
26
|
+
// distinguish; `git status` and `git push --force` must not share a subject.
|
|
27
|
+
subjectKey: "command",
|
|
28
|
+
// `command` is an enum subcommand, so on its own it rendered the subject
|
|
29
|
+
// `"push"` — and one "always allow" then covered every push, to any branch,
|
|
30
|
+
// with or without `--force`. These are the fields that change what the call
|
|
31
|
+
// actually does, so the stored trust rule is as specific as the invocation
|
|
32
|
+
// the user approved.
|
|
33
|
+
subjectFields: ["branch", "force", "worktreeAction", "worktreePath", "newBranch"],
|
|
34
|
+
mutating: true,
|
|
35
|
+
capabilities: ["fs.write", "shell.restricted"],
|
|
36
|
+
timeoutMs: TIMEOUT_MS,
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: {
|
|
40
|
+
command: {
|
|
41
|
+
type: "string",
|
|
42
|
+
enum: [
|
|
43
|
+
"status",
|
|
44
|
+
"log",
|
|
45
|
+
"diff",
|
|
46
|
+
"commit",
|
|
47
|
+
"branch",
|
|
48
|
+
"checkout",
|
|
49
|
+
"stash",
|
|
50
|
+
"push",
|
|
51
|
+
"pull",
|
|
52
|
+
"fetch",
|
|
53
|
+
"reset",
|
|
54
|
+
"worktree"
|
|
55
|
+
],
|
|
56
|
+
description: "Git subcommand"
|
|
57
|
+
},
|
|
58
|
+
files: {
|
|
59
|
+
type: "string",
|
|
60
|
+
description: 'File(s) for status/diff: single path, comma-separated list, or "**/*.ts" glob'
|
|
61
|
+
},
|
|
62
|
+
message: { type: "string", description: "Commit message (required for commit)" },
|
|
63
|
+
branch: { type: "string", description: "Branch name for checkout/branch" },
|
|
64
|
+
format: {
|
|
65
|
+
type: "string",
|
|
66
|
+
enum: ["short", "oneline", "stat", "graph"],
|
|
67
|
+
description: "Log format (default: short)"
|
|
68
|
+
},
|
|
69
|
+
limit: { type: "integer", description: "Limit for log (default: 20)" },
|
|
70
|
+
dry_run: { type: "boolean", description: "For commit: show what would be committed" },
|
|
71
|
+
worktreeAction: {
|
|
72
|
+
type: "string",
|
|
73
|
+
enum: ["list", "add", "remove", "prune"],
|
|
74
|
+
description: "Worktree action: list, add, remove, prune"
|
|
75
|
+
},
|
|
76
|
+
worktreePath: {
|
|
77
|
+
type: "string",
|
|
78
|
+
description: 'Path for worktree add/remove (e.g. "../wt-feature-xyz")'
|
|
79
|
+
},
|
|
80
|
+
newBranch: {
|
|
81
|
+
type: "boolean",
|
|
82
|
+
description: "Create new branch when adding worktree"
|
|
83
|
+
},
|
|
84
|
+
force: {
|
|
85
|
+
type: "boolean",
|
|
86
|
+
description: "Force operation (e.g. worktree remove --force)"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
required: ["command"]
|
|
90
|
+
},
|
|
91
|
+
async execute(input, ctx, opts) {
|
|
92
|
+
if (!input?.command) throw new Error("git: command is required");
|
|
93
|
+
if (input.command === "commit" && !input.message) {
|
|
94
|
+
return {
|
|
95
|
+
command: "commit",
|
|
96
|
+
stdout: "",
|
|
97
|
+
stderr: "git commit requires a message (-m flag)",
|
|
98
|
+
exitCode: 1,
|
|
99
|
+
truncated: false
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const branchGuard = validateBranchInput(input);
|
|
103
|
+
if (branchGuard) return branchGuard;
|
|
104
|
+
if (input.command === "worktree") {
|
|
105
|
+
const guard = validateWorktreeInput(input, ctx.projectRoot);
|
|
106
|
+
if (guard) return guard;
|
|
107
|
+
}
|
|
108
|
+
const gitDir = findGitDir(ctx.cwd, ctx.projectRoot);
|
|
109
|
+
if (!gitDir) {
|
|
110
|
+
return {
|
|
111
|
+
command: input.command,
|
|
112
|
+
stdout: "",
|
|
113
|
+
stderr: "Not in a git repository (within project root)",
|
|
114
|
+
exitCode: 128,
|
|
115
|
+
truncated: false
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const args = buildArgs(input);
|
|
119
|
+
let safetyWarning;
|
|
120
|
+
if (input.command === "commit") {
|
|
121
|
+
try {
|
|
122
|
+
const report = await assessCommitSafety({
|
|
123
|
+
cwd: ctx.cwd,
|
|
124
|
+
projectRoot: ctx.projectRoot,
|
|
125
|
+
sessionId: ctx.session?.id,
|
|
126
|
+
signal: opts.signal
|
|
127
|
+
});
|
|
128
|
+
if (report.warning) {
|
|
129
|
+
const scopeNote = input.files ? "" : "\nNote: this commit has no explicit `files` list, so it will include ALL staged changes. Pass `files` to scope the commit to only what you changed.";
|
|
130
|
+
safetyWarning = report.warning + scopeNote;
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
let stagedDiff;
|
|
136
|
+
if (input.command === "commit" && !input.dry_run) {
|
|
137
|
+
try {
|
|
138
|
+
const diffResult = await runGit(["diff", "--cached"], gitDir, opts.signal);
|
|
139
|
+
if (diffResult.exitCode === 0) {
|
|
140
|
+
const MAX_DIFF = 2e4;
|
|
141
|
+
stagedDiff = diffResult.stdout.length > MAX_DIFF ? diffResult.stdout.slice(0, MAX_DIFF) + "\n\n... (diff truncated)" : diffResult.stdout;
|
|
142
|
+
}
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const result = await runGit(args, gitDir, opts.signal);
|
|
147
|
+
if (stagedDiff !== void 0) result.diff = stagedDiff;
|
|
148
|
+
if (safetyWarning !== void 0) result.warning = safetyWarning;
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
function validateBranchInput(input) {
|
|
153
|
+
const branch = input.branch;
|
|
154
|
+
if (branch === void 0) return null;
|
|
155
|
+
if (!branch.startsWith("-") && !branch.includes(" --")) return null;
|
|
156
|
+
return {
|
|
157
|
+
command: input.command,
|
|
158
|
+
stdout: "",
|
|
159
|
+
stderr: `unsafe branch name (parsed as a git option): ${branch}`,
|
|
160
|
+
exitCode: 1,
|
|
161
|
+
truncated: false
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function validateWorktreeInput(input, projectRoot) {
|
|
165
|
+
const reject = (stderr) => ({
|
|
166
|
+
command: "worktree",
|
|
167
|
+
stdout: "",
|
|
168
|
+
stderr,
|
|
169
|
+
exitCode: 1,
|
|
170
|
+
truncated: false
|
|
171
|
+
});
|
|
172
|
+
if (input.worktreePath?.startsWith("-")) {
|
|
173
|
+
return reject(`unsafe worktree path: ${input.worktreePath}`);
|
|
174
|
+
}
|
|
175
|
+
if ((input.worktreeAction === "add" || input.worktreeAction === "remove") && input.worktreePath) {
|
|
176
|
+
const root = resolve(projectRoot);
|
|
177
|
+
const abs = resolve(root, input.worktreePath);
|
|
178
|
+
if (abs !== root && !abs.startsWith(root + sep)) {
|
|
179
|
+
return reject(`unsafe worktree path (escapes project root): ${input.worktreePath}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
function findGitDir(cwd, projectRoot) {
|
|
185
|
+
const root = projectRoot;
|
|
186
|
+
let dir = cwd;
|
|
187
|
+
for (let i = 0; i < 20; i++) {
|
|
188
|
+
try {
|
|
189
|
+
const stat = statSync(`${dir}/.git`);
|
|
190
|
+
if (stat.isDirectory() || stat.isFile()) return dir;
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
if (dir === root) break;
|
|
194
|
+
const parent = dirname(dir);
|
|
195
|
+
if (parent === dir) break;
|
|
196
|
+
dir = parent;
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
function buildArgs(input) {
|
|
201
|
+
const limit = input.limit ?? 20;
|
|
202
|
+
const files = input.files ? (Array.isArray(input.files) ? input.files : input.files.split(",")).map((s) => s.trim()).filter(Boolean) : [];
|
|
203
|
+
switch (input.command) {
|
|
204
|
+
case "status":
|
|
205
|
+
return ["status", ...files.length ? ["--", ...files] : []];
|
|
206
|
+
case "log":
|
|
207
|
+
return [
|
|
208
|
+
"log",
|
|
209
|
+
`--max-count=${limit}`,
|
|
210
|
+
...input.format === "oneline" ? ["--oneline"] : [],
|
|
211
|
+
...input.format === "stat" ? ["--stat"] : [],
|
|
212
|
+
...input.format === "graph" ? ["--oneline", "--graph", "--decorate"] : [],
|
|
213
|
+
...input.format === "short" || !input.format ? [] : []
|
|
214
|
+
];
|
|
215
|
+
case "diff":
|
|
216
|
+
return ["diff", "--no-color", ...files.length ? ["--", ...files] : []];
|
|
217
|
+
case "commit":
|
|
218
|
+
return [
|
|
219
|
+
"commit",
|
|
220
|
+
...input.dry_run ? ["--dry-run", "--porcelain"] : [],
|
|
221
|
+
...input.message ? ["-m", input.message] : [],
|
|
222
|
+
...files.length ? ["--", ...files] : []
|
|
223
|
+
];
|
|
224
|
+
case "branch":
|
|
225
|
+
return input.branch ? [
|
|
226
|
+
"branch",
|
|
227
|
+
...input.branch.startsWith("-") || input.branch.includes(" --") ? [] : [input.branch]
|
|
228
|
+
] : ["branch"];
|
|
229
|
+
case "checkout":
|
|
230
|
+
if (files.length) return ["checkout", "--", ...files];
|
|
231
|
+
return input.branch ? ["checkout", input.branch, "--"] : ["checkout"];
|
|
232
|
+
case "stash":
|
|
233
|
+
return input.message ? ["stash", "push", "-m", input.message] : ["stash", "push"];
|
|
234
|
+
case "push":
|
|
235
|
+
return ["push"];
|
|
236
|
+
case "pull":
|
|
237
|
+
return ["pull"];
|
|
238
|
+
case "fetch":
|
|
239
|
+
return ["fetch", ...input.branch ? [input.branch] : ["--all"]];
|
|
240
|
+
case "reset":
|
|
241
|
+
return ["reset", ...files.length ? ["--", ...files] : []];
|
|
242
|
+
case "worktree":
|
|
243
|
+
switch (input.worktreeAction) {
|
|
244
|
+
case "list":
|
|
245
|
+
return ["worktree", "list"];
|
|
246
|
+
case "add": {
|
|
247
|
+
if (!input.worktreePath) return ["worktree", "list"];
|
|
248
|
+
const add = ["worktree", "add"];
|
|
249
|
+
if (input.newBranch && input.branch) add.push("-b", input.branch);
|
|
250
|
+
add.push(input.worktreePath);
|
|
251
|
+
if (!input.newBranch && input.branch) add.push(input.branch);
|
|
252
|
+
return add;
|
|
253
|
+
}
|
|
254
|
+
case "remove":
|
|
255
|
+
return [
|
|
256
|
+
"worktree",
|
|
257
|
+
"remove",
|
|
258
|
+
...input.force ? ["--force"] : [],
|
|
259
|
+
input.worktreePath ?? ""
|
|
260
|
+
].filter(Boolean);
|
|
261
|
+
case "prune":
|
|
262
|
+
return ["worktree", "prune"];
|
|
263
|
+
default:
|
|
264
|
+
return ["worktree", "list"];
|
|
265
|
+
}
|
|
266
|
+
default:
|
|
267
|
+
return [input.command];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function runGit(args, cwd, signal) {
|
|
271
|
+
return new Promise((resolve2) => {
|
|
272
|
+
let stdout = "";
|
|
273
|
+
let stderr = "";
|
|
274
|
+
const child = spawn("git", args, {
|
|
275
|
+
cwd,
|
|
276
|
+
signal,
|
|
277
|
+
env: buildChildEnv(),
|
|
278
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
279
|
+
windowsHide: true
|
|
280
|
+
});
|
|
281
|
+
child.stdout?.on("data", (chunk) => {
|
|
282
|
+
if (stdout.length < MAX_OUTPUT) {
|
|
283
|
+
stdout += chunk.toString();
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
child.stderr?.on("data", (chunk) => {
|
|
287
|
+
if (stderr.length < MAX_OUTPUT) {
|
|
288
|
+
stderr += chunk.toString();
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
child.on("error", (err) => {
|
|
292
|
+
resolve2({
|
|
293
|
+
command: args[0],
|
|
294
|
+
stdout: normalizeCommandOutput(stdout),
|
|
295
|
+
stderr: err.message,
|
|
296
|
+
exitCode: 1,
|
|
297
|
+
truncated: Buffer.byteLength(stdout, "utf8") > COMMAND_OUTPUT_MAX_BYTES
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
child.on("close", (code) => {
|
|
301
|
+
resolve2({
|
|
302
|
+
command: args[0],
|
|
303
|
+
stdout: normalizeCommandOutput(stdout),
|
|
304
|
+
stderr: normalizeCommandOutput(stderr),
|
|
305
|
+
exitCode: code ?? 1,
|
|
306
|
+
truncated: Buffer.byteLength(stdout, "utf8") > COMMAND_OUTPUT_MAX_BYTES || Buffer.byteLength(stderr, "utf8") > COMMAND_OUTPUT_MAX_BYTES
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export {
|
|
313
|
+
gitTool
|
|
314
|
+
};
|
|
315
|
+
//# sourceMappingURL=chunk-RXISBFR5.js.map
|