Repository navigation
✨ daemon 同时接入多个 ScriptCat 实例,修复普通与隐身进程互相顶替 (#14) - #16
Merged
Merged
Conversation
- protocol.json 新增四个 ScriptCat 实例握手上下文(peers ["scriptcat"]),MAC 绑定实例 ID - auth 新增 ScriptCat*HMAC / VerifyScriptCat*HMAC - store 抽出共用的实例登记表实现,新增 <dataDir>/scriptcats.json(ScriptCatRegistry,保留名 scriptcat) - bridge 按实例 ID 保存新版 ScriptCat 连接,另保留一条老版连接;重名与保留名回 CONFLICT 且不落盘; 审计标注 scriptcat:<id>;scripts.* 暂时只在恰好一个 ScriptCat 在线时路由 - 更新 ScriptCat 生成 TS 的 SHA-256 摘要,protocol.md、threat-model.md、architecture.md 同步
- 未登记的新版 ScriptCat 实例在 pairing.key 存在时用其密钥按 ScriptCat 实例会话上下文校验; 能力声明被接受后先登记到 scriptcats.json,再删除 pairing.key,并断开在线的老版连接 - MAC 不符按握手失败处理、CONFLICT 不登记,两者都保留 pairing.key - 删除失败时登记保留;pairing.key 的密钥已属于某个实例即视为不存在,在启动与之后每次读取老版密钥时补删 - 接管、老版登记与老版密钥写入都在 regMu 下串行,接管前已握手的老版连接无法上线 - 新增 KeyStore.Delete(文件不存在不算错误);protocol.md §2.1 与 threat-model.md §5 同步
- 新增 SCRIPTCAT_OFFLINE / SCRIPTCAT_NOT_FOUND / SCRIPTCAT_AMBIGUOUS(peers: scriptcat) - 目标解析与合并在浏览器与 ScriptCat 间共用,老版 ScriptCat 只按保留名 scriptcat 选中 - scripts.list 声明 mergeField,汇总项带 scriptcat 来源;protocolgen 按对端类型校验来源字段 - /control/call 透传 scriptcat 目标;更新 ScriptCat TS 摘要与 docs/protocol.md
…s 工具支持 --scriptcat 目标
接管登记成功而删除 pairing.key 失败时,ScriptCatInstances 与 forget scriptcat 会因补删失败返回内部错误 (sctl status / sctl scriptcats 随之失败),目标 scriptcat 得到 SCRIPTCAT_OFFLINE。改为只判断这把密钥是否 仍归老版所有,补删仍只在启动与握手时进行。
…us 报错 - 接管时没删成的 pairing.key 只凭登记表里还有同一把密钥才作废;忘记或重新配对该实例会让密钥离开登记表, 残留随即重新成为老版密钥,被忘记的实例可借它再次握手或接管。现在先删残留,删不掉就报错且什么都不改。 - 内容损坏的 pairing.key 使 status、scriptcats list 与 forget scriptcat 报内部错误;现在视为存在(列为离线的 scriptcat,可被 forget 删除)。 - 合并浏览器与 ScriptCat 两份重复的实例列表、忘记与 ref 解析实现,CLI 两张实例表共用一个打印函数;修正过时注释。
This was referenced Nov 3, 2026
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.
背景
#14:同一 Chrome 配置里 ScriptCat 的普通进程和隐身(
"incognito": "split")进程都会连 daemon。daemon 只保留一条 ScriptCat 连接,新连接会顶掉旧的;ScriptCat 每次握手成功都把重连间隔重置为 2 秒,于是两个进程每 2 秒互相顶替,日志和审计缓冲区被handshake.ok刷满。本地用真实 daemon 加照抄 ScriptCat 重连策略的模拟客户端复现:单实例 12 秒内 1 次handshake.ok,两实例 7 次。修复分三步:
fix/incognito-external-access),直接消除 serve: ScriptCat's regular and Incognito instances replace each other's connection every 2 seconds #14 的循环。Spec:
docs/specs/2026-11-02-scriptcat-instances.md。改动
peer: {kind: "scriptcat", instanceId},HMAC 用四个新的scriptcat*上下文并绑定实例 ID;能力声明带名称与自报信息,名称在 ScriptCat 实例间唯一(scriptcat保留给老版),重名回CONFLICT且首次配对不落盘。新增错误码SCRIPTCAT_OFFLINE/SCRIPTCAT_NOT_FOUND/SCRIPTCAT_AMBIGUOUS;scripts.list增加mergeField。<dataDir>/scriptcats.json(0600,原子写入),与browsers.json共用一套登记实现。peer的 ScriptCat 仍用pairing.key连接,作为保留名scriptcat的老版实例,只顶替老版连接。pairing.key校验时,先登记到该实例、再删除pairing.key并断开在线的老版连接;MAC 不符或重名时pairing.key不变;删除失败时登记保留、启动和下次握手时重试,残留文件在列表、目标选择与忘记中视为不存在,忘记或重新配对该实例前先删残留,避免它重新变成可用的老版密钥。scripts.*可带 ScriptCat 目标(名称优先,其次实例 ID 前缀;scriptcat只按名称匹配老版)。规则与 sctl Browser 相同:一个在线直接发、多个在线时scripts.list合并(每条带scriptcat: {id, name},老版无id)、其他方法报SCRIPTCAT_AMBIGUOUS;跨类目标回INVALID_REQUEST;调用中目标断开回OPERATION_EXPIRED。get/grep/edit/install/enable/disable/delete新增--scriptcat(SCTL_SCRIPTCAT),未指定且有歧义时提示pass --scriptcat <name> or set SCTL_SCRIPTCAT;sctl get只在合并时多一列来源;新增sctl scriptcats [list]/forget;sctl status逐个列出 ScriptCat 实例,-o json保留extConnected并新增scriptcats。MCP 的 8 个scripts_*工具新增可选scriptcat字段。client: scriptcat:<instanceId>。与 ScriptCat 的协议同步
新上下文和错误码标注
peers: ["scriptcat"],生成给 ScriptCat 的 TS 因此变化。配对提交 scriptscat/scriptcat@bc6f6bb(分支chore/sctl-protocol-scriptcat-instances)只含make protocol-sync-scriptcat的生成文件和BRIDGE_ERROR_CODES新增的三个码,不改 ScriptCat 行为;本 PR 的SCRIPTCAT_REF指向它。合并顺序:先合 ScriptCat 同步提交,再合本 PR;若 ScriptCat 侧 squash 合并,生成文件不变,SCRIPTCAT_REF可改指向合并后的提交。验证
go build ./... && go vet ./... && go test ./... -race全部通过,golangci-lint 0 issues,make protocol-check通过;本地复现 CI 镜像检查(prettier 3.6.2 格式化后与 bc6f6bb4 的副本cmp一致)。--scriptcat只到达目标实例;MCP 字段透传;单目标与合并调用中途断开都作废;升级接管成功与两种失败路径;忘记新版实例与老版实例;sctl Browser 的配对、路由、合并与忘记不受 ScriptCat 实例影响,两类同名实例共存。未观察到
pairing.key失败时的重试:真实 daemon 里密钥与登记在同一目录,无法只让删除失败,仅由单元测试覆盖。Refs #14