neurastream 0.2.86 → 0.3.1
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 +22 -7
- package/package.json +1 -1
- package/src/adapters/omp/doctor.ts +10 -3
- package/src/adapters/omp/index.ts +21 -5
- package/src/cli/claim.ts +48 -17
- package/src/cli/dispatch.ts +23 -8
- package/src/cli/setup.ts +3 -3
- package/src/cli/team.ts +311 -0
- package/src/cli/workspace.ts +235 -0
- package/src/core/claims.ts +29 -11
- package/src/core/config.ts +16 -5
- package/src/core/guards.ts +182 -46
- package/src/core/incident-detectors.ts +1 -1
- package/src/core/mr-sweep.ts +33 -6
- package/src/core/owner-ui.ts +353 -132
- package/src/core/pages.ts +1 -1
- package/src/core/queue/lib.ts +23 -9
- package/src/core/queue-check.ts +5 -3
- package/src/core/queue-close.ts +3 -3
- package/src/core/team-client.ts +813 -0
- package/src/core/team-labels.ts +127 -0
- package/src/core/team-server.ts +1008 -0
- package/src/core/ui-setup.ts +186 -41
- package/templates/config.yml +5 -3
- package/templates/queue/TEMPLATE.md +2 -0
- package/templates/systemd/neurastream-workspace.service +14 -0
- package/src/cli/ui.ts +0 -104
- package/templates/systemd/neurastream-ui.service +0 -16
package/src/core/ui-setup.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
// `neurastream
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// `neurastream workspace on|off` core: one command sets workspace.enabled / workspace.owner_login
|
|
2
|
+
// (and workspace.port) in the user's config.yml, installs the systemd user unit, starts it and
|
|
3
|
+
// prints the phone link; `off` stops the unit and sets workspace.enabled back to false. Pure over
|
|
4
|
+
// an injected command runner and the Tailscale seam (src/cli/workspace.ts wires the real ones), so
|
|
5
|
+
// tests record argv and never run systemctl or the tailscale binary.
|
|
6
|
+
// (The command and keys were `ui` before the workspace rename; an existing `ui:` block moves to
|
|
7
|
+
// `workspace:` in loadConfig's migrateLegacy, and `on` retires the old neurastream-ui unit.)
|
|
6
8
|
|
|
7
9
|
import { spawnSync } from "node:child_process";
|
|
8
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
9
11
|
import { homedir } from "node:os";
|
|
10
12
|
import { dirname, join } from "node:path";
|
|
11
13
|
import { fileURLToPath } from "node:url";
|
|
12
|
-
import { ConfigError, configFile, loadConfig } from "./config.ts";
|
|
14
|
+
import { ConfigError, type Config, configFile, loadConfig } from "./config.ts";
|
|
13
15
|
import { realTailscale, type Tailscale } from "./tailscale.ts";
|
|
14
16
|
import { checkEdited, setConfigKeys } from "./config-edit.ts";
|
|
17
|
+
import { TEAM_NAME_HINT, TEAM_NAME_RE, repoListError } from "./team-labels.ts";
|
|
15
18
|
|
|
16
19
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
17
|
-
export const UI_UNIT_TEMPLATE = join(HERE, "../../templates/systemd/neurastream-
|
|
20
|
+
export const UI_UNIT_TEMPLATE = join(HERE, "../../templates/systemd/neurastream-workspace.service");
|
|
18
21
|
|
|
19
22
|
export interface RunnerResult {
|
|
20
23
|
status: number | null;
|
|
@@ -48,7 +51,7 @@ export const systemTerminal: Terminal = {
|
|
|
48
51
|
};
|
|
49
52
|
|
|
50
53
|
const TAILSCALE_DOWNLOAD = "https://tailscale.com/download";
|
|
51
|
-
const TAILSCALE_MISSING = "The phone page needs Tailscale (free, private network for your devices). Install it: Linux `curl -fsSL https://tailscale.com/install.sh | sh` (asks for your password), macOS: the App Store app, others: https://tailscale.com/download. Then run `neurastream
|
|
54
|
+
const TAILSCALE_MISSING = "The phone page needs Tailscale (free, private network for your devices). Install it: Linux `curl -fsSL https://tailscale.com/install.sh | sh` (asks for your password), macOS: the App Store app, others: https://tailscale.com/download. Then run `neurastream workspace on` again.";
|
|
52
55
|
const TAILSCALE_STOPPED = "Tailscale is installed but not connected. Run `sudo tailscale up` (Linux) or open the Tailscale app (macOS), then run this again.";
|
|
53
56
|
export { TAILSCALE_MISSING, TAILSCALE_STOPPED };
|
|
54
57
|
|
|
@@ -59,34 +62,129 @@ export interface UiSetupOptions {
|
|
|
59
62
|
runner?: Runner;
|
|
60
63
|
/** Tailscale seam. Default: realTailscale. */
|
|
61
64
|
tailscale?: Tailscale;
|
|
65
|
+
/** The personal owner page (default) or one team's page and queue server. */
|
|
66
|
+
scope?: Scope;
|
|
62
67
|
print?: (line: string) => void;
|
|
63
68
|
error?: (line: string) => void;
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
/** Which page a command sets up: the personal owner page, or the named team's page and queue server. */
|
|
72
|
+
export type Scope = { kind: "personal" } | { kind: "team"; name: string };
|
|
73
|
+
export const PERSONAL: Scope = { kind: "personal" };
|
|
74
|
+
|
|
66
75
|
export interface UiOnOptions extends UiSetupOptions {
|
|
67
|
-
|
|
68
|
-
|
|
76
|
+
/** Personal scope: the tailnet login that may open the page (required). */
|
|
77
|
+
login?: string;
|
|
78
|
+
/** Team scope: the tailnet login of the team's admin (required, checked against the tailnet). */
|
|
79
|
+
admin?: string;
|
|
80
|
+
/** Team scope: the repo globs the team's server serves (required, each checked by repoListError). */
|
|
81
|
+
repos?: string[];
|
|
82
|
+
/** The --port N of the command line; null leaves the config's workspace.port in place (personal) or the default (team). */
|
|
69
83
|
port?: number | null;
|
|
70
|
-
/** Terminal seam for the missing-tailscale question. Absent: no question, only the message. src/cli/
|
|
84
|
+
/** Terminal seam for the missing-tailscale question. Absent: no question, only the message. src/cli/workspace.ts passes the real one on a TTY. */
|
|
71
85
|
terminal?: Terminal;
|
|
72
86
|
}
|
|
73
87
|
|
|
88
|
+
/** One team's persisted server settings: `team-<name>.json` beside config.yml, written 0600. */
|
|
89
|
+
export interface TeamServerFile {
|
|
90
|
+
team: string;
|
|
91
|
+
admin: string;
|
|
92
|
+
leader: string;
|
|
93
|
+
repos: string[];
|
|
94
|
+
members: string[];
|
|
95
|
+
port: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function unitName(scope: Scope): string {
|
|
99
|
+
return scope.kind === "personal" ? "neurastream-workspace" : `neurastream-team-${scope.name}`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function teamServerFile(home: string, name: string): string {
|
|
103
|
+
return join(dirname(configFile(home)), `team-${name}.json`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The team names that have a settings file on this machine, so the personal page can refuse to run beside them. */
|
|
107
|
+
export function teamServerNames(home: string): string[] {
|
|
108
|
+
const dir = dirname(configFile(home));
|
|
109
|
+
if (!existsSync(dir)) return [];
|
|
110
|
+
return readdirSync(dir)
|
|
111
|
+
.filter(f => /^team-.+\.json$/.test(f))
|
|
112
|
+
.map(f => f.slice("team-".length, -".json".length));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Reads one team's settings file; null when it does not exist. A file that does not parse or lacks a field throws. */
|
|
116
|
+
export function readTeamServerFile(home: string, name: string): TeamServerFile | null {
|
|
117
|
+
const file = teamServerFile(home, name);
|
|
118
|
+
if (!existsSync(file)) return null;
|
|
119
|
+
const data = JSON.parse(readFileSync(file, "utf8")) as Partial<TeamServerFile>;
|
|
120
|
+
const ok = typeof data.team === "string" && typeof data.admin === "string" && typeof data.leader === "string"
|
|
121
|
+
&& Array.isArray(data.repos) && Array.isArray(data.members) && typeof data.port === "number";
|
|
122
|
+
if (!ok) throw new Error(`team settings ${file} is missing a field; run \`neurastream workspace off --team ${name}\` and set it up again`);
|
|
123
|
+
return data as TeamServerFile;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Writes one team's settings through a tmp file and a rename, so a crash never leaves half a file. */
|
|
127
|
+
export function writeTeamServerFile(home: string, name: string, data: TeamServerFile): void {
|
|
128
|
+
const file = teamServerFile(home, name);
|
|
129
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
130
|
+
const tmp = `${file}.tmp`;
|
|
131
|
+
writeFileSync(tmp, `${JSON.stringify(data, null, 2)}\n`, { mode: 0o600 });
|
|
132
|
+
renameSync(tmp, file);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The team's queue database: one SQLite file per team under the queue state dir, kept across off/on. */
|
|
136
|
+
export function teamDbPath(cfg: Config, name: string): string {
|
|
137
|
+
return join(cfg.paths.queue_state, "team-server", `${name}.sqlite`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The team unit is the personal page's template with `--team <name>` on ExecStart and the team named in its description. */
|
|
141
|
+
export function teamUnitText(template: string, team: string): string {
|
|
142
|
+
const exec = /^ExecStart=%h\/\.bun\/bin\/neurastream workspace$/m;
|
|
143
|
+
if (!exec.test(template)) throw new Error("the workspace unit template has no `ExecStart=… neurastream workspace` line");
|
|
144
|
+
return template
|
|
145
|
+
.replace(exec, `ExecStart=%h/.bun/bin/neurastream workspace --team ${team}`)
|
|
146
|
+
.replace(/^Description=(.*)$/m, `Description=$1 — team ${team}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
74
149
|
export function uiOn(opts: UiOnOptions): number {
|
|
75
150
|
const home = opts.home ?? homedir();
|
|
76
151
|
const runner = opts.runner ?? systemRunner;
|
|
77
152
|
const tailscale = opts.tailscale ?? realTailscale;
|
|
78
153
|
const print = opts.print ?? console.log;
|
|
79
154
|
const error = opts.error ?? console.error;
|
|
155
|
+
const scope = opts.scope ?? PERSONAL;
|
|
156
|
+
// Argument checks come first: a refused call reads, writes and runs nothing.
|
|
157
|
+
if (scope.kind === "team") {
|
|
158
|
+
if (!TEAM_NAME_RE.test(scope.name)) {
|
|
159
|
+
error(`neurastream workspace: ${TEAM_NAME_HINT}`);
|
|
160
|
+
return 2;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const who = scope.kind === "team" ? opts.admin : opts.login;
|
|
164
|
+
if (!who) {
|
|
165
|
+
error(scope.kind === "team"
|
|
166
|
+
? "neurastream workspace on --team: --admin <tailscale login> is required — e.g. neurastream workspace on --team <name> --admin me@example.com --repo github.com/acme/*"
|
|
167
|
+
: "neurastream workspace on: --login <tailscale login> is required — e.g. neurastream workspace on --login me@example.com");
|
|
168
|
+
return 1;
|
|
169
|
+
}
|
|
170
|
+
const repos = opts.repos ?? [];
|
|
171
|
+
if (scope.kind === "team") {
|
|
172
|
+
const repoErr = repoListError(repos);
|
|
173
|
+
if (repoErr) {
|
|
174
|
+
error(`neurastream workspace on --team: ${repoErr}`);
|
|
175
|
+
return 1;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
80
178
|
// Tailscale comes first (plan 20261028_2356 P2): nothing is read, written or run unless it is up.
|
|
81
179
|
const state = tailscale.state();
|
|
82
180
|
if (state === "missing") {
|
|
83
|
-
error(`neurastream
|
|
181
|
+
error(`neurastream workspace: ${TAILSCALE_MISSING}`);
|
|
84
182
|
const terminal = opts.terminal;
|
|
85
183
|
if (terminal && terminal.ask("Open the Tailscale download page now? [y/N] ").trim().toLowerCase() === "y") terminal.open(TAILSCALE_DOWNLOAD);
|
|
86
184
|
return 1;
|
|
87
185
|
}
|
|
88
186
|
if (state === "stopped") {
|
|
89
|
-
error(`neurastream
|
|
187
|
+
error(`neurastream workspace: ${TAILSCALE_STOPPED}`);
|
|
90
188
|
return 1;
|
|
91
189
|
}
|
|
92
190
|
const file = configFile(home);
|
|
@@ -97,47 +195,83 @@ export function uiOn(opts: UiOnOptions): number {
|
|
|
97
195
|
error(err instanceof ConfigError ? err.message : String(err));
|
|
98
196
|
return 1;
|
|
99
197
|
}
|
|
198
|
+
// A team server and the personal page never run together on one machine: each side refuses the other.
|
|
199
|
+
if (scope.kind === "personal") {
|
|
200
|
+
const teams = teamServerNames(home);
|
|
201
|
+
if (teams.length > 0) {
|
|
202
|
+
error(`neurastream workspace: team server "${teams[0]}" is set up on this machine; the personal page and a team server cannot run together. Run \`neurastream workspace off --team ${teams[0]}\` first.`);
|
|
203
|
+
return 1;
|
|
204
|
+
}
|
|
205
|
+
} else if (cfg.workspace.enabled) {
|
|
206
|
+
error("neurastream workspace: the personal page is on; run `neurastream workspace off` before setting up a team server.");
|
|
207
|
+
return 1;
|
|
208
|
+
}
|
|
100
209
|
const logins = tailscale.logins();
|
|
101
210
|
if (logins === null) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
211
|
+
// A team admin is a security boundary, so the team path fails closed; the personal page keeps its skip-with-warning.
|
|
212
|
+
if (scope.kind === "team") {
|
|
213
|
+
error("neurastream workspace: cannot read the tailnet logins (`tailscale status --json` failed); a team admin must be verified, so nothing was changed.");
|
|
214
|
+
return 1;
|
|
215
|
+
}
|
|
216
|
+
error("neurastream workspace: cannot read the tailnet logins (`tailscale status --json` failed) — skipping the login check");
|
|
217
|
+
} else if (!logins.includes(who)) {
|
|
218
|
+
error(`neurastream workspace: ${who} is not a login on this tailnet. Logins seen: ${logins.join(", ")}`);
|
|
105
219
|
return 1;
|
|
106
220
|
}
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
221
|
+
const port = typeof opts.port === "number" ? opts.port : cfg.workspace.port;
|
|
222
|
+
let edited = "";
|
|
223
|
+
if (scope.kind === "personal") {
|
|
224
|
+
const original = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
225
|
+
const values: Record<string, string> = { "workspace.enabled": "true", "workspace.owner_login": who };
|
|
226
|
+
if (typeof opts.port === "number") values["workspace.port"] = String(opts.port);
|
|
227
|
+
try {
|
|
228
|
+
edited = setConfigKeys(original, values);
|
|
229
|
+
} catch (err) {
|
|
230
|
+
error(err instanceof ConfigError ? err.message : String(err));
|
|
231
|
+
return 1;
|
|
232
|
+
}
|
|
233
|
+
if (!checkEdited(edited, home, error)) return 1;
|
|
234
|
+
// The page's unit was neurastream-ui before the workspace rename: retire it first. A machine that never
|
|
235
|
+
// had it still succeeds; an installed unit that cannot be stopped would keep running beside the new one.
|
|
236
|
+
const oldUnit = join(home, ".config", "systemd", "user", "neurastream-ui.service");
|
|
237
|
+
const retire = runner(["systemctl", "--user", "disable", "--now", "neurastream-ui"]);
|
|
238
|
+
if (retire.status !== 0 && existsSync(oldUnit)) {
|
|
239
|
+
if (retire.stderr.trim()) error(retire.stderr.trimEnd());
|
|
240
|
+
error("neurastream workspace: could not stop the old neurastream-ui unit — the workspace was not turned on; fix it (systemctl --user disable --now neurastream-ui) and run this command again.");
|
|
241
|
+
return 1;
|
|
242
|
+
}
|
|
243
|
+
if (existsSync(oldUnit)) unlinkSync(oldUnit);
|
|
116
244
|
}
|
|
117
|
-
|
|
118
|
-
const unitPath = join(home, ".config", "systemd", "user",
|
|
245
|
+
const unit = unitName(scope);
|
|
246
|
+
const unitPath = join(home, ".config", "systemd", "user", `${unit}.service`);
|
|
119
247
|
mkdirSync(dirname(unitPath), { recursive: true });
|
|
120
|
-
copyFileSync(UI_UNIT_TEMPLATE, unitPath);
|
|
248
|
+
if (scope.kind === "personal") copyFileSync(UI_UNIT_TEMPLATE, unitPath);
|
|
249
|
+
else writeFileSync(unitPath, teamUnitText(readFileSync(UI_UNIT_TEMPLATE, "utf8"), scope.name));
|
|
121
250
|
for (const args of [
|
|
122
251
|
["systemctl", "--user", "daemon-reload"],
|
|
123
|
-
["systemctl", "--user", "enable",
|
|
124
|
-
["systemctl", "--user", "restart",
|
|
252
|
+
["systemctl", "--user", "enable", unit],
|
|
253
|
+
["systemctl", "--user", "restart", unit],
|
|
125
254
|
]) {
|
|
126
255
|
const r = runner(args);
|
|
127
256
|
if (r.status !== 0) {
|
|
128
257
|
if (r.stderr.trim()) error(r.stderr.trimEnd());
|
|
129
|
-
error("neurastream
|
|
258
|
+
error("neurastream workspace: systemctl failed — the config was not changed; fix the unit and run `neurastream workspace` (or this command again).");
|
|
130
259
|
return 1;
|
|
131
260
|
}
|
|
132
261
|
}
|
|
133
|
-
// The config only
|
|
134
|
-
// exactly as it was (a leftover unit file is fine).
|
|
135
|
-
|
|
136
|
-
|
|
262
|
+
// The config (personal) or the team's settings file only changes once the unit is up: a systemctl
|
|
263
|
+
// failure leaves it exactly as it was (a leftover unit file is fine).
|
|
264
|
+
if (scope.kind === "personal") {
|
|
265
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
266
|
+
writeFileSync(file, edited);
|
|
267
|
+
} else {
|
|
268
|
+
// The leader starts as the admin; members start empty and are added with `workspace members add`.
|
|
269
|
+
writeTeamServerFile(home, scope.name, { team: scope.name, admin: who, leader: who, repos, members: [], port });
|
|
270
|
+
}
|
|
137
271
|
const name = tailscale.dnsName() ?? tailscale.ip4();
|
|
138
|
-
const port = opts.port ?? cfg.ui.port;
|
|
139
272
|
if (name) print(`http://${name}:${port}`);
|
|
140
|
-
else error("neurastream
|
|
273
|
+
else error("neurastream workspace: could not read this machine's MagicDNS name or tailnet address (is tailscale up?) — the page is running, open it at http://<MagicDNS name>:" + port);
|
|
274
|
+
if (scope.kind === "team") print(`team ${scope.name}: admin ${who}. Add members: neurastream workspace members add <login> --team ${scope.name}`);
|
|
141
275
|
return 0;
|
|
142
276
|
}
|
|
143
277
|
|
|
@@ -145,15 +279,26 @@ export function uiOff(opts: UiSetupOptions): number {
|
|
|
145
279
|
const home = opts.home ?? homedir();
|
|
146
280
|
const runner = opts.runner ?? systemRunner;
|
|
147
281
|
const error = opts.error ?? console.error;
|
|
148
|
-
const
|
|
282
|
+
const scope = opts.scope ?? PERSONAL;
|
|
283
|
+
if (scope.kind === "team" && !TEAM_NAME_RE.test(scope.name)) {
|
|
284
|
+
error(`neurastream workspace: ${TEAM_NAME_HINT}`);
|
|
285
|
+
return 2;
|
|
286
|
+
}
|
|
287
|
+
const r = runner(["systemctl", "--user", "disable", "--now", unitName(scope)]);
|
|
149
288
|
if (r.status !== 0) {
|
|
150
289
|
if (r.stderr.trim()) error(r.stderr.trimEnd());
|
|
151
|
-
error("neurastream
|
|
290
|
+
error("neurastream workspace: systemctl failed — the config was not touched.");
|
|
152
291
|
return 1;
|
|
153
292
|
}
|
|
293
|
+
if (scope.kind === "team") {
|
|
294
|
+
// The team's database stays, so `on --team` again brings the same queue back; only its settings file goes.
|
|
295
|
+
const file = teamServerFile(home, scope.name);
|
|
296
|
+
if (existsSync(file)) unlinkSync(file);
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
154
299
|
const file = configFile(home);
|
|
155
300
|
if (existsSync(file)) {
|
|
156
|
-
const edited = setConfigKeys(readFileSync(file, "utf8"), { "
|
|
301
|
+
const edited = setConfigKeys(readFileSync(file, "utf8"), { "workspace.enabled": "false" });
|
|
157
302
|
if (!checkEdited(edited, home, error)) return 1;
|
|
158
303
|
writeFileSync(file, edited);
|
|
159
304
|
}
|
package/templates/config.yml
CHANGED
|
@@ -169,12 +169,14 @@ review: # plan review gate (plan 20261028_1600): reuse lines
|
|
|
169
169
|
approval: # plan approval hard gate (plan 20261029_1455 P3): docs/config.md
|
|
170
170
|
since: "" # a plan stamped at or after this (YYYYMMDD_HHMM) needs a page and an approval record; "" = off
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
enabled: false # the owner's phone page (neurastream
|
|
174
|
-
port: 7787 # owner page port (neurastream
|
|
172
|
+
workspace:
|
|
173
|
+
enabled: false # the owner's phone page (neurastream workspace); binds the tailnet address only
|
|
174
|
+
port: 7787 # owner page port (neurastream workspace)
|
|
175
175
|
owner_login: "" # the tailscale login that may open the page; empty = the page refuses to start
|
|
176
176
|
allow_this_machine: false # admit this machine (loopback and its own tailnet IP) as the owner; any local process can then press the buttons
|
|
177
177
|
|
|
178
|
+
teams: [] # [{name, server, repos: ["host/group/*"]}] origin globs (host/path, no .git; * does not cross /) that may share plans carrying Queue: team. Empty = every repo is personal. Two teams must not match the same remote.
|
|
179
|
+
|
|
178
180
|
|
|
179
181
|
pages:
|
|
180
182
|
enabled: false # the pages server (neurastream pages on|off)
|
|
@@ -4,6 +4,8 @@ Worktree: <work root>/<repo>-<topic> (configure paths.work_roots, e.g. {{HOME}}/
|
|
|
4
4
|
bare `Planner: <agent>` line above the first `##` (no trailing comment). Omit it while Main plans. -->
|
|
5
5
|
Branch: <type>/<topic>
|
|
6
6
|
Summary: <one or two plain sentences: what this plan gives the owner>
|
|
7
|
+
Queue: personal
|
|
8
|
+
<!-- `team` opts this plan into the team queue for the team its repo's origin matches (config `teams:`). Absent or `personal` never leaves this machine. `neurastream team share <plan>` writes `team`; `team unshare <plan>` removes the line (only while you hold the claim, or the plan is unclaimed). -->
|
|
7
9
|
PRIORITY-ID: <optional, e.g. PR01>
|
|
8
10
|
<!-- One plan = one worktree: this file lives in the main checkout (<main checkout>/docs/plans/), never
|
|
9
11
|
inside its worktree, and the main index (paths.queue_index) lists its absolute path, one line per plan. -->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# User unit for the owner's phone page (neurastream workspace). `neurastream workspace on --login <email>`
|
|
2
|
+
# copies this into ~/.config/systemd/user/ and enables + restarts it; `neurastream workspace off`
|
|
3
|
+
# stops and disables it. Agents never install or start it — that is the owner's move, refused
|
|
4
|
+
# by the guards. (The unit was neurastream-ui.service before the workspace rename; `workspace on`
|
|
5
|
+
# disables the old unit and removes its file when one is installed.)
|
|
6
|
+
|
|
7
|
+
[Unit]
|
|
8
|
+
Description=neurastream owner page (neurastream workspace)
|
|
9
|
+
After=network-online.target
|
|
10
|
+
|
|
11
|
+
[Service]
|
|
12
|
+
ExecStart=%h/.bun/bin/neurastream workspace
|
|
13
|
+
Restart=on-failure
|
|
14
|
+
RestartSec=5
|
package/src/cli/ui.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// `neurastream ui`: serve the owner's phone page on the tailnet address only. Refuses to start
|
|
2
|
-
// when the config has the page off or no owner login; the core startOwnerUi enforces the same
|
|
3
|
-
// two refusals. Runs until killed (systemd user unit templates/systemd/neurastream-ui.service).
|
|
4
|
-
// `ui on --login <email> [--port N]` / `ui off` set up and undo that whole setup in one command
|
|
5
|
-
// (the core lives in src/core/ui-setup.ts); plain `neurastream ui` keeps serving as today.
|
|
6
|
-
|
|
7
|
-
import { getAdapter } from "../adapters/index.ts";
|
|
8
|
-
import { ConfigError, loadConfig, type Config } from "../core/config.ts";
|
|
9
|
-
import { beat, errorLine } from "../core/heartbeat.ts";
|
|
10
|
-
import { startOwnerUi, type OwnerUiOptions, type OwnerUiServer } from "../core/owner-ui.ts";
|
|
11
|
-
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
12
|
-
import { realTailscale, type Tailscale, untilIp4Changes } from "../core/tailscale.ts";
|
|
13
|
-
import { systemTerminal, uiOff, uiOn, type Runner } from "../core/ui-setup.ts";
|
|
14
|
-
|
|
15
|
-
export interface UiDeps {
|
|
16
|
-
/** The merged config. Default: loadConfig(). */
|
|
17
|
-
cfg?: Config;
|
|
18
|
-
/** Starts the page. Default: startOwnerUi. */
|
|
19
|
-
start?: (opts: OwnerUiOptions) => OwnerUiServer;
|
|
20
|
-
/** Command runner for `ui on`/`ui off` (default: spawnSync of systemctl --user). */
|
|
21
|
-
runner?: Runner;
|
|
22
|
-
/** Tailscale seam for `ui on` and the serve path (default: realTailscale). */
|
|
23
|
-
tailscale?: Tailscale;
|
|
24
|
-
/** HOME the `ui on`/`ui off` config and unit paths resolve against (default: homedir()). */
|
|
25
|
-
home?: string;
|
|
26
|
-
/** How often the serve path checks for a new tailnet address (default: IP4_POLL_MS). */
|
|
27
|
-
ipPollMs?: number;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const UI_USAGE = "usage: neurastream ui [on --login <tailscale login> [--port N] | off]";
|
|
31
|
-
|
|
32
|
-
// `ui on|off` argument handling: --login is required for on (exit 1, nothing done without it),
|
|
33
|
-
// --port optional; anything else is a usage error (exit 2). No args reaches the serve path.
|
|
34
|
-
function runUiSetup(args: string[], deps: UiDeps): number {
|
|
35
|
-
const on = args[0] === "on";
|
|
36
|
-
let login: string | undefined;
|
|
37
|
-
let port: number | null = null;
|
|
38
|
-
for (let i = 1; i < args.length; i++) {
|
|
39
|
-
if (on && args[i] === "--login") {
|
|
40
|
-
login = args[i + 1];
|
|
41
|
-
i++;
|
|
42
|
-
} else if (on && args[i] === "--port") {
|
|
43
|
-
const n = Number(args[i + 1]);
|
|
44
|
-
if (!Number.isInteger(n) || n! <= 0 || n! > 65535) {
|
|
45
|
-
console.error(`neurastream ui on: --port needs a port number (1..65535), got "${args[i + 1] ?? ""}"`);
|
|
46
|
-
return 2;
|
|
47
|
-
}
|
|
48
|
-
port = n;
|
|
49
|
-
i++;
|
|
50
|
-
} else {
|
|
51
|
-
console.error(UI_USAGE);
|
|
52
|
-
return 2;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const setup = { home: deps.home, runner: deps.runner, tailscale: deps.tailscale };
|
|
56
|
-
if (on) {
|
|
57
|
-
if (!login) {
|
|
58
|
-
console.error("neurastream ui on: --login <tailscale login> is required — e.g. neurastream ui on --login me@example.com");
|
|
59
|
-
return 1;
|
|
60
|
-
}
|
|
61
|
-
// A question only on a terminal: scripted runs get the message and exit 1, no prompt.
|
|
62
|
-
const terminal = process.stdin.isTTY && process.stdout.isTTY ? systemTerminal : undefined;
|
|
63
|
-
return uiOn({ login, port, terminal, ...setup });
|
|
64
|
-
}
|
|
65
|
-
return uiOff(setup);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function runUi(args: string[] = [], deps: UiDeps = {}): Promise<number> {
|
|
69
|
-
if (args[0] === "on" || args[0] === "off") return runUiSetup(args, deps);
|
|
70
|
-
if (args.length) {
|
|
71
|
-
console.error(UI_USAGE);
|
|
72
|
-
return 2;
|
|
73
|
-
}
|
|
74
|
-
let cfg = deps.cfg;
|
|
75
|
-
if (!cfg) {
|
|
76
|
-
try {
|
|
77
|
-
cfg = loadConfig();
|
|
78
|
-
} catch (err) {
|
|
79
|
-
console.error(err instanceof ConfigError ? err.message : String(err));
|
|
80
|
-
return 1;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
applyQueueEnv(cfg);
|
|
84
|
-
if (!cfg.ui.enabled) {
|
|
85
|
-
console.error("neurastream ui: ui.enabled is false — set it in the config first");
|
|
86
|
-
return 1;
|
|
87
|
-
}
|
|
88
|
-
if (!cfg.ui.owner_login) {
|
|
89
|
-
console.error("neurastream ui: ui.owner_login is empty — set the tailscale login that may open the page");
|
|
90
|
-
return 1;
|
|
91
|
-
}
|
|
92
|
-
const tailscale = deps.tailscale ?? realTailscale;
|
|
93
|
-
let server: OwnerUiServer;
|
|
94
|
-
try {
|
|
95
|
-
server = (deps.start ?? startOwnerUi)({ cfg, tailscale, source: getAdapter(cfg).runSource(cfg) });
|
|
96
|
-
} catch (e) {
|
|
97
|
-
beat(cfg, "ui", { ok: false, detail: errorLine(e) });
|
|
98
|
-
throw e;
|
|
99
|
-
}
|
|
100
|
-
beat(cfg, "ui", { ok: true });
|
|
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);
|
|
104
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# User unit for the owner's phone page (neurastream ui). `neurastream ui on --login <email>`
|
|
2
|
-
# copies this into ~/.config/systemd/user/ and enables + restarts it; `neurastream ui off`
|
|
3
|
-
# stops and disables it. Agents never install or start it — that is the owner's move, refused
|
|
4
|
-
# by the guards.
|
|
5
|
-
|
|
6
|
-
[Unit]
|
|
7
|
-
Description=neurastream owner page (neurastream ui)
|
|
8
|
-
After=network-online.target
|
|
9
|
-
|
|
10
|
-
[Service]
|
|
11
|
-
ExecStart=%h/.bun/bin/neurastream ui
|
|
12
|
-
Restart=on-failure
|
|
13
|
-
RestartSec=5
|
|
14
|
-
|
|
15
|
-
[Install]
|
|
16
|
-
WantedBy=default.target
|