Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ jobs:
timeout-minutes: 5
run: node scripts/workbench/e2e-deliveries.mjs

- name: Verify opt-in tracked Git inspection after repository packing
if: ${{ !cancelled() && steps.host_tests.outcome == 'success' }}
timeout-minutes: 5
run: node scripts/workbench/e2e-git-view.mjs

- name: Select the same installed Chrome for UI and worker
run: bash scripts/workbench/ci-select-chromium.sh

Expand Down
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ When memory is full, the next write by the model first consolidates the existing

## Headless server workbench (fork development)

The [amd64 Docker Compose workbench](apps/headless/README.md) supports browser enrollment, the original desktop model settings, and general text conversations with shared desktop UI, streaming, cancellation and reconnect. It also includes profile and role editing, avatar management, and notes scoped to the owner, a role, or a registered project. Manual workspaces and explicit chat attachments are separate: browsing a project does not send its files to a model. The workbench accepts supported UTF-8 text, static images and PDFs for compatible adapters. Confirmed replies can be exported as Markdown or plain text. Desktop delivery cards are reused for scoped downloads and project file reveal. An [optional human-operated browser](apps/browser-worker/README.md) uses a separate sandboxed worker and an explicit list of sites. The base app requires neither that worker nor a running desktop. This is separate from the mobile relay; see the [parity inventory](docs/development/web-workbench/README.md) for the remaining desktop workflows.
The [amd64 Docker Compose workbench](apps/headless/README.md) supports browser enrollment, the original desktop model settings, and general text conversations with shared desktop UI, streaming, cancellation and reconnect. It also includes profile and role editing, avatar management, and notes scoped to the owner, a role, or a registered project. Manual workspaces and explicit chat attachments are separate: browsing a project does not send its files to a model. Separately approved projects also have a manually activated Git view for tracked changes, branches, first-parent history and staged versus working-tree comparisons. The workbench accepts supported UTF-8 text, static images and PDFs for compatible adapters. Confirmed replies can be exported as Markdown or plain text. Desktop delivery cards are reused for scoped downloads and project file reveal. An [optional human-operated browser](apps/browser-worker/README.md) uses a separate sandboxed worker and an explicit list of sites. The base app requires neither that worker nor a running desktop. This is separate from the mobile relay; see the [parity inventory](docs/development/web-workbench/README.md) for the remaining desktop workflows.

## Build from Source

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ IM 机器人支持 `/new [角色名]`、`/list`、`/stop`、`/status`、`/help`

## 无 GUI 服务器工作台(本分支开发中)

[amd64 Docker Compose 与 Web 工作台说明](apps/headless/README.md):当前可在浏览器认领服务器、配置模型,并使用桌面同源的会话列表、编辑器及消息区进行通用文本对话;支持停止与刷新续接。网页还可以编辑个人资料、普通角色及其头像,并分别管理全局、角色和已授权项目的记忆。可手动浏览获准项目的文件,也可显式把所选文本、静态图片或兼容协议的 PDF 作为会话附件发送;浏览项目不会自动上传。已确认的回复可导出为 Markdown 或纯文本;桌面交付卡复用于 Web,支持按授权项目下载文件和定位。还可配置[独立人工浏览器面板](apps/browser-worker/README.md),由当前登录者接管已登记站点;实际工作器须通过 Chromium 沙箱就绪检查。它和手机版中转是两个不同部署目标;完整业务进度见[对等清单](docs/development/web-workbench/README.md)。
[amd64 Docker Compose 与 Web 工作台说明](apps/headless/README.md):当前可在浏览器认领服务器、配置模型,并使用桌面同源的会话列表、编辑器及消息区进行通用文本对话;支持停止与刷新续接。网页还可以编辑个人资料、普通角色及其头像,并分别管理全局、角色和已授权项目的记忆。可手动浏览获准项目的文件,也可显式把所选文本、静态图片或兼容协议的 PDF 作为会话附件发送;浏览项目不会自动上传。管理员另外批准的仓库可手动查看已跟踪文件的改动、分支、首父提交历史,以及暂存和工作树的差异。已确认的回复可导出为 Markdown 或纯文本;桌面交付卡复用于 Web,支持按授权项目下载文件和定位。还可配置[独立人工浏览器面板](apps/browser-worker/README.md),由当前登录者接管已登记站点;实际工作器须通过 Chromium 沙箱就绪检查。它和手机版中转是两个不同部署目标;完整业务进度见[对等清单](docs/development/web-workbench/README.md)。

## 从源码构建

Expand Down
18 changes: 18 additions & 0 deletions apps/desktop/src/renderer/src/redesign/GitBranchPill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { forwardRef, type ComponentPropsWithoutRef, type ReactNode } from 'react'
import { GitBranch } from 'lucide-react'

type GitBranchPillProps = ComponentPropsWithoutRef<'button'> & {
label: string; mergeLabel?: string; busy?: boolean; children?: ReactNode
}

