@bbcsoftwarefactory/cli 0.1.1 → 1.1.2

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 (86) hide show
  1. package/dist/audit-ledger.d.ts +2 -0
  2. package/dist/audit-ledger.js +71 -0
  3. package/dist/bbc-install.d.ts +2 -0
  4. package/dist/bbc-install.js +1250 -0
  5. package/dist/bbc.js +87 -3
  6. package/dist/change-lane/classification.js +3 -1
  7. package/dist/check-issue-claim.d.ts +2 -0
  8. package/dist/check-issue-claim.js +146 -0
  9. package/dist/check-worktree-guard.d.ts +2 -0
  10. package/dist/check-worktree-guard.js +114 -0
  11. package/dist/error-scan.d.ts +3 -0
  12. package/dist/error-scan.js +216 -0
  13. package/dist/export-public.d.ts +9 -0
  14. package/dist/export-public.js +274 -0
  15. package/dist/fetch-issue-attachments.d.ts +22 -0
  16. package/dist/fetch-issue-attachments.js +325 -0
  17. package/dist/issue-claim/evaluation.d.ts +66 -0
  18. package/dist/issue-claim/evaluation.js +259 -0
  19. package/dist/issue-claim/loaders.d.ts +5 -0
  20. package/dist/issue-claim/loaders.js +116 -0
  21. package/dist/list-zed-commands.d.ts +7 -0
  22. package/dist/list-zed-commands.js +288 -0
  23. package/dist/plan-issue-triage.d.ts +3 -0
  24. package/dist/plan-issue-triage.js +404 -0
  25. package/dist/question-gate/ledger.d.ts +5 -0
  26. package/dist/question-gate/ledger.js +115 -0
  27. package/dist/question-gate/rules.d.ts +40 -0
  28. package/dist/question-gate/rules.js +483 -0
  29. package/dist/recap/board.d.ts +5 -0
  30. package/dist/recap/board.js +384 -0
  31. package/dist/recap/git-and-github.d.ts +11 -0
  32. package/dist/recap/git-and-github.js +620 -0
  33. package/dist/recap/report-and-hud.d.ts +2 -0
  34. package/dist/recap/report-and-hud.js +294 -0
  35. package/dist/recap/time-and-refs.d.ts +27 -0
  36. package/dist/recap/time-and-refs.js +148 -0
  37. package/dist/recap.d.ts +2 -0
  38. package/dist/recap.js +217 -0
  39. package/dist/render-workflow.js +12 -14
  40. package/dist/resolve-containers.d.ts +2 -0
  41. package/dist/resolve-containers.js +96 -0
  42. package/dist/review-loop.d.ts +7 -0
  43. package/dist/review-loop.js +622 -0
  44. package/dist/save-counts.d.ts +2 -0
  45. package/dist/save-counts.js +191 -0
  46. package/dist/summarize-logs.d.ts +2 -0
  47. package/dist/summarize-logs.js +41 -0
  48. package/dist/sweep-github.d.ts +10 -0
  49. package/dist/sweep-github.js +453 -0
  50. package/dist/sweep-issues.d.ts +56 -0
  51. package/dist/sweep-issues.js +650 -0
  52. package/dist/sweep.d.ts +2 -0
  53. package/dist/sweep.js +301 -0
  54. package/dist/triage-question.d.ts +2 -0
  55. package/dist/triage-question.js +189 -0
  56. package/dist/validate-skills.d.ts +2 -0
  57. package/dist/validate-skills.js +48 -0
  58. package/dist/watch-live.d.ts +7 -0
  59. package/dist/watch-live.js +83 -0
  60. package/dist/watcher/config.d.ts +11 -0
  61. package/dist/watcher/config.js +265 -0
  62. package/dist/watcher/live-classifier.d.ts +52 -0
  63. package/dist/watcher/live-classifier.js +510 -0
  64. package/dist/watcher/safe-fs.d.ts +9 -0
  65. package/dist/watcher/safe-fs.js +159 -0
  66. package/dist/watcher/stream.d.ts +27 -0
  67. package/dist/watcher/stream.js +340 -0
  68. package/dist/watcher/summarizer.d.ts +19 -0
  69. package/dist/watcher/summarizer.js +121 -0
  70. package/dist/wave3/process.d.ts +14 -0
  71. package/dist/wave3/process.js +84 -0
  72. package/dist/wave4/process.d.ts +14 -0
  73. package/dist/wave4/process.js +128 -0
  74. package/dist/workflow/render.d.ts +1 -1
  75. package/dist/workflow/render.js +1 -1
  76. package/dist/workflow-auditor/audit.d.ts +27 -0
  77. package/dist/workflow-auditor/audit.js +583 -0
  78. package/dist/workflow-auditor/ledger-io.d.ts +5 -0
  79. package/dist/workflow-auditor/ledger-io.js +99 -0
  80. package/dist/workflow-auditor/skills-validator.d.ts +10 -0
  81. package/dist/workflow-auditor/skills-validator.js +533 -0
  82. package/dist/worktree-guard/evaluation.d.ts +19 -0
  83. package/dist/worktree-guard/evaluation.js +84 -0
  84. package/dist/worktree-guard/git.d.ts +3 -0
  85. package/dist/worktree-guard/git.js +61 -0
  86. package/package.json +32 -33
