@semalt-ai/code 1.19.0 → 1.20.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 (83) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/ARCHITECTURE.md +6 -95
  3. package/CLAUDE.md +196 -1874
  4. package/README.md +1 -1
  5. package/docs/ARCHITECTURE.md +1321 -0
  6. package/docs/CONFIG.md +340 -0
  7. package/docs/HISTORY.md +245 -0
  8. package/index.js +1 -1
  9. package/lib/agent.js +145 -16
  10. package/lib/api.js +28 -3
  11. package/lib/commands/chat-session.js +188 -4
  12. package/lib/commands/chat-slash.js +16 -0
  13. package/lib/commands/chat-turn.js +319 -52
  14. package/lib/commands/chat.js +12 -8
  15. package/lib/config.js +27 -0
  16. package/lib/constants.js +30 -1
  17. package/lib/headless.js +36 -1
  18. package/lib/images.js +8 -2
  19. package/lib/permissions.js +23 -16
  20. package/lib/prompts.js +15 -3
  21. package/lib/tool_registry.js +357 -53
  22. package/lib/tool_specs.js +42 -8
  23. package/lib/tools.js +80 -19
  24. package/lib/ui/anim.js +86 -0
  25. package/lib/ui/ansi.js +17 -27
  26. package/lib/ui/chat-history.js +253 -71
  27. package/lib/ui/create-ui.js +67 -24
  28. package/lib/ui/diff.js +90 -25
  29. package/lib/ui/file-activity.js +229 -0
  30. package/lib/ui/format.js +173 -28
  31. package/lib/ui/input-field.js +5 -4
  32. package/lib/ui/md-stream.js +234 -0
  33. package/lib/ui/render-operation.js +113 -0
  34. package/lib/ui/select.js +1 -4
  35. package/lib/ui/status-bar.js +99 -57
  36. package/lib/ui/stream.js +20 -13
  37. package/lib/ui/theme.js +190 -45
  38. package/lib/ui/tool-operation.js +190 -0
  39. package/lib/ui/utils.js +9 -5
  40. package/lib/ui/web-activity.js +58 -6
  41. package/lib/ui/writer.js +159 -45
  42. package/lib/ui.js +1 -1
  43. package/package.json +1 -1
  44. package/test/anim-driver.test.js +153 -0
  45. package/test/ask-user-display.test.js +226 -0
  46. package/test/ask-user-gate.test.js +231 -0
  47. package/test/chat-history-nocolor.test.js +155 -0
  48. package/test/chat-relogin.test.js +207 -0
  49. package/test/defer-detail-band.test.js +403 -0
  50. package/test/detail-band-tab-flatten.test.js +242 -0
  51. package/test/exec-diff.test.js +268 -0
  52. package/test/executors.test.js +250 -13
  53. package/test/extract-tool-calls.test.js +37 -3
  54. package/test/file-activity.test.js +542 -0
  55. package/test/grep-path-target.test.js +227 -0
  56. package/test/harness/chat-harness.js +2 -1
  57. package/test/headless.test.js +146 -1
  58. package/test/input-field-ctrl-o.test.js +37 -0
  59. package/test/live-height-physical.test.js +281 -0
  60. package/test/max-iterations.test.js +9 -7
  61. package/test/md-stream.test.js +183 -0
  62. package/test/narration-ordering.test.js +309 -0
  63. package/test/native-dispatch.test.js +53 -0
  64. package/test/native-live-narration.test.js +254 -0
  65. package/test/output-heredoc-leak.test.js +195 -0
  66. package/test/output-preview.test.js +245 -0
  67. package/test/permission-flush.test.js +302 -0
  68. package/test/permissions.test.js +199 -0
  69. package/test/read-paginate.test.js +1 -1
  70. package/test/render-operation.test.js +317 -0
  71. package/test/replay-descriptor-xml.test.js +216 -0
  72. package/test/replay-descriptor.test.js +189 -0
  73. package/test/replay-web-aggregate.test.js +291 -0
  74. package/test/replay-web-persist.test.js +241 -0
  75. package/test/running-glyph-anim.test.js +111 -0
  76. package/test/status-bar-driver.test.js +93 -0
  77. package/test/status-bar-resync.test.js +188 -0
  78. package/test/stream-parser.test.js +24 -0
  79. package/test/theme-palette.test.js +166 -0
  80. package/test/truncate-visible.test.js +78 -0
  81. package/test/view-image.test.js +199 -0
  82. package/test/web-activity-ordering.test.js +12 -3
  83. package/path +0 -1
