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 | * Git Tools |
| #3 | * |
| #4 | * Built-in git operations for the automaton. |
| #5 | * Used for both state versioning and code development. |
| #6 | */ |
| #7 | /** |
| #8 | * Get git status for a repository. |
| #9 | */ |
| #10 | export async function gitStatus(runtime, repoPath) { |
| #11 | const result = await runtime.exec(`cd ${repoPath} && git status --porcelain -b 2>/dev/null`, 10000); |
| #12 | const lines = result.stdout.split("\n").filter(Boolean); |
| #13 | let branch = "unknown"; |
| #14 | const staged = []; |
| #15 | const modified = []; |
| #16 | const untracked = []; |
| #17 | for (const line of lines) { |
| #18 | if (line.startsWith("## ")) { |
| #19 | branch = line.slice(3).split("...")[0]; |
| #20 | continue; |
| #21 | } |
| #22 | const statusCode = line.slice(0, 2); |
| #23 | const file = line.slice(3); |
| #24 | if (statusCode[0] !== " " && statusCode[0] !== "?") { |
| #25 | staged.push(file); |
| #26 | } |
| #27 | if (statusCode[1] === "M" || statusCode[1] === "D") { |
| #28 | modified.push(file); |
| #29 | } |
| #30 | if (statusCode === "??") { |
| #31 | untracked.push(file); |
| #32 | } |
| #33 | } |
| #34 | return { |
| #35 | branch, |
| #36 | staged, |
| #37 | modified, |
| #38 | untracked, |
| #39 | clean: staged.length === 0 && modified.length === 0 && untracked.length === 0, |
| #40 | }; |
| #41 | } |
| #42 | /** |
| #43 | * Get git diff output. |
| #44 | */ |
| #45 | export async function gitDiff(runtime, repoPath, staged = false) { |
| #46 | const flag = staged ? "--cached" : ""; |
| #47 | const result = await runtime.exec(`cd ${repoPath} && git diff ${flag} 2>/dev/null`, 10000); |
| #48 | return result.stdout || "(no changes)"; |
| #49 | } |
| #50 | /** |
| #51 | * Create a git commit. |
| #52 | */ |
| #53 | export async function gitCommit(runtime, repoPath, message, addAll = true) { |
| #54 | if (addAll) { |
| #55 | await runtime.exec(`cd ${repoPath} && git add -A`, 10000); |
| #56 | } |
| #57 | const result = await runtime.exec(`cd ${repoPath} && git commit -m ${escapeShellArg(message)} --allow-empty 2>&1`, 10000); |
| #58 | if (result.exitCode !== 0) { |
| #59 | throw new Error(`Git commit failed: ${result.stderr || result.stdout}`); |
| #60 | } |
| #61 | return result.stdout; |
| #62 | } |
| #63 | /** |
| #64 | * Get git log. |
| #65 | */ |
| #66 | export async function gitLog(runtime, repoPath, limit = 10) { |
| #67 | const result = await runtime.exec(`cd ${repoPath} && git log --format="%H|%s|%an|%ai" -n ${limit} 2>/dev/null`, 10000); |
| #68 | if (!result.stdout.trim()) |
| #69 | return []; |
| #70 | return result.stdout |
| #71 | .trim() |
| #72 | .split("\n") |
| #73 | .map((line) => { |
| #74 | const [hash, message, author, date] = line.split("|"); |
| #75 | return { hash, message, author, date }; |
| #76 | }); |
| #77 | } |
| #78 | /** |
| #79 | * Push to remote. |
| #80 | */ |
| #81 | export async function gitPush(runtime, repoPath, remote = "origin", branch) { |
| #82 | const branchArg = branch ? ` ${branch}` : ""; |
| #83 | const result = await runtime.exec(`cd ${repoPath} && git push ${remote}${branchArg} 2>&1`, 30000); |
| #84 | if (result.exitCode !== 0) { |
| #85 | throw new Error(`Git push failed: ${result.stderr || result.stdout}`); |
| #86 | } |
| #87 | return result.stdout || "Push successful"; |
| #88 | } |
| #89 | /** |
| #90 | * Manage branches. |
| #91 | */ |
| #92 | export async function gitBranch(runtime, repoPath, action, branchName) { |
| #93 | let cmd; |
| #94 | switch (action) { |
| #95 | case "list": |
| #96 | cmd = `cd ${repoPath} && git branch -a 2>/dev/null`; |
| #97 | break; |
| #98 | case "create": |
| #99 | if (!branchName) |
| #100 | throw new Error("Branch name required"); |
| #101 | cmd = `cd ${repoPath} && git checkout -b ${escapeShellArg(branchName)} 2>&1`; |
| #102 | break; |
| #103 | case "checkout": |
| #104 | if (!branchName) |
| #105 | throw new Error("Branch name required"); |
| #106 | cmd = `cd ${repoPath} && git checkout ${escapeShellArg(branchName)} 2>&1`; |
| #107 | break; |
| #108 | case "delete": |
| #109 | if (!branchName) |
| #110 | throw new Error("Branch name required"); |
| #111 | cmd = `cd ${repoPath} && git branch -d ${escapeShellArg(branchName)} 2>&1`; |
| #112 | break; |
| #113 | default: |
| #114 | throw new Error(`Unknown branch action: ${action}`); |
| #115 | } |
| #116 | const result = await runtime.exec(cmd, 10000); |
| #117 | return result.stdout || result.stderr || "Done"; |
| #118 | } |
| #119 | /** |
| #120 | * Clone a repository. |
| #121 | */ |
| #122 | export async function gitClone(runtime, url, targetPath, depth) { |
| #123 | const depthArg = depth ? ` --depth ${depth}` : ""; |
| #124 | const result = await runtime.exec(`git clone${depthArg} ${url} ${targetPath} 2>&1`, 120000); |
| #125 | if (result.exitCode !== 0) { |
| #126 | throw new Error(`Git clone failed: ${result.stderr || result.stdout}`); |
| #127 | } |
| #128 | return `Cloned ${url} to ${targetPath}`; |
| #129 | } |
| #130 | /** |
| #131 | * Initialize a git repository. |
| #132 | */ |
| #133 | export async function gitInit(runtime, repoPath) { |
| #134 | const result = await runtime.exec(`cd ${repoPath} && git init 2>&1`, 10000); |
| #135 | return result.stdout || "Git initialized"; |
| #136 | } |
| #137 | function escapeShellArg(arg) { |
| #138 | return `'${arg.replace(/'/g, "'\\''")}'`; |
| #139 | } |
| #140 | //# sourceMappingURL=tools.js.map |