8000 feat: protect AGENTS.md from auto-update in evoskills project by wxy · Pull Request #6 · wxy/evoskills · GitHub
[go: up one dir, main page]

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
15 changes: 13 additions & 2 deletions 8000 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ This will:
- Core (2): evolution infrastructure
- Required System (4): safety/runtime baseline (enforced by initialization protocol)
- Optional (8): user-selectable workflow enhancements
4. **Framework Files Management** - Dynamic and user-maintained files with protection:
- Framework files (`.github/AI_CONSTITUTION.md`, `.github/AI_INITIALIZATION.md`) are auto-generated for external projects
- `AGENTS.md` is protected: auto-generated in external projects, user-maintained in evoskills repository
- The CLI detects when running on itself and skips auto-updates to prevent overwriting user customizations

## 📚 Usage

Expand All @@ -100,13 +104,20 @@ evoskills install _git-commit # Install a skill
evoskills remove _git-commit # Remove a skill
```

### Update Skills and CLI
### Update Skills

```bash
evoskills update # Update CLI (via npm) and refresh all installed skills
evoskills update # Refresh all installed skills and framework files
evoskills update _git-commit # Update specific skill only
```

`evoskills update` will check for a newer CLI version and print a prompt, but it will not auto-install.
To update CLI explicitly:

```bash
npm install -g @xingyu.wang/evoskills@latest
```

### npm Release Authentication (GitHub Actions)

- Preferred: **Trusted Publishing (OIDC)**, no token needed
Expand Down
126 changes: 92 additions & 34 deletions evoskills
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CLI_VERSION="3.1.0"
CLI_VERSION="3.1.1"

# Project config file (in current directory)
PROJECT_CONFIG_FILE=".evoskills-config.json"
Expand Down Expand Up @@ -67,7 +67,7 @@ Commands:
install <skill> Install a skill from configured repository
add <skill> Alias of install
remove <skill> Remove a skill
update [OPTIONS] Update CLI and refresh skills/constitution
update [OPT 8000 IONS] Refresh skills and framework files
--repo <url> Switch to a different skill repository
[skill] Update specific skill only (omit to update all)
contribute <skill> Start contribution flow for a skill
Expand All @@ -79,7 +79,8 @@ Default repository: https://github.com/wxy/evoskills
Notes:
- Skills are installed to .agent/skills/
- Repository URL is auto-saved in .evoskills-config.json when using --repo
- 'update' without args refreshes CLI (via npm) and all skills from saved repo
- 'update' refreshes framework files and installed skills from saved repo
- CLI updates are check-only prompts during update (no auto npm install)
- AGENTS.md is auto-generated for openskills compatibility
- Skill tiers: Core (2), Required System (4), Optional (8)
EOF
Expand All @@ -90,6 +91,14 @@ ensure_layout() {
mkdir -p ".github"
}

is_evoskills_repo() {
# Check if this is the evoskills project itself
if [ -f "package.json" ] && grep -q '"name".*"evoskills"' package.json; then
return 0
fi
return 1
}

github_raw_url() {
local repo_url="$1"
local path="$2"
Expand Down Expand Up @@ -176,10 +185,7 @@ github_download() {

create_constitution_if_missing() {
if [ ! -f ".github/AI_CONSTITUTION.md" ]; then
local skills_repo
skills_repo=$(get_config_value "skillsRepo")
github_download "$skills_repo" ".github/AI_CONSTITUTION.md" ".github/AI_CONSTITUTION.md" "true"
if [ $? -ne 0 ]; then
if ! update_constitution; then
print_error "AI_CONSTITUTION.md is required for initialization"
exit 1
fi
Expand All @@ -188,10 +194,7 @@ create_constitution_if_missing() {

create_initialization_if_missing() {
if [ ! -f ".github/AI_INITIALIZATION.md" ]; then
local skills_repo
skills_repo=$(get_config_value "skillsRepo")
github_download "$skills_repo" ".github/AI_INITIALIZATION.md" ".github/AI_INITIALIZATION.md" "true"
if [ $? -ne 0 ]; then
if ! update_initialization; then
print_error "AI_INITIALIZATION.md is required for initialization"
exit 1
fi
Expand All @@ -200,32 +203,70 @@ create_initialization_if_missing() {

update_constitution() {
local skills_repo
skills_repo=$(get_config_value "skillsRepo")
local raw_url
local temp_file
local target_file=".github/AI_CONSTITUTION.md"
local bundled_file="$SCRIPT_DIR/.github/AI_CONSTITUTION.md"

skills_repo=$(get_config_value "skillsRepo")
raw_url=$(github_raw_url "$skills_repo" ".github/AI_CONSTITUTION.md")

if curl -sf "$raw_url" > ".github/AI_CONSTITUTION.md" 2>/dev/null; then
print_success "Updated .github/AI_CONSTITUTION.md"
temp_file=$(mktemp)

if curl -sfL "$raw_url" > "$temp_file" 2>/dev/null && [ -s "$temp_file" ]; then
mv "$temp_file" "$target_file"
print_success "Updated $target_file"
return 0
else
print_warn "Could not update .github/AI_CONSTITUTION.md from remote"
fi

rm -f "$temp_file"

if [ -s "$target_file" ]; then
print_warn "Could not update $target_file from remote; keeping local file"
return 1
fi

if [ -s "$bundled_file" ]; then
cp "$bundled_file" "$target_file"
print_warn "Remote unavailable; restored $target_file from local template"
return 0
fi

print_warn "Could not update $target_file from remote and no local template found"
return 1
}

update_initialization() {
local skills_repo
skills_repo=$(get_config_value "skillsRepo")
local raw_url
local temp_file
local target_file=".github/AI_INITIALIZATION.md"
local bundled_file="$SCRIPT_DIR/.github/AI_INITIALIZATION.md"

skills_repo=$(get_config_value "skillsRepo")
raw_url=$(github_raw_url "$skills_repo" ".github/AI_INITIALIZATION.md")

if curl -sf "$raw_url" > ".github/AI_INITIALIZATION.md" 2>/dev/null; then
print_success "Updated .github/AI_INITIALIZATION.md"
temp_file=$(mktemp)

if curl -sfL "$raw_url" > "$temp_file" 2>/dev/null && [ -s "$temp_file" ]; then
mv "$temp_file" "$target_file"
print_success "Updated $target_file"
return 0
else
print_warn "Could not update .github/AI_INITIALIZATION.md from remote"
fi

rm -f "$temp_file"

if [ -s "$target_file" ]; then
print_warn "Could not update $target_file from remote; keeping local file"
return 1
fi

if [ -s "$bundled_file" ]; then
cp "$bundled_file" "$target_file"
print_warn "Remote unavailable; restored $target_file from local template"
return 0
fi

print_warn "Could not update $target_file from remote and no local template found"
return 1
}

create_copilot_instructions_if_missing() {
Expand Down Expand Up @@ -522,7 +563,7 @@ cmd_init() {

cat > "$PROJECT_CONFIG_FILE" << EOF
{
"version": "3.1.0",
"version": "$CLI_VERSION",
"installedAt": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"skillsDir": ".agent/skills",
"openskillsCompatible": true,
Expand Down Expand Up @@ -561,7 +602,10 @@ EOF
fi
fi

write_agents_registry
# Only update AGENTS.md if not in evoskills project itself
if ! is_evoskills_repo; then
write_agents_registry
fi
print_success "Initialization complete (.agent/skills + AGENTS.md + AI_CONSTITUTION.md)"
}

Expand Down Expand Up @@ -606,7 +650,10 @@ cmd_install() {

ensure_layout
install_skill_github "$skill"
write_agents_registry
# Only update AGENTS.md if not in evoskills project itself
if ! is_evoskills_repo; then
write_agents_registry
fi
}

cmd_remove() {
Expand All @@ -623,7 +670,10 @@ cmd_remove() {
if [ -d "$SKILLS_DIR/$skill" ]; then
rm -rf "$SKILLS_DIR/$skill"
print_success "Removed skill: $skill"
write_agents_registry
# Only update AGENTS.md if not in evoskills project itself
if ! is_evoskills_repo; then
write_agents_registry
fi
else
print_warn "Skill is not installed: $skill"
fi
Expand All @@ -649,19 +699,23 @@ cmd_update() {
esac
done

# Update CLI itself if no specific skill requested
# Explicit check-and-prompt for CLI update (no automatic npm install)
if [ -z "$skill" ]; then
if command -v npm &> /dev/null; then
print_info "Updating evoskills CLI..."
npm install -g @xingyu.wang/evoskills@latest 2>/dev/null || print_warn "CLI update failed (may need sudo or already latest)"
local latest_version
latest_version=$(npm view @xingyu.wang/evoskills version 2>/dev/null || true)
if [ -n "$latest_version" ] && [ "$latest_version" != "$CLI_VERSION" ]; then
print_warn "New evoskills CLI version available: $CLI_VERSION -> $latest_version"
print_info "Run: npm install -g @xingyu.wang/evoskills@latest"
fi
else
print_warn "npm not found; skipping CLI update"
print_warn "npm not found; skipping CLI version check"
fi
fi

ensure_layout
update_constitution
update_initialization
update_constitution || true
update_initialization || true
create_copilot_instructions_if_missing

if [ -n "$skill" ]; then
Expand All @@ -683,7 +737,11 @@ cmd_update() {
fi
fi

write_agents_registry
# Only update AGENTS.md if not in evoskills project itself
# (in evoskills, AGENTS.md is user-maintained version-controlled file)
if ! is_evoskills_repo; then
write_agents_registry
fi
print_success "Update complete"
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xingyu.wang/evoskills",
"version": "3.1.0",
"version": "3.1.1",
"description": "Evolution Skills CLI for installing and managing openskills-compatible AI skills.",
"license": "MIT",
"bin": {
Expand Down
6 changes: 4 additions & 2 deletions tests/test_cli_basics.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ source "$(dirname "$BATS_TEST_FILENAME")/test_helper.sh"

@test "version flag shows current version" {
output=$("$EVOSKILLS_CMD" --version 2>&1)
[[ "$output" == *"3.0.1"* ]]
expected_version=$(grep '^CLI_VERSION=' "$EVOSKILLS_CMD" | sed 's/CLI_VERSION="\(.*\)"/\1/')
[[ "$output" == *"$expected_version"* ]]
}

@test "version short flag -v shows current version" {
output=$("$EVOSKILLS_CMD" -v 2>&1)
[[ "$output" == *"3.0.1"* ]]
expected_version=$(grep '^CLI_VERSION=' "$EVOSKILLS_CMD" | sed 's/CLI_VERSION="\(.*\)"/\1/')
[[ "$output" == *"$expected_version"* ]]
}

@test "help flag displays usage information" {
Expand Down
32 changes: 25 additions & 7 deletions tests/test_update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ teardown() {
[ $status -eq 0 ]
}

@test "update does not auto-install CLI" {
run bash -c "cd '$TEST_DIR' && '$EVOSKILLS_CMD' update 2>&1"
[ $status -eq 0 ]

[[ "$output" != *"Updating evoskills CLI"* ]]
}

@test "update unconditionally refreshes constitution file" {
# Modify the constitution file
echo "MODIFIED" > "$TEST_DIR/.github/AI_CONSTITUTION.md"
Expand Down Expand Up @@ -57,19 +64,30 @@ teardown() {
grep -q "Initialization Protocol" "$TEST_DIR/.github/AI_INITIALIZATION.md"
}

@test "update restores initialization file when remote is unavailable and local file is empty" {
# Simulate corrupted local file
: > "$TEST_DIR/.github/AI_INITIALIZATION.md"

# Set invalid repo to force remote fetch failure
run bash -c "cd '$TEST_DIR' && '$EVOSKILLS_CMD' update --repo 'https://github.com/invalid/does-not-exist' 2>&1"
# Command may fail later when refreshing skills from invalid repo, but recovery should still happen

# Should be recovered from bundled template and remain non-empty
[ -s "$TEST_DIR/.github/AI_INITIALIZATION.md" ]
grep -q "Required Initialization Protocol" "$TEST_DIR/.github/AI_INITIALIZATION.md"
}

@test "update refreshes all installed skills" {
# Install a skill
bash -c "cd '$TEST_DIR' && '$EVOSKILLS_CMD' install _git-commit" > /dev/null 2>&1

# Remove it manually to simulate outdated installation
rm -rf "$TEST_DIR/.agent/skills/_git-commit"
# Modify an already-installed core skill to simulate outdated installation
echo "MODIFIED" > "$TEST_DIR/.agent/skills/_evolution-core/SKILL.md"

# Run update
run bash -c "cd '$TEST_DIR' && '$EVOSKILLS_CMD' update 2>&1"
[ $status -eq 0 ]

# Skill should be reinstalled
[ -d "$TEST_DIR/.agent/skills/_git-commit" ]
# Skill file should be refreshed from remote
[ -f "$TEST_DIR/.agent/skills/_evolution-core/SKILL.md" ]
! grep -q "^MODIFIED$" "$TEST_DIR/.agent/skills/_evolution-core/SKILL.md"
}

@test "update with skill parameter updates only that skill" {
Expand Down
Loading
0