just-git 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -34
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,12 +15,12 @@ import { Bash } from "just-bash";
|
|
|
15
15
|
import { createGit } from "just-git";
|
|
16
16
|
|
|
17
17
|
const git = createGit({
|
|
18
|
-
|
|
18
|
+
identity: { name: "Alice", email: "alice@example.com" },
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
const bash = new Bash({
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
cwd: "/repo",
|
|
23
|
+
customCommands: [git],
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
await bash.exec("git init");
|
|
@@ -43,10 +43,10 @@ await bash.exec("git log --oneline");
|
|
|
43
43
|
|
|
44
44
|
```ts
|
|
45
45
|
const git = createGit({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
identity: { name: "Agent Bot", email: "bot@company.com", locked: true },
|
|
47
|
+
credentials: async (url) => ({ type: "bearer", token: "ghp_..." }),
|
|
48
|
+
disabled: ["rebase"],
|
|
49
|
+
network: { allowed: ["github.com"] },
|
|
50
50
|
});
|
|
51
51
|
```
|
|
52
52
|
|
|
@@ -59,31 +59,31 @@ The `CommandEvent` provides the execution context: `{ command, rawArgs, fs, cwd,
|
|
|
59
59
|
```ts
|
|
60
60
|
// Audit log — record every command the agent runs
|
|
61
61
|
git.use(async (event, next) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
const result = await next();
|
|
63
|
+
auditLog.push({ command: `git ${event.command}`, exitCode: result.exitCode });
|
|
64
|
+
return result;
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
// Gate pushes on human approval
|
|
68
68
|
git.use(async (event, next) => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
if (event.command === "push" && !(await getHumanApproval(event.rawArgs))) {
|
|
70
|
+
return { stdout: "", stderr: "Push blocked — awaiting approval.\n", exitCode: 1 };
|
|
71
|
+
}
|
|
72
|
+
return next();
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
// Block commits that add large files (uses event.fs to read the worktree)
|
|
76
76
|
git.use(async (event, next) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
if (event.command === "add") {
|
|
78
|
+
for (const path of event.rawArgs.filter((a) => !a.startsWith("-"))) {
|
|
79
|
+
const resolved = path.startsWith("/") ? path : `${event.cwd}/${path}`;
|
|
80
|
+
const stat = await event.fs.stat(resolved).catch(() => null);
|
|
81
|
+
if (stat && stat.size > 5_000_000) {
|
|
82
|
+
return { stdout: "", stderr: `Blocked: ${path} exceeds 5 MB\n`, exitCode: 1 };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return next();
|
|
87
87
|
});
|
|
88
88
|
```
|
|
89
89
|
|
|
@@ -100,17 +100,17 @@ Pre-hooks can abort the operation by returning `{ abort: true, message? }`.
|
|
|
100
100
|
```ts
|
|
101
101
|
// Block secrets from being committed
|
|
102
102
|
git.on("pre-commit", (event) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
const forbidden = event.index.entries.filter((e) => /\.(env|pem|key)$/.test(e.path));
|
|
104
|
+
if (forbidden.length) {
|
|
105
|
+
return { abort: true, message: `Blocked: ${forbidden.map((e) => e.path).join(", ")}` };
|
|
106
|
+
}
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
// Enforce conventional commit messages
|
|
110
110
|
git.on("commit-msg", (event) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
if (!/^(feat|fix|docs|refactor|test|chore)(\(.+\))?:/.test(event.message)) {
|
|
112
|
+
return { abort: true, message: "Commit message must follow conventional commits format" };
|
|
113
|
+
}
|
|
114
114
|
});
|
|
115
115
|
```
|
|
116
116
|
|
|
@@ -140,11 +140,11 @@ Post-hooks are observational -- return value is ignored. Handlers are awaited in
|
|
|
140
140
|
```ts
|
|
141
141
|
// Feed agent activity to your UI or orchestration layer
|
|
142
142
|
git.on("post-commit", (event) => {
|
|
143
|
-
|
|
143
|
+
onAgentCommit({ hash: event.hash, branch: event.branch, message: event.message });
|
|
144
144
|
});
|
|
145
145
|
|
|
146
146
|
git.on("post-push", (event) => {
|
|
147
|
-
|
|
147
|
+
onAgentPush({ remote: event.remote, refs: event.refs });
|
|
148
148
|
});
|
|
149
149
|
```
|
|
150
150
|
|
|
@@ -233,7 +233,7 @@ Fire-and-forget events emitted on every object/ref write. Handler errors are cau
|
|
|
233
233
|
|
|
234
234
|
High fidelity to real git (2.53.0) state and output. Tested using real git as an [oracle](test/oracle/README.md) across hundreds of randomized command traces.
|
|
235
235
|
|
|
236
|
-
|
|
236
|
+
This library is not yet interoperable with real git on the same filesystem (e.g. if you're using just-bash backed by a real filesystem where real git is also used to interact with repos). Interoperability happens at the network layer — clone, fetch, and push speak the Smart HTTP protocol and exchange standard packfiles. The internal `.git` directory layout is not guaranteed to be compatible with real git.
|
|
237
237
|
|
|
238
238
|
## Disclaimer
|
|
239
239
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "just-git",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Git implementation for virtual bash environments. Pure TypeScript, zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"author": "blindmansion",
|
|
16
16
|
"repository": {
|
|
17
17
|
"type": "git",
|
|
18
|
-
"url": "https://github.com/blindmansion/just-git.git"
|
|
18
|
+
"url": "git+https://github.com/blindmansion/just-git.git"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"dist"
|