lcode-cli 0.25.0__tar.gz → 0.27.0__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.
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/CHANGELOG.md +38 -1
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/PKG-INFO +1 -1
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/automation.md +2 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/bench.md +12 -1
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/configuration.md +2 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/how-it-works.md +17 -6
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/quickstart.md +1 -1
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/usage.md +33 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/__init__.py +1 -1
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/action.py +8 -1
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/agent.py +38 -7
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/api.py +2 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/cli.py +15 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/config.py +17 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/context.py +81 -4
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/gitflow.py +15 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/repl.py +2 -1
- lcode_cli-0.27.0/src/lcode/secretscan.py +315 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/tools.py +25 -2
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/conftest.py +40 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_context.py +86 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_gitflow.py +1 -40
- lcode_cli-0.27.0/tests/test_secretscan.py +163 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.editorconfig +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/CODEOWNERS +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/ISSUE_TEMPLATE/model_request.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/dependabot.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/workflows/ci.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/workflows/docs.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.github/workflows/release.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.gitignore +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/.pre-commit-config.yaml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/AGENTS.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/CODE_OF_CONDUCT.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/CONTRIBUTING.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/LICENSE +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/README.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/SECURITY.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/action.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/agents.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/assets/demo.svg +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/assets/extra.css +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/assets/logo.svg +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/assets/social-preview.png +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/changelog.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/commands.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/contributing.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/editors.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/git.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/hooks.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/index.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/installation.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/lsp.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/mcp.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/memory.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/models.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/sandbox.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/search.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/servers.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/docs/troubleshooting.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/examples/README.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/examples/api/fix_tests.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/examples/commands/review.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/examples/skills/commit-message/SKILL.md +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/examples/skills/commit-message/scripts/staged.sh +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/install.sh +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/mkdocs.yml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/overrides/main.html +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/pyproject.toml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/scripts/record_demo.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/scripts/social-preview.html +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/__main__.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/acp.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/backends.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/bench.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/bench_backend.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/bench_runtime.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/catalog.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/checkpoints.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/clipboard.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/codesearch.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/extensions.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/frontmatter.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/hardware.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/hooks.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/jobs.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/limits.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/lsp.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/__init__.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/auth.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/catalog.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/catalog.toml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/client.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/commands.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/config.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/http.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/manager.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/protocol.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/server.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/mcp/stdio.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/memory.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/models.toml +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/notify.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/ollama.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/permissions.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/planning.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/render.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/repeats.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/repomap.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/sandbox.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/servers/__init__.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/servers/encord.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/servers/valohai.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/servers/xai.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/sessions.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/subagents.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/update.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/vision.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/src/lcode/web.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/fake_lsp_server.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/fake_mcp_server.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_acp.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_action.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_agent.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_api.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_backends.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_bench.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_catalog.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_checkpoints.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_cli.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_clipboard.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_codesearch.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_config.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_context_picker.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_extensions.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_hooks.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_jobs.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_lsp.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_mcp.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_memory.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_permissions.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_plan_mode.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_repeats.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_repomap.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_sandbox.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_servers.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_sessions.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_subagents.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_tools.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_update.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_vision.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_web.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/tests/test_xai.py +0 -0
- {lcode_cli-0.25.0 → lcode_cli-0.27.0}/uv.lock +0 -0
|
@@ -6,6 +6,41 @@ All notable changes to lcode are documented here. The format follows
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.27.0] - 2026-10-10
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Long sessions are summarized earlier: once the conversation reaches 64K tokens (`compact_at`),
|
|
14
|
+
even when the window is larger. Before, a 256K window was summarized only at about 220K, far past
|
|
15
|
+
where small models work well. lcode still removes old tool output first, and summarizes only if
|
|
16
|
+
that's not enough. `lcode config set compact_at 0` keeps only the 85% rule, and
|
|
17
|
+
`lcode bench --compact-at` compares ceilings. Measured with qwen3.6-35b: making room earlier
|
|
18
|
+
doesn't cost tasks (21 of 24 either way) and saved 17% of the time. See
|
|
19
|
+
[Context management](https://nasser1941.github.io/lcode/how-it-works/#context-management).
|
|
20
|
+
- Summaries keep your latest requests (up to eight) word for word, so the goal survives the
|
|
21
|
+
retelling. `/context` shows where the session makes room.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- After lcode removed an earlier file read to make room, the model sometimes answered questions
|
|
26
|
+
about that file from memory, and got them wrong, instead of reading it again. The files whose
|
|
27
|
+
only copy went are now named next to the request it's working on, and the note in their place
|
|
28
|
+
says plainly that the content is gone. A conversation that was just summarized isn't summarized
|
|
29
|
+
again until it has grown by a quarter of `compact_at`, which must be at least 16K (or 0).
|
|
30
|
+
|
|
31
|
+
## [0.26.0] - 2026-10-10
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- lcode checks for secrets before the model runs `git commit` or `git push`: passwords, keys and
|
|
36
|
+
tokens in code or configuration, credentials in URLs (`rtsp://user:pass@…`), private keys,
|
|
37
|
+
tokens with a known form, and `.env` files, in the lines a commit adds or the commits a push
|
|
38
|
+
sends. In `ask` mode you decide; in `auto-edit` and `yolo` the command doesn't run, and the model
|
|
39
|
+
is told to move the secret out of the code. `/commit` and `/pr` show the findings before you
|
|
40
|
+
confirm, and the GitHub Action doesn't commit at all. `lcode: allow-secret` in a comment allows a
|
|
41
|
+
line; `secret_check = false` turns the check off. See
|
|
42
|
+
[Secrets in commits](https://nasser1941.github.io/lcode/usage/#secrets-in-commits).
|
|
43
|
+
|
|
9
44
|
## [0.25.0] - 2026-10-10
|
|
10
45
|
|
|
11
46
|
### Changed
|
|
@@ -540,7 +575,9 @@ First public release.
|
|
|
540
575
|
- `AGENTS.md` project instructions and `/init` to generate them.
|
|
541
576
|
- One-line installer for Linux and macOS.
|
|
542
577
|
|
|
543
|
-
[Unreleased]: https://github.com/nasser1941/lcode/compare/v0.
|
|
578
|
+
[Unreleased]: https://github.com/nasser1941/lcode/compare/v0.27.0...HEAD
|
|
579
|
+
[0.27.0]: https://github.com/nasser1941/lcode/compare/v0.26.0...v0.27.0
|
|
580
|
+
[0.26.0]: https://github.com/nasser1941/lcode/compare/v0.25.0...v0.26.0
|
|
544
581
|
[0.25.0]: https://github.com/nasser1941/lcode/compare/v0.24.0...v0.25.0
|
|
545
582
|
[0.24.0]: https://github.com/nasser1941/lcode/compare/v0.23.0...v0.24.0
|
|
546
583
|
[0.23.0]: https://github.com/nasser1941/lcode/compare/v0.22.0...v0.23.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: lcode-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.27.0
|
|
4
4
|
Summary: A local-first terminal coding agent powered by open-weight models on your own GPU or Mac, via Ollama.
|
|
5
5
|
Project-URL: Homepage, https://nasser1941.github.io/lcode/
|
|
6
6
|
Project-URL: Documentation, https://nasser1941.github.io/lcode/
|
|
@@ -90,6 +90,8 @@ with Session("path/to/repo", permission_mode="auto-edit") as session:
|
|
|
90
90
|
- **Events while it runs:** `session.stream(prompt)` yields the events above, ending with the result.
|
|
91
91
|
- **Permissions:** pass `approve` to decide permission requests. It gets
|
|
92
92
|
`{"kind": "bash", "title": "…", "target": "pytest -q"}`; without it, every request is refused.
|
|
93
|
+
A `git commit` or `git push` that would add [what looks like a secret](usage.md#secrets-in-commits)
|
|
94
|
+
comes as `{"kind": "secret", …}` in `ask` mode, and doesn't run in the other modes.
|
|
93
95
|
- **Options:** `model`, `context`, `permission_mode`, `allowed_tools`, `max_steps`, `think`,
|
|
94
96
|
`web`, `memory`, `mcp` and `sandbox`. Leave one out to use your
|
|
95
97
|
[configuration](configuration.md).
|
|
@@ -51,7 +51,7 @@ Each task normally starts a new conversation. `--session` runs them all in **one
|
|
|
51
51
|
instead, as a long working session would, so the context fills up and lcode's
|
|
52
52
|
[context management](how-it-works.md#context-management) has to work: the summary shows how often
|
|
53
53
|
it removed old tool output and how often it summarized the conversation. `--no-prune` turns the
|
|
54
|
-
removal off, to compare.
|
|
54
|
+
removal off, to compare, and `--compact-at` sets the ceiling (`--compact-at 0`: only at 85%).
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
57
|
lcode bench --context 32k --session --rounds 3
|
|
@@ -74,6 +74,17 @@ at no measurable cost in tasks solved or time. The bench tasks are independent o
|
|
|
74
74
|
which is where summaries hurt least; in a real session, where later requests build on earlier
|
|
75
75
|
ones, keeping the conversation intact matters more.
|
|
76
76
|
|
|
77
|
+
With a large window, `compact_at` decides when lcode makes room. In a 128K window, 24 tasks in one
|
|
78
|
+
conversation reach about 40K tokens, so the default ceiling of 64K never comes into play. Making
|
|
79
|
+
room earlier than needed doesn't cost tasks:
|
|
80
|
+
|
|
81
|
+
| 128K window, 24 tasks | No room made (peak ~40K) | `--compact-at 32k` |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| Conversation summarized | 0 times | 1 time (old tool output removed once) |
|
|
84
|
+
| Tasks solved | 21 of 24 | 21 of 24 |
|
|
85
|
+
| Time | 33 min | 27.5 min |
|
|
86
|
+
| Average prompt | 22.9K tokens | 16.6K tokens |
|
|
87
|
+
|
|
77
88
|
## The tasks
|
|
78
89
|
|
|
79
90
|
Every task runs in a new temporary folder, with every permission granted (`yolo` mode) and web
|
|
@@ -37,12 +37,14 @@ lcode config path # print the file location
|
|
|
37
37
|
| `repo_map` | `true` | Give the model a ranked [map of the repository](search.md) |
|
|
38
38
|
| `embed_model` | `auto` | Embedding model for [semantic code search](search.md#semantic-code-search): `auto`, `off` or a model name |
|
|
39
39
|
| `lsp` | `auto` | Use installed [language servers](lsp.md) for code navigation and errors after edits: `auto` or `off` |
|
|
40
|
+
| `compact_at` | `65536` | Make room (prune, then summarize) once the conversation reaches this many tokens, even in a larger window (at least 16K); `0` leaves only the 85% rule ([why](how-it-works.md#context-management)) |
|
|
40
41
|
| `prune` | `true` | When the context is 85% full, first remove old tool output, and summarize the conversation only if that's not enough ([how](how-it-works.md#context-management)) |
|
|
41
42
|
| `subagents` | `true` | Let the model hand tasks to [subagents](agents.md) with their own context |
|
|
42
43
|
| `max_parallel_agents` | `1` | Subagents that run at the same time; more needs `OLLAMA_NUM_PARALLEL` on the Ollama server ([details](agents.md#several-at-once)) |
|
|
43
44
|
| `notify` | `true` | A desktop [notification](usage.md#notifications) when a long request is done or waits for your answer |
|
|
44
45
|
| `notify_after` | `30` | Seconds a request runs before it notifies |
|
|
45
46
|
| `repeat_limit` | `3` | Identical tool calls with identical results before lcode [steps in](how-it-works.md#when-the-model-repeats-itself); `0` turns it off |
|
|
47
|
+
| `secret_check` | `true` | Before `git commit` and `git push`, look for passwords, keys and tokens they'd add ([details](usage.md#secrets-in-commits)) |
|
|
46
48
|
| `checkpoints` | `true` | Save a checkpoint before the model changes files, so [`/undo`](usage.md#undo-and-checkpoints) can restore them |
|
|
47
49
|
|
|
48
50
|
Besides these settings, `config.toml` can hold [hooks](hooks.md) (`[[hooks]]`) and
|
|
@@ -73,21 +73,32 @@ in a temporary git worktree, and their changes come back as a diff.
|
|
|
73
73
|
## Context management
|
|
74
74
|
|
|
75
75
|
Ollama keeps the processed conversation in its KV cache, so each turn only processes the new tokens.
|
|
76
|
-
lcode tracks how full the window is from Ollama's token counts.
|
|
77
|
-
|
|
76
|
+
lcode tracks how full the window is from Ollama's token counts. It makes room when the window is
|
|
77
|
+
85% full, or when the conversation reaches 64K tokens (`compact_at`), whichever comes first.
|
|
78
|
+
Small models lose track in long contexts well before a large window is full: in one long session,
|
|
79
|
+
Qwen3.6 35B started repeating itself and overlooking what it had read once the conversation passed
|
|
80
|
+
about 75K tokens. Most of a long session's
|
|
81
|
+
context is old tool output, so:
|
|
78
82
|
|
|
79
83
|
1. **lcode removes old tool output first.** File contents, command output and search results from
|
|
80
84
|
before your last two requests become one-line notes that say what was there, such as
|
|
81
|
-
`[lcode: read src/app.py earlier;
|
|
85
|
+
`[lcode: read src/app.py earlier; its content was removed …. Read it again before answering anything about it.]`.
|
|
82
86
|
An earlier copy of a file that was read again later goes too, even in recent requests. Subagent
|
|
83
|
-
reports, skill instructions and the approved plan stay.
|
|
84
|
-
|
|
87
|
+
reports, skill instructions and the approved plan stay. The files whose only copy went are also
|
|
88
|
+
named next to the request the model is working on, since models tend to overlook a note deep in
|
|
89
|
+
the conversation and answer from memory instead of reading the file again.
|
|
90
|
+
2. **If that brings the conversation well under the limit** (70% of the window, or about 53K
|
|
91
|
+
tokens with `compact_at`), the work simply continues: nothing is summarized,
|
|
85
92
|
and the conversation itself stays word for word.
|
|
86
93
|
If it's not, lcode also removes the tool output of your previous request, keeping only the
|
|
87
94
|
latest one's. (`lcode config set prune false` skips this step.)
|
|
88
95
|
3. **Otherwise lcode summarizes.** It asks whether anything is worth [remembering](memory.md), since
|
|
89
96
|
the summary leaves details out, then has the model write a summary of the conversation (goals,
|
|
90
|
-
findings, files changed, next steps) and continues from it.
|
|
97
|
+
findings, files changed, next steps) and continues from it. Your latest requests (up to eight)
|
|
98
|
+
are kept word for word under the summary, so the goal isn't lost in the retelling.
|
|
99
|
+
|
|
100
|
+
`lcode config set compact_at 128k` moves the ceiling, and `0` turns it off, leaving only the 85%
|
|
101
|
+
rule. `/context` shows where the current session makes room.
|
|
91
102
|
|
|
92
103
|
Long tool output (over 30,000 characters) keeps its beginning, its end and the lines in between
|
|
93
104
|
that look like errors. The full output is saved under `~/.local/state/lcode/outputs/` (for a week)
|
|
@@ -213,6 +213,39 @@ deny lists, per user or per repository; deny always wins, even in `yolo`. Text a
|
|
|
213
213
|
With the [sandbox](sandbox.md) on, `auto-edit` mode runs shell commands without asking too: they can
|
|
214
214
|
only reach the project, and `/undo` can take their changes back.
|
|
215
215
|
|
|
216
|
+
### Secrets in commits
|
|
217
|
+
|
|
218
|
+
Before the model runs `git commit` or `git push`, lcode checks what would go into the repository's
|
|
219
|
+
history: the lines a commit adds (including files a `git add` in the same command stages), or every
|
|
220
|
+
commit a push would send. It looks for:
|
|
221
|
+
|
|
222
|
+
- passwords, keys and tokens written as values in code or configuration, like
|
|
223
|
+
`"password": "…"` or `API_KEY=…`;
|
|
224
|
+
- credentials in addresses, like `rtsp://admin:…@192.168.1.10`;
|
|
225
|
+
- private keys and tokens with a known form (GitHub, GitLab, AWS, Slack, OpenAI, Anthropic, xAI,
|
|
226
|
+
Google, Hugging Face, Stripe);
|
|
227
|
+
- `.env` files.
|
|
228
|
+
|
|
229
|
+
Placeholders such as `CHANGE_ME`, `your_password`, `${PASSWORD}` or `os.environ["PASSWORD"]` don't
|
|
230
|
+
count.
|
|
231
|
+
|
|
232
|
+
```text
|
|
233
|
+
This commit would add what looks like a secret to the repository's history:
|
|
234
|
+
- camera_wall.py:42: a password or key: "password": "Xk…"
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- **In `ask` mode,** you decide: lcode shows the findings and the command.
|
|
238
|
+
- **In `auto-edit` and `yolo`,** the command doesn't run. The model is told to read the secret from
|
|
239
|
+
an environment variable or a configuration file that git ignores, and to ask you if it isn't one.
|
|
240
|
+
- **`/commit` and `/pr`** show the same findings before you confirm.
|
|
241
|
+
- **The [GitHub Action](automation.md#github-action)** doesn't commit or push at all when it finds
|
|
242
|
+
one.
|
|
243
|
+
|
|
244
|
+
If a line only looks like a secret, add `lcode: allow-secret` (or `gitleaks:allow`) in a comment
|
|
245
|
+
on it. `lcode config set secret_check false` turns the check off. It's a safety net, not a full
|
|
246
|
+
scanner: for a public repository, also run a tool such as [gitleaks](https://github.com/gitleaks/gitleaks)
|
|
247
|
+
before you push.
|
|
248
|
+
|
|
216
249
|
## Plan mode
|
|
217
250
|
|
|
218
251
|
Local models are slower than cloud models and make more mistakes, so on a bigger change it pays to
|
|
@@ -302,7 +302,14 @@ def answer(hub: GitHub, task: Task, inputs: Inputs, cwd: Path) -> None:
|
|
|
302
302
|
reply = result.text.strip() or "(no answer)"
|
|
303
303
|
changed = git(cwd, "status", "--porcelain").strip()
|
|
304
304
|
if changed:
|
|
305
|
-
from lcode import gitflow
|
|
305
|
+
from lcode import gitflow, secretscan
|
|
306
|
+
|
|
307
|
+
found = secretscan.in_files(cwd, ["."], staged=False)
|
|
308
|
+
if found:
|
|
309
|
+
raise ActionError(
|
|
310
|
+
secretscan.report("commit", found, excerpts=False) + "\n\nSo lcode didn't commit or push its "
|
|
311
|
+
"changes. Secrets belong in the repository's secrets or in configuration that git ignores."
|
|
312
|
+
)
|
|
306
313
|
|
|
307
314
|
data = gitflow.ask(
|
|
308
315
|
session.agent,
|
|
@@ -233,6 +233,8 @@ class Settings:
|
|
|
233
233
|
notify: bool = False # desktop notifications after long requests (lcode.notify)
|
|
234
234
|
notify_after: int = 30 # seconds: a request this long notifies when it's done or waits for an answer
|
|
235
235
|
max_parallel_agents: int = 1
|
|
236
|
+
secret_check: bool = True # scan what git commit and git push would add (lcode.secretscan)
|
|
237
|
+
compact_at: int = 0 # tokens: make room at this size even when the window is larger (0: only at 85%)
|
|
236
238
|
repeat_limit: int = 3 # identical calls with identical results before the model is told (lcode.repeats)
|
|
237
239
|
|
|
238
240
|
|
|
@@ -269,6 +271,7 @@ class Agent:
|
|
|
269
271
|
self.agent_runs: list[subagents.Record] = [] # subagents run in this session, for /agents
|
|
270
272
|
self.plan = "" # the plan the user approved; kept through compaction
|
|
271
273
|
self.pruned = self.compacted = 0 # how often the context was pruned or summarized automatically
|
|
274
|
+
self.summarized_size = 0 # tokens right after the last summary (0: none in this conversation)
|
|
272
275
|
self._extensions: tuple[Path, extensions.Extensions] | None = None
|
|
273
276
|
self.skills_loaded: set[str] = set() # skills whose instructions are in the conversation
|
|
274
277
|
# Set on subagents (see lcode.subagents):
|
|
@@ -513,6 +516,7 @@ class Agent:
|
|
|
513
516
|
return WEB_PROMPT.format(tools=tools, date=dt.date.today().isoformat())
|
|
514
517
|
|
|
515
518
|
def reset(self) -> None:
|
|
519
|
+
self.summarized_size = 0
|
|
516
520
|
self.messages = [{"role": "system", "content": self.system_prompt()}]
|
|
517
521
|
self._mcp_prompt = ""
|
|
518
522
|
self.tools.read_mtimes.clear()
|
|
@@ -1045,13 +1049,27 @@ class Agent:
|
|
|
1045
1049
|
return text + ("\n\n" + "\n\n".join(attached) if attached else "")
|
|
1046
1050
|
|
|
1047
1051
|
# -- context management
|
|
1052
|
+
def compact_limit(self) -> int:
|
|
1053
|
+
"""The tokens in use at which lcode makes room: 85% of the window, or `compact_at` when that's lower.
|
|
1054
|
+
Small models lose track in long contexts well before a large window is full."""
|
|
1055
|
+
limit = int(AUTO_COMPACT_RATIO * self.settings.context)
|
|
1056
|
+
if self.settings.compact_at > 0:
|
|
1057
|
+
limit = min(limit, self.settings.compact_at)
|
|
1058
|
+
return limit
|
|
1059
|
+
|
|
1048
1060
|
def maybe_compact(self) -> None:
|
|
1049
|
-
|
|
1061
|
+
limit = self.compact_limit()
|
|
1062
|
+
if self.ctx_used <= limit:
|
|
1050
1063
|
return
|
|
1064
|
+
enough = int(limit * PRUNED_ENOUGH / AUTO_COMPACT_RATIO) # after pruning, a summary isn't needed below this
|
|
1051
1065
|
if self.settings.prune:
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1066
|
+
removed: list[str] = [] # files and pages whose only copy goes
|
|
1067
|
+
saved = context_tools.prune(self.messages, removed=removed) # tool output from before the last two requests
|
|
1068
|
+
if self.ctx_used - saved // 3 > enough:
|
|
1069
|
+
saved += context_tools.prune(
|
|
1070
|
+
self.messages, keep=1, removed=removed
|
|
1071
|
+
) # not enough: before the last request
|
|
1072
|
+
context_tools.note_removed(self.messages, removed)
|
|
1055
1073
|
if saved:
|
|
1056
1074
|
self.pruned += 1
|
|
1057
1075
|
self.ctx_used = max(len(self.messages[0]["content"]) // 3, self.ctx_used - saved // 3)
|
|
@@ -1059,9 +1077,17 @@ class Agent:
|
|
|
1059
1077
|
f"[dim]Removed old tool output from the conversation (~{format_tokens(saved // 3)} tokens) to "
|
|
1060
1078
|
"make room.[/]"
|
|
1061
1079
|
)
|
|
1062
|
-
if self.ctx_used <=
|
|
1080
|
+
if self.ctx_used <= enough:
|
|
1063
1081
|
return
|
|
1064
|
-
self.
|
|
1082
|
+
window_full = self.ctx_used > AUTO_COMPACT_RATIO * self.settings.context
|
|
1083
|
+
if not window_full and self.summarized_size and self.ctx_used - self.summarized_size < limit // 4:
|
|
1084
|
+
return # summarized not long ago: summarizing again so soon would only lose more
|
|
1085
|
+
if limit < AUTO_COMPACT_RATIO * self.settings.context:
|
|
1086
|
+
self.console.print(
|
|
1087
|
+
f"[yellow]The conversation reached {format_tokens(limit)} tokens (compact_at) — summarizing it…[/]"
|
|
1088
|
+
)
|
|
1089
|
+
else:
|
|
1090
|
+
self.console.print("[yellow]Context is nearly full — compacting the conversation…[/]")
|
|
1065
1091
|
self.compacted += 1
|
|
1066
1092
|
self.compact()
|
|
1067
1093
|
|
|
@@ -1082,9 +1108,13 @@ class Agent:
|
|
|
1082
1108
|
with self.console.status("[cyan]Compacting…[/]"):
|
|
1083
1109
|
for chunk in self.chat([*self.messages, {"role": "user", "content": instructions}], None, False):
|
|
1084
1110
|
summary += chunk.get("message", {}).get("content", "")
|
|
1111
|
+
requests = context_tools.user_requests(self.messages)
|
|
1085
1112
|
self.messages = [
|
|
1086
1113
|
{"role": "system", "content": self.system_prompt()},
|
|
1087
|
-
{
|
|
1114
|
+
{
|
|
1115
|
+
"role": "user",
|
|
1116
|
+
"content": f"{sessions.SUMMARY_PREFIX}\n\n{summary}" + context_tools.requests_block(requests),
|
|
1117
|
+
},
|
|
1088
1118
|
{"role": "assistant", "content": "Got it — I have the context from the summary and will continue."},
|
|
1089
1119
|
]
|
|
1090
1120
|
if self.plan: # the approved plan stays word for word
|
|
@@ -1096,6 +1126,7 @@ class Agent:
|
|
|
1096
1126
|
)
|
|
1097
1127
|
self.skills_loaded.clear()
|
|
1098
1128
|
self.ctx_used = sum(len(m["content"]) for m in self.messages) // 3
|
|
1129
|
+
self.summarized_size = self.ctx_used
|
|
1099
1130
|
self.reflected = len(self.messages)
|
|
1100
1131
|
self.console.print(Panel(Markdown(summary), title="Compacted summary", border_style="blue"))
|
|
1101
1132
|
|
|
@@ -194,7 +194,9 @@ def open_agent(cwd: Path, options: Options, console: Console, hw: Hardware | Non
|
|
|
194
194
|
embed_model=cfg["embed_model"],
|
|
195
195
|
notify=cfg["notify"],
|
|
196
196
|
notify_after=cfg["notify_after"],
|
|
197
|
+
secret_check=cfg["secret_check"],
|
|
197
198
|
repeat_limit=cfg["repeat_limit"],
|
|
199
|
+
compact_at=cfg["compact_at"],
|
|
198
200
|
)
|
|
199
201
|
agent = Agent(ollama, settings, cwd, console=console)
|
|
200
202
|
agent.interactive = options.interactive
|
|
@@ -579,6 +579,7 @@ def cmd_bench(args) -> None:
|
|
|
579
579
|
web="off",
|
|
580
580
|
checkpoints=False,
|
|
581
581
|
prune=not args.no_prune,
|
|
582
|
+
compact_at=cfg["compact_at"] if args.compact_at is None else args.compact_at,
|
|
582
583
|
repo_map=args.repo_map,
|
|
583
584
|
embed_model=cfg["embed_model"] if args.code_search else "off",
|
|
584
585
|
)
|
|
@@ -678,6 +679,14 @@ def cmd_chat(args) -> None:
|
|
|
678
679
|
sys.exit(exit_code)
|
|
679
680
|
|
|
680
681
|
|
|
682
|
+
def compact_tokens(value: str) -> int:
|
|
683
|
+
"""`--compact-at`: a token count such as 64k, or 0."""
|
|
684
|
+
try:
|
|
685
|
+
return config.parse_compact_at(value)
|
|
686
|
+
except ConfigError as e:
|
|
687
|
+
raise argparse.ArgumentTypeError(str(e)) from e
|
|
688
|
+
|
|
689
|
+
|
|
681
690
|
def build_parser() -> argparse.ArgumentParser:
|
|
682
691
|
parser = argparse.ArgumentParser(
|
|
683
692
|
prog="lcode",
|
|
@@ -765,6 +774,12 @@ def build_subparsers() -> dict[str, argparse.ArgumentParser]:
|
|
|
765
774
|
p.add_argument("--repo-map", action="store_true", help="give the model the repository map (off by default)")
|
|
766
775
|
p.add_argument("--code-search", action="store_true", help="index each task's folder and offer semantic code search")
|
|
767
776
|
p.add_argument("--no-prune", action="store_true", help="don't remove old tool output (to compare, with --session)")
|
|
777
|
+
p.add_argument(
|
|
778
|
+
"--compact-at",
|
|
779
|
+
type=compact_tokens,
|
|
780
|
+
metavar="TOKENS",
|
|
781
|
+
help="summarize at this many tokens, e.g. 64k (default: the compact_at setting; 0: only at 85%%)",
|
|
782
|
+
)
|
|
768
783
|
subs["bench"] = p
|
|
769
784
|
p = argparse.ArgumentParser(
|
|
770
785
|
prog="lcode index",
|
|
@@ -60,6 +60,8 @@ SETTINGS: dict[str, tuple[object, type, str]] = {
|
|
|
60
60
|
"notify": (True, bool, "desktop notification when a long request is done or waits for you"),
|
|
61
61
|
"notify_after": (30, int, "seconds a request runs before it notifies (with notify on)"),
|
|
62
62
|
"repeat_limit": (3, int, "identical tool calls with identical results before lcode steps in (0: never)"),
|
|
63
|
+
"secret_check": (True, bool, "before git commit and git push, look for passwords, keys and tokens they'd add"),
|
|
64
|
+
"compact_at": (65536, int, "summarize at this many tokens even when the window is larger (0: only at 85%)"),
|
|
63
65
|
"max_parallel_agents": (1, int, "subagents that may run at the same time (more needs OLLAMA_NUM_PARALLEL)"),
|
|
64
66
|
}
|
|
65
67
|
ENV_OVERRIDES = {
|
|
@@ -80,6 +82,19 @@ class ConfigError(ValueError):
|
|
|
80
82
|
pass
|
|
81
83
|
|
|
82
84
|
|
|
85
|
+
MIN_COMPACT_AT = 16384 # below this, the system prompt and a summary alone come close to the ceiling
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def parse_compact_at(value: str | int) -> int:
|
|
89
|
+
"""compact_at: a token count like parse_context's, at least 16K, or 0 (off)."""
|
|
90
|
+
if str(value).strip().lower() in ("0", "off", "false", "none"):
|
|
91
|
+
return 0
|
|
92
|
+
tokens = parse_context(value)
|
|
93
|
+
if tokens < MIN_COMPACT_AT:
|
|
94
|
+
raise ConfigError(f"compact_at {tokens} is too small: use at least 16k, or 0 to turn it off")
|
|
95
|
+
return tokens
|
|
96
|
+
|
|
97
|
+
|
|
83
98
|
def parse_context(value: str | int) -> int:
|
|
84
99
|
"""Parse '131072', '128k', '128K' or '1m' into a token count (k = 1024)."""
|
|
85
100
|
if isinstance(value, int):
|
|
@@ -117,6 +132,8 @@ def coerce(key: str, value: object) -> object:
|
|
|
117
132
|
_, typ, _ = SETTINGS[key]
|
|
118
133
|
if key == "context":
|
|
119
134
|
return parse_context(value) # type: ignore[arg-type]
|
|
135
|
+
if key == "compact_at":
|
|
136
|
+
return parse_compact_at(value) # type: ignore[arg-type]
|
|
120
137
|
if key in ("ollama_host", "searxng_url"):
|
|
121
138
|
return normalize_host(str(value))
|
|
122
139
|
if key == "base_url":
|
|
@@ -29,6 +29,10 @@ if TYPE_CHECKING:
|
|
|
29
29
|
KEEP_RECENT_REQUESTS = 2 # tool results of the last requests stay as they are
|
|
30
30
|
MIN_PRUNE_CHARS = 400 # shorter results aren't worth replacing
|
|
31
31
|
PRUNED = "[lcode: " # how stubs start, so they're never pruned twice
|
|
32
|
+
GONE = ( # a removed file read: firm, because models answer from the stub instead of reading it again
|
|
33
|
+
"earlier; its content was removed to save context and isn't in this conversation any more. Read it again "
|
|
34
|
+
"before answering anything about it.]"
|
|
35
|
+
)
|
|
32
36
|
KEEP_TOOLS = {"agent", "skill", "memory", "todo_write", "present_plan"} # short, or still guiding the work
|
|
33
37
|
ERROR_LINE = re.compile(
|
|
34
38
|
r"error|exception|traceback|failed|failure|fatal|panic|assert|denied|not found|cannot|can't|undefined", re.I
|
|
@@ -37,6 +41,56 @@ MAX_ERROR_LINES = 40
|
|
|
37
41
|
OUTPUT_DAYS = 7 # saved full outputs are deleted after this
|
|
38
42
|
|
|
39
43
|
|
|
44
|
+
# ----------------------------------------------------------------------------- the user's requests
|
|
45
|
+
|
|
46
|
+
REQUESTS_HEADER = "[The user's requests in this conversation, word for word, oldest first]"
|
|
47
|
+
MAX_REQUESTS = 8 # the most recent ones are kept through a summary
|
|
48
|
+
MAX_REQUEST_CHARS = 1500
|
|
49
|
+
# What lcode appends to the user's words: attached files, images and folders, and its own notes.
|
|
50
|
+
ATTACHED = re.compile(r"\n\n(?:<file path=|<image path=|<directory path=|\[lcode[:\]] |\[The user wants the )")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def request_text(content: str) -> str:
|
|
54
|
+
"""The user's own words in a message, without what lcode attached to it."""
|
|
55
|
+
cut = ATTACHED.search(content)
|
|
56
|
+
return (content[: cut.start()] if cut else content).strip()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def user_requests(messages: list[dict]) -> list[str]:
|
|
60
|
+
"""What the user asked in the conversation, oldest first, including the requests an earlier summary kept."""
|
|
61
|
+
requests: list[str] = []
|
|
62
|
+
for message in messages:
|
|
63
|
+
content = message.get("content") or ""
|
|
64
|
+
if message.get("role") != "user":
|
|
65
|
+
continue
|
|
66
|
+
if content.startswith(SUMMARY_PREFIX):
|
|
67
|
+
start = content.find(REQUESTS_HEADER)
|
|
68
|
+
if start >= 0:
|
|
69
|
+
rest = content[start + len(REQUESTS_HEADER) :]
|
|
70
|
+
try:
|
|
71
|
+
kept, _ = json.JSONDecoder().raw_decode(rest[rest.index("[") :])
|
|
72
|
+
requests += [str(r) for r in kept]
|
|
73
|
+
except ValueError:
|
|
74
|
+
pass
|
|
75
|
+
continue
|
|
76
|
+
if content.startswith("[lcode]"):
|
|
77
|
+
continue # lcode's own nudges
|
|
78
|
+
text = request_text(content)
|
|
79
|
+
if text:
|
|
80
|
+
requests.append(text)
|
|
81
|
+
return requests
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def requests_block(requests: list[str]) -> str:
|
|
85
|
+
"""The user's latest requests, word for word, to keep the goal through a summary."""
|
|
86
|
+
if not requests:
|
|
87
|
+
return ""
|
|
88
|
+
kept = [r if len(r) <= MAX_REQUEST_CHARS else f"{r[: MAX_REQUEST_CHARS - 200]} […] {r[-150:]}" for r in requests]
|
|
89
|
+
older = len(kept) - MAX_REQUESTS
|
|
90
|
+
note = f" (and {older} earlier, in the summary)" if older > 0 else ""
|
|
91
|
+
return f"\n\n{REQUESTS_HEADER}{note}\n{json.dumps(kept[-MAX_REQUESTS:], ensure_ascii=False, indent=1)}"
|
|
92
|
+
|
|
93
|
+
|
|
40
94
|
# ----------------------------------------------------------------------------- pruning
|
|
41
95
|
|
|
42
96
|
|
|
@@ -63,7 +117,7 @@ def stub(name: str, args: dict, content: str) -> str:
|
|
|
63
117
|
if args.get("offset") or args.get("limit"):
|
|
64
118
|
start = int(args.get("offset") or 1)
|
|
65
119
|
span = f" from line {start}"
|
|
66
|
-
return f"{PRUNED}read {args.get('path', 'a file')}{span}
|
|
120
|
+
return f"{PRUNED}read {args.get('path', 'a file')}{span} {GONE}"
|
|
67
121
|
if name == "bash":
|
|
68
122
|
command = " ".join(str(args.get("command", "")).split())
|
|
69
123
|
command = command if len(command) <= 80 else command[:79] + "…"
|
|
@@ -92,8 +146,9 @@ def boundary(messages: list[dict], keep: int = KEEP_RECENT_REQUESTS) -> int:
|
|
|
92
146
|
return requests[-keep] if len(requests) >= keep else 0
|
|
93
147
|
|
|
94
148
|
|
|
95
|
-
def prune(messages: list[dict], keep: int = KEEP_RECENT_REQUESTS) -> int:
|
|
96
|
-
"""Replace stale tool results with stubs, in place. Returns the number of characters saved
|
|
149
|
+
def prune(messages: list[dict], keep: int = KEEP_RECENT_REQUESTS, removed: list[str] | None = None) -> int:
|
|
150
|
+
"""Replace stale tool results with stubs, in place. Returns the number of characters saved; the files and
|
|
151
|
+
pages whose only copy went are added to `removed`."""
|
|
97
152
|
calls = calls_for_results(messages)
|
|
98
153
|
edge = boundary(messages, keep)
|
|
99
154
|
# A read is superseded by a later read of the whole file, or of the same lines: not by a later
|
|
@@ -118,12 +173,34 @@ def prune(messages: list[dict], keep: int = KEEP_RECENT_REQUESTS) -> int:
|
|
|
118
173
|
continue
|
|
119
174
|
new = stub(name, args, content)
|
|
120
175
|
if reread:
|
|
121
|
-
new = new.replace(
|
|
176
|
+
new = new.replace(
|
|
177
|
+
GONE, "earlier (read again later); removed to save context. Read it again if you need it.]"
|
|
178
|
+
)
|
|
179
|
+
elif removed is not None and name in ("read_file", "web_fetch"):
|
|
180
|
+
what = str(args.get("path") or args.get("url") or "")
|
|
181
|
+
if what and what not in removed:
|
|
182
|
+
removed.append(what)
|
|
122
183
|
messages[i]["content"] = new
|
|
123
184
|
saved += len(content) - len(new)
|
|
124
185
|
return saved
|
|
125
186
|
|
|
126
187
|
|
|
188
|
+
def note_removed(messages: list[dict], removed: list[str]) -> None:
|
|
189
|
+
"""Tell the model, next to the request it's working on, which files it no longer has: a stub deep in the
|
|
190
|
+
conversation is easy to overlook, and models then answer from memory instead of reading again."""
|
|
191
|
+
if not removed:
|
|
192
|
+
return
|
|
193
|
+
for message in reversed(messages):
|
|
194
|
+
content = str(message.get("content", ""))
|
|
195
|
+
if message.get("role") == "user" and not content.startswith(("[lcode]", SUMMARY_PREFIX)):
|
|
196
|
+
names = ", ".join(removed[:10]) + (f" and {len(removed) - 10} more" if len(removed) > 10 else "")
|
|
197
|
+
message["content"] = (
|
|
198
|
+
f"{content}\n\n[lcode] To make room, lcode removed what you read earlier from: {names}. It isn't in "
|
|
199
|
+
"this conversation any more: read it again before answering anything about it, don't answer from memory."
|
|
200
|
+
)
|
|
201
|
+
return
|
|
202
|
+
|
|
203
|
+
|
|
127
204
|
# ----------------------------------------------------------------------------- long output
|
|
128
205
|
|
|
129
206
|
|
|
@@ -24,6 +24,7 @@ from typing import TYPE_CHECKING
|
|
|
24
24
|
|
|
25
25
|
from rich.markup import escape
|
|
26
26
|
from rich.panel import Panel
|
|
27
|
+
from rich.text import Text
|
|
27
28
|
|
|
28
29
|
if TYPE_CHECKING:
|
|
29
30
|
from lcode.agent import Agent
|
|
@@ -316,6 +317,9 @@ def commit_command(agent: Agent, hint: str = "") -> None:
|
|
|
316
317
|
chosen = [f for f in answer.get("files") or [] if f in paths]
|
|
317
318
|
files = chosen or paths
|
|
318
319
|
left_out = [p for p in paths if p not in files]
|
|
320
|
+
from lcode import secretscan
|
|
321
|
+
|
|
322
|
+
secrets_found = secretscan.in_files(root, files, bool(staged)) if agent.settings.secret_check else []
|
|
319
323
|
while True:
|
|
320
324
|
c.print(Panel(escape(message), title="Commit message", title_align="left", border_style="cyan"))
|
|
321
325
|
c.print(f" [bold]Files[/] {escape(', '.join(files))}")
|
|
@@ -323,6 +327,9 @@ def commit_command(agent: Agent, hint: str = "") -> None:
|
|
|
323
327
|
c.print(f" [dim]Left out (unrelated, the model thinks): {escape(', '.join(left_out))}[/]")
|
|
324
328
|
if risky:
|
|
325
329
|
c.print(f" [dim]Left out (may hold secrets; stage them yourself if needed): {escape(', '.join(risky))}[/]")
|
|
330
|
+
if secrets_found:
|
|
331
|
+
c.print(Text(secretscan.report("commit", secrets_found), style="red"))
|
|
332
|
+
c.print(" [dim]Commit them only if they aren't secrets; otherwise move them out of the code first.[/]")
|
|
326
333
|
choice = confirm(agent, " [y] commit · [e] edit the message · [n] cancel: ", message)
|
|
327
334
|
if choice == "e":
|
|
328
335
|
from lcode.planning import edit_text
|
|
@@ -552,6 +559,14 @@ def pr_command(agent: Agent, arg: str = "") -> None:
|
|
|
552
559
|
|
|
553
560
|
|
|
554
561
|
def push(agent: Agent, root: Path, remote: str, branch: str) -> bool:
|
|
562
|
+
from lcode import secretscan
|
|
563
|
+
|
|
564
|
+
found = secretscan.outgoing(root, branch) if agent.settings.secret_check else []
|
|
565
|
+
if found:
|
|
566
|
+
agent.console.print(Text(secretscan.report("push", found), style="red"))
|
|
567
|
+
if confirm(agent, " Push anyway? [y]es / [n]o: ") != "y":
|
|
568
|
+
agent.console.print("Not pushed.")
|
|
569
|
+
return False
|
|
555
570
|
try:
|
|
556
571
|
with agent.console.status(f"Pushing {escape(branch)}…", spinner="dots"):
|
|
557
572
|
git(root, "push", "-q", "-u", remote, branch, timeout=300)
|
|
@@ -242,7 +242,8 @@ def context_command(agent: Agent, arg: str, hardware: Hardware) -> None:
|
|
|
242
242
|
c.print(
|
|
243
243
|
f"In use: {format_tokens(agent.ctx_used)} of {format_tokens(s.context)} tokens "
|
|
244
244
|
f"({100 * agent.ctx_used / s.context:.0f}%) in {len(agent.messages)} message"
|
|
245
|
-
f"{'' if len(agent.messages) == 1 else 's'};
|
|
245
|
+
f"{'' if len(agent.messages) == 1 else 's'}; makes room at {format_tokens(agent.compact_limit())} "
|
|
246
|
+
+ ("(compact_at)." if agent.compact_limit() < AUTO_COMPACT_RATIO * s.context else "(85%).")
|
|
246
247
|
)
|
|
247
248
|
if agent.mcp and agent.mcp.ready():
|
|
248
249
|
how = "found on demand" if agent.mcp.searching(s.context) else "sent with every request"
|