feat(routing): 域名级系统锁冲突提示 + 重置默认按钮 + 客户端 follow-up 清理

承接 FT-A(GET /v1/me/routing 含只读 system_locked_domains)。

- RoutingProfile 加只读 systemLockedDomains(fromJson 读/toJson 不输出);
  routing_screen 冲突检测扩展到域名类规则(domain/domain_suffix/domain_keyword
  命中锁定域名 → systemLocked),ip_cidr 私网启发式保留。
- RoutingProfile.defaults() + RoutingProfileNotifier.resetToDefault()(复用
  _persist:乐观更新/失败回滚/存成功后自动重连,保留只读 systemLockedDomains
  不丢)+ routing_screen 加「重置默认」按钮与二次确认弹层(新增 3 个 l10n 键)。
- RoutingRule.copyWith 用哨兵支持 note 显式清空为 null;RoutingRule/Builtin/
  RoutingProfile 加值相等 operator==/hashCode。
- T8 smartRouteSub 清理:grep 全仓发现 design/prototype/i18n/alias.json →
  gen_proto_i18n.mjs(CI 漂移闸)仍有活引用,按计划口径不删,详见
  .superpowers/sdd/task-FTB-report.md。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-29 06:57:58 +08:00
parent 3159dd75c1
commit 2930d76cf3
14 changed files with 410 additions and 17 deletions
+80 -14
View File
@@ -7,13 +7,12 @@
// 冲突提示两类(prototype 里只是静态示例,这里落成真computed 逻辑):
// ①「已被上面规则覆盖」——同 type+value 的自定义规则被更靠前的规则遮蔽(纯本地计算,
// 首命中生效语义决定)。
// ②「系统强制走隧道,此规则不生效」——命中系统锁定目标。当前 RoutingProfile 契约
// 只下发 builtin 三个布尔开关,并未下发具体锁定域名清单(PANGOLIN_PRIVATE_SPLIT_DOMAINS
// 只在服务端 env,未经 API 暴露给客户端),故本屏对②采用保守启发式:仅当自定义规则
// 类型为 ip_cidr 且落在私网/回环地址段(RFC1918 + 127.0.0.0/8)时标记——这部分恒被
// 内置「局域网 / 私网直连」(builtin.lanDirect,强制不可关)接管,与用户规则动作冲突。
// 域名级私有服务分流(如 git.yanmeiai.com)不在此启发式覆盖范围,需服务端把锁定域名
// 清单下发给客户端后再补全(见 task-7-report.md 里的疑虑)。
// ②「系统强制走隧道,此规则不生效」——命中系统锁定目标,两类启发式并存:
// - ip_cidr 落在私网/回环地址段(RFC1918 + 127.0.0.0/8)——恒被内置「局域网 / 私网
// 直连」(builtin.lanDirect,强制不可关)接管。
// - 域名类规则(domain/domain_suffix/domain_keyword)命中 RoutingProfile.
// systemLockedDomains(FT-A 起 GET /v1/me/routing 下发的私有服务域名清单,
// PANGOLIN_PRIVATE_SPLIT_DOMAINS)——服务端渲染时恒强制走隧道,与用户规则动作冲突。
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@@ -139,8 +138,10 @@ class _RoutingBody extends ConsumerWidget {
onReorder: (oldIndex, newIndex) => notifier.reorder(oldIndex, newIndex),
children: [
for (var i = 0; i < profile.rules.length; i++)
_ruleRow(context, c, t, i, profile.rules[i],
_conflictFor(profile.rules, i), i < profile.rules.length - 1,
_ruleRow(
context, c, t, i, profile.rules[i],
_conflictFor(profile.rules, i, profile.systemLockedDomains),
i < profile.rules.length - 1,
onDelete: () => notifier.removeRule(i)),
],
),
@@ -172,10 +173,56 @@ class _RoutingBody extends ConsumerWidget {
]),
),
]),
const SizedBox(height: 20),
// ── 重置默认(桌面/移动共用同一按钮;二次确认防误触) ──
PangolinButton(
label: t.routingReset,
icon: PangolinIcons.refreshCw,
variant: PangolinButtonVariant.ghost,
expand: true,
onPressed: () => _confirmReset(context, ref, c, t),
),
],
);
}
Future<void> _confirmReset(BuildContext context, WidgetRef ref, PangolinScheme c, AppText t) async {
final ok = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: c.surface,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(PangolinRadius.xl)),
title: Row(children: [
Container(
width: 34, height: 34,
decoration: BoxDecoration(color: c.dangerSubtle, shape: BoxShape.circle),
child: Icon(PangolinIcons.refreshCw, size: 18, color: c.danger),
),
const SizedBox(width: 12),
Expanded(
child: Text(t.routingResetConfirmTitle,
overflow: TextOverflow.ellipsis,
style: PangolinText.body.copyWith(color: c.fg1, fontWeight: FontWeight.w700)),
),
]),
content: Text(t.routingResetConfirmBody, style: PangolinText.sm.copyWith(color: c.fg2, height: 1.5)),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: Text(t.devCancel, style: PangolinText.sm.copyWith(color: c.fg2, fontWeight: FontWeight.w600)),
),
TextButton(
onPressed: () => Navigator.pop(ctx, true),
child: Text(t.routingResetConfirmAction, style: PangolinText.sm.copyWith(color: c.danger, fontWeight: FontWeight.w700)),
),
],
),
);
if (ok != true) return;
await ref.read(routingProfileProvider.notifier).resetToDefault();
}
Future<void> _openAddDialog(BuildContext context, WidgetRef ref, AppText t) async {
final rule = await showDialog<RoutingRule>(context: context, builder: (_) => _AddRuleDialog(t: t));
if (rule == null) return;
@@ -291,9 +338,9 @@ class _RoutingBody extends ConsumerWidget {
/// 规则行冲突类型:先判系统锁定(与规则顺序无关),再判是否被更靠前的同规则遮蔽。
enum _RuleConflict { none, shadowed, systemLocked }
_RuleConflict _conflictFor(List<RoutingRule> rules, int i) {
_RuleConflict _conflictFor(List<RoutingRule> rules, int i, List<String> systemLockedDomains) {
final r = rules[i];
if (_looksSystemLocked(r)) return _RuleConflict.systemLocked;
if (_looksSystemLocked(r, systemLockedDomains)) return _RuleConflict.systemLocked;
for (var j = 0; j < i; j++) {
final o = rules[j];
if (o.type == r.type && o.value.trim().toLowerCase() == r.value.trim().toLowerCase()) {
@@ -303,10 +350,29 @@ _RuleConflict _conflictFor(List<RoutingRule> rules, int i) {
return _RuleConflict.none;
}
/// 私网/回环地址段启发式(RFC1918 + 127.0.0.0/8),见文件头注释——真正的系统锁定域名清单
/// 未经 API 下发,这里只覆盖 ip_cidr 类型且落在该地址段的情形。
/// 私网/回环地址段启发式(RFC1918 + 127.0.0.0/8),见文件头注释
final _privateIpPrefix = RegExp(r'^(10\.|192\.168\.|127\.|172\.(1[6-9]|2\d|3[01])\.)');
bool _looksSystemLocked(RoutingRule r) => r.type == 'ip_cidr' && _privateIpPrefix.hasMatch(r.value);
/// 系统锁定判定:ip_cidr 私网/回环启发式,或域名类规则命中 [systemLockedDomains]。
bool _looksSystemLocked(RoutingRule r, List<String> systemLockedDomains) {
if (r.type == 'ip_cidr') return _privateIpPrefix.hasMatch(r.value);
if (systemLockedDomains.isEmpty) return false;
final value = r.value.trim().toLowerCase();
if (value.isEmpty) return false;
switch (r.type) {
case 'domain':
return systemLockedDomains.any((d) => d.toLowerCase() == value);
case 'domain_suffix':
return systemLockedDomains.any((d) {
final dl = d.toLowerCase();
return dl == value || dl.endsWith('.$value');
});
case 'domain_keyword':
return systemLockedDomains.any((d) => d.toLowerCase().contains(value));
default:
return false;
}
}
String _routingTypeLabel(AppText t, String type) => switch (type) {
'domain' => t.routingTypeDomain,