@lumenflow/cli 5.5.0 → 5.7.12

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 (213) hide show
  1. package/README.md +42 -40
  2. package/dist/db-journal-recover.js +400 -0
  3. package/dist/db-journal-recover.js.map +1 -0
  4. package/dist/docs-sync.js +8 -3
  5. package/dist/docs-sync.js.map +1 -1
  6. package/dist/gate-defaults.js +37 -0
  7. package/dist/gate-defaults.js.map +1 -1
  8. package/dist/gates/monolithic-file-contention-guard.js +167 -0
  9. package/dist/gates/monolithic-file-contention-guard.js.map +1 -0
  10. package/dist/gates/prod-migration-drift.js +207 -0
  11. package/dist/gates/prod-migration-drift.js.map +1 -0
  12. package/dist/gates/test-over-deletion-guard.js +255 -0
  13. package/dist/gates/test-over-deletion-guard.js.map +1 -0
  14. package/dist/gates-runners.js +44 -3
  15. package/dist/gates-runners.js.map +1 -1
  16. package/dist/gates.js +3 -2
  17. package/dist/gates.js.map +1 -1
  18. package/dist/lumenflow-setup.js +144 -0
  19. package/dist/lumenflow-setup.js.map +1 -0
  20. package/dist/lumenflow-upgrade.js +2 -1
  21. package/dist/lumenflow-upgrade.js.map +1 -1
  22. package/dist/mem-create.js +10 -1
  23. package/dist/mem-create.js.map +1 -1
  24. package/dist/mem-signal.js +21 -4
  25. package/dist/mem-signal.js.map +1 -1
  26. package/dist/orchestrate-initiative.js +28 -3
  27. package/dist/orchestrate-initiative.js.map +1 -1
  28. package/dist/public-manifest.js +17 -0
  29. package/dist/public-manifest.js.map +1 -1
  30. package/dist/release.js +53 -18
  31. package/dist/release.js.map +1 -1
  32. package/dist/wu-done-gates.js +13 -9
  33. package/dist/wu-done-gates.js.map +1 -1
  34. package/dist/wu-edit-operations.js +74 -0
  35. package/dist/wu-edit-operations.js.map +1 -1
  36. package/dist/wu-edit-validators.js +58 -0
  37. package/dist/wu-edit-validators.js.map +1 -1
  38. package/dist/wu-edit.js +106 -4
  39. package/dist/wu-edit.js.map +1 -1
  40. package/dist/wu-prep.js +41 -7
  41. package/dist/wu-prep.js.map +1 -1
  42. package/dist/wu-recover.js +6 -0
  43. package/dist/wu-recover.js.map +1 -1
  44. package/dist/wu-release.js +120 -2
  45. package/dist/wu-release.js.map +1 -1
  46. package/dist/wu-sizing-validation.js +47 -17
  47. package/dist/wu-sizing-validation.js.map +1 -1
  48. package/dist/wu-status.js +33 -0
  49. package/dist/wu-status.js.map +1 -1
  50. package/package.json +13 -11
  51. package/packs/agent-runtime/package.json +1 -1
  52. package/packs/sidekick/package.json +1 -1
  53. package/packs/software-delivery/package.json +1 -1
  54. package/templates/core/AGENTS.md.template +67 -3
  55. package/templates/core/LUMENFLOW.md.template +197 -47
  56. package/packs/agent-runtime/agent-heartbeat.ts +0 -163
  57. package/packs/agent-runtime/auto-session-integration.ts +0 -888
  58. package/packs/agent-runtime/capability-factory.ts +0 -104
  59. package/packs/agent-runtime/constants.ts +0 -21
  60. package/packs/agent-runtime/delegation-registry-schema.ts +0 -220
  61. package/packs/agent-runtime/delegation-registry-store.ts +0 -269
  62. package/packs/agent-runtime/delegation-tree.ts +0 -328
  63. package/packs/agent-runtime/index.ts +0 -20
  64. package/packs/agent-runtime/manifest.ts +0 -348
  65. package/packs/agent-runtime/memory-coordination-contract.ts +0 -86
  66. package/packs/agent-runtime/orchestration.ts +0 -2027
  67. package/packs/agent-runtime/pack-registration.ts +0 -110
  68. package/packs/agent-runtime/policy-factory.ts +0 -165
  69. package/packs/agent-runtime/remote-controls/index.ts +0 -7
  70. package/packs/agent-runtime/remote-controls/operations.ts +0 -405
  71. package/packs/agent-runtime/remote-controls/port.ts +0 -48
  72. package/packs/agent-runtime/remote-controls/state-store.ts +0 -258
  73. package/packs/agent-runtime/remote-controls/types.ts +0 -105
  74. package/packs/agent-runtime/session-schema.ts +0 -467
  75. package/packs/agent-runtime/tool-impl/agent-turn-tools.ts +0 -793
  76. package/packs/agent-runtime/tool-impl/index.ts +0 -6
  77. package/packs/agent-runtime/tool-impl/provider-adapters.ts +0 -1245
  78. package/packs/agent-runtime/tool-impl/remote-controls.mock.ts +0 -256
  79. package/packs/agent-runtime/tool-impl/remote-controls.ts +0 -273
  80. package/packs/agent-runtime/tools/index.ts +0 -4
  81. package/packs/agent-runtime/tools/types.ts +0 -47
  82. package/packs/agent-runtime/turn-lifecycle-events.ts +0 -590
  83. package/packs/agent-runtime/types.ts +0 -128
  84. package/packs/agent-runtime/vitest.config.ts +0 -11
  85. package/packs/sidekick/channel-ingress.ts +0 -137
  86. package/packs/sidekick/constants.ts +0 -10
  87. package/packs/sidekick/index.ts +0 -8
  88. package/packs/sidekick/manifest-schema.ts +0 -49
  89. package/packs/sidekick/manifest.ts +0 -512
  90. package/packs/sidekick/pack-registration.ts +0 -110
  91. package/packs/sidekick/policy-factory.ts +0 -38
  92. package/packs/sidekick/sidekick-events.ts +0 -694
  93. package/packs/sidekick/src/adapters/cloud-queue.ts +0 -101
  94. package/packs/sidekick/src/adapters/control-plane-bridge.adapter.ts +0 -386
  95. package/packs/sidekick/src/adapters/filesystem-bridge.adapter.ts +0 -228
  96. package/packs/sidekick/src/domain/channel.types.ts +0 -64
  97. package/packs/sidekick/src/ports/channel-bridge.port.ts +0 -92
  98. package/packs/sidekick/src/routines/commit.ts +0 -74
  99. package/packs/sidekick/tool-impl/channel-tools.ts +0 -577
  100. package/packs/sidekick/tool-impl/channel-transports.ts +0 -75
  101. package/packs/sidekick/tool-impl/index.ts +0 -29
  102. package/packs/sidekick/tool-impl/memory-tools.ts +0 -290
  103. package/packs/sidekick/tool-impl/routine-commit.ts +0 -102
  104. package/packs/sidekick/tool-impl/routine-tools.ts +0 -440
  105. package/packs/sidekick/tool-impl/runtime-context.ts +0 -28
  106. package/packs/sidekick/tool-impl/shared.ts +0 -125
  107. package/packs/sidekick/tool-impl/storage.ts +0 -325
  108. package/packs/sidekick/tool-impl/system-tools.ts +0 -160
  109. package/packs/sidekick/tool-impl/task-tools.ts +0 -506
  110. package/packs/sidekick/tools/channel-tools.ts +0 -53
  111. package/packs/sidekick/tools/index.ts +0 -9
  112. package/packs/sidekick/tools/memory-tools.ts +0 -53
  113. package/packs/sidekick/tools/routine-tools.ts +0 -53
  114. package/packs/sidekick/tools/system-tools.ts +0 -47
  115. package/packs/sidekick/tools/task-tools.ts +0 -61
  116. package/packs/sidekick/tools/types.ts +0 -57
  117. package/packs/sidekick/vitest.config.ts +0 -11
  118. package/packs/software-delivery/constants.ts +0 -10
  119. package/packs/software-delivery/extensions.ts +0 -140
  120. package/packs/software-delivery/gate-policies.ts +0 -134
  121. package/packs/software-delivery/index.ts +0 -8
  122. package/packs/software-delivery/manifest-schema.ts +0 -268
  123. package/packs/software-delivery/manifest.ts +0 -657
  124. package/packs/software-delivery/pack-registration.ts +0 -113
  125. package/packs/software-delivery/src/commands/index.ts +0 -5
  126. package/packs/software-delivery/src/config/delivery-review-contract.ts +0 -256
  127. package/packs/software-delivery/src/config/env-accessors.ts +0 -66
  128. package/packs/software-delivery/src/config/index.ts +0 -8
  129. package/packs/software-delivery/src/config/normalize-config-keys.ts +0 -9
  130. package/packs/software-delivery/src/config/schemas/lumenflow-config-schema-types.ts +0 -460
  131. package/packs/software-delivery/src/config/workspace-reader.ts +0 -375
  132. package/packs/software-delivery/src/constants/backlog-patterns.ts +0 -31
  133. package/packs/software-delivery/src/constants/client-ids.ts +0 -19
  134. package/packs/software-delivery/src/constants/config-contract.ts +0 -7
  135. package/packs/software-delivery/src/constants/docs-layout-presets.ts +0 -50
  136. package/packs/software-delivery/src/constants/duration-constants.ts +0 -20
  137. package/packs/software-delivery/src/constants/gate-constants.ts +0 -32
  138. package/packs/software-delivery/src/constants/index.ts +0 -29
  139. package/packs/software-delivery/src/constants/lock-constants.ts +0 -35
  140. package/packs/software-delivery/src/constants/object-guards.ts +0 -12
  141. package/packs/software-delivery/src/constants/section-headings.ts +0 -107
  142. package/packs/software-delivery/src/constants/wu-cli-constants.ts +0 -500
  143. package/packs/software-delivery/src/constants/wu-domain-constants.ts +0 -466
  144. package/packs/software-delivery/src/constants/wu-git-constants.ts +0 -7
  145. package/packs/software-delivery/src/constants/wu-id-format.ts +0 -327
  146. package/packs/software-delivery/src/constants/wu-paths-constants.ts +0 -384
  147. package/packs/software-delivery/src/constants/wu-statuses.ts +0 -287
  148. package/packs/software-delivery/src/constants/wu-type-helpers.ts +0 -67
  149. package/packs/software-delivery/src/constants/wu-ui-constants.ts +0 -267
  150. package/packs/software-delivery/src/constants/wu-validation-constants.ts +0 -73
  151. package/packs/software-delivery/src/domain/index.ts +0 -5
  152. package/packs/software-delivery/src/domain/orchestration.constants.ts +0 -166
  153. package/packs/software-delivery/src/domain/orchestration.schemas.ts +0 -238
  154. package/packs/software-delivery/src/domain/orchestration.types.ts +0 -176
  155. package/packs/software-delivery/src/methodology/incremental-test.ts +0 -122
  156. package/packs/software-delivery/src/methodology/index.ts +0 -6
  157. package/packs/software-delivery/src/methodology/manual-test-validator.ts +0 -292
  158. package/packs/software-delivery/src/policy/coverage-gate.ts +0 -270
  159. package/packs/software-delivery/src/policy/gates-agent-mode.ts +0 -223
  160. package/packs/software-delivery/src/policy/gates-config-internal.ts +0 -121
  161. package/packs/software-delivery/src/policy/gates-config.ts +0 -300
  162. package/packs/software-delivery/src/policy/gates-coverage.ts +0 -356
  163. package/packs/software-delivery/src/policy/gates-presets.ts +0 -134
  164. package/packs/software-delivery/src/policy/gates-schemas.ts +0 -173
  165. package/packs/software-delivery/src/policy/index.ts +0 -22
  166. package/packs/software-delivery/src/policy/package-manager-resolver.ts +0 -319
  167. package/packs/software-delivery/src/policy/resolve-policy.ts +0 -601
  168. package/packs/software-delivery/src/ports/config.ports.ts +0 -90
  169. package/packs/software-delivery/src/ports/dashboard-renderer.port.ts +0 -125
  170. package/packs/software-delivery/src/ports/index.ts +0 -10
  171. package/packs/software-delivery/src/ports/sync-validator.ports.ts +0 -59
  172. package/packs/software-delivery/src/ports/wu-helpers.ports.ts +0 -168
  173. package/packs/software-delivery/src/ports/wu-state.ports.ts +0 -241
  174. package/packs/software-delivery/src/primitives/index.ts +0 -5
  175. package/packs/software-delivery/src/runtime/index.ts +0 -6
  176. package/packs/software-delivery/src/runtime/work-classifier.ts +0 -561
  177. package/packs/software-delivery/src/sandbox/index.ts +0 -10
  178. package/packs/software-delivery/src/sandbox/sandbox-allowlist.ts +0 -118
  179. package/packs/software-delivery/src/sandbox/sandbox-backend-linux.ts +0 -88
  180. package/packs/software-delivery/src/sandbox/sandbox-backend-macos.ts +0 -154
  181. package/packs/software-delivery/src/sandbox/sandbox-backend-windows.ts +0 -47
  182. package/packs/software-delivery/src/sandbox/sandbox-profile.ts +0 -153
  183. package/packs/software-delivery/src/schemas/index.ts +0 -5
  184. package/packs/software-delivery/src/state/date-utils.ts +0 -158
  185. package/packs/software-delivery/src/state/index.ts +0 -15
  186. package/packs/software-delivery/src/state/state-machine.ts +0 -119
  187. package/packs/software-delivery/src/state/wu-doc-types.ts +0 -51
  188. package/packs/software-delivery/src/state/wu-paths.ts +0 -381
  189. package/packs/software-delivery/src/state/wu-schema.ts +0 -1139
  190. package/packs/software-delivery/src/state/wu-state-schema.ts +0 -255
  191. package/packs/software-delivery/src/state/wu-yaml.ts +0 -338
  192. package/packs/software-delivery/tool-impl/agent-tools.ts +0 -263
  193. package/packs/software-delivery/tool-impl/delegation-tools.ts +0 -66
  194. package/packs/software-delivery/tool-impl/flow-metrics-tools.ts +0 -219
  195. package/packs/software-delivery/tool-impl/git-runner.ts +0 -113
  196. package/packs/software-delivery/tool-impl/git-tools.ts +0 -316
  197. package/packs/software-delivery/tool-impl/index.ts +0 -15
  198. package/packs/software-delivery/tool-impl/initiative-orchestration-tools.ts +0 -720
  199. package/packs/software-delivery/tool-impl/lane-lock.ts +0 -246
  200. package/packs/software-delivery/tool-impl/memory-tools.ts +0 -470
  201. package/packs/software-delivery/tool-impl/pending-runtime-tools.ts +0 -21
  202. package/packs/software-delivery/tool-impl/runtime-cli-adapter.ts +0 -329
  203. package/packs/software-delivery/tool-impl/runtime-native-tools.ts +0 -687
  204. package/packs/software-delivery/tool-impl/worker-loader.ts +0 -52
  205. package/packs/software-delivery/tool-impl/worktree-tools.ts +0 -46
  206. package/packs/software-delivery/tool-impl/wu-lifecycle-tools.ts +0 -807
  207. package/packs/software-delivery/tools/delegation-tools.ts +0 -23
  208. package/packs/software-delivery/tools/git-tools.ts +0 -55
  209. package/packs/software-delivery/tools/index.ts +0 -8
  210. package/packs/software-delivery/tools/lane-lock-tool.ts +0 -37
  211. package/packs/software-delivery/tools/types.ts +0 -71
  212. package/packs/software-delivery/tools/worktree-tools.ts +0 -49
  213. package/packs/software-delivery/vitest.config.ts +0 -11
@@ -1,577 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- import { getChannelTransport } from './channel-transports.js';
5
- import { getStoragePort, type ChannelMessageRecord, type ChannelRecord } from './storage.js';
6
- import {
7
- asInteger,
8
- asNonEmptyString,
9
- buildAuditEvent,
10
- createId,
11
- failure,
12
- isDryRun,
13
- nowIso,
14
- success,
15
- toRecord,
16
- type ToolContextLike,
17
- type ToolOutput,
18
- } from './shared.js';
19
- import {
20
- buildChannelBridgeConnectedEvent,
21
- buildChannelBridgeDisconnectedEvent,
22
- buildChannelMessageReceivedEvent,
23
- buildChannelMessageSentEvent,
24
- emitSidekickEvent,
25
- } from '../sidekick-events.js';
26
-
27
- // ---------------------------------------------------------------------------
28
- // Constants
29
- // ---------------------------------------------------------------------------
30
-
31
- const TOOL_NAMES = {
32
- CONFIGURE: 'channel:configure',
33
- LIST: 'channel:list',
34
- DELETE: 'channel:delete',
35
- SEND: 'channel:send',
36
- RECEIVE: 'channel:receive',
37
- } as const;
38
-
39
- const OUTBOX_CAP = 100;
40
- const DEFAULT_CHANNEL_NAME = 'default';
41
-
42
- function asOptionalRecord(value: unknown): Record<string, unknown> | undefined {
43
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
44
- return undefined;
45
- }
46
- return value as Record<string, unknown>;
47
- }
48
-
49
- function withTransportMetadata<T extends Record<string, unknown>>(
50
- data: T,
51
- metadata: Record<string, unknown> | undefined,
52
- ): T & Record<string, unknown> {
53
- if (!metadata) {
54
- return data;
55
- }
56
- return {
57
- ...data,
58
- metadata,
59
- };
60
- }
61
-
62
- // ---------------------------------------------------------------------------
63
- // channel:configure
64
- // ---------------------------------------------------------------------------
65
-
66
- async function channelConfigureTool(
67
- input: unknown,
68
- context?: ToolContextLike,
69
- ): Promise<ToolOutput> {
70
- const parsed = toRecord(input);
71
- const name = asNonEmptyString(parsed.name);
72
-
73
- if (!name) {
74
- return failure('INVALID_INPUT', 'name is required.');
75
- }
76
-
77
- const now = nowIso();
78
- const channel: ChannelRecord = {
79
- id: createId('chan'),
80
- name,
81
- created_at: now,
82
- updated_at: now,
83
- };
84
-
85
- if (isDryRun(parsed)) {
86
- return success({
87
- dry_run: true,
88
- channel: channel as unknown as Record<string, unknown>,
89
- });
90
- }
91
-
92
- const storage = getStoragePort();
93
- let resolvedChannel = channel;
94
-
95
- await storage.withLock(async () => {
96
- const channels = await storage.readStore('channels');
97
- const existing = channels.find((c) => c.name === name);
98
-
99
- if (existing) {
100
- resolvedChannel = { ...existing, updated_at: now };
101
- const updated = channels.map((c) => (c.id === existing.id ? resolvedChannel : c));
102
- await storage.writeStore('channels', updated);
103
- await storage.appendAudit(
104
- buildAuditEvent({
105
- tool: TOOL_NAMES.CONFIGURE,
106
- op: 'update',
107
- context,
108
- ids: [existing.id],
109
- }),
110
- );
111
- } else {
112
- channels.push(channel);
113
- await storage.writeStore('channels', channels);
114
- await storage.appendAudit(
115
- buildAuditEvent({
116
- tool: TOOL_NAMES.CONFIGURE,
117
- op: 'create',
118
- context,
119
- ids: [channel.id],
120
- }),
121
- );
122
- }
123
- });
124
-
125
- await emitSidekickEvent(buildChannelBridgeConnectedEvent(resolvedChannel));
126
-
127
- return success({ channel: resolvedChannel as unknown as Record<string, unknown> });
128
- }
129
-
130
- // ---------------------------------------------------------------------------
131
- // channel:list
132
- // ---------------------------------------------------------------------------
133
-
134
- async function channelListTool(_input: unknown, _context?: ToolContextLike): Promise<ToolOutput> {
135
- const storage = getStoragePort();
136
- const channels = await storage.readStore('channels');
137
- const messages = await storage.readStore('messages');
138
-
139
- const items = channels
140
- .map((channel) => {
141
- const channelMessages = messages.filter((message) => message.channel_id === channel.id);
142
- const lastMessage = channelMessages.toSorted(
143
- (left, right) => Date.parse(right.created_at) - Date.parse(left.created_at),
144
- )[0];
145
-
146
- return {
147
- ...channel,
148
- message_count: channelMessages.length,
149
- last_message_at: lastMessage?.created_at,
150
- };
151
- })
152
- .toSorted((left, right) => {
153
- const leftTs = left.last_message_at ?? left.updated_at;
154
- const rightTs = right.last_message_at ?? right.updated_at;
155
- return Date.parse(rightTs) - Date.parse(leftTs);
156
- });
157
-
158
- return success({
159
- items: items as unknown as Record<string, unknown>,
160
- count: items.length,
161
- });
162
- }
163
-
164
- // ---------------------------------------------------------------------------
165
- // channel:delete
166
- // ---------------------------------------------------------------------------
167
-
168
- async function channelDeleteTool(input: unknown, context?: ToolContextLike): Promise<ToolOutput> {
169
- const parsed = toRecord(input);
170
- const id = asNonEmptyString(parsed.id);
171
-
172
- if (!id) {
173
- return failure('INVALID_INPUT', 'id is required.');
174
- }
175
-
176
- const storage = getStoragePort();
177
- const channels = await storage.readStore('channels');
178
- const channel = channels.find((entry) => entry.id === id);
179
-
180
- if (!channel) {
181
- return failure('NOT_FOUND', `channel ${id} was not found.`);
182
- }
183
-
184
- const messages = await storage.readStore('messages');
185
- const deletedMessages = messages.filter((message) => message.channel_id === id);
186
-
187
- if (isDryRun(parsed)) {
188
- return success({
189
- dry_run: true,
190
- deleted_id: id,
191
- deleted_message_count: deletedMessages.length,
192
- });
193
- }
194
-
195
- await storage.withLock(async () => {
196
- const latestChannels = await storage.readStore('channels');
197
- const latestMessages = await storage.readStore('messages');
198
- await storage.writeStore(
199
- 'channels',
200
- latestChannels.filter((entry) => entry.id !== id),
201
- );
202
- await storage.writeStore(
203
- 'messages',
204
- latestMessages.filter((message) => message.channel_id !== id),
205
- );
206
- await storage.appendAudit(
207
- buildAuditEvent({
208
- tool: TOOL_NAMES.DELETE,
209
- op: 'delete',
210
- context,
211
- ids: [id],
212
- details: { deleted_message_count: deletedMessages.length },
213
- }),
214
- );
215
- });
216
-
217
- await emitSidekickEvent(
218
- buildChannelBridgeDisconnectedEvent({
219
- bridge_id: id,
220
- deleted_message_count: deletedMessages.length,
221
- }),
222
- );
223
-
224
- return success({
225
- deleted_id: id,
226
- deleted_message_count: deletedMessages.length,
227
- });
228
- }
229
-
230
- // ---------------------------------------------------------------------------
231
- // channel:send
232
- // ---------------------------------------------------------------------------
233
-
234
- async function channelSendViaTransport(
235
- input: Record<string, unknown>,
236
- context: ToolContextLike | undefined,
237
- provider: string,
238
- channel: string,
239
- content: string,
240
- ): Promise<ToolOutput> {
241
- const workspaceId = asNonEmptyString(context?.workspace_id);
242
- if (!workspaceId) {
243
- return failure(
244
- 'WORKSPACE_CONTEXT_REQUIRED',
245
- 'workspace_id is required when provider is specified.',
246
- );
247
- }
248
-
249
- const transport = getChannelTransport(provider);
250
- if (!transport) {
251
- return failure(
252
- 'INTEGRATION_PROVIDER_NOT_REGISTERED',
253
- `No channel transport registered for provider: ${provider}`,
254
- );
255
- }
256
-
257
- if (isDryRun(input)) {
258
- return success({
259
- dry_run: true,
260
- provider,
261
- capability: 'send',
262
- channel,
263
- content,
264
- });
265
- }
266
-
267
- const transportResult = await transport.send({
268
- workspaceId,
269
- provider,
270
- channel,
271
- content,
272
- metadata: asOptionalRecord(input.metadata),
273
- });
274
-
275
- const outputData = withTransportMetadata(
276
- {
277
- provider,
278
- capability: 'send',
279
- channel,
280
- ...(transportResult.externalMessageId !== undefined
281
- ? { externalMessageId: transportResult.externalMessageId }
282
- : {}),
283
- ...(transportResult.failureClass ? { failureClass: transportResult.failureClass } : {}),
284
- ...(transportResult.retryAfterSeconds !== undefined
285
- ? { retryAfterSeconds: transportResult.retryAfterSeconds }
286
- : {}),
287
- },
288
- transportResult.metadata,
289
- );
290
-
291
- if (!transportResult.success) {
292
- return {
293
- success: false,
294
- error: {
295
- code: 'INTEGRATION_PROVIDER_SEND_FAILED',
296
- message: transportResult.error ?? `Provider send failed for provider: ${provider}`,
297
- },
298
- data: outputData,
299
- };
300
- }
301
-
302
- // WU-2830 (INIT-062 WU-D): ChannelMessageSentEvent.message is a typed
303
- // ChannelMessageRecord. Provider sends do not have a local storage row,
304
- // so we synthesize a record using the external id when available.
305
- const providerSentMessage: ChannelMessageRecord = {
306
- id: transportResult.externalMessageId ?? createId('msg'),
307
- channel_id: `${provider}:${channel}`,
308
- sender: 'assistant',
309
- content,
310
- created_at: nowIso(),
311
- };
312
-
313
- await emitSidekickEvent(buildChannelMessageSentEvent(providerSentMessage));
314
-
315
- return success(outputData);
316
- }
317
-
318
- async function channelSendTool(input: unknown, context?: ToolContextLike): Promise<ToolOutput> {
319
- const parsed = toRecord(input);
320
- const content = asNonEmptyString(parsed.content);
321
-
322
- if (!content) {
323
- return failure('INVALID_INPUT', 'content is required.');
324
- }
325
-
326
- const channelName = asNonEmptyString(parsed.channel) ?? DEFAULT_CHANNEL_NAME;
327
- const provider = asNonEmptyString(parsed.provider);
328
-
329
- if (provider) {
330
- return channelSendViaTransport(parsed, context, provider, channelName, content);
331
- }
332
-
333
- const sender = asNonEmptyString(parsed.sender) ?? 'assistant';
334
- const now = nowIso();
335
-
336
- const message: ChannelMessageRecord = {
337
- id: createId('msg'),
338
- channel_id: '', // resolved below
339
- sender,
340
- content,
341
- created_at: now,
342
- };
343
-
344
- if (isDryRun(parsed)) {
345
- return success({
346
- dry_run: true,
347
- message: { ...message, channel_id: 'dry-run' } as unknown as Record<string, unknown>,
348
- });
349
- }
350
-
351
- const storage = getStoragePort();
352
- let resolvedMessage = message;
353
-
354
- await storage.withLock(async () => {
355
- const channels = await storage.readStore('channels');
356
- const found = channels.find((c) => c.name === channelName);
357
- let channelId: string;
358
-
359
- if (!found) {
360
- channelId = createId('chan');
361
- channels.push({
362
- id: channelId,
363
- name: channelName,
364
- created_at: now,
365
- updated_at: now,
366
- });
367
- await storage.writeStore('channels', channels);
368
- } else {
369
- channelId = found.id;
370
- const updated = channels.map((c) => (c.id === channelId ? { ...c, updated_at: now } : c));
371
- await storage.writeStore('channels', updated);
372
- }
373
-
374
- resolvedMessage = { ...message, channel_id: channelId };
375
-
376
- const messages = await storage.readStore('messages');
377
- messages.push(resolvedMessage);
378
-
379
- // Cap outbox at OUTBOX_CAP
380
- const capped = messages.length > OUTBOX_CAP ? messages.slice(-OUTBOX_CAP) : messages;
381
- await storage.writeStore('messages', capped);
382
-
383
- await storage.appendAudit(
384
- buildAuditEvent({
385
- tool: TOOL_NAMES.SEND,
386
- op: 'create',
387
- context,
388
- ids: [channelId, resolvedMessage.id],
389
- }),
390
- );
391
- });
392
-
393
- // WU-2830: pass the typed ChannelMessageRecord directly.
394
- await emitSidekickEvent(buildChannelMessageSentEvent(resolvedMessage));
395
-
396
- return success({ message: resolvedMessage as unknown as Record<string, unknown> });
397
- }
398
-
399
- // ---------------------------------------------------------------------------
400
- // channel:receive
401
- // ---------------------------------------------------------------------------
402
-
403
- async function channelReceiveViaTransport(
404
- input: Record<string, unknown>,
405
- context: ToolContextLike | undefined,
406
- provider: string,
407
- channel: string,
408
- limit: number | null,
409
- ): Promise<ToolOutput> {
410
- const workspaceId = asNonEmptyString(context?.workspace_id);
411
- if (!workspaceId) {
412
- return failure(
413
- 'WORKSPACE_CONTEXT_REQUIRED',
414
- 'workspace_id is required when provider is specified.',
415
- );
416
- }
417
-
418
- const transport = getChannelTransport(provider);
419
- if (!transport) {
420
- return failure(
421
- 'INTEGRATION_PROVIDER_NOT_REGISTERED',
422
- `No channel transport registered for provider: ${provider}`,
423
- );
424
- }
425
-
426
- const cursor = asNonEmptyString(input.cursor) ?? undefined;
427
-
428
- const transportResult = await transport.receive({
429
- workspaceId,
430
- provider,
431
- channel,
432
- cursor,
433
- limit: limit && limit > 0 ? limit : undefined,
434
- metadata: asOptionalRecord(input.metadata),
435
- });
436
-
437
- const outputData = withTransportMetadata(
438
- {
439
- provider,
440
- capability: 'read',
441
- channel,
442
- ...(transportResult.records !== undefined ? { records: transportResult.records } : {}),
443
- ...(transportResult.nextCursor !== undefined
444
- ? { nextCursor: transportResult.nextCursor }
445
- : {}),
446
- ...(transportResult.failureClass ? { failureClass: transportResult.failureClass } : {}),
447
- ...(transportResult.retryAfterSeconds !== undefined
448
- ? { retryAfterSeconds: transportResult.retryAfterSeconds }
449
- : {}),
450
- },
451
- transportResult.metadata,
452
- );
453
-
454
- if (!transportResult.success) {
455
- return {
456
- success: false,
457
- error: {
458
- code: 'INTEGRATION_PROVIDER_RECEIVE_FAILED',
459
- message: transportResult.error ?? `Provider receive failed for provider: ${provider}`,
460
- },
461
- data: outputData,
462
- };
463
- }
464
-
465
- // WU-2830: ChannelMessageReceivedEvent now carries typed
466
- // ChannelMessageRecord[] (symmetric with the sent event). Coerce
467
- // provider-opaque records into the canonical shape before emission.
468
- const receivedRecords = (transportResult.records ?? []).map((record) =>
469
- coerceProviderRecordToMessageRecord(record, `${provider}:${channel}`),
470
- );
471
-
472
- await emitSidekickEvent(
473
- buildChannelMessageReceivedEvent({
474
- provider,
475
- channel,
476
- messages: receivedRecords,
477
- }),
478
- );
479
-
480
- return success(outputData);
481
- }
482
-
483
- function coerceProviderRecordToMessageRecord(
484
- record: unknown,
485
- fallbackChannelId: string,
486
- ): ChannelMessageRecord {
487
- // WU-2830: provider transports declare `records?: unknown[]`. Type-narrow
488
- // to build a ChannelMessageRecord without unsafe casts; missing fields
489
- // fall back to sensible defaults so downstream consumers always see a
490
- // complete, typed payload.
491
- const source = record && typeof record === 'object' ? (record as Record<string, unknown>) : {};
492
- const now = nowIso();
493
- const id = typeof source.id === 'string' && source.id.length > 0 ? source.id : createId('msg');
494
- const channel_id =
495
- typeof source.channel_id === 'string' && source.channel_id.length > 0
496
- ? source.channel_id
497
- : fallbackChannelId;
498
- const sender =
499
- typeof source.sender === 'string' && source.sender.length > 0 ? source.sender : 'external';
500
- const content = typeof source.content === 'string' ? source.content : '';
501
- const created_at =
502
- typeof source.created_at === 'string' && source.created_at.length > 0 ? source.created_at : now;
503
- return { id, channel_id, sender, content, created_at };
504
- }
505
-
506
- async function channelReceiveTool(input: unknown, _context?: ToolContextLike): Promise<ToolOutput> {
507
- const parsed = toRecord(input);
508
- const channelName = asNonEmptyString(parsed.channel);
509
- const limit = asInteger(parsed.limit);
510
- const provider = asNonEmptyString(parsed.provider);
511
-
512
- if (provider) {
513
- return channelReceiveViaTransport(
514
- parsed,
515
- _context,
516
- provider,
517
- channelName ?? DEFAULT_CHANNEL_NAME,
518
- limit,
519
- );
520
- }
521
-
522
- const storage = getStoragePort();
523
- const messages = await storage.readStore('messages');
524
- const channels = await storage.readStore('channels');
525
-
526
- let filtered = messages;
527
-
528
- if (channelName) {
529
- const channel = channels.find((c) => c.name === channelName);
530
- if (channel) {
531
- filtered = messages.filter((m) => m.channel_id === channel.id);
532
- } else {
533
- filtered = [];
534
- }
535
- }
536
-
537
- const sorted = filtered.toSorted((a, b) => Date.parse(a.created_at) - Date.parse(b.created_at));
538
-
539
- const items = limit && limit > 0 ? sorted.slice(-limit) : sorted;
540
-
541
- await emitSidekickEvent(
542
- buildChannelMessageReceivedEvent({
543
- channel: channelName ?? DEFAULT_CHANNEL_NAME,
544
- // WU-2830: carry the full typed ChannelMessageRecord[] payload.
545
- messages: items,
546
- }),
547
- );
548
-
549
- return success({
550
- items: items as unknown as Record<string, unknown>,
551
- count: items.length,
552
- });
553
- }
554
-
555
- // ---------------------------------------------------------------------------
556
- // Router (default export)
557
- // ---------------------------------------------------------------------------
558
-
559
- export default async function channelTools(
560
- input: unknown,
561
- context?: ToolContextLike,
562
- ): Promise<ToolOutput> {
563
- switch (context?.tool_name) {
564
- case TOOL_NAMES.CONFIGURE:
565
- return channelConfigureTool(input, context);
566
- case TOOL_NAMES.LIST:
567
- return channelListTool(input, context);
568
- case TOOL_NAMES.DELETE:
569
- return channelDeleteTool(input, context);
570
- case TOOL_NAMES.SEND:
571
- return channelSendTool(input, context);
572
- case TOOL_NAMES.RECEIVE:
573
- return channelReceiveTool(input, context);
574
- default:
575
- return failure('UNKNOWN_TOOL', `Unknown channel tool: ${context?.tool_name ?? 'unknown'}`);
576
- }
577
- }
@@ -1,75 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- import { getSidekickRuntimeContext } from './runtime-context.js';
5
-
6
- export interface ChannelTransport {
7
- provider: string;
8
- send(req: {
9
- workspaceId: string;
10
- provider: string;
11
- channel: string;
12
- content: string;
13
- metadata?: Record<string, unknown>;
14
- }): Promise<{
15
- success: boolean;
16
- error?: string;
17
- externalMessageId?: string;
18
- failureClass?: 'retryable' | 'terminal';
19
- retryAfterSeconds?: number;
20
- metadata?: Record<string, unknown>;
21
- }>;
22
- receive(req: {
23
- workspaceId: string;
24
- provider: string;
25
- channel: string;
26
- cursor?: string;
27
- limit?: number;
28
- metadata?: Record<string, unknown>;
29
- }): Promise<{
30
- success: boolean;
31
- error?: string;
32
- records?: unknown[];
33
- nextCursor?: string;
34
- failureClass?: 'retryable' | 'terminal';
35
- retryAfterSeconds?: number;
36
- metadata?: Record<string, unknown>;
37
- }>;
38
- }
39
-
40
- function normalizeProvider(provider: string): string {
41
- return provider.trim().toLowerCase();
42
- }
43
-
44
- function getRegistry(): Map<string, ChannelTransport> | undefined {
45
- return getSidekickRuntimeContext()?.channelTransports;
46
- }
47
-
48
- export function registerChannelTransport(transport: ChannelTransport): void {
49
- const provider = normalizeProvider(transport.provider);
50
- if (provider.length === 0) {
51
- throw new Error('channel transport provider must be a non-empty string.');
52
- }
53
- const registry = getRegistry();
54
- if (!registry) {
55
- throw new Error('channel transport registry is unavailable outside sidekick runtime context.');
56
- }
57
- registry.set(provider, transport);
58
- }
59
-
60
- export function getChannelTransport(provider: string): ChannelTransport | undefined {
61
- const normalized = normalizeProvider(provider);
62
- if (normalized.length === 0) {
63
- return undefined;
64
- }
65
- const registry = getRegistry();
66
- return registry?.get(normalized);
67
- }
68
-
69
- export function clearChannelTransports(): void {
70
- const registry = getRegistry();
71
- if (!registry) {
72
- return;
73
- }
74
- registry.clear();
75
- }
@@ -1,29 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- export {
5
- type AuditEvent,
6
- type ChannelMessageRecord,
7
- type ChannelRecord,
8
- type MemoryRecord,
9
- type MemoryType,
10
- type RoutineRecord,
11
- type RoutineStepRecord,
12
- type SidekickStores,
13
- type StoragePort,
14
- type StoreName,
15
- type TaskPriority,
16
- type TaskRecord,
17
- type TaskStatus,
18
- FsStoragePort,
19
- getStoragePort,
20
- runWithStoragePort,
21
- setDefaultStoragePort,
22
- } from './storage.js';
23
-
24
- export {
25
- type ChannelTransport,
26
- clearChannelTransports,
27
- getChannelTransport,
28
- registerChannelTransport,
29
- } from './channel-transports.js';