@hyperwindmill/caretaker-cli 0.34.0 → 0.36.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 (38) hide show
  1. package/dist/cli/index.d.ts.map +1 -1
  2. package/dist/cli/index.js +16 -0
  3. package/dist/cli/orchestrator_demo.d.ts +39 -0
  4. package/dist/cli/orchestrator_demo.d.ts.map +1 -0
  5. package/dist/cli/orchestrator_demo.js +98 -0
  6. package/dist/cli/web/api_access.d.ts.map +1 -1
  7. package/dist/cli/web/api_access.js +1 -1
  8. package/dist/cli/web/openapi.d.ts +5 -0
  9. package/dist/cli/web/openapi.d.ts.map +1 -1
  10. package/dist/cli/web/openapi.js +78 -5
  11. package/dist/cli/web/orchestrator.d.ts +51 -0
  12. package/dist/cli/web/orchestrator.d.ts.map +1 -0
  13. package/dist/cli/web/orchestrator.js +596 -0
  14. package/dist/cli/web/orchestrator_core.d.ts +83 -0
  15. package/dist/cli/web/orchestrator_core.d.ts.map +1 -0
  16. package/dist/cli/web/orchestrator_core.js +219 -0
  17. package/dist/cli/web/save_config.d.ts +8 -0
  18. package/dist/cli/web/save_config.d.ts.map +1 -0
  19. package/dist/cli/web/save_config.js +9 -0
  20. package/dist/cli/web/scheduler/task_strategy.d.ts.map +1 -1
  21. package/dist/cli/web/scheduler/task_strategy.js +21 -2
  22. package/dist/cli/web/server.d.ts +3 -0
  23. package/dist/cli/web/server.d.ts.map +1 -1
  24. package/dist/cli/web/server.js +50 -19
  25. package/dist/lib/task_git.d.ts +3 -0
  26. package/dist/lib/task_git.d.ts.map +1 -1
  27. package/dist/lib/task_git.js +29 -0
  28. package/dist/store/db.d.ts +5 -0
  29. package/dist/store/db.d.ts.map +1 -1
  30. package/dist/store/db.js +12 -0
  31. package/dist/store/orchestrator.d.ts +50 -0
  32. package/dist/store/orchestrator.d.ts.map +1 -0
  33. package/dist/store/orchestrator.js +127 -0
  34. package/dist/webview/standalone.css +159 -1
  35. package/dist/webview/standalone.css.map +2 -2
  36. package/dist/webview/standalone.js +784 -504
  37. package/dist/webview/standalone.js.map +4 -4
  38. package/package.json +3 -3
