ai-release-notes 0.3.0 → 0.4.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 +261 -12
- package/dist/bin/cli.js +428 -331
- package/dist/bin/cli.js.map +1 -1
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +25 -44
- package/dist/generator.js.map +1 -1
- package/dist/index.d.ts +17 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -1
- package/dist/index.js.map +1 -1
- package/dist/output-index.d.ts +71 -1
- package/dist/output-index.d.ts.map +1 -1
- package/dist/output-index.js +333 -1
- package/dist/output-index.js.map +1 -1
- package/dist/output-path.d.ts +61 -0
- package/dist/output-path.d.ts.map +1 -0
- package/dist/output-path.js +182 -0
- package/dist/output-path.js.map +1 -0
- package/dist/promote.d.ts +133 -0
- package/dist/promote.d.ts.map +1 -0
- package/dist/promote.js +0 -0
- package/dist/promote.js.map +1 -0
- package/dist/prompt-session.d.ts +172 -0
- package/dist/prompt-session.d.ts.map +1 -0
- package/dist/prompt-session.js +484 -0
- package/dist/prompt-session.js.map +1 -0
- package/dist/prompts/builder.d.ts +77 -0
- package/dist/prompts/builder.d.ts.map +1 -1
- package/dist/prompts/builder.js +134 -0
- package/dist/prompts/builder.js.map +1 -1
- package/dist/release-date.d.ts +14 -0
- package/dist/release-date.d.ts.map +1 -0
- package/dist/release-date.js +54 -0
- package/dist/release-date.js.map +1 -0
- package/dist/release-document.d.ts +150 -0
- package/dist/release-document.d.ts.map +1 -0
- package/dist/release-document.js +651 -0
- package/dist/release-document.js.map +1 -0
- package/dist/release.d.ts +27 -3
- package/dist/release.d.ts.map +1 -1
- package/dist/release.js +88 -2
- package/dist/release.js.map +1 -1
- package/dist/text-diff.d.ts +19 -0
- package/dist/text-diff.d.ts.map +1 -0
- package/dist/text-diff.js +81 -0
- package/dist/text-diff.js.map +1 -0
- package/dist/types.d.ts +10 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/prompts/release-notes-edit-system.md +48 -0
- package/prompts/release-notes-promote-opening.md +59 -0
- package/prompts/release-notes-session-router.md +68 -0
- package/dist/prompts/translation-system.md +0 -8
package/dist/bin/cli.js
CHANGED
|
@@ -14,6 +14,10 @@ const llm_js_1 = require("../llm.js");
|
|
|
14
14
|
const release_js_1 = require("../release.js");
|
|
15
15
|
const config_js_1 = require("../config.js");
|
|
16
16
|
const output_index_js_1 = require("../output-index.js");
|
|
17
|
+
const output_path_js_1 = require("../output-path.js");
|
|
18
|
+
const promote_js_1 = require("../promote.js");
|
|
19
|
+
const prompt_session_js_1 = require("../prompt-session.js");
|
|
20
|
+
const text_diff_js_1 = require("../text-diff.js");
|
|
17
21
|
const git_js_1 = require("../git.js");
|
|
18
22
|
const promises_1 = require("fs/promises");
|
|
19
23
|
const fs_1 = require("fs");
|
|
@@ -22,7 +26,6 @@ const clipboardy_1 = __importDefault(require("clipboardy"));
|
|
|
22
26
|
const ora_1 = __importDefault(require("ora"));
|
|
23
27
|
const version_js_1 = require("../version.js");
|
|
24
28
|
const CLI_VERSION = version_js_1.AI_RELEASE_NOTES_VERSION;
|
|
25
|
-
const LANGUAGE_PATH_PLACEHOLDER = "aireleasenoteslanguageplaceholder";
|
|
26
29
|
const program = new commander_1.Command();
|
|
27
30
|
function printStatus(stdout, message) {
|
|
28
31
|
if (stdout) {
|
|
@@ -31,6 +34,18 @@ function printStatus(stdout, message) {
|
|
|
31
34
|
}
|
|
32
35
|
console.log(message);
|
|
33
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The output format, under the one name the rest of the tool knows it by.
|
|
39
|
+
*
|
|
40
|
+
* `output.format` in the configuration has always said `markdown`, and so does
|
|
41
|
+
* every type here, so `md` on the command line is read as the same thing rather
|
|
42
|
+
* than being a second word for it.
|
|
43
|
+
*/
|
|
44
|
+
function releaseFormat(value) {
|
|
45
|
+
if (!value)
|
|
46
|
+
return undefined;
|
|
47
|
+
return value === "md" ? "markdown" : value;
|
|
48
|
+
}
|
|
34
49
|
/** Where a prompt comes from, for the verbose report. */
|
|
35
50
|
function describePromptSource(source) {
|
|
36
51
|
if (!source)
|
|
@@ -105,20 +120,19 @@ program
|
|
|
105
120
|
// ── generate ──
|
|
106
121
|
program
|
|
107
122
|
.command("generate")
|
|
108
|
-
.alias("gen")
|
|
109
123
|
.description("Generate release notes from git tags")
|
|
110
124
|
.option("--from <version>", `Previous version tag, or "${git_js_1.FIRST_RELEASE}" for the full history`, git_js_1.FIRST_RELEASE)
|
|
111
125
|
.option("--to <version>", "Current version tag (e.g. v1.1.0)")
|
|
112
126
|
.requiredOption("--env <environment>", "Environment: PROD, STAGING, DEV...")
|
|
113
|
-
.option("--
|
|
114
|
-
.option("--date <value>", 'Alias for --release-date ("now", "tag", or an ISO date)')
|
|
127
|
+
.option("--date <date>", 'Release date: "now", "tag", or an ISO date (default: now)')
|
|
115
128
|
.option("--with <provider>", "LLM provider override (claude, gpt4, mistral, gemini, ollama)")
|
|
129
|
+
.option("--lang <language>", "Write one configured language only")
|
|
116
130
|
.option("--config <path>", "Path to config file")
|
|
117
131
|
.option("--output <path>", "Output file path (override config)")
|
|
118
|
-
.option("--
|
|
119
|
-
.option("--format <format>", "Output format:
|
|
132
|
+
.option("--to-dir <dir>", "Write the release into this folder (default: current dir)")
|
|
133
|
+
.option("--format <format>", "Output format: markdown or html")
|
|
120
134
|
.option("--template <path>", "Path to custom template file")
|
|
121
|
-
.option("--changelog <path>", "Path to a file containing raw changelog (skip git)")
|
|
135
|
+
.option("--changelog-file <path>", "Path to a file containing raw changelog (skip git)")
|
|
122
136
|
.option("--context <paths...>", "Context files or directories (specs, models, etc.)")
|
|
123
137
|
.option("--dry-run", "Show prompts without calling LLM")
|
|
124
138
|
.option("-v, --verbose", "Show applied instructions and generation steps")
|
|
@@ -129,6 +143,7 @@ program
|
|
|
129
143
|
let config;
|
|
130
144
|
let summaryPrinted = false;
|
|
131
145
|
try {
|
|
146
|
+
const format = releaseFormat(opts.format);
|
|
132
147
|
// Start at the repository's first commit unless an explicit tag/ref is provided.
|
|
133
148
|
const fromVersion = opts.from;
|
|
134
149
|
let toVersion = opts.to;
|
|
@@ -147,15 +162,16 @@ program
|
|
|
147
162
|
fromVersion,
|
|
148
163
|
toVersion,
|
|
149
164
|
environment: opts.env,
|
|
150
|
-
|
|
165
|
+
date: opts.date,
|
|
151
166
|
provider: opts.with,
|
|
167
|
+
language: opts.lang,
|
|
152
168
|
configPath: opts.config,
|
|
153
|
-
changelogFile: opts.
|
|
169
|
+
changelogFile: opts.changelogFile,
|
|
154
170
|
dryRun: opts.dryRun,
|
|
155
171
|
clipboard: opts.clipboard,
|
|
156
172
|
outputPath: opts.output,
|
|
157
|
-
|
|
158
|
-
format
|
|
173
|
+
toDir: opts.toDir,
|
|
174
|
+
format,
|
|
159
175
|
template: opts.template,
|
|
160
176
|
context: opts.context,
|
|
161
177
|
});
|
|
@@ -169,12 +185,12 @@ program
|
|
|
169
185
|
}
|
|
170
186
|
// Determine output path
|
|
171
187
|
let outputTargets = !opts.stdout && opts.output
|
|
172
|
-
? [{ path: opts.output, markdown: generatedResult.markdown, html: generatedResult.html, format
|
|
188
|
+
? [{ path: opts.output, markdown: generatedResult.markdown, html: generatedResult.html, format, ownedByRelease: true }]
|
|
173
189
|
: [];
|
|
174
|
-
if (!opts.stdout && outputTargets.length === 0 && opts.
|
|
175
|
-
const
|
|
176
|
-
const filename = `RELEASE_NOTES_${toVersion.replace(/^v/, "")}.${
|
|
177
|
-
outputTargets = [{ path: (0, path_1.join)((0, path_1.resolve)(opts.
|
|
190
|
+
if (!opts.stdout && outputTargets.length === 0 && opts.toDir) {
|
|
191
|
+
const extension = format === "html" ? "html" : "md";
|
|
192
|
+
const filename = `RELEASE_NOTES_${toVersion.replace(/^v/, "")}.${extension}`;
|
|
193
|
+
outputTargets = [{ path: (0, path_1.join)((0, path_1.resolve)(opts.toDir), filename), markdown: generatedResult.markdown, html: generatedResult.html, format, ownedByRelease: true }];
|
|
178
194
|
}
|
|
179
195
|
if (!opts.stdout && outputTargets.length === 0) {
|
|
180
196
|
if (loadedConfig.output) {
|
|
@@ -183,11 +199,14 @@ program
|
|
|
183
199
|
if (!output.saveTo)
|
|
184
200
|
return [];
|
|
185
201
|
const saveTo = Array.isArray(output.saveTo) ? output.saveTo : [output.saveTo];
|
|
202
|
+
// A release generated without --to is saved under the name the
|
|
203
|
+
// config asks for, which is not the tag it was detected as.
|
|
204
|
+
const versions = { fromVersion: opts.from || git_js_1.FIRST_RELEASE, toVersion: opts.to || "end" };
|
|
186
205
|
return saveTo.flatMap((path) => {
|
|
187
|
-
const ownedByRelease = isReleaseSpecificPath(path);
|
|
206
|
+
const ownedByRelease = (0, output_path_js_1.isReleaseSpecificPath)(path);
|
|
188
207
|
return path.includes("{lang}")
|
|
189
208
|
? generatedResult.localized.map((release) => ({
|
|
190
|
-
path:
|
|
209
|
+
path: (0, output_path_js_1.formatOutputPath)(path, { ...versions, environment: opts.env, language: release.language }),
|
|
191
210
|
markdown: release.markdown,
|
|
192
211
|
html: release.html,
|
|
193
212
|
format: output.format,
|
|
@@ -195,7 +214,7 @@ program
|
|
|
195
214
|
ownedByRelease,
|
|
196
215
|
}))
|
|
197
216
|
: [{
|
|
198
|
-
path:
|
|
217
|
+
path: (0, output_path_js_1.formatOutputPath)(path, { ...versions, environment: opts.env }),
|
|
199
218
|
markdown: generatedResult.markdown,
|
|
200
219
|
html: generatedResult.html,
|
|
201
220
|
format: output.format,
|
|
@@ -205,58 +224,6 @@ program
|
|
|
205
224
|
});
|
|
206
225
|
}
|
|
207
226
|
}
|
|
208
|
-
const outputIndexConfigs = loadedConfig.outputIndex
|
|
209
|
-
? (Array.isArray(loadedConfig.outputIndex) ? loadedConfig.outputIndex : [loadedConfig.outputIndex])
|
|
210
|
-
: [];
|
|
211
|
-
// An index template is written in the language the release is generated
|
|
212
|
-
// in, so prompt.languages already answers this.
|
|
213
|
-
const primaryLanguage = generatedResult.localized[0]?.language ?? "en";
|
|
214
|
-
const outputIndexTargets = outputIndexConfigs.flatMap((outputIndex, groupId) => outputIndex.saveTo.includes("{lang}")
|
|
215
|
-
? generatedResult.localized.map((release) => ({
|
|
216
|
-
path: (0, path_1.resolve)(getOutputPath(outputIndex.saveTo, opts.env, release.language, opts.from, opts.to)),
|
|
217
|
-
groupId,
|
|
218
|
-
language: release.language,
|
|
219
|
-
format: outputIndex.format,
|
|
220
|
-
templatePath: outputIndex.template,
|
|
221
|
-
entryTemplatePath: outputIndex.entryTemplate,
|
|
222
|
-
templateLanguage: primaryLanguage,
|
|
223
|
-
}))
|
|
224
|
-
: [{
|
|
225
|
-
path: (0, path_1.resolve)(getOutputPath(outputIndex.saveTo, opts.env, undefined, opts.from, opts.to)),
|
|
226
|
-
groupId,
|
|
227
|
-
format: outputIndex.format,
|
|
228
|
-
templatePath: outputIndex.template,
|
|
229
|
-
entryTemplatePath: outputIndex.entryTemplate,
|
|
230
|
-
templateLanguage: primaryLanguage,
|
|
231
|
-
}]);
|
|
232
|
-
if (outputIndexTargets.some((index) => outputTargets.some((target) => (0, path_1.resolve)(target.path) === index.path))) {
|
|
233
|
-
throw new Error("outputIndex.saveTo must be different from every output.saveTo path");
|
|
234
|
-
}
|
|
235
|
-
const duplicateIndexPath = outputIndexTargets.find((target, index) => outputIndexTargets.findIndex((candidate) => candidate.path.toLowerCase() === target.path.toLowerCase()) !== index);
|
|
236
|
-
if (duplicateIndexPath) {
|
|
237
|
-
throw new Error(`outputIndex.saveTo resolves more than once to ${duplicateIndexPath.path}. ` +
|
|
238
|
-
`Use distinct paths and language values.`);
|
|
239
|
-
}
|
|
240
|
-
const outputIndexLanguageTargets = outputIndexTargets
|
|
241
|
-
.flatMap((target) => target.language ? [{ ...target, language: target.language }] : []);
|
|
242
|
-
for (const [groupId, outputIndex] of outputIndexConfigs.entries()) {
|
|
243
|
-
if (!outputIndex.saveTo.includes("{lang}"))
|
|
244
|
-
continue;
|
|
245
|
-
const patternPath = (0, path_1.resolve)(getOutputPath(outputIndex.saveTo, opts.env, LANGUAGE_PATH_PLACEHOLDER, opts.from, opts.to));
|
|
246
|
-
const discovered = await (0, output_index_js_1.discoverOutputIndexLanguages)(patternPath, LANGUAGE_PATH_PLACEHOLDER);
|
|
247
|
-
for (const existingIndex of discovered) {
|
|
248
|
-
const alreadyAvailable = outputIndexLanguageTargets.some((target) => target.groupId === groupId &&
|
|
249
|
-
target.path.toLowerCase() === existingIndex.path.toLowerCase());
|
|
250
|
-
if (!alreadyAvailable) {
|
|
251
|
-
outputIndexLanguageTargets.push({
|
|
252
|
-
...existingIndex,
|
|
253
|
-
groupId,
|
|
254
|
-
format: outputIndex.format,
|
|
255
|
-
templatePath: outputIndex.template,
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
227
|
// Save to file
|
|
261
228
|
for (const target of outputTargets) {
|
|
262
229
|
const outputPath = target.path;
|
|
@@ -275,56 +242,31 @@ program
|
|
|
275
242
|
console.log(chalk_1.default.green("💾 Saved to " + outputPath));
|
|
276
243
|
}
|
|
277
244
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
language
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
});
|
|
304
|
-
await (0, promises_1.writeFile)(index.path, outputIndexContent, "utf-8");
|
|
305
|
-
console.log(chalk_1.default.green("📚 Updated output index " + index.path));
|
|
306
|
-
}
|
|
307
|
-
const currentIndexPaths = new Set(outputIndexTargets.map((target) => target.path.toLowerCase()));
|
|
308
|
-
for (const existingIndex of outputIndexLanguageTargets) {
|
|
309
|
-
if (currentIndexPaths.has(existingIndex.path.toLowerCase()))
|
|
310
|
-
continue;
|
|
311
|
-
const existing = await (0, promises_1.readFile)(existingIndex.path, "utf-8");
|
|
312
|
-
const languageLinks = getOutputIndexLanguageLinks(existingIndex, outputIndexLanguageTargets);
|
|
313
|
-
const languageSwitcher = (0, release_js_1.renderOutputIndexLanguageSwitcher)(existingIndex.format, languageLinks);
|
|
314
|
-
const hasLanguageSwitcher = (0, release_js_1.hasOutputIndexLanguageSwitcher)(existing);
|
|
315
|
-
let updated = (0, release_js_1.applyOutputIndexLanguageSwitcher)(existing, languageSwitcher);
|
|
316
|
-
if (!hasLanguageSwitcher &&
|
|
317
|
-
!existingIndex.templatePath &&
|
|
318
|
-
languageLinks.length > 1 &&
|
|
319
|
-
existing.includes(release_js_1.RELEASES_MARKER)) {
|
|
320
|
-
updated = existing.replace(release_js_1.RELEASES_MARKER, `${languageSwitcher}\n\n${release_js_1.RELEASES_MARKER}`);
|
|
321
|
-
}
|
|
322
|
-
if (updated !== existing) {
|
|
323
|
-
await (0, promises_1.writeFile)(existingIndex.path, updated, "utf-8");
|
|
324
|
-
console.log(chalk_1.default.green("🌐 Refreshed languages in " + existingIndex.path));
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
245
|
+
await (0, output_index_js_1.updateOutputIndexes)({
|
|
246
|
+
outputIndexes: outputIndexConfigs(loadedConfig),
|
|
247
|
+
releases: outputTargets,
|
|
248
|
+
projectName: loadedConfig.projectName,
|
|
249
|
+
environment: opts.env,
|
|
250
|
+
fromVersion,
|
|
251
|
+
toVersion,
|
|
252
|
+
// A release generated without --to is saved under the name the config
|
|
253
|
+
// asks for, which is not the tag it was detected as.
|
|
254
|
+
pathFromVersion: opts.from || git_js_1.FIRST_RELEASE,
|
|
255
|
+
pathToVersion: opts.to || "end",
|
|
256
|
+
date: generatedResult.metadata.date,
|
|
257
|
+
languages: generatedResult.localized.map((release) => release.language),
|
|
258
|
+
// An index template is written in the language the release is generated
|
|
259
|
+
// in, so prompt.languages already answers this.
|
|
260
|
+
primaryLanguage: generatedResult.localized[0]?.language ?? "en",
|
|
261
|
+
translateTemplate: opts.dryRun
|
|
262
|
+
? undefined
|
|
263
|
+
: async (template, language) => {
|
|
264
|
+
const translated = await translateOutputIndexTemplate(template, language, generatedResult.metadata.provider, loadedConfig.providers[generatedResult.metadata.provider]);
|
|
265
|
+
addTemplateUsage(generatedResult.metadata.usage, translated.usage);
|
|
266
|
+
return translated.text;
|
|
267
|
+
},
|
|
268
|
+
onUpdated: printOutputIndexUpdate,
|
|
269
|
+
});
|
|
328
270
|
// Clipboard
|
|
329
271
|
if (opts.clipboard) {
|
|
330
272
|
await clipboardy_1.default.write(generatedResult.markdown);
|
|
@@ -346,6 +288,163 @@ program
|
|
|
346
288
|
process.exit(1);
|
|
347
289
|
}
|
|
348
290
|
});
|
|
291
|
+
// ── promote ──
|
|
292
|
+
program
|
|
293
|
+
.command("promote")
|
|
294
|
+
.description("Move release notes from one environment to the next, reusing their wording")
|
|
295
|
+
.option("--from-env <environment>", "Environment to promote from: QUA, STAGING... (default: --from-dir's name)")
|
|
296
|
+
.option("--to-env <environment>", "Environment to promote to: PROD, PREPROD... (default: --to-dir's name)")
|
|
297
|
+
.option("--from <version>", "Start of the range (default: where the target environment is)")
|
|
298
|
+
.option("--to <version>", "End of the range (default: the newest release in the source)")
|
|
299
|
+
.option("--from-dir <dir>", "Read the source releases from this folder")
|
|
300
|
+
.option("--to-dir <dir>", "Write the promoted releases to this folder")
|
|
301
|
+
.option("--pattern <pattern>", "File name inside those folders, with {from} and {to}")
|
|
302
|
+
.option("--with <provider>", "LLM provider used to write the opening of a merged range")
|
|
303
|
+
.option("--lang <language>", "Promote one language only")
|
|
304
|
+
.option("--date <date>", 'Release date: "now", "tag", or an ISO date (default: now)')
|
|
305
|
+
.option("--config <path>", "Path to config file")
|
|
306
|
+
.option("--dry-run", "Show what would be promoted without writing anything")
|
|
307
|
+
.option("-v, --verbose", "Show what was promoted, release by release")
|
|
308
|
+
.option("--stdout", "Write the promoted release notes to the terminal without saving files")
|
|
309
|
+
.action(async (opts) => {
|
|
310
|
+
try {
|
|
311
|
+
// A layout that keeps each environment in a folder has already named
|
|
312
|
+
// them, so the folder answers for the environment when nothing else does.
|
|
313
|
+
const fromEnvironment = opts.fromEnv || folderName(opts.fromDir);
|
|
314
|
+
const toEnvironment = opts.toEnv || folderName(opts.toDir);
|
|
315
|
+
if (!fromEnvironment || !toEnvironment) {
|
|
316
|
+
throw new promote_js_1.PromotionError("Promoting needs both environments: pass --from-env and --to-env, " +
|
|
317
|
+
"or --from-dir and --to-dir to take their names from the folders.");
|
|
318
|
+
}
|
|
319
|
+
const result = await (0, promote_js_1.promote)({
|
|
320
|
+
fromEnvironment,
|
|
321
|
+
toEnvironment,
|
|
322
|
+
fromVersion: opts.from,
|
|
323
|
+
toVersion: opts.to,
|
|
324
|
+
fromDir: opts.fromDir,
|
|
325
|
+
toDir: opts.toDir,
|
|
326
|
+
pattern: opts.pattern,
|
|
327
|
+
provider: opts.with,
|
|
328
|
+
language: opts.lang,
|
|
329
|
+
date: opts.date,
|
|
330
|
+
configPath: opts.config,
|
|
331
|
+
});
|
|
332
|
+
const { fromVersion, toVersion } = result.metadata;
|
|
333
|
+
if (result.plan.segments.length === 0) {
|
|
334
|
+
console.log(chalk_1.default.yellow(`✅ ${toEnvironment} is already at ${toVersion}. Nothing to promote from ${fromEnvironment}.`));
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
printStatus(opts.stdout, chalk_1.default.blue(`🚀 Promoting ${fromEnvironment} → ${toEnvironment}: ${fromVersion} → ${toVersion}`));
|
|
338
|
+
for (const segment of result.plan.segments) {
|
|
339
|
+
printStatus(opts.stdout, chalk_1.default.gray(` ${segment.fromVersion} → ${segment.toVersion}`));
|
|
340
|
+
}
|
|
341
|
+
for (const skipped of result.metadata.skipped) {
|
|
342
|
+
printStatus(opts.stdout, chalk_1.default.gray(` Skipped ${skipped}: it holds every release, not one per file.`));
|
|
343
|
+
}
|
|
344
|
+
if (result.plan.segments.length > 1) {
|
|
345
|
+
printStatus(opts.stdout, chalk_1.default.gray(" Sections merged word for word."));
|
|
346
|
+
// Falling back is not wrong — the newest release's opening is a true
|
|
347
|
+
// one — but it is narrower than the range, so it is said out loud.
|
|
348
|
+
printStatus(opts.stdout, result.files.some((file) => file.openingRewritten)
|
|
349
|
+
? chalk_1.default.gray(" One title and summary written for the range.")
|
|
350
|
+
: chalk_1.default.yellow(` ⚠️ The ${toVersion} title and summary stand for the whole range: ` +
|
|
351
|
+
`${result.metadata.openingSkipped || "no opening was written"}.`));
|
|
352
|
+
}
|
|
353
|
+
if (opts.stdout) {
|
|
354
|
+
console.log(result.files.map((file) => file.content).join("\n\n"));
|
|
355
|
+
}
|
|
356
|
+
if (opts.verbose || opts.dryRun || opts.stdout) {
|
|
357
|
+
for (const file of result.files) {
|
|
358
|
+
printStatus(opts.stdout, chalk_1.default.gray(` ${file.path} ← ${file.sources.join(", ")}`));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (opts.dryRun || opts.stdout) {
|
|
362
|
+
printStatus(opts.stdout, chalk_1.default.gray(result.metadata.usage.modelCalls === 0
|
|
363
|
+
? "\n🤖 No model was called: the wording is the one already reviewed."
|
|
364
|
+
: "\n🤖 Every section is the wording already reviewed; only the title and summary were written."));
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
for (const file of result.files) {
|
|
368
|
+
await (0, promises_1.mkdir)((0, path_1.dirname)(file.path), { recursive: true });
|
|
369
|
+
const saved = await saveReleaseNotes(file.path, file.content, file.content, file.ownedByRelease);
|
|
370
|
+
console.log(chalk_1.default.green(`${saved === "replaced" ? "💾 Replaced" : "💾 Saved to"} ${file.path}`));
|
|
371
|
+
}
|
|
372
|
+
const languages = [...new Set(result.files.flatMap((file) => file.language ? [file.language] : []))];
|
|
373
|
+
await (0, output_index_js_1.updateOutputIndexes)({
|
|
374
|
+
outputIndexes: outputIndexConfigs(result.config),
|
|
375
|
+
releases: result.files,
|
|
376
|
+
projectName: result.config.projectName,
|
|
377
|
+
environment: toEnvironment,
|
|
378
|
+
fromVersion,
|
|
379
|
+
toVersion,
|
|
380
|
+
date: result.metadata.date,
|
|
381
|
+
languages: languages.length > 0 ? languages : (result.config.prompt?.languages ?? ["en"]),
|
|
382
|
+
primaryLanguage: result.config.prompt?.languages?.[0] ?? languages[0] ?? "en",
|
|
383
|
+
// Promoting calls no model, so an index in a language its template is
|
|
384
|
+
// not written in keeps the template's own wording.
|
|
385
|
+
onUpdated: printOutputIndexUpdate,
|
|
386
|
+
});
|
|
387
|
+
const { usage } = result.metadata;
|
|
388
|
+
console.log(chalk_1.default.gray(`\n📊 ${result.plan.segments.length} release${result.plan.segments.length === 1 ? "" : "s"} promoted | ` +
|
|
389
|
+
`${result.metadata.date} | ` +
|
|
390
|
+
(usage.modelCalls === 0
|
|
391
|
+
? "no model calls"
|
|
392
|
+
: `${formatNumber(usage.totalTokens)} tokens | ${usage.modelCalls} model call${usage.modelCalls === 1 ? "" : "s"}`)));
|
|
393
|
+
}
|
|
394
|
+
catch (err) {
|
|
395
|
+
const message = err instanceof promote_js_1.PromotionError ? err.message : (err?.message || String(err));
|
|
396
|
+
console.error(chalk_1.default.red("\n❌ Error:"), message);
|
|
397
|
+
process.exit(1);
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
// ── prompt ──
|
|
401
|
+
program
|
|
402
|
+
.command("prompt")
|
|
403
|
+
.description("Ask, in your own words, for a change to release notes already written")
|
|
404
|
+
.requiredOption("--env <environment>", "Whose release notes to open: PROD, QUA, DEV...")
|
|
405
|
+
.option("--from <version>", "Open only the releases a range covers, from here")
|
|
406
|
+
.option("--to <version>", "Open only the releases a range covers, up to here")
|
|
407
|
+
.option("--lang <language>", "Open one language only")
|
|
408
|
+
.option("--with <provider>", "LLM provider override (claude, gpt4, mistral, gemini, ollama)")
|
|
409
|
+
.option("--config <path>", "Path to config file")
|
|
410
|
+
.option("--ask <request>", "Apply a request and save, with nothing to answer. Repeatable, for CI", (value, previous) => [...previous, value], [])
|
|
411
|
+
.option("--dry-run", "Show what the requests would change without writing anything")
|
|
412
|
+
.option("-v, --verbose", "Show the provider and instructions the requests are answered with")
|
|
413
|
+
.option("--stdout", "Write the revised release notes to the terminal without saving files")
|
|
414
|
+
.action(async (opts) => {
|
|
415
|
+
try {
|
|
416
|
+
const session = await prompt_session_js_1.PromptSession.open({
|
|
417
|
+
environment: opts.env,
|
|
418
|
+
fromVersion: opts.from,
|
|
419
|
+
toVersion: opts.to,
|
|
420
|
+
language: opts.lang,
|
|
421
|
+
provider: opts.with,
|
|
422
|
+
configPath: opts.config,
|
|
423
|
+
});
|
|
424
|
+
printOpenDocuments(session, opts.stdout);
|
|
425
|
+
if (opts.verbose)
|
|
426
|
+
printVerbosePromptDetails(opts.stdout, session);
|
|
427
|
+
if (opts.ask.length > 0) {
|
|
428
|
+
const failures = await runRequestedChanges(session, opts.ask, opts.dryRun, opts.stdout);
|
|
429
|
+
await savePromptSession(session, opts.dryRun, opts.stdout);
|
|
430
|
+
// CI asked for something and is entitled to know it did not happen.
|
|
431
|
+
if (failures > 0)
|
|
432
|
+
process.exit(1);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
// Asking questions at a prompt is a conversation, and a conversation has
|
|
436
|
+
// nowhere to write its answers but the terminal it is held in.
|
|
437
|
+
if (opts.stdout) {
|
|
438
|
+
throw new prompt_session_js_1.PromptError("--stdout needs --ask: there is no conversation to hold when the terminal is the output.");
|
|
439
|
+
}
|
|
440
|
+
await holdConversation(session, opts.dryRun);
|
|
441
|
+
}
|
|
442
|
+
catch (err) {
|
|
443
|
+
const message = err instanceof prompt_session_js_1.PromptError ? err.message : (err?.message || String(err));
|
|
444
|
+
console.error(chalk_1.default.red("\n❌ Error:"), message);
|
|
445
|
+
process.exit(1);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
349
448
|
// ── providers ──
|
|
350
449
|
program
|
|
351
450
|
.command("providers")
|
|
@@ -366,219 +465,249 @@ program
|
|
|
366
465
|
console.log(chalk_1.default.gray("\nUse --with <alias> to override the default provider."));
|
|
367
466
|
});
|
|
368
467
|
program.parse();
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
468
|
+
/** The name of a folder, used as the environment it holds. */
|
|
469
|
+
function folderName(directory) {
|
|
470
|
+
return directory ? (0, path_1.basename)((0, path_1.resolve)(directory)) : undefined;
|
|
471
|
+
}
|
|
472
|
+
// ─────────────────────────────────────────
|
|
473
|
+
// Asking for a change, in your own words
|
|
474
|
+
// ─────────────────────────────────────────
|
|
475
|
+
/** Changed lines shown per file before the rest is summarized. */
|
|
476
|
+
const DIFF_LINE_LIMIT = 24;
|
|
477
|
+
/**
|
|
478
|
+
* A spinner that keeps quiet when nobody is watching it turn.
|
|
479
|
+
*
|
|
480
|
+
* The conversation reads its answers from wherever standard input comes from,
|
|
481
|
+
* so it runs just as well down a pipe — and there a spinner is a line of log
|
|
482
|
+
* noise landing in the middle of the question it was asked.
|
|
483
|
+
*/
|
|
484
|
+
function progress(text) {
|
|
485
|
+
return (0, ora_1.default)({ text, isSilent: !process.stdout.isTTY }).start();
|
|
377
486
|
}
|
|
378
487
|
/**
|
|
379
|
-
*
|
|
488
|
+
* Hold the conversation: ask what to change, do it, ask again.
|
|
380
489
|
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
490
|
+
* Nothing has to be learned first — every answer is read by a model that says
|
|
491
|
+
* what it meant, so "drop the docker part", "put that back" and "that's it" all
|
|
492
|
+
* work. Answers can equally arrive down a pipe, which is what makes the same
|
|
493
|
+
* loop usable from a script.
|
|
384
494
|
*/
|
|
385
|
-
function
|
|
386
|
-
|
|
495
|
+
async function holdConversation(session, dryRun) {
|
|
496
|
+
const { createInterface } = await import("node:readline/promises");
|
|
497
|
+
const input = createInterface({ input: process.stdin, output: process.stdout });
|
|
498
|
+
input.on("SIGINT", () => input.close());
|
|
499
|
+
const state = { leaving: false, warnedAboutUnsaved: false, toldAboutSaving: false };
|
|
500
|
+
console.log(chalk_1.default.bold("\n💬 Is there anything you would like to change?"));
|
|
501
|
+
console.log(chalk_1.default.gray(" Say it in your own words. Say you are done when you are done."));
|
|
502
|
+
input.setPrompt(chalk_1.default.cyan("\n› "));
|
|
503
|
+
input.prompt();
|
|
504
|
+
for await (const line of input) {
|
|
505
|
+
if (line.trim()) {
|
|
506
|
+
await answerMessage(session, line, dryRun, state);
|
|
507
|
+
if (state.leaving)
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
input.prompt();
|
|
511
|
+
}
|
|
512
|
+
input.close();
|
|
513
|
+
if (session.pending().length > 0 && !state.leaving) {
|
|
514
|
+
console.log(chalk_1.default.yellow(`\n⚠️ ${session.pending().length} release note(s) still hold changes that were never written.`));
|
|
515
|
+
}
|
|
387
516
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
517
|
+
/** Do what one message asked for, and say what happened. */
|
|
518
|
+
async function answerMessage(session, message, dryRun, state) {
|
|
519
|
+
const reading = progress("💭 Reading what you asked for...");
|
|
520
|
+
const action = await session.route(message);
|
|
521
|
+
reading.stop();
|
|
522
|
+
if (action.reply)
|
|
523
|
+
console.log(chalk_1.default.gray(` ${action.reply}`));
|
|
524
|
+
switch (action.action) {
|
|
525
|
+
case "revise": {
|
|
526
|
+
const working = progress("✍️ Revising...");
|
|
527
|
+
const result = await session.revise(action.instruction);
|
|
528
|
+
working.stop();
|
|
529
|
+
printPromptEdits(result);
|
|
530
|
+
// A revision that reports success reads like a file that was written, and
|
|
531
|
+
// this one was not. Said once: after that it is known.
|
|
532
|
+
if (session.pending().length > 0 && !state.toldAboutSaving && !dryRun) {
|
|
533
|
+
state.toldAboutSaving = true;
|
|
534
|
+
console.log(chalk_1.default.gray(" Not written yet — ask me to save when the notes read right."));
|
|
535
|
+
}
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
case "dedupe":
|
|
539
|
+
printPromptEdits(session.dedupe());
|
|
540
|
+
return;
|
|
541
|
+
case "undo":
|
|
542
|
+
console.log(session.undo()
|
|
543
|
+
? chalk_1.default.green("↩️ Took back the last change.")
|
|
544
|
+
: chalk_1.default.gray("Nothing to take back."));
|
|
545
|
+
return;
|
|
546
|
+
case "reset":
|
|
547
|
+
session.reset();
|
|
548
|
+
console.log(chalk_1.default.green("↩️ The release notes are back to the way they were saved."));
|
|
549
|
+
return;
|
|
550
|
+
case "save":
|
|
551
|
+
await savePromptSession(session, dryRun);
|
|
552
|
+
return;
|
|
553
|
+
case "list":
|
|
554
|
+
printOpenDocuments(session);
|
|
555
|
+
return;
|
|
556
|
+
case "done": {
|
|
557
|
+
const pending = session.pending().length;
|
|
558
|
+
// Leaving unsaved work behind is worth one question, and exactly one:
|
|
559
|
+
// saying it a second time means it was meant.
|
|
560
|
+
if (pending > 0 && !state.warnedAboutUnsaved && !dryRun) {
|
|
561
|
+
state.warnedAboutUnsaved = true;
|
|
562
|
+
console.log(chalk_1.default.yellow(`\n⚠️ ${pending} release note(s) hold changes that are not written yet.`));
|
|
563
|
+
console.log(chalk_1.default.gray(" Ask me to save them, or say you are done again to leave them alone."));
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
state.leaving = true;
|
|
567
|
+
console.log(chalk_1.default.gray("\n👋 Done."));
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
case "unclear":
|
|
571
|
+
if (!action.reply) {
|
|
572
|
+
console.log(chalk_1.default.gray(" I did not follow that. What should change in the release notes?"));
|
|
573
|
+
}
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
396
576
|
}
|
|
397
|
-
|
|
398
|
-
|
|
577
|
+
/** Apply the requests a command line carried, and report how many failed. */
|
|
578
|
+
async function runRequestedChanges(session, requests, dryRun, stdout = false) {
|
|
579
|
+
let failures = 0;
|
|
580
|
+
for (const request of requests) {
|
|
581
|
+
printStatus(stdout, chalk_1.default.cyan(`\n› ${request}`));
|
|
582
|
+
const action = await session.route(request);
|
|
583
|
+
if (action.reply)
|
|
584
|
+
printStatus(stdout, chalk_1.default.gray(` ${action.reply}`));
|
|
585
|
+
// A script asked for a change to the release notes, so that is all that is
|
|
586
|
+
// acted on here: saving is what the end of the run is for, and taking a
|
|
587
|
+
// change back has nothing to take back.
|
|
588
|
+
const result = action.action === "dedupe"
|
|
589
|
+
? session.dedupe()
|
|
590
|
+
: await session.revise(action.action === "revise" ? action.instruction : request);
|
|
591
|
+
failures += printPromptEdits(result, stdout);
|
|
592
|
+
}
|
|
593
|
+
return failures;
|
|
594
|
+
}
|
|
595
|
+
function printVerbosePromptDetails(stdout, session) {
|
|
596
|
+
const languages = [...new Set(session.documents.flatMap((d) => d.language ? [d.language] : []))];
|
|
597
|
+
printStatus(stdout, chalk_1.default.gray("\n🧭 Session details"));
|
|
598
|
+
printStatus(stdout, chalk_1.default.gray(` Provider: ${session.provider}`));
|
|
599
|
+
printStatus(stdout, chalk_1.default.gray(` Instructions: ${describePromptSource(session.config.prompt?.instructions)}`));
|
|
600
|
+
if (languages.length > 0) {
|
|
601
|
+
printStatus(stdout, chalk_1.default.gray(` Languages open: ${languages.join(", ")}`));
|
|
602
|
+
}
|
|
399
603
|
}
|
|
400
|
-
function
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
604
|
+
function printOpenDocuments(session, stdout = false) {
|
|
605
|
+
const count = session.documents.length;
|
|
606
|
+
printStatus(stdout, chalk_1.default.blue(`\n📝 ${count} release note${count === 1 ? "" : "s"} open for ${session.environment}`));
|
|
607
|
+
for (const document of session.documents) {
|
|
608
|
+
const range = [document.fromVersion, document.toVersion].filter(Boolean).join(" → ");
|
|
609
|
+
const language = document.language ? ` [${document.language}]` : "";
|
|
610
|
+
const pending = document.content !== document.saved ? chalk_1.default.yellow(" (changed)") : "";
|
|
611
|
+
printStatus(stdout, chalk_1.default.gray(` ${(0, path_1.relative)(process.cwd(), document.path)}`) +
|
|
612
|
+
chalk_1.default.gray(range ? ` ${range}` : "") + chalk_1.default.gray(language) + pending);
|
|
613
|
+
if (document.unrevisable) {
|
|
614
|
+
printStatus(stdout, chalk_1.default.yellow(` ⚠️ ${document.unrevisable}`));
|
|
615
|
+
}
|
|
616
|
+
}
|
|
408
617
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
});
|
|
424
|
-
if ((0, fs_1.existsSync)(params.outputPath)) {
|
|
425
|
-
const existing = await (0, promises_1.readFile)(params.outputPath, "utf-8");
|
|
426
|
-
// An index written before the releases were bounded ends its list at the
|
|
427
|
-
// first thing that follows it, so give it that boundary before reading the
|
|
428
|
-
// list back out.
|
|
429
|
-
const normalizedExisting = ensureOutputIndexReleaseBoundary(params.format === "html" ? unwrapHtmlDocumentCodeFence(existing) : existing, params.format);
|
|
430
|
-
// The entry template is read from its file on every run, so an index never
|
|
431
|
-
// has to carry a copy of it: editing the file is what changes the shape.
|
|
432
|
-
const { entryTemplate } = await loadOutputIndexEntryTemplate(params);
|
|
433
|
-
// Every release the index knows is rendered again from its record, so a
|
|
434
|
-
// template or a language that changed reaches the whole history, not just
|
|
435
|
-
// the release being added.
|
|
436
|
-
const region = (0, release_js_1.readOutputIndexReleasesRegion)(normalizedExisting);
|
|
437
|
-
const records = (0, release_js_1.upsertOutputIndexReleaseRecord)((0, release_js_1.readOutputIndexReleaseRecords)(region), record);
|
|
438
|
-
const legacyEntries = (0, release_js_1.readLegacyOutputIndexEntries)(region, records.map(release_js_1.outputIndexReleaseId));
|
|
439
|
-
const updated = (0, release_js_1.replaceOutputIndexReleases)(normalizedExisting, [renderReleases(records, entryTemplate), ...legacyEntries].filter(Boolean).join("\n"));
|
|
440
|
-
const hasLanguageSwitcher = (0, release_js_1.hasOutputIndexLanguageSwitcher)(updated);
|
|
441
|
-
const withLanguageSwitcher = (0, release_js_1.applyOutputIndexLanguageSwitcher)(updated, languageSwitcher);
|
|
442
|
-
if (!params.templatePath && params.languageLinks.length > 1 && !hasLanguageSwitcher) {
|
|
443
|
-
return updated.replace(release_js_1.RELEASES_MARKER, `${languageSwitcher}\n\n${release_js_1.RELEASES_MARKER}`);
|
|
618
|
+
/** Report what a request did, and return how many files it failed on. */
|
|
619
|
+
function printPromptEdits(result, stdout = false) {
|
|
620
|
+
let changed = 0;
|
|
621
|
+
let failed = 0;
|
|
622
|
+
for (const edit of result.edits) {
|
|
623
|
+
const path = (0, path_1.relative)(process.cwd(), edit.path);
|
|
624
|
+
if (edit.skipped) {
|
|
625
|
+
failed += 1;
|
|
626
|
+
printStatus(stdout, chalk_1.default.yellow(` ⏭️ ${path} — ${edit.skipped}`));
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
if (!edit.changed) {
|
|
630
|
+
printStatus(stdout, chalk_1.default.gray(` · ${path} — nothing there to change`));
|
|
631
|
+
continue;
|
|
444
632
|
}
|
|
445
|
-
|
|
633
|
+
changed += 1;
|
|
634
|
+
const removed = edit.removed?.length
|
|
635
|
+
? chalk_1.default.gray(` (${edit.removed.length} repeated line${edit.removed.length === 1 ? "" : "s"})`)
|
|
636
|
+
: "";
|
|
637
|
+
printStatus(stdout, chalk_1.default.green(` ✏️ ${path}`) + removed);
|
|
638
|
+
printDiff(edit.before, edit.after, stdout);
|
|
446
639
|
}
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
640
|
+
const usage = result.via === "comparison"
|
|
641
|
+
? " | no model call: the lines were compared exactly"
|
|
642
|
+
: ` | ${formatNumber(result.usage.totalTokens)} tokens | ${result.usage.modelCalls} model call${result.usage.modelCalls === 1 ? "" : "s"} | ${formatDuration(result.usage.durationMs)}`;
|
|
643
|
+
printStatus(stdout, chalk_1.default.gray(`\n ${changed} of ${result.edits.length} revised${usage}`));
|
|
644
|
+
return failed;
|
|
645
|
+
}
|
|
646
|
+
function printDiff(before, after, stdout = false) {
|
|
647
|
+
// A line that only gained or lost blank space is not a change anyone asked to
|
|
648
|
+
// review, and a long run of them would bury the ones that are.
|
|
649
|
+
const changes = (0, text_diff_js_1.changedLines)(before, after).filter((line) => line.text.trim());
|
|
650
|
+
for (const line of changes.slice(0, DIFF_LINE_LIMIT)) {
|
|
651
|
+
printStatus(stdout, line.kind === "added"
|
|
652
|
+
? chalk_1.default.green(` + ${line.text.trim()}`)
|
|
653
|
+
: chalk_1.default.red(` - ${line.text.trim()}`));
|
|
654
|
+
}
|
|
655
|
+
if (changes.length > DIFF_LINE_LIMIT) {
|
|
656
|
+
printStatus(stdout, chalk_1.default.gray(` … ${changes.length - DIFF_LINE_LIMIT} more changed lines`));
|
|
459
657
|
}
|
|
460
|
-
const isHtmlTemplate = !params.templatePath || /\.html?$/i.test(params.templatePath);
|
|
461
|
-
// An index is assembled here from the template and already-escaped entries,
|
|
462
|
-
// so its own markup is allowed through. A release note is model output and
|
|
463
|
-
// never gets that trust.
|
|
464
|
-
const html = isHtmlTemplate
|
|
465
|
-
? rendered
|
|
466
|
-
: (0, release_js_1.markdownToHtml)(rendered, { trustedHtml: true });
|
|
467
|
-
return html;
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Joins the summary and the entry template on their way to the translator.
|
|
471
|
-
*
|
|
472
|
-
* It exists for the length of one call: it is never written to a template nor
|
|
473
|
-
* to a generated index.
|
|
474
|
-
*/
|
|
475
|
-
const ENTRY_TEMPLATE_SEPARATOR = "__AI_RELEASE_NOTES_PART__";
|
|
476
|
-
/**
|
|
477
|
-
* The summary template to render, and the entry shape to list releases with.
|
|
478
|
-
*
|
|
479
|
-
* The entry shape is not configurable, so it never comes from the summary
|
|
480
|
-
* template. Both are translated in one pass, then split apart again: only the
|
|
481
|
-
* summary is rendered, and the entry shape is stored in the index.
|
|
482
|
-
*/
|
|
483
|
-
async function loadOutputIndexEntryTemplate(params) {
|
|
484
|
-
const summary = await loadOutputIndexTemplate(params.templatePath, params.format);
|
|
485
|
-
const entryFile = await loadEntryTemplate(params.entryTemplatePath, params.format);
|
|
486
|
-
const joined = `${summary}\n${ENTRY_TEMPLATE_SEPARATOR}\n${entryFile}`;
|
|
487
|
-
const localized = params.translateTemplate
|
|
488
|
-
? await params.translateTemplate(joined)
|
|
489
|
-
: joined;
|
|
490
|
-
// A translation that lost the separator cannot be split back apart. The
|
|
491
|
-
// summary stays usable; the entry falls back to the file that was sent.
|
|
492
|
-
const separator = localized.lastIndexOf(ENTRY_TEMPLATE_SEPARATOR);
|
|
493
|
-
return {
|
|
494
|
-
template: (separator < 0 ? localized : localized.slice(0, separator)).trimEnd(),
|
|
495
|
-
entryTemplate: separator < 0
|
|
496
|
-
? entryFile.trim()
|
|
497
|
-
: localized.slice(separator + ENTRY_TEMPLATE_SEPARATOR.length).trim(),
|
|
498
|
-
};
|
|
499
658
|
}
|
|
500
|
-
async function
|
|
501
|
-
|
|
502
|
-
|
|
659
|
+
async function savePromptSession(session, dryRun, stdout = false) {
|
|
660
|
+
const pending = session.pending();
|
|
661
|
+
if (pending.length === 0) {
|
|
662
|
+
printStatus(stdout, chalk_1.default.gray("\n Nothing to write: the release notes are as they were."));
|
|
663
|
+
return;
|
|
503
664
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
665
|
+
// The revised notes are the output asked for, so they go out whole and
|
|
666
|
+
// nothing is written over: what to keep is the caller's to decide.
|
|
667
|
+
if (stdout) {
|
|
668
|
+
console.log(pending.map((document) => document.content).join("\n\n"));
|
|
669
|
+
return;
|
|
507
670
|
}
|
|
508
|
-
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
671
|
+
if (dryRun) {
|
|
672
|
+
console.log(chalk_1.default.yellow(`\n🔍 Dry run — ${pending.length} file(s) would be written:`));
|
|
673
|
+
for (const document of pending) {
|
|
674
|
+
console.log(chalk_1.default.gray(` ${(0, path_1.relative)(process.cwd(), document.path)}`));
|
|
675
|
+
}
|
|
676
|
+
return;
|
|
513
677
|
}
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
throw new Error(`Output index template not found: ${resolvedTemplatePath}`);
|
|
678
|
+
for (const path of await session.save()) {
|
|
679
|
+
console.log(chalk_1.default.green(`💾 Saved ${(0, path_1.relative)(process.cwd(), path)}`));
|
|
517
680
|
}
|
|
518
|
-
return (0, promises_1.readFile)(resolvedTemplatePath, "utf-8");
|
|
519
|
-
}
|
|
520
|
-
function loadBundledTemplate(name, format) {
|
|
521
|
-
const extension = format === "html" ? "html" : "md";
|
|
522
|
-
return (0, promises_1.readFile)((0, path_1.resolve)(__dirname, `../../templates/${name}.${extension}`), "utf-8");
|
|
523
|
-
}
|
|
524
|
-
function renderOutputIndexTemplate(template, values, format = "markdown") {
|
|
525
|
-
// A project name and an environment reach an HTML index straight from config
|
|
526
|
-
// and the command line, so they are escaped like every other value there.
|
|
527
|
-
const value = (raw) => (format === "html" ? escapeHtml(raw) : raw);
|
|
528
|
-
const rendered = template
|
|
529
|
-
.replaceAll("{{projectName}}", value(values.projectName))
|
|
530
|
-
.replaceAll("{{environment}}", value(values.environment))
|
|
531
|
-
.replaceAll("{{language}}", value(values.language))
|
|
532
|
-
.replaceAll("{{date}}", value(values.date))
|
|
533
|
-
.replaceAll("{{releases}}", `${values.releases}\n${release_js_1.RELEASES_END_MARKER}`)
|
|
534
|
-
.replaceAll("{{version}}", value(values.version));
|
|
535
|
-
return (0, release_js_1.applyOutputIndexLanguageSwitcher)(rendered, values.languages);
|
|
536
681
|
}
|
|
537
|
-
function
|
|
538
|
-
if (!
|
|
539
|
-
return
|
|
540
|
-
|
|
541
|
-
if (Number.isNaN(parsed.getTime()))
|
|
542
|
-
return date;
|
|
543
|
-
return new Intl.DateTimeFormat(language, {
|
|
544
|
-
day: "numeric",
|
|
545
|
-
month: "long",
|
|
546
|
-
year: "numeric",
|
|
547
|
-
}).format(parsed);
|
|
682
|
+
function outputIndexConfigs(config) {
|
|
683
|
+
if (!config.outputIndex)
|
|
684
|
+
return [];
|
|
685
|
+
return Array.isArray(config.outputIndex) ? config.outputIndex : [config.outputIndex];
|
|
548
686
|
}
|
|
549
|
-
function
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
687
|
+
function printOutputIndexUpdate(path, change) {
|
|
688
|
+
console.log(chalk_1.default.green(change === "languages"
|
|
689
|
+
? "🌐 Refreshed languages in " + path
|
|
690
|
+
: "📚 Updated output index " + path));
|
|
553
691
|
}
|
|
554
692
|
async function translateOutputIndexTemplate(template, language, providerName, providerConfig) {
|
|
555
693
|
const protectedTemplate = protectTemplateTokens(template);
|
|
556
694
|
const result = await (0, llm_js_1.callLLM)(providerName, providerConfig, "You translate release-summary templates. Return only the translated template. " +
|
|
557
695
|
"Translate every human-readable sentence into the requested language, but preserve all HTML, CSS, Markdown syntax, URLs, and protected tokens exactly.", `Target language: ${language}\n\nTemplate:\n${protectedTemplate.template}`);
|
|
558
|
-
const translated = unwrapHtmlDocumentCodeFence(restoreTemplateTokens(result.text, protectedTemplate.tokens));
|
|
696
|
+
const translated = (0, output_index_js_1.unwrapHtmlDocumentCodeFence)(restoreTemplateTokens(result.text, protectedTemplate.tokens));
|
|
559
697
|
if (!translated.includes(release_js_1.RELEASES_MARKER) || !translated.includes("{{releases}}")) {
|
|
560
698
|
throw new Error("Translated output-index template did not preserve the required releases marker or {{releases}} token");
|
|
561
699
|
}
|
|
562
|
-
if (template.includes(ENTRY_TEMPLATE_SEPARATOR) && !translated.includes(ENTRY_TEMPLATE_SEPARATOR)) {
|
|
700
|
+
if (template.includes(output_index_js_1.ENTRY_TEMPLATE_SEPARATOR) && !translated.includes(output_index_js_1.ENTRY_TEMPLATE_SEPARATOR)) {
|
|
563
701
|
throw new Error("Translated output-index template did not preserve its entry template");
|
|
564
702
|
}
|
|
565
703
|
return { text: translated, usage: result.usage };
|
|
566
704
|
}
|
|
567
|
-
/** Models occasionally wrap an HTML template in a Markdown code fence. */
|
|
568
|
-
function unwrapHtmlDocumentCodeFence(content) {
|
|
569
|
-
const openingFence = /^\s*```html?\s*\r?\n(?=\s*<!doctype html|\s*<html\b)/i;
|
|
570
|
-
if (!openingFence.test(content))
|
|
571
|
-
return content;
|
|
572
|
-
return content
|
|
573
|
-
.replace(openingFence, "")
|
|
574
|
-
.replace(/\r?\n```\s*$/, "");
|
|
575
|
-
}
|
|
576
705
|
function protectTemplateTokens(template) {
|
|
577
706
|
const values = [
|
|
578
707
|
release_js_1.RELEASES_MARKER,
|
|
579
708
|
// The entry template travels with the summary. Its labels are meant to be
|
|
580
709
|
// translated; what separates and names its parts is not.
|
|
581
|
-
ENTRY_TEMPLATE_SEPARATOR,
|
|
710
|
+
output_index_js_1.ENTRY_TEMPLATE_SEPARATOR,
|
|
582
711
|
"{{projectName}}",
|
|
583
712
|
"{{environment}}",
|
|
584
713
|
"{{language}}",
|
|
@@ -608,38 +737,6 @@ function addTemplateUsage(total, usage) {
|
|
|
608
737
|
total.totalTokens += usage.totalTokens;
|
|
609
738
|
total.modelCalls += 1;
|
|
610
739
|
}
|
|
611
|
-
function languageCode(language) {
|
|
612
|
-
return language.toLowerCase().split(/[-_]/, 1)[0];
|
|
613
|
-
}
|
|
614
|
-
function ensureOutputIndexReleaseBoundary(content, format) {
|
|
615
|
-
if (!content.includes(release_js_1.RELEASES_MARKER) || content.includes(release_js_1.RELEASES_END_MARKER)) {
|
|
616
|
-
return content;
|
|
617
|
-
}
|
|
618
|
-
const releasesStart = content.indexOf(release_js_1.RELEASES_MARKER) + release_js_1.RELEASES_MARKER.length;
|
|
619
|
-
const boundary = [
|
|
620
|
-
format === "html"
|
|
621
|
-
? content.indexOf("</main>", releasesStart)
|
|
622
|
-
: content.indexOf("\n---\n", releasesStart),
|
|
623
|
-
].filter((index) => index >= 0)[0];
|
|
624
|
-
if (boundary === undefined) {
|
|
625
|
-
return `${content.trimEnd()}\n${release_js_1.RELEASES_END_MARKER}\n`;
|
|
626
|
-
}
|
|
627
|
-
return `${content.slice(0, boundary).trimEnd()}\n${release_js_1.RELEASES_END_MARKER}\n${content.slice(boundary).replace(/^\n/, "")}`;
|
|
628
|
-
}
|
|
629
|
-
function toRelativeLink(fromPath, toPath) {
|
|
630
|
-
return (0, path_1.relative)((0, path_1.dirname)(fromPath), toPath)
|
|
631
|
-
.replaceAll("\\", "/")
|
|
632
|
-
.split("/")
|
|
633
|
-
.map((segment) => segment === "." || segment === ".." ? segment : encodeURIComponent(segment))
|
|
634
|
-
.join("/");
|
|
635
|
-
}
|
|
636
|
-
function escapeHtml(value) {
|
|
637
|
-
return value
|
|
638
|
-
.replaceAll("&", "&")
|
|
639
|
-
.replaceAll("<", "<")
|
|
640
|
-
.replaceAll(">", ">")
|
|
641
|
-
.replaceAll('"', """);
|
|
642
|
-
}
|
|
643
740
|
function formatNumber(value) {
|
|
644
741
|
return new Intl.NumberFormat("en-US").format(value);
|
|
645
742
|
}
|