vouchington-tooling 0.65.0 → 0.66.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 +2 -0
- package/dist/shell-parse/git-invocations.d.mts +25 -0
- package/dist/shell-parse/git-invocations.mjs +153 -0
- package/dist/shell-parse/git-wrapper-options.d.mts +7 -0
- package/dist/shell-parse/git-wrapper-options.mjs +80 -0
- package/dist/shell-parse/index.d.mts +2 -0
- package/dist/shell-parse/index.mjs +1 -0
- package/dist/transient-retry/run-context-rule-attempts.mjs +2 -4
- package/package.json +1 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
package/README.md
CHANGED
|
@@ -581,6 +581,8 @@ import { tokenizeShellWords } from 'vouchington-tooling/shell-parse'
|
|
|
581
581
|
|
|
582
582
|
`vouchington-tooling/shell-parse` splits shell text into words, heredocs, redirections, and command prefixes. Callers pass the text. The parser does not decide which commands are allowed. `stripQuotedShellText` and `commandsToInspect*` do not scan `$(...)` substitutions in the command text: call `extractShellCommandSubstitutions` and inspect each result too.
|
|
583
583
|
|
|
584
|
+
`gitInvocations(command)` returns each `git` run in command position (after `;`, `&&`, `||`, `|`, a newline, env assignments, or wrappers such as `env`, `sudo`, `xargs`, `timeout`, `nice`) as `{ globalOptions, configOverrides: [{ key, value }], subcommand, args }`. Global options (`-c`, `-C`, `--git-dir`, `--no-pager`, ...) are skipped to reach the subcommand, and `git` as an argument (`printf '%s' git`) is not an invocation. `overridesConfig(invocation, 'core.hooksPath')` checks the `-c` keys case-insensitively. Substitutions and `bash -c` scripts are not read; run it on each result of `extractShellCommandSubstitutions` and `extractShellCommandArguments`. Known best-effort limits: value options inside clustered short wrapper flags are not read, backtick bodies are not read, and a quoted redirection-looking word mid-argv can truncate `args`.
|
|
585
|
+
|
|
584
586
|
`vouchington-tooling/command-policy` judges a tool call's shell command against a rule table the
|
|
585
587
|
caller supplies. `evaluateCommandPolicy(payload, policy, { automationContext })` returns a
|
|
586
588
|
`BlockDecision` or `null`. The `CommandPolicy` table holds typo paths, protected paths (blocked only
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** One `-c key=value` (or `--config-env=key=ENVVAR`, whose value is the variable name). */
|
|
2
|
+
export type GitConfigOverride = {
|
|
3
|
+
key: string;
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
export type GitInvocation = {
|
|
7
|
+
/** Subcommand arguments, unquoted, up to the end of the command segment. */
|
|
8
|
+
args: string[];
|
|
9
|
+
/** `-c key=value` pairs in order, with each key as written. */
|
|
10
|
+
configOverrides: GitConfigOverride[];
|
|
11
|
+
/** Every global option word skipped to reach the subcommand, as written (`['-C', '/x']`). */
|
|
12
|
+
globalOptions: string[];
|
|
13
|
+
/** The subcommand word, or undefined for a bare `git` or `git --version`. */
|
|
14
|
+
subcommand: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Each `git` the shell would run in command position: after a separator, env assignments, or a
|
|
18
|
+
* wrapper (`env`, `sudo`, `xargs`, `timeout`, `nice`, ...). A `git` word in argument position
|
|
19
|
+
* (`printf %s git`) is not an invocation. Global options are skipped to reach the subcommand and
|
|
20
|
+
* `-c` pairs are collected. `$(...)` text and `bash -c` scripts are not read: feed those to
|
|
21
|
+
* `extractShellCommandSubstitutions` / `extractShellCommandArguments` and call this on each.
|
|
22
|
+
*/
|
|
23
|
+
export declare function gitInvocations(command: string): GitInvocation[];
|
|
24
|
+
/** True when the invocation sets `key` with `-c`. Keys compare case-insensitively. */
|
|
25
|
+
export declare function overridesConfig(invocation: GitInvocation, key: string): boolean;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { EXTRA_WRAPPERS, skipWrapper } from "./git-wrapper-options.mjs";
|
|
2
|
+
import { stripNonShellHeredocBodies } from "./shell-heredoc.mjs";
|
|
3
|
+
import { readCommandPrefix, withoutRedirections } from "./shell-command-wrappers.mjs";
|
|
4
|
+
import { tokenizeShellWordsDetailed } from "./shell-tokenizer.mjs";
|
|
5
|
+
const VALUE_OPTIONS = new Set([
|
|
6
|
+
'-C',
|
|
7
|
+
'-c',
|
|
8
|
+
'--git-dir',
|
|
9
|
+
'--work-tree',
|
|
10
|
+
'--namespace',
|
|
11
|
+
'--config-env',
|
|
12
|
+
'--super-prefix',
|
|
13
|
+
'--attr-source',
|
|
14
|
+
]);
|
|
15
|
+
// These print and exit: any later word is not a subcommand.
|
|
16
|
+
const TERMINAL_OPTIONS = new Set([
|
|
17
|
+
'-h',
|
|
18
|
+
'-v',
|
|
19
|
+
'--exec-path',
|
|
20
|
+
'--help',
|
|
21
|
+
'--html-path',
|
|
22
|
+
'--info-path',
|
|
23
|
+
'--man-path',
|
|
24
|
+
'--version',
|
|
25
|
+
]);
|
|
26
|
+
const FLAG_OPTIONS = new Set([
|
|
27
|
+
'-p',
|
|
28
|
+
'-P',
|
|
29
|
+
'--bare',
|
|
30
|
+
'--glob-pathspecs',
|
|
31
|
+
'--icase-pathspecs',
|
|
32
|
+
'--literal-pathspecs',
|
|
33
|
+
'--no-advice',
|
|
34
|
+
'--no-lazy-fetch',
|
|
35
|
+
'--no-literal-pathspecs',
|
|
36
|
+
'--no-optional-locks',
|
|
37
|
+
'--no-pager',
|
|
38
|
+
'--no-replace-objects',
|
|
39
|
+
'--noglob-pathspecs',
|
|
40
|
+
'--paginate',
|
|
41
|
+
]);
|
|
42
|
+
const ATTACHED_OPTION = /^--(?:git-dir|work-tree|namespace|exec-path|config-env|super-prefix|attr-source|list-cmds)=/;
|
|
43
|
+
const CONFIG_ENV_PREFIX = '--config-env=';
|
|
44
|
+
/**
|
|
45
|
+
* Each `git` the shell would run in command position: after a separator, env assignments, or a
|
|
46
|
+
* wrapper (`env`, `sudo`, `xargs`, `timeout`, `nice`, ...). A `git` word in argument position
|
|
47
|
+
* (`printf %s git`) is not an invocation. Global options are skipped to reach the subcommand and
|
|
48
|
+
* `-c` pairs are collected. `$(...)` text and `bash -c` scripts are not read: feed those to
|
|
49
|
+
* `extractShellCommandSubstitutions` / `extractShellCommandArguments` and call this on each.
|
|
50
|
+
*/
|
|
51
|
+
export function gitInvocations(command) {
|
|
52
|
+
const invocations = [];
|
|
53
|
+
for (const segment of segmentsOf(command)) {
|
|
54
|
+
const words = commandWords(segment);
|
|
55
|
+
if (words !== null && basename(words[0]) === 'git')
|
|
56
|
+
invocations.push(readInvocation(words));
|
|
57
|
+
}
|
|
58
|
+
return invocations;
|
|
59
|
+
}
|
|
60
|
+
/** True when the invocation sets `key` with `-c`. Keys compare case-insensitively. */
|
|
61
|
+
export function overridesConfig(invocation, key) {
|
|
62
|
+
const wanted = key.toLowerCase();
|
|
63
|
+
return invocation.configOverrides.some((override) => override.key.toLowerCase() === wanted);
|
|
64
|
+
}
|
|
65
|
+
// Heredoc bodies that are data are dropped. A `$(` opens a substitution, `name=(` an array literal, and `<(` / `>(` a process substitution;: its body is skipped (it
|
|
66
|
+
// belongs to `extractShellCommandSubstitutions`) so the outer command keeps its later arguments.
|
|
67
|
+
function segmentsOf(command) {
|
|
68
|
+
const segments = [[]];
|
|
69
|
+
let depth = 0;
|
|
70
|
+
const words = tokenizeShellWordsDetailed(stripNonShellHeredocBodies(command).textWithoutBodies, {
|
|
71
|
+
markOperators: true,
|
|
72
|
+
splitRedirections: true,
|
|
73
|
+
});
|
|
74
|
+
for (const word of words) {
|
|
75
|
+
const current = segments.at(-1);
|
|
76
|
+
if (depth > 0 ||
|
|
77
|
+
(word.operator === true && word.value === '(' && /[$=<>]$/.test(current.at(-1) ?? ''))) {
|
|
78
|
+
// A bare `<` / `>` before `(` is a process substitution, not a redirection of the next word.
|
|
79
|
+
if (/^[<>]$/.test(current.at(-1)))
|
|
80
|
+
current.pop();
|
|
81
|
+
if (word.operator === true)
|
|
82
|
+
depth += word.value === '(' ? 1 : word.value === ')' ? -1 : 0;
|
|
83
|
+
}
|
|
84
|
+
else if (word.operator === true) {
|
|
85
|
+
segments.push([]);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
current.push(word.value);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return segments;
|
|
92
|
+
}
|
|
93
|
+
function basename(word) {
|
|
94
|
+
return word.slice(word.lastIndexOf('/') + 1);
|
|
95
|
+
}
|
|
96
|
+
/** The words from the command word on, or null when the segment runs nothing readable. */
|
|
97
|
+
function commandWords(segment) {
|
|
98
|
+
// A quoted `'>'` argument is indistinguishable from a redirection here; keep the words then.
|
|
99
|
+
let words = withoutRedirections(segment) ?? segment;
|
|
100
|
+
for (;;) {
|
|
101
|
+
const read = readCommandPrefix(words);
|
|
102
|
+
if (read === null || read.commandIndex >= words.length)
|
|
103
|
+
return null;
|
|
104
|
+
words = words.slice(read.commandIndex);
|
|
105
|
+
const wrapper = EXTRA_WRAPPERS.get(basename(words[0]));
|
|
106
|
+
if (wrapper === undefined)
|
|
107
|
+
return words;
|
|
108
|
+
words = skipWrapper(words, wrapper);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function readInvocation(words) {
|
|
112
|
+
const globalOptions = [];
|
|
113
|
+
const configOverrides = [];
|
|
114
|
+
let cursor = 1;
|
|
115
|
+
while (cursor < words.length) {
|
|
116
|
+
const word = words[cursor];
|
|
117
|
+
if (VALUE_OPTIONS.has(word)) {
|
|
118
|
+
const value = words[cursor + 1];
|
|
119
|
+
if (value === undefined)
|
|
120
|
+
break;
|
|
121
|
+
globalOptions.push(word, value);
|
|
122
|
+
if (word === '-c' || word === '--config-env')
|
|
123
|
+
configOverrides.push(splitOverride(value));
|
|
124
|
+
cursor += 2;
|
|
125
|
+
}
|
|
126
|
+
else if (TERMINAL_OPTIONS.has(word)) {
|
|
127
|
+
globalOptions.push(word);
|
|
128
|
+
return { args: [], configOverrides, globalOptions, subcommand: undefined };
|
|
129
|
+
}
|
|
130
|
+
else if (FLAG_OPTIONS.has(word) || ATTACHED_OPTION.test(word)) {
|
|
131
|
+
globalOptions.push(word);
|
|
132
|
+
if (word.startsWith(CONFIG_ENV_PREFIX)) {
|
|
133
|
+
configOverrides.push(splitOverride(word.slice(CONFIG_ENV_PREFIX.length)));
|
|
134
|
+
}
|
|
135
|
+
cursor += 1;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
args: words.slice(cursor + 1),
|
|
143
|
+
configOverrides,
|
|
144
|
+
globalOptions,
|
|
145
|
+
subcommand: words[cursor],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function splitOverride(pair) {
|
|
149
|
+
const equals = pair.indexOf('=');
|
|
150
|
+
return equals < 0
|
|
151
|
+
? { key: pair, value: '' }
|
|
152
|
+
: { key: pair.slice(0, equals), value: pair.slice(equals + 1) };
|
|
153
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type ExtraWrapper = {
|
|
2
|
+
duration?: true;
|
|
3
|
+
values: readonly string[];
|
|
4
|
+
};
|
|
5
|
+
export declare const EXTRA_WRAPPERS: ReadonlyMap<string, ExtraWrapper>;
|
|
6
|
+
/** The words after a wrapper's own options (and `timeout`'s duration). */
|
|
7
|
+
export declare function skipWrapper(words: string[], wrapper: ExtraWrapper): string[];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Wrappers `readCommandPrefix` does not read through, with the options that take a separate value.
|
|
2
|
+
export const EXTRA_WRAPPERS = new Map([
|
|
3
|
+
['doas', { values: ['-u', '-C'] }],
|
|
4
|
+
[
|
|
5
|
+
'ionice',
|
|
6
|
+
{
|
|
7
|
+
values: ['-c', '-n', '-p', '-P', '-u', '--class', '--classdata', '--pid', '--pgid', '--uid'],
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
['nice', { values: ['-n', '--adjustment'] }],
|
|
11
|
+
['setsid', { values: [] }],
|
|
12
|
+
['stdbuf', { values: ['-i', '-o', '-e', '--input', '--output', '--error'] }],
|
|
13
|
+
[
|
|
14
|
+
'sudo',
|
|
15
|
+
{
|
|
16
|
+
values: [
|
|
17
|
+
'-u',
|
|
18
|
+
'-g',
|
|
19
|
+
'-h',
|
|
20
|
+
'-p',
|
|
21
|
+
'-C',
|
|
22
|
+
'-D',
|
|
23
|
+
'-R',
|
|
24
|
+
'-T',
|
|
25
|
+
'-U',
|
|
26
|
+
'-r',
|
|
27
|
+
'-t',
|
|
28
|
+
'--user',
|
|
29
|
+
'--group',
|
|
30
|
+
'--host',
|
|
31
|
+
'--prompt',
|
|
32
|
+
'--close-from',
|
|
33
|
+
'--chdir',
|
|
34
|
+
'--chroot',
|
|
35
|
+
'--command-timeout',
|
|
36
|
+
'--other-user',
|
|
37
|
+
'--role',
|
|
38
|
+
'--type',
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
['timeout', { duration: true, values: ['-s', '-k', '--signal', '--kill-after'] }],
|
|
43
|
+
[
|
|
44
|
+
'xargs',
|
|
45
|
+
{
|
|
46
|
+
// `--replace`, `--eof` and `--max-lines` take their value only attached (`--eof=END`).
|
|
47
|
+
values: [
|
|
48
|
+
'-I',
|
|
49
|
+
'-n',
|
|
50
|
+
'-P',
|
|
51
|
+
'-L',
|
|
52
|
+
'-s',
|
|
53
|
+
'-E',
|
|
54
|
+
'-d',
|
|
55
|
+
'-a',
|
|
56
|
+
'--max-args',
|
|
57
|
+
'--max-procs',
|
|
58
|
+
'--max-chars',
|
|
59
|
+
'--delimiter',
|
|
60
|
+
'--arg-file',
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
]);
|
|
65
|
+
const DURATION = /^(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?[smhd]?$|^inf(?:inity)?[smhd]?$/i;
|
|
66
|
+
/** The words after a wrapper's own options (and `timeout`'s duration). */
|
|
67
|
+
export function skipWrapper(words, wrapper) {
|
|
68
|
+
let cursor = 1;
|
|
69
|
+
while (words[cursor]?.startsWith('-') === true) {
|
|
70
|
+
const word = words[cursor];
|
|
71
|
+
cursor += 1;
|
|
72
|
+
if (word === '--')
|
|
73
|
+
break;
|
|
74
|
+
if (wrapper.values.includes(word))
|
|
75
|
+
cursor += 1;
|
|
76
|
+
}
|
|
77
|
+
if (wrapper.duration === true && DURATION.test(words[cursor] ?? ''))
|
|
78
|
+
cursor += 1;
|
|
79
|
+
return words.slice(cursor);
|
|
80
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { decodeAnsiCStringEscape, decodeNumericAnsiEscape, readAnsiCString, } from './ansi-c-string.mts';
|
|
2
2
|
export { readBacktickSubstitution, readParenthesizedSubstitution, } from './shell-command-substitution-reads.mts';
|
|
3
3
|
export { extractShellCommandSubstitutions } from './shell-command-substitutions.mts';
|
|
4
|
+
export { gitInvocations, overridesConfig } from './git-invocations.mts';
|
|
5
|
+
export type { GitConfigOverride, GitInvocation } from './git-invocations.mts';
|
|
4
6
|
export { parseCommandPrefix, readCommandPrefix, withoutRedirections, } from './shell-command-wrappers.mts';
|
|
5
7
|
export type { CommandPrefix } from './shell-command-wrappers.mts';
|
|
6
8
|
export { commandsToInspectForGitPolicy, commandsToInspectPreservingQuotes, envPrefixSetsEditor, extractShellCommandArguments, isInteractiveRebaseContinue, shellCommandInheritsEditor, stripGitGlobalOptionsForPolicy, stripQuotedShellText, } from './shell-commands.mts';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { decodeAnsiCStringEscape, decodeNumericAnsiEscape, readAnsiCString, } from "./ansi-c-string.mjs";
|
|
2
2
|
export { readBacktickSubstitution, readParenthesizedSubstitution, } from "./shell-command-substitution-reads.mjs";
|
|
3
3
|
export { extractShellCommandSubstitutions } from "./shell-command-substitutions.mjs";
|
|
4
|
+
export { gitInvocations, overridesConfig } from "./git-invocations.mjs";
|
|
4
5
|
export { parseCommandPrefix, readCommandPrefix, withoutRedirections, } from "./shell-command-wrappers.mjs";
|
|
5
6
|
export { commandsToInspectForGitPolicy, commandsToInspectPreservingQuotes, envPrefixSetsEditor, extractShellCommandArguments, isInteractiveRebaseContinue, shellCommandInheritsEditor, stripGitGlobalOptionsForPolicy, stripQuotedShellText, } from "./shell-commands.mjs";
|
|
6
7
|
export { readHeredocDelimiter } from "./shell-heredoc-delimiter.mjs";
|
|
@@ -33,10 +33,8 @@ export async function deriveRuleAttempts(env, { priorCounts, rules, runAttempt,
|
|
|
33
33
|
const priorReruns = new Map();
|
|
34
34
|
let replayCount = rules.length;
|
|
35
35
|
for (let attempt = 1; attempt < runAttempt; attempt += 1) {
|
|
36
|
-
// An attempt that created no jobs
|
|
37
|
-
|
|
38
|
-
continue;
|
|
39
|
-
const jobs = await fetchJobs(env, attempt);
|
|
36
|
+
// An attempt that created no jobs still counts when a rule matches its run-level evidence.
|
|
37
|
+
const jobs = priorCounts[attempt - 1] === 0 ? [] : await fetchJobs(env, attempt);
|
|
40
38
|
const replayRules = rules.slice(0, replayCount);
|
|
41
39
|
const context = {
|
|
42
40
|
...buildJobsContext(env, jobs, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vouchington-tooling",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.66.0",
|
|
4
4
|
"description": "Vouchington CLI and extractable tooling libraries.",
|
|
5
5
|
"homepage": "https://github.com/vouchington/vouchington-tooling/tree/main/packages/vouchington-tooling#readme",
|
|
6
6
|
"bugs": {
|
|
Binary file
|