@jonit-dev/night-watch-cli 1.1.5 → 1.3.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.
Files changed (96) hide show
  1. package/README.md +1 -0
  2. package/dist/cli.js +3 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/dashboard/tab-actions.d.ts +10 -0
  5. package/dist/commands/dashboard/tab-actions.d.ts.map +1 -0
  6. package/dist/commands/dashboard/tab-actions.js +245 -0
  7. package/dist/commands/dashboard/tab-actions.js.map +1 -0
  8. package/dist/commands/dashboard/tab-config.d.ts +21 -0
  9. package/dist/commands/dashboard/tab-config.d.ts.map +1 -0
  10. package/dist/commands/dashboard/tab-config.js +821 -0
  11. package/dist/commands/dashboard/tab-config.js.map +1 -0
  12. package/dist/commands/dashboard/tab-logs.d.ts +10 -0
  13. package/dist/commands/dashboard/tab-logs.d.ts.map +1 -0
  14. package/dist/commands/dashboard/tab-logs.js +178 -0
  15. package/dist/commands/dashboard/tab-logs.js.map +1 -0
  16. package/dist/commands/dashboard/tab-schedules.d.ts +21 -0
  17. package/dist/commands/dashboard/tab-schedules.d.ts.map +1 -0
  18. package/dist/commands/dashboard/tab-schedules.js +304 -0
  19. package/dist/commands/dashboard/tab-schedules.js.map +1 -0
  20. package/dist/commands/dashboard/tab-status.d.ts +32 -0
  21. package/dist/commands/dashboard/tab-status.d.ts.map +1 -0
  22. package/dist/commands/dashboard/tab-status.js +416 -0
  23. package/dist/commands/dashboard/tab-status.js.map +1 -0
  24. package/dist/commands/dashboard/types.d.ts +43 -0
  25. package/dist/commands/dashboard/types.d.ts.map +1 -0
  26. package/dist/commands/dashboard/types.js +5 -0
  27. package/dist/commands/dashboard/types.js.map +1 -0
  28. package/dist/commands/dashboard.d.ts +11 -0
  29. package/dist/commands/dashboard.d.ts.map +1 -0
  30. package/dist/commands/dashboard.js +239 -0
  31. package/dist/commands/dashboard.js.map +1 -0
  32. package/dist/commands/doctor.d.ts +2 -2
  33. package/dist/commands/doctor.d.ts.map +1 -1
  34. package/dist/commands/doctor.js +1 -1
  35. package/dist/commands/doctor.js.map +1 -1
  36. package/dist/commands/init.d.ts.map +1 -1
  37. package/dist/commands/init.js +8 -8
  38. package/dist/commands/init.js.map +1 -1
  39. package/dist/commands/install.d.ts +17 -1
  40. package/dist/commands/install.d.ts.map +1 -1
  41. package/dist/commands/install.js +56 -2
  42. package/dist/commands/install.js.map +1 -1
  43. package/dist/commands/logs.d.ts +1 -1
  44. package/dist/commands/logs.d.ts.map +1 -1
  45. package/dist/commands/logs.js +1 -1
  46. package/dist/commands/logs.js.map +1 -1
  47. package/dist/commands/prd.d.ts +1 -1
  48. package/dist/commands/prd.d.ts.map +1 -1
  49. package/dist/commands/prd.js +2 -2
  50. package/dist/commands/prd.js.map +1 -1
  51. package/dist/commands/review.d.ts +3 -3
  52. package/dist/commands/review.d.ts.map +1 -1
  53. package/dist/commands/review.js +2 -2
  54. package/dist/commands/review.js.map +1 -1
  55. package/dist/commands/run.d.ts +5 -5
  56. package/dist/commands/run.d.ts.map +1 -1
  57. package/dist/commands/run.js +7 -3
  58. package/dist/commands/run.js.map +1 -1
  59. package/dist/commands/status.d.ts +1 -1
  60. package/dist/commands/status.d.ts.map +1 -1
  61. package/dist/commands/status.js +20 -202
  62. package/dist/commands/status.js.map +1 -1
  63. package/dist/commands/uninstall.d.ts +13 -1
  64. package/dist/commands/uninstall.d.ts.map +1 -1
  65. package/dist/commands/uninstall.js +46 -2
  66. package/dist/commands/uninstall.js.map +1 -1
  67. package/dist/config.d.ts.map +1 -1
  68. package/dist/config.js +9 -1
  69. package/dist/config.js.map +1 -1
  70. package/dist/constants.d.ts +3 -2
  71. package/dist/constants.d.ts.map +1 -1
  72. package/dist/constants.js +2 -0
  73. package/dist/constants.js.map +1 -1
  74. package/dist/templates/prd-template.d.ts +2 -2
  75. package/dist/templates/prd-template.d.ts.map +1 -1
  76. package/dist/templates/prd-template.js.map +1 -1
  77. package/dist/types.d.ts +6 -4
  78. package/dist/types.d.ts.map +1 -1
  79. package/dist/utils/config-writer.d.ts +16 -0
  80. package/dist/utils/config-writer.d.ts.map +1 -0
  81. package/dist/utils/config-writer.js +45 -0
  82. package/dist/utils/config-writer.js.map +1 -0
  83. package/dist/utils/crontab.js +1 -1
  84. package/dist/utils/crontab.js.map +1 -1
  85. package/dist/utils/github.d.ts +3 -3
  86. package/dist/utils/github.d.ts.map +1 -1
  87. package/dist/utils/notify.d.ts +8 -8
  88. package/dist/utils/notify.d.ts.map +1 -1
  89. package/dist/utils/notify.js +1 -1
  90. package/dist/utils/notify.js.map +1 -1
  91. package/dist/utils/status-data.d.ts +128 -0
  92. package/dist/utils/status-data.d.ts.map +1 -0
  93. package/dist/utils/status-data.js +403 -0
  94. package/dist/utils/status-data.js.map +1 -0
  95. package/package.json +11 -2
  96. package/scripts/night-watch-helpers.sh +20 -0
