pinokiod 7.1.67 → 7.1.69

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "7.1.67",
3
+ "version": "7.1.69",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/server/index.js CHANGED
@@ -5494,14 +5494,13 @@ class Server {
5494
5494
  https_running = true
5495
5495
  }
5496
5496
  } catch (e) {
5497
- // console.log(e)
5497
+ return { error: "caddy admin unavailable" }
5498
5498
  }
5499
5499
  // console.log({ https_running })
5500
5500
  if (!https_running) {
5501
5501
  return { error: "pinokio.host not yet available" }
5502
5502
  }
5503
5503
 
5504
-
5505
5504
  // check if pinokio.localhost router is running
5506
5505
  let router_running = false
5507
5506
  let router = this.kernel.router.published()
@@ -5518,6 +5517,44 @@ class Server {
5518
5517
 
5519
5518
  return { success: true }
5520
5519
  }
5520
+ async ensureSecureRouterReady(timeout = 120000, interval = 500) {
5521
+ if (!(this.kernel && this.kernel.peer && this.kernel.peer.https_active)) {
5522
+ return { success: true, stage: "disabled" }
5523
+ }
5524
+ const caddy = this.kernel && this.kernel.bin && this.kernel.bin.mod
5525
+ ? this.kernel.bin.mod.caddy
5526
+ : null
5527
+ const deadline = Date.now() + timeout
5528
+ let startedCaddyManually = false
5529
+ let refreshedRouter = false
5530
+ let lastStatus = null
5531
+ while (Date.now() < deadline) {
5532
+ lastStatus = await this.check_router_up()
5533
+ if (lastStatus && lastStatus.success) {
5534
+ return lastStatus
5535
+ }
5536
+ if (
5537
+ lastStatus &&
5538
+ lastStatus.error === "caddy admin unavailable" &&
5539
+ !startedCaddyManually &&
5540
+ caddy &&
5541
+ typeof caddy.start === "function"
5542
+ ) {
5543
+ startedCaddyManually = true
5544
+ await caddy.start()
5545
+ continue
5546
+ }
5547
+ if (!refreshedRouter) {
5548
+ refreshedRouter = true
5549
+ await this.kernel.refresh(true).catch(() => {})
5550
+ continue
5551
+ }
5552
+ await new Promise((resolve) => {
5553
+ setTimeout(resolve, interval)
5554
+ })
5555
+ }
5556
+ throw new Error(lastStatus && lastStatus.error ? lastStatus.error : "secure router did not come up")
5557
+ }
5521
5558
  async start(options) {
5522
5559
  this.debug = false
5523
5560
  if (options) {
@@ -5787,6 +5824,12 @@ class Server {
5787
5824
  phase: "initializing_environment"
5788
5825
  })
5789
5826
  await Environment.init({}, this.kernel)
5827
+ if (this.kernel && this.kernel.peer && this.kernel.peer.https_active) {
5828
+ setStartupStatus({
5829
+ phase: "waiting_for_secure_router"
5830
+ })
5831
+ await this.ensureSecureRouterReady()
5832
+ }
5790
5833
  setStartupStatus({
5791
5834
  sys_ready: this.getStartupStatus().sys_ready,
5792
5835
  managed_ready: true,
@@ -11446,7 +11489,6 @@ class Server {
11446
11489
  return
11447
11490
  }
11448
11491
 
11449
-
11450
11492
  // check if pinokio.localhost router is running
11451
11493
  let router_running = false
11452
11494
  let router = this.kernel.router.published()
@@ -243,11 +243,76 @@ document.addEventListener("DOMContentLoaded", async () => {
243
243
  const waitRoot = document.querySelector(".requirements .content")
244
244
  const waitLabel = document.querySelector(".requirements .content .loading span")
245
245
  const WAIT_TIMEOUT_MS = 120000
246
+ const WAIT_DEBUG_HISTORY_LIMIT = 12
247
+ const waitDebugState = {
248
+ events: [],
249
+ phase: null,
250
+ router: null,
251
+ startupError: null,
252
+ }
246
253
  const setWaitLabel = (message) => {
247
254
  if (waitLabel) {
248
255
  waitLabel.textContent = message
249
256
  }
250
257
  }
258
+ const pushWaitDebugEvent = (message) => {
259
+ const timestamp = new Date().toLocaleTimeString()
260
+ const entry = `[${timestamp}] ${message}`
261
+ if (waitDebugState.events[waitDebugState.events.length - 1] !== entry) {
262
+ waitDebugState.events.push(entry)
263
+ if (waitDebugState.events.length > WAIT_DEBUG_HISTORY_LIMIT) {
264
+ waitDebugState.events.shift()
265
+ }
266
+ }
267
+ }
268
+ const ensureWaitDebugPanel = () => {
269
+ if (!waitRoot) {
270
+ return null
271
+ }
272
+ let panel = waitRoot.querySelector(".wait-debug")
273
+ if (!panel) {
274
+ panel = document.createElement("div")
275
+ panel.className = "wait-debug"
276
+ panel.style.marginTop = "16px"
277
+ panel.style.padding = "12px"
278
+ panel.style.border = "1px solid rgba(255,255,255,0.12)"
279
+ panel.style.borderRadius = "8px"
280
+ panel.style.background = "rgba(255,255,255,0.04)"
281
+ panel.style.textAlign = "left"
282
+ panel.innerHTML = `
283
+ <div style="font-size:12px;font-weight:600;letter-spacing:0.04em;text-transform:uppercase;opacity:0.75;margin-bottom:8px;">Debug</div>
284
+ <pre class="wait-debug-body" style="margin:0;text-align:left;white-space:pre-wrap;word-break:break-word;font-size:12px;line-height:1.5;opacity:0.9;"></pre>
285
+ `
286
+ waitRoot.appendChild(panel)
287
+ }
288
+ return panel.querySelector(".wait-debug-body")
289
+ }
290
+ const renderWaitDebug = ({ startedAt, routerStatus, startupStatus } = {}) => {
291
+ const body = ensureWaitDebugPanel()
292
+ if (!body) {
293
+ return
294
+ }
295
+ const elapsedSeconds = startedAt ? Math.max(0, Math.floor((Date.now() - startedAt) / 1000)) : 0
296
+ const lines = [
297
+ `Elapsed: ${elapsedSeconds}s`,
298
+ `Startup phase: ${startupStatus && startupStatus.phase ? startupStatus.phase : "-"}`,
299
+ `Startup error: ${startupStatus && startupStatus.error ? startupStatus.error : "-"}`,
300
+ `Router check: ${routerStatus ? JSON.stringify(routerStatus) : "-"}`,
301
+ `Startup payload: ${startupStatus ? JSON.stringify({
302
+ phase: startupStatus.phase || null,
303
+ error: startupStatus.error || null,
304
+ startup_pending: startupStatus.startup_pending,
305
+ requirements_pending: startupStatus.requirements_pending,
306
+ updated_at: startupStatus.updated_at || null
307
+ }) : "-"}`,
308
+ ]
309
+ if (waitDebugState.events.length > 0) {
310
+ lines.push("")
311
+ lines.push("Recent events:")
312
+ lines.push(...waitDebugState.events)
313
+ }
314
+ body.textContent = lines.join("\n")
315
+ }
251
316
  const showWaitError = (message) => {
252
317
  if (waitRoot) {
253
318
  waitRoot.innerHTML = `
@@ -259,6 +324,7 @@ document.addEventListener("DOMContentLoaded", async () => {
259
324
  <a class='btn' href='${location.href}'>Retry</a>
260
325
  </div>
261
326
  `
327
+ renderWaitDebug()
262
328
  } else {
263
329
  alert(message)
264
330
  }
@@ -266,6 +332,8 @@ document.addEventListener("DOMContentLoaded", async () => {
266
332
 
267
333
  try {
268
334
  setWaitLabel("Enabling secure localhost access...")
335
+ pushWaitDebugEvent("saving secure localhost flags")
336
+ renderWaitDebug()
269
337
  const networkResponse = await fetch("/network", {
270
338
  method: "post",
271
339
  headers: { "Content-Type": "application/json" },
@@ -279,8 +347,12 @@ document.addEventListener("DOMContentLoaded", async () => {
279
347
  if (networkResponse && networkResponse.error) {
280
348
  throw new Error(networkResponse.error)
281
349
  }
350
+ pushWaitDebugEvent("secure localhost flags saved")
351
+ renderWaitDebug()
282
352
 
283
353
  setWaitLabel("Restarting Pinokio...")
354
+ pushWaitDebugEvent("restart requested")
355
+ renderWaitDebug()
284
356
  try {
285
357
  await fetch("/restart", {
286
358
  method: "post"
@@ -292,6 +364,7 @@ document.addEventListener("DOMContentLoaded", async () => {
292
364
  const startedAt = Date.now()
293
365
  let lastKnownError = null
294
366
  let lastKnownPhase = null
367
+ renderWaitDebug({ startedAt })
295
368
 
296
369
  await new Promise((resolve, reject) => {
297
370
  const interval = setInterval(async () => {
@@ -313,6 +386,21 @@ document.addEventListener("DOMContentLoaded", async () => {
313
386
  if (startupStatus && startupStatus.error) {
314
387
  lastKnownError = startupStatus.error
315
388
  }
389
+ if (startupStatus && startupStatus.phase && startupStatus.phase !== waitDebugState.phase) {
390
+ waitDebugState.phase = startupStatus.phase
391
+ pushWaitDebugEvent(`phase -> ${startupStatus.phase}`)
392
+ }
393
+ const routerSummary = routerStatus
394
+ ? (routerStatus.success ? "success" : (routerStatus.error || JSON.stringify(routerStatus)))
395
+ : null
396
+ if (routerSummary && routerSummary !== waitDebugState.router) {
397
+ waitDebugState.router = routerSummary
398
+ pushWaitDebugEvent(`router -> ${routerSummary}`)
399
+ }
400
+ if (startupStatus && startupStatus.error && startupStatus.error !== waitDebugState.startupError) {
401
+ waitDebugState.startupError = startupStatus.error
402
+ pushWaitDebugEvent(`startup error -> ${startupStatus.error}`)
403
+ }
316
404
  if (startupStatus && startupStatus.phase) {
317
405
  lastKnownPhase = startupStatus.phase
318
406
  const phaseMessage = startupStatus.phase === "ready"
@@ -320,6 +408,7 @@ document.addEventListener("DOMContentLoaded", async () => {
320
408
  : `Restarting Pinokio... (${startupStatus.phase.replace(/_/g, " ")})`
321
409
  setWaitLabel(phaseMessage)
322
410
  }
411
+ renderWaitDebug({ startedAt, routerStatus, startupStatus })
323
412
 
324
413
  if (startupStatus && startupStatus.phase === "error") {
325
414
  clearInterval(interval)
@@ -330,10 +419,14 @@ document.addEventListener("DOMContentLoaded", async () => {
330
419
  if ((Date.now() - startedAt) >= WAIT_TIMEOUT_MS) {
331
420
  clearInterval(interval)
332
421
  const detail = lastKnownError || lastKnownPhase || "secure localhost router did not come up"
422
+ pushWaitDebugEvent(`timeout -> ${detail}`)
423
+ renderWaitDebug({ startedAt, routerStatus, startupStatus })
333
424
  reject(new Error(`Timed out waiting for restart: ${detail}`))
334
425
  }
335
426
  } catch (error) {
336
427
  lastKnownError = error && error.message ? error.message : String(error)
428
+ pushWaitDebugEvent(`poll error -> ${lastKnownError}`)
429
+ renderWaitDebug({ startedAt })
337
430
  if ((Date.now() - startedAt) >= WAIT_TIMEOUT_MS) {
338
431
  clearInterval(interval)
339
432
  reject(new Error(`Timed out waiting for restart: ${lastKnownError}`))