pyaisync 0.1.0__tar.gz

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 (40) hide show
  1. pyaisync-0.1.0/.gitignore +6 -0
  2. pyaisync-0.1.0/AGENTS.md +42 -0
  3. pyaisync-0.1.0/LICENSE +21 -0
  4. pyaisync-0.1.0/PKG-INFO +365 -0
  5. pyaisync-0.1.0/PLAN.md +462 -0
  6. pyaisync-0.1.0/README.md +355 -0
  7. pyaisync-0.1.0/docs/ARCHITECTURE.md +158 -0
  8. pyaisync-0.1.0/docs/formats/README.md +178 -0
  9. pyaisync-0.1.0/pyproject.toml +32 -0
  10. pyaisync-0.1.0/src/pyaisync/__init__.py +3 -0
  11. pyaisync-0.1.0/src/pyaisync/cli.py +369 -0
  12. pyaisync-0.1.0/src/pyaisync/config.py +97 -0
  13. pyaisync-0.1.0/src/pyaisync/errors.py +5 -0
  14. pyaisync-0.1.0/src/pyaisync/frontmatter.py +42 -0
  15. pyaisync-0.1.0/src/pyaisync/importers/__init__.py +186 -0
  16. pyaisync-0.1.0/src/pyaisync/importers/common.py +54 -0
  17. pyaisync-0.1.0/src/pyaisync/importers/structured.py +879 -0
  18. pyaisync-0.1.0/src/pyaisync/loader.py +313 -0
  19. pyaisync-0.1.0/src/pyaisync/manifest.py +98 -0
  20. pyaisync-0.1.0/src/pyaisync/model.py +133 -0
  21. pyaisync-0.1.0/src/pyaisync/plugin.py +78 -0
  22. pyaisync-0.1.0/src/pyaisync/safefs.py +97 -0
  23. pyaisync-0.1.0/src/pyaisync/targets/__init__.py +62 -0
  24. pyaisync-0.1.0/src/pyaisync/targets/base.py +67 -0
  25. pyaisync-0.1.0/src/pyaisync/targets/claude.py +140 -0
  26. pyaisync-0.1.0/src/pyaisync/targets/cursor.py +154 -0
  27. pyaisync-0.1.0/src/pyaisync/targets/opencode.py +109 -0
  28. pyaisync-0.1.0/src/pyaisync/vocab.py +132 -0
  29. pyaisync-0.1.0/src/pyaisync/writer.py +356 -0
  30. pyaisync-0.1.0/tests/conftest.py +37 -0
  31. pyaisync-0.1.0/tests/test_generate.py +123 -0
  32. pyaisync-0.1.0/tests/test_hooks_flow.py +308 -0
  33. pyaisync-0.1.0/tests/test_import_structured.py +366 -0
  34. pyaisync-0.1.0/tests/test_init_import.py +95 -0
  35. pyaisync-0.1.0/tests/test_phase2.py +217 -0
  36. pyaisync-0.1.0/tests/test_phase3.py +203 -0
  37. pyaisync-0.1.0/tests/test_plugin.py +137 -0
  38. pyaisync-0.1.0/tests/test_security.py +66 -0
  39. pyaisync-0.1.0/tests/test_target_cmd.py +114 -0
  40. pyaisync-0.1.0/uv.lock +472 -0
