instar 0.9.78 → 0.9.79

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.
@@ -101,6 +101,17 @@ export function createRoutes(ctx) {
101
101
  usedPercent: Math.round(((totalMem - freeMem) / totalMem) * 1000) / 10,
102
102
  };
103
103
  }
104
+ // Memory pressure state from MemoryPressureMonitor (macOS-accurate via vm_stat).
105
+ // On macOS, os.freemem() is misleading — wired+compressed+app memory leaves little
106
+ // "free" even under no real pressure. MemoryPressureMonitor uses platform-native
107
+ // APIs to classify actual pressure as normal/warning/elevated/critical.
108
+ if (ctx.memoryMonitor) {
109
+ const ps = ctx.memoryMonitor.getState();
110
+ base.memoryPressure = {
111
+ state: ps.state,
112
+ pressurePercent: ps.pressurePercent,
113
+ };
114
+ }
104
115
  // Orphan reaper last report (per-process memory visibility)
105
116
  if (ctx.orphanReaper) {
106
117
  const reaperReport = ctx.orphanReaper.getLastReport();
@@ -1816,6 +1827,18 @@ export function createRoutes(ctx) {
1816
1827
  res.json({ autoApply, persisted: true });
1817
1828
  });
1818
1829
  router.post('/updates/apply', async (_req, res) => {
1830
+ // Prefer AutoUpdater path (coalescing + session-aware gating)
1831
+ if (ctx.autoUpdater) {
1832
+ try {
1833
+ await ctx.autoUpdater.applyPendingUpdate();
1834
+ res.json(ctx.autoUpdater.getStatus());
1835
+ }
1836
+ catch (err) {
1837
+ res.status(500).json({ error: err instanceof Error ? err.message : String(err) });
1838
+ }
1839
+ return;
1840
+ }
1841
+ // Fallback: direct apply (no coalescing/gating)
1819
1842
  if (!ctx.updateChecker) {
1820
1843
  res.status(503).json({ error: 'Update checker not configured' });
1821
1844
  return;
@@ -1855,6 +1878,29 @@ export function createRoutes(ctx) {
1855
1878
  }
1856
1879
  res.json(ctx.autoUpdater.getStatus());
1857
1880
  });
1881
+ // GET /updates/status — comprehensive update status for monitoring/UI
1882
+ router.get('/updates/status', async (_req, res) => {
1883
+ const status = {
1884
+ currentVersion: ctx.updateChecker?.getInstalledVersion() ?? 'unknown',
1885
+ autoApply: ctx.config.updates?.autoApply ?? true,
1886
+ };
1887
+ if (ctx.autoUpdater) {
1888
+ const auto = ctx.autoUpdater.getStatus();
1889
+ Object.assign(status, {
1890
+ pendingUpdate: auto.pendingUpdate,
1891
+ pendingUpdateDetectedAt: auto.pendingUpdateDetectedAt,
1892
+ coalescingUntil: auto.coalescingUntil,
1893
+ deferralReason: auto.deferralReason,
1894
+ deferralElapsedMinutes: auto.deferralElapsedMinutes,
1895
+ maxDeferralHours: auto.maxDeferralHours,
1896
+ lastCheck: auto.lastCheck,
1897
+ lastApply: auto.lastApply,
1898
+ lastAppliedVersion: auto.lastAppliedVersion,
1899
+ lastError: auto.lastError,
1900
+ });
1901
+ }
1902
+ res.json(status);
1903
+ });
1858
1904
  // ── Dispatches ───────────────────────────────────────────────────
1859
1905
  router.get('/dispatches', async (_req, res) => {
1860
1906
  if (!ctx.dispatches) {