@@ -0,0 +1,821 @@
1
+ /**
2
+ * Config tab for the dashboard TUI
3
+ * Allows viewing and editing all configuration fields
4
+ */
5
+ import blessed from "blessed";
6
+ import { VALID_PROVIDERS } from "../../constants.js";
7
+ import { saveConfig } from "../../utils/config-writer.js";
8
+ import { performUninstall } from "../uninstall.js";
9
+ import { performInstall } from "../install.js";
10
+ const SENSITIVE_PATTERNS = /TOKEN|KEY|SECRET|PASSWORD/i;
11
+ const WEBHOOK_TYPES = ["slack", "discord", "telegram"];
12
+ const NOTIFICATION_EVENTS = [
13
+ "run_succeeded", "run_failed", "run_timeout", "review_completed",
14
+ ];
15
+ /**
16
+ * GLM-5 default provider environment configuration
17
+ */
18
+ const GLM5_DEFAULTS = {
19
+ ANTHROPIC_BASE_URL: "https://api.z.ai/api/anthropic",
20
+ API_TIMEOUT_MS: "3000000",
21
+ ANTHROPIC_DEFAULT_OPUS_MODEL: "glm-5",
22
+ ANTHROPIC_DEFAULT_SONNET_MODEL: "glm-5",
23
+ };
24
+ export const CONFIG_FIELDS = [
25
+ { key: "provider", label: "Provider", type: "enum", options: [...VALID_PROVIDERS] },
26
+ { key: "reviewerEnabled", label: "Reviewer Enabled", type: "boolean" },
27
+ { key: "defaultBranch", label: "Default Branch", type: "string" },
28
+ { key: "prdDir", label: "PRD Directory", type: "string" },
29
+ { key: "branchPrefix", label: "Branch Prefix", type: "string" },
30
+ { key: "branchPatterns", label: "Branch Patterns", type: "string[]" },
31
+ { key: "cronSchedule", label: "Executor Schedule", type: "string" },
32
+ { key: "reviewerSchedule", label: "Reviewer Schedule", type: "string" },
33
+ {
34
+ key: "maxRuntime", label: "Max Runtime (s)", type: "number",
35
+ validate: (v) => { const n = parseInt(v, 10); return isNaN(n) || n <= 0 ? "Must be a positive integer" : null; },
36
+ },
37
+ {
38
+ key: "reviewerMaxRuntime", label: "Reviewer Max Runtime (s)", type: "number",
39
+ validate: (v) => { const n = parseInt(v, 10); return isNaN(n) || n <= 0 ? "Must be a positive integer" : null; },
40
+ },
41
+ {
42
+ key: "minReviewScore", label: "Min Review Score", type: "number",
43
+ validate: (v) => { const n = parseInt(v, 10); return isNaN(n) || n < 0 || n > 100 ? "Must be 0-100" : null; },
44
+ },
45
+ {
46
+ key: "maxLogSize", label: "Max Log Size (bytes)", type: "number",
47
+ validate: (v) => { const n = parseInt(v, 10); return isNaN(n) || n <= 0 ? "Must be a positive integer" : null; },
48
+ },
49
+ { key: "providerEnv", label: "Provider Env Vars", type: "keyvalue" },
50
+ { key: "notifications", label: "Notifications", type: "webhooks" },
51
+ ];
52
+ function maskValue(key, value) {
53
+ if (SENSITIVE_PATTERNS.test(key) && value.length > 6) {
54
+ return value.slice(0, 3) + "***" + value.slice(-3);
55
+ }
56
+ return value;
57
+ }
58
+ function formatFieldValue(config, field) {
59
+ const value = config[field.key];
60
+ if (field.type === "string[]" && Array.isArray(value)) {
61
+ return value.join(", ");
62
+ }
63
+ if (field.type === "keyvalue") {
64
+ const env = value;
65
+ const count = Object.keys(env).length;
66
+ return count > 0 ? `${count} variable(s) set` : "(none)";
67
+ }
68
+ if (field.type === "webhooks") {
69
+ const notif = value;
70
+ return notif.webhooks.length > 0 ? `${notif.webhooks.length} webhook(s)` : "(none)";
71
+ }
72
+ return String(value);
73
+ }
74
+ /**
75
+ * Create the Config editor tab
76
+ */
77
+ export function createConfigTab() {
78
+ const container = blessed.box({
79
+ top: 0,
80
+ left: 0,
81
+ width: "100%",
82
+ height: "100%",
83
+ hidden: true,
84
+ });
85
+ const configList = blessed.list({
86
+ top: 0,
87
+ left: 0,
88
+ width: "100%",
89
+ height: "100%-3",
90
+ border: { type: "line" },
91
+ label: "[ Configuration ]",
92
+ tags: true,
93
+ scrollable: true,
94
+ alwaysScroll: true,
95
+ scrollbar: { style: { bg: "blue" } },
96
+ style: {
97
+ border: { fg: "cyan" },
98
+ selected: { bg: "blue", fg: "white" },
99
+ item: { fg: "white" },
100
+ },
101
+ keys: true,
102
+ vi: false,
103
+ mouse: false,
104
+ interactive: true,
105
+ });
106
+ const statusBar = blessed.box({
107
+ bottom: 0,
108
+ left: 0,
109
+ width: "100%",
110
+ height: 3,
111
+ border: { type: "line" },
112
+ tags: true,
113
+ style: { border: { fg: "white" } },
114
+ content: "",
115
+ });
116
+ container.append(configList);
117
+ container.append(statusBar);
118
+ const pendingChanges = {};
119
+ let currentConfig = null;
120
+ function buildListItems(config) {
121
+ return CONFIG_FIELDS.map((field) => {
122
+ const hasChange = field.key in pendingChanges;
123
+ const value = hasChange
124
+ ? formatFieldValue({ ...config, ...pendingChanges }, field)
125
+ : formatFieldValue(config, field);
126
+ const marker = hasChange ? " {yellow-fg}*{/yellow-fg}" : "";
127
+ const editHint = field.type === "keyvalue" || field.type === "webhooks" ? " {#888888-fg}(Enter to manage){/#888888-fg}" : "";
128
+ return ` ${field.label}: ${value}${marker}${editHint}`;
129
+ });
130
+ }
131
+ function updateStatusBar() {
132
+ const changeCount = Object.keys(pendingChanges).length;
133
+ if (changeCount > 0) {
134
+ statusBar.setContent(` {yellow-fg}${changeCount} unsaved change(s){/yellow-fg} | s:Save & Apply u:Undo All`);
135
+ }
136
+ else {
137
+ statusBar.setContent(" No pending changes");
138
+ }
139
+ }
140
+ function refreshList(config) {
141
+ configList.setItems(buildListItems(config));
142
+ updateStatusBar();
143
+ }
144
+ // ── Key-Value Editor (providerEnv) ──────────────────────────────────────
145
+ function showKeyValueEditor(ctx, config) {
146
+ const currentEnv = {
147
+ ...(config.providerEnv || {}),
148
+ ...(pendingChanges.providerEnv || {}),
149
+ };
150
+ // If pendingChanges has providerEnv, use it entirely; otherwise merge from config
151
+ const editableEnv = pendingChanges.providerEnv
152
+ ? { ...pendingChanges.providerEnv }
153
+ : { ...currentEnv };
154
+ function buildItems() {
155
+ const entries = Object.entries(editableEnv);
156
+ if (entries.length === 0)
157
+ return [" (no variables set)"];
158
+ return entries.map(([k, v]) => ` ${k} = ${maskValue(k, v)}`);
159
+ }
160
+ const kvList = blessed.list({
161
+ top: "center",
162
+ left: "center",
163
+ width: "70%",
164
+ height: Math.min(Object.keys(editableEnv).length + 4, 20),
165
+ border: { type: "line" },
166
+ label: "[ Provider Env Vars | a:Add Enter:Edit d:Delete Esc:Done ]",
167
+ tags: true,
168
+ style: {
169
+ border: { fg: "cyan" },
170
+ selected: { bg: "blue", fg: "white" },
171
+ item: { fg: "white" },
172
+ },
173
+ keys: true,
174
+ vi: false,
175
+ interactive: true,
176
+ });
177
+ kvList.setItems(buildItems());
178
+ ctx.setEditing(true);
179
+ ctx.screen.append(kvList);
180
+ kvList.focus();
181
+ ctx.screen.render();
182
+ function refreshKvList() {
183
+ kvList.setItems(buildItems());
184
+ kvList.height = Math.min(Object.keys(editableEnv).length + 4, 20);
185
+ ctx.screen.render();
186
+ }
187
+ function promptTextbox(label, initialValue, cb) {
188
+ const input = blessed.textbox({
189
+ top: "center",
190
+ left: "center",
191
+ width: "50%",
192
+ height: 3,
193
+ border: { type: "line" },
194
+ label: `[ ${label} ]`,
195
+ tags: true,
196
+ style: { border: { fg: "yellow" }, fg: "white" },
197
+ inputOnFocus: true,
198
+ });
199
+ ctx.screen.append(input);
200
+ input.setValue(initialValue);
201
+ input.focus();
202
+ ctx.screen.render();
203
+ input.on("submit", (value) => {
204
+ input.destroy();
205
+ cb(value.trim());
206
+ });
207
+ input.on("cancel", () => {
208
+ input.destroy();
209
+ cb(null);
210
+ });
211
+ }
212
+ kvList.key(["a"], () => {
213
+ promptTextbox("Variable Name", "", (key) => {
214
+ if (!key) {
215
+ kvList.focus();
216
+ ctx.screen.render();
217
+ return;
218
+ }
219
+ promptTextbox(`Value for ${key}`, "", (value) => {
220
+ if (value !== null) {
221
+ editableEnv[key] = value;
222
+ pendingChanges.providerEnv = { ...editableEnv };
223
+ refreshKvList();
224
+ }
225
+ kvList.focus();
226
+ ctx.screen.render();
227
+ });
228
+ });
229
+ });
230
+ kvList.key(["enter"], () => {
231
+ const keys = Object.keys(editableEnv);
232
+ if (keys.length === 0)
233
+ return;
234
+ const idx = kvList.selected;
235
+ if (idx < 0 || idx >= keys.length)
236
+ return;
237
+ const selectedKey = keys[idx];
238
+ promptTextbox(`Edit ${selectedKey}`, editableEnv[selectedKey], (value) => {
239
+ if (value !== null) {
240
+ editableEnv[selectedKey] = value;
241
+ pendingChanges.providerEnv = { ...editableEnv };
242
+ refreshKvList();
243
+ }
244
+ kvList.focus();
245
+ ctx.screen.render();
246
+ });
247
+ });
248
+ kvList.key(["d"], () => {
249
+ const keys = Object.keys(editableEnv);
250
+ if (keys.length === 0)
251
+ return;
252
+ const idx = kvList.selected;
253
+ if (idx < 0 || idx >= keys.length)
254
+ return;
255
+ const selectedKey = keys[idx];
256
+ delete editableEnv[selectedKey];
257
+ pendingChanges.providerEnv = { ...editableEnv };
258
+ refreshKvList();
259
+ });
260
+ kvList.key(["escape"], () => {
261
+ kvList.destroy();
262
+ ctx.setEditing(false);
263
+ if (currentConfig)
264
+ refreshList(currentConfig);
265
+ configList.focus();
266
+ ctx.screen.render();
267
+ });
268
+ }
269
+ // ── Webhook Editor (notifications) ──────────────────────────────────────
270
+ function showWebhookEditor(ctx, config) {
271
+ const currentNotif = pendingChanges.notifications
272
+ ? pendingChanges.notifications
273
+ : config.notifications;
274
+ const editableWebhooks = currentNotif.webhooks.map((w) => ({ ...w, events: [...w.events] }));
275
+ function buildItems() {
276
+ if (editableWebhooks.length === 0)
277
+ return [" (no webhooks configured)"];
278
+ return editableWebhooks.map((w) => {
279
+ const identifier = w.type === "telegram"
280
+ ? `token:${maskValue("TOKEN", w.botToken || "")}`
281
+ : (w.url ? maskValue("URL", w.url) : "no url");
282
+ return ` [${w.type}] ${identifier} events: ${w.events.length}`;
283
+ });
284
+ }
285
+ const whList = blessed.list({
286
+ top: "center",
287
+ left: "center",
288
+ width: "70%",
289
+ height: Math.min(editableWebhooks.length + 4, 20),
290
+ border: { type: "line" },
291
+ label: "[ Webhooks | a:Add Enter:Edit d:Delete Esc:Done ]",
292
+ tags: true,
293
+ style: {
294
+ border: { fg: "cyan" },
295
+ selected: { bg: "blue", fg: "white" },
296
+ item: { fg: "white" },
297
+ },
298
+ keys: true,
299
+ vi: false,
300
+ interactive: true,
301
+ });
302
+ whList.setItems(buildItems());
303
+ ctx.setEditing(true);
304
+ ctx.screen.append(whList);
305
+ whList.focus();
306
+ ctx.screen.render();
307
+ function refreshWhList() {
308
+ whList.setItems(buildItems());
309
+ whList.height = Math.min(editableWebhooks.length + 4, 20);
310
+ ctx.screen.render();
311
+ }
312
+ function stageWebhookChanges() {
313
+ pendingChanges.notifications = { webhooks: editableWebhooks.map((w) => ({ ...w, events: [...w.events] })) };
314
+ }
315
+ function promptTextbox(label, initialValue, cb) {
316
+ const input = blessed.textbox({
317
+ top: "center",
318
+ left: "center",
319
+ width: "50%",
320
+ height: 3,
321
+ border: { type: "line" },
322
+ label: `[ ${label} ]`,
323
+ tags: true,
324
+ style: { border: { fg: "yellow" }, fg: "white" },
325
+ inputOnFocus: true,
326
+ });
327
+ ctx.screen.append(input);
328
+ input.setValue(initialValue);
329
+ input.focus();
330
+ ctx.screen.render();
331
+ input.on("submit", (value) => { input.destroy(); cb(value.trim()); });
332
+ input.on("cancel", () => { input.destroy(); cb(null); });
333
+ }
334
+ function selectType(cb) {
335
+ const typeList = blessed.list({
336
+ top: "center",
337
+ left: "center",
338
+ width: 30,
339
+ height: WEBHOOK_TYPES.length + 2,
340
+ border: { type: "line" },
341
+ label: "[ Webhook Type ]",
342
+ tags: true,
343
+ style: { border: { fg: "yellow" }, selected: { bg: "blue", fg: "white" }, item: { fg: "white" } },
344
+ keys: true,
345
+ vi: false,
346
+ interactive: true,
347
+ });
348
+ typeList.setItems(WEBHOOK_TYPES);
349
+ ctx.screen.append(typeList);
350
+ typeList.focus();
351
+ ctx.screen.render();
352
+ typeList.on("select", (_item, index) => {
353
+ typeList.destroy();
354
+ cb(WEBHOOK_TYPES[index]);
355
+ });
356
+ typeList.key(["escape"], () => { typeList.destroy(); cb(null); });
357
+ }
358
+ function selectEvents(current, cb) {
359
+ const selected = new Set(current);
360
+ const evList = blessed.list({
361
+ top: "center",
362
+ left: "center",
363
+ width: 40,
364
+ height: NOTIFICATION_EVENTS.length + 3,
365
+ border: { type: "line" },
366
+ label: "[ Events | Space:Toggle Enter:Done ]",
367
+ tags: true,
368
+ style: { border: { fg: "yellow" }, selected: { bg: "blue", fg: "white" }, item: { fg: "white" } },
369
+ keys: true,
370
+ vi: false,
371
+ interactive: true,
372
+ });
373
+ function renderEvents() {
374
+ evList.setItems(NOTIFICATION_EVENTS.map((e) => ` ${selected.has(e) ? "[x]" : "[ ]"} ${e}`));
375
+ }
376
+ renderEvents();
377
+ ctx.screen.append(evList);
378
+ evList.focus();
379
+ ctx.screen.render();
380
+ evList.key(["space"], () => {
381
+ const idx = evList.selected;
382
+ if (idx >= 0 && idx < NOTIFICATION_EVENTS.length) {
383
+ const ev = NOTIFICATION_EVENTS[idx];
384
+ if (selected.has(ev))
385
+ selected.delete(ev);
386
+ else
387
+ selected.add(ev);
388
+ renderEvents();
389
+ evList.select(idx);
390
+ ctx.screen.render();
391
+ }
392
+ });
393
+ evList.key(["enter"], () => {
394
+ evList.destroy();
395
+ cb([...selected]);
396
+ });
397
+ evList.key(["escape"], () => { evList.destroy(); cb(null); });
398
+ }
399
+ function addWebhookWizard() {
400
+ selectType((type) => {
401
+ if (!type) {
402
+ whList.focus();
403
+ ctx.screen.render();
404
+ return;
405
+ }
406
+ const webhook = { type, events: [...NOTIFICATION_EVENTS] };
407
+ const askCredentials = (done) => {
408
+ if (type === "telegram") {
409
+ promptTextbox("Bot Token", "", (botToken) => {
410
+ if (botToken === null) {
411
+ done(false);
412
+ return;
413
+ }
414
+ webhook.botToken = botToken;
415
+ promptTextbox("Chat ID", "", (chatId) => {
416
+ if (chatId === null) {
417
+ done(false);
418
+ return;
419
+ }
420
+ webhook.chatId = chatId;
421
+ done(true);
422
+ });
423
+ });
424
+ }
425
+ else {
426
+ promptTextbox("Webhook URL", "", (url) => {
427
+ if (url === null) {
428
+ done(false);
429
+ return;
430
+ }
431
+ webhook.url = url;
432
+ done(true);
433
+ });
434
+ }
435
+ };
436
+ askCredentials((ok) => {
437
+ if (!ok) {
438
+ whList.focus();
439
+ ctx.screen.render();
440
+ return;
441
+ }
442
+ selectEvents(webhook.events, (events) => {
443
+ if (events === null) {
444
+ whList.focus();
445
+ ctx.screen.render();
446
+ return;
447
+ }
448
+ webhook.events = events;
449
+ editableWebhooks.push(webhook);
450
+ stageWebhookChanges();
451
+ refreshWhList();
452
+ whList.focus();
453
+ ctx.screen.render();
454
+ });
455
+ });
456
+ });
457
+ }
458
+ function editWebhook(idx) {
459
+ const webhook = editableWebhooks[idx];
460
+ selectType((type) => {
461
+ if (type === null) {
462
+ whList.focus();
463
+ ctx.screen.render();
464
+ return;
465
+ }
466
+ webhook.type = type;
467
+ const askCredentials = (done) => {
468
+ if (type === "telegram") {
469
+ promptTextbox("Bot Token", webhook.botToken || "", (botToken) => {
470
+ if (botToken === null) {
471
+ done(false);
472
+ return;
473
+ }
474
+ webhook.botToken = botToken;
475
+ webhook.url = undefined;
476
+ promptTextbox("Chat ID", webhook.chatId || "", (chatId) => {
477
+ if (chatId === null) {
478
+ done(false);
479
+ return;
480
+ }
481
+ webhook.chatId = chatId;
482
+ done(true);
483
+ });
484
+ });
485
+ }
486
+ else {
487
+ promptTextbox("Webhook URL", webhook.url || "", (url) => {
488
+ if (url === null) {
489
+ done(false);
490
+ return;
491
+ }
492
+ webhook.url = url;
493
+ webhook.botToken = undefined;
494
+ webhook.chatId = undefined;
495
+ done(true);
496
+ });
497
+ }
498
+ };
499
+ askCredentials((ok) => {
500
+ if (!ok) {
501
+ whList.focus();
502
+ ctx.screen.render();
503
+ return;
504
+ }
505
+ selectEvents(webhook.events, (events) => {
506
+ if (events === null) {
507
+ whList.focus();
508
+ ctx.screen.render();
509
+ return;
510
+ }
511
+ webhook.events = events;
512
+ stageWebhookChanges();
513
+ refreshWhList();
514
+ whList.focus();
515
+ ctx.screen.render();
516
+ });
517
+ });
518
+ });
519
+ }
520
+ whList.key(["a"], () => addWebhookWizard());
521
+ whList.key(["enter"], () => {
522
+ if (editableWebhooks.length === 0)
523
+ return;
524
+ const idx = whList.selected;
525
+ if (idx >= 0 && idx < editableWebhooks.length) {
526
+ editWebhook(idx);
527
+ }
528
+ });
529
+ whList.key(["d"], () => {
530
+ if (editableWebhooks.length === 0)
531
+ return;
532
+ const idx = whList.selected;
533
+ if (idx >= 0 && idx < editableWebhooks.length) {
534
+ editableWebhooks.splice(idx, 1);
535
+ stageWebhookChanges();
536
+ refreshWhList();
537
+ }
538
+ });
539
+ whList.key(["escape"], () => {
540
+ whList.destroy();
541
+ ctx.setEditing(false);
542
+ if (currentConfig)
543
+ refreshList(currentConfig);
544
+ configList.focus();
545
+ ctx.screen.render();
546
+ });
547
+ }
548
+ // ── GLM-5 Quick Setup ──────────────────────────────────────────────────
549
+ function showGlm5Setup(ctx) {
550
+ const inputBox = blessed.textbox({
551
+ top: "center",
552
+ left: "center",
553
+ width: "60%",
554
+ height: 3,
555
+ border: { type: "line" },
556
+ label: "[ GLM-5 Quick Setup: Enter API Key ]",
557
+ tags: true,
558
+ style: { border: { fg: "cyan" }, fg: "white" },
559
+ inputOnFocus: true,
560
+ });
561
+ ctx.setEditing(true);
562
+ ctx.screen.append(inputBox);
563
+ inputBox.setValue("");
564
+ inputBox.focus();
565
+ ctx.screen.render();
566
+ inputBox.on("submit", (value) => {
567
+ const apiKey = value.trim();
568
+ inputBox.destroy();
569
+ ctx.setEditing(false);
570
+ if (!apiKey) {
571
+ ctx.showMessage("No API key provided", "error");
572
+ configList.focus();
573
+ ctx.screen.render();
574
+ return;
575
+ }
576
+ pendingChanges.providerEnv = {
577
+ ANTHROPIC_AUTH_TOKEN: apiKey,
578
+ ...GLM5_DEFAULTS,
579
+ };
580
+ ctx.showMessage("GLM-5 configured. Press s to save.", "success");
581
+ if (currentConfig)
582
+ refreshList(currentConfig);
583
+ configList.focus();
584
+ ctx.screen.render();
585
+ });
586
+ inputBox.on("cancel", () => {
587
+ inputBox.destroy();
588
+ ctx.setEditing(false);
589
+ configList.focus();
590
+ ctx.screen.render();
591
+ });
592
+ }
593
+ // ── Standard Editor ─────────────────────────────────────────────────────
594
+ function showEditor(ctx, field, config) {
595
+ if (field.type === "keyvalue") {
596
+ showKeyValueEditor(ctx, config);
597
+ return;
598
+ }
599
+ if (field.type === "webhooks") {
600
+ showWebhookEditor(ctx, config);
601
+ return;
602
+ }
603
+ const currentValue = field.key in pendingChanges
604
+ ? String(pendingChanges[field.key])
605
+ : formatFieldValue(config, field);
606
+ if (field.type === "enum" || field.type === "boolean") {
607
+ const options = field.type === "boolean" ? ["true", "false"] : (field.options || []);
608
+ const selectorList = blessed.list({
609
+ top: "center",
610
+ left: "center",
611
+ width: Math.max(30, ...options.map((o) => o.length + 6)),
612
+ height: options.length + 2,
613
+ border: { type: "line" },
614
+ label: `[ ${field.label} ]`,
615
+ tags: true,
616
+ style: {
617
+ border: { fg: "cyan" },
618
+ selected: { bg: "blue", fg: "white" },
619
+ item: { fg: "white" },
620
+ },
621
+ keys: true,
622
+ vi: false,
623
+ interactive: true,
624
+ });
625
+ selectorList.setItems(options);
626
+ // Pre-select current value
627
+ const currentIdx = options.indexOf(currentValue);
628
+ if (currentIdx >= 0) {
629
+ selectorList.select(currentIdx);
630
+ }
631
+ ctx.setEditing(true);
632
+ ctx.screen.append(selectorList);
633
+ selectorList.focus();
634
+ ctx.screen.render();
635
+ selectorList.on("select", (_item, index) => {
636
+ const selected = options[index];
637
+ if (field.type === "boolean") {
638
+ pendingChanges[field.key] = selected === "true";
639
+ }
640
+ else {
641
+ pendingChanges[field.key] = selected;
642
+ }
643
+ selectorList.destroy();
644
+ ctx.setEditing(false);
645
+ refreshList(config);
646
+ configList.focus();
647
+ ctx.screen.render();
648
+ });
649
+ selectorList.key(["escape"], () => {
650
+ selectorList.destroy();
651
+ ctx.setEditing(false);
652
+ configList.focus();
653
+ ctx.screen.render();
654
+ });
655
+ return;
656
+ }
657
+ // Text input for string, number, string[]
658
+ const inputBox = blessed.textbox({
659
+ top: "center",
660
+ left: "center",
661
+ width: "60%",
662
+ height: 3,
663
+ border: { type: "line" },
664
+ label: `[ ${field.label} ]`,
665
+ tags: true,
666
+ style: {
667
+ border: { fg: "cyan" },
668
+ fg: "white",
669
+ },
670
+ inputOnFocus: true,
671
+ });
672
+ ctx.setEditing(true);
673
+ ctx.screen.append(inputBox);
674
+ inputBox.setValue(currentValue);
675
+ inputBox.focus();
676
+ ctx.screen.render();
677
+ inputBox.on("submit", (value) => {
678
+ // Validate
679
+ if (field.validate) {
680
+ const error = field.validate(value);
681
+ if (error) {
682
+ ctx.showMessage(error, "error");
683
+ inputBox.destroy();
684
+ ctx.setEditing(false);
685
+ configList.focus();
686
+ ctx.screen.render();
687
+ return;
688
+ }
689
+ }
690
+ // Apply value
691
+ if (field.type === "number") {
692
+ pendingChanges[field.key] = parseInt(value, 10);
693
+ }
694
+ else if (field.type === "string[]") {
695
+ pendingChanges[field.key] = value.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
696
+ }
697
+ else {
698
+ pendingChanges[field.key] = value;
699
+ }
700
+ inputBox.destroy();
701
+ ctx.setEditing(false);
702
+ refreshList(config);
703
+ configList.focus();
704
+ ctx.screen.render();
705
+ });
706
+ inputBox.on("cancel", () => {
707
+ inputBox.destroy();
708
+ ctx.setEditing(false);
709
+ configList.focus();
710
+ ctx.screen.render();
711
+ });
712
+ }
713
+ let activeKeyHandlers = [];
714
+ let activeCtx = null;
715
+ function bindKeys(ctx) {
716
+ const handlers = [
717
+ [["enter"], () => {
718
+ const idx = configList.selected;
719
+ if (idx === undefined || idx < 0 || idx >= CONFIG_FIELDS.length)
720
+ return;
721
+ const field = CONFIG_FIELDS[idx];
722
+ if (currentConfig) {
723
+ showEditor(ctx, field, currentConfig);
724
+ }
725
+ }],
726
+ [["s"], () => {
727
+ if (Object.keys(pendingChanges).length === 0) {
728
+ ctx.showMessage("No changes to save", "info");
729
+ return;
730
+ }
731
+ // Save config
732
+ const result = saveConfig(ctx.projectDir, pendingChanges);
733
+ if (!result.success) {
734
+ ctx.showMessage(`Save failed: ${result.error}`, "error");
735
+ return;
736
+ }
737
+ // Check if schedules changed - reinstall cron
738
+ const scheduleChanged = "cronSchedule" in pendingChanges ||
739
+ "reviewerSchedule" in pendingChanges ||
740
+ "reviewerEnabled" in pendingChanges;
741
+ if (scheduleChanged) {
742
+ performUninstall(ctx.projectDir, { keepLogs: true });
743
+ const newConfig = ctx.reloadConfig();
744
+ const installResult = performInstall(ctx.projectDir, newConfig);
745
+ if (!installResult.success) {
746
+ ctx.showMessage(`Config saved but cron reinstall failed: ${installResult.error}`, "error");
747
+ }
748
+ else {
749
+ ctx.showMessage("Config saved & cron reinstalled", "success");
750
+ }
751
+ }
752
+ else {
753
+ ctx.showMessage("Config saved", "success");
754
+ }
755
+ // Reload config
756
+ currentConfig = ctx.reloadConfig();
757
+ // Clear pending
758
+ for (const key of Object.keys(pendingChanges)) {
759
+ delete pendingChanges[key];
760
+ }
761
+ refreshList(currentConfig);
762
+ ctx.screen.render();
763
+ }],
764
+ [["u"], () => {
765
+ for (const key of Object.keys(pendingChanges)) {
766
+ delete pendingChanges[key];
767
+ }
768
+ if (currentConfig) {
769
+ refreshList(currentConfig);
770
+ }
771
+ ctx.showMessage("Changes undone", "info");
772
+ ctx.screen.render();
773
+ }],
774
+ [["g"], () => {
775
+ showGlm5Setup(ctx);
776
+ }],
777
+ ];
778
+ for (const [keys, handler] of handlers) {
779
+ ctx.screen.key(keys, handler);
780
+ }
781
+ activeKeyHandlers = handlers;
782
+ }
783
+ function unbindKeys(ctx) {
784
+ for (const [keys, handler] of activeKeyHandlers) {
785
+ for (const key of keys) {
786
+ ctx.screen.unkey(key, handler);
787
+ }
788
+ }
789
+ activeKeyHandlers = [];
790
+ }
791
+ return {
792
+ name: "Config",
793
+ container,
794
+ activate(ctx) {
795
+ ctx.setFooter(" \u2191\u2193:Navigate Enter:Edit g:GLM-5 Setup s:Save u:Undo q:Quit");
796
+ currentConfig = ctx.config;
797
+ refreshList(currentConfig);
798
+ configList.focus();
799
+ activeCtx = ctx;
800
+ bindKeys(ctx);
801
+ ctx.screen.render();
802
+ },
803
+ deactivate() {
804
+ if (activeCtx) {
805
+ unbindKeys(activeCtx);
806
+ activeCtx = null;
807
+ }
808
+ },
809
+ refresh(ctx) {
810
+ // Only refresh if no pending changes (don't overwrite user edits)
811
+ if (Object.keys(pendingChanges).length === 0) {
812
+ currentConfig = ctx.config;
813
+ refreshList(currentConfig);
814
+ }
815
+ },
816
+ destroy() {
817
+ // Nothing to clean up
818
+ },
819
+ };
820
+ }
821
+ //# sourceMappingURL=tab-config.js.map