@nzyme/cli 0.14.0 → 0.15.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.
Files changed (137) hide show
  1. package/bin/cli.js +3 -0
  2. package/dist/Command.d.ts +48 -5
  3. package/dist/Command.js +69 -6
  4. package/dist/Command.js.map +1 -1
  5. package/dist/Command.test.d.ts +1 -0
  6. package/dist/Command.test.js +77 -0
  7. package/dist/Command.test.js.map +1 -0
  8. package/dist/cli.d.ts +1 -1
  9. package/dist/cli.js +23 -3
  10. package/dist/cli.js.map +1 -1
  11. package/dist/codeIndex/IndexSettings.d.ts +60 -0
  12. package/dist/codeIndex/IndexSettings.js +59 -0
  13. package/dist/codeIndex/IndexSettings.js.map +1 -0
  14. package/dist/codeIndex/IndexSymbol.d.ts +32 -0
  15. package/dist/codeIndex/IndexSymbol.js +2 -0
  16. package/dist/codeIndex/IndexSymbol.js.map +1 -0
  17. package/dist/codeIndex/NzymeIndexConfig.d.ts +72 -0
  18. package/dist/codeIndex/NzymeIndexConfig.js +101 -0
  19. package/dist/codeIndex/NzymeIndexConfig.js.map +1 -0
  20. package/dist/codeIndex/NzymeIndexConfig.test.d.ts +1 -0
  21. package/dist/codeIndex/NzymeIndexConfig.test.js +56 -0
  22. package/dist/codeIndex/NzymeIndexConfig.test.js.map +1 -0
  23. package/dist/codeIndex/collectIndexSourceFiles.d.ts +8 -0
  24. package/dist/codeIndex/collectIndexSourceFiles.js +57 -0
  25. package/dist/codeIndex/collectIndexSourceFiles.js.map +1 -0
  26. package/dist/codeIndex/collectSymbols.d.ts +27 -0
  27. package/dist/codeIndex/collectSymbols.js +151 -0
  28. package/dist/codeIndex/collectSymbols.js.map +1 -0
  29. package/dist/codeIndex/collectSymbols.test.d.ts +1 -0
  30. package/dist/codeIndex/collectSymbols.test.js +204 -0
  31. package/dist/codeIndex/collectSymbols.test.js.map +1 -0
  32. package/dist/codeIndex/extractComponent.d.ts +25 -0
  33. package/dist/codeIndex/extractComponent.js +38 -0
  34. package/dist/codeIndex/extractComponent.js.map +1 -0
  35. package/dist/codeIndex/extractComponent.test.d.ts +1 -0
  36. package/dist/codeIndex/extractComponent.test.js +65 -0
  37. package/dist/codeIndex/extractComponent.test.js.map +1 -0
  38. package/dist/codeIndex/extractDefineSymbol.d.ts +30 -0
  39. package/dist/codeIndex/extractDefineSymbol.js +86 -0
  40. package/dist/codeIndex/extractDefineSymbol.js.map +1 -0
  41. package/dist/codeIndex/extractDefineSymbol.test.d.ts +1 -0
  42. package/dist/codeIndex/extractDefineSymbol.test.js +142 -0
  43. package/dist/codeIndex/extractDefineSymbol.test.js.map +1 -0
  44. package/dist/codeIndex/extractEntity.d.ts +29 -0
  45. package/dist/codeIndex/extractEntity.js +63 -0
  46. package/dist/codeIndex/extractEntity.js.map +1 -0
  47. package/dist/codeIndex/extractEntity.test.d.ts +1 -0
  48. package/dist/codeIndex/extractEntity.test.js +79 -0
  49. package/dist/codeIndex/extractEntity.test.js.map +1 -0
  50. package/dist/codeIndex/extractUtil.d.ts +27 -0
  51. package/dist/codeIndex/extractUtil.js +98 -0
  52. package/dist/codeIndex/extractUtil.js.map +1 -0
  53. package/dist/codeIndex/extractUtil.test.d.ts +1 -0
  54. package/dist/codeIndex/extractUtil.test.js +111 -0
  55. package/dist/codeIndex/extractUtil.test.js.map +1 -0
  56. package/dist/codeIndex/importPathOf.d.ts +18 -0
  57. package/dist/codeIndex/importPathOf.js +17 -0
  58. package/dist/codeIndex/importPathOf.js.map +1 -0
  59. package/dist/codeIndex/importPathOf.test.d.ts +1 -0
  60. package/dist/codeIndex/importPathOf.test.js +40 -0
  61. package/dist/codeIndex/importPathOf.test.js.map +1 -0
  62. package/dist/codeIndex/jsdocSummary.d.ts +9 -0
  63. package/dist/codeIndex/jsdocSummary.js +18 -0
  64. package/dist/codeIndex/jsdocSummary.js.map +1 -0
  65. package/dist/codeIndex/jsdocSummary.test.d.ts +1 -0
  66. package/dist/codeIndex/jsdocSummary.test.js +33 -0
  67. package/dist/codeIndex/jsdocSummary.test.js.map +1 -0
  68. package/dist/codeIndex/renderMarkdown.d.ts +27 -0
  69. package/dist/codeIndex/renderMarkdown.js +171 -0
  70. package/dist/codeIndex/renderMarkdown.js.map +1 -0
  71. package/dist/codeIndex/renderMarkdown.test.d.ts +1 -0
  72. package/dist/codeIndex/renderMarkdown.test.js +291 -0
  73. package/dist/codeIndex/renderMarkdown.test.js.map +1 -0
  74. package/dist/commands/DepcheckCommand.d.ts +17 -0
  75. package/dist/commands/DepcheckCommand.js +229 -42
  76. package/dist/commands/DepcheckCommand.js.map +1 -1
  77. package/dist/commands/FormatMarkdownCommand.d.ts +22 -0
  78. package/dist/commands/FormatMarkdownCommand.js +256 -0
  79. package/dist/commands/FormatMarkdownCommand.js.map +1 -0
  80. package/dist/commands/FormatMarkdownCommand.test.d.ts +1 -0
  81. package/dist/commands/FormatMarkdownCommand.test.js +82 -0
  82. package/dist/commands/FormatMarkdownCommand.test.js.map +1 -0
  83. package/dist/commands/IndexCommand.d.ts +20 -0
  84. package/dist/commands/IndexCommand.js +81 -0
  85. package/dist/commands/IndexCommand.js.map +1 -0
  86. package/dist/commands/IndexCommand.test.d.ts +1 -0
  87. package/dist/commands/IndexCommand.test.js +126 -0
  88. package/dist/commands/IndexCommand.test.js.map +1 -0
  89. package/dist/commands/LocaliseCommand.d.ts +23 -0
  90. package/dist/commands/LocaliseCommand.js +125 -0
  91. package/dist/commands/LocaliseCommand.js.map +1 -0
  92. package/dist/commands/MonorepoCommand.d.ts +14 -0
  93. package/dist/commands/MonorepoCommand.js +243 -144
  94. package/dist/commands/MonorepoCommand.js.map +1 -1
  95. package/dist/commands/QuietRunCommand.d.ts +27 -0
  96. package/dist/commands/QuietRunCommand.js +140 -0
  97. package/dist/commands/QuietRunCommand.js.map +1 -0
  98. package/dist/commands/QuietRunCommand.test.d.ts +1 -0
  99. package/dist/commands/QuietRunCommand.test.js +48 -0
  100. package/dist/commands/QuietRunCommand.test.js.map +1 -0
  101. package/dist/commands/SubmoduleBumpCommand.d.ts +27 -0
  102. package/dist/commands/SubmoduleBumpCommand.js +77 -0
  103. package/dist/commands/SubmoduleBumpCommand.js.map +1 -0
  104. package/dist/execute.d.ts +7 -2
  105. package/dist/execute.js +4 -2
  106. package/dist/execute.js.map +1 -1
  107. package/dist/index.d.ts +1 -1
  108. package/dist/index.js +1 -1
  109. package/dist/index.js.map +1 -1
  110. package/dist/initialize.d.ts +1 -15
  111. package/dist/initialize.js +4 -8
  112. package/dist/initialize.js.map +1 -1
  113. package/dist/quietRun/quietRunReport.d.ts +70 -0
  114. package/dist/quietRun/quietRunReport.js +128 -0
  115. package/dist/quietRun/quietRunReport.js.map +1 -0
  116. package/dist/quietRun/quietRunReport.test.d.ts +1 -0
  117. package/dist/quietRun/quietRunReport.test.js +87 -0
  118. package/dist/quietRun/quietRunReport.test.js.map +1 -0
  119. package/dist/submodule/GitRepository.d.ts +70 -0
  120. package/dist/submodule/GitRepository.js +129 -0
  121. package/dist/submodule/GitRepository.js.map +1 -0
  122. package/dist/submodule/bumpSubmodule.d.ts +45 -0
  123. package/dist/submodule/bumpSubmodule.js +52 -0
  124. package/dist/submodule/bumpSubmodule.js.map +1 -0
  125. package/dist/submodule/renderBumpSummary.d.ts +12 -0
  126. package/dist/submodule/renderBumpSummary.js +50 -0
  127. package/dist/submodule/renderBumpSummary.js.map +1 -0
  128. package/dist/submodule/renderBumpSummary.test.d.ts +1 -0
  129. package/dist/submodule/renderBumpSummary.test.js +55 -0
  130. package/dist/submodule/renderBumpSummary.test.js.map +1 -0
  131. package/dist/submodule/submodule.test.d.ts +1 -0
  132. package/dist/submodule/submodule.test.js +155 -0
  133. package/dist/submodule/submodule.test.js.map +1 -0
  134. package/package.json +55 -50
  135. package/dist/commands/BuildCommand.d.ts +0 -15
  136. package/dist/commands/BuildCommand.js +0 -49
  137. package/dist/commands/BuildCommand.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ import { Command } from '../Command.js';
