ctxttools 0.1.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.
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: ctxttools
3
+ Version: 0.1.0
4
+ Summary: CLI tools for LLM conversations
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: typer>=0.9.0
7
+ Requires-Dist: rich>=13.0.0
8
+ Requires-Dist: tiktoken>=0.5.0
9
+ Provides-Extra: mcp
10
+ Requires-Dist: mcp>=1.2.0; extra == "mcp"
11
+ Provides-Extra: dev
12
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
@@ -0,0 +1,163 @@
1
+ # ctools
2
+
3
+ Context tools for LLM conversations. Extracted from [Gab n' Go](https://github.com/day50-dev/gabngo). Named after [GNU mtools](https://www.gnu.org/software/mtools/), which does the same thing for DOS floppies because your context window is about the size of a DOS-floppy. Maybe we can use that for inspiration.
4
+
5
+ ## The Problem
6
+
7
+ You talk to LLMs all day. Over weeks, you build up a set of constraints, preferences, and goals. "Use C17 standard." "Prefer snake_case." "Always check for null returns." These things live in your conversations as system messages. They are valuable. They are also trapped.
8
+
9
+ Say you have been working with opencode for a month. You have refined your coding style through dozens of sessions. Now you start a new Claude Code project and you want those same preferences. You could copy them by hand. Or you could use ctools.
10
+
11
+ ```sh
12
+ ccopy @opencode/ses_abc123 preferences.json
13
+ ccopy preferences.json @claude-code/ses_xyz
14
+ ```
15
+
16
+ Or skip the file entirely:
17
+
18
+ ```sh
19
+ ccopy @opencode/ses_abc123 @claude-code/ses_xyz
20
+ ```
21
+
22
+ The concepts are embedded in your conversations as "Use the following <type>: <text>" messages. ctools reads and writes these. Your context travels with you.
23
+
24
+ | GNU mtools | ctools | Does what |
25
+ |------------|--------|-----------|
26
+ | `mdir` | `cdir` | List sessions |
27
+ | `mcopy` | `ccopy` | Copy concepts |
28
+ | `mdu` | `cdu` | Token usage |
29
+ | `mtype` | `cgrep` | Search content |
30
+
31
+ ## Tools
32
+
33
+ ### ccopy
34
+
35
+ Extract, inject, and copy concepts between sessions and files. The `@` prefix means "this is a session reference." Plain paths are files. Directories get one file per concept.
36
+
37
+ ```sh
38
+ ccopy @opencode/ses_abc123 concepts/ # extract to directory (one file per concept)
39
+ ccopy @opencode/ses_abc123 constraints.json # extract to single file
40
+ ccopy concepts/ @opencode/ses_abc123 # inject all concepts from directory
41
+ ccopy constraints.json @opencode/ses_abc123 # inject from file
42
+ ccopy @opencode/ses_abc123 @claude-code/ses_xyz # session to session
43
+ ccopy --strategy my-strategy.json @opencode/ses_abc123 concepts/ # custom extraction
44
+ ```
45
+
46
+ When you extract to a directory, each concept becomes its own file. This is the core abstraction: the directory *is* the concept set. rm a file to exclude it. cp files in to merge. Edit the json to modify. `git add .` to share.
47
+
48
+ ```sh
49
+ ls concepts/
50
+ constraint_0aa712d89fbb067a.json
51
+ preference_a1b2c3d4e5f6g7h8.json
52
+ observation_x9y8z7w6v5u4t3s2.json
53
+ ```
54
+
55
+ Strategies let you define how concepts are extracted using an LLM. Ontology is contestable, so different strategies produce different chunkings:
56
+
57
+ ```json
58
+ {
59
+ "host": "http://localhost:11434",
60
+ "model": "qwen2.5:3b",
61
+ "api_key": null,
62
+ "prompt": "Extract the key concepts from this conversation..."
63
+ }
64
+ ```
65
+
66
+ ### cdir
67
+
68
+ Lists sessions. Think `ls` for your conversation history.
69
+
70
+ ```sh
71
+ cdir # list all known agents
72
+ cdir opencode/ # sessions for opencode
73
+ cdir claude-code/ # sessions for claude code
74
+ cdir -R # all agents, recursive
75
+ cdir opencode/ses_abc123 # export a session as JSON
76
+ ```
77
+
78
+ Output shows Found/Not Found with actual files when available:
79
+
80
+ ```
81
+ Found:
82
+ Claude Code Claude Code CLI ~/.claude [jsonl]
83
+ Opencode Opencode CLI ~/.local/share/opencode account.json, auth.json, opencode.db
84
+
85
+ Not Found:
86
+ Claude Claude Desktop (Anthropic) ~/.config/Claude [json]
87
+ Codex OpenAI Codex CLI ~/.codex [jsonl]
88
+ ```
89
+
90
+ Sort by time (`-t`), size (`-s`), reverse (`-r`). Output as json, xml, or markdown with `-f`.
91
+
92
+ ### cgrep
93
+
94
+ Searches conversation content. Regex supported. Works across agents.
95
+
96
+ ```sh
97
+ cgrep "pattern" "opencode/*"
98
+ cgrep -i "error" "claude-code/"
99
+ cgrep -c "def " "opencode/" # count per session
100
+ cgrep -C 2 "exception" "claude-code/" # context lines
101
+ cgrep "TODO" "opencode/" "claude-code/" # multiple agents
102
+ ```
103
+
104
+ Flags: `-l` list files, `-c` count, `-v` invert, `-i` case-insensitive, `-A/-B/-C` context.
105
+
106
+ ### cdu
107
+
108
+ Token usage. Like `du` but for context windows. Uses tiktoken for accurate counts.
109
+
110
+ ```sh
111
+ cdu # total across all agents
112
+ cdu opencode/ # sessions by token count
113
+ cdu opencode/ses_abc123 # breakdown by role
114
+ cdu --json opencode/ # machine-readable
115
+ ```
116
+
117
+ For opencode, it reads actual input/output tokens from the database. For other agents, it counts with tiktoken from the conversation content.
118
+
119
+ ## Supported Agents
120
+
121
+ | Agent | Format | Storage |
122
+ |-------|--------|---------|
123
+ | claude | JSON | `~/Library/Application Support/Claude-3p/` |
124
+ | claude-code | JSONL | `~/.claude/` |
125
+ | opencode | SQLite | `~/.local/share/opencode/` |
126
+ | codex | JSONL | `~/.codex/` |
127
+
128
+ ## MCP Server
129
+
130
+ There is an MCP server for use from Claude, opencode, Cursor, or anything else that speaks MCP.
131
+
132
+ Tools: `list_agents`, `list_sessions`, `search_sessions`, `export_session`, `extract_concepts`, `copy_concepts`, `get_session_concepts`.
133
+
134
+ Add to your MCP config:
135
+
136
+ ```json
137
+ {
138
+ "mcpServers": {
139
+ "ctools": {
140
+ "command": "python",
141
+ "args": ["/ABSOLUTE/PATH/TO/ctools/ctools_mcp.py"]
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ## Installation
148
+
149
+ ```sh
150
+ pip install -r requirements.txt
151
+ ```
152
+
153
+ ## Library
154
+
155
+ Works as a Python library too.
156
+
157
+ ```python
158
+ from ctools.lib import AGENTS, get_formatter
159
+ from ctools.cdir import get_opencode_sessions
160
+ from ctools.cgrep import grep_session
161
+ from ctools.ccopy import extract_concepts_from_messages, inject_concepts_to_session
162
+ from ctools.cdu import count_tokens, get_session_tokens
163
+ ```
@@ -0,0 +1,4 @@
1
+ """ctools - CLI tools for LLM context windows.
2
+
3
+ Provides cdir (ls for context windows) and cgrep (grep for context windows).
4
+ """