@livedesk/client 0.1.202 → 0.1.204
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/bin/livedesk-client-node.js +70 -190
- package/bin/livedesk-client.js +71 -31
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -62,9 +62,9 @@ System Settings path when access is missing; after granting access, restart the
|
|
|
62
62
|
client. When file transfer is enabled by the Hub, received files are saved
|
|
63
63
|
to `Desktop/LiveDeskFiles` unless the Hub sets another destination folder.
|
|
64
64
|
|
|
65
|
-
By default, the launcher uses the packaged C# RemoteFast engine when supported.
|
|
66
|
-
It falls back to the Node engine
|
|
67
|
-
|
|
65
|
+
By default, the launcher uses the packaged C# RemoteFast engine when supported.
|
|
66
|
+
It falls back to the Node engine only when a compatible RemoteFast runtime is
|
|
67
|
+
unavailable. Windows, macOS, and Linux all try RemoteFast first so
|
|
68
68
|
the Hub can request the Mode 3 hardware video path when it is available.
|
|
69
69
|
RemoteFast is shipped as a platform-specific self-contained .NET executable,
|
|
70
70
|
so client computers do not need a separate .NET installation.
|
|
@@ -19,15 +19,13 @@ const AGENT_VERSION = (() => {
|
|
|
19
19
|
const PRODUCT_VERSION = String(process.env.LIVEDESK_NPM_LAUNCHER_VERSION || AGENT_VERSION).trim() || AGENT_VERSION;
|
|
20
20
|
const DEFAULT_MANAGER = '127.0.0.1:5197';
|
|
21
21
|
const DEFAULT_HEARTBEAT_MS = 5000;
|
|
22
|
-
const DEFAULT_RECONNECT_MS = 5000;
|
|
23
|
-
const EXIT_INVALID_PAIR_TOKEN = 23;
|
|
24
|
-
const EXIT_CLIENT_UPDATE = 42;
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const MAX_AI_OUTPUT_CHARS = 6000;
|
|
30
|
-
const MAX_FILE_TRANSFER_FILES = 24;
|
|
22
|
+
const DEFAULT_RECONNECT_MS = 5000;
|
|
23
|
+
const EXIT_INVALID_PAIR_TOKEN = 23;
|
|
24
|
+
const EXIT_CLIENT_UPDATE = 42;
|
|
25
|
+
const DEFAULT_LIVE_FPS = 30;
|
|
26
|
+
const MAX_LIVE_FPS = 30;
|
|
27
|
+
const MAX_FRAME_BASE64_CHARS = 3 * 1024 * 1024;
|
|
28
|
+
const MAX_FILE_TRANSFER_FILES = 24;
|
|
31
29
|
const MAX_FILE_TRANSFER_BYTES = 24 * 1024 * 1024;
|
|
32
30
|
const MAX_AGENT_OUTPUT_CHARS = 32000;
|
|
33
31
|
const launchedProcessRegistry = new Map();
|
|
@@ -281,14 +279,10 @@ Options:
|
|
|
281
279
|
--no-thumbnail Disable thumbnail capture capability.
|
|
282
280
|
--live Enable focused live screen streaming. Default on.
|
|
283
281
|
--no-live Disable focused live screen streaming.
|
|
284
|
-
--tasks Enable safe remote task inbox. Default on.
|
|
285
|
-
--no-tasks Disable remote task dispatch capability.
|
|
286
|
-
--files-dir <path> Default folder for received files. Default: ~/Desktop/LiveDeskFiles.
|
|
287
|
-
--
|
|
288
|
-
--no-ai Disable OpenAI-backed remote AI assist tasks.
|
|
289
|
-
--ai-model <model> OpenAI model for AI assist. Default: ${DEFAULT_AI_MODEL}
|
|
290
|
-
--fake-ai Use deterministic AI assist responses for smoke tests.
|
|
291
|
-
--fake-thumbnail Use generated thumbnail frames for smoke tests.
|
|
282
|
+
--tasks Enable safe remote task inbox. Default on.
|
|
283
|
+
--no-tasks Disable remote task dispatch capability.
|
|
284
|
+
--files-dir <path> Default folder for received files. Default: ~/Desktop/LiveDeskFiles.
|
|
285
|
+
--fake-thumbnail Use generated thumbnail frames for smoke tests.
|
|
292
286
|
--exit-on-disconnect Exit after Hub disconnect. Useful for tests.
|
|
293
287
|
--exit-on-invalid-pair Exit when the Hub rejects the pair token.
|
|
294
288
|
--once Connect, send one status packet, and exit after welcome.
|
|
@@ -328,14 +322,10 @@ function parseArgs(argv) {
|
|
|
328
322
|
heartbeatMs: DEFAULT_HEARTBEAT_MS,
|
|
329
323
|
deviceId: '',
|
|
330
324
|
thumbnailEnabled: defaultDesktopCaptureEnabled && !isFalsy(process.env.LIVEDESK_CLIENT_THUMBNAIL ?? process.env.MINDEXEC_REMOTE_THUMBNAIL),
|
|
331
|
-
liveEnabled: defaultDesktopCaptureEnabled && !isFalsy(process.env.LIVEDESK_CLIENT_LIVE ?? process.env.MINDEXEC_REMOTE_LIVE),
|
|
332
|
-
taskEnabled: !isFalsy(process.env.LIVEDESK_CLIENT_TASKS ?? process.env.MINDEXEC_REMOTE_TASKS),
|
|
333
|
-
filesDir: process.env.LIVEDESK_CLIENT_FILES_DIR || process.env.MINDEXEC_REMOTE_FILES_DIR || '',
|
|
334
|
-
|
|
335
|
-
aiModel: process.env.LIVEDESK_CLIENT_AI_MODEL || process.env.MINDEXEC_REMOTE_AI_MODEL || process.env.OPENAI_MODEL || DEFAULT_AI_MODEL,
|
|
336
|
-
openAiApiKey: process.env.OPENAI_API_KEY || '',
|
|
337
|
-
fakeAi: isTruthy(process.env.LIVEDESK_CLIENT_FAKE_AI || process.env.MINDEXEC_REMOTE_FAKE_AI),
|
|
338
|
-
fakeThumbnail: isTruthy(process.env.LIVEDESK_CLIENT_FAKE_THUMBNAIL || process.env.MINDEXEC_REMOTE_FAKE_THUMBNAIL),
|
|
325
|
+
liveEnabled: defaultDesktopCaptureEnabled && !isFalsy(process.env.LIVEDESK_CLIENT_LIVE ?? process.env.MINDEXEC_REMOTE_LIVE),
|
|
326
|
+
taskEnabled: !isFalsy(process.env.LIVEDESK_CLIENT_TASKS ?? process.env.MINDEXEC_REMOTE_TASKS),
|
|
327
|
+
filesDir: process.env.LIVEDESK_CLIENT_FILES_DIR || process.env.MINDEXEC_REMOTE_FILES_DIR || '',
|
|
328
|
+
fakeThumbnail: isTruthy(process.env.LIVEDESK_CLIENT_FAKE_THUMBNAIL || process.env.MINDEXEC_REMOTE_FAKE_THUMBNAIL),
|
|
339
329
|
exitOnDisconnect: false,
|
|
340
330
|
exitOnInvalidPair: false,
|
|
341
331
|
once: false,
|
|
@@ -387,26 +377,11 @@ function parseArgs(argv) {
|
|
|
387
377
|
case '--no-tasks':
|
|
388
378
|
result.taskEnabled = false;
|
|
389
379
|
break;
|
|
390
|
-
case '--files-dir':
|
|
391
|
-
result.filesDir = args[++index] || result.filesDir;
|
|
392
|
-
break;
|
|
393
|
-
case '--
|
|
394
|
-
result.
|
|
395
|
-
result.taskEnabled = true;
|
|
396
|
-
break;
|
|
397
|
-
case '--no-ai':
|
|
398
|
-
result.aiEnabled = false;
|
|
399
|
-
break;
|
|
400
|
-
case '--ai-model':
|
|
401
|
-
result.aiModel = args[++index] || result.aiModel;
|
|
402
|
-
break;
|
|
403
|
-
case '--fake-ai':
|
|
404
|
-
result.fakeAi = true;
|
|
405
|
-
result.aiEnabled = true;
|
|
406
|
-
result.taskEnabled = true;
|
|
407
|
-
break;
|
|
408
|
-
case '--fake-thumbnail':
|
|
409
|
-
result.fakeThumbnail = true;
|
|
380
|
+
case '--files-dir':
|
|
381
|
+
result.filesDir = args[++index] || result.filesDir;
|
|
382
|
+
break;
|
|
383
|
+
case '--fake-thumbnail':
|
|
384
|
+
result.fakeThumbnail = true;
|
|
410
385
|
result.thumbnailEnabled = true;
|
|
411
386
|
break;
|
|
412
387
|
case '--exit-on-disconnect':
|
|
@@ -586,7 +561,7 @@ function getStatus(options = {}) {
|
|
|
586
561
|
usedMemRatio,
|
|
587
562
|
platform: os.platform(),
|
|
588
563
|
release: os.release(),
|
|
589
|
-
role: options.
|
|
564
|
+
role: options.taskEnabled ? 'Command-ready Client' : 'Local machine',
|
|
590
565
|
cpu: {
|
|
591
566
|
cores: cpuCores,
|
|
592
567
|
model: cpus[0]?.model || '',
|
|
@@ -609,9 +584,9 @@ function getStatus(options = {}) {
|
|
|
609
584
|
gpu: acceleratorStatus.gpu,
|
|
610
585
|
npu: acceleratorStatus.npu,
|
|
611
586
|
network: getNetworkStatus(),
|
|
612
|
-
workload: {
|
|
613
|
-
role: options.
|
|
614
|
-
status: 'idle',
|
|
587
|
+
workload: {
|
|
588
|
+
role: options.taskEnabled ? 'Command-ready Client' : 'Local machine',
|
|
589
|
+
status: 'idle',
|
|
615
590
|
title: 'idle'
|
|
616
591
|
},
|
|
617
592
|
timestamp: new Date().toISOString()
|
|
@@ -941,95 +916,17 @@ async function captureThumbnailFrame(options, payload, frameSeq) {
|
|
|
941
916
|
return await captureScreenFrame(options, payload, frameSeq, 'thumbnail');
|
|
942
917
|
}
|
|
943
918
|
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
return
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
'If the task requires external side effects, explain what would be needed and stop.',
|
|
956
|
-
'',
|
|
957
|
-
`Device: ${options.name} (${os.hostname()}, ${os.platform()} ${os.release()}, ${os.arch()})`,
|
|
958
|
-
`Task title: ${title}`,
|
|
959
|
-
'',
|
|
960
|
-
'Hub instruction:',
|
|
961
|
-
instruction
|
|
962
|
-
].join('\n');
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
function extractResponseText(response) {
|
|
966
|
-
if (typeof response?.output_text === 'string' && response.output_text.trim()) {
|
|
967
|
-
return response.output_text.trim();
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
const parts = [];
|
|
971
|
-
if (Array.isArray(response?.output)) {
|
|
972
|
-
for (const item of response.output) {
|
|
973
|
-
if (!Array.isArray(item?.content)) {
|
|
974
|
-
continue;
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
for (const content of item.content) {
|
|
978
|
-
if (typeof content?.text === 'string') {
|
|
979
|
-
parts.push(content.text);
|
|
980
|
-
}
|
|
981
|
-
if (typeof content?.output_text === 'string') {
|
|
982
|
-
parts.push(content.output_text);
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
return parts.join('\n').trim();
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
async function runAiAssistTask(options, payload, instruction) {
|
|
992
|
-
if (!options.aiEnabled) {
|
|
993
|
-
throw new Error('AI assist capability is disabled. Start the agent with --ai to enable it.');
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
if (options.fakeAi) {
|
|
997
|
-
return {
|
|
998
|
-
text: [
|
|
999
|
-
`Fake AI assist completed on ${options.name}.`,
|
|
1000
|
-
'',
|
|
1001
|
-
`Instruction: ${instruction.slice(0, 500)}`,
|
|
1002
|
-
'',
|
|
1003
|
-
'No shell, file, input, browser, or persistent side effects were performed.'
|
|
1004
|
-
].join('\n'),
|
|
1005
|
-
model: 'fake-ai',
|
|
1006
|
-
responseId: `fake-ai-${String(payload?.taskId || crypto.randomUUID()).slice(0, 96)}`
|
|
1007
|
-
};
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
if (!options.openAiApiKey) {
|
|
1011
|
-
throw new Error('OPENAI_API_KEY is required for --ai remote tasks.');
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
const openaiModule = await import('openai');
|
|
1015
|
-
const OpenAI = openaiModule.default || openaiModule.OpenAI;
|
|
1016
|
-
const client = new OpenAI({ apiKey: options.openAiApiKey });
|
|
1017
|
-
const model = String(payload?.model || options.aiModel || DEFAULT_AI_MODEL).trim() || DEFAULT_AI_MODEL;
|
|
1018
|
-
const response = await client.responses.create({
|
|
1019
|
-
model,
|
|
1020
|
-
input: buildAiPrompt(options, payload, instruction)
|
|
1021
|
-
});
|
|
1022
|
-
const text = extractResponseText(response);
|
|
1023
|
-
if (!text) {
|
|
1024
|
-
throw new Error('AI assist returned no text output.');
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
return {
|
|
1028
|
-
text: text.slice(0, MAX_AI_OUTPUT_CHARS),
|
|
1029
|
-
model,
|
|
1030
|
-
responseId: response?.id || ''
|
|
1031
|
-
};
|
|
1032
|
-
}
|
|
919
|
+
const RETIRED_CLIENT_AGENT_TASK_ERROR = 'agent-ai-assist-retired';
|
|
920
|
+
|
|
921
|
+
function getRetiredClientAgentTaskError(payload = {}) {
|
|
922
|
+
const source = payload && typeof payload === 'object' ? payload : {};
|
|
923
|
+
const approvalLevel = String(source.approvalLevel || '').trim().toLowerCase();
|
|
924
|
+
const hasModelSelection = ['model', 'aiModel', 'aiProvider', 'provider']
|
|
925
|
+
.some(key => Object.prototype.hasOwnProperty.call(source, key));
|
|
926
|
+
return approvalLevel === 'ai-assist' || hasModelSelection
|
|
927
|
+
? RETIRED_CLIENT_AGENT_TASK_ERROR
|
|
928
|
+
: '';
|
|
929
|
+
}
|
|
1033
930
|
|
|
1034
931
|
function clampInteger(value, min, max, fallback) {
|
|
1035
932
|
const number = Number(value);
|
|
@@ -1571,15 +1468,16 @@ function buildClientUpdateBootstrapScript() {
|
|
|
1571
1468
|
'const isGroupAlive = pid => { try { process.kill(-pid, 0); return true; } catch (error) { return error?.code === "EPERM"; } };',
|
|
1572
1469
|
'const runWindowsPowerShell = script => new Promise((resolve, reject) => { execFile("powershell.exe", ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script], { windowsHide: true, timeout: 15000, killSignal: "SIGKILL", maxBuffer: 4 * 1024 * 1024 }, (error, stdout, stderr) => { if (error) { reject(new Error(String(stderr || error.message || "PowerShell failed").trim())); return; } resolve(String(stdout || "").trim()); }); });',
|
|
1573
1470
|
'const queryWindowsProcessTable = async () => { const stdout = await runWindowsPowerShell(`$ErrorActionPreference = "Stop"; $records = @(Get-CimInstance Win32_Process -Property ProcessId,ParentProcessId,CreationDate | ForEach-Object { $ticks = if ($_.CreationDate) { [string]$_.CreationDate.ToUniversalTime().Ticks } else { "" }; [pscustomobject]@{ ProcessId = [int]$_.ProcessId; ParentProcessId = [int]$_.ParentProcessId; CreationUtcTicks = $ticks } }); [pscustomobject]@{ Records = $records } | ConvertTo-Json -Compress -Depth 4`); if (!stdout) throw new Error("Windows process snapshot returned no data"); const parsed = JSON.parse(stdout); const values = parsed?.Records == null ? [] : (Array.isArray(parsed.Records) ? parsed.Records : [parsed.Records]); return values.map(item => ({ pid: Number(item?.ProcessId || 0), parentPid: Number(item?.ParentProcessId || 0), startOrder: String(item?.CreationUtcTicks || "") })).filter(item => Number.isInteger(item.pid) && item.pid > 1 && /^\\d+$/.test(item.startOrder)); };',
|
|
1471
|
+
'const queryTrackedWindowsProcessTable = child => { if (child.livedeskWindowsSnapshotPromise) return child.livedeskWindowsSnapshotPromise; const pending = queryWindowsProcessTable(); child.livedeskWindowsSnapshotPromise = pending; const clear = () => { if (child.livedeskWindowsSnapshotPromise === pending) child.livedeskWindowsSnapshotPromise = null; }; pending.then(clear, clear); return pending; };',
|
|
1574
1472
|
'const sameWindowsIdentity = (left, right) => Number(left?.pid || 0) === Number(right?.pid || 0) && String(left?.startOrder || "") === String(right?.startOrder || "");',
|
|
1575
|
-
'const captureWindowsIdentity = async
|
|
1473
|
+
'const captureWindowsIdentity = async child => { const processId = Number(child?.pid || 0); const deadline = Date.now() + 2500; let lastError = null; do { try { const snapshot = await queryTrackedWindowsProcessTable(child); const identity = snapshot.find(item => item.pid === processId) || null; if (identity) return identity; } catch (error) { lastError = error; } if (Date.now() < deadline) await sleep(50); } while (Date.now() < deadline); throw new Error(`Could not capture immutable Windows CreationDate for pid=${processId}: ${lastError?.message || "process not visible"}`); };',
|
|
1576
1474
|
'const windowsTicksAtMilliseconds = value => BigInt(Math.trunc(Number(value) || Date.now())) * 10000n + 621355968000000000n;',
|
|
1577
1475
|
'const setWindowsRootLifetimeEnd = (child, ticks) => { const candidate = BigInt(ticks); const previous = child.livedeskWindowsRootLifetimeEndTicks; if (!previous || candidate < BigInt(previous)) child.livedeskWindowsRootLifetimeEndTicks = String(candidate); return BigInt(child.livedeskWindowsRootLifetimeEndTicks); };',
|
|
1578
1476
|
'const mergeRootAbsentWindowsTree = (child, rootPid, snapshot) => { const tracked = child.livedeskWindowsTrackedRecords || (child.livedeskWindowsTrackedRecords = new Map()); const currentByPid = new Map(snapshot.map(item => [item.pid, item])); const exactCurrentByPid = new Map(); for (const record of tracked.values()) { const current = currentByPid.get(record.pid); if (sameWindowsIdentity(current, record)) exactCurrentByPid.set(record.pid, record); } const lowerBound = windowsTicksAtMilliseconds(Number(child.livedeskWindowsSpawnedAtMs || Date.now()) - 2000); const upperBound = child.livedeskWindowsRootLifetimeEndTicks ? BigInt(child.livedeskWindowsRootLifetimeEndTicks) : null; let changed = true; while (changed) { changed = false; for (const record of snapshot) { const key = `${record.pid}:${record.startOrder}`; if (record.pid === rootPid || tracked.has(key)) continue; let recordStart; try { recordStart = BigInt(record.startOrder); if (recordStart < lowerBound || (upperBound && recordStart > upperBound)) continue; } catch { continue; } const parent = record.parentPid === rootPid ? { depth: 0 } : exactCurrentByPid.get(record.parentPid); if (!parent) continue; const descendant = { ...record, depth: Number(parent.depth || 0) + 1 }; tracked.set(key, descendant); exactCurrentByPid.set(descendant.pid, descendant); changed = true; } } return tracked; };',
|
|
1579
1477
|
'const mergeExactWindowsTree = (child, root, snapshot) => { const tracked = child.livedeskWindowsTrackedRecords || (child.livedeskWindowsTrackedRecords = new Map()); const currentByPid = new Map(snapshot.map(item => [item.pid, item])); const currentRoot = currentByPid.get(root.pid) || null; const rootIsExact = sameWindowsIdentity(currentRoot, root); const rootWasReused = Boolean(currentRoot && !rootIsExact); if (rootWasReused) setWindowsRootLifetimeEnd(child, BigInt(currentRoot.startOrder) - 1n); else if (!currentRoot && child.livedeskWindowsRootExitedAtMs) setWindowsRootLifetimeEnd(child, windowsTicksAtMilliseconds(child.livedeskWindowsRootExitedAtMs)); const rootLifetimeClosed = Boolean(child.livedeskWindowsRootLifetimeEndTicks); if (rootIsExact) tracked.set(`${root.pid}:${root.startOrder}`, { ...root, depth: 0 }); const exactCurrentByPid = new Map(); if (rootIsExact) exactCurrentByPid.set(root.pid, { ...root, depth: 0 }); for (const record of tracked.values()) { const current = currentByPid.get(record.pid); if (sameWindowsIdentity(current, record)) exactCurrentByPid.set(record.pid, record); } let changed = true; while (changed) { changed = false; for (const record of snapshot) { const key = `${record.pid}:${record.startOrder}`; if (record.pid === root.pid || tracked.has(key)) continue; let recordStart; try { recordStart = BigInt(record.startOrder); if (recordStart < BigInt(root.startOrder)) continue; if (rootLifetimeClosed && recordStart > BigInt(child.livedeskWindowsRootLifetimeEndTicks)) continue; } catch { continue; } let parent = exactCurrentByPid.get(record.parentPid) || null; if (!parent && !currentRoot && rootLifetimeClosed && record.parentPid === root.pid) parent = { ...root, depth: 0 }; if (!parent) continue; const descendant = { ...record, depth: Number(parent.depth || 0) + 1 }; tracked.set(key, descendant); exactCurrentByPid.set(descendant.pid, descendant); changed = true; } } return tracked; };',
|
|
1580
|
-
'const refreshTrackedWindowsTree = async (child, root = child.livedeskWindowsIdentity || null) => { const snapshot = await
|
|
1478
|
+
'const refreshTrackedWindowsTree = async (child, root = child.livedeskWindowsIdentity || null) => { const snapshot = await queryTrackedWindowsProcessTable(child); if (root) mergeExactWindowsTree(child, root, snapshot); else mergeRootAbsentWindowsTree(child, Number(child.pid || 0), snapshot); return snapshot; };',
|
|
1581
1479
|
'const stopExactWindowsRecords = async records => { if (!Array.isArray(records) || records.length === 0) return; const encoded = Buffer.from(JSON.stringify(records.map(record => ({ pid: record.pid, startOrder: record.startOrder }))), "utf8").toString("base64"); const script = `$ErrorActionPreference = "Stop"; $targetsJson = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String("${encoded}")); $targets = ConvertFrom-Json -InputObject $targetsJson; $failures = [System.Collections.Generic.List[string]]::new(); foreach ($item in $targets) { $targetPid = [int]$item.pid; $expectedStartTicks = [string]$item.startOrder; try { $target = Get-CimInstance Win32_Process -Filter "ProcessId = $targetPid" -Property ProcessId,CreationDate -ErrorAction SilentlyContinue | Select-Object -First 1; if (-not $target) { continue }; $targetStartTicks = if ($target.CreationDate) { [string]$target.CreationDate.ToUniversalTime().Ticks } else { "" }; if ($targetStartTicks -ne $expectedStartTicks) { continue }; Stop-Process -Id $targetPid -Force -ErrorAction Stop } catch { $failures.Add("pid=$targetPid $($_.Exception.Message)") } }; if ($failures.Count -gt 0) { [Console]::Error.WriteLine(($failures -join "; ")); exit 1 }`; await runWindowsPowerShell(script); };',
|
|
1582
|
-
'const trackWindowsChild = child => { if (process.platform !== "win32" || Number(child?.pid || 0) <= 1 || child.livedeskWindowsIdentityPromise) return; child.livedeskWindowsTrackedRecords = new Map(); child.livedeskWindowsSpawnedAtMs = Date.now(); child.livedeskWindowsRootExitedAtMs = null; child.livedeskWindowsTrackingStopped = false; child.once("exit", () => { if (!child.livedeskWindowsRootExitedAtMs) child.livedeskWindowsRootExitedAtMs = Date.now(); setWindowsRootLifetimeEnd(child, windowsTicksAtMilliseconds(child.livedeskWindowsRootExitedAtMs)); }); const refresh = () => { void refreshTrackedWindowsTree(child).then(() => { child.livedeskWindowsTrackingError = null; }).catch(error => { child.livedeskWindowsTrackingError = error; }); }; refresh(); child.livedeskWindowsTrackingTimer = setInterval(refresh, 250); child.livedeskWindowsTrackingTimer.unref?.(); child.livedeskWindowsIdentityPromise = (async () => { while (!child.livedeskWindowsTrackingStopped && !child.livedeskWindowsRootExitedAtMs) { try { const identity = await captureWindowsIdentity(child
|
|
1480
|
+
'const trackWindowsChild = child => { if (process.platform !== "win32" || Number(child?.pid || 0) <= 1 || child.livedeskWindowsIdentityPromise) return; child.livedeskWindowsTrackedRecords = new Map(); child.livedeskWindowsSpawnedAtMs = Date.now(); child.livedeskWindowsRootExitedAtMs = null; child.livedeskWindowsTrackingStopped = false; child.once("exit", () => { if (!child.livedeskWindowsRootExitedAtMs) child.livedeskWindowsRootExitedAtMs = Date.now(); setWindowsRootLifetimeEnd(child, windowsTicksAtMilliseconds(child.livedeskWindowsRootExitedAtMs)); }); const refresh = () => { void refreshTrackedWindowsTree(child).then(() => { child.livedeskWindowsTrackingError = null; }).catch(error => { child.livedeskWindowsTrackingError = error; }); }; refresh(); child.livedeskWindowsTrackingTimer = setInterval(refresh, 250); child.livedeskWindowsTrackingTimer.unref?.(); child.livedeskWindowsIdentityPromise = (async () => { while (!child.livedeskWindowsTrackingStopped && !child.livedeskWindowsRootExitedAtMs) { try { const identity = await captureWindowsIdentity(child); child.livedeskWindowsIdentity = identity; refresh(); return identity; } catch (error) { child.livedeskWindowsIdentityError = error; if (!child.livedeskWindowsTrackingStopped && !child.livedeskWindowsRootExitedAtMs) await sleep(250); } } return null; })(); };',
|
|
1583
1481
|
'const stopWindowsTracking = child => { child.livedeskWindowsTrackingStopped = true; if (child?.livedeskWindowsTrackingTimer) clearInterval(child.livedeskWindowsTrackingTimer); child.livedeskWindowsTrackingTimer = null; };',
|
|
1584
1482
|
'const terminateExactWindowsTrackedTree = (child, root) => { if (child.livedeskWindowsDrainPromise) return child.livedeskWindowsDrainPromise; child.livedeskWindowsDrainPromise = (async () => { let attempt = 0; let emptyPasses = 0; for (;;) { attempt += 1; try { const snapshot = await refreshTrackedWindowsTree(child, root); const currentByPid = new Map(snapshot.map(item => [item.pid, item])); const remaining = [...child.livedeskWindowsTrackedRecords.values()].filter(target => sameWindowsIdentity(currentByPid.get(target.pid), target)).sort((left, right) => Number(right.depth || 0) - Number(left.depth || 0)); if (remaining.length === 0) { emptyPasses += 1; if (emptyPasses >= 2) { stopWindowsTracking(child); return; } } else { emptyPasses = 0; await stopExactWindowsRecords(remaining); } child.livedeskWindowsTrackingError = null; } catch (error) { emptyPasses = 0; child.livedeskWindowsTrackingError = error; if (attempt === 1 || attempt % 10 === 0) process.stderr.write(`LiveDesk update cleanup is retrying exact Windows process-tree drain: ${error?.message || error}\\n`); } await sleep(Math.min(1000, 100 + (attempt * 50))); } })(); return child.livedeskWindowsDrainPromise; };',
|
|
1585
1483
|
'const stateLockPath = statePath + ".lock"; const lockWaitBuffer = new Int32Array(new SharedArrayBuffer(4));',
|
|
@@ -1845,10 +1743,25 @@ async function handleRemoteCommand(socket, options, message, nextFrameSeq, activ
|
|
|
1845
1743
|
error: 'remote task capability is disabled'
|
|
1846
1744
|
});
|
|
1847
1745
|
return;
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
const payload = message.payload || {};
|
|
1851
|
-
const
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
const payload = message.payload || {};
|
|
1749
|
+
const retiredTaskError = getRetiredClientAgentTaskError(payload);
|
|
1750
|
+
if (retiredTaskError) {
|
|
1751
|
+
writeJsonLine(socket, {
|
|
1752
|
+
type: 'command.result',
|
|
1753
|
+
commandId: message.commandId,
|
|
1754
|
+
error: retiredTaskError,
|
|
1755
|
+
result: {
|
|
1756
|
+
ok: false,
|
|
1757
|
+
status: 'failed',
|
|
1758
|
+
error: retiredTaskError,
|
|
1759
|
+
completedAt: new Date().toISOString()
|
|
1760
|
+
}
|
|
1761
|
+
});
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
const instruction = String(payload.instruction || '').replace(/\0/g, '').trim().slice(0, 4000);
|
|
1852
1765
|
if (!instruction) {
|
|
1853
1766
|
writeJsonLine(socket, {
|
|
1854
1767
|
type: 'command.result',
|
|
@@ -1858,43 +1771,13 @@ async function handleRemoteCommand(socket, options, message, nextFrameSeq, activ
|
|
|
1858
1771
|
return;
|
|
1859
1772
|
}
|
|
1860
1773
|
|
|
1861
|
-
const
|
|
1862
|
-
const
|
|
1863
|
-
|
|
1864
|
-
.
|
|
1865
|
-
.
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
try {
|
|
1869
|
-
const aiResult = await runAiAssistTask(options, payload, instruction);
|
|
1870
|
-
writeJsonLine(socket, {
|
|
1871
|
-
type: 'command.result',
|
|
1872
|
-
commandId: message.commandId,
|
|
1873
|
-
result: {
|
|
1874
|
-
kind: 'agent.task',
|
|
1875
|
-
mode: 'ai-assist',
|
|
1876
|
-
taskId: String(payload.taskId || '').slice(0, 128),
|
|
1877
|
-
title,
|
|
1878
|
-
status: 'completed',
|
|
1879
|
-
summary: aiResult.text,
|
|
1880
|
-
sideEffects: 'none',
|
|
1881
|
-
model: aiResult.model,
|
|
1882
|
-
responseId: aiResult.responseId,
|
|
1883
|
-
instructionPreview: instruction.slice(0, 320),
|
|
1884
|
-
completedAt: new Date().toISOString()
|
|
1885
|
-
}
|
|
1886
|
-
});
|
|
1887
|
-
} catch (error) {
|
|
1888
|
-
writeJsonLine(socket, {
|
|
1889
|
-
type: 'command.result',
|
|
1890
|
-
commandId: message.commandId,
|
|
1891
|
-
error: error?.message || String(error)
|
|
1892
|
-
});
|
|
1893
|
-
}
|
|
1894
|
-
return;
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
writeJsonLine(socket, {
|
|
1774
|
+
const completedAt = new Date().toISOString();
|
|
1775
|
+
const title = String(payload.title || instruction.split(/\r?\n/)[0] || 'Remote task')
|
|
1776
|
+
.replace(/[\r\n\t]/g, ' ')
|
|
1777
|
+
.trim()
|
|
1778
|
+
.slice(0, 120);
|
|
1779
|
+
|
|
1780
|
+
writeJsonLine(socket, {
|
|
1898
1781
|
type: 'command.result',
|
|
1899
1782
|
commandId: message.commandId,
|
|
1900
1783
|
result: {
|
|
@@ -2139,14 +2022,11 @@ function connectOnce(options, deviceId) {
|
|
|
2139
2022
|
taskDispatch: options.taskEnabled,
|
|
2140
2023
|
clientUpdate: true,
|
|
2141
2024
|
productVersion: PRODUCT_VERSION,
|
|
2142
|
-
agentApproval: options.taskEnabled,
|
|
2143
|
-
agentAudit: options.taskEnabled,
|
|
2144
|
-
agentTools: [...NODE_AGENT_OPERATIONS],
|
|
2145
|
-
elevation: typeof process.getuid === 'function' ? process.getuid() === 0 : false,
|
|
2146
|
-
|
|
2147
|
-
aiModel: options.aiModel,
|
|
2148
|
-
aiProvider: options.fakeAi ? 'fake' : (options.openAiApiKey ? 'openai' : ''),
|
|
2149
|
-
externalEffects: options.taskEnabled
|
|
2025
|
+
agentApproval: options.taskEnabled,
|
|
2026
|
+
agentAudit: options.taskEnabled,
|
|
2027
|
+
agentTools: [...NODE_AGENT_OPERATIONS],
|
|
2028
|
+
elevation: typeof process.getuid === 'function' ? process.getuid() === 0 : false,
|
|
2029
|
+
externalEffects: options.taskEnabled
|
|
2150
2030
|
}
|
|
2151
2031
|
});
|
|
2152
2032
|
});
|
package/bin/livedesk-client.js
CHANGED
|
@@ -67,6 +67,11 @@ const FAST_PREFLIGHT_CACHE_PATH = join(UNIFIED_CLIENT_STATE_DIR, 'fast-preflight
|
|
|
67
67
|
const CLIENT_SLOT_PATH = join(UNIFIED_CLIENT_STATE_DIR, 'device-slot.json');
|
|
68
68
|
const CLIENT_UPDATE_STATE_PATH = process.env.LIVEDESK_CLIENT_UPDATE_STATE_PATH
|
|
69
69
|
|| join(UNIFIED_CLIENT_STATE_DIR, 'client-update.json');
|
|
70
|
+
// Migration-only compatibility: releases before 0.1.204 could persist these
|
|
71
|
+
// Client-side model options in startup/update commands. Consume them without
|
|
72
|
+
// forwarding so an upgrade starts normally, but never restores that feature.
|
|
73
|
+
const RETIRED_CLIENT_MODEL_SINGLE_OPTIONS = new Set(['--ai', '--no-ai', '--fake-ai']);
|
|
74
|
+
const RETIRED_CLIENT_MODEL_VALUE_OPTION = '--ai-model';
|
|
70
75
|
let activeAgentProcess = null;
|
|
71
76
|
let roleRestartRequest = null;
|
|
72
77
|
let agentRestartRequest = null;
|
|
@@ -301,8 +306,8 @@ Options:
|
|
|
301
306
|
--version Show the agent version.
|
|
302
307
|
--help Show this help.
|
|
303
308
|
|
|
304
|
-
Auto uses C# RemoteFast when supported and falls back to Node
|
|
305
|
-
|
|
309
|
+
Auto uses C# RemoteFast when supported and falls back to Node only when a
|
|
310
|
+
packaged RemoteFast runtime is unavailable.
|
|
306
311
|
Enable Windows auto-start from the connection page when this client signs in.
|
|
307
312
|
`.trimStart());
|
|
308
313
|
}
|
|
@@ -394,15 +399,30 @@ export function parseLauncherArgs(argv) {
|
|
|
394
399
|
let slot = process.env.LIVEDESK_CLIENT_SLOT || process.env.MINDEXEC_REMOTE_SLOT || '';
|
|
395
400
|
let authPort = normalizePort(process.env.LIVEDESK_CLIENT_RUNTIME_PORT || process.env.LIVEDESK_CLIENT_AUTH_PORT) || DEFAULT_AUTH_CALLBACK_PORT;
|
|
396
401
|
let command = 'connect';
|
|
397
|
-
let
|
|
398
|
-
let fakeThumbnail = false;
|
|
402
|
+
let fakeThumbnail = false;
|
|
399
403
|
let startupRun = isTruthy(process.env.LIVEDESK_ROLE_TRANSITION);
|
|
400
|
-
let openBrowserOnStart = !isTruthy(process.env.LIVEDESK_SKIP_BROWSER_OPEN);
|
|
401
|
-
let updateWaitPid = 0;
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
404
|
+
let openBrowserOnStart = !isTruthy(process.env.LIVEDESK_SKIP_BROWSER_OPEN);
|
|
405
|
+
let updateWaitPid = 0;
|
|
406
|
+
let retiredModelOptionsDiscarded = 0;
|
|
407
|
+
|
|
408
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
409
|
+
const arg = argv[index];
|
|
410
|
+
if (RETIRED_CLIENT_MODEL_SINGLE_OPTIONS.has(arg)) {
|
|
411
|
+
retiredModelOptionsDiscarded += 1;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (arg === RETIRED_CLIENT_MODEL_VALUE_OPTION) {
|
|
415
|
+
retiredModelOptionsDiscarded += 1;
|
|
416
|
+
if (index + 1 < argv.length && !String(argv[index + 1] || '').startsWith('-')) {
|
|
417
|
+
index += 1;
|
|
418
|
+
}
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
if (String(arg || '').startsWith(`${RETIRED_CLIENT_MODEL_VALUE_OPTION}=`)) {
|
|
422
|
+
retiredModelOptionsDiscarded += 1;
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (arg && !arg.startsWith('-')) {
|
|
406
426
|
const lowerArg = arg.toLowerCase();
|
|
407
427
|
const shortcutSlot = normalizeSlotNumber(arg);
|
|
408
428
|
if (lowerArg === 'connect') {
|
|
@@ -512,11 +532,8 @@ export function parseLauncherArgs(argv) {
|
|
|
512
532
|
if (arg === '--version') {
|
|
513
533
|
version = true;
|
|
514
534
|
}
|
|
515
|
-
if (arg === '--
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
if (arg === '--fake-thumbnail') {
|
|
519
|
-
fakeThumbnail = true;
|
|
535
|
+
if (arg === '--fake-thumbnail') {
|
|
536
|
+
fakeThumbnail = true;
|
|
520
537
|
}
|
|
521
538
|
forwarded.push(arg);
|
|
522
539
|
}
|
|
@@ -539,13 +556,13 @@ export function parseLauncherArgs(argv) {
|
|
|
539
556
|
deviceId,
|
|
540
557
|
slot,
|
|
541
558
|
authPort,
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
};
|
|
548
|
-
}
|
|
559
|
+
fakeThumbnail,
|
|
560
|
+
startupRun,
|
|
561
|
+
openBrowserOnStart,
|
|
562
|
+
updateWaitPid,
|
|
563
|
+
retiredModelOptionsDiscarded
|
|
564
|
+
};
|
|
565
|
+
}
|
|
549
566
|
|
|
550
567
|
function normalizePort(value) {
|
|
551
568
|
const port = Number(String(value || '').trim());
|
|
@@ -854,13 +871,15 @@ const CLIENT_UPDATE_SINGLE_FLAGS = new Set([
|
|
|
854
871
|
'--no-open',
|
|
855
872
|
'--exit-on-disconnect',
|
|
856
873
|
'--exit-on-invalid-pair',
|
|
857
|
-
'--once'
|
|
874
|
+
'--once',
|
|
875
|
+
...RETIRED_CLIENT_MODEL_SINGLE_OPTIONS
|
|
858
876
|
]);
|
|
859
877
|
const CLIENT_UPDATE_VALUE_FLAGS = new Set([
|
|
860
878
|
'--update-wait-pid',
|
|
861
879
|
// Pairing credentials stay in the inherited private environment and must
|
|
862
880
|
// never be copied onto a replacement process command line.
|
|
863
|
-
'--pair'
|
|
881
|
+
'--pair',
|
|
882
|
+
RETIRED_CLIENT_MODEL_VALUE_OPTION
|
|
864
883
|
]);
|
|
865
884
|
|
|
866
885
|
export function buildClientUpdateRestartArgs(prepared = {}) {
|
|
@@ -874,6 +893,9 @@ export function buildClientUpdateRestartArgs(prepared = {}) {
|
|
|
874
893
|
if (arg.startsWith('--pair=')) {
|
|
875
894
|
continue;
|
|
876
895
|
}
|
|
896
|
+
if (arg.startsWith(`${RETIRED_CLIENT_MODEL_VALUE_OPTION}=`)) {
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
877
899
|
if (CLIENT_UPDATE_VALUE_FLAGS.has(arg)) {
|
|
878
900
|
index += 1;
|
|
879
901
|
continue;
|
|
@@ -4233,6 +4255,18 @@ export function buildFastArgs(args, fakeThumbnail, transport = 'auto', relay = '
|
|
|
4233
4255
|
const forwarded = [];
|
|
4234
4256
|
for (let index = 0; index < args.length; index += 1) {
|
|
4235
4257
|
const arg = args[index];
|
|
4258
|
+
if (RETIRED_CLIENT_MODEL_SINGLE_OPTIONS.has(arg)) {
|
|
4259
|
+
continue;
|
|
4260
|
+
}
|
|
4261
|
+
if (arg === RETIRED_CLIENT_MODEL_VALUE_OPTION) {
|
|
4262
|
+
if (index + 1 < args.length && !String(args[index + 1] || '').startsWith('-')) {
|
|
4263
|
+
index += 1;
|
|
4264
|
+
}
|
|
4265
|
+
continue;
|
|
4266
|
+
}
|
|
4267
|
+
if (String(arg || '').startsWith(`${RETIRED_CLIENT_MODEL_VALUE_OPTION}=`)) {
|
|
4268
|
+
continue;
|
|
4269
|
+
}
|
|
4236
4270
|
if (arg === '--transport' || arg === '--relay') {
|
|
4237
4271
|
index += 1;
|
|
4238
4272
|
continue;
|
|
@@ -4241,8 +4275,8 @@ export function buildFastArgs(args, fakeThumbnail, transport = 'auto', relay = '
|
|
|
4241
4275
|
forwarded.push('--fake-frame');
|
|
4242
4276
|
continue;
|
|
4243
4277
|
}
|
|
4244
|
-
if (arg === '--tasks' || arg === '--no-tasks'
|
|
4245
|
-
continue;
|
|
4278
|
+
if (arg === '--tasks' || arg === '--no-tasks') {
|
|
4279
|
+
continue;
|
|
4246
4280
|
}
|
|
4247
4281
|
forwarded.push(arg);
|
|
4248
4282
|
}
|
|
@@ -4446,15 +4480,15 @@ function spawnAgent(command, args, env = process.env, onStart = null) {
|
|
|
4446
4480
|
});
|
|
4447
4481
|
}
|
|
4448
4482
|
|
|
4449
|
-
function shouldUseFast(parsed) {
|
|
4450
|
-
if (parsed.engine === 'node') {
|
|
4451
|
-
return false;
|
|
4483
|
+
function shouldUseFast(parsed) {
|
|
4484
|
+
if (parsed.engine === 'node') {
|
|
4485
|
+
return false;
|
|
4452
4486
|
}
|
|
4453
4487
|
if (parsed.engine === 'fast') {
|
|
4454
4488
|
return true;
|
|
4455
4489
|
}
|
|
4456
|
-
return
|
|
4457
|
-
}
|
|
4490
|
+
return true;
|
|
4491
|
+
}
|
|
4458
4492
|
|
|
4459
4493
|
function shouldTryFast(parsed, runtime) {
|
|
4460
4494
|
if (parsed.engine === 'fast') {
|
|
@@ -4480,6 +4514,12 @@ export async function runClientRuntime(argv = process.argv.slice(2)) {
|
|
|
4480
4514
|
console.warn('[LiveDesk] @livedesk/client is deprecated. Use the unified livedesk package or LiveDesk Desktop.');
|
|
4481
4515
|
}
|
|
4482
4516
|
const parsed = parseLauncherArgs(argv);
|
|
4517
|
+
if (parsed.retiredModelOptionsDiscarded > 0) {
|
|
4518
|
+
console.warn(
|
|
4519
|
+
'[LiveDesk Client] Ignored retired Client model-runtime options. '
|
|
4520
|
+
+ 'Approved AI computer commands are handled by the Hub Codex Agent.'
|
|
4521
|
+
);
|
|
4522
|
+
}
|
|
4483
4523
|
if (parsed.updateWaitPid) {
|
|
4484
4524
|
await waitForProcessExit(parsed.updateWaitPid);
|
|
4485
4525
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livedesk/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.204",
|
|
4
4
|
"description": "LiveDesk local remote client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -37,14 +37,13 @@
|
|
|
37
37
|
"@livedesk/runtime-core": "0.1.0",
|
|
38
38
|
"@supabase/supabase-js": "^2.110.0",
|
|
39
39
|
"node-screenshots": "^0.2.8",
|
|
40
|
-
"openai": "^6.42.0",
|
|
41
40
|
"ws": "^8.18.3"
|
|
42
41
|
},
|
|
43
42
|
"optionalDependencies": {
|
|
44
|
-
"@livedesk/fast-linux-x64": "0.1.
|
|
45
|
-
"@livedesk/fast-osx-arm64": "0.1.
|
|
46
|
-
"@livedesk/fast-osx-x64": "0.1.
|
|
47
|
-
"@livedesk/fast-win-x64": "0.1.
|
|
43
|
+
"@livedesk/fast-linux-x64": "0.1.411",
|
|
44
|
+
"@livedesk/fast-osx-arm64": "0.1.411",
|
|
45
|
+
"@livedesk/fast-osx-x64": "0.1.411",
|
|
46
|
+
"@livedesk/fast-win-x64": "0.1.411"
|
|
48
47
|
},
|
|
49
48
|
"publishConfig": {
|
|
50
49
|
"access": "public"
|