@ddtcorex/dsh-maestro-core 0.10.0

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 (285) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +209 -0
  3. package/cordis.patch.yml +43 -0
  4. package/lib/bin.d.ts +2 -0
  5. package/lib/bin.js +3 -0
  6. package/lib/boot-guard.d.ts +33 -0
  7. package/lib/boot-guard.js +68 -0
  8. package/lib/boot-lock.d.ts +56 -0
  9. package/lib/boot-lock.js +155 -0
  10. package/lib/cli.d.ts +31 -0
  11. package/lib/cli.js +336 -0
  12. package/lib/client.js +2901 -0
  13. package/lib/config/index.d.ts +34 -0
  14. package/lib/config/index.js +62 -0
  15. package/lib/config/service.d.ts +18 -0
  16. package/lib/config/service.js +28 -0
  17. package/lib/config.d.ts +1 -0
  18. package/lib/config.js +19 -0
  19. package/lib/daemon-freshness.d.ts +48 -0
  20. package/lib/daemon-freshness.js +122 -0
  21. package/lib/debug-agent.d.ts +17 -0
  22. package/lib/debug-agent.js +144 -0
  23. package/lib/dsh-session.d.ts +26 -0
  24. package/lib/dsh-session.js +45 -0
  25. package/lib/guard/config.d.ts +82 -0
  26. package/lib/guard/config.js +211 -0
  27. package/lib/guard/decide.d.ts +30 -0
  28. package/lib/guard/decide.js +38 -0
  29. package/lib/guard/full-scan-tool.d.ts +6 -0
  30. package/lib/guard/full-scan-tool.js +65 -0
  31. package/lib/guard/index.d.ts +85 -0
  32. package/lib/guard/index.js +254 -0
  33. package/lib/guard/journal.d.ts +146 -0
  34. package/lib/guard/journal.js +398 -0
  35. package/lib/guard/migrate.d.ts +15 -0
  36. package/lib/guard/migrate.js +42 -0
  37. package/lib/guard/parse.d.ts +193 -0
  38. package/lib/guard/parse.js +1103 -0
  39. package/lib/guard/paths.d.ts +104 -0
  40. package/lib/guard/paths.js +254 -0
  41. package/lib/guard/permission-policy.d.ts +10 -0
  42. package/lib/guard/permission-policy.js +21 -0
  43. package/lib/guard/redact.d.ts +25 -0
  44. package/lib/guard/redact.js +52 -0
  45. package/lib/guard/rules.d.ts +65 -0
  46. package/lib/guard/rules.js +832 -0
  47. package/lib/guard/status-tool.d.ts +54 -0
  48. package/lib/guard/status-tool.js +195 -0
  49. package/lib/guard/tiers.d.ts +2 -0
  50. package/lib/guard/tiers.js +1 -0
  51. package/lib/guard/validators.d.ts +4 -0
  52. package/lib/guard/validators.js +45 -0
  53. package/lib/health-poller.d.ts +90 -0
  54. package/lib/health-poller.js +430 -0
  55. package/lib/index.d.ts +7 -0
  56. package/lib/index.js +7 -0
  57. package/lib/intents.d.ts +32 -0
  58. package/lib/intents.js +49 -0
  59. package/lib/notifier.d.ts +12 -0
  60. package/lib/notifier.js +62 -0
  61. package/lib/paths.d.ts +13 -0
  62. package/lib/paths.js +70 -0
  63. package/lib/plugin.d.ts +250 -0
  64. package/lib/plugin.js +1126 -0
  65. package/lib/preset.d.ts +73 -0
  66. package/lib/preset.js +158 -0
  67. package/lib/report.d.ts +11 -0
  68. package/lib/report.js +58 -0
  69. package/lib/restart-exec.d.ts +35 -0
  70. package/lib/restart-exec.js +60 -0
  71. package/lib/restart-guards.d.ts +39 -0
  72. package/lib/restart-guards.js +150 -0
  73. package/lib/restart-tool.d.ts +124 -0
  74. package/lib/restart-tool.js +539 -0
  75. package/lib/restart-web.d.ts +26 -0
  76. package/lib/restart-web.js +58 -0
  77. package/lib/resume-log.d.ts +24 -0
  78. package/lib/resume-log.js +18 -0
  79. package/lib/resume-tools.d.ts +131 -0
  80. package/lib/resume-tools.js +337 -0
  81. package/lib/resume.d.ts +33 -0
  82. package/lib/resume.js +221 -0
  83. package/lib/scan.d.ts +20 -0
  84. package/lib/scan.js +71 -0
  85. package/lib/self-kill-guard.d.ts +81 -0
  86. package/lib/self-kill-guard.js +208 -0
  87. package/lib/session-health.d.ts +89 -0
  88. package/lib/session-health.js +274 -0
  89. package/lib/session-log-file.d.ts +22 -0
  90. package/lib/session-log-file.js +74 -0
  91. package/lib/skill-provider.d.ts +6 -0
  92. package/lib/skill-provider.js +73 -0
  93. package/lib/snapshot.d.ts +59 -0
  94. package/lib/snapshot.js +358 -0
  95. package/lib/source.d.ts +19 -0
  96. package/lib/source.js +19 -0
  97. package/lib/store/index.d.ts +42 -0
  98. package/lib/store/index.js +340 -0
  99. package/lib/store/legacy.d.ts +17 -0
  100. package/lib/store/legacy.js +85 -0
  101. package/lib/supervisor.d.ts +119 -0
  102. package/lib/supervisor.js +741 -0
  103. package/lib/sync/backup-config.d.ts +55 -0
  104. package/lib/sync/backup-config.js +119 -0
  105. package/lib/sync/backup-service.d.ts +110 -0
  106. package/lib/sync/backup-service.js +440 -0
  107. package/lib/sync/bidirectional.d.ts +39 -0
  108. package/lib/sync/bidirectional.js +25 -0
  109. package/lib/sync/cli.d.ts +38 -0
  110. package/lib/sync/cli.js +536 -0
  111. package/lib/sync/config.d.ts +77 -0
  112. package/lib/sync/config.js +90 -0
  113. package/lib/sync/fingerprint.d.ts +29 -0
  114. package/lib/sync/fingerprint.js +65 -0
  115. package/lib/sync/hashing.d.ts +9 -0
  116. package/lib/sync/hashing.js +47 -0
  117. package/lib/sync/index.d.ts +6 -0
  118. package/lib/sync/index.js +634 -0
  119. package/lib/sync/machine-id.d.ts +29 -0
  120. package/lib/sync/machine-id.js +66 -0
  121. package/lib/sync/merge.d.ts +33 -0
  122. package/lib/sync/merge.js +88 -0
  123. package/lib/sync/peer-host.d.ts +22 -0
  124. package/lib/sync/peer-host.js +62 -0
  125. package/lib/sync/process-runner.d.ts +31 -0
  126. package/lib/sync/process-runner.js +161 -0
  127. package/lib/sync/remote-agent.d.ts +42 -0
  128. package/lib/sync/remote-agent.js +217 -0
  129. package/lib/sync/remote-cache.d.ts +18 -0
  130. package/lib/sync/remote-cache.js +60 -0
  131. package/lib/sync/remote-manifest.d.ts +8 -0
  132. package/lib/sync/remote-manifest.js +64 -0
  133. package/lib/sync/s3-object-store.d.ts +38 -0
  134. package/lib/sync/s3-object-store.js +126 -0
  135. package/lib/sync/session-merge.d.ts +18 -0
  136. package/lib/sync/session-merge.js +191 -0
  137. package/lib/sync/session-plan.d.ts +29 -0
  138. package/lib/sync/session-plan.js +213 -0
  139. package/lib/sync/sigv4.d.ts +20 -0
  140. package/lib/sync/sigv4.js +57 -0
  141. package/lib/sync/snapshot.d.ts +21 -0
  142. package/lib/sync/snapshot.js +176 -0
  143. package/lib/sync/ssh-mux.d.ts +12 -0
  144. package/lib/sync/ssh-mux.js +48 -0
  145. package/lib/sync/sync-plan.d.ts +24 -0
  146. package/lib/sync/sync-plan.js +366 -0
  147. package/lib/sync/sync-service.d.ts +177 -0
  148. package/lib/sync/sync-service.js +819 -0
  149. package/lib/sync/sync-types.d.ts +87 -0
  150. package/lib/sync/sync-types.js +1 -0
  151. package/lib/sync/transport.d.ts +75 -0
  152. package/lib/sync/transport.js +200 -0
  153. package/lib/sync/tunnel-restore.d.ts +77 -0
  154. package/lib/sync/tunnel-restore.js +142 -0
  155. package/lib/sync/validation.d.ts +10 -0
  156. package/lib/sync/validation.js +83 -0
  157. package/lib/tool-view.d.ts +62 -0
  158. package/lib/tool-view.js +70 -0
  159. package/lib/types/client/auto-reload.d.ts +8 -0
  160. package/lib/types/client/auto-reload.d.ts.map +1 -0
  161. package/lib/types/client/config/MaestroSettings.d.ts +25 -0
  162. package/lib/types/client/config/MaestroSettings.d.ts.map +1 -0
  163. package/lib/types/client/config/components/BrandMark.d.ts +50 -0
  164. package/lib/types/client/config/components/BrandMark.d.ts.map +1 -0
  165. package/lib/types/client/config/guard-view.d.ts +83 -0
  166. package/lib/types/client/config/guard-view.d.ts.map +1 -0
  167. package/lib/types/client/config/index.d.ts +20 -0
  168. package/lib/types/client/config/index.d.ts.map +1 -0
  169. package/lib/types/client/config/maestro-mark.d.ts +29 -0
  170. package/lib/types/client/config/maestro-mark.d.ts.map +1 -0
  171. package/lib/types/client/config/settings-nav-icon.d.ts +21 -0
  172. package/lib/types/client/config/settings-nav-icon.d.ts.map +1 -0
  173. package/lib/types/client/index.d.ts +16 -0
  174. package/lib/types/client/index.d.ts.map +1 -0
  175. package/lib/types/client/sync/R2SyncPanel.d.ts +6 -0
  176. package/lib/types/client/sync/R2SyncPanel.d.ts.map +1 -0
  177. package/lib/types/client/sync/SyncPanel.d.ts +12 -0
  178. package/lib/types/client/sync/SyncPanel.d.ts.map +1 -0
  179. package/lib/types/client/sync/confirm-dialog.d.ts +43 -0
  180. package/lib/types/client/sync/confirm-dialog.d.ts.map +1 -0
  181. package/lib/types/client/sync/index.d.ts +10 -0
  182. package/lib/types/client/sync/index.d.ts.map +1 -0
  183. package/lib/types/client/sync/ui.d.ts +79 -0
  184. package/lib/types/client/sync/ui.d.ts.map +1 -0
  185. package/lib/types/client/sync/use-backup.d.ts +50 -0
  186. package/lib/types/client/sync/use-backup.d.ts.map +1 -0
  187. package/lib/types/client/sync/use-sync.d.ts +88 -0
  188. package/lib/types/client/sync/use-sync.d.ts.map +1 -0
  189. package/package.json +89 -0
  190. package/skills/dsh-safe-restart/SKILL.md +206 -0
  191. package/skills/dsh-safe-restart/scripts/restart-dsh-web.sh +468 -0
  192. package/src/client/auto-reload.ts +104 -0
  193. package/src/client/config/MaestroSettings.tsx +892 -0
  194. package/src/client/config/components/BrandMark.tsx +94 -0
  195. package/src/client/config/guard-view.ts +187 -0
  196. package/src/client/config/index.tsx +109 -0
  197. package/src/client/config/maestro-mark.ts +37 -0
  198. package/src/client/config/settings-nav-icon.ts +68 -0
  199. package/src/client/index.tsx +33 -0
  200. package/src/client/sync/R2SyncPanel.tsx +260 -0
  201. package/src/client/sync/SyncPanel.tsx +422 -0
  202. package/src/client/sync/confirm-dialog.tsx +202 -0
  203. package/src/client/sync/index.tsx +336 -0
  204. package/src/client/sync/ui.tsx +313 -0
  205. package/src/client/sync/use-backup.ts +207 -0
  206. package/src/client/sync/use-sync.ts +502 -0
  207. package/src/host/bin.ts +3 -0
  208. package/src/host/boot-guard.ts +76 -0
  209. package/src/host/boot-lock.ts +155 -0
  210. package/src/host/cli.ts +288 -0
  211. package/src/host/config/index.ts +78 -0
  212. package/src/host/config/service.ts +40 -0
  213. package/src/host/config.ts +18 -0
  214. package/src/host/daemon-freshness.ts +143 -0
  215. package/src/host/debug-agent.ts +145 -0
  216. package/src/host/dsh-session.ts +56 -0
  217. package/src/host/dsh-skill.d.ts +44 -0
  218. package/src/host/guard/augment.d.ts +33 -0
  219. package/src/host/guard/config.ts +244 -0
  220. package/src/host/guard/decide.ts +40 -0
  221. package/src/host/guard/full-scan-tool.ts +61 -0
  222. package/src/host/guard/index.ts +281 -0
  223. package/src/host/guard/journal.ts +440 -0
  224. package/src/host/guard/migrate.ts +41 -0
  225. package/src/host/guard/parse.ts +1150 -0
  226. package/src/host/guard/paths.ts +239 -0
  227. package/src/host/guard/permission-policy.ts +15 -0
  228. package/src/host/guard/redact.ts +64 -0
  229. package/src/host/guard/rules.ts +891 -0
  230. package/src/host/guard/status-tool.ts +229 -0
  231. package/src/host/guard/tiers.ts +2 -0
  232. package/src/host/guard/validators.ts +29 -0
  233. package/src/host/health-poller.ts +446 -0
  234. package/src/host/index.ts +7 -0
  235. package/src/host/intents.ts +67 -0
  236. package/src/host/notifier.ts +71 -0
  237. package/src/host/paths.ts +70 -0
  238. package/src/host/plugin.ts +1097 -0
  239. package/src/host/preset.ts +170 -0
  240. package/src/host/report.ts +71 -0
  241. package/src/host/restart-exec.ts +81 -0
  242. package/src/host/restart-guards.ts +150 -0
  243. package/src/host/restart-tool.ts +483 -0
  244. package/src/host/restart-web.ts +72 -0
  245. package/src/host/resume-log.ts +39 -0
  246. package/src/host/resume-tools.ts +385 -0
  247. package/src/host/resume.ts +204 -0
  248. package/src/host/scan.ts +61 -0
  249. package/src/host/self-kill-guard.ts +216 -0
  250. package/src/host/session-health.ts +236 -0
  251. package/src/host/session-log-file.ts +77 -0
  252. package/src/host/skill-provider.ts +69 -0
  253. package/src/host/snapshot.ts +337 -0
  254. package/src/host/source.ts +19 -0
  255. package/src/host/store/index.ts +348 -0
  256. package/src/host/store/legacy.ts +96 -0
  257. package/src/host/supervisor.ts +720 -0
  258. package/src/host/sync/backup-config.ts +159 -0
  259. package/src/host/sync/backup-service.ts +453 -0
  260. package/src/host/sync/bidirectional.ts +66 -0
  261. package/src/host/sync/cli.ts +539 -0
  262. package/src/host/sync/config.ts +119 -0
  263. package/src/host/sync/fingerprint.ts +83 -0
  264. package/src/host/sync/hashing.ts +58 -0
  265. package/src/host/sync/index.ts +737 -0
  266. package/src/host/sync/machine-id.ts +81 -0
  267. package/src/host/sync/merge.ts +102 -0
  268. package/src/host/sync/peer-host.ts +65 -0
  269. package/src/host/sync/process-runner.ts +177 -0
  270. package/src/host/sync/remote-agent.ts +213 -0
  271. package/src/host/sync/remote-cache.ts +68 -0
  272. package/src/host/sync/remote-manifest.ts +70 -0
  273. package/src/host/sync/s3-object-store.ts +144 -0
  274. package/src/host/sync/session-merge.ts +220 -0
  275. package/src/host/sync/session-plan.ts +237 -0
  276. package/src/host/sync/sigv4.ts +81 -0
  277. package/src/host/sync/snapshot.ts +162 -0
  278. package/src/host/sync/ssh-mux.ts +56 -0
  279. package/src/host/sync/sync-plan.ts +366 -0
  280. package/src/host/sync/sync-service.ts +855 -0
  281. package/src/host/sync/sync-types.ts +102 -0
  282. package/src/host/sync/transport.ts +261 -0
  283. package/src/host/sync/tunnel-restore.ts +160 -0
  284. package/src/host/sync/validation.ts +91 -0
  285. package/src/host/tool-view.ts +98 -0
@@ -0,0 +1,94 @@
1
+ /**
2
+ * The Maestro M logo — canonical reference implementation.
3
+ *
4
+ * This file was a verbatim copy of dsh-maestro-dashboard's
5
+ * `src/client/components/BrandMark.tsx`, which this plugin set no longer
6
+ * installs. It is now the source of record: `AGENTS.md:394` points here, and
7
+ * the settings-nav mask in `index.tsx` plus the Settings card badge in
8
+ * `MaestroSettings.tsx` both build from the constants declared below.
9
+ *
10
+ * Every OTHER Maestro package still inlines its own copy of the path, and that
11
+ * duplication is structural — do not "fix" it with a cross-plugin import:
12
+ *
13
+ * - each plugin declares its own `dsh.client` entry ({platform: web}) and
14
+ * builds its own `lib/client.js`, so one plugin's client module cannot
15
+ * import another's;
16
+ * - dsh-maestro-remote's copy is a host-side HTML string (the PIN login
17
+ * badge in `src/host/remote-proxy.ts`), which no client module reaches;
18
+ * - dsh-maestro-gateway, -jobs and -sync each carry it in their own client
19
+ * bundle for the same reason.
20
+ *
21
+ * Mark: `M2 11 L5 4 L8 9 L11 4 L14 11`, currentColor, strokeWidth 1.6.
22
+ * Badge: `data-maestro-logo`, outer 28 / size 16 / radius 8, `#0A84FF` tile.
23
+ * The fixed brand blue keeps the badge visible on both light
24
+ * (`bg-base #fff`) and dark (`bg-base #121212`) — a token-only
25
+ * background can resolve to near-white on some dark tokens.
26
+ */
27
+
28
+ import { createElement as h } from 'react'
29
+ import {
30
+ MAESTRO_BRAND_TILE,
31
+ MAESTRO_MARK_PATH,
32
+ MAESTRO_MARK_STROKE_WIDTH,
33
+ MAESTRO_MARK_VIEWBOX,
34
+ } from '../maestro-mark.js'
35
+
36
+ // Re-exported so importers of this path keep working; the declarations live in
37
+ // ../maestro-mark.ts, which has no react import and is therefore importable
38
+ // from a test — BrandMark.tsx cannot be, because react is a client-bundler
39
+ // EXTERNAL with no entry in this package's package.json.
40
+ export {
41
+ MAESTRO_BRAND_TILE,
42
+ MAESTRO_MARK_PATH,
43
+ MAESTRO_MARK_STROKE_WIDTH,
44
+ MAESTRO_MARK_VIEWBOX,
45
+ maestroMarkMaskUri,
46
+ } from '../maestro-mark.js'
47
+
48
+ /**
49
+ * Keys a call site may override on the badge. POSITIONING ONLY — the tile's
50
+ * colour, border, shadow, radius and size are the brand and are not negotiable.
51
+ * A `style` prop spread wholesale would let any call site silently repaint the
52
+ * badge, which is the one thing the fixed `#0A84FF` exists to prevent.
53
+ */
54
+ export const BRAND_BADGE_LAYOUT_KEYS = [
55
+ 'alignSelf', 'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft',
56
+ ] as const
57
+
58
+ type BrandBadgeStyle = Partial<Record<(typeof BRAND_BADGE_LAYOUT_KEYS)[number], unknown>>
59
+
60
+ /** Keep only the layout keys; drop anything that would touch the chrome. */
61
+ function layoutOnly(style: BrandBadgeStyle | undefined): Record<string, unknown> {
62
+ const out: Record<string, unknown> = {}
63
+ for (const key of BRAND_BADGE_LAYOUT_KEYS) {
64
+ if (style?.[key] !== undefined) out[key] = style[key]
65
+ }
66
+ return out
67
+ }
68
+
69
+ export function MaestroMark(props: { size?: number }) {
70
+ const s = props.size ?? 16
71
+ return h('svg', { width: s, height: s, viewBox: MAESTRO_MARK_VIEWBOX, fill: 'none', 'aria-hidden': 'true' } as any,
72
+ h('path', { d: MAESTRO_MARK_PATH, stroke: 'currentColor', strokeWidth: MAESTRO_MARK_STROKE_WIDTH, strokeLinecap: 'round', strokeLinejoin: 'round' } as any)
73
+ )
74
+ }
75
+
76
+ /**
77
+ * `style` merges over the tile so a call site can position the badge without
78
+ * copying its chrome: the Settings card header needs `alignSelf`/`marginTop`
79
+ * to sit flush in a flex row, and those are layout, not brand.
80
+ */
81
+ export function BrandBadge(props: { size?: number; outer?: number; radius?: number; style?: BrandBadgeStyle }) {
82
+ const outer = props.outer ?? 28
83
+ const size = props.size ?? 16
84
+ const radius = props.radius ?? 8
85
+ return h('span', {
86
+ 'data-maestro-logo': '',
87
+ style: {
88
+ width: outer, height: outer, borderRadius: radius, display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
89
+ background: `var(--dsw-alias-brand-primary, ${MAESTRO_BRAND_TILE})`, backgroundColor: MAESTRO_BRAND_TILE, color: '#fff', flex: 'none',
90
+ border: '1px solid rgba(0,0,0,0.08)', boxShadow: '0 0 0 1px var(--dsw-alias-border-l1)', boxSizing: 'border-box' as any,
91
+ ...layoutOnly(props.style),
92
+ },
93
+ } as any, h(MaestroMark as any, { size }))
94
+ }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * Guard settings view-model (schema v2).
3
+ *
4
+ * The guard runtime (`dsh-maestro-guard/src/host/`) owns the authoritative
5
+ * schema (`GuardConfigV2`) and its legacy migration (`mapLegacyConfig`). This
6
+ * module mirrors both for DISPLAY ONLY so the Settings tab can render the
7
+ * effective state of a stored `domains.guard` document that may still carry
8
+ * the v1 keys (`gitProtection` / `publishBlocked` / `cwdContainment` /
9
+ * `credentialPaths`).
10
+ *
11
+ * Sync contract: `RULE_META` (ids, groups, default tiers) must match
12
+ * `RULE_IDS` + `DEFAULT_TIERS` in `dsh-maestro-guard/src/host/rules.ts`, and
13
+ * `effectiveGuardView` must match `mapLegacyConfig` + `DEFAULT_CONFIG` in
14
+ * `dsh-maestro-guard/src/host/config.ts`. `tests/guard-view.spec.ts` pins the
15
+ * parity against the sibling source; a guard-side rename breaks that test
16
+ * instead of silently desyncing this tab.
17
+ */
18
+
19
+ export type GuardTier = 'allow' | 'journal' | 'ask' | 'deny'
20
+
21
+ export const GUARD_TIERS: readonly GuardTier[] = ['allow', 'journal', 'ask', 'deny']
22
+
23
+ export function isGuardTier(v: unknown): v is GuardTier {
24
+ return v === 'allow' || v === 'journal' || v === 'ask' || v === 'deny'
25
+ }
26
+
27
+ export type GuardRuleGroup = 'Git' | 'Publish' | 'Filesystem' | 'Network' | 'Self-protection'
28
+
29
+ export interface GuardRuleMeta {
30
+ id: string
31
+ group: GuardRuleGroup
32
+ label: string
33
+ hint: string
34
+ defaultTier: GuardTier
35
+ /** True when the tier is a structural floor the UI must not offer below. */
36
+ locked?: boolean
37
+ }
38
+
39
+ /**
40
+ * The closed rule set with the copy the tab shows. `defaultTier` mirrors
41
+ * `DEFAULT_TIERS`; `hint` names the trigger in one line so the tab doubles as
42
+ * documentation. `guard.tamper` is `locked`: the runtime's `decide()` treats
43
+ * `deny` as a structural floor, so the selector offers no downgrade.
44
+ */
45
+ export const RULE_META: readonly GuardRuleMeta[] = [
46
+ { id: 'git.push.protected', group: 'Git', label: 'Push to protected branch', hint: 'Direct push to master/main (or your branch list).', defaultTier: 'ask' },
47
+ { id: 'git.merge.protected', group: 'Git', label: 'Merge into protected branch', hint: 'Local merge targeting a protected branch.', defaultTier: 'journal' },
48
+ { id: 'git.tag.release', group: 'Git', label: 'Release tag push', hint: 'Pushing a version-looking tag (v1.2.3).', defaultTier: 'ask' },
49
+ { id: 'git.push.force', group: 'Git', label: 'Force push', hint: 'push --force / --force-with-lease anywhere.', defaultTier: 'ask' },
50
+ { id: 'gh.release.create', group: 'Publish', label: 'Create GitHub/GitLab release', hint: 'gh release create and equivalents.', defaultTier: 'ask' },
51
+ { id: 'gh.protection.delete', group: 'Publish', label: 'Delete branch protection', hint: 'Removing protection rules from a branch.', defaultTier: 'ask' },
52
+ { id: 'pkg.publish', group: 'Publish', label: 'Publish a package', hint: 'pnpm/npm publish and tag pushes that trigger it.', defaultTier: 'ask' },
53
+ { id: 'secret.access', group: 'Filesystem', label: 'Read a secret location', hint: 'Any read of a protected credential path.', defaultTier: 'ask' },
54
+ { id: 'fs.write.outside', group: 'Filesystem', label: 'Write outside working dir', hint: 'File writes escaping the session cwd (temp dir exempt).', defaultTier: 'ask' },
55
+ { id: 'net.exec.remote', group: 'Network', label: 'Remote execution', hint: 'ssh / cloudflared-tunnelled commands.', defaultTier: 'ask' },
56
+ { id: 'guard.tamper', group: 'Self-protection', label: 'Edit guard config or journal', hint: 'Any write to the guard settings or its audit trail.', defaultTier: 'deny', locked: true },
57
+ ]
58
+
59
+ /** The three git rules the legacy `gitProtection.enabled: false` used to gate. */
60
+ const LEGACY_GIT_RULES: readonly string[] = ['git.push.protected', 'git.tag.release', 'git.push.force']
61
+
62
+ export type TierSource = 'default' | 'stored' | 'legacy'
63
+
64
+ export interface GuardRuleView extends GuardRuleMeta {
65
+ tier: GuardTier
66
+ source: TierSource
67
+ }
68
+
69
+ export interface GuardView {
70
+ rules: GuardRuleView[]
71
+ protectedBranches: string[]
72
+ branchesSource: TierSource
73
+ /** Extra user paths; the built-in always-blocked list lives in the runtime. */
74
+ protectedPaths: string[]
75
+ containment: { enabled: boolean; spillReads: boolean }
76
+ journal: { enabled: boolean; allowCounters: boolean; retainDays: number; retainFiles: number }
77
+ }
78
+
79
+ const DEFAULT_BRANCHES: readonly string[] = ['master', 'main']
80
+
81
+ function stringArray(v: unknown): string[] | undefined {
82
+ if (!Array.isArray(v)) return undefined
83
+ const out = v.filter((x): x is string => typeof x === 'string' && x.trim() !== '')
84
+ return out.length > 0 ? out : undefined
85
+ }
86
+
87
+ function booleanOr(v: unknown, fallback: boolean): boolean {
88
+ return typeof v === 'boolean' ? v : fallback
89
+ }
90
+
91
+ function positiveIntOr(v: unknown, fallback: number): number {
92
+ return typeof v === 'number' && Number.isInteger(v) && v > 0 ? v : fallback
93
+ }
94
+
95
+ function isRecord(v: unknown): v is Record<string, unknown> {
96
+ return typeof v === 'object' && v !== null && !Array.isArray(v)
97
+ }
98
+
99
+ /**
100
+ * Compute what the tab shows for a stored `domains.guard` document. Precedence
101
+ * mirrors the runtime: an explicit v2 entry wins, a legacy boolean fills the
102
+ * gap it used to own, otherwise the built-in default renders.
103
+ */
104
+ export function effectiveGuardView(raw: unknown): GuardView {
105
+ const doc = isRecord(raw) ? raw : {}
106
+ const storedRules = isRecord(doc.rules) ? doc.rules : {}
107
+
108
+ const rules: GuardRuleView[] = RULE_META.map((meta) => {
109
+ const stored = storedRules[meta.id]
110
+ if (isGuardTier(stored)) return { ...meta, tier: stored, source: 'stored' }
111
+ const legacyTier = legacyTierFor(meta.id, doc)
112
+ if (legacyTier !== undefined) return { ...meta, tier: legacyTier, source: 'legacy' }
113
+ return { ...meta, tier: meta.defaultTier, source: 'default' }
114
+ })
115
+
116
+ const v2Branches = stringArray(doc.protectedBranches)
117
+ const legacyBranches = isRecord(doc.gitProtection) ? stringArray(doc.gitProtection.branches) : undefined
118
+ const protectedBranches = v2Branches ?? legacyBranches ?? [...DEFAULT_BRANCHES]
119
+
120
+ const v2Paths = stringArray(doc.protectedPaths) ?? []
121
+ const legacyPaths = stringArray(doc.credentialPaths) ?? []
122
+ const protectedPaths = [...new Set([...v2Paths, ...legacyPaths])]
123
+
124
+ const containmentRaw = isRecord(doc.workingDirContainment) ? doc.workingDirContainment : {}
125
+ // Legacy `cwdContainment: false` meant "fs.write.outside journals instead of
126
+ // asking"; it never disabled containment, so `enabled` stays true and only
127
+ // the rule tier above reflects it.
128
+ const containment = {
129
+ enabled: booleanOr(containmentRaw.enabled, true),
130
+ spillReads: booleanOr(containmentRaw.spillReads, true),
131
+ }
132
+
133
+ const journalRaw = isRecord(doc.journal) ? doc.journal : {}
134
+ const journal = {
135
+ enabled: booleanOr(journalRaw.enabled, true),
136
+ allowCounters: booleanOr(journalRaw.allowCounters, true),
137
+ retainDays: positiveIntOr(journalRaw.retainDays, 30),
138
+ retainFiles: positiveIntOr(journalRaw.retainFiles, 14),
139
+ }
140
+
141
+ return {
142
+ rules,
143
+ protectedBranches,
144
+ branchesSource: v2Branches !== undefined ? 'stored' : legacyBranches !== undefined ? 'legacy' : 'default',
145
+ protectedPaths,
146
+ containment,
147
+ journal,
148
+ }
149
+ }
150
+
151
+ /** The tier a legacy v1 document implies for one rule, if any. */
152
+ function legacyTierFor(ruleId: string, doc: Record<string, unknown>): GuardTier | undefined {
153
+ if (LEGACY_GIT_RULES.includes(ruleId)) {
154
+ const gp = doc.gitProtection
155
+ if (isRecord(gp) && Object.keys(gp).length > 0 && gp.enabled === false) return 'journal'
156
+ return undefined
157
+ }
158
+ if (ruleId === 'pkg.publish' && doc.publishBlocked === false) return 'journal'
159
+ if (ruleId === 'fs.write.outside' && doc.cwdContainment === false) return 'journal'
160
+ return undefined
161
+ }
162
+
163
+ /**
164
+ * Split a comma-separated list field (branches, paths) the way the tab's text
165
+ * inputs commit it: trim, drop empties, de-duplicate.
166
+ */
167
+ export function parseListField(text: string): string[] {
168
+ return [...new Set(text.split(',').map((s) => s.trim()).filter((s) => s !== ''))]
169
+ }
170
+
171
+ /** True when at least one rule renders from a non-default source. */
172
+ export function hasCustomTiers(view: GuardView): boolean {
173
+ return view.rules.some((r) => r.source !== 'default')
174
+ }
175
+
176
+ /**
177
+ * Patch that sets one rule's tier, or unsets it back to the built-in default.
178
+ * Unset is an explicit null: the store's deep-merge cannot delete keys, but
179
+ * the runtime's `mergeGuardConfig` only copies string tiers, so a null is
180
+ * dropped at merge time and `decide()` never sees it — unlike writing the
181
+ * default tier out explicitly, which `decide()` ignores as an echo yet would
182
+ * still render as "customized" here. `effectiveGuardView` above treats null
183
+ * like an absent entry (not a tier), so the row returns to `default`.
184
+ */
185
+ export function ruleTierPatch(ruleId: string, tier: GuardTier | 'default'): Record<string, GuardTier | null> {
186
+ return { [ruleId]: tier === 'default' ? null : tier }
187
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Settings nav order for every Maestro section.
3
+ *
4
+ * The shell sorts `settings.section` rows by `order` alone, so two registrants
5
+ * sharing a number have no defined relative order. Upstream's
6
+ * `archived-sessions` page occupies 25, which is exactly where this plugin used
7
+ * to register: the Maestro tabs and Archived sessions swapped places between
8
+ * loads. The Maestro block therefore starts at 26, and the sibling tabs in
9
+ * dsh-maestro-jobs / -sync / -gateway continue from here — keep them ahead of
10
+ * later upstream sections and never reuse 25.
11
+ */
12
+ export const MAESTRO_SETTINGS_ORDER = 26
13
+
14
+ // DSH-native redesign — reuses DSH tokens & primitive geometry maximally (see MaestroSettings.tsx).
15
+ import { MaestroSettingsTab } from './MaestroSettings.js'
16
+ import { registerSettingsNavIcon, SETTINGS_NAV_MARKER } from './settings-nav-icon.js'
17
+ import { maestroMarkMaskUri } from './components/BrandMark.js'
18
+
19
+ /**
20
+ * DSH 0.1.x gives external settings sections a generic gear and exposes no
21
+ * icon field in the settings.section contract (mirrors dsh-better-sidebar):
22
+ * the marker only claims this plugin's localized row and this CSS paints the
23
+ * Maestro M-logo glyph as a currentColor mask so it follows native nav
24
+ * hover/active colors at the shell's 16px icon rhythm. The glyph itself is
25
+ * declared once in components/BrandMark.tsx — the workspace reference
26
+ * implementation.
27
+ */
28
+ const SETTINGS_NAV_CSS = `
29
+
30
+ /* maestro: replace the settings-nav fallback gear with the Maestro M-logo glyph — same mark as components/BrandMark.tsx */
31
+ [${SETTINGS_NAV_MARKER}] > svg:first-child,
32
+ [${SETTINGS_NAV_MARKER}] > svg.zWKi1a_navIcon {
33
+ display: none !important;
34
+ }
35
+
36
+ [${SETTINGS_NAV_MARKER}]::before {
37
+ content: '';
38
+ flex: none;
39
+ width: 16px;
40
+ height: 16px;
41
+ display: inline-block;
42
+ background: currentColor;
43
+ -webkit-mask: url("${maestroMarkMaskUri()}") center / contain no-repeat;
44
+ mask: url("${maestroMarkMaskUri()}") center / contain no-repeat;
45
+ }
46
+ `
47
+
48
+ type SlotsApi = {
49
+ inject(name: string, factory: () => unknown): void
50
+ register(
51
+ options: Record<string, unknown>,
52
+ render: (props: { configRpcCall: RpcCall; supervisorRpcCall: RpcCall }) => unknown,
53
+ ): unknown
54
+ }
55
+ type RpcCall = (endpoint: string, payload?: unknown, signal?: AbortSignal) => Promise<unknown>
56
+
57
+ interface ClientCtx {
58
+ get?(name: string): unknown
59
+ effect(fn: () => () => void, label?: string): unknown
60
+ }
61
+
62
+ export const inject = ['slots', 'connection'] as const
63
+
64
+ function installNavIconStyle(): () => void {
65
+ const tag = document.createElement('style')
66
+ tag.dataset.plugin = '@ddtcorex/dsh-maestro-config'
67
+ tag.dataset.pluginCss = 'maestro/settings-nav.css'
68
+ tag.textContent = SETTINGS_NAV_CSS
69
+ document.head.appendChild(tag)
70
+ return () => {
71
+ document.querySelector('style[data-plugin-css="maestro/settings-nav.css"]')?.remove()
72
+ }
73
+ }
74
+
75
+ export function apply(ctx: ClientCtx): void {
76
+ const slots = ctx.get?.('slots') as SlotsApi | undefined
77
+ if (slots === undefined) return
78
+
79
+ // Generic config RPC: guard, blacklist and supervisor documents
80
+ const configRpcCall: RpcCall = (endpoint, payload, signal) => {
81
+ const connection = ctx.get?.('connection') as
82
+ | { rpc: { call(ch: string, ep: string, p?: unknown, s?: AbortSignal): Promise<unknown> } }
83
+ | undefined
84
+ if (!connection?.rpc?.call) return Promise.reject(new Error('RPC not available'))
85
+ return connection.rpc.call('/dsh-maestro-config', endpoint, payload, signal)
86
+ }
87
+ // Supervisor's own loopback channel — used only to read the EFFECTIVE
88
+ // auto-resume state (`status`), so the toggle can render locked when an
89
+ // install-supplied Cordis config pins the value. Absent plugin → absent
90
+ // service → the caller falls back to the unlocked toggle.
91
+ const supervisorRpcCall: RpcCall = (endpoint, payload, signal) => {
92
+ const connection = ctx.get?.('connection') as
93
+ | { rpc: { call(ch: string, ep: string, p?: unknown, s?: AbortSignal): Promise<unknown> } }
94
+ | undefined
95
+ if (!connection?.rpc?.call) return Promise.reject(new Error('RPC not available'))
96
+ return connection.rpc.call('/dsh-maestro-supervisor-resume', endpoint, payload, signal)
97
+ }
98
+
99
+ // Reversible effects: nav-row marker observer + owned style tag.
100
+ ctx.effect(() => registerSettingsNavIcon(() => 'Maestro'), 'maestro: settings nav icon')
101
+ ctx.effect(installNavIconStyle, 'maestro: settings nav css')
102
+
103
+ slots.inject('settings.section', () =>
104
+ slots.register(
105
+ { name: 'settings.section', id: 'maestro', order: MAESTRO_SETTINGS_ORDER, label: () => 'Maestro', inject: () => ({ configRpcCall, supervisorRpcCall }) },
106
+ MaestroSettingsTab as unknown as (props: { configRpcCall: RpcCall; supervisorRpcCall: RpcCall }) => unknown,
107
+ ),
108
+ )
109
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Maestro M logo — the react-free half of the reference implementation.
3
+ *
4
+ * Split out from `components/BrandMark.tsx` so the glyph declaration and the
5
+ * CSS-mask encoding are importable from a test. `BrandMark.tsx` imports react,
6
+ * which the client bundler treats as an EXTERNAL with no entry in this
7
+ * package's `package.json` — so it cannot be imported from vitest at all, and a
8
+ * test that only greps its text would accept a naive `encodeURIComponent` that
9
+ * silently changes every rendered mask. This module has no react import, so
10
+ * `tests/brand-mark.spec.ts` can assert the exact URI bytes.
11
+ *
12
+ * The path itself is duplicated in other Maestro packages and that duplication
13
+ * is structural — see the header in `components/BrandMark.tsx`.
14
+ */
15
+
16
+ export const MAESTRO_MARK_PATH = 'M2 11 L5 4 L8 9 L11 4 L14 11'
17
+ export const MAESTRO_MARK_VIEWBOX = '0 0 16 16'
18
+ export const MAESTRO_MARK_STROKE_WIDTH = 1.6
19
+
20
+ /** Badge tile colour — part of the house pattern documented in AGENTS.md. */
21
+ export const MAESTRO_BRAND_TILE = '#0A84FF'
22
+
23
+ /**
24
+ * The exact data-URI the settings-nav row paints as a `currentColor` mask.
25
+ *
26
+ * Only `<` and `>` are encoded. `encodeURIComponent` would additionally escape
27
+ * quotes, slashes and spaces, producing a different URI than the literal this
28
+ * replaces — and the row renders through `mask`, so a subtly different URI can
29
+ * leave the glyph blank. `tests/brand-mark.spec.ts` pins the bytes.
30
+ */
31
+ export function maestroMarkMaskUri(): string {
32
+ const svg =
33
+ `<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='${MAESTRO_MARK_VIEWBOX}' ` +
34
+ `fill='none' stroke='black' stroke-width='${MAESTRO_MARK_STROKE_WIDTH}' ` +
35
+ `stroke-linecap='round' stroke-linejoin='round'><path d='${MAESTRO_MARK_PATH}'/></svg>`
36
+ return `data:image/svg+xml,${svg.replace(/</g, '%3C').replace(/>/g, '%3E')}`
37
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Mark this plugin's row in the DSH settings navigation so a style block can
3
+ * replace the shell's fallback gear with the maestro glyph.
4
+ *
5
+ * DSH 0.1.x projects only `id`, `order`, and `label` from a `settings.section`
6
+ * registration and picks icons from a closed built-in list, so each external
7
+ * plugin identifies its own localized row by visible text after the dialog
8
+ * mounts. The marker owns no shell structure and is removed on disposal.
9
+ */
10
+
11
+ export const SETTINGS_NAV_MARKER = 'data-maestro-settings-nav'
12
+
13
+ /** Minimal DOM surface used here; tests inject a stub instead of `document`. */
14
+ /** The two DOM iteration shapes this module touches (querySelector results). */
15
+ type NodeSeq = Iterable<Element> & { forEach(fn: (el: Element) => void): unknown }
16
+
17
+ interface DomScope {
18
+ querySelectorAll(selector: string): NodeSeq
19
+ }
20
+
21
+ type ElementLike = Element & {
22
+ setAttribute(name: string, value: string): void
23
+ removeAttribute(name: string): void
24
+ }
25
+
26
+ export function registerSettingsNavIcon(
27
+ label: () => string,
28
+ root?: DomScope,
29
+ ): () => void {
30
+ if (typeof document === 'undefined' && root === undefined) {
31
+ // Node-side import safety (tests inject a stub root instead).
32
+ return () => {}
33
+ }
34
+ const scope = (root ?? document) as DomScope
35
+
36
+ let disposed = false
37
+
38
+ const sync = () => {
39
+ if (disposed) return
40
+ const currentLabel = label().trim()
41
+ const buttons = scope.querySelectorAll('[role="dialog"] nav button')
42
+ for (const button of Array.from(buttons)) {
43
+ const el = button as ElementLike
44
+ const matches =
45
+ currentLabel.length > 0 &&
46
+ button.textContent != null &&
47
+ button.textContent.trim() === currentLabel
48
+ if (matches) el.setAttribute(SETTINGS_NAV_MARKER, '')
49
+ else el.removeAttribute(SETTINGS_NAV_MARKER)
50
+ }
51
+ }
52
+
53
+ sync()
54
+
55
+ let observer: MutationObserver | null = null
56
+ if (typeof MutationObserver !== 'undefined') {
57
+ observer = new MutationObserver(sync)
58
+ observer.observe(document.body, { childList: true, subtree: true, characterData: true })
59
+ }
60
+
61
+ return () => {
62
+ disposed = true
63
+ if (observer !== null) observer.disconnect()
64
+ for (const element of Array.from(scope.querySelectorAll(`[${SETTINGS_NAV_MARKER}]`))) {
65
+ ;(element as ElementLike).removeAttribute(SETTINGS_NAV_MARKER)
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * dsh-maestro-core — composed client bundle entry.
3
+ *
4
+ * One browser bundle registers every client surface this package owns: the
5
+ * supervisor auto-reload, the Maestro settings card and the Maestro Sync card.
6
+ * Each module apply is wrapped in its own try/catch so one broken surface never
7
+ * costs the other two their registration — a settings card that throws on
8
+ * mount must not also take the reload poller down with it.
9
+ */
10
+ import { apply as applyAutoReload } from './auto-reload.js'
11
+ import { apply as applyConfig } from './config/index.js'
12
+ import { apply as applySync } from './sync/index.js'
13
+
14
+ /** Union of what the three modules need from the client context. */
15
+ export const inject = ['slots', 'connection'] as const
16
+
17
+ type ClientCtx = Parameters<typeof applyAutoReload>[0]
18
+
19
+ const MODULES = [
20
+ ['auto-reload', applyAutoReload],
21
+ ['config', applyConfig],
22
+ ['sync', applySync],
23
+ ] as const
24
+
25
+ export function apply(ctx: ClientCtx): void {
26
+ for (const [name, register] of MODULES) {
27
+ try {
28
+ register(ctx as never)
29
+ } catch (err) {
30
+ console.error(`[dsh-maestro-core] ${name} client module failed to apply`, err)
31
+ }
32
+ }
33
+ }