@moikapy/lich 0.5.1 → 0.7.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +84 -4
  3. package/dist/chunk-JYURFAGB.js +92 -0
  4. package/dist/chunk-JYURFAGB.js.map +1 -0
  5. package/dist/{chunk-CV2YH3FH.js → chunk-QVJCIZIF.js} +748 -13
  6. package/dist/chunk-QVJCIZIF.js.map +1 -0
  7. package/dist/chunk-SAEB3QL3.js +58 -0
  8. package/dist/chunk-SAEB3QL3.js.map +1 -0
  9. package/dist/cli.js +263 -22
  10. package/dist/cli.js.map +1 -1
  11. package/dist/{gateway-W6S43ETE.js → gateway-5BG3YCZF.js} +2 -2
  12. package/dist/index.d.ts +229 -118
  13. package/dist/index.js +5 -3
  14. package/dist/{tui-2VO6LAFM.js → tui-L6RABP2J.js} +43 -41
  15. package/dist/tui-L6RABP2J.js.map +1 -0
  16. package/docs/.vitepress/config.mts +6 -1
  17. package/docs/architecture/agent-loop.md +5 -3
  18. package/docs/architecture/overview.md +36 -22
  19. package/docs/architecture/plugins.md +1 -1
  20. package/docs/architecture/tools.md +7 -2
  21. package/docs/getting-started.md +9 -7
  22. package/docs/index.md +6 -4
  23. package/docs/user-guide/cli.md +24 -9
  24. package/docs/user-guide/games.md +93 -0
  25. package/docs/user-guide/godot.md +3 -1
  26. package/docs/user-guide/library.md +8 -2
  27. package/docs/user-guide/plugins.md +2 -2
  28. package/docs/user-guide/redot.md +93 -0
  29. package/docs/user-guide/tui.md +11 -11
  30. package/examples/game_bridge/README.md +2 -0
  31. package/optional-mcps/godot/manifest.json +6 -0
  32. package/optional-mcps/redot/manifest.json +18 -0
  33. package/package.json +2 -1
  34. package/dist/chunk-6M6OAQGN.js +0 -17
  35. package/dist/chunk-6M6OAQGN.js.map +0 -1
  36. package/dist/chunk-CV2YH3FH.js.map +0 -1
  37. package/dist/tui-2VO6LAFM.js.map +0 -1
  38. /package/dist/{gateway-W6S43ETE.js.map → gateway-5BG3YCZF.js.map} +0 -0
package/dist/index.d.ts CHANGED
@@ -23,107 +23,6 @@ interface JsonSchemaObject {
23
23
  additionalProperties?: boolean;
24
24
  }
25
25
 
