@bbcsoftwarefactory/cli 0.1.1 → 1.1.3

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 (155) 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 +1278 -0
  5. package/dist/bbc.js +87 -3
  6. package/dist/bundle/commands/daily/SKILL.md +112 -0
  7. package/dist/bundle/commands/daily/adapters/command.md +17 -0
  8. package/dist/bundle/commands/daily/adapters/gemini.toml +17 -0
  9. package/dist/bundle/commands/issue-clean-and-close/SKILL.md +85 -0
  10. package/dist/bundle/commands/issue-clean-and-close/adapters/command.md +17 -0
  11. package/dist/bundle/commands/issue-clean-and-close/adapters/gemini.toml +17 -0
  12. package/dist/bundle/commands/issue-clean-and-close/references/policy.md +87 -0
  13. package/dist/bundle/commands/recap/SKILL.md +84 -0
  14. package/dist/bundle/commands/recap/adapters/command.md +17 -0
  15. package/dist/bundle/commands/recap/adapters/gemini.toml +17 -0
  16. package/dist/bundle/installer/clients.json +103 -0
  17. package/dist/bundle/skills/code-quality-gate/SKILL.md +58 -0
  18. package/dist/bundle/skills/code-quality-gate/references/gate-bigo.md +31 -0
  19. package/dist/bundle/skills/code-quality-gate/references/gate-earlyreturn.md +73 -0
  20. package/dist/bundle/skills/code-quality-gate/references/gate-typesafe.md +32 -0
  21. package/dist/bundle/skills/code-quality-gate/references/output-schema.yml +40 -0
  22. package/dist/bundle/skills/delivery-coordinator/SKILL.md +80 -0
  23. package/dist/bundle/skills/delivery-coordinator/references/hud-output.md +55 -0
  24. package/dist/bundle/skills/delivery-coordinator/references/intake.md +86 -0
  25. package/dist/bundle/skills/delivery-coordinator/references/issue-claim.md +143 -0
  26. package/dist/bundle/skills/delivery-coordinator/references/issue-dedup.md +38 -0
  27. package/dist/bundle/skills/delivery-coordinator/references/sleuth-regression-exercise.md +60 -0
  28. package/dist/bundle/skills/delivery-coordinator/references/visual-reference.md +45 -0
  29. package/dist/bundle/skills/delivery-coordinator/references/worktree-isolation.md +19 -0
  30. package/dist/bundle/skills/documentation-steward/SKILL.md +43 -0
  31. package/dist/bundle/skills/documentation-steward/references/discovery.md +17 -0
  32. package/dist/bundle/skills/documentation-steward/references/handoff.md +15 -0
  33. package/dist/bundle/skills/greptile-review-loop/SKILL.md +56 -0
  34. package/dist/bundle/skills/greptile-review-loop/references/review-protocol.md +37 -0
  35. package/dist/bundle/skills/issue-reviewer/SKILL.md +84 -0
  36. package/dist/bundle/skills/issue-reviewer/references/review-format.md +100 -0
  37. package/dist/bundle/skills/issue-reviewer/references/triage.md +105 -0
  38. package/dist/bundle/skills/question-gate/SKILL.md +64 -0
  39. package/dist/bundle/skills/question-gate/references/client-hooks.md +111 -0
  40. package/dist/bundle/skills/question-gate/references/diagram-routing.md +58 -0
  41. package/dist/bundle/skills/question-gate/tests/fixtures/question-corpus.json +481 -0
  42. package/dist/bundle/skills/regression-testing/SKILL.md +49 -0
  43. package/dist/bundle/skills/regression-testing/references/evidence-record.md +35 -0
  44. package/dist/bundle/skills/requirements-spec/SKILL.md +59 -0
  45. package/dist/bundle/skills/risk-scout/SKILL.md +53 -0
  46. package/dist/bundle/skills/risk-scout/references/risk-matrix.md +49 -0
  47. package/dist/bundle/skills/skill-clean-architecture/SKILL.md +53 -0
  48. package/dist/bundle/skills/skill-clean-architecture/references/layer-rules.md +22 -0
  49. package/dist/bundle/skills/skill-clean-architecture/references/source-headers.md +30 -0
  50. package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/bad-utf8.js +1 -0
  51. package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/edge-crlf.ts +6 -0
  52. package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/edge-mixed.ts +15 -0
  53. package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/empty.js +0 -0
  54. package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo/no-newline.js +1 -0
  55. package/dist/bundle/skills/skill-clean-architecture/tests/fixtures/bigo.expected.yml +95 -0
  56. package/dist/bundle/skills/tool-depot/SKILL.md +47 -0
  57. package/dist/bundle/skills/tool-depot/references/checkout.md +29 -0
  58. package/dist/bundle/skills/tool-depot/references/loki-read.md +41 -0
  59. package/dist/bundle/skills/tool-depot/references/readonly-access.md +84 -0
  60. package/dist/bundle/skills/tool-depot/references/tool-catalog.json +47 -0
  61. package/dist/bundle/skills/tool-depot/scripts/loki-runtime-logs.py +305 -0
  62. package/dist/bundle/skills/tool-depot/tests/loki-runtime-logs.test.sh +101 -0
  63. package/dist/bundle/skills/watcher-observability/SKILL.md +72 -0
  64. package/dist/bundle/skills/watcher-observability/references/batch-protocol.md +44 -0
  65. package/dist/bundle/skills/watcher-observability/references/configuration.md +31 -0
  66. package/dist/bundle/skills/watcher-observability/references/error-scan.md +102 -0
  67. package/dist/bundle/skills/watcher-observability/references/live-protocol.md +49 -0
  68. package/dist/bundle/skills/watcher-observability/references/server-account.md +72 -0
  69. package/dist/bundle/skills/watcher-observability/server/watcher-gate.sh +51 -0
  70. package/dist/bundle/skills/watcher-observability/tests/watcher-gate.test.sh +113 -0
  71. package/dist/bundle/skills/watcher-observability/watcher.json +1 -0
  72. package/dist/bundle/skills/workflow-auditor/SKILL.md +53 -0
  73. package/dist/bundle/skills/workflow-auditor/references/audit-protocol.md +49 -0
  74. package/dist/bundle/skills/workflow-auditor/references/ledger.md +122 -0
  75. package/dist/change-lane/classification.js +3 -1
  76. package/dist/check-issue-claim.d.ts +2 -0
  77. package/dist/check-issue-claim.js +146 -0
  78. package/dist/check-worktree-guard.d.ts +2 -0
  79. package/dist/check-worktree-guard.js +114 -0
  80. package/dist/error-scan.d.ts +3 -0
  81. package/dist/error-scan.js +216 -0
  82. package/dist/export-public.d.ts +9 -0
  83. package/dist/export-public.js +274 -0
  84. package/dist/fetch-issue-attachments.d.ts +22 -0
  85. package/dist/fetch-issue-attachments.js +325 -0
  86. package/dist/issue-claim/evaluation.d.ts +66 -0
  87. package/dist/issue-claim/evaluation.js +259 -0
  88. package/dist/issue-claim/loaders.d.ts +5 -0
  89. package/dist/issue-claim/loaders.js +116 -0
  90. package/dist/list-zed-commands.d.ts +7 -0
  91. package/dist/list-zed-commands.js +288 -0
  92. package/dist/plan-issue-triage.d.ts +3 -0
  93. package/dist/plan-issue-triage.js +404 -0
  94. package/dist/question-gate/ledger.d.ts +5 -0
  95. package/dist/question-gate/ledger.js +115 -0
  96. package/dist/question-gate/rules.d.ts +40 -0
  97. package/dist/question-gate/rules.js +483 -0
  98. package/dist/recap/board.d.ts +5 -0
  99. package/dist/recap/board.js +384 -0
  100. package/dist/recap/git-and-github.d.ts +11 -0
  101. package/dist/recap/git-and-github.js +620 -0
  102. package/dist/recap/report-and-hud.d.ts +2 -0
  103. package/dist/recap/report-and-hud.js +294 -0
  104. package/dist/recap/time-and-refs.d.ts +27 -0
  105. package/dist/recap/time-and-refs.js +148 -0
  106. package/dist/recap.d.ts +2 -0
  107. package/dist/recap.js +217 -0
  108. package/dist/render-workflow.js +12 -14
  109. package/dist/resolve-containers.d.ts +2 -0
  110. package/dist/resolve-containers.js +96 -0
  111. package/dist/review-loop.d.ts +7 -0
  112. package/dist/review-loop.js +622 -0
  113. package/dist/save-counts.d.ts +2 -0
  114. package/dist/save-counts.js +191 -0
  115. package/dist/summarize-logs.d.ts +2 -0
  116. package/dist/summarize-logs.js +41 -0
  117. package/dist/sweep-github.d.ts +10 -0
  118. package/dist/sweep-github.js +453 -0
  119. package/dist/sweep-issues.d.ts +56 -0
  120. package/dist/sweep-issues.js +650 -0
  121. package/dist/sweep.d.ts +2 -0
  122. package/dist/sweep.js +301 -0
  123. package/dist/triage-question.d.ts +2 -0
  124. package/dist/triage-question.js +189 -0
  125. package/dist/validate-skills.d.ts +2 -0
  126. package/dist/validate-skills.js +48 -0
  127. package/dist/watch-live.d.ts +7 -0
  128. package/dist/watch-live.js +83 -0
  129. package/dist/watcher/config.d.ts +11 -0
  130. package/dist/watcher/config.js +265 -0
  131. package/dist/watcher/live-classifier.d.ts +52 -0
  132. package/dist/watcher/live-classifier.js +510 -0
  133. package/dist/watcher/safe-fs.d.ts +9 -0
  134. package/dist/watcher/safe-fs.js +159 -0
  135. package/dist/watcher/stream.d.ts +27 -0
  136. package/dist/watcher/stream.js +340 -0
  137. package/dist/watcher/summarizer.d.ts +19 -0
  138. package/dist/watcher/summarizer.js +121 -0
  139. package/dist/wave3/process.d.ts +14 -0
  140. package/dist/wave3/process.js +84 -0
  141. package/dist/wave4/process.d.ts +14 -0
  142. package/dist/wave4/process.js +128 -0
  143. package/dist/workflow/render.d.ts +1 -1
  144. package/dist/workflow/render.js +1 -1
  145. package/dist/workflow-auditor/audit.d.ts +27 -0
  146. package/dist/workflow-auditor/audit.js +583 -0
  147. package/dist/workflow-auditor/ledger-io.d.ts +5 -0
  148. package/dist/workflow-auditor/ledger-io.js +99 -0
  149. package/dist/workflow-auditor/skills-validator.d.ts +10 -0
  150. package/dist/workflow-auditor/skills-validator.js +533 -0
  151. package/dist/worktree-guard/evaluation.d.ts +19 -0
  152. package/dist/worktree-guard/evaluation.js +84 -0
  153. package/dist/worktree-guard/git.d.ts +3 -0
  154. package/dist/worktree-guard/git.js +61 -0
  155. package/package.json +32 -33
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
+ }
@@ -21,20 +21,18 @@ const readmeName = 'README.md';
21
21
  const agentsName = 'AGENTS.md';
