refactor(agents): improve writeAgents with file-level tracking#228
refactor(agents): improve writeAgents with file-level tracking#228Paveltarno merged 9 commits intomainfrom
Conversation
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.0.34-pr.228.21866aePrefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.0.34-pr.228.21866ae"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.0.34-pr.228.21866ae"
}
}
Preview published to npm registry — try new features instantly! |
423bc4e to
57ac95b
Compare
|
@claude run lint fix and typecheck fix |
|
Claude finished @Paveltarno's task in 32s —— View job Unable to run lint fix and typecheckI attempted to run the requested commands but I don't have permission to execute Bash commands in this repository. The following commands require approval:
What you can doTo allow me to run these commands, you'll need to update my permissions by adding bun install
bun run lint:fix
bun run typecheckAlternatively, you can approve the commands when I request them, or configure the repository to allow me to run Bash commands without approval. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
1 similar comment
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
|
@claude lint fix |
|
Claude finished @Paveltarno's task in 54s —— View job Lint fix completed
SummarySuccessfully ran Changes made:
The changes have been committed and pushed to the --- | View commit |
| t.expectResult(result).toContain("Agent files written successfully"); | ||
| t.expectResult(result).toContain("Agent files synced successfully"); | ||
| t.expectResult(result).toContain("Pulled 2 agents"); | ||
| }); |
There was a problem hiding this comment.
can we create a fixture and also add a test that starts from the cli? and then check everything worked fine
There was a problem hiding this comment.
Claude finished @Paveltarno's task in 4m 59s —— View job
CLI fixture and integration tests added
- Read existing test files and understand patterns
- Create
with-agents-for-pullfixture with existing agent file - Add CLI-level integration tests with file system assertions
- Build and run tests — all 7 pass
- Commit and push — 6b0fa71
What was added
New fixture tests/fixtures/with-agents-for-pull/:
base44/.app.jsonc,base44/config.jsonc— standard project structurebase44/agents/support_agent.jsonc— agent file with a// My support agentJSONC comment (used to detect rewrites)
Three new tests in tests/cli/agents_pull.spec.ts:
| Test | Fixture | What it verifies |
|---|---|---|
writes agent files to disk after pull |
basic |
File created at base44/agents/support_agent.jsonc with correct name, description, instructions |
skips unchanged agents and preserves file content |
with-agents-for-pull |
"All agents are already up to date" message + JSONC comment still present (file not rewritten) |
updates agent file in-place when remote data changes |
with-agents-for-pull |
Same file path preserved, content updated to new description/instructions |
| View commit |
There was a problem hiding this comment.
@claude, thank you, just add another test for when there's a file naming clash
There was a problem hiding this comment.
Claude finished @Paveltarno's task in 4m 46s —— View job
Naming clash test added
- Read existing tests and agent config to understand naming clash scenario
- Fix
writeAgentsto detect file naming clashes - Create
with-agents-naming-clashfixture - Add CLI-level test for file naming clash
- Run tests — all 177 pass
- Commit and push — 7d1f297
What was added
New fixture tests/fixtures/with-agents-naming-clash/:
base44/agents/custom_name.jsonc— agent stored with a custom filename butname: "support_agent"
Bug fix in src/core/resources/agent/config.ts (writeAgents):
Before this PR, if a remote returned both support_agent (written to the existing custom_name.jsonc) and a new agent named custom_name (whose default path would also be custom_name.jsonc), the new agent would silently overwrite the first. Now it throws:
Cannot write agent "custom_name": file "…/custom_name.jsonc" is already used by another agent
New test in tests/cli/agents_pull.spec.ts:
fails when a new remote agent's default filename clashes with an existing custom-named fileUses the
with-agents-naming-clashfixture, mocks remote returning both agents, asserts the command fails and the output contains"custom_name".
|
@Paveltarno lets rebase / fix this PR and merge 🙏 |
…ip-unchanged Refactor writeAgents to track files by content name rather than filename, enabling correct updates when filenames don't match agent names. Skip writing unchanged data to preserve comments and formatting. Add duplicate name validation in write path for consistency with readAllAgents. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The early return skipped writeAgents() when remote had 0 agents, preventing deletion of stale local files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: paveltarno <Paveltarno@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c568c5d to
d7d5680
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add `with-agents-for-pull` fixture with a JSONC-commented agent file - Add tests verifying agent files are written to disk with correct content - Add test verifying unchanged agents are skipped (JSONC comment preserved) - Add test verifying changed agents are updated in-place at existing path Co-authored-by: paveltarno <Paveltarno@users.noreply.github.com>
…sion When an existing agent file uses a custom filename (e.g. custom_name.jsonc for an agent named "support_agent"), and a new remote agent arrives whose default filename matches that custom file, writeAgents now throws an error instead of silently overwriting the first agent's file. - Detects clash by tracking claimed file paths before writing new agents - Adds with-agents-naming-clash fixture (custom_name.jsonc with name "support_agent") - Adds CLI test asserting the command fails and mentions the clashing name Co-authored-by: paveltarno <Paveltarno@users.noreply.github.com>
When a new agent's default filename is already taken by a different agent's custom-named file, use a suffixed path (e.g. greeter_1.jsonc) instead of throwing. Aligns with how connectors handle duplicates (InvalidInputError with hints via shared buildNameToEntryMap helper). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Note
Description
This PR refactors
writeAgentsto track agent files by their actual path on disk rather than by a computed slug derived from the agent name. The result is idempotent pulls (unchanged files are skipped, preserving JSONC comments and formatting), correct handling of agents stored under custom filenames, and graceful fallback when a new remote agent's default filename is already claimed by an existing file.Related Issue
None
Type of Change
Changes Made
src/core/resources/agent/config.ts: RemovedtoFileSlughelper; updatedreadAgentFileto return both parsed data and raw content; addedAgentFileEntryinterface andreadAgentFiles/buildNameToEntryMaphelpers; addedfindAvailablePathfor_1/_2suffix fallback on filename collisions; rewrotewriteAgentsto delete/update using actual disk paths, skip unchanged files, write in-place for custom-named files, and useInvalidInputErrorfor duplicate name detection.src/cli/commands/agents/pull.ts: Removed early-exit when remote list is empty; changed task messaging from "Writing"/"written" to "Syncing"/"synced"; added "All agents are already up to date" log when nothing changed.tests/core/agents_write.spec.ts: New unit test suite covering write, delete, custom filename in-place update, skip-on-unchanged (comment preservation), changed-data overwrite, and filename collision lifecycle scenarios.tests/cli/agents_pull.spec.ts: Extended CLI integration tests covering file creation on disk, skip-on-unchanged with comment preservation, naming clash handling, and in-place update scenarios.with-agents-for-pullandwith-agents-naming-clashtest fixtures.Testing
npm test)Checklist
docs/(AGENTS.md) if I made architectural changesAdditional Notes
The previous implementation computed a filesystem slug from the agent name to locate files for deletion and updates. This broke when users stored agents under custom filenames (slug-based lookup found no file) and always rewrote every agent file on each pull (destroying JSONC comments). The new approach builds a
name → file entrymap from what is actually on disk, making all operations path-aware and idempotent.🤖 Generated by Claude | 2026-02-23 09:42 UTC