26
- interface ToolResult {
27
- ok: boolean;
28
- output: string;
29
- error?: string;
30
- }
31
- interface ToolContext {
32
- work_dir: string;
33
- env: Record<string, string>;
34
- signal?: AbortSignal;
35
- }
36
- interface Tool {
37
- name: string;
38
- description: string;
39
- parameters: JsonSchemaObject;
40
- /** Per-tool executor timeout override in ms; unset tools get the 30s default. */
41
- timeout_ms?: number;
42
- execute(args: Record<string, unknown>, context: ToolContext): Promise<ToolResult>;
43
- }
44
- interface Toolset {
45
- name: string;
46
- tools: Tool[];
47
- }
48
-
49
- /**
50
- * Plugin surface: user-authored tools and lifecycle hooks loaded at startup.
51
- *
52
- * A plugin is a plain object exported from a TS/JS module. Hooks observe and
53
- * (in the case of before_tool_call) veto tool executions; tools merge into the
54
- * agent registry after builtin filtering.
55
- */
56
-
57
- /** Runtime info handed to every hook call. */
58
- interface HookContext {
59
- work_dir: string;
60
- /**
61
- * This plugin's own per-run state sub-map. Every hook invocation receives
62
- * a ctx exposing only the invoking plugin's bag; the bag is swapped fresh
63
- * at each run start. Absent only on hand-built contexts outside the runner.
64
- */
65
- state?: Map<string, unknown>;
66
- }
67
- /** Argument passed to before_tool_call hooks. */
68
- interface BeforeToolCallInfo {
69
- tool_name: string;
70
- args: Record<string, unknown>;
71
- }
72
- /** Return value that vetoes a tool call; other hooks still run. */
73
- interface BeforeToolCallResult {
74
- block?: boolean;
75
- reason?: string;
76
- }
77
- /** Argument passed to after_tool_call hooks. */
78
- interface AfterToolCallInfo extends BeforeToolCallInfo {
79
- result_summary: string;
80
- /** Structured executor outcome; gate on this, never parse result_summary. */
81
- ok: boolean;
82
- error?: string;
83
- }
84
- interface RunEndInfo {
85
- stopped_reason: string;
86
- turns_used: number;
87
- }
88
- /** Optional lifecycle hooks a plugin may implement. All hooks are awaited. */
89
- interface PluginHooks {
90
- before_tool_call?(info: BeforeToolCallInfo, ctx: HookContext): Promise<BeforeToolCallResult | void> | BeforeToolCallResult | void;
91
- after_tool_call?(info: AfterToolCallInfo, ctx: HookContext): Promise<void> | void;
92
- on_run_start?(info: {
93
- input_chars: number;
94
- }, ctx: HookContext): Promise<void> | void;
95
- on_run_end?(info: RunEndInfo, ctx: HookContext): Promise<void> | void;
96
- }
97
- /** A user plugin: required unique name, optional tools and hooks. */
98
- interface Plugin {
99
- name: string;
100
- version?: string;
101
- tools?: Tool[];
102
- hooks?: PluginHooks;
103
- }
104
-
105
- /** A successfully loaded plugin plus the entry path it came from. */
106
- interface LoadedPlugin {
107
- plugin: Plugin;
108
- entry: string;
109
- }
110
- /** One failed entry: the specifier and why it failed. */
111
- interface PluginLoadError {
112
- entry: string;
113
- error_message: string;
114
- }
115
- /**
116
- * Load plugins from explicit entry paths (relative to `base_dir` or absolute).
117
- * Broken imports, missing exports, and duplicate names become error entries;
118
- * nothing is thrown for a bad plugin.
119
- */
120
- declare function load_plugins(entries: readonly string[], base_dir: string): Promise<{
121
- plugins: LoadedPlugin[];
122
- errors: PluginLoadError[];
123
- }>;
124
- /** Joined one-liner per load error, for a single warn log. */
125
- declare function plugin_errors_summary(errors: readonly PluginLoadError[]): string;
126
-
127
26
  type FinishReason = "stop" | "tool_calls" | "length" | "error" | "unknown";
128
27
  type ProviderErrorKind = "rate_limit" | "network" | "auth" | "overflow" | "bad_request" | "unknown";
