Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
27b9a64
feat: 1.9.0 — zstd rollouts, Codex titles/projects, goal mode
Nov 11, 2026
baf33a5
chore: ignore packed git bundles
Nov 11, 2026
5532312
chore: point repository/homepage/bugs at nlsp60/dsh-codex-sync
Nov 11, 2026
56068d9
fix: 1.9.1 — do not abort the import when a chat is open in DSH
Nov 11, 2026
f2981d2
fix: 1.9.2 — imported chats no longer open in 创造模式
Nov 12, 2026
1df3e1e
fix: 1.9.3 — the replayed goal chain must pass DSH's goal fold
Nov 12, 2026
9c6f223
feat: 1.10.0 — 管理已同步对话(按项目分组,勾选删除)
Nov 12, 2026
27fcf19
fix: 1.10.1 — 待同步列表里同一对话重复出现
Nov 12, 2026
48136c4
fix: 1.10.2 — 导入的会话可能静默不挂工作区(侧边栏找不到)
Nov 12, 2026
0c51e54
fix: 1.10.3 — 管理已同步:删除结果如实显示(含被拒绝的原因)
Nov 12, 2026
143f708
feat: 1.10.4 — 过滤 Codex 侧边聊天(fork 线程),同步与列表都不再出现
Nov 12, 2026
786e8c6
fix: 1.10.5 — 管理已同步补全(侧边聊天与孤儿导入也能列出并删除)
Nov 12, 2026
8f4d6f4
feat: 1.10.6 — 问答回复双向映射(Codex 信封 ⇄ DSH 答案卡片)
Nov 12, 2026
ba72eb7
fix: 1.10.7 — 问答卡片不再卡住 v0→v4 迁移(迁移期降级为 user,迁移后恢复)
Nov 12, 2026
a3c310a
feat: 1.10.8 — 单个会话迁移失败只跳过并汇报,不再中断整批导入
Nov 12, 2026
407234c
fix: 1.10.9 — 过滤追加在正文后的 <oai-mem-citation> 记忆引用块
Nov 12, 2026
fcfd2c3
feat: 1.10.10 — 批量导入有会话迁移失败时结果页显示警示(部分会话未导入)
Nov 12, 2026
5b61e89
feat: 1.10.11 — busy(对话打开未更新)也归入结果页警示态
Nov 12, 2026
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
*.tgz
.DS_Store
.npm-cache/
*.bundle
329 changes: 329 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

