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,548 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram Inbound Long Poller.
|
|
3
|
+
* Listens for incoming commands and prompts in Two-Way mode with strict Chat ID whitelist validation.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const dns = require('dns');
|
|
9
|
+
if (typeof dns.setDefaultResultOrder === 'function') {
|
|
10
|
+
dns.setDefaultResultOrder('ipv4first');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const configModule = require('./config');
|
|
15
|
+
const inboxModule = require('../queue/inbox');
|
|
16
|
+
const notifierModule = require('./notifier');
|
|
17
|
+
const sessionManager = require('./session_manager');
|
|
18
|
+
|
|
19
|
+
let isRunning = false;
|
|
20
|
+
let shouldStop = false;
|
|
21
|
+
let currentOffset = 0;
|
|
22
|
+
let _pollLoopPromise = null;
|
|
23
|
+
|
|
24
|
+
function isPollerRunning() {
|
|
25
|
+
return isRunning;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Safely escape HTML characters for Telegram HTML parse_mode.
|
|
30
|
+
*/
|
|
31
|
+
function escapeHtml(str) {
|
|
32
|
+
if (!str) return '';
|
|
33
|
+
return String(str)
|
|
34
|
+
.replace(/&/g, '&')
|
|
35
|
+
.replace(/</g, '<')
|
|
36
|
+
.replace(/>/g, '>');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Sanitize noisy shell preamble and non-critical job control warnings from interactive shell execution.
|
|
41
|
+
*/
|
|
42
|
+
function sanitizeShellOutput(text) {
|
|
43
|
+
if (!text || typeof text !== 'string') return '';
|
|
44
|
+
const lines = text.split('\n');
|
|
45
|
+
const filtered = [];
|
|
46
|
+
for (const line of lines) {
|
|
47
|
+
const trimmed = line.trim();
|
|
48
|
+
if (!trimmed) {
|
|
49
|
+
filtered.push(line);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// Filter out interactive shell job control warnings when run without TTY
|
|
53
|
+
if (/^bash:\s*cannot set terminal process group/i.test(trimmed)) continue;
|
|
54
|
+
if (/^bash:\s*no job control in this shell/i.test(trimmed)) continue;
|
|
55
|
+
if (/^zsh:\s*can't set tty pgrp/i.test(trimmed)) continue;
|
|
56
|
+
if (/^zsh:\s*no job control/i.test(trimmed)) continue;
|
|
57
|
+
// Filter out nvm / node startup announcement
|
|
58
|
+
if (/^Now using node v\d+/i.test(trimmed)) continue;
|
|
59
|
+
filtered.push(line);
|
|
60
|
+
}
|
|
61
|
+
return filtered.join('\n').trim();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Identify dangerous or destructive commands to prevent system harm via Telegram /sh.
|
|
66
|
+
*/
|
|
67
|
+
function isDangerousCommand(cmd) {
|
|
68
|
+
if (!cmd || typeof cmd !== 'string') return false;
|
|
69
|
+
const lower = cmd.toLowerCase().trim();
|
|
70
|
+
if (/rm\s+(-[a-z]*r[a-z]*f|-[a-z]*f[a-z]*r)\s+(\/|\/\*|~|\.|\.\.)(\s|$)/i.test(lower)) return true;
|
|
71
|
+
if (/rm\s+-[a-z]*r\s+(\/|\/\*|~|\.|\.\.)(\s|$)/i.test(lower)) return true;
|
|
72
|
+
if (/mkfs(\.[a-z0-9]+)?\s+/i.test(lower)) return true;
|
|
73
|
+
if (/dd\s+.*of=\/dev\/(sd[a-z]|nvme|hd[a-z]|null|zero)/i.test(lower)) return true;
|
|
74
|
+
if (/>\s*\/dev\/(sd[a-z]|nvme|hd[a-z])/i.test(lower)) return true;
|
|
75
|
+
if (/\b(drop\s+database|truncate\s+table|drop\s+table)\b/i.test(lower)) return true;
|
|
76
|
+
if (/:(\s*)\(\s*\)\s*\{/i.test(lower)) return true;
|
|
77
|
+
if (/chmod\s+(-[a-z]*r\s+)?777\s+(\/|~)/i.test(lower)) return true;
|
|
78
|
+
if (/curl\s+.*\|\s*(bash|sh|sudo)/i.test(lower)) return true;
|
|
79
|
+
if (/wget\s+.*\|\s*(bash|sh|sudo)/i.test(lower)) return true;
|
|
80
|
+
const patterns = ['rm -rf /', 'rm -rf ~', 'rm -rf *', 'rm -rf .', 'mkfs', 'dd if=', 'drop database', 'truncate table'];
|
|
81
|
+
return patterns.some(p => lower.includes(p));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Handle an incoming authorized message.
|
|
86
|
+
*/
|
|
87
|
+
async function handleMessage(msg) {
|
|
88
|
+
if (!msg || !msg.text) return;
|
|
89
|
+
|
|
90
|
+
const cfg = configModule.getTelegramConfig();
|
|
91
|
+
const allowedChatId = String(cfg.chat_id || '').trim();
|
|
92
|
+
const incomingChatId = String(msg.chat?.id || '').trim();
|
|
93
|
+
if (!allowedChatId || incomingChatId !== allowedChatId) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const rawText = msg.text.trim();
|
|
98
|
+
const chatId = msg.chat.id;
|
|
99
|
+
|
|
100
|
+
if (rawText.startsWith('/help') || rawText.startsWith('/start')) {
|
|
101
|
+
const helpText = [
|
|
102
|
+
'<b>🏯 [KONOHA TELEGRAM BOT ACTIVE]</b>',
|
|
103
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
104
|
+
'Welcome to Konoha Village Remote Ingress.',
|
|
105
|
+
'',
|
|
106
|
+
'<b>📋 Commands:</b>',
|
|
107
|
+
'• <b>/session [number]</b> - View or switch target client session (or /session create <client> <path>)',
|
|
108
|
+
'• <b>/run <task></b> - Queue coding task for autonomous execution',
|
|
109
|
+
'• <b>/sh <cmd></b> - Execute shell command in target workspace',
|
|
110
|
+
'• <b>/status</b> - View workspace status and pending tasks',
|
|
111
|
+
'• <b>/savings</b> - View token reduction telemetry',
|
|
112
|
+
'• <b>/cancel</b> - Cancel pending queued task',
|
|
113
|
+
'• <b>/help</b> - Show this command reference',
|
|
114
|
+
'',
|
|
115
|
+
'<b>🥷 Subagent Direct Dispatch:</b>',
|
|
116
|
+
'• <b>/kage <prompt></b> - Village Leader (Architecture & security audit)',
|
|
117
|
+
'• <b>/anbu <prompt></b> - Black Ops (Backend, DevOps, bug fixing)',
|
|
118
|
+
'• <b>/jonin <prompt></b> - Elite Builder (UI/UX, frontend components)',
|
|
119
|
+
'• <b>/genin <prompt></b> - Scout (Codebase exploration & analysis)',
|
|
120
|
+
'• <b>/chunin <prompt></b> - Intel Ninja (Web research & docs synthesis)',
|
|
121
|
+
'• <b>/tokubetsu_jonin <prompt></b> - Scribe (Tech docs, specs & reports)',
|
|
122
|
+
'• <b>/sannin <prompt></b> - Master Orchestrator (Triage & planning)',
|
|
123
|
+
'',
|
|
124
|
+
'<i>You can also send any plain message directly to queue it as a prompt.</i>',
|
|
125
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
126
|
+
].join('\n');
|
|
127
|
+
await notifierModule.sendTelegramMessage(helpText, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (rawText.startsWith('/session')) {
|
|
132
|
+
const arg = rawText.replace(/^\/session(?:@\w+)?\s*/i, '').trim();
|
|
133
|
+
if (!arg || arg === 'list' || arg === 'ls') {
|
|
134
|
+
const listText = sessionManager.formatSessionList(chatId);
|
|
135
|
+
await notifierModule.sendTelegramMessage(listText, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const isCreate = /^create\b/i.test(arg);
|
|
140
|
+
const isAdd = /^add\b/i.test(arg);
|
|
141
|
+
if (isCreate || isAdd) {
|
|
142
|
+
const sub = arg.replace(/^(create|add)\s*/i, '').trim();
|
|
143
|
+
if (!sub) {
|
|
144
|
+
const helpMsg = [
|
|
145
|
+
'<b>⚠️ [MISSING ARGUMENTS]</b>',
|
|
146
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
147
|
+
'<b>Usage:</b> <code>/session create <client> <path></code>',
|
|
148
|
+
'<b>Clients:</b> <code>agy, antigravity, claude, codex, pi, opencode, commandcode</code>',
|
|
149
|
+
'<b>Example:</b> <code>/session create agy /home/user/myproject</code>',
|
|
150
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
151
|
+
].join('\n');
|
|
152
|
+
await notifierModule.sendTelegramMessage(helpMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const match = sub.match(/^([^\s]+)\s+(.+)$/);
|
|
157
|
+
if (!match) {
|
|
158
|
+
const helpMsg = [
|
|
159
|
+
'<b>⚠️ [MISSING WORKSPACE PATH]</b>',
|
|
160
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
161
|
+
`<b>Message:</b> Client "${sub}" specified, but workspace directory path is missing.`,
|
|
162
|
+
'<b>Usage:</b> <code>/session create <client> <path></code>',
|
|
163
|
+
'<b>Clients:</b> <code>agy, antigravity, claude, codex, pi, opencode, commandcode</code>',
|
|
164
|
+
'<b>Example:</b> <code>/session create agy /home/user/myproject</code>',
|
|
165
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
166
|
+
].join('\n');
|
|
167
|
+
await notifierModule.sendTelegramMessage(helpMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const clientArg = match[1].trim();
|
|
172
|
+
const pathArg = match[2].trim();
|
|
173
|
+
const createRes = sessionManager.createSession(chatId, clientArg, pathArg);
|
|
174
|
+
if (createRes.success) {
|
|
175
|
+
const sess = createRes.session;
|
|
176
|
+
const clientName = sessionManager.CLIENT_DISPLAY_NAMES[sess.client.toLowerCase()] || sess.client;
|
|
177
|
+
const confirmMsg = [
|
|
178
|
+
'<b>🎛️ [SESSION CREATED & TARGETED]</b>',
|
|
179
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
180
|
+
`<b>💻 Target Client:</b> ${clientName}`,
|
|
181
|
+
`<b>📂 Workspace Root:</b> <code>${sess.workspace_root}</code>`,
|
|
182
|
+
`<b>🔖 Session ID:</b> <code>${sess.session_id}</code>`,
|
|
183
|
+
`<b>🔢 Session Index:</b> <code>#${createRes.index}</code> (of ${createRes.totalSessions})`,
|
|
184
|
+
'<b>⚡ Status:</b> Active for all subsequent /run and /sh commands',
|
|
185
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
186
|
+
].join('\n');
|
|
187
|
+
await notifierModule.sendTelegramMessage(confirmMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
188
|
+
} else {
|
|
189
|
+
const errReply = [
|
|
190
|
+
'<b>⚠️ [SESSION CREATION ERROR]</b>',
|
|
191
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
192
|
+
`<b>Message:</b> ${createRes.error}`,
|
|
193
|
+
'<b>Usage:</b> <code>/session create <client> <path></code>',
|
|
194
|
+
'<b>Clients:</b> <code>agy, antigravity, claude, codex, pi, opencode, commandcode</code>',
|
|
195
|
+
'<b>Example:</b> <code>/session create agy /home/user/myproject</code>',
|
|
196
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
197
|
+
].join('\n');
|
|
198
|
+
await notifierModule.sendTelegramMessage(errReply, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const setRes = sessionManager.setTargetSession(chatId, arg);
|
|
204
|
+
if (setRes.success) {
|
|
205
|
+
const sess = setRes.session;
|
|
206
|
+
const clientName = sessionManager.CLIENT_DISPLAY_NAMES[sess.client.toLowerCase()] || sess.client;
|
|
207
|
+
const confirmMsg = [
|
|
208
|
+
'<b>🎛️ [TARGET SESSION UPDATED]</b>',
|
|
209
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
210
|
+
`<b>💻 Target Client:</b> ${clientName}`,
|
|
211
|
+
`<b>📂 Workspace Root:</b> <code>${sess.workspace_root}</code>`,
|
|
212
|
+
`<b>🔖 Session ID:</b> <code>${sess.session_id}</code>`,
|
|
213
|
+
'<b>⚡ Status:</b> Active for all subsequent /run and /sh commands',
|
|
214
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
215
|
+
].join('\n');
|
|
216
|
+
await notifierModule.sendTelegramMessage(confirmMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
217
|
+
} else {
|
|
218
|
+
const errReply = [
|
|
219
|
+
'<b>⚠️ [INVALID SESSION NUMBER]</b>',
|
|
220
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
221
|
+
`<b>Message:</b> ${setRes.error}`,
|
|
222
|
+
'<b>Usage:</b> <code>/session <number></code>',
|
|
223
|
+
'<b>Example:</b> <code>/session 1</code> or <code>/session 2</code>',
|
|
224
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
225
|
+
].join('\n');
|
|
226
|
+
await notifierModule.sendTelegramMessage(errReply, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
227
|
+
}
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (/^\/(sh|exec)(\s+.*|@\S+.*)?$/i.test(rawText)) {
|
|
232
|
+
const cmd = rawText.replace(/^\/(sh|exec)(@[^\s]+)?\s*/i, '').trim();
|
|
233
|
+
if (!cmd) {
|
|
234
|
+
const errMsg = [
|
|
235
|
+
'<b>⚠️ [ERROR] Empty Command</b>',
|
|
236
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
237
|
+
'<b>Message:</b> Empty command received.',
|
|
238
|
+
'<b>Usage:</b> <code>/sh <command></code>',
|
|
239
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
240
|
+
].join('\n');
|
|
241
|
+
await notifierModule.sendTelegramMessage(errMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (isDangerousCommand(cmd)) {
|
|
245
|
+
const blockedMsg = [
|
|
246
|
+
'<b>🛡️ [BLOCKED] Security Guardrail</b>',
|
|
247
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
248
|
+
'<b>Status:</b> BLOCKED',
|
|
249
|
+
'<b>Reason:</b> Dangerous command blocked by security guardrails.',
|
|
250
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
251
|
+
].join('\n');
|
|
252
|
+
await notifierModule.sendTelegramMessage(blockedMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const { execFile } = require('child_process');
|
|
257
|
+
const targetSession = sessionManager.getTargetSession(chatId);
|
|
258
|
+
const execCwd = (targetSession.workspace_root && fs.existsSync(targetSession.workspace_root))
|
|
259
|
+
? targetSession.workspace_root
|
|
260
|
+
: process.cwd();
|
|
261
|
+
const clientName = sessionManager.CLIENT_DISPLAY_NAMES[targetSession.client.toLowerCase()] || targetSession.client;
|
|
262
|
+
|
|
263
|
+
const userShell = (process.env.SHELL && fs.existsSync(process.env.SHELL))
|
|
264
|
+
? process.env.SHELL
|
|
265
|
+
: (fs.existsSync('/bin/bash') ? '/bin/bash' : '/bin/sh');
|
|
266
|
+
|
|
267
|
+
await notifierModule.sendTelegramMessage(`⚙️ Executing in <code>${execCwd}</code> (${clientName}):\n<code>${escapeHtml(cmd)}</code>`, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
268
|
+
execFile(userShell, ['-i', '-c', cmd], { cwd: execCwd, timeout: 600000, maxBuffer: 1024 * 1024, env: { ...process.env, SHELL: userShell } }, async (err, stdout, stderr) => {
|
|
269
|
+
const cleanStdout = sanitizeShellOutput(stdout);
|
|
270
|
+
const cleanStderr = sanitizeShellOutput(stderr);
|
|
271
|
+
const combined = [cleanStdout, cleanStderr].filter(Boolean).join('\n').trim();
|
|
272
|
+
const output = combined || (err ? err.message : '');
|
|
273
|
+
const statusIcon = err ? '❌ [FAILED]' : '✅ [SUCCESS]';
|
|
274
|
+
const cleanOut = output ? (output.length > 3500 ? output.slice(0, 3500) + '\n...[truncated]' : output) : '(Command completed with 0 output)';
|
|
275
|
+
const formattedOut = cleanOut === '(Command completed with 0 output)'
|
|
276
|
+
? '<i>(Command completed with 0 output)</i>'
|
|
277
|
+
: `<pre>${escapeHtml(cleanOut)}</pre>`;
|
|
278
|
+
const reply = [
|
|
279
|
+
`<b>🏯 ${statusIcon}</b>`,
|
|
280
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
281
|
+
`<b>📂 Workspace:</b> <code>${execCwd}</code>`,
|
|
282
|
+
formattedOut,
|
|
283
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
284
|
+
].join('\n');
|
|
285
|
+
await notifierModule.sendTelegramMessage(reply, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
286
|
+
});
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (rawText.startsWith('/status')) {
|
|
291
|
+
const recent = inboxModule.listPrompts({ limit: 5 });
|
|
292
|
+
if (recent.length === 0) {
|
|
293
|
+
const idleMsg = [
|
|
294
|
+
'<b>Status Recent Task</b>',
|
|
295
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
296
|
+
'<b>Workspace Status:</b> IDLE',
|
|
297
|
+
'No active or queued tasks.',
|
|
298
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
299
|
+
].join('\n');
|
|
300
|
+
await notifierModule.sendTelegramMessage(idleMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const lines = [
|
|
304
|
+
'<b>Status Recent Task</b>',
|
|
305
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
306
|
+
];
|
|
307
|
+
recent.forEach((p, idx) => {
|
|
308
|
+
let displayStatus = (p.status || 'pending').toLowerCase();
|
|
309
|
+
if (displayStatus === 'processing') {
|
|
310
|
+
displayStatus = 'running';
|
|
311
|
+
}
|
|
312
|
+
lines.push(`<b>${idx + 1}. Task ID:</b> <code>${p.id}</code>`);
|
|
313
|
+
lines.push(` <b>Status:</b> ${displayStatus}`);
|
|
314
|
+
lines.push(` <b>Source:</b> ${p.source}`);
|
|
315
|
+
lines.push(` <b>Prompt:</b> ${p.prompt.length > 60 ? p.prompt.slice(0, 60) + '...' : p.prompt}`);
|
|
316
|
+
if (p.result_summary) {
|
|
317
|
+
lines.push(` <b>Result:</b> ${p.result_summary.length > 80 ? p.result_summary.slice(0, 80) + '...' : p.result_summary}`);
|
|
318
|
+
}
|
|
319
|
+
lines.push('────────────────────────────');
|
|
320
|
+
});
|
|
321
|
+
lines.push('━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
322
|
+
await notifierModule.sendTelegramMessage(lines.join('\n'), { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (rawText.startsWith('/savings')) {
|
|
327
|
+
const text = [
|
|
328
|
+
'<b>💎 [TOKEN TELEMETRY BENCHMARK]</b>',
|
|
329
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
330
|
+
'<b>Target Reduction:</b> 83% - 98% Saved',
|
|
331
|
+
'<b>Status:</b> Active across all coding agents',
|
|
332
|
+
'<b>Telemetry Engine:</b> Bounded file tools & SQLite FTS5 index active',
|
|
333
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
334
|
+
].join('\n');
|
|
335
|
+
await notifierModule.sendTelegramMessage(text, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (rawText.startsWith('/cancel')) {
|
|
340
|
+
const pending = inboxModule.getNextPendingPrompt();
|
|
341
|
+
if (pending) {
|
|
342
|
+
inboxModule.completePrompt(pending.id, { status: 'cancelled', result_summary: 'Cancelled from Telegram' });
|
|
343
|
+
const cancelMsg = [
|
|
344
|
+
`<b>🚫 [CANCELLED] Task ${pending.id}</b>`,
|
|
345
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
346
|
+
`<b>🔖 Task ID:</b> <code>${pending.id}</code>`,
|
|
347
|
+
'<b>📊 Status:</b> cancelled',
|
|
348
|
+
'<b>⚡ Detail:</b> Task cancelled from Telegram',
|
|
349
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
350
|
+
].join('\n');
|
|
351
|
+
await notifierModule.sendTelegramMessage(cancelMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
352
|
+
} else {
|
|
353
|
+
const noCancelMsg = [
|
|
354
|
+
'<b>🚫 [CANCEL] Notice</b>',
|
|
355
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
356
|
+
'<b>Notice:</b> No pending task found in queue to cancel.',
|
|
357
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
358
|
+
].join('\n');
|
|
359
|
+
await notifierModule.sendTelegramMessage(noCancelMsg, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
360
|
+
}
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Subagent Direct Dispatch: /kage, /anbu, /jonin, /genin, /chunin, /tokubetsu_jonin, /sannin
|
|
365
|
+
const AGENT_SUBCOMMANDS = {
|
|
366
|
+
kage: { name: 'Village Leader Kage', defaultPrompt: 'Execute Kage architecture and security risk assessment review on current workspace', icon: '🛡️' },
|
|
367
|
+
anbu: { name: 'Black Ops Anbu', defaultPrompt: 'Execute Anbu backend development, bug fixing, and infrastructure hardening', icon: '♠️' },
|
|
368
|
+
jonin: { name: 'Elite Builder Jonin', defaultPrompt: 'Execute Jonin UI/UX design matching and component development', icon: '♦️' },
|
|
369
|
+
genin: { name: 'Scout Genin', defaultPrompt: 'Execute Genin codebase exploration, symbol search, and dependency analysis', icon: '⚑' },
|
|
370
|
+
chunin: { name: 'Intel Ninja Chunin', defaultPrompt: 'Execute Chunin web research, documentation lookup, and synthesis', icon: '▫️' },
|
|
371
|
+
'tokubetsu-jonin': { name: 'Scribe Tokubetsu Jonin', defaultPrompt: 'Execute Tokubetsu Jonin technical documentation and report generation', icon: '⬡' },
|
|
372
|
+
sannin: { name: 'Master Orchestrator Sannin', defaultPrompt: 'Execute Sannin task triage and multi-agent workflow orchestration', icon: '✧' }
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const agentMatch = rawText.match(/^\/(kage|anbu|jonin|genin|chunin|tokubetsu[-_]jonin|sannin)(?:@\w+)?(?:\s+([\s\S]*))?$/i);
|
|
376
|
+
if (agentMatch) {
|
|
377
|
+
const rawAgentKey = agentMatch[1].toLowerCase().replace('_', '-');
|
|
378
|
+
const agentInfo = AGENT_SUBCOMMANDS[rawAgentKey];
|
|
379
|
+
const userPrompt = (agentMatch[2] || '').trim();
|
|
380
|
+
const finalPrompt = userPrompt || agentInfo.defaultPrompt;
|
|
381
|
+
const targetSession = sessionManager.getTargetSession(chatId);
|
|
382
|
+
|
|
383
|
+
const task = inboxModule.enqueuePrompt({
|
|
384
|
+
prompt: `/${rawAgentKey} ${finalPrompt}`,
|
|
385
|
+
source: 'telegram',
|
|
386
|
+
sender_info: msg.from?.username || String(chatId),
|
|
387
|
+
session_id: targetSession.session_id,
|
|
388
|
+
workspace_root: targetSession.workspace_root,
|
|
389
|
+
client: targetSession.client
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
const clientDisplay = sessionManager.CLIENT_DISPLAY_NAMES[targetSession.client.toLowerCase()] || targetSession.client;
|
|
393
|
+
const reply = [
|
|
394
|
+
`<b>${agentInfo.icon} [QUEUED #${task.id}] Task Dispatched to ${agentInfo.name}</b>`,
|
|
395
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
396
|
+
`<b>🔖 Task ID:</b> <code>${task.id}</code>`,
|
|
397
|
+
`<b>📋 Prompt:</b> ${finalPrompt.length > 100 ? finalPrompt.slice(0, 100) + '...' : finalPrompt}`,
|
|
398
|
+
`<b>💻 Target Client:</b> ${clientDisplay}`,
|
|
399
|
+
`<b>📂 Workspace:</b> <code>${targetSession.workspace_root}</code>`,
|
|
400
|
+
'<b>📊 Status:</b> pending',
|
|
401
|
+
`<b>⚡ Routing:</b> Direct dispatch to ${agentInfo.name}`,
|
|
402
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
403
|
+
].join('\n');
|
|
404
|
+
await notifierModule.sendTelegramMessage(reply, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Handle /run <prompt> or plain text prompt
|
|
409
|
+
let promptText = rawText;
|
|
410
|
+
if (promptText.startsWith('/run ')) {
|
|
411
|
+
promptText = promptText.slice(5).trim();
|
|
412
|
+
} else if (promptText.startsWith('/run@')) {
|
|
413
|
+
promptText = promptText.replace(/^\/run@[^\s]+\s*/, '').trim();
|
|
414
|
+
} else if (promptText === '/run' || promptText.startsWith('/run@')) {
|
|
415
|
+
promptText = '';
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (!promptText) {
|
|
419
|
+
const emptyErr = [
|
|
420
|
+
'<b>⚠️ [ERROR] Empty prompt received</b>',
|
|
421
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
422
|
+
'<b>Message:</b> Empty prompt received.',
|
|
423
|
+
'<b>Usage:</b> <code>/run <task description></code>',
|
|
424
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
425
|
+
].join('\n');
|
|
426
|
+
await notifierModule.sendTelegramMessage(emptyErr, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const targetSession = sessionManager.getTargetSession(chatId);
|
|
431
|
+
const task = inboxModule.enqueuePrompt({
|
|
432
|
+
prompt: promptText,
|
|
433
|
+
source: 'telegram',
|
|
434
|
+
sender_info: msg.from?.username || String(chatId),
|
|
435
|
+
session_id: targetSession.session_id,
|
|
436
|
+
workspace_root: targetSession.workspace_root,
|
|
437
|
+
client: targetSession.client
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
const clientDisplay = sessionManager.CLIENT_DISPLAY_NAMES[targetSession.client.toLowerCase()] || targetSession.client;
|
|
441
|
+
const reply = [
|
|
442
|
+
`<b>⏳ [QUEUED #${task.id}] Task Accepted</b>`,
|
|
443
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━',
|
|
444
|
+
`<b>🔖 Task ID:</b> <code>${task.id}</code>`,
|
|
445
|
+
`<b>📋 Prompt:</b> ${promptText.length > 100 ? promptText.slice(0, 100) + '...' : promptText}`,
|
|
446
|
+
`<b>💻 Target Client:</b> ${clientDisplay}`,
|
|
447
|
+
`<b>📂 Workspace:</b> <code>${targetSession.workspace_root}</code>`,
|
|
448
|
+
'<b>📊 Status:</b> pending',
|
|
449
|
+
'<b>⚡ Queue:</b> Dispatched to Autonomous Worker',
|
|
450
|
+
'━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
|
|
451
|
+
].join('\n');
|
|
452
|
+
|
|
453
|
+
await notifierModule.sendTelegramMessage(reply, { force: true, chat_id: chatId, parse_mode: 'HTML' });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Execute a single poll request.
|
|
458
|
+
*/
|
|
459
|
+
async function pollOnce(token, timeout = 30) {
|
|
460
|
+
const url = `https://api.telegram.org/bot${token}/getUpdates?offset=${currentOffset}&timeout=${timeout}`;
|
|
461
|
+
try {
|
|
462
|
+
const res = await fetch(url, {
|
|
463
|
+
method: 'GET',
|
|
464
|
+
signal: AbortSignal.timeout((timeout + 15) * 1000)
|
|
465
|
+
});
|
|
466
|
+
const data = await res.json();
|
|
467
|
+
if (!data.ok || !Array.isArray(data.result)) {
|
|
468
|
+
if (data && !data.ok) {
|
|
469
|
+
process.stderr.write(`[telegram poller] getUpdates API error: ${data.description || 'Unknown error'}\n`);
|
|
470
|
+
}
|
|
471
|
+
return [];
|
|
472
|
+
}
|
|
473
|
+
return data.result;
|
|
474
|
+
} catch (err) {
|
|
475
|
+
if (err.name !== 'TimeoutError' && !err.message.includes('aborted')) {
|
|
476
|
+
process.stderr.write(`[telegram poller] Polling fetch error: ${err.message}\n`);
|
|
477
|
+
}
|
|
478
|
+
return [];
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Start the polling loop.
|
|
484
|
+
*/
|
|
485
|
+
function startPoller() {
|
|
486
|
+
if (isRunning) return;
|
|
487
|
+
const config = configModule.getTelegramConfig();
|
|
488
|
+
|
|
489
|
+
if (!config.enabled || config.mode !== 'two_way' || !config.bot_token) {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
isRunning = true;
|
|
494
|
+
shouldStop = false;
|
|
495
|
+
|
|
496
|
+
_pollLoopPromise = (async () => {
|
|
497
|
+
while (!shouldStop) {
|
|
498
|
+
const cfg = configModule.getTelegramConfig();
|
|
499
|
+
if (!cfg.enabled || cfg.mode !== 'two_way' || !cfg.bot_token) {
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const updates = await pollOnce(cfg.bot_token, 15);
|
|
504
|
+
for (const update of updates) {
|
|
505
|
+
if (update.update_id >= currentOffset) {
|
|
506
|
+
currentOffset = update.update_id + 1;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const msg = update.message;
|
|
510
|
+
if (!msg) continue;
|
|
511
|
+
|
|
512
|
+
// Enforce strict chat_id whitelist with non-empty validation
|
|
513
|
+
const allowedChatId = String(cfg.chat_id || '').trim();
|
|
514
|
+
if (!allowedChatId || String(msg.chat.id).trim() !== allowedChatId) {
|
|
515
|
+
process.stderr.write(`[telegram poller] Dropped message from unauthorized chat ID: ${msg.chat?.id}\n`);
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
try {
|
|
520
|
+
process.stdout.write(`[telegram poller] Processing message #${update.update_id} from @${msg.from?.username || msg.chat.id}: "${(msg.text || '').slice(0, 60)}"\n`);
|
|
521
|
+
await handleMessage(msg);
|
|
522
|
+
} catch (handleErr) {
|
|
523
|
+
process.stderr.write(`[telegram poller] Message handling error: ${handleErr.message}\n`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (shouldStop) break;
|
|
528
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
529
|
+
}
|
|
530
|
+
isRunning = false;
|
|
531
|
+
})();
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Stop polling loop.
|
|
536
|
+
*/
|
|
537
|
+
function stopPoller() {
|
|
538
|
+
shouldStop = true;
|
|
539
|
+
isRunning = false;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
module.exports = {
|
|
543
|
+
isPollerRunning,
|
|
544
|
+
startPoller,
|
|
545
|
+
stopPoller,
|
|
546
|
+
pollOnce,
|
|
547
|
+
handleMessage
|
|
548
|
+
};
|