@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,27 @@
1
+ import type { LogStream } from './live-classifier.ts';
2
+ export declare function runBoundedCutoff(executable: string, args: readonly string[], deadlineMs: number, killGraceMs: number, cutoffBytes: number): Promise<{
3
+ ok: true;
4
+ data: Buffer;
5
+ } | {
6
+ ok: false;
7
+ reason: string;
8
+ }>;
9
+ export declare function runBoundedBatch(executable: string, args: readonly string[], deadlineMs: number, killGraceMs: number, capBytes: number): Promise<{
10
+ data: Buffer;
11
+ producerStatus: number;
12
+ } | null>;
13
+ export declare function runBoundedLineScan(executable: string, args: readonly string[], deadlineMs: number, maxBytes: number, onSegment: (segment: Buffer) => void): Promise<{
14
+ totalBytes: number;
15
+ }>;
16
+ export declare class ProcessLogStream implements LogStream {
17
+ private proc;
18
+ private queue;
19
+ private eof;
20
+ private waiter;
21
+ private closed;
22
+ private exited;
23
+ constructor(executable: string, args: readonly string[]);
24
+ private flushWaiter;
25
+ readUntil(deadlineSeconds: number): Promise<Buffer | null>;
26
+ stop(): Promise<boolean>;
27
+ }
@@ -0,0 +1,340 @@
1
+ /**
2
+ * LAYER: Infrastructure
3
+ * Contains: Bounded async child-process stream transports for Watcher SSH commands.
4
+ * Rules: Enforce byte limits, wall-clock deadlines, kill-grace, and backpressure without shells when possible.
5
+ * BigO: O(n^2) score:1
6
+ * keywords: [WatcherStream, BoundedChildProcess, DeadlineKill]
7
+ * GOAL: Stream bounded stdout/stderr from SSH child processes for live and batch capture.
8
+ */
9
+ import { spawn } from 'node:child_process';
10
+ function spawnCommand(executable, args, mergeStderr) {
11
+ const isWinBatch = process.platform === 'win32' && /\.(?:cmd|bat)$/i.test(executable);
12
+ if (isWinBatch) {
13
+ return spawn(process.env.ComSpec ?? 'cmd.exe', ['/d', '/c', executable, ...args], {
14
+ stdio: ['ignore', 'pipe', mergeStderr ? 'pipe' : 'ignore'],
15
+ windowsHide: true,
16
+ });
17
+ }
18
+ return spawn(executable, [...args], {
19
+ stdio: ['ignore', 'pipe', mergeStderr ? 'pipe' : 'ignore'],
20
+ windowsHide: true,
21
+ });
22
+ }
23
+ function attachMergedPipes(proc, mergeStderr, onChunk, onDone) {
24
+ let openStreams = mergeStderr ? 2 : 1;
25
+ const finishOne = () => {
26
+ openStreams -= 1;
27
+ if (openStreams <= 0)
28
+ onDone();
29
+ };
30
+ proc.stdout?.on('data', (chunk) => {
31
+ if (chunk.length > 0)
32
+ onChunk(chunk);
33
+ });
34
+ proc.stdout?.on('end', finishOne);
35
+ proc.stdout?.on('error', finishOne);
36
+ if (mergeStderr) {
37
+ proc.stderr?.on('data', (chunk) => {
38
+ if (chunk.length > 0)
39
+ onChunk(chunk);
40
+ });
41
+ proc.stderr?.on('end', finishOne);
42
+ proc.stderr?.on('error', finishOne);
43
+ }
44
+ }
45
+ export async function runBoundedCutoff(executable, args, deadlineMs, killGraceMs, cutoffBytes) {
46
+ return new Promise((resolve) => {
47
+ let proc;
48
+ try {
49
+ proc = spawnCommand(executable, args, false);
50
+ }
51
+ catch {
52
+ resolve({ ok: false, reason: 'spawn' });
53
+ return;
54
+ }
55
+ const chunks = [];
56
+ let total = 0;
57
+ let settled = false;
58
+ let exitCode = null;
59
+ let streamDone = false;
60
+ const finish = (result) => {
61
+ if (settled)
62
+ return;
63
+ settled = true;
64
+ clearTimeout(deadlineTimer);
65
+ resolve(result);
66
+ };
67
+ const killChild = () => {
68
+ if (proc.exitCode !== null || proc.signalCode !== null)
69
+ return;
70
+ try {
71
+ proc.kill('SIGTERM');
72
+ }
73
+ catch {
74
+ // Ignore termination race.
75
+ }
76
+ setTimeout(() => {
77
+ if (proc.exitCode === null && proc.signalCode === null) {
78
+ try {
79
+ proc.kill('SIGKILL');
80
+ }
81
+ catch {
82
+ // Ignore kill race.
83
+ }
84
+ }
85
+ }, killGraceMs).unref();
86
+ };
87
+ const deadlineTimer = setTimeout(() => {
88
+ killChild();
89
+ finish({ ok: false, reason: 'deadline' });
90
+ }, deadlineMs);
91
+ const tryComplete = () => {
92
+ if (!streamDone || exitCode === null)
93
+ return;
94
+ if (exitCode !== 0) {
95
+ finish({ ok: false, reason: 'status' });
96
+ return;
97
+ }
98
+ finish({ ok: true, data: Buffer.concat(chunks) });
99
+ };
100
+ proc.on('error', () => finish({ ok: false, reason: 'spawn' }));
101
+ proc.on('close', (code) => {
102
+ exitCode = code ?? 1;
103
+ streamDone = true;
104
+ tryComplete();
105
+ });
106
+ attachMergedPipes(proc, false, (chunk) => {
107
+ if (settled)
108
+ return;
109
+ total += chunk.length;
110
+ if (total >= cutoffBytes) {
111
+ killChild();
112
+ finish({ ok: false, reason: 'cutoff' });
113
+ return;
114
+ }
115
+ chunks.push(chunk);
116
+ }, () => {
117
+ streamDone = true;
118
+ tryComplete();
119
+ });
120
+ });
121
+ }
122
+ export async function runBoundedBatch(executable, args, deadlineMs, killGraceMs, capBytes) {
123
+ return new Promise((resolve) => {
124
+ let proc;
125
+ try {
126
+ proc = spawnCommand(executable, args, true);
127
+ }
128
+ catch {
129
+ resolve(null);
130
+ return;
131
+ }
132
+ const kept = [];
133
+ let size = 0;
134
+ let settled = false;
135
+ let expired = false;
136
+ let killTimer;
137
+ const finish = (value) => {
138
+ if (settled)
139
+ return;
140
+ settled = true;
141
+ clearTimeout(deadlineTimer);
142
+ if (killTimer !== undefined)
143
+ clearTimeout(killTimer);
144
+ resolve(value);
145
+ };
146
+ const deadlineTimer = setTimeout(() => {
147
+ expired = true;
148
+ if (proc.exitCode === null && proc.signalCode === null) {
149
+ try {
150
+ proc.kill('SIGTERM');
151
+ }
152
+ catch {
153
+ // Ignore race.
154
+ }
155
+ killTimer = setTimeout(() => {
156
+ if (proc.exitCode === null && proc.signalCode === null) {
157
+ try {
158
+ proc.kill('SIGKILL');
159
+ }
160
+ catch {
161
+ // Ignore race.
162
+ }
163
+ }
164
+ finish({ data: Buffer.concat(kept), producerStatus: 137 });
165
+ }, killGraceMs);
166
+ }
167
+ else {
168
+ finish({ data: Buffer.concat(kept), producerStatus: 124 });
169
+ }
170
+ }, deadlineMs);
171
+ proc.on('error', () => finish(null));
172
+ proc.on('close', (code, signal) => {
173
+ if (expired) {
174
+ finish({ data: Buffer.concat(kept), producerStatus: signal === 'SIGKILL' ? 137 : 124 });
175
+ return;
176
+ }
177
+ const status = code !== null ? code : 128 + 15;
178
+ finish({ data: Buffer.concat(kept), producerStatus: status });
179
+ });
180
+ attachMergedPipes(proc, true, (chunk) => {
181
+ if (size >= capBytes)
182
+ return;
183
+ const take = chunk.subarray(0, capBytes - size);
184
+ kept.push(take);
185
+ size += take.length;
186
+ }, () => { });
187
+ });
188
+ }
189
+ export async function runBoundedLineScan(executable, args, deadlineMs, maxBytes, onSegment) {
190
+ return new Promise((resolve, reject) => {
191
+ let proc;
192
+ try {
193
+ proc = spawnCommand(executable, args, false);
194
+ }
195
+ catch {
196
+ reject(new Error('Watcher scan failed; no counts.'));
197
+ return;
198
+ }
199
+ let pending = Buffer.alloc(0);
200
+ let totalBytes = 0;
201
+ let settled = false;
202
+ const fail = (message) => {
203
+ if (settled)
204
+ return;
205
+ settled = true;
206
+ clearTimeout(deadlineTimer);
207
+ try {
208
+ if (proc.exitCode === null && proc.signalCode === null)
209
+ proc.kill('SIGKILL');
210
+ }
211
+ catch {
212
+ // Ignore race.
213
+ }
214
+ reject(new Error(message));
215
+ };
216
+ const deadlineTimer = setTimeout(() => fail('Watcher scan failed; no counts.'), deadlineMs);
217
+ proc.on('error', () => fail('Watcher scan failed; no counts.'));
218
+ proc.on('close', (code) => {
219
+ if (settled)
220
+ return;
221
+ if (pending.length > 0)
222
+ onSegment(pending);
223
+ if (code !== 0) {
224
+ fail('Watcher scan failed; no counts.');
225
+ return;
226
+ }
227
+ settled = true;
228
+ clearTimeout(deadlineTimer);
229
+ resolve({ totalBytes });
230
+ });
231
+ attachMergedPipes(proc, false, (chunk) => {
232
+ if (settled)
233
+ return;
234
+ totalBytes += chunk.length;
235
+ if (totalBytes > maxBytes) {
236
+ fail(`Watcher scan refused: output over the ${maxBytes} byte ceiling.`);
237
+ return;
238
+ }
239
+ pending = pending.length === 0 ? chunk : Buffer.concat([pending, chunk]);
240
+ const cut = pending.lastIndexOf(0x0a);
241
+ if (cut >= 0) {
242
+ let start = 0;
243
+ const head = pending.subarray(0, cut);
244
+ while (start <= head.length) {
245
+ const lf = head.indexOf(0x0a, start);
246
+ const end = lf >= 0 ? lf : head.length;
247
+ onSegment(head.subarray(start, end));
248
+ if (lf < 0)
249
+ break;
250
+ start = lf + 1;
251
+ }
252
+ pending = pending.subarray(cut + 1);
253
+ }
254
+ }, () => { });
255
+ });
256
+ }
257
+ export class ProcessLogStream {
258
+ proc;
259
+ queue = [];
260
+ eof = false;
261
+ waiter = null;
262
+ closed = false;
263
+ exited = false;
264
+ constructor(executable, args) {
265
+ this.proc = spawnCommand(executable, args, true);
266
+ this.proc.on('error', () => {
267
+ this.eof = true;
268
+ this.exited = true;
269
+ this.flushWaiter();
270
+ });
271
+ this.proc.on('close', () => {
272
+ this.eof = true;
273
+ this.exited = true;
274
+ this.flushWaiter();
275
+ });
276
+ attachMergedPipes(this.proc, true, (chunk) => {
277
+ if (this.closed)
278
+ return;
279
+ this.queue.push(chunk);
280
+ this.flushWaiter();
281
+ }, () => {
282
+ this.eof = true;
283
+ this.flushWaiter();
284
+ });
285
+ }
286
+ flushWaiter() {
287
+ if (this.waiter === null)
288
+ return;
289
+ if (this.queue.length > 0) {
290
+ const resolve = this.waiter;
291
+ this.waiter = null;
292
+ resolve(this.queue.shift());
293
+ }
294
+ else if (this.eof) {
295
+ const resolve = this.waiter;
296
+ this.waiter = null;
297
+ resolve(Buffer.alloc(0));
298
+ }
299
+ }
300
+ readUntil(deadlineSeconds) {
301
+ if (this.queue.length > 0)
302
+ return Promise.resolve(this.queue.shift());
303
+ if (this.eof)
304
+ return Promise.resolve(Buffer.alloc(0));
305
+ const remainingMs = Math.max(0, Math.round((deadlineSeconds - performance.now() / 1000) * 1000));
306
+ if (remainingMs === 0)
307
+ return Promise.resolve(null);
308
+ return new Promise((resolve) => {
309
+ const timer = setTimeout(() => {
310
+ if (this.waiter === onItem)
311
+ this.waiter = null;
312
+ resolve(null);
313
+ }, remainingMs);
314
+ const onItem = (item) => {
315
+ clearTimeout(timer);
316
+ resolve(item);
317
+ };
318
+ this.waiter = onItem;
319
+ });
320
+ }
321
+ stop() {
322
+ this.closed = true;
323
+ const wasRunning = !this.exited && this.proc.exitCode === null && this.proc.signalCode === null;
324
+ if (!wasRunning)
325
+ return Promise.resolve(false);
326
+ try {
327
+ this.proc.kill('SIGKILL');
328
+ }
329
+ catch {
330
+ return Promise.resolve(false);
331
+ }
332
+ return new Promise((resolve) => {
333
+ const timer = setTimeout(() => resolve(this.exited), 1000);
334
+ this.proc.once('close', () => {
335
+ clearTimeout(timer);
336
+ resolve(true);
337
+ });
338
+ });
339
+ }
340
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * LAYER: Domain
3
+ * Contains: Pure bounded 32 KiB log batch summarizer and report helper builders.
4
+ * Rules: Zero external dependencies; C-locale ASCII tokenization matching summarize-logs.py.
5
+ * BigO: O(n^2) score:1
6
+ * keywords: [LogSummarizer, BoundedBatch, NumericFields]
7
+ * GOAL: Produce severity and category counts over at most 32 KiB of log bytes.
8
+ */
9
+ export declare const CAP = 32768;
10
+ export declare function summarize(input: Uint8Array): {
11
+ text: string;
12
+ status: 0 | 3 | 4;
13
+ };
14
+ export declare function numericFields(fields: readonly string[]): Record<string, number>;
15
+ export declare function noEvidence(): {
16
+ status: string;
17
+ message: string;
18
+ events: unknown[];
19
+ };
@@ -0,0 +1,121 @@
1
+ /**
2
+ * LAYER: Domain
3
+ * Contains: Pure bounded 32 KiB log batch summarizer and report helper builders.
4
+ * Rules: Zero external dependencies; C-locale ASCII tokenization matching summarize-logs.py.
5
+ * BigO: O(n^2) score:1
6
+ * keywords: [LogSummarizer, BoundedBatch, NumericFields]
7
+ * GOAL: Produce severity and category counts over at most 32 KiB of log bytes.
8
+ */
9
+ export const CAP = 32_768;
10
+ const LEVEL_WINDOW = 12;
11
+ const SEVERITY = {
12
+ error: 'error',
13
+ fatal: 'error',
14
+ panic: 'error',
15
+ warn: 'warn',
16
+ warning: 'warn',
17
+ info: 'info',
18
+ debug: 'debug',
19
+ trace: 'debug',
20
+ };
21
+ const SIGNATURE_RE = / (typeerror|unhandledpromiserejection|econnrefused|etimedout|econnreset|epipe|eai_again|getaddrinfo|out of memory) | http 5[0-9][0-9] /;
22
+ const TIMEOUT_RE = / (timeout|timed out) /;
23
+ const CONNECTION_RE = / (connection|connect|disconnect(ed)?) /;
24
+ const AUTH_RE = / (auth|authentication|unauthorized|forbidden) /;
25
+ function numericLevel(value) {
26
+ if (value >= 50)
27
+ return 'error';
28
+ if (value >= 40)
29
+ return 'warn';
30
+ if (value >= 30)
31
+ return 'info';
32
+ if (value >= 10)
33
+ return 'debug';
34
+ return '';
35
+ }
36
+ function recordLevel(tokens) {
37
+ const limit = Math.min(tokens.length, LEVEL_WINDOW);
38
+ for (let i = 0; i < limit; i++) {
39
+ const token = tokens[i];
40
+ const level = SEVERITY[token];
41
+ if (level !== undefined)
42
+ return level;
43
+ if ((token === 'level' || token === 'lvl') && i + 1 < tokens.length && /^\d+$/.test(tokens[i + 1])) {
44
+ const numeric = numericLevel(Number.parseInt(tokens[i + 1], 10));
45
+ if (numeric !== '')
46
+ return numeric;
47
+ }
48
+ }
49
+ return '';
50
+ }
51
+ function normalizeAsciiRecord(raw) {
52
+ let out = ' ';
53
+ let inSep = false;
54
+ for (let i = 0; i < raw.length; i++) {
55
+ const byte = raw[i];
56
+ const isWord = (byte >= 0x41 && byte <= 0x5a) ||
57
+ (byte >= 0x61 && byte <= 0x7a) ||
58
+ (byte >= 0x30 && byte <= 0x39) ||
59
+ byte === 0x5f;
60
+ if (isWord) {
61
+ const lowered = byte >= 0x41 && byte <= 0x5a ? byte + 32 : byte;
62
+ out += String.fromCharCode(lowered);
63
+ inSep = false;
64
+ }
65
+ else if (!inSep) {
66
+ out += ' ';
67
+ inSep = true;
68
+ }
69
+ }
70
+ if (!out.endsWith(' '))
71
+ out += ' ';
72
+ return out;
73
+ }
74
+ export function summarize(input) {
75
+ const data = input.subarray(0, CAP);
76
+ const severity = { error: 0, warn: 0, info: 0, debug: 0, unknown: 0 };
77
+ const category = { timeout: 0, connection: 0, auth: 0, other: 0 };
78
+ let start = 0;
79
+ for (let i = 0; i < data.length; i++) {
80
+ if (data[i] !== 0x0a)
81
+ continue;
82
+ const rec = normalizeAsciiRecord(data.subarray(start, i));
83
+ start = i + 1;
84
+ const tokens = rec.trim().split(' ').filter((t) => t !== '');
85
+ let level = recordLevel(tokens);
86
+ if (level === '' && SIGNATURE_RE.test(rec))
87
+ level = 'error';
88
+ const sevKey = level === '' ? 'unknown' : level;
89
+ severity[sevKey] = (severity[sevKey] ?? 0) + 1;
90
+ if (TIMEOUT_RE.test(rec))
91
+ category.timeout += 1;
92
+ else if (CONNECTION_RE.test(rec))
93
+ category.connection += 1;
94
+ else if (AUTH_RE.test(rec))
95
+ category.auth += 1;
96
+ else
97
+ category.other += 1;
98
+ }
99
+ const cap = data.length === CAP;
100
+ const partial = start < data.length;
101
+ const sevLine = Object.entries(severity).map(([k, v]) => `${k}=${v}`).join(' ');
102
+ const catLine = Object.entries(category).map(([k, v]) => `${k}=${v}`).join(' ');
103
+ const text = `severity ${sevLine}\n` +
104
+ `category ${catLine}\n` +
105
+ `input cap=${cap ? 'yes' : 'no'} partial=${partial ? 'yes' : 'no'}\n`;
106
+ const status = cap ? 3 : partial ? 4 : 0;
107
+ return { text, status };
108
+ }
109
+ export function numericFields(fields) {
110
+ const out = {};
111
+ for (const field of fields) {
112
+ const eq = field.indexOf('=');
113
+ if (eq === -1)
114
+ continue;
115
+ out[field.slice(0, eq)] = Number.parseInt(field.slice(eq + 1), 10);
116
+ }
117
+ return out;
118
+ }
119
+ export function noEvidence() {
120
+ return { status: 'not_observed', message: 'No detailed evidence observed.', events: [] };
121
+ }
@@ -0,0 +1,14 @@
1
+ export interface CommandResult {
2
+ readonly code: number;
3
+ readonly stdout: string;
4
+ readonly stderr: string;
5
+ }
6
+ export declare function runCommand(command: readonly string[], options?: {
7
+ readonly cwd?: string;
8
+ readonly input?: string;
9
+ readonly timeoutMs?: number;
10
+ }): CommandResult;
11
+ export declare function parseEnvCommand(name: string): string[] | null;
12
+ export declare function parseCommandOverride(name: string, fallback: string): string[];
13
+ /** Match Python urllib.parse.quote(value, safe='') for GitHub REST path segments. */
14
+ export declare function percentEncodeAll(value: string): string;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * LAYER: Application
3
+ * Contains: Shared subprocess and encoding helpers for Wave 3 CLI ports.
4
+ * Rules: Never invoke commands through a shell; resolve Windows batch wrappers safely.
5
+ * BigO: O(n) score:4
6
+ * keywords: [ProcessRunner, SubprocessSpec, PercentEncode]
7
+ * GOAL: Provide consistent command execution and RFC 3986 percent-encoding across Wave 3 ports.
8
+ */
9
+ import { spawnSync } from 'node:child_process';
10
+ export function runCommand(command, options = {}) {
11
+ const [executable, ...args] = command;
12
+ if (!executable) {
13
+ throw new Error('Command executable is missing.');
14
+ }
15
+ const useCmdWrapper = process.platform === 'win32' && /\.(?:cmd|bat)$/i.test(executable);
16
+ const bin = useCmdWrapper ? (process.env.ComSpec ?? 'cmd.exe') : executable;
17
+ const argv = useCmdWrapper ? ['/d', '/c', executable, ...args] : args;
18
+ const result = spawnSync(bin, argv, {
19
+ cwd: options.cwd,
20
+ input: options.input,
21
+ encoding: 'utf8',
22
+ timeout: options.timeoutMs,
23
+ maxBuffer: 32 * 1024 * 1024,
24
+ windowsHide: true,
25
+ });
26
+ if (result.error) {
27
+ const err = result.error;
28
+ if (err.code === 'ETIMEDOUT') {
29
+ const timeoutErr = new Error('ETIMEDOUT');
30
+ timeoutErr.code = 'ETIMEDOUT';
31
+ throw timeoutErr;
32
+ }
33
+ throw result.error;
34
+ }
35
+ return {
36
+ code: result.status ?? 1,
37
+ stdout: result.stdout ?? '',
38
+ stderr: (result.stderr ?? '').trim(),
39
+ };
40
+ }
41
+ export function parseEnvCommand(name) {
42
+ const raw = (process.env[name] ?? '').trim();
43
+ if (!raw)
44
+ return null;
45
+ let parsed;
46
+ try {
47
+ parsed = JSON.parse(raw);
48
+ }
49
+ catch {
50
+ throw new Error(`${name} must be a JSON array of strings, e.g. ["claude", "-p"].`);
51
+ }
52
+ if (!Array.isArray(parsed) || parsed.length === 0 || !parsed.every((item) => typeof item === 'string')) {
53
+ throw new Error(`${name} must be a JSON array of strings, e.g. ["claude", "-p"].`);
54
+ }
55
+ return parsed;
56
+ }
57
+ export function parseCommandOverride(name, fallback) {
58
+ const raw = (process.env[name] ?? '').trim();
59
+ if (!raw)
60
+ return [fallback];
61
+ if (raw.startsWith('[')) {
62
+ const parsed = JSON.parse(raw);
63
+ if (Array.isArray(parsed) && parsed.length > 0 && parsed.every((item) => typeof item === 'string')) {
64
+ return parsed;
65
+ }
66
+ }
67
+ return [raw];
68
+ }
69
+ /** Match Python urllib.parse.quote(value, safe='') for GitHub REST path segments. */
70
+ export function percentEncodeAll(value) {
71
+ const bytes = Buffer.from(value, 'utf8');
72
+ let out = '';
73
+ for (const byte of bytes) {
74
+ const isUnreserved = (byte >= 0x41 && byte <= 0x5a) || // A-Z
75
+ (byte >= 0x61 && byte <= 0x7a) || // a-z
76
+ (byte >= 0x30 && byte <= 0x39) || // 0-9
77
+ byte === 0x5f || // _
78
+ byte === 0x2e || // .
79
+ byte === 0x2d || // -
80
+ byte === 0x7e; // ~
81
+ out += isUnreserved ? String.fromCharCode(byte) : `%${byte.toString(16).toUpperCase().padStart(2, '0')}`;
82
+ }
83
+ return out;
84
+ }
@@ -0,0 +1,14 @@
1
+ export interface ExecResult {
2
+ readonly code: number;
3
+ readonly stdout: Buffer;
4
+ readonly stderr: Buffer;
5
+ readonly error?: Error;
6
+ }
7
+ export declare function decodeUtf8Strict(bytes: Uint8Array): string | null;
8
+ export declare function whichCommand(command: string, pathEnv?: string | undefined): string | null;
9
+ export declare function splitCommandWords(raw: string): string[];
10
+ export declare function runExecutable(argv: readonly string[], options?: {
11
+ readonly cwd?: string;
12
+ readonly env?: NodeJS.ProcessEnv;
13
+ readonly timeoutMs?: number;
14
+ }): ExecResult;