@cratis/pi 7.142.1 → 7.143.1

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.
Files changed (37) hide show
  1. package/package/corpus/harnesses/copilot/instructions/profiles.instructions.md +1 -0
  2. package/package/corpus/harnesses/copilot/instructions/secrets.instructions.md +8 -8
  3. package/package/corpus/hooks/README.md +39 -1
  4. package/package/corpus/hooks/scripts/cratis-guard-secrets.sh +150 -18
  5. package/package/corpus/hooks/scripts/cratis-guard-shell-writes.sh +39 -7
  6. package/package/corpus/prompts/reverse-engineer.prompt.md +50 -0
  7. package/package/corpus/rules/profiles.md +1 -0
  8. package/package/corpus/rules/secrets.md +8 -8
  9. package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +3 -4
  10. package/package/corpus/skills/cratis-screenplay-event-modeling/references/evidence-format.md +146 -0
  11. package/package/corpus/skills/cratis-screenplay-event-modeling/references/understanding-pipeline.md +58 -0
  12. package/package/corpus/skills/cratis-screenplay-event-modeling/verification.json +14 -0
  13. package/package/corpus/skills/cratis-screenplay-legacy-extraction/SKILL.md +13 -14
  14. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/evidence-table-template.md +15 -18
  15. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/loss-report-template.md +1 -1
  16. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/neighbouring-skills.md +2 -0
  17. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/prologue-safety.md +9 -0
  18. package/package/corpus/skills/cratis-screenplay-legacy-extraction/references/re-entry-and-passes.md +6 -6
  19. package/package/corpus/skills/cratis-screenplay-legacy-extraction/verification.json +9 -0
  20. package/package/corpus/skills/cratis-screenplay-modeling-lifecycle/SKILL.md +1 -0
  21. package/package/corpus/skills/cratis-screenplay-reverse-engineering/LICENSE +14 -0
  22. package/package/corpus/skills/cratis-screenplay-reverse-engineering/SKILL.md +180 -0
  23. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/documentation-intake-and-screens.md +108 -0
  24. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/evidence-format.md +43 -0
  25. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/executable-intake.md +125 -0
  26. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/fidelity-check.md +141 -0
  27. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/ground-truth-benchmark.md +75 -0
  28. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/intake-sources.md +87 -0
  29. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/neighbouring-skills.md +17 -0
  30. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/probing-and-naming.md +87 -0
  31. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/provenance.md +11 -0
  32. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/scoping.md +79 -0
  33. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/synthesis-rules.md +140 -0
  34. package/package/corpus/skills/cratis-screenplay-reverse-engineering/references/target-and-first-validation.md +42 -0
  35. package/package/corpus/skills/cratis-screenplay-reverse-engineering/verification.json +29 -0
  36. package/package/profile-catalog.json +1 -0
  37. package/package.json +1 -1
@@ -295,6 +295,7 @@ and one phase skill, then the construct skill needed for syntax.
295
295
  | `cratis-screenplay-scenario-coverage` | Coverage matrix, rejection, denial, lifecycle and external-failure scenarios |
296
296
  | `cratis-screenplay-model-review` | Independent critique, evidence checklist and business-question explanation |
297
297
  | `cratis-screenplay-legacy-extraction` | Evidence-led extraction, expert verification and loss report |
298
+ | `cratis-screenplay-reverse-engineering` | Black-box evidence from a running app, HAR, API description or executable to a reviewed model that runs |
298
299
  | `cratis-screenplay-toolchain` | Compiler and CLI versions, verdict commands, diagnostics and executable subsets |
299
300
  | `cratis-screenplay-render-and-gap-fill` | Admission, publication, target verification and contract-led hand-written delivery |
300
301
  | `cratis-screenplay-delivery-planning` | Slice counts by type, dependency waves, issue tracking and estimates from the team's own history |
@@ -5,10 +5,9 @@ applyTo: "**/*"
5
5
 
6
6
  # Secrets never enter agent transcripts
7
7
 
8
- A transcript is saved, summarized and shared, so a credential that is printed once is leaked.
9
- Every line is tagged **[contract]** (binding) per the Three Levels of Authority in
10
- [`general.md`](../../../rules/general.md). The `cratis-guard-secrets` hook blocks the commands below
11
- (see [`.cratis/ai/hooks/README.md`](../../../hooks/README.md)); the rule holds where no hook runs.
8
+ Printed credentials leak into saved transcripts. All lines are **[contract]** (binding;
9
+ see [`general.md`](../../../rules/general.md)). The [hook](../../../hooks/README.md) enforces these rules;
10
+ they also hold without it.
12
11
 
13
12
  ## Commands
14
13
 
@@ -21,10 +20,11 @@ Every line is tagged **[contract]** (binding) per the Three Levels of Authority
21
20
  - **[contract] Project the field you need and say which one:** `-o jsonpath='{.spec.containers[*].image}'`,
22
21
  `-o custom-columns=…`, `kubectl get … -o name`, status fields, `kubectl logs`, `docker inspect --format`.
23
22
  Read a `.env.example`, never the `.env`.
24
- - **[contract] The hook reads command text only.** It cannot see a command piped into a shell
25
- (`… | sh`, `bash -c "$(…)"`), a recursive search with no named file (`grep -r PASSWORD .`), or a
26
- value reached through a variable, alias or script. These stay your rule to keep; output redaction
27
- is the only backstop.
23
+ - **[contract] Command-text checks cannot see** shell-piped code (`… | sh`, `bash -c "$(…)"`),
24
+ recursive searches without filenames (`grep -r PASSWORD .`), or paths hidden in variables,
25
+ aliases or scripts. The rules still apply; output redaction is the backstop.
26
+ - **[contract] After a guard block, narrowing to literal non-credential files is supported remediation,
27
+ not a workaround.** Follow `Use instead`; never disguise the same secret read.
28
28
 
29
29
  ## Values
30
30
 
@@ -12,12 +12,50 @@ Three layers:
12
12
  | Hard block | `PreToolUse` on a write | `scripts/cratis-guard-writes.sh` | zero | exits **2** — the write does not happen |
13
13
  | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-shell-writes.sh` | zero tokens; one batch Write/Edit classification | exits **2** — a protected reference requires read-only syntax throughout the command; best-effort, not a sandbox |
14
14
  | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-store-mutations.sh` | zero; parses only commands that mention `cratis` | exits **2** — the store-changing `cratis chronicle` command does not run |
