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 | import { execSync } from "child_process"; |
| #9 | const REPO_ROOT = process.cwd(); |
| #10 | function git(cmd) { |
| #11 | return execSync(`git ${cmd}`, { |
| #12 | cwd: REPO_ROOT, |
| #13 | encoding: "utf-8", |
| #14 | timeout: 15_000, |
| #15 | }).trim(); |
| #16 | } |
| #17 | /** |
| #18 | * Return origin URL (credentials stripped), current branch, and HEAD info. |
| #19 | */ |
| #20 | export function getRepoInfo() { |
| #21 | const rawUrl = git("config --get remote.origin.url"); |
| #22 | // Strip embedded credentials (https://user:token@host/... -> https://host/...) |
| #23 | const originUrl = rawUrl.replace(/\/\/[^@]+@/, "//"); |
| #24 | const branch = git("rev-parse --abbrev-ref HEAD"); |
| #25 | const headLine = git('log -1 --format="%h %s"'); |
| #26 | const [headHash, ...rest] = headLine.split(" "); |
| #27 | return { originUrl, branch, headHash, headMessage: rest.join(" ") }; |
| #28 | } |
| #29 | /** |
| #30 | * Fetch origin and report how many commits we're behind. |
| #31 | */ |
| #32 | export function checkUpstream() { |
| #33 | git("fetch origin main --quiet"); |
| #34 | const log = git("log HEAD..origin/main --oneline"); |
| #35 | if (!log) |
| #36 | return { behind: 0, commits: [] }; |
| #37 | const commits = log.split("\n").map((line) => { |
| #38 | const [hash, ...rest] = line.split(" "); |
| #39 | return { hash, message: rest.join(" ") }; |
| #40 | }); |
| #41 | return { behind: commits.length, commits }; |
| #42 | } |
| #43 | /** |
| #44 | * Return per-commit diffs for every commit ahead of HEAD on origin/main. |
| #45 | */ |
| #46 | export function getUpstreamDiffs() { |
| #47 | const log = git('log HEAD..origin/main --format="%H %an|||%s"'); |
| #48 | if (!log) |
| #49 | return []; |
| #50 | return log.split("\n").map((line) => { |
| #51 | const [hashAndAuthor, message] = line.split("|||"); |
| #52 | const parts = hashAndAuthor.split(" "); |
| #53 | const hash = parts[0]; |
| #54 | const author = parts.slice(1).join(" "); |
| #55 | let diff; |
| #56 | try { |
| #57 | diff = git(`diff ${hash}~1..${hash}`); |
| #58 | } |
| #59 | catch { |
| #60 | // First commit in the range may not have a parent |
| #61 | diff = git(`show ${hash} --format="" --stat`); |
| #62 | } |
| #63 | return { hash: hash.slice(0, 12), message, author, diff }; |
| #64 | }); |
| #65 | } |
| #66 | //# sourceMappingURL=upstream.js.map |