adapter.py
python
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439
feat: K1-P1 complete — agent provenance, build-verification…
Sonnet 4.6
patch
53 days 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 | branch_result = self._muse("branch", "--show-current") |
| 25 | if isinstance(branch_result, ReadError): |
| 26 | return branch_result |
| 27 | dirty_result = self._muse_dirty() |
| 28 | if isinstance(dirty_result, ReadError): |
| 29 | return dirty_result |
| 30 | return StatusResult( |
| 31 | regime=self.regime, |
| 32 | dirty=dirty_result, |
| 33 | branch=branch_result.stdout, |
| 34 | notes=["canonical=muse", "git-forbidden"], |
| 35 | ) |
| 36 | |
| 37 | def read_head(self, ref: str) -> HeadResult | ReadError: |
| 38 | if ref.startswith("origin/") or ref.startswith(self.config.vcs.git.remote + "/"): |
| 39 | return ReadError("read_head", GIT_FORBIDDEN) |
| 40 | muse_ref = ref.removeprefix("muse:") |
| 41 | return self._muse_rev_parse_sha(muse_ref) |
| 42 | |
| 43 | def read_canonical_anchor(self) -> AnchorResult | ReadError: |
| 44 | main = self.config.vcs.muse.main_branch |
| 45 | if not main: |
| 46 | return ReadError("read_canonical_anchor", "muse.main_branch not configured") |
| 47 | head = self.read_head(f"muse:{main}") |
| 48 | if isinstance(head, ReadError): |
| 49 | return head |
| 50 | return AnchorResult(anchor_sha=head.sha, source=f"muse:{main}") |
| 51 | |
| 52 | def realign(self, *, dry_run: bool, max_commits: int) -> RealignResult: |
| 53 | return RealignResult( |
| 54 | would_import=0, |
| 55 | applied=False, |
| 56 | from_ref=None, |
| 57 | to_ref=None, |
| 58 | reason="single-history", |
| 59 | ) |
| 60 | |
| 61 | def commit_feature( |
| 62 | self, |
| 63 | *, |
| 64 | branch: str, |
| 65 | message: str, |
| 66 | paths: list[str], |
| 67 | ) -> CommitResult | ReadError | WriteError: |
| 68 | unsafe = self._validate_paths(paths) |
| 69 | if unsafe: |
| 70 | return unsafe |
| 71 | if self._is_protected_branch(branch): |
| 72 | return WriteError( |
| 73 | "commit_feature", |
| 74 | f"refused protected branch {branch!r}", |
| 75 | ) |
| 76 | |
| 77 | checkout = self._muse("checkout", branch) |
| 78 | if isinstance(checkout, ReadError): |
| 79 | return checkout |
| 80 | |
| 81 | if paths: |
| 82 | for path in paths: |
| 83 | add = self._muse("add", path) |
| 84 | if isinstance(add, ReadError): |
| 85 | return add |
| 86 | |
| 87 | commit = self._muse("commit", "-m", message) |
| 88 | if isinstance(commit, ReadError): |
| 89 | return commit |
| 90 | |
| 91 | head = self._muse_rev_parse_sha("HEAD") |
| 92 | if isinstance(head, ReadError): |
| 93 | return head |
| 94 | return CommitResult(committed=True, sha=head.sha) |
| 95 | |
| 96 | def mirror(self, *, dry_run: bool) -> MirrorResult: |
| 97 | return MirrorResult( |
| 98 | diff_summary="", |
| 99 | pushed=False, |
| 100 | reason=GIT_FORBIDDEN, |
| 101 | ) |
| 102 | |
| 103 | def _git(self, *args: str) -> CommandResult | ReadError: |
| 104 | return ReadError("git", GIT_FORBIDDEN) |
File History
1 commit
sha256:4671b7f787ddbe63ced31c895b688c77ab495653b65a730b423329f26b3c1439
feat: K1-P1 complete — agent provenance, build-verification…
Sonnet 4.6
patch
53 days ago