@ddtcorex/dsh-maestro-core 0.10.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +31 -12
  2. package/lib/cli.js +0 -2
  3. package/lib/client.js +69 -93
  4. package/lib/config/index.d.ts +11 -4
  5. package/lib/config/index.js +26 -9
  6. package/lib/config/service.d.ts +2 -2
  7. package/lib/config/service.js +2 -2
  8. package/lib/debug-agent.js +1 -1
  9. package/lib/paths.d.ts +8 -0
  10. package/lib/paths.js +22 -0
  11. package/lib/plugin.d.ts +21 -1
  12. package/lib/plugin.js +153 -42
  13. package/lib/restart-guards.js +1 -1
  14. package/lib/restart-tool.js +13 -4
  15. package/lib/resume-log.d.ts +4 -0
  16. package/lib/resume-log.js +13 -4
  17. package/lib/snapshot.d.ts +3 -2
  18. package/lib/snapshot.js +3 -2
  19. package/lib/store/index.js +119 -45
  20. package/lib/supervisor.js +5 -7
  21. package/lib/types/client/config/MaestroSettings.d.ts.map +1 -1
  22. package/package.json +4 -2
  23. package/scripts/build-client.mjs +53 -0
  24. package/scripts/install-systemd.sh +55 -0
  25. package/scripts/sync/bench-preview.mjs +43 -0
  26. package/scripts/sync/cdp-sync-probe.mjs +200 -0
  27. package/scripts/sync/cdp-sync-verify.mjs +169 -0
  28. package/scripts/vendor-store.mjs +104 -0
  29. package/skills/dsh-safe-restart/SKILL.md +2 -2
  30. package/skills/dsh-safe-restart/scripts/restart-dsh-web.sh +2 -2
  31. package/src/client/config/MaestroSettings.tsx +8 -139
  32. package/src/client/sync/SyncPanel.tsx +1 -1
  33. package/src/client/sync/index.tsx +4 -4
  34. package/src/host/cli.ts +0 -2
  35. package/src/host/config/index.ts +27 -10
  36. package/src/host/config/service.ts +2 -2
  37. package/src/host/debug-agent.ts +1 -1
  38. package/src/host/paths.ts +21 -0
  39. package/src/host/plugin.ts +140 -30
  40. package/src/host/restart-guards.ts +1 -1
  41. package/src/host/restart-tool.ts +12 -4
  42. package/src/host/resume-log.ts +20 -5
  43. package/src/host/snapshot.ts +3 -2
  44. package/src/host/store/index.ts +120 -33
  45. package/src/host/supervisor.ts +6 -8
  46. package/systemd/dsh-web-keepalive.service.template +12 -0
  47. package/systemd/dsh-web-supervisor.service.template +20 -0
  48. package/systemd/dsh-web.service.template +30 -0
@@ -0,0 +1,169 @@
1
+ // Live verify: settings card shows real status counts and Preview Pull lists real actions.
2
+ // Usage: DSH_WEB_TOKEN=... node scripts/cdp-sync-verify.mjs [mobile|desktop]
3
+ import http from 'node:http'
4
+ import { spawn } from 'node:child_process'
5
+ import { mkdtempSync } from 'node:fs'
6
+ import { tmpdir } from 'node:os'
7
+ import { join } from 'node:path'
8
+
9
+ const TOKEN = process.env.DSH_WEB_TOKEN || ''
10
+ const SESSION_ID = process.env.DSH_SESSION_ID || 'session-5674e8fd-f84a-4437-b648-b660fe59dbc9'
11
+ const TOKEN_URL = `http://127.0.0.1:3080/?token=${TOKEN}`
12
+ const MODE = process.argv[2] ?? 'mobile'
13
+ const VIEW = MODE === 'mobile' ? { width: 390, height: 844, deviceScaleFactor: 2, mobile: true, hasTouch: true } : { width: 1440, height: 900, deviceScaleFactor: 1, mobile: false, hasTouch: false }
14
+
15
+ function allocPort() {
16
+ return new Promise((res) => {
17
+ const srv = http.createServer()
18
+ srv.listen(0, '127.0.0.1', () => {
19
+ const p = srv.address().port
20
+ srv.close(() => res(p))
21
+ })
22
+ })
23
+ }
24
+ function rpc(ws, method, params = {}) {
25
+ return new Promise((res, rej) => {
26
+ const id = ++rpc._seq
27
+ const onMsg = (ev) => {
28
+ const m = JSON.parse(ev.data.toString())
29
+ if (m.id !== id) return
30
+ ws.removeEventListener('message', onMsg)
31
+ if (m.error) rej(new Error(method + ': ' + JSON.stringify(m.error)))
32
+ else res(m.result)
33
+ }
34
+ ws.addEventListener('message', onMsg)
35
+ ws.send(JSON.stringify({ id, method, params }))
36
+ })
37
+ }
38
+ rpc._seq = 0
39
+
40
+ async function evalJs(ws, expr) {
41
+ const r = await rpc(ws, 'Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true })
42
+ if (r.exceptionDetails) throw new Error('eval failed: ' + JSON.stringify(r.exceptionDetails.exception?.description ?? r.exceptionDetails.text))
43
+ return r.result.value
44
+ }
45
+
46
+ async function main() {
47
+ const port = await allocPort()
48
+ const userData = mkdtempSync(join(tmpdir(), 'sync-verify-'))
49
+ const chrome = spawn('/opt/google/chrome/chrome', [
50
+ '--headless=new', '--no-sandbox', '--remote-debugging-port=' + port, '--user-data-dir=' + userData,
51
+ ], { stdio: 'ignore' })
52
+ let ws = null
53
+ try {
54
+ // wait for devtools endpoint
55
+ let pages
56
+ for (let i = 0; i < 50; i++) {
57
+ try {
58
+ pages = await fetch(`http://127.0.0.1:${port}/json`).then((r) => r.json())
59
+ if (pages?.length) break
60
+ } catch {}
61
+ await new Promise((r) => setTimeout(r, 200))
62
+ }
63
+ const page = pages.find((p) => p.type === 'page')
64
+ ws = await new Promise((res, rej) => {
65
+ const w = new WebSocket(page.webSocketDebuggerUrl)
66
+ w.addEventListener('open', () => res(w))
67
+ w.addEventListener('error', (e) => rej(new Error('ws error')))
68
+ })
69
+
70
+ await rpc(ws, 'Emulation.setDeviceMetricsOverride', VIEW)
71
+ await rpc(ws, 'Page.addScriptToEvaluateOnNewDocument', {
72
+ source: `try { localStorage.setItem('dsh.sessions.current', ${JSON.stringify(JSON.stringify({ sessionId: SESSION_ID }))}); } catch (e) {}`,
73
+ })
74
+ await rpc(ws, 'Page.navigate', { url: TOKEN_URL })
75
+ await new Promise((r) => setTimeout(r, 3000))
76
+ // wait for app
77
+ for (let i = 0; i < 50; i++) {
78
+ const ready = await evalJs(ws, `typeof window.__DSH_BOOT__ === 'object' && !!(document.querySelector('[data-maestro-logo]') || document.body.innerText.includes('Settings'))`)
79
+ if (ready) break
80
+ await new Promise((r) => setTimeout(r, 300))
81
+ }
82
+ // open Settings -> Maestro Sync (mirrors cdp-sync-probe.mjs navigation)
83
+ await evalJs(ws, `(() => { const b = document.querySelector('button[aria-label="Open sidebar"]'); if (b) { b.click(); return true; } return false; })()`)
84
+ await new Promise((r) => setTimeout(r, 1200))
85
+ const settingsBtn = await evalJs(ws, `(() => {
86
+ const els = Array.from(document.querySelectorAll('button, [role="button"]'));
87
+ const hit = els.find((el) => {
88
+ const label = el.getAttribute('aria-label') || el.title || (el.textContent || '');
89
+ return label.trim().toLowerCase() === 'settings';
90
+ });
91
+ if (!hit) return null;
92
+ hit.click();
93
+ return true;
94
+ })()`)
95
+ if (!settingsBtn) throw new Error('settings trigger not found')
96
+ await new Promise((r) => setTimeout(r, 1400))
97
+ const syncNav = await evalJs(ws, `(() => {
98
+ const dialog = document.querySelector('[role="dialog"]');
99
+ if (!dialog) return null;
100
+ const btns = Array.from(dialog.querySelectorAll('button'));
101
+ const hit = btns.find((el) => (el.textContent || '').trim().toLowerCase().includes('maestro sync'));
102
+ if (!hit) return null;
103
+ hit.click();
104
+ return true;
105
+ })()`)
106
+ if (!syncNav) throw new Error('maestro sync trigger not found')
107
+ // wait for status to resolve (no longer "Checking connection…")
108
+ let cardText = ''
109
+ for (let i = 0; i < 60; i++) {
110
+ cardText = await evalJs(ws, `(() => { const c = document.querySelector('[data-sync-card], [data-maestro-logo]'); if (!c) return ''; let el = c; for (let k = 0; k < 6 && el; k++) { if ((el.innerText || '').includes('REMOTE HOST')) break; el = el.parentElement; } return (el || c).innerText })()`)
111
+ if (!cardText.includes('Checking connection')) break
112
+ await new Promise((r) => setTimeout(r, 500))
113
+ }
114
+ // stats + status line
115
+ const body = await evalJs(ws, `document.body.innerText`)
116
+ const statTiles = await evalJs(ws, `(() => { const tiles = [...document.querySelectorAll('[data-stat-tile], [data-stat]')].map((t) => t.innerText.replace(/\\n/g, ' ')); return tiles })()`)
117
+ // wait for bucket page loads to settle (data-sync-file rows appear)
118
+ for (let i = 0; i < 60; i++) {
119
+ const n = await evalJs(ws, `document.querySelectorAll('[data-sync-file]').length`)
120
+ if (n > 0) break
121
+ await new Promise((r) => setTimeout(r, 500))
122
+ }
123
+ // dump the file-list sections verbatim (no preview click, avoids busy noise)
124
+ const listSections = await evalJs(ws, `(() => {
125
+ const el = document.querySelector('[data-sync-card], [data-maestro-logo]');
126
+ if (!el) return [];
127
+ let root = el; for (let k = 0; k < 6 && root; k++) { if ((root.innerText || '').includes('Coming from the other machine')) break; root = root.parentElement; }
128
+ if (!root) return [];
129
+ return { section: (root.innerText || '').slice(0, 2000) };
130
+ })()`)
131
+ await evalJs(ws, `(() => { const el = document.querySelector('[data-testid="sync-preview-pull"]'); if (el) el.click(); return !!el })()`)
132
+ // capture the progress bar while the count-only preview runs (hashing ticks)
133
+ let progressSeen = null
134
+ for (let i = 0; i < 40; i++) {
135
+ progressSeen = await evalJs(ws, `(() => { const p = document.querySelector('[data-sync-progress]'); if (!p) return null; return p.innerText.slice(0, 200) })()`)
136
+ if (progressSeen) break
137
+ await new Promise((r) => setTimeout(r, 300))
138
+ }
139
+ let dialog = null
140
+ // remote preview runs a checksum-only session count now (~10s); md stage can still take a while
141
+ for (let i = 0; i < 360; i++) {
142
+ const alertHit = await evalJs(ws, `(() => { const a = document.querySelector('[role="alert"]'); return a ? a.innerText.slice(0, 300) : null })()`)
143
+ if (alertHit) { dialog = { alert: alertHit, rows: 0 }; break }
144
+ dialog = await evalJs(ws, `(() => { const d = [...document.querySelectorAll('[role="dialog"]')].find((x) => (x.innerText || '').includes('Cancel') && (x.innerText || '').includes('Apply')); if (!d) return null; const sc = d.querySelector('[data-sync-sessioncounts]'); return { text: d.innerText.slice(0, 800), rows: d.querySelectorAll('[data-action-row]').length, hasPreviewId: !!(d.innerText || '').match(/[a-f0-9]{32}/), sessionCounts: sc ? sc.innerText : null } })()`)
145
+ if (dialog) break
146
+ await new Promise((r) => setTimeout(r, 500))
147
+ }
148
+ const listSectionsOut = listSections
149
+ const statLines = body.split('\n').filter((l) => /^\d+$/.test(l.trim())).slice(0, 6)
150
+
151
+ const out = {
152
+ mode: MODE,
153
+ hasCard: await evalJs(ws, `!!document.querySelector('[data-maestro-logo]')`),
154
+ statusResolved: !cardText.includes('Checking connection'),
155
+ cardHead: cardText.slice(0, 160).replace(/\n/g, ' | '),
156
+ statTiles,
157
+ statsDigits: statLines,
158
+ previewButtonClicked: !!(await evalJs(ws, `!!document.querySelector('[data-testid="sync-preview-pull"]')`)),
159
+ progressSeen,
160
+ lists: listSectionsOut,
161
+ dialog,
162
+ }
163
+ console.log(JSON.stringify(out, null, 2))
164
+ } finally {
165
+ ws?.close()
166
+ chrome.kill('SIGKILL')
167
+ }
168
+ }
169
+ main().catch((e) => { console.error(e); process.exit(1) })
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Vendor the settings store into a consumer package.
4
+ *
5
+ * Every plugin embeds its own copy of the store so the plugins stay independent
6
+ * packages with no shared dependency. The copy is generated from the core
7
+ * source rather than copied by hand, and the first line carries the sha256 of
8
+ * the body, so a consumer's drift test can tell "generated from the current
9
+ * core store" from "hand edited" or "generated from an older core store".
10
+ *
11
+ * node scripts/vendor-store.mjs <consumer-package-dir>
12
+ *
13
+ * Writes `<consumer-package-dir>/src/host/vendor/store.ts`. No dependencies:
14
+ * the consumers run this from their own `node scripts/`, and a vendoring step
15
+ * that needs an install is a vendoring step that does not get run.
16
+ */
17
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
18
+ import { createHash } from 'node:crypto'
19
+ import { dirname, join } from 'node:path'
20
+ import { fileURLToPath, pathToFileURL } from 'node:url'
21
+
22
+ /** The core root is the parent of scripts/. */
23
+ const CORE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)))
24
+ const DEFAULT_SOURCE_DIR = join(CORE_ROOT, 'src', 'host', 'store')
25
+ const RELATIVE_OUT = join('src', 'host', 'vendor', 'store.ts')
26
+
27
+ /**
28
+ * legacy.ts imports load/set from './index.js'. Concatenated into one module
29
+ * those symbols are already in scope, so the import line is dropped.
30
+ */
31
+ const CROSS_FILE_IMPORT = /^import\s+\{[^}]*\}\s+from\s+'\.\/index\.js'\s*\n/m
32
+
33
+ /** Concatenate the two store sources into the single-module body. */
34
+ export function buildBody(sourceDir) {
35
+ const index = readFileSync(join(sourceDir, 'index.ts'), 'utf8')
36
+ const legacy = readFileSync(join(sourceDir, 'legacy.ts'), 'utf8')
37
+ const stripped = legacy.replace(CROSS_FILE_IMPORT, '')
38
+ if (stripped === legacy) {
39
+ throw new Error(`vendor-store: no './index.js' import found in ${join(sourceDir, 'legacy.ts')}`)
40
+ }
41
+ return `${index}\n${stripped}`
42
+ }
43
+
44
+ export function hashBody(body) {
45
+ return createHash('sha256').update(body).digest('hex')
46
+ }
47
+
48
+ /** Render the vendored file: the hash line, then the body it describes. */
49
+ export function renderVendored(body) {
50
+ return `// vendored from dsh-maestro-core store, sha256:${hashBody(body)}\n${body}`
51
+ }
52
+
53
+ /** Write the vendored copy into a consumer package; returns the file written. */
54
+ export function vendorStore(targetDir, sourceDir = DEFAULT_SOURCE_DIR) {
55
+ const file = join(targetDir, RELATIVE_OUT)
56
+ mkdirSync(dirname(file), { recursive: true })
57
+ writeFileSync(file, renderVendored(buildBody(sourceDir)))
58
+ return file
59
+ }
60
+
61
+ /**
62
+ * Check one vendored copy. With `sourceDir` the body is also compared against
63
+ * what the core store produces today, which is the half a self-consistency
64
+ * check cannot see: a copy generated from an older core store still hashes
65
+ * correctly against its own header.
66
+ */
67
+ export function verifyVendored(file, sourceDir) {
68
+ let text
69
+ try {
70
+ text = readFileSync(file, 'utf8')
71
+ } catch (err) {
72
+ return { ok: false, reason: `cannot read ${file}: ${err.message}` }
73
+ }
74
+ const newline = text.indexOf('\n')
75
+ const header = newline === -1 ? text : text.slice(0, newline)
76
+ const body = newline === -1 ? '' : text.slice(newline + 1)
77
+ const match = /^vendored from dsh-maestro-core store, sha256:([0-9a-f]{64})$/.exec(header.replace(/^\/\/ /, ''))
78
+ if (!match) return { ok: false, reason: 'missing or malformed vendored header' }
79
+ const actual = hashBody(body)
80
+ if (actual !== match[1]) {
81
+ return { ok: false, reason: 'body hash does not match the header', expected: match[1], actual }
82
+ }
83
+ if (sourceDir !== undefined) {
84
+ if (buildBody(sourceDir) !== body) {
85
+ return { ok: false, reason: 'vendored body differs from the core source' }
86
+ }
87
+ }
88
+ return { ok: true }
89
+ }
90
+
91
+ function main(argv) {
92
+ const target = argv[0]
93
+ if (!target) {
94
+ console.error('usage: node scripts/vendor-store.mjs <consumer-package-dir>')
95
+ return 2
96
+ }
97
+ const file = vendorStore(target)
98
+ console.log(`vendored ${file}`)
99
+ return 0
100
+ }
101
+
102
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
103
+ process.exit(main(process.argv.slice(2)))
104
+ }
@@ -66,7 +66,7 @@ validate first and get explicit user consent before a real swap.
66
66
  `stat -c '%y' <package>/lib/*.js`; a build newer than the daemon's start
