Skip to content

Commit 17c85cc

Browse files
committed
Add local CLI auth surface
1 parent a3d3710 commit 17c85cc

9 files changed

Lines changed: 648 additions & 57 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,18 @@ mix compile
526526
mix optimal.reality_check
527527
```
528528

529+
Build the local `./optimal` command wrapper:
530+
531+
```bash
532+
mix escript.build
533+
./optimal --help
534+
./optimal reality-check
535+
```
536+
537+
That wrapper is for source checkouts. It delegates to `mix optimal.*` so native
538+
database dependencies load correctly. For production/API deployment, use the OTP
539+
release or container shape instead of treating the escript as the server binary.
540+
529541
Create a markdown-operable workspace:
530542

531543
```bash
@@ -537,6 +549,15 @@ mix optimal.topology --workspace default:my-workspace
537549
Use `optimal.initiate` when starting from a messy dump. Use `optimal.setup` when
538550
you already know the workspace and starter Nodes you want.
539551

552+
Local CLI commands are trusted local commands against the configured store. For
553+
apps, MCP servers, remote agents, or scripts that connect over HTTP/API, mint a
554+
scoped API key:
555+
556+
```bash
557+
mix optimal.auth mint --name "Business OS" --workspace default:my-workspace
558+
mix optimal.auth env --name "Local Agent" --workspace default:my-workspace
559+
```
560+
540561
Render wiki/export projections:
541562

542563
```bash

docs/guides/agent-cli-sop.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,52 @@ preserve the dump
167167
This is how the engine handles noisy human language without corrupting the
168168
workspace.
169169

170+
## Local CLI Auth Model
171+
172+
The local CLI is a trusted local control surface.
173+
174+
```text
175+
human/agent on the same machine
176+
-> runs mix optimal.* or the local ./optimal wrapper
177+
-> reads/writes the local configured store
178+
-> records actor/service metadata where the command supports it
179+
```
180+
181+
That path does not require an API key because it is equivalent to a developer
182+
or local agent running commands on the machine that owns the workspace.
183+
184+
Use API keys when something connects over HTTP/API, MCP, a remote script, an
185+
external app, or a remote agent:
186+
187+
```text
188+
external app / MCP server / remote agent / automation
189+
-> gets scoped API key
190+
-> sends Authorization: Bearer <key> or X-API-Key
191+
-> API verifies tenant, principal, scopes, and workspace scope
192+
-> backend applies lifecycle and audit rules
193+
```
194+
195+
Create a key locally:
196+
197+
```bash
198+
mix optimal.auth mint --name "Business OS" --workspace default:my-workspace
199+
mix optimal.auth env --name "Local Agent" --workspace default:my-workspace
200+
mix optimal.auth list
201+
mix optimal.auth revoke <key-id>
202+
```
203+
204+
If the local `./optimal` wrapper was built in the checkout, the same commands
205+
can be run through it:
206+
207+
```bash
208+
./optimal auth mint --name "Business OS" --workspace default:my-workspace
209+
./optimal auth env --name "Local Agent" --workspace default:my-workspace
210+
```
211+
212+
Do not put raw API keys in markdown, Source Packages, package manifests, or
213+
Context Packages. Store them in shell environment, a local secret store, or the
214+
deployment secret manager.
215+
170216
## Retrieval Pattern
171217

172218
Agents should request context from the engine, not scrape random files first.

docs/guides/installation-and-deployment.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ mix compile
4646
mix optimal.reality_check
4747
```
4848

49+
Build the local `./optimal` command wrapper:
50+
51+
```bash
52+
mix escript.build
53+
./optimal --help
54+
```
55+
56+
The wrapper is for source checkouts. It delegates to the same backend commands
57+
as `mix optimal.*` so native dependencies such as SQLite load through the normal
58+
Mix build. For example:
59+
60+
```bash
61+
./optimal reality-check
62+
./optimal setup my-workspace --name "My Workspace"
63+
./optimal topology --workspace default:my-workspace
64+
```
65+
66+
Do not treat the escript as the production database/server binary. For a
67+
long-running API or team runtime, use the OTP release or container deployment.
68+
4969
Create a known structure:
5070

5171
```bash
@@ -110,6 +130,39 @@ stale context refresh schedule
110130
projection rebuild procedure
111131
```
112132

133+
## Local Auth Vs Remote Auth
134+
135+
Local CLI commands are trusted local commands. They run on the machine that owns
136+
the checkout/store and do not need an API key:
137+
138+
```text
139+
mix optimal.setup ...
140+
mix optimal.initiate ...
141+
mix optimal.topology ...
142+
mix optimal.rag ...
143+
```
144+
145+
Anything connecting over HTTP/API, MCP, app integration, remote script, or
146+
remote agent should use a scoped API key:
147+
148+
```bash
149+
mix optimal.auth mint --name "Business OS" --tenant default --workspace default:my-workspace
150+
mix optimal.auth env --name "Local Agent" --workspace default:my-workspace
151+
mix optimal.auth list
152+
mix optimal.auth revoke <key-id>
153+
```
154+
155+
API clients send the token as either:
156+
157+
```text
158+
Authorization: Bearer <token>
159+
X-API-Key: <token>
160+
```
161+
162+
For production, set API auth to required and store keys in a secret manager or
163+
environment variables. Do not store keys in markdown, Source Packages, Context
164+
Packages, or generated packages.
165+
113166
## Environment Variables
114167

115168
The default runtime reads these paths:
@@ -120,6 +173,7 @@ OPTIMAL_ENGINE_DB SQLite path for local runtime
120173
OPTIMAL_ENGINE_CACHE cache path
121174
OPTIMAL_ENGINE_TOPOLOGY local workspace config path
122175
OPTIMAL_ENGINE_TOPOLOGY_FULL root topology config path
176+
OPTIMAL_ENGINE_API_KEY API key used by external clients/agents
123177
OLLAMA_HOST local model server URL
124178
OPTIMAL_VLM_MODEL local visual model name for configured adapters
125179
```

docs/guides/mix-tasks.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ mix optimal.wiki check node-first-project --workspace default:my-workspace
105105
| Task | Purpose |
106106
| --- | --- |
107107
| `mix optimal.connector` | Connector registry/sync operations. |
108+
| `mix optimal.auth` | Mint, list, revoke, and delete API keys for apps, MCP servers, remote agents, and scripts. |
108109
| `mix optimal.api` | Start the HTTP API. |
109110
| `mix optimal.graph_ui` | Launch the graph visualizer against a running API. |
110111
| `mix optimal.compliance` | Compliance workflows. |
@@ -114,6 +115,15 @@ mix optimal.wiki check node-first-project --workspace default:my-workspace
114115
Tool, MCP, API, connector, script, and model outputs should flow through
115116
governance before becoming evidence, observations, Claims, or Facts.
116117

118+
Local CLI use is trusted local access to the configured store. Use API keys for
119+
HTTP/API clients, MCP servers, remote agents, external apps, and automation:
120+
121+
```bash
122+
mix optimal.auth mint --name "Business OS" --workspace default:my-workspace
123+
mix optimal.auth env --name "Local Agent" --workspace default:my-workspace
124+
mix optimal.auth list
125+
```
126+
117127
## Evaluation, Health, And Verification
118128

119129
| Task | Purpose |
@@ -170,4 +180,3 @@ Default local data shape:
170180
.optimal/cache/
171181
workspace folders and markdown projections
172182
```
173-

0 commit comments

Comments
 (0)