@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,246 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- /* eslint-disable security/detect-non-literal-fs-filename */
5
- import { mkdir, readFile, unlink, writeFile } from 'node:fs/promises';
6
- import path from 'node:path';
7
- import { UTF8_ENCODING } from '../constants.js';
8
-
9
- export interface LaneLockMetadata {
10
- lane: string;
11
- wuId: string;
12
- owner: string;
13
- timestamp: string;
14
- }
15
-
16
- export interface AcquireLaneLockInput {
17
- lane: string;
18
- wuId: string;
19
- owner: string;
20
- locksDir: string;
21
- staleAfterMs?: number;
22
- }
23
-
24
- export interface AcquireLaneLockResult {
25
- acquired: boolean;
26
- is_stale: boolean;
27
- lock_path: string;
28
- }
29
-
30
- export interface ReleaseLaneLockInput {
31
- lane: string;
32
- owner: string;
33
- locksDir: string;
34
- }
35
-
36
- export interface ReleaseLaneLockResult {
37
- released: boolean;
38
- lock_path: string;
39
- }
40
-
41
- function laneToLockFileName(lane: string): string {
42
- const chars: string[] = [];
43
- for (const char of lane.toLowerCase()) {
44
- if ((char >= 'a' && char <= 'z') || (char >= '0' && char <= '9')) {
45
- chars.push(char);
46
- continue;
47
- }
48
- if (chars[chars.length - 1] !== '-') {
49
- chars.push('-');
50
- }
51
- }
52
- let normalized = chars.join('');
53
- while (normalized.startsWith('-')) {
54
- normalized = normalized.slice(1);
55
- }
56
- while (normalized.endsWith('-')) {
57
- normalized = normalized.slice(0, -1);
58
- }
59
- return `${normalized || 'lane'}.lock`;
60
- }
61
-
62
- function lockPathFor(input: { lane: string; locksDir: string }): string {
63
- return path.join(input.locksDir, laneToLockFileName(input.lane));
64
- }
65
-
66
- function isStale(metadata: LaneLockMetadata, staleAfterMs: number): boolean {
67
- const lockTime = new Date(metadata.timestamp).getTime();
68
- return Number.isFinite(lockTime) && Date.now() - lockTime > staleAfterMs;
69
- }
70
-
71
- function staleTakeoverMarkerPath(lockPath: string): string {
72
- return `${lockPath}.takeover`;
73
- }
74
-
75
- async function acquireTakeoverMarker(
76
- markerPath: string,
77
- metadata: LaneLockMetadata,
78
- ): Promise<boolean> {
79
- try {
80
- await writeFile(markerPath, JSON.stringify(metadata), { encoding: UTF8_ENCODING, flag: 'wx' });
81
- return true;
82
- } catch (error) {
83
- if ((error as NodeJS.ErrnoException).code === 'EEXIST') {
84
- return false;
85
- }
86
- throw error;
87
- }
88
- }
89
-
90
- type LaneLockWarn = (message: string) => void;
91
-
92
- function writeWarning(message: string): void {
93
- process.stderr.write(`${message}\n`);
94
- }
95
-
96
- export async function cleanupTakeoverMarker(
97
- markerPath: string,
98
- options: {
99
- unlinkFile?: (targetPath: string) => Promise<void>;
100
- warn?: LaneLockWarn;
101
- } = {},
102
- ): Promise<void> {
103
- const unlinkFile = options.unlinkFile ?? unlink;
104
- const warn: LaneLockWarn = options.warn ?? writeWarning;
105
-
106
- try {
107
- await unlinkFile(markerPath);
108
- } catch (error) {
109
- const nodeError = error as NodeJS.ErrnoException;
110
- if (nodeError.code === 'ENOENT') {
111
- return;
112
- }
113
- const message = error instanceof Error ? error.message : String(error);
114
- warn(`[lane-lock] failed to cleanup takeover marker at ${markerPath}: ${message}`);
115
- }
116
- }
117
-
118
- export async function readLaneLockMetadata(lockPath: string): Promise<LaneLockMetadata | null> {
119
- try {
120
- const raw = await readFile(lockPath, UTF8_ENCODING);
121
- const parsed = JSON.parse(raw) as LaneLockMetadata;
122
- if (
123
- typeof parsed.lane !== 'string' ||
124
- typeof parsed.wuId !== 'string' ||
125
- typeof parsed.owner !== 'string' ||
126
- typeof parsed.timestamp !== 'string'
127
- ) {
128
- return null;
129
- }
130
- return parsed;
131
- } catch {
132
- return null;
133
- }
134
- }
135
-
136
- export async function acquireLaneLockTool(
137
- input: AcquireLaneLockInput,
138
- ): Promise<AcquireLaneLockResult> {
139
- await mkdir(input.locksDir, { recursive: true });
140
- const lockPath = lockPathFor(input);
141
- const staleAfterMs = input.staleAfterMs ?? 2 * 60 * 60 * 1000;
142
- const nextMetadata: LaneLockMetadata = {
143
- lane: input.lane,
144
- wuId: input.wuId,
145
- owner: input.owner,
146
- timestamp: new Date().toISOString(),
147
- };
148
-
149
- try {
150
- await writeFile(lockPath, JSON.stringify(nextMetadata), {
151
- encoding: UTF8_ENCODING,
152
- flag: 'wx',
153
- });
154
- return {
155
- acquired: true,
156
- is_stale: false,
157
- lock_path: lockPath,
158
- };
159
- } catch (error) {
160
- const isExists = (error as NodeJS.ErrnoException).code === 'EEXIST';
161
- if (!isExists) {
162
- throw error;
163
- }
164
-
165
- const existing = await readLaneLockMetadata(lockPath);
166
- if (existing && isStale(existing, staleAfterMs)) {
167
- const takeoverMarkerPath = staleTakeoverMarkerPath(lockPath);
168
- const wonTakeoverRace = await acquireTakeoverMarker(takeoverMarkerPath, nextMetadata);
169
- if (!wonTakeoverRace) {
170
- return {
171
- acquired: false,
172
- is_stale: false,
173
- lock_path: lockPath,
174
- };
175
- }
176
-
177
- try {
178
- const current = await readLaneLockMetadata(lockPath);
179
- if (!current || !isStale(current, staleAfterMs)) {
180
- return {
181
- acquired: false,
182
- is_stale: false,
183
- lock_path: lockPath,
184
- };
185
- }
186
-
187
- await unlink(lockPath).catch((unlinkError) => {
188
- const nodeError = unlinkError as NodeJS.ErrnoException;
189
- if (nodeError.code === 'ENOENT') {
190
- return;
191
- }
192
- throw unlinkError;
193
- });
194
-
195
- try {
196
- await writeFile(lockPath, JSON.stringify(nextMetadata), {
197
- encoding: UTF8_ENCODING,
198
- flag: 'wx',
199
- });
200
- } catch (writeError) {
201
- if ((writeError as NodeJS.ErrnoException).code === 'EEXIST') {
202
- return {
203
- acquired: false,
204
- is_stale: false,
205
- lock_path: lockPath,
206
- };
207
- }
208
- throw writeError;
209
- }
210
-
211
- return {
212
- acquired: true,
213
- is_stale: true,
214
- lock_path: lockPath,
215
- };
216
- } finally {
217
- await cleanupTakeoverMarker(takeoverMarkerPath);
218
- }
219
- }
220
-
221
- return {
222
- acquired: false,
223
- is_stale: false,
224
- lock_path: lockPath,
225
- };
226
- }
227
- }
228
-
229
- export async function releaseLaneLockTool(
230
- input: ReleaseLaneLockInput,
231
- ): Promise<ReleaseLaneLockResult> {
232
- const lockPath = lockPathFor(input);
233
- const metadata = await readLaneLockMetadata(lockPath);
234
- if (!metadata || metadata.owner !== input.owner) {
235
- return {
236
- released: false,
237
- lock_path: lockPath,
238
- };
239
- }
240
-
241
- await unlink(lockPath);
242
- return {
243
- released: true,
244
- lock_path: lockPath,
245
- };
246
- }
@@ -1,470 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- import type { ToolOutput } from '@lumenflow/kernel';
5
- import { RUNTIME_CLI_COMMANDS, runtimeCliAdapter } from './runtime-cli-adapter.js';
6
-
7
- const MEMORY_TOOLS = {
8
- MEM_INIT: 'mem:init',
9
- MEM_START: 'mem:start',
10
- MEM_READY: 'mem:ready',
11
- MEM_CHECKPOINT: 'mem:checkpoint',
12
- MEM_CLEANUP: 'mem:cleanup',
13
- MEM_CONTEXT: 'mem:context',
14
- MEM_CREATE: 'mem:create',
15
- MEM_DELETE: 'mem:delete',
16
- MEM_EXPORT: 'mem:export',
17
- MEM_INBOX: 'mem:inbox',
18
- MEM_SIGNAL: 'mem:signal',
19
- MEM_CONVERGED: 'mem:converged',
20
- MEM_SUMMARIZE: 'mem:summarize',
21
- MEM_TRIAGE: 'mem:triage',
22
- MEM_RECOVER: 'mem:recover',
23
- } as const;
24
-
25
- type MemoryToolName = (typeof MEMORY_TOOLS)[keyof typeof MEMORY_TOOLS];
26
-
27
- const MEMORY_TOOL_ERROR_CODES: Record<MemoryToolName, string> = {
28
- 'mem:init': 'MEM_INIT_ERROR',
29
- 'mem:start': 'MEM_START_ERROR',
30
- 'mem:ready': 'MEM_READY_ERROR',
31
- 'mem:checkpoint': 'MEM_CHECKPOINT_ERROR',
32
- 'mem:cleanup': 'MEM_CLEANUP_ERROR',
33
- 'mem:context': 'MEM_CONTEXT_ERROR',
34
- 'mem:create': 'MEM_CREATE_ERROR',
35
- 'mem:delete': 'MEM_DELETE_ERROR',
36
- 'mem:export': 'MEM_EXPORT_ERROR',
37
- 'mem:inbox': 'MEM_INBOX_ERROR',
38
- 'mem:signal': 'MEM_SIGNAL_ERROR',
39
- 'mem:converged': 'MEM_CONVERGED_ERROR',
40
- 'mem:summarize': 'MEM_SUMMARIZE_ERROR',
41
- 'mem:triage': 'MEM_TRIAGE_ERROR',
42
- 'mem:recover': 'MEM_RECOVER_ERROR',
43
- };
44
-
45
- const MEMORY_TOOL_COMMANDS: Record<
46
- MemoryToolName,
47
- (typeof RUNTIME_CLI_COMMANDS)[keyof typeof RUNTIME_CLI_COMMANDS]
48
- > = {
49
- 'mem:init': RUNTIME_CLI_COMMANDS.MEM_INIT,
50
- 'mem:start': RUNTIME_CLI_COMMANDS.MEM_START,
51
- 'mem:ready': RUNTIME_CLI_COMMANDS.MEM_READY,
52
- 'mem:checkpoint': RUNTIME_CLI_COMMANDS.MEM_CHECKPOINT,
53
- 'mem:cleanup': RUNTIME_CLI_COMMANDS.MEM_CLEANUP,
54
- 'mem:context': RUNTIME_CLI_COMMANDS.MEM_CONTEXT,
55
- 'mem:create': RUNTIME_CLI_COMMANDS.MEM_CREATE,
56
- 'mem:delete': RUNTIME_CLI_COMMANDS.MEM_DELETE,
57
- 'mem:export': RUNTIME_CLI_COMMANDS.MEM_EXPORT,
58
- 'mem:inbox': RUNTIME_CLI_COMMANDS.MEM_INBOX,
59
- 'mem:signal': RUNTIME_CLI_COMMANDS.MEM_SIGNAL,
60
- 'mem:converged': RUNTIME_CLI_COMMANDS.MEM_CONVERGED,
61
- 'mem:summarize': RUNTIME_CLI_COMMANDS.MEM_SUMMARIZE,
62
- 'mem:triage': RUNTIME_CLI_COMMANDS.MEM_TRIAGE,
63
- 'mem:recover': RUNTIME_CLI_COMMANDS.MEM_RECOVER,
64
- };
65
-
66
- const MISSING_PARAMETER_MESSAGES = {
67
- ID_REQUIRED: 'id is required',
68
- WU_REQUIRED: 'wu is required',
69
- MESSAGE_REQUIRED: 'message is required',
70
- } as const;
71
-
72
- interface CommandExecutionResult {
73
- ok: boolean;
74
- status: number;
75
- stdout: string;
76
- stderr: string;
77
- executionError?: string;
78
- }
79
-
80
- function toRecord(input: unknown): Record<string, unknown> {
81
- if (input && typeof input === 'object') {
82
- return input as Record<string, unknown>;
83
- }
84
- return {};
85
- }
86
-
87
- function toStringValue(value: unknown): string | null {
88
- if (typeof value !== 'string') {
89
- return null;
90
- }
91
- const trimmed = value.trim();
92
- return trimmed.length > 0 ? trimmed : null;
93
- }
94
-
95
- function toStringArray(value: unknown): string[] {
96
- if (!Array.isArray(value)) {
97
- return [];
98
- }
99
- return value
100
- .map((entry) => toStringValue(entry))
101
- .filter((entry): entry is string => entry !== null);
102
- }
103
-
104
- function toIntegerString(value: unknown): string | null {
105
- if (typeof value === 'number' && Number.isFinite(value)) {
106
- return String(Math.trunc(value));
107
- }
108
- if (typeof value === 'string') {
109
- const trimmed = value.trim();
110
- return trimmed.length > 0 ? trimmed : null;
111
- }
112
- return null;
113
- }
114
-
115
- async function runMemoryCommand(
116
- toolName: MemoryToolName,
117
- args: string[],
118
- ): Promise<CommandExecutionResult> {
119
- return runtimeCliAdapter.run(MEMORY_TOOL_COMMANDS[toolName], args);
120
- }
121
-
122
- function createMissingParameterOutput(message: string): ToolOutput {
123
- return {
124
- success: false,
125
- error: {
126
- code: 'MISSING_PARAMETER',
127
- message,
128
- },
129
- };
130
- }
131
-
132
- function createFailureOutput(
133
- toolName: MemoryToolName,
134
- execution: CommandExecutionResult,
135
- ): ToolOutput {
136
- const stderrMessage = execution.stderr.trim();
137
- const stdoutMessage = execution.stdout.trim();
138
- const message =
139
- execution.executionError ??
140
- (stderrMessage.length > 0
141
- ? stderrMessage
142
- : stdoutMessage.length > 0
143
- ? stdoutMessage
144
- : `${toolName} failed`);
145
- return {
146
- success: false,
147
- error: {
148
- code: MEMORY_TOOL_ERROR_CODES[toolName],
149
- message,
150
- details: {
151
- exit_code: execution.status,
152
- stdout: execution.stdout,
153
- stderr: execution.stderr,
154
- },
155
- },
156
- };
157
- }
158
-
159
- function parseJsonOutput(stdout: string): unknown | null {
160
- const trimmed = stdout.trim();
161
- if (trimmed.length === 0) {
162
- return null;
163
- }
164
- try {
165
- return JSON.parse(trimmed) as unknown;
166
- } catch {
167
- return null;
168
- }
169
- }
170
-
171
- function createSuccessOutput(
172
- toolName: MemoryToolName,
173
- execution: CommandExecutionResult,
174
- ): ToolOutput {
175
- const parsedJson = parseJsonOutput(execution.stdout);
176
- if (parsedJson !== null) {
177
- return {
178
- success: true,
179
- data: parsedJson,
180
- };
181
- }
182
-
183
- const message = execution.stdout.trim().length > 0 ? execution.stdout.trim() : `${toolName} ran`;
184
- return {
185
- success: true,
186
- data: {
187
- message,
188
- },
189
- };
190
- }
191
-
192
- async function executeMemoryTool(toolName: MemoryToolName, args: string[]): Promise<ToolOutput> {
193
- const execution = await runMemoryCommand(toolName, args);
194
- if (!execution.ok) {
195
- return createFailureOutput(toolName, execution);
196
- }
197
- return createSuccessOutput(toolName, execution);
198
- }
199
-
200
- export async function memInitTool(input: unknown): Promise<ToolOutput> {
201
- const parsed = toRecord(input);
202
- const wu = toStringValue(parsed.wu);
203
- if (!wu) {
204
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
205
- }
206
-
207
- return executeMemoryTool(MEMORY_TOOLS.MEM_INIT, ['--wu', wu]);
208
- }
209
-
210
- export async function memStartTool(input: unknown): Promise<ToolOutput> {
211
- const parsed = toRecord(input);
212
- const wu = toStringValue(parsed.wu);
213
- if (!wu) {
214
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
215
- }
216
-
217
- const args = ['--wu', wu];
218
- const lane = toStringValue(parsed.lane);
219
- if (lane) {
220
- args.push('--lane', lane);
221
- }
222
-
223
- return executeMemoryTool(MEMORY_TOOLS.MEM_START, args);
224
- }
225
-
226
- export async function memReadyTool(input: unknown): Promise<ToolOutput> {
227
- const parsed = toRecord(input);
228
- const wu = toStringValue(parsed.wu);
229
- if (!wu) {
230
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
231
- }
232
-
233
- return executeMemoryTool(MEMORY_TOOLS.MEM_READY, ['--wu', wu]);
234
- }
235
-
236
- export async function memCheckpointTool(input: unknown): Promise<ToolOutput> {
237
- const parsed = toRecord(input);
238
- const wu = toStringValue(parsed.wu);
239
- if (!wu) {
240
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
241
- }
242
-
243
- const args = ['--wu', wu];
244
- const message = toStringValue(parsed.message);
245
- if (message) {
246
- args.push('--message', message);
247
- }
248
-
249
- return executeMemoryTool(MEMORY_TOOLS.MEM_CHECKPOINT, args);
250
- }
251
-
252
- export async function memCleanupTool(input: unknown): Promise<ToolOutput> {
253
- const parsed = toRecord(input);
254
- const args: string[] = [];
255
- if (parsed.dry_run === true) {
256
- args.push('--dry-run');
257
- }
258
-
259
- return executeMemoryTool(MEMORY_TOOLS.MEM_CLEANUP, args);
260
- }
261
-
262
- export async function memContextTool(input: unknown): Promise<ToolOutput> {
263
- const parsed = toRecord(input);
264
- const wu = toStringValue(parsed.wu);
265
- if (!wu) {
266
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
267
- }
268
-
269
- const args = ['--wu', wu];
270
- const lane = toStringValue(parsed.lane);
271
- if (lane) {
272
- args.push('--lane', lane);
273
- }
274
-
275
- return executeMemoryTool(MEMORY_TOOLS.MEM_CONTEXT, args);
276
- }
277
-
278
- export async function memCreateTool(input: unknown): Promise<ToolOutput> {
279
- const parsed = toRecord(input);
280
- const message = toStringValue(parsed.message);
281
- if (!message) {
282
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.MESSAGE_REQUIRED);
283
- }
284
-
285
- const wu = toStringValue(parsed.wu);
286
- if (!wu) {
287
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
288
- }
289
-
290
- const args = [message, '--wu', wu];
291
- const type = toStringValue(parsed.type);
292
- if (type) {
293
- args.push('--type', type);
294
- }
295
- const tags = toStringArray(parsed.tags);
296
- if (tags.length > 0) {
297
- args.push('--tags', tags.join(','));
298
- }
299
-
300
- return executeMemoryTool(MEMORY_TOOLS.MEM_CREATE, args);
301
- }
302
-
303
- export async function memDeleteTool(input: unknown): Promise<ToolOutput> {
304
- const parsed = toRecord(input);
305
- const id = toStringValue(parsed.id);
306
- if (!id) {
307
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.ID_REQUIRED);
308
- }
309
-
310
- return executeMemoryTool(MEMORY_TOOLS.MEM_DELETE, ['--id', id]);
311
- }
312
-
313
- export async function memExportTool(input: unknown): Promise<ToolOutput> {
314
- const parsed = toRecord(input);
315
- const wu = toStringValue(parsed.wu);
316
- if (!wu) {
317
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
318
- }
319
-
320
- const args = ['--wu', wu];
321
- const format = toStringValue(parsed.format);
322
- if (format) {
323
- args.push('--format', format);
324
- }
325
-
326
- return executeMemoryTool(MEMORY_TOOLS.MEM_EXPORT, args);
327
- }
328
-
329
- export async function memInboxTool(input: unknown): Promise<ToolOutput> {
330
- const parsed = toRecord(input);
331
- const args: string[] = [];
332
- const since = toStringValue(parsed.since);
333
- if (since) {
334
- args.push('--since', since);
335
- }
336
- const wu = toStringValue(parsed.wu);
337
- if (wu) {
338
- args.push('--wu', wu);
339
- }
340
- const lane = toStringValue(parsed.lane);
341
- if (lane) {
342
- args.push('--lane', lane);
343
- }
344
- const reader = toStringValue(parsed.for);
345
- if (reader) {
346
- args.push('--for', reader);
347
- }
348
- const thread = toStringValue(parsed.thread);
349
- if (thread) {
350
- args.push('--thread', thread);
351
- }
352
- const intent = toStringValue(parsed.intent);
353
- if (intent) {
354
- args.push('--intent', intent);
355
- }
356
-
357
- return executeMemoryTool(MEMORY_TOOLS.MEM_INBOX, args);
358
- }
359
-
360
- export async function memSignalTool(input: unknown): Promise<ToolOutput> {
361
- const parsed = toRecord(input);
362
- const message = toStringValue(parsed.message);
363
- if (!message) {
364
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.MESSAGE_REQUIRED);
365
- }
366
-
367
- const wu = toStringValue(parsed.wu);
368
- if (!wu) {
369
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
370
- }
371
-
372
- const args = [message, '--wu', wu];
373
- const to = toStringValue(parsed.to);
374
- if (to) {
375
- args.push('--to', to);
376
- }
377
- const thread = toStringValue(parsed.thread);
378
- if (thread) {
379
- args.push('--thread', thread);
380
- }
381
- const replyTo = toStringValue(parsed.reply_to);
382
- if (replyTo) {
383
- args.push('--reply-to', replyTo);
384
- }
385
- const intent = toStringValue(parsed.intent);
386
- if (intent) {
387
- args.push('--intent', intent);
388
- }
389
- const interrupt = toStringValue(parsed.interrupt);
390
- if (interrupt) {
391
- args.push('--interrupt', interrupt);
392
- }
393
- if (parsed.requires_ack === true) {
394
- args.push('--requires-ack');
395
- }
396
-
397
- return executeMemoryTool(MEMORY_TOOLS.MEM_SIGNAL, args);
398
- }
399
-
400
- export async function memConvergedTool(input: unknown): Promise<ToolOutput> {
401
- const parsed = toRecord(input);
402
- const thread = toStringValue(parsed.thread);
403
- if (!thread) {
404
- return createMissingParameterOutput('thread is required');
405
- }
406
-
407
- const args = ['--thread', thread];
408
- if (parsed.quiet === true) {
409
- args.push('--quiet');
410
- }
411
-
412
- return executeMemoryTool(MEMORY_TOOLS.MEM_CONVERGED, args);
413
- }
414
-
415
- export async function memSummarizeTool(input: unknown): Promise<ToolOutput> {
416
- const parsed = toRecord(input);
417
- const wu = toStringValue(parsed.wu);
418
- if (!wu) {
419
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
420
- }
421
-
422
- return executeMemoryTool(MEMORY_TOOLS.MEM_SUMMARIZE, ['--wu', wu]);
423
- }
424
-
425
- export async function memTriageTool(input: unknown): Promise<ToolOutput> {
426
- const parsed = toRecord(input);
427
- const wu = toStringValue(parsed.wu);
428
- if (!wu) {
429
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
430
- }
431
-
432
- const args = ['--wu', wu];
433
- const promote = toStringValue(parsed.promote);
434
- if (promote) {
435
- args.push('--promote', promote);
436
- }
437
- const lane = toStringValue(parsed.lane);
438
- if (lane) {
439
- args.push('--lane', lane);
440
- }
441
-
442
- return executeMemoryTool(MEMORY_TOOLS.MEM_TRIAGE, args);
443
- }
444
-
445
- export async function memRecoverTool(input: unknown): Promise<ToolOutput> {
446
- const parsed = toRecord(input);
447
- const wu = toStringValue(parsed.wu);
448
- if (!wu) {
449
- return createMissingParameterOutput(MISSING_PARAMETER_MESSAGES.WU_REQUIRED);
450
- }
451
-
452
- const args = ['--wu', wu];
453
- const maxSize = toIntegerString(parsed.max_size);
454
- if (maxSize) {
455
- args.push('--max-size', maxSize);
456
- }
457
- const format = toStringValue(parsed.format);
458
- if (format) {
459
- args.push('--format', format);
460
- }
461
- if (parsed.quiet === true) {
462
- args.push('--quiet');
463
- }
464
- const baseDir = toStringValue(parsed.base_dir);
465
- if (baseDir) {
466
- args.push('--base-dir', baseDir);
467
- }
468
-
469
- return executeMemoryTool(MEMORY_TOOLS.MEM_RECOVER, args);
470
- }