@cratis/pi 7.165.2 → 7.165.4

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.
@@ -231,12 +231,7 @@ export const Projects = () => {
231
231
 
232
232
  ## Browser verification (optional)
233
233
 
234
- If the workspace has `workbench.browser.enableChatTools` enabled, use the agentic browser tools to verify the UI after implementation:
235
- 1. Open the app page in the integrated browser.
236
- 2. Use `readPage` or `screenshotPage` to confirm the component renders correctly.
237
- 3. Use `clickElement` or `typeInPage` to test interactive elements.
238
-
239
- This closes the development loop — build, render, verify — without leaving the editor.
234
+ Browser tools are a capability, not authority, and only the `browser-operator` agent receives them (`browser.md`). Do not drive a browser yourself, even when the workspace enables editor browser tools. To verify the UI after implementation, hand `browser-operator` the URL, the scope, the permit and the artifact directory, and use its evidence record. Production stays read-only and sign-in stops for a human. If no `browser-operator` is available, report the UI as unverified rather than using browser tools directly.
240
235
 
241
236
  ---
242
237
 
@@ -112,8 +112,11 @@ capacity numbers into workflows or guidance.
112
112
 
113
113
  ## Automation that writes back
114
114
 
115
- - A bot that pushes to a branch must **retry with `git pull --rebase`** — the branch
116
- moves while the job runs, and a plain push loses the whole run to a non-fast-forward.
115
+ - A bot that pushes to a branch must **retry by merging** — the branch moves while the
116
+ job runs, and a plain push loses the whole run to a non-fast-forward. Fetch, merge the
117
+ remote branch into the bot's commit (`git pull --no-rebase`), and push again. Never
118
+ rebase, amend, reset or force-push: `git-commits` forbids rewriting history, with no
119
+ automation exception.
117
120
  - A bot's pre-push verification build must match the strictest configuration any CI in
118
121
  the organization applies to the same commit (build `Release` when consumers enforce
119
122
  analyzers there). Do not add `[skip ci]` to bot commits as a load optimization: the
@@ -11,9 +11,10 @@ Cratis organization. It does not apply to applications built on Cratis.
11
11
 
12
12
  When a repository is created in the Cratis organization, prepare one transient,
13
13
  no-effect Strategy intake proposal. Do not create, comment on, assign, mention,
14
- link, or otherwise mutate a GitHub issue unless a current repository profile and
15
- the exact operation are separately accepted. Tool access and a request to create
16
- the repository do not supply that issue-effect authority.
14
+ link, or otherwise mutate a GitHub issue unless the user directly names that
15
+ issue operation or an accepted policy scopes it. Do not require another profile
16
+ or confirmation once either is present. Tool access and a request to create the
17
+ repository do not supply that issue-effect authority.
17
18
 
18
19
  The proposal should include only the bounded facts needed for Strategy triage:
19
20
 
@@ -12,7 +12,7 @@ authored a file or preserve a chain of evidence about how it arrived.
12
12
 
13
13
  - Run the narrowest relevant build, type check, lint, and specifications while iterating; explain when a wider gate is required before completion or push/PR.
14
14
  - Run one phase per command with its real exit status. Budget targeted checks around 120 seconds and build/test phases around 300 seconds; explain any longer budget first, and obtain explicit approval before a phase exceeds 600 seconds. Stop on a failure; do not blindly retry or repeat passing tests on unchanged inputs without a flaky-test hypothesis or required matrix.
15
- - CI is not a feedback loop: run every gate locally before pushing. On a shared machine cap parallelism, one heavy phase at once (`cratis-engineering-ci-gates`).
15
+ - CI is not a feedback loop: run the Tier 1 gate locally before pushing, and run integration (Tier 2) locally when the repository's policy requires it. Integration may wait for CI only when the repository allows it, CI demonstrably runs that coverage and it passes before merge; say it was deferred to CI, never call it a local pass. If integration is required but has neither local proof nor enforced CI coverage, treat it as unverified and stop. A stricter repository policy, such as local-only integration, wins. On a shared machine cap parallelism, one heavy phase at once (`cratis-engineering-ci-gates`).
16
16
  - Separate status/fetch from builds, Debug from Release, each test project, and frontend lint/compile/test/build. Do not combine these into an opaque command with a large outer timeout. Expose progress and cancellation; report the precise failed or timed-out phase and do not continue dependent phases after failure.
17
17
  - Never use `build/test | grep | sort/head/tail` as gate evidence. Capture the producer's exit status before summarising output; `pipefail` alone is insufficient with early-closing consumers such as `head`. Printed zero-error counts are not proof of success. Preserve needed full diagnostics in task-scoped `.ai-work/` logs rather than hiding them in `/tmp`.
18
18
  - Fast feedback is a product requirement: a spec takes milliseconds, the suite seconds; specs share setup and run in parallel; analyzers must not halt builds. CI builds the spec path without analyzers and enforces them, warnings as errors, in a parallel required job; the pre-push gate runs them. A slowdown is a defect.
@@ -226,12 +226,7 @@ export const Projects = () => {
226
226
 
227
227
  ## Browser verification (optional)
228
228
 
229
- If the workspace has `workbench.browser.enableChatTools` enabled, use the agentic browser tools to verify the UI after implementation:
230
- 1. Open the app page in the integrated browser.
231
- 2. Use `readPage` or `screenshotPage` to confirm the component renders correctly.
232
- 3. Use `clickElement` or `typeInPage` to test interactive elements.
233
-
234
- This closes the development loop — build, render, verify — without leaving the editor.
229
+ Browser tools are a capability, not authority, and only the `browser-operator` agent receives them (`browser.md`). Do not drive a browser yourself, even when the workspace enables editor browser tools. To verify the UI after implementation, hand `browser-operator` the URL, the scope, the permit and the artifact directory, and use its evidence record. Production stays read-only and sign-in stops for a human. If no `browser-operator` is available, report the UI as unverified rather than using browser tools directly.
235
230
 
236
231
  ---
237
232
 
@@ -8,6 +8,7 @@ import { corpusRoot } from './corpusRoot.ts';
8
8
  import { frontmatter } from './frontmatter.ts';
9
9
  import { globToRegExp, universalGlobs } from './globs.ts';
10
10
  import type { ManagedRule } from './ManagedRule.ts';
11
+ import { selectedProfileIds } from './skillSelection.ts';
11
12
 
12
13
  function rulesRoot(cwd: string): string {
13
14
  const managedRoot = join(cwd, '.cratis', 'ai', 'rules');
@@ -25,7 +26,7 @@ function configuration(cwd: string): AiConfiguration | undefined {
25
26
  }
26
27
 
27
28
  /**
28
- * A profile-specific rule is kept only when the repository selects that profile. Repositories without
29
+ * A profile-specific rule is kept when the repository selects or composes that profile. Repositories without
29
30
  * a `.cratis/ai.json` keep every rule, matching the `@cratis/pi` package.
30
31
  */
31
32
  function matchesProfile(rule: ManagedRule, selected: AiConfiguration | undefined): boolean {
@@ -37,6 +38,23 @@ function matchesProfile(rule: ManagedRule, selected: AiConfiguration | undefined
37
38
  return true;
38
39
  }
39
40
 
41
+ interface ScopeKind {
42
+ named: (scope: string, name: string) => boolean;
43
+ satisfied: (selected: AiConfiguration) => boolean;
44
+ }
45
+
46
+ const hasLanguage = (language: string) => (selected: AiConfiguration) => (selected.languages ?? []).includes(language);
47
+
48
+ const scopeKinds: ScopeKind[] = [
49
+ { named: scope => scope.includes('.cs'), satisfied: hasLanguage('csharp') },
50
+ { named: (scope, name) => scope.includes('.ts') || name === 'rtk.md' || name.endsWith('/rtk.md'), satisfied: hasLanguage('typescript') },
51
+ { named: scope => scope.includes('.go') || scope.includes('go.mod') || scope.includes('go.sum'), satisfied: hasLanguage('go') },
52
+ { named: scope => scope.includes('.kt'), satisfied: hasLanguage('kotlin') },
53
+ { named: scope => scope.includes('.java'), satisfied: hasLanguage('java') },
54
+ { named: scope => scope.includes('.ex'), satisfied: hasLanguage('elixir') },
55
+ { named: scope => scope.includes('md'), satisfied: selected => (selected.profiles ?? []).includes('cratis/documentation') },
56
+ ];
57
+
40
58
  /**
41
59
  * The packaged `@cratis/pi` corpus holds every rule, so the languages and documentation a repository selected
42
60
  * decide which apply: a rule scoped to `.cs` files needs `csharp`, to `.ts` files needs `typescript`, and to
@@ -46,23 +64,10 @@ function matchesSelection(name: string, applyTo: string[], selected: AiConfigura
46
64
  const languages = selected?.languages ?? [];
47
65
  if (!selected || languages.length === 0) return true;
48
66
  const scope = applyTo.join(',');
49
- const needsCSharp = scope.includes('.cs');
50
- const needsTypeScript = scope.includes('.ts') || name === 'rtk.md' || name.endsWith('/rtk.md');
51
- const needsGo = scope.includes('.go') || scope.includes('go.mod') || scope.includes('go.sum');
52
- const needsKotlin = scope.includes('.kt');
53
- const needsJava = scope.includes('.java');
54
- const needsElixir = scope.includes('.ex');
55
- const needsDocumentation = scope.includes('md');
56
67
  // A scope that also names model files (`.play`) is not tied to one language, so it is always kept.
57
68
  if (scope.includes('.play')) return true;
58
- if (!needsCSharp && !needsTypeScript && !needsGo && !needsKotlin && !needsJava && !needsElixir && !needsDocumentation) return true;
59
- return (needsCSharp && languages.includes('csharp')) ||
60
- (needsTypeScript && languages.includes('typescript')) ||
61
- (needsGo && languages.includes('go')) ||
62
- (needsKotlin && languages.includes('kotlin')) ||
63
- (needsJava && languages.includes('java')) ||
64
- (needsElixir && languages.includes('elixir')) ||
65
- (needsDocumentation && (selected.profiles ?? []).includes('cratis/documentation'));
69
+ const named = scopeKinds.filter(kind => kind.named(scope, name));
70
+ return named.length === 0 || named.some(kind => kind.satisfied(selected));
66
71
  }
67
72
 
68
73
  /**
@@ -72,7 +77,8 @@ function matchesSelection(name: string, applyTo: string[], selected: AiConfigura
72
77
  */
73
78
  export function managedRules(cwd: string): ManagedRule[] {
74
79
  const root = rulesRoot(cwd);
75
- const selected = configuration(cwd);
80
+ const configured = configuration(cwd);
81
+ const selected = configured ? { ...configured, profiles: [...selectedProfileIds(configured)] } : undefined;
76
82
  const resolved = existsSync(join(cwd, '.cratis', 'ai', 'rules'));
77
83
  return readdirSync(root, { recursive: true, encoding: 'utf8' })
78
84
  .filter((entry): entry is string => entry.endsWith('.md'))
@@ -27,10 +27,36 @@ function catalog(): Profile[] | undefined {
27
27
  }
28
28
 
29
29
  function supportsLanguage(profile: Profile, languages: Set<string>): boolean {
30
- if (!profile.languages?.length) return true;
30
+ if (!languages.size || !profile.languages?.length) return true;
31
31
  return profile.languages.some(language => language === 'language-agnostic' || languages.has(language));
32
32
  }
33
33
 
34
+ function profileForId(profiles: Profile[], selection: { id: string; allowUnknown: boolean }): Profile {
35
+ const profile = profiles.find(candidate => candidate.id === selection.id);
36
+ if (profile) return profile;
37
+ if (!selection.allowUnknown) throw new Error(`Unknown Cratis AI profile '${selection.id}'.`);
38
+ return { id: selection.id };
39
+ }
40
+
41
+ function resolveProfiles(configuration: AiConfiguration, profiles: Profile[], allowUnknown: boolean): Set<string> {
42
+ const languages = new Set(configuration.languages ?? []);
43
+ const selected = new Set<string>();
44
+ const select = (id: string, explicitSelection: boolean): void => {
45
+ const profile = profileForId(profiles, { id, allowUnknown });
46
+ if (!explicitSelection && !supportsLanguage(profile, languages)) return;
47
+ if (selected.has(id)) return;
48
+ selected.add(id);
49
+ profile.composes?.forEach(child => select(child, false));
50
+ };
51
+ configuration.profiles?.forEach(profile => select(profile, true));
52
+ return selected;
53
+ }
54
+
55
+ /** Effective rule profiles, retaining explicit custom profile IDs when they are not in the catalog. */
56
+ export function selectedProfileIds(configuration: AiConfiguration): Set<string> {
57
+ return resolveProfiles(configuration, catalog() ?? [], true);
58
+ }
59
+
34
60
  /**
35
61
  * The skills the packaged `@cratis/pi` makes available for a repository, resolved from `.cratis/ai.json` and the
36
62
  * profile catalog exactly as `selectedSkillPaths` in `@cratis/pi` does (a repository without `ai.json` gets every
@@ -49,17 +75,7 @@ export function selectedSkillNames(cwd: string): string[] | undefined {
49
75
  return [...new Set(profiles.flatMap(profile => profile.availableTargets ?? []))].sort();
50
76
  }
51
77
  const configuration = JSON.parse(readFileSync(configurationPath, 'utf8')) as AiConfiguration;
52
- const languages = new Set(configuration.languages ?? []);
53
- const selected = new Set<string>();
54
- const select = (id: string, explicitSelection: boolean): void => {
55
- const profile = profiles.find(candidate => candidate.id === id);
56
- if (!profile) throw new Error(`Unknown Cratis AI profile '${id}'.`);
57
- if (!explicitSelection && !supportsLanguage(profile, languages)) return;
58
- if (selected.has(id)) return;
59
- selected.add(id);
60
- profile.composes?.forEach(child => select(child, false));
61
- };
62
- configuration.profiles?.forEach(profile => select(profile, true));
78
+ const selected = resolveProfiles(configuration, profiles, false);
63
79
  return [...new Set(profiles.filter(profile => selected.has(profile.id)).flatMap(profile => profile.availableTargets ?? []))].sort();
64
80
  } catch {
65
81
  return undefined;
@@ -111,8 +111,11 @@ capacity numbers into workflows or guidance.
111
111
 
112
112
  ## Automation that writes back
113
113
 
114
- - A bot that pushes to a branch must **retry with `git pull --rebase`** — the branch
115
- moves while the job runs, and a plain push loses the whole run to a non-fast-forward.
114
+ - A bot that pushes to a branch must **retry by merging** — the branch moves while the
115
+ job runs, and a plain push loses the whole run to a non-fast-forward. Fetch, merge the
116
+ remote branch into the bot's commit (`git pull --no-rebase`), and push again. Never
117
+ rebase, amend, reset or force-push: `git-commits` forbids rewriting history, with no
118
+ automation exception.
116
119
  - A bot's pre-push verification build must match the strictest configuration any CI in
117
120
  the organization applies to the same commit (build `Release` when consumers enforce
118
121
  analyzers there). Do not add `[skip ci]` to bot commits as a load optimization: the
@@ -10,9 +10,10 @@ Cratis organization. It does not apply to applications built on Cratis.
10
10
 
11
11
  When a repository is created in the Cratis organization, prepare one transient,
12
12
  no-effect Strategy intake proposal. Do not create, comment on, assign, mention,
13
- link, or otherwise mutate a GitHub issue unless a current repository profile and
14
- the exact operation are separately accepted. Tool access and a request to create
15
- the repository do not supply that issue-effect authority.
13
+ link, or otherwise mutate a GitHub issue unless the user directly names that
14
+ issue operation or an accepted policy scopes it. Do not require another profile
15
+ or confirmation once either is present. Tool access and a request to create the
16
+ repository do not supply that issue-effect authority.
16
17
 
17
18
  The proposal should include only the bounded facts needed for Strategy triage:
18
19
 
@@ -11,7 +11,7 @@ authored a file or preserve a chain of evidence about how it arrived.
11
11
 
12
12
  - Run the narrowest relevant build, type check, lint, and specifications while iterating; explain when a wider gate is required before completion or push/PR.
13
13
  - Run one phase per command with its real exit status. Budget targeted checks around 120 seconds and build/test phases around 300 seconds; explain any longer budget first, and obtain explicit approval before a phase exceeds 600 seconds. Stop on a failure; do not blindly retry or repeat passing tests on unchanged inputs without a flaky-test hypothesis or required matrix.
14
- - CI is not a feedback loop: run every gate locally before pushing. On a shared machine cap parallelism, one heavy phase at once (`cratis-engineering-ci-gates`).
14
+ - CI is not a feedback loop: run the Tier 1 gate locally before pushing, and run integration (Tier 2) locally when the repository's policy requires it. Integration may wait for CI only when the repository allows it, CI demonstrably runs that coverage and it passes before merge; say it was deferred to CI, never call it a local pass. If integration is required but has neither local proof nor enforced CI coverage, treat it as unverified and stop. A stricter repository policy, such as local-only integration, wins. On a shared machine cap parallelism, one heavy phase at once (`cratis-engineering-ci-gates`).
15
15
  - Separate status/fetch from builds, Debug from Release, each test project, and frontend lint/compile/test/build. Do not combine these into an opaque command with a large outer timeout. Expose progress and cancellation; report the precise failed or timed-out phase and do not continue dependent phases after failure.
16
16
  - Never use `build/test | grep | sort/head/tail` as gate evidence. Capture the producer's exit status before summarising output; `pipefail` alone is insufficient with early-closing consumers such as `head`. Printed zero-error counts are not proof of success. Preserve needed full diagnostics in task-scoped `.ai-work/` logs rather than hiding them in `/tmp`.
17
17
  - Fast feedback is a product requirement: a spec takes milliseconds, the suite seconds; specs share setup and run in parallel; analyzers must not halt builds. CI builds the spec path without analyzers and enforces them, warnings as errors, in a parallel required job; the pre-push gate runs them. A slowdown is a defect.
@@ -97,12 +97,18 @@ into an approval ceremony merely because this skill is available.
97
97
  text in place — that text is what people relied on. Correct a typo or add
98
98
  context under a dated banner that says what changed and why. Change the
99
99
  *choice* only with a new record.
100
- 11. **Point both ways and sweep the citations.** The new record names the one it
101
- replaces in `supersedes`; the replaced record's `status` becomes
102
- `superseded` and it gains a `superseded-by` pointer forward, with its
103
- original text preserved. Then find every work item, pull request body, and
104
- commit trailer citing the old id and point it at the new one. A reader
105
- arriving at either record must be able to reach the other.
100
+ 11. **Point both ways; cite the new record only on new work.** The new record
101
+ names the one it replaces in `supersedes`; the replaced record's `status`
102
+ becomes `superseded` and it gains a `superseded-by` pointer forward, with
103
+ its original text preserved. Keep committed trailers and existing issue and
104
+ pull request text as written: they record which decision governed that work,
105
+ and updating a committed trailer means rewriting history, which
106
+ `git-commits` forbids. Cite the new id on new commits and new work. For
107
+ open work, add a forward link only where the user or an applicable policy
108
+ authorizes that issue or pull request effect; authority to write a record does
109
+ not cover it, and never rewrite another author's text. A reader arriving at
110
+ either record must be able to reach the other and tell which one governed the
111
+ original implementation.
106
112
 
107
113
  Read [record-format.md](references/record-format.md) when authoring or updating a record or regenerating its index; it defines the exact front-matter fields, closed value sets, and index shape.
108
114
 
@@ -39,8 +39,8 @@ Two engines:
39
39
 
40
40
  | Engine | Selected by | Behaviour |
41
41
  | --- | --- | --- |
42
- | EventModel (legacy; the image's default) | nothing | Commands evaluate their modeled `produces` mappings, append the facts to Chronicle and echo the payload. **Only part of modeled validation is enforced, and no authorization.** See [What the EventModel engine enforces](#what-the-eventmodel-engine-enforces). It registers Chronicle projections. Named event sources, streams and routes are refused with `STAGE-ESM-030` (`/stage/status` reports `state: "unsupported"` and `/api/**` answers 501), so a routed model does not run here |
43
- | Semantic (`cratis run`'s default) | `Stage__Runtime__Engine=semantic` | Evaluates validation, requirements, authorization, conditional production and constraints before accepting a command; appends one batch; denied is HTTP 403, validation or constraint failure HTTP 400, an unsupported command HTTP 501. `GET /stage/semantic/admission` lists what is admitted. Executes routes and event-triggered reactions (including `where`, `runs as`, `from`, productions, invocations and cascades), settling them with the initiating command in one batch. Refuses a model it cannot execute (`state: "unsupported"`, `/api/**` returns 501). Read models are in-process, not Chronicle projections in the Workbench; the history is unbounded, so use it for short sessions |
42
+ | EventModel (legacy; explicit only) | `--engine eventmodel` on `cratis run`, or `Stage__Runtime__Engine=eventmodel` | Commands evaluate their modeled `produces` mappings, append the facts to Chronicle and echo the payload. **Only part of modeled validation is enforced, and no authorization.** See [What the EventModel engine enforces](#what-the-eventmodel-engine-enforces). It registers Chronicle projections. Named event sources, streams and routes are refused with `STAGE-ESM-030` (`/stage/status` reports `state: "unsupported"` and `/api/**` answers 501), so a routed model does not run here |
43
+ | Semantic (the default of `cratis run` and of Stage) | nothing, `--engine semantic`, or `Stage__Runtime__Engine=semantic` | Evaluates validation, requirements, authorization, conditional production and constraints before accepting a command; appends one batch; denied is HTTP 403, validation or constraint failure HTTP 400, an unsupported command HTTP 501. `GET /stage/semantic/admission` lists what is admitted. Executes routes and event-triggered reactions (including `where`, `runs as`, `from`, productions, invocations and cascades), settling them with the initiating command in one batch. Refuses a model it cannot execute (`state: "unsupported"`, `/api/**` returns 501). Read models are in-process, not Chronicle projections in the Workbench; the history is unbounded, so use it for short sessions |
44
44
 
45
45
  Do not read an answering sandbox as evidence of correct authorization. Callers are
46
46
  built from unsigned `x-ms-client-principal` headers that anyone who can reach the host can
@@ -114,7 +114,7 @@ evidence about the rest.
114
114
  ## Protected command reads
115
115
 
116
116
  Requires Stage 4.129.0 for semantic Host and specification-executor protected reads;
117
- older engines refuse them with `STAGE-ESM-044`. The default EventModel Host and
117
+ older engines refuse them with `STAGE-ESM-044`. The EventModel Host and
118
118
  structural runner still refuse the preamble with `STAGE-ESM-044`; the structural
119
119
  runner exits `1` without a report. The Cratis renderer renders protected reads only from Stage 4.138.0 and refuses unpreservable shapes with `-044`:
120
120
  executing a model here does not make it renderable.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.165.2",
3
+ "version": "7.165.4",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [
package/src/index.ts CHANGED
@@ -34,17 +34,23 @@ function allSkillPaths(): string[] {
34
34
  }
35
35
 
36
36
  function supportsLanguage(profile: Profile, languages: Set<string>): boolean {
37
- if (!profile.languages?.length) return true;
37
+ if (!languages.size || !profile.languages?.length) return true;
38
38
  return profile.languages.some(language => language === 'language-agnostic' || languages.has(language));
39
39
  }
40
40
 
41
+ function profileForId(selection: { id: string; allowUnknown: boolean }): Profile {
42
+ const profile = profiles.find(candidate => candidate.id === selection.id);
43
+ if (profile) return profile;
44
+ if (!selection.allowUnknown) throw new Error(`Unknown Cratis AI profile '${selection.id}'.`);
45
+ return { id: selection.id };
46
+ }
47
+
41
48
  /** The ids of the configured profiles and, transitively, the composed profiles that support the configured languages. */
42
- function selectedProfileIds(configuration: AiConfiguration): Set<string> {
49
+ function selectedProfileIds(configuration: AiConfiguration, allowUnknown = false): Set<string> {
43
50
  const languages = new Set(configuration.languages ?? []);
44
51
  const selected = new Set<string>();
45
52
  const select = (id: string, explicitSelection: boolean): void => {
46
- const profile = profiles.find(candidate => candidate.id === id);
47
- if (!profile) throw new Error(`Unknown Cratis AI profile '${id}'.`);
53
+ const profile = profileForId({ id, allowUnknown });
48
54
  if (!explicitSelection && !supportsLanguage(profile, languages)) return;
49
55
  if (selected.has(id)) return;
50
56
  selected.add(id);
@@ -101,13 +107,13 @@ const scopeKinds: ScopeKind[] = [
101
107
  { named: applyTo => applyTo.includes('md'), satisfied: configuration => (configuration.profiles ?? []).includes('cratis/documentation') },
102
108
  ];
103
109
 
104
- function ruleMatchesConfiguration(path: string, content: string, configuration: AiConfiguration): boolean {
105
- if (!profileMatchesSelection(frontmatterValue(content, 'profile'), configuration.profiles ?? [])) return false;
110
+ function ruleMatchesConfiguration(rule: { path: string; content: string }, configuration: AiConfiguration): boolean {
111
+ if (!profileMatchesSelection(frontmatterValue(rule.content, 'profile'), configuration.profiles ?? [])) return false;
106
112
  if ((configuration.languages ?? []).length === 0) return true;
107
- const applyTo = frontmatterValue(content, 'applyTo') ?? '';
113
+ const applyTo = frontmatterValue(rule.content, 'applyTo') ?? '';
108
114
  // A scope that also names model files (`.play`) is not tied to one language, so it is always kept.
109
115
  if (applyTo.includes('.play')) return true;
110
- const named = scopeKinds.filter(kind => kind.named(applyTo, path));
116
+ const named = scopeKinds.filter(kind => kind.named(applyTo, rule.path));
111
117
  return named.length === 0 || named.some(kind => kind.satisfied(configuration));
112
118
  }
113
119
 
@@ -127,11 +133,12 @@ function rules(cwd: string): string {
127
133
  const configuration = existsSync(configurationPath)
128
134
  ? JSON.parse(readFileSync(configurationPath, 'utf8')) as AiConfiguration
129
135
  : undefined;
136
+ const effective = configuration ? { ...configuration, profiles: [...selectedProfileIds(configuration, true)] } : undefined;
130
137
  return readdirSync(root, { recursive: true, encoding: 'utf8' })
131
138
  .filter((entry): entry is string => entry.endsWith('.md'))
132
139
  .sort()
133
140
  .map(entry => ({ path: join(root, entry), content: readFileSync(join(root, entry), 'utf8') }))
134
- .filter(rule => !configuration || ruleMatchesConfiguration(rule.path, rule.content, configuration))
141
+ .filter(rule => !effective || ruleMatchesConfiguration(rule, effective))
135
142
  .filter(rule => isUniversalRule(rule.content))
136
143
  .map(rule => rule.content)
137
144
  .join('\n\n');