@lumenflow/cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +116 -0
- package/dist/gates.d.ts +41 -0
- package/dist/gates.d.ts.map +1 -0
- package/dist/gates.js +684 -0
- package/dist/gates.js.map +1 -0
- package/dist/initiative-add-wu.d.ts +22 -0
- package/dist/initiative-add-wu.d.ts.map +1 -0
- package/dist/initiative-add-wu.js +234 -0
- package/dist/initiative-add-wu.js.map +1 -0
- package/dist/initiative-create.d.ts +28 -0
- package/dist/initiative-create.d.ts.map +1 -0
- package/dist/initiative-create.js +172 -0
- package/dist/initiative-create.js.map +1 -0
- package/dist/initiative-edit.d.ts +34 -0
- package/dist/initiative-edit.d.ts.map +1 -0
- package/dist/initiative-edit.js +440 -0
- package/dist/initiative-edit.js.map +1 -0
- package/dist/initiative-list.d.ts +12 -0
- package/dist/initiative-list.d.ts.map +1 -0
- package/dist/initiative-list.js +101 -0
- package/dist/initiative-list.js.map +1 -0
- package/dist/initiative-status.d.ts +11 -0
- package/dist/initiative-status.d.ts.map +1 -0
- package/dist/initiative-status.js +221 -0
- package/dist/initiative-status.js.map +1 -0
- package/dist/mem-checkpoint.d.ts +16 -0
- package/dist/mem-checkpoint.d.ts.map +1 -0
- package/dist/mem-checkpoint.js +237 -0
- package/dist/mem-checkpoint.js.map +1 -0
- package/dist/mem-cleanup.d.ts +29 -0
- package/dist/mem-cleanup.d.ts.map +1 -0
- package/dist/mem-cleanup.js +267 -0
- package/dist/mem-cleanup.js.map +1 -0
- package/dist/mem-create.d.ts +17 -0
- package/dist/mem-create.d.ts.map +1 -0
- package/dist/mem-create.js +265 -0
- package/dist/mem-create.js.map +1 -0
- package/dist/mem-inbox.d.ts +35 -0
- package/dist/mem-inbox.d.ts.map +1 -0
- package/dist/mem-inbox.js +373 -0
- package/dist/mem-inbox.js.map +1 -0
- package/dist/mem-init.d.ts +15 -0
- package/dist/mem-init.d.ts.map +1 -0
- package/dist/mem-init.js +146 -0
- package/dist/mem-init.js.map +1 -0
- package/dist/mem-ready.d.ts +16 -0
- package/dist/mem-ready.d.ts.map +1 -0
- package/dist/mem-ready.js +224 -0
- package/dist/mem-ready.js.map +1 -0
- package/dist/mem-signal.d.ts +16 -0
- package/dist/mem-signal.d.ts.map +1 -0
- package/dist/mem-signal.js +204 -0
- package/dist/mem-signal.js.map +1 -0
- package/dist/mem-start.d.ts +16 -0
- package/dist/mem-start.d.ts.map +1 -0
- package/dist/mem-start.js +158 -0
- package/dist/mem-start.js.map +1 -0
- package/dist/mem-summarize.d.ts +22 -0
- package/dist/mem-summarize.d.ts.map +1 -0
- package/dist/mem-summarize.js +213 -0
- package/dist/mem-summarize.js.map +1 -0
- package/dist/mem-triage.d.ts +22 -0
- package/dist/mem-triage.d.ts.map +1 -0
- package/dist/mem-triage.js +328 -0
- package/dist/mem-triage.js.map +1 -0
- package/dist/spawn-list.d.ts +16 -0
- package/dist/spawn-list.d.ts.map +1 -0
- package/dist/spawn-list.js +140 -0
- package/dist/spawn-list.js.map +1 -0
- package/dist/wu-block.d.ts +16 -0
- package/dist/wu-block.d.ts.map +1 -0
- package/dist/wu-block.js +241 -0
- package/dist/wu-block.js.map +1 -0
- package/dist/wu-claim.d.ts +32 -0
- package/dist/wu-claim.d.ts.map +1 -0
- package/dist/wu-claim.js +1106 -0
- package/dist/wu-claim.js.map +1 -0
- package/dist/wu-cleanup.d.ts +17 -0
- package/dist/wu-cleanup.d.ts.map +1 -0
- package/dist/wu-cleanup.js +194 -0
- package/dist/wu-cleanup.js.map +1 -0
- package/dist/wu-create.d.ts +38 -0
- package/dist/wu-create.d.ts.map +1 -0
- package/dist/wu-create.js +520 -0
- package/dist/wu-create.js.map +1 -0
- package/dist/wu-deps.d.ts +13 -0
- package/dist/wu-deps.d.ts.map +1 -0
- package/dist/wu-deps.js +119 -0
- package/dist/wu-deps.js.map +1 -0
- package/dist/wu-done.d.ts +153 -0
- package/dist/wu-done.d.ts.map +1 -0
- package/dist/wu-done.js +2096 -0
- package/dist/wu-done.js.map +1 -0
- package/dist/wu-edit.d.ts +29 -0
- package/dist/wu-edit.d.ts.map +1 -0
- package/dist/wu-edit.js +852 -0
- package/dist/wu-edit.js.map +1 -0
- package/dist/wu-infer-lane.d.ts +17 -0
- package/dist/wu-infer-lane.d.ts.map +1 -0
- package/dist/wu-infer-lane.js +135 -0
- package/dist/wu-infer-lane.js.map +1 -0
- package/dist/wu-preflight.d.ts +47 -0
- package/dist/wu-preflight.d.ts.map +1 -0
- package/dist/wu-preflight.js +167 -0
- package/dist/wu-preflight.js.map +1 -0
- package/dist/wu-prune.d.ts +16 -0
- package/dist/wu-prune.d.ts.map +1 -0
- package/dist/wu-prune.js +259 -0
- package/dist/wu-prune.js.map +1 -0
- package/dist/wu-repair.d.ts +60 -0
- package/dist/wu-repair.d.ts.map +1 -0
- package/dist/wu-repair.js +226 -0
- package/dist/wu-repair.js.map +1 -0
- package/dist/wu-spawn-completion.d.ts +10 -0
- package/dist/wu-spawn-completion.js +30 -0
- package/dist/wu-spawn.d.ts +168 -0
- package/dist/wu-spawn.d.ts.map +1 -0
- package/dist/wu-spawn.js +1327 -0
- package/dist/wu-spawn.js.map +1 -0
- package/dist/wu-unblock.d.ts +16 -0
- package/dist/wu-unblock.d.ts.map +1 -0
- package/dist/wu-unblock.js +234 -0
- package/dist/wu-unblock.js.map +1 -0
- package/dist/wu-validate.d.ts +16 -0
- package/dist/wu-validate.d.ts.map +1 -0
- package/dist/wu-validate.js +193 -0
- package/dist/wu-validate.js.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Memory Cleanup CLI (WU-1472, WU-1554)
|
|
4
|
+
*
|
|
5
|
+
* Prune closed memory nodes based on lifecycle policy and TTL.
|
|
6
|
+
* Implements compaction to prevent memory bloat.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Remove ephemeral nodes (always discarded)
|
|
10
|
+
* - Remove session nodes when session is closed
|
|
11
|
+
* - Archive summarized nodes (marked with summarized_into)
|
|
12
|
+
* - Respect sensitive:true flag for stricter retention
|
|
13
|
+
* - Support dry-run mode for preview
|
|
14
|
+
* - Report compaction metrics (ratio, bytes freed)
|
|
15
|
+
* - WU-1554: TTL-based expiration (e.g., --ttl 30d)
|
|
16
|
+
* - WU-1554: Active session protection (never removed)
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* pnpm mem:cleanup # Cleanup based on lifecycle policy
|
|
20
|
+
* pnpm mem:cleanup --dry-run # Preview without changes
|
|
21
|
+
* pnpm mem:cleanup --ttl 30d # Remove nodes older than 30 days
|
|
22
|
+
* pnpm mem:cleanup --ttl 7d --dry-run # Preview TTL cleanup
|
|
23
|
+
* pnpm mem:cleanup --session-id <uuid> # Close specific session
|
|
24
|
+
* pnpm mem:cleanup --json # Output as JSON
|
|
25
|
+
*
|
|
26
|
+
* @see {@link tools/lib/mem-cleanup-core.mjs} - Core logic
|
|
27
|
+
* @see {@link tools/__tests__/mem-cleanup.test.mjs} - Tests
|
|
28
|
+
*/
|
|
29
|
+
import fs from 'node:fs/promises';
|
|
30
|
+
import path from 'node:path';
|
|
31
|
+
import { cleanupMemory } from '@lumenflow/memory/dist/mem-cleanup-core.js';
|
|
32
|
+
import { createWUParser } from '@lumenflow/core/dist/arg-parser.js';
|
|
33
|
+
import { EXIT_CODES } from '@lumenflow/core/dist/wu-constants.js';
|
|
34
|
+
/**
|
|
35
|
+
* Log prefix for mem:cleanup output
|
|
36
|
+
*/
|
|
37
|
+
const LOG_PREFIX = '[mem:cleanup]';
|
|
38
|
+
/**
|
|
39
|
+
* Tool name for audit logging
|
|
40
|
+
*/
|
|
41
|
+
const TOOL_NAME = 'mem:cleanup';
|
|
42
|
+
/**
|
|
43
|
+
* Audit log file path
|
|
44
|
+
*/
|
|
45
|
+
const AUDIT_LOG_PATH = '.beacon/telemetry/tools.ndjson';
|
|
46
|
+
/**
|
|
47
|
+
* Bytes per KB for formatting
|
|
48
|
+
*/
|
|
49
|
+
const BYTES_PER_KB = 1024;
|
|
50
|
+
/**
|
|
51
|
+
* CLI argument options specific to mem:cleanup
|
|
52
|
+
*/
|
|
53
|
+
const CLI_OPTIONS = {
|
|
54
|
+
dryRun: {
|
|
55
|
+
name: 'dryRun',
|
|
56
|
+
flags: '--dry-run',
|
|
57
|
+
description: 'Preview cleanup without making changes',
|
|
58
|
+
},
|
|
59
|
+
ttl: {
|
|
60
|
+
name: 'ttl',
|
|
61
|
+
flags: '--ttl <duration>',
|
|
62
|
+
description: 'Remove nodes older than duration (e.g., 30d, 7d, 24h). Active sessions are protected.',
|
|
63
|
+
},
|
|
64
|
+
sessionId: {
|
|
65
|
+
name: 'sessionId',
|
|
66
|
+
flags: '--session-id <uuid>',
|
|
67
|
+
description: 'Session ID to consider closed (removes session lifecycle nodes)',
|
|
68
|
+
},
|
|
69
|
+
json: {
|
|
70
|
+
name: 'json',
|
|
71
|
+
flags: '--json',
|
|
72
|
+
description: 'Output as JSON',
|
|
73
|
+
},
|
|
74
|
+
quiet: {
|
|
75
|
+
name: 'quiet',
|
|
76
|
+
flags: '-q, --quiet',
|
|
77
|
+
description: 'Suppress output except errors',
|
|
78
|
+
},
|
|
79
|
+
baseDir: {
|
|
80
|
+
name: 'baseDir',
|
|
81
|
+
flags: '-b, --base-dir <path>',
|
|
82
|
+
description: 'Base directory (defaults to current directory)',
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Write audit log entry for tool execution
|
|
87
|
+
*
|
|
88
|
+
* @param {string} baseDir - Base directory
|
|
89
|
+
* @param {object} entry - Audit log entry
|
|
90
|
+
*/
|
|
91
|
+
async function writeAuditLog(baseDir, entry) {
|
|
92
|
+
try {
|
|
93
|
+
const logPath = path.join(baseDir, AUDIT_LOG_PATH);
|
|
94
|
+
const logDir = path.dirname(logPath);
|
|
95
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- CLI tool creates known directory
|
|
96
|
+
await fs.mkdir(logDir, { recursive: true });
|
|
97
|
+
const line = `${JSON.stringify(entry)}\n`;
|
|
98
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- CLI tool writes audit log
|
|
99
|
+
await fs.appendFile(logPath, line, 'utf-8');
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
// Audit logging is non-fatal - silently ignore errors
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Format bytes as human-readable string
|
|
107
|
+
*
|
|
108
|
+
* @param {number} bytes - Number of bytes
|
|
109
|
+
* @returns {string} Formatted string (e.g., "1.5 KB")
|
|
110
|
+
*/
|
|
111
|
+
function formatBytes(bytes) {
|
|
112
|
+
if (bytes < BYTES_PER_KB) {
|
|
113
|
+
return `${bytes} B`;
|
|
114
|
+
}
|
|
115
|
+
const kb = (bytes / BYTES_PER_KB).toFixed(1);
|
|
116
|
+
return `${kb} KB`;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Format compaction ratio as percentage
|
|
120
|
+
*
|
|
121
|
+
* @param {number} ratio - Compaction ratio (0-1)
|
|
122
|
+
* @returns {string} Formatted percentage
|
|
123
|
+
*/
|
|
124
|
+
function formatRatio(ratio) {
|
|
125
|
+
return `${(ratio * 100).toFixed(1)}%`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parse CLI arguments
|
|
129
|
+
*
|
|
130
|
+
* @returns {object} Parsed arguments
|
|
131
|
+
*/
|
|
132
|
+
function parseArguments() {
|
|
133
|
+
return createWUParser({
|
|
134
|
+
name: 'mem-cleanup',
|
|
135
|
+
description: 'Prune closed memory nodes based on lifecycle policy and TTL',
|
|
136
|
+
options: [
|
|
137
|
+
CLI_OPTIONS.dryRun,
|
|
138
|
+
CLI_OPTIONS.ttl,
|
|
139
|
+
CLI_OPTIONS.sessionId,
|
|
140
|
+
CLI_OPTIONS.json,
|
|
141
|
+
CLI_OPTIONS.quiet,
|
|
142
|
+
CLI_OPTIONS.baseDir,
|
|
143
|
+
],
|
|
144
|
+
required: [],
|
|
145
|
+
allowPositionalId: false,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Print cleanup result to console
|
|
150
|
+
*
|
|
151
|
+
* @param {object} result - Cleanup result
|
|
152
|
+
* @param {boolean} quiet - Suppress verbose output
|
|
153
|
+
* @param {string} [ttl] - TTL string if provided
|
|
154
|
+
*/
|
|
155
|
+
function printResult(result, quiet, ttl) {
|
|
156
|
+
if (result.dryRun) {
|
|
157
|
+
console.log(`${LOG_PREFIX} Dry-run: Would remove ${result.removedIds.length} node(s)`);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
console.log(`${LOG_PREFIX} Cleanup complete`);
|
|
161
|
+
}
|
|
162
|
+
if (quiet) {
|
|
163
|
+
console.log(`${result.removedIds.length} removed, ${result.retainedIds.length} retained`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
console.log('');
|
|
167
|
+
console.log('Summary:');
|
|
168
|
+
console.log(` Removed: ${result.removedIds.length} node(s)`);
|
|
169
|
+
console.log(` Retained: ${result.retainedIds.length} node(s)`);
|
|
170
|
+
console.log(` Bytes Freed: ${formatBytes(result.bytesFreed)}`);
|
|
171
|
+
console.log(` Compaction Ratio: ${formatRatio(result.compactionRatio)}`);
|
|
172
|
+
// WU-1554: Show TTL if provided
|
|
173
|
+
if (ttl) {
|
|
174
|
+
console.log(` TTL: ${ttl}`);
|
|
175
|
+
}
|
|
176
|
+
console.log('');
|
|
177
|
+
console.log('Breakdown by Lifecycle:');
|
|
178
|
+
console.log(` Ephemeral: ${result.breakdown.ephemeral} removed`);
|
|
179
|
+
console.log(` Session: ${result.breakdown.session} removed`);
|
|
180
|
+
console.log(` WU (summarized): ${result.breakdown.wu} removed`);
|
|
181
|
+
console.log(` Sensitive: ${result.breakdown.sensitive} retained (stricter policy)`);
|
|
182
|
+
// WU-1554: Show TTL breakdown
|
|
183
|
+
if (result.breakdown.ttlExpired > 0 || result.breakdown.activeSessionProtected > 0) {
|
|
184
|
+
console.log('');
|
|
185
|
+
console.log('TTL Breakdown:');
|
|
186
|
+
console.log(` TTL Expired: ${result.breakdown.ttlExpired} removed`);
|
|
187
|
+
console.log(` Active Sessions: ${result.breakdown.activeSessionProtected} protected`);
|
|
188
|
+
}
|
|
189
|
+
if (result.removedIds.length > 0 && !result.dryRun) {
|
|
190
|
+
console.log('');
|
|
191
|
+
console.log('Removed Node IDs:');
|
|
192
|
+
// Show first 10, then "and X more" if needed
|
|
193
|
+
const displayLimit = 10;
|
|
194
|
+
const displayIds = result.removedIds.slice(0, displayLimit);
|
|
195
|
+
for (const id of displayIds) {
|
|
196
|
+
console.log(` - ${id}`);
|
|
197
|
+
}
|
|
198
|
+
if (result.removedIds.length > displayLimit) {
|
|
199
|
+
console.log(` ... and ${result.removedIds.length - displayLimit} more`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (result.dryRun) {
|
|
203
|
+
console.log('');
|
|
204
|
+
console.log('To execute, run without --dry-run');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Main CLI entry point
|
|
209
|
+
*/
|
|
210
|
+
async function main() {
|
|
211
|
+
const args = parseArguments();
|
|
212
|
+
const baseDir = args.baseDir || process.cwd();
|
|
213
|
+
const startedAt = new Date().toISOString();
|
|
214
|
+
const startTime = Date.now();
|
|
215
|
+
let result = null;
|
|
216
|
+
let error = null;
|
|
217
|
+
try {
|
|
218
|
+
result = await cleanupMemory(baseDir, {
|
|
219
|
+
dryRun: args.dryRun,
|
|
220
|
+
sessionId: args.sessionId,
|
|
221
|
+
ttl: args.ttl,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
error = err.message;
|
|
226
|
+
}
|
|
227
|
+
const durationMs = Date.now() - startTime;
|
|
228
|
+
await writeAuditLog(baseDir, {
|
|
229
|
+
tool: TOOL_NAME,
|
|
230
|
+
status: error ? 'failed' : 'success',
|
|
231
|
+
startedAt,
|
|
232
|
+
completedAt: new Date().toISOString(),
|
|
233
|
+
durationMs,
|
|
234
|
+
input: {
|
|
235
|
+
baseDir,
|
|
236
|
+
dryRun: args.dryRun,
|
|
237
|
+
sessionId: args.sessionId,
|
|
238
|
+
ttl: args.ttl,
|
|
239
|
+
},
|
|
240
|
+
output: result
|
|
241
|
+
? {
|
|
242
|
+
success: result.success,
|
|
243
|
+
removedCount: result.removedIds.length,
|
|
244
|
+
retainedCount: result.retainedIds.length,
|
|
245
|
+
bytesFreed: result.bytesFreed,
|
|
246
|
+
compactionRatio: result.compactionRatio,
|
|
247
|
+
breakdown: result.breakdown,
|
|
248
|
+
dryRun: result.dryRun,
|
|
249
|
+
ttlMs: result.ttlMs,
|
|
250
|
+
}
|
|
251
|
+
: null,
|
|
252
|
+
error: error ? { message: error } : null,
|
|
253
|
+
});
|
|
254
|
+
if (error) {
|
|
255
|
+
console.error(`${LOG_PREFIX} Error: ${error}`);
|
|
256
|
+
process.exit(EXIT_CODES.ERROR);
|
|
257
|
+
}
|
|
258
|
+
if (args.json) {
|
|
259
|
+
console.log(JSON.stringify(result, null, 2));
|
|
260
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
261
|
+
}
|
|
262
|
+
printResult(result, args.quiet, args.ttl);
|
|
263
|
+
}
|
|
264
|
+
main().catch((e) => {
|
|
265
|
+
console.error(`${LOG_PREFIX} ${e.message}`);
|
|
266
|
+
process.exit(EXIT_CODES.ERROR);
|
|
267
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mem-cleanup.js","sourceRoot":"","sources":["../src/mem-cleanup.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAA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
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Memory Create CLI (WU-1469)
|
|
4
|
+
*
|
|
5
|
+
* Create memory nodes with discovered-from provenance.
|
|
6
|
+
* KEY DIFFERENTIATOR: supports discovered-from relationship for scope-creep
|
|
7
|
+
* forensics. Creates audit trail of WHY work expanded, not just WHAT changed.
|
|
8
|
+
*
|
|
9
|
+
* Includes audit logging to .beacon/telemetry/tools.ndjson.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* pnpm mem:create 'title' [--type <type>] [--discovered-from <id>] [--wu <id>] [--quiet]
|
|
13
|
+
*
|
|
14
|
+
* @see {@link tools/lib/mem-create-core.mjs} - Core logic
|
|
15
|
+
* @see {@link tools/__tests__/mem-create.test.mjs} - Tests
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mem-create.d.ts","sourceRoot":"","sources":["../src/mem-create.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Memory Create CLI (WU-1469)
|
|
4
|
+
*
|
|
5
|
+
* Create memory nodes with discovered-from provenance.
|
|
6
|
+
* KEY DIFFERENTIATOR: supports discovered-from relationship for scope-creep
|
|
7
|
+
* forensics. Creates audit trail of WHY work expanded, not just WHAT changed.
|
|
8
|
+
*
|
|
9
|
+
* Includes audit logging to .beacon/telemetry/tools.ndjson.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* pnpm mem:create 'title' [--type <type>] [--discovered-from <id>] [--wu <id>] [--quiet]
|
|
13
|
+
*
|
|
14
|
+
* @see {@link tools/lib/mem-create-core.mjs} - Core logic
|
|
15
|
+
* @see {@link tools/__tests__/mem-create.test.mjs} - Tests
|
|
16
|
+
*/
|
|
17
|
+
import fs from 'node:fs/promises';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import { createMemoryNode } from '@lumenflow/memory/dist/mem-create-core.js';
|
|
20
|
+
import { createWUParser, WU_OPTIONS } from '@lumenflow/core/dist/arg-parser.js';
|
|
21
|
+
import { EXIT_CODES } from '@lumenflow/core/dist/wu-constants.js';
|
|
22
|
+
import { MEMORY_NODE_TYPES } from '@lumenflow/memory/dist/memory-schema.js';
|
|
23
|
+
/**
|
|
24
|
+
* Log prefix for mem:create output
|
|
25
|
+
*/
|
|
26
|
+
const LOG_PREFIX = '[mem:create]';
|
|
27
|
+
/**
|
|
28
|
+
* Tool name for audit logging
|
|
29
|
+
*/
|
|
30
|
+
const TOOL_NAME = 'mem:create';
|
|
31
|
+
/**
|
|
32
|
+
* Audit log file path
|
|
33
|
+
*/
|
|
34
|
+
const AUDIT_LOG_PATH = '.beacon/telemetry/tools.ndjson';
|
|
35
|
+
/**
|
|
36
|
+
* CLI argument options specific to mem:create
|
|
37
|
+
*/
|
|
38
|
+
const CLI_OPTIONS = {
|
|
39
|
+
title: {
|
|
40
|
+
name: 'title',
|
|
41
|
+
flags: '-t, --title <text>',
|
|
42
|
+
description: 'Node title/content (required if not positional)',
|
|
43
|
+
},
|
|
44
|
+
type: {
|
|
45
|
+
name: 'type',
|
|
46
|
+
flags: '--type <type>',
|
|
47
|
+
description: `Node type: ${MEMORY_NODE_TYPES.join(', ')} (default: discovery). Aliases: bug, idea, question, dependency (stored as discovery + tags).`,
|
|
48
|
+
},
|
|
49
|
+
discoveredFrom: {
|
|
50
|
+
name: 'discoveredFrom',
|
|
51
|
+
flags: '-d, --discovered-from <id>',
|
|
52
|
+
description: 'Parent node ID for provenance tracking (mem-XXXX format)',
|
|
53
|
+
},
|
|
54
|
+
session: {
|
|
55
|
+
name: 'session',
|
|
56
|
+
flags: '-s, --session <id>',
|
|
57
|
+
description: 'Session ID to link node to (UUID)',
|
|
58
|
+
},
|
|
59
|
+
tags: {
|
|
60
|
+
name: 'tags',
|
|
61
|
+
flags: '--tags <tags>',
|
|
62
|
+
description: 'Comma-separated tags for categorization',
|
|
63
|
+
},
|
|
64
|
+
priority: {
|
|
65
|
+
name: 'priority',
|
|
66
|
+
flags: '-p, --priority <level>',
|
|
67
|
+
description: 'Priority level (P0, P1, P2, P3)',
|
|
68
|
+
},
|
|
69
|
+
baseDir: {
|
|
70
|
+
name: 'baseDir',
|
|
71
|
+
flags: '-b, --base-dir <path>',
|
|
72
|
+
description: 'Base directory (defaults to current directory)',
|
|
73
|
+
},
|
|
74
|
+
quiet: {
|
|
75
|
+
name: 'quiet',
|
|
76
|
+
flags: '-q, --quiet',
|
|
77
|
+
description: 'Suppress output except errors',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Write audit log entry for tool execution
|
|
82
|
+
*
|
|
83
|
+
* @param {string} baseDir - Base directory
|
|
84
|
+
* @param {object} entry - Audit log entry
|
|
85
|
+
*/
|
|
86
|
+
async function writeAuditLog(baseDir, entry) {
|
|
87
|
+
try {
|
|
88
|
+
const logPath = path.join(baseDir, AUDIT_LOG_PATH);
|
|
89
|
+
const logDir = path.dirname(logPath);
|
|
90
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- CLI tool creates known directory
|
|
91
|
+
await fs.mkdir(logDir, { recursive: true });
|
|
92
|
+
const line = `${JSON.stringify(entry)}\n`;
|
|
93
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- CLI tool writes audit log
|
|
94
|
+
await fs.appendFile(logPath, line, 'utf-8');
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Audit logging is non-fatal - silently ignore errors
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Parse CLI arguments and extract the title
|
|
102
|
+
*
|
|
103
|
+
* @returns {{args: object, title: string|undefined}} Parsed args and title
|
|
104
|
+
*/
|
|
105
|
+
function parseArguments() {
|
|
106
|
+
const args = createWUParser({
|
|
107
|
+
name: 'mem-create',
|
|
108
|
+
description: 'Create a memory node with optional provenance tracking',
|
|
109
|
+
options: [
|
|
110
|
+
CLI_OPTIONS.title,
|
|
111
|
+
CLI_OPTIONS.type,
|
|
112
|
+
CLI_OPTIONS.discoveredFrom,
|
|
113
|
+
WU_OPTIONS.wu,
|
|
114
|
+
CLI_OPTIONS.session,
|
|
115
|
+
CLI_OPTIONS.tags,
|
|
116
|
+
CLI_OPTIONS.priority,
|
|
117
|
+
CLI_OPTIONS.baseDir,
|
|
118
|
+
CLI_OPTIONS.quiet,
|
|
119
|
+
],
|
|
120
|
+
required: [],
|
|
121
|
+
allowPositionalId: true,
|
|
122
|
+
});
|
|
123
|
+
let title = args.title;
|
|
124
|
+
if (!title && process.argv.length > 2) {
|
|
125
|
+
const positionalArgs = process.argv.slice(2).filter((arg) => !arg.startsWith('-'));
|
|
126
|
+
if (positionalArgs.length > 0) {
|
|
127
|
+
title = positionalArgs[0];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return { args, title };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Print node details to console
|
|
134
|
+
*
|
|
135
|
+
* @param {object} result - Creation result with node and optional relationship
|
|
136
|
+
*/
|
|
137
|
+
function printNodeDetails(result) {
|
|
138
|
+
const { node, relationship } = result;
|
|
139
|
+
console.log(`${LOG_PREFIX} Node created (${node.id})`);
|
|
140
|
+
console.log('');
|
|
141
|
+
console.log('Node Details:');
|
|
142
|
+
console.log(` ID: ${node.id}`);
|
|
143
|
+
console.log(` Type: ${node.type}`);
|
|
144
|
+
console.log(` Lifecycle: ${node.lifecycle}`);
|
|
145
|
+
console.log(` Created At: ${node.created_at}`);
|
|
146
|
+
if (node.wu_id) {
|
|
147
|
+
console.log(` WU: ${node.wu_id}`);
|
|
148
|
+
}
|
|
149
|
+
if (node.session_id) {
|
|
150
|
+
console.log(` Session: ${node.session_id}`);
|
|
151
|
+
}
|
|
152
|
+
console.log('');
|
|
153
|
+
console.log('Content:');
|
|
154
|
+
console.log(` ${node.content}`);
|
|
155
|
+
if (node.tags && node.tags.length > 0) {
|
|
156
|
+
console.log('');
|
|
157
|
+
console.log('Tags:');
|
|
158
|
+
console.log(` ${node.tags.join(', ')}`);
|
|
159
|
+
}
|
|
160
|
+
if (node.metadata) {
|
|
161
|
+
printMetadata(node.metadata);
|
|
162
|
+
}
|
|
163
|
+
if (relationship) {
|
|
164
|
+
console.log('');
|
|
165
|
+
console.log('Provenance:');
|
|
166
|
+
console.log(` Discovered From: ${relationship.to_id}`);
|
|
167
|
+
console.log(` Relationship: ${relationship.type}`);
|
|
168
|
+
}
|
|
169
|
+
console.log('');
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Print metadata section to console
|
|
173
|
+
*
|
|
174
|
+
* @param {object} metadata - Node metadata
|
|
175
|
+
*/
|
|
176
|
+
function printMetadata(metadata) {
|
|
177
|
+
console.log('');
|
|
178
|
+
console.log('Metadata:');
|
|
179
|
+
if (metadata.priority) {
|
|
180
|
+
console.log(` Priority: ${metadata.priority}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Main CLI entry point
|
|
185
|
+
*/
|
|
186
|
+
async function main() {
|
|
187
|
+
const { args, title } = parseArguments();
|
|
188
|
+
if (!title) {
|
|
189
|
+
console.error(`${LOG_PREFIX} Error: title is required`);
|
|
190
|
+
console.error('');
|
|
191
|
+
console.error("Usage: pnpm mem:create 'title' [options]");
|
|
192
|
+
console.error(" pnpm mem:create --title 'title' [options]");
|
|
193
|
+
console.error('');
|
|
194
|
+
console.error('Options:');
|
|
195
|
+
console.error(' --type <type> Node type (discovery, session, checkpoint, note, summary) or alias (bug, idea, question, dependency)');
|
|
196
|
+
console.error(' --discovered-from <id> Parent node ID for provenance (mem-XXXX)');
|
|
197
|
+
console.error(' --wu <id> WU ID to link node to (WU-XXX)');
|
|
198
|
+
console.error(' --session <id> Session ID to link node to (UUID)');
|
|
199
|
+
console.error(' --tags <tags> Comma-separated tags');
|
|
200
|
+
console.error(' --priority <level> Priority level (P0, P1, P2, P3)');
|
|
201
|
+
console.error(' --quiet Suppress output except errors');
|
|
202
|
+
process.exit(EXIT_CODES.ERROR);
|
|
203
|
+
}
|
|
204
|
+
const baseDir = args.baseDir || process.cwd();
|
|
205
|
+
const startedAt = new Date().toISOString();
|
|
206
|
+
const startTime = Date.now();
|
|
207
|
+
// Parse tags if provided
|
|
208
|
+
const tags = args.tags ? args.tags.split(',').map((t) => t.trim()) : undefined;
|
|
209
|
+
let result;
|
|
210
|
+
let error = null;
|
|
211
|
+
try {
|
|
212
|
+
result = await createMemoryNode(baseDir, {
|
|
213
|
+
title,
|
|
214
|
+
type: args.type,
|
|
215
|
+
wuId: args.wu,
|
|
216
|
+
sessionId: args.session,
|
|
217
|
+
discoveredFrom: args.discoveredFrom,
|
|
218
|
+
tags,
|
|
219
|
+
priority: args.priority,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
catch (err) {
|
|
223
|
+
error = err.message;
|
|
224
|
+
}
|
|
225
|
+
const durationMs = Date.now() - startTime;
|
|
226
|
+
await writeAuditLog(baseDir, {
|
|
227
|
+
tool: TOOL_NAME,
|
|
228
|
+
status: error ? 'failed' : 'success',
|
|
229
|
+
startedAt,
|
|
230
|
+
completedAt: new Date().toISOString(),
|
|
231
|
+
durationMs,
|
|
232
|
+
input: {
|
|
233
|
+
baseDir,
|
|
234
|
+
title,
|
|
235
|
+
type: args.type,
|
|
236
|
+
wuId: args.wu,
|
|
237
|
+
sessionId: args.session,
|
|
238
|
+
discoveredFrom: args.discoveredFrom,
|
|
239
|
+
tags,
|
|
240
|
+
priority: args.priority,
|
|
241
|
+
},
|
|
242
|
+
output: result
|
|
243
|
+
? {
|
|
244
|
+
success: result.success,
|
|
245
|
+
nodeId: result.node?.id,
|
|
246
|
+
wuId: result.node?.wu_id,
|
|
247
|
+
hasRelationship: !!result.relationship,
|
|
248
|
+
}
|
|
249
|
+
: null,
|
|
250
|
+
error: error ? { message: error } : null,
|
|
251
|
+
});
|
|
252
|
+
if (error) {
|
|
253
|
+
console.error(`${LOG_PREFIX} Error: ${error}`);
|
|
254
|
+
process.exit(EXIT_CODES.ERROR);
|
|
255
|
+
}
|
|
256
|
+
if (args.quiet) {
|
|
257
|
+
console.log(result.node.id);
|
|
258
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
259
|
+
}
|
|
260
|
+
printNodeDetails(result);
|
|
261
|
+
}
|
|
262
|
+
main().catch((e) => {
|
|
263
|
+
console.error(`${LOG_PREFIX} ${e.message}`);
|
|
264
|
+
process.exit(EXIT_CODES.ERROR);
|
|
265
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mem-create.js","sourceRoot":"","sources":["../src/mem-create.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E;;GAEG;AACH,MAAM,UAAU,GAAG,cAAc,CAAC;AAElC;;GAEG;AACH,MAAM,SAAS,GAAG,YAAY,CAAC;AAE/B;;GAEG;AACH,MAAM,cAAc,GAAG,gCAAgC,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,oBAAoB;QAC3B,WAAW,EAAE,iDAAiD;KAC/D;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,eAAe;QACtB,WAAW,EAAE,cAAc,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,+FAA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,KAAK,CAAC,CAAC;AACjC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Memory Inbox CLI (WU-1474)
|
|
4
|
+
*
|
|
5
|
+
* Read coordination signals from other agents for real-time awareness
|
|
6
|
+
* of parallel agent progress. Filter by lane, WU, or time range.
|
|
7
|
+
* Supports watch mode for continuous monitoring.
|
|
8
|
+
*
|
|
9
|
+
* Includes audit logging to .beacon/telemetry/tools.ndjson.
|
|
10
|
+
*
|
|
11
|
+
* WU-2202: Added dependency validation before operations to prevent silent
|
|
12
|
+
* failures when node_modules is corrupted or incomplete.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* pnpm mem:inbox [--lane <name>] [--wu <id>] [--since <time>] [--watch]
|
|
16
|
+
*
|
|
17
|
+
* @see {@link tools/lib/mem-signal-core.mjs} - Core logic
|
|
18
|
+
* @see {@link tools/__tests__/mem-inbox.test.mjs} - Tests
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Format signal count for --count flag output
|
|
22
|
+
* WU-2401: Lightweight polling for orchestrators
|
|
23
|
+
*
|
|
24
|
+
* @param {number} count - Number of unread signals
|
|
25
|
+
* @returns {string} Formatted count string
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatCount(count: any): string;
|
|
28
|
+
/**
|
|
29
|
+
* Parse relative time string to Date object
|
|
30
|
+
* WU-1849: Replaced custom regex with ms package
|
|
31
|
+
*
|
|
32
|
+
* @param {string} timeStr - Time string like "1h", "30m", "2d", or ISO date
|
|
33
|
+
* @returns {Date} Parsed date
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseTimeString(timeStr: any): Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mem-inbox.d.ts","sourceRoot":"","sources":["../src/mem-inbox.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;GAiBG;AAoFH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,KAAA,UAEhC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,OAAO,KAAA,QAatC"}
|