Repository navigation
feat(sessions): choose the working directory when creating a chat - #9
Merged
Merged
Conversation
The server's POST /api/chats/create takes only label/subscription/model -- there is no work_dir field -- so the working directory has to be set right after creation through RPC set_cwd with force=true, the same two-step flow the web client uses. force matters: it is the explicit-user-action path, so the server applies the path verbatim instead of substituting an inferred one. Create dialog gains a work-directory field plus one-tap candidates. There is no directory browsing endpoint on the server (the path lives on the host, not on the phone), so the candidates are the recently used paths (AppPrefs, max 5, newest first) merged with work_dir values from existing sessions -- a pure function so it can be unit-tested. set_cwd failing is not creation failing: the chat is kept and the reason is surfaced through a one-shot notice/snackbar; the path can still be changed later from the session. versionCode 23 (0.3.5), CHANGELOG 0.3.5 entry, and docs/agent/sessions.md covering the create -> set_cwd flow. AGENTS.md records the worktree gotcha that release builds need keystore.properties copied in.
Free-text was the wrong shape for this: the working directory lives on the
host, so Android's SAF picker cannot reach it, but the server already exposes
the same listing the web file tree uses -- POST /api/fs/list {path,
show_hidden} -> entries[name, isDir, size, mode, modTime].
Tapping the folder icon on the work-dir field now opens a browser dialog:
list subdirectories, walk into them, go up, and '使用此目录' writes the path
back. Only directories are listed; an empty directory and a failed read are
reported differently, and results are dropped if the path moved on while the
request was in flight (fast tapping used to be able to overwrite a newer
listing).
Path assembly is client-side because the server returns bare names --
joinPath/parentPath handle root, trailing slash and empty input, pinned by
FilePathTest. The recent-path suggestions stay as one-tap chips.
versionCode 24 (still 0.3.5).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目标
新建会话时能选工作目录;不填就用服务器默认目录。
为什么要两步
服务端
POST /api/chats/create只接受label/subscription_id/model,没有work_dir,所以只能建完再设:force: true是「显式用户动作」语义(服务端rpc_table.go的注释里就写着这个用途):传什么路径就用什么路径,不会被既有 cwd 或自动推断值改写。Web 端components/agent/api.ts的setCwd同样是force: true,两端行为一致。set_cwd失败不等于创建失败:会话保留,SessionsUiState.notice弹一条 snackbar 说明原因,之后仍可再改。目录浏览(修正:服务端其实是有的)
第一版写错了:工作目录在服务器上,Android 的 SAF 选目录拿不到这种路径,我据此以为只能手输 + 候选。
实际上 Web 端目录树走的就是现成接口:
所以现在:工作目录输入框右侧图标 → 目录浏览对话框(列子目录 / 进 / 上一级 / 「使用此目录」);
只列
isDir的项,空目录与读取失败分开提示,路径变化后的过期响应直接丢弃(连点不会覆盖新列表)。服务端只返回名字,完整路径由客户端拼(
joinPath/parentPath,FilePathTest钉住根目录、尾斜杠、空值)。另外仍保留「一点即填」的候选:
AppPrefs.recentWorkDirs:最近用过的,最新在前,最多 5 个(本地 SharedPreferences,只有set_cwd成功才记);work_dir作为补充;data/WorkDirSuggestions.kt,去重/跳过空串/截断,由WorkDirSuggestionsTest覆盖。候选在
SessionsViewModel.refresh()里算好放进 state,UI 只渲染(项目约定:UI 不做数据推导)。验证
./gradlew :app:testDebugUnitTest✅ 46 个用例(新增 4 个WorkDirSuggestionsTest+ 4 个FilePathTest)./gradlew :app:lintDebug✅./gradlew :app:assembleRelease✅ 签名CN=xbothttps://minio.cjiw.site/uploads/share/android/xbot-android-24.apk(versionCode 24 / 0.3.5,sha256
3c0254d5…,公网回拉校验一致)顺带
docs/agent/sessions.md:create → set_cwd 的流程、/api/fs/list目录浏览、候选来源、失败语义;AGENTS.md补一条本次踩到的坑:worktree 里首次assembleRelease会报SigningConfig "release" is missing required property "storeFile",因为keystore.properties/keystore/是 gitignored,新 worktree 没有,需要从主仓库复制;aapt2/apksigner也要用主仓库tools/sdk的绝对路径。