feat(ios,android): P2 wave, git panel, token UX, per-host WS token, docs
App layer, four sequential slices (a shared .xcodeproj means adding files regenerates it, so these could not run in parallel): - token UX end to end: pairing prompts for a token when a host 401s, POST /auth validates it, and 204-without-Set-Cookie is correctly read as "this server has auth disabled" rather than "authenticated". A host paired before the token was turned on recovers by re-pairing in place. Remove-host now exists and finally gives PushRegistrar.handleHostRemoved a caller. - project git panel + worktree lifecycle (T-iOS-32) + claude --resume history — the parity gap with Android and the web front end. - terminal search (T-iOS-33) and voice PTT (T-iOS-31) with an epoch guard so a session switch between dictation and confirm cannot inject into the wrong session. - theme + Dynamic Type (T-iOS-34) and web ?join= interop (T-iOS-35). RootView no longer hard-locks .preferredColorScheme(.dark). Also unpins SwiftTerm to 1.15.0 by dropping the local hasActiveSelection that collided with the upstream one, verified green from a fresh derivedDataPath. Includes the two HIGH fixes the security review found: - iOS resolved the WS token host-independently, so a token-gated host sitting next to an open one could never open a terminal and no on-screen remedy could fix it. Now one transport per host; cross-host leakage is structurally impossible since both read paths return only that host's own value. - Android reported the host's own git-credential 401 (git-ops.ts:108, "Push authentication required on the host.") as "your access token is wrong", because a blanket 401 mapping ran ahead of the per-route one. Git-write routes are now ROUTE_DEFINED and keep the server's message. And the doc sync: README/ios README no longer claim the client is unmerged on feat/ios-client, the Clients section finally lists Android, and the plan checkboxes reflect what is actually built. iOS 534 app tests + 452 package tests; Android 687 tests.
This commit is contained in:
@@ -5,6 +5,14 @@ import WireProtocol
|
||||
/// T-iOS-26 · 项目详情屏:sessions/worktrees/CLAUDE.md 渲染 + diff 入口
|
||||
/// (T-iOS-27 的 `DiffScreen(endpoint:path:http:)`)+ "在此仓库开新会话"。
|
||||
///
|
||||
/// C2 增量(与 web v0.6 / Android 对齐):
|
||||
/// - 头部**环境同步态**(`GitSyncBand`:↑↓ / 无上游 / 分离 HEAD / 脏度),不用敲
|
||||
/// git 命令就能看到"有没有没推的提交";
|
||||
/// - **Git 面板**入口(stage/commit/push/fetch + `git log` + PR/CI);
|
||||
/// - **worktree 生命周期**(T-iOS-32):新建 / 回收失效 / 删除(两级确认),
|
||||
/// 取代原先只读的列表;
|
||||
/// - **`claude --resume` 历史**:挑一条过去的会话在本仓库里接着跑。
|
||||
///
|
||||
/// 安全:名字/路径/分支/CLAUDE.md 内容全是**不可信服务器字节** ——
|
||||
/// 一律 `Text(verbatim:)`(绝不 LocalizedStringKey/Markdown/链接探测)。
|
||||
struct ProjectDetailScreen: View {
|
||||
@@ -12,7 +20,30 @@ struct ProjectDetailScreen: View {
|
||||
private let endpoint: HostEndpoint
|
||||
private let http: any HTTPTransport
|
||||
private let onOpenClaude: (String) -> Void
|
||||
@State private var isDiffPresented = false
|
||||
private let onResumeClaude: (String, String) -> Void
|
||||
|
||||
/// 详情屏级别的 worktree 状态机:只负责 prune / remove(create 归 sheet 自己的
|
||||
/// 实例,两个状态机互不干扰)。
|
||||
@State private var worktreeActions: WorktreeViewModel
|
||||
@State private var route: DetailRoute?
|
||||
@State private var sheet: DetailSheet?
|
||||
@State private var worktreePendingRemoval: WorktreeInfo?
|
||||
@State private var isPruneConfirmPresented = false
|
||||
|
||||
/// 推入式子屏(单一 destination,避免多个 `isPresented:` 目的地互相打断)。
|
||||
private enum DetailRoute: Hashable, Identifiable {
|
||||
case diff
|
||||
case gitPanel
|
||||
|
||||
var id: Self { self }
|
||||
}
|
||||
|
||||
private enum DetailSheet: Hashable, Identifiable {
|
||||
case newWorktree
|
||||
case resumeHistory
|
||||
|
||||
var id: Self { self }
|
||||
}
|
||||
|
||||
private enum Metrics {
|
||||
/// CLAUDE.md 预览行数上限(内容裁剪,非视觉 token)。
|
||||
@@ -23,12 +54,17 @@ struct ProjectDetailScreen: View {
|
||||
viewModel: ProjectDetailViewModel,
|
||||
endpoint: HostEndpoint,
|
||||
http: any HTTPTransport,
|
||||
onOpenClaude: @escaping (String) -> Void
|
||||
onOpenClaude: @escaping (String) -> Void,
|
||||
onResumeClaude: @escaping (String, String) -> Void
|
||||
) {
|
||||
_viewModel = State(initialValue: viewModel)
|
||||
self.endpoint = endpoint
|
||||
self.http = http
|
||||
self.onOpenClaude = onOpenClaude
|
||||
self.onResumeClaude = onResumeClaude
|
||||
_worktreeActions = State(initialValue: .forProject(
|
||||
endpoint: endpoint, http: http, path: viewModel.path
|
||||
))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -36,14 +72,118 @@ struct ProjectDetailScreen: View {
|
||||
.navigationTitle(ProjectDetailCopy.title)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.task { await viewModel.load() }
|
||||
.navigationDestination(isPresented: $isDiffPresented) {
|
||||
DiffScreen(endpoint: endpoint, path: viewModel.path, http: http)
|
||||
.navigationDestination(item: $route) { destination(for: $0) }
|
||||
.sheet(item: $sheet) { presentedSheet(for: $0) }
|
||||
}
|
||||
|
||||
/// 破坏性 worktree 操作的确认层:prune 一道、remove 两道(第二道只在服务器
|
||||
/// 回 409「有未提交改动」时才出现)。挂在 `content` 上而不是 `body` 上,
|
||||
/// 是为了让 `body` 保持可读。
|
||||
@ViewBuilder private var content: some View {
|
||||
phaseContent
|
||||
.confirmationDialog(
|
||||
WorktreeCopy.pruneConfirmTitle,
|
||||
isPresented: $isPruneConfirmPresented,
|
||||
titleVisibility: .visible
|
||||
) {
|
||||
Button(WorktreeCopy.pruneConfirm, role: .destructive) {
|
||||
Task {
|
||||
await worktreeActions.prune()
|
||||
await viewModel.load()
|
||||
}
|
||||
}
|
||||
} message: {
|
||||
Text(WorktreeCopy.pruneConfirmMessage)
|
||||
}
|
||||
.confirmationDialog(
|
||||
WorktreeCopy.removeConfirmTitle,
|
||||
isPresented: removalDialogBinding,
|
||||
titleVisibility: .visible,
|
||||
presenting: worktreePendingRemoval
|
||||
) { worktree in
|
||||
Button(WorktreeCopy.removeConfirm, role: .destructive) {
|
||||
remove(worktree)
|
||||
}
|
||||
} message: { worktree in
|
||||
Text(verbatim: WorktreeCopy.removeConfirmMessage(worktree.path))
|
||||
}
|
||||
.confirmationDialog(
|
||||
WorktreeCopy.forceConfirmTitle,
|
||||
isPresented: forceDialogBinding,
|
||||
titleVisibility: .visible
|
||||
) {
|
||||
// 409(脏工作树)后的**第二次**确认 —— 绝无单击数据丢失。
|
||||
Button(WorktreeCopy.forceConfirm, role: .destructive) {
|
||||
Task {
|
||||
await worktreeActions.confirmForceRemove()
|
||||
await viewModel.load()
|
||||
}
|
||||
}
|
||||
Button(WorktreeCopy.cancel, role: .cancel) {
|
||||
worktreeActions.cancelForceRemove()
|
||||
}
|
||||
} message: {
|
||||
Text(WorktreeCopy.forceConfirmMessage)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func destination(for route: DetailRoute) -> some View {
|
||||
switch route {
|
||||
case .diff:
|
||||
DiffScreen(endpoint: endpoint, path: viewModel.path, http: http)
|
||||
case .gitPanel:
|
||||
GitPanelScreen(endpoint: endpoint, http: http, path: viewModel.path)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func presentedSheet(for sheet: DetailSheet) -> some View {
|
||||
switch sheet {
|
||||
case .newWorktree:
|
||||
WorktreeSheet(
|
||||
viewModel: .forProject(endpoint: endpoint, http: http, path: viewModel.path),
|
||||
onCreated: { Task { await viewModel.load() } },
|
||||
onOpenSession: onOpenClaude
|
||||
)
|
||||
case .resumeHistory:
|
||||
ResumeHistorySheet(
|
||||
viewModel: .forProject(endpoint: endpoint, http: http, path: viewModel.path),
|
||||
onResume: onResumeClaude
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// 仅当某个 worktree 被暂存待删时呈现;关闭即清除暂存。
|
||||
private var removalDialogBinding: Binding<Bool> {
|
||||
Binding(
|
||||
get: { worktreePendingRemoval != nil },
|
||||
set: { presented in if !presented { worktreePendingRemoval = nil } }
|
||||
)
|
||||
}
|
||||
|
||||
/// 409 → 二次确认。关闭(含滑走)等于取消,绝不残留在待 force 态。
|
||||
private var forceDialogBinding: Binding<Bool> {
|
||||
Binding(
|
||||
get: {
|
||||
if case .forceConfirming = worktreeActions.removePhase { return true }
|
||||
return false
|
||||
},
|
||||
set: { presented in if !presented { worktreeActions.cancelForceRemove() } }
|
||||
)
|
||||
}
|
||||
|
||||
private func remove(_ worktree: WorktreeInfo) {
|
||||
Task {
|
||||
await worktreeActions.remove(worktreePath: worktree.path)
|
||||
if case .removed = worktreeActions.removePhase {
|
||||
DS.Haptics.warning()
|
||||
await viewModel.load()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Phase switch
|
||||
|
||||
@ViewBuilder private var content: some View {
|
||||
@ViewBuilder private var phaseContent: some View {
|
||||
switch viewModel.phase {
|
||||
case .loading:
|
||||
ProgressView()
|
||||
@@ -93,8 +233,8 @@ struct ProjectDetailScreen: View {
|
||||
List {
|
||||
headerSection(detail)
|
||||
actionsSection(detail)
|
||||
sessionsSection(detail.sessions)
|
||||
worktreesSection(detail.worktrees)
|
||||
sessionsSection(detail)
|
||||
worktreesSection(detail)
|
||||
claudeMdSection(detail)
|
||||
}
|
||||
.listStyle(.insetGrouped)
|
||||
@@ -127,6 +267,13 @@ struct ProjectDetailScreen: View {
|
||||
DirtyBadge()
|
||||
}
|
||||
}
|
||||
// 环境同步态(w6/G3):不敲 git 命令就知道有没有没推的提交。
|
||||
if let band = GitSyncBand.make(
|
||||
sync: detail.sync, dirtyCount: detail.dirtyCount,
|
||||
nowMs: Date().timeIntervalSince1970 * 1_000
|
||||
) {
|
||||
SyncSummaryChips(band: band)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,32 +293,53 @@ struct ProjectDetailScreen: View {
|
||||
))
|
||||
.listRowBackground(Color.clear)
|
||||
if detail.isGit {
|
||||
Button {
|
||||
isDiffPresented = true
|
||||
} label: {
|
||||
Label(ProjectDetailCopy.viewDiff, systemImage: "plus.forwardslash.minus")
|
||||
secondaryAction(GitPanelCopy.entryLabel, symbol: "point.3.filled.connected.trianglepath.dotted") {
|
||||
route = .gitPanel
|
||||
}
|
||||
secondaryAction(ProjectDetailCopy.viewDiff, symbol: "plus.forwardslash.minus") {
|
||||
route = .diff
|
||||
}
|
||||
.buttonStyle(DSButtonStyle(kind: .secondary))
|
||||
.listRowInsets(EdgeInsets(
|
||||
top: DS.Space.xs4, leading: DS.Space.lg16,
|
||||
bottom: DS.Space.sm8, trailing: DS.Space.lg16
|
||||
))
|
||||
.listRowBackground(Color.clear)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func sessionsSection(_ sessions: [ProjectSessionRef]) -> some View {
|
||||
private func secondaryAction(
|
||||
_ title: String, symbol: String, action: @escaping () -> Void
|
||||
) -> some View {
|
||||
Button(action: action) {
|
||||
Label(title, systemImage: symbol)
|
||||
}
|
||||
.buttonStyle(DSButtonStyle(kind: .secondary))
|
||||
.listRowInsets(EdgeInsets(
|
||||
top: DS.Space.xs4, leading: DS.Space.lg16,
|
||||
bottom: DS.Space.xs4, trailing: DS.Space.lg16
|
||||
))
|
||||
.listRowBackground(Color.clear)
|
||||
}
|
||||
|
||||
@ViewBuilder private func sessionsSection(_ detail: ProjectDetail) -> some View {
|
||||
Section(ProjectDetailCopy.sessionsHeader) {
|
||||
if sessions.isEmpty {
|
||||
if detail.sessions.isEmpty {
|
||||
Text(ProjectDetailCopy.noSessions)
|
||||
.font(DS.Typography.caption)
|
||||
.foregroundStyle(DS.Palette.textSecondary)
|
||||
} else {
|
||||
ForEach(sessions, id: \.id) { session in
|
||||
ForEach(detail.sessions, id: \.id) { session in
|
||||
sessionRow(session)
|
||||
}
|
||||
}
|
||||
// `claude --resume <id>`:挑一条历史会话在本仓库接着跑(T-iOS-32)。
|
||||
Button {
|
||||
sheet = .resumeHistory
|
||||
} label: {
|
||||
Label(ResumeCopy.entryLabel, systemImage: "clock.arrow.circlepath")
|
||||
}
|
||||
.buttonStyle(DSButtonStyle(kind: .secondary))
|
||||
.listRowInsets(EdgeInsets(
|
||||
top: DS.Space.xs4, leading: DS.Space.lg16,
|
||||
bottom: DS.Space.xs4, trailing: DS.Space.lg16
|
||||
))
|
||||
.listRowBackground(Color.clear)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,16 +367,75 @@ struct ProjectDetailScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func worktreesSection(_ worktrees: [WorktreeInfo]) -> some View {
|
||||
if !worktrees.isEmpty {
|
||||
Section(ProjectDetailCopy.worktreesHeader) {
|
||||
ForEach(worktrees, id: \.path) { worktree in
|
||||
// MARK: - Worktrees(T-iOS-32:读 + 建 + 回收 + 删)
|
||||
|
||||
/// git 仓库一律显示本区(哪怕只有一个 worktree)—— 标题固定,"空"不等于"没查"
|
||||
/// (w6/G5 的同一条纪律)。
|
||||
@ViewBuilder private func worktreesSection(_ detail: ProjectDetail) -> some View {
|
||||
if detail.isGit {
|
||||
Section {
|
||||
ForEach(detail.worktrees, id: \.path) { worktree in
|
||||
worktreeRow(worktree)
|
||||
}
|
||||
Button {
|
||||
sheet = .newWorktree
|
||||
} label: {
|
||||
Label(WorktreeCopy.sheetTitle, systemImage: "plus.rectangle.on.folder")
|
||||
}
|
||||
.buttonStyle(DSButtonStyle(kind: .secondary))
|
||||
.listRowInsets(EdgeInsets(
|
||||
top: DS.Space.xs4, leading: DS.Space.lg16,
|
||||
bottom: DS.Space.xs4, trailing: DS.Space.lg16
|
||||
))
|
||||
.listRowBackground(Color.clear)
|
||||
worktreeFeedback
|
||||
} header: {
|
||||
worktreeHeader(detail)
|
||||
} footer: {
|
||||
if detail.worktrees.contains(where: WorktreeViewModel.canRemove) {
|
||||
Text(ProjectDetailCopy.worktreeSwipeHint)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func worktreeHeader(_ detail: ProjectDetail) -> some View {
|
||||
HStack {
|
||||
Text(ProjectDetailCopy.worktreesHeader)
|
||||
Spacer(minLength: DS.Space.sm8)
|
||||
// 只有真的存在 prunable 登记项时才提供回收(不邀请无效动作)。
|
||||
if detail.worktrees.contains(where: { $0.prunable == true }) {
|
||||
Button(WorktreeCopy.pruneButton) {
|
||||
isPruneConfirmPresented = true
|
||||
}
|
||||
.font(DS.Typography.caption.weight(.semibold))
|
||||
.foregroundStyle(DS.Palette.accent)
|
||||
.frame(minHeight: DS.Layout.minHitTarget)
|
||||
.disabled(worktreeActions.isBusy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// prune / remove 的回执(服务器安全文案原样显示;成功也要说一声)。
|
||||
@ViewBuilder private var worktreeFeedback: some View {
|
||||
switch worktreeActions.prunePhase {
|
||||
case .done(let message):
|
||||
InlineMessage(text: message, tone: .success)
|
||||
case .failed(let message):
|
||||
InlineMessage(text: message, tone: .error)
|
||||
case .idle, .pruning:
|
||||
EmptyView()
|
||||
}
|
||||
switch worktreeActions.removePhase {
|
||||
case .removed(let path):
|
||||
InlineMessage(text: WorktreeCopy.removed(path), tone: .success)
|
||||
case .failed(let message):
|
||||
InlineMessage(text: message, tone: .error)
|
||||
case .idle, .removing, .forceConfirming:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
private func worktreeRow(_ worktree: WorktreeInfo) -> some View {
|
||||
VStack(alignment: .leading, spacing: DS.Space.xs4) {
|
||||
HStack(spacing: DS.Space.sm8) {
|
||||
@@ -225,12 +452,28 @@ struct ProjectDetailScreen: View {
|
||||
if worktree.locked == true {
|
||||
TagBadge(text: ProjectDetailCopy.worktreeLocked)
|
||||
}
|
||||
if worktree.prunable == true {
|
||||
TagBadge(text: ProjectDetailCopy.worktreePrunable)
|
||||
}
|
||||
}
|
||||
Text(verbatim: worktree.path)
|
||||
.font(DS.Typography.mono(.caption))
|
||||
.foregroundStyle(DS.Palette.textSecondary)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
if worktree.locked == true {
|
||||
Text(WorktreeCopy.lockedHint)
|
||||
.dsMetaText()
|
||||
}
|
||||
}
|
||||
.swipeActions(edge: .trailing) {
|
||||
// 主 worktree(仓库本体)与锁定的不给入口 —— 服务器必拒(400/409)。
|
||||
if WorktreeViewModel.canRemove(worktree) {
|
||||
Button(WorktreeCopy.removeButton, role: .destructive) {
|
||||
worktreePendingRemoval = worktree
|
||||
}
|
||||
.accessibilityLabel(WorktreeCopy.removeAccessibilityLabel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +511,7 @@ struct DirtyBadge: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// worktree 属性标签(主/当前/已锁定):accent 描边胶囊。
|
||||
/// worktree 属性标签(主/当前/已锁定/可回收):accent 描边胶囊。
|
||||
struct TagBadge: View {
|
||||
let text: String
|
||||
|
||||
@@ -297,6 +540,8 @@ enum ProjectDetailCopy {
|
||||
static let worktreeMain = "主"
|
||||
static let worktreeCurrent = "当前"
|
||||
static let worktreeLocked = "已锁定"
|
||||
static let worktreePrunable = "可回收"
|
||||
static let worktreeSwipeHint = "左滑一行可删除该 worktree(主 worktree 与已锁定的不可删)。"
|
||||
static let detachedHead = "(分离 HEAD)"
|
||||
static let claudeMdHeader = "CLAUDE.md"
|
||||
static let claudeMdPresent = "本仓库包含 CLAUDE.md。"
|
||||
|
||||
Reference in New Issue
Block a user