omowright 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +290 -2
  3. package/TOOLS.md +487 -0
  4. package/bin/omowright-cloak.mjs +112 -0
  5. package/package.json +57 -4
  6. package/presets/agent-events/SKILL.md +75 -0
  7. package/presets/captcha/SKILL.md +129 -0
  8. package/presets/chrome/SKILL.md +88 -0
  9. package/presets/cloak-bridge/SKILL.md +43 -0
  10. package/presets/network/SKILL.md +126 -0
  11. package/presets/visual-browse/SKILL.md +103 -0
  12. package/skills/omowright/SKILL.md +193 -0
  13. package/skills/omowright/references/1password.md +118 -0
  14. package/skills/omowright/references/browserskill.md +195 -0
  15. package/skills/omowright/references/eval-kernel.md +100 -0
  16. package/skills/omowright/references/frames-layers-human.md +123 -0
  17. package/skills/omowright/references/quickstart.md +109 -0
  18. package/skills/omowright/references/stealth.md +174 -0
  19. package/src/agent-tabs.js +179 -0
  20. package/src/aria-hidden.js +47 -0
  21. package/src/bridge-schemas.js +44 -0
  22. package/src/bridge-transport.js +83 -0
  23. package/src/browser-context.js +105 -0
  24. package/src/browser-process.js +127 -0
  25. package/src/bsk/browser-signals.js +90 -0
  26. package/src/bsk/browsers.js +114 -0
  27. package/src/bsk/connect.js +75 -0
  28. package/src/bsk/daemon-info.js +100 -0
  29. package/src/bsk/external-extension.js +110 -0
  30. package/src/bsk/identify-browser.js +88 -0
  31. package/src/bsk/install-cli.js +81 -0
  32. package/src/bsk/ipc-client.js +236 -0
  33. package/src/bsk/onboard.js +140 -0
  34. package/src/bsk/screenshot.js +49 -0
  35. package/src/bsk/session.js +131 -0
  36. package/src/bsk/snapshot.js +56 -0
  37. package/src/bsk/targets.js +25 -0
  38. package/src/captcha-wait.js +79 -0
  39. package/src/captcha.js +142 -0
  40. package/src/cdp-errors.js +23 -0
  41. package/src/cdp-methods.js +69 -0
  42. package/src/chrome-profile.js +176 -0
  43. package/src/chrome.js +194 -0
  44. package/src/cloak-profile.js +266 -0
  45. package/src/connection.js +234 -0
  46. package/src/console-events.js +12 -0
  47. package/src/cookies.js +39 -0
  48. package/src/core.js +1702 -0
  49. package/src/cua.js +74 -0
  50. package/src/dialog-policy.js +80 -0
  51. package/src/emulate.js +127 -0
  52. package/src/events.js +111 -0
  53. package/src/frames-snapshot.js +138 -0
  54. package/src/har.js +103 -0
  55. package/src/human-handoff.js +124 -0
  56. package/src/index.js +89 -0
  57. package/src/injected.js +3 -0
  58. package/src/instance-lock.js +74 -0
  59. package/src/instances.js +490 -0
  60. package/src/internal-capability.js +1 -0
  61. package/src/launch-endpoint.js +185 -0
  62. package/src/layers.js +138 -0
  63. package/src/llm.js +201 -0
  64. package/src/lock-backend-win32.js +54 -0
  65. package/src/lock-backend.js +81 -0
  66. package/src/native-host-win32.js +201 -0
  67. package/src/network-events.js +223 -0
  68. package/src/network-snoop.js +229 -0
  69. package/src/nul-frames.js +28 -0
  70. package/src/open-shadow-query.js +101 -0
  71. package/src/owner-only.js +196 -0
  72. package/src/page-bundle.js +1478 -0
  73. package/src/page-events.js +45 -0
  74. package/src/page-routes.js +94 -0
  75. package/src/page-setup.js +239 -0
  76. package/src/pipe.js +418 -0
  77. package/src/process-start-time.js +64 -0
  78. package/src/routes.js +256 -0
  79. package/src/running-browser.js +85 -0
  80. package/src/scroll-collect.js +73 -0
  81. package/src/serial-emitter.js +17 -0
  82. package/src/shared-connections.js +285 -0
  83. package/src/snapshot-diff.js +75 -0
  84. package/src/text-matching.js +101 -0
  85. package/src/trace.js +183 -0
  86. package/src/url-match.js +148 -0
  87. package/src/viewport.js +12 -0
@@ -0,0 +1,101 @@
1
+ // Self-contained because locator queries serialize this into the frame's page or isolated world.
2
+ // Order matches the CSS locator traversal: the scope's own matches, then each open shadow root below
3
+ // it, depth first in document order, nested roots included. Closed roots stay excluded.
4
+ // A selector with combinators also matches across open shadow boundaries (a host is the parent of its
5
+ // shadow root's top-level children), but matching never climbs above the scope, and an element scope
6
+ // anchors the selector to itself: `:scope` and leading compounds resolve inside it, not against its ancestors.
7
+ export function queryOpenShadowAll(root, selector) {
8
+ const groups = [];
9
+ let parts = [], token = "", depth = 0, quote = "", escaped = false, combinator = " ";
10
+ const flush = () => {
11
+ if (!token.trim()) return;
12
+ parts.push({ selector: token.trim(), combinator });
13
+ token = "";
14
+ combinator = " ";
15
+ };
16
+ for (const char of selector) {
17
+ if (escaped) { token += char; escaped = false; continue; }
18
+ if (char === "\\") { token += char; escaped = true; continue; }
19
+ if (quote) { token += char; if (char === quote) quote = ""; continue; }
20
+ if (char === '"' || char === "'") { quote = char; token += char; continue; }
21
+ if (char === "[" || char === "(") depth++;
22
+ if (char === "]" || char === ")") depth--;
23
+ if (!depth && (char === "," || char === ">" || char === "+" || char === "~" || /\s/.test(char))) {
24
+ flush();
25
+ if (char === ",") { groups.push(parts); parts = []; combinator = " "; }
26
+ else if (!/\s/.test(char)) combinator = char;
27
+ } else token += char;
28
+ }
29
+ flush();
30
+ groups.push(parts);
31
+ // One compound per group matches the same nodes in every tree scope, so each scope stays a native query.
32
+ const simple = groups.every(parts => parts.length === 1 && !/^:scope\b/.test(parts[0].selector));
33
+ let rootSelector = selector;
34
+ if (!simple && root instanceof Element) {
35
+ const scopedSelectors = [];
36
+ for (const parts of groups) {
37
+ const first = parts[0].selector;
38
+ const rest = parts.slice(1).map(part => `${part.combinator} ${part.selector}`).join(" ");
39
+ const scoped = /^:scope\b/.test(first);
40
+ scopedSelectors.push(`${scoped ? "" : ":scope "}${first} ${rest}`);
41
+ if (!scoped && parts.length > 1 && root.matches(first)) scopedSelectors.push(`:scope ${rest}`);
42
+ }
43
+ rootSelector = scopedSelectors.join(", ");
44
+ }
45
+ const rootElements = root.querySelectorAll("*");
46
+ const rootMatches = rootSelector === "*" ? rootElements : root.querySelectorAll(rootSelector);
47
+ // A stack of open roots, popped depth first; the scope's own shadow root comes first.
48
+ const pending = [];
49
+ for (let index = rootElements.length - 1; index >= 0; index--) {
50
+ if (rootElements[index].shadowRoot) pending.push(rootElements[index].shadowRoot);
51
+ }
52
+ if (root instanceof Element && root.shadowRoot) pending.push(root.shadowRoot);
53
+ if (pending.length === 0) return Array.from(rootMatches);
54
+ const results = [];
55
+ // Index loops, never spread: a scope can hold more nodes than the engine's argument limit.
56
+ for (let index = 0; index < rootMatches.length; index++) results.push(rootMatches[index]);
57
+ const parent = node => node.parentElement ?? node.getRootNode().host ?? null;
58
+ const scope = root instanceof Element ? root : root.documentElement;
59
+ const matches = (node, parts, index) => {
60
+ if (node === root && index > 0) return false;
61
+ const part = parts[index];
62
+ const scoped = /^:scope\b/.test(part.selector);
63
+ const compound = scoped ? part.selector.replace(/^:scope\b/, "*") : part.selector;
64
+ if (scoped && node !== scope) return false;
65
+ if (!node.matches(compound)) return false;
66
+ if (index === 0) return true;
67
+ if (part.combinator === ">") {
68
+ const ancestor = parent(node);
69
+ return !!ancestor && matches(ancestor, parts, index - 1);
70
+ }
71
+ if (part.combinator === "+") return !!node.previousElementSibling && matches(node.previousElementSibling, parts, index - 1);
72
+ if (part.combinator === "~") {
73
+ for (let sibling = node.previousElementSibling; sibling; sibling = sibling.previousElementSibling) {
74
+ if (matches(sibling, parts, index - 1)) return true;
75
+ }
76
+ return false;
77
+ }
78
+ for (let ancestor = parent(node); ancestor; ancestor = parent(ancestor)) {
79
+ if (matches(ancestor, parts, index - 1)) return true;
80
+ if (ancestor === root) break;
81
+ }
82
+ return false;
83
+ };
84
+ while (pending.length) {
85
+ const shadow = pending.pop();
86
+ const elements = shadow.querySelectorAll("*");
87
+ for (let index = elements.length - 1; index >= 0; index--) {
88
+ if (elements[index].shadowRoot) pending.push(elements[index].shadowRoot);
89
+ }
90
+ if (simple) {
91
+ const found = selector === "*" ? elements : shadow.querySelectorAll(selector);
92
+ for (let index = 0; index < found.length; index++) results.push(found[index]);
93
+ continue;
94
+ }
95
+ for (let index = 0; index < elements.length; index++) {
96
+ const node = elements[index];
97
+ if (groups.some(parts => matches(node, parts, parts.length - 1))) results.push(node);
98
+ }
99
+ }
100
+ return results;
101
+ }
@@ -0,0 +1,196 @@
1
+ // Owner-only access for the registry, lock and CloakBrowser profile state.
2
+ // POSIX expresses it with mode bits. On Windows chmod only toggles the
3
+ // read-only attribute, so the same property is a protected DACL that grants the
4
+ // current user alone: inherited entries (the parent's grants to other users or
5
+ // groups) are dropped, and files created inside a directory inherit its grant.
6
+ // A directory keeps its explicit entries for Windows' root equivalents (SYSTEM,
7
+ // Administrators, TrustedInstaller) and for OWNER RIGHTS and CREATOR OWNER; an
8
+ // explicit grant to anyone else is removed.
9
+ // The Windows tools are spawned by absolute path: a bare name is resolved from
10
+ // the process cwd before PATH, and a cwd another user can write would let them
11
+ // substitute the tool. Any failure throws, so a caller never goes on with the
12
+ // inherited ACL in place. A volume without ACLs (FAT32, exFAT, some network
13
+ // shares) cannot hold the grant, so icacls fails there and so does the caller.
14
+ import { execFile } from "node:child_process";
15
+ import { chmod, mkdtemp, readFile, rm, stat } from "node:fs/promises";
16
+ import { tmpdir } from "node:os";
17
+ import path from "node:path";
18
+ import { promisify } from "node:util";
19
+
20
+ const execFileAsync = promisify(execFile);
21
+ const WINDOWS_COMMAND_TIMEOUT_MS = 15_000;
22
+ // Directories this process restricted or found restricted, by volume and file
23
+ // id rather than by name: a directory that later takes a restricted one's name
24
+ // never got the grant, and on a case-sensitive NTFS directory two names that
25
+ // differ only in case are two directories.
26
+ const ownerOnlyDirectories = new Set();
27
+ // SDDL trustees that may hold allow entries on an owner-only directory besides
28
+ // the user: SYSTEM, Administrators and TrustedInstaller (the trusted set of
29
+ // src/native-host-win32.js), OWNER RIGHTS (the owner, the user) and CREATOR
30
+ // OWNER (whoever creates a child, on that child). SDDL writes well-known SIDs
31
+ // as aliases; their numeric forms are listed too.
32
+ const TRUSTED_TRUSTEES = new Set([
33
+ "SY", "S-1-5-18",
34
+ "BA", "S-1-5-32-544",
35
+ "S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464",
36
+ "OW", "S-1-3-4",
37
+ "CO", "S-1-3-0",
38
+ ]);
39
+ const DENY_ACE_TYPES = new Set(["D", "OD", "XD"]);
40
+ let currentUserSid;
41
+
42
+ export function windowsSystemTool(name, env = process.env) {
43
+ return path.win32.join(env.SystemRoot || env.windir || "C:\\Windows", "System32", name);
44
+ }
45
+
46
+ async function readCurrentUserSid(run) {
47
+ const { stdout } = await run(windowsSystemTool("whoami.exe"), ["/user", "/fo", "csv", "/nh"], {
48
+ timeout: WINDOWS_COMMAND_TIMEOUT_MS,
49
+ windowsHide: true,
50
+ });
51
+ const sid = /"(S-1-[\d-]+)"\s*$/.exec(String(stdout).trim())?.[1];
52
+ if (!sid) throw new Error(`cannot read the current user's SID from whoami: ${String(stdout).trim()}`);
53
+ return sid;
54
+ }
55
+
56
+ function cachedCurrentUserSid() {
57
+ currentUserSid ??= readCurrentUserSid(execFileAsync).catch((error) => {
58
+ currentUserSid = undefined;
59
+ throw error;
60
+ });
61
+ return currentUserSid;
62
+ }
63
+
64
+ // The directory's DACL as SDDL. `icacls /save` without /T reads this one
65
+ // object only and writes it, as UTF-16, to a file.
66
+ async function readDirectoryDacl(dir, run) {
67
+ const scratch = await mkdtemp(path.join(tmpdir(), "omowright-acl-"));
68
+ try {
69
+ const saved = path.join(scratch, "acl");
70
+ await run(windowsSystemTool("icacls.exe"), [dir, "/save", saved, "/Q"], {
71
+ timeout: WINDOWS_COMMAND_TIMEOUT_MS,
72
+ windowsHide: true,
73
+ });
74
+ const bytes = await readFile(saved);
75
+ const text = bytes.length > 1 && bytes[1] === 0 ? bytes.toString("utf16le") : bytes.toString("utf8");
76
+ return /D:[^\r\n]*/.exec(text)?.[0] ?? "";
77
+ } finally {
78
+ await rm(scratch, { recursive: true, force: true });
79
+ }
80
+ }
81
+
82
+ // The flags and ACE fields of an SDDL DACL (`D:` flags, then parenthesized
83
+ // ACEs, up to the SACL `S:` that may follow), or null when it does not parse,
84
+ // as for `D:NO_ACCESS_CONTROL`. A conditional ACE nests parentheses and may
85
+ // quote strings, so ACEs are split at depth zero, skipping quoted text.
86
+ function parseDacl(dacl) {
87
+ const head = /^D:([A-Z]*)/.exec(dacl);
88
+ if (!head) return null;
89
+ const aces = [];
90
+ let depth = 0;
91
+ let start = 0;
92
+ let i = head[0].length;
93
+ for (; i < dacl.length; i++) {
94
+ const c = dacl[i];
95
+ if (c === '"' && depth > 0) {
96
+ i = dacl.indexOf('"', i + 1);
97
+ if (i === -1) return null;
98
+ } else if (c === "(") {
99
+ if (depth++ === 0) start = i + 1;
100
+ } else if (c === ")") {
101
+ if (depth === 0) return null;
102
+ if (--depth === 0) aces.push(dacl.slice(start, i).split(";"));
103
+ } else if (depth === 0) {
104
+ break;
105
+ }
106
+ }
107
+ if (depth !== 0 || (i < dacl.length && !dacl.startsWith("S:", i))) return null;
108
+ return { flags: head[1], aces };
109
+ }
110
+
111
+ // Reads a directory DACL against the grant below. `ownerOnly`: already what
112
+ // the grant leaves, protected, with the user's one entry being the inheritable
113
+ // full-control allow and no allow entry for a trustee outside the trusted set.
114
+ // `foreign`: the trustees outside it with explicit allow entries, which the
115
+ // grant removes (it drops inherited entries itself). Deny entries grant nothing
116
+ // and stay. `parsed` is false for a DACL that could not be read, whose entries
117
+ // are unknown. SDDL names the built-in Administrator and Guest accounts LA and LG.
118
+ function inspectDirectoryDacl(text, sid) {
119
+ const dacl = parseDacl(text);
120
+ if (!dacl) return { parsed: false, ownerOnly: false, foreign: [] };
121
+ const isUser = (trustee) =>
122
+ trustee === sid || (trustee === "LA" && sid.endsWith("-500")) || (trustee === "LG" && sid.endsWith("-501"));
123
+ const own = dacl.aces.filter((fields) => isUser(fields[5]));
124
+ const others = dacl.aces.filter(([type, , , , , trustee]) => !isUser(trustee) && !TRUSTED_TRUSTEES.has(trustee) && !DENY_ACE_TYPES.has(type));
125
+ return {
126
+ parsed: true,
127
+ ownerOnly: dacl.flags.includes("P") && others.length === 0 &&
128
+ own.length === 1 && own[0][0] === "A" && own[0][1] === "OICI" && own[0][2] === "FA",
129
+ foreign: [...new Set(others.filter(([, flags]) => !flags.includes("ID")).map(([, , , , , trustee]) => trustee))],
130
+ };
131
+ }
132
+
133
+ // The memo key: volume, file id and creation time. The 64-bit id Node reports
134
+ // can name a later directory too (ReFS ids are 128-bit, and a file system may
135
+ // reuse a deleted directory's id); the creation time tells them apart. A file
136
+ // system that reports no file id gives none, and its directories are not
137
+ // remembered.
138
+ async function directoryIdentity(dir) {
139
+ const { dev, ino, birthtimeNs } = await stat(dir, { bigint: true });
140
+ return ino === 0n ? null : `${dev}:${ino}:${birthtimeNs}`;
141
+ }
142
+
143
+ // The memo only spares later tool runs, so a directory whose identity cannot
144
+ // be read is not remembered and files created in it get their own grant.
145
+ async function rememberOwnerOnlyDirectory(dir) {
146
+ const identity = await directoryIdentity(dir).catch(() => null);
147
+ if (identity) ownerOnlyDirectories.add(identity);
148
+ }
149
+
150
+ // `platform` and `run` let the security contract above (absolute tool paths,
151
+ // fail closed) be tested off Windows; production callers pass neither.
152
+ export async function restrictToOwner(target, kind, { platform = process.platform, run } = {}) {
153
+ if (platform !== "win32") {
154
+ await chmod(target, kind === "directory" ? 0o700 : 0o600);
155
+ return;
156
+ }
157
+ const command = run ?? execFileAsync;
158
+ const sid = run ? await readCurrentUserSid(run) : await cachedCurrentUserSid();
159
+ // Re-granting an inheritable entry makes Windows rewrite the inherited
160
+ // entries of everything below the directory, thousands of files in a used
161
+ // browser profile, so a directory that already holds the grant is left as is.
162
+ const dacl = kind === "directory" ? inspectDirectoryDacl(await readDirectoryDacl(target, command), sid) : null;
163
+ if (dacl?.ownerOnly) {
164
+ await rememberOwnerOnlyDirectory(target);
165
+ return;
166
+ }
167
+ const grant = kind === "directory" ? `*${sid}:(OI)(CI)F` : `*${sid}:F`;
168
+ await command(windowsSystemTool("icacls.exe"), [target, "/inheritance:r", "/grant:r", grant, "/Q"], {
169
+ timeout: WINDOWS_COMMAND_TIMEOUT_MS,
170
+ windowsHide: true,
171
+ });
172
+ if (!dacl) return;
173
+ // The grant keeps explicit entries; another trustee's is removed by SID (an
174
+ // SDDL alias such as WD is a SID string icacls accepts after `*`).
175
+ if (dacl.foreign.length > 0) {
176
+ await command(windowsSystemTool("icacls.exe"), [target, "/remove:g", ...dacl.foreign.map((trustee) => `*${trustee}`), "/Q"], {
177
+ timeout: WINDOWS_COMMAND_TIMEOUT_MS,
178
+ windowsHide: true,
179
+ });
180
+ }
181
+ // Entries of a DACL that could not be read may still grant someone else.
182
+ if (dacl.parsed) await rememberOwnerOnlyDirectory(target);
183
+ }
184
+
185
+ // For a file the caller has just created. On Windows a file created inside a
186
+ // directory restrictToOwner handled in this process inherits that directory's
187
+ // owner-only grant at creation, so no tool runs for it.
188
+ export async function restrictNewFileToOwner(target, options = {}) {
189
+ const platform = options.platform ?? process.platform;
190
+ if (platform === "win32") {
191
+ // A parent that cannot be identified is not trusted: the file gets its own grant.
192
+ const parent = await directoryIdentity(path.dirname(path.resolve(target))).catch(() => null);
193
+ if (parent && ownerOnlyDirectories.has(parent)) return;
194
+ }
195
+ await restrictToOwner(target, "file", options);
196
+ }