Skip to content

fix(scripts): add agent reference repair runtime#632

Open
rafaelscosta wants to merge 3 commits intomainfrom
hotfix/agent-reference-repair-runtime-only
Open

fix(scripts): add agent reference repair runtime#632
rafaelscosta wants to merge 3 commits intomainfrom
hotfix/agent-reference-repair-runtime-only

Conversation

@rafaelscosta
Copy link
Copy Markdown
Collaborator

@rafaelscosta rafaelscosta commented Apr 16, 2026

Runtime-only publish for the agent-reference repair flow.

Scope is intentionally limited to five runtime files:

  • .aiox-core/infrastructure/scripts/repair-agent-references.js
  • .aiox-core/infrastructure/scripts/codex-skills-sync/index.js
  • .aiox-core/infrastructure/scripts/codex-skills-sync/validate.js
  • .aiox-core/infrastructure/scripts/ide-sync/index.js
  • package.json

Intent:

  • remove legacy aios-* aliases for core agents
  • regenerate canonical aiox-* Codex/Gemini artifacts
  • expose npm run repair:agent-references

Validation:

  • git apply --check on the runtime-only patch: pass
  • npm run lint: pass with existing repo baseline of 236 warnings, 0 errors
  • npm run typecheck: pass
  • npm test: 1 failing test in tests/integration/onboarding-smoke.test.js that expects the legacy greeting Agent dev loaded; the branch now produces the canonical Dex greeting. This is outside the runtime-only publish scope and was not included in the remote diff.

Unrelated dirty files were intentionally excluded from this PR.

Summary by CodeRabbit

  • New Features
    • Added a repair command to detect, remove, and regenerate legacy agent/skill artifacts and emit human or JSON reports.
    • Validation now recognizes and normalizes legacy skill IDs and reports legacy alias directories alongside missing/orphaned entries.
    • Sync operations now accept an explicit project-root option for more predictable config and output resolution.
  • Chores
    • Added an npm script to invoke the repair command.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
aiox-core Ready Ready Preview, Comment Apr 16, 2026 7:06pm

Request Review

@github-actions github-actions Bot added area: agents Agent system related area: workflows Workflow system related squad mcp type: test Test coverage and quality area: core Core framework (.aios-core/core/) area: installer Installer and setup (packages/installer/) area: synapse SYNAPSE context engine area: cli CLI tools (bin/, packages/aios-pro-cli/) area: pro Pro features (pro/) area: health-check Health check system area: docs Documentation (docs/) area: devops CI/CD, GitHub Actions (.github/) labels Apr 16, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1561f524-0202-481b-8171-3fa15bc5802b

📥 Commits

Reviewing files that changed from the base of the PR and between 09fd55e and 04b329e.

📒 Files selected for processing (1)
  • .aiox-core/install-manifest.yaml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .aiox-core/install-manifest.yaml

Walkthrough

Adds a legacy-aware skill ID helper and validation changes, makes IDE sync respect an optional projectRoot, and introduces a new repair script to remove legacy agent/skill artifacts, re-sync artifacts, and validate resulting state.

Changes

Cohort / File(s) Summary
Skill ID Handling
.aiox-core/infrastructure/scripts/codex-skills-sync/index.js
Added and exported getLegacySkillId(agentId) to normalize legacy aiox-/aios- prefixes and produce canonical aios- IDs.
Validation (legacy-aware)
.aiox-core/infrastructure/scripts/codex-skills-sync/validate.js
Imported getLegacySkillId; validation now annotates expected entries with legacySkillId, recognizes aios- directories as legacy aliases (recorded in new legacy array), adds allowOrphaned option, and adjusts orphan/missing directory logic.
IDE Sync behavior
.aiox-core/infrastructure/scripts/ide-sync/index.js
commandSync now resolves projectRoot from options.projectRoot when provided, otherwise falls back to process.cwd(), affecting config loading and path resolution for sync outputs.
Repair script & package
.aiox-core/infrastructure/scripts/repair-agent-references.js, package.json, .aiox-core/install-manifest.yaml
Added repair-agent-references.js executable that builds/removes legacy artifacts (dry-run support), re-runs syncSkills/commandSync, validates local/global skills and Gemini commands, and emits human/JSON reports. Added npm script repair:agent-references. Manifest updated with new file and refreshed hashes/sizes for modified scripts.

