git-coco 0.22.3 → 0.22.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.
@@ -47,7 +47,7 @@ import { pathToFileURL } from 'url';
47
47
  /**
48
48
  * Current build version from package.json
49
49
  */
50
- const BUILD_VERSION = "0.22.3";
50
+ const BUILD_VERSION = "0.22.5";
51
51
 
52
52
  const isInteractive = (config) => {
53
53
  return config?.mode === 'interactive' || !!config?.interactive;
@@ -7960,6 +7960,40 @@ async function executeChainWithSchema(schema, llm, prompt, variables, options =
7960
7960
  }
7961
7961
  }
7962
7962
 
7963
+ /**
7964
+ * Utility function to ensure commit messages are properly formatted as strings
7965
+ * rather than JSON objects, whether they come as parsed objects or stringified JSON
7966
+ */
7967
+ function formatCommitMessage(result, options = {}) {
7968
+ const { append, ticketId, appendTicket } = options;
7969
+ // If it's a string, check if it contains a JSON object
7970
+ if (typeof result === 'string') {
7971
+ try {
7972
+ // Try to parse as JSON to see if it's a stringified object
7973
+ const parsed = JSON.parse(result);
7974
+ if (parsed && typeof parsed === 'object' && parsed.title && parsed.body) {
7975
+ // It's a stringified JSON object, format it properly
7976
+ const appendedText = append ? `\n\n${append}` : '';
7977
+ const ticketFooter = appendTicket && ticketId ? `\n\nPart of **${ticketId}**` : '';
7978
+ return `${parsed.title}\n\n${parsed.body}${appendedText}${ticketFooter}`;
7979
+ }
7980
+ }
7981
+ catch {
7982
+ // Not valid JSON, treat as regular string
7983
+ }
7984
+ return result;
7985
+ }
7986
+ // If it's already an object with title and body, format it
7987
+ if (typeof result === 'object' && result !== null && 'title' in result && 'body' in result) {
7988
+ const commitMsgObj = result;
7989
+ const appendedText = append ? `\n\n${append}` : '';
7990
+ const ticketFooter = appendTicket && ticketId ? `\n\nPart of **${ticketId}**` : '';
7991
+ return `${commitMsgObj.title}\n\n${commitMsgObj.body}${appendedText}${ticketFooter}`;
7992
+ }
7993
+ // Fallback - convert to string
7994
+ return String(result);
7995
+ }
7996
+
7963
7997
  /**
7964
7998
  * Extract the path from a file path string.
7965
7999
  * @param {string} filePath - The full file path.
@@ -11620,7 +11654,7 @@ ${schema.description}
11620
11654
  };
11621
11655
  // Use retry wrapper for commitlint validation with up to 4 total attempts
11622
11656
  // (2 automatic retries + 2 more if user chooses "Try again")
11623
- return await withRetry(generateCommitMessage, {
11657
+ const result = await withRetry(generateCommitMessage, {
11624
11658
  maxAttempts: 6, // Allow for multiple user retry requests
11625
11659
  shouldRetry: shouldRetryCommitlint,
11626
11660
  backoffMs: 0, // No delay needed for commitlint retries
@@ -11632,6 +11666,13 @@ ${schema.description}
11632
11666
  logger.verbose(`Retrying commit message generation (attempt ${attempt}): ${error.message}`, { color: 'yellow' });
11633
11667
  },
11634
11668
  });
11669
+ // Ensure we always return a properly formatted commit message string
11670
+ const ticketId = extractTicketIdFromBranchName(branchName);
11671
+ return formatCommitMessage(result, {
11672
+ append: argv.append,
11673
+ ticketId: ticketId || undefined,
11674
+ appendTicket: argv.appendTicket,
11675
+ });
11635
11676
  },
11636
11677
  noResult: async () => {
11637
11678
  await noResult$2({ git, logger });
package/dist/index.js CHANGED
@@ -69,7 +69,7 @@ var readline__namespace = /*#__PURE__*/_interopNamespaceDefault(readline);
69
69
  /**
70
70
  * Current build version from package.json
71
71
  */
