Showing the changes to apps/cli/src (5 of 265 files). Show all
Unified · Split
| @@ -68,8 +68,7 @@ const platformName = (t: Target) => (t.os === "win32" ? "windows" : t.os); · 67 unmodified lines | |||
| 68 | /** Per-platform suffix used in dist directory names, npm dist-tags, and the | 68 | /** Per-platform suffix used in dist directory names, npm dist-tags, and the |
| 69 | * semver prerelease segment of variant package versions. e.g. "linux-x64", | 69 | * semver prerelease segment of variant package versions. e.g. "linux-x64", |
| 70 | * "linux-x64-musl", "darwin-arm64". */ | 70 | * "linux-x64-musl", "darwin-arm64". */ |
| 71 | const platformTag = (t: Target) => | 71 | const platformTag = (t: Target) => [platformName(t), t.arch, t.abi].filter(Boolean).join("-"); |
| 72 | [platformName(t), t.arch, t.abi].filter(Boolean).join("-"); | ||
| 73 | 72 | ||
| 74 | /** Dist directory name (e.g. dist/executor-linux-x64). Only used as a build | 73 | /** Dist directory name (e.g. dist/executor-linux-x64). Only used as a build |
| 75 | * artifact convention; the actual npm package name inside is `executor`. */ | 74 | * artifact convention; the actual npm package name inside is `executor`. */ |
| @@ -126,7 +125,10 @@ const resolveKeyringNative = (t: Target): string | null => { · 50 unmodified lines | |||
| 126 | const platformMap: Record<string, { pkg: string; node: string }> = { | 125 | const platformMap: Record<string, { pkg: string; node: string }> = { |
| 127 | "darwin-arm64": { pkg: "@napi-rs/keyring-darwin-arm64", node: "keyring.darwin-arm64.node" }, | 126 | "darwin-arm64": { pkg: "@napi-rs/keyring-darwin-arm64", node: "keyring.darwin-arm64.node" }, |
| 128 | "darwin-x64": { pkg: "@napi-rs/keyring-darwin-x64", node: "keyring.darwin-x64.node" }, | 127 | "darwin-x64": { pkg: "@napi-rs/keyring-darwin-x64", node: "keyring.darwin-x64.node" }, |
| 129 | "linux-arm64": { pkg: "@napi-rs/keyring-linux-arm64-gnu", node: "keyring.linux-arm64-gnu.node" }, | 128 | "linux-arm64": { |
| 129 | pkg: "@napi-rs/keyring-linux-arm64-gnu", | ||
| 130 | node: "keyring.linux-arm64-gnu.node", | ||
| 131 | }, | ||
| 130 | "linux-x64": { pkg: "@napi-rs/keyring-linux-x64-gnu", node: "keyring.linux-x64-gnu.node" }, | 132 | "linux-x64": { pkg: "@napi-rs/keyring-linux-x64-gnu", node: "keyring.linux-x64-gnu.node" }, |
| 131 | "linux-arm64-musl": { | 133 | "linux-arm64-musl": { |
| 132 | pkg: "@napi-rs/keyring-linux-arm64-musl", | 134 | pkg: "@napi-rs/keyring-linux-arm64-musl", |
| @@ -146,9 +148,7 @@ const resolveKeyringNative = (t: Target): string | null => { · 13 unmodified lines | |||
| 146 | const entry = platformMap[key]; | 148 | const entry = platformMap[key]; |
| 147 | if (!entry) return null; | 149 | if (!entry) return null; |
| 148 | try { | 150 | try { |
| 149 | const req = createRequire( | 151 | const req = createRequire(join(repoRoot, "node_modules", "@napi-rs/keyring", "package.json")); |
| 150 | join(repoRoot, "node_modules", "@napi-rs/keyring", "package.json"), | ||
| 151 | ); | ||
| 152 | const pkgJson = req.resolve(`${entry.pkg}/package.json`); | 152 | const pkgJson = req.resolve(`${entry.pkg}/package.json`); |
| 153 | return join(dirname(pkgJson), entry.node); | 153 | return join(dirname(pkgJson), entry.node); |
| 154 | } catch { | 154 | } catch { |
| @@ -455,7 +455,10 @@ const buildPreviewTarballs = async (binaries: Record<string, string>) => { · 300 unmodified lines | |||
| 455 | 455 | ||
| 456 | const resolveTargetsFromEnv = (env: string | undefined): Target[] => { | 456 | const resolveTargetsFromEnv = (env: string | undefined): Target[] => { |
| 457 | if (!env) throw new Error("EXECUTOR_PREVIEW_TARGETS must be set (comma-separated package names)"); | 457 | if (!env) throw new Error("EXECUTOR_PREVIEW_TARGETS must be set (comma-separated package names)"); |
| 458 | const names = env.split(",").map((s) => s.trim()).filter(Boolean); | 458 | const names = env |
| 459 | .split(",") | ||
| 460 | .map((s) => s.trim()) | ||
| 461 | .filter(Boolean); | ||
| 459 | const resolved = names.map((name) => { | 462 | const resolved = names.map((name) => { |
| 460 | const match = ALL_TARGETS.find((t) => targetPackageName(t) === name); | 463 | const match = ALL_TARGETS.find((t) => targetPackageName(t) === name); |
| 461 | if (!match) throw new Error(`Unknown preview target: ${name}`); | 464 | if (!match) throw new Error(`Unknown preview target: ${name}`); |
| @@ -482,10 +485,7 @@ const buildPreviewWrapperPackage = async (targets: Target[]) => { · 20 unmodified lines | |||
| 482 | await writeFile(join(binDir, "executor"), NODE_SHIM); | 485 | await writeFile(join(binDir, "executor"), NODE_SHIM); |
| 483 | await chmod(join(binDir, "executor"), 0o755); | 486 | await chmod(join(binDir, "executor"), 0o755); |
| 484 | 487 | ||
| 485 | const postinstall = PREVIEW_POSTINSTALL_SCRIPT.replaceAll( | 488 | const postinstall = PREVIEW_POSTINSTALL_SCRIPT.replaceAll("__CDN_BASE_URL__", `${cdnUrl}/${sha}`); |
| 486 | "__CDN_BASE_URL__", | ||
| 487 | `${cdnUrl}/${sha}`, | ||
| 488 | ); | ||
| 489 | await writeFile(join(wrapperDir, "postinstall.cjs"), postinstall); | 489 | await writeFile(join(wrapperDir, "postinstall.cjs"), postinstall); |
| 490 | 490 | ||
| 491 | // Restrict os/cpu to platforms we actually built this run so npm refuses | 491 | // Restrict os/cpu to platforms we actually built this run so npm refuses |
| @@ -565,11 +565,10 @@ const publishPackedPackage = async (pkgDir: string, channel: string) => { · 73 unmodified lines | |||
| 565 | await $`bun pm pack`.cwd(pkgDir); | 565 | await $`bun pm pack`.cwd(pkgDir); |
| 566 | 566 | ||
| 567 | const provenance = process.env.GITHUB_ACTIONS === "true" ? ["--provenance"] : []; | 567 | const provenance = process.env.GITHUB_ACTIONS === "true" ? ["--provenance"] : []; |
| 568 | const result = | 568 | const result = await $`npm publish *.tgz --access public --tag ${channel} ${provenance}` |
| 569 | await $`npm publish *.tgz --access public --tag ${channel} ${provenance}` | 569 | .cwd(pkgDir) |
| 570 | .cwd(pkgDir) | 570 | .nothrow() |
| 571 | .nothrow() | 571 | .quiet(); |
| 572 | .quiet(); | ||
| 573 | 572 | ||
| 574 | const stdout = result.stdout.toString(); | 573 | const stdout = result.stdout.toString(); |
| 575 | const stderr = result.stderr.toString(); | 574 | const stderr = result.stderr.toString(); |
| @@ -59,7 +59,8 @@ export const currentDaemonScopeId = (): string => { · 58 unmodified lines | |||
| 59 | const resolveDaemonDataDir = (path: Path.Path): string => | 59 | const resolveDaemonDataDir = (path: Path.Path): string => |
| 60 | process.env.EXECUTOR_DATA_DIR ?? path.join(homedir(), ".executor"); | 60 | process.env.EXECUTOR_DATA_DIR ?? path.join(homedir(), ".executor"); |
| 61 | 61 | ||
| 62 | const sanitizeHostForPath = (hostname: string): string => hostname.replaceAll(/[^a-z0-9.-]+/gi, "_"); | 62 | const sanitizeHostForPath = (hostname: string): string => |
| 63 | hostname.replaceAll(/[^a-z0-9.-]+/gi, "_"); | ||
| 63 | const sanitizeScopeForPath = (scopeId: string): string => scopeId.replaceAll(/[^a-z0-9.-]+/gi, "_"); | 64 | const sanitizeScopeForPath = (scopeId: string): string => scopeId.replaceAll(/[^a-z0-9.-]+/gi, "_"); |
| 64 | 65 | ||
| 65 | const daemonRecordPath = (path: Path.Path, input: { hostname: string; port: number }): string => { | 66 | const daemonRecordPath = (path: Path.Path, input: { hostname: string; port: number }): string => { |
| @@ -67,14 +68,19 @@ const daemonRecordPath = (path: Path.Path, input: { hostname: string; port: numb · 1 unmodified line | |||
| 67 | return path.join(resolveDaemonDataDir(path), `daemon-${host}-${input.port}.json`); | 68 | return path.join(resolveDaemonDataDir(path), `daemon-${host}-${input.port}.json`); |
| 68 | }; | 69 | }; |
| 69 | 70 | ||
| 70 | const daemonPointerPath = (path: Path.Path, input: { hostname: string; scopeId: string }): string => { | 71 | const daemonPointerPath = ( |
| 72 | path: Path.Path, | ||
| 73 | input: { hostname: string; scopeId: string }, | ||
| 74 | ): string => { | ||
| 71 | const host = sanitizeHostForPath(canonicalDaemonHost(input.hostname)); | 75 | const host = sanitizeHostForPath(canonicalDaemonHost(input.hostname)); |
| 72 | const scope = sanitizeScopeForPath(input.scopeId); | 76 | const scope = sanitizeScopeForPath(input.scopeId); |
| 73 | return path.join(resolveDaemonDataDir(path), `daemon-active-${host}-${scope}.json`); | 77 | return path.join(resolveDaemonDataDir(path), `daemon-active-${host}-${scope}.json`); |
| 74 | }; | 78 | }; |
| 75 | 79 | ||
| 76 | const daemonStartLockPath = (path: Path.Path, input: { hostname: string; scopeId: string }): string => | 80 | const daemonStartLockPath = ( |
| 77 | `${daemonPointerPath(path, input)}.lock`; | 81 | path: Path.Path, |
| 82 | input: { hostname: string; scopeId: string }, | ||
| 83 | ): string => `${daemonPointerPath(path, input)}.lock`; | ||
| 78 | 84 | ||
| 79 | // --------------------------------------------------------------------------- | 85 | // --------------------------------------------------------------------------- |
| 80 | // Persistence | 86 | // Persistence |
| @@ -195,9 +201,9 @@ export const readDaemonRecord = (input: { · 114 unmodified lines | |||
| 195 | Effect.gen(function* () { | 201 | Effect.gen(function* () { |
| 196 | const fs = yield* FileSystem.FileSystem; | 202 | const fs = yield* FileSystem.FileSystem; |
| 197 | const path = yield* Path.Path; | 203 | const path = yield* Path.Path; |
| 198 | const raw = yield* fs.readFileString(daemonRecordPath(path, input)).pipe( | 204 | const raw = yield* fs |
| 199 | Effect.catchCause(() => Effect.succeed(null)), | 205 | .readFileString(daemonRecordPath(path, input)) |
| 200 | ); | 206 | .pipe(Effect.catchCause(() => Effect.succeed(null))); |
| 201 | if (raw === null) return null; | 207 | if (raw === null) return null; |
| 202 | return parseRecord(raw); | 208 | return parseRecord(raw); |
| 203 | }); | 209 | }); |
| @@ -322,7 +328,9 @@ export const acquireDaemonStartLock = (input: { · 118 unmodified lines | |||
| 322 | }; | 328 | }; |
| 323 | } | 329 | } |
| 324 | 330 | ||
| 325 | const existingRaw = yield* fs.readFileString(lockPath).pipe(Effect.catchCause(() => Effect.succeed(null))); | 331 | const existingRaw = yield* fs |
| 332 | .readFileString(lockPath) | ||
| 333 | .pipe(Effect.catchCause(() => Effect.succeed(null))); | ||
| 326 | if (existingRaw !== null) { | 334 | if (existingRaw !== null) { |
| 327 | const existingPid = parseLockPid(existingRaw); | 335 | const existingPid = parseLockPid(existingRaw); |
| 328 | if (existingPid !== null && !isPidAlive(existingPid)) { | 336 | if (existingPid !== null && !isPidAlive(existingPid)) { |
| @@ -344,11 +352,9 @@ export const acquireDaemonStartLock = (input: { · 15 unmodified lines | |||
| 344 | ); | 352 | ); |
| 345 | }); | 353 | }); |
| 346 | 354 | ||
| 347 | export const releaseDaemonStartLock = (input: DaemonStartLock): Effect.Effect< | 355 | export const releaseDaemonStartLock = ( |
| 348 | void, | 356 | input: DaemonStartLock, |
| 349 | PlatformError, | 357 | ): Effect.Effect<void, PlatformError, FileSystem.FileSystem | Path.Path> => |
| 350 | FileSystem.FileSystem | Path.Path | ||
| 351 | > => | ||
| 352 | Effect.gen(function* () { | 358 | Effect.gen(function* () { |
| 353 | const fs = yield* FileSystem.FileSystem; | 359 | const fs = yield* FileSystem.FileSystem; |
| 354 | yield* fs.remove(input.path, { force: true }); | 360 | yield* fs.remove(input.path, { force: true }); |
| @@ -374,5 +380,7 @@ export const terminatePid = (pid: number): Effect.Effect<void, Error> => · 19 unmodified lines | |||
| 374 | process.kill(pid, "SIGTERM"); | 380 | process.kill(pid, "SIGTERM"); |
| 375 | }, | 381 | }, |
| 376 | catch: (cause) => | 382 | catch: (cause) => |
| 377 | cause instanceof Error ? cause : new Error(`Failed to terminate pid ${pid}: ${String(cause)}`), | 383 | cause instanceof Error |
| 384 | ? cause | ||
| 385 | : new Error(`Failed to terminate pid ${pid}: ${String(cause)}`), | ||
| 378 | }); | 386 | }); |
| @@ -167,7 +167,10 @@ const toProbeHost = (hostname: string): string => { · 166 unmodified lines | |||
| 167 | return hostname; | 167 | return hostname; |
| 168 | }; | 168 | }; |
| 169 | 169 | ||
| 170 | const isPortAvailable = (input: { hostname: string; port: number }): Effect.Effect<boolean, Error> => | 170 | const isPortAvailable = (input: { |
| 171 | hostname: string; | ||
| 172 | port: number; | ||
| 173 | }): Effect.Effect<boolean, Error> => | ||
| 171 | Effect.tryPromise({ | 174 | Effect.tryPromise({ |
| 172 | try: () => | 175 | try: () => |
| 173 | new Promise<boolean>((resolve) => { | 176 | new Promise<boolean>((resolve) => { |
| @@ -215,7 +218,9 @@ const pickEphemeralPort = (hostname: string): Effect.Effect<number, Error> => · 41 unmodified lines | |||
| 215 | server.listen({ port: 0, host: toProbeHost(hostname) }); | 218 | server.listen({ port: 0, host: toProbeHost(hostname) }); |
| 216 | }), | 219 | }), |
| 217 | catch: (cause) => | 220 | catch: (cause) => |
| 218 | cause instanceof Error ? cause : new Error(`Failed selecting ephemeral port: ${String(cause)}`), | 221 | cause instanceof Error |
| 222 | ? cause | ||
| 223 | : new Error(`Failed selecting ephemeral port: ${String(cause)}`), | ||
| 219 | }); | 224 | }); |
| 220 | 225 | ||
| 221 | export const chooseDaemonPort = (input: { | 226 | export const chooseDaemonPort = (input: { |
| @@ -33,13 +33,10 @@ if (typeof Bun !== "undefined" && (await Bun.file(wasmOnDisk).exists())) { · 32 unmodified lines | |||
| 33 | type QuickJSSyncVariant = import("quickjs-emscripten").QuickJSSyncVariant; | 33 | type QuickJSSyncVariant = import("quickjs-emscripten").QuickJSSyncVariant; |
| 34 | const wasmBinary = await Bun.file(wasmOnDisk).arrayBuffer(); | 34 | const wasmBinary = await Bun.file(wasmOnDisk).arrayBuffer(); |
| 35 | const importFFI: QuickJSSyncVariant["importFFI"] = () => | 35 | const importFFI: QuickJSSyncVariant["importFFI"] = () => |
| 36 | import("@jitl/quickjs-wasmfile-release-sync/ffi").then( | 36 | import("@jitl/quickjs-wasmfile-release-sync/ffi").then((m) => m.QuickJSFFI); |
| 37 | (m) => m.QuickJSFFI, | ||
| 38 | ); | ||
| 39 | const importModuleLoader: QuickJSSyncVariant["importModuleLoader"] = async () => { | 37 | const importModuleLoader: QuickJSSyncVariant["importModuleLoader"] = async () => { |
| 40 | const { default: original } = await import( | 38 | const { default: original } = |
| 41 | "@jitl/quickjs-wasmfile-release-sync/emscripten-module" | 39 | await import("@jitl/quickjs-wasmfile-release-sync/emscripten-module"); |
| 42 | ); | ||
| 43 | return (moduleArg = {}) => original({ ...moduleArg, wasmBinary }); | 40 | return (moduleArg = {}) => original({ ...moduleArg, wasmBinary }); |
| 44 | }; | 41 | }; |
| 45 | const variant: QuickJSSyncVariant = { | 42 | const variant: QuickJSSyncVariant = { |
| @@ -42,7 +42,10 @@ export const inspectToolPath = (input: { · 41 unmodified lines | |||
| 42 | }): ToolPathInspection => { | 42 | }): ToolPathInspection => { |
| 43 | const prefixSegments = | 43 | const prefixSegments = |
| 44 | input.rawPrefixParts.length === 0 ? [] : buildToolPath(input.rawPrefixParts).split("."); | 44 | input.rawPrefixParts.length === 0 ? [] : buildToolPath(input.rawPrefixParts).split("."); |
| 45 | const children = new Map<string, { invokable: boolean; hasChildren: boolean; toolCount: number }>(); | 45 | const children = new Map< |
| 46 | string, | ||
| 47 | { invokable: boolean; hasChildren: boolean; toolCount: number } | ||
| 48 | >(); | ||
| 46 | let exactPath: string | undefined = undefined; | 49 | let exactPath: string | undefined = undefined; |
| 47 | let matchingToolCount = 0; | 50 | let matchingToolCount = 0; |
| 48 | 51 | ||
| @@ -97,9 +100,7 @@ export const buildToolPath = (parts: ReadonlyArray<string>): string => { · 48 unmodified lines | |||
| 97 | throw new Error("Tool path must include at least one segment"); | 100 | throw new Error("Tool path must include at least one segment"); |
| 98 | } | 101 | } |
| 99 | if (segments.some((segment) => !TOOL_PATH_TOKEN.test(segment))) { | 102 | if (segments.some((segment) => !TOOL_PATH_TOKEN.test(segment))) { |
| 100 | throw new Error( | 103 | throw new Error("Tool path segments must contain only letters, numbers, '.', '_' or '-'"); |
| 101 | "Tool path segments must contain only letters, numbers, '.', '_' or '-'", | ||
| 102 | ); | ||
| 103 | } | 104 | } |
| 104 | return segments.join("."); | 105 | return segments.join("."); |
| 105 | }; | 106 | }; |
| @@ -186,9 +187,7 @@ export interface PausedInteraction { · 80 unmodified lines | |||
| 186 | readonly requestedSchema?: Record<string, unknown>; | 187 | readonly requestedSchema?: Record<string, unknown>; |
| 187 | } | 188 | } |
| 188 | 189 | ||
| 189 | export const extractPausedInteraction = ( | 190 | export const extractPausedInteraction = (structured: unknown): PausedInteraction | undefined => { |
| 190 | structured: unknown, | ||
| 191 | ): PausedInteraction | undefined => { | ||
| 192 | if (!isRecord(structured) || !isRecord(structured.interaction)) { | 191 | if (!isRecord(structured) || !isRecord(structured.interaction)) { |
| 193 | return undefined; | 192 | return undefined; |
| 194 | } | 193 | } |