129
28
  interface ToolCall {
@@ -212,7 +111,7 @@ declare class ProviderError extends Error {
212
111
  */
213
112
 
214
113
  declare const agent_config_schema: z.ZodEffects<z.ZodObject<{
215
- /** Display name used by the TUI banner. */
114
+ /** Wizard label. The TUI banner uses the active theme welcome string. */
216
115
  agent_name: z.ZodDefault<z.ZodString>;
217
116
  system_prompt: z.ZodOptional<z.ZodString>;
218
117
  max_turns: z.ZodDefault<z.ZodNumber>;
@@ -269,9 +168,53 @@ declare const agent_config_schema: z.ZodEffects<z.ZodObject<{
269
168
  token_envs?: Record<string, string> | undefined;
270
169
  }>>;
271
170
  log_level: z.ZodDefault<z.ZodEnum<["debug", "info", "warn", "error"]>>;
171
+ theme: z.ZodDefault<z.ZodString>;
172
+ /** Named MCP servers. Each entry is stdio or loopback http. Default off. */
173
+ mcp_servers: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
174
+ enabled: z.ZodDefault<z.ZodBoolean>;
175
+ command: z.ZodString;
176
+ args: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
177
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
178
+ }, "strict", z.ZodTypeAny, {
179
+ enabled: boolean;
180
+ command: string;
181
+ args: string[];
182
+ env?: Record<string, string> | undefined;
183
+ }, {
184
+ command: string;
185
+ enabled?: boolean | undefined;
186
+ args?: string[] | undefined;
187
+ env?: Record<string, string> | undefined;
188
+ }>, z.ZodObject<{
189
+ enabled: z.ZodDefault<z.ZodBoolean>;
190
+ url: z.ZodString;
191
+ }, "strict", z.ZodTypeAny, {
192
+ url: string;
193
+ enabled: boolean;
194
+ }, {
195
+ url: string;
196
+ enabled?: boolean | undefined;
197
+ }>]>>, Record<string, {
198
+ enabled: boolean;
199
+ command: string;
200
+ args: string[];
201
+ env?: Record<string, string> | undefined;
202
+ } | {
203
+ url: string;
204
+ enabled: boolean;
205
+ }>, Record<string, {
206
+ command: string;
207
+ enabled?: boolean | undefined;
208
+ args?: string[] | undefined;
209
+ env?: Record<string, string> | undefined;
210
+ } | {
211
+ url: string;
212
+ enabled?: boolean | undefined;
213
+ }>>>;
272
214
  }, "strip", z.ZodTypeAny, {
273
215
  max_turns: number;
274
216
  log_level: "debug" | "info" | "warn" | "error";
217
+ theme: string;
275
218
  providers: z.objectOutputType<{
276
219
  kind: z.ZodEnum<["openai_compat", "anthropic", "ollama"]>;
277
220
  name: z.ZodString;
@@ -298,6 +241,15 @@ declare const agent_config_schema: z.ZodEffects<z.ZodObject<{
298
241
  } | undefined;
299
242
  temperature?: number | undefined;
300
243
  max_tokens?: number | undefined;
244
+ mcp_servers?: Record<string, {
245
+ enabled: boolean;
246
+ command: string;
247
+ args: string[];
248
+ env?: Record<string, string> | undefined;
249
+ } | {
250
+ url: string;
251
+ enabled: boolean;
252
+ }> | undefined;
301
253
  }, {
302
254
  providers: z.objectInputType<{
303
255
  kind: z.ZodEnum<["openai_compat", "anthropic", "ollama"]>;
@@ -315,6 +267,7 @@ declare const agent_config_schema: z.ZodEffects<z.ZodObject<{
315
267
  system_prompt?: string | undefined;
316
268
  session_dir?: string | undefined;
317
269
  log_level?: "debug" | "info" | "warn" | "error" | undefined;
270
+ theme?: string | undefined;
318
271
  gateway?: {
319
272
  platforms?: ("webhook" | "telegram" | "discord" | "twitch")[] | undefined;
320
273
  token_envs?: Record<string, string> | undefined;
@@ -327,12 +280,22 @@ declare const agent_config_schema: z.ZodEffects<z.ZodObject<{
327
280
  compress_threshold?: number | undefined;
328
281
  terminal_timeout_ms?: number | undefined;
329
282
  plugins?: string[] | undefined;
283
+ mcp_servers?: Record<string, {
284
+ command: string;
285
+ enabled?: boolean | undefined;
286
+ args?: string[] | undefined;
287
+ env?: Record<string, string> | undefined;
288
+ } | {
289
+ url: string;
290
+ enabled?: boolean | undefined;
291
+ }> | undefined;
330
292
  }>, {
331
293
  work_dir: string;
332
294
  providers: ProviderConfig[];
333
295
  session_dir: string;
334
296
  max_turns: number;
335
297
  log_level: "debug" | "info" | "warn" | "error";
298
+ theme: string;
336
299
  agent_name: string;
337
300
  tools_enabled: string[] | "all";
338
301
  context_budget_tokens: number;
@@ -346,6 +309,15 @@ declare const agent_config_schema: z.ZodEffects<z.ZodObject<{
346
309
  } | undefined;
347
310
  temperature?: number | undefined;
348
311
  max_tokens?: number | undefined;
312
+ mcp_servers?: Record<string, {
313
+ enabled: boolean;
314
+ command: string;
315
+ args: string[];
316
+ env?: Record<string, string> | undefined;
317
+ } | {
318
+ url: string;
319
+ enabled: boolean;
320
+ }> | undefined;
349
321
  }, {
350
322
  providers: z.objectInputType<{
351
323
  kind: z.ZodEnum<["openai_compat", "anthropic", "ollama"]>;
@@ -363,6 +335,7 @@ declare const agent_config_schema: z.ZodEffects<z.ZodObject<{
363
335
  system_prompt?: string | undefined;
364
336
  session_dir?: string | undefined;
365
337
  log_level?: "debug" | "info" | "warn" | "error" | undefined;
338
+ theme?: string | undefined;
366
339
  gateway?: {
367
340
  platforms?: ("webhook" | "telegram" | "discord" | "twitch")[] | undefined;
368
341
  token_envs?: Record<string, string> | undefined;
@@ -375,10 +348,154 @@ declare const agent_config_schema: z.ZodEffects<z.ZodObject<{
375
348
  compress_threshold?: number | undefined;
376
349
  terminal_timeout_ms?: number | undefined;
377
350
  plugins?: string[] | undefined;
351
+ mcp_servers?: Record<string, {
352
+ command: string;
353
+ enabled?: boolean | undefined;
354
+ args?: string[] | undefined;
355
+ env?: Record<string, string> | undefined;
356
+ } | {
357
+ url: string;
358
+ enabled?: boolean | undefined;
359
+ }> | undefined;
378
360
  }>;
379
361
  type AgentConfig = z.infer<typeof agent_config_schema>;
380
362
  declare function parse_agent_config(raw: unknown): AgentConfig;
381
363
 
364
+ interface ToolResult {
365
+ ok: boolean;
366
+ output: string;
367
+ error?: string;
368
+ }
369
+ interface ToolContext {
370
+ work_dir: string;
371
+ env: Record<string, string>;
372
+ signal?: AbortSignal;
373
+ }
374
+ interface Tool {
375
+ name: string;
376
+ description: string;
377
+ parameters: JsonSchemaObject;
378
+ /** Per-tool executor timeout override in ms; unset tools get the 30s default. */
379
+ timeout_ms?: number;
380
+ execute(args: Record<string, unknown>, context: ToolContext): Promise<ToolResult>;
381
+ }
382
+ interface Toolset {
383
+ name: string;
384
+ tools: Tool[];
385
+ }
386
+
387
+ /**
388
+ * Name-keyed registry of tools and toolsets. Registration rejects duplicate
389
+ * tool names so conflicting builtins fail loudly at startup.
390
+ */
391
+ declare class ToolRegistry {
392
+ private readonly tools;
393
+ register(tool: Tool): void;
394
+ register_toolset(toolset: Toolset): void;
395
+ get(name: string): Tool | undefined;
396
+ has(name: string): boolean;
397
+ list(): Tool[];
398
+ /** Map registered tools onto the provider-facing wire shape. */
399
+ definitions(): ToolDefinition[];
400
+ }
401
+
402
+ interface LineChild {
403
+ write_line(line: string): void;
404
+ read_line(): Promise<string | undefined>;
405
+ stop(): void;
406
+ failed(): string | undefined;
407
+ }
408
+ type LineSpawner = (command: string, args: readonly string[], env?: Record<string, string>) => LineChild;
409
+
410
+ /**
411
+ * Discover tools/list for each enabled server and register mcp_<server>_<tool>.
412
+ * tools_enabled filters them. An empty allowlist never connects.
413
+ */
414
+
415
+ interface McpRuntime {
416
+ spawn?: LineSpawner;
417
+ fetch_fn?: typeof fetch;
418
+ env_path?: string;
419
+ }
420
+
421
+ /**
422
+ * Plugin surface: user-authored tools and lifecycle hooks loaded at startup.
423
+ *
424
+ * A plugin is a plain object exported from a TS/JS module. Hooks observe and
425
+ * (in the case of before_tool_call) veto tool executions; tools merge into the
426
+ * agent registry after builtin filtering.
427
+ */
428
+
429
+ /** Runtime info handed to every hook call. */
430
+ interface HookContext {
431
+ work_dir: string;
432
+ /**
433
+ * This plugin's own per-run state sub-map. Every hook invocation receives
434
+ * a ctx exposing only the invoking plugin's bag; the bag is swapped fresh
435
+ * at each run start. Absent only on hand-built contexts outside the runner.
436
+ */
437
+ state?: Map<string, unknown>;
438
+ }
439
+ /** Argument passed to before_tool_call hooks. */
440
+ interface BeforeToolCallInfo {
441
+ tool_name: string;
442
+ args: Record<string, unknown>;
443
+ }
444
+ /** Return value that vetoes a tool call; other hooks still run. */
445
+ interface BeforeToolCallResult {
446
+ block?: boolean;
447
+ reason?: string;
448
+ }
449
+ /** Argument passed to after_tool_call hooks. */
450
+ interface AfterToolCallInfo extends BeforeToolCallInfo {
451
+ result_summary: string;
452
+ /** Structured executor outcome; gate on this, never parse result_summary. */
453
+ ok: boolean;
454
+ error?: string;
455
+ }
456
+ interface RunEndInfo {
457
+ stopped_reason: string;
458
+ turns_used: number;
459
+ }
460
+ /** Optional lifecycle hooks a plugin may implement. All hooks are awaited. */
461
+ interface PluginHooks {
462
+ before_tool_call?(info: BeforeToolCallInfo, ctx: HookContext): Promise<BeforeToolCallResult | void> | BeforeToolCallResult | void;
463
+ after_tool_call?(info: AfterToolCallInfo, ctx: HookContext): Promise<void> | void;
464
+ on_run_start?(info: {
465
+ input_chars: number;
466
+ }, ctx: HookContext): Promise<void> | void;
467
+ on_run_end?(info: RunEndInfo, ctx: HookContext): Promise<void> | void;
468
+ }
469
+ /** A user plugin: required unique name, optional tools and hooks. */
470
+ interface Plugin {
471
+ name: string;
472
+ version?: string;
473
+ tools?: Tool[];
474
+ hooks?: PluginHooks;
475
+ }
476
+
477
+ /** A successfully loaded plugin plus the entry path it came from. */
478
+ interface LoadedPlugin {
479
+ plugin: Plugin;
480
+ entry: string;
481
+ }
482
+ /** One failed entry: the specifier and why it failed. */
483
+ interface PluginLoadError {
484
+ entry: string;
485
+ error_message: string;
486
+ }
487
+ /**
488
+ * Load plugins from explicit entry paths (relative to `base_dir` or absolute).
489
+ * Broken imports, missing exports, and duplicate names become error entries;
490
+ * nothing is thrown for a bad plugin.
491
+ */
492
+ declare function load_plugins(entries: readonly string[], base_dir: string): Promise<{
493
+ plugins: LoadedPlugin[];
494
+ errors: PluginLoadError[];
495
+ }>;
496
+ /** Joined one-liner per load error, for a single warn log. */
497
+ declare function plugin_errors_summary(errors: readonly PluginLoadError[]): string;
498
+
382
499
  /**
383
500
  * Typed event emitter for the agent loop.
384
501
  *
@@ -487,8 +604,14 @@ declare class Agent {
487
604
  private readonly registry;
488
605
  private readonly executor;
489
606
  private readonly hook_runner;
490
- constructor(config: AgentConfig, plugins?: readonly LoadedPlugin[]);
607
+ private readonly mcp_runtime;
608
+ private mcp_attached;
609
+ constructor(config: AgentConfig, plugins?: readonly LoadedPlugin[], runtime?: {
610
+ mcp?: McpRuntime;
611
+ });
491
612
  run(options: AgentRunOptions): Promise<AgentRunResult>;
613
+ /** tools/list once, before the model sees definitions. Empty allowlists never connect. */
614
+ private attach_mcp_once;
492
615
  /** Per-run deps: the built-once ToolContext threads through every tool execution. */
493
616
  private loop_deps;
494
617
  /** Best-effort on_run_start fan-out; hook errors are logged, never fatal. */
@@ -506,20 +629,8 @@ declare function run_agent(raw_config: unknown, input: string, options?: {
506
629
  label?: string;
507
630
  }): Promise<AgentRunResult>;
508
631
 
509
- /**
510
- * Name-keyed registry of tools and toolsets. Registration rejects duplicate
511
- * tool names so conflicting builtins fail loudly at startup.
512
- */
513
- declare class ToolRegistry {
514
- private readonly tools;
515
- register(tool: Tool): void;
516
- register_toolset(toolset: Toolset): void;
517
- get(name: string): Tool | undefined;
518
- has(name: string): boolean;
519
- list(): Tool[];
520
- /** Map registered tools onto the provider-facing wire shape. */
521
- definitions(): ToolDefinition[];
522
- }
632
+ /** Write the client entry. The user sets enabled. Godot has nothing to write. */
633
+ declare function catalog_client_entry(name: string, substitutes?: Record<string, string>): Record<string, unknown> | string;
523
634
 
524
635
  interface ExecutorDefaults {
525
636
  work_dir?: string;
@@ -583,4 +694,4 @@ declare class HookedToolRunner {
583
694
 
584
695
  declare const LICH_VERSION: string;
585
696
 
586
- export { type AfterToolCallInfo, Agent, type AgentConfig, AgentEmitter, type AgentEvent, type AgentEventHandler, type AgentEvents, type AgentRunOptions, type AgentRunResult, type BeforeToolCallInfo, type BeforeToolCallResult, type ChatOptions, type ChatResult, type HookContext, HookedToolRunner, LICH_VERSION, type LoadedPlugin, type LoopOutcome, type LoopParams, type Message, type Plugin, type PluginHooks, type PluginLoadError, type ProviderConfig, ProviderError, type RunEndInfo, type Tool, type ToolCall, type ToolContext, type ToolDefinition, ToolExecutor, ToolRegistry, type ToolResult, type Usage, create_agent, create_agent_with_plugins, load_plugins, parse_agent_config, plugin_errors_summary, register_builtin_tools, run_agent };
697
+ export { type AfterToolCallInfo, Agent, type AgentConfig, AgentEmitter, type AgentEvent, type AgentEventHandler, type AgentEvents, type AgentRunOptions, type AgentRunResult, type BeforeToolCallInfo, type BeforeToolCallResult, type ChatOptions, type ChatResult, type HookContext, HookedToolRunner, LICH_VERSION, type LoadedPlugin, type LoopOutcome, type LoopParams, type Message, type Plugin, type PluginHooks, type PluginLoadError, type ProviderConfig, ProviderError, type RunEndInfo, type Tool, type ToolCall, type ToolContext, type ToolDefinition, ToolExecutor, ToolRegistry, type ToolResult, type Usage, catalog_client_entry, create_agent, create_agent_with_plugins, load_plugins, parse_agent_config, plugin_errors_summary, register_builtin_tools, run_agent };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
- LICH_VERSION
3
- } from "./chunk-6M6OAQGN.js";
2
+ LICH_VERSION,
3
+ catalog_client_entry
4
+ } from "./chunk-SAEB3QL3.js";
4
5
  import {
5
6
  Agent,
6
7
  AgentEmitter,
@@ -15,7 +16,7 @@ import {
15
16
  plugin_errors_summary,
16
17
  register_builtin_tools,
17
18
  run_agent
18
- } from "./chunk-CV2YH3FH.js";
19
+ } from "./chunk-QVJCIZIF.js";
19
20
  export {
20
21
  Agent,
21
22
  AgentEmitter,
@@ -24,6 +25,7 @@ export {
24
25
  ProviderError,
25
26
  ToolExecutor,
26
27
  ToolRegistry,
28
+ catalog_client_entry,
27
29
  create_agent,
28
30
  create_agent_with_plugins,
29
31
  load_plugins,