15
- | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-secrets.sh` | zero; parses only commands that mention a credential-bearing tool or file | exits **2** — the guard is a **best-effort, defense-in-depth text filter, NOT a sandbox**: it refuses some harmless commands rather than model the whole shell. Real protection requires **OS-level sandboxing or file permissions**. A command is *tainted* when a protected file-name stem appears in any token, including option values, in any letter case, after quotes, backslashes and line continuations are removed. Only search regex text is exempt: `-e`/`--regexp` values, or the first operand when neither `-e` nor `-f` is present. `-f`/`--file` values and all other operands are paths, not exempt patterns. The stems are `.env`, `.pem`, `.p12`, `.pfx`, `id_rsa`, `id_ed25519`, `id_ecdsa`, `id_dsa`, `.netrc`, `.npmrc`, `.pgpass`, `.pypirc`, `.git-credentials`, `.kube/`, `kubeconfig`, `credentials`, `.docker/`, `/environ` and `run/secrets`. Stars, question marks, bracket expressions and grouped pathname patterns count as the characters they can match when the pattern retains at least two literal stem characters. A command is also tainted when an assignment value or any expanded word can contain a stem. A tainted command runs only when it is a single simple command with every word literal: `cat`, `head`, `tail`, `less`, `more`, `wc`, `grep`, `egrep`, `fgrep` or `rg` of paths that are not protected (such as `cat .env.example`); `test` of literal paths; or `cp SOURCE DEST` with no options and a source that is not protected (for example, `cp .env.example example.txt`; the shell-write guard separately refuses `.env` destinations). A single simple `ls` or `stat` may also take glob operands, but not variables, substitutions, wrappers or other shell structure. Tainted searches cannot recurse, search a directory with `rg`, omit `rg` path operands, or use value-taking options other than `-e`/`--regexp`. Every other tainted command is refused, including variables, command substitution, globs for content readers, loops, conditionals, pipes, redirections, here-strings, here-documents, wrappers, `bash -c`, `eval` and transfer tools. Shell-option changes are checked even without a protected stem: modifying `shopt`, `setopt`, `unsetopt` and `emulate` are refused. `extglob` is refused as an option, not merely as text. Shell invocation `-o`/`-O` options, including clustered flags, must name a supported option. Expanded `set` arguments are refused. Only `set` flags `e`, `u`, `x`, `f`, `v`, `E`, `T` and named options `errexit`, `nounset`, `pipefail`, `xtrace`, `verbose`, `noglob`, `errtrace`, `functrace` (including their `+` forms) are supported. The message names the stem: run the read on its own with literal paths, or put long text that mentions the name in a file. Commands without a stem keep the full analysis. In that analysis a variable can hold any value the command assigns to it anywhere, a positional parameter or an unquoted expansion with glob or space characters is unknown, and an unknown file operand is refused. Residual classes include **shell glob grammar across bash and zsh, option toggles, option arity and quote concatenation**, as well as runtime-generated names, inherited state, filesystem indirection, user-defined commands, external programs and scripts, and searches without a named protected path. These classes are not modeled exhaustively. Use OS-level sandboxing or file permissions, harness isolation and least privilege as the primary boundary. Token files and key-extension globs (`*.key`, `*.jks`) are refused only through the listed reader, input, `dd` and transfer commands; see [`secrets.md`](../rules/secrets.md) |
15
+ | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-secrets.sh` | zero; parses only commands that mention a credential-bearing tool or file | exits **2** — the guard is a **best-effort, defense-in-depth text filter, NOT a sandbox**: it refuses some harmless commands rather than model the whole shell. Real protection requires **OS-level sandboxing or file permissions**. A command is *tainted* when a protected file-name stem appears in any token, including option values, in any letter case, after quotes, backslashes and line continuations are removed. Only search regex text is exempt: `-e`/`--regexp` values, or the first operand when neither `-e` nor `-f` is present. `-f`/`--file` values and all other operands are paths, not exempt patterns. The stems are `.env`, `.pem`, `.p12`, `.pfx`, `id_rsa`, `id_ed25519`, `id_ecdsa`, `id_dsa`, `.netrc`, `.npmrc`, `.pgpass`, `.pypirc`, `.git-credentials`, `.kube/`, `kubeconfig`, `credentials`, `.docker/`, `/environ` and `run/secrets`. Stars, question marks, bracket expressions and grouped pathname patterns count as the characters they can match when the pattern retains at least two literal stem characters. For `credentials` only, an embedded occurrence in a longer directory component or a recognized source filename (for example `Specs/for_ApplicationCredentials/a.cs` or `CredentialsProvider.cs`) is not a stem hit; exact `credentials`, `credentials.*` and a `credentials/` component remain protected. A command is also tainted when an assignment value or any expanded word can contain a stem. A tainted command runs only when it is a single simple command with every word literal: `cat`, `head`, `tail`, `less`, `more`, `wc`, `grep`, `egrep`, `fgrep` or `rg` of paths that are not protected (such as `cat .env.example`); `test` of literal paths; or `cp SOURCE DEST` with no options and a source that is not protected (for example, `cp .env.example example.txt`; the shell-write guard separately refuses `.env` destinations). A single simple `ls` or `stat` may also take glob operands, but not variables, substitutions, wrappers or other shell structure. Tainted searches cannot recurse, search a directory with `rg`, omit `rg` path operands, or use value-taking options other than `-e`/`--regexp`. Every other tainted command is refused, including variables, command substitution, globs for content readers, loops, conditionals, pipes, redirections, here-strings, here-documents, wrappers, `bash -c`, `eval` and transfer tools. Shell-option changes are checked even without a protected stem: modifying `shopt`, `setopt`, `unsetopt` and `emulate` are refused. `extglob` is refused as an option, not merely as text. Shell invocation `-o`/`-O` options, including clustered flags, must name a supported option. Expanded `set` arguments are refused. Only `set` flags `e`, `u`, `x`, `f`, `v`, `E`, `T` and named options `errexit`, `nounset`, `pipefail`, `xtrace`, `verbose`, `noglob`, `errtrace`, `functrace` (including their `+` forms) are supported. The message names the stem: list the directory with `ls`, then name exact non-credential paths, or use `rg -l PATTERN literal-file`. Narrowing to safe literal files is supported remediation, not a workaround; disguising the same secret read behind a variable, glob, wrapper, script or alias remains prohibited. Commands without a stem keep the full analysis. In that analysis a variable can hold any value the command assigns to it anywhere, a positional parameter or an unquoted expansion with glob or space characters is unknown, and an unknown file operand is refused. Residual classes include **shell glob grammar across bash and zsh, option toggles, option arity and quote concatenation**, as well as runtime-generated names, inherited state, filesystem indirection, user-defined commands, external programs and scripts, and searches without a named protected path. These classes are not modeled exhaustively. Use OS-level sandboxing or file permissions, harness isolation and least privilege as the primary boundary. Token files and key-extension globs (`*.key`, `*.jks`) are refused only through the listed reader, input, `dd` and transfer commands; see [`secrets.md`](../rules/secrets.md) |
16
16
  | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-pr-body.sh` | fetches shared rules only for `gh pr create/edit` | exits **2** for inline bodies, invalid notes or conflicting release labels; warns and allows when offline with no cache |
17
17
  | Cleanup of delivered work | `PostToolUse` on `Bash` (`gh pr merge`, `git pull/merge/worktree`) and `SessionStart` (Pi: `tool_result` and `session_start`) | `scripts/cratis-cleanup-worktrees.sh --hook` | zero when the command is unrelated | never blocks; removes delivered worktrees and branches, reports what it kept |
18
18
  | Quality gate (Claude) | `Stop` | `scripts/cratis-quality-gate.sh` | one build/test run, only when relevant files changed | exits **2** — the turn does not end |
19
19
  | Quality gate (Pi) | explicit `cratis_quality_gate` tool | same script | only at a requested verification checkpoint | error on failure; no turn-end hook |
20
20
 
21
+ For false positives, a literal-prefix trailing `*`, including literal directory components, can be
22
+ resolved in a known, readable cwd and parent directory. A single reader may stand alone or appear in
23
+ an `&&` chain of literal read-only Git metadata commands, optionally after a literal leading `cd`.
24
+ The probe is bound to that reader's parsed command index. Arbitrary earlier/later commands, functions,
25
+ quoted command names, other separators and shell evaluation do not qualify. Quoted search patterns
26
+ and format values remain data. Only fixed code with quoted positional arguments performs expansion;
27
+ command text is never evaluated. At most 200 ordinary, non-symlink matches are checked in both physical
28
+ absolute and original path contexts. Case-insensitive probing overapproximates filesystem case rules.
29
+ Protected matches block even filename-only searches. Unknown cwd, unreadable/missing directories,
30
+ complex patterns and ambiguous shell state fail closed. A successful empty expansion of a non-secret
31
+ prefix may pass; secret-like patterns (`.env*`, `*.pem`, `*.key`, `id_rsa*`) still block. Empty content
32
+ searches with secret/certificate/key-like prefixes also remain blocked. For ripgrep, `-L` follows
33
+ symlinks, not filename-only mode. Literal directory checks retain the process-cwd fallback when the
34
+ payload omits cwd; glob probing does not. Filesystem check/use races remain: this is not a sandbox.
35
+
36
+ The shell-write reference scan keeps conservative leading-dot intersections: a tool named `Bash`,
37
+ `SHELL`, and the hook process's options do not establish the execution shell's options. Globbed writes
38
+ therefore remain blocked. Read operands under protected paths are not write targets: `rg -n`/`-l`,
39
+ quoted `--glob`/`-g` filters, and numeric/last-line `sed -n …p` scripts are recognized as read-only.
40
+ `sed -n` scripts with writes, execution or extra options are not exempt. New `cd` and
41
+ `git branch --show-current` exemptions permit only `&&`-only read/search chains, not semicolons,
42
+ pipelines or other separators. Any file redirection in a cwd-changing chain fails closed because
43
+ its target is not proven against the changed cwd. Mutating commands and protected redirects stay
44
+ blocked. No shell-option assumption is used to dismiss leading-dot intersections.
45
+ Heredoc bodies receive the same conservative whole-text reference scan as other command text,
46
+ including code-like braces. Interpreter syntax does not exempt embedded shell strings. If an inline
47
+ script is blocked, write it with the edit/write tool and run the script file instead.
48
+ Portable bracket classes are kept; ambiguous backslash-bearing classes are widened instead of passed
49
+ as invalid awk regexes.
50
+
51
+ Literal `git ls-files` pathspecs are filename metadata, including `-s`/`--stage` and `--debug`,
52
+ so credential-worded source directories do not taint that single command. Other Git subcommands
53
+ receive no metadata exemption. Bare `git grep` uses grep's pattern/file distinction, including `-e`
54
+ pattern values; protected pathspecs remain blocked. `git show` and `git cat-file` of secret paths
55
+ remain content reads, not filename metadata.
56
+
57
+ Consumers receive these hook changes by running `cratis ai update`.
58
+
21
59
  The Claude Code wiring that fires them is tracked here, in
22
60
  [`settings.template.json`](./settings.template.json). Claude reads `.claude/settings.json`. In a
23
61
  repository set up with `cratis ai install`, that file is a **symlink** to this template and follows
@@ -110,12 +110,20 @@ function ansi_c(s, i, n, c, c2, v, d, k, lim, stop, digits) {
110
110
  # or operands (`kubectl get > /dev/stdout secrets`). Nothing is exempted: the command itself is still analyzed.
111
111
  # A word is a redirection only when its whole operator lies in the word's unquoted prefix (WP: characters before
112
112
  # the first quoted or escaped one), so `1">"b` and `">x"` stay operands; input redirections (`< file`) stay too.
113
- function stem_boundary(t, start, finish, stem, a, b, before, after) {
113
+ function stem_boundary(t, start, finish, stem, a, b, before, after, left, right, component) {
114
114
  if (stem == "/environ" && substr(t, finish + 1, 1) ~ /[a-z0-9_]/) return 0
115
115
  if (stem !~ /^(id_rsa|id_ed25519|id_ecdsa|id_dsa|kubeconfig|credentials)$/) return 1
116
116
  a = start; b = finish
117
117
  while (a > 1 && substr(t, a - 1, 1) ~ /[a-z0-9_]/) a--
118
118
  while (b < length(t) && substr(t, b + 1, 1) ~ /[a-z0-9_]/) b++
119
+ if (stem == "credentials") {
120
+ left = a; right = b
121
+ while (left > 1 && substr(t, left - 1, 1) ~ /[a-z0-9_.-]/) left--
122
+ while (right < length(t) && substr(t, right + 1, 1) ~ /[a-z0-9_.-]/) right++
123
+ component = substr(t, left, right - left + 1)
124
+ if (component !~ /^credentials([.]|$)/ && substr(t, right + 1, 1) == "/") return 0
125
+ if (code_file(component) && component !~ /^credentials\./) return 0
126
+ }
119
127
  before = substr(t, a - 1, 1); after = substr(t, b + 1)
120
128
  return !(before == "$" || before == "-" || (before == "{" && substr(t, a - 2, 1) == "$") || after ~ /^(=|\+=)/)
121
129
  }
@@ -206,6 +214,7 @@ function regex_short_flag(b, c) {
206
214
  function regex_slots(A, s, n, b, k, j, w, c, explicit, ended, attached, uncertain) {
207
215
  delete RP; delete ROPER
208
216
  b = base(A[s])
217
+ if (A[s] == "git" && A[s + 1] == "grep") { s++; b = "grep" }
209
218
  if (b !~ /^(grep|egrep|fgrep|rg|ag)$/) return
210
219
  for (k = s + 1; k <= n; k++) {
211
220
  w = A[k]
@@ -247,7 +256,7 @@ function directory_operand(w, path) {
247
256
  if (w ~ /\/$/ || w == "." || w == "..") return 1
248
257
  path = w
249
258
  if (path ~ /^~\//) path = ENVIRON["HOME"] substr(path, 2)
250
- if (path !~ /^\//) path = ENVIRON["GS_CWD"] "/" path
259
+ if (path !~ /^\//) path = ENVIRON["GS_CWD_FALLBACK"] "/" path
251
260
  return system("test -d " shell_quote(path)) == 0
252
261
  }
253
262
  function metadata_shape(A, M, n, k, j, c, mk) {
@@ -270,6 +279,14 @@ function literal_shape(A, M, n, k, j, b, words, count, pattern, ended, w, pat
270
279
  }
271
280
  }
272
281
  b = words[1]
282
+ if (b == "git" && words[2] == "ls-files") {
283
+ for (k = 3; k <= count; k++) {
284
+ w = words[k]
285
+ if (!ended && w == "--") { ended = 1; continue }
286
+ if (!ended && w ~ /^-/ && w !~ /^(-s|--stage|--debug)$/) return 0
287
+ }
288
+ return 1
289
+ }
273
290
  if (b ~ /\// || b !~ /^(cat|head|tail|less|more|wc|grep|egrep|fgrep|rg|ls|stat|test|cp)$/) return 0
274
291
  if (b ~ /^(ls|stat|test)$/) return 1
275
292
  if (b == "cp") return count == 3 && words[2] !~ /^-/ && words[3] !~ /^-/ && sensitive_path(words[2]) == ""
@@ -648,7 +665,7 @@ function variable_values(name, k, j, count, result, values, masks, value_part
648
665
  value_depth--; delete ACTIVE[name]
649
666
  return result
650
667
  }
651
- function param(w, m, i, c, j, name, inner, op, base, rest, depth, bad, special, kind) {
668
+ function param(w, m, i, c, j, name, inner, op, base_value, rest, depth, bad, special, kind) {
652
669
  delete PC; npc = 1; PC[1] = "$"
653
670
  c = substr(w, i + 1, 1); name = ""; op = ""; rest = ""
654
671
  if (c == "{") {
@@ -678,8 +695,8 @@ function param(w, m, i, c, j, name, inner, op, base, rest, depth, bad, specia
678
695
  if (name == "_") special = "\001"
679
696
  if (bad) { PC[1] = "\001"; return i }
680
697
  if (op == "=") bind_value(name, rest, "")
681
- base = (special != "") ? special : variable_values(name)
682
- delete PC; npc = split(base, PC, "\034")
698
+ base_value = (special != "") ? special : variable_values(name)
699
+ delete PC; npc = split(base_value, PC, "\034")
683
700
  if (op == "+") { npc = 2; PC[1] = rest; PC[2] = "" }
684
701
  else if (op == "-" || op == "=") PC[++npc] = rest
685
702
  return i
@@ -746,6 +763,22 @@ function resolve(w, m, k, j, words, masks, count, resolved_values, nr, failed
746
763
  }
747
764
  function has_sentinel(b) { return b ~ /[\001-\007]/ }
748
765
  function only_runtime(b, t) { t = b; gsub("\003", "", t); return t == "" }
766
+ # A shell bracket with escapes or nonportable class syntax is widened, never narrowed.
767
+ # In particular a trailing backslash must not escape the closing bracket in an awk regex.
768
+ function bracket_rx(body, check, k, before, after) {
769
+ if (body == "" || index(body, "\\")) return "[^/]"
770
+ if (index(body, "[:") && index(body, "-")) return "[^/]"
771
+ sub(/^!/, "^", body); check = body
772
+ # Preserve portable POSIX classes, but never feed unknown classes/collation to awk.
773
+ gsub(/\[:(alnum|alpha|blank|cntrl|digit|graph|lower|print|punct|space|upper|xdigit):\]/, "x", check)
774
+ sub(/^\^/, "", check)
775
+ if (check == "" || check ~ /[\[\]^]/) return "[^/]"
776
+ for (k = 2; k < length(check); k++) if (substr(check, k, 1) == "-") {
777
+ before = substr(check, k - 1, 1); after = substr(check, k + 1, 1)
778
+ if (before == "-" || after == "-" || before > after) return "[^/]"
779
+ }
780
+ return "[" body "]"
781
+ }
749
782
  # An anchored regex for a name that can hold sentinels: \001 and \003 match any string, \002 one character.
750
783
  function rxize(b, k, c, r, j, bracket) {
751
784
  r = ""
@@ -756,7 +789,7 @@ function rxize(b, k, c, r, j, bracket) {
756
789
  else if (c == "\002" || c == "\005") r = r "[^/]"
757
790
  else if (c == "\006") {
758
791
  j = index(substr(b, k + 1), "\007"); bracket = substr(b, k + 1, j - 1)
759
- sub(/^!/, "^", bracket); r = r "[" bracket "]"; k += j
792
+ r = r bracket_rx(bracket); k += j
760
793
  }
761
794
  else if (index(".[]()*+?{}|^$\\", c)) r = r "\\" c
762
795
  else r = r c
@@ -821,6 +854,83 @@ function path_probe(a, probe, path_parts, probe_parts, n, m, k, tail) {
821
854
  for (k = n-m+2; k <= n; k++) tail = tail "/" path_parts[k]
822
855
  return pattern_match(tail, probe)
823
856
  }
857
+ # Only a literal prefix plus one trailing star is resolved against the filesystem.
858
+ # The script is fixed shell code: cwd/prefix are single-quoted positional arguments, and
859
+ # only the literal basename prefix plus * is expanded. No command text, operand or bracket body is evaluated as code.
860
+ # Recognize only && chains with one reader and literal read-only Git metadata.
861
+ # Quoted regex/format text is opaque data; expansions and other shell syntax fail
862
+ # closed. The semantic command index binds a probe to that reader, not a later one.
863
+ function probe_read_chain(text, prior, i, c, q, normal, n, k, readers, reader_index, clause, parts) {
864
+ for (i = 1; i <= length(text); i++) {
865
+ c = substr(text, i, 1)
866
+ if (c ~ /[\001-\010\012-\037\177]/) return 0
867
+ if (q == "\047") { if (c == q) q = ""; continue }
868
+ if (c ~ /[$`\\]/) return 0
869
+ if (q == "\"") { if (c == q) q = ""; continue }
870
+ if (c == "\047" || c == "\"") { q = c; normal = normal "Q"; continue }
871
+ if (c == "&" && substr(text, i + 1, 1) == "&") { normal = normal "\034"; i++; continue }
872
+ if (c ~ /[;&|(){}<>]/) return 0
873
+ normal = normal c
874
+ }
875
+ if (q != "") return 0
876
+ n = split(normal, parts, "\034")
877
+ for (k = 1; k <= n; k++) {
878
+ clause = parts[k]; sub(/^[ \t]+/, "", clause); sub(/[ \t]+$/, "", clause)
879
+ if (clause ~ /^(cat|rg|grep|egrep|fgrep|head|tail)[ \t]/) { readers++; reader_index = prior + k; continue }
880
+ if (clause ~ /^git[ \t]+diff([ \t]+(--cc|--stat|--check|--no-color))*$/) continue
881
+ if (clause ~ /^git[ \t]+log([ \t]+(-[0-9]+|--format=[^ \t]+|--oneline|--no-color))*$/) continue
882
+ if (clause ~ /^git[ \t]+(branch[ \t]+--show-current|rev-parse[ \t]+HEAD|status[ \t]+--short)$/) continue
883
+ return 0
884
+ }
885
+ return readers == 1 && reader_index == commands
886
+ }
887
+ function glob_directory( text, head, dir, prior) {
888
+ dir = ENVIRON["GS_CWD"]; text = CMD
889
+ if (ENVIRON["GS_GLOB_SAFE"] != "1" || dir == "" || dir !~ /^\//) return ""
890
+ if (text ~ /^[ \t]*cd([ \t]|&&|$)/) {
891
+ if (!match(text, /^[ \t]*cd[ \t]+(\047[^\047\n]+\047|"[^"$`\\\n]+"|[A-Za-z0-9_.\/@+-]+)[ \t]*&&/)) return ""
892
+ head = substr(text, 1, RLENGTH); text = substr(text, RLENGTH + 1)
893
+ sub(/^[ \t]*cd[ \t]+/, "", head); sub(/[ \t]*&&$/, "", head)
894
+ if (head ~ /^[\047"]/) head = substr(head, 2, length(head) - 2)
895
+ if (head ~ /^[-~]/) return ""
896
+ if (head !~ /^\// && ENVIRON["CDPATH"] != "") return ""
897
+ if (head ~ /^\//) dir = head; else dir = dir "/" head
898
+ prior = 1
899
+ }
900
+ if (dir ~ /(^|\/)\.\.(\/|$)/ || qi != 1 || !probe_read_chain(text, prior)) return ""
901
+ return dir
902
+ }
903
+ function glob_secret_match(a, prefix, parent, dir, script, cmd, line, count, ok, kind, found, name, original, basename, k) {
904
+ prefix = substr(a, 1, length(a) - 1)
905
+ if (substr(a, length(a), 1) != "\004" || prefix == "" || prefix ~ /[^A-Za-z0-9._\/@+=,:%-]/) return "a key or certificate file"
906
+ parent = prefix; sub(/[^\/]*$/, "", parent)
907
+ dir = glob_directory()
908
+ if (dir == "" || parent ~ /(^|\/)\.\.(\/|$)/) return "a key or certificate file"
909
+ # Compare the actual directories reached under both cd modes before probing.
910
+ script = "unset GLOBIGNORE CDPATH; shopt -u failglob; shopt -s nullglob dotglob nocaseglob; " \
911
+ "checked_cd() { local logical; logical=$(cd -L -- \"$1\" && pwd -P) || return 3; " \
912
+ "cd -P -- \"$1\" || return 3; [ \"$logical\" = \"$PWD\" ] && [ -r . ] && [ -x . ]; }; " \
913
+ "checked_cd \"$1\" || exit 3; parent=${2%/*}; stem=${2##*/}; [ \"$parent\" != \"$2\" ] || parent=.; " \
914
+ "checked_cd \"$parent\" || exit 3; " \
915
+ "n=0; for f in \"$stem\"*; do n=$((n+1)); [ \"$n\" -le 200 ] && [ -f \"$f\" ] && [ ! -L \"$f\" ] || exit 3; " \
916
+ "case \"$PWD/$f\" in *[!a-zA-Z0-9._/@+=,:%-]*) exit 3;; esac; printf \"F:%s\\n\" \"$PWD/$f\"; done; echo OK"
917
+ cmd = "bash -c " shell_quote(script) " guard-glob " shell_quote(dir) " " shell_quote(prefix) " 2>/dev/null"
918
+ while ((cmd | getline line) > 0) {
919
+ if (line == "OK") { ok = 1; continue }
920
+ if (ok || substr(line, 1, 2) != "F:" || ++count > 200) { ok = 0; break }
921
+ name = substr(line, 3); kind = sensitive_path(name)
922
+ basename = name; sub(/.*\//, "", basename)
923
+ original = prefix; sub(/[^\/]*$/, "", original); original = original basename
924
+ if (original !~ /^\//) original = dir "/" original
925
+ if (kind == "") kind = sensitive_path(original)
926
+ for (k = 1; k <= nextension; k++) if (tolower(name) ~ ("\\." EXT[k] "$")) kind = "a key or certificate file"
927
+ if (kind != "" && found == "") { found = kind; matched_file = name }
928
+ }
929
+ close(cmd)
930
+ if (!ok) { matched_file = ""; return "a key or certificate file" }
931
+ if (!count && !filenames_only && (base(prefix) ~ /^(secrets?|cert(ificate)?s?|keys?|private|credentials?)([._-]|$)/ || tolower(prefix) ~ /\.(pem|key|p12|pfx|jks|keystore|kdbx|kubeconfig|env)([._-]|$)/ || sensitive_path(dir "/" prefix) != "")) return "a key or certificate file"
932
+ return found
933
+ }
824
934
  # Literal words retain the full classifier. Glob words use canonical names and all protected extensions;
825
935
  # substring-only token names outside that canonical set are not glob probes.
826
936
  function alt_kind(a, b, d, kind, k, glob) {
@@ -842,7 +952,7 @@ function alt_kind(a, b, d, kind, k, glob) {
842
952
  if (kind != "") return kind
843
953
  if (PROBE[k] == "credentials" || PROBE[k] == ".pypirc") return "a credentials file"
844
954
  }
845
- for (k = 1; k <= nextension; k++) if (overlap(b, "\004." EXT[k])) return "a key or certificate file"
955
+ for (k = 1; k <= nextension; k++) if (overlap(b, "\004." EXT[k])) return glob_secret_match(a)
846
956
  } else if (glob) {
847
957
  for (k = 1; k <= nprobe; k++) if (b == PROBE[k]) {
848
958
  kind = sensitive_path(d b)
@@ -855,8 +965,8 @@ function alt_kind(a, b, d, kind, k, glob) {
855
965
  return ""
856
966
  }
857
967
  # The kind of protected file operand k of A names; via_pattern says the answer came from a pattern or a variable.
858
- function operand_kind(A, k, off, w, m, j, kind) {
859
- w = A[k]; m = mask_of(A, k); via_pattern = 0
968
+ function operand_kind(A, k, off, filenames, w, m, j, kind) {
969
+ w = A[k]; m = mask_of(A, k); via_pattern = 0; matched_file = ""; filenames_only = filenames
860
970
  if (off > 0) { w = substr(w, off + 1); m = substr(m, off + 1) }
861
971
  if (!expands(w, m)) return sensitive_path(w)
862
972
  resolve(w, m); via_pattern = 1
@@ -1090,8 +1200,12 @@ function scan_short(w, shortvals, sed_like, i, c, last) {
1090
1200
  if (sed_like && c == "i") return
1091
1201
  }
1092
1202
  }
1093
- function reader(A, s, n, b, k, w, mode, havepat, need, afterdd, kind, valued, valued2, shortvals) {
1203
+ function reader(A, s, n, b, k, w, mode, havepat, need, afterdd, kind, valued, valued2, shortvals, filenames) {
1094
1204
  b = base(A[s]); mode = ""; valued = " "; valued2 = " "; shortvals = ""
1205
+ if (b ~ /^(rg|grep|egrep|fgrep)$/) {
1206
+ for (k = s + 1; k <= n; k++) if (A[k] == "-l" || (b != "rg" && A[k] == "-L") || A[k] ~ /^--files-with(out)?-match(es)?$/) filenames = 1
1207
+ for (k = s + 1; k <= n; k++) if (A[k] ~ /^-/ && ((b == "rg" && A[k] == "-L") || A[k] !~ /^(-[lL]|--files-with(out)?-match(es)?|--|-e|-F|--fixed-strings)$/)) filenames = 0
1208
+ }
1095
1209
  if (b ~ /^(grep|egrep|fgrep|rg|ag)$/) { mode = "pattern"; shortvals = (b ~ /^(grep|egrep|fgrep)$/) ? "mABCdD" : (b == "rg") ? "mABCdjEMrgtT" : "ABCGgmpW"; valued = " --glob --type --type-not --max-count --include --exclude --exclude-dir --context --after-context --before-context --max-depth --threads " }
1096
1210
  else if (b ~ /^(sed|awk|gawk|jq|yq)$/) { mode = "script"; shortvals = "vF"; valued = " --indent "; valued2 = " --arg --argjson --slurpfile --rawfile " }
1097
1211
  # The first operand is the pattern or script unless -e/-f/--regexp/--file/--expression supplies it; only the rest are files.
@@ -1113,8 +1227,9 @@ function reader(A, s, n, b, k, w, mode, havepat, need, afterdd, kind, valued,
1113
1227
  continue
1114
1228
  }
1115
1229
  if (need) { need = 0; continue }
1116
- kind = operand_kind(A, k, 0)
1117
- if (kind != "" && via_pattern) report(b " of a name that can match " kind " prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
1230
+ kind = operand_kind(A, k, 0, filenames)
1231
+ if (kind != "" && matched_file != "") report(b " of " kind " (" matched_file ") prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
1232
+ else if (kind != "" && via_pattern) report(b " of a glob that may match " kind " prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
1118
1233
  else if (kind != "") report(b " of " kind " prints credentials", "name the file and the key you need in your report; ask the user to confirm a value instead of printing it; for an env template read the .env.example")
1119
1234
  }
1120
1235
  }
@@ -1144,6 +1259,17 @@ function transfer_files(A, s, n, b, k, last, options, kind, w, eq, off, ended
1144
1259
  if (kind != "") report(b " reads " kind, "name only non-credential source files")
1145
1260
  }
1146
1261
  }
1262
+ # Git grep reuses pattern/file separation; ls-files never reaches this content path.
1263
+ function git_content(A, s, n, subcommand, k, w) {
1264
+ subcommand = A[s + 1]
1265
+ if (subcommand !~ /^(grep|show|cat-file)$/) return
1266
+ if (subcommand == "grep") reader(A, s + 1, n)
1267
+ for (k = s + 2; k <= n; k++) {
1268
+ if (subcommand == "grep" && !(k in ROPER)) continue
1269
+ w = tolower(A[k]); sub(/^.*[\/:]/, "", w)
1270
+ if (w == "secrets.json") report("git " subcommand " of a credentials file prints credentials", "name only non-credential source files; list filenames with git ls-files")
1271
+ }
1272
+ }
1147
1273
  function analyze(A, s, n, w, b, k, names, p, config, get, show, first) {
1148
1274
  nrt = 0; delete REDIRECT_TOKENS; delete ROFF; first = s
1149
1275
  while (s <= n) {
@@ -1179,6 +1305,7 @@ function analyze(A, s, n, w, b, k, names, p, config, get, show, first) {
1179
1305
  }
1180
1306
  if (expands(A[s], mask_of(A, s))) return dyn_command(A, s, n)
1181
1307
  b = base(A[s])
1308
+ if (A[s] == "git") git_content(A, s, n)
1182
1309
  shell_config(A, s, n, b)
1183
1310
  collect_bindings(A, s, n, b)
1184
1311
  if (b == "for" || b == "select" || b == "unset") return
@@ -1284,10 +1411,11 @@ BEGIN {
1284
1411
  }
1285
1412
  AWK
1286
1413
 
1287
- # Only literal rg needs the invocation directory to distinguish file and directory operands.
1288
- command_cwd="$PWD"
1289
- case "$probe" in *rg*) command_cwd="$(jq -r '.cwd // empty' <<<"$input")" || parser_failed; command_cwd="${command_cwd:-$PWD}" ;; esac
1290
- findings="$(GS_COMMAND="$command_text" GS_CWD="$command_cwd" LC_ALL=C awk "$awk_program" </dev/null)" || parser_failed
1414
+ # Never infer a missing hook cwd for filesystem-dependent glob decisions.
1415
+ command_cwd="$(jq -r '.cwd // empty' <<<"$input")" || parser_failed
1416
+ glob_shell_safe=1
1417
+ if [[ -n "${BASH_ENV+x}" || -n "${ENV+x}" || -n "${GLOBIGNORE+x}" ]] || shopt -q dotglob || shopt -q nocaseglob; then glob_shell_safe=0; fi
1418
+ findings="$(GS_COMMAND="$command_text" GS_CWD="$command_cwd" GS_CWD_FALLBACK="${command_cwd:-$PWD}" GS_GLOB_SAFE="$glob_shell_safe" LC_ALL=C awk "$awk_program" </dev/null)" || parser_failed
1291
1419
  [ -n "$findings" ] || exit 0
1292
1420
 
1293
1421
  {
@@ -1306,8 +1434,12 @@ refer to a secret by name (secret/key, environment variable) in notes, briefs an
1306
1434
  If a value has already appeared in output: stop, do not copy it onward, report "SECURITY INCIDENT" with the
1307
1435
  tool-call location and the credential kind, and ask for rotation.
1308
1436
 
1309
- Do not retry this, rephrase it, or work around the guard (another wrapper, a script file, a variable, an
1310
- alias). A person who authorized the read sets CRATIS_HOOKS_ALLOW_SECRET_READS=1 in the environment the agent
1437
+ For a false positive, a narrower command naming exact non-credential files is the supported route, not a
1438
+ workaround: ls the directory first, then use literal file paths (e.g. Specs/given/an_application.cs or
1439
+ rg -l PATTERN literal-file).
1440
+
1441
+ Do not retry the same read disguised behind a variable, glob, wrapper, script file or alias, or work around
1442
+ the guard. A person who authorized the read sets CRATIS_HOOKS_ALLOW_SECRET_READS=1 in the environment the agent
1311
1443
  harness was started from; setting it inside the command has no effect.
1312
1444
  EOF
1313
1445
  case "$findings" in
@@ -95,7 +95,10 @@ function protected(s) { return s in protected_paths }
95
95
  function endword() {
96
96
  if (!inword) return
97
97
  if (redirect) {
98
- if (!(redirect == 2 && word ~ /^([0-9]+|-)$/) && (word ~ /[$`*?\[{]/ || protected(word))) bad = 1
98
+ if (!(redirect == 2 && word ~ /^([0-9]+|-)$/)) {
99
+ file_redirect = 1
100
+ if (changed_cwd || word ~ /[$`*?\[{]/ || protected(word)) bad = 1
101
+ }
99
102
  redirect = 0
100
103
  } else {
101
104
  if (++argc > 256) bad = 1
@@ -151,6 +154,10 @@ function options_allowed(verb, first, i, w) {
151
154
  continue
152
155
  }
153
156
  }
157
+ if ((verb == "rg" && (w == "--glob" || w == "-g")) || (verb == "git grep" && (w == "-e" || w == "--regexp"))) {
158
+ if (++i > argc || globbed[i]) return 0
159
+ continue
160
+ }
154
161
  if (!short_flags(w, short_options[verb])) return 0
155
162
  }
156
163
  return 1
@@ -164,15 +171,36 @@ function directory_metadata() {
164
171
  if (argc == 5) return (W[4] == "status" && W[5] == "--short") || (W[4] == "rev-parse" && W[5] == "HEAD") || (W[4] == "branch" && W[5] == "--show-current")
165
172
  return argc == 6 && W[4] == "tag" && W[5] == "--list" && W[6] !~ /^-/
166
173
  }
174
+ # -n alone is not read-only: sed scripts can still execute or write files.
175
+ # Only numeric/last-line print addresses qualify, with no additional options.
176
+ function print_only_sed( i, ended) {
177
+ if (argc < 4 || W[2] != "-n" || W[3] !~ /^([0-9]+(,([0-9]+|\$))?|\$)?p$/) return 0
178
+ for (i = 4; i <= argc; i++) {
179
+ if (!ended && W[i] == "--") { ended = 1; continue }
180
+ if (!ended && W[i] ~ /^-/) return 0
181
+ }
182
+ return 1
183
+ }
167
184
  function allow_command( verb, first) {
168
185
  if (!argc) return
169
186
  if (++commands > 64) { bad = 1; return }
170
187
  verb = W[1]; first = 2
188
+ if (verb == "cd") {
189
+ conditional_only = 1
190
+ if (argc != 2 || W[2] == "" || W[2] ~ /^-/ || globbed[2] || file_redirect) bad = 1
191
+ changed_cwd = 1
192
+ return
193
+ }
194
+ if (verb == "sed") { if (!print_only_sed()) bad = 1; return }
171
195
  if (verb == "git" && W[2] == "-C") {
172
196
  if (!directory_metadata()) bad = 1
173
197
  return
174
198
  }
175
199
  if (verb == "git") { verb = verb " " W[2]; first = 3 }
200
+ if (verb == "git branch") {
201
+ conditional_only = 1
202
+ if (argc != 3 || W[3] != "--show-current") { bad = 1; return }
203
+ }
176
204
  if (!(verb in verbs) || !options_allowed(verb, first)) bad = 1
177
205
  }
178
206
  function command_end() { endword(); allow_command(); delete W; delete globbed; argc = 0 }
@@ -201,31 +229,33 @@ function readonly(s, i, c, c2, sq, dq) {
201
229
  if (c2 ~ /[><&|]/) { i++; if (substr(s, i + 1, 1) == ">") i++ }
202
230
  continue
203
231
  }
204
- if (c ~ /[;|&\n]/) { command_end(); if (redirect) bad = 1; continue }
232
+ if (c == "&" && c2 == "&") { command_end(); if (redirect) bad = 1; i++; continue }
233
+ if (c ~ /[;|&\n]/) { nonconditional_separator = 1; command_end(); if (redirect) bad = 1; continue }
205
234
  if (c ~ /[ \t\r]/) { endword(); continue }
206
235
  word = word c; inword = 1
207
236
  }
208
237
  command_end()
209
- if (sq || dq || redirect) bad = 1
238
+ if (sq || dq || redirect || (conditional_only && nonconditional_separator)) bad = 1
210
239
  return !bad
211
240
  }
212
241
  BEGIN {
213
242
  policy("cat", "nAvetsb", "")
214
243
  policy("head", "", ""); policy("tail", "", "")
215
244
  policy("wc", "lwcm", ""); policy("ls", "laA1hdRtrF", "")
216
- policy("rg", "n", "")
245
+ policy("rg", "nl", "")
217
246
  policy("grep", "nirRlLcvwxFEHhoqs", "")
218
247
  policy("egrep", "nirRlLcvwxFEHhoqs", ""); policy("fgrep", "nirRlLcvwxFEHhoqs", "")
219
248
  policy("echo", "neE", "")
220
249
  policy("printf", "", ""); policy("test", "", ""); policy("[", "", "")
221
250
  policy("true", "", ""); policy("false", "", ""); policy("pwd", "", "")
222
251
  policy("git status", "sb", "--short --porcelain")
223
- policy("git diff", "p", "--stat --numstat --name-only --name-status --cached --staged --check --no-color")
252
+ policy("git diff", "p", "--stat --numstat --name-only --name-status --cached --staged --check --no-color --cc")
224
253
  policy("git log", "p", "--oneline --stat --name-only --no-color --follow")
225
254
  policy("git show", "p", "--stat --name-only --no-color")
226
255
  policy("git add", "Aup", ""); policy("git commit", "aq", "")
227
- policy("git blame", "", ""); policy("git ls-files", "", "")
228
- policy("git rev-parse", "", ""); policy("git check-ignore", "", ""); policy("git grep", "", "")
256
+ policy("git blame", "", ""); policy("git ls-files", "s", "--stage --debug")
257
+ policy("git branch", "", "--show-current")
258
+ policy("git rev-parse", "", ""); policy("git check-ignore", "", ""); policy("git grep", "n", "")
229
259
  for (i = 0; i < 16; i++) HEX[substr("0123456789abcdef", i + 1, 1)] = i
230
260
  ESC["n"] = 10; ESC["r"] = 13; ESC["t"] = 9; ESC["\\"] = 92; ESC["\047"] = 39; ESC["\""] = 34
231
261
  text = ENVIRON["GSW_COMMAND"]
@@ -244,6 +274,8 @@ classifier="$script_directory/cratis-guard-writes.sh"
244
274
  exit 2
245
275
  }
246
276
  classifier_input="$(jq -nc --arg cwd "$cwd" --args '{cwd:$cwd,tool_input:{file_paths:$ARGS.positional}}' -- "${candidates[@]}")" || parser_failed
277
+ # Tool labels and this hook shell do not establish the execution shell options.
278
+ # Keep conservative dotfile intersections for every command, especially mutators.
247
279
  references="$("$BASH" "$classifier" --references <<<"$classifier_input")" || {
248
280
  printf '%s\n' 'BLOCKED by cratis-guard-shell-writes: could not check references (write guard failed).' >&2
249
281
  exit 2
@@ -0,0 +1,50 @@
1
+ ---
2
+ agent: agent
3
+ description: Reverse engineer a running system, its features or its executable (start URL, HAR, OpenAPI document, executable or package) into a reviewed Screenplay model and run it.
4
+ ---
5
+
6
+ # Reverse Engineer a System
7
+
8
+ Run the **cratis-screenplay-reverse-engineering** skill end to end for the input the user gave: a
9
+ start URL, a HAR file, an OpenAPI document, or an executable or package. Source code, if offered,
10
+ is read last. Follow its safety section before touching anything.
11
+
12
+ ## Confirm first
13
+
14
+ - **Permission:** the system is owned by the user or the user may test it, and any executable is
15
+ one the user may analyze. If not, stop. Running an executable also needs a named sandbox.
16
+ - **Discovery questions:** reuse what the user already said. Ask only what is missing, at most
17
+ two, one per turn: the start URL and actor, then any guidance for the walk. Unattended, assume
18
+ read-only, no hosted-model use and no writes, and record the assumptions.
19
+ - **Scope:** the key areas to model, and what is out (for example, contacts, companies and
20
+ the deal pipeline, not invoicing). If none is given, inventory first, propose a scope and ask
21
+ once; default to the smallest coherent core. Only in-scope areas become the model.
22
+ - **Model root and slug:** where an accepted model belongs, and the work area
23
+ `.ai-work/screenplay/<slug>/re/`.
24
+
25
+ ## Chain
26
+
27
+ 1. **Intake and evidence:** inventory the entry points, collect evidence from each source given,
28
+ scrub any HAR or capture before use, and write the evidence file with its unknowns.
29
+ 2. **Synthesis:** build the candidate through the Screenplay MCP propose, read-proposal, apply
30
+ loop, one slice at a time, citing evidence ids.
31
+ 3. **Review loop:** self-check, independent Screenplay Reviewer pass, then show the timeline
32
+ table and a keep / change / remove choice per slice. Re-synthesize only changed slices.
33
+ 4. **Run:** `cratis run <model folder>`; use `cratis render` only when real code is wanted.
34
+ 5. **Fidelity check:** re-walk the observed journeys on the running app and report pass, fail
35
+ or not run per journey.
36
+
37
+ ## Stop at each approval point
38
+
39
+ Stop and say what is needed before: any write to the target, a walk beyond the budget, any
40
+ executable run (naming the executable, sandbox and actions), first use of an external
41
+ reverse-engineering tool, sending captures to a hosted model, accepting (committing) the model,
42
+ and `render --force`. Do not
43
+ proceed on silence.
44
+
45
+ ## Report
46
+
47
+ First line `Outcome:`. Then the evidence counts, slices with decisions, run command and result,
48
+ the fidelity table, open unknowns and what was not verified.
49
+
50
+ The skill carries the detail; do not duplicate it here.
@@ -294,6 +294,7 @@ and one phase skill, then the construct skill needed for syntax.
294
294
  | `cratis-screenplay-scenario-coverage` | Coverage matrix, rejection, denial, lifecycle and external-failure scenarios |
295
295
  | `cratis-screenplay-model-review` | Independent critique, evidence checklist and business-question explanation |
296
296
  | `cratis-screenplay-legacy-extraction` | Evidence-led extraction, expert verification and loss report |
297
+ | `cratis-screenplay-reverse-engineering` | Black-box evidence from a running app, HAR, API description or executable to a reviewed model that runs |
297
298
  | `cratis-screenplay-toolchain` | Compiler and CLI versions, verdict commands, diagnostics and executable subsets |
298
299
  | `cratis-screenplay-render-and-gap-fill` | Admission, publication, target verification and contract-led hand-written delivery |
299
300
  | `cratis-screenplay-delivery-planning` | Slice counts by type, dependency waves, issue tracking and estimates from the team's own history |
@@ -4,10 +4,9 @@ applyTo: "**/*"
4
4
 
5
5
  # Secrets never enter agent transcripts
6
6
 
7
- A transcript is saved, summarized and shared, so a credential that is printed once is leaked.
8
- Every line is tagged **[contract]** (binding) per the Three Levels of Authority in
9
- [`general.md`](./general.md). The `cratis-guard-secrets` hook blocks the commands below
10
- (see [`.cratis/ai/hooks/README.md`](../hooks/README.md)); the rule holds where no hook runs.
7
+ Printed credentials leak into saved transcripts. All lines are **[contract]** (binding;
8
+ see [`general.md`](./general.md)). The [hook](../hooks/README.md) enforces these rules;
9
+ they also hold without it.
11
10
 
12
11
  ## Commands
13
12
 
@@ -20,10 +19,11 @@ Every line is tagged **[contract]** (binding) per the Three Levels of Authority
20
19
  - **[contract] Project the field you need and say which one:** `-o jsonpath='{.spec.containers[*].image}'`,
21
20
  `-o custom-columns=…`, `kubectl get … -o name`, status fields, `kubectl logs`, `docker inspect --format`.
22
21
  Read a `.env.example`, never the `.env`.
23
- - **[contract] The hook reads command text only.** It cannot see a command piped into a shell
24
- (`… | sh`, `bash -c "$(…)"`), a recursive search with no named file (`grep -r PASSWORD .`), or a
25
- value reached through a variable, alias or script. These stay your rule to keep; output redaction
26
- is the only backstop.
22
+ - **[contract] Command-text checks cannot see** shell-piped code (`… | sh`, `bash -c "$(…)"`),
23
+ recursive searches without filenames (`grep -r PASSWORD .`), or paths hidden in variables,
24
+ aliases or scripts. The rules still apply; output redaction is the backstop.
25
+ - **[contract] After a guard block, narrowing to literal non-credential files is supported remediation,
26
+ not a workaround.** Follow `Use instead`; never disguise the same secret read.
27
27
 
28
28
  ## Values
29
29