konoha-mcp 2.2.23 → 2.2.25

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 (132) hide show
  1. package/NOTICE +14 -8
  2. package/README.md +20 -5
  3. package/apps/web/build/adapter-node.js +1 -1
  4. package/apps/web/build/build-meta.json +2 -2
  5. package/apps/web/build/client/_app/immutable/entry/{app.TYH87iYy.js → app.DtoBIrs4.js} +2 -2
  6. package/apps/web/build/client/_app/immutable/entry/app.DtoBIrs4.js.br +0 -0
  7. package/apps/web/build/client/_app/immutable/entry/app.DtoBIrs4.js.gz +0 -0
  8. package/apps/web/build/client/_app/immutable/nodes/{0.D7dPIEWA.js → 0.B8Iw7Xl1.js} +1 -1
  9. package/apps/web/build/client/_app/immutable/nodes/0.B8Iw7Xl1.js.br +0 -0
  10. package/apps/web/build/client/_app/immutable/nodes/{0.D7dPIEWA.js.gz → 0.B8Iw7Xl1.js.gz} +0 -0
  11. package/apps/web/build/client/_app/immutable/nodes/{13.TOXVaTBr.js → 13.CQB_Ed6W.js} +1 -1
  12. package/apps/web/build/client/_app/immutable/nodes/13.CQB_Ed6W.js.br +0 -0
  13. package/apps/web/build/client/_app/immutable/nodes/{13.TOXVaTBr.js.gz → 13.CQB_Ed6W.js.gz} +0 -0
  14. package/apps/web/build/client/_app/version.json +1 -1
  15. package/apps/web/build/client/_app/version.json.br +0 -0
  16. package/apps/web/build/client/_app/version.json.gz +0 -0
  17. package/apps/web/build/server/chunks/instance.js +3 -3
  18. package/apps/web/build/server/chunks/internal.js +1 -1
  19. package/apps/web/build/server/entries/pages/_layout.svelte.js +1 -1
  20. package/apps/web/build/server/entries/pages/_layout.svelte.js.map +1 -1
  21. package/apps/web/build/server/entries/pages/docs/_page.svelte.js +1 -1
  22. package/apps/web/build/server/entries/pages/docs/_page.svelte.js.map +1 -1
  23. package/apps/web/build/server/manifest-full.js +1 -1
  24. package/apps/web/build/server/manifest.js +1 -1
  25. package/apps/web/build/server/nodes/0.js +1 -1
  26. package/apps/web/build/server/nodes/13.js +1 -1
  27. package/apps/web/build/server/server.js +1 -1
  28. package/apps/web/package.json +1 -1
  29. package/assets/demo-agy.webp +0 -0
  30. package/assets/demo-claude.webp +0 -0
  31. package/assets/demo-codex.webp +0 -0
  32. package/assets/demo-commandcode.webp +0 -0
  33. package/assets/demo-cursor.webp +0 -0
  34. package/assets/demo-opencode.webp +0 -0
  35. package/assets/demo-pi.webp +0 -0
  36. package/assets/demo-skill-embed.webp +0 -0
  37. package/assets/demo-skills.webp +0 -0
  38. package/assets/demo-web.webp +0 -0
  39. package/assets/demo.webp +0 -0
  40. package/assets/konoha-akatsuki-flow.webp +0 -0
  41. package/assets/konoha-anbu-flow.webp +0 -0
  42. package/assets/konoha-flow-12-cli-upgrade-progress-engine.webp +0 -0
  43. package/assets/konoha-jonin-flow.webp +0 -0
  44. package/assets/konoha-kage-gate.webp +0 -0
  45. package/assets/konoha-langgraph-flow.webp +0 -0
  46. package/assets/konoha-orchestration-flow.webp +0 -0
  47. package/assets/konoha-qa-flow.webp +0 -0
  48. package/assets/konoha-telegram-flow.webp +0 -0
  49. package/assets/testing.webp +0 -0
  50. package/bin/commands/bridge.js +62 -4
  51. package/bin/commands/doctor.js +2 -0
  52. package/bin/commands/doctor_services.js +57 -0
  53. package/bin/commands/init.js +29 -8
  54. package/bin/commands/init_clients.js +95 -8
  55. package/bin/commands/init_migration.js +32 -1
  56. package/bin/lib/config_defaults.js +3 -0
  57. package/bin/lib/runtime_install.js +147 -54
  58. package/node_modules/jszip/package.json +2 -2
  59. package/node_modules/string_decoder/package.json +1 -1
  60. package/package.json +10 -3
  61. package/patches/gpt-tokenizer@4.1.0.patch +15 -0
  62. package/patches/jszip@3.10.2.patch +11 -0
  63. package/patches/string_decoder@1.3.0.patch +12 -0
  64. package/src/agent_contract.js +2 -2
  65. package/src/agent_deployer.js +48 -35
  66. package/src/agent_file_safety.js +57 -0
  67. package/src/antigravity_subagent_hook.js +30 -12
  68. package/src/bridge/gateway.js +2 -0
  69. package/src/bridge/gateway_adapters.js +155 -29
  70. package/src/bridge/handlers/anthropic.js +95 -26
  71. package/src/bridge/handlers/openai.js +18 -5
  72. package/src/bridge/sidecar/raw.js +10 -2
  73. package/src/bridge/stream_usage.js +66 -0
  74. package/src/chunin_knowledge_ddl.js +95 -0
  75. package/src/client_commands.js +190 -0
  76. package/src/db_bridges.js +53 -7
  77. package/src/db_schema.js +14 -2
  78. package/src/deploy_installer.js +212 -11
  79. package/src/deploy_utils.js +4 -0
  80. package/src/file_tools/common.js +65 -3
  81. package/src/file_tools_mcp.js +17 -9
  82. package/src/file_tools_router.js +67 -6
  83. package/src/global_skill_sync.js +3 -1
  84. package/src/mcp/chunin_knowledge.js +509 -0
  85. package/src/mcp/langgraph/edges/router.js +3 -0
  86. package/src/mcp/langgraph/index.js +22 -3
  87. package/src/mcp/langgraph/nodes/dispatch.js +3 -0
  88. package/src/mcp/langgraph/nodes/execute.js +87 -13
  89. package/src/mcp/langgraph/nodes/review.js +13 -1
  90. package/src/mcp/langgraph/slice_executor_registry.js +22 -0
  91. package/src/mcp/langgraph/state.js +5 -0
  92. package/src/mcp/lazy_subagent.js +11 -1
  93. package/src/mcp/memory_project_context.js +4 -1
  94. package/src/mcp/memory_subagent_runner.js +2 -1
  95. package/src/mcp/skills_common.js +1 -0
  96. package/src/mcp/subagent_spawner.js +7 -0
  97. package/src/mcp/todo_walkthrough_sync.js +7 -0
  98. package/src/mcp/tool_dispatch.js +18 -1
  99. package/src/mcp/web_search.js +27 -3
  100. package/src/mcp/workflow_completion_helpers.js +6 -1
  101. package/src/mcp/workflow_gates.js +118 -5
  102. package/src/mcp/workflow_sannin.js +9 -3
  103. package/src/mcp_clients/common.js +31 -0
  104. package/src/mcp_tool_manifest.json +36 -1
  105. package/src/pi_fs_helpers.js +31 -0
  106. package/src/pi_manager.js +68 -28
  107. package/src/provider_usage_logger.js +92 -0
  108. package/src/schema_ddl.js +17 -1
  109. package/src/templates/AGENTS.md +1 -1
  110. package/src/templates/GEMINI.md +1 -1
  111. package/src/templates/skills/chunin-skill/SKILL.md +34 -0
  112. package/src/templates/skills/chunin-skill/references/deep-research-analyst.md +27 -10
  113. package/src/templates/skills/kage-skill/SKILL.md +1 -1
  114. package/src/templates/skills/konoha/SKILL.md +23 -165
  115. package/src/templates/skills/konoha/references/contract.md +2 -2
  116. package/src/templates/skills/konoha/references/peragent-usage.md +1 -1
  117. package/src/token_usage.js +57 -0
  118. package/src/tools_savings_logger.js +26 -8
  119. package/src/url_canonical.js +58 -0
  120. package/src/vector_pipeline.js +6 -4
  121. package/src/vector_search.js +4 -2
  122. package/src/web/controllers/core_controller.js +10 -1
  123. package/src/workflow/jonin-builder/live_browser_monitor.js +23 -7
  124. package/apps/web/build/client/_app/immutable/entry/app.TYH87iYy.js.br +0 -0
  125. package/apps/web/build/client/_app/immutable/entry/app.TYH87iYy.js.gz +0 -0
  126. package/apps/web/build/client/_app/immutable/nodes/0.D7dPIEWA.js.br +0 -0
  127. package/apps/web/build/client/_app/immutable/nodes/13.TOXVaTBr.js.br +0 -0
  128. package/src/templates/skills/konoha/references/architecture.md +0 -99
  129. package/src/templates/skills/konoha/references/benchmark.md +0 -123
  130. package/src/templates/skills/konoha/references/docs.md +0 -46
  131. package/src/templates/skills/konoha/references/test.md +0 -71
  132. package/src/templates/skills/konoha/references/workflow.md +0 -104