Sequence Diagram

sequenceDiagram
    participant CLI as CLI/Entry Point
    participant Script as repair-agent-references
    participant AgentLoader as Agent Metadata Loader
    participant ArtifactBuilder as Legacy Artifact Builder
    participant FileSystem as File System
    participant SyncEngine as Sync Engine
    participant Validators as Validators
    participant Reporter as Report Generator

    CLI->>Script: Execute with options
    Script->>Script: Parse args & resolve paths
    Script->>AgentLoader: Load agents from source
    AgentLoader-->>Script: Agent metadata
    Script->>ArtifactBuilder: Build legacy artifacts list
    ArtifactBuilder-->>Script: Artifacts to remove
    Script->>FileSystem: Remove or record artifacts (dry-run skips)
    FileSystem-->>Script: Removed/missing records
    Script->>SyncEngine: Run syncSkills & commandSync
    SyncEngine-->>Script: Regenerated artifacts
    Script->>Validators: Validate local/global skills & Gemini commands
    Validators-->>Script: Validation results
    Script->>Reporter: Aggregate and format report (human/JSON)
    Reporter-->>CLI: Output result & set exit code
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main addition: a new agent reference repair script. It accurately reflects the primary change across the five runtime files modified.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hotfix/agent-reference-repair-runtime-only

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

📊 Coverage Report

Coverage report not available

📈 Full coverage report available in Codecov


Generated by PR Automation (Story 6.1)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.aiox-core/infrastructure/scripts/codex-skills-sync/validate.js (1)

68-71: ⚠️ Potential issue | 🟡 Minor

Early return is missing the legacy field.

The early return when skillsDir doesn't exist omits the newly added legacy array, which could cause downstream code to fail if it expects that property.

Proposed fix
   if (!fs.existsSync(resolved.skillsDir)) {
     errors.push(`Skills directory not found: ${resolved.skillsDir}`);
-    return { ok: false, checked: 0, expected: 0, errors, warnings, missing: [], orphaned: [] };
+    return { ok: false, checked: 0, expected: 0, errors, warnings, missing: [], orphaned: [], legacy: [] };
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.aiox-core/infrastructure/scripts/codex-skills-sync/validate.js around lines
68 - 71, The early return when resolved.skillsDir is missing returns an object
without the new legacy property; update the return value in the skills directory
existence check to include legacy: [] alongside the existing properties (ok,
checked, expected, errors, warnings, missing, orphaned) so downstream code that
reads the legacy array (from this validation flow) won't break—locate the check
using resolved.skillsDir and the surrounding errors.push call in validate.js and
add the legacy field to the returned object.
🧹 Nitpick comments (2)
.aiox-core/infrastructure/scripts/repair-agent-references.js (2)

42-44: Minor duplication: isParsableAgent is defined in both files.

This helper is identical to the one in validate.js (Line 32-34). Consider importing it from validate.js or extracting it to a shared utility to avoid drift.

Option: Import from validate.js

Update validate.js to export isParsableAgent:

module.exports = {
  validateCodexSkills,
  validateSkillContent,
  parseArgs,
  getDefaultOptions,
  isParsableAgent,  // Add this export
};

Then in repair-agent-references.js:

-const { validateCodexSkills } = require('./codex-skills-sync/validate');
+const { validateCodexSkills, isParsableAgent } = require('./codex-skills-sync/validate');

-function isParsableAgent(agent) {
-  return !agent.error || agent.error === 'YAML parse failed, using fallback extraction';
-}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.aiox-core/infrastructure/scripts/repair-agent-references.js around lines 42
- 44, Duplicate helper isParsableAgent exists in both validate.js and
repair-agent-references.js; remove the duplicate by exporting isParsableAgent
from validate.js (add isParsableAgent to module.exports alongside
validateCodexSkills, validateSkillContent, parseArgs, getDefaultOptions) and
update repair-agent-references.js to import/require and use that exported
isParsableAgent instead of redefining it (or alternatively move isParsableAgent
into a new shared utility module and require it from both places).

91-109: Consider wrapping fs.removeSync in try/catch.

If removeSync fails (e.g., permission denied, file locked), the script will throw and abort mid-cleanup. Wrapping in try/catch would allow partial cleanup to complete and report failures in the result.

Proposed enhancement
 function removeLegacyArtifacts(artifacts, options) {
   const removed = [];
   const skipped = [];
+  const failed = [];

   for (const artifact of artifacts) {
     if (!fs.existsSync(artifact.path)) {
       skipped.push({ ...artifact, reason: 'not-found' });
       continue;
     }

     if (!options.dryRun) {
-      fs.removeSync(artifact.path);
+      try {
+        fs.removeSync(artifact.path);
+      } catch (error) {
+        failed.push({ ...artifact, reason: error.message });
+        continue;
+      }
     }

     removed.push(artifact);
   }

-  return { removed, skipped };
+  return { removed, skipped, failed };
 }

Then update repairAgentReferences and formatHumanReport to handle the failed array.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.aiox-core/infrastructure/scripts/repair-agent-references.js around lines 91
- 109, The removal loop in removeLegacyArtifacts currently calls fs.removeSync
directly and can throw, aborting the whole run; wrap the fs.removeSync call in a
try/catch to catch failures (when options.dryRun is false), push failed removals
into a new failed array (include artifact and error/reason), continue processing
other artifacts, and return { removed, skipped, failed }; then update
repairAgentReferences and formatHumanReport to accept and surface the failed
array (show artifact path and error/reason) so failures are reported alongside
removed/skipped results.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In @.aiox-core/infrastructure/scripts/codex-skills-sync/validate.js:
- Around line 68-71: The early return when resolved.skillsDir is missing returns
an object without the new legacy property; update the return value in the skills
directory existence check to include legacy: [] alongside the existing
properties (ok, checked, expected, errors, warnings, missing, orphaned) so
downstream code that reads the legacy array (from this validation flow) won't
break—locate the check using resolved.skillsDir and the surrounding errors.push
call in validate.js and add the legacy field to the returned object.

---

Nitpick comments:
In @.aiox-core/infrastructure/scripts/repair-agent-references.js:
- Around line 42-44: Duplicate helper isParsableAgent exists in both validate.js
and repair-agent-references.js; remove the duplicate by exporting
isParsableAgent from validate.js (add isParsableAgent to module.exports
alongside validateCodexSkills, validateSkillContent, parseArgs,
getDefaultOptions) and update repair-agent-references.js to import/require and
use that exported isParsableAgent instead of redefining it (or alternatively
move isParsableAgent into a new shared utility module and require it from both
places).
- Around line 91-109: The removal loop in removeLegacyArtifacts currently calls
fs.removeSync directly and can throw, aborting the whole run; wrap the
fs.removeSync call in a try/catch to catch failures (when options.dryRun is
false), push failed removals into a new failed array (include artifact and
error/reason), continue processing other artifacts, and return { removed,
skipped, failed }; then update repairAgentReferences and formatHumanReport to
accept and surface the failed array (show artifact path and error/reason) so
failures are reported alongside removed/skipped results.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4be2f5c4-1d05-4413-9ea7-97f947f12e3a

📥 Commits

Reviewing files that changed from the base of the PR and between dbb9e52 and 8a54427.

📒 Files selected for processing (5)
  • .aiox-core/infrastructure/scripts/codex-skills-sync/index.js
  • .aiox-core/infrastructure/scripts/codex-skills-sync/validate.js
  • .aiox-core/infrastructure/scripts/ide-sync/index.js
  • .aiox-core/infrastructure/scripts/repair-agent-references.js
  • package.json

coderabbitai[bot]
coderabbitai Bot previously approved these changes Apr 16, 2026
Copy link
Copy Markdown
Collaborator Author

@rafaelscosta rafaelscosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checking mergeability after code owner approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: agents Agent system related area: cli CLI tools (bin/, packages/aios-pro-cli/) area: core Core framework (.aios-core/core/) area: devops CI/CD, GitHub Actions (.github/) area: docs Documentation (docs/) area: health-check Health check system area: installer Installer and setup (packages/installer/) area: pro Pro features (pro/) area: synapse SYNAPSE context engine area: workflows Workflow system related mcp squad type: test Test coverage and quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant