depsonar 4.0.0

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.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +247 -0
  3. package/dist/checker.d.ts +14 -0
  4. package/dist/checker.d.ts.map +1 -0
  5. package/dist/checker.js +110 -0
  6. package/dist/checker.js.map +1 -0
  7. package/dist/constants.d.ts +21 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +136 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/dashboard.d.ts +3 -0
  12. package/dist/dashboard.d.ts.map +1 -0
  13. package/dist/dashboard.js +266 -0
  14. package/dist/dashboard.js.map +1 -0
  15. package/dist/index.d.ts +3 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +121 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/schemas/index.d.ts +106 -0
  20. package/dist/schemas/index.d.ts.map +1 -0
  21. package/dist/schemas/index.js +106 -0
  22. package/dist/schemas/index.js.map +1 -0
  23. package/dist/services/actions.d.ts +17 -0
  24. package/dist/services/actions.d.ts.map +1 -0
  25. package/dist/services/actions.js +125 -0
  26. package/dist/services/actions.js.map +1 -0
  27. package/dist/services/audit.d.ts +27 -0
  28. package/dist/services/audit.d.ts.map +1 -0
  29. package/dist/services/audit.js +267 -0
  30. package/dist/services/audit.js.map +1 -0
  31. package/dist/services/changelog.d.ts +15 -0
  32. package/dist/services/changelog.d.ts.map +1 -0
  33. package/dist/services/changelog.js +92 -0
  34. package/dist/services/changelog.js.map +1 -0
  35. package/dist/services/cve.d.ts +32 -0
  36. package/dist/services/cve.d.ts.map +1 -0
  37. package/dist/services/cve.js +239 -0
  38. package/dist/services/cve.js.map +1 -0
  39. package/dist/services/deprecated.d.ts +18 -0
  40. package/dist/services/deprecated.d.ts.map +1 -0
  41. package/dist/services/deprecated.js +93 -0
  42. package/dist/services/deprecated.js.map +1 -0
  43. package/dist/services/docker.d.ts +17 -0
  44. package/dist/services/docker.d.ts.map +1 -0
  45. package/dist/services/docker.js +152 -0
  46. package/dist/services/docker.js.map +1 -0
  47. package/dist/services/docs.d.ts +26 -0
  48. package/dist/services/docs.d.ts.map +1 -0
  49. package/dist/services/docs.js +203 -0
  50. package/dist/services/docs.js.map +1 -0
  51. package/dist/services/envcheck.d.ts +15 -0
  52. package/dist/services/envcheck.d.ts.map +1 -0
  53. package/dist/services/envcheck.js +189 -0
  54. package/dist/services/envcheck.js.map +1 -0
  55. package/dist/services/formatter.d.ts +105 -0
  56. package/dist/services/formatter.d.ts.map +1 -0
  57. package/dist/services/formatter.js +597 -0
  58. package/dist/services/formatter.js.map +1 -0
  59. package/dist/services/licenses.d.ts +19 -0
  60. package/dist/services/licenses.d.ts.map +1 -0
  61. package/dist/services/licenses.js +142 -0
  62. package/dist/services/licenses.js.map +1 -0
  63. package/dist/services/migrate.d.ts +24 -0
  64. package/dist/services/migrate.d.ts.map +1 -0
  65. package/dist/services/migrate.js +169 -0
  66. package/dist/services/migrate.js.map +1 -0
  67. package/dist/services/osv.d.ts +29 -0
  68. package/dist/services/osv.d.ts.map +1 -0
  69. package/dist/services/osv.js +161 -0
  70. package/dist/services/osv.js.map +1 -0
  71. package/dist/services/project.d.ts +29 -0
  72. package/dist/services/project.d.ts.map +1 -0
  73. package/dist/services/project.js +716 -0
  74. package/dist/services/project.js.map +1 -0
  75. package/dist/services/runtimes.d.ts +26 -0
  76. package/dist/services/runtimes.d.ts.map +1 -0
  77. package/dist/services/runtimes.js +236 -0
  78. package/dist/services/runtimes.js.map +1 -0
  79. package/dist/services/secrets.d.ts +18 -0
  80. package/dist/services/secrets.d.ts.map +1 -0
  81. package/dist/services/secrets.js +164 -0
  82. package/dist/services/secrets.js.map +1 -0
  83. package/dist/services/toolchain.d.ts +10 -0
  84. package/dist/services/toolchain.d.ts.map +1 -0
  85. package/dist/services/toolchain.js +243 -0
  86. package/dist/services/toolchain.js.map +1 -0
  87. package/dist/tools/index.d.ts +3 -0
  88. package/dist/tools/index.d.ts.map +1 -0
  89. package/dist/tools/index.js +1067 -0
  90. package/dist/tools/index.js.map +1 -0
  91. package/dist/types.d.ts +69 -0
  92. package/dist/types.d.ts.map +1 -0
  93. package/dist/types.js +2 -0
  94. package/dist/types.js.map +1 -0
  95. package/package.json +73 -0
