@sinm/kai 1.9.2 → 1.9.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.
Files changed (133) hide show
  1. package/README.md +152 -111
  2. package/dist-cli/kai-cli.js +591 -515
  3. package/dist-electron/renderer/assets/{_baseUniq-CsQsIo3h.js → _baseUniq-DoVY4MSS.js} +1 -1
  4. package/dist-electron/renderer/assets/_baseUniq-DoVY4MSS.js.gz +0 -0
  5. package/dist-electron/renderer/assets/{arc-CnDy2qlp.js → arc--9SigsrL.js} +1 -1
  6. package/dist-electron/renderer/assets/arc--9SigsrL.js.gz +0 -0
  7. package/dist-electron/renderer/assets/{architectureDiagram-Q4EWVU46-7xdcupg1.js → architectureDiagram-Q4EWVU46-B2-KW8QI.js} +5 -5
  8. package/dist-electron/renderer/assets/architectureDiagram-Q4EWVU46-B2-KW8QI.js.gz +0 -0
  9. package/dist-electron/renderer/assets/{blockDiagram-DXYQGD6D-NHzIf6KM.js → blockDiagram-DXYQGD6D-CY8AyV-u.js} +6 -6
  10. package/dist-electron/renderer/assets/blockDiagram-DXYQGD6D-CY8AyV-u.js.gz +0 -0
  11. package/dist-electron/renderer/assets/{c4Diagram-AHTNJAMY-C805hJap.js → c4Diagram-AHTNJAMY-fsUL-kLH.js} +2 -2
  12. package/dist-electron/renderer/assets/c4Diagram-AHTNJAMY-fsUL-kLH.js.gz +0 -0
  13. package/dist-electron/renderer/assets/{channel-yHIQhPj2.js → channel-DFRrClya.js} +1 -1
  14. package/dist-electron/renderer/assets/{chunk-4BX2VUAB-BW86W7DE.js → chunk-4BX2VUAB-C_b460N6.js} +1 -1
  15. package/dist-electron/renderer/assets/{chunk-4TB4RGXK-CiAgH5vp.js → chunk-4TB4RGXK-DznBU0eC.js} +5 -5
  16. package/dist-electron/renderer/assets/chunk-4TB4RGXK-DznBU0eC.js.gz +0 -0
  17. package/dist-electron/renderer/assets/{chunk-55IACEB6-CLYAwM0u.js → chunk-55IACEB6-BEn8Gyw6.js} +1 -1
  18. package/dist-electron/renderer/assets/{chunk-EDXVE4YY-SvJyEgqT.js → chunk-EDXVE4YY-C6Ylq851.js} +1 -1
  19. package/dist-electron/renderer/assets/chunk-EDXVE4YY-C6Ylq851.js.gz +0 -0
  20. package/dist-electron/renderer/assets/{chunk-FMBD7UC4-CTX3SpFe.js → chunk-FMBD7UC4-CNXONWYO.js} +1 -1
  21. package/dist-electron/renderer/assets/{chunk-OYMX7WX6-yuicy5fD.js → chunk-OYMX7WX6-DDnf0PhN.js} +3 -3
  22. package/dist-electron/renderer/assets/chunk-OYMX7WX6-DDnf0PhN.js.gz +0 -0
  23. package/dist-electron/renderer/assets/{chunk-QZHKN3VN-8uwLkZ2k.js → chunk-QZHKN3VN-B_Fq1xCk.js} +1 -1
  24. package/dist-electron/renderer/assets/{chunk-YZCP3GAM-BOYtvFmP.js → chunk-YZCP3GAM-DBTMP9qR.js} +1 -1
  25. package/dist-electron/renderer/assets/chunk-YZCP3GAM-DBTMP9qR.js.gz +0 -0
  26. package/dist-electron/renderer/assets/{classDiagram-6PBFFD2Q-DdqJHrBR.js → classDiagram-6PBFFD2Q-hV0XpFcD.js} +6 -6
  27. package/dist-electron/renderer/assets/{classDiagram-v2-HSJHXN6E-DdqJHrBR.js → classDiagram-v2-HSJHXN6E-hV0XpFcD.js} +6 -6
  28. package/dist-electron/renderer/assets/{clone-CohPIibk.js → clone-CaObVnzv.js} +1 -1
  29. package/dist-electron/renderer/assets/{cose-bilkent-S5V4N54A-B1jjJbx2.js → cose-bilkent-S5V4N54A-YSGABmDO.js} +1 -1
  30. package/dist-electron/renderer/assets/cose-bilkent-S5V4N54A-YSGABmDO.js.gz +0 -0
  31. package/dist-electron/renderer/assets/{dagre-KV5264BT-Cr1UGppV.js → dagre-KV5264BT-D-_h7-5B.js} +6 -6
  32. package/dist-electron/renderer/assets/dagre-KV5264BT-D-_h7-5B.js.gz +0 -0
  33. package/dist-electron/renderer/assets/{diagram-5BDNPKRD-OQB6O17M.js → diagram-5BDNPKRD-DUw8aQXg.js} +6 -6
  34. package/dist-electron/renderer/assets/diagram-5BDNPKRD-DUw8aQXg.js.gz +0 -0
  35. package/dist-electron/renderer/assets/{diagram-G4DWMVQ6-B992OGq3.js → diagram-G4DWMVQ6-B9hMMSLk.js} +6 -6
  36. package/dist-electron/renderer/assets/diagram-G4DWMVQ6-B9hMMSLk.js.gz +0 -0
  37. package/dist-electron/renderer/assets/{diagram-MMDJMWI5-sfDZyGEc.js → diagram-MMDJMWI5-D-3rSXTw.js} +5 -5
  38. package/dist-electron/renderer/assets/diagram-MMDJMWI5-D-3rSXTw.js.gz +0 -0
  39. package/dist-electron/renderer/assets/{diagram-TYMM5635-SAOHwHvV.js → diagram-TYMM5635-DUP-PBv8.js} +5 -5
  40. package/dist-electron/renderer/assets/diagram-TYMM5635-DUP-PBv8.js.gz +0 -0
  41. package/dist-electron/renderer/assets/{erDiagram-SMLLAGMA-B3lOLLG4.js → erDiagram-SMLLAGMA-DytsFZ__.js} +4 -4
  42. package/dist-electron/renderer/assets/erDiagram-SMLLAGMA-DytsFZ__.js.gz +0 -0
  43. package/dist-electron/renderer/assets/{flowDiagram-DWJPFMVM-DM8NWY2I.js → flowDiagram-DWJPFMVM-CzO3oLSq.js} +6 -6
  44. package/dist-electron/renderer/assets/flowDiagram-DWJPFMVM-CzO3oLSq.js.gz +0 -0
  45. package/dist-electron/renderer/assets/{ganttDiagram-T4ZO3ILL-Ck9cM-4F.js → ganttDiagram-T4ZO3ILL-V2OtiUyi.js} +2 -2
  46. package/dist-electron/renderer/assets/ganttDiagram-T4ZO3ILL-V2OtiUyi.js.gz +0 -0
  47. package/dist-electron/renderer/assets/{gitGraphDiagram-UUTBAWPF-BbTlLKCx.js → gitGraphDiagram-UUTBAWPF-Bda-RK4T.js} +6 -6
  48. package/dist-electron/renderer/assets/gitGraphDiagram-UUTBAWPF-Bda-RK4T.js.gz +0 -0
  49. package/dist-electron/renderer/assets/{graph-SD4HIKJw.js → graph-D-bM-Zax.js} +2 -2
  50. package/dist-electron/renderer/assets/graph-D-bM-Zax.js.gz +0 -0
  51. package/dist-electron/renderer/assets/{index-CHaHfSLU.js → index-B6AlLjch.js} +1269 -993
  52. package/dist-electron/renderer/assets/index-B6AlLjch.js.gz +0 -0
  53. package/dist-electron/renderer/assets/{index-CP1VBw7a.css → index-C4yFAlqR.css} +417 -322
  54. package/dist-electron/renderer/assets/{index-CP1VBw7a.css.gz → index-C4yFAlqR.css.gz} +0 -0
  55. package/dist-electron/renderer/assets/{infoDiagram-42DDH7IO-DyxtiwFL.js → infoDiagram-42DDH7IO-D2kpJRbq.js} +4 -4
  56. package/dist-electron/renderer/assets/{ishikawaDiagram-UXIWVN3A-BUrLWa0T.js → ishikawaDiagram-UXIWVN3A-Dkw87Tbt.js} +1 -1
  57. package/dist-electron/renderer/assets/ishikawaDiagram-UXIWVN3A-Dkw87Tbt.js.gz +0 -0
  58. package/dist-electron/renderer/assets/{journeyDiagram-VCZTEJTY-BMmtCdj3.js → journeyDiagram-VCZTEJTY-qJprDQ3l.js} +4 -4
  59. package/dist-electron/renderer/assets/journeyDiagram-VCZTEJTY-qJprDQ3l.js.gz +0 -0
  60. package/dist-electron/renderer/assets/{kanban-definition-6JOO6SKY-OQBC48Se.js → kanban-definition-6JOO6SKY-CMq0peT3.js} +2 -2
  61. package/dist-electron/renderer/assets/kanban-definition-6JOO6SKY-CMq0peT3.js.gz +0 -0
  62. package/dist-electron/renderer/assets/{layout-D2Rz390M.js → layout-CxXj_FIV.js} +4 -4
  63. package/dist-electron/renderer/assets/layout-CxXj_FIV.js.gz +0 -0
  64. package/dist-electron/renderer/assets/{linear-CQh0Mysb.js → linear-CtYMnotP.js} +1 -1
  65. package/dist-electron/renderer/assets/linear-CtYMnotP.js.gz +0 -0
  66. package/dist-electron/renderer/assets/{min-DlS-oIeB.js → min-Bqf3mXd1.js} +2 -2
  67. package/dist-electron/renderer/assets/min-Bqf3mXd1.js.gz +0 -0
  68. package/dist-electron/renderer/assets/{mindmap-definition-QFDTVHPH-aTTTq6Nc.js → mindmap-definition-QFDTVHPH-4RDe2kUB.js} +3 -3
  69. package/dist-electron/renderer/assets/mindmap-definition-QFDTVHPH-4RDe2kUB.js.gz +0 -0
  70. package/dist-electron/renderer/assets/{pieDiagram-DEJITSTG-n1e04sg0.js → pieDiagram-DEJITSTG-BCR81MRq.js} +6 -6
  71. package/dist-electron/renderer/assets/pieDiagram-DEJITSTG-BCR81MRq.js.gz +0 -0
  72. package/dist-electron/renderer/assets/{quadrantDiagram-34T5L4WZ-C-xW2Cqp.js → quadrantDiagram-34T5L4WZ-Bpmh-XvR.js} +2 -2
  73. package/dist-electron/renderer/assets/quadrantDiagram-34T5L4WZ-Bpmh-XvR.js.gz +0 -0
  74. package/dist-electron/renderer/assets/{requirementDiagram-MS252O5E-pnNGwrTw.js → requirementDiagram-MS252O5E-DNvlS_Mc.js} +3 -3
  75. package/dist-electron/renderer/assets/requirementDiagram-MS252O5E-DNvlS_Mc.js.gz +0 -0
  76. package/dist-electron/renderer/assets/{sankeyDiagram-XADWPNL6-CbT_Xb_y.js → sankeyDiagram-XADWPNL6-CIr3ReOD.js} +1 -1
  77. package/dist-electron/renderer/assets/sankeyDiagram-XADWPNL6-CIr3ReOD.js.gz +0 -0
  78. package/dist-electron/renderer/assets/{sequenceDiagram-FGHM5R23-a-9UfTJq.js → sequenceDiagram-FGHM5R23-DXmMVdpu.js} +3 -3
  79. package/dist-electron/renderer/assets/sequenceDiagram-FGHM5R23-DXmMVdpu.js.gz +0 -0
  80. package/dist-electron/renderer/assets/{stateDiagram-FHFEXIEX-LL3JhZd4.js → stateDiagram-FHFEXIEX-BXC-CMaD.js} +8 -8
  81. package/dist-electron/renderer/assets/stateDiagram-FHFEXIEX-BXC-CMaD.js.gz +0 -0
  82. package/dist-electron/renderer/assets/{stateDiagram-v2-QKLJ7IA2-BQfhbm-p.js → stateDiagram-v2-QKLJ7IA2-Cik6aC4X.js} +4 -4
  83. package/dist-electron/renderer/assets/{timeline-definition-GMOUNBTQ-DeBW6Or5.js → timeline-definition-GMOUNBTQ-dWERylNQ.js} +2 -2
  84. package/dist-electron/renderer/assets/timeline-definition-GMOUNBTQ-dWERylNQ.js.gz +0 -0
  85. package/dist-electron/renderer/assets/{vennDiagram-DHZGUBPP-DEq9JF1i.js → vennDiagram-DHZGUBPP-CuO9YmxO.js} +1 -1
  86. package/dist-electron/renderer/assets/vennDiagram-DHZGUBPP-CuO9YmxO.js.gz +0 -0
  87. package/dist-electron/renderer/assets/{wardley-RL74JXVD-ChJWklYY.js → wardley-RL74JXVD-bHTvhGGa.js} +3 -3
  88. package/dist-electron/renderer/assets/wardley-RL74JXVD-bHTvhGGa.js.gz +0 -0
  89. package/dist-electron/renderer/assets/{wardleyDiagram-NUSXRM2D-CIROAFHI.js → wardleyDiagram-NUSXRM2D-B8WNKIUZ.js} +5 -5
  90. package/dist-electron/renderer/assets/wardleyDiagram-NUSXRM2D-B8WNKIUZ.js.gz +0 -0
  91. package/dist-electron/renderer/assets/{xychartDiagram-5P7HB3ND-BedH4Z65.js → xychartDiagram-5P7HB3ND-D6pt_QSE.js} +2 -2
  92. package/dist-electron/renderer/assets/xychartDiagram-5P7HB3ND-D6pt_QSE.js.gz +0 -0
  93. package/dist-electron/renderer/index.html +2 -2
  94. package/package.json +1 -1
  95. package/dist-electron/renderer/assets/_baseUniq-CsQsIo3h.js.gz +0 -0
  96. package/dist-electron/renderer/assets/arc-CnDy2qlp.js.gz +0 -0
  97. package/dist-electron/renderer/assets/architectureDiagram-Q4EWVU46-7xdcupg1.js.gz +0 -0
  98. package/dist-electron/renderer/assets/blockDiagram-DXYQGD6D-NHzIf6KM.js.gz +0 -0
  99. package/dist-electron/renderer/assets/c4Diagram-AHTNJAMY-C805hJap.js.gz +0 -0
  100. package/dist-electron/renderer/assets/chunk-4TB4RGXK-CiAgH5vp.js.gz +0 -0
  101. package/dist-electron/renderer/assets/chunk-EDXVE4YY-SvJyEgqT.js.gz +0 -0
  102. package/dist-electron/renderer/assets/chunk-OYMX7WX6-yuicy5fD.js.gz +0 -0
  103. package/dist-electron/renderer/assets/chunk-YZCP3GAM-BOYtvFmP.js.gz +0 -0
  104. package/dist-electron/renderer/assets/cose-bilkent-S5V4N54A-B1jjJbx2.js.gz +0 -0
  105. package/dist-electron/renderer/assets/dagre-KV5264BT-Cr1UGppV.js.gz +0 -0
  106. package/dist-electron/renderer/assets/diagram-5BDNPKRD-OQB6O17M.js.gz +0 -0
  107. package/dist-electron/renderer/assets/diagram-G4DWMVQ6-B992OGq3.js.gz +0 -0
  108. package/dist-electron/renderer/assets/diagram-MMDJMWI5-sfDZyGEc.js.gz +0 -0
  109. package/dist-electron/renderer/assets/diagram-TYMM5635-SAOHwHvV.js.gz +0 -0
  110. package/dist-electron/renderer/assets/erDiagram-SMLLAGMA-B3lOLLG4.js.gz +0 -0
  111. package/dist-electron/renderer/assets/flowDiagram-DWJPFMVM-DM8NWY2I.js.gz +0 -0
  112. package/dist-electron/renderer/assets/ganttDiagram-T4ZO3ILL-Ck9cM-4F.js.gz +0 -0
  113. package/dist-electron/renderer/assets/gitGraphDiagram-UUTBAWPF-BbTlLKCx.js.gz +0 -0
  114. package/dist-electron/renderer/assets/graph-SD4HIKJw.js.gz +0 -0
  115. package/dist-electron/renderer/assets/index-CHaHfSLU.js.gz +0 -0
  116. package/dist-electron/renderer/assets/ishikawaDiagram-UXIWVN3A-BUrLWa0T.js.gz +0 -0
  117. package/dist-electron/renderer/assets/journeyDiagram-VCZTEJTY-BMmtCdj3.js.gz +0 -0
  118. package/dist-electron/renderer/assets/kanban-definition-6JOO6SKY-OQBC48Se.js.gz +0 -0
  119. package/dist-electron/renderer/assets/layout-D2Rz390M.js.gz +0 -0
  120. package/dist-electron/renderer/assets/linear-CQh0Mysb.js.gz +0 -0
  121. package/dist-electron/renderer/assets/min-DlS-oIeB.js.gz +0 -0
  122. package/dist-electron/renderer/assets/mindmap-definition-QFDTVHPH-aTTTq6Nc.js.gz +0 -0
  123. package/dist-electron/renderer/assets/pieDiagram-DEJITSTG-n1e04sg0.js.gz +0 -0
  124. package/dist-electron/renderer/assets/quadrantDiagram-34T5L4WZ-C-xW2Cqp.js.gz +0 -0
  125. package/dist-electron/renderer/assets/requirementDiagram-MS252O5E-pnNGwrTw.js.gz +0 -0
  126. package/dist-electron/renderer/assets/sankeyDiagram-XADWPNL6-CbT_Xb_y.js.gz +0 -0
  127. package/dist-electron/renderer/assets/sequenceDiagram-FGHM5R23-a-9UfTJq.js.gz +0 -0
  128. package/dist-electron/renderer/assets/stateDiagram-FHFEXIEX-LL3JhZd4.js.gz +0 -0
  129. package/dist-electron/renderer/assets/timeline-definition-GMOUNBTQ-DeBW6Or5.js.gz +0 -0
  130. package/dist-electron/renderer/assets/vennDiagram-DHZGUBPP-DEq9JF1i.js.gz +0 -0
  131. package/dist-electron/renderer/assets/wardley-RL74JXVD-ChJWklYY.js.gz +0 -0
  132. package/dist-electron/renderer/assets/wardleyDiagram-NUSXRM2D-CIROAFHI.js.gz +0 -0
  133. package/dist-electron/renderer/assets/xychartDiagram-5P7HB3ND-BedH4Z65.js.gz +0 -0
@@ -34,7 +34,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
34
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
35
 
36
36
  // src/shared/ipc-events.ts
