pyre-cli 10.1.0 → 10.2.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 (46) hide show
  1. package/README.md +195 -494
  2. package/dist/{checkCmd-RKW6QGDR.js → checkCmd-WQAHAUWO.js} +1 -1
  3. package/dist/{chunk-GHRDW646.js → chunk-23YWCI3O.js} +375 -135
  4. package/dist/{service-Q74BBILO.js → chunk-KFPTD266.js} +43 -3
  5. package/dist/{doctor-GYHFTNZQ.js → chunk-KVUMOA6C.js} +7 -6
  6. package/dist/{chunk-53O2RGSL.js → chunk-QM5L43EK.js} +19 -2
  7. package/dist/{chunk-6UHZP4QP.js → chunk-XTOOEKLM.js} +24 -12
  8. package/dist/{collectors-H43PN4PS.js → collectors-JDN5Y7EV.js} +1 -1
  9. package/dist/{completions-JKYEJNGR.js → completions-ZVTNE52B.js} +15 -11
  10. package/dist/{config-GYGJXU2Q.js → config-J4YMADEF.js} +3 -1
  11. package/dist/doctor-LHFW4UJP.js +10 -0
  12. package/dist/firebaseSync-ON3RZ6KX.js +91 -0
  13. package/dist/index.js +4243 -735
  14. package/dist/monitors/platform/windows-ui.ps1 +42 -0
  15. package/dist/{netUsageCmd-WKBTW2YG.js → netUsageCmd-67IBZZYN.js} +2 -2
  16. package/dist/{pipeCmd-7REDBLBU.js → pipeCmd-2N4JPKYE.js} +1 -1
  17. package/dist/{prometheusCmd-PL64BLN5.js → prometheusCmd-LEUM5WCZ.js} +1 -1
  18. package/dist/serveCmd-L7LVJOZN.js +353 -0
  19. package/dist/service-7GIX3YNC.js +16 -0
  20. package/dist/syncCmd-42IRF633.js +246 -0
  21. package/dist/{topoCmd-DU2HHZNH.js → topoCmd-DZ3YS5IL.js} +1 -1
  22. package/dist/{watchdogCmd-UF53JPZB.js → watchdogCmd-6GR4UN6B.js} +7 -7
  23. package/dist/{wizard-TD7BGX6O.js → wizard-JQMQWFAW.js} +1 -1
  24. package/package.json +4 -3
  25. package/parity.md +2 -0
  26. package/src/completions.ts +15 -11
  27. package/src/easy_features.test.ts +149 -0
  28. package/src/firebaseSync.ts +157 -0
  29. package/src/formatters/html_template.ts +3086 -598
  30. package/src/formatters/render.ts +25 -12
  31. package/src/index.ts +516 -23
  32. package/src/live/input.ts +501 -148
  33. package/src/live/render.ts +163 -18
  34. package/src/live/state.ts +52 -2
  35. package/src/live/types.ts +1 -1
  36. package/src/monitors/collectors.ts +3 -10
  37. package/src/monitors/platform/windows-ui.ps1 +42 -0
  38. package/src/monitors/platform/windows.ts +442 -147
  39. package/src/monitors/types.ts +8 -0
  40. package/src/serveCmd.ts +17 -2
  41. package/src/service.ts +49 -0
  42. package/src/state/config.ts +48 -0
  43. package/src/syncCmd.ts +159 -11
  44. package/src/web/dashboard.ts +205 -0
  45. package/dist/serveCmd-2H5VLF3P.js +0 -153
  46. package/dist/syncCmd-A2W3QB3S.js +0 -126
