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,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Outbound Task Notifier.
|
|
3
|
+
* Dispatches structured task completion reports, telemetry, and Kage confidence badges.
|
|
4
|
+
* Strictly adheres to Zero-Emoji formatting policies across all messages.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const dns = require('dns');
|
|
10
|
+
if (typeof dns.setDefaultResultOrder === 'function') {
|
|
11
|
+
dns.setDefaultResultOrder('ipv4first');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const configModule = require('./config');
|
|
15
|
+
|
|
16
|
+
const CLIENT_NAMES = {
|
|
17
|
+
antigravity: 'Antigravity IDE/CLI',
|
|
18
|
+
agy: 'Antigravity CLI',
|
|
19
|
+
claudecode: 'Claude Code',
|
|
20
|
+
claude: 'Claude Code',
|
|
21
|
+
cursor: 'Cursor',
|
|
22
|
+
codex: 'Codex',
|
|
23
|
+
opencode: 'OpenCode',
|
|
24
|
+
commandcode: 'Command Code',
|
|
25
|
+
pi: 'Pi Agent',
|
|
26
|
+
telegram: 'Telegram Bot'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Safely escape HTML characters for Telegram HTML parse_mode.
|
|
31
|
+
*/
|
|
32
|
+
function escapeHtml(str) {
|
|
33
|
+
if (!str) return '';
|
|
34
|
+
return String(str)
|
|
35
|
+
.replace(/&/g, '&')
|
|
36
|
+
.replace(/</g, '<')
|
|
37
|
+
.replace(/>/g, '>');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Format a task report into a premium Telegram notification with bold labels and zero icons after colons.
|
|
42
|
+
*/
|
|
43
|
+
function formatTaskReport({
|
|
44
|
+
title = 'Task Execution Finished',
|
|
45
|
+
status = 'SUCCESS',
|
|
46
|
+
duration = '0s',
|
|
47
|
+
summary = null,
|
|
48
|
+
filesModified = [],
|
|
49
|
+
tokenReduction = null,
|
|
50
|
+
kageScore = null,
|
|
51
|
+
slopFindings = 0,
|
|
52
|
+
dashboardUrl = null,
|
|
53
|
+
client = null,
|
|
54
|
+
agent = null,
|
|
55
|
+
taskId = null,
|
|
56
|
+
icons = false
|
|
57
|
+
}) {
|
|
58
|
+
const isSuccess = String(status).toUpperCase() === 'SUCCESS';
|
|
59
|
+
const cleanStatus = isSuccess ? 'SUCCESS' : 'FAILED';
|
|
60
|
+
|
|
61
|
+
if (icons) {
|
|
62
|
+
let clientName = 'Antigravity IDE/CLI';
|
|
63
|
+
if (client) {
|
|
64
|
+
clientName = CLIENT_NAMES[String(client).toLowerCase()] || String(client).replace(/^[^\w\s]+\s*/, '');
|
|
65
|
+
} else {
|
|
66
|
+
try {
|
|
67
|
+
const cd = require('../mcp/client_detection');
|
|
68
|
+
const detected = cd.detectActiveClient();
|
|
69
|
+
if (detected && detected !== 'unattributed') {
|
|
70
|
+
clientName = CLIENT_NAMES[detected.toLowerCase()] || detected;
|
|
71
|
+
}
|
|
72
|
+
} catch (_) {
|
|
73
|
+
/* intentional fallback: client detection failure must not crash formatting */
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const cleanAgent = agent ? String(agent).replace(/^[^\w\s]+\s*/, '') : 'Kage & Anbu';
|
|
78
|
+
|
|
79
|
+
const lines = [
|
|
80
|
+
'<b>━━━━━━━━━━━━━━━━━━━━━━━━━━━━</b>',
|
|
81
|
+
'<b>KONOHA REPORT</b>',
|
|
82
|
+
'<b>━━━━━━━━━━━━━━━━━━━━━━━━━━━━</b>',
|
|
83
|
+
`<b>📋 Task:</b> ${escapeHtml(title)}`,
|
|
84
|
+
...(taskId ? [`<b>🔖 Task ID:</b> <code>${escapeHtml(taskId)}</code>`] : []),
|
|
85
|
+
`<b>📊 Status:</b> ${cleanStatus}`,
|
|
86
|
+
`<b>⚡ Executing Client:</b> ${escapeHtml(clientName)}`,
|
|
87
|
+
`<b>🥷 Executing Agent:</b> ${escapeHtml(cleanAgent)}`,
|
|
88
|
+
`<b>⏱️ Duration:</b> ${duration}`
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
if (summary) {
|
|
92
|
+
lines.push('────────────────────────────');
|
|
93
|
+
lines.push('<b>📝 Summary:</b>');
|
|
94
|
+
const cleanSummary = String(summary).length > 800
|
|
95
|
+
? String(summary).slice(0, 800) + '...'
|
|
96
|
+
: String(summary);
|
|
97
|
+
lines.push(escapeHtml(cleanSummary));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
lines.push('────────────────────────────');
|
|
101
|
+
lines.push('<b>📈 Telemetry & Governance:</b>');
|
|
102
|
+
|
|
103
|
+
if (tokenReduction !== null && tokenReduction !== undefined) {
|
|
104
|
+
lines.push(`<b>💎 Token Reduction:</b> ${tokenReduction}% Saved (83-98% Target)`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (kageScore !== null && kageScore !== undefined) {
|
|
108
|
+
lines.push(`<b>🛡️ Kage Confidence:</b> ${kageScore}% Passed`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
lines.push(`<b>✨ AI Slop Scanner:</b> 100/100 (${slopFindings} Findings)`);
|
|
112
|
+
|
|
113
|
+
if (Array.isArray(filesModified) && filesModified.length > 0) {
|
|
114
|
+
lines.push('────────────────────────────');
|
|
115
|
+
lines.push('<b>📁 Files Modified:</b>');
|
|
116
|
+
filesModified.slice(0, 10).forEach(file => {
|
|
117
|
+
lines.push(`• <code>${escapeHtml(file)}</code>`);
|
|
118
|
+
});
|
|
119
|
+
if (filesModified.length > 10) {
|
|
120
|
+
lines.push(`• <i>...and ${filesModified.length - 10} more files</i>`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (dashboardUrl) {
|
|
125
|
+
lines.push('────────────────────────────');
|
|
126
|
+
lines.push(`<b>🌐 Remote Dashboard:</b> ${escapeHtml(dashboardUrl)}`);
|
|
127
|
+
}
|
|
128
|
+
lines.push('━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
129
|
+
|
|
130
|
+
return lines.join('\n');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Standard clean text formatting (Zero Emojis policy by default)
|
|
134
|
+
const statusBadge = isSuccess ? '[SUCCESS]' : '[FAILED]';
|
|
135
|
+
const lines = [
|
|
136
|
+
'[KONOHA TASK REPORT]',
|
|
137
|
+
`Task: ${title}`,
|
|
138
|
+
`Status: ${statusBadge}`,
|
|
139
|
+
`Duration: ${duration}`
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
if (summary) {
|
|
143
|
+
lines.push(`Summary:\n${summary}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (client) {
|
|
147
|
+
lines.push(`Executing Client: ${client}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (Array.isArray(filesModified) && filesModified.length > 0) {
|
|
151
|
+
lines.push('Files Modified:');
|
|
152
|
+
filesModified.slice(0, 10).forEach(file => {
|
|
153
|
+
lines.push(`- ${file}`);
|
|
154
|
+
});
|
|
155
|
+
if (filesModified.length > 10) {
|
|
156
|
+
lines.push(`... and ${filesModified.length - 10} more files`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (tokenReduction !== null && tokenReduction !== undefined) {
|
|
161
|
+
lines.push(`Token Reduction: ${tokenReduction}% Saved`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (kageScore !== null && kageScore !== undefined) {
|
|
165
|
+
lines.push(`Kage Confidence: ${kageScore}% Passed`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
lines.push(`AI Slop Findings: ${slopFindings} (100/100 Gate)`);
|
|
169
|
+
|
|
170
|
+
if (dashboardUrl) {
|
|
171
|
+
lines.push('');
|
|
172
|
+
lines.push(`Remote Dashboard: ${dashboardUrl}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return lines.join('\n');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Send an outbound message to Telegram API.
|
|
180
|
+
*/
|
|
181
|
+
async function sendTelegramMessage(text, options = {}) {
|
|
182
|
+
const config = configModule.getTelegramConfig();
|
|
183
|
+
|
|
184
|
+
if (!config.enabled && !options.force) {
|
|
185
|
+
return { ok: false, error: 'Telegram integration is disabled' };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const token = options.bot_token || config.bot_token;
|
|
189
|
+
if (!token) {
|
|
190
|
+
return { ok: false, error: 'Telegram bot_token is not configured' };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const targetChatId = options.chat_id || config.chat_id;
|
|
194
|
+
if (!targetChatId) {
|
|
195
|
+
return { ok: false, error: 'Telegram chat_id is not configured' };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const url = `https://api.telegram.org/bot${token}/sendMessage`;
|
|
199
|
+
const body = {
|
|
200
|
+
chat_id: targetChatId,
|
|
201
|
+
text: text
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const parseMode = options.parse_mode || (text.includes('<b>') ? 'HTML' : (text.includes('*') ? 'Markdown' : undefined));
|
|
205
|
+
if (parseMode) {
|
|
206
|
+
body.parse_mode = parseMode;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let lastError = null;
|
|
210
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
211
|
+
try {
|
|
212
|
+
const res = await fetch(url, {
|
|
213
|
+
method: 'POST',
|
|
214
|
+
headers: { 'Content-Type': 'application/json' },
|
|
215
|
+
body: JSON.stringify(body),
|
|
216
|
+
signal: AbortSignal.timeout(15000)
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const data = await res.json();
|
|
220
|
+
if (data.ok) {
|
|
221
|
+
configModule.recordLastNotified();
|
|
222
|
+
return { ok: true, result: data.result };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Entity parse error recovery (HTTP 400): strip HTML tags and retry as clean plain text
|
|
226
|
+
if (data.error_code === 400 && body.parse_mode) {
|
|
227
|
+
const fallbackBody = {
|
|
228
|
+
chat_id: targetChatId,
|
|
229
|
+
text: text.replace(/<[^>]+>/g, '')
|
|
230
|
+
};
|
|
231
|
+
const fallbackRes = await fetch(url, {
|
|
232
|
+
method: 'POST',
|
|
233
|
+
headers: { 'Content-Type': 'application/json' },
|
|
234
|
+
body: JSON.stringify(fallbackBody),
|
|
235
|
+
signal: AbortSignal.timeout(15000)
|
|
236
|
+
});
|
|
237
|
+
const fallbackData = await fallbackRes.json();
|
|
238
|
+
if (fallbackData.ok) {
|
|
239
|
+
configModule.recordLastNotified();
|
|
240
|
+
return { ok: true, result: fallbackData.result };
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return { ok: false, error: data.description || 'Telegram API error', error_code: data.error_code };
|
|
245
|
+
} catch (err) {
|
|
246
|
+
lastError = err;
|
|
247
|
+
if (attempt < 2) {
|
|
248
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return { ok: false, error: lastError ? lastError.message : 'Network fetch failed' };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const sentNotifications = new Map();
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Check if a task completion notification was recently sent.
|
|
260
|
+
*/
|
|
261
|
+
function isRecentlyNotified(taskId) {
|
|
262
|
+
if (!taskId) return false;
|
|
263
|
+
const lastTime = sentNotifications.get(taskId);
|
|
264
|
+
return Boolean(lastTime && (Date.now() - lastTime < 180000));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Record timestamp of sent notification to avoid duplicate spam.
|
|
269
|
+
*/
|
|
270
|
+
function recordNotificationSent(taskId) {
|
|
271
|
+
if (!taskId) return;
|
|
272
|
+
sentNotifications.set(taskId, Date.now());
|
|
273
|
+
if (sentNotifications.size > 200) {
|
|
274
|
+
const cutoff = Date.now() - 300000;
|
|
275
|
+
for (const [key, ts] of sentNotifications.entries()) {
|
|
276
|
+
if (ts < cutoff) sentNotifications.delete(key);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Dispatch task completion report.
|
|
283
|
+
*/
|
|
284
|
+
async function sendTaskCompletedNotification(reportData = {}, options = {}) {
|
|
285
|
+
const taskId = reportData.taskId;
|
|
286
|
+
if (taskId && isRecentlyNotified(taskId) && !options.allowDuplicate) {
|
|
287
|
+
return { ok: true, skipped: true, reason: 'Duplicate notification suppressed' };
|
|
288
|
+
}
|
|
289
|
+
const text = formatTaskReport({ icons: true, ...reportData });
|
|
290
|
+
const sender = (typeof module.exports.sendTelegramMessage === 'function')
|
|
291
|
+
? module.exports.sendTelegramMessage
|
|
292
|
+
: sendTelegramMessage;
|
|
293
|
+
const res = await sender(text, { force: true, ...options });
|
|
294
|
+
if (res && res.ok && taskId) {
|
|
295
|
+
recordNotificationSent(taskId);
|
|
296
|
+
}
|
|
297
|
+
return res;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Dispatches an outbound notification to Telegram when Kage final gate review passes.
|
|
302
|
+
* Designed for One-Way mode so local laptop sessions automatically report delivery approvals to Telegram.
|
|
303
|
+
*/
|
|
304
|
+
async function notifyKageReviewPassed({
|
|
305
|
+
title = 'Kage Final Gate Review: APPROVED',
|
|
306
|
+
taskId = null,
|
|
307
|
+
summary = null,
|
|
308
|
+
kageScore = 100,
|
|
309
|
+
slopFindings = 0,
|
|
310
|
+
filesModified = [],
|
|
311
|
+
client = null,
|
|
312
|
+
tokenReduction = 97.0
|
|
313
|
+
} = {}) {
|
|
314
|
+
const config = configModule.getTelegramConfig();
|
|
315
|
+
if (!config.enabled) {
|
|
316
|
+
return { ok: false, error: 'Telegram integration is disabled' };
|
|
317
|
+
}
|
|
318
|
+
if (!config.bot_token) {
|
|
319
|
+
return { ok: false, error: 'Telegram bot_token is not configured' };
|
|
320
|
+
}
|
|
321
|
+
if (!config.chat_id) {
|
|
322
|
+
return { ok: false, error: 'Telegram chat_id is not configured' };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return sendTaskCompletedNotification({
|
|
326
|
+
title,
|
|
327
|
+
taskId: taskId || `kage_gate_${Date.now()}`,
|
|
328
|
+
summary: summary || 'Kage Review Gate approved with ≥ 98% confidence and zero AI slop findings.',
|
|
329
|
+
status: (kageScore >= 98 && slopFindings === 0) ? 'SUCCESS' : 'FAILED',
|
|
330
|
+
duration: 'Review Passed',
|
|
331
|
+
client: client || 'Antigravity IDE/CLI',
|
|
332
|
+
agent: 'Village Leader Kage',
|
|
333
|
+
tokenReduction,
|
|
334
|
+
kageScore,
|
|
335
|
+
slopFindings,
|
|
336
|
+
filesModified
|
|
337
|
+
}, { force: true });
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Send a verification test ping.
|
|
342
|
+
*/
|
|
343
|
+
async function sendTestPing(overrideChatId = null, overrideToken = null) {
|
|
344
|
+
const config = configModule.getTelegramConfig();
|
|
345
|
+
const targetId = overrideChatId || config.chat_id;
|
|
346
|
+
const token = (overrideToken && !overrideToken.includes('...')) ? overrideToken : config.bot_token;
|
|
347
|
+
const text = '[KONOHA TEST] Telegram bot integration active. Ready for task reports.';
|
|
348
|
+
return sendTelegramMessage(text, { force: true, chat_id: targetId, bot_token: token });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
module.exports = {
|
|
352
|
+
formatTaskReport,
|
|
353
|
+
sendTelegramMessage,
|
|
354
|
+
sendTaskCompletedNotification,
|
|
355
|
+
notifyKageReviewPassed,
|
|
356
|
+
sendTestPing,
|
|
357
|
+
isRecentlyNotified,
|
|
358
|
+
recordNotificationSent
|
|
359
|
+
};
|