@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
package/lib/paths.js ADDED
@@ -0,0 +1,70 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ /**
4
+ * Resolve Maestro Harness root without hardcoding a machine-specific home path.
5
+ * Priority: env > walk up from current file > cwd check > homedir fallback (last resort).
6
+ */
7
+ export function resolveHarnessRoot() {
8
+ if (process.env.MAESTRO_HARNESS_ROOT)
9
+ return process.env.MAESTRO_HARNESS_ROOT;
10
+ // Walk up from this file's directory (works for both src and lib)
11
+ try {
12
+ // In ESM, __dirname is not available; use import.meta.url if possible, else process.cwd()
13
+ // Fallback to file path heuristic: supervisor is at packages/dsh-maestro-core/{src,lib}
14
+ const candidates = [];
15
+ // Try to derive from current working file via stack-relative: use process.argv[1] or cwd
16
+ // Most reliable: check common locations relative to this file
17
+ // For compiled lib: lib/paths.js -> ../../.. = maestro-harness
18
+ // For src: src/host/paths.ts -> ../../.. = maestro-harness
19
+ const here = path.dirname(new URL(import.meta.url).pathname);
20
+ candidates.push(path.resolve(here, '../../..')); // lib -> maestro-harness
21
+ candidates.push(path.resolve(here, '../../../..')); // src/host -> maestro-harness
22
+ candidates.push(path.resolve(here, '../../../../..'));
23
+ candidates.push(process.cwd());
24
+ for (const c of candidates) {
25
+ try {
26
+ if (fs.existsSync(path.join(c, 'deepseek-harness', 'package.json')) && fs.existsSync(path.join(c, 'packages', 'dsh-maestro-core', 'package.json'))) {
27
+ return c;
28
+ }
29
+ }
30
+ catch { }
31
+ }
32
+ // Fallback to first candidate that exists
33
+ for (const c of candidates) {
34
+ if (fs.existsSync(c))
35
+ return c;
36
+ }
37
+ }
38
+ catch { }
39
+ // Last resort: cwd
40
+ return process.cwd();
41
+ }
42
+ export function resolveDeepseekHarnessDir() {
43
+ return path.join(resolveHarnessRoot(), 'deepseek-harness');
44
+ }
45
+ /**
46
+ * Resolve this package's own directory (the one holding its package.json),
47
+ * walking up from this file. Works from `src/host/` and from the built `lib/`,
48
+ * and from an npm install under `node_modules/@ddtcorex/dsh-maestro-core`
49
+ * — so no call site has to assume a workspace layout.
50
+ */
51
+ export function resolveSupervisorPackageDir() {
52
+ const here = path.dirname(new URL(import.meta.url).pathname);
53
+ let dir = here;
54
+ for (let i = 0; i < 6; i++) {
55
+ try {
56
+ const pkg = path.join(dir, 'package.json');
57
+ if (fs.existsSync(pkg) && JSON.parse(fs.readFileSync(pkg, 'utf8')).name === '@ddtcorex/dsh-maestro-core') {
58
+ return dir;
59
+ }
60
+ }
61
+ catch { }
62
+ const up = path.dirname(dir);
63
+ if (up === dir)
64
+ break;
65
+ dir = up;
66
+ }
67
+ // Fallback: one level above the dir this module was loaded from — `lib/` in
68
+ // production, `src/host/` from vitest. Only used when the walk above fails.
69
+ return path.resolve(here, '..');
70
+ }
@@ -0,0 +1,250 @@
1
+ /**
2
+ * dsh-maestro-core — host plugin for auto-resume inside DSH web.
3
+ * Runs inside the DSH host process (outside the daemon's tree) and
4
+ * auto-resumes sessions interrupted within the configured window after
5
+ * a restart. The standalone daemon (systemd) handles crash detection
6
+ * and web restart; this plugin handles the in-process resume.
7
+ */
8
+ import { findInterrupted as defaultFindInterrupted, findDanglingOpenTurns as defaultFindDanglingOpenTurns } from './resume.js';
9
+ import type { RestartIntent } from './intents.js';
10
+ import { type ResumeLogEntry } from './resume-log.js';
11
+ import { runSessionHealthCheck } from './session-health.js';
12
+ export * from './resume-tools.js';
13
+ import { type ToolViewProbeFn, type ToolScopeResolver } from './tool-view.js';
14
+ export * from './tool-view.js';
15
+ import { type RepairOutcome } from './preset.js';
16
+ export * from './preset.js';
17
+ export declare const inject: readonly ["sessions", "agents", "connection", "tools", "skills"];
18
+ export interface SupervisorPluginConfig {
19
+ autoResumeWithin?: number | string;
20
+ autoResumeEnabled?: boolean;
21
+ sessionLogRoot?: string;
22
+ resumeCoreToolPolicy?: ResumeCoreToolPolicy;
23
+ /** Re-link a resumed agent that lost its preset (default true; kill switch for the live mutation). */
24
+ resumeAutoRepair?: boolean;
25
+ }
26
+ /**
27
+ * C2 — mitigation policy when a resumed session's post-resume probe (C1)
28
+ * reports a core tool (bash) missing from its SCOPED tool view:
29
+ * - 'warn': notify the operator once + inject a "System:" inventory message
30
+ * into the session telling the model which tools it CAN still call
31
+ * (default — the loss is real, but the session may still be usable).
32
+ * - 'park': additionally record the session id in the park set (exposed via
33
+ * maestro_resume_tool_health / /dsh-maestro-supervisor-resume-tool-health)
34
+ * and flag the notify with "(manual reopen required)" — the operator must
35
+ * reopen the session fresh because the core-tool surface is not guaranteed.
36
+ */
37
+ export type ResumeCoreToolPolicy = 'warn' | 'park';
38
+ /**
39
+ * Whether `autoResumeEnabled` is pinned by an install-supplied Cordis `config:` value.
40
+ * Used by `dsh-maestro-config`'s UI to render a locked/disabled state instead of
41
+ * an interactive toggle that has no effect.
42
+ */
43
+ export declare function isAutoResumePinned(config?: SupervisorPluginConfig): boolean;
44
+ export declare function getAutoResumeEnabledExported(config?: SupervisorPluginConfig): boolean;
45
+ export declare function runAutoResume(ctx: any, opts?: {
46
+ findInterrupted?: typeof defaultFindInterrupted;
47
+ findDanglingOpenTurns?: typeof defaultFindDanglingOpenTurns;
48
+ resumeInterrupted?: typeof resumeInterrupted;
49
+ logResume?: (entry: ResumeLogEntry) => void;
50
+ config?: SupervisorPluginConfig;
51
+ }): Promise<void>;
52
+ export interface RecoveredRoute {
53
+ provider: string;
54
+ model: string;
55
+ }
56
+ /**
57
+ * Recover the provider/model route a resumed agent needs for its
58
+ * `{{model}}` persona variable: handle seam first, raw session log as
59
+ * fallback. Returns `undefined` only for genuinely corrupt/routeless
60
+ * sessions, which the caller skips instead of resuming.
61
+ */
62
+ export declare function recoverAgentOptions(input: {
63
+ persistence: any;
64
+ sid: unknown;
65
+ sessionsRoot: string;
66
+ group: string;
67
+ sessionId: string;
68
+ logger?: {
69
+ warn?: (msg: string) => void;
70
+ };
71
+ id: string;
72
+ }): Promise<RecoveredRoute | undefined>;
73
+ /**
74
+ * Recovery prompt for a turn the crash interrupted. A bare "continue" made the
75
+ * model answer with text instead of re-issuing its tool call (36646045…,
76
+ * 31ae53a2…), so the prompt names the synthesized TOOL_OUTCOME_UNKNOWN result
77
+ * (repair.ts:104) and asks for verification before any retry.
78
+ */
79
+ export declare const RECOVERY_PROMPT_IDLE: string;
80
+ /**
81
+ * Admit a recovery prompt into a session this host already has open. The
82
+ * reconnecting browser holds that session's write handle, so `agents.resume`
83
+ * cannot take ownership (`SessionAlreadyOwnedError`); `sessionController.prompt`
84
+ * is the Host API the UI itself uses, and it resolves the session's agent
85
+ * first. Returns false when the service is absent, the prompt was refused, or
86
+ * delivery failed — the caller then reports the original ownership failure.
87
+ *
88
+ * @param ctx - plugin context providing the optional `sessionController`.
89
+ * @param sessionId - session to continue.
90
+ * @param text - recovery prompt text.
91
+ */
92
+ export declare function promptOwnedSession(ctx: any, sessionId: string, text: string): Promise<boolean>;
93
+ /** Backoff for a resume blocked by a write handle another owner still holds. */
94
+ export declare const DEFAULT_OWNERSHIP_RETRY_DELAYS_MS: number[];
95
+ /** True when the persistence backend refused a second write open. */
96
+ export declare function isSessionAlreadyOwned(error: any): boolean;
97
+ /**
98
+ * `agents.resume` while the target session's write handle may still be held by
99
+ * the just-restarted host: the reconnecting browser re-opens the interrupted
100
+ * session and keeps that handle while it loads and repairs it, so the boot
101
+ * scan's resume loses the race with
102
+ * `session "<id>" is already owned by an active write handle`. That is
103
+ * transient — on 2026-09-13 the same session accepted an agent seconds later —
104
+ * so retry a bounded number of times instead of abandoning the session.
105
+ *
106
+ * A failure that is not an ownership conflict is rethrown immediately: it
107
+ * cannot be fixed by waiting.
108
+ *
109
+ * @param agents - the agents service (`resume`).
110
+ * @param options - the resume request handed to `agents.resume`.
111
+ * @param hooks.delaysMs - backoff before each retry; length = retry count.
112
+ * @param hooks.onRetry - called before each wait, for the audit trail.
113
+ * @param hooks.sleep - injectable wait, for tests.
114
+ * @returns the agent handle from the first successful resume.
115
+ */
116
+ export declare function resumeAgentWithOwnershipRetry(agents: any, options: {
117
+ resumeSessionId: any;
118
+ agentOptions: any;
119
+ }, hooks?: {
120
+ delaysMs?: number[];
121
+ onRetry?: (attempt: number, delayMs: number, error: any) => void;
122
+ sleep?: (ms: number) => Promise<void>;
123
+ }): Promise<any>;
124
+ /**
125
+ * A `setup` failure: the agent could not be joined to the preset the session
126
+ * records. Distinguished from a resume/ownership failure because this one must
127
+ * never degrade into a preset-less resume.
128
+ */
129
+ export declare class PresetComposeError extends Error {
130
+ readonly presetId: string;
131
+ readonly cause: unknown;
132
+ /**
133
+ * @param presetId - the preset that could not be composed.
134
+ * @param cause - the roster's own failure, kept for the message.
135
+ */
136
+ constructor(presetId: string, cause: unknown);
137
+ }
138
+ /**
139
+ * Activate one session's agent through the single owner of agent activation.
140
+ *
141
+ * `sessionController.resolveAgent` is the entry point the Web API domain uses:
142
+ * it composes the session's preset, de-duplicates concurrent resumes for one
143
+ * session, and returns the live agent when the browser already re-opened it.
144
+ * Anything else — the service is absent, it throws, or it answers without an
145
+ * agent — falls back to `agents.resume` with the preset-composing `setup`,
146
+ * which still owns the write-handle retry and the owned-session prompt path.
147
+ *
148
+ * @param ctx - plugin context providing the optional `sessionController`.
149
+ * @param sessionId - the session to activate.
150
+ * @param deps.resolveSessionAgent - injectable controller call, for tests.
151
+ * @returns the resolved agent when the controller produced one, else `via: 'resume'`.
152
+ */
153
+ export declare function activateSessionAgent(ctx: any, sessionId: string, deps?: {
154
+ resolveSessionAgent?: (ctx: any, sessionId: string) => Promise<{
155
+ agent?: any;
156
+ error?: any;
157
+ } | undefined>;
158
+ }): Promise<{
159
+ agent?: any;
160
+ via: 'controller' | 'resume';
161
+ }>;
162
+ export declare function resumeInterrupted(ctx: any, ids: string[], deps?: {
163
+ readIntent?: (id: string) => RestartIntent | undefined;
164
+ consumeIntent?: (id: string) => void;
165
+ probeToolView?: ToolViewProbeFn;
166
+ resolveToolScope?: ToolScopeResolver;
167
+ notify?: (line: string) => Promise<void>;
168
+ injectSessionMessage?: (sessionId: string, content: string) => unknown;
169
+ logResume?: (entry: ResumeLogEntry) => void;
170
+ resumeOwnershipRetryDelaysMs?: number[];
171
+ resolveSessionAgent?: (ctx: any, sessionId: string) => Promise<{
172
+ agent?: any;
173
+ error?: any;
174
+ } | undefined>;
175
+ readPresetId?: (sessionId: string) => Promise<string | undefined>;
176
+ makeSetup?: (ctx: any, presetId: string) => ((agentCtx: unknown, agent?: unknown) => Promise<void>) | undefined;
177
+ repairPreset?: (ctx: any, sessionId: string, deps: {
178
+ readPresetId?: (id: string) => Promise<string | undefined>;
179
+ }) => Promise<RepairOutcome>;
180
+ config?: SupervisorPluginConfig;
181
+ }): Promise<string[]>;
182
+ export declare function createResumeRpcHandler(ctx: any, opts?: {
183
+ resumeInterrupted?: typeof resumeInterrupted;
184
+ config?: SupervisorPluginConfig;
185
+ notify?: (line: string) => Promise<void>;
186
+ injectSessionMessage?: (sessionId: string, content: string) => unknown;
187
+ }): (endpoint: string, payload: unknown, _signal: AbortSignal) => Promise<{
188
+ ok: boolean;
189
+ value: import("./resume.js").ResumeResult;
190
+ error?: undefined;
191
+ } | {
192
+ ok: boolean;
193
+ value: {
194
+ autoResumeEnabled: boolean;
195
+ autoResumePinned: boolean;
196
+ autoResumeWithinMs: number;
197
+ resumed?: undefined;
198
+ };
199
+ error?: undefined;
200
+ } | {
201
+ ok: boolean;
202
+ error: {
203
+ code: string;
204
+ message: string;
205
+ };
206
+ value?: undefined;
207
+ } | {
208
+ ok: boolean;
209
+ value: {
210
+ resumed: string[];
211
+ autoResumeEnabled?: undefined;
212
+ autoResumePinned?: undefined;
213
+ autoResumeWithinMs?: undefined;
214
+ };
215
+ error?: undefined;
216
+ }>;
217
+ /**
218
+ * Loopback RPC handler for /dsh-maestro-supervisor-session-health. Runs the
219
+ * A1 session-log health check over the resolved root with repair on and
220
+ * quarantine off (mirrors the safe-restart pre-flight — single-frame logs get
221
+ * re-encoded, corrupt logs stay in place and are only counted). Same
222
+ * `{ ok, value | error }` envelope shape as the resume handler.
223
+ */
224
+ export declare function createSessionHealthRpcHandler(ctx: any, deps?: {
225
+ run?: typeof runSessionHealthCheck;
226
+ config?: SupervisorPluginConfig;
227
+ }): (_endpoint: string, payload: unknown, _signal: AbortSignal) => Promise<{
228
+ ok: boolean;
229
+ value: {
230
+ fixed: number;
231
+ quarantined: number;
232
+ remaining: number;
233
+ };
234
+ error?: undefined;
235
+ } | {
236
+ ok: boolean;
237
+ error: {
238
+ code: string;
239
+ message: any;
240
+ };
241
+ value?: undefined;
242
+ }>;
243
+ /**
244
+ * Register the session-health RPC handle and the
245
+ * maestro_session_health host tool. Fail-safe like the other registrations:
246
+ * any registration error is logged, never thrown, and the returned disposer
247
+ * unregisters everything that did succeed.
248
+ */
249
+ export declare function registerSessionHealthService(ctx: any, config?: SupervisorPluginConfig): () => void;
250
+ export declare function apply(ctx: any, config?: SupervisorPluginConfig): void;