Skip to content

Add agent-first library organization API - #176

Merged
HamptonMakes merged 2 commits into
mainfrom
hampton/agent-library-organization
Aug 14, 2026
Merged

Add agent-first library organization API#176
HamptonMakes merged 2 commits into
mainfrom
hampton/agent-library-organization

Conversation

@HamptonMakes

Copy link
Copy Markdown
Collaborator

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 activity
  • GET /api/v1/library/contents — compact plan rows (summary/tags/author/dates/path) for classification without N+1 plan reads
  • POST /api/v1/library/organize — batched operations (move, move_many, move_by_tag, folder create/describe/delete) with dry_run, per-op savepoints, and a run_id grouping each request
  • Cross-library moves (e.g. personal → team library subfolder) via Plans::Place
  • Folder description column so folder names carry meaning agents can read
  • Append-only LibraryEvent audit log with actor_type (human/local_agent/cloud_persona/system), actor_label (API token name), and ?run_id= filtering; ActiveAdmin registration included
  • GET /agent-instructions/organizing sub-guide so the main agent instructions stay lean

Risk 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

  • Dogfooded via the API against a 2,013-plan scale-test library: 2,023 operations across 21 batches, zero errors, 0 unfiled/0 mismatches afterward
  • Follow-up: durable OrganizationRun proposal/apply lifecycle (COPLAN-36)

Generated with Amp

HamptonMakes and others added 2 commits August 13, 2026 19:38
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>
@HamptonMakes
HamptonMakes marked this pull request as ready for review August 14, 2026 00:46
@HamptonMakes
HamptonMakes merged commit 9679313 into main Aug 14, 2026
3 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread db/schema.rb
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|

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment on lines 110 to 114
LogEvent.call(
plan: @plan,
actor: @actor,
actor_type: @actor_type,
event_type: "moved_to_folder",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant