page-action-cache 1.0.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.
Files changed (73) hide show
  1. package/dist/actions-executor.d.ts +62 -0
  2. package/dist/actions-executor.d.ts.map +1 -0
  3. package/dist/actions-executor.js +339 -0
  4. package/dist/actions-executor.js.map +1 -0
  5. package/dist/cache-invalidator.d.ts +70 -0
  6. package/dist/cache-invalidator.d.ts.map +1 -0
  7. package/dist/cache-invalidator.js +212 -0
  8. package/dist/cache-invalidator.js.map +1 -0
  9. package/dist/cache-store.d.ts +80 -0
  10. package/dist/cache-store.d.ts.map +1 -0
  11. package/dist/cache-store.js +361 -0
  12. package/dist/cache-store.js.map +1 -0
  13. package/dist/cache-strategy.d.ts +65 -0
  14. package/dist/cache-strategy.d.ts.map +1 -0
  15. package/dist/cache-strategy.js +237 -0
  16. package/dist/cache-strategy.js.map +1 -0
  17. package/dist/hooks-entry.d.ts +18 -0
  18. package/dist/hooks-entry.d.ts.map +1 -0
  19. package/dist/hooks-entry.js +27 -0
  20. package/dist/hooks-entry.js.map +1 -0
  21. package/dist/hooks.d.ts +10 -0
  22. package/dist/hooks.d.ts.map +1 -0
  23. package/dist/hooks.js +277 -0
  24. package/dist/hooks.js.map +1 -0
  25. package/dist/index.d.ts +24 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +34 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/scenario-recognizer.d.ts +45 -0
  30. package/dist/scenario-recognizer.d.ts.map +1 -0
  31. package/dist/scenario-recognizer.js +213 -0
  32. package/dist/scenario-recognizer.js.map +1 -0
  33. package/dist/security-policy.d.ts +62 -0
  34. package/dist/security-policy.d.ts.map +1 -0
  35. package/dist/security-policy.js +219 -0
  36. package/dist/security-policy.js.map +1 -0
  37. package/dist/tools.d.ts +209 -0
  38. package/dist/tools.d.ts.map +1 -0
  39. package/dist/tools.js +383 -0
  40. package/dist/tools.js.map +1 -0
  41. package/dist/types.d.ts +336 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/types.js +8 -0
  44. package/dist/types.js.map +1 -0
  45. package/dist/ux-enhancer.d.ts +60 -0
  46. package/dist/ux-enhancer.d.ts.map +1 -0
  47. package/dist/ux-enhancer.js +218 -0
  48. package/dist/ux-enhancer.js.map +1 -0
  49. package/dist/variable-resolver.d.ts +28 -0
  50. package/dist/variable-resolver.d.ts.map +1 -0
  51. package/dist/variable-resolver.js +201 -0
  52. package/dist/variable-resolver.js.map +1 -0
  53. package/docs/API.md +555 -0
  54. package/docs/IMPLEMENTATION.md +1792 -0
  55. package/docs/INTEGRATION.md +387 -0
  56. package/docs/README.md +183 -0
  57. package/index.ts +118 -0
  58. package/openclaw.plugin.json +208 -0
  59. package/package.json +76 -0
  60. package/skills/page-action-cache/SKILL.md +216 -0
  61. package/src/actions-executor.ts +441 -0
  62. package/src/cache-invalidator.ts +271 -0
  63. package/src/cache-store.ts +457 -0
  64. package/src/cache-strategy.ts +327 -0
  65. package/src/hooks-entry.ts +114 -0
  66. package/src/hooks.ts +332 -0
  67. package/src/index.ts +104 -0
  68. package/src/scenario-recognizer.ts +259 -0
  69. package/src/security-policy.ts +268 -0
  70. package/src/tools.ts +437 -0
  71. package/src/types.ts +482 -0
  72. package/src/ux-enhancer.ts +266 -0
  73. package/src/variable-resolver.ts +258 -0
