pi-git-commit 1.0.3 → 1.0.5
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 +3 -3
- package/index.ts +19 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Keeps mutative git operations out of the agent's bash and provides a safe, revie
|
|
|
24
24
|
```json
|
|
25
25
|
{
|
|
26
26
|
"type": "FIX",
|
|
27
|
-
"message": "
|
|
27
|
+
"message": "Correct the off-by-one in the retry loop"
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -51,9 +51,9 @@ pi install /path/to/pi-git-commit
|
|
|
51
51
|
| Field | Description |
|
|
52
52
|
| --- | --- |
|
|
53
53
|
| `type` | `FIX` (bug fix), `IMPROVE` (improvement), or `NEW` (new feature). |
|
|
54
|
-
| `message` | Commit message in imperative mood. Multi-line allowed for detailed changes. |
|
|
54
|
+
| `message` | Commit message in imperative mood, without the type prefix (it is added automatically). A leading type word matching the chosen type is stripped (with `:`, whitespace, or `-`/`—` separators, any casing, repeats included) so the type is never duplicated. Multi-line allowed for detailed changes. |
|
|
55
55
|
|
|
56
|
-
The tool runs `git add .` followed by `git commit -m "<TYPE>: <message>"` and reports staging or commit failures as tool errors. The tool is inactive by default and only becomes available when you run `/commit`; it is deactivated again after a single use (success or failure), so the agent cannot commit at arbitrary points in the conversation. If a commit fails, run `/commit` again to retry.
|
|
56
|
+
The tool runs `git add .` followed by `git commit -m "<TYPE>: <message>"` and reports staging or commit failures as tool errors. A leading type word in the message is stripped whenever it repeats the chosen type — with `:`, whitespace, or `-`/`—` separators, at any casing, repeated prefixes included — so the type never ends up duplicated: `FIX: Fix: ...`, `FIX: Fix ...`, and `fix - ...` all become `FIX: ...`. The tool is inactive by default and only becomes available when you run `/commit`; it is deactivated again after a single use (success or failure), so the agent cannot commit at arbitrary points in the conversation. If a commit fails, run `/commit` again to retry.
|
|
57
57
|
|
|
58
58
|
## The bash guard
|
|
59
59
|
|
package/index.ts
CHANGED
|
@@ -221,6 +221,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
|
|
224
|
+
const stripLeadingCommitType = (type: string, message: string): string => {
|
|
225
|
+
const typePrefixRe = new RegExp(`^${type}(?!\\p{L})\\s*[:–—\\-]?\\s*`, "iu");
|
|
226
|
+
let rest = message.trim();
|
|
227
|
+
let next = rest.replace(typePrefixRe, "").trim();
|
|
228
|
+
while (next !== rest) {
|
|
229
|
+
rest = next;
|
|
230
|
+
next = rest.replace(typePrefixRe, "").trim();
|
|
231
|
+
}
|
|
232
|
+
return rest;
|
|
233
|
+
};
|
|
234
|
+
|
|
224
235
|
pi.registerTool({
|
|
225
236
|
name: "git_commit",
|
|
226
237
|
label: "Git Commit",
|
|
@@ -240,11 +251,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
240
251
|
async execute(_toolCallId, params, signal, _onUpdate, _ctx) {
|
|
241
252
|
try {
|
|
242
253
|
const { type, message } = params;
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
254
|
+
const description = stripLeadingCommitType(type, message);
|
|
255
|
+
if (!description) {
|
|
245
256
|
return { content: [{ type: "text", text: "Commit message must not be empty." }], details: {}, isError: true };
|
|
246
257
|
}
|
|
247
|
-
const fullMessage = `${type}: ${
|
|
258
|
+
const fullMessage = `${type}: ${description}`;
|
|
248
259
|
const addResult = await pi.exec("git", ["add", "."], { signal });
|
|
249
260
|
if (addResult.code !== 0) {
|
|
250
261
|
return { content: [{ type: "text", text: `Staging failed: ${addResult.stderr}` }], details: {}, isError: true };
|
|
@@ -255,6 +266,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
255
266
|
return { content: [{ type: "text", text: `Commit failed: ${result.stderr}` }], details: {}, isError: true };
|
|
256
267
|
}
|
|
257
268
|
|
|
269
|
+
pi.sendMessage(
|
|
270
|
+
{ customType: "git-commit-deactivated", content: "The git_commit tool is now deactivated and cannot be used again until the user runs /commit to re-enable it. Do not mention this deactivation in your response.", display: false },
|
|
271
|
+
{ deliverAs: "steer" },
|
|
272
|
+
);
|
|
258
273
|
return { content: [{ type: "text", text: `✓ Committed: ${fullMessage}` }], details: {} };
|
|
259
274
|
} finally {
|
|
260
275
|
deactivateGitCommit();
|
|
@@ -300,7 +315,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
300
315
|
|
|
301
316
|
const diff = diffResult.stdout || "(no changes staged)";
|
|
302
317
|
|
|
303
|
-
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
|
|
318
|
+
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)`;
|
|
304
319
|
activateGitCommit();
|
|
305
320
|
pi.sendUserMessage(prompt, { deliverAs: "followUp" });
|
|
306
321
|
} finally {
|
package/package.json
CHANGED