@cortex-agent/server 2026.5.19-3 → 2026.5.22

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 (132) hide show
  1. package/README.md +5 -1
  2. package/defaults/config/thread-templates.json +65 -39
  3. package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +4 -4
  4. package/defaults/prompts/directives/coder-reviewer.md +9 -4
  5. package/defaults/prompts/directives/coder.md +10 -2
  6. package/dist/core/log.js +61 -12
  7. package/dist/core/status-format.js +1 -1
  8. package/dist/core/task-parser.d.ts +1 -1
  9. package/dist/core/task-parser.js +13 -6
  10. package/dist/core/types/thread-types.d.ts +4 -2
  11. package/dist/domain/costs/codex-usage-monitor.d.ts +1 -2
  12. package/dist/domain/costs/codex-usage-monitor.js +2 -2
  13. package/dist/domain/costs/cost-tracker.d.ts +2 -0
  14. package/dist/domain/costs/cost-tracker.js +4 -20
  15. package/dist/domain/costs/rate-limit-throttle.js +1 -4
  16. package/dist/domain/mcp/tools/context.d.ts +4 -2
  17. package/dist/domain/mcp/tools/context.js +7 -5
  18. package/dist/domain/mcp/tools/schedule.d.ts +1 -1
  19. package/dist/domain/mcp/tools/schedule.js +24 -20
  20. package/dist/domain/memory/index-regen.js +8 -5
  21. package/dist/domain/monitor/disk-monitor.js +1 -6
  22. package/dist/domain/projects/index.d.ts +2 -0
  23. package/dist/domain/projects/index.js +3 -0
  24. package/dist/domain/projects/project-store.d.ts +54 -0
  25. package/dist/domain/projects/project-store.js +194 -0
  26. package/dist/domain/projects/project-types.d.ts +11 -0
  27. package/dist/domain/projects/project-types.js +5 -0
  28. package/dist/domain/remote/client-hot-reload.d.ts +1 -0
  29. package/dist/domain/remote/client-hot-reload.js +284 -53
  30. package/dist/domain/scheduling/jobs/_shared.d.ts +1 -1
  31. package/dist/domain/scheduling/jobs/_shared.js +6 -5
  32. package/dist/domain/scheduling/jobs/memory-index-regen.js +2 -2
  33. package/dist/domain/scheduling/jobs/scheduled-task.d.ts +2 -2
  34. package/dist/domain/scheduling/jobs/scheduled-task.js +38 -36
  35. package/dist/domain/scheduling/jobs/sync-public.d.ts +1 -0
  36. package/dist/domain/scheduling/jobs/sync-public.js +34 -0
  37. package/dist/domain/scheduling/jobs/target-dispatch.d.ts +3 -7
  38. package/dist/domain/scheduling/jobs/target-dispatch.js +7 -9
  39. package/dist/domain/scheduling/jobs/task-archive.js +2 -2
  40. package/dist/domain/scheduling/jobs/task-dispatch.js +18 -16
  41. package/dist/domain/scheduling/runner.d.ts +1 -0
  42. package/dist/domain/scheduling/runner.js +2 -0
  43. package/dist/domain/scheduling/schedule-cli.d.ts +1 -0
  44. package/dist/domain/scheduling/schedule-cli.js +14 -14
  45. package/dist/domain/scheduling/schedule-command.js +45 -36
  46. package/dist/domain/scheduling/scheduler.d.ts +1 -1
  47. package/dist/domain/scheduling/scheduler.js +12 -11
  48. package/dist/domain/sessions/session-hooks.d.ts +10 -11
  49. package/dist/domain/sessions/session-hooks.js +26 -27
  50. package/dist/domain/sessions/session-registry.d.ts +10 -5
  51. package/dist/domain/sessions/session-registry.js +24 -9
  52. package/dist/domain/tasks/pending-tracker.js +8 -9
  53. package/dist/domain/tasks/system/task-cli.d.ts +2 -0
  54. package/dist/domain/tasks/system/task-cli.js +189 -29
  55. package/dist/domain/tasks/system/task-lifecycle-edit.js +3 -3
  56. package/dist/domain/threads/hook-runner.js +12 -7
  57. package/dist/domain/threads/runner.d.ts +3 -3
  58. package/dist/domain/threads/runner.js +30 -28
  59. package/dist/domain/threads/state-machine.d.ts +3 -0
  60. package/dist/domain/threads/state-machine.js +4 -0
  61. package/dist/entry/app.js +30 -9
  62. package/dist/entry/cli.js +19 -4
  63. package/dist/entry/daemon.js +28 -2
  64. package/dist/entry/startup-notify.js +8 -6
  65. package/dist/orchestration/agent-runner.js +19 -13
  66. package/dist/orchestration/durable-helpers.js +3 -2
  67. package/dist/orchestration/interactions/ask-user-question.d.ts +2 -3
  68. package/dist/orchestration/interactions/ask-user-question.js +5 -4
  69. package/dist/orchestration/interactions/interaction-handlers.js +8 -5
  70. package/dist/orchestration/interactions/plan-handler.js +3 -3
  71. package/dist/orchestration/lifecycle.js +43 -38
  72. package/dist/orchestration/routing/commands/cancel.js +9 -8
  73. package/dist/orchestration/routing/commands/channel.js +32 -26
  74. package/dist/orchestration/routing/commands/cost.js +5 -3
  75. package/dist/orchestration/routing/commands/device.js +2 -1
  76. package/dist/orchestration/routing/commands/dispatch.js +8 -7
  77. package/dist/orchestration/routing/commands/index.js +7 -4
  78. package/dist/orchestration/routing/commands/mode.js +24 -18
  79. package/dist/orchestration/routing/commands/nvtop.js +14 -12
  80. package/dist/orchestration/routing/commands/orient.js +2 -1
  81. package/dist/orchestration/routing/commands/schedule.js +2 -1
  82. package/dist/orchestration/routing/commands/sendfile.js +12 -9
  83. package/dist/orchestration/routing/commands/session.js +12 -10
  84. package/dist/orchestration/routing/commands/status.js +2 -2
  85. package/dist/orchestration/routing/commands/tail.js +10 -6
  86. package/dist/orchestration/routing/commands/task.js +5 -4
  87. package/dist/orchestration/routing/commands/thread-handlers.js +19 -12
  88. package/dist/orchestration/routing/hook-bridge-subscribers.js +15 -13
  89. package/dist/orchestration/status-helpers.d.ts +4 -5
  90. package/dist/orchestration/status-helpers.js +7 -8
  91. package/dist/orchestration/thread-executor.js +21 -12
  92. package/dist/platform/adapter.d.ts +13 -9
  93. package/dist/platform/adapter.js +1 -1
  94. package/dist/platform/adapters/feishu-output-stream.d.ts +27 -0
  95. package/dist/platform/adapters/feishu-output-stream.js +114 -0
  96. package/dist/platform/adapters/feishu.d.ts +16 -7
  97. package/dist/platform/adapters/feishu.js +64 -18
  98. package/dist/platform/adapters/index.d.ts +4 -1
  99. package/dist/platform/adapters/index.js +1 -1
  100. package/dist/platform/adapters/slack-output-stream.d.ts +55 -0
  101. package/dist/platform/{virtual-message.js → adapters/slack-output-stream.js} +98 -165
  102. package/dist/platform/adapters/slack-project-conduits.d.ts +9 -0
  103. package/dist/platform/adapters/slack-project-conduits.js +40 -0
  104. package/dist/platform/adapters/slack.d.ts +18 -8
  105. package/dist/platform/adapters/slack.js +82 -24
  106. package/dist/platform/index.d.ts +3 -2
  107. package/dist/platform/index.js +1 -1
  108. package/dist/platform/output-stream-chunk.d.ts +6 -0
  109. package/dist/platform/output-stream-chunk.js +45 -0
  110. package/dist/platform/output-stream-helpers.d.ts +6 -0
  111. package/dist/platform/output-stream-helpers.js +11 -0
  112. package/dist/platform/output-stream.d.ts +28 -0
  113. package/dist/platform/output-stream.js +4 -0
  114. package/dist/platform/testing.d.ts +41 -8
  115. package/dist/platform/testing.js +93 -11
  116. package/dist/platform/tool-trace.d.ts +9 -8
  117. package/dist/platform/tool-trace.js +19 -17
  118. package/dist/platform/types.d.ts +21 -1
  119. package/dist/platform/types.js +17 -1
  120. package/dist/store/channel-repo.d.ts +6 -0
  121. package/dist/store/channel-repo.js +9 -0
  122. package/dist/store/json-repository.js +12 -1
  123. package/dist/store/outbound-queue.d.ts +5 -4
  124. package/dist/store/outbound-queue.js +9 -6
  125. package/dist/store/schedule-repo.d.ts +9 -5
  126. package/dist/store/schedule-repo.js +59 -14
  127. package/dist/store/session-registry-repo.d.ts +36 -7
  128. package/dist/store/session-registry-repo.js +186 -25
  129. package/dist/store/thread-repo.d.ts +1 -0
  130. package/dist/store/thread-repo.js +8 -0
  131. package/package.json +1 -1
  132. package/dist/platform/virtual-message.d.ts +0 -68
