feat(api): .kc item macros indexing + API (Phase 4) #144

Closed
opened 2026-02-18 20:59:03 +00:00 by forbes · 0 comments
Owner

Implement macro registration from .kc files and read-only API endpoints as specified in KC_SERVER.md Sections 3.4 and 4.4.

Depends on: #141 (Phase 1 -- commit extraction pipeline)
Supports: SILO_VIEWPORT Phase 6 (Macro Editor widget), future Macro Store module

Commit-time Extraction

Extend the extraction pipeline to read silo/macros/*.py files from the .kc ZIP and upsert rows into item_macros. Each macro is stored with its filename, trigger type, and full source content. UNIQUE(item_id, filename) -- re-committing the same file name overwrites.

API Endpoints (Section 4.4)

Method Path Auth Description
GET /api/items/{pn}/macros viewer List registered macros (filename, trigger, revision)
GET /api/items/{pn}/macros/{filename} viewer Get macro source content

These are read-only server-side. Macros are authored in Create and committed inside the .kc. The server indexes them for discoverability.

Implementation scope

  • Extend internal/kc/extract.go to iterate silo/macros/ ZIP entries
  • internal/db/item_macros.go -- repository (upsert, list, get by filename)
  • internal/api/macro_handlers.go -- HTTP handlers
  • Register routes in routes.go

Acceptance criteria

  • Committing a .kc with silo/macros/my_script.py populates item_macros
  • GET /macros lists all macros for the item
  • GET /macros/my_script.py returns the source content
  • Re-committing updates the content for existing filenames
  • Items without macros return empty list
Implement macro registration from .kc files and read-only API endpoints as specified in [KC_SERVER.md](docs/KC_SERVER.md) Sections 3.4 and 4.4. **Depends on:** #141 (Phase 1 -- commit extraction pipeline) **Supports:** SILO_VIEWPORT Phase 6 (Macro Editor widget), future Macro Store module ## Commit-time Extraction Extend the extraction pipeline to read `silo/macros/*.py` files from the .kc ZIP and upsert rows into `item_macros`. Each macro is stored with its filename, trigger type, and full source content. UNIQUE(item_id, filename) -- re-committing the same file name overwrites. ## API Endpoints (Section 4.4) | Method | Path | Auth | Description | |--------|------|------|-------------| | `GET` | `/api/items/{pn}/macros` | viewer | List registered macros (filename, trigger, revision) | | `GET` | `/api/items/{pn}/macros/{filename}` | viewer | Get macro source content | These are read-only server-side. Macros are authored in Create and committed inside the .kc. The server indexes them for discoverability. ## Implementation scope - Extend `internal/kc/extract.go` to iterate silo/macros/ ZIP entries - `internal/db/item_macros.go` -- repository (upsert, list, get by filename) - `internal/api/macro_handlers.go` -- HTTP handlers - Register routes in routes.go ## Acceptance criteria - Committing a .kc with silo/macros/my_script.py populates item_macros - GET /macros lists all macros for the item - GET /macros/my_script.py returns the source content - Re-committing updates the content for existing filenames - Items without macros return empty list
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/silo#144