@bbcsoftwarefactory/cli 0.1.0 → 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 (126) 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.d.ts +2 -0
  6. package/dist/bbc.js +124 -0
  7. package/dist/bigo/complexity.d.ts +18 -0
  8. package/dist/bigo/complexity.js +139 -0
  9. package/dist/bigo/functions.d.ts +5 -0
  10. package/dist/bigo/functions.js +174 -0
  11. package/dist/bigo/keywords.d.ts +1 -0
  12. package/dist/bigo/keywords.js +43 -0
  13. package/dist/bigo/lexical.d.ts +14 -0
  14. package/dist/bigo/lexical.js +69 -0
  15. package/dist/bigo/source-files.d.ts +1 -0
  16. package/dist/bigo/source-files.js +80 -0
  17. package/dist/change-lane/classification.d.ts +41 -0
  18. package/dist/change-lane/classification.js +104 -0
  19. package/dist/change-lane/git.d.ts +8 -0
  20. package/dist/change-lane/git.js +105 -0
  21. package/dist/check-issue-claim.d.ts +2 -0
  22. package/dist/check-issue-claim.js +146 -0
  23. package/dist/check-worktree-guard.d.ts +2 -0
  24. package/dist/check-worktree-guard.js +114 -0
  25. package/dist/classify-change-lane.d.ts +2 -0
  26. package/dist/classify-change-lane.js +128 -0
  27. package/dist/diff-scope/git-diff.d.ts +25 -0
  28. package/dist/diff-scope/git-diff.js +146 -0
  29. package/dist/error-scan.d.ts +3 -0
  30. package/dist/error-scan.js +216 -0
  31. package/dist/export-public.d.ts +9 -0
  32. package/dist/export-public.js +274 -0
  33. package/dist/extract-diff-scope.d.ts +2 -0
  34. package/dist/extract-diff-scope.js +111 -0
  35. package/dist/fetch-issue-attachments.d.ts +22 -0
  36. package/dist/fetch-issue-attachments.js +325 -0
  37. package/dist/issue-claim/evaluation.d.ts +66 -0
  38. package/dist/issue-claim/evaluation.js +259 -0
  39. package/dist/issue-claim/loaders.d.ts +5 -0
  40. package/dist/issue-claim/loaders.js +116 -0
  41. package/dist/list-zed-commands.d.ts +7 -0
  42. package/dist/list-zed-commands.js +288 -0
  43. package/dist/measure-bigo.d.ts +2 -0
  44. package/dist/measure-bigo.js +84 -0
  45. package/dist/plan-issue-triage.d.ts +3 -0
  46. package/dist/plan-issue-triage.js +404 -0
  47. package/dist/question-gate/ledger.d.ts +5 -0
  48. package/dist/question-gate/ledger.js +115 -0
  49. package/dist/question-gate/rules.d.ts +40 -0
  50. package/dist/question-gate/rules.js +483 -0
  51. package/dist/recap/board.d.ts +5 -0
  52. package/dist/recap/board.js +384 -0
  53. package/dist/recap/git-and-github.d.ts +11 -0
  54. package/dist/recap/git-and-github.js +620 -0
  55. package/dist/recap/report-and-hud.d.ts +2 -0
  56. package/dist/recap/report-and-hud.js +294 -0
  57. package/dist/recap/time-and-refs.d.ts +27 -0
  58. package/dist/recap/time-and-refs.js +148 -0
  59. package/dist/recap.d.ts +2 -0
  60. package/dist/recap.js +217 -0
  61. package/dist/render-workflow.d.ts +2 -0
  62. package/dist/render-workflow.js +142 -0
  63. package/dist/resolve-containers.d.ts +2 -0
  64. package/dist/resolve-containers.js +96 -0
  65. package/dist/review-loop.d.ts +7 -0
  66. package/dist/review-loop.js +622 -0
  67. package/dist/save-counts.d.ts +2 -0
  68. package/dist/save-counts.js +191 -0
  69. package/dist/summarize-logs.d.ts +2 -0
  70. package/dist/summarize-logs.js +41 -0
  71. package/dist/sweep-github.d.ts +10 -0
  72. package/dist/sweep-github.js +453 -0
  73. package/dist/sweep-issues.d.ts +56 -0
  74. package/dist/sweep-issues.js +650 -0
  75. package/dist/sweep.d.ts +2 -0
  76. package/dist/sweep.js +301 -0
  77. package/dist/triage-question.d.ts +2 -0
  78. package/dist/triage-question.js +189 -0
  79. package/dist/validate-skills.d.ts +2 -0
  80. package/dist/validate-skills.js +48 -0
  81. package/dist/watch-live.d.ts +7 -0
  82. package/dist/watch-live.js +83 -0
  83. package/dist/watcher/config.d.ts +11 -0
  84. package/dist/watcher/config.js +265 -0
  85. package/dist/watcher/live-classifier.d.ts +52 -0
  86. package/dist/watcher/live-classifier.js +510 -0
  87. package/dist/watcher/safe-fs.d.ts +9 -0
  88. package/dist/watcher/safe-fs.js +159 -0
  89. package/dist/watcher/stream.d.ts +27 -0
  90. package/dist/watcher/stream.js +340 -0
  91. package/dist/watcher/summarizer.d.ts +19 -0
  92. package/dist/watcher/summarizer.js +121 -0
  93. package/dist/wave3/process.d.ts +14 -0
  94. package/dist/wave3/process.js +84 -0
  95. package/dist/wave4/process.d.ts +14 -0
  96. package/dist/wave4/process.js +128 -0
  97. package/dist/workflow/render.d.ts +13 -0
  98. package/dist/workflow/render.js +31 -0
  99. package/dist/workflow/schema.d.ts +25 -0
  100. package/dist/workflow/schema.js +99 -0
  101. package/dist/workflow-auditor/audit.d.ts +27 -0
  102. package/dist/workflow-auditor/audit.js +583 -0
  103. package/dist/workflow-auditor/ledger-io.d.ts +5 -0
  104. package/dist/workflow-auditor/ledger-io.js +99 -0
  105. package/dist/workflow-auditor/skills-validator.d.ts +10 -0
  106. package/dist/workflow-auditor/skills-validator.js +533 -0
  107. package/dist/worktree-guard/evaluation.d.ts +19 -0
  108. package/dist/worktree-guard/evaluation.js +84 -0
  109. package/dist/worktree-guard/git.d.ts +3 -0
  110. package/dist/worktree-guard/git.js +61 -0
  111. package/package.json +32 -33
  112. package/src/bbc.ts +0 -39
  113. package/src/bigo/complexity.ts +0 -138
  114. package/src/bigo/functions.ts +0 -183
  115. package/src/bigo/keywords.ts +0 -41
  116. package/src/bigo/lexical.ts +0 -68
  117. package/src/bigo/source-files.ts +0 -80
  118. package/src/change-lane/classification.ts +0 -128
  119. package/src/change-lane/git.ts +0 -110
  120. package/src/classify-change-lane.ts +0 -140
  121. package/src/diff-scope/git-diff.ts +0 -161
  122. package/src/extract-diff-scope.ts +0 -130
  123. package/src/measure-bigo.ts +0 -86
  124. package/src/render-workflow.ts +0 -144
  125. package/src/workflow/render.ts +0 -40
  126. package/src/workflow/schema.ts +0 -141
package/dist/recap.js ADDED
@@ -0,0 +1,217 @@
1
+ /**
2
+ * LAYER: Interface
3
+ * Contains: CLI entry point for /recap daily progress summary and optional board sync.
4
+ * Rules: Read-only by default; board writes require --sync-board and valid --project.
5
+ * BigO: O(n) score:4
6
+ * keywords: [RecapCli, DailySummary, BoardSyncCli]
7
+ * GOAL: Parse recap CLI flags, coordinate collectors, and emit JSON or bilingual HUD output.
8
+ */
9
+ import { readFileSync } from 'node:fs';
10
+ import { resolve } from 'node:path';
11
+ import { applyBoardSync, planBoardSync } from "./recap/board.js";
12
+ import { collectGithub, collectLocalGit, collectProjectBoard, collectTeamMembers, collectTeamRecaps } from "./recap/git-and-github.js";
13
+ import { computeRecap, formatHud } from "./recap/report-and-hud.js";
14
+ import { parseProjectRef, parseSince, REPO_RE } from "./recap/time-and-refs.js";
15
+ export const recapUsage = 'bbc recap [--repo <owner/repo>|--all-repos] [--since <YYYY-MM-DD|Nh|Nd>] [--user <login>] [--team|--users <a,b>] [--project <url|owner/n>] [--sync-board [--fix-colors] [--apply-labels] [--dry-run]] [--cwd <dir>] [--lang es|en] [--no-github] [--json] [--stdin]';
16
+ const HELP = 'Usage: bbc recap [options]\n' +
17
+ 'Generate a daily progress summary from local Git, GitHub REST, and Project v2 boards.\n' +
18
+ ' --repo <owner/repo> Target GitHub repository\n' +
19
+ ' --all-repos Include all repositories for the GitHub user\n' +
20
+ ' --since <val> YYYY-MM-DD, <N>h, <N>d, or ISO-8601 (default: local midnight today)\n' +
21
+ ' --user <login> GitHub login override\n' +
22
+ ' --team Collect summary across organization members\n' +
23
+ ' --users <a,b> Comma-separated GitHub logins for team summary\n' +
24
+ ' --project <url|owner/n> GitHub Project v2 URL or <owner>/<number>\n' +
25
+ ' --sync-board Add missing items and move closed/merged items on --project\n' +
26
+ ' --fix-colors Normalize Status/field colors and board view fields\n' +
27
+ ' --apply-labels Add matching existing repo labels to added items\n' +
28
+ ' --dry-run Preview planned board changes without writing\n' +
29
+ ' --git-author <pattern> Git author filter\n' +
30
+ ' --cwd <dir> Working directory of the target Git repository\n' +
31
+ ' --lang es|en HUD output language (default: es)\n' +
32
+ ' --no-github Skip GitHub API queries and collect local Git only\n' +
33
+ ' --json Print structured JSON report instead of HUD\n' +
34
+ ' --stdin Read synthetic recap payload JSON from stdin';
35
+ function parseArgs(argv) {
36
+ const boolFlags = new Set([
37
+ '--all-repos',
38
+ '--team',
39
+ '--sync-board',
40
+ '--fix-colors',
41
+ '--apply-labels',
42
+ '--dry-run',
43
+ '--no-github',
44
+ '--json',
45
+ '--stdin',
46
+ ]);
47
+ const valueFlags = new Set(['--repo', '--since', '--user', '--users', '--project', '--git-author', '--cwd', '--lang']);
48
+ const values = { lang: 'es' };
49
+ const flags = new Set();
50
+ const queue = [...argv];
51
+ while (queue.length > 0) {
52
+ const arg = queue.shift();
53
+ if (arg === '-h' || arg === '--help') {
54
+ return {
55
+ help: true,
56
+ allRepos: false,
57
+ team: false,
58
+ syncBoard: false,
59
+ fixColors: false,
60
+ applyLabels: false,
61
+ dryRun: false,
62
+ lang: 'es',
63
+ noGithub: false,
64
+ json: false,
65
+ stdin: false,
66
+ };
67
+ }
68
+ if (boolFlags.has(arg)) {
69
+ flags.add(arg);
70
+ continue;
71
+ }
72
+ if (valueFlags.has(arg) && queue.length > 0) {
73
+ values[arg.slice(2)] = queue.shift();
74
+ continue;
75
+ }
76
+ return { error: `Unknown or incomplete argument: ${arg}` };
77
+ }
78
+ if (values.lang !== 'es' && values.lang !== 'en') {
79
+ return { error: `Invalid --lang ${JSON.stringify(values.lang)}; expected es or en.` };
80
+ }
81
+ return {
82
+ repo: values.repo,
83
+ allRepos: flags.has('--all-repos'),
84
+ since: values.since,
85
+ user: values.user,
86
+ team: flags.has('--team'),
87
+ users: values.users,
88
+ project: values.project,
89
+ syncBoard: flags.has('--sync-board'),
90
+ fixColors: flags.has('--fix-colors'),
91
+ applyLabels: flags.has('--apply-labels'),
92
+ dryRun: flags.has('--dry-run'),
93
+ gitAuthor: values['git-author'],
94
+ cwd: values.cwd,
95
+ lang: values.lang,
96
+ noGithub: flags.has('--no-github'),
97
+ json: flags.has('--json'),
98
+ stdin: flags.has('--stdin'),
99
+ };
100
+ }
101
+ export function recap(argv) {
102
+ const parsed = parseArgs(argv);
103
+ if ('error' in parsed) {
104
+ process.stdout.write(`${JSON.stringify({ error: parsed.error })}\n`);
105
+ return 2;
106
+ }
107
+ if (parsed.help) {
108
+ process.stdout.write(`${HELP}\n`);
109
+ return 0;
110
+ }
111
+ if (parsed.repo && !REPO_RE.test(parsed.repo)) {
112
+ process.stdout.write(`${JSON.stringify({ error: `Invalid --repo ${JSON.stringify(parsed.repo)}; expected owner/repo.` })}\n`);
113
+ return 2;
114
+ }
115
+ let sinceDt;
116
+ try {
117
+ sinceDt = parseSince(parsed.since);
118
+ }
119
+ catch (error) {
120
+ process.stdout.write(`${JSON.stringify({ error: error instanceof Error ? error.message : String(error) })}\n`);
121
+ return 2;
122
+ }
123
+ let projectRef = null;
124
+ try {
125
+ projectRef = parsed.project ? parseProjectRef(parsed.project) : null;
126
+ }
127
+ catch (error) {
128
+ process.stdout.write(`${JSON.stringify({ error: error instanceof Error ? error.message : String(error) })}\n`);
129
+ return 2;
130
+ }
131
+ if (parsed.syncBoard && !projectRef && !parsed.stdin) {
132
+ process.stdout.write(`${JSON.stringify({ error: '--sync-board requires --project <url|owner/number>.' })}\n`);
133
+ return 2;
134
+ }
135
+ let report;
136
+ if (parsed.stdin) {
137
+ let payload;
138
+ try {
139
+ payload = JSON.parse(readFileSync(0, 'utf8'));
140
+ }
141
+ catch (error) {
142
+ process.stdout.write(`${JSON.stringify({ error: `Invalid JSON on stdin: ${error instanceof Error ? error.message : String(error)}` })}\n`);
143
+ return 2;
144
+ }
145
+ if (parsed.since && !('since' in payload)) {
146
+ payload.since = sinceDt.iso;
147
+ }
148
+ report = computeRecap(payload);
149
+ }
150
+ else {
151
+ const cwd = parsed.cwd ? resolve(parsed.cwd) : process.cwd();
152
+ const local = collectLocalGit(cwd, sinceDt, parsed.gitAuthor);
153
+ const targetRepo = parsed.repo ?? (typeof local.repo === 'string' ? local.repo : null);
154
+ let gh;
155
+ let projectData = null;
156
+ let teamReports = null;
157
+ let teamActivity = [];
158
+ if (parsed.noGithub) {
159
+ gh = { available: false, gap: 'GitHub skipped (--no-github)' };
160
+ projectData = projectRef ? { available: false, gap: 'GitHub skipped (--no-github)' } : null;
161
+ }
162
+ else {
163
+ gh = collectGithub(targetRepo, parsed.allRepos, sinceDt, parsed.user);
164
+ projectData = projectRef ? collectProjectBoard(projectRef) : null;
165
+ if (parsed.team || parsed.users) {
166
+ const orgName = projectRef?.owner ?? (targetRepo && targetRepo.includes('/') ? (targetRepo.split('/', 1)[0] ?? null) : null);
167
+ const members = collectTeamMembers(orgName, parsed.users);
168
+ if (members.length > 0) {
169
+ [teamReports, teamActivity] = collectTeamRecaps(members, targetRepo, parsed.allRepos, sinceDt, gh);
170
+ }
171
+ else {
172
+ teamReports = [];
173
+ }
174
+ }
175
+ }
176
+ const payload = {
177
+ user: gh.user ?? parsed.user ?? local.author ?? null,
178
+ repo: parsed.allRepos ? 'all-repos' : targetRepo,
179
+ since: sinceDt.iso,
180
+ github_available: Boolean(gh.available),
181
+ github_gap: gh.gap ?? null,
182
+ issues_created: gh.issues_created ?? [],
183
+ issues_closed: gh.issues_closed ?? [],
184
+ prs_opened: gh.prs_opened ?? [],
185
+ prs_merged: gh.prs_merged ?? [],
186
+ prs_in_progress: gh.prs_in_progress ?? [],
187
+ reviews_and_comments: gh.reviews_and_comments ?? 0,
188
+ gaps: gh.gaps ?? [],
189
+ local_git: local,
190
+ };
191
+ if (teamReports !== null) {
192
+ payload.team = teamReports;
193
+ }
194
+ if (projectData !== null) {
195
+ payload.project = projectData;
196
+ if (teamActivity.length > 0) {
197
+ payload.project_activity_items = teamActivity;
198
+ }
199
+ }
200
+ report = computeRecap(payload);
201
+ if (parsed.syncBoard && projectData && projectData.available) {
202
+ const syncPlan = planBoardSync(report.project, projectData, parsed.fixColors);
203
+ const syncRes = applyBoardSync(syncPlan, parsed.dryRun, parsed.applyLabels);
204
+ report.board_sync = syncRes;
205
+ if (Array.isArray(syncRes.errors) && syncRes.errors.length > 0) {
206
+ report.gaps.push(...syncRes.errors);
207
+ }
208
+ }
209
+ }
210
+ if (parsed.json) {
211
+ process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
212
+ }
213
+ else {
214
+ process.stdout.write(`${formatHud(report, parsed.lang)}\n`);
215
+ }
216
+ return 0;
217
+ }
@@ -0,0 +1,2 @@
1
+ export declare const renderWorkflowUsage = "bbc render-workflow [--check | --write] [repo-root]";
2
+ export declare function renderWorkflow(args: readonly string[]): number;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * LAYER: Interface
3
+ * Contains: render-workflow command.
4
+ * Rules: Check by default; write only between the workflow markers, atomically.
5
+ * BigO: O(n^2) score:1
6
+ * keywords: [RenderWorkflowCommand, ReadmeMarkers]
7
+ * GOAL: Keep the README workflow block identical to the workflow source.
8
+ */
9
+ import { lstatSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
10
+ import { dirname, join } from 'node:path';
11
+ import { EOL } from 'node:os';
12
+ import { randomUUID } from 'node:crypto';
13
+ import { fileURLToPath } from 'node:url';
14
+ import { JsonError, parseJsonText } from '@bbcsoftwarefactory/cli-core/python-json';
15
+ import { pythonJoin, pythonPath, pythonRepr, universalNewlines } from '@bbcsoftwarefactory/cli-core/python-compat';
16
+ import { generatedSection, workflowBegin, workflowEnd } from "./workflow/render.js";
17
+ import { validateWorkflow, WorkflowError } from "./workflow/schema.js";
18
+ export const renderWorkflowUsage = 'bbc render-workflow [--check | --write] [repo-root]';
19
+ const sourceName = pythonPath('docs/diagrams/workflow.json');
20
+ const readmeName = 'README.md';
21
+ const agentsName = 'AGENTS.md';
22
+ // The package sits at packages/cli/src, so the repository root is three levels up.
23
+ const defaultRoot = pythonPath(fileURLToPath(new URL('../../../', import.meta.url)));
24
+ const helpText = `bbc render-workflow: generate the README workflow Mermaid block from one source.
25
+
26
+ Usage:
27
+ bbc render-workflow [--check | --write] [repo-root]
28
+
29
+ docs/diagrams/workflow.json is the single source of the workflow stages and edges
30
+ (ADR 0002). --check (the default, used by CI) only reads: it fails when the README
31
+ block between the workflow markers differs from what the JSON generates, when the
32
+ JSON is invalid, or when a stage's \`agents\` phrase is missing from the AGENTS.md
33
+ handoff block. --write replaces only the text between the two markers, atomically.
34
+ `;
35
+ const usageText = 'Usage:\n bbc render-workflow [--check | --write] [repo-root]';
36
+ const native = (text) => text.replaceAll('\n', EOL);
37
+ const flagsAllowed = ['--check', '--write', '--help'];
38
+ const handoffBlock = /## Skill handoffs\s+```text\n([\s\S]*?)```/;
39
+ function readText(path) {
40
+ let regular = false;
41
+ try {
42
+ const stat = lstatSync(path);
43
+ regular = stat.isFile() && !stat.isSymbolicLink();
44
+ }
45
+ catch {
46
+ regular = false;
47
+ }
48
+ if (!regular)
49
+ throw new WorkflowError(`${path}: must be a regular file, not a symlink`);
50
+ return universalNewlines(readFileSync(path, 'utf8'));
51
+ }
52
+ function sectionBounds(readme) {
53
+ const begin = readme.split(workflowBegin).length - 1;
54
+ const end = readme.split(workflowEnd).length - 1;
55
+ if (begin !== 1 || end !== 1)
56
+ throw new WorkflowError(`${readmeName}: needs exactly one pair of workflow markers`);
57
+ const start = readme.indexOf(workflowBegin);
58
+ const stop = readme.indexOf(workflowEnd) + workflowEnd.length;
59
+ if (start >= stop)
60
+ throw new WorkflowError(`${readmeName}: workflow markers are out of order`);
61
+ return [start, stop];
62
+ }
63
+ function load(sourcePath) {
64
+ const body = readText(sourcePath);
65
+ try {
66
+ return validateWorkflow(parseJsonText(body));
67
+ }
68
+ catch (error) {
69
+ if (error instanceof JsonError)
70
+ throw new WorkflowError(`${sourcePath}: invalid JSON (${error.message})`);
71
+ throw error;
72
+ }
73
+ }
74
+ function checkAgents(root, document) {
75
+ const block = handoffBlock.exec(readText(pythonJoin(root, agentsName)));
76
+ if (block === null)
77
+ throw new WorkflowError(`${agentsName}: handoff block not found`);
78
+ const words = block[1] ?? '';
79
+ const missing = Object.entries(document.nodes)
80
+ .filter(([, node]) => !words.includes(node.agents))
81
+ .map(([id, node]) => `${id} (${pythonRepr(node.agents)})`);
82
+ if (missing.length > 0) {
83
+ throw new WorkflowError(`${agentsName}: handoff block lacks the agents phrase of ${missing.join(', ')}`);
84
+ }
85
+ }
86
+ function writeAtomic(path, body) {
87
+ const temporary = join(dirname(path), `.README.${randomUUID().slice(0, 8)}.tmp`);
88
+ try {
89
+ writeFileSync(temporary, body, { encoding: 'utf8', flag: 'wx' });
90
+ renameSync(temporary, path);
91
+ }
92
+ catch (error) {
93
+ try {
94
+ unlinkSync(temporary);
95
+ }
96
+ catch {
97
+ // The temporary file was never created; nothing to remove.
98
+ }
99
+ throw error;
100
+ }
101
+ }
102
+ function run(root, write) {
103
+ const sourcePath = pythonJoin(root, sourceName);
104
+ const document = load(sourcePath);
105
+ checkAgents(root, document);
106
+ const readmePath = pythonJoin(root, readmeName);
107
+ const readme = readText(readmePath);
108
+ const [start, stop] = sectionBounds(readme);
109
+ const expected = generatedSection(document);
110
+ if (readme.slice(start, stop) === expected)
111
+ return 'up to date';
112
+ if (!write) {
113
+ throw new WorkflowError(`${readmeName}: workflow block differs from ${sourceName}; run bbc render-workflow --write`);
114
+ }
115
+ writeAtomic(readmePath, readme.slice(0, start) + expected + readme.slice(stop));
116
+ return 'written';
117
+ }
118
+ export function renderWorkflow(args) {
119
+ const flags = args.filter((argument) => argument.startsWith('--'));
120
+ const paths = args.filter((argument) => !argument.startsWith('--'));
121
+ const unknown = flags.some((flag) => !flagsAllowed.includes(flag));
122
+ const conflicting = flags.includes('--check') && flags.includes('--write');
123
+ if (unknown || conflicting || paths.length > 1) {
124
+ process.stderr.write(native(`${usageText}\n`));
125
+ return 2;
126
+ }
127
+ if (flags.includes('--help')) {
128
+ process.stdout.write(native(`${helpText}\n`));
129
+ return 0;
130
+ }
131
+ const root = paths[0] ?? defaultRoot;
132
+ try {
133
+ process.stdout.write(native(`workflow: ${run(root, flags.includes('--write'))}\n`));
134
+ }
135
+ catch (error) {
136
+ if (!(error instanceof WorkflowError))
137
+ throw error;
138
+ process.stderr.write(native(`workflow: ${error.message}\n`));
139
+ return 1;
140
+ }
141
+ return 0;
142
+ }
@@ -0,0 +1,2 @@
1
+ export declare const resolveContainersUsage = "bbc resolve-containers <ssh-alias> <container|literal-prefix*>";
2
+ export declare function resolveContainers(argv: readonly string[]): Promise<number>;
@@ -0,0 +1,96 @@
1
+ /**
2
+ * LAYER: Interface
3
+ * Contains: CLI entry point for bbc resolve-containers.
4
+ * Rules: Match resolve-containers.py stdout, stderr, and exit codes byte-for-byte.
5
+ * BigO: O(n^2) score:1
6
+ * keywords: [ResolveContainersCli, PrefixDiscovery]
7
+ * GOAL: Validate SSH alias and selector, resolving prefix* via names-only docker ps.
8
+ */
9
+ import { EOL } from 'node:os';
10
+ import { aliasPattern, ConfigError, CONTAINER_RE, resolveSshExecutable, SSH_OPTIONS, } from "./watcher/config.js";
11
+ import { runBoundedCutoff } from "./watcher/stream.js";
12
+ export const resolveContainersUsage = 'bbc resolve-containers <ssh-alias> <container|literal-prefix*>';
13
+ const INVALID = 'Watcher requires a valid SSH alias and container name, ID, or literal prefix followed by *.';
14
+ const FAILED = 'Watcher container discovery failed; no snapshot.';
15
+ const DEADLINE_MS = 15_000;
16
+ const KILL_GRACE_MS = 2_000;
17
+ const CUTOFF_BYTES = 8_192;
18
+ const MAX_NAMES = 16;
19
+ function writeErr(text) {
20
+ process.stderr.write(`${text.replaceAll('\n', EOL)}${EOL}`);
21
+ }
22
+ function remoteCommand(prefix) {
23
+ const escaped = prefix.replaceAll('.', '\\.');
24
+ return `docker ps --filter 'name=^/?${escaped}.*$' --format '{{.Names}}'`;
25
+ }
26
+ function parseOutput(output, prefix) {
27
+ if (output.length > 0 && output.at(-1) !== 0x0a)
28
+ return null;
29
+ if (output.length === 0)
30
+ return [];
31
+ const names = [];
32
+ const rawLines = output.subarray(0, -1).toString('latin1').split('\n');
33
+ for (const raw of rawLines) {
34
+ for (let i = 0; i < raw.length; i++) {
35
+ if (raw.charCodeAt(i) > 0x7f)
36
+ return null;
37
+ }
38
+ if (!CONTAINER_RE.test(raw) || !raw.startsWith(prefix))
39
+ return null;
40
+ if (!names.includes(raw))
41
+ names.push(raw);
42
+ }
43
+ if (names.length > MAX_NAMES)
44
+ return null;
45
+ return names;
46
+ }
47
+ export async function resolveContainers(argv) {
48
+ if (argv.length !== 2) {
49
+ writeErr(INVALID);
50
+ return 1;
51
+ }
52
+ const [alias, selector] = [argv[0], argv[1]];
53
+ let pattern;
54
+ try {
55
+ pattern = aliasPattern();
56
+ }
57
+ catch (error) {
58
+ if (error instanceof ConfigError) {
59
+ writeErr(error.message);
60
+ return 1;
61
+ }
62
+ throw error;
63
+ }
64
+ if (!pattern.test(alias)) {
65
+ writeErr(INVALID);
66
+ return 1;
67
+ }
68
+ if (CONTAINER_RE.test(selector)) {
69
+ process.stdout.write(`${selector}${EOL}`);
70
+ return 0;
71
+ }
72
+ if (!selector.endsWith('*') || !CONTAINER_RE.test(selector.slice(0, -1))) {
73
+ writeErr(INVALID);
74
+ return 1;
75
+ }
76
+ const prefix = selector.slice(0, -1);
77
+ const ssh = resolveSshExecutable();
78
+ if (ssh === null) {
79
+ writeErr(FAILED);
80
+ return 1;
81
+ }
82
+ const res = await runBoundedCutoff(ssh, [...SSH_OPTIONS, alias, remoteCommand(prefix)], DEADLINE_MS, KILL_GRACE_MS, CUTOFF_BYTES);
83
+ if (!res.ok) {
84
+ writeErr(FAILED);
85
+ return 1;
86
+ }
87
+ const names = parseOutput(res.data, prefix);
88
+ if (names === null) {
89
+ writeErr(FAILED);
90
+ return 1;
91
+ }
92
+ if (names.length > 0) {
93
+ process.stdout.write(names.map((name) => `${name}${EOL}`).join(''));
94
+ }
95
+ return 0;
96
+ }
@@ -0,0 +1,7 @@
1
+ export declare const reviewLoopUsage = "bbc review-loop run --repo <owner/repo> --pr <n> [--max-rounds 3] [--timeout 600] [--dry-run]";
2
+ export declare function commentableLines(patch: string): Set<number>;
3
+ export declare function numberedPatch(patch: string): string;
4
+ export declare function parseJsonOutput(text: string): Record<string, unknown> | null;
5
+ export declare function computeScore(severities: readonly string[]): number;
6
+ export declare function cleanText(text: unknown, limit: number): string;
7
+ export declare function reviewLoop(argv: readonly string[]): number;