22
22
  // The package sits at packages/cli/src, so the repository root is three levels up.
23
23
  const defaultRoot = pythonPath(fileURLToPath(new URL('../../../', import.meta.url)));
24
- const helpText = `render-workflow.py: generate the README workflow Mermaid block from one source.
25
-
26
- Usage:
27
- python3 -I -B scripts/render-workflow.py [--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
- Standard library only. JSON is parsed with \`json\`, which cannot run code.
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.
36
34
  `;
37
- const usageText = 'Usage:\n python3 -I -B scripts/render-workflow.py [--check | --write] [repo-root]';
35
+ const usageText = 'Usage:\n bbc render-workflow [--check | --write] [repo-root]';
38
36
  const native = (text) => text.replaceAll('\n', EOL);
39
37
  const flagsAllowed = ['--check', '--write', '--help'];
40
38
  const handoffBlock = /## Skill handoffs\s+```text\n([\s\S]*?)```/;
@@ -112,7 +110,7 @@ function run(root, write) {
112
110
  if (readme.slice(start, stop) === expected)
113
111
  return 'up to date';
114
112
  if (!write) {
115
- throw new WorkflowError(`${readmeName}: workflow block differs from ${sourceName}; run render-workflow.py --write`);
113
+ throw new WorkflowError(`${readmeName}: workflow block differs from ${sourceName}; run bbc render-workflow --write`);
116
114
  }
117
115
  writeAtomic(readmePath, readme.slice(0, start) + expected + readme.slice(stop));
118
116
  return 'written';
@@ -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;