refactor: CI optimization, logging improvements, and codebase formatting (#456)
* fix(db): remove unique constraint on folder to support multi-channel agents * ci: implement automated skill drift detection and self-healing PRs * fix: align registration logic with Gavriel's feedback and fix build/test issues from Daniel Mi * style: conform to prettier standards for CI validation * test: fix branch naming inconsistency in CI (master vs main) * fix(ci): robust module resolution by removing file extensions in scripts * refactor(ci): simplify skill validation by removing redundant combination tests * style: conform skills-engine to prettier, unify logging in index.ts and cleanup unused imports * refactor: extract multi-channel DB changes to separate branch Move channel column, folder suffix logic, and related migrations to feat/multi-channel-db-v2 for independent review. This PR now contains only CI/CD optimizations, Prettier formatting, and logging improvements. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
name: Test
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
ci:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -14,5 +14,12 @@ jobs:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- run: npx tsc --noEmit
|
||||
- run: npx vitest run
|
||||
|
||||
- name: Format check
|
||||
run: npm run format:check
|
||||
|
||||
- name: Typecheck
|
||||
run: npx tsc --noEmit
|
||||
|
||||
- name: Tests
|
||||
run: npx vitest run
|
||||
102
.github/workflows/skill-drift.yml
vendored
Normal file
102
.github/workflows/skill-drift.yml
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
name: Skill Drift Detection
|
||||
|
||||
# Runs after every push to main that touches source files.
|
||||
# Validates every skill can still be cleanly applied, type-checked, and tested.
|
||||
# If a skill drifts, attempts auto-fix via three-way merge of modify/ files,
|
||||
# then opens a PR with the result (auto-fixed or with conflict markers).
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'container/**'
|
||||
- 'package.json'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
# ── Step 1: Check all skills against current main ─────────────────────
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
drifted: ${{ steps.check.outputs.drifted }}
|
||||
drifted_skills: ${{ steps.check.outputs.drifted_skills }}
|
||||
results: ${{ steps.check.outputs.results }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
|
||||
- name: Validate all skills against main
|
||||
id: check
|
||||
run: npx tsx scripts/validate-all-skills.ts
|
||||
continue-on-error: true
|
||||
|
||||
# ── Step 2: Auto-fix and create PR ────────────────────────────────────
|
||||
fix-drift:
|
||||
needs: validate
|
||||
if: needs.validate.outputs.drifted == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/create-github-app-token@v1
|
||||
id: app-token
|
||||
with:
|
||||
app-id: ${{ secrets.APP_ID }}
|
||||
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ steps.app-token.outputs.token }}
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
|
||||
- name: Attempt auto-fix via three-way merge
|
||||
id: fix
|
||||
run: |
|
||||
SKILLS=$(echo '${{ needs.validate.outputs.drifted_skills }}' | jq -r '.[]')
|
||||
npx tsx scripts/fix-skill-drift.ts $SKILLS
|
||||
|
||||
- name: Create pull request
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
with:
|
||||
token: ${{ steps.app-token.outputs.token }}
|
||||
branch: ci/fix-skill-drift
|
||||
delete-branch: true
|
||||
title: 'fix(skills): auto-update drifted skills'
|
||||
body: |
|
||||
## Skill Drift Detected
|
||||
|
||||
A push to `main` (${{ github.sha }}) changed source files that caused
|
||||
the following skills to fail validation:
|
||||
|
||||
**Drifted:** ${{ needs.validate.outputs.drifted_skills }}
|
||||
|
||||
### Auto-fix results
|
||||
|
||||
${{ steps.fix.outputs.summary }}
|
||||
|
||||
### What to do
|
||||
|
||||
1. Review the changes to `.claude/skills/*/modify/` files
|
||||
2. If there are conflict markers (`<<<<<<<`), resolve them
|
||||
3. CI will run typecheck + tests on this PR automatically
|
||||
4. Merge when green
|
||||
|
||||
---
|
||||
*Auto-generated by [skill-drift CI](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})*
|
||||
labels: skill-drift,automated
|
||||
commit-message: 'fix(skills): auto-update drifted skill modify/ files'
|
||||
151
.github/workflows/skill-pr.yml
vendored
Normal file
151
.github/workflows/skill-pr.yml
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
name: Skill PR Validation
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths:
|
||||
- '.claude/skills/**'
|
||||
- 'skills-engine/**'
|
||||
|
||||
jobs:
|
||||
# ── Job 1: Policy gate ────────────────────────────────────────────────
|
||||
# Block PRs that add NEW skill files while also modifying source code.
|
||||
# Skill PRs should contain instructions for Claude, not raw source edits.
|
||||
policy-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check for mixed skill + source changes
|
||||
run: |
|
||||
ADDED_SKILLS=$(git diff --name-only --diff-filter=A origin/main...HEAD \
|
||||
| grep '^\\.claude/skills/' || true)
|
||||
CHANGED=$(git diff --name-only origin/main...HEAD)
|
||||
SOURCE=$(echo "$CHANGED" \
|
||||
| grep -E '^src/|^container/|^package\.json|^package-lock\.json' || true)
|
||||
|
||||
if [ -n "$ADDED_SKILLS" ] && [ -n "$SOURCE" ]; then
|
||||
echo "::error::PRs that add new skills should not modify source files."
|
||||
echo ""
|
||||
echo "New skill files:"
|
||||
echo "$ADDED_SKILLS"
|
||||
echo ""
|
||||
echo "Source files:"
|
||||
echo "$SOURCE"
|
||||
echo ""
|
||||
echo "Please split into separate PRs. See CONTRIBUTING.md."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Comment on failure
|
||||
if: failure()
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body: `This PR adds a skill while also modifying source code. A skill PR should not change source files—the skill should contain **instructions** for Claude to follow.
|
||||
|
||||
If you're fixing a bug or simplifying code, please submit that as a separate PR.
|
||||
|
||||
See [CONTRIBUTING.md](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md) for details.`
|
||||
})
|
||||
|
||||
# ── Job 2: Detect which skills changed ────────────────────────────────
|
||||
detect-changed:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
skills: ${{ steps.detect.outputs.skills }}
|
||||
has_skills: ${{ steps.detect.outputs.has_skills }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Detect changed skills
|
||||
id: detect
|
||||
run: |
|
||||
CHANGED_SKILLS=$(git diff --name-only origin/main...HEAD \
|
||||
| grep '^\\.claude/skills/' \
|
||||
| sed 's|^\.claude/skills/||' \
|
||||
| cut -d/ -f1 \
|
||||
| sort -u \
|
||||
| jq -R . | jq -s .)
|
||||
echo "skills=$CHANGED_SKILLS" >> "$GITHUB_OUTPUT"
|
||||
if [ "$CHANGED_SKILLS" = "[]" ]; then
|
||||
echo "has_skills=false" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "has_skills=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
echo "Changed skills: $CHANGED_SKILLS"
|
||||
|
||||
# ── Job 3: Validate each changed skill in isolation ───────────────────
|
||||
validate-skills:
|
||||
needs: detect-changed
|
||||
if: needs.detect-changed.outputs.has_skills == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
skill: ${{ fromJson(needs.detect-changed.outputs.skills) }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
|
||||
- name: Initialize skills system
|
||||
run: >-
|
||||
npx tsx -e
|
||||
"import { initNanoclawDir } from './skills-engine/index'; initNanoclawDir();"
|
||||
|
||||
- name: Apply skill
|
||||
run: npx tsx scripts/apply-skill.ts ".claude/skills/${{ matrix.skill }}"
|
||||
|
||||
- name: Typecheck after apply
|
||||
run: npx tsc --noEmit
|
||||
|
||||
- name: Run skill tests
|
||||
run: |
|
||||
TEST_CMD=$(npx tsx -e "
|
||||
import { parse } from 'yaml';
|
||||
import fs from 'fs';
|
||||
const m = parse(fs.readFileSync('.claude/skills/${{ matrix.skill }}/manifest.yaml', 'utf-8'));
|
||||
if (m.test) console.log(m.test);
|
||||
")
|
||||
if [ -n "$TEST_CMD" ]; then
|
||||
echo "Running: $TEST_CMD"
|
||||
eval "$TEST_CMD"
|
||||
else
|
||||
echo "No test command defined, skipping"
|
||||
fi
|
||||
|
||||
# ── Summary gate for branch protection ────────────────────────────────
|
||||
skill-validation-summary:
|
||||
needs:
|
||||
- policy-check
|
||||
- detect-changed
|
||||
- validate-skills
|
||||
if: always()
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check results
|
||||
run: |
|
||||
echo "policy-check: ${{ needs.policy-check.result }}"
|
||||
echo "validate-skills: ${{ needs.validate-skills.result }}"
|
||||
|
||||
if [ "${{ needs.policy-check.result }}" = "failure" ]; then
|
||||
echo "::error::Policy check failed"
|
||||
exit 1
|
||||
fi
|
||||
if [ "${{ needs.validate-skills.result }}" = "failure" ]; then
|
||||
echo "::error::Skill validation failed"
|
||||
exit 1
|
||||
fi
|
||||
echo "All skill checks passed"
|
||||
84
.github/workflows/skill-tests.yml
vendored
84
.github/workflows/skill-tests.yml
vendored
@@ -1,84 +0,0 @@
|
||||
name: Skill Combination Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'skills-engine/**'
|
||||
- '.claude/skills/**'
|
||||
- 'src/**'
|
||||
|
||||
jobs:
|
||||
generate-matrix:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
matrix: ${{ steps.matrix.outputs.matrix }}
|
||||
has_entries: ${{ steps.matrix.outputs.has_entries }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
- name: Generate overlap matrix
|
||||
id: matrix
|
||||
run: |
|
||||
MATRIX=$(npx tsx scripts/generate-ci-matrix.ts)
|
||||
{
|
||||
echo "matrix<<MATRIX_EOF"
|
||||
echo "$MATRIX"
|
||||
echo "MATRIX_EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
if [ "$MATRIX" = "[]" ]; then
|
||||
echo "has_entries=false" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "has_entries=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
test-combinations:
|
||||
needs: generate-matrix
|
||||
if: needs.generate-matrix.outputs.has_entries == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
entry: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
- run: npm ci
|
||||
|
||||
- name: Initialize nanoclaw dir
|
||||
run: npx tsx -e "import { initNanoclawDir } from './skills-engine/index.js'; initNanoclawDir();"
|
||||
|
||||
- name: Apply skills in sequence
|
||||
run: |
|
||||
for skill in $(echo '${{ toJson(matrix.entry.skills) }}' | jq -r '.[]'); do
|
||||
echo "Applying skill: $skill"
|
||||
npx tsx scripts/apply-skill.ts ".claude/skills/$skill"
|
||||
done
|
||||
|
||||
- name: Run skill tests
|
||||
run: npx vitest run --config vitest.skills.config.ts
|
||||
|
||||
skill-tests-summary:
|
||||
needs: [generate-matrix, test-combinations]
|
||||
if: always()
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Report result
|
||||
run: |
|
||||
if [ "${{ needs.generate-matrix.outputs.has_entries }}" = "false" ]; then
|
||||
echo "No overlapping skills found. Skipped combination tests."
|
||||
exit 0
|
||||
fi
|
||||
if [ "${{ needs.test-combinations.result }}" = "success" ]; then
|
||||
echo "All skill combination tests passed."
|
||||
else
|
||||
echo "Some skill combination tests failed."
|
||||
exit 1
|
||||
fi
|
||||
52
.github/workflows/skills-only.yml
vendored
52
.github/workflows/skills-only.yml
vendored
@@ -1,52 +0,0 @@
|
||||
name: Skill PR Check
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check for mixed skill + source changes
|
||||
run: |
|
||||
# Check if PR adds new skill files (not just modifies existing)
|
||||
ADDED_SKILLS=$(git diff --name-only --diff-filter=A origin/main...HEAD | grep '^\.claude/skills/' || true)
|
||||
|
||||
# Check if PR touches source
|
||||
CHANGED=$(git diff --name-only origin/main...HEAD)
|
||||
SOURCE=$(echo "$CHANGED" | grep -E '^src/|^container/|^package\.json|^package-lock\.json' || true)
|
||||
|
||||
# Block if new skills are added AND source is modified
|
||||
if [ -n "$ADDED_SKILLS" ] && [ -n "$SOURCE" ]; then
|
||||
echo "❌ PRs that add skills should not modify source files."
|
||||
echo ""
|
||||
echo "New skill files:"
|
||||
echo "$ADDED_SKILLS"
|
||||
echo ""
|
||||
echo "Source files:"
|
||||
echo "$SOURCE"
|
||||
echo ""
|
||||
echo "Please read CONTRIBUTING.md"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Comment on failure
|
||||
if: failure()
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
github.rest.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.issue.number,
|
||||
body: `This PR adds a skill while also modifying source code. A skill PR should not change source files—the skill should contain **instructions** for Claude to follow. See \`/add-telegram\` for an example.
|
||||
|
||||
If you're fixing a bug or simplifying code, please submit that as a separate PR.
|
||||
|
||||
See [CONTRIBUTING.md](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md) for details.`
|
||||
})
|
||||
Reference in New Issue
Block a user