@aidenhq/sdk 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ dependency) and `vendor/proxy`, `vendor/oauth`, `vendor/needs` (vendor connectio
7
7
  Also exported (0.5.0, with `executor` above): `kernel-client` (the module-to-kernel client), `tools-client` (the box's MCP client), `tiers` (risk tiers), `checks`
8
8
  (how check results are read), `repeat` (a repeat read's "unchanged" answer and size-bounded pages), `owner-day`, `attribution`,
9
9
  `maintained-repos`, `instance-paths`, `instance-details`, `pass-rule`, `box-bundle`, `pin-owner`, `churn`, `closed-event`, `for-others`,
10
- `model-text`, `quality`, `task-state-types` and `agent-paused`.
10
+ `model-text`, `quality`, `task-state-types` and `agent-paused`. From 0.5.5: `module-mcp` (a module service's MCP endpoint and Fleet page; its page kit ships in `assets/`), `schedule`, `url-setting`, `number-setting`, `teammate-name`, `face-kit`, `reason-codes`, `card-words` (the board's and compile's shared rules) and `requested-parent`.
11
11
 
12
12
  Every module imports it, the official ones in this repo included: a service depends on an exact version
13
13
  (`"@aidenhq/sdk": "X.Y.Z"`), its `bun.lock` pins the integrity, and its `bunfig.toml` names `minimumReleaseAgeExcludes =
@@ -19,7 +19,7 @@ the engines' `sdk/` folders (each runs from its module folder alone) and two fil
19
19
 
20
20
  Bump `version` in `package.json`: merging the change publishes that version. `.github/workflows/sdk-publish.yml` runs on every
21
21
  push to `main` that touches this folder, skips a version already on npm, and otherwise publishes with npm trusted publishing
22
- (provenance, no token). Pull requests that touch this folder dry-run the same publish, and fail when `src/` or `bin/` changed
22
+ (provenance, no token). Pull requests that touch this folder dry-run the same publish, and fail when `src/`, `bin/` or `assets/` changed
23
23
  without a version bump (services import the published package, so an unpublished change reaches nobody). The pack step
24
24
  (`scripts/sdk-pack.ts`) compiles with this folder's own TypeScript: `bun install --frozen-lockfile --ignore-scripts` here first.
25
25
 
@@ -0,0 +1,142 @@
1
+ :root { color-scheme: light dark; font-family: var(--font-sans, system-ui, sans-serif); font-size: 13.5px; line-height: 1.45; color: var(--color-text-primary, CanvasText); background: transparent;
2
+ --line: var(--color-border-primary, GrayText); --line-strong: var(--color-border-secondary, var(--line)); --soft: var(--color-text-secondary, GrayText); --accent: var(--color-ring-primary, Highlight); --r: var(--border-radius-md, 8px);
3
+ --r-sm: var(--border-radius-sm, 5px); --r-lg: var(--border-radius-lg, 10px); --sh: var(--shadow-sm, none); --sh-hover: var(--shadow-md, 0 4px 14px rgb(0 0 0 / .1));
4
+ --fs-xs: var(--font-text-xs-size, 12px); --hover: color-mix(in srgb, var(--line) 18%, transparent); --ease: cubic-bezier(.16, 1, .3, 1); }
5
+ * { box-sizing: border-box; }
6
+ body { margin: 0; display: grid; gap: 14px; }
7
+ /* A section: a hairline card with its header (title, meta and an action on the right), as the board's SectionCard. */
8
+ .card { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--color-background-primary, Canvas); box-shadow: var(--sh); overflow: hidden; }
9
+ .head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--color-background-secondary, transparent); }
10
+ .head b { font-size: 13.5px; font-weight: 600; }
11
+ .head small, .soft { color: var(--soft); }
12
+ .head small { font-size: var(--fs-xs); }
13
+ .head > :last-child:not(:first-child) { margin-left: auto; }
14
+ .row { display: grid; gap: 10px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line); }
15
+ .row.cols { border-top: 0; padding-top: 7px; padding-bottom: 7px; color: var(--soft); font-size: 12px; background: color-mix(in srgb, var(--line) 12%, transparent); }
16
+ .row:not(.cols) { transition: background .16s var(--ease); }
17
+ .row:not(.cols):hover { background: var(--hover); }
18
+ .row.unsaved { box-shadow: inset 2px 0 0 var(--accent); }
19
+ .repo { font-weight: 560; overflow-wrap: anywhere; }
20
+ .repo i { font-style: normal; font-weight: 400; color: var(--soft); margin-left: 6px; }
21
+ select, input[type=text] { font: inherit; width: 100%; min-width: 0; padding: 4px 8px; height: 28px; border-radius: 6px; border: 1px solid var(--line); background: var(--color-background-primary, Canvas); color: inherit; }
22
+ select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }
23
+ /* Buttons as the board's: hairline, a hover lift, a press that settles, a ring on focus. */
24
+ button { font: inherit; height: 28px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--line-strong); background: var(--color-background-primary, Canvas); color: inherit; cursor: pointer; white-space: nowrap; box-shadow: var(--sh); transition: background .16s var(--ease), box-shadow .16s var(--ease), transform .09s var(--ease); }
25
+ button:not(:disabled):hover { background: color-mix(in srgb, var(--line) 22%, var(--color-background-primary, Canvas)); box-shadow: var(--sh-hover); }
26
+ button:not(:disabled):active { transform: scale(.97); }
27
+ button.primary { background: linear-gradient(135deg, #7c3aed, #3b3be8); border-color: light-dark(transparent, rgb(255 255 255 / .3)); color: #fff; font-weight: 600; height: 32px; padding: 0 16px; box-shadow: inset 0 1px 0 rgb(255 255 255 / .22), 0 1px 3px rgb(59 59 232 / .45); }
28
+ button.primary:not(:disabled):hover { background: linear-gradient(135deg, #7c3aed, #3b3be8); filter: brightness(.9); box-shadow: inset 0 1px 0 rgb(255 255 255 / .22), 0 4px 14px rgb(59 59 232 / .45); }
29
+ button.primary:disabled { background: color-mix(in srgb, var(--line) 22%, var(--color-background-primary, Canvas)); border-color: var(--line); color: var(--soft); box-shadow: none; opacity: 1; }
30
+ button:disabled { opacity: .5; cursor: default; box-shadow: none; }
31
+ .sw { position: relative; width: 34px; height: 20px; padding: 0; border-radius: 6px; background: color-mix(in srgb, var(--line) 55%, transparent); border: 0; transition: background .16s; }
32
+ .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 4px; background: var(--color-background-primary, Canvas); box-shadow: 0 1px 2px rgb(0 0 0 / .3); transition: transform .16s; }
33
+ .sw[aria-checked=true] { background: var(--accent); }
34
+ .sw[aria-checked=true]::after { transform: translateX(14px); }
35
+ .sw.unsaved { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
36
+ .add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
37
+ .add input { flex: 1 1 140px; max-width: 320px; }
38
+ .empty { padding: 14px; color: var(--soft); }
39
+ .empty b { color: var(--color-text-primary, CanvasText); font-weight: 560; }
40
+ .intro { margin: 0; padding: 0 2px; color: var(--soft); max-width: 78ch; }
41
+ .intro code, .tip code, .note code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 0 4px; border-radius: 4px; background: color-mix(in srgb, var(--line) 22%, transparent); }
42
+ .hd { display: inline-flex; align-items: center; gap: 5px; }
43
+ .q { width: 16px; height: 16px; padding: 0; border-radius: 4px; font-size: 11px; font-weight: 600; line-height: 1; color: var(--soft); background: transparent; display: inline-grid; place-items: center; flex: none; }
44
+ .q:hover, .q[aria-expanded=true] { color: var(--color-text-primary, CanvasText); border-color: var(--accent); }
45
+ .tip { position: fixed; z-index: 10; max-width: min(300px, calc(100vw - 16px)); padding: 8px 10px; border-radius: var(--r); border: 1px solid var(--line); background: var(--color-background-primary, Canvas); color: var(--color-text-primary, CanvasText); font-size: 12.5px; line-height: 1.4; box-shadow: 0 6px 20px rgb(0 0 0 / .22); pointer-events: none; }
46
+ .tip[hidden] { display: none; }
47
+ .tip p { margin: 0; }
48
+ .tip p + p, .tip dl { margin-top: 6px; }
49
+ .tip dl { margin-bottom: 0; display: grid; gap: 3px; }
50
+ .tip dt { display: inline; font-weight: 600; }
51
+ .tip dd { display: inline; margin: 0; color: var(--soft); }
52
+ .tip dd::before { content: " "; }
53
+ .tip dt.cur::after { content: " (current)"; font-weight: 400; color: var(--accent); }
54
+ .tip .fine { color: var(--soft); }
55
+ .link { height: auto; padding: 0; border: 0; background: none; color: var(--accent); font-size: 12px; }
56
+ .link:hover { text-decoration: underline; }
57
+ .drawer { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px 18px; padding: 10px 14px 12px; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--line) 8%, transparent); }
58
+ .drawer .grp { grid-column: 1 / -1; margin: 4px 0 -2px; font-weight: 600; font-size: 12px; color: var(--soft); display: flex; gap: 6px; align-items: center; }
59
+ .drawer .grp:first-child { margin-top: 0; }
60
+ .fld { display: grid; gap: 3px; align-content: start; min-width: 0; }
61
+ .fl { font-size: 12.5px; }
62
+ .fld textarea { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; width: 100%; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--color-background-primary, Canvas); color: inherit; resize: vertical; }
63
+ .fld textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
64
+ .checks { display: flex; gap: 12px; flex-wrap: wrap; min-height: 28px; align-items: center; }
65
+ .checks label { display: inline-flex; gap: 5px; align-items: center; }
66
+ .meta { display: flex; gap: 4px 10px; flex-wrap: wrap; color: var(--soft); font-size: 12px; min-width: 0; }
67
+ .meta .dflt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
68
+ .meta .ovr { color: var(--accent); font-weight: 560; }
69
+ .meta .warn { color: var(--color-text-danger, red); flex-basis: 100%; }
70
+ .toggle { display: inline-flex; align-items: center; gap: 5px; }
71
+ .toggle::before { content: ""; width: 5px; height: 5px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .12s; }
72
+ .toggle[aria-expanded=true]::before { transform: rotate(45deg); }
73
+ /* A status tag: plain, or .ok, .needs (waiting on the owner) and .failed, in the host's semantic colours. */
74
+ .tag { display: inline-block; justify-self: start; padding: 1px 7px; border-radius: var(--r-sm); border: 1px solid var(--line); font-size: var(--fs-xs); font-weight: 500; line-height: 1.5; color: var(--soft); white-space: nowrap; }
75
+ .tag.ok { color: var(--color-text-success, green); background: var(--color-background-success, transparent); border-color: transparent; }
76
+ .tag.needs { color: var(--color-text-warning, darkorange); background: var(--color-background-warning, transparent); border-color: transparent; }
77
+ .tag.failed { color: var(--color-text-danger, red); background: var(--color-background-danger, transparent); border-color: transparent; }
78
+ .note { padding: 8px 14px; border-top: 1px solid var(--line); color: var(--soft); }
79
+ .note:empty { display: none; }
80
+ .note.err { color: var(--color-text-danger, red); }
81
+ .lnk { color: var(--accent); cursor: pointer; text-decoration: underline; overflow-wrap: anywhere; }
82
+ .md p, .md ul, .md ol { margin: 0 0 8px; } .md ul, .md ol { padding-left: 20px; } .md h3, .md h4, .md h5, .md h6 { margin: 10px 0 4px; font-size: 13.5px; font-weight: 600; }
83
+ .md pre { margin: 0 0 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; overflow-x: auto; white-space: pre; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
84
+ .md code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 0 4px; border-radius: 4px; background: color-mix(in srgb, var(--line) 22%, transparent); }
85
+ .lab { display: none; color: var(--soft); font-size: 12px; }
86
+ .lab .hd { vertical-align: middle; }
87
+ @media (max-width: 860px) { .row.cols { display: none; } .lab { display: block; margin-bottom: 2px; } }
88
+ .seg { display: inline-flex; max-width: 100%; padding: 2px; gap: 2px; border: 1px solid var(--line); border-radius: 7px; background: color-mix(in srgb, var(--line) 14%, transparent); }
89
+ .seg button { height: 22px; padding: 0 9px; border: 0; border-radius: 5px; background: transparent; color: var(--soft); font-size: 12px; }
90
+ .seg button:hover { color: var(--color-text-primary, CanvasText); }
91
+ .seg button[aria-checked=true] { color: var(--color-text-primary, CanvasText); font-weight: 560; background: color-mix(in srgb, var(--tone, var(--accent)) 20%, var(--color-background-primary, Canvas)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone, var(--accent)) 60%, transparent); }
92
+ .seg [data-v=on], .seg [data-v=ready] { --tone: #2f9e6a; } .seg [data-v=observe] { --tone: #c98a1b; } .seg [data-v=off] { --tone: #8b8f98; }
93
+ .chips { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 28px; padding: 2px 4px; border-radius: 6px; border: 1px solid var(--line); background: var(--color-background-primary, Canvas); }
94
+ .chips:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
95
+ .chips input { flex: 1 1 90px; width: auto; height: 22px; padding: 0 4px; border: 0; outline: 0; background: transparent; }
96
+ .chip { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; padding: 0 2px 0 7px; border-radius: 4px; background: color-mix(in srgb, var(--accent) 14%, transparent); font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
97
+ .chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
98
+ .chip .x { height: 18px; width: 18px; padding: 0; border: 0; background: transparent; color: var(--soft); font-size: 14px; line-height: 1; }
99
+ .chip .x:hover { color: var(--color-text-danger, red); }
100
+ /* Motion and small parts a results-first page uses (Reviews; any page may): a card rises in, a .collapse grows in place (put the content in its one child),
101
+ a quiet and a small button, an auto-width select for a toolbar (a bare select fills its row), and a running tag. */
102
+ @keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
103
+ .card { animation: rise .32s var(--ease) both; }
104
+ .collapse { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .26s var(--ease); }
105
+ .collapse.open { grid-template-rows: 1fr; }
106
+ .collapse > * { overflow: hidden; min-height: 0; }
107
+ button.quiet { border-color: transparent; background: none; box-shadow: none; color: var(--soft); }
108
+ button.sm { height: 24px; padding: 0 9px; font-size: 12px; }
109
+ select.pick { width: auto; max-width: 100%; }
110
+ .tag.run { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border-color: transparent; }
111
+ /* The model picker (modelPicker in page-kit.js), the twin of the board's ModelPicker. The panel is a popover (top layer): no card or dialog clips it; the script sets its place. */
112
+ .mp { position: relative; min-width: 0; width: 100%; }
113
+ .mp-trigger { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; height: auto; min-height: 38px; padding: 4px 10px; text-align: left; border-radius: 6px; border-color: var(--line); box-shadow: none; }
114
+ .mp-trigger[aria-expanded=true] { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 0; }
115
+ .mp-tn { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
116
+ .mp-tn b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
117
+ .mp-tn span { font-size: var(--fs-xs); color: var(--soft); overflow: hidden; text-overflow: ellipsis; }
118
+ .mp-none { color: var(--soft); font-weight: 400; }
119
+ .mp-chev { flex: none; width: 7px; height: 7px; margin: -3px 2px 0 0; border-right: 1.5px solid var(--soft); border-bottom: 1.5px solid var(--soft); transform: rotate(45deg); }
120
+ .mp-panel { position: fixed; inset: auto; margin: 0; padding: 0; flex-direction: column; overflow: hidden; background: var(--color-background-primary, Canvas); color: var(--color-text-primary, CanvasText); border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-lg, 0 8px 32px rgb(0 0 0 / .22)); font-size: 13.5px; }
121
+ .mp-panel:popover-open { display: flex; }
122
+ .mp-search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-bottom: 1px solid var(--line); color: var(--soft); }
123
+ .mp-search:focus-within { box-shadow: inset 0 -2px 0 var(--accent); }
124
+ .mp-mag { flex: none; width: 9px; height: 9px; border: 1.5px solid currentColor; border-radius: 50%; position: relative; margin-right: 3px; }
125
+ .mp-mag::after { content: ""; position: absolute; width: 5px; height: 1.5px; background: currentColor; right: -5px; bottom: -2px; transform: rotate(45deg); }
126
+ .mp-search input.mp-q { flex: 1; min-width: 0; width: auto; height: 38px; padding: 0; border: 0; border-radius: 0; background: none; outline: none; font-size: 14px; }
127
+ .mp-list { list-style: none; margin: 0; padding: 4px; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
128
+ .mp-head { position: sticky; top: -4px; z-index: 1; padding: 8px 8px 4px; background: var(--color-background-primary, Canvas); font-size: var(--fs-xs); font-weight: 600; color: var(--soft); }
129
+ .mp-opt { display: flex; align-items: baseline; gap: 8px; padding: 6px 8px 6px 4px; border-radius: 4px; cursor: pointer; }
130
+ .mp-opt[data-active=true] { background: var(--hover); }
131
+ .mp-check { flex: none; width: 16px; align-self: center; display: inline-flex; justify-content: center; }
132
+ .mp-tick { width: 9px; height: 5px; margin-top: -3px; border-left: 2px solid var(--accent); border-bottom: 2px solid var(--accent); transform: rotate(-45deg); }
133
+ .mp-opt[aria-selected=true] .mp-nm { font-weight: 650; }
134
+ .mp-nm { font-weight: 500; white-space: nowrap; }
135
+ .mp-nm.mp-use { white-space: normal; overflow-wrap: anywhere; }
136
+ .mp-sug { font-style: normal; font-size: var(--fs-xs); font-weight: 600; line-height: 18px; padding: 0 6px; border-radius: 4px; border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); white-space: nowrap; }
137
+ .mp-id { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--soft); }
138
+ .mp-meta { flex: none; font-size: var(--fs-xs); color: var(--soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
139
+ .mp-empty { padding: 14px 12px; color: var(--soft); }
140
+ .mp-foot { padding: 6px 12px; border-top: 1px solid var(--line); background: var(--color-background-secondary, transparent); font-size: var(--fs-xs); color: var(--soft); }
141
+ @media (max-width: 560px) { .mp-id { display: none; } .mp-opt { padding-block: 10px; } }
142
+ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } button:not(:disabled):active { transform: none; } }
@@ -0,0 +1,311 @@
1
+ // The view's half of the MCP Apps bridge (JSON-RPC 2.0 over postMessage to window.parent) and the small helpers every module page uses.
2
+ let next = 1;
3
+ const waiting = new Map();
4
+ const send = (method, params) => new Promise((ok, ko) => { const id = next++; waiting.set(id, { ok, ko }); parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*"); });
5
+ const notify = (method, params) => parent.postMessage({ jsonrpc: "2.0", method, params }, "*");
6
+ const theme = (ctx) => { for (const [k, v] of Object.entries(ctx?.styles?.variables ?? {})) if (v) document.documentElement.style.setProperty(k, v); if (ctx?.theme) document.documentElement.style.colorScheme = ctx.theme; };
7
+ // The part of this frame the host shows (its host context's frameViewport, { top, height, width } in this frame's coordinates): the
8
+ // board shows the frame inline in its own scrolling page, so the frame's innerHeight runs far below the fold. Kept from the last context.
9
+ let frameViewport = null, mpOpen = null;
10
+ const hostContext = (ctx) => { if (ctx?.frameViewport) frameViewport = ctx.frameViewport; theme(ctx); };
11
+ addEventListener("message", (e) => {
12
+ if (e.source !== parent) return;
13
+ // The host's theme or the visible part of the frame changed (a scroll, a resize): restyle, and keep an open picker with its trigger
14
+ // (re-place it while the trigger is still in sight, close it once the board's scroll has carried the trigger out of sight).
15
+ if (e.data?.method === "ui/notifications/host-context-changed") { hostContext(e.data.params); mpOpen?.keep?.(); return; }
16
+ const w = waiting.get(e.data?.id);
17
+ if (!w) return;
18
+ waiting.delete(e.data.id);
19
+ e.data.error ? w.ko(new Error(e.data.error.message)) : w.ok(e.data.result);
20
+ });
21
+ // In the owner's Claude the host fences every string the tool answers as untrusted data: read the value out of the fence (it still only ever reaches the page as text).
22
+ const unfence = (v) => typeof v === "string" ? (v.match(/^<untrusted-data[^>]*>([\s\S]*)<\/untrusted-data>$/)?.[1] ?? v).replace(/&lt;(\/?untrusted-data)/gi, "<$1") : Array.isArray(v) ? v.map(unfence) : v && typeof v === "object" ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, unfence(x)])) : v;
23
+ const tool = async (name, args) => { const r = await send("tools/call", { name, arguments: args }); if (r?.isError) throw new Error(r.content?.[0]?.text ?? "failed"); return unfence(r.structuredContent ?? {}); };
24
+ new ResizeObserver(() => { const r = document.body.getBoundingClientRect(); notify("ui/notifications/size-changed", { width: Math.ceil(r.width), height: Math.ceil(r.height) }); }).observe(document.body);
25
+ // A message to the owner's chat with the host (ui/message): the host opens its assistant with the text ready to send.
26
+ const ask = (text) => send("ui/message", { role: "user", content: [{ type: "text", text }] });
27
+ const $ = (id) => document.getElementById(id);
28
+ const h = (tag, props, ...kids) => { const el = Object.assign(document.createElement(tag), props); el.append(...kids.filter((k) => k !== null)); return el; };
29
+ const say = (t, err) => { $("note").textContent = t; $("note").className = err ? "note err" : "note"; };
30
+ // Proposal requests run one after another, so the last answer is the latest draft (the host shows each answer as the proposal).
31
+ let queue = Promise.resolve();
32
+ const inOrder = (fn) => (queue = queue.then(fn, fn));
33
+ const proposed = (r) => say(`Changes are proposed; Save in the bar above applies them. ${(r.changes ?? []).join("; ")}.`);
34
+ const setSwitch = (b, on) => b.setAttribute("aria-checked", String(!!on));
35
+ const toggle = (on, label, fn) => { const b = h("button", { className: "sw", role: "switch", ariaLabel: label }); setSwitch(b, on); b.addEventListener("click", fn); return b; };
36
+ // A link: the frame can't navigate, so a click asks the host (ui/open-link) to open it in a new tab. Only http(s) addresses are links; any other is plain text.
37
+ const link = (url, text) => {
38
+ if (!/^https?:\/\//i.test(String(url ?? ""))) return h("span", { textContent: text ?? String(url ?? "") });
39
+ const a = h("a", { href: url, textContent: text ?? url, className: "lnk", rel: "noopener noreferrer" });
40
+ const open = (e) => { e.preventDefault(); send("ui/open-link", { url }).catch((err) => say(err.message, true)); };
41
+ a.addEventListener("click", open); a.addEventListener("auxclick", open);
42
+ return a;
43
+ };
44
+ // A small safe markdown: headings, lists, fenced code, bold, italics, `code` and [text](http…) links. Built from text nodes only, so nothing in the source is ever HTML; a table or quote is shown as preformatted text.
45
+ const mdInline = (text) => {
46
+ const out = [], re = /`([^`]+)`|\*\*([^*]+)\*\*|\*([^*\s][^*]*)\*|\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g;
47
+ let i = 0, m;
48
+ while ((m = re.exec(text))) {
49
+ if (m.index > i) out.push(text.slice(i, m.index));
50
+ out.push(m[1] !== undefined ? h("code", { textContent: m[1] }) : m[2] !== undefined ? h("b", { textContent: m[2] }) : m[3] !== undefined ? h("i", { textContent: m[3] }) : link(m[5], m[4]));
51
+ i = re.lastIndex;
52
+ }
53
+ if (i < text.length) out.push(text.slice(i));
54
+ return out;
55
+ };
56
+ const md = (src) => {
57
+ const root = h("div", { className: "md" }), lines = String(src ?? "").replace(/\r/g, "").split("\n");
58
+ let para = [], list = null, i = 0;
59
+ const flush = () => { if (para.length) root.append(h("p", {}, ...mdInline(para.join(" ")))); para = []; list = null; };
60
+ while (i < lines.length) {
61
+ const l = lines[i];
62
+ if (/^```/.test(l)) { flush(); const code = []; for (i++; i < lines.length && !/^```/.test(lines[i]); i++) code.push(lines[i]); i++; root.append(h("pre", { textContent: code.join("\n") })); continue; }
63
+ const hd = /^(#{1,6})\s+(.*)$/.exec(l), li = /^(\s*)([-*]|\d+\.)\s+(.*)$/.exec(l);
64
+ if (hd) { flush(); root.append(h(`h${Math.min(6, hd[1].length + 2)}`, {}, ...mdInline(hd[2]))); }
65
+ else if (li) { const kind = /\d/.test(li[2]) ? "ol" : "ul"; if (!list || list.kind !== kind) { para.length && flush(); list = { kind, el: h(kind, {}) }; root.append(list.el); } list.el.append(h("li", { style: li[1].length ? `margin-left:${Math.min(6, li[1].length / 2) * 14}px` : "" }, ...mdInline(li[3]))); }
66
+ else if (/^\s*\|/.test(l) || /^>/.test(l)) { flush(); const rows = []; for (; i < lines.length && (/^\s*\|/.test(lines[i]) || /^>/.test(lines[i])); i++) rows.push(lines[i]); root.append(h("pre", { textContent: rows.join("\n") })); continue; }
67
+ else if (!l.trim()) flush();
68
+ else { list = null; para.push(l.trim()); }
69
+ i++;
70
+ }
71
+ flush();
72
+ return root;
73
+ };
74
+ // The help "?" next to a label: help(label, text, { options: { value: meaning }, current, note }) returns the label with its button. One shared
75
+ // tooltip (role=tooltip) opens on hover, on keyboard focus and on tap (a tap pins it; tap again, Escape or a tap elsewhere closes it), and is
76
+ // placed by the button inside the frame, so no card clips it. Call closeHelp() when a render replaces the buttons.
77
+ const tipEl = h("div", { id: "tip", className: "tip", role: "tooltip", hidden: true });
78
+ document.body.append(tipEl);
79
+ let tipFor = null, tipPinned = false;
80
+ const closeHelp = () => { tipEl.hidden = true; if (tipFor) tipFor.btn.setAttribute("aria-expanded", "false"); tipFor = null; tipPinned = false; };
81
+ const openHelp = (btn, c) => {
82
+ if (tipFor && tipFor.btn !== btn) closeHelp();
83
+ tipFor = { btn, c }; btn.setAttribute("aria-expanded", "true");
84
+ tipEl.replaceChildren(h("p", { textContent: c.text }), ...(c.options ? [h("dl", {}, ...Object.entries(c.options).flatMap(([v, m]) => [h("dt", { textContent: v, className: String(v) === String(c.current) ? "cur" : "" }), h("dd", { textContent: m })]))] : []), ...(c.note ? [h("p", { className: "fine", textContent: c.note })] : []));
85
+ tipEl.hidden = false;
86
+ const b = btn.getBoundingClientRect(), t = tipEl.getBoundingClientRect(), vw = innerWidth, vh = innerHeight;
87
+ const below = b.bottom + 6 + t.height <= vh || (b.top - 6 - t.height < 0 && vh - b.bottom >= b.top);
88
+ tipEl.style.left = `${Math.max(8, Math.min(b.left + b.width / 2 - t.width / 2, vw - t.width - 8))}px`;
89
+ tipEl.style.top = `${Math.max(4, Math.min(below ? b.bottom + 6 : b.top - 6 - t.height, vh - t.height - 4))}px`;
90
+ };
91
+ addEventListener("keydown", (e) => { if (e.key === "Escape") closeHelp(); });
92
+ addEventListener("pointerdown", (e) => { if (tipFor && e.target !== tipFor.btn) closeHelp(); });
93
+ addEventListener("resize", closeHelp);
94
+ let helpN = 0;
95
+ const help = (label, text, more = {}) => {
96
+ const c = { text, ...more }, btn = h("button", { type: "button", className: "q", textContent: "?", ariaLabel: `About ${label}` });
97
+ // The button's own description (hidden text, read by a screen reader); the shared tooltip is its sighted twin.
98
+ const did = `hd${++helpN}`, desc = [text, ...Object.entries(more.options ?? {}).map(([v, m]) => `${v}: ${m}`), more.note].filter(Boolean).join(" ");
99
+ const dsc = h("span", { id: did, hidden: true, textContent: desc });
100
+ btn.setAttribute("aria-describedby", did); btn.setAttribute("aria-expanded", "false");
101
+ btn.addEventListener("mouseenter", () => openHelp(btn, c));
102
+ btn.addEventListener("mouseleave", () => { if (!tipPinned) closeHelp(); });
103
+ btn.addEventListener("focus", () => openHelp(btn, c));
104
+ btn.addEventListener("blur", closeHelp);
105
+ btn.addEventListener("click", () => { if (tipFor?.btn === btn && tipPinned) closeHelp(); else { openHelp(btn, c); tipPinned = true; } });
106
+ return h("span", { className: "hd" }, more.bare ? null : label, btn, dsc);
107
+ };
108
+ // "3 hours ago" for an ISO time, or "" when there is none.
109
+ const ago = (iso) => { const s = (Date.now() - Date.parse(iso)) / 1000; if (!(s >= 0)) return ""; const [n, u] = s < 90 ? [0, ""] : s < 5400 ? [Math.round(s / 60), "minute"] : s < 172800 ? [Math.round(s / 3600), "hour"] : [Math.round(s / 86400), "day"]; return u ? `${n} ${u}${n === 1 ? "" : "s"} ago` : "just now"; };
110
+ // The Settings drawers: one field = a help label, an editor and a meta line. editor({ kind: select | checks | list | num | text, label, value, values, titles, f, set })
111
+ // builds the control (list: one item per line; num: blank = null, else a whole number); set(value, live) runs as you type (live: no redraw) and on the change, and
112
+ // keepFocus(render) puts the focus back on the control with the same data-f after a render replaced it.
113
+ // soon(fn): run fn after the current event, and after a pressed pointer is released (a redraw between a press and its click would lose the click); a newer soon(fn) of the same fn replaces a pending one.
114
+ let pointerDown = false, queued = null;
115
+ for (const [e, v] of [["pointerdown", true], ["pointerup", false], ["pointercancel", false]]) addEventListener(e, () => { pointerDown = v; }, true);
116
+ const soon = (fn) => { queued = fn; const go = () => setTimeout(() => { if (queued === fn) { queued = null; fn(); } }, 0); if (pointerDown) addEventListener("pointerup", go, { once: true }); else go(); };
117
+ const keepFocus = (fn) => { const f = document.activeElement?.dataset?.f; fn(); if (f) document.querySelector(`[data-f="${CSS.escape(f)}"]`)?.focus(); };
118
+ const lines = (t) => t.split("\n").map((s) => s.trim()).filter(Boolean);
119
+ const editor = (k) => {
120
+ const fire = (el, ev, get) => el.addEventListener(ev, () => { const v = get(); if (v !== undefined) k.set(v); });
121
+ if (k.kind === "checks") return h("div", { className: "checks" }, ...k.values.map((v) => { const c = h("input", { type: "checkbox", checked: (k.value ?? []).includes(v), title: k.titles?.[v] }); c.dataset.f = `${k.f}:${v}`; c.addEventListener("change", () => k.set(k.values.filter((x) => x === v ? c.checked : (k.value ?? []).includes(x)))); return h("label", {}, c, v); }));
122
+ if (k.kind === "seg") return h("div", { className: "seg", role: "radiogroup", ariaLabel: k.label }, ...k.values.map((v, i) => { const b = h("button", { type: "button", role: "radio", textContent: v, title: k.titles?.[v] }); b.setAttribute("aria-checked", String(v === k.value)); b.tabIndex = v === k.value ? 0 : -1; b.dataset.v = v; b.dataset.f = `${k.f}:${v}`; b.addEventListener("click", () => { if (v !== k.value) k.set(v); });
123
+ b.addEventListener("keydown", (e) => { const d = { ArrowRight: 1, ArrowDown: 1, ArrowLeft: -1, ArrowUp: -1 }[e.key]; if (d) { e.preventDefault(); const n = (i + d + k.values.length) % k.values.length; e.currentTarget.parentNode.children[n].focus(); k.set(k.values[n]); } }); return b; }));
124
+ if (k.kind === "chips") {
125
+ // One entry per chip; Enter (or leaving the box) adds what is typed, a multi-line paste adds one chip per line, and in a list that is not ordered (no k.dups) a comma-separated one too (a comma inside {braces} stays). k.dups allows a repeated entry (an ordered list).
126
+ let items = k.value ?? [];
127
+ const inp = h("input", { type: "text", ariaLabel: k.label, placeholder: k.placeholder ?? "Add one, press Enter", autocomplete: "off", spellcheck: false });
128
+ inp.dataset.f = k.f;
129
+ const put = (list) => { items = list; k.set(list); };
130
+ // A list pasted as lines or commas; a comma inside {braces} (nested too) or [brackets] belongs to a glob.
131
+ const splitList = (t) => { const out = [""]; let d = 0; for (const c of t) { if (c === "{" || c === "[") d++; else if ((c === "}" || c === "]") && d) d--; if (c === "\n" || (c === "," && !d)) out.push(""); else out[out.length - 1] += c; } return out; };
132
+ // What is typed is part of the draft before Enter, so a proposal made as the owner types (and Save) already carries it. `taken` is the
133
+ // entry a removal already put in the list while the box still shows it: it is never added a second time (an ordered list allows dups).
134
+ let taken = null;
135
+ // A `taken` entry is only skipped while a chip still carries it; once that chip is removed the text is pending again.
136
+ const pending = () => { const v = inp.value.trim(); if (v && taken === v && !items.includes(v)) taken = null; return v && v !== taken && (k.dups || !items.includes(v)) ? [...items, v] : items; };
137
+ const add = (vs) => { inp.value = ""; const was = taken; taken = null; const more = vs.map((x) => x.trim()).filter((x, i, all) => x && x !== was && (k.dups || (!items.includes(x) && all.indexOf(x) === i))); if (more.length) put([...items, ...more]); };
138
+ inp.addEventListener("keydown", (e) => { if (e.key === "Enter") { e.preventDefault(); add([inp.value]); } else if (e.key === "Backspace" && !inp.value && items.length) put(items.slice(0, -1)); });
139
+ inp.addEventListener("paste", (e) => { const t = e.clipboardData?.getData("text") ?? ""; if (!/[\n,]/.test(t)) return; e.preventDefault(); const all = inp.value.slice(0, inp.selectionStart) + t + inp.value.slice(inp.selectionEnd); add(k.dups ? all.split("\n") : splitList(all)); });
140
+ // What is typed is proposed with the list as you type (no redraw, so the caret stays): Save always carries it, with or without Enter.
141
+ let typing; inp.addEventListener("input", () => { clearTimeout(typing); if (inp.value.trim() !== taken) taken = null; typing = setTimeout(() => { if (inp.isConnected) k.set(pending(), true); }, 200); });
142
+ // Removing a chip keeps what is typed but not yet added: it is a chip of the same draft, so a save after the click does not drop it,
143
+ // and `taken` keeps a second removal or a late debounce from adding it again.
144
+ return h("div", { className: "chips" }, ...items.map((x, i) => { const b = h("button", { type: "button", className: "x", ariaLabel: `Remove ${x}`, textContent: "\u00d7" }); b.addEventListener("click", () => { const v = inp.value.trim(), list = pending(); if (v && list.length > items.length) taken = v; put(list.filter((_, j) => j !== i)); }); return h("span", { className: "chip", title: x }, h("span", { textContent: x }), b); }), inp);
145
+ }
146
+ const el = k.kind === "select" ? h("select", { ariaLabel: k.label }, ...k.values.map((v) => h("option", { value: v, textContent: v, title: k.titles?.[v], selected: v === k.value })))
147
+ : k.kind === "list" ? h("textarea", { rows: Math.min(6, Math.max(2, (k.value ?? []).length)), value: (k.value ?? []).join("\n"), ariaLabel: k.label, spellcheck: false })
148
+ : h("input", { type: "text", value: k.value ?? "", ariaLabel: k.label, autocomplete: "off", spellcheck: false, placeholder: k.placeholder ?? (k.kind === "num" ? "unlimited" : "") });
149
+ el.dataset.f = k.f;
150
+ // A text control proposes as you type (after a short pause, without a redraw, so the caret stays) and again on change, so the proposal the host shows is the latest by the time Save is pressed.
151
+ const read = (quiet) => k.kind === "list" ? lines(el.value) : k.kind === "num" ? (el.value.trim() === "" ? null : Number.isInteger(Number(el.value)) && Number(el.value) >= 0 ? Number(el.value) : (quiet || say("Use a whole number, or leave it blank.", true), undefined)) : el.value;
152
+ let typing; if (k.kind !== "select") el.addEventListener("input", () => { clearTimeout(typing); typing = setTimeout(() => { const v = read(true); if (v !== undefined) k.set(v, true); }, 200); });
153
+ el.addEventListener("change", () => { clearTimeout(typing); const v = read(false); if (v !== undefined) k.set(v); });
154
+ return el;
155
+ };
156
+ // One labelled field of a drawer: help label, editor, then a meta line (default, overridden mark, reset).
157
+ const fld = (label, text, more, ed, ...meta) => h("div", { className: "fld" }, h("div", { className: "fl" }, help(label, text, more)), ed, h("div", { className: "meta" }, ...meta.filter((m) => m)));
158
+ const linkBtn = (text, fn) => { const b = h("button", { type: "button", className: "link", textContent: text }); b.addEventListener("click", fn); return b; };
159
+ // The model picker, the twin of the board's ModelPicker.tsx: a trigger showing the model's plain name over its id, and a searchable list under it
160
+ // (a popover, so a card or dialog can't clip it): Recommended first, then by provider, a "Suggested" tag, a check on the current row, a count footer,
161
+ // arrows + Enter + Escape. modelPicker({ label, value, models, onChange, recommended, suggested, none, custom, name }) returns the element.
162
+ // models ids, or { id, name?, provider?, meta? } (a name and provider are made from the id when absent)
163
+ // recommended ids listed first (default: all of models); the rest are grouped by provider
164
+ // suggested the id that carries the "Suggested" tag
165
+ // none words for "no model" (a first row that picks ""; the trigger says them while the value is blank)
166
+ // custom a typed id that is not listed can be used as it is (a "Use ..." row)
167
+ // usable(id) whether the active provider can run that id: the list and the typed "Use" row offer only ids it can run, so a click
168
+ // and Enter both pick a model the page will accept
169
+ // name the name of the hidden input that carries the chosen id (for a page that submits a form)
170
+ // onChange(id) runs on a pick.
171
+ const MP_WORDS = { gpt: "GPT", glm: "GLM", deepseek: "DeepSeek", openai: "OpenAI", qwen: "Qwen", llm: "LLM", ai: "AI" };
172
+ const MP_VENDORS = { openai: "OpenAI", deepseek: "DeepSeek", "x-ai": "xAI", "meta-llama": "Meta", mistralai: "Mistral", moonshotai: "Moonshot AI", "z-ai": "Z.ai" };
173
+ const mpShort = (id) => String(id ?? "").replace(/^~/, "");
174
+ // "~openai/gpt-6.2-sol-latest" -> "GPT 6.2 Sol"; "claude-opus-4-7" -> "Claude Opus 4.7".
175
+ const mpName = (id) => mpShort(id).split("/").pop().split(":")[0].replace(/-latest$/, "").split("-").reduce((out, w) => {
176
+ if (/^\d{1,2}$/.test(w) && /^\d+(\.\d+)*$/.test(out[out.length - 1] ?? "")) out[out.length - 1] += `.${w}`; else out.push(w);
177
+ return out;
178
+ }, []).map((w) => MP_WORDS[w.toLowerCase()] ?? w.replace(/^./, (c) => c.toUpperCase())).join(" ");
179
+ const mpProvider = (id) => { const v = mpShort(id).split("/"); return v.length > 1 ? MP_VENDORS[v[0]] ?? v[0].replace(/^./, (c) => c.toUpperCase()) : ""; };
180
+ let mpN = 0;
181
+ // A manual popover stays open by itself: the open picker closes on a press elsewhere, a scroll or resize of the page, and when the frame loses focus.
182
+ addEventListener("pointerdown", (e) => { if (mpOpen && !mpOpen.has(e.target)) mpOpen.close(false); }, true);
183
+ addEventListener("resize", () => mpOpen?.close(false));
184
+ addEventListener("blur", () => mpOpen?.close(false));
185
+ addEventListener("scroll", (e) => { if (mpOpen && !mpOpen.has(e.target)) mpOpen.close(false); }, true);
186
+ // A phone keyboard shrinks the visual viewport without a window resize (opening the picker focuses its search box): re-place the open
187
+ // panel then, so it keeps to what is actually in sight rather than the size it had before the keyboard rose.
188
+ visualViewport?.addEventListener("resize", () => mpOpen?.keep?.());
189
+ const modelPicker = (k) => {
190
+ const uid = `mp${++mpN}`;
191
+ const rows = (k.models ?? []).map((m) => (typeof m === "string" ? { id: m } : m)).map((m) => ({ ...m, name: m.name ?? mpName(m.id), provider: m.provider ?? mpProvider(m.id) }));
192
+ const rec = new Set(k.recommended ?? rows.map((r) => r.id));
193
+ const info = (id) => rows.find((r) => r.id === id) ?? { id, name: mpName(id), provider: mpProvider(id) };
194
+ let value = k.value ?? "", query = "", act = 0, items = [];
195
+ const trigger = h("button", { type: "button", className: "mp-trigger" });
196
+ trigger.dataset.f = k.label; trigger.setAttribute("aria-haspopup", "listbox"); trigger.setAttribute("aria-expanded", "false"); trigger.setAttribute("aria-controls", `${uid}-list`);
197
+ const field = h("input", { type: "hidden", name: k.name ?? "" });
198
+ const paint = () => {
199
+ const cur = value ? info(value) : null, none = k.none ?? "Choose a model";
200
+ trigger.replaceChildren(h("span", { className: "mp-tn" }, h("b", { className: cur ? "" : "mp-none", textContent: cur ? cur.name : none }), cur ? h("span", { textContent: mpShort(value) }) : null), h("span", { className: "mp-chev", ariaHidden: "true" }));
201
+ trigger.setAttribute("aria-label", `${k.label}: ${cur ? cur.name : none}`);
202
+ field.value = value;
203
+ };
204
+ const input = h("input", { type: "text", className: "mp-q", placeholder: "Search by name, id or provider", ariaLabel: "Search models", autocomplete: "off", spellcheck: false });
205
+ input.setAttribute("role", "combobox"); input.setAttribute("aria-controls", `${uid}-list`); input.setAttribute("aria-expanded", "true");
206
+ const list = h("ul", { className: "mp-list", id: `${uid}-list`, role: "listbox", ariaLabel: k.label });
207
+ const foot = h("span", {});
208
+ const panel = h("div", { className: "mp-panel" }, h("div", { className: "mp-search" }, h("span", { className: "mp-mag", ariaHidden: "true" }), input), list, h("div", { className: "mp-foot" }, foot));
209
+ panel.setAttribute("popover", "manual");
210
+ // A sticky group heading (`.mp-head`, ~28px tall) sits over the list's top edge, so a row brought to "nearest" would hide under it;
211
+ // scroll by hand with that inset, and likewise keep the row off the bottom edge.
212
+ const HEAD_INSET = 30;
213
+ const reveal = (li) => {
214
+ const box = list.getBoundingClientRect(), r = li.getBoundingClientRect();
215
+ if (r.top < box.top + HEAD_INSET) list.scrollTop -= box.top + HEAD_INSET - r.top;
216
+ else if (r.bottom > box.bottom) list.scrollTop += Math.min(r.bottom - box.bottom, r.top - box.top - HEAD_INSET);
217
+ };
218
+ const mark = (scroll) => {
219
+ [...list.querySelectorAll(".mp-opt")].forEach((li, i) => { li.dataset.active = String(i === act); });
220
+ const li = list.querySelector(`#${uid}-o${act}`);
221
+ if (li) { input.setAttribute("aria-activedescendant", li.id); if (scroll) reveal(li); } else input.removeAttribute("aria-activedescendant");
222
+ };
223
+ const build = () => {
224
+ const q = query.trim().toLowerCase(), typed = query.trim(), fits = (id) => !k.usable || k.usable(id), hit = rows.filter((r) => fits(r.id) && (!q || `${r.name} ${r.id} ${r.provider}`.toLowerCase().includes(q)));
225
+ const groups = [{ title: "Recommended", rs: hit.filter((r) => rec.has(r.id)) }], by = new Map();
226
+ for (const r of hit.filter((x) => !rec.has(x.id))) by.set(r.provider || "Other", [...(by.get(r.provider || "Other") ?? []), r]);
227
+ for (const p of [...by.keys()].sort()) groups.push({ title: p, rs: by.get(p) });
228
+ items = [];
229
+ if (k.none && !q) items.push({ id: "", label: k.none, none: true });
230
+ for (const g of groups) for (const r of g.rs) items.push({ ...r, group: g.title });
231
+ if (k.custom && typed && fits(typed) && !rows.some((r) => r.id === typed)) items.push({ id: typed, label: `Use "${typed}"`, custom: true });
232
+ act = q ? 0 : Math.max(0, items.findIndex((i) => i.id === value));
233
+ const kids = []; let last = null;
234
+ items.forEach((it, i) => {
235
+ if (it.group && it.group !== last) { kids.push(h("li", { className: "mp-head", role: "presentation", textContent: it.group })); }
236
+ if (it.group) last = it.group;
237
+ const on = !it.custom && it.id === value;
238
+ const li = h("li", { className: "mp-opt", id: `${uid}-o${i}`, role: "option" }, h("span", { className: "mp-check" }, on ? h("span", { className: "mp-tick" }) : null),
239
+ ...(it.label ? [h("span", { className: it.none ? "mp-nm mp-none" : it.custom ? "mp-nm mp-use" : "mp-nm", textContent: it.label })]
240
+ : [h("span", { className: "mp-nm", textContent: it.name }), it.id === k.suggested ? h("i", { className: "mp-sug", textContent: "Suggested" }) : null, h("span", { className: "mp-id", textContent: mpShort(it.id) }), it.meta ? h("span", { className: "mp-meta", textContent: it.meta }) : null]));
241
+ li.setAttribute("aria-selected", String(on));
242
+ li.addEventListener("pointermove", () => { if (act !== i) { act = i; mark(false); } });
243
+ li.addEventListener("click", () => pick(it.id));
244
+ kids.push(li);
245
+ });
246
+ if (!items.length) kids.push(h("li", { className: "mp-empty", role: "presentation", textContent: `No model matches "${typed}".` }));
247
+ list.replaceChildren(...kids);
248
+ const n = items.filter((i) => !i.label).length;
249
+ foot.textContent = `${n} model${n === 1 ? "" : "s"}`;
250
+ mark(true);
251
+ };
252
+ // The frame's visible part, not its whole document: the board shows the frame inline inside its own scrolling page, so the bottom
253
+ // of `innerHeight` may be far below what the owner can see. The host sends that slice (frameViewport, this frame's coordinates);
254
+ // without it (another host, or before the first context) this frame is all shown. A phone keyboard shrinks the visual viewport
255
+ // without changing innerHeight, so the slice also ends at it.
256
+ const viewport = () => {
257
+ const vv = visualViewport, top = Math.max(frameViewport?.top ?? 0, vv?.offsetTop ?? 0), vvBottom = (vv?.offsetTop ?? 0) + (vv?.height ?? innerHeight);
258
+ const hostBottom = frameViewport ? frameViewport.top + frameViewport.height : innerHeight;
259
+ return { top, bottom: Math.min(hostBottom, vvBottom), width: Math.min(innerWidth, frameViewport?.width ?? innerWidth) };
260
+ };
261
+ const place = () => {
262
+ const v = viewport(), b = trigger.getBoundingClientRect(), vw = v.width, narrow = vw <= 560, w = narrow ? vw - 16 : Math.min(560, vw - 16);
263
+ // Room under the trigger down to what is visible, and above it up to the top of it (a trigger a keyboard covers counts as at the
264
+ // slice's bottom edge, so the panel sits in the visible part); open where the panel fits (300px), else on
265
+ // the larger side, never past the visible edge.
266
+ const below = v.bottom - b.bottom - 8, edge = Math.min(b.top, v.bottom), above = edge - v.top - 8, down = below >= 300 || below >= above, room = Math.max(160, down ? below : above);
267
+ Object.assign(panel.style, { width: `${w}px`, left: `${narrow ? 8 : Math.max(8, Math.min(b.left, vw - w - 8))}px`, maxHeight: `${Math.min(room, 420)}px`, top: down ? `${b.bottom + 4}px` : "auto", bottom: down ? "auto" : `${innerHeight - edge + 4}px` });
268
+ };
269
+ // After the host's page moved (its scroll, a resize), an open picker stays only while its trigger is in the visible slice: with the
270
+ // trigger scrolled out, a panel clamped to the edge would sit by nothing and a later Enter would pick a model the owner can't see.
271
+ const keep = () => {
272
+ if (!isOpen()) return;
273
+ const v = viewport(), b = trigger.getBoundingClientRect();
274
+ // A phone keyboard only lifts the bottom of the slice: while the search field is focused, a trigger under it keeps its picker open.
275
+ if (b.bottom <= v.top || (b.top >= v.bottom && document.activeElement !== input)) close(false); else place();
276
+ };
277
+ const isOpen = () => panel.matches(":popover-open");
278
+ const close = (refocus) => {
279
+ if (!isOpen()) return;
280
+ panel.hidePopover(); trigger.setAttribute("aria-expanded", "false"); if (mpOpen?.close === close) mpOpen = null; if (refocus) trigger.focus();
281
+ };
282
+ const open = () => {
283
+ mpOpen?.close(false); mpOpen = { close, keep, has: (n) => panel.contains(n) || trigger.contains(n) }; query = ""; input.value = ""; build(); place();
284
+ panel.showPopover(); trigger.setAttribute("aria-expanded", "true"); input.focus(); mark(true);
285
+ };
286
+ // A pick redraws the page, which may replace this trigger: the focus goes to its twin (same data-f).
287
+ const refocus = () => { if (!trigger.isConnected && document.activeElement === document.body) document.querySelector(`.mp-trigger[data-f="${CSS.escape(k.label)}"]`)?.focus(); };
288
+ const pick = (id) => { const same = id === value; value = id; paint(); close(true); if (same) return; k.onChange?.(id); refocus(); setTimeout(refocus, 0); };
289
+ trigger.addEventListener("click", () => (isOpen() ? close(true) : open()));
290
+ trigger.addEventListener("keydown", (e) => { if (e.key === "ArrowDown" || e.key === "ArrowUp") { e.preventDefault(); if (!isOpen()) open(); } });
291
+ input.addEventListener("input", () => { query = input.value; build(); });
292
+ input.addEventListener("keydown", (e) => {
293
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") { e.preventDefault(); if (items.length) { act = (act + (e.key === "ArrowDown" ? 1 : -1) + items.length) % items.length; mark(true); } }
294
+ else if (e.key === "Enter") {
295
+ e.preventDefault();
296
+ const it = items[act];
297
+ if (it) pick(it.id);
298
+ }
299
+ else if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); close(true); }
300
+ else if (e.key === "Tab") close(false);
301
+ });
302
+ paint();
303
+ return h("div", { className: `mp${k.className ? ` ${k.className}` : ""}` }, trigger, field, panel);
304
+ };
305
+ // Handshake with the host, then the page's own first load. The host context says where the page was opened (hostContext.route: the part of the address after the page's own).
306
+ const start = async (name, load) => {
307
+ const init = await send("ui/initialize", { appInfo: { name, version: "1" }, appCapabilities: {}, protocolVersion: "2026-01-26" });
308
+ hostContext(init.hostContext);
309
+ notify("ui/notifications/initialized", {});
310
+ load(init.hostContext);
311
+ };
@@ -0,0 +1,8 @@
1
+ /** The kernel's own tier rules (kernel/src/tier.ts) in words; a module's own rule shows as its code and reason. */
2
+ export declare const RULES: Record<string, string>;
3
+ /** The AI reviewer's reason codes (kernel/sdk/src/reason-codes.ts REVIEW_CODES) in words. */
4
+ export declare const REVIEW_WORDS: Record<string, string>;
5
+ export declare const capWords: (c: {
6
+ by?: string;
7
+ value: string;
8
+ }) => string;
@@ -0,0 +1,29 @@
1
+ // A card's words: the kernel's own tier rules, the AI reviewer's reason codes and an autonomy cap, in plain sentences. One place
2
+ // for what the kernel says on a card (kernel/src/card-context.ts, "why it reached you") and the board's Explain panel
3
+ // (services/board/src/explain.ts).
4
+ //
5
+ // Shared by the board and the kernel (the board imports @aidenhq/sdk/card-words).
6
+ /** The kernel's own tier rules (kernel/src/tier.ts) in words; a module's own rule shows as its code and reason. */
7
+ export const RULES = {
8
+ "autonomy-off": "Autonomy is off, so every write is yours to approve.",
9
+ "unknown-files": "The files it changes weren't known: the AI reviewer reads it.",
10
+ "foreign-authority": "It brings new authority from a marketplace's module or a fork: the AI reviewer reads it, then you decide.",
11
+ };
12
+ /** The AI reviewer's reason codes (kernel/sdk/src/reason-codes.ts REVIEW_CODES) in words. */
13
+ export const REVIEW_WORDS = {
14
+ clean: "Nothing malicious: approved.",
15
+ malicious: "The reviewer found it malicious.",
16
+ secret_exfiltration: "It would send a secret or private data out.",
17
+ prompt_injection: "It follows instructions from untrusted text.",
18
+ reviewer_failed: "The reviewer failed to answer.",
19
+ fail_open: "The review didn't finish twice, so it was approved (fail open).",
20
+ files_not_shown: "The diff didn't match the code host's own count of the change.",
21
+ instance_details: "It would post this server's hosts, addresses or paths to GitHub.",
22
+ tool_call_unreadable: "The tool call's arguments couldn't be read or shown whole, so it went back to the agent.",
23
+ code_review_owns: "Code approved it without an AI review: your setting leaves pushes and PRs on this repo to code review.",
24
+ owner_veto: "You vetoed this action on this task: it is yours.",
25
+ shadow: "Your autonomy is below full: the reviewer's verdict is only a note.",
26
+ refused_by_code: "Code refused it: the same content was already rejected as malicious.",
27
+ stale_head: "Its head moved before review, so nothing ran.",
28
+ };
29
+ export const capWords = (c) => (c.by === "foreign-authority" ? "It brings authority from a marketplace or a fork, so you decide after the AI reviewer." : `Autonomy is ${c.value}.`);
@@ -0,0 +1,20 @@
1
+ export declare const HAIRS: readonly ["short", "spiky", "long", "curly", "bun"];
2
+ export declare const ACCESSORIES: readonly ["none", "headset", "glasses", "round-glasses", "cap", "hard-hat", "earrings", "pencil", "headband"];
3
+ export declare const BODIES: readonly ["none", "tie", "notepad", "badge", "shield"];
4
+ /** How many of each colour the kit has (web/src/ui/tokens.css --face-skin-*, --face-hair-*, --face-bg-*). */
5
+ export declare const SKINS = 10;
6
+ export declare const HAIR_COLORS = 9;
7
+ export declare const PALETTES = 10;
8
+ export interface FaceKit {
9
+ hair: (typeof HAIRS)[number];
10
+ accessory: (typeof ACCESSORIES)[number];
11
+ body: (typeof BODIES)[number];
12
+ /** 0–9 */
13
+ skin: number;
14
+ /** 0–8; the brow follows. */
15
+ hair_color: number;
16
+ /** 0–9: the background and shirt pair. */
17
+ palette: number;
18
+ }
19
+ /** Why `v` isn't a face spec, or undefined when it is: exactly these six keys, all required. */
20
+ export declare function faceKitProblem(v: unknown): string | undefined;
@@ -0,0 +1,32 @@
1
+ // A teammate's face as a character-kit spec (an agent's `teammate.face:` in AGENTS.md or module.yaml): which hair,
2
+ // accessory and body mark, and which skin, hair colour and palette by index. One rule for the compiler (the gate) and the
3
+ // board (it draws the face: web/src/ui/Face.tsx). Plain TypeScript Node runs as is; the board holds a synced copy
4
+ // (scripts/sync-shared.ts).
5
+ export const HAIRS = ["short", "spiky", "long", "curly", "bun"];
6
+ export const ACCESSORIES = ["none", "headset", "glasses", "round-glasses", "cap", "hard-hat", "earrings", "pencil", "headband"];
7
+ export const BODIES = ["none", "tie", "notepad", "badge", "shield"];
8
+ /** How many of each colour the kit has (web/src/ui/tokens.css --face-skin-*, --face-hair-*, --face-bg-*). */
9
+ export const SKINS = 10;
10
+ export const HAIR_COLORS = 9;
11
+ export const PALETTES = 10;
12
+ const ENUMS = { hair: HAIRS, accessory: ACCESSORIES, body: BODIES };
13
+ const RANGES = { skin: SKINS, hair_color: HAIR_COLORS, palette: PALETTES };
14
+ /** Why `v` isn't a face spec, or undefined when it is: exactly these six keys, all required. */
15
+ export function faceKitProblem(v) {
16
+ if (!v || typeof v !== "object" || Array.isArray(v))
17
+ return "a face spec is a map of hair, accessory, body, skin, hair_color and palette";
18
+ const o = v;
19
+ for (const k of Object.keys(o))
20
+ if (!(k in ENUMS) && !(k in RANGES))
21
+ return `a face spec has no ${k}`;
22
+ for (const [k, values] of Object.entries(ENUMS)) {
23
+ if (!values.includes(o[k]))
24
+ return `face ${k} is one of ${values.join(", ")}`;
25
+ }
26
+ for (const [k, n] of Object.entries(RANGES)) {
27
+ const x = o[k];
28
+ if (typeof x !== "number" || !Number.isInteger(x) || x < 0 || x >= n)
29
+ return `face ${k} is a whole number from 0 to ${n - 1}`;
30
+ }
31
+ return undefined;
32
+ }