Repository navigation
✨ 新增 sctl run / sctl logs:触发后台/定时脚本运行并读取脚本运行日志 - #17
Merged
Merged
Conversation
3 tasks
CodFrm
added a commit
to scriptscat/scriptcat
that referenced
this pull request
Nov 5, 2026
…间接办法 - dev-loop.md:新增 sctl run / sctl logs 用法与注意事项(只限后台/定时脚本、exit 0 看状态、不经审批但有真实副作用、 手动运行不排重试、debug 级 GM_log 不入库、与编辑器运行或 cron 交叠可能误认),旧 sctl / 旧脚本猫的识别与回退 - background.md:删去无代码依据的「编辑器运行不同步值、菜单不触发」,改为与 sctl run 同一通路 - SKILL.md、api.md:GM_log 的 debug 级别在正式版不入库 - README 已知限制:依赖 scriptscat/sctl#17 与 #1825 的版本
Merged
3 tasks
…态不得误认、日志字段容错、MCP 运行等待发进度
- MCP scripts_run 等待期间周期发 progress(文案不提审批),wait:false 与 scripts_logs 不发 - sctl run 被 Ctrl-C 时说明运行可能已在 ScriptCat 中进行,不再说操作已作废 - run 结果日志被截断时提示 sctl logs <uuid>,不再指向 run 没有的筛选参数 - 升级提示同时覆盖旧版 ScriptCat 与旧版 sctl daemon - 修正 error 状态行的悬空冒号与 --timeout 上限的写法 - 补日志表格终端转义与 --since 30m 的测试
- protocol.md/cli.md/mcp.md:run-in 不符、统一超时含排队、wait:false 不排队、取消放弃未触发的排队运行 - METHOD_NOT_FOUND 的来源改为 daemon 的能力检查,并补旧版 daemon 需重启的说明 - mcp.md:scripts_run 等待期间发 progress,如实描述其他 ScriptCat 工具的 progress - 技能说明:logs 的 limit 语义(取最新 N 条、按旧到新打印)与 run-in 失败
CodFrm
added a commit
to scriptscat/scriptcat
that referenced
this pull request
Nov 5, 2026
…#1824) * 📝 新增 scriptcat-userscript Skill:指导 AI 编码代理编写页面/后台/定时脚本,并通过 sctl 安装与验证 - SKILL.md:选脚本类型、骨架、按权限/时机/存储/后台分组的易错规则,有无 sctl 两条验证路径 - references/api.md:按 script_compat.ts 的 grant 白名单列出已实现的 GM/CAT API 与和 TM 的差异 - references/background.md:Promise 生命周期、CATRetryError 重试、cron 与 once 扩展、日志 - references/userconfig.md:==UserConfig== 格式(类型推断按 UserConfigPanel 实际行为) - references/dev-loop.md:sctl install → 后台标签页 reload → debug console / page eval 验证 → 重装或 sctl edit 迭代; 已在真实浏览器实测:用户脚本 console 可见、整文件 edit 生效、同 name+namespace 重装原地更新(uuid 不变) * 📝 修正 scriptcat-userscript Skill 中与运行时不符的描述 - @grant none 下只有 GM_info/GM.info,没有 unsafeWindow(exec_script.ts 只注入 { GM, GM_info },unsafeWindow 仅在沙盒上下文 create_context.ts 设置) - cron 的 once 以「开始运行」计周期,失败的运行也占用本周期(lastruntime 在运行开始与每次状态更新时写入),失败重跑须用 CATRetryError - GM_foo 与 GM.foo 互通仅在名字完全一致时成立:@grant GM_xmlhttpRequest 不会暴露 GM.xmlHttpRequest(getGrantCandidates 只换前缀、区分大小写) - 每一行 @crontab 都会在运行时注册,安装校验和脚本列表只看第一行,任一行非法会停掉全部任务,因此改为「只写一行」 - 脚本体被包在 async 函数里,返回值总是 Promise;不 return Promise 时同步部分结束即记为完成,不会出现 "return not promise" 警告 - 解析 cron 的是 npm 包 cron(非 node-cron);UserConfig 的 min 不作用于 text;sctl grep 在多实例时同样报 SCRIPTCAT_AMBIGUOUS;page reload 已等待 load * 📝 scriptcat-userscript Skill 补充写脚本的方法与常用写法 - dev-loop.md:写之前用 sctl 侦察页面(snapshot/eval 试选择器与逻辑,debug network/request 找站点接口,鉴权信息不外泄) - dev-loop.md:用 @require file:/// 壳脚本迭代本地文件,审批一次即可(每次页面加载重读文件,需「允许访问文件网址」) - dev-loop.md:后台/定时脚本的可观测办法(重装即重跑 @background、测试时临时每分钟 cron、共享 @storageName 的探针页面脚本) - 新增 references/patterns.md:等待元素、SPA 路由切换、带记忆的菜单开关、跨域请求、样式、多语言、带重试的后台运行 - SKILL.md 加入口链接,README 结构表与已知限制同步 * ✨ scriptcat-userscript Skill 附带静态检查与壳脚本生成工具 - scripts/check.mjs:零依赖静态检查,按运行时规则报告未声明 grant 的 API 调用(含 depend 一并注入的 API)、@grant none 下用 GM API/unsafeWindow、none 与其他 grant 混写、页面脚本缺 @match/@include、后台脚本用 GM_getTab 系列、cron 字段/once/空格写法错误;警告未知 grant、后台脚本无顶层 return、多行 @crontab、@run-at/@early-start 不生效、请求域名不在 @connect 也不在 @match 下;有 error 时退出码 1 - scripts/stub.mjs:从本地脚本生成 @require file:/// 壳脚本(保留头部与 UserConfig),配合本地热重载 - check.test.mjs 对照 SUPPORTED_GRANTS 守卫内置 grant 清单;vitest 的 scripts 项目纳入 skills/**/*.test.mjs - SKILL.md、dev-loop.md、README 补充用法 * 📝 scriptcat-userscript Skill:后台/定时脚本优先用 sctl run / sctl logs 验证,旧版本退回间接办法 - dev-loop.md:新增 sctl run / sctl logs 用法与注意事项(只限后台/定时脚本、exit 0 看状态、不经审批但有真实副作用、 手动运行不排重试、debug 级 GM_log 不入库、与编辑器运行或 cron 交叠可能误认),旧 sctl / 旧脚本猫的识别与回退 - background.md:删去无代码依据的「编辑器运行不同步值、菜单不触发」,改为与 sctl run 同一通路 - SKILL.md、api.md:GM_log 的 debug 级别在正式版不入库 - README 已知限制:依赖 scriptscat/sctl#17 与 #1825 的版本 * 🐛 scriptcat-userscript check.mjs:修复对象键误报、关键字后正则漏报与 @connect 同域误判 - 对象字面量的键(`{ GM_getValue: 1 }`)不再算 API 调用;三元表达式里的仍算 - return/typeof/case/throw/in/of/void/delete/new 等关键字后的 `/` 按正则开头处理,正则里的引号不再吞掉同一行后面的调用 - @match 带通配子域或有多个域名时,请求其中一个域名不再视为同域(运行时只放行与页面完全相同的域名,见 getConnectMatched) - connect-missing 文案区分:脚本已有 @connect 时 GM_xmlhttpRequest 会被拒绝,没有任何 @connect 时询问用户;仍为 warn,因为检查只看 URL 字面量,无法确定它是否真被请求 - 某个文件读不了时继续检查其余文件,最后以退出码 2 结束 - check/stub 命令行用例真实 spawn node,按 scripts/check-i18n.test.mjs 的做法单独设超时,避免满载时超出 340ms 单测预算 * 📝 scriptcat-userscript Skill:按代码订正运行结果查看位置、@connect 拒绝规则与若干易错点 - 脚本列表只显示运行状态(运行中/错误/已停止)与定时脚本下次运行时间,GM_log 与错误信息改指向日志页(按 name/uuid 过滤)或 sctl logs - @connect:脚本已有 @connect 时未列入的域名被 GM_xmlhttpRequest 直接拒绝(之前允许过的除外),只有完全没有 @connect 才询问;native GM_download 总是询问;仅与页面完全相同的域名免声明 - CATRetryError 在 @grant none 下不存在;没有任何 @grant 行的脚本同样运行在沙盒里 - 同 @name/@namespace 不能在页面脚本与后台/定时脚本之间切换(类型不符被拒),临时页面脚本需另起名字 - GM_addElement 注入 <script> 在 Firefox 仍受页面 CSP 约束;urlchange 依赖 Navigation API,onurlchange === null 只说明授权生效 - dev-loop:补 get/run/logs 的 --scriptcat 行为、sctl run 的实际状态行与 JSON 字段(含 truncated)、@run-in 不符返回 INVALID_REQUEST;壳脚本示例的说明移到注释行;后台壳脚本可用 sctl run / 编辑器运行免审批重读本地 @require
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
sctl 无法触发脚本猫的后台/定时脚本运行,也读不到脚本运行日志。这两类脚本跑在 offscreen/sandbox 里,不是网页,sctl 也不能 attach 扩展页面(
PAGE_NOT_AUTOMATABLE),所以 AI 代理写完这类脚本后只能请用户去脚本列表里人工查看。Spec:
docs/specs/2026-11-04-script-run-logs.md(本 PR 前两个提交)。改动
scripts.run、scripts.logs(peerscriptcat,无审批阻塞)。schemaVersion保持 1.0.0:daemon 握手要求版本完全相等(conn.go:367),升版本会让旧版 ScriptCat 连不上,做法与 ✨ daemon 同时接入多个 ScriptCat 实例,修复普通与隐身进程互相顶替 (#14) #16 一致。protocol.md中“scriptcat 定义会改变schemaVersion”的说法已一并更正。生成给 ScriptCat 的 TS 不允许出现level子串,所以日志级别字段叫severity。sctl run <uuid>:默认等待本次运行结束,--timeout默认 60s、上限 240s;--no-wait触发后立即返回。sctl logs <uuid>:支持--since(默认 1h)、--level(映射到severity)、--text、--limit(默认 100,范围 1..1000)。METHOD_NOT_FOUND时附带升级提示,提示文案放在internal/cli/upgradehint,供 MCP 复用。terminalSafe转义后才输出到终端。scripts_run/scripts_logs的参数与 CLI 等价,不发“等待审批”进度,工具描述是静态文本。cli.md、mcp.md、architecture.md、README(中英)、skills/sctl已同步。threat-model.md把这两个操作列入未门控能力,并记录维护者于 2026-11-04 接受的残余风险:持有控制 token 的进程可以反复触发已安装的后台脚本,并读到GM_log过的内容。SCRIPTCAT_REF指向 ScriptCat373a117c。已知限制
GM_log的 debug 级别写进日志库,run/logs看不到 debug 日志。file://路径,来自 jsonschema 的错误格式。关联
SCRIPTCAT_REF。验证
base
2939485…headdc71bef,26 个文件。go test ./... -raceexit 0;make protocol-checkexit 0;golangci-lint run ./...0 issues。SCRIPTCAT_REF比对 exit 1,用373a117c比对 exit 0。docs/verification.md):本分支构建的 daemon 隔离在127.0.0.1:18643、使用临时 data dir,配对由 #1825 构建、在无头 Chromium 中运行的 ScriptCat。spec 的 18 项要求全部通过,包括:--no-wait;INVALID_REQUEST,未知 uuid 返回NOT_FOUND;6c0459b8构建的旧版收到METHOD_NOT_FOUND和升级提示,已有命令照常可用;SCRIPTCAT_AMBIGUOUS。审查修复(2026-11-05)
729a663spec 修订:INVALID_REQUEST;--no-wait不排队;取消时放弃还在排队的运行;62ef80d:scripts_run等待期间发中性进度(“Waiting for the script run to end…”),避免客户端 60 秒左右超时;wait:false和scripts_logs不发。sctl run被 Ctrl-C 时,提示运行可能已在 ScriptCat 中进行,不再说“已作废”。run的日志被截断时,提示改用sctl logs <uuid>查看完整记录。dc71bef:protocol.md、cli.md、mcp.md、skills/sctl按修订后的 spec 更新。验证(head
dc71bef):go test ./... -raceexit 0(我修复后自己重跑的结果),golangci-lint0 个问题,make protocol-checkexit 0。3b0038f5联合做了真实验证。SCRIPTCAT_REF不变。