38 changes: 30 additions & 8 deletions bin/dsh-codex-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,28 @@ export function ensureReverseServer(dir, noBuild) {
log(`✓ reverse MCP server already built: ${cliPath}`)
return cliPath
}
log(`→ cloning ${REVERSE_REPO} into ${dir}`)
execFileSync('git', ['clone', '--depth', '1', REVERSE_REPO, dir], { stdio: 'inherit' })
if (!existsSync(dir)) {
log(`→ cloning ${REVERSE_REPO} into ${dir}`)
execFileSync('git', ['clone', '--depth', '1', REVERSE_REPO, dir], { stdio: 'inherit' })
} else {
log(`→ directory exists, skipping clone: ${dir}`)
}
if (noBuild) {
log('! --no-build: server cloned but not built; run `pnpm install && pnpm build` inside the dir')
return cliPath
}
log('→ pnpm install')
execFileSync('pnpm', ['install'], { cwd: dir, stdio: 'inherit' })
log('→ pnpm build')
execFileSync('pnpm', ['build'], { cwd: dir, stdio: 'inherit' })
const pnpmPath = 'C:\\Users\\neo\\.dsh\\dsh-runtimes\\dsh-primary-runtime\\dependencies\\pnpm\\bin\\pnpm.mjs'
const nodeBin = process.execPath
if (existsSync(pnpmPath)) {
execFileSync(nodeBin, [pnpmPath, 'install'], { cwd: dir, stdio: 'inherit' })
log('→ pnpm build')
execFileSync(nodeBin, [pnpmPath, 'build'], { cwd: dir, stdio: 'inherit' })
} else {
execFileSync('pnpm', ['install'], { cwd: dir, stdio: 'inherit' })
log('→ pnpm build')
execFileSync('pnpm', ['build'], { cwd: dir, stdio: 'inherit' })
}
if (!existsSync(cliPath)) {
throw new Error(`build finished but ${cliPath} is missing`)
}
Expand Down Expand Up @@ -219,22 +231,25 @@ async function cmdDoctor(args) {
// codex sessions + oversized risk
try {
const { listCodexSessions, parseCodexSession } = await import('../lib/codex-reader.mjs')
const { DEFAULT_MAX_SESSION_BYTES } = await import('../lib/import-service.js')
const files = listCodexSessions(join(CODEX_HOME, 'sessions'))
let big = 0
let ok = 0
let subagents = 0
let compressed = 0
const { statSync } = await import('node:fs')
for (const f of files) {
if (f.endsWith('.zst')) compressed += 1
let size = 0
try {
size = statSync(f).size
} catch {
continue
}
if (size > 256 * 1024 * 1024) big += 1
if (size > DEFAULT_MAX_SESSION_BYTES) big += 1
else {
try {
const header = parseCodexSession(f).header
const header = (await parseCodexSession(f)).header
if (header.id) {
ok += 1
if (header.parentThreadId) subagents += 1
Expand All @@ -244,7 +259,14 @@ async function cmdDoctor(args) {
}
}
}
lines.push(`codex sessions: ${files.length} files, ${ok} importable, ${subagents} sub-agent threads (filtered from import), ${big} oversized (>256MiB, skipped)`)
lines.push(`codex sessions: ${files.length} files (${compressed} zstd-compressed), ${ok} importable, ${subagents} internal threads (guardian/sub-agent, filtered from import), ${big} oversized (>${Math.round(DEFAULT_MAX_SESSION_BYTES / 1024 / 1024)}MiB, skipped)`)
try {
const { loadCodexIndex } = await import('../lib/codex-index.mjs')
const index = loadCodexIndex(CODEX_HOME)
lines.push(`codex catalog: ${index.threads.size} threads, ${index.projects.size} projects (source: ${index.source})`)
} catch (error) {
lines.push(`codex catalog: unavailable (${error.message})`)
}
} catch (error) {
lines.push(`codex sessions: scan failed (${error.message})`)
}
Expand Down
104 changes: 68 additions & 36 deletions lib/attach-workspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
*
* dsh 的 workspace 归属是 cwd 精确匹配:每个会话按其持久化 header 的
* cwd 找 `workspaceRegistry` 中 path 相同的 workspace,不存在则创建。
* workspace 标题带绝对路径(`basename (/abs/path)`),同名项目也能区分。
*
* workspace 标题优先用 Codex 的项目名(`projects.name`,一个项目可以包含多个
* 仓库根目录),拿不到项目名时退回目录名 —— **不再把绝对路径写进标题**:
* 路径既长又会随机器变化,同名项目靠目录名区分即可。
*
* 服务不存在(headless 等未加载 workspace 插件的组合)时静默跳过。
*/

import { normalizePersistence } from './persistence-facade.mjs'

/** 路径显示:home 用 `~` 前缀;超过 3 级只保留最后 3 级(保证同名可区分又简洁)。 */
/** 路径显示:home 用 `~` 前缀;超过 3 级只保留最后 3 级(仅用于日志与提示)。 */
export function displayPath(cwd) {
const home = process.env.HOME ?? ''
if (cwd === home) return '~'
Expand All @@ -23,22 +26,43 @@ export function displayPath(cwd) {
return parts.length > 3 ? parts.slice(-3).join('/') : cwd
}

/** workspace 显示标题:basename + 缩短路径(`名称 (~/最后几级)`)。 */
export function workspaceTitle(cwd) {
const base = cwd.split('/').filter(Boolean).pop() ?? cwd
return `${base} (${displayPath(cwd)})`
/** 目录名(不区分分隔符,兼容 `\\?\D:\a\b` 这类 Windows 路径)。 */
function baseName(cwd) {
const parts = String(cwd).replace(/\\/gu, '/').split('/').filter(Boolean)
return parts.pop() ?? cwd
}

/**
* workspace 标题:Codex 项目名优先,否则目录名。绝不拼路径。
* @param {string} cwd
* @param {(cwd: string) => (string | undefined)} [projectNameOf]
*/
export function workspaceTitle(cwd, projectNameOf) {
const project = typeof projectNameOf === 'function' ? projectNameOf(cwd) : undefined
if (typeof project === 'string' && project.trim().length > 0) return project.trim()
return baseName(cwd)
}

/** 旧版本自动生成过的标题(`basename` 或 `basename (路径)`),可安全改写。 */
function isGeneratedTitle(title, cwd) {
const base = baseName(cwd)
if (title === base) return true
return new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')} \\(`).test(title)
}

/**
* 按 cwd 分组把会话 attach 到 workspace。
* @param ctx - 全局上下文(探测 workspaceRegistry)。
* @param sessions - [{id, cwd}],仅 cwd 非空的会话会被归位。
* @param options.projectNameOf - cwd → Codex 项目名(用于工作区标题)。
* @returns 摘要行数组。
*/
export async function attachSessionsToWorkspaces(ctx, sessions) {
export async function attachSessionsToWorkspaces(ctx, sessions, options = {}) {
const registry = ctx.get('workspaceRegistry')
if (registry === undefined) return []
const projectNameOf = options.projectNameOf
const lines = []
const unattached = []
const byCwd = new Map()
for (const session of sessions) {
if (typeof session.cwd !== 'string' || session.cwd.length === 0) continue
Expand All @@ -54,27 +78,35 @@ export async function attachSessionsToWorkspaces(ctx, sessions) {
lines.push(` [skipped] /: root directory skipped`)
continue
}
const title = workspaceTitle(cwd, projectNameOf)
try {
const existing = await registry.resolveByPath(cwd)
const workspace = existing ?? await registry.create(cwd, workspaceTitle(cwd))
// 统一命名:默认命名的 workspace(title 就是 basename,无路径)补上
// 绝对路径,同名项目也好区分;用户自定义过的标题不动。
const base = cwd.split('/').filter(Boolean).pop() ?? cwd
// 默认命名(title == basename)或旧版生成标题(`basename (绝对路径)`)
// 都统一成新格式;用户自定义标题不动。
const generated = new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')} \\(`)
if (workspace.title === base || generated.test(workspace.title)) {
await workspace.setTitle(workspaceTitle(cwd))
const workspace = existing ?? await registry.create(cwd, title)
// 只改自动生成过的标题(目录名或旧版的「目录名 (路径)」),用户自定义的不动。
if (existing !== undefined && isGeneratedTitle(workspace.title, cwd) && workspace.title !== title) {
await workspace.setTitle(title)
}
for (const id of ids) {
try {
await workspace.attachSession(id)
} catch (error) {
lines.push(` [skipped] ${id} attach to ${cwd}: ${error.message}`)
let attached = false
for (let attempt = 0; attempt < 2 && !attached; attempt += 1) {
if (attempt > 0) await new Promise((resolve) => setTimeout(resolve, 300))
try {
await workspace.attachSession(id)
attached = true
} catch (error) {
if (attempt > 0) unattached.push({ id, title, reason: error.message })
}
}
// `attachSession` is a silent no-op when the registry filters the id back
// out (an archived session never reaches `workspace.sessionIds`), and a
// silent no-op leaves the chat with no group to appear in — the symptom
// is "导入成功但侧边栏找不到".
if (attached && Array.isArray(workspace.sessionIds) && !workspace.sessionIds.includes(id)) {
unattached.push({ id, title, reason: '工作区未收录该会话(可能处于归档状态)' })
}
}
const action = existing === undefined ? 'created' : 'reused'
lines.push(` [${action}] ${workspaceTitle(cwd)}: ${ids.length} sessions`)
lines.push(` [${action}] ${title}: ${ids.length} sessions`)
} catch (error) {
if (error?.code === 'ENOENT') {
// 源机器的路径在本机不存在:会话照常导入,只是无法挂 workspace。
Expand All @@ -84,32 +116,32 @@ export async function attachSessionsToWorkspaces(ctx, sessions) {
}
}
}
for (const { id, title, reason } of unattached) {
lines.push(` [ungrouped] ${id} → ${title}: ${reason}`)
}
if (unattached.length > 0) {
lines.push(` [hint] ${unattached.length} 个会话没能挂到工作区,侧边栏可能看不到它们;先关闭该对话,再运行 /attach-workspaces 重试`)
}
return lines
}

/**
* 统一所有默认命名 workspace 的标题为 `basename (绝对路径)`。
* 只改 title 恰为 basename 的(GUI 默认命名);用户自定义标题不动。
* 把自动生成的工作区标题统一成「Codex 项目名 / 目录名」,去掉旧版标题里的路径。
* @param ctx - 全局上下文(workspaceRegistry)。
* @param options.projectNameOf - cwd → Codex 项目名。
* @returns 改动的 workspace 数量。
*/
export async function unifyWorkspaceTitles(ctx) {
export async function unifyWorkspaceTitles(ctx, options = {}) {
const registry = ctx.get('workspaceRegistry')
if (registry === undefined) return 0
const projectNameOf = options.projectNameOf
let changed = 0
for (const workspace of registry.list()) {
const base = workspace.path.split('/').filter(Boolean).pop() ?? workspace.path
if (workspace.title === base) {
await workspace.setTitle(workspaceTitle(workspace.path))
changed += 1
} else {
// 旧版生成标题(`basename (绝对路径)`)也统一成新格式(`basename (~/…)`)。
const generated = new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')} \\(`)
if (generated.test(workspace.title)) {
await workspace.setTitle(workspaceTitle(workspace.path))
changed += 1
}
}
if (!isGeneratedTitle(workspace.title, workspace.path)) continue
const title = workspaceTitle(workspace.path, projectNameOf)
if (workspace.title === title) continue
await workspace.setTitle(title)
changed += 1
}
return changed
}
Expand Down
Loading