@kvell007/embed-labs-local-bridge 0.1.0-alpha.21 → 0.1.0-alpha.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +16 -11
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.js +125 -4
  4. package/package.json +8 -4
  5. package/dist/adapters/debug.d.ts +0 -2
  6. package/dist/adapters/debug.js +0 -124
  7. package/dist/adapters/debug.js.map +0 -1
  8. package/dist/adapters/deploy.d.ts +0 -5
  9. package/dist/adapters/deploy.js +0 -132
  10. package/dist/adapters/deploy.js.map +0 -1
  11. package/dist/adapters/flash.d.ts +0 -3
  12. package/dist/adapters/flash.js +0 -169
  13. package/dist/adapters/flash.js.map +0 -1
  14. package/dist/adapters/logo.d.ts +0 -2
  15. package/dist/adapters/logo.js +0 -108
  16. package/dist/adapters/logo.js.map +0 -1
  17. package/dist/adapters/network.d.ts +0 -22
  18. package/dist/adapters/network.js +0 -64
  19. package/dist/adapters/network.js.map +0 -1
  20. package/dist/adapters/rp2350-monitor.d.ts +0 -121
  21. package/dist/adapters/rp2350-monitor.js +0 -404
  22. package/dist/adapters/rp2350-monitor.js.map +0 -1
  23. package/dist/adapters/serial.d.ts +0 -3
  24. package/dist/adapters/serial.js +0 -133
  25. package/dist/adapters/serial.js.map +0 -1
  26. package/dist/adapters/taishanpi-live.d.ts +0 -163
  27. package/dist/adapters/taishanpi-live.js +0 -349
  28. package/dist/adapters/taishanpi-live.js.map +0 -1
  29. package/dist/adapters/uf2.d.ts +0 -1
  30. package/dist/adapters/uf2.js +0 -53
  31. package/dist/adapters/uf2.js.map +0 -1
  32. package/dist/adapters/usb.d.ts +0 -3
  33. package/dist/adapters/usb.js +0 -102
  34. package/dist/adapters/usb.js.map +0 -1
  35. package/dist/hardware.d.ts +0 -19
  36. package/dist/hardware.js +0 -417
  37. package/dist/hardware.js.map +0 -1
  38. package/dist/index.js.map +0 -1
  39. package/dist/jobs.d.ts +0 -4
  40. package/dist/jobs.js +0 -125
  41. package/dist/jobs.js.map +0 -1
  42. package/dist/process.d.ts +0 -13
  43. package/dist/process.js +0 -128
  44. package/dist/process.js.map +0 -1
  45. package/dist/server.d.ts +0 -7
  46. package/dist/server.js +0 -399
  47. package/dist/server.js.map +0 -1
  48. package/dist/tools.d.ts +0 -3
  49. package/dist/tools.js +0 -1254
  50. package/dist/tools.js.map +0 -1
package/README.md CHANGED
@@ -12,8 +12,12 @@ are complete.
12
12
 
13
13
  ## What It Provides
14
14
 
15
- - `embed-local-bridge` binary.
16
- - `startServer()` library entry point.
15
+ - `embed-local-bridge` npm launcher.
16
+ - Native Go bridge binaries delivered through platform optional packages:
17
+ `@embed-labs/local-bridge-darwin-arm64`,
18
+ `@embed-labs/local-bridge-linux-x64`,
19
+ `@embed-labs/local-bridge-linux-arm64`, and
20
+ `@embed-labs/local-bridge-win32-x64`.
17
21
  - Local health endpoint.
18
22
  - Device discovery for serial ports, RP2350-compatible UF2 volumes, Rockchip
19
23
  USB Loader/Maskrom style devices, and the current TaishanPi USB ECM probe.
@@ -21,7 +25,7 @@ are complete.
21
25
  - Non-destructive debug tool availability scans for OpenOCD, probe-rs, pyOCD,
22
26
  and SEGGER J-Link command-line tools.
23
27
  - Flash plan endpoints and local job tracking.