@@ -91,7 +91,10 @@ function fileExists(p) {
91
91
  function ensureDir(p) {
92
92
  try {
93
93
  fs.mkdirSync(p, { recursive: true });
94
- } catch { /* intentional fallback */ }
94
+ } catch (err) {
95
+ // A swallowed mkdir loses every file written under it, so report the path.
96
+ console.warn(`[warning] Could not create directory ${p}: ${err && err.message ? err.message : err}`);
97
+ }
95
98
  }
96
99
 
97
100
  function copyIfDifferent(src, dest) {
@@ -105,7 +108,10 @@ function copyIfDifferent(src, dest) {
105
108
  ensureDir(path.dirname(dest));
106
109
  fs.writeFileSync(dest, srcBuf);
107
110
  return true;
108
- } catch {
111
+ } catch (err) {
112
+ // Returning false silently used to hide a missing runtime file behind an
113
+ // install that reported success.
114
+ console.warn(`[warning] Could not copy ${src} -> ${dest}: ${err && err.message ? err.message : err}`);
109
115
  return false;
110
116
  }
111
117
  }
@@ -206,6 +212,46 @@ function syncRuntimeJsFiles(srcDir, destDir) {
206
212
  copyJsFileIfMatching(entry, srcDir, destDir);
207
213
  }
