Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Suíte de freeze: orchestrator, bench, pytest do agent-setup e validate.
# Graphify fica OFF (EVOLVELOOP_GRAPHIFY não é definida).
# Ollama não é instalado: retrieval lexical usa o fallback BM25 (ADR-0005).
# Nenhuma API key de vendor — vendor_http_cache_hit permanece NOT_MEASURED.
name: CI

on:
pull_request:
push:
branches:
- "release/**"
- "cursor/**"

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
suite:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: orchestrator/package-lock.json

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install orchestrator
working-directory: orchestrator
run: npm ci

- name: npm test
working-directory: orchestrator
run: npm test

- name: npm run test:bench
working-directory: orchestrator
run: npm run test:bench

- name: Install agent-setup
run: python -m pip install -e "./agent-setup[dev]"

- name: pytest
working-directory: agent-setup
run: python -m pytest -q

- name: validate
run: bash docs/architecture/v2.2/scripts/validate-v22-artifacts.sh
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ Thanks for contributing. EvolveLoop is a **modular agent architecture** with con

## Tests

Local and CI (see [docs/development/ci.md](docs/development/ci.md)):

```bash
(cd orchestrator && npm ci && npm test && npm run test:bench)
python -m pip install -e "./agent-setup[dev]"
(cd agent-setup && python -m pytest -q)
bash docs/architecture/v2.2/scripts/validate-v22-artifacts.sh
```

- Prefer unit/integration tests under `orchestrator/tests/`.
- Evals live under `orchestrator/tests/evals/` — extend carefully; do not weaken freeze constraints on EvolveLoop V1 without an ADR.
- Do not claim regression pass without running the suite.
Expand Down
6 changes: 6 additions & 0 deletions agent-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Nunca versionar `.env` com valores reais. Usar `config/defaults/env.example`.

Testado: **Debian 13**, Python 3.11+. Cursor instalado. systemd user opcional (profile full).

## Skills wiki / wiki-mem

`install.sh standard` cria symlinks. Se `~/.cursor/skills/wiki` ou `wiki-mem` ainda for um diretório copiado por uma instalação antiga, esse diretório é movido para `~/.agent-setup/backups/<timestamp>/` e substituído pelo symlink. A segunda execução não altera o backup. Detalhe: `docs/wiki-skill-install.md`.

CI do monorepo (suíte, bench, pytest, validate): `docs/development/ci.md` na raiz do repositório.

## Uninstall

```bash
Expand Down
4 changes: 3 additions & 1 deletion agent-setup/docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ Install compares checksums / symlink targets. Existing correct config → `alrea

## Conflicts

Local modifications to managed files → backup + report `CONFLICT` (preserve by default).
Ficheiro gerido com conteúdo local diferente → backup por cópia + `CONFLICT` (o original fica no lugar).

Diretório real no destino de um componente `install: symlink` (cópia antiga de `wiki` / `wiki-mem`, ou `--force` sobre um diretório) → o diretório é **movido** para `~/.agent-setup/backups/<timestamp>/`. O destino passa a ser o symlink ou a cópia nova. O legado não é apagado. Ver `docs/wiki-skill-install.md`.
17 changes: 11 additions & 6 deletions agent-setup/docs/wiki-skill-install.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# wiki / wiki-mem install

`standard` profile installs `wiki` and `wiki-mem` from `repo:${AGENTS_ROOT}/.cursor/skills/...` as **symlinks** into `~/.cursor/skills/` (fallback: `agent-setup/skills/*`).
O perfil `standard` instala `wiki` e `wiki-mem` a partir de `repo:${AGENTS_ROOT}/.cursor/skills/...` como **symlinks** em `~/.cursor/skills/` (fallback: `agent-setup/skills/*`).

## CONFLICT
## Diretório legado

If `~/.cursor/skills/wiki` already exists as a **copied directory** from an older install (bundled copytree), a second run reports `CONFLICT skill:wiki` instead of overwriting. Remediation:
Uma instalação antiga fazia `copytree` e deixava `~/.cursor/skills/wiki` (e `wiki-mem`) como **diretório real**. A execução seguinte respondia `CONFLICT skill:wiki` e não instalava o symlink.

Agora o instalador **move** esse diretório para `~/.agent-setup/backups/<timestamp>/<nome>/` e só então cria o symlink. O conteúdo do usuário permanece no backup (`method: move` em `manifest.json`). Não há `rm` nem `rmtree` desse legado.

