clawmini 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gemini/settings.json +46 -0
- package/.prettierrc +7 -0
- package/GEMINI.md +11 -0
- package/README.md +137 -0
- package/dist/adapter-discord/index.d.mts +5 -0
- package/dist/adapter-discord/index.d.mts.map +1 -0
- package/dist/adapter-discord/index.mjs +456 -0
- package/dist/adapter-discord/index.mjs.map +1 -0
- package/dist/chats-DKgTeU7i.mjs +91 -0
- package/dist/chats-DKgTeU7i.mjs.map +1 -0
- package/dist/chats-Zd_HXDHx.mjs +29 -0
- package/dist/chats-Zd_HXDHx.mjs.map +1 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +850 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/cli/lite.d.mts +1 -0
- package/dist/cli/lite.mjs +4434 -0
- package/dist/cli/lite.mjs.map +1 -0
- package/dist/daemon/index.d.mts +5 -0
- package/dist/daemon/index.d.mts.map +1 -0
- package/dist/daemon/index.mjs +1222 -0
- package/dist/daemon/index.mjs.map +1 -0
- package/dist/fetch-BjZVyU3Z.mjs +37 -0
- package/dist/fetch-BjZVyU3Z.mjs.map +1 -0
- package/dist/fs-B5wW0oaH.mjs +14 -0
- package/dist/fs-B5wW0oaH.mjs.map +1 -0
- package/dist/lite-Dl7WXyaH.mjs +80 -0
- package/dist/lite-Dl7WXyaH.mjs.map +1 -0
- package/dist/rolldown-runtime-95iHPtFO.mjs +18 -0
- package/dist/web/_app/env.js +1 -0
- package/dist/web/_app/immutable/assets/0.GI4C4dpV.css +1 -0
- package/dist/web/_app/immutable/chunks/B5abRDXp.js +1 -0
- package/dist/web/_app/immutable/chunks/B8yYFADm.js +1 -0
- package/dist/web/_app/immutable/chunks/BPy8HLo7.js +5 -0
- package/dist/web/_app/immutable/chunks/Bi0jeV7Q.js +1 -0
- package/dist/web/_app/immutable/chunks/BmUXQ3wy.js +2 -0
- package/dist/web/_app/immutable/chunks/C3k55nDF.js +1 -0
- package/dist/web/_app/immutable/chunks/COekwvP2.js +1 -0
- package/dist/web/_app/immutable/chunks/CSvS_NwK.js +1 -0
- package/dist/web/_app/immutable/chunks/CpaGRn9L.js +1 -0
- package/dist/web/_app/immutable/chunks/CyNaE55B.js +1 -0
- package/dist/web/_app/immutable/chunks/DG5RZBw-.js +2 -0
- package/dist/web/_app/immutable/chunks/Dc-UOHw9.js +1 -0
- package/dist/web/_app/immutable/chunks/DcrmIfTj.js +1 -0
- package/dist/web/_app/immutable/chunks/ZkLyk0mE.js +1 -0
- package/dist/web/_app/immutable/entry/app.B-vZe7PN.js +2 -0
- package/dist/web/_app/immutable/entry/start.oP1AgKhs.js +1 -0
- package/dist/web/_app/immutable/nodes/0.B5WFN0zw.js +1 -0
- package/dist/web/_app/immutable/nodes/1.D1wtJb2k.js +1 -0
- package/dist/web/_app/immutable/nodes/2.CK3CLC0f.js +1 -0
- package/dist/web/_app/immutable/nodes/3.BB5wCoBf.js +4 -0
- package/dist/web/_app/immutable/nodes/4.Dr2jvAXK.js +1 -0
- package/dist/web/_app/immutable/nodes/5.BJl7oM3b.js +1 -0
- package/dist/web/_app/version.json +1 -0
- package/dist/web/index.html +37 -0
- package/dist/web/robots.txt +3 -0
- package/dist/workspace-CSgfo_2J.mjs +383 -0
- package/dist/workspace-CSgfo_2J.mjs.map +1 -0
- package/docs/01_chats/development_log.md +36 -0
- package/docs/01_chats/notes.md +27 -0
- package/docs/01_chats/prd.md +47 -0
- package/docs/01_chats/questions.md +19 -0
- package/docs/01_chats/tickets.md +67 -0
- package/docs/02_sessions/development_log.md +79 -0
- package/docs/02_sessions/notes.md +40 -0
- package/docs/02_sessions/prd.md +75 -0
- package/docs/02_sessions/questions.md +7 -0
- package/docs/02_sessions/tickets.md +68 -0
- package/docs/03_web_interface/development_log.md +60 -0
- package/docs/03_web_interface/notes.md +29 -0
- package/docs/03_web_interface/prd.md +42 -0
- package/docs/03_web_interface/questions.md +8 -0
- package/docs/03_web_interface/tickets.md +59 -0
- package/docs/04_agents/development_log.md +54 -0
- package/docs/04_agents/notes.md +45 -0
- package/docs/04_agents/prd.md +47 -0
- package/docs/04_agents/questions.md +13 -0
- package/docs/04_agents/tickets.md +107 -0
- package/docs/05_routers/development_log.md +13 -0
- package/docs/05_routers/notes.md +40 -0
- package/docs/05_routers/prd.md +55 -0
- package/docs/05_routers/questions.md +21 -0
- package/docs/05_routers/tickets.md +109 -0
- package/docs/06_agent_templates/development_log.md +38 -0
- package/docs/06_agent_templates/notes.md +25 -0
- package/docs/06_agent_templates/prd.md +34 -0
- package/docs/06_agent_templates/questions.md +11 -0
- package/docs/06_agent_templates/tickets.md +49 -0
- package/docs/06_cron/development_log.md +51 -0
- package/docs/06_cron/notes.md +14 -0
- package/docs/06_cron/prd.md +92 -0
- package/docs/06_cron/questions.md +15 -0
- package/docs/06_cron/tickets.md +75 -0
- package/docs/07_web_chat_ux/development_log.md +30 -0
- package/docs/07_web_chat_ux/notes.md +25 -0
- package/docs/07_web_chat_ux/prd.md +46 -0
- package/docs/07_web_chat_ux/questions.md +7 -0
- package/docs/07_web_chat_ux/tickets.md +48 -0
- package/docs/08_agent_api/development_log.md +52 -0
- package/docs/08_agent_api/notes.md +31 -0
- package/docs/08_agent_api/prd.md +56 -0
- package/docs/08_agent_api/questions.md +14 -0
- package/docs/08_agent_api/tickets.md +104 -0
- package/docs/09_agent_fallbacks/development_log.md +52 -0
- package/docs/09_agent_fallbacks/notes.md +40 -0
- package/docs/09_agent_fallbacks/prd.md +55 -0
- package/docs/09_agent_fallbacks/questions.md +10 -0
- package/docs/09_agent_fallbacks/tickets.md +88 -0
- package/docs/09_discord_adapter/development_log.md +95 -0
- package/docs/09_discord_adapter/notes.md +18 -0
- package/docs/09_discord_adapter/prd.md +57 -0
- package/docs/09_discord_adapter/questions.md +16 -0
- package/docs/09_discord_adapter/tickets.md +116 -0
- package/docs/10_file_attachments/development_log.md +55 -0
- package/docs/10_file_attachments/notes.md +59 -0
- package/docs/10_file_attachments/prd.md +73 -0
- package/docs/10_file_attachments/questions.md +15 -0
- package/docs/10_file_attachments/tickets.md +88 -0
- package/docs/11_message_verbosity/development_log.md +43 -0
- package/docs/11_message_verbosity/notes.md +26 -0
- package/docs/11_message_verbosity/prd.md +44 -0
- package/docs/11_message_verbosity/questions.md +8 -0
- package/docs/11_message_verbosity/tickets.md +33 -0
- package/docs/12_environments/development_log.md +43 -0
- package/docs/12_environments/notes.md +45 -0
- package/docs/12_environments/prd.md +113 -0
- package/docs/12_environments/questions.md +17 -0
- package/docs/12_environments/tickets.md +87 -0
- package/docs/12_setup_flow_improvements/development_log.md +40 -0
- package/docs/12_setup_flow_improvements/notes.md +34 -0
- package/docs/12_setup_flow_improvements/prd.md +35 -0
- package/docs/12_setup_flow_improvements/questions.md +8 -0
- package/docs/12_setup_flow_improvements/tickets.md +122 -0
- package/docs/13_discord_typing_indicators/development_log.md +38 -0
- package/docs/13_discord_typing_indicators/notes.md +18 -0
- package/docs/13_discord_typing_indicators/prd.md +41 -0
- package/docs/13_discord_typing_indicators/questions.md +6 -0
- package/docs/13_discord_typing_indicators/tickets.md +60 -0
- package/docs/14_interruptions/development_log.md +50 -0
- package/docs/14_interruptions/notes.md +38 -0
- package/docs/14_interruptions/prd.md +46 -0
- package/docs/14_interruptions/questions.md +12 -0
- package/docs/14_interruptions/tickets.md +69 -0
- package/docs/15_sandbox_policies/development_log.md +95 -0
- package/docs/15_sandbox_policies/notes.md +33 -0
- package/docs/15_sandbox_policies/prd.md +163 -0
- package/docs/15_sandbox_policies/questions.md +10 -0
- package/docs/15_sandbox_policies/tickets.md +196 -0
- package/docs/CHECKS.md +9 -0
- package/docs/guides/discord_adapter_setup.md +69 -0
- package/docs/guides/sandbox_policies.md +76 -0
- package/eslint.config.js +47 -0
- package/napkin.md +21 -0
- package/package.json +50 -0
- package/scripts/create_worktree.sh +49 -0
- package/scripts/get_pr_comments.sh +36 -0
- package/src/adapter-discord/client.test.ts +65 -0
- package/src/adapter-discord/client.ts +41 -0
- package/src/adapter-discord/config.test.ts +156 -0
- package/src/adapter-discord/config.ts +61 -0
- package/src/adapter-discord/forwarder.test.ts +493 -0
- package/src/adapter-discord/forwarder.ts +246 -0
- package/src/adapter-discord/index.test.ts +399 -0
- package/src/adapter-discord/index.ts +147 -0
- package/src/adapter-discord/state.test.ts +65 -0
- package/src/adapter-discord/state.ts +44 -0
- package/src/cli/client.ts +46 -0
- package/src/cli/commands/agents.ts +138 -0
- package/src/cli/commands/chats.ts +79 -0
- package/src/cli/commands/down.ts +32 -0
- package/src/cli/commands/environments.ts +39 -0
- package/src/cli/commands/export-lite.ts +62 -0
- package/src/cli/commands/init.ts +79 -0
- package/src/cli/commands/jobs.ts +141 -0
- package/src/cli/commands/messages.ts +103 -0
- package/src/cli/commands/up.ts +26 -0
- package/src/cli/commands/web-api/agents.ts +138 -0
- package/src/cli/commands/web-api/chats.ts +213 -0
- package/src/cli/commands/web-api/utils.ts +27 -0
- package/src/cli/commands/web.ts +105 -0
- package/src/cli/e2e/adapter-discord.test.ts +76 -0
- package/src/cli/e2e/agents.test.ts +140 -0
- package/src/cli/e2e/basic.test.ts +43 -0
- package/src/cli/e2e/cron.test.ts +132 -0
- package/src/cli/e2e/daemon.test.ts +293 -0
- package/src/cli/e2e/environments.test.ts +66 -0
- package/src/cli/e2e/export-lite-func.test.ts +155 -0
- package/src/cli/e2e/export-lite.test.ts +51 -0
- package/src/cli/e2e/fallbacks.test.ts +169 -0
- package/src/cli/e2e/global-setup.ts +15 -0
- package/src/cli/e2e/init.test.ts +70 -0
- package/src/cli/e2e/messages.test.ts +294 -0
- package/src/cli/e2e/requests.test.ts +165 -0
- package/src/cli/e2e/utils.ts +66 -0
- package/src/cli/index.test.ts +7 -0
- package/src/cli/index.ts +29 -0
- package/src/cli/lite.ts +247 -0
- package/src/cli/utils.ts +4 -0
- package/src/daemon/auth.test.ts +50 -0
- package/src/daemon/auth.ts +69 -0
- package/src/daemon/chats.ts +26 -0
- package/src/daemon/cron.test.ts +28 -0
- package/src/daemon/cron.ts +159 -0
- package/src/daemon/events.ts +15 -0
- package/src/daemon/index.ts +212 -0
- package/src/daemon/message-agent.test.ts +132 -0
- package/src/daemon/message-extraction.test.ts +166 -0
- package/src/daemon/message-fallbacks.test.ts +313 -0
- package/src/daemon/message-interruption.test.ts +125 -0
- package/src/daemon/message-queue.test.ts +143 -0
- package/src/daemon/message-router.test.ts +106 -0
- package/src/daemon/message-session.test.ts +127 -0
- package/src/daemon/message-test-utils.ts +41 -0
- package/src/daemon/message-typing.test.ts +93 -0
- package/src/daemon/message-verbosity.test.ts +127 -0
- package/src/daemon/message.ts +600 -0
- package/src/daemon/observation.test.ts +118 -0
- package/src/daemon/policy-request-service.test.ts +87 -0
- package/src/daemon/policy-request-service.ts +62 -0
- package/src/daemon/policy-utils.test.ts +138 -0
- package/src/daemon/policy-utils.ts +152 -0
- package/src/daemon/queue.test.ts +89 -0
- package/src/daemon/queue.ts +87 -0
- package/src/daemon/request-store.test.ts +103 -0
- package/src/daemon/request-store.ts +96 -0
- package/src/daemon/router-policy-request.test.ts +99 -0
- package/src/daemon/router.test.ts +380 -0
- package/src/daemon/router.ts +510 -0
- package/src/daemon/routers/slash-command.test.ts +145 -0
- package/src/daemon/routers/slash-command.ts +58 -0
- package/src/daemon/routers/slash-interrupt.test.ts +30 -0
- package/src/daemon/routers/slash-interrupt.ts +7 -0
- package/src/daemon/routers/slash-new.test.ts +59 -0
- package/src/daemon/routers/slash-new.ts +14 -0
- package/src/daemon/routers/slash-policies.test.ts +167 -0
- package/src/daemon/routers/slash-policies.ts +131 -0
- package/src/daemon/routers/slash-stop.test.ts +30 -0
- package/src/daemon/routers/slash-stop.ts +3 -0
- package/src/daemon/routers/types.ts +10 -0
- package/src/daemon/routers/utils.ts +22 -0
- package/src/daemon/routers.test.ts +141 -0
- package/src/daemon/routers.ts +115 -0
- package/src/daemon/utils/spawn.ts +61 -0
- package/src/shared/agent-utils.ts +30 -0
- package/src/shared/chats.test.ts +112 -0
- package/src/shared/chats.ts +164 -0
- package/src/shared/config.test.ts +90 -0
- package/src/shared/config.ts +100 -0
- package/src/shared/event-source.ts +121 -0
- package/src/shared/fetch.ts +45 -0
- package/src/shared/lite.ts +129 -0
- package/src/shared/policies.ts +24 -0
- package/src/shared/utils/env.ts +27 -0
- package/src/shared/utils/fs.ts +13 -0
- package/src/shared/workspace.test.ts +345 -0
- package/src/shared/workspace.ts +500 -0
- package/templates/environments/cladding/env.json +7 -0
- package/templates/environments/macos/env.json +8 -0
- package/templates/environments/macos/sandbox.sb +21 -0
- package/templates/environments/macos-proxy/allowlist.txt +1 -0
- package/templates/environments/macos-proxy/env.json +14 -0
- package/templates/environments/macos-proxy/proxy.mjs +86 -0
- package/templates/environments/macos-proxy/sandbox.sb +34 -0
- package/templates/gemini/settings.json +11 -0
- package/templates/gemini-claw/.gemini/hooks/clawmini-logging.sh +17 -0
- package/templates/gemini-claw/.gemini/settings.json +24 -0
- package/templates/gemini-claw/.gemini/skills/clawmini-jobs/SKILL.md +40 -0
- package/templates/gemini-claw/.gemini/system.md +98 -0
- package/templates/gemini-claw/BOOTSTRAP.md +54 -0
- package/templates/gemini-claw/GEMINI.md +107 -0
- package/templates/gemini-claw/HEARTBEAT.md +3 -0
- package/templates/gemini-claw/MEMORY.md +2 -0
- package/templates/gemini-claw/SOUL.md +42 -0
- package/templates/gemini-claw/TOOLS.md +38 -0
- package/templates/gemini-claw/USER.md +15 -0
- package/templates/gemini-claw/memory/.gitkeep +0 -0
- package/templates/gemini-claw/settings.json +24 -0
- package/templates/opencode/settings.json +11 -0
- package/tsconfig.json +42 -0
- package/tsdown.config.ts +19 -0
- package/vitest.config.ts +9 -0
- package/web/.svelte-kit/ambient.d.ts +382 -0
- package/web/.svelte-kit/generated/client/app.js +35 -0
- package/web/.svelte-kit/generated/client/matchers.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/0.js +3 -0
- package/web/.svelte-kit/generated/client/nodes/1.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/2.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/3.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/4.js +3 -0
- package/web/.svelte-kit/generated/client/nodes/5.js +3 -0
- package/web/.svelte-kit/generated/client-optimized/app.js +35 -0
- package/web/.svelte-kit/generated/client-optimized/matchers.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/0.js +3 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/1.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/2.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/3.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/4.js +3 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/5.js +3 -0
- package/web/.svelte-kit/generated/root.js +3 -0
- package/web/.svelte-kit/generated/root.svelte +68 -0
- package/web/.svelte-kit/generated/server/internal.js +53 -0
- package/web/.svelte-kit/non-ambient.d.ts +46 -0
- package/web/.svelte-kit/output/client/.vite/manifest.json +251 -0
- package/web/.svelte-kit/output/client/_app/immutable/assets/0.GI4C4dpV.css +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/B5abRDXp.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/B8yYFADm.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/BPy8HLo7.js +5 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/Bi0jeV7Q.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/BmUXQ3wy.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/C3k55nDF.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/COekwvP2.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CSvS_NwK.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CpaGRn9L.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CyNaE55B.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DG5RZBw-.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/Dc-UOHw9.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DcrmIfTj.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/ZkLyk0mE.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/entry/app.B-vZe7PN.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/entry/start.oP1AgKhs.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/0.B5WFN0zw.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/1.D1wtJb2k.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/2.CK3CLC0f.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/3.BB5wCoBf.js +4 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/4.Dr2jvAXK.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/5.BJl7oM3b.js +1 -0
- package/web/.svelte-kit/output/client/_app/version.json +1 -0
- package/web/.svelte-kit/output/client/robots.txt +3 -0
- package/web/.svelte-kit/output/prerendered/dependencies/_app/env.js +1 -0
- package/web/.svelte-kit/output/server/.vite/manifest.json +215 -0
- package/web/.svelte-kit/output/server/_app/immutable/assets/_layout.GI4C4dpV.css +1 -0
- package/web/.svelte-kit/output/server/chunks/Icon.js +153 -0
- package/web/.svelte-kit/output/server/chunks/bot.js +2753 -0
- package/web/.svelte-kit/output/server/chunks/client.js +47 -0
- package/web/.svelte-kit/output/server/chunks/environment.js +34 -0
- package/web/.svelte-kit/output/server/chunks/exports.js +231 -0
- package/web/.svelte-kit/output/server/chunks/false.js +4 -0
- package/web/.svelte-kit/output/server/chunks/index-server.js +20 -0
- package/web/.svelte-kit/output/server/chunks/index.js +24 -0
- package/web/.svelte-kit/output/server/chunks/internal.js +133 -0
- package/web/.svelte-kit/output/server/chunks/plus.js +81 -0
- package/web/.svelte-kit/output/server/chunks/root.js +4076 -0
- package/web/.svelte-kit/output/server/chunks/shared.js +789 -0
- package/web/.svelte-kit/output/server/chunks/utils.js +43 -0
- package/web/.svelte-kit/output/server/entries/fallbacks/error.svelte.js +11 -0
- package/web/.svelte-kit/output/server/entries/pages/_layout.svelte.js +3944 -0
- package/web/.svelte-kit/output/server/entries/pages/_layout.ts.js +28 -0
- package/web/.svelte-kit/output/server/entries/pages/_page.svelte.js +7 -0
- package/web/.svelte-kit/output/server/entries/pages/agents/_page.svelte.js +379 -0
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/_page.svelte.js +292 -0
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/_page.ts.js +17 -0
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/settings/_page.svelte.js +259 -0
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/settings/_page.ts.js +17 -0
- package/web/.svelte-kit/output/server/index.js +3748 -0
- package/web/.svelte-kit/output/server/internal.js +14 -0
- package/web/.svelte-kit/output/server/manifest-full.js +63 -0
- package/web/.svelte-kit/output/server/manifest.js +63 -0
- package/web/.svelte-kit/output/server/nodes/0.js +13 -0
- package/web/.svelte-kit/output/server/nodes/1.js +8 -0
- package/web/.svelte-kit/output/server/nodes/2.js +8 -0
- package/web/.svelte-kit/output/server/nodes/3.js +8 -0
- package/web/.svelte-kit/output/server/nodes/4.js +13 -0
- package/web/.svelte-kit/output/server/nodes/5.js +13 -0
- package/web/.svelte-kit/output/server/remote-entry.js +557 -0
- package/web/.svelte-kit/tsconfig.json +67 -0
- package/web/.svelte-kit/types/route_meta_data.json +17 -0
- package/web/.svelte-kit/types/src/routes/$types.d.ts +26 -0
- package/web/.svelte-kit/types/src/routes/agents/$types.d.ts +18 -0
- package/web/.svelte-kit/types/src/routes/chats/[id]/$types.d.ts +21 -0
- package/web/.svelte-kit/types/src/routes/chats/[id]/proxy+page.ts +20 -0
- package/web/.svelte-kit/types/src/routes/chats/[id]/settings/$types.d.ts +21 -0
- package/web/.svelte-kit/types/src/routes/chats/[id]/settings/proxy+page.ts +19 -0
- package/web/.svelte-kit/types/src/routes/proxy+layout.ts +35 -0
- package/web/README.md +42 -0
- package/web/components.json +16 -0
- package/web/package.json +41 -0
- package/web/src/app.css +121 -0
- package/web/src/app.d.ts +13 -0
- package/web/src/app.html +11 -0
- package/web/src/demo.spec.ts +7 -0
- package/web/src/lib/app-state.svelte.ts +3 -0
- package/web/src/lib/assets/favicon.svg +1 -0
- package/web/src/lib/components/app/app-sidebar-test-wrapper.svelte +10 -0
- package/web/src/lib/components/app/app-sidebar.svelte +171 -0
- package/web/src/lib/components/app/app-sidebar.svelte.spec.ts +13 -0
- package/web/src/lib/components/ui/button/button.svelte +82 -0
- package/web/src/lib/components/ui/button/index.ts +17 -0
- package/web/src/lib/components/ui/dialog/dialog-close.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog-content.svelte +45 -0
- package/web/src/lib/components/ui/dialog/dialog-description.svelte +17 -0
- package/web/src/lib/components/ui/dialog/dialog-footer.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-header.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-overlay.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-portal.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog-title.svelte +17 -0
- package/web/src/lib/components/ui/dialog/dialog-trigger.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog.svelte +7 -0
- package/web/src/lib/components/ui/dialog/index.ts +34 -0
- package/web/src/lib/components/ui/input/index.ts +7 -0
- package/web/src/lib/components/ui/input/input.svelte +52 -0
- package/web/src/lib/components/ui/separator/index.ts +7 -0
- package/web/src/lib/components/ui/separator/separator.svelte +21 -0
- package/web/src/lib/components/ui/sheet/index.ts +34 -0
- package/web/src/lib/components/ui/sheet/sheet-close.svelte +7 -0
- package/web/src/lib/components/ui/sheet/sheet-content.svelte +60 -0
- package/web/src/lib/components/ui/sheet/sheet-description.svelte +17 -0
- package/web/src/lib/components/ui/sheet/sheet-footer.svelte +20 -0
- package/web/src/lib/components/ui/sheet/sheet-header.svelte +20 -0
- package/web/src/lib/components/ui/sheet/sheet-overlay.svelte +20 -0
- package/web/src/lib/components/ui/sheet/sheet-portal.svelte +7 -0
- package/web/src/lib/components/ui/sheet/sheet-title.svelte +17 -0
- package/web/src/lib/components/ui/sheet/sheet-trigger.svelte +7 -0
- package/web/src/lib/components/ui/sheet/sheet.svelte +7 -0
- package/web/src/lib/components/ui/sidebar/constants.ts +6 -0
- package/web/src/lib/components/ui/sidebar/context.svelte.ts +79 -0
- package/web/src/lib/components/ui/sidebar/index.ts +75 -0
- package/web/src/lib/components/ui/sidebar/sidebar-content.svelte +24 -0
- package/web/src/lib/components/ui/sidebar/sidebar-footer.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-group-action.svelte +36 -0
- package/web/src/lib/components/ui/sidebar/sidebar-group-content.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-group-label.svelte +34 -0
- package/web/src/lib/components/ui/sidebar/sidebar-group.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-header.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-input.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-inset.svelte +24 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-action.svelte +43 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-badge.svelte +29 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-button.svelte +103 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-item.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-skeleton.svelte +36 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-sub-button.svelte +43 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-sub-item.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-sub.svelte +25 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-provider.svelte +53 -0
- package/web/src/lib/components/ui/sidebar/sidebar-rail.svelte +36 -0
- package/web/src/lib/components/ui/sidebar/sidebar-separator.svelte +19 -0
- package/web/src/lib/components/ui/sidebar/sidebar-trigger.svelte +35 -0
- package/web/src/lib/components/ui/sidebar/sidebar.svelte +104 -0
- package/web/src/lib/components/ui/skeleton/index.ts +7 -0
- package/web/src/lib/components/ui/skeleton/skeleton.svelte +17 -0
- package/web/src/lib/components/ui/switch/index.ts +7 -0
- package/web/src/lib/components/ui/switch/switch.svelte +29 -0
- package/web/src/lib/components/ui/textarea/index.ts +7 -0
- package/web/src/lib/components/ui/textarea/textarea.svelte +23 -0
- package/web/src/lib/components/ui/tooltip/index.ts +19 -0
- package/web/src/lib/components/ui/tooltip/tooltip-content.svelte +52 -0
- package/web/src/lib/components/ui/tooltip/tooltip-portal.svelte +7 -0
- package/web/src/lib/components/ui/tooltip/tooltip-provider.svelte +7 -0
- package/web/src/lib/components/ui/tooltip/tooltip-trigger.svelte +7 -0
- package/web/src/lib/components/ui/tooltip/tooltip.svelte +7 -0
- package/web/src/lib/hooks/is-mobile.svelte.ts +9 -0
- package/web/src/lib/index.ts +1 -0
- package/web/src/lib/types.ts +23 -0
- package/web/src/lib/utils.ts +13 -0
- package/web/src/routes/+layout.svelte +67 -0
- package/web/src/routes/+layout.ts +34 -0
- package/web/src/routes/+page.svelte +7 -0
- package/web/src/routes/agents/+page.svelte +206 -0
- package/web/src/routes/chats/[id]/+page.svelte +406 -0
- package/web/src/routes/chats/[id]/+page.ts +19 -0
- package/web/src/routes/chats/[id]/page.svelte.spec.ts +102 -0
- package/web/src/routes/chats/[id]/settings/+page.svelte +165 -0
- package/web/src/routes/chats/[id]/settings/+page.ts +18 -0
- package/web/src/routes/page.svelte.spec.ts +13 -0
- package/web/static/robots.txt +3 -0
- package/web/svelte.config.js +21 -0
- package/web/tsconfig.json +20 -0
- package/web/vite.config.ts +41 -0
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "clawmini",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"workspaces": [
|
|
6
|
+
"web"
|
|
7
|
+
],
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/tbuckley/clawmini.git"
|
|
11
|
+
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"clawmini": "./dist/cli/index.mjs",
|
|
14
|
+
"clawmini-adapter-discord": "./dist/adapter-discord/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"clean": "rm -rf dist",
|
|
18
|
+
"build": "tsdown && npm run build:web",
|
|
19
|
+
"dev:cli": "tsdown --watch",
|
|
20
|
+
"dev:daemon": "tsdown --watch",
|
|
21
|
+
"lint": "eslint -f codeframe .",
|
|
22
|
+
"lint:fix": "eslint . --fix",
|
|
23
|
+
"format:check": "prettier --check \"src/**/*.ts\" \"web/src/**/*.ts\"",
|
|
24
|
+
"format": "prettier --write \"src/**/*.ts\" \"web/src/**/*.ts\"",
|
|
25
|
+
"check": "tsc --noEmit && npm run check -w web",
|
|
26
|
+
"test": "vitest run && npm run test -w web",
|
|
27
|
+
"build:web": "npm run build -w web"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@trpc/client": "^11.12.0",
|
|
31
|
+
"@trpc/server": "^11.10.0",
|
|
32
|
+
"commander": "^14.0.3",
|
|
33
|
+
"discord.js": "^14.25.1",
|
|
34
|
+
"node-schedule": "^2.1.1",
|
|
35
|
+
"zod": "^4.3.6"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@eslint/js": "^10.0.1",
|
|
39
|
+
"@types/node": "^25.3.0",
|
|
40
|
+
"eslint": "^10.0.1",
|
|
41
|
+
"eslint-config-prettier": "^10.1.8",
|
|
42
|
+
"eslint-formatter-codeframe": "^7.32.2",
|
|
43
|
+
"globals": "^17.3.0",
|
|
44
|
+
"prettier": "^3.8.1",
|
|
45
|
+
"tsdown": "^0.20.3",
|
|
46
|
+
"typescript": "^5.9.3",
|
|
47
|
+
"typescript-eslint": "^8.56.1",
|
|
48
|
+
"vitest": "^4.0.18"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Check if an argument is provided
|
|
4
|
+
if [ -z "$1" ]; then
|
|
5
|
+
echo "Usage: $0 <branch-name>"
|
|
6
|
+
exit 1
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
BRANCH_NAME=$1
|
|
10
|
+
# Resolve the target directory relative to the current directory's parent
|
|
11
|
+
TARGET_DIR="../$BRANCH_NAME"
|
|
12
|
+
|
|
13
|
+
echo "Creating git worktree '$BRANCH_NAME' at '$TARGET_DIR'..."
|
|
14
|
+
# Create the worktree and the new branch
|
|
15
|
+
git worktree add -b "$BRANCH_NAME" "$TARGET_DIR"
|
|
16
|
+
|
|
17
|
+
if [ $? -ne 0 ]; then
|
|
18
|
+
echo "Error: Failed to create worktree. Please check git status and arguments."
|
|
19
|
+
exit 1
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
echo "Copying .gemini sandbox files..."
|
|
23
|
+
if [ -d ".gemini" ]; then
|
|
24
|
+
mkdir -p "$TARGET_DIR/.gemini"
|
|
25
|
+
if ls .gemini/*.sb 1> /dev/null 2>&1; then
|
|
26
|
+
cp .gemini/*.sb "$TARGET_DIR/.gemini/"
|
|
27
|
+
else
|
|
28
|
+
echo "No .sb files found in .gemini/"
|
|
29
|
+
fi
|
|
30
|
+
else
|
|
31
|
+
echo "Warning: .gemini directory not found. Skipping sandbox files copy."
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
echo "Running npm install in '$TARGET_DIR'..."
|
|
35
|
+
# Navigate to the new directory and install dependencies
|
|
36
|
+
cd "$TARGET_DIR" || exit 1
|
|
37
|
+
npm install
|
|
38
|
+
|
|
39
|
+
if [ $? -eq 0 ]; then
|
|
40
|
+
echo "--------------------------------------------------"
|
|
41
|
+
echo "Worktree setup complete for '$BRANCH_NAME'."
|
|
42
|
+
echo "Location: $TARGET_DIR"
|
|
43
|
+
echo "NOTE: To change your current shell to this directory, run:"
|
|
44
|
+
echo "source ./scripts/create_worktree.sh $BRANCH_NAME"
|
|
45
|
+
echo "--------------------------------------------------"
|
|
46
|
+
else
|
|
47
|
+
echo "Error: npm install failed."
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 1. Check if GitHub CLI is installed
|
|
4
|
+
if ! command -v gh &> /dev/null; then
|
|
5
|
+
echo "Error: GitHub CLI ('gh') is not installed."
|
|
6
|
+
exit 1
|
|
7
|
+
fi
|
|
8
|
+
|
|
9
|
+
# 2. Get the PR Number
|
|
10
|
+
# Accepts a number as an argument (./script.sh 123)
|
|
11
|
+
# OR defaults to the current branch's PR if no argument is provided.
|
|
12
|
+
PR_NUM=${1:-$(gh pr view --json number -q .number 2>/dev/null)}
|
|
13
|
+
|
|
14
|
+
if [ -z "$PR_NUM" ]; then
|
|
15
|
+
echo "Error: Could not detect a PR number. Are you on a branch with an open PR?"
|
|
16
|
+
echo "Usage: $0 [pr-number]"
|
|
17
|
+
exit 1
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
echo "Fetching review comments for PR #$PR_NUM..."
|
|
21
|
+
echo "---------------------------------------------------"
|
|
22
|
+
|
|
23
|
+
# 3. Fetch Comments via API
|
|
24
|
+
# - GH_PAGER="": Disables interactive pager (less)
|
|
25
|
+
# - --paginate: Ensures we get all comments (not just the first 30)
|
|
26
|
+
# - jq: Formats the raw JSON into readable text
|
|
27
|
+
GH_PAGER="" gh api --paginate \
|
|
28
|
+
"repos/:owner/:repo/pulls/$PR_NUM/comments" \
|
|
29
|
+
--jq '.[] |
|
|
30
|
+
"File: \(.path)",
|
|
31
|
+
"Line: \(if .line then .line else (.original_line | tostring + " (outdated)") end)",
|
|
32
|
+
"----",
|
|
33
|
+
"\(.body)",
|
|
34
|
+
"\n===================================================\n"'
|
|
35
|
+
|
|
36
|
+
# "Author: \(.user.login)",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { getTRPCClient } from './client.js';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import * as workspace from '../shared/workspace.js';
|
|
5
|
+
import { createTRPCClient, httpLink, splitLink, httpSubscriptionLink } from '@trpc/client';
|
|
6
|
+
import { createUnixSocketFetch } from '../shared/fetch.js';
|
|
7
|
+
|
|
8
|
+
vi.mock('node:fs');
|
|
9
|
+
vi.mock('../shared/workspace.js');
|
|
10
|
+
vi.mock('@trpc/client', () => ({
|
|
11
|
+
createTRPCClient: vi.fn().mockReturnValue({
|
|
12
|
+
ping: {
|
|
13
|
+
query: vi.fn().mockResolvedValue({ status: 'ok' }),
|
|
14
|
+
},
|
|
15
|
+
}),
|
|
16
|
+
httpLink: vi.fn(),
|
|
17
|
+
splitLink: vi.fn(),
|
|
18
|
+
httpSubscriptionLink: vi.fn(),
|
|
19
|
+
}));
|
|
20
|
+
vi.mock('../shared/fetch.js', () => ({
|
|
21
|
+
createUnixSocketFetch: vi.fn(),
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
describe('Discord Adapter TRPC Client', () => {
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
vi.clearAllMocks();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should throw error if daemon socket does not exist', () => {
|
|
30
|
+
vi.mocked(workspace.getSocketPath).mockReturnValue('/tmp/test.sock');
|
|
31
|
+
vi.mocked(fs.existsSync).mockReturnValue(false);
|
|
32
|
+
|
|
33
|
+
expect(() => getTRPCClient()).toThrow('Daemon not running. Socket not found at /tmp/test.sock');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should create TRPC client if daemon socket exists', () => {
|
|
37
|
+
vi.mocked(workspace.getSocketPath).mockReturnValue('/tmp/test.sock');
|
|
38
|
+
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
39
|
+
|
|
40
|
+
const client = getTRPCClient();
|
|
41
|
+
expect(client).toBeDefined();
|
|
42
|
+
expect(createTRPCClient).toHaveBeenCalled();
|
|
43
|
+
expect(splitLink).toHaveBeenCalled();
|
|
44
|
+
expect(httpLink).toHaveBeenCalledWith(
|
|
45
|
+
expect.objectContaining({
|
|
46
|
+
url: 'http://localhost',
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
expect(httpSubscriptionLink).toHaveBeenCalledWith(
|
|
50
|
+
expect.objectContaining({
|
|
51
|
+
url: 'http://localhost',
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
expect(createUnixSocketFetch).toHaveBeenCalledWith('/tmp/test.sock');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should be able to call ping on the client', async () => {
|
|
58
|
+
vi.mocked(workspace.getSocketPath).mockReturnValue('/tmp/test.sock');
|
|
59
|
+
vi.mocked(fs.existsSync).mockReturnValue(true);
|
|
60
|
+
|
|
61
|
+
const client = getTRPCClient();
|
|
62
|
+
const result = await client.ping.query();
|
|
63
|
+
expect(result).toEqual({ status: 'ok' });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createTRPCClient, httpLink, splitLink, httpSubscriptionLink } from '@trpc/client';
|
|
2
|
+
import type { AppRouter } from '../daemon/router.js';
|
|
3
|
+
import { getSocketPath } from '../shared/workspace.js';
|
|
4
|
+
import { createUnixSocketFetch } from '../shared/fetch.js';
|
|
5
|
+
import { createUnixSocketEventSource } from '../shared/event-source.js';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a TRPC client that connects to the Clawmini daemon via a Unix socket.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Configuration options for the client.
|
|
12
|
+
* @returns A TRPC client instance for the AppRouter.
|
|
13
|
+
*/
|
|
14
|
+
export function getTRPCClient(options: { socketPath?: string } = {}) {
|
|
15
|
+
const socketPath = options.socketPath ?? getSocketPath();
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(socketPath)) {
|
|
18
|
+
throw new Error(`Daemon not running. Socket not found at ${socketPath}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const customFetch = createUnixSocketFetch(socketPath);
|
|
22
|
+
const CustomEventSource = createUnixSocketEventSource(socketPath);
|
|
23
|
+
|
|
24
|
+
return createTRPCClient<AppRouter>({
|
|
25
|
+
links: [
|
|
26
|
+
splitLink({
|
|
27
|
+
condition(op) {
|
|
28
|
+
return op.type === 'subscription';
|
|
29
|
+
},
|
|
30
|
+
true: httpSubscriptionLink({
|
|
31
|
+
url: 'http://localhost',
|
|
32
|
+
EventSource: CustomEventSource,
|
|
33
|
+
}),
|
|
34
|
+
false: httpLink({
|
|
35
|
+
url: 'http://localhost',
|
|
36
|
+
fetch: customFetch,
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import fsPromises from 'node:fs/promises';
|
|
3
|
+
import {
|
|
4
|
+
DiscordConfigSchema,
|
|
5
|
+
isAuthorized,
|
|
6
|
+
readDiscordConfig,
|
|
7
|
+
getDiscordConfigPath,
|
|
8
|
+
} from './config.js';
|
|
9
|
+
|
|
10
|
+
vi.mock('node:fs/promises');
|
|
11
|
+
vi.mock('node:fs', () => ({
|
|
12
|
+
default: {
|
|
13
|
+
existsSync: vi.fn(),
|
|
14
|
+
},
|
|
15
|
+
existsSync: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
vi.mock('../shared/workspace.js', () => ({
|
|
18
|
+
getClawminiDir: () => '/mock/clawmini',
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
describe('Discord Adapter Configuration', () => {
|
|
22
|
+
describe('DiscordConfigSchema', () => {
|
|
23
|
+
it('should validate a correct configuration', () => {
|
|
24
|
+
const config = {
|
|
25
|
+
botToken: 'my-bot-token',
|
|
26
|
+
authorizedUserId: '1234567890',
|
|
27
|
+
};
|
|
28
|
+
const result = DiscordConfigSchema.safeParse(config);
|
|
29
|
+
expect(result.success).toBe(true);
|
|
30
|
+
if (result.success) {
|
|
31
|
+
expect(result.data).toEqual({
|
|
32
|
+
...config,
|
|
33
|
+
chatId: 'default',
|
|
34
|
+
maxAttachmentSizeMB: 25,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should validate a custom maxAttachmentSizeMB', () => {
|
|
40
|
+
const config = {
|
|
41
|
+
botToken: 'my-bot-token',
|
|
42
|
+
authorizedUserId: '1234567890',
|
|
43
|
+
maxAttachmentSizeMB: 50,
|
|
44
|
+
};
|
|
45
|
+
const result = DiscordConfigSchema.safeParse(config);
|
|
46
|
+
expect(result.success).toBe(true);
|
|
47
|
+
if (result.success) {
|
|
48
|
+
expect(result.data.maxAttachmentSizeMB).toBe(50);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should fail validation if fields are missing', () => {
|
|
53
|
+
const result = DiscordConfigSchema.safeParse({});
|
|
54
|
+
expect(result.success).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should fail validation if fields are empty', () => {
|
|
58
|
+
const result = DiscordConfigSchema.safeParse({
|
|
59
|
+
botToken: '',
|
|
60
|
+
authorizedUserId: '',
|
|
61
|
+
});
|
|
62
|
+
expect(result.success).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('isAuthorized', () => {
|
|
67
|
+
it('should return true if user ID matches authorized user ID', () => {
|
|
68
|
+
expect(isAuthorized('123', '123')).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should return false if user ID does not match', () => {
|
|
72
|
+
expect(isAuthorized('123', '456')).toBe(false);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('initDiscordConfig', () => {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
let fsMock: any;
|
|
79
|
+
|
|
80
|
+
beforeEach(async () => {
|
|
81
|
+
vi.clearAllMocks();
|
|
82
|
+
fsMock = await import('node:fs');
|
|
83
|
+
vi.mocked(fsMock.existsSync).mockReturnValue(false);
|
|
84
|
+
if (fsMock.default) {
|
|
85
|
+
vi.mocked(fsMock.default.existsSync).mockReturnValue(false);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should create directory and template config file if they do not exist', async () => {
|
|
90
|
+
const { initDiscordConfig } = await import('./config.js');
|
|
91
|
+
await initDiscordConfig();
|
|
92
|
+
|
|
93
|
+
expect(fsPromises.mkdir).toHaveBeenCalledWith('/mock/clawmini/adapters/discord', {
|
|
94
|
+
recursive: true,
|
|
95
|
+
});
|
|
96
|
+
expect(fsPromises.writeFile).toHaveBeenCalled();
|
|
97
|
+
const writeCall = vi.mocked(fsPromises.writeFile).mock.calls[0];
|
|
98
|
+
expect(writeCall![0]).toBe(getDiscordConfigPath());
|
|
99
|
+
expect(JSON.parse(writeCall![1] as string)).toEqual({
|
|
100
|
+
botToken: 'YOUR_DISCORD_BOT_TOKEN',
|
|
101
|
+
authorizedUserId: 'YOUR_DISCORD_USER_ID',
|
|
102
|
+
chatId: 'default',
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should not overwrite existing config file', async () => {
|
|
107
|
+
vi.mocked(fsMock.existsSync).mockReturnValue(true);
|
|
108
|
+
if (fsMock.default) {
|
|
109
|
+
vi.mocked(fsMock.default.existsSync).mockReturnValue(true);
|
|
110
|
+
}
|
|
111
|
+
const { initDiscordConfig } = await import('./config.js');
|
|
112
|
+
await initDiscordConfig();
|
|
113
|
+
|
|
114
|
+
expect(fsPromises.writeFile).not.toHaveBeenCalled();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('readDiscordConfig', () => {
|
|
119
|
+
beforeEach(() => {
|
|
120
|
+
vi.clearAllMocks();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should successfully read and parse a valid config file', async () => {
|
|
124
|
+
const mockConfig = {
|
|
125
|
+
botToken: 'my-bot-token',
|
|
126
|
+
authorizedUserId: '1234567890',
|
|
127
|
+
};
|
|
128
|
+
vi.mocked(fsPromises.readFile).mockResolvedValue(JSON.stringify(mockConfig));
|
|
129
|
+
|
|
130
|
+
const config = await readDiscordConfig();
|
|
131
|
+
expect(config).toEqual({ ...mockConfig, chatId: 'default', maxAttachmentSizeMB: 25 });
|
|
132
|
+
expect(fsPromises.readFile).toHaveBeenCalledWith(getDiscordConfigPath(), 'utf-8');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should return null if the config file does not exist', async () => {
|
|
136
|
+
vi.mocked(fsPromises.readFile).mockRejectedValue(new Error('File not found'));
|
|
137
|
+
|
|
138
|
+
const config = await readDiscordConfig();
|
|
139
|
+
expect(config).toBeNull();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should return null if the config file contains invalid JSON', async () => {
|
|
143
|
+
vi.mocked(fsPromises.readFile).mockResolvedValue('invalid-json');
|
|
144
|
+
|
|
145
|
+
const config = await readDiscordConfig();
|
|
146
|
+
expect(config).toBeNull();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should return null if the config fails schema validation', async () => {
|
|
150
|
+
vi.mocked(fsPromises.readFile).mockResolvedValue(JSON.stringify({ botToken: 'test' }));
|
|
151
|
+
|
|
152
|
+
const config = await readDiscordConfig();
|
|
153
|
+
expect(config).toBeNull();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fsPromises from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { getClawminiDir } from '../shared/workspace.js';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
|
|
7
|
+
export const DiscordConfigSchema = z.looseObject({
|
|
8
|
+
botToken: z.string().min(1, 'Discord Bot Token is required.'),
|
|
9
|
+
authorizedUserId: z.string().min(1, 'Authorized Discord User ID is required.'),
|
|
10
|
+
chatId: z.string().default('default'),
|
|
11
|
+
maxAttachmentSizeMB: z.number().default(25).optional(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type DiscordConfig = z.infer<typeof DiscordConfigSchema>;
|
|
15
|
+
|
|
16
|
+
export function getDiscordConfigPath(startDir = process.cwd()): string {
|
|
17
|
+
return path.join(getClawminiDir(startDir), 'adapters', 'discord', 'config.json');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function readDiscordConfig(startDir = process.cwd()): Promise<DiscordConfig | null> {
|
|
21
|
+
const configPath = getDiscordConfigPath(startDir);
|
|
22
|
+
try {
|
|
23
|
+
const data = await fsPromises.readFile(configPath, 'utf-8');
|
|
24
|
+
const parsed = JSON.parse(data);
|
|
25
|
+
const result = DiscordConfigSchema.safeParse(parsed);
|
|
26
|
+
if (!result.success) {
|
|
27
|
+
console.error('Invalid Discord configuration:', result.error.format());
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return result.data;
|
|
31
|
+
} catch {
|
|
32
|
+
// Return null if file doesn't exist or is invalid JSON
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function initDiscordConfig(startDir = process.cwd()): Promise<void> {
|
|
38
|
+
const configPath = getDiscordConfigPath(startDir);
|
|
39
|
+
const configDir = path.dirname(configPath);
|
|
40
|
+
|
|
41
|
+
await fsPromises.mkdir(configDir, { recursive: true });
|
|
42
|
+
|
|
43
|
+
if (fs.existsSync(configPath)) {
|
|
44
|
+
console.log(`Config file already exists at ${configPath}`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const templateConfig = {
|
|
49
|
+
botToken: 'YOUR_DISCORD_BOT_TOKEN',
|
|
50
|
+
authorizedUserId: 'YOUR_DISCORD_USER_ID',
|
|
51
|
+
chatId: 'default',
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
await fsPromises.writeFile(configPath, JSON.stringify(templateConfig, null, 2), 'utf-8');
|
|
55
|
+
console.log(`Created template configuration file at ${configPath}`);
|
|
56
|
+
console.log('Please update it with your actual Discord Bot Token and User ID.');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isAuthorized(userId: string, authorizedUserId: string): boolean {
|
|
60
|
+
return userId === authorizedUserId;
|
|
61
|
+
}
|