[codex] Add versioned admin agent markdown editor#302
Conversation
|
@claude Do a thorough review of this PR in terms of: KISS, YAGNI, DRY, Fail Fast, Secure by Default and performance/speed |
|
Claude finished @furukama's task in 3m 45s —— View job PR Review: KISS, YAGNI, DRY, Fail Fast, Secure by Default & Performance
|
| Principle | Severity | Location |
|---|---|---|
| DRY | Medium | saveGatewayAdminAgentMarkdownFile — 2 stats + 2 byte-checks for same data |
| DRY | Low | restoreGatewayAdminAgentMarkdownRevision — redundant && condition |
| DRY | Low | gateway-http-server.test.ts — mock agent shape repeated 4× |
| Performance | Medium | mapGatewayAdminAgent — 10N fs.statSync on every list call |
| Performance | Medium | listGatewayAdminAgentMarkdownRevisions — unbounded reads + O(N log N) Date.parse in comparator |
| Secure by Default | Low | Revision ID uses Math.random() instead of crypto.randomUUID() |
| Secure by Default | Low | sendApiAdminAgentError — regex-based error-to-status inference |
| KISS | Low | Path traversal guard is dead code after allowlist validation |
| KISS | Low | requireAdminAgentIdPathValue has dead === 'agents' check |
| YAGNI | Low | Injectable now param in buildGatewayAdminAgentMarkdownRevision unused in tests |
| YAGNI | Low | restoreAdminAgentMarkdownRevision sends empty body: {} |
| Fail Fast | Low | mapGatewayAdminAgent calls resolveAgentConfig twice per request |
There was a problem hiding this comment.
Pull request overview
Adds a versioned admin-console markdown editor for allowlisted agent workspace bootstrap files, backed by new gateway admin APIs for read/save/preview/restore and snapshot-based revision history.
Changes:
- Introduces gateway admin endpoints + shared/console types for agent markdown files and revisions.
- Implements revision snapshot storage and byte-based validation for save/restore flows.
- Adds admin console
/admin/agentsUI + tests (backend + console) for editing, restoring, oversized rejection, and dirty-draft preservation.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/gateway-service.agent-markdown.test.ts | Adds gateway-service tests for save/load, allowlist enforcement, and oversized rejection. |
| tests/gateway-http-server.test.ts | Adds HTTP handler tests for new admin agent markdown routes and input validation. |
| src/workspace.ts | Exports WORKSPACE_BOOTSTRAP_FILES for reuse as the markdown allowlist. |
| src/gateway/gateway-types.ts | Adds gateway admin response/type definitions for agent markdown files and revision metadata. |
| src/gateway/gateway-service.ts | Implements read/save/list revision/preview/restore logic and revision persistence on disk. |
| src/gateway/gateway-http-server.ts | Splits /api/admin/agents handling into subresource handlers (agent/file/revision/restore). |
| console/src/routes/agents.tsx | Adds Agent Files page UI with editor, revision list/preview, and dirty-draft protection. |
| console/src/routes/agents.test.tsx | Adds UI tests for loading/switching agents, saving, restoring, and draft preservation. |
| console/src/router.tsx | Registers /agents route in the admin console router. |
| console/src/components/sidebar/navigation.ts | Adds “Agent Files” navigation item. |
| console/src/api/types.ts | Adds console API types for admin agent markdown file + revision payloads. |
| console/src/api/client.ts | Adds client functions for new admin markdown endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aedf6b0 to
39a897c
Compare

What changed
Why it changed
Admins needed a narrow, backend-managed way to update agent bootstrap markdown without going through the filesystem directly. Version history was added so those edits are recoverable, and the follow-up review fixes tighten correctness and keep the route/editor logic easier to maintain.
User and developer impact
/admin/agentsRoot cause
The initial implementation duplicated write-path validation between save and restore and coupled local editor draft state directly to query refreshes. The route handler also accumulated multiple resource concerns in a single function.
Validation
npx biome check --write src/gateway/gateway-http-server.ts src/gateway/gateway-service.ts tests/gateway-service.agent-markdown.test.ts console/src/routes/agents.tsx console/src/routes/agents.test.tsxnpx vitest run tests/gateway-service.agent-markdown.test.ts tests/gateway-http-server.test.tsnpx vitest run --config console/vitest.config.ts console/src/routes/agents.test.tsxnpm run typecheckNotes
gateway-http-servertest stderr noise around runtime secret permissions and startup DB access is unchanged; the suites still pass