@rui.branco/claude-commands-mcp 2.0.27 → 2.0.29

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/index.js +25 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -113,14 +113,8 @@ function gitPushSync() {
113
113
  }
114
114
 
115
115
  function gitPush(message) {
116
- if (needsRecovery()) gitRecover();
117
- execSync("git add -A", { cwd: CACHE_DIR, stdio: "pipe" });
118
- try {
119
- execSync(`git commit -m "${message}"`, { cwd: CACHE_DIR, stdio: "pipe" });
120
- } catch {
121
- return;
122
- }
123
- // Push in background — don't block the caller
116
+ // Everything runs in background — don't block the caller
117
+ const escapedMessage = message.replace(/"/g, '\\"');
124
118
  const child = spawn(
125
119
  "node",
126
120
  [
@@ -128,6 +122,14 @@ function gitPush(message) {
128
122
  `
129
123
  const { execSync } = require("child_process");
130
124
  const cwd = ${JSON.stringify(CACHE_DIR)};
125
+ try { const s = execSync("git status --porcelain -b", { cwd, stdio: "pipe" }).toString();
126
+ if (s.includes("no branch") || s.includes("rebase")) {
127
+ try { execSync("git rebase --abort", { cwd, stdio: "pipe" }); } catch {}
128
+ try { execSync("git checkout main", { cwd, stdio: "pipe" }); } catch {}
129
+ }
130
+ } catch {}
131
+ execSync("git add -A", { cwd, stdio: "pipe" });
132
+ try { execSync('git commit -m "${escapedMessage}"', { cwd, stdio: "pipe" }); } catch { process.exit(0); }
131
133
  for (let i = 0; i < 3; i++) {
132
134
  try { execSync("git push", { cwd, stdio: "pipe" }); process.exit(0); } catch {}
133
135
  try { execSync("git pull --rebase", { cwd, stdio: "pipe" }); } catch {
@@ -304,7 +306,7 @@ server.tool(
304
306
  // Tool: save a file and push to git
305
307
  server.tool(
306
308
  "save_file",
307
- "Save/update a file in the commands directory and push to git. Use for tracking data, skill updates, or any file that should persist.",
309
+ "Save/update a file in the commands directory and push to git. Use for tracking data, skill updates, or any file that should persist. Use append:true for tracking files to add content without overwriting existing data (single tool call, no need to read first).",
308
310
  {
309
311
  path: z
310
312
  .string()
@@ -312,12 +314,18 @@ server.tool(
312
314
  "File path relative to commands/ (e.g. 'folder/tracking/2026-02-07.md')",
313
315
  ),
314
316
  content: z.string().describe("The file content to save"),
317
+ append: z
318
+ .boolean()
319
+ .optional()
320
+ .describe(
321
+ "If true, appends content to the existing file instead of overwriting. Creates the file if it doesn't exist.",
322
+ ),
315
323
  message: z
316
324
  .string()
317
325
  .optional()
318
326
  .describe("Git commit message (auto-generated if not provided)"),
319
327
  },
320
- async ({ path, content, message }) => {
328
+ async ({ path, content, append, message }) => {
321
329
  try {
322
330
  // If path has no extension but a .md file exists, use that (matches get_skill behavior)
323
331
  if (!extname(path)) {
@@ -331,7 +339,12 @@ server.tool(
331
339
  mkdirSync(fileDir, { recursive: true });
332
340
  }
333
341
 
334
- writeFileSync(filePath, content, "utf-8");
342
+ if (append && existsSync(filePath)) {
343
+ const existing = readFileSync(filePath, "utf-8");
344
+ writeFileSync(filePath, existing + content, "utf-8");
345
+ } else {
346
+ writeFileSync(filePath, content, "utf-8");
347
+ }
335
348
 
336
349
  const commitMsg = message || `update: ${path}`;
337
350
  gitPush(commitMsg);
@@ -340,7 +353,7 @@ server.tool(
340
353
  content: [
341
354
  {
342
355
  type: "text",
343
- text: `Saved and pushed: commands/${path}`,
356
+ text: `${append ? "Appended to" : "Saved and pushed"}: commands/${path}`,
344
357
  },
345
358
  ],
346
359
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rui.branco/claude-commands-mcp",
3
- "version": "2.0.27",
3
+ "version": "2.0.29",
4
4
  "description": "MCP server that serves Claude Code skill definitions from a git repo",
5
5
  "type": "module",
6
6
  "main": "index.js",