@lannguyensi/harness 0.42.0 → 0.44.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/CHANGELOG.md +62 -0
- package/dist/cli/approve/branch-protection.js +1 -1
- package/dist/cli/approve/branch-protection.js.map +1 -1
- package/dist/cli/dry-run.js +19 -1
- package/dist/cli/dry-run.js.map +1 -1
- package/dist/cli/index.js +4 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init/composer.js +6 -6
- package/dist/cli/init/composer.js.map +1 -1
- package/dist/cli/init/profiles.d.ts +1 -1
- package/dist/cli/init/profiles.js +1 -1
- package/dist/cli/init/templates.d.ts +1 -1
- package/dist/cli/init/templates.js +53 -31
- package/dist/cli/init/templates.js.map +1 -1
- package/dist/cli/pack/hook-branch-protection.js +1 -1
- package/dist/cli/pack/hook-branch-protection.js.map +1 -1
- package/dist/cli/pack/hook-post-merge-gate.js +43 -25
- package/dist/cli/pack/hook-post-merge-gate.js.map +1 -1
- package/dist/cli/pack/hook-solution-acceptance-writeguard.js +1 -1
- package/dist/cli/pack/hook-solution-acceptance-writeguard.js.map +1 -1
- package/dist/cli/pack/hook-solution-acceptance.js +1 -1
- package/dist/cli/pack/hook-solution-acceptance.js.map +1 -1
- package/dist/cli/policy/intercept.js +209 -14
- package/dist/cli/policy/intercept.js.map +1 -1
- package/dist/cli/validate/checks.js +2 -2
- package/dist/cli/validate/checks.js.map +1 -1
- package/dist/policy-packs/builtin/branch-protection-runtime.d.ts +1 -1
- package/dist/policy-packs/builtin/branch-protection-runtime.js +1 -1
- package/dist/policy-packs/builtin/branch-protection.js +2 -2
- package/dist/policy-packs/builtin/branch-protection.js.map +1 -1
- package/dist/policy-packs/builtin/post-merge-gate-runtime.d.ts +90 -10
- package/dist/policy-packs/builtin/post-merge-gate-runtime.js +112 -16
- package/dist/policy-packs/builtin/post-merge-gate-runtime.js.map +1 -1
- package/dist/policy-packs/builtin/post-merge-gate.js +40 -23
- package/dist/policy-packs/builtin/post-merge-gate.js.map +1 -1
- package/dist/policy-packs/builtin/solution-acceptance-runtime.d.ts +13 -0
- package/dist/policy-packs/builtin/solution-acceptance-runtime.js +15 -2
- package/dist/policy-packs/builtin/solution-acceptance-runtime.js.map +1 -1
- package/dist/policy-packs/builtin/solution-acceptance.js +1 -1
- package/dist/runtime/bash-match-facts.d.ts +58 -0
- package/dist/runtime/bash-match-facts.js +194 -0
- package/dist/runtime/bash-match-facts.js.map +1 -0
- package/dist/runtime/bash-match-registry.d.ts +75 -0
- package/dist/runtime/bash-match-registry.js +359 -0
- package/dist/runtime/bash-match-registry.js.map +1 -0
- package/dist/runtime/bash-prefix-parse.js +23 -0
- package/dist/runtime/bash-prefix-parse.js.map +1 -1
- package/dist/runtime/command-normalize.d.ts +405 -0
- package/dist/runtime/command-normalize.js +1888 -0
- package/dist/runtime/command-normalize.js.map +1 -0
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/intercept.d.ts +208 -2
- package/dist/runtime/intercept.js +437 -28
- package/dist/runtime/intercept.js.map +1 -1
- package/dist/runtime/read-only-bash.d.ts +43 -0
- package/dist/runtime/read-only-bash.js +73 -10
- package/dist/runtime/read-only-bash.js.map +1 -1
- package/dist/runtime/shell-word.d.ts +21 -0
- package/dist/runtime/shell-word.js +242 -0
- package/dist/runtime/shell-word.js.map +1 -0
- package/dist/schema/policies.js +1 -1
- package/dist/schema/policies.js.map +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
export interface NormalizedCommand {
|
|
2
|
+
/**
|
|
3
|
+
* The command with wrapper prefixes peeled and git invocations
|
|
4
|
+
* canonicalised to `git <subcommand>`. Shell boundary characters
|
|
5
|
+
* (`\n ; | && ( )`) are preserved verbatim so a boundary-anchored
|
|
6
|
+
* regex still matches. Byte-identical to the input when nothing
|
|
7
|
+
* recognisable was found anywhere in the command.
|
|
8
|
+
*/
|
|
9
|
+
normalized: string;
|
|
10
|
+
/**
|
|
11
|
+
* The effective target directory of the command's git invocation, or
|
|
12
|
+
* `null` when the command names none, the command names invocations
|
|
13
|
+
* that disagree, or the only named value is `~`-prefixed (see the
|
|
14
|
+
* module header's target-directory-extraction rules).
|
|
15
|
+
*
|
|
16
|
+
* STILL NOT WIRED TO ANY GATE (see the module header's STATUS
|
|
17
|
+
* paragraph): extracted and fully tested, but task `98ad072f`'s
|
|
18
|
+
* per-policy redesign (T-003) attributes a target from the per-segment
|
|
19
|
+
* `segmentViewOf` view below instead of this whole-command aggregate —
|
|
20
|
+
* a single per-event `targetDir` cannot express "this invocation
|
|
21
|
+
* targets repo B, but the gated verb after it runs in the caller's
|
|
22
|
+
* cwd," which is exactly the property the redesign needs.
|
|
23
|
+
*/
|
|
24
|
+
targetDir: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* When `targetDir` is a RELATIVE path, the directory it should be
|
|
27
|
+
* resolved against instead of the caller's own cwd — the wrapping
|
|
28
|
+
* `env -C` on the same invocation, or a leading `cd` prefix (see the
|
|
29
|
+
* module header). `null` when `targetDir` is absolute, `null` itself,
|
|
30
|
+
* or no more specific base was found.
|
|
31
|
+
*
|
|
32
|
+
* Same unconsumed status as `targetDir` above — see the module
|
|
33
|
+
* header's STATUS paragraph.
|
|
34
|
+
*/
|
|
35
|
+
targetBase: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* `true` when the input exceeded `MAX_NORMALIZE_LENGTH` and
|
|
38
|
+
* normalisation was skipped entirely (G4 fix, review round 2,
|
|
39
|
+
* 2026-07-27): the caller previously had no way to tell "nothing
|
|
40
|
+
* recognisable was found" apart from "normalisation never ran at all",
|
|
41
|
+
* so the skip carried no audit signal. `false` whenever the input WAS
|
|
42
|
+
* run through `normalizeCommandInner` (including when nothing
|
|
43
|
+
* recognisable was found there either — that case is still `false`,
|
|
44
|
+
* only the length-bound short-circuit sets this).
|
|
45
|
+
*/
|
|
46
|
+
truncated: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* One boundary-delimited segment's canonicalised text plus its own and
|
|
50
|
+
* "effective" target directory (task `98ad072f`, T-002 of run
|
|
51
|
+
* `2026-08-02-per-repo-gate-scoping-redesign`) — attributes a target to
|
|
52
|
+
* the SPECIFIC segment satisfying a policy's own `bash_match` trigger,
|
|
53
|
+
* instead of the single, whole-command `targetDir` / `targetBase` on
|
|
54
|
+
* `NormalizedCommand` above. Produced by `segmentViewOf`. WIRED as of
|
|
55
|
+
* T-003, this run: `src/runtime/intercept.ts`'s `attributeTriggerSegments`
|
|
56
|
+
* / `resolveAttributedContexts` are the consumer (see the module header's
|
|
57
|
+
* STATUS/UPDATE note for the exact contract).
|
|
58
|
+
*/
|
|
59
|
+
export interface CommandSegment {
|
|
60
|
+
/**
|
|
61
|
+
* This segment's canonicalised text — the same rewrite
|
|
62
|
+
* `NormalizedCommand.normalized` applies to the corresponding span,
|
|
63
|
+
* boundary tokens EXCLUDED (they sit between segments, never inside
|
|
64
|
+
* one). Every shipped `bash_match` pattern's boundary alternation
|
|
65
|
+
* includes a `^` branch, so testing such a pattern against THIS string
|
|
66
|
+
* alone (no leading boundary character) is well-defined — see
|
|
67
|
+
* `01-plan.md`'s Proposed Approach item 2 for how a future consumer
|
|
68
|
+
* uses this.
|
|
69
|
+
*/
|
|
70
|
+
text: string;
|
|
71
|
+
/**
|
|
72
|
+
* D-021 (UNIVERSAL-ADDITIVE, run 2026-08-02-per-repo-gate-scoping-
|
|
73
|
+
* redesign): the only remaining consumer of this field is
|
|
74
|
+
* `computeSegmentTarget`'s own internal `effectiveTarget` derivation
|
|
75
|
+
* (below) — `src/runtime/intercept.ts`'s `resolveAttributedContexts`
|
|
76
|
+
* (the gate) reads `effectiveTarget` only and no longer consults
|
|
77
|
+
* `ownTarget` at all. Kept as a public, separately-populated field
|
|
78
|
+
* (part of the T-002 API) rather than folded away, since a future
|
|
79
|
+
* consumer distinguishing "this segment's OWN explicit target" from
|
|
80
|
+
* "the directory it composes to once an incoming `cd` basis is
|
|
81
|
+
* accounted for" is exactly what the two-field split exists for.
|
|
82
|
+
*
|
|
83
|
+
* This segment's OWN explicit target, named by ITS OWN invocation
|
|
84
|
+
* only — a git invocation's REPO-RELOCATING global option ONLY: `-C` /
|
|
85
|
+
* `--git-dir` (or the SAME invocation's wrapping `env -C`, git-own-
|
|
86
|
+
* target-prioritised the same way `NormalizedCommand.targetDir` already
|
|
87
|
+
* is) — or, for a recognised bare `cd <path>` segment, the parsed path.
|
|
88
|
+
* Deliberately EXCLUDES `--work-tree` (D-017, fix round 2, run
|
|
89
|
+
* `2026-08-02-per-repo-gate-scoping-redesign`): `--work-tree` sets a
|
|
90
|
+
* git invocation's working tree but does NOT relocate its `--git-dir`
|
|
91
|
+
* search, so `git --work-tree=<B> push`/`log`/`status` still operate on
|
|
92
|
+
* whatever repo the invocation's ACTUAL directory names, never `<B>`
|
|
93
|
+
* alone — folding it into this field as though it were repo-identity-
|
|
94
|
+
* bearing (the pre-fix behaviour) let `resolveAttributedContexts`
|
|
95
|
+
* (`src/runtime/intercept.ts`, D-011) REPLACE the cwd demand with `<B>`'s
|
|
96
|
+
* on the strength of a flag that never moved the invocation there,
|
|
97
|
+
* measured as a live cross-repo fail-open. `null` when this segment
|
|
98
|
+
* names no repo-relocating target of its own (not a git invocation, not
|
|
99
|
+
* a `cd` segment, a bare git invocation, or a git invocation whose ONLY
|
|
100
|
+
* target-bearing flag is `--work-tree`) OR the named value is one of
|
|
101
|
+
* this view's unattributable forms: `~`-prefixed, carrying a stray quote
|
|
102
|
+
* character (the tokeniser is not quote-aware — a quoted value is
|
|
103
|
+
* captured WITH its quote character(s) still attached, not a real
|
|
104
|
+
* path), containing a command-substitution marker (`$(` or a backtick),
|
|
105
|
+
* or — for `cd` specifically — a bare `cd` with no argument or a `cd`
|
|
106
|
+
* with a flag (`cd -P /x`, three tokens instead of two). ALSO `null`
|
|
107
|
+
* when the SAME invocation names a git target via BOTH a relative own
|
|
108
|
+
* `-C` / `--git-dir` AND a wrapping `env -C` / `--chdir` base (`env -C
|
|
109
|
+
* /tmp/base git -C sub status`) — a mixed, internally ambiguous
|
|
110
|
+
* composition, unattributable for the same reason a relative own target
|
|
111
|
+
* after a preceding `cd` is (see `effectiveTarget` below); this is the
|
|
112
|
+
* ONE case where `ownTarget` itself, not just `effectiveTarget`, is
|
|
113
|
+
* nulled by a composition rule rather than by the raw value being
|
|
114
|
+
* unrecognisable on its own. A relative value (including `-C .`) and an
|
|
115
|
+
* absolute value are both otherwise preserved here verbatim, unresolved
|
|
116
|
+
* against any cwd — that resolution is a future consumer's job, not
|
|
117
|
+
* this module's. `git --git-dir=<A>/.git --work-tree=<B> ...`: this
|
|
118
|
+
* field is `<A>` (the `.git` parent) — `--git-dir` wins regardless of
|
|
119
|
+
* which flag appears first in the invocation, because `--work-tree`
|
|
120
|
+
* never contributes to this field at all, not because of any ordering
|
|
121
|
+
* rule between the two.
|
|
122
|
+
*
|
|
123
|
+
* ALSO `null` (D-018, fix round 3, pass-3 CRITICAL) when the invocation
|
|
124
|
+
* carries MORE THAN ONE recognised, resolved repo-relocating option:
|
|
125
|
+
* two-or-more `-C`, `-C` combined with `--git-dir`, `--git-dir` twice,
|
|
126
|
+
* or a same-invocation `env -C`/`--chdir` wrap whose target diverges
|
|
127
|
+
* from git's own ABSOLUTE `-C`/`--git-dir` target. Real git composes
|
|
128
|
+
* every one of these cumulatively (a later absolute value wins); this
|
|
129
|
+
* module does not encode that composition (same "not this module's
|
|
130
|
+
* job" reasoning as the relative-mix case above) and instead falls back
|
|
131
|
+
* to unattributable rather than trust the first flag it saw — `git -C
|
|
132
|
+
* <forge> -C <realA> push` actually runs in `<realA>`, but a first-
|
|
133
|
+
* flag-wins reading named `<forge>`, letting an agent redirect a gate's
|
|
134
|
+
* demanded evidence away from the repo the verb truly targets (measured
|
|
135
|
+
* against real git 2.34.1). An EXACT repeat of the same already-
|
|
136
|
+
* recorded value (`-C X -C X`, `env -C X git -C X`) is not new
|
|
137
|
+
* information and does not trigger this — see `peelGitGlobalOptions`'s
|
|
138
|
+
* `noteRelocatingOption` for the precise counting rule.
|
|
139
|
+
*
|
|
140
|
+
* D-021 (UNIVERSAL-ADDITIVE, operator decision, run 2026-08-02-per-
|
|
141
|
+
* repo-gate-scoping-redesign): the D-017/D-018 exclusions above (only a
|
|
142
|
+
* SINGLE recognised repo-relocating flag sets this field; `--work-tree`
|
|
143
|
+
* never does) are PRECISION, not the safety mechanism, since
|
|
144
|
+
* `src/runtime/intercept.ts`'s `resolveAttributedContexts` no longer
|
|
145
|
+
* REPLACES the cwd demand with this field's value — it ADDS to it, and
|
|
146
|
+
* the cwd demand is never dropped regardless of what this field
|
|
147
|
+
* resolves to. What these exclusions still prevent is a SPURIOUS extra
|
|
148
|
+
* demand (over-attributing a target the invocation does not actually,
|
|
149
|
+
* unambiguously name), not a dropped one — see that function's own doc
|
|
150
|
+
* comment for the full D-021 rationale.
|
|
151
|
+
*/
|
|
152
|
+
ownTarget: string | null;
|
|
153
|
+
/**
|
|
154
|
+
* The directory this segment's own invocation actually runs in, once
|
|
155
|
+
* composed with the LAST PRECEDING recognised `cd <path>` segment in the
|
|
156
|
+
* same command (not necessarily the immediately preceding segment — any
|
|
157
|
+
* non-`cd` segment in between leaves the running cd-basis unchanged, the
|
|
158
|
+
* same way a non-`cd` shell command never itself changes the directory).
|
|
159
|
+
* Composition rules (`01-plan.md`, Proposed Approach item 1, verbatim):
|
|
160
|
+
* - `ownTarget === null` → inherits the incoming cd-basis as-is
|
|
161
|
+
* (including `null` when nothing preceding named one either).
|
|
162
|
+
* - `ownTarget` absolute → itself, unconditionally — an absolute
|
|
163
|
+
* value is never "relative to" anything a preceding `cd` named.
|
|
164
|
+
* - `ownTarget` relative AND a preceding `cd` basis is known
|
|
165
|
+
* (non-`null`) → `null`. This is the K1 divergence case
|
|
166
|
+
* (`docs/okf/quote-model-divergence.md`): `cd T && git -C sub
|
|
167
|
+
* status` does NOT become `T/sub` here — that would need real
|
|
168
|
+
* filesystem-shaped path joining this module deliberately does not
|
|
169
|
+
* perform — so it is UNATTRIBUTABLE rather than guessed at.
|
|
170
|
+
* - `ownTarget` relative AND no preceding `cd` basis is known → the
|
|
171
|
+
* raw relative value itself (deferred to a future consumer to
|
|
172
|
+
* resolve against the real cwd).
|
|
173
|
+
* A same-invocation mixed `env -C <base>` + relative own `-C`/
|
|
174
|
+
* `--git-dir` composition (see `ownTarget` above — `--work-tree` is
|
|
175
|
+
* EXCLUDED from this mix entirely, D-017: it never sets `ownTarget`, so
|
|
176
|
+
* it can never trigger this ambiguity either) is `null` here TOO —
|
|
177
|
+
* checked BEFORE the cd-basis rules above and
|
|
178
|
+
* independently of them: `env -C /tmp/base git -C sub status` never
|
|
179
|
+
* becomes `/tmp/base/sub` (real path joining, deliberately not this
|
|
180
|
+
* module's job — same reasoning as the cd-basis K1 case) NOR does it
|
|
181
|
+
* fall through to the "relative, no cd basis, stays raw" branch above
|
|
182
|
+
* (that would hand a future consumer resolving relatives against ITS
|
|
183
|
+
* OWN cwd a CONFIDENTLY WRONG repository whenever the caller's cwd
|
|
184
|
+
* differs from `/tmp/base` — the "relative and `~` target dirs resolve
|
|
185
|
+
* to a confidently wrong repo" class named in the 07-27 review). A bare
|
|
186
|
+
* `env -C <base> git status` (no relative own target) is UNAFFECTED —
|
|
187
|
+
* `ownTarget` is `<base>` as usual, composed the ordinary way below.
|
|
188
|
+
* A recognised `cd <path>` segment whose OWN value is one of the
|
|
189
|
+
* unattributable forms above (e.g. `cd ~`) still RESETS the running
|
|
190
|
+
* cd-basis to `null` for every LATER segment — a later segment must not
|
|
191
|
+
* silently keep inheriting whatever basis existed BEFORE that `cd`,
|
|
192
|
+
* since the shell genuinely changed directory to somewhere this module
|
|
193
|
+
* cannot name.
|
|
194
|
+
*
|
|
195
|
+
* FULL reset-trigger list (D-014, fix round, run 2026-08-02-per-repo-
|
|
196
|
+
* gate-scoping-redesign — corrects this comment, which previously named
|
|
197
|
+
* only the unattributable-`cd`-value case above): the running basis
|
|
198
|
+
* resets to `null` — rather than the pre-fix behaviour of silently
|
|
199
|
+
* carrying an earlier basis forward unchanged — for ALL of: a bare `cd`
|
|
200
|
+
* with no argument, `cd -`, any other flagged `cd` (`cd -P /tmp/x`),
|
|
201
|
+
* `pushd`, `popd` (see `classifyCdSegment`), and the unattributable-
|
|
202
|
+
* `cd`-value case documented above. TWO of the reset triggers are NOT
|
|
203
|
+
* decided by this per-segment composition at all — they depend on the
|
|
204
|
+
* BOUNDARY a segment sits behind, which only the caller
|
|
205
|
+
* (`segmentAndCanonicalize`'s own walk) can see: the basis never
|
|
206
|
+
* crosses a bare `|` (each side of a pipe is bash's own subshell), and
|
|
207
|
+
* it resets after any segment whose text contains a `)` (a subshell
|
|
208
|
+
* close — `BOUNDARY_RE` has no `)` boundary of its own, so this is a
|
|
209
|
+
* substring check on the segment that happens to end there, not paren-
|
|
210
|
+
* depth tracking). See `segmentAndCanonicalize`'s own comment at its
|
|
211
|
+
* `computeSegmentTarget` call site for those two. NOT covered by any of
|
|
212
|
+
* this (same ceiling as before this fix round, unchanged): a `cd`
|
|
213
|
+
* inside a NESTED subshell that never closes within the command
|
|
214
|
+
* string's visible boundaries, and any construct outside this module's
|
|
215
|
+
* documented NOT-SUPPORTED list in the module header.
|
|
216
|
+
*/
|
|
217
|
+
effectiveTarget: string | null;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The `git` token itself, matched by BASENAME so a path-qualified
|
|
221
|
+
* invocation (`/usr/bin/git`, `./git`) is recognised too (F4 fix).
|
|
222
|
+
* Anchored to the WHOLE token (not a substring) so `mygit` / `git-foo`
|
|
223
|
+
* still correctly fail to match — `\S*` only ever contributes characters
|
|
224
|
+
* immediately before a literal `/`, never before `git` directly.
|
|
225
|
+
* Exported (fix round 2, finding F3) so
|
|
226
|
+
* `tests/runtime/bash-match-head-token-drift.test.ts` can couple this
|
|
227
|
+
* module's covered set to what FULL_TEMPLATE's shipped `bash_match`
|
|
228
|
+
* policies actually key on today, instead of a test-owned duplicate.
|
|
229
|
+
*/
|
|
230
|
+
export declare const GIT_TOKEN_RE: RegExp;
|
|
231
|
+
/**
|
|
232
|
+
* The three OTHER head tokens this module covers (D-001, run
|
|
233
|
+
* 2026-07-28-nongit-trigger-wrappers) — `gh` (`gh pr merge` / `gh pr
|
|
234
|
+
* create`), `npm` (`npm publish`), `harness` (the kill-switch verbs). A
|
|
235
|
+
* closed set, deliberately NOT a general "any head token" rule (see the
|
|
236
|
+
* module header): matched by EXACT literal equality, unlike `GIT_TOKEN_RE`'s
|
|
237
|
+
* basename match, so a path-qualified spelling of any of these three stays
|
|
238
|
+
* out of scope (named residual, module header NOT-SUPPORTED list). This is
|
|
239
|
+
* NOT the complete set of head tokens a shipped `bash_match` trigger keys
|
|
240
|
+
* on — see the module header's "SHIPPED BUT NOT COVERED" paragraph (fix
|
|
241
|
+
* round 2, finding F1) for the four that are NOT in this set (`env`,
|
|
242
|
+
* `unset`, `tee`, `cp`) and why. Exported (fix round 2, finding F3) for the
|
|
243
|
+
* same drift-guard reason as `GIT_TOKEN_RE` above.
|
|
244
|
+
*/
|
|
245
|
+
export declare const NON_GIT_HEAD_TOKENS: ReadonlySet<string>;
|
|
246
|
+
/**
|
|
247
|
+
* Above this length, normalisation is skipped entirely and the command
|
|
248
|
+
* is returned unchanged (F3 fix — see the module header for why command
|
|
249
|
+
* SIZE must be bounded even after `findNextBoundary` was made linear).
|
|
250
|
+
* 100k characters comfortably covers any command a human or agent would
|
|
251
|
+
* plausibly type, while keeping the worst case a small constant instead
|
|
252
|
+
* of scaling with whatever ends up pasted into a single Bash call.
|
|
253
|
+
* Exported (G4 fix, review round 2) so a caller reporting the skip (see
|
|
254
|
+
* `NormalizedCommand.truncated`) can reference the same number instead of
|
|
255
|
+
* hand-copying it into a diagnostic message.
|
|
256
|
+
*/
|
|
257
|
+
export declare const MAX_NORMALIZE_LENGTH = 100000;
|
|
258
|
+
/**
|
|
259
|
+
* Second boundary alphabet (task aabbad63): identical to `BOUNDARY_RE`
|
|
260
|
+
* plus a bare `&` — bash's OWN "start a new command here" token, which
|
|
261
|
+
* every shipped `bash_match` trigger regex has treated as one of its own
|
|
262
|
+
* anchor characters since task `d834a065`, but which `BOUNDARY_RE` above
|
|
263
|
+
* has never recognised as a NORMALISATION-time boundary (see its comment
|
|
264
|
+
* for the reverted, measured-140/140-regression attempt to add it there
|
|
265
|
+
* directly).
|
|
266
|
+
*
|
|
267
|
+
* ALTERNATION ORDER IS LOAD-BEARING: `&&` MUST be listed to the LEFT of
|
|
268
|
+
* the bare `&` alternative. JS regex alternation is leftmost-FIRST, not
|
|
269
|
+
* leftmost-longest — with `&` tried before `&&`, every `&&` in a command
|
|
270
|
+
* would tokenise as TWO consecutive one-character `&` boundary MATCHES
|
|
271
|
+
* instead of a single two-character `&&` boundary match.
|
|
272
|
+
*
|
|
273
|
+
* MEASURED, NOT ASSUMED (do not "simplify" the pin below to an
|
|
274
|
+
* end-to-end `.normalized` string assertion): for THIS module's segment-
|
|
275
|
+
* and-rejoin architecture specifically, that reordering is, perhaps
|
|
276
|
+
* counter-intuitively, INVISIBLE in `normalizeCommandAmpAware`'s own
|
|
277
|
+
* output string. Two adjacent single-`&` matches sandwich a genuinely
|
|
278
|
+
* zero-length segment between them (the two `&` characters of a real
|
|
279
|
+
* `&&` are, by definition, adjacent), `canonicalizeSegment("")` is a
|
|
280
|
+
* verbatim no-op, and `parts.join("")` reassembles the exact same bytes
|
|
281
|
+
* either way — verified directly (not merely reasoned about) by
|
|
282
|
+
* temporarily swapping this alternation's order, rebuilding, and
|
|
283
|
+
* diffing `normalizeCommandAmpAware(...).normalized` across several
|
|
284
|
+
* `&&`-bearing commands (including this comment's own `git -C
|
|
285
|
+
* /tmp/repoB status && git -C /tmp/repoB log` example): byte-identical
|
|
286
|
+
* output both ways. So a test asserting on the OUTPUT STRING alone
|
|
287
|
+
* cannot distinguish the two orderings for this architecture — the pin
|
|
288
|
+
* in `tests/runtime/command-normalize.test.ts` therefore execs this
|
|
289
|
+
* regex object DIRECTLY against a `&&`-bearing string and asserts the
|
|
290
|
+
* match text is `"&&"`, not `"&"`, which DOES fail under a swap. The
|
|
291
|
+
* order is still specified exactly as documented above (leftmost-first
|
|
292
|
+
* is real JS semantics, and the internal `segmentAndCanonicalize`
|
|
293
|
+
* bookkeeping this alphabet ALSO drives — `hasAmbiguousNonGitSegment`,
|
|
294
|
+
* discarded by `normalizeCommandAmpAware` but not by a hypothetical
|
|
295
|
+
* future consumer of `segmentAndCanonicalize` under this alphabet —
|
|
296
|
+
* would still see a spurious extra "non-git segment" under the wrong
|
|
297
|
+
* order), it just cannot be pinned through this module's ONE exposed
|
|
298
|
+
* string alone.
|
|
299
|
+
*
|
|
300
|
+
* Used ONLY by `normalizeCommandAmpAware` below, which is consulted ONLY
|
|
301
|
+
* as `policyMatchesEvent`'s third, additional matching arm — see that
|
|
302
|
+
* function's own comment for why its result never carries a `targetDir`/
|
|
303
|
+
* `targetBase`, and `src/runtime/intercept.ts` for the memoised-thunk
|
|
304
|
+
* threading that keeps this off the common (raw-or-normalised-already-
|
|
305
|
+
* matched) path. Exported (mirrors `GIT_TOKEN_RE` / `NON_GIT_HEAD_TOKENS`
|
|
306
|
+
* / `MAX_NORMALIZE_LENGTH` above) solely so the ordering pin test can
|
|
307
|
+
* exec it directly instead of re-declaring an equivalent regex literal
|
|
308
|
+
* that would test JS semantics in general, not THIS source's actual
|
|
309
|
+
* alternation.
|
|
310
|
+
*/
|
|
311
|
+
export declare const AMP_BOUNDARY_RE: RegExp;
|
|
312
|
+
/**
|
|
313
|
+
* Given a Bash command string, return its normalised form and the target
|
|
314
|
+
* directory (and base, if relative) of its git invocation. Never throws:
|
|
315
|
+
* any internal failure (there should be none — this is a defensive
|
|
316
|
+
* backstop matching the fail-safe shape used elsewhere in this codebase,
|
|
317
|
+
* e.g. `policyMatchesEvent`'s `try/catch` around `new RegExp`) falls back
|
|
318
|
+
* to the input unchanged.
|
|
319
|
+
*/
|
|
320
|
+
export declare function normalizeCommand(command: string): NormalizedCommand;
|
|
321
|
+
/**
|
|
322
|
+
* Given a Bash command string, return its per-segment view (task
|
|
323
|
+
* `98ad072f` groundwork, T-002) — see `CommandSegment`'s own doc comment
|
|
324
|
+
* for the field-level composition rules. `null` when the input exceeded
|
|
325
|
+
* `MAX_NORMALIZE_LENGTH` (mirrors `NormalizedCommand.truncated`, but as
|
|
326
|
+
* the ABSENCE of a view rather than a boolean flag alongside one, since
|
|
327
|
+
* there is no meaningful per-segment view to return for an input whose
|
|
328
|
+
* normalisation itself was skipped). `[]` for an empty or non-string
|
|
329
|
+
* command, and as the never-throws fallback (mirrors `normalizeCommand`'s
|
|
330
|
+
* own defensive backstop — see its doc comment above).
|
|
331
|
+
*
|
|
332
|
+
* THIS function's OWN call into `segmentAndCanonicalize` (`collectSegments:
|
|
333
|
+
* true`) is one walk, O(length) — the "no additional pass" claim is scoped
|
|
334
|
+
* to that ONE call, not to a caller's total work. CORRECTED (D-015, fix
|
|
335
|
+
* round, run 2026-08-02-per-repo-gate-scoping-redesign) — the prior wording
|
|
336
|
+
* here read "no additional pass over the command string" without that
|
|
337
|
+
* scoping, which a reader could take as "calling this costs nothing beyond
|
|
338
|
+
* `normalizeCommand`'s own walk." Measured false: `normalizeCommand(cmd)`
|
|
339
|
+
* and `segmentViewOf(cmd)` are two SEPARATE top-level calls, each running
|
|
340
|
+
* its own full `segmentAndCanonicalize` pass over the SAME string — a
|
|
341
|
+
* caller needing both (as `src/cli/policy/intercept.ts` does, for
|
|
342
|
+
* `normalized`/`truncated` and the segment view respectively) pays TWO
|
|
343
|
+
* walks, not one; measured +206% at the `MAX_NORMALIZE_LENGTH` bound
|
|
344
|
+
* (2.73 → 8.36 ms), harmless against the 1000 ms hook budget but not free.
|
|
345
|
+
* As of the same fix round, the one production caller only pays this
|
|
346
|
+
* second walk lazily, when some matching policy actually needs it (see
|
|
347
|
+
* `InterceptOptions.commandSegmentsThunk` in `src/runtime/intercept.ts`) —
|
|
348
|
+
* but that laziness lives in the CALLER, not in this function, which still
|
|
349
|
+
* does exactly one walk every time it runs. The ampersand-aware second pass
|
|
350
|
+
* (`normalizeCommandAmpAware`) NEVER collects a segment view (always calls
|
|
351
|
+
* `segmentAndCanonicalize` with `collectSegments: false`) — see that
|
|
352
|
+
* function's own comment for why a directory extracted under the
|
|
353
|
+
* ampersand-aware alphabet would be unreliable in the first place; the
|
|
354
|
+
* same reasoning applies here, so this module offers no amp-aware variant
|
|
355
|
+
* of this function at all.
|
|
356
|
+
*/
|
|
357
|
+
export declare function segmentViewOf(command: string): CommandSegment[] | null;
|
|
358
|
+
/**
|
|
359
|
+
* Return type of `normalizeCommandAmpAware` — deliberately NOT
|
|
360
|
+
* `NormalizedCommand` (task aabbad63, hard constraint). It carries only
|
|
361
|
+
* `normalized`/`truncated`; there is no `targetDir`/`targetBase` field at
|
|
362
|
+
* all, so a future caller cannot wire one up to a gate by mistake — see
|
|
363
|
+
* `normalizeCommandAmpAware`'s own comment for why a directory extracted
|
|
364
|
+
* under the ampersand-aware alphabet would be unreliable in the first
|
|
365
|
+
* place, not merely "unwired today".
|
|
366
|
+
*/
|
|
367
|
+
export interface AmpAwareNormalizedCommand {
|
|
368
|
+
/** Same contract as `NormalizedCommand.normalized`, under `AMP_BOUNDARY_RE`. */
|
|
369
|
+
normalized: string;
|
|
370
|
+
/** Same contract as `NormalizedCommand.truncated`. */
|
|
371
|
+
truncated: boolean;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Ampersand-aware SECOND normalisation pass (task aabbad63). Segments the
|
|
375
|
+
* command under `AMP_BOUNDARY_RE` (`BOUNDARY_RE` plus a bare `&`) instead
|
|
376
|
+
* of `BOUNDARY_RE`, then canonicalises exactly like the primary pass
|
|
377
|
+
* (same `canonicalizeSegment`, same wrapper-peeling rules, same
|
|
378
|
+
* `MAX_NORMALIZE_LENGTH` bound). Closes the gap `BOUNDARY_RE`'s own
|
|
379
|
+
* comment names: `A=x&env -C /tmp git status` and `echo hi & nice git
|
|
380
|
+
* status` were ungated because a wrapper can only be peeled after a
|
|
381
|
+
* recognised boundary, and a bare `&` was not one.
|
|
382
|
+
*
|
|
383
|
+
* Return type deliberately has NO `targetDir`/`targetBase` — not merely
|
|
384
|
+
* "always null under this alphabet", genuinely ABSENT from the type, so
|
|
385
|
+
* no consumer can read one by mistake. Reason: a bare `&` is ALSO how
|
|
386
|
+
* bash spells a background job (`git -C /x push &`) and how a redirect
|
|
387
|
+
* merges streams (`git -C /x log 2>&1`, `... &> out`). Under THIS
|
|
388
|
+
* alphabet each of those splits into a spurious extra "segment", which
|
|
389
|
+
* `segmentAndCanonicalize`'s own non-git-segment ambiguity rule (a
|
|
390
|
+
* segment that starts a new command and is not itself a git invocation
|
|
391
|
+
* forces `targetDir` to `null` — see its G1 comment) would turn into a
|
|
392
|
+
* wrong-shaped loss for a case the PRIMARY pass still resolves correctly
|
|
393
|
+
* today. Pinned in `tests/runtime/command-normalize.test.ts`'s "aabbad63
|
|
394
|
+
* groundwork" describe block, which exercises ONLY `normalizeCommand`
|
|
395
|
+
* (the primary pass), never this function — `targetDir`/`targetBase`
|
|
396
|
+
* stay the primary pass's property alone.
|
|
397
|
+
*
|
|
398
|
+
* Only consulted by `policyMatchesEvent`'s third arm
|
|
399
|
+
* (`src/runtime/intercept.ts`), and only when a policy's `bash_match`
|
|
400
|
+
* regex has already missed BOTH the raw command and the primary
|
|
401
|
+
* normalised form — see that module and `src/cli/policy/intercept.ts`
|
|
402
|
+
* for the memoised-thunk threading that keeps this computation off the
|
|
403
|
+
* common (already-matched) path.
|
|
404
|
+
*/
|
|
405
|
+
export declare function normalizeCommandAmpAware(command: string): AmpAwareNormalizedCommand;
|