2
+ /**
3
+ * Runs a command while keeping its full output OUT of a coding agent's context.
4
+ *
5
+ * Build, test, e2e and codegen commands dump hundreds to thousands of lines into the agent's
6
+ * context, where they sit and get re-read on every later turn — the single biggest driver of
7
+ * cache/token spend. On a green run the agent needs one line ("it passed"); on a red run it needs
8
+ * the failing lines and a count, not the whole log. So the full output goes to a gitignored log file
9
+ * and only a summary is printed. The log stays on disk for the rare case a deeper look is needed —
10
+ * read it selectively (grep, a line range) rather than dumping it back into context.
11
+ */
12
+ export declare class QuietRunCommand extends Command {
13
+ static paths: string[][];
14
+ static usage: import("clipanion").Usage;
15
+ command: string[];
16
+ cwd: string;
17
+ /**
18
+ * Execute the command.
19
+ */
20
+ run(): Promise<number>;
21
+ /** `QUIET_RUN_LOGDIR` (relative to the cwd) when set, else `.context/cmd-logs` under the project root. */
22
+ private getLogDir;
23
+ /** The project root, or the cwd outside any project — a command run anywhere still gets its log. */
24
+ private getProjectRoot;
25
+ /** The log path relative to the cwd when it lies beneath it (shorter to read), else absolute. */
26
+ private toDisplayPath;
27
+ }
@@ -0,0 +1,140 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { mkdir, open, readFile } from 'node:fs/promises';
3
+ import { constants } from 'node:os';
4
+ import path from 'node:path';
5
+ import { getProjectRoot } from '@nzyme/project-utils/getProjectRoot.js';
6
+ import { Command } from '../Command.js';
7
+ import { Option } from '../index.js';
8
+ import { getQuietRunLogFileName, renderQuietRunReport } from '../quietRun/quietRunReport.js';
9
+ /** Default lines of trailing output shown on failure. */
10
+ const DEFAULT_TAIL = 30;
11
+ /** Default maximum of error-signature lines shown on failure. */
12
+ const DEFAULT_MATCHES = 40;
13
+ /** Exit code a shell uses for a command it cannot find — reused when the command cannot be spawned. */
14
+ const COMMAND_NOT_FOUND = 127;
15
+ /**
16
+ * Runs a command while keeping its full output OUT of a coding agent's context.
17
+ *
18
+ * Build, test, e2e and codegen commands dump hundreds to thousands of lines into the agent's
19
+ * context, where they sit and get re-read on every later turn — the single biggest driver of
20
+ * cache/token spend. On a green run the agent needs one line ("it passed"); on a red run it needs
21
+ * the failing lines and a count, not the whole log. So the full output goes to a gitignored log file
22
+ * and only a summary is printed. The log stays on disk for the rare case a deeper look is needed —
23
+ * read it selectively (grep, a line range) rather than dumping it back into context.
24
+ */
25
+ export class QuietRunCommand extends Command {
26
+ static paths = [['quiet-run']];
27
+ static usage = Command.Usage({
28
+ category: 'Agents',
29
+ description: 'Run a command with its output sent to a log file, printing only a summary',
30
+ details: `
31
+ Runs the command with its combined stdout/stderr written to a log file in
32
+ \`<project root>/.context/cmd-logs/\`. On success prints one line (command, line
33
+ count, duration, log path). On failure prints the error-looking lines, the last
34
+ lines of output and the log path. The exit code is the command's own — except that
35
+ bun's "Usage: bun run" banner (an invalid invocation that exits 0 without running
36
+ anything) is reported as a failure with exit code 1.
37
+
38
+ Tunables (environment variables): QUIET_RUN_LOGDIR — where logs go (default
39
+ \`<project root>/.context/cmd-logs\`); QUIET_RUN_TAIL — lines of trailing output shown
40
+ on failure (default ${DEFAULT_TAIL}); QUIET_RUN_MATCHES — maximum error-signature lines
41
+ shown on failure (default ${DEFAULT_MATCHES}).
42
+ `,
43
+ examples: [
44
+ ['Build quietly', 'nzyme quiet-run bun run build'],
45
+ ['Type-check quietly', 'nzyme quiet-run tsgo --build'],
46
+ ],
47
+ });
48
+ command = Option.Proxy({ name: 'command', required: 1 });
49
+ cwd = process.cwd();
50
+ /**
51
+ * Execute the command.
52
+ */
53
+ async run() {
54
+ const [executable, ...args] = this.command;
55
+ if (!executable) {
56
+ this.context.stderr.write('usage: nzyme quiet-run <command> [args...]\n');
57
+ return 2;
58
+ }
59
+ const logDir = this.getLogDir();
60
+ await mkdir(logDir, { recursive: true });
61
+ const logPath = path.join(logDir, getQuietRunLogFileName({ executable, date: new Date(), pid: process.pid }));
62
+ const startedAt = Date.now();
63
+ const exitCode = await runToLog({ executable, args, logPath });
64
+ const seconds = Math.floor((Date.now() - startedAt) / 1000);
65
+ const report = renderQuietRunReport({
66
+ label: this.command.join(' '),
67
+ logPath: this.toDisplayPath(logPath),
68
+ exitCode,
69
+ seconds,
70
+ log: await readFile(logPath, 'utf8'),
71
+ tailCount: readCount('QUIET_RUN_TAIL', DEFAULT_TAIL),
72
+ maxMatches: readCount('QUIET_RUN_MATCHES', DEFAULT_MATCHES),
73
+ });
74
+ this.context.stdout.write(report.stdout);
75
+ this.context.stderr.write(report.stderr);
76
+ return report.exitCode;
77
+ }
78
+ /** `QUIET_RUN_LOGDIR` (relative to the cwd) when set, else `.context/cmd-logs` under the project root. */
79
+ getLogDir() {
80
+ const configured = process.env.QUIET_RUN_LOGDIR;
81
+ if (configured) {
82
+ return path.resolve(this.cwd, configured);
83
+ }
84
+ return path.join(this.getProjectRoot(), '.context', 'cmd-logs');
85
+ }
86
+ /** The project root, or the cwd outside any project — a command run anywhere still gets its log. */
87
+ getProjectRoot() {
88
+ try {
89
+ return getProjectRoot(this.cwd);
90
+ }
91
+ catch {
92
+ return this.cwd;
93
+ }
94
+ }
95
+ /** The log path relative to the cwd when it lies beneath it (shorter to read), else absolute. */
96
+ toDisplayPath(logPath) {
97
+ const relative = path.relative(this.cwd, logPath);
98
+ return relative.startsWith('..') || path.isAbsolute(relative) ? logPath : relative;
99
+ }
100
+ }
101
+ /**
102
+ * Runs the command with stdout and stderr both going to the log file — the same file descriptor, so
103
+ * their lines interleave in the order they were written, as `>log 2>&1` does. stdin stays attached,
104
+ * so an interactive prompt still works. Resolves with the exit code: `128 + signal` for a command
105
+ * killed by a signal and {@link COMMAND_NOT_FOUND} for one that could not be spawned, as a shell
106
+ * reports them.
107
+ */
108
+ async function runToLog(options) {
109
+ const { executable, args, logPath } = options;
110
+ const log = await open(logPath, 'w');
111
+ try {
112
+ const outcome = await new Promise(resolve => {
113
+ const child = spawn(executable, args, { stdio: ['inherit', log.fd, log.fd] });
114
+ child.on('error', error => resolve({ error }));
115
+ child.on('close', (code, signal) => resolve({ code: code ?? 128 + getSignalNumber(signal) }));
116
+ });
117
+ if ('error' in outcome) {
118
+ await log.write(`quiet-run: ${executable}: ${outcome.error.message}\n`);
119
+ return COMMAND_NOT_FOUND;
120
+ }
121
+ return outcome.code;
122
+ }
123
+ finally {
124
+ await log.close();
125
+ }
126
+ }
127
+ /** The number of a signal, or 0 when unknown. */
128
+ function getSignalNumber(signal) {
129
+ return signal ? constants.signals[signal] : 0;
130
+ }
131
+ /** Reads a non-negative integer tunable from the environment, falling back to its default. */
132
+ function readCount(name, fallback) {
133
+ const raw = process.env[name];
134
+ if (!raw) {
135
+ return fallback;
136
+ }
137
+ const value = Number(raw);
138
+ return Number.isInteger(value) && value >= 0 ? value : fallback;
139
+ }
140
+ //# sourceMappingURL=QuietRunCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuietRunCommand.js","sourceRoot":"","sources":["../../src/commands/QuietRunCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAExE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE7F,yDAAyD;AACzD,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB,iEAAiE;AACjE,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,uGAAuG;AACvG,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B;;;;;;;;;GASG;AACH,MAAM,OAAO,eAAgB,SAAQ,OAAO;IACxC,MAAM,CAAU,KAAK,GAAG,CAAC,CAAC,WAAW,CAAC,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AC;IACxB,CAAC;YAAS,CAAC;QACP,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;AACL,CAAC;AAED,iDAAiD;AACjD,SAAS,eAAe,CAAC,MAA6B;IAClD,OAAO,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,8FAA8F;AAC9F,SAAS,SAAS,CAAC,IAAY,EAAE,QAAgB;IAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,EAAE,CAAC;QACP,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AACpE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import fs from 'node:fs/promises';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { expect, test } from 'bun:test';
5
+ const CLI_PATH = new URL('../cli.ts', import.meta.url).pathname;
6
+ test('prints one line for a succeeding command and keeps its output in the log', async () => {
7
+ const logDir = await fs.mkdtemp(path.join(os.tmpdir(), 'quiet-run-'));
8
+ const result = await runQuietRun(logDir, [
9
+ process.execPath,
10
+ '-e',
11
+ 'console.log(["hello", "from the child"].join(" "))',
12
+ ]);
13
+ expect(result.exitCode).toBe(0);
14
+ expect(result.stdout).toMatch(/^✓ passed · .+ · 1 lines · \d+s · full log: .+\.log\n$/);
15
+ expect(result.stdout).not.toContain('hello from the child');
16
+ const logFiles = (await fs.readdir(logDir)).filter(file => file.endsWith('.log'));
17
+ expect(logFiles).toHaveLength(1);
18
+ expect(await fs.readFile(path.join(logDir, String(logFiles[0])), 'utf8')).toBe('hello from the child\n');
19
+ });
20
+ test('reports a failing command with its error lines and passes its exit code through', async () => {
21
+ const logDir = await fs.mkdtemp(path.join(os.tmpdir(), 'quiet-run-'));
22
+ const script = 'console.log("step one"); console.error("error: it broke"); process.exit(3)';
23
+ const result = await runQuietRun(logDir, [process.execPath, '-e', script]);
24
+ expect(result.exitCode).toBe(3);
25
+ expect(result.stdout).toMatch(/^✗ FAILED \(exit 3\) · /);
26
+ expect(result.stdout).toContain('--- error-signature lines (grep) ---\n2:error: it broke\n');
27
+ expect(result.stdout).toContain('--- last 30 lines ---\nstep one\nerror: it broke\n');
28
+ expect(result.stdout).toContain('(read selectively; do not re-dump it whole)');
29
+ });
30
+ test('reports a command that cannot be found with the shell exit code', async () => {
31
+ const logDir = await fs.mkdtemp(path.join(os.tmpdir(), 'quiet-run-'));
32
+ const result = await runQuietRun(logDir, ['nzyme-quiet-run-no-such-command']);
33
+ expect(result.exitCode).toBe(127);
34
+ expect(result.stdout).toMatch(/^✗ FAILED \(exit 127\) · /);
35
+ });
36
+ async function runQuietRun(logDir, command) {
37
+ // The CLI resolves the project root on start-up, so it has to run inside a project.
38
+ await fs.writeFile(path.join(logDir, 'package.json'), '{ "name": "fixture" }');
39
+ const child = Bun.spawn([process.execPath, '--conditions=source', CLI_PATH, 'quiet-run', ...command], {
40
+ cwd: logDir,
41
+ env: { ...process.env, QUIET_RUN_LOGDIR: logDir },
42
+ stdout: 'pipe',
43
+ stderr: 'pipe',
44
+ });
45
+ const [stdout, exitCode] = await Promise.all([new Response(child.stdout).text(), child.exited]);
46
+ return { stdout, exitCode };
47
+ }
48
+ //# sourceMappingURL=QuietRunCommand.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuietRunCommand.test.js","sourceRoot":"","sources":["../../src/commands/QuietRunCommand.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO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,WAAW,CAAC,MAAc,EAAE,OAAiB;IACxD,oFAAoF;IACpF,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,uBAAuB,CAAC,CAAC;IAE/E,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,qBAAqB,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,EAAE;QAClG,GAAG,EAAE,MAAM;QACX,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE;QACjD,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,MAAM;KACjB,CAAC,CAAC;IAEH,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAChG,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { Command } from '../Command.js';
2
+ /**
3
+ * The exact stdout of `submodule bump` when the gitlink already points at the source commit. A
4
+ * workflow tells "nothing to bump" from "bumped" by this line, so it must never change.
5
+ */
6
+ export declare const BUMP_UNCHANGED_OUTPUT = "unchanged";
7
+ /**
8
+ * Moves the product's submodule to a source ref and stages the new gitlink — the start of a bump PR.
9
+ *
10
+ * A product owns its pin and does not follow nzyme's `main` blindly: it proposes a newer nzyme commit
11
+ * in a PR, and only its own CI going green lets that commit in. This prepares that PR's change and
12
+ * its description; committing, pushing and merging stay with the product's workflow, which owns
13
+ * the policy (cadence, source ref, auto-merge). See `docs/consumers.md`.
14
+ */
15
+ export declare class SubmoduleBumpCommand extends Command {
16
+ static paths: string[][];
17
+ static usage: import("clipanion").Usage;
18
+ source: string;
19
+ submodulePath: string;
20
+ remote: string;
21
+ summaryFile: string | undefined;
22
+ cwd: string;
23
+ /**
24
+ * Execute the command.
25
+ */
26
+ run(): Promise<number>;
27
+ }
@@ -0,0 +1,77 @@
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { Command } from '../Command.js';
4
+ import { Option } from '../index.js';
5
+ import { bumpSubmodule } from '../submodule/bumpSubmodule.js';
6
+ import { renderBumpSummary } from '../submodule/renderBumpSummary.js';
7
+ /**
8
+ * The exact stdout of `submodule bump` when the gitlink already points at the source commit. A
9
+ * workflow tells "nothing to bump" from "bumped" by this line, so it must never change.
10
+ */
11
+ export const BUMP_UNCHANGED_OUTPUT = 'unchanged';
12
+ /**
13
+ * Moves the product's submodule to a source ref and stages the new gitlink — the start of a bump PR.
14
+ *
15
+ * A product owns its pin and does not follow nzyme's `main` blindly: it proposes a newer nzyme commit
16
+ * in a PR, and only its own CI going green lets that commit in. This prepares that PR's change and
17
+ * its description; committing, pushing and merging stay with the product's workflow, which owns
18
+ * the policy (cadence, source ref, auto-merge). See `docs/consumers.md`.
19
+ */
20
+ export class SubmoduleBumpCommand extends Command {
21
+ static paths = [['submodule', 'bump']];
22
+ static usage = Command.Usage({
23
+ category: 'Submodules',
24
+ description: 'Move the submodule to a source ref and stage it, printing a markdown summary',
25
+ details: `
26
+ Run in the product repository. Fetches \`--source\` in the submodule (a branch — \`main\`
27
+ or \`origin/main\` — a tag or a commit SHA), checks the submodule out at it (detached)
28
+ and \`git add\`s the submodule path. Commits and pushes nothing.
29
+
30
+ When the submodule moved, prints a markdown summary (old → new, a compare link for a
31
+ GitHub remote, the new commits) and writes it to \`--summary-file\` if given.
32
+
33
+ When the gitlink already points at the source commit, nothing is staged, no summary file
34
+ is written, and stdout is exactly the single line \`${BUMP_UNCHANGED_OUTPUT}\`. Both cases
35
+ exit 0; any other exit code is an error.
36
+ `,
37
+ examples: [
38
+ ['Bump to the tip of main', 'nzyme submodule bump --source origin/main'],
39
+ ['Bump to a release tag', 'nzyme submodule bump --source v0.15.0 --summary-file bump.md'],
40
+ ],
41
+ });
42
+ source = Option.String('--source', {
43
+ required: true,
44
+ description: 'Branch, tag or commit to move the submodule to, e.g. origin/main',
45
+ });
46
+ submodulePath = Option.String('--path', 'nzyme', {
47
+ description: 'Path of the submodule in the product repository',
48
+ });
49
+ remote = Option.String('--remote', 'origin', { description: "The submodule's remote to fetch from" });
50
+ summaryFile = Option.String('--summary-file', { description: 'Also write the markdown summary to this file' });
51
+ cwd = process.cwd();
52
+ /**
53
+ * Execute the command.
54
+ */
55
+ async run() {
56
+ const bump = await bumpSubmodule({
57
+ repoDir: this.cwd,
58
+ submodulePath: this.submodulePath,
59
+ source: this.source,
60
+ remote: this.remote,
61
+ });
62
+ if (!bump.changed) {
63
+ this.context.stderr.write(`${bump.submodulePath} is already at ${bump.current} (${bump.source}).\n`);
64
+ this.context.stdout.write(`${BUMP_UNCHANGED_OUTPUT}\n`);
65
+ return 0;
66
+ }
67
+ const summary = renderBumpSummary(bump);
68
+ if (this.summaryFile) {
69
+ const summaryPath = path.resolve(this.cwd, this.summaryFile);
70
+ await mkdir(path.dirname(summaryPath), { recursive: true });
71
+ await writeFile(summaryPath, summary);
72
+ }
73
+ this.context.stdout.write(summary);
74
+ return 0;
75
+ }
76
+ }
77
+ //# sourceMappingURL=SubmoduleBumpCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SubmoduleBumpCommand.js","sourceRoot":"","sources":["../../src/commands/SubmoduleBumpCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAA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AAI,CAAC,MAAM;SACtB,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAChB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,aAAa,kBAAkB,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,MAAM,MAAM,CAAC,CAAC;YACrG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,qBAAqB,IAAI,CAAC,CAAC;YACxD,OAAO,CAAC,CAAC;QACb,CAAC;QAED,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;YAC7D,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5D,MAAM,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,CAAC,CAAC;IACb,CAAC;CACJ"}
package/dist/execute.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Container } from '@nzyme/ioc';
2
- import { CommandClass } from './Command.js';
1
+ import type { Container } from '@nzyme/ioc/Container.js';
2
+ import type { CommandClass, CommandErrorHandler } from './Command.js';
3
3
  /**
4
4
  * Options for creating a CLI program
5
5
  */