@@ -0,0 +1,1067 @@
1
+ import { existsSync, writeFileSync, unlinkSync } from "fs";
2
+ import { join, resolve } from "path";
3
+ import { homedir, platform } from "os";
4
+ import { CheckSchema, UpdateSchema, ScanSchema, UpdateAllSchema, HealthSchema, InstallSchema, ConfigSchema, AlertsSchema, SetupCronSchema, RuntimesSchema, ToolchainSchema, ActionsSchema, DockerSchema, EnvCheckSchema, AuditSchema, InfraSchema, CveSchema, DeprecatedSchema, SecretsSchema, LicensesSchema, LiveCveSchema, ChangelogSchema, MigrateSchema, DocsSchema, SearchPackageSchema, } from "../schemas/index.js";
5
+ import { LANGUAGE_MARKERS } from "../constants.js";
6
+ import { getProjectsDir, getProjectInfo, discoverProjects, getOutdated, isMajorUpdate, computeHealthReport, buildUpdateCommand, getFrameworkVersion, run, readCache, getCacheStatus, loadConfig, saveConfig, } from "../services/project.js";
7
+ import { formatOutdated, formatScanSummary, formatHealthReport, formatUpdateResult, formatBatchResult, formatCacheAlerts, formatRuntimes, formatToolchain, formatActions, formatDocker, formatEnvCheck, formatAudit, formatInfraReport, formatCve, formatDeprecated, formatSecrets, formatLicenses, formatLiveCve, formatChangelog, formatMigration, } from "../services/formatter.js";
8
+ import { checkAllRuntimes, checkProjectVersionFiles } from "../services/runtimes.js";
9
+ import { checkAllTools } from "../services/toolchain.js";
10
+ import { scanWorkflows, scanAllProjectActions } from "../services/actions.js";
11
+ import { scanDockerfiles, scanAllProjectDocker } from "../services/docker.js";
12
+ import { checkProjectEnv, checkAllProjectEnvs } from "../services/envcheck.js";
13
+ import { auditProject, auditAllProjects } from "../services/audit.js";
14
+ import { checkProjectCves, checkAllProjectCves, getCveDatabaseStats, getCveDatabase } from "../services/cve.js";
15
+ import { checkDeprecated, checkAllDeprecated } from "../services/deprecated.js";
16
+ import { scanProjectSecrets, scanAllProjectSecrets } from "../services/secrets.js";
17
+ import { checkProjectLicenses, checkAllProjectLicenses } from "../services/licenses.js";
18
+ import { liveAuditProject, liveAuditAllProjects } from "../services/osv.js";
19
+ import { getProjectChangelog } from "../services/changelog.js";
20
+ import { detectMigration, detectAllMigrations } from "../services/migrate.js";
21
+ import { fetchLibraryDocs, searchPackage } from "../services/docs.js";
22
+ function text(content) {
23
+ return { content: [{ type: "text", text: content }] };
24
+ }
25
+ function error(message) {
26
+ return { content: [{ type: "text", text: `Error: ${message}` }], isError: true };
27
+ }
28
+ function resolveProject(project) {
29
+ if (existsSync(project) && (existsSync(join(project, "package.json")) ||
30
+ existsSync(join(project, "Cargo.toml")) ||
31
+ existsSync(join(project, "go.mod")) ||
32
+ existsSync(join(project, "requirements.txt")) ||
33
+ existsSync(join(project, "pyproject.toml")) ||
34
+ existsSync(join(project, "composer.json")) ||
35
+ existsSync(join(project, "Gemfile")) ||
36
+ existsSync(join(project, "pubspec.yaml")) ||
37
+ existsSync(join(project, "Package.swift")) ||
38
+ existsSync(join(project, "build.gradle.kts")) ||
39
+ existsSync(join(project, "build.gradle")))) {
40
+ return resolve(project);
41
+ }
42
+ const fromDir = join(getProjectsDir(), project);
43
+ if (existsSync(fromDir))
44
+ return fromDir;
45
+ throw new Error(`Project "${project}" not found.\nUse depsonar_scan to list available projects.`);
46
+ }
47
+ export function registerTools(server) {
48
+ // ─── depsonar_alerts ─────────────────────────────────────────────────
49
+ server.registerTool("depsonar_alerts", {
50
+ title: "Check Alerts",
51
+ description: `Show pending dependency alerts from the last background scan. This reads the cache file written by the background checker (no live scan, instant response).
52
+
53
+ If no cache exists, suggests running depsonar_scan or setting up the background checker.
54
+
55
+ Examples:
56
+ - "Any dependency alerts?"
57
+ - "Do any of my projects need updates?"
58
+ - "Show depsonar alerts"`,
59
+ inputSchema: AlertsSchema,
60
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
61
+ }, async () => {
62
+ const cache = readCache();
63
+ if (!cache) {
64
+ const status = getCacheStatus();
65
+ return text([
66
+ "# No Recent Scan Data",
67
+ "",
68
+ "No background scan results found. You can:",
69
+ "- Run `depsonar_scan` to scan now",
70
+ "- Run `depsonar_setup_checker` to set up automatic background scans",
71
+ "",
72
+ status.exists ? `Last scan was too old to use.` : "No scan has been run yet.",
73
+ ].join("\n"));
74
+ }
75
+ return text(formatCacheAlerts(cache));
76
+ });
77
+ // ─── depsonar_check ──────────────────────────────────────────────────
78
+ server.registerTool("depsonar_check", {
79
+ title: "Check Outdated Dependencies",
80
+ description: `Check a project for outdated dependencies. Supports Node.js, Python, Rust, Go, PHP, Ruby, and Dart/Flutter.
81
+
82
+ Groups results by ecosystem for Node projects. Flags major version updates.
83
+
84
+ Examples:
85
+ - "Check JobPin for outdated deps"
86
+ - "What needs updating in my Django project?"`,
87
+ inputSchema: CheckSchema,
88
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
89
+ }, async ({ project }) => {
90
+ try {
91
+ const projectPath = resolveProject(project);
92
+ const info = getProjectInfo(projectPath);
93
+ if (!info)
94
+ return error(`Cannot read project at ${projectPath}`);
95
+ const outdated = getOutdated(projectPath, info);
96
+ const fwVer = getFrameworkVersion(info);
97
+ const langName = LANGUAGE_MARKERS[info.language]?.name || info.language;
98
+ const header = [
99
+ `# ${info.name}`,
100
+ "",
101
+ `**Language**: ${langName}`,
102
+ `**Framework**: ${info.framework}${fwVer ? ` (${fwVer})` : ""}`,
103
+ `**Package Manager**: ${info.packageManager}`,
104
+ `**Path**: \`${projectPath}\``,
105
+ "",
106
+ ].join("\n");
107
+ return text(header + formatOutdated(outdated, info.language));
108
+ }
109
+ catch (err) {
110
+ return error(err instanceof Error ? err.message : String(err));
111
+ }
112
+ });
113
+ // ─── depsonar_update ─────────────────────────────────────────────────
114
+ server.registerTool("depsonar_update", {
115
+ title: "Update Dependencies",
116
+ description: `Update dependencies for a project. Works with any supported language.
117
+
118
+ Three safety levels:
119
+ - patch: Bugfixes only (safest)
120
+ - minor: New features, no breaking changes (default)
121
+ - latest: Includes major breaking changes
122
+
123
+ Examples:
124
+ - "Update all deps in JobPin"
125
+ - "Update svelte in Showly to latest"
126
+ - "Update my Python project dependencies"`,
127
+ inputSchema: UpdateSchema,
128
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
129
+ }, async ({ project, packages, level, dry_run }) => {
130
+ try {
131
+ const projectPath = resolveProject(project);
132
+ const info = getProjectInfo(projectPath);
133
+ if (!info)
134
+ return error(`Cannot read project at ${projectPath}`);
135
+ const beforeOutdated = getOutdated(projectPath, info);
136
+ const beforeCount = Object.keys(beforeOutdated).length;
137
+ if (beforeCount === 0) {
138
+ return text(`# ${info.name}\n\nAll dependencies are already up to date. ✅`);
139
+ }
140
+ if (dry_run) {
141
+ return text(`# Preview: ${info.name}\n\n${formatOutdated(beforeOutdated, info.language)}`);
142
+ }
143
+ const cmd = buildUpdateCommand(info, packages, level);
144
+ run(cmd, projectPath);
145
+ const afterOutdated = getOutdated(projectPath, info);
146
+ const afterCount = Object.keys(afterOutdated).length;
147
+ return text(formatUpdateResult(info.name, cmd, beforeCount, afterCount, afterOutdated));
148
+ }
149
+ catch (err) {
150
+ return error(err instanceof Error ? err.message : String(err));
151
+ }
152
+ });
153
+ // ─── depsonar_scan ───────────────────────────────────────────────────
154
+ server.registerTool("depsonar_scan", {
155
+ title: "Scan All Projects",
156
+ description: `Scan all projects in your workspace. Auto-detects language (Node, Python, Rust, Go, PHP, Ruby, Dart) and framework.
157
+
158
+ Can filter by framework or language.
159
+
160
+ Examples:
161
+ - "Scan all my projects"
162
+ - "Which Python projects need updates?"
163
+ - "Show all SvelteKit projects status"`,
164
+ inputSchema: ScanSchema,
165
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
166
+ }, async ({ directory, framework, language }) => {
167
+ try {
168
+ let projects = discoverProjects(directory);
169
+ if (projects.length === 0) {
170
+ return text(`No projects found in \`${directory || getProjectsDir()}\`.\n\nUse \`depsonar_config\` to set your projects directory.`);
171
+ }
172
+ if (framework) {
173
+ projects = projects.filter((p) => p.framework.toLowerCase() === framework.toLowerCase());
174
+ }
175
+ if (language) {
176
+ projects = projects.filter((p) => p.language === language);
177
+ }
178
+ const results = projects.map((info) => {
179
+ const outdated = getOutdated(info.path, info);
180
+ const hasMajor = Object.entries(outdated).some(([, pkg]) => isMajorUpdate(pkg.current, pkg.latest));
181
+ return {
182
+ name: info.name,
183
+ language: info.language,
184
+ framework: info.framework,
185
+ pm: info.packageManager,
186
+ fwVersion: getFrameworkVersion(info),
187
+ outdatedCount: Object.keys(outdated).length,
188
+ hasMajor,
189
+ };
190
+ });
191
+ return text(formatScanSummary(results));
192
+ }
193
+ catch (err) {
194
+ return error(err instanceof Error ? err.message : String(err));
195
+ }
196
+ });
197
+ // ─── depsonar_update_all ─────────────────────────────────────────────
198
+ server.registerTool("depsonar_update_all", {
199
+ title: "Update All Projects",
200
+ description: `Batch update across all projects. Defaults to dry_run=true (safe preview).
201
+
202
+ Can filter by framework or language.
203
+
204
+ Examples:
205
+ - "Update all my projects"
206
+ - "Update all SvelteKit projects, apply changes"
207
+ - "Preview updates for all Python projects"`,
208
+ inputSchema: UpdateAllSchema,
209
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
210
+ }, async ({ level, framework, language, dry_run, directory }) => {
211
+ try {
212
+ let projects = discoverProjects(directory);
213
+ if (projects.length === 0) {
214
+ return text("No projects found. Use `depsonar_config` to set your directory.");
215
+ }
216
+ if (framework)
217
+ projects = projects.filter((p) => p.framework.toLowerCase() === framework.toLowerCase());
218
+ if (language)
219
+ projects = projects.filter((p) => p.language === language);
220
+ const results = [];
221
+ for (const info of projects) {
222
+ const beforeOutdated = getOutdated(info.path, info);
223
+ const beforeCount = Object.keys(beforeOutdated).length;
224
+ if (beforeCount === 0) {
225
+ results.push({ name: info.name, updated: 0, remaining: 0 });
226
+ continue;
227
+ }
228
+ if (dry_run) {
229
+ results.push({ name: info.name, updated: beforeCount, remaining: 0 });
230
+ continue;
231
+ }
232
+ try {
233
+ const cmd = buildUpdateCommand(info, undefined, level);
234
+ run(cmd, info.path);
235
+ const afterOutdated = getOutdated(info.path, info);
236
+ results.push({
237
+ name: info.name,
238
+ updated: beforeCount - Object.keys(afterOutdated).length,
239
+ remaining: Object.keys(afterOutdated).length,
240
+ });
241
+ }
242
+ catch (err) {
243
+ results.push({
244
+ name: info.name,
245
+ updated: 0,
246
+ remaining: beforeCount,
247
+ error: err instanceof Error ? err.message.split("\n")[0] : String(err),
248
+ });
249
+ }
250
+ }
251
+ return text(formatBatchResult(results, dry_run));
252
+ }
253
+ catch (err) {
254
+ return error(err instanceof Error ? err.message : String(err));
255
+ }
256
+ });
257
+ // ─── depsonar_health ─────────────────────────────────────────────────
258
+ server.registerTool("depsonar_health", {
259
+ title: "Health Report",
260
+ description: `Score a project from 0-100. Checks outdated deps, security issues, lockfile.
261
+
262
+ Examples:
263
+ - "How healthy is JobPin?"
264
+ - "Health report for my Rust project"`,
265
+ inputSchema: HealthSchema,
266
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
267
+ }, async ({ project }) => {
268
+ try {
269
+ const projectPath = resolveProject(project);
270
+ const info = getProjectInfo(projectPath);
271
+ if (!info)
272
+ return error(`Cannot read project at ${projectPath}`);
273
+ return text(formatHealthReport(computeHealthReport(info)));
274
+ }
275
+ catch (err) {
276
+ return error(err instanceof Error ? err.message : String(err));
277
+ }
278
+ });
279
+ // ─── depsonar_install ────────────────────────────────────────────────
280
+ server.registerTool("depsonar_install", {
281
+ title: "Install Dependencies",
282
+ description: `Fresh install. Use clean=true to nuke node_modules/vendor first.
283
+
284
+ Examples:
285
+ - "Install deps for JobPin"
286
+ - "Clean install my project"`,
287
+ inputSchema: InstallSchema,
288
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
289
+ }, async ({ project, clean }) => {
290
+ try {
291
+ const projectPath = resolveProject(project);
292
+ const info = getProjectInfo(projectPath);
293
+ if (!info)
294
+ return error(`Cannot read project at ${projectPath}`);
295
+ const marker = LANGUAGE_MARKERS[info.language];
296
+ if (clean && marker?.cleanCmd) {
297
+ run(marker.cleanCmd, projectPath);
298
+ }
299
+ const installCmd = info.language === "node"
300
+ ? `${info.packageManager} install`
301
+ : marker?.installCmd || "npm install";
302
+ const output = run(installCmd, projectPath);
303
+ const preview = output.length > 3000 ? output.slice(-3000) : output;
304
+ return text(`# ${info.name}\n\n\`${installCmd}\`${clean ? " (clean)" : ""} done.\n\n\`\`\`\n${preview}\n\`\`\``);
305
+ }
306
+ catch (err) {
307
+ return error(err instanceof Error ? err.message : String(err));
308
+ }
309
+ });
310
+ // ─── depsonar_setup_checker ──────────────────────────────────────────
311
+ server.registerTool("depsonar_setup_checker", {
312
+ title: "Setup Background Checker",
313
+ description: `Install or remove the background dependency checker. On macOS, uses launchd (native, lightweight). On Linux, uses cron.
314
+
315
+ The checker runs on schedule, scans all projects, writes results to ~/.depsonar-cache.json, then exits. Zero RAM between runs, zero AI tokens, zero cost.
316
+
317
+ Results are shown by depsonar_alerts.
318
+
319
+ Examples:
320
+ - "Setup background dependency checking"
321
+ - "Check my deps every 12 hours"
322
+ - "Remove the background checker"`,
323
+ inputSchema: SetupCronSchema,
324
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
325
+ }, async ({ interval_hours, uninstall }) => {
326
+ try {
327
+ const isMac = platform() === "darwin";
328
+ if (isMac) {
329
+ return text(setupLaunchd(interval_hours, uninstall));
330
+ }
331
+ else {
332
+ return text(setupCron(interval_hours, uninstall));
333
+ }
334
+ }
335
+ catch (err) {
336
+ return error(err instanceof Error ? err.message : String(err));
337
+ }
338
+ });
339
+ // ─── depsonar_config ─────────────────────────────────────────────────
340
+ server.registerTool("depsonar_config", {
341
+ title: "Configure depsonar",
342
+ description: `View or update configuration. Saved to ~/.depsonarrc.json.
343
+
344
+ Examples:
345
+ - "Show depsonar config"
346
+ - "Set projects directory to ~/Code"`,
347
+ inputSchema: ConfigSchema,
348
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
349
+ }, async ({ projects_dir, show }) => {
350
+ try {
351
+ if (show || !projects_dir) {
352
+ const config = loadConfig();
353
+ const cacheStatus = getCacheStatus();
354
+ return text([
355
+ "# DepUp Configuration",
356
+ "",
357
+ `**Projects directory**: \`${config.projectsDir}\``,
358
+ `**Config file**: \`~/.depsonarrc.json\``,
359
+ "",
360
+ "### Background Checker",
361
+ cacheStatus.exists
362
+ ? `- Last scan: ${cacheStatus.age}`
363
+ + `\n- Projects tracked: ${cacheStatus.projectCount}`
364
+ + `\n- Alerts: ${cacheStatus.alerts}`
365
+ : "- Not configured. Use `depsonar_setup_checker` to enable.",
366
+ "",
367
+ "### Supported Languages",
368
+ ...Object.entries(LANGUAGE_MARKERS).map(([key, m]) => `- ${m.name} (${m.files.join(", ")})`),
369
+ ].join("\n"));
370
+ }
371
+ const configPath = saveConfig({ projectsDir: resolve(projects_dir) });
372
+ return text(`Projects directory set to \`${resolve(projects_dir)}\`.\nSaved to \`${configPath}\`.`);
373
+ }
374
+ catch (err) {
375
+ return error(err instanceof Error ? err.message : String(err));
376
+ }
377
+ });
378
+ // ─── depsonar_audit ──────────────────────────────────────────────────
379
+ server.registerTool("depsonar_audit", {
380
+ title: "Security Audit",
381
+ description: `Scan projects for known security vulnerabilities (CVEs). Uses npm audit, cargo audit, pip-audit, composer audit, govulncheck.
382
+
383
+ CRITICAL: Run this after any CVE announcement (e.g. Svelte CVE-2026-22775, devalue DoS).
384
+
385
+ Examples:
386
+ - "Audit all my projects for vulnerabilities"
387
+ - "Security scan JobPin"
388
+ - "Any CVEs in my SvelteKit projects?"`,
389
+ inputSchema: AuditSchema,
390
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
391
+ }, async ({ project, directory }) => {
392
+ try {
393
+ if (project) {
394
+ const projectPath = resolveProject(project);
395
+ const info = getProjectInfo(projectPath);
396
+ if (!info)
397
+ return error(`Cannot read project at ${projectPath}`);
398
+ const result = auditProject(projectPath, info.name, info.language);
399
+ return text(formatAudit([result]));
400
+ }
401
+ const projects = discoverProjects(directory);
402
+ if (projects.length === 0)
403
+ return text("No projects found.");
404
+ const results = auditAllProjects(projects.map(p => ({ name: p.name, path: p.path, language: p.language })));
405
+ return text(formatAudit(results));
406
+ }
407
+ catch (err) {
408
+ return error(err instanceof Error ? err.message : String(err));
409
+ }
410
+ });
411
+ // ─── depsonar_runtimes ───────────────────────────────────────────────
412
+ server.registerTool("depsonar_runtimes", {
413
+ title: "Check Runtime Versions",
414
+ description: `Check installed runtime versions (Node.js, Python, Rust, Go, PHP, Ruby, Dart, Swift). Detects EOL and outdated versions. Also checks project version files (.nvmrc, .python-version, rust-toolchain.toml, engines.node).
415
+
416
+ Examples:
417
+ - "Check my runtime versions"
418
+ - "Is my Node.js up to date?"
419
+ - "Any runtime mismatches in my projects?"`,
420
+ inputSchema: RuntimesSchema,
421
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
422
+ }, async ({ filter, check_projects, directory }) => {
423
+ try {
424
+ let runtimes = checkAllRuntimes();
425
+ if (filter) {
426
+ runtimes = runtimes.filter(r => r.name.toLowerCase().includes(filter.toLowerCase()));
427
+ }
428
+ let mismatches = [];
429
+ if (check_projects) {
430
+ const projects = discoverProjects(directory);
431
+ mismatches = projects.flatMap(p => checkProjectVersionFiles(p.path, p.name));
432
+ }
433
+ return text(formatRuntimes(runtimes, mismatches));
434
+ }
435
+ catch (err) {
436
+ return error(err instanceof Error ? err.message : String(err));
437
+ }
438
+ });
439
+ // ─── depsonar_toolchain ──────────────────────────────────────────────
440
+ server.registerTool("depsonar_toolchain", {
441
+ title: "Check Global Toolchain",
442
+ description: `Check versions of globally installed tools: npm, pnpm, yarn, bun, composer, cargo, pip, typescript, git, docker, homebrew, vercel-cli, supabase-cli, wrangler.
443
+
444
+ Shows installed vs latest version and update commands.
445
+
446
+ Examples:
447
+ - "Check my global tools"
448
+ - "Is pnpm up to date?"
449
+ - "Show all CLI tool versions"`,
450
+ inputSchema: ToolchainSchema,
451
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
452
+ }, async ({ category }) => {
453
+ try {
454
+ let tools = checkAllTools();
455
+ if (category) {
456
+ tools = tools.filter(t => t.category.toLowerCase().includes(category.toLowerCase()));
457
+ }
458
+ return text(formatToolchain(tools));
459
+ }
460
+ catch (err) {
461
+ return error(err instanceof Error ? err.message : String(err));
462
+ }
463
+ });
464
+ // ─── depsonar_docker ─────────────────────────────────────────────────
465
+ server.registerTool("depsonar_docker", {
466
+ title: "Docker Image Audit",
467
+ description: `Scan Dockerfile and docker-compose files for outdated or EOL base images. Checks: node, python, ruby, php, golang, rust, nginx, postgres, redis, ubuntu, alpine.
468
+
469
+ Examples:
470
+ - "Check my Docker images"
471
+ - "Any EOL images in my projects?"`,
472
+ inputSchema: DockerSchema,
473
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
474
+ }, async ({ project, directory }) => {
475
+ try {
476
+ if (project) {
477
+ const projectPath = resolveProject(project);
478
+ const info = getProjectInfo(projectPath);
479
+ if (!info)
480
+ return error(`Cannot read project at ${projectPath}`);
481
+ const images = scanDockerfiles(projectPath, info.name);
482
+ return text(formatDocker(images.length > 0 ? [{ project: info.name, images }] : []));
483
+ }
484
+ const projects = discoverProjects(directory);
485
+ const results = scanAllProjectDocker(projects.map(p => ({ name: p.name, path: p.path })));
486
+ return text(formatDocker(results));
487
+ }
488
+ catch (err) {
489
+ return error(err instanceof Error ? err.message : String(err));
490
+ }
491
+ });
492
+ // ─── depsonar_actions ────────────────────────────────────────────────
493
+ server.registerTool("depsonar_actions", {
494
+ title: "GitHub Actions Audit",
495
+ description: `Scan GitHub Actions workflow files for outdated or deprecated actions. Knows 30+ popular actions (actions/checkout, docker/build-push-action, cloudflare/wrangler-action, etc.).
496
+
497
+ Examples:
498
+ - "Check my GitHub Actions versions"
499
+ - "Any deprecated actions in my workflows?"`,
500
+ inputSchema: ActionsSchema,
501
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
502
+ }, async ({ project, directory }) => {
503
+ try {
504
+ if (project) {
505
+ const projectPath = resolveProject(project);
506
+ const info = getProjectInfo(projectPath);
507
+ if (!info)
508
+ return error(`Cannot read project at ${projectPath}`);
509
+ const actions = scanWorkflows(projectPath, info.name);
510
+ return text(formatActions(actions.length > 0 ? [{ project: info.name, actions }] : []));
511
+ }
512
+ const projects = discoverProjects(directory);
513
+ const results = scanAllProjectActions(projects.map(p => ({ name: p.name, path: p.path })));
514
+ return text(formatActions(results));
515
+ }
516
+ catch (err) {
517
+ return error(err instanceof Error ? err.message : String(err));
518
+ }
519
+ });
520
+ // ─── depsonar_envcheck ───────────────────────────────────────────────
521
+ server.registerTool("depsonar_envcheck", {
522
+ title: "Environment & Config Check",
523
+ description: `Validate project environments: .env/.env.example sync, lockfile freshness, tsconfig best practices, Svelte config (detects deprecated svelte-preprocess with Svelte 5, duplicate adapters, etc.), multiple lockfiles.
524
+
525
+ Examples:
526
+ - "Check my project environments"
527
+ - "Any env issues in JobPin?"
528
+ - "Validate all project configs"`,
529
+ inputSchema: EnvCheckSchema,
530
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
531
+ }, async ({ project, directory }) => {
532
+ try {
533
+ if (project) {
534
+ const projectPath = resolveProject(project);
535
+ const info = getProjectInfo(projectPath);
536
+ if (!info)
537
+ return error(`Cannot read project at ${projectPath}`);
538
+ const issues = checkProjectEnv(projectPath, info.name);
539
+ return text(formatEnvCheck(issues.length > 0 ? [{ project: info.name, issues }] : []));
540
+ }
541
+ const projects = discoverProjects(directory);
542
+ const results = checkAllProjectEnvs(projects.map(p => ({ name: p.name, path: p.path })));
543
+ return text(formatEnvCheck(results));
544
+ }
545
+ catch (err) {
546
+ return error(err instanceof Error ? err.message : String(err));
547
+ }
548
+ });
549
+ // ─── depsonar_infra ──────────────────────────────────────────────────
550
+ server.registerTool("depsonar_infra", {
551
+ title: "Full Infrastructure Report",
552
+ description: `Complete infrastructure health check in one command. Combines: runtime versions, global toolchain, security audit, CVE advisories, Docker images, GitHub Actions, environment configs, secret scanning, license compliance, deprecated packages, and optionally dependency scan.
553
+
554
+ This is the "run everything" command. Use when you want a full picture.
555
+
556
+ Examples:
557
+ - "Full infrastructure report"
558
+ - "Check everything"
559
+ - "How's my dev environment?"`,
560
+ inputSchema: InfraSchema,
561
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
562
+ }, async ({ directory, skip_deps }) => {
563
+ try {
564
+ const projects = discoverProjects(directory);
565
+ const projectList = projects.map(p => ({ name: p.name, path: p.path, language: p.language }));
566
+ // Runtimes
567
+ const runtimes = checkAllRuntimes();
568
+ const mismatches = projects.flatMap(p => checkProjectVersionFiles(p.path, p.name));
569
+ const runtimesSection = formatRuntimes(runtimes, mismatches);
570
+ // Toolchain
571
+ const tools = checkAllTools();
572
+ const toolchainSection = formatToolchain(tools);
573
+ // Security audit
574
+ const auditResults = auditAllProjects(projectList);
575
+ const auditSection = formatAudit(auditResults);
576
+ // Docker
577
+ const dockerResults = scanAllProjectDocker(projectList.map(p => ({ name: p.name, path: p.path })));
578
+ const dockerSection = formatDocker(dockerResults);
579
+ // GitHub Actions
580
+ const actionsResults = scanAllProjectActions(projectList.map(p => ({ name: p.name, path: p.path })));
581
+ const actionsSection = formatActions(actionsResults);
582
+ // Environment
583
+ const envResults = checkAllProjectEnvs(projectList.map(p => ({ name: p.name, path: p.path })));
584
+ const envSection = formatEnvCheck(envResults);
585
+ // CVE Advisories
586
+ const cveResults = checkAllProjectCves(projectList.map(p => ({ name: p.name, path: p.path })));
587
+ const cveSection = formatCve(cveResults, getCveDatabaseStats());
588
+ // Secrets
589
+ const secretsResults = scanAllProjectSecrets(projectList.map(p => ({ name: p.name, path: p.path })));
590
+ const secretsSection = formatSecrets(secretsResults);
591
+ // Deprecated
592
+ const deprecatedResults = checkAllDeprecated(projectList.map(p => ({ name: p.name, path: p.path })));
593
+ const deprecatedSection = formatDeprecated(deprecatedResults);
594
+ // Licenses
595
+ const licenseResults = checkAllProjectLicenses(projectList.map(p => ({ name: p.name, path: p.path })));
596
+ const licenseSection = formatLicenses(licenseResults);
597
+ // Deps (optional)
598
+ let depsSection;
599
+ if (!skip_deps) {
600
+ const scanResults = projects.map(info => {
601
+ const outdated = getOutdated(info.path, info);
602
+ const hasMajor = Object.entries(outdated).some(([, pkg]) => isMajorUpdate(pkg.current, pkg.latest));
603
+ return {
604
+ name: info.name, language: info.language, framework: info.framework,
605
+ pm: info.packageManager, fwVersion: getFrameworkVersion(info),
606
+ outdatedCount: Object.keys(outdated).length, hasMajor,
607
+ };
608
+ });
609
+ depsSection = formatScanSummary(scanResults);
610
+ }
611
+ return text(formatInfraReport({
612
+ runtimes: runtimesSection,
613
+ toolchain: toolchainSection,
614
+ audit: auditSection,
615
+ cve: cveSection,
616
+ docker: dockerSection,
617
+ actions: actionsSection,
618
+ env: envSection,
619
+ secrets: secretsSection,
620
+ deprecated: deprecatedSection,
621
+ licenses: licenseSection,
622
+ deps: depsSection,
623
+ }));
624
+ }
625
+ catch (err) {
626
+ return error(err instanceof Error ? err.message : String(err));
627
+ }
628
+ });
629
+ // ─── depsonar_cve ────────────────────────────────────────────────────
630
+ server.registerTool("depsonar_cve", {
631
+ title: "CVE Advisory Check",
632
+ description: `Check projects against known framework CVEs (Svelte, SvelteKit, devalue, Next.js, Vite, Express, Axios). Goes beyond npm audit by checking a curated database of framework-specific vulnerabilities.
633
+
634
+ CRITICAL after any CVE announcement. Run immediately when new CVEs are published.
635
+
636
+ Examples:
637
+ - "Check my projects for known CVEs"
638
+ - "Any Svelte CVEs affecting my code?"
639
+ - "Show CVE database"`,
640
+ inputSchema: CveSchema,
641
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
642
+ }, async ({ project, directory, show_db }) => {
643
+ try {
644
+ const dbStats = getCveDatabaseStats();
645
+ if (show_db) {
646
+ const db = getCveDatabase();
647
+ const lines = [`# CVE Advisory Database\n`, `${db.length} advisories | Last updated: ${dbStats.lastUpdate}\n`];
648
+ for (const cve of db) {
649
+ const emoji = cve.severity === "critical" ? "🔴" : cve.severity === "high" ? "🟠" : "🟡";
650
+ lines.push(`- ${emoji} **${cve.id}** \`${cve.package}\` (${cve.severity}): ${cve.title}`);
651
+ lines.push(` Affected: ${cve.affectedVersions} | Fix: ${cve.patchedVersion}`);
652
+ }
653
+ return text(lines.join("\n"));
654
+ }
655
+ if (project) {
656
+ const projectPath = resolveProject(project);
657
+ const info = getProjectInfo(projectPath);
658
+ if (!info)
659
+ return error(`Cannot read project at ${projectPath}`);
660
+ const result = checkProjectCves(projectPath, info.name);
661
+ return text(formatCve(result.affected.length > 0 ? [result] : [], dbStats));
662
+ }
663
+ const projects = discoverProjects(directory);
664
+ if (projects.length === 0)
665
+ return text("No projects found.");
666
+ const results = checkAllProjectCves(projects.map(p => ({ name: p.name, path: p.path })));
667
+ return text(formatCve(results, dbStats));
668
+ }
669
+ catch (err) {
670
+ return error(err instanceof Error ? err.message : String(err));
671
+ }
672
+ });
673
+ // ─── depsonar_deprecated ─────────────────────────────────────────────
674
+ server.registerTool("depsonar_deprecated", {
675
+ title: "Deprecated Package Check",
676
+ description: `Detect deprecated, unmaintained, or replaced packages. Checks both npm deprecated flags and a curated list of known replacements (moment→dayjs, node-fetch→native fetch, request→undici, etc.).
677
+
678
+ Examples:
679
+ - "Any deprecated packages in my projects?"
680
+ - "Check JobPin for deprecated deps"
681
+ - "Find packages that should be replaced"`,
682
+ inputSchema: DeprecatedSchema,
683
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
684
+ }, async ({ project, directory }) => {
685
+ try {
686
+ if (project) {
687
+ const projectPath = resolveProject(project);
688
+ const info = getProjectInfo(projectPath);
689
+ if (!info)
690
+ return error(`Cannot read project at ${projectPath}`);
691
+ const result = checkDeprecated(projectPath, info.name);
692
+ return text(formatDeprecated(result.deprecated.length > 0 ? [result] : []));
693
+ }
694
+ const projects = discoverProjects(directory);
695
+ if (projects.length === 0)
696
+ return text("No projects found.");
697
+ const results = checkAllDeprecated(projects.map(p => ({ name: p.name, path: p.path })));
698
+ return text(formatDeprecated(results));
699
+ }
700
+ catch (err) {
701
+ return error(err instanceof Error ? err.message : String(err));
702
+ }
703
+ });
704
+ // ─── depsonar_secrets ────────────────────────────────────────────────
705
+ server.registerTool("depsonar_secrets", {
706
+ title: "Secret Scanner",
707
+ description: `Scan project files for exposed secrets, API keys, tokens, and credentials. Detects: AWS keys, GitHub tokens, Stripe keys, Supabase JWT, OpenAI/Anthropic keys, private keys, database URLs, generic API key patterns.
708
+
709
+ Also checks that .env files are properly gitignored.
710
+
711
+ Examples:
712
+ - "Scan my projects for exposed secrets"
713
+ - "Any leaked API keys in JobPin?"
714
+ - "Secret scan all projects"`,
715
+ inputSchema: SecretsSchema,
716
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
717
+ }, async ({ project, directory }) => {
718
+ try {
719
+ if (project) {
720
+ const projectPath = resolveProject(project);
721
+ const info = getProjectInfo(projectPath);
722
+ if (!info)
723
+ return error(`Cannot read project at ${projectPath}`);
724
+ const result = scanProjectSecrets(projectPath, info.name);
725
+ return text(formatSecrets(result.findings.length > 0 ? [result] : []));
726
+ }
727
+ const projects = discoverProjects(directory);
728
+ if (projects.length === 0)
729
+ return text("No projects found.");
730
+ const results = scanAllProjectSecrets(projects.map(p => ({ name: p.name, path: p.path })));
731
+ return text(formatSecrets(results));
732
+ }
733
+ catch (err) {
734
+ return error(err instanceof Error ? err.message : String(err));
735
+ }
736
+ });
737
+ // ─── depsonar_licenses ───────────────────────────────────────────────
738
+ server.registerTool("depsonar_licenses", {
739
+ title: "License Compliance Check",
740
+ description: `Check dependency licenses for commercial/SaaS compatibility. Flags: GPL/AGPL (copyleft, requires source disclosure), non-commercial (CC-BY-NC), unknown licenses.
741
+
742
+ Important for SaaS products to avoid legal issues.
743
+
744
+ Examples:
745
+ - "Check license compliance for RoomPilot"
746
+ - "Any GPL dependencies in my projects?"
747
+ - "License audit all projects"`,
748
+ inputSchema: LicensesSchema,
749
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
750
+ }, async ({ project, directory }) => {
751
+ try {
752
+ if (project) {
753
+ const projectPath = resolveProject(project);
754
+ const info = getProjectInfo(projectPath);
755
+ if (!info)
756
+ return error(`Cannot read project at ${projectPath}`);
757
+ const result = checkProjectLicenses(projectPath, info.name);
758
+ return text(formatLicenses(result.issues > 0 ? [result] : []));
759
+ }
760
+ const projects = discoverProjects(directory);
761
+ if (projects.length === 0)
762
+ return text("No projects found.");
763
+ const results = checkAllProjectLicenses(projects.map(p => ({ name: p.name, path: p.path })));
764
+ return text(formatLicenses(results));
765
+ }
766
+ catch (err) {
767
+ return error(err instanceof Error ? err.message : String(err));
768
+ }
769
+ });
770
+ // ─── depsonar_live_cve ───────────────────────────────────────────────
771
+ server.registerTool("depsonar_live_cve", {
772
+ title: "Live CVE Scan (osv.dev)",
773
+ description: `Real-time vulnerability scan using the osv.dev API. Checks every installed package against the global OSV database (npm, PyPI, crates.io, Go, Packagist, RubyGems, Pub).
774
+
775
+ Unlike depsonar_audit (which uses local tools like npm audit), this queries the live osv.dev database for the most up-to-date vulnerability data. No API key needed.
776
+
777
+ Examples:
778
+ - "Live CVE scan all my projects"
779
+ - "Check RoomPilot for vulnerabilities with osv.dev"
780
+ - "Real-time security scan"`,
781
+ inputSchema: LiveCveSchema,
782
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
783
+ }, async ({ project, directory }) => {
784
+ try {
785
+ if (project) {
786
+ const projectPath = resolveProject(project);
787
+ const info = getProjectInfo(projectPath);
788
+ if (!info)
789
+ return error(`Cannot read project at ${projectPath}`);
790
+ const result = await liveAuditProject(projectPath, info.name, info.language);
791
+ return text(formatLiveCve(result.vulnerabilities.length > 0 ? [result] : []));
792
+ }
793
+ const projects = discoverProjects(directory);
794
+ if (projects.length === 0)
795
+ return text("No projects found.");
796
+ const results = await liveAuditAllProjects(projects.map(p => ({ name: p.name, path: p.path, language: p.language })));
797
+ return text(formatLiveCve(results));
798
+ }
799
+ catch (err) {
800
+ return error(err instanceof Error ? err.message : String(err));
801
+ }
802
+ });
803
+ // ─── depsonar_changelog ──────────────────────────────────────────────
804
+ server.registerTool("depsonar_changelog", {
805
+ title: "Changelog & Breaking Changes",
806
+ description: `Check changelogs and breaking changes before updating. Shows major/minor/patch breakdown with changelog URLs and release notes for breaking updates.
807
+
808
+ Run this BEFORE depsonar_update to understand what will change.
809
+
810
+ Examples:
811
+ - "Show changelog for RoomPilot before updating"
812
+ - "What breaking changes are pending in my project?"
813
+ - "Check what changed in latest versions"`,
814
+ inputSchema: ChangelogSchema,
815
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
816
+ }, async ({ project }) => {
817
+ try {
818
+ const projectPath = resolveProject(project);
819
+ const info = getProjectInfo(projectPath);
820
+ if (!info)
821
+ return error(`Cannot read project at ${projectPath}`);
822
+ const result = getProjectChangelog(projectPath, info.name);
823
+ return text(formatChangelog(result));
824
+ }
825
+ catch (err) {
826
+ return error(err instanceof Error ? err.message : String(err));
827
+ }
828
+ });
829
+ // ─── depsonar_migrate ────────────────────────────────────────────────
830
+ server.registerTool("depsonar_migrate", {
831
+ title: "Framework Migration Detector",
832
+ description: `Detect framework migration needs by scanning code for deprecated patterns. Currently supports: Svelte 4→5, Next.js 13→14→15.
833
+
834
+ Finds exact file locations of code that needs to change, with migration instructions for each pattern.
835
+
836
+ Examples:
837
+ - "Check if my projects need Svelte 5 migration"
838
+ - "Migration scan for all projects"
839
+ - "What Svelte 4 patterns are still in my code?"`,
840
+ inputSchema: MigrateSchema,
841
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
842
+ }, async ({ project, directory }) => {
843
+ try {
844
+ if (project) {
845
+ const projectPath = resolveProject(project);
846
+ const info = getProjectInfo(projectPath);
847
+ if (!info)
848
+ return error(`Cannot read project at ${projectPath}`);
849
+ const result = detectMigration(projectPath, info.name, info.framework);
850
+ return text(formatMigration(result.migrationNeeded ? [result] : []));
851
+ }
852
+ const projects = discoverProjects(directory);
853
+ if (projects.length === 0)
854
+ return text("No projects found.");
855
+ const results = detectAllMigrations(projects.map(p => ({ name: p.name, path: p.path, framework: p.framework })));
856
+ return text(formatMigration(results));
857
+ }
858
+ catch (err) {
859
+ return error(err instanceof Error ? err.message : String(err));
860
+ }
861
+ });
862
+ // ─── depsonar_docs ──────────────────────────────────────────────────
863
+ server.registerTool("depsonar_docs", {
864
+ title: "Library Documentation (Context)",
865
+ description: `Fetch up-to-date documentation, changelogs, and migration guides for any npm package directly from source (GitHub + npm registry).
866
+
867
+ Use this BEFORE writing code that depends on a library, to get the latest API docs and avoid hallucinating outdated APIs.
868
+
869
+ Sections available:
870
+ - **readme**: Latest README with API docs, examples, setup instructions
871
+ - **changelog**: Recent release notes (last 5 versions) with breaking changes
872
+ - **migration**: Migration/upgrade guides (supports Svelte, Next.js, Tailwind, Vite, Stripe, Supabase, Better Auth, etc.)
873
+
874
+ Combine with a query to focus on a specific topic (e.g. query="runes" for Svelte 5 migration docs).
875
+
876
+ Examples:
877
+ - "Get Svelte 5 docs focused on runes migration"
878
+ - "Show me the Supabase JS changelog"
879
+ - "What changed in Tailwind CSS v4?"
880
+ - "Get Better Auth setup docs"`,
881
+ inputSchema: DocsSchema,
882
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
883
+ }, async ({ package: pkg, query, sections }) => {
884
+ try {
885
+ const opts = {
886
+ readme: !sections || sections === "all" || sections === "readme",
887
+ changelog: !sections || sections === "all" || sections === "changelog",
888
+ migration: !sections || sections === "all" || sections === "migration",
889
+ };
890
+ const result = await fetchLibraryDocs(pkg, query, opts);
891
+ const parts = [];
892
+ parts.push(`# 📚 ${result.package}@${result.version || "unknown"}`);
893
+ if (result.description)
894
+ parts.push(`> ${result.description}`);
895
+ if (result.homepage)
896
+ parts.push(`🔗 Homepage: ${result.homepage}`);
897
+ if (result.repository)
898
+ parts.push(`📦 Repository: ${result.repository}`);
899
+ parts.push("");
900
+ if (result.readme) {
901
+ parts.push("---");
902
+ parts.push("## README");
903
+ parts.push(result.readme);
904
+ parts.push("");
905
+ }
906
+ if (result.changelog) {
907
+ parts.push("---");
908
+ parts.push("## CHANGELOG (recent versions)");
909
+ parts.push(result.changelog);
910
+ parts.push("");
911
+ }
912
+ if (result.migrationGuide) {
913
+ parts.push("---");
914
+ parts.push("## MIGRATION GUIDE");
915
+ parts.push(result.migrationGuide);
916
+ parts.push("");
917
+ }
918
+ if (!result.readme && !result.changelog && !result.migrationGuide) {
919
+ parts.push("No documentation found. The package may not be on npm or may not have a GitHub repository.");
920
+ }
921
+ return text(parts.join("\n"));
922
+ }
923
+ catch (err) {
924
+ return error(err instanceof Error ? err.message : String(err));
925
+ }
926
+ });
927
+ // ─── depsonar_search_package ────────────────────────────────────────
928
+ server.registerTool("depsonar_search_package", {
929
+ title: "Search npm Packages",
930
+ description: `Search the npm registry for packages by name or keyword. Returns matching packages with name, latest version, and description.
931
+
932
+ Use this to find the right package name before calling depsonar_docs.
933
+
934
+ Examples:
935
+ - "Search for Svelte authentication libraries"
936
+ - "Find Stripe payment packages"
937
+ - "What Tailwind utility packages exist?"`,
938
+ inputSchema: SearchPackageSchema,
939
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
940
+ }, async ({ query }) => {
941
+ try {
942
+ const results = await searchPackage(query);
943
+ if (!results.length)
944
+ return text(`No packages found for "${query}".`);
945
+ const lines = [`# 🔍 npm search: "${query}"\n`];
946
+ for (const r of results) {
947
+ lines.push(`- **${r.name}** \`${r.version}\` — ${r.description}`);
948
+ }
949
+ lines.push("\n> Use `depsonar_docs` with the package name to get full documentation.");
950
+ return text(lines.join("\n"));
951
+ }
952
+ catch (err) {
953
+ return error(err instanceof Error ? err.message : String(err));
954
+ }
955
+ });
956
+ }
957
+ // ─── Scheduler Setup ───────────────────────────────────────────────────
958
+ function getCheckerPath() {
959
+ // Find the checker script relative to this file
960
+ const thisDir = new URL(".", import.meta.url).pathname;
961
+ const checkerPath = join(thisDir, "checker.js");
962
+ if (existsSync(checkerPath))
963
+ return checkerPath;
964
+ // Fallback: try npx
965
+ return ""; // will use npx
966
+ }
967
+ function setupLaunchd(intervalHours, uninstall) {
968
+ const plistName = "com.depsonar.checker";
969
+ const plistPath = join(homedir(), "Library", "LaunchAgents", `${plistName}.plist`);
970
+ if (uninstall) {
971
+ try {
972
+ run(`launchctl unload ${plistPath}`, homedir());
973
+ }
974
+ catch { /* might not be loaded */ }
975
+ if (existsSync(plistPath))
976
+ unlinkSync(plistPath);
977
+ return `Background checker removed.\n\nDeleted: \`${plistPath}\``;
978
+ }
979
+ const checkerPath = getCheckerPath();
980
+ const intervalSeconds = intervalHours * 3600;
981
+ // Use npx as fallback if checker.js path not found
982
+ const programArgs = checkerPath
983
+ ? ` <string>node</string>\n <string>${checkerPath}</string>`
984
+ : ` <string>npx</string>\n <string>depsonar</string>\n <string>--check</string>`;
985
+ const plist = `<?xml version="1.0" encoding="UTF-8"?>
986
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
987
+ <plist version="1.0">
988
+ <dict>
989
+ <key>Label</key>
990
+ <string>${plistName}</string>
991
+ <key>ProgramArguments</key>
992
+ <array>
993
+ ${programArgs}
994
+ </array>
995
+ <key>StartInterval</key>
996
+ <integer>${intervalSeconds}</integer>
997
+ <key>RunAtLoad</key>
998
+ <true/>
999
+ <key>StandardErrorPath</key>
1000
+ <string>${join(homedir(), ".depsonar-checker.log")}</string>
1001
+ <key>EnvironmentVariables</key>
1002
+ <dict>
1003
+ <key>PATH</key>
1004
+ <string>/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin</string>
1005
+ </dict>
1006
+ </dict>
1007
+ </plist>`;
1008
+ writeFileSync(plistPath, plist, "utf-8");
1009
+ try {
1010
+ run(`launchctl unload ${plistPath}`, homedir());
1011
+ }
1012
+ catch { /* might not exist yet */ }
1013
+ run(`launchctl load ${plistPath}`, homedir());
1014
+ return [
1015
+ "# Background Checker Installed ✅",
1016
+ "",
1017
+ `**Schedule**: Every ${intervalHours} hour(s)`,
1018
+ `**Method**: macOS launchd (native, lightweight)`,
1019
+ `**Plist**: \`${plistPath}\``,
1020
+ `**Log**: \`~/.depsonar-checker.log\``,
1021
+ `**Cache**: \`~/.depsonar-cache.json\``,
1022
+ "",
1023
+ "The checker will run immediately, then every " + intervalHours + "h.",
1024
+ "It scans your projects, writes the cache, and exits. Zero RAM between runs.",
1025
+ "",
1026
+ "Use `depsonar_alerts` to see results.",
1027
+ "Use `depsonar_setup_checker` with `uninstall: true` to remove.",
1028
+ ].join("\n");
1029
+ }
1030
+ function setupCron(intervalHours, uninstall) {
1031
+ const marker = "# depsonar background checker";
1032
+ try {
1033
+ const currentCron = run("crontab -l", homedir()).split("\n");
1034
+ const filtered = currentCron.filter((line) => !line.includes(marker) && !line.includes("depsonar"));
1035
+ if (uninstall) {
1036
+ const newCron = filtered.join("\n").trim() + "\n";
1037
+ writeFileSync("/tmp/depsonar-crontab", newCron, "utf-8");
1038
+ run("crontab /tmp/depsonar-crontab", homedir());
1039
+ unlinkSync("/tmp/depsonar-crontab");
1040
+ return "Background checker removed from crontab.";
1041
+ }
1042
+ const checkerPath = getCheckerPath();
1043
+ const cmd = checkerPath
1044
+ ? `node ${checkerPath}`
1045
+ : "npx --yes depsonar --check";
1046
+ const cronLine = `0 */${intervalHours} * * * ${cmd} 2>> ~/.depsonar-checker.log ${marker}`;
1047
+ filtered.push(cronLine);
1048
+ const newCron = filtered.join("\n").trim() + "\n";
1049
+ writeFileSync("/tmp/depsonar-crontab", newCron, "utf-8");
1050
+ run("crontab /tmp/depsonar-crontab", homedir());
1051
+ unlinkSync("/tmp/depsonar-crontab");
1052
+ return [
1053
+ "# Background Checker Installed ✅",
1054
+ "",
1055
+ `**Schedule**: Every ${intervalHours} hour(s)`,
1056
+ `**Method**: crontab`,
1057
+ `**Log**: \`~/.depsonar-checker.log\``,
1058
+ `**Cache**: \`~/.depsonar-cache.json\``,
1059
+ "",
1060
+ "Use `depsonar_alerts` to see results.",
1061
+ ].join("\n");
1062
+ }
1063
+ catch {
1064
+ return "Could not configure crontab. You can manually add this to your crontab:\n\n```\n0 */6 * * * npx --yes depsonar --check 2>> ~/.depsonar-checker.log\n```";
1065
+ }
1066
+ }
1067
+ //# sourceMappingURL=index.js.map