Quando o destino já é um symlink para o mesmo caminho resolvido da origem, a instalação fica **skipped** (`already configured`). A segunda execução é idempotente e não move o backup de novo.

```bash
rm -rf ~/.cursor/skills/wiki ~/.cursor/skills/wiki-mem
AGENTS_ROOT=/path/to/repo agent install --profile standard
export AGENTS_ROOT=/path/to/repo
./install.sh standard
./install.sh standard
```

When the destination already symlinks to the same resolved path as the source, install is **skipped** (idempotent).
O backup da primeira execução fica em `~/.agent-setup/backups/`.
3 changes: 3 additions & 0 deletions agent-setup/install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env bash
# Profile install. Legacy skill directories (old copytree of wiki / wiki-mem)
# are moved to ~/.agent-setup/backups/<timestamp>/ by the Python installer.
# They are never deleted. A second run is idempotent when the symlink target matches.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export AGENT_SETUP_ROOT="$ROOT"
Expand Down
33 changes: 33 additions & 0 deletions agent-setup/src/agent_setup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,39 @@ def sha256_text(text: str) -> str:
return hashlib.sha256(text.encode("utf-8")).hexdigest()


def relocate_legacy_tree(component: str, source: Path, meta: dict[str, Any] | None = None) -> Path:
"""Move a real directory aside. Never deletes the tree.

Used when a legacy copied skill directory blocks a symlink install.
"""
if source.is_symlink() or not source.is_dir():
raise OSError(f"not a legacy directory: {source}")
ts = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
backup_root = state_dir() / "backups" / ts
backup_root.mkdir(parents=True, exist_ok=True)
dest = backup_root / source.name
n = 0
while dest.exists():
n += 1
dest = backup_root / f"{source.name}-{n}"
shutil.move(source, dest)
record = {
"timestamp": ts,
"component": component,
"original": str(source),
"backup": str(dest),
"method": "move",
**(meta or {}),
}
manifest = backup_root / "manifest.json"
existing: list[Any] = []
if manifest.is_file():
existing = json.loads(manifest.read_text(encoding="utf-8"))
existing.append(record)
manifest.write_text(json.dumps(existing, indent=2) + "\n", encoding="utf-8")
return dest


def create_backup(component: str, source: Path, meta: dict[str, Any] | None = None) -> str | None:
if not source.exists():
return None
Expand Down
132 changes: 106 additions & 26 deletions agent-setup/src/agent_setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path
from typing import Any

