v0.20 alpha skill-driven python core

This commit is contained in:
kai
2026-05-06 16:26:41 +08:00
parent d1169646b8
commit db626f1d58
87 changed files with 5213 additions and 2865 deletions
+29 -42
View File
@@ -1,61 +1,48 @@
#!/usr/bin/env python3
"""Install the Codex native adapter files into hidden project directories.
"""Backward-compatible wrapper for deploying the Codex adapter.
The Codex desktop sandbox may block agent-created writes into `.codex` and
`.agents/skills`. Run this script locally from the repository root when that
happens.
v0.20 keeps Codex adapter templates in the repository, but deploys the usable
adapter files to a Codex home outside the checkout.
"""
from __future__ import annotations
import argparse
import shutil
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
TEMPLATE_ROOT = REPO_ROOT / "codex_adapter_templates" / "codex"
CODEX_ROOT = REPO_ROOT / ".codex"
AGENTS_SKILLS = REPO_ROOT / ".agents" / "skills"
OPENCODE_SKILLS = REPO_ROOT / ".opencode" / "skills"
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
def copy_tree_contents(src: Path, dst: Path, *, force: bool) -> list[Path]:
written: list[Path] = []
if not src.exists():
raise SystemExit(f"template source not found: {src}")
dst.mkdir(parents=True, exist_ok=True)
for item in src.rglob("*"):
rel = item.relative_to(src)
target = dst / rel
if item.is_dir():
target.mkdir(parents=True, exist_ok=True)
continue
if target.exists() and not force:
continue
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(item, target)
written.append(target)
return written
from scripts.deploy_adapters import deploy_codex, print_result
def main() -> int:
parser = argparse.ArgumentParser(description="Install Codex native adapter")
parser.add_argument("--force", action="store_true", help="overwrite existing adapter files")
parser.add_argument("--skip-skills", action="store_true", help="do not copy .opencode/skills to .agents/skills")
parser = argparse.ArgumentParser(description="Deploy Codex native adapter")
parser.add_argument("--target", type=Path, help="Codex home target; defaults to $CODEX_HOME or ~/.codex")
parser.add_argument("--force", action="store_true", help="overwrite existing files and create .bak backups")
parser.add_argument("--skip-skills", action="store_true", help="do not copy canonical skills into target/skills")
parser.add_argument("--include-config", action="store_true", help="also copy config.toml; off by default to avoid overwriting global Codex config")
parser.add_argument("--dry-run", action="store_true", help="show files that would be written")
args = parser.parse_args()
codex_written = copy_tree_contents(TEMPLATE_ROOT, CODEX_ROOT, force=args.force)
skills_written: list[Path] = []
if not args.skip_skills:
skills_written = copy_tree_contents(OPENCODE_SKILLS, AGENTS_SKILLS, force=args.force)
print("Codex adapter installed.")
print(f" .codex files written: {len(codex_written)}")
print(f" .agents skills files written: {len(skills_written)}")
if codex_written:
for path in codex_written:
print(f" {path.relative_to(REPO_ROOT)}")
result = deploy_codex(
target=args.target,
force=args.force,
skip_skills=args.skip_skills,
include_config=args.include_config,
dry_run=args.dry_run,
)
print_result(result)
print()
print("Note: this no longer writes repository-local .codex files by default.")
print("Run Codex from this repository after deployment:")
if args.include_config:
print(" codex --profile deep-research")
else:
print(" codex")
print("Note: config.toml is not copied by default. Use --include-config only if you want the bundled profile.")
return 0