importfrommyharness 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.
- importfrommyharness-0.1.0/LICENSE +21 -0
- importfrommyharness-0.1.0/PKG-INFO +58 -0
- importfrommyharness-0.1.0/README.md +44 -0
- importfrommyharness-0.1.0/pyproject.toml +31 -0
- importfrommyharness-0.1.0/pyproject.toml.orig +24 -0
- importfrommyharness-0.1.0/src/importfrommyharness/__init__.py +98 -0
- importfrommyharness-0.1.0/src/importfrommyharness/engine.py +391 -0
- importfrommyharness-0.1.0/src/importfrommyharness/harnesses/claude.toml +66 -0
- importfrommyharness-0.1.0/src/importfrommyharness/harnesses/opencode+oh-my-opencode-slim.toml +20 -0
- importfrommyharness-0.1.0/src/importfrommyharness/harnesses/opencode.toml +113 -0
- importfrommyharness-0.1.0/src/importfrommyharness/setup.py +73 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 shulkwisec
|
|
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,58 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: importfrommyharness
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Import config from one AI-coding harness into another
|
|
5
|
+
Keywords: opencode,claude-code,migration,ai-coding,agents,mcp
|
|
6
|
+
Author: shulkwisec
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: pyyaml>=6
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Project-URL: Homepage, https://github.com/ShulkwiSEC/ImportFromMyHarness
|
|
12
|
+
Project-URL: Issues, https://github.com/ShulkwiSEC/ImportFromMyHarness/issues
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# ImportFromMyHarness
|
|
16
|
+
|
|
17
|
+
**Move an opencode project into Claude Code in one command.** It converts instructions, rules, skills, agents, MCP servers and `oh-my-opencode-slim` agents, and lists whatever it couldn't convert instead of silently dropping it.
|
|
18
|
+
|
|
19
|
+
| Direction | Status |
|
|
20
|
+
|---|---|
|
|
21
|
+
| opencode → Claude Code | supported and tested |
|
|
22
|
+
| Claude Code → opencode | experimental: mappings exist, not tested yet |
|
|
23
|
+
| Other harnesses | add one TOML file ([how](#add-a-harness)) |
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
curl -fsSL https://raw.githubusercontent.com/ShulkwiSEC/ImportFromMyHarness/main/install.sh | sh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
It checks for [uv](https://docs.astral.sh/uv/) (and offers to install it), installs the tool, then offers a guided first run. No sudo; re-running upgrades. Flags: `sh -s -- -y` (no questions), `sh -s -- --no-setup`. Or without the script: `uvx importfrommyharness` (run once) or `uv tool install importfrommyharness`.
|
|
34
|
+
|
|
35
|
+
## Use
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
importfrommyharness # guided setup (in a terminal)
|
|
39
|
+
importfrommyharness scan opencode:~/my-project
|
|
40
|
+
importfrommyharness import opencode:~/my-project --to claude # dry run
|
|
41
|
+
importfrommyharness import opencode:~/my-project --to claude --apply # write
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Options: `--out DIR` (default: the source path), `--only skill,mcp`, `--json`.
|
|
45
|
+
Exit codes: 0 ok, 1 error, 2 bad usage, 3 done, with lossy or unmapped items (see report).
|
|
46
|
+
|
|
47
|
+
## What you get
|
|
48
|
+
- Dry run by default. Existing JSON entries are never overwritten; existing files that change get a `.bak`.
|
|
49
|
+
- Things with no safe equivalent (npm plugins, permission rules, hooks, plugin config) are saved under `.importfrommyharness/unmapped/` and listed in the report, never dropped silently.
|
|
50
|
+
- Literal secrets in MCP env/headers are replaced with `${NAME}` references; `.env` is never read.
|
|
51
|
+
- `opencode` modes become Claude agents; `default_agent` becomes `"agent"` in `.claude/settings.json`.
|
|
52
|
+
- Scriptable: `--json` report on stdout, messages on stderr, no prompts outside `setup`.
|
|
53
|
+
|
|
54
|
+
## Add a harness
|
|
55
|
+
Drop one file in `src/importfrommyharness/harnesses/<name>.toml`: a `name`, a `detect` list, and `[[item]]` rows (`kind`, `path`, `fmt`, optional `map`/`xform`/`docs`). Copy `claude.toml` as a template. A plugin pack sets `host` and `origin` instead of `name` (see `opencode+oh-my-opencode-slim.toml`). No Python changes unless you need a new field transform (add it to `XF` in `engine.py`).
|
|
56
|
+
|
|
57
|
+
## Tests
|
|
58
|
+
`uv run python -m unittest discover tests`
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# ImportFromMyHarness
|
|
2
|
+
|
|
3
|
+
**Move an opencode project into Claude Code in one command.** It converts instructions, rules, skills, agents, MCP servers and `oh-my-opencode-slim` agents, and lists whatever it couldn't convert instead of silently dropping it.
|
|
4
|
+
|
|
5
|
+
| Direction | Status |
|
|
6
|
+
|---|---|
|
|
7
|
+
| opencode → Claude Code | supported and tested |
|
|
8
|
+
| Claude Code → opencode | experimental: mappings exist, not tested yet |
|
|
9
|
+
| Other harnesses | add one TOML file ([how](#add-a-harness)) |
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
curl -fsSL https://raw.githubusercontent.com/ShulkwiSEC/ImportFromMyHarness/main/install.sh | sh
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
It checks for [uv](https://docs.astral.sh/uv/) (and offers to install it), installs the tool, then offers a guided first run. No sudo; re-running upgrades. Flags: `sh -s -- -y` (no questions), `sh -s -- --no-setup`. Or without the script: `uvx importfrommyharness` (run once) or `uv tool install importfrommyharness`.
|
|
20
|
+
|
|
21
|
+
## Use
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
importfrommyharness # guided setup (in a terminal)
|
|
25
|
+
importfrommyharness scan opencode:~/my-project
|
|
26
|
+
importfrommyharness import opencode:~/my-project --to claude # dry run
|
|
27
|
+
importfrommyharness import opencode:~/my-project --to claude --apply # write
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Options: `--out DIR` (default: the source path), `--only skill,mcp`, `--json`.
|
|
31
|
+
Exit codes: 0 ok, 1 error, 2 bad usage, 3 done, with lossy or unmapped items (see report).
|
|
32
|
+
|
|
33
|
+
## What you get
|
|
34
|
+
- Dry run by default. Existing JSON entries are never overwritten; existing files that change get a `.bak`.
|
|
35
|
+
- Things with no safe equivalent (npm plugins, permission rules, hooks, plugin config) are saved under `.importfrommyharness/unmapped/` and listed in the report, never dropped silently.
|
|
36
|
+
- Literal secrets in MCP env/headers are replaced with `${NAME}` references; `.env` is never read.
|
|
37
|
+
- `opencode` modes become Claude agents; `default_agent` becomes `"agent"` in `.claude/settings.json`.
|
|
38
|
+
- Scriptable: `--json` report on stdout, messages on stderr, no prompts outside `setup`.
|
|
39
|
+
|
|
40
|
+
## Add a harness
|
|
41
|
+
Drop one file in `src/importfrommyharness/harnesses/<name>.toml`: a `name`, a `detect` list, and `[[item]]` rows (`kind`, `path`, `fmt`, optional `map`/`xform`/`docs`). Copy `claude.toml` as a template. A plugin pack sets `host` and `origin` instead of `name` (see `opencode+oh-my-opencode-slim.toml`). No Python changes unless you need a new field transform (add it to `XF` in `engine.py`).
|
|
42
|
+
|
|
43
|
+
## Tests
|
|
44
|
+
`uv run python -m unittest discover tests`
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "importfrommyharness"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Import config from one AI-coding harness into another"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
keywords = [
|
|
9
|
+
"opencode",
|
|
10
|
+
"claude-code",
|
|
11
|
+
"migration",
|
|
12
|
+
"ai-coding",
|
|
13
|
+
"agents",
|
|
14
|
+
"mcp",
|
|
15
|
+
]
|
|
16
|
+
requires-python = ">=3.12"
|
|
17
|
+
dependencies = ["pyyaml>=6"]
|
|
18
|
+
|
|
19
|
+
[[project.authors]]
|
|
20
|
+
name = "shulkwisec"
|
|
21
|
+
|
|
22
|
+
[project.scripts]
|
|
23
|
+
importfrommyharness = "importfrommyharness:main"
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/ShulkwiSEC/ImportFromMyHarness"
|
|
27
|
+
Issues = "https://github.com/ShulkwiSEC/ImportFromMyHarness/issues"
|
|
28
|
+
|
|
29
|
+
[build-system]
|
|
30
|
+
requires = ["uv_build>=0.12.0,<0.13.0"]
|
|
31
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "importfrommyharness"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Import config from one AI-coding harness into another"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
keywords = ["opencode", "claude-code", "migration", "ai-coding", "agents", "mcp"]
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "shulkwisec" }
|
|
11
|
+
]
|
|
12
|
+
requires-python = ">=3.12"
|
|
13
|
+
dependencies = ["pyyaml>=6"]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
importfrommyharness = "importfrommyharness:main"
|
|
17
|
+
|
|
18
|
+
[build-system]
|
|
19
|
+
requires = ["uv_build>=0.12.0,<0.13.0"]
|
|
20
|
+
build-backend = "uv_build"
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/ShulkwiSEC/ImportFromMyHarness"
|
|
24
|
+
Issues = "https://github.com/ShulkwiSEC/ImportFromMyHarness/issues"
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""importfrommyharness: import config from one AI-coding harness into another."""
|
|
2
|
+
import argparse
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from collections import Counter
|
|
6
|
+
from importlib.metadata import version
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from . import engine, setup
|
|
10
|
+
|
|
11
|
+
EPILOG = """examples:
|
|
12
|
+
importfrommyharness list
|
|
13
|
+
importfrommyharness scan opencode:~/my-project
|
|
14
|
+
importfrommyharness import opencode:~/my-project --to claude --json # dry run
|
|
15
|
+
importfrommyharness import opencode:~/my-project --to claude --apply
|
|
16
|
+
exit codes: 0 ok, 1 error, 2 bad usage, 3 done but some items lossy/unmapped"""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _die(msg, code):
|
|
20
|
+
print(f"error: {msg}", file=sys.stderr)
|
|
21
|
+
sys.exit(code)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _source(spec, hs):
|
|
25
|
+
"""'harness:path' or just 'path' (harness auto-detected when unambiguous)."""
|
|
26
|
+
name, sep, rest = spec.partition(":")
|
|
27
|
+
if sep and name in hs:
|
|
28
|
+
return hs[name], Path(rest).expanduser()
|
|
29
|
+
root = Path(spec).expanduser()
|
|
30
|
+
found = engine.detect(hs, root)
|
|
31
|
+
if len(found) != 1:
|
|
32
|
+
_die(f"cannot tell the harness of {root} (matches: {found or 'none'}); use <harness>:<path>", 2)
|
|
33
|
+
return hs[found[0]], root
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def main(argv=None):
|
|
37
|
+
ap = argparse.ArgumentParser(prog="importfrommyharness", description=__doc__, epilog=EPILOG,
|
|
38
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
39
|
+
ap.add_argument("--version", action="version", version=version("importfrommyharness"))
|
|
40
|
+
sub = ap.add_subparsers(dest="cmd", required=True)
|
|
41
|
+
sub.add_parser("setup", help="guided interactive setup (default when run bare in a terminal)")
|
|
42
|
+
sub.add_parser("list", help="show registered harnesses and plugin packs")
|
|
43
|
+
for n, h in (("scan", "show what a source contains"), ("import", "convert source into another harness")):
|
|
44
|
+
p = sub.add_parser(n, help=h)
|
|
45
|
+
p.add_argument("src", help="<harness>:<path> or <path>")
|
|
46
|
+
p.add_argument("--json", action="store_true", help="machine-readable report on stdout")
|
|
47
|
+
if n == "import":
|
|
48
|
+
p.add_argument("--to", required=True, help="destination harness")
|
|
49
|
+
p.add_argument("--out", help="destination root (default: same as source path)")
|
|
50
|
+
p.add_argument("--only", help="comma list of kinds, e.g. skill,mcp")
|
|
51
|
+
p.add_argument("--apply", action="store_true", help="write files (default is dry run)")
|
|
52
|
+
args = sys.argv[1:] if argv is None else argv
|
|
53
|
+
if not args: # bare run: wizard for humans, help for pipes and agents
|
|
54
|
+
args = ["setup"] if sys.stdin.isatty() and sys.stdout.isatty() else ["--help"]
|
|
55
|
+
a = ap.parse_args(args)
|
|
56
|
+
hs, packs = engine.load_harnesses()
|
|
57
|
+
if a.cmd == "setup":
|
|
58
|
+
return setup.run(hs, packs)
|
|
59
|
+
|
|
60
|
+
if a.cmd == "list":
|
|
61
|
+
for n in sorted(hs):
|
|
62
|
+
print(n, "+", ", ".join(p["origin"] for p in packs if p["host"] == n) or "-")
|
|
63
|
+
return 0
|
|
64
|
+
|
|
65
|
+
src, root = _source(a.src, hs)
|
|
66
|
+
if not root.is_dir():
|
|
67
|
+
_die(f"not a directory: {root}", 1)
|
|
68
|
+
rep = engine.Report()
|
|
69
|
+
items = engine.read(src, packs, root, rep)
|
|
70
|
+
|
|
71
|
+
if a.cmd == "scan":
|
|
72
|
+
c = Counter((i.kind, i.origin) for i in items)
|
|
73
|
+
out = [{"kind": k, "origin": o, "count": n} for (k, o), n in sorted(c.items())]
|
|
74
|
+
print(json.dumps(out, indent=2) if a.json else "\n".join(f"{x['kind']:<14}{x['count']:>5} {x['origin']}" for x in out))
|
|
75
|
+
return 0
|
|
76
|
+
|
|
77
|
+
if a.to not in hs:
|
|
78
|
+
_die(f"unknown harness '{a.to}' (try: list)", 2)
|
|
79
|
+
out_root = Path(a.out).expanduser() if a.out else root
|
|
80
|
+
plan = engine.build_plan(items, hs[a.to], out_root, rep, set(a.only.split(",")) if a.only else None)
|
|
81
|
+
result = rep.as_dict(plan) | {"from": src["name"], "to": a.to, "out": str(out_root), "applied": False}
|
|
82
|
+
if a.apply:
|
|
83
|
+
result["written"], result["applied"] = engine.apply(plan, out_root), True
|
|
84
|
+
if a.json:
|
|
85
|
+
print(json.dumps(result, indent=2))
|
|
86
|
+
else:
|
|
87
|
+
print(f"{src['name']} -> {a.to} ({'applied' if a.apply else 'dry run'}) out={out_root}")
|
|
88
|
+
print("mapped: ", ", ".join(f"{k}={v}" for k, v in result["mapped"].items()) or "-")
|
|
89
|
+
print("files: ", result["files"], result["by_dir"])
|
|
90
|
+
print("lossy: ", result["lossy"] or "-")
|
|
91
|
+
print("unmapped:", Counter(u["kind"] for u in rep.unmapped) or "-")
|
|
92
|
+
for n in result["notes"]:
|
|
93
|
+
print("note:", n)
|
|
94
|
+
return 3 if rep.lossy or rep.unmapped else 0
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
sys.exit(main())
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
"""Read one harness into neutral Items, write them out as another harness.
|
|
2
|
+
|
|
3
|
+
Harnesses are data: harnesses/*.toml. Nothing here knows about a specific harness.
|
|
4
|
+
Row keys: kind, name, path[#json.key], fmt, map {native: ir}, xform [..], keep, ignore,
|
|
5
|
+
default, need_body, skip_disabled, requires, set, body, docs, note.
|
|
6
|
+
"""
|
|
7
|
+
import json
|
|
8
|
+
import re
|
|
9
|
+
import tomllib
|
|
10
|
+
from collections import Counter
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from importlib import resources
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
import yaml
|
|
16
|
+
|
|
17
|
+
KIND_FALLBACK = {"mode": "agent"} # kind with no native twin -> closest concept
|
|
18
|
+
UNMAPPED = ".importfrommyharness/unmapped"
|
|
19
|
+
SECRET_KEY = re.compile(r"KEY|TOKEN|SECRET|PASS|PAT$|AUTH|CRED", re.I)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class Item:
|
|
24
|
+
kind: str
|
|
25
|
+
name: str
|
|
26
|
+
data: dict = field(default_factory=dict)
|
|
27
|
+
body: str = ""
|
|
28
|
+
files: dict = field(default_factory=dict) # rel path -> bytes (tree/raw)
|
|
29
|
+
origin: str = "docs"
|
|
30
|
+
src: str = ""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Report:
|
|
34
|
+
def __init__(self):
|
|
35
|
+
self.mapped, self.lossy = Counter(), Counter()
|
|
36
|
+
self.unmapped, self.notes = [], []
|
|
37
|
+
|
|
38
|
+
def as_dict(self, plan):
|
|
39
|
+
by_dir = Counter("/".join(p.split("/")[:2]) for p in plan)
|
|
40
|
+
return {"mapped": dict(self.mapped), "lossy": dict(self.lossy), "unmapped": self.unmapped,
|
|
41
|
+
"notes": sorted(set(self.notes)), "files": len(plan), "by_dir": dict(by_dir)}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# ---------- small format helpers ----------
|
|
45
|
+
_JSONC = re.compile(r'("(?:\\.|[^"\\])*")|//[^\n]*|/\*.*?\*/|,(?=\s*[}\]])', re.S)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def jsonc(text):
|
|
49
|
+
return json.loads(_JSONC.sub(lambda m: m.group(1) or "", text))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def split_md(text, src, rep):
|
|
53
|
+
m = re.match(r"---\r?\n(.*?)\r?\n---\r?\n?(.*)", text, re.S)
|
|
54
|
+
if not m:
|
|
55
|
+
return {}, text
|
|
56
|
+
try:
|
|
57
|
+
fm = yaml.safe_load(m[1]) or {}
|
|
58
|
+
if isinstance(fm, dict):
|
|
59
|
+
return fm, m[2]
|
|
60
|
+
except yaml.YAMLError:
|
|
61
|
+
pass
|
|
62
|
+
rep.notes.append(f"unparseable frontmatter kept as body text: {src}")
|
|
63
|
+
return {}, text
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def dig(d, dotted):
|
|
67
|
+
for k in dotted.split(".") if dotted else []:
|
|
68
|
+
d = d.get(k) if isinstance(d, dict) else None
|
|
69
|
+
return d
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def put(d, dotted, v):
|
|
73
|
+
ks = dotted.split(".")
|
|
74
|
+
for k in ks[:-1]:
|
|
75
|
+
d = d.setdefault(k, {})
|
|
76
|
+
d[ks[-1]] = v
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def json_file(root, rel):
|
|
80
|
+
for c in ([rel + "c"] if rel.endswith(".json") else []) + [rel]: # .jsonc wins
|
|
81
|
+
if (root / c).is_file():
|
|
82
|
+
return root / c
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# ---------- transforms: name -> (to_ir(native), from_ir(native)); may take rep ----------
|
|
86
|
+
_CLAUDE_TOOLS = {"webfetch": "WebFetch", "websearch": "WebSearch", "todowrite": "TodoWrite"}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _argv_in(d, rep):
|
|
90
|
+
d = dict(d)
|
|
91
|
+
if isinstance(d.get("command"), str):
|
|
92
|
+
d["command"] = [d["command"], *d.pop("args", [])]
|
|
93
|
+
return d
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _argv_out(d, rep):
|
|
97
|
+
d = dict(d)
|
|
98
|
+
if isinstance(d.get("command"), list):
|
|
99
|
+
c = d["command"]
|
|
100
|
+
d["command"] = c[0]
|
|
101
|
+
if c[1:]:
|
|
102
|
+
d["args"] = c[1:]
|
|
103
|
+
return d
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _refs_in(d, rep):
|
|
107
|
+
d = dict(d)
|
|
108
|
+
for key in ("env", "environment", "headers"):
|
|
109
|
+
out = {}
|
|
110
|
+
for k, v in (d.get(key) or {}).items():
|
|
111
|
+
v = str(v)
|
|
112
|
+
m = re.fullmatch(r"\{env:(\w+)\}", v)
|
|
113
|
+
if m:
|
|
114
|
+
v = "${%s}" % m[1]
|
|
115
|
+
elif SECRET_KEY.search(k) and not re.fullmatch(r"\$\{\w+\}", v):
|
|
116
|
+
v = "${%s}" % k # never copy a literal secret
|
|
117
|
+
rep.lossy["mcp.secret-literal-replaced"] += 1
|
|
118
|
+
out[k] = v
|
|
119
|
+
if out:
|
|
120
|
+
d[key] = out
|
|
121
|
+
return d
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _refs_oc_out(d, rep):
|
|
125
|
+
d = dict(d)
|
|
126
|
+
for key in ("environment", "headers"):
|
|
127
|
+
if key in d:
|
|
128
|
+
d[key] = {k: re.sub(r"\$\{(\w+)\}", r"{env:\1}", v) for k, v in d[key].items()}
|
|
129
|
+
return d
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _mcp_type_in(d, rep):
|
|
133
|
+
d = dict(d)
|
|
134
|
+
if d.pop("type", None) == "remote":
|
|
135
|
+
d["type"] = "http"
|
|
136
|
+
return d
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _mcp_type_out(d, rep):
|
|
140
|
+
d = dict(d)
|
|
141
|
+
d["type"] = "remote" if "url" in d else "local"
|
|
142
|
+
return d
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _tools_csv_in(d, rep):
|
|
146
|
+
d = dict(d)
|
|
147
|
+
if isinstance(d.get("tools"), str):
|
|
148
|
+
d["tools"] = [t.strip().lower() for t in d["tools"].split(",") if t.strip()]
|
|
149
|
+
return d
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _tools_csv_out(d, rep):
|
|
153
|
+
d = dict(d)
|
|
154
|
+
t = d.get("tools")
|
|
155
|
+
if isinstance(t, list):
|
|
156
|
+
if not t or "*" in t:
|
|
157
|
+
d.pop("tools") # claude: omitted = all tools
|
|
158
|
+
else:
|
|
159
|
+
d["tools"] = ", ".join(_CLAUDE_TOOLS.get(x, x.capitalize()) for x in t)
|
|
160
|
+
return d
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _tools_map_in(d, rep):
|
|
164
|
+
d = dict(d)
|
|
165
|
+
if isinstance(d.get("tools"), dict):
|
|
166
|
+
d["tools"] = [k for k, v in d["tools"].items() if v]
|
|
167
|
+
return d
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _tools_map_out(d, rep):
|
|
171
|
+
d = dict(d)
|
|
172
|
+
if isinstance(d.get("tools"), list):
|
|
173
|
+
d["tools"] = {t: True for t in d["tools"]}
|
|
174
|
+
return d
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
XF = {
|
|
178
|
+
"argv": (_argv_in, _argv_out),
|
|
179
|
+
"refs": (_refs_in, lambda d, r: d),
|
|
180
|
+
"refs_oc": (_refs_in, _refs_oc_out),
|
|
181
|
+
"mcp_type": (_mcp_type_in, _mcp_type_out),
|
|
182
|
+
"tools_csv": (_tools_csv_in, _tools_csv_out),
|
|
183
|
+
"tools_map": (_tools_map_in, _tools_map_out),
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
# ---------- registry (just reads the TOML files) ----------
|
|
188
|
+
def load_harnesses():
|
|
189
|
+
hs, packs = {}, []
|
|
190
|
+
for f in resources.files(__package__).joinpath("harnesses").iterdir():
|
|
191
|
+
if f.name.endswith(".toml"):
|
|
192
|
+
t = tomllib.loads(f.read_text(encoding="utf-8"))
|
|
193
|
+
if "host" in t:
|
|
194
|
+
packs.append(t)
|
|
195
|
+
else:
|
|
196
|
+
hs[t["name"]] = t
|
|
197
|
+
return hs, packs
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def detect(hs, root):
|
|
201
|
+
return [n for n, h in hs.items() if any((root / d).exists() for d in h.get("detect", []))]
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
# ---------- read ----------
|
|
205
|
+
def _glob(root, path):
|
|
206
|
+
if path.endswith("/"):
|
|
207
|
+
return sorted(p for p in root.glob(path.rstrip("/")) if p.is_dir())
|
|
208
|
+
return sorted(p for p in root.glob(path) if p.is_file())
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _attach_md(it, row, root, rep):
|
|
212
|
+
fm, body = {}, ""
|
|
213
|
+
main, extra = row["body"]
|
|
214
|
+
p = root / main.format(name=it.name)
|
|
215
|
+
if p.is_file():
|
|
216
|
+
fm, body = split_md(p.read_text(encoding="utf-8"), str(p), rep)
|
|
217
|
+
prompt = it.data.pop("prompt", None) # inline prompt beats the file
|
|
218
|
+
body = prompt or body
|
|
219
|
+
a = root / extra.format(name=it.name)
|
|
220
|
+
if a.is_file():
|
|
221
|
+
body += "\n\n" + split_md(a.read_text(encoding="utf-8"), str(a), rep)[1]
|
|
222
|
+
for k, v in fm.items():
|
|
223
|
+
it.data.setdefault(k, v)
|
|
224
|
+
it.body = body.strip()
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _to_ir(it, row, rep):
|
|
228
|
+
d = it.data
|
|
229
|
+
for x in row.get("xform", []):
|
|
230
|
+
d = XF[x][0](d, rep)
|
|
231
|
+
m, ignore, out = row.get("map", {}), row.get("ignore", []), {}
|
|
232
|
+
for k, v in d.items():
|
|
233
|
+
if k in m:
|
|
234
|
+
out[m[k]] = v
|
|
235
|
+
elif row.get("keep"):
|
|
236
|
+
out[k] = v
|
|
237
|
+
elif k not in ignore:
|
|
238
|
+
rep.lossy[f"{it.kind}.{k}"] += 1
|
|
239
|
+
it.data = out
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def read_row(row, root, origin, rep):
|
|
243
|
+
path, _, frag = row["path"].partition("#")
|
|
244
|
+
fmt, kind, items = row["fmt"], row["kind"], []
|
|
245
|
+
if fmt in ("json-path", "json-map", "json-map+md"):
|
|
246
|
+
p = json_file(root, path)
|
|
247
|
+
v = dig(jsonc(p.read_text(encoding="utf-8")), frag) if p else None
|
|
248
|
+
if v is None:
|
|
249
|
+
return []
|
|
250
|
+
if fmt == "json-path":
|
|
251
|
+
return [Item(kind, row["name"], {"value": v}, origin=origin, src=str(p))]
|
|
252
|
+
for n, e in v.items():
|
|
253
|
+
it = Item(kind, n, dict(e), origin=origin, src=f"{p}#{frag}")
|
|
254
|
+
if fmt == "json-map+md":
|
|
255
|
+
_attach_md(it, row, root, rep)
|
|
256
|
+
_to_ir(it, row, rep)
|
|
257
|
+
items.append(it)
|
|
258
|
+
return items
|
|
259
|
+
for p in _glob(root, path):
|
|
260
|
+
name = p.name if p.is_dir() else (p.stem if "*" in path else row.get("name") or str(p.relative_to(root)))
|
|
261
|
+
it = Item(kind, name, origin=origin, src=str(p))
|
|
262
|
+
if fmt == "tree":
|
|
263
|
+
it.files = {str(f.relative_to(p)): f.read_bytes() for f in p.rglob("*")
|
|
264
|
+
if f.is_file() and "__pycache__" not in f.parts}
|
|
265
|
+
elif fmt == "raw":
|
|
266
|
+
it.files = {p.name: p.read_bytes()}
|
|
267
|
+
else: # md
|
|
268
|
+
it.data, it.body = split_md(p.read_text(encoding="utf-8"), str(p), rep)
|
|
269
|
+
_to_ir(it, row, rep)
|
|
270
|
+
items.append(it)
|
|
271
|
+
return items
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def read(h, packs, root, rep):
|
|
275
|
+
rows = [(r, "docs") for r in h["item"]]
|
|
276
|
+
for p in packs:
|
|
277
|
+
if p["host"] == h["name"] and any((root / d).exists() for d in p["detect"]):
|
|
278
|
+
rows += [(r, p["origin"]) for r in p["item"]]
|
|
279
|
+
return [it for r, o in rows for it in read_row(r, root, o, rep)]
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
# ---------- write (builds a plan: relpath -> content; nothing touches disk) ----------
|
|
283
|
+
def _from_ir(it, row, rep):
|
|
284
|
+
m = {v: k for k, v in row.get("map", {}).items()}
|
|
285
|
+
ignore, out = row.get("ignore", []), {}
|
|
286
|
+
for k, v in it.data.items():
|
|
287
|
+
if k in m:
|
|
288
|
+
out[m[k]] = v
|
|
289
|
+
elif row.get("keep"):
|
|
290
|
+
out[k] = v
|
|
291
|
+
elif k not in ignore:
|
|
292
|
+
rep.lossy[f"->{row['kind']}.{k}"] += 1
|
|
293
|
+
for x in reversed(row.get("xform", [])):
|
|
294
|
+
out = XF[x][1](out, rep)
|
|
295
|
+
for k, v in row.get("default", {}).items():
|
|
296
|
+
out.setdefault(k, v.format(name=it.name) if isinstance(v, str) else v)
|
|
297
|
+
return out
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def _unmapped(it, why, plan, rep):
|
|
301
|
+
rep.unmapped.append({"kind": it.kind, "name": it.name, "origin": it.origin, "why": why})
|
|
302
|
+
base = f"{UNMAPPED}/{it.kind}/{it.name}"
|
|
303
|
+
if it.files:
|
|
304
|
+
for rel, b in it.files.items():
|
|
305
|
+
plan[f"{UNMAPPED}/{it.kind}/{rel}" if len(it.files) == 1 else f"{base}/{rel}"] = b
|
|
306
|
+
else:
|
|
307
|
+
plan[base + ".json"] = json.dumps({"data": it.data, "body": it.body, "src": it.src}, indent=2)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def build_plan(items, dst, out_root, rep, only=None):
|
|
311
|
+
plan, docs = {}, {}
|
|
312
|
+
rows = {}
|
|
313
|
+
for r in dst["item"]:
|
|
314
|
+
rows.setdefault((r["kind"], r.get("name")), r)
|
|
315
|
+
|
|
316
|
+
def doc(rel):
|
|
317
|
+
if rel not in docs:
|
|
318
|
+
p = json_file(out_root, rel) or out_root / rel
|
|
319
|
+
docs[rel] = jsonc(p.read_text(encoding="utf-8")) if p.is_file() else {}
|
|
320
|
+
return docs[rel]
|
|
321
|
+
|
|
322
|
+
for it in items:
|
|
323
|
+
if only and it.kind not in only:
|
|
324
|
+
continue
|
|
325
|
+
row = rows.get((it.kind, it.name)) or rows.get((it.kind, None))
|
|
326
|
+
if not row and it.kind in KIND_FALLBACK:
|
|
327
|
+
row = rows.get((KIND_FALLBACK[it.kind], None))
|
|
328
|
+
if row:
|
|
329
|
+
rep.notes.append(f"{dst['name']} has no '{it.kind}'; imported as '{row['kind']}'")
|
|
330
|
+
if not row:
|
|
331
|
+
_unmapped(it, f"no equivalent in {dst['name']}", plan, rep)
|
|
332
|
+
continue
|
|
333
|
+
path, _, frag = row["path"].partition("#")
|
|
334
|
+
fmt, dest = row["fmt"], path.replace("*", it.name)
|
|
335
|
+
if row.get("note"):
|
|
336
|
+
rep.notes.append(f"{it.kind} '{it.name}': {row['note']}")
|
|
337
|
+
if fmt in ("tree", "raw"):
|
|
338
|
+
for rel, b in it.files.items():
|
|
339
|
+
plan[f"{dest.rstrip('/')}/{rel}" if fmt == "tree" else dest] = b
|
|
340
|
+
elif fmt == "md":
|
|
341
|
+
if row.get("need_body") and not it.body:
|
|
342
|
+
_unmapped(it, "no prompt body (config-only override)", plan, rep)
|
|
343
|
+
continue
|
|
344
|
+
fm = _from_ir(it, row, rep)
|
|
345
|
+
head = "---\n" + yaml.safe_dump(fm, sort_keys=False, allow_unicode=True, width=10**6) + "---\n\n" if fm else ""
|
|
346
|
+
if dest in plan: # several sources -> one file (e.g. AGENTS.md + context.md -> CLAUDE.md)
|
|
347
|
+
plan[dest] += f"\n\n<!-- imported from {it.src} -->\n{it.body}\n"
|
|
348
|
+
else:
|
|
349
|
+
plan[dest] = head + (f"<!-- imported from {it.src} -->\n" if "*" not in path else "") + it.body + "\n"
|
|
350
|
+
elif fmt == "json-map":
|
|
351
|
+
if row.get("skip_disabled") and it.data.get("enabled") is False:
|
|
352
|
+
rep.notes.append(f"{it.kind} '{it.name}' skipped: disabled in source")
|
|
353
|
+
continue
|
|
354
|
+
cur = dig(doc(path), frag)
|
|
355
|
+
if cur is None:
|
|
356
|
+
put(doc(path), frag, {})
|
|
357
|
+
cur = dig(doc(path), frag)
|
|
358
|
+
if it.name in cur:
|
|
359
|
+
rep.notes.append(f"{it.kind}: existing entries in {path} kept, not overwritten")
|
|
360
|
+
continue
|
|
361
|
+
cur[it.name] = _from_ir(it, row, rep)
|
|
362
|
+
elif fmt == "json-path":
|
|
363
|
+
val = row.get("set", it.data["value"])
|
|
364
|
+
req = row.get("requires", "").format(value=val)
|
|
365
|
+
if req and req not in plan and not (out_root / req).exists():
|
|
366
|
+
_unmapped(it, f"needs {req}, which is not part of this import", plan, rep)
|
|
367
|
+
continue
|
|
368
|
+
if dig(doc(path), frag) is not None:
|
|
369
|
+
rep.notes.append(f"setting '{it.name}' kept existing value in {path}")
|
|
370
|
+
continue
|
|
371
|
+
put(doc(path), frag, val)
|
|
372
|
+
rep.mapped[it.kind] += 1
|
|
373
|
+
for rel, d in docs.items():
|
|
374
|
+
plan[rel] = json.dumps(d, indent=2, ensure_ascii=False) + "\n"
|
|
375
|
+
return plan
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def apply(plan, out_root):
|
|
379
|
+
"""Write plan to disk; a changed existing file is saved as *.bak first."""
|
|
380
|
+
n = 0
|
|
381
|
+
for rel, content in plan.items():
|
|
382
|
+
p = out_root / rel
|
|
383
|
+
data = content if isinstance(content, bytes) else content.encode()
|
|
384
|
+
if p.is_file():
|
|
385
|
+
if p.read_bytes() == data:
|
|
386
|
+
continue
|
|
387
|
+
p.with_name(p.name + ".bak").write_bytes(p.read_bytes())
|
|
388
|
+
p.parent.mkdir(parents=True, exist_ok=True)
|
|
389
|
+
p.write_bytes(data)
|
|
390
|
+
n += 1
|
|
391
|
+
return n
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Claude Code. Official docs: https://code.claude.com/docs/en/overview
|
|
2
|
+
# (docs= URLs below are from memory; verify before relying on them.)
|
|
3
|
+
name = "claude"
|
|
4
|
+
detect = [".claude/agents", ".claude/skills", ".claude/rules", ".claude/settings.json", "CLAUDE.md"]
|
|
5
|
+
|
|
6
|
+
[[item]]
|
|
7
|
+
kind = "instruction"
|
|
8
|
+
path = "CLAUDE.md"
|
|
9
|
+
fmt = "md"
|
|
10
|
+
keep = true
|
|
11
|
+
docs = "https://code.claude.com/docs/en/memory"
|
|
12
|
+
|
|
13
|
+
[[item]]
|
|
14
|
+
kind = "rule"
|
|
15
|
+
path = ".claude/rules/*.md"
|
|
16
|
+
fmt = "md"
|
|
17
|
+
keep = true
|
|
18
|
+
docs = "https://code.claude.com/docs/en/memory"
|
|
19
|
+
|
|
20
|
+
[[item]]
|
|
21
|
+
kind = "skill"
|
|
22
|
+
path = ".claude/skills/*/"
|
|
23
|
+
fmt = "tree" # SKILL.md format is shared with opencode: copy as-is
|
|
24
|
+
docs = "https://code.claude.com/docs/en/skills"
|
|
25
|
+
|
|
26
|
+
[[item]]
|
|
27
|
+
kind = "agent"
|
|
28
|
+
path = ".claude/agents/*.md"
|
|
29
|
+
fmt = "md"
|
|
30
|
+
docs = "https://code.claude.com/docs/en/sub-agents"
|
|
31
|
+
xform = ["tools_csv"]
|
|
32
|
+
map = { name = "name", description = "description", tools = "tools", model = "model" }
|
|
33
|
+
need_body = true
|
|
34
|
+
default = { name = "{name}", description = "{name}" }
|
|
35
|
+
|
|
36
|
+
[[item]]
|
|
37
|
+
kind = "command"
|
|
38
|
+
path = ".claude/commands/*.md"
|
|
39
|
+
fmt = "md"
|
|
40
|
+
docs = "https://code.claude.com/docs/en/slash-commands"
|
|
41
|
+
map = { description = "description" }
|
|
42
|
+
|
|
43
|
+
[[item]]
|
|
44
|
+
kind = "mcp"
|
|
45
|
+
path = ".mcp.json#mcpServers"
|
|
46
|
+
fmt = "json-map"
|
|
47
|
+
docs = "https://code.claude.com/docs/en/mcp"
|
|
48
|
+
xform = ["argv", "refs"]
|
|
49
|
+
map = { command = "command", env = "env", type = "type", url = "url", headers = "headers" }
|
|
50
|
+
ignore = ["enabled"]
|
|
51
|
+
skip_disabled = true # .mcp.json has no per-server enabled flag
|
|
52
|
+
|
|
53
|
+
[[item]]
|
|
54
|
+
kind = "setting"
|
|
55
|
+
name = "default_agent"
|
|
56
|
+
path = ".claude/settings.json#agent"
|
|
57
|
+
fmt = "json-path"
|
|
58
|
+
requires = ".claude/agents/{value}.md"
|
|
59
|
+
|
|
60
|
+
[[item]]
|
|
61
|
+
kind = "setting"
|
|
62
|
+
name = "subagent_depth"
|
|
63
|
+
path = ".claude/settings.json#env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS"
|
|
64
|
+
fmt = "json-path"
|
|
65
|
+
set = "1"
|
|
66
|
+
note = "enables agent teams via env var; the source depth value is not carried over (semantics unverified)"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Plugin pack. Source: https://github.com/alvinunreal/oh-my-opencode-slim/blob/master/docs/configuration.md
|
|
2
|
+
# Agents live in oh-my-opencode-slim.json[c]#agents; prompts in oh-my-opencode-slim/<name>.md
|
|
3
|
+
# (+ <name>_append.md). Inline `prompt` beats the file. Model chains, presets, fallback,
|
|
4
|
+
# council/observer/tui/etc. have no Claude equivalent -> reported as lossy/unmapped.
|
|
5
|
+
host = "opencode"
|
|
6
|
+
origin = "plugin:oh-my-opencode-slim"
|
|
7
|
+
detect = [".opencode/oh-my-opencode-slim.json", ".opencode/oh-my-opencode-slim.jsonc"]
|
|
8
|
+
|
|
9
|
+
[[item]]
|
|
10
|
+
kind = "agent"
|
|
11
|
+
path = ".opencode/oh-my-opencode-slim.json#agents"
|
|
12
|
+
fmt = "json-map+md"
|
|
13
|
+
body = [".opencode/oh-my-opencode-slim/{name}.md", ".opencode/oh-my-opencode-slim/{name}_append.md"]
|
|
14
|
+
map = { name = "name", description = "description" }
|
|
15
|
+
need_body = true
|
|
16
|
+
|
|
17
|
+
[[item]]
|
|
18
|
+
kind = "plugin-config"
|
|
19
|
+
path = ".opencode/oh-my-opencode-slim.json"
|
|
20
|
+
fmt = "raw"
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# OpenCode. Official docs: https://opencode.ai/docs/ (docs= URLs from memory; verify).
|
|
2
|
+
name = "opencode"
|
|
3
|
+
detect = [".opencode", "opencode.json", "opencode.jsonc"]
|
|
4
|
+
|
|
5
|
+
[[item]]
|
|
6
|
+
kind = "instruction"
|
|
7
|
+
path = ".opencode/AGENTS.md"
|
|
8
|
+
fmt = "md"
|
|
9
|
+
keep = true
|
|
10
|
+
docs = "https://opencode.ai/docs/rules"
|
|
11
|
+
|
|
12
|
+
[[item]]
|
|
13
|
+
kind = "instruction"
|
|
14
|
+
path = ".opencode/context.md"
|
|
15
|
+
fmt = "md"
|
|
16
|
+
keep = true
|
|
17
|
+
|
|
18
|
+
[[item]]
|
|
19
|
+
kind = "instruction"
|
|
20
|
+
path = "AGENTS.md"
|
|
21
|
+
fmt = "md"
|
|
22
|
+
keep = true
|
|
23
|
+
|
|
24
|
+
[[item]]
|
|
25
|
+
kind = "rule"
|
|
26
|
+
path = ".opencode/rules/*.md"
|
|
27
|
+
fmt = "md"
|
|
28
|
+
keep = true
|
|
29
|
+
|
|
30
|
+
[[item]]
|
|
31
|
+
kind = "skill"
|
|
32
|
+
path = ".opencode/skills/*/"
|
|
33
|
+
fmt = "tree"
|
|
34
|
+
docs = "https://opencode.ai/docs/skills"
|
|
35
|
+
|
|
36
|
+
[[item]]
|
|
37
|
+
kind = "agent"
|
|
38
|
+
path = ".opencode/agents/*.md"
|
|
39
|
+
fmt = "md"
|
|
40
|
+
docs = "https://opencode.ai/docs/agents"
|
|
41
|
+
xform = ["tools_map"]
|
|
42
|
+
map = { name = "name", description = "description", tools = "tools" }
|
|
43
|
+
default = { mode = "subagent" }
|
|
44
|
+
need_body = true
|
|
45
|
+
|
|
46
|
+
[[item]]
|
|
47
|
+
kind = "mode" # legacy primary-agent files; claude has no modes
|
|
48
|
+
path = ".opencode/modes/*.md"
|
|
49
|
+
fmt = "md"
|
|
50
|
+
xform = ["tools_map"]
|
|
51
|
+
map = { name = "name", description = "description", tools = "tools" }
|
|
52
|
+
|
|
53
|
+
[[item]]
|
|
54
|
+
kind = "command"
|
|
55
|
+
path = ".opencode/commands/*.md"
|
|
56
|
+
fmt = "md"
|
|
57
|
+
docs = "https://opencode.ai/docs/commands"
|
|
58
|
+
map = { description = "description" }
|
|
59
|
+
|
|
60
|
+
[[item]]
|
|
61
|
+
kind = "mcp"
|
|
62
|
+
path = ".opencode/opencode.json#mcp"
|
|
63
|
+
fmt = "json-map"
|
|
64
|
+
docs = "https://opencode.ai/docs/mcp-servers"
|
|
65
|
+
xform = ["mcp_type", "refs_oc"]
|
|
66
|
+
map = { command = "command", environment = "env", enabled = "enabled", url = "url", headers = "headers", type = "type" }
|
|
67
|
+
|
|
68
|
+
[[item]]
|
|
69
|
+
kind = "setting"
|
|
70
|
+
name = "default_agent"
|
|
71
|
+
path = ".opencode/opencode.json#default_agent"
|
|
72
|
+
fmt = "json-path"
|
|
73
|
+
|
|
74
|
+
[[item]]
|
|
75
|
+
kind = "setting"
|
|
76
|
+
name = "subagent_depth"
|
|
77
|
+
path = ".opencode/opencode.json#subagent_depth"
|
|
78
|
+
fmt = "json-path"
|
|
79
|
+
|
|
80
|
+
# Read-only on purpose: no safe Claude equivalent, so they land in unmapped/ for review.
|
|
81
|
+
[[item]]
|
|
82
|
+
kind = "permission"
|
|
83
|
+
name = "permission"
|
|
84
|
+
path = ".opencode/opencode.json#permission"
|
|
85
|
+
fmt = "json-path" # last-match-wins globs; never auto-grant in claude
|
|
86
|
+
|
|
87
|
+
[[item]]
|
|
88
|
+
kind = "plugin"
|
|
89
|
+
name = "plugins"
|
|
90
|
+
path = ".opencode/opencode.json#plugin"
|
|
91
|
+
fmt = "json-path" # npm plugins
|
|
92
|
+
|
|
93
|
+
[[item]]
|
|
94
|
+
kind = "env"
|
|
95
|
+
name = "env"
|
|
96
|
+
path = ".opencode/opencode.json#env"
|
|
97
|
+
fmt = "json-path"
|
|
98
|
+
|
|
99
|
+
[[item]]
|
|
100
|
+
kind = "lsp"
|
|
101
|
+
name = "lsp"
|
|
102
|
+
path = ".opencode/opencode.json#lsp"
|
|
103
|
+
fmt = "json-path"
|
|
104
|
+
|
|
105
|
+
[[item]]
|
|
106
|
+
kind = "hook"
|
|
107
|
+
path = ".opencode/hooks/*"
|
|
108
|
+
fmt = "raw"
|
|
109
|
+
|
|
110
|
+
[[item]]
|
|
111
|
+
kind = "coordinators"
|
|
112
|
+
path = ".opencode/coordinators*.json"
|
|
113
|
+
fmt = "raw"
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Guided setup wizard: `importfrommyharness setup` (also what a bare run does in a terminal)."""
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
from collections import Counter
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from . import engine
|
|
8
|
+
|
|
9
|
+
USE_COLOR = sys.stdout.isatty() and "NO_COLOR" not in os.environ
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def c(code, s):
|
|
13
|
+
return f"\033[{code}m{s}\033[0m" if USE_COLOR else s
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def ask(q, default=""):
|
|
17
|
+
try:
|
|
18
|
+
a = input(f"{c('1', q)} {c('2', f'[{default}]') if default else ''} ").strip()
|
|
19
|
+
except (EOFError, KeyboardInterrupt):
|
|
20
|
+
print("\nNothing was changed.")
|
|
21
|
+
raise SystemExit(130)
|
|
22
|
+
return a or default
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def choose(q, options):
|
|
26
|
+
print(c("1", q))
|
|
27
|
+
for i, o in enumerate(options, 1):
|
|
28
|
+
print(f" {i}) {o}")
|
|
29
|
+
while True:
|
|
30
|
+
a = ask("Pick a number", "1")
|
|
31
|
+
if a.isdigit() and 1 <= int(a) <= len(options):
|
|
32
|
+
return options[int(a) - 1]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def run(hs, packs):
|
|
36
|
+
if not (sys.stdin.isatty() and sys.stdout.isatty()):
|
|
37
|
+
print("setup needs a terminal. Non-interactive: importfrommyharness import <harness>:<path> --to <harness> [--apply]",
|
|
38
|
+
file=sys.stderr)
|
|
39
|
+
return 2
|
|
40
|
+
print(c("1;36", "\n ImportFromMyHarness") + c("2", " bring your whole harness with you\n"))
|
|
41
|
+
root = Path(ask("Which project folder holds your harness config?", os.getcwd())).expanduser()
|
|
42
|
+
found = engine.detect(hs, root) if root.is_dir() else []
|
|
43
|
+
if not found:
|
|
44
|
+
print(f"I can't see a known harness in {root}. Known: {', '.join(sorted(hs))}.", file=sys.stderr)
|
|
45
|
+
return 1
|
|
46
|
+
src = found[0] if len(found) == 1 else choose("I see more than one harness here. Import from:", found)
|
|
47
|
+
rep = engine.Report()
|
|
48
|
+
items = engine.read(hs[src], packs, root, rep)
|
|
49
|
+
counts = Counter(i.kind for i in items)
|
|
50
|
+
print(f"\nFound in {c('1', src)}:")
|
|
51
|
+
for k, n in counts.most_common():
|
|
52
|
+
print(f" {k:<14}{n:>5} {c('36', '█' * max(1, n * 30 // max(counts.values())))}")
|
|
53
|
+
targets = sorted(h for h in hs if h != src)
|
|
54
|
+
dst = targets[0] if len(targets) == 1 else choose("\nImport into:", targets)
|
|
55
|
+
plan = engine.build_plan(items, hs[dst], root, rep)
|
|
56
|
+
r = rep.as_dict(plan)
|
|
57
|
+
print(f"\nPreview (nothing written yet): {c('1', str(r['files']))} files for {dst}")
|
|
58
|
+
print(" converted:", ", ".join(f"{k} x{v}" for k, v in r["mapped"].items()) or "nothing")
|
|
59
|
+
if rep.unmapped:
|
|
60
|
+
kinds = ", ".join(f"{k} x{v}" for k, v in Counter(u["kind"] for u in rep.unmapped).items())
|
|
61
|
+
print(c("33", f" needs your review: {kinds}") + " (saved in .importfrommyharness/unmapped/)")
|
|
62
|
+
if rep.lossy:
|
|
63
|
+
top = ", ".join(k for k, _ in rep.lossy.most_common(3))
|
|
64
|
+
print(c("33", f" loses detail: {top}") + f" ... ({len(rep.lossy)} fields)")
|
|
65
|
+
for n in r["notes"][:5]:
|
|
66
|
+
print(c("2", f" note: {n}"))
|
|
67
|
+
cmd = f"importfrommyharness import {src}:{root} --to {dst} --apply"
|
|
68
|
+
if ask("\nWrite these files into the project now? Changed files are backed up as .bak. (y/N)", "N").lower() != "y":
|
|
69
|
+
print(f"\nNothing was changed. When you're ready:\n {c('1', cmd)}")
|
|
70
|
+
return 0
|
|
71
|
+
print(f"\nDone: {engine.apply(plan, root)} files written in {root}.")
|
|
72
|
+
print(f"Next time, skip the questions:\n {c('1', cmd)}")
|
|
73
|
+
return 3 if rep.lossy or rep.unmapped else 0
|