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
@@ -92,6 +92,8 @@ Usage:
92
92
  konoha bridge delete <bridge name> Delete a bridge configuration
93
93
  konoha bridge enable <bridge name> Enable a bridge configuration
94
94
  konoha bridge disable <bridge name> Disable a bridge configuration
95
+ konoha bridge stream-usage <name> [auto|always|never]
96
+ Allow this upstream to receive stream_options.include_usage
95
97
 
96
98
  Examples:
97
99
  konoha bridge start (Launch standalone bridge proxy on port ${GATEWAY_PORT})
@@ -146,6 +148,10 @@ async function cmdBridge(args) {
146
148
  case 'create':
147
149
  await cmdBridgeCreate(subArgs[0]);
148
150
  break;
151
+ case 'stream-usage':
152
+ case 'set-stream-usage':
153
+ await cmdBridgeStreamUsage(subArgs[0], subArgs[1]);
154
+ break;
149
155
  default:
150
156
  error(`Unknown bridge subcommand: ${subcommand}`);
151
157
  log(`Run ${C.cyan}konoha bridge help${C.reset} for usage.`);
@@ -265,19 +271,21 @@ async function cmdBridgeList() {
265
271
  providerLabel,
266
272
  b.enabled ? 'Enabled' : 'Disabled',
267
273
  active ? 'Running' : 'Stopped',
274
+ b.supportsStreamUsage === undefined ? 'Auto' : (b.supportsStreamUsage ? 'Always' : 'Never'),
268
275
  b.targetUrl || '-'
269
276
  ]);
270
277
  }
271
278
 
