@ainova-systems/intelligence 0.11.3 → 0.11.5

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.
@@ -92,8 +92,8 @@ _ver_gt() {
92
92
  IFS=. read -r -a A <<< "$a"
93
93
  IFS=. read -r -a B <<< "$b"
94
94
  for i in 0 1 2; do
95
- ai=$(printf '%s' "${A[$i]:-0}" | tr -cd '0-9'); ai=${ai:-0}
96
- bi=$(printf '%s' "${B[$i]:-0}" | tr -cd '0-9'); bi=${bi:-0}
95
+ ai="${A[$i]:-0}"; ai="${ai//[!0-9]/}"; ai=${ai:-0}
96
+ bi="${B[$i]:-0}"; bi="${bi//[!0-9]/}"; bi=${bi:-0}
97
97
  if [ "$((10#$ai))" -gt "$((10#$bi))" ]; then return 0; fi
98
98
  if [ "$((10#$ai))" -lt "$((10#$bi))" ]; then return 1; fi
99
99
  done
package/engine/sync.sh CHANGED
@@ -86,24 +86,38 @@ echo " Config: $CONFIG_FILE"
86
86
  echo " Root: $REPO_ROOT"
87
87
  echo ""
88
88
 
89
+ # The engine never mutates the manifest, so parse its hot sections exactly
90
+ # once: every later read_yaml_list / target lookup — in this process and in
91
+ # adapter process substitutions — hits the in-memory copy instead of
92
+ # spawning awk.
93
+ load_targets_cache "$CONFIG_FILE"
94
+ for section in rules agents skills ignore submodules; do
95
+ load_yaml_list "$CONFIG_FILE" "$section"
96
+ done
97
+
89
98
  # Lint frontmatter across all source files (rules, agents, skills).
90
99
  # Catches issues like unquoted colons that strict YAML consumers reject.
100
+ LINT_FILES=()
91
101
  for section in rules agents skills; do
102
+ load_yaml_list "$CONFIG_FILE" "$section"
92
103
  while IFS= read -r src; do
93
104
  [ -z "$src" ] && continue
94
- src_dir="$(resolve_source_dir "$REPO_ROOT" "$src")"
105
+ src_dir="$REPO_ROOT/$src"
95
106
  [ -d "$src_dir" ] || continue
96
107
  if [ "$section" = "skills" ]; then
97
108
  while IFS= read -r f; do
98
- [ -n "$f" ] && lint_frontmatter "$f"
109
+ [ -n "$f" ] && LINT_FILES+=("$f")
99
110
  done < <(find "$src_dir" -mindepth 2 -maxdepth 2 -name 'SKILL.md' 2>/dev/null)
100
111
  else
101
112
  for f in "$src_dir"/*.md; do
102
- [ -f "$f" ] && lint_frontmatter "$f"
113
+ [ -f "$f" ] && LINT_FILES+=("$f")
103
114
  done
104
115
  fi
105
- done < <(read_yaml_list "$CONFIG_FILE" "$section")
116
+ done <<< "$IS_YAML_LIST"
106
117
  done
118
+ if [ "${#LINT_FILES[@]}" -gt 0 ]; then
119
+ lint_frontmatter_files "${LINT_FILES[@]}"
120
+ fi
107
121
 
108
122
  # Adapters come from two places, discovered by filename (minus `.sh`,
109
123
  # `_template` excluded):
@@ -149,24 +163,27 @@ done
149
163
  # point of view.
150
164
  SYNC_TX_DIR="$(mktemp -d -t intelligence-sync-XXXXXX)"
151
165
  SYNC_TX_INDEX="$SYNC_TX_DIR/paths.tsv"
152
- SYNC_TX_SEEN="$SYNC_TX_DIR/seen"
153
166
  mkdir -p "$SYNC_TX_DIR/data"
154
167
  : > "$SYNC_TX_INDEX"
155
- : > "$SYNC_TX_SEEN"
156
168
  SYNC_TX_ACTIVE=0
169
+ SYNC_TX_SEEN_LIST=$'\n'
170
+ SYNC_TX_COUNT=0
157
171
 
158
172
  snapshot_sync_path() {
159
173
  local adapter_name="$1" rel="$2" src index present=0
160
- grep -Fqx -- "$rel" "$SYNC_TX_SEEN" && return 0
161
- printf '%s\n' "$rel" >> "$SYNC_TX_SEEN"
174
+ case "$SYNC_TX_SEEN_LIST" in
175
+ *$'\n'"$rel"$'\n'*) return 0 ;;
176
+ esac
177
+ SYNC_TX_SEEN_LIST="$SYNC_TX_SEEN_LIST$rel"$'\n'
162
178
  validate_output_path "$REPO_ROOT" "$CONFIG_FILE" "$adapter_name" "$REPO_ROOT/$rel"
163
- index="$(wc -l < "$SYNC_TX_INDEX" | tr -d ' ')"
179
+ index="$SYNC_TX_COUNT"
164
180
  src="$REPO_ROOT/$rel"
165
181
  if [ -e "$src" ] || [ -L "$src" ]; then
166
182
  cp -a "$src" "$SYNC_TX_DIR/data/$index"
167
183
  present=1
168
184
  fi
169
185
  printf '%s\t%s\t%s\n' "$index" "$rel" "$present" >> "$SYNC_TX_INDEX"
186
+ SYNC_TX_COUNT=$((SYNC_TX_COUNT + 1))
170
187
  }
171
188
 
172
189
  restore_sync_snapshot() {
@@ -204,14 +221,17 @@ while [ "$preflight_idx" -lt "${#ADAPTERS[@]}" ]; do
204
221
  if [ -n "$TARGET_FILTER" ] && [ "$adapter" != "$TARGET_FILTER" ]; then
205
222
  continue
206
223
  fi
207
- [ "$(is_target_enabled "$CONFIG_FILE" "$adapter")" = "1" ] || continue
208
- output="$(get_target_output "$CONFIG_FILE" "$adapter")"
224
+ target_enabled_var "$CONFIG_FILE" "$adapter"
225
+ [ "$IS_TGT_ENABLED" = "1" ] || continue
226
+ target_output_var "$CONFIG_FILE" "$adapter"
227
+ output="$IS_TGT_OUTPUT"
209
228
  [ -n "$output" ] || output=".$adapter"
210
229
  validate_output_path "$REPO_ROOT" "$CONFIG_FILE" "$adapter" "$REPO_ROOT/$output"
211
230
  records="$(adapter_contract_records "$adapter" "$adapter_file" "$output")" || exit 1
212
231
  while IFS=$'\t' read -r kind value; do
213
232
  [ "$kind" = "requires" ] || continue
214
- if [ "$(is_target_enabled "$CONFIG_FILE" "$value")" != "1" ]; then
233
+ target_enabled_var "$CONFIG_FILE" "$value"
234
+ if [ "$IS_TGT_ENABLED" != "1" ]; then
215
235
  echo "ERROR: targets.$adapter requires enabled target '$value'." >&2
216
236
  echo " Enable it first: intelligence adapter enable $value" >&2
217
237
  exit 1
@@ -240,7 +260,8 @@ while [ "$adapter_idx" -lt "$adapter_count" ]; do
240
260
  fi
241
261
 
242
262
  # Check if target is enabled in config
243
- enabled=$(is_target_enabled "$CONFIG_FILE" "$adapter")
263
+ target_enabled_var "$CONFIG_FILE" "$adapter"
264
+ enabled="$IS_TGT_ENABLED"
244
265
  if [ "$enabled" != "1" ]; then
245
266
  if [ -n "$TARGET_FILTER" ]; then
246
267
  echo "ERROR: Adapter '$TARGET_FILTER' is disabled in $CONFIG_FILE." >&2
@@ -251,7 +272,8 @@ while [ "$adapter_idx" -lt "$adapter_count" ]; do
251
272
  fi
252
273
 
253
274
  # Get output directory
254
- output=$(get_target_output "$CONFIG_FILE" "$adapter")
275
+ target_output_var "$CONFIG_FILE" "$adapter"
276
+ output="$IS_TGT_OUTPUT"
255
277
  if [ -z "$output" ]; then
256
278
  output=".$adapter"
257
279
  fi
@@ -289,6 +311,9 @@ trap - EXIT INT TERM
289
311
  # Warn about unsynced directories
290
312
  warn_unsynced "$REPO_ROOT" "$CONFIG_FILE"
291
313
 
314
+ # Report adapter-agnostic source context pressure on every successful sync.
315
+ report_context_source_sizes "$REPO_ROOT" "$CONFIG_FILE"
316
+
292
317
  # Report model overrides that drift from intelligence-sync defaults
293
318
  # (helpful when defaults move forward — e.g., gpt-5.5 -> gpt-5.6).
294
319
  report_model_drift "$CONFIG_FILE"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainova-systems/intelligence",
3
- "version": "0.11.3",
3
+ "version": "0.11.5",
4
4
  "description": "Build, version and distribute AI agent intelligence across your organization — one CLI, versioned Intelligence Packages, and a sync engine for Claude Code, Cursor, Copilot, Codex, Pi and OpenCode.",
5
5
  "bin": {
6
6
  "intelligence": "bin/intelligence.js"
@@ -8,6 +8,7 @@ skills:
8
8
  - intelligence-add-agent
9
9
  - intelligence-add-skill
10
10
  - intelligence-extract-skill
11
+ - intelligence-compact-context
11
12
  - intelligence-review-skills
12
13
  - intelligence-learn-from-repository
13
14
  - intelligence-learn-from-context
@@ -45,6 +46,7 @@ The per-artifact checks are procedure, so they live in the meta-skills rather th
45
46
  |---|---|
46
47
  | `intelligence-add-rule` / `intelligence-add-agent` / `intelligence-add-skill` | author one artifact |
47
48
  | `intelligence-extract-skill` | turn an observed workflow into a skill |
49
+ | `intelligence-compact-context` | reduce context without changing behavior or teaching terse output |
48
50
  | `intelligence-review-skills` | audit the layer for duplication, drift, size, hardcoded paths |
49
51
  | `intelligence-learn-from-repository` | recover and complete first-time repository onboarding |
50
52
  | `intelligence-learn-from-context` | fold one later session lesson into an established layer |
@@ -131,18 +131,26 @@ Use the engine library instead of copying parsers or file-handling logic.
131
131
  |---|---|
132
132
  | `resolve_source_dir(repo_root, source)` | Resolve a manifest source to its local directory. |
133
133
  | `read_yaml_list(config, section)` | Stream entries from `sources.<section>`. |
134
+ | `load_yaml_list(config, section)` | Same list into `IS_YAML_LIST`, cached — no subprocess on repeat reads. |
134
135
  | `get_frontmatter_value(key, file)` | Read a scalar from the first frontmatter block. |
136
+ | `frontmatter_index(keys, file...)` | Read several frontmatter scalars for many files in one pass (`\x1f`-separated rows; special key `paths#` counts `paths:` lines). |
135
137
  | `has_frontmatter(file)` / `has_paths(file)` | Inspect source shape. |
136
138
  | `strip_frontmatter(file)` | Emit the body without its first frontmatter block. |
137
139
  | `get_model(config, tool, tier)` | Resolve a `heavy`, `standard` or `light` model, including manifest overrides. |
138
140
  | `get_model_default(tool, tier)` | Read the built-in model default. |
141
+ | `load_model_tiers(config, tool)` / `resolve_model_var(tier)` | Resolve the three standard tiers once, then map per file without subprocesses. |
139
142
  | `copy_skill_bundle(src, dest)` | Copy `SKILL.md` and all resources safely, normalize Markdown and quote free-text frontmatter. |
143
+ | `copy_skill_bundle_dirs(dest_root, src...)` | Batch form: copy every skill directory into `dest_root/<name>` with one copy and one finalize pass. |
140
144
  | `sync_open_skill_dirs(root, config, dest)` | Own and populate a shared Agent Skills directory such as `.agents/skills/`. |
141
145
  | `finalize_output_file(file)` | Expand layout tokens and normalize line endings; required for every emitted text file. |
146
+ | `finalize_output_files(file...)` / `finalize_copy_files(dest, src...)` | Batch forms: finalize in place, or copy-and-finalize into a directory, in one process. |
147
+ | `emit_wrapped_bodies(spec)` | Emit many header + source-body + tail outputs in one process (see `engine/lib/common.sh` for the spec format). |
142
148
  | `get_target_field(config, target, field)` | Read another field from the target configuration. |
143
149
  | `repo_rel_link(root, path)` | Produce a stable repo-relative link for a committed output. |
144
150
 
145
- `lint_frontmatter` is run across all inputs by the engine before adapters execute. It warns about common YAML hazards; adapters should not duplicate that pass.
151
+ `lint_frontmatter` is run across all inputs by the engine before adapters execute (batched as `lint_frontmatter_files`). It warns about common YAML hazards; adapters should not duplicate that pass.
152
+
153
+ Prefer the batched forms inside per-file loops: a process spawn costs tens of milliseconds on Git Bash for Windows, so one-awk-per-file adapters turn large projects into minutes of process creation. The built-in adapters are the reference for the pattern.
146
154
 
147
155
  ## Rules, skills and agents
148
156
 
@@ -164,6 +172,10 @@ Intelligence routes always-on rules once through `AGENTS.md` for tools that cons
164
172
 
165
173
  If a new adapter relies on `AGENTS.md` for always-on rules, its target must require `agents`. Add that invariant to `engine/sync.sh` when contributing the adapter upstream.
166
174
 
175
+ Every successful sync prints an adapter-agnostic `CONTEXT:` summary with source byte totals and file counts. It separates always-on rules from custom context (scoped rules, agent prompts and skill entry points), then reports a numeric `agents-md` byte count and `generated`, `not-generated`, or `disabled` status; supporting skill assets are excluded until explicitly read. Adapter-specific hard limits and suppression controls stay inside the adapter that owns them.
176
+
177
+ The Codex adapter checks its `project_doc_max_bytes` default (32 KiB). When generated `AGENTS.md` exceeds it, sync prints the byte count and a sufficient Codex setting. The warning says "may truncate" because a developer can already have a larger override. `targets.codex.warn_project_doc_limit` accepts `true` or omission for the default threshold, a positive byte count to match another effective limit, or `false` to disable the Intelligence warning. Both inline and block target forms work, and the field does not change Codex configuration. The warning remains visible in `sync --compact`.
178
+
167
179
  ### Skills
168
180
 
169
181
  Skills follow the [Agent Skills standard](https://agentskills.io). Copy each skill directory as a complete bundle—not only `SKILL.md`—because its body may reference `references/`, `scripts/` or `assets/` beside it.
@@ -385,7 +385,7 @@ The permanent applied-schema key is the top-level scalar `schema_version` in `in
385
385
  The public lifecycle is deliberately compact:
386
386
 
387
387
  - `intelligence init [--preview|--apply]` is universal: it creates a new setup, aligns an existing Intelligence project, or plans/applies conversion of an eligible legacy Intelligence Sync project.
388
- - `intelligence sync [adapter] [--compact]` first aligns an existing Intelligence project with the installed CLI, restores a missing store strictly from `intelligence.lock`, then renders. Compact mode shows only final status on success and all diagnostics on failure. In CI it refuses an alignment that would change tracked files and points to a local `intelligence init --apply` plus review/commit.
388
+ - `intelligence sync [adapter] [--compact]` first aligns an existing Intelligence project with the installed CLI, restores a missing store strictly from `intelligence.lock`, then renders. Compact mode shows context sizes, actionable warnings and final status on success, and all diagnostics on failure. In CI it refuses an alignment that would change tracked files and points to a local `intelligence init --apply` plus review/commit.
389
389
  - `intelligence update [@scope/name] [--preview|--apply]` is the only update surface. It prints the CLI/project/package plan; default mode prompts, `--preview` never writes, and `--apply` does not prompt. It never moves `ref:` pins.
390
390
  - `intelligence package add|remove|list|search` owns package inventory.
391
391
  - `intelligence adapter list|create|enable|disable|remove` owns adapter inventory and target state.
@@ -60,7 +60,7 @@ The mistakes that actually happen, in order of frequency:
60
60
 
61
61
  ### Invariants
62
62
 
63
- - **Never state behaviour of a tool or engine you have not verified in its documentation or source.** This invariant exists because the claim *"Claude Code does not auto-load `.claude/rules/`"* was once written into this layer as fact. It is false — rules without `paths:` load at launch, path-scoped ones activate on matching files, and custom subagents inherit both (Claude Code docs: *Memory → Organize rules with `.claude/rules/`*, and *Subagents → What loads at startup*). An unverified claim about tooling is worse than a gap: nothing in the repository contradicts it, so it silently reshapes every decision downstream.
63
+ - **Never state behaviour of a tool or engine you have not verified in its documentation or source.** An unverified claim about tooling is worse than a gap: nothing in the repository contradicts it, so it silently reshapes every decision downstream. Verified means a page you can cite - for how rules load, the Claude Code docs *Memory → Organize rules with `.claude/rules/`* and *Subagents → What loads at startup*.
64
64
  - **Never write a current defect into a rule as if it were the design.** Known breakage belongs in one place that says so. Every other rule describes the project *as it is meant to work* — a workaround documented as procedure becomes permanent.
65
65
  - **Never link from one always-on rule to another.** Always-on rules are inlined verbatim into `AGENTS.md`, and the path-scoped channels carry only scoped rules, so a relative link is dead in at least one output. Name the rule instead; it loads on its own.
66
66
 
@@ -0,0 +1,118 @@
1
+ ---
2
+ name: intelligence-compact-context
3
+ description: "Reduce rules, agents, and skills without changing behavior or teaching terse output"
4
+ argument-hint: "[target: rules|agents|skills|all]"
5
+ agent: intelligence-architect
6
+ ---
7
+
8
+ # Compact intelligence context
9
+
10
+ Reduce persistent and on-demand prompt cost by changing structure before wording.
11
+ The result must preserve the layer's behavioral contract and ordinary, complete
12
+ language; a smaller file is not a success if agents become terse, vague, or less
13
+ reliable.
14
+
15
+ ## Analyze
16
+
17
+ 1. Resolve `<manifest>`, `<content-dir>`, and `<module>`. Enumerate the source
18
+ directories declared under `sources.rules`, `sources.agents`, and
19
+ `sources.skills`; skip installed package sources and generated adapter output.
20
+
21
+ 2. Read `<module>/references/conventions.md`, the `intelligence-authoring` rule,
22
+ and [references/principles.md](references/principles.md). The reference
23
+ explains which forms of indirection save context and which merely move text.
24
+
25
+ 3. Run `<sync-cmd> --compact` and save the `CONTEXT:` line as the baseline,
26
+ including its rendered `agents-md` byte count. Record individual source-file
27
+ byte and line counts for the requested target.
28
+
29
+ 4. Invoke `intelligence-review-skills` for the same target. Reuse its findings
30
+ for duplication, misplaced content, scope, stale artifacts, pressure markers,
31
+ history narrative, and description budget; do not reproduce its audit.
32
+
33
+ 5. Build a semantic ledger before drafting edits. For every candidate passage,
34
+ record:
35
+
36
+ - the behavior, constraint, procedure, or expertise it carries;
37
+ - its one authoritative owner;
38
+ - when it must load;
39
+ - the reason or example needed to apply it correctly;
40
+ - the repository evidence or external documentation that supports it.
41
+
42
+ Two passages are duplicates only when those meanings match. Similar wording
43
+ with different scope, priority, or failure behavior is not duplication.
44
+
45
+ ## Draft the compaction
46
+
47
+ 6. Apply structural reductions in this order:
48
+
49
+ 1. Replace an instruction with a deterministic gate or command when the
50
+ repository already enforces it.
51
+ 2. Delete generic knowledge and facts the agent can read directly from the
52
+ repository, unless a non-obvious interpretation is the instruction.
53
+ 3. Keep one owner for duplicated guidance and remove the copies. A skill may
54
+ invoke another skill by name; an agent may list a skill; neither restates
55
+ the called artifact.
56
+ 4. Add `paths:` to rules that matter only in part of the repository.
57
+ 5. Move multi-step procedures from rules or agents into skills, and move
58
+ reusable constraints or expertise to the artifact type that owns them.
59
+ 6. Move optional skill detail into skill-local `references/` and state the
60
+ exact condition that requires each file. Do not use an always-loaded
61
+ import or an unconditional read step and call that compaction.
62
+ 7. Tighten prose only after the preceding reductions are exhausted.
63
+
64
+ 7. Preserve language quality while tightening prose:
65
+
66
+ - Use complete grammatical sentences and ordinary project vocabulary.
67
+ - Preserve the reason when it guides judgment, and keep one minimal example
68
+ when the rule would otherwise be ambiguous.
69
+ - Preserve triggers, boundaries, ordering, failure behavior, verification,
70
+ and output contracts exactly.
71
+ - Shorten descriptions by retaining the unique trigger that distinguishes a
72
+ sibling; never reduce them to vague labels.
73
+ - Do not add instructions telling agents to be terse, abbreviated, clipped,
74
+ or concise unless that response style is an explicit product requirement.
75
+ - Do not turn prose into fragments, dense acronyms, slash-separated phrases,
76
+ or unexplained labels. Compression targets redundancy, not grammar.
77
+
78
+ 8. Treat references according to load behavior:
79
+
80
+ - A conditional skill reference saves startup context.
81
+ - An always-loaded import improves organization but does not save context.
82
+ - A plain link is navigation, not guaranteed instruction loading; never hide
83
+ a critical constraint behind one.
84
+ - An always-on rule that is too large normally needs deletion, scoping, a
85
+ gate, or conversion of its procedure into a skill—not a reference index.
86
+
87
+ ## Approval and apply
88
+
89
+ 9. Present a proposal grouped as `DELETE`, `MERGE`, `SCOPE`, `MOVE`,
90
+ `REFERENCE`, or `REWRITE`. For each item show the owner, semantic contract,
91
+ estimated bytes saved, and any behavior that could change. Ask for approval
92
+ before changing meaning, ownership, scope, or load timing.
93
+
94
+ 10. Apply only accepted items to project-owned sources. Preserve unapproved
95
+ passages byte-for-byte and never edit generated output or installed package
96
+ sources locally.
97
+
98
+ ## Verify
99
+
100
+ 11. Compare the semantic ledger with the diff. Every original behavior must be
101
+ present once in its authoritative owner, deliberately removed with approval,
102
+ or enforced by the named deterministic mechanism. Check that no move created
103
+ a dead link, unconditional reference load, conflicting instruction, or
104
+ broader scope.
105
+
106
+ 12. Run `<sync-cmd> --compact`, require `IS_STATUS=ok`, then run
107
+ `intelligence status --check`. Compare the new `CONTEXT:` line and per-file
108
+ counts with the baseline.
109
+
110
+ 13. Exercise three representative prompts when the environment supports agent
111
+ evaluation: one direct case governed by a compacted instruction, one adjacent
112
+ judgment case that needs its reason, and one ordinary explanation that would
113
+ reveal clipped language. If behavioral evaluation is unavailable, report
114
+ that explicitly; a smaller byte count proves size reduction, not quality.
115
+
116
+ 14. Report bytes and percentage saved for always-on and custom context, the
117
+ before-and-after `agents-md` size, the artifacts changed, the semantic
118
+ checks performed, and any remaining item that needs an owner decision.
@@ -0,0 +1,58 @@
1
+ # Context compaction principles
2
+
3
+ Use these principles to decide what to remove, relocate, or keep. They summarize
4
+ current primary guidance; they do not replace repository evidence or an
5
+ artifact's semantic ledger.
6
+
7
+ ## What consistently improves instruction context
8
+
9
+ - Keep persistent instructions specific, focused, and grounded in behavior the
10
+ agent would otherwise miss. Current vendor guidance consistently recommends
11
+ removing unclear or conflicting instructions because they reduce adherence.
12
+ - Scope narrow guidance so it loads only for matching work. Anthropic, GitHub,
13
+ and Cursor all recommend path-specific rules instead of making framework or
14
+ component guidance repository-wide.
15
+ - Prefer one authoritative statement. Duplicate instructions spend context;
16
+ slightly different copies can also become a conflict whose winner is
17
+ unpredictable.
18
+ - Keep what is non-obvious: project conventions, pitfalls, rationale, failure
19
+ behavior, and evidence-backed exceptions. Remove generic tutorials and facts
20
+ the agent can obtain directly from code or configuration.
21
+ - Use progressive disclosure for skills. Keep the executable core in
22
+ `SKILL.md`; move optional detail to a nearby reference and name the exact
23
+ condition under which the agent reads it.
24
+ - Test changes on representative work. Instruction quality is behavioral, so a
25
+ byte reduction alone cannot prove that meaning or adherence survived.
26
+
27
+ ## References are not automatically compression
28
+
29
+ Indirection saves context only when the target is not loaded until it is needed.
30
+ Anthropic explicitly notes that `@path` imports still enter startup context. A
31
+ plain Markdown link has the opposite risk: some tools will not load it at all.
32
+
33
+ Use a reference when all three conditions hold:
34
+
35
+ 1. the parent artifact remains actionable without the detail;
36
+ 2. the parent gives a precise condition for reading the reference; and
37
+ 3. every adapter that needs the detail copies or can resolve the reference.
38
+
39
+ This works naturally for skill-local `references/`. It is usually the wrong fix
40
+ for an always-on rule: scope the rule, convert its procedure to a skill, enforce
41
+ it mechanically, or delete redundant material instead.
42
+
43
+ ## Preserve natural language
44
+
45
+ Compaction changes the information architecture, not the desired voice of the
46
+ agent. Keep complete sentences, clear headings, reasons that support judgment,
47
+ and one concrete example where it prevents ambiguity. Do not achieve a smaller
48
+ file by instructing the agent to answer tersely or by rewriting the source into
49
+ telegraphic fragments. Persistent instructions shape behavior as well as task
50
+ decisions, so clipped source language is a quality risk rather than a valid
51
+ optimization.
52
+
53
+ ## Primary sources
54
+
55
+ - [Claude Code memory documentation](https://code.claude.com/docs/en/memory) — specific instructions, path scoping, conflict removal, and why imports do not reduce startup context.
56
+ - [Agent Skills best practices](https://agentskills.io/skill-creation/best-practices) — omit generic knowledge, keep coherent units, and use conditional progressive disclosure.
57
+ - [GitHub Copilot custom-instruction guidance](https://docs.github.com/en/copilot/tutorials/customize-code-review) — short, focused instructions, path-specific files, concrete examples, and iteration.
58
+ - [Cursor rules documentation](https://docs.cursor.com/context/rules) — focused, actionable, scoped rules and composable rule files.
@@ -19,23 +19,26 @@ The name uses "skills" as shorthand for all AI artifacts (rules, agents, and ski
19
19
 
20
20
  3. **Skip installed package sources.** Sources under `<module>/` (`<module>/rules`, `<module>/agents`, `<module>/skills/intelligence-*`) are package-owned and restored by CLI lifecycle operations, so a local "fix" is not durable. Never propose a project-local edit to them. If one is wrong, make an upstream proposal instead.
21
21
 
22
- 4. **Never read or edit generated output** (`.claude/`, `.cursor/`, `.github/`, `.codex/`, `.agents/`, `.pi/`, `.opencode/`, `AGENTS.md`). Sync owns those entirely; the finding always belongs to the source.
22
+ 4. **Never read or edit generated output** (`.claude/`, `.cursor/`, `.github/`, `.codex/`, `.agents/`, `.pi/`, `.opencode/`, `AGENTS.md`). Sync owns those entirely; the finding always belongs to the source. Reading its byte count from sync's `CONTEXT:` summary or a byte-count command is the metadata-only exception—do not open the output to audit its prose.
23
23
 
24
24
  ## Steps
25
25
 
26
26
  5. **Pull git history** (when available) for each artifact — last edit, edit count, first-add date. A stale candidate has no recent edits *and* nothing cross-referencing it.
27
27
 
28
- 6. **Run the detection checks.** Judgement decides; the checks only make a finding evidence rather than an impression.
28
+ 6. **Run the detection checks.** Resolve the shared agents target output from `<manifest>` and measure only its byte count; use the `agents-md` value when a fresh `CONTEXT:` summary is already available. Apply the shared instruction budget below, but do not run sync during this read-only audit. Judgement decides; the checks only make a finding evidence rather than an impression.
29
29
 
30
30
  | Check | What it is | Proposed action |
31
31
  |---|---|---|
32
32
  | **Duplicate content** | Two artifacts cover overlapping scope, or their descriptions share trigger phrases | `MERGE` — present both, propose one |
33
33
  | **Misplaced content** | A checklist or procedure in an agent body; a convention in an agent; a workflow in a rule; expertise in a skill (the *Pick the right artifact* table in `intelligence-authoring`) | `MOVE` — a move, not a rewrite: both files change together |
34
34
  | **Over the cap** | `SKILL.md` over 1000 lines, rule over 500, agent over 200 | `SPLIT` — two artifacts, or move detail into `references/<topic>.md` |
35
+ | **Shared instruction budget** | The measured shared agents output, or `agents-md` in sync's `CONTEXT:` summary, is over 32 KiB (32,768 bytes) | `COMPACT` — this is Intelligence's recommended maximum, not an adapter rejection threshold; use `intelligence-compact-context` to reduce the owning sources without teaching terse output |
35
36
  | **Rule links to a rule** | A markdown link from one rule to another (`R1`) | `UNLINK` — name the rule instead: always-on rules are inlined into `AGENTS.md` and the scoped channels carry only scoped rules, so the link is dead in at least one output |
36
37
  | **Machine facts in a rule** | OS, shell, editor or a local absolute path (`R2`) | `MOVE` — these belong in a personal, gitignored `CLAUDE.md`; a rule is committed and read by everyone, including whoever is on another platform |
37
38
  | **Literal path or command in a skill** | A path *outside the skill's own folder* baked into a procedure (`R3`) | `PARAMETERIZE` — a skill is *executed*, so a literal path breaks the moment the layout moves; resolve it from a rule or from `<manifest>`. **Exempt:** the skill's own bundle (`references/`, `scripts/`, `assets/` — content is co-located with its skill by default); rules and agents (describing the repository is their job); an example inside an output-format block; the resolution step itself |
38
39
  | **Skill with no verification** | Nothing at the end proves the procedure worked (`R4`) | `FLAG` — a procedure that proves nothing is a note, or just the work: give it a verification, or delete it |
40
+ | **Pressure marker** | A heading or section named CRITICAL / MANDATORY / HARD RULE / READ FIRST, or a density of `MUST` / `NEVER` / `ALWAYS` with no reason beside it (`R5`) | `REWRITE` - plain heading, one reason per constraint; when several instructions are each marked critical the marker stops carrying information, so keep emphasis for the one instruction demonstrably under-weighted without it |
41
+ | **History narrative** | A PR number, incident id, commit SHA, date or "this session" inside a rule body (`R6`) | `REWRITE` - keep the causal sentence, drop the archaeology; a rule's authority is the behaviour it prescribes, and git history keeps the date |
39
42
  | **Reserved prefix** | A project artifact named `intelligence-*` | `RENAME` — the prefix belongs to the sync package and collides in generated output |
40
43
  | **Naming** | A skill that is not `<domain>-<verb>-<noun>`, or a domain invented rather than reused | `RENAME` — or introduce the new domain deliberately |
41
44
  | **Stale** | No edits in 6+ months and nothing cross-references it | `ARCHIVE` — move to `<content-dir>/_archive/` |
@@ -50,6 +53,9 @@ The name uses "skills" as shorthand for all AI artifacts (rules, agents, and ski
50
53
  Detection commands, portable on purpose — no `\b` and no `-P`, so the same command works in Git Bash on Windows, on macOS (BSD grep) and on Linux. Run each over the source directories resolved in step 2, never over generated output:
51
54
 
52
55
  ```sh
56
+ # Shared instruction budget — resolve this output path from <manifest>
57
+ wc -c "<agents-output>"
58
+
53
59
  # R1 — a markdown link from one rule to another
54
60
  grep -rnE '\]\([^)]*\.md\)' <rule-dirs>
55
61
 
@@ -62,9 +68,17 @@ The name uses "skills" as shorthand for all AI artifacts (rules, agents, and ski
62
68
 
63
69
  # R4 — skills whose body never mentions verifying anything (-L lists files with NO match)
64
70
  grep -riLE --include=SKILL.md 'verif|expect|assert|check|test|IS_STATUS' <skill-dirs>
71
+
72
+ # R5 - pressure markers: a heading or label named for urgency, then absolute-language density per file
73
+ grep -rnE '^#+ .*(CRITICAL|MANDATORY|HARD RULE|READ FIRST)|\((CRITICAL|MANDATORY|HARD RULE)\)' <rule-dirs> <agent-dirs> <skill-dirs>
74
+ grep -rcE '(MUST|NEVER|ALWAYS)' <rule-dirs> <agent-dirs> <skill-dirs> | grep -vE ':0$'
75
+
76
+ # R6 - history narrative in a rule body: PR numbers, incident ids, dates, "this session", commit SHAs
77
+ grep -rniE -e '(#|PR )[0-9]{3,}' -e '[0-9]{4}-[0-9]{2}-[0-9]{2}' -e 'this session|origin session' \
78
+ -e '`[0-9a-f]{7,40}`' <rule-dirs>
65
79
  ```
66
80
 
67
- `R4` is a coarse net, not a verdict: a skill that merely *mentions* a verification command anywhere passes it. Read the final step of every skill regardless — the question is whether something at the end **proves the work landed**, not whether the word appears.
81
+ `R4` is a coarse net, not a verdict: a skill that merely *mentions* a verification command anywhere passes it. Read the final step of every skill regardless — the question is whether something at the end **proves the work landed**, not whether the word appears. So are `R5` and `R6`: a `NEVER` that carries its reason and a date inside a frontmatter template are both legitimate hits, and the row's action applies only where the marker or the id is doing no work.
68
82
 
69
83
  7. **Ask subtraction first.** Before proposing any `SPLIT`, `REWRITE` or `PATCH`, ask whether the artifact should exist at all, whether two should become one, and whether the rule could be replaced by a gate the model cannot skip. A deletion is a better outcome than a tidy-up, and the punch-list should say so when it is true.
70
84
 
@@ -84,3 +98,4 @@ The user accepts items individually; bulk-accept for low-impact tweaks is fine.
84
98
 
85
99
  - `intelligence-learn-from-context` — single-session lesson capture; this skill delegates accepted edits to its Phase B
86
100
  - `intelligence-extract-skill` — when the audit surfaces a workflow that should become a skill
101
+ - `intelligence-compact-context` — approval-gated structural compaction when the shared instruction budget or source size needs reduction