/** The desktop branch chip, without workspace access or Git behavior. */
export const GitBranchPill = forwardRef<HTMLButtonElement, GitBranchPillProps>(function GitBranchPill(
{ label, mergeLabel, busy, className, children, ...button }, ref
) {
return <button {...button} type="button" ref={ref} className={`cf-gitchip${busy ? ' is-busy' : ''}${className ? ` ${className}` : ''}`}>
<GitBranch size={13} aria-hidden="true" />
<span className="cf-gitchip__branch" title={label}>{label}</span>
{mergeLabel && <span className="cf-gitchip__merge">{mergeLabel}</span>}
{children}
</button>
})
15 changes: 6 additions & 9 deletions apps/desktop/src/renderer/src/redesign/GitWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { useToast, type ToastOptions } from '../components/ToastProvider'
import { Modal } from '../components/Modal'
import { basename } from './shell-common'
import { type CtxEntry, ContextMenu } from './ContextMenu'
import { GitBranchPill } from './GitBranchPill'

/* ─────────────────────────── Git 快捷面板(IDEA 式点击浮出) ───────────────────────────
* 挂载工作区若是 git 仓库,则在挂载 chip 里跟一枚分支 pill,点击浮出常用操作。
Expand Down Expand Up @@ -455,20 +456,16 @@ export function GitWidget({ root, streaming }: { root: string; streaming: boolea

return (
<>
<button
<GitBranchPill
ref={pillRef}
type="button"
className={`cf-gitchip${opBusy || busy ? ' is-busy' : ''}`}
label={label}
mergeLabel={status.mergeInProgress ? t('cf.git.merging') : undefined}
busy={opBusy || busy}
title={t('cf.git.menuHint')}
aria-label={t('cf.git.menuHint')}
onClick={() => void openMenu()}
disabled={opBusy}
>
<GitBranch size={13} />
<span className="cf-gitchip__branch" title={label}>
{label}
</span>
{status.mergeInProgress && <span className="cf-gitchip__merge">{t('cf.git.merging')}</span>}
{(status.ahead > 0 || status.behind > 0) && (
<span className="cf-gitchip__ab">
{status.ahead > 0 && (
Expand All @@ -485,7 +482,7 @@ export function GitWidget({ root, streaming }: { root: string; streaming: boolea
)}
</span>
)}
</button>
</GitBranchPill>
{menu && (
<ContextMenu
x={menu.x}
Expand Down
152 changes: 152 additions & 0 deletions apps/desktop/src/workbench/git-view-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { HttpFailure } from './transport'
import type { WorkspaceFiles, WorkspaceFilesView } from './workspace-files'
import { GIT_LOG_MAX, GIT_LOG_STEP, type GitBranches, type GitDiff, type GitDiffRequest, type GitLog,
type GitRepoState, type GitSide, type GitStatus, type GitViewTransport } from './git-view-transport'

type Tab = 'changes' | 'branches' | 'history'
type Action = 'status' | 'branches' | 'log' | 'diff'
export type GitIssue = 'auth' | 'origin' | 'csrf' | 'not_granted' | 'workspace_unavailable' | 'unsafe' |
'stale' | 'busy' | 'budget' | 'unsupported_layout' | 'incomplete' | 'unavailable' | 'failure'
type Block = 'auth' | 'origin' | 'csrf' | 'not_granted' | 'workspace_unavailable' | 'unsafe'
export type GitViewState = {
workspaceId?: string; open: boolean; tab: Tab; pending?: Action; issue?: GitIssue; stale?: boolean;
status?: GitStatus; branches?: GitBranches; log?: GitLog; limit: number;
selection?: GitDiffRequest; diff?: GitDiff
}

function classify(error: unknown, action: Action): GitIssue {
if (!(error instanceof HttpFailure)) return 'failure'
if (error.status === 401) return 'auth'
if (error.status === 403) {
if (error.code === 'origin') return 'origin'
if (error.code === 'git_not_granted') return 'not_granted'
if (error.code === 'git_unsafe') return 'unsafe'
return error.code === 'csrf_failed' ? 'csrf' : 'not_granted'
}
if (error.status === 404 || error.status === 410) return 'workspace_unavailable'
if (error.status === 409) return error.code === 'git_stale' || (action === 'diff' && !error.code) ? 'stale' : 'busy'
if (error.status === 413 || error.status === 429 || error.code === 'git_timeout') return 'budget'
if (error.code === 'unsupported_git_layout') return 'unsupported_layout'
if (error.status === 422) return 'incomplete'
if (error.status === 503) return 'unavailable'
return 'failure'
}
function blocked(issue: GitIssue): issue is Block {
return issue === 'auth' || issue === 'origin' || issue === 'csrf' || issue === 'not_granted' || issue === 'workspace_unavailable' || issue === 'unsafe'
}
function baseline(workspaceId?: string, open = false): GitViewState {
return { workspaceId, open, tab: 'changes', limit: GIT_LOG_STEP }
}
export function hasGitData(state?: GitRepoState): boolean { return state === 'ready' || state === 'partial' }

/** The only roots of requests are explicit actions. Changes in workspace/visibility only cancel and clear. */
export function createWorkspaceGitView(api: GitViewTransport, onExpired: () => void) {
let view = baseline()
let active: AbortController | undefined
let block: Block | undefined
const listeners = new Set<() => void>()
function publish(next: GitViewState): void {
view = next
listeners.forEach((listener) => listener())
}
function cancel(): void {
const previous = active
active = undefined
previous?.abort()
}
function selectWorkspace(workspaceId?: string): void {
if (workspaceId === view.workspaceId) return
cancel()
block = undefined
publish(baseline(workspaceId))
}
function dismiss(): void {
cancel()
publish(baseline(view.workspaceId))
}
async function run<T>(action: Action, next: GitViewState,
request: (id: string, signal: AbortSignal) => Promise<T>, complete: (data: T) => Partial<GitViewState>): Promise<void> {
const id = view.workspaceId
if (!id || block) return
cancel()
const ticket = new AbortController()
active = ticket
publish({ ...next, pending: action, issue: undefined })
if (active !== ticket) return
try {
const data = await request(id, ticket.signal)
if (active !== ticket) return
const patch = complete(data)
active = undefined
publish({ ...view, ...patch, pending: undefined })
} catch (error) {
if (active !== ticket) return
active = undefined
const issue = classify(error, action)
if (blocked(issue)) {
block = issue
publish({ ...baseline(id, true), issue })
if (issue === 'auth') onExpired()
} else if (issue === 'stale') {
publish({ ...view, status: view.status && { ...view.status, viewId: null }, pending: undefined, issue, stale: true })
} else {
publish({ ...view, pending: undefined, issue })
}
}
}
function refresh(): Promise<void> | undefined {
if (!view.open || view.pending === 'status') return
return run('status', baseline(view.workspaceId, true), api.status, (status) => ({ status }))
}
function open(): Promise<void> | undefined {
if (!view.workspaceId || view.open) return
if (block) { publish({ ...baseline(view.workspaceId, true), issue: block }); return }
return run('status', baseline(view.workspaceId, true), api.status, (status) => ({ status }))
}
function canInspect(): boolean { return view.open && hasGitData(view.status?.state) && !view.stale && !block }
function changes(): void {
if (!canInspect() || view.tab === 'changes') return
cancel()
publish({ ...view, tab: 'changes', branches: undefined, log: undefined, pending: undefined, issue: undefined })
}
function branches(): Promise<void> | undefined {
if (!canInspect() || view.pending === 'branches') return
return run('branches', { ...view, tab: 'branches', branches: undefined, log: undefined, selection: undefined, diff: undefined },
api.branches, (branches) => ({ branches }))
}
function history(more = false): Promise<void> | undefined {
if (!canInspect() || view.pending === 'log' || (more && (view.tab !== 'history' || !view.log?.more || view.limit >= GIT_LOG_MAX))) return
const limit = more ? Math.min(view.limit + GIT_LOG_STEP, GIT_LOG_MAX) : GIT_LOG_STEP
return run('log', { ...view, tab: 'history', branches: undefined, log: more ? view.log : undefined, limit: more ? view.limit : limit,
selection: undefined, diff: undefined }, (id, signal) => api.log(id, limit, signal), (log) => ({ log, limit }))
}
function diff(entryId: string, side: GitSide): Promise<void> | undefined {
const viewId = view.status?.viewId
const entry = view.status?.entries.find((item) => item.entryId === entryId)
if (!canInspect() || view.tab !== 'changes' || !viewId || !entry?.diffSides.includes(side) ||
(view.pending === 'diff' && view.selection?.entryId === entryId && view.selection.side === side)) return
const selection = { viewId, entryId, side }
return run('diff', { ...view, selection, diff: undefined }, (id, signal) => api.diff(id, selection, signal), (diff) => {
if (diff.rel !== entry.rel || diff.side !== side) throw new Error('Unexpected Git diff projection')
return { diff }
})
}
return {
snapshot: () => view,
subscribe(notify: () => void): () => void { listeners.add(notify); return () => { listeners.delete(notify) } },
selectWorkspace, open, dismiss, refresh, changes, branches, history, diff
}
}
export type WorkspaceGitView = ReturnType<typeof createWorkspaceGitView>

export function authorizedWorkspaceId(view: WorkspaceFilesView): string | undefined {
return !view.issue && view.projects.data?.some((project) => project.id === view.projectId) ? view.projectId : undefined
}

/** Subscribe to the selector itself so a change (including delivery reveal) aborts immediately. */
export function bindWorkspaceGitView(git: WorkspaceGitView, files: WorkspaceFiles): () => void {
const sync = (): void => git.selectWorkspace(authorizedWorkspaceId(files.snapshot()))
const unsubscribe = files.subscribe(sync)
sync()
return () => { unsubscribe(); git.selectWorkspace(undefined) }
}
Loading
Loading