vouchington-tooling 0.58.0 → 0.60.0
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/README.md +80 -0
- package/dist/agent-issue-labels/ensure-labels.d.mts +1 -1
- package/dist/agent-issue-labels/ensure-labels.mjs +1 -1
- package/dist/browser-session-runner/tail-queue.d.mts +1 -1
- package/dist/browser-session-runner/tail-queue.mjs +1 -1
- package/dist/cli/commands/gitleaks-directory-scan.d.mts +4 -0
- package/dist/cli/commands/gitleaks-directory-scan.mjs +9 -0
- package/dist/cli/commands/hook.d.mts +2 -0
- package/dist/cli/commands/hook.mjs +19 -0
- package/dist/cli/commands/transient-retry.d.mts +13 -0
- package/dist/cli/commands/transient-retry.mjs +68 -0
- package/dist/cli/index.mjs +14 -53
- package/dist/cli/parse-forwarded-commands.d.mts +12 -0
- package/dist/cli/parse-forwarded-commands.mjs +8 -0
- package/dist/cli/parse.d.mts +12 -0
- package/dist/cli/script-paths.d.mts +5 -0
- package/dist/cli/script-paths.mjs +48 -0
- package/dist/cli/usage-text.d.mts +1 -0
- package/dist/cli/usage-text.mjs +170 -0
- package/dist/cli/usage.d.mts +2 -1
- package/dist/cli/usage.mjs +2 -149
- package/dist/command-policy/engine.d.mts +7 -0
- package/dist/command-policy/engine.mjs +58 -0
- package/dist/command-policy/git-patterns.d.mts +20 -0
- package/dist/command-policy/git-patterns.mjs +82 -0
- package/dist/command-policy/git-process.d.mts +4 -0
- package/dist/command-policy/git-process.mjs +54 -0
- package/dist/command-policy/github-checkout-owners.d.mts +22 -0
- package/dist/command-policy/github-checkout-owners.mjs +122 -0
- package/dist/command-policy/github-command-context.d.mts +6 -0
- package/dist/command-policy/github-command-context.mjs +19 -0
- package/dist/command-policy/github-command-cwd.d.mts +8 -0
- package/dist/command-policy/github-command-cwd.mjs +130 -0
- package/dist/command-policy/github-command-position.d.mts +7 -0
- package/dist/command-policy/github-command-position.mjs +12 -0
- package/dist/command-policy/github-configured-base.d.mts +25 -0
- package/dist/command-policy/github-configured-base.mjs +59 -0
- package/dist/command-policy/github-invocation.d.mts +9 -0
- package/dist/command-policy/github-invocation.mjs +80 -0
- package/dist/command-policy/github-merge-authority.d.mts +21 -0
- package/dist/command-policy/github-merge-authority.mjs +86 -0
- package/dist/command-policy/github-option-flags.d.mts +3 -0
- package/dist/command-policy/github-option-flags.mjs +67 -0
- package/dist/command-policy/github-options.d.mts +12 -0
- package/dist/command-policy/github-options.mjs +73 -0
- package/dist/command-policy/github-stack-workflow.d.mts +9 -0
- package/dist/command-policy/github-stack-workflow.mjs +94 -0
- package/dist/command-policy/github-workflow.d.mts +7 -0
- package/dist/command-policy/github-workflow.mjs +50 -0
- package/dist/command-policy/hook/args.d.mts +11 -0
- package/dist/command-policy/hook/args.mjs +49 -0
- package/dist/command-policy/hook/harness.d.mts +26 -0
- package/dist/command-policy/hook/harness.mjs +119 -0
- package/dist/command-policy/hook/policy-module.d.mts +7 -0
- package/dist/command-policy/hook/policy-module.mjs +48 -0
- package/dist/command-policy/hook/post-tool-use.d.mts +9 -0
- package/dist/command-policy/hook/post-tool-use.mjs +51 -0
- package/dist/command-policy/hook/pre-tool-use.d.mts +21 -0
- package/dist/command-policy/hook/pre-tool-use.mjs +45 -0
- package/dist/command-policy/hook/run.d.mts +17 -0
- package/dist/command-policy/hook/run.mjs +69 -0
- package/dist/command-policy/hook/types.d.mts +33 -0
- package/dist/command-policy/hook/types.mjs +5 -0
- package/dist/command-policy/index.d.mts +29 -0
- package/dist/command-policy/index.mjs +23 -0
- package/dist/command-policy/path-references.d.mts +14 -0
- package/dist/command-policy/path-references.mjs +68 -0
- package/dist/command-policy/path-rules.d.mts +11 -0
- package/dist/command-policy/path-rules.mjs +37 -0
- package/dist/command-policy/payload.d.mts +8 -0
- package/dist/command-policy/payload.mjs +54 -0
- package/dist/command-policy/types.d.mts +77 -0
- package/dist/command-policy/types.mjs +1 -0
- package/dist/dead-code/baseline.d.mts +19 -0
- package/dist/dead-code/baseline.mjs +124 -0
- package/dist/dead-code/child-command.d.mts +6 -0
- package/dist/dead-code/child-command.mjs +107 -0
- package/dist/dead-code/cli.d.mts +5 -0
- package/dist/dead-code/cli.mjs +71 -0
- package/dist/dead-code/entry-roots.d.mts +7 -0
- package/dist/dead-code/entry-roots.mjs +43 -0
- package/dist/dead-code/fixture-deadline.test-helpers.d.mts +1 -0
- package/dist/dead-code/fixture-deadline.test-helpers.mjs +9 -0
- package/dist/dead-code/gate.d.mts +29 -0
- package/dist/dead-code/gate.mjs +33 -0
- package/dist/dead-code/gate.test-helpers.d.mts +14 -0
- package/dist/dead-code/gate.test-helpers.mjs +35 -0
- package/dist/dead-code/index.d.mts +9 -0
- package/dist/dead-code/index.mjs +7 -0
- package/dist/dead-code/scan.d.mts +11 -0
- package/dist/dead-code/scan.mjs +37 -0
- package/dist/dead-code/tracked-snapshot.d.mts +2 -0
- package/dist/dead-code/tracked-snapshot.mjs +72 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/markdown/details-scope.d.mts +1 -1
- package/dist/markdown/details-scope.mjs +1 -1
- package/dist/tmux/cli-shared.d.mts +18 -0
- package/dist/tmux/cli-shared.mjs +8 -0
- package/dist/tmux/cli.d.mts +3 -0
- package/dist/tmux/cli.mjs +34 -0
- package/dist/tmux/config.d.mts +24 -0
- package/dist/tmux/config.mjs +91 -0
- package/dist/tmux/fake-tmux.test-helpers.d.mts +46 -0
- package/dist/tmux/fake-tmux.test-helpers.mjs +105 -0
- package/dist/tmux/hook-payload.d.mts +8 -0
- package/dist/tmux/hook-payload.mjs +39 -0
- package/dist/tmux/index.d.mts +9 -0
- package/dist/tmux/index.mjs +7 -0
- package/dist/tmux/launcher.d.mts +11 -0
- package/dist/tmux/launcher.mjs +127 -0
- package/dist/tmux/reminder-post-tool.d.mts +21 -0
- package/dist/tmux/reminder-post-tool.mjs +88 -0
- package/dist/tmux/runner.d.mts +11 -0
- package/dist/tmux/runner.mjs +26 -0
- package/dist/tmux/session-name.d.mts +5 -0
- package/dist/tmux/session-name.mjs +10 -0
- package/dist/tmux/shell-quote.d.mts +9 -0
- package/dist/tmux/shell-quote.mjs +16 -0
- package/dist/tmux/up.d.mts +2 -0
- package/dist/tmux/up.mjs +73 -0
- package/dist/tmux/windows.d.mts +18 -0
- package/dist/tmux/windows.mjs +50 -0
- package/dist/transient-retry/attempts.d.mts +1 -1
- package/dist/transient-retry/attempts.mjs +1 -1
- package/dist/transient-retry/decision-evaluator.d.mts +3 -3
- package/dist/transient-retry/gh-api.d.mts +30 -0
- package/dist/transient-retry/gh-api.mjs +68 -0
- package/dist/transient-retry/github-actions-log.d.mts +7 -0
- package/dist/transient-retry/github-actions-log.mjs +33 -0
- package/dist/transient-retry/index.d.mts +15 -0
- package/dist/transient-retry/index.mjs +8 -0
- package/dist/transient-retry/log-stream.d.mts +12 -0
- package/dist/transient-retry/log-stream.mjs +39 -0
- package/dist/transient-retry/log-window.d.mts +18 -0
- package/dist/transient-retry/log-window.mjs +94 -0
- package/dist/transient-retry/rerun.d.mts +23 -0
- package/dist/transient-retry/rerun.mjs +68 -0
- package/dist/transient-retry/run-context-annotations.d.mts +7 -0
- package/dist/transient-retry/run-context-annotations.mjs +44 -0
- package/dist/transient-retry/run-context-jobs.d.mts +20 -0
- package/dist/transient-retry/run-context-jobs.mjs +54 -0
- package/dist/transient-retry/run-context-logs.d.mts +12 -0
- package/dist/transient-retry/run-context-logs.mjs +86 -0
- package/dist/transient-retry/run-context-rule-attempts.d.mts +14 -0
- package/dist/transient-retry/run-context-rule-attempts.mjs +65 -0
- package/dist/transient-retry/run-context-types.d.mts +49 -0
- package/dist/transient-retry/run-context-types.mjs +3 -0
- package/dist/transient-retry/run-context.d.mts +9 -0
- package/dist/transient-retry/run-context.mjs +25 -0
- package/dist/transient-retry/run-context.test-helpers.d.mts +16 -0
- package/dist/transient-retry/run-context.test-helpers.mjs +56 -0
- package/dist/transient-retry/types.d.mts +8 -7
- package/dist/vitest-diagnostics/vitest-worker-exit-diagnostics-reporter.mjs +1 -1
- package/dist/workflow-secrets-drift/gh.d.mts +1 -1
- package/dist/workflow-secrets-drift/gh.mjs +1 -1
- package/package.json +16 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
- package/scripts/tmux/tmux-agent-reminder.sh +68 -0
- package/scripts/tmux/tmux-name.sh +34 -0
- package/scripts/tmux/tmux-read-title.sh +13 -0
- package/scripts/tmux/tmux-target.sh +130 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { packageScriptPath } from "../cli/script-path.mjs";
|
|
3
|
+
import { extractToolCommand, hookToolName, toolExitCode, } from "./hook-payload.mjs";
|
|
4
|
+
const PR_CREATE_COMMAND_PATTERN = /(^|[;&|])\s*gh\s+pr\s+create(\s|$)/;
|
|
5
|
+
const GIT_PUSH_COMMAND_PATTERN = /(^|[;&|])\s*git\s+push(\s|$)/;
|
|
6
|
+
const RESET_WORKTREE_PATTERN = /(^|[;&|])\s*(?:\S*\/)?reset-worktree(?:\.sh)?(?:\s+(--help|-h))?(?=[;&|]|\s|$)/g;
|
|
7
|
+
const SHELL_TOOLS = new Set(['Bash', 'Shell', 'run_terminal_command']);
|
|
8
|
+
const PR_SUFFIX_PATTERN = /-pr\d+$/;
|
|
9
|
+
const transientSpawnCodes = new Set(['EAGAIN', 'EBUSY', 'EINTR', 'EMFILE', 'ENFILE', 'ETXTBSY']);
|
|
10
|
+
const transientStderrPattern = /\b(?:EAGAIN|EBUSY|EINTR|EMFILE|ENFILE|ETXTBSY)\b|resource temporarily unavailable|device or resource busy|interrupted system call|too many open files|text file busy/i;
|
|
11
|
+
const spawnAttempts = 3;
|
|
12
|
+
function spawnReadTitle(command, args, env) {
|
|
13
|
+
// Diagnostics are matched below, so request stable English errno text for this helper only.
|
|
14
|
+
const result = spawnSync(command, [...args], { encoding: 'utf8', env: { ...env, LC_ALL: 'C' } });
|
|
15
|
+
return {
|
|
16
|
+
error: result.error,
|
|
17
|
+
status: result.status,
|
|
18
|
+
stdout: result.stdout,
|
|
19
|
+
stderr: result.stderr,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function paneTitle(env, spawn) {
|
|
23
|
+
// The script validates the socket, pane, and worktree before reading, so a failed
|
|
24
|
+
// lookup is not an empty pane title.
|
|
25
|
+
const script = packageScriptPath('scripts/tmux/tmux-read-title.sh');
|
|
26
|
+
for (let attempt = 0; attempt < spawnAttempts; attempt += 1) {
|
|
27
|
+
const result = spawn('bash', [script], env);
|
|
28
|
+
if (result.status === 0)
|
|
29
|
+
return result.stdout.trim();
|
|
30
|
+
const code = result.error?.code;
|
|
31
|
+
const retryableSpawn = typeof code === 'string' && transientSpawnCodes.has(code);
|
|
32
|
+
if (!retryableSpawn && !transientStderrPattern.test(result.stderr ?? ''))
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
// Scans every reset-worktree invocation separately: a compound command like
|
|
38
|
+
// `reset-worktree --help; reset-worktree --force` still runs a real reset.
|
|
39
|
+
function hasNonHelpResetInvocation(command) {
|
|
40
|
+
const pattern = new RegExp(RESET_WORKTREE_PATTERN.source, 'g');
|
|
41
|
+
for (let match = pattern.exec(command); match !== null; match = pattern.exec(command)) {
|
|
42
|
+
if (match[2] === undefined)
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Remind the agent to (re)name its tmux window at the checkpoints a post-tool payload can
|
|
49
|
+
* detect: a plan was accepted, a PR was created, a push landed without a `-pr<N>` title suffix,
|
|
50
|
+
* or reset-worktree left a stale title. Silent (`null`) without a verified pane and for every
|
|
51
|
+
* other tool call. The pane is read only after a checkpoint matches.
|
|
52
|
+
*/
|
|
53
|
+
export function renderPostToolReminder(payload, options = {}) {
|
|
54
|
+
const env = { ...(options.env ?? process.env) };
|
|
55
|
+
const spawn = options.spawnPaneTitle ?? spawnReadTitle;
|
|
56
|
+
const name = options.nameCommand ?? env.TMUX_NAME_COMMAND ?? 'vouchington tmux name';
|
|
57
|
+
const hint = '(dangerouslyDisableSandbox: true)';
|
|
58
|
+
const toolName = hookToolName(payload);
|
|
59
|
+
if (toolName === 'ExitPlanMode') {
|
|
60
|
+
if (paneTitle(env, spawn) === null)
|
|
61
|
+
return null;
|
|
62
|
+
return `[tmux-window-name] Plan accepted — refine window name if scope shifted. ${name} <name> ${hint}`;
|
|
63
|
+
}
|
|
64
|
+
if (!SHELL_TOOLS.has(toolName))
|
|
65
|
+
return null;
|
|
66
|
+
const command = extractToolCommand(payload);
|
|
67
|
+
const exitCode = toolExitCode(payload);
|
|
68
|
+
if (command === '' || (exitCode !== undefined && exitCode !== 0))
|
|
69
|
+
return null;
|
|
70
|
+
if (PR_CREATE_COMMAND_PATTERN.test(command)) {
|
|
71
|
+
if (paneTitle(env, spawn) === null)
|
|
72
|
+
return null;
|
|
73
|
+
return `[tmux-window-name] PR created — add the -pr<N> suffix: ${name} <feature-pr123> ${hint}`;
|
|
74
|
+
}
|
|
75
|
+
if (GIT_PUSH_COMMAND_PATTERN.test(command)) {
|
|
76
|
+
const title = paneTitle(env, spawn);
|
|
77
|
+
if (title === null || PR_SUFFIX_PATTERN.test(title))
|
|
78
|
+
return null;
|
|
79
|
+
return `[tmux-window-name] git push on PR branch — confirm -pr<N> suffix is set: ${name} <feature-pr123> ${hint}`;
|
|
80
|
+
}
|
|
81
|
+
if (hasNonHelpResetInvocation(command)) {
|
|
82
|
+
const title = paneTitle(env, spawn);
|
|
83
|
+
if (title === null || title === '')
|
|
84
|
+
return null;
|
|
85
|
+
return `[tmux-window-name] reset-worktree ran — pane title should be empty. ${name} "" ${hint}`;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type TmuxResult = {
|
|
2
|
+
status: number | null;
|
|
3
|
+
stdout: string;
|
|
4
|
+
};
|
|
5
|
+
/** Runs one tmux command. `inherit` hands the terminal to tmux (attach). */
|
|
6
|
+
export type TmuxRun = (args: readonly string[], inherit?: boolean) => TmuxResult;
|
|
7
|
+
export declare function createTmuxRun(bin: string): TmuxRun;
|
|
8
|
+
/** True when the process has any child process (the window's command is running). */
|
|
9
|
+
export declare function pgrepHasChildren(pid: string): boolean;
|
|
10
|
+
export declare function isPidAlive(pid: number): boolean;
|
|
11
|
+
export declare function sleepMs(milliseconds: number): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
export function createTmuxRun(bin) {
|
|
3
|
+
return (args, inherit = false) => {
|
|
4
|
+
const result = spawnSync(bin, [...args], {
|
|
5
|
+
encoding: 'utf8',
|
|
6
|
+
stdio: inherit ? 'inherit' : ['ignore', 'pipe', 'ignore'],
|
|
7
|
+
});
|
|
8
|
+
return { status: result.error ? null : result.status, stdout: result.stdout ?? '' };
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** True when the process has any child process (the window's command is running). */
|
|
12
|
+
export function pgrepHasChildren(pid) {
|
|
13
|
+
return spawnSync('pgrep', ['-P', pid, '.'], { stdio: 'ignore' }).status === 0;
|
|
14
|
+
}
|
|
15
|
+
export function isPidAlive(pid) {
|
|
16
|
+
try {
|
|
17
|
+
process.kill(pid, 0);
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return error.code === 'EPERM';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function sleepMs(milliseconds) {
|
|
25
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
/**
|
|
4
|
+
* Session names are the configured prefix plus a hash of the physical worktree
|
|
5
|
+
* path, so same-basename worktrees never share a session.
|
|
6
|
+
*/
|
|
7
|
+
export function tmuxSessionName(prefix, root) {
|
|
8
|
+
const physical = realpathSync(root);
|
|
9
|
+
return `${prefix}d${createHash('sha256').update(physical).digest('hex').slice(0, 12)}`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TmuxSessionConfig, TmuxWindowConfig } from './config.mts';
|
|
2
|
+
export declare function quoteShellArg(value: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* The shell command tmux runs in a window: `bash -lc` with one quoted body that first exports
|
|
5
|
+
* the extra, shared, then per-window environment and then runs the command. Exporting inside
|
|
6
|
+
* the body (rather than prefixing `bash`) keeps a configured PATH from hiding `bash` itself and
|
|
7
|
+
* lets the configured values win over login-profile defaults.
|
|
8
|
+
*/
|
|
9
|
+
export declare function windowCommand(config: TmuxSessionConfig, window: TmuxWindowConfig, extraEnv?: Readonly<Record<string, string>>): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function quoteShellArg(value) {
|
|
2
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* The shell command tmux runs in a window: `bash -lc` with one quoted body that first exports
|
|
6
|
+
* the extra, shared, then per-window environment and then runs the command. Exporting inside
|
|
7
|
+
* the body (rather than prefixing `bash`) keeps a configured PATH from hiding `bash` itself and
|
|
8
|
+
* lets the configured values win over login-profile defaults.
|
|
9
|
+
*/
|
|
10
|
+
export function windowCommand(config, window, extraEnv = {}) {
|
|
11
|
+
const exports = Object.entries({ ...extraEnv, ...config.env, ...window.env })
|
|
12
|
+
.map(([key, value]) => `export ${key}=${quoteShellArg(value)}; `)
|
|
13
|
+
.join('');
|
|
14
|
+
const body = `${exports}${window.command}${window.keepOpen ? '; read' : ''}`;
|
|
15
|
+
return `bash -lc ${quoteShellArg(body)}`;
|
|
16
|
+
}
|
package/dist/tmux/up.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { TMUX_USAGE } from "./cli-shared.mjs";
|
|
3
|
+
import { loadTmuxConfig } from "./config.mjs";
|
|
4
|
+
import { launchSession } from "./launcher.mjs";
|
|
5
|
+
import { createTmuxRun, isPidAlive, pgrepHasChildren, sleepMs } from "./runner.mjs";
|
|
6
|
+
import { tmuxSessionName } from "./session-name.mjs";
|
|
7
|
+
function parseUp(args) {
|
|
8
|
+
const flags = { noAttach: false, verbose: false };
|
|
9
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
10
|
+
const arg = args[index];
|
|
11
|
+
if (arg === '--no-attach' || arg === '--verbose' || arg === '-v') {
|
|
12
|
+
const key = arg === '--no-attach' ? 'noAttach' : 'verbose';
|
|
13
|
+
if (flags[key])
|
|
14
|
+
return `duplicate option: ${arg}`;
|
|
15
|
+
flags[key] = true;
|
|
16
|
+
}
|
|
17
|
+
else if (arg === '--config' || arg === '--root') {
|
|
18
|
+
const value = args[index + 1];
|
|
19
|
+
if (value === undefined || value === '')
|
|
20
|
+
return `missing value for ${arg}`;
|
|
21
|
+
flags[arg === '--config' ? 'config' : 'root'] = value;
|
|
22
|
+
index += 1;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return `unknown option: ${arg}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return flags.config === undefined ? '--config is required' : flags;
|
|
29
|
+
}
|
|
30
|
+
export function runUp(args, deps) {
|
|
31
|
+
const err = deps.err ?? ((text) => void process.stderr.write(text));
|
|
32
|
+
const env = deps.env ?? process.env;
|
|
33
|
+
const flags = parseUp(args);
|
|
34
|
+
if (typeof flags === 'string') {
|
|
35
|
+
err(`vouchington: ${flags}\n${TMUX_USAGE}`);
|
|
36
|
+
return 2;
|
|
37
|
+
}
|
|
38
|
+
const tmux = deps.tmux ?? createTmuxRun(env.TMUX_TARGET_BIN || 'tmux');
|
|
39
|
+
if (tmux(['-V']).status !== 0) {
|
|
40
|
+
err('Error: tmux is not installed.\n');
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
if (env.TMUX && !flags.noAttach) {
|
|
44
|
+
err('Error: run this outside tmux. Pass --no-attach to start services without attaching.\n');
|
|
45
|
+
return 1;
|
|
46
|
+
}
|
|
47
|
+
const cwd = deps.cwd ?? process.cwd();
|
|
48
|
+
const root = resolve(cwd, flags.root ?? env.TMUX_TARGET_ROOT ?? '.');
|
|
49
|
+
try {
|
|
50
|
+
const config = loadTmuxConfig(resolve(cwd, flags.config));
|
|
51
|
+
const context = {
|
|
52
|
+
config,
|
|
53
|
+
root,
|
|
54
|
+
session: tmuxSessionName(config.sessionPrefix, root),
|
|
55
|
+
extraEnv: { TMUX_LOG_LEVEL: flags.verbose ? 'info' : 'error' },
|
|
56
|
+
tmux,
|
|
57
|
+
hasChildren: deps.hasChildren ?? pgrepHasChildren,
|
|
58
|
+
out: deps.out ?? ((text) => void process.stdout.write(text)),
|
|
59
|
+
err,
|
|
60
|
+
};
|
|
61
|
+
const sleep = deps.sleep ?? sleepMs;
|
|
62
|
+
return launchSession(context, {
|
|
63
|
+
noAttach: flags.noAttach,
|
|
64
|
+
pid: deps.pid ?? process.pid,
|
|
65
|
+
sleep,
|
|
66
|
+
isPidAlive: deps.isPidAlive ?? isPidAlive,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
err(`vouchington: ${error.message}\n`);
|
|
71
|
+
return 2;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TmuxSessionConfig, TmuxWindowConfig } from './config.mts';
|
|
2
|
+
import type { TmuxRun } from './runner.mts';
|
|
3
|
+
export type SessionContext = {
|
|
4
|
+
config: TmuxSessionConfig;
|
|
5
|
+
root: string;
|
|
6
|
+
session: string;
|
|
7
|
+
/** Variables injected into every window, e.g. the log level. */
|
|
8
|
+
extraEnv: Record<string, string>;
|
|
9
|
+
tmux: TmuxRun;
|
|
10
|
+
hasChildren: (pid: string) => boolean;
|
|
11
|
+
out: (text: string) => void;
|
|
12
|
+
err: (text: string) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function windowCwd(context: SessionContext, window: TmuxWindowConfig): string;
|
|
15
|
+
export declare function commandFor(context: SessionContext, window: TmuxWindowConfig): string;
|
|
16
|
+
export declare function decorateWindow(context: SessionContext, name: string): boolean;
|
|
17
|
+
/** Respawn dead windows (or recreate missing ones). False when any step fails. */
|
|
18
|
+
export declare function restoreDeadWindows(context: SessionContext): boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { windowCommand } from "./shell-quote.mjs";
|
|
3
|
+
export function windowCwd(context, window) {
|
|
4
|
+
return resolve(context.root, window.cwd ?? '.');
|
|
5
|
+
}
|
|
6
|
+
export function commandFor(context, window) {
|
|
7
|
+
return windowCommand(context.config, window, context.extraEnv);
|
|
8
|
+
}
|
|
9
|
+
function windowExists(context, name) {
|
|
10
|
+
const result = context.tmux(['list-windows', '-t', `=${context.session}`, '-F', '#{window_name}']);
|
|
11
|
+
return result.stdout.split('\n').includes(name);
|
|
12
|
+
}
|
|
13
|
+
// A keep-open pane leaves its shell running after the command ends, so only a child process
|
|
14
|
+
// proves the command is alive. Without keepOpen the pane closes with the command, and bash may
|
|
15
|
+
// exec it directly (no child), so the window existing is the liveness signal.
|
|
16
|
+
function windowIsLive(context, window) {
|
|
17
|
+
const name = window.name;
|
|
18
|
+
if (!windowExists(context, name))
|
|
19
|
+
return false;
|
|
20
|
+
if (!window.keepOpen)
|
|
21
|
+
return true;
|
|
22
|
+
const result = context.tmux([
|
|
23
|
+
'list-panes',
|
|
24
|
+
'-t',
|
|
25
|
+
`=${context.session}:${name}`,
|
|
26
|
+
'-F',
|
|
27
|
+
'#{pane_pid}',
|
|
28
|
+
]);
|
|
29
|
+
return result.stdout.split('\n').some((pid) => /^[0-9]+$/.test(pid) && context.hasChildren(pid));
|
|
30
|
+
}
|
|
31
|
+
export function decorateWindow(context, name) {
|
|
32
|
+
const target = `=${context.session}:${name}`;
|
|
33
|
+
return (context.tmux(['select-pane', '-T', name, '-t', target]).status === 0 &&
|
|
34
|
+
context.tmux(['set-option', '-w', '-t', target, 'pane-border-status', 'top']).status === 0);
|
|
35
|
+
}
|
|
36
|
+
/** Respawn dead windows (or recreate missing ones). False when any step fails. */
|
|
37
|
+
export function restoreDeadWindows(context) {
|
|
38
|
+
for (const window of context.config.windows) {
|
|
39
|
+
if (windowIsLive(context, window))
|
|
40
|
+
continue;
|
|
41
|
+
const base = ['-c', windowCwd(context, window), commandFor(context, window)];
|
|
42
|
+
const target = `=${context.session}`;
|
|
43
|
+
const args = windowExists(context, window.name)
|
|
44
|
+
? ['respawn-pane', '-k', '-t', `${target}:${window.name}`, ...base]
|
|
45
|
+
: ['new-window', '-d', '-t', target, '-n', window.name, ...base];
|
|
46
|
+
if (context.tmux(args).status !== 0 || !decorateWindow(context, window.name))
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Normalizes a provider's attempt count when earlier attempts produced no targets.
|
|
3
|
-
*
|
|
3
|
+
* Fetching a provider's run state lives in `run-context*.mts`.
|
|
4
4
|
*/
|
|
5
5
|
export declare function deriveRetryAttempt(runAttempt: number, priorTargetCounts: readonly number[]): number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Normalizes a provider's attempt count when earlier attempts produced no targets.
|
|
3
|
-
*
|
|
3
|
+
* Fetching a provider's run state lives in `run-context*.mts`.
|
|
4
4
|
*/
|
|
5
5
|
export function deriveRetryAttempt(runAttempt, priorTargetCounts) {
|
|
6
6
|
const emptyPriorAttempts = priorTargetCounts.filter((count) => count === 0).length;
|
|
@@ -12,9 +12,9 @@ export type DecisionResult = {
|
|
|
12
12
|
matchedRule: string;
|
|
13
13
|
reason: NoMatchReason;
|
|
14
14
|
};
|
|
15
|
-
export interface EvaluateRulesOptions {
|
|
16
|
-
afterRuleEvaluated?: (context:
|
|
15
|
+
export interface EvaluateRulesOptions<C extends RetryContext = RetryContext> {
|
|
16
|
+
afterRuleEvaluated?: (context: C, rule: RetryRule<C>) => Promise<void> | void;
|
|
17
17
|
/** Defaults to `no-match`. Use `dispatch` when unmatched work should leave the retry engine. */
|
|
18
18
|
unmatchedDecision?: 'no-match' | 'dispatch';
|
|
19
19
|
}
|
|
20
|
-
export declare function decide(context:
|
|
20
|
+
export declare function decide<C extends RetryContext = RetryContext>(context: C, rules: readonly RetryRule<C>[], options?: EvaluateRulesOptions<C>): Promise<DecisionResult>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type RunTextCommand } from '../gh-cli/exec.mts';
|
|
2
|
+
/** Substrings of a failed `gh` call that mark a transport hiccup worth retrying. */
|
|
3
|
+
export declare const DEFAULT_RETRYABLE_MARKERS: readonly string[];
|
|
4
|
+
/** The largest stdout one buffered `gh api` call may return; job logs are streamed, not buffered. */
|
|
5
|
+
export declare const API_MAX_BUFFER_BYTES: number;
|
|
6
|
+
export interface GhApiOptions {
|
|
7
|
+
/** Runs `gh` with the given argv and returns stdout. Defaults to {@link createGhRunner}. */
|
|
8
|
+
run?: RunTextCommand;
|
|
9
|
+
attempts?: number;
|
|
10
|
+
retryableMarkers?: readonly string[];
|
|
11
|
+
sleep?: (ms: number) => Promise<void>;
|
|
12
|
+
warn?: (message: string) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface GhApi {
|
|
15
|
+
/** `gh api <args>` with bounded retries on transport errors. Resolves to stdout. */
|
|
16
|
+
call: (args: string[]) => Promise<string>;
|
|
17
|
+
isRetryable: (error: unknown) => boolean;
|
|
18
|
+
sleep: (ms: number) => Promise<void>;
|
|
19
|
+
/** Runs an arbitrary `gh` argv once, without retries. */
|
|
20
|
+
run: RunTextCommand;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds the default `gh` runner. `tokenEnv` names the environment variable that holds the
|
|
24
|
+
* token; when set and present it is passed to `gh` as `GH_TOKEN`. Otherwise `gh` uses its own
|
|
25
|
+
* credentials.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createGhRunner(tokenEnv?: string): RunTextCommand;
|
|
28
|
+
/** The `gh` child environment: forced color removed, and `tokenEnv`'s value exposed as `GH_TOKEN`. */
|
|
29
|
+
export declare function ghEnvWithToken(tokenEnv?: string): (env: NodeJS.ProcessEnv) => NodeJS.ProcessEnv;
|
|
30
|
+
export declare function createGhApi({ run, attempts, retryableMarkers, sleep, warn, }?: GhApiOptions): GhApi;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { setTimeout as sleepFor } from 'node:timers/promises';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
import { ghSpawnEnv } from "../gh-cli/env.mjs";
|
|
5
|
+
import { createCommandRunner } from "../gh-cli/exec.mjs";
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
/** Substrings of a failed `gh` call that mark a transport hiccup worth retrying. */
|
|
8
|
+
export const DEFAULT_RETRYABLE_MARKERS = [
|
|
9
|
+
'ECONNRESET',
|
|
10
|
+
'ETIMEDOUT',
|
|
11
|
+
'EAI_AGAIN',
|
|
12
|
+
'connection reset',
|
|
13
|
+
'TLS handshake timeout',
|
|
14
|
+
'unexpected EOF',
|
|
15
|
+
'HTTP 502',
|
|
16
|
+
'HTTP 503',
|
|
17
|
+
'HTTP 504',
|
|
18
|
+
];
|
|
19
|
+
/** The largest stdout one buffered `gh api` call may return; job logs are streamed, not buffered. */
|
|
20
|
+
export const API_MAX_BUFFER_BYTES = 16 * 1024 * 1024;
|
|
21
|
+
/**
|
|
22
|
+
* Builds the default `gh` runner. `tokenEnv` names the environment variable that holds the
|
|
23
|
+
* token; when set and present it is passed to `gh` as `GH_TOKEN`. Otherwise `gh` uses its own
|
|
24
|
+
* credentials.
|
|
25
|
+
*/
|
|
26
|
+
export function createGhRunner(tokenEnv) {
|
|
27
|
+
return createCommandRunner('gh', (command, args, options) => execFileAsync(command, args, {
|
|
28
|
+
...options,
|
|
29
|
+
encoding: 'utf8',
|
|
30
|
+
maxBuffer: API_MAX_BUFFER_BYTES,
|
|
31
|
+
}), ghEnvWithToken(tokenEnv));
|
|
32
|
+
}
|
|
33
|
+
/** The `gh` child environment: forced color removed, and `tokenEnv`'s value exposed as `GH_TOKEN`. */
|
|
34
|
+
export function ghEnvWithToken(tokenEnv) {
|
|
35
|
+
return (env) => {
|
|
36
|
+
const base = ghSpawnEnv(env);
|
|
37
|
+
const token = tokenEnv === undefined ? undefined : env[tokenEnv];
|
|
38
|
+
return token ? { ...base, GH_TOKEN: token } : base;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function errorText(error) {
|
|
42
|
+
const stderr = error?.stderr;
|
|
43
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
44
|
+
return typeof stderr === 'string' ? `${message}\n${stderr}` : message;
|
|
45
|
+
}
|
|
46
|
+
export function createGhApi({ run = createGhRunner(), attempts = 3, retryableMarkers = DEFAULT_RETRYABLE_MARKERS, sleep = (ms) => sleepFor(ms), warn = (message) => console.error(message), } = {}) {
|
|
47
|
+
if (!Number.isInteger(attempts) || attempts < 1) {
|
|
48
|
+
throw new Error(`Invalid gh api retry attempts: ${attempts}`);
|
|
49
|
+
}
|
|
50
|
+
const isRetryable = (error) => {
|
|
51
|
+
const text = errorText(error);
|
|
52
|
+
return retryableMarkers.some((marker) => text.includes(marker));
|
|
53
|
+
};
|
|
54
|
+
const call = async (args) => {
|
|
55
|
+
for (let attempt = 1;; attempt += 1) {
|
|
56
|
+
try {
|
|
57
|
+
return await run(['api', ...args]);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (attempt >= attempts || !isRetryable(error))
|
|
61
|
+
throw error;
|
|
62
|
+
warn(`::warning::gh api attempt ${attempt}/${attempts} failed; retrying`);
|
|
63
|
+
await sleep(attempt * 1000);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return { call, isRetryable, sleep, run };
|
|
68
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface GithubActionsStepGroupSlice {
|
|
2
|
+
header: string;
|
|
3
|
+
log: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function getGithubActionsStepGroupSlices(log: string): GithubActionsStepGroupSlice[];
|
|
6
|
+
export declare function sliceGithubActionsStepGroup(log: string, runGroup: string): string;
|
|
7
|
+
export declare function terminalFailedGithubActionsStepLog(log: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function findGithubActionsStepGroupStarts(log) {
|
|
2
|
+
return [...log.matchAll(/##\[group\]Run [^\n]*/g)].map((match) => match.index);
|
|
3
|
+
}
|
|
4
|
+
export function getGithubActionsStepGroupSlices(log) {
|
|
5
|
+
const starts = findGithubActionsStepGroupStarts(log);
|
|
6
|
+
return starts.map((start, index) => {
|
|
7
|
+
const end = starts[index + 1] ?? log.length;
|
|
8
|
+
const headerEnd = log.indexOf('\n', start);
|
|
9
|
+
return {
|
|
10
|
+
header: headerEnd === -1 ? log.slice(start, end) : log.slice(start, headerEnd),
|
|
11
|
+
log: log.slice(start, end),
|
|
12
|
+
};
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function sliceGithubActionsStepGroup(log, runGroup) {
|
|
16
|
+
const start = log.indexOf(runGroup);
|
|
17
|
+
if (start === -1)
|
|
18
|
+
return '';
|
|
19
|
+
const searchStart = start + runGroup.length;
|
|
20
|
+
const nextGroupIndex = log.slice(searchStart).search(/##\[group\]Run [^\n]*/);
|
|
21
|
+
const end = nextGroupIndex === -1 ? log.length : searchStart + nextGroupIndex;
|
|
22
|
+
return log.slice(start, end);
|
|
23
|
+
}
|
|
24
|
+
const stepFailurePattern = /(?:Process completed with exit code [1-9]\d*\.|The action(?: '[^']+')? has timed out)/;
|
|
25
|
+
export function terminalFailedGithubActionsStepLog(log) {
|
|
26
|
+
const slices = getGithubActionsStepGroupSlices(log);
|
|
27
|
+
for (let index = slices.length - 1; index >= 0; index -= 1) {
|
|
28
|
+
const stepLog = slices[index].log;
|
|
29
|
+
if (stepFailurePattern.test(stepLog))
|
|
30
|
+
return stepLog;
|
|
31
|
+
}
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
@@ -2,3 +2,18 @@ export { deriveRetryAttempt } from './attempts.mts';
|
|
|
2
2
|
export { decide } from './decision-evaluator.mts';
|
|
3
3
|
export type { DecisionResult, EvaluateRulesOptions, NoMatchReason } from './decision-evaluator.mts';
|
|
4
4
|
export type { RetryContext, RetryDecision, RetryRule, RetryTarget } from './types.mts';
|
|
5
|
+
export { API_MAX_BUFFER_BYTES, createGhApi, createGhRunner, ghEnvWithToken, DEFAULT_RETRYABLE_MARKERS, } from './gh-api.mts';
|
|
6
|
+
export type { GhApi, GhApiOptions } from './gh-api.mts';
|
|
7
|
+
export { getGithubActionsStepGroupSlices, sliceGithubActionsStepGroup, terminalFailedGithubActionsStepLog, } from './github-actions-log.mts';
|
|
8
|
+
export type { GithubActionsStepGroupSlice } from './github-actions-log.mts';
|
|
9
|
+
export { createGhLogStreamer, streamGhApiLog } from './log-stream.mts';
|
|
10
|
+
export { DEFAULT_LOG_LIMITS, LOG_OMISSION_MARKER } from './log-window.mts';
|
|
11
|
+
export type { LogLimits } from './log-window.mts';
|
|
12
|
+
export { NO_RERUN, RERUN_REQUESTED, rerunKnownTransient } from './rerun.mts';
|
|
13
|
+
export type { RerunKnownTransientOptions } from './rerun.mts';
|
|
14
|
+
export { buildWorkflowRunContext } from './run-context.mts';
|
|
15
|
+
export type { BuildWorkflowRunContextOptions } from './run-context.mts';
|
|
16
|
+
export { fetchWorkflowRunSummary } from './run-context-jobs.mts';
|
|
17
|
+
export type { WorkflowRunSummary } from './run-context-jobs.mts';
|
|
18
|
+
export { isFailedWorkflowConclusion } from './run-context-types.mts';
|
|
19
|
+
export type { JobEntry, RunFetchEnv, WorkflowConclusion, WorkflowJobStep, WorkflowRetryRule, WorkflowRunContext, } from './run-context-types.mts';
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
export { deriveRetryAttempt } from "./attempts.mjs";
|
|
2
2
|
export { decide } from "./decision-evaluator.mjs";
|
|
3
|
+
export { API_MAX_BUFFER_BYTES, createGhApi, createGhRunner, ghEnvWithToken, DEFAULT_RETRYABLE_MARKERS, } from "./gh-api.mjs";
|
|
4
|
+
export { getGithubActionsStepGroupSlices, sliceGithubActionsStepGroup, terminalFailedGithubActionsStepLog, } from "./github-actions-log.mjs";
|
|
5
|
+
export { createGhLogStreamer, streamGhApiLog } from "./log-stream.mjs";
|
|
6
|
+
export { DEFAULT_LOG_LIMITS, LOG_OMISSION_MARKER } from "./log-window.mjs";
|
|
7
|
+
export { NO_RERUN, RERUN_REQUESTED, rerunKnownTransient } from "./rerun.mjs";
|
|
8
|
+
export { buildWorkflowRunContext } from "./run-context.mjs";
|
|
9
|
+
export { fetchWorkflowRunSummary } from "./run-context-jobs.mjs";
|
|
10
|
+
export { isFailedWorkflowConclusion } from "./run-context-types.mjs";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ChildProcessByStdio } from 'node:child_process';
|
|
2
|
+
import type { Readable } from 'node:stream';
|
|
3
|
+
type GhChild = ChildProcessByStdio<null, Readable, Readable>;
|
|
4
|
+
export type SpawnGh = (args: string[]) => GhChild;
|
|
5
|
+
/** A log streamer whose `gh` child sees `tokenEnv`'s value as `GH_TOKEN`, like `createGhRunner`. */
|
|
6
|
+
export declare const createGhLogStreamer: (tokenEnv?: string) => (path: string) => AsyncGenerator<Buffer<ArrayBufferLike>, any, any>;
|
|
7
|
+
/**
|
|
8
|
+
* Streams one `gh api` response body in chunks so the caller never buffers a whole job log. If the
|
|
9
|
+
* consumer stops early the child is killed. A non-zero exit throws with at most 4 KiB of stderr.
|
|
10
|
+
*/
|
|
11
|
+
export declare function streamGhApiLog(path: string, spawnChild?: SpawnGh): AsyncGenerator<Buffer>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { ghEnvWithToken } from "./gh-api.mjs";
|
|
3
|
+
const STDERR_MAX_BYTES = 4 * 1024;
|
|
4
|
+
const spawnGhWith = (buildEnv) => (args) => spawn('gh', args, { env: buildEnv(process.env), stdio: ['ignore', 'pipe', 'pipe'] });
|
|
5
|
+
/** A log streamer whose `gh` child sees `tokenEnv`'s value as `GH_TOKEN`, like `createGhRunner`. */
|
|
6
|
+
export const createGhLogStreamer = (tokenEnv) => (path) => streamGhApiLog(path, spawnGhWith(ghEnvWithToken(tokenEnv)));
|
|
7
|
+
/**
|
|
8
|
+
* Streams one `gh api` response body in chunks so the caller never buffers a whole job log. If the
|
|
9
|
+
* consumer stops early the child is killed. A non-zero exit throws with at most 4 KiB of stderr.
|
|
10
|
+
*/
|
|
11
|
+
export async function* streamGhApiLog(path, spawnChild = spawnGhWith(ghEnvWithToken())) {
|
|
12
|
+
const child = spawnChild(['api', '--allow-escape-sequences', path]);
|
|
13
|
+
const stderr = [];
|
|
14
|
+
let stderrBytes = 0;
|
|
15
|
+
child.stderr.on('data', (chunk) => {
|
|
16
|
+
const part = Buffer.from(chunk).subarray(0, STDERR_MAX_BYTES - stderrBytes);
|
|
17
|
+
stderr.push(part);
|
|
18
|
+
stderrBytes += part.byteLength;
|
|
19
|
+
});
|
|
20
|
+
const closed = new Promise((resolve, reject) => {
|
|
21
|
+
child.once('error', reject);
|
|
22
|
+
child.once('close', resolve);
|
|
23
|
+
});
|
|
24
|
+
closed.catch(() => undefined);
|
|
25
|
+
let finished = false;
|
|
26
|
+
try {
|
|
27
|
+
for await (const chunk of child.stdout)
|
|
28
|
+
yield Buffer.from(chunk);
|
|
29
|
+
finished = true;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
if (!finished)
|
|
33
|
+
child.kill();
|
|
34
|
+
}
|
|
35
|
+
const code = await closed;
|
|
36
|
+
if (code !== 0) {
|
|
37
|
+
throw new Error(`gh api ${path} exited with status ${String(code)}: ${Buffer.concat(stderr).toString('utf8')}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const LOG_OMISSION_MARKER = "\n[...job log middle omitted...]\n";
|
|
2
|
+
export interface LogLimits {
|
|
3
|
+
/** Bytes kept from the start of each job log. */
|
|
4
|
+
headBytes: number;
|
|
5
|
+
/** Bytes kept from the end of each job log. */
|
|
6
|
+
tailBytes: number;
|
|
7
|
+
/** Most bytes read from one job log stream before the rest is abandoned. */
|
|
8
|
+
maxReadBytes: number;
|
|
9
|
+
/** Most bytes retained across every job log of one run context. */
|
|
10
|
+
totalBytes: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const DEFAULT_LOG_LIMITS: LogLimits;
|
|
13
|
+
/**
|
|
14
|
+
* Reads a log stream keeping only a head and a tail window, so memory stays bounded by the limits
|
|
15
|
+
* rather than by the log size. Bytes between the windows are replaced by an omission marker.
|
|
16
|
+
*/
|
|
17
|
+
export declare function collectDiagnosticWindow(stream: AsyncIterable<Buffer>, { headBytes, tailBytes, maxReadBytes }: LogLimits): Promise<string>;
|
|
18
|
+
export declare function fitDiagnosticWindow(log: string, maxBytes: number): string;
|