repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * Upstream Awareness |
| #3 | * |
| #4 | * Helpers for the automaton to know its own git origin, |
| #5 | * detect new upstream commits, and review diffs. |
| #6 | * All git commands run locally via child_process (not sandbox API). |
| #7 | */ |
| #8 | |
| #9 | import { execSync } from "child_process"; |
| #10 | |
| #11 | const REPO_ROOT = process.cwd(); |
| #12 | |
| #13 | function git(cmd: string): string { |
| #14 | return execSync(`git ${cmd}`, { |
| #15 | cwd: REPO_ROOT, |
| #16 | encoding: "utf-8", |
| #17 | timeout: 15_000, |
| #18 | }).trim(); |
| #19 | } |
| #20 | |
| #21 | /** |
| #22 | * Return origin URL (credentials stripped), current branch, and HEAD info. |
| #23 | */ |
| #24 | export function getRepoInfo(): { |
| #25 | originUrl: string; |
| #26 | branch: string; |
| #27 | headHash: string; |
| #28 | headMessage: string; |
| #29 | } { |
| #30 | const rawUrl = git("config --get remote.origin.url"); |
| #31 | // Strip embedded credentials (https://user:token@host/... -> https://host/...) |
| #32 | const originUrl = rawUrl.replace(/\/\/[^@]+@/, "//"); |
| #33 | const branch = git("rev-parse --abbrev-ref HEAD"); |
| #34 | const headLine = git('log -1 --format="%h %s"'); |
| #35 | const [headHash, ...rest] = headLine.split(" "); |
| #36 | return { originUrl, branch, headHash, headMessage: rest.join(" ") }; |
| #37 | } |
| #38 | |
| #39 | /** |
| #40 | * Fetch origin and report how many commits we're behind. |
| #41 | */ |
| #42 | export function checkUpstream(): { |
| #43 | behind: number; |
| #44 | commits: { hash: string; message: string }[]; |
| #45 | } { |
| #46 | git("fetch origin main --quiet"); |
| #47 | const log = git("log HEAD..origin/main --oneline"); |
| #48 | if (!log) return { behind: 0, commits: [] }; |
| #49 | const commits = log.split("\n").map((line) => { |
| #50 | const [hash, ...rest] = line.split(" "); |
| #51 | return { hash, message: rest.join(" ") }; |
| #52 | }); |
| #53 | return { behind: commits.length, commits }; |
| #54 | } |
| #55 | |
| #56 | /** |
| #57 | * Return per-commit diffs for every commit ahead of HEAD on origin/main. |
| #58 | */ |
| #59 | export function getUpstreamDiffs(): { |
| #60 | hash: string; |
| #61 | message: string; |
| #62 | author: string; |
| #63 | diff: string; |
| #64 | }[] { |
| #65 | const log = git('log HEAD..origin/main --format="%H %an|||%s"'); |
| #66 | if (!log) return []; |
| #67 | |
| #68 | return log.split("\n").map((line) => { |
| #69 | const [hashAndAuthor, message] = line.split("|||"); |
| #70 | const parts = hashAndAuthor.split(" "); |
| #71 | const hash = parts[0]; |
| #72 | const author = parts.slice(1).join(" "); |
| #73 | let diff: string; |
| #74 | try { |
| #75 | diff = git(`diff ${hash}~1..${hash}`); |
| #76 | } catch { |
| #77 | // First commit in the range may not have a parent |
| #78 | diff = git(`show ${hash} --format="" --stat`); |
| #79 | } |
| #80 | return { hash: hash.slice(0, 12), message, author, diff }; |
| #81 | }); |
| #82 | } |
| #83 |