@jbr589/magcc 0.0.0-amorce.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@jbr589/magcc` are documented here. The project follows
4
+ Semantic Versioning; while the version is `0.x`, a breaking change to the
5
+ IR format or to the CLI bumps the minor version and a fix bumps the patch version.
6
+
7
+ ## [0.1.0] - 2026-12-06
8
+
9
+ First release of the compiler as a single npm package.
10
+
11
+ ### Added
12
+
13
+ - `magcc build`: compiles a neutral `setup/` (agents, commands, hooks, guardrails, MCP servers,
14
+ model policy) to Claude Code, opencode and pi, with `--prune` to remove orphaned outputs.
15
+ - `magcc check`: read-only parity check; exits 0 when every generated file is bit-for-bit what
16
+ `build` would write, 1 on drift or orphaned outputs.
17
+ - `magcc deps`: dependency graph between entities, as text or `--json`.
18
+ - `magcc pipeline-run`: step-by-step execution of a compiled orchestration pipeline.
19
+ - Neutral IR: closed vocabularies for tiers (`fast`, `standard`, `deep`, `apex`, `inherit`),
20
+ capabilities and hook events; a value outside a vocabulary is discarded with a `WARN`.
21
+ - Composition of a shared base setup with a per-project overlay through `setup.toml`.
22
+ - Explicit loss reporting: each emitter declares what it renders in `capabilities()`, compared at
23
+ build time with the features the setup demands; a missing token is a `WARN`.
24
+ - Emission option `packages` for the pi target, read from an `emit-options.toml` outside the IR;
25
+ without it, pi gets no `.pi/settings.json`.
26
+ - Hook bodies written once in Node (`.mjs`) and wrapped per target.
27
+ - A generated-file header on every emitted file whose format has comments, in English
28
+ (`Generated from <source> — do not edit by hand.`).
29
+ - Warnings and errors printed by the compiler are in English.
30
+ - `examples/minimal`: a complete neutral setup with its generated output for the three targets.
31
+ - Published as one bundle (`magcc.mjs`) that runs on Node >= 24 with no runtime dependency.
32
+
33
+ ### Known limits
34
+
35
+ - Three targets only; the provider used to resolve tiers is fixed per target (opencode:
36
+ `github-copilot`, pi: `deepseek`); Claude Code receives its native model aliases.
package/NOTICE ADDED
@@ -0,0 +1,12 @@
1
+ magcc — Copyright 2026 Joffray Braga
2
+
3
+ Licensed under the Apache License, Version 2.0 (see LICENSE).
4
+
5
+ This product includes software developed by third parties. Their notices follow.
6
+
7
+ Bundled components. The published package `@jbr589/magcc` inlines two libraries into its single
8
+ file `magcc.mjs`: `yaml` (ISC licence) and `smol-toml` (BSD-3-Clause licence). Their licence texts
9
+ are reproduced as is in `THIRD_PARTY_NOTICES.md`, which ships with the package.
10
+
11
+ Development tools. The TypeScript compiler and the Bun type definitions are used to build and
12
+ check this repository; they are not part of the published package.
package/README.md CHANGED
@@ -1,12 +1,239 @@
1
- # @jbr589/magcc (placeholder)
1
+ # magcc
2
2
 
3
- This version contains no code. It only reserves the package name so that later releases can be
4
- published from CI with npm trusted publishing.
3
+ **Define your agentic setup once, compile it to Claude Code, opencode and pi.**
5
4
 
6
- Install the real compiler instead:
5
+ Coding agents (subagents, slash commands, hooks, always-on rules) are configured in a different
6
+ file format by every harness, so a setup written for one is rewritten by hand for the next and
7
+ the copies drift apart. Tools that only synchronise a rules file do not cover agents with model
8
+ tiers, commands or hooks. `magcc` keeps one neutral source (`setup/`), compiles it to each
9
+ target, and tells you, target by target, what that target cannot express.
10
+
11
+ ## Install
7
12
 
8
13
  ```sh
