@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.
- package/dist/audit-ledger.d.ts +2 -0
- package/dist/audit-ledger.js +71 -0
- package/dist/bbc-install.d.ts +2 -0
- package/dist/bbc-install.js +1250 -0
- package/dist/bbc.d.ts +2 -0
- package/dist/bbc.js +124 -0
- package/dist/bigo/complexity.d.ts +18 -0
- package/dist/bigo/complexity.js +139 -0
- package/dist/bigo/functions.d.ts +5 -0
- package/dist/bigo/functions.js +174 -0
- package/dist/bigo/keywords.d.ts +1 -0
- package/dist/bigo/keywords.js +43 -0
- package/dist/bigo/lexical.d.ts +14 -0
- package/dist/bigo/lexical.js +69 -0
- package/dist/bigo/source-files.d.ts +1 -0
- package/dist/bigo/source-files.js +80 -0
- package/dist/change-lane/classification.d.ts +41 -0
- package/dist/change-lane/classification.js +104 -0
- package/dist/change-lane/git.d.ts +8 -0
- package/dist/change-lane/git.js +105 -0
- package/dist/check-issue-claim.d.ts +2 -0
- package/dist/check-issue-claim.js +146 -0
- package/dist/check-worktree-guard.d.ts +2 -0
- package/dist/check-worktree-guard.js +114 -0
- package/dist/classify-change-lane.d.ts +2 -0
- package/dist/classify-change-lane.js +128 -0
- package/dist/diff-scope/git-diff.d.ts +25 -0
- package/dist/diff-scope/git-diff.js +146 -0
- package/dist/error-scan.d.ts +3 -0
- package/dist/error-scan.js +216 -0
- package/dist/export-public.d.ts +9 -0
- package/dist/export-public.js +274 -0
- package/dist/extract-diff-scope.d.ts +2 -0
- package/dist/extract-diff-scope.js +111 -0
- package/dist/fetch-issue-attachments.d.ts +22 -0
- package/dist/fetch-issue-attachments.js +325 -0
- package/dist/issue-claim/evaluation.d.ts +66 -0
- package/dist/issue-claim/evaluation.js +259 -0
- package/dist/issue-claim/loaders.d.ts +5 -0
- package/dist/issue-claim/loaders.js +116 -0
- package/dist/list-zed-commands.d.ts +7 -0
- package/dist/list-zed-commands.js +288 -0
- package/dist/measure-bigo.d.ts +2 -0
- package/dist/measure-bigo.js +84 -0
- package/dist/plan-issue-triage.d.ts +3 -0
- package/dist/plan-issue-triage.js +404 -0
- package/dist/question-gate/ledger.d.ts +5 -0
- package/dist/question-gate/ledger.js +115 -0
- package/dist/question-gate/rules.d.ts +40 -0
- package/dist/question-gate/rules.js +483 -0
- package/dist/recap/board.d.ts +5 -0
- package/dist/recap/board.js +384 -0
- package/dist/recap/git-and-github.d.ts +11 -0
- package/dist/recap/git-and-github.js +620 -0
- package/dist/recap/report-and-hud.d.ts +2 -0
- package/dist/recap/report-and-hud.js +294 -0
- package/dist/recap/time-and-refs.d.ts +27 -0
- package/dist/recap/time-and-refs.js +148 -0
- package/dist/recap.d.ts +2 -0
- package/dist/recap.js +217 -0
- package/dist/render-workflow.d.ts +2 -0
- package/dist/render-workflow.js +142 -0
- package/dist/resolve-containers.d.ts +2 -0
- package/dist/resolve-containers.js +96 -0
- package/dist/review-loop.d.ts +7 -0
- package/dist/review-loop.js +622 -0
- package/dist/save-counts.d.ts +2 -0
- package/dist/save-counts.js +191 -0
- package/dist/summarize-logs.d.ts +2 -0
- package/dist/summarize-logs.js +41 -0
- package/dist/sweep-github.d.ts +10 -0
- package/dist/sweep-github.js +453 -0
- package/dist/sweep-issues.d.ts +56 -0
- package/dist/sweep-issues.js +650 -0
- package/dist/sweep.d.ts +2 -0
- package/dist/sweep.js +301 -0
- package/dist/triage-question.d.ts +2 -0
- package/dist/triage-question.js +189 -0
- package/dist/validate-skills.d.ts +2 -0
- package/dist/validate-skills.js +48 -0
- package/dist/watch-live.d.ts +7 -0
- package/dist/watch-live.js +83 -0
- package/dist/watcher/config.d.ts +11 -0
- package/dist/watcher/config.js +265 -0
- package/dist/watcher/live-classifier.d.ts +52 -0
- package/dist/watcher/live-classifier.js +510 -0
- package/dist/watcher/safe-fs.d.ts +9 -0
- package/dist/watcher/safe-fs.js +159 -0
- package/dist/watcher/stream.d.ts +27 -0
- package/dist/watcher/stream.js +340 -0
- package/dist/watcher/summarizer.d.ts +19 -0
- package/dist/watcher/summarizer.js +121 -0
- package/dist/wave3/process.d.ts +14 -0
- package/dist/wave3/process.js +84 -0
- package/dist/wave4/process.d.ts +14 -0
- package/dist/wave4/process.js +128 -0
- package/dist/workflow/render.d.ts +13 -0
- package/dist/workflow/render.js +31 -0
- package/dist/workflow/schema.d.ts +25 -0
- package/dist/workflow/schema.js +99 -0
- package/dist/workflow-auditor/audit.d.ts +27 -0
- package/dist/workflow-auditor/audit.js +583 -0
- package/dist/workflow-auditor/ledger-io.d.ts +5 -0
- package/dist/workflow-auditor/ledger-io.js +99 -0
- package/dist/workflow-auditor/skills-validator.d.ts +10 -0
- package/dist/workflow-auditor/skills-validator.js +533 -0
- package/dist/worktree-guard/evaluation.d.ts +19 -0
- package/dist/worktree-guard/evaluation.js +84 -0
- package/dist/worktree-guard/git.d.ts +3 -0
- package/dist/worktree-guard/git.js +61 -0
- package/package.json +32 -33
- package/src/bbc.ts +0 -39
- package/src/bigo/complexity.ts +0 -138
- package/src/bigo/functions.ts +0 -183
- package/src/bigo/keywords.ts +0 -41
- package/src/bigo/lexical.ts +0 -68
- package/src/bigo/source-files.ts +0 -80
- package/src/change-lane/classification.ts +0 -128
- package/src/change-lane/git.ts +0 -110
- package/src/classify-change-lane.ts +0 -140
- package/src/diff-scope/git-diff.ts +0 -161
- package/src/extract-diff-scope.ts +0 -130
- package/src/measure-bigo.ts +0 -86
- package/src/render-workflow.ts +0 -144
- package/src/workflow/render.ts +0 -40
- package/src/workflow/schema.ts +0 -141
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare const gates: readonly (readonly [string, RegExp | null])[];
|
|
2
|
+
export type Mode = 'working' | 'staged' | 'range' | 'head';
|
|
3
|
+
export interface ScopeRequest {
|
|
4
|
+
mode: Mode;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Record {
|
|
8
|
+
path: string;
|
|
9
|
+
line: number;
|
|
10
|
+
content: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function isTarget(path: string): boolean;
|
|
13
|
+
export declare function yamlEscape(value: string): string;
|
|
14
|
+
export declare function awkQuote(value: string): string;
|
|
15
|
+
export declare function diffArgs(request: ScopeRequest, hasHead: boolean): string[];
|
|
16
|
+
export declare function hasHeadCommit(): boolean;
|
|
17
|
+
export declare function changedFiles(args: readonly string[]): string[];
|
|
18
|
+
export declare function untrackedFiles(): string[];
|
|
19
|
+
export declare function trackedRecords(args: readonly string[], files: readonly string[]): Record[];
|
|
20
|
+
export declare function untrackedRecords(path: string): Record[];
|
|
21
|
+
export declare function countLines(args: readonly string[], files: readonly string[]): {
|
|
22
|
+
added: number;
|
|
23
|
+
removed: number;
|
|
24
|
+
};
|
|
25
|
+
export declare function untrackedLineCount(path: string): number;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LAYER: Infrastructure
|
|
3
|
+
* Contains: Git diff scope collection.
|
|
4
|
+
* Rules: Keep bytes intact with a latin1 round-trip and never rewrite git output.
|
|
5
|
+
* BigO: O(n) score:3
|
|
6
|
+
* keywords: [DiffScope, HunkParsing]
|
|
7
|
+
* GOAL: Turn a local Git diff into the sections the quality gate consumes.
|
|
8
|
+
*/
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
import { statSync } from 'node:fs';
|
|
11
|
+
import { readFileSync } from 'node:fs';
|
|
12
|
+
const codePattern = /\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/;
|
|
13
|
+
const excludedPattern = /(^|\/)(dist|node_modules|graphify-out|\.next|\.vite|build|\.vercel|coverage)\/|^prisma\/generated\/|^server\/dist\//;
|
|
14
|
+
export const gates = [
|
|
15
|
+
['records', null],
|
|
16
|
+
['typesafe_candidates', /(:\s*any([^A-Za-z0-9_]|$)|\sas\s+any([^A-Za-z0-9_]|$)|\sas\s+[A-Za-z_]|!\.|!\[|@ts-ignore|@ts-expect-error|@ts-nocheck|<any>)/],
|
|
17
|
+
['earlyreturn_candidates', /(}\s*else(\s|$)|else\s+if\s*\(|^\s{12,}(if|for|while)\s*\(|\.then\s*\(|^\s*[?:]\s*(await\s+)?[A-Za-z0-9_$.]+\()/],
|
|
18
|
+
['bigo_candidates', /(\.(forEach|map|filter|find|some|includes|indexOf|reduce)\s*\(|for\s*\(|while\s*\(|\.\.\.acc)/],
|
|
19
|
+
];
|
|
20
|
+
const decode = (buffer) => buffer.toString('latin1');
|
|
21
|
+
function git(args, quiet) {
|
|
22
|
+
const result = spawnSync('git', [...args], {
|
|
23
|
+
stdio: ['ignore', 'pipe', quiet ? 'ignore' : 'inherit'],
|
|
24
|
+
});
|
|
25
|
+
if (result.error !== undefined || result.stdout === null)
|
|
26
|
+
return { stdout: Buffer.alloc(0), status: 1 };
|
|
27
|
+
return { stdout: result.stdout, status: result.status ?? 1 };
|
|
28
|
+
}
|
|
29
|
+
export function isTarget(path) {
|
|
30
|
+
return codePattern.test(path) && !excludedPattern.test(path);
|
|
31
|
+
}
|
|
32
|
+
export function yamlEscape(value) {
|
|
33
|
+
const parts = value.split('\n');
|
|
34
|
+
if (parts.length > 1 && parts.at(-1) === '')
|
|
35
|
+
parts.pop();
|
|
36
|
+
return parts.map((part) => part.replaceAll('\\', '\\\\').replaceAll('"', '\\"')).join('\\n');
|
|
37
|
+
}
|
|
38
|
+
export function awkQuote(value) {
|
|
39
|
+
return value.replaceAll('\\', '\\\\').replaceAll('"', '\\"');
|
|
40
|
+
}
|
|
41
|
+
function recordsOf(lines) {
|
|
42
|
+
return lines.length > 0 && lines.at(-1) === '' ? lines.slice(0, -1) : lines;
|
|
43
|
+
}
|
|
44
|
+
export function diffArgs(request, hasHead) {
|
|
45
|
+
if (request.mode === 'staged')
|
|
46
|
+
return ['--staged'];
|
|
47
|
+
if (request.mode === 'range')
|
|
48
|
+
return [request.value];
|
|
49
|
+
if (request.mode === 'head')
|
|
50
|
+
return [`HEAD~${request.value}..HEAD`];
|
|
51
|
+
return hasHead ? ['HEAD'] : ['--staged'];
|
|
52
|
+
}
|
|
53
|
+
export function hasHeadCommit() {
|
|
54
|
+
return git(['rev-parse', '--verify', 'HEAD'], true).status === 0;
|
|
55
|
+
}
|
|
56
|
+
export function changedFiles(args) {
|
|
57
|
+
const names = git(['-c', 'core.quotePath=false', 'diff', ...args, '--name-only', '-z'], true);
|
|
58
|
+
return decode(names.stdout).split('\0').filter((path) => path !== '' && isTarget(path));
|
|
59
|
+
}
|
|
60
|
+
export function untrackedFiles() {
|
|
61
|
+
const others = git(['-c', 'core.quotePath=false', 'ls-files', '--others', '--exclude-standard', '-z'], true);
|
|
62
|
+
return decode(others.stdout)
|
|
63
|
+
.split('\0')
|
|
64
|
+
.filter((path) => path !== '' && isTarget(path))
|
|
65
|
+
.filter((path) => {
|
|
66
|
+
try {
|
|
67
|
+
return statSync(path, { throwIfNoEntry: false })?.isFile() === true;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function hunkStart(row) {
|
|
75
|
+
const fields = row.split(/\s+/);
|
|
76
|
+
let start = fields[2] ?? '';
|
|
77
|
+
if (start.startsWith('+'))
|
|
78
|
+
start = start.slice(1);
|
|
79
|
+
const digits = /^[0-9]*/.exec(start.split(',')[0] ?? '')?.[0] ?? '';
|
|
80
|
+
return digits === '' ? 0 : Number(digits);
|
|
81
|
+
}
|
|
82
|
+
export function trackedRecords(args, files) {
|
|
83
|
+
const diff = git(['-c', 'core.quotePath=false', '-c', 'diff.noprefix=false', 'diff', ...args, '-U0', '--no-color', '--', ...files], false);
|
|
84
|
+
const out = [];
|
|
85
|
+
let current = '';
|
|
86
|
+
let line = 0;
|
|
87
|
+
for (const row of recordsOf(decode(diff.stdout).split('\n'))) {
|
|
88
|
+
if (row.startsWith('+++ b/')) {
|
|
89
|
+
current = row.slice(6);
|
|
90
|
+
line = 0;
|
|
91
|
+
}
|
|
92
|
+
else if (row.startsWith('+++ /dev/null')) {
|
|
93
|
+
current = '';
|
|
94
|
+
line = 0;
|
|
95
|
+
}
|
|
96
|
+
else if (row.startsWith('@@ ')) {
|
|
97
|
+
line = hunkStart(row);
|
|
98
|
+
}
|
|
99
|
+
else if (row.startsWith('+') && !row.startsWith('+++')) {
|
|
100
|
+
if (current !== '' && line > 0)
|
|
101
|
+
out.push({ path: current, line, content: row.slice(1) });
|
|
102
|
+
line += 1;
|
|
103
|
+
}
|
|
104
|
+
else if (line > 0 && row.startsWith(' ')) {
|
|
105
|
+
line += 1;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
export function untrackedRecords(path) {
|
|
111
|
+
let data;
|
|
112
|
+
try {
|
|
113
|
+
data = readFileSync(path);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
return recordsOf(decode(data).split('\n')).map((content, index) => ({ path, line: index + 1, content }));
|
|
119
|
+
}
|
|
120
|
+
export function countLines(args, files) {
|
|
121
|
+
const stat = git(['-c', 'core.quotePath=false', 'diff', ...args, '--numstat', '--', ...files], false);
|
|
122
|
+
let added = 0;
|
|
123
|
+
let removed = 0;
|
|
124
|
+
for (const row of decode(stat.stdout).split('\n')) {
|
|
125
|
+
const columns = row.split('\t');
|
|
126
|
+
const first = columns[0] ?? '';
|
|
127
|
+
if (/^[0-9]+$/.test(first))
|
|
128
|
+
added += Number(first);
|
|
129
|
+
const second = columns[1] ?? '';
|
|
130
|
+
if (/^[0-9]+$/.test(second))
|
|
131
|
+
removed += Number(second);
|
|
132
|
+
}
|
|
133
|
+
return { added, removed };
|
|
134
|
+
}
|
|
135
|
+
export function untrackedLineCount(path) {
|
|
136
|
+
try {
|
|
137
|
+
let total = 0;
|
|
138
|
+
for (const byte of readFileSync(path))
|
|
139
|
+
if (byte === 0x0a)
|
|
140
|
+
total += 1;
|
|
141
|
+
return total;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const errorScanUsage = "bbc error-scan [--project <uuid>] <ssh-alias> <exact-container> [minutes | --tail <lines>]";
|
|
2
|
+
export declare function digest(body: string, record?: Record<string, unknown> | null): string;
|
|
3
|
+
export declare function errorScan(argv: readonly string[]): Promise<number>;
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LAYER: Interface
|
|
3
|
+
* Contains: CLI entry point and allowlisted digest builder for bbc error-scan.
|
|
4
|
+
* Rules: Match error-scan.py help, output, digest allowlist, and tmp_logs/scan/ save contract.
|
|
5
|
+
* BigO: O(n^2) score:1
|
|
6
|
+
* keywords: [ErrorScanCli, DigestAllowlist, BoundedScan]
|
|
7
|
+
* GOAL: Perform one bounded historical error scan and optionally save an allowlisted digest.
|
|
8
|
+
*/
|
|
9
|
+
import { EOL } from 'node:os';
|
|
10
|
+
import { aliasPattern, ConfigError, CONTAINER_RE, resolveSshExecutable, SSH_OPTIONS, } from "./watcher/config.js";
|
|
11
|
+
import { CODES, EXCEPTIONS, jsonHit, jsonLevel, LEVELS, PATTERNS, PLAIN_LEVEL_RE, stripHeaders, } from "./watcher/live-classifier.js";
|
|
12
|
+
import { saveScanReport } from "./watcher/safe-fs.js";
|
|
13
|
+
import { runBoundedLineScan } from "./watcher/stream.js";
|
|
14
|
+
export const errorScanUsage = 'bbc error-scan [--project <uuid>] <ssh-alias> <exact-container> [minutes | --tail <lines>]';
|
|
15
|
+
const MAX_BYTES = 16 * 1024 * 1024;
|
|
16
|
+
const MAX_MINUTES = 120;
|
|
17
|
+
const MAX_TAIL = 50_000;
|
|
18
|
+
const MAX_ROWS = 40;
|
|
19
|
+
const DEADLINE_MS = 60_000;
|
|
20
|
+
const PROJECT_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
21
|
+
const EVENT_RE = /"event":"([^"]+)"/;
|
|
22
|
+
const HELP = 'Usage: bbc error-scan [--project <uuid>] <ssh-alias> <exact-container> [minutes | --tail <lines>]\n' +
|
|
23
|
+
'Read one bounded window once (1-120 minutes, or 1-50000 lines) and report only warn/error signal.\n' +
|
|
24
|
+
'--project keeps only lines that contain that project uuid (any field name, any case).';
|
|
25
|
+
const DIGEST_WORDS = new Set([
|
|
26
|
+
'error', 'errors', 'warn', 'warning', 'fatal', 'critical', 'failed', 'failure', 'fails', 'fail',
|
|
27
|
+
'timeout', 'timed', 'out', 'refused', 'reset', 'closed', 'broken', 'pipe', 'connection',
|
|
28
|
+
'connect', 'socket', 'retry', 'retrying', 'retries', 'unavailable', 'upstream', 'downstream',
|
|
29
|
+
'denied', 'forbidden', 'unauthorized', 'auth', 'authentication', 'expired', 'invalid',
|
|
30
|
+
'missing', 'not', 'found', 'exceeded', 'limit', 'rate', 'quota', 'crash', 'crashed', 'killed',
|
|
31
|
+
'memory', 'disk', 'full', 'database', 'db', 'query', 'request', 'response', 'webhook', 'message',
|
|
32
|
+
'send', 'sent', 'delivery', 'deliver', 'template', 'queue', 'job', 'worker', 'payment', 'charge',
|
|
33
|
+
'handshake', 'tls', 'ssl', 'dns', 'lookup', 'parse', 'json', 'unexpected', 'token', 'status',
|
|
34
|
+
'server', 'client', 'internal', 'gateway', 'bad', 'service', 'for', 'to', 'from', 'with', 'on',
|
|
35
|
+
'in', 'of', 'the', 'a', 'an', 'is', 'was', 'while', 'after', 'during', 'cannot', 'could',
|
|
36
|
+
]);
|
|
37
|
+
const DIGEST_EXACT = { ...CODES, ...EXCEPTIONS };
|
|
38
|
+
const DIGEST_MESSAGE_KEYS = ['msg', 'message', 'error', 'err'];
|
|
39
|
+
const DIGEST_TOKENS = 16;
|
|
40
|
+
const DIGEST_CHARS = 220;
|
|
41
|
+
const REDACTED = '[redacted]';
|
|
42
|
+
function writeOut(text) {
|
|
43
|
+
process.stdout.write(`${text.replaceAll('\n', EOL)}${EOL}`);
|
|
44
|
+
}
|
|
45
|
+
function writeErr(text) {
|
|
46
|
+
process.stderr.write(`${text.replaceAll('\n', EOL)}${EOL}`);
|
|
47
|
+
}
|
|
48
|
+
export function digest(body, record = null) {
|
|
49
|
+
let text = body;
|
|
50
|
+
if (record !== null) {
|
|
51
|
+
const key = DIGEST_MESSAGE_KEYS.find((k) => typeof record[k] === 'string');
|
|
52
|
+
text = key !== undefined ? record[key] : '';
|
|
53
|
+
}
|
|
54
|
+
const out = [];
|
|
55
|
+
for (const raw of text.trim().split(/\s+/).filter((t) => t !== '').slice(0, DIGEST_TOKENS)) {
|
|
56
|
+
const token = raw.replace(/^[.,;:()[\]{}"'!?]+|[.,;:()[\]{}"'!?]+$/g, '');
|
|
57
|
+
const exact = Object.hasOwn(DIGEST_EXACT, token) ? DIGEST_EXACT[token] : undefined;
|
|
58
|
+
const lowered = token.toLowerCase();
|
|
59
|
+
const word = exact ?? (DIGEST_WORDS.has(lowered) ? lowered : REDACTED);
|
|
60
|
+
if (word !== REDACTED || out.length === 0 || out.at(-1) !== REDACTED)
|
|
61
|
+
out.push(word);
|
|
62
|
+
}
|
|
63
|
+
return out.join(' ').slice(0, DIGEST_CHARS);
|
|
64
|
+
}
|
|
65
|
+
function classifyLine(line) {
|
|
66
|
+
const body = stripHeaders(line.trim());
|
|
67
|
+
let record = null;
|
|
68
|
+
const brace = body.indexOf('{');
|
|
69
|
+
if (brace >= 0 && body.trimEnd().endsWith('}')) {
|
|
70
|
+
try {
|
|
71
|
+
const parsed = JSON.parse(body.slice(brace));
|
|
72
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
73
|
+
record = parsed;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
record = null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let level = record !== null ? jsonLevel(record) : null;
|
|
81
|
+
let hit = record !== null ? jsonHit(record) : null;
|
|
82
|
+
if (level === null) {
|
|
83
|
+
const match = PLAIN_LEVEL_RE.exec(body);
|
|
84
|
+
if (match !== null)
|
|
85
|
+
level = LEVELS[(match[1] ?? match[2] ?? '').toLowerCase()] ?? null;
|
|
86
|
+
}
|
|
87
|
+
if (hit === null) {
|
|
88
|
+
const idx = PATTERNS.findIndex(([, regex]) => regex.test(body));
|
|
89
|
+
hit = idx === -1 ? null : idx;
|
|
90
|
+
}
|
|
91
|
+
return { level: level ?? (hit !== null ? 'error' : null), hit, body, record };
|
|
92
|
+
}
|
|
93
|
+
class Tally {
|
|
94
|
+
project;
|
|
95
|
+
filtered = 0;
|
|
96
|
+
counts = { error: 0, warn: 0, info: 0, debug: 0, unclassified: 0 };
|
|
97
|
+
hits = new Array(PATTERNS.length).fill(0);
|
|
98
|
+
events = {};
|
|
99
|
+
rows = [];
|
|
100
|
+
constructor(project) {
|
|
101
|
+
this.project = project;
|
|
102
|
+
}
|
|
103
|
+
feed(segment) {
|
|
104
|
+
const decoded = new TextDecoder('utf-8', { fatal: false }).decode(segment);
|
|
105
|
+
for (const raw of decoded.split(/\r\n|\n|\r/)) {
|
|
106
|
+
if (raw.trim() === '')
|
|
107
|
+
continue;
|
|
108
|
+
if (this.project !== null && !raw.toLowerCase().includes(this.project)) {
|
|
109
|
+
this.filtered += 1;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const { level, hit, body, record } = classifyLine(raw);
|
|
113
|
+
const bucket = level ?? 'unclassified';
|
|
114
|
+
this.counts[bucket] = (this.counts[bucket] ?? 0) + 1;
|
|
115
|
+
if (hit !== null)
|
|
116
|
+
this.hits[hit] = (this.hits[hit] ?? 0) + 1;
|
|
117
|
+
const event = EVENT_RE.exec(raw);
|
|
118
|
+
if (event !== null) {
|
|
119
|
+
const name = event[1];
|
|
120
|
+
this.events[name] = (this.events[name] ?? 0) + 1;
|
|
121
|
+
}
|
|
122
|
+
if ((level === 'error' || level === 'warn' || hit !== null) && this.rows.length < MAX_ROWS) {
|
|
123
|
+
this.rows.push({
|
|
124
|
+
level: level ?? 'signature',
|
|
125
|
+
signature: hit !== null ? PATTERNS[hit][0] : null,
|
|
126
|
+
digest: digest(body, record),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function parseSelector(args) {
|
|
133
|
+
if (args.length === 2)
|
|
134
|
+
return { kind: 'since', value: 15 };
|
|
135
|
+
if (args.length === 3 && /^\d+$/.test(args[2])) {
|
|
136
|
+
const minutes = Number.parseInt(args[2], 10);
|
|
137
|
+
if (minutes >= 1 && minutes <= MAX_MINUTES)
|
|
138
|
+
return { kind: 'since', value: minutes };
|
|
139
|
+
}
|
|
140
|
+
if (args.length === 4 && args[2] === '--tail' && /^\d+$/.test(args[3])) {
|
|
141
|
+
const tail = Number.parseInt(args[3], 10);
|
|
142
|
+
if (tail >= 1 && tail <= MAX_TAIL)
|
|
143
|
+
return { kind: 'tail', value: tail };
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
export async function errorScan(argv) {
|
|
148
|
+
let args = [...argv];
|
|
149
|
+
let project = null;
|
|
150
|
+
if (args[0] === '--project') {
|
|
151
|
+
if (args.length < 2 || !PROJECT_RE.test(args[1])) {
|
|
152
|
+
writeErr(HELP);
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
project = args[1].toLowerCase();
|
|
156
|
+
args = args.slice(2);
|
|
157
|
+
}
|
|
158
|
+
if (args.length < 2 || args.length > 4) {
|
|
159
|
+
writeErr(HELP);
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
let aliasOk;
|
|
163
|
+
try {
|
|
164
|
+
aliasOk = aliasPattern();
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (error instanceof ConfigError) {
|
|
168
|
+
writeErr(error.message);
|
|
169
|
+
return 1;
|
|
170
|
+
}
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
const [alias, container] = [args[0], args[1]];
|
|
174
|
+
const selector = parseSelector(args);
|
|
175
|
+
if (!aliasOk.test(alias) || !CONTAINER_RE.test(container) || selector === null) {
|
|
176
|
+
writeErr(HELP);
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
const ssh = resolveSshExecutable();
|
|
180
|
+
if (ssh === null) {
|
|
181
|
+
writeErr('Watcher scan failed; no counts.');
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
const flag = selector.kind === 'since' ? `--since=${selector.value}m` : `--tail=${selector.value}`;
|
|
185
|
+
const tally = new Tally(project);
|
|
186
|
+
let totalBytes = 0;
|
|
187
|
+
try {
|
|
188
|
+
const res = await runBoundedLineScan(ssh, [...SSH_OPTIONS, alias, 'docker', 'logs', flag, '--timestamps', '--', container], DEADLINE_MS, MAX_BYTES, (segment) => tally.feed(segment));
|
|
189
|
+
totalBytes = res.totalBytes;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
const msg = error instanceof Error ? error.message : 'Watcher scan failed; no counts.';
|
|
193
|
+
writeErr(msg);
|
|
194
|
+
return 1;
|
|
195
|
+
}
|
|
196
|
+
const total = Object.values(tally.counts).reduce((a, b) => a + b, 0);
|
|
197
|
+
const scope = project !== null ? ` project=${project} filtered_out=${tally.filtered}` : '';
|
|
198
|
+
const label = selector.kind === 'since' ? `${selector.value}m` : `${selector.value}l`;
|
|
199
|
+
writeOut(`scan alias=${alias} container=${container} selector=${label} lines=${total} bytes=${totalBytes}${scope}`);
|
|
200
|
+
writeOut(`severity ${Object.entries(tally.counts).map(([k, v]) => `${k}=${v}`).join(' ')}`);
|
|
201
|
+
const ranked = PATTERNS.map(([name], i) => [name, tally.hits[i] ?? 0])
|
|
202
|
+
.filter(([, n]) => n > 0)
|
|
203
|
+
.sort((a, b) => b[1] - a[1]);
|
|
204
|
+
writeOut(`signatures ${ranked.length > 0 ? ranked.map(([name, n]) => `${name}:${n}`).join(', ') : 'none'}`);
|
|
205
|
+
const topEvents = Object.entries(tally.events).sort((a, b) => b[1] - a[1]).slice(0, 8);
|
|
206
|
+
writeOut(`events ${topEvents.length > 0 ? topEvents.map(([name, n]) => `${name}:${n}`).join(', ') : 'none'}`);
|
|
207
|
+
writeOut(`evidence rows=${tally.rows.length}`);
|
|
208
|
+
for (const row of tally.rows) {
|
|
209
|
+
const sig = row.signature !== null ? ` sig=${row.signature}` : '';
|
|
210
|
+
writeOut(` [${row.level}]${sig} ${row.digest}`);
|
|
211
|
+
}
|
|
212
|
+
const saved = saveScanReport(alias, container, selector, tally.counts, tally.hits, PATTERNS.map(([name]) => name), tally.events, tally.rows, totalBytes, project, tally.filtered);
|
|
213
|
+
if (saved !== null)
|
|
214
|
+
writeOut(`saved=${saved}`);
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const exportPublicUsage = "bbc export-public <out-dir> --public-repo <owner/name> [--repo <repo-root>]";
|
|
2
|
+
export declare class ExportRefusedError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function trackedFiles(root: string): string[];
|
|
6
|
+
export declare function privateProfiles(root: string): Map<string, string[]>;
|
|
7
|
+
export declare function dropMarked(text: string, srcName: string): string;
|
|
8
|
+
export declare function exportPublicEdition(rootInput: string, outInput: string, publicRepo: string): Record<string, unknown>;
|
|
9
|
+
export declare function exportPublic(argv: readonly string[]): number;
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LAYER: Application
|
|
3
|
+
* Contains: Public edition exporter stripping private profiles, release tooling, launch docs, and git history.
|
|
4
|
+
* Rules: Fail closed and remove output directory on any leak, marker error, or validation failure.
|
|
5
|
+
* BigO: O(n^2) score:1
|
|
6
|
+
* keywords: [ExportPublic, LeakScanner, ExportDrop, ProfileIsolation]
|
|
7
|
+
* GOAL: Build a leak-free public edition directory from git-tracked repository files.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
10
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { decodeUtf8Strict, runExecutable } from "./wave4/process.js";
|
|
13
|
+
import { validateRepo } from "./workflow-auditor/skills-validator.js";
|
|
14
|
+
export const exportPublicUsage = 'bbc export-public <out-dir> --public-repo <owner/name> [--repo <repo-root>]';
|
|
15
|
+
const MARKER = 'export' + ':drop';
|
|
16
|
+
const LINE_MARK = new RegExp(`(?:<!-- ${MARKER} -->|(?:^|\\s)# ${MARKER}(?![:\\w])[^\\n]*)\\s*$`);
|
|
17
|
+
const BLOCK_START = new Set([`<!-- ${MARKER}:start -->`, `# ${MARKER}:start`]);
|
|
18
|
+
const BLOCK_END = new Set([`<!-- ${MARKER}:end -->`, `# ${MARKER}:end`]);
|
|
19
|
+
const ALWAYS_DROPPED = ['tools/', 'docs/launch/', 'odd/'];
|
|
20
|
+
const ALLOWED_EMAIL = /@(?:[a-z0-9-]+\.)*(?:example\.(?:com|org|net)|[a-z0-9-]+\.(?:test|invalid|example)|users\.noreply\.github\.com|anthropic\.com)$|^git@github\.com$/i;
|
|
21
|
+
const EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
22
|
+
const SLUG_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9._-]{1,100}$/;
|
|
23
|
+
const HELP = 'Usage: bbc export-public <out-dir> --public-repo <owner/name> [--repo <repo-root>]\n';
|
|
24
|
+
export class ExportRefusedError extends Error {
|
|
25
|
+
constructor(message) {
|
|
26
|
+
super(message);
|
|
27
|
+
this.name = 'ExportRefusedError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function escapeRegex(value) {
|
|
31
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
32
|
+
}
|
|
33
|
+
function defaultRepoRoot() {
|
|
34
|
+
return fileURLToPath(new URL('../../..', import.meta.url));
|
|
35
|
+
}
|
|
36
|
+
export function trackedFiles(root) {
|
|
37
|
+
const res = runExecutable(['git', '-C', root, 'ls-files', '-z']);
|
|
38
|
+
if (res.code !== 0 || res.error) {
|
|
39
|
+
throw new ExportRefusedError(`git ls-files failed: ${res.stderr.toString('utf8').trim()}`);
|
|
40
|
+
}
|
|
41
|
+
return res.stdout
|
|
42
|
+
.toString('utf8')
|
|
43
|
+
.split('\0')
|
|
44
|
+
.filter((name) => name.length > 0);
|
|
45
|
+
}
|
|
46
|
+
export function privateProfiles(root) {
|
|
47
|
+
const profiles = new Map();
|
|
48
|
+
const commandsDir = join(root, 'commands');
|
|
49
|
+
if (!existsSync(commandsDir))
|
|
50
|
+
return profiles;
|
|
51
|
+
let dirs;
|
|
52
|
+
try {
|
|
53
|
+
dirs = readdirSync(commandsDir).sort();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return profiles;
|
|
57
|
+
}
|
|
58
|
+
for (const name of dirs) {
|
|
59
|
+
const idFile = join(commandsDir, name, 'profile-identifiers.txt');
|
|
60
|
+
if (!existsSync(idFile))
|
|
61
|
+
continue;
|
|
62
|
+
const raw = readFileSync(idFile, 'utf8');
|
|
63
|
+
const words = raw
|
|
64
|
+
.split(/\r?\n/)
|
|
65
|
+
.map((line) => (line.split('#', 1)[0] ?? '').trim())
|
|
66
|
+
.filter((w) => w.length > 0);
|
|
67
|
+
profiles.set(name, words);
|
|
68
|
+
}
|
|
69
|
+
return profiles;
|
|
70
|
+
}
|
|
71
|
+
function buildLeakPatterns(profiles, privateName) {
|
|
72
|
+
const patterns = [
|
|
73
|
+
[new RegExp(escapeRegex(privateName)), 'reference to the private repository'],
|
|
74
|
+
];
|
|
75
|
+
for (const [name, words] of profiles.entries()) {
|
|
76
|
+
for (const word of words) {
|
|
77
|
+
patterns.push([
|
|
78
|
+
new RegExp(`(?<![A-Za-z0-9])${escapeRegex(word)}(?![A-Za-z0-9])`, 'i'),
|
|
79
|
+
`identifier '${word.toLowerCase()}' of the ${name} profile`,
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
const n = escapeRegex(name);
|
|
83
|
+
patterns.push([
|
|
84
|
+
new RegExp(`commands/${n}\\b|(?<![A-Za-z0-9_-])/${n}\\b|(?<![A-Za-z0-9_./-])${n}/|--skill ${n}\\b`),
|
|
85
|
+
`reference to the removed ${name} profile`,
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
patterns.push([
|
|
89
|
+
new RegExp(`${LINE_MARK.source}|^\\s*(?:<!-- |# )${MARKER}:(?:start|end)`, 'm'),
|
|
90
|
+
`leftover ${MARKER} marker`,
|
|
91
|
+
]);
|
|
92
|
+
return patterns;
|
|
93
|
+
}
|
|
94
|
+
export function dropMarked(text, srcName) {
|
|
95
|
+
const kept = [];
|
|
96
|
+
let inside = false;
|
|
97
|
+
const lines = text.match(/[^\n]*\n|[^\n]+$/g) ?? [];
|
|
98
|
+
for (const line of lines) {
|
|
99
|
+
const stripped = line.trim();
|
|
100
|
+
if (BLOCK_START.has(stripped)) {
|
|
101
|
+
if (inside)
|
|
102
|
+
throw new ExportRefusedError(`${srcName}: nested ${MARKER}:start`);
|
|
103
|
+
inside = true;
|
|
104
|
+
}
|
|
105
|
+
else if (BLOCK_END.has(stripped)) {
|
|
106
|
+
if (!inside)
|
|
107
|
+
throw new ExportRefusedError(`${srcName}: ${MARKER}:end without start`);
|
|
108
|
+
inside = false;
|
|
109
|
+
}
|
|
110
|
+
else if (!inside && !LINE_MARK.test(line)) {
|
|
111
|
+
kept.push(line);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (inside)
|
|
115
|
+
throw new ExportRefusedError(`${srcName}: ${MARKER}:start is never closed`);
|
|
116
|
+
return kept.join('');
|
|
117
|
+
}
|
|
118
|
+
function copyFileFiltered(src, dst, renames) {
|
|
119
|
+
const data = readFileSync(src);
|
|
120
|
+
let text = decodeUtf8Strict(data);
|
|
121
|
+
if (text === null) {
|
|
122
|
+
writeFileSync(dst, data);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (text.includes(MARKER)) {
|
|
126
|
+
text = dropMarked(text, src.split(/[\\/]/).pop() ?? src);
|
|
127
|
+
}
|
|
128
|
+
for (const [oldStr, newStr] of renames) {
|
|
129
|
+
text = text.replaceAll(oldStr, newStr);
|
|
130
|
+
}
|
|
131
|
+
writeFileSync(dst, text, 'utf8');
|
|
132
|
+
}
|
|
133
|
+
function walkFilesSorted(dir, rootDir, out) {
|
|
134
|
+
const entries = readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));
|
|
135
|
+
for (const entry of entries) {
|
|
136
|
+
const full = join(dir, entry.name);
|
|
137
|
+
if (entry.isDirectory()) {
|
|
138
|
+
walkFilesSorted(full, rootDir, out);
|
|
139
|
+
}
|
|
140
|
+
else if (entry.isFile()) {
|
|
141
|
+
out.push(relative(rootDir, full).replaceAll('\\', '/'));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function problemsIn(outDir, patterns) {
|
|
146
|
+
const found = [];
|
|
147
|
+
const files = [];
|
|
148
|
+
walkFilesSorted(outDir, outDir, files);
|
|
149
|
+
files.sort();
|
|
150
|
+
for (const rel of files) {
|
|
151
|
+
const text = decodeUtf8Strict(readFileSync(join(outDir, rel)));
|
|
152
|
+
if (text === null)
|
|
153
|
+
continue;
|
|
154
|
+
for (const [pattern, label] of patterns) {
|
|
155
|
+
if (pattern.test(text)) {
|
|
156
|
+
found.push(`${rel}: ${label}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const emails = Array.from(new Set(text.match(EMAIL_RE) ?? [])).sort();
|
|
160
|
+
for (const address of emails) {
|
|
161
|
+
if (!ALLOWED_EMAIL.test(address)) {
|
|
162
|
+
const domain = address.split('@', 2)[1] ?? '';
|
|
163
|
+
found.push(`${rel}: personal or real e-mail address (${domain} domain)`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return found;
|
|
168
|
+
}
|
|
169
|
+
function isSubPath(parent, candidate) {
|
|
170
|
+
const p = parent.endsWith(sep) ? parent : `${parent}${sep}`;
|
|
171
|
+
return candidate.startsWith(p);
|
|
172
|
+
}
|
|
173
|
+
function validatePublicExport(outDir) {
|
|
174
|
+
const report = validateRepo(outDir);
|
|
175
|
+
if (report.verdict !== 'pass') {
|
|
176
|
+
throw new ExportRefusedError(`validate-skills fails on the public edition:\n${report.errors.join('\n')}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
export function exportPublicEdition(rootInput, outInput, publicRepo) {
|
|
180
|
+
const root = resolve(rootInput);
|
|
181
|
+
const out = resolve(outInput);
|
|
182
|
+
if (!SLUG_RE.test(publicRepo)) {
|
|
183
|
+
throw new ExportRefusedError(`--public-repo must be owner/name, got '${publicRepo}'`);
|
|
184
|
+
}
|
|
185
|
+
const exportConfig = JSON.parse(readFileSync(join(root, 'tools', 'export.json'), 'utf8'));
|
|
186
|
+
const privateRepo = String(exportConfig.private_repo ?? '');
|
|
187
|
+
const privateName = privateRepo.split('/')[1] ?? '';
|
|
188
|
+
const publicName = publicRepo.split('/')[1] ?? '';
|
|
189
|
+
const renames = [
|
|
190
|
+
[privateRepo, publicRepo],
|
|
191
|
+
[privateName, publicName],
|
|
192
|
+
];
|
|
193
|
+
if (existsSync(out)) {
|
|
194
|
+
const st = statSync(out);
|
|
195
|
+
if (!st.isDirectory() || readdirSync(out).length > 0) {
|
|
196
|
+
throw new ExportRefusedError(`${out} exists and is not an empty directory; nothing was written`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (out === root || isSubPath(root, out)) {
|
|
200
|
+
throw new ExportRefusedError('the output directory must be outside the repository');
|
|
201
|
+
}
|
|
202
|
+
const profiles = privateProfiles(root);
|
|
203
|
+
const droppedPrefixes = [...ALWAYS_DROPPED, ...Array.from(profiles.keys()).map((name) => `commands/${name}/`)];
|
|
204
|
+
let kept = 0;
|
|
205
|
+
let skipped = 0;
|
|
206
|
+
mkdirSync(out, { recursive: true });
|
|
207
|
+
try {
|
|
208
|
+
for (const name of trackedFiles(root)) {
|
|
209
|
+
if (droppedPrefixes.some((prefix) => name.startsWith(prefix))) {
|
|
210
|
+
skipped += 1;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const src = join(root, name);
|
|
214
|
+
if (!existsSync(src) || !statSync(src).isFile()) {
|
|
215
|
+
throw new ExportRefusedError(`${name} is tracked but missing from the working tree`);
|
|
216
|
+
}
|
|
217
|
+
const dst = join(out, name);
|
|
218
|
+
mkdirSync(dirname(dst), { recursive: true });
|
|
219
|
+
copyFileFiltered(src, dst, renames);
|
|
220
|
+
kept += 1;
|
|
221
|
+
}
|
|
222
|
+
const found = problemsIn(out, buildLeakPatterns(profiles, privateName));
|
|
223
|
+
if (found.length > 0) {
|
|
224
|
+
throw new ExportRefusedError(`the public edition would leak:\n ${found.join('\n ')}`);
|
|
225
|
+
}
|
|
226
|
+
validatePublicExport(out);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
rmSync(out, { recursive: true, force: true });
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
verdict: 'exported',
|
|
234
|
+
output: out,
|
|
235
|
+
files: kept,
|
|
236
|
+
left_out: skipped,
|
|
237
|
+
profiles_removed: Array.from(profiles.keys()).sort(),
|
|
238
|
+
public_repo: publicRepo,
|
|
239
|
+
history: 'none (files only)',
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
export function exportPublic(argv) {
|
|
243
|
+
if (argv.length === 0 || argv[0] === '-h' || argv[0] === '--help') {
|
|
244
|
+
process.stdout.write(`${HELP}\n`);
|
|
245
|
+
return argv.length > 0 ? 0 : 2;
|
|
246
|
+
}
|
|
247
|
+
const outDir = argv[0];
|
|
248
|
+
let root = defaultRepoRoot();
|
|
249
|
+
let publicRepo = null;
|
|
250
|
+
let idx = 1;
|
|
251
|
+
while (idx + 1 < argv.length && (argv[idx] === '--repo' || argv[idx] === '--public-repo')) {
|
|
252
|
+
if (argv[idx] === '--repo') {
|
|
253
|
+
root = argv[idx + 1];
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
publicRepo = argv[idx + 1];
|
|
257
|
+
}
|
|
258
|
+
idx += 2;
|
|
259
|
+
}
|
|
260
|
+
if (idx < argv.length || publicRepo === null) {
|
|
261
|
+
process.stderr.write(`${HELP}\n`);
|
|
262
|
+
return 2;
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
const report = exportPublicEdition(root, outDir, publicRepo);
|
|
266
|
+
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
267
|
+
return 0;
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
271
|
+
process.stderr.write(`export refused: ${msg}\n`);
|
|
272
|
+
return 1;
|
|
273
|
+
}
|
|
274
|
+
}
|