just-git 0.1.2 → 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.
Files changed (2) hide show
  1. package/README.md +33 -33
  2. package/package.json +1 -1
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
- identity: { name: "Alice", email: "alice@example.com" },
18
+ identity: { name: "Alice", email: "alice@example.com" },
19
19
  });
20
20
 
21
21
  const bash = new Bash({
22
- cwd: "/repo",
23
- customCommands: [git],
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
- 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"] },
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
- const result = await next();
63
- auditLog.push({ command: `git ${event.command}`, exitCode: result.exitCode });
64
- return result;
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
- if (event.command === "push" && !(await getHumanApproval(event.rawArgs))) {
70
- return { stdout: "", stderr: "Push blocked — awaiting approval.\n", exitCode: 1 };
71
- }
72
- return next();
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
- 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();
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
- 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
- }
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
- if (!/^(feat|fix|docs|refactor|test|chore)(\(.+\))?:/.test(event.message)) {
112
- return { abort: true, message: "Commit message must follow conventional commits format" };
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
- onAgentCommit({ hash: event.hash, branch: event.branch, message: event.message });
143
+ onAgentCommit({ hash: event.hash, branch: event.branch, message: event.message });
144
144
  });
145
145
 
146
146
  git.on("post-push", (event) => {
147
- onAgentPush({ remote: event.remote, refs: event.refs });
147
+ onAgentPush({ remote: event.remote, refs: event.refs });
148
148
  });
149
149
  ```
150
150
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-git",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Git implementation for virtual bash environments. Pure TypeScript, zero dependencies.",
5
5
  "keywords": [
6
6
  "agent",