Skip to content

Commit d4d5eb6

Browse files
Gustav-SimonssonTheGreatAxios
authored andcommitted
refactor(plugins): compress verbose comments in the diagnostics module
1 parent a16e4d8 commit d4d5eb6

1 file changed

Lines changed: 20 additions & 26 deletions

File tree

‎src/plugins/diagnostics.ts‎

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Collector for plugin load/discovery diagnostics. Callers (especially the
2-
// interactive TUI) accumulate warnings and emit a single summary instead of
3-
// writing one stderr line per miss mid-frame.
1+
// Collect load/discovery warnings and emit one summary instead of writing
2+
// one stderr line per miss mid-frame.
43

54
import { getLogger } from "@intx/log";
65
import { LOG_NAMESPACE_ROOT } from "../branding.js";
@@ -15,7 +14,7 @@ export function createPluginLoadDiagnostics(): PluginLoadDiagnostics {
1514
return { warnings: [] };
1615
}
1716

18-
/** Build an onWarning callback that records into `diag`. */
17+
/** onWarning callback recording into `diag`. */
1918
export function pluginWarningSink(
2019
diag: PluginLoadDiagnostics,
2120
): (msg: string) => void {
@@ -25,10 +24,9 @@ export function pluginWarningSink(
2524
}
2625

2726
/**
28-
* Resolve the warning sink for a load call. There is no default: callers
29-
* must decide between a diagnostics collector (batched into one summary,
30-
* safe mid-frame) and an explicit onWarning (e.g. a raw stderr writer for
31-
* headless paths where no frame is being held).
27+
* Resolve the sink for a load call. No default: callers choose a collector
28+
* (batched, safe mid-frame) or an explicit onWarning (raw stderr where no
29+
* frame is held).
3230
*/
3331
export function resolvePluginWarningHandler(
3432
opts:
@@ -40,18 +38,16 @@ export function resolvePluginWarningHandler(
4038
: opts.onWarning;
4139
}
4240

43-
/** Named raw-stderr choice: `{ onWarning: stderrPluginWarning }`. */
41+
/** Raw-stderr choice: `{ onWarning: stderrPluginWarning }`. */
4442
export function stderrPluginWarning(msg: string): void {
4543
process.stderr.write(`plugins: ${msg}\n`);
4644
}
4745

4846
/**
49-
* One-line summary for a batch of load warnings. Skill-miss messages are
50-
* collapsed to `N skills missing: a, b, c`; mixed warnings get a count line.
51-
* Returns undefined when there is nothing to report.
52-
*
53-
* Skill names are deduplicated: a skill is missing once however many plugins
54-
* referenced it, and the count matches the printed names.
47+
* One-line load-warning summary. Skill misses collapse to `N skills
48+
* missing: a, b, c`; mixed warnings get a count line; nothing to report
49+
* yields undefined. Skill names dedupe: listed once however many plugins
50+
* referenced them, so the count matches the printed names.
5551
*/
5652
export function formatPluginWarningsSummary(
5753
warnings: readonly string[],
@@ -84,8 +80,8 @@ export function formatPluginWarningsSummary(
8480
}
8581

8682
/**
87-
* Format + emit a diagnostics summary in one call. Default write is one stderr
88-
* line; pass a custom sink for logger-backed callers (e.g. headless exec).
83+
* Format and emit a summary in one call. Default writes one stderr line;
84+
* pass a sink for logger-backed callers (headless exec).
8985
*/
9086
export function emitPluginWarningSummary(
9187
diag: PluginLoadDiagnostics,
@@ -98,19 +94,18 @@ export function emitPluginWarningSummary(
9894
}
9995

10096
/**
101-
* Emit a diagnostics summary through the structured logger instead of raw
102-
* stderr. The TUI holds the alternate screen for the whole session, so a
103-
* bare write lands mid-frame and corrupts the rendered transcript. The
104-
* logger already routes to the file-log sink installed at startup, so this
105-
* reuses it rather than adding a second path.
97+
* Emit the summary via the structured logger, not raw stderr. The TUI
98+
* holds the alternate screen the whole session, so a bare write lands
99+
* mid-frame and corrupts the transcript. The logger already routes to the
100+
* startup file-log sink, so this reuses it.
106101
*/
107102
export function emitPluginWarningLog(diag: PluginLoadDiagnostics): void {
108103
emitPluginWarningSummary(diag, (line) => pluginDiagnosticsLogger.warn(line));
109104
}
110105

111106
/**
112-
* Extract a plugin or agent id a warning names, when present. Skill-miss lines
113-
* lead with `agent <id>:`; tool-plugin start failures quote the candidate id.
107+
* Extract the plugin or agent id a warning names. Skill-miss lines lead
108+
* with `agent <id>:`; tool-plugin start failures quote the candidate id.
114109
*/
115110
export function pluginWarningSubjectId(warning: string): string | undefined {
116111
const agent = /^agent ([^:]+):/.exec(warning)?.[1];
@@ -121,8 +116,7 @@ export function pluginWarningSubjectId(warning: string): string | undefined {
121116
}
122117

123118
/**
124-
* Warnings attributable to one plugin: subject id matches the plugin id or any
125-
* of its agent profile ids.
119+
* Warnings whose subject id matches the plugin id or an agent profile id.
126120
*/
127121
export function warningsForPluginEntry(
128122
warnings: readonly string[],

0 commit comments

Comments
 (0)