@routerhub/agent-rules 1.5.198 → 1.5.199

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/AGENTS.base.md CHANGED
@@ -706,14 +706,16 @@ Chrome Helper 会越积越多,表现为“agent-browser 用着用着越来越
706
706
  1. 每次 `agent-browser tab new` 后必须记录本次任务创建的 tab id;任务结束前,必须关闭
707
707
  本任务打开的所有 tab,禁止把 Cloud Console、GitHub、Slack、Google 登录页等任务页面
708
708
  长期留在 agent-browser Chrome 里。
709
- 2. 每次浏览器自动化任务结束前,必须执行一次内存收尾检查:
710
- `agent-browser-cleanup status`(或仓库源码内 `bash scripts/agent-browser-cleanup.sh status`)。
711
- 3. `9226` 无头 Chrome 优先用于 agent 自动化;若 `9226` 的 tab 数 > 10,或 RSS > 1500MB,
712
- 必须执行 `agent-browser-cleanup auto` `agent-browser-cleanup hard` 释放内存。释放后下次
713
- 需要浏览器时再重新启动,不要为了“可能等会用”长期占着内存。
709
+ 2. 每次浏览器自动化任务结束前,**执行任务的 Agent 必须自动运行** `agent-browser-cleanup auto`
710
+ (或仓库源码内 `bash scripts/agent-browser-cleanup.sh auto`),禁止把这一步交给用户手动判断。
711
+ 用户只负责提出任务,Agent 负责判断是否该释放内存。
712
+ 3. `9226` 无头 Chrome 优先用于 agent 自动化;`agent-browser-cleanup auto` 会在 `9226` 的 tab 数
713
+ > 10,或 RSS > 1500MB 时自动释放它。释放后下次需要浏览器时再重新启动,不要为了“可能等会用”
714
+ 长期占着内存。
714
715
  4. `9223` 有头 Chrome 只在需要用户手动登录、手动查看动态效果、或必须共享可见页面时启动;
715
- 任务结束且用户不再需要查看时,必须关闭本任务 tab,并在确认没有人工操作中的页面后再
716
- `agent-browser-cleanup hard`。
716
+ 任务结束且用户不再需要查看时,必须关闭本任务 tab;`auto` 默认不会关闭 `9223`,避免误关用户
717
+ 正在看的页面。只有明确确认 `9223` 没有人工操作中的页面时,才允许设置
718
+ `AGENT_BROWSER_CLEANUP_INCLUDE_HEADED=1 agent-browser-cleanup auto` 或执行 `agent-browser-cleanup hard`。
717
719
  5. 禁止长期同时保留 `9223` + `9226` 两套 agent-browser Chrome 实例,除非当前任务明确需要。
718
720
  多会话并行时也必须各自用 namespace 隔离,任务完成各自清理自己创建的 tab。
719
721
  6. 禁止用 `kill -9` / `pkill -9` 强杀 Chrome;清理只能使用 `agent-browser-cleanup`、
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  所有对 @routerhub/agent-rules 的重大更改都会记录在这个文件中。
4
4
 
5
+ ## [1.5.199] - 2026-09-08
6
+
7
+ ### Changed
8
+
9
+ - **agent-browser 收尾从“手动命令”升级为“Agent 自动判断”**:规则明确要求每次浏览器自动化任务结束前,由执行任务的 Agent 自动运行 `agent-browser-cleanup auto`,禁止把判断交给用户。`auto` 模式同步调整为默认只自动释放超阈值的 `9226` 无头 Chrome;`9223` 有头 Chrome 默认只提示,需设置 `AGENT_BROWSER_CLEANUP_INCLUDE_HEADED=1` 才会自动关闭,避免误关用户正在看的页面。
10
+
5
11
  ## [1.5.198] - 2026-09-08
6
12
 
7
13
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routerhub/agent-rules",
3
- "version": "1.5.198",
3
+ "version": "1.5.199",
4
4
  "description": "Shared Copilot agent rules and guidelines for RouterHub projects",
5
5
  "main": "AGENTS.base.md",