208
214
  } catch (_) { /* non-fatal */ }
215
+ // Repoint the flat root modules at the mirrored src/ tree; the copy above is
216
+ // what a partial install (no src/ mirror yet) still needs.
217
+ ensureMirroredRootFileLinks(destDir);
218
+ }
219
+
220
+ // Top-level entries under src/ that are build or scratch output rather than
221
+ // shipped runtime code. Everything else in src/ is mirrored, so a new src/<sub>
222
+ // directory is installed without also being added to a hand-maintained list —
223
+ // the list is what let src/web, src/telegram and src/templates go missing while
224
+ // modules under src/mcp/ kept requiring them.
225
+ const RUNTIME_MIRROR_DENYLIST = new Set([
226
+ 'node_modules',
227
+ '.git',
228
+ '.cache',
229
+ '.svelte-kit',
230
+ '__pycache__',
231
+ '.pytest_cache',
232
+ '.ruff_cache',
233
+ '.DS_Store',
234
+ 'build',
235
+ 'dist',
236
+ 'coverage',
237
+ 'tmp',
238
+ 'scratch'
239
+ ]);
240
+
241
+ function listRuntimeSubdirectories(srcDir) {
242
+ const names = [];
243
+ let entries = [];
244
+ try {
245
+ entries = fs.readdirSync(srcDir, { withFileTypes: true });
246
+ } catch (_) {
247
+ return names;
248
+ }
249
+ for (const entry of entries) {
250
+ if (!entry.isDirectory()) continue;
251
+ if (RUNTIME_MIRROR_DENYLIST.has(entry.name)) continue;
252
+ names.push(entry.name);
253
+ }
254
+ return names.sort();
209
255
  }
210
256
 