272
- const headers = ['Name', 'Port', 'Provider', 'Configured Status', 'Runtime Status', 'Target URL'];
273
- const widths = computeTableWidths(headers, rows, { minWidths: [15, 6, 12, 10, 10, 20] });
274
- drawTable(headers, widths, ['left', 'left', 'left', 'left', 'left', 'left'], rows, [], RASENGAN_THEME, {
279
+ const headers = ['Name', 'Port', 'Provider', 'Configured Status', 'Runtime Status', 'Stream Usage', 'Target URL'];
280
+ const widths = computeTableWidths(headers, rows, { minWidths: [15, 6, 12, 10, 10, 8, 20] });
281
+ drawTable(headers, widths, ['left', 'left', 'left', 'left', 'left', 'left', 'left'], rows, [], RASENGAN_THEME, {
275
282
  columnFormatters: [
276
283
  (cell) => applyGradient(cell.trimEnd(), RASENGAN_THEME, 0.9) + cell.slice(cell.trimEnd().length),
277
284
  (cell) => cell,
278
285
  (cell) => cell,
279
286
  (cell) => cell.includes('Enabled') ? `${C.green}${cell}${C.reset}` : `${C.dim}${cell}${C.reset}`,
280
287
  (cell) => cell.includes('Running') ? `${C.green}${cell}${C.reset}` : `${C.red}${cell}${C.reset}`,
288
+ (cell) => cell,
281
289
  (cell) => cell
282
290
  ]
283
291
  });
@@ -550,6 +558,15 @@ async function cmdBridgeCreate(name) {
550
558
  const apiKey = await askQuestion(' API Key (required for most APIs): ');
551
559
  if (!apiKey?.trim()) { error('API Key is required.'); process.exit(1); }
552
560
 
561
+ // Some OpenAI-compatible servers validate unknown parameters and reject the
562
+ // whole request over stream_options, so the capability is explicit per bridge.
563
+ const usageAnswer = await askQuestion(' Send stream usage (stream_options.include_usage)? [auto/always/never, default auto]: ');
564
+ const streamUsage = parseStreamUsageAnswer(usageAnswer);
565
+ if (streamUsage === undefined) {
566
+ error('Invalid answer. Use auto, always, or never.');
567
+ process.exit(1);
568
+ }
569
+
553
570
  const newBridge = {
554
571
  name: bridgeName,
555
572
  port,
@@ -558,6 +575,7 @@ async function cmdBridgeCreate(name) {
558
575
  apiKey: apiKey.trim(),
559
576
  enabled: true
560
577
  };
578
+ if (streamUsage !== null) newBridge.supportsStreamUsage = streamUsage;
561
579
 
562
580
  if (!saveBridgeSqlite('upsert', newBridge)) {
563
581
  error(`Failed to create bridge "${bridgeName}".`);
@@ -565,7 +583,46 @@ async function cmdBridgeCreate(name) {
565
583
  }
566
584
  log('');
567
585
  success(`Bridge "${bridgeName}" created!`);
568
- log(` Provider : OpenAI Compatible\n`);
586
+ log(` Provider : OpenAI Compatible\n Stream usage: ${streamUsage === null ? 'auto (provider allowlist)' : (streamUsage ? 'always' : 'never')}\n`);
587
+ }
588
+
589
+ /** `null` = auto, `true`/`false` = explicit override, `undefined` = unparseable. */
590
+ function parseStreamUsageAnswer(answer) {
591
+ const token = String(answer === undefined || answer === null ? '' : answer).trim().toLowerCase();
592
+ if (token === '' || token === 'auto' || token === '1') return null;
593
+ if (['always', 'on', 'true', 'yes', '2'].includes(token)) return true;
594
+ if (['never', 'off', 'false', 'no', '3'].includes(token)) return false;
595
+ return undefined;
596
+ }
597
+
598
+ async function cmdBridgeStreamUsage(name, mode) {
599
+ if (!name) {
600
+ error('Please specify a bridge name.');
601
+ log(`Usage: ${C.cyan}konoha bridge stream-usage <name> [auto|always|never]${C.reset}`);
602
+ process.exit(1);
603
+ }
604
+ let answer = mode;
605
+ if (answer === undefined) {
606
+ const bridges = loadBridges();
607
+ const bridge = bridges.find(b => b.name === name);
608
+ if (!bridge) { error(`Bridge "${name}" not found.`); process.exit(1); }
609
+ const current = bridge.supportsStreamUsage === undefined ? 'auto' : (bridge.supportsStreamUsage ? 'always' : 'never');
610
+ answer = await askQuestion(` Send stream usage (stream_options.include_usage)? [auto/always/never, current: ${current}]: `);
611
+ }
612
+ const streamUsage = parseStreamUsageAnswer(answer);
613
+ if (streamUsage === undefined) {
614
+ error(`Unknown stream usage mode "${answer}". Use auto, always, or never.`);
615
+ process.exit(1);
616
+ }
617
+ let stored;
618
+ try {
619
+ stored = require('../../src/db_bridges').setStreamUsage(name, streamUsage);
620
+ } catch (err) {
621
+ error(err.message || 'Failed to update stream usage capability.');
622
+ process.exit(1);
623
+ }
624
+ const label = stored === null ? 'auto (provider allowlist)' : (stored ? 'always' : 'never');
625
+ success(`Stream usage for "${name}" set to ${label}.`);
569
626
  }
570
627
 
571
628
 
@@ -584,6 +641,7 @@ module.exports = {
584
641
  cmdBridgeEnable,
585
642
  cmdBridgeDisable,
586
643
  cmdBridgeCreate,
644
+ cmdBridgeStreamUsage,
587
645
  loadBridges,
588
646
  saveBridgeSqlite,
589
647
  checkPortActive,
@@ -24,6 +24,7 @@ const { checkAndRepairClientConfigs } = require('./doctor_clients');
24
24
  const {
25
25
  checkDatabaseAndMigrations,
26
26
  checkGeminiAndAgentsConfig,
27
+ checkClientCommandsAndConflicts,
27
28
  checkPromptHookConfig,
28
29
  checkGovernanceAndServices,
29
30
  checkVpsPreflight
@@ -138,6 +139,7 @@ async function cmdDoctor(args = []) {
138
139
  await checkDatabaseAndMigrations(context);
139
140
  if (args.includes('--vps')) await checkVpsPreflight(context);
140
141
  checkGeminiAndAgentsConfig(context);
142
+ checkClientCommandsAndConflicts(context);
141
143
  await checkPromptHookConfig(context, globalSpinner);
142
144
 
143
145
  const clientRepairOptions = {
@@ -194,6 +194,62 @@ function checkGeminiAndAgentsConfig(context) {
194
194
  }
195
195
  }
196
196
 
197
+ /**
198
+ * `/konoha` exists only where a prompt file was deployed, and a parked
199
+ * `.konoha-proposed` candidate means a foreign profile won and is silently in
200
+ * effect. Both are invisible otherwise, which is exactly how a client ends up
201
+ * with no `/konoha` and an unresolvable agent name.
202
+ */
203
+ function checkClientCommandsAndConflicts(context) {
204
+ let commands = null;
205
+ try {
206
+ commands = require('../../src/client_commands').deployKonohaCommands({ home: HOME, statusOnly: true });
207
+ } catch (e) {
208
+ context.record('Slash Command (/konoha)', 'FAILED', `Error: ${e.message}`);
209
+ context.markError();
210
+ }
211
+
212
+ if (commands) {
213
+ const names = commands.deployed.filter((d) => d.scope === 'user').map((d) => d.client);
214
+ const unsupported = commands.skipped
215
+ .filter((s) => s.scope === 'user' && !/not present for this user/.test(s.reason))
216
+ .map((s) => `${s.client} (${s.reason})`);
217
+ if (names.length > 0) {
218
+ context.record('Slash Command (/konoha)', 'HEALTHY', `Installed for: ${names.join(', ')}`);
219
+ } else {
220
+ context.record('Slash Command (/konoha)', 'WARNING', 'No /konoha command file is installed — run `konoha init`');
221
+ }
222
+ if (unsupported.length > 0) {
223
+ context.record('Slash Command Coverage', 'WARNING', unsupported.join('; '));
224
+ }
225
+ }
226
+
227
+ let conflicts = [];
228
+ try {
229
+ conflicts = require('../../src/agent_file_safety').listAgentConflicts(HOME);
230
+ } catch (e) {
231
+ context.record('Agent Profile Conflicts', 'FAILED', `Error: ${e.message}`);
232
+ context.markError();
233
+ return;
234
+ }
235
+ const foreign = conflicts.filter((c) => c.kind === 'foreign');
236
+ const residue = conflicts.filter((c) => c.kind !== 'foreign');
237
+ if (foreign.length === 0) {
238
+ const detail = residue.length === 0
239
+ ? 'No parked agent profiles'
240
+ : `${residue.length} parked candidate(s) differ from Konoha's live profile; they are leftovers and can be removed`;
241
+ context.record('Agent Profile Conflicts', 'HEALTHY', detail);
242
+ return;
243
+ }
244
+ // Never auto-apply: the file in place is user-authored, so overwriting it
245
+ // would destroy user config. Report the exact resolution instead.
246
+ context.record(
247
+ 'Agent Profile Conflicts',
248
+ 'WARNING',
249
+ `${foreign.length} foreign profile(s) in effect; Konoha's version parked at ${foreign[0].proposed}`
250
+ );
251
+ }
252
+
197
253
  function inspectPromptHooksStatus() {
198
254
  const HOOKS_CONFIG_PATH = path.join(HOME, '.gemini', 'config', 'hooks.json');
199
255
  if (!fileExists(HOOKS_CONFIG_PATH)) return { promptOk: false, sanitizeOk: false };
@@ -484,6 +540,7 @@ module.exports = {
484
540
  checkDatabaseAndMigrations,
485
541
  checkEmbeddingHealth,
486
542
  checkGeminiAndAgentsConfig,
543
+ checkClientCommandsAndConflicts,
487
544
  checkPromptHookConfig,
488
545
  checkGovernanceAndServices,
489
546
  checkVpsPreflight
@@ -51,7 +51,7 @@ const { installUv } = require('../lib/extension');
51
51
  const { checkPortActive } = require('../lib/ui_commands');
52
52
  const { cmdBridgeStart } = require('./bridge');
53
53
  const { parseRequestedClients, setupClientIntegrations } = require('./init_clients');
54
- const { executeInitMigration, renderInitSummary, measureEmbeddingCoverage } = require('./init_migration');
54
+ const { executeInitMigration, renderInitSummary, measureEmbeddingCoverage, verifyRuntimeDeployment } = require('./init_migration');
55
55
  const { createEmbedProgress, INIT_PHASES } = require('../lib/embed_progress');
56
56
  const {
57
57
  executePreInstallBackup,
@@ -91,7 +91,12 @@ function recordAutoSetupState() {
91
91
  try {
92
92
  ensureDir(path.dirname(marker));
93
93
  fs.writeFileSync(marker, `${Date.now()}\n`);
94
- } catch { /* best-effort */ }
94
+ } catch (err) {
95
+ // Silent best-effort used to hide the one signal that explains a seed gate
96
+ // failing with exit status 0: the marker is a required seed sentinel, so a
97
+ // swallowed write makes CI report an incomplete seed with no cause.
98
+ log(` ! Could not write ${marker}: ${err && err.message ? err.message : err}`);
99
+ }
95
100
  }
96
101
 
97
102
  function checkNodeAndToolchains(options) {
@@ -218,7 +223,7 @@ function detectAllClientFlags(args) {
218
223
  const appendProject = Boolean(args.includes('--project'));
219
224
 
220
225
  return {
221
- explicitSelection: Array.isArray(requestedClients) && requestedClients.length > 0,
226
+ explicitSelection: requestedClients !== null,
222
227
  requestedClients,
223
228
  deployProject,
224
229
  appendProject,
@@ -291,9 +296,8 @@ async function migrateExistingInstallation(options = {}) {
291
296
  }
292
297
  }
293
298
 
294
- async function promptInitializationConsent(args) {
295
- const hasExplicitClient = Boolean(parseRequestedClients(args));
296
- const isNonInteractive = hasExplicitClient || args.includes('--yes') || args.includes('-y') || process.env.CI === 'true';
299
+ async function promptInitializationConsent(args, explicitSelection) {
300
+ const isNonInteractive = explicitSelection || args.includes('--yes') || args.includes('-y') || process.env.CI === 'true';
297
301
  if (isNonInteractive) return true;
298
302
  return await confirmPrompt('Initialize Konoha runtime and SQLite database (~/.konoha/)?', true);
299
303
  }
@@ -303,6 +307,18 @@ async function cmdInit(args, options = {}) {
303
307
  cmdInitHelp();
304
308
  return;
305
309
  }
310
+ // Validate an explicit client selection before anything has a side effect —
311
+ // before the `--force` cache purge, before the UI stop, before any write — so
312
+ // `--client=` or `--client=unknown` can never cause work before it fails.
313
+ let explicitSelection = false;
314
+ try {
315
+ explicitSelection = parseRequestedClients(args) !== null;
316
+ } catch (err) {
317
+ error(err.message);
318
+ process.exitCode = 1;
319
+ return;
320
+ }
321
+
306
322
  if (args.includes('--force')) {
307
323
  purgePackageCaches({ silent: true });
308
324
  try {
@@ -316,7 +332,7 @@ async function cmdInit(args, options = {}) {
316
332
  log(`${C.dim}MCP Tools Orchestrator for Antigravity, Cursor, Claude Code, OpenCode, Command Code, and Codex${C.reset}`);
317
333
  log(`${C.dim}Reduces token usage by 83-98% via on-demand skill search${C.reset}\n`);
318
334
 
319
- const doInit = await promptInitializationConsent(args);
335
+ const doInit = await promptInitializationConsent(args, explicitSelection);
320
336
  if (!doInit) {
321
337
  warn('Initialization aborted.');
322
338
  return;
@@ -421,6 +437,12 @@ async function cmdInit(args, options = {}) {
421
437
  : 'installation complete');
422
438
  }
423
439
 
440
+ // Write the marker and verify the deployment before the summary claims success:
441
+ // the banner reads its paths from constants, so it used to print "Server: <path>"
442
+ // for a server.js that a failed mirror swap had deleted.
443
+ recordAutoSetupState();
444
+ verifyRuntimeDeployment();
445
+
424
446
  const embedCoverage = skipEmbed ? null : measureEmbeddingCoverage();
425
447
  renderInitSummary({
426
448
  ...clientFlags,
@@ -433,7 +455,6 @@ async function cmdInit(args, options = {}) {
433
455
  if (args.includes('--with-red-team')) {
434
456
  await installCyberPackAfterInit();
435
457
  }
436
- recordAutoSetupState();
437
458
  }
438
459
 
439
460
  /**
@@ -21,16 +21,53 @@ function normalizeClientToken(token) {
21
21
  return clean;
22
22
  }
23
23
 
24
+ const KNOWN_CLIENTS = Object.freeze([
25
+ 'claude', 'cursor', 'opencode', 'commandcode', 'codex', 'omp', 'pi', 'antigravity', 'all'
26
+ ]);
27
+
28
+ const CLIENT_VALUE_REQUIRED = `--client requires a value: one of ${KNOWN_CLIENTS.join(', ')}`;
29
+
30
+ // An explicit `--client` is validated, never repaired. The previous parser
31
+ // filtered empty tokens out of the list, so `--client=` produced `[]`, which
32
+ // `explicitSelection` then read as "no flag" and widened to every client.
33
+ function parseClientList(raw) {
34
+ const value = String(raw == null ? '' : raw).trim();
35
+ if (!value) throw new Error(CLIENT_VALUE_REQUIRED);
36
+ const rawTokens = value.toLowerCase().split(',');
37
+ // An empty member (`cursor,,codex` or a trailing comma) is a malformed explicit
38
+ // list. Filtering it away would quietly repair a selection the user mistyped.
39
+ const emptyAt = rawTokens.findIndex((t) => !t.trim());
40
+ if (emptyAt !== -1) {
41
+ throw new Error(`--client has an empty entry at position ${emptyAt + 1}: "${value}"; list clients as cursor,codex`);
42
+ }
43
+ const tokens = rawTokens.map(normalizeClientToken);
44
+ for (const token of tokens) {
45
+ if (!KNOWN_CLIENTS.includes(token)) {
46
+ throw new Error(`unknown client "${token}"; expected one of ${KNOWN_CLIENTS.join(', ')}`);
47
+ }
48
+ }
49
+ // `all` is a whole selection, never a member of one: `cursor,all` must fail
50
+ // rather than silently widening the explicit list the user asked for.
51
+ if (tokens.includes('all') && tokens.length > 1) {
52
+ throw new Error(`"--client=all" cannot be combined with other clients: "${value}"; use all alone or name each client`);
53
+ }
54
+ return tokens;
55
+ }
56
+
57
+ /**
58
+ * @returns {string[]|null} null when no `--client`/`--clients` flag is present.
59
+ * @throws when the flag is present but its value is missing, empty, or unknown,
60
+ * so an explicit selection is never silently widened to every client.
61
+ */
24
62
  function parseRequestedClients(args) {
25
63
  const clientFlag = args.find(a => a.startsWith('--client=') || a.startsWith('--clients='));
26
- if (clientFlag) {
27
- const val = clientFlag.split('=')[1].toLowerCase();
28
- return val === 'all' ? ['all'] : val.split(',').map(normalizeClientToken).filter(Boolean);
29
- }
30
- const clientIdx = args.indexOf('--client');
31
- if (clientIdx !== -1 && args[clientIdx + 1]) {
32
- const val = args[clientIdx + 1].toLowerCase();
33
- return val === 'all' ? ['all'] : val.split(',').map(normalizeClientToken).filter(Boolean);
64
+ if (clientFlag) return parseClientList(clientFlag.split('=').slice(1).join('='));
65
+ for (const flag of ['--client', '--clients']) {
66
+ const idx = args.indexOf(flag);
67
+ if (idx === -1) continue;
68
+ const next = args[idx + 1];
69
+ if (next === undefined || next.startsWith('-')) throw new Error(CLIENT_VALUE_REQUIRED);
70
+ return parseClientList(next);
34
71
  }
35
72
  return null;
36
73
  }
@@ -166,6 +203,54 @@ function configureOmp(context) {
166
203
  else spinner.warn(`OMP setup skipped: ${ompSetup.reason || 'unknown error'}`);
167
204
  }
168
205
 
206
+ // Every client init can select, including the two that have no command file of
207
+ // their own. Keeping them here means `--client=pi` produces the list `['pi']`,
208
+ // which selects no target and reports pi as unsupported — rather than an empty
209
+ // list that would read as "no filter" and write every target.
210
+ const COMMAND_CLIENT_FLAGS = Object.freeze([
211
+ ['allowClaudeCode', 'claudecode'],
212
+ ['allowCursor', 'cursor'],
213
+ ['allowOpenCode', 'opencode'],
214
+ ['allowCommandCode', 'commandcode'],
215
+ ['allowCodex', 'codex'],
216
+ ['allowOmp', 'omp'],
217
+ ['allowPi', 'pi'],
218
+ ['allowAntigravity', 'antigravity']
219
+ ]);
220
+
221
+ function configureCommands(context) {
222
+ const { deployKonohaCommands } = require('../../src/client_commands');
223
+ header('⌘ Installing the /konoha slash command');
224
+ const spinner = startSpinner('Writing the prompt file into each configured client...');
225
+ // `--client=<x>` narrows the command layer the same way it narrows the
226
+ // per-client setup above; otherwise init would write files for clients the
227
+ // user did not ask for.
228
+ const clients = COMMAND_CLIENT_FLAGS
229
+ .filter(([flag]) => context[flag])
230
+ .map(([, client]) => client);
231
+ // An explicit `--client=pi` selects no command-capable client, so the empty
232
+ // list must stay empty. Only an absent `--client` means "every target".
233
+ let result;
234
+ try {
235
+ result = deployKonohaCommands({
236
+ home: context.home,
237
+ clients: context.explicitSelection ? clients : null,
238
+ projectRoot: context.deployProject ? context.currentCwd : null
239
+ });
240
+ } catch (err) {
241
+ // A command file is an extra; it must never abort the install. Reported,
242
+ // not swallowed.
243
+ spinner.warn(`/konoha was not installed: ${err.message}`);
244
+ return;
245
+ }
246
+ const names = result.deployed
247
+ .map((d) => (d.scope === 'project' ? `${d.client} (project)` : d.client))
248
+ .join(', ');
249
+ if (result.deployed.length > 0) spinner.success(`/konoha installed for: ${names}`);
250
+ else spinner.warn('No client received /konoha — none of the selected clients has a prompt directory Konoha can write to.');
251
+ for (const skip of result.skipped) info(` ${skip.client}: ${skip.reason}`);
252
+ }
253
+
169
254
  function setupClientIntegrations(options) {
170
255
  const { onProgress } = options;
171
256
  if (onProgress) onProgress(4, 'MCP Clients', 'Configuring requested AI coding clients');
@@ -177,9 +262,11 @@ function setupClientIntegrations(options) {
177
262
  configureCodex(options);
178
263
  configurePi(options);
179
264
  configureOmp(options);
265
+ configureCommands(options);
180
266
  }
181
267
 
182
268
  module.exports = {
269
+ KNOWN_CLIENTS,
183
270
  parseRequestedClients,
184
271
  setupClientIntegrations
185
272
  };
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const fs = require('fs');
3
4
  const path = require('path');
4
5
  const { fileExists } = require('../../src/platform_utils');
5
6
  const {
@@ -194,6 +195,35 @@ function buildClientStatusLines(flags) {
194
195
  ];
195
196
  }
196
197
 
198
+ /**
199
+ * Assert that init actually deployed what the summary is about to claim.
200
+ *
201
+ * The Windows golden seed failed for four runs because the success banner printed
202
+ * `Server: <path>` from a constant, never from the filesystem: a mirror swap had
203
+ * replaced server.js with a dangling link and init still exited 0. Read the paths
204
+ * back and throw with the exact missing file instead of reporting a healthy install.
205
+ */
206
+ function verifyRuntimeDeployment() {
207
+ const expected = [
208
+ ['MCP server', SERVER_PATH],
209
+ ['migration script', MIGRATE_PATH],
210
+ ['database', DB_PATH],
211
+ ['auto-setup marker', path.join(HOME, '.konoha', '.autosetup-done')],
212
+ ['Konoha skill', path.join(HOME, '.agents', 'skills', 'konoha', 'SKILL.md')]
213
+ ];
214
+ const failures = [];
215
+ for (const [label, target] of expected) {
216
+ try {
217
+ fs.readFileSync(target);
218
+ } catch (err) {
219
+ failures.push(`${label} missing or unreadable: ${target} (${err && err.code ? err.code : err})`);
220
+ }
221
+ }
222
+ if (failures.length > 0) {
223
+ throw new Error(`[INIT] Runtime deployment incomplete:\n ${failures.join('\n ')}`);
224
+ }
225
+ }
226
+
197
227
  function renderInitSummary(flags) {
198
228
  const summaryLines = [
199
229
  `${C.bold}Konoha MCP Orchestrator installed successfully!${C.reset}`,
@@ -237,5 +267,6 @@ function renderInitSummary(flags) {
237
267
  module.exports = {
238
268
  executeInitMigration,
239
269
  measureEmbeddingCoverage,
240
- renderInitSummary
270
+ renderInitSummary,
271
+ verifyRuntimeDeployment
241
272
  };
@@ -63,6 +63,8 @@ const CONFIG_DEFAULTS = Object.freeze({
63
63
  semantic_top_k: 10,
64
64
  doc_gate_max_attempts: 3,
65
65
  bridge_max_tool_output_chars: 24000,
66
+ // providers whose contract defines stream_options.include_usage
67
+ bridge_stream_usage_providers: 'openai,openai-compatible,9router',
66
68
  qa_retention_count: 20,
67
69
  // sessions / web auth
68
70
  session_ttl_ms: 43200000,
@@ -148,6 +150,7 @@ const ENV_ALIASES = Object.freeze({
148
150
  spinners: ['KONOHA_SPINNERS'],
149
151
  offline_search: ['KONOHA_OFFLINE_SEARCH'],
150
152
  migrate_time_budget_seconds: ['KONOHA_MIGRATE_TIME_BUDGET'],
153
+ bridge_stream_usage_providers: ['KONOHA_BRIDGE_STREAM_USAGE_PROVIDERS'],
151
154
  // sessions / web auth
152
155
  session_ttl_ms: ['KONOHA_SESSION_TTL_MS'],
153
156
  web_token_ttl_ms: ['KONOHA_WEB_TOKEN_TTL_MS'],