@@ -0,0 +1,208 @@
1
+ {
2
+ "id": "page-action-cache",
3
+ "name": "Page Action Cache",
4
+ "version": "1.0.0",
5
+ "description": "Caches LLM browser operations to avoid re-analyzing the same DOM. Reduces token consumption and operation latency through scenario recognition (login, search, payment, etc.) and multi-level caching (L3/L2/L1).",
6
+ "author": "OpenClaw",
7
+ "license": "MIT",
8
+ "kind": "extension",
9
+ "main": "./src/hooks-entry.js",
10
+ "exports": {
11
+ ".": "./src/index.js",
12
+ "./hooks-entry": "./src/hooks-entry.js"
13
+ },
14
+ "configSchema": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "properties": {
18
+ "enabled": {
19
+ "type": "boolean",
20
+ "default": true,
21
+ "description": "Enable or disable the page action cache extension"
22
+ },
23
+ "autoUseCache": {
24
+ "type": "boolean",
25
+ "default": true,
26
+ "description": "Automatically use cached actions when available"
27
+ },
28
+ "scenarioRecognitionEnabled": {
29
+ "type": "boolean",
30
+ "default": true,
31
+ "description": "Enable automatic scenario recognition (login, search, checkout, etc.)"
32
+ },
33
+ "llmClassificationThreshold": {
34
+ "type": "number",
35
+ "default": 70,
36
+ "minimum": 0,
37
+ "maximum": 100,
38
+ "description": "Confidence threshold for LLM-based scenario classification (0-100)"
39
+ },
40
+ "cacheLevelStrategy": {
41
+ "type": "string",
42
+ "enum": ["auto", "l3-only", "l2-only", "l1-only"],
43
+ "default": "auto",
44
+ "description": "Cache level strategy: auto (default), l3-only (scenario-level only), l2-only (flow-level only), l1-only (atomic-level only)"
45
+ },
46
+ "defaultCacheLevel": {
47
+ "type": "string",
48
+ "enum": ["L3", "L2", "L1"],
49
+ "default": "L3",
50
+ "description": "Default cache level when no scenario is recognized"
51
+ },
52
+ "pageChangeDetectionEnabled": {
53
+ "type": "boolean",
54
+ "default": true,
55
+ "description": "Enable automatic page change detection to invalidate stale caches"
56
+ },
57
+ "changeInvalidationThreshold": {
58
+ "type": "number",
59
+ "default": 80,
60
+ "minimum": 0,
61
+ "maximum": 100,
62
+ "description": "Page change confidence threshold for cache invalidation (0-100)"
63
+ },
64
+ "invalidationStrategy": {
65
+ "type": "string",
66
+ "enum": ["soft", "hard"],
67
+ "default": "soft",
68
+ "description": "Cache invalidation strategy: soft (mark stale, allow override) or hard (immediately delete)"
69
+ },
70
+ "variableExtractionEnabled": {
71
+ "type": "boolean",
72
+ "default": true,
73
+ "description": "Enable automatic variable extraction from user input (username, password, etc.)"
74
+ },
75
+ "allowUserConfirmVariables": {
76
+ "type": "boolean",
77
+ "default": false,
78
+ "description": "Allow user confirmation for extracted variables before execution"
79
+ },
80
+ "encryptSensitiveCache": {
81
+ "type": "boolean",
82
+ "default": false,
83
+ "description": "Encrypt sensitive cache entries (passwords, tokens) using AES-256-GCM"
84
+ },
85
+ "accessControlEnabled": {
86
+ "type": "boolean",
87
+ "default": false,
88
+ "description": "Enable access control for sensitive cache operations"
89
+ },
90
+ "logSanitizationEnabled": {
91
+ "type": "boolean",
92
+ "default": true,
93
+ "description": "Automatically redact sensitive data from logs"
94
+ },
95
+ "showCacheStatusToUser": {
96
+ "type": "boolean",
97
+ "default": true,
98
+ "description": "Display cache hit/miss status to users"
99
+ },
100
+ "enableUserCacheConfirmation": {
101
+ "type": "boolean",
102
+ "default": false,
103
+ "description": "Require user confirmation before using cached actions"
104
+ },
105
+ "enableUserForcedRefresh": {
106
+ "type": "boolean",
107
+ "default": true,
108
+ "description": "Allow users to force refresh specific cache entries"
109
+ },
110
+ "enableUserCacheErrorReport": {
111
+ "type": "boolean",
112
+ "default": true,
113
+ "description": "Enable user reporting of cache execution errors"
114
+ },
115
+ "trackExecutionStats": {
116
+ "type": "boolean",
117
+ "default": true,
118
+ "description": "Track execution statistics (hit rate, saved tokens, saved time)"
119
+ },
120
+ "statsUpdateInterval": {
121
+ "type": "number",
122
+ "default": 60,
123
+ "minimum": 10,
124
+ "description": "Statistics update interval in seconds (minimum 10)"
125
+ }
126
+ }
127
+ },
128
+ "uiHints": {
129
+ "enabled": {
130
+ "label": "Enable Cache Extension",
131
+ "description": "Enable or disable the page action cache extension"
132
+ },
133
+ "autoUseCache": {
134
+ "label": "Auto Use Cache",
135
+ "description": "Automatically use cached actions when available"
136
+ },
137
+ "scenarioRecognitionEnabled": {
138
+ "label": "Scenario Recognition",
139
+ "description": "Enable automatic scenario recognition (login, search, checkout, etc.)"
140
+ },
141
+ "cacheLevelStrategy": {
142
+ "label": "Cache Strategy",
143
+ "description": "Cache level strategy (auto, l3-only, l2-only, l1-only)"
144
+ },
145
+ "encryptSensitiveCache": {
146
+ "label": "Encrypt Sensitive Data",
147
+ "description": "Encrypt sensitive cache entries (passwords, tokens)",
148
+ "sensitive": false
149
+ },
150
+ "showCacheStatusToUser": {
151
+ "label": "Show Cache Status",
152
+ "description": "Display cache hit/miss status to users"
153
+ }
154
+ },
155
+ "tools": [
156
+ {
157
+ "name": "execute_cached",
158
+ "label": "Execute Cached Actions",
159
+ "description": "Execute cached page action sequences, skipping LLM analysis. Significantly reduces token consumption and operation latency."
160
+ },
161
+ {
162
+ "name": "cache_stats",
163
+ "label": "Cache Statistics",
164
+ "description": "View cache statistics including hit rate, saved tokens, and saved time."
165
+ },
166
+ {
167
+ "name": "cache_list",
168
+ "label": "List Cache Entries",
169
+ "description": "List all cached page action entries with their metadata."
170
+ },
171
+ {
172
+ "name": "cache_clear",
173
+ "label": "Clear Cache",
174
+ "description": "Clear all cached page action entries."
175
+ },
176
+ {
177
+ "name": "scenario_list",
178
+ "label": "List Scenarios",
179
+ "description": "List all recognized scenarios with their match patterns."
180
+ },
181
+ {
182
+ "name": "force_refresh",
183
+ "label": "Force Refresh Cache",
184
+ "description": "Force refresh a specific cache entry by URL and viewport."
185
+ }
186
+ ],
187
+ "hooks": [
188
+ {
189
+ "name": "before_tool_call",
190
+ "description": "Scenario recognition and cache interception"
191
+ },
192
+ {
193
+ "name": "after_tool_call",
194
+ "description": "Save LLM analysis results to cache"
195
+ },
196
+ {
197
+ "name": "before_prompt_build",
198
+ "description": "Inject cache usage guide into prompts"
199
+ }
200
+ ],
201
+ "runtime": {
202
+ "node": ">=18.0.0"
203
+ },
204
+ "openclaw": {
205
+ "minVersion": "2026.2.0",
206
+ "extensions": ["./src/hooks-entry.js"]
207
+ }
208
+ }
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "page-action-cache",
3
+ "version": "1.0.1",
4
+ "description": "Page action caching extension for OpenClaw - caches LLM browser operations to avoid re-analyzing the same DOM",
5
+ "keywords": [
6
+ "automation",
7
+ "browser",
8
+ "cache",
9
+ "extension",
10
+ "openclaw"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "OpenClaw",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/openclaw/openclaw.git",
17
+ "directory": "extensions/page-action-cache"
18
+ },
19
+ "files": [
20
+ "index.ts",
21
+ "dist/",
22
+ "src/",
23
+ "skills/",
24
+ "docs/",
25
+ "package.json",
26
+ "openclaw.plugin.json"
27
+ ],
28
+ "type": "module",
29
+ "main": "src/hooks-entry.js",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./src/index.d.ts",
33
+ "default": "./src/index.js"
34
+ },
35
+ "./hooks-entry": {
36
+ "types": "./src/hooks-entry.d.ts",
37
+ "default": "./src/hooks-entry.js"
38
+ }
39
+ },
40
+ "scripts": {
41
+ "build": "tsc",
42
+ "publish:npm": "./scripts/npm_publish.sh",
43
+ "test": "vitest",
44
+ "typecheck": "tsc --noEmit"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^20.0.0",
48
+ "typescript": "^5.0.0",
49
+ "vitest": "^1.0.0"
50
+ },
51
+ "peerDependencies": {
52
+ "openclaw": ">=2026.2.0"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "openclaw": {
56
+ "optional": true
57
+ }
58
+ },
59
+ "config": {
60
+ "test": {
61
+ "include": [
62
+ "tests/**/*.test.ts"
63
+ ],
64
+ "exclude": [
65
+ "node_modules",
66
+ "dist",
67
+ "**/node_modules/**"
68
+ ]
69
+ }
70
+ },
71
+ "openclaw": {
72
+ "extensions": [
73
+ "./src/hooks-entry.js"
74
+ ]
75
+ }
76
+ }
@@ -0,0 +1,216 @@
1
+ # 页面操作缓存扩展 - 使用指南
2
+
3
+ **版本**: 1.0.0
4
+ **更新日期**: 2026-03-13
5
+
6
+ ## 概述
7
+
8
+ ## 概述
9
+
10
+ 本技能提供了页面操作缓存功能,可以缓存 LLM 分析浏览器页面后生成的操作序列。当再次访问相同页面时,直接使用缓存的操作,无需重新分析 DOM,大幅降低 token 消耗和操作延迟。
11
+
12
+ ## 核心优势
13
+
14
+ - **节省 Token**: 避免每次操作都发送 DOM 给 LLM 分析
15
+ - **加速执行**: 跳过 LLM 分析,直接执行缓存的操作
16
+ - **智能匹配**: 多层场景识别(规则+LLM+历史)
17
+ - **安全可靠**: 自动检测页面变化,缓存失效
18
+
19
+ ## 可用工具
20
+
21
+ ### 1. execute_cached - 执行缓存操作
22
+
23
+ **用途**: 执行缓存的页面操作序列
24
+
25
+ **参数**:
26
+ - `cacheKey` (必需): 缓存键(从 cache_info 中获取)
27
+ - `fromIndex` (可选): 从第几个操作开始执行(默认 0)
28
+ - `toIndex` (可选): 执行到第几个操作(不指定则执行全部)
29
+ - `dryRun` (可选): 试运行模式,不实际执行
30
+ - `force` (可选): 强制执行(忽略页面变化检测)
31
+
32
+ **示例**:
33
+ ```
34
+ 使用缓存登录 example.com,cacheKey: abc123
35
+ ```
36
+
37
+ ### 2. cache_stats - 查看缓存统计
38
+
39
+ **用途**: 查看缓存命中统计、节省的 token 等
40
+
41
+ **参数**: 无
42
+
43
+ **示例**:
44
+ ```
45
+ 查看缓存统计信息
46
+ ```
47
+
48
+ ### 3. cache_list - 列出所有缓存
49
+
50
+ **用途**: 列出所有缓存条目及其详情
51
+
52
+ **参数**:
53
+ - `limit` (可选): 最多返回的条目数(默认 20)
54
+ - `filterScenario` (可选): 按场景过滤(如 login, checkout)
55
+
56
+ **示例**:
57
+ ```
58
+ 列出所有登录相关的缓存
59
+ ```
60
+
61
+ ### 4. cache_clear - 清空缓存
62
+
63
+ **用途**: 清空缓存条目
64
+
65
+ **参数**:
66
+ - `scenario` (可选): 只清空指定场景的缓存
67
+
68
+ **示例**:
69
+ ```
70
+ 清空所有缓存
71
+ 清空登录场景的缓存
72
+ ```
73
+
74
+ ### 5. scenario_list - 列出所有场景
75
+
76
+ **用途**: 列出所有支持的缓存场景及其匹配规则
77
+
78
+ **参数**: 无
79
+
80
+ **示例**:
81
+ ```
82
+ 列出所有支持的缓存场景
83
+ ```
84
+
85
+ ### 6. force_refresh - 强制刷新缓存
86
+
87
+ **用途**: 强制刷新指定页面的缓存
88
+
89
+ **参数**:
90
+ - `url` (必需): 页面 URL
91
+ - `viewport` (可选): 视口尺寸
92
+
93
+ **示例**:
94
+ ```
95
+ 强制刷新 example.com/login 的缓存
96
+ ```
97
+
98
+ ## 使用流程
99
+
100
+ ### 场景 1: 首次访问页面
101
+
102
+ ```
103
+ 用户: "登录 example.com"
104
+
105
+ LLM: 分析页面 DOM,生成操作序列
106
+
107
+ 系统: 自动保存到缓存(L3 级)
108
+ ```
109
+
110
+ ### 场景 2: 再次访问相同页面
111
+
112
+ ```
113
+ 用户: "登录 example.com"
114
+
115
+ 系统: 检测到缓存匹配(置信度 95%)
116
+
117
+ LLM: 收到 cacheInfo,决定使用缓存
118
+
119
+ 系统: 使用 execute_cached 工具执行缓存操作
120
+
121
+ 结果: 节省 5000 tokens,加速 2 秒
122
+ ```
123
+
124
+ ### 场景 3: 页面发生变化
125
+
126
+ ```
127
+ 用户: "登录 example.com"
128
+
129
+ 系统: 检测页面结构变化
130
+
131
+ 系统: 自动失效缓存
132
+
133
+ LLM: 重新分析页面,生成新操作
134
+
135
+ 系统: 保存新的缓存
136
+ ```
137
+
138
+ ## 支持的场景
139
+
140
+ | 场景 | 关键词 | 缓存层级 |
141
+ |------|---------|---------|
142
+ | login | 登录、登陆、注册、sign in | L3 |
143
+ | logout | 退出、登出、注销、logout | L3 |
144
+ | search | 搜索、查找、search | L3 |
145
+ | checkout | 结账、结算、支付、checkout | L3 |
146
+ | settings | 设置、配置、修改 | L3 |
147
+ | form_fill | 填写、填表单、提交 | L2 |
148
+ | navigate | 打开、进入、跳转 | L2 |
149
+ | screenshot | 截图、screenshot | L1 |
150
+
151
+ ## 缓存层级
152
+
153
+ - **L3: 场景级** - 包含变量模板(如 username, password),高置信度时使用
154
+ - **L2: 流程级** - 固定操作序列,中等置信度时使用
155
+ - **L1: 原子级** - 单个操作,低置信度时使用
156
+
157
+ ## 注意事项
158
+
159
+ 1. **页面变化检测**: 系统会自动检测页面结构变化,如果检测到变化会自动失效缓存
160
+ 2. **变量替换**: 支持变量模板(如 ${username}),执行时自动从用户输入提取
161
+ 3. **敏感数据**: 密码等敏感数据会自动脱敏存储
162
+ 4. **试运行**: 使用 dryRun 参数可以预览操作而不执行
163
+ 5. **强制执行**: 使用 force 参数可以跳过页面变化检测(谨慎使用)
164
+
165
+ ## 最佳实践
166
+
167
+ 1. **优先使用缓存**: 当工具返回 cacheInfo 时,优先使用 execute_cached 工具
168
+ 2. **检查命中统计**: 定期查看 cache_stats,了解缓存效果
169
+ 3. **及时清理**: 使用 cache_clear 清理不再需要的缓存
170
+ 4. **测试新功能**: 使用 dryRun 模式测试缓存操作
171
+ 5. **处理变化**: 当页面变化导致操作失败时,使用 force_refresh 刷新缓存
172
+
173
+ ## 故障排查
174
+
175
+ ### 问题 1: 缓存未命中
176
+
177
+ **原因**:
178
+ - 首次访问该页面
179
+ - 缓存已过期
180
+ - 页面结构发生变化
181
+
182
+ **解决**:
183
+ - 使用 scenario_list 查看支持的场景
184
+ - 使用 cache_list 查看现有缓存
185
+ - 使用 force_refresh 强制刷新
186
+
187
+ ### 问题 2: 缓存执行失败
188
+
189
+ **原因**:
190
+ - 页面结构发生变化
191
+ - 元素选择器失效
192
+ - 操作顺序错误
193
+
194
+ **解决**:
195
+ - 查看执行结果中的错误信息
196
+ - 使用 force_refresh 刷新缓存
197
+ - 调整操作序列
198
+
199
+ ### 问题 3: 变量未替换
200
+
201
+ **原因**:
202
+ - 用户输入中不包含变量值
203
+ - 变量名不匹配
204
+
205
+ **解决**:
206
+ - 确保用户输入包含变量值(如 "用户名 alice")
207
+ - 使用变量提取测试验证
208
+
209
+ ## 统计信息含义
210
+
211
+ - **总条目数**: 当前缓存的页面操作条目数量
212
+ - **总命中**: 缓存命中的总次数
213
+ - **命中率**: 缓存命中占总请求的百分比
214
+ - **L3/L2/L1 命中**: 各层级缓存命中的次数
215
+ - **节省 Token**: 估算节省的 token 数量
216
+ - **节省时间**: 估算节省的时间(毫秒)