@releasekit/notes 0.3.0-next.3 → 0.3.0
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 +2 -0
- package/dist/cli.js +0 -173
- package/package.json +14 -12
- package/dist/aggregator-JZ3VUZKP.js +0 -13
- package/dist/chunk-QCF6V2IY.js +0 -135
- package/dist/chunk-QUBVC5LF.js +0 -1488
- package/dist/chunk-TSLTZ26C.js +0 -163
- package/dist/cli.cjs +0 -1939
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/index.cjs +0 -1866
- package/dist/index.d.cts +0 -219
- package/dist/index.d.ts +0 -219
- package/dist/index.js +0 -61
package/dist/chunk-QUBVC5LF.js
DELETED
|
@@ -1,1488 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatVersion,
|
|
3
|
-
renderMarkdown,
|
|
4
|
-
writeMarkdown
|
|
5
|
-
} from "./chunk-QCF6V2IY.js";
|
|
6
|
-
|
|
7
|
-
// src/core/config.ts
|
|
8
|
-
import {
|
|
9
|
-
loadAuth,
|
|
10
|
-
loadNotesConfig as loadSharedNotesConfig,
|
|
11
|
-
saveAuth
|
|
12
|
-
} from "@releasekit/config";
|
|
13
|
-
function loadConfig(projectDir = process.cwd(), configFile) {
|
|
14
|
-
const options = { cwd: projectDir, configPath: configFile };
|
|
15
|
-
return loadSharedNotesConfig(options) ?? getDefaultConfig();
|
|
16
|
-
}
|
|
17
|
-
function getDefaultConfig() {
|
|
18
|
-
return {
|
|
19
|
-
output: [{ format: "markdown", file: "CHANGELOG.md" }],
|
|
20
|
-
updateStrategy: "prepend"
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// src/errors/index.ts
|
|
25
|
-
import { EXIT_CODES, ReleaseKitError } from "@releasekit/core";
|
|
26
|
-
import { EXIT_CODES as EXIT_CODES2 } from "@releasekit/core";
|
|
27
|
-
var NotesError = class extends ReleaseKitError {
|
|
28
|
-
};
|
|
29
|
-
var InputParseError = class extends NotesError {
|
|
30
|
-
code = "INPUT_PARSE_ERROR";
|
|
31
|
-
suggestions = [
|
|
32
|
-
"Ensure input is valid JSON",
|
|
33
|
-
"Check that input matches expected schema",
|
|
34
|
-
"Use --input-source to specify format"
|
|
35
|
-
];
|
|
36
|
-
};
|
|
37
|
-
var TemplateError = class extends NotesError {
|
|
38
|
-
code = "TEMPLATE_ERROR";
|
|
39
|
-
suggestions = [
|
|
40
|
-
"Check template syntax",
|
|
41
|
-
"Ensure all required files exist (document, version, entry)",
|
|
42
|
-
"Verify template engine matches file extension"
|
|
43
|
-
];
|
|
44
|
-
};
|
|
45
|
-
var LLMError = class extends NotesError {
|
|
46
|
-
code = "LLM_ERROR";
|
|
47
|
-
suggestions = [
|
|
48
|
-
"Check API key is configured",
|
|
49
|
-
"Verify model name is correct",
|
|
50
|
-
"Check network connectivity",
|
|
51
|
-
"Try with --no-llm to skip LLM processing"
|
|
52
|
-
];
|
|
53
|
-
};
|
|
54
|
-
var GitHubError = class extends NotesError {
|
|
55
|
-
code = "GITHUB_ERROR";
|
|
56
|
-
suggestions = [
|
|
57
|
-
"Ensure GITHUB_TOKEN is set",
|
|
58
|
-
"Check token has repo scope",
|
|
59
|
-
"Verify repository exists and is accessible"
|
|
60
|
-
];
|
|
61
|
-
};
|
|
62
|
-
var ConfigError = class extends NotesError {
|
|
63
|
-
code = "CONFIG_ERROR";
|
|
64
|
-
suggestions = [
|
|
65
|
-
"Check config file syntax",
|
|
66
|
-
"Verify all required fields are present",
|
|
67
|
-
"Run releasekit-notes init to create default config"
|
|
68
|
-
];
|
|
69
|
-
};
|
|
70
|
-
function getExitCode(error) {
|
|
71
|
-
switch (error.code) {
|
|
72
|
-
case "CONFIG_ERROR":
|
|
73
|
-
return EXIT_CODES.CONFIG_ERROR;
|
|
74
|
-
case "INPUT_PARSE_ERROR":
|
|
75
|
-
return EXIT_CODES.INPUT_ERROR;
|
|
76
|
-
case "TEMPLATE_ERROR":
|
|
77
|
-
return EXIT_CODES.TEMPLATE_ERROR;
|
|
78
|
-
case "LLM_ERROR":
|
|
79
|
-
return EXIT_CODES.LLM_ERROR;
|
|
80
|
-
case "GITHUB_ERROR":
|
|
81
|
-
return EXIT_CODES.GITHUB_ERROR;
|
|
82
|
-
default:
|
|
83
|
-
return EXIT_CODES.GENERAL_ERROR;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// src/input/package-versioner.ts
|
|
88
|
-
import * as fs from "fs";
|
|
89
|
-
function normalizeEntryType(type) {
|
|
90
|
-
const typeMap = {
|
|
91
|
-
added: "added",
|
|
92
|
-
feat: "added",
|
|
93
|
-
feature: "added",
|
|
94
|
-
changed: "changed",
|
|
95
|
-
update: "changed",
|
|
96
|
-
refactor: "changed",
|
|
97
|
-
deprecated: "deprecated",
|
|
98
|
-
removed: "removed",
|
|
99
|
-
fixed: "fixed",
|
|
100
|
-
fix: "fixed",
|
|
101
|
-
security: "security",
|
|
102
|
-
sec: "security"
|
|
103
|
-
};
|
|
104
|
-
return typeMap[type.toLowerCase()] ?? "changed";
|
|
105
|
-
}
|
|
106
|
-
function parsePackageVersioner(json) {
|
|
107
|
-
let data;
|
|
108
|
-
try {
|
|
109
|
-
data = JSON.parse(json);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
throw new InputParseError(`Invalid JSON input: ${error instanceof Error ? error.message : String(error)}`);
|
|
112
|
-
}
|
|
113
|
-
if (!data.changelogs || !Array.isArray(data.changelogs)) {
|
|
114
|
-
throw new InputParseError('Input must contain a "changelogs" array');
|
|
115
|
-
}
|
|
116
|
-
const packages = data.changelogs.map((changelog) => ({
|
|
117
|
-
packageName: changelog.packageName,
|
|
118
|
-
version: changelog.version,
|
|
119
|
-
previousVersion: changelog.previousVersion,
|
|
120
|
-
revisionRange: changelog.revisionRange,
|
|
121
|
-
repoUrl: changelog.repoUrl,
|
|
122
|
-
date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "",
|
|
123
|
-
entries: changelog.entries.map((entry) => ({
|
|
124
|
-
type: normalizeEntryType(entry.type),
|
|
125
|
-
description: entry.description,
|
|
126
|
-
issueIds: entry.issueIds,
|
|
127
|
-
scope: entry.scope,
|
|
128
|
-
originalType: entry.originalType,
|
|
129
|
-
breaking: entry.breaking ?? entry.originalType?.includes("!") ?? false
|
|
130
|
-
}))
|
|
131
|
-
}));
|
|
132
|
-
const repoUrl = packages[0]?.repoUrl ?? null;
|
|
133
|
-
return {
|
|
134
|
-
source: "package-versioner",
|
|
135
|
-
packages,
|
|
136
|
-
metadata: {
|
|
137
|
-
repoUrl: repoUrl ?? void 0
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function parsePackageVersionerFile(filePath) {
|
|
142
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
143
|
-
return parsePackageVersioner(content);
|
|
144
|
-
}
|
|
145
|
-
async function parsePackageVersionerStdin() {
|
|
146
|
-
const chunks = [];
|
|
147
|
-
for await (const chunk of process.stdin) {
|
|
148
|
-
chunks.push(chunk);
|
|
149
|
-
}
|
|
150
|
-
const content = chunks.join("");
|
|
151
|
-
return parsePackageVersioner(content);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// src/output/json.ts
|
|
155
|
-
import * as fs2 from "fs";
|
|
156
|
-
import * as path from "path";
|
|
157
|
-
import { debug, info, success } from "@releasekit/core";
|
|
158
|
-
function renderJson(contexts) {
|
|
159
|
-
return JSON.stringify(
|
|
160
|
-
{
|
|
161
|
-
versions: contexts.map((ctx) => ({
|
|
162
|
-
packageName: ctx.packageName,
|
|
163
|
-
version: ctx.version,
|
|
164
|
-
previousVersion: ctx.previousVersion,
|
|
165
|
-
date: ctx.date,
|
|
166
|
-
entries: ctx.entries,
|
|
167
|
-
compareUrl: ctx.compareUrl
|
|
168
|
-
}))
|
|
169
|
-
},
|
|
170
|
-
null,
|
|
171
|
-
2
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
function writeJson(outputPath, contexts, dryRun) {
|
|
175
|
-
const content = renderJson(contexts);
|
|
176
|
-
if (dryRun) {
|
|
177
|
-
info(`Would write JSON output to ${outputPath}`);
|
|
178
|
-
debug("--- JSON Output Preview ---");
|
|
179
|
-
debug(content);
|
|
180
|
-
debug("--- End Preview ---");
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const dir = path.dirname(outputPath);
|
|
184
|
-
if (!fs2.existsSync(dir)) {
|
|
185
|
-
fs2.mkdirSync(dir, { recursive: true });
|
|
186
|
-
}
|
|
187
|
-
fs2.writeFileSync(outputPath, content, "utf-8");
|
|
188
|
-
success(`JSON output written to ${outputPath}`);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// src/core/pipeline.ts
|
|
192
|
-
import * as fs7 from "fs";
|
|
193
|
-
import * as path5 from "path";
|
|
194
|
-
import { debug as debug2, info as info3, success as success3, warn as warn3 } from "@releasekit/core";
|
|
195
|
-
|
|
196
|
-
// src/llm/defaults.ts
|
|
197
|
-
var LLM_DEFAULTS = {
|
|
198
|
-
timeout: 6e4,
|
|
199
|
-
maxTokens: 2e3,
|
|
200
|
-
temperature: 0.7,
|
|
201
|
-
concurrency: 5,
|
|
202
|
-
retry: {
|
|
203
|
-
maxAttempts: 3,
|
|
204
|
-
initialDelay: 1e3,
|
|
205
|
-
maxDelay: 3e4,
|
|
206
|
-
backoffFactor: 2
|
|
207
|
-
},
|
|
208
|
-
models: {
|
|
209
|
-
openai: "gpt-4o-mini",
|
|
210
|
-
"openai-compatible": "gpt-4o-mini",
|
|
211
|
-
anthropic: "claude-3-5-haiku-latest",
|
|
212
|
-
ollama: "llama3.2"
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// src/llm/anthropic.ts
|
|
217
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
218
|
-
|
|
219
|
-
// src/llm/base.ts
|
|
220
|
-
var BaseLLMProvider = class {
|
|
221
|
-
getTimeout(options) {
|
|
222
|
-
return options?.timeout ?? LLM_DEFAULTS.timeout;
|
|
223
|
-
}
|
|
224
|
-
getMaxTokens(options) {
|
|
225
|
-
return options?.maxTokens ?? LLM_DEFAULTS.maxTokens;
|
|
226
|
-
}
|
|
227
|
-
getTemperature(options) {
|
|
228
|
-
return options?.temperature ?? LLM_DEFAULTS.temperature;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
// src/llm/anthropic.ts
|
|
233
|
-
var AnthropicProvider = class extends BaseLLMProvider {
|
|
234
|
-
name = "anthropic";
|
|
235
|
-
client;
|
|
236
|
-
model;
|
|
237
|
-
constructor(config = {}) {
|
|
238
|
-
super();
|
|
239
|
-
const apiKey = config.apiKey ?? process.env.ANTHROPIC_API_KEY;
|
|
240
|
-
if (!apiKey) {
|
|
241
|
-
throw new LLMError("Anthropic API key not configured. Set ANTHROPIC_API_KEY or use --llm-api-key");
|
|
242
|
-
}
|
|
243
|
-
this.client = new Anthropic({ apiKey });
|
|
244
|
-
this.model = config.model ?? LLM_DEFAULTS.models.anthropic;
|
|
245
|
-
}
|
|
246
|
-
async complete(prompt, options) {
|
|
247
|
-
try {
|
|
248
|
-
const response = await this.client.messages.create({
|
|
249
|
-
model: this.model,
|
|
250
|
-
max_tokens: this.getMaxTokens(options),
|
|
251
|
-
messages: [{ role: "user", content: prompt }]
|
|
252
|
-
});
|
|
253
|
-
const firstBlock = response.content[0];
|
|
254
|
-
if (!firstBlock || firstBlock.type !== "text") {
|
|
255
|
-
throw new LLMError("Unexpected response format from Anthropic");
|
|
256
|
-
}
|
|
257
|
-
return firstBlock.text;
|
|
258
|
-
} catch (error) {
|
|
259
|
-
if (error instanceof LLMError) throw error;
|
|
260
|
-
throw new LLMError(`Anthropic API error: ${error instanceof Error ? error.message : String(error)}`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
// src/llm/ollama.ts
|
|
266
|
-
var OllamaProvider = class extends BaseLLMProvider {
|
|
267
|
-
name = "ollama";
|
|
268
|
-
baseURL;
|
|
269
|
-
model;
|
|
270
|
-
apiKey;
|
|
271
|
-
constructor(config = {}) {
|
|
272
|
-
super();
|
|
273
|
-
this.baseURL = config.baseURL ?? process.env.OLLAMA_BASE_URL ?? "http://localhost:11434";
|
|
274
|
-
this.model = config.model ?? LLM_DEFAULTS.models.ollama;
|
|
275
|
-
this.apiKey = config.apiKey ?? process.env.OLLAMA_API_KEY;
|
|
276
|
-
}
|
|
277
|
-
async complete(prompt, options) {
|
|
278
|
-
const requestBody = {
|
|
279
|
-
model: this.model,
|
|
280
|
-
messages: [{ role: "user", content: prompt }],
|
|
281
|
-
stream: false,
|
|
282
|
-
options: {
|
|
283
|
-
num_predict: this.getMaxTokens(options),
|
|
284
|
-
temperature: this.getTemperature(options)
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
try {
|
|
288
|
-
const headers = {
|
|
289
|
-
"Content-Type": "application/json"
|
|
290
|
-
};
|
|
291
|
-
if (this.apiKey) {
|
|
292
|
-
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
293
|
-
}
|
|
294
|
-
const baseUrl = this.baseURL.endsWith("/api") ? this.baseURL.slice(0, -4) : this.baseURL;
|
|
295
|
-
const response = await fetch(`${baseUrl}/api/chat`, {
|
|
296
|
-
method: "POST",
|
|
297
|
-
headers,
|
|
298
|
-
body: JSON.stringify(requestBody)
|
|
299
|
-
});
|
|
300
|
-
if (!response.ok) {
|
|
301
|
-
const text = await response.text();
|
|
302
|
-
throw new LLMError(`Ollama request failed: ${response.status} ${text}`);
|
|
303
|
-
}
|
|
304
|
-
const data = await response.json();
|
|
305
|
-
if (!data.message?.content) {
|
|
306
|
-
throw new LLMError("Empty response from Ollama");
|
|
307
|
-
}
|
|
308
|
-
return data.message.content;
|
|
309
|
-
} catch (error) {
|
|
310
|
-
if (error instanceof LLMError) throw error;
|
|
311
|
-
throw new LLMError(`Ollama error: ${error instanceof Error ? error.message : String(error)}`);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// src/llm/openai.ts
|
|
317
|
-
import OpenAI from "openai";
|
|
318
|
-
var OpenAIProvider = class extends BaseLLMProvider {
|
|
319
|
-
name = "openai";
|
|
320
|
-
client;
|
|
321
|
-
model;
|
|
322
|
-
constructor(config = {}) {
|
|
323
|
-
super();
|
|
324
|
-
const apiKey = config.apiKey ?? process.env.OPENAI_API_KEY;
|
|
325
|
-
if (!apiKey) {
|
|
326
|
-
throw new LLMError("OpenAI API key not configured. Set OPENAI_API_KEY or use --llm-api-key");
|
|
327
|
-
}
|
|
328
|
-
this.client = new OpenAI({
|
|
329
|
-
apiKey,
|
|
330
|
-
baseURL: config.baseURL
|
|
331
|
-
});
|
|
332
|
-
this.model = config.model ?? LLM_DEFAULTS.models.openai;
|
|
333
|
-
}
|
|
334
|
-
async complete(prompt, options) {
|
|
335
|
-
try {
|
|
336
|
-
const response = await this.client.chat.completions.create({
|
|
337
|
-
model: this.model,
|
|
338
|
-
messages: [{ role: "user", content: prompt }],
|
|
339
|
-
max_tokens: this.getMaxTokens(options),
|
|
340
|
-
temperature: this.getTemperature(options)
|
|
341
|
-
});
|
|
342
|
-
const content = response.choices[0]?.message?.content;
|
|
343
|
-
if (!content) {
|
|
344
|
-
throw new LLMError("Empty response from OpenAI");
|
|
345
|
-
}
|
|
346
|
-
return content;
|
|
347
|
-
} catch (error) {
|
|
348
|
-
if (error instanceof LLMError) throw error;
|
|
349
|
-
throw new LLMError(`OpenAI API error: ${error instanceof Error ? error.message : String(error)}`);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
// src/llm/openai-compatible.ts
|
|
355
|
-
import OpenAI2 from "openai";
|
|
356
|
-
var OpenAICompatibleProvider = class extends BaseLLMProvider {
|
|
357
|
-
name = "openai-compatible";
|
|
358
|
-
client;
|
|
359
|
-
model;
|
|
360
|
-
constructor(config) {
|
|
361
|
-
super();
|
|
362
|
-
const apiKey = config.apiKey ?? process.env.OPENAI_API_KEY ?? "dummy";
|
|
363
|
-
this.client = new OpenAI2({
|
|
364
|
-
apiKey,
|
|
365
|
-
baseURL: config.baseURL
|
|
366
|
-
});
|
|
367
|
-
this.model = config.model ?? LLM_DEFAULTS.models["openai-compatible"];
|
|
368
|
-
}
|
|
369
|
-
async complete(prompt, options) {
|
|
370
|
-
try {
|
|
371
|
-
const response = await this.client.chat.completions.create({
|
|
372
|
-
model: this.model,
|
|
373
|
-
messages: [{ role: "user", content: prompt }],
|
|
374
|
-
max_tokens: this.getMaxTokens(options),
|
|
375
|
-
temperature: this.getTemperature(options)
|
|
376
|
-
});
|
|
377
|
-
const content = response.choices[0]?.message?.content;
|
|
378
|
-
if (!content) {
|
|
379
|
-
throw new LLMError("Empty response from LLM");
|
|
380
|
-
}
|
|
381
|
-
return content;
|
|
382
|
-
} catch (error) {
|
|
383
|
-
if (error instanceof LLMError) throw error;
|
|
384
|
-
throw new LLMError(`LLM API error: ${error instanceof Error ? error.message : String(error)}`);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
// src/llm/tasks/categorize.ts
|
|
390
|
-
import { warn } from "@releasekit/core";
|
|
391
|
-
|
|
392
|
-
// src/llm/prompts.ts
|
|
393
|
-
function resolvePrompt(taskName, defaultPrompt, promptsConfig) {
|
|
394
|
-
if (!promptsConfig) return defaultPrompt;
|
|
395
|
-
const fullTemplate = promptsConfig.templates?.[taskName];
|
|
396
|
-
if (fullTemplate) return fullTemplate;
|
|
397
|
-
const additionalInstructions = promptsConfig.instructions?.[taskName];
|
|
398
|
-
if (additionalInstructions) {
|
|
399
|
-
const insertionPoint = defaultPrompt.lastIndexOf("Output only valid JSON");
|
|
400
|
-
if (insertionPoint !== -1) {
|
|
401
|
-
return `${defaultPrompt.slice(0, insertionPoint)}Additional instructions:
|
|
402
|
-
${additionalInstructions}
|
|
403
|
-
|
|
404
|
-
${defaultPrompt.slice(insertionPoint)}`;
|
|
405
|
-
}
|
|
406
|
-
return `${defaultPrompt}
|
|
407
|
-
|
|
408
|
-
Additional instructions:
|
|
409
|
-
${additionalInstructions}`;
|
|
410
|
-
}
|
|
411
|
-
return defaultPrompt;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// src/llm/scopes.ts
|
|
415
|
-
function getAllowedScopesFromCategories(categories) {
|
|
416
|
-
const scopeMap = /* @__PURE__ */ new Map();
|
|
417
|
-
for (const cat of categories) {
|
|
418
|
-
if (cat.scopes && cat.scopes.length > 0) {
|
|
419
|
-
scopeMap.set(cat.name, cat.scopes);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return scopeMap;
|
|
423
|
-
}
|
|
424
|
-
function resolveAllowedScopes(scopeConfig, categories, packageNames) {
|
|
425
|
-
if (!scopeConfig || scopeConfig.mode === "unrestricted") return null;
|
|
426
|
-
if (scopeConfig.mode === "none") return [];
|
|
427
|
-
if (scopeConfig.mode === "packages") return packageNames ?? [];
|
|
428
|
-
if (scopeConfig.mode === "restricted") {
|
|
429
|
-
const explicit = scopeConfig.rules?.allowed ?? [];
|
|
430
|
-
const all = new Set(explicit);
|
|
431
|
-
if (categories) {
|
|
432
|
-
const fromCategories = getAllowedScopesFromCategories(categories);
|
|
433
|
-
for (const scopes of fromCategories.values()) {
|
|
434
|
-
for (const s of scopes) all.add(s);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
return [...all];
|
|
438
|
-
}
|
|
439
|
-
return null;
|
|
440
|
-
}
|
|
441
|
-
function validateScope(scope, allowedScopes, rules) {
|
|
442
|
-
if (!scope || allowedScopes === null) return scope;
|
|
443
|
-
if (allowedScopes.length === 0) return void 0;
|
|
444
|
-
const caseSensitive = rules?.caseSensitive ?? false;
|
|
445
|
-
const normalise = (s) => caseSensitive ? s : s.toLowerCase();
|
|
446
|
-
const isAllowed = allowedScopes.some((a) => normalise(a) === normalise(scope));
|
|
447
|
-
if (isAllowed) return scope;
|
|
448
|
-
switch (rules?.invalidScopeAction ?? "remove") {
|
|
449
|
-
case "keep":
|
|
450
|
-
return scope;
|
|
451
|
-
case "fallback":
|
|
452
|
-
return rules?.fallbackScope;
|
|
453
|
-
default:
|
|
454
|
-
return void 0;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
function validateEntryScopes(entries, scopeConfig, categories) {
|
|
458
|
-
const allowedScopes = resolveAllowedScopes(scopeConfig, categories);
|
|
459
|
-
if (allowedScopes === null) return entries;
|
|
460
|
-
return entries.map((entry) => ({
|
|
461
|
-
...entry,
|
|
462
|
-
scope: validateScope(entry.scope, allowedScopes, scopeConfig?.rules)
|
|
463
|
-
}));
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// src/llm/tasks/categorize.ts
|
|
467
|
-
var DEFAULT_CATEGORIZE_PROMPT = `You are categorizing changelog entries for a software release.
|
|
468
|
-
|
|
469
|
-
Given the following entries, group them into meaningful categories (e.g., "Core", "UI", "API", "Performance", "Bug Fixes", "Documentation").
|
|
470
|
-
|
|
471
|
-
Output a JSON object where keys are category names and values are arrays of entry indices (0-based).
|
|
472
|
-
|
|
473
|
-
Entries:
|
|
474
|
-
{{entries}}
|
|
475
|
-
|
|
476
|
-
Output only valid JSON, nothing else:`;
|
|
477
|
-
function buildCustomCategorizePrompt(categories) {
|
|
478
|
-
const categoryList = categories.map((c) => {
|
|
479
|
-
const scopeInfo = c.scopes?.length ? ` Allowed scopes: ${c.scopes.join(", ")}.` : "";
|
|
480
|
-
return `- "${c.name}": ${c.description}${scopeInfo}`;
|
|
481
|
-
}).join("\n");
|
|
482
|
-
const scopeMap = getAllowedScopesFromCategories(categories);
|
|
483
|
-
let scopeInstructions = "";
|
|
484
|
-
if (scopeMap.size > 0) {
|
|
485
|
-
const entries = [];
|
|
486
|
-
for (const [catName, scopes] of scopeMap) {
|
|
487
|
-
entries.push(`For "${catName}", assign a scope from: ${scopes.join(", ")}.`);
|
|
488
|
-
}
|
|
489
|
-
scopeInstructions = `
|
|
490
|
-
|
|
491
|
-
${entries.join("\n")}
|
|
492
|
-
Only use scopes from these predefined lists. If an entry does not fit any scope, set scope to null.`;
|
|
493
|
-
}
|
|
494
|
-
return `You are categorizing changelog entries for a software release.
|
|
495
|
-
|
|
496
|
-
Given the following entries, group them into the specified categories. Only use the categories listed below in this exact order:
|
|
497
|
-
|
|
498
|
-
Categories:
|
|
499
|
-
${categoryList}${scopeInstructions}
|
|
500
|
-
|
|
501
|
-
Output a JSON object with two fields:
|
|
502
|
-
- "categories": an object where keys are category names and values are arrays of entry indices (0-based)
|
|
503
|
-
- "scopes": an object where keys are entry indices (as strings) and values are scope labels. Only include entries that have a valid scope from the predefined list.
|
|
504
|
-
|
|
505
|
-
Entries:
|
|
506
|
-
{{entries}}
|
|
507
|
-
|
|
508
|
-
Output only valid JSON, nothing else:`;
|
|
509
|
-
}
|
|
510
|
-
async function categorizeEntries(provider, entries, context) {
|
|
511
|
-
if (entries.length === 0) {
|
|
512
|
-
return [];
|
|
513
|
-
}
|
|
514
|
-
const entriesCopy = entries.map((e) => ({ ...e, scope: void 0 }));
|
|
515
|
-
const entriesText = entriesCopy.map((e, i) => `${i}. [${e.type}]: ${e.description}`).join("\n");
|
|
516
|
-
const hasCustomCategories = context.categories && context.categories.length > 0;
|
|
517
|
-
const defaultPrompt = hasCustomCategories ? buildCustomCategorizePrompt(context.categories) : DEFAULT_CATEGORIZE_PROMPT;
|
|
518
|
-
const promptTemplate = resolvePrompt("categorize", defaultPrompt, context.prompts);
|
|
519
|
-
const prompt = promptTemplate.replace("{{entries}}", entriesText);
|
|
520
|
-
try {
|
|
521
|
-
const response = await provider.complete(prompt);
|
|
522
|
-
const cleaned = response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim();
|
|
523
|
-
const parsed = JSON.parse(cleaned);
|
|
524
|
-
const result = [];
|
|
525
|
-
if (hasCustomCategories && parsed.categories) {
|
|
526
|
-
const categoryMap = parsed.categories;
|
|
527
|
-
const scopeMap = parsed.scopes || {};
|
|
528
|
-
for (const [indexStr, scope] of Object.entries(scopeMap)) {
|
|
529
|
-
const idx = Number.parseInt(indexStr, 10);
|
|
530
|
-
if (entriesCopy[idx] && scope && scope.trim()) {
|
|
531
|
-
entriesCopy[idx] = { ...entriesCopy[idx], scope: scope.trim() };
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
const validatedEntries = validateEntryScopes(entriesCopy, context.scopes, context.categories);
|
|
535
|
-
for (const [category, rawIndices] of Object.entries(categoryMap)) {
|
|
536
|
-
const indices = Array.isArray(rawIndices) ? rawIndices : [];
|
|
537
|
-
const categoryEntries = indices.map((i) => validatedEntries[i]).filter((e) => e !== void 0);
|
|
538
|
-
if (categoryEntries.length > 0) {
|
|
539
|
-
result.push({ category, entries: categoryEntries });
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
} else {
|
|
543
|
-
const categoryMap = parsed;
|
|
544
|
-
for (const [category, rawIndices] of Object.entries(categoryMap)) {
|
|
545
|
-
const indices = Array.isArray(rawIndices) ? rawIndices : [];
|
|
546
|
-
const categoryEntries = indices.map((i) => entriesCopy[i]).filter((e) => e !== void 0);
|
|
547
|
-
if (categoryEntries.length > 0) {
|
|
548
|
-
result.push({ category, entries: categoryEntries });
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
return result;
|
|
553
|
-
} catch (error) {
|
|
554
|
-
warn(
|
|
555
|
-
`LLM categorization failed, falling back to General: ${error instanceof Error ? error.message : String(error)}`
|
|
556
|
-
);
|
|
557
|
-
return [{ category: "General", entries: entriesCopy }];
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// src/llm/tasks/enhance.ts
|
|
562
|
-
var DEFAULT_ENHANCE_PROMPT = `You are improving changelog entries for a software project.
|
|
563
|
-
Given a technical commit message, rewrite it as a clear, user-friendly changelog entry.
|
|
564
|
-
|
|
565
|
-
Rules:
|
|
566
|
-
- Be concise (1-2 sentences max)
|
|
567
|
-
- Focus on user impact, not implementation details
|
|
568
|
-
- Don't use technical jargon unless necessary
|
|
569
|
-
- Preserve the scope if mentioned (e.g., "core:", "api:")
|
|
570
|
-
{{style}}
|
|
571
|
-
|
|
572
|
-
Original entry:
|
|
573
|
-
Type: {{type}}
|
|
574
|
-
{{#if scope}}Scope: {{scope}}{{/if}}
|
|
575
|
-
Description: {{description}}
|
|
576
|
-
|
|
577
|
-
Rewritten description (only output the new description, nothing else):`;
|
|
578
|
-
async function enhanceEntry(provider, entry, context) {
|
|
579
|
-
const styleText = context.style ? `- ${context.style}` : '- Use present tense ("Add feature" not "Added feature")';
|
|
580
|
-
const defaultPrompt = DEFAULT_ENHANCE_PROMPT.replace("{{style}}", styleText).replace("{{type}}", entry.type).replace("{{#if scope}}Scope: {{scope}}{{/if}}", entry.scope ? `Scope: ${entry.scope}` : "").replace("{{description}}", entry.description);
|
|
581
|
-
const prompt = resolvePrompt("enhance", defaultPrompt, context.prompts);
|
|
582
|
-
const response = await provider.complete(prompt);
|
|
583
|
-
return response.trim();
|
|
584
|
-
}
|
|
585
|
-
async function enhanceEntries(provider, entries, context, concurrency = LLM_DEFAULTS.concurrency) {
|
|
586
|
-
const results = [];
|
|
587
|
-
for (let i = 0; i < entries.length; i += concurrency) {
|
|
588
|
-
const batch = entries.slice(i, i + concurrency);
|
|
589
|
-
const batchResults = await Promise.all(
|
|
590
|
-
batch.map(async (entry) => {
|
|
591
|
-
try {
|
|
592
|
-
const newDescription = await enhanceEntry(provider, entry, context);
|
|
593
|
-
return { ...entry, description: newDescription };
|
|
594
|
-
} catch {
|
|
595
|
-
return entry;
|
|
596
|
-
}
|
|
597
|
-
})
|
|
598
|
-
);
|
|
599
|
-
results.push(...batchResults);
|
|
600
|
-
}
|
|
601
|
-
return results;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// src/llm/tasks/enhance-and-categorize.ts
|
|
605
|
-
import { warn as warn2 } from "@releasekit/core";
|
|
606
|
-
|
|
607
|
-
// src/utils/retry.ts
|
|
608
|
-
function sleep(ms) {
|
|
609
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
610
|
-
}
|
|
611
|
-
async function withRetry(fn, options = {}) {
|
|
612
|
-
const maxAttempts = options.maxAttempts ?? 3;
|
|
613
|
-
const initialDelay = options.initialDelay ?? 1e3;
|
|
614
|
-
const maxDelay = options.maxDelay ?? 3e4;
|
|
615
|
-
const backoffFactor = options.backoffFactor ?? 2;
|
|
616
|
-
let lastError;
|
|
617
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
618
|
-
try {
|
|
619
|
-
return await fn();
|
|
620
|
-
} catch (error) {
|
|
621
|
-
lastError = error;
|
|
622
|
-
if (attempt < maxAttempts - 1) {
|
|
623
|
-
const base = Math.min(initialDelay * backoffFactor ** attempt, maxDelay);
|
|
624
|
-
const jitter = base * 0.2 * (Math.random() * 2 - 1);
|
|
625
|
-
await sleep(Math.max(0, base + jitter));
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
throw lastError;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// src/llm/tasks/enhance-and-categorize.ts
|
|
633
|
-
function buildPrompt(entries, categories, style) {
|
|
634
|
-
const entriesText = entries.map((e, i) => `${i}. [${e.type}]${e.scope ? ` (${e.scope})` : ""}: ${e.description}`).join("\n");
|
|
635
|
-
const styleText = style || 'Use present tense ("Add feature" not "Added feature"). Be concise.';
|
|
636
|
-
const categorySection = categories ? `Categories (use ONLY these):
|
|
637
|
-
${categories.map((c) => {
|
|
638
|
-
const scopeInfo = c.scopes?.length ? ` Allowed scopes: ${c.scopes.join(", ")}.` : "";
|
|
639
|
-
return `- "${c.name}": ${c.description}${scopeInfo}`;
|
|
640
|
-
}).join("\n")}` : `Categories: Group into meaningful categories (e.g., "New", "Fixed", "Changed", "Removed").`;
|
|
641
|
-
let scopeInstruction = "";
|
|
642
|
-
if (categories) {
|
|
643
|
-
const scopeMap = getAllowedScopesFromCategories(categories);
|
|
644
|
-
if (scopeMap.size > 0) {
|
|
645
|
-
const parts = [];
|
|
646
|
-
for (const [catName, scopes] of scopeMap) {
|
|
647
|
-
parts.push(`For "${catName}" entries, assign a scope from: ${scopes.join(", ")}.`);
|
|
648
|
-
}
|
|
649
|
-
scopeInstruction = `
|
|
650
|
-
${parts.join("\n")}
|
|
651
|
-
Only use scopes from these predefined lists. Set scope to null if no scope applies.`;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
return `You are generating release notes for a software project. Given the following changelog entries, do two things:
|
|
655
|
-
|
|
656
|
-
1. **Rewrite** each entry as a clear, user-friendly description
|
|
657
|
-
2. **Categorize** each entry into the appropriate category
|
|
658
|
-
|
|
659
|
-
Style guidelines:
|
|
660
|
-
- ${styleText}
|
|
661
|
-
- Be concise (1 short sentence per entry)
|
|
662
|
-
- Focus on what changed, not implementation details
|
|
663
|
-
|
|
664
|
-
${categorySection}${scopeInstruction}
|
|
665
|
-
|
|
666
|
-
Entries:
|
|
667
|
-
${entriesText}
|
|
668
|
-
|
|
669
|
-
Output a JSON object with:
|
|
670
|
-
- "entries": array of objects, one per input entry (same order), each with: { "description": "rewritten text", "category": "CategoryName", "scope": "optional subcategory label or null" }
|
|
671
|
-
|
|
672
|
-
Output only valid JSON, nothing else:`;
|
|
673
|
-
}
|
|
674
|
-
async function enhanceAndCategorize(provider, entries, context) {
|
|
675
|
-
if (entries.length === 0) {
|
|
676
|
-
return { enhancedEntries: [], categories: [] };
|
|
677
|
-
}
|
|
678
|
-
const retryOpts = LLM_DEFAULTS.retry;
|
|
679
|
-
try {
|
|
680
|
-
return await withRetry(async () => {
|
|
681
|
-
const defaultPrompt = buildPrompt(entries, context.categories, context.style);
|
|
682
|
-
const prompt = resolvePrompt("enhanceAndCategorize", defaultPrompt, context.prompts);
|
|
683
|
-
const response = await provider.complete(prompt);
|
|
684
|
-
const cleaned = response.replace(/^```(?:json)?\n?/, "").replace(/\n?```$/, "").trim();
|
|
685
|
-
const parsed = JSON.parse(cleaned);
|
|
686
|
-
if (!Array.isArray(parsed.entries)) {
|
|
687
|
-
throw new Error('Response missing "entries" array');
|
|
688
|
-
}
|
|
689
|
-
const enhancedEntries = entries.map((original, i) => {
|
|
690
|
-
const result = parsed.entries[i];
|
|
691
|
-
if (!result) return original;
|
|
692
|
-
return {
|
|
693
|
-
...original,
|
|
694
|
-
description: result.description || original.description,
|
|
695
|
-
scope: result.scope || original.scope
|
|
696
|
-
};
|
|
697
|
-
});
|
|
698
|
-
const validatedEntries = validateEntryScopes(enhancedEntries, context.scopes, context.categories);
|
|
699
|
-
const categoryMap = /* @__PURE__ */ new Map();
|
|
700
|
-
for (let i = 0; i < parsed.entries.length; i++) {
|
|
701
|
-
const result = parsed.entries[i];
|
|
702
|
-
const category = result?.category || "General";
|
|
703
|
-
const entry = validatedEntries[i];
|
|
704
|
-
if (!entry) continue;
|
|
705
|
-
if (!categoryMap.has(category)) {
|
|
706
|
-
categoryMap.set(category, []);
|
|
707
|
-
}
|
|
708
|
-
categoryMap.get(category)?.push(entry);
|
|
709
|
-
}
|
|
710
|
-
const categories = [];
|
|
711
|
-
for (const [category, catEntries] of categoryMap) {
|
|
712
|
-
categories.push({ category, entries: catEntries });
|
|
713
|
-
}
|
|
714
|
-
return { enhancedEntries: validatedEntries, categories };
|
|
715
|
-
}, retryOpts);
|
|
716
|
-
} catch (error) {
|
|
717
|
-
warn2(
|
|
718
|
-
`Combined enhance+categorize failed after ${retryOpts.maxAttempts} attempts: ${error instanceof Error ? error.message : String(error)}`
|
|
719
|
-
);
|
|
720
|
-
return {
|
|
721
|
-
enhancedEntries: entries,
|
|
722
|
-
categories: [{ category: "General", entries }]
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// src/llm/tasks/release-notes.ts
|
|
728
|
-
var DEFAULT_RELEASE_NOTES_PROMPT = `You are writing release notes for a software project.
|
|
729
|
-
|
|
730
|
-
Create engaging, user-friendly release notes for the following changes.
|
|
731
|
-
|
|
732
|
-
Rules:
|
|
733
|
-
- Start with a brief introduction (1-2 sentences)
|
|
734
|
-
- Group related changes into sections
|
|
735
|
-
- Use friendly, approachable language
|
|
736
|
-
- Highlight breaking changes prominently
|
|
737
|
-
- End with a brief conclusion or call to action
|
|
738
|
-
- Use markdown formatting
|
|
739
|
-
|
|
740
|
-
Version: {{version}}
|
|
741
|
-
{{#if previousVersion}}Previous version: {{previousVersion}}{{/if}}
|
|
742
|
-
Date: {{date}}
|
|
743
|
-
|
|
744
|
-
Changes:
|
|
745
|
-
{{entries}}
|
|
746
|
-
|
|
747
|
-
Release notes (output only the markdown content):`;
|
|
748
|
-
async function generateReleaseNotes(provider, entries, context) {
|
|
749
|
-
if (entries.length === 0) {
|
|
750
|
-
return `## Release ${context.version ?? "v1.0.0"}
|
|
751
|
-
|
|
752
|
-
No notable changes in this release.`;
|
|
753
|
-
}
|
|
754
|
-
const entriesText = entries.map((e) => {
|
|
755
|
-
let line = `- [${e.type}]`;
|
|
756
|
-
if (e.scope) line += ` (${e.scope})`;
|
|
757
|
-
line += `: ${e.description}`;
|
|
758
|
-
if (e.breaking) line += " **BREAKING**";
|
|
759
|
-
return line;
|
|
760
|
-
}).join("\n");
|
|
761
|
-
const defaultPrompt = DEFAULT_RELEASE_NOTES_PROMPT.replace("{{version}}", context.version ?? "v1.0.0").replace(
|
|
762
|
-
"{{#if previousVersion}}Previous version: {{previousVersion}}{{/if}}",
|
|
763
|
-
context.previousVersion ? `Previous version: ${context.previousVersion}` : ""
|
|
764
|
-
).replace("{{date}}", context.date ?? (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "").replace("{{entries}}", entriesText);
|
|
765
|
-
const prompt = resolvePrompt("releaseNotes", defaultPrompt, context.prompts);
|
|
766
|
-
const response = await provider.complete(prompt);
|
|
767
|
-
return response.trim();
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
// src/llm/tasks/summarize.ts
|
|
771
|
-
var DEFAULT_SUMMARIZE_PROMPT = `You are creating a summary of changes for a software release.
|
|
772
|
-
|
|
773
|
-
Given the following changelog entries, create a brief summary (2-3 sentences) that captures the main themes of this release.
|
|
774
|
-
|
|
775
|
-
Entries:
|
|
776
|
-
{{entries}}
|
|
777
|
-
|
|
778
|
-
Summary (only output the summary, nothing else):`;
|
|
779
|
-
async function summarizeEntries(provider, entries, context) {
|
|
780
|
-
if (entries.length === 0) {
|
|
781
|
-
return "";
|
|
782
|
-
}
|
|
783
|
-
const entriesText = entries.map((e) => `- [${e.type}]${e.scope ? ` (${e.scope})` : ""}: ${e.description}`).join("\n");
|
|
784
|
-
const defaultPrompt = DEFAULT_SUMMARIZE_PROMPT.replace("{{entries}}", entriesText);
|
|
785
|
-
const prompt = resolvePrompt("summarize", defaultPrompt, context.prompts);
|
|
786
|
-
const response = await provider.complete(prompt);
|
|
787
|
-
return response.trim();
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
// src/llm/index.ts
|
|
791
|
-
function createProvider(config) {
|
|
792
|
-
const authKeys = loadAuth();
|
|
793
|
-
const apiKey = config.apiKey ?? authKeys[config.provider];
|
|
794
|
-
switch (config.provider) {
|
|
795
|
-
case "openai":
|
|
796
|
-
return new OpenAIProvider({
|
|
797
|
-
apiKey,
|
|
798
|
-
baseURL: config.baseURL,
|
|
799
|
-
model: config.model
|
|
800
|
-
});
|
|
801
|
-
case "anthropic":
|
|
802
|
-
return new AnthropicProvider({
|
|
803
|
-
apiKey,
|
|
804
|
-
model: config.model
|
|
805
|
-
});
|
|
806
|
-
case "ollama":
|
|
807
|
-
return new OllamaProvider({
|
|
808
|
-
apiKey,
|
|
809
|
-
baseURL: config.baseURL,
|
|
810
|
-
model: config.model
|
|
811
|
-
});
|
|
812
|
-
case "openai-compatible": {
|
|
813
|
-
if (!config.baseURL) {
|
|
814
|
-
throw new LLMError("openai-compatible provider requires baseURL");
|
|
815
|
-
}
|
|
816
|
-
return new OpenAICompatibleProvider({
|
|
817
|
-
apiKey,
|
|
818
|
-
baseURL: config.baseURL,
|
|
819
|
-
model: config.model
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
default:
|
|
823
|
-
throw new LLMError(`Unknown LLM provider: ${config.provider}`);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
// src/output/github-release.ts
|
|
828
|
-
import { Octokit } from "@octokit/rest";
|
|
829
|
-
import { info as info2, success as success2 } from "@releasekit/core";
|
|
830
|
-
var GitHubClient = class {
|
|
831
|
-
octokit;
|
|
832
|
-
owner;
|
|
833
|
-
repo;
|
|
834
|
-
constructor(options) {
|
|
835
|
-
const token = options.token ?? process.env.GITHUB_TOKEN;
|
|
836
|
-
if (!token) {
|
|
837
|
-
throw new GitHubError("GITHUB_TOKEN not set. Set it as an environment variable.");
|
|
838
|
-
}
|
|
839
|
-
this.octokit = new Octokit({ auth: token });
|
|
840
|
-
this.owner = options.owner;
|
|
841
|
-
this.repo = options.repo;
|
|
842
|
-
}
|
|
843
|
-
async createRelease(context, options = {}) {
|
|
844
|
-
const tagName = `v${context.version}`;
|
|
845
|
-
let body;
|
|
846
|
-
if (context.enhanced?.releaseNotes) {
|
|
847
|
-
body = context.enhanced.releaseNotes;
|
|
848
|
-
} else {
|
|
849
|
-
body = renderMarkdown([context]);
|
|
850
|
-
}
|
|
851
|
-
info2(`Creating GitHub release for ${tagName}`);
|
|
852
|
-
try {
|
|
853
|
-
const response = await this.octokit.repos.createRelease({
|
|
854
|
-
owner: this.owner,
|
|
855
|
-
repo: this.repo,
|
|
856
|
-
tag_name: tagName,
|
|
857
|
-
name: tagName,
|
|
858
|
-
body,
|
|
859
|
-
draft: options.draft ?? false,
|
|
860
|
-
prerelease: options.prerelease ?? false,
|
|
861
|
-
generate_release_notes: options.generateNotes ?? false
|
|
862
|
-
});
|
|
863
|
-
success2(`Release created: ${response.data.html_url}`);
|
|
864
|
-
return {
|
|
865
|
-
id: response.data.id,
|
|
866
|
-
htmlUrl: response.data.html_url,
|
|
867
|
-
tagName
|
|
868
|
-
};
|
|
869
|
-
} catch (error) {
|
|
870
|
-
throw new GitHubError(`Failed to create release: ${error instanceof Error ? error.message : String(error)}`);
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
async updateRelease(releaseId, context, options = {}) {
|
|
874
|
-
const tagName = `v${context.version}`;
|
|
875
|
-
let body;
|
|
876
|
-
if (context.enhanced?.releaseNotes) {
|
|
877
|
-
body = context.enhanced.releaseNotes;
|
|
878
|
-
} else {
|
|
879
|
-
body = renderMarkdown([context]);
|
|
880
|
-
}
|
|
881
|
-
info2(`Updating GitHub release ${releaseId}`);
|
|
882
|
-
try {
|
|
883
|
-
const response = await this.octokit.repos.updateRelease({
|
|
884
|
-
owner: this.owner,
|
|
885
|
-
repo: this.repo,
|
|
886
|
-
release_id: releaseId,
|
|
887
|
-
tag_name: tagName,
|
|
888
|
-
name: tagName,
|
|
889
|
-
body,
|
|
890
|
-
draft: options.draft ?? false,
|
|
891
|
-
prerelease: options.prerelease ?? false
|
|
892
|
-
});
|
|
893
|
-
success2(`Release updated: ${response.data.html_url}`);
|
|
894
|
-
return {
|
|
895
|
-
id: response.data.id,
|
|
896
|
-
htmlUrl: response.data.html_url,
|
|
897
|
-
tagName
|
|
898
|
-
};
|
|
899
|
-
} catch (error) {
|
|
900
|
-
throw new GitHubError(`Failed to update release: ${error instanceof Error ? error.message : String(error)}`);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
async getReleaseByTag(tag) {
|
|
904
|
-
try {
|
|
905
|
-
const response = await this.octokit.repos.getReleaseByTag({
|
|
906
|
-
owner: this.owner,
|
|
907
|
-
repo: this.repo,
|
|
908
|
-
tag
|
|
909
|
-
});
|
|
910
|
-
return {
|
|
911
|
-
id: response.data.id,
|
|
912
|
-
htmlUrl: response.data.html_url,
|
|
913
|
-
tagName: response.data.tag_name
|
|
914
|
-
};
|
|
915
|
-
} catch {
|
|
916
|
-
return null;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
};
|
|
920
|
-
function parseRepoUrl(repoUrl) {
|
|
921
|
-
const patterns = [
|
|
922
|
-
/^https:\/\/github\.com\/([^/]+)\/([^/]+)/,
|
|
923
|
-
/^git@github\.com:([^/]+)\/([^/]+)/,
|
|
924
|
-
/^github\.com\/([^/]+)\/([^/]+)/
|
|
925
|
-
];
|
|
926
|
-
for (const pattern of patterns) {
|
|
927
|
-
const match = repoUrl.match(pattern);
|
|
928
|
-
if (match?.[1] && match[2]) {
|
|
929
|
-
return {
|
|
930
|
-
owner: match[1],
|
|
931
|
-
repo: match[2].replace(/\.git$/, "")
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
return null;
|
|
936
|
-
}
|
|
937
|
-
async function createGitHubRelease(context, options) {
|
|
938
|
-
const client = new GitHubClient(options);
|
|
939
|
-
return client.createRelease(context, options);
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
// src/templates/ejs.ts
|
|
943
|
-
import * as fs3 from "fs";
|
|
944
|
-
import ejs from "ejs";
|
|
945
|
-
function renderEjs(template, context) {
|
|
946
|
-
try {
|
|
947
|
-
return ejs.render(template, context);
|
|
948
|
-
} catch (error) {
|
|
949
|
-
throw new TemplateError(`EJS render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
function renderEjsFile(filePath, context) {
|
|
953
|
-
if (!fs3.existsSync(filePath)) {
|
|
954
|
-
throw new TemplateError(`Template file not found: ${filePath}`);
|
|
955
|
-
}
|
|
956
|
-
const template = fs3.readFileSync(filePath, "utf-8");
|
|
957
|
-
return renderEjs(template, context);
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
// src/templates/handlebars.ts
|
|
961
|
-
import * as fs4 from "fs";
|
|
962
|
-
import * as path2 from "path";
|
|
963
|
-
import Handlebars from "handlebars";
|
|
964
|
-
function registerHandlebarsHelpers() {
|
|
965
|
-
Handlebars.registerHelper("capitalize", (str) => {
|
|
966
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
967
|
-
});
|
|
968
|
-
Handlebars.registerHelper("eq", (a, b) => {
|
|
969
|
-
return a === b;
|
|
970
|
-
});
|
|
971
|
-
Handlebars.registerHelper("ne", (a, b) => {
|
|
972
|
-
return a !== b;
|
|
973
|
-
});
|
|
974
|
-
Handlebars.registerHelper("join", (arr, separator) => {
|
|
975
|
-
return Array.isArray(arr) ? arr.join(separator) : "";
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
function renderHandlebars(template, context) {
|
|
979
|
-
registerHandlebarsHelpers();
|
|
980
|
-
try {
|
|
981
|
-
const compiled = Handlebars.compile(template);
|
|
982
|
-
return compiled(context);
|
|
983
|
-
} catch (error) {
|
|
984
|
-
throw new TemplateError(`Handlebars render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
function renderHandlebarsFile(filePath, context) {
|
|
988
|
-
if (!fs4.existsSync(filePath)) {
|
|
989
|
-
throw new TemplateError(`Template file not found: ${filePath}`);
|
|
990
|
-
}
|
|
991
|
-
const template = fs4.readFileSync(filePath, "utf-8");
|
|
992
|
-
return renderHandlebars(template, context);
|
|
993
|
-
}
|
|
994
|
-
function renderHandlebarsComposable(templateDir, context) {
|
|
995
|
-
registerHandlebarsHelpers();
|
|
996
|
-
const versionPath = path2.join(templateDir, "version.hbs");
|
|
997
|
-
const entryPath = path2.join(templateDir, "entry.hbs");
|
|
998
|
-
const documentPath = path2.join(templateDir, "document.hbs");
|
|
999
|
-
if (!fs4.existsSync(documentPath)) {
|
|
1000
|
-
throw new TemplateError(`Document template not found: ${documentPath}`);
|
|
1001
|
-
}
|
|
1002
|
-
if (fs4.existsSync(versionPath)) {
|
|
1003
|
-
Handlebars.registerPartial("version", fs4.readFileSync(versionPath, "utf-8"));
|
|
1004
|
-
}
|
|
1005
|
-
if (fs4.existsSync(entryPath)) {
|
|
1006
|
-
Handlebars.registerPartial("entry", fs4.readFileSync(entryPath, "utf-8"));
|
|
1007
|
-
}
|
|
1008
|
-
try {
|
|
1009
|
-
const compiled = Handlebars.compile(fs4.readFileSync(documentPath, "utf-8"));
|
|
1010
|
-
return compiled(context);
|
|
1011
|
-
} catch (error) {
|
|
1012
|
-
throw new TemplateError(`Handlebars render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
// src/templates/liquid.ts
|
|
1017
|
-
import * as fs5 from "fs";
|
|
1018
|
-
import * as path3 from "path";
|
|
1019
|
-
import { Liquid } from "liquidjs";
|
|
1020
|
-
function createLiquidEngine(root) {
|
|
1021
|
-
return new Liquid({
|
|
1022
|
-
root: root ? [root] : [],
|
|
1023
|
-
extname: ".liquid",
|
|
1024
|
-
cache: false
|
|
1025
|
-
});
|
|
1026
|
-
}
|
|
1027
|
-
function renderLiquid(template, context) {
|
|
1028
|
-
const engine = createLiquidEngine();
|
|
1029
|
-
try {
|
|
1030
|
-
return engine.renderSync(engine.parse(template), context);
|
|
1031
|
-
} catch (error) {
|
|
1032
|
-
throw new TemplateError(`Liquid render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
function renderLiquidFile(filePath, context) {
|
|
1036
|
-
if (!fs5.existsSync(filePath)) {
|
|
1037
|
-
throw new TemplateError(`Template file not found: ${filePath}`);
|
|
1038
|
-
}
|
|
1039
|
-
const template = fs5.readFileSync(filePath, "utf-8");
|
|
1040
|
-
return renderLiquid(template, context);
|
|
1041
|
-
}
|
|
1042
|
-
function renderLiquidComposable(templateDir, context) {
|
|
1043
|
-
const documentPath = path3.join(templateDir, "document.liquid");
|
|
1044
|
-
if (!fs5.existsSync(documentPath)) {
|
|
1045
|
-
throw new TemplateError(`Document template not found: ${documentPath}`);
|
|
1046
|
-
}
|
|
1047
|
-
const engine = createLiquidEngine(templateDir);
|
|
1048
|
-
try {
|
|
1049
|
-
return engine.renderFileSync("document", context);
|
|
1050
|
-
} catch (error) {
|
|
1051
|
-
throw new TemplateError(`Liquid render error: ${error instanceof Error ? error.message : String(error)}`);
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
// src/templates/loader.ts
|
|
1056
|
-
import * as fs6 from "fs";
|
|
1057
|
-
import * as path4 from "path";
|
|
1058
|
-
function getEngineFromFile(filePath) {
|
|
1059
|
-
const ext = path4.extname(filePath).toLowerCase();
|
|
1060
|
-
switch (ext) {
|
|
1061
|
-
case ".liquid":
|
|
1062
|
-
return "liquid";
|
|
1063
|
-
case ".hbs":
|
|
1064
|
-
case ".handlebars":
|
|
1065
|
-
return "handlebars";
|
|
1066
|
-
case ".ejs":
|
|
1067
|
-
return "ejs";
|
|
1068
|
-
default:
|
|
1069
|
-
throw new TemplateError(`Unknown template extension: ${ext}`);
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
function getRenderFn(engine) {
|
|
1073
|
-
switch (engine) {
|
|
1074
|
-
case "liquid":
|
|
1075
|
-
return renderLiquid;
|
|
1076
|
-
case "handlebars":
|
|
1077
|
-
return renderHandlebars;
|
|
1078
|
-
case "ejs":
|
|
1079
|
-
return renderEjs;
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
function getRenderFileFn(engine) {
|
|
1083
|
-
switch (engine) {
|
|
1084
|
-
case "liquid":
|
|
1085
|
-
return renderLiquidFile;
|
|
1086
|
-
case "handlebars":
|
|
1087
|
-
return renderHandlebarsFile;
|
|
1088
|
-
case "ejs":
|
|
1089
|
-
return renderEjsFile;
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
function detectTemplateMode(templatePath) {
|
|
1093
|
-
if (!fs6.existsSync(templatePath)) {
|
|
1094
|
-
throw new TemplateError(`Template path not found: ${templatePath}`);
|
|
1095
|
-
}
|
|
1096
|
-
const stat = fs6.statSync(templatePath);
|
|
1097
|
-
if (stat.isFile()) {
|
|
1098
|
-
return "single";
|
|
1099
|
-
}
|
|
1100
|
-
if (stat.isDirectory()) {
|
|
1101
|
-
return "composable";
|
|
1102
|
-
}
|
|
1103
|
-
throw new TemplateError(`Invalid template path: ${templatePath}`);
|
|
1104
|
-
}
|
|
1105
|
-
function renderSingleFile(templatePath, context, engine) {
|
|
1106
|
-
const resolvedEngine = engine ?? getEngineFromFile(templatePath);
|
|
1107
|
-
const renderFile = getRenderFileFn(resolvedEngine);
|
|
1108
|
-
return {
|
|
1109
|
-
content: renderFile(templatePath, context),
|
|
1110
|
-
engine: resolvedEngine
|
|
1111
|
-
};
|
|
1112
|
-
}
|
|
1113
|
-
function renderComposable(templateDir, context, engine) {
|
|
1114
|
-
const files = fs6.readdirSync(templateDir);
|
|
1115
|
-
const engineMap = {
|
|
1116
|
-
liquid: { document: "document.liquid", version: "version.liquid", entry: "entry.liquid" },
|
|
1117
|
-
handlebars: { document: "document.hbs", version: "version.hbs", entry: "entry.hbs" },
|
|
1118
|
-
ejs: { document: "document.ejs", version: "version.ejs", entry: "entry.ejs" }
|
|
1119
|
-
};
|
|
1120
|
-
let resolvedEngine;
|
|
1121
|
-
if (engine) {
|
|
1122
|
-
resolvedEngine = engine;
|
|
1123
|
-
} else {
|
|
1124
|
-
const detected = detectEngineFromFiles(templateDir, files);
|
|
1125
|
-
if (!detected) {
|
|
1126
|
-
throw new TemplateError(`Could not detect template engine. Found files: ${files.join(", ")}`);
|
|
1127
|
-
}
|
|
1128
|
-
resolvedEngine = detected;
|
|
1129
|
-
}
|
|
1130
|
-
if (resolvedEngine === "liquid") {
|
|
1131
|
-
return { content: renderLiquidComposable(templateDir, context), engine: resolvedEngine };
|
|
1132
|
-
}
|
|
1133
|
-
if (resolvedEngine === "handlebars") {
|
|
1134
|
-
return { content: renderHandlebarsComposable(templateDir, context), engine: resolvedEngine };
|
|
1135
|
-
}
|
|
1136
|
-
const expectedFiles = engineMap[resolvedEngine];
|
|
1137
|
-
const documentPath = path4.join(templateDir, expectedFiles.document);
|
|
1138
|
-
if (!fs6.existsSync(documentPath)) {
|
|
1139
|
-
throw new TemplateError(`Document template not found: ${expectedFiles.document}`);
|
|
1140
|
-
}
|
|
1141
|
-
const versionPath = path4.join(templateDir, expectedFiles.version);
|
|
1142
|
-
const entryPath = path4.join(templateDir, expectedFiles.entry);
|
|
1143
|
-
const render = getRenderFn(resolvedEngine);
|
|
1144
|
-
const entryTemplate = fs6.existsSync(entryPath) ? fs6.readFileSync(entryPath, "utf-8") : null;
|
|
1145
|
-
const versionTemplate = fs6.existsSync(versionPath) ? fs6.readFileSync(versionPath, "utf-8") : null;
|
|
1146
|
-
if (entryTemplate && versionTemplate) {
|
|
1147
|
-
const versionsWithEntries = context.versions.map((versionCtx) => {
|
|
1148
|
-
const entries = versionCtx.entries.map((entry) => {
|
|
1149
|
-
const entryCtx = { ...entry, packageName: versionCtx.packageName, version: versionCtx.version };
|
|
1150
|
-
return render(entryTemplate, entryCtx);
|
|
1151
|
-
});
|
|
1152
|
-
return render(versionTemplate, { ...versionCtx, renderedEntries: entries });
|
|
1153
|
-
});
|
|
1154
|
-
const docContext = { ...context, renderedVersions: versionsWithEntries };
|
|
1155
|
-
return {
|
|
1156
|
-
content: render(fs6.readFileSync(documentPath, "utf-8"), docContext),
|
|
1157
|
-
engine: resolvedEngine
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
return renderSingleFile(documentPath, context, resolvedEngine);
|
|
1161
|
-
}
|
|
1162
|
-
function detectEngineFromFiles(_dir, files) {
|
|
1163
|
-
if (files.some((f) => f.endsWith(".liquid"))) return "liquid";
|
|
1164
|
-
if (files.some((f) => f.endsWith(".hbs") || f.endsWith(".handlebars"))) return "handlebars";
|
|
1165
|
-
if (files.some((f) => f.endsWith(".ejs"))) return "ejs";
|
|
1166
|
-
return null;
|
|
1167
|
-
}
|
|
1168
|
-
function validateDocumentContext(context, templatePath) {
|
|
1169
|
-
if (!context.project?.name) {
|
|
1170
|
-
throw new TemplateError(`${templatePath}: DocumentContext missing required field "project.name"`);
|
|
1171
|
-
}
|
|
1172
|
-
if (!Array.isArray(context.versions)) {
|
|
1173
|
-
throw new TemplateError(`${templatePath}: DocumentContext missing required field "versions" (must be an array)`);
|
|
1174
|
-
}
|
|
1175
|
-
const requiredVersionFields = ["packageName", "version", "date", "entries"];
|
|
1176
|
-
for (const [i, v] of context.versions.entries()) {
|
|
1177
|
-
for (const field of requiredVersionFields) {
|
|
1178
|
-
if (v[field] === void 0 || v[field] === null) {
|
|
1179
|
-
throw new TemplateError(`${templatePath}: versions[${i}] missing required field "${field}"`);
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
if (!Array.isArray(v.entries)) {
|
|
1183
|
-
throw new TemplateError(`${templatePath}: versions[${i}].entries must be an array`);
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
function renderTemplate(templatePath, context, engine) {
|
|
1188
|
-
validateDocumentContext(context, templatePath);
|
|
1189
|
-
const mode = detectTemplateMode(templatePath);
|
|
1190
|
-
if (mode === "single") {
|
|
1191
|
-
return renderSingleFile(templatePath, context, engine);
|
|
1192
|
-
}
|
|
1193
|
-
return renderComposable(templatePath, context, engine);
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
// src/core/pipeline.ts
|
|
1197
|
-
function generateCompareUrl(repoUrl, from, to, packageName) {
|
|
1198
|
-
const isPackageSpecific = from.includes("@") && packageName && from.includes(packageName);
|
|
1199
|
-
let fromVersion;
|
|
1200
|
-
let toVersion;
|
|
1201
|
-
if (isPackageSpecific) {
|
|
1202
|
-
fromVersion = from;
|
|
1203
|
-
toVersion = `${packageName}@${to.startsWith("v") ? "" : "v"}${to}`;
|
|
1204
|
-
} else {
|
|
1205
|
-
fromVersion = from.replace(/^v/, "");
|
|
1206
|
-
toVersion = to.replace(/^v/, "");
|
|
1207
|
-
}
|
|
1208
|
-
if (/gitlab\.com/i.test(repoUrl)) {
|
|
1209
|
-
return `${repoUrl}/-/compare/${fromVersion}...${toVersion}`;
|
|
1210
|
-
}
|
|
1211
|
-
if (/bitbucket\.org/i.test(repoUrl)) {
|
|
1212
|
-
return `${repoUrl}/branches/compare/${fromVersion}..${toVersion}`;
|
|
1213
|
-
}
|
|
1214
|
-
return `${repoUrl}/compare/${fromVersion}...${toVersion}`;
|
|
1215
|
-
}
|
|
1216
|
-
function createTemplateContext(pkg) {
|
|
1217
|
-
const compareUrl = pkg.repoUrl && pkg.previousVersion ? generateCompareUrl(pkg.repoUrl, pkg.previousVersion, pkg.version, pkg.packageName) : void 0;
|
|
1218
|
-
return {
|
|
1219
|
-
packageName: pkg.packageName,
|
|
1220
|
-
version: pkg.version,
|
|
1221
|
-
previousVersion: pkg.previousVersion,
|
|
1222
|
-
date: pkg.date,
|
|
1223
|
-
repoUrl: pkg.repoUrl,
|
|
1224
|
-
entries: pkg.entries,
|
|
1225
|
-
compareUrl
|
|
1226
|
-
};
|
|
1227
|
-
}
|
|
1228
|
-
function createDocumentContext(contexts, repoUrl) {
|
|
1229
|
-
const compareUrls = {};
|
|
1230
|
-
for (const ctx of contexts) {
|
|
1231
|
-
if (ctx.compareUrl) {
|
|
1232
|
-
compareUrls[ctx.version] = ctx.compareUrl;
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
return {
|
|
1236
|
-
project: {
|
|
1237
|
-
name: contexts[0]?.packageName ?? "project",
|
|
1238
|
-
repoUrl
|
|
1239
|
-
},
|
|
1240
|
-
versions: contexts,
|
|
1241
|
-
compareUrls: Object.keys(compareUrls).length > 0 ? compareUrls : void 0
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1244
|
-
async function processWithLLM(context, config) {
|
|
1245
|
-
if (!config.llm) {
|
|
1246
|
-
return context;
|
|
1247
|
-
}
|
|
1248
|
-
const tasks = config.llm.tasks ?? {};
|
|
1249
|
-
const llmContext = {
|
|
1250
|
-
packageName: context.packageName,
|
|
1251
|
-
version: context.version,
|
|
1252
|
-
previousVersion: context.previousVersion ?? void 0,
|
|
1253
|
-
date: context.date,
|
|
1254
|
-
categories: config.llm.categories,
|
|
1255
|
-
style: config.llm.style,
|
|
1256
|
-
scopes: config.llm.scopes,
|
|
1257
|
-
prompts: config.llm.prompts
|
|
1258
|
-
};
|
|
1259
|
-
const enhanced = {
|
|
1260
|
-
entries: context.entries
|
|
1261
|
-
};
|
|
1262
|
-
try {
|
|
1263
|
-
info3(`Using LLM provider: ${config.llm.provider}${config.llm.model ? ` (${config.llm.model})` : ""}`);
|
|
1264
|
-
if (config.llm.baseURL) {
|
|
1265
|
-
info3(`LLM base URL: ${config.llm.baseURL}`);
|
|
1266
|
-
}
|
|
1267
|
-
const rawProvider = createProvider(config.llm);
|
|
1268
|
-
const retryOpts = config.llm.retry ?? LLM_DEFAULTS.retry;
|
|
1269
|
-
const provider = {
|
|
1270
|
-
name: rawProvider.name,
|
|
1271
|
-
complete: (prompt, opts) => withRetry(() => rawProvider.complete(prompt, opts), retryOpts)
|
|
1272
|
-
};
|
|
1273
|
-
const activeTasks = Object.entries(tasks).filter(([, enabled]) => enabled).map(([name]) => name);
|
|
1274
|
-
info3(`Running LLM tasks: ${activeTasks.join(", ")}`);
|
|
1275
|
-
if (tasks.enhance && tasks.categorize) {
|
|
1276
|
-
info3("Enhancing and categorizing entries with LLM...");
|
|
1277
|
-
const result = await enhanceAndCategorize(provider, context.entries, llmContext);
|
|
1278
|
-
enhanced.entries = result.enhancedEntries;
|
|
1279
|
-
enhanced.categories = {};
|
|
1280
|
-
for (const cat of result.categories) {
|
|
1281
|
-
enhanced.categories[cat.category] = cat.entries;
|
|
1282
|
-
}
|
|
1283
|
-
info3(`Enhanced ${enhanced.entries.length} entries into ${result.categories.length} categories`);
|
|
1284
|
-
} else {
|
|
1285
|
-
if (tasks.enhance) {
|
|
1286
|
-
info3("Enhancing entries with LLM...");
|
|
1287
|
-
enhanced.entries = await enhanceEntries(provider, context.entries, llmContext, config.llm.concurrency);
|
|
1288
|
-
info3(`Enhanced ${enhanced.entries.length} entries`);
|
|
1289
|
-
}
|
|
1290
|
-
if (tasks.categorize) {
|
|
1291
|
-
info3("Categorizing entries with LLM...");
|
|
1292
|
-
const categorized = await categorizeEntries(provider, enhanced.entries, llmContext);
|
|
1293
|
-
enhanced.categories = {};
|
|
1294
|
-
for (const cat of categorized) {
|
|
1295
|
-
enhanced.categories[cat.category] = cat.entries;
|
|
1296
|
-
}
|
|
1297
|
-
info3(`Created ${categorized.length} categories`);
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
if (tasks.summarize) {
|
|
1301
|
-
info3("Summarizing entries with LLM...");
|
|
1302
|
-
enhanced.summary = await summarizeEntries(provider, enhanced.entries, llmContext);
|
|
1303
|
-
if (enhanced.summary) {
|
|
1304
|
-
info3("Summary generated successfully");
|
|
1305
|
-
debug2(`Summary: ${enhanced.summary.substring(0, 100)}...`);
|
|
1306
|
-
} else {
|
|
1307
|
-
warn3("Summary generation returned empty result");
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
if (tasks.releaseNotes) {
|
|
1311
|
-
info3("Generating release notes with LLM...");
|
|
1312
|
-
enhanced.releaseNotes = await generateReleaseNotes(provider, enhanced.entries, llmContext);
|
|
1313
|
-
if (enhanced.releaseNotes) {
|
|
1314
|
-
info3("Release notes generated successfully");
|
|
1315
|
-
} else {
|
|
1316
|
-
warn3("Release notes generation returned empty result");
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
return {
|
|
1320
|
-
...context,
|
|
1321
|
-
enhanced
|
|
1322
|
-
};
|
|
1323
|
-
} catch (error) {
|
|
1324
|
-
warn3(`LLM processing failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1325
|
-
warn3("Falling back to raw entries");
|
|
1326
|
-
return context;
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
function getBuiltinTemplatePath(style) {
|
|
1330
|
-
let packageRoot;
|
|
1331
|
-
try {
|
|
1332
|
-
const currentUrl = import.meta.url;
|
|
1333
|
-
packageRoot = path5.dirname(new URL(currentUrl).pathname);
|
|
1334
|
-
packageRoot = path5.join(packageRoot, "..", "..");
|
|
1335
|
-
} catch {
|
|
1336
|
-
packageRoot = __dirname;
|
|
1337
|
-
}
|
|
1338
|
-
return path5.join(packageRoot, "templates", style);
|
|
1339
|
-
}
|
|
1340
|
-
async function generateWithTemplate(contexts, config, outputPath, dryRun) {
|
|
1341
|
-
let templatePath;
|
|
1342
|
-
if (config.templates?.path) {
|
|
1343
|
-
templatePath = path5.resolve(config.templates.path);
|
|
1344
|
-
} else {
|
|
1345
|
-
templatePath = getBuiltinTemplatePath("keep-a-changelog");
|
|
1346
|
-
}
|
|
1347
|
-
const documentContext = createDocumentContext(
|
|
1348
|
-
contexts,
|
|
1349
|
-
config.templates?.path ? void 0 : contexts[0]?.repoUrl ?? void 0
|
|
1350
|
-
);
|
|
1351
|
-
const result = renderTemplate(templatePath, documentContext, config.templates?.engine);
|
|
1352
|
-
if (dryRun) {
|
|
1353
|
-
info3(`Would write templated output to ${outputPath}`);
|
|
1354
|
-
debug2("--- Changelog Preview ---");
|
|
1355
|
-
debug2(result.content);
|
|
1356
|
-
debug2("--- End Preview ---");
|
|
1357
|
-
return;
|
|
1358
|
-
}
|
|
1359
|
-
if (outputPath === "-") {
|
|
1360
|
-
process.stdout.write(result.content);
|
|
1361
|
-
return;
|
|
1362
|
-
}
|
|
1363
|
-
const dir = path5.dirname(outputPath);
|
|
1364
|
-
if (!fs7.existsSync(dir)) {
|
|
1365
|
-
fs7.mkdirSync(dir, { recursive: true });
|
|
1366
|
-
}
|
|
1367
|
-
fs7.writeFileSync(outputPath, result.content, "utf-8");
|
|
1368
|
-
success3(`Changelog written to ${outputPath} (using ${result.engine} template)`);
|
|
1369
|
-
}
|
|
1370
|
-
async function runPipeline(input, config, dryRun) {
|
|
1371
|
-
debug2(`Processing ${input.packages.length} package(s)`);
|
|
1372
|
-
let contexts = input.packages.map(createTemplateContext);
|
|
1373
|
-
if (config.llm && !process.env.CHANGELOG_NO_LLM) {
|
|
1374
|
-
info3("Processing with LLM enhancement");
|
|
1375
|
-
contexts = await Promise.all(contexts.map((ctx) => processWithLLM(ctx, config)));
|
|
1376
|
-
}
|
|
1377
|
-
const files = [];
|
|
1378
|
-
for (const output of config.output) {
|
|
1379
|
-
const outputLabel = output.file ? `${output.format} output \u2192 ${output.file}` : `${output.format} output`;
|
|
1380
|
-
info3(`Generating ${outputLabel}`);
|
|
1381
|
-
switch (output.format) {
|
|
1382
|
-
case "markdown": {
|
|
1383
|
-
const file = output.file ?? "CHANGELOG.md";
|
|
1384
|
-
try {
|
|
1385
|
-
const effectiveTemplateConfig = output.templates ?? config.templates;
|
|
1386
|
-
if (effectiveTemplateConfig?.path || output.options?.template) {
|
|
1387
|
-
const configWithTemplate = { ...config, templates: effectiveTemplateConfig };
|
|
1388
|
-
await generateWithTemplate(contexts, configWithTemplate, file, dryRun);
|
|
1389
|
-
} else {
|
|
1390
|
-
writeMarkdown(file, contexts, config, dryRun);
|
|
1391
|
-
}
|
|
1392
|
-
if (!dryRun) files.push(file);
|
|
1393
|
-
} catch (error) {
|
|
1394
|
-
warn3(`Failed to write ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1395
|
-
}
|
|
1396
|
-
break;
|
|
1397
|
-
}
|
|
1398
|
-
case "json": {
|
|
1399
|
-
const file = output.file ?? "changelog.json";
|
|
1400
|
-
try {
|
|
1401
|
-
writeJson(file, contexts, dryRun);
|
|
1402
|
-
if (!dryRun) files.push(file);
|
|
1403
|
-
} catch (error) {
|
|
1404
|
-
warn3(`Failed to write ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1405
|
-
}
|
|
1406
|
-
break;
|
|
1407
|
-
}
|
|
1408
|
-
case "github-release": {
|
|
1409
|
-
if (dryRun) {
|
|
1410
|
-
info3("[DRY RUN] Would create GitHub release");
|
|
1411
|
-
break;
|
|
1412
|
-
}
|
|
1413
|
-
const firstContext = contexts[0];
|
|
1414
|
-
if (!firstContext) {
|
|
1415
|
-
warn3("No context available for GitHub release");
|
|
1416
|
-
break;
|
|
1417
|
-
}
|
|
1418
|
-
const repoUrl = firstContext.repoUrl;
|
|
1419
|
-
if (!repoUrl) {
|
|
1420
|
-
warn3("No repo URL available, cannot create GitHub release");
|
|
1421
|
-
break;
|
|
1422
|
-
}
|
|
1423
|
-
const parsed = parseRepoUrl(repoUrl);
|
|
1424
|
-
if (!parsed) {
|
|
1425
|
-
warn3(`Could not parse repo URL: ${repoUrl}`);
|
|
1426
|
-
break;
|
|
1427
|
-
}
|
|
1428
|
-
await createGitHubRelease(firstContext, {
|
|
1429
|
-
owner: parsed.owner,
|
|
1430
|
-
repo: parsed.repo,
|
|
1431
|
-
draft: output.options?.draft,
|
|
1432
|
-
prerelease: output.options?.prerelease
|
|
1433
|
-
});
|
|
1434
|
-
break;
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
if (config.monorepo?.mode) {
|
|
1439
|
-
const { detectMonorepo, writeMonorepoChangelogs } = await import("./aggregator-JZ3VUZKP.js");
|
|
1440
|
-
const cwd = process.cwd();
|
|
1441
|
-
const detected = detectMonorepo(cwd);
|
|
1442
|
-
if (detected.isMonorepo) {
|
|
1443
|
-
const monoFiles = writeMonorepoChangelogs(
|
|
1444
|
-
contexts,
|
|
1445
|
-
{
|
|
1446
|
-
rootPath: config.monorepo.rootPath ?? cwd,
|
|
1447
|
-
packagesPath: config.monorepo.packagesPath ?? detected.packagesPath,
|
|
1448
|
-
mode: config.monorepo.mode
|
|
1449
|
-
},
|
|
1450
|
-
config,
|
|
1451
|
-
dryRun
|
|
1452
|
-
);
|
|
1453
|
-
files.push(...monoFiles);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
const packageNotes = {};
|
|
1457
|
-
for (const ctx of contexts) {
|
|
1458
|
-
packageNotes[ctx.packageName] = formatVersion(ctx);
|
|
1459
|
-
}
|
|
1460
|
-
return { packageNotes, files };
|
|
1461
|
-
}
|
|
1462
|
-
async function processInput(inputJson, config, dryRun) {
|
|
1463
|
-
const input = parsePackageVersioner(inputJson);
|
|
1464
|
-
return runPipeline(input, config, dryRun);
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
export {
|
|
1468
|
-
loadAuth,
|
|
1469
|
-
saveAuth,
|
|
1470
|
-
loadConfig,
|
|
1471
|
-
getDefaultConfig,
|
|
1472
|
-
NotesError,
|
|
1473
|
-
InputParseError,
|
|
1474
|
-
TemplateError,
|
|
1475
|
-
LLMError,
|
|
1476
|
-
GitHubError,
|
|
1477
|
-
ConfigError,
|
|
1478
|
-
getExitCode,
|
|
1479
|
-
EXIT_CODES2 as EXIT_CODES,
|
|
1480
|
-
parsePackageVersioner,
|
|
1481
|
-
parsePackageVersionerFile,
|
|
1482
|
-
parsePackageVersionerStdin,
|
|
1483
|
-
renderJson,
|
|
1484
|
-
writeJson,
|
|
1485
|
-
createTemplateContext,
|
|
1486
|
-
runPipeline,
|
|
1487
|
-
processInput
|
|
1488
|
-
};
|