@shareai-lab/kode 2.0.1 → 2.0.3
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/LICENSE +201 -0
- package/README.md +649 -25
- package/README.zh-CN.md +579 -0
- package/cli-acp.js +3 -17
- package/cli.js +5 -7
- package/dist/chunks/Doctor-M3J7GRTJ.js +12 -0
- package/dist/chunks/LogList-ISWZ6DDD.js +121 -0
- package/dist/chunks/LogList-ISWZ6DDD.js.map +7 -0
- package/dist/chunks/REPL-RQ6LO6S7.js +56 -0
- package/dist/chunks/ResumeConversation-6DMVBEGH.js +56 -0
- package/dist/chunks/agentLoader-FCRG3TFJ.js +31 -0
- package/dist/{agentsValidate-7LH4HTNR.js → chunks/agentsValidate-PEWMYN4Q.js} +97 -69
- package/dist/chunks/agentsValidate-PEWMYN4Q.js.map +7 -0
- package/dist/{ask-3NHFFUQG.js → chunks/ask-D7SOHJ6Z.js} +36 -44
- package/dist/chunks/ask-D7SOHJ6Z.js.map +7 -0
- package/dist/chunks/autoUpdater-CNESBOKO.js +19 -0
- package/dist/{chunk-AFFSCMYS.js → chunks/chunk-2JN5MY67.js} +12 -14
- package/dist/chunks/chunk-2JN5MY67.js.map +7 -0
- package/dist/chunks/chunk-2QONJ5MG.js +14 -0
- package/dist/chunks/chunk-2QONJ5MG.js.map +7 -0
- package/dist/chunks/chunk-2WEXPKHH.js +903 -0
- package/dist/chunks/chunk-2WEXPKHH.js.map +7 -0
- package/dist/{chunk-ARZSBOAO.js → chunks/chunk-3BYE3ME6.js} +717 -792
- package/dist/chunks/chunk-3BYE3ME6.js.map +7 -0
- package/dist/chunks/chunk-3JDNWX7W.js +1264 -0
- package/dist/chunks/chunk-3JDNWX7W.js.map +7 -0
- package/dist/chunks/chunk-3OEJVB5A.js +906 -0
- package/dist/chunks/chunk-3OEJVB5A.js.map +7 -0
- package/dist/chunks/chunk-3TNIOEBO.js +369 -0
- package/dist/chunks/chunk-3TNIOEBO.js.map +7 -0
- package/dist/chunks/chunk-4A46ZXMJ.js +67 -0
- package/dist/chunks/chunk-4A46ZXMJ.js.map +7 -0
- package/dist/{chunk-UHYRLID6.js → chunks/chunk-4ATBQOFO.js} +107 -55
- package/dist/chunks/chunk-4ATBQOFO.js.map +7 -0
- package/dist/chunks/chunk-4CRUCZR4.js +0 -0
- package/dist/{chunk-YC6LJCDE.js → chunks/chunk-4EO6SIQY.js} +32 -75
- package/dist/chunks/chunk-4EO6SIQY.js.map +7 -0
- package/dist/chunks/chunk-53M46S5I.js +64 -0
- package/dist/chunks/chunk-53M46S5I.js.map +7 -0
- package/dist/{chunk-JC6NCUG5.js → chunks/chunk-54KOYG5C.js} +0 -2
- package/dist/{chunk-EZXMVTDU.js → chunks/chunk-6BAS4WY6.js} +29 -45
- package/dist/chunks/chunk-6BAS4WY6.js.map +7 -0
- package/dist/{chunk-3IN27HA5.js → chunks/chunk-6KRRFSDN.js} +4 -6
- package/dist/chunks/chunk-6KRRFSDN.js.map +7 -0
- package/dist/chunks/chunk-6LJNZK4K.js +39 -0
- package/dist/chunks/chunk-6LJNZK4K.js.map +7 -0
- package/dist/chunks/chunk-6ZWEOSEI.js +666 -0
- package/dist/chunks/chunk-6ZWEOSEI.js.map +7 -0
- package/dist/chunks/chunk-77XDJMBP.js +3326 -0
- package/dist/chunks/chunk-77XDJMBP.js.map +7 -0
- package/dist/chunks/chunk-7RRW4NTB.js +6454 -0
- package/dist/chunks/chunk-7RRW4NTB.js.map +7 -0
- package/dist/chunks/chunk-7X3TW4JB.js +4520 -0
- package/dist/chunks/chunk-7X3TW4JB.js.map +7 -0
- package/dist/chunks/chunk-B3MW3YGY.js +1409 -0
- package/dist/chunks/chunk-B3MW3YGY.js.map +7 -0
- package/dist/chunks/chunk-BBJFHTBC.js +28 -0
- package/dist/chunks/chunk-BBJFHTBC.js.map +7 -0
- package/dist/chunks/chunk-BHDHXOXB.js +24 -0
- package/dist/chunks/chunk-BHDHXOXB.js.map +7 -0
- package/dist/{chunk-73WGVYLQ.js → chunks/chunk-BTA7SZ26.js} +152 -223
- package/dist/chunks/chunk-BTA7SZ26.js.map +7 -0
- package/dist/chunks/chunk-CDGRYGPZ.js +103 -0
- package/dist/chunks/chunk-CDGRYGPZ.js.map +7 -0
- package/dist/{chunk-S6HRABTA.js → chunks/chunk-CP6E5UG6.js} +1 -4
- package/dist/chunks/chunk-CP6E5UG6.js.map +7 -0
- package/dist/{chunk-QVLYOPO5.js → chunks/chunk-DQ4JHXMT.js} +462 -424
- package/dist/chunks/chunk-DQ4JHXMT.js.map +7 -0
- package/dist/chunks/chunk-DXD76CMV.js +208 -0
- package/dist/chunks/chunk-DXD76CMV.js.map +7 -0
- package/dist/chunks/chunk-GCQCAXJZ.js +0 -0
- package/dist/chunks/chunk-GELCZWMB.js +42 -0
- package/dist/chunks/chunk-GELCZWMB.js.map +7 -0
- package/dist/{chunk-K2CWOTI2.js → chunks/chunk-HJYOH4HC.js} +23 -18
- package/dist/chunks/chunk-HJYOH4HC.js.map +7 -0
- package/dist/chunks/chunk-HPYNW6TT.js +744 -0
- package/dist/chunks/chunk-HPYNW6TT.js.map +7 -0
- package/dist/{chunk-RZWOUA25.js → chunks/chunk-HRJ3ICQK.js} +59 -55
- package/dist/chunks/chunk-HRJ3ICQK.js.map +7 -0
- package/dist/{chunk-DZE5YA7L.js → chunks/chunk-IFCIADS3.js} +571 -573
- package/dist/chunks/chunk-IFCIADS3.js.map +7 -0
- package/dist/chunks/chunk-IN7XZ7BC.js +27 -0
- package/dist/chunks/chunk-IN7XZ7BC.js.map +7 -0
- package/dist/chunks/chunk-L7P4M4KW.js +193 -0
- package/dist/chunks/chunk-L7P4M4KW.js.map +7 -0
- package/dist/chunks/chunk-LB6TCPDI.js +0 -0
- package/dist/{chunk-3RUXVV4S.js → chunks/chunk-LOCXPQNJ.js} +1 -4
- package/dist/{chunk-3RUXVV4S.js.map → chunks/chunk-LOCXPQNJ.js.map} +2 -2
- package/dist/{chunk-7M2YN6TU.js → chunks/chunk-LOD5ZHCI.js} +213 -208
- package/dist/chunks/chunk-LOD5ZHCI.js.map +7 -0
- package/dist/{chunk-S3J2TLV6.js → chunks/chunk-M7P3QNRU.js} +1 -4
- package/dist/{chunk-S3J2TLV6.js.map → chunks/chunk-M7P3QNRU.js.map} +2 -2
- package/dist/chunks/chunk-PPHLQVL7.js +4234 -0
- package/dist/chunks/chunk-PPHLQVL7.js.map +7 -0
- package/dist/{chunk-ABLVTESJ.js → chunks/chunk-QAXE37B5.js} +1 -4
- package/dist/chunks/chunk-QAXE37B5.js.map +7 -0
- package/dist/chunks/chunk-QHQOBUF6.js +60 -0
- package/dist/chunks/chunk-QHQOBUF6.js.map +7 -0
- package/dist/{chunk-W7GRKO7Q.js → chunks/chunk-RPJXO7GG.js} +241 -214
- package/dist/chunks/chunk-RPJXO7GG.js.map +7 -0
- package/dist/{chunk-NPFOMITO.js → chunks/chunk-SWQV4KSY.js} +1 -4
- package/dist/{chunk-NPFOMITO.js.map → chunks/chunk-SWQV4KSY.js.map} +2 -2
- package/dist/chunks/chunk-SZLAPULP.js +28 -0
- package/dist/chunks/chunk-SZLAPULP.js.map +7 -0
- package/dist/{chunk-7U7L4NMD.js → chunks/chunk-T7RB5V5J.js} +23 -25
- package/dist/chunks/chunk-T7RB5V5J.js.map +7 -0
- package/dist/{chunk-HN4E4UUQ.js → chunks/chunk-TI2CTTMA.js} +25 -17
- package/dist/chunks/chunk-TI2CTTMA.js.map +7 -0
- package/dist/{chunk-ZVDRDPII.js → chunks/chunk-TNGVRTO5.js} +45 -20
- package/dist/chunks/chunk-TNGVRTO5.js.map +7 -0
- package/dist/chunks/chunk-TNWB3U5Y.js +2077 -0
- package/dist/chunks/chunk-TNWB3U5Y.js.map +7 -0
- package/dist/chunks/chunk-U2IHWPCU.js +12 -0
- package/dist/chunks/chunk-U2IHWPCU.js.map +7 -0
- package/dist/{chunk-KAA5BGMQ.js → chunks/chunk-UNOY3VJ2.js} +1 -4
- package/dist/{chunk-KAA5BGMQ.js.map → chunks/chunk-UNOY3VJ2.js.map} +2 -2
- package/dist/{chunk-MWRSY4X6.js → chunks/chunk-UVDJL6ZZ.js} +97 -58
- package/dist/chunks/chunk-UVDJL6ZZ.js.map +7 -0
- package/dist/chunks/chunk-VNCW4C2Z.js +13452 -0
- package/dist/chunks/chunk-VNCW4C2Z.js.map +7 -0
- package/dist/chunks/chunk-W5EGGA44.js +15 -0
- package/dist/chunks/chunk-W5EGGA44.js.map +7 -0
- package/dist/chunks/chunk-XR2W3MAM.js +1533 -0
- package/dist/chunks/chunk-XR2W3MAM.js.map +7 -0
- package/dist/{chunk-STSX7GIX.js → chunks/chunk-YIO5EBMQ.js} +423 -377
- package/dist/chunks/chunk-YIO5EBMQ.js.map +7 -0
- package/dist/chunks/chunk-ZBVLKZ5V.js +1062 -0
- package/dist/chunks/chunk-ZBVLKZ5V.js.map +7 -0
- package/dist/{chunk-E6YNABER.js → chunks/chunk-ZCLTZIVP.js} +1 -4
- package/dist/chunks/chunk-ZCLTZIVP.js.map +7 -0
- package/dist/chunks/client-SILZNM5N.js +42 -0
- package/dist/{config-RUSD6G5Y.js → chunks/config-25HRTPSP.js} +48 -10
- package/dist/chunks/cost-tracker-Z2UZT2J5.js +28 -0
- package/dist/{customCommands-TOIJFZAL.js → chunks/customCommands-TYMYZRG5.js} +11 -8
- package/dist/chunks/engine-MRVF6FK6.js +39 -0
- package/dist/{env-XGKBLU3D.js → chunks/env-TJ5NOBEB.js} +7 -5
- package/dist/{kodeAgentSessionId-X6XWQW7B.js → chunks/kodeAgentSessionId-VTNISJ2L.js} +2 -4
- package/dist/chunks/kodeAgentSessionLoad-YB2RKBGJ.js +15 -0
- package/dist/chunks/kodeAgentSessionResume-DZSIVKVA.js +13 -0
- package/dist/chunks/kodeAgentStreamJson-X5PLS2S6.js +11 -0
- package/dist/{kodeAgentStreamJsonSession-UGEZJJEB.js → chunks/kodeAgentStreamJsonSession-RDXM4XYF.js} +38 -24
- package/dist/chunks/kodeAgentStreamJsonSession-RDXM4XYF.js.map +7 -0
- package/dist/{chunk-4RTX4AG4.js → chunks/kodeAgentStructuredStdio-SVGDSB4P.js} +14 -9
- package/dist/chunks/kodeAgentStructuredStdio-SVGDSB4P.js.map +7 -0
- package/dist/{kodeHooks-QWM36A3D.js → chunks/kodeHooks-RVKYRJHG.js} +11 -9
- package/dist/{llm-ZUQC4WYM.js → chunks/llm-62N6T5ZT.js} +1734 -1526
- package/dist/chunks/llm-62N6T5ZT.js.map +7 -0
- package/dist/chunks/llmLazy-ZUSSE3ZA.js +13 -0
- package/dist/{mentionProcessor-EE3XFHCJ.js → chunks/mentionProcessor-RJW5UPJD.js} +46 -16
- package/dist/chunks/mentionProcessor-RJW5UPJD.js.map +7 -0
- package/dist/{messages-EOYQKPGM.js → chunks/messages-EEWWLPHN.js} +2 -6
- package/dist/chunks/model-5TIEKQPD.js +37 -0
- package/dist/{openai-RRCWW33N.js → chunks/openai-XXK3YZG4.js} +13 -10
- package/dist/{outputStyles-62Q3VH2J.js → chunks/outputStyles-FAJTXN2A.js} +6 -9
- package/dist/chunks/permissions-HO7INPWM.js +27 -0
- package/dist/{pluginRuntime-6ETCZ2LL.js → chunks/pluginRuntime-C7K5ULK2.js} +31 -48
- package/dist/chunks/pluginRuntime-C7K5ULK2.js.map +7 -0
- package/dist/chunks/pluginValidation-DAM7WRTC.js +20 -0
- package/dist/chunks/registry-XYJXMOA5.js +60 -0
- package/dist/chunks/responsesStreaming-JNGE2P3D.js +8 -0
- package/dist/chunks/runNonTextPrintMode-SVBLCZQX.js +577 -0
- package/dist/chunks/runNonTextPrintMode-SVBLCZQX.js.map +7 -0
- package/dist/chunks/server-REXXF5IK.js +46 -0
- package/dist/{skillMarketplace-3RXQBVOL.js → chunks/skillMarketplace-N4HVHNST.js} +8 -6
- package/dist/chunks/src-OROQIWP3.js +44 -0
- package/dist/chunks/src-QXLGGMUW.js +1647 -0
- package/dist/chunks/src-QXLGGMUW.js.map +7 -0
- package/dist/{cli-DOPVY2CW.js → chunks/src-SSDT6MVP.js} +2659 -3384
- package/dist/chunks/src-SSDT6MVP.js.map +7 -0
- package/dist/chunks/theme-YBJUIMWK.js +10 -0
- package/dist/{toolPermissionContext-65L65VEZ.js → chunks/toolPermissionContext-MOCTRR7N.js} +2 -4
- package/dist/chunks/toolPermissionSettings-EV2EJAXL.js +18 -0
- package/dist/chunks/toolPermissionSettings-EV2EJAXL.js.map +7 -0
- package/dist/chunks/uuid-6577SO6X.js +7 -0
- package/dist/chunks/uuid-6577SO6X.js.map +7 -0
- package/dist/chunks/webOnlyMode-ALXX7UQY.js +66 -0
- package/dist/chunks/webOnlyMode-ALXX7UQY.js.map +7 -0
- package/dist/entrypoints/cli.js +10 -0
- package/dist/entrypoints/cli.js.map +7 -0
- package/dist/entrypoints/daemon.js +10 -0
- package/dist/entrypoints/daemon.js.map +7 -0
- package/dist/entrypoints/mcp.js +71 -0
- package/dist/entrypoints/mcp.js.map +7 -0
- package/dist/index.js +6 -7
- package/dist/index.js.map +3 -3
- package/dist/sdk/client.cjs +391 -0
- package/dist/sdk/client.cjs.map +7 -0
- package/dist/sdk/client.js +364 -0
- package/dist/sdk/client.js.map +7 -0
- package/dist/sdk/core.cjs +19932 -0
- package/dist/sdk/core.cjs.map +7 -0
- package/dist/sdk/core.js +19893 -0
- package/dist/sdk/core.js.map +7 -0
- package/dist/sdk/daemon-client.cjs +257 -0
- package/dist/sdk/daemon-client.cjs.map +7 -0
- package/dist/sdk/daemon-client.js +221 -0
- package/dist/sdk/daemon-client.js.map +7 -0
- package/dist/sdk/protocol.cjs +170 -0
- package/dist/sdk/protocol.cjs.map +7 -0
- package/dist/sdk/protocol.js +140 -0
- package/dist/sdk/protocol.js.map +7 -0
- package/dist/sdk/runtime-node.cjs +236 -0
- package/dist/sdk/runtime-node.cjs.map +7 -0
- package/dist/sdk/runtime-node.js +222 -0
- package/dist/sdk/runtime-node.js.map +7 -0
- package/dist/sdk/runtime.cjs +17 -0
- package/dist/sdk/runtime.cjs.map +7 -0
- package/dist/sdk/runtime.js +0 -0
- package/dist/sdk/runtime.js.map +7 -0
- package/dist/sdk/tools.cjs +30300 -0
- package/dist/sdk/tools.cjs.map +7 -0
- package/dist/sdk/tools.js +30282 -0
- package/dist/sdk/tools.js.map +7 -0
- package/dist/webui/assets/index-5hlfByVS.css +1 -0
- package/dist/webui/assets/index-BR9lm1lA.js +82 -0
- package/dist/webui/index.html +28 -0
- package/package.json +93 -22
- package/scripts/binary-utils.cjs +12 -4
- package/scripts/cli-acp-wrapper.cjs +3 -17
- package/scripts/cli-wrapper.cjs +5 -7
- package/scripts/postinstall.js +8 -4
- package/dist/REPL-CW7AYLVL.js +0 -42
- package/dist/acp-VEPJ74LT.js +0 -1357
- package/dist/acp-VEPJ74LT.js.map +0 -7
- package/dist/agentsValidate-7LH4HTNR.js.map +0 -7
- package/dist/ask-3NHFFUQG.js.map +0 -7
- package/dist/autoUpdater-ITPIHCOI.js +0 -17
- package/dist/chunk-3IN27HA5.js.map +0 -7
- package/dist/chunk-4FX3IVPT.js +0 -164
- package/dist/chunk-4FX3IVPT.js.map +0 -7
- package/dist/chunk-4RTX4AG4.js.map +0 -7
- package/dist/chunk-5PDP7R6N.js +0 -515
- package/dist/chunk-5PDP7R6N.js.map +0 -7
- package/dist/chunk-73WGVYLQ.js.map +0 -7
- package/dist/chunk-7M2YN6TU.js.map +0 -7
- package/dist/chunk-7U7L4NMD.js.map +0 -7
- package/dist/chunk-ABLVTESJ.js.map +0 -7
- package/dist/chunk-AFFSCMYS.js.map +0 -7
- package/dist/chunk-ARZSBOAO.js.map +0 -7
- package/dist/chunk-CIG63V4E.js +0 -72
- package/dist/chunk-CIG63V4E.js.map +0 -7
- package/dist/chunk-CM3EGTG6.js +0 -1609
- package/dist/chunk-CM3EGTG6.js.map +0 -7
- package/dist/chunk-DZE5YA7L.js.map +0 -7
- package/dist/chunk-E6YNABER.js.map +0 -7
- package/dist/chunk-EZXMVTDU.js.map +0 -7
- package/dist/chunk-F2SJXUDI.js +0 -148
- package/dist/chunk-F2SJXUDI.js.map +0 -7
- package/dist/chunk-FC5ZCKBI.js +0 -30167
- package/dist/chunk-FC5ZCKBI.js.map +0 -7
- package/dist/chunk-HCBELH4J.js +0 -145
- package/dist/chunk-HCBELH4J.js.map +0 -7
- package/dist/chunk-HN4E4UUQ.js.map +0 -7
- package/dist/chunk-IZVMU4S2.js +0 -654
- package/dist/chunk-IZVMU4S2.js.map +0 -7
- package/dist/chunk-K2CWOTI2.js.map +0 -7
- package/dist/chunk-LC4TVOCZ.js +0 -835
- package/dist/chunk-LC4TVOCZ.js.map +0 -7
- package/dist/chunk-MIW7N2MY.js +0 -2613
- package/dist/chunk-MIW7N2MY.js.map +0 -7
- package/dist/chunk-MWRSY4X6.js.map +0 -7
- package/dist/chunk-ND3XWFO6.js +0 -34
- package/dist/chunk-ND3XWFO6.js.map +0 -7
- package/dist/chunk-QVLYOPO5.js.map +0 -7
- package/dist/chunk-RZWOUA25.js.map +0 -7
- package/dist/chunk-S6HRABTA.js.map +0 -7
- package/dist/chunk-STSX7GIX.js.map +0 -7
- package/dist/chunk-UHYRLID6.js.map +0 -7
- package/dist/chunk-UKHTVRJM.js +0 -47
- package/dist/chunk-UKHTVRJM.js.map +0 -7
- package/dist/chunk-UYXEDKOZ.js +0 -24
- package/dist/chunk-UYXEDKOZ.js.map +0 -7
- package/dist/chunk-W7GRKO7Q.js.map +0 -7
- package/dist/chunk-WVHORZQ5.js +0 -17
- package/dist/chunk-WVHORZQ5.js.map +0 -7
- package/dist/chunk-WWUWDNWW.js +0 -49
- package/dist/chunk-WWUWDNWW.js.map +0 -7
- package/dist/chunk-YC6LJCDE.js.map +0 -7
- package/dist/chunk-YXYYDIMI.js +0 -2931
- package/dist/chunk-YXYYDIMI.js.map +0 -7
- package/dist/chunk-ZVDRDPII.js.map +0 -7
- package/dist/cli-DOPVY2CW.js.map +0 -7
- package/dist/commands-2BF2CJ3A.js +0 -46
- package/dist/context-6FXPETYH.js +0 -30
- package/dist/costTracker-6SL26FDB.js +0 -19
- package/dist/kodeAgentSessionLoad-MITZADPB.js +0 -18
- package/dist/kodeAgentSessionResume-GVRWB4WO.js +0 -16
- package/dist/kodeAgentStreamJson-NXFN7TXH.js +0 -13
- package/dist/kodeAgentStreamJsonSession-UGEZJJEB.js.map +0 -7
- package/dist/kodeAgentStructuredStdio-HGWJT7CU.js +0 -10
- package/dist/llm-ZUQC4WYM.js.map +0 -7
- package/dist/llmLazy-54QQHA54.js +0 -15
- package/dist/loader-FYHJQES5.js +0 -28
- package/dist/mcp-J332IKT3.js +0 -49
- package/dist/mentionProcessor-EE3XFHCJ.js.map +0 -7
- package/dist/model-FV3JDJKH.js +0 -30
- package/dist/pluginRuntime-6ETCZ2LL.js.map +0 -7
- package/dist/pluginValidation-I4YKUWGS.js +0 -17
- package/dist/prompts-ZLEKDD77.js +0 -48
- package/dist/query-VFRJPBGD.js +0 -50
- package/dist/responsesStreaming-AW344PQO.js +0 -10
- package/dist/ripgrep-3NTIKQYW.js +0 -17
- package/dist/state-P5G6CO5V.js +0 -16
- package/dist/theme-3LWP3BG7.js +0 -14
- package/dist/toolPermissionSettings-3ROBVTUK.js +0 -18
- package/dist/tools-RO7HSSE5.js +0 -47
- package/dist/userInput-JSBJRFSK.js +0 -311
- package/dist/userInput-JSBJRFSK.js.map +0 -7
- package/dist/uuid-QN2CNKKN.js +0 -9
- /package/dist/{REPL-CW7AYLVL.js.map → chunks/Doctor-M3J7GRTJ.js.map} +0 -0
- /package/dist/{autoUpdater-ITPIHCOI.js.map → chunks/REPL-RQ6LO6S7.js.map} +0 -0
- /package/dist/{chunk-JC6NCUG5.js.map → chunks/ResumeConversation-6DMVBEGH.js.map} +0 -0
- /package/dist/{commands-2BF2CJ3A.js.map → chunks/agentLoader-FCRG3TFJ.js.map} +0 -0
- /package/dist/{config-RUSD6G5Y.js.map → chunks/autoUpdater-CNESBOKO.js.map} +0 -0
- /package/dist/{context-6FXPETYH.js.map → chunks/chunk-4CRUCZR4.js.map} +0 -0
- /package/dist/{costTracker-6SL26FDB.js.map → chunks/chunk-54KOYG5C.js.map} +0 -0
- /package/dist/{customCommands-TOIJFZAL.js.map → chunks/chunk-GCQCAXJZ.js.map} +0 -0
- /package/dist/{env-XGKBLU3D.js.map → chunks/chunk-LB6TCPDI.js.map} +0 -0
- /package/dist/{kodeAgentSessionId-X6XWQW7B.js.map → chunks/client-SILZNM5N.js.map} +0 -0
- /package/dist/{kodeAgentSessionLoad-MITZADPB.js.map → chunks/config-25HRTPSP.js.map} +0 -0
- /package/dist/{kodeAgentSessionResume-GVRWB4WO.js.map → chunks/cost-tracker-Z2UZT2J5.js.map} +0 -0
- /package/dist/{kodeAgentStreamJson-NXFN7TXH.js.map → chunks/customCommands-TYMYZRG5.js.map} +0 -0
- /package/dist/{kodeAgentStructuredStdio-HGWJT7CU.js.map → chunks/engine-MRVF6FK6.js.map} +0 -0
- /package/dist/{kodeHooks-QWM36A3D.js.map → chunks/env-TJ5NOBEB.js.map} +0 -0
- /package/dist/{llmLazy-54QQHA54.js.map → chunks/kodeAgentSessionId-VTNISJ2L.js.map} +0 -0
- /package/dist/{loader-FYHJQES5.js.map → chunks/kodeAgentSessionLoad-YB2RKBGJ.js.map} +0 -0
- /package/dist/{mcp-J332IKT3.js.map → chunks/kodeAgentSessionResume-DZSIVKVA.js.map} +0 -0
- /package/dist/{messages-EOYQKPGM.js.map → chunks/kodeAgentStreamJson-X5PLS2S6.js.map} +0 -0
- /package/dist/{model-FV3JDJKH.js.map → chunks/kodeHooks-RVKYRJHG.js.map} +0 -0
- /package/dist/{openai-RRCWW33N.js.map → chunks/llmLazy-ZUSSE3ZA.js.map} +0 -0
- /package/dist/{outputStyles-62Q3VH2J.js.map → chunks/messages-EEWWLPHN.js.map} +0 -0
- /package/dist/{pluginValidation-I4YKUWGS.js.map → chunks/model-5TIEKQPD.js.map} +0 -0
- /package/dist/{prompts-ZLEKDD77.js.map → chunks/openai-XXK3YZG4.js.map} +0 -0
- /package/dist/{query-VFRJPBGD.js.map → chunks/outputStyles-FAJTXN2A.js.map} +0 -0
- /package/dist/{responsesStreaming-AW344PQO.js.map → chunks/permissions-HO7INPWM.js.map} +0 -0
- /package/dist/{ripgrep-3NTIKQYW.js.map → chunks/pluginValidation-DAM7WRTC.js.map} +0 -0
- /package/dist/{skillMarketplace-3RXQBVOL.js.map → chunks/registry-XYJXMOA5.js.map} +0 -0
- /package/dist/{state-P5G6CO5V.js.map → chunks/responsesStreaming-JNGE2P3D.js.map} +0 -0
- /package/dist/{theme-3LWP3BG7.js.map → chunks/server-REXXF5IK.js.map} +0 -0
- /package/dist/{toolPermissionContext-65L65VEZ.js.map → chunks/skillMarketplace-N4HVHNST.js.map} +0 -0
- /package/dist/{toolPermissionSettings-3ROBVTUK.js.map → chunks/src-OROQIWP3.js.map} +0 -0
- /package/dist/{tools-RO7HSSE5.js.map → chunks/theme-YBJUIMWK.js.map} +0 -0
- /package/dist/{uuid-QN2CNKKN.js.map → chunks/toolPermissionContext-MOCTRR7N.js.map} +0 -0
|
@@ -0,0 +1,1264 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadKodeAgentSessionMessages
|
|
3
|
+
} from "./chunk-TNGVRTO5.js";
|
|
4
|
+
import {
|
|
5
|
+
listKodeAgentSessions
|
|
6
|
+
} from "./chunk-HJYOH4HC.js";
|
|
7
|
+
import {
|
|
8
|
+
isUuid
|
|
9
|
+
} from "./chunk-UNOY3VJ2.js";
|
|
10
|
+
import {
|
|
11
|
+
buildSystemPromptForSession,
|
|
12
|
+
getSessionContext,
|
|
13
|
+
runTurn
|
|
14
|
+
} from "./chunk-4A46ZXMJ.js";
|
|
15
|
+
import {
|
|
16
|
+
getTotalCost
|
|
17
|
+
} from "./chunk-6BAS4WY6.js";
|
|
18
|
+
import {
|
|
19
|
+
getTools
|
|
20
|
+
} from "./chunk-77XDJMBP.js";
|
|
21
|
+
import {
|
|
22
|
+
grantReadPermissionForOriginalDir,
|
|
23
|
+
hasPermissionsToUseTool,
|
|
24
|
+
savePermission
|
|
25
|
+
} from "./chunk-PPHLQVL7.js";
|
|
26
|
+
import {
|
|
27
|
+
loadToolPermissionContextFromDisk
|
|
28
|
+
} from "./chunk-2JN5MY67.js";
|
|
29
|
+
import {
|
|
30
|
+
kodeMessageToSdkMessage,
|
|
31
|
+
makeSdkInitMessage,
|
|
32
|
+
makeSdkResultMessage
|
|
33
|
+
} from "./chunk-CDGRYGPZ.js";
|
|
34
|
+
import {
|
|
35
|
+
setKodeAgentSessionId
|
|
36
|
+
} from "./chunk-SWQV4KSY.js";
|
|
37
|
+
import {
|
|
38
|
+
REJECT_MESSAGE,
|
|
39
|
+
REJECT_MESSAGE_WITH_FEEDBACK_PREFIX,
|
|
40
|
+
createAssistantMessage,
|
|
41
|
+
createUserMessage
|
|
42
|
+
} from "./chunk-HRJ3ICQK.js";
|
|
43
|
+
import {
|
|
44
|
+
setCwd,
|
|
45
|
+
setOriginalCwd
|
|
46
|
+
} from "./chunk-BBJFHTBC.js";
|
|
47
|
+
|
|
48
|
+
// apps/server/src/server.ts
|
|
49
|
+
import { dirname, resolve as resolve4 } from "node:path";
|
|
50
|
+
import { fileURLToPath } from "node:url";
|
|
51
|
+
|
|
52
|
+
// apps/server/src/server/serveNode.ts
|
|
53
|
+
import {
|
|
54
|
+
createServer
|
|
55
|
+
} from "node:http";
|
|
56
|
+
import { WebSocketServer } from "ws";
|
|
57
|
+
async function readRequestBody(req) {
|
|
58
|
+
const method = req.method ?? "GET";
|
|
59
|
+
if (method === "GET" || method === "HEAD") return void 0;
|
|
60
|
+
const chunks = [];
|
|
61
|
+
for await (const chunk of req) {
|
|
62
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
63
|
+
}
|
|
64
|
+
if (chunks.length === 0) return void 0;
|
|
65
|
+
const buf = Buffer.concat(chunks);
|
|
66
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
67
|
+
}
|
|
68
|
+
async function toFetchRequest(req, hostname) {
|
|
69
|
+
const base = `http://${req.headers.host ?? hostname}`;
|
|
70
|
+
const url = new URL(req.url ?? "/", base);
|
|
71
|
+
const headers = new Headers();
|
|
72
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
73
|
+
if (typeof value === "string") headers.set(key, value);
|
|
74
|
+
else if (Array.isArray(value)) headers.set(key, value.join(", "));
|
|
75
|
+
}
|
|
76
|
+
const body = await readRequestBody(req);
|
|
77
|
+
return new Request(url.toString(), {
|
|
78
|
+
method: req.method ?? "GET",
|
|
79
|
+
headers,
|
|
80
|
+
...body ? { body } : {}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
async function sendFetchResponse(res, response) {
|
|
84
|
+
res.statusCode = response.status;
|
|
85
|
+
for (const [key, value] of response.headers.entries()) {
|
|
86
|
+
try {
|
|
87
|
+
res.setHeader(key, value);
|
|
88
|
+
} catch {
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!response.body || res.req?.method === "HEAD") {
|
|
92
|
+
res.end();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const buf = Buffer.from(await response.arrayBuffer());
|
|
96
|
+
res.setHeader("content-length", String(buf.length));
|
|
97
|
+
res.end(buf);
|
|
98
|
+
}
|
|
99
|
+
async function sendFetchResponseToSocket(socket, response) {
|
|
100
|
+
const headers = [];
|
|
101
|
+
for (const [key, value] of response.headers.entries()) {
|
|
102
|
+
headers.push(`${key}: ${value}`);
|
|
103
|
+
}
|
|
104
|
+
if (!response.headers.has("connection")) headers.push("connection: close");
|
|
105
|
+
const body = response.body ? Buffer.from(await response.arrayBuffer()) : Buffer.alloc(0);
|
|
106
|
+
headers.push(`content-length: ${body.length}`);
|
|
107
|
+
const statusText = response.statusText || "OK";
|
|
108
|
+
socket.write(`HTTP/1.1 ${response.status} ${statusText}\r
|
|
109
|
+
`);
|
|
110
|
+
socket.write(headers.join("\r\n"));
|
|
111
|
+
socket.write("\r\n\r\n");
|
|
112
|
+
if (body.length) socket.write(body);
|
|
113
|
+
socket.destroy();
|
|
114
|
+
}
|
|
115
|
+
async function serveNode(options) {
|
|
116
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
117
|
+
const httpServer = createServer(async (req, res) => {
|
|
118
|
+
const request = await toFetchRequest(req, options.hostname);
|
|
119
|
+
const response = await options.fetch(request, { upgrade: () => false });
|
|
120
|
+
if (!response) {
|
|
121
|
+
res.statusCode = 500;
|
|
122
|
+
res.end("No response");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
await sendFetchResponse(res, response);
|
|
126
|
+
});
|
|
127
|
+
httpServer.on("upgrade", async (req, socket, head) => {
|
|
128
|
+
const request = await toFetchRequest(req, options.hostname);
|
|
129
|
+
let upgraded = false;
|
|
130
|
+
const response = await options.fetch(request, {
|
|
131
|
+
upgrade: (_request, upgradeOptions) => {
|
|
132
|
+
if (upgraded) return true;
|
|
133
|
+
upgraded = true;
|
|
134
|
+
try {
|
|
135
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
136
|
+
const wsWithData = Object.assign(ws, { data: upgradeOptions.data });
|
|
137
|
+
try {
|
|
138
|
+
options.websocket.open(wsWithData);
|
|
139
|
+
} catch {
|
|
140
|
+
}
|
|
141
|
+
ws.on("message", (message) => {
|
|
142
|
+
Promise.resolve(
|
|
143
|
+
options.websocket.message(wsWithData, message)
|
|
144
|
+
).catch(() => {
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
ws.on("close", () => {
|
|
148
|
+
try {
|
|
149
|
+
options.websocket.close(wsWithData);
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return true;
|
|
155
|
+
} catch {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
if (upgraded) return;
|
|
161
|
+
if (response) {
|
|
162
|
+
await sendFetchResponseToSocket(socket, response);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
socket.destroy();
|
|
166
|
+
});
|
|
167
|
+
await new Promise((resolve5, reject) => {
|
|
168
|
+
const onError = (err) => {
|
|
169
|
+
reject(err);
|
|
170
|
+
};
|
|
171
|
+
httpServer.once("error", onError);
|
|
172
|
+
httpServer.listen(options.port, options.hostname, () => {
|
|
173
|
+
httpServer.removeListener("error", onError);
|
|
174
|
+
resolve5();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
const address = httpServer.address();
|
|
178
|
+
const actualPort = typeof address === "object" && address && typeof address.port === "number" ? address.port : options.port;
|
|
179
|
+
const stop = () => {
|
|
180
|
+
try {
|
|
181
|
+
wss.clients.forEach((ws) => {
|
|
182
|
+
try {
|
|
183
|
+
ws.close();
|
|
184
|
+
} catch {
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
} catch {
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
wss.close();
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
httpServer.close();
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return { port: actualPort, stop };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// apps/server/src/server/auth.ts
|
|
202
|
+
import { timingSafeEqual } from "node:crypto";
|
|
203
|
+
function timingSafeEquals(a, b) {
|
|
204
|
+
try {
|
|
205
|
+
const aBuf = Buffer.from(a, "utf8");
|
|
206
|
+
const bBuf = Buffer.from(b, "utf8");
|
|
207
|
+
if (aBuf.length !== bBuf.length) return false;
|
|
208
|
+
return timingSafeEqual(aBuf, bBuf);
|
|
209
|
+
} catch {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function getCookieValue(cookieHeader, name) {
|
|
214
|
+
if (!cookieHeader) return null;
|
|
215
|
+
const parts = cookieHeader.split(";");
|
|
216
|
+
for (const part of parts) {
|
|
217
|
+
const [k, ...rest] = part.trim().split("=");
|
|
218
|
+
if (!k) continue;
|
|
219
|
+
if (k === name) {
|
|
220
|
+
const value = rest.join("=");
|
|
221
|
+
if (!value) return "";
|
|
222
|
+
try {
|
|
223
|
+
return decodeURIComponent(value);
|
|
224
|
+
} catch {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
function createTokenChecker(args) {
|
|
232
|
+
const token = args.token;
|
|
233
|
+
return (req) => {
|
|
234
|
+
const url = new URL(req.url);
|
|
235
|
+
const qp = url.searchParams.get("token");
|
|
236
|
+
if (qp && timingSafeEquals(qp, token)) return true;
|
|
237
|
+
const header = req.headers.get("authorization");
|
|
238
|
+
if (header && header.startsWith("Bearer ")) {
|
|
239
|
+
const h = header.slice("Bearer ".length).trim();
|
|
240
|
+
if (h && timingSafeEquals(h, token)) return true;
|
|
241
|
+
}
|
|
242
|
+
const cookieToken = getCookieValue(req.headers.get("cookie"), "kode_token");
|
|
243
|
+
if (cookieToken && timingSafeEquals(cookieToken, token)) return true;
|
|
244
|
+
return false;
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// apps/server/src/server/webui.ts
|
|
249
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
250
|
+
import { resolve, sep } from "node:path";
|
|
251
|
+
function detectWebuiDir(moduleDir) {
|
|
252
|
+
const candidates = [
|
|
253
|
+
// Packaged: dist/* → dist/webui (compiled chunks may live in dist/, dist/entrypoints/, dist/chunks/, etc.)
|
|
254
|
+
resolve(moduleDir, "webui"),
|
|
255
|
+
resolve(moduleDir, "..", "webui"),
|
|
256
|
+
resolve(moduleDir, "..", "..", "webui")
|
|
257
|
+
];
|
|
258
|
+
for (let up = 0; up <= 6; up++) {
|
|
259
|
+
const parents = Array(up).fill("..");
|
|
260
|
+
candidates.push(resolve(moduleDir, ...parents, "apps", "server", "static"));
|
|
261
|
+
candidates.push(resolve(moduleDir, ...parents, "ui", "web", "dist"));
|
|
262
|
+
candidates.push(resolve(moduleDir, ...parents, "ui", "web"));
|
|
263
|
+
candidates.push(resolve(moduleDir, ...parents, "dist", "webui"));
|
|
264
|
+
}
|
|
265
|
+
for (const candidate of candidates) {
|
|
266
|
+
try {
|
|
267
|
+
if (existsSync(resolve(candidate, "index.html"))) return candidate;
|
|
268
|
+
} catch {
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
function contentTypeForPath(filePath) {
|
|
274
|
+
const ext = filePath.split(".").pop()?.toLowerCase() ?? "";
|
|
275
|
+
return ext === "html" ? "text/html; charset=utf-8" : ext === "js" ? "text/javascript; charset=utf-8" : ext === "css" ? "text/css; charset=utf-8" : ext === "svg" ? "image/svg+xml" : ext === "json" ? "application/json; charset=utf-8" : ext === "png" ? "image/png" : ext === "jpg" || ext === "jpeg" ? "image/jpeg" : "application/octet-stream";
|
|
276
|
+
}
|
|
277
|
+
function maybeServeWebui(args) {
|
|
278
|
+
const webuiRoot = resolve(args.webuiRoot);
|
|
279
|
+
const pathname = args.url.pathname;
|
|
280
|
+
const requested = pathname === "/" ? "/index.html" : pathname;
|
|
281
|
+
const rel = requested.startsWith("/") ? requested.slice(1) : requested;
|
|
282
|
+
const filePath = resolve(webuiRoot, rel);
|
|
283
|
+
if (!(filePath === webuiRoot || filePath.startsWith(webuiRoot + sep))) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
if (!existsSync(filePath)) return null;
|
|
287
|
+
const file = readFileSync(filePath);
|
|
288
|
+
return new Response(file, {
|
|
289
|
+
headers: {
|
|
290
|
+
"content-type": contentTypeForPath(filePath),
|
|
291
|
+
"cache-control": "no-cache"
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// apps/server/src/handlers/workspaces.handler.ts
|
|
297
|
+
import { spawn } from "node:child_process";
|
|
298
|
+
import { basename, resolve as resolve2 } from "node:path";
|
|
299
|
+
function parseWorktreePorcelain(stdout) {
|
|
300
|
+
const entries = [];
|
|
301
|
+
let current = null;
|
|
302
|
+
const lines = stdout.split(/\r?\n/);
|
|
303
|
+
for (const rawLine of lines) {
|
|
304
|
+
const line = rawLine.trim();
|
|
305
|
+
if (!line) {
|
|
306
|
+
if (current?.path) entries.push(current);
|
|
307
|
+
current = null;
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
if (line.startsWith("worktree ")) {
|
|
311
|
+
if (current?.path) entries.push(current);
|
|
312
|
+
current = { path: line.slice("worktree ".length).trim(), branch: null };
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
if (!current) continue;
|
|
316
|
+
if (line.startsWith("branch ")) {
|
|
317
|
+
const ref = line.slice("branch ".length).trim();
|
|
318
|
+
const branch = ref.startsWith("refs/heads/") ? ref.slice("refs/heads/".length) : ref;
|
|
319
|
+
current.branch = branch || null;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (current?.path) entries.push(current);
|
|
323
|
+
return entries;
|
|
324
|
+
}
|
|
325
|
+
async function execArgs(cmd, options) {
|
|
326
|
+
const timeoutMs = options.timeoutMs ?? 12e4;
|
|
327
|
+
const abortController = new AbortController();
|
|
328
|
+
let wasAborted = false;
|
|
329
|
+
let proc = null;
|
|
330
|
+
const onAbort = () => {
|
|
331
|
+
wasAborted = true;
|
|
332
|
+
try {
|
|
333
|
+
abortController.abort();
|
|
334
|
+
} catch {
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
proc?.kill();
|
|
338
|
+
} catch {
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
if (options.abortSignal) {
|
|
342
|
+
options.abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
proc = spawn(cmd[0] ?? "", cmd.slice(1), {
|
|
346
|
+
cwd: options.cwd,
|
|
347
|
+
env: { ...process.env, ...options.env ?? {} },
|
|
348
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
349
|
+
});
|
|
350
|
+
let stdout = "";
|
|
351
|
+
let stderr = "";
|
|
352
|
+
proc.stdout?.setEncoding("utf8");
|
|
353
|
+
proc.stdout?.on("data", (chunk) => {
|
|
354
|
+
stdout += chunk;
|
|
355
|
+
});
|
|
356
|
+
proc.stderr?.setEncoding("utf8");
|
|
357
|
+
proc.stderr?.on("data", (chunk) => {
|
|
358
|
+
stderr += chunk;
|
|
359
|
+
});
|
|
360
|
+
const exitPromise = new Promise((resolve5) => {
|
|
361
|
+
proc?.once("exit", (code2) => resolve5({ kind: "exit", code: code2 }));
|
|
362
|
+
proc?.once("error", (error) => resolve5({ kind: "error", error }));
|
|
363
|
+
});
|
|
364
|
+
let timeoutHandle = null;
|
|
365
|
+
const timeoutPromise = new Promise((resolveTimeout) => {
|
|
366
|
+
timeoutHandle = setTimeout(() => resolveTimeout("timeout"), timeoutMs);
|
|
367
|
+
});
|
|
368
|
+
const outcome = await Promise.race([
|
|
369
|
+
exitPromise.then(() => "completed"),
|
|
370
|
+
timeoutPromise
|
|
371
|
+
]);
|
|
372
|
+
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
373
|
+
if (outcome === "timeout") {
|
|
374
|
+
onAbort();
|
|
375
|
+
try {
|
|
376
|
+
await exitPromise;
|
|
377
|
+
} catch {
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
stdout: "",
|
|
381
|
+
stderr: "Command timed out",
|
|
382
|
+
code: 143,
|
|
383
|
+
interrupted: true
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
const exitOutcome = await exitPromise;
|
|
387
|
+
if (exitOutcome.kind === "error") {
|
|
388
|
+
stderr = [stderr, exitOutcome.error.message].filter(Boolean).join("\n");
|
|
389
|
+
}
|
|
390
|
+
const interrupted = wasAborted || options.abortSignal?.aborted === true || abortController.signal.aborted === true;
|
|
391
|
+
const code = exitOutcome.kind === "exit" && typeof exitOutcome.code === "number" ? exitOutcome.code : exitOutcome.kind === "error" ? 2 : interrupted ? 143 : 0;
|
|
392
|
+
return { stdout, stderr, code, interrupted };
|
|
393
|
+
} finally {
|
|
394
|
+
if (options.abortSignal) {
|
|
395
|
+
options.abortSignal.removeEventListener("abort", onAbort);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function createWorkspaceLister(args) {
|
|
400
|
+
const workspaceCacheTtlMs = args.cacheTtlMs ?? 2e3;
|
|
401
|
+
let workspaceCache = null;
|
|
402
|
+
const listWorkspaces = async () => {
|
|
403
|
+
const now = Date.now();
|
|
404
|
+
if (workspaceCache && now - workspaceCache.at < workspaceCacheTtlMs) {
|
|
405
|
+
return {
|
|
406
|
+
workspaces: workspaceCache.workspaces,
|
|
407
|
+
currentId: workspaceCache.currentId
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
const absCwd = resolve2(args.cwd);
|
|
411
|
+
const repoRootRes = await execArgs(
|
|
412
|
+
["git", "rev-parse", "--show-toplevel"],
|
|
413
|
+
{
|
|
414
|
+
cwd: absCwd,
|
|
415
|
+
timeoutMs: 2e3
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
const repoRoot = repoRootRes.code === 0 ? repoRootRes.stdout.trim() : "";
|
|
419
|
+
if (!repoRoot) {
|
|
420
|
+
const only = {
|
|
421
|
+
id: absCwd,
|
|
422
|
+
path: absCwd,
|
|
423
|
+
title: basename(absCwd) || absCwd,
|
|
424
|
+
branch: null,
|
|
425
|
+
isCurrent: true
|
|
426
|
+
};
|
|
427
|
+
workspaceCache = { at: now, workspaces: [only], currentId: only.id };
|
|
428
|
+
return { workspaces: [only], currentId: only.id };
|
|
429
|
+
}
|
|
430
|
+
const porcelainRes = await execArgs(
|
|
431
|
+
["git", "worktree", "list", "--porcelain"],
|
|
432
|
+
{ cwd: repoRoot, timeoutMs: 3e3 }
|
|
433
|
+
);
|
|
434
|
+
const worktreeEntries = porcelainRes.code === 0 ? parseWorktreePorcelain(porcelainRes.stdout) : [];
|
|
435
|
+
const normalized = worktreeEntries.map((e) => ({
|
|
436
|
+
path: resolve2(e.path),
|
|
437
|
+
branch: e.branch
|
|
438
|
+
})).filter((e) => e.path);
|
|
439
|
+
const currentRoot = resolve2(repoRoot);
|
|
440
|
+
const unique = /* @__PURE__ */ new Map();
|
|
441
|
+
for (const e of normalized) {
|
|
442
|
+
unique.set(e.path, {
|
|
443
|
+
id: e.path,
|
|
444
|
+
path: e.path,
|
|
445
|
+
title: e.branch || basename(e.path) || e.path,
|
|
446
|
+
branch: e.branch,
|
|
447
|
+
isCurrent: e.path === currentRoot
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
if (!unique.has(currentRoot)) {
|
|
451
|
+
unique.set(currentRoot, {
|
|
452
|
+
id: currentRoot,
|
|
453
|
+
path: currentRoot,
|
|
454
|
+
title: basename(currentRoot) || currentRoot,
|
|
455
|
+
branch: null,
|
|
456
|
+
isCurrent: true
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
const workspaces = Array.from(unique.values()).sort((a, b) => {
|
|
460
|
+
if (a.isCurrent !== b.isCurrent) return a.isCurrent ? -1 : 1;
|
|
461
|
+
return a.title.localeCompare(b.title);
|
|
462
|
+
});
|
|
463
|
+
const currentId = workspaces.find((w) => w.isCurrent)?.id ?? workspaces[0]?.id ?? currentRoot;
|
|
464
|
+
workspaceCache = { at: now, workspaces, currentId };
|
|
465
|
+
return { workspaces, currentId };
|
|
466
|
+
};
|
|
467
|
+
return { listWorkspaces };
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// apps/server/src/routes/index.ts
|
|
471
|
+
import { basename as basename2, resolve as resolve3 } from "node:path";
|
|
472
|
+
|
|
473
|
+
// apps/server/src/handlers/chat.handler.ts
|
|
474
|
+
function extractFirstAssistantText(message) {
|
|
475
|
+
const blocks = Array.isArray(message.content) ? message.content : [];
|
|
476
|
+
for (const block of blocks) {
|
|
477
|
+
if (block && typeof block === "object" && block.type === "text") {
|
|
478
|
+
const maybeText = block.text;
|
|
479
|
+
if (typeof maybeText === "string") return maybeText;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
async function getToolDescription(tool, input) {
|
|
485
|
+
if (typeof tool.description === "function") {
|
|
486
|
+
return await tool.description(input);
|
|
487
|
+
}
|
|
488
|
+
if (typeof tool.description === "string") return tool.description;
|
|
489
|
+
return `Tool: ${tool.name}`;
|
|
490
|
+
}
|
|
491
|
+
async function handleChatPrompt(args) {
|
|
492
|
+
const {
|
|
493
|
+
wsSend,
|
|
494
|
+
session,
|
|
495
|
+
prompt,
|
|
496
|
+
echo,
|
|
497
|
+
commands,
|
|
498
|
+
tools,
|
|
499
|
+
toolNames,
|
|
500
|
+
slashCommands
|
|
501
|
+
} = args;
|
|
502
|
+
setOriginalCwd(session.cwd);
|
|
503
|
+
await setCwd(session.cwd);
|
|
504
|
+
grantReadPermissionForOriginalDir();
|
|
505
|
+
setKodeAgentSessionId(session.sessionId);
|
|
506
|
+
const abortController = new AbortController();
|
|
507
|
+
session.activeAbortController = abortController;
|
|
508
|
+
const startedAt = Date.now();
|
|
509
|
+
const costBefore = getTotalCost();
|
|
510
|
+
const userMsg = createUserMessage(prompt);
|
|
511
|
+
session.messages.push(userMsg);
|
|
512
|
+
const sdkUser = kodeMessageToSdkMessage(userMsg, session.sessionId);
|
|
513
|
+
if (sdkUser) wsSend(sdkUser);
|
|
514
|
+
if (echo) {
|
|
515
|
+
const assistant = createAssistantMessage(prompt);
|
|
516
|
+
session.messages.push(assistant);
|
|
517
|
+
const sdkAssistant = kodeMessageToSdkMessage(assistant, session.sessionId);
|
|
518
|
+
if (sdkAssistant) wsSend(sdkAssistant);
|
|
519
|
+
wsSend(
|
|
520
|
+
makeSdkResultMessage({
|
|
521
|
+
sessionId: session.sessionId,
|
|
522
|
+
result: prompt,
|
|
523
|
+
numTurns: 1,
|
|
524
|
+
usage: void 0,
|
|
525
|
+
totalCostUsd: 0,
|
|
526
|
+
durationMs: Date.now() - startedAt,
|
|
527
|
+
durationApiMs: 0,
|
|
528
|
+
isError: false
|
|
529
|
+
})
|
|
530
|
+
);
|
|
531
|
+
session.activeAbortController = null;
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
const requestToolPermission = async (params) => {
|
|
535
|
+
const base = await hasPermissionsToUseTool(
|
|
536
|
+
params.tool,
|
|
537
|
+
params.input,
|
|
538
|
+
params.toolUseContext,
|
|
539
|
+
params.assistantMessage
|
|
540
|
+
);
|
|
541
|
+
if (base.result === true) return { result: true };
|
|
542
|
+
if (base.shouldPromptUser === false) {
|
|
543
|
+
return {
|
|
544
|
+
result: false,
|
|
545
|
+
message: base.message,
|
|
546
|
+
shouldPromptUser: false
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
if (params.toolUseContext.abortController.signal.aborted) {
|
|
550
|
+
return {
|
|
551
|
+
result: false,
|
|
552
|
+
message: REJECT_MESSAGE,
|
|
553
|
+
shouldPromptUser: false
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
const requestId = typeof params.toolUseContext.toolUseId === "string" && params.toolUseContext.toolUseId ? params.toolUseContext.toolUseId : crypto.randomUUID();
|
|
557
|
+
const toolDescription = await getToolDescription(params.tool, params.input);
|
|
558
|
+
const request = {
|
|
559
|
+
type: "permission_request",
|
|
560
|
+
request_id: requestId,
|
|
561
|
+
tool_name: params.tool.name,
|
|
562
|
+
tool_description: toolDescription,
|
|
563
|
+
input: params.input
|
|
564
|
+
};
|
|
565
|
+
wsSend(request);
|
|
566
|
+
const decision = await new Promise((resolve5) => {
|
|
567
|
+
session.inflightPermissionRequests.set(requestId, resolve5);
|
|
568
|
+
});
|
|
569
|
+
if (params.toolUseContext.abortController.signal.aborted) {
|
|
570
|
+
return {
|
|
571
|
+
result: false,
|
|
572
|
+
message: REJECT_MESSAGE,
|
|
573
|
+
shouldPromptUser: false
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
if (decision.updatedInput && typeof decision.updatedInput === "object") {
|
|
577
|
+
Object.assign(params.input, decision.updatedInput);
|
|
578
|
+
}
|
|
579
|
+
if (decision.decision === "deny") {
|
|
580
|
+
try {
|
|
581
|
+
params.toolUseContext.abortController.abort();
|
|
582
|
+
} catch {
|
|
583
|
+
}
|
|
584
|
+
const message = decision.rejectionMessage && decision.rejectionMessage.trim() ? `${REJECT_MESSAGE_WITH_FEEDBACK_PREFIX}${decision.rejectionMessage.trim()}` : REJECT_MESSAGE;
|
|
585
|
+
return { result: false, message, shouldPromptUser: false };
|
|
586
|
+
}
|
|
587
|
+
if (decision.decision === "allow_always") {
|
|
588
|
+
try {
|
|
589
|
+
await savePermission(
|
|
590
|
+
params.tool,
|
|
591
|
+
params.input,
|
|
592
|
+
null,
|
|
593
|
+
params.toolUseContext
|
|
594
|
+
);
|
|
595
|
+
} catch {
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return { result: true };
|
|
599
|
+
};
|
|
600
|
+
const canUseTool = async (tool, input, toolUseContext, assistantMessage) => {
|
|
601
|
+
return await requestToolPermission({
|
|
602
|
+
tool,
|
|
603
|
+
input,
|
|
604
|
+
toolUseContext,
|
|
605
|
+
assistantMessage
|
|
606
|
+
});
|
|
607
|
+
};
|
|
608
|
+
const [context, systemPrompt] = await Promise.all([
|
|
609
|
+
getSessionContext(),
|
|
610
|
+
buildSystemPromptForSession({ disableSlashCommands: false })
|
|
611
|
+
]);
|
|
612
|
+
const options = {
|
|
613
|
+
commands,
|
|
614
|
+
tools,
|
|
615
|
+
verbose: true,
|
|
616
|
+
safeMode: false,
|
|
617
|
+
forkNumber: 0,
|
|
618
|
+
messageLogName: session.sessionId,
|
|
619
|
+
maxThinkingTokens: 0,
|
|
620
|
+
persistSession: true,
|
|
621
|
+
toolPermissionContext: session.toolPermissionContext,
|
|
622
|
+
mcpClients: [],
|
|
623
|
+
shouldAvoidPermissionPrompts: false
|
|
624
|
+
};
|
|
625
|
+
let lastAssistant = null;
|
|
626
|
+
let queryError = null;
|
|
627
|
+
try {
|
|
628
|
+
const baseMessages = [...session.messages];
|
|
629
|
+
for await (const m of runTurn({
|
|
630
|
+
messages: baseMessages,
|
|
631
|
+
systemPrompt,
|
|
632
|
+
context,
|
|
633
|
+
canUseTool,
|
|
634
|
+
toolUseContext: {
|
|
635
|
+
options,
|
|
636
|
+
abortController,
|
|
637
|
+
messageId: void 0,
|
|
638
|
+
readFileTimestamps: session.readFileTimestamps,
|
|
639
|
+
setToolJSX: () => {
|
|
640
|
+
},
|
|
641
|
+
agentId: "main",
|
|
642
|
+
responseState: session.responseState
|
|
643
|
+
}
|
|
644
|
+
})) {
|
|
645
|
+
if (abortController.signal.aborted) break;
|
|
646
|
+
if (m.type === "assistant") lastAssistant = m;
|
|
647
|
+
if (m.type !== "progress") {
|
|
648
|
+
session.messages.push(m);
|
|
649
|
+
}
|
|
650
|
+
const sdk = kodeMessageToSdkMessage(m, session.sessionId);
|
|
651
|
+
if (sdk) wsSend(sdk);
|
|
652
|
+
}
|
|
653
|
+
} catch (err) {
|
|
654
|
+
queryError = err;
|
|
655
|
+
try {
|
|
656
|
+
abortController.abort();
|
|
657
|
+
} catch {
|
|
658
|
+
}
|
|
659
|
+
} finally {
|
|
660
|
+
session.activeAbortController = null;
|
|
661
|
+
}
|
|
662
|
+
const resultFromAssistant = lastAssistant ? extractFirstAssistantText(lastAssistant.message) : null;
|
|
663
|
+
const resultText = typeof resultFromAssistant === "string" ? resultFromAssistant : queryError instanceof Error ? queryError.message : queryError ? String(queryError) : "";
|
|
664
|
+
const usage = lastAssistant?.message?.usage;
|
|
665
|
+
const durationMs = Date.now() - startedAt;
|
|
666
|
+
const totalCostUsd = Math.max(0, getTotalCost() - costBefore);
|
|
667
|
+
const isError = Boolean(queryError) || abortController.signal.aborted;
|
|
668
|
+
wsSend(
|
|
669
|
+
makeSdkResultMessage({
|
|
670
|
+
sessionId: session.sessionId,
|
|
671
|
+
result: String(resultText),
|
|
672
|
+
numTurns: 1,
|
|
673
|
+
usage,
|
|
674
|
+
totalCostUsd,
|
|
675
|
+
durationMs,
|
|
676
|
+
durationApiMs: 0,
|
|
677
|
+
isError
|
|
678
|
+
})
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// apps/server/src/handlers/session.handler.ts
|
|
683
|
+
function loadSessionMessages(args) {
|
|
684
|
+
return loadKodeAgentSessionMessages(args);
|
|
685
|
+
}
|
|
686
|
+
function buildSessionList(args) {
|
|
687
|
+
return listKodeAgentSessions({ cwd: args.cwd }).map((s) => ({
|
|
688
|
+
sessionId: s.sessionId,
|
|
689
|
+
slug: s.slug,
|
|
690
|
+
customTitle: s.customTitle,
|
|
691
|
+
tag: s.tag,
|
|
692
|
+
summary: s.summary,
|
|
693
|
+
cwd: s.cwd,
|
|
694
|
+
createdAt: s.createdAt ? s.createdAt.toISOString() : null,
|
|
695
|
+
modifiedAt: s.modifiedAt ? s.modifiedAt.toISOString() : null
|
|
696
|
+
}));
|
|
697
|
+
}
|
|
698
|
+
function sendSessionList(ws, args) {
|
|
699
|
+
try {
|
|
700
|
+
const sessions = buildSessionList({ cwd: args.cwd });
|
|
701
|
+
ws.send(JSON.stringify({ type: "session_list", sessions }));
|
|
702
|
+
} catch (err) {
|
|
703
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
704
|
+
args.onError?.(message);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// apps/server/src/ws/events.ts
|
|
709
|
+
function isRecord(value) {
|
|
710
|
+
return typeof value === "object" && value !== null;
|
|
711
|
+
}
|
|
712
|
+
function toText(message) {
|
|
713
|
+
if (typeof message === "string") return message;
|
|
714
|
+
if (Array.isArray(message)) {
|
|
715
|
+
return message.map((part) => typeof part === "string" ? part : part.toString()).join("");
|
|
716
|
+
}
|
|
717
|
+
return message.toString();
|
|
718
|
+
}
|
|
719
|
+
function parseClientWsMessage(message) {
|
|
720
|
+
const text = toText(message);
|
|
721
|
+
let payload;
|
|
722
|
+
try {
|
|
723
|
+
payload = JSON.parse(text);
|
|
724
|
+
} catch {
|
|
725
|
+
return { ok: false, error: "Invalid JSON message" };
|
|
726
|
+
}
|
|
727
|
+
if (!isRecord(payload)) return { ok: false, error: "Invalid payload" };
|
|
728
|
+
const type = payload.type;
|
|
729
|
+
if (type === "cancel") return { ok: true, value: { type: "cancel" } };
|
|
730
|
+
if (type === "list_sessions")
|
|
731
|
+
return { ok: true, value: { type: "list_sessions" } };
|
|
732
|
+
if (type === "new_session")
|
|
733
|
+
return { ok: true, value: { type: "new_session" } };
|
|
734
|
+
if (type === "resume") {
|
|
735
|
+
const sessionId = typeof payload.session_id === "string" ? payload.session_id.trim() : "";
|
|
736
|
+
if (!sessionId) return { ok: false, error: "Invalid session_id" };
|
|
737
|
+
return { ok: true, value: { type: "resume", sessionId } };
|
|
738
|
+
}
|
|
739
|
+
if (type === "prompt") {
|
|
740
|
+
const prompt = typeof payload.prompt === "string" ? payload.prompt : "";
|
|
741
|
+
if (!prompt.trim()) return { ok: false, error: "Missing prompt" };
|
|
742
|
+
return { ok: true, value: { type: "prompt", prompt } };
|
|
743
|
+
}
|
|
744
|
+
if (type === "permission_response") {
|
|
745
|
+
const requestId = typeof payload.request_id === "string" ? payload.request_id : "";
|
|
746
|
+
const decision = payload.decision === "allow_once" || payload.decision === "allow_always" || payload.decision === "deny" ? payload.decision : null;
|
|
747
|
+
if (!requestId || !decision)
|
|
748
|
+
return { ok: false, error: "Invalid permission response" };
|
|
749
|
+
const updatedInput = isRecord(payload.updated_input) ? payload.updated_input : null;
|
|
750
|
+
const rejectionMessage = typeof payload.rejection_message === "string" ? payload.rejection_message : null;
|
|
751
|
+
return {
|
|
752
|
+
ok: true,
|
|
753
|
+
value: {
|
|
754
|
+
type: "permission_response",
|
|
755
|
+
requestId,
|
|
756
|
+
decision,
|
|
757
|
+
updatedInput,
|
|
758
|
+
rejectionMessage
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
return { ok: false, error: `Unsupported message type: ${String(type)}` };
|
|
763
|
+
}
|
|
764
|
+
function sendJson(ws, payload) {
|
|
765
|
+
ws.send(JSON.stringify(payload));
|
|
766
|
+
}
|
|
767
|
+
function log(level, message) {
|
|
768
|
+
return { type: "log", log: { level, message } };
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// apps/server/src/routes/chat.ts
|
|
772
|
+
function isRecord2(value) {
|
|
773
|
+
return typeof value === "object" && value !== null;
|
|
774
|
+
}
|
|
775
|
+
function sendJson2(ws, payload) {
|
|
776
|
+
ws.send(JSON.stringify(payload));
|
|
777
|
+
}
|
|
778
|
+
async function routeChat(req, ctx) {
|
|
779
|
+
const url = new URL(req.url);
|
|
780
|
+
if (url.pathname !== "/api/chat") return void 0;
|
|
781
|
+
if (req.method !== "POST") {
|
|
782
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
783
|
+
}
|
|
784
|
+
let body;
|
|
785
|
+
try {
|
|
786
|
+
body = await req.json();
|
|
787
|
+
} catch {
|
|
788
|
+
body = null;
|
|
789
|
+
}
|
|
790
|
+
if (!isRecord2(body)) {
|
|
791
|
+
return Response.json(
|
|
792
|
+
{ ok: false, error: "Invalid JSON body" },
|
|
793
|
+
{ status: 400 }
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
const sessionId = typeof body.sessionId === "string" ? body.sessionId.trim() : "";
|
|
797
|
+
const prompt = typeof body.prompt === "string" ? body.prompt : "";
|
|
798
|
+
if (!sessionId) {
|
|
799
|
+
return Response.json(
|
|
800
|
+
{ ok: false, error: "Missing sessionId" },
|
|
801
|
+
{ status: 400 }
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
if (!prompt.trim()) {
|
|
805
|
+
return Response.json(
|
|
806
|
+
{ ok: false, error: "Missing prompt" },
|
|
807
|
+
{ status: 400 }
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
const session = ctx.sessions.get(sessionId);
|
|
811
|
+
if (!session) {
|
|
812
|
+
return Response.json(
|
|
813
|
+
{ ok: false, error: "Unknown session" },
|
|
814
|
+
{ status: 404 }
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
const ws = session.ws;
|
|
818
|
+
if (!ws) {
|
|
819
|
+
return Response.json(
|
|
820
|
+
{ ok: false, error: "No active websocket connection for this session" },
|
|
821
|
+
{ status: 409 }
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
if (session.activeAbortController) {
|
|
825
|
+
return Response.json(
|
|
826
|
+
{ ok: false, error: "Session already has an active prompt" },
|
|
827
|
+
{ status: 409 }
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
const wsSend = (payload) => {
|
|
831
|
+
try {
|
|
832
|
+
sendJson2(ws, payload);
|
|
833
|
+
} catch {
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
void (async () => {
|
|
837
|
+
try {
|
|
838
|
+
await handleChatPrompt({
|
|
839
|
+
wsSend,
|
|
840
|
+
session,
|
|
841
|
+
prompt,
|
|
842
|
+
echo: ctx.echo,
|
|
843
|
+
commands: ctx.commands,
|
|
844
|
+
tools: ctx.tools,
|
|
845
|
+
toolNames: ctx.toolNames,
|
|
846
|
+
slashCommands: ctx.slashCommands
|
|
847
|
+
});
|
|
848
|
+
} catch (err) {
|
|
849
|
+
wsSend(log("error", err instanceof Error ? err.message : String(err)));
|
|
850
|
+
} finally {
|
|
851
|
+
try {
|
|
852
|
+
sendSessionList(ws, {
|
|
853
|
+
cwd: session.cwd,
|
|
854
|
+
onError: (message) => wsSend(log("error", message))
|
|
855
|
+
});
|
|
856
|
+
} catch {
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
})();
|
|
860
|
+
return Response.json({ ok: true });
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// apps/server/src/routes/session.ts
|
|
864
|
+
async function routeSession(req, ctx) {
|
|
865
|
+
const url = new URL(req.url);
|
|
866
|
+
if (!url.pathname.startsWith("/api/sessions")) return void 0;
|
|
867
|
+
if (req.method !== "GET") {
|
|
868
|
+
return new Response("Method Not Allowed", { status: 405 });
|
|
869
|
+
}
|
|
870
|
+
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
871
|
+
const hasId = pathParts.length >= 3;
|
|
872
|
+
const requestedId = hasId ? pathParts[2] ?? "" : "";
|
|
873
|
+
if (!hasId) {
|
|
874
|
+
const sessions2 = buildSessionList({ cwd: ctx.cwd });
|
|
875
|
+
return Response.json({ sessions: sessions2 });
|
|
876
|
+
}
|
|
877
|
+
const sessionId = requestedId.trim();
|
|
878
|
+
if (!sessionId || !isUuid(sessionId)) {
|
|
879
|
+
return Response.json(
|
|
880
|
+
{ ok: false, error: "Invalid session id" },
|
|
881
|
+
{ status: 400 }
|
|
882
|
+
);
|
|
883
|
+
}
|
|
884
|
+
const sessions = buildSessionList({ cwd: ctx.cwd });
|
|
885
|
+
const base = sessions.find((s) => s.sessionId === sessionId) ?? {
|
|
886
|
+
sessionId,
|
|
887
|
+
slug: null,
|
|
888
|
+
customTitle: null,
|
|
889
|
+
tag: null,
|
|
890
|
+
summary: null,
|
|
891
|
+
cwd: ctx.cwd,
|
|
892
|
+
createdAt: null,
|
|
893
|
+
modifiedAt: null
|
|
894
|
+
};
|
|
895
|
+
const messages = loadSessionMessages({ cwd: ctx.cwd, sessionId });
|
|
896
|
+
const events = messages.map((m) => kodeMessageToSdkMessage(m, sessionId)).filter((e) => Boolean(e));
|
|
897
|
+
return Response.json({ ...base, events });
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// apps/server/src/routes/index.ts
|
|
901
|
+
function createRoutes(args) {
|
|
902
|
+
return {
|
|
903
|
+
async fetch(req, server) {
|
|
904
|
+
const url = new URL(req.url);
|
|
905
|
+
if (args.webuiRoot) {
|
|
906
|
+
const response = maybeServeWebui({ webuiRoot: args.webuiRoot, url });
|
|
907
|
+
if (response) return response;
|
|
908
|
+
}
|
|
909
|
+
if (url.pathname === "/health") {
|
|
910
|
+
return Response.json({
|
|
911
|
+
ok: true,
|
|
912
|
+
version: process.env.npm_package_version ?? null,
|
|
913
|
+
pid: process.pid
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
if (url.pathname === "/api/health") {
|
|
917
|
+
if (!args.checkToken(req))
|
|
918
|
+
return new Response("Unauthorized", { status: 401 });
|
|
919
|
+
return Response.json({ ok: true });
|
|
920
|
+
}
|
|
921
|
+
if (url.pathname.startsWith("/api/")) {
|
|
922
|
+
if (!args.checkToken(req))
|
|
923
|
+
return new Response("Unauthorized", { status: 401 });
|
|
924
|
+
}
|
|
925
|
+
if (url.pathname === "/api/workspaces") {
|
|
926
|
+
try {
|
|
927
|
+
const { workspaces, currentId } = await args.listWorkspaces();
|
|
928
|
+
return Response.json({ workspaces, currentId });
|
|
929
|
+
} catch (err) {
|
|
930
|
+
const only = resolve3(args.cwd);
|
|
931
|
+
return Response.json(
|
|
932
|
+
{
|
|
933
|
+
workspaces: [
|
|
934
|
+
{
|
|
935
|
+
id: only,
|
|
936
|
+
path: only,
|
|
937
|
+
title: basename2(only) || only,
|
|
938
|
+
branch: null,
|
|
939
|
+
isCurrent: true
|
|
940
|
+
}
|
|
941
|
+
],
|
|
942
|
+
currentId: only,
|
|
943
|
+
error: err instanceof Error ? err.message : String(err)
|
|
944
|
+
},
|
|
945
|
+
{ status: 200 }
|
|
946
|
+
);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
const chatResponse = await routeChat(req, {
|
|
950
|
+
sessions: args.sessions,
|
|
951
|
+
echo: args.echo,
|
|
952
|
+
commands: args.commands,
|
|
953
|
+
tools: args.tools,
|
|
954
|
+
toolNames: args.toolNames,
|
|
955
|
+
slashCommands: args.slashCommands
|
|
956
|
+
});
|
|
957
|
+
if (chatResponse) return chatResponse;
|
|
958
|
+
const sessionResponse = await routeSession(req, { cwd: args.cwd });
|
|
959
|
+
if (sessionResponse) return sessionResponse;
|
|
960
|
+
if (url.pathname === "/ws") {
|
|
961
|
+
if (!args.checkToken(req))
|
|
962
|
+
return new Response("Unauthorized", { status: 401 });
|
|
963
|
+
const { workspaces, currentId } = await args.listWorkspaces();
|
|
964
|
+
const requested = url.searchParams.get("workspace");
|
|
965
|
+
const selected = requested && workspaces.some((w) => w.id === requested) ? requested : currentId;
|
|
966
|
+
const selectedCwd = workspaces.find((w) => w.id === selected)?.path ?? resolve3(args.cwd);
|
|
967
|
+
const sessionId = crypto.randomUUID();
|
|
968
|
+
const session = {
|
|
969
|
+
sessionId,
|
|
970
|
+
cwd: selectedCwd,
|
|
971
|
+
ws: null,
|
|
972
|
+
messages: [],
|
|
973
|
+
readFileTimestamps: {},
|
|
974
|
+
responseState: {},
|
|
975
|
+
toolPermissionContext: loadToolPermissionContextFromDisk({
|
|
976
|
+
projectDir: selectedCwd,
|
|
977
|
+
includeKodeProjectConfig: true,
|
|
978
|
+
isBypassPermissionsModeAvailable: true
|
|
979
|
+
}),
|
|
980
|
+
activeAbortController: null,
|
|
981
|
+
inflightPermissionRequests: /* @__PURE__ */ new Map()
|
|
982
|
+
};
|
|
983
|
+
args.sessions.set(sessionId, session);
|
|
984
|
+
const ok = server.upgrade(req, { data: { session } });
|
|
985
|
+
return ok ? void 0 : new Response("Upgrade failed", { status: 400 });
|
|
986
|
+
}
|
|
987
|
+
return new Response("Not found", { status: 404 });
|
|
988
|
+
}
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
// apps/server/src/ws/connection.ts
|
|
993
|
+
function createWebSocketHandlers(args) {
|
|
994
|
+
return {
|
|
995
|
+
open(ws) {
|
|
996
|
+
const session = ws.data.session;
|
|
997
|
+
session.ws = ws;
|
|
998
|
+
sendJson(
|
|
999
|
+
ws,
|
|
1000
|
+
makeSdkInitMessage({
|
|
1001
|
+
sessionId: session.sessionId,
|
|
1002
|
+
cwd: session.cwd,
|
|
1003
|
+
tools: args.toolNames,
|
|
1004
|
+
slashCommands: args.slashCommands
|
|
1005
|
+
})
|
|
1006
|
+
);
|
|
1007
|
+
sendSessionList(ws, {
|
|
1008
|
+
cwd: session.cwd,
|
|
1009
|
+
onError: (message) => sendJson(ws, log("error", message))
|
|
1010
|
+
});
|
|
1011
|
+
},
|
|
1012
|
+
async message(ws, message) {
|
|
1013
|
+
const session = ws.data.session;
|
|
1014
|
+
const parsed = parseClientWsMessage(message);
|
|
1015
|
+
if (parsed.ok === false) {
|
|
1016
|
+
sendJson(ws, log("error", parsed.error));
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
const payload = parsed.value;
|
|
1020
|
+
if (payload.type === "cancel") {
|
|
1021
|
+
try {
|
|
1022
|
+
session.activeAbortController?.abort();
|
|
1023
|
+
} catch {
|
|
1024
|
+
}
|
|
1025
|
+
for (const resolve5 of session.inflightPermissionRequests.values()) {
|
|
1026
|
+
try {
|
|
1027
|
+
resolve5({
|
|
1028
|
+
decision: "deny",
|
|
1029
|
+
rejectionMessage: "Cancelled",
|
|
1030
|
+
updatedInput: null
|
|
1031
|
+
});
|
|
1032
|
+
} catch {
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
session.inflightPermissionRequests.clear();
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
if (payload.type === "permission_response") {
|
|
1039
|
+
const resolve5 = session.inflightPermissionRequests.get(
|
|
1040
|
+
payload.requestId
|
|
1041
|
+
);
|
|
1042
|
+
if (!resolve5) return;
|
|
1043
|
+
session.inflightPermissionRequests.delete(payload.requestId);
|
|
1044
|
+
try {
|
|
1045
|
+
resolve5({
|
|
1046
|
+
decision: payload.decision,
|
|
1047
|
+
updatedInput: payload.updatedInput,
|
|
1048
|
+
rejectionMessage: payload.rejectionMessage
|
|
1049
|
+
});
|
|
1050
|
+
} catch {
|
|
1051
|
+
}
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
if (payload.type === "list_sessions") {
|
|
1055
|
+
sendSessionList(ws, {
|
|
1056
|
+
cwd: session.cwd,
|
|
1057
|
+
onError: (message2) => sendJson(ws, log("error", message2))
|
|
1058
|
+
});
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
if (payload.type === "new_session") {
|
|
1062
|
+
try {
|
|
1063
|
+
session.activeAbortController?.abort();
|
|
1064
|
+
} catch {
|
|
1065
|
+
}
|
|
1066
|
+
for (const resolve5 of session.inflightPermissionRequests.values()) {
|
|
1067
|
+
try {
|
|
1068
|
+
resolve5({
|
|
1069
|
+
decision: "deny",
|
|
1070
|
+
rejectionMessage: "Cancelled",
|
|
1071
|
+
updatedInput: null
|
|
1072
|
+
});
|
|
1073
|
+
} catch {
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
session.inflightPermissionRequests.clear();
|
|
1077
|
+
session.messages = [];
|
|
1078
|
+
session.readFileTimestamps = {};
|
|
1079
|
+
session.responseState = {};
|
|
1080
|
+
session.activeAbortController = null;
|
|
1081
|
+
session.toolPermissionContext = loadToolPermissionContextFromDisk({
|
|
1082
|
+
projectDir: session.cwd,
|
|
1083
|
+
includeKodeProjectConfig: true,
|
|
1084
|
+
isBypassPermissionsModeAvailable: true
|
|
1085
|
+
});
|
|
1086
|
+
const nextId = crypto.randomUUID();
|
|
1087
|
+
args.sessions.delete(session.sessionId);
|
|
1088
|
+
session.sessionId = nextId;
|
|
1089
|
+
args.sessions.set(session.sessionId, session);
|
|
1090
|
+
sendJson(
|
|
1091
|
+
ws,
|
|
1092
|
+
makeSdkInitMessage({
|
|
1093
|
+
sessionId: session.sessionId,
|
|
1094
|
+
cwd: session.cwd,
|
|
1095
|
+
tools: args.toolNames,
|
|
1096
|
+
slashCommands: args.slashCommands
|
|
1097
|
+
})
|
|
1098
|
+
);
|
|
1099
|
+
sendSessionList(ws, {
|
|
1100
|
+
cwd: session.cwd,
|
|
1101
|
+
onError: (message2) => sendJson(ws, log("error", message2))
|
|
1102
|
+
});
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
if (payload.type === "resume") {
|
|
1106
|
+
if (!isUuid(payload.sessionId)) {
|
|
1107
|
+
sendJson(ws, log("error", "Invalid session_id"));
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
try {
|
|
1111
|
+
const loaded = loadSessionMessages({
|
|
1112
|
+
cwd: session.cwd,
|
|
1113
|
+
sessionId: payload.sessionId
|
|
1114
|
+
});
|
|
1115
|
+
session.messages = loaded;
|
|
1116
|
+
session.readFileTimestamps = {};
|
|
1117
|
+
session.responseState = {};
|
|
1118
|
+
try {
|
|
1119
|
+
session.activeAbortController?.abort();
|
|
1120
|
+
} catch {
|
|
1121
|
+
}
|
|
1122
|
+
session.activeAbortController = null;
|
|
1123
|
+
args.sessions.delete(session.sessionId);
|
|
1124
|
+
session.sessionId = payload.sessionId;
|
|
1125
|
+
args.sessions.set(session.sessionId, session);
|
|
1126
|
+
sendJson(
|
|
1127
|
+
ws,
|
|
1128
|
+
makeSdkInitMessage({
|
|
1129
|
+
sessionId: session.sessionId,
|
|
1130
|
+
cwd: session.cwd,
|
|
1131
|
+
tools: args.toolNames,
|
|
1132
|
+
slashCommands: args.slashCommands
|
|
1133
|
+
})
|
|
1134
|
+
);
|
|
1135
|
+
sendJson(ws, { type: "history_begin", sessionId: session.sessionId });
|
|
1136
|
+
for (const m of loaded) {
|
|
1137
|
+
const sdk = kodeMessageToSdkMessage(m, session.sessionId);
|
|
1138
|
+
if (sdk) sendJson(ws, sdk);
|
|
1139
|
+
}
|
|
1140
|
+
sendJson(ws, { type: "history_end", sessionId: session.sessionId });
|
|
1141
|
+
sendSessionList(ws, {
|
|
1142
|
+
cwd: session.cwd,
|
|
1143
|
+
onError: (message2) => sendJson(ws, log("error", message2))
|
|
1144
|
+
});
|
|
1145
|
+
} catch (err) {
|
|
1146
|
+
sendJson(
|
|
1147
|
+
ws,
|
|
1148
|
+
log("error", err instanceof Error ? err.message : String(err))
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
if (payload.type === "prompt") {
|
|
1154
|
+
if (session.activeAbortController) {
|
|
1155
|
+
sendJson(ws, log("error", "Session already has an active prompt"));
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
const wsSend = (outgoing) => sendJson(ws, outgoing);
|
|
1159
|
+
try {
|
|
1160
|
+
await handleChatPrompt({
|
|
1161
|
+
wsSend,
|
|
1162
|
+
session,
|
|
1163
|
+
prompt: payload.prompt,
|
|
1164
|
+
echo: args.echo,
|
|
1165
|
+
commands: args.commands,
|
|
1166
|
+
tools: args.tools,
|
|
1167
|
+
toolNames: args.toolNames,
|
|
1168
|
+
slashCommands: args.slashCommands
|
|
1169
|
+
});
|
|
1170
|
+
} finally {
|
|
1171
|
+
sendSessionList(ws, {
|
|
1172
|
+
cwd: session.cwd,
|
|
1173
|
+
onError: (message2) => sendJson(ws, log("error", message2))
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
},
|
|
1178
|
+
close(ws) {
|
|
1179
|
+
const session = ws.data.session;
|
|
1180
|
+
session.ws = null;
|
|
1181
|
+
try {
|
|
1182
|
+
session.activeAbortController?.abort();
|
|
1183
|
+
} catch {
|
|
1184
|
+
}
|
|
1185
|
+
for (const resolve5 of session.inflightPermissionRequests.values()) {
|
|
1186
|
+
try {
|
|
1187
|
+
resolve5({
|
|
1188
|
+
decision: "deny",
|
|
1189
|
+
rejectionMessage: "Disconnected",
|
|
1190
|
+
updatedInput: null
|
|
1191
|
+
});
|
|
1192
|
+
} catch {
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
session.inflightPermissionRequests.clear();
|
|
1196
|
+
args.sessions.delete(session.sessionId);
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
// apps/server/src/server.ts
|
|
1202
|
+
async function startKodeDaemon(args) {
|
|
1203
|
+
const host = args.host ?? "127.0.0.1";
|
|
1204
|
+
const port = args.port ?? 0;
|
|
1205
|
+
const token = args.token ?? crypto.randomUUID().replace(/-/g, "").slice(0, 9);
|
|
1206
|
+
const cwd = resolve4(args.cwd);
|
|
1207
|
+
const echo = args.echo === true || process.env.KODE_DAEMON_ECHO === "1";
|
|
1208
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
1209
|
+
const webuiDir = typeof args.webuiDir === "string" ? args.webuiDir : detectWebuiDir(moduleDir);
|
|
1210
|
+
const webuiRoot = webuiDir ? resolve4(webuiDir) : null;
|
|
1211
|
+
setOriginalCwd(cwd);
|
|
1212
|
+
await setCwd(cwd);
|
|
1213
|
+
grantReadPermissionForOriginalDir();
|
|
1214
|
+
const tools = await getTools();
|
|
1215
|
+
const toolNames = tools.map((t) => t.name);
|
|
1216
|
+
const commands = [];
|
|
1217
|
+
const slashCommands = [];
|
|
1218
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
1219
|
+
const checkToken = createTokenChecker({ token });
|
|
1220
|
+
const workspaces = createWorkspaceLister({ cwd });
|
|
1221
|
+
const routes = createRoutes({
|
|
1222
|
+
webuiRoot,
|
|
1223
|
+
checkToken,
|
|
1224
|
+
listWorkspaces: workspaces.listWorkspaces,
|
|
1225
|
+
sessions,
|
|
1226
|
+
cwd,
|
|
1227
|
+
echo,
|
|
1228
|
+
commands,
|
|
1229
|
+
tools,
|
|
1230
|
+
toolNames,
|
|
1231
|
+
slashCommands
|
|
1232
|
+
});
|
|
1233
|
+
const websocket = createWebSocketHandlers({
|
|
1234
|
+
sessions,
|
|
1235
|
+
toolNames,
|
|
1236
|
+
slashCommands,
|
|
1237
|
+
commands,
|
|
1238
|
+
tools,
|
|
1239
|
+
echo
|
|
1240
|
+
});
|
|
1241
|
+
const server = await serveNode({
|
|
1242
|
+
hostname: host,
|
|
1243
|
+
port,
|
|
1244
|
+
fetch: routes.fetch,
|
|
1245
|
+
websocket
|
|
1246
|
+
});
|
|
1247
|
+
const displayHost = host === "127.0.0.1" ? "localhost" : host;
|
|
1248
|
+
return {
|
|
1249
|
+
url: `http://${displayHost}:${server.port}?token=${encodeURIComponent(token)}`,
|
|
1250
|
+
host,
|
|
1251
|
+
port: server.port,
|
|
1252
|
+
token,
|
|
1253
|
+
stop: () => {
|
|
1254
|
+
try {
|
|
1255
|
+
server.stop(true);
|
|
1256
|
+
} catch {
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
export {
|
|
1263
|
+
startKodeDaemon
|
|
1264
|
+
};
|