Skip to content

feat(default-cwd): create dated folders under ~/pi-cwd using the local date - #996

Merged
agegr merged 1 commit into
mainfrom
claude/default-cwd-dated-folder
Sep 29, 2026
Merged

agegr merged 1 commit into
mainfrom
claude/default-cwd-dated-folder

Conversation

@agegr

@agegr agegr commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • "Use default directory" now opens ~/pi-cwd/YYYYMMDD instead of creating ~/pi-cwd-YYYYMMDD folders directly in home. Folders are still dated, so a first-time user never lands in a folder holding their own data and gets a fresh scratch cwd per day.
  • The date is the local calendar date. toISOString() gave the UTC date, so in UTC+8 the folder was named after yesterday until 08:00.
  • The default directory is selected exactly like any other directory: /api/default-cwd only creates the folder and returns its path, and the sidebar passes it to commitCustomPath(), so /api/cwd/validate checks it, adds it to the file allow-list, and resolves its project identity. remember: false keeps it from replacing the custom-path picker's last path.
  • The file allow-list no longer scans home for default cwds. Older ~/pi-cwd-YYYYMMDD folders with sessions stay browsable as session cwds; selecting one again goes through /api/cwd/validate.

Supersedes the approach in #892 (configurable default path): the dated name is deliberate, so only its location changes.

Test plan

  • lib/default-cwd.test.mjs: local date stamp (checked under TZ=Asia/Shanghai and TZ=America/Los_Angeles), path under ~/pi-cwd
  • components/SessionSidebar.project-identity.test.mjs: default cwd goes through commitCustomPath(..., { remember: false })
  • tsc --noEmit, eslint on changed files
  • Dev server: clicking "Use default directory" issues POST /api/default-cwd → POST /api/cwd/validate → file list 200, sidebar shows ~/pi-cwd/20260929, pi-web:last-custom-cwd untouched, no console errors

🤖 Generated with Claude Code

…l date

"Use default directory" now opens ~/pi-cwd/YYYYMMDD instead of scattering
~/pi-cwd-YYYYMMDD folders across home. The date still keeps a first-time user
out of folders that hold their own data and gives a fresh scratch cwd per day.

The stamp is the local calendar date; toISOString() gave the UTC one, so in
UTC+8 the folder was named after yesterday until 08:00.

The default directory is now selected exactly like any other directory.
/api/default-cwd only creates the folder and returns its path; the sidebar
then passes it to commitCustomPath(), so /api/cwd/validate checks it, adds it
to the file allow-list, and resolves its project identity. The only difference
is remember: false, so it does not replace the custom-path picker's last path.

