neurastream 0.2.83 → 0.2.84

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/README.md CHANGED
@@ -179,6 +179,8 @@ One setting decides how much Main does without asking: `autonomy.tier` in the co
179
179
 
180
180
  With `ui.enabled: true` and `ui.owner_login` set (`neurastream config`, `docs/config.md`), `neurastream ui` serves one page bound to this machine's tailnet address only (port `ui.port`, default 7787; `templates/systemd/neurastream-ui.service` runs it as a user unit). A sticky top bar holds the "ns" logo, five pill tabs — Now, Queue, Agents, Spend, Base (see "Base tab" below), each a server-rendered view (`/?tab=…`, an unknown value falls back to Now) — and the lock pill ("🔒 Off" / "🔓 12 min") that opens the guard unlock ("Unlock 15 min", "Unlock 30 min", "Lock now"; when `guards.chat_unlock` is off it says so in plain words with the exact config line). Now is the home tab: a Today tile card over the last 24 h (needs-you count in warn color, list-price spend with a sparkline and the Main/agents split, agent runs with running/died counts and a sparkline, open plans), then one card per open `WAITING on owner:` plan that says why it needs him — the plan's `#` title, then Do (what to do), Stuck until then (what stays blocked, including plans this answer unblocks), and Why you (why Main cannot do it), with the goal folded into a Background block. A question ask gets "Yes"/"No"/"Reply…"; a task ask gets "Done". The answer shows as a one-time receipt ("Sent to Main · 08:12"); once the owner inbox already holds an answer for a plan, the card says so ("You answered ‘yes' · 14:19 — Main is on it") with a small change-answer link. The queue is one flat ranked list in `INDEX.md` order. Each card shows the plan title, a two-line summary from the plan's `Summary:` header (one or two plain sentences under Branch; if that line is missing, the first Goal bullet with a leading Owner or INCIDENT prefix cut off), and a status chip — waits you, waits on another plan, not started, phase K of N, or all N done. Drag a card by its ≡ handle, or tap "↑ top"/"↑"/"↓"; the drop rewrites `INDEX.md`, Main gets the move as a message and the page confirms "Moved to #2". Now shows the first 8 rows with a "Show all N ›" link to the Queue tab. The Agents tab lists working-now rows (a run that died before its first reply shows the model from the spawning agent's `model:` frontmatter, never "?"), the agent-score table, open incidents, recent merges/CI and machine health; the Spend tab pairs the spend tile with per-model spend over 24 h. The Now tab also has a "Tell Main" message box for a text note and up to four images; Main receives the text and pictures, and the page keeps a "Sent today" list for 12 hours before removing those messages and their image files. Light and dark follow the OS; there are no external assets and no build step — one server-rendered HTML string, inline CSS and one small inline script under a per-response CSP nonce (`bun scripts/ui-preview.ts <out.html> [--tab <name>]` renders a preview without a server). No chat, no plan editing, no shell.
181
181
 
