@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,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts AiwgEvent objects into platform-agnostic AiwgMessage structures
|
|
3
|
+
* that platform adapters translate to native rendering.
|
|
4
|
+
*
|
|
5
|
+
* @implements @.aiwg/architecture/adrs/ADR-messaging-bot-mode.md
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Severity, ButtonStyle } from './types.mjs';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Object} AiwgMessage
|
|
12
|
+
* @property {string} title
|
|
13
|
+
* @property {string} body
|
|
14
|
+
* @property {'info'|'warning'|'critical'} severity
|
|
15
|
+
* @property {Array<{label: string, value: string, inline: boolean}>} fields
|
|
16
|
+
* @property {Array<{id: string, label: string, style: string, command: string}>} [actions]
|
|
17
|
+
* @property {string} [threadId]
|
|
18
|
+
* @property {string} project
|
|
19
|
+
* @property {string} timestamp
|
|
20
|
+
* @property {string} [codeBlock]
|
|
21
|
+
* @property {string} [linkUrl]
|
|
22
|
+
* @property {string} [linkText]
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Severity colors for Slack/Discord
|
|
27
|
+
*/
|
|
28
|
+
const SEVERITY_COLORS = {
|
|
29
|
+
[Severity.INFO]: '#36a64f', // Green
|
|
30
|
+
[Severity.WARNING]: '#daa520', // Goldenrod
|
|
31
|
+
[Severity.CRITICAL]: '#dc3545', // Red
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Severity emoji for Telegram
|
|
36
|
+
*/
|
|
37
|
+
const SEVERITY_EMOJI = {
|
|
38
|
+
[Severity.INFO]: '\u2705', // Green check
|
|
39
|
+
[Severity.WARNING]: '\u26a0\ufe0f', // Warning
|
|
40
|
+
[Severity.CRITICAL]: '\ud83d\udea8', // Siren
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Format an AiwgEvent into an AiwgMessage.
|
|
45
|
+
*
|
|
46
|
+
* @param {import('./event-bus.mjs').AiwgEvent} event
|
|
47
|
+
* @returns {AiwgMessage}
|
|
48
|
+
*/
|
|
49
|
+
export function formatEvent(event) {
|
|
50
|
+
const formatter = EVENT_FORMATTERS[event.topic] || formatGenericEvent;
|
|
51
|
+
return formatter(event);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get the color for a severity level.
|
|
56
|
+
*
|
|
57
|
+
* @param {'info'|'warning'|'critical'} severity
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
export function getSeverityColor(severity) {
|
|
61
|
+
return SEVERITY_COLORS[severity] || SEVERITY_COLORS[Severity.INFO];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get the emoji for a severity level.
|
|
66
|
+
*
|
|
67
|
+
* @param {'info'|'warning'|'critical'} severity
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
export function getSeverityEmoji(severity) {
|
|
71
|
+
return SEVERITY_EMOJI[severity] || SEVERITY_EMOJI[Severity.INFO];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// Event-specific formatters
|
|
76
|
+
// ============================================================================
|
|
77
|
+
|
|
78
|
+
const EVENT_FORMATTERS = {
|
|
79
|
+
'ralph.started': formatRalphStarted,
|
|
80
|
+
'ralph.iteration': formatRalphIteration,
|
|
81
|
+
'ralph.completed': formatRalphCompleted,
|
|
82
|
+
'ralph.failed': formatRalphFailed,
|
|
83
|
+
'ralph.aborted': formatRalphAborted,
|
|
84
|
+
'gate.pending': formatGatePending,
|
|
85
|
+
'gate.approved': formatGateApproved,
|
|
86
|
+
'gate.rejected': formatGateRejected,
|
|
87
|
+
'gate.timeout': formatGateTimeout,
|
|
88
|
+
'security.critical': formatSecurityCritical,
|
|
89
|
+
'health.degraded': formatHealthDegraded,
|
|
90
|
+
'health.recovered': formatHealthRecovered,
|
|
91
|
+
'daemon.started': formatDaemonStarted,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function formatRalphStarted(event) {
|
|
95
|
+
const d = event.details;
|
|
96
|
+
return {
|
|
97
|
+
title: `Ralph Loop Started`,
|
|
98
|
+
body: event.summary,
|
|
99
|
+
severity: Severity.INFO,
|
|
100
|
+
fields: [
|
|
101
|
+
{ label: 'Objective', value: d.objective || 'N/A', inline: false },
|
|
102
|
+
{ label: 'Max Iterations', value: String(d.maxIterations || 'N/A'), inline: true },
|
|
103
|
+
{ label: 'Loop ID', value: event.loopId || 'N/A', inline: true },
|
|
104
|
+
],
|
|
105
|
+
project: event.project,
|
|
106
|
+
timestamp: event.timestamp,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function formatRalphIteration(event) {
|
|
111
|
+
const d = event.details;
|
|
112
|
+
const progress = d.progress != null ? `${d.progress}%` : 'N/A';
|
|
113
|
+
return {
|
|
114
|
+
title: `Iteration ${d.iteration}/${d.maxIterations}`,
|
|
115
|
+
body: event.summary,
|
|
116
|
+
severity: d.progress >= 80 ? Severity.INFO : Severity.WARNING,
|
|
117
|
+
fields: [
|
|
118
|
+
{ label: 'Progress', value: progress, inline: true },
|
|
119
|
+
{ label: 'Status', value: d.status || 'in_progress', inline: true },
|
|
120
|
+
],
|
|
121
|
+
threadId: event.loopId,
|
|
122
|
+
project: event.project,
|
|
123
|
+
timestamp: event.timestamp,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function formatRalphCompleted(event) {
|
|
128
|
+
const d = event.details;
|
|
129
|
+
return {
|
|
130
|
+
title: `Ralph Loop Completed`,
|
|
131
|
+
body: event.summary,
|
|
132
|
+
severity: Severity.INFO,
|
|
133
|
+
fields: [
|
|
134
|
+
{ label: 'Iterations', value: String(d.iterations || 'N/A'), inline: true },
|
|
135
|
+
{ label: 'Result', value: d.success ? 'Success' : 'Partial', inline: true },
|
|
136
|
+
{ label: 'Loop ID', value: event.loopId || 'N/A', inline: true },
|
|
137
|
+
],
|
|
138
|
+
threadId: event.loopId,
|
|
139
|
+
project: event.project,
|
|
140
|
+
timestamp: event.timestamp,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function formatRalphFailed(event) {
|
|
145
|
+
const d = event.details;
|
|
146
|
+
return {
|
|
147
|
+
title: `Ralph Loop Failed`,
|
|
148
|
+
body: event.summary,
|
|
149
|
+
severity: Severity.CRITICAL,
|
|
150
|
+
fields: [
|
|
151
|
+
{ label: 'Reason', value: d.reason || 'Unknown', inline: false },
|
|
152
|
+
{ label: 'Iterations', value: String(d.iterations || 'N/A'), inline: true },
|
|
153
|
+
{ label: 'Loop ID', value: event.loopId || 'N/A', inline: true },
|
|
154
|
+
],
|
|
155
|
+
codeBlock: d.lastError || undefined,
|
|
156
|
+
threadId: event.loopId,
|
|
157
|
+
project: event.project,
|
|
158
|
+
timestamp: event.timestamp,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function formatRalphAborted(event) {
|
|
163
|
+
return {
|
|
164
|
+
title: `Ralph Loop Aborted`,
|
|
165
|
+
body: event.summary,
|
|
166
|
+
severity: Severity.WARNING,
|
|
167
|
+
fields: [
|
|
168
|
+
{ label: 'Reason', value: event.details.reason || 'User request', inline: false },
|
|
169
|
+
{ label: 'Loop ID', value: event.loopId || 'N/A', inline: true },
|
|
170
|
+
],
|
|
171
|
+
threadId: event.loopId,
|
|
172
|
+
project: event.project,
|
|
173
|
+
timestamp: event.timestamp,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function formatGatePending(event) {
|
|
178
|
+
const d = event.details;
|
|
179
|
+
return {
|
|
180
|
+
title: `HITL Gate: Approval Required`,
|
|
181
|
+
body: event.summary,
|
|
182
|
+
severity: Severity.WARNING,
|
|
183
|
+
fields: [
|
|
184
|
+
{ label: 'Gate', value: d.gateName || event.gateId || 'N/A', inline: true },
|
|
185
|
+
{ label: 'Quality Score', value: d.qualityScore != null ? `${d.qualityScore}%` : 'N/A', inline: true },
|
|
186
|
+
{ label: 'Artifacts', value: String(d.artifactCount || 0), inline: true },
|
|
187
|
+
],
|
|
188
|
+
actions: [
|
|
189
|
+
{
|
|
190
|
+
id: `approve_${event.gateId}`,
|
|
191
|
+
label: 'Approve',
|
|
192
|
+
style: ButtonStyle.PRIMARY,
|
|
193
|
+
command: `approve ${event.gateId}`,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: `reject_${event.gateId}`,
|
|
197
|
+
label: 'Reject',
|
|
198
|
+
style: ButtonStyle.DANGER,
|
|
199
|
+
command: `reject ${event.gateId}`,
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
project: event.project,
|
|
203
|
+
timestamp: event.timestamp,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function formatGateApproved(event) {
|
|
208
|
+
return {
|
|
209
|
+
title: `Gate Approved`,
|
|
210
|
+
body: event.summary,
|
|
211
|
+
severity: Severity.INFO,
|
|
212
|
+
fields: [
|
|
213
|
+
{ label: 'Gate', value: event.gateId || 'N/A', inline: true },
|
|
214
|
+
{ label: 'Approved By', value: event.details.approvedBy || 'N/A', inline: true },
|
|
215
|
+
],
|
|
216
|
+
project: event.project,
|
|
217
|
+
timestamp: event.timestamp,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function formatGateRejected(event) {
|
|
222
|
+
return {
|
|
223
|
+
title: `Gate Rejected`,
|
|
224
|
+
body: event.summary,
|
|
225
|
+
severity: Severity.WARNING,
|
|
226
|
+
fields: [
|
|
227
|
+
{ label: 'Gate', value: event.gateId || 'N/A', inline: true },
|
|
228
|
+
{ label: 'Rejected By', value: event.details.rejectedBy || 'N/A', inline: true },
|
|
229
|
+
{ label: 'Reason', value: event.details.reason || 'N/A', inline: false },
|
|
230
|
+
],
|
|
231
|
+
project: event.project,
|
|
232
|
+
timestamp: event.timestamp,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function formatGateTimeout(event) {
|
|
237
|
+
return {
|
|
238
|
+
title: `Gate Timed Out`,
|
|
239
|
+
body: event.summary,
|
|
240
|
+
severity: Severity.CRITICAL,
|
|
241
|
+
fields: [
|
|
242
|
+
{ label: 'Gate', value: event.gateId || 'N/A', inline: true },
|
|
243
|
+
{ label: 'Action', value: event.details.timeoutAction || 'block', inline: true },
|
|
244
|
+
],
|
|
245
|
+
project: event.project,
|
|
246
|
+
timestamp: event.timestamp,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function formatSecurityCritical(event) {
|
|
251
|
+
return {
|
|
252
|
+
title: `Security Alert: Critical Finding`,
|
|
253
|
+
body: event.summary,
|
|
254
|
+
severity: Severity.CRITICAL,
|
|
255
|
+
fields: [
|
|
256
|
+
{ label: 'Finding', value: event.details.finding || 'N/A', inline: false },
|
|
257
|
+
{ label: 'File', value: event.details.file || 'N/A', inline: true },
|
|
258
|
+
{ label: 'Severity', value: 'CRITICAL', inline: true },
|
|
259
|
+
],
|
|
260
|
+
project: event.project,
|
|
261
|
+
timestamp: event.timestamp,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function formatHealthDegraded(event) {
|
|
266
|
+
return {
|
|
267
|
+
title: `System Health Degraded`,
|
|
268
|
+
body: event.summary,
|
|
269
|
+
severity: Severity.WARNING,
|
|
270
|
+
fields: [
|
|
271
|
+
{ label: 'Component', value: event.details.component || 'N/A', inline: true },
|
|
272
|
+
{ label: 'Status', value: event.details.status || 'degraded', inline: true },
|
|
273
|
+
],
|
|
274
|
+
project: event.project,
|
|
275
|
+
timestamp: event.timestamp,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function formatHealthRecovered(event) {
|
|
280
|
+
return {
|
|
281
|
+
title: `System Health Recovered`,
|
|
282
|
+
body: event.summary,
|
|
283
|
+
severity: Severity.INFO,
|
|
284
|
+
fields: [
|
|
285
|
+
{ label: 'Component', value: event.details.component || 'N/A', inline: true },
|
|
286
|
+
],
|
|
287
|
+
project: event.project,
|
|
288
|
+
timestamp: event.timestamp,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function formatDaemonStarted(event) {
|
|
293
|
+
const d = event.details;
|
|
294
|
+
return {
|
|
295
|
+
title: `AIWG Daemon Started`,
|
|
296
|
+
body: event.summary,
|
|
297
|
+
severity: Severity.INFO,
|
|
298
|
+
fields: [
|
|
299
|
+
{ label: 'PID', value: String(d.pid || process.pid), inline: true },
|
|
300
|
+
{ label: 'Adapters', value: (d.adapters || []).join(', ') || 'none', inline: true },
|
|
301
|
+
],
|
|
302
|
+
project: event.project,
|
|
303
|
+
timestamp: event.timestamp,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function formatGenericEvent(event) {
|
|
308
|
+
return {
|
|
309
|
+
title: event.topic,
|
|
310
|
+
body: event.summary,
|
|
311
|
+
severity: event.severity || Severity.INFO,
|
|
312
|
+
fields: Object.entries(event.details || {}).map(([key, value]) => ({
|
|
313
|
+
label: key,
|
|
314
|
+
value: String(value),
|
|
315
|
+
inline: true,
|
|
316
|
+
})),
|
|
317
|
+
project: event.project,
|
|
318
|
+
timestamp: event.timestamp,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RoomManager — Multi-room coordination for messaging adapters.
|
|
3
|
+
*
|
|
4
|
+
* Manages a registry of rooms across all platforms, room-to-task bindings,
|
|
5
|
+
* and targeted message delivery. Each room has a purpose classification
|
|
6
|
+
* (interactive, notifications, logs) and visibility settings.
|
|
7
|
+
*
|
|
8
|
+
* @implements Plan: Daemon Starter — Multi-Room Messaging
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { EventEmitter } from 'events';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {Object} RoomConfig
|
|
15
|
+
* @property {string} id - Composite key "platform:platformRoomId"
|
|
16
|
+
* @property {string} platform - "telegram" | "discord" | "slack"
|
|
17
|
+
* @property {string} platformRoomId - Native channel/chat ID
|
|
18
|
+
* @property {string} label - Human-readable name
|
|
19
|
+
* @property {'interactive'|'notifications'|'logs'} purpose - Room purpose
|
|
20
|
+
* @property {boolean} isDefault - Receives broadcast messages
|
|
21
|
+
* @property {'own'|'all'|string[]} visibility - Task visibility scope
|
|
22
|
+
* @property {'static'|'dynamic'} source - How the room was added
|
|
23
|
+
* @property {string} joinedAt - ISO-8601 timestamp
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Object} RoomManagerOptions
|
|
28
|
+
* @property {RoomConfig[]} [rooms] - Initial rooms from config
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export class RoomManager extends EventEmitter {
|
|
32
|
+
/** @type {Map<string, RoomConfig>} */
|
|
33
|
+
#rooms = new Map();
|
|
34
|
+
|
|
35
|
+
/** @type {Map<string, string>} taskId -> room composite key */
|
|
36
|
+
#taskBindings = new Map();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {RoomManagerOptions} [options]
|
|
40
|
+
*/
|
|
41
|
+
constructor(options = {}) {
|
|
42
|
+
super();
|
|
43
|
+
if (options.rooms) {
|
|
44
|
+
for (const room of options.rooms) {
|
|
45
|
+
this.addRoom(room.platform, room.platformRoomId, room);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Register a room.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} platform
|
|
54
|
+
* @param {string} platformRoomId
|
|
55
|
+
* @param {Partial<RoomConfig>} [options]
|
|
56
|
+
* @returns {RoomConfig}
|
|
57
|
+
*/
|
|
58
|
+
addRoom(platform, platformRoomId, options = {}) {
|
|
59
|
+
const id = `${platform}:${platformRoomId}`;
|
|
60
|
+
|
|
61
|
+
if (this.#rooms.has(id)) {
|
|
62
|
+
return this.#rooms.get(id);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @type {RoomConfig} */
|
|
66
|
+
const room = {
|
|
67
|
+
id,
|
|
68
|
+
platform,
|
|
69
|
+
platformRoomId,
|
|
70
|
+
label: options.label || platformRoomId,
|
|
71
|
+
purpose: options.purpose || 'interactive',
|
|
72
|
+
isDefault: options.isDefault ?? options.is_default ?? false,
|
|
73
|
+
visibility: options.visibility || 'own',
|
|
74
|
+
source: options.source || 'static',
|
|
75
|
+
joinedAt: new Date().toISOString(),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
this.#rooms.set(id, room);
|
|
79
|
+
this.emit('room:added', room);
|
|
80
|
+
return room;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Remove a room.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} platform
|
|
87
|
+
* @param {string} platformRoomId
|
|
88
|
+
* @returns {boolean}
|
|
89
|
+
*/
|
|
90
|
+
removeRoom(platform, platformRoomId) {
|
|
91
|
+
const id = `${platform}:${platformRoomId}`;
|
|
92
|
+
const room = this.#rooms.get(id);
|
|
93
|
+
if (!room) return false;
|
|
94
|
+
|
|
95
|
+
// Unbind any tasks associated with this room
|
|
96
|
+
for (const [taskId, roomId] of this.#taskBindings) {
|
|
97
|
+
if (roomId === id) {
|
|
98
|
+
this.#taskBindings.delete(taskId);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.#rooms.delete(id);
|
|
103
|
+
this.emit('room:removed', room);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Bind a task to a room so its output is routed there.
|
|
109
|
+
*
|
|
110
|
+
* @param {string} taskId
|
|
111
|
+
* @param {string} platform
|
|
112
|
+
* @param {string} platformRoomId
|
|
113
|
+
*/
|
|
114
|
+
bindTask(taskId, platform, platformRoomId) {
|
|
115
|
+
const roomId = `${platform}:${platformRoomId}`;
|
|
116
|
+
this.#taskBindings.set(taskId, roomId);
|
|
117
|
+
this.emit('task:bound', { taskId, roomId });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Remove a task-room binding.
|
|
122
|
+
*
|
|
123
|
+
* @param {string} taskId
|
|
124
|
+
*/
|
|
125
|
+
unbindTask(taskId) {
|
|
126
|
+
this.#taskBindings.delete(taskId);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Look up which room a task is bound to.
|
|
131
|
+
*
|
|
132
|
+
* @param {string} taskId
|
|
133
|
+
* @returns {RoomConfig|null}
|
|
134
|
+
*/
|
|
135
|
+
getRoomForTask(taskId) {
|
|
136
|
+
const roomId = this.#taskBindings.get(taskId);
|
|
137
|
+
if (!roomId) return null;
|
|
138
|
+
return this.#rooms.get(roomId) || null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Get all rooms marked as default (receive broadcast messages).
|
|
143
|
+
*
|
|
144
|
+
* @param {string} [platform] - Filter by platform
|
|
145
|
+
* @returns {RoomConfig[]}
|
|
146
|
+
*/
|
|
147
|
+
getBroadcastRooms(platform) {
|
|
148
|
+
const rooms = [];
|
|
149
|
+
for (const room of this.#rooms.values()) {
|
|
150
|
+
if (!room.isDefault) continue;
|
|
151
|
+
if (platform && room.platform !== platform) continue;
|
|
152
|
+
rooms.push(room);
|
|
153
|
+
}
|
|
154
|
+
return rooms;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Get all rooms, optionally filtered by platform.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} [platform]
|
|
161
|
+
* @returns {RoomConfig[]}
|
|
162
|
+
*/
|
|
163
|
+
getRooms(platform) {
|
|
164
|
+
if (!platform) return [...this.#rooms.values()];
|
|
165
|
+
return [...this.#rooms.values()].filter(r => r.platform === platform);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Get a specific room.
|
|
170
|
+
*
|
|
171
|
+
* @param {string} platform
|
|
172
|
+
* @param {string} platformRoomId
|
|
173
|
+
* @returns {RoomConfig|null}
|
|
174
|
+
*/
|
|
175
|
+
getRoom(platform, platformRoomId) {
|
|
176
|
+
return this.#rooms.get(`${platform}:${platformRoomId}`) || null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Check if a room should see a task's events based on visibility settings.
|
|
181
|
+
*
|
|
182
|
+
* @param {RoomConfig} room
|
|
183
|
+
* @param {string} taskId
|
|
184
|
+
* @returns {boolean}
|
|
185
|
+
*/
|
|
186
|
+
shouldSeeTask(room, taskId) {
|
|
187
|
+
if (room.visibility === 'all') return true;
|
|
188
|
+
if (room.visibility === 'own') {
|
|
189
|
+
const boundRoom = this.#taskBindings.get(taskId);
|
|
190
|
+
return boundRoom === room.id;
|
|
191
|
+
}
|
|
192
|
+
if (Array.isArray(room.visibility)) {
|
|
193
|
+
return room.visibility.includes(taskId);
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Get rooms that should receive events for a specific task.
|
|
200
|
+
*
|
|
201
|
+
* @param {string} taskId
|
|
202
|
+
* @returns {RoomConfig[]}
|
|
203
|
+
*/
|
|
204
|
+
getRoomsForTaskEvent(taskId) {
|
|
205
|
+
const rooms = [];
|
|
206
|
+
for (const room of this.#rooms.values()) {
|
|
207
|
+
if (this.shouldSeeTask(room, taskId)) {
|
|
208
|
+
rooms.push(room);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return rooms;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** @returns {number} */
|
|
215
|
+
get size() {
|
|
216
|
+
return this.#rooms.size;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** @returns {number} */
|
|
220
|
+
get bindingCount() {
|
|
221
|
+
return this.#taskBindings.size;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Load rooms from a messaging config section.
|
|
226
|
+
*
|
|
227
|
+
* @param {Object} messagingConfig - The messaging section of daemon config
|
|
228
|
+
*/
|
|
229
|
+
loadFromConfig(messagingConfig) {
|
|
230
|
+
if (!messagingConfig) return;
|
|
231
|
+
|
|
232
|
+
for (const [platform, platformConfig] of Object.entries(messagingConfig)) {
|
|
233
|
+
if (!platformConfig?.rooms || !Array.isArray(platformConfig.rooms)) continue;
|
|
234
|
+
|
|
235
|
+
for (const roomDef of platformConfig.rooms) {
|
|
236
|
+
const platformRoomId = roomDef.chat_id || roomDef.channel_id || roomDef.roomId;
|
|
237
|
+
if (!platformRoomId) continue;
|
|
238
|
+
|
|
239
|
+
this.addRoom(platform, platformRoomId, {
|
|
240
|
+
label: roomDef.label || roomDef.name || platformRoomId,
|
|
241
|
+
purpose: roomDef.purpose || 'interactive',
|
|
242
|
+
isDefault: roomDef.is_default ?? roomDef.isDefault ?? false,
|
|
243
|
+
visibility: roomDef.visibility || 'own',
|
|
244
|
+
source: 'static',
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Serialize room state for status reporting.
|
|
252
|
+
*
|
|
253
|
+
* @returns {Object}
|
|
254
|
+
*/
|
|
255
|
+
getStatus() {
|
|
256
|
+
const platforms = {};
|
|
257
|
+
for (const room of this.#rooms.values()) {
|
|
258
|
+
if (!platforms[room.platform]) platforms[room.platform] = [];
|
|
259
|
+
platforms[room.platform].push({
|
|
260
|
+
id: room.platformRoomId,
|
|
261
|
+
label: room.label,
|
|
262
|
+
purpose: room.purpose,
|
|
263
|
+
isDefault: room.isDefault,
|
|
264
|
+
boundTasks: [...this.#taskBindings.entries()]
|
|
265
|
+
.filter(([, rid]) => rid === room.id)
|
|
266
|
+
.map(([tid]) => tid),
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
totalRooms: this.#rooms.size,
|
|
271
|
+
totalBindings: this.#taskBindings.size,
|
|
272
|
+
platforms,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export default RoomManager;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Messaging subsystem type definitions and constants.
|
|
3
|
+
*
|
|
4
|
+
* @implements @.aiwg/architecture/adrs/ADR-messaging-bot-mode.md
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Severity levels for events and messages
|
|
9
|
+
* @enum {string}
|
|
10
|
+
*/
|
|
11
|
+
export const Severity = Object.freeze({
|
|
12
|
+
INFO: 'info',
|
|
13
|
+
WARNING: 'warning',
|
|
14
|
+
CRITICAL: 'critical',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Event topics emitted by AIWG subsystems
|
|
19
|
+
* @enum {string}
|
|
20
|
+
*/
|
|
21
|
+
export const EventTopic = Object.freeze({
|
|
22
|
+
// Ralph lifecycle
|
|
23
|
+
RALPH_STARTED: 'ralph.started',
|
|
24
|
+
RALPH_ITERATION: 'ralph.iteration',
|
|
25
|
+
RALPH_COMPLETED: 'ralph.completed',
|
|
26
|
+
RALPH_FAILED: 'ralph.failed',
|
|
27
|
+
RALPH_ABORTED: 'ralph.aborted',
|
|
28
|
+
|
|
29
|
+
// HITL gates
|
|
30
|
+
GATE_PENDING: 'gate.pending',
|
|
31
|
+
GATE_APPROVED: 'gate.approved',
|
|
32
|
+
GATE_REJECTED: 'gate.rejected',
|
|
33
|
+
GATE_TIMEOUT: 'gate.timeout',
|
|
34
|
+
|
|
35
|
+
// Security
|
|
36
|
+
SECURITY_CRITICAL: 'security.critical',
|
|
37
|
+
SECURITY_WARNING: 'security.warning',
|
|
38
|
+
SECURITY_SCAN_DONE: 'security.scan_done',
|
|
39
|
+
|
|
40
|
+
// Health
|
|
41
|
+
HEALTH_CHECK: 'health.check',
|
|
42
|
+
HEALTH_DEGRADED: 'health.degraded',
|
|
43
|
+
HEALTH_RECOVERED: 'health.recovered',
|
|
44
|
+
|
|
45
|
+
// Build
|
|
46
|
+
BUILD_FAILED: 'build.failed',
|
|
47
|
+
BUILD_PASSED: 'build.passed',
|
|
48
|
+
|
|
49
|
+
// Daemon
|
|
50
|
+
DAEMON_STARTED: 'daemon.started',
|
|
51
|
+
DAEMON_STOPPING: 'daemon.stopping',
|
|
52
|
+
|
|
53
|
+
// Chat
|
|
54
|
+
CHAT_MESSAGE: 'chat.message',
|
|
55
|
+
CHAT_RESPONSE: 'chat.response',
|
|
56
|
+
CHAT_ERROR: 'chat.error',
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Command permission levels
|
|
61
|
+
* @enum {string}
|
|
62
|
+
*/
|
|
63
|
+
export const CommandPermission = Object.freeze({
|
|
64
|
+
READ: 'read',
|
|
65
|
+
WRITE: 'write',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Default command definitions with permission levels
|
|
70
|
+
*/
|
|
71
|
+
export const COMMANDS = Object.freeze({
|
|
72
|
+
status: { permission: CommandPermission.READ, description: 'Show project status' },
|
|
73
|
+
'ralph-status': { permission: CommandPermission.READ, description: 'Show Ralph loop status' },
|
|
74
|
+
approve: { permission: CommandPermission.WRITE, description: 'Approve a pending HITL gate' },
|
|
75
|
+
reject: { permission: CommandPermission.WRITE, description: 'Reject a pending HITL gate' },
|
|
76
|
+
health: { permission: CommandPermission.READ, description: 'Run health check' },
|
|
77
|
+
help: { permission: CommandPermission.READ, description: 'List available commands' },
|
|
78
|
+
ask: { permission: CommandPermission.READ, description: 'Ask AI a question (e.g., /ask what is our test coverage?)' },
|
|
79
|
+
join: { permission: CommandPermission.WRITE, description: 'Add this chat as a room (dynamic join)' },
|
|
80
|
+
leave: { permission: CommandPermission.WRITE, description: 'Remove this chat from rooms' },
|
|
81
|
+
rooms: { permission: CommandPermission.READ, description: 'List all active rooms' },
|
|
82
|
+
subscribe: { permission: CommandPermission.WRITE, description: 'Subscribe this room to a task (e.g., /subscribe task-0001)' },
|
|
83
|
+
unsubscribe: { permission: CommandPermission.WRITE, description: 'Unsubscribe from a task' },
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Button styles for interactive messages
|
|
88
|
+
* @enum {string}
|
|
89
|
+
*/
|
|
90
|
+
export const ButtonStyle = Object.freeze({
|
|
91
|
+
PRIMARY: 'primary',
|
|
92
|
+
DANGER: 'danger',
|
|
93
|
+
DEFAULT: 'default',
|
|
94
|
+
});
|