With that, the allow-list no longer scans home for default cwds at all. Older
~/pi-cwd-YYYYMMDD folders with sessions are ordinary session cwds, and
selecting any dated folder again goes through /api/cwd/validate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit 433d09e into main Sep 29, 2026
2 checks passed
dreadster3 added a commit to dreadster3/pi-web that referenced this pull request Sep 30, 2026
…ence fix + default-CWD folders (#12)

* fix: do not persist new-session model picks into global defaults (agegr#871)

* fix: do not persist new-session model picks into global defaults

Selecting a model for a single Pi Web chat was rewriting
~/.pi/agent/settings.json via persistExplicitStartupPreferences, so a
one-off DeepSeek/flash pick silently became the CLI/global default.
Align with the TUI: session-scoped selection unless the user explicitly
opts into persist (future "Save as default").

* feat: explicit save-as-default for model and reasoning level

With new-session picks now session-scoped, pi-web had no way left to change
the default model or reasoning level. Add the Web counterpart of the TUI's
Ctrl+S: a star on each row of the model selector and the reasoning menu.

- PUT /api/models/default writes defaultProvider/defaultModel or
  defaultThinkingLevel, only for models the selector can offer, and refuses
  with 409 when a trusted project's .pi/settings.json overrides the key.
- The star saves the default and selects it for the current chat.
- Menu rows use SelectorRow, styled like session-list rows: the save star
  floats on hover/focus (always visible on touch), the default gets an
  inline marker.
- Remove the no-op startup-preferences helper and its call site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style: simpler default marker in model and reasoning menus

Drop the session-list accent bar on the active row and the inline star
after the default's name. The default row now shows a small static grey
star in the right gutter, the same spot where the save button floats in
on hover or focus, so an idle menu carries a single marker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: luwanglin <[email protected]>
Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

* feat(default-cwd): create dated folders under ~/pi-cwd using the local date (agegr#996)

"Use default directory" now opens ~/pi-cwd/YYYYMMDD instead of scattering
~/pi-cwd-YYYYMMDD folders across home. The date still keeps a first-time user
out of folders that hold their own data and gives a fresh scratch cwd per day.

The stamp is the local calendar date; toISOString() gave the UTC one, so in
UTC+8 the folder was named after yesterday until 08:00.

The default directory is now selected exactly like any other directory.
/api/default-cwd only creates the folder and returns its path; the sidebar
then passes it to commitCustomPath(), so /api/cwd/validate checks it, adds it
to the file allow-list, and resolves its project identity. The only difference
is remember: false, so it does not replace the custom-path picker's last path.

With that, the allow-list no longer scans home for default cwds at all. Older
~/pi-cwd-YYYYMMDD folders with sessions are ordinary session cwds, and
selecting any dated folder again goes through /api/cwd/validate.

Co-authored-by: Claude Opus 5.5 <[email protected]>

* fix(sidebar): keep handleDefaultCwd next to the worktree handlers

The fork's branch quick-switch added `handleUseBranch` right after
`handleDefaultCwd`, so the source slice the project-identity test reads
(handleDefaultCwd → handleCreateWorktree) swallowed a `setSelectedCwd`
call and the assertion failed. Move `handleUseBranch` above
`handleDefaultCwd` instead: `handleCreateWorktree` closes over it, so
moving it below would trip the temporal dead zone.

Functionally neutral — no body change, only declaration order. Follow-up
to upstream 433d09e, which added the test and the commitCustomPath
`remember` param the slice also asserts on.

* chore(demo): mirror the upstream model-default selectors byte-identically

Port the byte-identical mirrors from upstream 6a1246e so the demo copies
stay byte-identical mirrors of the root files as they were before the
merge: ChatInput, ModelSelector, useAgentSession, models-cache and the
three i18n message files, plus the new SelectorRow both selectors import.

* chore(demo): port upstream's feature hunks into the adapted copies

ChatWindow and SessionSidebar are pre-adapted demo copies, so they get the
feature hunks from 6a1246e (defaultModel/savedDefaultThinkingLevel props
into ChatInput) and 433d09e (commitCustomPath's remember param plus the
handleDefaultCwd -> commitCustomPath hand-off) rather than a byte copy.
Their divergence from the root is unchanged, 3 and 39 diff lines.

* chore(demo): stub PUT /api/models/default in the mock

The model and reasoning selectors' star now writes the global default
through PUT /api/models/default (upstream 6a1246e); the demo has no real
models.json, so the mock records the pick in memory and serves it back as
`defaultModel` / `savedDefaultThinkingLevel` from GET /api/models, the
same way the other mutable settings panels work in the demo.

POST /api/default-cwd already exists and needs no change: 433d09e only
made the client select its result through /api/cwd/validate, which the
mock's cwdRoute already answers for SCRATCH_ROOT.

* chore(demo): validate default-model mock like the real route

Fold-in from review: reject empty provider/modelId and validate the
thinking level set, mirroring app/api/models/default/route.ts 400s.

---------

Co-authored-by: luck <[email protected]>
Co-authored-by: luwanglin <[email protected]>
Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@agegr
agegr deleted the claude/default-cwd-dated-folder branch October 1, 2026 13:28
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…l date (agegr#996)

"Use default directory" now opens ~/pi-cwd/YYYYMMDD instead of scattering
~/pi-cwd-YYYYMMDD folders across home. The date still keeps a first-time user
out of folders that hold their own data and gives a fresh scratch cwd per day.

The stamp is the local calendar date; toISOString() gave the UTC one, so in
UTC+8 the folder was named after yesterday until 08:00.

The default directory is now selected exactly like any other directory.
/api/default-cwd only creates the folder and returns its path; the sidebar
then passes it to commitCustomPath(), so /api/cwd/validate checks it, adds it
to the file allow-list, and resolves its project identity. The only difference
is remember: false, so it does not replace the custom-path picker's last path.

With that, the allow-list no longer scans home for default cwds at all. Older
~/pi-cwd-YYYYMMDD folders with sessions are ordinary session cwds, and
selecting any dated folder again goes through /api/cwd/validate.

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 433d09e)
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…egr#996

The built-in default is ~/pi-cwd/{date} now, so the initial placeholder before
GET /api/default-cwd answers must show that instead of the old ~/pi-cwd-{date}.
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…w project its own path setting

Upstream closed agegr#892 in favour of agegr#996, so the configurable default cwd is gone:
lib/default-cwd.ts, app/api/default-cwd/route.ts, lib/file-access.ts and
lib/default-cwd.test.mjs are byte-identical to upstream/main again, and the
DirectoryPicker Escape tweak that came with agegr#892 is reverted. "Use default
directory" therefore keeps upstream's dated ~/pi-cwd/<YYYYMMDD> behaviour.

The New project action that grew out of it keeps working through its own layer:

- lib/default-project.ts stores defaultProjectPath in ~/.pi/agent/pi-web.json,
  empty meaning the built-in ~/pi-cwd (upstream's dated-folder parent).
- GET/PUT /api/default-project own that setting; POST { name } creates or reuses
  <project directory>/<name>, and the sidebar selects the result through
  /api/cwd/validate like any other directory.
- The Settings panel's General section now offers "Default project directory"
  instead of "Default directory" (settings.defaultProjectPath*).
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
上游已合并的 agegr#884/agegr#871/agegr#996 我们已同步(代码与上游一致),agegr#892 已回退,
四行都不再是取舍信息,删掉;保留的都是上游仍未合并(我们领先)或被我们
拒绝的 PR。顺带修掉 agegr#907 的理由措辞:状态列里出现「已摘取」会让
scripts/prs.sh 把它误判成已摘取。
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…#907 agegr#941 agegr#946 agegr#961 agegr#968 agegr#969 agegr#1007 agegr#1008 agegr#1009 agegr#1010)

上游已把我们提前摘取的 agegr#884 / agegr#871 / agegr#996 / agegr#961 原样合并(agegr#961 逐字节相同),
agegr#967 与 agegr#963 由上游的 agegr#1009 / agegr#1008 接管。

冲突解决:
- demo/ 对齐上游 fe288c0,撤销 agegr#963 对 demo 的两处改动(`@/lib/chat-phase-label`
  在 demo/lib 下不存在,会打断 Pages 构建)。
- AGENTS.md:保留我们的 default-project 条目,open-folder 换成上游的
  open-in-explorer。
- MessageView.tsx / SessionSidebar.tsx / FileExplorer.tsx:以上游为准,
  DismissButton 采用上游的独立文件,保留我们的思考卡片与文件管理改动。
- SessionSidebar 移除引用已删函数的旧 agegr#951 工作区按钮(agegr#951 的其他入口另行收尾)。
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
上游以 agegr#996 的 ~/pi-cwd/YYYYMMDD 关闭了 agegr#892,我们保留的却是另一层东西
(lib/default-project.ts + /api/default-project + defaultProjectPath),
不与 agegr#996 冲突,也不在还活着的 PR 上,所以之前只写在 AGENTS.md 里。
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…l date (agegr#996)

"Use default directory" now opens ~/pi-cwd/YYYYMMDD instead of scattering
~/pi-cwd-YYYYMMDD folders across home. The date still keeps a first-time user
out of folders that hold their own data and gives a fresh scratch cwd per day.

The stamp is the local calendar date; toISOString() gave the UTC one, so in
UTC+8 the folder was named after yesterday until 08:00.

The default directory is now selected exactly like any other directory.
/api/default-cwd only creates the folder and returns its path; the sidebar
then passes it to commitCustomPath(), so /api/cwd/validate checks it, adds it
to the file allow-list, and resolves its project identity. The only difference
is remember: false, so it does not replace the custom-path picker's last path.

With that, the allow-list no longer scans home for default cwds at all. Older
~/pi-cwd-YYYYMMDD folders with sessions are ordinary session cwds, and
selecting any dated folder again goes through /api/cwd/validate.

Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…l date (agegr#996)

"Use default directory" now opens ~/pi-cwd/YYYYMMDD instead of scattering
~/pi-cwd-YYYYMMDD folders across home. The date still keeps a first-time user
out of folders that hold their own data and gives a fresh scratch cwd per day.

The stamp is the local calendar date; toISOString() gave the UTC one, so in
UTC+8 the folder was named after yesterday until 08:00.

The default directory is now selected exactly like any other directory.
/api/default-cwd only creates the folder and returns its path; the sidebar
then passes it to commitCustomPath(), so /api/cwd/validate checks it, adds it
to the file allow-list, and resolves its project identity. The only difference
is remember: false, so it does not replace the custom-path picker's last path.

With that, the allow-list no longer scans home for default cwds at all. Older
~/pi-cwd-YYYYMMDD folders with sessions are ordinary session cwds, and
selecting any dated folder again goes through /api/cwd/validate.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant