Add agent-first library organization API - #176
Conversation
Give agents a bulk view of a library (folder map with descriptions, counts, tags, activity), compact plan contents for classification, placement operations (move, move_many, move_by_tag, folder create/describe/delete) with dry_run and per-op savepoints, a run_id grouping every organize request, and an append-only LibraryEvent audit log that records who moved what where — human, local agent, cloud persona, or system. Amp-Thread-ID: https://ampcode.com/threads/T-019ffc42-a65a-707b-b5e3-79b0276a17c5 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019ffc42-a65a-707b-b5e3-79b0276a17c5 Co-authored-by: Amp <amp@ampcode.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9bde9be51b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true | ||
| end | ||
|
|
||
| create_table "coplan_agent_events", id: { type: :string, limit: 36 }, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| |
There was a problem hiding this comment.
Remove schema entries that have no owning migrations
A fresh db:schema:load creates coplan_agent_events, coplan_agent_sessions, and extra API-token columns, but a repo-wide search of both migration trees at this commit finds no migrations for that state. Migration-based installations therefore omit these objects while schema-loaded installations include them, making runtime behavior and future migrations depend on how the database was initialized. Remove the unrelated schema state or add the corresponding engine migrations and host copies.
AGENTS.md reference: AGENTS.md:L18-L18
Useful? React with 👍 / 👎.
| LogEvent.call( | ||
| plan: @plan, | ||
| actor: @actor, | ||
| actor_type: @actor_type, | ||
| event_type: "moved_to_folder", |
There was a problem hiding this comment.
Preserve the API token identity in plan move events
When a bearer-token request moves the token owner's plan through either the plan update or organize endpoint, actor is the owning user while actor_type is local_agent; this call consequently lets Plans::LogEvent infer actor_id from the user. Unlike the other API plan-event paths that explicitly pass api_actor_id, the history renderer then resolves actor_user and displays the owner's avatar/name, falsely attributing the agent's move to the human. Thread the token actor ID through Plans::Place and into this event.
AGENTS.md reference: AGENTS.md:L5-L5
Useful? React with 👍 / 👎.
Why
Agents helping users organize their plan libraries had no efficient way to learn a library's layout, classify plans in bulk, or move things safely — and there was no audit trail of who moved what where. This adds an organization API designed for agents: one-call discovery, compact bulk reads, batched placement operations, and full provenance.
What
GET /api/v1/library— one-call library map: folder tree with semantic descriptions, direct/subtree counts, unfiled count, tag histogram, recent activityGET /api/v1/library/contents— compact plan rows (summary/tags/author/dates/path) for classification without N+1 plan readsPOST /api/v1/library/organize— batched operations (move,move_many,move_by_tag, folder create/describe/delete) withdry_run, per-op savepoints, and arun_idgrouping each requestPlans::Placedescriptioncolumn so folder names carry meaning agents can readLibraryEventaudit log withactor_type(human/local_agent/cloud_persona/system),actor_label(API token name), and?run_id=filtering; ActiveAdmin registration includedGET /agent-instructions/organizingsub-guide so the main agent instructions stay leanRisk Assessment
Low — new endpoints and two additive migrations; existing plan/folder behavior only gains an audit hook in
Plans::Place. Not yet exercised by the web UI.References
Generated with Amp