@@ -0,0 +1,6 @@
1
+ __pycache__/
2
+ .venv/
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ dist/
6
+ *.egg-info/
@@ -0,0 +1,42 @@
1
+ # AGENTS.md — pyaisync
2
+
3
+ Instructions for AI coding agents working **on this repository**. (For using the tool, see `README.md`.)
4
+
5
+ ## What this is
6
+ `pyaisync` keeps AI coding agent configuration in one source (`.ai/`) and transpiles it into the native files of Claude Code,
7
+ Cursor and OpenCode; it also imports native config and packages a Claude Code plugin. Python 3.11+, one runtime dependency
8
+ (`pyyaml`), managed with `uv`.
9
+
10
+ **Read first:** [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) (modules, data flow, writer rules, how to extend),
11
+ [`docs/formats/README.md`](docs/formats/README.md) (verified native formats), [`PLAN.md`](PLAN.md) (design rationale).
12
+
13
+ ## Commands
14
+ ```bash
15
+ uv sync # install (includes dev tools)
16
+ uv run pytest -q # tests (must pass)
17
+ uv run ruff check . && uv run ruff format --check .
18
+ uv run mypy # strict (must pass)
19
+ uv run pyaisync --help
20
+ ```
21
+ All three checks must be green before you finish a change.
22
+
23
+ ## Rules you must not break
24
+ 1. **Non-destructive.** Never overwrite or delete a file pyaisync did not generate. All writes go through `writer.apply`
25
+ (manifest + hashes) and `safefs`. If any conflict exists, nothing is written.
26
+ 2. **No network, no execution.** The package never makes network calls and never runs hooks, MCP servers or user content.
27
+ 3. **Deterministic output.** Sorted iteration, fixed formatting; `generate` twice must change nothing (`check` relies on it).
28
+ 4. **Never widen access** when importing or translating (an allow rule or tool allowlist that cannot be mapped exactly is
29
+ skipped, not approximated) and **never write literal secrets** into `.ai/` or generated files (`${VAR}` only).
30
+ 5. **Unsupported means a warning**, not a silent approximation.
31
+ 6. **Verify native formats against the official docs** before changing an adapter or importer, and record the source URL and
32
+ date in `docs/formats/README.md`. Do not rely on memory.
33
+ 7. **Everything is in English** (code, comments, docs, messages, commits).
34
+ 8. No new runtime dependencies without a strong reason.
35
+
36
+ ## Working here
37
+ - Adapters in `targets/` are pure (`Model -> Plan`); keep disk access in `writer.py`/`safefs.py`/`importers/`.
38
+ - Tests must never write outside `tmp_path`; run the CLI with `main(["--root", str(root), ...])`. Relative path options are
39
+ resolved against `--root`.
40
+ - Add tests with every behaviour change: generate output, idempotence, import round trip, and the security cases.
41
+ - Update `README.md` (scope/limitations), `docs/formats/README.md` and `docs/ARCHITECTURE.md` when behaviour or formats change.
42
+ - Do not commit unless asked. Do not push or publish anything.
pyaisync-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pyaisync contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,365 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyaisync
3
+ Version: 0.1.0
4
+ Summary: One source (.ai/) for AI coding agent configuration: generates the native files for Claude Code, Cursor and OpenCode.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: pyyaml>=6.0
9
+ Description-Content-Type: text/markdown
10
+
11
+ # pyaisync
12
+
13
+ One source (`.ai/`) for the AI coding agent configuration of a repository.
14
+ `pyaisync` transpiles it into the native files of **Claude Code**, **Cursor** and **OpenCode**.
15
+
16
+ ## Installation
17
+
18
+ **Requirements:** Python 3.11 or newer and [`uv`](https://docs.astral.sh/uv/). `pyaisync` is not on PyPI yet, so it is
19
+ installed from GitHub. Its only runtime dependency is `PyYAML`.
20
+
21
+ ### Add it to your project (recommended)
22
+
23
+ Install it as a **development dependency** of the Python project whose AI configuration you want to manage:
24
+
25
+ ```bash
26
+ uv add --dev git+https://github.com/AbdielFco/pyaisync
27
+ uv run pyaisync --version
28
+ ```
29
+
30
+ This records it in your `pyproject.toml` (`dependency-groups.dev` plus a `tool.uv.sources` entry) and **pins the exact
31
+ commit in `uv.lock`**, so everyone on the team and your CI get the same version after `uv sync`. Commit both files.
32
+ To pin a release instead of the latest commit, add a tag or commit: `uv add --dev git+https://github.com/AbdielFco/pyaisync --rev <tag-or-commit>`.
33
+ To update: `uv lock --upgrade-package pyaisync && uv sync`.
34
+
35
+ Then use it as `uv run pyaisync ...` (see the quick start below).
36
+
37
+ <details>
38
+ <summary>Other ways to install</summary>
39
+
40
+ - **Without installing anything:** `uvx --from git+https://github.com/AbdielFco/pyaisync pyaisync --help`
41
+ - **As a global command:** `uv tool install git+https://github.com/AbdielFco/pyaisync` (then run `pyaisync ...` directly;
42
+ update with `uv tool upgrade pyaisync`, remove with `uv tool uninstall pyaisync`).
43
+ - **With pip / a requirements file:** `pip install git+https://github.com/AbdielFco/pyaisync.git`, or add
44
+ `pyaisync @ git+https://github.com/AbdielFco/pyaisync.git` to `requirements-dev.txt`.
45
+ - **From a clone (to work on pyaisync itself):** `git clone https://github.com/AbdielFco/pyaisync.git && cd pyaisync && uv sync`.
46
+
47
+ </details>
48
+
49
+ ## Getting started
50
+
51
+ `pyaisync` has one source of truth, the `.ai/` folder. You edit `.ai/`; `generate` writes the files each tool reads
52
+ (`CLAUDE.md`, `.cursor/`, `AGENTS.md`, `.mcp.json`, ...). Never edit those generated files by hand.
53
+
54
+ ```mermaid
55
+ flowchart TD
56
+ A{"Does the repo already have AI config?<br/>(CLAUDE.md, .cursor/, opencode.json, .mcp.json, hooks...)"}
57
+ A -- "No: new project" --> N1["uv run pyaisync init"]
58
+ N1 --> N2["edit the examples in .ai/<br/>and add what you need"]
59
+ A -- "Yes" --> E1["uv run pyaisync init --from claude<br/>(or cursor / opencode)"]
60
+ E1 --> E2["import the other tools you use:<br/>uv run pyaisync import cursor"]
61
+ E2 --> E3["read the warnings: they list<br/>everything that was NOT imported"]
62
+ N2 --> G1
63
+ E3 --> G1["uv run pyaisync generate --dry-run<br/>(preview)"]
64
+ G1 --> G2["uv run pyaisync generate<br/>(first time on existing files: add --adopt)"]
65
+ G2 --> G3["commit .ai/ and the generated files"]
66
+ G3 --> C["CI / pre-commit: uv run pyaisync check<br/>fails if generated files drifted"]
67
+ G3 --> D["later changes: edit .ai/ -> generate"]
68
+ ```
69
+
70
+ ### A. New project
71
+
72
+ ```bash
73
+ uv run pyaisync init # creates .ai/ with an example rule and command
74
+ # edit .ai/rules/*.md, add .ai/commands/*.md, .ai/agents/*.md, .ai/mcp.toml, ...
75
+ uv run pyaisync generate --dry-run # preview
76
+ uv run pyaisync generate # writes CLAUDE.md, .cursor/, AGENTS.md, ...
77
+ ```
78
+
79
+ ### B. A repo that already has configuration
80
+
81
+ ```bash
82
+ uv run pyaisync init --from claude # creates .ai/ and imports CLAUDE.md, .claude/*, .mcp.json, settings hooks/permissions
83
+ uv run pyaisync import cursor # repeat for every other tool you use (cursor, opencode)
84
+ uv run pyaisync generate --dry-run # shows what will be created and which of your entries get replaced
85
+ uv run pyaisync generate --adopt # first time only: take over your existing files (it refuses without --adopt)
86
+ ```
87
+
88
+ `import` never changes your files; it only writes to `.ai/`, and it **tells you everything it could not carry over**.
89
+ After the first `generate --adopt`, the generated files are owned by pyaisync: edit `.ai/` from then on. Your own
90
+ entries in shared JSON files (`.mcp.json`, `.claude/settings.json`, `opencode.json`, ...) are never touched.
91
+
92
+ ### Choose which tools to generate for
93
+
94
+ The tools are the `targets` list in `.ai/config.toml`; `generate` and `check` print which ones are enabled.
95
+
96
+ ```toml
97
+ # .ai/config.toml
98
+ targets = ["claude", "cursor", "opencode"]
99
+ ```
100
+
101
+ `init` fills it with the tools it **finds in the repo** (for example only `cursor` if you only have `.cursor/`), or all
102
+ three in an empty repo. To change it, use the command instead of editing the file:
103
+
104
+ ```bash
105
+ uv run pyaisync target add claude # enable Claude Code (also: cursor, opencode; several at once)
106
+ uv run pyaisync target remove cursor # disable one (the next generate removes only what pyaisync generated for it)
107
+ uv run pyaisync list # shows which tools are enabled and what each one supports
108
+ uv run pyaisync generate # apply
109
+ ```
110
+
111
+ `target add` also tells you when that tool already has configuration in the repo, so you can bring it in with
112
+ `pyaisync import <tool>` first. To try a tool once without changing the config, pass `--targets claude` to `generate`. Skills are written once, to `.claude/skills/` when `claude` is enabled and otherwise to
113
+ `.agents/skills/` (that is why a repo without `claude` gets `.agents/`).
114
+
115
+ ### Day to day
116
+
117
+ ```bash
118
+ # edit anything in .ai/, then:
119
+ uv run pyaisync generate
120
+ git add -A && git commit
121
+ ```
122
+
123
+ ### What goes where in `.ai/`
124
+
125
+ | You want to define | Put it in | It becomes |
126
+ |---|---|---|
127
+ | Project instructions | `.ai/rules/*.md` | `CLAUDE.md`, `AGENTS.md`, `.cursor/rules/*.mdc` |
128
+ | Prompt shortcuts | `.ai/commands/*.md` | `.claude/commands/`, `.cursor/commands/`, `.opencode/commands/` |
129
+ | Subagents | `.ai/agents/*.md` | `.claude/agents/`, `.cursor/agents/`, `.opencode/agents/` |
130
+ | Skills (with their files) | `.ai/skills/<name>/SKILL.md` | `.claude/skills/<name>/` (all three tools read it) |
131
+ | MCP servers | `.ai/mcp.toml` | `.mcp.json`, `.cursor/mcp.json`, `opencode.json` |
132
+ | Hooks (when and what runs) | `.ai/hooks.toml` | `.claude/settings.json`, `.cursor/hooks.json` |
133
+ | **Hook scripts** (`gates.py`, `format.sh`, ...) | `.ai/hooks/` | **not copied**: hooks run them in place, see below |
134
+ | Permissions | `.ai/permissions.toml` | `.claude/settings.json`, `.cursor/cli.json`, `opencode.json` |
135
+
136
+ ### Hook scripts
137
+
138
+ A hook is a **command**; `.ai/hooks.toml` says when it runs, and the script it runs lives in `.ai/hooks/`:
139
+
140
+ ```toml
141
+ # .ai/hooks.toml
142
+ [[hooks]]
143
+ event = "before_shell_execution" # Cursor-only event: use `pattern` (a regex) to filter
144
+ pattern = "git push|rm "
145
+ command = "python3 .ai/hooks/gates.py"
146
+ fail_closed = true # Cursor: block the action if the hook itself fails
147
+ timeout = 10
148
+ ```
149
+
150
+ The script stays in `.ai/hooks/gates.py` and every tool runs it from there: Cursor from the project root, and for
151
+ Claude Code `pyaisync` writes `"${CLAUDE_PROJECT_DIR}"/.ai/hooks/gates.py` so it works from any directory.
152
+ Nothing is copied, so there is no second version to drift.
153
+
154
+ When you **import** hooks, the scripts their commands run (from `.cursor/hooks/`, `.claude/hooks/`, `.opencode/` or `hooks/`)
155
+ are **copied** into `.ai/hooks/` (permissions kept) and the commands are rewritten to point at the copies. Your original files
156
+ are left alone; delete them when you are satisfied. If a script needs other files from its folder (helpers, config),
157
+ `import` lists them: copy those to `.ai/hooks/` yourself.
158
+
159
+ The plan this project implements is [PLAN.md](PLAN.md).
160
+
161
+ ## How it works
162
+
163
+ ```mermaid
164
+ flowchart LR
165
+ subgraph SRC[".ai/ (single source, committed)"]
166
+ direction TB
167
+ S1["config.toml"]
168
+ S2["rules, commands, agents<br/>(Markdown + frontmatter)"]
169
+ S3["skills/ (SKILL.md)"]
170
+ S4["mcp, hooks, permissions<br/>(TOML)"]
171
+ end
172
+
173
+ SRC -->|"loader: parse + validate"| M["Model<br/>(frozen dataclasses)"]
174
+ M --> A{"adapter per target"}
175
+ A --> C["Claude Code"]
176
+ A --> U["Cursor"]
177
+ A --> O["OpenCode"]
178
+ C --> P["Plan<br/>files + JSON merges<br/>+ warnings + hook notices"]
179
+ U --> P
180
+ O --> P
181
+ P --> W{"writer<br/>(manifest + hashes)"}
182
+ W -->|"generate"| D["native files on disk"]
183
+ W -->|"generate --dry-run / check"| R["diff / drift report<br/>(exit 1 on drift)"]
184
+
185
+ N["native config<br/>(CLAUDE.md, .mcp.json, ...)"] -->|"import"| SRC
186
+ SRC -->|"plugin claude"| G["dist/&lt;name&gt;/<br/>Claude Code plugin"]
187
+ ```
188
+
189
+ What the writer does with each file it is about to write (any conflict aborts **before** anything is written):
190
+
191
+ ```mermaid
192
+ flowchart TD
193
+ F["planned file or JSON entry"] --> X{"exists on disk?"}
194
+ X -- no --> CR["create"]
195
+ X -- yes --> Q{"same content?"}
196
+ Q -- yes --> UN["unchanged<br/>(becomes owned)"]
197
+ Q -- no --> MG{"in the manifest?"}
198
+ MG -- "no (not ours)" --> AD{"--adopt or --force?"}
199
+ AD -- yes --> UP["update"]
200
+ AD -- no --> CF["CONFLICT<br/>nothing is written"]
201
+ MG -- yes --> HE{"disk still matches<br/>the recorded hash?"}
202
+ HE -- yes --> UP
203
+ HE -- "no (hand edited)" --> FO{"--force?"}
204
+ FO -- yes --> UP
205
+ FO -- no --> CF
206
+ ```
207
+
208
+ Typical workflow: `init` (or `init --from <tool>` to migrate an existing setup) -> edit `.ai/` -> `generate` ->
209
+ commit both; `check` in CI or a pre-commit hook fails when the generated files drift from `.ai/`.
210
+
211
+ ## Usage
212
+
213
+ The examples below use `uv run pyaisync`, which works when it is a dependency of your project. If you installed it
214
+ as a global command (`uv tool install`), drop the `uv run` prefix.
215
+
216
+ ```bash
217
+ uv run pyaisync init # create .ai/ (detects existing targets)
218
+ uv run pyaisync init --from claude # init + import CLAUDE.md, .claude/commands and skills
219
+ uv run pyaisync generate --dry-run # preview what would change
220
+ uv run pyaisync generate # write the native files
221
+ uv run pyaisync check # CI / pre-commit: fails on drift
222
+ uv run pyaisync list # support matrix
223
+ uv run pyaisync import cursor # bring Cursor's native config into .ai/
224
+ uv run pyaisync plugin claude # package .ai/ as a Claude Code plugin (dist/<name>)
225
+ ```
226
+
227
+ From another project: `uvx --from /path/to/pyaisync pyaisync check`.
228
+
229
+ ## What it generates
230
+
231
+ | Source `.ai/` | Claude Code | Cursor | OpenCode |
232
+ |---|---|---|---|
233
+ | `rules/*.md` | `CLAUDE.md` | `.cursor/rules/<n>.mdc` | `AGENTS.md` |
234
+ | `commands/*.md` | `.claude/commands/<n>.md` | `.cursor/commands/<n>.md` | `.opencode/commands/<n>.md` |
235
+ | `skills/<n>/` | `.claude/skills/<n>/` (all 3 read it) | ← same | ← same |
236
+ | `agents/*.md` | `.claude/agents/<n>.md` | `.cursor/agents/<n>.md` | `.opencode/agents/<n>.md` |
237
+ | `mcp.toml` | `.mcp.json` (`mcpServers`) | `.cursor/mcp.json` (`mcpServers`) | `opencode.json` (`mcp.servers`) |
238
+ | `hooks.toml` | `.claude/settings.json` (`hooks`) | `.cursor/hooks.json` | not supported (warning) |
239
+ | `permissions.toml` | `.claude/settings.json` (`permissions`) | `.cursor/cli.json` (CLI only, no `ask`) | `opencode.json` (`permissions`) |
240
+
241
+ If Claude is not among the targets, skills go to `.agents/skills/` (read by Cursor and OpenCode).
242
+
243
+ ## Subagents and MCP
244
+
245
+ ```markdown
246
+ <!-- .ai/agents/reviewer.md -->
247
+ ---
248
+ description: Read-only code reviewer
249
+ tools: [read, grep, glob] # read, grep, glob, edit, shell, web (omit = inherit all)
250
+ ---
251
+ You are a strict reviewer. Do not modify files.
252
+ ```
253
+
254
+ ```toml
255
+ # .ai/mcp.toml
256
+ [servers.docs]
257
+ type = "http" # stdio | http | sse
258
+ url = "https://example.com/mcp"
259
+ headers = { Authorization = "Bearer ${DOCS_TOKEN}" } # secrets only as ${VAR}
260
+ ```
261
+
262
+ MCP entries are **merged** into `.mcp.json`, `.cursor/mcp.json` and `opencode.json`: your own entries
263
+ are kept, and only the ones pyaisync generated are updated or removed. Files with comments (JSONC)
264
+ are refused instead of rewritten. OpenCode support targets the **V2** config schema.
265
+
266
+ ## Hooks and permissions
267
+
268
+ ```toml
269
+ # .ai/hooks.toml — hooks run COMMANDS on your machine; review them like code
270
+ [[hooks]]
271
+ event = "pre_tool_use"
272
+ matcher = ["shell"] # read, grep, glob, edit, shell, web
273
+ command = "./scripts/guard.sh" # one line, relative to the repository root
274
+
275
+ # .ai/permissions.toml
276
+ allow = ["shell(uv run pytest*)"]
277
+ ask = ["shell(git push*)"]
278
+ deny = ["read(.env*)", "shell(rm -rf*)"]
279
+ ```
280
+
281
+ Besides the events both tools share (`session_start`, `session_end`, `pre_tool_use`, `post_tool_use`,
282
+ `post_tool_use_failure`, `user_prompt_submit`, `stop`, `subagent_start`, `subagent_stop`, `pre_compact`), there are
283
+ Claude-only (`notification`) and Cursor-only events (`before_shell_execution`, `after_shell_execution`, `before_read_file`,
284
+ `after_file_edit`, `before_mcp_execution`, `after_mcp_execution`, `after_agent_response`, `after_agent_thought`).
285
+ An event that only one tool has is skipped, with a warning, for the other.
286
+
287
+ `generate` and `check` print every hook command that will run. Rules or hooks a target cannot express
288
+ (Cursor has no `ask`; OpenCode has no declarative hooks) are skipped **with a warning**, never approximated.
289
+ Your own entries in `.claude/settings.json`, `.cursor/hooks.json`, etc. are preserved.
290
+
291
+ ## Import
292
+
293
+ `import <claude|cursor|opencode>` reads the native files and writes only to `.ai/`: rules, commands, skills,
294
+ **subagents, MCP servers, hooks and permissions**. It reports everything it cannot map, never widens access
295
+ (an allow rule or tool allowlist that cannot be mapped exactly is skipped) and **never copies a literal secret**:
296
+ sensitive values become `${VAR}` references and the warning tells you which variable to set. Entries pyaisync generated
297
+ itself are not re-imported. Conflicts: `--on-conflict skip|rename|overwrite`.
298
+
299
+ ## Claude Code plugin
300
+
301
+ ```toml
302
+ # .ai/config.toml
303
+ [plugin]
304
+ name = "my-tools" # kebab-case; names starting with claude-/anthropic- are reserved
305
+ version = "1.0.0"
306
+ description = "Team tools"
307
+ ```
308
+
309
+ `pyaisync plugin claude` writes `dist/my-tools/` (`.claude-plugin/plugin.json`, `commands/`, `agents/`, `skills/`,
310
+ `hooks/hooks.json`, `.mcp.json`). Rules and permissions cannot be part of a plugin and hook scripts are not bundled;
311
+ both are reported. Same non-destructive rules as `generate`.
312
+
313
+ ## Scope and limitations
314
+
315
+ ### In scope
316
+ - **Targets:** Claude Code, Cursor and OpenCode (V2 config schema), at **project level** only.
317
+ - **Features:** rules, commands, skills, subagents, MCP servers, hooks, permissions; `import` of all of them; a
318
+ Claude Code plugin package.
319
+ - **Guarantees:** deterministic output, no network access, nothing from your content is ever executed, and files it did
320
+ not generate are never overwritten.
321
+
322
+ ### Not in scope
323
+ - More targets (Windsurf, Copilot, Gemini, ...). Adding one means writing an adapter and an importer.
324
+ - User-level/global configuration (`~/.claude`, `~/.cursor`, `~/.config/opencode`).
325
+ - Downloading rules or skills from remote repositories.
326
+ - Running agents, hooks or MCP servers, or two-way/continuous sync (`import` is a one-off migration).
327
+ - Cursor and OpenCode plugin packaging. OpenCode plugins are JS/TS code, not configuration; Cursor's plugin format
328
+ was not verified. `plugin` exists for Claude Code only.
329
+
330
+ ### Differences between targets
331
+ Features a target cannot express are skipped **with a warning**, never approximated:
332
+
333
+ | Feature | Limitation |
334
+ |---|---|
335
+ | Hooks | OpenCode has no declarative hooks (skipped). Cursor cannot match `glob`/`web` tools (that hook is skipped for Cursor). Events that exist in one tool only are skipped for the other. `fail_closed` and `pattern` are Cursor-only (`fail_closed` is warned about for Claude). Cursor's `loop_limit`, prompt hooks and Tab hooks are not imported. |
336
+ | Permissions | Cursor's apply to the **Cursor CLI only** (`.cursor/cli.json`) and have no `ask`. Claude cannot express path rules for `grep`/`glob`. |
337
+ | Subagents | Cursor has no tool allowlist: only `readonly` is derived from `tools`. A non-`inherit` `model` is passed through verbatim and warned about, because model names differ per tool. |
338
+ | MCP | OpenCode V2 offers only Streamable HTTP, so `sse` servers are skipped for it. |
339
+ | Rules | Claude and OpenCode read a single instructions file, so scoped rules (`globs`/`description`) become labelled sections instead of being conditionally applied. |
340
+ | Plugin | Cannot carry project rules (a `CLAUDE.md` in a plugin is not loaded) or permissions. Hook scripts are not bundled. |
341
+
342
+ ### Known technical limits
343
+ - **JSONC is refused.** `opencode.json`, `.mcp.json`, `settings.json` and similar files that contain comments are not
344
+ merged (that would destroy the comments). Remove the comments or manage those files by hand.
345
+ - **Hook scripts' neighbours.** `import` copies the scripts a hook command names, not the other files they may read.
346
+ - **JSON formatting.** A shared JSON file is rewritten with 2-space indentation, only when one of its entries changes.
347
+ - **List items are matched by content.** If you edit by hand a hook or permission that pyaisync added, it stops being
348
+ recognised as generated: it is treated as yours and the regenerated item is added next to it.
349
+ - **OpenCode V1** config (`mcp.<name>`, `permission`, `tools`) is neither generated nor imported.
350
+ - **Import is best effort and conservative.** It skips what it cannot map exactly (regex hook matchers, non-command
351
+ hooks, `disallowedTools`, order-dependent OpenCode rules, WebSocket MCP servers) and reports it. It does not split a
352
+ large `CLAUDE.md`/`AGENTS.md`: it becomes one always-on rule.
353
+ - **Formats move fast.** The native formats were checked against the official docs on 2026-11-25. The one entry not
354
+ confirmed in the docs is Cursor's `.cursor/commands/*.md`; see `docs/formats/README.md` before relying on it.
355
+ - **Python 3.11+** is required (`tomllib`).
356
+
357
+ ## Safety
358
+
359
+ - No network access; nothing from the content is ever executed.
360
+ - Never overwrites files it did not generate (manifest with hashes in `.ai/.manifest.json`).
361
+ - Rejects names containing `..`, absolute paths and symlinks.
362
+ - Rejects literal secrets in `mcp.toml` (sensitive-looking keys must use `${VAR}`).
363
+
364
+ Development: `uv run pytest`, `uv run ruff check .`, `uv run mypy`. Contributors and AI agents: see
365
+ [AGENTS.md](AGENTS.md) and [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).