neurastream 0.2.20 → 0.2.22
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 +10 -0
- package/package.json +1 -1
- package/src/adapters/omp/doctor.ts +9 -0
- package/src/adapters/omp/install.ts +29 -4
- package/src/cli/dispatch.ts +8 -1
- package/src/cli/pages.ts +21 -0
- package/src/core/config.ts +4 -0
- package/src/core/owner-ui.ts +2 -2
- package/src/core/pages-doctor.ts +14 -0
- package/src/core/pages-setup.ts +53 -0
- package/src/core/pages.ts +40 -0
- package/src/core/uninstall.ts +24 -0
- package/templates/config.yml +5 -0
- package/templates/skills/architecture-drilldown/SKILL.md +56 -0
- package/templates/skills/architecture-drilldown/template.html +244 -0
- package/templates/systemd/neurastream-pages.service +12 -0
package/README.md
CHANGED
|
@@ -65,6 +65,12 @@ neurastream config --json
|
|
|
65
65
|
|
|
66
66
|
Every tool is one program, selected by the name it was called with: `agent-score`, `agent-ledger`, `brief-lint`, `oc-run`, `wip-check`, `wip-backup`, `wip-snapshot`, `main-health`, `queue-check`, `queue-close`, `queue-cancel`, `queue-trim`, `main-start`, `machine-guard`, `quota-reset`, `priority-watch`, `resource-alerts`, `tmp-snapshot`, `heavy-run`.
|
|
67
67
|
|
|
68
|
+
## Skill pack
|
|
69
|
+
|
|
70
|
+
`templates/skills/` ships skills for any agent that reads `~/.agents/skills/`. `neurastream adapter install omp` copies each one to `~/.agents/skills/<name>/` only when that directory is missing; an existing directory is kept as it is, so your edits survive a reinstall. `doctor` reports a shipped file that is missing from the live copy. `uninstall` removes a skill directory only when its whole tree is byte-identical to the shipped one; a directory with your own file or an edited file is kept and listed as `kept:`.
|
|
71
|
+
|
|
72
|
+
The first skill is `architecture-drilldown`: a self-contained HTML atlas with drill-down boxes. Its data is the `T` tree between `/* === DATA === */` and `/* === END DATA === */` in `template.html`; replace that block and leave the engine below it alone. `SKILL.md` lists the schema and the checks.
|
|
73
|
+
|
|
68
74
|
## Develop
|
|
69
75
|
|
|
70
76
|
```sh
|
|
@@ -113,6 +119,10 @@ A request is served only when the peer is a tailnet address that is neither loop
|
|
|
113
119
|
|
|
114
120
|
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.
|
|
115
121
|
|
|
122
|
+
## Static pages (`neurastream pages`)
|
|
123
|
+
|
|
124
|
+
`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]` publishes an artifact and prints its MagicDNS URL. `pages list` lists published files and `pages off` stops the service. Requests are limited to the configured owner's tailnet login or loopback; hidden files, symlinks and paths outside the directory are not served.
|
|
125
|
+
|
|
116
126
|
## Session rollover
|
|
117
127
|
|
|
118
128
|
Main's session file grows with every turn. When it reaches `rollover.max_session_mb` (default 5, `docs/config.md`), Main writes a handoff note to `<queue_state>/rollover/<session id>.md`. The note covers the work in progress and its state, the decisions made and why, the next step, and the files involved. Main is asked for it once per session file, when a turn ends.
|
package/package.json
CHANGED
|
@@ -69,6 +69,15 @@ export function adapterLiveFiles(home: string, root: string = PACKAGE_ROOT): Liv
|
|
|
69
69
|
if (!name.endsWith(".md") || name.includes(".bak")) continue;
|
|
70
70
|
files.push({ live: join(home, ".omp/agent/agents", name), source: join(agents, name) });
|
|
71
71
|
}
|
|
72
|
+
// Skills are copied under ~/.agents/skills/<name>/ by adapter install (copySkills), never linked.
|
|
73
|
+
// Only each shipped SKILL.md is listed: doctor reports a missing or edited skill the way it reports agents.
|
|
74
|
+
const skills = join(root, "templates/skills");
|
|
75
|
+
if (existsSync(skills)) {
|
|
76
|
+
for (const name of readdirSync(skills).sort()) {
|
|
77
|
+
if (!statSync(join(skills, name)).isDirectory()) continue;
|
|
78
|
+
files.push({ live: join(home, ".agents/skills", name, "SKILL.md"), source: join(skills, name, "SKILL.md") });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
72
81
|
return files;
|
|
73
82
|
}
|
|
74
83
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Does not read or write the real user's agent directory: every path is under `home`.
|
|
3
3
|
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
|
-
import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
import { dirname, join, resolve } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
@@ -31,6 +31,8 @@ export interface InstallResult {
|
|
|
31
31
|
removedStaleLink: string | null;
|
|
32
32
|
pinsCopied: string[];
|
|
33
33
|
pinsKept: string[];
|
|
34
|
+
skillsCopied: string[];
|
|
35
|
+
skillsKept: string[];
|
|
34
36
|
overlay: "written" | "unchanged";
|
|
35
37
|
agentsMd: "written" | "unchanged";
|
|
36
38
|
}
|
|
@@ -53,9 +55,9 @@ function ensureLink(link: string, target: string): void {
|
|
|
53
55
|
|
|
54
56
|
function linkInstalled(home: string): void {
|
|
55
57
|
for (const file of adapterLiveFiles(home)) {
|
|
56
|
-
// agents/ are copied, not linked; the plugin link is `omp plugin link`'s
|
|
58
|
+
// agents/ and skills/ are copied, not linked; the plugin link is `omp plugin link`'s
|
|
57
59
|
// own output (linkPlugin below), never ours to ensureLink.
|
|
58
|
-
if (file.live.includes("/.omp/agent/agents/") || file.live.includes("/.omp/plugins/")) continue;
|
|
60
|
+
if (file.live.includes("/.omp/agent/agents/") || file.live.includes("/.omp/plugins/") || file.live.includes("/.agents/skills/")) continue;
|
|
59
61
|
ensureLink(file.live, file.source);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -78,6 +80,27 @@ function copyPins(dest: string): { copied: string[]; kept: string[] } {
|
|
|
78
80
|
return { copied, kept };
|
|
79
81
|
}
|
|
80
82
|
|
|
83
|
+
// Shipped skills (templates/skills/<name>/) are copied, not linked: the owner
|
|
84
|
+
// edits them, so an existing skill dir is kept as it is.
|
|
85
|
+
function copySkills(home: string): { copied: string[]; kept: string[] } {
|
|
86
|
+
const src = join(PACKAGE_ROOT, "templates/skills");
|
|
87
|
+
const dest = join(home, ".agents/skills");
|
|
88
|
+
const copied: string[] = [];
|
|
89
|
+
const kept: string[] = [];
|
|
90
|
+
if (!existsSync(src)) return { copied, kept };
|
|
91
|
+
mkdirSync(dest, { recursive: true });
|
|
92
|
+
for (const name of readdirSync(src, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort()) {
|
|
93
|
+
const to = join(dest, name);
|
|
94
|
+
if (existsSync(to)) {
|
|
95
|
+
kept.push(to);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
cpSync(join(src, name), to, { recursive: true });
|
|
99
|
+
copied.push(to);
|
|
100
|
+
}
|
|
101
|
+
return { copied, kept };
|
|
102
|
+
}
|
|
103
|
+
|
|
81
104
|
export function writeOverlay(file: string): "written" | "unchanged" {
|
|
82
105
|
let text = readFileSync(file, "utf8");
|
|
83
106
|
let changed = false;
|
|
@@ -162,7 +185,8 @@ export function installOmp(home: string): InstallResult {
|
|
|
162
185
|
const plugin = linkPlugin(home);
|
|
163
186
|
const overlay = writeOverlay(file);
|
|
164
187
|
const agentsMd = writeAgentsMd(home);
|
|
165
|
-
|
|
188
|
+
const skills = copySkills(home);
|
|
189
|
+
return { plugin, removedStaleLink, pinsCopied: pins.copied, pinsKept: pins.kept, skillsCopied: skills.copied, skillsKept: skills.kept, overlay, agentsMd };
|
|
166
190
|
}
|
|
167
191
|
|
|
168
192
|
export function printInstall(result: InstallResult): void {
|
|
@@ -171,6 +195,7 @@ export function printInstall(result: InstallResult): void {
|
|
|
171
195
|
console.log(
|
|
172
196
|
`neurastream adapter install omp: pins copied ${result.pinsCopied.length}, kept ${result.pinsKept.length}; overlay ${result.overlay}`,
|
|
173
197
|
);
|
|
198
|
+
console.log(`neurastream adapter install omp: skills copied ${result.skillsCopied.length}, kept ${result.skillsKept.length}`);
|
|
174
199
|
console.log(`neurastream adapter install omp: AGENTS.md block ${result.agentsMd}`);
|
|
175
200
|
}
|
|
176
201
|
|
package/src/cli/dispatch.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pagesDoctor } from "../core/pages-doctor.ts";
|
|
1
2
|
import { ConfigError, configFile, loadConfig, type Config } from "../core/config.ts";
|
|
2
3
|
import { postReply } from "../core/notify.ts";
|
|
3
4
|
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
@@ -10,6 +11,7 @@ import { runMetrics } from "./metrics.ts";
|
|
|
10
11
|
import { runIncident } from "./incident.ts";
|
|
11
12
|
import { runTraces } from "./traces.ts";
|
|
12
13
|
import { runUi } from "./ui.ts";
|
|
14
|
+
import { runPages } from "./pages.ts";
|
|
13
15
|
import { runUninstall } from "../core/uninstall.ts";
|
|
14
16
|
import { queueMigrate } from "../core/queue-migrate.ts";
|
|
15
17
|
import { allowedAgents, subagentsPath } from "../core/queue/lib.ts";
|
|
@@ -80,6 +82,7 @@ export function helpText(): string {
|
|
|
80
82
|
" one go: writes ui.enabled/owner_login (and port) into the config,",
|
|
81
83
|
" installs and restarts the neurastream-ui user unit, prints the phone",
|
|
82
84
|
" link; `neurastream ui off` stops and disables it, sets enabled: false",
|
|
85
|
+
" neurastream pages on|off|serve|publish|list host static files over the tailnet",
|
|
83
86
|
" neurastream agents list | allow <slug>... | deny <slug>...",
|
|
84
87
|
" the subagent allow-list (## Allowed in notes/subagents.md)",
|
|
85
88
|
"",
|
|
@@ -102,6 +105,7 @@ export async function run(cmd: string, args: string[]): Promise<number> {
|
|
|
102
105
|
if (cmd === "incident") return runIncident(args);
|
|
103
106
|
if (cmd === "traces") return runTraces(args);
|
|
104
107
|
if (cmd === "ui") return runUi(args);
|
|
108
|
+
if (cmd === "pages") return runPages(args);
|
|
105
109
|
if (cmd === "adapter") return runAdapterInstall(args);
|
|
106
110
|
if (cmd === "config") {
|
|
107
111
|
try {
|
|
@@ -113,7 +117,10 @@ export async function run(cmd: string, args: string[]): Promise<number> {
|
|
|
113
117
|
return 1;
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
|
-
if (cmd === "doctor")
|
|
120
|
+
if (cmd === "doctor") {
|
|
121
|
+
for (const warning of pagesDoctor()) console.warn(`warning: ${warning}`);
|
|
122
|
+
return runDoctor();
|
|
123
|
+
}
|
|
117
124
|
if (cmd === "notify") return runNotify(args);
|
|
118
125
|
if (cmd === "uninstall") return runUninstall(args);
|
|
119
126
|
if (cmd === "queue" && args[0] === "migrate") {
|
package/src/cli/pages.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { defaultRunSource } from "../adapters/omp/sessions.ts";
|
|
4
|
+
import { loadConfig } from "../core/config.ts";
|
|
5
|
+
import { startPagesServer } from "../core/pages.ts";
|
|
6
|
+
import { pagesOff, pagesOn, publishPage, type Runner } from "../core/pages-setup.ts";
|
|
7
|
+
import { realTailscale, type Tailscale } from "../core/tailscale.ts";
|
|
8
|
+
|
|
9
|
+
export interface PagesDeps { home?: string; runner?: Runner; tailscale?: Tailscale }
|
|
10
|
+
export async function runPages(args: string[] = [], deps: PagesDeps = {}): Promise<number> {
|
|
11
|
+
const home=deps.home ?? homedir();
|
|
12
|
+
try {
|
|
13
|
+
if(args[0]==="on") { let port:number|undefined,dir:string|undefined; for(let i=1;i<args.length;i++){if(args[i]==="--port")port=Number(args[++i]);else if(args[i]==="--dir")dir=args[++i];else return 2;} return pagesOn({home,runner:deps.runner,tailscale:deps.tailscale,port,dir}); }
|
|
14
|
+
if(args[0]==="off"&&args.length===1)return pagesOff({home,runner:deps.runner});
|
|
15
|
+
const cfg=loadConfig({home});
|
|
16
|
+
if(args[0]==="serve"&&args.length===1){if(!cfg.pages.enabled)throw new Error("pages.enabled is false");startPagesServer({cfg,tailscale:deps.tailscale ?? realTailscale,source:defaultRunSource(cfg)});return new Promise<number>(()=>{});}
|
|
17
|
+
if(args[0]==="publish"&&args[1]){let force=false,name:string|undefined;for(const arg of args.slice(2)){if(arg==="--force")force=true;else if(!name)name=arg;else return 2;}const n=publishPage(args[1],name,force,cfg.pages.dir);const host=(deps.tailscale ?? realTailscale).dnsName() ?? "tailnet";console.log(`http://${host}:${cfg.pages.port}/${encodeURIComponent(n)}`);return 0;}
|
|
18
|
+
if(args[0]==="list"&&args.length===1){for(const f of readdirSync(cfg.pages.dir,{withFileTypes:true}).filter(e=>e.isFile()&&!e.name.startsWith(".")))console.log(f.name);return 0;}
|
|
19
|
+
} catch(e){console.error(e instanceof Error?e.message:String(e));return 1;}
|
|
20
|
+
console.error("usage: neurastream pages on [--port N] [--dir D] | off | serve | publish <file> [<name>] [--force] | list");return 2;
|
|
21
|
+
}
|
package/src/core/config.ts
CHANGED
|
@@ -135,6 +135,8 @@ export interface Config {
|
|
|
135
135
|
};
|
|
136
136
|
/** The owner's phone page (`neurastream ui`): binds the tailnet address only. */
|
|
137
137
|
ui: { enabled: boolean; port: number; owner_login: string };
|
|
138
|
+
/** Static pages hosted over the tailnet. */
|
|
139
|
+
pages: { enabled: boolean; port: number; dir: string };
|
|
138
140
|
rollover: { enabled: boolean; max_session_mb: number; exit_grace_s: number };
|
|
139
141
|
metrics: { report_days: number; correction_patterns: string[]; ci_pipelines_cmd: string };
|
|
140
142
|
/** Incident detectors (src/core/incident-detectors.ts): when a sighting becomes an incident. */
|
|
@@ -405,6 +407,8 @@ function check(cfg: Config): void {
|
|
|
405
407
|
if (!(cfg.rollover.exit_grace_s > 0)) throw new ConfigError("rollover.exit_grace_s must be > 0");
|
|
406
408
|
if (!(cfg.metrics.report_days >= 1)) throw new ConfigError("metrics.report_days must be >= 1");
|
|
407
409
|
if (!(cfg.ui.port >= 1 && cfg.ui.port <= 65535)) throw new ConfigError("ui.port must be between 1 and 65535");
|
|
410
|
+
if (!Number.isInteger(cfg.pages.port) || cfg.pages.port < 1 || cfg.pages.port > 65535) throw new ConfigError("pages.port must be an integer between 1 and 65535");
|
|
411
|
+
if (typeof cfg.pages.dir !== "string" || cfg.pages.dir.length === 0) throw new ConfigError("pages.dir must be a non-empty path");
|
|
408
412
|
for (const p of cfg.metrics.correction_patterns) {
|
|
409
413
|
try {
|
|
410
414
|
new RegExp(p, "i");
|
package/src/core/owner-ui.ts
CHANGED
|
@@ -56,11 +56,11 @@ export function inboxPath(): string {
|
|
|
56
56
|
return `${stateDirPath()}/owner-inbox.jsonl`;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
function isLoopback(peer: string): boolean {
|
|
59
|
+
export function isLoopback(peer: string): boolean {
|
|
60
60
|
return peer === "::1" || peer === "localhost" || peer.startsWith("127.");
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function isTailnet(peer: string): boolean {
|
|
63
|
+
export function isTailnet(peer: string): boolean {
|
|
64
64
|
const v4 = /^(\d+)\.(\d+)\./.exec(peer);
|
|
65
65
|
if (v4) return v4[1] === "100" && Number(v4[2]) >= 64 && Number(v4[2]) <= 127;
|
|
66
66
|
return TAILNET6.test(peer);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readdirSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { configFile, loadConfig } from "./config.ts";
|
|
6
|
+
import { PAGES_UNIT_TEMPLATE, type Runner } from "./pages-setup.ts";
|
|
7
|
+
|
|
8
|
+
export function pagesDoctor(home=homedir(), runner:Runner=args=>{const r=spawnSync("systemctl",args,{encoding:"utf8"});return{status:r.status,stderr:r.stderr??""}}): string[] {
|
|
9
|
+
const warnings:string[]=[];let cfg;
|
|
10
|
+
try{cfg=loadConfig({home,file:configFile(home)});}catch(e){return [`pages config invalid: ${e instanceof Error?e.message:String(e)}`];}
|
|
11
|
+
if(cfg.pages.enabled){if(!existsSync(cfg.pages.dir))warnings.push(`pages directory missing: ${cfg.pages.dir}`);if(!existsSync(join(home,".config/systemd/user/neurastream-pages.service"))||!existsSync(PAGES_UNIT_TEMPLATE))warnings.push("pages unit file missing");const result=runner(["--user","is-active","neurastream-pages"]);if(result.status!==0)warnings.push("neurastream-pages unit is not active");}
|
|
12
|
+
if(existsSync(cfg.pages.dir)){try{if(readdirSync(cfg.pages.dir).some(name=>{try{return lstatSync(join(cfg.pages.dir,name)).isSymbolicLink();}catch{return false;}}))warnings.push("pages directory contains a symlink");}catch{}}
|
|
13
|
+
return warnings;
|
|
14
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join, basename, extname } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { configFile, loadConfig } from "./config.ts";
|
|
7
|
+
import { realTailscale, type Tailscale } from "./tailscale.ts";
|
|
8
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
export const PAGES_UNIT_TEMPLATE = join(HERE, "../../templates/systemd/neurastream-pages.service");
|
|
10
|
+
export interface RunnerResult { status: number | null; stderr: string }
|
|
11
|
+
export type Runner = (args: string[]) => RunnerResult;
|
|
12
|
+
export const systemRunner: Runner = args => { const r = spawnSync("systemctl", args, { encoding:"utf8" }); return { status:r.status, stderr:r.stderr ?? "" }; };
|
|
13
|
+
export interface Setup { home?: string; runner?: Runner; tailscale?: Tailscale }
|
|
14
|
+
function editBlock(text: string | null, values: { enabled: boolean; port: number; dir: string }): string {
|
|
15
|
+
const fresh = ["pages:", ` enabled: ${values.enabled}`, ` port: ${values.port}`, ` dir: "${values.dir.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`];
|
|
16
|
+
if (text === null) return `${fresh.join("\n")}\n`;
|
|
17
|
+
const lines = text.split("\n");
|
|
18
|
+
let start = -1;
|
|
19
|
+
for (let i = 0; i < lines.length; i++) if (/^pages\s*:(\s*(?:#.*)?)?$/.test(lines[i] ?? "")) { start = i; break; }
|
|
20
|
+
if (start < 0) return `${text === "" || text.endsWith("\n") ? text : `${text}\n`}${fresh.join("\n")}\n`;
|
|
21
|
+
let end = start + 1;
|
|
22
|
+
while (end < lines.length && (lines[end] === "" || /^[ \t]/.test(lines[end]!))) end++;
|
|
23
|
+
const setKey = (key: string, value: string): void => {
|
|
24
|
+
const re = new RegExp(`^([ \\t]+)${key}\\s*:.*$`);
|
|
25
|
+
for (let i = start + 1; i < end; i++) if (re.test(lines[i]!)) { lines[i] = lines[i]!.replace(re, `$1${key}: ${value}`); return; }
|
|
26
|
+
let at = start + 1;
|
|
27
|
+
for (let i = start + 1; i < end; i++) if (lines[i]!.trim() !== "") at = i + 1;
|
|
28
|
+
lines.splice(at, 0, ` ${key}: ${value}`); end++;
|
|
29
|
+
};
|
|
30
|
+
setKey("enabled", String(values.enabled)); setKey("port", String(values.port)); setKey("dir", `"${values.dir.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`);
|
|
31
|
+
return lines.join("\n");
|
|
32
|
+
}
|
|
33
|
+
export function pagesOn(opts: Setup & { port?: number; dir?: string }): number {
|
|
34
|
+
const home = opts.home ?? homedir(), runner = opts.runner ?? systemRunner, ts = opts.tailscale ?? realTailscale;
|
|
35
|
+
const file = configFile(home), old = existsSync(file) ? readFileSync(file,"utf8") : null; const cfg = loadConfig({ home });
|
|
36
|
+
const port = opts.port ?? cfg.pages.port, dir = opts.dir ?? cfg.pages.dir;
|
|
37
|
+
const edited = editBlock(old, { enabled:true, port, dir }); mkdirSync(dirname(file), { recursive:true }); writeFileSync(file, edited);
|
|
38
|
+
mkdirSync(dir, { recursive:true });
|
|
39
|
+
mkdirSync(join(home,".config/systemd/user"),{recursive:true}); copyFileSync(PAGES_UNIT_TEMPLATE, join(home,".config/systemd/user/neurastream-pages.service"));
|
|
40
|
+
for (const args of [["--user","daemon-reload"],["--user","enable","--now","neurastream-pages"]]) { const r=runner(args); if(r.status!==0){console.error(r.stderr);return 1;} }
|
|
41
|
+
const dns=ts.dnsName(); console.log(`pages: http://${dns ?? ts.ip4() ?? "<tailnet>"}:${port}/`); return 0;
|
|
42
|
+
}
|
|
43
|
+
export function pagesOff(opts: Setup = {}): number {
|
|
44
|
+
const home=opts.home ?? homedir(), runner=opts.runner ?? systemRunner, file=configFile(home), old=existsSync(file)?readFileSync(file,"utf8"):null;
|
|
45
|
+
const cfg=loadConfig({home}); writeFileSync(file,editBlock(old,{enabled:false,port:cfg.pages.port,dir:cfg.pages.dir}));
|
|
46
|
+
const r=runner(["--user","stop","neurastream-pages"]); if(r.status!==0){console.error(r.stderr);return 1;} return 0;
|
|
47
|
+
}
|
|
48
|
+
export function publishPage(file: string, name: string | undefined, force: boolean, dir: string): string {
|
|
49
|
+
const source=basename(file), base=(name ?? source.slice(0,source.length-extname(source).length)).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");
|
|
50
|
+
const targetName=base+extname(source).toLowerCase(), target=join(dir,targetName); mkdirSync(dir,{recursive:true});
|
|
51
|
+
if(existsSync(target)){const a=readFileSync(file),b=readFileSync(target); if(a.equals(b)) return targetName; if(!force) throw new Error(`pages: ${targetName} exists with different content (use --force)`);}
|
|
52
|
+
copyFileSync(file,target); return targetName;
|
|
53
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { basename, extname, resolve } from "node:path";
|
|
3
|
+
import type { Config } from "./config.ts";
|
|
4
|
+
import { isLoopback, isTailnet, type UiHttpServer } from "./owner-ui.ts";
|
|
5
|
+
import type { RunSource } from "./adapter.ts";
|
|
6
|
+
import type { Tailscale } from "./tailscale.ts";
|
|
7
|
+
|
|
8
|
+
export interface PagesServer { stop(): void; hostname: string; port: number }
|
|
9
|
+
export interface PagesOptions { cfg: Config; tailscale: Tailscale; source: RunSource; hostname?: string; port?: number; peerOf?: (req: Request, server: UiHttpServer) => string; root?: string }
|
|
10
|
+
const MIME: Record<string, string> = { ".html":"text/html; charset=utf-8", ".css":"text/css; charset=utf-8", ".js":"text/javascript; charset=utf-8", ".mjs":"text/javascript; charset=utf-8", ".svg":"image/svg+xml", ".png":"image/png", ".jpg":"image/jpeg", ".jpeg":"image/jpeg", ".webp":"image/webp", ".json":"application/json", ".txt":"text/plain; charset=utf-8", ".ico":"image/x-icon", ".woff2":"font/woff2", ".map":"application/json" };
|
|
11
|
+
function urlPart(value: string): string { return encodeURI(value).replaceAll("?", "%3F").replaceAll("#", "%23").replaceAll('"', "%22").replaceAll("'", "%27"); }
|
|
12
|
+
function plain(body: string, status: number): Response { return new Response(body, { status, headers: { "content-type":"text/plain; charset=utf-8" } }); }
|
|
13
|
+
export function startPagesServer(opts: PagesOptions): PagesServer {
|
|
14
|
+
const hostname = opts.hostname ?? opts.tailscale.ip4();
|
|
15
|
+
if (!hostname) throw new Error("pages: tailscale ip -4 did not answer");
|
|
16
|
+
const root = resolve(opts.root ?? opts.cfg.pages.dir);
|
|
17
|
+
const peerOf = opts.peerOf ?? ((req: Request, server: UiHttpServer) => server.requestIP(req)?.address ?? "");
|
|
18
|
+
const server = Bun.serve({ hostname, port: opts.port ?? opts.cfg.pages.port, async fetch(req, srv) {
|
|
19
|
+
if (req.method !== "GET" && req.method !== "HEAD") return plain("method not allowed", 405);
|
|
20
|
+
const peer = peerOf(req, srv);
|
|
21
|
+
const login = isLoopback(peer) ? null : isTailnet(peer) ? opts.tailscale.whois(peer) : null;
|
|
22
|
+
if (!isLoopback(peer) && (!login || login !== opts.cfg.ui.owner_login)) return plain("forbidden", 403);
|
|
23
|
+
const url = new URL(req.url); let name = decodeURI(url.pathname.slice(1));
|
|
24
|
+
if (name.includes("/") || name.includes("\\") || name === ".." || name.startsWith(".")) return plain("not found", 404);
|
|
25
|
+
if (!name) {
|
|
26
|
+
const index = resolve(root, "index.html");
|
|
27
|
+
if (existsSync(index) && lstatSync(index).isFile()) name = "index.html";
|
|
28
|
+
else {
|
|
29
|
+
const files = existsSync(root) ? readdirSync(root, { withFileTypes:true }).filter(e => !e.name.startsWith(".") && e.isFile()).map(e => e.name) : [];
|
|
30
|
+
const body = `<!doctype html><ul>${files.map(f => `<li><a href="/${urlPart(f)}">${f.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}</a></li>`).join("")}</ul>`;
|
|
31
|
+
return new Response(req.method === "HEAD" ? null : body, { headers:{ "content-type":"text/html; charset=utf-8" } });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const path = resolve(root, name);
|
|
35
|
+
if (basename(path) !== name || !existsSync(path) || !lstatSync(path).isFile()) return plain("not found", 404);
|
|
36
|
+
const type = MIME[extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
37
|
+
return new Response(req.method === "HEAD" ? null : readFileSync(path), { headers:{ "content-type":type, ...(type === "application/octet-stream" ? { "content-disposition":`attachment; filename*=UTF-8''${urlPart(name)}` } : {}) } });
|
|
38
|
+
}});
|
|
39
|
+
return { stop: () => server.stop(true), hostname, port: Number(server.port) };
|
|
40
|
+
}
|
package/src/core/uninstall.ts
CHANGED
|
@@ -102,6 +102,19 @@ function bins(cfg: Config, out: UninstallTarget[]): void {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/** A skill dir is ours only when every file in it matches the shipped copy; any file the owner added keeps it. */
|
|
106
|
+
function sameTree(live: string, shipped: string): boolean {
|
|
107
|
+
if (!lstatSync(live).isDirectory()) return false;
|
|
108
|
+
const names = readdirSync(live).sort();
|
|
109
|
+
if (names.join("\0") !== readdirSync(shipped).sort().join("\0")) return false;
|
|
110
|
+
return names.every((name) => {
|
|
111
|
+
const a = join(live, name);
|
|
112
|
+
const b = join(shipped, name);
|
|
113
|
+
if (lstatSync(a).isDirectory()) return lstatSync(b).isDirectory() && sameTree(a, b);
|
|
114
|
+
return lstatSync(a).isFile() && readFileSync(a).equals(readFileSync(b));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
105
118
|
function adapterSurface(cfg: Config, out: UninstallTarget[], kept: string[]): void {
|
|
106
119
|
const adapter = cfg.adapter;
|
|
107
120
|
if (!adapter) return;
|
|
@@ -126,6 +139,17 @@ function adapterSurface(cfg: Config, out: UninstallTarget[], kept: string[]): vo
|
|
|
126
139
|
}
|
|
127
140
|
}
|
|
128
141
|
|
|
142
|
+
const skillsDir = join(cfg.paths.home, ".agents/skills");
|
|
143
|
+
const shippedSkills = join(PACKAGE_ROOT, "templates/skills");
|
|
144
|
+
if (existsSync(shippedSkills)) {
|
|
145
|
+
for (const name of readdirSync(shippedSkills).sort()) {
|
|
146
|
+
const live = join(skillsDir, name);
|
|
147
|
+
if (!existsSync(live)) continue;
|
|
148
|
+
if (sameTree(live, join(shippedSkills, name))) out.push({ path: live, what: `template-identical skill ${name}` });
|
|
149
|
+
else kept.push(`${live} (skill differs from the shipped copy; kept)`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
129
153
|
const agentsMd = join(dirname(adapter.sessions), "AGENTS.md");
|
|
130
154
|
if (existsSync(agentsMd)) {
|
|
131
155
|
const probe = stripBlock(readFileSync(agentsMd, "utf8"));
|
package/templates/config.yml
CHANGED
|
@@ -130,6 +130,11 @@ ui:
|
|
|
130
130
|
port: 7787
|
|
131
131
|
owner_login: "" # the tailscale login that may open the page; empty = the page refuses to start
|
|
132
132
|
|
|
133
|
+
|
|
134
|
+
pages:
|
|
135
|
+
enabled: false
|
|
136
|
+
port: 7788
|
|
137
|
+
dir: "~/.local/share/neurastream/pages"
|
|
133
138
|
rollover:
|
|
134
139
|
enabled: true
|
|
135
140
|
max_session_mb: 5
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: architecture-drilldown
|
|
3
|
+
description: Build a self-contained, click-to-drill architecture diagram (one HTML file) from a template. Use when the user wants an interactive system map with boxes that open into their parts.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# architecture-drilldown
|
|
7
|
+
|
|
8
|
+
Make one HTML file that shows a system as boxes. Tap a box to open its inside; the root is the whole system, each level is one part of the level above.
|
|
9
|
+
|
|
10
|
+
## Start
|
|
11
|
+
|
|
12
|
+
1. Copy `template.html` (this folder) to the target, e.g. `architecture.html`. Keep the file self-contained: no CDN, no build step.
|
|
13
|
+
2. Edit only the block between `/* === DATA === */` and `/* === END DATA === */`. Everything below `END DATA` is the engine: leave it as it is.
|
|
14
|
+
3. Open the file in a browser and check the root and one drilled level (see Verify).
|
|
15
|
+
|
|
16
|
+
## Data schema
|
|
17
|
+
|
|
18
|
+
The root is `const T={...}`. Each box is an object:
|
|
19
|
+
|
|
20
|
+
| Field | Meaning |
|
|
21
|
+
|---|---|
|
|
22
|
+
| `id` | Unique string. Used in `flows` and in the URL hash. |
|
|
23
|
+
| `nm` | Name shown on the box. |
|
|
24
|
+
| `role` | Short subtitle, one line. |
|
|
25
|
+
| `st` | `"built"`, `"almost"` or `"plan"`. Drives the box style. |
|
|
26
|
+
| `at` | `[col,row]` cell in this level's desktop grid. |
|
|
27
|
+
| `atM` | `[col,row]` cell on the phone grid (root and any level with `gm`). |
|
|
28
|
+
| `c` | Colour (CSS hex). Children inherit it. |
|
|
29
|
+
| `kind` | `"actor"` = outside party (grey pill, not clickable). |
|
|
30
|
+
| `g` | `[cols,rows]` desktop grid of this level. |
|
|
31
|
+
| `gm` | `[cols,rows]` phone grid of this level. Without `gm` the desktop grid is transposed on the phone when it has more than 2 columns. |
|
|
32
|
+
| `flows` | `[from, to, label]` arrows between boxes of this level. Labels: 3 words max. |
|
|
33
|
+
| `kids` | Boxes one level down. A box with `kids` shows "open ›". |
|
|
34
|
+
| `what`, `files`, `ex` | Sheet text on a leaf: what it does, source files, one example. |
|
|
35
|
+
| `steps` | Root only: numbered list in the sheet. |
|
|
36
|
+
|
|
37
|
+
## Style rules
|
|
38
|
+
|
|
39
|
+
- Max 4 columns on the desktop grid, 2 on the phone grid.
|
|
40
|
+
- Keep each level to 3-6 boxes. If a level needs more, split it into a child level.
|
|
41
|
+
- Every arrow connects neighbours on the grid. An arrow that passes through a box is a layout bug: move the box or add a middle step.
|
|
42
|
+
- Actors are the outside world (users, third-party services). Do not give them `kids`.
|
|
43
|
+
- Use one colour per top-level area; reuse it for that area's children.
|
|
44
|
+
- Labels say what moves, not how it is built.
|
|
45
|
+
|
|
46
|
+
## Verify
|
|
47
|
+
|
|
48
|
+
Open the file at two widths and check the root plus one drilled level:
|
|
49
|
+
|
|
50
|
+
- Desktop 1280 px: boxes and arrows sit in their grid cells, no arrow crosses a box, the sheet opens on tap and closes on `×`.
|
|
51
|
+
- Phone 390 px: the phone grid (`gm`/`atM`) is used, boxes stay readable, no horizontal scroll.
|
|
52
|
+
- Console: no JS errors on load, on drill-down, or on going back.
|
|
53
|
+
|
|
54
|
+
## Host
|
|
55
|
+
|
|
56
|
+
Single file: open it from disk, or serve the folder with any static server. Share the file as-is.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
|
6
|
+
<title>Architecture</title>
|
|
7
|
+
<style>
|
|
8
|
+
*{box-sizing:border-box}
|
|
9
|
+
html,body{margin:0;background:#f6f7f9;color:#1d2433;font:15px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
|
|
10
|
+
#wrap{max-width:1180px;margin:0 auto;padding:22px 22px 40px}
|
|
11
|
+
#bar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;min-height:34px}
|
|
12
|
+
#back{border:1px solid #d4d9e2;background:#fff;border-radius:9px;padding:5px 12px;font:inherit;font-size:14px;cursor:pointer;color:#1d2433}
|
|
13
|
+
#back[disabled]{opacity:.35;cursor:default}
|
|
14
|
+
#crumbs{display:flex;flex-wrap:wrap;gap:4px;align-items:center;font-size:14px;color:#6b7385}
|
|
15
|
+
#crumbs button{border:0;background:none;font:inherit;color:#3b6fd8;cursor:pointer;padding:2px 3px}
|
|
16
|
+
#crumbs .here{color:#1d2433;font-weight:600;padding:2px 3px}
|
|
17
|
+
h1{font-size:25px;margin:14px 0 4px;letter-spacing:-.01em}
|
|
18
|
+
#sub{color:#5a6275;margin:0 0 14px;font-size:15.5px;max-width:880px}
|
|
19
|
+
#legend{display:flex;gap:16px;flex-wrap:wrap;font-size:13px;color:#5a6275;margin:0 0 12px}
|
|
20
|
+
#legend span{display:inline-flex;align-items:center;gap:6px}
|
|
21
|
+
#legend i{display:inline-block;width:22px;height:13px;border-radius:4px;border:2px solid #4b8cf0;background:#fff}
|
|
22
|
+
#legend i.p{border-style:dashed;border-color:#9aa3b5}
|
|
23
|
+
#legend i.h{background:linear-gradient(90deg,#fff 50%,#fff3d6 50%);border-color:#e0a526}
|
|
24
|
+
#stage{position:relative;background:#fff;border:1px solid #e1e5ec;border-radius:16px;overflow:hidden}
|
|
25
|
+
#stage svg{display:block;width:100%;height:auto}
|
|
26
|
+
.box{cursor:pointer}
|
|
27
|
+
.box .card{transition:filter .15s}
|
|
28
|
+
.box:hover .card{filter:drop-shadow(0 4px 10px rgba(30,50,90,.16))}
|
|
29
|
+
.box.actor{cursor:default}
|
|
30
|
+
.box.actor:hover .card{filter:none}
|
|
31
|
+
.t{font-weight:650;font-size:15.5px;fill:#1d2433}
|
|
32
|
+
.s{font-size:12.5px;fill:#5a6275}
|
|
33
|
+
.badge{font-size:10.5px;font-weight:600;letter-spacing:.02em}
|
|
34
|
+
.open{font-size:12px;font-weight:600}
|
|
35
|
+
.el{font-size:11.5px;fill:#4a5263}
|
|
36
|
+
#steps{margin:16px 0 0;padding:0;list-style:none;display:grid;gap:8px}
|
|
37
|
+
#steps li{background:#fff;border:1px solid #e1e5ec;border-radius:12px;padding:10px 14px;display:flex;gap:10px}
|
|
38
|
+
#steps li b.n{flex:0 0 22px;height:22px;border-radius:50%;color:#fff;font-size:12px;display:flex;align-items:center;justify-content:center}
|
|
39
|
+
#hint{color:#8a92a3;font-size:13px;margin-top:10px}
|
|
40
|
+
#zoom{position:fixed;z-index:40;background:#fff;border:2px solid #4b8cf0;border-radius:12px;pointer-events:none;
|
|
41
|
+
transition:all .34s cubic-bezier(.3,.7,.2,1);opacity:1}
|
|
42
|
+
#sheet{position:fixed;z-index:50;right:18px;top:18px;bottom:18px;width:380px;background:#fff;border:1px solid #d9dee7;
|
|
43
|
+
border-radius:16px;box-shadow:0 16px 40px rgba(20,30,60,.18);padding:18px 20px;overflow:auto;transform:translateX(120%);transition:transform .25s}
|
|
44
|
+
#sheet.on{transform:none}
|
|
45
|
+
#sheet h2{margin:2px 0 6px;font-size:19px}
|
|
46
|
+
#sheet .st{font-size:12px;font-weight:700;letter-spacing:.03em}
|
|
47
|
+
#sheet .what{font-size:15px;margin:10px 0}
|
|
48
|
+
#sheet .k{font-size:12px;color:#8a92a3;text-transform:uppercase;letter-spacing:.05em;margin-top:14px}
|
|
49
|
+
#sheet code{font:12.5px ui-monospace,SFMono-Regular,Menlo,monospace;background:#f1f3f7;border-radius:6px;padding:6px 8px;display:block;white-space:pre-wrap;word-break:break-word}
|
|
50
|
+
#sheet .ex{background:#f7f9fc;border-left:3px solid #4b8cf0;padding:8px 10px;border-radius:6px;font-size:14px}
|
|
51
|
+
#sheet .x{position:absolute;right:12px;top:10px;border:0;background:none;font-size:22px;cursor:pointer;color:#6b7385}
|
|
52
|
+
#scrim{position:fixed;inset:0;z-index:45;background:rgba(20,30,50,.18);display:none}
|
|
53
|
+
#scrim.on{display:block}
|
|
54
|
+
@media(max-width:700px){
|
|
55
|
+
#wrap{padding:12px 10px 30px}
|
|
56
|
+
h1{font-size:21px;margin-top:10px}
|
|
57
|
+
#sub{font-size:14.5px}
|
|
58
|
+
#sheet{left:8px;right:8px;top:auto;bottom:8px;width:auto;max-height:72vh;transform:translateY(calc(100% + 40px))}
|
|
59
|
+
#sheet.on{transform:none}
|
|
60
|
+
}
|
|
61
|
+
</style>
|
|
62
|
+
</head>
|
|
63
|
+
<body>
|
|
64
|
+
<div id="wrap">
|
|
65
|
+
<div id="bar"><button id="back" disabled>‹ Back</button><div id="crumbs"></div></div>
|
|
66
|
+
<h1 id="title"></h1>
|
|
67
|
+
<p id="sub"></p>
|
|
68
|
+
<div id="legend">
|
|
69
|
+
<span><i></i>built</span><span><i class="h"></i>almost done</span><span><i class="p"></i>planned</span>
|
|
70
|
+
<span>› = tap to open its insides</span>
|
|
71
|
+
</div>
|
|
72
|
+
<div id="stage"></div>
|
|
73
|
+
<ol id="steps"></ol>
|
|
74
|
+
<div id="hint">Tap a box to open it. Back button, or Esc, goes up a level.</div>
|
|
75
|
+
</div>
|
|
76
|
+
<div id="scrim"></div>
|
|
77
|
+
<div id="sheet"><button class="x" aria-label="close">×</button><div id="sheetBody"></div></div>
|
|
78
|
+
<script>
|
|
79
|
+
/* === DATA === */
|
|
80
|
+
/* Example data. Replace it with your system; the engine below END DATA stays as it is.
|
|
81
|
+
Box: id (unique), nm name, role short subtitle, st built | almost | plan, at:[col,row] cell in this level's grid g:[cols,rows].
|
|
82
|
+
kind:"actor" = outside party (grey, not clickable). c colour, inherited by children.
|
|
83
|
+
Phone (<700px): gm:[cols,rows] and atM:[col,row] per box; a level without gm gets its desktop grid transposed.
|
|
84
|
+
flows:[from,to,label] arrows between boxes of one level. kids: boxes one level down.
|
|
85
|
+
Leaves: what, files, ex (sheet text). Root only: steps (numbered list). */
|
|
86
|
+
const T={id:"root",nm:"Example Shop",
|
|
87
|
+
role:"Customers buy online; one back office packs and ships every order.",
|
|
88
|
+
g:[4,2],gm:[2,4],
|
|
89
|
+
flows:[["customer","site","buys"],["site","orders","new order"],["site","pay","charge card"],["orders","carrier","ship parcel"],["orders","stock","take items"],["orders","loyalty","earn points"]],
|
|
90
|
+
steps:["The customer picks items in the web shop.","The shop charges the card.","The order goes to the back office.","Staff pick, pack and hand the parcel to the carrier.","The customer gets the parcel and any points."],
|
|
91
|
+
kids:[
|
|
92
|
+
{id:"customer",nm:"Customer",role:"web or phone",kind:"actor",at:[0,0],atM:[0,0]},
|
|
93
|
+
{id:"site",nm:"Web shop",role:"catalogue and checkout",st:"built",at:[1,0],atM:[0,1],c:"#3b6fd8",what:"Where customers browse, add to cart and pay.",files:"shop/web",ex:"A declined card shows a retry prompt; nothing ships."},
|
|
94
|
+
{id:"orders",nm:"Orders",role:"packing and dispatch",st:"built",at:[2,0],atM:[0,2],c:"#2f9e6d",
|
|
95
|
+
g:[3,1],flows:[["pick","pack","bag it"],["pack","returns","if wrong"]],
|
|
96
|
+
kids:[
|
|
97
|
+
{id:"pick",nm:"Pick",role:"walk the shelves",st:"built",at:[0,0],what:"Staff collect each item on the order list.",
|
|
98
|
+
g:[2,1],flows:[["scan","bin","item found"]],
|
|
99
|
+
kids:[
|
|
100
|
+
{id:"scan",nm:"Scan",role:"barcode check",st:"built",at:[0,0],what:"Each item is scanned so a wrong one is caught early.",files:"scanner app"},
|
|
101
|
+
{id:"bin",nm:"Find shelf",role:"shelf location",st:"built",at:[1,0],what:"The app shows the shelf for the next item."}]},
|
|
102
|
+
{id:"pack",nm:"Pack",role:"box and label",st:"almost",at:[1,0],what:"Items are boxed with the packing slip. Label printing is moving to the new printer.",files:"packing plan (printer left)"},
|
|
103
|
+
{id:"returns",nm:"Returns",role:"send back wrong items",st:"plan",at:[2,0],what:"Planned: a return label printed from the order page."}]},
|
|
104
|
+
{id:"carrier",nm:"Carrier",role:"delivers the parcel",kind:"actor",at:[3,0],atM:[0,3]},
|
|
105
|
+
{id:"pay",nm:"Card payments",role:"takes the money",st:"built",at:[1,1],atM:[1,0],c:"#c98a12",what:"A card provider charges the customer and confirms the payment.",ex:"A failed payment never creates an order."},
|
|
106
|
+
{id:"stock",nm:"Stock count",role:"items left on the shelf",st:"almost",at:[2,1],atM:[1,1],c:"#7a55d6",what:"Counts drop when an order is packed. Live counts for shop pages are almost done.",files:"stock plan (live counts left)"},
|
|
107
|
+
{id:"loyalty",nm:"Loyalty points",role:"reward repeat buyers",st:"plan",at:[3,1],atM:[1,3],c:"#d9782d",what:"Planned: every order earns points spendable at checkout."}
|
|
108
|
+
]};
|
|
109
|
+
/* === END DATA === */
|
|
110
|
+
|
|
111
|
+
/* ---------- index ---------- */
|
|
112
|
+
const byId={},parent={};
|
|
113
|
+
(function walk(n,p,c){byId[n.id]=n;parent[n.id]=p;n.col=n.c||c;(n.kids||[]).forEach(k=>walk(k,n.id,n.col));})(T,null,"#3b6fd8");
|
|
114
|
+
const NS="http://www.w3.org/2000/svg";
|
|
115
|
+
const S=(tag,attrs,txt)=>{const e=document.createElementNS(NS,tag);for(const k in attrs)e.setAttribute(k,attrs[k]);if(txt!=null)e.textContent=txt;return e;};
|
|
116
|
+
const ST={built:["● BUILT","#2f9e6d"],almost:["◐ ALMOST DONE","#c98a12"],plan:["○ PLANNED","#8a92a3"]};
|
|
117
|
+
function wrap(text,max){const w=(text||"").split(" "),out=[];let line="";for(const x of w){if((line+" "+x).trim().length>max&&line){out.push(line);line=x;}else line=(line+" "+x).trim();}if(line)out.push(line);return out.slice(0,2);}
|
|
118
|
+
|
|
119
|
+
/* ---------- layout ---------- */
|
|
120
|
+
function geometry(n){
|
|
121
|
+
const phone=innerWidth<700, kids=n.kids;
|
|
122
|
+
if(!phone){
|
|
123
|
+
const [C,R]=n.g,cw=Math.min(290,1120/C),ch=170,bw=Math.min(206,cw-88),bh=104;
|
|
124
|
+
const W=C*cw,H=R*ch+20;
|
|
125
|
+
const pos={};kids.forEach(k=>{const [c,r]=k.at;pos[k.id]={x:c*cw+(cw-bw)/2,y:20+r*ch+(ch-bh)/2-4,w:bw,h:bh};});
|
|
126
|
+
return {W,H,pos,phone};
|
|
127
|
+
}
|
|
128
|
+
// phone: a level's own portrait grid (gm + atM), else transpose the desktop grid so arrows keep their shape
|
|
129
|
+
const [C,R]=n.g, own=!!n.gm, tr=!own&&C>2;
|
|
130
|
+
const cols=own?n.gm[0]:tr?R:C, rows=own?n.gm[1]:tr?C:R;
|
|
131
|
+
const cw=cols===1?360:195, ch=148, bw=cols===1?300:172, bh=108;
|
|
132
|
+
const W=cols*cw, H=rows*ch+16;
|
|
133
|
+
const pos={};kids.forEach(k=>{const [c,r]=own?k.atM:tr?[k.at[1],k.at[0]]:k.at;pos[k.id]={x:c*cw+(cw-bw)/2,y:12+r*ch+(ch-bh)/2,w:bw,h:bh};});
|
|
134
|
+
return {W,H,pos,phone};
|
|
135
|
+
}
|
|
136
|
+
function edgePoint(b,tx,ty){ // where the line from box centre towards (tx,ty) leaves the box
|
|
137
|
+
const cx=b.x+b.w/2,cy=b.y+b.h/2,dx=tx-cx,dy=ty-cy;
|
|
138
|
+
const s=Math.min(Math.abs((b.w/2+6)/(dx||1e-9)),Math.abs((b.h/2+6)/(dy||1e-9)));
|
|
139
|
+
return [cx+dx*s,cy+dy*s];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* ---------- render a level ---------- */
|
|
143
|
+
let current=T;
|
|
144
|
+
function render(n){
|
|
145
|
+
current=n;
|
|
146
|
+
const g=geometry(n), stage=document.getElementById("stage");
|
|
147
|
+
const svg=S("svg",{viewBox:`0 0 ${g.W} ${g.H}`,role:"img"});
|
|
148
|
+
const defs=S("defs");svg.append(defs);
|
|
149
|
+
const markers={};
|
|
150
|
+
const mk=col=>{if(markers[col])return markers[col];const id="m"+Object.keys(markers).length;
|
|
151
|
+
const m=S("marker",{id,viewBox:"0 0 10 10",refX:"9",refY:"5",markerWidth:"7",markerHeight:"7",orient:"auto-start-reverse"});
|
|
152
|
+
m.append(S("path",{d:"M0,0 L10,5 L0,10 z",fill:col}));defs.append(m);return markers[col]="url(#"+id+")";};
|
|
153
|
+
const flows=n.flows||[], have=new Set(flows.map(f=>f[0]+">"+f[1]));
|
|
154
|
+
const lines=S("g"), labels=S("g"), boxes=S("g");
|
|
155
|
+
for(const [a,b,label] of flows){
|
|
156
|
+
const A=g.pos[a],B=g.pos[b];if(!A||!B)continue;
|
|
157
|
+
const col=byId[a].kind==="actor"?"#7d8597":byId[a].col;
|
|
158
|
+
let [x1,y1]=edgePoint(A,B.x+B.w/2,B.y+B.h/2),[x2,y2]=edgePoint(B,A.x+A.w/2,A.y+A.h/2);
|
|
159
|
+
if(have.has(b+">"+a)){const dx=x2-x1,dy=y2-y1,L=Math.hypot(dx,dy)||1,ox=-dy/L*9,oy=dx/L*9;x1+=ox;y1+=oy;x2+=ox;y2+=oy;}
|
|
160
|
+
lines.append(S("line",{x1,y1,x2,y2,stroke:col,"stroke-width":"2.2","marker-end":mk(col),opacity:".9"}));
|
|
161
|
+
if(label){
|
|
162
|
+
const two=have.has(b+">"+a),tt=two?.3:.5,L=Math.hypot(x2-x1,y2-y1)||1,po=two?13:0,mx=x1+(x2-x1)*tt-(y2-y1)/L*po,my=y1+(y2-y1)*tt+(x2-x1)/L*po,t=S("text",{x:mx,y:my+4,"text-anchor":"middle",class:"el"},label);
|
|
163
|
+
const w=label.length*6.1+12;
|
|
164
|
+
labels.append(S("rect",{x:mx-w/2,y:my-9,width:w,height:18,rx:9,fill:"#fff",stroke:"#e3e7ee"}));labels.append(t);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for(const k of n.kids){
|
|
168
|
+
const p=g.pos[k.id],grp=S("g",{class:"box"+(k.kind==="actor"?" actor":""),tabindex:k.kind==="actor"?"-1":"0","data-id":k.id});
|
|
169
|
+
const card=S("g",{class:"card"});
|
|
170
|
+
if(k.kind==="actor"){
|
|
171
|
+
card.append(S("rect",{x:p.x,y:p.y+14,width:p.w,height:p.h-28,rx:(p.h-28)/2,fill:"#eef0f4",stroke:"#c9ced8","stroke-width":"1.5"}));
|
|
172
|
+
card.append(S("text",{x:p.x+p.w/2,y:p.y+p.h/2+(k.role?-2:5),"text-anchor":"middle",class:"t"},k.nm));
|
|
173
|
+
if(k.role)card.append(S("text",{x:p.x+p.w/2,y:p.y+p.h/2+15,"text-anchor":"middle",class:"s"},k.role));
|
|
174
|
+
}else{
|
|
175
|
+
const has=!!(k.kids&&k.kids.length),dashed=k.st==="plan";
|
|
176
|
+
const stroke=dashed?"#9aa3b5":k.col, fill=k.st==="almost"?"#fffaf0":"#fff";
|
|
177
|
+
if(has){card.append(S("rect",{x:p.x+7,y:p.y+7,width:p.w,height:p.h,rx:12,fill:"#fff",stroke,"stroke-width":"1.3",opacity:".55","stroke-dasharray":dashed?"6 4":""}));}
|
|
178
|
+
card.append(S("rect",{x:p.x,y:p.y,width:p.w,height:p.h,rx:12,fill,stroke,"stroke-width":"2.2","stroke-dasharray":dashed?"6 4":""}));
|
|
179
|
+
const [bt,bc]=ST[k.st]||ST.built;
|
|
180
|
+
card.append(S("text",{x:p.x+14,y:p.y+20,class:"badge",fill:bc},bt));
|
|
181
|
+
card.append(S("text",{x:p.x+14,y:p.y+43,class:"t"},k.nm));
|
|
182
|
+
wrap(k.role,g.phone?24:32).forEach((ln,i)=>card.append(S("text",{x:p.x+14,y:p.y+62+i*16,class:"s"},ln)));
|
|
183
|
+
if(has)card.append(S("text",{x:p.x+p.w-12,y:p.y+20,"text-anchor":"end",class:"open",fill:k.col},"open ›"));
|
|
184
|
+
}
|
|
185
|
+
grp.append(card);boxes.append(grp);
|
|
186
|
+
if(k.kind!=="actor"){
|
|
187
|
+
grp.addEventListener("click",ev=>open(k,grp));
|
|
188
|
+
grp.addEventListener("keydown",ev=>{if(ev.key==="Enter")open(k,grp);});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
svg.append(lines,boxes,labels);
|
|
192
|
+
stage.replaceChildren(svg);
|
|
193
|
+
// header
|
|
194
|
+
document.getElementById("title").textContent=n===T?`${T.nm} — how it works`:n.nm;document.title=`${T.nm} — architecture`;
|
|
195
|
+
document.getElementById("sub").textContent=n===T?n.role:(n.what||n.role);
|
|
196
|
+
const path=[];for(let x=n.id;x;x=parent[x])path.unshift(byId[x]);
|
|
197
|
+
const cr=document.getElementById("crumbs");cr.replaceChildren();
|
|
198
|
+
path.forEach((p,i)=>{if(i)cr.append("›");
|
|
199
|
+
if(i===path.length-1){const s=document.createElement("span");s.className="here";s.textContent=p.nm;cr.append(s);}
|
|
200
|
+
else{const b=document.createElement("button");b.textContent=p.nm;b.onclick=()=>go(p);cr.append(b);}});
|
|
201
|
+
document.getElementById("back").disabled=n===T;
|
|
202
|
+
const st=document.getElementById("steps");st.replaceChildren();
|
|
203
|
+
(n.steps||[]).forEach((s,i)=>{const li=document.createElement("li"),b=document.createElement("b");b.className="n";b.style.background=["#3b6fd8","#7a55d6","#2f9e6d","#d9782d","#c2457a"][i%5];b.textContent=i+1;li.append(b,document.createTextNode(s));st.append(li);});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* ---------- navigation ---------- */
|
|
207
|
+
function pathOf(n){const p=[];for(let x=n.id;x&&x!=="root";x=parent[x])p.unshift(x);return p.join("/");}
|
|
208
|
+
function go(n,push=true){closeSheet();render(n);if(push)history.pushState(null,"","#"+pathOf(n));window.scrollTo({top:0});}
|
|
209
|
+
function open(k,grp){
|
|
210
|
+
if(!(k.kids&&k.kids.length)){showSheet(k);return;}
|
|
211
|
+
const r=grp.querySelector(".card rect:last-of-type").getBoundingClientRect(),s=document.getElementById("stage").getBoundingClientRect();
|
|
212
|
+
const z=document.createElement("div");z.id="zoom";z.style.borderColor=k.col;
|
|
213
|
+
Object.assign(z.style,{left:r.left+"px",top:r.top+"px",width:r.width+"px",height:r.height+"px"});
|
|
214
|
+
document.body.append(z);
|
|
215
|
+
requestAnimationFrame(()=>requestAnimationFrame(()=>{Object.assign(z.style,{left:s.left+"px",top:Math.max(s.top,0)+"px",width:s.width+"px",height:Math.min(s.height,innerHeight)+"px"});}));
|
|
216
|
+
setTimeout(()=>{go(k);z.style.opacity="0";setTimeout(()=>z.remove(),260);},340);
|
|
217
|
+
}
|
|
218
|
+
function up(){if(current===T)return;go(byId[parent[current.id]]);}
|
|
219
|
+
document.getElementById("back").onclick=up;
|
|
220
|
+
addEventListener("keydown",e=>{if(e.key==="Escape"){if(document.getElementById("sheet").classList.contains("on"))closeSheet();else up();}});
|
|
221
|
+
addEventListener("popstate",()=>{const id=(location.hash.slice(1).split("/").pop())||"root";render(byId[id]||T);closeSheet();});
|
|
222
|
+
let lastPhone=innerWidth<700;addEventListener("resize",()=>{const p=innerWidth<700;if(p!==lastPhone){lastPhone=p;render(current);}});
|
|
223
|
+
|
|
224
|
+
/* ---------- leaf sheet ---------- */
|
|
225
|
+
function showSheet(k){
|
|
226
|
+
const [bt,bc]=ST[k.st]||ST.built,b=document.getElementById("sheetBody");b.replaceChildren();
|
|
227
|
+
const add=(tag,cls,txt)=>{const e=document.createElement(tag);if(cls)e.className=cls;e.textContent=txt;b.append(e);return e;};
|
|
228
|
+
const s=add("div","st",bt);s.style.color=bc;
|
|
229
|
+
add("h2","",k.nm);
|
|
230
|
+
add("div","what",k.what||k.role);
|
|
231
|
+
if(k.ex){add("div","k","Example");add("div","ex",k.ex);}
|
|
232
|
+
if(k.files){add("div","k","Where");add("code","",k.files);}
|
|
233
|
+
const crumb=[];for(let x=parent[k.id];x;x=parent[x])crumb.unshift(byId[x].nm);
|
|
234
|
+
add("div","k","Part of");add("div","",crumb.join(" › "));
|
|
235
|
+
document.getElementById("sheet").classList.add("on");document.getElementById("scrim").classList.add("on");
|
|
236
|
+
}
|
|
237
|
+
function closeSheet(){document.getElementById("sheet").classList.remove("on");document.getElementById("scrim").classList.remove("on");}
|
|
238
|
+
document.querySelector("#sheet .x").onclick=closeSheet;document.getElementById("scrim").onclick=closeSheet;
|
|
239
|
+
|
|
240
|
+
/* ---------- start ---------- */
|
|
241
|
+
{const id=(location.hash.slice(1).split("/").pop())||"root";render(byId[id]||T);}
|
|
242
|
+
</script>
|
|
243
|
+
</body>
|
|
244
|
+
</html>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# User unit for tailnet-hosted static pages.
|
|
2
|
+
[Unit]
|
|
3
|
+
Description=neurastream static pages
|
|
4
|
+
After=network-online.target
|
|
5
|
+
|
|
6
|
+
[Service]
|
|
7
|
+
ExecStart=%h/.bun/bin/neurastream pages serve
|
|
8
|
+
Restart=on-failure
|
|
9
|
+
RestartSec=5
|
|
10
|
+
|
|
11
|
+
[Install]
|
|
12
|
+
WantedBy=default.target
|