* feat: add session-worktree contract types and canonicalizeWorktreeState API - Add SessionWorktreeAttachment type and worktree metadata fields (worktreeRoot, worktreeStatus, headState, worktreeSource) to session/worktree types - Add GitAPI.validateWorktreeDirectory() and canonicalizeWorktreeState() methods with full HTTP delegation chain (gitApiHttp → routes.js → service.js) - Add canonicalizeWorktreeState() implementation that resolves worktreeRoot, headState (branch/detached/unborn), attentionReason (merge/rebase/etc), and worktreeStatus (ready/missing/invalid/not-a-repo) for a given directory - Add validateWorktreeDirectory() to check whether a cwd is inside a worktreeRoot - Add session-worktree-contract.ts: pure functions for resolving session worktree state, formatting badges, and building repair actions - Add session-worktree-store.ts: authoritative Zustand store for session-to-worktree attachments, replacing session-ui-store as the source of truth for worktree binding - Add unit tests for contract functions and store operations * feat: canonicalize worktree metadata producers - worktreeManager.listProjectWorktrees: derive headState (branch/detached/unborn) from worktree list entry instead of relying on external state, and populate all Phase 1 canonical fields (worktreeRoot, worktreeStatus, worktreeSource) for each discovered worktree entry - worktreeManager.createWorktree: include all Phase 1 canonical fields (worktreeRoot, worktreeStatus, headState, worktreeSource) in returned metadata - useDetectedWorktreeRoot: populate fallback canonical fields so that sessions without store-based metadata still have worktreeRoot/worktreeStatus/ headState/worktreeSource when resolved through the fallback path * feat: route sessions through authoritative worktree attachments - session-ui-store: import session-worktree-store as the authoritative source for session↔worktree attachment state - setWorktreeMetadata: mirror all writes to session-worktree-store so that session-worktree-store.attachments is always the authoritative record; local worktreeMetadata map is kept for backward-compatible reads - Add session-ui-store.test.js with unit tests covering: valid cwd routing, degraded fallback, created-for-session attachments, legacy upgrade recovery, missing/not-a-repo status handling * feat: clarify session worktree targets - session-worktree-contract: extend buildSessionTargetOptions to accept pendingBootstrapDirectory and mark pending worktrees with pending=true; extend SessionTargetOption to include optional pending flag - ChatInput: replace manual worktree branch options construction with buildSessionTargetOptions; add ⏳ prefix for pending bootstrap worktrees - Add test for pending bootstrap worktree distinction * feat: show worktree-backed session state - Header: read worktree attachment from authoritative session-worktree-store and render needs-attention/degraded/missing badge with alert icon next to current session info when session has degraded/missing/invalid state - GitView: show 'Worktree features are unavailable' message when session has missing worktree status and open-without-worktree-features repair action * feat: enforce safe mutations for attached worktrees - session-worktree-contract: add getMutationBlockingReasons helper that returns blocking reasons (missing/invalid/attention state) for high-risk mutations - GitView: gate handleCheckoutBranch, handleCreateBranch, and handleRenameBranch with getMutationBlockingReasons; block with explicit toast message when worktree is missing, invalid, or has an in-progress git operation - session-worktree-contract.test: add 7 tests covering mutation blocking for missing/invalid/attention states (merge/rebase/cherry-pick) * feat: implement session worktree isolation This adds a shared session↔worktree contract that makes session switching worktree-backed. Sessions attached to different worktrees keep stable branch context without shared-directory auto-checkout. Commits: - feat: add session-worktree contract types and canonicalizeWorktreeState API - feat: canonicalize worktree metadata producers - feat: route sessions through authoritative worktree attachments - feat: clarify session worktree targets - feat: show worktree-backed session state - feat: enforce safe mutations for attached worktrees * feat: make authoritative attachment first-priority source for session directory resolution Phase A: resolveSessionDirectory, getDirectoryForSession, hooks read authoritative attachment before falling back to worktreeMetadata. Phase B: createSession canonicalizes and writes attachment on creation; setCurrentSession recovers legacy/missing attachments via async canonicalization. * feat: make authoritative attachment the primary branch source in Header/GitView Phase C: Header branch label and GitView project root now read from authoritative SessionWorktreeAttachment first, falling back to live git and legacy sources only when attachment is absent, degraded, or legacy. Adds getAttachmentBranchLabel() helper with 7 tests. * feat: add runtime parity for validateWorktreeDirectory and canonicalizeWorktreeState Phase D: Web runtime API, VS Code bridge, and VS Code gitService now expose validateWorktreeDirectory and canonicalizeWorktreeState, matching the server-side implementations. All three runtimes (web, desktop, VS Code) can now delegate worktree canonicalization without HTTP fallback. * feat: add dirty-tree blocking to mutation safety gates getMutationBlockingReasons now accepts an optional gitStatus param and blocks branch mutations when the tree has uncommitted changes. GitView passes live status to all three blocking call sites. 5 new tests covering dirty, clean, null, combined, and no-file-count cases. * refactor: revert branch label to live-git-first, remove getAttachmentBranchLabel Live git is the correct source for branch labels in all scenarios: dedicated worktree sessions have identical live/attachment branches, and shared-directory sessions must show the real current branch. Attachment remains authoritative for worktreeRoot, cwd, degraded/ missing/repair status, and mutation blocking. * chore: remove session worktree isolation plan doc * refactor: simplify session worktree isolation implementation --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
64 lines
2.6 KiB
TypeScript
64 lines
2.6 KiB
TypeScript
import * as gitApiHttp from '@openchamber/ui/lib/gitApiHttp';
|
|
import type {
|
|
GitAPI,
|
|
CreateGitCommitOptions,
|
|
GitLogOptions,
|
|
} from '@openchamber/ui/lib/api/types';
|
|
|
|
export const createWebGitAPI = (): GitAPI => ({
|
|
checkIsGitRepository: gitApiHttp.checkIsGitRepository,
|
|
getGitStatus: gitApiHttp.getGitStatus,
|
|
getGitDiff: gitApiHttp.getGitDiff,
|
|
getGitFileDiff: gitApiHttp.getGitFileDiff,
|
|
revertGitFile: gitApiHttp.revertGitFile,
|
|
isLinkedWorktree: gitApiHttp.isLinkedWorktree,
|
|
getGitBranches: gitApiHttp.getGitBranches,
|
|
deleteGitBranch: gitApiHttp.deleteGitBranch as GitAPI['deleteGitBranch'],
|
|
deleteRemoteBranch: gitApiHttp.deleteRemoteBranch as GitAPI['deleteRemoteBranch'],
|
|
removeRemote: gitApiHttp.removeRemote as GitAPI['removeRemote'],
|
|
generateCommitMessage: gitApiHttp.generateCommitMessage,
|
|
generatePullRequestDescription: gitApiHttp.generatePullRequestDescription,
|
|
listGitWorktrees: gitApiHttp.listGitWorktrees,
|
|
validateGitWorktree: gitApiHttp.validateGitWorktree,
|
|
createGitWorktree: gitApiHttp.createGitWorktree,
|
|
deleteGitWorktree: gitApiHttp.deleteGitWorktree,
|
|
validateWorktreeDirectory: gitApiHttp.validateWorktreeDirectory,
|
|
canonicalizeWorktreeState: gitApiHttp.canonicalizeWorktreeState,
|
|
createGitCommit(directory: string, message: string, options?: CreateGitCommitOptions) {
|
|
return gitApiHttp.createGitCommit(directory, message, options);
|
|
},
|
|
gitPush: gitApiHttp.gitPush,
|
|
gitPull: gitApiHttp.gitPull,
|
|
gitFetch: gitApiHttp.gitFetch,
|
|
checkoutBranch: gitApiHttp.checkoutBranch,
|
|
createBranch: gitApiHttp.createBranch,
|
|
renameBranch: gitApiHttp.renameBranch,
|
|
getGitLog(directory: string, options?: GitLogOptions) {
|
|
return gitApiHttp.getGitLog(directory, options);
|
|
},
|
|
getCommitFiles: gitApiHttp.getCommitFiles,
|
|
getCurrentGitIdentity: gitApiHttp.getCurrentGitIdentity,
|
|
hasLocalIdentity: gitApiHttp.hasLocalIdentity,
|
|
setGitIdentity: gitApiHttp.setGitIdentity,
|
|
getGitIdentities: gitApiHttp.getGitIdentities,
|
|
createGitIdentity: gitApiHttp.createGitIdentity,
|
|
updateGitIdentity: gitApiHttp.updateGitIdentity,
|
|
deleteGitIdentity: gitApiHttp.deleteGitIdentity,
|
|
getRemotes: gitApiHttp.getRemotes,
|
|
rebase: gitApiHttp.rebase,
|
|
abortRebase: gitApiHttp.abortRebase,
|
|
continueRebase: gitApiHttp.continueRebase,
|
|
merge: gitApiHttp.merge,
|
|
abortMerge: gitApiHttp.abortMerge,
|
|
continueMerge: gitApiHttp.continueMerge,
|
|
stash: gitApiHttp.stash,
|
|
stashPop: gitApiHttp.stashPop,
|
|
getConflictDetails: gitApiHttp.getConflictDetails,
|
|
worktree: {
|
|
list: gitApiHttp.listGitWorktrees,
|
|
validate: gitApiHttp.validateGitWorktree,
|
|
create: gitApiHttp.createGitWorktree,
|
|
remove: gitApiHttp.deleteGitWorktree,
|
|
},
|
|
});
|