@@ -9,14 +9,15 @@ import { supersededEdits } from './superseded-edits.js';
9
9
  import { runningExecutions } from '../core/running-executions.js';
10
10
  import { finalizeLocalExecution, buildSessionTag, buildUserProcessingMessage, makeFallbackNotifier, makeStreamingMessageCallback, computeElapsed, formatMetricsSuffix, writeStatus, sealStatus, buildStatusActionBlocks, buildSealedStatusActionBlocks, initStatusBlocks } from './status-helpers.js';
11
11
  import { getSessionAsync, setSessionAsync } from '../domain/sessions/session.js';
12
- import { sessionRegistryRepo } from '../store/session-registry-repo.js';
12
+ import { sessionStore } from '../store/session-registry-repo.js';
13
13
  import { conversationLedger } from '../store/conversation-ledger-repo.js';
14
14
  import * as sessionBackup from '../domain/sessions/session-backup.js';
15
15
  import { isOnMessageEndHookConfigured, runMessageEndSessionHook } from '../domain/sessions/session-hooks.js';
16
16
  import * as executionRegistry from '../domain/executions/registry.js';
17
17
  import * as askUserQuestion from './interactions/ask-user-question.js';
18
18
  import { runAgent, getClaudeMode, getActiveProfile, resolveBackendForChannel } from '../domain/agents/index.js';
19
- import { detectProject } from '../domain/costs/cost-tracker.js';
19
+ import { projectStore } from '../domain/projects/index.js';
20
+ import { projectDirRepo } from '../store/project-dir-repo.js';
20
21
  import { setStreamingCallback, clearStreamingCallback } from './routing/hook-bridge.js';
21
22
  import { maybeNotifyCodexLowUsage } from '../domain/costs/codex-usage-monitor.js';
22
23
  import { normalizeSkillCommandPrefix } from '../domain/memory/skill-scanner.js';