@@ -0,0 +1,127 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { mkdirSync } from 'node:fs';
3
+ import { readFile } from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import { dataDir } from './json.js';
6
+ import { encrypt, isEncrypted } from '../lib/encryption.js';
7
+ import { atomicWriteFile } from '../cli/web/scheduler/telegram_window.js';
8
+ export function orchestratorPath() {
9
+ return path.join(dataDir(), 'orchestrator.json');
10
+ }
11
+ export function orchestratorLedgerPath() {
12
+ return path.join(dataDir(), 'orchestrator-ledger.json');
13
+ }
14
+ async function readRaw() {
15
+ try {
16
+ const parsed = JSON.parse(await readFile(orchestratorPath(), 'utf8'));
17
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
18
+ return parsed;
19
+ }
20
+ }
21
+ catch {
22
+ // Missing or unreadable file -> defaults
23
+ }
24
+ return {};
25
+ }
26
+ const hasInstanceId = (raw) => typeof raw.instanceId === 'string' && raw.instanceId.length > 0;
27
+ /** The one in-flight instanceId creation: concurrent first loads (the loop and
28
+ * the settings GET at boot) would otherwise each mint and save their own id. */
29
+ let idCreation = null;
30
+ /**
31
+ * Loads orchestrator.json with defaults (disabled, '', '', '', 15, 'approve').
32
+ * Generates and persists `instanceId` (randomUUID) when missing.
33
+ * Always returns a fresh object.
34
+ */
35
+ export async function loadOrchestrator() {
36
+ let raw = await readRaw();
37
+ if (!hasInstanceId(raw)) {
38
+ idCreation ??= (async () => {
39
+ const again = await readRaw();
40
+ if (!hasInstanceId(again))
41
+ await saveOrchestrator(normalize({ ...again, instanceId: randomUUID() }));
42
+ })().finally(() => {
43
+ idCreation = null;
44
+ });
45
+ await idCreation;
46
+ raw = await readRaw();
47
+ }
48
+ return normalize(raw);
49
+ }
50
+ function normalize(raw) {
51
+ return {
52
+ enabled: typeof raw.enabled === 'boolean' ? raw.enabled : false,
53
+ name: typeof raw.name === 'string' ? raw.name : '',
54
+ endpoint: typeof raw.endpoint === 'string' ? raw.endpoint : '',
55
+ token: typeof raw.token === 'string' ? raw.token : '',
56
+ pollSeconds: typeof raw.pollSeconds === 'number' && Number.isFinite(raw.pollSeconds) ? raw.pollSeconds : 15,
57
+ policy: raw.policy === 'auto' || raw.policy === 'approve' ? raw.policy : 'approve',
58
+ instanceId: hasInstanceId(raw) ? raw.instanceId : '',
59
+ };
60
+ }
61
+ /**
62
+ * Persists orchestrator.json atomically. Encrypts `token` when it is not
63
+ * already an encrypted blob.
64
+ */
65
+ export async function saveOrchestrator(c) {
66
+ const copy = { ...c };
67
+ if (copy.token && !isEncrypted(copy.token)) {
68
+ copy.token = encrypt(copy.token);
69
+ }
70
+ const filePath = orchestratorPath();
71
+ mkdirSync(path.dirname(filePath), { recursive: true });
72
+ await atomicWriteFile(filePath, JSON.stringify(copy, null, 2));
73
+ }
74
+ function isValidLedgerRecord(r) {
75
+ if (!r || typeof r !== 'object' || Array.isArray(r))
76
+ return false;
77
+ const o = r;
78
+ if (typeof o.id !== 'string' || o.id.length === 0)
79
+ return false;
80
+ if (typeof o.method !== 'string')
81
+ return false;
82
+ if (typeof o.path !== 'string')
83
+ return false;
84
+ if (typeof o.receivedAt !== 'string')
85
+ return false;
86
+ if (o.state !== 'pending' && o.state !== 'applying' && o.state !== 'done')
87
+ return false;
88
+ if (typeof o.delivered !== 'boolean')
89
+ return false;
90
+ if (o.body !== undefined && typeof o.body !== 'string')
91
+ return false;
92
+ if (o.resolvedAt !== undefined && typeof o.resolvedAt !== 'string')
93
+ return false;
94
+ if (o.result !== undefined) {
95
+ if (!o.result || typeof o.result !== 'object' || Array.isArray(o.result))
96
+ return false;
97
+ const res = o.result;
98
+ if (typeof res.status !== 'number' || !Number.isFinite(res.status))
99
+ return false;
100
+ if (res.body !== undefined && typeof res.body !== 'string')
101
+ return false;
102
+ }
103
+ return true;
104
+ }
105
+ /**
106
+ * Loads orchestrator-ledger.json. Unreadable or non-array file returns [].
107
+ * Malformed records are dropped.
108
+ */
109
+ export async function loadLedger() {
110
+ try {
111
+ const parsed = JSON.parse(await readFile(orchestratorLedgerPath(), 'utf8'));
112
+ if (!Array.isArray(parsed))
113
+ return [];
114
+ return parsed.filter(isValidLedgerRecord);
115
+ }
116
+ catch {
117
+ return [];
118
+ }
119
+ }
120
+ /**
121
+ * Persists orchestrator-ledger.json atomically.
122
+ */
123
+ export async function saveLedger(records) {
124
+ const filePath = orchestratorLedgerPath();
125
+ mkdirSync(path.dirname(filePath), { recursive: true });
126
+ await atomicWriteFile(filePath, JSON.stringify(records, null, 2));
127
+ }
@@ -1325,7 +1325,7 @@ body.vscode-light .thinking__content {
1325
1325
  }
