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,67 @@
|
|
|
1
|
+
import { attachedShortOptionValue, optionValueFromLongToken } from "./github-options.mjs";
|
|
2
|
+
const FALSE_FLAG_VALUES = new Set(['false', '0', 'no', 'off']);
|
|
3
|
+
function clusteredShortOptionValue(token, shortName) {
|
|
4
|
+
if (!token.startsWith('-') || token.startsWith('--') || shortName.length !== 1) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
const body = token.slice(1);
|
|
8
|
+
const flagIndex = body.indexOf(shortName);
|
|
9
|
+
if (flagIndex === -1) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
// pflag reads `-B=main` as the value `main`.
|
|
13
|
+
return body.slice(flagIndex + 1).replace(/^=/, '');
|
|
14
|
+
}
|
|
15
|
+
export function lastNamedOption(optionTokens, name, shortFlag) {
|
|
16
|
+
const flag = `--${name}`;
|
|
17
|
+
const short = shortFlag === undefined ? undefined : `-${shortFlag}`;
|
|
18
|
+
let value;
|
|
19
|
+
for (let index = 0; index < optionTokens.length; index += 1) {
|
|
20
|
+
const token = optionTokens[index];
|
|
21
|
+
if (token === flag || (short !== undefined && token === short)) {
|
|
22
|
+
const next = optionTokens[index + 1];
|
|
23
|
+
if (next !== undefined && !next.startsWith('-')) {
|
|
24
|
+
value = next;
|
|
25
|
+
index += 1;
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const clustered = shortFlag === undefined ? null : clusteredShortOptionValue(token, shortFlag);
|
|
30
|
+
if (clustered !== null) {
|
|
31
|
+
if (clustered !== '') {
|
|
32
|
+
value = clustered;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const next = optionTokens[index + 1];
|
|
36
|
+
if (next !== undefined && !next.startsWith('-')) {
|
|
37
|
+
value = next;
|
|
38
|
+
index += 1;
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const attached = optionValueFromLongToken(token, flag) ??
|
|
43
|
+
(short === undefined ? null : attachedShortOptionValue(token, short));
|
|
44
|
+
if (attached !== null) {
|
|
45
|
+
value = attached;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
export function hasNamedFlag(optionTokens, name) {
|
|
51
|
+
const flag = `--${name}`;
|
|
52
|
+
let enabled = false;
|
|
53
|
+
for (const token of optionTokens) {
|
|
54
|
+
if (token === flag) {
|
|
55
|
+
enabled = true;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const attached = optionValueFromLongToken(token, flag);
|
|
59
|
+
if (attached !== null) {
|
|
60
|
+
enabled = !FALSE_FLAG_VALUES.has(attached.toLowerCase());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return enabled;
|
|
64
|
+
}
|
|
65
|
+
export function hasNumericPrSelector(optionTokens) {
|
|
66
|
+
return optionTokens.some((token) => /^\d+$/.test(token));
|
|
67
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function attachedShortOptionValue(token: string, flag: string): string | null;
|
|
2
|
+
export declare function optionValueFromLongToken(token: string, option: string): string | null;
|
|
3
|
+
export declare function isGhCommandSeparator(token: string): boolean;
|
|
4
|
+
export type GhOptions = {
|
|
5
|
+
body: string[];
|
|
6
|
+
bodyFile: string[];
|
|
7
|
+
draft: boolean;
|
|
8
|
+
label: string[];
|
|
9
|
+
repo: string[];
|
|
10
|
+
title: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare function parseGhOptions(tokens: string[]): GhOptions;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
function addOptionValue(options, key, value) {
|
|
2
|
+
if (value === undefined) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
options[key].push(value);
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
export function attachedShortOptionValue(token, flag) {
|
|
9
|
+
if (token.startsWith(`${flag}=`)) {
|
|
10
|
+
return token.slice(flag.length + 1);
|
|
11
|
+
}
|
|
12
|
+
if (token.startsWith(flag) && token.length > flag.length) {
|
|
13
|
+
return token.slice(flag.length);
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
export function optionValueFromLongToken(token, option) {
|
|
18
|
+
if (!token.startsWith(`${option}=`)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return token.slice(option.length + 1);
|
|
22
|
+
}
|
|
23
|
+
export function isGhCommandSeparator(token) {
|
|
24
|
+
return (token === '&&' ||
|
|
25
|
+
token === '&' ||
|
|
26
|
+
token === '(' ||
|
|
27
|
+
token === ')' ||
|
|
28
|
+
token === ';' ||
|
|
29
|
+
token === '|' ||
|
|
30
|
+
token === '||' ||
|
|
31
|
+
token === '\n');
|
|
32
|
+
}
|
|
33
|
+
const OPTION_SPECS = [
|
|
34
|
+
['body', '--body', '-b'],
|
|
35
|
+
['bodyFile', '--body-file', '-F'],
|
|
36
|
+
['label', '--label', '-l'],
|
|
37
|
+
['repo', '--repo', '-R'],
|
|
38
|
+
['title', '--title', '-t'],
|
|
39
|
+
];
|
|
40
|
+
// Records the value for the first spec `token` names and returns how many tokens it consumed
|
|
41
|
+
// (2 for a separate value, 1 for an attached one, 0 when no spec matches).
|
|
42
|
+
function consumeOption(options, token, next) {
|
|
43
|
+
// A separator ends the command, so it is never an option's value.
|
|
44
|
+
const nextToken = next !== undefined && isGhCommandSeparator(next) ? undefined : next;
|
|
45
|
+
for (const [key, long, short] of OPTION_SPECS) {
|
|
46
|
+
if ((token === long || token === short) && addOptionValue(options, key, nextToken))
|
|
47
|
+
return 2;
|
|
48
|
+
const attached = optionValueFromLongToken(token, long) ?? attachedShortOptionValue(token, short);
|
|
49
|
+
if (addOptionValue(options, key, attached ?? undefined))
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
export function parseGhOptions(tokens) {
|
|
55
|
+
const options = {
|
|
56
|
+
body: [],
|
|
57
|
+
bodyFile: [],
|
|
58
|
+
draft: false,
|
|
59
|
+
label: [],
|
|
60
|
+
repo: [],
|
|
61
|
+
title: [],
|
|
62
|
+
};
|
|
63
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
64
|
+
const token = tokens[index];
|
|
65
|
+
if (isGhCommandSeparator(token))
|
|
66
|
+
break;
|
|
67
|
+
if (token === '--draft')
|
|
68
|
+
options.draft = true;
|
|
69
|
+
else
|
|
70
|
+
index += Math.max(consumeOption(options, token, tokens[index + 1]) - 1, 0);
|
|
71
|
+
}
|
|
72
|
+
return options;
|
|
73
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ResolvedStackPolicy } from './github-configured-base.mts';
|
|
2
|
+
import type { GhInvocation } from './github-invocation.mts';
|
|
3
|
+
import type { BlockDecision } from './types.mts';
|
|
4
|
+
/**
|
|
5
|
+
* `cwd` is the invocation's working directory, or undefined when it could not be determined (an
|
|
6
|
+
* unresolved `cd` target). The init HEAD-ancestry guard fails open in that case rather than
|
|
7
|
+
* substitute the session cwd.
|
|
8
|
+
*/
|
|
9
|
+
export declare function findGitHubStackWorkflowBlock(invocation: GhInvocation, cwd: string | undefined, policy: ResolvedStackPolicy): BlockDecision | null;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { findStackInitBaseBlock, withGuidance, } from "./github-configured-base.mjs";
|
|
2
|
+
import { hasNamedFlag, hasNumericPrSelector } from "./github-option-flags.mjs";
|
|
3
|
+
const STACK_AGENT_ACTIONS = new Set([
|
|
4
|
+
'add',
|
|
5
|
+
'bottom',
|
|
6
|
+
'checkout',
|
|
7
|
+
'delete',
|
|
8
|
+
'down',
|
|
9
|
+
'init',
|
|
10
|
+
'link',
|
|
11
|
+
'merge',
|
|
12
|
+
'push',
|
|
13
|
+
'rebase',
|
|
14
|
+
'submit',
|
|
15
|
+
'sync',
|
|
16
|
+
'top',
|
|
17
|
+
'unstack',
|
|
18
|
+
'up',
|
|
19
|
+
'view',
|
|
20
|
+
]);
|
|
21
|
+
const HELP_FLAGS = new Set(['--help', '-h']);
|
|
22
|
+
/**
|
|
23
|
+
* `cwd` is the invocation's working directory, or undefined when it could not be determined (an
|
|
24
|
+
* unresolved `cd` target). The init HEAD-ancestry guard fails open in that case rather than
|
|
25
|
+
* substitute the session cwd.
|
|
26
|
+
*/
|
|
27
|
+
export function findGitHubStackWorkflowBlock(invocation, cwd, policy) {
|
|
28
|
+
const stack = stackInvocation(invocation);
|
|
29
|
+
if (stack === null || isStackHelp(stack)) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const block = (reason) => ({
|
|
33
|
+
reason: withGuidance(reason, policy.guidance),
|
|
34
|
+
});
|
|
35
|
+
const { action, optionTokens } = stack;
|
|
36
|
+
const draftFirst = `New PRs must be opened as draft first.`;
|
|
37
|
+
const followUp = policy.draftFollowUp === '' ? '' : `, then ${policy.draftFollowUp}`;
|
|
38
|
+
if (!STACK_AGENT_ACTIONS.has(action)) {
|
|
39
|
+
return block('gh stack allowlist is closed. Use only the non-interactive commands. Interactive TUIs (modify, switch) and trunk are banned.');
|
|
40
|
+
}
|
|
41
|
+
if (action === 'init') {
|
|
42
|
+
return findStackInitBaseBlock(optionTokens, cwd, policy);
|
|
43
|
+
}
|
|
44
|
+
if (action === 'checkout') {
|
|
45
|
+
return isStackCheckoutTarget(optionTokens)
|
|
46
|
+
? null
|
|
47
|
+
: block('gh stack checkout takes exactly one stack number or PR number: `gh stack checkout <stack-number>`. The bare form is an interactive picker, and a branch-name target resolves only against stacks this worktree already tracks.');
|
|
48
|
+
}
|
|
49
|
+
if (action === 'submit') {
|
|
50
|
+
if (hasNamedFlag(optionTokens, 'open')) {
|
|
51
|
+
return block(`${draftFirst} Use \`gh stack submit --auto\`${followUp}.`);
|
|
52
|
+
}
|
|
53
|
+
return hasNamedFlag(optionTokens, 'auto')
|
|
54
|
+
? null
|
|
55
|
+
: block('gh stack submit is an interactive TUI. Use `gh stack submit --auto` so new stacked PRs open as drafts.');
|
|
56
|
+
}
|
|
57
|
+
if (action === 'link' && hasNamedFlag(optionTokens, 'open')) {
|
|
58
|
+
return block(`${draftFirst} Use \`gh stack link\` without --open${followUp}.`);
|
|
59
|
+
}
|
|
60
|
+
// Merge authority itself belongs to findAutomationMergeBlock and findInteractiveMergeConfirm.
|
|
61
|
+
if (action === 'merge' && !hasNumericPrSelector(optionTokens)) {
|
|
62
|
+
return block('gh stack merge requires a PR-number selector. Bare merge is a TUI and lands the whole stack. Use `gh stack merge --squash <pr>`.');
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
// Exactly one positive stack or PR number. The bare form opens a picker, and gh-stack resolves a
|
|
67
|
+
// branch name only against stacks this worktree already tracks.
|
|
68
|
+
function isStackCheckoutTarget(optionTokens) {
|
|
69
|
+
return optionTokens.length === 1 && /^[1-9]\d*$/.test(optionTokens[0]);
|
|
70
|
+
}
|
|
71
|
+
// gh-stack is a cobra CLI. Its root command only prints help, `help [command]` only prints help,
|
|
72
|
+
// and `--help` or `-h` prints a command's help and exits before the command runs. Only the bare
|
|
73
|
+
// forms count, since a `--` or any other argument beside the flag can change what runs.
|
|
74
|
+
function isStackHelp({ action, optionTokens }) {
|
|
75
|
+
if (HELP_FLAGS.has(action) || action === 'help') {
|
|
76
|
+
return (optionTokens.length === 0 ||
|
|
77
|
+
(action === 'help' && optionTokens.length === 1 && STACK_AGENT_ACTIONS.has(optionTokens[0])));
|
|
78
|
+
}
|
|
79
|
+
return (STACK_AGENT_ACTIONS.has(action) && optionTokens.length === 1 && HELP_FLAGS.has(optionTokens[0]));
|
|
80
|
+
}
|
|
81
|
+
const EXTENSION_AREAS = new Set(['extension', 'extensions', 'ext']);
|
|
82
|
+
function stackInvocation(invocation) {
|
|
83
|
+
if (invocation.area === 'stack') {
|
|
84
|
+
return invocation;
|
|
85
|
+
}
|
|
86
|
+
const action = invocation.optionTokens[1];
|
|
87
|
+
if (EXTENSION_AREAS.has(invocation.area) &&
|
|
88
|
+
invocation.action === 'exec' &&
|
|
89
|
+
invocation.optionTokens[0] === 'stack' &&
|
|
90
|
+
action !== undefined) {
|
|
91
|
+
return { ...invocation, action, area: 'stack', optionTokens: invocation.optionTokens.slice(2) };
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BlockDecision, StackPolicy } from './types.mts';
|
|
2
|
+
export type GitHubWorkflowPolicy = {
|
|
3
|
+
automationContext: boolean;
|
|
4
|
+
mergeGuidance?: string | undefined;
|
|
5
|
+
stack?: StackPolicy | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare function findGitHubWorkflowBlock(command: string, cwd: string, policy: GitHubWorkflowPolicy): BlockDecision | null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { tokenizeShellWordsDetailed } from "../shell-parse/index.mjs";
|
|
2
|
+
import { commandsToInspectForGitHubPolicy } from "./github-command-context.mjs";
|
|
3
|
+
import { commandCwd } from "./github-command-cwd.mjs";
|
|
4
|
+
import { commandPrefixAt } from "./github-command-position.mjs";
|
|
5
|
+
import { defaultGitProbe } from "./git-process.mjs";
|
|
6
|
+
import { parseGhOrGhStackInvocation } from "./github-invocation.mjs";
|
|
7
|
+
import { findAutomationMergeBlock } from "./github-merge-authority.mjs";
|
|
8
|
+
import { findGitHubStackWorkflowBlock } from "./github-stack-workflow.mjs";
|
|
9
|
+
function resolveStackPolicy(stack) {
|
|
10
|
+
return {
|
|
11
|
+
baseBranch: stack.baseBranch ?? 'main',
|
|
12
|
+
remote: stack.remote ?? 'origin',
|
|
13
|
+
guidance: stack.guidance ?? '',
|
|
14
|
+
draftFollowUp: stack.draftFollowUp ?? '',
|
|
15
|
+
git: stack.git ?? defaultGitProbe,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function findGitHubWorkflowBlock(command, cwd, policy) {
|
|
19
|
+
const stackBlock = policy.stack === undefined
|
|
20
|
+
? null
|
|
21
|
+
: findStackBlock(command, cwd, resolveStackPolicy(policy.stack));
|
|
22
|
+
// The specific reasons win; any other merge in automation gets the coarse block.
|
|
23
|
+
return (stackBlock ??
|
|
24
|
+
findAutomationMergeBlock(command, policy.automationContext, policy.mergeGuidance ?? ''));
|
|
25
|
+
}
|
|
26
|
+
function findStackBlock(command, cwd, stack) {
|
|
27
|
+
for (const commandToInspect of commandsToInspectForGitHubPolicy(command)) {
|
|
28
|
+
const tokens = tokenizeShellWordsDetailed(commandToInspect, { splitRedirections: true }).map((token) => token.value);
|
|
29
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
30
|
+
if (!mayRunGh(tokens[index]) || commandPrefixAt(tokens, index) === null) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const invocation = parseGhOrGhStackInvocation(tokens, index);
|
|
34
|
+
if (invocation === null) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const block = findGitHubStackWorkflowBlock(invocation, commandCwd(tokens, index, cwd), stack);
|
|
38
|
+
if (block !== null) {
|
|
39
|
+
return block;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
// Every policy above reads a gh or gh-stack command. Skipping other words before commandPrefixAt
|
|
46
|
+
// keeps a long command from rescanning its segment at every word.
|
|
47
|
+
function mayRunGh(word) {
|
|
48
|
+
const name = word.slice(word.lastIndexOf('/') + 1);
|
|
49
|
+
return name === 'gh' || name === 'gh-stack';
|
|
50
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HookHarness } from './types.mts';
|
|
2
|
+
export type HookArgs = {
|
|
3
|
+
event: 'pre-tool-use' | 'post-tool-use';
|
|
4
|
+
harness: HookHarness;
|
|
5
|
+
policy: string;
|
|
6
|
+
root?: string;
|
|
7
|
+
/** Environment variable names that mark an unattended run when set (see isAutomationContext). */
|
|
8
|
+
automationEnv: string[];
|
|
9
|
+
};
|
|
10
|
+
/** Parses `hook` arguments; throws a usage error naming the first problem. */
|
|
11
|
+
export declare function parseHookArgs(args: readonly string[]): HookArgs;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HOOK_HARNESSES } from "./types.mjs";
|
|
2
|
+
const HOOK_USAGE = 'usage: vouchington hook pre-tool-use|post-tool-use --harness claude|codex|cursor|grok --policy <module> [--root <dir>] [--automation-env NAME]...';
|
|
3
|
+
const VALUE_FLAGS = new Set(['--harness', '--policy', '--root', '--automation-env']);
|
|
4
|
+
/** Parses `hook` arguments; throws a usage error naming the first problem. */
|
|
5
|
+
export function parseHookArgs(args) {
|
|
6
|
+
const [event, ...rest] = args;
|
|
7
|
+
if (event !== 'pre-tool-use' && event !== 'post-tool-use') {
|
|
8
|
+
throw new Error(`${HOOK_USAGE}\nunknown or missing hook event: ${event ?? '(none)'}`);
|
|
9
|
+
}
|
|
10
|
+
const flags = parseFlags(rest);
|
|
11
|
+
const harness = flags.harness;
|
|
12
|
+
if (!HOOK_HARNESSES.includes(harness)) {
|
|
13
|
+
throw new Error(`${HOOK_USAGE}\n--harness must be one of ${HOOK_HARNESSES.join(', ')}`);
|
|
14
|
+
}
|
|
15
|
+
if (flags.policy === undefined || flags.policy === '') {
|
|
16
|
+
throw new Error(`${HOOK_USAGE}\n--policy <module> is required`);
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
event,
|
|
20
|
+
harness: harness,
|
|
21
|
+
policy: flags.policy,
|
|
22
|
+
automationEnv: flags.automationEnv,
|
|
23
|
+
...(flags.root === undefined ? {} : { root: flags.root }),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function parseFlags(args) {
|
|
27
|
+
const flags = { automationEnv: [] };
|
|
28
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
29
|
+
const arg = args[index];
|
|
30
|
+
const [name, inline] = arg.startsWith('--') ? splitFlag(arg) : [arg, undefined];
|
|
31
|
+
if (!VALUE_FLAGS.has(name)) {
|
|
32
|
+
throw new Error(`${HOOK_USAGE}\nunknown argument: ${arg}`);
|
|
33
|
+
}
|
|
34
|
+
const value = inline ?? args[(index += 1)];
|
|
35
|
+
// A flag-looking token is the next flag, not this flag's value (`--policy --root x`).
|
|
36
|
+
if (value === undefined || (inline === undefined && value.startsWith('--'))) {
|
|
37
|
+
throw new Error(`${HOOK_USAGE}\n${name} needs a value`);
|
|
38
|
+
}
|
|
39
|
+
if (name === '--automation-env')
|
|
40
|
+
flags.automationEnv.push(value);
|
|
41
|
+
else
|
|
42
|
+
flags[name.slice(2)] = value;
|
|
43
|
+
}
|
|
44
|
+
return flags;
|
|
45
|
+
}
|
|
46
|
+
function splitFlag(arg) {
|
|
47
|
+
const equals = arg.indexOf('=');
|
|
48
|
+
return equals === -1 ? [arg, undefined] : [arg.slice(0, equals), arg.slice(equals + 1)];
|
|
49
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { HookPayload } from '../types.mts';
|
|
2
|
+
import type { HookHarness } from './types.mts';
|
|
3
|
+
/**
|
|
4
|
+
* True when the process runs unattended, where merge authority is never delegated: Claude's
|
|
5
|
+
* `claude -p` (`CLAUDE_CODE_SESSION_ATTENDED=0`) or a CI marker. `extraMarkers` adds
|
|
6
|
+
* caller-specific variable names.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isAutomationContext(env: NodeJS.ProcessEnv, extraMarkers?: readonly string[]): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Parses hook stdin into a payload. Blank, invalid, or non-object input is an empty payload unless
|
|
11
|
+
* `strict`, which throws so a blocking hook fails closed instead of reading a missing or truncated
|
|
12
|
+
* payload as "nothing to judge".
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseHookPayload(stdin: string, strict?: boolean): HookPayload;
|
|
15
|
+
export declare function normalizeCursorShellPayload(payload: HookPayload): HookPayload;
|
|
16
|
+
/**
|
|
17
|
+
* The harness actually calling. Grok and Cursor reuse another harness's hook configuration, so
|
|
18
|
+
* their own env and payload markers win over the declared `--harness`. Cursor resolves before
|
|
19
|
+
* `claude` is trusted because it inherits Claude's attended env when launched from a Claude session.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveHarness(declared: HookHarness, env: NodeJS.ProcessEnv, payload: HookPayload): HookHarness;
|
|
22
|
+
/**
|
|
23
|
+
* True only when Claude Code marks the session attended (CLAUDE_CODE_SESSION_ATTENDED=1; 0 for
|
|
24
|
+
* `claude -p`). A missing or changed variable fails safe: no silent merge allow.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isAttendedClaudeSession(env: NodeJS.ProcessEnv): boolean;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { isRecord } from "../payload.mjs";
|
|
2
|
+
/** Environment variables that mark an automated launch. Set to anything but empty, `0`, or `false`. */
|
|
3
|
+
const AUTOMATION_MARKERS = [
|
|
4
|
+
'CI',
|
|
5
|
+
'GITHUB_ACTIONS',
|
|
6
|
+
'GITLAB_CI',
|
|
7
|
+
'BUILDKITE',
|
|
8
|
+
'CIRCLECI',
|
|
9
|
+
'JENKINS_URL',
|
|
10
|
+
'TF_BUILD',
|
|
11
|
+
'CODEBUILD_BUILD_ID',
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* True when the process runs unattended, where merge authority is never delegated: Claude's
|
|
15
|
+
* `claude -p` (`CLAUDE_CODE_SESSION_ATTENDED=0`) or a CI marker. `extraMarkers` adds
|
|
16
|
+
* caller-specific variable names.
|
|
17
|
+
*/
|
|
18
|
+
export function isAutomationContext(env, extraMarkers = []) {
|
|
19
|
+
if (env.CLAUDE_CODE_SESSION_ATTENDED === '0')
|
|
20
|
+
return true;
|
|
21
|
+
return [...AUTOMATION_MARKERS, ...extraMarkers].some((name) => {
|
|
22
|
+
const value = env[name]?.trim().toLowerCase();
|
|
23
|
+
return value !== undefined && value !== '' && value !== '0' && value !== 'false';
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parses hook stdin into a payload. Blank, invalid, or non-object input is an empty payload unless
|
|
28
|
+
* `strict`, which throws so a blocking hook fails closed instead of reading a missing or truncated
|
|
29
|
+
* payload as "nothing to judge".
|
|
30
|
+
*/
|
|
31
|
+
export function parseHookPayload(stdin, strict = false) {
|
|
32
|
+
if (stdin.trim() === '') {
|
|
33
|
+
if (strict)
|
|
34
|
+
throw new Error('hook payload is empty');
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(stdin);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (strict)
|
|
43
|
+
throw new Error(`hook payload is not valid JSON: ${error.message}`);
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
if (isRecord(parsed) && !Array.isArray(parsed))
|
|
47
|
+
return normalizeCursorShellPayload(parsed);
|
|
48
|
+
if (strict)
|
|
49
|
+
throw new Error('hook payload is not a JSON object');
|
|
50
|
+
return {};
|
|
51
|
+
}
|
|
52
|
+
// Cursor runs the Claude-compat hooks but names its shell tool `Shell` and reports the result as
|
|
53
|
+
// `tool_output`, a JSON string `{exitCode, output}`. Normalizing both to Claude's `Bash` +
|
|
54
|
+
// `tool_response` shape means policy reads one payload dialect. An existing `tool_response` is
|
|
55
|
+
// never overwritten.
|
|
56
|
+
export function normalizeCursorShellPayload(payload) {
|
|
57
|
+
if (payload.tool_name !== 'Shell')
|
|
58
|
+
return payload;
|
|
59
|
+
const result = cursorShellResult(payload.tool_output);
|
|
60
|
+
return {
|
|
61
|
+
...payload,
|
|
62
|
+
tool_name: 'Bash',
|
|
63
|
+
...(result === undefined || payload.tool_response !== undefined
|
|
64
|
+
? {}
|
|
65
|
+
: { tool_response: result }),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function cursorShellResult(raw) {
|
|
69
|
+
let parsed = raw;
|
|
70
|
+
if (typeof raw === 'string') {
|
|
71
|
+
try {
|
|
72
|
+
parsed = JSON.parse(raw);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!isRecord(parsed) || typeof parsed.exitCode !== 'number')
|
|
79
|
+
return undefined;
|
|
80
|
+
return {
|
|
81
|
+
exit_code: parsed.exitCode,
|
|
82
|
+
stdout: firstString(parsed.stdout, parsed.output),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// GROK_AGENT is deliberately not a signal: it is a shell-level marker that could be exported in a
|
|
86
|
+
// Claude or Codex session.
|
|
87
|
+
function isGrokHookProcess(env) {
|
|
88
|
+
return Boolean(env.GROK_SESSION_ID || env.GROK_HOOK_EVENT);
|
|
89
|
+
}
|
|
90
|
+
// Cursor passes `cursor_version` in every payload and sets CURSOR_VERSION/CURSOR_PROJECT_DIR in the
|
|
91
|
+
// hook env. It runs the Claude-compat config, so the markers only override `claude`, never `codex`.
|
|
92
|
+
function isCursorHookProcess(declared, env, payload) {
|
|
93
|
+
return (declared === 'claude' &&
|
|
94
|
+
(typeof payload.cursor_version === 'string' ||
|
|
95
|
+
Boolean(env.CURSOR_VERSION || env.CURSOR_PROJECT_DIR)));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The harness actually calling. Grok and Cursor reuse another harness's hook configuration, so
|
|
99
|
+
* their own env and payload markers win over the declared `--harness`. Cursor resolves before
|
|
100
|
+
* `claude` is trusted because it inherits Claude's attended env when launched from a Claude session.
|
|
101
|
+
*/
|
|
102
|
+
export function resolveHarness(declared, env, payload) {
|
|
103
|
+
if (isGrokHookProcess(env))
|
|
104
|
+
return 'grok';
|
|
105
|
+
if (isCursorHookProcess(declared, env, payload))
|
|
106
|
+
return 'cursor';
|
|
107
|
+
return declared;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* True only when Claude Code marks the session attended (CLAUDE_CODE_SESSION_ATTENDED=1; 0 for
|
|
111
|
+
* `claude -p`). A missing or changed variable fails safe: no silent merge allow.
|
|
112
|
+
*/
|
|
113
|
+
export function isAttendedClaudeSession(env) {
|
|
114
|
+
return env.CLAUDE_CODE_SESSION_ATTENDED === '1';
|
|
115
|
+
}
|
|
116
|
+
// Cursor documents `stdout`; `output` is kept as a fallback for older payloads.
|
|
117
|
+
function firstString(...values) {
|
|
118
|
+
return values.find((value) => typeof value === 'string') ?? '';
|
|
119
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HookContext, HookPolicy } from './types.mts';
|
|
2
|
+
/**
|
|
3
|
+
* Imports a `--policy` module and resolves its policy. The module's default export (or a named
|
|
4
|
+
* `policy` export) is a `HookPolicy` object or a function of the hook context that returns one.
|
|
5
|
+
* A relative path resolves against the repository root.
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadHookPolicy(specifier: string, context: HookContext): Promise<HookPolicy>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { resolve } from 'node:path';
|
|
10
|
+
import { pathToFileURL } from 'node:url';
|
|
11
|
+
import { isRecord } from "../payload.mjs";
|
|
12
|
+
/**
|
|
13
|
+
* Imports a `--policy` module and resolves its policy. The module's default export (or a named
|
|
14
|
+
* `policy` export) is a `HookPolicy` object or a function of the hook context that returns one.
|
|
15
|
+
* A relative path resolves against the repository root.
|
|
16
|
+
*/
|
|
17
|
+
export async function loadHookPolicy(specifier, context) {
|
|
18
|
+
const url = pathToFileURL(resolve(context.root, specifier)).href;
|
|
19
|
+
const loaded = (await import(__rewriteRelativeImportExtension(url)));
|
|
20
|
+
const exported = selectExport(loaded);
|
|
21
|
+
const policy = typeof exported === 'function' ? await exported(context) : exported;
|
|
22
|
+
if (!isRecord(policy) || Array.isArray(policy)) {
|
|
23
|
+
throw new Error(`policy module ${specifier} must default-export a policy object or a function returning one`);
|
|
24
|
+
}
|
|
25
|
+
return validated(policy, specifier);
|
|
26
|
+
}
|
|
27
|
+
const FIELD_SHAPES = {
|
|
28
|
+
command: (value) => isRecord(value) && !Array.isArray(value),
|
|
29
|
+
checkers: Array.isArray,
|
|
30
|
+
reminder: (value) => typeof value === 'function',
|
|
31
|
+
onPayload: (value) => typeof value === 'function',
|
|
32
|
+
};
|
|
33
|
+
// A misspelled shape would silently disable the policy, so a present field must have its type.
|
|
34
|
+
function validated(policy, specifier) {
|
|
35
|
+
for (const [field, isValid] of Object.entries(FIELD_SHAPES)) {
|
|
36
|
+
if (policy[field] !== undefined && !isValid(policy[field])) {
|
|
37
|
+
throw new Error(`policy module ${specifier} has an invalid \`${field}\``);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return policy;
|
|
41
|
+
}
|
|
42
|
+
// A CommonJS module's `default` is its whole `module.exports`, so `exports.policy = {...}` shows up as
|
|
43
|
+
// `default: { policy }` beside the named `policy`; the named export is the policy then.
|
|
44
|
+
function selectExport(loaded) {
|
|
45
|
+
const wrapper = loaded.default;
|
|
46
|
+
const wrapsNamed = isRecord(wrapper) && loaded.policy !== undefined && wrapper.policy === loaded.policy;
|
|
47
|
+
return wrapsNamed ? loaded.policy : (wrapper ?? loaded.policy);
|
|
48
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HookContext, HookPolicy, PostToolUseWarning } from './types.mts';
|
|
2
|
+
/** Runs every matching checker. A checker that throws becomes one error warning, never a crash. */
|
|
3
|
+
export declare function checkFile(filePath: string, root: string, checkers?: HookPolicy['checkers']): PostToolUseWarning[];
|
|
4
|
+
/**
|
|
5
|
+
* The stdout of a post-tool-use hook: one `additionalContext` JSON object carrying the checkers'
|
|
6
|
+
* `[level] message` lines and the reminder, or an empty string when there is nothing to say. The
|
|
7
|
+
* hook is advisory and never blocks, so failures here are swallowed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function postToolUseOutput(context: HookContext, policy: HookPolicy): Promise<string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { hookFilePath, hookToolInput } from "../payload.mjs";
|
|
2
|
+
import { patchResultPaths } from "../path-references.mjs";
|
|
3
|
+
function failure(error) {
|
|
4
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5
|
+
return { level: 'error', message: `Unexpected error in post-tool-use checks: ${message}` };
|
|
6
|
+
}
|
|
7
|
+
/** Runs every matching checker. A checker that throws becomes one error warning, never a crash. */
|
|
8
|
+
export function checkFile(filePath, root, checkers = []) {
|
|
9
|
+
return checkers.flatMap((checker) => {
|
|
10
|
+
try {
|
|
11
|
+
return checker.matches(filePath, root) ? checker.check(filePath, root) : [];
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
return [failure(error)];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// Edit/Write report `file_path`; Codex's apply_patch carries every touched file in its patch headers,
|
|
19
|
+
// and only files that exist afterwards are checked.
|
|
20
|
+
function editedPaths(context) {
|
|
21
|
+
const command = hookToolInput(context.payload)?.command;
|
|
22
|
+
if (typeof command === 'string' && command.startsWith('*** Begin Patch')) {
|
|
23
|
+
return patchResultPaths(command);
|
|
24
|
+
}
|
|
25
|
+
const filePath = hookFilePath(context.payload);
|
|
26
|
+
return filePath === '' ? [] : [filePath];
|
|
27
|
+
}
|
|
28
|
+
async function reminderOf(policy, context) {
|
|
29
|
+
try {
|
|
30
|
+
return (await policy.reminder?.(context)) || null;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The stdout of a post-tool-use hook: one `additionalContext` JSON object carrying the checkers'
|
|
38
|
+
* `[level] message` lines and the reminder, or an empty string when there is nothing to say. The
|
|
39
|
+
* hook is advisory and never blocks, so failures here are swallowed.
|
|
40
|
+
*/
|
|
41
|
+
export async function postToolUseOutput(context, policy) {
|
|
42
|
+
const warnings = editedPaths(context).flatMap((path) => checkFile(path, context.root, policy.checkers));
|
|
43
|
+
const lines = warnings.map(({ level, message }) => `[${level}] ${message}`);
|
|
44
|
+
const reminder = await reminderOf(policy, context);
|
|
45
|
+
const text = [...lines, ...(reminder === null ? [] : [reminder])].join('\n');
|
|
46
|
+
if (text === '')
|
|
47
|
+
return '';
|
|
48
|
+
return `${JSON.stringify({
|
|
49
|
+
hookSpecificOutput: { additionalContext: text, hookEventName: 'PostToolUse' },
|
|
50
|
+
})}\n`;
|
|
51
|
+
}
|