octopi-agent 0.122.0 → 0.130.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  [中文文档](./README.zh.md) · [Documentation](./docs/) · [Architecture](./docs/architecture.md) · [Contributing](./docs/CONTRIBUTING.md)
9
9
 
10
- ![License](https://img.shields.io/badge/license-Apache--2.0-blue) ![Node](https://img.shields.io/badge/node-%3E%3D24-brightgreen) ![npm](https://img.shields.io/npm/v/octopi-agent?label=octopi-agent)
10
+ [![CI](https://github.com/JK-Ai-Era/octopi/actions/workflows/ci.yml/badge.svg)](https://github.com/JK-Ai-Era/octopi/actions/workflows/ci.yml) ![License](https://img.shields.io/badge/license-Apache--2.0-blue) ![Node](https://img.shields.io/badge/node-%3E%3D24-brightgreen) ![npm](https://img.shields.io/npm/v/octopi-agent?label=octopi-agent)
11
11
 
12
12
  ---
13
13
 
@@ -51,45 +51,294 @@ Your product ── Principal / Intent / IAM ──► Octopi engine ──► M
51
51
 
52
52
  ---
53
53
 
54
+ ## Quick Start
55
+
56
+ **Prerequisites**: Node.js ≥ 24.
57
+
58
+ ```bash
59
+ npm install -g octopi-agent
60
+ ```
61
+
62
+ ### Three minutes to your first conversation
63
+
64
+ ```bash
65
+ octopi init
66
+ ```
67
+
68
+ On a fresh machine `octopi init` **is** the first-run experience: it scaffolds
69
+ `OCTOPI_HOME` and then walks you through the setup wizard in your terminal. The
70
+ state machine has nine steps; terminal mode auto-selects CLI, so you answer
71
+ eight:
72
+
73
+ ```text
74
+ language → deployment mode → model provider → API key → model
75
+ → connectivity probe → start services → first message
76
+ ```
77
+
78
+ - **Deployment mode** is a real decision, not a formality: *personal* (just you
79
+ on this machine, no login), *organization* (one org, several users, shared
80
+ knowledge base), *multi-organization* (isolated orgs on one deployment). The
81
+ two org modes ask for an admin password — typed twice, stored hashed.
82
+ - **API key** is never written into `octopi.json`: it lands in
83
+ `OCTOPI_HOME/.env` while the config keeps a `${VAR}` placeholder. The wizard
84
+ probes the provider before it commits, and every failure comes with a way out
85
+ (retry, re-enter the key, switch provider, save and exit).
86
+ - **Config takes effect immediately** — the wizard writes before it starts
87
+ services, and the Web wizard hot-applies into the running gateway. If you
88
+ re-run `octopi init` against an already-running gateway, restart it (or change
89
+ config through the console) — the CLI wizard does not hot-apply.
90
+
91
+ When the wizard finishes it offers to start services and to chat right away,
92
+ and prints the console access key (the random `channels[type=http].apiKey`
93
+ scaffolded for you). Local access needs nothing; for LAN or remote access paste
94
+ that key into the WebUI login page's "Access key" field.
95
+
96
+ ```bash
97
+ octopi serve start # gateway + web console; the wizard can do this for you
98
+ octopi chat # TUI chat, same agent, same config
99
+ octopi doctor # diagnose deployment/config, no LLM needed
100
+ octopi --version # installed version (also: octopi version, or -v)
101
+ ```
102
+
103
+ Bare `octopi` follows the same rule: uninitialized → the init wizard,
104
+ initialized → TUI chat.
105
+
106
+ **Prefer the browser?** `octopi init --web` starts the service for you if it is
107
+ not running (`serve start`, itself idempotent), then opens the Web wizard at the
108
+ printed setup link. On a fresh deployment that link is what `octopi serve start`
109
+ prints:
110
+
111
+ ```text
112
+ 🧙 First-run setup wizard (Web): http://localhost:8180/?setup=<token>
113
+ ```
114
+
115
+ (Port `8180` is the default; with `web.port` set, trust the printed link.) The
116
+ link is valid for 30 minutes and revoked once the wizard completes. The setup
117
+ endpoint requires that token from any source — loopback included — so nothing
118
+ else on the machine can drive the wizard and rewrite the config; requests a
119
+ browser sends from a non-local origin are refused. If no valid token exists
120
+ (already configured, or expired), `--web` says so and points at the console
121
+ instead of opening a page without a wizard. The CLI and Web wizards share one
122
+ state machine and write the same config — pick either.
123
+
124
+ **Non-interactive** (CI, dotfiles, scripted installs) — `--yes` skips the wizard
125
+ and reads everything from flags plus env, so nothing is probed:
126
+
127
+ ```bash
128
+ OCTOPI_API_KEY=sk-… octopi init --yes --provider deepseek --model deepseek-flash
129
+ ```
130
+
131
+ `--yes` takes defaults plus env: `OCTOPI_API_KEY` (required by presets that need
132
+ a key — omit it only for keyless `ollama`), `OCTOPI_DEPLOYMENT_MODE`,
133
+ `OCTOPI_ADMIN_PASSWORD` (required by the org modes), `OCTOPI_ORG_NAME`,
134
+ `OCTOPI_ADMIN_NAME`, `OCTOPI_LANG`. Defaults: provider `ollama`, deployment mode
135
+ `personal`. `--web` hands off to the browser wizard; `--cli` forces the terminal
136
+ one.
137
+
138
+ **A second agent** is a wizard of its own — pick a type, name it and say how it
139
+ should address you, get pointed at attaching material, then try it. It needs a
140
+ deployment whose registry has a user:
141
+
142
+ ```bash
143
+ octopi agent new
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Build your own agent
149
+
150
+ Three steps, in the order you actually decide them: **what it is** → **how it
151
+ remembers** → **what it can touch**.
152
+
153
+ ### Start from files
154
+
155
+ An agent is a directory. Persona and skills are plain Markdown — diffable,
156
+ reviewable, versionable. Extension = add a file. Composition = overlay
157
+ directories.
158
+
159
+ ```text
160
+ my-agent/
161
+ ├── AGENTS.md # main persona — loaded first
162
+ ├── persona/ # supplemental persona, alphabetical
163
+ │ ├── 10-soul.md
164
+ │ ├── 20-identity.md
165
+ │ └── 30-user.md
166
+ └── skills/
167
+ └── deploy/
168
+ └── SKILL.md # two-stage loaded: metadata now, content on demand
169
+ ```
170
+
171
+ The learning substrate (Memory / Cognition / Wisdom) lives in a per-agent
172
+ SQLite store — it is *grown*, not hand-written. See [docs/memory.md](./docs/memory.md).
173
+
174
+ ### Run it in your code
175
+
176
+ ```typescript
177
+ import { AgentBuilder, JsonlSessionStore, OpenAIProvider } from 'octopi-agent';
178
+
179
+ const { runner, runtime } = await new AgentBuilder()
180
+ .model(new OpenAIProvider({
181
+ apiKey: process.env.OPENAI_API_KEY!,
182
+ models: ['gpt-6.1-terra'],
183
+ defaultModel: 'gpt-6.1-terra',
184
+ }))
185
+ .persona('./my-agent')
186
+ // The builder's default store is in-memory: sessions vanish on process exit.
187
+ // Pass one explicitly, or you have built the amnesia this engine exists to fix.
188
+ .store(new JsonlSessionStore({ sessionsDir: './sessions' }))
189
+ .build();
190
+
191
+ const userMessage = { role: 'user' as const, content: 'hello', timestamp: Date.now() };
192
+
193
+ for await (const event of runner.handle('session-1', userMessage, {
194
+ systemPrompt: '', // empty = resolve persona per run (hot-reload aware)
195
+ })) {
196
+ if (event.type === 'llm_stream_delta') {
197
+ process.stdout.write(String(event.data?.delta ?? ''));
198
+ }
199
+ }
200
+
201
+ runtime?.dispose(); // autonomous subsystems hold timers — dispose to let the process exit
202
+ ```
203
+
204
+ `runner.handle()` is the session-aware entry: it owns the session lifecycle and
205
+ write-back. Leaving `systemPrompt` empty lets the runner resolve persona per run
206
+ (editing `AGENTS.md` takes effect on the next message); passing a string pins
207
+ that prompt for the call.
208
+
209
+ **Two paths, and they are not the same size.** Building by hand (above) means you
210
+ also wire the substrate yourself — `.memoryStore(...)`, `.wisdomStore(...)` — or
211
+ your agent has a persona but no memory. `buildFromConfigFile()` is the other path:
212
+ it runs the canonical wiring (`wireAgentBuilder`), which attaches SQLite-backed
213
+ memory / wisdom / cognition against the agent home, and returns a `Map` of
214
+ `agentId → BuiltAgent` (`{ agent, runner, runtime, ... }`). It does **not** pick a
215
+ session store for you — that stays your call, exactly as above.
216
+ For a single agent with no host session store, `build({ mode: 'core' })`
217
+ plus `agent.run()` is the bare library-level path.
218
+
219
+ **You own identity.** `RunConfig.principal` carries who is driving; if you host
220
+ real users, pass it per call and map your `conversationId` to `sessionId` before
221
+ calling. Omitting it is the no-host path — fine for a CLI you own, wrong the
222
+ moment a second user exists. The engine never infers a principal from prose.
223
+
224
+ ### Give it tools
225
+
226
+ Tools arrive from three places: built-in harness tools, host-registered tools
227
+ (`agent.registerTool`), and MCP servers. The MCP SDK client is an Integration
228
+ adapter — import it from its subpath, not the package root:
229
+
230
+ ```typescript
231
+ import { AgentBuilder, OpenAIProvider } from 'octopi-agent';
232
+ import { createSdkMcpClient } from '@octopi-agent/engine/integration';
233
+
234
+ const { agent, runner, mcpManager, runtime } = await new AgentBuilder()
235
+ .model(new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY!, models: ['gpt-6.1-terra'], defaultModel: 'gpt-6.1-terra' }))
236
+ .persona('./my-agent')
237
+ .mcpClientFactory(createSdkMcpClient)
238
+ .mcp({
239
+ id: 'filesystem',
240
+ transport: 'stdio',
241
+ command: 'npx',
242
+ args: ['-y', '@modelcontextprotocol/server-filesystem', '/data'],
243
+ })
244
+ .build();
245
+
246
+ console.log(agent.tools.map((t) => t.name));
247
+
248
+ await mcpManager.disconnectAll(); // MCP servers keep child processes alive
249
+ runtime?.dispose();
250
+ ```
251
+
252
+ Tools are namespaced as `{serverId}__{toolName}` (separator `__`), so the server
253
+ above registers under a `filesystem` prefix and two servers advertising the same
254
+ tool name cannot collide. `effectPolicy` (I5) governs what those tools may touch;
255
+ see [docs/architecture.md](./docs/architecture.md) for the containment modes.
256
+
257
+ ---
258
+
54
259
  ## The Constitution
55
260
 
56
- Most frameworks define classes. Octopi defines **law** — an ontology with
57
- exclusive definitions and enforceable invariants. A few of the laws of physics:
261
+ ### What it is
262
+
263
+ The constitution is not documentation decoration — **it is the development
264
+ method, and it is this project's single largest source of reliability.**
265
+
266
+ Every concept has exactly one authoritative definition. Every invariant is an
267
+ enforceable law with a named implementation site — the load-bearing ones also
268
+ carry a test that fails when broken. Design decisions travel through change
269
+ records and bilingual sync — never through tribal memory. When code and
270
+ constitution disagree, the code moves.
271
+
272
+ Most frameworks define classes. Octopi defines **law** — and a codebase that
273
+ answers to it.
274
+
275
+ ### The ontology — one authoritative definition per concept
276
+
277
+ Naming a thing once, and only once, is what makes the rest checkable. These are
278
+ the objects the engine is built out of:
58
279
 
59
280
  | Object | What it is |
60
281
  |---|---|
282
+ | **Host** | The embedding boundary: supplies the Principal, maps `conversationId ↔ sessionId`, owns human IAM |
283
+ | **Principal / Intent** | Who drives, and a structured request (`run` / `preferred` / `consult` / `handoff`…) — auditable, never inferred from prose |
284
+ | **Agent** | A template: persona, tools, default model, substrate — never a bag of live state |
285
+ | **Substrate** | What the agent has learned across sessions: Memory / Cognition / Wisdom |
286
+ | **Knowledge** | **Exogenous corpus** (source-anchored; indexes rebuildable) — scope is Global / Project / Session, never Agent-level |
61
287
  | **Session** | The first-class aggregate of continuity (`sessionId`) |
62
288
  | **Discourse** | The session's append-only authoritative log |
63
289
  | **Projection** | Any derived view (status / tasks / compact / index) — rebuildable, never authoritative |
64
- | **Agent** | A template: persona, tools, default model, substrate — never a bag of live state |
65
290
  | **Run / RunScope** | One episode; **all mutable context lives only inside a RunScope** and is discarded after write-back |
66
- | **Substrate** | What the agent has learned across sessions: Memory / Cognition / Wisdom |
67
- | **Principal / Intent** | Who drives, and a structured request (`run` / `consult` / `handoff`…) — auditable, never inferred from prose |
291
+ | **Turn / Step** | A Turn is one discourse exchange; a Step is one model round. Never the same word for both |
292
+
293
+ Three distinctions this table exists to kill: **Substrate** (what the agent learned) ≠ **Knowledge** (what the world wrote down) ≠ **Discourse** (what happened). A derived view is a **Projection**, and a projection may be rebuilt from authority — never the other way round.
294
+
295
+ ### The invariants — laws that can be executed
68
296
 
69
- And the invariants they imply:
297
+ Constitutional (violation = bug):
70
298
 
71
299
  - **I1** — Mutable context exists only in a RunScope. Agents are templates; the same agent runs many sessions concurrently without cross-talk (the lease key is `sessionId` — from day one).
72
300
  - **I2** — Discourse is the single authority. Everything else is a projection that can be invalidated and rebuilt.
73
301
  - **I3** — Accountability ≠ Agency. Being able to act is not being responsible; switching executors is not a `handoff`.
302
+ - **I4** — Context is a *type × Scope* cross product, not a layer count. Priority order is never a substitute for ownership.
74
303
  - **I5** — The effect plane is governed exactly like the cognition plane. Tools touch the world; their effects are policy, not trust.
75
304
  - **I6** — The engine consumes structured Intents and keeps every Principal in the audit log. "Understanding language" belongs to the host; enforcing the law belongs to the engine.
76
305
 
77
- ### Constitution-driven development
306
+ Engineering (implementations must obey) — `I` answers *what must be true*; `E`
307
+ answers *how the implementation is allowed to be built*: E1 runs on one
308
+ `sessionId` are serialized while the same agent may run sessions concurrently;
309
+ E2 the lock/lease key is `sessionId`; E3 substrates are written only by their
310
+ own agent; E4 compact is keyed by `(sessionId, agentId)`; E5 the loop stays
311
+ stateless and runs through `Agent.run` with per-run context; E6 effective rights
312
+ are an intersection (`floor ∩ role ∩ agent ∩ binding`), illegal grants rejected
313
+ at grant time; E7 an in-memory lock is never pretended to be globally valid —
314
+ one gateway host may run several run processes, and a real Session Lease
315
+ replaces the lock wherever the deployment outgrows that; E8 volatile context never enters the system prompt
316
+ prefix and history is never rewritten to "drop" it.
78
317
 
79
- The constitution is not documentation decoration — **it is the development
80
- method, and it is this project's single largest source of reliability.**
318
+ ### How it does its job
81
319
 
82
- Every concept has exactly one authoritative definition. Every invariant is an
83
- enforceable law with a named implementation site and a verification test.
84
- Design decisions travel through change records and bilingual sync — never
85
- through tribal memory. When code and constitution disagree, the code moves.
320
+ The invariants are not aspirations developers are trusted to remember. Enforcement
321
+ is graded, and the grade is stated rather than implied:
322
+
323
+ **Checked on every build — breaking them fails CI:**
324
+
325
+ - **Dependency direction** is checked, not requested — `tests/architecture/boundaries.test.ts` fails on a core → harness import, and the rule is mirrored in lint (`no-restricted-imports`).
326
+ - **Catalog single sources of truth** — the domain count comes from `docs/domains.yaml`, so docs drift from code is a red build (`tests/architecture/domains-catalog.test.ts`).
327
+ - **Behavioural invariants get targeted tests** — RunScope isolation (I1), session projection (I2), session ACL and handoff (I3/E6), lease and revision (E2/E7), cache-stable assembly (E8) each have a test that fails when the law is broken.
328
+ - **Structural drift is gated** — `arch/check-sync.sh` goes red when a path list or module map no longer matches the tree.
86
329
 
87
- That is why the invariants above survive concurrency and growth: RunScope
88
- isolation, Discourse authority, and the permission lattice are not aspirations
89
- remembered by developers — they are **checked**: automated dependency
90
- boundary checks, catalog single-sources-of-truth, and tests that fail when the
91
- law is broken. New work is judged by one question first: *does it violate
92
- the constitution?*
330
+ **Held as contracts, with a named landing site:** every invariant has an
331
+ implementation owner in the constitution's mapping table (I4 → context
332
+ ownership, I5 → tool/effect policy, E3/E4 → substrate write paths and compact
333
+ keys…). Those are enforced at the seam where the code is written, but not all of
334
+ them yet fail a build on their own — saying otherwise would be the exact kind of
335
+ untrue claim this document exists to prevent.
336
+
337
+ **Rules change the slow way** — an invariant is amended in the constitution and
338
+ its change log first; code follows. Never the other way round.
339
+
340
+ That is why these laws survive concurrency and growth: the load-bearing ones are
341
+ **checked**, and the rest are written down where they can be checked next.
93
342
 
94
343
  📖 **[Read the full constitution →](./docs/north-star.md)** (中文版:[docs/north-star.zh.md](./docs/north-star.zh.md))
95
344
 
@@ -252,12 +501,12 @@ dependencies.**
252
501
  │ │ knowledge · activation · run · context · ││
253
502
  │ │ extension · collaboration ││
254
503
  │ │ ┌────────────────────────────────────────────────────┐││
255
- │ │ │ Layer 1 Core — EventBus · StateMachine · │││
256
- │ │ │ Kernel ports (ModelProvider, Security- │││
257
- │ │ │ Guard, RunGuard, ErrorStrategy, …) │││
504
+ │ │ │ Layer 1 Loop — pure async generator: │││
505
+ │ │ │ agentLoop · callModel · classifyError │││
258
506
  │ │ │ ┌────────────────────────────────────────────────┐│││
259
- │ │ │ │ Layer 0 Loop — pure async generator: ││││
260
- │ │ │ │ agentLoop · callModel · classifyError ││││
507
+ │ │ │ │ Layer 0 Core (kernel) — EventBus · ││││
508
+ │ │ │ │ StateMachine · Kernel ports (ModelProvider, ││││
509
+ │ │ │ │ SecurityGuard, RunGuard, ErrorStrategy, …) ││││
261
510
  │ │ │ └────────────────────────────────────────────────┘│││
262
511
  │ │ └────────────────────────────────────────────────────┘││
263
512
  │ └────────────────────────────────────────────────────────┘│
@@ -272,195 +521,11 @@ collaboration). The count authority is
272
521
  [docs/domains.yaml](./docs/domains.yaml); the narrative is
273
522
  [docs/domains.md](./docs/domains.md).
274
523
 
275
- The Loop layer is a **pure async generator** — zero state, zero external
276
- dependencies — so the entire runtime above it is contracts you can swap:
524
+ The Loop layer is a **pure async generator** — zero state, no I/O, built only on the kernel vocabulary — so the entire runtime above it is contracts you can swap:
277
525
  `ModelProvider`, `SessionStore`, `ContextEngine`, `SecurityGuard`, …
278
526
 
279
527
  ---
280
528
 
281
- ## Quick Start
282
-
283
- **Prerequisites**: Node.js ≥ 24.
284
-
285
- ```bash
286
- npm install -g octopi-agent
287
- ```
288
-
289
- ### Three minutes to your first conversation
290
-
291
- ```bash
292
- octopi init
293
- ```
294
-
295
- On a fresh machine `octopi init` **is** the first-run experience: it scaffolds
296
- `OCTOPI_HOME` and then walks you through the setup wizard in your terminal. The
297
- state machine has nine steps; terminal mode auto-selects CLI, so you answer
298
- eight:
299
-
300
- ```text
301
- language → deployment mode → model provider → API key → model
302
- → connectivity probe → start services → first message
303
- ```
304
-
305
- - **Deployment mode** is a real decision, not a formality: *personal* (just you
306
- on this machine, no login), *organization* (one org, several users, shared
307
- knowledge base), *multi-organization* (isolated orgs on one deployment). The
308
- two org modes ask for an admin password — typed twice, stored hashed.
309
- - **API key** is never written into `octopi.json`: it lands in
310
- `OCTOPI_HOME/.env` while the config keeps a `${VAR}` placeholder. The wizard
311
- probes the provider before it commits, and every failure comes with a way out
312
- (retry, re-enter the key, switch provider, save and exit).
313
- - **Config takes effect immediately** — the wizard writes before it starts
314
- services, and the Web wizard hot-applies into the running gateway. If you
315
- re-run `octopi init` against an already-running gateway, restart it (or change
316
- config through the console) — the CLI wizard does not hot-apply.
317
-
318
- When the wizard finishes it offers to start services and to chat right away,
319
- and prints the console access key (the random `channels[type=http].apiKey`
320
- scaffolded for you). Local access needs nothing; for LAN or remote access paste
321
- that key into the WebUI login page's "Access key" field.
322
-
323
- ```bash
324
- octopi serve start # gateway + web console; the wizard can do this for you
325
- octopi chat # TUI chat, same agent, same config
326
- octopi doctor # diagnose deployment/config, no LLM needed
327
- octopi --version # installed version (also: octopi version, or -v)
328
- ```
329
-
330
- Bare `octopi` follows the same rule: uninitialized → the init wizard,
331
- initialized → TUI chat.
332
-
333
- **Prefer the browser?** `octopi init --web` starts the service for you if it is
334
- not running (`serve start`, itself idempotent), then opens the Web wizard at the
335
- printed setup link. On a fresh deployment that link is what `octopi serve start`
336
- prints:
337
-
338
- ```text
339
- 🧙 First-run setup wizard (Web): http://localhost:8180/?setup=<token>
340
- ```
341
-
342
- (Port `8180` is the default; with `web.port` set, trust the printed link.) The
343
- link is valid for 30 minutes and revoked once the wizard completes. The setup
344
- endpoint requires that token from any source — loopback included — so nothing
345
- else on the machine can drive the wizard and rewrite the config; requests a
346
- browser sends from a non-local origin are refused. If no valid token exists
347
- (already configured, or expired), `--web` says so and points at the console
348
- instead of opening a page without a wizard. The CLI and Web wizards share one
349
- state machine and write the same config — pick either.
350
-
351
- **Non-interactive** (CI, dotfiles, scripted installs) — `--yes` skips the wizard
352
- and reads everything from flags plus env, so nothing is probed:
353
-
354
- ```bash
355
- OCTOPI_API_KEY=sk-… octopi init --yes --provider deepseek --model deepseek-flash
356
- ```
357
-
358
- `--yes` takes defaults plus env: `OCTOPI_API_KEY` (required by presets that need
359
- a key — omit it only for keyless `ollama`), `OCTOPI_DEPLOYMENT_MODE`,
360
- `OCTOPI_ADMIN_PASSWORD` (required by the org modes), `OCTOPI_ORG_NAME`,
361
- `OCTOPI_ADMIN_NAME`, `OCTOPI_LANG`. Defaults: provider `ollama`, deployment mode
362
- `personal`. `--web` hands off to the browser wizard; `--cli` forces the terminal
363
- one.
364
-
365
- **A second agent** (journey B) is a wizard of its own — pick a type, name it and
366
- say how it should address you, get pointed at attaching material, then try it.
367
- It needs an initialized deployment (the registry must have a user):
368
-
369
- ```bash
370
- octopi agent new
371
- ```
372
-
373
- ### Embed in code
374
-
375
- ```typescript
376
- import { AgentBuilder, OpenAIProvider } from 'octopi-agent';
377
-
378
- const { runner, runtime } = await new AgentBuilder()
379
- .model(new OpenAIProvider({
380
- apiKey: process.env.OPENAI_API_KEY!,
381
- models: ['gpt-6.1-terra'],
382
- defaultModel: 'gpt-6.1-terra',
383
- }))
384
- .persona('./my-agent')
385
- .build();
386
-
387
- const userMessage = { role: 'user' as const, content: 'hello', timestamp: Date.now() };
388
-
389
- for await (const event of runner.handle('session-1', userMessage, {
390
- systemPrompt: '', // let the runner resolve persona per run (hot-reload aware)
391
- agentId: 'default',
392
- sessionId: 'session-1',
393
- })) {
394
- if (event.type === 'llm_stream_delta') {
395
- process.stdout.write(String(event.data?.delta ?? ''));
396
- }
397
- }
398
-
399
- runtime?.dispose(); // autonomous subsystems hold timers — dispose so the process can exit
400
- ```
401
-
402
- `runner.handle()` is the session-aware entry: it owns the session lifecycle and
403
- write-back. Leaving `systemPrompt` empty lets the runner resolve persona per run
404
- (editing `AGENTS.md` takes effect on the next message); passing a string pins
405
- that prompt for the call. For a single agent with no host session store,
406
- `build({ mode: 'core' })` plus `agent.run()` is the library-level path. Hosts
407
- that already have a config file can skip the builder: `buildFromConfigFile()`
408
- returns a `Map` of `agentId → BuiltAgent` (`agent`, `runner`, `runtime`, …).
409
-
410
- ### Files as configuration
411
-
412
- Persona and skills are plain Markdown — diffable, reviewable, versionable.
413
- Extension = add a file. Composition = overlay directories.
414
-
415
- ```text
416
- my-agent/
417
- ├── AGENTS.md # main persona — loaded first
418
- ├── persona/ # supplemental persona, alphabetical
419
- │ ├── 10-soul.md
420
- │ ├── 20-identity.md
421
- │ └── 30-user.md
422
- └── skills/
423
- └── deploy/
424
- └── SKILL.md # two-stage loaded: metadata now, content on demand
425
- ```
426
-
427
- The learning substrate (Memory / Cognition / Wisdom) lives in a per-agent
428
- SQLite store — it is *grown*, not hand-written. See [docs/memory.md](./docs/memory.md).
429
-
430
- ### Mount MCP servers
431
-
432
- The MCP SDK client is an Integration adapter — import it from its subpath, not
433
- the package root:
434
-
435
- ```typescript
436
- import { AgentBuilder, OpenAIProvider } from 'octopi-agent';
437
- import { createSdkMcpClient } from '@octopi-agent/engine/integration';
438
-
439
- const { agent, runner, mcpManager, runtime } = await new AgentBuilder()
440
- .model(new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY!, models: ['gpt-6.1-terra'], defaultModel: 'gpt-6.1-terra' }))
441
- .persona('./my-agent')
442
- .mcpClientFactory(createSdkMcpClient)
443
- .mcp({
444
- id: 'filesystem',
445
- transport: 'stdio',
446
- command: 'npx',
447
- args: ['-y', '@modelcontextprotocol/server-filesystem', '/data'],
448
- })
449
- .build();
450
-
451
- // same loop as above, now with the MCP server's tools in the tool set
452
- console.log(agent.context.tools?.map((t) => t.name));
453
-
454
- await mcpManager.disconnectAll(); // MCP servers keep child processes alive
455
- runtime?.dispose();
456
- ```
457
-
458
- Tools arrive namespaced as `{serverId}__{toolName}` (separator `__`), so the
459
- server above registers its own tools under a `filesystem` prefix — two servers
460
- advertising the same tool name cannot collide.
461
-
462
- ---
463
-
464
529
  ## Capability tour
465
530
 
466
531
  | Capability | One-liner | Details |
@@ -515,14 +580,23 @@ theater; it is how the invariants stay invariant.
515
580
 
516
581
  Octopi is pre-1.0 and moving fast. Being honest about the edges:
517
582
 
518
- - **Deployment assumption**: single process is the v1 reality; cross-process
519
- requires a distributed Session Lease (in-process lease exists today).
583
+ - **Deployment assumption**: one gateway host running **multiple run
584
+ processes** is supported today — `fleet.replicasPerVersion` (up to 64) spawns
585
+ N run instances, sessions stay sticky to an instance, and a session gets at
586
+ most one live run (`lease_held` otherwise; the lease table lives in the
587
+ gateway, with `fleet.leaseTtlMs` as the TTL backstop). Quota, sessions, and
588
+ concurrency are scoped to that host.
520
589
  - **Collaboration domain** ships with `status: incomplete` — semantics are
521
590
  defined; some implementations are staged.
522
591
  - **Not for everyone**: if a single-vendor SDK's loop is enough, or you need a
523
592
  vertical business workflow engine, or human-level IAM inside the engine —
524
593
  Octopi is not what you want. It is an engine for products that need
525
594
  continuity, learning, and governance *below* their own product logic.
595
+ - **Concrete blockers** (check these before you start, not after):
596
+ - **Node.js ≥ 24 is a hard requirement.** We use the built-in `node:sqlite`
597
+ instead of shipping a native SQLite binding, because native bindings break
598
+ on cross-platform installs and are awkward to combine with vector search.
599
+ Node 22 and older will not install.
526
600
 
527
601
  Open items live in [docs/KNOWN-ISSUES.md](./docs/KNOWN-ISSUES.md).
528
602