@@ -22,7 +22,8 @@
22
22
  "Read(//srv/www/ai/**)",
23
23
  "Read(//srv/www/ai/cli.semalt.ai/**)",
24
24
  "Bash(npm run *)",
25
- "Bash(— normalized\\\\|mcp)"
25
+ "Bash(— normalized\\\\|mcp)",
26
+ "Bash(awk '{print $5, $9}')"
26
27
  ]
27
28
  }
28
29
  }
package/ARCHITECTURE.md CHANGED
@@ -1,99 +1,10 @@
1
- # semalt-code — Architecture Reference
1
+ # semalt-code — Architecture
2
2
 
3
- ## lib/ File Responsibilities
3
+ The architecture documentation has moved. The current, maintained reference lives at:
4
4
 
5
- | File | Responsibility |
6
- |------|----------------|
7
- | `lib/agent.js` | Agent loop: iterates up to 10 times, streams LLM response, extracts tool calls, dispatches execution, accumulates results back into the message history |
8
- | `lib/api.js` | HTTP client for both OpenAI-compatible inference (`chatStream`, `chatSync`) and dashboard REST calls (auth, models, chat history); manually parses `text/event-stream` |
9
- | `lib/args.js` | CLI argument parser; maps flags (`-m`, `-f`, `--dry-run`, …) to an `opts` object and collects positional args |
10
- | `lib/commands.js` | All top-level command handlers: `cmdChat`, `cmdCode`, `cmdEdit`, `cmdShell`, `cmdLogin`, `cmdLogout`, `cmdWhoAmI`, `cmdModels`, `cmdInit` |
11
- | `lib/config.js` | Read/write `~/.semalt-ai/config.json`; `normalizeConfig` merges defaults, migrates legacy keys, validates types |
12
- | `lib/constants.js` | `DEFAULT_CONFIG`, `DEFAULT_API_TIMEOUT_MS`, `CONFIG_PATH`, `PACKAGE_JSON` |
13
- | `lib/context.js` | Loads file or directory trees into a prompt context string; caps directory walks at 50 files, single files at 10 000 chars |
14
- | `lib/permissions.js` | Per-session approval tracking; interactive yes/always/no prompt before each tool action; `toggleAll` for `/approve` |
15
- | `lib/prompts.js` | Returns the system prompt string that instructs the LLM which XML tool tags to use and how |
16
- | `lib/tools.js` | Implements `agentExecShell` and `agentExecFile` (16 file/env/network actions) plus `extractToolCalls` regex parser |
17
- | `lib/ui.js` | All terminal rendering: ANSI constants, `StreamRenderer` (markdown + tool-call display + inline diff), `readInteractiveInput`, `interactiveSelect`, `printBanner`, `printStatusBar` |
5
+ **[docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md)** per-subsystem internals (MCP, checkpoints, sandbox, web-fetch pipeline, SDK, subagents, hooks, git tools, …).
18
6
 
19
- ---
7
+ See also:
20
8
 
