@velaro/cli 1.4.120 → 1.4.122

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 (68) hide show
  1. package/README.md +0 -19
  2. package/bin/velaro.js +21 -92
  3. package/lib/avatar-motion.test.js +1 -1
  4. package/lib/avatar-switch.test.js +1 -1
  5. package/lib/commands/agent.js +7 -58
  6. package/lib/commands/ai-config.js +8 -34
  7. package/lib/commands/index.js +18 -14
  8. package/lib/commands/kb.js +4 -94
  9. package/lib/commands/knowledge.js +2 -2
  10. package/lib/commands/ops-groups.js +0 -13
  11. package/lib/commands/safety.js +1 -1
  12. package/lib/commands/salesforce.js +1 -1
  13. package/lib/commands/sap.js +1 -1
  14. package/lib/commands/schedule-adherence.js +1 -1
  15. package/lib/commands/signature.js +39 -3
  16. package/lib/commands/teams.js +1 -1
  17. package/lib/commands/woocommerce.js +1 -1
  18. package/lib/commands/workflow.js +4 -31
  19. package/lib/signature-policy.js +42 -0
  20. package/lib/signature-policy.test.js +28 -2
  21. package/lib/staff-optional.js +10 -0
  22. package/package.json +2 -2
  23. package/lib/cobrowse-settings.js +0 -90
  24. package/lib/cobrowse-settings.test.js +0 -45
  25. package/lib/commands/activity.js +0 -147
  26. package/lib/commands/acuity.js +0 -66
  27. package/lib/commands/ai-federation.js +0 -55
  28. package/lib/commands/ai-models.js +0 -203
  29. package/lib/commands/ai-spend.js +0 -71
  30. package/lib/commands/avatar.js +0 -253
  31. package/lib/commands/bigcommerce.js +0 -50
  32. package/lib/commands/calendly.js +0 -62
  33. package/lib/commands/cobrowse.js +0 -99
  34. package/lib/commands/coupon-grant.js +0 -192
  35. package/lib/commands/diag-groups.js +0 -108
  36. package/lib/commands/diagnostics.js +0 -298
  37. package/lib/commands/email-inbox.js +0 -110
  38. package/lib/commands/entitlement.js +0 -375
  39. package/lib/commands/image-analysis.js +0 -27
  40. package/lib/commands/logs-insights.js +0 -342
  41. package/lib/commands/logs.js +0 -1248
  42. package/lib/commands/migrate.js +0 -379
  43. package/lib/commands/migration-status.js +0 -66
  44. package/lib/commands/ops.js +0 -266
  45. package/lib/commands/parity-staff-tools.js +0 -205
  46. package/lib/commands/pricing.js +0 -132
  47. package/lib/commands/report-speed.js +0 -112
  48. package/lib/commands/scraper.js +0 -38
  49. package/lib/commands/site-provision.js +0 -68
  50. package/lib/commands/sitesync.js +0 -158
  51. package/lib/commands/skill-usage.js +0 -39
  52. package/lib/commands/staff.js +0 -31
  53. package/lib/commands/status-page.js +0 -95
  54. package/lib/commands/status-sla.js +0 -47
  55. package/lib/commands/subscription.js +0 -102
  56. package/lib/commands/support.js +0 -309
  57. package/lib/commands/tour-policy.js +0 -61
  58. package/lib/commands/triage.js +0 -66
  59. package/lib/entitlement-report-packages.test.js +0 -47
  60. package/lib/log-search.js +0 -252
  61. package/lib/log-search.test.js +0 -374
  62. package/lib/logs-insights.test.js +0 -146
  63. package/lib/messaging-routes.test.js +0 -37
  64. package/lib/report-speed.test.js +0 -26
  65. package/lib/siteUser.js +0 -35
  66. package/lib/siteUser.test.js +0 -45
  67. package/lib/skill-usage.test.js +0 -36
  68. package/lib/status-sla.test.js +0 -23
