@ainova-systems/intelligence 0.11.0-rc.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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +46 -0
  3. package/bin/intelligence.js +59 -0
  4. package/cli/commands/add.sh +133 -0
  5. package/cli/commands/doctor.sh +100 -0
  6. package/cli/commands/init.sh +96 -0
  7. package/cli/commands/install.sh +84 -0
  8. package/cli/commands/list.sh +28 -0
  9. package/cli/commands/migrate.sh +251 -0
  10. package/cli/commands/registry.sh +51 -0
  11. package/cli/commands/remove.sh +39 -0
  12. package/cli/commands/status.sh +34 -0
  13. package/cli/commands/sync.sh +22 -0
  14. package/cli/commands/update.sh +59 -0
  15. package/cli/commands/upgrade.sh +27 -0
  16. package/cli/intelligence +71 -0
  17. package/cli/lib/cli-common.sh +149 -0
  18. package/cli/lib/lockfile.sh +97 -0
  19. package/cli/lib/manifest.sh +211 -0
  20. package/cli/lib/registry.sh +141 -0
  21. package/cli/lib/semver.sh +127 -0
  22. package/engine/INIT.md +498 -0
  23. package/engine/agents/intelligence-architect.md +53 -0
  24. package/engine/agents/intelligence-operator.md +49 -0
  25. package/engine/docs/ADAPTERS.md +212 -0
  26. package/engine/docs/CLI.md +91 -0
  27. package/engine/docs/CONVENTIONS.md +440 -0
  28. package/engine/rules/intelligence-authoring.md +114 -0
  29. package/engine/scripts/VERSION +1 -0
  30. package/engine/scripts/adapters/_template.sh +86 -0
  31. package/engine/scripts/adapters/agents.sh +299 -0
  32. package/engine/scripts/adapters/claude.sh +136 -0
  33. package/engine/scripts/adapters/codex.sh +118 -0
  34. package/engine/scripts/adapters/copilot.sh +193 -0
  35. package/engine/scripts/adapters/cursor.sh +146 -0
  36. package/engine/scripts/adapters/opencode.sh +200 -0
  37. package/engine/scripts/adapters/pi.sh +256 -0
  38. package/engine/scripts/lib/common.sh +1602 -0
  39. package/engine/scripts/lib/layout.sh +51 -0
  40. package/engine/scripts/lib/migrations.sh +708 -0
  41. package/engine/scripts/sync.sh +311 -0
  42. package/engine/scripts/update.sh +237 -0
  43. package/engine/skills/intelligence-add-agent/SKILL.md +62 -0
  44. package/engine/skills/intelligence-add-rule/SKILL.md +54 -0
  45. package/engine/skills/intelligence-add-skill/SKILL.md +53 -0
  46. package/engine/skills/intelligence-extract-skill/SKILL.md +47 -0
  47. package/engine/skills/intelligence-install-adapter/SKILL.md +31 -0
  48. package/engine/skills/intelligence-learn-from-context/SKILL.md +69 -0
  49. package/engine/skills/intelligence-review-skills/SKILL.md +86 -0
  50. package/engine/skills/intelligence-sync/SKILL.md +18 -0
  51. package/engine/skills/intelligence-uninstall-adapter/SKILL.md +42 -0
  52. package/engine/skills/intelligence-update/SKILL.md +159 -0
  53. package/package.json +39 -0
  54. package/registry/index.yaml +15 -0
