@aiwg/cli 2026.10.14 → 2026.10.16

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 (210) hide show
  1. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.core.md +13 -0
  2. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +118 -0
  3. package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
  4. package/dist/src/artifacts/citation-parser.js +7 -6
  5. package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
  6. package/dist/src/artifacts/corpus-tools/cli.js +37 -0
  7. package/dist/src/artifacts/corpus-tools/discovery-log.js +27 -25
  8. package/dist/src/artifacts/corpus-tools/expand-cli.js +90 -0
  9. package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
  10. package/dist/src/artifacts/corpus-tools/expand-queue.js +41 -0
  11. package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
  12. package/dist/src/artifacts/corpus-tools/expand-state.js +56 -0
  13. package/dist/src/artifacts/corpus-tools/expand.js +124 -0
  14. package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
  15. package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
  16. package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
  17. package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
  18. package/dist/src/artifacts/corpus-tools/resolve-cli.js +99 -0
  19. package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
  20. package/dist/src/artifacts/corpus-tools/resolve.js +119 -0
  21. package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
  22. package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
  23. package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
  24. package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
  25. package/dist/src/artifacts/graph-query.js +5 -3
  26. package/dist/src/artifacts/hybrid-query.js +11 -2
  27. package/dist/src/artifacts/index-refresh.js +2 -0
  28. package/dist/src/cli/handlers/daemon.js +17 -1
  29. package/dist/src/cli/handlers/doctor-args.js +45 -0
  30. package/dist/src/cli/handlers/doctor-help.js +8 -3
  31. package/dist/src/cli/handlers/index.js +2 -2
  32. package/dist/src/cli/handlers/models-resource-sample.js +10 -0
  33. package/dist/src/cli/handlers/models.js +3 -2
  34. package/dist/src/cli/handlers/regenerate.js +8 -16
  35. package/dist/src/cli/handlers/sessions.js +7 -7
  36. package/dist/src/cli/handlers/subcommands.js +8 -0
  37. package/dist/src/cli/handlers/update.js +157 -0
  38. package/dist/src/cli/handlers/use.js +14 -4
  39. package/dist/src/cli/handlers/utilities.js +3 -586
  40. package/dist/src/cli/handlers/utility-doctor.js +412 -0
  41. package/dist/src/cli/services/deployment-verification.js +0 -1
  42. package/dist/src/config/aiwg-config.js +2 -1
  43. package/dist/src/config/authorization-cli.js +7 -3
  44. package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
  45. package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
  46. package/dist/src/config/framework-aliases.js +12 -0
  47. package/dist/src/config/host-resource-report.d.mts +19 -0
  48. package/dist/src/config/host-resource-report.mjs +80 -0
  49. package/dist/src/config/host-resource-runtime.d.mts +34 -0
  50. package/dist/src/config/host-resource-runtime.mjs +293 -0
  51. package/dist/src/config/installed-selection.js +22 -0
  52. package/dist/src/config/worker-context.js +33 -4
  53. package/dist/src/config/worker-invocation-marker.d.mts +1 -0
  54. package/dist/src/config/worker-invocation-marker.mjs +2 -0
  55. package/dist/src/decision/heldout/access.js +74 -0
  56. package/dist/src/decision/heldout/calibration.js +1 -0
  57. package/dist/src/decision/heldout/collector.js +9 -2
  58. package/dist/src/effects/verifiers/file.js +22 -5
  59. package/dist/src/extensions/claude-attribution.js +82 -0
  60. package/dist/src/extensions/claude-hooks-installer.js +115 -69
  61. package/dist/src/extensions/commands/daemon.js +109 -0
  62. package/dist/src/extensions/commands/definitions.js +5 -89
  63. package/dist/src/features/catalog.js +1 -1
  64. package/dist/src/gates/evaluate.js +2 -2
  65. package/dist/src/gates/heldout.js +52 -0
  66. package/dist/src/gates/index.js +2 -1
  67. package/dist/src/lint/check-patterns.js +163 -0
  68. package/dist/src/lint/checks.js +268 -0
  69. package/dist/src/lint/reference-resolution.js +54 -0
  70. package/dist/src/lint/runner.js +3 -465
  71. package/dist/src/mcp/helpers.mjs +11 -1
  72. package/dist/src/memory/project-registry.js +44 -4
  73. package/dist/src/models/worker-installation-store.mjs +228 -0
  74. package/dist/src/models/worker-installation.mjs +7 -162
  75. package/dist/src/models/worker-plan.js +36 -5
  76. package/dist/src/models/wrapper-deployment.js +25 -12
  77. package/dist/src/models/wrapper-enforcement.js +47 -7
  78. package/dist/src/network-analysis/research.js +2 -1
  79. package/dist/src/policy/hitl-check.js +14 -4
  80. package/dist/src/policy/hitl-consume.js +54 -0
  81. package/dist/src/policy/hitl-receipt.js +2 -0
  82. package/dist/src/policy/hitl.js +11 -3
  83. package/dist/src/providers/provider-context-contracts.js +162 -0
  84. package/dist/src/providers/provider-definition-schema.js +136 -0
  85. package/dist/src/providers/provider-definitions.js +8 -1298
  86. package/dist/src/providers/provider-seeds-1.js +360 -0
  87. package/dist/src/providers/provider-seeds-2.js +387 -0
  88. package/dist/src/providers/provider-seeds-3.js +262 -0
  89. package/dist/src/research/clients/arxiv.js +14 -34
  90. package/dist/src/research/clients/base.js +53 -26
  91. package/dist/src/research/clients/crossref.js +9 -1
  92. package/dist/src/research/clients/semantic-scholar.js +73 -44
  93. package/dist/src/research/identity.js +117 -0
  94. package/dist/src/research/index.js +1 -0
  95. package/dist/src/research/query-cli.js +3 -87
  96. package/dist/src/research/query-options.js +87 -0
  97. package/dist/src/research/reference-match.js +135 -0
  98. package/dist/src/research/services/acquisition.js +9 -7
  99. package/dist/src/research/services/citation.js +5 -2
  100. package/dist/src/research/types.js +2 -0
  101. package/dist/src/rules/core-startup.d.mts +2 -0
  102. package/dist/src/rules/core-startup.mjs +31 -0
  103. package/dist/src/serve/mission-conductor.js +48 -4
  104. package/dist/src/sessions/adapters/grok-build-native.js +23 -0
  105. package/dist/src/sessions/adapters/grok-build.js +14 -7
  106. package/dist/src/sessions/workspace-discovery.js +5 -5
  107. package/dist/src/smiths/context-pipeline/agents-md.js +34 -0
  108. package/dist/src/smiths/context-pipeline/aiwg-md.js +19 -46
  109. package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
  110. package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
  111. package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
  112. package/dist/src/smiths/context-pipeline/finalization.js +81 -51
  113. package/dist/src/smiths/context-pipeline/generator.js +49 -114
  114. package/dist/src/smiths/context-pipeline/managed-hook.js +11 -1
  115. package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
  116. package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
  117. package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
  118. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
  119. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
  120. package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
  121. package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
  122. package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
  123. package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
  124. package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
  125. package/package.json +13 -2
  126. package/schemas/decision/D29Study.v10.schema.json +65 -0
  127. package/tools/agents/deploy-agents.mjs +12 -123
  128. package/tools/agents/providers/antigravity.mjs +1 -1
  129. package/tools/agents/providers/claude-post-deploy.mjs +12 -1
  130. package/tools/agents/providers/context-write.mjs +16 -0
  131. package/tools/agents/providers/grok-build.mjs +8 -5
  132. package/tools/agents/providers/hermes-skill-lifecycle.mjs +144 -0
  133. package/tools/agents/providers/hermes-startup.mjs +209 -0
  134. package/tools/agents/providers/hermes.mjs +9 -359
  135. package/tools/agents/providers/model-wrapper.mjs +5 -1
  136. package/tools/agents/providers/muse.mjs +3 -3
  137. package/tools/agents/providers/pi.mjs +4 -2
  138. package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
  139. package/tools/agents/providers/rule-delivery.mjs +20 -1346
  140. package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
  141. package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
  142. package/tools/agents/providers/rule-deployment-state.mjs +300 -0
  143. package/tools/agents/providers/rule-presentation.mjs +13 -4
  144. package/tools/agents/providers/rule-projection.mjs +119 -0
  145. package/tools/agents/providers/rule-startup.mjs +70 -0
  146. package/tools/agents/providers/stale-artifact-prune.mjs +128 -0
  147. package/tools/agents/providers/warp.mjs +2 -2
  148. package/tools/agents/providers/windsurf.mjs +11 -57
  149. package/tools/daemon/README.md +511 -0
  150. package/tools/daemon/adapters/base-adapter.mjs +84 -0
  151. package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
  152. package/tools/daemon/agent-supervisor.mjs +299 -0
  153. package/tools/daemon/automation-engine.mjs +310 -0
  154. package/tools/daemon/autonomous-engine.mjs +346 -0
  155. package/tools/daemon/behavior-loader.mjs +316 -0
  156. package/tools/daemon/behavior.mjs +174 -0
  157. package/tools/daemon/concierge/intent-router.mjs +401 -0
  158. package/tools/daemon/concierge/orchestrator.mjs +272 -0
  159. package/tools/daemon/concierge/response-translator.mjs +462 -0
  160. package/tools/daemon/config.mjs +377 -0
  161. package/tools/daemon/cron-scheduler.mjs +178 -0
  162. package/tools/daemon/daemon-main.mjs +1169 -0
  163. package/tools/daemon/event-router.mjs +84 -0
  164. package/tools/daemon/file-watcher.mjs +383 -0
  165. package/tools/daemon/index.mjs +1181 -0
  166. package/tools/daemon/init-profile.mjs +124 -0
  167. package/tools/daemon/ipc-client.mjs +197 -0
  168. package/tools/daemon/ipc-ops-handlers.mjs +236 -0
  169. package/tools/daemon/ipc-server.mjs +275 -0
  170. package/tools/daemon/maintenance-owner.mjs +79 -0
  171. package/tools/daemon/memory-manager.mjs +386 -0
  172. package/tools/daemon/message-router.mjs +194 -0
  173. package/tools/daemon/provider-watcher.mjs +585 -0
  174. package/tools/daemon/pty-adapter.mjs +420 -0
  175. package/tools/daemon/repl-chat.mjs +359 -0
  176. package/tools/daemon/resource-bounds.mjs +88 -0
  177. package/tools/daemon/sandbox-transport.mjs +295 -0
  178. package/tools/daemon/scheduled-task-runner.mjs +535 -0
  179. package/tools/daemon/task-store.mjs +450 -0
  180. package/tools/daemon/tmux-manager.mjs +324 -0
  181. package/tools/daemon/update-policy.mjs +517 -0
  182. package/tools/daemon/web-server.mjs +399 -0
  183. package/tools/daemon/web-ui/index.html +585 -0
  184. package/tools/daemon/web-ui/styles.css +156 -0
  185. package/tools/docker/Dockerfile.daemon +35 -0
  186. package/tools/docker/container-manager.mjs +291 -0
  187. package/tools/messaging/adapter-registry.mjs +230 -0
  188. package/tools/messaging/adapters/base.mjs +326 -0
  189. package/tools/messaging/adapters/discord.mjs +462 -0
  190. package/tools/messaging/adapters/slack.mjs +402 -0
  191. package/tools/messaging/adapters/telegram.mjs +552 -0
  192. package/tools/messaging/chat-handler.mjs +297 -0
  193. package/tools/messaging/command-router.mjs +269 -0
  194. package/tools/messaging/event-bus.mjs +199 -0
  195. package/tools/messaging/index.mjs +456 -0
  196. package/tools/messaging/message-formatter.mjs +320 -0
  197. package/tools/messaging/room-manager.mjs +277 -0
  198. package/tools/messaging/types.mjs +94 -0
  199. package/tools/plugin/plugin-links.mjs +3 -0
  200. package/tools/providers/pi-bridge-policy.mjs +4 -0
  201. package/tools/ralph-external/daemon-supervisor.mjs +394 -0
  202. package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
  203. package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
  204. package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
  205. package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
  206. package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
  207. package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
  208. package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
  209. package/tools/ralph-external/session-launcher.mjs +7 -7
  210. package/tools/scripts/resource-preflight.mjs +3 -242
