@moikapy/lich 0.7.0 → 0.8.0
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/CHANGELOG.md +75 -5
- package/README.md +38 -9
- package/dist/{chunk-QVJCIZIF.js → chunk-EDRUZF22.js} +763 -286
- package/dist/chunk-EDRUZF22.js.map +1 -0
- package/dist/chunk-PL6MKRKE.js +75 -0
- package/dist/chunk-PL6MKRKE.js.map +1 -0
- package/dist/{chunk-JYURFAGB.js → chunk-QOTECFCN.js} +2 -2
- package/dist/chunk-VKEOHUCB.js +86 -0
- package/dist/chunk-VKEOHUCB.js.map +1 -0
- package/dist/{chunk-SAEB3QL3.js → chunk-W6JXZBUE.js} +2 -2
- package/dist/cli.d.ts +19 -1
- package/dist/cli.js +53 -11
- package/dist/cli.js.map +1 -1
- package/dist/{gateway-5BG3YCZF.js → gateway-WU5G4ODO.js} +109 -49
- package/dist/gateway-WU5G4ODO.js.map +1 -0
- package/dist/index.d.ts +46 -3
- package/dist/index.js +3 -2
- package/dist/resolve-H22TOVB5.js +7 -0
- package/dist/resolve-H22TOVB5.js.map +1 -0
- package/dist/store-COOLBAHB.js +9 -0
- package/dist/store-COOLBAHB.js.map +1 -0
- package/dist/{tui-L6RABP2J.js → tui-4BP3TI7J.js} +224 -30
- package/dist/tui-4BP3TI7J.js.map +1 -0
- package/docs/architecture/agent-loop.md +28 -9
- package/docs/architecture/overview.md +10 -10
- package/docs/architecture/tools.md +30 -3
- package/docs/getting-started.md +3 -3
- package/docs/index.md +1 -1
- package/docs/user-guide/cli.md +13 -5
- package/docs/user-guide/games.md +3 -3
- package/docs/user-guide/gateway.md +70 -16
- package/docs/user-guide/library.md +6 -3
- package/docs/user-guide/redot.md +2 -2
- package/docs/user-guide/tui.md +3 -2
- package/package.json +1 -1
- package/dist/chunk-QVJCIZIF.js.map +0 -1
- package/dist/gateway-5BG3YCZF.js.map +0 -1
- package/dist/tui-L6RABP2J.js.map +0 -1
- /package/dist/{chunk-JYURFAGB.js.map → chunk-QOTECFCN.js.map} +0 -0
- /package/dist/{chunk-SAEB3QL3.js.map → chunk-W6JXZBUE.js.map} +0 -0
|
@@ -38,8 +38,9 @@ result either way.
|
|
|
38
38
|
|
|
39
39
|
**`ToolContext`** gives each execution a working directory (`work_dir`, the
|
|
40
40
|
confinement root), a process environment map (the agent injects
|
|
41
|
-
`LICH_TERMINAL_TIMEOUT_MS`), and an abort `signal`
|
|
42
|
-
**or** the executor deadline
|
|
41
|
+
`LICH_TERMINAL_TIMEOUT_MS`), and an optional abort `signal` the agent passes
|
|
42
|
+
from `Agent.run` so tools cancel on caller abort **or** the executor deadline
|
|
43
|
+
(`tool.timeout_ms`, else
|
|
43
44
|
`DEFAULT_TOOL_TIMEOUT_MS` = 30000). `terminal` sets 300000, `run_tests` sets
|
|
44
45
|
600000, and registered MCP tools set 120000.
|
|
45
46
|
|
|
@@ -151,7 +152,7 @@ Docs tools join the list only when a docs root resolves.
|
|
|
151
152
|
| `edit_file` | `path`, `old_string`, `new_string`, `replace_all?` | Fails `old_string_not_found` / `old_string_not_unique (N)` unless `replace_all` - an exact-match protocol that forces the model to anchor edits. |
|
|
152
153
|
| `list_dir` | `path?`, `depth?` (1-4) | Iterative worklist (no recursion), dirs-first sorting, skips `node_modules`/`.git`/`dist`/`.lich`/`.cursor`, caps at 500 entries, file sizes via `stat`. |
|
|
153
154
|
| `terminal` | `command`, `timeout_ms?` | Spawns `bash -lc`, streams and caps stdout+stderr at 50 K chars, SIGKILLs on deadline, appends `[exit N]`; `ok` requires exit code 0 and no cancellation. |
|
|
154
|
-
| `grep_files` | `pattern`, `path?`, `glob?`, `max_results?` | Explicit stack walk (no recursion), binary sniff (NUL byte in first 1000 bytes), 1 MB file cap, `*.ext` suffix-glob matcher, overcollect-by-one to report suppressed counts. |
|
|
155
|
+
| `grep_files` | `pattern`, `path?`, `glob?`, `max_results?` | Explicit stack walk (no recursion), skips `SKIP_DIRS` entries and symbolic links, per-file `assert_file_tool_access` check (`.lich/config.json` is denied), binary sniff (NUL byte in first 1000 bytes), 1 MB file cap, `*.ext` suffix-glob matcher, overcollect-by-one to report suppressed counts. |
|
|
155
156
|
| `fetch_url` | `url`, `max_chars?`, `timeout_ms?` | GET only; rejects non-http(s) protocols; refuses images/octet-stream; tags HTML bodies with `[html content]`; status/type header line first. |
|
|
156
157
|
| `web_search` | `query`, `max_results?` | Scrapes DuckDuckGo's HTML endpoint (no API key); unwraps `uddg=` redirect links; decodes the handful of entities DDG emits. |
|
|
157
158
|
| `http_request` | `url`, `method?`, `headers?`, `body?`, ... | Method allowlist (GET/POST/PUT/PATCH/DELETE/HEAD/OPTIONS); stringified caller headers; reports `content-length`, `ratelimit-remaining`, `retry-after`. |
|
|
@@ -166,6 +167,32 @@ allowlist), `compose_abort_signal` (per-call `AbortSignal.timeout` merged
|
|
|
166
167
|
with the executor's cancellation via `AbortSignal.any`), and `clamp_int_arg`
|
|
167
168
|
(floored, bounded to `[1, max]`).
|
|
168
169
|
|
|
170
|
+
`grep_files` also runs `assert_file_tool_access` on every candidate path
|
|
171
|
+
(the same deny list as `read_file`/`write_file`/`edit_file`): a direct
|
|
172
|
+
grep of `.lich/config.json` fails with `forbidden_path:
|
|
173
|
+
.lich/config.json`. During the walk, symbolic links are skipped on the
|
|
174
|
+
same branch as `SKIP_DIRS`, so symlink entries are neither followed nor
|
|
175
|
+
searched.
|
|
176
|
+
|
|
177
|
+
### HTTP tools and `safe_fetch` - pinned outbound requests
|
|
178
|
+
|
|
179
|
+
`fetch_url` and `http_request` send every request through `safe_fetch`
|
|
180
|
+
([`src/tools/url_guard.ts`](../../src/tools/url_guard.ts)). Per hop:
|
|
181
|
+
|
|
182
|
+
1. `resolve_public_ip` resolves the hostname and rejects private,
|
|
183
|
+
loopback, link-local, and ULA addresses (`blocked_url:`), including
|
|
184
|
+
`localhost` / `*.localhost` / `*.local` names.
|
|
185
|
+
2. The request is then issued with the **original hostname** kept for
|
|
186
|
+
TLS/SNI and the `Host` header - the URL is not rewritten to the IP.
|
|
187
|
+
The connect is pinned instead: a custom DNS `lookup` function handed
|
|
188
|
+
to `http(s).request` returns only the already-vetted public IP.
|
|
189
|
+
3. Redirects are followed manually (`redirect: "manual"`) and every
|
|
190
|
+
`Location` hop is re-resolved and re-vetted, up to 5 hops.
|
|
191
|
+
|
|
192
|
+
The operator opt-out is exact: `LICH_ALLOW_PRIVATE_URLS=1` allows
|
|
193
|
+
private targets (the value is compared to `"1"`), while unset or any
|
|
194
|
+
other value is fail-closed and private URLs stay blocked.
|
|
195
|
+
|
|
169
196
|
## Docs search and skills
|
|
170
197
|
|
|
171
198
|
`docs_search` scores sections under the resolved docs root (memoized) and, when
|
package/docs/getting-started.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
12
|
npm install -g @moikapy/lich
|
|
13
|
-
lich --version # -> 0.
|
|
13
|
+
lich --version # -> 0.7.0 (reads package.json)
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Choose a configuration path
|
|
@@ -153,7 +153,7 @@ To hack on Lich itself, run the CLI straight from a clone instead of the npm pac
|
|
|
153
153
|
```sh
|
|
154
154
|
git clone https://github.com/Moikapy/lich.git && cd lich
|
|
155
155
|
bun install
|
|
156
|
-
bun src/cli.ts --version # -> 0.
|
|
156
|
+
bun src/cli.ts --version # -> 0.7.0 (package.json)
|
|
157
157
|
```
|
|
158
158
|
|
|
159
159
|
`bun src/cli.ts` accepts the same arguments as the installed `lich` binary, so every command on this page works unchanged.
|
|
@@ -165,4 +165,4 @@ bun src/cli.ts --version # -> 0.6.0 (package.json; MCP in this tree is unrelea
|
|
|
165
165
|
- Telegram, Discord, Twitch, and webhook setup: [Gateway guide](user-guide/gateway.md).
|
|
166
166
|
- Embedding the agent in your own TypeScript: [Library guide](user-guide/library.md).
|
|
167
167
|
- Session JSONL as a combat log: [Games guide](user-guide/games.md).
|
|
168
|
-
- Editor MCP (`lich mcp
|
|
168
|
+
- Editor MCP (`lich mcp`): [Redot guide](user-guide/redot.md). Play is still the [Godot guide](user-guide/godot.md).
|
package/docs/index.md
CHANGED
|
@@ -68,4 +68,4 @@ Working from a clone of the repository? `bun install`, then run the same command
|
|
|
68
68
|
|
|
69
69
|
## Version compatibility
|
|
70
70
|
|
|
71
|
-
The published npm package is **0.
|
|
71
|
+
The published npm package is **0.7.0**. `lich --version` reads `package.json`. Editor MCP (`mcp_servers`, `lich mcp`) ships in 0.7.0. Node >= 20 (`engines` in `package.json`); Bun is the recommended runtime for development from a clone (`bun src/cli.ts ...`). The TUI needs a TTY; the gateway and library run headless on both runtimes.
|
package/docs/user-guide/cli.md
CHANGED
|
@@ -19,7 +19,7 @@ lich mcp enable <name> # set enabled true
|
|
|
19
19
|
lich mcp disable <name>
|
|
20
20
|
lich mcp remove <name>
|
|
21
21
|
lich --help # usage text
|
|
22
|
-
lich --version # package.json version (published package and this tree: 0.
|
|
22
|
+
lich --version # package.json version (published package and this tree: 0.7.0)
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
- **Bare `lich`** opens the same TUI as `lich tui`. It does not print usage. On a TTY, if neither `.lich/config.json` nor `~/.config/lich/config.json` exists, a setup wizard runs first (name, provider, optional gateway env-var names, optional plugins) and writes `.lich/config.json` once. `LICH_MODEL` / `--model` prefills the model prompt; it does not skip the wizard. An existing config in that chain skips the wizard and is not replaced. Non-TTY stdin skips the wizard and prints guidance instead of hanging. `lich --help` still prints usage.
|
|
@@ -29,9 +29,9 @@ lich --version # package.json version (published package and this tree:
|
|
|
29
29
|
- **TUI** launches the ink interface. See the [TUI guide](tui.md).
|
|
30
30
|
- **Gateway** runs platform adapters (defaults to `webhook` when no platform is given). See the [Gateway guide](gateway.md). Unknown platform names are skipped with a warning; if none remain, the CLI exits `1`.
|
|
31
31
|
- **Update** compares the installed version to the npm registry and, when a newer release exists, runs `npm install -g @moikapy/lich@latest`. Exit any running TUI or gateway first; npm cannot replace the package while those processes are running. A git clone is told to `git pull`. See [Updating](../getting-started.md#updating).
|
|
32
|
-
- **MCP**
|
|
32
|
+
- **MCP** ships in 0.7.0 (`lich mcp`). It edits only `mcp_servers` in `<work-dir>/.lich/config.json` through the same writer as `lich init` (`update` mode, so other keys stay). A missing file lists as empty; `add` creates the file if needed. New entries stay disabled until `enable`. Names must match `^[a-z][a-z0-9_]*$`. Catalog names use `optional-mcps/`; otherwise pass `--command` and repeatable `--arg`, or `--url` (loopback only), not both. Redot still needs `--project-path` for the catalog args, and the command basename must be `redot`. No prompts. See the [Redot guide](redot.md).
|
|
33
33
|
|
|
34
|
-
A repository clone's `bun src/cli.ts` matches that checkout. The published 0.
|
|
34
|
+
A repository clone's `bun src/cli.ts` matches that checkout. The published 0.7.0 binary includes `lich mcp`.
|
|
35
35
|
|
|
36
36
|
## Flags
|
|
37
37
|
|
|
@@ -48,6 +48,7 @@ Flags work before or after the subcommand. Every value flag can also be set via
|
|
|
48
48
|
| `--api-key-env <NAME>` | Env var holding the api key for `providers[0]`. | `LICH_API_KEY_ENV`, else per-kind default |
|
|
49
49
|
| `--system-prompt <s>` | Replaces the default system prompt. | built-in concise-assistant prompt |
|
|
50
50
|
| `--session-dir <path>` | Transcript directory. | `<work_dir>/.lich/sessions` |
|
|
51
|
+
| `--resume <id\|latest>` | TUI only: load an existing session transcript into history. Exact id, unique filename prefix, or `latest` (newest by mtime). | – |
|
|
51
52
|
| `--log-level <level>` | `debug` \| `info` \| `warn` \| `error`. | `info` |
|
|
52
53
|
| `--theme <name>` | Display theme loaded once at startup. `lich` is built-in; other names read `~/.lich/themes/<name>.json`. | `lich` |
|
|
53
54
|
| `--command <bin>` | `lich mcp add` only: local stdio binary. | – |
|
|
@@ -55,7 +56,7 @@ Flags work before or after the subcommand. Every value flag can also be set via
|
|
|
55
56
|
| `--url <url>` | `lich mcp add` only: loopback HTTP MCP URL. | – |
|
|
56
57
|
| `--project-path <path>` | `lich mcp add` only: catalog `${project_path}` substitute. | – |
|
|
57
58
|
|
|
58
|
-
Passing `--max-turns 0` or a non-integer fails with `--max-turns must be a positive integer`. Unknown flags fail with `unknown flag: --foo`. A flag missing its value fails with `<flag> requires a value`.
|
|
59
|
+
Passing `--max-turns 0` or a non-integer fails with `--max-turns must be a positive integer`. Unknown flags fail with `unknown flag: --foo`. A flag missing its value fails with `<flag> requires a value`. `--resume` outside the TUI (one-shot, `chat`, `gateway`) fails with `--resume is only supported in TUI mode (not <mode>)`.
|
|
59
60
|
|
|
60
61
|
## Provider resolution
|
|
61
62
|
|
|
@@ -127,7 +128,7 @@ Validated by zod (top-level unknown keys are silently stripped; extra keys insid
|
|
|
127
128
|
| `theme` | string | `lich` | Display theme name. See [Themes](https://github.com/Moikapy/lich/blob/main/README.md#themes). |
|
|
128
129
|
| `gateway` | object | omitted | Optional. `platforms` (`webhook` \| `telegram` \| `discord` \| `twitch`) and `token_envs` (platform → env-var name). Secrets stay in the environment. |
|
|
129
130
|
| `plugins` | string array | `[]` | Module paths relative to `work_dir` or absolute. Bare `lich`, one-shot, chat, tui, and gateway load them through `create_agent_with_plugins`. `run_agent` does too. `create_agent` does not. See the [plugins guide](plugins.md). |
|
|
130
|
-
| `mcp_servers` | object | omitted | Optional. Closed record of named servers. Each entry is stdio `{command, args, env?}` or loopback http `{url}`. `enabled` defaults to false. Unknown keys are rejected.
|
|
131
|
+
| `mcp_servers` | object | omitted | Optional. Closed record of named servers. Each entry is stdio `{command, args, env?}` or loopback http `{url}`. `enabled` defaults to false. Unknown keys are rejected. Ships in 0.7.0. See the [Redot guide](redot.md). |
|
|
131
132
|
| `system_prompt` | string | built-in | Replaces the default system prompt. |
|
|
132
133
|
| `max_turns` | int >= 1 | `25` | Turn budget per run. |
|
|
133
134
|
| `work_dir` | string | cwd | Root for all file tools; paths outside are rejected. |
|
|
@@ -160,6 +161,7 @@ never accepted as a config passthrough.
|
|
|
160
161
|
| Variable | Meaning |
|
|
161
162
|
| --- | --- |
|
|
162
163
|
| `LICH_ALLOW_SELF_COMMIT` | Set to `1` to allow one gated `git_commit` per run. Unset or any other value is fail-closed. Read at agent construction. |
|
|
164
|
+
| `LICH_ALLOW_PRIVATE_URLS` | Set to exactly `1` to let `fetch_url` / `http_request` reach private or loopback URLs. Unset or any other value is fail-closed (they are blocked). |
|
|
163
165
|
| `LICH_TEST_COMMAND` | Command `run_tests` runs in `work_dir` (default `node node_modules/vitest/vitest.mjs run`). An optional `filter` argument is appended. |
|
|
164
166
|
|
|
165
167
|
Veto reasons, the terminal git denylist, skills, and `MEMORY.md` are in the
|
|
@@ -173,6 +175,12 @@ Each run writes `.lich/sessions/<timestamp36>-<counter>[-label].jsonl` where the
|
|
|
173
175
|
# follow the newest session
|
|
174
176
|
ls -t .lich/sessions/*.jsonl | head -1
|
|
175
177
|
|
|
178
|
+
# resume that session in the TUI (loads history; new turns append to one
|
|
179
|
+
# per-launch transcript via incremental persistence).
|
|
180
|
+
# Inside a running TUI, `/resume <id|latest>` uses the same load path (Phase 3).
|
|
181
|
+
lich --resume latest
|
|
182
|
+
lich tui --resume m1abc-1-tui
|
|
183
|
+
|
|
176
184
|
# print the conversation
|
|
177
185
|
jq -r 'select(.kind=="message") | "\(.message.role): \(.message.content // "(tool call)")"' .lich/sessions/<file>.jsonl
|
|
178
186
|
```
|
package/docs/user-guide/games.md
CHANGED
|
@@ -8,7 +8,7 @@ Tool shapes live in [`examples/game_bridge/README.md`](https://github.com/Moikap
|
|
|
8
8
|
|
|
9
9
|
## Session files as combat logs
|
|
10
10
|
|
|
11
|
-
Each `Agent.run` appends one `.jsonl` file under `session_dir` (default `<work_dir>/.lich/sessions`). Records are `{ts, kind: "message"|"meta", message?, meta?}`.
|
|
11
|
+
Each `Agent.run` without a shared `session` handle appends one `.jsonl` file under `session_dir` (default `<work_dir>/.lich/sessions`). The TUI passes one handle per launch so N turns share one file. Records are `{ts, kind: "message"|"meta", message?, meta?}`.
|
|
12
12
|
|
|
13
13
|
| What you want | Where it is |
|
|
14
14
|
| --- | --- |
|
|
@@ -75,9 +75,9 @@ Recipe 2 counts assistant tool-call arguments, including orders a hook later vet
|
|
|
75
75
|
|
|
76
76
|
## Do not glob a playthrough blindly
|
|
77
77
|
|
|
78
|
-
A gateway conversation of N posts writes N files. `Agent.run` seeds from `history`, and `
|
|
78
|
+
A gateway conversation of N posts writes N files. `Agent.run` seeds from `history`, and without a shared `session` handle each run opens a new file that includes prior history plus the new exchange, so each file is a superset of the previous. Globbing `*.jsonl` double-counts. Take the newest file per label (names sort by timestamp prefix), or dedupe on `tool_call.id`, which stays stable when the same call is replayed into the next file. TUI launches avoid this by sharing one handle.
|
|
79
79
|
|
|
80
|
-
Compression can rewrite
|
|
80
|
+
Compression can rewrite in-memory history: when estimated tokens cross `compress_threshold` of `context_budget_tokens`, older messages become one summary and the 8 most recent non-system messages stay verbatim. The transcript keeps raw pre-compress messages plus a `compress_end` meta marker; on resume those raw messages replay and compression may run again. Early rounds may survive only as the in-memory summary for the live agent. Offline recipes see the file on disk.
|
|
81
81
|
|
|
82
82
|
## Player modeling
|
|
83
83
|
|
|
@@ -27,37 +27,54 @@ lich gateway # defaults to webhook
|
|
|
27
27
|
|
|
28
28
|
The gateway is silent after startup: Telegram/Discord/Twitch respond only in chats, channels, or servers the bot can see or has joined, and the webhook only serves HTTP. Telegram media messages arrive as the placeholder text `media not supported yet`; other non-text events are ignored. Telegram `/start` is answered like a plain "hello".
|
|
29
29
|
|
|
30
|
+
**Security defaults:** the webhook binds loopback only; Telegram/Discord/Twitch default-deny until you configure allowlists; the gateway agent uses a read-only tool subset (no `terminal`, no file writes) unless you override `gateway.tools_enabled`.
|
|
31
|
+
|
|
30
32
|
## Setup: webhook
|
|
31
33
|
|
|
32
|
-
Zero configuration — the server binds `
|
|
34
|
+
Zero configuration for local use — the server binds `127.0.0.1:$LICH_GATEWAY_PORT` (default 8089). Set `LICH_GATEWAY_HOST` only when you intentionally expose the port.
|
|
33
35
|
|
|
34
36
|
```sh
|
|
35
37
|
lich gateway webhook
|
|
36
38
|
```
|
|
37
39
|
|
|
38
40
|
```sh
|
|
39
|
-
curl -s -X POST http://
|
|
41
|
+
curl -s -X POST http://127.0.0.1:8089/message \
|
|
40
42
|
-H "content-type: application/json" -d '{"text": "hello"}'
|
|
41
43
|
# -> {"reply":"...","usage":null}
|
|
42
44
|
|
|
43
|
-
curl -s http://
|
|
45
|
+
curl -s http://127.0.0.1:8089/health
|
|
44
46
|
# -> {"status":"ok"}
|
|
45
47
|
```
|
|
46
48
|
|
|
49
|
+
To bind a non-loopback address you **must** set a token; otherwise the adapter refuses to start:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
LICH_GATEWAY_HOST=0.0.0.0 LICH_GATEWAY_TOKEN=s3cret lich gateway webhook
|
|
53
|
+
```
|
|
54
|
+
|
|
47
55
|
With token auth, every POST must carry the exact `x-lich-token` header; mismatched or missing tokens get `401 {"error":"unauthorized"}`:
|
|
48
56
|
|
|
49
57
|
```sh
|
|
50
58
|
LICH_GATEWAY_TOKEN=s3cret lich gateway webhook
|
|
51
|
-
curl -s -X POST http://
|
|
59
|
+
curl -s -X POST http://127.0.0.1:8089/message \
|
|
52
60
|
-H "x-lich-token: s3cret" -H "content-type: application/json" -d '{"text": "hello"}'
|
|
53
61
|
```
|
|
54
62
|
|
|
55
|
-
Payload fields (all optional except `text`): `
|
|
63
|
+
Payload fields (all optional except `text`): `chat_id` (default `"default"`), `user_id` (default `"anonymous"`), `text` (required; missing `text` is a `400`). A `platform` field in the body is **ignored** — conversations are always keyed as `webhook:<chat_id>`. Use distinct `chat_id` values to keep independent conversation memories.
|
|
56
64
|
|
|
57
65
|
## Setup: Telegram
|
|
58
66
|
|
|
59
67
|
1. Message [@BotFather](https://t.me/BotFather) → `/newbot` → copy the token.
|
|
60
|
-
2.
|
|
68
|
+
2. Allow your user (and optionally chat) ids in config, export the bot token, and run:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"gateway": {
|
|
73
|
+
"allowed_users": { "telegram": ["123456789"] },
|
|
74
|
+
"allowed_chats": { "telegram": ["123456789"] }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
61
78
|
|
|
62
79
|
```sh
|
|
63
80
|
export LICH_TELEGRAM_BOT_TOKEN=123456:ABC-your-token
|
|
@@ -66,14 +83,22 @@ lich gateway telegram
|
|
|
66
83
|
|
|
67
84
|
3. Open your bot in Telegram, send a message, get a reply. Media messages arrive as the text `media not supported yet`; the bot replies from there.
|
|
68
85
|
|
|
69
|
-
Telegram uses long polling (no public URL needed). Replies split at 4096 chars.
|
|
86
|
+
Without `allowed_users` / `allowed_chats` for `telegram`, every inbound message is denied (default-deny). Telegram uses long polling (no public URL needed). Replies split at 4096 chars.
|
|
70
87
|
|
|
71
88
|
## Setup: Discord
|
|
72
89
|
|
|
73
90
|
1. Create an application at the [Discord developer portal](https://discord.com/developers/applications), add a **Bot**, and copy the bot token.
|
|
74
91
|
2. Enable the **Message Content Intent** (Bot settings → Privileged Gateway Intents) — the adapter requests intents `512 | 32768`, which includes message content.
|
|
75
92
|
3. Invite the bot with the `bot` scope (OAuth2 → URL Generator; no extra permissions needed beyond sending messages in target channels).
|
|
76
|
-
4.
|
|
93
|
+
4. Allow channel and/or user ids in config, export the token (and the bot's application/user id, so leading `<@BOT_ID>` mentions are stripped) and run:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"gateway": {
|
|
98
|
+
"allowed_chats": { "discord": ["123456789012345678"] }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
77
102
|
|
|
78
103
|
```sh
|
|
79
104
|
export LICH_DISCORD_BOT_TOKEN=your-bot-token
|
|
@@ -81,14 +106,23 @@ export LICH_DISCORD_BOT_ID=123456789012345678
|
|
|
81
106
|
lich gateway discord
|
|
82
107
|
```
|
|
83
108
|
|
|
84
|
-
5. Send the bot a message
|
|
109
|
+
5. Send the bot a message in an allowed channel; each channel has its own conversation memory (keyed by `channel_id`). Replies split at 2000 chars. Bot-authored messages are ignored (no loops). Without allowlists for `discord`, every inbound message is denied.
|
|
85
110
|
|
|
86
111
|
**Known limitation:** the Discord adapter has no reconnect resume. If its gateway WebSocket drops, messages sent while offline are missed permanently; the adapter reconnects fresh after 5s. If guaranteed delivery across disconnects matters, run webhook or Telegram instead.
|
|
87
112
|
|
|
88
113
|
## Setup: Twitch
|
|
89
114
|
|
|
90
115
|
1. Generate an OAuth token with the `chat:read` and `chat:edit` scopes (for example via [twitchtokengen](https://twitchtokengen.com)).
|
|
91
|
-
2.
|
|
116
|
+
2. Allow channel names and/or viewer nicks in config, export credentials, and run:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"gateway": {
|
|
121
|
+
"allowed_chats": { "twitch": ["channelone"] },
|
|
122
|
+
"allowed_users": { "twitch": ["trustedviewer"] }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
92
126
|
|
|
93
127
|
```sh
|
|
94
128
|
export LICH_TWITCH_OAUTH_TOKEN=oauth:abc123...
|
|
@@ -97,9 +131,28 @@ export LICH_TWITCH_CHANNELS=channelone,channeltwo
|
|
|
97
131
|
lich gateway twitch
|
|
98
132
|
```
|
|
99
133
|
|
|
100
|
-
3. The bot joins `#channelone` and `#channeltwo` and replies in chat (own messages are ignored). Replies split at 512 chars; IRC PING/PONG is answered automatically.
|
|
134
|
+
3. The bot joins `#channelone` and `#channeltwo` and replies in chat only when the allowlist matches (own messages are ignored). Replies split at 512 chars; IRC PING/PONG is answered automatically.
|
|
135
|
+
|
|
136
|
+
Only real chat messages count for the allowlist: the adapter strips optional IRC tags and then requires a full `PRIVMSG` line (`^:<nick>!... PRIVMSG #<channel> :<text>`), so Twitch events such as `USERNOTICE` (raids, subs) and `WHISPER` are ignored even if their text contains something that looks like a `PRIVMSG` — they can never impersonate an allowed user or channel.
|
|
137
|
+
|
|
138
|
+
All three fields (`token`, `nick`, `channels`) are required — a missing one idles the adapter. Without allowlists for `twitch`, every inbound message is denied.
|
|
139
|
+
|
|
140
|
+
## Allowlists and gateway tools
|
|
141
|
+
|
|
142
|
+
Public platforms (telegram, discord, twitch) are **default-deny**. Configure at least one of:
|
|
143
|
+
|
|
144
|
+
| Field | Meaning |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| `gateway.allowed_users.<platform>` | User ids (Telegram/Discord) or nicks (Twitch) that may talk to the bot. |
|
|
147
|
+
| `gateway.allowed_chats.<platform>` | Chat / channel ids (or Twitch channel names) that may talk to the bot. |
|
|
148
|
+
|
|
149
|
+
If both lists are set for a platform, a message must match **both**. If only one list is set, the other dimension is unrestricted. Enforcement lives in the shared gateway bus — denied senders get no agent run and no reply.
|
|
150
|
+
|
|
151
|
+
The gateway agent ignores top-level `tools_enabled` and uses `gateway.tools_enabled`, which defaults to a read-only subset:
|
|
152
|
+
|
|
153
|
+
`read_file`, `list_dir`, `grep_files`, `fetch_url`, `web_search`, `docs_read`, `docs_search`
|
|
101
154
|
|
|
102
|
-
|
|
155
|
+
Set `"gateway": { "tools_enabled": "all" }` (or an explicit name list) only when you intentionally want writes / `terminal` on chat platforms.
|
|
103
156
|
|
|
104
157
|
## Running multiple platforms at once
|
|
105
158
|
|
|
@@ -116,8 +169,9 @@ Adapters whose credentials are missing start **idle** (a warning is logged, e.g.
|
|
|
116
169
|
|
|
117
170
|
| Variable | Default | Purpose |
|
|
118
171
|
| --- | --- | --- |
|
|
172
|
+
| `LICH_GATEWAY_HOST` | `127.0.0.1` | Webhook bind address. Non-loopback requires `LICH_GATEWAY_TOKEN`. |
|
|
119
173
|
| `LICH_GATEWAY_PORT` | `8089` | Webhook server port (invalid/empty values fall back to 8089). |
|
|
120
|
-
| `LICH_GATEWAY_TOKEN` | unset | If set, POST `/message` requires header `x-lich-token` to match; else 401. |
|
|
174
|
+
| `LICH_GATEWAY_TOKEN` | unset | If set, POST `/message` requires header `x-lich-token` to match; else 401. Required for non-loopback binds. |
|
|
121
175
|
| `LICH_TELEGRAM_BOT_TOKEN` | unset | Bot token from BotFather; adapter idles without it. |
|
|
122
176
|
| `LICH_DISCORD_BOT_TOKEN` | unset | Bot token from the developer portal; adapter idles without it. |
|
|
123
177
|
| `LICH_DISCORD_BOT_ID` | unset | Bot user id; strips a leading `<@id>` mention from messages. |
|
|
@@ -143,10 +197,10 @@ Provider/model configuration comes from the same resolution as every mode (`LICH
|
|
|
143
197
|
Request:
|
|
144
198
|
|
|
145
199
|
```json
|
|
146
|
-
{"text": "hello", "
|
|
200
|
+
{"text": "hello", "chat_id": "default", "user_id": "anonymous"}
|
|
147
201
|
```
|
|
148
202
|
|
|
149
|
-
Only `text` is required. Success (`200`):
|
|
203
|
+
Only `text` is required. Any `platform` field in the body is ignored; the conversation key is always `webhook:<chat_id>`. Success (`200`):
|
|
150
204
|
|
|
151
205
|
```json
|
|
152
206
|
{"reply":"Hello! How can I help you today? ...","usage":null}
|
|
@@ -165,4 +219,4 @@ Agent-level failures (e.g. every provider failed) return `200` with `reply` set
|
|
|
165
219
|
|
|
166
220
|
### `GET /health`
|
|
167
221
|
|
|
168
|
-
`200 {"status":"ok"}` unconditionally — the webhook server itself is alive; it does not reflect platform adapters or provider health.
|
|
222
|
+
`200 {"status":"ok"}` unconditionally — the webhook server itself is alive; it does not reflect platform adapters or provider health.
|
|
@@ -62,7 +62,8 @@ const result = await run_agent(
|
|
|
62
62
|
| `input` | `string` | Required user message for this run. |
|
|
63
63
|
| `history` | `Message[]` | Prior conversation to continue (multi-turn). |
|
|
64
64
|
| `signal` | `AbortSignal` | Cooperative cancellation; the loop returns `outcome.stopped_reason: "aborted"`. |
|
|
65
|
-
| `label` | `string` | Origin tag for the session filename (e.g. `"tui"`, `"gw:webhook:default"`). |
|
|
65
|
+
| `label` | `string` | Origin tag for the session filename (e.g. `"tui"`, `"gw:webhook:default"`). Unused when `session` is set. |
|
|
66
|
+
| `session` | `SessionHandle` | Optional shared transcript handle. When set, `Agent.run` reuses it instead of opening a new file (TUI: one handle per launch). |
|
|
66
67
|
|
|
67
68
|
`AgentRunResult`:
|
|
68
69
|
|
|
@@ -147,7 +148,7 @@ Listed providers form a failover chain tried in order: `rate_limit`/`network` er
|
|
|
147
148
|
|
|
148
149
|
`tools_enabled` accepts `"all"` (default) or an array of tool names to register; everything else stays unregistered and invisible to the model. MCP tools, when a named server is `enabled`, use the same allowlist and stay off when the list is `[]` (that empty list does not connect). The filter does not apply to plugin tools: they register afterward, including the gatekeeper's `git_commit` (fail-closed unless `LICH_ALLOW_SELF_COMMIT=1`). `[]` strips every builtin and every MCP tool and does not throw.
|
|
149
150
|
|
|
150
|
-
`mcp_servers` and `catalog_client_entry`
|
|
151
|
+
`mcp_servers` and `catalog_client_entry` ship in 0.7.0. See the [Redot guide](redot.md).
|
|
151
152
|
|
|
152
153
|
```ts
|
|
153
154
|
const agent = create_agent({
|
|
@@ -190,4 +191,6 @@ A Godot client does not embed the library. A game backend that does is still one
|
|
|
190
191
|
|
|
191
192
|
## Session access
|
|
192
193
|
|
|
193
|
-
Each `run()` appends a transcript
|
|
194
|
+
Each `run()` appends to a JSONL transcript under `config.session_dir` (default `<work_dir>/.lich/sessions`) while the loop runs: `run_start`, seeded system/user (plus history when the handle is new), then assistant/tool messages on `llm_end` / `tool_call_end`, optional `budget_exhausted` / `compress_end` meta, and `run_end` (`stopped_reason`, `usage` matching `usage_total`) when the run completes. Pass `session` to reuse one handle across runs (the TUI does this so one launch = one file). Omit it for per-run files (one-shot, chat, gateway). `result.session_path` is the handle path when recording started. Records carry `{ts, kind: "message"|"meta", message?, meta?}`. Provider throws leave whatever was already appended; they do not write `run_end`. `read_session_messages` drops a trailing user message so resume does not start with two consecutive user turns. Read transcripts with `jq` (see the [games guide](games.md)) or `read_session_messages(path)` from a source checkout — it is not a package export. Persistence is best-effort: a write failure logs a warning and never fails the run.
|
|
195
|
+
|
|
196
|
+
**CLI resume:** `lich --resume <id|latest>` (TUI only) resolves a transcript via `src/session/resolve.ts`, loads messages with `read_session_messages`, and seeds the TUI history. New turns append into the launch's shared handle (history is written once on first seed).
|
package/docs/user-guide/redot.md
CHANGED
|
@@ -22,13 +22,13 @@ The client is general, the same shape as Hermes and Claude: a named list you ext
|
|
|
22
22
|
}
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
stdio is a local binary you named, plus `args`, plus optional `env`. The process is spawned with those argv, never a shell. `npx`, `npm`, `bunx`, `uvx`, `curl`, `wget`, a URL, and shell metacharacters are refused. lich does not run `npx -y` or fetch an addon. Values in `env` are passed to the process and are never logged. `lich mcp add` has no flag for `env`; set that key in the file if you need it.
|
|
25
|
+
stdio is a local binary you named, plus `args`, plus optional `env`. The process is spawned with those argv, never a shell. `npx`, `npm`, `bunx`, `uvx`, `curl`, `wget`, a URL, and shell metacharacters are refused. lich does not run `npx -y` or fetch an addon. Values in `env` are passed to the process and are never logged. `lich mcp add` has no flag for `env`; set that key in the file if you need it. On Bun, the spawned child is not `unref`'d, so one-shot and other short-lived runs wait for the MCP answer instead of exiting while the child is still working; `Agent.close()` (every CLI mode calls it) kills the child.
|
|
26
26
|
|
|
27
27
|
HTTP is `{ "url": "http://127.0.0.1:9/mcp" }`. The host must be `127.0.0.1` or `localhost`. `0.0.0.0` and any other host are refused. There is no remote MCP in v1.
|
|
28
28
|
|
|
29
29
|
On connect the client sends `initialize`, then `notifications/initialized`, then `tools/list`. `tools/call` runs only when the model invokes a registered tool. Registered names are `mcp_<server>_<tool>`, so two servers cannot collide. They appear only when that server is `enabled` and `tools_enabled` is `"all"` or lists the prefixed name. `tools_enabled: []` drops them even when the server is enabled, and does not connect. Plugin tools still register, including the gatekeeper's `git_commit`. The commander persona keeps `tools_enabled: []` and the `game_bridge` plugin only — `persona_config` does not copy `mcp_servers`.
|
|
30
30
|
|
|
31
|
-
This client
|
|
31
|
+
This client ships in 0.7.0 (`lich mcp`, `mcp_servers`). From a clone, use `bun src/cli.ts mcp ...`.
|
|
32
32
|
|
|
33
33
|
## Add a server
|
|
34
34
|
|
package/docs/user-guide/tui.md
CHANGED
|
@@ -9,12 +9,12 @@ lich # front door: TUI, plus a first-run setup wizard when no config exi
|
|
|
9
9
|
lich tui # same TUI, no wizard. From a clone: bun src/cli.ts tui
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
The TUI needs a TTY and a resolvable provider (same resolution as every mode). On startup it prints a dim header from the active theme welcome string, e.g. `⚱ lich v0.
|
|
12
|
+
The TUI needs a TTY and a resolvable provider (same resolution as every mode). On startup it prints a dim header from the active theme welcome string, e.g. `⚱ lich v0.7.0 — the agent that will not stay dead · llama3.2 (ollama)`. `{version}` is `LICH_VERSION` from `package.json`. That banner is the only tagline placement. Quit with `/exit`, `/quit`, `/q`, or Ctrl+C.
|
|
13
13
|
|
|
14
14
|
## Anatomy
|
|
15
15
|
|
|
16
16
|
```
|
|
17
|
-
⚱ lich v0.
|
|
17
|
+
⚱ lich v0.7.0 — the agent that will not stay dead · llama3.2 (ollama)
|
|
18
18
|
mortal › list the files here <- your input, echoed into the transcript
|
|
19
19
|
⏺ list_dir({}) <- live tool-call row (name + args preview)
|
|
20
20
|
⏷ list_dir: ok (d src/ d test/ ...) <- result row (ok/error + output preview)
|
|
@@ -37,6 +37,7 @@ model llama3.2 · turns 2 · tokens 1,204 · [dormant] · /path/.lich/sessions/.
|
|
|
37
37
|
| `/usage` | Show tokens used this session (cumulative across turns). |
|
|
38
38
|
| `/clear` | Wipe the on-screen transcript. Does **not** reset agent memory — the next message still sees prior turns. |
|
|
39
39
|
| `/sessions` | List the 10 newest `.jsonl` files in `session_dir` with sizes. The heading uses the theme sessions label (`phylacteries (n):` by default). |
|
|
40
|
+
| `/resume <id\|latest>` | Load a stored transcript into agent history (exact id, unique prefix, or `latest` by mtime — same resolver as `--resume`). Resets the on-screen transcript with a `· resumed <id> (n messages)` notice and updates the header banner. Missing/ambiguous ids print an error notice. |
|
|
40
41
|
| `/exit`, `/quit`, `/q` | Exit the TUI. |
|
|
41
42
|
|
|
42
43
|
Unknown commands print `· unknown command: /x (try /help)`. Slash commands are handled client-side and never invoke the model.
|