Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,17 @@ You should not have to run `git status` in every worktree to find out what your

Not everyone lives in a terminal. `/gentle:tower` opens a local web view where each project is a painted building and each open Gentle Shell session is a floor of it. The orchestrator and its named helpers (`worker`, `explore`, `verify`, or `worker-tests` when a role repeats) stand in the room of what they are doing: the map while exploring, the workshop while building, the lab while testing, the lounge when done. A `?` means a floor needs you.

To open it without a session, run `gentle-shell tower` from any terminal: it prints the local URL, opens your browser and keeps serving until Ctrl+C (`--no-open` only prints the URL; `--port <n>` fixes the port, still `127.0.0.1` only; `--json` prints the URL as one JSON line for programs).
To open it without a session, run `gentle-shell tower` from any terminal: it prints the local URL, opens your browser and keeps serving until Ctrl+C (`--no-open` only prints the URL; `--port <n>` fixes the port, still `127.0.0.1` only; `--json` prints the URL as one JSON line for programs). Add `--lan` to also serve the machine's network addresses, so a phone on the same network can open the view: it prints one URL per address, a QR code of the first for the phone to scan, and the warning below.

- **Tasks at a glance**: each floor shows its todo progress (`2/4 · blocked: …`); click it for the full list. The map's corkboard notes are the same tasks.
- **Talk to a floor** (`T`): read the orchestrator's latest words and send a message; it arrives as a new turn, or as a follow-up while the agent works. Questions asked in the terminal show as waiting; answer them there or tell the floor.
- **Artifacts**: the docs, Mermaid diagrams and images a floor wrote open in a viewer.
- **Engram library and your tab**: a read-only window on the project's memories and on what the open sessions spent, by model and by project.
- **Controls**: stop a helper, change a floor's permissions, and switch review mode.

The web never has more power than the terminal: it listens on `127.0.0.1` only, with a fresh token in the path on every launch, refuses other origins. Lowering a floor's permissions applies at once; raising them asks for confirmation in that session's terminal. Each session runs the requests itself, with its own rules.
On a phone (or any touch screen) the same view adapts: the building scales to the viewport width, the floor cards become a tappable list under it with at least 44px targets, the helpers on a floor get their own tappable chips, and the panels — Talk, tasks, artifacts, the Engram library, your tab, permissions — dock into a bottom sheet. `/gentle:tower-mobile` (or `/gentle:tower --lan`) serves the view on your network for the phone; `gentle-shell tower --lan` from a terminal prints a QR code to scan.

