konoha-mcp 2.2.23 → 2.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +38 -0
- package/README.md +3 -3
- package/apps/web/build/adapter-node.js +1 -1
- package/apps/web/build/build-meta.json +2 -2
- package/apps/web/build/client/_app/immutable/entry/{app.TYH87iYy.js → app.CKJ0NhrX.js} +2 -2
- package/apps/web/build/client/_app/immutable/entry/app.CKJ0NhrX.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.CKJ0NhrX.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{0.D7dPIEWA.js → 0.7A6fQJ6z.js} +1 -1
- package/apps/web/build/client/_app/immutable/nodes/0.7A6fQJ6z.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{0.D7dPIEWA.js.gz → 0.7A6fQJ6z.js.gz} +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{13.TOXVaTBr.js → 13.CQB_Ed6W.js} +1 -1
- package/apps/web/build/client/_app/immutable/nodes/13.CQB_Ed6W.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{13.TOXVaTBr.js.gz → 13.CQB_Ed6W.js.gz} +0 -0
- package/apps/web/build/client/_app/version.json +1 -1
- package/apps/web/build/client/_app/version.json.br +0 -0
- package/apps/web/build/client/_app/version.json.gz +0 -0
- package/apps/web/build/server/chunks/instance.js +3 -3
- package/apps/web/build/server/chunks/internal.js +1 -1
- package/apps/web/build/server/entries/pages/_layout.svelte.js +1 -1
- package/apps/web/build/server/entries/pages/_layout.svelte.js.map +1 -1
- package/apps/web/build/server/entries/pages/docs/_page.svelte.js +1 -1
- package/apps/web/build/server/entries/pages/docs/_page.svelte.js.map +1 -1
- package/apps/web/build/server/manifest-full.js +1 -1
- package/apps/web/build/server/manifest.js +1 -1
- package/apps/web/build/server/nodes/0.js +1 -1
- package/apps/web/build/server/nodes/13.js +1 -1
- package/apps/web/build/server/server.js +1 -1
- package/apps/web/package.json +1 -1
- package/bin/commands/bridge.js +62 -4
- package/bin/commands/doctor.js +2 -0
- package/bin/commands/doctor_services.js +57 -0
- package/bin/commands/init.js +16 -5
- package/bin/commands/init_clients.js +95 -8
- package/bin/lib/config_defaults.js +3 -0
- package/bin/lib/runtime_install.js +141 -54
- package/package.json +2 -1
- package/patches/gpt-tokenizer@4.1.0.patch +15 -0
- package/src/agent_contract.js +1 -1
- package/src/agent_deployer.js +48 -35
- package/src/agent_file_safety.js +57 -0
- package/src/bridge/gateway.js +2 -0
- package/src/bridge/gateway_adapters.js +155 -29
- package/src/bridge/handlers/anthropic.js +95 -26
- package/src/bridge/handlers/openai.js +18 -5
- package/src/bridge/sidecar/raw.js +10 -2
- package/src/bridge/stream_usage.js +66 -0
- package/src/client_commands.js +190 -0
- package/src/db_bridges.js +53 -7
- package/src/db_schema.js +11 -2
- package/src/file_tools_mcp.js +17 -9
- package/src/global_skill_sync.js +3 -1
- package/src/mcp/langgraph/edges/router.js +3 -0
- package/src/mcp/langgraph/index.js +22 -3
- package/src/mcp/langgraph/nodes/dispatch.js +3 -0
- package/src/mcp/langgraph/nodes/execute.js +87 -13
- package/src/mcp/langgraph/nodes/review.js +13 -1
- package/src/mcp/langgraph/slice_executor_registry.js +22 -0
- package/src/mcp/langgraph/state.js +5 -0
- package/src/mcp/lazy_subagent.js +11 -1
- package/src/mcp/memory_project_context.js +4 -1
- package/src/mcp/memory_subagent_runner.js +2 -1
- package/src/mcp/skills_common.js +1 -0
- package/src/mcp/subagent_spawner.js +7 -0
- package/src/mcp/todo_walkthrough_sync.js +7 -0
- package/src/mcp/tool_dispatch.js +16 -0
- package/src/mcp/workflow_completion_helpers.js +6 -1
- package/src/mcp/workflow_gates.js +118 -5
- package/src/mcp/workflow_sannin.js +9 -3
- package/src/mcp_tool_manifest.json +5 -1
- package/src/provider_usage_logger.js +92 -0
- package/src/schema_ddl.js +17 -1
- package/src/templates/AGENTS.md +1 -1
- package/src/templates/GEMINI.md +1 -1
- package/src/templates/skills/kage-skill/SKILL.md +1 -1
- package/src/templates/skills/konoha/SKILL.md +23 -165
- package/src/templates/skills/konoha/references/contract.md +1 -1
- package/src/templates/skills/konoha/references/peragent-usage.md +1 -1
- package/src/token_usage.js +57 -0
- package/src/tools_savings_logger.js +26 -8
- package/src/web/controllers/core_controller.js +10 -1
- package/src/workflow/jonin-builder/live_browser_monitor.js +23 -7
- package/apps/web/build/client/_app/immutable/entry/app.TYH87iYy.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.TYH87iYy.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.D7dPIEWA.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.TOXVaTBr.js.br +0 -0
- package/src/templates/skills/konoha/references/architecture.md +0 -99
- package/src/templates/skills/konoha/references/benchmark.md +0 -123
- package/src/templates/skills/konoha/references/docs.md +0 -46
- package/src/templates/skills/konoha/references/test.md +0 -71
- package/src/templates/skills/konoha/references/workflow.md +0 -104
package/bin/commands/bridge.js
CHANGED
|
@@ -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,
|
package/bin/commands/doctor.js
CHANGED
|
@@ -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
|
package/bin/commands/init.js
CHANGED
|
@@ -218,7 +218,7 @@ function detectAllClientFlags(args) {
|
|
|
218
218
|
const appendProject = Boolean(args.includes('--project'));
|
|
219
219
|
|
|
220
220
|
return {
|
|
221
|
-
explicitSelection:
|
|
221
|
+
explicitSelection: requestedClients !== null,
|
|
222
222
|
requestedClients,
|
|
223
223
|
deployProject,
|
|
224
224
|
appendProject,
|
|
@@ -291,9 +291,8 @@ async function migrateExistingInstallation(options = {}) {
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
async function promptInitializationConsent(args) {
|
|
295
|
-
const
|
|
296
|
-
const isNonInteractive = hasExplicitClient || args.includes('--yes') || args.includes('-y') || process.env.CI === 'true';
|
|
294
|
+
async function promptInitializationConsent(args, explicitSelection) {
|
|
295
|
+
const isNonInteractive = explicitSelection || args.includes('--yes') || args.includes('-y') || process.env.CI === 'true';
|
|
297
296
|
if (isNonInteractive) return true;
|
|
298
297
|
return await confirmPrompt('Initialize Konoha runtime and SQLite database (~/.konoha/)?', true);
|
|
299
298
|
}
|
|
@@ -303,6 +302,18 @@ async function cmdInit(args, options = {}) {
|
|
|
303
302
|
cmdInitHelp();
|
|
304
303
|
return;
|
|
305
304
|
}
|
|
305
|
+
// Validate an explicit client selection before anything has a side effect —
|
|
306
|
+
// before the `--force` cache purge, before the UI stop, before any write — so
|
|
307
|
+
// `--client=` or `--client=unknown` can never cause work before it fails.
|
|
308
|
+
let explicitSelection = false;
|
|
309
|
+
try {
|
|
310
|
+
explicitSelection = parseRequestedClients(args) !== null;
|
|
311
|
+
} catch (err) {
|
|
312
|
+
error(err.message);
|
|
313
|
+
process.exitCode = 1;
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
|
|
306
317
|
if (args.includes('--force')) {
|
|
307
318
|
purgePackageCaches({ silent: true });
|
|
308
319
|
try {
|
|
@@ -316,7 +327,7 @@ async function cmdInit(args, options = {}) {
|
|
|
316
327
|
log(`${C.dim}MCP Tools Orchestrator for Antigravity, Cursor, Claude Code, OpenCode, Command Code, and Codex${C.reset}`);
|
|
317
328
|
log(`${C.dim}Reduces token usage by 83-98% via on-demand skill search${C.reset}\n`);
|
|
318
329
|
|
|
319
|
-
const doInit = await promptInitializationConsent(args);
|
|
330
|
+
const doInit = await promptInitializationConsent(args, explicitSelection);
|
|
320
331
|
if (!doInit) {
|
|
321
332
|
warn('Initialization aborted.');
|
|
322
333
|
return;
|
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
};
|
|
@@ -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'],
|
|
@@ -283,71 +283,138 @@ function copyRuntimeFiles(copyTree, sourceRoot = REPO_ROOT) {
|
|
|
283
283
|
return cliDest;
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
// A build is only usable if its own metadata says what it is. `handler.js` proves the
|
|
287
|
+
// tree was built, not which source produced it, and the destination package.json is
|
|
288
|
+
// copied from the source manifest — neither is provenance.
|
|
289
|
+
function readBuildMeta(dir) {
|
|
290
|
+
const metaPath = path.join(dir, 'build-meta.json');
|
|
291
|
+
if (!fileExists(metaPath)) return { ok: false, reason: 'missing build-meta.json' };
|
|
292
|
+
let raw;
|
|
289
293
|
try {
|
|
290
|
-
|
|
291
|
-
} catch {
|
|
292
|
-
return
|
|
294
|
+
raw = JSON.parse(fs.readFileSync(metaPath, 'utf8'));
|
|
295
|
+
} catch (err) {
|
|
296
|
+
return { ok: false, reason: `unreadable build-meta.json (${err.message})` };
|
|
293
297
|
}
|
|
298
|
+
const version = raw && typeof raw.version === 'string' ? raw.version.trim() : '';
|
|
299
|
+
if (!version) return { ok: false, reason: 'build-meta.json has no string version' };
|
|
300
|
+
return { ok: true, version, builtAt: typeof raw.builtAt === 'string' ? raw.builtAt : null };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function readBuildVersion(dir) {
|
|
304
|
+
const meta = readBuildMeta(dir);
|
|
305
|
+
return meta.ok ? meta.version : null;
|
|
294
306
|
}
|
|
295
307
|
|
|
296
|
-
function
|
|
297
|
-
|
|
308
|
+
function defaultWebBuildCandidates(sourceRoot) {
|
|
309
|
+
return [
|
|
298
310
|
path.join(sourceRoot, 'apps', 'web', 'build'),
|
|
299
311
|
path.resolve(__dirname, '..', '..', 'apps', 'web', 'build'),
|
|
300
312
|
path.join(process.cwd(), 'apps', 'web', 'build'),
|
|
301
313
|
path.join(process.cwd(), 'build')
|
|
302
314
|
];
|
|
303
|
-
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function resolveWebBuildSource(sourceRoot = REPO_ROOT, currentVersion = null, candidates = defaultWebBuildCandidates(sourceRoot)) {
|
|
318
|
+
const rejected = [];
|
|
304
319
|
for (const cand of candidates) {
|
|
305
|
-
if (!fileExists(path.join(cand, 'handler.js')))
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
320
|
+
if (!fileExists(path.join(cand, 'handler.js'))) {
|
|
321
|
+
rejected.push(`${cand}: no handler.js`);
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const meta = readBuildMeta(cand);
|
|
325
|
+
if (!meta.ok) {
|
|
326
|
+
warn(`Skipping unverified Web UI build at ${cand}: ${meta.reason}`);
|
|
327
|
+
rejected.push(`${cand}: ${meta.reason}`);
|
|
309
328
|
continue;
|
|
310
329
|
}
|
|
311
|
-
|
|
330
|
+
if (currentVersion && meta.version !== currentVersion) {
|
|
331
|
+
warn(`Skipping stale Web UI build ${meta.version} at ${cand} (installing ${currentVersion})`);
|
|
332
|
+
rejected.push(`${cand}: stale ${meta.version}`);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (rejected.length > 0) {
|
|
336
|
+
warn(`Web UI build accepted: ${cand} (v${meta.version}), ${rejected.length} candidate(s) rejected`);
|
|
337
|
+
}
|
|
338
|
+
return cand;
|
|
312
339
|
}
|
|
313
|
-
// Every candidate was stale. Returning
|
|
314
|
-
// very artifact we just rejected, so signal "no usable source" and let the
|
|
315
|
-
//
|
|
316
|
-
|
|
340
|
+
// Every candidate was unverified or stale. Returning a default path here would copy
|
|
341
|
+
// the very artifact we just rejected, so signal "no usable source" and let the caller
|
|
342
|
+
// fall back to an on-demand build.
|
|
343
|
+
warn(`No verified Web UI build found among ${candidates.length} candidate(s): ${rejected.join('; ')}`);
|
|
344
|
+
return null;
|
|
317
345
|
}
|
|
318
346
|
|
|
319
347
|
function _syncWebBuildOutput(builtOutput, webBuildDest, destWebPkg, currentVersion) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (process.platform === 'win32') {
|
|
324
|
-
warn(`Web UI destination cleanup note (${rmErr.message}); proceeding with in-place synchronization.`);
|
|
325
|
-
}
|
|
348
|
+
const srcMeta = readBuildMeta(builtOutput);
|
|
349
|
+
if (!srcMeta.ok) {
|
|
350
|
+
return { ok: false, reason: `source ${builtOutput} has no usable provenance: ${srcMeta.reason}` };
|
|
326
351
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
fs.cpSync(builtOutput, webBuildDest, { recursive: true, force: true });
|
|
330
|
-
} catch (cpErr) {
|
|
331
|
-
warn(`Web UI assets sync note: ${cpErr.message}`);
|
|
352
|
+
if (currentVersion && srcMeta.version !== currentVersion) {
|
|
353
|
+
return { ok: false, reason: `source declares v${srcMeta.version}, expected v${currentVersion}` };
|
|
332
354
|
}
|
|
333
|
-
fs.writeFileSync(destWebPkg, JSON.stringify({ name: 'konoha-web', version: currentVersion, type: 'module', private: true }, null, 2) + '\n');
|
|
334
|
-
fs.writeFileSync(path.join(webBuildDest, 'package.json'), '{\n "type": "module"\n}\n');
|
|
335
355
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
356
|
+
const sameDir = path.resolve(builtOutput) === path.resolve(webBuildDest);
|
|
357
|
+
if (!sameDir) {
|
|
358
|
+
try {
|
|
359
|
+
fs.rmSync(webBuildDest, { recursive: true, force: true, maxRetries: 3 });
|
|
360
|
+
} catch (rmErr) {
|
|
361
|
+
if (process.platform === 'win32') {
|
|
362
|
+
warn(`Web UI destination cleanup note (${rmErr.message}); proceeding with in-place synchronization.`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
ensureDir(webBuildDest);
|
|
366
|
+
try {
|
|
367
|
+
fs.cpSync(builtOutput, webBuildDest, { recursive: true, force: true });
|
|
368
|
+
} catch (cpErr) {
|
|
369
|
+
warn(`Web UI assets sync note: ${cpErr.message}`);
|
|
370
|
+
}
|
|
371
|
+
fs.writeFileSync(
|
|
372
|
+
destWebPkg,
|
|
373
|
+
JSON.stringify({ name: 'konoha-web', version: srcMeta.version, type: 'module', private: true }, null, 2) + '\n'
|
|
374
|
+
);
|
|
375
|
+
fs.writeFileSync(path.join(webBuildDest, 'package.json'), '{\n "type": "module"\n}\n');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// The copy is only trusted once the destination's own metadata agrees with the
|
|
379
|
+
// source's. A failed verification removes the unverified tree: absence is a state
|
|
380
|
+
// the server reports, a garbage build is one it serves.
|
|
381
|
+
const destMeta = readBuildMeta(webBuildDest);
|
|
382
|
+
if (!destMeta.ok || destMeta.version !== srcMeta.version) {
|
|
383
|
+
const reason = destMeta.ok
|
|
384
|
+
? `destination declares v${destMeta.version}, source v${srcMeta.version}`
|
|
385
|
+
: destMeta.reason;
|
|
386
|
+
if (!sameDir) {
|
|
387
|
+
try {
|
|
388
|
+
fs.rmSync(webBuildDest, { recursive: true, force: true, maxRetries: 3 });
|
|
389
|
+
} catch { /* best-effort removal of an unverified tree */ }
|
|
390
|
+
}
|
|
391
|
+
warn(`ERROR: Web UI provenance verification failed at ${webBuildDest}: ${reason}; the unverified build was removed`);
|
|
392
|
+
return { ok: false, reason };
|
|
344
393
|
}
|
|
345
|
-
|
|
394
|
+
|
|
395
|
+
info(`Pre-built Web UI installed to ${webBuildDest} (v${destMeta.version} verified)`);
|
|
396
|
+
return { ok: true, version: destMeta.version };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function shouldBuildWebUiOnDemand(webBuildDest, currentVersion) {
|
|
400
|
+
if (!fileExists(path.join(webBuildDest, 'handler.js'))) return { needed: true, reason: 'no-handler' };
|
|
401
|
+
const meta = readBuildMeta(webBuildDest);
|
|
402
|
+
if (!meta.ok) {
|
|
403
|
+
const slug = meta.reason.startsWith('missing ')
|
|
404
|
+
? 'missing'
|
|
405
|
+
: meta.reason.startsWith('unreadable ') ? 'invalid' : 'no-version';
|
|
406
|
+
return { needed: true, reason: `provenance-${slug}` };
|
|
407
|
+
}
|
|
408
|
+
if (currentVersion && meta.version !== currentVersion) return { needed: true, reason: 'stale' };
|
|
409
|
+
return { needed: false, reason: 'verified' };
|
|
346
410
|
}
|
|
347
411
|
|
|
348
412
|
function buildWebUiOnDemand(webBuildDest, destWebPkg, currentVersion) {
|
|
349
413
|
const sourceDir = deployUtils.resolveWebUiDir({ preferSources: true });
|
|
350
|
-
if (!sourceDir || !fileExists(path.join(sourceDir, 'src', 'routes')))
|
|
414
|
+
if (!sourceDir || !fileExists(path.join(sourceDir, 'src', 'routes'))) {
|
|
415
|
+
warn('No Web UI source found; cannot build on demand');
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
351
418
|
try {
|
|
352
419
|
const { execSync } = require('child_process');
|
|
353
420
|
info(`Building Web UI v${currentVersion} during runtime initialization...`);
|
|
@@ -357,11 +424,17 @@ function buildWebUiOnDemand(webBuildDest, destWebPkg, currentVersion) {
|
|
|
357
424
|
execSync('npm run build', { cwd: sourceDir, stdio: 'ignore', timeout: INSTALL_BUILD_MIGRATE_TIMEOUT_MS });
|
|
358
425
|
}
|
|
359
426
|
const builtOutput = path.join(sourceDir, 'build');
|
|
360
|
-
|
|
361
|
-
|
|
427
|
+
const builtMeta = readBuildMeta(builtOutput);
|
|
428
|
+
if (!fileExists(path.join(builtOutput, 'handler.js')) || !builtMeta.ok || builtMeta.version !== currentVersion) {
|
|
429
|
+
const why = builtMeta.ok ? `declares v${builtMeta.version}, expected v${currentVersion}` : builtMeta.reason;
|
|
430
|
+
warn(`ERROR: on-demand Web UI build produced no verifiable metadata at ${builtOutput} (${why}); run \`pnpm run build:web\``);
|
|
431
|
+
return false;
|
|
362
432
|
}
|
|
433
|
+
if (path.resolve(builtOutput) === path.resolve(webBuildDest)) return true;
|
|
434
|
+
return _syncWebBuildOutput(builtOutput, webBuildDest, destWebPkg, currentVersion).ok;
|
|
363
435
|
} catch (buildErr) {
|
|
364
436
|
warn(`Could not build Web UI automatically: ${buildErr.message}`);
|
|
437
|
+
return false;
|
|
365
438
|
}
|
|
366
439
|
}
|
|
367
440
|
|
|
@@ -377,23 +450,34 @@ function installWebUiRuntime(copyTree, sourceRoot = REPO_ROOT) {
|
|
|
377
450
|
}
|
|
378
451
|
|
|
379
452
|
const currentVersion = readPackageVersionSafe(path.join(sourceRoot, 'package.json')) || getCliVersion();
|
|
380
|
-
const webBuildSrc = resolveWebBuildSource(sourceRoot, currentVersion);
|
|
381
453
|
const webBuildDest = path.join(SKILLS_DB_DIR, 'apps', 'web', 'build');
|
|
382
454
|
const destWebPkg = path.join(webDestDir, 'package.json');
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (fileExists(destWebPkg)) destVersion = JSON.parse(fs.readFileSync(destWebPkg, 'utf8')).version;
|
|
386
|
-
} catch (_) { /* best-effort */ }
|
|
387
|
-
const isUiOutdated = !destVersion || destVersion !== currentVersion;
|
|
455
|
+
const destState = shouldBuildWebUiOnDemand(webBuildDest, currentVersion);
|
|
456
|
+
const webBuildSrc = resolveWebBuildSource(sourceRoot, currentVersion);
|
|
388
457
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
458
|
+
let synced = false;
|
|
459
|
+
if (webBuildSrc) {
|
|
460
|
+
if (path.resolve(webBuildSrc) !== path.resolve(webBuildDest) || !destState.needed) {
|
|
461
|
+
const result = _syncWebBuildOutput(webBuildSrc, webBuildDest, destWebPkg, currentVersion);
|
|
462
|
+
synced = result.ok;
|
|
463
|
+
if (!result.ok) warn(`Web UI sync rejected: ${result.reason}`);
|
|
392
464
|
}
|
|
393
|
-
}
|
|
394
|
-
|
|
465
|
+
}
|
|
466
|
+
if (!synced && (destState.needed || !webBuildSrc)) {
|
|
467
|
+
if (!webBuildSrc && destState.needed) warn(`No Web UI build matches the installed version (${destState.reason}); building on demand.`);
|
|
395
468
|
buildWebUiOnDemand(webBuildDest, destWebPkg, currentVersion);
|
|
396
469
|
}
|
|
470
|
+
|
|
471
|
+
// The only place a version may be claimed: the metadata of the tree that will be served.
|
|
472
|
+
const finalMeta = readBuildMeta(webBuildDest);
|
|
473
|
+
if (finalMeta.ok && finalMeta.version === currentVersion && fileExists(path.join(webBuildDest, 'handler.js'))) {
|
|
474
|
+
info(`Web UI v${finalMeta.version} verified at ${webBuildDest}`);
|
|
475
|
+
} else {
|
|
476
|
+
warn(
|
|
477
|
+
`ERROR: Web UI at ${webBuildDest} is unverified (${finalMeta.ok ? `v${finalMeta.version}` : finalMeta.reason}); ` +
|
|
478
|
+
`reported version ${currentVersion} is not claimed. Run \`pnpm run build:web\` and re-run \`konoha init\`.`
|
|
479
|
+
);
|
|
480
|
+
}
|
|
397
481
|
}
|
|
398
482
|
|
|
399
483
|
function installMissingDependencies(deps) {
|
|
@@ -598,6 +682,9 @@ module.exports = {
|
|
|
598
682
|
installCliRuntime,
|
|
599
683
|
reconcileGlobalCommand,
|
|
600
684
|
resolveWebBuildSource,
|
|
685
|
+
readBuildMeta,
|
|
601
686
|
readBuildVersion,
|
|
687
|
+
_syncWebBuildOutput,
|
|
688
|
+
shouldBuildWebUiOnDemand,
|
|
602
689
|
installWebUiRuntime
|
|
603
690
|
};
|