67
67
  means the daemon is **stale** and must be reloaded BEFORE the swap.
68
68
  `restart-dsh-web.sh --check-supervisor` reports this and changes nothing.
69
- 6. Ask for explicit consent and timing. “restart đi” is consent; silence is
69
+ 6. Ask for explicit consent and timing. An explicit “restart now” is consent; silence is
70
70
  not.
71
71
 
72
72
  ## Run the bundled helper only after consent
@@ -127,7 +127,7 @@ touch the live process:
127
127
  `detail` also carries the supervisor-daemon verdict and the real swap budget
128
128
  (see "Budget the turn, not the tool call").
129
129
 
130
- Settings-staging rule: config-lib memoizes settings per process, so an
130
+ Settings-staging rule: the settings store memoizes settings per process, so an
131
131
  out-of-band settings edit is invisible to the host until restart. Stage ALL
132
132
  such edits, then restart ONCE. Prefer in-host Settings UI saves — they are
133
133
  visible immediately with no restart at all.
@@ -4,8 +4,8 @@ set -euo pipefail
4
4
 
5
5
  repo="${DSH_REPO:-}"
6
6
  log="${DSH_RESTART_LOG:-/tmp/dsh-web-restart.log}"
7
- # Coordination with dsh-web-supervisor (see workspace docs/specs/
8
- # 2026-08-28-supervisor-planned-restart-design.md): the supervisor treats a
7
+ # Coordination with dsh-web-supervisor (see
8
+ # <workspace-root>/docs/specs/2026-09-13-supervisor-restart-resilience-design.md): the supervisor treats a
9
9
  # down poll as a crash unless this marker is fresh, so it never races this
