Commit Graph
22 Commits
Author SHA1 Message Date
Qiu Yuzhou 31e9f6e95f refactor(sysproxy): 观察机写面收成意图命令,字段退回实现 2026-10-03 20:29:15 +08:00
Qiu Yuzhou 16a2384498 fix(runtime): 收敛票据恒查全部失效事实,agent 关闭不再被旧收敛复活
mode/catalog 路径的票据子集缺 .flow/.agentEnabled:agent 关闭落在
mode 切换健康门 await 窗口内会被误分类为失败并触发 restore,把用户
显式的 off 意图静默撤销。删除逐 call site 挑子集的 Checks 政策,
convergenceIsCurrent 恒查 flow/mode/preparation/agentEnabled 四事实;
deployPrepared 的手工 preparation 守卫随之删除。

restore 门禁先行:agent 意图与票据时效先于回滚载荷持久化——竞态下
不再把旧 mode 写回持久层(内存/持久层分叉、用户切换被无声撤销)。

轮询写入守卫对齐同一票据词汇:防火墙轮询 await 恢复后补查代际
(cancel 后不得把 .firewallBlocked 盖回 .off);系统代理健康 Task
post-await 守卫补 agentEnabled。

新增 5 个交错/门禁测试(BlockingProbe/BlockingFirewallChecker 暂停
缝;修复前实测全红:agent 重注册、running 复活、.direct 意图被改回
.global、载荷写回、.failed 误分类);CONTEXT.md 增补 Convergence
ticket 词条。全量 792 测试通过。
2026-10-03 18:44:58 +08:00
Qiu Yuzhou eac30c4abd refactor(sysproxy): 系统代理策略机抽为 SystemProxyObserver 模块
ADR-0022 的观察/修复/挂起策略此前溶解在控制器 15 个可变字段里、由
Gate/Inspection/Commands/Health/Mode 五个文件交叉读写。现在策略机独立为
SystemProxyObserver:意图开关、出口可用性、期望配置与健康循环调度以
@MainActor 闭包注入,模块不反向依赖控制器;底层继续只依赖
SystemProxyControlling / helper 注册缝 / 网络变化监视三条既有缝。

- 3 个 @Published 呈现事实随迁,控制器留同名只读门面(测试与诊断面零改动);
  adapter 再发布链 merge 观察机 objectWillChange,主队列 hop 语义不变
- 健康循环留在控制器(循环体含运行时健康呈现),任务柄归观察机;
  cleanup-until-quiet、网络变化 inspection 调度与操作互斥全部内聚
- 方法体逐字搬运(settings.systemProxyEnabled→isIntentEnabled() 等机械替换),
  语义零改动;既有 777 测试全绿
2026-10-03 12:44:20 +08:00
Qiu Yuzhou 1fed58c903 refactor(rules): drop the dead rule-mode validation seam
ruleModeCandidateRules / ruleModeValidation 零生产调用者——生产校验经由
RulesWorkflow 预检与 RuleRuntimeCompiler.compile;控制器内这份薄复制删除。
相关测试断言改为直接调用领域层 RuleRuntimeCompiler.validation(与被删缝
同参同义),遮蔽关系与重排不变性断言原样保留。
2026-10-03 11:13:10 +08:00
Qiu Yuzhou d7169d9f01 refactor(runtime): route catalog sync through the convergence spine
- catalogDidCommit 的 deployed 分支体(派生 + 幂等跳过 + deployPrepared)
  与 deploy() 逐语义等价,改走 deploy();runtimeAlreadyConverged 独立机制
  删除,plan 空判定由 apply 层的 convergencePlanIsEmpty 统一承担。
- deploy/deployPrepared 返回 ConvergenceResult:被取代的派生按 .superseded
  呈现为 .revalidated,其余路径仍由状态面映射。
- reexpand 三-case 开关收敛为 convergeToReexpanded:convergeAgent /
  updateSettings / resyncOnLaunch 各变一行;catalogDidCommit 保留按 case
  的结构化 outcome 映射。
- 统一设置持久化 epilogue 为 persistSettings:setAgentEnabled /
  setSystemProxyEnabled / transitionMode 三处相同 save-fail 语义折叠
  (updateSettings 的 throw 变体与级联关闭的 return-nil 变体语义不同,
  保持原样)。
- SkeletonTests 运行时适配器豁免名单登记 +Convergence.swift。
2026-10-03 11:08:24 +08:00
Qiu Yuzhou 8587b2e80c refactor(runtime): unify apply/restore into the convergence spine
三份「执行 → 健康门 → 失败回滚」编排骨架(mode 切换 / rules 提交 /
deployPrepared)统一为收敛脊柱的 apply 层:

- apply:幂等跳过(派生契约与运行中运行时逐字节相同 → .unchanged,
  不闪 starting、不重走健康门)→ 计划执行 → 健康门(requiresReceipt /
  convergeProxyOnSuccess / preserveProxyOnFailure 逐路径参数照旧)→
  成功后按 proxyTail 收敛系统代理。