6
6
  "bin": {
@@ -4,6 +4,7 @@ set -euo pipefail
4
4
  MODE="${1:-status}"
5
5
  TAB_LIMIT="${AGENT_BROWSER_TAB_LIMIT:-10}"
6
6
  RSS_LIMIT_MB="${AGENT_BROWSER_RSS_LIMIT_MB:-1500}"
7
+ INCLUDE_HEADED="${AGENT_BROWSER_CLEANUP_INCLUDE_HEADED:-0}"
7
8
 
8
9
  profileForPort() {
9
10
  case "$1" in
@@ -21,11 +22,12 @@ Modes:
21
22
  status 只查看 9223/9226 的标签页数量与内存占用
22
23
  soft 关闭 about:blank、newtab、devtools 等无业务标签页
23
24
  hard 优雅退出 agent-browser 专用 Chrome(9223/9226),释放内存
24
- auto tab 数或 RSS 超阈值时自动执行 hard,否则只输出状态
25
+ auto 超阈值时自动释放 9226;9223 默认只提示,避免误关用户正在看的页面
25
26
 
26
27
  Env:
27
28
  AGENT_BROWSER_TAB_LIMIT 默认 10
28
29
  AGENT_BROWSER_RSS_LIMIT_MB 默认 1500
30
+ AGENT_BROWSER_CLEANUP_INCLUDE_HEADED=1 时,auto 也允许释放 9223
29
31
  USAGE
30
32
  }
31
33
 
@@ -77,17 +79,17 @@ printStatus() {
77
79
  closeChromeByPort() {
78
80
  local portNumber="$1"
79
81
  local profileDir=""
82
+ local profileArg=""
80
83
  local processIds=""
81
84
  profileDir=$(profileForPort "$portNumber")
82
- processIds=$(ps -axo pid=,command= | awk -v portArg="--remote-debugging-port=${portNumber}" -v profileArg="--user-data-dir=${profileDir}" '
85
+ profileArg="--user-data-dir=${profileDir}"
86
+ processIds=$(ps -axo pid=,command= | awk -v profileArg="$profileArg" '
83
87
  {
84
- hasPort = 0
85
88
  hasProfile = 0
86
89
  for (fieldIndex = 2; fieldIndex <= NF; fieldIndex++) {
87
- if ($fieldIndex == portArg) hasPort = 1
88
90
  if ($fieldIndex == profileArg) hasProfile = 1
89
91
  }
90
- if (hasPort && hasProfile) print $1
92
+ if (hasProfile) print $1
91
93
  }
92
94
  ')
93
95
  if [[ -z "$processIds" ]]; then
@@ -116,15 +118,25 @@ softCleanup() {
116
118
  rm -f "/tmp/agent-browser-tabs-${portNumber}.json"
117
119
  }
118
120
 
119
- needsHardCleanup() {
120
- local overLimit="0"
121
+ autoCleanup() {
121
122
  while read -r portNumber tabCount rssMb; do
122
- if (( tabCount > TAB_LIMIT || rssMb > RSS_LIMIT_MB )); then
123
- echo "port ${portNumber}: over limit tabs=${tabCount}/${TAB_LIMIT} rssMB=${rssMb}/${RSS_LIMIT_MB}"
124
- overLimit="1"
123
+ if (( tabCount <= TAB_LIMIT && rssMb <= RSS_LIMIT_MB )); then
124
+ continue
125
+ fi
126
+
127
+ echo "port ${portNumber}: over limit tabs=${tabCount}/${TAB_LIMIT} rssMB=${rssMb}/${RSS_LIMIT_MB}"
128
+ if [[ "$portNumber" == "9226" ]]; then
129
+ closeChromeByPort "$portNumber"
130
+ continue
125
131
  fi
132
+
133
+ if [[ "$portNumber" == "9223" && "$INCLUDE_HEADED" == "1" ]]; then
134
+ closeChromeByPort "$portNumber"
135
+ continue
136
+ fi
137
+
138
+ echo "port ${portNumber}: headed Chrome skipped; set AGENT_BROWSER_CLEANUP_INCLUDE_HEADED=1 to close it automatically"
126
139
  done < <(portStatus 9223 && portStatus 9226)
127
- [[ "$overLimit" == "1" ]]
128
140
  }
129
141
 
130
142
  case "$MODE" in
@@ -142,11 +154,6 @@ case "$MODE" in
142
154
  ;;
143
155
  auto)
144
156
  printStatus
145
- if needsHardCleanup; then
146
- closeChromeByPort 9223
147
- closeChromeByPort 9226
148
- else
149
- echo "agent-browser Chrome is below cleanup thresholds"
150
- fi
157
+ autoCleanup
151
158
  ;;
152
159
  esac