惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
腾讯CDC
T
Tailwind CSS Blog
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
The Cloudflare Blog
D
DataBreaches.Net
Recent Announcements
Recent Announcements
Engineering at Meta
Engineering at Meta
B
Blog
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
博客园 - 司徒正美
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
perf(browser): index role snapshot references · openclaw/...
vincentkoc · 2026-06-24 · via Recent Commits to openclaw:main

File tree

  • extensions/browser/src/browser

Original file line numberDiff line numberDiff line change

@@ -779,6 +779,7 @@ async function buildCdpRoleSnapshot(params: {

779779
780780

const counts = new Map<string, number>();

781781

const refsByKey = new Map<string, string[]>();

782+

const nodesByRef = new Map<string, RoleTreeNode>();

782783

const refs: Record<string, CdpRoleRef> = {};

783784

for (const node of tree) {

784785

const role = node.role.toLowerCase();

@@ -797,7 +798,13 @@ async function buildCdpRoleSnapshot(params: {

797798

params.nextRef.value += 1;

798799

node.ref = ref;

799800

node.nth = nth;

800-

refsByKey.set(key, [...(refsByKey.get(key) ?? []), ref]);

801+

const refsForKey = refsByKey.get(key);

802+

if (refsForKey) {

803+

refsForKey.push(ref);

804+

} else {

805+

refsByKey.set(key, [ref]);

806+

}

807+

nodesByRef.set(ref, node);

801808

refs[ref] = {

802809

role,

803810

...(node.name ? { name: node.name } : {}),

@@ -813,7 +820,7 @@ async function buildCdpRoleSnapshot(params: {

813820

const ref = refList[0];

814821

if (ref) {

815822

delete refs[ref]?.nth;

816-

const node = tree.find((entry) => entry.ref === ref);

823+

const node = nodesByRef.get(ref);

817824

if (node) {

818825

delete node.nth;

819826

}

Original file line numberDiff line numberDiff line change

@@ -46,6 +46,16 @@ describe("pw-role-snapshot", () => {

4646

expect(res.snapshot).not.toContain("button");

4747

});

4848
49+

it("keeps named branches with refs and drops empty branches when compact", () => {

50+

const aria = ['- list "Menu":', ' - button "Save"', '- list "Empty":', " - generic"].join(

51+

"\n",

52+

);

53+
54+

const res = buildRoleSnapshotFromAriaSnapshot(aria, { compact: true });

55+
56+

expect(res.snapshot).toBe('- list "Menu":\n - button "Save" [ref=e1]');

57+

});

58+
4959

it("computes stats", () => {

5060

const aria = ['- button "OK"', '- button "Cancel"'].join("\n");

5161

const res = buildRoleSnapshotFromAriaSnapshot(aria);

Original file line numberDiff line numberDiff line change

@@ -131,37 +131,42 @@ function removeNthFromNonDuplicates(refs: RoleRefMap, tracker: RoleNameTracker)

131131
132132

function compactTree(tree: string) {

133133

const lines = tree.split("\n");

134-

const result: string[] = [];

134+

const entries: Array<{ line: string; keep: boolean; hasRef: boolean; indent: number }> = [];

135+

const stack: Array<{ entry: (typeof entries)[number]; indent: number }> = [];

135136
136-

for (let i = 0; i < lines.length; i += 1) {

137-

const line = lines[i];

138-

if (line.includes("[ref=")) {

139-

result.push(line);

140-

continue;

137+

const finishEntry = () => {

138+

const current = stack.pop();

139+

if (!current) {

140+

return;

141141

}

142-

if (line.includes(":") && !line.trimEnd().endsWith(":")) {

143-

result.push(line);

144-

continue;

142+

current.entry.keep ||= current.entry.hasRef;

143+

if (current.entry.hasRef && stack.length > 0) {

144+

stack[stack.length - 1].entry.hasRef = true;

145145

}

146+

};

146147
147-

const currentIndent = getIndentLevel(line);

148-

let hasRelevantChildren = false;

149-

for (let j = i + 1; j < lines.length; j += 1) {

150-

const childIndent = getIndentLevel(lines[j]);

151-

if (childIndent <= currentIndent) {

152-

break;

153-

}

154-

if (lines[j]?.includes("[ref=")) {

155-

hasRelevantChildren = true;

156-

break;

157-

}

158-

}

159-

if (hasRelevantChildren) {

160-

result.push(line);

148+

for (const line of lines) {

149+

const indent = getIndentLevel(line);

150+

while (stack.length > 0 && stack[stack.length - 1].indent >= indent) {

151+

finishEntry();

161152

}

153+

const entry = {

154+

line,

155+

keep: line.includes("[ref=") || (line.includes(":") && !line.trimEnd().endsWith(":")),

156+

hasRef: line.includes("[ref="),

157+

indent,

158+

};

159+

entries.push(entry);

160+

stack.push({ entry, indent });

161+

}

162+

while (stack.length > 0) {

163+

finishEntry();

162164

}

163165
164-

return result.join("\n");

166+

return entries

167+

.filter((entry) => entry.keep)

168+

.map((entry) => entry.line)

169+

.join("\n");

165170

}

166171
167172

function processLine(

Original file line numberDiff line numberDiff line change

@@ -104,7 +104,12 @@ function buildStoredAriaRefs(

104104

const key = `${role}:${name ?? ""}`;

105105

const nth = counts.get(key) ?? 0;

106106

counts.set(key, nth + 1);

107-

refsByKey.set(key, [...(refsByKey.get(key) ?? []), node.ref]);

107+

const refsForKey = refsByKey.get(key);

108+

if (refsForKey) {

109+

refsForKey.push(node.ref);

110+

} else {

111+

refsByKey.set(key, [node.ref]);

112+

}

108113

refs[node.ref] = {

109114

role,

110115

...(name ? { name } : {}),