@wrongstack/tools 0.260.0 → 0.265.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 +154 -10
- package/dist/audit.js.map +1 -1
- package/dist/bash.js +138 -2
- package/dist/bash.js.map +1 -1
- package/dist/batch-tool-use.js +1 -0
- package/dist/batch-tool-use.js.map +1 -1
- package/dist/builtin.d.ts +20 -1
- package/dist/builtin.js +674 -333
- package/dist/builtin.js.map +1 -1
- package/dist/circuit-breaker.d.ts +20 -0
- package/dist/circuit-breaker.js +40 -2
- package/dist/circuit-breaker.js.map +1 -1
- package/dist/codebase-index/index.d.ts +16 -0
- package/dist/codebase-index/index.js +62 -27
- package/dist/codebase-index/index.js.map +1 -1
- package/dist/codebase-index/worker.js +59 -27
- package/dist/codebase-index/worker.js.map +1 -1
- package/dist/diff.js +14 -6
- package/dist/diff.js.map +1 -1
- package/dist/document.js +18 -11
- package/dist/document.js.map +1 -1
- package/dist/edit.js +22 -14
- package/dist/edit.js.map +1 -1
- package/dist/exec.js +140 -3
- package/dist/exec.js.map +1 -1
- package/dist/fetch.d.ts +19 -1
- package/dist/fetch.js +2 -1
- package/dist/fetch.js.map +1 -1
- package/dist/format.js +153 -10
- package/dist/format.js.map +1 -1
- package/dist/git.js +1 -0
- package/dist/git.js.map +1 -1
- package/dist/glob.js +14 -6
- package/dist/glob.js.map +1 -1
- package/dist/grep.js +14 -6
- package/dist/grep.js.map +1 -1
- package/dist/index.d.ts +55 -3
- package/dist/index.js +833 -336
- package/dist/index.js.map +1 -1
- package/dist/install.js +154 -10
- package/dist/install.js.map +1 -1
- package/dist/json.js +2 -0
- package/dist/json.js.map +1 -1
- package/dist/lint.js +153 -10
- package/dist/lint.js.map +1 -1
- package/dist/logs.js +14 -6
- package/dist/logs.js.map +1 -1
- package/dist/memory.js +1 -0
- package/dist/memory.js.map +1 -1
- package/dist/mode.js +1 -0
- package/dist/mode.js.map +1 -1
- package/dist/outdated.js +16 -7
- package/dist/outdated.js.map +1 -1
- package/dist/pack.js +643 -332
- package/dist/pack.js.map +1 -1
- package/dist/patch.js +14 -6
- package/dist/patch.js.map +1 -1
- package/dist/process-registry.d.ts +56 -2
- package/dist/process-registry.js +138 -3
- package/dist/process-registry.js.map +1 -1
- package/dist/read.js +24 -18
- package/dist/read.js.map +1 -1
- package/dist/replace.js +14 -6
- package/dist/replace.js.map +1 -1
- package/dist/scaffold.js +14 -6
- package/dist/scaffold.js.map +1 -1
- package/dist/search.js +3 -3
- package/dist/search.js.map +1 -1
- package/dist/test.js +153 -10
- package/dist/test.js.map +1 -1
- package/dist/todo.js +1 -0
- package/dist/todo.js.map +1 -1
- package/dist/tool-help.js +1 -0
- package/dist/tool-help.js.map +1 -1
- package/dist/tool-icons.d.ts +20 -0
- package/dist/tool-icons.js +130 -0
- package/dist/tool-icons.js.map +1 -0
- package/dist/tool-search.js +1 -0
- package/dist/tool-search.js.map +1 -1
- package/dist/tool-use.js +1 -0
- package/dist/tool-use.js.map +1 -1
- package/dist/tree.js +14 -6
- package/dist/tree.js.map +1 -1
- package/dist/typecheck.js +153 -10
- package/dist/typecheck.js.map +1 -1
- package/dist/write.js +22 -14
- package/dist/write.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/tool-icons.ts
|
|
2
|
+
var TOOL_ICON_CONFIG = {
|
|
3
|
+
file: { color: "#60a5fa" },
|
|
4
|
+
// blue
|
|
5
|
+
edit: { color: "#fbbf24" },
|
|
6
|
+
// amber
|
|
7
|
+
search: { color: "#a78bfa" },
|
|
8
|
+
// violet
|
|
9
|
+
folder: { color: "#38bdf8" },
|
|
10
|
+
// sky
|
|
11
|
+
terminal: { color: "#ef4444" },
|
|
12
|
+
// red
|
|
13
|
+
web: { color: "#34d399" },
|
|
14
|
+
// emerald
|
|
15
|
+
git: { color: "#fb923c" },
|
|
16
|
+
// orange
|
|
17
|
+
tree: { color: "#22d3ee" },
|
|
18
|
+
// cyan
|
|
19
|
+
code: { color: "#818cf8" },
|
|
20
|
+
// indigo
|
|
21
|
+
test: { color: "#4ade80" },
|
|
22
|
+
// green
|
|
23
|
+
package: { color: "#f472b6" },
|
|
24
|
+
// pink
|
|
25
|
+
document: { color: "#94a3b8" },
|
|
26
|
+
// slate
|
|
27
|
+
scaffold: { color: "#c084fc" },
|
|
28
|
+
// purple
|
|
29
|
+
todo: { color: "#facc15" },
|
|
30
|
+
// yellow
|
|
31
|
+
plan: { color: "#2dd4bf" },
|
|
32
|
+
// teal
|
|
33
|
+
task: { color: "#5eead4" },
|
|
34
|
+
// teal-light
|
|
35
|
+
meta: { color: "#cbd5e1" },
|
|
36
|
+
// slate-light
|
|
37
|
+
index: { color: "#06b6d4" },
|
|
38
|
+
// cyan-dark
|
|
39
|
+
json: { color: "#eab308" },
|
|
40
|
+
// yellow-dark
|
|
41
|
+
diff: { color: "#f97316" },
|
|
42
|
+
// orange-dark
|
|
43
|
+
logs: { color: "#a3a3a3" },
|
|
44
|
+
// neutral
|
|
45
|
+
settings: { color: "#9ca3af" },
|
|
46
|
+
// gray
|
|
47
|
+
brain: { color: "#e879f9" },
|
|
48
|
+
// fuchsia
|
|
49
|
+
fallback: { color: "#9ca3af" }
|
|
50
|
+
// gray
|
|
51
|
+
};
|
|
52
|
+
var TOOL_ICON_MAP = {
|
|
53
|
+
// ── file IO ──
|
|
54
|
+
read: "file",
|
|
55
|
+
cat: "file",
|
|
56
|
+
view: "file",
|
|
57
|
+
write: "file",
|
|
58
|
+
create: "file",
|
|
59
|
+
edit: "edit",
|
|
60
|
+
replace: "edit",
|
|
61
|
+
str_replace: "edit",
|
|
62
|
+
multi_edit: "edit",
|
|
63
|
+
patch: "diff",
|
|
64
|
+
// ── search ──
|
|
65
|
+
grep: "search",
|
|
66
|
+
search: "search",
|
|
67
|
+
rg: "search",
|
|
68
|
+
ripgrep: "search",
|
|
69
|
+
glob: "search",
|
|
70
|
+
find: "search",
|
|
71
|
+
// ── navigation ──
|
|
72
|
+
folder: "folder",
|
|
73
|
+
ls: "folder",
|
|
74
|
+
list: "folder",
|
|
75
|
+
set_working_dir: "folder",
|
|
76
|
+
tree: "tree",
|
|
77
|
+
// ── shell ──
|
|
78
|
+
bash: "terminal",
|
|
79
|
+
shell: "terminal",
|
|
80
|
+
sh: "terminal",
|
|
81
|
+
exec: "terminal",
|
|
82
|
+
run: "terminal",
|
|
83
|
+
command: "terminal",
|
|
84
|
+
// ── web ──
|
|
85
|
+
fetch: "web",
|
|
86
|
+
web_fetch: "web",
|
|
87
|
+
web_search: "web",
|
|
88
|
+
// ── vcs ──
|
|
89
|
+
git: "git",
|
|
90
|
+
diff: "diff",
|
|
91
|
+
// ── code quality ──
|
|
92
|
+
lint: "code",
|
|
93
|
+
format: "settings",
|
|
94
|
+
typecheck: "code",
|
|
95
|
+
test: "test",
|
|
96
|
+
// ── packages ──
|
|
97
|
+
install: "package",
|
|
98
|
+
outdated: "package",
|
|
99
|
+
audit: "package",
|
|
100
|
+
// ── docs / scaffold ──
|
|
101
|
+
document: "document",
|
|
102
|
+
scaffold: "scaffold",
|
|
103
|
+
// ── planning / work tracking ──
|
|
104
|
+
todo: "todo",
|
|
105
|
+
plan: "plan",
|
|
106
|
+
task: "task",
|
|
107
|
+
// ── data ──
|
|
108
|
+
json: "json",
|
|
109
|
+
index: "index",
|
|
110
|
+
logs: "logs",
|
|
111
|
+
// ── meta / tooling ──
|
|
112
|
+
mode: "meta",
|
|
113
|
+
tool_search: "meta",
|
|
114
|
+
tool_use: "meta",
|
|
115
|
+
batch_tool_use: "meta",
|
|
116
|
+
tool_help: "meta",
|
|
117
|
+
// ── memory ──
|
|
118
|
+
remember: "brain",
|
|
119
|
+
forget: "brain",
|
|
120
|
+
search_memory: "brain",
|
|
121
|
+
find_related_memories: "brain"
|
|
122
|
+
};
|
|
123
|
+
function getToolIcon(name) {
|
|
124
|
+
if (!name) return "fallback";
|
|
125
|
+
return TOOL_ICON_MAP[name.toLowerCase()] ?? "fallback";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { TOOL_ICON_CONFIG, TOOL_ICON_MAP, getToolIcon };
|
|
129
|
+
//# sourceMappingURL=tool-icons.js.map
|
|
130
|
+
//# sourceMappingURL=tool-icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tool-icons.ts"],"names":[],"mappings":";AAwCO,IAAM,gBAAA,GAA0D;AAAA,EACrE,IAAA,EAAM,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACzB,IAAA,EAAM,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACzB,MAAA,EAAQ,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EAC3B,MAAA,EAAQ,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EAC3B,QAAA,EAAU,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EAC7B,GAAA,EAAK,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACxB,GAAA,EAAK,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACxB,IAAA,EAAM,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACzB,IAAA,EAAM,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACzB,IAAA,EAAM,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACzB,OAAA,EAAS,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EAC5B,QAAA,EAAU,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EAC7B,QAAA,EAAU,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EAC7B,IAAA,EAAM,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACzB,IAAA,EAAM,EAAE,KAAA,EAAO,SAAA,EAAU;AAAA;AAAA,EACzB,IAAA,EAAM,EAAE,KAAA,EAAO,SAAA,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// This is PURE DATA (no node imports) so it is safe to import from the browser\n// (WebUI) as well as the TUI. Each surface maps a `ToolIconId` to its own\n// rendering primitive — the WebUI to a lucide-react component (`tool-icon.ts`),\n// the TUI to a unicode glyph (`tool-glyph.ts`) — and pulls the shared color\n// from `TOOL_ICON_CONFIG` so both stay in lockstep.\n//\n// Add a new tool by giving it an entry in `TOOL_ICON_MAP` (name → id). The id\n// must be one of the `ToolIconId` union members below; every id already has a\n// color, a lucide component, and a glyph.\n\n/** The closed set of visual identities a tool can map to. */\nexport type ToolIconId =\n | 'file'\n | 'edit'\n | 'search'\n | 'folder'\n | 'terminal'\n | 'web'\n | 'git'\n | 'tree'\n | 'code'\n | 'test'\n | 'package'\n | 'document'\n | 'scaffold'\n | 'todo'\n | 'plan'\n | 'task'\n | 'meta'\n | 'index'\n | 'json'\n | 'diff'\n | 'logs'\n | 'settings'\n | 'brain'\n | 'fallback';\n\n/** Canonical hex color per icon id — the single source both surfaces read. */\nexport const TOOL_ICON_CONFIG: Record<ToolIconId, { color: string }> = {\n file: { color: '#60a5fa' }, // blue\n edit: { color: '#fbbf24' }, // amber\n search: { color: '#a78bfa' }, // violet\n folder: { color: '#38bdf8' }, // sky\n terminal: { color: '#ef4444' }, // red\n web: { color: '#34d399' }, // emerald\n git: { color: '#fb923c' }, // orange\n tree: { color: '#22d3ee' }, // cyan\n code: { color: '#818cf8' }, // indigo\n test: { color: '#4ade80' }, // green\n package: { color: '#f472b6' }, // pink\n document: { color: '#94a3b8' }, // slate\n scaffold: { color: '#c084fc' }, // purple\n todo: { color: '#facc15' }, // yellow\n plan: { color: '#2dd4bf' }, // teal\n task: { color: '#5eead4' }, // teal-light\n meta: { color: '#cbd5e1' }, // slate-light\n index: { color: '#06b6d4' }, // cyan-dark\n json: { color: '#eab308' }, // yellow-dark\n diff: { color: '#f97316' }, // orange-dark\n logs: { color: '#a3a3a3' }, // neutral\n settings: { color: '#9ca3af' }, // gray\n brain: { color: '#e879f9' }, // fuchsia\n fallback: { color: '#9ca3af' }, // gray\n};\n\n/**\n * Tool name (and common alias) → icon id. Keys are lowercase; `getToolIcon`\n * lowercases the query, so lookups are case-insensitive. Covers every builtin\n * tool plus the aliases models commonly emit.\n */\nexport const TOOL_ICON_MAP: Record<string, ToolIconId> = {\n // ── file IO ──\n read: 'file',\n cat: 'file',\n view: 'file',\n write: 'file',\n create: 'file',\n edit: 'edit',\n replace: 'edit',\n str_replace: 'edit',\n multi_edit: 'edit',\n patch: 'diff',\n // ── search ──\n grep: 'search',\n search: 'search',\n rg: 'search',\n ripgrep: 'search',\n glob: 'search',\n find: 'search',\n // ── navigation ──\n folder: 'folder',\n ls: 'folder',\n list: 'folder',\n set_working_dir: 'folder',\n tree: 'tree',\n // ── shell ──\n bash: 'terminal',\n shell: 'terminal',\n sh: 'terminal',\n exec: 'terminal',\n run: 'terminal',\n command: 'terminal',\n // ── web ──\n fetch: 'web',\n web_fetch: 'web',\n web_search: 'web',\n // ── vcs ──\n git: 'git',\n diff: 'diff',\n // ── code quality ──\n lint: 'code',\n format: 'settings',\n typecheck: 'code',\n test: 'test',\n // ── packages ──\n install: 'package',\n outdated: 'package',\n audit: 'package',\n // ── docs / scaffold ──\n document: 'document',\n scaffold: 'scaffold',\n // ── planning / work tracking ──\n todo: 'todo',\n plan: 'plan',\n task: 'task',\n // ── data ──\n json: 'json',\n index: 'index',\n logs: 'logs',\n // ── meta / tooling ──\n mode: 'meta',\n tool_search: 'meta',\n tool_use: 'meta',\n batch_tool_use: 'meta',\n tool_help: 'meta',\n // ── memory ──\n remember: 'brain',\n forget: 'brain',\n search_memory: 'brain',\n find_related_memories: 'brain',\n};\n\n/**\n * Resolve a tool name to its canonical `ToolIconId`. Case-insensitive.\n * Unknown names — including `mcp__*` server tools and plugin tools — fall back\n * to `'fallback'`.\n */\nexport function getToolIcon(name: string): ToolIconId {\n if (!name) return 'fallback';\n return TOOL_ICON_MAP[name.toLowerCase()] ?? 'fallback';\n}\n"]}
|
package/dist/tool-search.js
CHANGED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AA,CAAE,UAAA;AAAA,MACd,UAAU,CAAA,CAAE;AAAA,KACd,CAAE,CAAA;AAKF,IAAA,MAAM,iBAAiB,KAAA,CAAM,MAAA;AAC7B,IAAA,MAAM,IAAA,GACJ,OAAA,CAAQ,MAAA,KAAW,CAAA,IAAK,KAAA,GACpB,qBAAqB,KAAA,CAAM,KAAK,CAAA,gDAAA,EAAmD,cAAc,CAAA,iBAAA,CAAA,GACjG,MAAA;AAEN,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,OAAA;AAAA,MACP,OAAO,QAAA,CAAS,MAAA;AAAA,MAChB,SAAA,EAAW,SAAS,MAAA,GAAS,KAAA;AAAA,MAC7B,GAAI,IAAA,GAAO,EAAE,IAAA,KAAS,EAAC;AAAA,MACvB,UAAA,EAAY;AAAA,KACd;AAAA,EACF;AACF","file":"tool-search.js","sourcesContent":["import type { Tool } from '@wrongstack/core';\n\ninterface ToolSearchInput {\n query?: string | undefined;\n tags?: string[] | undefined;\n permission?: 'auto' | 'confirm' | 'deny' | undefined;\n mutating?: boolean | undefined;\n limit?: number | undefined;\n}\n\ninterface ToolSearchOutput {\n tools: {\n name: string;\n description: string;\n permission: string;\n mutating: boolean;\n }[];\n total: number;\n truncated: boolean;\n /** Total count of tools in the registry (for \"no results\" hints). */\n _available?: number;\n}\n\nexport const toolSearchTool: Tool<ToolSearchInput, ToolSearchOutput> = {\n name: 'tool_search',\n category: 'Meta',\n description:\n 'Search the catalog of available tools. Very useful when you are unsure which tool to use for a task.',\n usageHint:\n 'SELF-DISCOVERY TOOL:\\n\\n' +\n '- Use when you need to find the right tool for a job.\\n' +\n '- `query` searches names and descriptions.\\n' +\n '- You can filter by `tags` (category), `permission`, or `mutating`.\\n' +\n 'Call this before guessing tool names. It helps you discover the best tool for the current situation.',\n permission: 'auto',\n mutating: false,\n timeoutMs: 1_000,\n capabilities: ['tool.meta'],\n inputSchema: {\n type: 'object',\n properties: {\n query: {\n type: 'string',\n description: 'Search query for tool name or description',\n },\n tags: {\n type: 'array',\n items: { type: 'string' },\n description: 'Filter by tags (e.g. \"filesystem\", \"network\", \"dev\")',\n },\n permission: {\n type: 'string',\n enum: ['auto', 'confirm', 'deny'],\n description: 'Filter by required permission level',\n },\n mutating: {\n type: 'boolean',\n description: 'Filter by mutating flag (true=filters that modify, false=read-only)',\n },\n limit: {\n type: 'integer',\n description: 'Maximum results to return (default: 20)',\n minimum: 1,\n maximum: 100,\n },\n },\n },\n async execute(input, ctx) {\n const limit = Math.min(input.limit ?? 20, 100);\n const tools = ctx.tools;\n const query = input.query?.toLowerCase() ?? '';\n\n const filtered = tools.filter((t: Tool) => {\n if (\n query &&\n !t.name.toLowerCase().includes(query) &&\n !t.description.toLowerCase().includes(query)\n ) {\n return false;\n }\n if (input.tags && input.tags.length > 0) {\n const toolCat = (t.category ?? '').toLowerCase();\n if (!input.tags.some((tag: string) => toolCat.includes(tag.toLowerCase()))) {\n return false;\n }\n }\n if (input.permission && t.permission !== input.permission) {\n return false;\n }\n if (typeof input.mutating === 'boolean' && t.mutating !== input.mutating) {\n return false;\n }\n return true;\n });\n\n const results = filtered.slice(0, limit).map((t: Tool) => ({\n name: t.name,\n description: t.description,\n permission: t.permission,\n mutating: t.mutating,\n }));\n\n // When no tools match, give the model actionable guidance so it\n // doesn't spiral through random queries. Point it at tool-help\n // which lists every available tool with descriptions.\n const totalAvailable = tools.length;\n const hint =\n results.length === 0 && query\n ? `No tools matched \"${input.query}\". Use tool-help (without arguments) to see all ${totalAvailable} available tools.`\n : undefined;\n\n return {\n tools: results,\n total: filtered.length,\n truncated: filtered.length > limit,\n ...(hint ? { hint } : {}),\n _available: totalAvailable,\n };\n },\n};"]}
|
|
1
|
+
{"version":3,"sources":["../src/tool-search.ts"],"names":[],"mappings":";AAuBO,IAAM,cAAA,GAA0D;AAAA,EACrE,IAAA,EAAM,aAAA;AAAA,EACN,QAAA,EAAU,MAAA;AAAA,EACV,WAAA,EACE,sGAAA;AAAA,EACF,SAAA,EACE,sSAAA;AA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AAK,CAAA,gDAAA,EAAmD,cAAc,CAAA,iBAAA,CAAA,GACjG,MAAA;AAEN,IAAA,OAAO;AAAA,MACL,KAAA,EAAO,OAAA;AAAA,MACP,OAAO,QAAA,CAAS,MAAA;AAAA,MAChB,SAAA,EAAW,SAAS,MAAA,GAAS,KAAA;AAAA,MAC7B,GAAI,IAAA,GAAO,EAAE,IAAA,KAAS,EAAC;AAAA,MACvB,UAAA,EAAY;AAAA,KACd;AAAA,EACF;AACF","file":"tool-search.js","sourcesContent":["import type { Tool } from '@wrongstack/core';\n\ninterface ToolSearchInput {\n query?: string | undefined;\n tags?: string[] | undefined;\n permission?: 'auto' | 'confirm' | 'deny' | undefined;\n mutating?: boolean | undefined;\n limit?: number | undefined;\n}\n\ninterface ToolSearchOutput {\n tools: {\n name: string;\n description: string;\n permission: string;\n mutating: boolean;\n }[];\n total: number;\n truncated: boolean;\n /** Total count of tools in the registry (for \"no results\" hints). */\n _available?: number;\n}\n\nexport const toolSearchTool: Tool<ToolSearchInput, ToolSearchOutput> = {\n name: 'tool_search',\n category: 'Meta',\n description:\n 'Search the catalog of available tools. Very useful when you are unsure which tool to use for a task.',\n usageHint:\n 'SELF-DISCOVERY TOOL:\\n\\n' +\n '- Use when you need to find the right tool for a job.\\n' +\n '- `query` searches names and descriptions.\\n' +\n '- You can filter by `tags` (category), `permission`, or `mutating`.\\n' +\n 'Call this before guessing tool names. It helps you discover the best tool for the current situation.',\n permission: 'auto',\n mutating: false,\n timeoutMs: 1_000,\n capabilities: ['tool.meta'],\n icon: 'meta',\n inputSchema: {\n type: 'object',\n properties: {\n query: {\n type: 'string',\n description: 'Search query for tool name or description',\n },\n tags: {\n type: 'array',\n items: { type: 'string' },\n description: 'Filter by tags (e.g. \"filesystem\", \"network\", \"dev\")',\n },\n permission: {\n type: 'string',\n enum: ['auto', 'confirm', 'deny'],\n description: 'Filter by required permission level',\n },\n mutating: {\n type: 'boolean',\n description: 'Filter by mutating flag (true=filters that modify, false=read-only)',\n },\n limit: {\n type: 'integer',\n description: 'Maximum results to return (default: 20)',\n minimum: 1,\n maximum: 100,\n },\n },\n },\n async execute(input, ctx) {\n const limit = Math.min(input.limit ?? 20, 100);\n const tools = ctx.tools;\n const query = input.query?.toLowerCase() ?? '';\n\n const filtered = tools.filter((t: Tool) => {\n if (\n query &&\n !t.name.toLowerCase().includes(query) &&\n !t.description.toLowerCase().includes(query)\n ) {\n return false;\n }\n if (input.tags && input.tags.length > 0) {\n const toolCat = (t.category ?? '').toLowerCase();\n if (!input.tags.some((tag: string) => toolCat.includes(tag.toLowerCase()))) {\n return false;\n }\n }\n if (input.permission && t.permission !== input.permission) {\n return false;\n }\n if (typeof input.mutating === 'boolean' && t.mutating !== input.mutating) {\n return false;\n }\n return true;\n });\n\n const results = filtered.slice(0, limit).map((t: Tool) => ({\n name: t.name,\n description: t.description,\n permission: t.permission,\n mutating: t.mutating,\n }));\n\n // When no tools match, give the model actionable guidance so it\n // doesn't spiral through random queries. Point it at tool-help\n // which lists every available tool with descriptions.\n const totalAvailable = tools.length;\n const hint =\n results.length === 0 && query\n ? `No tools matched \"${input.query}\". Use tool-help (without arguments) to see all ${totalAvailable} available tools.`\n : undefined;\n\n return {\n tools: results,\n total: filtered.length,\n truncated: filtered.length > limit,\n ...(hint ? { hint } : {}),\n _available: totalAvailable,\n };\n },\n};"]}
|
package/dist/tool-use.js
CHANGED
package/dist/tool-use.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tool-use.ts"],"names":[],"mappings":";AAeO,IAAM,WAAA,GAAiD;AAAA,EAC5D,IAAA,EAAM,UAAA;AAAA,EACN,QAAA,EAAU,MAAA;AAAA,EACV,WAAA,EACE,gNAAA;AAAA,EAEF,SAAA,EACE,+WAAA;AAAA,EAKF,UAAA,EAAY,SAAA;AAAA,EACZ,QAAA,EAAU,IAAA;AAAA,EACV,SAAA,EAAW,GAAA;AAAA,EACX,YAAA,EAAc,CAAC,iBAAiB,CAAA;AAA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pC,WAAA,EAAa,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,OAC5B;AAAA,IACF;AAWA,IAAA,IAAI;AACF,MAAA,MAAM,SAAS,MAAM,IAAA,CAAK,QAAQ,KAAA,CAAM,KAAA,EAAO,KAAK,IAAI,CAAA;AACxD,MAAA,OAAO;AAAA,QACL,MAAM,KAAA,CAAM,IAAA;AAAA,QACZ,OAAA,EAAS,IAAA;AAAA,QACT,MAAA;AAAA,QACA,WAAA,EAAa,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,OAC5B;AAAA,IACF,SAAS,CAAA,EAAG;AACV,MAAA,OAAO;AAAA,QACL,MAAM,KAAA,CAAM,IAAA;AAAA,QACZ,OAAA,EAAS,KAAA;AAAA,QACT,OAAO,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AAAA,QAChD,WAAA,EAAa,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,OAC5B;AAAA,IACF;AAAA,EACF;AACF","file":"tool-use.js","sourcesContent":["import type { Tool } from '@wrongstack/core';\n\ninterface ToolUseInput {\n tool: string;\n input: Record<string, unknown>;\n}\n\ninterface ToolUseOutput {\n tool: string;\n success: boolean;\n result?: unknown | undefined;\n error?: string | undefined;\n executionMs: number;\n}\n\nexport const toolUseTool: Tool<ToolUseInput, ToolUseOutput> = {\n name: 'tool_use',\n category: 'Meta',\n description:\n 'Directly execute any registered tool by its exact name, bypassing normal discovery. ' +\n 'This is a powerful meta-tool intended for cases where the agent has a clear plan and knows precisely which tool to invoke.',\n usageHint:\n 'ADVANCED META TOOL — USE WITH CARE:\\n\\n' +\n '- Only use when you are certain of the exact tool name and its expected input shape.\\n' +\n '- Prefer using the normal tool calling mechanism when possible.\\n' +\n '- Very useful in batch-tool-use or when orchestrating complex workflows programmatically.\\n' +\n '- The call still goes through full permission checks and capability validation.',\n permission: 'confirm',\n mutating: true,\n timeoutMs: 60_000,\n capabilities: ['tool.mutate.any'],\n inputSchema: {\n type: 'object',\n properties: {\n tool: {\n type: 'string',\n description: 'The exact registered name of the tool to invoke (e.g. \"bash\", \"read\", \"codebase-search\").',\n },\n input: {\n type: 'object',\n description: 'The input object matching the target tool\\'s inputSchema.',\n },\n },\n required: ['tool'],\n },\n async execute(input, ctx, opts) {\n const start = Date.now();\n\n if (!input?.tool) {\n return {\n tool: 'unknown',\n success: false,\n error: 'tool_use: tool name is required',\n executionMs: 0,\n };\n }\n\n const tool = ctx.tools.find((t: Tool) => t.name === input.tool);\n if (!tool) {\n return {\n tool: input.tool,\n success: false,\n error: `tool_use: tool \"${input.tool}\" not found`,\n executionMs: Date.now() - start,\n };\n }\n\n // `deny` is a hard policy gate — bypassing it through a meta-tool\n // would defeat the whole point of the permission system. Keep this\n // check even though the outer `tool_use` already requires `confirm`.\n if (tool.permission === 'deny') {\n return {\n tool: input.tool,\n success: false,\n error: `tool_use: tool \"${input.tool}\" is denied by policy`,\n executionMs: Date.now() - start,\n };\n }\n\n // Note: inner `permission === 'confirm'` is intentionally NOT short-\n // circuited here. The outer `tool_use` itself has `permission: 'confirm'`,\n // so the user already saw the full args (including which inner tool will\n // run, and with what input) before approving the meta-call. Duplicating\n // the check inside execute() turned every confirm-tool dispatch through\n // `tool_use` into a hard failure — the model would see \"requires\n // confirmation\" with no way to proceed, even after the user said yes.\n // `batch_tool_use` already follows this same model.\n\n try {\n const result = await tool.execute(input.input, ctx, opts);\n return {\n tool: input.tool,\n success: true,\n result,\n executionMs: Date.now() - start,\n };\n } catch (e) {\n return {\n tool: input.tool,\n success: false,\n error: e instanceof Error ? e.message : String(e),\n executionMs: Date.now() - start,\n };\n }\n },\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/tool-use.ts"],"names":[],"mappings":";AAeO,IAAM,WAAA,GAAiD;AAAA,EAC5D,IAAA,EAAM,UAAA;AAAA,EACN,QAAA,EAAU,MAAA;AAAA,EACV,WAAA,EACE,gNAAA;AAAA,EAEF,SAAA,EACE,+WAAA;A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AA,OAAO;AAAA,QACL,MAAM,KAAA,CAAM,IAAA;AAAA,QACZ,OAAA,EAAS,KAAA;AAAA,QACT,KAAA,EAAO,CAAA,gBAAA,EAAmB,KAAA,CAAM,IAAI,CAAA,qBAAA,CAAA;AAAA,QACpC,WAAA,EAAa,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,OAC5B;AAAA,IACF;AAWA,IAAA,IAAI;AACF,MAAA,MAAM,SAAS,MAAM,IAAA,CAAK,QAAQ,KAAA,CAAM,KAAA,EAAO,KAAK,IAAI,CAAA;AACxD,MAAA,OAAO;AAAA,QACL,MAAM,KAAA,CAAM,IAAA;AAAA,QACZ,OAAA,EAAS,IAAA;AAAA,QACT,MAAA;AAAA,QACA,WAAA,EAAa,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,OAC5B;AAAA,IACF,SAAS,CAAA,EAAG;AACV,MAAA,OAAO;AAAA,QACL,MAAM,KAAA,CAAM,IAAA;AAAA,QACZ,OAAA,EAAS,KAAA;AAAA,QACT,OAAO,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AAAA,QAChD,WAAA,EAAa,IAAA,CAAK,GAAA,EAAI,GAAI;AAAA,OAC5B;AAAA,IACF;AAAA,EACF;AACF","file":"tool-use.js","sourcesContent":["import type { Tool } from '@wrongstack/core';\n\ninterface ToolUseInput {\n tool: string;\n input: Record<string, unknown>;\n}\n\ninterface ToolUseOutput {\n tool: string;\n success: boolean;\n result?: unknown | undefined;\n error?: string | undefined;\n executionMs: number;\n}\n\nexport const toolUseTool: Tool<ToolUseInput, ToolUseOutput> = {\n name: 'tool_use',\n category: 'Meta',\n description:\n 'Directly execute any registered tool by its exact name, bypassing normal discovery. ' +\n 'This is a powerful meta-tool intended for cases where the agent has a clear plan and knows precisely which tool to invoke.',\n usageHint:\n 'ADVANCED META TOOL — USE WITH CARE:\\n\\n' +\n '- Only use when you are certain of the exact tool name and its expected input shape.\\n' +\n '- Prefer using the normal tool calling mechanism when possible.\\n' +\n '- Very useful in batch-tool-use or when orchestrating complex workflows programmatically.\\n' +\n '- The call still goes through full permission checks and capability validation.',\n permission: 'confirm',\n mutating: true,\n timeoutMs: 60_000,\n capabilities: ['tool.mutate.any'],\n icon: 'meta',\n inputSchema: {\n type: 'object',\n properties: {\n tool: {\n type: 'string',\n description: 'The exact registered name of the tool to invoke (e.g. \"bash\", \"read\", \"codebase-search\").',\n },\n input: {\n type: 'object',\n description: 'The input object matching the target tool\\'s inputSchema.',\n },\n },\n required: ['tool'],\n },\n async execute(input, ctx, opts) {\n const start = Date.now();\n\n if (!input?.tool) {\n return {\n tool: 'unknown',\n success: false,\n error: 'tool_use: tool name is required',\n executionMs: 0,\n };\n }\n\n const tool = ctx.tools.find((t: Tool) => t.name === input.tool);\n if (!tool) {\n return {\n tool: input.tool,\n success: false,\n error: `tool_use: tool \"${input.tool}\" not found`,\n executionMs: Date.now() - start,\n };\n }\n\n // `deny` is a hard policy gate — bypassing it through a meta-tool\n // would defeat the whole point of the permission system. Keep this\n // check even though the outer `tool_use` already requires `confirm`.\n if (tool.permission === 'deny') {\n return {\n tool: input.tool,\n success: false,\n error: `tool_use: tool \"${input.tool}\" is denied by policy`,\n executionMs: Date.now() - start,\n };\n }\n\n // Note: inner `permission === 'confirm'` is intentionally NOT short-\n // circuited here. The outer `tool_use` itself has `permission: 'confirm'`,\n // so the user already saw the full args (including which inner tool will\n // run, and with what input) before approving the meta-call. Duplicating\n // the check inside execute() turned every confirm-tool dispatch through\n // `tool_use` into a hard failure — the model would see \"requires\n // confirmation\" with no way to proceed, even after the user said yes.\n // `batch_tool_use` already follows this same model.\n\n try {\n const result = await tool.execute(input.input, ctx, opts);\n return {\n tool: input.tool,\n success: true,\n result,\n executionMs: Date.now() - start,\n };\n } catch (e) {\n return {\n tool: input.tool,\n success: false,\n error: e instanceof Error ? e.message : String(e),\n executionMs: Date.now() - start,\n };\n }\n },\n};\n"]}
|
package/dist/tree.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Core from '@wrongstack/core';
|
|
1
2
|
import { expectDefined } from '@wrongstack/core';
|
|
2
3
|
import * as fs from 'node:fs/promises';
|
|
3
4
|
import * as path from 'node:path';
|
|
@@ -6,14 +7,20 @@ import * as path from 'node:path';
|
|
|
6
7
|
function resolvePath(input, ctx) {
|
|
7
8
|
return path.isAbsolute(input) ? path.normalize(input) : path.resolve(ctx.workingDir ?? ctx.cwd, input);
|
|
8
9
|
}
|
|
10
|
+
function allowedRoots(ctx) {
|
|
11
|
+
return [path.resolve(ctx.projectRoot), path.resolve(Core.wstackGlobalRoot())];
|
|
12
|
+
}
|
|
13
|
+
function isInsideAny(target, roots) {
|
|
14
|
+
return roots.some((root) => {
|
|
15
|
+
const rel = path.relative(root, target);
|
|
16
|
+
return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
9
19
|
function ensureInsideRoot(absPath, ctx) {
|
|
10
|
-
const root = path.resolve(ctx.projectRoot);
|
|
11
20
|
const target = path.resolve(absPath);
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return target;
|
|
21
|
+
if (ctx.allowOutsideProjectRoot) return target;
|
|
22
|
+
if (isInsideAny(target, allowedRoots(ctx))) return target;
|
|
23
|
+
throw new Error(`Path "${absPath}" is outside project root "${path.resolve(ctx.projectRoot)}"`);
|
|
17
24
|
}
|
|
18
25
|
function safeResolve(input, ctx) {
|
|
19
26
|
return ensureInsideRoot(resolvePath(input, ctx), ctx);
|
|
@@ -41,6 +48,7 @@ var treeTool = {
|
|
|
41
48
|
permission: "auto",
|
|
42
49
|
mutating: false,
|
|
43
50
|
capabilities: ["fs.read"],
|
|
51
|
+
icon: "tree",
|
|
44
52
|
timeoutMs: 15e3,
|
|
45
53
|
inputSchema: {
|
|
46
54
|
type: "object",
|
package/dist/tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|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AM,IAAA,CAAK,IAAA,CAAK,MAAA,GAAS,SAAS,WAAW,CAAA;AAElD,IAAA,IAAI,KAAA,CAAM,aAAY,KAAM,IAAA,CAAK,aAAa,CAAA,IAAK,KAAA,GAAQ,KAAK,QAAA,CAAA,EAAW;AACzE,MAAA,MAAM,WAAA,GAAc,KAAK,MAAA,GAAS,SAAA;AAClC,MAAA,MAAM,QAAaA,IAAA,CAAA,IAAA,CAAK,GAAA,EAAK,MAAM,IAAI,CAAA,EAAG,QAAQ,CAAA,EAAG;AAAA,QACnD,GAAG,IAAA;AAAA,QACH,MAAA,EAAQ,WAAA;AAAA,QACR;AAAA,OACD,CAAA;AAAA,IACH;AAAA,EACF;AACF","file":"tree.js","sourcesContent":["import * as fsp from 'node:fs/promises';\nimport * as path from 'node:path';\nimport * as Core from '@wrongstack/core';\nimport type { Context } from '@wrongstack/core';\n/** Detected package manager for a project directory. */\nexport type PackageManager = 'pnpm' | 'yarn' | 'npm';\n\n/**\n * Detect the project's package manager by inspecting lockfiles in `cwd`.\n * Order: pnpm → yarn → npm (default). Missing or unreadable directories fall\n * back to `npm` rather than throwing, so a `safeResolve`-checked cwd that\n * happens to be empty never aborts the tool.\n */\nexport async function detectPackageManager(cwd: string): Promise<PackageManager> {\n const { stat } = await import('node:fs/promises');\n try {\n await stat(`${cwd}/pnpm-lock.yaml`);\n return 'pnpm';\n } catch {\n /* not pnpm */\n }\n try {\n await stat(`${cwd}/yarn.lock`);\n return 'yarn';\n } catch {\n /* not yarn */\n }\n return 'npm';\n}\n\nexport function resolvePath(input: string, ctx: Context): string {\n return path.isAbsolute(input) ? path.normalize(input) : path.resolve(ctx.workingDir ?? ctx.cwd, input);\n}\n\nexport function ensureInsideRoot(absPath: string, ctx: Context): string {\n const root = path.resolve(ctx.projectRoot);\n const target = path.resolve(absPath);\n const rel = path.relative(root, target);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new Error(`Path \"${absPath}\" is outside project root \"${root}\"`);\n }\n return target;\n}\n\nexport function safeResolve(input: string, ctx: Context): string {\n return ensureInsideRoot(resolvePath(input, ctx), ctx);\n}\n\n/**\n * Defense against in-root→out-of-root symlink escape (CWE-59). `safeResolve`\n * only does a syntactic `../` check, so a symlink that lives *inside* the\n * project root but points outside still passes it. This resolves the path\n * through `fs.realpath` and re-verifies containment against the realpath of\n * the project root (comparing like-for-like, since the root itself may be a\n * symlink — macOS `/var`→`/private/var`, Windows 8.3 short names). For a path\n * that does not exist yet (e.g. a `write` to a new file) the nearest existing\n * ancestor directory is checked instead. Throws if the real target escapes.\n *\n * Mirrors the per-file guard already used in `replace.ts`/`grep.ts`; applied\n * to single-file `read`/`edit`/`write` it throws (rather than skips) because\n * the caller named exactly one file.\n */\nexport async function assertRealInsideRoot(absPath: string, ctx: Context): Promise<void> {\n const realRoot = await fsp.realpath(ctx.projectRoot).catch(() => path.resolve(ctx.projectRoot));\n let probe = absPath;\n for (;;) {\n let real: string;\n try {\n real = await fsp.realpath(probe);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n const parent = path.dirname(probe);\n if (parent === probe) return; // reached fs root without escaping\n probe = parent;\n continue;\n }\n throw err;\n }\n const rel = path.relative(realRoot, real);\n if (rel.startsWith('..') || path.isAbsolute(rel)) {\n throw new Error(\n `Path \"${absPath}\" resolves through a symlink outside project root \"${realRoot}\"`,\n );\n }\n return;\n }\n}\n\n/** `safeResolve` + symlink realpath containment check. Async. */\nexport async function safeResolveReal(input: string, ctx: Context): Promise<string> {\n const abs = safeResolve(input, ctx);\n await assertRealInsideRoot(abs, ctx);\n return abs;\n}\n\nexport function truncateMiddle(s: string, max: number): string {\n if (Buffer.byteLength(s, 'utf8') <= max) return s;\n const half = Math.floor(max / 2);\n return (\n s.slice(0, half) +\n `\\n…[truncated ${Buffer.byteLength(s, 'utf8') - max} bytes from middle]…\\n` +\n s.slice(-half)\n );\n}\n\nexport function isBinaryBuffer(buf: Buffer): boolean {\n const len = Math.min(buf.length, 8192);\n for (let i = 0; i < len; i++) {\n if (buf[i] === 0) return true;\n }\n return false;\n}\n\n// ─── Command-output normalization (token-saving) ────────────────────────────\n//\n// Raw process output is full of tokens the model gains nothing from: ANSI\n// escapes, carriage-return progress spam, runs of identical warning lines, and\n// huge tails of build noise. These helpers strip that noise before the output\n// reaches the LLM. They are scoped to COMMAND tools (bash/git/exec and the\n// _spawn-stream consumers) — never applied to structured/code outputs.\n\n/** Unified byte cap for all command tool output fed to the model. */\nexport const COMMAND_OUTPUT_MAX_BYTES = 32_768;\n\n/** Runs of >= this many identical consecutive lines are collapsed. */\nconst REPEAT_RUN_THRESHOLD = 3;\n\n/**\n * Collapse carriage-return overwrites the way a terminal would: `\\r\\n` becomes\n * `\\n`, and a bare `\\r` (progress redraw) keeps only the text after the LAST\n * `\\r` on its physical line. Without this, a single progress bar that redraws\n * 200 times explodes into 200 lines.\n */\nexport function collapseCarriageReturns(text: string): string {\n const lf = text.replace(/\\r\\n/g, '\\n');\n if (!lf.includes('\\r')) return lf;\n return lf\n .split('\\n')\n .map((line) => (line.includes('\\r') ? line.slice(line.lastIndexOf('\\r') + 1) : line))\n .join('\\n');\n}\n\n/**\n * Collapse a run of `minRun`+ identical consecutive lines into the line once\n * plus a marker. Consecutive-only — it never reorders or dedups non-adjacent\n * lines, so diffs/source stay intact.\n */\nexport function collapseConsecutiveDuplicates(text: string, minRun = REPEAT_RUN_THRESHOLD): string {\n const lines = text.split('\\n');\n const out: string[] = [];\n let i = 0;\n while (i < lines.length) {\n let j = i + 1;\n while (j < lines.length && lines[j] === lines[i]) j++;\n const run = j - i;\n if (run >= minRun) {\n out.push(lines[i]!, `… ⟨repeated ${run}×⟩`);\n } else {\n for (let k = i; k < j; k++) out.push(lines[k]!);\n }\n i = j;\n }\n return out.join('\\n');\n}\n\n/** Largest prefix of `s` whose UTF-8 byte length is <= `maxBytes`. */\nfunction takeHeadBytes(s: string, maxBytes: number): string {\n if (maxBytes <= 0) return '';\n if (Buffer.byteLength(s, 'utf8') <= maxBytes) return s;\n let lo = 0;\n let hi = s.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (Buffer.byteLength(s.slice(0, mid), 'utf8') <= maxBytes) lo = mid;\n else hi = mid - 1;\n }\n return s.slice(0, lo);\n}\n\n/** Largest suffix of `s` whose UTF-8 byte length is <= `maxBytes`. */\nfunction takeTailBytes(s: string, maxBytes: number): string {\n if (maxBytes <= 0) return '';\n if (Buffer.byteLength(s, 'utf8') <= maxBytes) return s;\n let lo = 0;\n let hi = s.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (Buffer.byteLength(s.slice(s.length - mid), 'utf8') <= maxBytes) lo = mid;\n else hi = mid - 1;\n }\n return s.slice(s.length - lo);\n}\n\n/**\n * Truncate to `maxBytes` keeping BOTH ends — the head (what ran / early context)\n * and the tail (errors and summaries usually land last), biased ~45/55 toward\n * the tail. The result never exceeds `maxBytes`.\n */\nexport function truncateHeadTail(s: string, maxBytes: number): string {\n const total = Buffer.byteLength(s, 'utf8');\n if (total <= maxBytes) return s;\n // Reserve a fixed allowance for the marker so the final string can't exceed\n // the cap even though the dropped-byte count's digit width varies.\n const MARKER_RESERVE = 64;\n const avail = Math.max(0, maxBytes - MARKER_RESERVE);\n const headBudget = Math.floor(avail * 0.45);\n const head = takeHeadBytes(s, headBudget);\n const tail = takeTailBytes(s, avail - Buffer.byteLength(head, 'utf8'));\n const kept = Buffer.byteLength(head, 'utf8') + Buffer.byteLength(tail, 'utf8');\n return `${head}\\n…[truncated ${total - kept} bytes]…\\n${tail}`;\n}\n\n/**\n * Full token-saving pipeline for command tool output: strip ANSI → collapse\n * carriage-return progress → trim trailing whitespace → collapse identical\n * consecutive lines → squeeze blank-line runs → head+tail truncate to the cap.\n */\nexport function normalizeCommandOutput(\n raw: string,\n opts: { maxBytes?: number | undefined } = {},\n): string {\n if (!raw) return raw;\n let text = Core.stripAnsi(raw);\n text = collapseCarriageReturns(text);\n text = text.replace(/[ \\t]+$/gm, ''); // trailing whitespace per line\n text = collapseConsecutiveDuplicates(text);\n text = text.replace(/\\n{3,}/g, '\\n\\n'); // >=2 blank lines → 1\n return truncateHeadTail(text, opts.maxBytes ?? COMMAND_OUTPUT_MAX_BYTES);\n}\n","import { expectDefined } from '@wrongstack/core';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type { Tool, ToolProgressEvent, ToolStreamEvent } from '@wrongstack/core';\nimport { safeResolve } from './_util.js';\nconst DEFAULT_IGNORE = [\n 'node_modules',\n '.git',\n 'dist',\n 'build',\n '.next',\n 'coverage',\n '__pycache__',\n '.wrongstack',\n '.ssh',\n '.gnupg',\n '.aws',\n];\n\ninterface TreeInput {\n path?: string | undefined;\n depth?: number | undefined;\n glob?: string | undefined;\n exclude?: string[] | undefined;\n show_files?: boolean | undefined;\n show_dirs?: boolean | undefined;\n show_hidden?: boolean | undefined;\n}\n\ninterface TreeOutput {\n tree: string;\n total_files: number;\n total_dirs: number;\n truncated: boolean;\n path: string;\n}\n\nexport const treeTool: Tool<TreeInput, TreeOutput> = {\n name: 'tree',\n category: 'Filesystem',\n description:\n 'Display a directory tree of the project (or a subpath). This is the recommended way to explore the high-level structure of a codebase before reading specific files.',\n usageHint:\n 'BEST PRACTICE FOR INITIAL EXPLORATION:\\n\\n' +\n '- Call early when working with an unfamiliar project or module.\\n' +\n '- Tune `depth` (default 3) and use `glob`/`exclude` to focus the view.\\n' +\n '- Prefer this over raw `bash find` or `glob` + manual reading when you need a quick structural overview.\\n' +\n 'Output is truncated for very large trees.',\n permission: 'auto',\n mutating: false,\n capabilities: ['fs.read'],\n timeoutMs: 15_000,\n inputSchema: {\n type: 'object',\n properties: {\n path: {\n type: 'string',\n description: 'Root directory to display the tree from (defaults to project root).',\n },\n depth: {\n type: 'integer',\n description: 'Maximum directory depth to traverse (default 3, use 0 for unlimited).',\n minimum: 0,\n maximum: 20,\n },\n glob: {\n type: 'string',\n description: 'Only include files matching this glob pattern.',\n },\n exclude: {\n type: 'array',\n items: { type: 'string' },\n description: 'List of directory names to completely ignore.',\n },\n show_files: {\n type: 'boolean',\n description: 'Whether to show individual files (default true).',\n },\n show_dirs: {\n type: 'boolean',\n description: 'Whether to show directories (default true).',\n },\n show_hidden: {\n type: 'boolean',\n description: 'Show hidden files starting with . (default: false)',\n },\n },\n },\n async execute(input, ctx, opts) {\n let final: TreeOutput | undefined;\n const executeStream = treeTool.executeStream;\n if (!executeStream) throw new Error('treeTool: stream execution unavailable');\n for await (const ev of executeStream(input, ctx, opts)) {\n if (ev.type === 'final') final = ev.output;\n }\n if (!final) throw new Error('tree: stream ended without final event');\n return final;\n },\n async *executeStream(input, ctx): AsyncGenerator<ToolStreamEvent<TreeOutput>> {\n const basePath = input.path ? safeResolve(input.path, ctx) : ctx.cwd;\n const maxDepth = input.depth ?? 3;\n const showFiles = input.show_files ?? true;\n const showDirs = input.show_dirs ?? true;\n const showHidden = input.show_hidden ?? false;\n const exclude = new Set([...DEFAULT_IGNORE, ...(input.exclude ?? [])]);\n const filterGlob = input.glob;\n\n const lines: string[] = [basePath];\n const totals = { totalFiles: { value: 0 }, totalDirs: { value: 0 } };\n\n // Walker pushes progress into an async queue; the generator drains it.\n const queue: ToolProgressEvent[] = [];\n const FLUSH_EVERY = 200; // emit metric every 200 entries seen\n let lastEmittedTotal = 0;\n\n const tickProgress = () => {\n const seen = totals.totalFiles.value + totals.totalDirs.value;\n if (seen - lastEmittedTotal >= FLUSH_EVERY) {\n queue.push({\n type: 'metric',\n text: `${seen} entries`,\n data: { files: totals.totalFiles.value, dirs: totals.totalDirs.value },\n });\n lastEmittedTotal = seen;\n }\n };\n\n const walkPromise = walkDir(basePath, 0, {\n maxDepth,\n exclude,\n showFiles,\n showDirs,\n showHidden,\n filterGlob,\n lines,\n prefix: '',\n isLast: true,\n totalFiles: totals.totalFiles,\n totalDirs: totals.totalDirs,\n onProgress: tickProgress,\n });\n\n // Race the walk against periodic flushes — yield metrics while it runs.\n let walkDone = false;\n walkPromise.finally(() => {\n walkDone = true;\n });\n\n while (!walkDone || queue.length > 0) {\n if (queue.length > 0) {\n yield expectDefined(queue.shift());\n } else {\n // Race the walk completion against a short tick so we don't busy-\n // spin while the producer fills the queue. Previously the\n // setTimeout was never cleared when walkPromise won — one stray\n // timer per drain iteration accumulated on the event loop.\n let pollTimer: ReturnType<typeof setTimeout> | undefined;\n const poll = new Promise<void>((r) => {\n pollTimer = setTimeout(r, 50);\n });\n try {\n await Promise.race([walkPromise, poll]).catch(() => undefined);\n } finally {\n if (pollTimer) clearTimeout(pollTimer);\n }\n }\n }\n await walkPromise; // surface any error\n\n yield {\n type: 'final',\n output: {\n tree: lines.join('\\n'),\n total_files: totals.totalFiles.value,\n total_dirs: totals.totalDirs.value,\n truncated: false,\n path: basePath,\n },\n };\n },\n};\n\ninterface WalkOptions {\n maxDepth: number;\n exclude: Set<string>;\n showFiles: boolean;\n showDirs: boolean;\n showHidden: boolean;\n filterGlob?: string | undefined;\n lines: string[];\n prefix: string;\n isLast: boolean;\n totalFiles: { value: number };\n totalDirs: { value: number };\n onProgress?: (() => void) | undefined;\n}\n\nasync function walkDir(dir: string, depth: number, opts: WalkOptions): Promise<void> {\n const entries = await fs\n .readdir(dir, { withFileTypes: true })\n .catch(() => [] as import('node:fs').Dirent[]);\n\n const filtered = entries.filter((e) => {\n if (!opts.showHidden && e.name.startsWith('.')) return false;\n if (opts.exclude.has(e.name)) return false;\n return true;\n });\n\n if (depth > 0) {\n const dirCount = filtered.filter((e) => e.isDirectory()).length;\n const fileCount = filtered.filter((e) => e.isFile()).length;\n opts.totalDirs.value += dirCount;\n opts.totalFiles.value += fileCount;\n opts.onProgress?.();\n }\n\n const items = filtered.sort((a, b) => {\n if (a.isDirectory() && !b.isDirectory()) return -1;\n if (!a.isDirectory() && b.isDirectory()) return 1;\n return a.name.localeCompare(b.name);\n });\n\n for (let i = 0; i < items.length; i++) {\n const entry = items[i];\n if (!entry) continue;\n const isLast = i === items.length - 1;\n const connector = opts.isLast ? ' ' : '│ ';\n const branch = isLast ? '└── ' : '├── ';\n const displayName = entry.name + (entry.isDirectory() ? '/' : '');\n\n if (!opts.showDirs && entry.isDirectory()) continue;\n if (!opts.showFiles && entry.isFile()) continue;\n\n opts.lines.push(opts.prefix + branch + displayName);\n\n if (entry.isDirectory() && (opts.maxDepth === 0 || depth < opts.maxDepth)) {\n const childPrefix = opts.prefix + connector;\n await walkDir(path.join(dir, entry.name), depth + 1, {\n ...opts,\n prefix: childPrefix,\n isLast,\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/_util.ts","../src/tree.ts"],"names":["path2"],"mappings":";;;;;;AA8BO,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,UAAA,IAAc,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AACvG;AAOA,SAAS,aAAa,GAAA,EAAwB;AAC5C,EAAA,OAAO,CAAM,aAAQ,GAAA,CAAI,WAAW,GAAQ,IAAA,CAAA,OAAA,CAAa,IAAA,CAAA,gBAAA,EAAkB,CAAC,CAAA;AAC9E;AAGA,SAAS,WAAA,CAAY,QAAgB,KAAA,EAA0B;AAC7D,EAAA,OAAO,KAAA,CAAM,IAAA,CAAK,CAAC,IAAA,KAAS;AAC1B,IAAA,MAAM,GAAA,GAAW,IAAA,CAAA,QAAA,CAAS,IAAA,EAAM,MAAM,CAAA;AACtC,IAAA,OAAO,GAAA,KAAQ,MAAO,CAAC,GAAA,CAAI,WAAW,IAAI,CAAA,IAAK,CAAM,IAAA,CAAA,UAAA,CAAW,GAAG,CAAA;AAAA,EACrE,CAAC,CAAA;AACH;AAEO,SAAS,gBAAA,CAAiB,SAAiB,GAAA,EAAsB;AACtE,EAAA,MAAM,MAAA,GAAc,aAAQ,OAAO,CAAA;AAEnC,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\nimport type { Context } from '@wrongstack/core';\n/** Detected package manager for a project directory. */\nexport type PackageManager = 'pnpm' | 'yarn' | 'npm';\n\n/**\n * Detect the project's package manager by inspecting lockfiles in `cwd`.\n * Order: pnpm → yarn → npm (default). Missing or unreadable directories fall\n * back to `npm` rather than throwing, so a `safeResolve`-checked cwd that\n * happens to be empty never aborts the tool.\n */\nexport async function detectPackageManager(cwd: string): Promise<PackageManager> {\n const { stat } = await import('node:fs/promises');\n try {\n await stat(`${cwd}/pnpm-lock.yaml`);\n return 'pnpm';\n } catch {\n /* not pnpm */\n }\n try {\n await stat(`${cwd}/yarn.lock`);\n return 'yarn';\n } catch {\n /* not yarn */\n }\n return 'npm';\n}\n\nexport function resolvePath(input: string, ctx: Context): string {\n return path.isAbsolute(input) ? path.normalize(input) : path.resolve(ctx.workingDir ?? ctx.cwd, input);\n}\n\n/**\n * Roots every file tool may always reach, even in restricted mode: the\n * project root and the user-global `~/.wrongstack` directory (config, memory,\n * sessions, skills). `~/.wrongstack` honors the `WRONGSTACK_HOME` override.\n */\nfunction allowedRoots(ctx: Context): string[] {\n return [path.resolve(ctx.projectRoot), path.resolve(Core.wstackGlobalRoot())];\n}\n\n/** True if `target` is `root` itself or nested inside any of `roots`. */\nfunction isInsideAny(target: string, roots: string[]): boolean {\n return roots.some((root) => {\n const rel = path.relative(root, target);\n return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));\n });\n}\n\nexport function ensureInsideRoot(absPath: string, ctx: Context): string {\n const target = path.resolve(absPath);\n // Unrestricted filesystem access: skip the project-root containment check.\n if (ctx.allowOutsideProjectRoot) return target;\n if (isInsideAny(target, allowedRoots(ctx))) return target;\n throw new Error(`Path \"${absPath}\" is outside project root \"${path.resolve(ctx.projectRoot)}\"`);\n}\n\nexport function safeResolve(input: string, ctx: Context): string {\n return ensureInsideRoot(resolvePath(input, ctx), ctx);\n}\n\n/**\n * Defense against in-root→out-of-root symlink escape (CWE-59). `safeResolve`\n * only does a syntactic `../` check, so a symlink that lives *inside* the\n * project root but points outside still passes it. This resolves the path\n * through `fs.realpath` and re-verifies containment against the realpath of\n * the project root (comparing like-for-like, since the root itself may be a\n * symlink — macOS `/var`→`/private/var`, Windows 8.3 short names). For a path\n * that does not exist yet (e.g. a `write` to a new file) the nearest existing\n * ancestor directory is checked instead. Throws if the real target escapes.\n *\n * Mirrors the per-file guard already used in `replace.ts`/`grep.ts`; applied\n * to single-file `read`/`edit`/`write` it throws (rather than skips) because\n * the caller named exactly one file.\n */\nexport async function assertRealInsideRoot(absPath: string, ctx: Context): Promise<void> {\n // Unrestricted filesystem access: no symlink-escape check to perform.\n if (ctx.allowOutsideProjectRoot) return;\n // Compare like-for-like against the realpath of each always-allowed root\n // (project root + ~/.wrongstack), since a root may itself be a symlink.\n const realRoots = await Promise.all(\n allowedRoots(ctx).map((r) => fsp.realpath(r).catch(() => path.resolve(r))),\n );\n let probe = absPath;\n for (;;) {\n let real: string;\n try {\n real = await fsp.realpath(probe);\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n const parent = path.dirname(probe);\n if (parent === probe) return; // reached fs root without escaping\n probe = parent;\n continue;\n }\n throw err;\n }\n if (isInsideAny(real, realRoots)) return;\n throw new Error(\n `Path \"${absPath}\" resolves through a symlink outside project root \"${realRoots[0]}\"`,\n );\n }\n}\n\n/** `safeResolve` + symlink realpath containment check. Async. */\nexport async function safeResolveReal(input: string, ctx: Context): Promise<string> {\n const abs = safeResolve(input, ctx);\n await assertRealInsideRoot(abs, ctx);\n return abs;\n}\n\nexport function truncateMiddle(s: string, max: number): string {\n if (Buffer.byteLength(s, 'utf8') <= max) return s;\n const half = Math.floor(max / 2);\n return (\n s.slice(0, half) +\n `\\n…[truncated ${Buffer.byteLength(s, 'utf8') - max} bytes from middle]…\\n` +\n s.slice(-half)\n );\n}\n\nexport function isBinaryBuffer(buf: Buffer): boolean {\n const len = Math.min(buf.length, 8192);\n for (let i = 0; i < len; i++) {\n if (buf[i] === 0) return true;\n }\n return false;\n}\n\n// ─── Command-output normalization (token-saving) ────────────────────────────\n//\n// Raw process output is full of tokens the model gains nothing from: ANSI\n// escapes, carriage-return progress spam, runs of identical warning lines, and\n// huge tails of build noise. These helpers strip that noise before the output\n// reaches the LLM. They are scoped to COMMAND tools (bash/git/exec and the\n// _spawn-stream consumers) — never applied to structured/code outputs.\n\n/** Unified byte cap for all command tool output fed to the model. */\nexport const COMMAND_OUTPUT_MAX_BYTES = 32_768;\n\n/** Runs of >= this many identical consecutive lines are collapsed. */\nconst REPEAT_RUN_THRESHOLD = 3;\n\n/**\n * Collapse carriage-return overwrites the way a terminal would: `\\r\\n` becomes\n * `\\n`, and a bare `\\r` (progress redraw) keeps only the text after the LAST\n * `\\r` on its physical line. Without this, a single progress bar that redraws\n * 200 times explodes into 200 lines.\n */\nexport function collapseCarriageReturns(text: string): string {\n const lf = text.replace(/\\r\\n/g, '\\n');\n if (!lf.includes('\\r')) return lf;\n return lf\n .split('\\n')\n .map((line) => (line.includes('\\r') ? line.slice(line.lastIndexOf('\\r') + 1) : line))\n .join('\\n');\n}\n\n/**\n * Collapse a run of `minRun`+ identical consecutive lines into the line once\n * plus a marker. Consecutive-only — it never reorders or dedups non-adjacent\n * lines, so diffs/source stay intact.\n */\nexport function collapseConsecutiveDuplicates(text: string, minRun = REPEAT_RUN_THRESHOLD): string {\n const lines = text.split('\\n');\n const out: string[] = [];\n let i = 0;\n while (i < lines.length) {\n let j = i + 1;\n while (j < lines.length && lines[j] === lines[i]) j++;\n const run = j - i;\n if (run >= minRun) {\n out.push(lines[i]!, `… ⟨repeated ${run}×⟩`);\n } else {\n for (let k = i; k < j; k++) out.push(lines[k]!);\n }\n i = j;\n }\n return out.join('\\n');\n}\n\n/** Largest prefix of `s` whose UTF-8 byte length is <= `maxBytes`. */\nfunction takeHeadBytes(s: string, maxBytes: number): string {\n if (maxBytes <= 0) return '';\n /* v8 ignore next -- only caller (truncateHeadTail) passes a budget smaller than s; defensive. */\n if (Buffer.byteLength(s, 'utf8') <= maxBytes) return s;\n let lo = 0;\n let hi = s.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (Buffer.byteLength(s.slice(0, mid), 'utf8') <= maxBytes) lo = mid;\n else hi = mid - 1;\n }\n return s.slice(0, lo);\n}\n\n/** Largest suffix of `s` whose UTF-8 byte length is <= `maxBytes`. */\nfunction takeTailBytes(s: string, maxBytes: number): string {\n if (maxBytes <= 0) return '';\n /* v8 ignore next -- only caller (truncateHeadTail) passes a budget smaller than s; defensive. */\n if (Buffer.byteLength(s, 'utf8') <= maxBytes) return s;\n let lo = 0;\n let hi = s.length;\n while (lo < hi) {\n const mid = Math.ceil((lo + hi) / 2);\n if (Buffer.byteLength(s.slice(s.length - mid), 'utf8') <= maxBytes) lo = mid;\n else hi = mid - 1;\n }\n return s.slice(s.length - lo);\n}\n\n/**\n * Truncate to `maxBytes` keeping BOTH ends — the head (what ran / early context)\n * and the tail (errors and summaries usually land last), biased ~45/55 toward\n * the tail. The result never exceeds `maxBytes`.\n */\nexport function truncateHeadTail(s: string, maxBytes: number): string {\n const total = Buffer.byteLength(s, 'utf8');\n if (total <= maxBytes) return s;\n // Reserve a fixed allowance for the marker so the final string can't exceed\n // the cap even though the dropped-byte count's digit width varies.\n const MARKER_RESERVE = 64;\n const avail = Math.max(0, maxBytes - MARKER_RESERVE);\n const headBudget = Math.floor(avail * 0.45);\n const head = takeHeadBytes(s, headBudget);\n const tail = takeTailBytes(s, avail - Buffer.byteLength(head, 'utf8'));\n const kept = Buffer.byteLength(head, 'utf8') + Buffer.byteLength(tail, 'utf8');\n return `${head}\\n…[truncated ${total - kept} bytes]…\\n${tail}`;\n}\n\n/**\n * Full token-saving pipeline for command tool output: strip ANSI → collapse\n * carriage-return progress → trim trailing whitespace → collapse identical\n * consecutive lines → squeeze blank-line runs → head+tail truncate to the cap.\n */\nexport function normalizeCommandOutput(\n raw: string,\n opts: { maxBytes?: number | undefined } = {},\n): string {\n if (!raw) return raw;\n let text = Core.stripAnsi(raw);\n text = collapseCarriageReturns(text);\n text = text.replace(/[ \\t]+$/gm, ''); // trailing whitespace per line\n text = collapseConsecutiveDuplicates(text);\n text = text.replace(/\\n{3,}/g, '\\n\\n'); // >=2 blank lines → 1\n return truncateHeadTail(text, opts.maxBytes ?? COMMAND_OUTPUT_MAX_BYTES);\n}\n","import { expectDefined } from '@wrongstack/core';\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport type { Tool, ToolProgressEvent, ToolStreamEvent } from '@wrongstack/core';\nimport { safeResolve } from './_util.js';\nconst DEFAULT_IGNORE = [\n 'node_modules',\n '.git',\n 'dist',\n 'build',\n '.next',\n 'coverage',\n '__pycache__',\n '.wrongstack',\n '.ssh',\n '.gnupg',\n '.aws',\n];\n\ninterface TreeInput {\n path?: string | undefined;\n depth?: number | undefined;\n glob?: string | undefined;\n exclude?: string[] | undefined;\n show_files?: boolean | undefined;\n show_dirs?: boolean | undefined;\n show_hidden?: boolean | undefined;\n}\n\ninterface TreeOutput {\n tree: string;\n total_files: number;\n total_dirs: number;\n truncated: boolean;\n path: string;\n}\n\nexport const treeTool: Tool<TreeInput, TreeOutput> = {\n name: 'tree',\n category: 'Filesystem',\n description:\n 'Display a directory tree of the project (or a subpath). This is the recommended way to explore the high-level structure of a codebase before reading specific files.',\n usageHint:\n 'BEST PRACTICE FOR INITIAL EXPLORATION:\\n\\n' +\n '- Call early when working with an unfamiliar project or module.\\n' +\n '- Tune `depth` (default 3) and use `glob`/`exclude` to focus the view.\\n' +\n '- Prefer this over raw `bash find` or `glob` + manual reading when you need a quick structural overview.\\n' +\n 'Output is truncated for very large trees.',\n permission: 'auto',\n mutating: false,\n capabilities: ['fs.read'],\n icon: 'tree',\n timeoutMs: 15_000,\n inputSchema: {\n type: 'object',\n properties: {\n path: {\n type: 'string',\n description: 'Root directory to display the tree from (defaults to project root).',\n },\n depth: {\n type: 'integer',\n description: 'Maximum directory depth to traverse (default 3, use 0 for unlimited).',\n minimum: 0,\n maximum: 20,\n },\n glob: {\n type: 'string',\n description: 'Only include files matching this glob pattern.',\n },\n exclude: {\n type: 'array',\n items: { type: 'string' },\n description: 'List of directory names to completely ignore.',\n },\n show_files: {\n type: 'boolean',\n description: 'Whether to show individual files (default true).',\n },\n show_dirs: {\n type: 'boolean',\n description: 'Whether to show directories (default true).',\n },\n show_hidden: {\n type: 'boolean',\n description: 'Show hidden files starting with . (default: false)',\n },\n },\n },\n async execute(input, ctx, opts) {\n let final: TreeOutput | undefined;\n const executeStream = treeTool.executeStream;\n if (!executeStream) throw new Error('treeTool: stream execution unavailable');\n for await (const ev of executeStream(input, ctx, opts)) {\n if (ev.type === 'final') final = ev.output;\n }\n if (!final) throw new Error('tree: stream ended without final event');\n return final;\n },\n async *executeStream(input, ctx): AsyncGenerator<ToolStreamEvent<TreeOutput>> {\n const basePath = input.path ? safeResolve(input.path, ctx) : ctx.cwd;\n const maxDepth = input.depth ?? 3;\n const showFiles = input.show_files ?? true;\n const showDirs = input.show_dirs ?? true;\n const showHidden = input.show_hidden ?? false;\n const exclude = new Set([...DEFAULT_IGNORE, ...(input.exclude ?? [])]);\n const filterGlob = input.glob;\n\n const lines: string[] = [basePath];\n const totals = { totalFiles: { value: 0 }, totalDirs: { value: 0 } };\n\n // Walker pushes progress into an async queue; the generator drains it.\n const queue: ToolProgressEvent[] = [];\n const FLUSH_EVERY = 200; // emit metric every 200 entries seen\n let lastEmittedTotal = 0;\n\n const tickProgress = () => {\n const seen = totals.totalFiles.value + totals.totalDirs.value;\n if (seen - lastEmittedTotal >= FLUSH_EVERY) {\n queue.push({\n type: 'metric',\n text: `${seen} entries`,\n data: { files: totals.totalFiles.value, dirs: totals.totalDirs.value },\n });\n lastEmittedTotal = seen;\n }\n };\n\n const walkPromise = walkDir(basePath, 0, {\n maxDepth,\n exclude,\n showFiles,\n showDirs,\n showHidden,\n filterGlob,\n lines,\n prefix: '',\n isLast: true,\n totalFiles: totals.totalFiles,\n totalDirs: totals.totalDirs,\n onProgress: tickProgress,\n });\n\n // Race the walk against periodic flushes — yield metrics while it runs.\n let walkDone = false;\n walkPromise.finally(() => {\n walkDone = true;\n });\n\n while (!walkDone || queue.length > 0) {\n if (queue.length > 0) {\n yield expectDefined(queue.shift());\n } else {\n // Race the walk completion against a short tick so we don't busy-\n // spin while the producer fills the queue. Previously the\n // setTimeout was never cleared when walkPromise won — one stray\n // timer per drain iteration accumulated on the event loop.\n let pollTimer: ReturnType<typeof setTimeout> | undefined;\n const poll = new Promise<void>((r) => {\n pollTimer = setTimeout(r, 50);\n });\n try {\n await Promise.race([walkPromise, poll]).catch(() => undefined);\n } finally {\n if (pollTimer) clearTimeout(pollTimer);\n }\n }\n }\n await walkPromise; // surface any error\n\n yield {\n type: 'final',\n output: {\n tree: lines.join('\\n'),\n total_files: totals.totalFiles.value,\n total_dirs: totals.totalDirs.value,\n truncated: false,\n path: basePath,\n },\n };\n },\n};\n\ninterface WalkOptions {\n maxDepth: number;\n exclude: Set<string>;\n showFiles: boolean;\n showDirs: boolean;\n showHidden: boolean;\n filterGlob?: string | undefined;\n lines: string[];\n prefix: string;\n isLast: boolean;\n totalFiles: { value: number };\n totalDirs: { value: number };\n onProgress?: (() => void) | undefined;\n}\n\nasync function walkDir(dir: string, depth: number, opts: WalkOptions): Promise<void> {\n const entries = await fs\n .readdir(dir, { withFileTypes: true })\n .catch(() => [] as import('node:fs').Dirent[]);\n\n const filtered = entries.filter((e) => {\n if (!opts.showHidden && e.name.startsWith('.')) return false;\n if (opts.exclude.has(e.name)) return false;\n return true;\n });\n\n if (depth > 0) {\n const dirCount = filtered.filter((e) => e.isDirectory()).length;\n const fileCount = filtered.filter((e) => e.isFile()).length;\n opts.totalDirs.value += dirCount;\n opts.totalFiles.value += fileCount;\n opts.onProgress?.();\n }\n\n const items = filtered.sort((a, b) => {\n if (a.isDirectory() && !b.isDirectory()) return -1;\n if (!a.isDirectory() && b.isDirectory()) return 1;\n return a.name.localeCompare(b.name);\n });\n\n for (let i = 0; i < items.length; i++) {\n const entry = items[i];\n /* v8 ignore next -- i is bounded by items.length, so entry is always defined; defensive. */\n if (!entry) continue;\n const isLast = i === items.length - 1;\n const connector = opts.isLast ? ' ' : '│ ';\n const branch = isLast ? '└── ' : '├── ';\n const displayName = entry.name + (entry.isDirectory() ? '/' : '');\n\n if (!opts.showDirs && entry.isDirectory()) continue;\n if (!opts.showFiles && entry.isFile()) continue;\n\n opts.lines.push(opts.prefix + branch + displayName);\n\n if (entry.isDirectory() && (opts.maxDepth === 0 || depth < opts.maxDepth)) {\n const childPrefix = opts.prefix + connector;\n await walkDir(path.join(dir, entry.name), depth + 1, {\n ...opts,\n prefix: childPrefix,\n isLast,\n });\n }\n }\n}\n"]}
|
package/dist/typecheck.js
CHANGED
|
@@ -131,6 +131,23 @@ var CircuitBreaker = class {
|
|
|
131
131
|
lastSlowAt = null;
|
|
132
132
|
/** Timestamp when the breaker was opened (for cooldown calculation). */
|
|
133
133
|
openedAt = null;
|
|
134
|
+
/**
|
|
135
|
+
* Master enable flag. When false the breaker is bypassed: `beforeCall`
|
|
136
|
+
* always returns true and `afterCall` records nothing. The class itself
|
|
137
|
+
* defaults to enabled (so the standalone unit tests exercise tripping); the
|
|
138
|
+
* ProcessRegistry flips this off until the user opts in via `/settings`.
|
|
139
|
+
*/
|
|
140
|
+
enabled = true;
|
|
141
|
+
/**
|
|
142
|
+
* Fired (best-effort) when the breaker transitions into the `open` state.
|
|
143
|
+
* The registry uses this to arm its auto kill/reset countdown.
|
|
144
|
+
*/
|
|
145
|
+
onTrip;
|
|
146
|
+
/**
|
|
147
|
+
* Fired (best-effort) when the breaker returns to `closed` after having been
|
|
148
|
+
* open/half-open. The registry uses this to cancel a pending kill/reset.
|
|
149
|
+
*/
|
|
150
|
+
onReset;
|
|
134
151
|
constructor(config = {}) {
|
|
135
152
|
this.maxConsecutiveFailures = config.maxConsecutiveFailures ?? DEFAULT_MAX_CONSECUTIVE_FAILURES;
|
|
136
153
|
this.slowCallThresholdMs = config.slowCallThresholdMs ?? DEFAULT_SLOW_CALL_THRESHOLD_MS;
|
|
@@ -139,12 +156,22 @@ var CircuitBreaker = class {
|
|
|
139
156
|
this.maxCallsPerWindow = config.maxCallsPerWindow ?? DEFAULT_MAX_CALLS_PER_WINDOW;
|
|
140
157
|
this.cooldownMs = config.cooldownMs ?? DEFAULT_COOLDOWN_MS;
|
|
141
158
|
}
|
|
159
|
+
/** Toggle the master enable. Disabling resets to a clean `closed` state. */
|
|
160
|
+
setEnabled(enabled) {
|
|
161
|
+
if (this.enabled === enabled) return;
|
|
162
|
+
this.enabled = enabled;
|
|
163
|
+
if (!enabled) this._reset();
|
|
164
|
+
}
|
|
165
|
+
get isEnabled() {
|
|
166
|
+
return this.enabled;
|
|
167
|
+
}
|
|
142
168
|
/**
|
|
143
169
|
* Returns true if the circuit allows a new call to proceed.
|
|
144
170
|
* When false, callers should abort the tool call and return a
|
|
145
171
|
* circuit-breaker error instead of spawning a process.
|
|
146
172
|
*/
|
|
147
173
|
get canProceed() {
|
|
174
|
+
if (!this.enabled) return true;
|
|
148
175
|
this._checkStateTransition();
|
|
149
176
|
return this.state !== "open";
|
|
150
177
|
}
|
|
@@ -180,7 +207,7 @@ var CircuitBreaker = class {
|
|
|
180
207
|
* not affect breaker state.
|
|
181
208
|
*/
|
|
182
209
|
beforeCall(bypass = false) {
|
|
183
|
-
if (bypass) return true;
|
|
210
|
+
if (bypass || !this.enabled) return true;
|
|
184
211
|
this._checkStateTransition();
|
|
185
212
|
if (this.state === "open") return false;
|
|
186
213
|
return true;
|
|
@@ -195,7 +222,7 @@ var CircuitBreaker = class {
|
|
|
195
222
|
* Use for background/fire-and-forget processes.
|
|
196
223
|
*/
|
|
197
224
|
afterCall(durationMs, failed, bypass = false) {
|
|
198
|
-
if (bypass) return;
|
|
225
|
+
if (bypass || !this.enabled) return;
|
|
199
226
|
const now = Date.now();
|
|
200
227
|
if (this.state === "half-open") {
|
|
201
228
|
if (failed) {
|
|
@@ -241,12 +268,23 @@ var CircuitBreaker = class {
|
|
|
241
268
|
if (this.state === "open") return;
|
|
242
269
|
this.state = "open";
|
|
243
270
|
this.openedAt = Date.now();
|
|
271
|
+
try {
|
|
272
|
+
this.onTrip?.();
|
|
273
|
+
} catch {
|
|
274
|
+
}
|
|
244
275
|
}
|
|
245
276
|
_reset() {
|
|
277
|
+
const wasRecovering = this.state !== "closed";
|
|
246
278
|
this.state = "closed";
|
|
247
279
|
this.consecutiveFailures = 0;
|
|
248
280
|
this.window = [];
|
|
249
281
|
this.openedAt = null;
|
|
282
|
+
if (wasRecovering) {
|
|
283
|
+
try {
|
|
284
|
+
this.onReset?.();
|
|
285
|
+
} catch {
|
|
286
|
+
}
|
|
287
|
+
}
|
|
250
288
|
}
|
|
251
289
|
/** Transition from open → half-open when cooldown elapses. */
|
|
252
290
|
_checkStateTransition() {
|
|
@@ -308,8 +346,21 @@ function killWin32Tree(pid) {
|
|
|
308
346
|
var ProcessRegistryImpl = class {
|
|
309
347
|
processes = /* @__PURE__ */ new Map();
|
|
310
348
|
breaker;
|
|
349
|
+
/**
|
|
350
|
+
* Auto kill/reset config. When the breaker trips and `autoKillResetMs > 0`,
|
|
351
|
+
* a countdown is armed; on expiry all tracked processes are killed and the
|
|
352
|
+
* breaker is reset to closed (forced recovery). Zero means manual recovery
|
|
353
|
+
* only (`/kill reset`).
|
|
354
|
+
*/
|
|
355
|
+
autoKillResetMs = 0;
|
|
356
|
+
autoKillTimer = null;
|
|
357
|
+
autoKillArmedAt = null;
|
|
358
|
+
breakerCountdownListeners = [];
|
|
311
359
|
constructor(breakerConfig) {
|
|
312
360
|
this.breaker = new CircuitBreaker(breakerConfig);
|
|
361
|
+
this.breaker.onTrip = () => this._armAutoKillReset();
|
|
362
|
+
this.breaker.onReset = () => this._cancelAutoKillReset();
|
|
363
|
+
this.breaker.setEnabled(false);
|
|
313
364
|
}
|
|
314
365
|
register(info) {
|
|
315
366
|
this.processes.set(info.pid, { ...info, killed: false, protected: info.protected ?? false });
|
|
@@ -385,6 +436,90 @@ var ProcessRegistryImpl = class {
|
|
|
385
436
|
forceBreakerReset() {
|
|
386
437
|
this.breaker.forceReset();
|
|
387
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Configure circuit-breaker protection at runtime. Called from `/settings`
|
|
441
|
+
* (instant, all modes) and on TUI mount (applies persisted config).
|
|
442
|
+
*
|
|
443
|
+
* - `enabled` toggles whether the breaker gates `bash`/`exec`.
|
|
444
|
+
* - `autoKillResetMs` arms the auto kill/reset countdown when the breaker
|
|
445
|
+
* trips (0 = manual recovery only).
|
|
446
|
+
*
|
|
447
|
+
* Re-applies cleanly on every call: cancels a pending countdown when the
|
|
448
|
+
* timeout is cleared or protection disabled, and re-arms if the breaker is
|
|
449
|
+
* currently open under the new settings.
|
|
450
|
+
*/
|
|
451
|
+
setBreakerConfig(cfg) {
|
|
452
|
+
if (cfg.enabled !== void 0) this.breaker.setEnabled(cfg.enabled);
|
|
453
|
+
if (cfg.autoKillResetMs !== void 0) this.autoKillResetMs = Math.max(0, cfg.autoKillResetMs);
|
|
454
|
+
if (this.autoKillResetMs <= 0) {
|
|
455
|
+
this._cancelAutoKillReset();
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (this.breaker.isEnabled && this.breaker.snapshot().state === "open") {
|
|
459
|
+
this._armAutoKillReset();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Live countdown to the next auto kill/reset, or null when nothing is armed.
|
|
464
|
+
* The TUI polls this on a 1s tick while armed so the statusline decrements.
|
|
465
|
+
*/
|
|
466
|
+
getBreakerCountdown() {
|
|
467
|
+
if (this.autoKillArmedAt === null || this.autoKillResetMs <= 0) return null;
|
|
468
|
+
const elapsed = Date.now() - this.autoKillArmedAt;
|
|
469
|
+
return { remainingMs: Math.max(0, this.autoKillResetMs - elapsed), totalMs: this.autoKillResetMs };
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Subscribe to countdown arm/cancel events. Returns an unsubscribe function.
|
|
473
|
+
* Use {@link getBreakerCountdown} for the live ticking value between events.
|
|
474
|
+
*/
|
|
475
|
+
onBreakerCountdownChange(listener) {
|
|
476
|
+
this.breakerCountdownListeners.push(listener);
|
|
477
|
+
return () => {
|
|
478
|
+
this.breakerCountdownListeners = this.breakerCountdownListeners.filter((l) => l !== listener);
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
_emitBreakerCountdown() {
|
|
482
|
+
const snap = this.getBreakerCountdown();
|
|
483
|
+
for (const l of this.breakerCountdownListeners) {
|
|
484
|
+
try {
|
|
485
|
+
l(snap);
|
|
486
|
+
} catch {
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Arm the auto kill/reset countdown. Idempotent: re-arming resets the window
|
|
492
|
+
* (a fresh trip after a failed half-open probe restarts the clock). No-op
|
|
493
|
+
* when protection is off or no timeout is configured.
|
|
494
|
+
*/
|
|
495
|
+
_armAutoKillReset() {
|
|
496
|
+
if (this.autoKillResetMs <= 0 || !this.breaker.isEnabled) return;
|
|
497
|
+
this._clearAutoKillTimer();
|
|
498
|
+
this.autoKillArmedAt = Date.now();
|
|
499
|
+
this.autoKillTimer = setTimeout(() => {
|
|
500
|
+
this.autoKillTimer = null;
|
|
501
|
+
this.autoKillArmedAt = null;
|
|
502
|
+
this.killAll({ force: false });
|
|
503
|
+
this.breaker.forceReset();
|
|
504
|
+
this._emitBreakerCountdown();
|
|
505
|
+
}, this.autoKillResetMs);
|
|
506
|
+
this.autoKillTimer.unref?.();
|
|
507
|
+
this._emitBreakerCountdown();
|
|
508
|
+
}
|
|
509
|
+
_cancelAutoKillReset() {
|
|
510
|
+
const wasArmed = this.autoKillArmedAt !== null;
|
|
511
|
+
this._clearAutoKillTimer();
|
|
512
|
+
if (wasArmed) {
|
|
513
|
+
this.autoKillArmedAt = null;
|
|
514
|
+
this._emitBreakerCountdown();
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
_clearAutoKillTimer() {
|
|
518
|
+
if (this.autoKillTimer !== null) {
|
|
519
|
+
clearTimeout(this.autoKillTimer);
|
|
520
|
+
this.autoKillTimer = null;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
388
523
|
/** Kill a single process by PID.
|
|
389
524
|
*
|
|
390
525
|
* On POSIX: sends SIGTERM to the *process group* (-pid) so that
|
|
@@ -523,8 +658,9 @@ async function* spawnStream(opts) {
|
|
|
523
658
|
let pending = "";
|
|
524
659
|
let error;
|
|
525
660
|
const spool = createOutputSpool({ tool: opts.cmd, thresholdBytes: max });
|
|
526
|
-
const
|
|
527
|
-
const needsShell = isWin && (
|
|
661
|
+
const resolved = resolveWin32Command(opts.cmd);
|
|
662
|
+
const needsShell = isWin && (resolved.endsWith(".cmd") || resolved.endsWith(".bat"));
|
|
663
|
+
const cmd = needsShell ? opts.cmd : resolved;
|
|
528
664
|
const child = spawn(cmd, opts.args, {
|
|
529
665
|
cwd: opts.cwd,
|
|
530
666
|
env: buildChildEnv(),
|
|
@@ -674,14 +810,20 @@ async function* spawnStream(opts) {
|
|
|
674
810
|
function resolvePath(input, ctx) {
|
|
675
811
|
return path3.isAbsolute(input) ? path3.normalize(input) : path3.resolve(ctx.workingDir ?? ctx.cwd, input);
|
|
676
812
|
}
|
|
813
|
+
function allowedRoots(ctx) {
|
|
814
|
+
return [path3.resolve(ctx.projectRoot), path3.resolve(Core.wstackGlobalRoot())];
|
|
815
|
+
}
|
|
816
|
+
function isInsideAny(target, roots) {
|
|
817
|
+
return roots.some((root) => {
|
|
818
|
+
const rel = path3.relative(root, target);
|
|
819
|
+
return rel === "" || !rel.startsWith("..") && !path3.isAbsolute(rel);
|
|
820
|
+
});
|
|
821
|
+
}
|
|
677
822
|
function ensureInsideRoot(absPath, ctx) {
|
|
678
|
-
const root = path3.resolve(ctx.projectRoot);
|
|
679
823
|
const target = path3.resolve(absPath);
|
|
680
|
-
|
|
681
|
-
if (
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
return target;
|
|
824
|
+
if (ctx.allowOutsideProjectRoot) return target;
|
|
825
|
+
if (isInsideAny(target, allowedRoots(ctx))) return target;
|
|
826
|
+
throw new Error(`Path "${absPath}" is outside project root "${path3.resolve(ctx.projectRoot)}"`);
|
|
685
827
|
}
|
|
686
828
|
function safeResolve(input, ctx) {
|
|
687
829
|
return ensureInsideRoot(resolvePath(input, ctx), ctx);
|
|
@@ -767,6 +909,7 @@ var typecheckTool = {
|
|
|
767
909
|
mutating: false,
|
|
768
910
|
timeoutMs: 12e4,
|
|
769
911
|
capabilities: ["shell.restricted"],
|
|
912
|
+
icon: "code",
|
|
770
913
|
inputSchema: {
|
|
771
914
|
type: "object",
|
|
772
915
|
properties: {
|