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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@ jobs:
if-no-files-found: error
retention-days: 14

- name: Verify owner read synchronization and the real context meter in two browsers
id: conversation_status_ui
if: ${{ !cancelled() && steps.host_tests.outcome == 'success' }}
timeout-minutes: 6
env:
DEVA_QA_STATUS_CAPTURE: '1'
run: node scripts/workbench/e2e-conversation-status.mjs

- name: Publish the verified synthetic read indicator and native context meter
if: ${{ !cancelled() && steps.conversation_status_ui.outcome == 'success' }}
uses: actions/upload-artifact@v4
with:
name: workbench-conversation-status
path: |
test-results/conversation-status/pr18-*/read-indicator.png
test-results/conversation-status/pr18-*/context-meter.png
if-no-files-found: error
retention-days: 14

- name: Select the same installed Chrome for UI and worker
if: ${{ !cancelled() && steps.host_tests.outcome == 'success' }}
id: handoff_chrome
Expand Down Expand Up @@ -379,6 +398,28 @@ jobs:
timeout-minutes: 3
run: node scripts/workbench/container-skill-library.mjs

packaged-conversation-status:
name: Conversation read marks and measured context across native amd64 containers
if: ${{ (github.event_name == 'pull_request' && github.head_ref == 'feat/web-workbench-conversation-status') || (github.event_name == 'workflow_dispatch' && github.ref_name == 'feat/web-workbench-conversation-status') }}
runs-on: ubuntu-latest
timeout-minutes: 16
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
package-manager-cache: false
- name: Build the production Linux amd64 runtime image
timeout-minutes: 9
run: |
set -eu
test "$(uname -m)" = x86_64
docker build --platform linux/amd64 --target runtime -t deva-workbench:conversation-status-verify .
docker image inspect -f '{{.Os}}/{{.Architecture}} {{.Id}} {{.Size}} bytes' deva-workbench:conversation-status-verify
- name: Verify exact native read state and token receipt across fresh containers
timeout-minutes: 5
run: node scripts/workbench/container-conversation-status.mjs

packaged-project-documents:
name: Exclusive project documents across native amd64 Compose modes
if: ${{ (github.event_name == 'pull_request' && github.head_ref == 'feat/web-workbench-project-documents') || (github.event_name == 'workflow_dispatch' && github.ref_name == 'feat/web-workbench-project-documents') }}
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ CMD ["serve"]
FROM ${NODE_IMAGE} AS runtime
WORKDIR /opt/deva
ENV NODE_ENV=production DEVA_HOME=/data DEVA_RUN_DIR=/run/deva DEVA_MASTER_KEY_FILE=/keys/master.key DEVA_WEB_DIR=/opt/deva/web DEVA_HOST=127.0.0.1 DEVA_PORT=8787
RUN test -x /usr/bin/flock && install -d -m 0700 -o node -g node /data /keys /run/deva /run/deva-browser-control /run/deva-pty-control
# The read marker's xattr check uses only inherited descriptors and a fixed local Perl syscall probe.
RUN test -x /usr/bin/flock && test -x /usr/bin/perl && install -d -m 0700 -o node -g node /data /keys /run/deva /run/deva-browser-control /run/deva-pty-control
COPY --from=build /src/apps/headless/package.json ./apps/headless/package.json
COPY --from=build /src/apps/desktop/package.json ./apps/desktop/package.json
COPY --from=build /src/apps/headless/src ./apps/headless/src
Expand Down
1 change: 1 addition & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ When memory is full, the next write by the model first consolidates the existing
The [amd64 Docker Compose workbench](apps/headless/README.md) runs independently of Electron, a remote desktop or the mobile relay, using the same React components as the desktop application.

- **Conversations:** claim the instance, configure models, stream, stop and reconnect. Use the desktop message menu to copy a selection or quote it in an unsent draft. Clipboard, sidebar shortcuts and page fullscreen belong to the client browser.
- **Conversation status:** read marks synchronize across the owner’s browser sessions only after the latest messages are visible in the foreground. The desktop context ring distinguishes provider-reported input tokens from a saved-history estimate.
- **Library and projects:** manage profiles, roles, avatars and scoped notes. A conversation can inherit or explicitly attach an approved project; reveal a file’s parent folder in the workspace tree. A separate opt-in allows owners to review and create new Markdown or plain-text documents without replacing an existing file. Browsing or creating a document does not send it to a model.
- **Skill settings:** inspect existing skills under Settings → Extensions and save their enabled preferences and role scopes. Opening a custom skill displays its document; web chat does not load or execute skills.
- **Read-only terminal:** an optional [network-isolated PTY worker](apps/terminal-worker/README.md) displays a confirmed, saved workspace text file in the original file panel. Navigation, resize and exit come from a real native process; this is not a host command shell.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ IM 机器人支持 `/new [角色名]`、`/list`、`/stop`、`/status`、`/help`
[amd64 Docker Compose 部署与使用](apps/headless/README.md)。这是独立的服务器工作台,复用桌面 React 界面;运行时无需 Electron、远程桌面或手机版中转。

