Files
OpenHands/__tests__/api
Robert Brennanandopenhands 2cbfa80f32 fix(files-tab): default to Diff view when a workspace or repo is attached (#349)
* fix(files-tab): default to Diff view when a workspace or repo is attached

Previously, the Files tab only defaulted to Diff view when the user
explicitly picked a Git repository on the home page (`selected_repository`
on the conversation). Conversations created via the workspace picker —
which sets a local working directory but not `selected_repository` —
fell through to Files view, even though those conversations also have a
pre-existing working tree the user came in to inspect.

Treat workspace selection the same as repo selection:

- Extend `ConversationMetadata` with an optional `selected_workspace`
  field and persist it client-side when the home-page workspace picker
  supplies a `workingDirOverride` (the agent-server runtime has no
  concept of workspace selection, so this stays client-side, mirroring
  how repo metadata already works).
- Rename `useIsGitRepo` → `useHasAttachedSource` and broaden it to
  return true when *either* `selected_repository` is set on the active
  conversation *or* a `selected_workspace` was stored at creation time.
- Files tab now keys its diff-view default off `hasAttachedSource`
  instead of `isGitRepo`. The existing `useHasGitCommits` probe still
  gates the default off when the attached working tree has no commits
  yet, so non-git workspaces and unborn-HEAD repos correctly fall back
  to Files view.

The user's persisted per-conversation toggle choice continues to win
over the computed default.

Co-authored-by: openhands <openhands@all-hands.dev>

* chore(files-tab): align comments and test names with attached-source semantics

Follow-up cleanup to the diff-default fix. No behaviour change.

- `useHasGitCommits` jsdoc + inline comment now describe all three
  "no diff base" cases (unborn HEAD, non-git workspace, other git
  error) instead of singling out empty repos, and reference
  `useHasAttachedSource` as the gating signal.
- Files-tab test descriptions / inline comment dropped the
  "git repo" framing in favour of "attached source", matching the
  hook the suite is exercising.
- Added an AGENTS.md note capturing the design and warning future
  agents off the filesystem-probe approach that was tried (and reverted)
  in earlier passes at this logic.
- Minor prettier reflow in `use-has-attached-source.ts` picked up by
  `eslint --fix`.

Co-authored-by: openhands <openhands@all-hands.dev>

---------

Co-authored-by: openhands <openhands@all-hands.dev>
2026-05-11 17:30:59 -07:00
..