@ddtcorex/dsh-maestro-core 0.15.1 → 0.16.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 (117) hide show
  1. package/README.md +7 -7
  2. package/assets/icon.svg +4 -0
  3. package/cordis.patch.yml +0 -12
  4. package/lib/client.js +3 -1744
  5. package/lib/health-poller.js +1 -1
  6. package/lib/self-kill-guard.d.ts +25 -8
  7. package/lib/self-kill-guard.js +81 -27
  8. package/lib/types/client/config/components/BrandMark.d.ts +3 -3
  9. package/lib/types/client/index.d.ts.map +1 -1
  10. package/locale/en.json +6 -0
  11. package/package.json +9 -5
  12. package/src/client/config/components/BrandMark.tsx +3 -3
  13. package/src/client/index.tsx +0 -2
  14. package/src/host/health-poller.ts +1 -1
  15. package/src/host/self-kill-guard.ts +84 -26
  16. package/lib/sync/backup-config.d.ts +0 -55
  17. package/lib/sync/backup-config.js +0 -119
  18. package/lib/sync/backup-service.d.ts +0 -123
  19. package/lib/sync/backup-service.js +0 -486
  20. package/lib/sync/bidirectional.d.ts +0 -39
  21. package/lib/sync/bidirectional.js +0 -25
  22. package/lib/sync/cli.d.ts +0 -38
  23. package/lib/sync/cli.js +0 -528
  24. package/lib/sync/config.d.ts +0 -59
  25. package/lib/sync/config.js +0 -72
  26. package/lib/sync/fingerprint.d.ts +0 -29
  27. package/lib/sync/fingerprint.js +0 -65
  28. package/lib/sync/hashing.d.ts +0 -22
  29. package/lib/sync/hashing.js +0 -77
  30. package/lib/sync/index.d.ts +0 -6
  31. package/lib/sync/index.js +0 -619
  32. package/lib/sync/machine-id.d.ts +0 -29
  33. package/lib/sync/machine-id.js +0 -66
  34. package/lib/sync/merge.d.ts +0 -31
  35. package/lib/sync/merge.js +0 -86
  36. package/lib/sync/peer-host.d.ts +0 -22
  37. package/lib/sync/peer-host.js +0 -62
  38. package/lib/sync/process-runner.d.ts +0 -31
  39. package/lib/sync/process-runner.js +0 -161
  40. package/lib/sync/remote-agent.d.ts +0 -41
  41. package/lib/sync/remote-agent.js +0 -216
  42. package/lib/sync/remote-cache.d.ts +0 -18
  43. package/lib/sync/remote-cache.js +0 -60
  44. package/lib/sync/remote-manifest.d.ts +0 -20
  45. package/lib/sync/remote-manifest.js +0 -86
  46. package/lib/sync/s3-object-store.d.ts +0 -38
  47. package/lib/sync/s3-object-store.js +0 -126
  48. package/lib/sync/session-plan.d.ts +0 -29
  49. package/lib/sync/session-plan.js +0 -213
  50. package/lib/sync/sigv4.d.ts +0 -20
  51. package/lib/sync/sigv4.js +0 -57
  52. package/lib/sync/snapshot.d.ts +0 -16
  53. package/lib/sync/snapshot.js +0 -143
  54. package/lib/sync/ssh-mux.d.ts +0 -12
  55. package/lib/sync/ssh-mux.js +0 -48
  56. package/lib/sync/store-root.d.ts +0 -44
  57. package/lib/sync/store-root.js +0 -67
  58. package/lib/sync/sync-plan.d.ts +0 -24
  59. package/lib/sync/sync-plan.js +0 -366
  60. package/lib/sync/sync-service.d.ts +0 -183
  61. package/lib/sync/sync-service.js +0 -926
  62. package/lib/sync/sync-types.d.ts +0 -87
  63. package/lib/sync/sync-types.js +0 -1
  64. package/lib/sync/transport.d.ts +0 -75
  65. package/lib/sync/transport.js +0 -196
  66. package/lib/sync/tunnel-restore.d.ts +0 -77
  67. package/lib/sync/tunnel-restore.js +0 -142
  68. package/lib/sync/validation.d.ts +0 -12
  69. package/lib/sync/validation.js +0 -96
  70. package/lib/types/client/sync/R2SyncPanel.d.ts +0 -6
  71. package/lib/types/client/sync/R2SyncPanel.d.ts.map +0 -1
  72. package/lib/types/client/sync/SyncPanel.d.ts +0 -12
  73. package/lib/types/client/sync/SyncPanel.d.ts.map +0 -1
  74. package/lib/types/client/sync/confirm-dialog.d.ts +0 -43
  75. package/lib/types/client/sync/confirm-dialog.d.ts.map +0 -1
  76. package/lib/types/client/sync/index.d.ts +0 -10
  77. package/lib/types/client/sync/index.d.ts.map +0 -1
  78. package/lib/types/client/sync/ui.d.ts +0 -75
  79. package/lib/types/client/sync/ui.d.ts.map +0 -1
  80. package/lib/types/client/sync/use-backup.d.ts +0 -50
  81. package/lib/types/client/sync/use-backup.d.ts.map +0 -1
  82. package/lib/types/client/sync/use-sync.d.ts +0 -88
  83. package/lib/types/client/sync/use-sync.d.ts.map +0 -1
  84. package/src/client/sync/R2SyncPanel.tsx +0 -260
  85. package/src/client/sync/SyncPanel.tsx +0 -422
  86. package/src/client/sync/confirm-dialog.tsx +0 -202
  87. package/src/client/sync/index.tsx +0 -286
  88. package/src/client/sync/ui.tsx +0 -297
  89. package/src/client/sync/use-backup.ts +0 -207
  90. package/src/client/sync/use-sync.ts +0 -502
  91. package/src/host/sync/backup-config.ts +0 -158
  92. package/src/host/sync/backup-service.ts +0 -506
  93. package/src/host/sync/bidirectional.ts +0 -66
  94. package/src/host/sync/cli.ts +0 -530
  95. package/src/host/sync/config.ts +0 -96
  96. package/src/host/sync/fingerprint.ts +0 -83
  97. package/src/host/sync/hashing.ts +0 -91
  98. package/src/host/sync/index.ts +0 -697
  99. package/src/host/sync/machine-id.ts +0 -81
  100. package/src/host/sync/merge.ts +0 -99
  101. package/src/host/sync/peer-host.ts +0 -65
  102. package/src/host/sync/process-runner.ts +0 -177
  103. package/src/host/sync/remote-agent.ts +0 -212
  104. package/src/host/sync/remote-cache.ts +0 -68
  105. package/src/host/sync/remote-manifest.ts +0 -91
  106. package/src/host/sync/s3-object-store.ts +0 -144
  107. package/src/host/sync/session-plan.ts +0 -237
  108. package/src/host/sync/sigv4.ts +0 -81
  109. package/src/host/sync/snapshot.ts +0 -132
  110. package/src/host/sync/ssh-mux.ts +0 -55
  111. package/src/host/sync/store-root.ts +0 -83
  112. package/src/host/sync/sync-plan.ts +0 -366
  113. package/src/host/sync/sync-service.ts +0 -960
  114. package/src/host/sync/sync-types.ts +0 -102
  115. package/src/host/sync/transport.ts +0 -256
  116. package/src/host/sync/tunnel-restore.ts +0 -160
  117. package/src/host/sync/validation.ts +0 -104
@@ -26,7 +26,7 @@ export function getActiveEnterMs() {
26
26
  }
27
27
  // Specific parse/boot-failure markers only. Bare 'JSON'/'YAML' were removed
28
28
  // (2026-08-31): they matched any line whose payload merely *contained* those
29
- // substrings — e.g. maestro-sync's status JSON listing session.jsonl.zstd /
29
+ // substrings — e.g. a sync status JSON listing session.jsonl.zstd /
30
30
  // settings.json paths — turning a healthy 401 into a restart.
31
31
  const ERROR_PATTERNS = [
32
32
  'ERR_MODULE_NOT_FOUND',
@@ -3,6 +3,13 @@
3
3
  * kill or restart the very dsh web process the agent is running inside. The
4
4
  * model must route restarts through the supervisor's dsh_web_restart tool, not
5
5
  * by killing the host.
6
+ *
7
+ * The predicate is scoped to the HOST, not to the verb family: what makes a
8
+ * command a self-kill is its TARGET (a live host pid, or the `dsh` name in a
9
+ * kill/restart shape), never the mere presence of `kill`/`pkill`/`killall`.
10
+ * A blanket verb deny read as "no process may ever be killed through the agent"
11
+ * and blocked ordinary work (`pkill -f chrome`, `systemctl status nginx`,
12
+ * `kill 1234 2>/dev/null`), which is not the protection this file exists for.
6
13
  */
7
14
  /**
8
15
  * Remove data spans (quoted strings and heredoc bodies) from a command before
@@ -49,14 +56,24 @@ export interface ProcessRow {
49
56
  */
50
57
  export declare function resolveDshWebTreePids(listeners: number[], rows: ProcessRow[], boundary?: (pid: number) => TreeBoundaryKind): number[];
51
58
  /**
52
- * Whether a shell command is a self-kill. `livePids` are the pids of the dsh
53
- * web process forest; a `kill <pid>` whose pid is one of ours is a self-kill
54
- * regardless of anything else in the command. The kill parser accepts flag
55
- * forms (`kill -9 <pid>`, `kill -TERM <pid>`). A command that is essentially
56
- * JUST a `kill <unrelated-pid>` is allowed (idempotent cleanups are common),
57
- * as are kill attempts whose output reports "not found"/"done" — but any
58
- * compound that chains a restart/kill after it (or before the end) stays
59
- * denied.
59
+ * Whether a shell command is a self-kill. Two questions decide it, and both are
60
+ * about the TARGET, never about the verb:
61
+ *
62
+ * 1. does the command name a pid of the dsh web process forest? A command that
63
+ * signals a live host pid is a self-kill in whatever shape it arrives
64
+ * (`kill -9 300`, `kill -9 300 2>/dev/null`, `nice kill 300`, `pkill -9 300`),
65
+ * because the target is exact;
66
+ * 2. does a kill-family or restart shape name the host? `kill`/`pkill`/`killall`
67
+ * carrying `dsh` in any argument (`pkill -f "dsh web"`, `bash -c "pkill -f
68
+ * dsh"`), a `systemctl` ACTION on a dsh unit, the `restart-dsh-web` helper,
69
+ * and killing whatever owns :3080.
70
+ *
71
+ * Everything else is allowed, including a kill of an unrelated pid, `killall
72
+ * node`, `pkill -f chrome` and `systemctl restart mysql`. Wide patterns such as
73
+ * `pkill -f node` can still take the host down, so the guard only promises that
74
+ * it will not DENY ordinary kill-family work: the host's own recovery (supervisor
75
+ * daemon + auto-resume) is what covers an agent that aims badly, exactly as
76
+ * before this file existed.
60
77
  */
61
78
  export declare function isSelfKillCommand(cmd: string, livePids: number[]): boolean;
62
79
  /**
@@ -3,8 +3,16 @@
3
3
  * kill or restart the very dsh web process the agent is running inside. The
4
4
  * model must route restarts through the supervisor's dsh_web_restart tool, not
5
5
  * by killing the host.
6
+ *
7
+ * The predicate is scoped to the HOST, not to the verb family: what makes a
8
+ * command a self-kill is its TARGET (a live host pid, or the `dsh` name in a
9
+ * kill/restart shape), never the mere presence of `kill`/`pkill`/`killall`.
10
+ * A blanket verb deny read as "no process may ever be killed through the agent"
11
+ * and blocked ordinary work (`pkill -f chrome`, `systemctl status nginx`,
12
+ * `kill 1234 2>/dev/null`), which is not the protection this file exists for.
6
13
  */
7
14
  import { createRequire } from 'node:module';
15
+ import { parseCommand, unwrapSegments } from './guard/parse.js';
8
16
  const require = createRequire(import.meta.url);
9
17
  // Patterns that restart/stop/start or kill dsh web (systemctl --user units,
10
18
  // pkill/killall over the dsh tree, killing holders of :3080, and the
@@ -13,11 +21,21 @@ const require = createRequire(import.meta.url);
13
21
  // text that merely MENTIONS these words (echo/printf/script bodies) is data,
14
22
  // not argv.
15
23
  const SELF_KILL_RE = /(systemctl\s+--?user\s+.*(restart|stop|start).*dsh-web|pkill\s+.*dsh|killall\s+.*dsh|ss\s+.*3080.*kill|restart-dsh-web)/i;
16
- // A segment whose command position is one of these verbs is a real kill-family
17
- // invocation: blanket-denied even when its target lives inside quotes
18
- // (`pkill -f "dsh web"` must still be caught). `sudo`/`env VAR=` prefixes are
19
- // stripped before the verb is read.
20
- const DANGEROUS_KILL_VERB = /^(?:sudo\s+|env\s+\S+\s+)*(pkill|killall|kill|systemctl)\b/i;
24
+ /** Verbs whose whole job is ending a process (their target is what matters). */
25
+ const KILL_FAMILY = new Set(['kill', 'pkill', 'killall']);
26
+ /**
27
+ * The `systemctl` actions that can stop the host or something it depends on. A
28
+ * read-only `systemctl status` is deliberately absent: it is how an operator
29
+ * inspects the host, and refusing it protects nothing.
30
+ */
31
+ const SYSTEMCTL_ACTIONS = new Set([
32
+ 'restart', 'stop', 'start', 'kill', 'try-restart', 'reload-or-restart',
33
+ 'force-reload', 'isolate', 'reboot', 'halt', 'poweroff', 'suspend',
34
+ ]);
35
+ /** The host's own name, in any spelling the process or unit carries it in. */
36
+ const DSH_TARGET = /dsh/i;
37
+ /** Fallback reading for input the parser refuses: a kill-family word plus the host's name. */
38
+ const KILL_FAMILY_RAW = /\b(?:kill|pkill|killall)\b/i;
21
39
  /**
22
40
  * Remove data spans (quoted strings and heredoc bodies) from a command before
23
41
  * self-kill matching. Text inside quotes or a heredoc is content — an echo,
@@ -112,40 +130,76 @@ export function resolveDshWebTreePids(listeners, rows, boundary = () => 'launche
112
130
  return [...protectedSet].sort((a, b) => a - b);
113
131
  }
114
132
  /**
115
- * Whether a shell command is a self-kill. `livePids` are the pids of the dsh
116
- * web process forest; a `kill <pid>` whose pid is one of ours is a self-kill
117
- * regardless of anything else in the command. The kill parser accepts flag
118
- * forms (`kill -9 <pid>`, `kill -TERM <pid>`). A command that is essentially
119
- * JUST a `kill <unrelated-pid>` is allowed (idempotent cleanups are common),
120
- * as are kill attempts whose output reports "not found"/"done" — but any
121
- * compound that chains a restart/kill after it (or before the end) stays
122
- * denied.
133
+ * Whether a shell command is a self-kill. Two questions decide it, and both are
134
+ * about the TARGET, never about the verb:
135
+ *
136
+ * 1. does the command name a pid of the dsh web process forest? A command that
137
+ * signals a live host pid is a self-kill in whatever shape it arrives
138
+ * (`kill -9 300`, `kill -9 300 2>/dev/null`, `nice kill 300`, `pkill -9 300`),
139
+ * because the target is exact;
140
+ * 2. does a kill-family or restart shape name the host? `kill`/`pkill`/`killall`
141
+ * carrying `dsh` in any argument (`pkill -f "dsh web"`, `bash -c "pkill -f
142
+ * dsh"`), a `systemctl` ACTION on a dsh unit, the `restart-dsh-web` helper,
143
+ * and killing whatever owns :3080.
144
+ *
145
+ * Everything else is allowed, including a kill of an unrelated pid, `killall
146
+ * node`, `pkill -f chrome` and `systemctl restart mysql`. Wide patterns such as
147
+ * `pkill -f node` can still take the host down, so the guard only promises that
148
+ * it will not DENY ordinary kill-family work: the host's own recovery (supervisor
149
+ * daemon + auto-resume) is what covers an agent that aims badly, exactly as
150
+ * before this file existed.
123
151
  */
124
152
  export function isSelfKillCommand(cmd, livePids) {
125
- // pid-targeted kill: an exact live pid is a self-kill regardless of context
126
- if (/kill\s+(?:-\S+\s+)?(\d+)/i.test(cmd)) {
127
- const pid = Number(cmd.match(/kill\s+(?:-\S+\s+)?(\d+)/i)?.[1]);
128
- if (livePids.includes(pid))
153
+ const live = new Set(livePids);
154
+ // An exact host pid anywhere in a kill invocation is a self-kill, including
155
+ // through wrappers whose verb the parser cannot see (`nice -n 10 kill 300`).
156
+ for (const match of cmd.matchAll(/\bkill\s+(?:-\S+\s+)*(\d+)/gi)) {
157
+ if (live.has(Number(match[1])))
129
158
  return true;
130
159
  }
131
- // Targeted patterns may span segments (`ss ... | grep 3080 | xargs kill`),
132
- // so test the stripped full text once, then verbs per segment.
160
+ // Shapes whose target the argv does not carry: killing whatever owns :3080,
161
+ // and the guarded restart helper itself.
133
162
  const stripped = stripDataSpans(cmd);
134
163
  if (SELF_KILL_RE.test(stripped))
135
164
  return true;
136
- for (const seg of stripped.split(/\s*(?:&&|\|\||;|\||\r?\n)+\s*/)) {
137
- // Exclude ONLY a command that is JUST `kill [flags] <unrelated pid>` —
138
- // anchored end-to-end so `kill 1234 && systemctl restart dsh-web` cannot
139
- // whitelist the compound through its prefix.
140
- if (/^kill\s+(?:-\S+\s+)?\d+\s*$/i.test(seg.trim()))
141
- continue;
142
- if (/kill\s+(?:-\S+\s+)?(\d+)\s+.*(not found|done)/i.test(seg))
165
+ const segs = segmentsOf(cmd);
166
+ if (segs === undefined) {
167
+ // Input the parser refused cannot be proven safe, so it keeps the
168
+ // conservative reading: a kill-family word next to the host's name.
169
+ return KILL_FAMILY_RAW.test(stripped) && DSH_TARGET.test(stripped);
170
+ }
171
+ for (const seg of segs) {
172
+ const verb = commandVerb(seg.verb);
173
+ const argv = seg.argv.slice(1);
174
+ if (!argv.some((token) => DSH_TARGET.test(token)))
143
175
  continue;
144
- if (DANGEROUS_KILL_VERB.test(seg))
176
+ if (verb !== undefined && KILL_FAMILY.has(verb))
177
+ return true;
178
+ if (verb === 'systemctl' && argv.some((token) => SYSTEMCTL_ACTIONS.has(token.toLowerCase())))
145
179
  return true;
146
180
  }
147
181
  return false;
148
182
  }
183
+ /** The segment's verb without its directory (`/bin/kill` → `kill`). */
184
+ function commandVerb(verb) {
185
+ if (verb === undefined)
186
+ return undefined;
187
+ const cut = verb.lastIndexOf('/');
188
+ return cut === -1 ? verb : verb.slice(cut + 1);
189
+ }
190
+ /**
191
+ * The command's segments with shell wrappers unwrapped, so a kill hidden behind
192
+ * `bash -c` is judged as the kill it runs. `undefined` when the parser throws,
193
+ * which the caller answers conservatively rather than with an allow.
194
+ */
195
+ function segmentsOf(cmd) {
196
+ try {
197
+ return unwrapSegments(parseCommand(cmd));
198
+ }
199
+ catch {
200
+ return undefined;
201
+ }
202
+ }
149
203
  /**
150
204
  * Live pids of the dsh web OWN forest: pids owning the dsh-web ports
151
205
  * (3000/3080) plus their ancestor chain up to the pnpm/systemd boundary and
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * The Maestro M logo — canonical reference implementation.
3
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
4
+ * This file started as a copy of a settings dashboard that this plugin set no
5
+ * longer installs. It is now the source of record: `AGENTS.md:394` points
6
+ * here, and
7
7
  * the settings-nav mask in `index.tsx` plus the Settings card badge in
8
8
  * `MaestroSettings.tsx` both build from the constants declared below.
9
9
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAI3D,oEAAoE;AACpE,eAAO,MAAM,MAAM,kCAAmC,CAAA;AAEtD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;AAQtD,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAQ1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAG3D,oEAAoE;AACpE,eAAO,MAAM,MAAM,kCAAmC,CAAA;AAEtD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAA;AAOtD,wBAAgB,KAAK,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAQ1C"}
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Maestro core",
4
+ "description": "The Maestro settings store, the Maestro settings card and the tool guard, plus recovery: a session interrupted by a dsh web restart is resumed automatically, and the page reloads itself when the server comes back. The restart daemon runs outside this plugin as a systemd service, so crash restarts keep working with the plugin off. Driven from Settings, Maestro."
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@ddtcorex/dsh-maestro-core",
3
- "version": "0.15.1",
4
- "description": "DSH Web supervisor, settings store, tool guard and sync engine",
3
+ "version": "0.16.0",
4
+ "description": "Maestro supervisor, settings store and tool guard for the DeepSeek Harness Web",
5
+ "icon": "assets/icon.svg",
5
6
  "license": "MIT",
6
7
  "repository": {
7
8
  "type": "git",
@@ -28,6 +29,7 @@
28
29
  },
29
30
  "./lib/*": "./lib/*",
30
31
  "./cordis.patch.yml": "./cordis.patch.yml",
32
+ "./locale/*.json": "./locale/*.json",
31
33
  "./package.json": "./package.json"
32
34
  },
33
35
  "bin": {
@@ -55,10 +57,12 @@
55
57
  "!scripts/sync/cdp-sync-verify.mjs",
56
58
  "systemd",
57
59
  "README.md",
58
- "cordis.patch.yml"
60
+ "cordis.patch.yml",
61
+ "assets",
62
+ "locale"
59
63
  ],
60
64
  "peerDependencies": {
61
- "@deepseek-ai/cordis": "~4.0.4",
65
+ "@deepseek-ai/cordis": "~4.1.0 || ~4.2.0-alpha.1",
62
66
  "@deepseek-ai/dsh-client-connection": "^0.1.0-rc.6 || >=0.1.1-rc.0 <0.3.0-0",
63
67
  "@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.6 || >=0.1.1-rc.0 <0.3.0-0"
64
68
  },
@@ -66,7 +70,7 @@
66
70
  "fzstd": "0.1.1"
67
71
  },
68
72
  "devDependencies": {
69
- "@deepseek-ai/cordis": "~4.0.4",
73
+ "@deepseek-ai/cordis": "~4.2.0-alpha.1",
70
74
  "@deepseek-ai/dsh-client-connection": "0.2.0-rc.2",
71
75
  "@deepseek-ai/dsh-client-ui-slots": "0.2.0-rc.2",
72
76
  "@deepseek-ai/dsh-llm": "0.2.0-rc.2",
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * The Maestro M logo — canonical reference implementation.
3
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
4
+ * This file started as a copy of a settings dashboard that this plugin set no
5
+ * longer installs. It is now the source of record: `AGENTS.md:394` points
6
+ * here, and
7
7
  * the settings-nav mask in `index.tsx` plus the Settings card badge in
8
8
  * `MaestroSettings.tsx` both build from the constants declared below.
9
9
  *
@@ -9,7 +9,6 @@
9
9
  */
10
10
  import { apply as applyAutoReload } from './auto-reload.js'
11
11
  import { apply as applyConfig } from './config/index.js'
12
- import { apply as applySync } from './sync/index.js'
13
12
 
14
13
  /** Union of what the three modules need from the client context. */
15
14
  export const inject = ['slots', 'connection'] as const
@@ -19,7 +18,6 @@ type ClientCtx = Parameters<typeof applyAutoReload>[0]
19
18
  const MODULES = [
20
19
  ['auto-reload', applyAutoReload],
21
20
  ['config', applyConfig],
22
- ['sync', applySync],
23
21
  ] as const
24
22
 
25
23
  export function apply(ctx: ClientCtx): void {
@@ -48,7 +48,7 @@ export interface PollHealthOpts {
48
48
 
49
49
  // Specific parse/boot-failure markers only. Bare 'JSON'/'YAML' were removed
50
50
  // (2026-08-31): they matched any line whose payload merely *contained* those
51
- // substrings — e.g. maestro-sync's status JSON listing session.jsonl.zstd /
51
+ // substrings — e.g. a sync status JSON listing session.jsonl.zstd /
52
52
  // settings.json paths — turning a healthy 401 into a restart.
53
53
  const ERROR_PATTERNS = [
54
54
  'ERR_MODULE_NOT_FOUND',
@@ -3,9 +3,17 @@
3
3
  * kill or restart the very dsh web process the agent is running inside. The
4
4
  * model must route restarts through the supervisor's dsh_web_restart tool, not
5
5
  * by killing the host.
6
+ *
7
+ * The predicate is scoped to the HOST, not to the verb family: what makes a
8
+ * command a self-kill is its TARGET (a live host pid, or the `dsh` name in a
9
+ * kill/restart shape), never the mere presence of `kill`/`pkill`/`killall`.
10
+ * A blanket verb deny read as "no process may ever be killed through the agent"
11
+ * and blocked ordinary work (`pkill -f chrome`, `systemctl status nginx`,
12
+ * `kill 1234 2>/dev/null`), which is not the protection this file exists for.
6
13
  */
7
14
 
8
15
  import { createRequire } from 'node:module'
16
+ import { parseCommand, unwrapSegments, type Segment } from './guard/parse.js'
9
17
 
10
18
  const require = createRequire(import.meta.url)
11
19
 
@@ -17,11 +25,24 @@ const require = createRequire(import.meta.url)
17
25
  // not argv.
18
26
  const SELF_KILL_RE = /(systemctl\s+--?user\s+.*(restart|stop|start).*dsh-web|pkill\s+.*dsh|killall\s+.*dsh|ss\s+.*3080.*kill|restart-dsh-web)/i
19
27
 
20
- // A segment whose command position is one of these verbs is a real kill-family
21
- // invocation: blanket-denied even when its target lives inside quotes
22
- // (`pkill -f "dsh web"` must still be caught). `sudo`/`env VAR=` prefixes are
23
- // stripped before the verb is read.
24
- const DANGEROUS_KILL_VERB = /^(?:sudo\s+|env\s+\S+\s+)*(pkill|killall|kill|systemctl)\b/i
28
+ /** Verbs whose whole job is ending a process (their target is what matters). */
29
+ const KILL_FAMILY = new Set(['kill', 'pkill', 'killall'])
30
+
31
+ /**
32
+ * The `systemctl` actions that can stop the host or something it depends on. A
33
+ * read-only `systemctl status` is deliberately absent: it is how an operator
34
+ * inspects the host, and refusing it protects nothing.
35
+ */
36
+ const SYSTEMCTL_ACTIONS = new Set([
37
+ 'restart', 'stop', 'start', 'kill', 'try-restart', 'reload-or-restart',
38
+ 'force-reload', 'isolate', 'reboot', 'halt', 'poweroff', 'suspend',
39
+ ])
40
+
41
+ /** The host's own name, in any spelling the process or unit carries it in. */
42
+ const DSH_TARGET = /dsh/i
43
+
44
+ /** Fallback reading for input the parser refuses: a kill-family word plus the host's name. */
45
+ const KILL_FAMILY_RAW = /\b(?:kill|pkill|killall)\b/i
25
46
 
26
47
  /**
27
48
  * Remove data spans (quoted strings and heredoc bodies) from a command before
@@ -122,36 +143,73 @@ export function resolveDshWebTreePids(
122
143
  }
123
144
 
124
145
  /**
125
- * Whether a shell command is a self-kill. `livePids` are the pids of the dsh
126
- * web process forest; a `kill <pid>` whose pid is one of ours is a self-kill
127
- * regardless of anything else in the command. The kill parser accepts flag
128
- * forms (`kill -9 <pid>`, `kill -TERM <pid>`). A command that is essentially
129
- * JUST a `kill <unrelated-pid>` is allowed (idempotent cleanups are common),
130
- * as are kill attempts whose output reports "not found"/"done" — but any
131
- * compound that chains a restart/kill after it (or before the end) stays
132
- * denied.
146
+ * Whether a shell command is a self-kill. Two questions decide it, and both are
147
+ * about the TARGET, never about the verb:
148
+ *
149
+ * 1. does the command name a pid of the dsh web process forest? A command that
150
+ * signals a live host pid is a self-kill in whatever shape it arrives
151
+ * (`kill -9 300`, `kill -9 300 2>/dev/null`, `nice kill 300`, `pkill -9 300`),
152
+ * because the target is exact;
153
+ * 2. does a kill-family or restart shape name the host? `kill`/`pkill`/`killall`
154
+ * carrying `dsh` in any argument (`pkill -f "dsh web"`, `bash -c "pkill -f
155
+ * dsh"`), a `systemctl` ACTION on a dsh unit, the `restart-dsh-web` helper,
156
+ * and killing whatever owns :3080.
157
+ *
158
+ * Everything else is allowed, including a kill of an unrelated pid, `killall
159
+ * node`, `pkill -f chrome` and `systemctl restart mysql`. Wide patterns such as
160
+ * `pkill -f node` can still take the host down, so the guard only promises that
161
+ * it will not DENY ordinary kill-family work: the host's own recovery (supervisor
162
+ * daemon + auto-resume) is what covers an agent that aims badly, exactly as
163
+ * before this file existed.
133
164
  */
134
165
  export function isSelfKillCommand(cmd: string, livePids: number[]): boolean {
135
- // pid-targeted kill: an exact live pid is a self-kill regardless of context
136
- if (/kill\s+(?:-\S+\s+)?(\d+)/i.test(cmd)) {
137
- const pid = Number(cmd.match(/kill\s+(?:-\S+\s+)?(\d+)/i)?.[1])
138
- if (livePids.includes(pid)) return true
166
+ const live = new Set(livePids)
167
+ // An exact host pid anywhere in a kill invocation is a self-kill, including
168
+ // through wrappers whose verb the parser cannot see (`nice -n 10 kill 300`).
169
+ for (const match of cmd.matchAll(/\bkill\s+(?:-\S+\s+)*(\d+)/gi)) {
170
+ if (live.has(Number(match[1]))) return true
139
171
  }
140
- // Targeted patterns may span segments (`ss ... | grep 3080 | xargs kill`),
141
- // so test the stripped full text once, then verbs per segment.
172
+ // Shapes whose target the argv does not carry: killing whatever owns :3080,
173
+ // and the guarded restart helper itself.
142
174
  const stripped = stripDataSpans(cmd)
143
175
  if (SELF_KILL_RE.test(stripped)) return true
144
- for (const seg of stripped.split(/\s*(?:&&|\|\||;|\||\r?\n)+\s*/)) {
145
- // Exclude ONLY a command that is JUST `kill [flags] <unrelated pid>` —
146
- // anchored end-to-end so `kill 1234 && systemctl restart dsh-web` cannot
147
- // whitelist the compound through its prefix.
148
- if (/^kill\s+(?:-\S+\s+)?\d+\s*$/i.test(seg.trim())) continue
149
- if (/kill\s+(?:-\S+\s+)?(\d+)\s+.*(not found|done)/i.test(seg)) continue
150
- if (DANGEROUS_KILL_VERB.test(seg)) return true
176
+
177
+ const segs = segmentsOf(cmd)
178
+ if (segs === undefined) {
179
+ // Input the parser refused cannot be proven safe, so it keeps the
180
+ // conservative reading: a kill-family word next to the host's name.
181
+ return KILL_FAMILY_RAW.test(stripped) && DSH_TARGET.test(stripped)
182
+ }
183
+ for (const seg of segs) {
184
+ const verb = commandVerb(seg.verb)
185
+ const argv = seg.argv.slice(1)
186
+ if (!argv.some((token) => DSH_TARGET.test(token))) continue
187
+ if (verb !== undefined && KILL_FAMILY.has(verb)) return true
188
+ if (verb === 'systemctl' && argv.some((token) => SYSTEMCTL_ACTIONS.has(token.toLowerCase()))) return true
151
189
  }
152
190
  return false
153
191
  }
154
192
 
193
+ /** The segment's verb without its directory (`/bin/kill` → `kill`). */
194
+ function commandVerb(verb: string | undefined): string | undefined {
195
+ if (verb === undefined) return undefined
196
+ const cut = verb.lastIndexOf('/')
197
+ return cut === -1 ? verb : verb.slice(cut + 1)
198
+ }
199
+
200
+ /**
201
+ * The command's segments with shell wrappers unwrapped, so a kill hidden behind
202
+ * `bash -c` is judged as the kill it runs. `undefined` when the parser throws,
203
+ * which the caller answers conservatively rather than with an allow.
204
+ */
205
+ function segmentsOf(cmd: string): Segment[] | undefined {
206
+ try {
207
+ return unwrapSegments(parseCommand(cmd))
208
+ } catch {
209
+ return undefined
210
+ }
211
+ }
212
+
155
213
  /**
156
214
  * Live pids of the dsh web OWN forest: pids owning the dsh-web ports
157
215
  * (3000/3080) plus their ancestor chain up to the pnpm/systemd boundary and
@@ -1,55 +0,0 @@
1
- export interface BackupProviderConfig {
2
- provider: 'r2' | 'aws';
3
- endpoint: string;
4
- region: string;
5
- bucket: string;
6
- prefix: string;
7
- }
8
- export interface BackupSecrets {
9
- accessKeyId: string;
10
- secretAccessKey: string;
11
- }
12
- export interface BackupTarget {
13
- provider: 'r2' | 'aws';
14
- bucket: string;
15
- prefix: string;
16
- hostId: string;
17
- }
18
- export type SecretSource = 'env' | 'file' | 'none';
19
- export declare const BACKUP_SIDECAR_REL = "dsh-maestro-sync/backup-secrets.json";
20
- export declare function describeSecretSource(env: Record<string, string | undefined>, sidecarPath: string): SecretSource;
21
- export declare function resolveBackupTarget(doc?: {
22
- domains?: {
23
- sync?: {
24
- r2?: Record<string, unknown>;
25
- };
26
- };
27
- }, env?: Record<string, string | undefined>, dshHome?: string): Promise<{
28
- config: BackupProviderConfig;
29
- secrets: BackupSecrets;
30
- source: SecretSource;
31
- }>;
32
- export interface R2ConfigInput {
33
- provider?: unknown;
34
- accountId?: unknown;
35
- endpoint?: unknown;
36
- region?: unknown;
37
- bucket?: unknown;
38
- prefix?: unknown;
39
- }
40
- export interface NormalizedR2Config {
41
- provider: 'r2' | 'aws';
42
- accountId: string;
43
- endpoint: string;
44
- region: string;
45
- bucket: string;
46
- prefix: string;
47
- }
48
- /**
49
- * Validate + normalize non-secret R2/S3 config from the Settings UI.
50
- * Fail-closed: throws on the first invalid field. Empty strings mean
51
- * "use the default" and are stripped so built-in fallbacks keep working.
52
- * Secret material is never accepted here — keys live in env or the 0600
53
- * sidecar only.
54
- */
55
- export declare function validateR2ConfigInput(input: R2ConfigInput): NormalizedR2Config;
@@ -1,119 +0,0 @@
1
- // src/host/backup-config.ts — backup target config + secret resolution.
2
- //
3
- // Non-secret config comes from the shared settings store (domains.sync.r2.*);
4
- // secret material never lives in settings, never is logged, and never crosses
5
- // RPC/tools — resolution order: environment first, then a private 0600 sidecar
6
- // in the plugin's own runtime directory (outside the eligible data boundary,
7
- // so the merge CLI never reads or syncs it). Status surfaces only the source
8
- // label, the bucket, the prefix and the provider.
9
- import { createHash } from 'node:crypto';
10
- import * as os from 'node:os';
11
- import * as nodeFs from 'node:fs';
12
- import * as nodePath from 'node:path';
13
- export const BACKUP_SIDECAR_REL = 'dsh-maestro-sync/backup-secrets.json';
14
- export function describeSecretSource(env, sidecarPath) {
15
- if ((env.R2_ACCESS_KEY_ID && env.R2_SECRET_ACCESS_KEY) || (env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY))
16
- return 'env';
17
- try {
18
- if (nodeFs.existsSync(sidecarPath))
19
- return 'file';
20
- }
21
- catch { }
22
- return 'none';
23
- }
24
- export async function resolveBackupTarget(doc = {}, env = process.env, dshHome = process.env.DSH_HOME || nodePath.join(os.homedir(), '.dsh')) {
25
- const sync = doc.domains?.sync;
26
- const r2 = (sync?.r2 ?? {});
27
- const provider = r2.provider === 'aws' ? 'aws' : 'r2';
28
- const accountId = r2.accountId ?? '';
29
- const bucket = r2.bucket ?? 'maestro-backup';
30
- const hostId = createHash('sha256').update(os.hostname()).digest('hex').slice(0, 12);
31
- const prefix = r2.prefix ?? `v1/hosts/${hostId}/`;
32
- const region = r2.region ?? (provider === 'r2' ? 'auto' : '');
33
- const endpoint = r2.endpoint ?? (provider === 'r2' ? `https://${accountId}.r2.cloudflarestorage.com` : '');
34
- const sidecar = nodePath.join(dshHome, BACKUP_SIDECAR_REL);
35
- let secrets = null;
36
- let source = 'none';
37
- if (env.R2_ACCESS_KEY_ID && env.R2_SECRET_ACCESS_KEY) {
38
- secrets = { accessKeyId: env.R2_ACCESS_KEY_ID, secretAccessKey: env.R2_SECRET_ACCESS_KEY };
39
- source = 'env';
40
- }
41
- else if (env.AWS_ACCESS_KEY_ID && env.AWS_SECRET_ACCESS_KEY) {
42
- secrets = { accessKeyId: env.AWS_ACCESS_KEY_ID, secretAccessKey: env.AWS_SECRET_ACCESS_KEY };
43
- source = 'env';
44
- }
45
- else {
46
- try {
47
- const raw = nodeFs.readFileSync(sidecar, 'utf-8');
48
- const parsed = JSON.parse(raw);
49
- if (parsed.accessKeyId && parsed.secretAccessKey) {
50
- secrets = { accessKeyId: parsed.accessKeyId, secretAccessKey: parsed.secretAccessKey };
51
- source = 'file';
52
- }
53
- }
54
- catch { }
55
- }
56
- if (!secrets) {
57
- throw Object.assign(new Error('backup requires access key secret material: set R2_ACCESS_KEY_ID + R2_SECRET_ACCESS_KEY '
58
- + '(or AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY) in the environment, '
59
- + `or write a 0600 ${sidecar}`), {
60
- phase: 'validate',
61
- code: 'MISSING_BACKUP_SECRETS',
62
- });
63
- }
64
- return { config: { provider, endpoint, region, bucket, prefix }, secrets, source };
65
- }
66
- const SHELL_META_RE = /[;`$|&><*?'"\\(){}!\s=]/;
67
- const BUCKET_RE = /^[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/;
68
- const REGION_RE = /^[A-Za-z0-9-]{1,32}$/;
69
- const ACCOUNT_RE = /^[0-9a-f]{32}$/i;
70
- const PREFIX_SEG_RE = /^[A-Za-z0-9._-]{1,64}$/;
71
- /**
72
- * Validate + normalize non-secret R2/S3 config from the Settings UI.
73
- * Fail-closed: throws on the first invalid field. Empty strings mean
74
- * "use the default" and are stripped so built-in fallbacks keep working.
75
- * Secret material is never accepted here — keys live in env or the 0600
76
- * sidecar only.
77
- */
78
- export function validateR2ConfigInput(input) {
79
- const str = (v) => (typeof v === 'string' ? v.trim() : '');
80
- const provider = str(input.provider) || 'r2';
81
- if (provider !== 'r2' && provider !== 'aws')
82
- throw new Error(`invalid provider: ${JSON.stringify(provider)} (want 'r2'|'aws')`);
83
- const accountId = str(input.accountId);
84
- if (accountId && !ACCOUNT_RE.test(accountId))
85
- throw new Error('invalid accountId: want 32 hex chars');
86
- if (provider === 'aws' && accountId)
87
- throw new Error('invalid accountId: only meaningful for provider r2');
88
- const endpoint = str(input.endpoint);
89
- if (endpoint) {
90
- if (SHELL_META_RE.test(endpoint) || endpoint.length > 256)
91
- throw new Error('invalid endpoint: illegal characters');
92
- if (!/^https:\/\/[A-Za-z0-9.-]+(?::\d+)?(?:\/[A-Za-z0-9._~:/?#[\]@!$&'()*+,;=-]*)?$/.test(endpoint)) {
93
- throw new Error('invalid endpoint: want an https:// URL');
94
- }
95
- }
96
- const region = str(input.region);
97
- if (region && !REGION_RE.test(region))
98
- throw new Error(`invalid region: ${JSON.stringify(region)}`);
99
- const bucket = str(input.bucket);
100
- if (!bucket)
101
- throw new Error('bucket is required');
102
- if (!BUCKET_RE.test(bucket))
103
- throw new Error(`invalid bucket: ${JSON.stringify(bucket)} (3-63 lowercase letters/digits/dots/hyphens)`);
104
- let prefix = str(input.prefix);
105
- if (!prefix)
106
- throw new Error('prefix is required');
107
- if (prefix.startsWith('/') || prefix.includes('\\') || prefix.includes('..') || /[\u0000-\u001f\u007f]/.test(prefix)) {
108
- throw new Error(`invalid prefix: ${JSON.stringify(prefix)}`);
109
- }
110
- if (!prefix.endsWith('/'))
111
- prefix += '/';
112
- const segs = prefix.split('/').filter((s) => s.length > 0);
113
- if (segs.length === 0 || segs.length > 8 || !segs.every((s) => PREFIX_SEG_RE.test(s))) {
114
- throw new Error(`invalid prefix: ${JSON.stringify(prefix)}`);
115
- }
116
- if (prefix.length > 200)
117
- throw new Error('invalid prefix: too long');
118
- return { provider, accountId, endpoint, region, bucket, prefix };
119
- }