- **对话**:在浏览器认领实例、配置模型,使用原会话列表和编辑器聊天、停止、刷新续接。选中文字可复制或加入当前草稿的引用条;剪贴板、侧栏快捷键和页面全屏都属于操作电脑。
- **会话状态**:未读标记在同一所有者的浏览器之间同步,只有前台显示到最新消息才确认已读。模型旁的原桌面圆环区分服务商返回的输入用量和根据历史得出的估算。
- **资料与项目**:管理个人资料、角色、头像和分域记忆。会话可继承或显式关联管理员登记的项目;文件页可定位当前文件夹。另行启用创建权限后,所有者可核对目标并新建 Markdown 或纯文本文档,同名文件保持原样。手动打开或创建文档不会将内容发送给模型。
- **技能设置**:在桌面同源的「设置 → 扩展」查看现有技能,保存启用偏好和角色范围。只有打开自定义条目才显示正文;Web 对话不会加载或运行这些技能。
- **只读终端**:可选的[无网络 PTY 工作器](apps/terminal-worker/README.md)在原文件面板中显示已保存的文本。翻页、调整行列、退出都由真实子进程响应;它不会提供宿主命令行。
Expand Down
45 changes: 4 additions & 41 deletions apps/desktop/src/main/services/compaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CompactStatus } from '../../shared/chat-protocol'
import { streamChat } from '../providers'
import type { ContentPart, Message } from '../providers/types'
import type { Message } from '../providers/types'
import { getConfig } from './config'
import { save as saveProject, type StoredSession } from './chat-store'
import { todoSnapshotText } from './todos'
Expand All @@ -15,12 +15,8 @@ import {
modelMessages,
modelRange
} from './model-view'
import {
DEFAULT_CONTEXT_WINDOW,
autoContextWindow,
autoOutputBudget,
estimateTextTokens
} from '../../shared/context'
import { DEFAULT_CONTEXT_WINDOW, autoContextWindow, autoOutputBudget } from '../../shared/context'
import { estimateTokens, messageTokens } from '../../shared/context-estimate'

/**
* 上下文压缩(主进程)。
Expand Down Expand Up @@ -179,41 +175,8 @@ export function triggerTokens(model: LimitModelRef, cfg: CompactionCfg = compact
return cfg.triggerRatio !== undefined ? Math.min(window * cfg.triggerRatio, byWindow) : byWindow
}

// ── token 估算(字符法,中日韩文字另计;图片/文档按固定成本,规避 base64 数长度失真)──────
const CHARS_PER_TOKEN = 3.5
const IMAGE_TOKENS = 1600
const DOC_TOKENS = 3000

function partTokens(p: ContentPart): number {
switch (p.type) {
case 'text':
return estimateTextTokens(p.text)
case 'tool_use':
return estimateTextTokens(JSON.stringify(p.input ?? {})) + 8
case 'tool_result':
return estimateTextTokens(p.content) + 8 + (p.images?.length ?? 0) * IMAGE_TOKENS
case 'image':
return IMAGE_TOKENS
case 'document':
return DOC_TOKENS
default:
return 0
}
}

function messageTokens(m: Message): number {
if (typeof m.content === 'string') return estimateTextTokens(m.content) + 4
let t = 4
for (const p of m.content) t += partTokens(p)
return t
}

/** 全历史 token 估算(触发判定的字符法回退)。 */
export function estimateTokens(messages: Message[]): number {
let t = 0
for (const m of messages) t += messageTokens(m)
return Math.round(t)
}
export { estimateTokens } from '../../shared/context-estimate'