@@ -0,0 +1,157 @@
1
+ /**
2
+ * pyre Firebase Sync — Firestore backend for `pyre sync`.
3
+ *
4
+ * Stores each machine's config and profiles as a single document in the
5
+ * `pyre-sync` Firestore collection, keyed by hostname (or a user-defined ID).
6
+ *
7
+ * Data model:
8
+ * pyre-sync/{hostId}
9
+ * version: number
10
+ * lastUpdated: ISO string
11
+ * sourceHost: string
12
+ * checksum: string
13
+ * profilesCount: number
14
+ * config: PyreConfig
15
+ * profiles: { [name: string]: PyreConfig }
16
+ */
17
+
18
+ import crypto from 'node:crypto';
19
+ import os from 'node:os';
20
+ import { initializeApp, getApps } from 'firebase/app';
21
+ import {
22
+ getFirestore,
23
+ doc,
24
+ setDoc,
25
+ getDoc,
26
+ getDocs,
27
+ collection,
28
+ query,
29
+ orderBy,
30
+ limit,
31
+ Firestore,
32
+ } from 'firebase/firestore';
33
+ import type { PyreConfig } from './state/config.js';
34
+
35
+ // ─── Firebase project config ──────────────────────────────────────────────────
36
+
37
+ const FIREBASE_CONFIG = {
38
+ apiKey: 'AIzaSyAA86V_wRGJpzc27ZHZd1OBIt4Q-72ASdI',
39
+ authDomain: 'dearborn-internal-tool.firebaseapp.com',
40
+ projectId: 'dearborn-internal-tool',
41
+ storageBucket: 'dearborn-internal-tool.firebasestorage.app',
42
+ messagingSenderId: '77553447918',
43
+ appId: '1:77553447918:web:5c9128660ceeb087c794ff',
44
+ };
45
+
46
+ const COLLECTION = 'pyre-sync';
47
+
48
+ // ─── Types ────────────────────────────────────────────────────────────────────
49
+
50
+ export interface FirebaseSyncDoc {
51
+ version: number;
52
+ lastUpdated: string;
53
+ sourceHost: string;
54
+ checksum: string;
55
+ profilesCount: number;
56
+ config: PyreConfig;
57
+ profiles: Record<string, PyreConfig>;
58
+ }
59
+
60
+ // ─── Internal helpers ─────────────────────────────────────────────────────────
61
+
62
+ let _db: Firestore | null = null;
63
+
64
+ /** Lazily initialise Firebase (idempotent). */
65
+ function getDb(): Firestore {
66
+ if (_db) return _db;
67
+ const app = getApps().length ? getApps()[0] : initializeApp(FIREBASE_CONFIG);
68
+ _db = getFirestore(app);
69
+ return _db;
70
+ }
71
+
72
+ function computeChecksum(config: PyreConfig, profiles: Record<string, PyreConfig>): string {
73
+ const hash = crypto.createHash('sha256');
74
+ hash.update(JSON.stringify(config));
75
+ hash.update(JSON.stringify(profiles));
76
+ return hash.digest('hex').slice(0, 16);
77
+ }
78
+
79
+ function resolveHostId(hostId?: string): string {
80
+ return (hostId || os.hostname()).replace(/[^a-zA-Z0-9_-]/g, '-');
81
+ }
82
+
83
+ // ─── Public API ───────────────────────────────────────────────────────────────
84
+
85
+ /**
86
+ * Push local config + profiles to Firestore.
87
+ */
88
+ export async function firebasePush(
89
+ config: PyreConfig,
90
+ profiles: Record<string, PyreConfig>,
91
+ hostId?: string,
92
+ ): Promise<{ hostId: string; checksum: string; lastUpdated: string }> {
93
+ const db = getDb();
94
+ const id = resolveHostId(hostId);
95
+ const checksum = computeChecksum(config, profiles);
96
+ const lastUpdated = new Date().toISOString();
97
+
98
+ const payload: FirebaseSyncDoc = {
99
+ version: 1,
100
+ lastUpdated,
101
+ sourceHost: os.hostname(),
102
+ checksum,
103
+ profilesCount: Object.keys(profiles).length,
104
+ config,
105
+ profiles,
106
+ };
107
+
108
+ await setDoc(doc(db, COLLECTION, id), payload);
109
+ return { hostId: id, checksum, lastUpdated };
110
+ }
111
+
112
+ /**
113
+ * Pull config + profiles from Firestore.
114
+ * If hostId is provided, fetches that specific machine's document.
115
+ * Otherwise fetches the most-recently-updated document across all hosts.
116
+ */
117
+ export async function firebasePull(hostId?: string): Promise<{
118
+ doc: FirebaseSyncDoc;
119
+ hostId: string;
120
+ } | null> {
121
+ const db = getDb();
122
+
123
+ if (hostId) {
124
+ const id = resolveHostId(hostId);
125
+ const snap = await getDoc(doc(db, COLLECTION, id));
126
+ if (!snap.exists()) return null;
127
+ return { doc: snap.data() as FirebaseSyncDoc, hostId: id };
128
+ }
129
+
130
+ // No hostId — grab the most-recently-updated doc across all hosts
131
+ const q = query(collection(db, COLLECTION), orderBy('lastUpdated', 'desc'), limit(1));
132
+ const snaps = await getDocs(q);
133
+ if (snaps.empty) return null;
134
+ const first = snaps.docs[0];
135
+ return { doc: first.data() as FirebaseSyncDoc, hostId: first.id };
136
+ }
137
+
138
+ /**
139
+ * List all sync documents (one per machine) sorted newest-first.
140
+ */
141
+ export async function firebaseStatus(): Promise<
142
+ Array<{ hostId: string; sourceHost: string; lastUpdated: string; profilesCount: number; checksum: string }>
143
+ > {
144
+ const db = getDb();
145
+ const q = query(collection(db, COLLECTION), orderBy('lastUpdated', 'desc'));
146
+ const snaps = await getDocs(q);
147
+ return snaps.docs.map((d) => {
148
+ const data = d.data() as FirebaseSyncDoc;
149
+ return {
150
+ hostId: d.id,
151
+ sourceHost: data.sourceHost,
152
+ lastUpdated: data.lastUpdated,
153
+ profilesCount: data.profilesCount,
154
+ checksum: data.checksum,
155
+ };
156
+ });
157
+ }