@moikapy/lich 0.4.0 → 0.5.1

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 (37) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/chunk-6M6OAQGN.js +17 -0
  3. package/dist/chunk-6M6OAQGN.js.map +1 -0
  4. package/dist/{chunk-MLFJW4JU.js → chunk-CV2YH3FH.js} +51 -2
  5. package/dist/chunk-CV2YH3FH.js.map +1 -0
  6. package/dist/cli.d.ts +13 -0
  7. package/dist/cli.js +666 -29
  8. package/dist/cli.js.map +1 -1
  9. package/dist/{gateway-XTYDYT67.js → gateway-W6S43ETE.js} +27 -18
  10. package/dist/gateway-W6S43ETE.js.map +1 -0
  11. package/dist/index.d.ts +56 -26
  12. package/dist/index.js +2 -2
  13. package/dist/{tui-VYBJSGRV.js → tui-2VO6LAFM.js} +9 -6
  14. package/dist/tui-2VO6LAFM.js.map +1 -0
  15. package/docs/getting-started.md +15 -4
  16. package/docs/index.md +1 -0
  17. package/docs/user-guide/cli.md +11 -3
  18. package/docs/user-guide/godot.md +160 -0
  19. package/docs/user-guide/library.md +1 -1
  20. package/docs/user-guide/plugins.md +23 -2
  21. package/docs/user-guide/tui.md +4 -3
  22. package/examples/game_bridge/README.md +68 -0
  23. package/examples/game_bridge/bridge_io.mjs +60 -0
  24. package/examples/game_bridge/bridge_paths.mjs +11 -0
  25. package/examples/game_bridge/dungeon_memory.mjs +56 -0
  26. package/examples/game_bridge/enemy_actions.mjs +44 -0
  27. package/examples/game_bridge/game_bridge.plugin.mjs +17 -0
  28. package/examples/game_bridge/meteor_veto.mjs +22 -0
  29. package/examples/game_bridge/schemas.mjs +48 -0
  30. package/examples/game_bridge/snapshot.mjs +19 -0
  31. package/examples/game_bridge/validate_order.mjs +44 -0
  32. package/package.json +3 -1
  33. package/dist/chunk-MLFJW4JU.js.map +0 -1
  34. package/dist/chunk-ZVK3MUPC.js +0 -7
  35. package/dist/chunk-ZVK3MUPC.js.map +0 -1
  36. package/dist/gateway-XTYDYT67.js.map +0 -1
  37. package/dist/tui-VYBJSGRV.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.1
4
+
5
+ - fix the CLI so bun's global bin enters main (symlink argv no longer skips the entry).
6
+ - read LICH_VERSION from package.json so lich --version is not stuck at 0.3.0.
7
+
8
+ ## 0.5.0
9
+
10
+ - add a `game_bridge` example plugin that queues batched enemy actions
11
+ and durable dungeon memory under `.lich/game/` for a Godot combat tick.
12
+ a `before_tool_call` hook holds meteor until round 3. node loads the
13
+ `.mjs` entry from `config.plugins`.
14
+ - load `config.plugins` on every CLI entry point and on `run_agent`
15
+ (`create_agent_with_plugins`). one-shot, chat, tui, and the gateway
16
+ bus no longer ignore plugin entries. broken plugins still warn and
17
+ continue. `create_agent` stays plugin-free.
18
+ - bare `lich` opens the TUI. On a TTY, when no config is in the search
19
+ chain and `LICH_MODEL` is unset, a readline wizard collects agent name,
20
+ provider, gateway env-var names (never secrets), and plugins, then
21
+ writes `.lich/config.json` once. Non-TTY stdin skips the wizard and
22
+ prints guidance. `lich init` writes the starter file through the same
23
+ writer and never overwrites an existing `.lich/config.json`.
24
+ - add `lich update`: compare the installed version with `npm view
25
+ @moikapy/lich version` and, when newer, run
26
+ `npm install -g @moikapy/lich@latest`. git clones are told to
27
+ `git pull`; npx cannot persist an update.
28
+ - document embedding that plugin beside a Godot game: one webhook call
29
+ per combat round, and the `.lich/game/` drain tick. see
30
+ docs/user-guide/godot.md.
31
+
3
32
  ## 0.4.0
4
33
 
5
34
  - add a self-improvement loop: `run_tests`, a gatekeeper plugin, and
