@ddtcorex/dsh-maestro-core 0.13.0 → 0.15.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.
- package/README.md +3 -3
- package/lib/client.js +4 -125
- package/lib/debug-agent.d.ts +7 -0
- package/lib/debug-agent.js +15 -5
- package/lib/dsh-launch.d.ts +26 -0
- package/lib/dsh-launch.js +27 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +17 -4
- package/lib/restart-tool.d.ts +3 -1
- package/lib/restart-tool.js +8 -4
- package/lib/restart-web.d.ts +3 -0
- package/lib/restart-web.js +7 -3
- package/lib/resume.js +9 -1
- package/lib/sync/backup-service.d.ts +13 -0
- package/lib/sync/backup-service.js +60 -14
- package/lib/sync/hashing.d.ts +13 -0
- package/lib/sync/hashing.js +30 -0
- package/lib/sync/merge.d.ts +1 -1
- package/lib/sync/merge.js +1 -1
- package/lib/sync/remote-agent.js +12 -1
- package/lib/sync/remote-cache.js +1 -1
- package/lib/sync/remote-manifest.d.ts +25 -0
- package/lib/sync/remote-manifest.js +49 -2
- package/lib/sync/store-root.d.ts +44 -0
- package/lib/sync/store-root.js +67 -0
- package/lib/sync/sync-service.d.ts +25 -1
- package/lib/sync/sync-service.js +117 -12
- package/lib/sync/sync-types.d.ts +1 -1
- package/lib/sync/validation.d.ts +2 -0
- package/lib/sync/validation.js +15 -2
- package/lib/types/client/config/components/BrandMark.d.ts +1 -1
- package/lib/types/client/config/components/BrandMark.d.ts.map +1 -1
- package/lib/types/client/config/index.d.ts +0 -1
- package/lib/types/client/config/index.d.ts.map +1 -1
- package/lib/types/client/config/maestro-mark.d.ts +6 -16
- package/lib/types/client/config/maestro-mark.d.ts.map +1 -1
- package/lib/types/client/sync/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/skills/dsh-safe-restart/SKILL.md +4 -3
- package/skills/dsh-safe-restart/scripts/restart-dsh-web.sh +20 -36
- package/src/client/config/components/BrandMark.tsx +0 -1
- package/src/client/config/index.tsx +5 -44
- package/src/client/config/maestro-mark.ts +6 -23
- package/src/client/sync/index.tsx +0 -50
- package/src/client/sync/ui.tsx +4 -4
- package/src/host/debug-agent.ts +17 -8
- package/src/host/dsh-launch.ts +48 -0
- package/src/host/plugin.ts +19 -5
- package/src/host/restart-tool.ts +8 -4
- package/src/host/restart-web.ts +8 -6
- package/src/host/resume.ts +10 -1
- package/src/host/sync/backup-service.ts +67 -14
- package/src/host/sync/hashing.ts +34 -1
- package/src/host/sync/merge.ts +1 -1
- package/src/host/sync/remote-agent.ts +12 -1
- package/src/host/sync/remote-cache.ts +1 -1
- package/src/host/sync/remote-manifest.ts +49 -2
- package/src/host/sync/store-root.ts +83 -0
- package/src/host/sync/sync-service.ts +131 -12
- package/src/host/sync/sync-types.ts +1 -1
- package/src/host/sync/validation.ts +15 -2
- package/systemd/dsh-web-supervisor.service.template +2 -0
- package/systemd/dsh-web.service.template +8 -2
- package/lib/types/client/config/settings-nav-icon.d.ts +0 -21
- package/lib/types/client/config/settings-nav-icon.d.ts.map +0 -1
- package/src/client/config/settings-nav-icon.ts +0 -68
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ The package declares `dsh.client` (`platform: web`, `inject: ["@deepseek-ai/dsh-
|
|
|
86
86
|
**Pre-flight (required):** before adding to a live profile's `bundles`, dry-boot must pass:
|
|
87
87
|
|
|
88
88
|
```bash
|
|
89
|
-
DSH_HOME=$(mktemp -d)
|
|
89
|
+
DSH_HOME=$(mktemp -d) "$DSH_BIN" web --port 0 &
|
|
90
90
|
# wait for "dsh web: http://127.0.0.1:<port>" and curl 200, then kill
|
|
91
91
|
# This catches load-time failures (missing lib/index.js, stale build, bad cordis.patch.yml)
|
|
92
92
|
# that no in-code try/catch can catch. See dsh-safe-restart skill.
|
|
@@ -195,7 +195,7 @@ curl -s http://127.0.0.1:3080/plugins/@ddtcorex/dsh-maestro-core/client.js | gre
|
|
|
195
195
|
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:3080/ # 200
|
|
196
196
|
curl -s http://127.0.0.1:3080/dsh-maestro-supervisor-resume/scan -X POST -H 'content-type: application/json' -d '{"type":"client-request","rpcId":"t","method":"scan","payload":{"withinMs":300000}}' | head -c 200
|
|
197
197
|
node --input-type=module -e "import {findDanglingOpenTurns} from './packages/dsh-maestro-core/lib/resume.js'; console.log(await findDanglingOpenTurns(undefined,{withinMs:5*60*1000}))"
|
|
198
|
-
# Create a real dangling:
|
|
198
|
+
# Create a real dangling: "$DSH_BIN" --profile headless "Run bash synchronously sleep 60" & sleep 4; kill $!; node -e "...findDangling..." # should be 1
|
|
199
199
|
# After restart, it should have turn/end interrupted → continue → turn2
|
|
200
200
|
```
|
|
201
201
|
|
|
@@ -230,7 +230,7 @@ pnpm --dir packages/dsh-maestro-core test
|
|
|
230
230
|
pnpm --dir packages/dsh-maestro-core build
|
|
231
231
|
```
|
|
232
232
|
|
|
233
|
-
For daemon changes: `DSH_HOME=$(mktemp -d)
|
|
233
|
+
For daemon changes: `DSH_HOME=$(mktemp -d) "$DSH_BIN" web --port 0` + corrupt `settings.json` → assert `report` + `rollback`.
|
|
234
234
|
|
|
235
235
|
## Telegram
|
|
236
236
|
|
package/lib/client.js
CHANGED
|
@@ -209,10 +209,6 @@ var MAESTRO_MARK_PATH = "M2 11 L5 4 L8 9 L11 4 L14 11";
|
|
|
209
209
|
var MAESTRO_MARK_VIEWBOX = "0 0 16 16";
|
|
210
210
|
var MAESTRO_MARK_STROKE_WIDTH = 1.6;
|
|
211
211
|
var MAESTRO_BRAND_TILE = "#0A84FF";
|
|
212
|
-
function maestroMarkMaskUri() {
|
|
213
|
-
const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='${MAESTRO_MARK_VIEWBOX}' fill='none' stroke='black' stroke-width='${MAESTRO_MARK_STROKE_WIDTH}' stroke-linecap='round' stroke-linejoin='round'><path d='${MAESTRO_MARK_PATH}'/></svg>`;
|
|
214
|
-
return `data:image/svg+xml,${svg.replace(/</g, "%3C").replace(/>/g, "%3E")}`;
|
|
215
|
-
}
|
|
216
212
|
|
|
217
213
|
// src/client/config/components/BrandMark.tsx
|
|
218
214
|
var BRAND_BADGE_LAYOUT_KEYS = [
|
|
@@ -960,73 +956,8 @@ function MaestroSettingsTab({ configRpcCall, supervisorRpcCall }) {
|
|
|
960
956
|
);
|
|
961
957
|
}
|
|
962
958
|
|
|
963
|
-
// src/client/config/settings-nav-icon.ts
|
|
964
|
-
var SETTINGS_NAV_MARKER = "data-maestro-settings-nav";
|
|
965
|
-
function registerSettingsNavIcon(label, root) {
|
|
966
|
-
if (typeof document === "undefined" && root === void 0) {
|
|
967
|
-
return () => {
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
|
-
const scope = root ?? document;
|
|
971
|
-
let disposed = false;
|
|
972
|
-
const sync = () => {
|
|
973
|
-
if (disposed) return;
|
|
974
|
-
const currentLabel = label().trim();
|
|
975
|
-
const buttons = scope.querySelectorAll('[role="dialog"] nav button');
|
|
976
|
-
for (const button of Array.from(buttons)) {
|
|
977
|
-
const el = button;
|
|
978
|
-
const matches = currentLabel.length > 0 && button.textContent != null && button.textContent.trim() === currentLabel;
|
|
979
|
-
if (matches) el.setAttribute(SETTINGS_NAV_MARKER, "");
|
|
980
|
-
else el.removeAttribute(SETTINGS_NAV_MARKER);
|
|
981
|
-
}
|
|
982
|
-
};
|
|
983
|
-
sync();
|
|
984
|
-
let observer = null;
|
|
985
|
-
if (typeof MutationObserver !== "undefined") {
|
|
986
|
-
observer = new MutationObserver(sync);
|
|
987
|
-
observer.observe(document.body, { childList: true, subtree: true, characterData: true });
|
|
988
|
-
}
|
|
989
|
-
return () => {
|
|
990
|
-
disposed = true;
|
|
991
|
-
if (observer !== null) observer.disconnect();
|
|
992
|
-
for (const element of Array.from(scope.querySelectorAll(`[${SETTINGS_NAV_MARKER}]`))) {
|
|
993
|
-
;
|
|
994
|
-
element.removeAttribute(SETTINGS_NAV_MARKER);
|
|
995
|
-
}
|
|
996
|
-
};
|
|
997
|
-
}
|
|
998
|
-
|
|
999
959
|
// src/client/config/index.tsx
|
|
1000
960
|
var MAESTRO_SETTINGS_ORDER = 26;
|
|
1001
|
-
var SETTINGS_NAV_CSS = `
|
|
1002
|
-
|
|
1003
|
-
/* maestro: replace the settings-nav fallback gear with the Maestro M-logo glyph \u2014 same mark as components/BrandMark.tsx */
|
|
1004
|
-
[${SETTINGS_NAV_MARKER}] > svg:first-child,
|
|
1005
|
-
[${SETTINGS_NAV_MARKER}] > svg.zWKi1a_navIcon {
|
|
1006
|
-
display: none !important;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
[${SETTINGS_NAV_MARKER}]::before {
|
|
1010
|
-
content: '';
|
|
1011
|
-
flex: none;
|
|
1012
|
-
width: 16px;
|
|
1013
|
-
height: 16px;
|
|
1014
|
-
display: inline-block;
|
|
1015
|
-
background: currentColor;
|
|
1016
|
-
-webkit-mask: url("${maestroMarkMaskUri()}") center / contain no-repeat;
|
|
1017
|
-
mask: url("${maestroMarkMaskUri()}") center / contain no-repeat;
|
|
1018
|
-
}
|
|
1019
|
-
`;
|
|
1020
|
-
function installNavIconStyle() {
|
|
1021
|
-
const tag = document.createElement("style");
|
|
1022
|
-
tag.dataset.plugin = "@ddtcorex/dsh-maestro-config";
|
|
1023
|
-
tag.dataset.pluginCss = "maestro/settings-nav.css";
|
|
1024
|
-
tag.textContent = SETTINGS_NAV_CSS;
|
|
1025
|
-
document.head.appendChild(tag);
|
|
1026
|
-
return () => {
|
|
1027
|
-
document.querySelector('style[data-plugin-css="maestro/settings-nav.css"]')?.remove();
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
961
|
function apply2(ctx) {
|
|
1031
962
|
const slots = ctx.get?.("slots");
|
|
1032
963
|
if (slots === void 0) return;
|
|
@@ -1040,8 +971,6 @@ function apply2(ctx) {
|
|
|
1040
971
|
if (!connection?.rpc?.call) return Promise.reject(new Error("RPC not available"));
|
|
1041
972
|
return connection.rpc.call("/dsh-maestro-supervisor-resume", endpoint, payload, signal);
|
|
1042
973
|
};
|
|
1043
|
-
ctx.effect(() => registerSettingsNavIcon(() => "Maestro"), "maestro: settings nav icon");
|
|
1044
|
-
ctx.effect(installNavIconStyle, "maestro: settings nav css");
|
|
1045
974
|
slots.inject(
|
|
1046
975
|
"settings.section",
|
|
1047
976
|
() => slots.register(
|
|
@@ -1232,8 +1161,8 @@ function formatLastSync(v) {
|
|
|
1232
1161
|
}
|
|
1233
1162
|
}
|
|
1234
1163
|
function formatFile(path) {
|
|
1235
|
-
if (path.startsWith("
|
|
1236
|
-
const date = path.replace("
|
|
1164
|
+
if (path.startsWith("maestro-memory/daily/")) {
|
|
1165
|
+
const date = path.replace("maestro-memory/daily/", "").replace(".md", "");
|
|
1237
1166
|
try {
|
|
1238
1167
|
const d = new Date(date);
|
|
1239
1168
|
if (!isNaN(d.getTime())) return { icon: "calendar", title: `Daily notes \u2014 ${d.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" })}`, path, meta: "Daily" };
|
|
@@ -1241,11 +1170,11 @@ function formatFile(path) {
|
|
|
1241
1170
|
}
|
|
1242
1171
|
return { icon: "calendar", title: `Daily notes \u2014 ${date}`, path, meta: "Daily" };
|
|
1243
1172
|
}
|
|
1244
|
-
if (path.startsWith("
|
|
1173
|
+
if (path.startsWith("maestro-memory/projects/")) {
|
|
1245
1174
|
const hash = path.split("/")[2] ?? "";
|
|
1246
1175
|
return { icon: "folder", title: "Project memory", path, meta: hash.slice(0, 7) };
|
|
1247
1176
|
}
|
|
1248
|
-
if (path === "
|
|
1177
|
+
if (path === "maestro-memory/MEMORY.md") return { icon: "star", title: "Global memory", path, meta: "Global" };
|
|
1249
1178
|
if (path.startsWith("sessions/")) {
|
|
1250
1179
|
const hash = path.split("/")[1] ?? "";
|
|
1251
1180
|
return { icon: "message", title: "Session", path, meta: hash.slice(0, 7) };
|
|
@@ -2516,54 +2445,6 @@ function SyncPanel(props) {
|
|
|
2516
2445
|
}
|
|
2517
2446
|
|
|
2518
2447
|
// src/client/sync/index.tsx
|
|
2519
|
-
var SETTINGS_NAV_MARKER2 = "data-maestro-sync-settings-nav";
|
|
2520
|
-
var SETTINGS_NAV_CSS2 = `
|
|
2521
|
-
[${SETTINGS_NAV_MARKER2}] > svg:first-child,
|
|
2522
|
-
[${SETTINGS_NAV_MARKER2}] > svg.zWKi1a_navIcon {
|
|
2523
|
-
display: none !important;
|
|
2524
|
-
}
|
|
2525
|
-
[${SETTINGS_NAV_MARKER2}]::before {
|
|
2526
|
-
content: '';
|
|
2527
|
-
flex: none;
|
|
2528
|
-
width: 16px;
|
|
2529
|
-
height: 16px;
|
|
2530
|
-
display: inline-block;
|
|
2531
|
-
background: currentColor;
|
|
2532
|
-
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 11 L5 4 L8 9 L11 4 L14 11'/%3E%3C/svg%3E") center / contain no-repeat;
|
|
2533
|
-
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 11 L5 4 L8 9 L11 4 L14 11'/%3E%3C/svg%3E") center / contain no-repeat;
|
|
2534
|
-
}
|
|
2535
|
-
`;
|
|
2536
|
-
function registerSyncNavIcon(label, root) {
|
|
2537
|
-
if (typeof document === "undefined" && root === void 0) return () => {
|
|
2538
|
-
};
|
|
2539
|
-
const scope = root ?? document;
|
|
2540
|
-
let disposed = false;
|
|
2541
|
-
const sync = () => {
|
|
2542
|
-
if (disposed) return;
|
|
2543
|
-
const currentLabel = label().trim();
|
|
2544
|
-
const buttons = scope.querySelectorAll('[role="dialog"] nav button');
|
|
2545
|
-
for (const button of Array.from(buttons)) {
|
|
2546
|
-
const el = button;
|
|
2547
|
-
const matches = currentLabel.length > 0 && button.textContent != null && button.textContent.trim() === currentLabel;
|
|
2548
|
-
if (matches) el.setAttribute(SETTINGS_NAV_MARKER2, "");
|
|
2549
|
-
else el.removeAttribute(SETTINGS_NAV_MARKER2);
|
|
2550
|
-
}
|
|
2551
|
-
};
|
|
2552
|
-
sync();
|
|
2553
|
-
let observer = null;
|
|
2554
|
-
if (typeof MutationObserver !== "undefined") {
|
|
2555
|
-
observer = new MutationObserver(sync);
|
|
2556
|
-
observer.observe(document.body, { childList: true, subtree: true, characterData: true });
|
|
2557
|
-
}
|
|
2558
|
-
return () => {
|
|
2559
|
-
disposed = true;
|
|
2560
|
-
if (observer !== null) observer.disconnect();
|
|
2561
|
-
for (const element of Array.from(scope.querySelectorAll(`[${SETTINGS_NAV_MARKER2}]`))) {
|
|
2562
|
-
;
|
|
2563
|
-
element.removeAttribute(SETTINGS_NAV_MARKER2);
|
|
2564
|
-
}
|
|
2565
|
-
};
|
|
2566
|
-
}
|
|
2567
2448
|
function installStyleTag(css, pluginCss) {
|
|
2568
2449
|
if (typeof document === "undefined") return () => {
|
|
2569
2450
|
};
|
|
@@ -2811,8 +2692,6 @@ button[data-sync-stat]:focus-visible { outline: 2px solid var(--dsw-alias-border
|
|
|
2811
2692
|
function apply3(ctx) {
|
|
2812
2693
|
const slots = ctx.slots ?? ctx.get?.("slots");
|
|
2813
2694
|
if (!slots?.inject || !slots?.register) return;
|
|
2814
|
-
ctx.effect(() => registerSyncNavIcon(() => "Maestro Sync"), "maestro-sync: settings nav icon");
|
|
2815
|
-
ctx.effect(() => installStyleTag(SETTINGS_NAV_CSS2, "maestro-sync/settings-nav.css"), "maestro-sync: settings nav css");
|
|
2816
2695
|
ctx.effect(() => installStyleTag(SYNC_CSS, "maestro-sync/settings.css"), "maestro-sync: settings css");
|
|
2817
2696
|
ctx.effect(() => {
|
|
2818
2697
|
const dispose = slots.inject(
|
package/lib/debug-agent.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type DshLaunchDeps } from './dsh-launch.js';
|
|
1
2
|
export interface DebugAgentOpts {
|
|
2
3
|
reportPath: string;
|
|
3
4
|
health: {
|
|
@@ -14,4 +15,10 @@ export declare function runDebugAgent(opts: DebugAgentOpts): Promise<{
|
|
|
14
15
|
fixed: boolean;
|
|
15
16
|
reason: string;
|
|
16
17
|
}>;
|
|
18
|
+
/**
|
|
19
|
+
* The bounded dry-boot probe: boot `dsh web` on `tmp` as DSH_HOME and an
|
|
20
|
+
* ephemeral port, poll for 200, print ok/fail. The boot follows
|
|
21
|
+
* `resolveDshLaunch`, so a packaged host verifies the runtime it runs.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildDryBootCommand(tmp: string, port: number, deps?: DshLaunchDeps): string;
|
|
17
24
|
export declare function _resetDebugAgentForTest(): void;
|
package/lib/debug-agent.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveDshLaunch } from './dsh-launch.js';
|
|
1
2
|
let lastRun = 0;
|
|
2
3
|
let attempts = 0;
|
|
3
4
|
const MAX_ATTEMPTS = 3;
|
|
@@ -57,7 +58,8 @@ async function autoFixKnownPatterns(err, exec, readFile, writeFile) {
|
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
59
60
|
if (err.includes('ERR_MODULE_NOT_FOUND') || err.includes('Cannot find module')) {
|
|
60
|
-
|
|
61
|
+
// memory left the workspace on 2026-11-09 for ~/Work/htdocs/maestro-memory
|
|
62
|
+
const candidates = ['dsh-maestro-core', 'dsh-maestro-observe'];
|
|
61
63
|
for (const pkg of candidates) {
|
|
62
64
|
try {
|
|
63
65
|
const p = `${harnessRoot}/packages/${pkg}/lib/index.js`;
|
|
@@ -102,17 +104,25 @@ function defaultWriteFile(p, c) {
|
|
|
102
104
|
mkdirSync(dirname(p), { recursive: true });
|
|
103
105
|
writeFileSync(p, c, 'utf-8');
|
|
104
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* The bounded dry-boot probe: boot `dsh web` on `tmp` as DSH_HOME and an
|
|
109
|
+
* ephemeral port, poll for 200, print ok/fail. The boot follows
|
|
110
|
+
* `resolveDshLaunch`, so a packaged host verifies the runtime it runs.
|
|
111
|
+
*/
|
|
112
|
+
export function buildDryBootCommand(tmp, port, deps = {}) {
|
|
113
|
+
const launch = resolveDshLaunch(['web', '--port', String(port), '--no-open'], deps);
|
|
114
|
+
const argv = [launch.command, ...launch.args].map(a => JSON.stringify(a)).join(' ');
|
|
115
|
+
const boot = `${launch.cwd ? `cd ${JSON.stringify(launch.cwd)} && ` : ''}DSH_HOME=${tmp} ${argv} >${tmp}/dsh.log 2>&1 &`;
|
|
116
|
+
return `timeout 8 bash -c '${boot} pid=$!; for i in $(seq 1 5); do sleep 1; if curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${port}/ 2>&1 | grep -q 200; then echo ok; exit 0; fi; done; echo fail; exit 1'`;
|
|
117
|
+
}
|
|
105
118
|
async function defaultDryBoot() {
|
|
106
119
|
const { execSync } = await import('node:child_process');
|
|
107
|
-
const { resolveDeepseekHarnessDir } = await import('./paths.js');
|
|
108
120
|
const { buildKillStalePortsCommand } = await import('./restart-guards.js');
|
|
109
121
|
const port = Math.floor(19000 + Math.random() * 1000);
|
|
110
122
|
let tmp = '';
|
|
111
123
|
try {
|
|
112
|
-
const deepseekDir = resolveDeepseekHarnessDir();
|
|
113
124
|
tmp = execSync('mktemp -d', { encoding: 'utf-8' }).trim();
|
|
114
|
-
|
|
115
|
-
const out = execSync(`timeout 8 bash -c 'DSH_HOME=${tmp} pnpm --dir ${deepseekDir} dsh web --port ${port} --no-open >${tmp}/dsh.log 2>&1 & pid=$!; for i in $(seq 1 5); do sleep 1; if curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${port}/ 2>&1 | grep -q 200; then echo ok; exit 0; fi; done; echo fail; exit 1'`, { encoding: 'utf-8', timeout: 12000 });
|
|
125
|
+
const out = execSync(buildDryBootCommand(tmp, port), { encoding: 'utf-8', timeout: 12000 });
|
|
116
126
|
return out.includes('ok');
|
|
117
127
|
}
|
|
118
128
|
catch {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How to start the `dsh` CLI on this host. `DSH_BIN` (the installed package's
|
|
3
|
+
* bin, e.g. `~/.local/share/dsh/current/bin/dsh`) is the single switch: set,
|
|
4
|
+
* the packaged runtime runs through the current node; unset, the source
|
|
5
|
+
* checkout runs through tsx, which is how hosts without a packaged install
|
|
6
|
+
* have always booted.
|
|
7
|
+
*/
|
|
8
|
+
export interface DshLaunch {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
cwd?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface DshLaunchDeps {
|
|
14
|
+
env?: Record<string, string | undefined>;
|
|
15
|
+
execPath?: string;
|
|
16
|
+
sourceDir?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function resolveDshLaunch(args: string[], deps?: DshLaunchDeps): DshLaunch;
|
|
19
|
+
/** The same launch as a shell fragment (`[cd <dir> && ]exec <argv>`), every word quoted. */
|
|
20
|
+
export declare function dshLaunchShell(args: string[], deps?: DshLaunchDeps): string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a process command line is a `dsh web` boot in either form: the
|
|
23
|
+
* source entry (`apps/cli/src/bin.ts web`), the package entry (`lib/bin.js
|
|
24
|
+
* web`) or the installed bin (`.../dsh web`).
|
|
25
|
+
*/
|
|
26
|
+
export declare function isDshWebCommand(cmd: string): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { resolveDeepseekHarnessDir } from './paths.js';
|
|
2
|
+
export function resolveDshLaunch(args, deps = {}) {
|
|
3
|
+
const env = deps.env ?? process.env;
|
|
4
|
+
const command = deps.execPath ?? process.execPath;
|
|
5
|
+
const bin = env.DSH_BIN?.trim();
|
|
6
|
+
if (bin)
|
|
7
|
+
return { command, args: [bin, ...args] };
|
|
8
|
+
return {
|
|
9
|
+
command,
|
|
10
|
+
args: ['--import', 'tsx/esm', 'apps/cli/src/bin.ts', ...args],
|
|
11
|
+
cwd: deps.sourceDir ?? resolveDeepseekHarnessDir(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** The same launch as a shell fragment (`[cd <dir> && ]exec <argv>`), every word quoted. */
|
|
15
|
+
export function dshLaunchShell(args, deps = {}) {
|
|
16
|
+
const launch = resolveDshLaunch(args, deps);
|
|
17
|
+
const argv = [launch.command, ...launch.args].map(a => JSON.stringify(a)).join(' ');
|
|
18
|
+
return launch.cwd ? `cd ${JSON.stringify(launch.cwd)} && exec ${argv}` : `exec ${argv}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Whether a process command line is a `dsh web` boot in either form: the
|
|
22
|
+
* source entry (`apps/cli/src/bin.ts web`), the package entry (`lib/bin.js
|
|
23
|
+
* web`) or the installed bin (`.../dsh web`).
|
|
24
|
+
*/
|
|
25
|
+
export function isDshWebCommand(cmd) {
|
|
26
|
+
return /(?:\bbin\.[jt]s|\/dsh)\s+web(?:\s|$)/.test(cmd);
|
|
27
|
+
}
|
package/lib/plugin.d.ts
CHANGED
|
@@ -177,6 +177,7 @@ export declare function activateSessionAgent(ctx: any, sessionId: string, deps?:
|
|
|
177
177
|
}): Promise<{
|
|
178
178
|
agent?: any;
|
|
179
179
|
via: 'controller' | 'resume';
|
|
180
|
+
controller: 'resolved' | 'declined' | 'absent' | 'threw';
|
|
180
181
|
}>;
|
|
181
182
|
export declare function resumeInterrupted(ctx: any, ids: string[], deps?: {
|
|
182
183
|
readIntent?: (id: string) => RestartIntent | undefined;
|
package/lib/plugin.js
CHANGED
|
@@ -577,12 +577,14 @@ export async function activateSessionAgent(ctx, sessionId, deps = {}) {
|
|
|
577
577
|
try {
|
|
578
578
|
const resolved = await resolveViaController(ctx, sessionId);
|
|
579
579
|
if (resolved?.agent !== undefined)
|
|
580
|
-
return { agent: resolved.agent, via: 'controller' };
|
|
580
|
+
return { agent: resolved.agent, via: 'controller', controller: 'resolved' };
|
|
581
|
+
const controller = ctx?.get?.('sessionController') ?? ctx?.sessionController;
|
|
582
|
+
return { via: 'resume', controller: typeof controller?.resolveAgent === 'function' || deps.resolveSessionAgent !== undefined ? 'declined' : 'absent' };
|
|
581
583
|
}
|
|
582
584
|
catch {
|
|
583
585
|
/* fall through: the resume path owns the ownership retry and prompt delivery */
|
|
584
586
|
}
|
|
585
|
-
return { via: 'resume' };
|
|
587
|
+
return { via: 'resume', controller: 'threw' };
|
|
586
588
|
}
|
|
587
589
|
export async function resumeInterrupted(ctx, ids, deps = {}) {
|
|
588
590
|
const doReadIntent = deps.readIntent ?? readIntent;
|
|
@@ -695,14 +697,21 @@ export async function resumeInterrupted(ctx, ids, deps = {}) {
|
|
|
695
697
|
const sessionId = id.split('/').pop();
|
|
696
698
|
const agents = ctx.get?.('agents') ?? ctx.agents;
|
|
697
699
|
let agent = agents?.get?.(sessionId);
|
|
700
|
+
// Which branch last produced the agent candidate. The no-agent journal
|
|
701
|
+
// entry reports it, so a silent miss (absent service, empty handle)
|
|
702
|
+
// cannot masquerade as a resume that returned a bad agent.
|
|
703
|
+
let source = agent === undefined ? 'none' : 'live';
|
|
704
|
+
let controllerState = 'unprobed';
|
|
698
705
|
if (agent === undefined) {
|
|
699
706
|
// The activation owner runs FIRST and needs no recovered route: it
|
|
700
707
|
// resolves provider/model itself while composing the session's preset.
|
|
701
708
|
const activation = await activateSessionAgent(ctx, sessionId, {
|
|
702
709
|
...(deps.resolveSessionAgent !== undefined ? { resolveSessionAgent: deps.resolveSessionAgent } : {}),
|
|
703
710
|
});
|
|
711
|
+
controllerState = activation.controller;
|
|
704
712
|
if (activation.agent !== undefined) {
|
|
705
713
|
agent = activation.agent;
|
|
714
|
+
source = 'controller';
|
|
706
715
|
ctx.logger?.info?.(`[supervisor] auto-resume: resolved the agent for ${id} through sessionController`);
|
|
707
716
|
}
|
|
708
717
|
else {
|
|
@@ -796,13 +805,17 @@ export async function resumeInterrupted(ctx, ids, deps = {}) {
|
|
|
796
805
|
throw error;
|
|
797
806
|
}
|
|
798
807
|
agent = handle?.agent;
|
|
808
|
+
source = 'manual';
|
|
799
809
|
if (agent !== undefined)
|
|
800
810
|
ctx.logger?.info?.(`[supervisor] auto-resume: re-attached agent for ${id}`);
|
|
801
811
|
}
|
|
802
812
|
}
|
|
803
813
|
if (typeof agent?.followup !== 'function') {
|
|
804
|
-
|
|
805
|
-
|
|
814
|
+
const detail = `agents.resume returned no followup-capable handle ` +
|
|
815
|
+
`(source=${source} agents=${agents == null ? 'absent' : 'present'} ` +
|
|
816
|
+
`controller=${controllerState} agentType=${agent === undefined ? 'undefined' : typeof agent})`;
|
|
817
|
+
ctx.logger?.warn?.(`[supervisor] auto-resume: no live agent available for ${id} — ${detail}`);
|
|
818
|
+
doLog({ ts: Date.now(), sessionId, kind: 'no-agent', detail });
|
|
806
819
|
continue;
|
|
807
820
|
}
|
|
808
821
|
await verifyResumedComposition(sessionId, agent);
|
package/lib/restart-tool.d.ts
CHANGED
|
@@ -53,7 +53,9 @@ export declare function listDryBootCandidates(readers?: GcReaders): DryBootCandi
|
|
|
53
53
|
* Boot a copy of the live web profile on an isolated DSH_HOME and verify the
|
|
54
54
|
* plugin tree loads and serves. Returns ok + a one-line detail for the tool
|
|
55
55
|
* message. The spawned tree is killed (best-effort) and the temp home removed.
|
|
56
|
-
* Unit tests mock this (never spawn a real node boot in tests).
|
|
56
|
+
* Unit tests mock this (never spawn a real node boot in tests). The boot uses
|
|
57
|
+
* `resolveDshLaunch`, so `harnessRoot` (the source checkout) only matters
|
|
58
|
+
* when `DSH_BIN` is unset.
|
|
57
59
|
*
|
|
58
60
|
* NOTE (bin.ts finding): the `web` alias already implies `--profile web`, and
|
|
59
61
|
* the web app's own commander program (no allowUnknownOption) rejects a stray
|
package/lib/restart-tool.js
CHANGED
|
@@ -19,6 +19,7 @@ import { createRequire } from 'node:module';
|
|
|
19
19
|
import { writeRestartRequest, readRestartRequest } from './restart-guards.js';
|
|
20
20
|
import { intentPath, readIntent, readRestartOutcome } from './intents.js';
|
|
21
21
|
import { supervisorDaemonState, describeDaemonState } from './daemon-freshness.js';
|
|
22
|
+
import { resolveDshLaunch, isDshWebCommand } from './dsh-launch.js';
|
|
22
23
|
/**
|
|
23
24
|
* Copy a live profile tree for an isolated dry-boot. A naive recursive copy
|
|
24
25
|
* breaks `link:` installs: their node_modules entries are relative symlinks
|
|
@@ -104,7 +105,7 @@ export function listDryBootCandidates(readers = {}) {
|
|
|
104
105
|
for (const p of readProc()) {
|
|
105
106
|
if (p.pid === selfPid)
|
|
106
107
|
continue;
|
|
107
|
-
if (
|
|
108
|
+
if (!isDshWebCommand(p.cmd))
|
|
108
109
|
continue;
|
|
109
110
|
const home = /^DSH_HOME=([^\0]*)/m.exec(p.env)?.[1] ?? '';
|
|
110
111
|
if (!home.startsWith(join(tmpdir(), 'dsh-dryboot-')))
|
|
@@ -123,7 +124,9 @@ export function listDryBootCandidates(readers = {}) {
|
|
|
123
124
|
* Boot a copy of the live web profile on an isolated DSH_HOME and verify the
|
|
124
125
|
* plugin tree loads and serves. Returns ok + a one-line detail for the tool
|
|
125
126
|
* message. The spawned tree is killed (best-effort) and the temp home removed.
|
|
126
|
-
* Unit tests mock this (never spawn a real node boot in tests).
|
|
127
|
+
* Unit tests mock this (never spawn a real node boot in tests). The boot uses
|
|
128
|
+
* `resolveDshLaunch`, so `harnessRoot` (the source checkout) only matters
|
|
129
|
+
* when `DSH_BIN` is unset.
|
|
127
130
|
*
|
|
128
131
|
* NOTE (bin.ts finding): the `web` alias already implies `--profile web`, and
|
|
129
132
|
* the web app's own commander program (no allowUnknownOption) rejects a stray
|
|
@@ -143,8 +146,9 @@ export async function dryBootVerify(harnessRoot, opts = {}) {
|
|
|
143
146
|
copyProfileForDryBoot(liveProfile, join(tmpHome, 'profiles', 'web'));
|
|
144
147
|
const port = String(9000 + Math.floor(Math.random() * 1000));
|
|
145
148
|
const url = `http://127.0.0.1:${port}/`;
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
const launch = resolveDshLaunch(['web', '--no-open', '--port', port], { sourceDir: harnessRoot });
|
|
150
|
+
child = spawn(launch.command, launch.args, {
|
|
151
|
+
cwd: launch.cwd, env: { ...process.env, DSH_HOME: tmpHome }, stdio: ['ignore', 'pipe', 'pipe'],
|
|
148
152
|
});
|
|
149
153
|
child.stdout?.on('data', (d) => logs.push(d.toString()));
|
|
150
154
|
child.stderr?.on('data', (d) => logs.push(d.toString()));
|
package/lib/restart-web.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type BootLockDeps } from './boot-lock.js';
|
|
2
|
+
import { type DshLaunchDeps } from './dsh-launch.js';
|
|
2
3
|
/** Boot budget: how long a boot may take before its failures are judged. */
|
|
3
4
|
export declare const DEFAULT_BOOT_GRACE_MS = 180000;
|
|
4
5
|
export interface RestartWebDeps {
|
|
@@ -24,3 +25,5 @@ export interface RestartWebResult {
|
|
|
24
25
|
* systemd start that turned the incident's log tail toxic (2026-09-13).
|
|
25
26
|
*/
|
|
26
27
|
export declare function performSingleBootRestart(deps?: RestartWebDeps): Promise<RestartWebResult>;
|
|
28
|
+
/** The detached last-resort start, appending to the web log. Exported for tests. */
|
|
29
|
+
export declare function buildNohupCommand(logPath: string, deps?: DshLaunchDeps): string;
|
package/lib/restart-web.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as path from 'node:path';
|
|
|
3
3
|
import { buildKillStalePortsCommand, writePlannedRestart } from './restart-guards.js';
|
|
4
4
|
import { serializedSystemdRestart, shouldUseNohupFallback, systemdUnitExists } from './restart-exec.js';
|
|
5
5
|
import { withBootLock } from './boot-lock.js';
|
|
6
|
-
import {
|
|
6
|
+
import { dshLaunchShell } from './dsh-launch.js';
|
|
7
7
|
/** Boot budget: how long a boot may take before its failures are judged. */
|
|
8
8
|
export const DEFAULT_BOOT_GRACE_MS = 180_000;
|
|
9
9
|
/**
|
|
@@ -50,9 +50,13 @@ export async function performSingleBootRestart(deps = {}) {
|
|
|
50
50
|
return { restarted: false, reason: 'another boot already holds boot.lock' };
|
|
51
51
|
return { restarted: true };
|
|
52
52
|
}
|
|
53
|
+
/** The detached last-resort start, appending to the web log. Exported for tests. */
|
|
54
|
+
export function buildNohupCommand(logPath, deps = {}) {
|
|
55
|
+
const launch = dshLaunchShell(['web', '--no-open'], deps);
|
|
56
|
+
return `setsid nohup bash -c 'export NVM_DIR="$HOME/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; ${launch} >> ${JSON.stringify(logPath)} 2>&1' &`;
|
|
57
|
+
}
|
|
53
58
|
async function defaultNohup() {
|
|
54
59
|
const { execSync } = await import('node:child_process');
|
|
55
|
-
const harnessRoot = resolveDeepseekHarnessDir();
|
|
56
60
|
const logPath = path.join(os.homedir(), '.dsh/dsh-web.log');
|
|
57
|
-
execSync(
|
|
61
|
+
execSync(buildNohupCommand(logPath), { timeout: 5000 });
|
|
58
62
|
}
|
package/lib/resume.js
CHANGED
|
@@ -75,7 +75,15 @@ export async function findInterrupted(dshHome, opts) {
|
|
|
75
75
|
try {
|
|
76
76
|
const obj = JSON.parse(line);
|
|
77
77
|
foundTime = typeof obj.time === 'number' ? obj.time : undefined;
|
|
78
|
-
|
|
78
|
+
// Two shapes mean "this turn never finished":
|
|
79
|
+
// interrupted the host died with the turn in flight
|
|
80
|
+
// aborted/disposed the host shut the turn down on purpose
|
|
81
|
+
// (supervisor restart, graceful stop)
|
|
82
|
+
// `aborted/user` is the person pressing stop and must stay out.
|
|
83
|
+
const reason = obj.data?.reason;
|
|
84
|
+
const resumable = reason?.kind === 'interrupted' ||
|
|
85
|
+
(reason?.kind === 'aborted' && reason?.reason?.kind === 'disposed');
|
|
86
|
+
if (obj.type === 'turn/end' && resumable) {
|
|
79
87
|
found = true;
|
|
80
88
|
break;
|
|
81
89
|
}
|
|
@@ -38,13 +38,26 @@ export declare class BackupService {
|
|
|
38
38
|
private readonly opts;
|
|
39
39
|
constructor(opts: {
|
|
40
40
|
localDsh: string;
|
|
41
|
+
storeRoot?: string;
|
|
41
42
|
store: S3ObjectStore;
|
|
42
43
|
target: BackupTarget;
|
|
43
44
|
previewDir: string;
|
|
44
45
|
cacheDir: string;
|
|
45
46
|
fs?: any;
|
|
46
47
|
});
|
|
48
|
+
/**
|
|
49
|
+
* The store may live outside the DSH home. Reads and writes of memory content map
|
|
50
|
+
* through the resolved root; sessions and sync state stay under the DSH home.
|
|
51
|
+
*/
|
|
52
|
+
private resolveStoreRoot;
|
|
53
|
+
private localPathForWirePath;
|
|
47
54
|
blobKey(sha: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* A backup taken in the core-first release window would walk a root that does not
|
|
57
|
+
* exist yet, record zero memory files, and report `ok: true`. Refuse instead, with
|
|
58
|
+
* the same sentinel sync uses.
|
|
59
|
+
*/
|
|
60
|
+
assertStoreMigrated(): void;
|
|
48
61
|
listEligibleFiles(): string[];
|
|
49
62
|
readHeadManifest(): Promise<{
|
|
50
63
|
key: string;
|