@aiwg/cli 2026.10.15 → 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.
- package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
- package/dist/src/artifacts/citation-parser.js +7 -6
- package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
- package/dist/src/artifacts/corpus-tools/cli.js +8 -3
- package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
- package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
- package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
- package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
- package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
- package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
- package/dist/src/artifacts/corpus-tools/expand.js +16 -17
- package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
- package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
- package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
- package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
- package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
- package/dist/src/artifacts/corpus-tools/resolve.js +23 -9
- package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
- package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
- package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
- package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
- package/dist/src/artifacts/graph-query.js +5 -3
- package/dist/src/artifacts/hybrid-query.js +11 -2
- package/dist/src/artifacts/index-refresh.js +2 -0
- package/dist/src/cli/handlers/daemon.js +17 -1
- package/dist/src/cli/handlers/doctor-args.js +10 -5
- package/dist/src/cli/handlers/doctor-help.js +4 -1
- package/dist/src/cli/handlers/index.js +2 -2
- package/dist/src/cli/handlers/models-resource-sample.js +10 -0
- package/dist/src/cli/handlers/models.js +3 -2
- package/dist/src/cli/handlers/regenerate.js +8 -16
- package/dist/src/cli/handlers/sessions.js +7 -7
- package/dist/src/cli/handlers/subcommands.js +8 -0
- package/dist/src/cli/handlers/update.js +157 -0
- package/dist/src/cli/handlers/use.js +14 -4
- package/dist/src/cli/handlers/utilities.js +3 -560
- package/dist/src/cli/handlers/utility-doctor.js +412 -0
- package/dist/src/cli/services/deployment-verification.js +0 -1
- package/dist/src/config/aiwg-config.js +2 -1
- package/dist/src/config/authorization-cli.js +7 -3
- package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
- package/dist/src/config/dispatch-thresholds-runtime.mjs +17 -7
- package/dist/src/config/framework-aliases.js +12 -0
- package/dist/src/config/host-resource-report.d.mts +19 -0
- package/dist/src/config/host-resource-report.mjs +80 -0
- package/dist/src/config/host-resource-runtime.d.mts +34 -0
- package/dist/src/config/host-resource-runtime.mjs +293 -0
- package/dist/src/config/installed-selection.js +22 -0
- package/dist/src/config/worker-invocation-marker.d.mts +1 -0
- package/dist/src/config/worker-invocation-marker.mjs +2 -0
- package/dist/src/decision/heldout/access.js +74 -0
- package/dist/src/decision/heldout/calibration.js +1 -0
- package/dist/src/decision/heldout/collector.js +8 -1
- package/dist/src/effects/verifiers/file.js +22 -5
- package/dist/src/extensions/claude-attribution.js +82 -0
- package/dist/src/extensions/claude-hooks-installer.js +115 -69
- package/dist/src/extensions/commands/daemon.js +109 -0
- package/dist/src/extensions/commands/definitions.js +5 -89
- package/dist/src/gates/heldout.js +17 -7
- package/dist/src/lint/check-patterns.js +163 -0
- package/dist/src/lint/checks.js +268 -0
- package/dist/src/lint/reference-resolution.js +54 -0
- package/dist/src/lint/runner.js +3 -465
- package/dist/src/mcp/helpers.mjs +11 -1
- package/dist/src/memory/project-registry.js +44 -4
- package/dist/src/models/worker-plan.js +36 -5
- package/dist/src/models/wrapper-deployment.js +25 -12
- package/dist/src/models/wrapper-enforcement.js +47 -7
- package/dist/src/network-analysis/research.js +2 -1
- package/dist/src/policy/hitl-check.js +14 -4
- package/dist/src/policy/hitl-consume.js +54 -0
- package/dist/src/policy/hitl-receipt.js +2 -0
- package/dist/src/policy/hitl.js +11 -3
- package/dist/src/providers/provider-context-contracts.js +162 -0
- package/dist/src/providers/provider-definition-schema.js +136 -0
- package/dist/src/providers/provider-definitions.js +8 -1298
- package/dist/src/providers/provider-seeds-1.js +360 -0
- package/dist/src/providers/provider-seeds-2.js +387 -0
- package/dist/src/providers/provider-seeds-3.js +262 -0
- package/dist/src/research/clients/arxiv.js +4 -30
- package/dist/src/research/clients/base.js +48 -22
- package/dist/src/research/identity.js +34 -2
- package/dist/src/research/query-cli.js +3 -87
- package/dist/src/research/query-options.js +87 -0
- package/dist/src/research/reference-match.js +70 -24
- package/dist/src/research/services/acquisition.js +9 -7
- package/dist/src/research/services/citation.js +5 -2
- package/dist/src/research/types.js +2 -0
- package/dist/src/serve/mission-conductor.js +48 -4
- package/dist/src/sessions/adapters/grok-build-native.js +23 -0
- package/dist/src/sessions/adapters/grok-build.js +14 -7
- package/dist/src/sessions/workspace-discovery.js +5 -5
- package/dist/src/smiths/context-pipeline/aiwg-md.js +16 -46
- package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
- package/dist/src/smiths/context-pipeline/finalization.js +81 -51
- package/dist/src/smiths/context-pipeline/generator.js +9 -10
- package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
- package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
- package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
- package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
- package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
- package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
- package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
- package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
- package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
- package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
- package/package.json +10 -1
- package/schemas/decision/D29Study.v10.schema.json +65 -0
- package/tools/agents/deploy-agents.mjs +10 -0
- package/tools/agents/providers/claude-post-deploy.mjs +12 -1
- package/tools/agents/providers/context-write.mjs +4 -0
- package/tools/agents/providers/pi.mjs +3 -1
- package/tools/agents/providers/rule-delivery-surface.mjs +332 -0
- package/tools/agents/providers/rule-delivery.mjs +20 -1144
- package/tools/agents/providers/rule-deployment-commit.mjs +144 -0
- package/tools/agents/providers/rule-deployment-prepare.mjs +452 -0
- package/tools/agents/providers/rule-deployment-state.mjs +300 -0
- package/tools/daemon/README.md +511 -0
- package/tools/daemon/adapters/base-adapter.mjs +84 -0
- package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
- package/tools/daemon/agent-supervisor.mjs +299 -0
- package/tools/daemon/automation-engine.mjs +310 -0
- package/tools/daemon/autonomous-engine.mjs +346 -0
- package/tools/daemon/behavior-loader.mjs +316 -0
- package/tools/daemon/behavior.mjs +174 -0
- package/tools/daemon/concierge/intent-router.mjs +401 -0
- package/tools/daemon/concierge/orchestrator.mjs +272 -0
- package/tools/daemon/concierge/response-translator.mjs +462 -0
- package/tools/daemon/config.mjs +377 -0
- package/tools/daemon/cron-scheduler.mjs +178 -0
- package/tools/daemon/daemon-main.mjs +1169 -0
- package/tools/daemon/event-router.mjs +84 -0
- package/tools/daemon/file-watcher.mjs +383 -0
- package/tools/daemon/index.mjs +1181 -0
- package/tools/daemon/init-profile.mjs +124 -0
- package/tools/daemon/ipc-client.mjs +197 -0
- package/tools/daemon/ipc-ops-handlers.mjs +236 -0
- package/tools/daemon/ipc-server.mjs +275 -0
- package/tools/daemon/maintenance-owner.mjs +79 -0
- package/tools/daemon/memory-manager.mjs +386 -0
- package/tools/daemon/message-router.mjs +194 -0
- package/tools/daemon/provider-watcher.mjs +585 -0
- package/tools/daemon/pty-adapter.mjs +420 -0
- package/tools/daemon/repl-chat.mjs +359 -0
- package/tools/daemon/resource-bounds.mjs +88 -0
- package/tools/daemon/sandbox-transport.mjs +295 -0
- package/tools/daemon/scheduled-task-runner.mjs +535 -0
- package/tools/daemon/task-store.mjs +450 -0
- package/tools/daemon/tmux-manager.mjs +324 -0
- package/tools/daemon/update-policy.mjs +517 -0
- package/tools/daemon/web-server.mjs +399 -0
- package/tools/daemon/web-ui/index.html +585 -0
- package/tools/daemon/web-ui/styles.css +156 -0
- package/tools/docker/Dockerfile.daemon +35 -0
- package/tools/docker/container-manager.mjs +291 -0
- package/tools/messaging/adapter-registry.mjs +230 -0
- package/tools/messaging/adapters/base.mjs +326 -0
- package/tools/messaging/adapters/discord.mjs +462 -0
- package/tools/messaging/adapters/slack.mjs +402 -0
- package/tools/messaging/adapters/telegram.mjs +552 -0
- package/tools/messaging/chat-handler.mjs +297 -0
- package/tools/messaging/command-router.mjs +269 -0
- package/tools/messaging/event-bus.mjs +199 -0
- package/tools/messaging/index.mjs +456 -0
- package/tools/messaging/message-formatter.mjs +320 -0
- package/tools/messaging/room-manager.mjs +277 -0
- package/tools/messaging/types.mjs +94 -0
- package/tools/providers/pi-bridge-policy.mjs +4 -0
- package/tools/ralph-external/daemon-supervisor.mjs +394 -0
- package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +3 -2
- package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
- package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
- package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
- package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
- package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
- package/tools/ralph-external/session-launcher.mjs +7 -7
- 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;
|