@@ -1,379 +0,0 @@
1
- import { get, post, request } from '../api.js';
2
- import { runCommand } from '../run.js';
3
-
4
- export const migrateCommand = {
5
- command: 'migrate <subcommand>',
6
- describe: 'Migrate customer setups between Velaro platforms',
7
- builder: (yargs) =>
8
- yargs
9
- .command(migrateExportCommand)
10
- .command(migrateLivefluenceCommand)
11
- .command(migrateUrlRulesCommand)
12
- .command(migrateTeamsCommand)
13
- .command(migrateWorkflowsCommand)
14
- .command(migrateRulesCommand)
15
- .command(migrateAdviseCommand)
16
- .demandCommand(1, 'Specify a subcommand: export, livefluence, url-rules, teams, workflows, rules, advise'),
17
- handler: () => {},
18
- };
19
-
20
- // ── export V10 routing rules for a site ───────────────────────────────────────
21
-
22
- const migrateExportCommand = {
23
- command: 'export <v10SiteId>',
24
- describe: 'Export V10 (Livefluence) routing rules for a site and preview V20 migration',
25
- builder: (y) =>
26
- y
27
- .positional('v10SiteId', { type: 'number', describe: 'V10 site ID to export from' })
28
- .option('v20-site-id', { type: 'number', alias: 's', describe: 'V20 site ID for auto-matching teams/AI configs' })
29
- .option('include-non-routing', { type: 'boolean', default: false, describe: 'Also include v10 rules with IsRouting=false (group-assignment rules)' })
30
- .option('path-only-urls', { type: 'boolean', default: false, describe: 'Strip v10 URL terms to their path (demo-page testing only). Default keeps the host, like v10.' }),
31
- handler: runCommand(async (argv) => {
32
- const params = [];
33
- if (argv['v20-site-id']) params.push(`v20SiteId=${argv['v20-site-id']}`);
34
- if (argv['include-non-routing']) params.push('includeNonRouting=true');
35
- if (argv['path-only-urls']) params.push('pathOnlyUrls=true');
36
- const qs = params.length ? `?${params.join('&')}` : '';
37
- const data = await get(`/DatabaseTool/V10Export/${argv.v10SiteId}${qs}`);
38
-
39
- console.log(`\n${'─'.repeat(60)}`);
40
- console.log(` V10 Site ${data.v10SiteId} — Livefluence Routing Rules`);
41
- console.log(` ${data.ruleCount} rule(s) across ${data.groupCount} group(s)`);
42
- console.log(`${'─'.repeat(60)}\n`);
43
-
44
- for (const r of data.rules) {
45
- const resolved = r.canAutoResolve ? '✅' : '⚠';
46
- console.log(` ${resolved} [#${r.priority}] ${r.name}`);
47
- console.log(` Group: ${r.groupName} → ${r.action}`);
48
- console.log(` V10 expression: ${r.v10Expression}`);
49
- if (r.canAutoResolve) {
50
- if (r.suggestedAiConfigName)
51
- console.log(` → AI Config: "${r.suggestedAiConfigName}" (id=${r.suggestedAiConfigId})`);
52
- if (r.suggestedTeamName)
53
- console.log(` → Team: "${r.suggestedTeamName}" (id=${r.suggestedTeamId})`);
54
- } else {
55
- if (r.hasBot)
56
- console.log(` ⚠ No V20 AI config named "${r.groupName}" — create it first`);
57
- else
58
- console.log(` ⚠ No V20 team named "${r.groupName}" — create it first`);
59
- }
60
- console.log('');
61
- }
62
-
63
- console.log(` Auto-resolvable: ${data.autoResolvable}/${data.ruleCount}`);
64
- if (data.needsManualMapping > 0) {
65
- console.log(` Needs manual mapping: ${data.needsManualMapping} rule(s)`);
66
- console.log(` Create matching V20 teams/AI configs by name, then re-run.`);
67
- }
68
-
69
- if (data.v20Teams?.length) {
70
- console.log(`\n V20 Teams on site ${data.v20SiteId}: ${data.v20Teams.map(t => t.name).join(', ')}`);
71
- }
72
- if (data.v20AiConfigs?.length) {
73
- console.log(` V20 AI Configs: ${data.v20AiConfigs.map(a => a.name).join(', ')}`);
74
- }
75
-
76
- console.log(`\n Run: velaro migrate livefluence --v10-site-id ${argv.v10SiteId} --v20-site-id <id> --dry-run`);
77
- console.log(`${'─'.repeat(60)}\n`);
78
- }),
79
- };
80
-
81
- // ── migrate Livefluence → V20 canvas workflows ────────────────────────────────
82
-
83
- const migrateLivefluenceCommand = {
84
- command: 'livefluence',
85
- describe: 'Migrate a Livefluence site\'s routing rules to V20 canvas workflows',
86
- builder: (y) =>
87
- y
88
- .option('v10-site-id', { type: 'number', alias: 'v', describe: 'V10 (Livefluence) site ID', demandOption: true })
89
- .option('v20-site-id', { type: 'number', alias: 's', describe: 'V20 destination site ID', demandOption: true })
90
- .option('dry-run', { type: 'boolean', default: false, describe: 'Preview without creating' })
91
- .option('enable', { type: 'boolean', default: false, describe: 'Enable created workflows immediately (default: disabled; workflows with unconverted v10 terms always stay disabled)' })
92
- .option('include-non-routing', { type: 'boolean', default: false, describe: 'Also migrate v10 rules with IsRouting=false (group-assignment rules)' })
93
- .option('route-bot-groups-to-team', { type: 'boolean', default: false, describe: 'Route to the v20 team named after the v10 group even if the group had a v10 bot' })
94
- .option('path-only-urls', { type: 'boolean', default: false, describe: 'Strip v10 URL terms to their path (demo-page testing only). Default keeps the host, like v10.' })
95
- .option('page-team-availability', { type: 'boolean', default: true, describe: "Launcher availability follows the page's team like v10 (page-load Route to Team workflows + chat window flag). --no-page-team-availability to skip." })
96
- .option('team-map', { type: 'string', describe: 'JSON: [{"v10GroupId":1,"v20TeamId":5},...] override auto-resolution for teams' })
97
- .option('ai-config-map',{ type: 'string', describe: 'JSON: [{"v10GroupId":2,"v20AiConfigId":3},...] override auto-resolution for AI configs' }),
98
- handler: runCommand(async (argv) => {
99
- const v10SiteId = argv['v10-site-id'];
100
- const v20SiteId = argv['v20-site-id'];
101
-
102
- const body = {
103
- v10SiteId,
104
- v20SiteId,
105
- dryRun: argv['dry-run'],
106
- enable: argv.enable,
107
- includeNonRouting: argv['include-non-routing'],
108
- routeBotGroupsToTeam: argv['route-bot-groups-to-team'],
109
- pathOnlyUrls: argv['path-only-urls'],
110
- pageTeamAvailability: argv['page-team-availability'] !== false,
111
- teamMappings: argv['team-map'] ? JSON.parse(argv['team-map']) : [],
112
- aiConfigMappings: argv['ai-config-map'] ? JSON.parse(argv['ai-config-map']) : [],
113
- };
114
-
115
- console.log(`\n${'─'.repeat(60)}`);
116
- console.log(` Livefluence → V20 Canvas Workflow Migration`);
117
- console.log(` V10 site: ${v10SiteId} → V20 site: ${v20SiteId}`);
118
- console.log(` Mode: ${argv['dry-run'] ? 'DRY RUN (no changes)' : 'LIVE'}`);
119
- console.log(`${'─'.repeat(60)}\n`);
120
-
121
- const result = await post('/DatabaseTool/V10Migrate', body);
122
-
123
- if (result.createdItems?.length) {
124
- console.log(` Workflows ${argv['dry-run'] ? '(would create)' : 'created'}:\n`);
125
- for (const item of result.createdItems) {
126
- const id = item.workflowId ? ` [id=${item.workflowId}]` : '';
127
- console.log(` + [#${item.priority}] ${item.ruleName}${id}`);
128
- console.log(` Action: ${item.action}`);
129
- if (item.v2AiConfigId) console.log(` → AI Config id=${item.v2AiConfigId}`);
130
- if (item.v2TeamId) console.log(` → Team id=${item.v2TeamId}`);
131
- if (item.v10Expression) console.log(` V10 expression: ${item.v10Expression}`);
132
- if (item.conditionGroups !== undefined) console.log(` v20 condition groups (OR): ${item.conditionGroups}`);
133
- for (const u of item.unconverted ?? []) console.log(` ⚠ not converted: ${u}`);
134
- console.log('');
135
- }
136
- }
137
-
138
- if (result.skippedItems?.length) {
139
- console.log(` Skipped (unresolvable):\n`);
140
- for (const item of result.skippedItems) {
141
- console.log(` ⚠ ${item.name}: ${item.reason}`);
142
- }
143
- console.log('');
144
- }
145
-
146
- console.log(`${'─'.repeat(60)}`);
147
- console.log(` ${result.message}`);
148
- if (!argv['dry-run'] && result.created > 0) {
149
- console.log(`\n ⚠ All workflows created DISABLED — review conditions in the canvas then enable.`);
150
- console.log(` Country and URL terms are converted; terms marked 'not converted' need manual canvas conditions.`);
151
- }
152
- console.log(`${'─'.repeat(60)}\n`);
153
- }),
154
- };
155
-
156
- // -- seed v20 URL routing rules from a v10 rules JSON file ---------------------
157
-
158
- const migrateUrlRulesCommand = {
159
- command: 'url-rules',
160
- describe: 'Seed v20 use-ai routing rules (path-only "url contains") from a v10 rules JSON file',
161
- builder: (y) =>
162
- y
163
- .option('site', { type: 'number', alias: 's', demandOption: true, describe: 'V20 destination site ID' })
164
- .option('ai-config-id', { type: 'number', alias: 'a', demandOption: true, describe: 'AI config on that site that receives the routed chats' })
165
- .option('file', { type: 'string', alias: 'f', demandOption: true, describe: 'JSON array of {name, urls[]} in v10 priority order' })
166
- .option('dry-run', { type: 'boolean', default: false }),
167
- handler: runCommand(async (argv) => {
168
- const { readFileSync } = await import('fs');
169
- const src = JSON.parse(readFileSync(argv.file, 'utf8'));
170
- const rules = src.map((r, i) => ({ name: r.name, priority: (i + 1) * 10, paths: r.urls || [] }));
171
- const result = await post('/DatabaseTool/V10SeedUrlRules', {
172
- siteId: argv.site, aiConfigId: argv['ai-config-id'], dryRun: argv['dry-run'], rules,
173
- });
174
- for (const i of result.createdItems || []) console.log(` + [${i.priority}] ${i.name} (${i.pathCount} paths)`);
175
- for (const i of result.skippedItems || []) console.log(` - ${i.name}: ${i.reason}`);
176
- console.log(`\n ${result.dryRun ? 'DRY RUN: ' : ''}created ${result.created}, skipped ${result.skipped}`);
177
- }),
178
- };
179
-
180
- // -- copy v10 groups to v20 teams (v10 read-only) ------------------------------
181
-
182
- const migrateTeamsCommand = {
183
- command: 'teams',
184
- describe: 'Copy v10 (Livefluence) groups to v20 teams on a site (v10 is read-only; idempotent by name)',
185
- builder: (y) =>
186
- y
187
- .option('v10-site-id', { type: 'number', alias: 'v', describe: 'V10 (Livefluence) site ID', demandOption: true })
188
- .option('v20-site-id', { type: 'number', alias: 's', describe: 'V20 destination site ID', demandOption: true })
189
- .option('groups', { type: 'string', describe: 'Comma-separated group names to copy (default: every non-deleted v10 group). "Default Group" maps to the site default team.' })
190
- .option('dry-run', { type: 'boolean', default: false, describe: 'Preview without creating' }),
191
- handler: runCommand(async (argv) => {
192
- const body = {
193
- v10SiteId: argv['v10-site-id'],
194
- v20SiteId: argv['v20-site-id'],
195
- dryRun: argv['dry-run'],
196
- groupNames: argv.groups ? argv.groups.split(',').map(g => g.trim()).filter(Boolean) : [],
197
- };
198
- const result = await post('/DatabaseTool/V10CreateTeams', body);
199
- console.log(`\n ${result.dryRun ? 'DRY RUN - ' : ''}v10 site ${body.v10SiteId} -> v20 site ${body.v20SiteId}\n`);
200
- for (const t of result.teams ?? []) {
201
- const members = t.v10Members !== undefined ? ` (v10 members: ${t.v10Members})` : '';
202
- console.log(` ${t.status.padEnd(24)} ${t.name}${t.teamId ? ` [team id=${t.teamId}]` : ''}${members}`);
203
- }
204
- console.log('\n Members are not copied; assign v20 agents to the new teams.\n');
205
- }),
206
- };
207
-
208
- // -- staff, site-targeted workflow + rule ops (superadmin only) ----------------
209
- // Act on ANOTHER v20 site's workflows/Rules after `migrate livefluence` created them disabled.
210
-
211
- const csv = (v) => (v ? String(v).split(',').map(x => x.trim()).filter(Boolean) : []);
212
- const printItems = (result) => {
213
- for (const i of result.items ?? []) console.log(` ${String(i.status).padEnd(13)} [${i.id}] ${i.name ?? ''}${i.reason ? ` -- ${i.reason}` : ''}`);
214
- for (const n of result.notFound ?? []) console.log(` not-found ${n}`);
215
- console.log(`\n ${result.dryRun ? 'DRY RUN: ' : ''}changed ${result.changed}${result.refused !== undefined ? `, refused ${result.refused}` : ''}\n`);
216
- };
217
-
218
- const migrateWorkflowsCommand = {
219
- command: 'workflows <op>',
220
- describe: 'Staff: list / enable / disable / create / re-target workflows on a v20 site',
221
- builder: (y) =>
222
- y
223
- .command({
224
- command: 'list',
225
- describe: 'List a v20 site workflows (id, name, enabled, priority, action, team/AI target)',
226
- builder: (b) => b.option('site', { type: 'number', alias: 's', demandOption: true, describe: 'V20 site ID' }),
227
- handler: runCommand(async (argv) => {
228
- const r = await get(`/DatabaseTool/SiteWorkflows/${argv.site}`);
229
- for (const w of r.workflows ?? []) {
230
- const target = w.teamId ? `team ${w.teamId} ${w.teamName ?? ''}` : w.aiConfigId ? `ai ${w.aiConfigId} ${w.aiConfigName ?? ''}` : '-';
231
- console.log(` [${w.id}] ${w.enabled ? 'ON ' : 'off'} p=${w.priority ?? '-'} ${String(w.action ?? '-').padEnd(12)} ${target.padEnd(28)} groups=${w.conditionGroups} ${w.name}`);
232
- }
233
- console.log(`\n ${r.count} workflow(s) on site ${r.siteId}\n`);
234
- }),
235
- })
236
- .command({
237
- command: 'set-enabled',
238
- describe: 'Enable or disable workflows by ids or names. Enabling refuses partially converted triggers unless --force-partial.',
239
- builder: (b) => b
240
- .option('site', { type: 'number', alias: 's', demandOption: true, describe: 'V20 site ID' })
241
- .option('ids', { type: 'string', describe: 'Comma-separated workflow ids' })
242
- .option('names', { type: 'string', describe: 'Comma-separated workflow names' })
243
- .option('enable', { type: 'boolean', demandOption: true, describe: '--enable to turn on, --no-enable to turn off' })
244
- .option('v10-site-id', { type: 'number', alias: 'v', describe: 'Check each workflow against its same-named v10 rule conversion' })
245
- .option('force-partial', { type: 'boolean', default: false, describe: 'Enable even if the v10 expression was not fully converted' })
246
- .option('dry-run', { type: 'boolean', default: false }),
247
- handler: runCommand(async (argv) => {
248
- const r = await post('/DatabaseTool/SiteWorkflows/SetEnabled', {
249
- siteId: argv.site, workflowIds: csv(argv.ids).map(Number), names: csv(argv.names),
250
- enabled: argv.enable, dryRun: argv['dry-run'], forcePartial: argv['force-partial'], v10SiteId: argv['v10-site-id'] ?? null,
251
- });
252
- printItems(r);
253
- }),
254
- })
255
- .command({
256
- command: 'create',
257
- describe: 'Create a workflow on a site from a nodes-blob JSON file (disabled unless --enable)',
258
- builder: (b) => b
259
- .option('site', { type: 'number', alias: 's', demandOption: true })
260
- .option('name', { type: 'string', alias: 'n', demandOption: true })
261
- .option('file', { type: 'string', alias: 'f', demandOption: true, describe: 'JSON file: the nodes object, e.g. {"1":{"type":"trigger",...},"2":{"type":"action",...}}' })
262
- .option('trigger-type', { type: 'string', default: 'conversation_opened' })
263
- .option('enable', { type: 'boolean', default: false })
264
- .option('dry-run', { type: 'boolean', default: false }),
265
- handler: runCommand(async (argv) => {
266
- const { readFileSync } = await import('fs');
267
- const nodesBlob = JSON.stringify(JSON.parse(readFileSync(argv.file, 'utf8')));
268
- const r = await post('/DatabaseTool/SiteWorkflows/Create', {
269
- siteId: argv.site, name: argv.name, triggerType: argv['trigger-type'], nodesBlob, enabled: argv.enable, dryRun: argv['dry-run'],
270
- });
271
- console.log(`\n ${r.status}${r.workflowId ? ` (workflow id=${r.workflowId})` : ''}\n`);
272
- }),
273
- })
274
- .command({
275
- command: 'set-action',
276
- describe: 'Set a workflow action node to transferToAI {aiConfigId} or routeToTeam {teamId}',
277
- builder: (b) => b
278
- .option('site', { type: 'number', alias: 's', demandOption: true })
279
- .option('workflow-id', { type: 'number', alias: 'w', demandOption: true })
280
- .option('ai-config-id',{ type: 'number', describe: 'Set action to transferToAI with this AI config' })
281
- .option('team-id', { type: 'number', describe: 'Set action to routeToTeam with this team' })
282
- .check((a) => (!!a['ai-config-id'] !== !!a['team-id']) || 'Pass exactly one of --ai-config-id or --team-id')
283
- .option('dry-run', { type: 'boolean', default: false }),
284
- handler: runCommand(async (argv) => {
285
- const r = await post('/DatabaseTool/SiteWorkflows/SetAction', {
286
- siteId: argv.site, workflowId: argv['workflow-id'],
287
- actionType: argv['ai-config-id'] ? 'transferToAI' : 'routeToTeam',
288
- targetId: argv['ai-config-id'] || argv['team-id'], dryRun: argv['dry-run'],
289
- });
290
- console.log(`\n ${r.status} (workflow ${r.workflowId})\n`);
291
- }),
292
- })
293
- .demandCommand(1, 'Specify: list, set-enabled, create, set-action'),
294
- handler: () => {},
295
- };
296
-
297
- const migrateRulesCommand = {
298
- command: 'rules <op>',
299
- describe: 'Staff: list / switch off v20 Rules on a site (e.g. the #1253 use-ai rules) without deleting them',
300
- builder: (y) =>
301
- y
302
- .command({
303
- command: 'list',
304
- describe: 'List a v20 site Rules with enabled state',
305
- builder: (b) => b.option('site', { type: 'number', alias: 's', demandOption: true }),
306
- handler: runCommand(async (argv) => {
307
- const r = await get(`/DatabaseTool/SiteRules/${argv.site}`);
308
- for (const x of r.rules ?? []) console.log(` [${x.id}] ${x.enabled ? 'ON ' : 'off'} p=${x.priority} ${x.trigger} ${x.valueJson ?? ''}`);
309
- console.log(`\n ${r.count} rule(s) on site ${r.siteId}\n`);
310
- }),
311
- })
312
- .command({
313
- command: 'set-enabled',
314
- describe: 'Switch Rules off/on (reversible; a "disabled:" prefix on the trigger). Select by ids or --trigger use-ai.',
315
- builder: (b) => b
316
- .option('site', { type: 'number', alias: 's', demandOption: true })
317
- .option('ids', { type: 'string', describe: 'Comma-separated rule ids' })
318
- .option('trigger', { type: 'string', describe: 'Every rule with this trigger, e.g. use-ai' })
319
- .option('enable', { type: 'boolean', demandOption: true, describe: '--enable to turn on, --no-enable to turn off' })
320
- .option('dry-run', { type: 'boolean', default: false }),
321
- handler: runCommand(async (argv) => {
322
- const r = await post('/DatabaseTool/SiteRules/SetEnabled', {
323
- siteId: argv.site, ruleIds: csv(argv.ids).map(Number), trigger: argv.trigger ?? null, enabled: argv.enable, dryRun: argv['dry-run'],
324
- });
325
- printItems(r);
326
- }),
327
- })
328
- .demandCommand(1, 'Specify: list, set-enabled'),
329
- handler: () => {},
330
- };
331
-
332
- // ── conversion advisor: consolidated v20 design from a v10 site or an intent list ──
333
-
334
- const migrateAdviseCommand = {
335
- command: 'advise',
336
- describe: 'Livefluence conversion advisor: recommend (dry run, default) or build (--apply) a consolidated v20 routing design. Staff only.',
337
- builder: (y) =>
338
- y
339
- .option('v10-site-id', { type: 'number', alias: 'v', describe: 'V10 (Livefluence) site to read (omit when using --intents)' })
340
- .option('v20-site-id', { type: 'number', alias: 's', describe: 'V20 destination site ID', demandOption: true })
341
- .option('intents', { type: 'string', describe: 'JSON array (or @file.json) of intents: [{"intent":"support","paths":["/support"],"device":"any","target":"Service team + troubleshooting AI node"}]' })
342
- .option('apply', { type: 'boolean', default: false, describe: 'Create missing teams and DISABLED workflows (default: dry run + diff)' })
343
- .option('include-non-routing', { type: 'boolean', default: false, describe: 'Also read v10 rules with IsRouting=false (group-assignment rules)' }),
344
- handler: runCommand(async (argv) => {
345
- let intents = null;
346
- if (argv.intents) {
347
- const raw = argv.intents.startsWith('@')
348
- ? (await import('node:fs')).readFileSync(argv.intents.slice(1), 'utf8')
349
- : argv.intents;
350
- intents = JSON.parse(raw);
351
- }
352
- if (!intents && !argv['v10-site-id']) throw new Error('Give -v <v10 site> or --intents.');
353
-
354
- const result = await post('/DatabaseTool/ConversionAdvisor', {
355
- v10SiteId: intents ? null : argv['v10-site-id'],
356
- v20SiteId: argv['v20-site-id'],
357
- apply: argv.apply,
358
- includeNonRouting: argv['include-non-routing'],
359
- intents,
360
- });
361
-
362
- console.log(`\n${'─'.repeat(60)}`);
363
- console.log(` Conversion advisor (${result.source}) -> V20 site ${result.v20SiteId} ${result.dryRun ? 'DRY RUN' : 'APPLIED (all workflows disabled)'}`);
364
- if (result.v10RuleCount) console.log(` ${result.v10RuleCount} v10 rule(s) -> ${result.consolidatedWorkflows} workflow(s)`);
365
- console.log(`${'─'.repeat(60)}\n`);
366
- for (const t of result.teams ?? [])
367
- console.log(` team ${t.status.padEnd(8)} ${t.name}${t.v10Members ? ` (${t.v10Members} v10 members, assign v20 agents by hand)` : ''}`);
368
- console.log('');
369
- for (const w of result.workflows ?? []) {
370
- console.log(` [${w.status}] #${w.priority} ${w.name} mode=${w.mode}${w.device !== 'any' ? ` device=${w.device}` : ''}`);
371
- console.log(` team: ${w.teamName ?? '-'} AI node: ${w.aiNodeName ?? '-'} condition groups (OR): ${w.conditionGroups}`);
372
- if (w.statusReason) console.log(` ${w.statusReason}`);
373
- for (const x of w.warnings ?? []) console.log(` ! ${x}`);
374
- }
375
- if (result.existingNotInPlan?.length) console.log(`\n Already on the v20 site, not in this plan: ${result.existingNotInPlan.join(', ')}`);
376
- for (const n of result.notes ?? []) console.log(` note: ${n}`);
377
- console.log(`\n ${result.message}\n`);
378
- }),
379
- };
@@ -1,66 +0,0 @@
1
- import { get } from '../api.js';
2
- import { runCommand } from '../run.js';
3
-
4
- // Reads AdminStartupDiagnostics (SuperAdmin/StartupDiagnostics) — the dependency-free canary
5
- // table StartupMigrationRunner.WriteCanary writes on every startup, one row per DbContext per
6
- // restart. Built 2026-08-23: no CLI/MCP/REST surface previously existed to read this table, so
7
- // every prior round of the MessagingContext production migration investigation
8
- // (docs/architecture/postmortems.md, 2026-07-14 through 2026-08-19) had to guess at the real
9
- // Database.Migrate()/SchemaDriftChecker outcome instead of just reading it directly.
10
- export const migrationStatusCommand = {
11
- command: 'migration-status [contextLabel]',
12
- describe: 'Show recent StartupMigrationRunner/SchemaDriftChecker outcomes (AdminStartupDiagnostics canary table)',
13
- builder: (y) =>
14
- y
15
- .positional('contextLabel', { type: 'string', describe: 'Filter to one DbContext label, e.g. Messaging, Marketing, Billing' })
16
- .option('count', { type: 'number', alias: 'n', default: 20, describe: 'Max rows to show (1-200)' }),
17
- handler: runCommand(async (argv) => {
18
- const qs = new URLSearchParams();
19
- if (argv.contextLabel) qs.set('contextLabel', argv.contextLabel);
20
- if (argv.count) qs.set('count', String(argv.count));
21
-
22
- const data = await get(`/SuperAdmin/StartupDiagnostics?${qs.toString()}`);
23
-
24
- if (data.note) {
25
- console.log(`\n ${data.note}\n`);
26
- return;
27
- }
28
-
29
- if (!data.rows?.length) {
30
- console.log(`\n No AdminStartupDiagnostics rows${argv.contextLabel ? ` for '${argv.contextLabel}'` : ''}.\n`);
31
- return;
32
- }
33
-
34
- console.log(`\n${'─'.repeat(70)}`);
35
- console.log(` Startup Migration Diagnostics${argv.contextLabel ? ` — ${argv.contextLabel}` : ''}`);
36
- console.log(`${'─'.repeat(70)}\n`);
37
-
38
- for (const row of data.rows) {
39
- const outcomeIcon =
40
- row.outcome === 'Success' ? '✅' :
41
- row.outcome === 'PendingAfterMigrate_HistoryOnly' ? '🟡' :
42
- row.outcome?.startsWith('PendingAfterMigrate_RealDrift') ? '🔴' :
43
- row.outcome === 'PendingAfterMigrate_Unchecked' ? '⚠️' :
44
- row.outcome === 'MigrateThrew' || row.outcome === 'DriftCheckThrew' ? '❌' :
45
- '·';
46
-
47
- console.log(` ${outcomeIcon} [${row.contextLabel}] ${row.outcome} — ${new Date(row.createdAtUtc).toISOString()}`);
48
- if (row.pendingCount > 0) {
49
- console.log(` Pending (${row.pendingCount}): ${row.pendingMigrationIds}`);
50
- }
51
- if (row.exceptionType) {
52
- console.log(` Exception: ${row.exceptionType}`);
53
- console.log(` Detail: ${(row.exceptionDetail || '').slice(0, 400)}${(row.exceptionDetail || '').length > 400 ? '…' : ''}`);
54
- }
55
- console.log('');
56
- }
57
-
58
- console.log(`${'─'.repeat(70)}`);
59
- console.log(' Outcomes: Success | PendingAfterMigrate_HistoryOnly (safe, Degraded) |');
60
- console.log(' PendingAfterMigrate_RealDrift* (real missing schema, Critical) |');
61
- console.log(' PendingAfterMigrate_Unchecked (drift check never ran, fail-safe Critical) |');
62
- console.log(' MigrateThrew (Database.Migrate() itself threw) |');
63
- console.log(' DriftCheckThrew (SchemaDriftChecker itself threw after a successful Migrate())');
64
- console.log(`${'─'.repeat(70)}\n`);
65
- }),
66
- };