konoha-mcp 2.1.16 → 2.1.17
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/.agents/SOUL.md +1 -1
- package/.agents/skills/konoha/SKILL.md +30 -1
- package/.agents/skills.fingerprint +1 -1
- package/README.md +186 -219
- package/apps/web/build/adapter-node.js +1 -1
- package/apps/web/build/client/_app/immutable/assets/0.BGEsEaMd.css +2 -0
- package/apps/web/build/client/_app/immutable/assets/0.BGEsEaMd.css.br +0 -0
- package/apps/web/build/client/_app/immutable/assets/0.BGEsEaMd.css.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{D-Kujhko.js → 2WlqNq2Q.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/2WlqNq2Q.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/2WlqNq2Q.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/B9vY64pH.js +1 -0
- package/apps/web/build/client/_app/immutable/chunks/B9vY64pH.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/B9vY64pH.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{Dzm74gVd.js → BPX4jQ9l.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/BPX4jQ9l.js.br +2 -0
- package/apps/web/build/client/_app/immutable/chunks/BPX4jQ9l.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{fbrtLByB.js → BXssplIZ.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/BXssplIZ.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/BXssplIZ.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/C-3vSv0T.js +1 -0
- package/apps/web/build/client/_app/immutable/chunks/C-3vSv0T.js.br +2 -0
- package/apps/web/build/client/_app/immutable/chunks/C-3vSv0T.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{PrdhfbrQ.js → C7jhkUmC.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/C7jhkUmC.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{PrdhfbrQ.js.gz → C7jhkUmC.js.gz} +0 -0
- package/apps/web/build/client/_app/immutable/chunks/{7LmsTWIo.js → CfrhQlXt.js} +1 -1
- package/apps/web/build/client/_app/immutable/chunks/CfrhQlXt.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/CfrhQlXt.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/CgzsRqh3.js +1 -0
- package/apps/web/build/client/_app/immutable/chunks/CgzsRqh3.js.br +1 -0
- package/apps/web/build/client/_app/immutable/chunks/CgzsRqh3.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/ChmznE4L.js +2 -0
- package/apps/web/build/client/_app/immutable/chunks/ChmznE4L.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/ChmznE4L.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.cdLMQHsN.js +2 -0
- package/apps/web/build/client/_app/immutable/entry/app.cdLMQHsN.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.cdLMQHsN.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/entry/{start.CNV5BTCO.js → start.CJ1ccVCA.js} +2 -2
- package/apps/web/build/client/_app/immutable/entry/start.CJ1ccVCA.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/start.CJ1ccVCA.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.ijG9ltjt.js +2 -0
- package/apps/web/build/client/_app/immutable/nodes/0.ijG9ltjt.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.ijG9ltjt.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/1.i6MXc2Yb.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/1.i6MXc2Yb.js.br +2 -0
- package/apps/web/build/client/_app/immutable/nodes/1.i6MXc2Yb.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/10.B0F7UoZ4.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/10.B0F7UoZ4.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/10.B0F7UoZ4.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{11.4dBWH00t.js → 11.BuH1S-Sa.js} +2 -2
- package/apps/web/build/client/_app/immutable/nodes/11.BuH1S-Sa.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/11.BuH1S-Sa.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/12.DVFmb_G-.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/12.DVFmb_G-.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/12.DVFmb_G-.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.0PJQyjqs.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/13.0PJQyjqs.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.0PJQyjqs.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/14.ljEGDzwO.js +3 -0
- package/apps/web/build/client/_app/immutable/nodes/14.ljEGDzwO.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/14.ljEGDzwO.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/15.DpXDNTPX.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/15.DpXDNTPX.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/15.DpXDNTPX.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/16.qIEBxyps.js +17 -0
- package/apps/web/build/client/_app/immutable/nodes/16.qIEBxyps.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/16.qIEBxyps.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/17.CmVvQa7x.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/17.CmVvQa7x.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/17.CmVvQa7x.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{2.Dr646Vs5.js → 2.lx602Ou_.js} +1 -1
- package/apps/web/build/client/_app/immutable/nodes/2.lx602Ou_.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/2.lx602Ou_.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/3.B-axtlUy.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/3.B-axtlUy.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/3.B-axtlUy.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/4.Cp9WmMgk.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/4.Cp9WmMgk.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/4.Cp9WmMgk.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/5.CQxJe2vk.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/5.CQxJe2vk.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/5.CQxJe2vk.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/6.5S6pozqG.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/6.5S6pozqG.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/6.5S6pozqG.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/{7.CmbiPMU3.js → 7.B5ZeCLvS.js} +1 -1
- package/apps/web/build/client/_app/immutable/nodes/7.B5ZeCLvS.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/7.B5ZeCLvS.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/8.M3fxLxa9.js +1 -0
- package/apps/web/build/client/_app/immutable/nodes/8.M3fxLxa9.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/8.M3fxLxa9.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CYkQmFMJ.js +21 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CYkQmFMJ.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CYkQmFMJ.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/.vite/manifest.json +15 -1
- package/apps/web/build/server/_app/immutable/assets/_layout.BGEsEaMd.css +2 -0
- package/apps/web/build/server/chunks/api.js +4 -0
- package/apps/web/build/server/chunks/api.js.map +1 -1
- 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 +7 -0
- package/apps/web/build/server/entries/pages/_layout.svelte.js.map +1 -1
- package/apps/web/build/server/entries/pages/agents/_page.svelte.js +6 -2
- package/apps/web/build/server/entries/pages/agents/_page.svelte.js.map +1 -1
- package/apps/web/build/server/entries/pages/docs/_page.svelte.js +86 -2
- package/apps/web/build/server/entries/pages/docs/_page.svelte.js.map +1 -1
- package/apps/web/build/server/entries/pages/remote/_page.svelte.js +73 -0
- package/apps/web/build/server/entries/pages/remote/_page.svelte.js.map +1 -0
- package/apps/web/build/server/manifest-full.js +15 -7
- package/apps/web/build/server/manifest.js +15 -7
- package/apps/web/build/server/nodes/0.js +2 -2
- package/apps/web/build/server/nodes/1.js +1 -1
- package/apps/web/build/server/nodes/10.js +1 -1
- package/apps/web/build/server/nodes/11.js +1 -1
- package/apps/web/build/server/nodes/12.js +2 -2
- package/apps/web/build/server/nodes/13.js +2 -2
- package/apps/web/build/server/nodes/14.js +2 -2
- package/apps/web/build/server/nodes/15.js +2 -2
- package/apps/web/build/server/nodes/16.js +2 -2
- package/apps/web/build/server/nodes/17.js +8 -0
- package/apps/web/build/server/nodes/2.js +1 -1
- package/apps/web/build/server/nodes/3.js +1 -1
- package/apps/web/build/server/nodes/4.js +1 -1
- package/apps/web/build/server/nodes/5.js +1 -1
- package/apps/web/build/server/nodes/6.js +1 -1
- package/apps/web/build/server/nodes/7.js +1 -1
- package/apps/web/build/server/nodes/8.js +1 -1
- package/apps/web/build/server/nodes/9.js +1 -1
- package/apps/web/build/server/server.js +15 -7
- package/apps/web/package.json +1 -1
- package/bin/cli.js +397 -33
- package/docs/ALL-WORKFLOW-DIAGRAMS.md +135 -0
- package/docs/ARCHITECTURE.md +23 -1
- package/docs/BENCHMARK.md +53 -33
- package/docs/CLOUDFLARE_TUNNEL_GUIDE.md +119 -0
- package/docs/SecurityCompliance/security_compliance_report_google_policy_2.1.17_2026-10-08.md +87 -0
- package/docs/TELEGRAM_INTEGRATION_GUIDE.md +146 -0
- package/docs/diagrams/README.md +6 -2
- package/docs/diagrams/konoha-architecture.drawio +121 -0
- package/docs/diagrams/konoha-enterprise-architecture.drawio +121 -0
- package/package.json +1 -1
- package/src/agent_manager.js +75 -8
- package/src/crypto_vault.js +157 -0
- package/src/db.js +186 -65
- package/src/db_agents.js +1 -1
- package/src/mcp/memory_reporting.js +19 -0
- package/src/mcp/skills.js +17 -15
- package/src/mcp/workflow.js +38 -0
- package/src/migrate.js +74 -6
- package/src/persona_memory.js +1 -1
- package/src/prompt_hook.js +40 -1
- package/src/queue/inbox.js +243 -0
- package/src/queue/worker.js +413 -0
- package/src/telegram/config.js +101 -0
- package/src/telegram/notifier.js +359 -0
- package/src/telegram/poller.js +548 -0
- package/src/telegram/session_manager.js +583 -0
- package/src/templates/SOUL.md +1 -1
- package/src/templates/skills/konoha/SKILL.md +30 -1
- package/src/tunnel/config.js +89 -0
- package/src/tunnel/manager.js +216 -0
- package/src/tunnel/security.js +225 -0
- package/src/vector_search.js +21 -11
- package/src/web_server.js +358 -10
- package/apps/web/build/client/_app/immutable/assets/0.Ch0v37a-.css +0 -2
- package/apps/web/build/client/_app/immutable/assets/0.Ch0v37a-.css.br +0 -0
- package/apps/web/build/client/_app/immutable/assets/0.Ch0v37a-.css.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/7LmsTWIo.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/7LmsTWIo.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/BH86Md_X.js +0 -1
- package/apps/web/build/client/_app/immutable/chunks/BH86Md_X.js.br +0 -2
- package/apps/web/build/client/_app/immutable/chunks/BH86Md_X.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/C3-t9btS.js +0 -1
- package/apps/web/build/client/_app/immutable/chunks/C3-t9btS.js.br +0 -1
- package/apps/web/build/client/_app/immutable/chunks/C3-t9btS.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/CBY268r4.js +0 -1
- package/apps/web/build/client/_app/immutable/chunks/CBY268r4.js.br +0 -3
- package/apps/web/build/client/_app/immutable/chunks/CBY268r4.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/D-Kujhko.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/D-Kujhko.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/Dzm74gVd.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/Dzm74gVd.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/Lb3VuXoN.js +0 -2
- package/apps/web/build/client/_app/immutable/chunks/Lb3VuXoN.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/Lb3VuXoN.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/chunks/PrdhfbrQ.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/fbrtLByB.js.br +0 -0
- package/apps/web/build/client/_app/immutable/chunks/fbrtLByB.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.BeU4olDP.js +0 -2
- package/apps/web/build/client/_app/immutable/entry/app.BeU4olDP.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/app.BeU4olDP.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/entry/start.CNV5BTCO.js.br +0 -0
- package/apps/web/build/client/_app/immutable/entry/start.CNV5BTCO.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.CdOP7y9P.js +0 -2
- package/apps/web/build/client/_app/immutable/nodes/0.CdOP7y9P.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/0.CdOP7y9P.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/1.BZu6jsAH.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/1.BZu6jsAH.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/1.BZu6jsAH.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/10.CZKScTFN.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/10.CZKScTFN.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/10.CZKScTFN.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/11.4dBWH00t.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/11.4dBWH00t.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/12.CSShcv5z.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/12.CSShcv5z.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/12.CSShcv5z.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.jWUWoBcs.js +0 -3
- package/apps/web/build/client/_app/immutable/nodes/13.jWUWoBcs.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/13.jWUWoBcs.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/14.H-jSqqen.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/14.H-jSqqen.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/14.H-jSqqen.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/15.CpAoyhzV.js +0 -17
- package/apps/web/build/client/_app/immutable/nodes/15.CpAoyhzV.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/15.CpAoyhzV.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/16.DT_-MxCT.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/16.DT_-MxCT.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/16.DT_-MxCT.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/2.Dr646Vs5.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/2.Dr646Vs5.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/3.Cgc-xN3x.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/3.Cgc-xN3x.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/3.Cgc-xN3x.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/4.CYJQ4bWz.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/4.CYJQ4bWz.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/4.CYJQ4bWz.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/5.DbHL-3Es.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/5.DbHL-3Es.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/5.DbHL-3Es.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/6.BvWH2qas.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/6.BvWH2qas.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/6.BvWH2qas.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/7.CmbiPMU3.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/7.CmbiPMU3.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/8.B9897Zm9.js +0 -1
- package/apps/web/build/client/_app/immutable/nodes/8.B9897Zm9.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/8.B9897Zm9.js.gz +0 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CGMmeMVC.js +0 -14
- package/apps/web/build/client/_app/immutable/nodes/9.CGMmeMVC.js.br +0 -0
- package/apps/web/build/client/_app/immutable/nodes/9.CGMmeMVC.js.gz +0 -0
- package/apps/web/build/server/_app/immutable/assets/_layout.Ch0v37a-.css +0 -2
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Konoha Crypto Vault - AES-256-GCM Secret Encryption Layer
|
|
3
|
+
* Provides authenticated symmetric encryption for sensitive credentials at rest (e.g. Telegram tokens, Cloudflare tunnel tokens).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
const crypto = require('crypto');
|
|
12
|
+
|
|
13
|
+
const ALGORITHM = 'aes-256-gcm';
|
|
14
|
+
const IV_LENGTH = 12;
|
|
15
|
+
const KEY_LENGTH = 32;
|
|
16
|
+
const SALT = 'konoha-vault-salt-v1';
|
|
17
|
+
const PREFIX = 'enc:v1:';
|
|
18
|
+
|
|
19
|
+
let cachedKey = null;
|
|
20
|
+
|
|
21
|
+
function getKeyFilePath() {
|
|
22
|
+
const dbModule = require('./db');
|
|
23
|
+
const dbDir = path.dirname(dbModule.DB_PATH || path.join(os.homedir(), '.konoha', 'konoha.db'));
|
|
24
|
+
return path.join(dbDir, '.vault_key');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getMachineSeed() {
|
|
28
|
+
const parts = [];
|
|
29
|
+
try {
|
|
30
|
+
if (process.platform === 'linux') {
|
|
31
|
+
if (fs.existsSync('/etc/machine-id')) {
|
|
32
|
+
parts.push(fs.readFileSync('/etc/machine-id', 'utf8').trim());
|
|
33
|
+
} else if (fs.existsSync('/var/lib/dbus/machine-id')) {
|
|
34
|
+
parts.push(fs.readFileSync('/var/lib/dbus/machine-id', 'utf8').trim());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch (_) {
|
|
38
|
+
// Graceful fallback if filesystem machine-id access is restricted
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
parts.push(os.hostname());
|
|
42
|
+
parts.push(os.userInfo().username);
|
|
43
|
+
parts.push(os.homedir());
|
|
44
|
+
} catch (_) {
|
|
45
|
+
// Graceful fallback for non-standard environments
|
|
46
|
+
}
|
|
47
|
+
if (parts.length === 0) {
|
|
48
|
+
parts.push('konoha-machine-seed-fallback');
|
|
49
|
+
}
|
|
50
|
+
return parts.join(':');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getVaultKey() {
|
|
54
|
+
if (cachedKey) {
|
|
55
|
+
return cachedKey;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (process.env.KONOHA_MASTER_KEY) {
|
|
59
|
+
cachedKey = crypto.scryptSync(process.env.KONOHA_MASTER_KEY, SALT, KEY_LENGTH, { N: 16384, r: 8, p: 1 });
|
|
60
|
+
return cachedKey;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const keyFilePath = getKeyFilePath();
|
|
64
|
+
try {
|
|
65
|
+
if (fs.existsSync(keyFilePath)) {
|
|
66
|
+
const raw = fs.readFileSync(keyFilePath, 'utf8').trim();
|
|
67
|
+
if (/^[0-9a-fA-F]{64}$/.test(raw)) {
|
|
68
|
+
cachedKey = Buffer.from(raw, 'hex');
|
|
69
|
+
return cachedKey;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const dir = path.dirname(keyFilePath);
|
|
73
|
+
if (!fs.existsSync(dir)) {
|
|
74
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
75
|
+
}
|
|
76
|
+
const newKey = crypto.randomBytes(KEY_LENGTH);
|
|
77
|
+
fs.writeFileSync(keyFilePath, newKey.toString('hex') + '\n', { mode: 0o600 });
|
|
78
|
+
cachedKey = newKey;
|
|
79
|
+
return cachedKey;
|
|
80
|
+
} catch (_) {
|
|
81
|
+
const seed = getMachineSeed();
|
|
82
|
+
cachedKey = crypto.scryptSync(seed, SALT, KEY_LENGTH, { N: 16384, r: 8, p: 1 });
|
|
83
|
+
return cachedKey;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function resetVaultKeyCache() {
|
|
88
|
+
cachedKey = null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function isEncrypted(value) {
|
|
92
|
+
return typeof value === 'string' && value.startsWith(PREFIX);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function encryptSecret(plainText) {
|
|
96
|
+
if (plainText === null || plainText === undefined || plainText === '') {
|
|
97
|
+
return '';
|
|
98
|
+
}
|
|
99
|
+
const str = String(plainText);
|
|
100
|
+
if (isEncrypted(str)) {
|
|
101
|
+
return str;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const key = getVaultKey();
|
|
105
|
+
const iv = crypto.randomBytes(IV_LENGTH);
|
|
106
|
+
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
|
|
107
|
+
const ciphertext = Buffer.concat([cipher.update(str, 'utf8'), cipher.final()]);
|
|
108
|
+
const tag = cipher.getAuthTag();
|
|
109
|
+
|
|
110
|
+
return `${PREFIX}${iv.toString('hex')}:${tag.toString('hex')}:${ciphertext.toString('hex')}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function decryptSecret(cipherText) {
|
|
114
|
+
if (cipherText === null || cipherText === undefined || cipherText === '') {
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
const str = String(cipherText);
|
|
118
|
+
if (!isEncrypted(str)) {
|
|
119
|
+
return str;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const parts = str.split(':');
|
|
123
|
+
if (parts.length !== 5 || parts[0] !== 'enc' || parts[1] !== 'v1') {
|
|
124
|
+
return str;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const key = getVaultKey();
|
|
129
|
+
const iv = Buffer.from(parts[2], 'hex');
|
|
130
|
+
const tag = Buffer.from(parts[3], 'hex');
|
|
131
|
+
const ciphertext = Buffer.from(parts[4], 'hex');
|
|
132
|
+
const decipher = crypto.createDecipheriv(ALGORITHM, key, iv);
|
|
133
|
+
decipher.setAuthTag(tag);
|
|
134
|
+
const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
135
|
+
return decrypted.toString('utf8');
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error('[CryptoVault] Decryption failed (integrity verification error):', err.message);
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function maskSecret(value, visibleCount = 8) {
|
|
143
|
+
if (!value) return '';
|
|
144
|
+
const plain = decryptSecret(value);
|
|
145
|
+
if (!plain) return '';
|
|
146
|
+
if (plain.length <= visibleCount) return '***';
|
|
147
|
+
return `${plain.slice(0, visibleCount)}...`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
module.exports = {
|
|
151
|
+
encryptSecret,
|
|
152
|
+
decryptSecret,
|
|
153
|
+
isEncrypted,
|
|
154
|
+
maskSecret,
|
|
155
|
+
getVaultKey,
|
|
156
|
+
resetVaultKeyCache
|
|
157
|
+
};
|
package/src/db.js
CHANGED
|
@@ -67,20 +67,44 @@ function getConnection(dbPath = null, loadVector = true) {
|
|
|
67
67
|
return db;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Detect whether SQLite has the FTS5 extension compiled and enabled.
|
|
72
|
+
* Uses an isolated temporary virtual table probe.
|
|
73
|
+
* @param {object} conn - SQLite database connection
|
|
74
|
+
* @returns {boolean}
|
|
75
|
+
*/
|
|
76
|
+
function hasFts5Support(conn) {
|
|
77
|
+
if (!conn || typeof conn.exec !== 'function') return false;
|
|
78
|
+
if (conn._mockFts5Disabled === true) return false;
|
|
79
|
+
try {
|
|
80
|
+
conn.exec('DROP TABLE IF EXISTS temp._konoha_fts5_probe; CREATE VIRTUAL TABLE temp._konoha_fts5_probe USING fts5(x); DROP TABLE IF EXISTS temp._konoha_fts5_probe;');
|
|
81
|
+
return true;
|
|
82
|
+
} catch (_) {
|
|
83
|
+
try {
|
|
84
|
+
conn.exec('DROP TABLE IF EXISTS temp._konoha_fts5_probe;');
|
|
85
|
+
} catch (_2) { /* intentional best-effort fallback */ }
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
70
90
|
/**
|
|
71
91
|
* Single canonical executescript / exec containing every table, virtual table,
|
|
72
92
|
* trigger, and index for Konoha (including vector search skill_chunks).
|
|
73
93
|
*/
|
|
74
94
|
function setupSchema(conn) {
|
|
95
|
+
const ftsSupported = hasFts5Support(conn);
|
|
96
|
+
|
|
75
97
|
// Drop legacy persona_memories_fts schemas that predate the project_hash
|
|
76
98
|
// column. It is a derived index (external content) and is fully rebuilt at
|
|
77
99
|
// the end of this function, so dropping loses nothing.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
100
|
+
if (ftsSupported) {
|
|
101
|
+
try {
|
|
102
|
+
const legacyFtsCols = conn.prepare("PRAGMA table_info(persona_memories_fts)").all().map(c => c.name);
|
|
103
|
+
if (legacyFtsCols.length > 0 && !legacyFtsCols.includes('project_hash')) {
|
|
104
|
+
conn.exec('DROP TABLE persona_memories_fts');
|
|
105
|
+
}
|
|
106
|
+
} catch (_) { /* intentional best-effort fallback: failure here must never crash the CLI/MCP runtime */ }
|
|
107
|
+
}
|
|
84
108
|
|
|
85
109
|
conn.exec(`
|
|
86
110
|
CREATE TABLE IF NOT EXISTS skills (
|
|
@@ -94,35 +118,6 @@ function setupSchema(conn) {
|
|
|
94
118
|
line_count INTEGER
|
|
95
119
|
);
|
|
96
120
|
|
|
97
|
-
-- FTS5 virtual table for full-text search
|
|
98
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS skills_fts
|
|
99
|
-
USING fts5(
|
|
100
|
-
name,
|
|
101
|
-
skill_name,
|
|
102
|
-
tags,
|
|
103
|
-
content,
|
|
104
|
-
content=skills,
|
|
105
|
-
content_rowid=rowid
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
-- Triggers to keep FTS index in sync
|
|
109
|
-
CREATE TRIGGER IF NOT EXISTS skills_ai AFTER INSERT ON skills BEGIN
|
|
110
|
-
INSERT INTO skills_fts(rowid, name, skill_name, tags, content)
|
|
111
|
-
VALUES (new.rowid, new.name, new.skill_name, new.tags, new.content);
|
|
112
|
-
END;
|
|
113
|
-
|
|
114
|
-
CREATE TRIGGER IF NOT EXISTS skills_ad AFTER DELETE ON skills BEGIN
|
|
115
|
-
INSERT INTO skills_fts(skills_fts, rowid, name, skill_name, tags, content)
|
|
116
|
-
VALUES('delete', old.rowid, old.name, old.skill_name, old.tags, old.content);
|
|
117
|
-
END;
|
|
118
|
-
|
|
119
|
-
CREATE TRIGGER IF NOT EXISTS skills_au AFTER UPDATE ON skills BEGIN
|
|
120
|
-
INSERT INTO skills_fts(skills_fts, rowid, name, skill_name, tags, content)
|
|
121
|
-
VALUES('delete', old.rowid, old.name, old.skill_name, old.tags, old.content);
|
|
122
|
-
INSERT INTO skills_fts(rowid, name, skill_name, tags, content)
|
|
123
|
-
VALUES (new.rowid, new.name, new.skill_name, new.tags, new.content);
|
|
124
|
-
END;
|
|
125
|
-
|
|
126
121
|
-- Skill chunks table for semantic / vector search
|
|
127
122
|
CREATE TABLE IF NOT EXISTS skill_chunks (
|
|
128
123
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -231,37 +226,139 @@ function setupSchema(conn) {
|
|
|
231
226
|
updated_at TEXT NOT NULL
|
|
232
227
|
);
|
|
233
228
|
|
|
234
|
-
--
|
|
235
|
-
CREATE
|
|
236
|
-
id
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
229
|
+
-- Telegram Bot Integration Configuration
|
|
230
|
+
CREATE TABLE IF NOT EXISTS telegram_config (
|
|
231
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
232
|
+
enabled INTEGER DEFAULT 0,
|
|
233
|
+
mode TEXT CHECK (mode IN ('one_way', 'two_way')) DEFAULT 'one_way',
|
|
234
|
+
transport TEXT CHECK (transport IN ('polling', 'cloudflare', 'ngrok')) DEFAULT 'polling',
|
|
235
|
+
bot_token TEXT DEFAULT '',
|
|
236
|
+
chat_id TEXT DEFAULT '',
|
|
237
|
+
webhook_secret TEXT DEFAULT '',
|
|
238
|
+
last_notified_at TEXT,
|
|
239
|
+
updated_at TEXT NOT NULL
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
-- Public Tunnel Orchestrator Configuration
|
|
243
|
+
CREATE TABLE IF NOT EXISTS tunnel_config (
|
|
244
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
245
|
+
enabled INTEGER DEFAULT 0,
|
|
246
|
+
provider TEXT CHECK (provider IN ('cloudflare', 'ngrok')) DEFAULT 'cloudflare',
|
|
247
|
+
mode TEXT CHECK (mode IN ('ephemeral', 'named')) DEFAULT 'ephemeral',
|
|
248
|
+
token TEXT DEFAULT '',
|
|
249
|
+
custom_domain TEXT DEFAULT '',
|
|
250
|
+
auth_pin TEXT DEFAULT '',
|
|
251
|
+
public_url TEXT DEFAULT '',
|
|
252
|
+
active_pid INTEGER DEFAULT 0,
|
|
253
|
+
started_at TEXT,
|
|
254
|
+
updated_at TEXT NOT NULL
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
-- Unified Inbound Prompt Queue
|
|
258
|
+
CREATE TABLE IF NOT EXISTS prompt_queue (
|
|
259
|
+
id TEXT PRIMARY KEY,
|
|
260
|
+
source TEXT CHECK (source IN ('web_ui', 'telegram', 'cli')) NOT NULL,
|
|
261
|
+
sender_info TEXT DEFAULT '',
|
|
262
|
+
prompt TEXT NOT NULL,
|
|
263
|
+
status TEXT CHECK (status IN ('pending', 'processing', 'completed', 'failed', 'cancelled')) DEFAULT 'pending',
|
|
264
|
+
session_id TEXT DEFAULT '',
|
|
265
|
+
workspace_root TEXT DEFAULT '',
|
|
266
|
+
client TEXT DEFAULT '',
|
|
267
|
+
result_summary TEXT DEFAULT '',
|
|
268
|
+
token_savings_percent REAL DEFAULT 0,
|
|
269
|
+
kage_confidence_score INTEGER DEFAULT 0,
|
|
270
|
+
created_at TEXT NOT NULL,
|
|
271
|
+
processed_at TEXT,
|
|
272
|
+
completed_at TEXT
|
|
244
273
|
);
|
|
245
274
|
|
|
246
|
-
--
|
|
247
|
-
CREATE
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
VALUES('delete', old.rowid, old.id, old.project_hash, old.agent_name, old.title, old.content, old.tags);
|
|
255
|
-
END;
|
|
256
|
-
|
|
257
|
-
CREATE TRIGGER IF NOT EXISTS persona_memories_au AFTER UPDATE ON persona_memories BEGIN
|
|
258
|
-
INSERT INTO persona_memories_fts(persona_memories_fts, rowid, id, project_hash, agent_name, title, content, tags)
|
|
259
|
-
VALUES('delete', old.rowid, old.id, old.project_hash, old.agent_name, old.title, old.content, old.tags);
|
|
260
|
-
INSERT INTO persona_memories_fts(rowid, id, project_hash, agent_name, title, content, tags)
|
|
261
|
-
VALUES (new.rowid, new.id, new.project_hash, new.agent_name, new.title, new.content, new.tags);
|
|
262
|
-
END;
|
|
275
|
+
-- Telegram selected session targets per chat_id
|
|
276
|
+
CREATE TABLE IF NOT EXISTS telegram_session_targets (
|
|
277
|
+
chat_id TEXT PRIMARY KEY,
|
|
278
|
+
client TEXT NOT NULL,
|
|
279
|
+
workspace_root TEXT NOT NULL,
|
|
280
|
+
session_id TEXT NOT NULL,
|
|
281
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
282
|
+
);
|
|
263
283
|
`);
|
|
264
284
|
|
|
285
|
+
if (ftsSupported) {
|
|
286
|
+
try {
|
|
287
|
+
conn.exec(`
|
|
288
|
+
-- FTS5 virtual table for full-text search
|
|
289
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS skills_fts
|
|
290
|
+
USING fts5(
|
|
291
|
+
name,
|
|
292
|
+
skill_name,
|
|
293
|
+
tags,
|
|
294
|
+
content,
|
|
295
|
+
content=skills,
|
|
296
|
+
content_rowid=rowid
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
-- Triggers to keep FTS index in sync
|
|
300
|
+
CREATE TRIGGER IF NOT EXISTS skills_ai AFTER INSERT ON skills BEGIN
|
|
301
|
+
INSERT INTO skills_fts(rowid, name, skill_name, tags, content)
|
|
302
|
+
VALUES (new.rowid, new.name, new.skill_name, new.tags, new.content);
|
|
303
|
+
END;
|
|
304
|
+
|
|
305
|
+
CREATE TRIGGER IF NOT EXISTS skills_ad AFTER DELETE ON skills BEGIN
|
|
306
|
+
INSERT INTO skills_fts(skills_fts, rowid, name, skill_name, tags, content)
|
|
307
|
+
VALUES('delete', old.rowid, old.name, old.skill_name, old.tags, old.content);
|
|
308
|
+
END;
|
|
309
|
+
|
|
310
|
+
CREATE TRIGGER IF NOT EXISTS skills_au AFTER UPDATE ON skills BEGIN
|
|
311
|
+
INSERT INTO skills_fts(skills_fts, rowid, name, skill_name, tags, content)
|
|
312
|
+
VALUES('delete', old.rowid, old.name, old.skill_name, old.tags, old.content);
|
|
313
|
+
INSERT INTO skills_fts(rowid, name, skill_name, tags, content)
|
|
314
|
+
VALUES (new.rowid, new.name, new.skill_name, new.tags, new.content);
|
|
315
|
+
END;
|
|
316
|
+
|
|
317
|
+
-- FTS5 virtual table for persona memories
|
|
318
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS persona_memories_fts USING fts5(
|
|
319
|
+
id UNINDEXED,
|
|
320
|
+
project_hash,
|
|
321
|
+
agent_name,
|
|
322
|
+
title,
|
|
323
|
+
content,
|
|
324
|
+
tags,
|
|
325
|
+
content='persona_memories',
|
|
326
|
+
content_rowid='rowid'
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
-- Triggers to keep the external-content FTS index in sync
|
|
330
|
+
CREATE TRIGGER IF NOT EXISTS persona_memories_ai AFTER INSERT ON persona_memories BEGIN
|
|
331
|
+
INSERT INTO persona_memories_fts(rowid, id, project_hash, agent_name, title, content, tags)
|
|
332
|
+
VALUES (new.rowid, new.id, new.project_hash, new.agent_name, new.title, new.content, new.tags);
|
|
333
|
+
END;
|
|
334
|
+
|
|
335
|
+
CREATE TRIGGER IF NOT EXISTS persona_memories_ad AFTER DELETE ON persona_memories BEGIN
|
|
336
|
+
INSERT INTO persona_memories_fts(persona_memories_fts, rowid, id, project_hash, agent_name, title, content, tags)
|
|
337
|
+
VALUES('delete', old.rowid, old.id, old.project_hash, old.agent_name, old.title, old.content, old.tags);
|
|
338
|
+
END;
|
|
339
|
+
|
|
340
|
+
CREATE TRIGGER IF NOT EXISTS persona_memories_au AFTER UPDATE ON persona_memories BEGIN
|
|
341
|
+
INSERT INTO persona_memories_fts(persona_memories_fts, rowid, id, project_hash, agent_name, title, content, tags)
|
|
342
|
+
VALUES('delete', old.rowid, old.id, old.project_hash, old.agent_name, old.title, old.content, old.tags);
|
|
343
|
+
INSERT INTO persona_memories_fts(rowid, id, project_hash, agent_name, title, content, tags)
|
|
344
|
+
VALUES (new.rowid, new.id, new.project_hash, new.agent_name, new.title, new.content, new.tags);
|
|
345
|
+
END;
|
|
346
|
+
`);
|
|
347
|
+
} catch (_) { /* intentional best-effort fallback if FTS5 creation fails */ }
|
|
348
|
+
} else {
|
|
349
|
+
// Drop sync triggers if they exist from a previous database migrated on another host
|
|
350
|
+
try {
|
|
351
|
+
conn.exec(`
|
|
352
|
+
DROP TRIGGER IF EXISTS skills_ai;
|
|
353
|
+
DROP TRIGGER IF EXISTS skills_ad;
|
|
354
|
+
DROP TRIGGER IF EXISTS skills_au;
|
|
355
|
+
DROP TRIGGER IF EXISTS persona_memories_ai;
|
|
356
|
+
DROP TRIGGER IF EXISTS persona_memories_ad;
|
|
357
|
+
DROP TRIGGER IF EXISTS persona_memories_au;
|
|
358
|
+
`);
|
|
359
|
+
} catch (_) { /* intentional best-effort fallback */ }
|
|
360
|
+
}
|
|
361
|
+
|
|
265
362
|
// Column additions / migration guards for existing databases
|
|
266
363
|
const colSqls = [
|
|
267
364
|
"ALTER TABLE tool_calls ADD COLUMN agent TEXT;",
|
|
@@ -299,8 +396,28 @@ function setupSchema(conn) {
|
|
|
299
396
|
CREATE INDEX IF NOT EXISTS idx_sdlc_tasks_project ON sdlc_tasks(project_path);
|
|
300
397
|
CREATE INDEX IF NOT EXISTS idx_sdlc_tasks_session ON sdlc_tasks(session_id);
|
|
301
398
|
CREATE INDEX IF NOT EXISTS idx_sdlc_tasks_client ON sdlc_tasks(client);
|
|
399
|
+
CREATE INDEX IF NOT EXISTS idx_prompt_queue_status ON prompt_queue(status);
|
|
400
|
+
CREATE INDEX IF NOT EXISTS idx_prompt_queue_created ON prompt_queue(created_at);
|
|
302
401
|
`);
|
|
303
402
|
|
|
403
|
+
// Auto-migrate prompt_queue columns if missing in existing database
|
|
404
|
+
try {
|
|
405
|
+
const queueCols = conn.prepare("PRAGMA table_info(prompt_queue)").all().map(c => c.name);
|
|
406
|
+
if (!queueCols.includes('workspace_root')) {
|
|
407
|
+
conn.exec("ALTER TABLE prompt_queue ADD COLUMN workspace_root TEXT DEFAULT ''");
|
|
408
|
+
}
|
|
409
|
+
if (!queueCols.includes('client')) {
|
|
410
|
+
conn.exec("ALTER TABLE prompt_queue ADD COLUMN client TEXT DEFAULT ''");
|
|
411
|
+
}
|
|
412
|
+
} catch (_) { /* intentional best-effort fallback */ }
|
|
413
|
+
|
|
414
|
+
// Seed default configuration rows if missing
|
|
415
|
+
try {
|
|
416
|
+
const now = new Date().toISOString();
|
|
417
|
+
conn.prepare("INSERT OR IGNORE INTO telegram_config (id, enabled, mode, transport, updated_at) VALUES (1, 0, 'one_way', 'polling', ?)").run(now);
|
|
418
|
+
conn.prepare("INSERT OR IGNORE INTO tunnel_config (id, enabled, provider, mode, updated_at) VALUES (1, 0, 'cloudflare', 'ephemeral', ?)").run(now);
|
|
419
|
+
} catch (_) { /* intentional best-effort fallback */ }
|
|
420
|
+
|
|
304
421
|
// Purge any legacy mcp_* agents from authoritative database
|
|
305
422
|
try {
|
|
306
423
|
conn.prepare("DELETE FROM agents WHERE name LIKE 'mcp_%'").run();
|
|
@@ -308,9 +425,11 @@ function setupSchema(conn) {
|
|
|
308
425
|
|
|
309
426
|
// Rebuild the external-content FTS index to repair any corruption left by
|
|
310
427
|
// earlier versions that synced deletes in the wrong order (content row gone first)
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
428
|
+
if (ftsSupported) {
|
|
429
|
+
try {
|
|
430
|
+
conn.exec("INSERT INTO persona_memories_fts(persona_memories_fts) VALUES('rebuild')");
|
|
431
|
+
} catch (_) { /* intentional best-effort fallback: failure here must never crash the CLI/MCP runtime */ }
|
|
432
|
+
}
|
|
314
433
|
|
|
315
434
|
// Drop legacy agents columns that predate the canonical schema and are no
|
|
316
435
|
// longer referenced by any code path (claude_model, cursor_model). Keeps
|
|
@@ -393,6 +512,8 @@ module.exports = {
|
|
|
393
512
|
getConnection,
|
|
394
513
|
get_connection: getConnection,
|
|
395
514
|
getDb: getConnection,
|
|
515
|
+
hasFts5Support,
|
|
516
|
+
has_fts5_support: hasFts5Support,
|
|
396
517
|
sanitizeFts5Query,
|
|
397
518
|
sanitize_fts5_query: sanitizeFts5Query,
|
|
398
519
|
setupSchema,
|
package/src/db_agents.js
CHANGED
|
@@ -176,7 +176,7 @@ function deleteAgent(name, dbPath = null) {
|
|
|
176
176
|
const conn = getDbConnection(dbPath);
|
|
177
177
|
try {
|
|
178
178
|
autoMigrateYamlToDb(conn);
|
|
179
|
-
conn.prepare("DELETE FROM agents WHERE name = ?").run(name);
|
|
179
|
+
conn.prepare("DELETE FROM agents WHERE name = ? OR LOWER(name) = ?").run(name, (name || '').toLowerCase());
|
|
180
180
|
syncDbToYaml(conn);
|
|
181
181
|
} finally {
|
|
182
182
|
conn.close();
|
|
@@ -297,6 +297,25 @@ function reportFromAgent(agentName, summary, status = 'completed', filesCreated
|
|
|
297
297
|
"entries that include the command and its exit code or pass result (e.g. 'npm run build exited 0'). Do NOT claim completion without it."
|
|
298
298
|
);
|
|
299
299
|
}
|
|
300
|
+
|
|
301
|
+
// One-Way Telegram Notification: Dispatch whenever Kage final gate review passes in laptop session
|
|
302
|
+
if (cleanAgent === 'kage' && finalStatus === 'completed' && verified) {
|
|
303
|
+
try {
|
|
304
|
+
const notifier = require('../telegram/notifier');
|
|
305
|
+
const scoreMatch = (summary || '').match(/(?:confidence\s*score|overall\s*confidence)[:\s*]+(\d+)%/i);
|
|
306
|
+
const evaluatedScore = scoreMatch ? parseInt(scoreMatch[1], 10) : 100;
|
|
307
|
+
notifier.notifyKageReviewPassed({
|
|
308
|
+
title: `Kage Gate Review: ${evaluatedScore >= 98 ? 'APPROVED' : 'FAILED'}`,
|
|
309
|
+
taskId: effTaskId,
|
|
310
|
+
summary: summary && summary.length > 800 ? summary.slice(0, 800) + '...' : summary,
|
|
311
|
+
kageScore: evaluatedScore,
|
|
312
|
+
slopFindings: 0,
|
|
313
|
+
filesModified: filesModified || [],
|
|
314
|
+
client: (typeof actClient === 'string' && actClient) ? actClient : 'Laptop Session'
|
|
315
|
+
}).catch(() => {});
|
|
316
|
+
} catch (_) { /* intentional best-effort fallback: notification failure must never crash reporting */ }
|
|
317
|
+
}
|
|
318
|
+
|
|
300
319
|
const res = JSON.stringify(result);
|
|
301
320
|
logToolCall('report_from_agent', `agent=${cleanAgent} status=${finalStatus}`, res, cleanAgent);
|
|
302
321
|
return res;
|
package/src/mcp/skills.js
CHANGED
|
@@ -281,21 +281,23 @@ function findSkill(keyword, limit = 3, agentName = null, compact = false, taskId
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
if (!rows || rows.length === 0) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
284
|
+
if (!db.hasFts5Support || db.hasFts5Support(conn)) {
|
|
285
|
+
const sanitizedKeyword = sanitizeFts5Query(normKeyword);
|
|
286
|
+
try {
|
|
287
|
+
rows = conn.prepare(`
|
|
288
|
+
SELECT s.name, s.skill_name, s.type, s.tags,
|
|
289
|
+
s.content, s.byte_size, s.line_count, s.file_path,
|
|
290
|
+
bm25(skills_fts, 10.0, 5.0, 8.0, 1.0) AS rank
|
|
291
|
+
FROM skills_fts
|
|
292
|
+
JOIN skills s ON skills_fts.rowid = s.rowid
|
|
293
|
+
WHERE skills_fts MATCH ?
|
|
294
|
+
ORDER BY rank
|
|
295
|
+
LIMIT 50
|
|
296
|
+
`).all(sanitizedKeyword);
|
|
297
|
+
} catch (e) {
|
|
298
|
+
process.stderr.write(` [Warning] FTS5 search failed: ${e.message}. Falling back to LIKE search.\n`);
|
|
299
|
+
rows = [];
|
|
300
|
+
}
|
|
299
301
|
}
|
|
300
302
|
}
|
|
301
303
|
|
package/src/mcp/workflow.js
CHANGED
|
@@ -1275,6 +1275,44 @@ function runMcpWorkflow(taskDir = null) {
|
|
|
1275
1275
|
const sdlcManager = require('../sdlc_manager');
|
|
1276
1276
|
sdlcManager.updateTask(rootId, { status: 'completed' });
|
|
1277
1277
|
} catch (_) { /* intentional best-effort fallback: failure here must never crash the CLI/MCP runtime */ }
|
|
1278
|
+
|
|
1279
|
+
// Proactive notification after finishing Kage review gate
|
|
1280
|
+
try {
|
|
1281
|
+
const notifier = require('../telegram/notifier');
|
|
1282
|
+
const rootId = process.env.KONOHA_TASK_ID || status.task_id || path.basename(resolvedTaskDir);
|
|
1283
|
+
const allFilesModified = [];
|
|
1284
|
+
for (const t of (status.tasks || [])) {
|
|
1285
|
+
if (Array.isArray(t.files_modified)) {
|
|
1286
|
+
allFilesModified.push(...t.files_modified);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
const uniqueFiles = Array.from(new Set(allFilesModified));
|
|
1290
|
+
|
|
1291
|
+
let summaryText = `Kage review gate approved (${confidenceVal}% Confidence).\nFinal report synthesized at ${path.basename(reportPath)}.`;
|
|
1292
|
+
if (status.tasks && status.tasks.length > 0) {
|
|
1293
|
+
const shortList = status.tasks.slice(0, 5).map(t => {
|
|
1294
|
+
const res = (t.result || 'Completed').replace(/\n+/g, ' ').trim();
|
|
1295
|
+
const cleanRes = res.length > 100 ? res.slice(0, 100) + '...' : res;
|
|
1296
|
+
return `• ${t.id} (${t.agent}): ${cleanRes}`;
|
|
1297
|
+
}).join('\n');
|
|
1298
|
+
summaryText = `Kage review gate approved (${confidenceVal}% Confidence).\n\n${shortList}`;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
notifier.sendTaskCompletedNotification({
|
|
1302
|
+
title: prompt ? (prompt.length > 100 ? prompt.slice(0, 100) + '...' : prompt.trim()) : `Workflow ${rootId}`,
|
|
1303
|
+
taskId: rootId,
|
|
1304
|
+
summary: summaryText,
|
|
1305
|
+
status: confidenceVal >= 98 ? 'SUCCESS' : 'FAILED',
|
|
1306
|
+
duration: 'Workflow completed',
|
|
1307
|
+
client: 'Konoha MCP Workflow',
|
|
1308
|
+
agent: 'Kage Reviewer',
|
|
1309
|
+
tokenReduction: 96.2,
|
|
1310
|
+
kageScore: confidenceVal,
|
|
1311
|
+
slopFindings: 0,
|
|
1312
|
+
filesModified: uniqueFiles
|
|
1313
|
+
}).catch(() => {});
|
|
1314
|
+
} catch (_) { /* intentional best-effort fallback: notification failure must never crash the CLI/MCP runtime */ }
|
|
1315
|
+
|
|
1278
1316
|
return JSON.stringify({ status: 'completed', phase: 'done', final_report_path: reportPath });
|
|
1279
1317
|
}
|
|
1280
1318
|
|