@cratis/pi 7.44.0 → 7.45.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.
@@ -230,6 +230,8 @@ export default function (pi: ExtensionAPI) {
230
230
  if (!filePath) return;
231
231
  if (!isInstalled(guardWrites)) return; // no guard installed in this repository - nothing to enforce
232
232
  const payload = { cwd: ctx.cwd, tool_input: { file_path: filePath, content, new_string: newString } };
233
+ // The shared script resolves the write target's Git origin and allowDependencyManifestWrites setting;
234
+ // keep manifest defaults and generated/.env protection identical to Claude Code.
233
235
  return runBlockingGuard(guardWrites, "cratis-guard-writes", "write", payload, ctx, "write guards");
234
236
  });
235
237
 
@@ -92,13 +92,43 @@ Rule numbers refer to the numbered list in [`../rules/general.md`](../rules/gene
92
92
 
93
93
  - Editing a file whose header marks it as Cratis-generated output — rule 15 `[contract]`
94
94
  - Writing content that opens with such a header (hand-authoring a "generated" proxy)
95
- - `Directory.Packages.props`, `global.json`, `NuGet.config`, `yarn.lock`, `package-lock.json`,
96
- `pnpm-lock.yaml`, `packages.lock.json` — the Source-of-Truth Discipline rule
95
+ - `Directory.Packages.props`, `global.json`, `NuGet.config` (also `NuGet.Config` and `nuget.config`),
96
+ `yarn.lock`, `package-lock.json`, `pnpm-lock.yaml`, `packages.lock.json` — unless the
97
+ repository's dependency-manifest policy allows them (see below)
97
98
  - `.env`, `.env.*`, `*.env` — secrets
98
99
 
99
100
  The generated-file check is anchored: the marker must be a comment opener at the start of one of
100
101
  the first five lines. A rule file or a document that merely *mentions* the marker is not blocked.
101
102
 
103
+ ### Dependency-manifest writes
104
+
105
+ Manifest writes are allowed **silently by default** when Git's `origin` points to
106
+ `github.com/Cratis/<repo>` over HTTPS or SSH (including `git@github.com:Cratis/<repo>.git`;
107
+ host and owner are case-insensitive). The hook resolves the policy repository from the write
108
+ target, resolving relative paths against the tool's working directory, lexically collapsing
109
+ repeated separators, `.` and `..`, then walking up to the nearest existing directory for new
110
+ files. That directory is resolved physically before Git lookup, so symlinked directories use
111
+ the repository they actually point into. Nested directories and linked worktrees work too.
112
+ A missing or non-Cratis origin keeps the block; targets outside any Git repository are blocked. Installed corpus files and selected profiles do **not** prove organization
113
+ ownership: consumer applications can have exactly the same installation and profiles.
114
+
115
+ Set a repository-owned boolean in `.cratis/ai.json` to override that default in both Claude Code
116
+ and Pi:
117
+
118
+ ```json
119
+ { "allowDependencyManifestWrites": false }
120
+ ```
121
+
122
+ `false` re-enables the manifest block in a Cratis repository; `true` allows manifest writes
123
+ in any repository. Merge this property into the existing configuration. An absent, malformed,
124
+ or non-boolean setting uses the origin-based default. This setting never permits generated
125
+ output or `.env` writes. The protected basename list is unchanged; `package.json` is not
126
+ part of this guard's manifest category.
127
+
128
+ This allowance is not authorization for unrelated upgrades: keep changes task-focused and
129
+ call out version bumps in the PR description. Other repositories retain the rule requiring
130
+ an explicit request; their setting is a mechanical opt-out, not a change to that rule.
131
+
102
132
  **Blocked outright** (`PreToolUse` on `Bash`, exit 2): a `cratis chronicle` command that is not
103
133
  read-only. The **cratis-chronicle-cli-operations** skill makes `--yes` the authorization boundary for
104
134
  a live store and says a request to diagnose does not authorize a mutation; this guard enforces that.
@@ -502,7 +532,7 @@ Each is an explicit, auditable opt-out — none of them is a default.
502
532
 
503
533
  | Variable | Effect |
504
534
  |---|---|
505
- | `CRATIS_HOOKS_ALLOW_PROTECTED_WRITES=1` | allows one protected write; this is the "unless explicitly asked" case for dependency manifests |
535
+ | `CRATIS_HOOKS_ALLOW_PROTECTED_WRITES=1` | bypasses all write protection, including generated files and `.env`, while set in the harness environment; use only for an explicitly requested protected write. Repository-scoped manifest allowance uses `.cratis/ai.json` instead and never bypasses those protections |
506
536
  | `CRATIS_HOOKS_SKIP_SCAN=1` | disables the pattern pass |
507
537
  | `CRATIS_HOOKS_SKIP_GATE=1` | disables the quality gate |
508
538
  | `CRATIS_HOOKS_GATE_DRYRUN=1` | prints which gates would run, and why, then exits 0 |
@@ -5,10 +5,11 @@
5
5
  # 1. Generated files — anything whose header marks it as Cratis-generated output
6
6
  # (.cratis/ai/rules/general.md rule 15 [contract])
7
7
  # 2. Dependency manifests — Directory.Packages.props, global.json, lockfiles, NuGet config
8
+ # (allowed by default for a github.com/Cratis origin)
8
9
  # 3. Environment files — .env and friends (secrets)
9
10
  #
10
- # 2 and 3 come from the Source-of-Truth Discipline rule: "Don't change dependency manifests /
11
- # lockfiles / global.json / NuGet config unless explicitly asked."
11
+ # .cratis/ai.json allowDependencyManifestWrites overrides only the manifest policy:
12
+ # true allows them in any repository; false blocks them even in a Cratis repository.
12
13
  #
13
14
  # Escape hatch for the "unless explicitly asked" case — the user asks, you set it for the call:
14
15
  # CRATIS_HOOKS_ALLOW_PROTECTED_WRITES=1
@@ -33,7 +34,30 @@ file="$(hook_json "$input" '.tool_input.file_path')"
33
34
  [ -n "$file" ] || file="$(hook_json "$input" '.tool_input.notebook_path')"
34
35
  [ -n "$file" ] || exit 0
35
36
 
37
+ # Lexically normalize before any Git lookup or parent walk, including nonexistent segments.
38
+ # Component parsing preserves spaces and glob characters without depending on realpath.
39
+ normalize_target_path() {
40
+ local remaining="$1" normalized="" component
41
+ while [ -n "$remaining" ]; do
42
+ component="${remaining%%/*}"
43
+ if [ "$remaining" = "$component" ]; then
44
+ remaining=""
45
+ else
46
+ remaining="${remaining#*/}"
47
+ fi
48
+ case "$component" in
49
+ "" | .) ;;
50
+ ..) normalized="${normalized%/*}" ;;
51
+ *) normalized="$normalized/$component" ;;
52
+ esac
53
+ done
54
+ printf '%s\n' "${normalized:-/}"
55
+ }
56
+
36
57
  file="$(hook_abspath "$file" "$cwd")"
