@lumenflow/cli 5.5.0 → 5.7.14

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 (229) hide show
  1. package/README.md +41 -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/doctor.js +11 -0
  7. package/dist/doctor.js.map +1 -1
  8. package/dist/gate-defaults.js +37 -0
  9. package/dist/gate-defaults.js.map +1 -1
  10. package/dist/gates/monolithic-file-contention-guard.js +167 -0
  11. package/dist/gates/monolithic-file-contention-guard.js.map +1 -0
  12. package/dist/gates/prod-migration-drift.js +207 -0
  13. package/dist/gates/prod-migration-drift.js.map +1 -0
  14. package/dist/gates/test-over-deletion-guard.js +280 -0
  15. package/dist/gates/test-over-deletion-guard.js.map +1 -0
  16. package/dist/gates-runners.js +44 -3
  17. package/dist/gates-runners.js.map +1 -1
  18. package/dist/gates.js +3 -2
  19. package/dist/gates.js.map +1 -1
  20. package/dist/hooks/config-resolver.js +16 -1
  21. package/dist/hooks/config-resolver.js.map +1 -1
  22. package/dist/hooks/dirty-guard.js +43 -2
  23. package/dist/hooks/dirty-guard.js.map +1 -1
  24. package/dist/hooks/git-status-parser.js +22 -8
  25. package/dist/hooks/git-status-parser.js.map +1 -1
  26. package/dist/init-templates.js +241 -0
  27. package/dist/init-templates.js.map +1 -1
  28. package/dist/init.js +122 -16
  29. package/dist/init.js.map +1 -1
  30. package/dist/lumenflow-setup.js +144 -0
  31. package/dist/lumenflow-setup.js.map +1 -0
  32. package/dist/lumenflow-upgrade.js +43 -1
  33. package/dist/lumenflow-upgrade.js.map +1 -1
  34. package/dist/mem-create.js +10 -1
  35. package/dist/mem-create.js.map +1 -1
  36. package/dist/mem-signal.js +21 -4
  37. package/dist/mem-signal.js.map +1 -1
  38. package/dist/orchestrate-initiative.js +28 -3
  39. package/dist/orchestrate-initiative.js.map +1 -1
  40. package/dist/public-manifest.js +17 -7
  41. package/dist/public-manifest.js.map +1 -1
  42. package/dist/release.js +53 -18
  43. package/dist/release.js.map +1 -1
  44. package/dist/wu-done-gates.js +13 -9
  45. package/dist/wu-done-gates.js.map +1 -1
  46. package/dist/wu-done.js +14 -2
  47. package/dist/wu-done.js.map +1 -1
  48. package/dist/wu-edit-operations.js +74 -0
  49. package/dist/wu-edit-operations.js.map +1 -1
  50. package/dist/wu-edit-validators.js +58 -0
  51. package/dist/wu-edit-validators.js.map +1 -1
  52. package/dist/wu-edit.js +106 -4
  53. package/dist/wu-edit.js.map +1 -1
  54. package/dist/wu-prep.js +57 -9
  55. package/dist/wu-prep.js.map +1 -1
  56. package/dist/wu-recover.js +6 -0
  57. package/dist/wu-recover.js.map +1 -1
  58. package/dist/wu-release.js +120 -2
  59. package/dist/wu-release.js.map +1 -1
  60. package/dist/wu-sizing-validation.js +47 -17
  61. package/dist/wu-sizing-validation.js.map +1 -1
  62. package/dist/wu-status.js +33 -0
  63. package/dist/wu-status.js.map +1 -1
  64. package/package.json +13 -12
  65. package/packs/agent-runtime/package.json +1 -1
  66. package/packs/sidekick/package.json +1 -1
  67. package/packs/software-delivery/package.json +1 -1
  68. package/templates/core/AGENTS.md.template +67 -3
  69. package/templates/core/LUMENFLOW.md.template +196 -47
  70. package/dist/distribution-preflight.js +0 -230
  71. package/dist/distribution-preflight.js.map +0 -1
  72. package/packs/agent-runtime/agent-heartbeat.ts +0 -163
  73. package/packs/agent-runtime/auto-session-integration.ts +0 -888
  74. package/packs/agent-runtime/capability-factory.ts +0 -104
  75. package/packs/agent-runtime/constants.ts +0 -21
  76. package/packs/agent-runtime/delegation-registry-schema.ts +0 -220
  77. package/packs/agent-runtime/delegation-registry-store.ts +0 -269
  78. package/packs/agent-runtime/delegation-tree.ts +0 -328
  79. package/packs/agent-runtime/index.ts +0 -20
  80. package/packs/agent-runtime/manifest.ts +0 -348
  81. package/packs/agent-runtime/memory-coordination-contract.ts +0 -86
  82. package/packs/agent-runtime/orchestration.ts +0 -2027
  83. package/packs/agent-runtime/pack-registration.ts +0 -110
  84. package/packs/agent-runtime/policy-factory.ts +0 -165
  85. package/packs/agent-runtime/remote-controls/index.ts +0 -7
  86. package/packs/agent-runtime/remote-controls/operations.ts +0 -405
  87. package/packs/agent-runtime/remote-controls/port.ts +0 -48
  88. package/packs/agent-runtime/remote-controls/state-store.ts +0 -258
  89. package/packs/agent-runtime/remote-controls/types.ts +0 -105
  90. package/packs/agent-runtime/session-schema.ts +0 -467
  91. package/packs/agent-runtime/tool-impl/agent-turn-tools.ts +0 -793
  92. package/packs/agent-runtime/tool-impl/index.ts +0 -6
  93. package/packs/agent-runtime/tool-impl/provider-adapters.ts +0 -1245
  94. package/packs/agent-runtime/tool-impl/remote-controls.mock.ts +0 -256
  95. package/packs/agent-runtime/tool-impl/remote-controls.ts +0 -273
  96. package/packs/agent-runtime/tools/index.ts +0 -4
  97. package/packs/agent-runtime/tools/types.ts +0 -47
  98. package/packs/agent-runtime/turn-lifecycle-events.ts +0 -590
  99. package/packs/agent-runtime/types.ts +0 -128
  100. package/packs/agent-runtime/vitest.config.ts +0 -11
  101. package/packs/sidekick/channel-ingress.ts +0 -137
  102. package/packs/sidekick/constants.ts +0 -10
  103. package/packs/sidekick/index.ts +0 -8
  104. package/packs/sidekick/manifest-schema.ts +0 -49
  105. package/packs/sidekick/manifest.ts +0 -512
  106. package/packs/sidekick/pack-registration.ts +0 -110
  107. package/packs/sidekick/policy-factory.ts +0 -38
  108. package/packs/sidekick/sidekick-events.ts +0 -694
  109. package/packs/sidekick/src/adapters/cloud-queue.ts +0 -101
  110. package/packs/sidekick/src/adapters/control-plane-bridge.adapter.ts +0 -386
  111. package/packs/sidekick/src/adapters/filesystem-bridge.adapter.ts +0 -228
  112. package/packs/sidekick/src/domain/channel.types.ts +0 -64
  113. package/packs/sidekick/src/ports/channel-bridge.port.ts +0 -92
  114. package/packs/sidekick/src/routines/commit.ts +0 -74
  115. package/packs/sidekick/tool-impl/channel-tools.ts +0 -577
  116. package/packs/sidekick/tool-impl/channel-transports.ts +0 -75
  117. package/packs/sidekick/tool-impl/index.ts +0 -29
  118. package/packs/sidekick/tool-impl/memory-tools.ts +0 -290
  119. package/packs/sidekick/tool-impl/routine-commit.ts +0 -102
  120. package/packs/sidekick/tool-impl/routine-tools.ts +0 -440
  121. package/packs/sidekick/tool-impl/runtime-context.ts +0 -28
  122. package/packs/sidekick/tool-impl/shared.ts +0 -125
  123. package/packs/sidekick/tool-impl/storage.ts +0 -325
  124. package/packs/sidekick/tool-impl/system-tools.ts +0 -160
  125. package/packs/sidekick/tool-impl/task-tools.ts +0 -506
  126. package/packs/sidekick/tools/channel-tools.ts +0 -53
  127. package/packs/sidekick/tools/index.ts +0 -9
  128. package/packs/sidekick/tools/memory-tools.ts +0 -53
  129. package/packs/sidekick/tools/routine-tools.ts +0 -53
  130. package/packs/sidekick/tools/system-tools.ts +0 -47
  131. package/packs/sidekick/tools/task-tools.ts +0 -61
  132. package/packs/sidekick/tools/types.ts +0 -57
  133. package/packs/sidekick/vitest.config.ts +0 -11
  134. package/packs/software-delivery/constants.ts +0 -10
  135. package/packs/software-delivery/extensions.ts +0 -140
  136. package/packs/software-delivery/gate-policies.ts +0 -134
  137. package/packs/software-delivery/index.ts +0 -8
  138. package/packs/software-delivery/manifest-schema.ts +0 -268
  139. package/packs/software-delivery/manifest.ts +0 -657
  140. package/packs/software-delivery/pack-registration.ts +0 -113
  141. package/packs/software-delivery/src/commands/index.ts +0 -5
  142. package/packs/software-delivery/src/config/delivery-review-contract.ts +0 -256
  143. package/packs/software-delivery/src/config/env-accessors.ts +0 -66
  144. package/packs/software-delivery/src/config/index.ts +0 -8
  145. package/packs/software-delivery/src/config/normalize-config-keys.ts +0 -9
  146. package/packs/software-delivery/src/config/schemas/lumenflow-config-schema-types.ts +0 -460
  147. package/packs/software-delivery/src/config/workspace-reader.ts +0 -375
  148. package/packs/software-delivery/src/constants/backlog-patterns.ts +0 -31
  149. package/packs/software-delivery/src/constants/client-ids.ts +0 -19
  150. package/packs/software-delivery/src/constants/config-contract.ts +0 -7
  151. package/packs/software-delivery/src/constants/docs-layout-presets.ts +0 -50
  152. package/packs/software-delivery/src/constants/duration-constants.ts +0 -20
  153. package/packs/software-delivery/src/constants/gate-constants.ts +0 -32
  154. package/packs/software-delivery/src/constants/index.ts +0 -29
  155. package/packs/software-delivery/src/constants/lock-constants.ts +0 -35
  156. package/packs/software-delivery/src/constants/object-guards.ts +0 -12
  157. package/packs/software-delivery/src/constants/section-headings.ts +0 -107
  158. package/packs/software-delivery/src/constants/wu-cli-constants.ts +0 -500
  159. package/packs/software-delivery/src/constants/wu-domain-constants.ts +0 -466
  160. package/packs/software-delivery/src/constants/wu-git-constants.ts +0 -7
  161. package/packs/software-delivery/src/constants/wu-id-format.ts +0 -327
  162. package/packs/software-delivery/src/constants/wu-paths-constants.ts +0 -384
  163. package/packs/software-delivery/src/constants/wu-statuses.ts +0 -287
  164. package/packs/software-delivery/src/constants/wu-type-helpers.ts +0 -67
  165. package/packs/software-delivery/src/constants/wu-ui-constants.ts +0 -267
  166. package/packs/software-delivery/src/constants/wu-validation-constants.ts +0 -73
  167. package/packs/software-delivery/src/domain/index.ts +0 -5
  168. package/packs/software-delivery/src/domain/orchestration.constants.ts +0 -166
  169. package/packs/software-delivery/src/domain/orchestration.schemas.ts +0 -238
  170. package/packs/software-delivery/src/domain/orchestration.types.ts +0 -176
  171. package/packs/software-delivery/src/methodology/incremental-test.ts +0 -122
  172. package/packs/software-delivery/src/methodology/index.ts +0 -6
  173. package/packs/software-delivery/src/methodology/manual-test-validator.ts +0 -292
  174. package/packs/software-delivery/src/policy/coverage-gate.ts +0 -270
  175. package/packs/software-delivery/src/policy/gates-agent-mode.ts +0 -223
  176. package/packs/software-delivery/src/policy/gates-config-internal.ts +0 -121
  177. package/packs/software-delivery/src/policy/gates-config.ts +0 -300
  178. package/packs/software-delivery/src/policy/gates-coverage.ts +0 -356
  179. package/packs/software-delivery/src/policy/gates-presets.ts +0 -134
  180. package/packs/software-delivery/src/policy/gates-schemas.ts +0 -173
  181. package/packs/software-delivery/src/policy/index.ts +0 -22
  182. package/packs/software-delivery/src/policy/package-manager-resolver.ts +0 -319
  183. package/packs/software-delivery/src/policy/resolve-policy.ts +0 -601
  184. package/packs/software-delivery/src/ports/config.ports.ts +0 -90
  185. package/packs/software-delivery/src/ports/dashboard-renderer.port.ts +0 -125
  186. package/packs/software-delivery/src/ports/index.ts +0 -10
  187. package/packs/software-delivery/src/ports/sync-validator.ports.ts +0 -59
  188. package/packs/software-delivery/src/ports/wu-helpers.ports.ts +0 -168
  189. package/packs/software-delivery/src/ports/wu-state.ports.ts +0 -241
  190. package/packs/software-delivery/src/primitives/index.ts +0 -5
  191. package/packs/software-delivery/src/runtime/index.ts +0 -6
  192. package/packs/software-delivery/src/runtime/work-classifier.ts +0 -561
  193. package/packs/software-delivery/src/sandbox/index.ts +0 -10
  194. package/packs/software-delivery/src/sandbox/sandbox-allowlist.ts +0 -118
  195. package/packs/software-delivery/src/sandbox/sandbox-backend-linux.ts +0 -88
  196. package/packs/software-delivery/src/sandbox/sandbox-backend-macos.ts +0 -154
  197. package/packs/software-delivery/src/sandbox/sandbox-backend-windows.ts +0 -47
  198. package/packs/software-delivery/src/sandbox/sandbox-profile.ts +0 -153
  199. package/packs/software-delivery/src/schemas/index.ts +0 -5
  200. package/packs/software-delivery/src/state/date-utils.ts +0 -158
  201. package/packs/software-delivery/src/state/index.ts +0 -15
  202. package/packs/software-delivery/src/state/state-machine.ts +0 -119
  203. package/packs/software-delivery/src/state/wu-doc-types.ts +0 -51
  204. package/packs/software-delivery/src/state/wu-paths.ts +0 -381
  205. package/packs/software-delivery/src/state/wu-schema.ts +0 -1139
  206. package/packs/software-delivery/src/state/wu-state-schema.ts +0 -255
  207. package/packs/software-delivery/src/state/wu-yaml.ts +0 -338
  208. package/packs/software-delivery/tool-impl/agent-tools.ts +0 -263
  209. package/packs/software-delivery/tool-impl/delegation-tools.ts +0 -66
  210. package/packs/software-delivery/tool-impl/flow-metrics-tools.ts +0 -219
  211. package/packs/software-delivery/tool-impl/git-runner.ts +0 -113
  212. package/packs/software-delivery/tool-impl/git-tools.ts +0 -316
  213. package/packs/software-delivery/tool-impl/index.ts +0 -15
  214. package/packs/software-delivery/tool-impl/initiative-orchestration-tools.ts +0 -720
  215. package/packs/software-delivery/tool-impl/lane-lock.ts +0 -246
  216. package/packs/software-delivery/tool-impl/memory-tools.ts +0 -470
  217. package/packs/software-delivery/tool-impl/pending-runtime-tools.ts +0 -21
  218. package/packs/software-delivery/tool-impl/runtime-cli-adapter.ts +0 -329
  219. package/packs/software-delivery/tool-impl/runtime-native-tools.ts +0 -687
  220. package/packs/software-delivery/tool-impl/worker-loader.ts +0 -52
  221. package/packs/software-delivery/tool-impl/worktree-tools.ts +0 -46
  222. package/packs/software-delivery/tool-impl/wu-lifecycle-tools.ts +0 -807
  223. package/packs/software-delivery/tools/delegation-tools.ts +0 -23
  224. package/packs/software-delivery/tools/git-tools.ts +0 -55
  225. package/packs/software-delivery/tools/index.ts +0 -8
  226. package/packs/software-delivery/tools/lane-lock-tool.ts +0 -37
  227. package/packs/software-delivery/tools/types.ts +0 -71
  228. package/packs/software-delivery/tools/worktree-tools.ts +0 -49
  229. 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';