agent-messenger 1.0.0
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/.claude/commands/release.md +92 -0
- package/.claude-plugin/README.md +144 -0
- package/.claude-plugin/marketplace.json +37 -0
- package/.claude-plugin/plugin.json +17 -0
- package/.github/workflows/ci.yml +30 -0
- package/CLAUDE.md +106 -0
- package/CONTRIBUTING.md +131 -0
- package/README.md +140 -0
- package/biome.json +34 -0
- package/bun.lock +252 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +21 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +140 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/channel.d.ts +3 -0
- package/dist/commands/channel.d.ts.map +1 -0
- package/dist/commands/channel.js +118 -0
- package/dist/commands/channel.js.map +1 -0
- package/dist/commands/file.d.ts +3 -0
- package/dist/commands/file.d.ts.map +1 -0
- package/dist/commands/file.js +113 -0
- package/dist/commands/file.js.map +1 -0
- package/dist/commands/index.d.ts +9 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +9 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/message.d.ts +3 -0
- package/dist/commands/message.d.ts.map +1 -0
- package/dist/commands/message.js +214 -0
- package/dist/commands/message.js.map +1 -0
- package/dist/commands/reaction.d.ts +3 -0
- package/dist/commands/reaction.d.ts.map +1 -0
- package/dist/commands/reaction.js +100 -0
- package/dist/commands/reaction.js.map +1 -0
- package/dist/commands/snapshot.d.ts +3 -0
- package/dist/commands/snapshot.d.ts.map +1 -0
- package/dist/commands/snapshot.js +88 -0
- package/dist/commands/snapshot.js.map +1 -0
- package/dist/commands/user.d.ts +3 -0
- package/dist/commands/user.d.ts.map +1 -0
- package/dist/commands/user.js +96 -0
- package/dist/commands/user.js.map +1 -0
- package/dist/commands/workspace.d.ts +3 -0
- package/dist/commands/workspace.d.ts.map +1 -0
- package/dist/commands/workspace.js +89 -0
- package/dist/commands/workspace.js.map +1 -0
- package/dist/lib/credential-manager.d.ts +13 -0
- package/dist/lib/credential-manager.d.ts.map +1 -0
- package/dist/lib/credential-manager.js +58 -0
- package/dist/lib/credential-manager.js.map +1 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/ref-manager.d.ts +26 -0
- package/dist/lib/ref-manager.d.ts.map +1 -0
- package/dist/lib/ref-manager.js +92 -0
- package/dist/lib/ref-manager.js.map +1 -0
- package/dist/lib/slack-client.d.ts +37 -0
- package/dist/lib/slack-client.d.ts.map +1 -0
- package/dist/lib/slack-client.js +379 -0
- package/dist/lib/slack-client.js.map +1 -0
- package/dist/lib/token-extractor.d.ts +28 -0
- package/dist/lib/token-extractor.d.ts.map +1 -0
- package/dist/lib/token-extractor.js +401 -0
- package/dist/lib/token-extractor.js.map +1 -0
- package/dist/package.json +37 -0
- package/dist/src/cli.d.ts +5 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +22 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/platforms/discord/cli.d.ts +5 -0
- package/dist/src/platforms/discord/cli.d.ts.map +1 -0
- package/dist/src/platforms/discord/cli.js +22 -0
- package/dist/src/platforms/discord/cli.js.map +1 -0
- package/dist/src/platforms/discord/client.d.ts +34 -0
- package/dist/src/platforms/discord/client.d.ts.map +1 -0
- package/dist/src/platforms/discord/client.js +187 -0
- package/dist/src/platforms/discord/client.js.map +1 -0
- package/dist/src/platforms/discord/client.test.d.ts +2 -0
- package/dist/src/platforms/discord/client.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/client.test.js +367 -0
- package/dist/src/platforms/discord/client.test.js.map +1 -0
- package/dist/src/platforms/discord/commands/auth.d.ts +13 -0
- package/dist/src/platforms/discord/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/auth.js +155 -0
- package/dist/src/platforms/discord/commands/auth.js.map +1 -0
- package/dist/src/platforms/discord/commands/auth.test.d.ts +2 -0
- package/dist/src/platforms/discord/commands/auth.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/auth.test.js +65 -0
- package/dist/src/platforms/discord/commands/auth.test.js.map +1 -0
- package/dist/src/platforms/discord/commands/channel.d.ts +13 -0
- package/dist/src/platforms/discord/commands/channel.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/channel.js +99 -0
- package/dist/src/platforms/discord/commands/channel.js.map +1 -0
- package/dist/src/platforms/discord/commands/channel.test.d.ts +2 -0
- package/dist/src/platforms/discord/commands/channel.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/channel.test.js +136 -0
- package/dist/src/platforms/discord/commands/channel.test.js.map +1 -0
- package/dist/src/platforms/discord/commands/file.d.ts +13 -0
- package/dist/src/platforms/discord/commands/file.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/file.js +99 -0
- package/dist/src/platforms/discord/commands/file.js.map +1 -0
- package/dist/src/platforms/discord/commands/file.test.d.ts +2 -0
- package/dist/src/platforms/discord/commands/file.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/file.test.js +83 -0
- package/dist/src/platforms/discord/commands/file.test.js.map +1 -0
- package/dist/src/platforms/discord/commands/guild.d.ts +15 -0
- package/dist/src/platforms/discord/commands/guild.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/guild.js +102 -0
- package/dist/src/platforms/discord/commands/guild.js.map +1 -0
- package/dist/src/platforms/discord/commands/guild.test.d.ts +2 -0
- package/dist/src/platforms/discord/commands/guild.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/guild.test.js +100 -0
- package/dist/src/platforms/discord/commands/guild.test.js.map +1 -0
- package/dist/src/platforms/discord/commands/index.d.ts +9 -0
- package/dist/src/platforms/discord/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/index.js +9 -0
- package/dist/src/platforms/discord/commands/index.js.map +1 -0
- package/dist/src/platforms/discord/commands/message.d.ts +17 -0
- package/dist/src/platforms/discord/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/message.js +131 -0
- package/dist/src/platforms/discord/commands/message.js.map +1 -0
- package/dist/src/platforms/discord/commands/message.test.d.ts +2 -0
- package/dist/src/platforms/discord/commands/message.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/message.test.js +91 -0
- package/dist/src/platforms/discord/commands/message.test.js.map +1 -0
- package/dist/src/platforms/discord/commands/reaction.d.ts +12 -0
- package/dist/src/platforms/discord/commands/reaction.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/reaction.js +99 -0
- package/dist/src/platforms/discord/commands/reaction.js.map +1 -0
- package/dist/src/platforms/discord/commands/reaction.test.d.ts +2 -0
- package/dist/src/platforms/discord/commands/reaction.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/reaction.test.js +115 -0
- package/dist/src/platforms/discord/commands/reaction.test.js.map +1 -0
- package/dist/src/platforms/discord/commands/snapshot.d.ts +9 -0
- package/dist/src/platforms/discord/commands/snapshot.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/snapshot.js +80 -0
- package/dist/src/platforms/discord/commands/snapshot.js.map +1 -0
- package/dist/src/platforms/discord/commands/snapshot.test.d.ts +2 -0
- package/dist/src/platforms/discord/commands/snapshot.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/snapshot.test.js +25 -0
- package/dist/src/platforms/discord/commands/snapshot.test.js.map +1 -0
- package/dist/src/platforms/discord/commands/user.d.ts +3 -0
- package/dist/src/platforms/discord/commands/user.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/user.js +94 -0
- package/dist/src/platforms/discord/commands/user.js.map +1 -0
- package/dist/src/platforms/discord/commands/user.test.d.ts +2 -0
- package/dist/src/platforms/discord/commands/user.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/commands/user.test.js +103 -0
- package/dist/src/platforms/discord/commands/user.test.js.map +1 -0
- package/dist/src/platforms/discord/credential-manager.d.ts +33 -0
- package/dist/src/platforms/discord/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/discord/credential-manager.js +73 -0
- package/dist/src/platforms/discord/credential-manager.js.map +1 -0
- package/dist/src/platforms/discord/credential-manager.test.d.ts +2 -0
- package/dist/src/platforms/discord/credential-manager.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/credential-manager.test.js +136 -0
- package/dist/src/platforms/discord/credential-manager.test.js.map +1 -0
- package/dist/src/platforms/discord/token-extractor.d.ts +55 -0
- package/dist/src/platforms/discord/token-extractor.d.ts.map +1 -0
- package/dist/src/platforms/discord/token-extractor.js +462 -0
- package/dist/src/platforms/discord/token-extractor.js.map +1 -0
- package/dist/src/platforms/discord/token-extractor.test.d.ts +2 -0
- package/dist/src/platforms/discord/token-extractor.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/token-extractor.test.js +789 -0
- package/dist/src/platforms/discord/token-extractor.test.js.map +1 -0
- package/dist/src/platforms/discord/types.d.ts +251 -0
- package/dist/src/platforms/discord/types.d.ts.map +1 -0
- package/dist/src/platforms/discord/types.js +74 -0
- package/dist/src/platforms/discord/types.js.map +1 -0
- package/dist/src/platforms/discord/types.test.d.ts +2 -0
- package/dist/src/platforms/discord/types.test.d.ts.map +1 -0
- package/dist/src/platforms/discord/types.test.js +211 -0
- package/dist/src/platforms/discord/types.test.js.map +1 -0
- package/dist/src/platforms/slack/cli.d.ts +5 -0
- package/dist/src/platforms/slack/cli.d.ts.map +1 -0
- package/dist/src/platforms/slack/cli.js +22 -0
- package/dist/src/platforms/slack/cli.js.map +1 -0
- package/dist/src/platforms/slack/client.d.ts +47 -0
- package/dist/src/platforms/slack/client.d.ts.map +1 -0
- package/dist/src/platforms/slack/client.js +412 -0
- package/dist/src/platforms/slack/client.js.map +1 -0
- package/dist/src/platforms/slack/commands/auth.d.ts +3 -0
- package/dist/src/platforms/slack/commands/auth.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/auth.js +156 -0
- package/dist/src/platforms/slack/commands/auth.js.map +1 -0
- package/dist/src/platforms/slack/commands/channel.d.ts +3 -0
- package/dist/src/platforms/slack/commands/channel.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/channel.js +118 -0
- package/dist/src/platforms/slack/commands/channel.js.map +1 -0
- package/dist/src/platforms/slack/commands/file.d.ts +3 -0
- package/dist/src/platforms/slack/commands/file.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/file.js +113 -0
- package/dist/src/platforms/slack/commands/file.js.map +1 -0
- package/dist/src/platforms/slack/commands/index.d.ts +9 -0
- package/dist/src/platforms/slack/commands/index.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/index.js +9 -0
- package/dist/src/platforms/slack/commands/index.js.map +1 -0
- package/dist/src/platforms/slack/commands/message.d.ts +3 -0
- package/dist/src/platforms/slack/commands/message.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/message.js +263 -0
- package/dist/src/platforms/slack/commands/message.js.map +1 -0
- package/dist/src/platforms/slack/commands/reaction.d.ts +3 -0
- package/dist/src/platforms/slack/commands/reaction.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/reaction.js +100 -0
- package/dist/src/platforms/slack/commands/reaction.js.map +1 -0
- package/dist/src/platforms/slack/commands/snapshot.d.ts +3 -0
- package/dist/src/platforms/slack/commands/snapshot.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/snapshot.js +87 -0
- package/dist/src/platforms/slack/commands/snapshot.js.map +1 -0
- package/dist/src/platforms/slack/commands/user.d.ts +3 -0
- package/dist/src/platforms/slack/commands/user.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/user.js +96 -0
- package/dist/src/platforms/slack/commands/user.js.map +1 -0
- package/dist/src/platforms/slack/commands/workspace.d.ts +3 -0
- package/dist/src/platforms/slack/commands/workspace.d.ts.map +1 -0
- package/dist/src/platforms/slack/commands/workspace.js +89 -0
- package/dist/src/platforms/slack/commands/workspace.js.map +1 -0
- package/dist/src/platforms/slack/credential-manager.d.ts +13 -0
- package/dist/src/platforms/slack/credential-manager.d.ts.map +1 -0
- package/dist/src/platforms/slack/credential-manager.js +58 -0
- package/dist/src/platforms/slack/credential-manager.js.map +1 -0
- package/dist/src/platforms/slack/index.d.ts +3 -0
- package/dist/src/platforms/slack/index.d.ts.map +1 -0
- package/dist/src/platforms/slack/index.js +3 -0
- package/dist/src/platforms/slack/index.js.map +1 -0
- package/dist/src/platforms/slack/token-extractor.d.ts +28 -0
- package/dist/src/platforms/slack/token-extractor.d.ts.map +1 -0
- package/dist/src/platforms/slack/token-extractor.js +401 -0
- package/dist/src/platforms/slack/token-extractor.js.map +1 -0
- package/dist/src/platforms/slack/types.d.ts +369 -0
- package/dist/src/platforms/slack/types.d.ts.map +1 -0
- package/dist/src/platforms/slack/types.js +92 -0
- package/dist/src/platforms/slack/types.js.map +1 -0
- package/dist/src/shared/utils/concurrency.d.ts +2 -0
- package/dist/src/shared/utils/concurrency.d.ts.map +1 -0
- package/dist/src/shared/utils/concurrency.js +14 -0
- package/dist/src/shared/utils/concurrency.js.map +1 -0
- package/dist/src/shared/utils/concurrency.test.d.ts +2 -0
- package/dist/src/shared/utils/concurrency.test.d.ts.map +1 -0
- package/dist/src/shared/utils/concurrency.test.js +39 -0
- package/dist/src/shared/utils/concurrency.test.js.map +1 -0
- package/dist/src/shared/utils/error-handler.d.ts +2 -0
- package/dist/src/shared/utils/error-handler.d.ts.map +1 -0
- package/dist/src/shared/utils/error-handler.js +5 -0
- package/dist/src/shared/utils/error-handler.js.map +1 -0
- package/dist/src/shared/utils/output.d.ts +2 -0
- package/dist/src/shared/utils/output.d.ts.map +1 -0
- package/dist/src/shared/utils/output.js +4 -0
- package/dist/src/shared/utils/output.js.map +1 -0
- package/dist/tests/cli.test.d.ts +2 -0
- package/dist/tests/cli.test.d.ts.map +1 -0
- package/dist/tests/cli.test.js +83 -0
- package/dist/tests/cli.test.js.map +1 -0
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/CURRENT +1 -0
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOCK +0 -0
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOG +3 -0
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/LOG.old +1 -0
- package/dist/tests/commands/.test-slack-data/Local Storage/leveldb/MANIFEST-000004 +0 -0
- package/dist/tests/commands/auth.test.d.ts +2 -0
- package/dist/tests/commands/auth.test.d.ts.map +1 -0
- package/dist/tests/commands/auth.test.js +304 -0
- package/dist/tests/commands/auth.test.js.map +1 -0
- package/dist/tests/commands/channel.test.d.ts +2 -0
- package/dist/tests/commands/channel.test.d.ts.map +1 -0
- package/dist/tests/commands/channel.test.js +166 -0
- package/dist/tests/commands/channel.test.js.map +1 -0
- package/dist/tests/commands/file.test.d.ts +2 -0
- package/dist/tests/commands/file.test.d.ts.map +1 -0
- package/dist/tests/commands/file.test.js +175 -0
- package/dist/tests/commands/file.test.js.map +1 -0
- package/dist/tests/commands/message.test.d.ts +2 -0
- package/dist/tests/commands/message.test.d.ts.map +1 -0
- package/dist/tests/commands/message.test.js +293 -0
- package/dist/tests/commands/message.test.js.map +1 -0
- package/dist/tests/commands/reaction.test.d.ts +2 -0
- package/dist/tests/commands/reaction.test.d.ts.map +1 -0
- package/dist/tests/commands/reaction.test.js +84 -0
- package/dist/tests/commands/reaction.test.js.map +1 -0
- package/dist/tests/commands/snapshot.test.d.ts +2 -0
- package/dist/tests/commands/snapshot.test.d.ts.map +1 -0
- package/dist/tests/commands/snapshot.test.js +280 -0
- package/dist/tests/commands/snapshot.test.js.map +1 -0
- package/dist/tests/commands/user.test.d.ts +2 -0
- package/dist/tests/commands/user.test.d.ts.map +1 -0
- package/dist/tests/commands/user.test.js +117 -0
- package/dist/tests/commands/user.test.js.map +1 -0
- package/dist/tests/commands/workspace.test.d.ts +2 -0
- package/dist/tests/commands/workspace.test.d.ts.map +1 -0
- package/dist/tests/commands/workspace.test.js +453 -0
- package/dist/tests/commands/workspace.test.js.map +1 -0
- package/dist/tests/credential-manager.test.d.ts +2 -0
- package/dist/tests/credential-manager.test.d.ts.map +1 -0
- package/dist/tests/credential-manager.test.js +199 -0
- package/dist/tests/credential-manager.test.js.map +1 -0
- package/dist/tests/slack-client.test.d.ts +2 -0
- package/dist/tests/slack-client.test.d.ts.map +1 -0
- package/dist/tests/slack-client.test.js +741 -0
- package/dist/tests/slack-client.test.js.map +1 -0
- package/dist/tests/types.test.d.ts +2 -0
- package/dist/tests/types.test.d.ts.map +1 -0
- package/dist/tests/types.test.js +215 -0
- package/dist/tests/types.test.js.map +1 -0
- package/dist/types/index.d.ts +369 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +92 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/error-handler.d.ts +2 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +5 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/output.d.ts +2 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +4 -0
- package/dist/utils/output.js.map +1 -0
- package/docs/discord.md +182 -0
- package/docs/slack.md +160 -0
- package/package.json +37 -0
- package/skills/agent-discord/SKILL.md +273 -0
- package/skills/agent-discord/references/authentication.md +294 -0
- package/skills/agent-discord/references/common-patterns.md +455 -0
- package/skills/agent-discord/templates/guild-summary.sh +167 -0
- package/skills/agent-discord/templates/monitor-channel.sh +180 -0
- package/skills/agent-discord/templates/post-message.sh +173 -0
- package/skills/agent-slack/SKILL.md +268 -0
- package/skills/agent-slack/references/authentication.md +332 -0
- package/skills/agent-slack/references/common-patterns.md +527 -0
- package/skills/agent-slack/templates/monitor-channel.sh +186 -0
- package/skills/agent-slack/templates/post-message.sh +130 -0
- package/skills/agent-slack/templates/workspace-summary.sh +149 -0
- package/src/cli.ts +29 -0
- package/src/platforms/discord/cli.ts +36 -0
- package/src/platforms/discord/client.test.ts +456 -0
- package/src/platforms/discord/client.ts +281 -0
- package/src/platforms/discord/commands/auth.test.ts +72 -0
- package/src/platforms/discord/commands/auth.ts +206 -0
- package/src/platforms/discord/commands/channel.test.ts +153 -0
- package/src/platforms/discord/commands/channel.ts +127 -0
- package/src/platforms/discord/commands/file.test.ts +98 -0
- package/src/platforms/discord/commands/file.ts +134 -0
- package/src/platforms/discord/commands/guild.test.ts +117 -0
- package/src/platforms/discord/commands/guild.ts +129 -0
- package/src/platforms/discord/commands/index.ts +8 -0
- package/src/platforms/discord/commands/message.test.ts +107 -0
- package/src/platforms/discord/commands/message.ts +182 -0
- package/src/platforms/discord/commands/reaction.test.ts +123 -0
- package/src/platforms/discord/commands/reaction.ts +156 -0
- package/src/platforms/discord/commands/snapshot.test.ts +29 -0
- package/src/platforms/discord/commands/snapshot.ts +104 -0
- package/src/platforms/discord/commands/user.test.ts +115 -0
- package/src/platforms/discord/commands/user.ts +124 -0
- package/src/platforms/discord/credential-manager.test.ts +173 -0
- package/src/platforms/discord/credential-manager.ts +95 -0
- package/src/platforms/discord/token-extractor.test.ts +918 -0
- package/src/platforms/discord/token-extractor.ts +549 -0
- package/src/platforms/discord/types.test.ts +245 -0
- package/src/platforms/discord/types.ts +158 -0
- package/src/platforms/slack/cli.ts +36 -0
- package/src/platforms/slack/client.ts +466 -0
- package/src/platforms/slack/commands/auth.ts +211 -0
- package/src/platforms/slack/commands/channel.ts +158 -0
- package/src/platforms/slack/commands/file.ts +153 -0
- package/src/platforms/slack/commands/index.ts +8 -0
- package/src/platforms/slack/commands/message.ts +369 -0
- package/src/platforms/slack/commands/reaction.ts +166 -0
- package/src/platforms/slack/commands/snapshot.ts +114 -0
- package/src/platforms/slack/commands/user.ts +110 -0
- package/src/platforms/slack/commands/workspace.ts +111 -0
- package/src/platforms/slack/credential-manager.ts +74 -0
- package/src/platforms/slack/index.ts +2 -0
- package/src/platforms/slack/token-extractor.ts +496 -0
- package/src/platforms/slack/types.ts +193 -0
- package/src/shared/utils/concurrency.test.ts +53 -0
- package/src/shared/utils/concurrency.ts +20 -0
- package/src/shared/utils/error-handler.ts +4 -0
- package/src/shared/utils/output.ts +3 -0
- package/tests/cli.test.ts +94 -0
- package/tests/commands/auth.test.ts +383 -0
- package/tests/commands/channel.test.ts +185 -0
- package/tests/commands/file.test.ts +204 -0
- package/tests/commands/message.test.ts +344 -0
- package/tests/commands/reaction.test.ts +101 -0
- package/tests/commands/snapshot.test.ts +308 -0
- package/tests/commands/user.test.ts +138 -0
- package/tests/commands/workspace.test.ts +528 -0
- package/tests/credential-manager.test.ts +241 -0
- package/tests/slack-client.test.ts +916 -0
- package/tests/types.test.ts +241 -0
- package/tsconfig.json +36 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { handleError } from '../../../shared/utils/error-handler'
|
|
3
|
+
import { formatOutput } from '../../../shared/utils/output'
|
|
4
|
+
import { SlackClient } from '../client'
|
|
5
|
+
import { CredentialManager } from '../credential-manager'
|
|
6
|
+
|
|
7
|
+
async function addAction(
|
|
8
|
+
channel: string,
|
|
9
|
+
ts: string,
|
|
10
|
+
emoji: string,
|
|
11
|
+
options: { pretty?: boolean }
|
|
12
|
+
): Promise<void> {
|
|
13
|
+
try {
|
|
14
|
+
const credManager = new CredentialManager()
|
|
15
|
+
const ws = await credManager.getWorkspace()
|
|
16
|
+
|
|
17
|
+
if (!ws) {
|
|
18
|
+
console.log(
|
|
19
|
+
formatOutput(
|
|
20
|
+
{ error: 'No workspace configured. Run "auth extract" first.' },
|
|
21
|
+
options.pretty
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
process.exit(1)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const client = new SlackClient(ws.token, ws.cookie)
|
|
28
|
+
await client.addReaction(channel, ts, emoji)
|
|
29
|
+
|
|
30
|
+
console.log(
|
|
31
|
+
formatOutput(
|
|
32
|
+
{
|
|
33
|
+
success: true,
|
|
34
|
+
channel,
|
|
35
|
+
ts,
|
|
36
|
+
emoji,
|
|
37
|
+
},
|
|
38
|
+
options.pretty
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
} catch (error) {
|
|
42
|
+
handleError(error as Error)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function removeAction(
|
|
47
|
+
channel: string,
|
|
48
|
+
ts: string,
|
|
49
|
+
emoji: string,
|
|
50
|
+
options: { pretty?: boolean }
|
|
51
|
+
): Promise<void> {
|
|
52
|
+
try {
|
|
53
|
+
const credManager = new CredentialManager()
|
|
54
|
+
const ws = await credManager.getWorkspace()
|
|
55
|
+
|
|
56
|
+
if (!ws) {
|
|
57
|
+
console.log(
|
|
58
|
+
formatOutput(
|
|
59
|
+
{ error: 'No workspace configured. Run "auth extract" first.' },
|
|
60
|
+
options.pretty
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const client = new SlackClient(ws.token, ws.cookie)
|
|
67
|
+
await client.removeReaction(channel, ts, emoji)
|
|
68
|
+
|
|
69
|
+
console.log(
|
|
70
|
+
formatOutput(
|
|
71
|
+
{
|
|
72
|
+
success: true,
|
|
73
|
+
channel,
|
|
74
|
+
ts,
|
|
75
|
+
emoji,
|
|
76
|
+
},
|
|
77
|
+
options.pretty
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
} catch (error) {
|
|
81
|
+
handleError(error as Error)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function listAction(
|
|
86
|
+
channel: string,
|
|
87
|
+
ts: string,
|
|
88
|
+
options: { pretty?: boolean }
|
|
89
|
+
): Promise<void> {
|
|
90
|
+
try {
|
|
91
|
+
const credManager = new CredentialManager()
|
|
92
|
+
const ws = await credManager.getWorkspace()
|
|
93
|
+
|
|
94
|
+
if (!ws) {
|
|
95
|
+
console.log(
|
|
96
|
+
formatOutput(
|
|
97
|
+
{ error: 'No workspace configured. Run "auth extract" first.' },
|
|
98
|
+
options.pretty
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
process.exit(1)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const client = new SlackClient(ws.token, ws.cookie)
|
|
105
|
+
const messages = await client.getMessages(channel, 1)
|
|
106
|
+
const message = messages.find((m) => m.ts === ts)
|
|
107
|
+
|
|
108
|
+
if (!message) {
|
|
109
|
+
console.log(
|
|
110
|
+
formatOutput(
|
|
111
|
+
{
|
|
112
|
+
error: 'Message not found',
|
|
113
|
+
channel,
|
|
114
|
+
ts,
|
|
115
|
+
},
|
|
116
|
+
options.pretty
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
process.exit(1)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const reactions = (message as any).reactions || []
|
|
123
|
+
|
|
124
|
+
console.log(
|
|
125
|
+
formatOutput(
|
|
126
|
+
{
|
|
127
|
+
channel,
|
|
128
|
+
ts,
|
|
129
|
+
reactions,
|
|
130
|
+
},
|
|
131
|
+
options.pretty
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
} catch (error) {
|
|
135
|
+
handleError(error as Error)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export const reactionCommand = new Command('reaction')
|
|
140
|
+
.description('Reaction commands')
|
|
141
|
+
.addCommand(
|
|
142
|
+
new Command('add')
|
|
143
|
+
.description('Add emoji reaction to message')
|
|
144
|
+
.argument('<channel>', 'Channel ID or name')
|
|
145
|
+
.argument('<ts>', 'Message timestamp')
|
|
146
|
+
.argument('<emoji>', 'Emoji name (without colons)')
|
|
147
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
148
|
+
.action(addAction)
|
|
149
|
+
)
|
|
150
|
+
.addCommand(
|
|
151
|
+
new Command('remove')
|
|
152
|
+
.description('Remove emoji reaction from message')
|
|
153
|
+
.argument('<channel>', 'Channel ID or name')
|
|
154
|
+
.argument('<ts>', 'Message timestamp')
|
|
155
|
+
.argument('<emoji>', 'Emoji name (without colons)')
|
|
156
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
157
|
+
.action(removeAction)
|
|
158
|
+
)
|
|
159
|
+
.addCommand(
|
|
160
|
+
new Command('list')
|
|
161
|
+
.description('List reactions on a message')
|
|
162
|
+
.argument('<channel>', 'Channel ID or name')
|
|
163
|
+
.argument('<ts>', 'Message timestamp')
|
|
164
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
165
|
+
.action(listAction)
|
|
166
|
+
)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { parallelMap } from '../../../shared/utils/concurrency'
|
|
3
|
+
import { handleError } from '../../../shared/utils/error-handler'
|
|
4
|
+
import { formatOutput } from '../../../shared/utils/output'
|
|
5
|
+
import { SlackClient } from '../client'
|
|
6
|
+
import { CredentialManager } from '../credential-manager'
|
|
7
|
+
import type { SlackChannel } from '../types'
|
|
8
|
+
|
|
9
|
+
async function snapshotAction(options: {
|
|
10
|
+
channelsOnly?: boolean
|
|
11
|
+
usersOnly?: boolean
|
|
12
|
+
limit?: number
|
|
13
|
+
pretty?: boolean
|
|
14
|
+
}): Promise<void> {
|
|
15
|
+
try {
|
|
16
|
+
const credManager = new CredentialManager()
|
|
17
|
+
const workspace = await credManager.getWorkspace()
|
|
18
|
+
|
|
19
|
+
if (!workspace) {
|
|
20
|
+
console.log(
|
|
21
|
+
formatOutput(
|
|
22
|
+
{ error: 'No current workspace set. Run "auth extract" first.' },
|
|
23
|
+
options.pretty
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const client = new SlackClient(workspace.token, workspace.cookie)
|
|
30
|
+
|
|
31
|
+
const auth = await client.testAuth()
|
|
32
|
+
const messageLimit = options.limit || 20
|
|
33
|
+
|
|
34
|
+
const snapshot: Record<string, any> = {
|
|
35
|
+
workspace: {
|
|
36
|
+
id: auth.team_id,
|
|
37
|
+
name: auth.team,
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!options.usersOnly) {
|
|
42
|
+
const channels = await client.listChannels()
|
|
43
|
+
|
|
44
|
+
snapshot.channels = channels.map((ch) => ({
|
|
45
|
+
id: ch.id,
|
|
46
|
+
name: ch.name,
|
|
47
|
+
is_private: ch.is_private,
|
|
48
|
+
is_archived: ch.is_archived,
|
|
49
|
+
created: ch.created,
|
|
50
|
+
topic: ch.topic?.value,
|
|
51
|
+
purpose: ch.purpose?.value,
|
|
52
|
+
}))
|
|
53
|
+
|
|
54
|
+
if (!options.channelsOnly) {
|
|
55
|
+
const activeChannels = channels.filter((ch) => !ch.is_archived)
|
|
56
|
+
|
|
57
|
+
const channelMessages = await parallelMap(
|
|
58
|
+
activeChannels,
|
|
59
|
+
async (channel: SlackChannel) => {
|
|
60
|
+
const messages = await client.getMessages(channel.id, messageLimit)
|
|
61
|
+
return messages.map((msg) => ({
|
|
62
|
+
...msg,
|
|
63
|
+
channel_id: channel.id,
|
|
64
|
+
channel_name: channel.name,
|
|
65
|
+
}))
|
|
66
|
+
},
|
|
67
|
+
5
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
snapshot.recent_messages = channelMessages.flat().map((msg) => ({
|
|
71
|
+
channel_id: msg.channel_id,
|
|
72
|
+
channel_name: msg.channel_name,
|
|
73
|
+
ts: msg.ts,
|
|
74
|
+
text: msg.text,
|
|
75
|
+
user: msg.user,
|
|
76
|
+
username: msg.username,
|
|
77
|
+
thread_ts: msg.thread_ts,
|
|
78
|
+
}))
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!options.channelsOnly) {
|
|
83
|
+
const users = await client.listUsers()
|
|
84
|
+
|
|
85
|
+
snapshot.users = users.map((u) => ({
|
|
86
|
+
id: u.id,
|
|
87
|
+
name: u.name,
|
|
88
|
+
real_name: u.real_name,
|
|
89
|
+
is_admin: u.is_admin,
|
|
90
|
+
is_bot: u.is_bot,
|
|
91
|
+
profile: u.profile,
|
|
92
|
+
}))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
console.log(formatOutput(snapshot, options.pretty))
|
|
96
|
+
} catch (error) {
|
|
97
|
+
handleError(error as Error)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const snapshotCommand = new Command()
|
|
102
|
+
.name('snapshot')
|
|
103
|
+
.description('Get comprehensive workspace state for AI agents')
|
|
104
|
+
.option('--channels-only', 'Include only channels (exclude messages and users)')
|
|
105
|
+
.option('--users-only', 'Include only users (exclude channels and messages)')
|
|
106
|
+
.option('--limit <n>', 'Number of recent messages per channel (default: 20)', '20')
|
|
107
|
+
.action(async (options) => {
|
|
108
|
+
await snapshotAction({
|
|
109
|
+
channelsOnly: options.channelsOnly,
|
|
110
|
+
usersOnly: options.usersOnly,
|
|
111
|
+
limit: parseInt(options.limit, 10),
|
|
112
|
+
pretty: options.pretty,
|
|
113
|
+
})
|
|
114
|
+
})
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { handleError } from '../../../shared/utils/error-handler'
|
|
3
|
+
import { formatOutput } from '../../../shared/utils/output'
|
|
4
|
+
import { SlackClient } from '../client'
|
|
5
|
+
import { CredentialManager } from '../credential-manager'
|
|
6
|
+
|
|
7
|
+
async function getClient(pretty?: boolean): Promise<SlackClient | null> {
|
|
8
|
+
const credManager = new CredentialManager()
|
|
9
|
+
const workspace = await credManager.getWorkspace()
|
|
10
|
+
|
|
11
|
+
if (!workspace) {
|
|
12
|
+
console.log(
|
|
13
|
+
formatOutput({ error: 'No current workspace set. Run "auth extract" first.' }, pretty)
|
|
14
|
+
)
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return new SlackClient(workspace.token, workspace.cookie)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const userCommand = new Command('user')
|
|
22
|
+
.description('user commands')
|
|
23
|
+
.addCommand(
|
|
24
|
+
new Command('list')
|
|
25
|
+
.description('list workspace users')
|
|
26
|
+
.option('--include-bots', 'include bot users')
|
|
27
|
+
.option('--pretty', 'pretty-print JSON output')
|
|
28
|
+
.action(async (options) => {
|
|
29
|
+
try {
|
|
30
|
+
const client = await getClient(options.pretty)
|
|
31
|
+
if (!client) return process.exit(1)
|
|
32
|
+
|
|
33
|
+
const users = await client.listUsers()
|
|
34
|
+
|
|
35
|
+
const filtered = options.includeBots ? users : users.filter((u) => !u.is_bot)
|
|
36
|
+
|
|
37
|
+
const output = filtered.map((user) => ({
|
|
38
|
+
id: user.id,
|
|
39
|
+
name: user.name,
|
|
40
|
+
real_name: user.real_name,
|
|
41
|
+
is_admin: user.is_admin,
|
|
42
|
+
is_owner: user.is_owner,
|
|
43
|
+
is_bot: user.is_bot,
|
|
44
|
+
is_app_user: user.is_app_user,
|
|
45
|
+
profile: user.profile,
|
|
46
|
+
}))
|
|
47
|
+
|
|
48
|
+
console.log(formatOutput(output, options.pretty))
|
|
49
|
+
} catch (error) {
|
|
50
|
+
handleError(error as Error)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
)
|
|
54
|
+
.addCommand(
|
|
55
|
+
new Command('info')
|
|
56
|
+
.description('show user details')
|
|
57
|
+
.argument('<user>', 'user ID or username')
|
|
58
|
+
.option('--pretty', 'pretty-print JSON output')
|
|
59
|
+
.action(async (userArg, options) => {
|
|
60
|
+
try {
|
|
61
|
+
const client = await getClient(options.pretty)
|
|
62
|
+
if (!client) return process.exit(1)
|
|
63
|
+
|
|
64
|
+
const user = await client.getUser(userArg)
|
|
65
|
+
|
|
66
|
+
const output = {
|
|
67
|
+
id: user.id,
|
|
68
|
+
name: user.name,
|
|
69
|
+
real_name: user.real_name,
|
|
70
|
+
is_admin: user.is_admin,
|
|
71
|
+
is_owner: user.is_owner,
|
|
72
|
+
is_bot: user.is_bot,
|
|
73
|
+
is_app_user: user.is_app_user,
|
|
74
|
+
profile: user.profile,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log(formatOutput(output, options.pretty))
|
|
78
|
+
} catch (error) {
|
|
79
|
+
handleError(error as Error)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
)
|
|
83
|
+
.addCommand(
|
|
84
|
+
new Command('me')
|
|
85
|
+
.description('show current authenticated user')
|
|
86
|
+
.option('--pretty', 'pretty-print JSON output')
|
|
87
|
+
.action(async (options) => {
|
|
88
|
+
try {
|
|
89
|
+
const client = await getClient(options.pretty)
|
|
90
|
+
if (!client) return process.exit(1)
|
|
91
|
+
const authInfo = await client.testAuth()
|
|
92
|
+
const user = await client.getUser(authInfo.user_id)
|
|
93
|
+
|
|
94
|
+
const output = {
|
|
95
|
+
id: user.id,
|
|
96
|
+
name: user.name,
|
|
97
|
+
real_name: user.real_name,
|
|
98
|
+
is_admin: user.is_admin,
|
|
99
|
+
is_owner: user.is_owner,
|
|
100
|
+
is_bot: user.is_bot,
|
|
101
|
+
is_app_user: user.is_app_user,
|
|
102
|
+
profile: user.profile,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log(formatOutput(output, options.pretty))
|
|
106
|
+
} catch (error) {
|
|
107
|
+
handleError(error as Error)
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { handleError } from '../../../shared/utils/error-handler'
|
|
3
|
+
import { formatOutput } from '../../../shared/utils/output'
|
|
4
|
+
import { CredentialManager } from '../credential-manager'
|
|
5
|
+
|
|
6
|
+
async function listAction(options: { pretty?: boolean }): Promise<void> {
|
|
7
|
+
try {
|
|
8
|
+
const credManager = new CredentialManager()
|
|
9
|
+
const config = await credManager.load()
|
|
10
|
+
const workspaces = Object.values(config.workspaces)
|
|
11
|
+
|
|
12
|
+
const output = workspaces.map((ws) => ({
|
|
13
|
+
id: ws.workspace_id,
|
|
14
|
+
name: ws.workspace_name,
|
|
15
|
+
current: ws.workspace_id === config.current_workspace,
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
console.log(formatOutput(output, options.pretty))
|
|
19
|
+
} catch (error) {
|
|
20
|
+
handleError(error as Error)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function switchAction(id: string, options: { pretty?: boolean }): Promise<void> {
|
|
25
|
+
try {
|
|
26
|
+
const credManager = new CredentialManager()
|
|
27
|
+
const config = await credManager.load()
|
|
28
|
+
|
|
29
|
+
if (!config.workspaces[id]) {
|
|
30
|
+
console.log(formatOutput({ error: `Workspace not found: ${id}` }, options.pretty))
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
await credManager.setCurrentWorkspace(id)
|
|
35
|
+
console.log(formatOutput({ current: id }, options.pretty))
|
|
36
|
+
} catch (error) {
|
|
37
|
+
handleError(error as Error)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function currentAction(options: { pretty?: boolean }): Promise<void> {
|
|
42
|
+
try {
|
|
43
|
+
const credManager = new CredentialManager()
|
|
44
|
+
const workspace = await credManager.getWorkspace()
|
|
45
|
+
|
|
46
|
+
if (!workspace) {
|
|
47
|
+
console.log(
|
|
48
|
+
formatOutput(
|
|
49
|
+
{ error: 'No current workspace set. Run "auth extract" first.' },
|
|
50
|
+
options.pretty
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
process.exit(1)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const output = {
|
|
57
|
+
workspace_id: workspace.workspace_id,
|
|
58
|
+
workspace_name: workspace.workspace_name,
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
console.log(formatOutput(output, options.pretty))
|
|
62
|
+
} catch (error) {
|
|
63
|
+
handleError(error as Error)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function removeAction(id: string, options: { pretty?: boolean }): Promise<void> {
|
|
68
|
+
try {
|
|
69
|
+
const credManager = new CredentialManager()
|
|
70
|
+
const config = await credManager.load()
|
|
71
|
+
|
|
72
|
+
if (!config.workspaces[id]) {
|
|
73
|
+
console.log(formatOutput({ error: `Workspace not found: ${id}` }, options.pretty))
|
|
74
|
+
process.exit(1)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
await credManager.removeWorkspace(id)
|
|
78
|
+
console.log(formatOutput({ removed: id }, options.pretty))
|
|
79
|
+
} catch (error) {
|
|
80
|
+
handleError(error as Error)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const workspaceCommand = new Command('workspace')
|
|
85
|
+
.description('Workspace management commands')
|
|
86
|
+
.addCommand(
|
|
87
|
+
new Command('list')
|
|
88
|
+
.description('List all workspaces')
|
|
89
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
90
|
+
.action(listAction)
|
|
91
|
+
)
|
|
92
|
+
.addCommand(
|
|
93
|
+
new Command('switch')
|
|
94
|
+
.description('Switch to workspace')
|
|
95
|
+
.argument('<id>', 'Workspace ID')
|
|
96
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
97
|
+
.action(switchAction)
|
|
98
|
+
)
|
|
99
|
+
.addCommand(
|
|
100
|
+
new Command('current')
|
|
101
|
+
.description('Show current workspace')
|
|
102
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
103
|
+
.action(currentAction)
|
|
104
|
+
)
|
|
105
|
+
.addCommand(
|
|
106
|
+
new Command('remove')
|
|
107
|
+
.description('Remove workspace')
|
|
108
|
+
.argument('<id>', 'Workspace ID')
|
|
109
|
+
.option('--pretty', 'Pretty print JSON output')
|
|
110
|
+
.action(removeAction)
|
|
111
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { mkdir } from 'node:fs/promises'
|
|
3
|
+
import { homedir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import type { Config, WorkspaceCredentials } from './types'
|
|
6
|
+
|
|
7
|
+
export class CredentialManager {
|
|
8
|
+
private configDir: string
|
|
9
|
+
private credentialsPath: string
|
|
10
|
+
|
|
11
|
+
constructor(configDir?: string) {
|
|
12
|
+
this.configDir = configDir ?? join(homedir(), '.config', 'agent-messenger')
|
|
13
|
+
this.credentialsPath = join(this.configDir, 'slack-credentials.json')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async load(): Promise<Config> {
|
|
17
|
+
if (!existsSync(this.credentialsPath)) {
|
|
18
|
+
return {
|
|
19
|
+
current_workspace: null,
|
|
20
|
+
workspaces: {},
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const file = Bun.file(this.credentialsPath)
|
|
25
|
+
const content = await file.text()
|
|
26
|
+
return JSON.parse(content) as Config
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async save(config: Config): Promise<void> {
|
|
30
|
+
await mkdir(this.configDir, { recursive: true })
|
|
31
|
+
|
|
32
|
+
const file = Bun.file(this.credentialsPath)
|
|
33
|
+
await Bun.write(file, JSON.stringify(config, null, 2))
|
|
34
|
+
|
|
35
|
+
await Bun.spawn(['chmod', '0600', this.credentialsPath]).exited
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async getWorkspace(id?: string): Promise<WorkspaceCredentials | null> {
|
|
39
|
+
const config = await this.load()
|
|
40
|
+
|
|
41
|
+
if (id) {
|
|
42
|
+
return config.workspaces[id] ?? null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!config.current_workspace) {
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return config.workspaces[config.current_workspace] ?? null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async setWorkspace(creds: WorkspaceCredentials): Promise<void> {
|
|
53
|
+
const config = await this.load()
|
|
54
|
+
config.workspaces[creds.workspace_id] = creds
|
|
55
|
+
await this.save(config)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async removeWorkspace(id: string): Promise<void> {
|
|
59
|
+
const config = await this.load()
|
|
60
|
+
delete config.workspaces[id]
|
|
61
|
+
|
|
62
|
+
if (config.current_workspace === id) {
|
|
63
|
+
config.current_workspace = null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
await this.save(config)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async setCurrentWorkspace(id: string): Promise<void> {
|
|
70
|
+
const config = await this.load()
|
|
71
|
+
config.current_workspace = id
|
|
72
|
+
await this.save(config)
|
|
73
|
+
}
|
|
74
|
+
}
|