Files
ruvnet--ruflo/scripts/bulk-fix-tool-descriptions.mjs
wehub-resource-sync 23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:02:19 +08:00

188 lines
16 KiB
JavaScript

#!/usr/bin/env node
/**
* ADR-112 Phase 1+2+3 — bulk applier for "Use when …" guidance suffixes.
*
* For each MCP tool name we know its category (agent / memory / agentdb /
* workflow / hooks / swarm / embeddings / claims / browser / cost /
* intelligence / aidefence / autopilot / federation / iot-cognitum / wasm /
* ruvllm / config / session / hive-mind / coordination / system / mcp /
* neural / progress / claims / transfer / daa / performance / analyze /
* guidance / ruvllm), and for each category we know the native-tool overlap
* and the Ruflo value-add. The script appends a category-appropriate
* "Use when … is wrong because …" suffix to any description that doesn't
* already include "Use when" / "Prefer over" / "Pair with" / "fall back".
*
* The script never modifies descriptions that already have guidance —
* agent_spawn, agent_execute, the seven we hand-wrote, etc.
*
* Run:
* node scripts/bulk-fix-tool-descriptions.mjs # dry-run
* node scripts/bulk-fix-tool-descriptions.mjs --write # apply
*/
import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
const TOOLS_DIR = 'v3/@claude-flow/cli/src/mcp-tools';
const WRITE = process.argv.includes('--write');
const GUIDANCE_RE = /Use when|Prefer .* over|Pair with|fall back|native .* is (fine|wrong)/i;
// Category → "Use when …" suffix. Each suffix names the native overlap (if
// any) and the Ruflo value-add. Honest about when native is fine — that
// keeps Claude's trust in our guidance.
const SUFFIX = {
// -------- Memory & persistence --------
memory_: ' Use when native Read/Write is wrong because you need (a) cross-session retrieval by semantic similarity (vector embeddings) not by file path, (b) namespacing across projects without managing directory layout, or (c) the .swarm/memory.db audit trail. For one-shot file I/O, native Read/Write is fine.',
agentdb_: ' Use when generic memory_* tools are wrong because you need AgentDB-specific controllers (HNSW vector search, hierarchical tiers, causal-graph links, pattern store/recall, RaBitQ quantization). For simple key-value persistence, memory_store/memory_retrieve are simpler. For unrelated file work, native Read/Write are fine.',
embeddings_: ' Use when text similarity matters beyond keyword match — native Grep finds exact strings, embeddings find meaning. Pair with memory_store / agentdb_pattern-search to land the vector against your knowledge base. For literal symbol search, native Grep is faster.',
// -------- Agents & orchestration --------
agent_: ' Use when native Task is wrong because you need agent-lifecycle state (cost-tracking, taskCount across turns, swarm coordination, model routing via 3-tier). For one-shot subagents with no learning loop, native Task is fine.',
swarm_: ' Use when native Task tool is wrong because you need multi-agent coordination — topology (hierarchical/mesh/star), consensus (raft/byzantine/gossip/crdt/quorum), shared memory namespace, or anti-drift gates. For independent one-shot subagents, native Task is fine; spawn each separately.',
task_: ' Use when native TodoWrite is wrong because you need cross-session task persistence, agent assignment, dependency tracking, or completion analytics in the .swarm/memory.db. For in-session checklists native TodoWrite is simpler and faster.',
coordination_: ' Use when native Task is wrong because the work crosses multiple agents that need to vote/sync/load-balance — TodoWrite + a single Task cannot orchestrate consensus. For one-off subtask dispatch, native Task is fine.',
'hive-mind_': ' Use when native Task is wrong because you need queen-led collective intelligence — Byzantine-FT consensus, broadcast across many worker agents, shared memory with bounded conflict. For a single subagent, native Task is fine. Pair with swarm_init first to set topology.',
// -------- Hooks & lifecycle --------
hooks_: ' Use when native Bash hooks (via Claude Code\'s settings.json) are wrong because you need Ruflo-side state — pattern persistence, neural training signals, model-routing learning, cost tracking, audit chain. For one-off shell commands, plain Bash hooks are fine.',
// -------- Sessions --------
session_: ' Use when native conversation memory is wrong because you need durable cross-session state — restoring agent definitions, swarm topology, memory store, breaker history. For in-session continuation only, no tool needed. Pair with session_save before exiting and session_restore on resume.',
// -------- Config / system --------
config_: ' Use when native settings.json edits are wrong because the values need to be read by the Ruflo runtime (daemon, MCP server, neural router) — those load via the config_* path, not by re-reading settings.json. For .gitignore / .editorconfig style files, native Edit is fine.',
system_: ' Use when native Bash is wrong because you need Ruflo runtime metrics (HNSW index size, ReasoningBank state, swarm health, breaker status) — those are not in /proc, only in the running daemon. For OS-level info (uptime, disk, mem), native Bash + standard tools are fine.',
mcp_: ' Use when native Claude Code MCP status is wrong because you need Ruflo-side server detail — tool counts per namespace, transport stats, MCP handshake errors. For just "is MCP up?", `claude mcp list` is fine.',
status_: ' Use when generic Ruflo health checks are wrong because you want a single quick read of overall system state — daemon up?, swarm initialized?, memory db healthy?, federation peers connected? For deep debugging, prefer the dedicated tools each subsystem exposes.',
doctor_: ' Use when generic shell debugging is wrong because you want Ruflo-aware checks — Node/npm versions, daemon, memory DB, API keys, MCP servers, disk space. For unrelated environment troubleshooting, native shell + git/which/env are fine.',
// -------- Workflow --------
workflow_: ' Use when native TodoWrite + sequential Bash is wrong because the work has a real dependency graph that needs persistence, retry policy, pause/resume, and step-output binding across LLM-driven steps. For a single linear todo list, native TodoWrite is fine.',
// -------- Browser --------
browser_: ' Use when native WebFetch is wrong because you need real browser automation — JS-heavy SPA scraping, login flows with cookie reuse, replay against DOM-drifted versions, AIDefence PII gating before content reaches Claude. For static HTML pages, native WebFetch is faster and free.',
// -------- Security & defense --------
aidefence_: ' Use when nothing native exists — Claude Code does not have a PII / prompt-injection / adversarial-text scanner. Pair with any tool that ingests untrusted input (browser scrape, federation envelope, memory_import_claude).',
security_: ' Use when native package-audit (`npm audit`) is wrong because you need Ruflo-aware checks — known-bad dep patterns, secret detection, path-traversal in MCP inputs, witness chain verify. For just listing CVEs in your lockfile, native `npm audit` is fine.',
// -------- Federation --------
federation_: ' Use when nothing native covers cross-installation agent communication — Claude Code talks to its own MCP server only. Pair with federation_init first; once peers are joined, federation_send routes signed envelopes with PII gating, breaker, and audit. For local-only work, no federation tool is needed.',
// -------- Cost tracking --------
cost_: ' Use when native usage estimates are wrong because you need per-agent / per-model / per-task attribution across turns and sessions. The cost-tracking namespace persists between calls; reading the Claude CLI\'s built-in usage shows only the current turn. For one-shot cost checks, the native CLI suffices.',
// -------- Intelligence / neural --------
intelligence_: ' Use when native Task / Read prompting is wrong because you want learned-pattern routing — Ruflo\'s SONA neural router picks tier (Agent Booster / Haiku / Sonnet+Opus) based on past success on similar tasks. Pair with hooks_post-task to feed back outcomes. For one-shot prompts without learning, native Task is fine.',
neural_: ' Use when nothing native trains on your workflow — Claude Code has no learning loop. Use to train SONA/MoE/EWC patterns from successful task outcomes; query via neural_predict before spawning agents. Off-path for one-shot work.',
// -------- Autopilot --------
autopilot_: ' Use when running long-horizon goals that should resume automatically across sessions — Claude Code has no native autonomous-loop scheduler. Pair with autopilot_enable + a goal description, then let cron fires advance the work. For interactive single-task sessions, native Task is fine.',
// -------- DAA --------
daa_: ' Use when native Task is wrong because you need agents that adapt their cognitive pattern (convergent / divergent / lateral / systems / critical) per-task and share knowledge across the swarm. For static one-shot agents, native Task is fine.',
// -------- WASM agents --------
wasm_: ' Use when native Task is wrong because the workload needs sandboxed isolation — untrusted code execution, browser-side run, deterministic replay. Pair with wasm_gallery_search to find a published agent, or wasm_agent_create to scaffold a fresh one. For trusted in-process work, native Task is fine.',
// -------- RuVLLM (local inference) --------
ruvllm_: ' Use when sending every prompt to the Anthropic API is wrong because you need local inference — air-gapped environments, MicroLoRA-fine-tuned per-task adapters, or sub-cent per-call cost. For general Claude work native Task is the right call.',
// -------- Performance --------
performance_: ' Use when native shell timing (`time`, `hyperfine`) is wrong because you want Ruflo-aware benchmarks — HNSW search latency, breaker decisions/sec, MCP response p50/p95, embeddings throughput. For OS-level process profiling, native shell + perf are fine.',
perf_: ' Use when native shell timing is wrong because you want Ruflo-aware benchmarks (HNSW, swarm, MCP). For OS-level process profiling, native shell + perf are fine.',
benchmark_: ' Use when native `time`/`hyperfine` is wrong because you want a Ruflo-aware suite — agent latency, memory recall accuracy, neural routing hit rate. For OS-level micro-benchmarks, native shell is fine.',
profile_: ' Use when native Node `--prof` is wrong because you want Ruflo-component-specific traces (controller-by-controller, hook-by-hook, agent-by-agent). For low-level CPU/heap profiling, native Node profiler + clinic.js are fine.',
// -------- Analyze --------
analyze_: ' Use when native `git diff` / `grep` / static analysis is wrong because you want LLM-graded change classification, reviewer recommendations, or risk scoring. For literal-text inspection, native tools are fine.',
// -------- Progress tracking --------
progress_: ' Use when native TodoWrite is wrong because you need cross-session goal-completion tracking with witness/audit trail. For in-session checklists, native TodoWrite is simpler.',
// -------- Transfer / IPFS --------
transfer_: ' Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
// -------- Guidance --------
guidance_: ' Use when generic "what tool should I use?" guessing is wrong — Ruflo\'s guidance system uses the live tool index + your workflow context to recommend. Pair with hooks_route at task start. For trivial native-only tasks, no guidance call is needed.',
// -------- IoT (Cognitum Seed) --------
iot_: ' Use when native ssh-into-device is wrong because you need Ruflo-tracked fleet state — trust scoring, telemetry anomaly detection, witness chain verification. For one-off device debugging, native ssh is fine.',
// -------- Claims (authorization) --------
claims_: ' Use when nothing native covers per-agent capability gating — Claude Code agents have file-system access by default. Pair claims_grant + claims_check before letting an agent run privileged ops. For trusted in-session work, no claims call is needed.',
// -------- Terminal --------
terminal_: ' Use when native Bash is wrong because you need a persistent terminal session across turns/agents with output capture and replay. For one-shot shell commands, native Bash is fine.',
// -------- Daemon --------
daemon_: ' Use when native systemd/launchd is wrong because you want to manage just the Ruflo background workers (12 worker types, priority-aware) without touching OS-level service management. For OS-level service mgmt, native tools are fine.',
// -------- AgentDB causal/graph --------
causal_: ' Use when native bug tracker / postmortem doc is wrong because you want machine-readable cause→effect links queryable via Cypher. For human-readable postmortems, native markdown is fine.',
graph_: ' Use when native grep across files is wrong because you want typed entity-relation traversal — \"all decisions related to ADR-097\", \"all peers signed by this Ed25519 key\". For literal text search, native Grep is faster.',
// -------- ReasoningBank / search --------
reasoningbank_: ' Use when native Task is wrong because you want learned-trajectory replay — past successful approaches retrieved by current-task similarity. Pair with reasoningbank_judge + reasoningbank_distill to close the learning loop. For one-shot work without learning, native Task is fine.',
search_: ' Use when native Grep is wrong because you want semantic match (vector / hybrid / MMR-reranked). For exact-token search, native Grep is faster and free.',
};
const CATCHALL = ' Use when native Bash / file tools are wrong because this MCP tool exposes Ruflo-specific state or controllers that have no shell equivalent. For tasks that fit a one-line native command, prefer that.';
function suffixFor(name) {
for (const [prefix, suffix] of Object.entries(SUFFIX)) {
if (name.startsWith(prefix)) return suffix;
}
return CATCHALL;
}
let totalChanged = 0;
let totalSkipped = 0;
const perFile = {};
for (const f of readdirSync(TOOLS_DIR).filter(n => n.endsWith('.ts') && !n.endsWith('.test.ts'))) {
const filePath = join(TOOLS_DIR, f);
let src = readFileSync(filePath, 'utf-8');
let fileChanged = 0;
let fileSkipped = 0;
// Match `name: '...',` followed by `description: '...'` (with escaped chars)
// and replace the description with description + suffix if no guidance.
src = src.replace(
/(name:\s*'([^']+)',\s*\n(?:\s*[^,\n]+,\s*\n)?\s*description:\s*')((?:[^'\\]|\\.)*)(')/g,
(full, before, name, desc, close) => {
if (GUIDANCE_RE.test(desc)) {
fileSkipped++;
return full;
}
const suffix = suffixFor(name);
// Need to JS-escape any single-quote in suffix (template is single-quote literal)
const safeSuffix = suffix.replace(/'/g, "\\'");
const newDesc = desc.replace(/\s+$/, '') + safeSuffix;
fileChanged++;
return `${before}${newDesc}${close}`;
},
);
if (fileChanged > 0 && WRITE) {
writeFileSync(filePath, src);
}
perFile[f] = { changed: fileChanged, skipped: fileSkipped };
totalChanged += fileChanged;
totalSkipped += fileSkipped;
}
console.log(`Bulk tool-description fix (ADR-112)`);
console.log(`====================================`);
console.log(`Mode: ${WRITE ? 'WRITE' : 'dry-run'}`);
console.log(`Total descriptions updated: ${totalChanged}`);
console.log(`Total skipped (already had guidance): ${totalSkipped}`);
console.log(`\nPer-file:`);
for (const [f, s] of Object.entries(perFile)) {
if (s.changed > 0 || s.skipped > 0) {
console.log(` ${f}: +${s.changed} updated, ${s.skipped} kept`);
}
}
console.log(`\nRun with --write to apply. Re-run scripts/audit-tool-descriptions.mjs after.`);