The web never has more power than the terminal: it listens on `127.0.0.1` only (`--lan` additionally serves the machine's own addresses), with a fresh token in the path on every launch, refuses other origins. Lowering a floor's permissions applies at once; raising them asks for confirmation in that session's terminal. Each session runs the requests itself, with its own rules. `--lan` is for a trusted home network: anyone on it who opens the URL can read and drive your sessions, and the traffic is not encrypted — the launch prints this warning.

**[Docs →](docs/gentle-shell.md#gentle-tower)**

Expand Down
2 changes: 1 addition & 1 deletion bin/gentle-shell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,7 @@ async function main() {
const tower = parseTowerArgs(args.commandArgs);
if (tower.error !== undefined) fail(`gentle-shell tower: ${tower.error}\nRun 'gentle-shell --help' for usage.`, 2);
const { runTower } = await import("../runtime/tower-open.mjs");
process.exitCode = await runTower({ env: process.env, open: tower.open, port: tower.port, json: tower.json === true,
process.exitCode = await runTower({ env: process.env, open: tower.open, port: tower.port, json: tower.json === true, lan: tower.lan === true,
stdout: (text) => process.stdout.write(text), stderr: (text) => process.stderr.write(text) });
return;
}
Expand Down
6 changes: 3 additions & 3 deletions docs/gentle-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ The canvas server binds `127.0.0.1` on a random port and needs a random per-serv

### Gentle Tower

Gentle Tower is a web view of every open Gentle Shell session, for people who prefer a picture to a terminal. Each project is a painted building and each session is a floor of it. Open it with `/gentle:tower` inside a session, or with `gentle-shell tower` from any terminal (`--no-open` prints the URL only, `--port <n>` fixes the port, `--json` prints one JSON line `{"schema":"gentle-shell.tower/v1","url":…,"host":"127.0.0.1","port":…}` instead of the text, for programs such as the desktop app). It serves until Ctrl+C or until the session that opened it ends. Hovering anything clickable outlines it and names what a click does; a short tour on the first visit points at the floors, people, rooms, door and top bar, and the `?` button (or the `?` key) shows it again.
Gentle Tower is a web view of every open Gentle Shell session, for people who prefer a picture to a terminal. Each project is a painted building and each session is a floor of it. Open it with `/gentle:tower` inside a session, or with `gentle-shell tower` from any terminal (`--no-open` prints the URL only, `--port <n>` fixes the port, `--json` prints one JSON line `{"schema":"gentle-shell.tower/v1","url":…,"host":"127.0.0.1","port":…}` instead of the text, for programs such as the desktop app; with `--lan` the line also carries `lan`, `urls` and `warning`). `/gentle:tower-mobile` is the one-word way to open the same-network mode from a session (equivalent to `/gentle:tower --lan`); asking for a different mode replaces the running tower with one in that mode. It serves until Ctrl+C or until the session that opened it ends. Hovering anything clickable outlines it and names what a click does; a short tour on the first visit points at the floors, people, rooms, door and top bar, and the `?` button (or the `?` key) shows it again. `/gentle:tower --lan` turns on the same-network mode from a session: the report lists one URL per LAN address and the warning, and the QR code is left to the terminal command, whose text mode prints it under the URLs.

<img width="100%" src="assets/features/gentle-tower.png" alt="Gentle Tower with two floors of the gentle-pi building, their todo bars on the left and the selection strip with Talk, Tasks, Artifacts and Permissions at the bottom">

Expand Down Expand Up @@ -566,9 +566,9 @@ node bin/gentle-shell.mjs --link --package-root "$PWD"

`--link` alone may use the `gentle-pi` already installed in that home, rather than the checkout; `--package-root` explicitly selects the checkout for this linked launch.

The server listens on `127.0.0.1` only, on a random port unless you pick one, with a fresh token as the first path segment on every launch; it refuses other origins. A request from the page is checked and queued to that session's private inbox, and the session runs it itself with its own rules; the web never has more power than the terminal. Set `GENTLE_TOWER=off` to stop a session from publishing.
The server listens on `127.0.0.1` only, on a random port unless you pick one, with a fresh token as the first path segment on every launch; it refuses other origins. With `--lan` it binds every interface instead and serves one URL per LAN address, still token-gated, and an origin is accepted only when it names the exact address the page was served on — a host the launch does not serve is refused, which blocks DNS rebinding. The mode prints a warning because anyone on the network holding the URL can read and drive the sessions over unencrypted HTTP; it is meant for a trusted home network. A request from the page is checked and queued to that session's private inbox, and the session runs it itself with its own rules; the web never has more power than the terminal. Set `GENTLE_TOWER=off` to stop a session from publishing.

The web app is built with Vite, TypeScript and PixiJS into `web/tower/dist`, which ships with the package (`pnpm build:tower` rebuilds it).
The web app is built with Vite, TypeScript and PixiJS into `web/tower/dist`, which ships with the package (`pnpm build:tower` rebuilds it). On a phone or any touch screen the layout adapts: the building scales to the viewport width, the floor cards become a tappable list under it (44px minimum targets, one chip per helper), and the panels dock into a bottom sheet; the transport is SSE, so a dropped Wi-Fi reconnects on its own and the next event re-renders the full snapshot.

### Gentle Music

Expand Down
65 changes: 52 additions & 13 deletions extensions/gentle-tower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
// the desktop agents adapter; it owns no state of its own beyond the file.

import { execFile } from "node:child_process";
import { type NetworkInterfaceInfo } from "node:os";
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
import type { TowerServer } from "../lib/tower-server.ts";
import { openInBrowser, openTowerServer, TOWER_WEB_DIR, TowerNotBuiltError } from "../lib/tower-open.ts";
import { openInBrowser, openTowerServer, TOWER_LAN_WARNING, TOWER_WEB_DIR, TowerNotBuiltError } from "../lib/tower-open.ts";
import { discoverDesktopAgentsService } from "../lib/desktop-agents-service.ts";
import { oddPhaseRegistry } from "../lib/odd-phase.ts";
import { collectSessionStats } from "../lib/shell-stats.ts";
Expand All @@ -24,6 +25,8 @@ export interface TowerPublisherOptions {
now?: () => number;
/** Built web app folder (defaults to the package's web/tower/dist). */
webDir?: string;
/** Network interfaces to enumerate the LAN addresses from (defaults to the OS's). */
interfaces?: NodeJS.Dict<readonly NetworkInterfaceInfo[]>;
/** Opens the tower URL; defaults to the system browser. */
openUrl?: (url: string) => void;
/** How often the session checks its action inbox. */
Expand Down Expand Up @@ -64,6 +67,8 @@ export function createTowerPublisher(pi: ExtensionAPI, options: TowerPublisherOp
const webDir = options.webDir ?? TOWER_WEB_DIR;
const openUrl = options.openUrl ?? openInBrowser;
let server: Promise<TowerServer> | undefined;
/** The mode the current server promise runs in, so a mode change replaces it. */
let serverLan: boolean | undefined;
const debounceMs = options.debounceMs ?? 300;
const now = options.now ?? Date.now;
let ctx: ExtensionContext | undefined;
Expand Down Expand Up @@ -93,6 +98,10 @@ export function createTowerPublisher(pi: ExtensionAPI, options: TowerPublisherOp
const stats = collectSessionStats(branch);
const usage = ctx.getContextUsage?.();
// The agents service keeps finished tasks as history; only live helpers are on the floor.
// SAFETY: the agents service's record shape is not exported, but every field the
// tower reads from it is an optional member of TowerAgentInput consumed defensively
// (String() coercion for status, optional chains elsewhere), so a field it lacks
// degrades to "unknown" instead of breaking the snapshot.
const listed = ((agents?.read().agents ?? []) as unknown as TowerAgentInput[]).filter((a) => LIVE_HELPER.has(String(a.status)));
writeTowerSnapshot(dir, { pid: process.pid, ...buildTowerSnapshot({
sessionId,
Expand Down Expand Up @@ -275,28 +284,58 @@ export function createTowerPublisher(pi: ExtensionAPI, options: TowerPublisherOp
// The tower this session opened ends with it.
const opened = server;
server = undefined;
serverLan = undefined;
void opened?.then((s) => s.close()).catch(() => undefined);
});

// Same startup as `gentle-shell tower`: hub, web app, token, presence, new floors.
// The server is reused while the requested mode matches; a different mode
// closes the running one and starts its replacement.
const ensureTower = (lan: boolean): Promise<TowerServer> => {
if (server !== undefined && serverLan === lan) return server;
const previous = server;
serverLan = lan;
server = openTowerServer(env, { webDir, ...(lan ? { lan: true } : {}), ...(options.interfaces === undefined ? {} : { interfaces: options.interfaces }) });
if (previous !== undefined) void previous.then((s) => s.close()).catch(() => undefined);
return server;
};

const reportTower = async (lan: boolean, notify: (text: string, level: "info" | "warning" | "error") => void): Promise<void> => {
let pending: Promise<TowerServer> | undefined;
try {
pending = ensureTower(lan);
const s = await pending;
// The TUI notify box cannot carry QR art; the terminal command prints it.
const lines = [`Gentle Tower: ${s.url}`, ...s.urls.slice(1).map((u) => ` ${u}`), ...(s.lan ? [TOWER_LAN_WARNING] : [])];
notify(lines.join("\n"), "info");
openUrl(s.url);
} catch (error) {
// Clear only the startup this report owns; a newer command may have replaced it.
if (pending === undefined || server === pending) {
server = undefined;
serverLan = undefined;
}
if (error instanceof TowerNotBuiltError) return notify(error.message, "warning");
notify(`Gentle Tower could not start: ${error instanceof Error ? error.message : String(error)}`, "error");
}
};

pi.registerCommand("gentle:tower", {
description: "Open the Gentle Tower: every Gentle Shell session as a floor, in your browser",
handler: async (args, c) => {
// One flag only: --lan turns on the same-network mode.
await reportTower((args ?? "").trim() === "--lan", (text, level) => c.ui.notify(text, level));
},
});
pi.registerCommand("gentle:tower-mobile", {
description: "Open the Gentle Tower for your phone: the same view served on your network, with a URL to open from the phone",
handler: async (_args, c) => {
// Same startup as `gentle-shell tower`: hub, web app, token, presence, new floors.
server ??= openTowerServer(env, { webDir });
try {
const s = await server;
c.ui.notify(`Gentle Tower: ${s.url}`, "info");
openUrl(s.url);
} catch (error) {
server = undefined;
if (error instanceof TowerNotBuiltError) return c.ui.notify(error.message, "warning");
c.ui.notify(`Gentle Tower could not start: ${error instanceof Error ? error.message : String(error)}`, "error");
}
await reportTower(true, (text, level) => c.ui.notify(text, level));
},
});

return {
close: async () => { const s = server; server = undefined; if (s) await (await s).close(); },
close: async () => { const s = server; server = undefined; serverLan = undefined; if (s) await (await s).close(); },
};
}

Expand Down
24 changes: 17 additions & 7 deletions lib/gentle-shell-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,19 @@ export interface TowerArgs {
port?: number;
/** Print one JSON line (`gentle-shell.tower/v1`) instead of the text lines. */
json?: true;
/** Bind every network interface and serve one URL per LAN address (opt-in). */
lan?: true;
error?: string;
}

// `gentle-shell tower [--no-open] [--port <n>] [--json]`: the server always
// binds 127.0.0.1; --port only fixes which local port; --json is for programs
// (the desktop app) that read the URL instead of a person.
// `gentle-shell tower [--no-open] [--port <n>] [--json] [--lan]`: the server
// binds 127.0.0.1 unless --lan; --port only fixes which local port; --json is
// for programs (the desktop app) that read the URL instead of a person.
export function parseTowerArgs(args: string[]): TowerArgs {
let open = true;
let port: number | undefined;
let json = false;
let lan = false;
for (let i = 0; i < args.length; i += 1) {
const arg = args[i];
if (arg === "--no-open") {
Expand All @@ -205,6 +208,10 @@ export function parseTowerArgs(args: string[]): TowerArgs {
json = true;
continue;
}
if (arg === "--lan") {
lan = true;
continue;
}
if (arg === "--port" || arg.startsWith("--port=")) {
const value = arg === "--port" ? args[(i += 1)] : arg.slice("--port=".length);
if (value === undefined) return { open, error: "--port needs a whole number from 1 to 65535" };
Expand All @@ -215,7 +222,7 @@ export function parseTowerArgs(args: string[]): TowerArgs {
}
return { open, error: `unknown tower argument "${arg}"` };
}
return { open, ...(port === undefined ? {} : { port }), ...(json ? { json: true as const } : {}) };
return { open, ...(port === undefined ? {} : { port }), ...(json ? { json: true as const } : {}), ...(lan ? { lan: true as const } : {}) };
}

// --- home resolution -------------------------------------------------------
Expand Down Expand Up @@ -1380,7 +1387,7 @@ export function helpText(): string {
" gentle-shell memory migrate --confirm-quiescent",
" gentle-shell self-uninstall [--dry-run] [--yes] [--include-shared]",
" gentle-shell desktop [--yes] [--no-open] | --status | --uninstall",
" gentle-shell tower [--no-open] [--port <n>] [--json]",
" gentle-shell tower [--no-open] [--port <n>] [--json] [--lan]",
"",
"Opens pi with the Gentle Shell package loaded, without touching your",
"vanilla pi installation.",
Expand Down Expand Up @@ -1431,8 +1438,11 @@ export function helpText(): string {
" question); --status and --uninstall; 'gentle-shell desktop --help'.",
" tower Open the Gentle Tower outside any session: every open Gentle Shell session",
" as a floor, in your browser. Prints the local URL and serves until Ctrl+C.",
" --no-open only prints the URL; --port <n> fixes the port (127.0.0.1 only);",
" --json prints one JSON line with the URL instead, for programs.",
" --no-open only prints the URL; --port <n> fixes the port (127.0.0.1 only,",
" unless --lan); --json prints one JSON line with the URL instead, for programs.",
" --lan also binds every network interface, to open the view from a",
" phone on the same network: it prints one URL per address, a QR code and a warning;",
" --port then fixes the port on every interface.",
"",
"Managing packages:",
" gentle-shell install npm:<pkg> Run pi's own 'install' against the resolved home.",
Expand Down
Loading