@bastani/atomic 0.9.89-alpha.1 → 0.9.89-alpha.2
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/CHANGELOG.md +45 -0
- package/dist/builtin/intercom/CHANGELOG.md +8 -0
- package/dist/builtin/intercom/broker/broker-instance.ts +15 -1
- package/dist/builtin/intercom/broker/broker.ts +25 -8
- package/dist/builtin/intercom/broker/client.ts +29 -14
- package/dist/builtin/intercom/broker/multinode-router.ts +193 -52
- package/dist/builtin/intercom/broker/multinode-state-store.ts +6 -2
- package/dist/builtin/intercom/broker/restoring-recipients.ts +5 -0
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +3 -2
- package/dist/builtin/intercom/index.bundle.mjs +19 -12
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/types.ts +6 -2
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +17 -6
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +12 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +310 -344
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +99 -17
- package/dist/builtin/workflows/src/index.js +99 -17
- package/dist/builtin/workflows/src/local-worker-entry.mjs +99 -17
- package/dist/cli/storage-command.js +8 -0
- package/dist/cli/storage-command.js.map +1 -1
- package/dist/core/auth-storage-backends.d.ts.map +1 -1
- package/dist/core/auth-storage-backends.js +1 -0
- package/dist/core/auth-storage-backends.js.map +1 -1
- package/dist/core/keybindings.d.ts +8 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +4 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/process-start-token.d.ts.map +1 -1
- package/dist/core/process-start-token.js +8 -1
- package/dist/core/process-start-token.js.map +1 -1
- package/dist/core/resume/blueprint/build-lock.d.ts.map +1 -1
- package/dist/core/resume/blueprint/build-lock.js +2 -1
- package/dist/core/resume/blueprint/build-lock.js.map +1 -1
- package/dist/core/storage/errors.d.ts +4 -2
- package/dist/core/storage/errors.d.ts.map +1 -1
- package/dist/core/storage/errors.js +6 -1
- package/dist/core/storage/errors.js.map +1 -1
- package/dist/core/tasks/completion.d.ts +5 -0
- package/dist/core/tasks/completion.d.ts.map +1 -1
- package/dist/core/tasks/completion.js +13 -0
- package/dist/core/tasks/completion.js.map +1 -1
- package/dist/core/tools/shell-task-render.d.ts +1 -2
- package/dist/core/tools/shell-task-render.d.ts.map +1 -1
- package/dist/core/tools/shell-task-render.js +3 -7
- package/dist/core/tools/shell-task-render.js.map +1 -1
- package/dist/core/tools/windows-directory-security.d.ts.map +1 -1
- package/dist/core/tools/windows-directory-security.js +3 -11
- package/dist/core/tools/windows-directory-security.js.map +1 -1
- package/dist/core/worktree-snapshot/capture.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/capture.js +25 -1
- package/dist/core/worktree-snapshot/capture.js.map +1 -1
- package/dist/core/worktree-snapshot/restore.d.ts.map +1 -1
- package/dist/core/worktree-snapshot/restore.js +38 -9
- package/dist/core/worktree-snapshot/restore.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/agent-panel.d.ts +5 -0
- package/dist/modes/interactive/components/agent-panel.d.ts.map +1 -1
- package/dist/modes/interactive/components/agent-panel.js +13 -0
- package/dist/modes/interactive/components/agent-panel.js.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-transcript.js +5 -2
- package/dist/modes/interactive/components/chat-transcript.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +1 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/heartbeat-block.d.ts +34 -0
- package/dist/modes/interactive/components/heartbeat-block.d.ts.map +1 -0
- package/dist/modes/interactive/components/heartbeat-block.js +50 -0
- package/dist/modes/interactive/components/heartbeat-block.js.map +1 -0
- package/dist/modes/interactive/components/input-label.d.ts.map +1 -1
- package/dist/modes/interactive/components/input-label.js +8 -3
- package/dist/modes/interactive/components/input-label.js.map +1 -1
- package/dist/modes/interactive/components/main-composer-keys.d.ts.map +1 -1
- package/dist/modes/interactive/components/main-composer-keys.js +3 -7
- package/dist/modes/interactive/components/main-composer-keys.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +13 -7
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/notice-line.d.ts +10 -2
- package/dist/modes/interactive/components/notice-line.d.ts.map +1 -1
- package/dist/modes/interactive/components/notice-line.js +13 -3
- package/dist/modes/interactive/components/notice-line.js.map +1 -1
- package/dist/modes/interactive/components/provider-brand.d.ts.map +1 -1
- package/dist/modes/interactive/components/provider-brand.js +3 -0
- package/dist/modes/interactive/components/provider-brand.js.map +1 -1
- package/dist/modes/interactive/components/task-heartbeat-message.d.ts +9 -4
- package/dist/modes/interactive/components/task-heartbeat-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-heartbeat-message.js +33 -27
- package/dist/modes/interactive/components/task-heartbeat-message.js.map +1 -1
- package/dist/modes/interactive/components/task-inspector.d.ts +16 -0
- package/dist/modes/interactive/components/task-inspector.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-inspector.js +95 -4
- package/dist/modes/interactive/components/task-inspector.js.map +1 -1
- package/dist/modes/interactive/components/task-list.d.ts +5 -1
- package/dist/modes/interactive/components/task-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-list.js +20 -3
- package/dist/modes/interactive/components/task-list.js.map +1 -1
- package/dist/modes/interactive/components/task-transcript-page.d.ts +1 -1
- package/dist/modes/interactive/components/task-transcript-page.d.ts.map +1 -1
- package/dist/modes/interactive/components/task-transcript-page.js +10 -7
- package/dist/modes/interactive/components/task-transcript-page.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +1 -2
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive/theme/color-utils.d.ts +29 -1
- package/dist/modes/interactive/theme/color-utils.d.ts.map +1 -1
- package/dist/modes/interactive/theme/color-utils.js +81 -7
- package/dist/modes/interactive/theme/color-utils.js.map +1 -1
- package/dist/modes/interactive/theme/global-theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/global-theme.js +3 -0
- package/dist/modes/interactive/theme/global-theme.js.map +1 -1
- package/dist/modes/interactive/theme/theme-class.d.ts +22 -2
- package/dist/modes/interactive/theme/theme-class.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-class.js +64 -18
- package/dist/modes/interactive/theme/theme-class.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +1 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +1 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -0
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +2 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +6 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +170 -15
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/windows-powershell.d.ts +9 -0
- package/dist/utils/windows-powershell.d.ts.map +1 -0
- package/dist/utils/windows-powershell.js +16 -0
- package/dist/utils/windows-powershell.js.map +1 -0
- package/docs/background-tasks.md +6 -6
- package/docs/getting-started/installation.md +4 -2
- package/docs/keybindings.md +3 -0
- package/docs/storage.md +24 -5
- package/docs/subagents.md +1 -1
- package/docs/themes/reference.md +7 -0
- package/docs/tui/reference.md +1 -1
- package/docs/windows.md +1 -1
- package/docs/workflows/api-reference.md +9 -1
- package/docs/workflows/operations.md +1 -1
- package/npm-shrinkwrap.json +49 -49
- package/package.json +6 -6
- package/schemas/keybindings.schema.json +4 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAwB,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAWjC;;;;GAIG;AACH,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,SAAS,mBAAmB,CAAC,OAAe,EAAE,IAAc,EAAE,OAAmC;IAChG,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE;YACjC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,GAAG,EAAE,OAAO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GAAG,KAAK,CAAC;IACtB,IAAI,CAAC,YAAY,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC;QACxD,IAAI,SAAS,CAAC,IAAI,CAAC;YAAE,MAAM,GAAG,IAAI,CAAC;;YAC9B,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;IACD,IAAI,MAAM;QAAE,OAAO;IACnB,IAAI,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC5F,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;QACnB,IAAI,GAAG,CAAC,eAAe,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;QACtG,CAAC;QACD,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;QAC1F,CAAC;IACF,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import { execFile, spawn } from \"child_process\";\nimport { randomUUID } from \"crypto\";\nimport { unlink, writeFile } from \"fs/promises\";\nimport { platform, tmpdir } from \"os\";\nimport { join } from \"path\";\nimport { ENV_CLIPBOARD_OSC52, getEnvNames } from \"../config.js\";\nimport { createChildProcessEnvironment } from \"./child-process.ts\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { type ClipboardModule, clipboard } from \"./clipboard-native.ts\";\nimport { isWSL } from \"./wsl.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n\tenv: NodeJS.ProcessEnv;\n\tdetached: boolean;\n\tcwd: string;\n};\n\n/**\n * Clipboard tools ignore the working directory, and WSL cannot start Windows executables (powershell.exe)\n * when the cwd's \\\\wsl.localhost\\... path exceeds MAX_PATH (pi#11592). Running them from / (the current\n * drive root on Windows) also keeps a daemonizing clipboard owner from pinning the cwd.\n */\nconst CLIPBOARD_CWD = \"/\";\n\nfunction runClipboardCommand(command: string, args: string[], options: NativeClipboardExecOptions): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst proc = spawn(command, args, {\n\t\t\ttimeout: options.timeout,\n\t\t\tstdio: options.stdio,\n\t\t\tenv: options.env,\n\t\t\tdetached: options.detached,\n\t\t\tcwd: options.cwd,\n\t\t});\n\t\tlet settled = false;\n\t\tconst finish = (error?: Error) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tif (error) reject(error);\n\t\t\telse resolve();\n\t\t};\n\t\tproc.once(\"error\", (error) => finish(error));\n\t\tproc.once(\"close\", (code) => {\n\t\t\tif (code === 0) finish();\n\t\t\telse finish(new Error(`${command} exited with code ${code ?? 1}`));\n\t\t});\n\t\tproc.stdin.on(\"error\", () => {});\n\t\tproc.stdin.end(options.input);\n\t});\n}\n\nasync function copyToX11Clipboard(options: NativeClipboardExecOptions): Promise<void> {\n\ttry {\n\t\tawait runClipboardCommand(\"xclip\", [\"-selection\", \"clipboard\"], options);\n\t} catch {\n\t\tawait runClipboardCommand(\"xsel\", [\"--clipboard\", \"--input\"], options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\n/**\n * Remote sessions also emit OSC 52 so the client terminal receives the copy. Rex terminals count as\n * remote: a Rex server spawns shells without SSH markers, and its client may be another machine.\n * ATOMIC_CLIPBOARD_OSC52=1 (or its PI_CLIPBOARD_OSC52 alias) covers remote clients that leave no\n * markers, such as multiplexer attaches or remote IDE daemons.\n */\nfunction isRemoteSession(env: NodeJS.ProcessEnv): boolean {\n\tconst forceOsc52 = getEnvNames(ENV_CLIPBOARD_OSC52)\n\t\t.map((name) => env[name])\n\t\t.find((value) => value !== undefined);\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION || env.REX_SESSION || forceOsc52 === \"1\");\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nfunction runClipboardExecFile(\n\tfile: string,\n\targs: string[],\n\toptions: { timeout: number; env: NodeJS.ProcessEnv; cwd: string },\n): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\texecFile(file, args, options, (error, stdout) => {\n\t\t\tif (error) reject(error);\n\t\t\telse resolve(typeof stdout === \"string\" ? stdout : Buffer.from(stdout ?? \"\").toString(\"utf8\"));\n\t\t});\n\t});\n}\n\n/**\n * WSL without WSLg has no Linux display, so the Windows clipboard is written through\n * interop. PowerShell reads the text from a file because `clip.exe` and PowerShell stdin\n * decode piped bytes with the console code page, which mangles non-ASCII UTF-8.\n */\nasync function copyViaWindowsClipboard(text: string): Promise<boolean> {\n\tconst tmpFile = join(tmpdir(), `pi-wsl-clip-${randomUUID()}.txt`);\n\tconst env = createChildProcessEnvironment();\n\ttry {\n\t\tawait writeFile(tmpFile, text, { encoding: \"utf8\", mode: 0o600 });\n\t\tconst winPath = (\n\t\t\tawait runClipboardExecFile(\"wslpath\", [\"-w\", tmpFile], {\n\t\t\t\ttimeout: 1000,\n\t\t\t\tenv,\n\t\t\t\tcwd: CLIPBOARD_CWD,\n\t\t\t})\n\t\t).trim();\n\t\tif (!winPath) return false;\n\t\tconst script = `Set-Clipboard -Value ([System.IO.File]::ReadAllText('${winPath.replaceAll(\"'\", \"''\")}', [System.Text.Encoding]::UTF8))`;\n\t\tawait runClipboardExecFile(\"powershell.exe\", [\"-NoProfile\", \"-Command\", script], {\n\t\t\ttimeout: 5000,\n\t\t\tenv,\n\t\t\tcwd: CLIPBOARD_CWD,\n\t\t});\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t} finally {\n\t\ttry {\n\t\t\tawait unlink(tmpFile);\n\t\t} catch {\n\t\t\t// The file may not have been created.\n\t\t}\n\t}\n}\n\nfunction readTermuxClipboardText(): Promise<string | undefined> {\n\treturn new Promise((resolve) => {\n\t\texecFile(\"termux-clipboard-get\", [], { timeout: 5000, env: createChildProcessEnvironment() }, (error, stdout) =>\n\t\t\tresolve(error ? undefined : stdout),\n\t\t);\n\t});\n}\n\nexport async function readClipboardText(\n\tsource: { getText(): Promise<string> } | null = clipboard,\n): Promise<string | null> {\n\tif (process.env.TERMUX_VERSION) {\n\t\tconst text = await readTermuxClipboardText();\n\t\tif (text !== undefined) return text || null;\n\t}\n\ttry {\n\t\tif (!source) return null;\n\t\treturn await source.getText();\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** Pasteboard type that Finder and other macOS apps publish for copied files. */\nconst FILE_URL_PASTEBOARD_TYPE = \"public.file-url\";\n\n/** Prints the POSIX paths of the file URLs on the general pasteboard as a JSON array. */\nconst READ_FILE_URLS_SCRIPT = `ObjC.import(\"AppKit\");\nconst urls = $.NSPasteboard.generalPasteboard.readObjectsForClassesOptions(\n\t$.NSArray.arrayWithObject($.NSURL),\n\t$.NSDictionary.dictionaryWithObjectForKey($.NSNumber.numberWithBool(true), $.NSPasteboardURLReadingFileURLsOnlyKey)\n);\nconst paths = [];\nfor (let i = 0; i < urls.count; i++) paths.push(ObjC.unwrap(urls.objectAtIndex(i).path));\nJSON.stringify(paths);`;\n\n/**\n * Read file paths, such as Finder file copies, from the macOS clipboard. The native clipboard\n * module reports whether file URLs are present; AppKit is read through JavaScript for Automation\n * only then, because the module cannot read file URLs itself.\n */\nexport async function readClipboardFilePaths(\n\tsource: Pick<ClipboardModule, \"availableFormats\"> | null = clipboard,\n\tcurrentPlatform: NodeJS.Platform = process.platform,\n): Promise<string[] | null> {\n\tif (currentPlatform !== \"darwin\" || !source?.availableFormats?.().includes(FILE_URL_PASTEBOARD_TYPE)) return null;\n\tconst stdout = await new Promise<string>((resolve, reject) => {\n\t\texecFile(\n\t\t\t\"osascript\",\n\t\t\t[\"-l\", \"JavaScript\", \"-e\", READ_FILE_URLS_SCRIPT],\n\t\t\t{ timeout: 5000, env: createChildProcessEnvironment() },\n\t\t\t(error, output, stderr) => {\n\t\t\t\tif (error) {\n\t\t\t\t\t// The default error message repeats the whole script; report what osascript printed instead.\n\t\t\t\t\tconst detail = stderr.trim();\n\t\t\t\t\treject(new Error(`osascript could not read the copied files${detail ? `: ${detail}` : \"\"}`));\n\t\t\t\t} else resolve(output);\n\t\t\t},\n\t\t);\n\t});\n\tconst paths = JSON.parse(stdout) as string[] | null;\n\tif (!Array.isArray(paths) || paths.some((path) => typeof path !== \"string\")) {\n\t\tthrow new Error(\"Unexpected clipboard file path output\");\n\t}\n\treturn paths.length > 0 ? paths : null;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\tconst env = process.env;\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession(env);\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = {\n\t\tinput: text,\n\t\ttimeout: 5000,\n\t\tstdio: [\"pipe\", \"ignore\", \"ignore\"],\n\t\tenv: createChildProcessEnvironment(),\n\t\t// Clipboard writers can daemonize. Detach on POSIX so the daemon leaves Atomic's process group\n\t\t// and Ctrl+Z suspend (SIGTSTP to the group) does not stop the clipboard owner (earendil-works/pi#11179).\n\t\tdetached: p !== \"win32\",\n\t\tcwd: CLIPBOARD_CWD,\n\t};\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\tawait runClipboardCommand(\"pbcopy\", [], options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\tawait runClipboardCommand(\"clip\", [], options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait runClipboardCommand(\"termux-clipboard-set\", [], options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait runClipboardCommand(\"wl-copy\", [], options);\n\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tawait copyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tawait copyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tlet osc52Emitted = false;\n\t// A remote session skips the Windows clipboard: the copied text belongs on the connected\n\t// client, which the OSC 52 fallback below reaches, not on the remote host.\n\tif (!copied && !remote && p === \"linux\" && (await isWSL(env))) {\n\t\t// Windows Terminal supports OSC 52; prefer it over the slower PowerShell round trip.\n\t\tif (env.WT_SESSION) osc52Emitted = emitOsc52(text);\n\t\tcopied = osc52Emitted || (await copyViaWindowsClipboard(text));\n\t}\n\t// OSC 52 cannot be verified, so a desktop session with a display reports the failure\n\t// instead. Without a display the terminal is the only clipboard route (containers,\n\t// WSL without WSLg). A remote session emits it even after a successful local write:\n\t// that write reached the remote host's display clipboard, while the user is at the\n\t// client, which only the terminal can reach. The Windows interop fallback above is\n\t// different because it is a last resort that a remote session gains nothing from.\n\tconst headless = p === \"linux\" && !env.DISPLAY && !env.WAYLAND_DISPLAY && !env.TERMUX_VERSION;\n\tlet oversized = false;\n\tif (!osc52Emitted && (remote || (!copied && headless))) {\n\t\tif (emitOsc52(text)) copied = true;\n\t\telse oversized = true;\n\t}\n\tif (copied) return;\n\tif (oversized) throw new Error(\"Clipboard unavailable: text exceeds the OSC 52 size limit\");\n\tif (env.TERMUX_VERSION) {\n\t\tthrow new Error(\"Clipboard unavailable: install the Termux:API app and `termux-api` package\");\n\t}\n\tif (p === \"linux\") {\n\t\tif (env.WAYLAND_DISPLAY) {\n\t\t\tthrow new Error(\"Clipboard unavailable: install `wl-clipboard` (`wl-copy`) or check Wayland access\");\n\t\t}\n\t\tif (env.DISPLAY) {\n\t\t\tthrow new Error(\"Clipboard unavailable: install `xclip` or `xsel`, or check X11 access\");\n\t\t}\n\t}\n\tthrow new Error(\"Clipboard unavailable\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM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,IAAI,MAAM;QAAE,OAAO;IACnB,IAAI,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC5F,IAAI,GAAG,CAAC,cAAc,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;QACnB,IAAI,GAAG,CAAC,eAAe,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;QACtG,CAAC;QACD,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;QAC1F,CAAC;IACF,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import { execFile, spawn } from \"child_process\";\nimport { randomUUID } from \"crypto\";\nimport { unlink, writeFile } from \"fs/promises\";\nimport { platform, tmpdir } from \"os\";\nimport { join } from \"path\";\nimport { ENV_CLIPBOARD_OSC52, getEnvNames } from \"../config.js\";\nimport { createChildProcessEnvironment } from \"./child-process.ts\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { type ClipboardModule, clipboard } from \"./clipboard-native.ts\";\nimport { windowsPowerShellEnvironment } from \"./windows-powershell.ts\";\nimport { isWSL } from \"./wsl.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n\tenv: NodeJS.ProcessEnv;\n\tdetached: boolean;\n\tcwd: string;\n};\n\n/**\n * Clipboard tools ignore the working directory, and WSL cannot start Windows executables (powershell.exe)\n * when the cwd's \\\\wsl.localhost\\... path exceeds MAX_PATH (pi#11592). Running them from / (the current\n * drive root on Windows) also keeps a daemonizing clipboard owner from pinning the cwd.\n */\nconst CLIPBOARD_CWD = \"/\";\n\nfunction runClipboardCommand(command: string, args: string[], options: NativeClipboardExecOptions): Promise<void> {\n\treturn new Promise((resolve, reject) => {\n\t\tconst proc = spawn(command, args, {\n\t\t\ttimeout: options.timeout,\n\t\t\tstdio: options.stdio,\n\t\t\tenv: options.env,\n\t\t\tdetached: options.detached,\n\t\t\tcwd: options.cwd,\n\t\t});\n\t\tlet settled = false;\n\t\tconst finish = (error?: Error) => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tif (error) reject(error);\n\t\t\telse resolve();\n\t\t};\n\t\tproc.once(\"error\", (error) => finish(error));\n\t\tproc.once(\"close\", (code) => {\n\t\t\tif (code === 0) finish();\n\t\t\telse finish(new Error(`${command} exited with code ${code ?? 1}`));\n\t\t});\n\t\tproc.stdin.on(\"error\", () => {});\n\t\tproc.stdin.end(options.input);\n\t});\n}\n\nasync function copyToX11Clipboard(options: NativeClipboardExecOptions): Promise<void> {\n\ttry {\n\t\tawait runClipboardCommand(\"xclip\", [\"-selection\", \"clipboard\"], options);\n\t} catch {\n\t\tawait runClipboardCommand(\"xsel\", [\"--clipboard\", \"--input\"], options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\n/**\n * Remote sessions also emit OSC 52 so the client terminal receives the copy. Rex terminals count as\n * remote: a Rex server spawns shells without SSH markers, and its client may be another machine.\n * ATOMIC_CLIPBOARD_OSC52=1 (or its PI_CLIPBOARD_OSC52 alias) covers remote clients that leave no\n * markers, such as multiplexer attaches or remote IDE daemons.\n */\nfunction isRemoteSession(env: NodeJS.ProcessEnv): boolean {\n\tconst forceOsc52 = getEnvNames(ENV_CLIPBOARD_OSC52)\n\t\t.map((name) => env[name])\n\t\t.find((value) => value !== undefined);\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION || env.REX_SESSION || forceOsc52 === \"1\");\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nfunction runClipboardExecFile(\n\tfile: string,\n\targs: string[],\n\toptions: { timeout: number; env: NodeJS.ProcessEnv; cwd: string },\n): Promise<string> {\n\treturn new Promise((resolve, reject) => {\n\t\texecFile(file, args, options, (error, stdout) => {\n\t\t\tif (error) reject(error);\n\t\t\telse resolve(typeof stdout === \"string\" ? stdout : Buffer.from(stdout ?? \"\").toString(\"utf8\"));\n\t\t});\n\t});\n}\n\n/**\n * WSL without WSLg has no Linux display, so the Windows clipboard is written through\n * interop. PowerShell reads the text from a file because `clip.exe` and PowerShell stdin\n * decode piped bytes with the console code page, which mangles non-ASCII UTF-8.\n */\nasync function copyViaWindowsClipboard(text: string): Promise<boolean> {\n\tconst tmpFile = join(tmpdir(), `pi-wsl-clip-${randomUUID()}.txt`);\n\tconst env = createChildProcessEnvironment();\n\ttry {\n\t\tawait writeFile(tmpFile, text, { encoding: \"utf8\", mode: 0o600 });\n\t\tconst winPath = (\n\t\t\tawait runClipboardExecFile(\"wslpath\", [\"-w\", tmpFile], {\n\t\t\t\ttimeout: 1000,\n\t\t\t\tenv,\n\t\t\t\tcwd: CLIPBOARD_CWD,\n\t\t\t})\n\t\t).trim();\n\t\tif (!winPath) return false;\n\t\tconst script = `Set-Clipboard -Value ([System.IO.File]::ReadAllText('${winPath.replaceAll(\"'\", \"''\")}', [System.Text.Encoding]::UTF8))`;\n\t\tawait runClipboardExecFile(\"powershell.exe\", [\"-NoProfile\", \"-Command\", script], {\n\t\t\ttimeout: 5000,\n\t\t\tenv: windowsPowerShellEnvironment(env),\n\t\t\tcwd: CLIPBOARD_CWD,\n\t\t});\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t} finally {\n\t\ttry {\n\t\t\tawait unlink(tmpFile);\n\t\t} catch {\n\t\t\t// The file may not have been created.\n\t\t}\n\t}\n}\n\nfunction readTermuxClipboardText(): Promise<string | undefined> {\n\treturn new Promise((resolve) => {\n\t\texecFile(\"termux-clipboard-get\", [], { timeout: 5000, env: createChildProcessEnvironment() }, (error, stdout) =>\n\t\t\tresolve(error ? undefined : stdout),\n\t\t);\n\t});\n}\n\nexport async function readClipboardText(\n\tsource: { getText(): Promise<string> } | null = clipboard,\n): Promise<string | null> {\n\tif (process.env.TERMUX_VERSION) {\n\t\tconst text = await readTermuxClipboardText();\n\t\tif (text !== undefined) return text || null;\n\t}\n\ttry {\n\t\tif (!source) return null;\n\t\treturn await source.getText();\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/** Pasteboard type that Finder and other macOS apps publish for copied files. */\nconst FILE_URL_PASTEBOARD_TYPE = \"public.file-url\";\n\n/** Prints the POSIX paths of the file URLs on the general pasteboard as a JSON array. */\nconst READ_FILE_URLS_SCRIPT = `ObjC.import(\"AppKit\");\nconst urls = $.NSPasteboard.generalPasteboard.readObjectsForClassesOptions(\n\t$.NSArray.arrayWithObject($.NSURL),\n\t$.NSDictionary.dictionaryWithObjectForKey($.NSNumber.numberWithBool(true), $.NSPasteboardURLReadingFileURLsOnlyKey)\n);\nconst paths = [];\nfor (let i = 0; i < urls.count; i++) paths.push(ObjC.unwrap(urls.objectAtIndex(i).path));\nJSON.stringify(paths);`;\n\n/**\n * Read file paths, such as Finder file copies, from the macOS clipboard. The native clipboard\n * module reports whether file URLs are present; AppKit is read through JavaScript for Automation\n * only then, because the module cannot read file URLs itself.\n */\nexport async function readClipboardFilePaths(\n\tsource: Pick<ClipboardModule, \"availableFormats\"> | null = clipboard,\n\tcurrentPlatform: NodeJS.Platform = process.platform,\n): Promise<string[] | null> {\n\tif (currentPlatform !== \"darwin\" || !source?.availableFormats?.().includes(FILE_URL_PASTEBOARD_TYPE)) return null;\n\tconst stdout = await new Promise<string>((resolve, reject) => {\n\t\texecFile(\n\t\t\t\"osascript\",\n\t\t\t[\"-l\", \"JavaScript\", \"-e\", READ_FILE_URLS_SCRIPT],\n\t\t\t{ timeout: 5000, env: createChildProcessEnvironment() },\n\t\t\t(error, output, stderr) => {\n\t\t\t\tif (error) {\n\t\t\t\t\t// The default error message repeats the whole script; report what osascript printed instead.\n\t\t\t\t\tconst detail = stderr.trim();\n\t\t\t\t\treject(new Error(`osascript could not read the copied files${detail ? `: ${detail}` : \"\"}`));\n\t\t\t\t} else resolve(output);\n\t\t\t},\n\t\t);\n\t});\n\tconst paths = JSON.parse(stdout) as string[] | null;\n\tif (!Array.isArray(paths) || paths.some((path) => typeof path !== \"string\")) {\n\t\tthrow new Error(\"Unexpected clipboard file path output\");\n\t}\n\treturn paths.length > 0 ? paths : null;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\tconst env = process.env;\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession(env);\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = {\n\t\tinput: text,\n\t\ttimeout: 5000,\n\t\tstdio: [\"pipe\", \"ignore\", \"ignore\"],\n\t\tenv: createChildProcessEnvironment(),\n\t\t// Clipboard writers can daemonize. Detach on POSIX so the daemon leaves Atomic's process group\n\t\t// and Ctrl+Z suspend (SIGTSTP to the group) does not stop the clipboard owner (earendil-works/pi#11179).\n\t\tdetached: p !== \"win32\",\n\t\tcwd: CLIPBOARD_CWD,\n\t};\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\tawait runClipboardCommand(\"pbcopy\", [], options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\tawait runClipboardCommand(\"clip\", [], options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait runClipboardCommand(\"termux-clipboard-set\", [], options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait runClipboardCommand(\"wl-copy\", [], options);\n\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tawait copyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tawait copyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tlet osc52Emitted = false;\n\t// A remote session skips the Windows clipboard: the copied text belongs on the connected\n\t// client, which the OSC 52 fallback below reaches, not on the remote host.\n\tif (!copied && !remote && p === \"linux\" && (await isWSL(env))) {\n\t\t// Windows Terminal supports OSC 52; prefer it over the slower PowerShell round trip.\n\t\tif (env.WT_SESSION) osc52Emitted = emitOsc52(text);\n\t\tcopied = osc52Emitted || (await copyViaWindowsClipboard(text));\n\t}\n\t// OSC 52 cannot be verified, so a desktop session with a display reports the failure\n\t// instead. Without a display the terminal is the only clipboard route (containers,\n\t// WSL without WSLg). A remote session emits it even after a successful local write:\n\t// that write reached the remote host's display clipboard, while the user is at the\n\t// client, which only the terminal can reach. The Windows interop fallback above is\n\t// different because it is a last resort that a remote session gains nothing from.\n\tconst headless = p === \"linux\" && !env.DISPLAY && !env.WAYLAND_DISPLAY && !env.TERMUX_VERSION;\n\tlet oversized = false;\n\tif (!osc52Emitted && (remote || (!copied && headless))) {\n\t\tif (emitOsc52(text)) copied = true;\n\t\telse oversized = true;\n\t}\n\tif (copied) return;\n\tif (oversized) throw new Error(\"Clipboard unavailable: text exceeds the OSC 52 size limit\");\n\tif (env.TERMUX_VERSION) {\n\t\tthrow new Error(\"Clipboard unavailable: install the Termux:API app and `termux-api` package\");\n\t}\n\tif (p === \"linux\") {\n\t\tif (env.WAYLAND_DISPLAY) {\n\t\t\tthrow new Error(\"Clipboard unavailable: install `wl-clipboard` (`wl-copy`) or check Wayland access\");\n\t\t}\n\t\tif (env.DISPLAY) {\n\t\t\tthrow new Error(\"Clipboard unavailable: install `xclip` or `xsel`, or check X11 access\");\n\t\t}\n\t}\n\tthrow new Error(\"Clipboard unavailable\");\n}\n"]}
|
|
@@ -158,5 +158,11 @@ export declare function getGitShellEnvironmentAsync(baseEnv: NodeJS.ProcessEnv):
|
|
|
158
158
|
readonly pathEntry: string;
|
|
159
159
|
readonly env: Record<string, string>;
|
|
160
160
|
} | undefined>;
|
|
161
|
+
/**
|
|
162
|
+
* The mtime a plain `stat` reports for `mtimeNs`, in whole milliseconds, computed as Node computes it (seconds and
|
|
163
|
+
* nanoseconds summed in floating point, then rounded). proper-lockfile compares its holder's stamp with that value,
|
|
164
|
+
* so a lock put back must carry exactly it.
|
|
165
|
+
*/
|
|
166
|
+
export declare function plainStatMtimeMs(mtimeNs: bigint): number;
|
|
161
167
|
export {};
|
|
162
168
|
//# sourceMappingURL=tools-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools-manager.d.ts","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools-manager.d.ts","sourceRoot":"","sources":["../../src/utils/tools-manager.ts"],"names":[],"mappings":"AAwBA,OAAO,EAUN,KAAK,oBAAoB,EAEzB,KAAK,2BAA2B,EAChC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAqB,KAAK,SAAS,EAAqC,MAAM,0BAA0B,CAAC;AAChH,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAGpB,MAAM,0BAA0B,CAAC;AAiElC,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;AACvE,wBAAgB,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAqEvF,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAoB7E;AAwOD,0EAA0E;AAC1E,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,iHAAiH;IACjH,KAAK,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC/B,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,KAAK,EACzB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,GACrC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,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EAA2E;AAC3E,MAAM,MAAM,aAAa,GACtB;IACA,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;CACjC,GACD;IAAE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,2BAA2B,CAAA;CAAE,CAAC;AAgCnF,wBAAgB,YAAY,IAAI,aAAa,CAc5C;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,aAAa,CAAC,CAchE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACrC,OAAO,EAAE,MAAM,CAAC,UAAU,GACxB;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,SAAS,CAYlF;AAED,wBAAsB,2BAA2B,CAChD,OAAO,EAAE,MAAM,CAAC,UAAU,GACxB,OAAO,CAAC;IAAE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,SAAS,CAAC,CAY3F;AAuKD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execFile, spawnSync } from "child_process";
|
|
2
2
|
import { createHash, randomUUID } from "crypto";
|
|
3
3
|
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
4
|
-
import { chmod, lstat, mkdir, mkdtemp, readdir, readFile, readlink, rename, rm, stat, writeFile } from "fs/promises";
|
|
4
|
+
import { chmod, lstat, mkdir, mkdtemp, readdir, readFile, readlink, rename, rm, stat, utimes, writeFile, } from "fs/promises";
|
|
5
5
|
import { arch, hostname, platform } from "os";
|
|
6
6
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
7
7
|
import lockfile from "proper-lockfile";
|
|
@@ -15,6 +15,7 @@ import { isManagedToolError, ManagedToolDownloadError, ManagedToolTimeoutError,
|
|
|
15
15
|
import { fetchWithRetry } from "./management-http.js";
|
|
16
16
|
import { pathExists } from "./path-exists.js";
|
|
17
17
|
import { getPiUserAgent } from "./pi-user-agent.js";
|
|
18
|
+
import { windowsPowerShellEnvironment } from "./windows-powershell.js";
|
|
18
19
|
const TOOLS_DIR = getBinDir();
|
|
19
20
|
const NETWORK_TIMEOUT_MS = 10_000;
|
|
20
21
|
const DOWNLOAD_TIMEOUT_MS = 120_000;
|
|
@@ -183,9 +184,9 @@ function formatExecFileFailure(error, stdout, stderr) {
|
|
|
183
184
|
}
|
|
184
185
|
return "exit status unknown";
|
|
185
186
|
}
|
|
186
|
-
function runExtractionCommand(command, args) {
|
|
187
|
+
function runExtractionCommand(command, args, env = process.env) {
|
|
187
188
|
return new Promise((resolvePromise) => {
|
|
188
|
-
execFile(command, args, { env: createChildProcessEnvironment() }, (error, stdout, stderr) => {
|
|
189
|
+
execFile(command, args, { env: createChildProcessEnvironment(undefined, env) }, (error, stdout, stderr) => {
|
|
189
190
|
if (!error) {
|
|
190
191
|
resolvePromise(null);
|
|
191
192
|
return;
|
|
@@ -235,7 +236,7 @@ async function extractZipArchive(archivePath, extractDir, assetName) {
|
|
|
235
236
|
script,
|
|
236
237
|
archivePath,
|
|
237
238
|
extractDir,
|
|
238
|
-
]);
|
|
239
|
+
], windowsPowerShellEnvironment());
|
|
239
240
|
if (!powershellFailure)
|
|
240
241
|
return;
|
|
241
242
|
failures.push(powershellFailure);
|
|
@@ -1359,6 +1360,136 @@ function errnoCode(error) {
|
|
|
1359
1360
|
}
|
|
1360
1361
|
/** proper-lockfile never declares a lock stale by itself: wall-clock staleness breaks under clock skew. */
|
|
1361
1362
|
const LOCK_NEVER_STALE_MS = 2 ** 31 - 1;
|
|
1363
|
+
const GIT_INSTALL_LOCK_NAME = "git.install.lock";
|
|
1364
|
+
const LOCK_TRASH_INFIX = ".stale-";
|
|
1365
|
+
/** The random UUID that ends every moved-aside lock's name, so the sweep only ever touches those fixed-length names. */
|
|
1366
|
+
const LOCK_TRASH_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
1367
|
+
/** Attempts at a lock path operation that fails for a moment while another process has the path open. */
|
|
1368
|
+
const LOCK_RETRY_ATTEMPTS = 5;
|
|
1369
|
+
const LOCK_RETRY_MS = 20;
|
|
1370
|
+
/**
|
|
1371
|
+
* Errors a lock path reports for a moment while another process has it open or is removing it: EBUSY anywhere, and on
|
|
1372
|
+
* Windows EPERM/EACCES, which a directory opened without delete sharing or pending deletion reports.
|
|
1373
|
+
*/
|
|
1374
|
+
function isTransientLockError(error) {
|
|
1375
|
+
const code = errnoCode(error);
|
|
1376
|
+
return code === "EBUSY" || (process.platform === "win32" && (code === "EPERM" || code === "EACCES"));
|
|
1377
|
+
}
|
|
1378
|
+
/** Run `operation`, again after a short wait while it fails with a transient lock error, at most a few times. */
|
|
1379
|
+
async function retryTransient(operation) {
|
|
1380
|
+
for (let attempt = 1;; attempt++) {
|
|
1381
|
+
try {
|
|
1382
|
+
return await operation();
|
|
1383
|
+
}
|
|
1384
|
+
catch (error) {
|
|
1385
|
+
if (!isTransientLockError(error) || attempt >= LOCK_RETRY_ATTEMPTS)
|
|
1386
|
+
throw error;
|
|
1387
|
+
}
|
|
1388
|
+
await delay(LOCK_RETRY_MS);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Which lock directory is at `path`: its device, its inode (the NTFS file index on Windows) and its mtime, read as
|
|
1393
|
+
* bigints so no precision is lost. Renaming a directory keeps all three, and a lock removed and taken again is a new
|
|
1394
|
+
* directory, so a moved lock can be told apart from the one a waiter judged abandoned. Undefined when nothing is there.
|
|
1395
|
+
*/
|
|
1396
|
+
async function lockIdentity(path) {
|
|
1397
|
+
try {
|
|
1398
|
+
const stats = await retryTransient(() => stat(path, { bigint: true }));
|
|
1399
|
+
return { id: `${stats.dev}:${stats.ino}:${stats.mtimeNs}`, mtime: new Date(plainStatMtimeMs(stats.mtimeNs)) };
|
|
1400
|
+
}
|
|
1401
|
+
catch (error) {
|
|
1402
|
+
if (errnoCode(error) === "ENOENT")
|
|
1403
|
+
return undefined;
|
|
1404
|
+
throw error;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* The mtime a plain `stat` reports for `mtimeNs`, in whole milliseconds, computed as Node computes it (seconds and
|
|
1409
|
+
* nanoseconds summed in floating point, then rounded). proper-lockfile compares its holder's stamp with that value,
|
|
1410
|
+
* so a lock put back must carry exactly it.
|
|
1411
|
+
*/
|
|
1412
|
+
export function plainStatMtimeMs(mtimeNs) {
|
|
1413
|
+
return Math.round(Number(mtimeNs / 1000000000n) * 1000 + Number(mtimeNs % 1000000000n) / 1_000_000);
|
|
1414
|
+
}
|
|
1415
|
+
/** Move `from` to `to` atomically; false when `from` is gone. */
|
|
1416
|
+
async function moveLock(from, to) {
|
|
1417
|
+
try {
|
|
1418
|
+
await retryTransient(() => rename(from, to));
|
|
1419
|
+
return true;
|
|
1420
|
+
}
|
|
1421
|
+
catch (error) {
|
|
1422
|
+
if (errnoCode(error) === "ENOENT")
|
|
1423
|
+
return false;
|
|
1424
|
+
throw error;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
/** Delete a lock directory moved aside. One that stays busy is left for `removeAbandonedLockTrash`. */
|
|
1428
|
+
async function removeLockTrash(path) {
|
|
1429
|
+
try {
|
|
1430
|
+
await retryTransient(() => rm(path, { recursive: true, force: true }));
|
|
1431
|
+
}
|
|
1432
|
+
catch (error) {
|
|
1433
|
+
if (!isTransientLockError(error))
|
|
1434
|
+
throw error;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Remove the abandoned lock `stale`, and never a lock someone else holds. The lock is moved aside to a name of its own
|
|
1439
|
+
* in one atomic rename, so of all waiters that judged it abandoned only one moves it. If what was moved is not the
|
|
1440
|
+
* lock that was judged abandoned (it was replaced between the check and the move), it goes back at once: an exclusive
|
|
1441
|
+
* mkdir recreates the lock path with the moved lock's mtime, which is all its holder checks.
|
|
1442
|
+
*
|
|
1443
|
+
* Node has no rename that refuses to replace, so the put-back is not atomic: the lock path is empty from the move until
|
|
1444
|
+
* the mkdir. Only a waiter paused between its check and its move gets there, and a process taking the lock in that
|
|
1445
|
+
* instant keeps it. The holder that lost its lock sees it as compromised at its next refresh, and if it finishes
|
|
1446
|
+
* before that, its release removes the newcomer's lock instead. Either holder still finishes its install, which is
|
|
1447
|
+
* published by an atomic rename, so the cost is at most one more download, never a failed or partial install.
|
|
1448
|
+
*/
|
|
1449
|
+
async function takeOverStaleLock(lockPath, stale) {
|
|
1450
|
+
if ((await lockIdentity(lockPath))?.id !== stale)
|
|
1451
|
+
return;
|
|
1452
|
+
const trash = `${lockPath}${LOCK_TRASH_INFIX}${randomUUID()}`;
|
|
1453
|
+
if (!(await moveLock(lockPath, trash)))
|
|
1454
|
+
return;
|
|
1455
|
+
const moved = await lockIdentity(trash);
|
|
1456
|
+
if (moved !== undefined && moved.id !== stale) {
|
|
1457
|
+
try {
|
|
1458
|
+
await mkdir(lockPath);
|
|
1459
|
+
await retryTransient(() => utimes(lockPath, moved.mtime, moved.mtime));
|
|
1460
|
+
}
|
|
1461
|
+
catch (error) {
|
|
1462
|
+
// Taken in that instant, or removed again: its holder carries on without it.
|
|
1463
|
+
if (errnoCode(error) !== "EEXIST" && errnoCode(error) !== "ENOENT" && !isTransientLockError(error))
|
|
1464
|
+
throw error;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
await removeLockTrash(trash);
|
|
1468
|
+
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Remove locks moved aside by waiters that died before deleting them. Their mtime is the abandoned lock's, so any of
|
|
1471
|
+
* them more than `lockStaleMs` from now, in either direction for a skewed clock, is debris; a lock moved by mistake an
|
|
1472
|
+
* instant ago is fresh and stays for the waiter that is putting it back.
|
|
1473
|
+
*/
|
|
1474
|
+
async function removeAbandonedLockTrash(lockPath) {
|
|
1475
|
+
const binDir = dirname(lockPath);
|
|
1476
|
+
const prefix = `${basename(lockPath)}${LOCK_TRASH_INFIX}`;
|
|
1477
|
+
const names = (await readdir(binDir)).filter((name) => name.startsWith(prefix) && LOCK_TRASH_ID.test(name.slice(prefix.length)));
|
|
1478
|
+
for (const name of names) {
|
|
1479
|
+
const path = join(binDir, name);
|
|
1480
|
+
let identity;
|
|
1481
|
+
try {
|
|
1482
|
+
identity = await lockIdentity(path);
|
|
1483
|
+
}
|
|
1484
|
+
catch (error) {
|
|
1485
|
+
if (isTransientLockError(error))
|
|
1486
|
+
continue;
|
|
1487
|
+
throw error;
|
|
1488
|
+
}
|
|
1489
|
+
if (identity !== undefined && Math.abs(Date.now() - identity.mtime.getTime()) >= gitProvisionSettings.lockStaleMs)
|
|
1490
|
+
await removeLockTrash(path);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1362
1493
|
/**
|
|
1363
1494
|
* Serialize installs across processes so concurrent starts download once. A waiter treats the lock as abandoned only
|
|
1364
1495
|
* after its mtime stops changing for `lockStaleMs` of the waiter's own monotonic time, so neither clock skew nor a
|
|
@@ -1368,9 +1499,9 @@ const LOCK_NEVER_STALE_MS = 2 ** 31 - 1;
|
|
|
1368
1499
|
*/
|
|
1369
1500
|
async function acquireGitInstallLock(target, layout, signal, emit) {
|
|
1370
1501
|
const binDir = dirname(layout.root);
|
|
1371
|
-
const lockPath = join(binDir,
|
|
1502
|
+
const lockPath = join(binDir, GIT_INSTALL_LOCK_NAME);
|
|
1372
1503
|
const startedAt = performance.now();
|
|
1373
|
-
let
|
|
1504
|
+
let observed;
|
|
1374
1505
|
let observedSince = startedAt;
|
|
1375
1506
|
let announced = false;
|
|
1376
1507
|
for (;;) {
|
|
@@ -1390,21 +1521,29 @@ async function acquireGitInstallLock(target, layout, signal, emit) {
|
|
|
1390
1521
|
return { kind: "held", release, compromised: () => compromised };
|
|
1391
1522
|
}
|
|
1392
1523
|
catch (error) {
|
|
1393
|
-
|
|
1524
|
+
// ENOENT after the lock directory was created: it vanished before its first stamp. Contend again.
|
|
1525
|
+
const vanished = errnoCode(error) === "ENOENT" && error.syscall !== "mkdir";
|
|
1526
|
+
if (errnoCode(error) !== "ELOCKED" && !vanished)
|
|
1394
1527
|
throw await installFailedAsync("stage", target, layout, error, "install lock");
|
|
1395
1528
|
}
|
|
1396
1529
|
const provisioned = await findCurrentGitAsync(target);
|
|
1397
1530
|
if (provisioned !== undefined)
|
|
1398
1531
|
return { kind: "installed", provisioned };
|
|
1399
1532
|
const now = performance.now();
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1533
|
+
try {
|
|
1534
|
+
const identity = (await lockIdentity(lockPath))?.id;
|
|
1535
|
+
if (identity !== observed) {
|
|
1536
|
+
observed = identity;
|
|
1537
|
+
observedSince = now;
|
|
1538
|
+
}
|
|
1539
|
+
else if (identity !== undefined && now - observedSince >= gitProvisionSettings.lockStaleMs) {
|
|
1540
|
+
await takeOverStaleLock(lockPath, identity);
|
|
1541
|
+
}
|
|
1405
1542
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1543
|
+
catch (error) {
|
|
1544
|
+
// A lock path that stays busy is looked at again on the next poll.
|
|
1545
|
+
if (!isTransientLockError(error))
|
|
1546
|
+
throw await installFailedAsync("stage", target, layout, error, "install lock");
|
|
1408
1547
|
}
|
|
1409
1548
|
const elapsedMs = Math.round(now - startedAt);
|
|
1410
1549
|
if (elapsedMs >= gitProvisionSettings.lockWaitTimeoutMs)
|
|
@@ -1633,10 +1772,26 @@ async function installGitDistribution(target, system, signal, emit) {
|
|
|
1633
1772
|
throw await installFailedAsync("stage", target, layout, error);
|
|
1634
1773
|
}
|
|
1635
1774
|
const lock = await acquireGitInstallLock(target, layout, signal, emit);
|
|
1636
|
-
if (lock.kind === "installed")
|
|
1775
|
+
if (lock.kind === "installed") {
|
|
1776
|
+
try {
|
|
1777
|
+
await removeAbandonedLockTrash(join(binDir, GIT_INSTALL_LOCK_NAME));
|
|
1778
|
+
}
|
|
1779
|
+
catch (error) {
|
|
1780
|
+
emit({
|
|
1781
|
+
type: "warning",
|
|
1782
|
+
message: `Could not remove an abandoned git install lock: ${firstLine(String(error))}`,
|
|
1783
|
+
});
|
|
1784
|
+
}
|
|
1637
1785
|
return lock.provisioned;
|
|
1786
|
+
}
|
|
1638
1787
|
let primary;
|
|
1639
1788
|
try {
|
|
1789
|
+
try {
|
|
1790
|
+
await removeAbandonedLockTrash(join(binDir, GIT_INSTALL_LOCK_NAME));
|
|
1791
|
+
}
|
|
1792
|
+
catch (error) {
|
|
1793
|
+
throw await installFailedAsync("stage", target, layout, error, "install lock");
|
|
1794
|
+
}
|
|
1640
1795
|
const existing = await findCurrentGitAsync(target);
|
|
1641
1796
|
if (existing !== undefined)
|
|
1642
1797
|
return existing;
|