24
- - Shared response contracts from `@embed-labs/protocol`.
28
+ - Stable HTTP/JSON response contracts used by the CLI and agent plugins.
25
29
 
26
30
  ## Install
27
31
 
@@ -50,19 +54,17 @@ The bridge listens on `127.0.0.1:18083` by default.
50
54
  EMBED_BRIDGE_HOST=127.0.0.1 EMBED_BRIDGE_PORT=18083 embed-local-bridge
51
55
  ```
52
56
 
53
- Library usage:
54
-
55
- ```ts
56
- import { startServer } from "@embed-labs/local-bridge";
57
-
58
- const server = startServer({ host: "127.0.0.1", port: 18083 });
59
- ```
57
+ This package no longer exports a TypeScript `startServer()` runtime. It is a
58
+ small JavaScript launcher for the Go binary. If optional dependencies were
59
+ omitted during install, reinstall without `--omit=optional`.
60
60
 
61
61
  ## HTTP Surface
62
62
 
63
63
  - `GET /healthz`
64
64
  - `GET /v1/devices`
65
65
  - `GET /v1/debug/tools`
66
+ - `GET /v1/tools/capabilities`
67
+ - `POST /v1/tools/invoke`
66
68
  - `POST /v1/devices/probe`
67
69
  - `GET /v1/serial/ports`
68
70
  - `POST /v1/serial/capture`
@@ -71,6 +73,8 @@ const server = startServer({ host: "127.0.0.1", port: 18083 });
71
73
  - `POST /v1/flash/run`
72
74
  - `GET /v1/jobs`
73
75
  - `GET /v1/jobs/<local_job_id>`
76
+ - RP2350 Monitor paths: `GET /api/health`, `GET /api/snapshot`,
77
+ `POST /api/operation`, `GET /api/stream`, and `/rp2350-monitor/`.
74
78
 
75
79
  Examples:
76
80
 
@@ -114,7 +118,8 @@ claims.
114
118
 
115
119
  ## Runtime Requirements
116
120
 
117
- - Node.js 20 or newer.
121
+ - Node.js 20 or newer for the npm launcher.
122
+ - The matching native optional package for the current OS/CPU.
118
123
  - Optional platform tools depending on the requested action, such as OpenSSH
119
124
  for `POST /v1/ssh/run`, `rkdeveloptool` for TaishanPi planning checks, and
120
125
  debug tools such as `openocd`, `probe-rs`, `pyocd`, `JLinkExe`, and
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  #!/usr/bin/env node
2
- export { startServer } from "./server.js";
2
+ export declare function resolveBridgeBinary(): string;
3
+ export declare function startBridgeProcess(args?: string[]): Promise<number>;
package/dist/index.js CHANGED
@@ -1,10 +1,131 @@
1
1
  #!/usr/bin/env node
2
- import { realpathSync } from "node:fs";
2
+ import { spawn } from "node:child_process";
3
+ import { accessSync, constants, realpathSync } from "node:fs";
4
+ import { createRequire } from "node:module";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { arch, platform } from "node:os";
3
7
  import { fileURLToPath } from "node:url";
4
- import { startServer } from "./server.js";
5
- export { startServer } from "./server.js";
8
+ const require = createRequire(import.meta.url);
9
+ const TARGETS = {
10
+ "darwin-arm64": {
11
+ packageName: "@embed-labs/local-bridge-darwin-arm64",
12
+ artifactDir: "darwin-arm64",
13
+ binaryName: "embed-local-bridge"
14
+ },
15
+ "linux-x64": {
16
+ packageName: "@embed-labs/local-bridge-linux-x64",
17
+ artifactDir: "linux-x64",
18
+ binaryName: "embed-local-bridge"
19
+ },
20
+ "linux-arm64": {
21
+ packageName: "@embed-labs/local-bridge-linux-arm64",
22
+ artifactDir: "linux-arm64",
23
+ binaryName: "embed-local-bridge"
24
+ },
25
+ "win32-x64": {
26
+ packageName: "@embed-labs/local-bridge-win32-x64",
27
+ artifactDir: "win32-x64",
28
+ binaryName: "embed-local-bridge.exe"
29
+ }
30
+ };
31
+ export function resolveBridgeBinary() {
32
+ const explicit = process.env.EMBED_LOCAL_BRIDGE_BINARY?.trim();
33
+ if (explicit) {
34
+ return assertExecutable(explicit, `EMBED_LOCAL_BRIDGE_BINARY points to a non-executable file: ${explicit}`);
35
+ }
36
+ const targetKey = `${platform()}-${arch()}`;
37
+ const target = TARGETS[targetKey];
38
+ if (!target) {
39
+ throw new Error(`Embed Labs Local Bridge does not provide a native binary for ${targetKey}. Supported targets: ${Object.keys(TARGETS).join(", ")}.`);
40
+ }
41
+ const packagedBinary = resolvePackagedBinary(target);
42
+ if (packagedBinary) {
43
+ return packagedBinary;
44
+ }
45
+ const repoBinary = resolveRepoArtifactBinary(target);
46
+ if (repoBinary) {
47
+ return repoBinary;
48
+ }
49
+ throw new Error([
50
+ `Embed Labs Local Bridge native package is missing for ${targetKey}.`,
51
+ `Expected optional dependency ${target.packageName}.`,
52
+ "Reinstall without omitting optional dependencies:",
53
+ " npm install",
54
+ "or install the CLI package again without --omit=optional.",
55
+ "For source-tree development, run npm run build:bridge-go first."
56
+ ].join("\n"));
57
+ }
58
+ export function startBridgeProcess(args = process.argv.slice(2)) {
59
+ const binary = resolveBridgeBinary();
60
+ const child = spawn(binary, args, {
61
+ stdio: "inherit",
62
+ env: process.env
63
+ });
64
+ const forwardSignal = (signal) => {
65
+ if (!child.killed) {
66
+ child.kill(signal);
67
+ }
68
+ };
69
+ process.once("SIGINT", forwardSignal);
70
+ process.once("SIGTERM", forwardSignal);
71
+ return new Promise((resolve) => {
72
+ child.on("error", (error) => {
73
+ console.error(error instanceof Error ? error.message : String(error));
74
+ resolve(1);
75
+ });
76
+ child.on("close", (code, signal) => {
77
+ process.off("SIGINT", forwardSignal);
78
+ process.off("SIGTERM", forwardSignal);
79
+ if (signal) {
80
+ resolve(signal === "SIGINT" || signal === "SIGTERM" ? 0 : 1);
81
+ }
82
+ else {
83
+ resolve(code ?? 0);
84
+ }
85
+ });
86
+ });
87
+ }
6
88
  if (isDirectRun()) {
7
- startServer();
89
+ startBridgeProcess().then((code) => {
90
+ process.exitCode = code;
91
+ });
92
+ }
93
+ function resolvePackagedBinary(target) {
94
+ try {
95
+ const packageJson = require.resolve(`${target.packageName}/package.json`);
96
+ return assertExecutable(join(dirname(packageJson), "bin", target.binaryName), "");
97
+ }
98
+ catch {
99
+ return undefined;
100
+ }
101
+ }
102
+ function resolveRepoArtifactBinary(target) {
103
+ const here = dirname(fileURLToPath(import.meta.url));
104
+ const candidates = [
105
+ resolve(here, "../../../artifacts/local-bridge-bin", target.artifactDir, target.binaryName),
106
+ resolve(here, "../../artifacts/local-bridge-bin", target.artifactDir, target.binaryName)
107
+ ];
108
+ for (const candidate of candidates) {
109
+ try {
110
+ return assertExecutable(candidate, "");
111
+ }
112
+ catch {
113
+ // Keep searching fallback candidates.
114
+ }
115
+ }
116
+ return undefined;
117
+ }
118
+ function assertExecutable(path, message) {
119
+ try {
120
+ accessSync(path, constants.X_OK);
121
+ }
122
+ catch (error) {
123
+ if (message) {
124
+ throw new Error(message);
125
+ }
126
+ throw error;
127
+ }
128
+ return path;
8
129
  }
9
130
  function isDirectRun() {
10
131
  if (!process.argv[1]) {
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@kvell007/embed-labs-local-bridge",
3
- "version": "0.1.0-alpha.21",
3
+ "version": "0.1.0-alpha.22",
4
4
  "description": "Local hardware bridge service for Embed Labs Cloud. Experimental npm publish.",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "files": [
10
- "dist",
10
+ "dist/index.js",
11
+ "dist/index.d.ts",
11
12
  "README.md"
12
13
  ],
13
14
  "engines": {
@@ -16,8 +17,11 @@
16
17
  "bin": {
17
18
  "embed-local-bridge": "dist/index.js"
18
19
  },
19
- "dependencies": {
20
- "@embed-labs/protocol": "npm:@kvell007/embed-labs-protocol@0.1.0-alpha.21"
20
+ "optionalDependencies": {
21
+ "@embed-labs/local-bridge-darwin-arm64": "npm:@kvell007/embed-labs-local-bridge-darwin-arm64@0.1.0-alpha.22",
22
+ "@embed-labs/local-bridge-linux-arm64": "npm:@kvell007/embed-labs-local-bridge-linux-arm64@0.1.0-alpha.22",
23
+ "@embed-labs/local-bridge-linux-x64": "npm:@kvell007/embed-labs-local-bridge-linux-x64@0.1.0-alpha.22",
24
+ "@embed-labs/local-bridge-win32-x64": "npm:@kvell007/embed-labs-local-bridge-win32-x64@0.1.0-alpha.22"
21
25
  },
22
26
  "publishConfig": {
23
27
  "access": "public",
@@ -1,2 +0,0 @@
1
- import type { DebugToolScanResult } from "@embed-labs/protocol";
2
- export declare function scanDebugTools(): Promise<DebugToolScanResult>;
@@ -1,124 +0,0 @@
1
- import { resolveCommand, runCommand, tailLines } from "../process.js";
2
- const VERSION_TIMEOUT_MS = 2500;
3
- const DEBUG_TOOLS = [
4
- {
5
- tool_id: "openocd",
6
- display_name: "OpenOCD",
7
- command: "openocd",
8
- version_args: ["--version"]
9
- },
10
- {
11
- tool_id: "probe-rs",
12
- display_name: "probe-rs",
13
- command: "probe-rs",
14
- version_args: ["--version"]
15
- },
16
- {
17
- tool_id: "pyocd",
18
- display_name: "pyOCD",
19
- command: "pyocd",
20
- version_args: ["--version"]
21
- },
22
- {
23
- tool_id: "jlink-commander",
24
- display_name: "SEGGER J-Link Commander",
25
- command: "JLinkExe",
26
- version_args: ["-?"]
27
- },
28
- {
29
- tool_id: "jlink-gdb-server",
30
- display_name: "SEGGER J-Link GDB Server",
31
- command: "JLinkGDBServerCLExe",
32
- version_args: ["-?"]
33
- }
34
- ];
35
- export async function scanDebugTools() {
36
- const observedAt = new Date().toISOString();
37
- const tools = await Promise.all(DEBUG_TOOLS.map((tool) => scanDebugTool(tool, observedAt)));
38
- const availableCount = tools.filter((tool) => tool.available).length;
39
- return {
40
- tools,
41
- observed_at: observedAt,
42
- summary_for_user: `Debug tool scan finished: ${availableCount}/${tools.length} tools available. No debug sessions or probe connections were opened.`
43
- };
44
- }
45
- async function scanDebugTool(spec, observedAt) {
46
- const evidence = [];
47
- const resolvedPath = await resolveCommand(spec.command);
48
- evidence.push({
49
- evidence_id: evidenceId(spec.tool_id, "path", observedAt),
50
- tool_id: spec.tool_id,
51
- kind: "path_lookup",
52
- command: spec.command,
53
- observed_at: observedAt,
54
- available: resolvedPath !== undefined,
55
- resolved_path: resolvedPath,
56
- summary: resolvedPath
57
- ? `Found ${spec.command} on PATH or an Embed Labs local toolchain path.`
58
- : `${spec.command} was not found on PATH or an Embed Labs local toolchain path.`
59
- });
60
- if (!resolvedPath) {
61
- return {
62
- tool_id: spec.tool_id,
63
- display_name: spec.display_name,
64
- command: spec.command,
65
- available: false,
66
- evidence,
67
- summary_for_user: `${spec.display_name} is not available on PATH or an Embed Labs local toolchain path.`
68
- };
69
- }
70
- const versionResult = await runCommand(resolvedPath, spec.version_args, VERSION_TIMEOUT_MS);
71
- const stdoutTail = tailLines(versionResult.stdout, 8);
72
- const stderrTail = tailLines(versionResult.stderr, 8);
73
- const version = extractVersionLine(`${versionResult.stdout}\n${versionResult.stderr}`);
74
- evidence.push({
75
- evidence_id: evidenceId(spec.tool_id, "version", observedAt),
76
- tool_id: spec.tool_id,
77
- kind: "version_command",
78
- command: spec.command,
79
- args: spec.version_args,
80
- observed_at: observedAt,
81
- exit_code: versionResult.exit_code,
82
- timed_out: versionResult.timed_out,
83
- stdout_tail: stdoutTail.length > 0 ? stdoutTail : undefined,
84
- stderr_tail: stderrTail.length > 0 ? stderrTail : undefined,
85
- error_code: versionResult.timed_out
86
- ? "version_command_timeout"
87
- : versionResult.exit_code === 0
88
- ? undefined
89
- : "version_command_nonzero",
90
- error_message: versionResult.timed_out
91
- ? `Version/help command exceeded ${VERSION_TIMEOUT_MS}ms.`
92
- : versionResult.exit_code === 0
93
- ? undefined
94
- : `Version/help command exited with code ${versionResult.exit_code ?? "unknown"}.`,
95
- summary: versionResult.timed_out
96
- ? `${spec.command} was found, but the bounded version/help command timed out.`
97
- : versionResult.exit_code === 0
98
- ? `${spec.command} version/help command completed.`
99
- : `${spec.command} was found, but its version/help command exited non-zero.`
100
- });
101
- return {
102
- tool_id: spec.tool_id,
103
- display_name: spec.display_name,
104
- command: spec.command,
105
- available: true,
106
- version,
107
- evidence,
108
- summary_for_user: version
109
- ? `${spec.display_name} is available (${version}).`
110
- : `${spec.display_name} is available; version output was not recognized.`
111
- };
112
- }
113
- function extractVersionLine(output) {
114
- return output
115
- .split(/\r?\n/)
116
- .map((line) => line.trim())
117
- .find((line) => line.length > 0)
118
- ?.slice(0, 160);
119
- }
120
- function evidenceId(toolId, kind, observedAt) {
121
- const stableTime = observedAt.replace(/[^0-9]/g, "");
122
- return `debug_${toolId}_${kind}_${stableTime}`;
123
- }
124
- //# sourceMappingURL=debug.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/adapters/debug.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAStE,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,WAAW,GAAoB;IACnC;QACE,OAAO,EAAE,SAAS;QAClB,YAAY,EAAE,SAAS;QACvB,OAAO,EAAE,SAAS;QAClB,YAAY,EAAE,CAAC,WAAW,CAAC;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CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,mDAAmD;KAC5E,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAc;IACxC,OAAO,MAAM;SACV,KAAK,CAAC,OAAO,CAAC;SACd,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,UAAU,CAAC,MAAmB,EAAE,IAAY,EAAE,UAAkB;IACvE,MAAM,UAAU,GAAG,UAAU,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACrD,OAAO,SAAS,MAAM,IAAI,IAAI,IAAI,UAAU,EAAE,CAAC;AACjD,CAAC"}
@@ -1,5 +0,0 @@
1
- import type { BoardDeployRequest, BoardDeployResult, ErrorEnvelope } from "@embed-labs/protocol";
2
- export declare function deployTaishanPiArtifact(request: BoardDeployRequest): Promise<BoardDeployResult | {
3
- ok: false;
4
- error: ErrorEnvelope;
5
- }>;
@@ -1,132 +0,0 @@
1
- import { readFile, stat } from "node:fs/promises";
2
- import { posix } from "node:path";
3
- import { commandExists, runCommand, tailLines } from "../process.js";
4
- const DEFAULT_REMOTE_PATH = "/userdata/embed-labs/apps/app";
5
- const REMOTE_ROOT = "/userdata/embed-labs/apps";
6
- const MAX_ARTIFACT_BYTES = 16 * 1024 * 1024;
7
- export async function deployTaishanPiArtifact(request) {
8
- const observedAt = new Date().toISOString();
9
- if (request.board_id !== "taishanpi") {
10
- return failDeploy("unsupported_board", `board_id must be taishanpi, got ${request.board_id}.`);
11
- }
12
- const host = request.host.trim();
13
- const user = request.user?.trim() || "root";
14
- const remotePath = normalizeRemotePath(request.remote_path ?? DEFAULT_REMOTE_PATH);
15
- const timeoutSeconds = clampTimeoutSeconds(request.timeout_seconds);
16
- if (!remotePath) {
17
- return failDeploy("invalid_remote_path", `remote_path must stay under ${REMOTE_ROOT} and contain only safe path characters.`);
18
- }
19
- if (!/^[A-Za-z0-9._-]{1,64}$/.test(user)) {
20
- return failDeploy("invalid_user", "SSH user must contain only letters, numbers, dots, underscores, or hyphens.");
21
- }
22
- if (!await commandExists("ssh")) {
23
- return failDeploy("ssh_not_found", "ssh binary was not found on PATH.", "Install OpenSSH client or add ssh to PATH.");
24
- }
25
- const artifactStat = await stat(request.artifact_path).catch(() => undefined);
26
- if (!artifactStat?.isFile()) {
27
- return failDeploy("artifact_file_not_found", `Local artifact file is not available: ${request.artifact_path}`);
28
- }
29
- if (artifactStat.size > MAX_ARTIFACT_BYTES) {
30
- return failDeploy("artifact_file_too_large", `Local Bridge deploy currently accepts artifacts up to ${MAX_ARTIFACT_BYTES} bytes on the SSH/base64 MVP path.`);
31
- }
32
- const artifactBytes = await readFile(request.artifact_path);
33
- const remoteDir = posix.dirname(remotePath);
34
- const tmpPath = `${remotePath}.tmp.${Date.now()}`;
35
- const logPath = `${remotePath}.log`;
36
- const pidPath = `${remotePath}.pid`;
37
- const upload = await ssh(host, user, [
38
- `mkdir -p ${shellQuote(remoteDir)}`,
39
- "umask 077",
40
- `base64 -d > ${shellQuote(tmpPath)}`,
41
- `chmod 0755 ${shellQuote(tmpPath)}`,
42
- `mv -f ${shellQuote(tmpPath)} ${shellQuote(remotePath)}`
43
- ].join(" && "), timeoutSeconds, artifactBytes.toString("base64"));
44
- if (upload.exit_code !== 0) {
45
- return commandFailure(upload.timed_out ? "artifact_upload_timeout" : "artifact_upload_failed", "Failed to upload the artifact to the board over SSH/base64.", upload);
46
- }
47
- let runResult;
48
- if (request.run === true) {
49
- runResult = await ssh(host, user, [
50
- `cd ${shellQuote(remoteDir)}`,
51
- `(nohup ${shellQuote(remotePath)} > ${shellQuote(logPath)} 2>&1 < /dev/null & printf '%s' "$!" > ${shellQuote(pidPath)})`,
52
- "sleep 1",
53
- "printf 'pid='",
54
- `cat ${shellQuote(pidPath)}`,
55
- "printf '\\n'",
56
- `tail -n 40 ${shellQuote(logPath)} 2>/dev/null || true`
57
- ].join(" && "), timeoutSeconds);
58
- if (runResult.exit_code !== 0) {
59
- return commandFailure(runResult.timed_out ? "artifact_run_timeout" : "artifact_run_failed", "The artifact was deployed, but the start/log command failed.", runResult);
60
- }
61
- }
62
- return {
63
- board_id: "taishanpi",
64
- host,
65
- user,
66
- artifact_path: request.artifact_path,
67
- artifact_size_bytes: artifactStat.size,
68
- remote_path: remotePath,
69
- deployed: true,
70
- ran: request.run === true && runResult?.exit_code === 0,
71
- remote_pid: runResult ? extractPid(runResult.stdout) : undefined,
72
- log_path: logPath,
73
- exit_code: runResult?.exit_code,
74
- stdout: runResult?.stdout,
75
- stderr: runResult?.stderr,
76
- output_tail: runResult ? tailLines(`${runResult.stdout}\n${runResult.stderr}`) : tailLines(`${upload.stdout}\n${upload.stderr}`),
77
- observed_at: observedAt
78
- };
79
- }
80
- async function ssh(host, user, command, timeoutSeconds, stdin) {
81
- return runCommand("ssh", [
82
- "-o", "BatchMode=yes",
83
- "-o", "UserKnownHostsFile=/dev/null",
84
- "-o", "StrictHostKeyChecking=no",
85
- "-o", `ConnectTimeout=${Math.max(1, Math.min(timeoutSeconds, 30))}`,
86
- `${user}@${host}`,
87
- command
88
- ], timeoutSeconds * 1000 + 1000, stdin);
89
- }
90
- function normalizeRemotePath(input) {
91
- if (!input.startsWith("/") || /[\u0000-\u001f\u007f]/.test(input)) {
92
- return undefined;
93
- }
94
- const normalized = posix.normalize(input);
95
- if (normalized === REMOTE_ROOT || !normalized.startsWith(`${REMOTE_ROOT}/`)) {
96
- return undefined;
97
- }
98
- if (!/^\/[A-Za-z0-9._/-]+$/.test(normalized) || normalized.endsWith("/")) {
99
- return undefined;
100
- }
101
- return normalized;
102
- }
103
- function clampTimeoutSeconds(value) {
104
- const timeout = Number.isFinite(value) ? Number(value) : 30;
105
- return Math.max(5, Math.min(Math.trunc(timeout), 120));
106
- }
107
- function failDeploy(code, message, remediation) {
108
- return { ok: false, error: { code, message, remediation } };
109
- }
110
- function commandFailure(code, message, result) {
111
- return {
112
- ok: false,
113
- error: {
114
- code,
115
- message,
116
- details: {
117
- exit_code: result.exit_code,
118
- stdout: result.stdout,
119
- stderr: result.stderr,
120
- timed_out: result.timed_out
121
- }
122
- }
123
- };
124
- }
125
- function shellQuote(value) {
126
- return `'${value.replace(/'/g, "'\\''")}'`;
127
- }
128
- function extractPid(stdout) {
129
- const match = stdout.match(/^pid=(\d+)/m);
130
- return match?.[1];
131
- }
132
- //# sourceMappingURL=deploy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/adapters/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAErE,MAAM,mBAAmB,GAAG,+BAA+B,CAAC;AAC5D,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAChD,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,OAA2B;IACvE,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC5C,IAAI,OAAO,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;QACrC,OAAO,UAAU,CAAC,mBAAmB,EAAE,mCAAmC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACjG,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACjC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,MAAM,CA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J,OAAO;YACP,OAAO,EAAE;gBACP,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,SAAS,EAAE,MAAM,CAAC,SAAS;aAC5B;SACF;KACO,CAAC;AACb,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;AAC7C,CAAC;AAED,SAAS,UAAU,CAAC,MAAc;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC1C,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { FlashPlan, FlashPlanRequest } from "@embed-labs/protocol";
2
- export declare function buildFlashPlan(request: FlashPlanRequest): Promise<FlashPlan>;
3
- export declare function executeRp2350Uf2Flash(plan: FlashPlan): Promise<Record<string, unknown>>;