@creatornader/agent-bridge 0.2.0 → 0.3.1
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 +86 -4
- package/README.md +567 -55
- package/ROADMAP.md +114 -0
- package/SECURITY.md +90 -0
- package/SKILL.md +68 -2
- package/bin/agent-bridge +2 -2
- package/clients/claude-desktop.json +3 -1
- package/dist/archive.d.ts +163 -0
- package/dist/archive.js +50 -0
- package/dist/archive.js.map +1 -0
- package/dist/bridge-domain-CBX3IVqC.d.ts +153 -0
- package/dist/{bridge-service-CfqMcMAn.d.ts → bridge-service-hX1ZQp4W.d.ts} +15 -5
- package/dist/bridge-store-DPVSCwfs.d.ts +102 -0
- package/dist/bridge.d.ts +76 -17
- package/dist/bridge.js +52 -24
- package/dist/chunk-2DFNOLMO.js +618 -0
- package/dist/chunk-2DFNOLMO.js.map +1 -0
- package/dist/{chunk-KVR4JBRF.js → chunk-2EVLG3YA.js} +2 -2
- package/dist/{chunk-KVR4JBRF.js.map → chunk-2EVLG3YA.js.map} +1 -1
- package/dist/chunk-45BZGB77.js +709 -0
- package/dist/chunk-45BZGB77.js.map +1 -0
- package/dist/chunk-4VB44KJU.js +230 -0
- package/dist/chunk-4VB44KJU.js.map +1 -0
- package/dist/chunk-5GMB3A77.js +1013 -0
- package/dist/chunk-5GMB3A77.js.map +1 -0
- package/dist/chunk-A6W4QALF.js +1258 -0
- package/dist/chunk-A6W4QALF.js.map +1 -0
- package/dist/chunk-BZLMF5O5.js +328 -0
- package/dist/chunk-BZLMF5O5.js.map +1 -0
- package/dist/{chunk-AXL2I7FH.js → chunk-CEXBMOI5.js} +240 -79
- package/dist/chunk-CEXBMOI5.js.map +1 -0
- package/dist/chunk-GADH244D.js +527 -0
- package/dist/chunk-GADH244D.js.map +1 -0
- package/dist/chunk-MBPZXTJA.js +2428 -0
- package/dist/chunk-MBPZXTJA.js.map +1 -0
- package/dist/chunk-NCO7RLBM.js +146 -0
- package/dist/chunk-NCO7RLBM.js.map +1 -0
- package/dist/chunk-Q6PPMXJC.js +1050 -0
- package/dist/chunk-Q6PPMXJC.js.map +1 -0
- package/dist/{chunk-4KAOBC5X.js → chunk-SPSMZOCJ.js} +190 -165
- package/dist/chunk-SPSMZOCJ.js.map +1 -0
- package/dist/chunk-UAHMP6GC.js +54 -0
- package/dist/chunk-UAHMP6GC.js.map +1 -0
- package/dist/{chunk-YD6YJATN.js → chunk-VOQIDTCJ.js} +4 -2
- package/dist/chunk-VOQIDTCJ.js.map +1 -0
- package/dist/chunk-WAI2IYIQ.js +554 -0
- package/dist/chunk-WAI2IYIQ.js.map +1 -0
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +3555 -214
- package/dist/cli.js.map +1 -1
- package/dist/client-config.d.ts +1 -1
- package/dist/client-config.js +1 -1
- package/dist/client-runtime.d.ts +10 -6
- package/dist/client-runtime.js +9 -6
- package/dist/contracts/generate.d.ts +2 -0
- package/dist/contracts/generate.js +247 -0
- package/dist/contracts/generate.js.map +1 -0
- package/dist/dr.d.ts +324 -0
- package/dist/dr.js +124 -0
- package/dist/dr.js.map +1 -0
- package/dist/gateway-CggQ8vTC.d.ts +78 -0
- package/dist/gateway-main.js +190 -8
- package/dist/gateway-main.js.map +1 -1
- package/dist/gateway.d.ts +4 -3
- package/dist/gateway.js +4 -3
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/postgres-bridge-store-Bfd3hRId.d.ts +49 -0
- package/dist/server.d.ts +3 -2
- package/dist/server.js +13 -8
- package/dist/sqlite.d.ts +94 -12
- package/dist/sqlite.js +7 -4
- package/docs/architecture-v2.md +394 -0
- package/docs/decisions/0001-protocol-layers-and-acknowledgment-semantics.md +85 -0
- package/docs/decisions/0002-canonical-operation-contract-registry.md +46 -0
- package/docs/decisions/0003-host-adapters-and-consumer-instance-keys.md +88 -0
- package/docs/ecosystem.md +86 -0
- package/docs/postmortems/2026-07-08-wrapper-source-drift.md +82 -0
- package/docs/troubleshooting.md +89 -0
- package/llms.txt +107 -6
- package/openapi/agent-bridge-v2.openapi.json +9610 -0
- package/package.json +24 -4
- package/schemas/agent-bridge-v2.capabilities.json +1829 -0
- package/schemas/agent-bridge-v2.mcp.json +2074 -0
- package/schemas/agent-bridge-v2.schema.json +4560 -0
- package/sql/migrations/008_message_projects.sql +36 -0
- package/sql/migrations/009_mailbox_query_indexes.sql +28 -0
- package/sql/migrations/010_publisher_delivery_policy.sql +210 -0
- package/sql/migrations/011_credential_security.sql +875 -0
- package/sql/migrations/012_request_authority.sql +177 -0
- package/sql/migrations/013_row_isolation.sql +495 -0
- package/sql/migrations/014_owner_control_plane.sql +1641 -0
- package/sql/migrations/015_portable_archives.sql +1813 -0
- package/sql/migrations/016_native_dr_fence.sql +1005 -0
- package/bin/CLAUDE.md +0 -11
- package/dist/bridge-domain-BcnBeHOn.d.ts +0 -97
- package/dist/bridge-store-BuGjxTn4.d.ts +0 -61
- package/dist/chunk-4KAOBC5X.js.map +0 -1
- package/dist/chunk-6MAZ6YLZ.js +0 -146
- package/dist/chunk-6MAZ6YLZ.js.map +0 -1
- package/dist/chunk-AXL2I7FH.js.map +0 -1
- package/dist/chunk-BV6W4AJK.js +0 -211
- package/dist/chunk-BV6W4AJK.js.map +0 -1
- package/dist/chunk-CKSKUBDQ.js +0 -153
- package/dist/chunk-CKSKUBDQ.js.map +0 -1
- package/dist/chunk-JOUBDRYX.js +0 -272
- package/dist/chunk-JOUBDRYX.js.map +0 -1
- package/dist/chunk-JTC5YURG.js +0 -49
- package/dist/chunk-JTC5YURG.js.map +0 -1
- package/dist/chunk-O26W5QHS.js +0 -409
- package/dist/chunk-O26W5QHS.js.map +0 -1
- package/dist/chunk-WEULPMUY.js +0 -988
- package/dist/chunk-WEULPMUY.js.map +0 -1
- package/dist/chunk-YD6YJATN.js.map +0 -1
- package/dist/gateway-BULozv3K.d.ts +0 -54
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/private-path.ts
|
|
4
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync } from "fs";
|
|
5
|
+
import { dirname, resolve } from "path";
|
|
6
|
+
import { spawnSync } from "child_process";
|
|
7
|
+
var PrivatePathError = class extends Error {
|
|
8
|
+
};
|
|
9
|
+
var defaults = {
|
|
10
|
+
platform: process.platform,
|
|
11
|
+
execute: (command, args, env) => spawnSync(command, args, {
|
|
12
|
+
encoding: "utf8",
|
|
13
|
+
windowsHide: true,
|
|
14
|
+
env
|
|
15
|
+
}),
|
|
16
|
+
inspect: (path) => lstatSync(path)
|
|
17
|
+
};
|
|
18
|
+
function windowsScript(kind, apply) {
|
|
19
|
+
const flags = kind === "directory" ? "[System.Security.AccessControl.InheritanceFlags]'ContainerInherit,ObjectInherit'" : "[System.Security.AccessControl.InheritanceFlags]::None";
|
|
20
|
+
const pathInfo = kind === "directory" ? "[System.IO.DirectoryInfo]::new($p)" : "[System.IO.FileInfo]::new($p)";
|
|
21
|
+
return [
|
|
22
|
+
"$p=$env:AGENT_BRIDGE_PRIVATE_PATH",
|
|
23
|
+
"$identity=[System.Security.Principal.WindowsIdentity]::GetCurrent()",
|
|
24
|
+
"$sid=$identity.User",
|
|
25
|
+
"$tokenOwner=$identity.Owner",
|
|
26
|
+
`$pathInfo=${pathInfo}`,
|
|
27
|
+
"$pathInfo.Refresh()",
|
|
28
|
+
"if(($pathInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0){exit 25}",
|
|
29
|
+
`$flags=${flags}`,
|
|
30
|
+
"$sections=[System.Security.AccessControl.AccessControlSections]([System.Security.AccessControl.AccessControlSections]::Owner -bor [System.Security.AccessControl.AccessControlSections]::Access)",
|
|
31
|
+
"$before=$pathInfo.GetAccessControl($sections)",
|
|
32
|
+
"$beforeOwner=$before.GetOwner([System.Security.Principal.SecurityIdentifier])",
|
|
33
|
+
"$beforeMatchesUser=$false",
|
|
34
|
+
"$beforeMatchesToken=$false",
|
|
35
|
+
"if($null -ne $beforeOwner){$beforeMatchesUser=$beforeOwner.Equals($sid);if($null -ne $tokenOwner){$beforeMatchesToken=$beforeOwner.Equals($tokenOwner)}}",
|
|
36
|
+
'if(-not $beforeMatchesUser -and -not $beforeMatchesToken){Write-Output ("explicit owner present {0}; matches user {1}; matches token {2}" -f ($null -ne $beforeOwner),$beforeMatchesUser,$beforeMatchesToken);exit 24}',
|
|
37
|
+
...apply ? [
|
|
38
|
+
"$acl=$before",
|
|
39
|
+
"$acl.SetAccessRuleProtection($true,$false)",
|
|
40
|
+
"$existingRules=@($acl.GetAccessRules($true,$true,[System.Security.Principal.SecurityIdentifier]))",
|
|
41
|
+
"foreach($existing in $existingRules){$acl.RemoveAccessRuleSpecific($existing)}",
|
|
42
|
+
"$acl.SetOwner($sid)",
|
|
43
|
+
"$rule=New-Object System.Security.AccessControl.FileSystemAccessRule($sid,'FullControl',$flags,[System.Security.AccessControl.PropagationFlags]::None,[System.Security.AccessControl.AccessControlType]::Allow)",
|
|
44
|
+
"$acl.AddAccessRule($rule)",
|
|
45
|
+
"$pathInfo.SetAccessControl($acl)"
|
|
46
|
+
] : [],
|
|
47
|
+
`$checkPathInfo=${pathInfo}`,
|
|
48
|
+
"$checkPathInfo.Refresh()",
|
|
49
|
+
"if(($checkPathInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0){exit 25}",
|
|
50
|
+
"$check=$checkPathInfo.GetAccessControl($sections)",
|
|
51
|
+
"$owner=$check.GetOwner([System.Security.Principal.SecurityIdentifier])",
|
|
52
|
+
"$ownerMatches=$false",
|
|
53
|
+
"if($null -ne $owner){$ownerMatches=$owner.Equals($sid)}",
|
|
54
|
+
"$rules=@($check.GetAccessRules($true,$true,[System.Security.Principal.SecurityIdentifier]))",
|
|
55
|
+
"$ruleMatches=$false",
|
|
56
|
+
"$ruleInherited=$true",
|
|
57
|
+
"$ruleAllow=$false",
|
|
58
|
+
"$rightsExact=$false",
|
|
59
|
+
"$inheritanceExact=$false",
|
|
60
|
+
"$propagationExact=$false",
|
|
61
|
+
"if($rules.Count -eq 1){$ruleSid=$rules[0].IdentityReference.Translate([System.Security.Principal.SecurityIdentifier]);$ruleMatches=$ruleSid.Equals($sid);$ruleInherited=$rules[0].IsInherited;$ruleAllow=$rules[0].AccessControlType -eq [System.Security.AccessControl.AccessControlType]::Allow;$rightsExact=$rules[0].FileSystemRights -eq [System.Security.AccessControl.FileSystemRights]::FullControl;$inheritanceExact=$rules[0].InheritanceFlags -eq $flags;$propagationExact=$rules[0].PropagationFlags -eq [System.Security.AccessControl.PropagationFlags]::None}",
|
|
62
|
+
'if(-not $ownerMatches -or -not $check.AreAccessRulesProtected -or $rules.Count -ne 1 -or -not $ruleMatches -or $ruleInherited -or -not $ruleAllow -or -not $rightsExact -or -not $inheritanceExact -or -not $propagationExact){Write-Output ("final owner {0}; protected {1}; rules {2}; sid {3}; inherited {4}; allow {5}; rights {6}; inheritance {7}; propagation {8}" -f $ownerMatches,$check.AreAccessRulesProtected,$rules.Count,$ruleMatches,$ruleInherited,$ruleAllow,$rightsExact,$inheritanceExact,$propagationExact);exit 23}'
|
|
63
|
+
].join(";");
|
|
64
|
+
}
|
|
65
|
+
function windowsPrivatePath(path, kind, apply, dependencies) {
|
|
66
|
+
const before = dependencies.inspect(path);
|
|
67
|
+
if (before.isSymbolicLink() || (kind === "file" ? !before.isFile() : !before.isDirectory())) {
|
|
68
|
+
throw new PrivatePathError("private Windows paths cannot be symlinks, junctions, or reparse objects");
|
|
69
|
+
}
|
|
70
|
+
const result = dependencies.execute("powershell.exe", [
|
|
71
|
+
"-NoProfile",
|
|
72
|
+
"-NonInteractive",
|
|
73
|
+
"-Command",
|
|
74
|
+
windowsScript(kind, apply)
|
|
75
|
+
], { ...process.env, AGENT_BRIDGE_PRIVATE_PATH: path });
|
|
76
|
+
if (result.status !== 0) {
|
|
77
|
+
const phase = result.status === 23 ? `final ACL verification failed${result.stdout.trim() ? ` (${result.stdout.trim()})` : ""}` : result.status === 24 ? `the existing owner is not trusted${result.stdout.trim() ? ` (${result.stdout.trim()})` : ""}` : result.status === 25 ? "the path is a reparse object" : "the native ACL command failed";
|
|
78
|
+
throw new PrivatePathError(`${apply ? "cannot apply" : "path does not satisfy"} the current-user private path policy: ${phase}`);
|
|
79
|
+
}
|
|
80
|
+
const after = dependencies.inspect(path);
|
|
81
|
+
if (after.isSymbolicLink() || (kind === "file" ? !after.isFile() : !after.isDirectory()) || after.dev !== before.dev || after.ino !== before.ino) {
|
|
82
|
+
throw new PrivatePathError("private Windows path identity changed during policy validation");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function posixPrivatePath(path, kind, apply) {
|
|
86
|
+
const details = lstatSync(path);
|
|
87
|
+
if (details.isSymbolicLink() || (kind === "file" ? !details.isFile() : !details.isDirectory())) {
|
|
88
|
+
throw new PrivatePathError("private path has the wrong file type");
|
|
89
|
+
}
|
|
90
|
+
if (typeof process.getuid === "function" && details.uid !== process.getuid()) {
|
|
91
|
+
throw new PrivatePathError("private path must be owned by the current user");
|
|
92
|
+
}
|
|
93
|
+
const mode = kind === "file" ? 384 : 448;
|
|
94
|
+
if (apply) chmodSync(path, mode);
|
|
95
|
+
const secured = lstatSync(path);
|
|
96
|
+
if ((secured.mode & 511) !== mode) {
|
|
97
|
+
throw new PrivatePathError("private path permissions are not owner-only");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function securePrivatePath(path, kind, dependencies = defaults) {
|
|
101
|
+
if (dependencies.platform === "win32") windowsPrivatePath(path, kind, true, dependencies);
|
|
102
|
+
else posixPrivatePath(path, kind, true);
|
|
103
|
+
}
|
|
104
|
+
function verifyPrivatePathAccess(path, kind, dependencies = defaults) {
|
|
105
|
+
if (dependencies.platform === "win32") windowsPrivatePath(path, kind, false, dependencies);
|
|
106
|
+
else posixPrivatePath(path, kind, false);
|
|
107
|
+
}
|
|
108
|
+
function preparePrivateFileLocation(path, createParent = false) {
|
|
109
|
+
const target = resolve(path);
|
|
110
|
+
const parent = dirname(target);
|
|
111
|
+
const parentExisted = existsSync(parent);
|
|
112
|
+
if (createParent && !parentExisted) mkdirSync(parent, { recursive: true, mode: 448 });
|
|
113
|
+
if (!existsSync(parent)) throw new PrivatePathError("private path parent does not exist");
|
|
114
|
+
if (!parentExisted) securePrivatePath(parent, "directory");
|
|
115
|
+
verifyPrivatePathAccess(parent, "directory");
|
|
116
|
+
if (existsSync(target)) verifyPrivatePathAccess(target, "file");
|
|
117
|
+
return target;
|
|
118
|
+
}
|
|
119
|
+
function securePrivateSqliteFiles(path) {
|
|
120
|
+
if (path === ":memory:") return;
|
|
121
|
+
const target = resolve(path);
|
|
122
|
+
verifyPrivatePathAccess(dirname(target), "directory");
|
|
123
|
+
for (const candidate of [target, `${target}-wal`, `${target}-shm`]) {
|
|
124
|
+
if (!existsSync(candidate)) continue;
|
|
125
|
+
securePrivatePath(candidate, "file");
|
|
126
|
+
verifyPrivatePathAccess(candidate, "file");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function preparePrivateSqliteLocation(path, createParent = false) {
|
|
130
|
+
if (path === ":memory:") return path;
|
|
131
|
+
const target = preparePrivateFileLocation(path, createParent);
|
|
132
|
+
for (const candidate of [`${target}-wal`, `${target}-shm`]) {
|
|
133
|
+
if (existsSync(candidate)) securePrivatePath(candidate, "file");
|
|
134
|
+
}
|
|
135
|
+
return target;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export {
|
|
139
|
+
PrivatePathError,
|
|
140
|
+
securePrivatePath,
|
|
141
|
+
verifyPrivatePathAccess,
|
|
142
|
+
preparePrivateFileLocation,
|
|
143
|
+
securePrivateSqliteFiles,
|
|
144
|
+
preparePrivateSqliteLocation
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=chunk-NCO7RLBM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/private-path.ts"],"sourcesContent":["import { chmodSync, existsSync, lstatSync, mkdirSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { spawnSync, type SpawnSyncReturns } from \"node:child_process\";\n\nexport type PrivatePathKind = \"file\" | \"directory\";\n\nexport class PrivatePathError extends Error {}\n\ninterface PrivatePathDependencies {\n platform: NodeJS.Platform;\n execute(command: string, args: string[], env: NodeJS.ProcessEnv): SpawnSyncReturns<string>;\n inspect(path: string): {\n dev: number;\n ino: number;\n isSymbolicLink(): boolean;\n isFile(): boolean;\n isDirectory(): boolean;\n };\n}\n\nconst defaults: PrivatePathDependencies = {\n platform: process.platform,\n execute: (command, args, env) => spawnSync(command, args, {\n encoding: \"utf8\",\n windowsHide: true,\n env,\n }),\n inspect: (path) => lstatSync(path),\n};\n\nfunction windowsScript(kind: PrivatePathKind, apply: boolean): string {\n const flags = kind === \"directory\"\n ? \"[System.Security.AccessControl.InheritanceFlags]'ContainerInherit,ObjectInherit'\"\n : \"[System.Security.AccessControl.InheritanceFlags]::None\";\n const pathInfo = kind === \"directory\"\n ? \"[System.IO.DirectoryInfo]::new($p)\"\n : \"[System.IO.FileInfo]::new($p)\";\n return [\n \"$p=$env:AGENT_BRIDGE_PRIVATE_PATH\",\n \"$identity=[System.Security.Principal.WindowsIdentity]::GetCurrent()\",\n \"$sid=$identity.User\",\n \"$tokenOwner=$identity.Owner\",\n `$pathInfo=${pathInfo}`,\n \"$pathInfo.Refresh()\",\n \"if(($pathInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0){exit 25}\",\n `$flags=${flags}`,\n \"$sections=[System.Security.AccessControl.AccessControlSections]([System.Security.AccessControl.AccessControlSections]::Owner -bor [System.Security.AccessControl.AccessControlSections]::Access)\",\n \"$before=$pathInfo.GetAccessControl($sections)\",\n \"$beforeOwner=$before.GetOwner([System.Security.Principal.SecurityIdentifier])\",\n \"$beforeMatchesUser=$false\",\n \"$beforeMatchesToken=$false\",\n \"if($null -ne $beforeOwner){$beforeMatchesUser=$beforeOwner.Equals($sid);if($null -ne $tokenOwner){$beforeMatchesToken=$beforeOwner.Equals($tokenOwner)}}\",\n \"if(-not $beforeMatchesUser -and -not $beforeMatchesToken){Write-Output (\\\"explicit owner present {0}; matches user {1}; matches token {2}\\\" -f ($null -ne $beforeOwner),$beforeMatchesUser,$beforeMatchesToken);exit 24}\",\n ...(apply ? [\n \"$acl=$before\",\n \"$acl.SetAccessRuleProtection($true,$false)\",\n \"$existingRules=@($acl.GetAccessRules($true,$true,[System.Security.Principal.SecurityIdentifier]))\",\n \"foreach($existing in $existingRules){$acl.RemoveAccessRuleSpecific($existing)}\",\n \"$acl.SetOwner($sid)\",\n \"$rule=New-Object System.Security.AccessControl.FileSystemAccessRule($sid,'FullControl',$flags,[System.Security.AccessControl.PropagationFlags]::None,[System.Security.AccessControl.AccessControlType]::Allow)\",\n \"$acl.AddAccessRule($rule)\",\n \"$pathInfo.SetAccessControl($acl)\",\n ] : []),\n `$checkPathInfo=${pathInfo}`,\n \"$checkPathInfo.Refresh()\",\n \"if(($checkPathInfo.Attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0){exit 25}\",\n \"$check=$checkPathInfo.GetAccessControl($sections)\",\n \"$owner=$check.GetOwner([System.Security.Principal.SecurityIdentifier])\",\n \"$ownerMatches=$false\",\n \"if($null -ne $owner){$ownerMatches=$owner.Equals($sid)}\",\n \"$rules=@($check.GetAccessRules($true,$true,[System.Security.Principal.SecurityIdentifier]))\",\n \"$ruleMatches=$false\",\n \"$ruleInherited=$true\",\n \"$ruleAllow=$false\",\n \"$rightsExact=$false\",\n \"$inheritanceExact=$false\",\n \"$propagationExact=$false\",\n \"if($rules.Count -eq 1){$ruleSid=$rules[0].IdentityReference.Translate([System.Security.Principal.SecurityIdentifier]);$ruleMatches=$ruleSid.Equals($sid);$ruleInherited=$rules[0].IsInherited;$ruleAllow=$rules[0].AccessControlType -eq [System.Security.AccessControl.AccessControlType]::Allow;$rightsExact=$rules[0].FileSystemRights -eq [System.Security.AccessControl.FileSystemRights]::FullControl;$inheritanceExact=$rules[0].InheritanceFlags -eq $flags;$propagationExact=$rules[0].PropagationFlags -eq [System.Security.AccessControl.PropagationFlags]::None}\",\n \"if(-not $ownerMatches -or -not $check.AreAccessRulesProtected -or $rules.Count -ne 1 -or -not $ruleMatches -or $ruleInherited -or -not $ruleAllow -or -not $rightsExact -or -not $inheritanceExact -or -not $propagationExact){Write-Output (\\\"final owner {0}; protected {1}; rules {2}; sid {3}; inherited {4}; allow {5}; rights {6}; inheritance {7}; propagation {8}\\\" -f $ownerMatches,$check.AreAccessRulesProtected,$rules.Count,$ruleMatches,$ruleInherited,$ruleAllow,$rightsExact,$inheritanceExact,$propagationExact);exit 23}\",\n ].join(\";\");\n}\n\nfunction windowsPrivatePath(\n path: string,\n kind: PrivatePathKind,\n apply: boolean,\n dependencies: PrivatePathDependencies,\n): void {\n const before = dependencies.inspect(path);\n if (before.isSymbolicLink()\n || (kind === \"file\" ? !before.isFile() : !before.isDirectory())) {\n throw new PrivatePathError(\"private Windows paths cannot be symlinks, junctions, or reparse objects\");\n }\n const result = dependencies.execute(\"powershell.exe\", [\n \"-NoProfile\", \"-NonInteractive\", \"-Command\", windowsScript(kind, apply),\n ], { ...process.env, AGENT_BRIDGE_PRIVATE_PATH: path });\n if (result.status !== 0) {\n const phase = result.status === 23\n ? `final ACL verification failed${result.stdout.trim() ? ` (${result.stdout.trim()})` : \"\"}`\n : result.status === 24\n ? `the existing owner is not trusted${result.stdout.trim() ? ` (${result.stdout.trim()})` : \"\"}`\n : result.status === 25\n ? \"the path is a reparse object\"\n : \"the native ACL command failed\";\n throw new PrivatePathError(`${apply\n ? \"cannot apply\"\n : \"path does not satisfy\"} the current-user private path policy: ${phase}`);\n }\n const after = dependencies.inspect(path);\n if (after.isSymbolicLink()\n || (kind === \"file\" ? !after.isFile() : !after.isDirectory())\n || after.dev !== before.dev || after.ino !== before.ino) {\n throw new PrivatePathError(\"private Windows path identity changed during policy validation\");\n }\n}\n\nfunction posixPrivatePath(path: string, kind: PrivatePathKind, apply: boolean): void {\n const details = lstatSync(path);\n if (details.isSymbolicLink()\n || (kind === \"file\" ? !details.isFile() : !details.isDirectory())) {\n throw new PrivatePathError(\"private path has the wrong file type\");\n }\n if (typeof process.getuid === \"function\" && details.uid !== process.getuid()) {\n throw new PrivatePathError(\"private path must be owned by the current user\");\n }\n const mode = kind === \"file\" ? 0o600 : 0o700;\n if (apply) chmodSync(path, mode);\n const secured = lstatSync(path);\n if ((secured.mode & 0o777) !== mode) {\n throw new PrivatePathError(\"private path permissions are not owner-only\");\n }\n}\n\nexport function securePrivatePath(\n path: string,\n kind: PrivatePathKind,\n dependencies: PrivatePathDependencies = defaults,\n): void {\n if (dependencies.platform === \"win32\") windowsPrivatePath(path, kind, true, dependencies);\n else posixPrivatePath(path, kind, true);\n}\n\nexport function verifyPrivatePathAccess(\n path: string,\n kind: PrivatePathKind,\n dependencies: PrivatePathDependencies = defaults,\n): void {\n if (dependencies.platform === \"win32\") windowsPrivatePath(path, kind, false, dependencies);\n else posixPrivatePath(path, kind, false);\n}\n\n/** Prepare an immediate parent and reject link-like file locations before use. */\nexport function preparePrivateFileLocation(path: string, createParent = false): string {\n const target = resolve(path);\n const parent = dirname(target);\n const parentExisted = existsSync(parent);\n if (createParent && !parentExisted) mkdirSync(parent, { recursive: true, mode: 0o700 });\n if (!existsSync(parent)) throw new PrivatePathError(\"private path parent does not exist\");\n if (!parentExisted) securePrivatePath(parent, \"directory\");\n verifyPrivatePathAccess(parent, \"directory\");\n if (existsSync(target)) verifyPrivatePathAccess(target, \"file\");\n return target;\n}\n\n/** Apply and verify owner-only policy for a SQLite database and live sidecars. */\nexport function securePrivateSqliteFiles(path: string): void {\n if (path === \":memory:\") return;\n const target = resolve(path);\n verifyPrivatePathAccess(dirname(target), \"directory\");\n for (const candidate of [target, `${target}-wal`, `${target}-shm`]) {\n if (!existsSync(candidate)) continue;\n securePrivatePath(candidate, \"file\");\n verifyPrivatePathAccess(candidate, \"file\");\n }\n}\n\nexport function preparePrivateSqliteLocation(path: string, createParent = false): string {\n if (path === \":memory:\") return path;\n const target = preparePrivateFileLocation(path, createParent);\n for (const candidate of [`${target}-wal`, `${target}-shm`]) {\n if (existsSync(candidate)) securePrivatePath(candidate, \"file\");\n }\n return target;\n}\n"],"mappings":";;;AAAA,SAAS,WAAW,YAAY,WAAW,iBAAiB;AAC5D,SAAS,SAAS,eAAe;AACjC,SAAS,iBAAwC;AAI1C,IAAM,mBAAN,cAA+B,MAAM;AAAC;AAc7C,IAAM,WAAoC;AAAA,EACxC,UAAU,QAAQ;AAAA,EAClB,SAAS,CAAC,SAAS,MAAM,QAAQ,UAAU,SAAS,MAAM;AAAA,IACxD,UAAU;AAAA,IACV,aAAa;AAAA,IACb;AAAA,EACF,CAAC;AAAA,EACD,SAAS,CAAC,SAAS,UAAU,IAAI;AACnC;AAEA,SAAS,cAAc,MAAuB,OAAwB;AACpE,QAAM,QAAQ,SAAS,cACnB,qFACA;AACJ,QAAM,WAAW,SAAS,cACtB,uCACA;AACJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,QAAQ;AAAA,IACrB;AAAA,IACA;AAAA,IACA,UAAU,KAAK;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,QAAQ;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI,CAAC;AAAA,IACL,kBAAkB,QAAQ;AAAA,IAC1B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EAAE,KAAK,GAAG;AACZ;AAEA,SAAS,mBACP,MACA,MACA,OACA,cACM;AACN,QAAM,SAAS,aAAa,QAAQ,I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