pi-git-commit 1.0.5 → 1.0.6
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 +7 -3
- package/index.ts +35 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# pi-git-commit
|
|
2
2
|
|
|
3
|
-
Keeps mutative git operations out of the agent's bash and provides a safe, reviewable commit flow in [pi-coding-agent](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent): a bash guard, a `git_commit` tool, and `/commit`
|
|
3
|
+
Keeps mutative git operations out of the agent's bash and provides a safe, reviewable commit flow in [pi-coding-agent](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent): a bash guard, a `git_commit` tool, and `/commit`, `/stop-commit` and `/toggle-allow-git` commands.
|
|
4
4
|
|
|
5
5
|
## What you get
|
|
6
6
|
|
|
7
7
|
- **Bash git guard.** Mutative git commands are blocked in the agent's bash tool — `add`, `stage`, `commit`, `push`, `pull`, `merge`, `rebase`, `reset`, `clean`, `rm`, `restore`, `switch`, `cherry-pick`, `revert`, `mv`, `init`, `clone`, index/object plumbing (`read-tree`, `checkout-index`, `merge-file`, `prune-packed`), plus mutative forms of `branch` (including creation, `-u`, `-f`, `-c`/`-C`/`--copy`, `-D`/`-M`, `--force`, `-t`/`--track`), `tag` (including creation), `checkout` (including whole-tree restores like `checkout -- .`), `stash`, `submodule`, `worktree`, `config`, `remote`, `apply`, `notes`, `update-ref`, `gc` and more. Read-only commands (`status`, `diff`, `log`, `fetch`, `branch`, `tag`, `stash list`, ...) stay allowed.
|
|
8
8
|
- **`git_commit` tool.** The agent stages everything and commits with a `FIX` / `IMPROVE` / `NEW` type prefix. Inactive by default: `/commit` activates it for the commit flow and it is disabled again after use, so the agent cannot commit on its own at other times.
|
|
9
|
-
- **`/commit` command.** Waits for queued messages to finish, stages all changes, shows the staged diff, activates the `git_commit` tool, and asks the agent to review it and commit via `git_commit` — never via bash.
|
|
9
|
+
- **`/commit` command.** Waits for queued messages to finish, stages all changes, shows the staged diff, activates the `git_commit` tool, and asks the agent to review it and commit via `git_commit` — never via bash. Run `/stop-commit` at any point to abort the flow.
|
|
10
|
+
- **`/stop-commit` command.** Aborts a pending commit flow: deactivates the `git_commit` tool and cancels a `/commit` that is still waiting for queued messages, so no commit is made.
|
|
10
11
|
- **`/toggle-allow-git` command.** Temporarily allows mutative git commands in bash for the current session. The guard re-arms on the next session.
|
|
11
12
|
|
|
12
13
|
## Quick start
|
|
@@ -28,7 +29,9 @@ Keeps mutative git operations out of the agent's bash and provides a safe, revie
|
|
|
28
29
|
}
|
|
29
30
|
```
|
|
30
31
|
|
|
31
|
-
4.
|
|
32
|
+
4. Changed your mind? Run `/stop-commit` to abort the flow before the agent commits.
|
|
33
|
+
|
|
34
|
+
5. If you need to run mutative git yourself, allow it for the session:
|
|
32
35
|
|
|
33
36
|
```text
|
|
34
37
|
/toggle-allow-git
|
|
@@ -70,6 +73,7 @@ Mutative git commands are blocked. Use /toggle-allow-git to allow for this sessi
|
|
|
70
73
|
## Troubleshooting
|
|
71
74
|
|
|
72
75
|
- **The agent refuses to commit.** The guard blocks `git commit` in bash by design. Run `/commit` and let the agent use the `git_commit` tool.
|
|
76
|
+
- **The agent stopped committing.** You ran `/stop-commit`, which aborted the pending flow. Run `/commit` again to start a new one.
|
|
73
77
|
- **"Nothing to commit (empty diff)."** There are no staged changes — make edits first, then run `/commit` again.
|
|
74
78
|
- **I need git in bash right now.** Run `/toggle-allow-git`; the guard re-arms automatically on the next session start.
|
|
75
79
|
|
package/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ const COMMIT_TYPES = ["FIX", "IMPROVE", "NEW"] as const;
|
|
|
5
5
|
|
|
6
6
|
export default function (pi: ExtensionAPI) {
|
|
7
7
|
let gitBlocked = true;
|
|
8
|
+
let commitFlowActive = false;
|
|
8
9
|
|
|
9
10
|
const PREFIXES = new Set(["sudo", "env", "command", "nohup", "nice", "time", "exec", "builtin", "doas", "eval", "timeout", "runuser", "pkexec"]);
|
|
10
11
|
const CONTROL_KEYWORDS = new Set(["if", "then", "else", "elif", "while", "until", "do", "case", "select"]);
|
|
@@ -272,6 +273,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
272
273
|
);
|
|
273
274
|
return { content: [{ type: "text", text: `✓ Committed: ${fullMessage}` }], details: {} };
|
|
274
275
|
} finally {
|
|
276
|
+
commitFlowActive = false;
|
|
275
277
|
deactivateGitCommit();
|
|
276
278
|
}
|
|
277
279
|
},
|
|
@@ -279,6 +281,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
279
281
|
|
|
280
282
|
pi.on("session_start", () => {
|
|
281
283
|
gitBlocked = true;
|
|
284
|
+
commitFlowActive = false;
|
|
282
285
|
deactivateGitCommit();
|
|
283
286
|
});
|
|
284
287
|
|
|
@@ -289,15 +292,18 @@ export default function (pi: ExtensionAPI) {
|
|
|
289
292
|
ctx.ui.notify("commit requires interactive mode", "error");
|
|
290
293
|
return;
|
|
291
294
|
}
|
|
295
|
+
commitFlowActive = true;
|
|
292
296
|
|
|
293
297
|
try {
|
|
294
298
|
await ctx.ui.setWorkingMessage("Waiting for queued messages to complete...");
|
|
295
299
|
await ctx.waitForIdle();
|
|
300
|
+
if (!commitFlowActive) return;
|
|
296
301
|
|
|
297
302
|
await ctx.ui.setWorkingMessage("Staging files...");
|
|
298
303
|
const addResult = await pi.exec("git", ["add", "."]);
|
|
299
304
|
if (addResult.code !== 0) {
|
|
300
305
|
ctx.ui.notify(`git add failed: ${addResult.stderr}`, "error");
|
|
306
|
+
commitFlowActive = false;
|
|
301
307
|
return;
|
|
302
308
|
}
|
|
303
309
|
|
|
@@ -305,17 +311,20 @@ export default function (pi: ExtensionAPI) {
|
|
|
305
311
|
const diffResult = await pi.exec("git", ["diff", "--staged"]);
|
|
306
312
|
if (diffResult.code !== 0) {
|
|
307
313
|
ctx.ui.notify(`git diff failed: ${diffResult.stderr}`, "error");
|
|
314
|
+
commitFlowActive = false;
|
|
308
315
|
return;
|
|
309
316
|
}
|
|
310
317
|
|
|
311
318
|
if (!diffResult.stdout.trim()) {
|
|
312
319
|
ctx.ui.notify("Nothing to commit (empty diff). Stage files first.", "warning");
|
|
320
|
+
commitFlowActive = false;
|
|
313
321
|
return;
|
|
314
322
|
}
|
|
315
323
|
|
|
316
324
|
const diff = diffResult.stdout || "(no changes staged)";
|
|
317
325
|
|
|
318
326
|
const prompt = `DO NOT use bash for git. Use ONLY the \`git_commit\` tool.\n\nReview staged changes:\n\`\`\`diff\n${diff}\`\`\`\n\nUse \`git_commit\` tool with:\n- type: FIX, IMPROVE, or NEW\n- message: brief description (imperative mood)`;
|
|
327
|
+
if (!commitFlowActive) return;
|
|
319
328
|
activateGitCommit();
|
|
320
329
|
pi.sendUserMessage(prompt, { deliverAs: "followUp" });
|
|
321
330
|
} finally {
|
|
@@ -323,6 +332,32 @@ export default function (pi: ExtensionAPI) {
|
|
|
323
332
|
}
|
|
324
333
|
},
|
|
325
334
|
});
|
|
335
|
+
|
|
336
|
+
pi.registerCommand("stop-commit", {
|
|
337
|
+
description: "Stop the pending commit flow started by /commit",
|
|
338
|
+
handler: async (_args, ctx) => {
|
|
339
|
+
if (!ctx.hasUI) {
|
|
340
|
+
ctx.ui.notify("stop-commit requires interactive mode", "error");
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const toolWasActive = pi.getActiveTools().includes("git_commit");
|
|
344
|
+
const flowWasActive = commitFlowActive;
|
|
345
|
+
commitFlowActive = false;
|
|
346
|
+
deactivateGitCommit();
|
|
347
|
+
if (toolWasActive) {
|
|
348
|
+
pi.sendMessage(
|
|
349
|
+
{ customType: "git-commit-stopped", content: "The user stopped the commit flow with /stop-commit. Do not attempt to commit. Do not mention this in your response.", display: false },
|
|
350
|
+
{ deliverAs: "steer" },
|
|
351
|
+
);
|
|
352
|
+
ctx.ui.notify("Commit flow stopped. The git_commit tool is deactivated.", "info");
|
|
353
|
+
} else if (flowWasActive) {
|
|
354
|
+
ctx.ui.notify("Commit flow stopped.", "info");
|
|
355
|
+
} else {
|
|
356
|
+
ctx.ui.notify("No commit flow in progress.", "info");
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
|
|
326
361
|
pi.registerCommand("toggle-allow-git", {
|
|
327
362
|
description: "Toggle whether mutative git commands are allowed in bash for this session",
|
|
328
363
|
handler: async (_args, ctx) => {
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-git-commit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Pi extension: block mutative git commands in bash and provide a git_commit tool plus /commit and /toggle-allow-git commands",
|
|
5
|
+
"description": "Pi extension: block mutative git commands in bash and provide a git_commit tool plus /commit, /stop-commit and /toggle-allow-git commands",
|
|
6
6
|
"main": "index.ts",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|