lemonpie-cli 0.3.0__tar.gz → 0.3.1__tar.gz
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.
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/.gitignore +1 -0
- lemonpie_cli-0.3.1/.release-please/manifest.json +3 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/CHANGELOG.md +19 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/PKG-INFO +4 -1
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/README.md +3 -0
- lemonpie_cli-0.3.1/docs/design/feature-ideas.md +187 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/docs/usage/command-index.md +2 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/_version.py +2 -2
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/cli/parser.py +1 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/client.py +11 -6
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/main.py +51 -5
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/tests/test_client.py +22 -11
- lemonpie_cli-0.3.1/tests/test_dry_run.py +221 -0
- lemonpie_cli-0.3.0/.release-please/manifest.json +0 -3
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/.github/workflows/ci.yml +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/.github/workflows/release.yml +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/.release-please/config.json +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/LICENSE +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/docs/ROADMAP.md +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/docs/config.example.json +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/docs/design/code-completion.md +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/docs/design/model-verification.md +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/docs/design/packaging.md +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/pyproject.toml +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/__init__.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/cli/__init__.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/cli/config_cmd.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/cli/ui.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/config.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/models.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/paths.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/sessions/__init__.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/sessions/storage.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/src/lemonpie/time_utils.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/tests/conftest.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/tests/test_cli.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/tests/test_config_cmd.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/tests/test_sessions.py +0 -0
- {lemonpie_cli-0.3.0 → lemonpie_cli-0.3.1}/uv.lock +0 -0
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.1](https://github.com/famousStratum/LemonPie/compare/v0.3.0...v0.3.1) (2026-11-15)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add --dry-run flag for previewing actions ([b432c2e](https://github.com/famousStratum/LemonPie/commit/b432c2e115c323af9ee13c13da560891873328ba))
|
|
9
|
+
* add --dry-run flag to preview actions without executing them ([dab6f25](https://github.com/famousStratum/LemonPie/commit/dab6f2527f753375d1489d51610aef743980051f))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* add autouse mock_argv fixture to prevent CI test failures ([3b7745f](https://github.com/famousStratum/LemonPie/commit/3b7745ffd605068c49b3ccbf296e35265e741f28))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Documentation
|
|
18
|
+
|
|
19
|
+
* create a doc for feature ideas ([#45](https://github.com/famousStratum/LemonPie/issues/45)) ([9e83b95](https://github.com/famousStratum/LemonPie/commit/9e83b95456b6657f17b1d3442cf1c984049671a7))
|
|
20
|
+
* update README description and --dry-run status ([999159f](https://github.com/famousStratum/LemonPie/commit/999159f9782039d4049e448121ccbae4538ea779))
|
|
21
|
+
|
|
3
22
|
## [0.3.0](https://github.com/famousStratum/LemonPie/compare/v0.2.0...v0.3.0) (2026-11-11)
|
|
4
23
|
|
|
5
24
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: lemonpie-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: LemonPie — A lightweight CLI for LLM inference servers
|
|
5
5
|
Project-URL: homepage, https://versicode.com/projects/lemon-pie
|
|
6
6
|
Project-URL: repository, https://github.com/famousStratum/LemonPie
|
|
@@ -123,6 +123,9 @@ models: list of objects with alias (nullable) and name
|
|
|
123
123
|
- Print current session history\
|
|
124
124
|
`lm -p`
|
|
125
125
|
|
|
126
|
+
- Show what would happen without sending requests or modifying any data (dry run)\
|
|
127
|
+
`lm --dry-run -n "Hello"`
|
|
128
|
+
|
|
126
129
|
- Switch model in current session\
|
|
127
130
|
`lm -m qwen2.5-coder:3b`
|
|
128
131
|
|
|
@@ -104,6 +104,9 @@ models: list of objects with alias (nullable) and name
|
|
|
104
104
|
- Print current session history\
|
|
105
105
|
`lm -p`
|
|
106
106
|
|
|
107
|
+
- Show what would happen without sending requests or modifying any data (dry run)\
|
|
108
|
+
`lm --dry-run -n "Hello"`
|
|
109
|
+
|
|
107
110
|
- Switch model in current session\
|
|
108
111
|
`lm -m qwen2.5-coder:3b`
|
|
109
112
|
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# 🍋 Feature Ideas & Enhancement Brainstorm
|
|
2
|
+
|
|
3
|
+
**Status:** Draft / Brainstorm
|
|
4
|
+
|
|
5
|
+
This document collects feature ideas and enhancement recommendations for LemonPie.
|
|
6
|
+
It serves as a living reference for prioritization and implementation planning.
|
|
7
|
+
Items are categorized by effort/value and linked to design docs where applicable.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🔥 High Priority — Essential
|
|
12
|
+
|
|
13
|
+
### 1. Session Truncation / Context Management
|
|
14
|
+
|
|
15
|
+
**Problem:** Session history grows without bound. Eventually hits model context limits and inflates API cost. This is a technical bottleneck, not just a convenience issue.
|
|
16
|
+
|
|
17
|
+
**Proposal:**
|
|
18
|
+
- `--max-turns N` — auto-truncate oldest conversation turns (simple, no model call)
|
|
19
|
+
- `--context-size <tokens>` — trim messages to fit a specified context window
|
|
20
|
+
- `--compact` — summarize older turns before sending to reduce client-side memory and network payload size (inference cost is on the server, not the client)
|
|
21
|
+
|
|
22
|
+
**Status:** Not implemented.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
### 2. System Prompt Support
|
|
27
|
+
|
|
28
|
+
**Problem:** No way to give the model a role or instructions outside the conversation. Cannot do "act as a code reviewer" or set context.
|
|
29
|
+
|
|
30
|
+
**Proposal:** Add system prompt via:
|
|
31
|
+
- `lm --system "You are a helpful Python tutor"`
|
|
32
|
+
- `lm --system-file ./system-prompt.txt`
|
|
33
|
+
|
|
34
|
+
Stored per-session so it persists with history. Default system prompt could be configured in `config.json`.
|
|
35
|
+
|
|
36
|
+
**Status:** Not implemented.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
### 3. Interactive REPL Mode
|
|
41
|
+
|
|
42
|
+
**Problem:** `lm` is a single-shot tool — type prompt, get response, exit. No persistent chat.
|
|
43
|
+
|
|
44
|
+
**Proposal:** A `lm --repl` mode that stays in the loop:
|
|
45
|
+
- Accepts user input interactively
|
|
46
|
+
- Auto-appends to current session history
|
|
47
|
+
- Supports slash-commands:
|
|
48
|
+
- `/new` — start a new session
|
|
49
|
+
- `/close` — close current session
|
|
50
|
+
- `/history` — print conversation history
|
|
51
|
+
- `/model <name>` — switch model
|
|
52
|
+
- `/title <text>` — rename session
|
|
53
|
+
- `/exit` — quit
|
|
54
|
+
- Can be combined with existing flags: `lm --repl -m qwen`
|
|
55
|
+
|
|
56
|
+
**Sub-features:** REPL keyboard shortcuts and history (up-arrow for previous prompts, tab completion for model names/aliases, `Ctrl+R` for search). Depends on REPL being implemented first.
|
|
57
|
+
|
|
58
|
+
**Status:** Not implemented. Mentioned in [ROADMAP.md](../ROADMAP.md).
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## ⚡ Medium Priority — Medium Value
|
|
63
|
+
|
|
64
|
+
### 4. Temperature / Sampling Parameters
|
|
65
|
+
|
|
66
|
+
**Proposal:** Add sampling control:
|
|
67
|
+
```
|
|
68
|
+
lm --temperature 0.7 --top-p 0.9 --max-tokens 2048
|
|
69
|
+
```
|
|
70
|
+
Store defaults in `config.json` or allow per-session overrides. Useful for code generation (low temp) vs. brainstorming (high temp).
|
|
71
|
+
|
|
72
|
+
**Status:** Not implemented.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### 5. Stdin / Pipe Input
|
|
77
|
+
|
|
78
|
+
**Problem:** No way to pipe text into a prompt. Forces users to type or use `-n "..."` with shell escaping.
|
|
79
|
+
|
|
80
|
+
**Proposal:**
|
|
81
|
+
- `lm -n -m qwen < some_file.py` — send a file's contents as the prompt
|
|
82
|
+
- `cat log.txt | lm "summarize this"` — natural Unix workflow
|
|
83
|
+
- Detect EOF / tty to differentiate pipe from interactive
|
|
84
|
+
|
|
85
|
+
**Status:** Not implemented.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### 6. Schema Validation for Config
|
|
90
|
+
|
|
91
|
+
**Problem:** Config is entirely duck-typed JSON. Typos like `"serer"` instead of `"server"` cause silent misbehavior.
|
|
92
|
+
|
|
93
|
+
**Proposal:** Validate `config.json` on load:
|
|
94
|
+
- Use `pydantic` or `jsonschema`
|
|
95
|
+
- Warn and auto-migrate on unknown fields
|
|
96
|
+
- Type-check required fields
|
|
97
|
+
|
|
98
|
+
**Status:** Partial — `ensure_models_list()` handles one migration case. No general validation.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 🛠 Quick Wins — Low Effort, Noticeable Improvement
|
|
103
|
+
|
|
104
|
+
### 7. `--config <path>` Flag
|
|
105
|
+
|
|
106
|
+
Override the config file location from the CLI. Useful for testing, temporary overrides, or multi-environment setups.
|
|
107
|
+
|
|
108
|
+
**Status:** Not implemented.
|
|
109
|
+
|
|
110
|
+
### 8. `--dry-run` Flag
|
|
111
|
+
|
|
112
|
+
Print the HTTP payload (`/v1/chat/completions` body) without sending it. Debugging tool for verifying prompts, system prompts, and message history.
|
|
113
|
+
|
|
114
|
+
**Status:** Implemented.
|
|
115
|
+
|
|
116
|
+
### 9. Config Migration Warnings
|
|
117
|
+
|
|
118
|
+
Warn the user when loading an old config format (e.g. pre-0.2.0) and auto-migrate. Currently, missing keys silently default to `None`.
|
|
119
|
+
|
|
120
|
+
**Status:** Not implemented.
|
|
121
|
+
|
|
122
|
+
### 10. `lmConfig --update-models`
|
|
123
|
+
|
|
124
|
+
Re-fetch available models from the server without re-running the full `--init` wizard. A quick way to refresh the model list.
|
|
125
|
+
|
|
126
|
+
**Status:** Not implemented.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## ⏳ Deferred
|
|
131
|
+
|
|
132
|
+
### ~~Session Export / Import~~ — Deferred
|
|
133
|
+
|
|
134
|
+
~~**Proposal:**~~
|
|
135
|
+
~~- `lm --export <id> > session.json` — export a session to a file~~
|
|
136
|
+
~~- `lm --import session.json` — import a session from a file~~
|
|
137
|
+
~~- Useful for sharing, migrating, or backup~~
|
|
138
|
+
|
|
139
|
+
**Reason deferred:** Sessions are already JSON files stored on disk. For SBC/low-resource use cases, `scp` or `rsync` for backups, and git for migration, cover the common workflows. A dedicated export/import feature adds complexity for a convenience gap that file operations solve adequately today.
|
|
140
|
+
|
|
141
|
+
**Status:** Deferred — may revisit for schema versioning or batch operations in the future.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### ~~Model Comparison Mode~~ — Deferred
|
|
146
|
+
|
|
147
|
+
~~`lm --compare model1 model2 --prompt "explain quantum computing"` — sends the same prompt to two models, outputs responses side by side.~~
|
|
148
|
+
|
|
149
|
+
**Reason deferred:** Relatively high resource cost (2× API requests, 2× compute) for a niche feature. Lower priority than core functionality. May revisit if a lightweight streaming side-by-side mode makes sense later.
|
|
150
|
+
|
|
151
|
+
**Status:** Deferred.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## 📋 Already Planned (Linked Design Docs)
|
|
156
|
+
|
|
157
|
+
### Code Completion
|
|
158
|
+
- See [code-completion.md](code-completion.md)
|
|
159
|
+
- `--autocomplete` flag, system role enforcement, REPL integration
|
|
160
|
+
|
|
161
|
+
### Model Verification State Machine
|
|
162
|
+
- See [model-verification.md](model-verification.md)
|
|
163
|
+
- Server reachability check, model installation, pull workflow
|
|
164
|
+
|
|
165
|
+
### Cross-Platform Packaging
|
|
166
|
+
- See [packaging.md](packaging.md)
|
|
167
|
+
- `.deb`, `winget`, Homebrew distribution
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 📌 How to Use This Document
|
|
172
|
+
|
|
173
|
+
1. **Discuss and debate** — add comments, objections, alternatives
|
|
174
|
+
2. **Prioritize** — assign priority labels or move items between sections
|
|
175
|
+
3. **Combine** — ideas can merge (e.g., REPL + System Prompt + Parameters are related)
|
|
176
|
+
4. **Split** — large ideas can be broken into sub-tasks
|
|
177
|
+
5. **When ready**, promote an item to a dedicated design doc and move it to "Implemented"
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
*Last updated: 2026-11-12*
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
### Changes
|
|
186
|
+
|
|
187
|
+
- **2026-11-12:** Promoted session truncation and REPL mode to essential priority. Reordered essential section: (1) Truncation, (2) System prompt, (3) REPL. Moved compaction back in (client resource savings, not server cost concern). Moved session export/import and model comparison to "Deferred" section (crossed out). Removed "Niche/Fun" section (REPL shortcuts absorbed into REPL section).
|
|
@@ -33,11 +33,13 @@ Run LemonPie with a given model or prompt.
|
|
|
33
33
|
- `-c, --close` — Close current session
|
|
34
34
|
- `-p, --print` — Print current session history
|
|
35
35
|
- `--delete-all` — Delete all stored sessions
|
|
36
|
+
- `--dry-run` — Print the HTTP payload without sending it (debugging tool)
|
|
36
37
|
- `prompt` — Prompt text (positional argument)
|
|
37
38
|
|
|
38
39
|
---
|
|
39
40
|
|
|
40
41
|
## Notes
|
|
42
|
+
- `--dry-run` prints the full JSON payload to `/v1/chat/completions` and exits (exit code 0)
|
|
41
43
|
- Flags can be combined with prompts, e.g.:
|
|
42
44
|
`lm -m smollm:360m -n "Hello world"`
|
|
43
45
|
- `--force` applies to `lmConfig --add-model` (overwrite alias conflicts) and `lmConfig --init` (skip server verification).
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.3.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 3,
|
|
21
|
+
__version__ = version = '0.3.1'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 3, 1)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -18,5 +18,6 @@ def build_parser():
|
|
|
18
18
|
parser.add_argument("-c", "--close", action="store_true", help="Close current session")
|
|
19
19
|
parser.add_argument("-p", "--print", action="store_true", help="Print current session history")
|
|
20
20
|
parser.add_argument("--delete-all", action="store_true", help="Delete all stored sessions")
|
|
21
|
+
parser.add_argument("--dry-run", action="store_true", help="Show what would happen without sending requests or modifying any data")
|
|
21
22
|
parser.add_argument("prompt", nargs="*", help="Prompt text")
|
|
22
23
|
return parser
|
|
@@ -12,17 +12,22 @@ def build_client(server_host, timeout, api_key=None):
|
|
|
12
12
|
return httpx.Client(base_url=server_host, timeout=timeout, headers=headers)
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
def
|
|
16
|
-
"""
|
|
17
|
-
Stream a chat completion from an OpenAI-compatible endpoint,
|
|
18
|
-
yielding text content chunks.
|
|
19
|
-
"""
|
|
15
|
+
def build_payload(model, messages, stream=True, **extra_params):
|
|
16
|
+
"""Build the JSON payload for /v1/chat/completions."""
|
|
20
17
|
payload = {
|
|
21
18
|
"model": model,
|
|
22
19
|
"messages": [{"role": m["role"], "content": m["content"]} for m in messages],
|
|
23
|
-
"stream":
|
|
20
|
+
"stream": stream,
|
|
24
21
|
}
|
|
22
|
+
payload.update(extra_params)
|
|
23
|
+
return payload
|
|
24
|
+
|
|
25
25
|
|
|
26
|
+
def stream_chat(client, payload):
|
|
27
|
+
"""
|
|
28
|
+
Stream a chat completion from an OpenAI-compatible endpoint,
|
|
29
|
+
yielding text content chunks.
|
|
30
|
+
"""
|
|
26
31
|
with client.stream("POST", "/v1/chat/completions", json=payload) as response:
|
|
27
32
|
response.raise_for_status()
|
|
28
33
|
for line in response.iter_lines():
|
|
@@ -17,6 +17,7 @@ Quick usage
|
|
|
17
17
|
See README.md for details and maintainer notes.
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
|
+
import json
|
|
20
21
|
import sys
|
|
21
22
|
|
|
22
23
|
import httpx
|
|
@@ -30,6 +31,7 @@ from lemonpie.cli.ui import (
|
|
|
30
31
|
)
|
|
31
32
|
from lemonpie.client import (
|
|
32
33
|
build_client,
|
|
34
|
+
build_payload,
|
|
33
35
|
resolve_error,
|
|
34
36
|
stream_chat,
|
|
35
37
|
)
|
|
@@ -73,6 +75,18 @@ def main():
|
|
|
73
75
|
|
|
74
76
|
# Direct CLI actions
|
|
75
77
|
|
|
78
|
+
# dry_run intercept: show what would happen, don't perform any action
|
|
79
|
+
if args.dry_run:
|
|
80
|
+
if args.delete:
|
|
81
|
+
print(f"Would delete session {args.delete}.")
|
|
82
|
+
sys.exit(0)
|
|
83
|
+
if args.delete_all:
|
|
84
|
+
print("Would delete all sessions.")
|
|
85
|
+
sys.exit(0)
|
|
86
|
+
if args.close:
|
|
87
|
+
print("Would close the current session.")
|
|
88
|
+
sys.exit(0)
|
|
89
|
+
|
|
76
90
|
if args.list:
|
|
77
91
|
print_sessions_list()
|
|
78
92
|
sys.exit(0)
|
|
@@ -114,6 +128,36 @@ def main():
|
|
|
114
128
|
print("Use lmConfig to add one or pass a known alias with -m.")
|
|
115
129
|
sys.exit(1)
|
|
116
130
|
|
|
131
|
+
# --- dry_run: build and print payload without writing anything ---
|
|
132
|
+
if args.dry_run:
|
|
133
|
+
# Explicit session override takes precedence over current session pointer
|
|
134
|
+
if args.session:
|
|
135
|
+
session = load_session(args.session)
|
|
136
|
+
history = session.get("history", []) if session else []
|
|
137
|
+
elif current_id:
|
|
138
|
+
session = load_session(current_id)
|
|
139
|
+
history = session.get("history", []) if session else []
|
|
140
|
+
else:
|
|
141
|
+
history = []
|
|
142
|
+
|
|
143
|
+
# Build messages: session history + prompt
|
|
144
|
+
payload_messages = [
|
|
145
|
+
{"role": m["role"], "content": m["content"]} for m in history
|
|
146
|
+
]
|
|
147
|
+
if args.prompt:
|
|
148
|
+
payload_messages.append(
|
|
149
|
+
{"role": "user", "content": " ".join(args.prompt)}
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
if not payload_messages:
|
|
153
|
+
print("No messages to send. Provide a prompt or load a session.")
|
|
154
|
+
sys.exit(0)
|
|
155
|
+
|
|
156
|
+
payload = build_payload(model, payload_messages)
|
|
157
|
+
print("=== Dry Run: HTTP Payload ===")
|
|
158
|
+
print(json.dumps(payload, indent=2))
|
|
159
|
+
sys.exit(0)
|
|
160
|
+
|
|
117
161
|
if (
|
|
118
162
|
model_flag
|
|
119
163
|
and not current_id
|
|
@@ -147,6 +191,8 @@ def main():
|
|
|
147
191
|
{"role": "user", "content": user_prompt, "ts": turn_ts}
|
|
148
192
|
)
|
|
149
193
|
session["updated_at"] = turn_ts
|
|
194
|
+
|
|
195
|
+
payload = build_payload(model, session["history"])
|
|
150
196
|
save_session(session_id, session)
|
|
151
197
|
|
|
152
198
|
if not find_by_name(cfg, model):
|
|
@@ -155,6 +201,10 @@ def main():
|
|
|
155
201
|
)
|
|
156
202
|
sys.exit(1)
|
|
157
203
|
|
|
204
|
+
if not server_host:
|
|
205
|
+
print("No server configured. Run `lmConfig --init` to get started.")
|
|
206
|
+
sys.exit(1)
|
|
207
|
+
|
|
158
208
|
spinner = StatusSpinner(CONNECTING_MSGS)
|
|
159
209
|
spinner.start()
|
|
160
210
|
|
|
@@ -162,11 +212,7 @@ def main():
|
|
|
162
212
|
reply_ts = None
|
|
163
213
|
first_chunk_seen = False
|
|
164
214
|
|
|
165
|
-
|
|
166
|
-
print("No server configured. Run `lmConfig --init` to get started.")
|
|
167
|
-
sys.exit(1)
|
|
168
|
-
|
|
169
|
-
chunks = stream_chat(client, model, session["history"])
|
|
215
|
+
chunks = stream_chat(client, payload)
|
|
170
216
|
|
|
171
217
|
try:
|
|
172
218
|
for content in chunks:
|
|
@@ -5,9 +5,8 @@ from contextlib import contextmanager
|
|
|
5
5
|
from unittest.mock import MagicMock, patch
|
|
6
6
|
|
|
7
7
|
import httpx
|
|
8
|
-
import pytest
|
|
9
8
|
|
|
10
|
-
from lemonpie.client import build_client, resolve_error, stream_chat
|
|
9
|
+
from lemonpie.client import build_client, build_payload, resolve_error, stream_chat
|
|
11
10
|
|
|
12
11
|
SERVER = "http://localhost:9931"
|
|
13
12
|
|
|
@@ -16,11 +15,11 @@ SERVER = "http://localhost:9931"
|
|
|
16
15
|
# Helpers
|
|
17
16
|
# ---------------------------------------------------------------------------
|
|
18
17
|
|
|
18
|
+
|
|
19
19
|
def _make_sse_lines(chunks):
|
|
20
20
|
"""Build an SSE line list from a list of content strings."""
|
|
21
21
|
lines = [
|
|
22
|
-
f
|
|
23
|
-
for c in chunks
|
|
22
|
+
f"data: {json.dumps({'choices': [{'delta': {'content': c}}]})}" for c in chunks
|
|
24
23
|
]
|
|
25
24
|
lines.append("data: [DONE]")
|
|
26
25
|
return lines
|
|
@@ -43,6 +42,7 @@ def _mock_stream(lines):
|
|
|
43
42
|
# build_client
|
|
44
43
|
# ---------------------------------------------------------------------------
|
|
45
44
|
|
|
45
|
+
|
|
46
46
|
class TestBuildClient:
|
|
47
47
|
def test_returns_httpx_client(self):
|
|
48
48
|
client = build_client(SERVER, httpx.Timeout(5.0))
|
|
@@ -65,6 +65,7 @@ class TestBuildClient:
|
|
|
65
65
|
# stream_chat
|
|
66
66
|
# ---------------------------------------------------------------------------
|
|
67
67
|
|
|
68
|
+
|
|
68
69
|
class TestStreamChat:
|
|
69
70
|
def _client(self):
|
|
70
71
|
return httpx.Client(base_url=SERVER)
|
|
@@ -72,8 +73,13 @@ class TestStreamChat:
|
|
|
72
73
|
def test_yields_content_chunks(self):
|
|
73
74
|
client = self._client()
|
|
74
75
|
messages = [{"role": "user", "content": "hi"}]
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
payload = build_payload("qwen", messages)
|
|
77
|
+
with patch.object(
|
|
78
|
+
client,
|
|
79
|
+
"stream",
|
|
80
|
+
new=_mock_stream(_make_sse_lines(["Hello", ", ", "world"])),
|
|
81
|
+
):
|
|
82
|
+
result = list(stream_chat(client, payload))
|
|
77
83
|
assert result == ["Hello", ", ", "world"]
|
|
78
84
|
|
|
79
85
|
def test_strips_ts_from_messages(self):
|
|
@@ -91,7 +97,7 @@ class TestStreamChat:
|
|
|
91
97
|
yield mock_response
|
|
92
98
|
|
|
93
99
|
with patch.object(client, "stream", new=capturing_stream):
|
|
94
|
-
list(stream_chat(client, "qwen", messages))
|
|
100
|
+
list(stream_chat(client, build_payload("qwen", messages)))
|
|
95
101
|
|
|
96
102
|
sent = captured["json"]["messages"]
|
|
97
103
|
assert sent == [{"role": "user", "content": "hi"}]
|
|
@@ -99,6 +105,7 @@ class TestStreamChat:
|
|
|
99
105
|
def test_skips_empty_content(self):
|
|
100
106
|
client = self._client()
|
|
101
107
|
messages = [{"role": "user", "content": "hi"}]
|
|
108
|
+
payload = build_payload("qwen", messages)
|
|
102
109
|
lines = [
|
|
103
110
|
'data: {"choices": [{"delta": {"content": ""}}]}',
|
|
104
111
|
'data: {"choices": [{"delta": {}}]}',
|
|
@@ -106,24 +113,26 @@ class TestStreamChat:
|
|
|
106
113
|
"data: [DONE]",
|
|
107
114
|
]
|
|
108
115
|
with patch.object(client, "stream", new=_mock_stream(lines)):
|
|
109
|
-
result = list(stream_chat(client,
|
|
116
|
+
result = list(stream_chat(client, payload))
|
|
110
117
|
assert result == ["real"]
|
|
111
118
|
|
|
112
119
|
def test_stops_at_done_sentinel(self):
|
|
113
120
|
client = self._client()
|
|
114
121
|
messages = [{"role": "user", "content": "hi"}]
|
|
122
|
+
payload = build_payload("qwen", messages)
|
|
115
123
|
lines = [
|
|
116
124
|
'data: {"choices": [{"delta": {"content": "before"}}]}',
|
|
117
125
|
"data: [DONE]",
|
|
118
126
|
'data: {"choices": [{"delta": {"content": "after"}}]}',
|
|
119
127
|
]
|
|
120
128
|
with patch.object(client, "stream", new=_mock_stream(lines)):
|
|
121
|
-
result = list(stream_chat(client,
|
|
129
|
+
result = list(stream_chat(client, payload))
|
|
122
130
|
assert result == ["before"]
|
|
123
131
|
|
|
124
132
|
def test_skips_non_data_lines(self):
|
|
125
133
|
client = self._client()
|
|
126
134
|
messages = [{"role": "user", "content": "hi"}]
|
|
135
|
+
payload = build_payload("qwen", messages)
|
|
127
136
|
lines = [
|
|
128
137
|
": keep-alive",
|
|
129
138
|
"",
|
|
@@ -131,19 +140,20 @@ class TestStreamChat:
|
|
|
131
140
|
"data: [DONE]",
|
|
132
141
|
]
|
|
133
142
|
with patch.object(client, "stream", new=_mock_stream(lines)):
|
|
134
|
-
result = list(stream_chat(client,
|
|
143
|
+
result = list(stream_chat(client, payload))
|
|
135
144
|
assert result == ["hi"]
|
|
136
145
|
|
|
137
146
|
def test_skips_malformed_json(self):
|
|
138
147
|
client = self._client()
|
|
139
148
|
messages = [{"role": "user", "content": "hi"}]
|
|
149
|
+
payload = build_payload("qwen", messages)
|
|
140
150
|
lines = [
|
|
141
151
|
"data: {not valid json",
|
|
142
152
|
'data: {"choices": [{"delta": {"content": "ok"}}]}',
|
|
143
153
|
"data: [DONE]",
|
|
144
154
|
]
|
|
145
155
|
with patch.object(client, "stream", new=_mock_stream(lines)):
|
|
146
|
-
result = list(stream_chat(client,
|
|
156
|
+
result = list(stream_chat(client, payload))
|
|
147
157
|
assert result == ["ok"]
|
|
148
158
|
|
|
149
159
|
|
|
@@ -151,6 +161,7 @@ class TestStreamChat:
|
|
|
151
161
|
# resolve_error
|
|
152
162
|
# ---------------------------------------------------------------------------
|
|
153
163
|
|
|
164
|
+
|
|
154
165
|
class TestResolveError:
|
|
155
166
|
def test_connect_timeout(self):
|
|
156
167
|
exc = httpx.ConnectTimeout("timed out")
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"""Integration tests for `lm --dry-run` behaviour in lemonpie.main."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from unittest.mock import MagicMock, patch
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from lemonpie.main import main
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.fixture(autouse=True)
|
|
12
|
+
def mock_argv():
|
|
13
|
+
with patch("sys.argv", ["lm", "--dry-run"]):
|
|
14
|
+
yield
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
|
+
# Helpers
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
def _mock_args(**overrides):
|
|
22
|
+
"""Build a parser-args mock with sensible defaults."""
|
|
23
|
+
defaults = {
|
|
24
|
+
"model": None,
|
|
25
|
+
"new": False,
|
|
26
|
+
"session": None,
|
|
27
|
+
"list": False,
|
|
28
|
+
"delete": None,
|
|
29
|
+
"title": None,
|
|
30
|
+
"close": False,
|
|
31
|
+
"print": False,
|
|
32
|
+
"delete_all": False,
|
|
33
|
+
"dry_run": False,
|
|
34
|
+
"prompt": [],
|
|
35
|
+
}
|
|
36
|
+
defaults.update(overrides)
|
|
37
|
+
return MagicMock(**defaults)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# ---------------------------------------------------------------------------
|
|
41
|
+
# --dry-run: no prompt, no session
|
|
42
|
+
# ---------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
class TestDryRunNoPrompt:
|
|
45
|
+
def test_exits_zero_and_prints_message(self, isolated_dirs, write_cfg, capsys):
|
|
46
|
+
"""No prompt + no current session → 'No messages to send', exit 0."""
|
|
47
|
+
with patch("lemonpie.main.build_parser") as mock_parser_cls:
|
|
48
|
+
mock_parser_cls.return_value.parse_args.return_value = _mock_args(dry_run=True)
|
|
49
|
+
with pytest.raises(SystemExit) as exc:
|
|
50
|
+
main()
|
|
51
|
+
assert exc.value.code == 0
|
|
52
|
+
assert "No messages to send" in capsys.readouterr().out
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# ---------------------------------------------------------------------------
|
|
56
|
+
# --dry-run: prompt with no existing session
|
|
57
|
+
# ---------------------------------------------------------------------------
|
|
58
|
+
|
|
59
|
+
class TestDryRunPromptNoSession:
|
|
60
|
+
def test_payload_contains_only_user_message(self, isolated_dirs, write_cfg, capsys):
|
|
61
|
+
"""Prompt + no session → payload has just the user message, no writes."""
|
|
62
|
+
with patch("lemonpie.main.build_parser") as mock_parser_cls:
|
|
63
|
+
mock_parser_cls.return_value.parse_args.return_value = _mock_args(
|
|
64
|
+
dry_run=True, prompt=["hello world"]
|
|
65
|
+
)
|
|
66
|
+
with pytest.raises(SystemExit) as exc:
|
|
67
|
+
main()
|
|
68
|
+
|
|
69
|
+
assert exc.value.code == 0
|
|
70
|
+
output = capsys.readouterr().out
|
|
71
|
+
|
|
72
|
+
# Should start with the header line
|
|
73
|
+
assert "=== Dry Run: HTTP Payload ===" in output
|
|
74
|
+
|
|
75
|
+
# Parse the JSON and verify its contents
|
|
76
|
+
# Output has header line, then JSON object on following lines
|
|
77
|
+
json_part = output.split("=== Dry Run: HTTP Payload ===", 1)[1].strip()
|
|
78
|
+
payload = json.loads(json_part)
|
|
79
|
+
|
|
80
|
+
assert payload["model"] == "qwen2.5-coder:3b"
|
|
81
|
+
assert payload["stream"] is True
|
|
82
|
+
assert len(payload["messages"]) == 1
|
|
83
|
+
assert payload["messages"][0] == {"role": "user", "content": "hello world"}
|
|
84
|
+
|
|
85
|
+
# No session file should have been created
|
|
86
|
+
session_files = list(isolated_dirs["session_dir"].glob("*.json"))
|
|
87
|
+
assert len(session_files) == 0, (
|
|
88
|
+
"dry-run with no session must not create session files"
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
# ---------------------------------------------------------------------------
|
|
93
|
+
# --dry-run: -s flag takes precedence over current session pointer
|
|
94
|
+
# ---------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
class TestDryRunWithSessionFlag:
|
|
97
|
+
def test_loads_specified_session_not_current(self, isolated_dirs, write_cfg, capsys):
|
|
98
|
+
"""-s <id> loads that session's history, not the current session's."""
|
|
99
|
+
# Create two sessions with different history
|
|
100
|
+
session_a = {
|
|
101
|
+
"id": "20260101-000000-aaa",
|
|
102
|
+
"model": "qwen2.5-coder:3b",
|
|
103
|
+
"title": "Current Session",
|
|
104
|
+
"history": [
|
|
105
|
+
{"role": "user", "content": "current-only"},
|
|
106
|
+
{"role": "assistant", "content": "from-current"},
|
|
107
|
+
],
|
|
108
|
+
}
|
|
109
|
+
session_b = {
|
|
110
|
+
"id": "20260101-000000-bbb",
|
|
111
|
+
"model": "qwen2.5-coder:3b",
|
|
112
|
+
"title": "Target Session",
|
|
113
|
+
"history": [
|
|
114
|
+
{"role": "user", "content": "target-only"},
|
|
115
|
+
{"role": "assistant", "content": "from-target"},
|
|
116
|
+
],
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
# Write session A as the "current" session
|
|
120
|
+
isolated_dirs["current_file"].write_text("20260101-000000-aaa", encoding="utf-8")
|
|
121
|
+
isolated_dirs["session_dir"].joinpath(
|
|
122
|
+
"20260101-000000-aaa.json"
|
|
123
|
+
).write_text(json.dumps(session_a), encoding="utf-8")
|
|
124
|
+
|
|
125
|
+
# Write session B (the one we want to load via -s)
|
|
126
|
+
isolated_dirs["session_dir"].joinpath(
|
|
127
|
+
"20260101-000000-bbb.json"
|
|
128
|
+
).write_text(json.dumps(session_b), encoding="utf-8")
|
|
129
|
+
|
|
130
|
+
with patch("lemonpie.main.build_parser") as mock_parser_cls:
|
|
131
|
+
mock_parser_cls.return_value.parse_args.return_value = _mock_args(
|
|
132
|
+
dry_run=True,
|
|
133
|
+
prompt=["added-later"],
|
|
134
|
+
session="20260101-000000-bbb",
|
|
135
|
+
)
|
|
136
|
+
with pytest.raises(SystemExit) as exc:
|
|
137
|
+
main()
|
|
138
|
+
|
|
139
|
+
assert exc.value.code == 0
|
|
140
|
+
output = capsys.readouterr().out
|
|
141
|
+
|
|
142
|
+
json_part = output.split("=== Dry Run: HTTP Payload ===", 1)[1].strip()
|
|
143
|
+
payload = json.loads(json_part)
|
|
144
|
+
|
|
145
|
+
messages = [m["content"] for m in payload["messages"]]
|
|
146
|
+
# Should contain target session history + prompt
|
|
147
|
+
assert "target-only" in messages
|
|
148
|
+
assert "from-target" in messages
|
|
149
|
+
assert "added-later" in messages
|
|
150
|
+
# Must NOT contain current session messages
|
|
151
|
+
assert "current-only" not in messages
|
|
152
|
+
assert "from-current" not in messages
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# ---------------------------------------------------------------------------
|
|
156
|
+
# Regression guard: normal prompt flow still works
|
|
157
|
+
# ---------------------------------------------------------------------------
|
|
158
|
+
|
|
159
|
+
class TestNormalPromptFlow:
|
|
160
|
+
def test_sends_request_via_stream_chat(self, isolated_dirs, write_cfg):
|
|
161
|
+
"""A normal prompt (no --dry-run) reaches stream_chat without crashing."""
|
|
162
|
+
with patch("lemonpie.main.build_parser") as mock_parser_cls:
|
|
163
|
+
mock_parser_cls.return_value.parse_args.return_value = _mock_args(
|
|
164
|
+
prompt=["test prompt"]
|
|
165
|
+
)
|
|
166
|
+
with patch("lemonpie.main.StatusSpinner") as mock_spinner_cls:
|
|
167
|
+
mock_spinner_cls.return_value = MagicMock()
|
|
168
|
+
with patch("lemonpie.main.stream_chat") as mock_stream:
|
|
169
|
+
mock_stream.return_value = iter(["got response"])
|
|
170
|
+
# No exception should be raised
|
|
171
|
+
main()
|
|
172
|
+
|
|
173
|
+
# Verify that stream_chat was called
|
|
174
|
+
assert mock_stream.called
|
|
175
|
+
|
|
176
|
+
# Verify it received a properly-structured payload
|
|
177
|
+
_, payload = mock_stream.call_args.args
|
|
178
|
+
assert isinstance(payload, dict)
|
|
179
|
+
assert "messages" in payload
|
|
180
|
+
assert payload["stream"] is True
|
|
181
|
+
|
|
182
|
+
# The user message should be in the payload
|
|
183
|
+
messages = payload["messages"]
|
|
184
|
+
user_contents = [m["content"] for m in messages if m["role"] == "user"]
|
|
185
|
+
assert "test prompt" in user_contents
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# ---------------------------------------------------------------------------
|
|
189
|
+
# --dry-run intercepts for write/delete operations
|
|
190
|
+
# ---------------------------------------------------------------------------
|
|
191
|
+
|
|
192
|
+
class TestDryRunIntercepts:
|
|
193
|
+
def test_delete_prints_message_and_exits_zero(self, write_cfg, capsys):
|
|
194
|
+
with patch("lemonpie.main.build_parser") as mock_parser_cls:
|
|
195
|
+
mock_parser_cls.return_value.parse_args.return_value = _mock_args(
|
|
196
|
+
dry_run=True, delete="abc123"
|
|
197
|
+
)
|
|
198
|
+
with pytest.raises(SystemExit) as exc:
|
|
199
|
+
main()
|
|
200
|
+
assert exc.value.code == 0
|
|
201
|
+
assert "Would delete session abc123." in capsys.readouterr().out
|
|
202
|
+
|
|
203
|
+
def test_delete_all_prints_message_and_exits_zero(self, write_cfg, capsys):
|
|
204
|
+
with patch("lemonpie.main.build_parser") as mock_parser_cls:
|
|
205
|
+
mock_parser_cls.return_value.parse_args.return_value = _mock_args(
|
|
206
|
+
dry_run=True, delete_all=True
|
|
207
|
+
)
|
|
208
|
+
with pytest.raises(SystemExit) as exc:
|
|
209
|
+
main()
|
|
210
|
+
assert exc.value.code == 0
|
|
211
|
+
assert "Would delete all sessions." in capsys.readouterr().out
|
|
212
|
+
|
|
213
|
+
def test_close_prints_message_and_exits_zero(self, write_cfg, capsys):
|
|
214
|
+
with patch("lemonpie.main.build_parser") as mock_parser_cls:
|
|
215
|
+
mock_parser_cls.return_value.parse_args.return_value = _mock_args(
|
|
216
|
+
dry_run=True, close=True
|
|
217
|
+
)
|
|
218
|
+
with pytest.raises(SystemExit) as exc:
|
|
219
|
+
main()
|
|
220
|
+
assert exc.value.code == 0
|
|
221
|
+
assert "Would close the current session." in capsys.readouterr().out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|