@wrongstack/tools 0.313.0 → 0.316.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/_edit-match.d.ts +3 -2
- package/dist/_output-spool.d.ts +4 -3
- package/dist/_shell-pick.d.ts +2 -1
- package/dist/_spawn-stream.d.ts +2 -1
- package/dist/_syntax-check.d.ts +2 -1
- package/dist/audit.js +10 -4055
- package/dist/bash-kill-guard.d.ts +3 -6
- package/dist/bash.js +9 -2308
- package/dist/batch-tool-use.js +2 -187
- package/dist/browser/index.js +25 -1339
- package/dist/browser/network-guard-proxy.d.ts +2 -1
- package/dist/builtin.js +69 -33949
- package/dist/chunk-22B7GE5T.js +260 -0
- package/dist/chunk-2VSZC6QM.js +113 -0
- package/dist/chunk-3PVYQFRQ.js +472 -0
- package/dist/chunk-42BHI7TN.js +337 -0
- package/dist/chunk-4BHUSMNL.js +104 -0
- package/dist/chunk-4I4LWFOO.js +431 -0
- package/dist/chunk-4UESMQDP.js +122 -0
- package/dist/chunk-553IQUMO.js +478 -0
- package/dist/chunk-5H4GSJAI.js +223 -0
- package/dist/chunk-6RNIFLG4.js +305 -0
- package/dist/chunk-7EY5DCRO.js +434 -0
- package/dist/chunk-A6BRWIXN.js +317 -0
- package/dist/chunk-AHHDWNXC.js +200 -0
- package/dist/chunk-BSLVR56S.js +199 -0
- package/dist/chunk-BTSFTGIL.js +7 -0
- package/dist/chunk-D33S4RQG.js +222 -0
- package/dist/chunk-DA4KNE2H.js +4412 -0
- package/dist/chunk-DR7JOQTC.js +520 -0
- package/dist/chunk-EEOFQDT6.js +898 -0
- package/dist/chunk-EJWSCQ6D.js +137 -0
- package/dist/chunk-EMRGN4KM.js +170 -0
- package/dist/chunk-FQZOHLG3.js +89 -0
- package/dist/chunk-GOIZNNOA.js +221 -0
- package/dist/chunk-HFXSNKCV.js +196 -0
- package/dist/chunk-HYX2TZ7O.js +1272 -0
- package/dist/chunk-I64BS3VC.js +15 -0
- package/dist/chunk-IVWV2UM6.js +955 -0
- package/dist/chunk-IXMNTNW5.js +238 -0
- package/dist/chunk-IYK7XGDZ.js +892 -0
- package/dist/chunk-J5SKD6LN.js +235 -0
- package/dist/chunk-JNNVRHMV.js +2111 -0
- package/dist/chunk-JOHXDF3D.js +295 -0
- package/dist/chunk-JRJJX3L5.js +424 -0
- package/dist/chunk-K3WNSHUF.js +1371 -0
- package/dist/chunk-L25CVUVR.js +2830 -0
- package/dist/chunk-LIJQMYYX.js +59 -0
- package/dist/chunk-LWKUTMD5.js +197 -0
- package/dist/chunk-MQX2KXVW.js +54 -0
- package/dist/chunk-MZZN7VCD.js +359 -0
- package/dist/chunk-NBDZMMG2.js +169 -0
- package/dist/chunk-NKJW5GFO.js +366 -0
- package/dist/chunk-NKNOBUBU.js +522 -0
- package/dist/chunk-O4MBV4AX.js +134 -0
- package/dist/chunk-OUBDL3WH.js +3515 -0
- package/dist/chunk-PQKK5JH7.js +101 -0
- package/dist/chunk-PY2IOS7C.js +1000 -0
- package/dist/chunk-Q5JPPCZC.js +12 -0
- package/dist/chunk-QBV725YG.js +128 -0
- package/dist/chunk-QZQSPUBF.js +315 -0
- package/dist/chunk-RGISBZBD.js +231 -0
- package/dist/chunk-RJZQWEMS.js +84 -0
- package/dist/chunk-RXISBFR5.js +315 -0
- package/dist/chunk-S5CCLZL3.js +99 -0
- package/dist/chunk-SDLVH5RZ.js +178 -0
- package/dist/chunk-T2F4S7U4.js +1723 -0
- package/dist/chunk-TEBQ4VPZ.js +163 -0
- package/dist/chunk-U4D5S3VQ.js +21 -0
- package/dist/chunk-U4VAATKP.js +193 -0
- package/dist/chunk-UCYQTZ7F.js +113 -0
- package/dist/chunk-UKU2ZX4C.js +203 -0
- package/dist/chunk-UNSKG6DC.js +159 -0
- package/dist/chunk-V43EQ6VR.js +68 -0
- package/dist/chunk-VB3MJGCV.js +610 -0
- package/dist/chunk-VFKPWSOX.js +154 -0
- package/dist/chunk-VJNHFZ7J.js +190 -0
- package/dist/chunk-VXECAJJ7.js +1091 -0
- package/dist/chunk-WHIIIREL.js +223 -0
- package/dist/chunk-Z6DAKQ3U.js +1 -0
- package/dist/chunk-ZJQ4IGXK.js +474 -0
- package/dist/chunk-ZLTFLC25.js +385 -0
- package/dist/circuit-breaker.js +3 -191
- package/dist/codebase-index/ast-invariant-engine.d.ts +5 -4
- package/dist/codebase-index/binary-frame.d.ts +0 -2
- package/dist/codebase-index/bm25.d.ts +1 -1
- package/dist/codebase-index/circuit-breaker.d.ts +2 -1
- package/dist/codebase-index/codebase-ast-replace-tool.d.ts +3 -2
- package/dist/codebase-index/codebase-impact-analysis-tool.d.ts +4 -3
- package/dist/codebase-index/codebase-invariant-check-tool.d.ts +3 -2
- package/dist/codebase-index/codebase-repo-map-tool.d.ts +3 -2
- package/dist/codebase-index/codebase-skeleton-tool.d.ts +3 -2
- package/dist/codebase-index/codebase-targeted-test-tool.d.ts +3 -2
- package/dist/codebase-index/content-hash.d.ts +0 -2
- package/dist/codebase-index/import-extractor.d.ts +0 -13
- package/dist/codebase-index/index-service.d.ts +1 -1
- package/dist/codebase-index/index.js +84 -13688
- package/dist/codebase-index/languages.d.ts +2 -1
- package/dist/codebase-index/module-roots.d.ts +3 -2
- package/dist/codebase-index/parser-batch.d.ts +0 -5
- package/dist/codebase-index/parser-dispatch.d.ts +2 -1
- package/dist/codebase-index/parser-output.d.ts +4 -3
- package/dist/codebase-index/parser-worker-pool.d.ts +0 -2
- package/dist/codebase-index/parser-worker-script.d.ts +1 -16
- package/dist/codebase-index/parser-worker-script.js +8 -3995
- package/dist/codebase-index/project-server-client-state.d.ts +2 -2
- package/dist/codebase-index/project-server-endpoint.d.ts +0 -15
- package/dist/codebase-index/project-server.js +60 -8548
- package/dist/codebase-index/tree-sitter/visitor.d.ts +2 -1
- package/dist/codebase-index/tree-sitter-parser.d.ts +0 -2
- package/dist/codebase-index/ts-parser.d.ts +1 -1
- package/dist/codebase-index/vector-search.d.ts +2 -1
- package/dist/codebase-index/wal-maintenance.d.ts +3 -2
- package/dist/codebase-index/worker.js +20 -8416
- package/dist/codebase-index/writer-admin.d.ts +0 -1
- package/dist/codebase-index/writer-search.d.ts +0 -9
- 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-JXYKJHRC.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-IBHZ4BZC.js +213 -0
- package/dist/json.js +4 -665
- package/dist/kanban-contract-actions.d.ts +1 -1
- package/dist/kanban-detail-actions.d.ts +2 -1
- package/dist/kanban-presence.d.ts +2 -1
- package/dist/kanban-serializer.d.ts +0 -8
- package/dist/kanban-split-task-handler.d.ts +2 -2
- package/dist/kanban-tool-types.d.ts +2 -1
- package/dist/kanban.js +3 -2096
- package/dist/languages/diagnostics.d.ts +2 -1
- package/dist/languages/index.js +23 -4664
- package/dist/languages/legacy-bridge.d.ts +3 -2
- package/dist/languages/types.d.ts +2 -1
- package/dist/legacy-bridge-7M6QLUQN.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-QH4XPGG6.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/pwsh.d.ts +0 -1
- package/dist/py-parser-IS4HKYMF.js +16 -0
- package/dist/read.js +13 -9816
- package/dist/replace.js +15 -10014
- package/dist/rs-parser-XHUUO2KZ.js +81 -0
- package/dist/scaffold.js +4 -253
- package/dist/search.js +5 -585
- package/dist/session-kanban-sync.d.ts +0 -6
- package/dist/session-kanban.js +30 -972
- package/dist/skill.js +2 -215
- package/dist/spawn-background.d.ts +1 -1
- 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-AIERW3YI.js +15 -0
- package/dist/tree.js +4 -288
- package/dist/ts-parser-RCTYKSVI.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-4SAXV3PL.js +157 -0
- package/package.json +5 -5
|
@@ -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,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
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/tool-use.ts
|
|
2
|
+
import {
|
|
3
|
+
GOVERNED_TOOL_EXECUTOR_META_KEY
|
|
4
|
+
} from "@wrongstack/core/types";
|
|
5
|
+
var toolUseTool = {
|
|
6
|
+
name: "tool_use",
|
|
7
|
+
category: "Meta",
|
|
8
|
+
description: "Directly execute any registered tool by its exact name, bypassing normal discovery. This is a powerful meta-tool intended for cases where the agent has a clear plan and knows precisely which tool to invoke.",
|
|
9
|
+
usageHint: "ADVANCED META TOOL \u2014 USE WITH CARE:\n\n- Only use when you are certain of the exact tool name and its expected input shape.\n- Prefer using the normal tool calling mechanism when possible.\n- Very useful in batch-tool-use or when orchestrating complex workflows programmatically.\n- The call still goes through full permission checks and capability validation.",
|
|
10
|
+
permission: "confirm",
|
|
11
|
+
// WS-046: gives permission decisions something to key on.
|
|
12
|
+
// The tool being invoked through this indirection — the whole point of a
|
|
13
|
+
// permission decision here is WHICH tool is being reached.
|
|
14
|
+
subjectKey: "tool",
|
|
15
|
+
mutating: true,
|
|
16
|
+
timeoutMs: 6e4,
|
|
17
|
+
capabilities: ["tool.mutate.any"],
|
|
18
|
+
icon: "meta",
|
|
19
|
+
inputSchema: {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
tool: {
|
|
23
|
+
type: "string",
|
|
24
|
+
description: 'The exact registered name of the tool to invoke (e.g. "bash", "read", "codebase-search").'
|
|
25
|
+
},
|
|
26
|
+
input: {
|
|
27
|
+
type: "object",
|
|
28
|
+
description: "The input object matching the target tool's inputSchema."
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
required: ["tool"]
|
|
32
|
+
},
|
|
33
|
+
async execute(input, ctx) {
|
|
34
|
+
const start = Date.now();
|
|
35
|
+
if (!input?.tool) {
|
|
36
|
+
return {
|
|
37
|
+
tool: "unknown",
|
|
38
|
+
success: false,
|
|
39
|
+
error: "tool_use: tool name is required",
|
|
40
|
+
executionMs: 0
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const tool = (ctx.catalogTools ?? ctx.tools).find((t) => t.name === input.tool);
|
|
44
|
+
if (!tool) {
|
|
45
|
+
return {
|
|
46
|
+
tool: input.tool,
|
|
47
|
+
success: false,
|
|
48
|
+
error: `tool_use: tool "${input.tool}" not found`,
|
|
49
|
+
executionMs: Date.now() - start
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (tool.name === toolUseTool.name) {
|
|
53
|
+
return {
|
|
54
|
+
tool: input.tool,
|
|
55
|
+
success: false,
|
|
56
|
+
error: "tool_use: recursive meta-tool execution is not allowed",
|
|
57
|
+
executionMs: Date.now() - start
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (tool.permission === "deny") {
|
|
61
|
+
return {
|
|
62
|
+
tool: input.tool,
|
|
63
|
+
success: false,
|
|
64
|
+
error: `tool_use: tool "${input.tool}" is denied by policy`,
|
|
65
|
+
executionMs: Date.now() - start
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const governedExecute = ctx.meta[GOVERNED_TOOL_EXECUTOR_META_KEY];
|
|
69
|
+
if (typeof governedExecute !== "function") {
|
|
70
|
+
return {
|
|
71
|
+
tool: input.tool,
|
|
72
|
+
success: false,
|
|
73
|
+
error: "tool_use: governed nested execution is unavailable; call the tool directly",
|
|
74
|
+
executionMs: Date.now() - start
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const result = await governedExecute(input.tool, input.input ?? {});
|
|
79
|
+
return {
|
|
80
|
+
tool: input.tool,
|
|
81
|
+
success: result.success,
|
|
82
|
+
...result.success ? { result: result.result } : { error: result.error ?? "nested tool failed" },
|
|
83
|
+
executionMs: Date.now() - start
|
|
84
|
+
};
|
|
85
|
+
} catch (e) {
|
|
86
|
+
return {
|
|
87
|
+
tool: input.tool,
|
|
88
|
+
success: false,
|
|
89
|
+
error: e instanceof Error ? e.message : String(e),
|
|
90
|
+
executionMs: Date.now() - start
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export {
|
|
97
|
+
toolUseTool
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=chunk-S5CCLZL3.js.map
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tryLegacyCodeOperation
|
|
3
|
+
} from "./chunk-PQKK5JH7.js";
|
|
4
|
+
import {
|
|
5
|
+
spawnStream
|
|
6
|
+
} from "./chunk-22B7GE5T.js";
|
|
7
|
+
import {
|
|
8
|
+
normalizeCommandOutput,
|
|
9
|
+
safeResolveReal
|
|
10
|
+
} from "./chunk-D33S4RQG.js";
|
|
11
|
+
|
|
12
|
+
// src/format.ts
|
|
13
|
+
var formatTool = {
|
|
14
|
+
name: "format",
|
|
15
|
+
category: "Code Quality",
|
|
16
|
+
description: "Format source files according to project style (Biome). Can also run in check-only mode.",
|
|
17
|
+
usageHint: "RUN REGULARLY:\n\n- Use on changed files before committing.\n- `check: true` verifies formatting without making changes (useful in CI-like flows).\nThis project has very consistent formatting expectations. Always ensure your changes are formatted.",
|
|
18
|
+
permission: "confirm",
|
|
19
|
+
// WS-046: gives permission decisions something to key on.
|
|
20
|
+
// The files being rewritten are the subject; the fixer is how, not what.
|
|
21
|
+
subjectKey: "files",
|
|
22
|
+
mutating: true,
|
|
23
|
+
capabilities: ["fs.write", "shell.restricted"],
|
|
24
|
+
icon: "code",
|
|
25
|
+
timeoutMs: 6e4,
|
|
26
|
+
inputSchema: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
files: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description: "Files/patterns: single path, comma-separated list, or glob"
|
|
32
|
+
},
|
|
33
|
+
fixer: {
|
|
34
|
+
type: "string",
|
|
35
|
+
enum: ["biome", "prettier", "auto"],
|
|
36
|
+
description: "Formatter to use (default: auto-detect)"
|
|
37
|
+
},
|
|
38
|
+
check: {
|
|
39
|
+
type: "boolean",
|
|
40
|
+
description: "Verify only, do not modify files (default: false)"
|
|
41
|
+
},
|
|
42
|
+
cwd: { type: "string", description: "Working directory (default: cwd)" }
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
async execute(input, ctx, opts) {
|
|
46
|
+
let final;
|
|
47
|
+
const executeStream = formatTool.executeStream;
|
|
48
|
+
if (!executeStream) throw new Error("formatTool: stream execution unavailable");
|
|
49
|
+
for await (const ev of executeStream(input, ctx, opts)) {
|
|
50
|
+
if (ev.type === "final") final = ev.output;
|
|
51
|
+
}
|
|
52
|
+
if (!final) throw new Error("format: stream ended without final event");
|
|
53
|
+
return final;
|
|
54
|
+
},
|
|
55
|
+
async *executeStream(input, ctx, opts) {
|
|
56
|
+
const cwd = input.cwd ? await safeResolveReal(input.cwd, ctx) : ctx.cwd;
|
|
57
|
+
const fixer = input.fixer ?? "auto";
|
|
58
|
+
if (fixer === "auto" && !input.files) {
|
|
59
|
+
const op = input.check ? "format-check" : "format-write";
|
|
60
|
+
const bridge = await tryLegacyCodeOperation(op, {
|
|
61
|
+
cwd,
|
|
62
|
+
projectRoot: ctx.projectRoot,
|
|
63
|
+
signal: opts.signal
|
|
64
|
+
});
|
|
65
|
+
if (bridge?.run) {
|
|
66
|
+
const run = bridge.run;
|
|
67
|
+
yield {
|
|
68
|
+
type: "final",
|
|
69
|
+
output: {
|
|
70
|
+
fixer: bridge.language,
|
|
71
|
+
// Language-bridge runs don't report per-file counts.
|
|
72
|
+
files_checked: void 0,
|
|
73
|
+
files_changed: void 0,
|
|
74
|
+
output: normalizeCommandOutput(run.output || run.error || ""),
|
|
75
|
+
truncated: run.truncated
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const detected = fixer === "auto" ? await detectFixer(cwd) : fixer;
|
|
82
|
+
if (!detected) {
|
|
83
|
+
yield {
|
|
84
|
+
type: "final",
|
|
85
|
+
output: {
|
|
86
|
+
fixer: "none",
|
|
87
|
+
files_checked: 0,
|
|
88
|
+
files_changed: 0,
|
|
89
|
+
output: "No formatter found (biome.json, .prettierrc)",
|
|
90
|
+
truncated: false
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
yield {
|
|
96
|
+
type: "log",
|
|
97
|
+
text: `Running ${detected}\u2026`,
|
|
98
|
+
data: { fixer: detected, check: !!input.check }
|
|
99
|
+
};
|
|
100
|
+
const fileList = input.files ? (Array.isArray(input.files) ? input.files : input.files.split(",")).map((f) => f.trim()) : [];
|
|
101
|
+
let args;
|
|
102
|
+
if (detected === "prettier") {
|
|
103
|
+
args = [input.check ? "--check" : "--write"];
|
|
104
|
+
args.push(...fileList.length > 0 ? fileList : ["."]);
|
|
105
|
+
} else {
|
|
106
|
+
args = ["format", input.check ? "--check" : "--write"];
|
|
107
|
+
if (fileList.length > 0) args.push("--", ...fileList);
|
|
108
|
+
}
|
|
109
|
+
const result = yield* spawnStream({
|
|
110
|
+
cmd: detected,
|
|
111
|
+
args,
|
|
112
|
+
cwd,
|
|
113
|
+
signal: opts.signal,
|
|
114
|
+
maxBytes: 1e5
|
|
115
|
+
});
|
|
116
|
+
const combinedOut = `${result.stdout}
|
|
117
|
+
${result.stderr}`;
|
|
118
|
+
const counts = parseFormatterCounts(detected, combinedOut);
|
|
119
|
+
yield {
|
|
120
|
+
type: "final",
|
|
121
|
+
output: {
|
|
122
|
+
fixer: detected,
|
|
123
|
+
files_checked: counts.checked,
|
|
124
|
+
files_changed: counts.changed,
|
|
125
|
+
output: normalizeCommandOutput(result.stdout || result.stderr || result.error || ""),
|
|
126
|
+
truncated: result.truncated
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
function parseFormatterCounts(fixer, output) {
|
|
132
|
+
if (fixer !== "biome") return { checked: void 0, changed: void 0 };
|
|
133
|
+
const checkedMatch = /\b(?:Checked|Formatted)\s+(\d+)\s+files?\b/i.exec(output);
|
|
134
|
+
const changedMatch = /\bFixed\s+(\d+)\s+files?\b/i.exec(output);
|
|
135
|
+
return {
|
|
136
|
+
checked: checkedMatch?.[1] !== void 0 ? Number(checkedMatch[1]) : void 0,
|
|
137
|
+
changed: changedMatch?.[1] !== void 0 ? Number(changedMatch[1]) : void 0
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async function detectFixer(cwd) {
|
|
141
|
+
const fs = await import("node:fs/promises");
|
|
142
|
+
const exists = async (file) => {
|
|
143
|
+
try {
|
|
144
|
+
await fs.stat(`${cwd}/${file}`);
|
|
145
|
+
return true;
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
if (await exists("biome.json") || await exists("biome.jsonc")) return "biome";
|
|
151
|
+
const PRETTIER_CONFIGS = [
|
|
152
|
+
".prettierrc",
|
|
153
|
+
".prettierrc.json",
|
|
154
|
+
".prettierrc.yml",
|
|
155
|
+
".prettierrc.yaml",
|
|
156
|
+
".prettierrc.js",
|
|
157
|
+
".prettierrc.cjs",
|
|
158
|
+
".prettierrc.mjs",
|
|
159
|
+
"prettier.config.js",
|
|
160
|
+
"prettier.config.cjs",
|
|
161
|
+
"prettier.config.mjs"
|
|
162
|
+
];
|
|
163
|
+
for (const cfg of PRETTIER_CONFIGS) {
|
|
164
|
+
if (await exists(cfg)) return "prettier";
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const raw = await fs.readFile(`${cwd}/package.json`, "utf8");
|
|
168
|
+
const pkg = JSON.parse(raw);
|
|
169
|
+
if (pkg["prettier"] !== void 0) return "prettier";
|
|
170
|
+
} catch {
|
|
171
|
+
}
|
|
172
|
+
return "biome";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export {
|
|
176
|
+
formatTool
|
|
177
|
+
};
|
|
178
|
+
//# sourceMappingURL=chunk-SDLVH5RZ.js.map
|