@@ -0,0 +1,402 @@
1
+ /**
2
+ * @file Slack adapter for AIWG messaging bot
3
+ * @implements BaseAdapter
4
+ */
5
+
6
+ import { BaseAdapter } from './base.mjs';
7
+
8
+ /**
9
+ * Slack adapter for AIWG messaging
10
+ *
11
+ * @extends BaseAdapter
12
+ * @example
13
+ * const slack = new SlackAdapter({
14
+ * webhookUrl: 'https://hooks.slack.com/services/...',
15
+ * botToken: 'xoxb-...',
16
+ * defaultChannel: '#aiwg-notifications'
17
+ * });
18
+ * await slack.initialize();
19
+ * await slack.send(message, '#channel');
20
+ */
21
+ export class SlackAdapter extends BaseAdapter {
22
+ /**
23
+ * Create a Slack adapter
24
+ *
25
+ * @param {Object} config - Slack configuration
26
+ * @param {string} [config.webhookUrl] - Slack webhook URL
27
+ * @param {string} [config.botToken] - Slack bot token for updates
28
+ * @param {string} [config.defaultChannel] - Default channel for messages
29
+ */
30
+ constructor(config = {}) {
31
+ super('slack');
32
+
33
+ this.webhookUrl = config.webhookUrl || process.env.AIWG_SLACK_WEBHOOK_URL;
34
+ this.botToken = config.botToken || process.env.AIWG_SLACK_BOT_TOKEN;
35
+ this._setSensitiveValues(this.webhookUrl, this.botToken);
36
+ this.defaultChannel = config.defaultChannel || '#aiwg-notifications';
37
+
38
+ /** @type {Map<string, Function>} */
39
+ this.commandHandlers = new Map();
40
+
41
+ /** @type {number} */
42
+ this.rateLimitRemaining = 100;
43
+
44
+ /** @type {number|null} */
45
+ this.rateLimitReset = null;
46
+ }
47
+
48
+ /**
49
+ * Initialize the Slack adapter
50
+ *
51
+ * @returns {Promise<void>}
52
+ * @throws {Error} If webhook URL is not configured
53
+ */
54
+ async initialize() {
55
+ if (!this.webhookUrl) {
56
+ throw new Error('Slack webhook URL not configured. Set AIWG_SLACK_WEBHOOK_URL environment variable or pass webhookUrl in config.');
57
+ }
58
+
59
+ // Validate webhook URL format
60
+ if (!this.webhookUrl.startsWith('https://hooks.slack.com/')) {
61
+ throw new Error('Invalid Slack webhook URL format.');
62
+ }
63
+
64
+ // Send test ping to verify connectivity
65
+ try {
66
+ const response = await fetch(this.webhookUrl, {
67
+ method: 'POST',
68
+ headers: {
69
+ 'Content-Type': 'application/json',
70
+ },
71
+ body: JSON.stringify({
72
+ text: 'AIWG Slack adapter initialized',
73
+ attachments: [{
74
+ color: '#36a64f',
75
+ text: 'Connection test successful',
76
+ footer: 'AIWG Messaging Bot',
77
+ ts: Math.floor(Date.now() / 1000),
78
+ }],
79
+ }),
80
+ });
81
+
82
+ if (!response.ok) {
83
+ const errorText = await response.text();
84
+ throw new Error(`Slack webhook test failed: ${response.status} ${errorText}`);
85
+ }
86
+
87
+ this._setConnected();
88
+ } catch (error) {
89
+ error = this._redactError(error);
90
+ this._recordError(error);
91
+ throw new Error(`Failed to initialize Slack adapter: ${error.message}`);
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Shutdown the Slack adapter
97
+ *
98
+ * @returns {Promise<void>}
99
+ */
100
+ async shutdown() {
101
+ this._setDisconnected();
102
+ }
103
+
104
+ /**
105
+ * Send a message to Slack
106
+ *
107
+ * @param {Object} message - AiwgMessage to send
108
+ * @param {string} [channel] - Target channel (overrides default)
109
+ * @returns {Promise<string>} Message ID (timestamp)
110
+ * @throws {Error} If send fails
111
+ */
112
+ async send(message, channel) {
113
+ if (!this.isConnected()) {
114
+ throw new Error('Slack adapter not connected. Call initialize() first.');
115
+ }
116
+
117
+ await this._checkRateLimit();
118
+
119
+ const slackMessage = this._convertToSlackFormat(message, channel);
120
+
121
+ try {
122
+ const response = await fetch(this.webhookUrl, {
123
+ method: 'POST',
124
+ headers: {
125
+ 'Content-Type': 'application/json',
126
+ },
127
+ body: JSON.stringify(slackMessage),
128
+ });
129
+
130
+ this._updateRateLimitInfo(response);
131
+
132
+ if (!response.ok) {
133
+ const errorText = await response.text();
134
+ throw new Error(`Slack API error: ${response.status} ${errorText}`);
135
+ }
136
+
137
+ const result = await response.text();
138
+ if (result !== 'ok') {
139
+ throw new Error(`Slack webhook returned: ${result}`);
140
+ }
141
+
142
+ this._recordSend();
143
+
144
+ // Slack webhooks don't return message IDs, so we generate one based on timestamp
145
+ const messageId = `slack_${Date.now()}`;
146
+ return messageId;
147
+ } catch (error) {
148
+ error = this._redactError(error);
149
+ this._recordError(error);
150
+ throw error;
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Update an existing Slack message
156
+ *
157
+ * @param {string} messageId - Message timestamp (ts) to update
158
+ * @param {Object} message - Updated AiwgMessage
159
+ * @returns {Promise<void>}
160
+ * @throws {Error} If bot token not configured or update fails
161
+ */
162
+ async update(messageId, message) {
163
+ if (!this.botToken) {
164
+ throw new Error('Slack bot token required for message updates. Set AIWG_SLACK_BOT_TOKEN environment variable.');
165
+ }
166
+
167
+ if (!this.isConnected()) {
168
+ throw new Error('Slack adapter not connected. Call initialize() first.');
169
+ }
170
+
171
+ await this._checkRateLimit();
172
+
173
+ // Extract channel and timestamp from messageId if in format "channel:ts"
174
+ let channel, ts;
175
+ if (messageId.includes(':')) {
176
+ [channel, ts] = messageId.split(':');
177
+ } else {
178
+ channel = this.defaultChannel;
179
+ ts = messageId;
180
+ }
181
+
182
+ const slackMessage = this._convertToSlackFormat(message, channel);
183
+
184
+ try {
185
+ const response = await fetch('https://slack.com/api/chat.update', {
186
+ method: 'POST',
187
+ headers: {
188
+ 'Content-Type': 'application/json',
189
+ 'Authorization': `Bearer ${this.botToken}`,
190
+ },
191
+ body: JSON.stringify({
192
+ channel,
193
+ ts,
194
+ text: slackMessage.text,
195
+ attachments: slackMessage.attachments,
196
+ }),
197
+ });
198
+
199
+ this._updateRateLimitInfo(response);
200
+
201
+ const result = await response.json();
202
+
203
+ if (!result.ok) {
204
+ throw new Error(`Slack API error: ${result.error}`);
205
+ }
206
+
207
+ this._recordSend();
208
+ } catch (error) {
209
+ error = this._redactError(error);
210
+ this._recordError(error);
211
+ throw error;
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Register a command handler
217
+ *
218
+ * @param {Function} handler - Function to handle commands: (command, args, context) => void
219
+ */
220
+ onCommand(handler) {
221
+ this.commandHandlers.set('default', handler);
222
+ }
223
+
224
+ /**
225
+ * Parse and dispatch a Slack slash command
226
+ *
227
+ * @param {Object} slackPayload - Slack slash command payload
228
+ * @returns {Promise<void>}
229
+ */
230
+ async handleSlashCommand(slackPayload) {
231
+ const { command, text, user_name, channel_name, channel_id, team_domain } = slackPayload;
232
+
233
+ this._recordReceive();
234
+
235
+ // Parse command and arguments
236
+ const commandName = command.replace(/^\//, '');
237
+ const args = text ? text.split(/\s+/) : [];
238
+
239
+ const context = {
240
+ platform: 'slack',
241
+ userId: user_name,
242
+ channelId: channel_id,
243
+ channelName: channel_name,
244
+ teamDomain: team_domain,
245
+ timestamp: new Date().toISOString(),
246
+ };
247
+
248
+ await this._dispatchCommand(commandName, args, context);
249
+ }
250
+
251
+ /**
252
+ * Convert AiwgMessage to Slack attachment format
253
+ *
254
+ * @private
255
+ * @param {Object} message - AiwgMessage
256
+ * @param {string} [channel] - Target channel
257
+ * @returns {Object} Slack message payload
258
+ */
259
+ _convertToSlackFormat(message, channel) {
260
+ const severityColors = {
261
+ info: '#36a64f',
262
+ warning: '#daa520',
263
+ critical: '#dc3545',
264
+ };
265
+
266
+ const color = severityColors[message.severity] || severityColors.info;
267
+
268
+ const attachment = {
269
+ color,
270
+ fallback: `${message.title}: ${message.body}`,
271
+ title: message.title,
272
+ text: message.body,
273
+ footer: `AIWG • ${message.project}`,
274
+ ts: Math.floor(new Date(message.timestamp).getTime() / 1000),
275
+ };
276
+
277
+ // Add fields if present
278
+ if (message.fields && message.fields.length > 0) {
279
+ attachment.fields = message.fields.map(field => ({
280
+ title: field.label,
281
+ value: field.value,
282
+ short: field.inline || false,
283
+ }));
284
+ }
285
+
286
+ // Add code block if present
287
+ if (message.codeBlock) {
288
+ attachment.text = `${attachment.text}\n\`\`\`\n${message.codeBlock}\n\`\`\``;
289
+ }
290
+
291
+ // Add link if present
292
+ if (message.linkUrl && message.linkText) {
293
+ attachment.text = `${attachment.text}\n<${message.linkUrl}|${message.linkText}>`;
294
+ }
295
+
296
+ // Add actions if present (Slack Block Kit actions)
297
+ if (message.actions && message.actions.length > 0) {
298
+ attachment.actions = message.actions.map(action => ({
299
+ type: 'button',
300
+ text: action.label,
301
+ value: action.id,
302
+ style: this._mapActionStyle(action.style),
303
+ url: action.command ? undefined : action.url,
304
+ }));
305
+ }
306
+
307
+ const payload = {
308
+ text: message.title,
309
+ attachments: [attachment],
310
+ };
311
+
312
+ // Set channel if provided
313
+ if (channel) {
314
+ payload.channel = channel;
315
+ }
316
+
317
+ // Set thread if provided
318
+ if (message.threadId) {
319
+ payload.thread_ts = message.threadId;
320
+ }
321
+
322
+ return payload;
323
+ }
324
+
325
+ /**
326
+ * Map AIWG action style to Slack button style
327
+ *
328
+ * @private
329
+ * @param {string} style - AIWG action style (primary, danger, default)
330
+ * @returns {string} Slack button style
331
+ */
332
+ _mapActionStyle(style) {
333
+ const styleMap = {
334
+ primary: 'primary',
335
+ danger: 'danger',
336
+ default: 'default',
337
+ };
338
+
339
+ return styleMap[style] || 'default';
340
+ }
341
+
342
+ /**
343
+ * Check rate limit and wait if necessary
344
+ *
345
+ * @private
346
+ * @returns {Promise<void>}
347
+ */
348
+ async _checkRateLimit() {
349
+ if (this.rateLimitRemaining <= 0 && this.rateLimitReset) {
350
+ const now = Date.now() / 1000;
351
+ if (now < this.rateLimitReset) {
352
+ const waitTime = (this.rateLimitReset - now) * 1000;
353
+ console.warn(`[Slack] Rate limit exceeded. Waiting ${Math.ceil(waitTime / 1000)}s...`);
354
+ await new Promise(resolve => setTimeout(resolve, waitTime));
355
+ }
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Update rate limit information from response headers
361
+ *
362
+ * @private
363
+ * @param {Response} response - Fetch response
364
+ */
365
+ _updateRateLimitInfo(response) {
366
+ const remaining = response.headers.get('X-Rate-Limit-Remaining');
367
+ const reset = response.headers.get('X-Rate-Limit-Reset');
368
+
369
+ if (remaining !== null) {
370
+ this.rateLimitRemaining = parseInt(remaining, 10);
371
+ }
372
+
373
+ if (reset !== null) {
374
+ this.rateLimitReset = parseInt(reset, 10);
375
+ }
376
+ }
377
+
378
+ /**
379
+ * Get adapter status including rate limit info
380
+ *
381
+ * @returns {Object} Status information
382
+ */
383
+ getStatus() {
384
+ const baseStatus = super.getStatus();
385
+
386
+ return {
387
+ ...baseStatus,
388
+ rateLimit: {
389
+ remaining: this.rateLimitRemaining,
390
+ resetAt: this.rateLimitReset ? new Date(this.rateLimitReset * 1000).toISOString() : null,
391
+ },
392
+ config: {
393
+ webhookConfigured: !!this.webhookUrl,
394
+ botTokenConfigured: !!this.botToken,
395
+ defaultChannel: this.defaultChannel,
396
+ },
397
+ };
398
+ }
399
+ }
400
+
401
+ // Export as default and named export
402
+ export default SlackAdapter;