@parall/daemon 1.62.0 → 1.63.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/bundle/manifest.json +11 -11
- package/bundle/parall-browser-pod.js +78 -18
- package/bundle/parall-claude-agent.js +271 -181
- package/bundle/parall-codex-agent.js +125 -45
- package/bundle/parall-daemon.js +2302 -1411
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +75 -2
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -2
- package/dist/diagnostics.d.ts +127 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +358 -0
- package/dist/updater.d.ts +14 -0
- package/dist/updater.d.ts.map +1 -1
- package/dist/updater.js +19 -15
- package/package.json +6 -6
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AA+oBA,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CA0D9E"}
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as os from 'node:os';
|
|
|
4
4
|
import * as path from 'node:path';
|
|
5
5
|
import * as readline from 'node:readline';
|
|
6
6
|
import { daemonConfigDir, daemonConfigPath } from './config.js';
|
|
7
|
+
import { DIAGNOSTICS_NOTE_MAX_CHARS, collectDiagnostics, resolveDaemonLogPath, serializeBundle, uploadDiagnostics, } from './diagnostics.js';
|
|
7
8
|
import { WIN_TASK_NAME, buildLauncherCjs, buildLauncherVbs, buildTaskXml, encodeUtf16LeBom, winServicePaths, } from './win-service.js';
|
|
8
9
|
import { probePidIdentity, queryTaskDisabled, queryTaskExists, readTrackedPid, stopDaemonWindows, uninstallDaemonWindows, } from './win-lifecycle.js';
|
|
9
10
|
const CONFIG_DIR = daemonConfigDir();
|
|
@@ -414,8 +415,10 @@ function cmdLogs(lines) {
|
|
|
414
415
|
child.on('exit', (code) => process.exit(code ?? 0));
|
|
415
416
|
return;
|
|
416
417
|
}
|
|
417
|
-
|
|
418
|
-
|
|
418
|
+
// Desktop-managed daemons log to an env-suffixed file (parall-daemon-staging.log);
|
|
419
|
+
// the shell passes that path so `logs` and `diagnostics` read the right one.
|
|
420
|
+
const logPath = resolveDaemonLogPath();
|
|
421
|
+
if (!logPath || !fs.existsSync(logPath)) {
|
|
419
422
|
console.log('No log file found at', logPath);
|
|
420
423
|
return;
|
|
421
424
|
}
|
|
@@ -485,6 +488,69 @@ async function cmdUpdate(checkOnly) {
|
|
|
485
488
|
console.log('Already up to date.');
|
|
486
489
|
}
|
|
487
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* `diagnostics upload|dry-run`: assemble the redacted bundle from disk and
|
|
493
|
+
* either POST it with the machine key or write it next to the user for
|
|
494
|
+
* inspection. Out of process on purpose — works while the daemon is wedged.
|
|
495
|
+
*/
|
|
496
|
+
async function cmdDiagnostics(args) {
|
|
497
|
+
const sub = args[0];
|
|
498
|
+
const json = args.includes('--json');
|
|
499
|
+
let note;
|
|
500
|
+
let dryRunPath;
|
|
501
|
+
for (let i = 1; i < args.length; i++) {
|
|
502
|
+
if (args[i] === '--note')
|
|
503
|
+
note = args[++i];
|
|
504
|
+
else if (args[i] === '--out')
|
|
505
|
+
dryRunPath = args[++i];
|
|
506
|
+
}
|
|
507
|
+
if (sub !== 'upload' && sub !== 'dry-run') {
|
|
508
|
+
console.error(`Unknown diagnostics command: ${sub ?? '(none)'}`);
|
|
509
|
+
console.log('Usage: parall-daemon diagnostics upload [--note TEXT] [--json]');
|
|
510
|
+
console.log(' parall-daemon diagnostics dry-run [--out FILE]');
|
|
511
|
+
process.exit(1);
|
|
512
|
+
}
|
|
513
|
+
if (note && [...note].length > DIAGNOSTICS_NOTE_MAX_CHARS) {
|
|
514
|
+
console.error(`Error: --note must be at most ${DIAGNOSTICS_NOTE_MAX_CHARS} characters`);
|
|
515
|
+
process.exit(1);
|
|
516
|
+
}
|
|
517
|
+
// Upload needs a configured daemon; say so before the multi-second collect.
|
|
518
|
+
const config = sub === 'upload' ? readConfig() : null;
|
|
519
|
+
if (sub === 'upload' && (!config?.api_url || !config.api_key)) {
|
|
520
|
+
console.error('Error: daemon is not configured (no config.json). Run `parall-daemon init` first.');
|
|
521
|
+
process.exit(1);
|
|
522
|
+
}
|
|
523
|
+
const bundle = await collectDiagnostics();
|
|
524
|
+
if (sub === 'dry-run' || !config) {
|
|
525
|
+
const out = dryRunPath ?? path.join(process.cwd(), `parall-diagnostics-${Date.now()}.json.gz`);
|
|
526
|
+
fs.writeFileSync(out, serializeBundle(bundle), { mode: 0o600 });
|
|
527
|
+
fs.chmodSync(out, 0o600); // mode above does not tighten an existing file
|
|
528
|
+
const summary = { path: out, bytes: fs.statSync(out).size, log_bytes: bundle.log.bytes };
|
|
529
|
+
console.log(json ? JSON.stringify(summary) : `Wrote ${summary.bytes} bytes to ${out} (not uploaded)`);
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const { ParallClient } = await import('@parall/sdk');
|
|
533
|
+
const client = new ParallClient({ baseUrl: config.api_url, token: config.api_key });
|
|
534
|
+
try {
|
|
535
|
+
const receipt = await uploadDiagnostics(client, bundle, note);
|
|
536
|
+
if (json) {
|
|
537
|
+
console.log(JSON.stringify(receipt));
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
console.log(`Uploaded diagnostics bundle ${receipt.id} (${receipt.size_bytes} bytes).`);
|
|
541
|
+
console.log('Share the bundle id with Parall support.');
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
catch (err) {
|
|
545
|
+
if (json) {
|
|
546
|
+
console.log(JSON.stringify({ error: String(err) }));
|
|
547
|
+
}
|
|
548
|
+
else {
|
|
549
|
+
console.error(`Upload failed: ${String(err)}`);
|
|
550
|
+
}
|
|
551
|
+
process.exit(1);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
488
554
|
function printUsage() {
|
|
489
555
|
console.log(`
|
|
490
556
|
parall-daemon — Parall local agent runtime
|
|
@@ -496,6 +562,10 @@ Usage:
|
|
|
496
562
|
parall-daemon stop Stop the background service
|
|
497
563
|
parall-daemon update [--check] Check for / apply daemon updates
|
|
498
564
|
parall-daemon logs [-n LINES] Tail daemon logs
|
|
565
|
+
parall-daemon diagnostics upload [--note TEXT] [--json]
|
|
566
|
+
Upload a redacted diagnostics bundle for Parall support
|
|
567
|
+
parall-daemon diagnostics dry-run [--out FILE]
|
|
568
|
+
Write the bundle locally to inspect it (nothing is sent)
|
|
499
569
|
parall-daemon service install Install as background service (launchd/systemd/Task Scheduler)
|
|
500
570
|
parall-daemon service uninstall Uninstall background service
|
|
501
571
|
parall-daemon help Show this help
|
|
@@ -529,6 +599,9 @@ export async function runCLI(args) {
|
|
|
529
599
|
case 'update':
|
|
530
600
|
await cmdUpdate(args.includes('--check'));
|
|
531
601
|
return 'handled';
|
|
602
|
+
case 'diagnostics':
|
|
603
|
+
await cmdDiagnostics(args.slice(1));
|
|
604
|
+
return 'handled';
|
|
532
605
|
case 'service': {
|
|
533
606
|
const sub = args[1];
|
|
534
607
|
if (sub === 'install') {
|
package/dist/config.d.ts
CHANGED
|
@@ -71,6 +71,10 @@ export type ClaudeDaemonConfig = {
|
|
|
71
71
|
};
|
|
72
72
|
export declare function daemonConfigPath(env?: NodeJS.ProcessEnv): string;
|
|
73
73
|
export declare function resolveClaudeDaemonConfig(env?: NodeJS.ProcessEnv): ClaudeDaemonConfig;
|
|
74
|
+
/** The operator's real HOME (or PRLL_CLAUDE_HOME) that per-agent homes hang off. */
|
|
75
|
+
export declare function resolveRootClaudeHome(env?: NodeJS.ProcessEnv): string;
|
|
76
|
+
/** Root of all per-agent state (`agents/<id>/…`): PRLL_CLAUDE_STATE_DIR or `~/.parall-agent`. */
|
|
77
|
+
export declare function resolveRootStateDir(env?: NodeJS.ProcessEnv): string;
|
|
74
78
|
/** Per-agent state dir under the shared host volume. */
|
|
75
79
|
export declare function agentStateDirFor(rootStateDir: string, agentId: string): string;
|
|
76
80
|
/** Per-agent HOME dir. Claude Code stores project/session state under
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAe,MAAM,mBAAmB,CAAC;AAEnF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,2GAA2G;IAC3G,QAAQ,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,YAAY,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,cAAc,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,cAAc,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,gBAAgB,EAAE,MAAM,CAAC;IACzB,oFAAoF;IACpF,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B,qBAAqB,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,0BAA0B,EAAE,MAAM,CAAC;IACnC,6BAA6B,EAAE,MAAM,CAAC;IACtC,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,gBAAgB,EAAE,MAAM,CAAC;IACzB,4DAA4D;IAC5D,cAAc,EAAE,OAAO,C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EACtB,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAMR"}
|
package/dist/config.js
CHANGED
|
@@ -69,8 +69,8 @@ export function resolveClaudeDaemonConfig(env = process.env) {
|
|
|
69
69
|
throw new Error(`PRLL_API_KEY does not look like a Machine bearer (expected prefix "mck_"). ` +
|
|
70
70
|
`Daemon mode requires a machine-scoped key issued via POST /machines/{id}/keys.`);
|
|
71
71
|
}
|
|
72
|
-
const rootClaudeHome =
|
|
73
|
-
const rootStateDir =
|
|
72
|
+
const rootClaudeHome = resolveRootClaudeHome(env);
|
|
73
|
+
const rootStateDir = resolveRootStateDir(env);
|
|
74
74
|
return {
|
|
75
75
|
apiUrl,
|
|
76
76
|
apiKey,
|
|
@@ -102,6 +102,14 @@ function assertSafeAgentId(agentId) {
|
|
|
102
102
|
}
|
|
103
103
|
return agentId;
|
|
104
104
|
}
|
|
105
|
+
/** The operator's real HOME (or PRLL_CLAUDE_HOME) that per-agent homes hang off. */
|
|
106
|
+
export function resolveRootClaudeHome(env = process.env) {
|
|
107
|
+
return resolvePath(env.PRLL_CLAUDE_HOME?.trim() || env.HOME || os.homedir());
|
|
108
|
+
}
|
|
109
|
+
/** Root of all per-agent state (`agents/<id>/…`): PRLL_CLAUDE_STATE_DIR or `~/.parall-agent`. */
|
|
110
|
+
export function resolveRootStateDir(env = process.env) {
|
|
111
|
+
return resolvePath(env.PRLL_CLAUDE_STATE_DIR?.trim() || path.join(resolveRootClaudeHome(env), '.parall-agent'));
|
|
112
|
+
}
|
|
105
113
|
/** Per-agent state dir under the shared host volume. */
|
|
106
114
|
export function agentStateDirFor(rootStateDir, agentId) {
|
|
107
115
|
return path.join(rootStateDir, 'agents', assertSafeAgentId(agentId));
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type DetectedRuntime, type MachineDiagnosticsUploadResponse, type ParallClient } from '@parall/sdk';
|
|
2
|
+
import { buildMachineRuntimeReport } from './runtime-report.js';
|
|
3
|
+
import { type UpdateState } from './updater.js';
|
|
4
|
+
/**
|
|
5
|
+
* Diagnostics bundle (daemon-diagnostics-bundle-design.md): what a
|
|
6
|
+
* self-hosted machine's owner sends the platform to get a problem looked at.
|
|
7
|
+
* Assembled OUT of process from files on disk — the CLI (and the Desktop
|
|
8
|
+
* button, which runs the CLI) never talks to the running daemon.
|
|
9
|
+
*
|
|
10
|
+
* Everything in the bundle comes from the ALLOWLIST below; nothing is read
|
|
11
|
+
* from anywhere else. The one credential this process can see, config.json's
|
|
12
|
+
* `api_key`, is dropped from the config copy and used as an exact value for
|
|
13
|
+
* redacting the log tail. Credentials the daemon keeps in memory (per-agent
|
|
14
|
+
* agk_ launch keys, PRLL_PROVIDER_CONFIG) are not on disk and can only be
|
|
15
|
+
* caught by redactSecrets' prefix rules — the log tail is the bridges' raw
|
|
16
|
+
* stdout/stderr, so that rule set is the floor, not a guarantee.
|
|
17
|
+
*/
|
|
18
|
+
export declare const DIAGNOSTICS_SCHEMA_VERSION = 1;
|
|
19
|
+
/** Bytes of the log file's tail that travel; well under the server's 16 MB body cap. */
|
|
20
|
+
export declare const DIAGNOSTICS_LOG_TAIL_BYTES: number;
|
|
21
|
+
/** Runtime probes spawn `--version` (and maybe a login shell); bound the whole step. */
|
|
22
|
+
export declare const DIAGNOSTICS_DETECT_BUDGET_MS = 20000;
|
|
23
|
+
export declare const DIAGNOSTICS_NOTE_MAX_CHARS = 500;
|
|
24
|
+
/**
|
|
25
|
+
* A URL as it may appear in the bundle: userinfo, query and fragment are the
|
|
26
|
+
* places a credential usually rides along (`https://u:p@host/?token=…`), so
|
|
27
|
+
* they are dropped outright; what remains (and an unparseable value) still
|
|
28
|
+
* goes through `redactSecrets`, so a credential-shaped path segment is masked
|
|
29
|
+
* like it would be in the log. The daemon's own config is never rewritten.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sanitizeUrlValue(value: string, knownSecrets: string[]): string;
|
|
32
|
+
export interface DiagnosticsBundle {
|
|
33
|
+
schema_version: number;
|
|
34
|
+
created_at: string;
|
|
35
|
+
manifest: {
|
|
36
|
+
daemon_version: string;
|
|
37
|
+
bundle_manifest_version: string | null;
|
|
38
|
+
platform: string;
|
|
39
|
+
arch: string;
|
|
40
|
+
node_version: string;
|
|
41
|
+
os_release: string;
|
|
42
|
+
hostname_length: number;
|
|
43
|
+
config_dir: string;
|
|
44
|
+
bundle_dir: string;
|
|
45
|
+
state_dir: string;
|
|
46
|
+
};
|
|
47
|
+
/** config.json without api_key. */
|
|
48
|
+
config: Record<string, unknown>;
|
|
49
|
+
update_state: UpdateState | null;
|
|
50
|
+
bundle_versions: string[];
|
|
51
|
+
runtime_report: {
|
|
52
|
+
skipped: string;
|
|
53
|
+
} | ReturnType<typeof buildMachineRuntimeReport>;
|
|
54
|
+
spool: SpoolStats[];
|
|
55
|
+
agents: AgentDirStats[];
|
|
56
|
+
env: {
|
|
57
|
+
present: string[];
|
|
58
|
+
values: Record<string, string>;
|
|
59
|
+
proxy: string[];
|
|
60
|
+
};
|
|
61
|
+
log: {
|
|
62
|
+
source: string;
|
|
63
|
+
truncated: boolean;
|
|
64
|
+
bytes: number;
|
|
65
|
+
text: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface SpoolStats {
|
|
69
|
+
dir: string;
|
|
70
|
+
signal: string;
|
|
71
|
+
files: number;
|
|
72
|
+
bytes: number;
|
|
73
|
+
oldest_at: string | null;
|
|
74
|
+
}
|
|
75
|
+
export interface AgentDirStats {
|
|
76
|
+
agent_id: string;
|
|
77
|
+
workspace: boolean;
|
|
78
|
+
home: boolean;
|
|
79
|
+
}
|
|
80
|
+
export interface CollectOptions {
|
|
81
|
+
env?: NodeJS.ProcessEnv;
|
|
82
|
+
now?: () => Date;
|
|
83
|
+
/** Reads the log tail; defaults to the platform's daemon log. */
|
|
84
|
+
logSource?: () => Promise<{
|
|
85
|
+
source: string;
|
|
86
|
+
text: string;
|
|
87
|
+
truncated: boolean;
|
|
88
|
+
}>;
|
|
89
|
+
/** Runtime probing; defaults to detectRuntimes. Either way the budget below applies. */
|
|
90
|
+
detect?: () => Promise<DetectedRuntime[]>;
|
|
91
|
+
detectBudgetMs?: number;
|
|
92
|
+
importMetaUrl?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The last `maxBytes` of a buffer as text. `total` is the size of the whole
|
|
96
|
+
* source (the buffer may already be its trailing window); when anything was
|
|
97
|
+
* cut, the text restarts at the next line so no partial line or split UTF-8
|
|
98
|
+
* sequence leads the tail. A window with no newline at all (one line longer
|
|
99
|
+
* than the window) is kept as the partial line: a huge bridge line is still
|
|
100
|
+
* evidence, and `truncated` says it was cut.
|
|
101
|
+
*/
|
|
102
|
+
export declare function tailBuffer(buf: Buffer, maxBytes: number, total?: number): {
|
|
103
|
+
text: string;
|
|
104
|
+
truncated: boolean;
|
|
105
|
+
};
|
|
106
|
+
/** Last maxBytes of a file, cut to a line boundary; empty when the file is absent. */
|
|
107
|
+
export declare function tailFile(file: string, maxBytes: number): {
|
|
108
|
+
text: string;
|
|
109
|
+
truncated: boolean;
|
|
110
|
+
};
|
|
111
|
+
/** Where this platform's daemon log lives for the CLI; Desktop passes its env-suffixed path. */
|
|
112
|
+
export declare function resolveDaemonLogPath(env?: NodeJS.ProcessEnv): string | null;
|
|
113
|
+
/**
|
|
114
|
+
* Run a command and keep only the trailing `maxBytes` of its stdout, however
|
|
115
|
+
* much it prints: the buffer is trimmed as chunks arrive, so a verbose journal
|
|
116
|
+
* never hits a fixed maxBuffer and loses the useful end. Rejects when the
|
|
117
|
+
* command cannot start or exits non-zero without printing anything.
|
|
118
|
+
*/
|
|
119
|
+
export declare function commandTail(cmd: string, args: string[], maxBytes: number): Promise<{
|
|
120
|
+
text: string;
|
|
121
|
+
truncated: boolean;
|
|
122
|
+
}>;
|
|
123
|
+
export declare function collectDiagnostics(opts?: CollectOptions): Promise<DiagnosticsBundle>;
|
|
124
|
+
/** The wire form: gzip of the JSON document. */
|
|
125
|
+
export declare function serializeBundle(bundle: DiagnosticsBundle): Buffer;
|
|
126
|
+
export declare function uploadDiagnostics(client: Pick<ParallClient, 'uploadMachineDiagnostics'>, bundle: DiagnosticsBundle, note?: string): Promise<MachineDiagnosticsUploadResponse>;
|
|
127
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,KAAK,eAAe,EAEpB,KAAK,gCAAgC,EACrC,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAYrB,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,KAAK,WAAW,EAAsC,MAAM,cAAc,CAAC;AAGpF;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAC5C,wFAAwF;AACxF,eAAO,MAAM,0BAA0B,QAAU,CAAC;AAClD,wFAAwF;AACxF,eAAO,MAAM,4BAA4B,QAAS,CAAC;AACnD,eAAO,MAAM,0BAA0B,MAAqC,CAAC;AAqB7E;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,CAc9E;AAUD,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE;QACR,cAAc,EAAE,MAAM,CAAC;QACvB,uBAAuB,EAAE,MAAM,GAAG,IAAI,CAAC;QACvC,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,MAAM,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;I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|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as os from 'node:os';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import * as zlib from 'node:zlib';
|
|
6
|
+
import { maskKnownValues, redactSecrets, resolveServiceVersion } from '@parall/agent-core';
|
|
7
|
+
import { MACHINE_DIAGNOSTICS_NOTE_MAX_CHARS, } from '@parall/sdk';
|
|
8
|
+
import { agentHomeDirFor, agentWorkspaceDirFor, daemonConfigDir, resolveBundleDir, resolveRootStateDir, } from './config.js';
|
|
9
|
+
import { proxyEnvNames } from './daemon-telemetry.js';
|
|
10
|
+
import { isSelfUpdateManaged } from './daemon-update-mode.js';
|
|
11
|
+
import { DETECTABLE_RUNTIME_TYPES } from './runtime-bin-resolver.js';
|
|
12
|
+
import { detectRuntimes } from './runtime-detector.js';
|
|
13
|
+
import { buildMachineRuntimeReport } from './runtime-report.js';
|
|
14
|
+
import { loadLocalManifest, loadUpdateState } from './updater.js';
|
|
15
|
+
import { winServicePaths } from './win-service.js';
|
|
16
|
+
/**
|
|
17
|
+
* Diagnostics bundle (daemon-diagnostics-bundle-design.md): what a
|
|
18
|
+
* self-hosted machine's owner sends the platform to get a problem looked at.
|
|
19
|
+
* Assembled OUT of process from files on disk — the CLI (and the Desktop
|
|
20
|
+
* button, which runs the CLI) never talks to the running daemon.
|
|
21
|
+
*
|
|
22
|
+
* Everything in the bundle comes from the ALLOWLIST below; nothing is read
|
|
23
|
+
* from anywhere else. The one credential this process can see, config.json's
|
|
24
|
+
* `api_key`, is dropped from the config copy and used as an exact value for
|
|
25
|
+
* redacting the log tail. Credentials the daemon keeps in memory (per-agent
|
|
26
|
+
* agk_ launch keys, PRLL_PROVIDER_CONFIG) are not on disk and can only be
|
|
27
|
+
* caught by redactSecrets' prefix rules — the log tail is the bridges' raw
|
|
28
|
+
* stdout/stderr, so that rule set is the floor, not a guarantee.
|
|
29
|
+
*/
|
|
30
|
+
export const DIAGNOSTICS_SCHEMA_VERSION = 1;
|
|
31
|
+
/** Bytes of the log file's tail that travel; well under the server's 16 MB body cap. */
|
|
32
|
+
export const DIAGNOSTICS_LOG_TAIL_BYTES = 1 << 20;
|
|
33
|
+
/** Runtime probes spawn `--version` (and maybe a login shell); bound the whole step. */
|
|
34
|
+
export const DIAGNOSTICS_DETECT_BUDGET_MS = 20_000;
|
|
35
|
+
export const DIAGNOSTICS_NOTE_MAX_CHARS = MACHINE_DIAGNOSTICS_NOTE_MAX_CHARS;
|
|
36
|
+
/** Env keys whose VALUES are safe to include; every other PRLL_* key contributes its name only. */
|
|
37
|
+
const ENV_VALUE_ALLOWLIST = new Set([
|
|
38
|
+
'PRLL_DAEMON_CONFIG_DIR',
|
|
39
|
+
'PRLL_DAEMON_BUNDLE_DIR',
|
|
40
|
+
'PRLL_SERVER_ENV',
|
|
41
|
+
'PRLL_DAEMON_MANAGED',
|
|
42
|
+
'PRLL_DAEMON_UPDATE_CDN_URL',
|
|
43
|
+
'PRLL_DAEMON_UPDATE_CHANNEL',
|
|
44
|
+
'PRLL_DAEMON_UPDATE_INTERVAL_MS',
|
|
45
|
+
'PRLL_DAEMON_UPDATE_DISABLED',
|
|
46
|
+
'PRLL_DAEMON_UPDATE_CONFIRM_DELAY_MS',
|
|
47
|
+
'PRLL_DAEMON_HOME_ISOLATION',
|
|
48
|
+
'PRLL_CLIP_RUNTIME_ENABLED',
|
|
49
|
+
'PRLL_OTEL_SPOOL_DIR',
|
|
50
|
+
]);
|
|
51
|
+
const CONFIG_KEYS_ALLOWLIST = ['api_url', 'machine_id', 'org_id', 'update_cdn_url'];
|
|
52
|
+
/** Allowlisted values that are URLs: only scheme, host and path leave the machine. */
|
|
53
|
+
const URL_VALUED_KEYS = new Set(['api_url', 'update_cdn_url', 'PRLL_DAEMON_UPDATE_CDN_URL']);
|
|
54
|
+
/**
|
|
55
|
+
* A URL as it may appear in the bundle: userinfo, query and fragment are the
|
|
56
|
+
* places a credential usually rides along (`https://u:p@host/?token=…`), so
|
|
57
|
+
* they are dropped outright; what remains (and an unparseable value) still
|
|
58
|
+
* goes through `redactSecrets`, so a credential-shaped path segment is masked
|
|
59
|
+
* like it would be in the log. The daemon's own config is never rewritten.
|
|
60
|
+
*/
|
|
61
|
+
export function sanitizeUrlValue(value, knownSecrets) {
|
|
62
|
+
let kept = value;
|
|
63
|
+
try {
|
|
64
|
+
const u = new URL(value);
|
|
65
|
+
// Only http(s) with a host has the scheme/host/path shape the contract
|
|
66
|
+
// keeps; anything else (mailto:, data:, file:) is opaque content.
|
|
67
|
+
if ((u.protocol !== 'http:' && u.protocol !== 'https:') || !u.host)
|
|
68
|
+
return '***';
|
|
69
|
+
if (u.username || u.password || u.search || u.hash) {
|
|
70
|
+
kept = `${u.protocol}//${u.host}${u.pathname}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// not a URL: fall through to the redaction rules alone
|
|
75
|
+
}
|
|
76
|
+
return redactSecrets(kept, knownSecrets);
|
|
77
|
+
}
|
|
78
|
+
/** Other allowlisted strings (ids, directory paths) keep their shape: known-value masking only. */
|
|
79
|
+
function allowlistedValue(key, value, knownSecrets) {
|
|
80
|
+
if (typeof value !== 'string')
|
|
81
|
+
return value;
|
|
82
|
+
return URL_VALUED_KEYS.has(key)
|
|
83
|
+
? sanitizeUrlValue(value, knownSecrets)
|
|
84
|
+
: maskKnownValues(value, knownSecrets);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The last `maxBytes` of a buffer as text. `total` is the size of the whole
|
|
88
|
+
* source (the buffer may already be its trailing window); when anything was
|
|
89
|
+
* cut, the text restarts at the next line so no partial line or split UTF-8
|
|
90
|
+
* sequence leads the tail. A window with no newline at all (one line longer
|
|
91
|
+
* than the window) is kept as the partial line: a huge bridge line is still
|
|
92
|
+
* evidence, and `truncated` says it was cut.
|
|
93
|
+
*/
|
|
94
|
+
export function tailBuffer(buf, maxBytes, total = buf.length) {
|
|
95
|
+
let window = buf.length > maxBytes ? buf.subarray(buf.length - maxBytes) : buf;
|
|
96
|
+
const truncated = total > window.length;
|
|
97
|
+
if (truncated) {
|
|
98
|
+
// A cut inside a multi-byte character would decode to U+FFFD (3 bytes
|
|
99
|
+
// each) and push the re-encoded size past maxBytes: skip continuation
|
|
100
|
+
// bytes so the window starts on a character boundary.
|
|
101
|
+
let start = 0;
|
|
102
|
+
while (start < window.length && (window[start] & 0xc0) === 0x80)
|
|
103
|
+
start++;
|
|
104
|
+
window = window.subarray(start);
|
|
105
|
+
}
|
|
106
|
+
let text = window.toString('utf-8');
|
|
107
|
+
if (truncated) {
|
|
108
|
+
const nl = text.indexOf('\n');
|
|
109
|
+
if (nl >= 0)
|
|
110
|
+
text = text.slice(nl + 1);
|
|
111
|
+
}
|
|
112
|
+
return { text, truncated };
|
|
113
|
+
}
|
|
114
|
+
/** Last maxBytes of a file, cut to a line boundary; empty when the file is absent. */
|
|
115
|
+
export function tailFile(file, maxBytes) {
|
|
116
|
+
let fd;
|
|
117
|
+
try {
|
|
118
|
+
fd = fs.openSync(file, 'r');
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return { text: '', truncated: false };
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const size = fs.fstatSync(fd).size;
|
|
125
|
+
const start = Math.max(0, size - maxBytes);
|
|
126
|
+
const buf = Buffer.alloc(size - start);
|
|
127
|
+
fs.readSync(fd, buf, 0, buf.length, start);
|
|
128
|
+
return tailBuffer(buf, maxBytes, size);
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
fs.closeSync(fd);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** Where this platform's daemon log lives for the CLI; Desktop passes its env-suffixed path. */
|
|
135
|
+
export function resolveDaemonLogPath(env = process.env) {
|
|
136
|
+
const explicit = env.PRLL_DAEMON_LOG_PATH?.trim();
|
|
137
|
+
if (explicit)
|
|
138
|
+
return explicit;
|
|
139
|
+
if (process.platform === 'win32')
|
|
140
|
+
return winServicePaths(os.homedir()).logFile;
|
|
141
|
+
if (process.platform === 'darwin') {
|
|
142
|
+
return path.join(os.homedir(), 'Library', 'Logs', 'parall-daemon.log');
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
async function defaultLogSource(env) {
|
|
147
|
+
const file = resolveDaemonLogPath(env);
|
|
148
|
+
if (file)
|
|
149
|
+
return { source: file, ...tailFile(file, DIAGNOSTICS_LOG_TAIL_BYTES) };
|
|
150
|
+
// Linux service installs log to journald.
|
|
151
|
+
try {
|
|
152
|
+
return {
|
|
153
|
+
source: 'journalctl --user-unit parall-daemon',
|
|
154
|
+
...(await commandTail('journalctl', ['--user-unit', 'parall-daemon', '-n', '4000', '-o', 'cat', '--no-pager'], DIAGNOSTICS_LOG_TAIL_BYTES)),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
return { source: 'journalctl (failed)', text: String(err), truncated: false };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Run a command and keep only the trailing `maxBytes` of its stdout, however
|
|
163
|
+
* much it prints: the buffer is trimmed as chunks arrive, so a verbose journal
|
|
164
|
+
* never hits a fixed maxBuffer and loses the useful end. Rejects when the
|
|
165
|
+
* command cannot start or exits non-zero without printing anything.
|
|
166
|
+
*/
|
|
167
|
+
export function commandTail(cmd, args, maxBytes) {
|
|
168
|
+
return new Promise((resolve, reject) => {
|
|
169
|
+
const child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
170
|
+
let kept = Buffer.alloc(0);
|
|
171
|
+
let total = 0;
|
|
172
|
+
let stderr = '';
|
|
173
|
+
child.stdout.on('data', (chunk) => {
|
|
174
|
+
total += chunk.length;
|
|
175
|
+
kept = Buffer.concat([kept, chunk]);
|
|
176
|
+
// Keep a little more than the window so the line cut still has slack.
|
|
177
|
+
if (kept.length > maxBytes * 2)
|
|
178
|
+
kept = kept.subarray(kept.length - maxBytes);
|
|
179
|
+
});
|
|
180
|
+
child.stderr.on('data', (chunk) => {
|
|
181
|
+
if (stderr.length < 4096)
|
|
182
|
+
stderr += chunk.toString('utf-8');
|
|
183
|
+
});
|
|
184
|
+
child.on('error', reject);
|
|
185
|
+
child.on('close', (code) => {
|
|
186
|
+
if (code !== 0 && total === 0) {
|
|
187
|
+
reject(new Error(`${cmd} exited with code ${code}: ${stderr.trim()}`));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
resolve(tailBuffer(kept, maxBytes, total));
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function readJson(file) {
|
|
195
|
+
try {
|
|
196
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
197
|
+
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function listDir(dir) {
|
|
204
|
+
try {
|
|
205
|
+
return fs.readdirSync(dir).sort();
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
return [];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function spoolStats(spoolRoot) {
|
|
212
|
+
const out = [];
|
|
213
|
+
for (const dir of listDir(spoolRoot)) {
|
|
214
|
+
for (const signal of listDir(path.join(spoolRoot, dir))) {
|
|
215
|
+
const signalDir = path.join(spoolRoot, dir, signal);
|
|
216
|
+
let files = 0;
|
|
217
|
+
let bytes = 0;
|
|
218
|
+
let oldest = null;
|
|
219
|
+
for (const name of listDir(signalDir)) {
|
|
220
|
+
if (!name.endsWith('.pb'))
|
|
221
|
+
continue;
|
|
222
|
+
try {
|
|
223
|
+
bytes += fs.statSync(path.join(signalDir, name)).size;
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
files += 1;
|
|
229
|
+
const ts = Number(name.slice(0, 13));
|
|
230
|
+
if (Number.isFinite(ts) && (oldest === null || ts < oldest))
|
|
231
|
+
oldest = ts;
|
|
232
|
+
}
|
|
233
|
+
if (files > 0) {
|
|
234
|
+
out.push({
|
|
235
|
+
dir,
|
|
236
|
+
signal,
|
|
237
|
+
files,
|
|
238
|
+
bytes,
|
|
239
|
+
oldest_at: oldest === null ? null : new Date(oldest).toISOString(),
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
function agentDirStats(stateDir) {
|
|
247
|
+
const out = [];
|
|
248
|
+
for (const agentId of listDir(path.join(stateDir, 'agents'))) {
|
|
249
|
+
try {
|
|
250
|
+
// The per-agent layout resolvers reject names that are not agent ids
|
|
251
|
+
// (a stray .DS_Store); those are not agents and are skipped.
|
|
252
|
+
out.push({
|
|
253
|
+
agent_id: agentId,
|
|
254
|
+
workspace: fs.existsSync(agentWorkspaceDirFor(stateDir, agentId)),
|
|
255
|
+
home: fs.existsSync(agentHomeDirFor(stateDir, agentId)),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
// not an agent directory
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
function withBudget(promise, ms, fallback) {
|
|
265
|
+
return new Promise((resolve) => {
|
|
266
|
+
// Deliberately NOT unref'd: the timer is the only thing keeping the loop
|
|
267
|
+
// alive while a stuck probe never settles, and it is cleared the moment
|
|
268
|
+
// the probe answers.
|
|
269
|
+
const timer = setTimeout(() => resolve(fallback), ms);
|
|
270
|
+
promise.then((v) => {
|
|
271
|
+
clearTimeout(timer);
|
|
272
|
+
resolve(v);
|
|
273
|
+
}, () => {
|
|
274
|
+
clearTimeout(timer);
|
|
275
|
+
resolve(fallback);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
export async function collectDiagnostics(opts = {}) {
|
|
280
|
+
const env = opts.env ?? process.env;
|
|
281
|
+
const now = opts.now ?? (() => new Date());
|
|
282
|
+
const configDir = daemonConfigDir(env);
|
|
283
|
+
const bundleDir = resolveBundleDir(env);
|
|
284
|
+
const rawConfig = readJson(path.join(configDir, 'config.json')) ?? {};
|
|
285
|
+
const apiKey = typeof rawConfig.api_key === 'string' ? rawConfig.api_key : '';
|
|
286
|
+
const config = {};
|
|
287
|
+
for (const key of CONFIG_KEYS_ALLOWLIST) {
|
|
288
|
+
if (key in rawConfig)
|
|
289
|
+
config[key] = allowlistedValue(key, rawConfig[key], [apiKey]);
|
|
290
|
+
}
|
|
291
|
+
const stateDir = resolveRootStateDir(env);
|
|
292
|
+
const manifest = loadLocalManifest(bundleDir);
|
|
293
|
+
const manifestVersion = typeof manifest?.version === 'string' ? manifest.version : null;
|
|
294
|
+
const bundleVersions = listDir(path.join(bundleDir, 'versions'));
|
|
295
|
+
// The runtime probe and the log source are independent; overlap them.
|
|
296
|
+
const [detected, log] = await Promise.all([
|
|
297
|
+
withBudget(opts.detect ? opts.detect() : detectRuntimes(env, { info() { }, warn() { } }), opts.detectBudgetMs ?? DIAGNOSTICS_DETECT_BUDGET_MS, null),
|
|
298
|
+
opts.logSource ? opts.logSource() : defaultLogSource(env),
|
|
299
|
+
]);
|
|
300
|
+
const runtimeReport = detected === null
|
|
301
|
+
? { skipped: 'timeout' }
|
|
302
|
+
: buildMachineRuntimeReport({
|
|
303
|
+
daemonVersion: manifestVersion ?? undefined,
|
|
304
|
+
selfUpdateCapable: isSelfUpdateManaged(bundleDir, env),
|
|
305
|
+
detected,
|
|
306
|
+
runtimeTypes: DETECTABLE_RUNTIME_TYPES,
|
|
307
|
+
});
|
|
308
|
+
const present = Object.keys(env)
|
|
309
|
+
.filter((k) => k.startsWith('PRLL_'))
|
|
310
|
+
.sort();
|
|
311
|
+
const values = {};
|
|
312
|
+
for (const key of present) {
|
|
313
|
+
if (ENV_VALUE_ALLOWLIST.has(key) && env[key]) {
|
|
314
|
+
values[key] = allowlistedValue(key, env[key], [apiKey]);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const redacted = redactSecrets(log.text, [apiKey]);
|
|
318
|
+
return {
|
|
319
|
+
schema_version: DIAGNOSTICS_SCHEMA_VERSION,
|
|
320
|
+
created_at: now().toISOString(),
|
|
321
|
+
manifest: {
|
|
322
|
+
daemon_version: resolveServiceVersion(opts.importMetaUrl ?? import.meta.url),
|
|
323
|
+
bundle_manifest_version: manifestVersion,
|
|
324
|
+
platform: process.platform,
|
|
325
|
+
arch: process.arch,
|
|
326
|
+
node_version: process.versions.node,
|
|
327
|
+
os_release: os.release(),
|
|
328
|
+
hostname_length: os.hostname().length,
|
|
329
|
+
config_dir: configDir,
|
|
330
|
+
bundle_dir: bundleDir,
|
|
331
|
+
state_dir: stateDir,
|
|
332
|
+
},
|
|
333
|
+
config,
|
|
334
|
+
update_state: loadUpdateState(bundleDir),
|
|
335
|
+
bundle_versions: bundleVersions,
|
|
336
|
+
runtime_report: runtimeReport,
|
|
337
|
+
spool: spoolStats(path.join(configDir, 'otel-spool')),
|
|
338
|
+
agents: agentDirStats(stateDir),
|
|
339
|
+
env: { present, values, proxy: proxyEnvNames(env) },
|
|
340
|
+
log: {
|
|
341
|
+
source: log.source,
|
|
342
|
+
truncated: log.truncated,
|
|
343
|
+
bytes: Buffer.byteLength(redacted, 'utf-8'),
|
|
344
|
+
text: redacted,
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
/** The wire form: gzip of the JSON document. */
|
|
349
|
+
export function serializeBundle(bundle) {
|
|
350
|
+
return zlib.gzipSync(Buffer.from(JSON.stringify(bundle), 'utf-8'), { level: 9 });
|
|
351
|
+
}
|
|
352
|
+
export async function uploadDiagnostics(client, bundle, note) {
|
|
353
|
+
const bytes = serializeBundle(bundle);
|
|
354
|
+
return client.uploadMachineDiagnostics(new Uint8Array(bytes), {
|
|
355
|
+
daemon_version: bundle.manifest.daemon_version,
|
|
356
|
+
...(note ? { note } : {}),
|
|
357
|
+
});
|
|
358
|
+
}
|