21
- ## Agent Loop Flow
22
-
23
- 1. `runAgentLoop(messages, model)` is called with the current message array (max 10 iterations).
24
- 2. `chatStream(messages, { model })` sends the array to the LLM and streams tokens through `StreamRenderer` to the terminal.
25
- 3. The full assistant text is appended to `messages` as `{ role: 'assistant', content }`.
26
- 4. `extractToolCalls(reply)` scans the text for XML tool tags and fenced shell blocks; returns an ordered list of `[action, ...args]` tuples.
27
- 5. If no tool calls are found, the loop ends.
28
- 6. For each tool call, `permissionManager.askPermission(type, description)` prompts the user (yes / yes-always / no).
29
- 7. Approved shell calls go to `agentExecShell`; all other calls go to `agentExecFile`.
30
- 8. Results (or denial messages) are concatenated and pushed to `messages` as a `user` turn: `"Tool execution results:\n\n…\n\nContinue with the task."`.
31
- 9. If any call was denied, a warning is printed and the loop continues with partial results.
32
- 10. Go to step 2.
33
-
34
- ---
35
-
36
- ## Tool Tags
37
-
38
- All tags are parsed by `extractToolCalls` in `lib/tools.js` and displayed by `StreamRenderer` in `lib/ui.js`.
39
-
40
- | Tag | Syntax | Action dispatched |
41
- |-----|--------|-------------------|
42
- | `exec` | `<exec>command</exec>` | `shell` |
43
- | `shell` | `<shell>command</shell>` | `shell` (alias) |
44
- | `run_command` | `<run_command>command</run_command>` | `shell` (alias) |
45
- | `run` | `<run>command</run>` | `shell` (alias) |
46
- | Fenced shell block | ` ```shell\ncommand\n``` ` | `shell` (one call per non-comment line) |
47
- | `read_file` (content) | `<read_file>/path</read_file>` | `read` |
48
- | `read_file` (attribute) | `<read_file path="/path"/>` | `read` |
49
- | `write_file` | `<write_file path="/path">content</write_file>` | `write` |
50
- | `append_file` | `<append_file path="/path">content</append_file>` | `append` |
51
- | `list_dir` | `<list_dir>/path</list_dir>` | `list_dir` |
52
- | `search_files` | `<search_files>pattern</search_files>` | `search_files` |
53
- | `delete_file` | `<delete_file>/path</delete_file>` | `delete_file` |
54
- | `make_dir` | `<make_dir>/path</make_dir>` | `make_dir` |
55
- | `remove_dir` | `<remove_dir>/path</remove_dir>` | `remove_dir` |
56
- | `get_env` | `<get_env>VAR_NAME</get_env>` | `get_env` |
57
- | `set_env` | `<set_env name="VAR" value="val"/>` | `set_env` |
58
- | `move_file` | `<move_file src="/src" dst="/dst"/>` | `move_file` |
59
- | `copy_file` | `<copy_file src="/src" dst="/dst"/>` | `copy_file` |
60
- | `edit_file` | `<edit_file path="/path" line="N">new line content</edit_file>` | `edit_file` |
61
- | `search_in_file` | `<search_in_file path="/path">regex</search_in_file>` | `search_in_file` |
62
- | `replace_in_file` | `<replace_in_file path="/path" search="old" replace="new"></replace_in_file>` | `replace_in_file` |
63
- | `download` | `<download>https://url</download>` | `download` |
64
- | `upload` | `<upload path="/path">base64content</upload>` | `upload` |
65
-
66
- ---
67
-
68
- ## DEFAULT_CONFIG Keys
69
-
70
- Defined in `lib/constants.js` and merged/validated by `lib/config.js`.
71
-
72
- | Key | Default | Description |
73
- |-----|---------|-------------|
74
- | `api_base` | `"http://127.0.0.1:8800"` | OpenAI-compatible inference base URL (normalized to include `/v1`) |
75
- | `api_key` | `"any"` | API key sent as `Authorization: Bearer` to the inference endpoint |
76
- | `dashboard_url` | `"https://cli.semalt.ai"` | Base URL for the web dashboard (auth, models, chat history) |
77
- | `auth_token` | `""` | Bearer token written by `semalt login`, cleared by `logout` |
78
- | `default_model` | `"default"` | Model identifier sent in chat completions payloads |
79
- | `dashboard_model_id` | `null` | Integer PK of the active model in `available_models`; required for chat history sync |
80
- | `temperature` | `0.7` | Sampling temperature passed to the LLM |
81
- | `request_timeout_ms` | `900000` | HTTP request timeout for inference calls (ms) |
82
- | `stream` | `true` | Whether to use streaming (`text/event-stream`) for inference |
83
- | `models` | `[]` | Local model profile overrides (each: `api_base`, `api_key`, `model`) |
84
- | `theme` | `"dark"` | Terminal color theme |
85
- | `max_file_size_kb` | `512` | Maximum file size the agent will read (KB) |
86
- | `command_timeout_ms` | `30000` | Timeout for shell command execution (ms) |
87
- | `max_output_lines` | `50` | Maximum lines of tool output shown before truncation |
88
- | `show_token_count` | `true` | Display token usage in the status line after each turn |
89
- | `show_cost` | `false` | Display estimated cost alongside token count |
90
-
91
- ---
92
-
93
- ## Planned Additions
94
-
95
- | File | Intended Responsibility |
96
- |------|------------------------|
97
- | `lib/audit.js` | Persistent log of all tool calls executed per session (command, args, exit code, timestamp); used for replay and compliance review |
98
- | `lib/storage.js` | Local SQLite or JSON-lines store for offline chat history, message deduplication, and cache of dashboard responses |
99
- | `lib/metrics.js` | Collects per-session telemetry (token counts, latency, tool-call frequency) and exposes summary output for `/compact` and future analytics export |
9
+ - [docs/CONFIG.md](./docs/CONFIG.md) config keys, CLI flags/commands, slash commands, tool tags.
10
+ - [docs/HISTORY.md](./docs/HISTORY.md) — design rationale, dependency policy, and roadmap.