@@ -27,17 +28,17 @@ const log = createLogger('lifecycle');
27
28
  export async function handleAgentSuccess({ result, channel, adapter, statusMsg, startTime, userMessage, executionId, trigger = 'user', sessionName = null, threadTs = null, userMessageTs = null, onAssistantMessage = null }) {
28
29
  if (result?.sessionId)
29
30
  await setSessionAsync(channel, result.sessionId, resolveBackendForChannel(channel));
30
- await registerOrUpdateSession(result, sessionName, channel, trigger);
31
+ await registerOrUpdateSession(result, sessionName, channel, trigger, projectStore.resolveFromMessage(userMessage)?.id ?? 'general');
31
32
  await backfillLedgerSessionId(result, channel);
32
33
  const { elapsedStr, elapsedS } = computeElapsed(startTime);
33
34
  finalizeLocalExecution({ executionId, status: 'completed', result, durationS: elapsedS });
34
35
  const metrics = formatMetricsSuffix({ costUsd: result?.total_cost_usd ?? null, numTurns: result?.num_turns ?? null });
35
36
  const sessionTag = buildSessionTag(sessionName, result?.sessionId);
36
- const vm = onAssistantMessage?.vm ?? null;
37
- const askCount = await askUserQuestion.sendMessages(result, channel, adapter, statusMsg.messageId, threadTs, vm);
37
+ const stream = onAssistantMessage?.stream ?? null;
38
+ const askCount = await askUserQuestion.sendMessages(result, channel, adapter, statusMsg.messageId, threadTs, stream);
38
39
  const statusText = askCount > 0
39
- ? `:speech_balloon: ${sessionTag}Waiting for user input (${elapsedStr}s${metrics})`
40
- : `:white_check_mark: Done | ${sessionTag}(${elapsedStr}s${metrics})`;
40
+ ? `:speech_balloon: ${sessionTag}Waiting for user input (${elapsedStr}${metrics})`
41
+ : `:white_check_mark: Done | ${sessionTag}(${elapsedStr}${metrics})`;
41
42
  await sealStatus(adapter, statusMsg, statusText, buildSealedStatusActionBlocks(statusText, { channel, sessionName, isDm: true }));
42
43
  if (userMessageTs) {
43
44
  await conversationLedger.completeTurn(channel, userMessageTs, { executionId });
@@ -46,12 +47,12 @@ export async function handleAgentSuccess({ result, channel, adapter, statusMsg,
46
47
  // which forwards the plan through webhook /hook/exit-plan-mode → sendPlanToSlack.
47
48
  // Re-sending here would duplicate the plan message (and historically could
48
49
  // desync when the hook's mtime-based lookup picked a stale file).
49
- // onMessageEnd hook: extends the assistant turn's VirtualMessage so hook lines
50
+ // onMessageEnd hook: extends the assistant turn's OutputStream so hook lines
50
51
  // (status/preview/error) and any injected agent turn share one continuous Slack
51
- // thread with the reply we just finished — no top-level leak, no detached vm.
52
+ // thread with the reply we just finished — no top-level leak, no detached stream.
52
53
  if (isOnMessageEndHookConfigured() && result?.sessionId) {
53
- const hookVm = onAssistantMessage?.vm;
54
- if (hookVm) {
54
+ const hookStream = onAssistantMessage?.stream;
55
+ if (hookStream) {
55
56
  try {
56
57
  const conv = await conversationLedger.getConversation(channel);
57
58
  const profileName = conv?.profileName ?? null;
@@ -61,7 +62,7 @@ export async function handleAgentSuccess({ result, channel, adapter, statusMsg,
61
62
  sessionName: sessionName ?? '',
62
63
  executionId: executionId ?? '',
63
64
  profile: profileName,
64
- vm: hookVm,
65
+ stream: hookStream,
65
66
  });
66
67
  }
67
68
  catch (err) {
@@ -69,25 +70,26 @@ export async function handleAgentSuccess({ result, channel, adapter, statusMsg,
69
70
  }
70
71
  }
71
72
  else {
72
- log.warn('onMessageEnd hook skipped: assistant vm unavailable on onAssistantMessage');
73
+ log.warn('onMessageEnd hook skipped: assistant stream unavailable on onAssistantMessage');
73
74
  }
74
75
  }
75
76
  }
76
- async function registerOrUpdateSession(result, sessionName, channel, trigger) {
77
+ async function registerOrUpdateSession(result, sessionName, channel, trigger, projectId = 'general') {
77
78
  if (!result?.sessionId || !sessionName)
78
79
  return;
79
- const existing = await sessionRegistryRepo.lookupBySessionId(result.sessionId);
80
+ const existing = await sessionStore.lookupBySessionId(result.sessionId);
80
81
  if (!existing) {
81
- await sessionRegistryRepo.registerSession(sessionName, {
82
+ await sessionStore.registerSession(sessionName, {
82
83
  sessionId: result.sessionId, channel,
83
84
  backend: resolveBackendForChannel(channel),
84
85
  kind: trigger === 'scheduled' ? 'scheduled' : 'local',
85
86
  label: null,
86
87
  profileName: getActiveProfile(channel),
88
+ projectId,
87
89
  });
88
90
  }
89
91
  else {
90
- await sessionRegistryRepo.updateSession(existing, { lastUsedAt: new Date().toISOString() });
92
+ await sessionStore.updateSession(existing, { lastUsedAt: new Date().toISOString() });
91
93
  }
92
94
  }
93
95
  async function backfillLedgerSessionId(result, channel) {
@@ -107,7 +109,7 @@ export async function handleAgentError({ error, channel, adapter, statusMsg, sta
107
109
  if (error?.cancelled && supersededEdits.check(channel)) {
108
110
  supersededEdits.clear(channel);
109
111
  finalizeLocalExecution({ executionId, status: 'cancelled', error, durationS: elapsedS });
110
- const supersededText = `:fast_forward: ${sessionTag}Superseded by edit (${elapsedStr}s)`;
112
+ const supersededText = `:fast_forward: ${sessionTag}Superseded by edit (${elapsedStr})`;
111
113
  await sealStatus(adapter, statusMsg, supersededText, buildSealedStatusActionBlocks(supersededText, { channel, sessionName, isDm: true }));
112
114
  return;
113
115
  }
@@ -116,20 +118,21 @@ export async function handleAgentError({ error, channel, adapter, statusMsg, sta
116
118
  await conversationLedger.completeTurn(channel, userMessageTs, { executionId });
117
119
  if (error?.cancelled) {
118
120
  finalizeLocalExecution({ executionId, status: 'failed', error, durationS: elapsedS });
119
- const cancelledText = `:octagonal_sign: ${sessionTag}Cancelled (${elapsedStr}s)`;
121
+ const cancelledText = `:octagonal_sign: ${sessionTag}Cancelled (${elapsedStr})`;
120
122
  await sealStatus(adapter, statusMsg, cancelledText, buildSealedStatusActionBlocks(cancelledText, { channel, sessionName, isDm: true }));
121
123
  return;
122
124
  }
123
125
  log.error('Agent error:', error.message);
124
126
  finalizeLocalExecution({ executionId, status: 'failed', error, durationS: elapsedS });
125
- const errorText = `:x: ${sessionTag}Error (${elapsedStr}s)`;
127
+ const errorText = `:x: ${sessionTag}Error (${elapsedStr})`;
126
128
  await sealStatus(adapter, statusMsg, errorText, buildSealedStatusActionBlocks(errorText, { channel, sessionName, isDm: true }));
129
+ const errorDest = { type: 'interactive-reply', conduit: channel, sessionId: resolvedSessionId ?? '' };
127
130
  const queue = getOutboundQueue();
128
131
  if (queue) {
129
- await durablePost(queue, adapter, channel, { text: `Error: ${error.message}` }, threadTs ? { threadId: threadTs } : undefined);
132
+ await durablePost(queue, adapter, errorDest, { text: `Error: ${error.message}` }, threadTs ? { threadId: threadTs } : undefined);
130
133
  }
131
134
  else {
132
- await adapter.postMessage(channel, { text: `Error: ${error.message}` }, threadTs ? { threadId: threadTs } : undefined);
135
+ await adapter.postMessage(errorDest, { text: `Error: ${error.message}` }, threadTs ? { threadId: threadTs } : undefined);
133
136
  }
134
137
  }
135
138
  async function persistErrorSession(resolvedSessionId, sessionName, channel) {
@@ -140,14 +143,15 @@ async function persistErrorSession(resolvedSessionId, sessionName, channel) {
140
143
  await backfillLedgerSessionId({ sessionId: resolvedSessionId }, channel);
141
144
  if (!sessionName)
142
145
  return;
143
- const existing = await sessionRegistryRepo.lookupBySessionId(resolvedSessionId);
146
+ const existing = await sessionStore.lookupBySessionId(resolvedSessionId);
144
147
  if (!existing) {
145
- await sessionRegistryRepo.registerSession(sessionName, { sessionId: resolvedSessionId, channel, backend, kind: 'local', profileName: getActiveProfile(channel) });
148
+ await sessionStore.registerSession(sessionName, { sessionId: resolvedSessionId, channel, backend, kind: 'local', profileName: getActiveProfile(channel), projectId: (await projectDirRepo.getChannelProject(channel)) ?? 'general' });
146
149
  }
147
150
  }
148
151
  // --- AskUserQuestion resume ---
149
152
  export async function resumeAskUserQuestionGroup({ adapter, group, responseText }) {
150
- const statusMsg = await adapter.postMessage(group.channel, { text: ':hourglass_flowing_sand: Processing AskUserQuestion response...' });
153
+ const askDest = { type: 'interactive-reply', conduit: group.channel, sessionId: group.sessionId };
154
+ const statusMsg = await adapter.postMessage(askDest, { text: ':hourglass_flowing_sand: Processing AskUserQuestion response...' });
151
155
  const startTime = Date.now();
152
156
  let executionId = null;
153
157
  let handle;
@@ -155,7 +159,7 @@ export async function resumeAskUserQuestionGroup({ adapter, group, responseText
155
159
  const askBackend = resolveBackendForChannel(group.channel);
156
160
  const execution = executionRegistry.startLocalExecution({
157
161
  kind: 'local', channel: group.channel,
158
- project: detectProject(responseText),
162
+ project: projectStore.resolveFromMessage(responseText)?.id ?? 'general',
159
163
  trigger: 'ask-user-question',
160
164
  backend: askBackend, billingMode: getClaudeMode(),
161
165
  sessionId: group.sessionId, label: responseText,
@@ -163,12 +167,12 @@ export async function resumeAskUserQuestionGroup({ adapter, group, responseText
163
167
  executionId = execution.id;
164
168
  const askQueue = getOutboundQueue();
165
169
  const askDurable = askQueue ? buildDurableHooks(askQueue) : null;
166
- const onAssistantMsg = makeStreamingMessageCallback(adapter, group.channel, null, null, askDurable);
167
- handle = runAgent(responseText, { channel: group.channel, sessionId: group.sessionId, files: [], project: detectProject(responseText), trigger: 'ask-user-question', onAssistantMessage: onAssistantMsg });
170
+ const onAssistantMsg = makeStreamingMessageCallback(adapter, askDest, null, null, askDurable);
171
+ handle = runAgent(responseText, { channel: group.channel, sessionId: group.sessionId, files: [], project: projectStore.resolveFromMessage(responseText)?.id ?? 'general', trigger: 'ask-user-question', onAssistantMessage: onAssistantMsg });
168
172
  runningExecutions.register(group.channel, { threadId: group.threadId ?? null, channel: group.channel, agentSlotId: null, executionId, kill: () => handle.kill(), backend: askBackend });
169
173
  const result = await handle.promise;
170
174
  runningExecutions.complete(group.channel, result?.total_cost_usd ?? 0);
171
- await maybeNotifyCodexLowUsage({ adapter, channel: group.channel, result });
175
+ await maybeNotifyCodexLowUsage({ adapter, result });
172
176
  await handleAgentSuccess({ result, channel: group.channel, adapter, statusMsg, startTime, userMessage: responseText, executionId, trigger: 'ask-user-question', onAssistantMessage: onAssistantMsg });
173
177
  }
174
178
  catch (error) {
@@ -193,12 +197,13 @@ export function reprocessMessage(channel, text, adapter, opts) {
193
197
  async function executeRetry(channel, text, adapter, opts) {
194
198
  const startTime = Date.now();
195
199
  const sessionId = opts.sessionId ?? await getSessionAsync(channel, resolveBackendForChannel(channel));
196
- const sessionName = opts.sessionName || await sessionRegistryRepo.generateSessionName();
200
+ const sessionName = opts.sessionName || await sessionStore.generateSessionName();
197
201
  const userMessageTs = opts.originalTs;
202
+ const retryDest = { type: 'interactive-reply', conduit: channel, sessionId: sessionId ?? '' };
198
203
  const retryPrefix = ':arrows_counterclockwise: Retry (edited) | ';
199
204
  const retryStatusText = retryPrefix + buildUserProcessingMessage({ startTime, profileName: getActiveProfile(channel), sessionName, sessionId });
200
205
  const retryBlocksTemplate = { channel, sessionName, isDm: true };
201
- const statusMsg = await adapter.postMessage(channel, {
206
+ const statusMsg = await adapter.postMessage(retryDest, {
202
207
  text: retryStatusText,
203
208
  richBlocks: buildStatusActionBlocks(retryStatusText, retryBlocksTemplate),
204
209
  });
@@ -206,25 +211,25 @@ async function executeRetry(channel, text, adapter, opts) {
206
211
  updateRetryPermalinks(adapter, channel, userMessageTs, statusMsg, opts.supersededStatusTimestamps, retryPrefix, startTime, sessionName, sessionId);
207
212
  await initTurnTracking(channel, sessionId, sessionName, userMessageTs, text, statusMsg.messageId);
208
213
  const onMessagePosted = (ref) => void conversationLedger.addResponseTs(channel, userMessageTs, ref.messageId).catch((e) => log.error(e));
209
- await runRetryAgent({ channel, text, adapter, statusMsg, startTime, sessionId, sessionName, userMessageTs, retryPrefix, onMessagePosted });
214
+ await runRetryAgent({ channel, text, adapter, statusMsg, startTime, sessionId, sessionName, userMessageTs, retryPrefix, onMessagePosted, retryDest });
210
215
  }
211
- async function runRetryAgent({ channel, text, adapter, statusMsg, startTime, sessionId, sessionName, userMessageTs, retryPrefix, onMessagePosted }) {
216
+ async function runRetryAgent({ channel, text, adapter, statusMsg, startTime, sessionId, sessionName, userMessageTs, retryPrefix, onMessagePosted, retryDest }) {
212
217
  const agentMessage = normalizeSkillCommandPrefix(text || '');
213
218
  let executionId = null;
214
219
  let handle;
215
220
  try {
216
221
  const retryBackend = resolveBackendForChannel(channel);
217
222
  executionId = executionRegistry.startLocalExecution({
218
- kind: 'local', channel, project: detectProject(text || ''),
223
+ kind: 'local', channel, project: projectStore.resolveFromMessage(text || '')?.id ?? 'general',
219
224
  trigger: 'edit-retry', backend: retryBackend, billingMode: getClaudeMode(), sessionId, label: agentMessage,
220
225
  }).id;
221
226
  const retryQueue = getOutboundQueue();
222
227
  const retryDurable = retryQueue ? buildDurableHooks(retryQueue) : null;
223
- const onAssistantMsg = makeStreamingMessageCallback(adapter, channel, null, onMessagePosted, retryDurable);
228
+ const onAssistantMsg = makeStreamingMessageCallback(adapter, retryDest, null, onMessagePosted, retryDurable);
224
229
  setStreamingCallback(channel, onAssistantMsg);
225
230
  handle = runAgent(agentMessage, {
226
231
  channel, sessionId, files: [], profileName: getActiveProfile(channel),
227
- project: detectProject(text || ''), trigger: 'edit-retry',
232
+ project: projectStore.resolveFromMessage(text || '')?.id ?? 'general', trigger: 'edit-retry',
228
233
  onFallback: makeFallbackNotifier(channel, statusMsg, adapter),
229
234
  isUserInitiated: true, onAssistantMessage: onAssistantMsg,
230
235
  onProgress: buildRetryProgressUpdater(adapter, channel, statusMsg, retryPrefix, startTime, sessionName, sessionId),
@@ -233,10 +238,10 @@ async function runRetryAgent({ channel, text, adapter, statusMsg, startTime, ses
233
238
  const result = await handle.promise;
234
239
  runningExecutions.complete(channel, result?.total_cost_usd ?? 0);
235
240
  clearStreamingCallback(channel);
236
- await maybeNotifyCodexLowUsage({ adapter, channel, result });
241
+ await maybeNotifyCodexLowUsage({ adapter, result });
237
242
  if (result?.rateLimited) {
238
243
  const { elapsedStr } = computeElapsed(startTime);
239
- const rateLimitText = `:warning: ${buildSessionTag(sessionName, sessionId)}Rate limited \u2014 all fallbacks exhausted (${elapsedStr}s)`;
244
+ const rateLimitText = `:warning: ${buildSessionTag(sessionName, sessionId)}Rate limited \u2014 all fallbacks exhausted (${elapsedStr})`;
240
245
  await sealStatus(adapter, statusMsg, rateLimitText, buildSealedStatusActionBlocks(rateLimitText, { channel, sessionName, isDm: true }));
241
246
  }
242
247
  else {
@@ -45,6 +45,7 @@ export function createCancelHandler(cancelDispatchedTask, router) {
45
45
  });
46
46
  }
47
47
  return async function handleCancelCmd(channel, adapter, trimmedMessage) {
48
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
48
49
  const args = trimmedMessage.split(/\s+/).slice(1);
49
50
  if (args.length > 0) {
50
51
  const firstArg = args[0];
@@ -52,7 +53,7 @@ export function createCancelHandler(cancelDispatchedTask, router) {
52
53
  if (firstArg === '--all') {
53
54
  const executions = runningExecutions.getAll().filter(e => e.channel === channel);
54
55
  if (executions.length === 0) {
55
- await adapter.postMessage(channel, { text: 'Nothing running to cancel.' });
56
+ await adapter.postMessage(dest, { text: 'Nothing running to cancel.' });
56
57
  return;
57
58
  }
58
59
  for (const exec of executions) {
@@ -65,7 +66,7 @@ export function createCancelHandler(cancelDispatchedTask, router) {
65
66
  runningExecutions.killByKey(exec.registryKey);
66
67
  }
67
68
  channelQueues.delete(channel);
68
- await adapter.postMessage(channel, { text: `:octagonal_sign: Cancelled ${executions.length} execution(s).` });
69
+ await adapter.postMessage(dest, { text: `:octagonal_sign: Cancelled ${executions.length} execution(s).` });
69
70
  return;
70
71
  }
71
72
  // Thread ID pattern: kill by threadId + cancel thread store record
@@ -77,27 +78,27 @@ export function createCancelHandler(cancelDispatchedTask, router) {
77
78
  await setSessionAsync(channel, exec.sessionId, getActiveBackend()).catch(() => { });
78
79
  }
79
80
  log.info('Cancel requested for thread:', firstArg);
80
- await adapter.postMessage(channel, { text: `:octagonal_sign: Thread \`${firstArg}\` cancelled.` });
81
+ await adapter.postMessage(dest, { text: `:octagonal_sign: Thread \`${firstArg}\` cancelled.` });
81
82
  }
82
83
  else {
83
- await adapter.postMessage(channel, { text: `No running thread \`${firstArg}\` found to cancel.` });
84
+ await adapter.postMessage(dest, { text: `No running thread \`${firstArg}\` found to cancel.` });
84
85
  }
85
86
  return;
86
87
  }
87
88
  // Fallback: dispatched-task cancellation
88
89
  if (!cancelDispatchedTask) {
89
- await adapter.postMessage(channel, { text: 'Dispatched-task cancellation is not available in this process.' });
90
+ await adapter.postMessage(dest, { text: 'Dispatched-task cancellation is not available in this process.' });
90
91
  return;
91
92
  }
92
93
  const result = await cancelDispatchedTask({ taskId: firstArg, channel });
93
- await adapter.postMessage(channel, { text: result.message });
94
+ await adapter.postMessage(dest, { text: result.message });
94
95
  return;
95
96
  }
96
97
  // No args: check how many executions are running on this channel
97
98
  const executions = runningExecutions.getAll().filter(e => e.channel === channel);
98
99
  // 0 executions: nothing to cancel
99
100
  if (executions.length === 0) {
100
- await adapter.postMessage(channel, { text: 'Nothing running to cancel.' });
101
+ await adapter.postMessage(dest, { text: 'Nothing running to cancel.' });
101
102
  return;
102
103
  }
103
104
  // 1 execution: cancel directly (existing default behavior)
@@ -111,7 +112,7 @@ export function createCancelHandler(cancelDispatchedTask, router) {
111
112
  await setSessionAsync(channel, exec.sessionId, getActiveBackend()).catch(() => { });
112
113
  }
113
114
  channelQueues.delete(channel);
114
- await adapter.postMessage(channel, { text: ':octagonal_sign: Cancelled. Session preserved — next message will resume.' });
115
+ await adapter.postMessage(dest, { text: ':octagonal_sign: Cancelled. Session preserved — next message will resume.' });
115
116
  return;
116
117
  }
117
118
  // 2+ executions: show interactive list with cancel buttons
@@ -1,19 +1,20 @@
1
- import { channelRepo } from '../../../store/channel-repo.js';
1
+ import { projectStore } from '../../../domain/projects/index.js';
2
2
  import { projectDirRepo } from '../../../store/project-dir-repo.js';
3
3
  import { getMachineRegistry } from '../../../domain/tasks/dispatch-utils.js';
4
4
  export async function handleProjectsCmd(channel, adapter) {
5
- const projects = await channelRepo.listProjects();
5
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
6
+ const projects = projectStore.list().map(p => p.id);
6
7
  if (projects.length === 0) {
7
- await adapter.postMessage(channel, { text: 'No projects found.' });
8
+ await adapter.postMessage(dest, { text: 'No projects found.' });
8
9
  return;
9
10
  }
10
- const registrations = await channelRepo.getAllRegistrations();
11
+ const registrations = await adapter.getProjectConduits();
11
12
  const lines = projects.map(p => {
12
13
  const ch = registrations[p];
13
14
  const status = ch ? ` → <#${ch}>` : '';
14
15
  return `• \`${p}\`${status}`;
15
16
  });
16
- await adapter.postMessage(channel, { text: `*Projects*\n${lines.join('\n')}` });
17
+ await adapter.postMessage(dest, { text: `*Projects*\n${lines.join('\n')}` });
17
18
  }
18
19
  const MAX_PROJECT_BUTTONS = 10;
19
20
  export function createRegisterHandler(router) {
@@ -24,7 +25,7 @@ export function createRegisterHandler(router) {
24
25
  return;
25
26
  const project = ctx.value;
26
27
  try {
27
- await channelRepo.setProjectChannel(project, ctx.channelId);
28
+ await adapter.bindProjectConduit(project, ctx.channelId);
28
29
  if (ctx.messageRef) {
29
30
  await adapter.updateMessage(ctx.messageRef, {
30
31
  text: `:white_check_mark: Registered for \`${project}\` task notifications.`,
@@ -41,21 +42,22 @@ export function createRegisterHandler(router) {
41
42
  });
42
43
  }
43
44
  return async function handleRegisterCmdInteractive(channel, adapter, trimmedMessage) {
45
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
44
46
  const args = trimmedMessage.split(/\s+/).slice(1);
45
47
  if (args.length > 0) {
46
48
  const project = args[0];
47
- const projects = await channelRepo.listProjects();
49
+ const projects = projectStore.list().map(p => p.id);
48
50
  if (!projects.includes(project)) {
49
- await adapter.postMessage(channel, { text: `:x: Unknown project: \`${project}\`\nAvailable: ${projects.map(p => `\`${p}\``).join(', ')}` });
51
+ await adapter.postMessage(dest, { text: `:x: Unknown project: \`${project}\`\nAvailable: ${projects.map(p => `\`${p}\``).join(', ')}` });
50
52
  return;
51
53
  }
52
- await channelRepo.setProjectChannel(project, channel);
53
- await adapter.postMessage(channel, { text: `:white_check_mark: This channel is now registered for project \`${project}\` task notifications.` });
54
+ await adapter.bindProjectConduit(project, channel);
55
+ await adapter.postMessage(dest, { text: `:white_check_mark: This channel is now registered for project \`${project}\` task notifications.` });
54
56
  return;
55
57
  }
56
- const registrations = await channelRepo.getAllRegistrations();
58
+ const registrations = await adapter.getProjectConduits();
57
59
  const bound = Object.entries(registrations).filter(([, ch]) => ch === channel).map(([p]) => p);
58
- const projects = await channelRepo.listProjects();
60
+ const projects = projectStore.list().map(p => p.id);
59
61
  const unbound = projects.filter(p => !bound.includes(p));
60
62
  const lines = [];
61
63
  if (bound.length > 0) {
@@ -69,7 +71,7 @@ export function createRegisterHandler(router) {
69
71
  }
70
72
  const text = lines.join('\n');
71
73
  if (!router || unbound.length === 0) {
72
- await adapter.postMessage(channel, { text });
74
+ await adapter.postMessage(dest, { text });
73
75
  return;
74
76
  }
75
77
  return {
@@ -91,19 +93,21 @@ export async function handleRegisterCmd(channel, adapter, trimmedMessage) {
91
93
  await handler(channel, adapter, trimmedMessage);
92
94
  }
93
95
  export async function handleUnregisterCmd(channel, adapter, trimmedMessage) {
96
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
94
97
  const args = trimmedMessage.split(/\s+/).slice(1);
95
98
  if (args.length === 0) {
96
- await adapter.postMessage(channel, { text: 'Usage: `!unregister <project>`' });
99
+ await adapter.postMessage(dest, { text: 'Usage: `!unregister <project>`' });
97
100
  return;
98
101
  }
99
102
  const project = args[0];
100
- const current = await channelRepo.getProjectChannel(project);
103
+ const registrations = await adapter.getProjectConduits();
104
+ const current = registrations[project] ?? null;
101
105
  if (!current || current !== channel) {
102
- await adapter.postMessage(channel, { text: `:x: This channel is not registered for project \`${project}\`.` });
106
+ await adapter.postMessage(dest, { text: `:x: This channel is not registered for project \`${project}\`.` });
103
107
  return;
104
108
  }
105
- await channelRepo.removeProjectChannel(project);
106
- await adapter.postMessage(channel, { text: `:white_check_mark: Unregistered this channel from project \`${project}\`.` });
109
+ await adapter.unbindProjectConduit(project);
110
+ await adapter.postMessage(dest, { text: `:white_check_mark: Unregistered this channel from project \`${project}\`.` });
107
111
  }
108
112
  function buildProjectDirModal(channel) {
109
113
  const machines = Object.keys(getMachineRegistry());
@@ -142,13 +146,14 @@ export function createProjectDirHandler(router) {
142
146
  if (!adapter)
143
147
  return;
144
148
  const { channel } = JSON.parse(ctx.privateMetadata);
149
+ const modalDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
145
150
  const project = ctx.values?.pd_project?.text?.value;
146
151
  const machine = ctx.values?.pd_machine?.selection?.selectedOption?.value;
147
152
  const dirPath = ctx.values?.pd_path?.text?.value;
148
153
  if (!project || !machine || !dirPath)
149
154
  return;
150
155
  await projectDirRepo.setProjectDir(project, machine, dirPath);
151
- await adapter.postMessage(channel, {
156
+ await adapter.postMessage(modalDest, {
152
157
  text: `:white_check_mark: \`${project}\` on \`${machine}\` → \`${dirPath}\``,
153
158
  });
154
159
  },
@@ -156,37 +161,38 @@ export function createProjectDirHandler(router) {
156
161
  });
157
162
  }
158
163
  return async function handleProjectDirCmdInteractive(channel, adapter, trimmedMessage) {
164
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
159
165
  const args = trimmedMessage.split(/\s+/).slice(1);
160
166
  if (args.length > 0) {
161
167
  if (args.length < 2) {
162
- await adapter.postMessage(channel, { text: ':x: Usage: `!project-dir <project> <machine> <path>` or `!project-dir <project> <machine> --remove`' });
168
+ await adapter.postMessage(dest, { text: ':x: Usage: `!project-dir <project> <machine> <path>` or `!project-dir <project> <machine> --remove`' });
163
169
  return;
164
170
  }
165
171
  const [project, machine] = args;
166
172
  const validMachines = Object.keys(getMachineRegistry());
167
173
  if (!validMachines.includes(machine)) {
168
- await adapter.postMessage(channel, { text: `:x: Unknown machine: \`${machine}\`\nValid: ${validMachines.map(m => `\`${m}\``).join(', ')}` });
174
+ await adapter.postMessage(dest, { text: `:x: Unknown machine: \`${machine}\`\nValid: ${validMachines.map(m => `\`${m}\``).join(', ')}` });
169
175
  return;
170
176
  }
171
177
  if (args.length === 2 || args[2] === '--remove') {
172
178
  if (args[2] === '--remove') {
173
179
  await projectDirRepo.removeProjectDir(project, machine);
174
- await adapter.postMessage(channel, { text: `:white_check_mark: Removed \`${project}\` directory on \`${machine}\`.` });
180
+ await adapter.postMessage(dest, { text: `:white_check_mark: Removed \`${project}\` directory on \`${machine}\`.` });
175
181
  }
176
182
  else {
177
183
  const dir = await projectDirRepo.getProjectDir(project, machine);
178
184
  if (dir) {
179
- await adapter.postMessage(channel, { text: `\`${project}\` on \`${machine}\` → \`${dir}\`` });
185
+ await adapter.postMessage(dest, { text: `\`${project}\` on \`${machine}\` → \`${dir}\`` });
180
186
  }
181
187
  else {
182
- await adapter.postMessage(channel, { text: `No directory registered for \`${project}\` on \`${machine}\`.` });
188
+ await adapter.postMessage(dest, { text: `No directory registered for \`${project}\` on \`${machine}\`.` });
183
189
  }
184
190
  }
185
191
  return;
186
192
  }
187
193
  const dirPath = args.slice(2).join(' ');
188
194
  await projectDirRepo.setProjectDir(project, machine, dirPath);
189
- await adapter.postMessage(channel, { text: `:white_check_mark: \`${project}\` on \`${machine}\` → \`${dirPath}\`` });
195
+ await adapter.postMessage(dest, { text: `:white_check_mark: \`${project}\` on \`${machine}\` → \`${dirPath}\`` });
190
196
  return;
191
197
  }
192
198
  const allDirs = await projectDirRepo.getAllProjectDirs();
@@ -196,7 +202,7 @@ export function createProjectDirHandler(router) {
196
202
  : ['No project directories registered.'];
197
203
  const text = `*Project Directories*\n${lines.join('\n')}`;
198
204
  if (!router) {
199
- await adapter.postMessage(channel, { text });
205
+ await adapter.postMessage(dest, { text });
200
206
  return;
201
207
  }
202
208
  return {
@@ -1,13 +1,15 @@
1
1
  import { formatCostReport, checkBudget, setBudget } from '../../../domain/costs/cost-tracker.js';
2
2
  export async function handleCostCmd(channel, adapter, trimmedMessage) {
3
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
3
4
  const project = trimmedMessage.split(/\s+/).slice(1).join(' ').trim() || null;
4
- await adapter.postMessage(channel, { text: await formatCostReport(project) });
5
+ await adapter.postMessage(dest, { text: await formatCostReport(project) });
5
6
  }
6
7
  export async function handleBudgetCmd(channel, adapter, trimmedMessage) {
8
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
7
9
  const args = trimmedMessage.split(/\s+/).slice(1);
8
10
  if (args.length === 0) {
9
11
  const b = await checkBudget();
10
- await adapter.postMessage(channel, {
12
+ await adapter.postMessage(dest, {
11
13
  text: `*Budget*\n• Daily: $${b.dailyBudget} (spent: $${b.dailySpent.toFixed(2)}, remaining: $${b.dailyRemaining.toFixed(2)})\n• Monthly: $${b.monthlyBudget} (spent: $${b.monthlySpent.toFixed(2)}, remaining: $${b.monthlyRemaining.toFixed(2)})`,
12
14
  });
13
15
  return;
@@ -18,5 +20,5 @@ export async function handleBudgetCmd(channel, adapter, trimmedMessage) {
18
20
  daily_usd: daily ? parseFloat(daily) : undefined,
19
21
  monthly_usd: monthly ? parseFloat(monthly) : undefined,
20
22
  });
21
- await adapter.postMessage(channel, { text: `:white_check_mark: Budget updated: $${result.daily_usd}/day, $${result.monthly_usd}/month` });
23
+ await adapter.postMessage(dest, { text: `:white_check_mark: Budget updated: $${result.daily_usd}/day, $${result.monthly_usd}/month` });
22
24
  }
@@ -64,9 +64,10 @@ export function createDevicesHandler(router) {
64
64
  });
65
65
  }
66
66
  return async function handleDevicesCmd(channel, adapter) {
67
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
67
68
  const text = buildDevicesText();
68
69
  if (!router) {
69
- await adapter.postMessage(channel, { text });
70
+ await adapter.postMessage(dest, { text });
70
71
  return;
71
72
  }
72
73
  return {
@@ -5,23 +5,24 @@ import { threadStore } from '../../../store/thread-repo.js';
5
5
  import { resolveProfile } from '../../../domain/agents/profile-manager.js';
6
6
  const USAGE = 'Usage: `!dispatch <threadId> [--profile <name>]`';
7
7
  export async function handleDispatchCmd(channel, adapter, trimmedMessage) {
8
+ const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
8
9
  const args = trimmedMessage.split(/\s+/).slice(1);
9
10
  if (args.length === 0) {
10
- await adapter.postMessage(channel, { text: USAGE });
11
+ await adapter.postMessage(dest, { text: USAGE });
11
12
  return;
12
13
  }
13
14
  const threadId = args[0];
14
15
  const thread = threadStore.get(threadId);
15
16
  if (!thread) {
16
- await adapter.postMessage(channel, { text: `:x: Thread not found: \`${threadId}\`` });
17
+ await adapter.postMessage(dest, { text: `:x: Thread not found: \`${threadId}\`` });
17
18
  return;
18
19
  }
19
20
  if (thread.metadata?.trigger !== 'task-dispatch') {
20
- await adapter.postMessage(channel, { text: `:x: Thread \`${threadId}\` is not a dispatch thread.` });
21
+ await adapter.postMessage(dest, { text: `:x: Thread \`${threadId}\` is not a dispatch thread.` });
21
22
  return;
22
23
  }
23
24
  if (thread.status === 'completed' || thread.status === 'failed' || thread.status === 'cancelled' || thread.status === 'aborted') {
24
- await adapter.postMessage(channel, {
25
+ await adapter.postMessage(dest, {
25
26
  text: `:warning: Dispatch \`${threadId.substring(0, 12)}\` is \`${thread.status}\`. Profile override will only apply if the thread is continued via \`!thread add\`.${thread.status === 'completed' ? '' : ''}`,
26
27
  });
27
28
  // Allow the change to go through even for completed threads — it takes effect if continued.
@@ -29,7 +30,7 @@ export async function handleDispatchCmd(channel, adapter, trimmedMessage) {
29
30
  const profileIdx = args.indexOf('--profile');
30
31
  if (profileIdx === -1 || profileIdx + 1 >= args.length) {
31
32
  const current = thread.metadata?.profileOverride || '(not set)';
32
- await adapter.postMessage(channel, { text: `Dispatch \`${threadId.substring(0, 12)}\`: current \`profileOverride\` = \`${current}\`\n${USAGE}` });
33
+ await adapter.postMessage(dest, { text: `Dispatch \`${threadId.substring(0, 12)}\`: current \`profileOverride\` = \`${current}\`\n${USAGE}` });
33
34
  return;
34
35
  }
35
36
  const profileName = args[profileIdx + 1];
@@ -37,13 +38,13 @@ export async function handleDispatchCmd(channel, adapter, trimmedMessage) {
37
38
  resolveProfile(profileName);
38
39
  }
39
40
  catch {
40
- await adapter.postMessage(channel, { text: `:x: Unknown profile: \`${profileName}\`. Use \`!profile\` to see available profiles.` });
41
+ await adapter.postMessage(dest, { text: `:x: Unknown profile: \`${profileName}\`. Use \`!profile\` to see available profiles.` });
41
42
  return;
42
43
  }
43
44
  await threadStore.mutate(threadId, (t) => {
44
45
  t.metadata = { ...t.metadata, profileOverride: profileName };
45
46
  });
46
- await adapter.postMessage(channel, {
47
+ await adapter.postMessage(dest, {
47
48
  text: `:white_check_mark: Dispatch \`${threadId.substring(0, 12)}\`: \`profileOverride\` set to \`${profileName}\`. Next step will use this profile.`,
48
49
  });
49
50
  }
@@ -22,6 +22,7 @@ const log = createLogger('command-handler');
22
22
  */
23
23
  async function executeCommand(handler, channel, adapter, trimmedMessage, _commandName, threadTs) {
24
24
  const result = await handler(channel, adapter, trimmedMessage, threadTs);
25
+ const cmdDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
25
26
  if (result && typeof result === 'object' && 'text' in result) {
26
27
  if (result.actions && result.actions.length > 0) {
27
28
  // Merge actions into richBlocks as a trailing actions block,
@@ -31,13 +32,13 @@ async function executeCommand(handler, channel, adapter, trimmedMessage, _comman
31
32
  ...(result.richBlocks || []),
32
33
  { type: 'actions', elements: result.actions },
33
34
  ];
34
- await adapter.postMessage(channel, {
35
+ await adapter.postMessage(cmdDest, {
35
36
  text: result.text,
36
37
  richBlocks: blocks,
37
38
  });
38
39
  }
39
40
  else {
40
- await adapter.postMessage(channel, {
41
+ await adapter.postMessage(cmdDest, {
41
42
  text: result.text,
42
43
  richBlocks: result.richBlocks,
43
44
  });
@@ -49,7 +50,8 @@ const catchHandlerError = (promise, cmd, channel, adapter, threadTs) => {
49
50
  log.error(`Error in ${cmd}:`, err?.message || err);
50
51
  if (err?.data)
51
52
  log.error(`Slack error data:`, JSON.stringify(err.data));
52
- adapter.postMessage(channel, { text: `:x: Command error: ${err?.message || 'unknown error'}` }).catch(() => { });
53
+ const cmdDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
54
+ adapter.postMessage(cmdDest, { text: `:x: Command error: ${err?.message || 'unknown error'}` }).catch(() => { });
53
55
  });
54
56
  };
55
57
  export function registerCommands(deps) {
@@ -119,7 +121,8 @@ export function registerCommands(deps) {
119
121
  }
120
122
  if (trimmedMessage.startsWith('!')) {
121
123
  const cmd = trimmedMessage.split(/\s+/)[0];
122
- adapter.postMessage(channel, { text: `:x: Unknown command: \`${cmd}\`. Run \`!help\` for available commands.` });
124
+ const cmdDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
125
+ adapter.postMessage(cmdDest, { text: `:x: Unknown command: \`${cmd}\`. Run \`!help\` for available commands.` });
123
126
  return true;
124
127
  }
125
128
  return false;