@semalt-ai/code 1.8.0 → 1.8.3

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.
@@ -2,7 +2,20 @@
2
2
  "permissions": {
3
3
  "allow": [
4
4
  "Bash(grep -oP '.{0,120}chat:stash.{0,120}' /usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js)",
5
- "Bash(grep -oP '.{0,100}externalEditor.{0,100}' /usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js)"
5
+ "Bash(grep -oP '.{0,100}externalEditor.{0,100}' /usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js)",
6
+ "Bash(node *)",
7
+ "Bash(git -C /srv/www/ai/semalt-code diff lib/constants.js lib/agent.js lib/prompts.js lib/tools.js)",
8
+ "Bash(git *)",
9
+ "WebFetch(domain:api.github.com)",
10
+ "WebFetch(domain:raw.githubusercontent.com)",
11
+ "WebFetch(domain:github.com)",
12
+ "Bash(xargs -I{} sh -c 'head -c 3000 \"$1\"' _ {})",
13
+ "Bash(xargs -I{} sh -c 'echo \"=== $1 ===\"; head -c 500 \"$1\"; echo' _ {})",
14
+ "Bash(xargs -I{} sh -c 'echo \"=== $1 ===\"; python3 -c \"import json,sys; d=json.load\\(open\\(\\\\\"$1\\\\\"\\)\\); print\\(len\\(d.get\\(\\\\\"messages\\\\\",[]\\)\\), \\\\\"msgs; roles:\\\\\", [m.get\\(\\\\\"role\\\\\"\\) for m in d.get\\(\\\\\"messages\\\\\",[]\\)[:20]]\\)\"' _ {})",
15
+ "Bash(python3 *)",
16
+ "Read(//tmp/**)",
17
+ "Bash(sed -i \"s/addMessage\\('>>> AI MSG 2'.*$/addMessage\\('>>> AI MSG 2', ['response body 2a', 'response body 2b']\\);\\\\nfor \\(let k = 3; k <= 8; k++\\) { addMessage\\('>>> USER MSG ' + k, ['line body ' + k]\\); addMessage\\('>>> AI MSG ' + k, ['response body ' + k + 'a', 'response body ' + k + 'b']\\); }/\" scroll-capture.js)",
18
+ "Bash(echo \"exit=$?\")"
6
19
  ]
7
20
  }
8
21
  }
package/CLAUDE.md CHANGED
@@ -299,7 +299,7 @@ Managed by `lib/config.js`. Normalized on every load. The config directory is cr
299
299
  - `max_output_lines` caps shell and HTTP response lines returned to the agent (default 50).
300
300
  - `show_token_count` controls whether token count is shown in the status bar.
301
301
  - `show_cost` reserved for future cost-display feature.
302
- - `context_length` / `models[].context_length` — token limit used for context-usage bar and warnings.
302
+ - `context_length` / `models[].context_length` — token limit used for context-usage bar, warnings, and proactive trimming. Self-calibrating: when a request triggers a context-overflow 400 (`"context length is only N"`), `api.js` parses the real window, persists it to `config.context_length` (and to the matching `models[]` entry), and trims to ~90% of it on subsequent calls. The value is never cached in memory only — a restart keeps the learned limit.
303
303
  - Local `models[]` entries override dashboard models when selected.
304
304
 
305
305
  ---
@@ -311,6 +311,7 @@ Managed by `lib/config.js`. Normalized on every load. The config directory is cr
311
311
  - **Streaming**: `api.js` manually parses `text/event-stream`. The parser in `chatStream()` handles partial JSON lines — be careful editing it.
312
312
  - **Permissions are per-session**: `PermissionManager` resets on each CLI invocation. Approvals never persist to disk. In non-TTY mode all tool calls are auto-approved with a warning.
313
313
  - **Token counting is approximate**: `estimateTokens()` divides char count by 4. It is used only for the `/compact` display — do not rely on it for hard limits.
314
+ - **Context trimming is proactive when a limit is known**: `chatStream()` uses the in-process `_sessionInputLimits` learned from a prior 400 overflow first, then falls back to `config.context_length * 0.9`. When neither is set, no pre-flight trim runs and the client relies on the reactive 400/413 handler (which then persists the discovered window). `Metrics.tokenLimitStatus()` returns `{ used, limit: null }` until a limit is learned, so the status bar shows "N tok · limit unknown" instead of hiding the line.
314
315
  - **Tool output is truncated**: `tools.js` caps output at `max_output_lines` (default 50). Configurable via config.
315
316
  - **Max 10 agent iterations**: hard-coded in `agent.js`. Prevents runaway loops.
316
317
  - **Malformed tags are skipped**: each tool dispatch in the agent loop is wrapped in try/catch; errors emit a warning line and continue to the next tool call.
package/index.js CHANGED
@@ -8,6 +8,7 @@ const path = require('path');
8
8
  const { PACKAGE_JSON } = require('./lib/constants');
9
9
  const { loadConfig, saveConfig, configSet, configShow } = require('./lib/config');
10
10
  const ui = require('./lib/ui');
11
+ const { registerTerminalCleanup } = require('./lib/ui/terminal');
11
12
  const { createPermissionManager } = require('./lib/permissions');
12
13
  const { createToolExecutor, extractToolCalls } = require('./lib/tools');
13
14
  const { readFileContext } = require('./lib/context');
@@ -18,6 +19,11 @@ const { parseArgs } = require('./lib/args');
18
19
  const { CONFIG_PATH } = require('./lib/constants');
19
20
  const { AUDIT_LOG } = require('./lib/audit');
20
21
 
22
+ // Install process-wide signal handlers so every exit path (normal, SIGINT,
23
+ // SIGHUP, SIGTERM, uncaught exception) restores the terminal. Safe to call
24
+ // from multiple entrypoints — the function is internally idempotent.
25
+ registerTerminalCleanup();
26
+
21
27
  let config = loadConfig();
22
28
 
23
29
  function getConfig() {
@@ -53,10 +59,14 @@ const apiClient = createApiClient({
53
59
  });
54
60
  const { runAgentLoop } = createAgentRunner({
55
61
  chatStream: apiClient.chatStream,
56
- extractToolCalls,
62
+ extractToolCalls: (reply, options = {}) => extractToolCalls(reply, {
63
+ repairMalformedXml: !!getConfig().repair_malformed_tool_xml,
64
+ ...options,
65
+ }),
57
66
  agentExecShell,
58
67
  agentExecFile,
59
68
  ui,
69
+ getConfig,
60
70
  });
61
71
  const commands = createCommands({
62
72
  getConfig,
@@ -113,6 +123,7 @@ Options:
113
123
  --allow-exec Auto-approve shell command execution
114
124
  --allow-net Auto-approve network operations
115
125
  --allow-all Auto-approve everything (use carefully)
126
+ --allow-anywhere Allow writes outside the project CWD and in sensitive dirs
116
127
  --readonly Block all write operations
117
128
  --new Skip session resume prompt
118
129
  -v, --version Show CLI version
@@ -195,6 +206,9 @@ Config: ${CONFIG_PATH}
195
206
  }
196
207
 
197
208
  main().catch((error) => {
209
+ // Tear down the TUI synchronously so the error message lands below the
210
+ // last scrollback line, not on top of a still-rendered live region.
211
+ try { ui.teardownTerminal(); } catch {}
198
212
  process.stderr.write(`\n ${ui.FG_RED}✗ Fatal: ${error.message}${ui.RST}\n\n`);
199
213
  process.exit(1);
200
214
  });