/** 是否需要压缩:优先真实 usage.input,回退字符估算(只算模型看到的部分),与压缩线(见 triggerTokens)比较。 */
export function needsCompaction(
Expand Down
11 changes: 9 additions & 2 deletions apps/desktop/src/renderer/src/redesign/ContextRing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 卡片优先以圆环为中心弹出;超出窗口时往里挪,左右各留 8px。
* 没有读数(新对话、模型已删)时由 ModelPanel 整个不渲染。
*/
import { useLayoutEffect, useRef, useState } from 'react'
import { useLayoutEffect, useRef, useState, type ReactNode } from 'react'
import type { ContextUsage } from '../../../preload'
import { formatTokens } from '../../../shared/context'
import { useI18n } from '../i18n/i18n'
Expand All @@ -26,11 +26,15 @@ function usageText(t: T, u: ContextUsage): string {
export function ContextRing({
usage,
open,
onToggle
onToggle,
cardId,
details
}: {
usage: ContextUsage
open: boolean
onToggle: () => void
cardId?: string
details?: ReactNode
}): React.JSX.Element {
const { t } = useI18n()
const text = usageText(t, usage)
Expand Down Expand Up @@ -62,6 +66,7 @@ export function ContextRing({
aria-label={title}
aria-haspopup="dialog"
aria-expanded={open}
aria-controls={open ? cardId : undefined}
onClick={onToggle}
>
<Ring ratio={usageRatio(usage)} />
Expand All @@ -70,6 +75,7 @@ export function ContextRing({
<div
ref={cardRef}
className="cf-mp__card"
id={cardId}
role="dialog"
aria-label={t('chat.panel.context')}
style={{ transform: `translateX(calc(-50% + ${shift}px))` }}
Expand All @@ -88,6 +94,7 @@ export function ContextRing({
/>
)}
</div>
{details}
</div>
)}
</div>
Expand Down
37 changes: 37 additions & 0 deletions apps/desktop/src/shared/context-estimate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { ContentPart, Message } from '../main/providers/types'
import { estimateTextTokens } from './context'

// Media estimates count model-visible parts, not their wire encoding.
const IMAGE_TOKENS = 1600
const DOC_TOKENS = 3000

function partTokens(p: ContentPart): number {
switch (p.type) {
case 'text':
return estimateTextTokens(p.text)
case 'tool_use':
return estimateTextTokens(JSON.stringify(p.input ?? {})) + 8
case 'tool_result':
return estimateTextTokens(p.content) + 8 + (p.images?.length ?? 0) * IMAGE_TOKENS
case 'image':
return IMAGE_TOKENS
case 'document':
return DOC_TOKENS
default:
return 0
}
}

export function messageTokens(m: Message): number {
if (typeof m.content === 'string') return estimateTextTokens(m.content) + 4
let t = 4
for (const p of m.content) t += partTokens(p)
return t
}

/** Character-based fallback for a model-visible message sequence. */
export function estimateTokens(messages: Message[]): number {
let t = 0
for (const m of messages) t += messageTokens(m)
return Math.round(t)
}
7 changes: 5 additions & 2 deletions apps/desktop/src/workbench/chat-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ export function applyChatFrame(current: ChatSnapshot | undefined, frame: ChatFra
if (next.seq !== cursor.seq + 1) return null
const { turnId, event } = frame
if (['turn_start', 'done', 'error', 'stream_reset'].includes(event.type)) return null
if (event.type !== 'text_delta') return { state, cursor: next } // No desktop-only features are projected into the text view.
if (event.type === 'context_changed' && state.active?.turnId === turnId) {
return { ...current, cursor: next, contextVersion: next.seq }
}
if (event.type !== 'text_delta') return { ...current, cursor: next } // Desktop-only payloads stay outside this projection.
if (!state.active || state.active.turnId !== turnId || event.text === undefined) return null
return { cursor: next, state: { ...state, active: { ...state.active, text: state.active.text + event.text } } }
return { ...current, cursor: next, state: { ...state, active: { ...state.active, text: state.active.text + event.text } } }
}

export type ChatLink = 'loading' | 'ready' | 'reconnecting' | 'missing' | 'expired'
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/workbench/chat-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface ChatState extends Omit<ChatSummary, 'updatedAt'> {
lastTurn: ChatTurn | null
}
export interface ChatCursor { epoch: string; scope: string; seq: number; generation: string }
export interface ChatSnapshot { cursor: ChatCursor; state: ChatState }
export interface ChatSnapshot { cursor: ChatCursor; state: ChatState; contextVersion?: number }
export type ChatFrame = ({ t: 'snapshot' } & ChatSnapshot) | {
t: 'event'; cursor: ChatCursor; sessionId: string; turnId: string; type: 'chat'; event: { type: string; text?: string }
}
Expand Down Expand Up @@ -123,7 +123,7 @@ export function parseChatFrame(data: unknown, sid: string): ChatFrame | null {
const { type, text } = value.event
if (type === 'text_delta' && typeof text !== 'string') return null
return { t: 'event', type: 'chat', cursor: value.cursor, sessionId: sid, turnId: value.turnId,
event: { type, ...(typeof text === 'string' ? { text } : {}) } }
event: { type, ...(type !== 'context_changed' && typeof text === 'string' ? { text } : {}) } }
}
} catch { /* The next authoritative snapshot replaces a malformed stream. */ }
return null
Expand Down
Loading