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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { MarkdownSectionsDiagnostic } from './document-types.mts';
|
|
2
2
|
/** Tracks disclosure tags from HTML nodes, never from fenced code or Markdown comments. */
|
|
3
3
|
export declare class DetailsScope {
|
|
4
|
-
private readonly markdown;
|
|
5
4
|
readonly diagnostics: MarkdownSectionsDiagnostic[];
|
|
6
5
|
private readonly frames;
|
|
6
|
+
private readonly markdown;
|
|
7
7
|
constructor(markdown: string);
|
|
8
8
|
get visible(): boolean;
|
|
9
9
|
acceptHtml(html: string, startOffset: number): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ScriptSpawn } from '../cli/commands/spawn-script.mts';
|
|
2
|
+
import type { PaneTitleSpawn } from './reminder-post-tool.mts';
|
|
3
|
+
import type { TmuxRun } from './runner.mts';
|
|
4
|
+
export declare const TMUX_USAGE = "tmux up --config <file> [--root <dir>] [--no-attach] [-v|--verbose]\ntmux name [--socket PATH --pane %ID --worktree PATH] <name>\ntmux read-title\ntmux agent-reminder session-start|user-prompt\ntmux post-tool (hook payload on stdin)\n Environment: TMUX_TARGET_BIN (tmux binary), TMUX_TARGET_ROOT (worktree, default cwd),\n TMUX_NAME_COMMAND (rename command named in reminders), AGENT_TMUX_SOCKET/PANE/WORKTREE.\n";
|
|
5
|
+
export type TmuxCliDeps = {
|
|
6
|
+
env?: NodeJS.ProcessEnv;
|
|
7
|
+
cwd?: string;
|
|
8
|
+
spawn?: ScriptSpawn;
|
|
9
|
+
readStdin?: () => string;
|
|
10
|
+
tmux?: TmuxRun;
|
|
11
|
+
hasChildren?: (pid: string) => boolean;
|
|
12
|
+
sleep?: (milliseconds: number) => void;
|
|
13
|
+
spawnPaneTitle?: PaneTitleSpawn;
|
|
14
|
+
out?: (text: string) => void;
|
|
15
|
+
err?: (text: string) => void;
|
|
16
|
+
pid?: number;
|
|
17
|
+
isPidAlive?: (pid: number) => boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const TMUX_USAGE = `tmux up --config <file> [--root <dir>] [--no-attach] [-v|--verbose]
|
|
2
|
+
tmux name [--socket PATH --pane %ID --worktree PATH] <name>
|
|
3
|
+
tmux read-title
|
|
4
|
+
tmux agent-reminder session-start|user-prompt
|
|
5
|
+
tmux post-tool (hook payload on stdin)
|
|
6
|
+
Environment: TMUX_TARGET_BIN (tmux binary), TMUX_TARGET_ROOT (worktree, default cwd),
|
|
7
|
+
TMUX_NAME_COMMAND (rename command named in reminders), AGENT_TMUX_SOCKET/PANE/WORKTREE.
|
|
8
|
+
`;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { runScript } from "../cli/commands/spawn-script.mjs";
|
|
3
|
+
import { packageScriptPath } from "../cli/script-path.mjs";
|
|
4
|
+
import { TMUX_USAGE } from "./cli-shared.mjs";
|
|
5
|
+
import { parseHookPayload } from "./hook-payload.mjs";
|
|
6
|
+
import { renderPostToolReminder } from "./reminder-post-tool.mjs";
|
|
7
|
+
import { runUp } from "./up.mjs";
|
|
8
|
+
export { TMUX_USAGE };
|
|
9
|
+
const SCRIPTS = {
|
|
10
|
+
name: 'scripts/tmux/tmux-name.sh',
|
|
11
|
+
'read-title': 'scripts/tmux/tmux-read-title.sh',
|
|
12
|
+
'agent-reminder': 'scripts/tmux/tmux-agent-reminder.sh',
|
|
13
|
+
};
|
|
14
|
+
export function runTmuxCommand(args, deps = {}) {
|
|
15
|
+
const [subcommand, ...rest] = args;
|
|
16
|
+
const script = subcommand === undefined ? undefined : SCRIPTS[subcommand];
|
|
17
|
+
if (script !== undefined)
|
|
18
|
+
return runScript('bash', packageScriptPath(script), rest, deps.spawn);
|
|
19
|
+
if (subcommand === 'up')
|
|
20
|
+
return runUp(rest, deps);
|
|
21
|
+
if (subcommand === 'post-tool' && rest.length === 0) {
|
|
22
|
+
const stdin = deps.readStdin ?? (() => readFileSync(0, 'utf8'));
|
|
23
|
+
const reminder = renderPostToolReminder(parseHookPayload(stdin()), {
|
|
24
|
+
env: deps.env,
|
|
25
|
+
spawnPaneTitle: deps.spawnPaneTitle,
|
|
26
|
+
});
|
|
27
|
+
if (reminder !== null)
|
|
28
|
+
(deps.out ?? ((text) => void process.stdout.write(text)))(`${reminder}\n`);
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
;
|
|
32
|
+
(deps.err ?? ((text) => void process.stderr.write(text)))(`vouchington: expected: up|name|read-title|agent-reminder|post-tool\n${TMUX_USAGE}`);
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TmuxWindowConfig = {
|
|
2
|
+
name: string;
|
|
3
|
+
/** Shell body run through `bash -lc`. */
|
|
4
|
+
command: string;
|
|
5
|
+
/** Working directory, relative to the worktree root unless absolute. */
|
|
6
|
+
cwd?: string;
|
|
7
|
+
env: Record<string, string>;
|
|
8
|
+
/** Keep the pane open after the command exits (appends `; read`). Default true. */
|
|
9
|
+
keepOpen: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type TmuxSessionConfig = {
|
|
12
|
+
/** Prepended to the worktree hash to form the tmux session name. */
|
|
13
|
+
sessionPrefix: string;
|
|
14
|
+
/** Session option (without the leading `@`) set once every window exists. */
|
|
15
|
+
readyMarker: string;
|
|
16
|
+
/** Variable recorded in the tmux session environment to identify the launcher. */
|
|
17
|
+
launcherPidVar: string;
|
|
18
|
+
env: Record<string, string>;
|
|
19
|
+
windows: TmuxWindowConfig[];
|
|
20
|
+
/** Lines printed before a fresh session starts. */
|
|
21
|
+
summary: string[];
|
|
22
|
+
};
|
|
23
|
+
export declare function parseTmuxConfig(value: unknown): TmuxSessionConfig;
|
|
24
|
+
export declare function loadTmuxConfig(path: string): TmuxSessionConfig;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
const ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
3
|
+
const TMUX_NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
|
|
4
|
+
// A purely numeric window name would be read by tmux as an index.
|
|
5
|
+
const WINDOW_NAME = /^(?![0-9]+$)[A-Za-z0-9][A-Za-z0-9_.-]*$/;
|
|
6
|
+
const OPTION_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
7
|
+
function isRecord(value) {
|
|
8
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
function text(value, label, pattern) {
|
|
11
|
+
if (typeof value !== 'string' ||
|
|
12
|
+
value === '' ||
|
|
13
|
+
(pattern !== undefined && !pattern.test(value))) {
|
|
14
|
+
throw new Error(`tmux config: ${label} must be a ${pattern ? 'valid ' : 'non-empty '}string`);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function envMap(value, label) {
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
return {};
|
|
21
|
+
if (!isRecord(value))
|
|
22
|
+
throw new Error(`tmux config: ${label} must be an object`);
|
|
23
|
+
const result = {};
|
|
24
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
25
|
+
if (!ENV_KEY.test(key))
|
|
26
|
+
throw new Error(`tmux config: ${label} has invalid name "${key}"`);
|
|
27
|
+
if (typeof raw !== 'string' && typeof raw !== 'number') {
|
|
28
|
+
throw new Error(`tmux config: ${label}.${key} must be a string or number`);
|
|
29
|
+
}
|
|
30
|
+
result[key] = String(raw);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
function windowConfig(value, index) {
|
|
35
|
+
const label = `windows[${index}]`;
|
|
36
|
+
if (!isRecord(value))
|
|
37
|
+
throw new Error(`tmux config: ${label} must be an object`);
|
|
38
|
+
const cwd = value.cwd === undefined ? undefined : text(value.cwd, `${label}.cwd`);
|
|
39
|
+
if (value.keepOpen !== undefined && typeof value.keepOpen !== 'boolean') {
|
|
40
|
+
throw new Error(`tmux config: ${label}.keepOpen must be a boolean`);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
name: text(value.name, `${label}.name`, WINDOW_NAME),
|
|
44
|
+
command: text(value.command, `${label}.command`),
|
|
45
|
+
...(cwd === undefined ? {} : { cwd }),
|
|
46
|
+
env: envMap(value.env, `${label}.env`),
|
|
47
|
+
keepOpen: value.keepOpen ?? true,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export function parseTmuxConfig(value) {
|
|
51
|
+
if (!isRecord(value))
|
|
52
|
+
throw new Error('tmux config: expected a JSON object');
|
|
53
|
+
if (!Array.isArray(value.windows) || value.windows.length === 0) {
|
|
54
|
+
throw new Error('tmux config: windows must be a non-empty array');
|
|
55
|
+
}
|
|
56
|
+
const windows = value.windows.map(windowConfig);
|
|
57
|
+
const names = new Set(windows.map((window) => window.name));
|
|
58
|
+
if (names.size !== windows.length)
|
|
59
|
+
throw new Error('tmux config: window names must be unique');
|
|
60
|
+
const summary = value.summary ?? [];
|
|
61
|
+
if (!Array.isArray(summary) || summary.some((line) => typeof line !== 'string')) {
|
|
62
|
+
throw new Error('tmux config: summary must be an array of strings');
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
sessionPrefix: text(value.sessionPrefix ?? 'dev-', 'sessionPrefix', TMUX_NAME),
|
|
66
|
+
readyMarker: text(value.readyMarker ?? 'ready', 'readyMarker', OPTION_NAME),
|
|
67
|
+
launcherPidVar: text(value.launcherPidVar ?? 'TMUX_LAUNCHER_PID', 'launcherPidVar', ENV_KEY),
|
|
68
|
+
env: envMap(value.env, 'env'),
|
|
69
|
+
windows,
|
|
70
|
+
summary: summary,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function loadTmuxConfig(path) {
|
|
74
|
+
let raw;
|
|
75
|
+
try {
|
|
76
|
+
raw = readFileSync(path, 'utf8');
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new Error(`tmux config: cannot read ${path}: ${error.message}`, {
|
|
80
|
+
cause: error,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return parseTmuxConfig(JSON.parse(raw));
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error instanceof SyntaxError)
|
|
88
|
+
throw new Error(`tmux config: ${path} is not valid JSON`);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { TmuxSessionConfig } from './config.mts';
|
|
2
|
+
import type { TmuxRun } from './runner.mts';
|
|
3
|
+
import type { SessionContext } from './windows.mts';
|
|
4
|
+
export type FakeTmuxOptions = {
|
|
5
|
+
exists?: boolean;
|
|
6
|
+
windows?: string[];
|
|
7
|
+
dead?: string[];
|
|
8
|
+
/** Polls of the ready option that report not-ready before it becomes `1`. */
|
|
9
|
+
readyAfter?: number;
|
|
10
|
+
/** Never ready. */
|
|
11
|
+
neverReady?: boolean;
|
|
12
|
+
/** The session vanishes after this many has-session calls. */
|
|
13
|
+
vanishAfterChecks?: number;
|
|
14
|
+
/** Subcommands (first argument) that exit 1. */
|
|
15
|
+
failOn?: string[];
|
|
16
|
+
/** Subcommand to fail only the first time it runs. */
|
|
17
|
+
failOnce?: string;
|
|
18
|
+
/** Environment value returned for the launcher pid variable. */
|
|
19
|
+
launcherPid?: string;
|
|
20
|
+
attachStatus?: number | null;
|
|
21
|
+
/** Whether `isPidAlive` reports the recorded launcher as running. Default true. */
|
|
22
|
+
ownerAlive?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function createFakeTmux(options?: FakeTmuxOptions): {
|
|
25
|
+
run: TmuxRun;
|
|
26
|
+
calls: string[][];
|
|
27
|
+
out: string[];
|
|
28
|
+
err: string[];
|
|
29
|
+
sleeps: number[];
|
|
30
|
+
state: {
|
|
31
|
+
exists: boolean;
|
|
32
|
+
windows: string[];
|
|
33
|
+
polls: number;
|
|
34
|
+
checks: number;
|
|
35
|
+
failedOnce: boolean;
|
|
36
|
+
};
|
|
37
|
+
context: (config?: TmuxSessionConfig) => SessionContext;
|
|
38
|
+
launch: (noAttach?: boolean) => {
|
|
39
|
+
noAttach: boolean;
|
|
40
|
+
pid: number;
|
|
41
|
+
sleep: (ms: number) => undefined;
|
|
42
|
+
isPidAlive: () => boolean;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** Subcommand lines, e.g. `new-window -t =dev-dabc -n web ...`. */
|
|
46
|
+
export declare function lines(calls: readonly string[][]): string[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const sampleConfig = {
|
|
2
|
+
sessionPrefix: 'dev-',
|
|
3
|
+
readyMarker: 'ready',
|
|
4
|
+
launcherPidVar: 'TMUX_LAUNCHER_PID',
|
|
5
|
+
env: { SHARED: '1' },
|
|
6
|
+
summary: ['Web: http://localhost:3000'],
|
|
7
|
+
windows: [
|
|
8
|
+
{ name: 'web', command: 'serve web', cwd: 'web', env: { SERVICE: 'web' }, keepOpen: true },
|
|
9
|
+
{ name: 'api', command: 'serve api', env: {}, keepOpen: false },
|
|
10
|
+
{ name: 'jobs', command: 'serve jobs', env: {}, keepOpen: true },
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
export function createFakeTmux(options = {}) {
|
|
14
|
+
const state = {
|
|
15
|
+
exists: options.exists ?? false,
|
|
16
|
+
windows: [...(options.windows ?? [])],
|
|
17
|
+
polls: 0,
|
|
18
|
+
checks: 0,
|
|
19
|
+
failedOnce: false,
|
|
20
|
+
};
|
|
21
|
+
const calls = [];
|
|
22
|
+
const pids = new Map();
|
|
23
|
+
const deadPids = new Set();
|
|
24
|
+
const pidFor = (name) => {
|
|
25
|
+
if (!pids.has(name)) {
|
|
26
|
+
pids.set(name, String(1000 + pids.size));
|
|
27
|
+
if (options.dead?.includes(name))
|
|
28
|
+
deadPids.add(pids.get(name));
|
|
29
|
+
}
|
|
30
|
+
return pids.get(name);
|
|
31
|
+
};
|
|
32
|
+
const ok = (stdout = '') => ({ status: 0, stdout });
|
|
33
|
+
const fail = { status: 1, stdout: '' };
|
|
34
|
+
const run = (args) => {
|
|
35
|
+
calls.push([...args]);
|
|
36
|
+
const [command = '', ...rest] = args;
|
|
37
|
+
if (options.failOn?.includes(command))
|
|
38
|
+
return fail;
|
|
39
|
+
if (options.failOnce === command && !state.failedOnce) {
|
|
40
|
+
state.failedOnce = true;
|
|
41
|
+
return fail;
|
|
42
|
+
}
|
|
43
|
+
switch (command) {
|
|
44
|
+
case '-V':
|
|
45
|
+
return ok('tmux 3.5\n');
|
|
46
|
+
case 'has-session':
|
|
47
|
+
state.checks += 1;
|
|
48
|
+
if (options.vanishAfterChecks !== undefined && state.checks > options.vanishAfterChecks) {
|
|
49
|
+
state.exists = false;
|
|
50
|
+
}
|
|
51
|
+
return state.exists ? ok() : fail;
|
|
52
|
+
case 'show-options': {
|
|
53
|
+
state.polls += 1;
|
|
54
|
+
const ready = !options.neverReady && state.polls > (options.readyAfter ?? 0);
|
|
55
|
+
return ok(ready ? '1\n' : '');
|
|
56
|
+
}
|
|
57
|
+
case 'show-environment':
|
|
58
|
+
return ok(`${rest[2]}=${options.launcherPid ?? ''}\n`);
|
|
59
|
+
case 'list-windows':
|
|
60
|
+
return ok(state.windows.join('\n'));
|
|
61
|
+
case 'list-panes': {
|
|
62
|
+
const name = rest[1].split(':')[1];
|
|
63
|
+
return ok(`${pidFor(name)}\nnot-a-pid\n`);
|
|
64
|
+
}
|
|
65
|
+
case 'new-session':
|
|
66
|
+
state.exists = true;
|
|
67
|
+
state.windows.push(rest[rest.indexOf('-n') + 1]);
|
|
68
|
+
return ok();
|
|
69
|
+
case 'new-window':
|
|
70
|
+
state.windows.push(rest[rest.indexOf('-n') + 1]);
|
|
71
|
+
return ok();
|
|
72
|
+
case 'kill-session':
|
|
73
|
+
state.exists = false;
|
|
74
|
+
return ok();
|
|
75
|
+
case 'attach':
|
|
76
|
+
return { status: options.attachStatus === undefined ? 0 : options.attachStatus, stdout: '' };
|
|
77
|
+
default:
|
|
78
|
+
return ok();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const out = [];
|
|
82
|
+
const err = [];
|
|
83
|
+
const sleeps = [];
|
|
84
|
+
const context = (config = sampleConfig) => ({
|
|
85
|
+
config,
|
|
86
|
+
root: '/work',
|
|
87
|
+
session: 'dev-dabc',
|
|
88
|
+
extraEnv: { TMUX_LOG_LEVEL: 'error' },
|
|
89
|
+
tmux: run,
|
|
90
|
+
hasChildren: (pid) => !deadPids.has(pid),
|
|
91
|
+
out: (text) => void out.push(text),
|
|
92
|
+
err: (text) => void err.push(text),
|
|
93
|
+
});
|
|
94
|
+
const launch = (noAttach = true) => ({
|
|
95
|
+
noAttach,
|
|
96
|
+
pid: 4242,
|
|
97
|
+
sleep: (ms) => void sleeps.push(ms),
|
|
98
|
+
isPidAlive: () => options.ownerAlive ?? true,
|
|
99
|
+
});
|
|
100
|
+
return { run, calls, out, err, sleeps, state, context, launch };
|
|
101
|
+
}
|
|
102
|
+
/** Subcommand lines, e.g. `new-window -t =dev-dabc -n web ...`. */
|
|
103
|
+
export function lines(calls) {
|
|
104
|
+
return calls.map((call) => call.join(' '));
|
|
105
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type HookPayload = Record<string, unknown>;
|
|
2
|
+
/** Tool name across Claude-compatible (`tool_name`), camelCase and bare (`name`) payloads. */
|
|
3
|
+
export declare function hookToolName(payload: HookPayload): string;
|
|
4
|
+
/** The shell command a tool call ran, or '' when the payload carries none. */
|
|
5
|
+
export declare function extractToolCommand(payload: HookPayload): string;
|
|
6
|
+
/** A numeric `exit_code` from the response shapes that carry one; undefined otherwise. */
|
|
7
|
+
export declare function toolExitCode(payload: HookPayload): number | undefined;
|
|
8
|
+
export declare function parseHookPayload(raw: string): HookPayload;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
/** Tool name across Claude-compatible (`tool_name`), camelCase and bare (`name`) payloads. */
|
|
5
|
+
export function hookToolName(payload) {
|
|
6
|
+
for (const key of ['tool_name', 'toolName', 'name']) {
|
|
7
|
+
const value = payload[key];
|
|
8
|
+
if (typeof value === 'string')
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
/** The shell command a tool call ran, or '' when the payload carries none. */
|
|
14
|
+
export function extractToolCommand(payload) {
|
|
15
|
+
for (const key of ['tool_input', 'toolInput', 'input']) {
|
|
16
|
+
const input = payload[key];
|
|
17
|
+
if (isRecord(input) && typeof input.command === 'string')
|
|
18
|
+
return input.command;
|
|
19
|
+
}
|
|
20
|
+
return typeof payload.command === 'string' ? payload.command : '';
|
|
21
|
+
}
|
|
22
|
+
/** A numeric `exit_code` from the response shapes that carry one; undefined otherwise. */
|
|
23
|
+
export function toolExitCode(payload) {
|
|
24
|
+
for (const key of ['tool_response', 'toolResponse', 'toolResult']) {
|
|
25
|
+
const response = payload[key];
|
|
26
|
+
if (isRecord(response) && typeof response.exit_code === 'number')
|
|
27
|
+
return response.exit_code;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
export function parseHookPayload(raw) {
|
|
32
|
+
try {
|
|
33
|
+
const parsed = JSON.parse(raw);
|
|
34
|
+
return isRecord(parsed) ? parsed : {};
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { runTmuxCommand, TMUX_USAGE, type TmuxCliDeps } from './cli.mts';
|
|
2
|
+
export { loadTmuxConfig, parseTmuxConfig } from './config.mts';
|
|
3
|
+
export type { TmuxSessionConfig, TmuxWindowConfig } from './config.mts';
|
|
4
|
+
export { launchSession, type LaunchOptions } from './launcher.mts';
|
|
5
|
+
export { createTmuxRun, type TmuxResult, type TmuxRun } from './runner.mts';
|
|
6
|
+
export { renderPostToolReminder, type PostToolTmuxOptions } from './reminder-post-tool.mts';
|
|
7
|
+
export { tmuxSessionName } from './session-name.mts';
|
|
8
|
+
export { quoteShellArg, windowCommand } from './shell-quote.mts';
|
|
9
|
+
export type { SessionContext } from './windows.mts';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { runTmuxCommand, TMUX_USAGE } from "./cli.mjs";
|
|
2
|
+
export { loadTmuxConfig, parseTmuxConfig } from "./config.mjs";
|
|
3
|
+
export { launchSession } from "./launcher.mjs";
|
|
4
|
+
export { createTmuxRun } from "./runner.mjs";
|
|
5
|
+
export { renderPostToolReminder } from "./reminder-post-tool.mjs";
|
|
6
|
+
export { tmuxSessionName } from "./session-name.mjs";
|
|
7
|
+
export { quoteShellArg, windowCommand } from "./shell-quote.mjs";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SessionContext } from './windows.mts';
|
|
2
|
+
export type LaunchOptions = {
|
|
3
|
+
noAttach: boolean;
|
|
4
|
+
/** Pid recorded in the session environment to prove this launcher owns it. */
|
|
5
|
+
pid: number;
|
|
6
|
+
sleep: (milliseconds: number) => void;
|
|
7
|
+
/** Whether the launcher process recorded in the session environment still runs. */
|
|
8
|
+
isPidAlive: (pid: number) => boolean;
|
|
9
|
+
};
|
|
10
|
+
/** Start the configured windows in a worktree-scoped tmux session, or reuse a running one. */
|
|
11
|
+
export declare function launchSession(context: SessionContext, options: LaunchOptions): number;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { commandFor, decorateWindow, restoreDeadWindows, windowCwd, } from "./windows.mjs";
|
|
2
|
+
const READY_ATTEMPTS = 99;
|
|
3
|
+
const READY_POLL_MS = 100;
|
|
4
|
+
function isReady(context) {
|
|
5
|
+
const marker = `@${context.config.readyMarker}`;
|
|
6
|
+
const result = context.tmux(['show-options', '-qv', '-t', `=${context.session}:`, marker]);
|
|
7
|
+
return result.stdout.trim() === '1';
|
|
8
|
+
}
|
|
9
|
+
function hasSession(context) {
|
|
10
|
+
return context.tmux(['has-session', '-t', `=${context.session}`]).status === 0;
|
|
11
|
+
}
|
|
12
|
+
function finishExisting(context, options) {
|
|
13
|
+
if (options.noAttach) {
|
|
14
|
+
context.out(`Services already running in tmux session '${context.session}'.\n`);
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
context.out(`Reattaching to existing tmux session '${context.session}'...\n`);
|
|
18
|
+
return context.tmux(['attach', '-t', `=${context.session}`], true).status ?? 1;
|
|
19
|
+
}
|
|
20
|
+
function waitUntilReady(context, options) {
|
|
21
|
+
for (let attempt = 0; attempt < READY_ATTEMPTS; attempt += 1) {
|
|
22
|
+
if (!hasSession(context)) {
|
|
23
|
+
context.err(`Error: tmux session '${context.session}' disappeared during startup.\n`);
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
options.sleep(READY_POLL_MS);
|
|
27
|
+
if (isReady(context))
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
if (ownerIsDead(context, options)) {
|
|
31
|
+
context.err(`Error: tmux session '${context.session}' was left unfinished; recreating it.\n`);
|
|
32
|
+
context.tmux(['kill-session', '-t', `=${context.session}`]);
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
35
|
+
context.err(`Error: tmux session '${context.session}' did not finish startup.\n`);
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
/** True when the session records a launcher pid and that process no longer exists. */
|
|
39
|
+
function ownerIsDead(context, options) {
|
|
40
|
+
const variable = context.config.launcherPidVar;
|
|
41
|
+
const result = context.tmux(['show-environment', '-t', `=${context.session}`, variable]);
|
|
42
|
+
const pid = /=([0-9]+)\s*$/.exec(result.stdout)?.[1];
|
|
43
|
+
return pid !== undefined && !options.isPidAlive(Number(pid));
|
|
44
|
+
}
|
|
45
|
+
/** 0 = done, 2 = session was killed and must be recreated, other = failure. */
|
|
46
|
+
function reuseExisting(context, options, allowRestore) {
|
|
47
|
+
if (!isReady(context)) {
|
|
48
|
+
const waited = waitUntilReady(context, options);
|
|
49
|
+
if (waited !== 0)
|
|
50
|
+
return waited;
|
|
51
|
+
}
|
|
52
|
+
else if (allowRestore && !restoreDeadWindows(context)) {
|
|
53
|
+
context.err('Error: failed to restore managed tmux windows; recreating session.\n');
|
|
54
|
+
context.tmux(['kill-session', '-t', `=${context.session}`]);
|
|
55
|
+
return 2;
|
|
56
|
+
}
|
|
57
|
+
return finishExisting(context, options);
|
|
58
|
+
}
|
|
59
|
+
function ownsSession(context, pid) {
|
|
60
|
+
const variable = context.config.launcherPidVar;
|
|
61
|
+
const result = context.tmux(['show-environment', '-t', `=${context.session}`, variable]);
|
|
62
|
+
return result.stdout.trim() === `${variable}=${pid}`;
|
|
63
|
+
}
|
|
64
|
+
function createSession(context, options) {
|
|
65
|
+
const [first, ...rest] = context.config.windows;
|
|
66
|
+
const target = `=${context.session}`;
|
|
67
|
+
const created = context.tmux([
|
|
68
|
+
'new-session',
|
|
69
|
+
'-d',
|
|
70
|
+
'-s',
|
|
71
|
+
context.session,
|
|
72
|
+
'-e',
|
|
73
|
+
`${context.config.launcherPidVar}=${options.pid}`,
|
|
74
|
+
'-n',
|
|
75
|
+
first.name,
|
|
76
|
+
'-c',
|
|
77
|
+
windowCwd(context, first),
|
|
78
|
+
commandFor(context, first),
|
|
79
|
+
]);
|
|
80
|
+
if (created.status !== 0) {
|
|
81
|
+
if (hasSession(context))
|
|
82
|
+
return reuseExisting(context, options, false);
|
|
83
|
+
context.err(`Error: failed to create tmux session '${context.session}'.\n`);
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
const steps = rest.map((window) => [
|
|
87
|
+
'new-window',
|
|
88
|
+
'-t',
|
|
89
|
+
target,
|
|
90
|
+
'-n',
|
|
91
|
+
window.name,
|
|
92
|
+
'-c',
|
|
93
|
+
windowCwd(context, window),
|
|
94
|
+
commandFor(context, window),
|
|
95
|
+
]);
|
|
96
|
+
const ok = decorateWindow(context, first.name) &&
|
|
97
|
+
rest.every((window, index) => context.tmux(steps[index]).status === 0 && decorateWindow(context, window.name)) &&
|
|
98
|
+
context.tmux(['select-window', '-t', `${target}:${first.name}`]).status === 0 &&
|
|
99
|
+
context.tmux(['set-option', '-t', `${target}:`, `@${context.config.readyMarker}`, '1'])
|
|
100
|
+
.status === 0;
|
|
101
|
+
if (!ok) {
|
|
102
|
+
if (ownsSession(context, options.pid))
|
|
103
|
+
context.tmux(['kill-session', '-t', target]);
|
|
104
|
+
context.err(`Error: failed to start tmux session '${context.session}'.\n`);
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
if (options.noAttach) {
|
|
108
|
+
context.out(`Services started in tmux session '${context.session}'.\n`);
|
|
109
|
+
context.out(`To attach: tmux attach -t '${context.session}'\n`);
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
context.out(`Attaching to tmux session '${context.session}'...\n`);
|
|
113
|
+
return context.tmux(['attach', '-t', target], true).status ?? 1;
|
|
114
|
+
}
|
|
115
|
+
/** Start the configured windows in a worktree-scoped tmux session, or reuse a running one. */
|
|
116
|
+
export function launchSession(context, options) {
|
|
117
|
+
if (hasSession(context)) {
|
|
118
|
+
const status = reuseExisting(context, options, true);
|
|
119
|
+
if (status !== 2)
|
|
120
|
+
return status;
|
|
121
|
+
}
|
|
122
|
+
for (const line of context.config.summary)
|
|
123
|
+
context.out(`${line}\n`);
|
|
124
|
+
if (context.config.summary.length > 0)
|
|
125
|
+
context.out('\n');
|
|
126
|
+
return createSession(context, options);
|
|
127
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type HookPayload } from './hook-payload.mts';
|
|
2
|
+
export type PaneTitleSpawnResult = {
|
|
3
|
+
error?: NodeJS.ErrnoException | null | undefined;
|
|
4
|
+
status: number | null;
|
|
5
|
+
stdout: string;
|
|
6
|
+
stderr?: string;
|
|
7
|
+
};
|
|
8
|
+
export type PaneTitleSpawn = (command: string, args: readonly string[], env: NodeJS.ProcessEnv) => PaneTitleSpawnResult;
|
|
9
|
+
export type PostToolTmuxOptions = {
|
|
10
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
11
|
+
spawnPaneTitle?: PaneTitleSpawn | undefined;
|
|
12
|
+
/** Command the reminder tells the agent to run. Default: `TMUX_NAME_COMMAND` or `vouchington tmux name`. */
|
|
13
|
+
nameCommand?: string | undefined;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Remind the agent to (re)name its tmux window at the checkpoints a post-tool payload can
|
|
17
|
+
* detect: a plan was accepted, a PR was created, a push landed without a `-pr<N>` title suffix,
|
|
18
|
+
* or reset-worktree left a stale title. Silent (`null`) without a verified pane and for every
|
|
19
|
+
* other tool call. The pane is read only after a checkpoint matches.
|
|
20
|
+
*/
|
|
21
|
+
export declare function renderPostToolReminder(payload: HookPayload, options?: PostToolTmuxOptions): string | null;
|