feat(api): macro indexing from .kc files and read-only API #152

Merged
forbes merged 2 commits from feat/kc-macros into main 2026-02-19 01:06:01 +00:00
Owner

Summary

Extract silo/macros/*.py files from .kc ZIP archives on commit and index them into the item_macros table (migration 018). Two read-only API endpoints let clients list macros and retrieve source content.

New files

  • internal/db/item_macros.go — Repository with ReplaceForItem, ListByItem, GetByFilename
  • internal/api/macro_handlers.goHandleGetMacros, HandleGetMacro

Modified files

  • internal/kc/kc.goMacroFile type, Macros field in ExtractResult, ZIP scan for silo/macros/*
  • internal/api/handlers.go — Add macros field to Server struct
  • internal/api/metadata_handlers.go — Index macros in extractKCMetadata + SSE broadcast
  • internal/api/routes.go — Register GET /macros and GET /macros/{filename}

Endpoints

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

Design decisions

  • Replace-on-item: Each .kc commit deletes all macros for the item and re-inserts (handles renames/removals)
  • List omits content: List endpoint returns filename, trigger, and revision only — content fetched individually
  • Trigger defaults to "manual": Future iterations can parse trigger type from file headers
  • No packing needed: Macros live in the .kc ZIP as silo/macros/* and are preserved on pass-through

Closes #144
Depends on: PR #149 (Phase 1)

## Summary Extract `silo/macros/*.py` files from .kc ZIP archives on commit and index them into the `item_macros` table (migration 018). Two read-only API endpoints let clients list macros and retrieve source content. ### New files - `internal/db/item_macros.go` — Repository with `ReplaceForItem`, `ListByItem`, `GetByFilename` - `internal/api/macro_handlers.go` — `HandleGetMacros`, `HandleGetMacro` ### Modified files - `internal/kc/kc.go` — `MacroFile` type, `Macros` field in `ExtractResult`, ZIP scan for `silo/macros/*` - `internal/api/handlers.go` — Add `macros` field to Server struct - `internal/api/metadata_handlers.go` — Index macros in `extractKCMetadata` + SSE broadcast - `internal/api/routes.go` — Register `GET /macros` and `GET /macros/{filename}` ### Endpoints | Method | Path | Auth | Description | |--------|------|------|-------------| | GET | `/api/items/{partNumber}/macros` | viewer | List macros (filename, trigger, revision) | | GET | `/api/items/{partNumber}/macros/{filename}` | viewer | Get macro source content | ### Design decisions - **Replace-on-item**: Each .kc commit deletes all macros for the item and re-inserts (handles renames/removals) - **List omits content**: List endpoint returns filename, trigger, and revision only — content fetched individually - **Trigger defaults to "manual"**: Future iterations can parse trigger type from file headers - **No packing needed**: Macros live in the .kc ZIP as `silo/macros/*` and are preserved on pass-through Closes #144 Depends on: PR #149 (Phase 1)
forbes added 1 commit 2026-02-19 01:04:04 +00:00
- Add MacroFile type to internal/kc and extract silo/macros/* files
  from .kc ZIP archives on commit
- Create ItemMacroRepository with ReplaceForItem, ListByItem, and
  GetByFilename methods
- Add GET /{partNumber}/macros (list) and
  GET /{partNumber}/macros/{filename} (source content) endpoints
- Index macros in extractKCMetadata with SSE broadcast
- List endpoint omits content for lightweight responses

Closes #144
forbes added 1 commit 2026-02-19 01:05:54 +00:00
forbes merged commit 161c1c1e62 into main 2026-02-19 01:06:01 +00:00
forbes deleted branch feat/kc-macros 2026-02-19 01:06:01 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/silo#152