Code API
An agent sends one Starlark script on stdin and reads structured JSON from stdout. This page lists every builtin and its limits.
$ lighthouse code --project my-project --session optional-session < script.star--project sets the default scope. Pass --session only when the host gives you a stable conversation ID.
Script language
Starlark is a Python-like language interpreted inside the Lighthouse CLI. Scripts have no shell, filesystem, environment, raw SQL or network builtins.
Builtins
| Builtin | Purpose |
|---|---|
load_memory(project, session, limit) | Build a context snapshot with its ID, revision, text, memories and recent results |
search(query, project, limit) | Full-text search of stored results |
get(id) | Fetch a result by stable source ID |
describe(project) | Show the fixed fields and the custom fields in use |
audit(limit) | Recent mutations with actor, scope, revision and sensitivity |
save(title, content, project, agent, kind, fields) | Store a result and return it with a refreshed snapshot |
update(id, fields) | Change core attributes or merge custom fields |
delete(id) | Permanently delete a result. Audited as sensitive |
upsert_memory(key, body, project, kind, source_id) | Create or update durable memory |
delete_memory(id, project) | Retract a memory item. Audited as sensitive |
emit(value) | Write one value as JSON to stdout |
query(kind, where, order, limit, cursor) | Filter records by kind and fields, with a stable pagination cursor |
save_many(items) / update_many(items) | Write several records in one transaction |
batch(ops) / batch_undo(batch_id) | Run a group of writes as one undoable batch |
changes(since, limit) | Read the change feed after a sequence number |
link(from_id, rel, to_id) / unlink(from_id, rel, to_id) / links(id) | Connect records and read the connections |
restore(id) / purge(id) | Bring back a soft-deleted record, or remove it for good |
register_kind(name, schema) | Register a kind so its writes are validated. Needs full write access |
describe(kind=...) | Show a registered kind and its schema |
load_memory(..., include=["dock"]) | Include Dock records, which are hidden by default |
dock.* | Propose plans and tasks, ask questions, read outcomes. Needs lighthouse kind install dock. See Local API and Dock |
Every record now carries revision, seq, updated_at and actor. delete(id) is still a permanent delete from the code API. Pass soft=True to keep the record recoverable. lighthouse code --agent NAME records who made the change.
Write and refresh
Every successful write advances the scope revision and returns a context_patch. If a script writes more than once, keep the last patch.
updated = upsert_memory( key="storage-choice", body="Lighthouse uses a local SQLite file.", project="lighthouse", kind="decision",)emit(updated)The response includes the committed artifact or memory, revision, snapshot_id and context_patch. If the write commits but the refresh fails, you get the record plus refresh_error. Retry the context load, not the write.
Custom fields
Agents add properties as JSON in fields. They never change the SQL schema.
save(title="Flaky test", content="Fixed with a fake clock.", fields={"confidence": 0.9, "area": "testing"})Inspect what is in use before editing:
$ lighthouse code --project harbor-api <<'EOF'emit(describe())EOF{"collection":"artifacts","core_fields":["id","title","content","project","agent","kind","created_at","content_hash"],"custom_fields":{"area":5,"confidence":2},"project":"harbor-api"}Limits
Input, output, instruction count, collection sizes and wall time are bounded. The runner has no hard memory limit, so treat it as a boundary for trusted local scripts, not hostile code.