change-log-agent 1.0.1 → 1.1.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/dist/index.mjs +43 -7
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { execa } from "execa";
|
|
5
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
import { createInterface } from "node:readline/promises";
|
|
7
|
+
import { stdin, stdout } from "node:process";
|
|
6
8
|
|
|
7
9
|
//#region src/core/git.ts
|
|
8
10
|
/**
|
|
@@ -101,19 +103,29 @@ async function checkMarkers(filePath) {
|
|
|
101
103
|
const lastDate = hasStart && hasEnd ? extractLastDate(content) : void 0;
|
|
102
104
|
return {
|
|
103
105
|
found: hasStart && hasEnd,
|
|
106
|
+
fileExists: true,
|
|
104
107
|
lastDate,
|
|
105
108
|
startTag: START_TAG,
|
|
106
109
|
endTag: END_TAG
|
|
107
110
|
};
|
|
108
|
-
} catch {
|
|
111
|
+
} catch (error) {
|
|
109
112
|
return {
|
|
110
113
|
found: false,
|
|
114
|
+
fileExists: !(error instanceof Error && "code" in error && error.code === "ENOENT"),
|
|
111
115
|
lastDate: void 0,
|
|
112
116
|
startTag: START_TAG,
|
|
113
117
|
endTag: END_TAG
|
|
114
118
|
};
|
|
115
119
|
}
|
|
116
120
|
}
|
|
121
|
+
const MARKER_TEMPLATE = `# Changelog
|
|
122
|
+
|
|
123
|
+
${START_TAG}
|
|
124
|
+
${END_TAG}
|
|
125
|
+
`;
|
|
126
|
+
async function createMarkerFile(filePath) {
|
|
127
|
+
await writeFile(filePath, MARKER_TEMPLATE, "utf-8");
|
|
128
|
+
}
|
|
117
129
|
function extractLastDate(content) {
|
|
118
130
|
const startIdx = content.indexOf(START_TAG);
|
|
119
131
|
const endIdx = content.indexOf(END_TAG);
|
|
@@ -121,16 +133,39 @@ function extractLastDate(content) {
|
|
|
121
133
|
return [...content.slice(startIdx, endIdx).matchAll(/###\s+(\d{4}-\d{2}-\d{2})/g)].map((m) => m[1]).filter((d) => d !== void 0).sort().at(-1);
|
|
122
134
|
}
|
|
123
135
|
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/utils/prompt.ts
|
|
138
|
+
async function confirmPrompt(message) {
|
|
139
|
+
const rl = createInterface({
|
|
140
|
+
input: stdin,
|
|
141
|
+
output: stdout
|
|
142
|
+
});
|
|
143
|
+
try {
|
|
144
|
+
const trimmed = (await rl.question(`${message} (Y/n) `)).trim().toLowerCase();
|
|
145
|
+
return trimmed === "" || trimmed === "y";
|
|
146
|
+
} finally {
|
|
147
|
+
rl.close();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
124
151
|
//#endregion
|
|
125
152
|
//#region src/index.ts
|
|
126
153
|
const program = new Command();
|
|
127
154
|
program.name("log-agent").description("AI-Powered Agentic Documentation CLI").version("0.1.0");
|
|
128
|
-
|
|
129
|
-
const { target: targetFile, since, dryRun } = options;
|
|
155
|
+
async function syncAction(options) {
|
|
156
|
+
const { target: targetFile, since, dryRun, yes: autoYes } = options;
|
|
130
157
|
try {
|
|
131
158
|
console.log(chalk.blue("Starting log-agent sync..."));
|
|
132
159
|
const markers = await checkMarkers(targetFile);
|
|
133
|
-
if (!dryRun && !markers.found) {
|
|
160
|
+
if (!dryRun && !markers.found) if (!markers.fileExists) {
|
|
161
|
+
if (!(autoYes || await confirmPrompt(`${targetFile} not found. Create it?`))) {
|
|
162
|
+
console.error(chalk.red("Aborted."));
|
|
163
|
+
process.exitCode = 1;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
await createMarkerFile(targetFile);
|
|
167
|
+
console.log(chalk.green(`Created ${targetFile} with markers.`));
|
|
168
|
+
} else {
|
|
134
169
|
console.error(chalk.red(`Markers not found in ${targetFile}.`));
|
|
135
170
|
console.error(chalk.gray(`Add these lines to your file:\n ${markers.startTag}\n ${markers.endTag}`));
|
|
136
171
|
process.exitCode = 1;
|
|
@@ -164,8 +199,9 @@ program.command("sync").description("Sync git log to documentation").option("--s
|
|
|
164
199
|
else console.error(chalk.red(`Sync failed: ${message}`));
|
|
165
200
|
process.exitCode = 1;
|
|
166
201
|
}
|
|
167
|
-
}
|
|
202
|
+
}
|
|
203
|
+
program.command("sync").description("Sync git log to documentation").option("--since <date>", "Only include commits after this date (e.g. 2026-02-01)").option("--target <file>", "Target file to update", "CHANGELOG.md").option("--dry-run", "Preview the mission spec without executing", false).option("--yes", "Skip interactive confirmation (for CI/CD)", false).action(syncAction);
|
|
168
204
|
program.parse();
|
|
169
205
|
|
|
170
206
|
//#endregion
|
|
171
|
-
export {
|
|
207
|
+
export { syncAction };
|