@@ -0,0 +1,17 @@
1
+ // src/index.ts
2
+ import { readFileSync } from "fs";
3
+ import { fileURLToPath } from "url";
4
+ function read_package_version() {
5
+ const pkg_path = fileURLToPath(new URL("../package.json", import.meta.url));
6
+ const pkg = JSON.parse(readFileSync(pkg_path, "utf8"));
7
+ if (typeof pkg.version !== "string" || pkg.version.length === 0) {
8
+ throw new Error("package.json is missing version");
9
+ }
10
+ return pkg.version;
11
+ }
12
+ var LICH_VERSION = read_package_version();
13
+
14
+ export {
15
+ LICH_VERSION
16
+ };
17
+ //# sourceMappingURL=chunk-6M6OAQGN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Public surface of the lich agent harness. Pure re-exports, plus the package version.\n */\nimport { readFileSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\n\nfunction read_package_version(): string {\n const pkg_path = fileURLToPath(new URL(\"../package.json\", import.meta.url));\n const pkg = JSON.parse(readFileSync(pkg_path, \"utf8\")) as { version?: unknown };\n if (typeof pkg.version !== \"string\" || pkg.version.length === 0) {\n throw new Error(\"package.json is missing version\");\n }\n return pkg.version;\n}\n\nexport const LICH_VERSION = read_package_version();\n\nexport { Agent, create_agent, run_agent, create_agent_with_plugins } from \"./agent/agent.js\";\nexport type { AgentRunOptions, AgentRunResult } from \"./agent/agent.js\";\nexport type { AgentConfig } from \"./agent/config.js\";\nexport { parse_agent_config } from \"./agent/config.js\";\nexport { AgentEmitter } from \"./agent/events.js\";\nexport type { AgentEvent, AgentEventHandler, AgentEvents } from \"./agent/events.js\";\nexport type { LoopOutcome, LoopParams } from \"./agent/loop.js\";\nexport type {\n ChatOptions,\n ChatResult,\n Message,\n ProviderConfig,\n ToolCall,\n ToolDefinition,\n Usage,\n} from \"./providers/types.js\";\nexport { ProviderError } from \"./providers/types.js\";\nexport { ToolExecutor } from \"./tools/executor.js\";\nexport { ToolRegistry } from \"./tools/registry.js\";\nexport type { Tool, ToolContext, ToolResult } from \"./tools/types.js\";\nexport { register_builtin_tools } from \"./tools/builtin/index.js\";\nexport { HookedToolRunner } from \"./plugins/hooks.js\";\nexport { load_plugins, plugin_errors_summary } from \"./plugins/loader.js\";\nexport type { LoadedPlugin, PluginLoadError } from \"./plugins/loader.js\";\nexport type {\n AfterToolCallInfo,\n BeforeToolCallInfo,\n BeforeToolCallResult,\n HookContext,\n Plugin,\n PluginHooks,\n RunEndInfo,\n} from \"./plugins/types.js\";"],"mappings":";AAGA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAE9B,SAAS,uBAA+B;AACtC,QAAM,WAAW,cAAc,IAAI,IAAI,mBAAmB,YAAY,GAAG,CAAC;AAC1E,QAAM,MAAM,KAAK,MAAM,aAAa,UAAU,MAAM,CAAC;AACrD,MAAI,OAAO,IAAI,YAAY,YAAY,IAAI,QAAQ,WAAW,GAAG;AAC/D,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AACA,SAAO,IAAI;AACb;AAEO,IAAM,eAAe,qBAAqB;","names":[]}
@@ -1881,6 +1881,43 @@ var ProviderError = class extends Error {
1881
1881
 
1882
1882
  // src/agent/config.ts
1883
1883
  import { z } from "zod";
1884
+
1885
+ // src/gateway/token_env.ts
1886
+ var DEFAULT_GATEWAY_TOKEN_ENVS = {
1887
+ webhook: "LICH_GATEWAY_TOKEN",
1888
+ telegram: "LICH_TELEGRAM_BOT_TOKEN",
1889
+ discord: "LICH_DISCORD_BOT_TOKEN",
1890
+ twitch: "LICH_TWITCH_OAUTH_TOKEN"
1891
+ };
1892
+ var ENV_VAR_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
1893
+ function is_env_var_name(value) {
1894
+ return ENV_VAR_NAME.test(value) === true;
1895
+ }
1896
+ function platform_token_env(config, platform) {
1897
+ const named = config.gateway?.token_envs[platform];
1898
+ if (named !== void 0 && named.length > 0) {
1899
+ return is_env_var_name(named) === true ? named : "";
1900
+ }
1901
+ return DEFAULT_GATEWAY_TOKEN_ENVS[platform] ?? "";
1902
+ }
1903
+ function read_platform_token(config, platform) {
1904
+ const key = platform_token_env(config, platform);
1905
+ if (is_env_var_name(key) === false) {
1906
+ return void 0;
1907
+ }
1908
+ const value = process.env[key];
1909
+ if (typeof value !== "string" || value.length === 0) {
1910
+ return void 0;
1911
+ }
1912
+ return value;
1913
+ }
1914
+
1915
+ // src/agent/config.ts
1916
+ var gateway_schema = z.object({
1917
+ platforms: z.array(z.enum(["webhook", "telegram", "discord", "twitch"])).default([]),
1918
+ /** Env-var names that hold tokens. Never store the secrets themselves. */
1919
+ token_envs: z.record(z.string(), z.string().regex(ENV_VAR_NAME, "invalid env var name")).default({})
1920
+ }).optional();
1884
1921
  var provider_schema = z.object({
1885
1922
  kind: z.enum(["openai_compat", "anthropic", "ollama"]),
1886
1923
  name: z.string().min(1),
@@ -1893,6 +1930,8 @@ var provider_schema = z.object({
1893
1930
  fetch_fn: z.custom(() => true).optional()
1894
1931
  }).passthrough();
1895
1932
  var agent_config_schema = z.object({
1933
+ /** Display name used by the TUI banner. */
1934
+ agent_name: z.string().min(1).default("lich"),
1896
1935
  system_prompt: z.string().optional(),
1897
1936
  max_turns: z.number().int().min(1).default(25),
1898
1937
  providers: z.array(provider_schema).min(1),
@@ -1906,6 +1945,7 @@ var agent_config_schema = z.object({
1906
1945
  terminal_timeout_ms: z.number().int().positive().default(6e4),
1907
1946
  /** Plugin entry module specifiers, relative to work_dir or absolute. */
1908
1947
  plugins: z.array(z.string()).default([]),
1948
+ gateway: gateway_schema,
1909
1949
  log_level: z.enum(["debug", "info", "warn", "error"]).default("info")
1910
1950
  }).transform((config) => {
1911
1951
  const work_dir = config.work_dir ?? process.cwd();
@@ -1922,6 +1962,11 @@ function freeze_config(config) {
1922
1962
  for (const provider of config.providers) {
1923
1963
  Object.freeze(provider);
1924
1964
  }
1965
+ if (config.gateway !== void 0) {
1966
+ Object.freeze(config.gateway.platforms);
1967
+ Object.freeze(config.gateway.token_envs);
1968
+ Object.freeze(config.gateway);
1969
+ }
1925
1970
  return config;
1926
1971
  }
1927
1972
  function parse_agent_config(raw) {
@@ -3734,7 +3779,7 @@ async function create_agent_with_plugins(raw_config) {
3734
3779
  return new Agent(config, plugins);
3735
3780
  }
3736
3781
  async function run_agent(raw_config, input, options) {
3737
- const agent = create_agent(raw_config);
3782
+ const agent = await create_agent_with_plugins(raw_config);
3738
3783
  return agent.run({ input, signal: options?.signal, label: options?.label });
3739
3784
  }
3740
3785
 
@@ -3750,6 +3795,10 @@ export {
3750
3795
  plugin_errors_summary,
3751
3796
  sleep,
3752
3797
  ProviderError,
3798
+ DEFAULT_GATEWAY_TOKEN_ENVS,
3799
+ is_env_var_name,
3800
+ platform_token_env,
3801
+ read_platform_token,
3753
3802
  parse_agent_config,
3754
3803
  AgentEmitter,
3755
3804
  Agent,
@@ -3757,4 +3806,4 @@ export {
3757
3806
  create_agent_with_plugins,
3758
3807
  run_agent
3759
3808
  };
3760
- //# sourceMappingURL=chunk-MLFJW4JU.js.map
3809
+ //# sourceMappingURL=chunk-CV2YH3FH.js.map