@webpieces/agent-workflow-rules 0.4.965 → 0.4.967

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.
@@ -213,15 +213,36 @@ WP_LOG_DIR=""
213
213
  WP_PRIMARY_LOG_DIR=""
214
214
  WP_TAB="$(printf '\t')" # one real tab, so the OPTIONAL bin= field can carry its own separator
215
215
  wp_resolve_log_dir() {
216
- _wp_rp="$(git -C "$WP_CWD" rev-parse --git-dir --git-common-dir 2>/dev/null)"
217
- _wp_gd="$(printf '%s\n' "$_wp_rp" | sed -n 1p)"
218
- _wp_cd="$(printf '%s\n' "$_wp_rp" | sed -n 2p)"
216
+ _wp_gd=""
217
+ _wp_cd=""
218
+ _wp_d="$WP_CWD"
219
+ while [ -n "$_wp_d" ]; do
220
+ if [ -d "$_wp_d/.git" ]; then _wp_gd="$_wp_d/.git"; break; fi
221
+ if [ -f "$_wp_d/.git" ]; then
222
+ _wp_l=""; IFS= read -r _wp_l < "$_wp_d/.git" || :
223
+ case "$_wp_l" in "gitdir: "*) _wp_gd="${_wp_l#gitdir: }" ;; esac
224
+ case "$_wp_gd" in ''|/*) : ;; *) _wp_gd="$_wp_d/$_wp_gd" ;; esac
225
+ [ -d "$_wp_gd" ] || _wp_gd=""
226
+ break
227
+ fi
228
+ _wp_d="${_wp_d%/*}"
229
+ done
230
+ # The shared git dir: <gitdir>/commondir (relative to the git dir) when present, else the git dir.
231
+ # Normalized with `cd && pwd -P` — builtins in a subshell, never a process.
232
+ if [ -n "$_wp_gd" ]; then
233
+ _wp_cd="$_wp_gd"
234
+ if [ -f "$_wp_gd/commondir" ]; then
235
+ _wp_l=""; IFS= read -r _wp_l < "$_wp_gd/commondir" || :
236
+ case "$_wp_l" in ''|/*) : ;; *) _wp_l="$_wp_gd/$_wp_l" ;; esac
237
+ [ -n "$_wp_l" ] && _wp_cd="$(CDPATH= cd -- "$_wp_l" 2>/dev/null && pwd -P)"
238
+ fi
239
+ fi
219
240
  if [ -z "$_wp_gd" ] || [ -z "$_wp_cd" ]; then
220
241
  WP_TREE=primary; WP_LOG_DIR="$WP_CWD/.webpieces/logs"
221
242
  WP_PRIMARY_LOG_DIR="$WP_LOG_DIR"; return 0
222
243
  fi
223
- # git prints a BARE .git from the primary clone and an absolute path from a linked worktree; the TS
224
- # twin runs path.resolve(cwd, printed), so do the same before comparing or taking a basename.
244
+ # Both are absolute whenever the cwd is; a relative cwd (a hand-run) is anchored the way the TS twin's
245
+ # path.resolve(cwd, …) anchors it, before comparing or taking a basename.
225
246
  case "$_wp_gd" in /*) : ;; *) _wp_gd="$WP_CWD/$_wp_gd" ;; esac
226
247
  case "$_wp_cd" in /*) : ;; *) _wp_cd="$WP_CWD/$_wp_cd" ;; esac
227
248
  # The primary clone's root is the parent of the SHARED git dir — declining any layout whose shared
@@ -1,27 +0,0 @@
1
- import { CommandScanner } from '@webpieces/hook-runtime';
2
- /**
3
- * Is this Bash command a PLAIN `git add` — the cure for an untracked declared policy file (#1327)?
4
- *
5
- * While `UntrackedPolicyError` is the reason the config will not load, every Bash call is denied with
6
- * that refusal, and the refusal's own cure is `git add <the files>`. Denying it sent agents round the
7
- * same deny until they found `wp-migrate-dirs --stage`. The runner asks this question ONLY while that
8
- * specific refusal is active, so a healthy tree never sees it.
9
- *
10
- * ANY plain `git add` passes, not only one whose pathspecs cover the missing files, deliberately:
11
- * - `git add` touches only the index; it commits nothing, pushes nothing, and `git restore --staged`
12
- * undoes it. There is nothing to protect by narrowing it further;
13
- * - matching pathspecs against the missing files means re-implementing git's pathspec semantics
14
- * (directories, globs, `-A`, `.`, `:(top)` magic) — and every mismatch is the loop coming back,
15
- * because an agent's natural `git add -A` or `git add .webpieces-config` would be refused again.
16
- *
17
- * What it refuses is everything that could make the command do MORE than stage: any segment that is
18
- * not `git add` (an optional leading `cd <literal path> &&` excepted), a pipe or background `&`, and any
19
- * `$`, backtick or redirect — command substitution inside double quotes is not split out by the
20
- * scanner, so the characters themselves are refused rather than trusting the split.
21
- */
22
- export declare class PolicyStagingCommand {
23
- private readonly scanner;
24
- constructor(scanner?: CommandScanner);
25
- isPlainGitAdd(command: string): boolean;
26
- private sequential;
27
- }
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PolicyStagingCommand = void 0;
4
- const hook_runtime_1 = require("@webpieces/hook-runtime");
5
- /**
6
- * Is this Bash command a PLAIN `git add` — the cure for an untracked declared policy file (#1327)?
7
- *
8
- * While `UntrackedPolicyError` is the reason the config will not load, every Bash call is denied with
9
- * that refusal, and the refusal's own cure is `git add <the files>`. Denying it sent agents round the
10
- * same deny until they found `wp-migrate-dirs --stage`. The runner asks this question ONLY while that
11
- * specific refusal is active, so a healthy tree never sees it.
12
- *
13
- * ANY plain `git add` passes, not only one whose pathspecs cover the missing files, deliberately:
14
- * - `git add` touches only the index; it commits nothing, pushes nothing, and `git restore --staged`
15
- * undoes it. There is nothing to protect by narrowing it further;
16
- * - matching pathspecs against the missing files means re-implementing git's pathspec semantics
17
- * (directories, globs, `-A`, `.`, `:(top)` magic) — and every mismatch is the loop coming back,
18
- * because an agent's natural `git add -A` or `git add .webpieces-config` would be refused again.
19
- *
20
- * What it refuses is everything that could make the command do MORE than stage: any segment that is
21
- * not `git add` (an optional leading `cd <literal path> &&` excepted), a pipe or background `&`, and any
22
- * `$`, backtick or redirect — command substitution inside double quotes is not split out by the
23
- * scanner, so the characters themselves are refused rather than trusting the split.
24
- */
25
- class PolicyStagingCommand {
26
- scanner;
27
- constructor(scanner = new hook_runtime_1.CommandScanner()) {
28
- this.scanner = scanner;
29
- }
30
- isPlainGitAdd(command) {
31
- // A trailing `&` leaves no segment to carry its join, so pipes and lone `&` are refused as text.
32
- if (/[`$<>|]/.test(command) || command.replace(/&&/g, '').includes('&'))
33
- return false;
34
- const segments = this.scanner.segmentsWithJoins(command);
35
- if (segments.length === 0)
36
- return false;
37
- let staged = false;
38
- for (let index = 0; index < segments.length; index++) {
39
- const segment = segments[index];
40
- if (!this.sequential(segment))
41
- return false;
42
- if (index === 0 && segments.length > 1 && /^cd\s+\S+$/.test(segment.text))
43
- continue;
44
- // The RAW text, not `words()`: that strips `sudo` / `env` / `VAR=x` prefixes, and
45
- // `GIT_DIR=… git add` stages into some other repository.
46
- if (!/^git\s+add(\s|$)/.test(segment.text))
47
- return false;
48
- staged = true;
49
- }
50
- return staged;
51
- }
52
- // `&&` / `;` / newline only: a pipe hands git's output to another program, `&` backgrounds it.
53
- sequential(segment) {
54
- return segment.join === 'none' || segment.join === '&&' || segment.join === ';' || segment.join === '\n';
55
- }
56
- }
57
- exports.PolicyStagingCommand = PolicyStagingCommand;
58
- //# sourceMappingURL=policy-staging-command.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"policy-staging-command.js","sourceRoot":"","sources":["../../../../../../packages/tooling/agent-workflow-rules/src/core/policy-staging-command.ts"],"names":[],"mappings":";;;AAAA,0DAAyE;AAEzE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,oBAAoB;IACA;IAA7B,YAA6B,UAA0B,IAAI,6BAAc,EAAE;QAA9C,YAAO,GAAP,OAAO,CAAuC;IAAG,CAAC;IAE/E,aAAa,CAAC,OAAe;QACzB,iGAAiG;QACjG,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QACtF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACzD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACxC,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACnD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBAAE,OAAO,KAAK,CAAC;YAC5C,IAAI,KAAK,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBAAE,SAAS;YACpF,kFAAkF;YAClF,yDAAyD;YACzD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBAAE,OAAO,KAAK,CAAC;YACzD,MAAM,GAAG,IAAI,CAAC;QAClB,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,+FAA+F;IACvF,UAAU,CAAC,OAAuB;QACtC,OAAO,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,GAAG,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC;IAC7G,CAAC;CACJ;AAzBD,oDAyBC","sourcesContent":["import { CommandScanner, CommandSegment } from '@webpieces/hook-runtime';\n\n/**\n * Is this Bash command a PLAIN `git add` — the cure for an untracked declared policy file (#1327)?\n *\n * While `UntrackedPolicyError` is the reason the config will not load, every Bash call is denied with\n * that refusal, and the refusal's own cure is `git add <the files>`. Denying it sent agents round the\n * same deny until they found `wp-migrate-dirs --stage`. The runner asks this question ONLY while that\n * specific refusal is active, so a healthy tree never sees it.\n *\n * ANY plain `git add` passes, not only one whose pathspecs cover the missing files, deliberately:\n * - `git add` touches only the index; it commits nothing, pushes nothing, and `git restore --staged`\n * undoes it. There is nothing to protect by narrowing it further;\n * - matching pathspecs against the missing files means re-implementing git's pathspec semantics\n * (directories, globs, `-A`, `.`, `:(top)` magic) — and every mismatch is the loop coming back,\n * because an agent's natural `git add -A` or `git add .webpieces-config` would be refused again.\n *\n * What it refuses is everything that could make the command do MORE than stage: any segment that is\n * not `git add` (an optional leading `cd <literal path> &&` excepted), a pipe or background `&`, and any\n * `$`, backtick or redirect — command substitution inside double quotes is not split out by the\n * scanner, so the characters themselves are refused rather than trusting the split.\n */\nexport class PolicyStagingCommand {\n constructor(private readonly scanner: CommandScanner = new CommandScanner()) {}\n\n isPlainGitAdd(command: string): boolean {\n // A trailing `&` leaves no segment to carry its join, so pipes and lone `&` are refused as text.\n if (/[`$<>|]/.test(command) || command.replace(/&&/g, '').includes('&')) return false;\n const segments = this.scanner.segmentsWithJoins(command);\n if (segments.length === 0) return false;\n let staged = false;\n for (let index = 0; index < segments.length; index++) {\n const segment = segments[index];\n if (!this.sequential(segment)) return false;\n if (index === 0 && segments.length > 1 && /^cd\\s+\\S+$/.test(segment.text)) continue;\n // The RAW text, not `words()`: that strips `sudo` / `env` / `VAR=x` prefixes, and\n // `GIT_DIR=… git add` stages into some other repository.\n if (!/^git\\s+add(\\s|$)/.test(segment.text)) return false;\n staged = true;\n }\n return staged;\n }\n\n // `&&` / `;` / newline only: a pipe hands git's output to another program, `&` backgrounds it.\n private sequential(segment: CommandSegment): boolean {\n return segment.join === 'none' || segment.join === '&&' || segment.join === ';' || segment.join === '\\n';\n }\n}\n"]}