adapter.py python
120 lines 4.2 KB
Raw
sha256:208d9dc47f0c6d8553ee80aafc8f0993a6ebf0a88410746f47f58b4e7c6fd6a6 fix(muse): use rev-parse for muse-only branch status Human minor ⚠ breaking 1 day ago
1 """Muse-only VCS adapter backend (§4)."""
2
3 from __future__ import annotations
4
5 from adapters.base import BaseAdapter
6 from adapters.errors import ReadError, WriteError
7 from adapters.runner import CommandResult
8 from adapters.types import (
9 AnchorResult,
10 CommitResult,
11 HeadResult,
12 MirrorResult,
13 RealignResult,
14 StatusResult,
15 )
16
17 GIT_FORBIDDEN = "git forbidden in this regime"
18
19
20 class MuseOnlyAdapter(BaseAdapter):
21 """MuseHub backend — git and mirror are hard no-ops."""
22
23 def status(self) -> StatusResult | ReadError:
24 # Muse 0.2.x exposes the current branch through rev-parse; unlike Git,
25 # its branch command does not accept --show-current.
26 branch_result = self._muse("rev-parse", "--abbrev-ref", "HEAD")
27 if isinstance(branch_result, ReadError):
28 return branch_result
29 dirty_result = self._muse_dirty()
30 if isinstance(dirty_result, ReadError):
31 return dirty_result
32 return StatusResult(
33 regime=self.regime,
34 dirty=dirty_result,
35 branch=branch_result.stdout,
36 notes=["canonical=muse", "git-forbidden"],
37 muse_dirty=dirty_result,
38 git_dirty=None,
39 )
40
41 def read_head(self, ref: str) -> HeadResult | ReadError:
42 if ref.startswith("origin/") or ref.startswith(self.config.vcs.git.remote + "/"):
43 return ReadError("read_head", GIT_FORBIDDEN)
44 muse_ref = ref.removeprefix("muse:")
45 return self._muse_rev_parse_sha(muse_ref)
46
47 def read_canonical_anchor(self) -> AnchorResult | ReadError:
48 main = self.config.vcs.muse.main_branch
49 if not main:
50 return ReadError("read_canonical_anchor", "muse.main_branch not configured")
51 head = self.read_head(f"muse:{main}")
52 if isinstance(head, ReadError):
53 return head
54 return AnchorResult(anchor_sha=head.sha, source=f"muse:{main}")
55
56 def realign(self, *, dry_run: bool, max_commits: int) -> RealignResult:
57 return RealignResult(
58 would_import=0,
59 applied=False,
60 from_ref=None,
61 to_ref=None,
62 reason="single-history",
63 )
64
65 def commit_feature(
66 self,
67 *,
68 branch: str,
69 message: str,
70 paths: list[str],
71 ) -> CommitResult | ReadError | WriteError:
72 unsafe = self._validate_paths(paths)
73 if unsafe:
74 return unsafe
75 if self._is_protected_branch(branch):
76 return WriteError(
77 "commit_feature",
78 f"refused protected branch {branch!r}",
79 )
80
81 # §GSW.6.1: skip checkout when Muse HEAD is already on the branch —
82 # dirty handover/roadmap paths must never fail the commit here.
83 current = self._muse("rev-parse", "--abbrev-ref", "HEAD")
84 if isinstance(current, ReadError):
85 return current
86 if current.stdout.strip() != branch:
87 # §GSW.6.2: bare checkout refuses dirty tracked files (Muse 0.2.x);
88 # retry with --autoshelf to carry them. --force is forbidden.
89 checkout = self._muse("checkout", branch)
90 if isinstance(checkout, ReadError):
91 checkout = self._muse("checkout", "--autoshelf", branch)
92 if isinstance(checkout, ReadError):
93 return checkout
94
95 if paths:
96 for path in paths:
97 # Muse 0.2.x has no top-level `add`; staging is `muse code add`
98 # (matches the KH2 remediation string). Found live in GSW land-b.
99 add = self._muse("code", "add", path)
100 if isinstance(add, ReadError):
101 return add
102
103 commit = self._muse("commit", "-m", message)
104 if isinstance(commit, ReadError):
105 return commit
106
107 head = self._muse_rev_parse_sha("HEAD")
108 if isinstance(head, ReadError):
109 return head
110 return CommitResult(committed=True, sha=head.sha)
111
112 def mirror(self, *, dry_run: bool) -> MirrorResult:
113 return MirrorResult(
114 diff_summary="",
115 pushed=False,
116 reason=GIT_FORBIDDEN,
117 )
118
119 def _git(self, *args: str) -> CommandResult | ReadError:
120 return ReadError("git", GIT_FORBIDDEN)
File History 2 commits
sha256:208d9dc47f0c6d8553ee80aafc8f0993a6ebf0a88410746f47f58b4e7c6fd6a6 fix(muse): use rev-parse for muse-only branch status Human minor 1 day ago
sha256:8461d44b77376fbf06fa7c3e085d309e3010fd8d5886d63c63e69ce118811ad4 docs: record AFF-b feature-tip SHAs after AFF-b-ISR commit. Human 3 days ago