9
- npm i -g @jbr589/magcc@latest
14
+ npm i -g @jbr589/magcc # Node >= 24, no other runtime dependency
15
+ magcc --version
16
+ ```
17
+
18
+ ## Try it in two minutes (no clone needed)
19
+
20
+ ```sh
21
+ mkdir demo && cd demo && git init -q && mkdir -p setup/agents
22
+
23
+ cat > setup/model-policy.toml <<'EOT'
24
+ default_provider = "anthropic"
25
+
26
+ [tiers.anthropic]
27
+ standard = "model-standard-1"
28
+
29
+ [tiers.github-copilot]
30
+ standard = "github-copilot/model-standard-1"
31
+
32
+ [tiers.deepseek]
33
+ standard = "deepseek-standard-1"
34
+ EOT
35
+
36
+ cat > setup/agents/reader.md <<'EOT'
37
+ ---
38
+ id: reader
39
+ description: "Read-only explorer: reads code and returns a short summary."
40
+ tier: standard
41
+ capabilities: [read, search]
42
+ access:
43
+ read: ["**"]
44
+ ---
45
+ You read the requested code and report a concise summary. You modify no file.
46
+ EOT
47
+
48
+ magcc build # writes .claude/agents/reader.md, .opencode/agent/reader.md, .pi/agents/reader.md, ...
49
+ magcc check # exit 0 while the outputs match the source, 1 as soon as one drifts
10
50
  ```
11
51
 
12
- Source: https://github.com/jbr589/magcc
52
+ (`git init` matters: `magcc` uses git to detect orphan outputs; outside a git repository it prints a `WARN` and skips that detection.)
53
+
54
+ Edit a generated file by hand and `magcc check` reports the drift and exits 1; run `magcc build`
55
+ to regenerate. Every generated file starts with a header such as
56
+ `Generated from setup/agents/reader.md — do not edit by hand.` (JSON outputs carry none, since
57
+ JSON has no comment syntax).
58
+
59
+ A larger, committed example lives in the repository under `examples/minimal`: three agents on
60
+ three tiers, one command, one Node hook, one guardrail, and the generated output for the three
61
+ targets.
62
+
63
+ ```sh
64
+ magcc build examples/minimal
65
+ magcc check examples/minimal
66
+ ```
67
+
68
+ ## Commands
69
+
70
+ | Command | What it does |
71
+ | --- | --- |
72
+ | `magcc build [--prune [--dry-run]] [dir]` | Emits the files of every target. `--prune` removes outputs that no source produces any more. |
73
+ | `magcc check [dir]` | Read-only parity check: exit 0 when every output is bit-for-bit what `build` would write. |
74
+ | `magcc deps [--json] [dir]` | Dependency graph between entities (agents, hooks, commands, guardrails). |
75
+ | `magcc pipeline-run ...` | Runs a compiled orchestration pipeline step by step. |
76
+ | `magcc help`, `magcc --version` | Usage and version. Any other command exits 2. |
77
+
78
+ `dir` is the project directory (default: the current directory). A project is a `setup/`
79
+ directory next to the outputs; an optional `setup.toml` composes a shared base with a per-project
80
+ overlay, picks the output directory and restricts the targets.
81
+
82
+ ## Source layout
83
+
84
+ ```text
85
+ setup/
86
+ model-policy.toml # tier -> concrete model, per provider
87
+ agents/<id>.md # subagents (frontmatter + prompt body)
88
+ commands/<id>.md # slash commands / prompt templates
89
+ hooks/<id>.toml # hook declaration (event, match, contract)
90
+ hooks/impl/<id>.mjs # the hook body, written once in Node
91
+ memory/guardrails/<id>.md # always-loaded rules, one per file
92
+ mcp/<id>.toml # MCP servers
93
+ ```
94
+
95
+ Apart from `model-policy.toml`, the source never names a harness or a concrete model id: that file
96
+ alone associates tiers with providers and model ids (its comments and provider names may refer to
97
+ a target). Everywhere else, tiers are a closed vocabulary
98
+ (`fast`, `standard`, `deep`, `apex`, `inherit`); capabilities are neutral tokens (`read`, `write`,
99
+ `search`, `shell`, `mcp:<id>`, ...); hook events are neutral too (`pre-tool`, `session-end`, ...).
100
+ A value outside a closed vocabulary is discarded with a `WARN`, never cast silently.
101
+
102
+ ## What gets generated
103
+
104
+ | Target | Agents | Commands | Hooks | Always-loaded rules |
105
+ | --- | --- | --- | --- | --- |
106
+ | Claude Code | `.claude/agents/` | `.claude/commands/` | `.claude/hooks/*.mjs` + `.claude/settings.json` | `CLAUDE.md` |
107
+ | opencode | `.opencode/agent/` | `.opencode/command/` | `.opencode/hooks/*.mjs` + `.opencode/plugins/*.js` | `AGENTS.md` |
108
+ | pi | `.pi/agents/` | `.pi/prompts/` | `.pi/magcc-hooks/*.mjs` + `.pi/extensions/` | `.pi/APPEND_SYSTEM.md` |
109
+
110
+ Hooks are written once as a Node module (`.mjs`, never bash, so the guard also runs on native
111
+ Windows) and wrapped by a thin per-target shim. Tiers become the target's own model naming:
112
+ Claude Code receives its native model alias for the tier, opencode and pi resolve the tier through
113
+ `model-policy.toml`.
114
+
115
+ ## Architecture
116
+
117
+ ```text
118
+ setup/ --parse--> neutral IR --resolve--> Setup --emit--> .claude/ .opencode/ .pi/
119
+ (core, pure) (tiers, inheritance, (one emitter per target)
120
+ composition)
121
+ ```
122
+
123
+ | Package | Role |
124
+ | --- | --- |
125
+ | `packages/core` | Neutral IR types, parsing, resolution (tiers, inheritance, base + overlay composition), pipeline and dependency graph, emitter contract. **Pure**: no disk I/O. |
126
+ | `packages/emitter-claude-code`, `packages/emitter-opencode`, `packages/emitter-pi` | One emitter per target. Each declares what it renders through `capabilities()`. |
127
+ | `packages/cli` | Reads `setup/`, writes the outputs, runs `build`, `check`, `deps`, `pipeline-run`. Bundled into the single `magcc.mjs` file that npm ships. |
128
+
129
+ Three rules hold the design together:
130
+
131
+ - **Lossy, but explicit.** An emitter may be unable to render a feature, but it must say so:
132
+ every feature it renders is a token in its `capabilities()`, compared at build time with the
133
+ features the setup actually demands (`setupFeatureDemands`). A missing token is a `WARN`, never
134
+ a silent loss.
135
+ - **Zero drift.** Outputs are generated, never edited. `magcc check` regenerates them in memory
136
+ and compares them bit for bit with what is on disk, so it can run in CI.
137
+ - **A pure core.** Reading `setup/` and writing outputs are the CLI's job; the core can be tested
138
+ in memory and reused elsewhere.
139
+
140
+ ## Loss matrix
141
+
142
+ What each target renders natively. Every "no" is reported as a `WARN` at build time when your
143
+ setup uses the feature; nothing is dropped silently. The table is generated from the three
144
+ `capabilities()` sets and the tokens `setupFeatureDemands` can project, and a test fails if it
145
+ drifts: `bun test packages/cli/test/readme-loss-matrix.test.ts` (print the expected table with
146
+ `bun packages/cli/test/helpers/loss-matrix.ts`).
147
+
148
+ <!-- loss-matrix:start -->
149
+ | Token | Feature | Claude Code | opencode | pi |
150
+ | --- | --- | --- | --- | --- |
151
+ | `agent` | Agents | yes | yes | yes |
152
+ | `command` | Commands | yes | yes | yes |
153
+ | `tier` | Model tier resolved from the policy | yes | yes | yes |
154
+ | `effort` | Reasoning effort (policy default per tier) | yes | **no** | yes |
155
+ | `capabilities` | Tool allowlist | yes | **no** | yes |
156
+ | `access:readonly` | Read-only access mode | yes | yes | yes |
157
+ | `access:path-scope` | Per-agent path scope | **no** | yes | **no** |
158
+ | `agent:mcp-binding` | Per-agent MCP binding | **no** | **no** | **no** |
159
+ | `mcp` | MCP servers | yes | yes | **no** |
160
+ | `hooks` | Hooks (Node body, thin per-target wrapper) | yes | yes | yes |
161
+ | `event:session-start` | Hook event `session-start` | yes | yes | yes |
162
+ | `event:prompt-submit` | Hook event `prompt-submit` | yes | yes | yes |
163
+ | `event:pre-tool` | Hook event `pre-tool` | yes | yes | yes |
164
+ | `event:post-tool` | Hook event `post-tool` | yes | yes | yes |
165
+ | `event:stop` | Hook event `stop` | yes | **no** | yes |
166
+ | `event:session-end` | Hook event `session-end` | yes | **no** | yes |
167
+ | `memory:guardrails` | Always-loaded guardrails | yes | yes | yes |
168
+ | `option:packages` | Emission option `packages` (extension packages) | **no** | **no** | yes |
169
+ <!-- loss-matrix:end -->
170
+
171
+ Finer points that a token cannot carry:
172
+
173
+ - On pi, `tier`, `effort` and a tool allowlist are rendered for agents only. A command is a plain
174
+ prompt template there, so those fields on a command are lost and reported
175
+ (`magcc build examples/minimal` shows this warning for the `summarize` command).
176
+ - On opencode, a read-only agent keeps its read-only mode and its path scope, but an explicit tool
177
+ allowlist and the reasoning effort are not translated.
178
+ - On Claude Code, a fine-grained per-agent path scope cannot be expressed; only the read-only mode
179
+ is. A path-guard hook is the documented mitigation.
180
+ - The emission option `packages` (extension packages for pi) is not part of the IR. It comes from
181
+ an `emit-options.toml` next to `setup/`; without it, pi gets no `.pi/settings.json`.
182
+
183
+ ## Limits
184
+
185
+ - **Three targets.** Claude Code, opencode and pi. Adding a target means writing an emitter.
186
+ - **Provider per target is fixed.** opencode resolves tiers against the `github-copilot` section of
187
+ the model policy and pi against `deepseek`; Claude Code uses its native aliases. The policy's
188
+ `default_provider` only drives the default reasoning effort.
189
+ - **Early version (0.x).** A breaking change to the IR format or to the CLI bumps the minor
190
+ version. Placeholder model ids in the examples must be replaced with real ones.
191
+ - **No Agent SDK emission and no runtime.** `magcc` compiles configuration; it does not run agents.
192
+ - **Node >= 24** is required for the published bundle. Building the bundle itself needs Bun.
193
+
194
+ ## Where it sits
195
+
196
+ Rule-synchronisation tools (rulesync, ai-rulez, ruler and similar) copy a rules or instructions
197
+ file, and some of their configuration, to the layout of many harnesses. They cover more targets
198
+ than `magcc` and are more mature; if rule files across many editors are all you need, use them.
199
+ `magcc` makes a narrower bet: a typed, harness-neutral source for the parts that are not plain
200
+ rules (agents with model tiers, commands, hooks written once, guardrails), a model policy that
201
+ resolves tiers only at emission time, a declared loss per target, and a parity check that makes
202
+ generated files safe to commit.
203
+
204
+ ## Documentation
205
+
206
+ The reference documents are in the `docs/` directory:
207
+
208
+ - `docs/IR-SPEC.md`: the specification of the intermediate representation;
209
+ - `docs/PIPELINE-IR.md`: the compiler pipeline;
210
+ - `docs/00-doctrine.md`: the vision and its axes;
211
+ - `docs/01-concepts.md`: the concepts;
212
+ - `docs/ADR-001-compiler-stack.md`, `docs/ADR-002-build-approach.md` and
213
+ `docs/ADR-003-hooks-node-canonical.md`: the architecture decisions;
214
+ - `docs/BACKEND-CONTRACT.md`: the contract every emitter follows;
215
+ - `docs/MEMORY-TIERS.md`: the tiered memory concept.
216
+
217
+ ## Development
218
+
219
+ ```sh
220
+ bun install --frozen-lockfile
221
+ bun run check # typecheck, tests, example parity, bundle built and run under Node
222
+ bun run build # builds packages/cli/dist/magcc.mjs (the published bundle)
223
+ ```
224
+
225
+ ## Language and contributions
226
+
227
+ Everything in this repository is in English: this README, the package metadata, the changelog,
228
+ the specification, the code comments and the messages `magcc` prints and writes are all in English.
229
+ The one exception is a handful of French sample strings in the tests, used as input data.
230
+
231
+ This is a mirror repository: contributions are reviewed and ported by hand. Issues are welcome;
232
+ pull requests are read but not merged as such, and a change that is accepted lands in a later
233
+ release. Security reports: see [SECURITY.md](SECURITY.md).
234
+
235
+ ## License
236
+
237
+ Apache License 2.0, see [LICENSE](LICENSE) and [NOTICE](NOTICE). The published package also ships
238
+ `THIRD_PARTY_NOTICES.md`, the licences of the two components bundled into `magcc.mjs` (`yaml` and
239
+ `smol-toml`).
@@ -0,0 +1,51 @@
1
+ # Third-party notices
2
+
3
+ `@jbr589/magcc` bundles, in `magcc.mjs`, the code of the components below. Their licences
4
+ are reproduced as is.
5
+
6
+ ## yaml 2.9.0 — ISC
7
+
8
+ ```text
9
+ Copyright Eemeli Aro <eemeli@gmail.com>
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any purpose
12
+ with or without fee is hereby granted, provided that the above copyright notice
13
+ and this permission notice appear in all copies.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
21
+ THIS SOFTWARE.
22
+ ```
23
+
24
+ ## smol-toml 1.7.0 — BSD-3-Clause
25
+
26
+ ```text
27
+ Copyright (c) Squirrel Chat et al., All rights reserved.
28
+
29
+ Redistribution and use in source and binary forms, with or without
30
+ modification, are permitted provided that the following conditions are met:
31
+
32
+ 1. Redistributions of source code must retain the above copyright notice, this
33
+ list of conditions and the following disclaimer.
34
+ 2. Redistributions in binary form must reproduce the above copyright notice,
35
+ this list of conditions and the following disclaimer in the
36
+ documentation and/or other materials provided with the distribution.
37
+ 3. Neither the name of the copyright holder nor the names of its contributors
38
+ may be used to endorse or promote products derived from this software without
39
+ specific prior written permission.
40
+
41
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
42
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
45
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
47
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
48
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51
+ ```