lakonai 0.16.4 → 0.16.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/mem-llm.js +19 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lakonai",
3
- "version": "0.16.4",
3
+ "version": "0.16.5",
4
4
  "description": "lakonai — save AI context tokens. Filters & compresses CLI output (git, ls, grep, find, test runners, lint/build, docker/kubectl/aws) before it reaches Claude Code, Codex, Cursor, Windsurf, Cline or Gemini — and learns to filter new commands automatically the more you use it.",
5
5
  "keywords": [
6
6
  "claude",
package/src/mem-llm.js CHANGED
@@ -11,6 +11,17 @@ const fs = require('fs');
11
11
  const path = require('path');
12
12
  const { spawnSync } = require('child_process');
13
13
 
14
+ // Hard wall-clock cap per CLI call so a hung agent (auth prompt, network stall)
15
+ // can never block the caller forever — `lakonai gain` fires 8 of these in a row.
16
+ // Override with LAKONAI_LLM_TIMEOUT_MS; 0/invalid disables the cap.
17
+ const DEFAULT_TIMEOUT_MS = 120000;
18
+ function defaultTimeout(env = process.env) {
19
+ const raw = env.LAKONAI_LLM_TIMEOUT_MS;
20
+ if (raw == null || raw === '') return DEFAULT_TIMEOUT_MS;
21
+ const n = Number(raw);
22
+ return Number.isFinite(n) && n >= 0 ? n : DEFAULT_TIMEOUT_MS;
23
+ }
24
+
14
25
  // Local agent CLIs that can run a one-shot, non-interactive prompt. Order is the
15
26
  // detection preference. `args(prompt)` builds argv; when `stdin` is true the
16
27
  // prompt is piped instead of passed as an argument. `modelFlag` (+ env
@@ -113,7 +124,7 @@ ${compressed}`;
113
124
  // Run the chosen agent CLI in non-interactive mode. `run` is injectable for tests
114
125
  // (production: spawnSync). Throws a clear error when the CLI is missing or returns
115
126
  // non-zero so the caller can surface it.
116
- function callAgent(prompt, { run = spawnSync, provider, model = process.env.LAKONAI_MEM_MODEL, systemPrompt, ruleFree, cwd } = {}) {
127
+ function callAgent(prompt, { run = spawnSync, provider, model = process.env.LAKONAI_MEM_MODEL, systemPrompt, ruleFree, cwd, timeout = defaultTimeout() } = {}) {
117
128
  const p = provider || pickProvider();
118
129
  // Prefer the CLI's real system-prompt flag (stronger behavioral effect); fall
119
130
  // back to prepending it to the prompt when the CLI has no such flag.
@@ -132,11 +143,18 @@ function callAgent(prompt, { run = spawnSync, provider, model = process.env.LAKO
132
143
  if (ruleFree && p.ruleFreeArgs) args.push(...p.ruleFreeArgs);
133
144
  const opts = { input: p.stdin ? effective : undefined, encoding: 'utf8', maxBuffer: 8 * 1024 * 1024 };
134
145
  if (cwd) opts.cwd = cwd;
146
+ if (timeout > 0) {
147
+ opts.timeout = timeout;
148
+ opts.killSignal = 'SIGKILL';
149
+ }
135
150
  const res = run(p.bin, args, opts);
136
151
  if (res.error) {
137
152
  if (res.error.code === 'ENOENT') {
138
153
  throw new Error(`\`${p.bin}\` (${p.platform}) not found on PATH.`);
139
154
  }
155
+ if (res.error.code === 'ETIMEDOUT') {
156
+ throw new Error(`${p.bin} timed out after ${timeout}ms (set LAKONAI_LLM_TIMEOUT_MS to adjust).`);
157
+ }
140
158
  throw new Error(`${p.bin} failed: ${res.error.message}`);
141
159
  }
142
160
  if (res.status !== 0) {