dsh-plugin-agentdeck 0.1.0 → 0.2.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 +29 -54
- package/lib/client.js +484 -592
- package/lib/index.js +151 -18
- package/lib/setup.js +175 -5
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +6 -3
package/lib/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { homedir } from 'node:os';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import {
|
|
4
|
+
AWAKE_MODES,
|
|
4
5
|
controlAgentDeckDaemon,
|
|
5
6
|
getAgentDeckStatus,
|
|
6
7
|
runAgentDeckSetup,
|
|
8
|
+
setAgentDeckAwake,
|
|
9
|
+
syncAgentDeckModels,
|
|
7
10
|
} from './setup.js';
|
|
8
11
|
|
|
9
12
|
export const name = 'agentdeck';
|
|
@@ -12,6 +15,8 @@ export const inject = ['webServer'];
|
|
|
12
15
|
const STATUS_PATH = '/api/agentdeck/status';
|
|
13
16
|
const SETUP_PATH = '/api/agentdeck/setup';
|
|
14
17
|
const DAEMON_PATH = '/api/agentdeck/daemon';
|
|
18
|
+
const AWAKE_PATH = '/api/agentdeck/awake';
|
|
19
|
+
const SYNC_MODELS_PATH = '/api/agentdeck/sync-models';
|
|
15
20
|
const MAX_BODY_BYTES = 16 * 1024;
|
|
16
21
|
|
|
17
22
|
function sendJson(res, statusCode, payload) {
|
|
@@ -58,7 +63,7 @@ async function parseJsonRequest(req, res) {
|
|
|
58
63
|
.split(';', 1)[0]
|
|
59
64
|
.trim()
|
|
60
65
|
.toLowerCase();
|
|
61
|
-
if (contentType
|
|
66
|
+
if (contentType !== 'application/json') {
|
|
62
67
|
sendJson(res, 415, {
|
|
63
68
|
ok: false,
|
|
64
69
|
error: 'content-type must be application/json',
|
|
@@ -101,6 +106,57 @@ function getProfileInfo(ctx) {
|
|
|
101
106
|
|
|
102
107
|
export function apply(ctx) {
|
|
103
108
|
let opInFlight = null;
|
|
109
|
+
let disposed = false;
|
|
110
|
+
let provisioning = { state: 'idle', error: null };
|
|
111
|
+
|
|
112
|
+
const startAutoProvision = ({ forceStartDaemon = false } = {}) => {
|
|
113
|
+
if (opInFlight || disposed) return opInFlight;
|
|
114
|
+
const info = getProfileInfo(ctx);
|
|
115
|
+
provisioning = { state: 'running', error: null };
|
|
116
|
+
const task = (async () => {
|
|
117
|
+
try {
|
|
118
|
+
const current = await getAgentDeckStatus(info);
|
|
119
|
+
const needsSetup =
|
|
120
|
+
!current.acpPlugin.installed ||
|
|
121
|
+
!current.customAgent.configured ||
|
|
122
|
+
current.models.acpNeedsProviderPin ||
|
|
123
|
+
!current.daemon.installed ||
|
|
124
|
+
(!current.daemon.running &&
|
|
125
|
+
(forceStartDaemon || !current.daemon.pairedReady));
|
|
126
|
+
if (!needsSetup || disposed) {
|
|
127
|
+
provisioning = { state: 'idle', error: null };
|
|
128
|
+
return { ok: true, status: current };
|
|
129
|
+
}
|
|
130
|
+
const result = await runAgentDeckSetup({
|
|
131
|
+
...info,
|
|
132
|
+
syncModels: false,
|
|
133
|
+
startDaemon: forceStartDaemon || !current.daemon.pairedReady || !current.customAgent.configured,
|
|
134
|
+
});
|
|
135
|
+
provisioning = { state: 'idle', error: null };
|
|
136
|
+
return result;
|
|
137
|
+
} catch (err) {
|
|
138
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
139
|
+
provisioning = { state: 'error', error: message };
|
|
140
|
+
throw err;
|
|
141
|
+
} finally {
|
|
142
|
+
if (opInFlight === task) opInFlight = null;
|
|
143
|
+
}
|
|
144
|
+
})();
|
|
145
|
+
opInFlight = task;
|
|
146
|
+
return task;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// Automatically provision ACP, custom_agents.json, and agentdeckd in the
|
|
150
|
+
// background when the plugin activates so the QR code is ready without clicks.
|
|
151
|
+
ctx.effect(() => {
|
|
152
|
+
disposed = false;
|
|
153
|
+
startAutoProvision().catch(() => {
|
|
154
|
+
// Error is captured in `provisioning` and surfaced in the Settings UI
|
|
155
|
+
});
|
|
156
|
+
return () => {
|
|
157
|
+
disposed = true;
|
|
158
|
+
};
|
|
159
|
+
}, 'agentdeck: auto-provision');
|
|
104
160
|
|
|
105
161
|
const isRejected = (req, res) => {
|
|
106
162
|
const connection = ctx.get?.('connection') ?? Reflect.get(ctx, 'connection');
|
|
@@ -111,6 +167,12 @@ export function apply(ctx) {
|
|
|
111
167
|
return true;
|
|
112
168
|
};
|
|
113
169
|
|
|
170
|
+
const buildStatusPayload = async () => {
|
|
171
|
+
const info = getProfileInfo(ctx);
|
|
172
|
+
const status = await getAgentDeckStatus(info);
|
|
173
|
+
return { ...status, provisioning };
|
|
174
|
+
};
|
|
175
|
+
|
|
114
176
|
ctx.effect(
|
|
115
177
|
() =>
|
|
116
178
|
ctx.webServer.register({
|
|
@@ -123,9 +185,7 @@ export function apply(ctx) {
|
|
|
123
185
|
return;
|
|
124
186
|
}
|
|
125
187
|
try {
|
|
126
|
-
|
|
127
|
-
const status = await getAgentDeckStatus(info);
|
|
128
|
-
sendJson(res, 200, status);
|
|
188
|
+
sendJson(res, 200, await buildStatusPayload());
|
|
129
189
|
} catch (err) {
|
|
130
190
|
sendJson(res, 500, {
|
|
131
191
|
ok: false,
|
|
@@ -137,6 +197,7 @@ export function apply(ctx) {
|
|
|
137
197
|
`agentdeck: GET ${STATUS_PATH}`,
|
|
138
198
|
);
|
|
139
199
|
|
|
200
|
+
// Retry/repair endpoint if auto-provisioning failed or user wants to re-run
|
|
140
201
|
ctx.effect(
|
|
141
202
|
() =>
|
|
142
203
|
ctx.webServer.register({
|
|
@@ -152,29 +213,25 @@ export function apply(ctx) {
|
|
|
152
213
|
if (parsed === null) return;
|
|
153
214
|
|
|
154
215
|
if (opInFlight) {
|
|
155
|
-
sendJson(res,
|
|
156
|
-
ok:
|
|
157
|
-
|
|
216
|
+
sendJson(res, 202, {
|
|
217
|
+
ok: true,
|
|
218
|
+
status: await buildStatusPayload(),
|
|
158
219
|
});
|
|
159
220
|
return;
|
|
160
221
|
}
|
|
161
222
|
|
|
162
|
-
const info = getProfileInfo(ctx);
|
|
163
|
-
const task = runAgentDeckSetup({
|
|
164
|
-
...info,
|
|
165
|
-
syncModels: Boolean(parsed?.syncModels),
|
|
166
|
-
});
|
|
167
|
-
opInFlight = task;
|
|
168
223
|
try {
|
|
169
|
-
const result = await
|
|
170
|
-
sendJson(res, 200,
|
|
224
|
+
const result = await startAutoProvision({ forceStartDaemon: true });
|
|
225
|
+
sendJson(res, 200, {
|
|
226
|
+
ok: true,
|
|
227
|
+
status: { ...result.status, provisioning },
|
|
228
|
+
});
|
|
171
229
|
} catch (err) {
|
|
172
230
|
sendJson(res, 500, {
|
|
173
231
|
ok: false,
|
|
174
232
|
error: err instanceof Error ? err.message : String(err),
|
|
233
|
+
status: await buildStatusPayload(),
|
|
175
234
|
});
|
|
176
|
-
} finally {
|
|
177
|
-
if (opInFlight === task) opInFlight = null;
|
|
178
235
|
}
|
|
179
236
|
},
|
|
180
237
|
}),
|
|
@@ -217,7 +274,10 @@ export function apply(ctx) {
|
|
|
217
274
|
opInFlight = task;
|
|
218
275
|
try {
|
|
219
276
|
const result = await task;
|
|
220
|
-
sendJson(res, 200,
|
|
277
|
+
sendJson(res, 200, {
|
|
278
|
+
ok: true,
|
|
279
|
+
status: { ...result.status, provisioning },
|
|
280
|
+
});
|
|
221
281
|
} catch (err) {
|
|
222
282
|
sendJson(res, 500, {
|
|
223
283
|
ok: false,
|
|
@@ -230,4 +290,77 @@ export function apply(ctx) {
|
|
|
230
290
|
}),
|
|
231
291
|
`agentdeck: POST ${DAEMON_PATH}`,
|
|
232
292
|
);
|
|
293
|
+
|
|
294
|
+
ctx.effect(
|
|
295
|
+
() =>
|
|
296
|
+
ctx.webServer.register({
|
|
297
|
+
kind: 'exact',
|
|
298
|
+
path: AWAKE_PATH,
|
|
299
|
+
handler: async (req, res) => {
|
|
300
|
+
if (isRejected(req, res)) return;
|
|
301
|
+
if (req.method !== 'POST') {
|
|
302
|
+
sendMethodNotAllowed(res, 'POST');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const parsed = await parseJsonRequest(req, res);
|
|
306
|
+
if (parsed === null) return;
|
|
307
|
+
|
|
308
|
+
const mode = parsed?.mode;
|
|
309
|
+
if (!AWAKE_MODES.includes(mode)) {
|
|
310
|
+
sendJson(res, 400, {
|
|
311
|
+
ok: false,
|
|
312
|
+
error: `mode must be one of: ${AWAKE_MODES.join(', ')}`,
|
|
313
|
+
});
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
try {
|
|
318
|
+
const info = getProfileInfo(ctx);
|
|
319
|
+
const result = await setAgentDeckAwake({ ...info, mode });
|
|
320
|
+
sendJson(res, 200, {
|
|
321
|
+
ok: true,
|
|
322
|
+
status: { ...result.status, provisioning },
|
|
323
|
+
});
|
|
324
|
+
} catch (err) {
|
|
325
|
+
sendJson(res, 500, {
|
|
326
|
+
ok: false,
|
|
327
|
+
error: err instanceof Error ? err.message : String(err),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
}),
|
|
332
|
+
`agentdeck: POST ${AWAKE_PATH}`,
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
ctx.effect(
|
|
336
|
+
() =>
|
|
337
|
+
ctx.webServer.register({
|
|
338
|
+
kind: 'exact',
|
|
339
|
+
path: SYNC_MODELS_PATH,
|
|
340
|
+
handler: async (req, res) => {
|
|
341
|
+
if (isRejected(req, res)) return;
|
|
342
|
+
if (req.method !== 'POST') {
|
|
343
|
+
sendMethodNotAllowed(res, 'POST');
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const parsed = await parseJsonRequest(req, res);
|
|
347
|
+
if (parsed === null) return;
|
|
348
|
+
|
|
349
|
+
try {
|
|
350
|
+
const info = getProfileInfo(ctx);
|
|
351
|
+
const result = await syncAgentDeckModels(info);
|
|
352
|
+
sendJson(res, 200, {
|
|
353
|
+
ok: true,
|
|
354
|
+
status: { ...result.status, provisioning },
|
|
355
|
+
});
|
|
356
|
+
} catch (err) {
|
|
357
|
+
sendJson(res, 500, {
|
|
358
|
+
ok: false,
|
|
359
|
+
error: err instanceof Error ? err.message : String(err),
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
}),
|
|
364
|
+
`agentdeck: POST ${SYNC_MODELS_PATH}`,
|
|
365
|
+
);
|
|
233
366
|
}
|
package/lib/setup.js
CHANGED
|
@@ -5,7 +5,10 @@ import {
|
|
|
5
5
|
existsSync,
|
|
6
6
|
mkdirSync,
|
|
7
7
|
readFileSync,
|
|
8
|
+
chmodSync,
|
|
8
9
|
renameSync,
|
|
10
|
+
statSync,
|
|
11
|
+
unlinkSync,
|
|
9
12
|
writeFileSync,
|
|
10
13
|
} from 'node:fs';
|
|
11
14
|
import { arch, homedir } from 'node:os';
|
|
@@ -21,6 +24,7 @@ export const ACP_PLUGIN_PACKAGES = [
|
|
|
21
24
|
'@cnctem/dsh-acp',
|
|
22
25
|
];
|
|
23
26
|
export const DEFAULT_ACP_PLUGIN = '@openma/deepseek-harness-acp@latest';
|
|
27
|
+
export const AWAKE_MODES = ['never', 'plugged', 'active', 'always'];
|
|
24
28
|
|
|
25
29
|
const BUILTIN_DEEPSEEK_PROVIDERS = new Set([
|
|
26
30
|
'deepseek-official',
|
|
@@ -112,14 +116,17 @@ export function findExecutable(
|
|
|
112
116
|
? [`${name}.exe`, `${name}.cmd`, `${name}.bat`, name]
|
|
113
117
|
: [name];
|
|
114
118
|
const pathDirs = (env.PATH || '').split(delimiter).filter(Boolean);
|
|
119
|
+
const nodeBinDir = dirname(process.execPath);
|
|
115
120
|
const fallbackDirs =
|
|
116
121
|
platform === 'win32'
|
|
117
122
|
? [
|
|
123
|
+
nodeBinDir,
|
|
118
124
|
join(home, 'scoop', 'shims'),
|
|
119
125
|
join(env.APPDATA || join(home, 'AppData', 'Roaming'), 'npm'),
|
|
120
126
|
join(home, '.cargo', 'bin'),
|
|
121
127
|
]
|
|
122
128
|
: [
|
|
129
|
+
nodeBinDir,
|
|
123
130
|
join(home, '.local', 'bin'),
|
|
124
131
|
'/opt/homebrew/bin',
|
|
125
132
|
'/usr/local/bin',
|
|
@@ -158,8 +165,9 @@ export function findAgentDeckDaemon({
|
|
|
158
165
|
platform = process.platform,
|
|
159
166
|
env = process.env,
|
|
160
167
|
home = homedir(),
|
|
168
|
+
extraDirs = [],
|
|
161
169
|
} = {}) {
|
|
162
|
-
const onPath = findExecutable('agentdeckd', { platform, env, home });
|
|
170
|
+
const onPath = findExecutable('agentdeckd', { platform, env, home, extraDirs });
|
|
163
171
|
if (onPath) return onPath;
|
|
164
172
|
|
|
165
173
|
const cliDir = join(dataDir, 'cli');
|
|
@@ -261,6 +269,7 @@ export async function readDaemonState(
|
|
|
261
269
|
let relayId = null;
|
|
262
270
|
let relayUrl = DEFAULT_RELAY_URL;
|
|
263
271
|
let hasCustomRelay = false;
|
|
272
|
+
let awakeMode = 'never';
|
|
264
273
|
if (existsSync(configPath)) {
|
|
265
274
|
try {
|
|
266
275
|
const raw = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
@@ -275,11 +284,29 @@ export async function readDaemonState(
|
|
|
275
284
|
relayUrl = raw.relay_url.trim();
|
|
276
285
|
hasCustomRelay = relayUrl !== DEFAULT_RELAY_URL;
|
|
277
286
|
}
|
|
287
|
+
if (typeof raw?.awake === 'string' && AWAKE_MODES.includes(raw.awake)) {
|
|
288
|
+
awakeMode = raw.awake;
|
|
289
|
+
}
|
|
278
290
|
} catch {
|
|
279
291
|
// Ignore corrupt daemon.json
|
|
280
292
|
}
|
|
281
293
|
}
|
|
282
294
|
|
|
295
|
+
const awakeStatusPath = join(dataDir, 'awake_status.json');
|
|
296
|
+
let awakeActive = false;
|
|
297
|
+
let awakeError = null;
|
|
298
|
+
if (running && existsSync(awakeStatusPath)) {
|
|
299
|
+
try {
|
|
300
|
+
const st = JSON.parse(readFileSync(awakeStatusPath, 'utf8'));
|
|
301
|
+
if (st?.pid === pid && st?.mode === awakeMode) {
|
|
302
|
+
awakeActive = Boolean(st.on);
|
|
303
|
+
awakeError = typeof st.error === 'string' ? st.error : null;
|
|
304
|
+
}
|
|
305
|
+
} catch {
|
|
306
|
+
// Ignore unreadable awake_status.json
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
283
310
|
let qrSvg = null;
|
|
284
311
|
let maskedPairingId = null;
|
|
285
312
|
if (relayId) {
|
|
@@ -301,6 +328,11 @@ export async function readDaemonState(
|
|
|
301
328
|
relayUrl,
|
|
302
329
|
hasCustomRelay,
|
|
303
330
|
qrSvg,
|
|
331
|
+
awake: {
|
|
332
|
+
mode: awakeMode,
|
|
333
|
+
active: awakeActive,
|
|
334
|
+
error: awakeError,
|
|
335
|
+
},
|
|
304
336
|
};
|
|
305
337
|
}
|
|
306
338
|
|
|
@@ -429,11 +461,38 @@ export function extractModelSummary(patchPath) {
|
|
|
429
461
|
}
|
|
430
462
|
}
|
|
431
463
|
|
|
432
|
-
function writeFileAtomic(filePath, content) {
|
|
464
|
+
function writeFileAtomic(filePath, content, { mode } = {}) {
|
|
433
465
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
466
|
+
let targetMode = mode;
|
|
467
|
+
if (targetMode === undefined && existsSync(filePath)) {
|
|
468
|
+
try {
|
|
469
|
+
targetMode = statSync(filePath).mode & 0o777;
|
|
470
|
+
} catch {
|
|
471
|
+
// Fall back to default umask
|
|
472
|
+
}
|
|
473
|
+
}
|
|
434
474
|
const tmpPath = `${filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
435
|
-
|
|
436
|
-
|
|
475
|
+
try {
|
|
476
|
+
writeFileSync(tmpPath, content, {
|
|
477
|
+
encoding: 'utf8',
|
|
478
|
+
...(targetMode !== undefined ? { mode: targetMode } : {}),
|
|
479
|
+
});
|
|
480
|
+
if (targetMode !== undefined && process.platform !== 'win32') {
|
|
481
|
+
try {
|
|
482
|
+
chmodSync(tmpPath, targetMode);
|
|
483
|
+
} catch {
|
|
484
|
+
// Ignore chmod failure on unsupported filesystems
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
renameSync(tmpPath, filePath);
|
|
488
|
+
} catch (err) {
|
|
489
|
+
try {
|
|
490
|
+
unlinkSync(tmpPath);
|
|
491
|
+
} catch {
|
|
492
|
+
// Ignore cleanup failure
|
|
493
|
+
}
|
|
494
|
+
throw err;
|
|
495
|
+
}
|
|
437
496
|
}
|
|
438
497
|
|
|
439
498
|
/**
|
|
@@ -603,11 +662,14 @@ function runCommand(
|
|
|
603
662
|
{ cwd, env = process.env, timeoutMs = 180_000 } = {},
|
|
604
663
|
) {
|
|
605
664
|
return new Promise((resolvePromise, reject) => {
|
|
665
|
+
const needsWindowsShell =
|
|
666
|
+
process.platform === 'win32' && /\.(cmd|bat)$/i.test(command);
|
|
606
667
|
const child = spawn(command, args, {
|
|
607
668
|
cwd,
|
|
608
669
|
env,
|
|
609
670
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
610
671
|
windowsHide: true,
|
|
672
|
+
shell: needsWindowsShell,
|
|
611
673
|
});
|
|
612
674
|
let stdout = '';
|
|
613
675
|
let stderr = '';
|
|
@@ -699,7 +761,26 @@ export async function installAgentDeckDaemon({
|
|
|
699
761
|
{ env, timeoutMs: 180_000 },
|
|
700
762
|
);
|
|
701
763
|
if (res.code === 0) {
|
|
702
|
-
const
|
|
764
|
+
const npmExtraDirs = [dirname(npmBin)];
|
|
765
|
+
try {
|
|
766
|
+
const prefixRes = await runCommand(npmBin, ['prefix', '-g'], {
|
|
767
|
+
env,
|
|
768
|
+
timeoutMs: 15_000,
|
|
769
|
+
});
|
|
770
|
+
const prefix = prefixRes.code === 0 ? prefixRes.stdout.trim() : '';
|
|
771
|
+
if (prefix) {
|
|
772
|
+
npmExtraDirs.push(platform === 'win32' ? prefix : join(prefix, 'bin'));
|
|
773
|
+
}
|
|
774
|
+
} catch {
|
|
775
|
+
// Ignore prefix lookup failure
|
|
776
|
+
}
|
|
777
|
+
const bin = findAgentDeckDaemon({
|
|
778
|
+
dataDir,
|
|
779
|
+
platform,
|
|
780
|
+
env,
|
|
781
|
+
home,
|
|
782
|
+
extraDirs: npmExtraDirs,
|
|
783
|
+
});
|
|
703
784
|
if (bin) return { installed: true, method: 'npm-global', binaryPath: bin };
|
|
704
785
|
}
|
|
705
786
|
errors.push(
|
|
@@ -922,6 +1003,7 @@ export async function runAgentDeckSetup({
|
|
|
922
1003
|
sourcePatchPath = null,
|
|
923
1004
|
dataDir = getAgentDeckDataDir(),
|
|
924
1005
|
syncModels = false,
|
|
1006
|
+
startDaemon = true,
|
|
925
1007
|
platform = process.platform,
|
|
926
1008
|
packageManager = null,
|
|
927
1009
|
} = {}) {
|
|
@@ -1020,6 +1102,13 @@ export async function runAgentDeckSetup({
|
|
|
1020
1102
|
}
|
|
1021
1103
|
|
|
1022
1104
|
// Step 5: Register autostart service & start `agentdeckd`
|
|
1105
|
+
if (!startDaemon) {
|
|
1106
|
+
steps.push({
|
|
1107
|
+
id: 'agentdeckd-autostart',
|
|
1108
|
+
status: 'skipped',
|
|
1109
|
+
detail: 'stopped by user',
|
|
1110
|
+
});
|
|
1111
|
+
} else {
|
|
1023
1112
|
const startRes = await runCommand(daemonBin, ['start'], {
|
|
1024
1113
|
timeoutMs: 30_000,
|
|
1025
1114
|
});
|
|
@@ -1039,6 +1128,7 @@ export async function runAgentDeckSetup({
|
|
|
1039
1128
|
status: 'started',
|
|
1040
1129
|
detail: 'autostart enabled',
|
|
1041
1130
|
});
|
|
1131
|
+
}
|
|
1042
1132
|
}
|
|
1043
1133
|
|
|
1044
1134
|
const status = await getAgentDeckStatus({
|
|
@@ -1051,3 +1141,83 @@ export async function runAgentDeckSetup({
|
|
|
1051
1141
|
|
|
1052
1142
|
return { ok: true, steps, status };
|
|
1053
1143
|
}
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* Update `daemon.json` `awake` mode atomically (preserving `relay_id`, `relay_url`,
|
|
1147
|
+
* and `features`). A running `agentdeckd` automatically hot-reloads this setting.
|
|
1148
|
+
*/
|
|
1149
|
+
export async function setAgentDeckAwake({
|
|
1150
|
+
mode,
|
|
1151
|
+
profileName = 'web',
|
|
1152
|
+
dshHome = join(homedir(), '.dsh'),
|
|
1153
|
+
sourcePatchPath = null,
|
|
1154
|
+
dataDir = getAgentDeckDataDir(),
|
|
1155
|
+
platform = process.platform,
|
|
1156
|
+
} = {}) {
|
|
1157
|
+
if (!AWAKE_MODES.includes(mode)) {
|
|
1158
|
+
throw new Error(`Invalid awake mode "${mode}". Expected one of: ${AWAKE_MODES.join(', ')}`);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
const configPath = join(dataDir, 'daemon.json');
|
|
1162
|
+
let config = {};
|
|
1163
|
+
if (existsSync(configPath)) {
|
|
1164
|
+
try {
|
|
1165
|
+
const parsed = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
1166
|
+
if (parsed && typeof parsed === 'object') config = parsed;
|
|
1167
|
+
} catch {
|
|
1168
|
+
throw new Error(`Invalid daemon config at ${configPath}`);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
config.awake = mode;
|
|
1172
|
+
writeFileAtomic(configPath, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
1173
|
+
|
|
1174
|
+
// If daemon is running, wait briefly for awake_status.json to reflect the new mode
|
|
1175
|
+
const awakeStatusPath = join(dataDir, 'awake_status.json');
|
|
1176
|
+
const lockPath = join(dataDir, 'daemon.lock');
|
|
1177
|
+
let runningPid = null;
|
|
1178
|
+
if (existsSync(lockPath)) {
|
|
1179
|
+
const p = Number.parseInt(readFileSync(lockPath, 'utf8').trim(), 10);
|
|
1180
|
+
if (isPidAlive(p)) runningPid = p;
|
|
1181
|
+
}
|
|
1182
|
+
if (runningPid) {
|
|
1183
|
+
for (let i = 0; i < 12; i++) {
|
|
1184
|
+
if (existsSync(awakeStatusPath)) {
|
|
1185
|
+
try {
|
|
1186
|
+
const st = JSON.parse(readFileSync(awakeStatusPath, 'utf8'));
|
|
1187
|
+
if (st?.pid === runningPid && st?.mode === mode) break;
|
|
1188
|
+
} catch {
|
|
1189
|
+
// Ignore transient read
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
await sleep(100);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
const status = await getAgentDeckStatus({
|
|
1197
|
+
profileName,
|
|
1198
|
+
dshHome,
|
|
1199
|
+
sourcePatchPath,
|
|
1200
|
+
dataDir,
|
|
1201
|
+
platform,
|
|
1202
|
+
});
|
|
1203
|
+
return { ok: true, mode, status };
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
export async function syncAgentDeckModels({
|
|
1207
|
+
profileName = 'web',
|
|
1208
|
+
dshHome = join(homedir(), '.dsh'),
|
|
1209
|
+
sourcePatchPath = null,
|
|
1210
|
+
dataDir = getAgentDeckDataDir(),
|
|
1211
|
+
platform = process.platform,
|
|
1212
|
+
} = {}) {
|
|
1213
|
+
const acpPatchPath = join(dshHome, 'profiles', 'acp', 'cordis.patch.yml');
|
|
1214
|
+
syncAcpPatch({ sourcePatchPath, acpPatchPath, syncModels: true });
|
|
1215
|
+
const status = await getAgentDeckStatus({
|
|
1216
|
+
profileName,
|
|
1217
|
+
dshHome,
|
|
1218
|
+
sourcePatchPath,
|
|
1219
|
+
dataDir,
|
|
1220
|
+
platform,
|
|
1221
|
+
});
|
|
1222
|
+
return { ok: true, status };
|
|
1223
|
+
}
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "AgentDeck Mobile Remote",
|
|
4
|
-
"description": "Control DeepSeek Harness from your iPhone or Android via AgentDeck —
|
|
4
|
+
"description": "Control DeepSeek Harness from your iPhone or Android via AgentDeck — installs and starts automatically, just scan the QR code in Settings."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-agentdeck",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "AgentDeck mobile remote control plugin for DeepSeek Harness (dsh) —
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Zero-config AgentDeck mobile remote control plugin for DeepSeek Harness (dsh) — auto-installs ACP & agentdeckd with autostart, shows pairing QR & keep-awake controls in Settings",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "mantou132",
|
|
7
7
|
"homepage": "https://agentdeck.xianqiao.wang",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"platform": "web",
|
|
54
54
|
"inject": [
|
|
55
55
|
"@deepseek-ai/dsh-client-locale",
|
|
56
|
-
"@deepseek-ai/dsh-client-ui-
|
|
56
|
+
"@deepseek-ai/dsh-client-ui-slots",
|
|
57
57
|
"@deepseek-ai/dsh-client-ui-settings-general"
|
|
58
58
|
]
|
|
59
59
|
}
|
|
@@ -64,5 +64,8 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"qrcode": "^1.5.4",
|
|
66
66
|
"yaml": "^2.7.0"
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public"
|
|
67
70
|
}
|
|
68
71
|
}
|