Spaces:
Sleeping
Sleeping
hfpi status: terminals running a command (Restart and update waits for them)
Browse files- piweb/hf-design.patch +4 -2
- sandbox/hfpi.mjs +22 -0
piweb/hf-design.patch
CHANGED
|
@@ -31592,10 +31592,10 @@ index 0000000..78e09cf
|
|
| 31592 |
+ limitations under the License.
|
| 31593 |
diff --git a/components/carbon/icons.ts b/components/carbon/icons.ts
|
| 31594 |
new file mode 100644
|
| 31595 |
-
index 0000000..
|
| 31596 |
--- /dev/null
|
| 31597 |
+++ b/components/carbon/icons.ts
|
| 31598 |
-
@@ -0,0 +1,
|
| 31599 |
+// Generated by design/carbon-icons.mjs from @carbon/icons 11.89.0 (Apache-2.0, Copyright IBM Corp.). Do not edit.
|
| 31600 |
+// Each icon is its grid (Carbon's 32 units, or 16 for icons drawn for 16px) and its shapes; CarbonIcon (../CarbonIcon.tsx) renders it.
|
| 31601 |
+
|
|
@@ -31830,6 +31830,8 @@ index 0000000..1b29eaa
|
|
| 31830 |
+export const Undo: CarbonIconData = { viewBox: "0 0 32 32", shapes: [["path", {"d":"M20,10H7.8149l3.5874-3.5859L10,5,4,11,10,17l1.4023-1.4146L7.8179,12H20a6,6,0,0,1,0,12H12v2h8a8,8,0,0,0,0-16Z"}]] };
|
| 31831 |
+/** carbon: unlocked */
|
| 31832 |
+export const Unlocked: CarbonIconData = { viewBox: "0 0 16 16", shapes: [["path", {"d":"M12,7H6V4c0-1.1,0.9-2,2-2s2,0.9,2,2h1c0-1.7-1.3-3-3-3S5,2.3,5,4v3H4C3.4,7,3,7.4,3,8v6c0,0.6,0.4,1,1,1h8c0.6,0,1-0.4,1-1\tV8C13,7.4,12.6,7,12,7z M12,14H4V8h8V14z"}]] };
|
|
|
|
|
|
|
| 31833 |
+/** carbon: upload */
|
| 31834 |
+export const Upload: CarbonIconData = { viewBox: "0 0 16 16", shapes: [["path", {"d":"M3 9 3.7 9.7 7.5 5.9 7.5 15 8.5 15 8.5 5.9 12.3 9.7 13 9 8 4z"}], ["path", {"d":"M3,4V2h10v2h1V2c0-0.6-0.4-1-1-1H3C2.4,1,2,1.4,2,2v2H3z"}]] };
|
| 31835 |
+/** carbon: user */
|
|
|
|
| 31592 |
+ limitations under the License.
|
| 31593 |
diff --git a/components/carbon/icons.ts b/components/carbon/icons.ts
|
| 31594 |
new file mode 100644
|
| 31595 |
+
index 0000000..9fd2161
|
| 31596 |
--- /dev/null
|
| 31597 |
+++ b/components/carbon/icons.ts
|
| 31598 |
+
@@ -0,0 +1,252 @@
|
| 31599 |
+// Generated by design/carbon-icons.mjs from @carbon/icons 11.89.0 (Apache-2.0, Copyright IBM Corp.). Do not edit.
|
| 31600 |
+// Each icon is its grid (Carbon's 32 units, or 16 for icons drawn for 16px) and its shapes; CarbonIcon (../CarbonIcon.tsx) renders it.
|
| 31601 |
+
|
|
|
|
| 31830 |
+export const Undo: CarbonIconData = { viewBox: "0 0 32 32", shapes: [["path", {"d":"M20,10H7.8149l3.5874-3.5859L10,5,4,11,10,17l1.4023-1.4146L7.8179,12H20a6,6,0,0,1,0,12H12v2h8a8,8,0,0,0,0-16Z"}]] };
|
| 31831 |
+/** carbon: unlocked */
|
| 31832 |
+export const Unlocked: CarbonIconData = { viewBox: "0 0 16 16", shapes: [["path", {"d":"M12,7H6V4c0-1.1,0.9-2,2-2s2,0.9,2,2h1c0-1.7-1.3-3-3-3S5,2.3,5,4v3H4C3.4,7,3,7.4,3,8v6c0,0.6,0.4,1,1,1h8c0.6,0,1-0.4,1-1\tV8C13,7.4,12.6,7,12,7z M12,14H4V8h8V14z"}]] };
|
| 31833 |
+
+/** carbon: upgrade */
|
| 31834 |
+
+export const Upgrade: CarbonIconData = { viewBox: "0 0 32 32", shapes: [["path", {"d":"M21,24H11a2,2,0,0,0-2,2v2a2,2,0,0,0,2,2H21a2,2,0,0,0,2-2V26A2,2,0,0,0,21,24Zm0,4H11V26H21Z"}], ["path", {"d":"M28.707,14.293l-12-12a.9994.9994,0,0,0-1.414,0l-12,12A1,1,0,0,0,4,16H9v4a2.0023,2.0023,0,0,0,2,2H21a2.0027,2.0027,0,0,0,2-2V16h5a1,1,0,0,0,.707-1.707ZM21,14v6H11V14H6.4141L16,4.4141,25.5859,14Z"}]] };
|
| 31835 |
+/** carbon: upload */
|
| 31836 |
+export const Upload: CarbonIconData = { viewBox: "0 0 16 16", shapes: [["path", {"d":"M3 9 3.7 9.7 7.5 5.9 7.5 15 8.5 15 8.5 5.9 12.3 9.7 13 9 8 4z"}], ["path", {"d":"M3,4V2h10v2h1V2c0-0.6-0.4-1-1-1H3C2.4,1,2,1.4,2,2v2H3z"}]] };
|
| 31837 |
+/** carbon: user */
|
sandbox/hfpi.mjs
CHANGED
|
@@ -516,6 +516,27 @@ async function runningSessions() {
|
|
| 516 |
return data.runningSessionIds || [];
|
| 517 |
}
|
| 518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
// ---------------------------------------------------------------- commands
|
| 520 |
|
| 521 |
async function cmdRun() {
|
|
@@ -782,6 +803,7 @@ async function cmdStatus() {
|
|
| 782 |
return {
|
| 783 |
supervisor: sup ? { ...sup, alive: supervisorAlive } : null,
|
| 784 |
piweb: { healthy: running !== null, running_sessions: running || [] },
|
|
|
|
| 785 |
idle_seconds: Math.round((Date.now() - mtimeMs(path.join(RUN_DIR, "heartbeat"))) / 1000),
|
| 786 |
idle_minutes_limit: IDLE_MINUTES,
|
| 787 |
agent_saved_at: exists(AGENT_ARCHIVE) ? new Date(mtimeMs(AGENT_ARCHIVE)).toISOString() : null,
|
|
|
|
| 516 |
return data.runningSessionIds || [];
|
| 517 |
}
|
| 518 |
|
| 519 |
+
// Pi Web's terminals are login shells (`$SHELL -l`) under its node server. One with a
|
| 520 |
+
// child process is running a command (a build, a dev server): restarting would kill it.
|
| 521 |
+
function terminals(procRoot = "/proc") {
|
| 522 |
+
const procs = new Map();
|
| 523 |
+
for (const pid of fs.readdirSync(procRoot).filter((name) => /^\d+$/.test(name))) {
|
| 524 |
+
try {
|
| 525 |
+
const stat = fs.readFileSync(path.join(procRoot, pid, "stat"), "utf8");
|
| 526 |
+
const ppid = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1];
|
| 527 |
+
const argv = fs.readFileSync(path.join(procRoot, pid, "cmdline"), "utf8").split("\0").filter(Boolean);
|
| 528 |
+
procs.set(pid, { ppid, argv });
|
| 529 |
+
} catch {} // gone meanwhile
|
| 530 |
+
}
|
| 531 |
+
const shells = [...procs].filter(([, p]) => p.argv.length === 2 && p.argv[1] === "-l" && /(^|\/)node$|^next-server/.test(procs.get(p.ppid)?.argv[0] || ""));
|
| 532 |
+
const busy = [];
|
| 533 |
+
for (const [pid] of shells) {
|
| 534 |
+
const child = [...procs.values()].find((p) => p.ppid === pid);
|
| 535 |
+
if (child) busy.push({ command: child.argv.join(" ").slice(0, 120) });
|
| 536 |
+
}
|
| 537 |
+
return { open: shells.length, busy };
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
// ---------------------------------------------------------------- commands
|
| 541 |
|
| 542 |
async function cmdRun() {
|
|
|
|
| 803 |
return {
|
| 804 |
supervisor: sup ? { ...sup, alive: supervisorAlive } : null,
|
| 805 |
piweb: { healthy: running !== null, running_sessions: running || [] },
|
| 806 |
+
terminals: (() => { try { return terminals(); } catch { return null; } })(),
|
| 807 |
idle_seconds: Math.round((Date.now() - mtimeMs(path.join(RUN_DIR, "heartbeat"))) / 1000),
|
| 808 |
idle_minutes_limit: IDLE_MINUTES,
|
| 809 |
agent_saved_at: exists(AGENT_ARCHIVE) ? new Date(mtimeMs(AGENT_ARCHIVE)).toISOString() : null,
|