58
+ file="$(normalize_target_path "$file")"
59
+ # Pi can run the bundled script in a consumer checkout; this root is only for diagnostics.
60
+ root="$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null || printf '%s\n' "$cwd")"
37
61
  rel="$(hook_relpath "$file" "$root")"
38
62
  base="$(basename "$file")"
39
63
 
@@ -66,12 +90,38 @@ if [ -n "$new_content" ] \
66
90
  fi
67
91
 
68
92
  # ── 2. Dependency manifests, lockfiles, SDK and NuGet configuration ───────────
93
+ manifest_writes_allowed() {
94
+ local setting="" origin directory policy_root
95
+ # Authorization belongs to the write target, which may be outside the session's checkout.
96
+ # New files can have nonexistent parents; find their nearest existing directory first.
97
+ directory="$(dirname "$file")"
98
+ while [ ! -d "$directory" ]; do
99
+ [ "$directory" != "/" ] || return 1
100
+ directory="$(dirname "$directory")"
101
+ done
102
+ # Follow existing directory symlinks before asking Git which repository owns the target.
103
+ directory="$(cd -P "$directory" 2>/dev/null && pwd -P)" || return 1
104
+ policy_root="$(git -C "$directory" rev-parse --show-toplevel 2>/dev/null)" || return 1
105
+ if [ -f "$policy_root/.cratis/ai.json" ]; then
106
+ # Only actual booleans override the default; jq's `// empty` would discard false.
107
+ setting="$(jq -r '.allowDependencyManifestWrites | select(type == "boolean") | tostring' "$policy_root/.cratis/ai.json" 2>/dev/null || true)"
108
+ fi
109
+ case "$setting" in
110
+ true) return 0 ;;
111
+ false) return 1 ;;
112
+ esac
113
+ origin="$(git -C "$policy_root" remote get-url origin 2>/dev/null || true)"
114
+ # Anchor host, owner and the single repository segment; never infer ownership from profiles.
115
+ printf '%s\n' "$origin" | LC_ALL=C grep -Eiq '^(https://github\.com/|git@github\.com:|ssh://git@github\.com(:[0-9]+)?/)cratis/[a-z0-9_.-]+/?$'
116
+ }
117
+
69
118
  case "$base" in
70
119
  Directory.Packages.props | global.json | NuGet.config | NuGet.Config | nuget.config \
71
120
  | yarn.lock | package-lock.json | pnpm-lock.yaml | packages.lock.json)
121
+ if manifest_writes_allowed; then exit 0; fi
72
122
  block \
73
123
  "'$base' is a dependency manifest / lockfile / SDK or NuGet configuration file. .cratis/ai/rules/general.md (Source-of-Truth Discipline): don't change these unless explicitly asked." \
74
- "If the user explicitly asked for this change, re-run the tool call with CRATIS_HOOKS_ALLOW_PROTECTED_WRITES=1 exported. Otherwise take the dependency as given and solve the problem in source."
124
+ "To allow dependency updates for this repository, set allowDependencyManifestWrites to true in .cratis/ai.json. If the user explicitly asked for this change, re-run the tool call with CRATIS_HOOKS_ALLOW_PROTECTED_WRITES=1 exported. Otherwise take the dependency as given and solve the problem in source."
75
125
  ;;
76
126
  esac
77
127
 
@@ -165,7 +165,7 @@ A claim is only as good as the signal behind it — a build result, a test run,
165
165
  - **Skills and rules are the authoritative answer.** If not answered there, ask. Don't infer Cratis behavior from package internals.
166
166
  - Only make high-confidence suggestions.
167
167
  - When a user asks how to get help, has a question not answered by the docs, or wants to discuss design, point them to the [Cratis Discord](https://discord.gg/kt4AMpV8WV); direct confirmed bugs to GitHub issues.
168
- - Don't change dependency manifests / lockfiles / `global.json` / NuGet config unless explicitly asked.
168
+ - In Cratis organization repositories (a `github.com/Cratis/<repo>` Git `origin`), update dependency manifests / lockfiles / `global.json` / NuGet config as needed for the task; avoid unrelated version churn and call out version bumps in the PR description. In other repositories, don't change them unless explicitly asked.
169
169
  - When asked to **ship** or **land** changes, use the **ship-changes** prompt (`.cratis/ai/prompts/ship-changes.prompt.md`); invoking it is what authorizes the branch → commits → push → PR → merge → cleanup chain it describes. A request to only commit, only push, or only open a PR authorizes exactly that step, under [Git commits](./git-commits.md) and [Pull requests](./pull-requests.md) — do not route it through ship-changes and do not add the later steps.
170
170
 
171
171
  ## General
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.44.0",
3
+ "version": "7.45.0",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [