lcode-cli 0.51.0__py3-none-any.whl → 0.52.0__py3-none-any.whl
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/__init__.py +1 -1
- lcode/agent.py +23 -7
- lcode/api.py +1 -0
- lcode/cli.py +10 -1
- lcode/config.py +5 -0
- lcode/docs/configuration.md +4 -3
- lcode/docs/how-it-works.md +2 -1
- lcode/docs/memory.md +31 -16
- lcode/docs/quickstart.md +1 -1
- lcode/docs/usage.md +31 -12
- lcode/memory.py +62 -8
- lcode/repl.py +59 -27
- lcode/repoid.py +65 -0
- lcode/sessions.py +120 -14
- {lcode_cli-0.51.0.dist-info → lcode_cli-0.52.0.dist-info}/METADATA +1 -1
- {lcode_cli-0.51.0.dist-info → lcode_cli-0.52.0.dist-info}/RECORD +19 -18
- {lcode_cli-0.51.0.dist-info → lcode_cli-0.52.0.dist-info}/WHEEL +0 -0
- {lcode_cli-0.51.0.dist-info → lcode_cli-0.52.0.dist-info}/entry_points.txt +0 -0
- {lcode_cli-0.51.0.dist-info → lcode_cli-0.52.0.dist-info}/licenses/LICENSE +0 -0
lcode/__init__.py
CHANGED
lcode/agent.py
CHANGED
|
@@ -35,6 +35,7 @@ from lcode import (
|
|
|
35
35
|
manual,
|
|
36
36
|
notify,
|
|
37
37
|
planning,
|
|
38
|
+
repoid,
|
|
38
39
|
repomap,
|
|
39
40
|
residency,
|
|
40
41
|
review,
|
|
@@ -329,6 +330,7 @@ class Settings:
|
|
|
329
330
|
sandbox_network: bool = False
|
|
330
331
|
vision_model: str = "auto" # auto, off or an Ollama model that can see images
|
|
331
332
|
memory: str = "off" # off, ask or auto: notes that carry over to later sessions (lcode.memory)
|
|
333
|
+
memory_check: bool = False # ask the model what's worth remembering when a conversation ends
|
|
332
334
|
subagents: bool = False # the agent tool (lcode.subagents)
|
|
333
335
|
trust_project: bool = False # use the repository's own commands, skills and agents (lcode.extensions)
|
|
334
336
|
skills: str = "off" # all, lcode (only lcode's own skill folders) or off
|
|
@@ -431,6 +433,7 @@ class Agent:
|
|
|
431
433
|
self.reply_trouble = "" # what went wrong with the last reply: "circles", "cut_off" or ""
|
|
432
434
|
self.response = None # the streaming response, so another thread can abort it
|
|
433
435
|
self.ctx_used = 0
|
|
436
|
+
self._repo: tuple[Path, repoid.Repo | None] | None = None # the workspace's repository, for saved sessions
|
|
434
437
|
self.last_speed = 0.0
|
|
435
438
|
self.usage = {"requests": 0, "prompt_tokens": 0, "prompt_ns": 0, "output_tokens": 0, "output_ns": 0}
|
|
436
439
|
self.messages: list[dict] = []
|
|
@@ -701,8 +704,12 @@ class Agent:
|
|
|
701
704
|
self.session_title = self.session_title or sessions.title_from(self.messages)
|
|
702
705
|
f = self.session_file()
|
|
703
706
|
f.parent.mkdir(parents=True, exist_ok=True)
|
|
707
|
+
repo = self.workspace_repo()
|
|
704
708
|
data = {
|
|
705
709
|
"cwd": str(self.workspace), # where `lcode -c` there finds it, wherever the shell moved
|
|
710
|
+
# /resume lists it under "this folder" in any checkout of the same repository, wherever it moves
|
|
711
|
+
**({"repo": repo.to_json()} if repo else {}),
|
|
712
|
+
"context": {"used": self.next_request_tokens(), "window": self.settings.context},
|
|
706
713
|
"model": self.settings.model,
|
|
707
714
|
"mode": self.settings.mode,
|
|
708
715
|
"image_model": self.settings.image_model,
|
|
@@ -721,6 +728,12 @@ class Agent:
|
|
|
721
728
|
partial.write_text(json.dumps(data))
|
|
722
729
|
os.replace(partial, f)
|
|
723
730
|
|
|
731
|
+
def workspace_repo(self) -> repoid.Repo | None:
|
|
732
|
+
"""The repository the workspace is in, looked up again when the workspace changes or gets its first commit."""
|
|
733
|
+
if self._repo is None or self._repo[0] != self.workspace or (self._repo[1] and not self._repo[1].first):
|
|
734
|
+
self._repo = (self.workspace, repoid.find(self.workspace))
|
|
735
|
+
return self._repo[1]
|
|
736
|
+
|
|
724
737
|
def new_session(self) -> None:
|
|
725
738
|
self.reset()
|
|
726
739
|
self.skills_loaded.clear()
|
|
@@ -770,15 +783,18 @@ class Agent:
|
|
|
770
783
|
self.tools.notes = [str(n) for n in data.get("notes") or []]
|
|
771
784
|
self.tools.changed = dict.fromkeys(str(f) for f in data.get("changed") or [])
|
|
772
785
|
self.reflected = len(self.messages) # checked for notes to remember when that session ended
|
|
773
|
-
|
|
774
|
-
|
|
786
|
+
saved = (data.get("context") or {}).get("used") if isinstance(data.get("context"), dict) else None
|
|
787
|
+
if isinstance(saved, int) and saved > 0: # what the model counted, plus what came after
|
|
788
|
+
self.ctx_used, self.counted_chars = saved, conversation_chars(self.messages)
|
|
789
|
+
else: # saved by a version before 0.52
|
|
790
|
+
self.ctx_used, self.counted_chars = sessions.estimate_tokens(self.messages), None
|
|
775
791
|
return note
|
|
776
792
|
|
|
777
|
-
def load_latest(self) ->
|
|
778
|
-
latest
|
|
779
|
-
if
|
|
780
|
-
|
|
781
|
-
return
|
|
793
|
+
def load_latest(self) -> str | None:
|
|
794
|
+
"""Continue the latest conversation in this folder (or its repository). Returns a note about the working
|
|
795
|
+
directory ("" if it stayed), or None when there's nothing to continue."""
|
|
796
|
+
latest = sessions.latest(self.workspace)
|
|
797
|
+
return self.load(latest) if latest else None
|
|
782
798
|
|
|
783
799
|
# -- model calls
|
|
784
800
|
def options(self) -> dict:
|
lcode/api.py
CHANGED
|
@@ -214,6 +214,7 @@ def open_agent(cwd: Path, options: Options, console: Console, hw: Hardware | Non
|
|
|
214
214
|
sandbox_network=cfg["sandbox_network"],
|
|
215
215
|
vision_model=cfg["vision_model"],
|
|
216
216
|
memory=switch(options.memory, cfg["memory"], "ask"),
|
|
217
|
+
memory_check=cfg["memory_check"],
|
|
217
218
|
subagents=cfg["subagents"],
|
|
218
219
|
max_parallel_agents=cfg["max_parallel_agents"],
|
|
219
220
|
trust_project=trust_project,
|
lcode/cli.py
CHANGED
|
@@ -20,7 +20,7 @@ from rich.progress import BarColumn, DownloadColumn, Progress, TextColumn, TimeR
|
|
|
20
20
|
from rich.prompt import Confirm
|
|
21
21
|
from rich.table import Table
|
|
22
22
|
|
|
23
|
-
from lcode import __version__, backends, catalog, config, limits, web
|
|
23
|
+
from lcode import __version__, backends, catalog, config, limits, sessions, web
|
|
24
24
|
from lcode.agent import Settings
|
|
25
25
|
from lcode.catalog import ModelSpec
|
|
26
26
|
from lcode.cloud import is_cloud, signin_command
|
|
@@ -553,6 +553,7 @@ def cmd_doctor(args) -> None:
|
|
|
553
553
|
|
|
554
554
|
project, user = Memory(Path.cwd()).counts()
|
|
555
555
|
line("Memory", f"{cfg['memory']} · {project} note(s) for this repository, {user} for every repository", True)
|
|
556
|
+
line("Sessions", sessions_status(Path.cwd()), True)
|
|
556
557
|
node = shutil.which("npx")
|
|
557
558
|
line("Node.js", "found" if node else "not found (some MCP servers need npx)", True if node else None)
|
|
558
559
|
sys.exit(0 if ok else 1)
|
|
@@ -775,6 +776,14 @@ def exit_on_hangup() -> None:
|
|
|
775
776
|
signal.signal(sig, leave)
|
|
776
777
|
|
|
777
778
|
|
|
779
|
+
def sessions_status(cwd: Path) -> str:
|
|
780
|
+
"""How many conversations are saved, and where: a terminal with another LCODE_HOME or XDG_STATE_HOME has
|
|
781
|
+
other ones."""
|
|
782
|
+
listing = sessions.grouped(cwd, everything=True)
|
|
783
|
+
saved = len(listing.here) + len(listing.elsewhere)
|
|
784
|
+
return f"{saved} saved, {len(listing.here)} for this folder · in {sessions.sessions_dir()}"
|
|
785
|
+
|
|
786
|
+
|
|
778
787
|
def comfyui_status(cfg: dict) -> tuple[str, bool | None]:
|
|
779
788
|
"""lcode doctor's ComfyUI line: running or found, and whether the image model is there."""
|
|
780
789
|
from lcode import comfy
|
lcode/config.py
CHANGED
|
@@ -61,6 +61,11 @@ SETTINGS: dict[str, tuple[object, type, str]] = {
|
|
|
61
61
|
"vision_model": ("auto", str, "model that looks at images: auto | off | an Ollama model with vision"),
|
|
62
62
|
"mcp_tools": ("auto", str, "how MCP tools reach the model: auto | direct | search (on demand, saves context)"),
|
|
63
63
|
"memory": ("ask", str, "notes that carry over to later sessions: off | ask (confirm each) | auto"),
|
|
64
|
+
"memory_check": (
|
|
65
|
+
False,
|
|
66
|
+
bool,
|
|
67
|
+
"when a conversation ends (quit, /clear, or before it's summarized), ask the model what's worth remembering",
|
|
68
|
+
),
|
|
64
69
|
"skills": ("all", str, "skills to offer the model: all (also other agents' folders) | lcode | off"),
|
|
65
70
|
"repo_map": (True, bool, "give the model a ranked map of the repository's symbols"),
|
|
66
71
|
"embed_model": ("auto", str, "embedding model for semantic code search (lcode index): auto | off | a model"),
|
lcode/docs/configuration.md
CHANGED
|
@@ -42,6 +42,7 @@ lcode config path # print the file location
|
|
|
42
42
|
| `vision_model` | `auto` | The model that [looks at images](usage.md#images): `auto`, `off` or an Ollama model that can see |
|
|
43
43
|
| `mcp_tools` | `auto` | How [MCP](mcp.md#context) tool definitions reach the model: `auto`, `direct` or `search` (on demand) |
|
|
44
44
|
| `memory` | `ask` | [Notes that carry over](memory.md) to later sessions: `ask` (confirm each), `auto` or `off` |
|
|
45
|
+
| `memory_check` | `false` | When a conversation ends, [ask the model what's worth remembering](memory.md#a-check-when-a-session-ends) (a model call before you can leave) |
|
|
45
46
|
| `skills` | `all` | Which [skills](commands.md#skills) the model is offered: `all` (lcode's folders and the ones other agents share), `lcode` (only `.lcode/skills/` and `~/.config/lcode/skills/`) or `off` |
|
|
46
47
|
| `repo_map` | `true` | Give the model a ranked [map of the repository](search.md) |
|
|
47
48
|
| `embed_model` | `auto` | Embedding model for [semantic code search](search.md#semantic-code-search): `auto`, `off` or a model name |
|
|
@@ -93,20 +94,20 @@ Environment variables override the file, which is useful for one-off runs and CI
|
|
|
93
94
|
| `LCODE_SANDBOX` | `sandbox` |
|
|
94
95
|
| `LCODE_MEMORY` | `memory` |
|
|
95
96
|
| `OLLAMA_API_KEY`, `BRAVE_API_KEY`, `TAVILY_API_KEY` | API key for that [search provider](usage.md#web-search) (never stored in the config file) |
|
|
96
|
-
| `LCODE_HOME` | where sessions and prompt history are stored |
|
|
97
|
+
| `LCODE_HOME` | where sessions, notes and prompt history are stored, instead of `~/.local/state/lcode` |
|
|
97
98
|
|
|
98
99
|
## Files lcode creates
|
|
99
100
|
|
|
100
101
|
| Path | Contents |
|
|
101
102
|
|---|---|
|
|
102
103
|
| `~/.config/lcode/config.toml` | Settings |
|
|
103
|
-
| `~/.local/state/lcode/sessions/` | Saved conversations (for `lcode -c`) |
|
|
104
|
+
| `~/.local/state/lcode/sessions/` | Saved conversations (for `/resume` and `lcode -c`), one JSON file each |
|
|
104
105
|
| `~/.local/state/lcode/history` | Prompt history (++up++ in the prompt) |
|
|
105
106
|
| `~/.config/lcode/mcp.json` | [MCP servers](mcp.md) (readable only by you; may contain tokens) |
|
|
106
107
|
| `~/.local/state/lcode/mcp-auth/` | Sign-in tokens for remote MCP servers (readable only by you) |
|
|
107
108
|
| `~/.local/state/lcode/mcp-logs/` | Error output of local MCP servers |
|
|
108
109
|
| `~/.local/state/lcode/checkpoints/` | Checkpoints for `/undo` (copies of your project's files; deleted after 14 days) |
|
|
109
|
-
| `~/.local/state/lcode/memory/` | [Memory](memory.md) notes: `user/` for every repository, `projects/<repository>/` for each one |
|
|
110
|
+
| `~/.local/state/lcode/memory/` | [Memory](memory.md) notes: `user/` for every repository, `projects/<repository>/` for each one (`/memory path` shows this repository's) |
|
|
110
111
|
| `~/.config/lcode/commands/`, `~/.config/lcode/skills/` | Your [commands and skills](commands.md) (a repository's go in `.lcode/`) |
|
|
111
112
|
| `~/.local/state/lcode/extensions-approved.json` | Repositories whose commands, skills and agents you approved |
|
|
112
113
|
| `~/.config/lcode/agents/` | Your [custom agents](agents.md#custom-agents) (a repository's go in `.lcode/agents/`) |
|
lcode/docs/how-it-works.md
CHANGED
|
@@ -197,7 +197,8 @@ the Ollama server you configure, it only contacts the web when the model searche
|
|
|
197
197
|
| `extensions.py` | Custom commands and skills, and approving a repository's own |
|
|
198
198
|
| `frontmatter.py` | The `---` headers of notes, agents, commands and skills |
|
|
199
199
|
| `planning.py` | Plan mode: what it allows, presenting a plan and approving it |
|
|
200
|
-
| `memory.py` | Notes that carry over between sessions, and the end-of-session check |
|
|
200
|
+
| `memory.py` | Notes that carry over between sessions, and the optional end-of-session check |
|
|
201
|
+
| `sessions.py`, `repoid.py` | Saved conversations: listing them for this folder and elsewhere; which repository a folder is in, by its first commit |
|
|
201
202
|
| `sandbox.py` | The optional container for shell commands |
|
|
202
203
|
| `checkpoints.py` | Snapshots before the model changes files, for `/undo` and `/rewind` |
|
|
203
204
|
| `catalog.py`, `models.toml` | Model catalog and memory estimates |
|
lcode/docs/memory.md
CHANGED
|
@@ -49,29 +49,37 @@ instead ("staging credentials are in 1Password, vault Dev").
|
|
|
49
49
|
`-g` saves it for every repository. Start with `feedback:`, `reference:` or `user:` to set the
|
|
50
50
|
type (the default is `project`).
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
asks the model one short question: is anything from this session worth remembering? It happens
|
|
54
|
-
when you quit, on `/clear`, and before the conversation is compacted (the summary leaves details
|
|
55
|
-
out). The model proposes at most three notes:
|
|
52
|
+
## A check when a session ends
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
Local models rarely save notes on their own. With `memory_check` on, lcode asks the model one short
|
|
55
|
+
question when a conversation ends: is anything from it worth remembering? It happens when you
|
|
56
|
+
quit, on `/clear`, and before the conversation is summarized (the summary leaves details out). The
|
|
57
|
+
model proposes at most three notes:
|
|
58
|
+
|
|
59
|
+
```text
|
|
60
|
+
╭─ Worth remembering? ────────────────────────────────────────────────────────╮
|
|
61
|
+
│ 1 [feedback] Use pnpm, not npm (this repository) │
|
|
62
|
+
│ 2 [project] Integration tests need `docker compose up db` first (this │
|
|
63
|
+
│ repository) │
|
|
64
|
+
╰───────────────────────────────────────────────────────────────────────────────╯
|
|
65
|
+
Save them? [y]es / numbers to keep, e.g. 1,3 / [n]o: 1
|
|
66
|
+
```
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
It's off by default, because it's a model call you wait for before you can leave. Turn it on with:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
lcode config set memory_check true
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The question reuses the conversation Ollama already has in memory, so the model only writes a few
|
|
75
|
+
lines. Short sessions (one request and little work) are skipped, and Ctrl+C skips it too. The
|
|
76
|
+
conversation itself is always saved, with or without the check.
|
|
69
77
|
|
|
70
78
|
## Asking first: the `memory` setting
|
|
71
79
|
|
|
72
80
|
| `memory` | |
|
|
73
81
|
|---|---|
|
|
74
|
-
| `ask` (default) | Every note the model saves, and the end-of-session proposals, need your OK. Answer `a` once to allow the model's notes for the rest of the session. This holds in `yolo` mode too. |
|
|
82
|
+
| `ask` (default) | Every note the model saves, and the [end-of-session](#a-check-when-a-session-ends) proposals, need your OK. Answer `a` once to allow the model's notes for the rest of the session. This holds in `yolo` mode too. |
|
|
75
83
|
| `auto` | Notes are saved without asking; lcode prints each one. |
|
|
76
84
|
| `off` | No notes are loaded or saved, and the model has no `memory` tool. |
|
|
77
85
|
|
|
@@ -116,6 +124,13 @@ The dev dependencies are in a uv dependency group, which plain pytest doesn't se
|
|
|
116
124
|
|
|
117
125
|
Each folder also has a `MEMORY.md` listing its notes, for reading; lcode regenerates it, so edit
|
|
118
126
|
the notes rather than that file. A folder that isn't in a git repository gets its own notes.
|
|
127
|
+
`/memory path` shows where this repository's are.
|
|
128
|
+
|
|
129
|
+
A repository's notes follow it when you move or rename it, or clone it again: its folder has a
|
|
130
|
+
`repo.json` naming the repository's first commit, which every clone shares. Notes saved before
|
|
131
|
+
lcode 0.52 get that file the first time lcode runs in their repository. Notes of a repository
|
|
132
|
+
that moved before then are in a folder named after its old name; copy them into the new one
|
|
133
|
+
(`/memory path`) to keep them.
|
|
119
134
|
|
|
120
135
|
At the start of a session, the model gets a one-line index of the notes (description, name, date)
|
|
121
136
|
in its instructions. The index is capped at about 2,000 tokens, or 5% of a small context window;
|
lcode/docs/quickstart.md
CHANGED
lcode/docs/usage.md
CHANGED
|
@@ -712,40 +712,59 @@ Instructions that are only needed for some tasks fit better in a [command or ski
|
|
|
712
712
|
which costs no context until it's used.
|
|
713
713
|
|
|
714
714
|
What doesn't belong in `AGENTS.md` but should carry over, such as your corrections and preferences,
|
|
715
|
-
goes into lcode's [memory](memory.md): short notes the model
|
|
716
|
-
|
|
715
|
+
goes into lcode's [memory](memory.md): short notes the model or you (`/remember`) save, and that
|
|
716
|
+
every later session in the repository loads.
|
|
717
717
|
|
|
718
718
|
## Sessions
|
|
719
719
|
|
|
720
720
|
Every conversation is saved after each request to `~/.local/state/lcode/sessions/`, so you can
|
|
721
|
-
leave and pick up where you stopped.
|
|
721
|
+
leave and pick up where you stopped. Upgrading lcode keeps them, and the installed lcode and a
|
|
722
|
+
development checkout (`uv run lcode`) share them.
|
|
722
723
|
|
|
723
724
|
```text
|
|
724
725
|
❯ /rename auth refactor # name the current session
|
|
725
|
-
❯ /resume # list
|
|
726
|
+
❯ /resume # list the saved sessions and pick one
|
|
726
727
|
```
|
|
727
728
|
|
|
728
729
|
```text
|
|
729
|
-
|
|
730
|
-
# Session Last used Requests
|
|
731
|
-
1 auth refactor 2 h ago 14
|
|
730
|
+
This folder · ~/code/my-project
|
|
731
|
+
# Session Last used Requests Context
|
|
732
|
+
1 auth refactor 2 h ago 14 41.3K / 128K (32%)
|
|
732
733
|
Explain how login tokens are validated
|
|
733
|
-
2 The tests in tests/test_parser.py fail… yesterday 6
|
|
734
|
+
2 The tests in tests/test_parser.py fail… yesterday 6 ~18K / 128K (14%)
|
|
735
|
+
in tests
|
|
736
|
+
Elsewhere
|
|
737
|
+
# Session Last used Requests Context Folder
|
|
738
|
+
3 Set up the release script Oct 20 3 9.6K / 128K (8%) ~/code/tools
|
|
734
739
|
Resume which session? (number or name, Enter to cancel): 1
|
|
735
740
|
```
|
|
736
741
|
|
|
742
|
+
- **This folder** lists the sessions saved in this folder, and anywhere else in its git
|
|
743
|
+
repository: a subfolder, a worktree, or another clone of the same repository (it has the same
|
|
744
|
+
first commit). A row from another folder says where it was.
|
|
745
|
+
- **Elsewhere** lists the 20 newest sessions from other folders. Sessions from temporary folders
|
|
746
|
+
that no longer exist, such as scripted test runs, are left out. `/resume all` lists everything.
|
|
747
|
+
- **Context** is what the conversation takes of the current context window. A `~` means it's an
|
|
748
|
+
estimate, for sessions saved before lcode 0.52. After resuming, the status bar shows it right
|
|
749
|
+
away, and a yellow number means lcode summarizes the conversation before your next request.
|
|
750
|
+
|
|
737
751
|
Unnamed sessions are listed by their first request. After resuming, lcode shows your last request
|
|
738
752
|
and the start of its last answer so you know where you left off.
|
|
739
753
|
|
|
740
754
|
| From the shell | From a session | Resumes |
|
|
741
755
|
|---|---|---|
|
|
742
|
-
| `lcode -c` | | the
|
|
756
|
+
| `lcode -c` | | the latest session in this folder, else the latest under "This folder" |
|
|
743
757
|
| `lcode --resume` | `/resume` | one you pick from a list |
|
|
744
758
|
| `lcode --resume "auth refactor"` | `/resume auth refactor` | a session by name, list number, id or a unique part of its title |
|
|
745
|
-
|
|
|
759
|
+
| `lcode --resume all` | `/resume all` | one you pick from every saved session |
|
|
760
|
+
|
|
761
|
+
A session from another folder takes lcode to that folder. `/clear` starts a new conversation and
|
|
762
|
+
keeps the old one saved. Files may have changed since a session was saved, so after resuming the
|
|
763
|
+
model has to read a file again before editing it.
|
|
746
764
|
|
|
747
|
-
|
|
748
|
-
|
|
765
|
+
**Where are my sessions?** `lcode doctor` shows how many are saved and the folder they're in.
|
|
766
|
+
`LCODE_HOME`, or `XDG_STATE_HOME`, moves that folder: a terminal that sets one of them (some IDEs
|
|
767
|
+
and test scripts do) sees other sessions. `lcode bench` doesn't save its runs as sessions.
|
|
749
768
|
|
|
750
769
|
## Scripting
|
|
751
770
|
|
lcode/memory.py
CHANGED
|
@@ -15,13 +15,17 @@ repository, and `memory/projects/<repo>/` holds one repository's notes, shared b
|
|
|
15
15
|
worktrees. The system prompt gets a one-line index of both, capped so it costs little context;
|
|
16
16
|
the model reads a note's details with the memory tool.
|
|
17
17
|
|
|
18
|
-
Notes come from
|
|
19
|
-
reflection when a session ends ("what from this session is worth remembering?"),
|
|
20
|
-
models rarely save anything on their own.
|
|
18
|
+
Notes come from the model's memory tool and the user's /remember. With the memory_check setting on,
|
|
19
|
+
also from a short reflection when a session ends ("what from this session is worth remembering?"),
|
|
20
|
+
because local models rarely save anything on their own.
|
|
21
|
+
|
|
22
|
+
A repository's notes follow it when it's moved, renamed or cloned again: its folder holds a repo.json
|
|
23
|
+
naming the repository's first commit, and a checkout whose own folder has no notes finds them by it.
|
|
21
24
|
"""
|
|
22
25
|
|
|
23
26
|
from __future__ import annotations
|
|
24
27
|
|
|
28
|
+
import contextlib
|
|
25
29
|
import datetime as dt
|
|
26
30
|
import difflib
|
|
27
31
|
import hashlib
|
|
@@ -38,7 +42,7 @@ from rich.markup import escape
|
|
|
38
42
|
from rich.panel import Panel
|
|
39
43
|
from rich.text import Text
|
|
40
44
|
|
|
41
|
-
from lcode import config
|
|
45
|
+
from lcode import config, repoid
|
|
42
46
|
from lcode.frontmatter import split as frontmatter
|
|
43
47
|
|
|
44
48
|
if TYPE_CHECKING:
|
|
@@ -175,9 +179,12 @@ def _git_common_dir(cwd: Path) -> Path | None:
|
|
|
175
179
|
return (cwd / out).resolve()
|
|
176
180
|
|
|
177
181
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
IDENTITY = "repo.json" # in a repository's notes folder: which repository it is, by its first commit
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def path_dir(cwd: Path, common: Path | None = None) -> Path:
|
|
186
|
+
"""The notes folder named after where the repository (or folder) is: what lcode before 0.52 used."""
|
|
187
|
+
common = common or _git_common_dir(cwd)
|
|
181
188
|
if common:
|
|
182
189
|
root = common.parent if common.name == ".git" else common
|
|
183
190
|
name, ident = root.name.removesuffix(".git"), common
|
|
@@ -187,6 +194,46 @@ def project_dir(cwd: Path) -> Path:
|
|
|
187
194
|
return memory_dir() / "projects" / f"{slugify(name, 40) or 'folder'}-{key}"
|
|
188
195
|
|
|
189
196
|
|
|
197
|
+
def read_identity(folder: Path) -> str:
|
|
198
|
+
"""The first commit a notes folder belongs to ("" if it doesn't say)."""
|
|
199
|
+
try:
|
|
200
|
+
data = json.loads((folder / IDENTITY).read_text())
|
|
201
|
+
except (OSError, ValueError):
|
|
202
|
+
return ""
|
|
203
|
+
return str(data.get("first") or "") if isinstance(data, dict) else ""
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def write_identity(folder: Path, first: str, root: Path) -> None:
|
|
207
|
+
with contextlib.suppress(OSError):
|
|
208
|
+
_write_atomic(folder / IDENTITY, json.dumps({"first": first, "path": str(root)}, indent=1) + "\n")
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def project_dir(cwd: Path) -> Path:
|
|
212
|
+
"""Where the notes for the repository around `cwd` live: shared by its worktrees and every clone of it.
|
|
213
|
+
|
|
214
|
+
The folder named after the repository's place comes first, as older versions find it there. When that
|
|
215
|
+
folder has no notes, the repository may have moved or been cloned again: a folder whose repo.json names
|
|
216
|
+
the same first commit holds its notes."""
|
|
217
|
+
common = _git_common_dir(cwd)
|
|
218
|
+
here = path_dir(cwd, common)
|
|
219
|
+
if common is None:
|
|
220
|
+
return here # not a repository: notes for this folder
|
|
221
|
+
if here.is_dir() and read_identity(here):
|
|
222
|
+
return here
|
|
223
|
+
first = repoid.first_commit(cwd)
|
|
224
|
+
if not first:
|
|
225
|
+
return here
|
|
226
|
+
repo = repoid.find(cwd)
|
|
227
|
+
if here.is_dir(): # notes from before 0.52: say which repository they're for, so they follow it
|
|
228
|
+
write_identity(here, first, repo.root if repo else cwd)
|
|
229
|
+
return here
|
|
230
|
+
projects = memory_dir() / "projects"
|
|
231
|
+
elsewhere = [f for f in projects.iterdir() if f.is_dir() and read_identity(f) == first] if projects.is_dir() else []
|
|
232
|
+
if elsewhere: # the most recently used, if several clones had notes of their own
|
|
233
|
+
return max(elsewhere, key=lambda f: (f / "MEMORY.md").stat().st_mtime if (f / "MEMORY.md").exists() else 0)
|
|
234
|
+
return here
|
|
235
|
+
|
|
236
|
+
|
|
190
237
|
def parse(text: str, scope: str, path: Path | None = None) -> Note | None:
|
|
191
238
|
split = frontmatter(text)
|
|
192
239
|
if not split:
|
|
@@ -293,7 +340,12 @@ class Memory:
|
|
|
293
340
|
if existing and not note.details and existing.description == note.description:
|
|
294
341
|
note = replace(note, details=existing.details)
|
|
295
342
|
folder = self.folder(note.scope)
|
|
343
|
+
new_folder = not folder.is_dir()
|
|
296
344
|
folder.mkdir(parents=True, exist_ok=True)
|
|
345
|
+
if new_folder and note.scope == "project":
|
|
346
|
+
repo = repoid.find(self.cwd)
|
|
347
|
+
if repo and repo.first:
|
|
348
|
+
write_identity(folder, repo.first, repo.root)
|
|
297
349
|
path = folder / f"{note.name}.md"
|
|
298
350
|
_write_atomic(path, note.render())
|
|
299
351
|
self.write_index(note.scope)
|
|
@@ -471,7 +523,9 @@ def propose(agent: Agent) -> list[Note]:
|
|
|
471
523
|
|
|
472
524
|
def reflect(agent: Agent) -> None:
|
|
473
525
|
"""At the end of a session (or before compaction): propose notes, then save the ones the user accepts."""
|
|
474
|
-
if agent.settings.memory == "off" or not
|
|
526
|
+
if agent.settings.memory == "off" or not agent.settings.memory_check:
|
|
527
|
+
return # off by default: quitting just saves the conversation
|
|
528
|
+
if not worth_reflecting(agent.messages, agent.reflected):
|
|
475
529
|
return
|
|
476
530
|
agent.reflected = len(agent.messages)
|
|
477
531
|
c = agent.console
|
lcode/repl.py
CHANGED
|
@@ -62,7 +62,7 @@ COMMANDS = {
|
|
|
62
62
|
"/init": "Analyze the repo and write an AGENTS.md guide (loaded at every start)",
|
|
63
63
|
"/clear": "Start a fresh conversation",
|
|
64
64
|
"/rename": "Name this session so you can find it later, e.g. /rename auth refactor",
|
|
65
|
-
"/resume": "Resume a saved session:
|
|
65
|
+
"/resume": "Resume a saved session: this folder's, then others; /resume <number|name>; /resume all: older too",
|
|
66
66
|
"/undo": "Undo the file changes of the last request (lcode saves a checkpoint before changing files)",
|
|
67
67
|
"/rewind": "Go back to before an earlier request: its files, and optionally the conversation",
|
|
68
68
|
"/checkpoints": "List the requests that changed files, and which files",
|
|
@@ -1263,51 +1263,80 @@ def handle_command(agent: Agent, line: str, hardware: Hardware) -> bool:
|
|
|
1263
1263
|
return True
|
|
1264
1264
|
|
|
1265
1265
|
|
|
1266
|
-
def
|
|
1267
|
-
|
|
1268
|
-
|
|
1266
|
+
def short_path(folder: str) -> str:
|
|
1267
|
+
"""A folder for a list: under the home folder as ~/…"""
|
|
1268
|
+
home = str(Path.home())
|
|
1269
|
+
return "~" + folder[len(home) :] if folder == home or folder.startswith(home + "/") else folder
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
def session_table(agent: Agent, title: str, found: list[sessions.SessionInfo], first: int, folders: bool) -> Table:
|
|
1273
|
+
table = Table(title=title, title_justify="left", header_style="bold")
|
|
1269
1274
|
table.add_column("#", justify="right", style="cyan")
|
|
1270
1275
|
table.add_column("Session")
|
|
1271
1276
|
table.add_column("Last used", no_wrap=True)
|
|
1272
1277
|
table.add_column("Requests", justify="right")
|
|
1273
|
-
|
|
1278
|
+
table.add_column("Context", no_wrap=True)
|
|
1279
|
+
if folders:
|
|
1274
1280
|
table.add_column("Folder", overflow="fold")
|
|
1275
|
-
for i, info in enumerate(found,
|
|
1281
|
+
for i, info in enumerate(found, first):
|
|
1276
1282
|
if info.name:
|
|
1277
1283
|
label = f"[bold]{escape(info.name)}[/]\n[dim]{escape(info.title or '(no requests yet)')}[/]"
|
|
1278
1284
|
else:
|
|
1279
1285
|
label = escape(info.label)
|
|
1280
1286
|
if info.id == agent.session_id:
|
|
1281
1287
|
label += " [green](current)[/]"
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1288
|
+
elif not folders and info.cwd != str(agent.workspace): # in another folder or checkout of this repository
|
|
1289
|
+
saved = Path(info.cwd)
|
|
1290
|
+
where = saved.relative_to(agent.workspace) if agent.workspace in saved.parents else short_path(info.cwd)
|
|
1291
|
+
label += f"\n[dim]in {escape(str(where))}[/]"
|
|
1292
|
+
tokens = info.context(agent.settings.context)
|
|
1293
|
+
if info.tokens > agent.settings.context * 0.85: # resuming summarizes it first
|
|
1294
|
+
tokens = f"[yellow]{tokens}[/]"
|
|
1295
|
+
row = [str(i), label, sessions.age(info.updated), str(info.turns), tokens]
|
|
1296
|
+
if folders:
|
|
1297
|
+
row.append(escape(short_path(info.cwd)))
|
|
1285
1298
|
table.add_row(*row)
|
|
1286
|
-
|
|
1299
|
+
return table
|
|
1300
|
+
|
|
1301
|
+
|
|
1302
|
+
def print_sessions(agent: Agent, listing: sessions.Listing) -> None:
|
|
1303
|
+
"""This folder's sessions, then the others with their folders, numbered across both."""
|
|
1304
|
+
c = agent.console
|
|
1305
|
+
here = short_path(str(agent.workspace))
|
|
1306
|
+
if listing.here:
|
|
1307
|
+
c.print(session_table(agent, f"This folder · {here}", listing.here, 1, folders=False))
|
|
1308
|
+
else:
|
|
1309
|
+
c.print(f"[dim]No saved sessions in this folder ({escape(here)}) yet.[/]")
|
|
1310
|
+
if listing.elsewhere:
|
|
1311
|
+
c.print(session_table(agent, "Elsewhere", listing.elsewhere, len(listing.here) + 1, folders=True))
|
|
1312
|
+
left_out = []
|
|
1313
|
+
if listing.more:
|
|
1314
|
+
left_out.append(f"{listing.more} older session{'' if listing.more == 1 else 's'} elsewhere")
|
|
1315
|
+
if listing.hidden:
|
|
1316
|
+
left_out.append(f"{listing.hidden} test run{'' if listing.hidden == 1 else 's'} from temporary folders")
|
|
1317
|
+
if left_out:
|
|
1318
|
+
c.print(f"[dim]Not shown: {' and '.join(left_out)}. /resume all lists them.[/]")
|
|
1287
1319
|
|
|
1288
1320
|
|
|
1289
1321
|
def choose_session(agent: Agent, query: str = "") -> sessions.SessionInfo | None:
|
|
1290
|
-
"""Find a session by number/name/id, or list them and ask. `all` lists
|
|
1322
|
+
"""Find a session by number/name/id, or list them and ask. `all` also lists older sessions elsewhere."""
|
|
1291
1323
|
c = agent.console
|
|
1292
1324
|
words = query.split()
|
|
1293
|
-
|
|
1294
|
-
query = " ".join(words[1:] if
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
found, all_dirs = sessions.list_sessions(None), True
|
|
1298
|
-
if found and not query:
|
|
1299
|
-
c.print("[dim]No saved sessions in this folder; showing all folders.[/]")
|
|
1300
|
-
if not found:
|
|
1301
|
-
c.print("No saved sessions yet. Sessions are saved after every request.")
|
|
1302
|
-
return None
|
|
1325
|
+
everything = bool(words) and words[0].lower() in ("all", "--all", "-a")
|
|
1326
|
+
query = " ".join(words[1:] if everything else words)
|
|
1327
|
+
listing = sessions.grouped(agent.workspace, everything=everything)
|
|
1328
|
+
found = listing.numbered
|
|
1303
1329
|
if query:
|
|
1304
1330
|
match = sessions.find(query, found)
|
|
1305
|
-
if match is None and not
|
|
1306
|
-
match = sessions.find(query, sessions.
|
|
1331
|
+
if match is None and not everything:
|
|
1332
|
+
match = sessions.find(query, sessions.grouped(agent.workspace, everything=True).numbered)
|
|
1307
1333
|
if match:
|
|
1308
1334
|
return match
|
|
1309
1335
|
c.print(f"[yellow]No session matches '{escape(query)}'.[/]")
|
|
1310
|
-
|
|
1336
|
+
if not found:
|
|
1337
|
+
c.print("No saved sessions yet. Sessions are saved after every request.")
|
|
1338
|
+
return None
|
|
1339
|
+
print_sessions(agent, listing)
|
|
1311
1340
|
try:
|
|
1312
1341
|
answer = input(" Resume which session? (number or name, Enter to cancel): ").strip()
|
|
1313
1342
|
except EOFError:
|
|
@@ -1358,11 +1387,14 @@ def print_recap(agent: Agent) -> None:
|
|
|
1358
1387
|
|
|
1359
1388
|
def repl(agent: Agent, prompt: str | None, hardware: Hardware, cont: bool = False, resume: str | None = None) -> None:
|
|
1360
1389
|
if cont:
|
|
1361
|
-
|
|
1390
|
+
note = agent.load_latest()
|
|
1391
|
+
if note is None:
|
|
1392
|
+
agent.console.print("[dim]No saved session in this folder yet; starting a new one.[/]")
|
|
1393
|
+
else:
|
|
1362
1394
|
agent.console.print(f"[green]Continuing[/] [bold]{escape(agent.session_name or agent.session_title)}[/]")
|
|
1395
|
+
if note:
|
|
1396
|
+
agent.console.print(f"[yellow]{escape(note)}[/]")
|
|
1363
1397
|
print_recap(agent)
|
|
1364
|
-
else:
|
|
1365
|
-
agent.console.print("[dim]No saved session in this folder yet; starting a new one.[/]")
|
|
1366
1398
|
elif resume is not None:
|
|
1367
1399
|
info = choose_session(agent, resume)
|
|
1368
1400
|
if info:
|
lcode/repoid.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Which git repository a folder belongs to, so saved conversations and notes follow a repository that was
|
|
2
|
+
moved, renamed or cloned again.
|
|
3
|
+
|
|
4
|
+
A repository is known by its first commit, which every clone and worktree of it shares wherever it lives,
|
|
5
|
+
plus its git directory (shared by its worktrees) and the top of its working tree.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import subprocess
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class Repo:
|
|
18
|
+
root: Path # the top of the working tree
|
|
19
|
+
common: Path # the git directory, the same for every worktree of the repository
|
|
20
|
+
first: str = "" # the first commit's hash; empty in a repository without commits
|
|
21
|
+
|
|
22
|
+
def same(self, other: Repo) -> bool:
|
|
23
|
+
"""Two checkouts of one repository: the same first commit, git directory or working tree."""
|
|
24
|
+
return bool(self.first and self.first == other.first) or self.common == other.common or self.root == other.root
|
|
25
|
+
|
|
26
|
+
def to_json(self) -> dict:
|
|
27
|
+
return {"root": str(self.root), "common": str(self.common), "first": self.first}
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def from_json(cls, data: object) -> Repo | None:
|
|
31
|
+
if not isinstance(data, dict) or not data.get("root") or not data.get("common"):
|
|
32
|
+
return None
|
|
33
|
+
return cls(Path(str(data["root"])), Path(str(data["common"])), str(data.get("first") or ""))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _git(folder: Path, *args: str) -> str | None:
|
|
37
|
+
env = {k: v for k, v in os.environ.items() if not k.startswith("GIT_")} # a hook's GIT_DIR would point elsewhere
|
|
38
|
+
try:
|
|
39
|
+
r = subprocess.run(["git", *args], cwd=folder, capture_output=True, text=True, timeout=10, env=env)
|
|
40
|
+
except (OSError, subprocess.SubprocessError):
|
|
41
|
+
return None
|
|
42
|
+
return r.stdout.strip() if r.returncode == 0 else None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def first_commit(folder: Path) -> str:
|
|
46
|
+
"""The repository's first commit (the oldest root, for one with several); empty without commits."""
|
|
47
|
+
out = _git(folder, "rev-list", "--max-parents=0", "HEAD")
|
|
48
|
+
return sorted(out.split())[0] if out else ""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def find(folder: Path | str) -> Repo | None:
|
|
52
|
+
"""The repository around `folder`, or None outside git (or when the folder no longer exists)."""
|
|
53
|
+
folder = Path(folder)
|
|
54
|
+
if not folder.is_dir():
|
|
55
|
+
return None
|
|
56
|
+
out = _git(folder, "rev-parse", "--show-toplevel", "--git-common-dir")
|
|
57
|
+
lines = out.splitlines() if out else []
|
|
58
|
+
if len(lines) != 2:
|
|
59
|
+
return None
|
|
60
|
+
return Repo(Path(lines[0]).resolve(), (folder / lines[1]).resolve(), first_commit(folder))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def within(path: Path, folder: Path) -> bool:
|
|
64
|
+
"""`path` is `folder` or somewhere inside it."""
|
|
65
|
+
return path == folder or folder in path.parents
|
lcode/sessions.py
CHANGED
|
@@ -2,15 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import contextlib
|
|
5
6
|
import datetime as dt
|
|
7
|
+
import itertools
|
|
6
8
|
import json
|
|
7
9
|
import re
|
|
8
|
-
|
|
10
|
+
import tempfile
|
|
11
|
+
from collections.abc import Iterator
|
|
12
|
+
from dataclasses import dataclass, field
|
|
9
13
|
from pathlib import Path
|
|
10
14
|
|
|
11
|
-
from lcode import config
|
|
15
|
+
from lcode import config, repoid
|
|
16
|
+
from lcode.config import format_tokens
|
|
12
17
|
|
|
13
18
|
TITLE_LENGTH = 70
|
|
19
|
+
ELSEWHERE_LIMIT = 20 # sessions from other folders /resume lists; /resume all lists them all
|
|
14
20
|
SUMMARY_PREFIX = "[Summary of our conversation so far]" # first message of a compacted conversation
|
|
15
21
|
EXIT_WORDS = {"exit", "quit", ":q", ":quit"}
|
|
16
22
|
|
|
@@ -25,11 +31,35 @@ class SessionInfo:
|
|
|
25
31
|
model: str
|
|
26
32
|
updated: float # modification time of the session file
|
|
27
33
|
turns: int # number of requests from the user (and images made, in image mode)
|
|
34
|
+
tokens: int = 0 # the context the conversation uses
|
|
35
|
+
estimated: bool = True # tokens estimated from the text: saved by a version before 0.52
|
|
36
|
+
repo: repoid.Repo | None = field(default=None, compare=False) # the repository it was saved in, if saved
|
|
28
37
|
|
|
29
38
|
@property
|
|
30
39
|
def label(self) -> str:
|
|
31
40
|
return self.name or self.title or "(no requests yet)"
|
|
32
41
|
|
|
42
|
+
def context(self, window: int) -> str:
|
|
43
|
+
"""The context it uses against a window, e.g. `18.2K / 32K (57%)`."""
|
|
44
|
+
if not self.tokens:
|
|
45
|
+
return ""
|
|
46
|
+
used = f"{'~' if self.estimated else ''}{format_tokens(self.tokens)}"
|
|
47
|
+
return f"{used} / {format_tokens(window)} ({100 * self.tokens / window:.0f}%)" if window else used
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class Listing:
|
|
52
|
+
"""Saved sessions in two sections, numbered across both: this folder's first."""
|
|
53
|
+
|
|
54
|
+
here: list[SessionInfo] # saved in this folder, or anywhere in its repository (another checkout too)
|
|
55
|
+
elsewhere: list[SessionInfo]
|
|
56
|
+
more: int = 0 # older sessions elsewhere not listed
|
|
57
|
+
hidden: int = 0 # from temporary folders that are gone (test runs)
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def numbered(self) -> list[SessionInfo]:
|
|
61
|
+
return [*self.here, *self.elsewhere]
|
|
62
|
+
|
|
33
63
|
|
|
34
64
|
def sessions_dir() -> Path:
|
|
35
65
|
return config.STATE_DIR / "sessions"
|
|
@@ -54,13 +84,22 @@ def title_from(messages: list[dict]) -> str:
|
|
|
54
84
|
return "Compacted conversation" if compacted else ""
|
|
55
85
|
|
|
56
86
|
|
|
87
|
+
def estimate_tokens(messages: list[dict]) -> int:
|
|
88
|
+
"""About how many tokens a conversation takes: a token is about three characters of its JSON."""
|
|
89
|
+
return sum(len(json.dumps(m)) for m in messages) // 3
|
|
90
|
+
|
|
91
|
+
|
|
57
92
|
def read_info(path: Path) -> SessionInfo | None:
|
|
58
93
|
try:
|
|
59
94
|
data = json.loads(path.read_text())
|
|
60
95
|
updated = path.stat().st_mtime
|
|
61
96
|
except (OSError, ValueError):
|
|
62
97
|
return None
|
|
63
|
-
|
|
98
|
+
if not isinstance(data, dict):
|
|
99
|
+
return None
|
|
100
|
+
messages = [m for m in data.get("messages") or [] if isinstance(m, dict)]
|
|
101
|
+
saved = data.get("context") if isinstance(data.get("context"), dict) else {}
|
|
102
|
+
tokens = saved.get("used") if isinstance(saved.get("used"), int) and saved.get("used") > 0 else 0
|
|
64
103
|
return SessionInfo(
|
|
65
104
|
id=path.stem,
|
|
66
105
|
path=path,
|
|
@@ -70,23 +109,90 @@ def read_info(path: Path) -> SessionInfo | None:
|
|
|
70
109
|
model=data.get("model", ""),
|
|
71
110
|
updated=updated,
|
|
72
111
|
turns=sum(1 for m in messages if m.get("role") == "user") + len((data.get("media") or {}).get("results") or []),
|
|
112
|
+
tokens=tokens or estimate_tokens(messages),
|
|
113
|
+
estimated=not tokens,
|
|
114
|
+
repo=repoid.Repo.from_json(data.get("repo")),
|
|
73
115
|
)
|
|
74
116
|
|
|
75
117
|
|
|
76
|
-
def
|
|
77
|
-
"""
|
|
118
|
+
def _each() -> Iterator[SessionInfo]:
|
|
119
|
+
"""Every saved session worth listing, most recently used first, read as they're needed."""
|
|
78
120
|
directory = sessions_dir()
|
|
79
121
|
if not directory.is_dir():
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
122
|
+
return
|
|
123
|
+
stamped = []
|
|
124
|
+
for f in directory.glob("*.json"):
|
|
125
|
+
with contextlib.suppress(OSError): # deleted while listing
|
|
126
|
+
stamped.append((f.stat().st_mtime, f))
|
|
127
|
+
for _, f in sorted(stamped, reverse=True):
|
|
84
128
|
info = read_info(f)
|
|
85
|
-
if info and (info.turns or info.name)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
129
|
+
if info and (info.turns or info.name):
|
|
130
|
+
yield info
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def list_sessions(cwd: Path | str | None = None, limit: int = 50) -> list[SessionInfo]:
|
|
134
|
+
"""Saved sessions, most recently used first; only those saved in exactly `cwd` if given."""
|
|
135
|
+
found = (info for info in _each() if cwd is None or info.cwd == str(cwd))
|
|
136
|
+
return list(itertools.islice(found, limit))
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _gone_test_run(folder: str) -> bool:
|
|
140
|
+
"""Saved in a temporary folder that no longer exists: a scripted test run, not a conversation to go back to."""
|
|
141
|
+
path = Path(folder)
|
|
142
|
+
return bool(folder) and repoid.within(path, Path(tempfile.gettempdir()).resolve()) and not path.exists()
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class _Matcher:
|
|
146
|
+
"""Whether a session belongs to this folder: saved here, or in any checkout of the same repository."""
|
|
147
|
+
|
|
148
|
+
def __init__(self, cwd: Path):
|
|
149
|
+
self.cwd = cwd.resolve()
|
|
150
|
+
self.repo = repoid.find(self.cwd)
|
|
151
|
+
self.found: dict[str, repoid.Repo | None] = {}
|
|
152
|
+
|
|
153
|
+
def __call__(self, info: SessionInfo) -> bool:
|
|
154
|
+
if not info.cwd:
|
|
155
|
+
return False
|
|
156
|
+
saved = Path(info.cwd)
|
|
157
|
+
if saved == self.cwd:
|
|
158
|
+
return True
|
|
159
|
+
if self.repo is None:
|
|
160
|
+
return False
|
|
161
|
+
if info.repo is None and saved.is_dir(): # saved by an older version: look at the folder as it is now
|
|
162
|
+
if info.cwd not in self.found:
|
|
163
|
+
self.found[info.cwd] = repoid.find(saved)
|
|
164
|
+
other = self.found[info.cwd]
|
|
165
|
+
return other is not None and self.repo.same(other)
|
|
166
|
+
if info.repo is None: # its folder is gone: whether it was inside this repository
|
|
167
|
+
return repoid.within(saved, self.repo.root)
|
|
168
|
+
return self.repo.same(info.repo)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def grouped(cwd: Path, everything: bool = False, elsewhere_limit: int | None = None) -> Listing:
|
|
172
|
+
"""This folder's sessions and the others, newest first. Unless `everything`, the others are cut to the
|
|
173
|
+
newest few, and test runs from temporary folders that are gone are left out."""
|
|
174
|
+
elsewhere_limit = ELSEWHERE_LIMIT if elsewhere_limit is None else elsewhere_limit
|
|
175
|
+
belongs = _Matcher(cwd)
|
|
176
|
+
listing = Listing([], [])
|
|
177
|
+
for info in _each():
|
|
178
|
+
if belongs(info):
|
|
179
|
+
listing.here.append(info)
|
|
180
|
+
elif not everything and _gone_test_run(info.cwd):
|
|
181
|
+
listing.hidden += 1
|
|
182
|
+
elif not everything and len(listing.elsewhere) >= elsewhere_limit:
|
|
183
|
+
listing.more += 1
|
|
184
|
+
else:
|
|
185
|
+
listing.elsewhere.append(info)
|
|
186
|
+
return listing
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def latest(cwd: Path) -> SessionInfo | None:
|
|
190
|
+
"""The conversation `lcode -c` continues: the latest saved in this folder, else in its repository."""
|
|
191
|
+
exact = list_sessions(cwd, limit=1)
|
|
192
|
+
if exact:
|
|
193
|
+
return exact[0]
|
|
194
|
+
here = grouped(cwd, elsewhere_limit=0).here
|
|
195
|
+
return here[0] if here else None
|
|
90
196
|
|
|
91
197
|
|
|
92
198
|
def find(query: str, sessions: list[SessionInfo]) -> SessionInfo | None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: lcode-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.52.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/
|
|
@@ -2,30 +2,30 @@ lcode/docs/agents.md,sha256=A1heI40IKf767li9ffAH1grLlo2RhfbmB7lHL2uhZ4g,6915
|
|
|
2
2
|
lcode/docs/automation.md,sha256=Y57MWEVDjhOIDsnuWhzTB0K-5wlAm4nW2uOVWTAzeEM,9450
|
|
3
3
|
lcode/docs/bench.md,sha256=cF5XqCfz7woYmW6HtCwYd8kh52uAPWcOtXpfHy4msWo,12966
|
|
4
4
|
lcode/docs/commands.md,sha256=PpRcOoKZXw1OQyGxEbmipEPDYAid1fLDiaarHax7ynU,5973
|
|
5
|
-
lcode/docs/configuration.md,sha256=
|
|
5
|
+
lcode/docs/configuration.md,sha256=HaPm3qRwK6Hc9h5--uOnXChm_qPtA0Urw1Ibw25PH4Y,10796
|
|
6
6
|
lcode/docs/editors.md,sha256=9Ztqg_nyV5UTnMlJYrJrNvzY59X0d1HdWKYrs9-tZn4,3295
|
|
7
7
|
lcode/docs/git.md,sha256=zX25G1CxCUNQCZ_gnXja_0UjeCQ8kj3SiZxEWzWpp3A,5394
|
|
8
8
|
lcode/docs/hooks.md,sha256=3EvyYVlD0D8zB7c80yOgbs-fkx0niPM2NeiWXnX7AxQ,5214
|
|
9
|
-
lcode/docs/how-it-works.md,sha256=
|
|
9
|
+
lcode/docs/how-it-works.md,sha256=76eQZs883sMITL0wJZ5aYldosWTWyAQoT1FZ3Ntchfk,12779
|
|
10
10
|
lcode/docs/index.md,sha256=MbXP--ui-OwfNE4Q91oRh7TubdFNMH-RrliHkld6lYE,3815
|
|
11
11
|
lcode/docs/installation.md,sha256=Nu9OiKTLn4w7Mx9wMnqGA5SZlu8hVCXjh1rTvEL56Wc,6849
|
|
12
12
|
lcode/docs/lsp.md,sha256=tou-eJFMPvAJt0_-NaCm-c4OtfgVhok4Ig8NJnj6Rhs,3405
|
|
13
13
|
lcode/docs/mcp.md,sha256=Ol3ScuP4i2KsoN9xaSEbnm86Tvoc1qnUV7zkRprWwHo,15168
|
|
14
|
-
lcode/docs/memory.md,sha256=
|
|
14
|
+
lcode/docs/memory.md,sha256=XbsNnTwRdnUEYW7_2U1GHbtK0uOjTxR-s2EujgJbR0Y,6889
|
|
15
15
|
lcode/docs/models.md,sha256=d9wLOVBlMtnd8_2jQG9f0-qcEbGT6qtnwOdQSco-RD8,17121
|
|
16
16
|
lcode/docs/modes.md,sha256=vNQv5K-lk6egNQNlnOHk8YeIdoAsmyaWvSu-RbQeZnQ,34039
|
|
17
|
-
lcode/docs/quickstart.md,sha256=
|
|
17
|
+
lcode/docs/quickstart.md,sha256=ZS9UVhT-i676qYx1SNsUxtgpYXOcsgvJNhhS4VRlqiU,3403
|
|
18
18
|
lcode/docs/sandbox.md,sha256=-_jc2I0LXKQIYCz_JOuHGaP2ehVuEqEepKqMATlFpZY,4064
|
|
19
19
|
lcode/docs/search.md,sha256=UKYrYG_xo67-bOLU1hLgiiTh3Dy6s9LG4nuc2JTQHa8,4249
|
|
20
20
|
lcode/docs/servers.md,sha256=0ddumHseQXx0CP0nqzgwV-493s81kdEBa6qtUYe9t6k,5718
|
|
21
21
|
lcode/docs/troubleshooting.md,sha256=_jOxj5Aq_yCUiifBkhuW4jXM34jBQ5Hir8Rjzm0cGqI,5527
|
|
22
|
-
lcode/docs/usage.md,sha256=
|
|
23
|
-
lcode/__init__.py,sha256=
|
|
22
|
+
lcode/docs/usage.md,sha256=aPf2rEar0nusiPByHclGK_oh8wsGgVljOzmVCRpXcT8,47409
|
|
23
|
+
lcode/__init__.py,sha256=CTMlPsUHkJ3li9CzhASQ0_9ASJ5MV6Jp2xXvGIq0wJs,473
|
|
24
24
|
lcode/__main__.py,sha256=s5N5pryX2FAu93GGZ3FxUrIXHWGzxz66lKUoaV_h8Ws,35
|
|
25
25
|
lcode/acp.py,sha256=eFNYdJNJd9tdCbF2UIj1N3UU4RnF2-pcMLA0KBYZbwE,29082
|
|
26
26
|
lcode/action.py,sha256=wuT5F9EJCdEligPeytzmEi8FpahWBhXer528tpuTj_k,16711
|
|
27
|
-
lcode/agent.py,sha256=
|
|
28
|
-
lcode/api.py,sha256=
|
|
27
|
+
lcode/agent.py,sha256=1cbgarpFf1y6GDG8Kra3d2m39hqTe_5x8NuYg3935Cw,90792
|
|
28
|
+
lcode/api.py,sha256=hev8Z_EACX5gVB3A1gYtdekiRHytLr05zKYk3R5cAtA,17840
|
|
29
29
|
lcode/assistant.py,sha256=zEj6Pt771154xokyy4Xq9cII03lrIjFnCVcc423QyEY,8032
|
|
30
30
|
lcode/backends.py,sha256=343alwyDZin-bEhb5-Es4f8ek1oBQUzEvV6RFWR1VZo,21160
|
|
31
31
|
lcode/bench.py,sha256=HxeUfy9Kv_0Rug1HAlDLyHYfYd9dw2bMgbXsvUy9nd4,43096
|
|
@@ -34,12 +34,12 @@ lcode/bench_runtime.py,sha256=EjzNgIvUkdbT8cbSy1TpmlyeIk6e-ipjlDFpM7Dnqx0,6835
|
|
|
34
34
|
lcode/catalog.py,sha256=pZ1azX9OH2r4JE2c6E5OfwywpgS39-W2oXzoCHJhmtM,4141
|
|
35
35
|
lcode/checkpoints.py,sha256=eqPtmPe44-aweWqc2H21ROogwzIt3NpvcUobsaCHoGY,18354
|
|
36
36
|
lcode/checks.py,sha256=haYYIPhadKavGYEhh8YWAaWrPMcfzrpT2i6638f4xjQ,12933
|
|
37
|
-
lcode/cli.py,sha256=
|
|
37
|
+
lcode/cli.py,sha256=oPzML6tHKKnNOwsPiVo9DgO8PawxAGnAg_83eROWF54,52158
|
|
38
38
|
lcode/clipboard.py,sha256=nTSdJyCXPdtjH947RjvB3QvRqnL5HZsS9KB8EkC42cc,5138
|
|
39
39
|
lcode/cloud.py,sha256=q5Dl5GuqWvKzBCIso-eh6yomvEOsnQ0LW8ZgaAGwBxc,2131
|
|
40
40
|
lcode/codesearch.py,sha256=Io8leN1nb_Y-Dvlm9xaGtwUWYXX-ooswuznJV6dGU1s,10766
|
|
41
41
|
lcode/comfy.py,sha256=_pbLVQS_1clsa7awPrxQ7xIOwp5XzyMHPDAagomEswc,26614
|
|
42
|
-
lcode/config.py,sha256=
|
|
42
|
+
lcode/config.py,sha256=31wqWqXJvpB6OqRNfWnZEArSMsMb80xxVtdilgIVEqI,14379
|
|
43
43
|
lcode/context.py,sha256=wgK16ZcNNnq4ngHx0EmtyKHDFTImciGEmtC5NP8tKJQ,20435
|
|
44
44
|
lcode/edits.py,sha256=iYXSbKv4ZfxP12B1ov6-CLEWvR_tWFUdHRQbER3O8d0,13340
|
|
45
45
|
lcode/escalate.py,sha256=f-_6_moPaHi2kLuJw2JtkzvTkCl6DoBQgYBOCYLhunM,15120
|
|
@@ -59,7 +59,7 @@ lcode/media.py,sha256=2__Oy-S2orCVLRhSh-XZVGENrTdtsUVyhq5uG-us5zE,64464
|
|
|
59
59
|
lcode/media.toml,sha256=cvXxmTEmdwQokadYRVCjmTNIXwk3EoV82XGVj_oCFB8,11297
|
|
60
60
|
lcode/media_catalog.py,sha256=hp68dG6MtS8rqgcp3coeA5tS1EAA6ATXZEMbsJhWvsk,15730
|
|
61
61
|
lcode/media_cloud.py,sha256=85CJR-sTKaAgPKfZ4fXBSUEXUg-0srRfe1_BXT7Xyuw,21408
|
|
62
|
-
lcode/memory.py,sha256=
|
|
62
|
+
lcode/memory.py,sha256=uyGNn_yNdvn-ie1vnum25-VNieHyZip7lnzrcIzGNb0,24526
|
|
63
63
|
lcode/models.toml,sha256=lt2G64zzo_Ryxv2ISRSNZoVD_JqCqYqsM01n8WoXGs8,4098
|
|
64
64
|
lcode/modes.py,sha256=Ybn9Pe2JJjOCIsixZpg-AHvB1nUMckNEiDKGHBLFXjA,5190
|
|
65
65
|
lcode/notify.py,sha256=uieDeXe7XwuVHjOk4tqVyZEW_85XWkoWQmFOWEf77oc,1538
|
|
@@ -69,14 +69,15 @@ lcode/planning.py,sha256=a0rjnj57qwlxqremFgfDGCNgKO-fTKWj36Hj4fBmhbg,6562
|
|
|
69
69
|
lcode/preview.py,sha256=ATzEs6yaI1__bfo2_juWznrTDXUD4QTc_aQMPRCytgA,6253
|
|
70
70
|
lcode/render.py,sha256=gMvf4W3qkLUJ4Vot3az_hP_zRDAItJC9pP-68dHFkfA,1375
|
|
71
71
|
lcode/repeats.py,sha256=2lcH25X4EIbgIfNSYyVczRvKFyKhw_DxEzXOX7lRoY0,5986
|
|
72
|
-
lcode/repl.py,sha256=
|
|
72
|
+
lcode/repl.py,sha256=GOwidDDMWuYai_svAe_xQWXV191XMYbRNGP4I8wl7kw,84623
|
|
73
|
+
lcode/repoid.py,sha256=jLIzr7aD5H0q0R5lu7s1ENo33Qlf_OQ5Vr2Ucrpl8pQ,2685
|
|
73
74
|
lcode/repomap.py,sha256=1GRJgEUjBl9XHSXsF7tSGXBCEgsY-3CzwMohaTudZ_M,13969
|
|
74
75
|
lcode/residency.py,sha256=7a2NYGyHpTm8y4yrcCrDkrtn43vOnE_wg79k9e8dNqY,8484
|
|
75
76
|
lcode/review.py,sha256=0QBIS-R1B2b3zqx5TcC1qZptpKBbrDhYvMKSNCaDAUo,4686
|
|
76
77
|
lcode/sandbox.py,sha256=u_pkrVRXhCGhh-wFDPwuZ3jGG7UeXxXRAeBNsm37ZvE,8608
|
|
77
78
|
lcode/screenshots.py,sha256=pmrw_tp8eXzNyCZa5uot5rTgsxqsi3AdmkGn-XF9saY,57056
|
|
78
79
|
lcode/secretscan.py,sha256=6Euvfk2gCtK7lZbuQD84zgWuSECi6OnSw8V5rFu1tfU,13575
|
|
79
|
-
lcode/sessions.py,sha256=
|
|
80
|
+
lcode/sessions.py,sha256=EvopvWzoLeB_PTSKmWfZ9Rk_graFhYgoRXBgfyHgqg4,8913
|
|
80
81
|
lcode/steer.py,sha256=0vaqLxgRKgC0yGp8xoQfV1f9VEOzH3U4rCIb74eFnZ8,12127
|
|
81
82
|
lcode/subagents.py,sha256=thR2ZzFZ1DeoAf0Ctr_oeKjYajhvd3uRs2kGdw6LlJM,29349
|
|
82
83
|
lcode/tools.py,sha256=XTdtcQe8Bg4GoanVSr8cbgkiFwQ-uqr_HyTT5MHVn9Q,69595
|
|
@@ -112,8 +113,8 @@ lcode/workflows/wan21-vace.json,sha256=vJsiRvLCXCjKIibOO0SGM3fT6bedAGxF8N2sN2vcP
|
|
|
112
113
|
lcode/workflows/wan22-fun-inp-5b.json,sha256=4HbKEezik8MHvxTMP6PjQUPQPfCeSu10U9FrC-DHKYw,3327
|
|
113
114
|
lcode/workflows/wan22-ti2v-5b.json,sha256=RcTehoC2pNizzlb7Ed3keJ56DiE7V5lhXmsvR2Y0smQ,3371
|
|
114
115
|
lcode/workflows/z-image-turbo-t2i.json,sha256=sHsL7xnnuULOuWGYlQrDl4jOTySdAmb2T82c_cChv0s,1585
|
|
115
|
-
lcode_cli-0.
|
|
116
|
-
lcode_cli-0.
|
|
117
|
-
lcode_cli-0.
|
|
118
|
-
lcode_cli-0.
|
|
119
|
-
lcode_cli-0.
|
|
116
|
+
lcode_cli-0.52.0.dist-info/METADATA,sha256=lJGOC0u7o_AIFuCYoV6FdqaCwfnZaDpVsWCbVirPKTQ,13915
|
|
117
|
+
lcode_cli-0.52.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
118
|
+
lcode_cli-0.52.0.dist-info/entry_points.txt,sha256=Hxsn_itbnbgft3U0FwxWdmEt0yoAV2LB-nJDnL9WT20,172
|
|
119
|
+
lcode_cli-0.52.0.dist-info/licenses/LICENSE,sha256=JWjmoL7nNIC1XUa-dZm2hwLUgjUQMFo6k8APb0idNzs,1074
|
|
120
|
+
lcode_cli-0.52.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|