kodevu 0.1.48 → 0.1.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kodevu",
3
- "version": "0.1.48",
3
+ "version": "0.1.49",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "Poll SVN revisions or Git commits, send each change diff to a reviewer CLI, and write configurable review reports.",
package/src/logger.js CHANGED
@@ -6,7 +6,6 @@ class Logger {
6
6
  constructor() {
7
7
  this.config = null;
8
8
  this.logFile = null;
9
- this.progressDisplay = null;
10
9
  this.initialized = false;
11
10
  }
12
11
 
@@ -31,10 +30,6 @@ class Logger {
31
30
  }
32
31
  }
33
32
 
34
- setProgressDisplay(pd) {
35
- this.progressDisplay = pd;
36
- }
37
-
38
33
  info(message) {
39
34
  this._log("INFO", message);
40
35
  }
@@ -78,14 +73,10 @@ class Logger {
78
73
  // If it's debug and debug mode is off, skip console
79
74
  if (isDebug && !this.config?.debug) return;
80
75
 
81
- if (this.progressDisplay) {
82
- this.progressDisplay.log(logLine);
76
+ if (isError || isWarn) {
77
+ console.error(logLine);
83
78
  } else {
84
- if (isError || isWarn) {
85
- console.error(logLine);
86
- } else {
87
- console.log(logLine);
88
- }
79
+ console.log(logLine);
89
80
  }
90
81
  }
91
82
 
@@ -1,5 +1,3 @@
1
- import { logger } from "./logger.js";
2
-
3
1
  function clampProgress(value) {
4
2
  if (!Number.isFinite(value)) {
5
3
  return 0;
@@ -8,89 +6,34 @@ function clampProgress(value) {
8
6
  return Math.max(0, Math.min(1, value));
9
7
  }
10
8
 
11
- class ProgressItem {
12
- constructor(display, label) {
13
- this.display = display;
14
- this.label = label;
15
- this.progress = 0;
16
- this.stage = "";
17
- this.active = false;
18
- this.lastStatusLine = "";
19
- }
20
-
21
- start(stage = "starting") {
22
- this.active = true;
23
- this.stage = stage;
24
- logger.debug(`${this.label} batch start: ${stage}`);
25
- this.writeStatus();
26
- }
27
-
28
- update(progress, stage) {
29
- this.progress = clampProgress(progress);
30
-
31
- if (stage) {
32
- this.stage = stage;
33
- logger.debug(`${this.label} stage: ${stage} (${Math.round(this.progress * 100)}%)`);
34
- }
35
-
36
- this.writeStatus();
37
- }
9
+ function formatStatusLine(label, progress, stage) {
10
+ const pct = `${Math.round(progress * 100)}`.padStart(3, " ");
11
+ return `[progress] ${pct}% ${label}${stage ? ` | ${stage}` : ""}`;
12
+ }
38
13
 
39
- log(message) {
40
- // We don't log to file here because usually progress.log() is called alongside logger.info()
41
- // or we want the caller to decide whether it goes to the log file.
42
- this.display.writeLine(message);
43
- }
14
+ export function createProgressReporter(label, options = {}) {
15
+ const stream = options.stream || process.stdout;
16
+ let lastStatusLine = "";
44
17
 
45
- succeed(message) {
46
- const finalMsg = message || `${this.label} complete`;
47
- this.finish("[done]", 1, finalMsg);
48
- logger.debug(`${this.label} batch succeed: ${finalMsg}`);
18
+ function writeLine(message) {
19
+ stream.write(`${message}\n`);
49
20
  }
50
21
 
51
- fail(message) {
52
- const finalMsg = message || `${this.label} failed`;
53
- this.finish("[fail]", this.progress, finalMsg);
54
- logger.error(`${this.label} batch fail: ${finalMsg}`);
55
- }
22
+ return {
23
+ update(progress, stage = "") {
24
+ const line = formatStatusLine(label, clampProgress(progress), stage);
56
25
 
57
- finish(prefix, progress, message) {
58
- this.progress = clampProgress(progress);
59
- this.active = false;
60
- this.display.writeLine(`${prefix} ${message}`);
61
- }
26
+ if (line === lastStatusLine) {
27
+ return;
28
+ }
62
29
 
63
- writeStatus() {
64
- const line = this.buildStatusLine();
30
+ lastStatusLine = line;
31
+ writeLine(line);
32
+ },
65
33
 
66
- if (line === this.lastStatusLine) {
67
- return;
34
+ finish(status, message) {
35
+ const prefix = status === "fail" ? "[fail]" : "[done]";
36
+ writeLine(`${prefix} ${message || label}`);
68
37
  }
69
-
70
- this.lastStatusLine = line;
71
- this.display.writeLine(line);
72
- }
73
-
74
- buildStatusLine() {
75
- const pct = `${Math.round(this.progress * 100)}`.padStart(3, " ");
76
- return `[progress] ${pct}% ${this.label}${this.stage ? ` | ${this.stage}` : ""}`;
77
- }
78
- }
79
-
80
- export class ProgressDisplay {
81
- constructor(options = {}) {
82
- this.stream = options.stream || process.stdout;
83
- }
84
-
85
- createItem(label) {
86
- return new ProgressItem(this, label);
87
- }
88
-
89
- writeLine(message) {
90
- this.stream.write(`${message}\n`);
91
- }
92
-
93
- log(message) {
94
- this.writeLine(message);
95
- }
38
+ };
96
39
  }
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { ProgressDisplay } from "./progress-ui.js";
2
+ import { createProgressReporter } from "./progress-ui.js";
3
3
  import { resolveRepositoryContext } from "./vcs-client.js";
4
4
  import { logger } from "./logger.js";
5
5
  import {
@@ -172,10 +172,8 @@ export async function runReviewCycle(config) {
172
172
  }
173
173
 
174
174
  logger.info(`Reviewing ${backend.displayName} ${backend.changeName}s ${formatChangeList(backend, changeIdsToReview)}`);
175
- const progressDisplay = new ProgressDisplay();
176
- logger.setProgressDisplay(progressDisplay);
177
- const progress = progressDisplay.createItem(`${backend.displayName} ${backend.changeName} batch`);
178
- progress.start("0/" + changeIdsToReview.length + " completed");
175
+ const progress = createProgressReporter(`${backend.displayName} ${backend.changeName} batch`);
176
+ progress.update(0, `0/${changeIdsToReview.length} completed`);
179
177
 
180
178
  for (const [index, changeId] of changeIdsToReview.entries()) {
181
179
  logger.debug(`Starting review for ${backend.formatChangeId(changeId)}.`);
@@ -187,11 +185,13 @@ export async function runReviewCycle(config) {
187
185
  };
188
186
 
189
187
  try {
190
- await reviewChange(config, backend, targetInfo, changeId, { update: syncOverallProgress, log: (message) => progress.log(message) });
188
+ await reviewChange(config, backend, targetInfo, changeId, { update: syncOverallProgress });
191
189
  updateOverallProgress(progress, index + 1, changeIdsToReview.length, 0, `finished ${displayId}`);
192
190
  } catch (error) {
193
- progress.fail(`failed at ${displayId} (${index}/${changeIdsToReview.length} completed)`);
191
+ progress.finish("fail", `failed at ${displayId} (${index}/${changeIdsToReview.length} completed)`);
194
192
  throw error;
195
193
  }
196
194
  }
195
+
196
+ progress.finish("done", `${backend.displayName} ${backend.changeName} batch complete`);
197
197
  }