newpr 1.0.12 → 1.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "newpr",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "AI-powered large PR review tool - understand PRs with 1000+ lines of changes",
5
5
  "module": "src/cli/index.ts",
6
6
  "type": "module",
@@ -2,6 +2,24 @@ import type { LlmClient } from "../llm/client.ts";
2
2
  import type { StackGroup } from "./types.ts";
3
3
 
4
4
  const MAX_TITLE_LENGTH = 72;
5
+ const TYPE_PREFIX: Record<string, string> = {
6
+ feature: "feat",
7
+ feat: "feat",
8
+ bugfix: "fix",
9
+ fix: "fix",
10
+ refactor: "refactor",
11
+ chore: "chore",
12
+ docs: "docs",
13
+ test: "test",
14
+ config: "chore",
15
+ perf: "perf",
16
+ style: "style",
17
+ ci: "ci",
18
+ };
19
+
20
+ function normalizeTypePrefix(type: string): string {
21
+ return TYPE_PREFIX[type] ?? "chore";
22
+ }
5
23
 
6
24
  function sanitizeTitle(raw: string): string {
7
25
  let title = raw.trim().replace(/\.+$/, "");
@@ -13,13 +31,13 @@ function sanitizeTitle(raw: string): string {
13
31
 
14
32
  function fallbackTitle(g: StackGroup): string {
15
33
  const desc = g.description || g.name;
16
- const cleaned = desc.replace(/[^\w\s\-/.,()]/g, " ").replace(/\s+/g, " ").trim();
17
- const prefix = `${g.type}: `;
34
+ const cleaned = desc.replace(/[^\p{L}\p{N}\s\-/.,()]/gu, " ").replace(/\s+/g, " ").trim();
35
+ const prefix = `${normalizeTypePrefix(g.type)}: `;
18
36
  const maxDesc = MAX_TITLE_LENGTH - prefix.length;
19
37
  const truncated = cleaned.length > maxDesc
20
38
  ? cleaned.slice(0, maxDesc).replace(/\s\S*$/, "").trimEnd()
21
39
  : cleaned;
22
- return truncated ? `${prefix}${truncated}` : `${g.type}: ${g.name}`;
40
+ return truncated ? `${prefix}${truncated}` : `${prefix}${g.name}`;
23
41
  }
24
42
 
25
43
  export async function generatePrTitles(
@@ -37,7 +55,12 @@ export async function generatePrTitles(
37
55
  ].join("\n"))
38
56
  .join("\n\n");
39
57
 
40
- const lang = language && language !== "English" ? language : null;
58
+ const hasKoreanContext = /[가-힣]/.test(prTitle) || groups.some((g) => /[가-힣]/.test(`${g.name} ${g.description}`));
59
+ const lang = language && language !== "English" && language !== "auto"
60
+ ? language
61
+ : hasKoreanContext
62
+ ? "Korean"
63
+ : null;
41
64
  const langRule = lang
42
65
  ? `- Write the description part in ${lang}. Keep the type prefix (feat/fix/etc.) in English.`
43
66
  : "- Write the description in English.";
@@ -85,7 +108,14 @@ Generate a descriptive PR title (40-72 chars) for each group. Return JSON array:
85
108
 
86
109
  try {
87
110
  const cleaned = response.content.replace(/```(?:json)?\s*/g, "").replace(/```\s*/g, "").trim();
88
- const parsed = JSON.parse(cleaned) as Array<{ group_id: string; title: string }>;
111
+ let parsed: Array<{ group_id: string; title: string }> = [];
112
+ try {
113
+ parsed = JSON.parse(cleaned) as Array<{ group_id: string; title: string }>;
114
+ } catch {
115
+ const arrayMatch = cleaned.match(/\[[\s\S]*\]/);
116
+ if (!arrayMatch) throw new Error("No JSON array found in response");
117
+ parsed = JSON.parse(arrayMatch[0]) as Array<{ group_id: string; title: string }>;
118
+ }
89
119
  for (const item of parsed) {
90
120
  if (item.group_id && item.title?.trim()) {
91
121
  titles.set(item.group_id, sanitizeTitle(item.title));