@moikapy/lich 0.3.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 +24 -0
- package/README.md +186 -0
- package/dist/chunk-P52U5M3L.js +3431 -0
- package/dist/chunk-P52U5M3L.js.map +1 -0
- package/dist/chunk-ZVK3MUPC.js +7 -0
- package/dist/chunk-ZVK3MUPC.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +409 -0
- package/dist/cli.js.map +1 -0
- package/dist/gateway-CWPVIU3W.js +752 -0
- package/dist/gateway-CWPVIU3W.js.map +1 -0
- package/dist/index.d.ts +542 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/tui-V7ATLIKW.js +430 -0
- package/dist/tui-V7ATLIKW.js.map +1 -0
- package/docs/.vitepress/config.mts +55 -0
- package/docs/architecture/agent-loop.md +234 -0
- package/docs/architecture/extending.md +284 -0
- package/docs/architecture/overview.md +188 -0
- package/docs/architecture/plugins.md +91 -0
- package/docs/architecture/providers.md +273 -0
- package/docs/architecture/tools.md +180 -0
- package/docs/design/council/architecture-review.md +47 -0
- package/docs/design/council/security-review.md +39 -0
- package/docs/design/council/simplicity-review.md +45 -0
- package/docs/design/self-improvement-loop.md +166 -0
- package/docs/getting-started.md +133 -0
- package/docs/index.md +68 -0
- package/docs/user-guide/cli.md +182 -0
- package/docs/user-guide/gateway.md +168 -0
- package/docs/user-guide/library.md +181 -0
- package/docs/user-guide/plugins.md +120 -0
- package/docs/user-guide/tui.md +76 -0
- package/package.json +54 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- Plugin system (v0.3.0): load user-authored tools and lifecycle hooks from
|
|
6
|
+
explicit module paths (`plugins` config array). Hooks cover
|
|
7
|
+
`before_tool_call` (veto with `blocked_by_plugin`), `after_tool_call`,
|
|
8
|
+
`on_run_start`, and `on_run_end`; broken plugins warn and are skipped.
|
|
9
|
+
New API: `create_agent_with_plugins`, `load_plugins`, `HookedToolRunner`,
|
|
10
|
+
`Plugin`/`PluginHooks`/`LoadedPlugin` types. Docs:
|
|
11
|
+
docs/user-guide/plugins.md, docs/architecture/plugins.md.
|
|
12
|
+
|
|
13
|
+
## 0.2.0
|
|
14
|
+
|
|
15
|
+
- Gateway: route Telegram, Discord, Twitch, and a zero-config webhook HTTP
|
|
16
|
+
endpoint into one shared agent with per-conversation memory (webhook serves
|
|
17
|
+
`POST /message` + `GET /health`, optional `x-lich-token` auth).
|
|
18
|
+
- Ink terminal UI: `lich tui` with live transcript (tool-call rows), status
|
|
19
|
+
bar (model/turns/tokens), slash commands, and input history recall.
|
|
20
|
+
- Six new builtin tools: `fetch_url`, `web_search`, `http_request`,
|
|
21
|
+
`process_list`, `disk_usage`, `env_get` (12 builtins total).
|
|
22
|
+
- Multi-turn history API: `AgentRunOptions.history` + `AgentRunResult.messages`.
|
|
23
|
+
- Ollama provider (local + cloud, optional bearer auth, `think`/`keep_alive`).
|
|
24
|
+
- README: gateway + TUI documentation and the four CLI modes.
|
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# lich
|
|
2
|
+
|
|
3
|
+
Lich is a TypeScript AI agent harness (library + CLI) that runs a
|
|
4
|
+
Think-Act-Observe loop: an LLM plans, calls tools, observes results, and
|
|
5
|
+
repeats until it produces a final answer. It ships with provider failover,
|
|
6
|
+
tool guardrails, context compression, and JSONL session persistence.
|
|
7
|
+
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
10
|
+
| Page | Contents |
|
|
11
|
+
| --- | --- |
|
|
12
|
+
| [Docs home](docs/index.md) | Overview, feature map, and a 60-second quickstart. |
|
|
13
|
+
| [Getting started](docs/getting-started.md) | Zero-to-first-reply: install, config paths, one-shot, TUI, gateway. |
|
|
14
|
+
| [CLI reference](docs/user-guide/cli.md) | All four modes, flags, provider resolution, config schema, recipes. |
|
|
15
|
+
| [TUI guide](docs/user-guide/tui.md) | Launch, slash commands, status bar, memory semantics. |
|
|
16
|
+
| [Gateway guide](docs/user-guide/gateway.md) | Webhook/Telegram/Discord/Twitch setup and the webhook API. |
|
|
17
|
+
| [Library guide](docs/user-guide/library.md) | Embedding: `create_agent`, events, multi-turn history, errors. |
|
|
18
|
+
|
|
19
|
+
## Quick start (CLI)
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
# one-shot task
|
|
23
|
+
LICH_MODEL=gpt-4.1-mini LICH_PROVIDER_KIND=openai_compat bun src/cli.ts "summarize this repo"
|
|
24
|
+
|
|
25
|
+
# interactive chat (commands: /exit, /quit)
|
|
26
|
+
LICH_MODEL=claude-sonnet-4 LICH_PROVIDER_KIND=anthropic bun src/cli.ts chat
|
|
27
|
+
|
|
28
|
+
# local ollama (no api key needed)
|
|
29
|
+
ollama pull llama3.2
|
|
30
|
+
LICH_PROVIDER_KIND=ollama LICH_MODEL=llama3.2 bun src/cli.ts "hello"
|
|
31
|
+
|
|
32
|
+
# terminal UI
|
|
33
|
+
lich tui
|
|
34
|
+
|
|
35
|
+
# messaging gateway (webhook | telegram | discord | twitch)
|
|
36
|
+
lich gateway webhook
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The CLI has four modes: **one-shot** (`lich "task"`), **chat**
|
|
40
|
+
(`lich chat`), **tui** (`lich tui`), and **gateway**
|
|
41
|
+
(`lich gateway <platform...>`).
|
|
42
|
+
|
|
43
|
+
Or use a JSON config file: `bun src/cli.ts --config lich.json "task"` (see
|
|
44
|
+
`AgentConfig` in `src/agent/config.ts` for the schema).
|
|
45
|
+
|
|
46
|
+
## Library usage
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { run_agent } from "lich";
|
|
50
|
+
|
|
51
|
+
const result = await run_agent(
|
|
52
|
+
{
|
|
53
|
+
providers: [
|
|
54
|
+
{ kind: "ollama", name: "local", model: "llama3.2:latest" },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
"Use the list_dir tool to list files, then summarize.",
|
|
58
|
+
);
|
|
59
|
+
console.log(result.outcome.final?.content);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Tools
|
|
63
|
+
|
|
64
|
+
Twelve builtins ship with the agent (`register_builtin_tools`); all accept
|
|
65
|
+
snake_case args and are registered under the `builtin` toolset.
|
|
66
|
+
|
|
67
|
+
| Tool | Purpose |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `read_file` | Read a text file inside the working directory, with optional offset/limit. |
|
|
70
|
+
| `write_file` | Write (or overwrite) a file inside the working directory. |
|
|
71
|
+
| `edit_file` | Replace a unique string in a file, with an optional replace-all. |
|
|
72
|
+
| `list_dir` | List a directory tree iteratively (dirs first, file sizes). |
|
|
73
|
+
| `terminal` | Run a shell command via `bash -lc` and capture output plus exit code. |
|
|
74
|
+
| `grep_files` | Regex search across files, skipping node_modules/.git/dist and binaries. |
|
|
75
|
+
| `fetch_url` | GET an http(s) URL and return the body text with a status header. |
|
|
76
|
+
| `web_search` | Web search via DuckDuckGo's HTML endpoint (no api key). |
|
|
77
|
+
| `http_request` | Generic HTTP calls (method/headers/body) for REST-ish APIs. |
|
|
78
|
+
| `process_list` | Snapshot running processes from /proc with an optional filter. |
|
|
79
|
+
| `disk_usage` | `du -sb` sizes for depth-1 entries of a directory, sorted with a total. |
|
|
80
|
+
| `env_get` | Inspect environment variables (names/lengths; secrets always masked). |
|
|
81
|
+
| `docs_read` | Read a bundled lich doc (path relative to docs root; offset/limit; `.md` optional). |
|
|
82
|
+
| `docs_search` | Keyword search across bundled lich docs with scored section snippets. |
|
|
83
|
+
|
|
84
|
+
## Plugins
|
|
85
|
+
|
|
86
|
+
Customize lich with your own tools and lifecycle hooks: keep a `Plugin`
|
|
87
|
+
object (`{name, tools?, hooks?}`) in your repo, list its file path in the
|
|
88
|
+
`plugins` config array, and the agent merges your tools and lets your hooks
|
|
89
|
+
observe or veto tool calls. See
|
|
90
|
+
[docs/user-guide/plugins.md](docs/user-guide/plugins.md).
|
|
91
|
+
|
|
92
|
+
## Environment variables
|
|
93
|
+
|
|
94
|
+
| Variable | Purpose |
|
|
95
|
+
| --- | --- |
|
|
96
|
+
| `LICH_MODEL` | model name (e.g. `gpt-4.1-mini`, `claude-sonnet-4`, `llama3.2`) |
|
|
97
|
+
| `LICH_PROVIDER_KIND` | `openai_compat` \| `anthropic` \| `ollama` (default `openai_compat`) |
|
|
98
|
+
| `LICH_BASE_URL` | provider base url (ollama default: `http://localhost:11434`) |
|
|
99
|
+
| `LICH_API_KEY_ENV` | env var holding the api key (unused by ollama) |
|
|
100
|
+
|
|
101
|
+
## Ollama
|
|
102
|
+
|
|
103
|
+
Ollama needs no api key and defaults to `http://localhost:11434`:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
LICH_PROVIDER_KIND=ollama LICH_MODEL=llama3.2 bun src/cli.ts "Reply with ok"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Notes:
|
|
110
|
+
|
|
111
|
+
- Requests go to `POST /api/chat` with `stream: false`; tool calls use the
|
|
112
|
+
OpenAI-style function shape, and tool results are sent 1:1 as
|
|
113
|
+
`{role: "tool", tool_name, content}` messages.
|
|
114
|
+
- Set `think: true` on the provider config (or chat options) to request
|
|
115
|
+
thinking mode; `keep_alive` controls model residency (e.g. `"10m"`).
|
|
116
|
+
- 429/5xx are retried with backoff before failing over to the next provider.
|
|
117
|
+
|
|
118
|
+
## Gateway
|
|
119
|
+
|
|
120
|
+
`lich gateway` turns lich into a long-running messaging gateway: every
|
|
121
|
+
supported platform (Telegram, Discord, Twitch, plus a zero-config webhook
|
|
122
|
+
HTTP endpoint) is routed into **one shared agent** with **per-conversation
|
|
123
|
+
memory**, so each chat keeps its own bounded history while the tools,
|
|
124
|
+
guardrails, and provider failover stay common.
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
lich gateway webhook # http only
|
|
128
|
+
lich gateway webhook telegram # http + telegram polling
|
|
129
|
+
lich gateway telegram discord twitch # no webhook server
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Environment variables:
|
|
133
|
+
|
|
134
|
+
| Variable | Purpose |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| `LICH_GATEWAY_PORT` | webhook port (default `8089`) |
|
|
137
|
+
| `LICH_GATEWAY_TOKEN` | webhook auth: requests must send header `x-lich-token` |
|
|
138
|
+
| `LICH_TELEGRAM_BOT_TOKEN` | telegram bot token (adapter idles without it) |
|
|
139
|
+
| `LICH_DISCORD_BOT_TOKEN` | discord bot token (adapter idles without it) |
|
|
140
|
+
| `LICH_DISCORD_BOT_ID` | discord bot id; mentions of `<@id>` are stripped |
|
|
141
|
+
| `LICH_TWITCH_OAUTH_TOKEN` | twitch irc oauth token (adapter idles without it) |
|
|
142
|
+
| `LICH_TWITCH_NICK` | twitch irc nickname |
|
|
143
|
+
| `LICH_TWITCH_CHANNELS` | comma-separated twitch channels to join |
|
|
144
|
+
|
|
145
|
+
Adapters whose tokens are missing start **idle** (they log and skip) — the
|
|
146
|
+
gateway still runs the rest. The discord adapter has no reconnect-resume:
|
|
147
|
+
if its gateway websocket drops, messages are missed until the process
|
|
148
|
+
restarts.
|
|
149
|
+
|
|
150
|
+
Webhook API:
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
curl -X POST http://localhost:8089/message \
|
|
154
|
+
-H "content-type: application/json" -d '{"text": "Reply with ok"}'
|
|
155
|
+
# -> {"reply":"...","usage":{...}}
|
|
156
|
+
|
|
157
|
+
curl http://localhost:8089/health # -> {"status":"ok"}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## TUI
|
|
161
|
+
|
|
162
|
+
`lich tui` launches an ink-based terminal UI: a scrolling transcript with
|
|
163
|
+
tool-call rows, a status bar (model, turns, tokens), and a command input
|
|
164
|
+
row with Up/Down history recall (Ctrl+C quits).
|
|
165
|
+
|
|
166
|
+
```sh
|
|
167
|
+
lich tui
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Slash commands: `/help`, `/model`, `/usage`, `/clear`, `/sessions`,
|
|
171
|
+
`/exit` (also `/quit`, `/q`). The transcript shows the newest 50 blocks.
|
|
172
|
+
|
|
173
|
+
## Development
|
|
174
|
+
|
|
175
|
+
```sh
|
|
176
|
+
bun x tsc --noEmit # typecheck
|
|
177
|
+
node node_modules/vitest/vitest.mjs run # tests (project-local binaries)
|
|
178
|
+
node node_modules/tsup/dist/cli-default.js src/index.ts src/cli.ts --format esm --dts --clean --sourcemap # build
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Use project-local binaries for vitest/tsup (not `bun x`), which would isolate
|
|
182
|
+
packages in /tmp and break dependency resolution.
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
MIT
|