37
- var IPC_SEND_USER_MESSAGE, IPC_STOP_RUN, IPC_CREATE_NEW_SESSION, IPC_COMPACT_CONVERSATION, IPC_CANCEL_QUEUED_MESSAGES, IPC_REQUEST_CONVERSATION_SNAPSHOT, IPC_CONVERSATION_EVENT, IPC_GET_SETTINGS, IPC_SAVE_SETTINGS, IPC_FETCH_MODELS, IPC_GET_MCP_SERVERS, IPC_SAVE_MCP_SERVERS, IPC_TEST_MCP_SERVER, IPC_GET_SKILLS, IPC_GET_SKILL, IPC_TOGGLE_SKILL, IPC_CREATE_AGENT, IPC_GET_AGENT, IPC_GET_AGENT_CONFIG, IPC_LIST_AGENTS, IPC_UPDATE_AGENT, IPC_DELETE_AGENT, IPC_SET_AGENT_AVATAR, IPC_REMOVE_AGENT_AVATAR, IPC_OPTIMIZE_AGENT_DESCRIPTION, IPC_GET_AGENT_CHANNELS, IPC_UPDATE_AGENT_CHANNELS, IPC_SWITCH_CHANNEL, IPC_CREATE_CONVERSATION, IPC_GET_CONVERSATION, IPC_LIST_CONVERSATIONS, IPC_GET_CONVERSATION_AGENTS, IPC_UPDATE_CONVERSATION, IPC_DELETE_CONVERSATION, IPC_CREATE_GROUP, IPC_GET_GROUP, IPC_UPDATE_GROUP, IPC_DELETE_GROUP, IPC_SET_GROUP_AVATAR, IPC_REMOVE_GROUP_AVATAR, IPC_GET_GROUP_MEMBERS, IPC_GET_TEAM_MEMORY, IPC_SAVE_GROUP_FILE, IPC_GET_GROUP_SETTINGS, IPC_GET_GROUP_MEMORY, IPC_LIST_GROUP_THREADS, IPC_GET_GROUP_THREAD, IPC_CREATE_GROUP_THREAD, IPC_UPDATE_GROUP_THREAD, IPC_DELETE_GROUP_THREAD, IPC_ARCHIVE_GROUP_THREAD, IPC_GET_MESSAGES, IPC_GET_MESSAGE, IPC_CREATE_LLM_CHANNEL, IPC_GET_LLM_CHANNEL, IPC_LIST_LLM_CHANNELS, IPC_UPDATE_LLM_CHANNEL, IPC_DELETE_LLM_CHANNEL, IPC_SET_DEFAULT_LLM_CHANNEL, IPC_GET_WORKSPACE_FILE, IPC_UPDATE_WORKSPACE_FILE, IPC_LIST_WORKSPACE_FILES, IPC_OPEN_WORKSPACE_DIR, IPC_OPEN_CHAT_DATA_DIR, IPC_GET_SEARCH_ENGINES, IPC_ADD_CUSTOM_ENGINE, IPC_UPDATE_CUSTOM_ENGINE, IPC_DELETE_CUSTOM_ENGINE, IPC_SET_DEFAULT_ENGINE, IPC_CREATE_SCHEDULED_TASK, IPC_GET_SCHEDULED_TASK, IPC_LIST_SCHEDULED_TASKS, IPC_UPDATE_SCHEDULED_TASK, IPC_DELETE_SCHEDULED_TASK, IPC_TOGGLE_SCHEDULED_TASK, IPC_LIST_TASK_EXECUTIONS, IPC_TASK_EXECUTION_EVENT, IPC_TRIGGER_MEMORY_UPDATE, IPC_GET_NIGHTLY_MEMORY_CONFIG, IPC_UPDATE_NIGHTLY_MEMORY_CONFIG, IPC_RUN_NIGHTLY_MEMORY_NOW, IPC_LIST_NIGHTLY_MEMORY_EXECUTIONS, IPC_OPEN_EXTERNAL_URL, IPC_OPEN_LOCAL_PATH, IPC_READ_FILE_CONTENT, IPC_SHOW_LOCAL_ITEM_IN_FOLDER, IPC_COPY_IMAGE_TO_CLIPBOARD, IPC_UPLOAD_ATTACHMENT, IPC_OPEN_ATTACHMENT, IPC_MEMORY_UPDATE_PROGRESS, IPC_HEALTH_GET_ALL, IPC_HEALTH_GET, IPC_HEALTH_UPDATE, IPC_REMOTE_ACCESS_START, IPC_REMOTE_ACCESS_STOP, IPC_REMOTE_ACCESS_ROTATE, IPC_REMOTE_ACCESS_STATUS, IPC_GET_APP_INFO, IPC_GET_RELEASE_NOTES, IPC_UPDATE_CHECK, IPC_UPDATE_DOWNLOAD, IPC_UPDATE_INSTALL, IPC_UPDATE_STATUS, IPC_UPDATE_STATUS_EVENT, IPC_UPDATE_AVAILABLE_EVENT, IPC_UPDATE_ERROR_EVENT, IPC_GET_PINNED, IPC_TOGGLE_PIN, IPC_CHANNEL_LIST, IPC_CHANNEL_BIND, IPC_CHANNEL_UPDATE_TARGET, IPC_CHANNEL_UNBIND, IPC_CHANNEL_TEST, IPC_CHANNEL_RECONNECT, IPC_CHANNEL_STATUS, IPC_CHANNEL_QRCODE, IPC_CHANNEL_QRCODE_POLL, IPC_CHANNEL_WECHAT_PERSONAL_QRCODE, IPC_CHANNEL_WECHAT_PERSONAL_QRCODE_POLL, IPC_TELEMETRY_TRACK, IPC_TELEMETRY_FEEDBACK, IPC_TELEMETRY_SET_ENABLED, IPC_TELEMETRY_IS_ENABLED;
37
+ var IPC_SEND_USER_MESSAGE, IPC_STOP_RUN, IPC_CREATE_NEW_SESSION, IPC_COMPACT_CONVERSATION, IPC_CANCEL_QUEUED_MESSAGES, IPC_REQUEST_CONVERSATION_SNAPSHOT, IPC_CONVERSATION_EVENT, IPC_GET_SETTINGS, IPC_SAVE_SETTINGS, IPC_FETCH_MODELS, IPC_GET_MCP_SERVERS, IPC_SAVE_MCP_SERVERS, IPC_TEST_MCP_SERVER, IPC_GET_SKILLS, IPC_GET_SKILL, IPC_TOGGLE_SKILL, IPC_CREATE_AGENT, IPC_GET_AGENT, IPC_GET_AGENT_CONFIG, IPC_LIST_AGENTS, IPC_UPDATE_AGENT, IPC_DELETE_AGENT, IPC_SET_AGENT_AVATAR, IPC_REMOVE_AGENT_AVATAR, IPC_OPTIMIZE_AGENT_DESCRIPTION, IPC_GET_AGENT_CHANNELS, IPC_UPDATE_AGENT_CHANNELS, IPC_SWITCH_CHANNEL, IPC_CREATE_CONVERSATION, IPC_GET_CONVERSATION, IPC_LIST_CONVERSATIONS, IPC_GET_CONVERSATION_AGENTS, IPC_UPDATE_CONVERSATION, IPC_DELETE_CONVERSATION, IPC_CREATE_GROUP, IPC_GET_GROUP, IPC_UPDATE_GROUP, IPC_DELETE_GROUP, IPC_SET_GROUP_AVATAR, IPC_REMOVE_GROUP_AVATAR, IPC_GET_GROUP_MEMBERS, IPC_GET_TEAM_MEMORY, IPC_SAVE_GROUP_FILE, IPC_GET_GROUP_SETTINGS, IPC_GET_GROUP_MEMORY, IPC_LIST_GROUP_THREADS, IPC_GET_GROUP_THREAD, IPC_CREATE_GROUP_THREAD, IPC_UPDATE_GROUP_THREAD, IPC_DELETE_GROUP_THREAD, IPC_ARCHIVE_GROUP_THREAD, IPC_GET_MESSAGES, IPC_GET_MESSAGE, IPC_CREATE_LLM_CHANNEL, IPC_GET_LLM_CHANNEL, IPC_LIST_LLM_CHANNELS, IPC_UPDATE_LLM_CHANNEL, IPC_DELETE_LLM_CHANNEL, IPC_SET_DEFAULT_LLM_CHANNEL, IPC_GET_WORKSPACE_FILE, IPC_UPDATE_WORKSPACE_FILE, IPC_LIST_WORKSPACE_FILES, IPC_OPEN_WORKSPACE_DIR, IPC_OPEN_CHAT_DATA_DIR, IPC_GET_SEARCH_ENGINES, IPC_ADD_CUSTOM_ENGINE, IPC_UPDATE_CUSTOM_ENGINE, IPC_DELETE_CUSTOM_ENGINE, IPC_SET_DEFAULT_ENGINE, IPC_CREATE_SCHEDULED_TASK, IPC_GET_SCHEDULED_TASK, IPC_LIST_SCHEDULED_TASKS, IPC_UPDATE_SCHEDULED_TASK, IPC_DELETE_SCHEDULED_TASK, IPC_TOGGLE_SCHEDULED_TASK, IPC_LIST_TASK_EXECUTIONS, IPC_TASK_EXECUTION_EVENT, IPC_TRIGGER_MEMORY_UPDATE, IPC_GET_NIGHTLY_MEMORY_CONFIG, IPC_UPDATE_NIGHTLY_MEMORY_CONFIG, IPC_RUN_NIGHTLY_MEMORY_NOW, IPC_LIST_NIGHTLY_MEMORY_EXECUTIONS, IPC_OPEN_EXTERNAL_URL, IPC_OPEN_LOCAL_PATH, IPC_READ_FILE_CONTENT, IPC_SHOW_LOCAL_ITEM_IN_FOLDER, IPC_COPY_IMAGE_TO_CLIPBOARD, IPC_UPLOAD_ATTACHMENT, IPC_OPEN_ATTACHMENT, IPC_MEMORY_UPDATE_PROGRESS, IPC_HEALTH_GET_ALL, IPC_HEALTH_GET, IPC_HEALTH_UPDATE, IPC_REMOTE_ACCESS_START, IPC_REMOTE_ACCESS_STOP, IPC_REMOTE_ACCESS_ROTATE, IPC_REMOTE_ACCESS_STATUS, IPC_GET_APP_INFO, IPC_GET_RELEASE_NOTES, IPC_UPDATE_CHECK, IPC_UPDATE_DOWNLOAD, IPC_UPDATE_INSTALL, IPC_UPDATE_STATUS, IPC_UPDATE_STATUS_EVENT, IPC_UPDATE_AVAILABLE_EVENT, IPC_UPDATE_PROGRESS_EVENT, IPC_UPDATE_DOWNLOADED_EVENT, IPC_UPDATE_ERROR_EVENT, IPC_GET_PINNED, IPC_TOGGLE_PIN, IPC_CHANNEL_LIST, IPC_CHANNEL_BIND, IPC_CHANNEL_UPDATE_TARGET, IPC_CHANNEL_UNBIND, IPC_CHANNEL_TEST, IPC_CHANNEL_RECONNECT, IPC_CHANNEL_STATUS, IPC_CHANNEL_QRCODE, IPC_CHANNEL_QRCODE_POLL, IPC_CHANNEL_WECHAT_PERSONAL_QRCODE, IPC_CHANNEL_WECHAT_PERSONAL_QRCODE_POLL, IPC_TELEMETRY_TRACK, IPC_TELEMETRY_FEEDBACK, IPC_TELEMETRY_SET_ENABLED, IPC_TELEMETRY_IS_ENABLED;
38
38
  var init_ipc_events = __esm({
39
39
  "src/shared/ipc-events.ts"() {
40
40
  "use strict";
@@ -143,6 +143,8 @@ var init_ipc_events = __esm({
143
143
  IPC_UPDATE_STATUS = "UPDATE_STATUS";
144
144
  IPC_UPDATE_STATUS_EVENT = "UPDATE_STATUS_EVENT";
145
145
  IPC_UPDATE_AVAILABLE_EVENT = "UPDATE_AVAILABLE_EVENT";
146
+ IPC_UPDATE_PROGRESS_EVENT = "UPDATE_PROGRESS_EVENT";
147
+ IPC_UPDATE_DOWNLOADED_EVENT = "UPDATE_DOWNLOADED_EVENT";
146
148
  IPC_UPDATE_ERROR_EVENT = "UPDATE_ERROR_EVENT";
147
149
  IPC_GET_PINNED = "GET_PINNED";
148
150
  IPC_TOGGLE_PIN = "TOGGLE_PIN";
@@ -85613,29 +85615,48 @@ var init_agent_identity = __esm({
85613
85615
  }
85614
85616
  });
85615
85617
 
85616
- // src/adapters/storage/agent-file-store.ts
85617
- function getAgentRootDir(agentId) {
85618
- const workspaceDir = getAgentWorkspaceDir(agentId);
85619
- return (0, import_path5.join)(workspaceDir, "..");
85620
- }
85621
- function getMetaPath(agentId) {
85622
- return (0, import_path5.join)(getAgentRootDir(agentId), META_FILE);
85618
+ // src/adapters/storage/json-file.ts
85619
+ async function atomicWriteJson(path10, data2) {
85620
+ await atomicWriteText(path10, `${JSON.stringify(data2, null, 2)}
85621
+ `);
85623
85622
  }
85624
- function getConfigPath(agentId) {
85625
- return (0, import_path5.join)(getAgentRootDir(agentId), CONFIG_FILE);
85623
+ async function readJsonFile2(path10) {
85624
+ if (!(0, import_fs5.existsSync)(path10)) return null;
85625
+ const raw = await (0, import_promises3.readFile)(path10, "utf-8");
85626
+ return JSON.parse(raw);
85626
85627
  }
85627
- async function atomicWriteJson(path10, data2) {
85628
+ async function atomicWriteText(path10, content) {
85628
85629
  const dir = (0, import_path5.dirname)(path10);
85629
85630
  await (0, import_promises3.mkdir)(dir, { recursive: true });
85630
85631
  const tmp = `${path10}.tmp`;
85631
- await (0, import_promises3.writeFile)(tmp, `${JSON.stringify(data2, null, 2)}
85632
- `, "utf-8");
85632
+ await (0, import_promises3.writeFile)(tmp, content, "utf-8");
85633
85633
  await (0, import_promises3.rename)(tmp, path10);
85634
85634
  }
85635
- async function readJsonFile2(path10) {
85635
+ async function readTextFile(path10) {
85636
85636
  if (!(0, import_fs5.existsSync)(path10)) return null;
85637
- const raw = await (0, import_promises3.readFile)(path10, "utf-8");
85638
- return JSON.parse(raw);
85637
+ const content = await (0, import_promises3.readFile)(path10, "utf-8");
85638
+ return content || null;
85639
+ }
85640
+ var import_path5, import_promises3, import_fs5;
85641
+ var init_json_file = __esm({
85642
+ "src/adapters/storage/json-file.ts"() {
85643
+ "use strict";
85644
+ import_path5 = require("path");
85645
+ import_promises3 = require("fs/promises");
85646
+ import_fs5 = require("fs");
85647
+ }
85648
+ });
85649
+
85650
+ // src/adapters/storage/agent-file-store.ts
85651
+ function getAgentRootDir(agentId) {
85652
+ const workspaceDir = getAgentWorkspaceDir(agentId);
85653
+ return (0, import_path6.join)(workspaceDir, "..");
85654
+ }
85655
+ function getMetaPath(agentId) {
85656
+ return (0, import_path6.join)(getAgentRootDir(agentId), META_FILE);
85657
+ }
85658
+ function getConfigPath(agentId) {
85659
+ return (0, import_path6.join)(getAgentRootDir(agentId), CONFIG_FILE);
85639
85660
  }
85640
85661
  function normalizeFallbacks(channelConfig) {
85641
85662
  return [...channelConfig?.channels ?? []].filter((entry) => entry.priority > 0).sort((a, b) => a.priority - b.priority).map((entry, index2) => ({
@@ -85734,17 +85755,18 @@ function deriveChannelConfig(agentId, config3) {
85734
85755
  }
85735
85756
  return buildChannelConfigFromModels(agentId, config3.models);
85736
85757
  }
85737
- var import_path5, import_promises3, import_fs5, META_FILE, CONFIG_FILE, SCHEMA_VERSION, AgentFileStore, agentFileStore;
85758
+ var import_path6, import_promises4, import_fs6, META_FILE, CONFIG_FILE, SCHEMA_VERSION, AgentFileStore, agentFileStore;
85738
85759
  var init_agent_file_store = __esm({
85739
85760
  "src/adapters/storage/agent-file-store.ts"() {
85740
85761
  "use strict";
85741
- import_path5 = require("path");
85742
- import_promises3 = require("fs/promises");
85743
- import_fs5 = require("fs");
85762
+ import_path6 = require("path");
85763
+ import_promises4 = require("fs/promises");
85764
+ import_fs6 = require("fs");
85744
85765
  init_AgentConfigModel();
85745
85766
  init_agentConfigUtils();
85746
85767
  init_workspace();
85747
85768
  init_agent_identity();
85769
+ init_json_file();
85748
85770
  META_FILE = "meta.json";
85749
85771
  CONFIG_FILE = "config.json";
85750
85772
  SCHEMA_VERSION = 1;
@@ -85752,9 +85774,9 @@ var init_agent_file_store = __esm({
85752
85774
  metaCache = /* @__PURE__ */ new Map();
85753
85775
  configCache = /* @__PURE__ */ new Map();
85754
85776
  async listMeta() {
85755
- const parentDir = (0, import_path5.dirname)(getAgentRootDir("placeholder"));
85756
- if (!(0, import_fs5.existsSync)(parentDir)) return [];
85757
- const entries = await (0, import_promises3.readdir)(parentDir, { withFileTypes: true });
85777
+ const parentDir = (0, import_path6.dirname)(getAgentRootDir("placeholder"));
85778
+ if (!(0, import_fs6.existsSync)(parentDir)) return [];
85779
+ const entries = await (0, import_promises4.readdir)(parentDir, { withFileTypes: true });
85758
85780
  const agents = await Promise.all(
85759
85781
  entries.filter((entry) => entry.isDirectory()).map(async (entry) => this.readMeta(entry.name))
85760
85782
  );
@@ -85789,12 +85811,12 @@ var init_agent_file_store = __esm({
85789
85811
  this.configCache.set(config3.agentId, fromConfigFile(config3.agentId, file2));
85790
85812
  }
85791
85813
  async exists(agentId) {
85792
- return (0, import_fs5.existsSync)(getMetaPath(agentId)) && (0, import_fs5.existsSync)(getConfigPath(agentId));
85814
+ return (0, import_fs6.existsSync)(getMetaPath(agentId)) && (0, import_fs6.existsSync)(getConfigPath(agentId));
85793
85815
  }
85794
85816
  async delete(agentId) {
85795
85817
  this.metaCache.delete(agentId);
85796
85818
  this.configCache.delete(agentId);
85797
- await (0, import_promises3.rm)(getAgentRootDir(agentId), { force: true, recursive: true });
85819
+ await (0, import_promises4.rm)(getAgentRootDir(agentId), { force: true, recursive: true });
85798
85820
  }
85799
85821
  clear(agentId) {
85800
85822
  if (agentId) {
@@ -105511,56 +105533,31 @@ var require_index_cjs = __commonJS({
105511
105533
 
105512
105534
  // src/adapters/storage/group-file-store.ts
105513
105535
  function getGroupsRootDir() {
105514
- return (0, import_path8.join)(config.getAppDataPath(), "groups");
105536
+ return (0, import_path9.join)(config.getAppDataPath(), "groups");
105515
105537
  }
105516
105538
  function getGroupDir(groupId) {
105517
- return (0, import_path8.join)(getGroupsRootDir(), groupId);
105539
+ return (0, import_path9.join)(getGroupsRootDir(), groupId);
105518
105540
  }
105519
105541
  function getMetaPath2(groupId) {
105520
- return (0, import_path8.join)(getGroupDir(groupId), META_FILE2);
105542
+ return (0, import_path9.join)(getGroupDir(groupId), META_FILE2);
105521
105543
  }
105522
105544
  function getConfigPath2(groupId) {
105523
- return (0, import_path8.join)(getGroupDir(groupId), CONFIG_FILE2);
105545
+ return (0, import_path9.join)(getGroupDir(groupId), CONFIG_FILE2);
105524
105546
  }
105525
105547
  function getMembersPath(groupId) {
105526
- return (0, import_path8.join)(getGroupDir(groupId), MEMBERS_FILE);
105548
+ return (0, import_path9.join)(getGroupDir(groupId), MEMBERS_FILE);
105527
105549
  }
105528
105550
  function getGroupMemoryPath(groupId) {
105529
- return (0, import_path8.join)(getGroupDir(groupId), GROUP_MEMORY_FILE);
105551
+ return (0, import_path9.join)(getGroupDir(groupId), GROUP_MEMORY_FILE);
105530
105552
  }
105531
105553
  function getLegacyTeamMemoryPath(groupId) {
105532
- return (0, import_path8.join)(getGroupDir(groupId), TEAM_MEMORY_FILE);
105554
+ return (0, import_path9.join)(getGroupDir(groupId), TEAM_MEMORY_FILE);
105533
105555
  }
105534
105556
  function getGroupSettingsPath(groupId) {
105535
- return (0, import_path8.join)(getGroupDir(groupId), GROUP_SETTINGS_FILE);
105557
+ return (0, import_path9.join)(getGroupDir(groupId), GROUP_SETTINGS_FILE);
105536
105558
  }
105537
105559
  function getGroupMemoryDir(groupId) {
105538
- return (0, import_path8.join)(getGroupDir(groupId), GROUP_MEMORY_DIR);
105539
- }
105540
- async function atomicWriteJson2(path10, data2) {
105541
- const dir = (0, import_path8.dirname)(path10);
105542
- await (0, import_promises5.mkdir)(dir, { recursive: true });
105543
- const tmp = `${path10}.tmp`;
105544
- await (0, import_promises5.writeFile)(tmp, `${JSON.stringify(data2, null, 2)}
105545
- `, "utf-8");
105546
- await (0, import_promises5.rename)(tmp, path10);
105547
- }
105548
- async function readJsonFile3(path10) {
105549
- if (!(0, import_fs8.existsSync)(path10)) return null;
105550
- const raw = await (0, import_promises5.readFile)(path10, "utf-8");
105551
- return JSON.parse(raw);
105552
- }
105553
- async function atomicWriteText(path10, content) {
105554
- const dir = (0, import_path8.dirname)(path10);
105555
- await (0, import_promises5.mkdir)(dir, { recursive: true });
105556
- const tmp = `${path10}.tmp`;
105557
- await (0, import_promises5.writeFile)(tmp, content, "utf-8");
105558
- await (0, import_promises5.rename)(tmp, path10);
105559
- }
105560
- async function readTextFile(path10) {
105561
- if (!(0, import_fs8.existsSync)(path10)) return null;
105562
- const content = await (0, import_promises5.readFile)(path10, "utf-8");
105563
- return content || null;
105560
+ return (0, import_path9.join)(getGroupDir(groupId), GROUP_MEMORY_DIR);
105564
105561
  }
105565
105562
  function metaToIGroup(meta3, groupConfig, members, groupMemory, groupSettings) {
105566
105563
  return {
@@ -105585,15 +105582,16 @@ function metaToIGroup(meta3, groupConfig, members, groupMemory, groupSettings) {
105585
105582
  updatedAt: meta3.updatedAt
105586
105583
  };
105587
105584
  }
105588
- var import_path8, import_promises5, import_fs8, META_FILE2, CONFIG_FILE2, MEMBERS_FILE, TEAM_MEMORY_FILE, GROUP_MEMORY_FILE, GROUP_SETTINGS_FILE, GROUP_MEMORY_DIR, SCHEMA_VERSION2, ALLOWED_SAVE_FILENAMES, GroupFileStore, groupFileStore;
105585
+ var import_path9, import_promises6, import_fs9, META_FILE2, CONFIG_FILE2, MEMBERS_FILE, TEAM_MEMORY_FILE, GROUP_MEMORY_FILE, GROUP_SETTINGS_FILE, GROUP_MEMORY_DIR, SCHEMA_VERSION2, ALLOWED_SAVE_FILENAMES, GroupFileStore, groupFileStore;
105589
105586
  var init_group_file_store = __esm({
105590
105587
  "src/adapters/storage/group-file-store.ts"() {
105591
105588
  "use strict";
105592
- import_path8 = require("path");
105593
- import_promises5 = require("fs/promises");
105594
- import_fs8 = require("fs");
105589
+ import_path9 = require("path");
105590
+ import_promises6 = require("fs/promises");
105591
+ import_fs9 = require("fs");
105595
105592
  init_config();
105596
105593
  init_id2();
105594
+ init_json_file();
105597
105595
  META_FILE2 = "meta.json";
105598
105596
  CONFIG_FILE2 = "config.json";
105599
105597
  MEMBERS_FILE = "members.json";
@@ -105608,8 +105606,8 @@ var init_group_file_store = __esm({
105608
105606
  // --- Read operations ---
105609
105607
  async list() {
105610
105608
  const rootDir = getGroupsRootDir();
105611
- if (!(0, import_fs8.existsSync)(rootDir)) return [];
105612
- const entries = await (0, import_promises5.readdir)(rootDir, { withFileTypes: true });
105609
+ if (!(0, import_fs9.existsSync)(rootDir)) return [];
105610
+ const entries = await (0, import_promises6.readdir)(rootDir, { withFileTypes: true });
105613
105611
  const groups = await Promise.all(
105614
105612
  entries.filter((entry) => entry.isDirectory()).map((entry) => this.get(entry.name))
105615
105613
  );
@@ -105618,9 +105616,9 @@ var init_group_file_store = __esm({
105618
105616
  async get(groupId) {
105619
105617
  const cached2 = this.cache.get(groupId);
105620
105618
  if (cached2) return cached2;
105621
- const meta3 = await readJsonFile3(getMetaPath2(groupId));
105619
+ const meta3 = await readJsonFile2(getMetaPath2(groupId));
105622
105620
  if (!meta3) return null;
105623
- const configFile = await readJsonFile3(getConfigPath2(groupId));
105621
+ const configFile = await readJsonFile2(getConfigPath2(groupId));
105624
105622
  const defaultConfig = {
105625
105623
  version: SCHEMA_VERSION2,
105626
105624
  strategy: "sequential",
@@ -105628,7 +105626,7 @@ var init_group_file_store = __esm({
105628
105626
  timeout: 3e5,
105629
105627
  updatedAt: meta3.updatedAt
105630
105628
  };
105631
- const membersFile = await readJsonFile3(getMembersPath(groupId));
105629
+ const membersFile = await readJsonFile2(getMembersPath(groupId));
105632
105630
  const members = membersFile?.members ?? [];
105633
105631
  const groupMemory = await this.readGroupMemoryContent(groupId);
105634
105632
  const groupSettings = await readTextFile(getGroupSettingsPath(groupId));
@@ -105637,7 +105635,7 @@ var init_group_file_store = __esm({
105637
105635
  return group;
105638
105636
  }
105639
105637
  async exists(groupId) {
105640
- return (0, import_fs8.existsSync)(getMetaPath2(groupId));
105638
+ return (0, import_fs9.existsSync)(getMetaPath2(groupId));
105641
105639
  }
105642
105640
  // --- Write operations ---
105643
105641
  async create(name21, speakerId, memberIds, groupConfig, avatar) {
@@ -105663,18 +105661,18 @@ var init_group_file_store = __esm({
105663
105661
  members: memberIds,
105664
105662
  updatedAt: now2
105665
105663
  };
105666
- await (0, import_promises5.mkdir)(getGroupDir(id), { recursive: true });
105664
+ await (0, import_promises6.mkdir)(getGroupDir(id), { recursive: true });
105667
105665
  await Promise.all([
105668
- atomicWriteJson2(getMetaPath2(id), meta3),
105669
- atomicWriteJson2(getConfigPath2(id), configFile),
105670
- atomicWriteJson2(getMembersPath(id), members)
105666
+ atomicWriteJson(getMetaPath2(id), meta3),
105667
+ atomicWriteJson(getConfigPath2(id), configFile),
105668
+ atomicWriteJson(getMembersPath(id), members)
105671
105669
  ]);
105672
105670
  const group = metaToIGroup(meta3, configFile, memberIds, null, null);
105673
105671
  this.cache.set(id, group);
105674
105672
  return id;
105675
105673
  }
105676
105674
  async update(groupId, updates) {
105677
- const meta3 = await readJsonFile3(getMetaPath2(groupId));
105675
+ const meta3 = await readJsonFile2(getMetaPath2(groupId));
105678
105676
  if (!meta3) throw new Error(`Group not found: ${groupId}`);
105679
105677
  const now2 = Date.now();
105680
105678
  meta3.updatedAt = now2;
@@ -105682,7 +105680,7 @@ var init_group_file_store = __esm({
105682
105680
  if (updates.avatar !== void 0) meta3.avatar = updates.avatar;
105683
105681
  const speakerValue = updates.defaultSpeakerId ?? updates.speakerId;
105684
105682
  if (speakerValue !== void 0) meta3.speakerId = speakerValue;
105685
- const writes = [atomicWriteJson2(getMetaPath2(groupId), meta3)];
105683
+ const writes = [atomicWriteJson(getMetaPath2(groupId), meta3)];
105686
105684
  if (updates.config !== void 0) {
105687
105685
  const configFile = {
105688
105686
  version: SCHEMA_VERSION2,
@@ -105691,14 +105689,14 @@ var init_group_file_store = __esm({
105691
105689
  timeout: updates.config.timeout ?? 3e5,
105692
105690
  updatedAt: now2
105693
105691
  };
105694
- writes.push(atomicWriteJson2(getConfigPath2(groupId), configFile));
105692
+ writes.push(atomicWriteJson(getConfigPath2(groupId), configFile));
105695
105693
  }
105696
105694
  if (updates.memberIds !== void 0) {
105697
105695
  const membersFile = {
105698
105696
  members: updates.memberIds,
105699
105697
  updatedAt: now2
105700
105698
  };
105701
- writes.push(atomicWriteJson2(getMembersPath(groupId), membersFile));
105699
+ writes.push(atomicWriteJson(getMembersPath(groupId), membersFile));
105702
105700
  }
105703
105701
  await Promise.all(writes);
105704
105702
  this.cache.delete(groupId);
@@ -105706,13 +105704,13 @@ var init_group_file_store = __esm({
105706
105704
  async delete(groupId) {
105707
105705
  this.cache.delete(groupId);
105708
105706
  const dir = getGroupDir(groupId);
105709
- if ((0, import_fs8.existsSync)(dir)) {
105710
- await (0, import_promises5.rm)(dir, { force: true, recursive: true });
105707
+ if ((0, import_fs9.existsSync)(dir)) {
105708
+ await (0, import_promises6.rm)(dir, { force: true, recursive: true });
105711
105709
  }
105712
105710
  }
105713
105711
  // --- Members ---
105714
105712
  async getMembers(groupId) {
105715
- const membersFile = await readJsonFile3(getMembersPath(groupId));
105713
+ const membersFile = await readJsonFile2(getMembersPath(groupId));
105716
105714
  return membersFile?.members ?? [];
105717
105715
  }
105718
105716
  // --- Group Settings ---
@@ -105738,13 +105736,13 @@ var init_group_file_store = __esm({
105738
105736
  const content = await this.readGroupMemoryContent(groupId);
105739
105737
  let updatedAt = null;
105740
105738
  const memoryPath = getGroupMemoryPath(groupId);
105741
- if ((0, import_fs8.existsSync)(memoryPath)) {
105742
- const s = await (0, import_promises5.stat)(memoryPath);
105739
+ if ((0, import_fs9.existsSync)(memoryPath)) {
105740
+ const s = await (0, import_promises6.stat)(memoryPath);
105743
105741
  updatedAt = s.mtime;
105744
105742
  } else {
105745
105743
  const legacyPath = getLegacyTeamMemoryPath(groupId);
105746
- if ((0, import_fs8.existsSync)(legacyPath)) {
105747
- const s = await (0, import_promises5.stat)(legacyPath);
105744
+ if ((0, import_fs9.existsSync)(legacyPath)) {
105745
+ const s = await (0, import_promises6.stat)(legacyPath);
105748
105746
  updatedAt = s.mtime;
105749
105747
  }
105750
105748
  }
@@ -105759,14 +105757,14 @@ var init_group_file_store = __esm({
105759
105757
  /** Read the last N days of memory/YYYY-MM-DD.md files. Returns content with last 50 lines per file. */
105760
105758
  async readRecentDailyMemory(groupId, days = 2) {
105761
105759
  const memDir = getGroupMemoryDir(groupId);
105762
- if (!(0, import_fs8.existsSync)(memDir)) return "";
105760
+ if (!(0, import_fs9.existsSync)(memDir)) return "";
105763
105761
  const today = /* @__PURE__ */ new Date();
105764
105762
  const results = [];
105765
105763
  for (let i = 0; i < days; i++) {
105766
105764
  const d = new Date(today);
105767
105765
  d.setDate(d.getDate() - i);
105768
105766
  const filename = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}.md`;
105769
- const filePath = (0, import_path8.join)(memDir, filename);
105767
+ const filePath = (0, import_path9.join)(memDir, filename);
105770
105768
  const content = await readTextFile(filePath);
105771
105769
  if (content) {
105772
105770
  const lines = content.split("\n");
@@ -105778,24 +105776,24 @@ var init_group_file_store = __esm({
105778
105776
  }
105779
105777
  // --- saveGroupFile (for IPC / frontend) ---
105780
105778
  async saveGroupFile(groupId, filename, content) {
105781
- if (filename !== (0, import_path8.basename)(filename)) {
105779
+ if (filename !== (0, import_path9.basename)(filename)) {
105782
105780
  throw new Error(`saveGroupFile: nested paths not allowed: ${filename}`);
105783
105781
  }
105784
105782
  if (!ALLOWED_SAVE_FILENAMES.has(filename)) {
105785
105783
  throw new Error(`saveGroupFile: filename not allowed: ${filename}`);
105786
105784
  }
105787
- const filePath = (0, import_path8.join)(getGroupDir(groupId), filename);
105785
+ const filePath = (0, import_path9.join)(getGroupDir(groupId), filename);
105788
105786
  if (!content) {
105789
- if ((0, import_fs8.existsSync)(filePath)) {
105790
- await (0, import_promises5.unlink)(filePath);
105787
+ if ((0, import_fs9.existsSync)(filePath)) {
105788
+ await (0, import_promises6.unlink)(filePath);
105791
105789
  }
105792
105790
  } else {
105793
105791
  await atomicWriteText(filePath, content);
105794
105792
  }
105795
- const meta3 = await readJsonFile3(getMetaPath2(groupId));
105793
+ const meta3 = await readJsonFile2(getMetaPath2(groupId));
105796
105794
  if (meta3) {
105797
105795
  meta3.updatedAt = Date.now();
105798
- await atomicWriteJson2(getMetaPath2(groupId), meta3);
105796
+ await atomicWriteJson(getMetaPath2(groupId), meta3);
105799
105797
  }
105800
105798
  this.cache.delete(groupId);
105801
105799
  }
@@ -105822,11 +105820,11 @@ var init_group_file_store = __esm({
105822
105820
  members: data2.members,
105823
105821
  updatedAt: data2.updatedAt
105824
105822
  };
105825
- await (0, import_promises5.mkdir)(getGroupDir(data2.id), { recursive: true });
105823
+ await (0, import_promises6.mkdir)(getGroupDir(data2.id), { recursive: true });
105826
105824
  const writes = [
105827
- atomicWriteJson2(getMetaPath2(data2.id), meta3),
105828
- atomicWriteJson2(getConfigPath2(data2.id), configFile),
105829
- atomicWriteJson2(getMembersPath(data2.id), membersFile)
105825
+ atomicWriteJson(getMetaPath2(data2.id), meta3),
105826
+ atomicWriteJson(getConfigPath2(data2.id), configFile),
105827
+ atomicWriteJson(getMembersPath(data2.id), membersFile)
105830
105828
  ];
105831
105829
  if (data2.teamMemory) {
105832
105830
  writes.push(atomicWriteText(getGroupMemoryPath(data2.id), data2.teamMemory));
@@ -105834,12 +105832,12 @@ var init_group_file_store = __esm({
105834
105832
  await Promise.all(writes);
105835
105833
  const legacyPath = getLegacyTeamMemoryPath(data2.id);
105836
105834
  const newPath = getGroupMemoryPath(data2.id);
105837
- if ((0, import_fs8.existsSync)(legacyPath) && !(0, import_fs8.existsSync)(newPath)) {
105838
- await (0, import_promises5.rename)(legacyPath, newPath);
105835
+ if ((0, import_fs9.existsSync)(legacyPath) && !(0, import_fs9.existsSync)(newPath)) {
105836
+ await (0, import_promises6.rename)(legacyPath, newPath);
105839
105837
  }
105840
- const metaJsonPath = (0, import_path8.join)(getGroupDir(data2.id), "team-memory.meta.json");
105841
- if ((0, import_fs8.existsSync)(metaJsonPath)) {
105842
- await (0, import_promises5.unlink)(metaJsonPath).catch(() => {
105838
+ const metaJsonPath = (0, import_path9.join)(getGroupDir(data2.id), "team-memory.meta.json");
105839
+ if ((0, import_fs9.existsSync)(metaJsonPath)) {
105840
+ await (0, import_promises6.unlink)(metaJsonPath).catch(() => {
105843
105841
  });
105844
105842
  }
105845
105843
  }
@@ -105858,29 +105856,21 @@ var init_group_file_store = __esm({
105858
105856
 
105859
105857
  // src/adapters/storage/thread-file-store.ts
105860
105858
  function getThreadsRootDir(groupId) {
105861
- return (0, import_path9.join)(getGroupDir(groupId), "threads");
105859
+ return (0, import_path10.join)(getGroupDir(groupId), "threads");
105862
105860
  }
105863
105861
  function getThreadDir(groupId, threadId) {
105864
- return (0, import_path9.join)(getThreadsRootDir(groupId), threadId);
105862
+ return (0, import_path10.join)(getThreadsRootDir(groupId), threadId);
105865
105863
  }
105866
105864
  function getMetaPath3(groupId, threadId) {
105867
- return (0, import_path9.join)(getThreadDir(groupId, threadId), META_FILE3);
105865
+ return (0, import_path10.join)(getThreadDir(groupId, threadId), META_FILE3);
105868
105866
  }
105869
105867
  function getConfigPath3(groupId, threadId) {
105870
- return (0, import_path9.join)(getThreadDir(groupId, threadId), CONFIG_FILE3);
105868
+ return (0, import_path10.join)(getThreadDir(groupId, threadId), CONFIG_FILE3);
105871
105869
  }
105872
- async function atomicWriteJson3(path10, data2) {
105873
- const dir = (0, import_path9.dirname)(path10);
105874
- await (0, import_promises6.mkdir)(dir, { recursive: true });
105875
- const tmp = `${path10}.tmp`;
105876
- await (0, import_promises6.writeFile)(tmp, `${JSON.stringify(data2, null, 2)}
105877
- `, "utf-8");
105878
- await (0, import_promises6.rename)(tmp, path10);
105879
- }
105880
- async function readJsonFile4(path10) {
105881
- if (!(0, import_fs9.existsSync)(path10)) return null;
105870
+ async function readJsonFile3(path10) {
105871
+ if (!(0, import_fs10.existsSync)(path10)) return null;
105882
105872
  try {
105883
- const raw = await (0, import_promises6.readFile)(path10, "utf-8");
105873
+ const raw = await (0, import_promises7.readFile)(path10, "utf-8");
105884
105874
  return JSON.parse(raw);
105885
105875
  } catch (e) {
105886
105876
  logger9.warn("Failed to parse:", path10, e);
@@ -105930,31 +105920,32 @@ function threadToConfigFile(thread) {
105930
105920
  };
105931
105921
  }
105932
105922
  async function findGroupIdForThread(threadId) {
105933
- const groupsRoot = (0, import_path9.join)(config.getAppDataPath(), "groups");
105934
- if (!(0, import_fs9.existsSync)(groupsRoot)) return null;
105935
- const entries = await (0, import_promises6.readdir)(groupsRoot, { withFileTypes: true });
105923
+ const groupsRoot = (0, import_path10.join)(config.getAppDataPath(), "groups");
105924
+ if (!(0, import_fs10.existsSync)(groupsRoot)) return null;
105925
+ const entries = await (0, import_promises7.readdir)(groupsRoot, { withFileTypes: true });
105936
105926
  for (const entry of entries) {
105937
105927
  if (!entry.isDirectory()) continue;
105938
- const threadsDir = (0, import_path9.join)(groupsRoot, entry.name, "threads");
105939
- if (!(0, import_fs9.existsSync)(threadsDir)) continue;
105940
- const threadMetaPath = (0, import_path9.join)(threadsDir, threadId, META_FILE3);
105941
- if ((0, import_fs9.existsSync)(threadMetaPath)) {
105928
+ const threadsDir = (0, import_path10.join)(groupsRoot, entry.name, "threads");
105929
+ if (!(0, import_fs10.existsSync)(threadsDir)) continue;
105930
+ const threadMetaPath = (0, import_path10.join)(threadsDir, threadId, META_FILE3);
105931
+ if ((0, import_fs10.existsSync)(threadMetaPath)) {
105942
105932
  return entry.name;
105943
105933
  }
105944
105934
  }
105945
105935
  return null;
105946
105936
  }
105947
- var import_path9, import_promises6, import_fs9, logger9, META_FILE3, CONFIG_FILE3, SCHEMA_VERSION3, ThreadFileStore, threadFileStore;
105937
+ var import_path10, import_promises7, import_fs10, logger9, META_FILE3, CONFIG_FILE3, SCHEMA_VERSION3, ThreadFileStore, threadFileStore;
105948
105938
  var init_thread_file_store = __esm({
105949
105939
  "src/adapters/storage/thread-file-store.ts"() {
105950
105940
  "use strict";
105951
- import_path9 = require("path");
105952
- import_promises6 = require("fs/promises");
105953
- import_fs9 = require("fs");
105941
+ import_path10 = require("path");
105942
+ import_promises7 = require("fs/promises");
105943
+ import_fs10 = require("fs");
105954
105944
  init_id2();
105955
105945
  init_config();
105956
105946
  init_group_file_store();
105957
105947
  init_logger();
105948
+ init_json_file();
105958
105949
  logger9 = createLogger("thread-file-store");
105959
105950
  META_FILE3 = "meta.json";
105960
105951
  CONFIG_FILE3 = "config.json";
@@ -105978,8 +105969,8 @@ var init_thread_file_store = __esm({
105978
105969
  createdAt: now2,
105979
105970
  updatedAt: now2
105980
105971
  };
105981
- await (0, import_promises6.mkdir)(getThreadDir(groupId, id), { recursive: true });
105982
- await atomicWriteJson3(getMetaPath3(groupId, id), meta3);
105972
+ await (0, import_promises7.mkdir)(getThreadDir(groupId, id), { recursive: true });
105973
+ await atomicWriteJson(getMetaPath3(groupId, id), meta3);
105983
105974
  const thread = {
105984
105975
  id,
105985
105976
  groupId,
@@ -105998,7 +105989,7 @@ var init_thread_file_store = __esm({
105998
105989
  temperature: params.config.temperature,
105999
105990
  updatedAt: now2
106000
105991
  };
106001
- await atomicWriteJson3(getConfigPath3(groupId, id), configFile);
105992
+ await atomicWriteJson(getConfigPath3(groupId, id), configFile);
106002
105993
  }
106003
105994
  this.cache.set(id, thread);
106004
105995
  this.groupIndex.set(id, groupId);
@@ -106019,9 +106010,9 @@ var init_thread_file_store = __esm({
106019
106010
  async findByGroupIdAndId(groupId, threadId) {
106020
106011
  const cached2 = this.cache.get(threadId);
106021
106012
  if (cached2) return cached2;
106022
- const meta3 = await readJsonFile4(getMetaPath3(groupId, threadId));
106013
+ const meta3 = await readJsonFile3(getMetaPath3(groupId, threadId));
106023
106014
  if (!meta3) return null;
106024
- const configFile = await readJsonFile4(getConfigPath3(groupId, threadId));
106015
+ const configFile = await readJsonFile3(getConfigPath3(groupId, threadId));
106025
106016
  const thread = metaFileToThread(meta3, configFile ?? void 0);
106026
106017
  this.cache.set(threadId, thread);
106027
106018
  this.groupIndex.set(threadId, groupId);
@@ -106029,10 +106020,10 @@ var init_thread_file_store = __esm({
106029
106020
  }
106030
106021
  async listByGroupId(groupId) {
106031
106022
  const threadsDir = getThreadsRootDir(groupId);
106032
- if (!(0, import_fs9.existsSync)(threadsDir)) return [];
106023
+ if (!(0, import_fs10.existsSync)(threadsDir)) return [];
106033
106024
  let entries;
106034
106025
  try {
106035
- entries = await (0, import_promises6.readdir)(threadsDir, { withFileTypes: true });
106026
+ entries = await (0, import_promises7.readdir)(threadsDir, { withFileTypes: true });
106036
106027
  } catch {
106037
106028
  return [];
106038
106029
  }
@@ -106052,7 +106043,7 @@ var init_thread_file_store = __esm({
106052
106043
  if (this.cache.has(threadId)) return true;
106053
106044
  const groupId = this.groupIndex.get(threadId) ?? await findGroupIdForThread(threadId);
106054
106045
  if (!groupId) return false;
106055
- return (0, import_fs9.existsSync)(getMetaPath3(groupId, threadId));
106046
+ return (0, import_fs10.existsSync)(getMetaPath3(groupId, threadId));
106056
106047
  }
106057
106048
  async countByGroupId(groupId) {
106058
106049
  const threads = await this.listByGroupId(groupId);
@@ -106069,11 +106060,11 @@ var init_thread_file_store = __esm({
106069
106060
  if (patch.config !== void 0) current.config = patch.config;
106070
106061
  current.updatedAt = now2;
106071
106062
  const meta3 = threadToMetaFile(current);
106072
- await atomicWriteJson3(getMetaPath3(current.groupId, threadId), meta3);
106063
+ await atomicWriteJson(getMetaPath3(current.groupId, threadId), meta3);
106073
106064
  const configFile = threadToConfigFile(current);
106074
106065
  if (configFile) {
106075
106066
  configFile.updatedAt = now2;
106076
- await atomicWriteJson3(getConfigPath3(current.groupId, threadId), configFile);
106067
+ await atomicWriteJson(getConfigPath3(current.groupId, threadId), configFile);
106077
106068
  }
106078
106069
  this.cache.set(threadId, current);
106079
106070
  this.groupIndex.set(threadId, current.groupId);
@@ -106086,8 +106077,8 @@ var init_thread_file_store = __esm({
106086
106077
  this.cache.delete(threadId);
106087
106078
  this.groupIndex.delete(threadId);
106088
106079
  const dir = getThreadDir(current.groupId, threadId);
106089
- if ((0, import_fs9.existsSync)(dir)) {
106090
- await (0, import_promises6.rm)(dir, { force: true, recursive: true });
106080
+ if ((0, import_fs10.existsSync)(dir)) {
106081
+ await (0, import_promises7.rm)(dir, { force: true, recursive: true });
106091
106082
  }
106092
106083
  return true;
106093
106084
  }
@@ -106098,8 +106089,8 @@ var init_thread_file_store = __esm({
106098
106089
  this.cache.delete(thread.id);
106099
106090
  this.groupIndex.delete(thread.id);
106100
106091
  const dir = getThreadDir(groupId, thread.id);
106101
- if ((0, import_fs9.existsSync)(dir)) {
106102
- await (0, import_promises6.rm)(dir, { force: true, recursive: true });
106092
+ if ((0, import_fs10.existsSync)(dir)) {
106093
+ await (0, import_promises7.rm)(dir, { force: true, recursive: true });
106103
106094
  }
106104
106095
  count++;
106105
106096
  }
@@ -107035,19 +107026,19 @@ var require_token_io = __commonJS({
107035
107026
  getUserDataDir: () => getUserDataDir
107036
107027
  });
107037
107028
  module2.exports = __toCommonJS2(token_io_exports);
107038
- var import_path31 = __toESM2(require("path"));
107039
- var import_fs22 = __toESM2(require("fs"));
107029
+ var import_path32 = __toESM2(require("path"));
107030
+ var import_fs23 = __toESM2(require("fs"));
107040
107031
  var import_os4 = __toESM2(require("os"));
107041
107032
  var import_token_error = require_token_error();
107042
107033
  function findRootDir() {
107043
107034
  try {
107044
107035
  let dir = process.cwd();
107045
- while (dir !== import_path31.default.dirname(dir)) {
107046
- const pkgPath = import_path31.default.join(dir, ".vercel");
107047
- if (import_fs22.default.existsSync(pkgPath)) {
107036
+ while (dir !== import_path32.default.dirname(dir)) {
107037
+ const pkgPath = import_path32.default.join(dir, ".vercel");
107038
+ if (import_fs23.default.existsSync(pkgPath)) {
107048
107039
  return dir;
107049
107040
  }
107050
- dir = import_path31.default.dirname(dir);
107041
+ dir = import_path32.default.dirname(dir);
107051
107042
  }
107052
107043
  } catch (e) {
107053
107044
  throw new import_token_error.VercelOidcTokenError(
@@ -107062,9 +107053,9 @@ var require_token_io = __commonJS({
107062
107053
  }
107063
107054
  switch (import_os4.default.platform()) {
107064
107055
  case "darwin":
107065
- return import_path31.default.join(import_os4.default.homedir(), "Library/Application Support");
107056
+ return import_path32.default.join(import_os4.default.homedir(), "Library/Application Support");
107066
107057
  case "linux":
107067
- return import_path31.default.join(import_os4.default.homedir(), ".local/share");
107058
+ return import_path32.default.join(import_os4.default.homedir(), ".local/share");
107068
107059
  case "win32":
107069
107060
  if (process.env.LOCALAPPDATA) {
107070
107061
  return process.env.LOCALAPPDATA;
@@ -123933,15 +123924,15 @@ ${failureStats.recentFailures.slice(-3).map((f) => ` - ${f.toolName}(${f.toolCa
123933
123924
  failureStats.recentFailures = [];
123934
123925
  }
123935
123926
  }
123936
- var import_path13, import_promises10, logger12, failureStats, FAILURE_REPORT_THRESHOLD, FAILURE_REPORT_INTERVAL, ToolResultSpillStrategy;
123927
+ var import_path14, import_promises11, logger12, failureStats, FAILURE_REPORT_THRESHOLD, FAILURE_REPORT_INTERVAL, ToolResultSpillStrategy;
123937
123928
  var init_ToolResultSpillStrategy = __esm({
123938
123929
  "src/core/agent/kernel/compression/strategies/ToolResultSpillStrategy.ts"() {
123939
123930
  "use strict";
123940
123931
  init_token_estimator();
123941
123932
  init_constants2();
123942
123933
  init_workspace();
123943
- import_path13 = __toESM(require("path"));
123944
- import_promises10 = __toESM(require("fs/promises"));
123934
+ import_path14 = __toESM(require("path"));
123935
+ import_promises11 = __toESM(require("fs/promises"));
123945
123936
  init_logger();
123946
123937
  logger12 = createLogger("tool-result-spill");
123947
123938
  failureStats = {
@@ -124029,11 +124020,11 @@ ${preview}${lines.length > 50 ? `
124029
124020
  async saveToolResultToFile(agentId, toolCallId, content) {
124030
124021
  const workspaceDir = getAgentWorkspaceDir(agentId);
124031
124022
  const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
124032
- const toolResultsDir = import_path13.default.join(workspaceDir, "tool_results", today);
124033
- await import_promises10.default.mkdir(toolResultsDir, { recursive: true });
124023
+ const toolResultsDir = import_path14.default.join(workspaceDir, "tool_results", today);
124024
+ await import_promises11.default.mkdir(toolResultsDir, { recursive: true });
124034
124025
  const filename = `${toolCallId}.json`;
124035
- const filepath = import_path13.default.join(toolResultsDir, filename);
124036
- await import_promises10.default.writeFile(filepath, content, "utf-8");
124026
+ const filepath = import_path14.default.join(toolResultsDir, filename);
124027
+ await import_promises11.default.writeFile(filepath, content, "utf-8");
124037
124028
  return `tool_results/${today}/${filename}`;
124038
124029
  }
124039
124030
  };
@@ -125156,9 +125147,9 @@ function getWorkdirArg(args2) {
125156
125147
  return typeof workdir === "string" && workdir.length > 0 ? workdir : null;
125157
125148
  }
125158
125149
  function resolveFilePath(filePath, scope) {
125159
- if ((0, import_path14.isAbsolute)(filePath)) return filePath;
125150
+ if ((0, import_path15.isAbsolute)(filePath)) return filePath;
125160
125151
  const baseDir = scope?.groupId ? getGroupDir(scope.groupId) : scope?.agentId ? getAgentWorkspaceDir(scope.agentId) : process.cwd();
125161
- return (0, import_path14.resolve)(baseDir, filePath);
125152
+ return (0, import_path15.resolve)(baseDir, filePath);
125162
125153
  }
125163
125154
  function normalizeToolArgsForDisplay(toolName, args2, agentId, groupId) {
125164
125155
  if (!isFilePathTool(toolName)) return args2;
@@ -125166,15 +125157,15 @@ function normalizeToolArgsForDisplay(toolName, args2, agentId, groupId) {
125166
125157
  if (!path10) return args2;
125167
125158
  const workdir = getWorkdirArg(args2);
125168
125159
  if (workdir) {
125169
- return replaceToolPathArg(args2, (0, import_path14.isAbsolute)(path10) ? path10 : (0, import_path14.resolve)(workdir, path10));
125160
+ return replaceToolPathArg(args2, (0, import_path15.isAbsolute)(path10) ? path10 : (0, import_path15.resolve)(workdir, path10));
125170
125161
  }
125171
125162
  return replaceToolPathArg(args2, resolveFilePath(path10, { agentId, groupId }));
125172
125163
  }
125173
- var import_path14;
125164
+ var import_path15;
125174
125165
  var init_display = __esm({
125175
125166
  "src/core/tools/shared/display.ts"() {
125176
125167
  "use strict";
125177
- import_path14 = require("path");
125168
+ import_path15 = require("path");
125178
125169
  init_workspace();
125179
125170
  init_group_file_store();
125180
125171
  init_tool_args();
@@ -130094,11 +130085,10 @@ var require_gray_matter = __commonJS({
130094
130085
  });
130095
130086
 
130096
130087
  // src/core/skill/SkillManager.ts
130097
- function getAgentDir2(agentId) {
130088
+ function validateAgentId(agentId) {
130098
130089
  if (!/^[a-zA-Z0-9_-]{1,64}$/.test(agentId)) {
130099
130090
  throw new Error(`Invalid agentId: ${agentId}`);
130100
130091
  }
130101
- return (0, import_path15.join)(config.getAppDataPath(), "agents", agentId);
130102
130092
  }
130103
130093
  function normalizeAllowedTools(value) {
130104
130094
  if (!value) return void 0;
@@ -130109,9 +130099,9 @@ function normalizeAllowedTools(value) {
130109
130099
  async function scanSkillsFromPaths(paths) {
130110
130100
  const skillMap = /* @__PURE__ */ new Map();
130111
130101
  async function readSkillFile(skillsDir, skillName) {
130112
- const skillMdPath = (0, import_path15.join)(skillsDir, skillName, "SKILL.md");
130102
+ const skillMdPath = (0, import_path16.join)(skillsDir, skillName, "SKILL.md");
130113
130103
  try {
130114
- const fileContent = await (0, import_promises11.readFile)(skillMdPath, "utf-8");
130104
+ const fileContent = await (0, import_promises12.readFile)(skillMdPath, "utf-8");
130115
130105
  const { data: data2, content } = (0, import_gray_matter.default)(fileContent);
130116
130106
  if (!data2.description) return null;
130117
130107
  if (data2.name && data2.name !== skillName) {
@@ -130134,9 +130124,9 @@ async function scanSkillsFromPaths(paths) {
130134
130124
  return null;
130135
130125
  }
130136
130126
  }
130137
- for (const skillsDir of paths.reverse()) {
130127
+ for (const skillsDir of [...paths].reverse()) {
130138
130128
  try {
130139
- const entries = await (0, import_promises11.readdir)(skillsDir, { withFileTypes: true });
130129
+ const entries = await (0, import_promises12.readdir)(skillsDir, { withFileTypes: true });
130140
130130
  const skillDirs = entries.filter((e) => e.isDirectory()).map((e) => e.name);
130141
130131
  const results = await Promise.all(
130142
130132
  skillDirs.map((skillName) => readSkillFile(skillsDir, skillName))
@@ -130155,12 +130145,33 @@ async function scanSkillsFromPaths(paths) {
130155
130145
  }
130156
130146
  return Array.from(skillMap.values());
130157
130147
  }
130158
- var import_path15, import_promises11, import_os3, import_gray_matter, logger18, SkillManager;
130148
+ function buildSkillSearchPaths({
130149
+ appDataPath,
130150
+ homeDir,
130151
+ agentId,
130152
+ projectPath
130153
+ }) {
130154
+ const paths = [];
130155
+ if (projectPath) {
130156
+ paths.push((0, import_path16.join)(projectPath, ".kai", "skills"));
130157
+ paths.push((0, import_path16.join)(projectPath, ".agents", "skills"));
130158
+ }
130159
+ if (agentId) {
130160
+ paths.push((0, import_path16.join)(appDataPath, "agents", agentId, "skills"));
130161
+ }
130162
+ paths.push((0, import_path16.join)(appDataPath, "skills"));
130163
+ paths.push((0, import_path16.join)(homeDir, ".agents", "skills"));
130164
+ paths.push((0, import_path16.join)(homeDir, ".claude", "skills"));
130165
+ paths.push((0, import_path16.join)(homeDir, ".openclaw", "skills"));
130166
+ paths.push((0, import_path16.join)(homeDir, ".codex", "skills"));
130167
+ return paths;
130168
+ }
130169
+ var import_path16, import_promises12, import_os3, import_gray_matter, logger18, SkillManager;
130159
130170
  var init_SkillManager = __esm({
130160
130171
  "src/core/skill/SkillManager.ts"() {
130161
130172
  "use strict";
130162
- import_path15 = require("path");
130163
- import_promises11 = require("fs/promises");
130173
+ import_path16 = require("path");
130174
+ import_promises12 = require("fs/promises");
130164
130175
  import_os3 = require("os");
130165
130176
  import_gray_matter = __toESM(require_gray_matter());
130166
130177
  init_config();
@@ -130188,17 +130199,15 @@ var init_SkillManager = __esm({
130188
130199
  if (cached2 && Date.now() - cached2.timestamp < this.CACHE_TTL) {
130189
130200
  return cached2.skills;
130190
130201
  }
130191
- const paths = [];
130192
- if (projectPath) {
130193
- paths.push((0, import_path15.join)(projectPath, ".kai", "skills"));
130194
- paths.push((0, import_path15.join)(projectPath, ".agents", "skills"));
130195
- }
130196
130202
  if (agentId) {
130197
- const agentDir = getAgentDir2(agentId);
130198
- paths.push((0, import_path15.join)(agentDir, "skills"));
130203
+ validateAgentId(agentId);
130199
130204
  }
130200
- paths.push((0, import_path15.join)(config.getAppDataPath(), "skills"));
130201
- paths.push((0, import_path15.join)((0, import_os3.homedir)(), ".agents", "skills"));
130205
+ const paths = buildSkillSearchPaths({
130206
+ appDataPath: config.getAppDataPath(),
130207
+ homeDir: (0, import_os3.homedir)(),
130208
+ agentId,
130209
+ projectPath
130210
+ });
130202
130211
  const skills = await scanSkillsFromPaths(paths);
130203
130212
  const skillsConfig = config.get("skills") || {};
130204
130213
  const result = skills.map((skill) => ({
@@ -130279,24 +130288,24 @@ async function listSkillResources(skillDir) {
130279
130288
  const MAX_FILES_PER_DIR = 10;
130280
130289
  async function walk(dir, category) {
130281
130290
  try {
130282
- const entries = await (0, import_promises12.readdir)(dir, { withFileTypes: true });
130291
+ const entries = await (0, import_promises13.readdir)(dir, { withFileTypes: true });
130283
130292
  for (const entry of entries) {
130284
130293
  if (resources[category].length >= MAX_FILES_PER_DIR) break;
130285
- const fullPath = (0, import_path16.join)(dir, entry.name);
130294
+ const fullPath = (0, import_path17.join)(dir, entry.name);
130286
130295
  if (entry.isDirectory() && !entry.isSymbolicLink()) {
130287
130296
  await walk(fullPath, category);
130288
130297
  } else if (!entry.isSymbolicLink()) {
130289
- resources[category].push((0, import_path16.relative)(skillDir, fullPath));
130298
+ resources[category].push((0, import_path17.relative)(skillDir, fullPath));
130290
130299
  }
130291
130300
  }
130292
130301
  } catch {
130293
130302
  }
130294
130303
  }
130295
- await walk((0, import_path16.join)(skillDir, "scripts"), "scripts");
130296
- await walk((0, import_path16.join)(skillDir, "references"), "references");
130297
- await walk((0, import_path16.join)(skillDir, "assets"), "assets");
130304
+ await walk((0, import_path17.join)(skillDir, "scripts"), "scripts");
130305
+ await walk((0, import_path17.join)(skillDir, "references"), "references");
130306
+ await walk((0, import_path17.join)(skillDir, "assets"), "assets");
130298
130307
  try {
130299
- const entries = await (0, import_promises12.readdir)(skillDir, { withFileTypes: true });
130308
+ const entries = await (0, import_promises13.readdir)(skillDir, { withFileTypes: true });
130300
130309
  for (const entry of entries) {
130301
130310
  if (resources.other.length >= 5) break;
130302
130311
  if (entry.name === "SKILL.md" || entry.isDirectory()) continue;
@@ -130352,12 +130361,12 @@ ${otherXml}
130352
130361
  `</skill_content>`
130353
130362
  ].filter(Boolean).join("\n");
130354
130363
  }
130355
- var import_path16, import_promises12, import_child_process2, import_util6, import_gray_matter2, logger19, execAsync, skillManager, SHELL_REGEX;
130364
+ var import_path17, import_promises13, import_child_process2, import_util6, import_gray_matter2, logger19, execAsync, skillManager, SHELL_REGEX;
130356
130365
  var init_skill = __esm({
130357
130366
  "src/core/skill/index.ts"() {
130358
130367
  "use strict";
130359
- import_path16 = require("path");
130360
- import_promises12 = require("fs/promises");
130368
+ import_path17 = require("path");
130369
+ import_promises13 = require("fs/promises");
130361
130370
  import_child_process2 = require("child_process");
130362
130371
  import_util6 = require("util");
130363
130372
  import_gray_matter2 = __toESM(require_gray_matter());
@@ -131810,7 +131819,7 @@ var init_TaskOrchestrator = __esm({
131810
131819
  status: "failed",
131811
131820
  blocks: [{
131812
131821
  type: "text",
131813
- text: "\u76EE\u6807\u6210\u5458\u4E0D\u5B58\u5728\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u76EE\u6807\uFF0C\u8BF7\u4ECE\u76EE\u6807\u5217\u8868\u4E2D\u79FB\u9664\u65E0\u6548 agentId \u540E\u518D\u8BD5\u3002",
131822
+ text: "\u76EE\u6807\u6210\u5458\u4E0D\u5B58\u5728\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u76EE\u6807\u3002",
131814
131823
  id: `broadcast-error-${agentId}`
131815
131824
  }],
131816
131825
  error: `Agent ${agentId} \u4E0D\u5728\u5F53\u524D\u7FA4\u804A\u6210\u5458\u4E2D\u3002\u5F53\u524D\u6210\u5458 ID\uFF1A${memberIds.join(", ")}\u3002`
@@ -134037,6 +134046,29 @@ var init_StreamingPersistScheduler = __esm({
134037
134046
  });
134038
134047
 
134039
134048
  // src/core/message/queue/MessageProcessor.ts
134049
+ function settlePendingBlocks(blocks, now2 = Date.now()) {
134050
+ let changed = false;
134051
+ const settled = blocks.map((block) => {
134052
+ if (!block.isPending) return block;
134053
+ changed = true;
134054
+ if (block.type !== "tool" || block.toolCall.status !== "pending") {
134055
+ return { ...block, isPending: false };
134056
+ }
134057
+ const endedAt = now2;
134058
+ return {
134059
+ ...block,
134060
+ isPending: false,
134061
+ toolCall: {
134062
+ ...block.toolCall,
134063
+ status: "error",
134064
+ error: "\u7528\u6237\u5DF2\u505C\u6B62\u6267\u884C",
134065
+ endedAt,
134066
+ durationMs: endedAt - block.toolCall.startedAt
134067
+ }
134068
+ };
134069
+ });
134070
+ return changed ? settled : blocks;
134071
+ }
134040
134072
  function normalizeUsage(usage) {
134041
134073
  const normalized = {};
134042
134074
  for (const key of TOKEN_USAGE_KEYS) {
@@ -134299,6 +134331,7 @@ var init_MessageProcessor = __esm({
134299
134331
  try {
134300
134332
  if (err instanceof DOMException ? err.name === "AbortError" : err instanceof Error && err.name === "AbortError") {
134301
134333
  if (streamingBlocks.length > 0) {
134334
+ ctx.streamingBlocks = settlePendingBlocks(streamingBlocks);
134302
134335
  await this.persistErrorMessage(ctx);
134303
134336
  }
134304
134337
  eventBus.emit({
@@ -136556,7 +136589,7 @@ var init_entities = __esm({
136556
136589
  });
136557
136590
 
136558
136591
  // src/adapters/scheduler/MemoryUpdateExecutor.ts
136559
- var import_path17, MemoryUpdateExecutor;
136592
+ var import_path18, MemoryUpdateExecutor;
136560
136593
  var init_MemoryUpdateExecutor = __esm({
136561
136594
  "src/adapters/scheduler/MemoryUpdateExecutor.ts"() {
136562
136595
  "use strict";
@@ -136564,7 +136597,7 @@ var init_MemoryUpdateExecutor = __esm({
136564
136597
  init_ipc_events();
136565
136598
  init_entities();
136566
136599
  init_workspace();
136567
- import_path17 = __toESM(require("path"));
136600
+ import_path18 = __toESM(require("path"));
136568
136601
  MemoryUpdateExecutor = class _MemoryUpdateExecutor {
136569
136602
  type = "memory-update";
136570
136603
  async execute(task, ctx) {
@@ -136720,13 +136753,13 @@ var init_MemoryUpdateExecutor = __esm({
136720
136753
  return result;
136721
136754
  }
136722
136755
  toRelativeWorkspacePath(workspaceDir, absolutePath) {
136723
- const normalizedWorkspace = import_path17.default.resolve(workspaceDir);
136724
- const normalizedTarget = import_path17.default.resolve(absolutePath);
136725
- const relativePath = import_path17.default.relative(normalizedWorkspace, normalizedTarget);
136726
- if (!relativePath || relativePath.startsWith("..") || import_path17.default.isAbsolute(relativePath)) {
136756
+ const normalizedWorkspace = import_path18.default.resolve(workspaceDir);
136757
+ const normalizedTarget = import_path18.default.resolve(absolutePath);
136758
+ const relativePath = import_path18.default.relative(normalizedWorkspace, normalizedTarget);
136759
+ if (!relativePath || relativePath.startsWith("..") || import_path18.default.isAbsolute(relativePath)) {
136727
136760
  return null;
136728
136761
  }
136729
- return relativePath.split(import_path17.default.sep).join("/");
136762
+ return relativePath.split(import_path18.default.sep).join("/");
136730
136763
  }
136731
136764
  summarizeDiff(diff) {
136732
136765
  if (!diff) return void 0;
@@ -140703,31 +140736,31 @@ function getKaiRoot() {
140703
140736
  return config.getAppDataPath();
140704
140737
  }
140705
140738
  function getDbPath() {
140706
- return (0, import_path20.join)(config.getAppDataPath(), "kai.db");
140739
+ return (0, import_path21.join)(config.getAppDataPath(), "kai.db");
140707
140740
  }
140708
140741
  function getThreadsRoot(groupId) {
140709
- return (0, import_path20.join)(getGroupDir(groupId), "threads");
140742
+ return (0, import_path21.join)(getGroupDir(groupId), "threads");
140710
140743
  }
140711
140744
  function getThreadMetaPath(groupId, threadId) {
140712
- return (0, import_path20.join)(getThreadsRoot(groupId), threadId, "meta.json");
140745
+ return (0, import_path21.join)(getThreadsRoot(groupId), threadId, "meta.json");
140713
140746
  }
140714
- async function atomicWriteJson5(filePath, data2) {
140715
- await (0, import_promises21.mkdir)((0, import_path20.dirname)(filePath), { recursive: true });
140747
+ async function atomicWriteJson3(filePath, data2) {
140748
+ await (0, import_promises22.mkdir)((0, import_path21.dirname)(filePath), { recursive: true });
140716
140749
  const tmp = `${filePath}.tmp`;
140717
- await (0, import_promises21.writeFile)(tmp, `${JSON.stringify(data2, null, 2)}
140750
+ await (0, import_promises22.writeFile)(tmp, `${JSON.stringify(data2, null, 2)}
140718
140751
  `, "utf-8");
140719
- await (0, import_promises21.rename)(tmp, filePath);
140752
+ await (0, import_promises22.rename)(tmp, filePath);
140720
140753
  }
140721
140754
  async function isMigrationNeeded() {
140722
- const groupsRoot = (0, import_path20.join)(getKaiRoot(), "groups");
140723
- if ((0, import_fs13.existsSync)(groupsRoot)) {
140755
+ const groupsRoot = (0, import_path21.join)(getKaiRoot(), "groups");
140756
+ if ((0, import_fs14.existsSync)(groupsRoot)) {
140724
140757
  try {
140725
140758
  const { readdir: readdir9 } = await import("fs/promises");
140726
140759
  const entries = await readdir9(groupsRoot, { withFileTypes: true });
140727
140760
  const dirs = entries.filter((e) => e.isDirectory()).map((e) => e.name);
140728
140761
  if (dirs.length > 0) {
140729
140762
  const allMigrated = dirs.every(
140730
- (g) => (0, import_fs13.existsSync)((0, import_path20.join)(getGroupDir(g), "threads"))
140763
+ (g) => (0, import_fs14.existsSync)((0, import_path21.join)(getGroupDir(g), "threads"))
140731
140764
  );
140732
140765
  if (allMigrated) return false;
140733
140766
  }
@@ -140772,7 +140805,7 @@ async function migrateGroupsToThreads() {
140772
140805
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
140773
140806
  const backupPath = `${dbPath}.bak.${timestamp}`;
140774
140807
  logger33.debug(`Backing up database to ${backupPath}`);
140775
- await (0, import_promises21.copyFile)(dbPath, backupPath);
140808
+ await (0, import_promises22.copyFile)(dbPath, backupPath);
140776
140809
  try {
140777
140810
  logger33.debug("Rebuilding messages table (removing FK)");
140778
140811
  await sequelize.transaction(async (t) => {
@@ -140897,20 +140930,20 @@ async function migrateGroupsToThreads() {
140897
140930
  createdAt,
140898
140931
  updatedAt
140899
140932
  };
140900
- await atomicWriteJson5(getThreadMetaPath(groupId, threadId), threadMeta);
140933
+ await atomicWriteJson3(getThreadMetaPath(groupId, threadId), threadMeta);
140901
140934
  }
140902
140935
  logger33.debug("Thread files created");
140903
140936
  let groupsWithThread = 0;
140904
140937
  for (const conv of groupConversations) {
140905
140938
  const row = conv;
140906
140939
  const groupId = row.target_id;
140907
- const threadsDir = (0, import_path20.join)(getGroupDir(groupId), "threads");
140908
- if (!(0, import_fs13.existsSync)(threadsDir)) continue;
140940
+ const threadsDir = (0, import_path21.join)(getGroupDir(groupId), "threads");
140941
+ if (!(0, import_fs14.existsSync)(threadsDir)) continue;
140909
140942
  try {
140910
140943
  const { readdir: readdirAsync } = await import("fs/promises");
140911
140944
  const threadDirs = (await readdirAsync(threadsDir, { withFileTypes: true })).filter((e) => e.isDirectory());
140912
140945
  const hasMeta = threadDirs.some(
140913
- (td) => (0, import_fs13.existsSync)((0, import_path20.join)(threadsDir, td.name, "meta.json"))
140946
+ (td) => (0, import_fs14.existsSync)((0, import_path21.join)(threadsDir, td.name, "meta.json"))
140914
140947
  );
140915
140948
  if (hasMeta) groupsWithThread++;
140916
140949
  } catch {
@@ -140943,10 +140976,10 @@ async function migrateGroupsToThreads() {
140943
140976
  );
140944
140977
  } catch (error48) {
140945
140978
  logger33.error("Migration failed:", error48);
140946
- if ((0, import_fs13.existsSync)(backupPath)) {
140979
+ if ((0, import_fs14.existsSync)(backupPath)) {
140947
140980
  logger33.debug("Restoring database from backup...");
140948
140981
  try {
140949
- await (0, import_promises21.copyFile)(backupPath, dbPath);
140982
+ await (0, import_promises22.copyFile)(backupPath, dbPath);
140950
140983
  logger33.debug("Database restored from backup");
140951
140984
  } catch (restoreError) {
140952
140985
  logger33.error(
@@ -140961,15 +140994,15 @@ async function migrateGroupsToThreads() {
140961
140994
  async function rollbackThreads() {
140962
140995
  const sequelize = getSequelize();
140963
140996
  const dbPath = getDbPath();
140964
- const groupsRoot = (0, import_path20.join)(getKaiRoot(), "groups");
140965
- if (!(0, import_fs13.existsSync)(groupsRoot)) {
140997
+ const groupsRoot = (0, import_path21.join)(getKaiRoot(), "groups");
140998
+ if (!(0, import_fs14.existsSync)(groupsRoot)) {
140966
140999
  logger33.debug("No groups directory, nothing to rollback.");
140967
141000
  return;
140968
141001
  }
140969
141002
  const { readdir: readdir9 } = await import("fs/promises");
140970
141003
  const dirs = (await readdir9(groupsRoot, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => e.name);
140971
141004
  const hasThreads = dirs.some(
140972
- (g) => (0, import_fs13.existsSync)((0, import_path20.join)(getGroupDir(g), "threads"))
141005
+ (g) => (0, import_fs14.existsSync)((0, import_path21.join)(getGroupDir(g), "threads"))
140973
141006
  );
140974
141007
  if (!hasThreads) {
140975
141008
  logger33.debug("No threads directories found, nothing to rollback.");
@@ -140984,13 +141017,13 @@ async function rollbackThreads() {
140984
141017
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
140985
141018
  const backupPath = `${dbPath}.bak.rollback.${timestamp}`;
140986
141019
  logger33.debug(`Backing up database to ${backupPath}`);
140987
- await (0, import_promises21.copyFile)(dbPath, backupPath);
141020
+ await (0, import_promises22.copyFile)(dbPath, backupPath);
140988
141021
  try {
140989
141022
  logger33.debug("Restoring group conversations from thread files");
140990
141023
  let restored = 0;
140991
141024
  for (const groupId of dirs) {
140992
- const threadsDir = (0, import_path20.join)(getGroupDir(groupId), "threads");
140993
- if (!(0, import_fs13.existsSync)(threadsDir)) continue;
141025
+ const threadsDir = (0, import_path21.join)(getGroupDir(groupId), "threads");
141026
+ if (!(0, import_fs14.existsSync)(threadsDir)) continue;
140994
141027
  let threadDirs;
140995
141028
  try {
140996
141029
  threadDirs = (await readdir9(threadsDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => e.name);
@@ -140999,8 +141032,8 @@ async function rollbackThreads() {
140999
141032
  }
141000
141033
  for (const threadId of threadDirs) {
141001
141034
  const metaPath = getThreadMetaPath(groupId, threadId);
141002
- if (!(0, import_fs13.existsSync)(metaPath)) continue;
141003
- const raw = await (0, import_promises21.readFile)(metaPath, "utf-8");
141035
+ if (!(0, import_fs14.existsSync)(metaPath)) continue;
141036
+ const raw = await (0, import_promises22.readFile)(metaPath, "utf-8");
141004
141037
  const meta3 = JSON.parse(raw);
141005
141038
  if (!meta3.isDefault) {
141006
141039
  const orphanCount = await sequelize.query(
@@ -141127,9 +141160,9 @@ async function rollbackThreads() {
141127
141160
  logger33.debug("Messages table rebuilt with FK restored");
141128
141161
  logger33.debug("Removing threads directories");
141129
141162
  for (const groupId of dirs) {
141130
- const threadsDir = (0, import_path20.join)(getGroupDir(groupId), "threads");
141131
- if ((0, import_fs13.existsSync)(threadsDir)) {
141132
- await (0, import_promises21.rm)(threadsDir, { recursive: true, force: true });
141163
+ const threadsDir = (0, import_path21.join)(getGroupDir(groupId), "threads");
141164
+ if ((0, import_fs14.existsSync)(threadsDir)) {
141165
+ await (0, import_promises22.rm)(threadsDir, { recursive: true, force: true });
141133
141166
  }
141134
141167
  }
141135
141168
  const finalRows = await sequelize.query(
@@ -141147,10 +141180,10 @@ async function rollbackThreads() {
141147
141180
  );
141148
141181
  } catch (error48) {
141149
141182
  logger33.error("Rollback failed:", error48);
141150
- if ((0, import_fs13.existsSync)(backupPath)) {
141183
+ if ((0, import_fs14.existsSync)(backupPath)) {
141151
141184
  logger33.debug("Restoring database from backup...");
141152
141185
  try {
141153
- await (0, import_promises21.copyFile)(backupPath, dbPath);
141186
+ await (0, import_promises22.copyFile)(backupPath, dbPath);
141154
141187
  logger33.debug("Database restored from backup");
141155
141188
  } catch (restoreError) {
141156
141189
  logger33.error(
@@ -141162,13 +141195,13 @@ async function rollbackThreads() {
141162
141195
  throw error48;
141163
141196
  }
141164
141197
  }
141165
- var import_path20, import_fs13, import_promises21, logger33;
141198
+ var import_path21, import_fs14, import_promises22, logger33;
141166
141199
  var init_threads_migration = __esm({
141167
141200
  "src/adapters/db/migration/threads-migration.ts"() {
141168
141201
  "use strict";
141169
- import_path20 = require("path");
141170
- import_fs13 = require("fs");
141171
- import_promises21 = require("fs/promises");
141202
+ import_path21 = require("path");
141203
+ import_fs14 = require("fs");
141204
+ import_promises22 = require("fs/promises");
141172
141205
  init_lib();
141173
141206
  init_sequelize();
141174
141207
  init_config();
@@ -141186,13 +141219,13 @@ __export(cron_sqlite_migration_exports, {
141186
141219
  migrateCronSqliteToFileStore: () => migrateCronSqliteToFileStore
141187
141220
  });
141188
141221
  function getDataCronDir2() {
141189
- return (0, import_path21.join)(config.getAppDataPath(), "data", CRON_DIR2);
141222
+ return (0, import_path22.join)(config.getAppDataPath(), "data", CRON_DIR2);
141190
141223
  }
141191
141224
  function getAgentsDir2() {
141192
- return (0, import_path21.join)(config.getAppDataPath(), "agents");
141225
+ return (0, import_path22.join)(config.getAppDataPath(), "agents");
141193
141226
  }
141194
141227
  function getGroupsDir2() {
141195
- return (0, import_path21.join)(config.getAppDataPath(), "groups");
141228
+ return (0, import_path22.join)(config.getAppDataPath(), "groups");
141196
141229
  }
141197
141230
  function parseDatetime(value) {
141198
141231
  if (!value) return 0;
@@ -141210,17 +141243,17 @@ function parseScriptArgs(raw) {
141210
141243
  }
141211
141244
  async function writeJsonAtomic(filePath, data2) {
141212
141245
  const dir = filePath.substring(0, filePath.lastIndexOf("/"));
141213
- await (0, import_promises22.mkdir)(dir, { recursive: true });
141246
+ await (0, import_promises23.mkdir)(dir, { recursive: true });
141214
141247
  const tmp = `${filePath}.tmp`;
141215
- await (0, import_promises22.writeFile)(tmp, JSON.stringify(data2, null, 2), "utf-8");
141216
- await (0, import_promises22.rename)(tmp, filePath);
141248
+ await (0, import_promises23.writeFile)(tmp, JSON.stringify(data2, null, 2), "utf-8");
141249
+ await (0, import_promises23.rename)(tmp, filePath);
141217
141250
  }
141218
141251
  function getTaskDir2(task) {
141219
141252
  if (task.type === "agent" && task.agentId) {
141220
- return (0, import_path21.join)(getAgentsDir2(), task.agentId, CRON_DIR2);
141253
+ return (0, import_path22.join)(getAgentsDir2(), task.agentId, CRON_DIR2);
141221
141254
  }
141222
141255
  if (task.type === "group" && task.groupId) {
141223
- return (0, import_path21.join)(getGroupsDir2(), task.groupId, CRON_DIR2);
141256
+ return (0, import_path22.join)(getGroupsDir2(), task.groupId, CRON_DIR2);
141224
141257
  }
141225
141258
  return getDataCronDir2();
141226
141259
  }
@@ -141257,8 +141290,8 @@ async function migrateTasks(sequelize) {
141257
141290
  continue;
141258
141291
  }
141259
141292
  const dir = getTaskDir2(task);
141260
- const filePath = (0, import_path21.join)(dir, `${task.id}.json`);
141261
- if ((0, import_fs14.existsSync)(filePath)) {
141293
+ const filePath = (0, import_path22.join)(dir, `${task.id}.json`);
141294
+ if ((0, import_fs15.existsSync)(filePath)) {
141262
141295
  logger34.debug(`Task ${task.id} already exists in filesystem, skipping`);
141263
141296
  continue;
141264
141297
  }
@@ -141290,10 +141323,10 @@ async function migrateExecutions(sequelize) {
141290
141323
  for (const [taskId, execs] of byTask) {
141291
141324
  try {
141292
141325
  const taskDir = await findTaskBaseDir(taskId);
141293
- const execDir = (0, import_path21.join)(taskDir, taskId);
141326
+ const execDir = (0, import_path22.join)(taskDir, taskId);
141294
141327
  for (const row of execs) {
141295
- const filePath = (0, import_path21.join)(execDir, `${row.id}.json`);
141296
- if ((0, import_fs14.existsSync)(filePath)) continue;
141328
+ const filePath = (0, import_path22.join)(execDir, `${row.id}.json`);
141329
+ if ((0, import_fs15.existsSync)(filePath)) continue;
141297
141330
  const execution = {
141298
141331
  id: row.id,
141299
141332
  taskId: row.task_id,
@@ -141385,28 +141418,28 @@ function rowToTask(row, conversationMap) {
141385
141418
  };
141386
141419
  }
141387
141420
  async function findTaskBaseDir(taskId) {
141388
- const directGlobalPath = (0, import_path21.join)(getDataCronDir2(), `${taskId}.json`);
141389
- if ((0, import_fs14.existsSync)(directGlobalPath)) return getDataCronDir2();
141421
+ const directGlobalPath = (0, import_path22.join)(getDataCronDir2(), `${taskId}.json`);
141422
+ if ((0, import_fs15.existsSync)(directGlobalPath)) return getDataCronDir2();
141390
141423
  const agentsDir = getAgentsDir2();
141391
- if ((0, import_fs14.existsSync)(agentsDir)) {
141424
+ if ((0, import_fs15.existsSync)(agentsDir)) {
141392
141425
  try {
141393
- const owners = await (0, import_promises22.readdir)(agentsDir);
141426
+ const owners = await (0, import_promises23.readdir)(agentsDir);
141394
141427
  for (const ownerId of owners) {
141395
- const cronDir = (0, import_path21.join)(agentsDir, ownerId, CRON_DIR2);
141396
- const filePath = (0, import_path21.join)(cronDir, `${taskId}.json`);
141397
- if ((0, import_fs14.existsSync)(filePath)) return cronDir;
141428
+ const cronDir = (0, import_path22.join)(agentsDir, ownerId, CRON_DIR2);
141429
+ const filePath = (0, import_path22.join)(cronDir, `${taskId}.json`);
141430
+ if ((0, import_fs15.existsSync)(filePath)) return cronDir;
141398
141431
  }
141399
141432
  } catch {
141400
141433
  }
141401
141434
  }
141402
141435
  const groupsDir = getGroupsDir2();
141403
- if ((0, import_fs14.existsSync)(groupsDir)) {
141436
+ if ((0, import_fs15.existsSync)(groupsDir)) {
141404
141437
  try {
141405
- const owners = await (0, import_promises22.readdir)(groupsDir);
141438
+ const owners = await (0, import_promises23.readdir)(groupsDir);
141406
141439
  for (const ownerId of owners) {
141407
- const cronDir = (0, import_path21.join)(groupsDir, ownerId, CRON_DIR2);
141408
- const filePath = (0, import_path21.join)(cronDir, `${taskId}.json`);
141409
- if ((0, import_fs14.existsSync)(filePath)) return cronDir;
141440
+ const cronDir = (0, import_path22.join)(groupsDir, ownerId, CRON_DIR2);
141441
+ const filePath = (0, import_path22.join)(cronDir, `${taskId}.json`);
141442
+ if ((0, import_fs15.existsSync)(filePath)) return cronDir;
141410
141443
  }
141411
141444
  } catch {
141412
141445
  }
@@ -141439,14 +141472,14 @@ async function migrateCronSqliteToFileStore() {
141439
141472
  logger34.debug(`Migrated ${tasksMigrated} tasks and ${execsMigrated} executions to filesystem`);
141440
141473
  await dropLegacyTables(sequelize);
141441
141474
  }
141442
- var import_path21, import_promises22, import_fs14, logger34, CRON_DIR2;
141475
+ var import_path22, import_promises23, import_fs15, logger34, CRON_DIR2;
141443
141476
  var init_cron_sqlite_migration = __esm({
141444
141477
  "src/adapters/db/migration/cron-sqlite-migration.ts"() {
141445
141478
  "use strict";
141446
141479
  init_lib();
141447
- import_path21 = require("path");
141448
- import_promises22 = require("fs/promises");
141449
- import_fs14 = require("fs");
141480
+ import_path22 = require("path");
141481
+ import_promises23 = require("fs/promises");
141482
+ import_fs15 = require("fs");
141450
141483
  init_config();
141451
141484
  init_logger();
141452
141485
  logger34 = createLogger("cron-sqlite-migration");
@@ -160932,8 +160965,8 @@ var require_snapshot_utils = __commonJS({
160932
160965
  var require_snapshot_recorder = __commonJS({
160933
160966
  "node_modules/undici/lib/mock/snapshot-recorder.js"(exports2, module2) {
160934
160967
  "use strict";
160935
- var { writeFile: writeFile15, readFile: readFile18, mkdir: mkdir15 } = require("node:fs/promises");
160936
- var { dirname: dirname9, resolve: resolve9 } = require("node:path");
160968
+ var { writeFile: writeFile13, readFile: readFile17, mkdir: mkdir15 } = require("node:fs/promises");
160969
+ var { dirname: dirname8, resolve: resolve9 } = require("node:path");
160937
160970
  var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = require("node:timers");
160938
160971
  var { InvalidArgumentError: InvalidArgumentError3, UndiciError } = require_errors3();
160939
160972
  var { hashId, isUrlExcludedFactory, normalizeHeaders: normalizeHeaders3, createHeaderFilters } = require_snapshot_utils();
@@ -161134,7 +161167,7 @@ var require_snapshot_recorder = __commonJS({
161134
161167
  throw new InvalidArgumentError3("Snapshot path is required");
161135
161168
  }
161136
161169
  try {
161137
- const data2 = await readFile18(resolve9(path10), "utf8");
161170
+ const data2 = await readFile17(resolve9(path10), "utf8");
161138
161171
  const parsed = JSON.parse(data2);
161139
161172
  if (Array.isArray(parsed)) {
161140
161173
  this.#snapshots.clear();
@@ -161164,12 +161197,12 @@ var require_snapshot_recorder = __commonJS({
161164
161197
  throw new InvalidArgumentError3("Snapshot path is required");
161165
161198
  }
161166
161199
  const resolvedPath = resolve9(path10);
161167
- await mkdir15(dirname9(resolvedPath), { recursive: true });
161200
+ await mkdir15(dirname8(resolvedPath), { recursive: true });
161168
161201
  const data2 = Array.from(this.#snapshots.entries()).map(([hash2, snapshot]) => ({
161169
161202
  hash: hash2,
161170
161203
  snapshot
161171
161204
  }));
161172
- await writeFile15(resolvedPath, JSON.stringify(data2, null, 2), { flush: true });
161205
+ await writeFile13(resolvedPath, JSON.stringify(data2, null, 2), { flush: true });
161173
161206
  }
161174
161207
  /**
161175
161208
  * Clears all recorded snapshots
@@ -189923,7 +189956,7 @@ var McpManager = class {
189923
189956
  this.clients.set(id, client);
189924
189957
  const tools = await client.listTools();
189925
189958
  for (const tool2 of tools) {
189926
- const namespacedName = `${id}:${tool2.name}`;
189959
+ const namespacedName = `${id}_${tool2.name}`;
189927
189960
  this.tools.set(namespacedName, { client, tool: tool2, serverId: id, originalName: tool2.name });
189928
189961
  }
189929
189962
  }
@@ -190302,27 +190335,27 @@ var eventBridge = new EventBridge();
190302
190335
 
190303
190336
  // src/adapters/storage/SessionCleaner.ts
190304
190337
  init_config();
190305
- var import_path6 = __toESM(require("path"));
190306
- var import_promises4 = __toESM(require("fs/promises"));
190307
- var import_fs6 = require("fs");
190338
+ var import_path7 = __toESM(require("path"));
190339
+ var import_promises5 = __toESM(require("fs/promises"));
190340
+ var import_fs7 = require("fs");
190308
190341
  init_logger();
190309
190342
  var logger7 = createLogger("SessionCleaner");
190310
190343
  var SessionCleaner = class {
190311
190344
  async cleanOldSessions(maxAgeDays = 30) {
190312
- const sessionsDir = import_path6.default.join(config.getAppDataPath(), "sessions");
190313
- if (!(0, import_fs6.existsSync)(sessionsDir)) {
190345
+ const sessionsDir = import_path7.default.join(config.getAppDataPath(), "sessions");
190346
+ if (!(0, import_fs7.existsSync)(sessionsDir)) {
190314
190347
  return 0;
190315
190348
  }
190316
190349
  try {
190317
- const dirs = await import_promises4.default.readdir(sessionsDir);
190350
+ const dirs = await import_promises5.default.readdir(sessionsDir);
190318
190351
  const cutoffTime = Date.now() - maxAgeDays * 24 * 60 * 60 * 1e3;
190319
190352
  let cleaned = 0;
190320
190353
  for (const dir of dirs) {
190321
- const fullPath = import_path6.default.join(sessionsDir, dir);
190354
+ const fullPath = import_path7.default.join(sessionsDir, dir);
190322
190355
  try {
190323
- const stat5 = await import_promises4.default.stat(fullPath);
190356
+ const stat5 = await import_promises5.default.stat(fullPath);
190324
190357
  if (stat5.isDirectory() && stat5.mtimeMs < cutoffTime) {
190325
- await import_promises4.default.rm(fullPath, { recursive: true, force: true });
190358
+ await import_promises5.default.rm(fullPath, { recursive: true, force: true });
190326
190359
  cleaned++;
190327
190360
  logger7.debug("Removed old session:", dir);
190328
190361
  }
@@ -190655,12 +190688,12 @@ function extractQuoteText(quote) {
190655
190688
 
190656
190689
  // src/adapters/channel/wecom/WeComBotAdapter.ts
190657
190690
  init_logger();
190658
- var import_promises8 = require("node:fs/promises");
190691
+ var import_promises9 = require("node:fs/promises");
190659
190692
  var import_node_path = require("node:path");
190660
190693
 
190661
190694
  // src/adapters/storage/AttachmentStorage.ts
190662
- var import_fs7 = require("fs");
190663
- var import_path7 = require("path");
190695
+ var import_fs8 = require("fs");
190696
+ var import_path8 = require("path");
190664
190697
  init_config();
190665
190698
 
190666
190699
  // src/shared/utils/mime-types.ts
@@ -190746,10 +190779,10 @@ var logger8 = createLogger("attachment-storage");
190746
190779
  var AttachmentStorage = class {
190747
190780
  baseDir;
190748
190781
  constructor() {
190749
- this.baseDir = (0, import_path7.join)(config.getAppDataPath(), "attachments");
190782
+ this.baseDir = (0, import_path8.join)(config.getAppDataPath(), "attachments");
190750
190783
  }
190751
190784
  async ensureBaseDir() {
190752
- await import_fs7.promises.mkdir(this.baseDir, { recursive: true });
190785
+ await import_fs8.promises.mkdir(this.baseDir, { recursive: true });
190753
190786
  }
190754
190787
  getDateFolder() {
190755
190788
  const now2 = /* @__PURE__ */ new Date();
@@ -190758,16 +190791,16 @@ var AttachmentStorage = class {
190758
190791
  async saveAttachment(fileBuffer, originalFilename, providedMimeType) {
190759
190792
  await this.ensureBaseDir();
190760
190793
  const dateFolder = this.getDateFolder();
190761
- const datePath = (0, import_path7.join)(this.baseDir, dateFolder);
190762
- await import_fs7.promises.mkdir(datePath, { recursive: true });
190794
+ const datePath = (0, import_path8.join)(this.baseDir, dateFolder);
190795
+ await import_fs8.promises.mkdir(datePath, { recursive: true });
190763
190796
  const timestamp = Date.now();
190764
190797
  const sanitized = sanitizeFilename(originalFilename);
190765
190798
  const filename = `${timestamp}_${sanitized}`;
190766
- const absolutePath = (0, import_path7.join)(datePath, filename);
190767
- const relativePath = (0, import_path7.join)(dateFolder, filename);
190768
- await import_fs7.promises.writeFile(absolutePath, fileBuffer);
190769
- const stats = await import_fs7.promises.stat(absolutePath);
190770
- const ext = (0, import_path7.extname)(originalFilename).toLowerCase();
190799
+ const absolutePath = (0, import_path8.join)(datePath, filename);
190800
+ const relativePath = (0, import_path8.join)(dateFolder, filename);
190801
+ await import_fs8.promises.writeFile(absolutePath, fileBuffer);
190802
+ const stats = await import_fs8.promises.stat(absolutePath);
190803
+ const ext = (0, import_path8.extname)(originalFilename).toLowerCase();
190771
190804
  const mimeType = providedMimeType?.trim() || getMimeType(ext);
190772
190805
  return {
190773
190806
  id: `${timestamp}`,
@@ -190779,12 +190812,12 @@ var AttachmentStorage = class {
190779
190812
  };
190780
190813
  }
190781
190814
  async getAttachmentPath(relativePath) {
190782
- return (0, import_path7.join)(this.baseDir, relativePath);
190815
+ return (0, import_path8.join)(this.baseDir, relativePath);
190783
190816
  }
190784
190817
  async deleteAttachment(relativePath) {
190785
- const absolutePath = (0, import_path7.join)(this.baseDir, relativePath);
190818
+ const absolutePath = (0, import_path8.join)(this.baseDir, relativePath);
190786
190819
  try {
190787
- await import_fs7.promises.unlink(absolutePath);
190820
+ await import_fs8.promises.unlink(absolutePath);
190788
190821
  } catch (error48) {
190789
190822
  logger8.error("Failed to delete attachment:", error48);
190790
190823
  }
@@ -190800,8 +190833,8 @@ var AttachmentStorage = class {
190800
190833
 
190801
190834
  // src/adapters/storage/SessionStorage.ts
190802
190835
  init_config();
190803
- var import_path10 = __toESM(require("path"));
190804
- var import_promises7 = __toESM(require("fs/promises"));
190836
+ var import_path11 = __toESM(require("path"));
190837
+ var import_promises8 = __toESM(require("fs/promises"));
190805
190838
  init_thread_file_store();
190806
190839
  init_agent_file_store();
190807
190840
  init_logger();
@@ -190816,14 +190849,14 @@ var SessionStorage = class {
190816
190849
  */
190817
190850
  async getConversationsFile(conversationId) {
190818
190851
  const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
190819
- const dir = import_path10.default.resolve(
190852
+ const dir = import_path11.default.resolve(
190820
190853
  config.getAppDataPath(),
190821
190854
  `conversations/${conversationId}/messages`
190822
190855
  );
190823
- await import_promises7.default.mkdir(dir, { recursive: true }).catch((err) => {
190856
+ await import_promises8.default.mkdir(dir, { recursive: true }).catch((err) => {
190824
190857
  logger10.warn("Failed to create messages directory:", dir, err);
190825
190858
  });
190826
- return import_path10.default.resolve(dir, `${today}.jsonl`);
190859
+ return import_path11.default.resolve(dir, `${today}.jsonl`);
190827
190860
  }
190828
190861
  // ---------------------------------------------------------------------------
190829
190862
  // 单聊:~/.kai/agents/{agentId}/context.json
@@ -190832,7 +190865,7 @@ var SessionStorage = class {
190832
190865
  * 获取单聊上下文文件路径(纯函数)。
190833
190866
  */
190834
190867
  getAgentContextPath(agentId) {
190835
- return import_path10.default.join(getAgentRootDir(agentId), "context.json");
190868
+ return import_path11.default.join(getAgentRootDir(agentId), "context.json");
190836
190869
  }
190837
190870
  /**
190838
190871
  * 读取单聊上下文。
@@ -190840,7 +190873,7 @@ var SessionStorage = class {
190840
190873
  async getAgentContext(agentId) {
190841
190874
  const file2 = this.getAgentContextPath(agentId);
190842
190875
  try {
190843
- const content = await import_promises7.default.readFile(file2, "utf-8");
190876
+ const content = await import_promises8.default.readFile(file2, "utf-8");
190844
190877
  return JSON.parse(content);
190845
190878
  } catch (error48) {
190846
190879
  if (isErrnoException(error48) && error48.code === "ENOENT") {
@@ -190855,11 +190888,11 @@ var SessionStorage = class {
190855
190888
  */
190856
190889
  async saveAgentContext(agentId, messages) {
190857
190890
  const agentDir = getAgentRootDir(agentId);
190858
- await import_promises7.default.mkdir(agentDir, { recursive: true });
190891
+ await import_promises8.default.mkdir(agentDir, { recursive: true });
190859
190892
  const file2 = this.getAgentContextPath(agentId);
190860
190893
  const tmp = `${file2}.tmp`;
190861
- await import_promises7.default.writeFile(tmp, JSON.stringify(messages, null, 2), "utf-8");
190862
- await import_promises7.default.rename(tmp, file2);
190894
+ await import_promises8.default.writeFile(tmp, JSON.stringify(messages, null, 2), "utf-8");
190895
+ await import_promises8.default.rename(tmp, file2);
190863
190896
  }
190864
190897
  // ---------------------------------------------------------------------------
190865
190898
  // 群聊:groups/{groupId}/threads/{threadId}/context.json
@@ -190868,7 +190901,7 @@ var SessionStorage = class {
190868
190901
  * 获取线程上下文文件路径(纯函数,无副作用)。
190869
190902
  */
190870
190903
  getThreadContextPath(groupId, threadId) {
190871
- return import_path10.default.join(getThreadDir(groupId, threadId), "context.json");
190904
+ return import_path11.default.join(getThreadDir(groupId, threadId), "context.json");
190872
190905
  }
190873
190906
  /**
190874
190907
  * 读取线程上下文(群聊)。
@@ -190876,7 +190909,7 @@ var SessionStorage = class {
190876
190909
  async getThreadContext(groupId, threadId) {
190877
190910
  const file2 = this.getThreadContextPath(groupId, threadId);
190878
190911
  try {
190879
- const content = await import_promises7.default.readFile(file2, "utf-8");
190912
+ const content = await import_promises8.default.readFile(file2, "utf-8");
190880
190913
  return JSON.parse(content);
190881
190914
  } catch (error48) {
190882
190915
  if (isErrnoException(error48) && error48.code === "ENOENT") {
@@ -190891,11 +190924,11 @@ var SessionStorage = class {
190891
190924
  */
190892
190925
  async saveThreadContext(groupId, threadId, messages) {
190893
190926
  const threadDir = getThreadDir(groupId, threadId);
190894
- await import_promises7.default.mkdir(threadDir, { recursive: true });
190927
+ await import_promises8.default.mkdir(threadDir, { recursive: true });
190895
190928
  const file2 = this.getThreadContextPath(groupId, threadId);
190896
190929
  const tmp = `${file2}.tmp`;
190897
- await import_promises7.default.writeFile(tmp, JSON.stringify(messages, null, 2), "utf-8");
190898
- await import_promises7.default.rename(tmp, file2);
190930
+ await import_promises8.default.writeFile(tmp, JSON.stringify(messages, null, 2), "utf-8");
190931
+ await import_promises8.default.rename(tmp, file2);
190899
190932
  }
190900
190933
  // ---------------------------------------------------------------------------
190901
190934
  // 通用
@@ -190906,14 +190939,14 @@ var SessionStorage = class {
190906
190939
  const file2 = await this.getConversationsFile(conversationId);
190907
190940
  let startSeq = 1;
190908
190941
  try {
190909
- const existing = await import_promises7.default.readFile(file2, "utf-8");
190942
+ const existing = await import_promises8.default.readFile(file2, "utf-8");
190910
190943
  startSeq = existing.trim().split("\n").filter(Boolean).length + 1;
190911
190944
  } catch {
190912
190945
  }
190913
190946
  const lines = filtered.map(
190914
190947
  (m, i) => JSON.stringify({ seq: startSeq + i, role: m.role, content: m.content, timestamp: Date.now() })
190915
190948
  );
190916
- await import_promises7.default.appendFile(file2, lines.join("\n") + "\n", "utf-8");
190949
+ await import_promises8.default.appendFile(file2, lines.join("\n") + "\n", "utf-8");
190917
190950
  }
190918
190951
  };
190919
190952
 
@@ -191024,7 +191057,7 @@ var WeComBotAdapter = class {
191024
191057
  if (!this.client) {
191025
191058
  throw new Error("Client not initialized");
191026
191059
  }
191027
- const buffer = await (0, import_promises8.readFile)(filePath);
191060
+ const buffer = await (0, import_promises9.readFile)(filePath);
191028
191061
  const filename = (0, import_node_path.basename)(filePath);
191029
191062
  const mediaType = isImageExtension((0, import_node_path.extname)(filePath)) ? "image" : "file";
191030
191063
  const uploaded = await this.client.uploadMedia(buffer, { type: mediaType, filename });
@@ -191742,7 +191775,7 @@ var WeChatPersonalClient = class {
191742
191775
 
191743
191776
  // src/adapters/channel/wechat-personal/WeChatPersonalAdapter.ts
191744
191777
  init_logger();
191745
- var import_promises9 = require("node:fs/promises");
191778
+ var import_promises10 = require("node:fs/promises");
191746
191779
  var import_node_path2 = require("node:path");
191747
191780
  var log7 = createLogger("WeChatPersonalAdapter");
191748
191781
  var WeChatPersonalAdapter = class {
@@ -191810,7 +191843,7 @@ var WeChatPersonalAdapter = class {
191810
191843
  if (!this.client) {
191811
191844
  throw new Error("Client not initialized");
191812
191845
  }
191813
- const buffer = await (0, import_promises9.readFile)(filePath);
191846
+ const buffer = await (0, import_promises10.readFile)(filePath);
191814
191847
  const filename = (0, import_node_path2.basename)(filePath);
191815
191848
  const mediaType = isImageExtension((0, import_node_path2.extname)(filePath)) ? "image" : "file";
191816
191849
  await this.client.sendFile(chatId, buffer, filename, mediaType);
@@ -191901,15 +191934,15 @@ var WeChatPersonalAdapter = class {
191901
191934
  };
191902
191935
 
191903
191936
  // src/adapters/channel/shared/ChannelConfigStore.ts
191904
- var import_fs10 = require("fs");
191905
- var import_path11 = require("path");
191937
+ var import_fs11 = require("fs");
191938
+ var import_path12 = require("path");
191906
191939
  init_logger();
191907
191940
  init_config();
191908
191941
  var log8 = createLogger("ChannelConfigStore");
191909
191942
  var ChannelConfigStore = class {
191910
191943
  baseDir;
191911
191944
  constructor(baseDir) {
191912
- this.baseDir = baseDir ?? (0, import_path11.join)(config.getAppDataPath(), "channels");
191945
+ this.baseDir = baseDir ?? (0, import_path12.join)(config.getAppDataPath(), "channels");
191913
191946
  this.ensureDir();
191914
191947
  }
191915
191948
  /** 文件名:{type}_{connectionId}.json */
@@ -191918,24 +191951,31 @@ var ChannelConfigStore = class {
191918
191951
  }
191919
191952
  /** 确保存储目录存在 */
191920
191953
  ensureDir() {
191921
- if (!(0, import_fs10.existsSync)(this.baseDir)) {
191922
- (0, import_fs10.mkdirSync)(this.baseDir, { recursive: true });
191954
+ if (!(0, import_fs11.existsSync)(this.baseDir)) {
191955
+ (0, import_fs11.mkdirSync)(this.baseDir, { recursive: true });
191923
191956
  log8.info(`Created channels directory: ${this.baseDir}`);
191924
191957
  }
191925
191958
  }
191959
+ readConfig(filePath) {
191960
+ const raw = (0, import_fs11.readFileSync)(filePath, "utf-8");
191961
+ const config3 = JSON.parse(raw);
191962
+ if (!config3.createdAt) {
191963
+ const stat5 = (0, import_fs11.statSync)(filePath);
191964
+ config3.createdAt = stat5.birthtimeMs || stat5.mtimeMs;
191965
+ }
191966
+ return config3;
191967
+ }
191926
191968
  /** 列出所有已配置的接入 */
191927
191969
  async list() {
191928
- if (!(0, import_fs10.existsSync)(this.baseDir)) {
191970
+ if (!(0, import_fs11.existsSync)(this.baseDir)) {
191929
191971
  return [];
191930
191972
  }
191931
- const files = (0, import_fs10.readdirSync)(this.baseDir).filter((f) => f.endsWith(".json"));
191973
+ const files = (0, import_fs11.readdirSync)(this.baseDir).filter((f) => f.endsWith(".json"));
191932
191974
  const configs = [];
191933
191975
  for (const file2 of files) {
191934
191976
  try {
191935
- const filePath = (0, import_path11.join)(this.baseDir, file2);
191936
- const raw = (0, import_fs10.readFileSync)(filePath, "utf-8");
191937
- const config3 = JSON.parse(raw);
191938
- configs.push(config3);
191977
+ const filePath = (0, import_path12.join)(this.baseDir, file2);
191978
+ configs.push(this.readConfig(filePath));
191939
191979
  } catch (err) {
191940
191980
  log8.error(`Failed to read channel config ${file2}:`, err);
191941
191981
  }
@@ -191945,12 +191985,11 @@ var ChannelConfigStore = class {
191945
191985
  }
191946
191986
  /** 获取指定接入配置 */
191947
191987
  async get(connectionId) {
191948
- const files = (0, import_fs10.readdirSync)(this.baseDir).filter((f) => f.endsWith(".json"));
191988
+ const files = (0, import_fs11.readdirSync)(this.baseDir).filter((f) => f.endsWith(".json"));
191949
191989
  for (const file2 of files) {
191950
- const filePath = (0, import_path11.join)(this.baseDir, file2);
191990
+ const filePath = (0, import_path12.join)(this.baseDir, file2);
191951
191991
  try {
191952
- const raw = (0, import_fs10.readFileSync)(filePath, "utf-8");
191953
- const config3 = JSON.parse(raw);
191992
+ const config3 = this.readConfig(filePath);
191954
191993
  if (config3.connectionId === connectionId) {
191955
191994
  return config3;
191956
191995
  }
@@ -191963,9 +192002,9 @@ var ChannelConfigStore = class {
191963
192002
  /** 保存接入配置 */
191964
192003
  async save(config3) {
191965
192004
  this.ensureDir();
191966
- const filePath = (0, import_path11.join)(this.baseDir, this.filename(config3));
192005
+ const filePath = (0, import_path12.join)(this.baseDir, this.filename(config3));
191967
192006
  const raw = JSON.stringify(config3, null, 2);
191968
- (0, import_fs10.writeFileSync)(filePath, raw, "utf-8");
192007
+ (0, import_fs11.writeFileSync)(filePath, raw, "utf-8");
191969
192008
  log8.info(`Saved channel config: ${filePath}`);
191970
192009
  }
191971
192010
  /** 删除接入配置 */
@@ -191975,8 +192014,8 @@ var ChannelConfigStore = class {
191975
192014
  log8.warn(`Channel config not found for deletion: ${connectionId}`);
191976
192015
  return;
191977
192016
  }
191978
- const filePath = (0, import_path11.join)(this.baseDir, this.filename(config3));
191979
- (0, import_fs10.unlinkSync)(filePath);
192017
+ const filePath = (0, import_path12.join)(this.baseDir, this.filename(config3));
192018
+ (0, import_fs11.unlinkSync)(filePath);
191980
192019
  log8.info(`Deleted channel config: ${filePath}`);
191981
192020
  }
191982
192021
  /** 获取存储目录路径 */
@@ -192052,8 +192091,8 @@ var DedupeModule = class {
192052
192091
  };
192053
192092
 
192054
192093
  // src/adapters/channel/shared/LocalSecretStore.ts
192055
- var import_fs11 = require("fs");
192056
- var import_path12 = require("path");
192094
+ var import_fs12 = require("fs");
192095
+ var import_path13 = require("path");
192057
192096
  init_logger();
192058
192097
  init_crypto();
192059
192098
  init_constants();
@@ -192063,9 +192102,9 @@ var LocalSecretStore = class {
192063
192102
  baseDir;
192064
192103
  encryptionKey = null;
192065
192104
  constructor(baseDir) {
192066
- this.baseDir = baseDir ?? (0, import_path12.join)(config.getAppDataPath(), "channels", "secrets");
192067
- if (!(0, import_fs11.existsSync)(this.baseDir)) {
192068
- (0, import_fs11.mkdirSync)(this.baseDir, { recursive: true });
192105
+ this.baseDir = baseDir ?? (0, import_path13.join)(config.getAppDataPath(), "channels", "secrets");
192106
+ if (!(0, import_fs12.existsSync)(this.baseDir)) {
192107
+ (0, import_fs12.mkdirSync)(this.baseDir, { recursive: true });
192069
192108
  }
192070
192109
  this.migrateColonFilenames();
192071
192110
  }
@@ -192075,17 +192114,17 @@ var LocalSecretStore = class {
192075
192114
  */
192076
192115
  migrateColonFilenames() {
192077
192116
  try {
192078
- const files = (0, import_fs11.readdirSync)(this.baseDir);
192117
+ const files = (0, import_fs12.readdirSync)(this.baseDir);
192079
192118
  for (const file2 of files) {
192080
192119
  const sanitized = sanitizeFilename(file2, { allowUnicode: false });
192081
192120
  if (sanitized !== file2) {
192082
- const oldPath = (0, import_path12.join)(this.baseDir, file2);
192083
- const newPath = (0, import_path12.join)(this.baseDir, sanitized);
192084
- if (!(0, import_fs11.existsSync)(newPath)) {
192085
- (0, import_fs11.renameSync)(oldPath, newPath);
192121
+ const oldPath = (0, import_path13.join)(this.baseDir, file2);
192122
+ const newPath = (0, import_path13.join)(this.baseDir, sanitized);
192123
+ if (!(0, import_fs12.existsSync)(newPath)) {
192124
+ (0, import_fs12.renameSync)(oldPath, newPath);
192086
192125
  log10.info(`Migrated secret file: ${file2} \u2192 ${sanitized}`);
192087
192126
  } else {
192088
- (0, import_fs11.unlinkSync)(oldPath);
192127
+ (0, import_fs12.unlinkSync)(oldPath);
192089
192128
  log10.info(`Removed legacy secret file (new exists): ${file2}`);
192090
192129
  }
192091
192130
  }
@@ -192099,13 +192138,13 @@ var LocalSecretStore = class {
192099
192138
  */
192100
192139
  getEncryptionKey() {
192101
192140
  if (this.encryptionKey) return this.encryptionKey;
192102
- const configDir = (0, import_path12.join)(config.getAppDataPath(), CONFIG.CONFIG_DIR);
192103
- const saltPath = (0, import_path12.join)(configDir, CONFIG.SALT_FILE);
192104
- const machineIdPath = (0, import_path12.join)(configDir, CONFIG.MACHINE_ID_FILE);
192105
- if (!(0, import_fs11.existsSync)(saltPath) || !(0, import_fs11.existsSync)(machineIdPath)) {
192141
+ const configDir = (0, import_path13.join)(config.getAppDataPath(), CONFIG.CONFIG_DIR);
192142
+ const saltPath = (0, import_path13.join)(configDir, CONFIG.SALT_FILE);
192143
+ const machineIdPath = (0, import_path13.join)(configDir, CONFIG.MACHINE_ID_FILE);
192144
+ if (!(0, import_fs12.existsSync)(saltPath) || !(0, import_fs12.existsSync)(machineIdPath)) {
192106
192145
  throw new Error("\u52A0\u5BC6\u57FA\u7840\u8BBE\u65BD\u672A\u521D\u59CB\u5316\uFF1A\u8BF7\u5148\u542F\u52A8\u5E94\u7528\u5B8C\u6210\u914D\u7F6E\u521D\u59CB\u5316");
192107
192146
  }
192108
- const salt = (0, import_fs11.readFileSync)(saltPath);
192147
+ const salt = (0, import_fs12.readFileSync)(saltPath);
192109
192148
  const machineId = getMachineId(machineIdPath);
192110
192149
  this.encryptionKey = deriveKey(machineId, salt);
192111
192150
  return this.encryptionKey;
@@ -192115,10 +192154,10 @@ var LocalSecretStore = class {
192115
192154
  return sanitizeFilename(key, { allowUnicode: false }) + ".secret";
192116
192155
  }
192117
192156
  async get(key) {
192118
- const filePath = (0, import_path12.join)(this.baseDir, this.filename(key));
192119
- if (!(0, import_fs11.existsSync)(filePath)) return null;
192157
+ const filePath = (0, import_path13.join)(this.baseDir, this.filename(key));
192158
+ if (!(0, import_fs12.existsSync)(filePath)) return null;
192120
192159
  try {
192121
- const raw = (0, import_fs11.readFileSync)(filePath, "utf-8").trim();
192160
+ const raw = (0, import_fs12.readFileSync)(filePath, "utf-8").trim();
192122
192161
  if (!isEncrypted(raw)) {
192123
192162
  log10.error(`Secret file corrupted (no enc: prefix): ${key}`);
192124
192163
  return null;
@@ -192131,14 +192170,14 @@ var LocalSecretStore = class {
192131
192170
  }
192132
192171
  async set(key, value) {
192133
192172
  const encrypted = encrypt(value, this.getEncryptionKey());
192134
- const filePath = (0, import_path12.join)(this.baseDir, this.filename(key));
192135
- (0, import_fs11.writeFileSync)(filePath, encrypted, "utf-8");
192173
+ const filePath = (0, import_path13.join)(this.baseDir, this.filename(key));
192174
+ (0, import_fs12.writeFileSync)(filePath, encrypted, "utf-8");
192136
192175
  log10.info(`Secret saved: ${key}`);
192137
192176
  }
192138
192177
  async delete(key) {
192139
- const filePath = (0, import_path12.join)(this.baseDir, this.filename(key));
192140
- if ((0, import_fs11.existsSync)(filePath)) {
192141
- (0, import_fs11.unlinkSync)(filePath);
192178
+ const filePath = (0, import_path13.join)(this.baseDir, this.filename(key));
192179
+ if ((0, import_fs12.existsSync)(filePath)) {
192180
+ (0, import_fs12.unlinkSync)(filePath);
192142
192181
  log10.info(`Secret deleted: ${key}`);
192143
192182
  }
192144
192183
  }
@@ -192320,7 +192359,7 @@ function checkSendFilePolicy(resolvedPath) {
192320
192359
  }
192321
192360
 
192322
192361
  // src/adapters/channel/shared/ChannelManager.ts
192323
- var import_promises13 = require("node:fs/promises");
192362
+ var import_promises14 = require("node:fs/promises");
192324
192363
  init_config();
192325
192364
  var log20 = createLogger("ChannelManager");
192326
192365
  var ChannelManager = class {
@@ -192899,12 +192938,12 @@ var ChannelManager = class {
192899
192938
  }
192900
192939
  /** 黑名单校验:拒绝敏感路径,仅允许真实普通文件且不超过附件大小上限 */
192901
192940
  async assertSendableFilePath(filePath) {
192902
- const resolvedPath = await (0, import_promises13.realpath)(filePath);
192941
+ const resolvedPath = await (0, import_promises14.realpath)(filePath);
192903
192942
  const policyReject = checkSendFilePolicy(resolvedPath);
192904
192943
  if (policyReject) {
192905
192944
  throw new Error(`sendFile blocked: ${policyReject}`);
192906
192945
  }
192907
- const fileStat = await (0, import_promises13.stat)(resolvedPath);
192946
+ const fileStat = await (0, import_promises14.stat)(resolvedPath);
192908
192947
  if (!fileStat.isFile()) {
192909
192948
  throw new Error(`sendFile path is not a file: ${filePath}`);
192910
192949
  }
@@ -212978,6 +213017,13 @@ function getAutoUpdater() {
212978
213017
  return autoUpdater;
212979
213018
  }
212980
213019
  var AutoUpdaterManager = class {
213020
+ constructor(deps = {
213021
+ electron: getElectron,
213022
+ autoUpdater: getAutoUpdater
213023
+ }) {
213024
+ this.deps = deps;
213025
+ }
213026
+ deps;
212981
213027
  status = "idle";
212982
213028
  updateInfo = null;
212983
213029
  errorMessage = null;
@@ -212985,12 +213031,16 @@ var AutoUpdaterManager = class {
212985
213031
  dailyCheckRunning = false;
212986
213032
  suppressErrorEvents = false;
212987
213033
  suppressRoutineStatusEvents = false;
212988
- /** 检测到更新时,从 files 列表中提取的 DMG 下载 URL */
212989
- dmgUrl = null;
213034
+ progress = null;
213035
+ /** macOS 无签名证书时走浏览器手动下载 DMG;Windows/Linux 走 electron-updater。 */
213036
+ manualDownloadUrl = null;
213037
+ initialized = false;
212990
213038
  init() {
212991
- const { app } = getElectron();
213039
+ if (this.initialized) return;
213040
+ const { app } = this.deps.electron();
212992
213041
  if (!app.isPackaged) return;
212993
- const autoUpdater = getAutoUpdater();
213042
+ this.initialized = true;
213043
+ const autoUpdater = this.deps.autoUpdater();
212994
213044
  autoUpdater.autoDownload = false;
212995
213045
  autoUpdater.autoRunAppAfterInstall = true;
212996
213046
  autoUpdater.on("checking-for-update", () => {
@@ -212999,21 +213049,26 @@ var AutoUpdaterManager = class {
212999
213049
  autoUpdater.on("update-available", (info) => {
213000
213050
  this.updateInfo = {
213001
213051
  version: info.version,
213002
- releaseDate: info.releaseDate ?? null
213052
+ releaseDate: info.releaseDate ?? null,
213053
+ manualDownloadUrl: this.resolveManualDownloadUrl(info)
213003
213054
  };
213004
- const arch = process.arch;
213005
- const files = info.files;
213006
- if (files && files.length > 0) {
213007
- const matched = arch === "arm64" ? files.find((f) => f.url.toLowerCase().endsWith(".dmg") && f.url.toLowerCase().includes("arm64")) : files.find((f) => f.url.toLowerCase().endsWith(".dmg") && !f.url.toLowerCase().includes("arm64"));
213008
- if (matched) {
213009
- this.dmgUrl = `${PUBLISH_BASE_URL}/${matched.url}`;
213010
- }
213011
- }
213055
+ this.manualDownloadUrl = this.updateInfo.manualDownloadUrl ?? null;
213012
213056
  this.updateState("available");
213013
- eventBridge.broadcast(IPC_UPDATE_AVAILABLE_EVENT, {
213014
- ...this.updateInfo,
213015
- dmgUrl: this.dmgUrl
213016
- });
213057
+ eventBridge.broadcast(IPC_UPDATE_AVAILABLE_EVENT, this.updateInfo);
213058
+ });
213059
+ autoUpdater.on("download-progress", (progress) => {
213060
+ this.progress = {
213061
+ percent: progress.percent,
213062
+ bytesPerSecond: progress.bytesPerSecond,
213063
+ transferred: progress.transferred,
213064
+ total: progress.total
213065
+ };
213066
+ this.updateState("downloading");
213067
+ eventBridge.broadcast(IPC_UPDATE_PROGRESS_EVENT, this.progress);
213068
+ });
213069
+ autoUpdater.on("update-downloaded", () => {
213070
+ this.updateState("downloaded");
213071
+ eventBridge.broadcast(IPC_UPDATE_DOWNLOADED_EVENT);
213017
213072
  });
213018
213073
  autoUpdater.on("update-not-available", () => {
213019
213074
  this.updateState("not-available");
@@ -213029,7 +213084,7 @@ var AutoUpdaterManager = class {
213029
213084
  /** 用户每日首次发送消息后静默检查(延迟 3s) */
213030
213085
  triggerDailyAutoCheck() {
213031
213086
  if (process.env.KAI_RUNTIME === "cli") return;
213032
- const { app } = getElectron();
213087
+ const { app } = this.deps.electron();
213033
213088
  if (!app.isPackaged) return;
213034
213089
  const enabled = config.get("autoCheckForUpdates");
213035
213090
  if (enabled === false) return;
@@ -213054,15 +213109,16 @@ var AutoUpdaterManager = class {
213054
213109
  }
213055
213110
  }
213056
213111
  async checkForUpdate(options2 = {}) {
213057
- const { app } = getElectron();
213112
+ const { app } = this.deps.electron();
213058
213113
  if (!app.isPackaged) {
213059
213114
  this.updateState("not-available");
213060
213115
  return;
213061
213116
  }
213062
213117
  this.updateInfo = null;
213063
213118
  this.errorMessage = null;
213064
- this.dmgUrl = null;
213065
- const autoUpdater = getAutoUpdater();
213119
+ this.progress = null;
213120
+ this.manualDownloadUrl = null;
213121
+ const autoUpdater = this.deps.autoUpdater();
213066
213122
  const silent = options2.silent === true;
213067
213123
  const previousSuppressErrorEvents = this.suppressErrorEvents;
213068
213124
  const previousSuppressRoutineStatusEvents = this.suppressRoutineStatusEvents;
@@ -213085,30 +213141,39 @@ var AutoUpdaterManager = class {
213085
213141
  }
213086
213142
  }
213087
213143
  /**
213088
- * 打开 DMG 下载链接(浏览器)
213144
+ * macOS 打开 DMG 下载链接;Windows/Linux 使用 electron-updater 标准下载。
213089
213145
  *
213090
213146
  * 没有开发者证书时,electron-updater 的 zip + ShipIt 路线走不通(签名验证失败)。
213091
213147
  * 改为直接在浏览器下载 DMG,用户手动安装。
213092
213148
  */
213093
213149
  async downloadUpdate() {
213094
- const url2 = this.dmgUrl;
213150
+ if (process.platform !== "darwin") {
213151
+ await this.deps.autoUpdater().downloadUpdate();
213152
+ return;
213153
+ }
213154
+ const url2 = this.manualDownloadUrl;
213095
213155
  if (!url2) {
213096
213156
  this.errorMessage = "\u672A\u627E\u5230\u4E0B\u8F7D\u94FE\u63A5";
213097
213157
  this.updateState("error");
213098
213158
  eventBridge.broadcast(IPC_UPDATE_ERROR_EVENT, { message: this.errorMessage });
213099
213159
  return;
213100
213160
  }
213101
- await getElectron().shell.openExternal(url2);
213161
+ await this.deps.electron().shell.openExternal(url2);
213102
213162
  }
213103
- /** DMG 模式下不可用,保留接口兼容 */
213163
+ /** macOS 手动 DMG 模式下不可用,保留接口兼容 */
213104
213164
  quitAndInstall() {
213165
+ if (process.platform !== "darwin") {
213166
+ this.deps.autoUpdater().quitAndInstall(false, true);
213167
+ return;
213168
+ }
213105
213169
  const message = "\u8BF7\u624B\u52A8\u5B89\u88C5\u4E0B\u8F7D\u7684 DMG \u6587\u4EF6";
213106
213170
  eventBridge.broadcast(IPC_UPDATE_ERROR_EVENT, { message });
213107
213171
  }
213108
213172
  getStatus() {
213109
213173
  return {
213110
213174
  status: this.status,
213111
- info: this.updateInfo ? { ...this.updateInfo, dmgUrl: this.dmgUrl } : null,
213175
+ info: this.updateInfo,
213176
+ progress: this.progress,
213112
213177
  errorMessage: this.errorMessage
213113
213178
  };
213114
213179
  }
@@ -213117,7 +213182,17 @@ var AutoUpdaterManager = class {
213117
213182
  if (this.suppressRoutineStatusEvents && s !== "available") return;
213118
213183
  eventBridge.broadcast(IPC_UPDATE_STATUS_EVENT, s);
213119
213184
  }
213185
+ resolveManualDownloadUrl(info) {
213186
+ if (process.platform !== "darwin") return null;
213187
+ const files = info.files ?? [];
213188
+ const arch = process.arch;
213189
+ const matched = arch === "arm64" ? files.find((file2) => isDmg(file2.url) && file2.url.toLowerCase().includes("arm64")) : files.find((file2) => isDmg(file2.url) && !file2.url.toLowerCase().includes("arm64"));
213190
+ return matched ? new URL(encodeURI(matched.url), `${PUBLISH_BASE_URL}/`).toString() : null;
213191
+ }
213120
213192
  };
213193
+ function isDmg(url2) {
213194
+ return url2.toLowerCase().endsWith(".dmg");
213195
+ }
213121
213196
  function getLocalDateString(date5 = /* @__PURE__ */ new Date()) {
213122
213197
  const year = date5.getFullYear();
213123
213198
  const month = String(date5.getMonth() + 1).padStart(2, "0");
@@ -213363,7 +213438,7 @@ function registerChatHandlers() {
213363
213438
  }
213364
213439
 
213365
213440
  // src/electron/main/handlers/conversation-handlers.ts
213366
- var import_promises15 = require("fs/promises");
213441
+ var import_promises16 = require("fs/promises");
213367
213442
  init_conversation_event_bus();
213368
213443
  init_message2();
213369
213444
  init_agent_file_store();
@@ -213380,8 +213455,8 @@ init_ThreadManagerPool();
213380
213455
  init_logger();
213381
213456
 
213382
213457
  // src/electron/main/handlers/avatar-storage.ts
213383
- var import_promises14 = require("fs/promises");
213384
- var import_path18 = require("path");
213458
+ var import_promises15 = require("fs/promises");
213459
+ var import_path19 = require("path");
213385
213460
  var import_sharp = __toESM(require("sharp"));
213386
213461
  var AVATAR_DIR = "avatars";
213387
213462
  var AVATAR_FILE = "avatar.png";
@@ -213391,12 +213466,12 @@ var AVATAR_SIZE = 256;
213391
213466
  async function writeOwnerAvatar(ownerDir, sourcePath) {
213392
213467
  const source = sourcePath.trim();
213393
213468
  if (!source) throw new Error("AVATAR_SOURCE_REQUIRED");
213394
- const sourceStats = await (0, import_promises14.stat)(source).catch(() => null);
213469
+ const sourceStats = await (0, import_promises15.stat)(source).catch(() => null);
213395
213470
  if (!sourceStats?.isFile()) throw new Error("AVATAR_SOURCE_NOT_FILE");
213396
213471
  if (sourceStats.size > MAX_AVATAR_SOURCE_BYTES) throw new Error("AVATAR_IMAGE_TOO_LARGE");
213397
- const avatarDir = (0, import_path18.join)(ownerDir, AVATAR_DIR);
213398
- const avatarPath = (0, import_path18.join)(avatarDir, AVATAR_FILE);
213399
- await (0, import_promises14.mkdir)(avatarDir, { recursive: true });
213472
+ const avatarDir = (0, import_path19.join)(ownerDir, AVATAR_DIR);
213473
+ const avatarPath = (0, import_path19.join)(avatarDir, AVATAR_FILE);
213474
+ await (0, import_promises15.mkdir)(avatarDir, { recursive: true });
213400
213475
  try {
213401
213476
  await (0, import_sharp.default)(source, { failOn: "error" }).rotate().resize(AVATAR_SIZE, AVATAR_SIZE, { fit: "cover", position: "centre" }).png().toFile(avatarPath);
213402
213477
  } catch (error48) {
@@ -213408,7 +213483,7 @@ async function writeOwnerAvatar(ownerDir, sourcePath) {
213408
213483
  return AVATAR_RELATIVE_PATH;
213409
213484
  }
213410
213485
  async function removeOwnerAvatar(ownerDir) {
213411
- await (0, import_promises14.rm)((0, import_path18.join)(ownerDir, AVATAR_DIR), { force: true, recursive: true }).catch(() => void 0);
213486
+ await (0, import_promises15.rm)((0, import_path19.join)(ownerDir, AVATAR_DIR), { force: true, recursive: true }).catch(() => void 0);
213412
213487
  }
213413
213488
 
213414
213489
  // src/electron/main/handlers/conversation-handlers.ts
@@ -213675,7 +213750,7 @@ async function handleOpenAttachment(relativePath) {
213675
213750
  await shell2.openPath(absolutePath);
213676
213751
  }
213677
213752
  async function openDir(dir) {
213678
- await (0, import_promises15.mkdir)(dir, { recursive: true });
213753
+ await (0, import_promises16.mkdir)(dir, { recursive: true });
213679
213754
  const { shell: shell2 } = require("electron");
213680
213755
  const error48 = await shell2.openPath(dir);
213681
213756
  if (error48) throw new Error(error48);
@@ -214513,7 +214588,7 @@ function registerSearchHandlers() {
214513
214588
  }
214514
214589
 
214515
214590
  // src/electron/main/handlers/url-handlers.ts
214516
- var import_promises16 = __toESM(require("node:fs/promises"));
214591
+ var import_promises17 = __toESM(require("node:fs/promises"));
214517
214592
  var import_node_path4 = __toESM(require("node:path"));
214518
214593
  init_ipc_events();
214519
214594
  init_config();
@@ -214620,7 +214695,7 @@ async function handleOpenExternalUrl(url2) {
214620
214695
  }
214621
214696
  async function handleOpenLocalPath(inputPath) {
214622
214697
  const resolvedPath = resolveLocalPath(inputPath);
214623
- const stats = await import_promises16.default.stat(resolvedPath).catch(() => null);
214698
+ const stats = await import_promises17.default.stat(resolvedPath).catch(() => null);
214624
214699
  if (!stats?.isFile()) {
214625
214700
  throw new Error("ERROR_LOCAL_PATH_NOT_FILE");
214626
214701
  }
@@ -214630,7 +214705,7 @@ async function handleOpenLocalPath(inputPath) {
214630
214705
  }
214631
214706
  async function handleReadFileContent(inputPath) {
214632
214707
  const resolvedPath = resolveLocalPath(inputPath);
214633
- const stats = await import_promises16.default.stat(resolvedPath).catch(() => null);
214708
+ const stats = await import_promises17.default.stat(resolvedPath).catch(() => null);
214634
214709
  if (!stats?.isFile()) {
214635
214710
  throw new Error("ERROR_LOCAL_PATH_NOT_FILE");
214636
214711
  }
@@ -214644,7 +214719,7 @@ async function handleReadFileContent(inputPath) {
214644
214719
  mimeType
214645
214720
  };
214646
214721
  }
214647
- const buffer = await import_promises16.default.readFile(resolvedPath);
214722
+ const buffer = await import_promises17.default.readFile(resolvedPath);
214648
214723
  const isText2 = !isBufferBinary(buffer);
214649
214724
  const content = isText2 ? buffer.toString("utf-8") : "";
214650
214725
  return {
@@ -214661,7 +214736,7 @@ async function handleShowLocalItemInFolder(localUrlOrPath) {
214661
214736
  }
214662
214737
  async function handleCopyImageToClipboard(localUrlOrPath) {
214663
214738
  const resolvedPath = localUrlOrPath.startsWith("kai://local/") ? resolveKaiLocalPath(localUrlOrPath) : resolveLocalPath(localUrlOrPath);
214664
- const stats = await import_promises16.default.stat(resolvedPath).catch(() => null);
214739
+ const stats = await import_promises17.default.stat(resolvedPath).catch(() => null);
214665
214740
  if (!stats?.isFile()) {
214666
214741
  throw new Error("ERROR_LOCAL_PATH_NOT_FILE");
214667
214742
  }
@@ -215172,7 +215247,7 @@ function setupHealthIPC() {
215172
215247
 
215173
215248
  // src/electron/main/handlers/app-info-handlers.ts
215174
215249
  init_ipc_events();
215175
- var import_promises17 = __toESM(require("node:fs/promises"));
215250
+ var import_promises18 = __toESM(require("node:fs/promises"));
215176
215251
  var import_node_path5 = __toESM(require("node:path"));
215177
215252
  function getReleaseNotesPath() {
215178
215253
  const { app } = require("electron");
@@ -215191,7 +215266,7 @@ async function handleGetAppInfo() {
215191
215266
  }
215192
215267
  async function handleGetReleaseNotes() {
215193
215268
  try {
215194
- return await import_promises17.default.readFile(getReleaseNotesPath(), "utf-8");
215269
+ return await import_promises18.default.readFile(getReleaseNotesPath(), "utf-8");
215195
215270
  } catch {
215196
215271
  return "";
215197
215272
  }
@@ -215209,12 +215284,12 @@ init_config();
215209
215284
 
215210
215285
  // src/adapters/transport/http-server.ts
215211
215286
  var import_node_http = __toESM(require("node:http"));
215212
- var import_promises18 = __toESM(require("node:fs/promises"));
215287
+ var import_promises19 = __toESM(require("node:fs/promises"));
215213
215288
  var import_node_path6 = __toESM(require("node:path"));
215214
215289
  var import_node_os2 = __toESM(require("node:os"));
215215
215290
  var import_node_zlib = __toESM(require("node:zlib"));
215216
215291
  var import_node_fs = require("node:fs");
215217
- var import_promises19 = require("node:stream/promises");
215292
+ var import_promises20 = require("node:stream/promises");
215218
215293
 
215219
215294
  // node_modules/ws/wrapper.mjs
215220
215295
  var import_stream5 = __toESM(require_stream(), 1);
@@ -215423,7 +215498,7 @@ function getCacheControl2(filePath) {
215423
215498
  }
215424
215499
  async function fileExists(filePath) {
215425
215500
  try {
215426
- const stat5 = await import_promises18.default.stat(filePath);
215501
+ const stat5 = await import_promises19.default.stat(filePath);
215427
215502
  return stat5.isFile();
215428
215503
  } catch {
215429
215504
  return false;
@@ -215453,7 +215528,7 @@ async function sendStaticAsset(filePath, response, requestHeaders) {
215453
215528
  }
215454
215529
  response.writeHead(200, headers);
215455
215530
  try {
215456
- await (0, import_promises19.pipeline)((0, import_node_fs.createReadStream)(actualPath), response);
215531
+ await (0, import_promises20.pipeline)((0, import_node_fs.createReadStream)(actualPath), response);
215457
215532
  } catch (error48) {
215458
215533
  if (!response.headersSent) {
215459
215534
  response.writeHead(500);
@@ -215474,7 +215549,7 @@ async function serveStaticFile(urlPath, response, requestHeaders) {
215474
215549
  return;
215475
215550
  }
215476
215551
  try {
215477
- const stat5 = await import_promises18.default.stat(resolvedPath);
215552
+ const stat5 = await import_promises19.default.stat(resolvedPath);
215478
215553
  const filePath = stat5.isDirectory() ? import_node_path6.default.join(resolvedPath, "index.html") : resolvedPath;
215479
215554
  if (!await fileExists(filePath)) throw new Error("Not a file");
215480
215555
  await sendStaticAsset(filePath, response, requestHeaders);
@@ -215660,7 +215735,7 @@ var HttpTransportServer = class {
215660
215735
  return;
215661
215736
  }
215662
215737
  try {
215663
- await import_promises18.default.stat(resolvedPath);
215738
+ await import_promises19.default.stat(resolvedPath);
215664
215739
  const ext = import_node_path6.default.extname(resolvedPath).toLowerCase();
215665
215740
  const mimeType = getMimeType(ext);
215666
215741
  const headers = { "Content-Type": mimeType };
@@ -216100,14 +216175,14 @@ function registerUpdateHandlers() {
216100
216175
  }
216101
216176
 
216102
216177
  // src/adapters/storage/PinnedStore.ts
216103
- var import_path19 = require("path");
216104
- var import_promises20 = require("fs/promises");
216105
- var import_fs12 = require("fs");
216178
+ var import_path20 = require("path");
216179
+ var import_promises21 = require("fs/promises");
216180
+ var import_fs13 = require("fs");
216106
216181
  init_config();
216107
216182
  var FILE_NAME = "pinned.json";
216108
216183
  var SCHEMA_VERSION4 = 1;
216109
216184
  function getPinnedPath() {
216110
- return (0, import_path19.join)(config.getAppDataPath(), "config", FILE_NAME);
216185
+ return (0, import_path20.join)(config.getAppDataPath(), "config", FILE_NAME);
216111
216186
  }
216112
216187
  function createDefaultPinnedFile() {
216113
216188
  return { version: SCHEMA_VERSION4, agents: {}, groups: {} };
@@ -216141,18 +216216,18 @@ function clonePinnedFile(data2) {
216141
216216
  groups: { ...data2.groups }
216142
216217
  };
216143
216218
  }
216144
- async function atomicWriteJson4(path10, data2) {
216145
- const dir = (0, import_path19.dirname)(path10);
216146
- await (0, import_promises20.mkdir)(dir, { recursive: true });
216219
+ async function atomicWriteJson2(path10, data2) {
216220
+ const dir = (0, import_path20.dirname)(path10);
216221
+ await (0, import_promises21.mkdir)(dir, { recursive: true });
216147
216222
  const tmp = `${path10}.tmp`;
216148
- await (0, import_promises20.writeFile)(tmp, `${JSON.stringify(data2, null, 2)}
216223
+ await (0, import_promises21.writeFile)(tmp, `${JSON.stringify(data2, null, 2)}
216149
216224
  `, "utf-8");
216150
- await (0, import_promises20.rename)(tmp, path10);
216225
+ await (0, import_promises21.rename)(tmp, path10);
216151
216226
  }
216152
- async function readJsonFile5(path10) {
216153
- if (!(0, import_fs12.existsSync)(path10)) return null;
216227
+ async function readJsonFile4(path10) {
216228
+ if (!(0, import_fs13.existsSync)(path10)) return null;
216154
216229
  try {
216155
- const raw = await (0, import_promises20.readFile)(path10, "utf-8");
216230
+ const raw = await (0, import_promises21.readFile)(path10, "utf-8");
216156
216231
  return JSON.parse(raw);
216157
216232
  } catch {
216158
216233
  return null;
@@ -216162,13 +216237,13 @@ var PinnedStore = class {
216162
216237
  cache = null;
216163
216238
  async load() {
216164
216239
  if (this.cache) return this.cache;
216165
- const raw = await readJsonFile5(getPinnedPath());
216240
+ const raw = await readJsonFile4(getPinnedPath());
216166
216241
  this.cache = normalizePinnedFile(raw);
216167
216242
  return this.cache;
216168
216243
  }
216169
216244
  async flush() {
216170
216245
  if (!this.cache) return;
216171
- await atomicWriteJson4(getPinnedPath(), this.cache);
216246
+ await atomicWriteJson2(getPinnedPath(), this.cache);
216172
216247
  }
216173
216248
  async getAll() {
216174
216249
  const data2 = await this.load();
@@ -216300,6 +216375,7 @@ function registerChannelHandlers() {
216300
216375
  botId,
216301
216376
  secretRef: `channel:${connectionId}:secret`,
216302
216377
  target,
216378
+ createdAt: Date.now(),
216303
216379
  ...baseUrl ? { baseUrl } : {}
216304
216380
  };
216305
216381
  await channelManager.register(config3, secret);
@@ -216414,9 +216490,9 @@ function registerHandlers() {
216414
216490
  }
216415
216491
 
216416
216492
  // src/adapters/db/migration/kai-migration.ts
216417
- var import_path22 = require("path");
216418
- var import_fs15 = require("fs");
216419
- var import_promises23 = require("fs/promises");
216493
+ var import_path23 = require("path");
216494
+ var import_fs16 = require("fs");
216495
+ var import_promises24 = require("fs/promises");
216420
216496
  var import_lt2 = __toESM(require_lt());
216421
216497
  init_lib();
216422
216498
  init_agent_file_store();
@@ -216443,12 +216519,12 @@ function getKaiRootDir() {
216443
216519
  return config.getAppDataPath();
216444
216520
  }
216445
216521
  function getKaiConfigPath() {
216446
- return (0, import_path22.join)(getKaiRootDir(), KAI_CONFIG_FILE);
216522
+ return (0, import_path23.join)(getKaiRootDir(), KAI_CONFIG_FILE);
216447
216523
  }
216448
216524
  function ensureKaiRootDir() {
216449
216525
  const root2 = getKaiRootDir();
216450
- if (!(0, import_fs15.existsSync)(root2)) {
216451
- (0, import_fs15.mkdirSync)(root2, { recursive: true });
216526
+ if (!(0, import_fs16.existsSync)(root2)) {
216527
+ (0, import_fs16.mkdirSync)(root2, { recursive: true });
216452
216528
  }
216453
216529
  }
216454
216530
  function isVersionLessThan(current, target) {
@@ -216456,9 +216532,9 @@ function isVersionLessThan(current, target) {
216456
216532
  }
216457
216533
  function readKaiDataFile() {
216458
216534
  const path10 = getKaiConfigPath();
216459
- if (!(0, import_fs15.existsSync)(path10)) return null;
216535
+ if (!(0, import_fs16.existsSync)(path10)) return null;
216460
216536
  try {
216461
- return JSON.parse((0, import_fs15.readFileSync)(path10, "utf-8"));
216537
+ return JSON.parse((0, import_fs16.readFileSync)(path10, "utf-8"));
216462
216538
  } catch (error48) {
216463
216539
  logger35.error("Failed to read kai.json:", error48);
216464
216540
  return null;
@@ -216468,9 +216544,9 @@ async function writeKaiDataFile(version3) {
216468
216544
  ensureKaiRootDir();
216469
216545
  const path10 = getKaiConfigPath();
216470
216546
  const tmp = `${path10}.tmp`;
216471
- await (0, import_promises23.writeFile)(tmp, `${JSON.stringify({ version: version3 }, null, 2)}
216547
+ await (0, import_promises24.writeFile)(tmp, `${JSON.stringify({ version: version3 }, null, 2)}
216472
216548
  `, "utf-8");
216473
- await (0, import_promises23.rename)(tmp, path10);
216549
+ await (0, import_promises24.rename)(tmp, path10);
216474
216550
  }
216475
216551
  function currentVersion() {
216476
216552
  return readKaiDataFile()?.version ?? "0.0.0";
@@ -216647,18 +216723,18 @@ async function migrateConversationIds() {
216647
216723
  });
216648
216724
  await sequelize.query("PRAGMA foreign_keys = ON");
216649
216725
  }
216650
- const conversationsDir = (0, import_path22.resolve)(config.getAppDataPath(), "conversations");
216651
- if ((0, import_fs15.existsSync)(conversationsDir)) {
216726
+ const conversationsDir = (0, import_path23.resolve)(config.getAppDataPath(), "conversations");
216727
+ if ((0, import_fs16.existsSync)(conversationsDir)) {
216652
216728
  try {
216653
- const entries = (0, import_fs15.readdirSync)(conversationsDir, { withFileTypes: true });
216729
+ const entries = (0, import_fs16.readdirSync)(conversationsDir, { withFileTypes: true });
216654
216730
  for (const entry of entries) {
216655
216731
  if (!entry.isDirectory()) continue;
216656
- const oldDir = (0, import_path22.join)(conversationsDir, entry.name);
216732
+ const oldDir = (0, import_path23.join)(conversationsDir, entry.name);
216657
216733
  const targetId = idMap.get(entry.name);
216658
216734
  if (targetId) {
216659
- const newDir = (0, import_path22.join)(conversationsDir, targetId);
216660
- if (!(0, import_fs15.existsSync)(newDir)) {
216661
- (0, import_fs15.renameSync)(oldDir, newDir);
216735
+ const newDir = (0, import_path23.join)(conversationsDir, targetId);
216736
+ if (!(0, import_fs16.existsSync)(newDir)) {
216737
+ (0, import_fs16.renameSync)(oldDir, newDir);
216662
216738
  logger35.debug(`Renamed dir ${entry.name} \u2192 ${targetId}`);
216663
216739
  } else {
216664
216740
  logger35.debug(
@@ -216906,7 +216982,7 @@ init_normalize_tool_schema();
216906
216982
  var import_child_process3 = require("child_process");
216907
216983
  init_dist6();
216908
216984
  init_zod();
216909
- var import_path23 = require("path");
216985
+ var import_path24 = require("path");
216910
216986
  init_workspace();
216911
216987
 
216912
216988
  // node_modules/shell-env/index.js
@@ -217061,7 +217137,7 @@ function createShellTool(agentId) {
217061
217137
  };
217062
217138
  if (workdir) {
217063
217139
  const baseDir = agentId ? getAgentWorkspaceDir(agentId) : process.cwd();
217064
- options2.cwd = (0, import_path23.isAbsolute)(workdir) ? workdir : (0, import_path23.resolve)(baseDir, workdir);
217140
+ options2.cwd = (0, import_path24.isAbsolute)(workdir) ? workdir : (0, import_path24.resolve)(baseDir, workdir);
217065
217141
  } else if (agentId) {
217066
217142
  options2.cwd = getAgentWorkspaceDir(agentId);
217067
217143
  }
@@ -217186,11 +217262,11 @@ function spawnWithAbort(shell2, command, options2, timeoutMs, abortSignal) {
217186
217262
  // src/adapters/tools/filesystem/read-file.ts
217187
217263
  init_dist6();
217188
217264
  init_zod();
217189
- var import_promises24 = require("fs/promises");
217190
- var import_fs16 = require("fs");
217265
+ var import_promises25 = require("fs/promises");
217266
+ var import_fs17 = require("fs");
217191
217267
 
217192
217268
  // src/adapters/tools/filesystem/resolve-file-path.ts
217193
- var import_path24 = require("path");
217269
+ var import_path25 = require("path");
217194
217270
  init_workspace();
217195
217271
  init_group_file_store();
217196
217272
  var GROUP_PROTECTED_JSON_FILES = /* @__PURE__ */ new Set([
@@ -217199,34 +217275,34 @@ var GROUP_PROTECTED_JSON_FILES = /* @__PURE__ */ new Set([
217199
217275
  "members.json"
217200
217276
  ]);
217201
217277
  function containsPathTraversal(p) {
217202
- return (0, import_path24.normalize)(p).split(/[/\\]+/).some((part) => part === "..");
217278
+ return (0, import_path25.normalize)(p).split(/[/\\]+/).some((part) => part === "..");
217203
217279
  }
217204
217280
  function isWithinBase(resolvedPath, baseDir) {
217205
- const rel = (0, import_path24.relative)(baseDir, resolvedPath);
217206
- return !rel.startsWith("..") && !(0, import_path24.isAbsolute)(rel);
217281
+ const rel = (0, import_path25.relative)(baseDir, resolvedPath);
217282
+ return !rel.startsWith("..") && !(0, import_path25.isAbsolute)(rel);
217207
217283
  }
217208
217284
  function isGroupProtectedFile(resolvedPath, groupDir) {
217209
- if (!isWithinBase((0, import_path24.normalize)(resolvedPath), (0, import_path24.normalize)(groupDir))) {
217285
+ if (!isWithinBase((0, import_path25.normalize)(resolvedPath), (0, import_path25.normalize)(groupDir))) {
217210
217286
  return false;
217211
217287
  }
217212
- const name21 = (0, import_path24.basename)(resolvedPath);
217288
+ const name21 = (0, import_path25.basename)(resolvedPath);
217213
217289
  return name21.endsWith(".json") && GROUP_PROTECTED_JSON_FILES.has(name21);
217214
217290
  }
217215
217291
  function resolveToolFilePath(workdir, filePath) {
217216
- if (!workdir || !(0, import_path24.isAbsolute)(workdir)) {
217292
+ if (!workdir || !(0, import_path25.isAbsolute)(workdir)) {
217217
217293
  throw new Error("workdir is required and must be an absolute path");
217218
217294
  }
217219
217295
  if (!filePath) {
217220
217296
  throw new Error("path is required and must be relative to workdir");
217221
217297
  }
217222
- if ((0, import_path24.isAbsolute)(filePath)) {
217298
+ if ((0, import_path25.isAbsolute)(filePath)) {
217223
217299
  throw new Error("path must be relative to workdir, not absolute");
217224
217300
  }
217225
217301
  if (containsPathTraversal(filePath)) {
217226
217302
  throw new Error(`Path traversal not allowed: ${filePath}`);
217227
217303
  }
217228
- const normalizedWorkdir = (0, import_path24.normalize)(workdir);
217229
- const resolvedPath = (0, import_path24.resolve)(normalizedWorkdir, filePath);
217304
+ const normalizedWorkdir = (0, import_path25.normalize)(workdir);
217305
+ const resolvedPath = (0, import_path25.resolve)(normalizedWorkdir, filePath);
217230
217306
  if (!isWithinBase(resolvedPath, normalizedWorkdir)) {
217231
217307
  throw new Error(`Path escapes workdir: ${filePath}`);
217232
217308
  }
@@ -217303,13 +217379,13 @@ function createReadFileTool(_scope = {}, tracker) {
217303
217379
  if (abortSignal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
217304
217380
  try {
217305
217381
  const resolvedPath = resolveToolFilePath(workdir, filePath);
217306
- if (!(0, import_fs16.existsSync)(resolvedPath)) {
217382
+ if (!(0, import_fs17.existsSync)(resolvedPath)) {
217307
217383
  return { error: `Path does not exist: ${filePath}`, content: "" };
217308
217384
  }
217309
- const fileStat = await (0, import_promises24.stat)(resolvedPath);
217385
+ const fileStat = await (0, import_promises25.stat)(resolvedPath);
217310
217386
  if (fileStat.isDirectory()) {
217311
217387
  tracker?.markKnown(resolvedPath);
217312
- const entries = await (0, import_promises24.readdir)(resolvedPath, { withFileTypes: true });
217388
+ const entries = await (0, import_promises25.readdir)(resolvedPath, { withFileTypes: true });
217313
217389
  const lines = entries.sort((a, b) => {
217314
217390
  if (a.isDirectory() && !b.isDirectory()) return -1;
217315
217391
  if (!a.isDirectory() && b.isDirectory()) return 1;
@@ -217332,7 +217408,7 @@ function createReadFileTool(_scope = {}, tracker) {
217332
217408
  content: ""
217333
217409
  };
217334
217410
  }
217335
- const content = await (0, import_promises24.readFile)(resolvedPath, "utf-8");
217411
+ const content = await (0, import_promises25.readFile)(resolvedPath, "utf-8");
217336
217412
  const allLines = content.split("\n");
217337
217413
  if (allLines.length > 0 && allLines[allLines.length - 1] === "") {
217338
217414
  allLines.pop();
@@ -217366,9 +217442,9 @@ function createReadFileTool(_scope = {}, tracker) {
217366
217442
  // src/adapters/tools/filesystem/write-file.ts
217367
217443
  init_dist6();
217368
217444
  init_zod();
217369
- var import_promises25 = require("fs/promises");
217370
- var import_path25 = require("path");
217371
- var import_fs17 = require("fs");
217445
+ var import_promises26 = require("fs/promises");
217446
+ var import_path26 = require("path");
217447
+ var import_fs18 = require("fs");
217372
217448
  init_group_file_store();
217373
217449
 
217374
217450
  // node_modules/diff/libesm/diff/base.js
@@ -218163,7 +218239,7 @@ function createWriteFileTool(scope = {}, tracker) {
218163
218239
  };
218164
218240
  }
218165
218241
  }
218166
- const isNewFile = !(0, import_fs17.existsSync)(resolvedPath);
218242
+ const isNewFile = !(0, import_fs18.existsSync)(resolvedPath);
218167
218243
  if (mode === "overwrite" && !isNewFile && tracker && !tracker.isKnown(resolvedPath)) {
218168
218244
  return {
218169
218245
  success: false,
@@ -218173,17 +218249,17 @@ function createWriteFileTool(scope = {}, tracker) {
218173
218249
  let oldContent = "";
218174
218250
  if (!isNewFile) {
218175
218251
  try {
218176
- oldContent = await (0, import_promises25.readFile)(resolvedPath, "utf-8");
218252
+ oldContent = await (0, import_promises26.readFile)(resolvedPath, "utf-8");
218177
218253
  } catch {
218178
218254
  }
218179
218255
  }
218180
218256
  const nextContent = mode === "append" ? oldContent + content : content;
218181
218257
  const diff = createUnifiedFileDiff(filePath, oldContent, nextContent);
218182
- await (0, import_promises25.mkdir)((0, import_path25.dirname)(resolvedPath), { recursive: true });
218258
+ await (0, import_promises26.mkdir)((0, import_path26.dirname)(resolvedPath), { recursive: true });
218183
218259
  if (mode === "append") {
218184
- await (0, import_promises25.appendFile)(resolvedPath, content, "utf-8");
218260
+ await (0, import_promises26.appendFile)(resolvedPath, content, "utf-8");
218185
218261
  } else {
218186
- await (0, import_promises25.writeFile)(resolvedPath, content, "utf-8");
218262
+ await (0, import_promises26.writeFile)(resolvedPath, content, "utf-8");
218187
218263
  }
218188
218264
  if (isNewFile) {
218189
218265
  tracker?.markKnown(resolvedPath);
@@ -218210,8 +218286,8 @@ function createWriteFileTool(scope = {}, tracker) {
218210
218286
  // src/adapters/tools/filesystem/edit-file.ts
218211
218287
  init_dist6();
218212
218288
  init_zod();
218213
- var import_promises26 = require("fs/promises");
218214
- var import_fs18 = require("fs");
218289
+ var import_promises27 = require("fs/promises");
218290
+ var import_fs19 = require("fs");
218215
218291
  init_group_file_store();
218216
218292
  function createEditFileTool(scope = {}, tracker) {
218217
218293
  return {
@@ -218239,14 +218315,14 @@ function createEditFileTool(scope = {}, tracker) {
218239
218315
  };
218240
218316
  }
218241
218317
  }
218242
- if (!(0, import_fs18.existsSync)(resolvedPath)) {
218318
+ if (!(0, import_fs19.existsSync)(resolvedPath)) {
218243
218319
  return { success: false, error: `File does not exist: ${filePath}` };
218244
218320
  }
218245
218321
  const accessError = tracker?.assertKnownForMutation(resolvedPath, "edit", "editFile", filePath);
218246
218322
  if (accessError) {
218247
218323
  return { success: false, error: accessError };
218248
218324
  }
218249
- const content = await (0, import_promises26.readFile)(resolvedPath, "utf-8");
218325
+ const content = await (0, import_promises27.readFile)(resolvedPath, "utf-8");
218250
218326
  const matchCount = content.split(oldString).length - 1;
218251
218327
  if (matchCount === 0) {
218252
218328
  return { success: false, error: "oldString not found in file" };
@@ -218259,7 +218335,7 @@ function createEditFileTool(scope = {}, tracker) {
218259
218335
  }
218260
218336
  const updatedContent = replaceAll ? content.split(oldString).join(newString) : content.replace(oldString, newString);
218261
218337
  const diff = createUnifiedFileDiff(filePath, content, updatedContent);
218262
- await (0, import_promises26.writeFile)(resolvedPath, updatedContent, "utf-8");
218338
+ await (0, import_promises27.writeFile)(resolvedPath, updatedContent, "utf-8");
218263
218339
  tracker?.markKnown(resolvedPath);
218264
218340
  return {
218265
218341
  success: true,
@@ -218281,42 +218357,42 @@ function createEditFileTool(scope = {}, tracker) {
218281
218357
  // src/adapters/tools/filesystem/apply-patch.ts
218282
218358
  init_dist6();
218283
218359
  init_zod();
218284
- var import_promises27 = require("fs/promises");
218285
- var import_fs19 = require("fs");
218286
- var import_path26 = require("path");
218360
+ var import_promises28 = require("fs/promises");
218361
+ var import_fs20 = require("fs");
218362
+ var import_path27 = require("path");
218287
218363
  init_group_file_store();
218288
218364
  function containsPathTraversal2(p) {
218289
- return (0, import_path26.normalize)(p).split(/[/\\]+/).some((part) => part === "..");
218365
+ return (0, import_path27.normalize)(p).split(/[/\\]+/).some((part) => part === "..");
218290
218366
  }
218291
218367
  function isWithinBase2(resolvedPath, baseDir) {
218292
- const rel = (0, import_path26.relative)(baseDir, resolvedPath);
218293
- return !rel.startsWith("..") && !(0, import_path26.isAbsolute)(rel);
218368
+ const rel = (0, import_path27.relative)(baseDir, resolvedPath);
218369
+ return !rel.startsWith("..") && !(0, import_path27.isAbsolute)(rel);
218294
218370
  }
218295
218371
  function resolvePatchWorkdir(workdir) {
218296
218372
  if (typeof workdir !== "string" || workdir.length === 0) {
218297
218373
  throw new Error("patch workdir is required and must be an absolute path");
218298
218374
  }
218299
- if (!(0, import_path26.isAbsolute)(workdir)) {
218375
+ if (!(0, import_path27.isAbsolute)(workdir)) {
218300
218376
  throw new Error("patch workdir must be an absolute path");
218301
218377
  }
218302
- return (0, import_path26.normalize)(workdir);
218378
+ return (0, import_path27.normalize)(workdir);
218303
218379
  }
218304
218380
  function resolvePatchPath(filePath, workdir) {
218305
- if ((0, import_path26.isAbsolute)(filePath)) {
218381
+ if ((0, import_path27.isAbsolute)(filePath)) {
218306
218382
  throw new Error(`Patch file paths must be relative to workdir; pass workdir instead of absolute paths: ${filePath}`);
218307
218383
  }
218308
218384
  if (containsPathTraversal2(filePath)) {
218309
218385
  throw new Error(`Path traversal not allowed in patch file path: ${filePath}`);
218310
218386
  }
218311
- const resolved = (0, import_path26.resolve)(workdir, filePath);
218387
+ const resolved = (0, import_path27.resolve)(workdir, filePath);
218312
218388
  if (!isWithinBase2(resolved, workdir)) {
218313
218389
  throw new Error(`Patch file path escapes workdir: ${filePath}`);
218314
218390
  }
218315
218391
  return resolved;
218316
218392
  }
218317
218393
  function getPatchMutationAccessError(filePatch, resolvedPath, displayPath, tracker) {
218318
- if (filePatch.action === "add" && !(0, import_fs19.existsSync)(resolvedPath)) return null;
218319
- if (filePatch.action !== "add" && !(0, import_fs19.existsSync)(resolvedPath)) return null;
218394
+ if (filePatch.action === "add" && !(0, import_fs20.existsSync)(resolvedPath)) return null;
218395
+ if (filePatch.action !== "add" && !(0, import_fs20.existsSync)(resolvedPath)) return null;
218320
218396
  if (filePatch.action === "add") {
218321
218397
  return tracker.assertKnownForMutation(resolvedPath, "replace", "applyPatch", displayPath);
218322
218398
  }
@@ -218488,7 +218564,7 @@ function createApplyPatchTool(scope = {}, tracker) {
218488
218564
  try {
218489
218565
  switch (filePatch.action) {
218490
218566
  case "add": {
218491
- if ((0, import_fs19.existsSync)(resolvedPath)) {
218567
+ if ((0, import_fs20.existsSync)(resolvedPath)) {
218492
218568
  results.push({
218493
218569
  action: "add",
218494
218570
  path: filePatch.path,
@@ -218498,8 +218574,8 @@ function createApplyPatchTool(scope = {}, tracker) {
218498
218574
  continue;
218499
218575
  }
218500
218576
  const content = (filePatch.content || "").replace(/\n$/, "");
218501
- await (0, import_promises27.mkdir)((0, import_path26.dirname)(resolvedPath), { recursive: true });
218502
- await (0, import_promises27.writeFile)(resolvedPath, content, "utf-8");
218577
+ await (0, import_promises28.mkdir)((0, import_path27.dirname)(resolvedPath), { recursive: true });
218578
+ await (0, import_promises28.writeFile)(resolvedPath, content, "utf-8");
218503
218579
  tracker?.markKnown(resolvedPath);
218504
218580
  results.push({
218505
218581
  action: "add",
@@ -218509,7 +218585,7 @@ function createApplyPatchTool(scope = {}, tracker) {
218509
218585
  break;
218510
218586
  }
218511
218587
  case "update": {
218512
- if (!(0, import_fs19.existsSync)(resolvedPath)) {
218588
+ if (!(0, import_fs20.existsSync)(resolvedPath)) {
218513
218589
  results.push({
218514
218590
  action: "update",
218515
218591
  path: filePatch.path,
@@ -218518,7 +218594,7 @@ function createApplyPatchTool(scope = {}, tracker) {
218518
218594
  });
218519
218595
  continue;
218520
218596
  }
218521
- const oldContent = await (0, import_promises27.readFile)(resolvedPath, "utf-8");
218597
+ const oldContent = await (0, import_promises28.readFile)(resolvedPath, "utf-8");
218522
218598
  let newContent;
218523
218599
  if (filePatch.hunks && filePatch.hunks.length > 0) {
218524
218600
  const { result, error: error48 } = applyHunks(oldContent, filePatch.path, filePatch.hunks);
@@ -218558,14 +218634,14 @@ function createApplyPatchTool(scope = {}, tracker) {
218558
218634
  continue;
218559
218635
  }
218560
218636
  }
218561
- await (0, import_promises27.mkdir)((0, import_path26.dirname)(newResolvedPath), { recursive: true });
218637
+ await (0, import_promises28.mkdir)((0, import_path27.dirname)(newResolvedPath), { recursive: true });
218562
218638
  const moveTargetError = tracker?.assertKnownForMutation(
218563
218639
  newResolvedPath,
218564
218640
  "overwrite rename target",
218565
218641
  "applyPatch",
218566
218642
  filePatch.moveTo
218567
218643
  );
218568
- if ((0, import_fs19.existsSync)(newResolvedPath) && moveTargetError) {
218644
+ if ((0, import_fs20.existsSync)(newResolvedPath) && moveTargetError) {
218569
218645
  results.push({
218570
218646
  action: "rename",
218571
218647
  path: `${filePatch.path} \u2192 ${filePatch.moveTo}`,
@@ -218574,8 +218650,8 @@ function createApplyPatchTool(scope = {}, tracker) {
218574
218650
  });
218575
218651
  continue;
218576
218652
  }
218577
- await (0, import_promises27.writeFile)(newResolvedPath, newContent, "utf-8");
218578
- await (0, import_promises27.unlink)(resolvedPath);
218653
+ await (0, import_promises28.writeFile)(newResolvedPath, newContent, "utf-8");
218654
+ await (0, import_promises28.unlink)(resolvedPath);
218579
218655
  tracker?.markKnown(newResolvedPath);
218580
218656
  const diff = createUnifiedFileDiff(filePatch.path, oldContent, newContent);
218581
218657
  results.push({
@@ -218586,7 +218662,7 @@ function createApplyPatchTool(scope = {}, tracker) {
218586
218662
  });
218587
218663
  } else {
218588
218664
  const diff = createUnifiedFileDiff(filePatch.path, oldContent, newContent);
218589
- await (0, import_promises27.writeFile)(resolvedPath, newContent, "utf-8");
218665
+ await (0, import_promises28.writeFile)(resolvedPath, newContent, "utf-8");
218590
218666
  tracker?.markKnown(resolvedPath);
218591
218667
  results.push({
218592
218668
  action: "update",
@@ -218598,7 +218674,7 @@ function createApplyPatchTool(scope = {}, tracker) {
218598
218674
  break;
218599
218675
  }
218600
218676
  case "delete": {
218601
- if (!(0, import_fs19.existsSync)(resolvedPath)) {
218677
+ if (!(0, import_fs20.existsSync)(resolvedPath)) {
218602
218678
  results.push({
218603
218679
  action: "delete",
218604
218680
  path: filePatch.path,
@@ -218607,7 +218683,7 @@ function createApplyPatchTool(scope = {}, tracker) {
218607
218683
  });
218608
218684
  continue;
218609
218685
  }
218610
- await (0, import_promises27.unlink)(resolvedPath);
218686
+ await (0, import_promises28.unlink)(resolvedPath);
218611
218687
  results.push({
218612
218688
  action: "delete",
218613
218689
  path: filePatch.path,
@@ -233315,12 +233391,12 @@ function createWebSearchTool(executor) {
233315
233391
  }
233316
233392
 
233317
233393
  // src/electron/main/utils/icon.ts
233318
- var import_path27 = require("path");
233394
+ var import_path28 = require("path");
233319
233395
  function getIconPath() {
233320
233396
  if (process.env.NODE_ENV === "development") {
233321
- return (0, import_path27.join)(__dirname, "../../resources/icon.png");
233397
+ return (0, import_path28.join)(__dirname, "../../resources/icon.png");
233322
233398
  }
233323
- return (0, import_path27.join)(process.resourcesPath, "icon.png");
233399
+ return (0, import_path28.join)(process.resourcesPath, "icon.png");
233324
233400
  }
233325
233401
 
233326
233402
  // src/adapters/tools/web/search/electron/search-with-window.ts
@@ -233764,16 +233840,16 @@ function createSchedulerTools(scope) {
233764
233840
  // src/adapters/tools/image/analyze.ts
233765
233841
  init_dist6();
233766
233842
  init_zod();
233767
- var import_promises28 = require("fs/promises");
233768
- var import_fs20 = require("fs");
233769
- var import_path28 = require("path");
233843
+ var import_promises29 = require("fs/promises");
233844
+ var import_fs21 = require("fs");
233845
+ var import_path29 = require("path");
233770
233846
  init_config();
233771
233847
  init_multimodal();
233772
233848
  init_logger();
233773
233849
  var logger37 = createLogger("AnalyzeImageTool");
233774
233850
  function resolveImagePath(imagePath) {
233775
- if ((0, import_path28.isAbsolute)(imagePath)) return imagePath;
233776
- return (0, import_path28.resolve)(process.cwd(), imagePath);
233851
+ if ((0, import_path29.isAbsolute)(imagePath)) return imagePath;
233852
+ return (0, import_path29.resolve)(process.cwd(), imagePath);
233777
233853
  }
233778
233854
  function createModelFromCandidate(candidate) {
233779
233855
  const channels = config.get("llmChannels") ?? [];
@@ -233823,9 +233899,9 @@ async function loadImageAsDataUrl(imagePathOrUrl, abortSignal) {
233823
233899
  buffer = Buffer.from(await response.arrayBuffer());
233824
233900
  } else {
233825
233901
  const absPath = resolveImagePath(imagePathOrUrl);
233826
- if (!(0, import_fs20.existsSync)(absPath)) throw new Error(`\u56FE\u7247\u6587\u4EF6\u4E0D\u5B58\u5728: ${absPath}`);
233827
- buffer = await (0, import_promises28.readFile)(absPath);
233828
- mimeType = extToMime((0, import_path28.extname)(absPath));
233902
+ if (!(0, import_fs21.existsSync)(absPath)) throw new Error(`\u56FE\u7247\u6587\u4EF6\u4E0D\u5B58\u5728: ${absPath}`);
233903
+ buffer = await (0, import_promises29.readFile)(absPath);
233904
+ mimeType = extToMime((0, import_path29.extname)(absPath));
233829
233905
  }
233830
233906
  const maxDim = getMaxImageDimension();
233831
233907
  const resized = await resizeImageBuffer(buffer, maxDim);
@@ -233892,9 +233968,9 @@ function createAnalyzeImageTool() {
233892
233968
  // src/adapters/tools/image/generate.ts
233893
233969
  init_dist6();
233894
233970
  init_zod();
233895
- var import_promises29 = require("fs/promises");
233896
- var import_fs21 = require("fs");
233897
- var import_path29 = require("path");
233971
+ var import_promises30 = require("fs/promises");
233972
+ var import_fs22 = require("fs");
233973
+ var import_path30 = require("path");
233898
233974
  init_config();
233899
233975
  init_logger();
233900
233976
  var logger38 = createLogger("GenerateImageTool");
@@ -233931,9 +234007,9 @@ async function loadImageBuffer(imagePathOrUrl, abortSignal) {
233931
234007
  if (!response.ok) throw new Error(`\u83B7\u53D6\u56FE\u7247\u5931\u8D25: ${response.status} ${response.statusText}`);
233932
234008
  return Buffer.from(await response.arrayBuffer());
233933
234009
  }
233934
- const absPath = (0, import_path29.isAbsolute)(imagePathOrUrl) ? imagePathOrUrl : (0, import_path29.resolve)(process.cwd(), imagePathOrUrl);
233935
- if (!(0, import_fs21.existsSync)(absPath)) throw new Error(`\u56FE\u7247\u6587\u4EF6\u4E0D\u5B58\u5728: ${absPath}`);
233936
- return (0, import_promises29.readFile)(absPath);
234010
+ const absPath = (0, import_path30.isAbsolute)(imagePathOrUrl) ? imagePathOrUrl : (0, import_path30.resolve)(process.cwd(), imagePathOrUrl);
234011
+ if (!(0, import_fs22.existsSync)(absPath)) throw new Error(`\u56FE\u7247\u6587\u4EF6\u4E0D\u5B58\u5728: ${absPath}`);
234012
+ return (0, import_promises30.readFile)(absPath);
233937
234013
  }
233938
234014
  function createGenerateImageTool() {
233939
234015
  return {
@@ -234375,8 +234451,8 @@ var ToolOutputArtifactStateSlot = defineExecutionSlot({
234375
234451
  });
234376
234452
 
234377
234453
  // src/adapters/tools/middleware/save-tool-output-artifact.ts
234378
- var import_promises30 = require("fs/promises");
234379
- var import_path30 = require("path");
234454
+ var import_promises31 = require("fs/promises");
234455
+ var import_path31 = require("path");
234380
234456
  init_workspace();
234381
234457
  init_thread_file_store();
234382
234458
 
@@ -234648,11 +234724,11 @@ async function saveArtifact(ctx, filename, text4) {
234648
234724
  const resultsRoot = resolveToolResultsRoot(ctx);
234649
234725
  const now2 = ctx.runtime.now();
234650
234726
  const today = now2.toISOString().split("T")[0];
234651
- const dir = (0, import_path30.join)(resultsRoot, today);
234652
- await (0, import_promises30.mkdir)(dir, { recursive: true });
234653
- const absolutePath = (0, import_path30.join)(dir, filename);
234727
+ const dir = (0, import_path31.join)(resultsRoot, today);
234728
+ await (0, import_promises31.mkdir)(dir, { recursive: true });
234729
+ const absolutePath = (0, import_path31.join)(dir, filename);
234654
234730
  const content = limitArtifactBytes(text4);
234655
- await (0, import_promises30.writeFile)(absolutePath, content, "utf-8");
234731
+ await (0, import_promises31.writeFile)(absolutePath, content, "utf-8");
234656
234732
  return {
234657
234733
  absolutePath,
234658
234734
  relativePath: `tool_results/${today}/${filename}`,
@@ -234663,9 +234739,9 @@ async function saveArtifact(ctx, filename, text4) {
234663
234739
  }
234664
234740
  function resolveToolResultsRoot(ctx) {
234665
234741
  if (ctx.groupId && ctx.threadId) {
234666
- return (0, import_path30.join)(getThreadDir(ctx.groupId, ctx.threadId), "tool_results");
234742
+ return (0, import_path31.join)(getThreadDir(ctx.groupId, ctx.threadId), "tool_results");
234667
234743
  }
234668
- return (0, import_path30.join)(getAgentWorkspaceDir(ctx.agentId), "tool_results");
234744
+ return (0, import_path31.join)(getAgentWorkspaceDir(ctx.agentId), "tool_results");
234669
234745
  }
234670
234746
  function recordArtifact(ctx, stream, artifact) {
234671
234747
  const state = ctx.runtime.runState.getOrCreate(ToolOutputArtifactStateSlot, () => ({ artifacts: [] }));