@@ -0,0 +1,127 @@
1
+ #!/bin/bash
2
+ # Semver over git tags — the whole version story of Intelligence Packages.
3
+ #
4
+ # Ranges match STABLE x.y.z versions only (an optional leading `v` is
5
+ # stripped); prerelease/build-suffixed tags are ignored, matching the
6
+ # engine's own digits-only comparator (`_ver_gt`) and BSD sort's lack of
7
+ # `sort -V`. A branch or SHA pin is expressed with `ref:` instead of a range.
8
+
9
+ # semver_cmp <a> <b> — prints -1 / 0 / 1.
10
+ semver_cmp() {
11
+ awk -v a="${1#v}" -v b="${2#v}" '
12
+ BEGIN {
13
+ na = split(a, A, "."); nb = split(b, B, ".")
14
+ for (i = 1; i <= 3; i++) {
15
+ x = (i <= na) ? A[i] + 0 : 0
16
+ y = (i <= nb) ? B[i] + 0 : 0
17
+ if (x < y) { print -1; exit }
18
+ if (x > y) { print 1; exit }
19
+ }
20
+ print 0
21
+ }'
22
+ }
23
+
24
+ # semver_is_stable <version> — 0 iff `[v]x.y.z` with nothing else.
25
+ semver_is_stable() {
26
+ case "${1#v}" in
27
+ *[!0-9.]*) return 1 ;;
28
+ esac
29
+ awk -v v="${1#v}" 'BEGIN { exit (split(v, P, ".") == 3 && P[1] != "" && P[2] != "" && P[3] != "") ? 0 : 1 }'
30
+ }
31
+
32
+ # semver_match <version> <range> — 0 iff the stable version satisfies the range.
33
+ # Ranges: `*`/`latest` (any), exact `1.2.3`, `^1.2.3` (npm caret, incl. the
34
+ # 0.x rules), `~1.2.3` (same minor).
35
+ semver_match() {
36
+ local v="${1#v}" range="$2"
37
+ semver_is_stable "$v" || return 1
38
+ case "$range" in
39
+ ""|"*"|latest) return 0 ;;
40
+ esac
41
+ local op="" base="$range"
42
+ case "$range" in
43
+ "^"*) op="^"; base="${range#^}" ;;
44
+ "~"*) op="~"; base="${range#~}" ;;
45
+ esac
46
+ base="${base#v}"
47
+ semver_is_stable "$base" || return 1
48
+ awk -v v="$v" -v base="$base" -v op="$op" '
49
+ BEGIN {
50
+ split(v, V, "."); split(base, B, ".")
51
+ for (i = 1; i <= 3; i++) { V[i] += 0; B[i] += 0 }
52
+ # below the base -> never a match
53
+ for (i = 1; i <= 3; i++) {
54
+ if (V[i] < B[i]) exit 1
55
+ if (V[i] > B[i]) break
56
+ }
57
+ if (op == "") {
58
+ exit (V[1] == B[1] && V[2] == B[2] && V[3] == B[3]) ? 0 : 1
59
+ }
60
+ if (op == "~") {
61
+ exit (V[1] == B[1] && V[2] == B[2]) ? 0 : 1
62
+ }
63
+ # caret: everything up to the next left-most non-zero digit bump
64
+ if (B[1] != 0) exit (V[1] == B[1]) ? 0 : 1
65
+ if (B[2] != 0) exit (V[1] == 0 && V[2] == B[2]) ? 0 : 1
66
+ exit (V[1] == 0 && V[2] == 0 && V[3] == B[3]) ? 0 : 1
67
+ }'
68
+ }
69
+
70
+ # list_remote_versions <git-url> — stable versions from remote tags, one per
71
+ # line, `v` stripped, unsorted, deduplicated. Peeled refs (`^{}`) collapse
72
+ # onto their tag.
73
+ list_remote_versions() {
74
+ local url="$1"
75
+ GIT_TERMINAL_PROMPT=0 git ls-remote --tags "$url" 2>/dev/null \
76
+ | awk '{
77
+ sub(/\r$/, "")
78
+ ref = $2
79
+ sub(/\^\{\}$/, "", ref)
80
+ n = split(ref, P, "/")
81
+ t = P[n]
82
+ sub(/^v/, "", t)
83
+ if (t ~ /^[0-9]+\.[0-9]+\.[0-9]+$/ && !(t in seen)) { seen[t] = 1; print t }
84
+ }'
85
+ }
86
+
87
+ # remote_tag_for_version <git-url> <version> — the actual tag name (with or
88
+ # without `v`) a stable version came from, and its commit sha:
89
+ # prints "<tag> <sha>". Peeled sha (the commit a tag object points at) wins.
90
+ remote_tag_for_version() {
91
+ local url="$1" ver="${2#v}"
92
+ GIT_TERMINAL_PROMPT=0 git ls-remote --tags "$url" 2>/dev/null \
93
+ | awk -v want="$ver" '
94
+ {
95
+ sub(/\r$/, "")
96
+ ref = $2; peeled = 0
97
+ if (sub(/\^\{\}$/, "", ref)) peeled = 1
98
+ n = split(ref, P, "/")
99
+ tag = P[n]
100
+ t = tag
101
+ sub(/^v/, "", t)
102
+ if (t != want) next
103
+ if (peeled) { psha[tag] = $1 } else { sha[tag] = $1; order[++cnt] = tag }
104
+ }
105
+ END {
106
+ for (i = 1; i <= cnt; i++) {
107
+ tag = order[i]
108
+ s = (tag in psha) ? psha[tag] : sha[tag]
109
+ print tag " " s
110
+ exit
111
+ }
112
+ }'
113
+ }
114
+
115
+ # semver_pick_highest <range> — reads versions on stdin, prints the highest
116
+ # one matching the range (empty output when nothing matches).
117
+ semver_pick_highest() {
118
+ local range="$1" best="" v
119
+ while IFS= read -r v; do
120
+ [ -n "$v" ] || continue
121
+ semver_match "$v" "$range" || continue
122
+ if [ -z "$best" ] || [ "$(semver_cmp "$v" "$best")" = "1" ]; then
123
+ best="$v"
124
+ fi
125
+ done
126
+ printf '%s' "$best"
127
+ }
package/engine/INIT.md ADDED
@@ -0,0 +1,498 @@
1
+ # intelligence-sync: Initialize Your Project
2
+
3
+ The sync engine is already installed in this directory's `scripts/` subfolder. Your job: analyze this codebase, ask the user targeted questions, and generate the project-specific configuration and content.
4
+
5
+ **Execute phases sequentially. Do not skip or combine phases. Each phase has a gate — wait for it before proceeding.**
6
+
7
+ ## Bootstrap: install the engine if it isn't here yet
8
+
9
+ You can reach this file two ways:
10
+
11
+ - **Already vendored in the project** (`intelligence/sync/INIT.md`) — the engine is installed. Skip straight to *Phase 0* below.
12
+ - **Fetched remotely** (a raw GitHub URL) — the engine is **not** installed yet. Install it first, then continue:
13
+
14
+ 1. Check whether `intelligence/sync/scripts/sync.sh` exists at the project root. If it does, the engine is already installed — skip the rest of this section.
15
+ 2. If it does not, clone upstream into a temp directory and copy the `intelligence/` folder into the project root (never clone into the project tree itself). Adapt the temp path to the platform:
16
+
17
+ ```bash
18
+ tmp="$(mktemp -d)"
19
+ git clone --depth=1 https://github.com/ainova-systems/intelligence-sync.git "$tmp"
20
+ cp -r "$tmp/intelligence" ./intelligence
21
+ rm -rf "$tmp"
22
+ ```
23
+
24
+ If the project already has an umbrella folder holding a `config.yaml` under a different name (see *Phase 0*), copy the `sync/` module into that existing folder instead of creating a second `intelligence/`.
25
+ 3. From here on, work against the freshly copied, version-matched `intelligence/sync/INIT.md` and the rest of this document — that copy is authoritative.
26
+
27
+ ## Phase 0: detect the source folder name
28
+
29
+ This document is read by an AI agent and contains many literal references to `intelligence/` (lowercase). The folder you are reading from may have been **renamed** by the user (e.g. `Intelligence/`, `prompts/`, a project codename). Before doing anything else:
30
+
31
+ 1. Identify the directory that contains this `INIT.md` and a `scripts/sync.sh` file. Call its basename `<intel>`.
32
+ 2. Throughout the rest of this document, every reference to `intelligence/` means `<intel>/` — substitute it consistently in every path you write (`config.yaml` `sources:`, `targets.agents.header` Markdown links, generated content, skill instructions).
33
+ 3. Do NOT create a second folder named `intelligence/` if `<intel>` is already different. The sync engine is folder-name-agnostic — `bash <intel>/sync/scripts/sync.sh` works regardless of casing or naming.
34
+
35
+ If the user has not renamed it, `<intel>` is `intelligence` and the literal text below applies as-is.
36
+
37
+ ## What You Will Generate
38
+
39
+ 1. `intelligence/config.yaml` -- sync configuration
40
+ 2. `intelligence/rules/` -- coding standards and conventions
41
+ 3. `intelligence/agents/` -- specialized AI personas
42
+ 4. `intelligence/skills/` -- reusable command sequences
43
+ 5. `AGENTS.md` -- project documentation for LLMs (committed)
44
+ 6. `CLAUDE.md` -- local user preferences (gitignored, if Claude enabled)
45
+ 7. `.gitignore` updates
46
+
47
+ ## Pre-check
48
+
49
+ Before starting, verify:
50
+
51
+ 1. `intelligence/sync/scripts/sync.sh` exists
52
+ 2. `intelligence/sync/scripts/lib/common.sh` exists
53
+ 3. `intelligence/sync/scripts/adapters/claude.sh` exists
54
+ 4. Check initialization state:
55
+ - **Already initialized** = `intelligence/config.yaml` exists AND `intelligence/rules/` contains at least one `.md` file
56
+ - **Partially initialized** = either exists but not both
57
+ - **Fresh** = neither exists
58
+
59
+ If files from steps 1-3 are missing, the engine isn't installed yet — go back to **Bootstrap** above and install it (clone upstream, copy `intelligence/` in), then re-run this Pre-check. Do not proceed to Phase 1 until they exist.
60
+
61
+ ### Already initialized → offer sync-only path
62
+
63
+ If the project is **already initialized** (config + rules present), do NOT run the full bootstrap. Instead:
64
+
65
+ 1. Check if local IDE output is missing or stale: for each enabled target in `config.yaml`, see whether the output path exists (e.g., `.claude/`, `.cursor/`, `AGENTS.md`). If any are missing, this is a new clone / new team member.
66
+ 2. Tell the user: "This project is already initialized. I can just run `bash intelligence/sync/scripts/sync.sh` to generate your local IDE files from `intelligence/`."
67
+ 3. Offer two options:
68
+ - **Sync** — run `intelligence/sync/scripts/sync.sh` and exit (do not touch rules/agents/skills/config)
69
+ - **Re-initialize** — wipe existing rules/agents/skills and regenerate (destructive; only if the user explicitly wants a fresh bootstrap)
70
+ 4. Default to sync. Only proceed to Phase 1 if the user explicitly chooses re-initialize.
71
+
72
+ ---
73
+
74
+ ## Phase 1: Discovery
75
+
76
+ Explore the codebase to detect:
77
+
78
+ **Language & Framework** (check for these markers):
79
+
80
+ | Marker files | Stack |
81
+ |---|---|
82
+ | `.sln`, `.csproj`, `global.json` | .NET / C# |
83
+ | `package.json` | Node.js -- inspect `dependencies` for framework: |
84
+ | -- `react`, `react-dom` | React |
85
+ | -- `next` | Next.js |
86
+ | -- `@angular/core` | Angular |
87
+ | -- `vue` | Vue |
88
+ | -- `svelte` | Svelte / SvelteKit |
89
+ | -- `nuxt` | Nuxt |
90
+ | -- `express`, `fastify`, `nestjs`, `hono` | Node.js backend |
91
+ | -- `electron` | Electron desktop app |
92
+ | -- `react-native`, `expo` | React Native mobile |
93
+ | `go.mod` | Go |
94
+ | `requirements.txt`, `pyproject.toml`, `setup.py`, `Pipfile` | Python |
95
+ | -- `django` in deps | Django |
96
+ | -- `fastapi` in deps | FastAPI |
97
+ | -- `flask` in deps | Flask |
98
+ | `pom.xml` | Java (Maven) |
99
+ | `build.gradle`, `build.gradle.kts` | Java/Kotlin (Gradle) |
100
+ | `Cargo.toml` | Rust |
101
+ | `composer.json` | PHP |
102
+ | -- `laravel/framework` in deps | Laravel |
103
+ | `Gemfile` | Ruby |
104
+ | -- `rails` in deps | Ruby on Rails |
105
+ | `mix.exs` | Elixir / Phoenix |
106
+ | `pubspec.yaml` | Dart / Flutter |
107
+ | `Package.swift` | Swift |
108
+ | `*.xcodeproj`, `*.xcworkspace` | iOS / macOS (Xcode) |
109
+ | `CMakeLists.txt`, `Makefile` (with `.c`/`.cpp`) | C / C++ |
110
+ | `terraform/`, `*.tf` | Terraform (IaC) |
111
+ | `pulumi/`, `Pulumi.yaml` | Pulumi (IaC) |
112
+ | `helm/`, `Chart.yaml` | Helm charts |
113
+ | `docker-compose.yml`, `compose.yaml` | Docker Compose |
114
+ | `serverless.yml` | Serverless Framework |
115
+ | `deno.json`, `deno.jsonc` | Deno |
116
+ | `bun.lockb`, `bunfig.toml` | Bun |
117
+
118
+ **Project Components** -- identify what this project actually is:
119
+
120
+ Scan the directory tree and determine which components exist. A project may have one or several:
121
+ - Backend API, frontend app, BFF layer
122
+ - Infrastructure / deployment configs
123
+ - Shared libraries, CLI tools, workers
124
+ - Mobile app, documentation site
125
+ - Git submodules (check `.gitmodules`)
126
+ - Workspace tooling (`pnpm-workspace.yaml`, `lerna.json`, `nx.json`, `turbo.json`)
127
+
128
+ Describe what you find naturally: "This is a .NET 8 API with a React frontend and Terraform infrastructure" -- not abstract labels.
129
+
130
+ **Build & Test:**
131
+ - Build tools: Makefile, Dockerfile, docker-compose, Taskfile.yml, justfile
132
+ - CI: `.github/workflows/`, `.gitlab-ci.yml`, `.circleci/`, `Jenkinsfile`
133
+ - Test frameworks, linters, formatters, package managers
134
+
135
+ **Existing AI Prompt Infrastructure** (CRITICAL -- check all):
136
+ - `AGENTS.md`, `CLAUDE.md`, `.cursorrules`
137
+ - `.github/copilot-instructions.md`
138
+ - `.claude/` directory (rules, agents, skills)
139
+ - `.cursor/` directory (rules, agents)
140
+ - `.pi/` directory (`settings.json`, `extensions/`, `prompts/`)
141
+ - `.opencode/` directory (`opencode.json`, `agents/`)
142
+ - `.claude/settings.json`, `.claude/settings.local.json`
143
+ - Any sync scripts (`sync.sh`, `sync-to-claude.sh`, etc.)
144
+ - `.gitignore` entries for `.claude`, `.cursor`, `.pi`, `.opencode`, `CLAUDE.md`
145
+
146
+ ---
147
+
148
+ ## Phase 2: Present Recommended Setup
149
+
150
+ Present everything in ONE summary. The user confirms once.
151
+
152
+ Include these sections:
153
+
154
+ 1. **Components detected**: list with paths
155
+ 2. **Rules recommended**: N component rules + 1 shared context
156
+ 3. **Targets to enable**:
157
+ - `agents` is **always enabled** by default — it generates `AGENTS.md` (committed project index consumed by many LLM tools).
158
+ - At least **one IDE adapter** must be enabled. Detect which by scanning for existing tool markers:
159
+ - `.claude/`, `CLAUDE.md`, `.claude/settings.json` -> recommend `claude`
160
+ - `.cursor/`, `.cursorrules` (legacy single-file Cursor format) -> recommend `cursor`
161
+ - `.github/copilot-instructions.md` (legacy Copilot single-file), `.github/instructions/` -> recommend `copilot`
162
+ - `.codex/`, `.agents/` -> recommend `codex`
163
+ - `.pi/`, `.pi/settings.json`, `.pi/extensions/`, `.pi/prompts/` -> recommend `pi`
164
+ - `.opencode/`, `.opencode/opencode.json`, `.opencode/agents/` -> recommend `opencode`
165
+ - If nothing detected, default to `claude` (most common).
166
+ - If the user explicitly names a tool, honor that instead.
167
+ - Present as: "I detected [existing configs]. I will enable: `agents` + `<detected IDE>`. Other adapters (Claude, Cursor, Copilot, Codex, Pi, opencode) can be added any time via `/intelligence-install-adapter`."
168
+ 4. **Agents recommended**: list with tier/access
169
+ 5. **Skills recommended**: pre-installed + migrated + new suggestions (see Phase 3.5)
170
+ 6. **Conventions detected**: key patterns from codebase
171
+ 7. **Submodules** (if found): recommend excluding
172
+ 8. **Migration** (only if existing AI infrastructure found): conflict report with file counts:
173
+ ```
174
+ WILL BE OVERWRITTEN: .claude/rules/ (N files), .cursor/rules/ (N files), etc.
175
+ WILL BE PRESERVED: .claude/settings.local.json, .claude/settings.json
176
+ NEEDS MIGRATION: CLAUDE.md, .cursorrules, existing skills/commands
177
+ ```
178
+
179
+ End with:
180
+
181
+ > **Accept** to proceed (backup + migrate + generate), or **Cancel** to stop.
182
+
183
+ If **Cancel** -- stop completely. intelligence-sync cannot coexist with manually managed IDE prompts.
184
+
185
+ If **Accept** -- execute migration (if needed), then generate.
186
+
187
+ ### Migration (only if existing AI infrastructure found)
188
+
189
+ 1. **Backup:** Create `intelligence/_backup/`, move (not copy) all existing AI files. Add `intelligence/_backup/` to `.gitignore`.
190
+ 2. **Migrate** to tool-agnostic format:
191
+ - `.claude/rules/*.md` -- copy as-is
192
+ - `.cursor/rules/*.mdc` -- rename `.md`, `globs:` -> `paths:`, remove `alwaysApply:`
193
+ - `.github/copilot-instructions.md`, `.cursorrules` -- split by topic
194
+ - `.claude/agents/*.md` -- reverse: `model:` -> `tier:`, remove IDE fields, add `access:`
195
+ - `.cursor/agents/*.md` -- reverse: `model: fast` -> `tier: standard`, `readonly:` -> `access:`
196
+ - `.claude/skills/*/SKILL.md`, `.cursor/skills/*/SKILL.md`, `.claude/commands/*.md`, `.cursor/commands/*.md` -- copy as skills
197
+ 3. **Cleanup:** `git rm` tracked files, `rm` untracked. Remove empty directories.
198
+ 4. **Post-migration validation** (CRITICAL -- do not skip):
199
+ - Build a list of the paths that were removed/renamed (e.g., `dev/scripts/`, `dev/prompts/`, `.cursorrules`, `.claude/rules/`, old directory names).
200
+ - Run `git ls-files` to enumerate every tracked file in the repository (no whitelist -- references to old paths live in `README.md`, scripts, config files, wikis, workflow YAML, not just `docs/`).
201
+ - For each tracked file, grep for each removed path. Record findings.
202
+ - For unambiguous replacements (e.g., `dev/scripts/sync-to-claude.sh` -> `intelligence/sync/scripts/sync.sh`), patch the file automatically.
203
+ - For ambiguous references (path removed without a clear successor, references inside narrative prose, references to scripts that no longer exist), print them to the user grouped by file with line numbers and ask how to resolve.
204
+ - Do not proceed to Phase 3 generation until stale references are resolved or explicitly deferred by the user.
205
+
206
+ ### Files we NEVER touch
207
+
208
+ - `.claude/settings.local.json`, `.claude/settings.json`
209
+ - `.git/`
210
+ - Anything outside AI prompt scope
211
+
212
+ ---
213
+
214
+ ## Phase 3: Generate
215
+
216
+ **Principles:**
217
+ 1. **Adopt, don't impose.** Use the repo's existing directory names and casing conventions.
218
+ 2. **Derive from code, not general knowledge.** Read actual source files. Extract real patterns, real commands, real examples. Every FORBIDDEN/REQUIRED rule must be backed by something you observed in the codebase. Do not generate generic best-practice rules.
219
+ 3. **Agents must reflect reality.** Read existing implementations to determine expertise, architecture patterns, and build commands. If you cannot verify a pattern exists in the code, do not include it.
220
+
221
+ ### 3.1 `intelligence/config.yaml`
222
+
223
+ Set `sync_version` to the engine version — read it verbatim from
224
+ `intelligence/sync/scripts/VERSION`. This is a **managed contract key**: emit
225
+ it on first bootstrap and **preserve its existing value if `config.yaml`
226
+ already has one** when re-bootstrapping (never drop or guess it — the update
227
+ flow owns its value).
228
+
229
+ ```yaml
230
+ project:
231
+ name: "project-name"
232
+
233
+ # Managed by intelligence-sync — applied schema version. Do not hand-edit;
234
+ # preserve on re-bootstrap. (Value = intelligence/sync/scripts/VERSION.)
235
+ sync_version: "0.11.0"
236
+
237
+ sources:
238
+ rules:
239
+ - "intelligence/rules"
240
+ - "intelligence/sync/rules" # engine-owned: intelligence-authoring
241
+ agents:
242
+ - "intelligence/agents"
243
+ - "intelligence/sync/agents" # engine-owned: intelligence-architect, intelligence-operator
244
+ skills:
245
+ - "intelligence/skills"
246
+ - "intelligence/sync/skills" # engine-owned: intelligence-* meta-skills
247
+
248
+ targets:
249
+ # agents: ALWAYS enabled — generates committed AGENTS.md as the
250
+ # canonical project doc. Always-on rules (no `paths:`) are inlined
251
+ # automatically; path-scoped rules stay in tool-specific channels
252
+ # (.cursor/rules/, .github/instructions/) for monorepo scoping.
253
+ agents:
254
+ enabled: true
255
+ output: "AGENTS.md"
256
+ header: |
257
+ # <Project Name>
258
+
259
+ <one-line stack summary — e.g., ".NET 8 API + React 19 | Azure | Phase: MVP">
260
+
261
+ **Full context**: [`intelligence/rules/context.md`](intelligence/rules/context.md)
262
+ # At least one IDE adapter — pick based on detection or user preference
263
+ claude: { enabled: true, output: ".claude" }
264
+ # Optional adapters: cursor, copilot, codex, pi, opencode
265
+ # pi: { enabled: false, output: ".pi" }
266
+ # opencode: { enabled: false, output: ".opencode" }
267
+
268
+ ignore:
269
+ - "node_modules"
270
+ - "vendor"
271
+ - "dist"
272
+
273
+ # Optional: override per-IDE tier -> model mappings. Defaults live in
274
+ # intelligence/sync/scripts/lib/common.sh. Add only the entries you want to
275
+ # pin; everything else uses the current default.
276
+ # Example:
277
+ # models:
278
+ # copilot:
279
+ # heavy: "gpt-5.6-sol"
280
+ ```
281
+
282
+ The `agents.header` block is the only hand-authored part of `AGENTS.md`. Everything else (tables for agents/skills, list of rules) is regenerated from frontmatter on every sync. Keep the header to 3–5 lines: project name, one-liner stack summary, link to `context.md`.
283
+
284
+ Engine scripts (under `intelligence/sync/scripts/`):
285
+
286
+ - `sync.sh` — generate IDE outputs from `intelligence/`
287
+ - `update.sh` — pull latest scripts/INIT.md from upstream without touching project content
288
+ - `lib/common.sh` — shared helpers (`get_model`, `lint_frontmatter`, frontmatter parsers, etc.)
289
+
290
+ Built-in adapters:
291
+
292
+ | Target | Adapter | Output | Notes |
293
+ |--------|---------|--------|-------|
294
+ | `agents` | `agents.sh` | `AGENTS.md` | Committed; canonical project doc with inlined always-on rules |
295
+ | `claude` | `claude.sh` | `.claude/` | Full rule copy (Claude does not read AGENTS.md) |
296
+ | `cursor` | `cursor.sh` | `.cursor/` | Path-scoped rules only (always-on come from AGENTS.md) |
297
+ | `copilot` | `copilot.sh` | `.github/` | Path-scoped rules only; shares dir with workflows |
298
+ | `codex` | `codex.sh` | `.agents/skills/` + `.codex/agents/` | Reads AGENTS.md for context |
299
+ | `pi` | `pi.sh` | `.pi/` + `.agents/skills/` | Reads AGENTS.md for always-on context; generated extension surfaces scoped rules; agents become prompt templates |
300
+ | `opencode` | `opencode.sh` | `.opencode/` + `.agents/skills/` | Reads AGENTS.md natively; agents become markdown subagents (`.opencode/agents/<name>.md`); skills via `.agents/skills/`; no scoped-rules emission (users may opt in via `instructions:` globs in `opencode.json`) |
301
+
302
+ Need a target with no built-in adapter? Write it as `<intel>/adapters/<name>.sh` — beside `config.yaml`, using the folder name detected in *Phase 0*, and **never** inside `<intel>/sync/scripts/adapters/`, which `update.sh` replaces wholesale (an adapter written there is deleted by the next engine update). `sync.sh` scans both locations; a project adapter overrides a built-in of the same name. See `/intelligence-install-adapter` and `<intel>/sync/docs/ADAPTERS.md`.
303
+
304
+ ### 3.2 `intelligence/rules/context.md`
305
+
306
+ Always-loaded context (no `paths:` in frontmatter):
307
+ - Project name and description
308
+ - Repository structure
309
+ - Build and test commands
310
+ - Global rules (naming, formatting, forbidden patterns)
311
+
312
+ ### 3.3 Component-specific rules
313
+
314
+ One rule per component, scoped with `paths:` frontmatter:
315
+ - REQUIRED patterns (positive defaults — what to do, judgment calls)
316
+ - Invariants (true must-nots: safety, output format, security — never judgment calls)
317
+ - Architecture patterns
318
+ - Component-specific build/test commands
319
+ - Code examples from the actual codebase
320
+ - Patterns to recognize and replace (optional — anti-patterns documented as reference with positive replacements; documentation, not LLM instruction)
321
+
322
+ ### 3.4 Agents
323
+
324
+ **Developer agents** (tier: heavy, access: full) -- one per distinct stack:
325
+ - Expertise based on detected patterns; boundaries (where the agent stops); build/verify commands
326
+ - **Never instruct an agent to read the rules.** Rules load on their own — Claude Code loads `.claude/rules/` into every custom subagent's startup context, and Cursor / Copilot / Codex / Pi / opencode get always-on rules inlined in `AGENTS.md`. A "read `intelligence/rules/<domain>.md` first" line duplicates content the agent already has and drifts from the rule it copied.
327
+ - Link relevant skills via `skills:` in frontmatter
328
+
329
+ **Code reviewer** (tier: standard, access: readonly):
330
+ - Review criteria per component, output format
331
+ - Link review skills if created (e.g., `<domain>-review-` skills)
332
+
333
+ ### 3.5 Skills
334
+
335
+ Pre-installed by the engine — never recreate these, and never use the reserved `intelligence-` prefix for a project skill:
336
+ - `/intelligence-sync` — sync to all enabled IDE targets
337
+ - `/intelligence-update` — update or migrate the engine
338
+ - `/intelligence-install-adapter` / `/intelligence-uninstall-adapter` — turn an IDE channel on or off
339
+ - `/intelligence-add-rule`, `/intelligence-add-agent`, `/intelligence-add-skill` — author an artifact with the conventions applied
340
+ - `/intelligence-extract-skill`, `/intelligence-learn-from-context`, `/intelligence-review-skills` — turn observed work into artifacts, and audit the layer
341
+
342
+ The engine also ships the `intelligence-authoring` rule (authoring discipline, scoped to `<intel>/`) and two agents: `intelligence-architect` (designs and prunes this layer) and `intelligence-operator` (runs the sync, update, and adapter-install/removal flows). They are upstream-owned and arrive via `sources` — do not copy or rewrite them into project content.
343
+
344
+ **Derive skills from this repository. Do not pick them from a catalogue.** A list of plausible skill names ("add-entity", "add-endpoint", "run-tests") is a trap: every one of them sounds right for every project, so working from such a list produces a registry that describes software in general rather than *this* codebase — and every entry costs context budget forever, whether or not anyone invokes it.
345
+
346
+ A candidate skill has to clear all four bars:
347
+
348
+ 1. **Repeated.** The operation has demonstrably been done more than once. Evidence: near-identical sibling files, a "how to add X" section in `README`/`CONTRIBUTING`, the same multi-file shape appearing across git history. Not "a project like this usually needs it".
349
+ 2. **Multi-step and mechanical.** 3+ concrete steps in a predictable pattern, usually across more than one file. If it is one edit, the model does not need a procedure.
350
+ 3. **Verifiable.** It ends in a command or check that proves it worked (build, test, lint, migration, sync). **If there is nothing to verify at the end, it is not a skill** — it is a note, or just work.
351
+ 4. **Stable.** It describes the project *as it is meant to work*. A procedure that only exists to route around a current bug is not a skill — that belongs in a single rule that records known breakage, so it disappears when the bug is fixed instead of becoming permanent.
352
+
353
+ **Show your evidence.** For every skill you propose, name the files it would touch and the concrete instance in the repo you derived it from. If you cannot point at one, do not propose it.
354
+
355
+ **Start small: 0–3 skills at bootstrap.** Zero is a legitimate answer for a young or simple repository — say so plainly rather than padding. Skills can be added at any time with `/intelligence-add-skill`, and one added later, from a pattern the team actually hit twice, is worth more than five guessed today.
356
+
357
+ Naming (details in `<intel>/sync/docs/CONVENTIONS.md`): `<domain>-<verb>-<noun>`, domain prefix taken from the set already in use. Two verbs are told apart by what already exists — **`add-` puts one new member into a set that is already there**, and **`create-` brings into existence the container nothing hosted before**; neither describes how the skill is factored inside. Other verbs (`run-`, `review-`, `update-`, `extract-`) read fine; prefer a verb already in use over a new synonym for the same thing. `intelligence-` is reserved for the engine's meta-skills.
358
+
359
+ Present the shortlist with its evidence and let the user choose. Then create only what they pick.
360
+
361
+ ### 3.6 `.gitignore`
362
+
363
+ Add (if not present):
364
+ ```
365
+ # AI IDE tools (generated by intelligence-sync)
366
+ CLAUDE.md
367
+ .cursorrules
368
+ .agents/
369
+ .codex/
370
+
371
+ # Pi: generated prompt templates, scoped-rule extension, and copied rule files.
372
+ # Keep .pi/settings.json and any hand-authored extensions/prompts outside these
373
+ # paths tracked if you want to share them.
374
+ .pi/intelligence-sync/
375
+ .pi/extensions/intelligence-sync-rules.ts
376
+ .pi/prompts/intelligence-agent-*.md
377
+
378
+ # opencode: only the generated subagents and slash commands are owned by the adapter.
379
+ # Keep .opencode/opencode.json (and any hand-authored config) tracked.
380
+ .opencode/agents/
381
+ .opencode/commands/
382
+
383
+ # Claude Code: ignore everything except project-shared settings.
384
+ # This catches generated subdirs (rules/, skills/, agents/) plus any
385
+ # per-machine state Claude writes (settings.local.json, *.lock,
386
+ # scheduled_tasks.*, sessions/, cache/, etc.) without us having to
387
+ # enumerate every filename Claude may add in the future.
388
+ .claude/*
389
+ !.claude/settings.json
390
+
391
+ # Cursor: same pattern.
392
+ .cursor/*
393
+ !.cursor/settings.json
394
+ ```
395
+
396
+ Notes:
397
+ - `.github/` and `AGENTS.md` are intentionally NOT gitignored — they contain shared content.
398
+ - Only `.claude/settings.json` and `.cursor/settings.json` are tracked by default — they hold project-shared IDE settings (allowed bash commands, tool permissions). Everything else under those directories is either generated by sync or per-user state.
399
+ - The Pi adapter writes only three generated paths: `.pi/intelligence-sync/`, `.pi/extensions/intelligence-sync-rules.ts`, and `.pi/prompts/intelligence-agent-*.md`. It does NOT own `.pi/settings.json` or any other `.pi/extensions/*.ts` / `.pi/prompts/*.md` files.
400
+ - The opencode adapter writes only `.opencode/agents/` (one markdown subagent per source agent) and `.opencode/commands/` (one slash command per source skill, mirroring Claude Code's skill-as-command UX). It does NOT own `.opencode/opencode.json` or any other `.opencode/*` files — those remain hand-authored and tracked. Generated command files carry an `<!-- Generated by intelligence-sync. Do not edit manually. -->` marker; only marker-bearing files are removed on re-sync, so any hand-authored command in `.opencode/commands/` survives.
401
+ - If you need to track another file under `.claude/` or `.cursor/` (e.g., `.claude/commands/<name>.md` for a hand-authored command), add another `!path` un-ignore line below.
402
+
403
+ ### 3.7 `AGENTS.md` (auto-generated by `agents.sh`)
404
+
405
+ `AGENTS.md` is produced by the `agents` adapter on every sync. It is NOT hand-authored. Do not create this file yourself in Phase 3 -- it will be generated in Phase 4 by `intelligence/sync/scripts/sync.sh`.
406
+
407
+ Your job in Phase 3 is to fill `targets.agents.header` in `config.yaml` (see 3.1) with a 3-5 line project summary: title, stack one-liner, link to `intelligence/rules/context.md`. The adapter appends auto-built tables for agents/skills and a list of rules after the header.
408
+
409
+ The file is committed (not gitignored) but carries a `<!-- Generated ... do not edit manually -->` marker. All regeneration happens via `bash intelligence/sync/scripts/sync.sh`.
410
+
411
+ ### 3.8 `CLAUDE.md` (if Claude enabled)
412
+
413
+ Gitignored user preferences:
414
+ - Response language
415
+ - Setup: `intelligence/sync/scripts/sync.sh`
416
+ - Helper scripts, git commit rules
417
+
418
+ ---
419
+
420
+ ## Phase 4: Verify
421
+
422
+ 1. Run `intelligence/sync/scripts/sync.sh`
423
+ 2. If sync fails -- read the error, fix the cause (usually missing directory or malformed frontmatter), retry
424
+ 3. Verify output counts match expectations
425
+ 4. Report to user:
426
+ - Files created (rules, agents, skills)
427
+ - Sync results per target
428
+ - **Enabled targets**: list what was configured (e.g., "claude, cursor, copilot")
429
+ - **Available but not enabled**: list remaining adapters (e.g., "codex, pi, opencode — enable via `/intelligence-install-adapter <name>`")
430
+ - **Available skills**: list all (pre-installed + generated)
431
+ - "To add rules/agents/skills: `/intelligence-add-rule`, `/intelligence-add-agent`, `/intelligence-add-skill`"
432
+ - "After manual edits: `/intelligence-sync` to re-sync"
433
+
434
+ ---
435
+
436
+ ## Reference
437
+
438
+ ### Frontmatter
439
+
440
+ **YAML safety (required):** **always wrap `description` and any other free-text string field in double quotes**, even when no special characters are present. Codex CLI uses strict YAML — an unquoted colon, hyphen, or word that parses as boolean (`yes`, `no`) silently breaks the file. Quoting unconditionally removes a whole class of bugs and makes lint trivial. If the value itself contains a double quote, escape it as `\"` or wrap the value in single quotes — an unescaped inner quote terminates the scalar early. The sync engine auto-escapes inner quotes when it quotes a value, as a backstop.
441
+
442
+ **Agent:**
443
+ ```yaml
444
+ ---
445
+ name: agent-name
446
+ description: "When to use this agent"
447
+ tier: heavy|standard|light # heavy=opus, standard=sonnet, light=haiku
448
+ access: full|readonly # full=all tools, readonly=no write/edit
449
+ skills: # optional: skills this agent can invoke
450
+ - domain-add-something
451
+ - domain-run-tests
452
+ ---
453
+ ```
454
+
455
+ **Rule:**
456
+ ```yaml
457
+ ---
458
+ paths: # omit for always-loaded rules
459
+ - "src/backend/**"
460
+ ---
461
+ ```
462
+
463
+ **Skill:**
464
+ ```yaml
465
+ ---
466
+ name: domain-verb-noun
467
+ description: "What the skill does"
468
+ argument-hint: <arg1> [arg2] # optional
469
+ agent: agent-name # optional: which agent executes this skill
470
+ ---
471
+ ```
472
+
473
+ ### Content structure
474
+
475
+ **Rule body:** REQUIRED -> Invariants -> Architecture -> Build & Test -> Examples (from actual codebase) -> Patterns to recognize and replace (optional reference section)
476
+
477
+ - Lead with REQUIRED (positive defaults / judgment calls)
478
+ - Reserve **Invariants** for true must-nots — safety, output format, security
479
+ - **Patterns to recognize and replace** is reference documentation of anti-patterns with their positive replacement, not LLM instructions
480
+
481
+ **Agent body:** Expertise -> Boundaries (where it stops) -> Build & Verify. An agent is thin — rules reach it automatically, so it never lists rules to read.
482
+
483
+ **Skill body:** Steps (numbered, concrete, with verification at the end). A skill that dispatches to other skills names them and never restates their content.
484
+
485
+ ### Skill naming
486
+
487
+ Prefix with domain: `backend-`, `frontend-`, `devops-`, `intelligence-`, etc.
488
+
489
+ | Prefix | Type |
490
+ |--------|------|
491
+ | `<domain>-add-` | Adds one member to a set that already exists |
492
+ | `<domain>-create-` | Brings into existence a container nothing hosted before |
493
+ | `<domain>-run-` | Runs an operation |
494
+ | `<domain>-review-` | Analyzes without changes |
495
+
496
+ ---
497
+
498
+ intelligence-sync is created by [Ainova Systems](https://www.ainovasystems.com). MIT License.