@@ -0,0 +1,191 @@
1
+ /**
2
+ * LAYER: Interface
3
+ * Contains: CLI entry point for bbc save-counts.
4
+ * Rules: Match save-counts.py help, output, exit codes, and ignored tmp_logs/<UTC>-<hash>/report.json.
5
+ * BigO: O(n^2) score:1
6
+ * keywords: [SaveCountsCli, HistoricalCapture, SafeReport]
7
+ * GOAL: Capture live, sleuth, or historical Watcher counts and save safely under /tmp_logs/.
8
+ */
9
+ import { randomBytes } from 'node:crypto';
10
+ import { EOL } from 'node:os';
11
+ import { captureLive } from "./watch-live.js";
12
+ import { aliasPattern, ConfigError, CONTAINER_RE, resolveSshExecutable, SSH_OPTIONS } from "./watcher/config.js";
13
+ import { liveOutput, PATTERNS, WINDOW_SECONDS, WINDOWS, BYTE_LIMIT } from "./watcher/live-classifier.js";
14
+ import { checkBaseDir, requireIgnoredPaths, resolveWorktreeRoot, saveCountsReport } from "./watcher/safe-fs.js";
15
+ import { runBoundedBatch } from "./watcher/stream.js";
16
+ import { CAP, noEvidence, numericFields, summarize } from "./watcher/summarizer.js";
17
+ export const saveCountsUsage = 'bbc save-counts [--no-save] {live|sleuth|historical} <ssh-alias> <exact-container>';
18
+ const DESTINATION = 'Watcher counts destination unavailable; nothing saved.';
19
+ const FAILED = 'Watcher counts capture failed; nothing saved.';
20
+ const INVALID = 'Watcher counts capture requires a valid SSH alias and exact container name or ID.';
21
+ const HELP = 'Usage: bbc save-counts {live|sleuth|historical} <ssh-alias> <exact-container>\n' +
22
+ ' bbc save-counts --no-save historical <ssh-alias> <exact-container>\n' +
23
+ 'Run from the caller Git worktree with the script path pointing to the installed skill.\n' +
24
+ 'Save counts and coverage to ignored tmp_logs/<UTC>-<hash>/report.json.\n' +
25
+ '--no-save prints the same historical result and writes nothing (explicit no-save requests).\n' +
26
+ 'Only authorized sleuth mode prints and saves the bundled redactor\u2019s detailed evidence.';
27
+ const DEADLINE_MS = 15_000;
28
+ const KILL_GRACE_MS = 2_000;
29
+ const WINDOW_ROW_RE = /^window=([1-4]) error=[0-9]{1,20} warn=[0-9]{1,20} info=[0-9]{1,20} debug=[0-9]{1,20} unclassified=[0-9]{1,20} frames=[0-9]{1,20} dropped_bytes=[0-9]{1,20} top=(.+)$/;
30
+ const HIT_RE = /^([A-Za-z_0-9]+):([0-9]{1,20})$/;
31
+ function writeOut(text) {
32
+ process.stdout.write(`${text.replaceAll('\n', EOL)}${EOL}`);
33
+ }
34
+ function writeOutRaw(text) {
35
+ process.stdout.write(text.replaceAll('\n', EOL));
36
+ }
37
+ function writeErr(text) {
38
+ process.stderr.write(`${text.replaceAll('\n', EOL)}${EOL}`);
39
+ }
40
+ function utcSessionId() {
41
+ const now = new Date();
42
+ const pad = (n) => String(n).padStart(2, '0');
43
+ const stamp = `${now.getUTCFullYear()}${pad(now.getUTCMonth() + 1)}${pad(now.getUTCDate())}` +
44
+ `T${pad(now.getUTCHours())}${pad(now.getUTCMinutes())}${pad(now.getUTCSeconds())}Z`;
45
+ return `${stamp}-${randomBytes(16).toString('hex')}`;
46
+ }
47
+ async function runHistorical(alias, container) {
48
+ const ssh = resolveSshExecutable();
49
+ if (ssh === null)
50
+ return null;
51
+ const captured = await runBoundedBatch(ssh, [...SSH_OPTIONS, alias, 'docker', 'logs', '-f', '--tail=1000', '--', container], DEADLINE_MS, KILL_GRACE_MS, CAP);
52
+ if (captured === null)
53
+ return null;
54
+ const { text: summary, status: consumer } = summarize(captured.data);
55
+ const producer = captured.producerStatus;
56
+ if (producer !== 0 && producer !== 124 && !(producer === 141 && consumer === 3)) {
57
+ return null;
58
+ }
59
+ const status = producer === 0 && consumer === 0 ? 'finished' : 'incomplete';
60
+ const lines = summary.trimEnd().split('\n');
61
+ const severity = lines[0] ?? '';
62
+ const category = lines[1] ?? '';
63
+ return {
64
+ output: `historical status=${status}\n${summary}`,
65
+ report: {
66
+ status,
67
+ counts: {
68
+ severity: numericFields(severity.split(' ').slice(1)),
69
+ category: numericFields(category.split(' ').slice(1)),
70
+ },
71
+ coverage: {
72
+ cap: consumer === 3,
73
+ partial: summary.trimEnd().endsWith('partial=yes'),
74
+ deadline: producer === 124,
75
+ },
76
+ evidence: noEvidence(),
77
+ },
78
+ };
79
+ }
80
+ async function runLive(sleuth, alias, container) {
81
+ const result = await captureLive(alias, container, sleuth);
82
+ if (result === null)
83
+ return null;
84
+ const { rows, evidence } = result;
85
+ if (rows.length !== WINDOWS || (evidence !== null) !== sleuth)
86
+ return null;
87
+ const patternNames = new Set(PATTERNS.map(([name]) => name));
88
+ const windows = [];
89
+ for (let i = 0; i < rows.length; i++) {
90
+ const row = rows[i];
91
+ const match = WINDOW_ROW_RE.exec(row);
92
+ if (match === null || Number.parseInt(match[1], 10) !== i + 1)
93
+ return null;
94
+ const hitParts = match[2].split(',');
95
+ const top = {};
96
+ for (const part of hitParts) {
97
+ const hm = HIT_RE.exec(part);
98
+ if (hm === null)
99
+ return null;
100
+ top[hm[1]] = Number.parseInt(hm[2], 10);
101
+ }
102
+ if (hitParts.length !== patternNames.size || Object.keys(top).length !== patternNames.size)
103
+ return null;
104
+ if (!Object.keys(top).every((k) => patternNames.has(k)))
105
+ return null;
106
+ const win = numericFields(row.split(' ').slice(0, -1));
107
+ win.top = top;
108
+ windows.push(win);
109
+ }
110
+ const droppedBytes = windows.reduce((sum, win) => sum + (typeof win.dropped_bytes === 'number' ? win.dropped_bytes : 0), 0);
111
+ return {
112
+ output: `${liveOutput(rows, evidence).join('\n')}\n`,
113
+ report: {
114
+ status: 'deadline',
115
+ counts: { windows },
116
+ coverage: {
117
+ window_seconds: WINDOW_SECONDS,
118
+ byte_limit_per_window: BYTE_LIMIT,
119
+ dropped_bytes: droppedBytes,
120
+ },
121
+ evidence: sleuth && evidence !== null ? evidence : noEvidence(),
122
+ },
123
+ };
124
+ }
125
+ export async function saveCounts(argv) {
126
+ if (argv.length === 1 && argv[0] === '--help') {
127
+ writeOut(HELP);
128
+ return 0;
129
+ }
130
+ let aliasOk;
131
+ try {
132
+ aliasOk = aliasPattern();
133
+ }
134
+ catch (error) {
135
+ if (error instanceof ConfigError) {
136
+ writeErr(error.message);
137
+ return 1;
138
+ }
139
+ throw error;
140
+ }
141
+ let args = [...argv];
142
+ const noSave = args[0] === '--no-save';
143
+ if (noSave)
144
+ args = args.slice(1);
145
+ if (args.length !== 3 ||
146
+ (args[0] !== 'live' && args[0] !== 'sleuth' && args[0] !== 'historical') ||
147
+ (noSave && args[0] !== 'historical') ||
148
+ !aliasOk.test(args[1]) ||
149
+ !CONTAINER_RE.test(args[2])) {
150
+ writeErr(INVALID);
151
+ return 1;
152
+ }
153
+ const [mode, alias, container] = [args[0], args[1], args[2]];
154
+ if (noSave) {
155
+ const result = await runHistorical(alias, container);
156
+ if (result === null) {
157
+ writeErr(FAILED.replace('; nothing saved.', '.'));
158
+ return 1;
159
+ }
160
+ writeOutRaw(result.output);
161
+ return 0;
162
+ }
163
+ let root;
164
+ let session;
165
+ try {
166
+ root = resolveWorktreeRoot();
167
+ session = utcSessionId();
168
+ checkBaseDir(root);
169
+ requireIgnoredPaths(root, ['tmp_logs/', `tmp_logs/${session}/`, `tmp_logs/${session}/report.json`]);
170
+ }
171
+ catch {
172
+ writeErr(DESTINATION);
173
+ return 1;
174
+ }
175
+ const result = mode === 'historical'
176
+ ? await runHistorical(alias, container)
177
+ : await runLive(mode === 'sleuth', alias, container);
178
+ if (result === null) {
179
+ writeErr(FAILED);
180
+ return 1;
181
+ }
182
+ try {
183
+ saveCountsReport(root, session, { ...result.report, mode, source: { container } });
184
+ }
185
+ catch {
186
+ writeErr(DESTINATION);
187
+ return 1;
188
+ }
189
+ writeOutRaw(result.output);
190
+ return 0;
191
+ }
@@ -0,0 +1,2 @@
1
+ export declare const summarizeLogsUsage = "bbc summarize-logs";
2
+ export declare function summarizeLogs(argv: readonly string[]): Promise<number>;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * LAYER: Interface
3
+ * Contains: CLI entry point for bbc summarize-logs.
4
+ * Rules: Read at most 32 KiB from stdin and match summarize-logs.py output/exit status byte-for-byte.
5
+ * BigO: O(n) score:3
6
+ * keywords: [SummarizeLogsCli, BoundedStdin]
7
+ * GOAL: Compute bounded severity and category counts from stdin.
8
+ */
9
+ import { EOL } from 'node:os';
10
+ import { CAP, summarize } from "./watcher/summarizer.js";
11
+ export const summarizeLogsUsage = 'bbc summarize-logs';
12
+ async function readStdinCapped() {
13
+ const chunks = [];
14
+ let size = 0;
15
+ for await (const raw of process.stdin) {
16
+ const chunk = Buffer.isBuffer(raw) ? raw : Buffer.from(String(raw));
17
+ const take = Math.min(chunk.length, CAP - size);
18
+ if (take > 0) {
19
+ chunks.push(chunk.subarray(0, take));
20
+ size += take;
21
+ }
22
+ if (size >= CAP) {
23
+ process.stdin.destroy();
24
+ break;
25
+ }
26
+ }
27
+ return Buffer.concat(chunks);
28
+ }
29
+ export async function summarizeLogs(argv) {
30
+ if (argv.length > 0)
31
+ return 1;
32
+ try {
33
+ const input = await readStdinCapped();
34
+ const { text, status } = summarize(input);
35
+ process.stdout.write(text.replaceAll('\n', EOL));
36
+ return status;
37
+ }
38
+ catch {
39
+ return 1;
40
+ }
41
+ }
@@ -0,0 +1,10 @@
1
+ export declare const sweepGithubUsage = "bbc sweep-github <fetch|apply> --repo <owner/repo> [--out <snapshot.json> | --plan <plan.json>] [--only 12,15] [--dry-run]";
2
+ export declare class SweepGithubUnusableError extends Error {
3
+ }
4
+ export declare function toSnapshot(pages: readonly Record<string, unknown>[], fetchedAt: string, sweeperLogin?: string): Record<string, unknown>;
5
+ export declare function issueCommands(plan: Record<string, unknown>, repo: string): Array<readonly [number | string, string[]]>;
6
+ export declare function reportCommand(plan: Record<string, unknown>, repo: string): string[];
7
+ export declare function sweepFetch(repo: string, outPath: string, sweeperLogin: string): Record<string, unknown>;
8
+ export declare function sweepApply(repo: string, planPath: string, dryRun: boolean, only?: Set<number> | null): readonly [Record<string, unknown>, number];
9
+ export declare function parseOnly(value: string): Set<number>;
10
+ export declare function sweepGithub(argv: readonly string[]): number;