neurastream 0.2.20 → 0.2.21
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 +6 -0
- package/package.json +1 -1
- package/src/adapters/omp/doctor.ts +9 -0
- package/src/adapters/omp/install.ts +29 -4
- package/src/core/uninstall.ts +24 -0
- package/templates/skills/architecture-drilldown/SKILL.md +56 -0
- package/templates/skills/architecture-drilldown/template.html +244 -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
|
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/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"));
|
|
@@ -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>
|