@@ -12,6 +12,11 @@ export interface ExecuteOptions {
12
12
  commands: CommandClass[];
13
13
  /** Container to use for the CLI program */
14
14
  container?: Container;
15
+ /**
16
+ * Rewrites any error a command throws before it is reported — one handler for the whole
17
+ * program, so no command has to opt in or be subclassed. See {@link CommandErrorHandler}.
18
+ */
19
+ onError?: CommandErrorHandler;
15
20
  }
16
21
  /**
17
22
  * Execute a CLI program
package/dist/execute.js CHANGED
@@ -1,5 +1,6 @@
1
- import { createContainer } from '@nzyme/ioc';
2
1
  import { Builtins, Cli } from 'clipanion';
2
+ import { createContainer } from '@nzyme/ioc/Container.js';
3
+ import { PrettyCliLoggerTransport } from '@nzyme/logging/PrettyCliLoggerTransport.js';
3
4
  /**
4
5
  * Execute a CLI program
5
6
  * @param options - Program configuration options
@@ -10,11 +11,12 @@ export async function execute(options) {
10
11
  binaryLabel: options.title,
11
12
  });
12
13
  const container = options.container ?? createContainer();
14
+ container.register(PrettyCliLoggerTransport);
13
15
  for (const command of options.commands) {
14
16
  cli.register(command);
15
17
  }
16
18
  cli.register(Builtins.HelpCommand);
17
19
  cli.register(Builtins.VersionCommand);
18
- await cli.runExit(process.argv.slice(2), { container });
20
+ await cli.runExit(process.argv.slice(2), { container, onError: options.onError });
19
21
  }
20
22
  //# sourceMappingURL=execute.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"execute.js","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,eAAe,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAiB1C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAuB;IACjD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAiB;QAChC,UAAU,EAAE,OAAO,CAAC,IAAI;QACxB,WAAW,EAAE,OAAO,CAAC,KAAK;KAC7B,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,eAAe,EAAE,CAAC;IAEzD,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC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1
  export * from './Command.js';
2
2
  export * from './execute.js';
3
3
  export * from './initialize.js';
4
- export { UsageError, Option } from 'clipanion';
4
+ export { Option, UsageError } from 'clipanion';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './Command.js';
2
2
  export * from './execute.js';
3
3
  export * from './initialize.js';
4
- export { UsageError, Option } from 'clipanion';
4
+ export { Option, UsageError } from 'clipanion';
5
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
@@ -1,18 +1,4 @@
1
- /**
2
- * Options for initializing the CLI.
3
- */
4
- export interface InitializeOptions {
5
- /**
6
- * The environment to load files for.
7
- * When provided, it will load files with the `.env.<env>` format.
8
- */
9
- env?: string | string[];
10
- /**
11
- * The working directory to load the environment file from.
12
- */
13
- cwd?: string;
14
- }
15
1
  /**
16
2
  * Initialize the CLI.
17
3
  */
18
- export declare function initialize(options?: InitializeOptions): void;
4
+ export declare function initialize(): void;
@@ -1,14 +1,10 @@
1
- import { consola } from 'consola';
2
- import sourceMap from 'source-map-support';
3
- import { patchNodeWarnings } from '@nzyme/node-utils';
4
- import { loadEnvVariables } from '@nzyme/project-utils';
1
+ import { install } from 'source-map-support';
2
+ import { patchNodeWarnings } from '@nzyme/node-utils/patchNodeWarnings.js';
5
3
  /**
6
4
  * Initialize the CLI.
7
5
  */
8
- export function initialize(options = {}) {
9
- consola.wrapAll();
10
- sourceMap.install();
6
+ export function initialize() {
7
+ install();
11
8
  patchNodeWarnings();
12
- loadEnvVariables({ env: options.env });
13
9
  }
14
10
  //# sourceMappingURL=initialize.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../src/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAiBxD;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,UAA6B,EAAE;IACtD,OAAO,CAAC,OAAO,EAAE,CAAC;IAClB,SAAS,CAAC,OAAO,EAAE,CAAC;IACpB,iBAAiB,EAAE,CAAC;IACpB,gBAAgB,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAC3C,CAAC"}
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../src/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAE3E;;GAEG;AACH,MAAM,UAAU,UAAU;IACtB,OAAO,EAAE,CAAC;IACV,iBAAiB,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,70 @@
1
+ /** Inputs for {@link renderQuietRunReport}. */
2
+ export interface QuietRunReportOptions {
3
+ /** The wrapped command line, as shown to the reader. */
4
+ label: string;
5
+ /** Path of the full log, as shown to the reader. */
6
+ logPath: string;
7
+ /** The wrapped command's exit code. */
8
+ exitCode: number;
9
+ /** Wall-clock duration of the run, in whole seconds. */
10
+ seconds: number;
11
+ /** The full combined stdout/stderr of the run. */
12
+ log: string;
13
+ /** Lines of trailing output to show on failure. */
14
+ tailCount: number;
15
+ /** Maximum number of error-signature lines to show on failure. */
16
+ maxMatches: number;
17
+ }
18
+ /** What `quiet-run` prints and the exit code it ends with. */
19
+ export interface QuietRunReport {
20
+ /** The exit code to end with — the wrapped command's own, except for a bun usage banner. */
21
+ exitCode: number;
22
+ /** Text for stdout. */
23
+ stdout: string;
24
+ /** Text for stderr. */
25
+ stderr: string;
26
+ }
27
+ /**
28
+ * Turns a finished run into the little that should reach a coding agent's context: one line on
29
+ * success; on failure the error-looking lines, a bounded tail and the log path. Kept pure so the
30
+ * exact output format — which agents learn to read — is pinned by tests.
31
+ *
32
+ * The exit code is passed through, with one exception: a bun usage banner on an otherwise
33
+ * successful run is reported as a failure with exit code 1 (see {@link getBunUsageBanner}).
34
+ * @__NO_SIDE_EFFECTS__
35
+ */
36
+ export declare function renderQuietRunReport(options: QuietRunReportOptions): QuietRunReport;
37
+ /**
38
+ * Returns the lines of a log that look like errors, prefixed with their 1-based line number
39
+ * (`12:error TS2322: …`, as `grep -n` prints them), at most `maxMatches` of them. Counting stops at
40
+ * the limit rather than truncating afterwards, so an empty result reliably means "no error lines at
41
+ * all", never "too many to show".
42
+ * @__NO_SIDE_EFFECTS__
43
+ */
44
+ export declare function extractErrorLines(log: string, maxMatches: number): string[];
45
+ /**
46
+ * Detects bun's own usage banner, returning the banner line, or `null` when the log is not one.
47
+ *
48
+ * An invalid `bun … run …` invocation (e.g. a stale or renamed script name) prints bun's usage
49
+ * banner and exits 0 — a false green with no command actually run. Narrow on purpose: only the
50
+ * FIRST non-empty output line counts, so a later legitimate mention of `Usage: bun run` in real
51
+ * output cannot trip it.
52
+ * @__NO_SIDE_EFFECTS__
53
+ */
54
+ export declare function getBunUsageBanner(log: string): string | null;
55
+ /** Inputs for {@link getQuietRunLogFileName}. */
56
+ export interface QuietRunLogFileNameOptions {
57
+ /** The command's first word, e.g. `bun` or `./scripts/build.sh`. */
58
+ executable: string;
59
+ /** When the run started. */
60
+ date: Date;
61
+ /** Id of the process running it. */
62
+ pid: number;
63
+ }
64
+ /**
65
+ * The log file name for a run: the command's first word made filename-safe, a local timestamp and
66
+ * the process id — e.g. `bun-20260102-030405-1234.log`. The timestamp keeps logs in run order; the
67
+ * pid keeps two runs started in the same second apart.
68
+ * @__NO_SIDE_EFFECTS__
69
+ */
70
+ export declare function getQuietRunLogFileName(options: QuietRunLogFileNameOptions): string;