211
257
  function syncRuntimeSubdirectories(srcDir, destDir) {
@@ -219,21 +265,21 @@ function syncRuntimeSubdirectories(srcDir, destDir) {
219
265
  if (fileExists(migrationsSrc)) {
220
266
  synced += copyRecursiveIfDifferent(migrationsSrc, path.join(destDir, 'migrations'));
221
267
  }
222
- const subdirs = [
223
- { src: 'file_tools', dest: FILE_TOOLS_PY_DIR },
224
- { src: 'mcp', dest: path.join(destDir, 'mcp') },
225
- { src: 'mcp_clients', dest: path.join(destDir, 'mcp_clients') },
226
- { src: 'queue', dest: path.join(destDir, 'queue') },
227
- { src: 'workflow', dest: path.join(destDir, 'workflow') },
228
- { src: 'bridge', dest: path.join(destDir, 'bridge') },
229
- { src: 'code_intel', dest: path.join(destDir, 'code_intel') }
230
- ];
268
+ const subdirs = listRuntimeSubdirectories(srcDir).map(name => ({
269
+ src: name,
270
+ // The Python file tools keep their own destination; every other
271
+ // subdirectory mirrors under its own name.
272
+ dest: name === 'file_tools' ? FILE_TOOLS_PY_DIR : path.join(destDir, name)
273
+ }));
231
274
  for (const item of subdirs) {
232
275
  const fullSrc = path.join(srcDir, item.src);
233
276
  if (fileExists(fullSrc)) {
234
277
  synced += copyRecursiveIfDifferent(fullSrc, item.dest);
235
278
  }
236
279
  }
280
+ // Link after the copy, so each flat name resolves at its mirrored tree and a
281
+ // module below it reaches src/ siblings instead of one level too high.
282
+ ensureMirroredSubdirLinks(destDir);
237
283
  const grammarsSrc = path.join(rootDir, 'assets', 'grammars');
238
284
  if (fileExists(grammarsSrc)) {
239
285
  synced += copyRecursiveIfDifferent(grammarsSrc, path.join(destDir, 'assets', 'grammars'));
@@ -241,6 +287,159 @@ function syncRuntimeSubdirectories(srcDir, destDir) {
241
287
  return synced;
242
288
  }
243
289
 
290
+ // The flat ~/.konoha/<sub> mirror sits one level above the mirrored
291
+ // ~/.konoha/src/<sub> tree, so an escaped require such as
292
+ // ../../web/controllers/common from ~/.konoha/mcp/three_asset/ resolves to
293
+ // ~/.konoha/web instead of the mirrored src/web and fails at load. Linking the
294
+ // flat name at the mirrored tree restores repo-relative resolution for every
295
+ // module below it, rather than patching one require at a time.
296
+ //
297
+ // Node resolves a module's filename through realpath, so the link is enough: the
298
+ // require graph is then evaluated at the mirrored depth, which is the depth the
299
+ // repo tree has. src/file_tools is linked too, because its common.js reaches
300
+ // ../../bin/lib/paths, which only resolves from that depth.
301
+ function ensureMirroredSubdirLinks(destDir) {
302
+ const linked = new Set();
303
+ const mirrorRoot = path.join(destDir, 'src');
304
+ if (!fileExists(mirrorRoot)) return linked;
305
+ for (const sub of listRuntimeSubdirectories(mirrorRoot)) {
306
+ const target = path.join(mirrorRoot, sub);
307
+ if (!fileExists(target)) continue;
308
+ const linkPath = path.join(destDir, sub);
309
+ const relativeTarget = path.join('src', sub);
310
+ if (replaceWithMirrorLink(linkPath, relativeTarget, destDir)) linked.add(sub);
311
+ }
312
+ return linked;
313
+ }
314
+
315
+ // A root module is copied flat into ~/.konoha/, where its upward require —
316
+ // ../package.json in cyber_pack.js, ../bin/lib/yaml_utils in db_agents.js —
317
+ // escapes to the home directory instead of the install. Link each flat root
318
+ // module at the mirrored src/ file so it resolves from the repo's own depth.
319
+ function ensureMirroredRootFileLinks(destDir) {
320
+ const linked = new Set();
321
+ const mirrorRoot = path.join(destDir, 'src');
322
+ if (!fileExists(mirrorRoot)) return linked;
323
+ let entries = [];
324
+ try {
325
+ entries = fs.readdirSync(mirrorRoot, { withFileTypes: true });
326
+ } catch (_) {
327
+ return linked;
328
+ }
329
+ for (const entry of entries) {
330
+ if (!entry.isFile() || !entry.name.endsWith('.js')) continue;
331
+ const linkPath = path.join(destDir, entry.name);
332
+ const relativeTarget = path.join('src', entry.name);
333
+ if (replaceWithMirrorLink(linkPath, relativeTarget, destDir)) linked.add(entry.name);
334
+ }
335
+ return linked;
336
+ }
337
+
338
+ // A link is an optimisation, not a correctness requirement: the flat copy is a
339
+ // valid install, so every failure here must keep the copy rather than lose it.
340
+ //
341
+ // The probe is per link KIND because the two are not interchangeable on Windows.
342
+ // A 'junction' is a directory reparse point; pointing one at a FILE is created
343
+ // without error and then resolves to nothing, so probing only a directory
344
+ // junction authorised file links that could never work and silently deleted the
345
+ // file they replaced. Probe a directory junction and a real file link separately.
346
+ let symlinkSupport = null;
347
+
348
+ // statSync follows the link, and readdir/readFile then prove the target is
349
+ // actually reachable. existsSync alone returns false for a dangling link, so it
350
+ // cannot distinguish a working link from one that resolves to nothing.
351
+ function linkResolves(linkPath, expectDirectory) {
352
+ try {
353
+ const stat = fs.statSync(linkPath);
354
+ if (stat.isDirectory() !== expectDirectory) return false;
355
+ if (expectDirectory) fs.readdirSync(linkPath);
356
+ else fs.readFileSync(linkPath);
357
+ return true;
358
+ } catch (_) {
359
+ return false;
360
+ }
361
+ }
362
+
363
+ function probeSymlinkSupport(destDir) {
364
+ if (symlinkSupport !== null) return symlinkSupport;
365
+ const probeDir = path.join(destDir, '.konoha-link-probe');
366
+ const support = { dir: false, file: false };
367
+ try {
368
+ fs.rmSync(probeDir, { recursive: true, force: true });
369
+ fs.mkdirSync(probeDir, { recursive: true });
370
+
371
+ const dirTarget = path.join(probeDir, 'dir-target');
372
+ fs.mkdirSync(dirTarget, { recursive: true });
373
+ const dirLink = path.join(probeDir, 'dir-link');
374
+ try {
375
+ fs.symlinkSync(dirTarget, dirLink, 'junction');
376
+ support.dir = linkResolves(dirLink, true);
377
+ } catch (_) {
378
+ support.dir = false;
379
+ }
380
+
381
+ const fileTarget = path.join(probeDir, 'file-target');
382
+ fs.writeFileSync(fileTarget, 'probe');
383
+ const fileLink = path.join(probeDir, 'file-link');
384
+ try {
385
+ fs.symlinkSync(fileTarget, fileLink, 'file');
386
+ support.file = linkResolves(fileLink, false);
387
+ } catch (_) {
388
+ support.file = false;
389
+ }
390
+ } catch (_) {
391
+ support.dir = false;
392
+ support.file = false;
393
+ } finally {
394
+ try { fs.rmSync(probeDir, { recursive: true, force: true }); } catch (_) { /* best effort */ }
395
+ }
396
+ symlinkSupport = support;
397
+ return support;
398
+ }
399
+
400
+ function replaceWithMirrorLink(linkPath, relativeTarget, destDir) {
401
+ // The link kind follows the target: directories take a junction, files take a
402
+ // real file link, and on Windows only the directory form is elevation-free.
403
+ let targetIsDirectory = null;
404
+ try {
405
+ targetIsDirectory = fs.statSync(path.join(destDir, relativeTarget)).isDirectory();
406
+ } catch (_) {
407
+ return false;
408
+ }
409
+ const support = probeSymlinkSupport(destDir);
410
+ if (targetIsDirectory ? !support.dir : !support.file) return false;
411
+ const linkType = targetIsDirectory ? 'junction' : 'file';
412
+
413
+ const staging = `${linkPath}.konoha-link-tmp`;
414
+ try {
415
+ let existing = null;
416
+ try {
417
+ existing = fs.lstatSync(linkPath);
418
+ } catch (_) {
419
+ existing = null;
420
+ }
421
+ if (existing && existing.isSymbolicLink()) {
422
+ try {
423
+ if (fs.readlinkSync(linkPath) === relativeTarget && linkResolves(linkPath, targetIsDirectory)) return true;
424
+ } catch (_) { /* rebuild below */ }
425
+ }
426
+ fs.rmSync(staging, { recursive: true, force: true });
427
+ fs.symlinkSync(relativeTarget, staging, linkType);
428
+ // Nothing is deleted until the replacement is proven to resolve. A dangling
429
+ // staging link leaves the working copy untouched and reports failure.
430
+ if (!linkResolves(staging, targetIsDirectory)) {
431
+ fs.rmSync(staging, { recursive: true, force: true });
432
+ return false;
433
+ }
434
+ fs.rmSync(linkPath, { recursive: true, force: true });
435
+ fs.renameSync(staging, linkPath);
436
+ return true;
437
+ } catch (_) {
438
+ try { fs.rmSync(staging, { recursive: true, force: true }); } catch (_) { /* best effort */ }
439
+ return false;
440
+ }
441
+ }
442
+
244
443
  function installRuntimePackageDependencies(destDir, silent) {
245
444
  const pkgPath = path.join(destDir, 'package.json');
246
445
  const nodeModulesPath = path.join(destDir, 'node_modules');
@@ -481,6 +680,8 @@ module.exports = {
481
680
  KONOHA_CANONICAL_TOOLS,
482
681
  buildKonohaFilesMcpEntry,
483
682
  installFileTools,
683
+ ensureMirroredSubdirLinks,
684
+ ensureMirroredRootFileLinks,
484
685
  syncRuntimeSubdirectories,
485
686
  cleanKonohaRuntimeDir
486
687
  };
@@ -38,6 +38,8 @@ const {
38
38
  KONOHA_CANONICAL_TOOLS,
39
39
  buildKonohaFilesMcpEntry,
40
40
  installFileTools,
41
+ ensureMirroredSubdirLinks,
42
+ ensureMirroredRootFileLinks,
41
43
  cleanKonohaRuntimeDir
42
44
  } = require('./deploy_installer');
43
45
 
@@ -612,6 +614,8 @@ module.exports = {
612
614
  copySkillsDirFast,
613
615
  pruneObsoleteStandaloneSkills,
614
616
  installFileTools,
617
+ ensureMirroredSubdirLinks,
618
+ ensureMirroredRootFileLinks,
615
619
  cleanKonohaRuntimeDir,
616
620
  parseNodeVersion,
617
621
  isNodeVersionCompatible,
@@ -85,6 +85,43 @@ function norm(p) {
85
85
  }
86
86
 
87
87
  let _KONOHA_HOME = null;
88
+
89
+ // Extra project roots an operator opted into, path.delimiter-separated in
90
+ // KONOHA_ALLOWED_ROOTS (the same shape as KONOHA_ALLOWED_DB_ROOTS). Empty by
91
+ // default, so the boundary only widens for a root that is named explicitly.
92
+ // Resolve a path through symlinks, tolerating one that does not exist yet: fall
93
+ // back to resolving its deepest existing ancestor and re-appending the rest, so a
94
+ // path under a symlinked parent (macOS /var -> /private/var) still matches a root.
95
+ function realpathOrSelf(target) {
96
+ const resolved = path.resolve(target);
97
+ try {
98
+ return fs.realpathSync(resolved);
99
+ } catch (_) {
100
+ try {
101
+ return path.join(fs.realpathSync(path.dirname(resolved)), path.basename(resolved));
102
+ } catch (_) {
103
+ return resolved;
104
+ }
105
+ }
106
+ }
107
+
108
+ function getAllowedRoots() {
109
+ const raw = process.env.KONOHA_ALLOWED_ROOTS;
110
+ if (!raw || typeof raw !== 'string') return [];
111
+ const roots = [];
112
+ for (const part of raw.split(path.delimiter)) {
113
+ const entry = part && part.trim();
114
+ if (!entry) continue;
115
+ let real;
116
+ try {
117
+ real = fs.realpathSync(path.resolve(entry));
118
+ } catch {
119
+ continue; // An entry that does not exist authorizes nothing.
120
+ }
121
+ roots.push(norm(stripWinPrefix(real)));
122
+ }
123
+ return roots;
124
+ }
88
125
  function getKonohaHome() {
89
126
  const dynamicHome = process.env.HOME || process.env.USERPROFILE || os.homedir();
90
127
  const candidate = stripWinPrefix(path.resolve(path.normalize(path.join(dynamicHome, '.konoha'))));
@@ -208,12 +245,37 @@ function assertWithinAllowed(resolvedPath, baseDir = null, devRoot = null) {
208
245
  wsReal = stripWinPrefix(wsReal);
209
246
  const wsNorm = norm(wsReal);
210
247
 
211
- const rel = path.relative(wsNorm, normPath);
212
- if (!rel.startsWith('..') && !path.isAbsolute(rel)) {
248
+ // macOS exposes /var as a symlink to /private/var, and the roots above are
249
+ // realpath'd, so an input still carrying the unresolved form would not match
250
+ // its own root. Compare both forms; a sibling still fails closed in both.
251
+ const candidates = [normPath];
252
+ const realNorm = norm(realpathOrSelf(resolvedPath));
253
+ if (realNorm !== normPath) candidates.push(realNorm);
254
+ const containedIn = (root, candidate) => {
255
+ const rel = path.relative(root, candidate);
256
+ return !rel.startsWith('..') && !path.isAbsolute(rel);
257
+ };
258
+
259
+ if (candidates.some((candidate) => containedIn(wsNorm, candidate))) {
213
260
  return;
214
261
  }
215
262
 
216
- throw new Error(`Path outside workspace: ${resolvedPath}`);
263
+ // Operator-allowlisted project roots, checked with the same containment rule
264
+ // as the workspace so a sibling of a named root still fails closed.
265
+ for (const allowed of getAllowedRoots()) {
266
+ if (candidates.some((candidate) => containedIn(allowed, candidate))) {
267
+ return;
268
+ }
269
+ }
270
+
271
+ // Name the boundary and the remedy: a bare path leaves the reader with nothing
272
+ // to act on, and this refusal is the most common report against the file tools.
273
+ throw new Error(
274
+ `Path outside workspace: ${resolvedPath}. `
275
+ + `Allowed: the workspace root (${wsNorm}), any root named in KONOHA_ALLOWED_ROOTS, `
276
+ + 'or a Konoha scratch directory. Set WORKSPACE_ROOT to the project, or add it to '
277
+ + 'KONOHA_ALLOWED_ROOTS (path-delimiter separated) and restart the MCP server.'
278
+ );
217
279
  }
218
280
 
219
281
  function resolvePath(rawPath, baseDir = null, devRoot = null) {
@@ -372,15 +372,23 @@ function loadBridgesFromMcp() {
372
372
  try {
373
373
  const db = require("./db");
374
374
  conn = db.getConnection();
375
- const rows = conn.prepare("SELECT name, port, provider, enabled, target_url AS targetUrl, api_key AS apiKey FROM bridges").all();
376
- const existing = rows.map(r => ({
377
- name: r.name,
378
- port: r.port,
379
- provider: r.provider,
380
- enabled: Boolean(r.enabled),
381
- targetUrl: r.targetUrl,
382
- apiKey: r.apiKey
383
- }));
375
+ const rows = conn.prepare("SELECT name, port, provider, enabled, target_url AS targetUrl, api_key AS apiKey, supports_stream_usage AS supportsStreamUsage FROM bridges").all();
376
+ const existing = rows.map(r => {
377
+ const bridge = {
378
+ name: r.name,
379
+ port: r.port,
380
+ provider: r.provider,
381
+ enabled: Boolean(r.enabled),
382
+ targetUrl: r.targetUrl,
383
+ apiKey: r.apiKey
384
+ };
385
+ // Only an explicit stored override becomes a boolean; `undefined` keeps
386
+ // the provider allowlist in charge.
387
+ if (r.supportsStreamUsage !== null && r.supportsStreamUsage !== undefined) {
388
+ bridge.supportsStreamUsage = Boolean(r.supportsStreamUsage);
389
+ }
390
+ return bridge;
391
+ });
384
392
  for (const b of existing) {
385
393
  validateBridgeTargetUrl(b);
386
394
  }
@@ -156,10 +156,46 @@ function getWorkspaceRoot() {
156
156
  return ws ? platform.stripWinExtendedPrefix(ws) : ws;
157
157
  }
158
158
 
159
- function uriToPath(uri) {
160
- return platform.uriToPath(uri);
159
+ // Extra project roots an operator opted into, path.delimiter-separated in
160
+ // KONOHA_ALLOWED_ROOTS (the same shape as KONOHA_ALLOWED_DB_ROOTS). Empty by
161
+ // default, so the boundary only widens for a root that is named explicitly.
162
+ function getAllowedRoots() {
163
+ const raw = process.env.KONOHA_ALLOWED_ROOTS;
164
+ if (!raw || typeof raw !== 'string') return [];
165
+ const roots = [];
166
+ for (const part of raw.split(path.delimiter)) {
167
+ const entry = part && part.trim();
168
+ if (!entry) continue;
169
+ let real;
170
+ try {
171
+ real = fs.realpathSync(path.resolve(platform.expandUser(entry)));
172
+ } catch {
173
+ continue; // An entry that does not exist authorizes nothing.
174
+ }
175
+ roots.push(platform.normPath(platform.stripWinExtendedPrefix(real)));
176
+ }
177
+ return roots;
161
178
  }
162
179
 
180
+ // Resolve a path through symlinks, tolerating one that does not exist yet: fall
181
+ // back to resolving its deepest existing ancestor and re-appending the rest, so a
182
+ // path under a symlinked parent (macOS /var -> /private/var) still matches a root.
183
+ function realpathOrSelf(target) {
184
+ const resolved = path.resolve(target);
185
+ try {
186
+ return fs.realpathSync(resolved);
187
+ } catch (_) {
188
+ try {
189
+ return path.join(fs.realpathSync(path.dirname(resolved)), path.basename(resolved));
190
+ } catch (_) {
191
+ return resolved;
192
+ }
193
+ }
194
+ }
195
+
196
+ function uriToPath(uri) {
197
+ return platform.uriToPath(uri);}
198
+
163
199
  function resolveInputPath(rawPath) {
164
200
  let p = rawPath;
165
201
  if (p && typeof p === 'object') {
@@ -256,13 +292,38 @@ function assertWithinAllowed(resolvedPath) {
256
292
  }
257
293
  wsReal = platform.stripWinExtendedPrefix(wsReal);
258
294
  const wsNorm = platform.normPath(wsReal);
259
- const rel = path.relative(wsNorm, pathNorm);
260
- if (!rel.startsWith('..') && !path.isAbsolute(rel)) {
295
+
296
+ // macOS exposes /var as a symlink to /private/var, and every root above is
297
+ // realpath'd, so an input that still carries the unresolved form would never
298
+ // match its own root. Compare both forms; containment must hold for the real
299
+ // path, and a sibling of a named root still fails closed in both.
300
+ const candidates = [pathNorm];
301
+ const realNorm = platform.normPath(
302
+ platform.stripWinExtendedPrefix(realpathOrSelf(resolvedPath))
303
+ );
304
+ if (realNorm !== pathNorm) candidates.push(realNorm);
305
+
306
+ const containedIn = (root, candidate) => {
307
+ const rel = path.relative(root, candidate);
308
+ return !rel.startsWith('..') && !path.isAbsolute(rel);
309
+ };
310
+
311
+ if (candidates.some((candidate) => containedIn(wsNorm, candidate))) {
261
312
  return;
262
313
  }
263
314
 
264
- // Path outside workspace boundary
265
- throw new Error(`Path outside workspace: ${resolvedPath}`);
315
+ // Operator-allowlisted project roots, checked with the same containment rule
316
+ // as the workspace so a sibling of a named root still fails closed.
317
+ for (const allowed of getAllowedRoots()) {
318
+ if (candidates.some((candidate) => containedIn(allowed, candidate))) {
319
+ return;
320
+ }
321
+ }
322
+
323
+ // Name the boundary and the remedy: a bare path leaves nothing to act on.
324
+ throw new Error(
325
+ `Path outside workspace: ${resolvedPath}. Allowed: the workspace root (${wsNorm}) or any root in KONOHA_ALLOWED_ROOTS. Set WORKSPACE_ROOT to the project, or add it to KONOHA_ALLOWED_ROOTS (path-delimiter separated) and restart the MCP server.`
326
+ );
266
327
  }
267
328
 
268
329
 
@@ -378,7 +378,9 @@ function syncAllGlobalClientSkills(options = {}) {
378
378
  clientsSynced: []
379
379
  };
380
380
 
381
- const requestedClients = Array.isArray(options.clients) && options.clients.length > 0 && !options.clients.includes('all')
381
+ // `undefined`/`null` = every target; an explicit array means exactly those
382
+ // clients (plus the shared `global` dir). An empty array is a valid "none".
383
+ const requestedClients = Array.isArray(options.clients) && !options.clients.includes('all')
382
384
  ? new Set(['global', ...options.clients])
383
385
  : null;
384
386