@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":"windows-directory-security.js","sourceRoot":"","sources":["../../../src/core/tools/windows-directory-security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AA4BpE;;;;;;;;;;;GAWG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAS;IAC3C,UAAU,EAAE,eAAe;IAC3B,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE,gBAAgB;IAC3B,SAAS,EAAE,eAAe;CAC1B,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,gCAAgC,CAAC,QAAkC;IAClF,MAAM,OAAO,GAAG,CAAC,GAAW,EAAW,EAAE,CAAC,GAAG,KAAK,QAAQ,CAAC,UAAU,IAAI,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACtG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,OAAO,iCAAiC,CAAC;IAC1C,CAAC;IACD,IA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AAK,KAAK,EAAE,CAAC;QACzC,mCAAmC,CAAC,YAAY,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,2BAA2B,CAAC;AACpC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,8CAA8C;IACnE,OAAO,WAAW,CAAC,IAAI,IAAI,WAAW,CAAC,IAAI,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;QAClE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,EAAE,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/G,CAAC;AACF,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,2CAA2C,CAAC,MAAkC;IAC7F,cAAc,GAAG,MAAM,IAAI,iCAAiC,CAAC;AAC9D,CAAC;AAED,wGAAwG;AACxG,MAAM,UAAU,4CAA4C;IAC3D,eAAe,IAAI,CAAC,CAAC;IACrB,aAAa,CAAC,KAAK,EAAE,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;QAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5D,WAAW,CAAC,KAAK,EAAE,CAAC;IACpB,eAAe,GAAG,SAAS,CAAC;IAC5B,cAAc,GAAG,iCAAiC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Windows owner-SID and DACL verification for the session temp tree.\n *\n * POSIX proves ownership of an existing temp component with a uid comparison\n * and a mode check. Node exposes neither on Windows — `lstatSync` reports\n * uid/gid 0 — so this module reads the real security descriptor and decides\n * from SIDs alone: the owner must\n * be a trusted principal and every access-allowed ACE must grant only trusted\n * principals. Names are never compared; two accounts can share a display name,\n * but never a SID.\n *\n * The native module reads the descriptor directly. When that binding is\n * unavailable or cannot read the directory, an asynchronous PowerShell\n * subprocess reads it instead. Reads start after the synchronous caller\n * returns, so a synchronous check never reads the descriptor. A successful\n * verification is cached for the life of the process, keyed to the\n * directory's path and identity (its file ID and creation time),\n * and a directory inside a verified one needs no read of its own (see\n * `verifyWindowsDirectorySecurityAsync`). A directory swapped underneath the\n * path is a new file with a new ID and is read again.\n * Failures are not cached: a refusal means \"no spill file this time\", and a\n * transient read failure must not disable persistence for the rest of the\n * process.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { statSync } from \"node:fs\";\nimport { stat as statAsync } from \"node:fs/promises\";\nimport type { Socket } from \"node:net\";\nimport { dirname, resolve } from \"node:path\";\nimport type { Readable } from \"node:stream\";\nimport { clearTimeout, setTimeout } from \"node:timers\";\nimport { createModuleRequire } from \"../../utils/module-require.js\";\n\n/** One DACL entry with its trustee resolved to a literal SID. */\nexport interface WindowsAccessRule {\n\t/** True for an access-allowed entry, false for access-denied. */\n\tallow: boolean;\n\t/** The SID the entry applies to. */\n\tsid: string;\n}\n\n/** What the security read produces: the caller's SID plus the descriptor. */\nexport interface WindowsDirectorySecurity {\n\t/** SID of the current process token's user. */\n\tcurrentSid: string;\n\t/** SID owning the directory. */\n\townerSid: string;\n\t/** The DACL portion of the descriptor in SDDL form (may be empty). */\n\tdacl: string;\n\t/**\n\t * Every DACL entry with its trustee as a literal SID (`GetAccessRules`\n\t * resolves domain-relative SDDL abbreviations such as `LA` that a\n\t * name-side parse cannot). The SDDL string above cross-checks that these\n\t * rules describe the whole DACL: only plain allow/deny ACE types, one\n\t * rule per ACE.\n\t */\n\taccessRules: readonly WindowsAccessRule[];\n}\n\n/**\n * Principals allowed to own, or hold access-allowed ACEs on, a temp component.\n *\n * SYSTEM and Administrators hold both on any per-user Windows temp directory\n * by inheritance, and both can reach any file on the volume regardless, so\n * permitting them grants nothing an attacker did not already have. Elevated\n * processes also create directories owned by the Administrators group rather\n * than the user, which is why the owner check shares this set. CREATOR OWNER\n * is inherit-only plumbing: it materializes as the creating account on\n * descendants, and creation inside the tree is already restricted to the\n * SIDs allowed here.\n */\nconst TRUSTED_STATIC_SIDS = new Set<string>([\n\t\"S-1-5-18\", // Local System\n\t\"S-1-5-32-544\", // Builtin Administrators\n\t\"S-1-3-0\", // Creator Owner\n\t\"S-1-3-4\", // Owner Rights\n]);\n\n/**\n * Decide whether a directory's descriptor is safe to adopt.\n *\n * Returns a refusal reason, or `undefined` when the directory is owned by a\n * trusted principal and its DACL grants access to trusted principals only.\n * Exported as a pure function so the decision table is testable on any host.\n */\nexport function evaluateWindowsDirectorySecurity(security: WindowsDirectorySecurity): string | undefined {\n\tconst trusted = (sid: string): boolean => sid === security.currentSid || TRUSTED_STATIC_SIDS.has(sid);\n\tif (!security.ownerSid.startsWith(\"S-1-\")) {\n\t\treturn \"its owner could not be verified\";\n\t}\n\tif (!trusted(security.ownerSid)) {\n\t\treturn \"it is owned by another account\";\n\t}\n\t// `Get-Acl` renders a null DACL (everyone has full control) as an absent\n\t// `D:` section; an empty DACL (`D:` with no ACEs) grants nobody anything\n\t// and is fine.\n\tconst dacl = security.dacl.trim();\n\tif (!dacl.startsWith(\"D:\")) {\n\t\treturn \"it has no access control list\";\n\t}\n\tlet rest = dacl.slice(2);\n\tconst flagsEnd = rest.indexOf(\"(\");\n\tconst flags = flagsEnd === -1 ? rest : rest.slice(0, flagsEnd);\n\tif (!/^[A-Z]*$/.test(flags)) {\n\t\treturn \"its access control list could not be parsed\";\n\t}\n\trest = flagsEnd === -1 ? \"\" : rest.slice(flagsEnd);\n\tconst aces = rest.match(/\\([^()]*\\)/g) ?? [];\n\tif (aces.join(\"\") !== rest) {\n\t\treturn \"its access control list could not be parsed\";\n\t}\n\tfor (const ace of aces) {\n\t\tconst type = ace.slice(1, -1).split(\";\")[0];\n\t\tif (type !== \"A\" && type !== \"D\") {\n\t\t\t// Conditional, object, and callback ACEs are not modeled by the\n\t\t\t// resolved access rules below, so a DACL containing one cannot be\n\t\t\t// proven restrictive.\n\t\t\treturn \"its access control list could not be verified\";\n\t\t}\n\t}\n\tif (security.accessRules.length !== aces.length) {\n\t\t// The resolved rules must describe the whole DACL; a mismatch means\n\t\t// part of it was not translated and cannot be checked.\n\t\treturn \"its access control list could not be verified\";\n\t}\n\tfor (const rule of security.accessRules) {\n\t\tif (!rule.allow) {\n\t\t\tcontinue; // A deny entry only ever removes access.\n\t\t}\n\t\tif (!rule.sid.startsWith(\"S-1-\")) {\n\t\t\treturn \"its access control list could not be verified\";\n\t\t}\n\t\tif (!trusted(rule.sid)) {\n\t\t\treturn \"it grants access to another account\";\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * One PowerShell round trip: the caller's SID, the owner SID, the DACL in\n * SDDL form, and one `Allow|Deny;SID` line per resolved access rule. The path\n * travels through the environment rather than the command line so no quoting\n * rules apply to it.\n */\nconst READ_SECURITY_SCRIPT = [\n\t\"$ErrorActionPreference = 'Stop'\",\n\t\"$acl = Get-Acl -LiteralPath $env:ATOMIC_SECURITY_QUERY_PATH\",\n\t\"$owner = $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value\",\n\t\"$dacl = $acl.GetSecurityDescriptorSddlForm('Access')\",\n\t\"$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value\",\n\t\"$lines = @($user, $owner, $dacl)\",\n\t\"foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))\" +\n\t\t' { $lines += \"$($rule.AccessControlType);$($rule.IdentityReference.Value)\" }',\n\t'[Console]::Out.Write(($lines -join \"`n\"))',\n].join(\"; \");\n\n/** Bounded wait for the security read; a wedged subprocess must not hang a spill. */\nconst READ_SECURITY_TIMEOUT_MS = 30_000;\n\nexport const VERIFICATION_PENDING_REASON = \"its ownership is still being verified\";\n\n/** PowerShell hosts to try, most specific first: an absolute Windows\n * PowerShell path immune to a stripped `PATH`, then whichever of\n * `powershell.exe`/`pwsh.exe` the environment resolves. */\nexport function powershellCandidates(): string[] {\n\tconst candidates: string[] = [];\n\tcandidates.push(`${windowsDirectory()}\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe`);\n\tcandidates.push(\"powershell.exe\", \"pwsh.exe\");\n\treturn candidates;\n}\n\n/**\n * The environment for a PowerShell read. A PowerShell 7 parent puts its own module directories in `PSModulePath`, and\n * Windows PowerShell started from it then fails to load `Get-Acl`'s module. Without the variable each host uses its\n * own default module path.\n */\nfunction powershellEnvironment(path: string): NodeJS.ProcessEnv {\n\tconst env: NodeJS.ProcessEnv = { ATOMIC_SECURITY_QUERY_PATH: path };\n\tfor (const [key, value] of Object.entries(process.env)) {\n\t\tif (key.toLowerCase() !== \"psmodulepath\" && key !== \"ATOMIC_SECURITY_QUERY_PATH\") env[key] = value;\n\t}\n\treturn env;\n}\n\nfunction windowsDirectory(): string {\n\treturn process.env.SystemRoot ?? process.env.windir ?? \"C:\\\\Windows\";\n}\n\nasync function neutralWorkingDirectory(): Promise<string | undefined> {\n\ttry {\n\t\treturn (await statAsync(windowsDirectory())).isDirectory() ? windowsDirectory() : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nlet lastReadFailure: string | undefined;\n\n/** Test seam: why the most recent descriptor read returned `undefined`. */\nexport function getLastWindowsSecurityReadFailureForTesting(): string | undefined {\n\treturn lastReadFailure;\n}\n\ntype NativeSecurityReader = (path: string) => Promise<WindowsDirectorySecurity | null | undefined>;\n\nlet nativeReader: NativeSecurityReader | null | undefined;\n\nfunction nativeSecurityReader(): NativeSecurityReader | null {\n\tif (nativeReader === undefined) {\n\t\ttry {\n\t\t\tconst binding = createModuleRequire(import.meta.url)(\"@bastani/atomic-natives\") as {\n\t\t\t\twindowsDirectorySecurityAsync?: NativeSecurityReader;\n\t\t\t};\n\t\t\tnativeReader = binding.windowsDirectorySecurityAsync ?? null;\n\t\t} catch {\n\t\t\tnativeReader = null;\n\t\t}\n\t}\n\treturn nativeReader;\n}\n\nasync function readNatively(path: string): Promise<WindowsDirectorySecurity | null> {\n\tconst native = nativeSecurityReader();\n\tif (native === null) {\n\t\treturn null;\n\t}\n\ttry {\n\t\treturn (await native(path)) ?? null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport interface ReadWindowsDirectorySecurityOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n\tbackground?: boolean;\n\tidentity?: string;\n}\n\ntype SecurityAttempt = { security: WindowsDirectorySecurity } | { failure: string };\n\ntype ChildStream = (Readable & Partial<Pick<Socket, \"ref\" | \"unref\">>) | null;\n\nconst outsideAnyCaller = AsyncLocalStorage.snapshot();\n\nconst sharedReads = new Map<string, SharedSecurityRead>();\nconst currentReadOwner = new AsyncLocalStorage<WeakRef<AbortSignal>>();\nconst ownedReads = new WeakMap<AbortSignal, Set<Promise<void>>>();\nconst activeReads = new Set<Promise<void>>();\n\nexport function trackWindowsDirectorySecurityWork<T>(operation: () => Promise<T>): Promise<T> {\n\tconst owner = currentReadOwner.getStore()?.deref();\n\tconst result = operation();\n\tconst settled = result.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\tactiveReads.add(settled);\n\tconst pending = owner ? (ownedReads.get(owner) ?? new Set<Promise<void>>()) : undefined;\n\tif (owner && pending) ownedReads.set(owner, pending);\n\tpending?.add(settled);\n\tvoid settled.then(() => {\n\t\tactiveReads.delete(settled);\n\t\tpending?.delete(settled);\n\t});\n\treturn result;\n}\nconst closingReads = new Set<SharedSecurityRead>();\n\nexport function withWindowsDirectorySecurityOwner<T>(\n\tsignal: AbortSignal,\n\toperation: () => T,\n\toptions: { inherit?: boolean } = {},\n): T {\n\tconst inheritedOwner = options.inherit ? currentReadOwner.getStore()?.deref() : undefined;\n\treturn currentReadOwner.run(new WeakRef(inheritedOwner ?? signal), operation);\n}\n\nexport async function drainWindowsDirectorySecurityReads(signal: AbortSignal): Promise<void> {\n\tconst pending = ownedReads.get(signal);\n\twhile (pending?.size) await Promise.all(pending);\n}\n\nclass SharedSecurityRead {\n\treadonly result: Promise<WindowsDirectorySecurity | undefined>;\n\tprivate readonly controller = new AbortController();\n\tprivate waiters = 0;\n\tprivate foregroundWaiters = 0;\n\tprivate child: ChildProcess | undefined;\n\tprivate finished = false;\n\tprivate readonly path: string;\n\tprivate readonly key: string;\n\n\tconstructor(path: string, key: string) {\n\t\tthis.path = path;\n\t\tthis.key = key;\n\t\tthis.result = outsideAnyCaller(() => Promise.resolve().then(() => this.readCandidates())).finally(() => {\n\t\t\tif (sharedReads.get(key) === this) sharedReads.delete(key);\n\t\t\tthis.finished = true;\n\t\t\tclosingReads.delete(this);\n\t\t});\n\t}\n\n\tjoin(\n\t\ttimeoutMs: number,\n\t\tsignal: AbortSignal | undefined,\n\t\tbackground: boolean,\n\t): Promise<WindowsDirectorySecurity | undefined> {\n\t\tthis.waiters += 1;\n\t\tif (!background) this.foregroundWaiters += 1;\n\t\tthis.applyKeepAlive();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet left = false;\n\t\t\tconst leave = (security: WindowsDirectorySecurity | undefined) => {\n\t\t\t\tif (left) return;\n\t\t\t\tleft = true;\n\t\t\t\tclearTimeout(deadline);\n\t\t\t\tsignal?.removeEventListener(\"abort\", stopWaiting);\n\t\t\t\tthis.waiters -= 1;\n\t\t\t\tif (!background) this.foregroundWaiters -= 1;\n\t\t\t\tif (this.waiters === 0) {\n\t\t\t\t\tthis.cancel();\n\t\t\t\t\tvoid this.result.then(\n\t\t\t\t\t\t() => resolve(security),\n\t\t\t\t\t\t() => resolve(undefined),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.applyKeepAlive();\n\t\t\t\t\tresolve(security);\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst stopWaiting = () => leave(undefined);\n\t\t\tconst deadline = setTimeout(stopWaiting, timeoutMs);\n\t\t\tif (background) deadline.unref();\n\t\t\tsignal?.addEventListener(\"abort\", stopWaiting, { once: true });\n\t\t\tvoid this.result.then(leave, () => leave(undefined));\n\t\t});\n\t}\n\n\tcancel(): void {\n\t\tif (sharedReads.get(this.key) === this) sharedReads.delete(this.key);\n\t\tif (!this.finished) closingReads.add(this);\n\t\tthis.controller.abort();\n\t}\n\n\tprivate async readCandidates(): Promise<WindowsDirectorySecurity | undefined> {\n\t\tif (this.controller.signal.aborted) return undefined;\n\t\tlastReadFailure = undefined;\n\t\tconst security = await readNatively(this.path);\n\t\tif (this.controller.signal.aborted) return undefined;\n\t\tif (security !== null) return security;\n\t\tconst failures: string[] = [];\n\t\tfor (const executable of powershellCandidates()) {\n\t\t\tif (this.controller.signal.aborted) break;\n\t\t\tconst attempt = await this.readWith(executable);\n\t\t\tif (\"security\" in attempt) return attempt.security;\n\t\t\tfailures.push(attempt.failure);\n\t\t}\n\t\tlastReadFailure = failures.join(\" | \");\n\t\treturn undefined;\n\t}\n\n\tprivate async readWith(executable: string): Promise<SecurityAttempt> {\n\t\tconst cwd = await neutralWorkingDirectory();\n\t\tif (this.controller.signal.aborted) return { failure: `${executable}: aborted` };\n\t\treturn new Promise((resolve) => {\n\t\t\tlet child: ChildProcess;\n\t\t\ttry {\n\t\t\t\tchild = spawn(executable, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", READ_SECURITY_SCRIPT], {\n\t\t\t\t\tcwd,\n\t\t\t\t\tenv: powershellEnvironment(this.path),\n\t\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tresolve({ failure: `${executable}: error=${error instanceof Error ? error.message : String(error)}` });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.child = child;\n\t\t\tthis.applyKeepAlive();\n\t\t\tconst stdout: Buffer[] = [];\n\t\t\tconst stderr: Buffer[] = [];\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => stdout.push(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => stderr.push(chunk));\n\t\t\tlet settled = false;\n\t\t\tconst settle = (attempt: SecurityAttempt) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tthis.child = undefined;\n\t\t\t\tthis.controller.signal.removeEventListener(\"abort\", stop);\n\t\t\t\tresolve(attempt);\n\t\t\t};\n\t\t\tlet failure: string | undefined;\n\t\t\tlet stopping = false;\n\t\t\tconst stop = () => {\n\t\t\t\tfailure ??= `${executable}: aborted`;\n\t\t\t\tif (stopping) return;\n\t\t\t\tstopping = true;\n\t\t\t\tchild.ref();\n\t\t\t\tchild.kill();\n\t\t\t\tchild.stdout?.destroy();\n\t\t\t\tchild.stderr?.destroy();\n\t\t\t};\n\t\t\tthis.controller.signal.addEventListener(\"abort\", stop, { once: true });\n\t\t\tconst fail = (error: Error) => {\n\t\t\t\tfailure ??= `${executable}: error=${error.message}`;\n\t\t\t\tstop();\n\t\t\t};\n\t\t\tchild.on(\"error\", fail);\n\t\t\tchild.stdout?.on(\"error\", fail);\n\t\t\tchild.stderr?.on(\"error\", fail);\n\t\t\tchild.once(\"close\", (status, signal) => {\n\t\t\t\tif (failure !== undefined) {\n\t\t\t\t\tsettle({ failure });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst output = Buffer.concat(stdout).toString(\"utf8\");\n\t\t\t\tif (status !== 0) {\n\t\t\t\t\tconst detail = Buffer.concat(stderr).toString(\"utf8\").trim().slice(0, 500);\n\t\t\t\t\tsettle({ failure: `${executable}: status=${status} signal=${signal} stderr=${detail}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst security = parseSecurityOutput(output);\n\t\t\t\tsettle(\n\t\t\t\t\tsecurity === undefined\n\t\t\t\t\t\t? { failure: `${executable}: unparseable output ${JSON.stringify(output.slice(0, 500))}` }\n\t\t\t\t\t\t: { security },\n\t\t\t\t);\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate applyKeepAlive(): void {\n\t\tconst child = this.child;\n\t\tif (child === undefined) return;\n\t\tconst keepAlive = this.foregroundWaiters > 0;\n\t\tif (keepAlive) child.ref();\n\t\telse child.unref();\n\t\tconst streams: ChildStream[] = [child.stdout, child.stderr];\n\t\tfor (const stream of streams) {\n\t\t\tif (keepAlive) stream?.ref?.();\n\t\t\telse stream?.unref?.();\n\t\t}\n\t}\n}\n\n/**\n * Read the security descriptor of `path` without blocking the main thread, or\n * `undefined` when it cannot be read (access denied, missing PowerShell, the\n * timeout, an aborted signal). Callers treat `undefined` as unverifiable and\n * refuse the directory.\n */\nexport function readWindowsDirectorySecurityAsync(\n\tpath: string,\n\toptions: ReadWindowsDirectorySecurityOptions = {},\n): Promise<WindowsDirectorySecurity | undefined> {\n\treturn trackWindowsDirectorySecurityWork(async () => {\n\t\tconst owner = currentReadOwner.getStore()?.deref();\n\t\tconst signal = owner && options.signal ? AbortSignal.any([owner, options.signal]) : (owner ?? options.signal);\n\t\tif (signal?.aborted) return undefined;\n\t\tconst generation = stateGeneration;\n\t\tconst resolvedPath = resolve(path);\n\t\tconst identity = options.identity ?? (await identityOfAsync(resolvedPath));\n\t\tif (identity === undefined || signal?.aborted || generation !== stateGeneration) return undefined;\n\t\tconst key = `${identity}\\0${resolvedPath}`;\n\t\tlet read = sharedReads.get(key);\n\t\tif (read === undefined) {\n\t\t\tread = new SharedSecurityRead(resolvedPath, key);\n\t\t\tsharedReads.set(key, read);\n\t\t}\n\t\treturn read.join(options.timeoutMs ?? READ_SECURITY_TIMEOUT_MS, signal, options.background ?? false);\n\t});\n}\n\nfunction parseSecurityOutput(stdout: string): WindowsDirectorySecurity | undefined {\n\tconst [currentSid, ownerSid, dacl, ...ruleLines] = stdout.split(\"\\n\").map((line) => line.trim());\n\tif (!currentSid || !ownerSid || dacl === undefined) {\n\t\treturn undefined;\n\t}\n\tconst accessRules: WindowsAccessRule[] = [];\n\tfor (const line of ruleLines) {\n\t\tif (line.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst [type, sid] = line.split(\";\");\n\t\tif ((type !== \"Allow\" && type !== \"Deny\") || !sid) {\n\t\t\treturn undefined;\n\t\t}\n\t\taccessRules.push({ allow: type === \"Allow\", sid });\n\t}\n\treturn { currentSid, ownerSid, dacl, accessRules };\n}\n\ntype SecurityReader = (\n\tpath: string,\n\toptions: ReadWindowsDirectorySecurityOptions,\n) => WindowsDirectorySecurity | undefined | Promise<WindowsDirectorySecurity | undefined>;\n\nlet securityReader: SecurityReader = readWindowsDirectorySecurityAsync;\n\nlet stateGeneration = 0;\n\n/**\n * Verified paths mapped to the identity of the directory verified there: its volume, file ID and creation time. A\n * directory recreated at the path is a new file with a new ID; the creation time alone would not tell, since NTFS gives\n * a name recreated within seconds of its deletion the old creation time back (\"tunneling\").\n */\nconst verifiedPaths = new Map<string, string>();\n\n/** The identity of the directory at `path`, or `undefined` when it cannot be read. */\nfunction identityOf(path: string): string | undefined {\n\ttry {\n\t\tconst stat = statSync(path, { bigint: true });\n\t\treturn `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function identityOfAsync(path: string): Promise<string | undefined> {\n\ttry {\n\t\tconst stat = await statAsync(path, { bigint: true });\n\t\treturn `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** True when `path` was verified in this process and is still the directory verified there. */\nfunction stillVerified(path: string, identity: string | undefined): boolean {\n\treturn identity !== undefined && verifiedPaths.get(path) === identity;\n}\n\nfunction verifiedWithoutReading(path: string, identity: string): boolean {\n\tif (stillVerified(path, identity)) {\n\t\treturn true;\n\t}\n\tconst parent = dirname(path);\n\tif (parent !== path && stillVerified(parent, identityOf(parent))) {\n\t\tverifiedPaths.set(path, identity);\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Verify `path` as adoptable, returning the refusal reason when it is not.\n *\n * The descriptor is read natively, with an asynchronous PowerShell fallback, once per private root per process:\n *\n * - A directory verified in this process is trusted for the rest of it while it is the same directory (same file ID and\n * creation time). Only its owner or an administrator can change its DACL (the verified DACL grants nobody else that\n * right), and both can already reach everything below it, so an in-place edit by one of them is not read again. A\n * directory swapped underneath the path is a new file and is read again, and so is one swapped while it was read.\n * - A directory inside a verified one needs no read of its own. The verified DACL lets only trusted principals create\n * entries in it, and grants nobody else access through inheritance either, since an inheritable entry for another\n * account refuses the parent itself; so a directory inside it was made by a trusted principal and starts private.\n *\n * The symlink/directory checks in `session-temp-dir.ts` still run on every use. A failure is never cached, so a\n * transient read error does not permanently disable spills.\n */\nexport function verifyWindowsDirectorySecurityAsync(\n\tpath: string,\n\tsignal?: AbortSignal,\n\toptions: { background?: boolean } = {},\n): Promise<string | undefined> {\n\treturn trackWindowsDirectorySecurityWork(async () => {\n\t\tconst generation = stateGeneration;\n\t\tconst resolvedPath = resolve(path);\n\t\tconst identity = await identityOfAsync(resolvedPath);\n\t\tif (identity === undefined || generation !== stateGeneration) return \"its ownership could not be verified\";\n\t\tif (stillVerified(resolvedPath, identity)) return undefined;\n\t\tconst parent = dirname(resolvedPath);\n\t\tconst inherited = parent !== resolvedPath && stillVerified(parent, await identityOfAsync(parent));\n\t\tif (generation !== stateGeneration) return \"its ownership could not be verified\";\n\t\tif (!inherited) {\n\t\t\tconst security = await securityReader(resolvedPath, { signal, background: options.background, identity });\n\t\t\tif (security === undefined) return \"its ownership could not be verified\";\n\t\t\tconst refusal = evaluateWindowsDirectorySecurity(security);\n\t\t\tif (generation !== stateGeneration) return refusal ?? \"its ownership could not be verified\";\n\t\t\tif (refusal !== undefined) {\n\t\t\t\tif (verifiedPaths.get(resolvedPath) === identity) verifiedPaths.delete(resolvedPath);\n\t\t\t\treturn refusal;\n\t\t\t}\n\t\t}\n\t\tif ((await identityOfAsync(resolvedPath)) !== identity || generation !== stateGeneration)\n\t\t\treturn \"its ownership could not be verified\";\n\t\tverifiedPaths.set(resolvedPath, identity);\n\t\treturn undefined;\n\t});\n}\n\nexport function verifyWindowsDirectorySecurity(\n\tpath: string,\n\toptions: { startVerification?: boolean } = {},\n): string | undefined {\n\tconst resolvedPath = resolve(path);\n\tconst identity = identityOf(resolvedPath);\n\tif (identity === undefined) {\n\t\treturn \"its ownership could not be verified\";\n\t}\n\tif (verifiedWithoutReading(resolvedPath, identity)) {\n\t\treturn undefined;\n\t}\n\tif (options.startVerification !== false) {\n\t\tverifyWindowsDirectorySecurityAsync(resolvedPath, undefined, { background: true }).catch(() => undefined);\n\t}\n\treturn VERIFICATION_PENDING_REASON;\n}\n\nexport async function waitForWindowsDirectorySecurityReadsForTesting(): Promise<void> {\n\twhile (activeReads.size || sharedReads.size || closingReads.size) {\n\t\tawait Promise.all([...activeReads, ...[...sharedReads.values(), ...closingReads].map((read) => read.result)]);\n\t}\n}\n\n/** Test seam: substitute the descriptor reader; pass `undefined` to restore. */\nexport function setWindowsDirectorySecurityReaderForTesting(reader: SecurityReader | undefined): void {\n\tsecurityReader = reader ?? readWindowsDirectorySecurityAsync;\n}\n\n/** Test seam: forget verified paths and cancel reads in flight so a suite can re-drive verification. */\nexport function resetWindowsDirectorySecurityStateForTesting(): void {\n\tstateGeneration += 1;\n\tverifiedPaths.clear();\n\tfor (const read of [...sharedReads.values()]) read.cancel();\n\tsharedReads.clear();\n\tlastReadFailure = undefined;\n\tsecurityReader = readWindowsDirectorySecurityAsync;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"windows-directory-security.js","sourceRoot":"","sources":["../../../src/core/tools/windows-directory-security.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,OAAO,EA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C,KAAK,EAAE,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;QAAE,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5D,WAAW,CAAC,KAAK,EAAE,CAAC;IACpB,eAAe,GAAG,SAAS,CAAC;IAC5B,cAAc,GAAG,iCAAiC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Windows owner-SID and DACL verification for the session temp tree.\n *\n * POSIX proves ownership of an existing temp component with a uid comparison\n * and a mode check. Node exposes neither on Windows — `lstatSync` reports\n * uid/gid 0 — so this module reads the real security descriptor and decides\n * from SIDs alone: the owner must\n * be a trusted principal and every access-allowed ACE must grant only trusted\n * principals. Names are never compared; two accounts can share a display name,\n * but never a SID.\n *\n * The native module reads the descriptor directly. When that binding is\n * unavailable or cannot read the directory, an asynchronous PowerShell\n * subprocess reads it instead. Reads start after the synchronous caller\n * returns, so a synchronous check never reads the descriptor. A successful\n * verification is cached for the life of the process, keyed to the\n * directory's path and identity (its file ID and creation time),\n * and a directory inside a verified one needs no read of its own (see\n * `verifyWindowsDirectorySecurityAsync`). A directory swapped underneath the\n * path is a new file with a new ID and is read again.\n * Failures are not cached: a refusal means \"no spill file this time\", and a\n * transient read failure must not disable persistence for the rest of the\n * process.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport { statSync } from \"node:fs\";\nimport { stat as statAsync } from \"node:fs/promises\";\nimport type { Socket } from \"node:net\";\nimport { dirname, resolve } from \"node:path\";\nimport type { Readable } from \"node:stream\";\nimport { clearTimeout, setTimeout } from \"node:timers\";\nimport { createModuleRequire } from \"../../utils/module-require.js\";\nimport { windowsPowerShellEnvironment } from \"../../utils/windows-powershell.ts\";\n\n/** One DACL entry with its trustee resolved to a literal SID. */\nexport interface WindowsAccessRule {\n\t/** True for an access-allowed entry, false for access-denied. */\n\tallow: boolean;\n\t/** The SID the entry applies to. */\n\tsid: string;\n}\n\n/** What the security read produces: the caller's SID plus the descriptor. */\nexport interface WindowsDirectorySecurity {\n\t/** SID of the current process token's user. */\n\tcurrentSid: string;\n\t/** SID owning the directory. */\n\townerSid: string;\n\t/** The DACL portion of the descriptor in SDDL form (may be empty). */\n\tdacl: string;\n\t/**\n\t * Every DACL entry with its trustee as a literal SID (`GetAccessRules`\n\t * resolves domain-relative SDDL abbreviations such as `LA` that a\n\t * name-side parse cannot). The SDDL string above cross-checks that these\n\t * rules describe the whole DACL: only plain allow/deny ACE types, one\n\t * rule per ACE.\n\t */\n\taccessRules: readonly WindowsAccessRule[];\n}\n\n/**\n * Principals allowed to own, or hold access-allowed ACEs on, a temp component.\n *\n * SYSTEM and Administrators hold both on any per-user Windows temp directory\n * by inheritance, and both can reach any file on the volume regardless, so\n * permitting them grants nothing an attacker did not already have. Elevated\n * processes also create directories owned by the Administrators group rather\n * than the user, which is why the owner check shares this set. CREATOR OWNER\n * is inherit-only plumbing: it materializes as the creating account on\n * descendants, and creation inside the tree is already restricted to the\n * SIDs allowed here.\n */\nconst TRUSTED_STATIC_SIDS = new Set<string>([\n\t\"S-1-5-18\", // Local System\n\t\"S-1-5-32-544\", // Builtin Administrators\n\t\"S-1-3-0\", // Creator Owner\n\t\"S-1-3-4\", // Owner Rights\n]);\n\n/**\n * Decide whether a directory's descriptor is safe to adopt.\n *\n * Returns a refusal reason, or `undefined` when the directory is owned by a\n * trusted principal and its DACL grants access to trusted principals only.\n * Exported as a pure function so the decision table is testable on any host.\n */\nexport function evaluateWindowsDirectorySecurity(security: WindowsDirectorySecurity): string | undefined {\n\tconst trusted = (sid: string): boolean => sid === security.currentSid || TRUSTED_STATIC_SIDS.has(sid);\n\tif (!security.ownerSid.startsWith(\"S-1-\")) {\n\t\treturn \"its owner could not be verified\";\n\t}\n\tif (!trusted(security.ownerSid)) {\n\t\treturn \"it is owned by another account\";\n\t}\n\t// `Get-Acl` renders a null DACL (everyone has full control) as an absent\n\t// `D:` section; an empty DACL (`D:` with no ACEs) grants nobody anything\n\t// and is fine.\n\tconst dacl = security.dacl.trim();\n\tif (!dacl.startsWith(\"D:\")) {\n\t\treturn \"it has no access control list\";\n\t}\n\tlet rest = dacl.slice(2);\n\tconst flagsEnd = rest.indexOf(\"(\");\n\tconst flags = flagsEnd === -1 ? rest : rest.slice(0, flagsEnd);\n\tif (!/^[A-Z]*$/.test(flags)) {\n\t\treturn \"its access control list could not be parsed\";\n\t}\n\trest = flagsEnd === -1 ? \"\" : rest.slice(flagsEnd);\n\tconst aces = rest.match(/\\([^()]*\\)/g) ?? [];\n\tif (aces.join(\"\") !== rest) {\n\t\treturn \"its access control list could not be parsed\";\n\t}\n\tfor (const ace of aces) {\n\t\tconst type = ace.slice(1, -1).split(\";\")[0];\n\t\tif (type !== \"A\" && type !== \"D\") {\n\t\t\t// Conditional, object, and callback ACEs are not modeled by the\n\t\t\t// resolved access rules below, so a DACL containing one cannot be\n\t\t\t// proven restrictive.\n\t\t\treturn \"its access control list could not be verified\";\n\t\t}\n\t}\n\tif (security.accessRules.length !== aces.length) {\n\t\t// The resolved rules must describe the whole DACL; a mismatch means\n\t\t// part of it was not translated and cannot be checked.\n\t\treturn \"its access control list could not be verified\";\n\t}\n\tfor (const rule of security.accessRules) {\n\t\tif (!rule.allow) {\n\t\t\tcontinue; // A deny entry only ever removes access.\n\t\t}\n\t\tif (!rule.sid.startsWith(\"S-1-\")) {\n\t\t\treturn \"its access control list could not be verified\";\n\t\t}\n\t\tif (!trusted(rule.sid)) {\n\t\t\treturn \"it grants access to another account\";\n\t\t}\n\t}\n\treturn undefined;\n}\n\n/**\n * One PowerShell round trip: the caller's SID, the owner SID, the DACL in\n * SDDL form, and one `Allow|Deny;SID` line per resolved access rule. The path\n * travels through the environment rather than the command line so no quoting\n * rules apply to it.\n */\nconst READ_SECURITY_SCRIPT = [\n\t\"$ErrorActionPreference = 'Stop'\",\n\t\"$acl = Get-Acl -LiteralPath $env:ATOMIC_SECURITY_QUERY_PATH\",\n\t\"$owner = $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value\",\n\t\"$dacl = $acl.GetSecurityDescriptorSddlForm('Access')\",\n\t\"$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value\",\n\t\"$lines = @($user, $owner, $dacl)\",\n\t\"foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))\" +\n\t\t' { $lines += \"$($rule.AccessControlType);$($rule.IdentityReference.Value)\" }',\n\t'[Console]::Out.Write(($lines -join \"`n\"))',\n].join(\"; \");\n\n/** Bounded wait for the security read; a wedged subprocess must not hang a spill. */\nconst READ_SECURITY_TIMEOUT_MS = 30_000;\n\nexport const VERIFICATION_PENDING_REASON = \"its ownership is still being verified\";\n\n/** PowerShell hosts to try, most specific first: an absolute Windows\n * PowerShell path immune to a stripped `PATH`, then whichever of\n * `powershell.exe`/`pwsh.exe` the environment resolves. */\nexport function powershellCandidates(): string[] {\n\tconst candidates: string[] = [];\n\tcandidates.push(`${windowsDirectory()}\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe`);\n\tcandidates.push(\"powershell.exe\", \"pwsh.exe\");\n\treturn candidates;\n}\n\n/** The environment for a PowerShell read: Windows PowerShell's, plus the path the read is for. */\nfunction powershellEnvironment(path: string): NodeJS.ProcessEnv {\n\treturn { ...windowsPowerShellEnvironment(), ATOMIC_SECURITY_QUERY_PATH: path };\n}\n\nfunction windowsDirectory(): string {\n\treturn process.env.SystemRoot ?? process.env.windir ?? \"C:\\\\Windows\";\n}\n\nasync function neutralWorkingDirectory(): Promise<string | undefined> {\n\ttry {\n\t\treturn (await statAsync(windowsDirectory())).isDirectory() ? windowsDirectory() : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nlet lastReadFailure: string | undefined;\n\n/** Test seam: why the most recent descriptor read returned `undefined`. */\nexport function getLastWindowsSecurityReadFailureForTesting(): string | undefined {\n\treturn lastReadFailure;\n}\n\ntype NativeSecurityReader = (path: string) => Promise<WindowsDirectorySecurity | null | undefined>;\n\nlet nativeReader: NativeSecurityReader | null | undefined;\n\nfunction nativeSecurityReader(): NativeSecurityReader | null {\n\tif (nativeReader === undefined) {\n\t\ttry {\n\t\t\tconst binding = createModuleRequire(import.meta.url)(\"@bastani/atomic-natives\") as {\n\t\t\t\twindowsDirectorySecurityAsync?: NativeSecurityReader;\n\t\t\t};\n\t\t\tnativeReader = binding.windowsDirectorySecurityAsync ?? null;\n\t\t} catch {\n\t\t\tnativeReader = null;\n\t\t}\n\t}\n\treturn nativeReader;\n}\n\nasync function readNatively(path: string): Promise<WindowsDirectorySecurity | null> {\n\tconst native = nativeSecurityReader();\n\tif (native === null) {\n\t\treturn null;\n\t}\n\ttry {\n\t\treturn (await native(path)) ?? null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nexport interface ReadWindowsDirectorySecurityOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n\tbackground?: boolean;\n\tidentity?: string;\n}\n\ntype SecurityAttempt = { security: WindowsDirectorySecurity } | { failure: string };\n\ntype ChildStream = (Readable & Partial<Pick<Socket, \"ref\" | \"unref\">>) | null;\n\nconst outsideAnyCaller = AsyncLocalStorage.snapshot();\n\nconst sharedReads = new Map<string, SharedSecurityRead>();\nconst currentReadOwner = new AsyncLocalStorage<WeakRef<AbortSignal>>();\nconst ownedReads = new WeakMap<AbortSignal, Set<Promise<void>>>();\nconst activeReads = new Set<Promise<void>>();\n\nexport function trackWindowsDirectorySecurityWork<T>(operation: () => Promise<T>): Promise<T> {\n\tconst owner = currentReadOwner.getStore()?.deref();\n\tconst result = operation();\n\tconst settled = result.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\tactiveReads.add(settled);\n\tconst pending = owner ? (ownedReads.get(owner) ?? new Set<Promise<void>>()) : undefined;\n\tif (owner && pending) ownedReads.set(owner, pending);\n\tpending?.add(settled);\n\tvoid settled.then(() => {\n\t\tactiveReads.delete(settled);\n\t\tpending?.delete(settled);\n\t});\n\treturn result;\n}\nconst closingReads = new Set<SharedSecurityRead>();\n\nexport function withWindowsDirectorySecurityOwner<T>(\n\tsignal: AbortSignal,\n\toperation: () => T,\n\toptions: { inherit?: boolean } = {},\n): T {\n\tconst inheritedOwner = options.inherit ? currentReadOwner.getStore()?.deref() : undefined;\n\treturn currentReadOwner.run(new WeakRef(inheritedOwner ?? signal), operation);\n}\n\nexport async function drainWindowsDirectorySecurityReads(signal: AbortSignal): Promise<void> {\n\tconst pending = ownedReads.get(signal);\n\twhile (pending?.size) await Promise.all(pending);\n}\n\nclass SharedSecurityRead {\n\treadonly result: Promise<WindowsDirectorySecurity | undefined>;\n\tprivate readonly controller = new AbortController();\n\tprivate waiters = 0;\n\tprivate foregroundWaiters = 0;\n\tprivate child: ChildProcess | undefined;\n\tprivate finished = false;\n\tprivate readonly path: string;\n\tprivate readonly key: string;\n\n\tconstructor(path: string, key: string) {\n\t\tthis.path = path;\n\t\tthis.key = key;\n\t\tthis.result = outsideAnyCaller(() => Promise.resolve().then(() => this.readCandidates())).finally(() => {\n\t\t\tif (sharedReads.get(key) === this) sharedReads.delete(key);\n\t\t\tthis.finished = true;\n\t\t\tclosingReads.delete(this);\n\t\t});\n\t}\n\n\tjoin(\n\t\ttimeoutMs: number,\n\t\tsignal: AbortSignal | undefined,\n\t\tbackground: boolean,\n\t): Promise<WindowsDirectorySecurity | undefined> {\n\t\tthis.waiters += 1;\n\t\tif (!background) this.foregroundWaiters += 1;\n\t\tthis.applyKeepAlive();\n\t\treturn new Promise((resolve) => {\n\t\t\tlet left = false;\n\t\t\tconst leave = (security: WindowsDirectorySecurity | undefined) => {\n\t\t\t\tif (left) return;\n\t\t\t\tleft = true;\n\t\t\t\tclearTimeout(deadline);\n\t\t\t\tsignal?.removeEventListener(\"abort\", stopWaiting);\n\t\t\t\tthis.waiters -= 1;\n\t\t\t\tif (!background) this.foregroundWaiters -= 1;\n\t\t\t\tif (this.waiters === 0) {\n\t\t\t\t\tthis.cancel();\n\t\t\t\t\tvoid this.result.then(\n\t\t\t\t\t\t() => resolve(security),\n\t\t\t\t\t\t() => resolve(undefined),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.applyKeepAlive();\n\t\t\t\t\tresolve(security);\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst stopWaiting = () => leave(undefined);\n\t\t\tconst deadline = setTimeout(stopWaiting, timeoutMs);\n\t\t\tif (background) deadline.unref();\n\t\t\tsignal?.addEventListener(\"abort\", stopWaiting, { once: true });\n\t\t\tvoid this.result.then(leave, () => leave(undefined));\n\t\t});\n\t}\n\n\tcancel(): void {\n\t\tif (sharedReads.get(this.key) === this) sharedReads.delete(this.key);\n\t\tif (!this.finished) closingReads.add(this);\n\t\tthis.controller.abort();\n\t}\n\n\tprivate async readCandidates(): Promise<WindowsDirectorySecurity | undefined> {\n\t\tif (this.controller.signal.aborted) return undefined;\n\t\tlastReadFailure = undefined;\n\t\tconst security = await readNatively(this.path);\n\t\tif (this.controller.signal.aborted) return undefined;\n\t\tif (security !== null) return security;\n\t\tconst failures: string[] = [];\n\t\tfor (const executable of powershellCandidates()) {\n\t\t\tif (this.controller.signal.aborted) break;\n\t\t\tconst attempt = await this.readWith(executable);\n\t\t\tif (\"security\" in attempt) return attempt.security;\n\t\t\tfailures.push(attempt.failure);\n\t\t}\n\t\tlastReadFailure = failures.join(\" | \");\n\t\treturn undefined;\n\t}\n\n\tprivate async readWith(executable: string): Promise<SecurityAttempt> {\n\t\tconst cwd = await neutralWorkingDirectory();\n\t\tif (this.controller.signal.aborted) return { failure: `${executable}: aborted` };\n\t\treturn new Promise((resolve) => {\n\t\t\tlet child: ChildProcess;\n\t\t\ttry {\n\t\t\t\tchild = spawn(executable, [\"-NoProfile\", \"-NonInteractive\", \"-Command\", READ_SECURITY_SCRIPT], {\n\t\t\t\t\tcwd,\n\t\t\t\t\tenv: powershellEnvironment(this.path),\n\t\t\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tresolve({ failure: `${executable}: error=${error instanceof Error ? error.message : String(error)}` });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.child = child;\n\t\t\tthis.applyKeepAlive();\n\t\t\tconst stdout: Buffer[] = [];\n\t\t\tconst stderr: Buffer[] = [];\n\t\t\tchild.stdout?.on(\"data\", (chunk: Buffer) => stdout.push(chunk));\n\t\t\tchild.stderr?.on(\"data\", (chunk: Buffer) => stderr.push(chunk));\n\t\t\tlet settled = false;\n\t\t\tconst settle = (attempt: SecurityAttempt) => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tthis.child = undefined;\n\t\t\t\tthis.controller.signal.removeEventListener(\"abort\", stop);\n\t\t\t\tresolve(attempt);\n\t\t\t};\n\t\t\tlet failure: string | undefined;\n\t\t\tlet stopping = false;\n\t\t\tconst stop = () => {\n\t\t\t\tfailure ??= `${executable}: aborted`;\n\t\t\t\tif (stopping) return;\n\t\t\t\tstopping = true;\n\t\t\t\tchild.ref();\n\t\t\t\tchild.kill();\n\t\t\t\tchild.stdout?.destroy();\n\t\t\t\tchild.stderr?.destroy();\n\t\t\t};\n\t\t\tthis.controller.signal.addEventListener(\"abort\", stop, { once: true });\n\t\t\tconst fail = (error: Error) => {\n\t\t\t\tfailure ??= `${executable}: error=${error.message}`;\n\t\t\t\tstop();\n\t\t\t};\n\t\t\tchild.on(\"error\", fail);\n\t\t\tchild.stdout?.on(\"error\", fail);\n\t\t\tchild.stderr?.on(\"error\", fail);\n\t\t\tchild.once(\"close\", (status, signal) => {\n\t\t\t\tif (failure !== undefined) {\n\t\t\t\t\tsettle({ failure });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst output = Buffer.concat(stdout).toString(\"utf8\");\n\t\t\t\tif (status !== 0) {\n\t\t\t\t\tconst detail = Buffer.concat(stderr).toString(\"utf8\").trim().slice(0, 500);\n\t\t\t\t\tsettle({ failure: `${executable}: status=${status} signal=${signal} stderr=${detail}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst security = parseSecurityOutput(output);\n\t\t\t\tsettle(\n\t\t\t\t\tsecurity === undefined\n\t\t\t\t\t\t? { failure: `${executable}: unparseable output ${JSON.stringify(output.slice(0, 500))}` }\n\t\t\t\t\t\t: { security },\n\t\t\t\t);\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate applyKeepAlive(): void {\n\t\tconst child = this.child;\n\t\tif (child === undefined) return;\n\t\tconst keepAlive = this.foregroundWaiters > 0;\n\t\tif (keepAlive) child.ref();\n\t\telse child.unref();\n\t\tconst streams: ChildStream[] = [child.stdout, child.stderr];\n\t\tfor (const stream of streams) {\n\t\t\tif (keepAlive) stream?.ref?.();\n\t\t\telse stream?.unref?.();\n\t\t}\n\t}\n}\n\n/**\n * Read the security descriptor of `path` without blocking the main thread, or\n * `undefined` when it cannot be read (access denied, missing PowerShell, the\n * timeout, an aborted signal). Callers treat `undefined` as unverifiable and\n * refuse the directory.\n */\nexport function readWindowsDirectorySecurityAsync(\n\tpath: string,\n\toptions: ReadWindowsDirectorySecurityOptions = {},\n): Promise<WindowsDirectorySecurity | undefined> {\n\treturn trackWindowsDirectorySecurityWork(async () => {\n\t\tconst owner = currentReadOwner.getStore()?.deref();\n\t\tconst signal = owner && options.signal ? AbortSignal.any([owner, options.signal]) : (owner ?? options.signal);\n\t\tif (signal?.aborted) return undefined;\n\t\tconst generation = stateGeneration;\n\t\tconst resolvedPath = resolve(path);\n\t\tconst identity = options.identity ?? (await identityOfAsync(resolvedPath));\n\t\tif (identity === undefined || signal?.aborted || generation !== stateGeneration) return undefined;\n\t\tconst key = `${identity}\\0${resolvedPath}`;\n\t\tlet read = sharedReads.get(key);\n\t\tif (read === undefined) {\n\t\t\tread = new SharedSecurityRead(resolvedPath, key);\n\t\t\tsharedReads.set(key, read);\n\t\t}\n\t\treturn read.join(options.timeoutMs ?? READ_SECURITY_TIMEOUT_MS, signal, options.background ?? false);\n\t});\n}\n\nfunction parseSecurityOutput(stdout: string): WindowsDirectorySecurity | undefined {\n\tconst [currentSid, ownerSid, dacl, ...ruleLines] = stdout.split(\"\\n\").map((line) => line.trim());\n\tif (!currentSid || !ownerSid || dacl === undefined) {\n\t\treturn undefined;\n\t}\n\tconst accessRules: WindowsAccessRule[] = [];\n\tfor (const line of ruleLines) {\n\t\tif (line.length === 0) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst [type, sid] = line.split(\";\");\n\t\tif ((type !== \"Allow\" && type !== \"Deny\") || !sid) {\n\t\t\treturn undefined;\n\t\t}\n\t\taccessRules.push({ allow: type === \"Allow\", sid });\n\t}\n\treturn { currentSid, ownerSid, dacl, accessRules };\n}\n\ntype SecurityReader = (\n\tpath: string,\n\toptions: ReadWindowsDirectorySecurityOptions,\n) => WindowsDirectorySecurity | undefined | Promise<WindowsDirectorySecurity | undefined>;\n\nlet securityReader: SecurityReader = readWindowsDirectorySecurityAsync;\n\nlet stateGeneration = 0;\n\n/**\n * Verified paths mapped to the identity of the directory verified there: its volume, file ID and creation time. A\n * directory recreated at the path is a new file with a new ID; the creation time alone would not tell, since NTFS gives\n * a name recreated within seconds of its deletion the old creation time back (\"tunneling\").\n */\nconst verifiedPaths = new Map<string, string>();\n\n/** The identity of the directory at `path`, or `undefined` when it cannot be read. */\nfunction identityOf(path: string): string | undefined {\n\ttry {\n\t\tconst stat = statSync(path, { bigint: true });\n\t\treturn `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function identityOfAsync(path: string): Promise<string | undefined> {\n\ttry {\n\t\tconst stat = await statAsync(path, { bigint: true });\n\t\treturn `${stat.dev}:${stat.ino}:${stat.birthtimeNs}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** True when `path` was verified in this process and is still the directory verified there. */\nfunction stillVerified(path: string, identity: string | undefined): boolean {\n\treturn identity !== undefined && verifiedPaths.get(path) === identity;\n}\n\nfunction verifiedWithoutReading(path: string, identity: string): boolean {\n\tif (stillVerified(path, identity)) {\n\t\treturn true;\n\t}\n\tconst parent = dirname(path);\n\tif (parent !== path && stillVerified(parent, identityOf(parent))) {\n\t\tverifiedPaths.set(path, identity);\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/**\n * Verify `path` as adoptable, returning the refusal reason when it is not.\n *\n * The descriptor is read natively, with an asynchronous PowerShell fallback, once per private root per process:\n *\n * - A directory verified in this process is trusted for the rest of it while it is the same directory (same file ID and\n * creation time). Only its owner or an administrator can change its DACL (the verified DACL grants nobody else that\n * right), and both can already reach everything below it, so an in-place edit by one of them is not read again. A\n * directory swapped underneath the path is a new file and is read again, and so is one swapped while it was read.\n * - A directory inside a verified one needs no read of its own. The verified DACL lets only trusted principals create\n * entries in it, and grants nobody else access through inheritance either, since an inheritable entry for another\n * account refuses the parent itself; so a directory inside it was made by a trusted principal and starts private.\n *\n * The symlink/directory checks in `session-temp-dir.ts` still run on every use. A failure is never cached, so a\n * transient read error does not permanently disable spills.\n */\nexport function verifyWindowsDirectorySecurityAsync(\n\tpath: string,\n\tsignal?: AbortSignal,\n\toptions: { background?: boolean } = {},\n): Promise<string | undefined> {\n\treturn trackWindowsDirectorySecurityWork(async () => {\n\t\tconst generation = stateGeneration;\n\t\tconst resolvedPath = resolve(path);\n\t\tconst identity = await identityOfAsync(resolvedPath);\n\t\tif (identity === undefined || generation !== stateGeneration) return \"its ownership could not be verified\";\n\t\tif (stillVerified(resolvedPath, identity)) return undefined;\n\t\tconst parent = dirname(resolvedPath);\n\t\tconst inherited = parent !== resolvedPath && stillVerified(parent, await identityOfAsync(parent));\n\t\tif (generation !== stateGeneration) return \"its ownership could not be verified\";\n\t\tif (!inherited) {\n\t\t\tconst security = await securityReader(resolvedPath, { signal, background: options.background, identity });\n\t\t\tif (security === undefined) return \"its ownership could not be verified\";\n\t\t\tconst refusal = evaluateWindowsDirectorySecurity(security);\n\t\t\tif (generation !== stateGeneration) return refusal ?? \"its ownership could not be verified\";\n\t\t\tif (refusal !== undefined) {\n\t\t\t\tif (verifiedPaths.get(resolvedPath) === identity) verifiedPaths.delete(resolvedPath);\n\t\t\t\treturn refusal;\n\t\t\t}\n\t\t}\n\t\tif ((await identityOfAsync(resolvedPath)) !== identity || generation !== stateGeneration)\n\t\t\treturn \"its ownership could not be verified\";\n\t\tverifiedPaths.set(resolvedPath, identity);\n\t\treturn undefined;\n\t});\n}\n\nexport function verifyWindowsDirectorySecurity(\n\tpath: string,\n\toptions: { startVerification?: boolean } = {},\n): string | undefined {\n\tconst resolvedPath = resolve(path);\n\tconst identity = identityOf(resolvedPath);\n\tif (identity === undefined) {\n\t\treturn \"its ownership could not be verified\";\n\t}\n\tif (verifiedWithoutReading(resolvedPath, identity)) {\n\t\treturn undefined;\n\t}\n\tif (options.startVerification !== false) {\n\t\tverifyWindowsDirectorySecurityAsync(resolvedPath, undefined, { background: true }).catch(() => undefined);\n\t}\n\treturn VERIFICATION_PENDING_REASON;\n}\n\nexport async function waitForWindowsDirectorySecurityReadsForTesting(): Promise<void> {\n\twhile (activeReads.size || sharedReads.size || closingReads.size) {\n\t\tawait Promise.all([...activeReads, ...[...sharedReads.values(), ...closingReads].map((read) => read.result)]);\n\t}\n}\n\n/** Test seam: substitute the descriptor reader; pass `undefined` to restore. */\nexport function setWindowsDirectorySecurityReaderForTesting(reader: SecurityReader | undefined): void {\n\tsecurityReader = reader ?? readWindowsDirectorySecurityAsync;\n}\n\n/** Test seam: forget verified paths and cancel reads in flight so a suite can re-drive verification. */\nexport function resetWindowsDirectorySecurityStateForTesting(): void {\n\tstateGeneration += 1;\n\tverifiedPaths.clear();\n\tfor (const read of [...sharedReads.values()]) read.cancel();\n\tsharedReads.clear();\n\tlastReadFailure = undefined;\n\tsecurityReader = readWindowsDirectorySecurityAsync;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../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AQ,EAAE,QAAQ,EAClB,OAAO,GAAE,8BAAmC,GAC1C,OAAO,CAAC,uBAAuB,CAAC,CASlC;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAC1C,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,MAAM,OAAO,CAAC,uBAAuB,CAAC,EAC/C,MAAM,EAAE,CAAC,OAAO,EAAE,uBAAuB,KAAK,OAAO,CAAC,IAAI,CAAC,GACzD,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,8GAA8G;AAC9G,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CAErF"}
|
|
@@ -141,9 +141,33 @@ export async function withScratchDirectory(action) {
|
|
|
141
141
|
export const RESTORED_TREE_FILE = "atomic-restored-tree";
|
|
142
142
|
/** Records `tree` as the tree the restored worktree at `worktree` holds. */
|
|
143
143
|
export async function recordRestoredTree(worktree, tree) {
|
|
144
|
-
const gitDir = await gitText(["rev-parse", "--absolute-git-dir"], worktree);
|
|
144
|
+
const gitDir = (await linkedWorktreeGitDir(worktree.cwd)) ?? (await gitText(["rev-parse", "--absolute-git-dir"], worktree));
|
|
145
145
|
await writeFile(join(gitDir, RESTORED_TREE_FILE), `${tree}\n`);
|
|
146
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* The Git directory a linked worktree's `.git` file at `root` names, read without starting Git: `git worktree add`
|
|
149
|
+
* writes it as one `gitdir: <path>` line, relative to `root` when Git writes relative worktree paths. Undefined for
|
|
150
|
+
* anything else, such as a `.git` directory or a file naming no existing directory, which Git is asked about instead.
|
|
151
|
+
*/
|
|
152
|
+
async function linkedWorktreeGitDir(root) {
|
|
153
|
+
let text;
|
|
154
|
+
try {
|
|
155
|
+
text = await readFile(join(root, ".git"), "utf8");
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
const match = /^gitdir: (.+?)\r?\n?$/.exec(text);
|
|
161
|
+
if (match === null)
|
|
162
|
+
return undefined;
|
|
163
|
+
const gitDir = resolve(root, match[1]);
|
|
164
|
+
try {
|
|
165
|
+
return (await stat(gitDir)).isDirectory() ? gitDir : undefined;
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
147
171
|
/** The tree a restore recorded in the Git directory `gitDir`, or undefined when it is not a restored worktree. */
|
|
148
172
|
async function restoredTreeOf(gitDir) {
|
|
149
173
|
try {
|