1326
1326
  .app--settings-centered .settings-panel {
1327
1327
  width: 100% !important;
1328
- max-width: 1280px !important;
1328
+ max-width: 1440px !important;
1329
1329
  height: 100% !important;
1330
1330
  margin: 0 auto !important;
1331
1331
  border-left: 1px solid var(--vscode-panel-border, oklch(1 0 0 / 0.08));
@@ -1459,6 +1459,164 @@ body.vscode-light .settings-panel__tab-btn--active {
1459
1459
  flex-direction: column;
1460
1460
  gap: var(--spacing-md);
1461
1461
  }
1462
+ .settings-panel--vertical {
1463
+ display: grid;
1464
+ grid-template-columns: 160px 1fr;
1465
+ grid-template-rows: auto 1fr;
1466
+ }
1467
+ .settings-panel--vertical .settings-panel__header {
1468
+ grid-column: 1 / -1;
1469
+ }
1470
+ .settings-panel--vertical .settings-panel__tabs {
1471
+ flex-direction: column;
1472
+ width: 160px;
1473
+ border-bottom: none;
1474
+ border-right: 1px solid var(--vscode-panel-border, oklch(1 0 0 / 0.08));
1475
+ padding: 8px 6px;
1476
+ gap: 2px;
1477
+ overflow-y: auto;
1478
+ }
1479
+ .settings-panel--vertical .settings-panel__tab-btn {
1480
+ flex: none;
1481
+ display: flex;
1482
+ align-items: center;
1483
+ justify-content: space-between;
1484
+ text-align: left;
1485
+ padding: 8px 12px;
1486
+ font-size: 12px;
1487
+ }
1488
+ .settings-panel--vertical .settings-panel__content {
1489
+ min-width: 0;
1490
+ min-height: 0;
1491
+ }
1492
+ .settings-panel__badge,
1493
+ .app__nav-badge {
1494
+ display: inline-flex;
1495
+ align-items: center;
1496
+ justify-content: center;
1497
+ min-width: 18px;
1498
+ height: 18px;
1499
+ padding: 0 5px;
1500
+ border-radius: 999px;
1501
+ font-size: 10px;
1502
+ font-weight: 700;
1503
+ background: var(--primary-blue);
1504
+ color: #ffffff;
1505
+ }
1506
+ .settings-panel__tab-btn--active .settings-panel__badge {
1507
+ background: oklch(1 0 0 / 0.25);
1508
+ }
1509
+ .app__nav-btn {
1510
+ position: relative;
1511
+ }
1512
+ .app__nav-badge {
1513
+ position: absolute;
1514
+ top: 4px;
1515
+ right: 4px;
1516
+ min-width: 16px;
1517
+ height: 16px;
1518
+ font-size: 9px;
1519
+ }
1520
+ .orchestration-tab__header {
1521
+ display: flex;
1522
+ align-items: center;
1523
+ justify-content: space-between;
1524
+ gap: var(--spacing-md);
1525
+ flex-wrap: wrap;
1526
+ }
1527
+ .orchestration-tab__status {
1528
+ font-size: 12px;
1529
+ color: var(--vscode-descriptionForeground);
1530
+ }
1531
+ .orchestration-tab__status--connected {
1532
+ color: var(--accent-cyan);
1533
+ }
1534
+ .orchestration-tab__status--error {
1535
+ color: var(--vscode-errorForeground, #f48771);
1536
+ }
1537
+ .orchestration-tab__radios {
1538
+ display: flex;
1539
+ flex-direction: column;
1540
+ gap: 6px;
1541
+ }
1542
+ .orchestration-tab__warning {
1543
+ color: var(--vscode-editorWarning-foreground, #cca700);
1544
+ margin-left: 20px;
1545
+ }
1546
+ .orchestration-tab__actions {
1547
+ display: flex;
1548
+ gap: 8px;
1549
+ }
1550
+ .orchestration-tab__test-ok {
1551
+ color: var(--accent-cyan);
1552
+ }
1553
+ .orchestration-tab__section {
1554
+ margin-top: 16px;
1555
+ padding-top: 12px;
1556
+ border-top: 1px solid var(--vscode-panel-border, oklch(1 0 0 / 0.08));
1557
+ }
1558
+ .orchestration-tab__section h5 {
1559
+ margin: 0 0 8px 0;
1560
+ font-size: 12px;
1561
+ font-weight: 600;
1562
+ }
1563
+ .orchestration-tab__empty {
1564
+ color: var(--vscode-descriptionForeground);
1565
+ }
1566
+ .orchestration-tab__list {
1567
+ display: flex;
1568
+ flex-direction: column;
1569
+ gap: 8px;
1570
+ }
1571
+ .orchestration-tab__pending-row {
1572
+ padding: 8px 10px;
1573
+ border-radius: var(--radius-sm);
1574
+ background: oklch(1 0 0 / 0.03);
1575
+ border: 1px solid var(--vscode-panel-border, oklch(1 0 0 / 0.08));
1576
+ }
1577
+ .orchestration-tab__pending-main {
1578
+ display: flex;
1579
+ align-items: center;
1580
+ gap: 8px;
1581
+ font-size: 12px;
1582
+ }
1583
+ .orchestration-tab__row-actions {
1584
+ margin-left: auto;
1585
+ display: flex;
1586
+ gap: 6px;
1587
+ }
1588
+ .orchestration-tab__details {
1589
+ margin-top: 6px;
1590
+ font-size: 11px;
1591
+ }
1592
+ .orchestration-tab__details pre {
1593
+ margin: 4px 0 0 0;
1594
+ padding: 6px;
1595
+ border-radius: var(--radius-sm);
1596
+ background: oklch(0 0 0 / 0.25);
1597
+ overflow-x: auto;
1598
+ }
1599
+ .orchestration-tab__activity-row {
1600
+ display: flex;
1601
+ align-items: center;
1602
+ gap: 8px;
1603
+ font-size: 12px;
1604
+ padding: 4px 0;
1605
+ }
1606
+ .orchestration-tab__time {
1607
+ color: var(--vscode-descriptionForeground);
1608
+ font-variant-numeric: tabular-nums;
1609
+ }
1610
+ .orchestration-tab__path {
1611
+ flex: 1;
1612
+ min-width: 0;
1613
+ overflow: hidden;
1614
+ text-overflow: ellipsis;
1615
+ white-space: nowrap;
1616
+ }
1617
+ .orchestration-tab__code {
1618
+ color: var(--vscode-descriptionForeground);
1619
+ }
1462
1620
  .settings-panel__content::-webkit-scrollbar {
1463
1621
  width: 4px;
1464
1622
  }