72
- const BUILD_VERSION = "0.22.3";
72
+ const BUILD_VERSION = "0.22.5";
73
73
 
74
74
  const isInteractive = (config) => {
75
75
  return config?.mode === 'interactive' || !!config?.interactive;
@@ -7982,6 +7982,40 @@ async function executeChainWithSchema(schema, llm, prompt, variables, options =
7982
7982
  }
7983
7983
  }
7984
7984
 
7985
+ /**
7986
+ * Utility function to ensure commit messages are properly formatted as strings
7987
+ * rather than JSON objects, whether they come as parsed objects or stringified JSON
7988
+ */
7989
+ function formatCommitMessage(result, options = {}) {
7990
+ const { append, ticketId, appendTicket } = options;
7991
+ // If it's a string, check if it contains a JSON object
7992
+ if (typeof result === 'string') {
7993
+ try {
7994
+ // Try to parse as JSON to see if it's a stringified object
7995
+ const parsed = JSON.parse(result);
7996
+ if (parsed && typeof parsed === 'object' && parsed.title && parsed.body) {
7997
+ // It's a stringified JSON object, format it properly
7998
+ const appendedText = append ? `\n\n${append}` : '';
7999
+ const ticketFooter = appendTicket && ticketId ? `\n\nPart of **${ticketId}**` : '';
8000
+ return `${parsed.title}\n\n${parsed.body}${appendedText}${ticketFooter}`;
8001
+ }
8002
+ }
8003
+ catch {
8004
+ // Not valid JSON, treat as regular string
8005
+ }
8006
+ return result;
8007
+ }
8008
+ // If it's already an object with title and body, format it
8009
+ if (typeof result === 'object' && result !== null && 'title' in result && 'body' in result) {
8010
+ const commitMsgObj = result;
8011
+ const appendedText = append ? `\n\n${append}` : '';
8012
+ const ticketFooter = appendTicket && ticketId ? `\n\nPart of **${ticketId}**` : '';
8013
+ return `${commitMsgObj.title}\n\n${commitMsgObj.body}${appendedText}${ticketFooter}`;
8014
+ }
8015
+ // Fallback - convert to string
8016
+ return String(result);
8017
+ }
8018
+
7985
8019
  /**
7986
8020
  * Extract the path from a file path string.
7987
8021
  * @param {string} filePath - The full file path.
@@ -11642,7 +11676,7 @@ ${schema.description}
11642
11676
  };
11643
11677
  // Use retry wrapper for commitlint validation with up to 4 total attempts
11644
11678
  // (2 automatic retries + 2 more if user chooses "Try again")
11645
- return await withRetry(generateCommitMessage, {
11679
+ const result = await withRetry(generateCommitMessage, {
11646
11680
  maxAttempts: 6, // Allow for multiple user retry requests
11647
11681
  shouldRetry: shouldRetryCommitlint,
11648
11682
  backoffMs: 0, // No delay needed for commitlint retries
@@ -11654,6 +11688,13 @@ ${schema.description}
11654
11688
  logger.verbose(`Retrying commit message generation (attempt ${attempt}): ${error.message}`, { color: 'yellow' });
11655
11689
  },
11656
11690
  });
11691
+ // Ensure we always return a properly formatted commit message string
11692
+ const ticketId = extractTicketIdFromBranchName(branchName);
11693
+ return formatCommitMessage(result, {
11694
+ append: argv.append,
11695
+ ticketId: ticketId || undefined,
11696
+ appendTicket: argv.appendTicket,
11697
+ });
11657
11698
  },
11658
11699
  noResult: async () => {
11659
11700
  await noResult$2({ git, logger });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-coco",
3
- "version": "0.22.3",
3
+ "version": "0.22.5",
4
4
  "description": "zero-effort git commits with coco.",
5
5
  "author": "gfargo <ghfargo@gmail.com>",
6
6
  "license": "MIT",