from agent_setup.backup import create_backup, sha256_file, sha256_text
from agent_setup.backup import create_backup, relocate_legacy_tree, sha256_file, sha256_text
from agent_setup.manifest import ManifestBundle, read_version
from agent_setup.paths import expand, repo_root, resolve_env_defaults
from agent_setup.state import init_state, load_state, save_state, state_dir
Expand Down Expand Up @@ -55,24 +55,34 @@ def _copy_or_link(src: Path, dest: Path, *, symlink: bool, force: bool, componen
return "skipped"
except OSError:
pass
if dest.is_symlink() and dest.resolve() == src.resolve():
return "skipped"
if dest.is_file():
if sha256_file(dest) == (sha256_file(src) if src.is_file() else ""):
if dest.is_symlink():
# Replacing a symlink does not delete its target.
create_backup(component, dest)
dest.unlink()
elif dest.is_file():
if src.is_file() and sha256_file(dest) == sha256_file(src):
return "skipped"
if not force:
create_backup(component, dest)
if dest.is_symlink() or dest.is_file():
dest.unlink()
elif dest.is_dir():
if symlink:
return "conflict"
dest.unlink()
elif dest.is_dir():
# Legacy copytree (wiki / wiki-mem). Move the tree aside — never rmtree.
if symlink or force:
try:
moved = relocate_legacy_tree(component, dest)
except OSError as exc:
return f"error:legacy_relocate:{exc}"
state.setdefault("legacy_relocations", []).append(
{
"component": component,
"original": str(dest),
"backup": str(moved),
}
)
else:
create_backup(component, dest)
return "conflict"
else:
if dest.is_symlink() or dest.is_file():
dest.unlink()
elif dest.is_dir():
shutil.rmtree(dest)
return "conflict"

_ensure_parent(dest)
if symlink:
Expand Down Expand Up @@ -173,17 +183,33 @@ def install(profile: str = "standard", *, force: bool = False, dry_run: bool = F
continue
src = _resolve_source(rule["source"], env)
dest = expand(rule["destination"], extra=env)
status = _copy_or_link(src, dest, symlink=False, force=force, component=f"rule:{rule['name']}", state=state)
_record(result, f"rule:{rule['name']}", status)
_install_component(
result,
f"rule:{rule['name']}",
src,
dest,
symlink=False,
force=force,
component=f"rule:{rule['name']}",
state=state,
)

# Commands
for cmd in components.get("commands", []):
if profile not in cmd.get("profiles", []):
continue
src = _resolve_source(cmd["source"], env)
dest = expand(cmd["destination"], extra=env)
status = _copy_or_link(src, dest, symlink=False, force=force, component=f"command:{cmd['name']}", state=state)
_record(result, f"command:{cmd['name']}", status)
_install_component(
result,
f"command:{cmd['name']}",
src,
dest,
symlink=False,
force=force,
component=f"command:{cmd['name']}",
state=state,
)

# Skills
for skill in components.get("skills", []):
Expand All @@ -195,12 +221,29 @@ def install(profile: str = "standard", *, force: bool = False, dry_run: bool = F
src = _resolve_source(fallback, env)
dest = expand(skill["destination"], extra=env)
use_symlink = skill.get("install") == "symlink"
status = _copy_or_link(src, dest, symlink=use_symlink, force=force, component=f"skill:{skill['name']}", state=state)
_record(result, f"skill:{skill['name']}", status)
status = _install_component(
result,
f"skill:{skill['name']}",
src,
dest,
symlink=use_symlink,
force=force,
component=f"skill:{skill['name']}",
state=state,
)
also = skill.get("also_link")
if also and status in ("installed", "skipped"):
link_dest = expand(also, extra=env)
_copy_or_link(dest if dest.exists() else src, link_dest, symlink=True, force=force, component=f"skill-link:{skill['name']}", state=state)
_install_component(
result,
f"skill-link:{skill['name']}",
dest if dest.exists() else src,
link_dest,
symlink=True,
force=force,
component=f"skill-link:{skill['name']}",
state=state,
)

# Worker skills (standard/full)
if profile_data.get("components", {}).get("worker_skills"):
Expand All @@ -211,8 +254,16 @@ def install(profile: str = "standard", *, force: bool = False, dry_run: bool = F
for name in ws.get("names", []):
src = Path(os.path.expanduser(base)) / name
dest = expand(f"~/.cursor/skills/{name}", extra=env)
status = _copy_or_link(src, dest, symlink=True, force=force, component=f"worker:{name}", state=state)
_record(result, f"worker:{name}", status)
_install_component(
result,
f"worker:{name}",
src,
dest,
symlink=True,
force=force,
component=f"worker:{name}",
state=state,
)

# Hooks merge
try:
Expand Down Expand Up @@ -242,8 +293,16 @@ def install(profile: str = "standard", *, force: bool = False, dry_run: bool = F
)
_record(result, f"env:{tmpl['name']}", "installed")
else:
status = _copy_or_link(src, dest, symlink=False, force=force, component=f"env:{tmpl['name']}", state=state)
_record(result, f"env:{tmpl['name']}", status)
_install_component(
result,
f"env:{tmpl['name']}",
src,
dest,
symlink=False,
force=force,
component=f"env:{tmpl['name']}",
state=state,
)

# RAG full profile
if profile_data.get("components", {}).get("rag"):
Expand Down Expand Up @@ -277,6 +336,27 @@ def install(profile: str = "standard", *, force: bool = False, dry_run: bool = F
return result


def _install_component(
result: InstallResult,
name: str,
src: Path,
dest: Path,
*,
symlink: bool,
force: bool,
component: str,
state: dict,
) -> str:
before = len(state.get("legacy_relocations", []))
status = _copy_or_link(
src, dest, symlink=symlink, force=force, component=component, state=state
)
_record(result, name, status)
for entry in state.get("legacy_relocations", [])[before:]:
result.ok.append(f"legacy-moved:{name} -> {entry['backup']}")
return status


def _record(result: InstallResult, name: str, status: str) -> None:
if status == "installed":
result.ok.append(name)
Expand Down
Loading
Loading