10
10
  # script's own kill -> dry-boot -> relaunch sequence with its own rollback.
11
11
  marker="${DSH_SUPERVISOR_MARKER:-$HOME/.dsh/.supervisor/planned-restart}"
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Maestro Settings — DSH-native redesign.
4
3
  * Reuses DeepSeek Harness design tokens & primitive geometry maximally:
@@ -22,6 +21,7 @@ const t = {
22
21
  bgLayer2: 'var(--dsw-alias-bg-layer-2)',
23
22
  bgLayer3: 'var(--dsw-alias-bg-layer-3)',
24
23
  borderL2: 'var(--dsw-alias-border-l2)',
24
+ borderL4: 'var(--dsw-alias-border-l4)',
25
25
  labelPrimary: 'var(--dsw-alias-label-primary)',
26
26
  labelSecondary: 'var(--dsw-alias-label-secondary)',
27
27
  labelTertiary: 'var(--dsw-alias-label-tertiary)',
@@ -184,116 +184,6 @@ function FieldInput(props: React.InputHTMLAttributes<HTMLInputElement> & { icon?
184
184
  )
185
185
  }
186
186
 
187
- // DSH DisclosureRow — 24px row, 14px glyph, hover chevron swap, same semantics as host
188
- function DisclosureRow({
189
- icon,
190
- title,
191
- caption,
192
- open,
193
- expandable,
194
- onToggle,
195
- children,
196
- }: {
197
- icon: unknown
198
- title: string
199
- caption?: string
200
- open: boolean
201
- expandable: boolean
202
- onToggle: () => void
203
- children?: unknown
204
- }) {
205
- const rowExpands = expandable
206
- return h(
207
- 'div',
208
- { style: { display: 'flex', flexDirection: 'column', width: '100%', minWidth: 0 } },
209
- h(
210
- 'div',
211
- {
212
- role: rowExpands ? 'button' : undefined,
213
- tabIndex: rowExpands ? 0 : undefined,
214
- 'aria-expanded': rowExpands ? open : undefined,
215
- onClick: rowExpands ? onToggle : undefined,
216
- onKeyDown: rowExpands
217
- ? (e: any) => {
218
- if (e.key === 'Enter' || e.key === ' ') {
219
- e.preventDefault()
220
- onToggle()
221
- }
222
- }
223
- : undefined,
224
- style: {
225
- display: 'flex',
226
- alignItems: 'center',
227
- gap: 8,
228
- minHeight: 40,
229
- padding: '8px 10px',
230
- borderRadius: 12,
231
- cursor: rowExpands ? 'pointer' : 'default',
232
- background: open ? 'var(--dsw-specific-sidebar-nav-item-active)' : 'transparent',
233
- border: `1px solid ${open ? t.borderL2 : 'transparent'}`,
234
- boxSizing: 'border-box' as const,
235
- },
236
- onMouseEnter: (e: any) => {
237
- if (!open) (e.currentTarget as HTMLElement).style.background = 'var(--dsw-specific-sidebar-nav-item-hover)'
238
- },
239
- onMouseLeave: (e: any) => {
240
- if (!open) (e.currentTarget as HTMLElement).style.background = 'transparent'
241
- },
242
- },
243
- expandable
244
- ? h(
245
- 'button',
246
- {
247
- type: 'button',
248
- 'aria-expanded': open,
249
- onClick: (e: any) => {
250
- e.stopPropagation()
251
- onToggle()
252
- },
253
- style: {
254
- flex: 'none',
255
- width: 20,
256
- height: 20,
257
- display: 'inline-flex',
258
- alignItems: 'center',
259
- justifyContent: 'center',
260
- border: 'none',
261
- background: 'none',
262
- cursor: 'pointer',
263
- color: t.labelTertiary,
264
- padding: 0,
265
- },
266
- },
267
- open
268
- ? h('span', { style: { fontSize: 12, lineHeight: 1 } }, '▾')
269
- : h('span', { style: { fontSize: 12, lineHeight: 1 } }, '▸'),
270
- )
271
- : h('span', { style: { width: 20, display: 'inline-flex', justifyContent: 'center', color: t.labelTertiary, flex: 'none' } }, icon as any),
272
- h('span', { style: { flex: 1, minWidth: 0 } },
273
- h('span', { style: { display: 'block', fontSize: 14, lineHeight: '20px', fontWeight: 500, color: t.labelPrimary } }, title),
274
- caption ? h('span', { style: { display: 'block', fontSize: 12, lineHeight: '16px', color: t.labelSecondary, marginTop: 1 } }, caption) : null,
275
- ),
276
- !open && expandable
277
- ? h('span', { style: { color: t.labelTertiary, fontSize: 12 } }, '›')
278
- : null,
279
- ),
280
- open ? h('div', { style: { padding: '10px 0 14px 30px', display: 'flex', flexDirection: 'column', gap: 10 } }, children as any) : null,
281
- )
282
- }
283
-
284
- // ---------------------------------------------------------------------------
285
- // Shared field helpers — DSH-native label / caption rhythm
286
- // ---------------------------------------------------------------------------
287
- const fieldLabelStyle: Record<string, string> = {
288
- display: 'flex',
289
- flexDirection: 'column',
290
- gap: '6px',
291
- fontSize: '12px',
292
- lineHeight: '16px',
293
- fontWeight: '500',
294
- color: t.labelSecondary as string,
295
- margin: '12px 0 0',
296
- }
297
187
  const captionStyle: Record<string, string> = {
298
188
  fontSize: '12px',
299
189
  lineHeight: '16px',
@@ -341,23 +231,6 @@ const rowDescStyle: Record<string, string> = {
341
231
  lineHeight: '18px',
342
232
  color: t.labelTertiary as string,
343
233
  }
344
- // Pill selector — same as LanguageRow/EnterBehaviorRow: h36 r18 bg-module-platform
345
- const pillSelectorStyle: Record<string, string> = {
346
- display: 'inline-flex',
347
- alignItems: 'center',
348
- gap: '12px',
349
- height: '36px',
350
- padding: '0 14px',
351
- border: 'none',
352
- borderRadius: '18px',
353
- background: 'var(--dsw-alias-bg-module-platform, #F5F6F7)',
354
- font: 'inherit',
355
- fontSize: '14px',
356
- lineHeight: '22px',
357
- color: t.labelPrimary as string,
358
- cursor: 'pointer',
359
- whiteSpace: 'nowrap',
360
- }
361
234
  function SettingRow({ title, description, control }: { title: string; description?: string; control: unknown }) {
362
235
  return h(
363
236
  'div',
@@ -483,15 +356,6 @@ function ListEditor({ values, placeholder, onCommit, ariaLabel, emptyHint }: { v
483
356
  )
484
357
  }
485
358
 
486
- function ToggleField({ label, caption, checked, onChange }: { label: string; caption?: string; checked?: boolean; onChange: (v: boolean) => void }) {
487
- return h(
488
- 'label',
489
- { style: { display: 'flex', alignItems: 'flex-start', gap: 10, margin: '8px 0', cursor: 'pointer' } },
490
- h('input', { type: 'checkbox', checked: checked === true, onChange: (e: any) => onChange(e.target.checked), style: { marginTop: 4, width: 16, height: 16, accentColor: t.primaryFill as string } }),
491
- h('span', null, h('div', { style: { fontSize: 13, color: t.labelPrimary as string, lineHeight: '18px' } }, label), caption ? h('div', { style: captionStyle }, caption) : null),
492
- )
493
- }
494
-
495
359
  export function MaestroSettingsTab({ configRpcCall, supervisorRpcCall }: { configRpcCall?: any; supervisorRpcCall?: any }) {
496
360
  const [guard, setGuard] = useState<any>({})
497
361
  const [patterns, setPatterns] = useState<string[]>([])
@@ -502,6 +366,10 @@ export function MaestroSettingsTab({ configRpcCall, supervisorRpcCall }: { confi
502
366
  const [supervisorStatus, setSupervisorStatus] = useState<any>(null)
503
367
  const [supervisorCfg, setSupervisorCfg] = useState<any>({})
504
368
  const [activeTab, setActiveTab] = useState('guard')
369
+ // Every save in this tab reports its failure here, and the render reads it
370
+ // back. The declaration is load-bearing: without it the render raises
371
+ // `ReferenceError` and the whole section mounts empty.
372
+ const [error, setError] = useState<string | null>(null)
505
373
  // Mobile: inject responsive overrides once (mirrors dsh-maestro-mobile settings-sheet pill pattern + market catsWrap)
506
374
  useEffect(() => {
507
375
  const css = `
@@ -752,8 +620,9 @@ export function MaestroSettingsTab({ configRpcCall, supervisorRpcCall }: { confi
752
620
  },
753
621
  'aria-label': meta.label,
754
622
  style: {
755
- height: 36, padding: '0 12px', border: `1px solid ${t.borderL2}`, borderRadius: 18,
756
- background: 'var(--dsw-alias-bg-module-platform, #F5F6F7)' as string, color: t.labelPrimary as string, font: 'inherit', fontSize: 13,
623
+ minHeight: 44, padding: '6px 12px', border: '0.5px solid var(--dsw-alias-border-l4)',
624
+ borderRadius: 'var(--dsw-radius-md)', background: t.bgLayer3 as string,
625
+ color: t.labelPrimary as string, font: 'inherit', fontSize: 13,
757
626
  },
758
627
  },
759
628
  h('option', { value: 'default' }, `Default (${meta.defaultTier})`),
@@ -156,7 +156,7 @@ export function SyncPanel(props: { ctx: any }): React.ReactElement {
156
156
  aria-invalid={hostFieldError ? 'true' : undefined}
157
157
  />
158
158
  {hostFieldError ? (
159
- <span data-sync-field-error="" role="alert" data-testid="sync-ssh-host-error" style={{ gridColumn: '1 / -1', fontSize: 12, lineHeight: '16px', color: 'var(--dsw-alias-state-error-primary)', overflowWrap: 'anywhere' }}>
159
+ <span data-sync-field-error="" role="alert" data-testid="sync-ssh-host-error" style={{ fontSize: 12, lineHeight: '16px', color: 'var(--dsw-alias-state-error-primary)', overflowWrap: 'anywhere' }}>
160
160
  {hostFieldError}
161
161
  </span>
162
162
  ) : null}
@@ -255,8 +255,8 @@ button[data-sync-stat]:focus-visible { outline: 2px solid var(--dsw-alias-border
255
255
  }
256
256
  /* SSH configuration — user-filled target, explicit check, nothing auto-probes */
257
257
  [data-sync-ssh] { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px; background: var(--dsw-alias-bg-layer-2); }
258
- [data-sync-ssh-label] { font-size: 11px; color: var(--dsw-alias-label-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
259
- [data-sync-ssh-input] { min-height: 44px; padding: 0 12px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 10px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; width: 100%; box-sizing: border-box; }
258
+ [data-sync-ssh-label] { font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
259
+ [data-sync-ssh-input] { min-height: 44px; padding: 6px 12px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; width: 100%; box-sizing: border-box; }
260
260
  [data-sync-ssh-input]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
261
261
  [data-sync-ssh-input]:disabled { opacity: 0.6; }
262
262
  [data-sync-ssh-row] { display: flex; gap: 8px; flex-wrap: wrap; }
@@ -269,7 +269,7 @@ button[data-sync-stat]:focus-visible { outline: 2px solid var(--dsw-alias-border
269
269
  [data-r2-config-label] { font-size: 11px; color: var(--dsw-alias-label-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
270
270
  [data-r2-field] { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
271
271
  [data-r2-field-label] { font-size: 12px; font-weight: 600; color: var(--dsw-alias-label-primary); }
272
- [data-r2-field-input] { min-height: 44px; padding: 0 12px; border: 1px solid var(--dsw-alias-border-l2); border-radius: 10px; background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary); font: inherit; font-size: 13px; width: 100%; box-sizing: border-box; }
272
+ [data-r2-field-input] { min-height: 44px; padding: 6px 12px; border: 0.5px solid var(--dsw-alias-border-l4); border-radius: var(--dsw-radius-md); background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); font: inherit; width: 100%; box-sizing: border-box; }
273
273
  [data-r2-field-input]:focus-visible { outline: 2px solid var(--dsw-alias-border-l2); outline-offset: 2px; }
274
274
  [data-r2-field-input]:disabled { opacity: 0.6; }
275
275
  [data-r2-field-hint] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-tertiary); }
@@ -287,7 +287,7 @@ button[data-sync-stat]:focus-visible { outline: 2px solid var(--dsw-alias-border
287
287
  [data-r2-config-row] > [data-sync-btn] { flex: 1 1 0; }
288
288
  [data-r2-config-hint] { font-size: 11px; line-height: 14px; color: var(--dsw-alias-label-secondary); }
289
289
  @media (max-width: 640px) {
290
- [data-sync-ssh-row] > [data-sync-btn] { min-height: 48px !important; }
290
+ [data-sync-ssh-row] > [data-sync-btn] { min-height: 44px !important; }
291
291
  }
292
292
 
293
293
  /* iOS 16px field floor hold (dsh-maestro-mobile zoom guard).
package/src/host/cli.ts CHANGED
@@ -142,8 +142,6 @@ export async function runCli(args: string[]): Promise<void> {
142
142
  Commands:
143
143
  daemon Run supervisor daemon (poll every 3s)
144
144
  status Show health + LKG status
145
- logs Tail supervisor reports
146
- rollback --to <ts> Rollback to LKG <ts>
147
145
  resume [--within <dur>] List interrupted sessions (filter by time, e.g. 5m, 30s, 1h)
148
146
  boot-guard acquire|release --pid <pid> Take/release boot.lock + boot-boundary (used by the safe-restart script)
149
147
  `)
@@ -33,41 +33,58 @@ function fail(message: string): RpcResult<never> {
33
33
  }
34
34
  }
35
35
 
36
+ /**
37
+ * Domains this channel may touch: exactly the ones the core Settings card reads
38
+ * and writes (Guard and Supervisor tabs). The store is shared with every other
39
+ * plugin (gitlab token, webhook secret, Telegram bot token, tunnel credentials
40
+ * path), and this channel is reachable from any logged-in browser session, so
41
+ * the allowlist is applied to ALL four endpoints, `list` included. Foreign
42
+ * domains are owned and validated by their own plugins.
43
+ */
44
+ export const RPC_DOMAINS: readonly string[] = ['guard', 'guardBlacklist', 'supervisor']
45
+
46
+ function isAllowed(domain: string): boolean {
47
+ return RPC_DOMAINS.includes(domain)
48
+ }
49
+
50
+ function refuse(domain: string): RpcResult<never> {
51
+ return fail(`domain '${domain}' is not available through this channel`)
52
+ }
53
+
36
54
  /**
37
55
  * Publish maestroConfig over the shared store + loopback RPC for clients.
38
- * Exposes guard/guardBlacklist/supervisor/notifier domains (Task 1 validators)
39
- * via generic get/set — validation is delegated to the lib's domain validators.
40
- * Host also handles '/dsh-maestro-config/get' and '/dsh-maestro-config/set'
41
- * style calls through the single channel with endpoint dispatch.
56
+ * The RPC serves only RPC_DOMAINS; in-process consumers of `ctx.maestroConfig`
57
+ * keep the full service. Validation is delegated to the store's domain validators.
42
58
  */
43
59
  export function apply(ctx: Context): void {
44
60
  const svc = createMaestroConfigService()
45
61
  ctx.provide('maestroConfig', svc)
46
62
  ctx.effect(() =>
47
63
  ctx.connection.rpc.handle(RPC_CHANNEL, async (endpoint: string, payload: unknown): Promise<RpcResult<unknown>> => {
48
- const body = (payload ?? {}) as { domain?: string; patch?: object }
64
+ const body = (payload ?? {}) as { domain?: string; patch?: object; key?: unknown }
49
65
  if (endpoint === 'list') {
50
- return ok({ domains: await svc.listDomains() })
66
+ return ok({ domains: (await svc.listDomains()).filter(isAllowed) })
51
67
  }
52
68
  if (endpoint === 'get') {
53
69
  if (typeof body.domain !== 'string') return fail('domain (string) is required')
54
- // guard / guardBlacklist / supervisor / notifier are all valid domains here
70
+ if (!isAllowed(body.domain)) return refuse(body.domain)
55
71
  return ok(await svc.get(body.domain))
56
72
  }
57
73
  if (endpoint === 'set') {
58
74
  if (typeof body.domain !== 'string' || typeof body.patch !== 'object' || body.patch === null) {
59
75
  return fail('domain (string) and patch (object) are required')
60
76
  }
77
+ if (!isAllowed(body.domain)) return refuse(body.domain)
61
78
  await svc.set(body.domain, body.patch)
62
79
  return ok(null)
63
80
  }
64
81
  if (endpoint === 'unset') {
65
- const key = (payload ?? {}) as { key?: unknown }
66
- if (typeof body.domain !== 'string' || typeof key.key !== 'string') {
82
+ if (typeof body.domain !== 'string' || typeof body.key !== 'string') {
67
83
  return fail('domain (string) and key (string) are required')
68
84
  }
85
+ if (!isAllowed(body.domain)) return refuse(body.domain)
69
86
  try {
70
- return ok({ deleted: await svc.unset(body.domain, key.key) })
87
+ return ok({ deleted: await svc.unset(body.domain, body.key) })
71
88
  } catch (e: any) {
72
89
  return fail(e?.message ?? String(e))
73
90
  }
@@ -14,8 +14,8 @@ export interface MaestroConfigService {
14
14
  }
15
15
 
16
16
  /**
17
- * Thin facade over @ddtcorex/dsh-maestro-config-lib. `dshHome` defaults to the
18
- * lib's resolution (explicit > DSH_HOME env > ~/.dsh); tests inject a tmpdir.
17
+ * Thin facade over the embedded settings store (`../store`). `dshHome` defaults to the
18
+ * the store's resolution (explicit > DSH_HOME env > ~/.dsh); tests inject a tmpdir.
19
19
  */
20
20
  export function createMaestroConfigService(opts?: { dshHome?: string }): MaestroConfigService {
21
21
  const libOpts = opts?.dshHome ? { dshHome: opts.dshHome } : undefined
@@ -85,7 +85,7 @@ async function autoFixKnownPatterns(err: string, exec: (c: string, o?: any) => s
85
85
  }
86
86
  if (lower.includes('syntaxerror') || lower.includes('yamlparseerror') || lower.includes('json')) {
87
87
  // corrupted settings.json — try restore from bak
88
- try { exec('ls ~/.dsh/maestro/*.bak 2>&1 | head -5', { timeout: 5000 }) } catch {}
88
+ try { exec('ls ~/.dsh/dsh-maestro-config/*.bak 2>&1 | head -5', { timeout: 5000 }) } catch {}
89
89
  return
90
90
  }
91
91
  }