182
+ When `tailscale ip -4` answers a new address, the server exits within 30 s and its user unit's `Restart=on-failure` starts it on the new address; no manual restart.
183
+
182
184
  A request is served only when the peer is a tailnet address that is neither loopback nor this machine's own tailnet IP, `tailscale whois` names the `ui.owner_login` login — and the Host header is this machine: the tailnet address or the MagicDNS name, with the served port. The Host check runs on every request before whois, and a POST's Origin must match it, so a DNS-rebinding page (foreign Host, matching Origin, owner's phone) gets a 403 like everyone else. `ui.allow_this_machine: true` skips only the two this-machine refusals — loopback and the machine's own tailnet IP are then served as the owner, GET and POST — with the risk in one line: any local process can then press the buttons. Every request logs one `UI <method> <path> login=<l> → <code>` line to the guard log.
183
185
 
184
186
  An answer appends one record to `<queue_state>/owner-inbox.jsonl` (plan, question, answer, login); unlock/lock go through the core unlock and log `UNLOCK ui source=ui:<login> minutes=N`. Main's session delivers each record once as a user message — at turn end and on a 15 s poll while idle — and marks the consumed rows in `<queue_state>/owner-inbox.cursor`; subagent sessions never deliver. Both files sit under the queue state dir, so guards refuse agent writes to them: an agent cannot forge an owner answer. Guards also refuse agent commands that start the page (`neurastream ui`, or `systemctl --user start/restart/enable` of `neurastream-ui`): starting it is the owner's move.
@@ -187,6 +189,8 @@ An answer appends one record to `<queue_state>/owner-inbox.jsonl` (plan, questio
187
189
 
188
190
  `neurastream pages on [--port N] [--dir D]` installs the systemd user unit and serves regular files in the configured pages directory on the tailnet; `pages publish <file> [name] [--force] [--keep]` publishes an artifact and prints its MagicDNS URL, then `expires YYYY-MM-DD` or `kept`. A page without `--keep` is deleted `pages.keep_days` days after publishing (default 15). `pages list` prints each file as `<name> expires YYYY-MM-DD` or `<name> kept`, and `pages off` stops the service. Publish, list, and serve remove expired files first; serve repeats that sweep every hour. Requests are limited to the configured owner's tailnet login or loopback; hidden files, symlinks and paths outside the directory are not served. A published HTML page carries the notes panel `pages publish` injects: `neurastream notes check <page>` exits 1 while any note on it has no answer in `<queue_state>/page-notes/<page>.answers.json`, and `pages publish` refuses that page until the file answers every id; `pages publish <html> <name> --plan <plan.md>` marks the page as a plan's diagram: it then carries an Approve bar that records the plan's text hash in `<queue_state>/plan-approvals.json` and never edits the plan (disabled, and refused with 409, while a note on the page has no answer), and `neurastream diagram check <html> <plan.md>` requires that page to show every phase of the plan and every file or command its phase lines name, with 2+ kids behind every drilldown — `pages publish --plan` runs it, and Approve stays disabled (the server answers 409) until it passes. main-guard refuses a spawn on a plan that has such a page and no approval record whose hash matches the plan's current text. The publish that goes through prints each answer beside its note, archives the closed notes and never reuses an id.
189
191
 
192
+ When `tailscale ip -4` answers a new address, the server exits within 30 s and its user unit's `Restart=on-failure` starts it on the new address; no manual restart.
193
+
190
194
  ## Base tab (`/?tab=knowledge`)
191
195
 
192
196
  The phone page's Base tab (`/?tab=knowledge`) lists the HTML explainers that live next to the code they explain, so a page is versioned with its repo. The convention is the registration: any git repository directly under `knowledge.roots` (`docs/config.md`, default `$HOME/projects` and `$HOME/Work`) that has a `docs/knowledge/<topic>.html` appears — drop a file in, `git pull`, and it shows up on the next reload once the cached list is older than `knowledge.max_age_s` (300 s); no list to edit and nothing to restart. The repo name is the `origin` remote's basename without `.git` (the checkout directory name when there is no remote), and linked worktrees are skipped so one repo appears once however many checkouts it has. The page is a breadcrumb `knowledge-base / <repo> / <topic>`: the pill opens the repo list (name, topic count, newest update), a repo opens its topic cards (title from the page's `<title>`, plus the last commit date that touched the file), and each earlier segment of the breadcrumb links back. Topic pages are served through the pages server behind the same single-user login. The tab is read-only: there is no upload, write, delete or rename route for a topic, and topics change only through git.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neurastream",
3
- "version": "0.2.83",
3
+ "version": "0.2.84",
4
4
  "description": "Guardrails for running many AI coding agents at once: plan queue, blockers, call budgets, provider caps, scoring, merge-verified close.",
5
5
  "keywords": [
6
6
  "ai-agents",
package/src/cli/pages.ts CHANGED
@@ -4,12 +4,12 @@ import { getAdapter } from "../adapters/index.ts";
4
4
  import { loadConfig } from "../core/config.ts";
5
5
  import { beat, errorLine } from "../core/heartbeat.ts";
6
6
  import { readExpiry, sweepPages } from "../core/pages-expiry.ts";
7
- import { startPagesServer } from "../core/pages.ts";
7
+ import { startPagesServer, type PagesServer } from "../core/pages.ts";
8
8
  import { pageNotesGate } from "../core/page-notes.ts";
9
9
  import { pagesOff, pagesOn, publishPage, repoForPublish, type Runner } from "../core/pages-setup.ts";
10
- import { realTailscale, type Tailscale } from "../core/tailscale.ts";
10
+ import { realTailscale, type Tailscale, untilIp4Changes } from "../core/tailscale.ts";
11
11
 
12
- export interface PagesDeps { home?: string; runner?: Runner; tailscale?: Tailscale; clock?: () => Date }
12
+ export interface PagesDeps { home?: string; runner?: Runner; tailscale?: Tailscale; clock?: () => Date; ipPollMs?: number }
13
13
  const HOUR_MS = 60 * 60 * 1000;
14
14
  export async function runPages(args: string[] = [], deps: PagesDeps = {}): Promise<number> {
15
15
  const home = deps.home ?? homedir();
@@ -19,17 +19,19 @@ export async function runPages(args: string[] = [], deps: PagesDeps = {}): Promi
19
19
  if (args[0] === "off" && args.length === 1) return pagesOff({ home, runner: deps.runner });
20
20
  const cfg = loadConfig({ home });
21
21
  if (args[0] === "serve" && args.length === 1) {
22
+ const tailscale = deps.tailscale ?? realTailscale;
23
+ let server: PagesServer;
22
24
  try {
23
25
  if (!cfg.pages.enabled) throw new Error("pages.enabled is false");
24
26
  sweepPages(cfg.pages.dir, cfg.pages.keep_days, clock());
25
- startPagesServer({ cfg, tailscale: deps.tailscale ?? realTailscale, source: getAdapter(cfg).runSource(cfg) });
27
+ server = startPagesServer({ cfg, tailscale, source: getAdapter(cfg).runSource(cfg) });
26
28
  } catch (e) {
27
29
  beat(cfg, "pages-serve", { ok: false, detail: errorLine(e) });
28
30
  throw e;
29
31
  }
30
32
  beat(cfg, "pages-serve", { ok: true });
31
33
  setInterval(() => { try { sweepPages(cfg.pages.dir, cfg.pages.keep_days, clock()); } catch (e) { console.error(e instanceof Error ? e.message : String(e)); } }, HOUR_MS);
32
- return new Promise<number>(() => {});
34
+ return untilIp4Changes(tailscale, server.hostname, deps.ipPollMs);
33
35
  }
34
36
  if (args[0] === "publish" && args[1]) {
35
37
  let force = false, keep = false, plan: string | undefined, repo: string | undefined;
package/src/cli/ui.ts CHANGED
@@ -9,7 +9,7 @@ import { ConfigError, loadConfig, type Config } from "../core/config.ts";
9
9
  import { beat, errorLine } from "../core/heartbeat.ts";
10
10
  import { startOwnerUi, type OwnerUiOptions, type OwnerUiServer } from "../core/owner-ui.ts";
11
11
  import { applyQueueEnv } from "../core/queue/env.ts";
12
- import { realTailscale, type Tailscale } from "../core/tailscale.ts";
12
+ import { realTailscale, type Tailscale, untilIp4Changes } from "../core/tailscale.ts";
13
13
  import { systemTerminal, uiOff, uiOn, type Runner } from "../core/ui-setup.ts";
14
14
 
15
15
  export interface UiDeps {
@@ -19,10 +19,12 @@ export interface UiDeps {
19
19
  start?: (opts: OwnerUiOptions) => OwnerUiServer;
20
20
  /** Command runner for `ui on`/`ui off` (default: spawnSync of systemctl --user). */
21
21
  runner?: Runner;
22
- /** Tailscale seam for `ui on` (default: realTailscale). */
22
+ /** Tailscale seam for `ui on` and the serve path (default: realTailscale). */
23
23
  tailscale?: Tailscale;
24
24
  /** HOME the `ui on`/`ui off` config and unit paths resolve against (default: homedir()). */
25
25
  home?: string;
26
+ /** How often the serve path checks for a new tailnet address (default: IP4_POLL_MS). */
27
+ ipPollMs?: number;
26
28
  }
27
29
 
28
30
  const UI_USAGE = "usage: neurastream ui [on --login <tailscale login> [--port N] | off]";
@@ -87,14 +89,16 @@ export async function runUi(args: string[] = [], deps: UiDeps = {}): Promise<num
87
89
  console.error("neurastream ui: ui.owner_login is empty — set the tailscale login that may open the page");
88
90
  return 1;
89
91
  }
92
+ const tailscale = deps.tailscale ?? realTailscale;
93
+ let server: OwnerUiServer;
90
94
  try {
91
- (deps.start ?? startOwnerUi)({ cfg, tailscale: realTailscale, source: getAdapter(cfg).runSource(cfg) });
95
+ server = (deps.start ?? startOwnerUi)({ cfg, tailscale, source: getAdapter(cfg).runSource(cfg) });
92
96
  } catch (e) {
93
97
  beat(cfg, "ui", { ok: false, detail: errorLine(e) });
94
98
  throw e;
95
99
  }
96
100
  beat(cfg, "ui", { ok: true });
97
- // src/cli/main.ts exits with the code this returns, which would kill the server: serving
98
- // never resolves, and the process runs until systemd or a signal stops it.
99
- return new Promise<number>(() => {});
101
+ // Resolves 1 when the tailnet address moves: src/cli/main.ts exits with it, which would end the
102
+ // server, and systemd restarts it on the new address. Otherwise serving runs until systemd or a signal stops it.
103
+ return untilIp4Changes(tailscale, server.hostname, deps.ipPollMs);
100
104
  }
@@ -26,6 +26,31 @@ function firstStdoutLine(args: string[]): string | null {
26
26
  return line || null;
27
27
  }
28
28
 
29
+ /** How often the servers check whether `tailscale ip -4` moved to another address. */
30
+ export const IP4_POLL_MS = 30_000;
31
+
32
+ function isIpv4(answer: string | null): answer is string {
33
+ const octets = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(answer ?? "");
34
+ return octets !== null && octets.slice(1).every(o => Number(o) <= 255);
35
+ }
36
+
37
+ /**
38
+ * Resolves 1 once `tailscale ip -4` answers a different IPv4 address than `bound`, after printing why
39
+ * to stderr; the caller exits so the service manager restarts it on the new address. Any other answer
40
+ * (the same address, null, or a status-0 line such as "Logged out.") keeps it serving.
41
+ */
42
+ export function untilIp4Changes(tailscale: Tailscale, bound: string, everyMs = IP4_POLL_MS): Promise<number> {
43
+ const { promise, resolve } = Promise.withResolvers<number>();
44
+ const timer = setInterval(() => {
45
+ const now = tailscale.ip4();
46
+ if (!isIpv4(now) || now === bound) return;
47
+ clearInterval(timer);
48
+ console.error(`tailnet address changed ${bound} → ${now}; exiting so the service manager restarts on the new address`);
49
+ resolve(1);
50
+ }, everyMs);
51
+ return promise;
52
+ }
53
+
29
54
  /** The login in `tailscale whois --json` output: multi-line JSON with the login at `UserProfile.LoginName`. Null when absent or unparseable. */
30
55
  export function parseWhoisLogin(stdout: string): string | null {
31
56
  try {