- restore:单一回滚例程 + RollbackPlan 两种载荷 policy(mode 的
  settings/mode 回退 + 意图变化强制重收敛;rules 的规则文档恢复)。
  restoreRuntimeDocument/relaunchPreviousInstance 删除——计划层对
  写契约/信号/注销重注的裁决与旧例程逐场景等价。
- 票据 inout 传参:execute 后的 flow 推进对调用方可见,rules 提交在
  apply 之后的时效检查使用推进过的票据。
- ModeTransitionSnapshotForRules 删除,rules 回滚计划在部署入口构建。

行为保持:.run 计划动作全部同步执行,starting 前置不可观测;mode/rules
路径到 apply 时计划必非空,幂等跳过只对 deploy 路径生效(与「有效值未
变的提交不做运行时收敛」不变量一致)。
2026-10-03 10:56:23 +08:00
Qiu Yuzhou dc35e70798 refactor(runtime): capture convergence tickets instead of hand-checked generations
execute 现在返回 RuntimeExecutionOutcome(成功与否 + 本次占用的并发流
代际),mode 与 rules 路径的 24 处手写代际 guard 收拢为 ConvergenceTicket
的 convergenceIsCurrent 检查;两处 flowGeneration + 1 手算随之消失。
行为逐字节保持:mode 路径的 mode 代际仍在派生前捕获、preparation 分量
在派生后推进;rules 路径四个代际事实全查不变。
2026-10-03 10:30:47 +08:00
Qiu Yuzhou e345d772eb fix(runtime): make ACL deployment transactional 2026-10-03 00:09:42 +08:00
Qiu Yuzhou e5de11a5fe perf(rules): share snapshots and reuse commit results 2026-10-02 23:50:59 +08:00
Qiu Yuzhou 09686a80db feat(rules): persist cross-source enablement and recover deployments (#78) 2026-10-02 21:38:03 +08:00
Qiu Yuzhou 280a3fe6fe fix(rules): make validation and ACL order independent (#75)
Normalize source-independent match/action identities while preserving custom UUIDs. Analyze complete valid candidates for same-action coverage and full or partial opposite-action shadowing without dropping saved intent. Keep duplicate and fixed-local conflicts blocking, including mapped IPv6.

Canonicalize ACL entries without changing runtime source selection or proxy-default skeleton. Verify persistence and no-restart reordering through the Controller, collection permutations, and pinned sslocal loopback comparisons.

Validation: 728 hostless tests and 2 pinned-binary smoke tests passed with ad-hoc arm64 signing; format, lint (3 existing warnings, 0 errors), and diff checks passed. No real system-proxy writes or automatic visual checks.
2026-10-02 16:34:52 +08:00
Qiu Yuzhou 4a0a72c6cf feat: observe and repair system proxy configuration (#73) 2026-10-01 23:29:56 +08:00
Qiu Yuzhou 7d0ebc79b4 refactor(tests): drop TEST_HOST by linking tests against app-source static lib
单测不再以 app 可执行为宿主:新增 ShadowsocksX-NG2Core 静态库 target 同源
编译 App/(除 @main)与 Domain/,模块名沿用 ShadowsocksX_NG2 使全部测试的
@testable import 零改动;app target 模块改名 ShadowsocksX_NG2App 避免共享
Products 目录 swiftmodule 撞名。两个测试 target 改链 Core 后 xcodegen 不再
生成 TEST_HOST,xcodebuild test 只构建不启动 app——与安装版运行实例零接触
(pgrep 全程验证无 app 进程)。同源双编译沿用 Agent/Helper 共享 Domain 文件
的既定模式,Core 只被测试 target 依赖,发布链不编译它。

随之删除 MainApp.swift 的整套测试宿主脚手架(isUnitTesting/makeTesting/
Noop 服务/Ephemeral 存储,-142 行),app 在测试下不再启动,守卫失去存在
理由。宿主移除暴露三处 Bundle.main 依赖,改为显式缝:控制器新增 appBundle
注入(内置规则快照 BuiltinRuleCatalog 与 LaunchDaemon 清单指纹
launchDaemonPlistData(in:) 均按 bundle 读取,生产默认 .main 不变);XPC
listener delegate 期望客户端身份改为可注入(测试按本进程 SecCode 自查)。
测试经 AppArtifact.bundle(沿测试包落盘位置向上查找 app 产物,兼容
TEST_HOST 内嵌与平级两种布局)统一取产物。

665 单测 + 11 冒烟全绿,task build 生产构建不受影响。
2026-09-30 20:44:13 +08:00
Qiu Yuzhou d2a8d6105c feat(system-proxy): route writes through privileged LaunchDaemon helper
Implements issue #71 with ADR-0020 (supersedes ADR-0019's endpoint-signature
cleanup, startup cleanup, and health-gate cleanup).

- New ShadowsocksX-NG2SystemProxyHelper target: app-bundled root LaunchDaemon
  (SMAppService.daemon, on-demand via MachServices) that mechanically applies
  a closed typed configuration or executes an unconditional clear. Clients are
  accepted by code-signing bundle identifier only; requests run serially on a
  shared queue (last-writer-wins).
- SystemProxyConfiguration is now the closed typed apply payload (Codable over
  JSON XPC): explicit SOCKS/HTTP/HTTPS enable + endpoints, PAC and
  auto-discovery disabled with URL/JS removed, explicit simple-hostname
  exclusion, complete ExceptionsList. Unmodeled Proxies keys are preserved and
  equivalent values skip the commit.
- Cleanup is a side effect of a persisted system-proxy intent on-to-off
  transition only: the switch itself, or the agent-off cascade (persist both
  intents off, clear, then stop listeners; failed cascade persistence records
  no transition and clears nothing). Launch with the switch off, health-gate
  closure, invalid targets, and passive events never clear. Failed clears are
  surfaced without deferred retry.
- Endpoint-signature store, ownership migration, and direct Authorization
  Services writes are removed; old signature files stay inert. Helper
  unavailability or pending approval keeps an enabled intent pending and
  surfaces the Login Items approval path (HomeView button + menu label).
2026-09-30 12:26:40 +08:00
Qiu Yuzhou a8cd6262c2 feat(proxy): remove PAC and accept ACL system proxy path
Remove the PAC product feature entirely: PAC HTTP service, port, health
probe, runtime extension, PAC URL system proxy projection, PAC rule
editing, and GFWList URL settings. The product now exposes rule / global /
direct modes only, all projected as a local SOCKS system-proxy target.

First-run defaults are rule + proxyWhenUnmatched, agent on, system proxy
off. Homepage and status menu share one ProxyControlSnapshot showing the
three modes and rule sub-options. Manual servers, subscriptions, Legacy
import, and independent SOCKS/HTTP inbounds are retained.

Fix: include verbose in SslocalListenFingerprint so a verbose-only
contract change restarts sslocal instead of leaving RUST_LOG stale.

Revise CONTEXT.md vocabulary, ADR-0007, and ADR-0009. Record GFWList
exception shadowing, IPv6 system-exception, DNS, and traffic-coverage
boundaries. Add host acceptance evidence document.

Closes #67
2026-09-26 21:58:12 +08:00
Qiu Yuzhou 9b32400b24 feat(proxy): add custom rule storage, validation, and ACL merge
Persist user custom rules (exact domain, domain suffix, IPv4/IPv6 CIDR)
with stable identity and source metadata. Reject rules that conflict
with the fixed local scope or are shadowed by sslocal domain-proxy /
IP-direct priority, with explainable reasons. Merge valid custom rules
into both rule sub-modes ACL; global and direct modes do not load them.
Rule content changes recompile ACL via full restart with rollback.
Diagnostics expose only count and content-version summary.
2026-09-26 20:27:56 +08:00
Qiu Yuzhou 4a4535b947 feat(proxy): add GFWList proxy candidates for direct-when-unmatched rule mode 2026-09-26 19:20:09 +08:00
Qiu Yuzhou 7a59ca7827 feat(proxy): add China IPv4 CIDR direct candidates to rule mode
Pin gaoyifan/china-operator-ip china.txt and compile its IPv4 CIDRs into
the proxy_all ACL alongside China domain candidates. Explicit maintainer
update normalizes and deduplicates CIDRs and blocks replacement on
abnormal format, corruption, scale change, or all-invalid input.

Closes #64
2026-09-26 18:16:44 +08:00
Qiu Yuzhou 827fb98be3 refactor(ng2): fix all swiftlint warnings
77 → 0 warnings. Split oversized functions and files: controller and
agent extension files, standalone RuleSet/ProxySettingsFileStore/
SslocalListenSettings/LegacyImportService, test classes into topic
extensions. Regroup activation options into RuntimeDocumentOptions and
converter metadata into Provenance.

Runtime controller DI seams widen private → internal so the extension
files stay cohesive; new controller files are registered in the
architecture guard exemption list; Agent target adds RuleSet and
SslocalListenSettings to project.yml. Test JSON literals wrap inside
the string literal only.
2026-09-26 17:13:31 +08:00
Qiu Yuzhou 120116627a feat(proxy): add built-in China domain rules and rule mode
Introduce a source-independent rule model (action, domain/CIDR match,
source identity, conflict metadata) and ship a pinned geolocation-cn
snapshot produced by an explicit maintainer update. Rule mode with
proxy-when-unmatched compiles China domains as direct candidates into a
proxy_all ACL; the sub-option is selectable and persisted from home and
the status menu. Ordinary builds only read the local snapshot and fail
when it is missing or corrupt.
2026-09-26 15:25:45 +08:00
Qiu Yuzhou f2e9cff69d feat(proxy): add ACL-backed global mode with local bypass
Global mode now deploys a minimal proxy_all ACL carrying only the fixed
local safety rules, so public targets default through Shadowsocks while
loopback/RFC1918/link-local/ULA/localhost/*.local/no-dot hosts stay
direct for SOCKS, HTTP, and LAN-sharing clients. System proxy exceptions
include that fixed scope; IPv6 system-exception limits are documented
with the ACL as the routing guarantee. Mode switches keep the
full-restart and rollback path.

Closes #62
2026-09-26 12:33:35 +08:00
Qiu Yuzhou 39e25477bb feat(proxy): add ACL-backed direct mode 2026-09-26 11:46:45 +08:00