pico-cli 0.1.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.
pico/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """pico meta-package: all code lives in the workspace members.
2
+
3
+ ``pico_ai``, ``pico_core``, ``pico_sdk``, and ``pico_tui`` (under
4
+ ``packages/``) provide the implementation; this dist only carries the
5
+ dependency pins and the ``picoCLI`` / ``picoCLI-chat`` entry points.
6
+ """
@@ -0,0 +1,236 @@
1
+ Metadata-Version: 2.5
2
+ Name: pico-cli
3
+ Version: 0.1.0
4
+ Summary: A Python CLI coding agent — autonomous, tool-using, and session-persistent.
5
+ Project-URL: Homepage, https://github.com/Arya-Ojha/PicoCLI_Learn
6
+ Project-URL: Repository, https://github.com/Arya-Ojha/PicoCLI_Learn
7
+ Project-URL: Issues, https://github.com/Arya-Ojha/PicoCLI_Learn/issues
8
+ Author-email: Arya-Ojha <aryaojha195@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai-agent,cli,coding-assistant,llm,tui
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Utilities
21
+ Requires-Python: >=3.12
22
+ Requires-Dist: pico-cli-sdk
23
+ Requires-Dist: pico-tui
24
+ Description-Content-Type: text/markdown
25
+
26
+ # pico
27
+
28
+ A Python CLI coding agent — autonomous, tool-using, and session-persistent. Inspired by Pi's modular, plugin-driven architecture.
29
+
30
+ `pico` operates on a repository on your behalf: reading, writing, and editing files, and running bash commands to build, test, and inspect the code. It runs in **yolo mode** (acts on its own without per-step approval), keeps an append-only, branchable session history, and automatically compacts context to stay within the model's token budget.
31
+
32
+ ```text
33
+ pico_ai ─► pico_core ─► pico_sdk ─► pico_tui
34
+ (LLM) (agent (library (terminal UI)
35
+ loop/session) API)
36
+ ```
37
+
38
+ ## Features
39
+
40
+ - **Headless CLI** — `picoCLI run "do a task"` completes a coding task end-to-end with a single prompt.
41
+ - **Interactive TUI** — `picoCLI-chat` is a full terminal UI (Textual + Rich) for back-and-forth sessions.
42
+ - **Status bar** — the bottom bar always shows `provider | model`, a `thinking` indicator while streaming, and a color-coded context-window bar (`green < 70%`, `yellow < 90%`, `red ≥ 90%`) with the live token estimate.
43
+ - **Nine hardcoded core tools** — `read`, `write`, `edit`, `grep`, `fetch`, `websearch`, `bash`, `todo`, and `task` (see ADR-0003, ADR-0005).
44
+ - **Todo tracking** — the agent tracks multi-step work with a `todo` tool (add / update / list / clear); the TUI shows the in-memory list in a read-only side panel that appears once the first todo exists. A run only ends once every todo is completed — stopping early nudges the agent back in. When the run ends clean, the list is cleared for the next run (a run stopped by the stuck-model guard keeps its open todos).
45
+ - **Sub-agents** — the model delegates self-contained work via the `task` tool; each child runs isolated with its own session file, fresh todos, and restricted tools (overridable per spawn, never escalating past the parent), returning only a summary. Pure-delegation turns fan out in parallel; nesting is bounded (see ADR-0005).
46
+ - **One-way LLM gateway** — every provider is reached through one unified streaming "AI call" shape. Responses stream token-by-token.
47
+ - **Six native providers** — OpenRouter, OpenAI, Anthropic, Gemini, DeepSeek, and local Ollama, each a one-file adapter (`pico_ai/providers/`) normalizing to the same event shape. Switch with `/provider` (picker + per-provider setup form for API key, URL, model) or `--provider` (see ADR-0004).
48
+ - **Reasoning & usage** — thinking blocks stream live, then collapse to one clickable line (click to expand); token counts are estimated continuously for the status bar and compaction.
49
+ - **Filterable pickers** — `/history`, `/model`, `/provider`, and `/skills` all open modal pickers with a filter bar: type to narrow (case-insensitive substring), `↑/↓` to move, `Enter` to pick, `Esc` to cancel.
50
+ - **Session tree** — sessions are persisted as append-only trees of nodes; you can resume, rewind, and fork branches.
51
+ - **Auto-compaction** — context is summarised automatically at a token threshold, plus a manual override.
52
+ - **Curated extensions** — observe-only hooks (`session_start`, `pre_tool_use`, `post_tool_use`, `post_tool_failure`) and model-invoked `SKILL.md` skills from `~/.pico/skills/` + `~/.agents/skills/`; permission gating via `allowed_tools` (see ADR-0003).
53
+ - **Yolo mode** — no approval prompts: it self-corrects by looping between streaming and tool execution.
54
+
55
+ ## Packages
56
+
57
+ | Package | Responsibility | ADR |
58
+ |---|---|---|
59
+ | `pico_ai` | LLM abstraction; unified "AI call" + per-provider adapters | ADR-0001, ADR-0004 |
60
+ | `pico_core` | The finite-state-machine agent loop + append-only session tree | ADR-0001, ADR-0002 |
61
+ | `pico_sdk` | The headless `AgentSession` API + curated hooks/skills | ADR-0001, ADR-0003 |
62
+ | `pico_tui` | The interactive terminal UI (Textual + Rich) | ADR-0001 |
63
+
64
+ Dependencies flow one way — `pico_ai` ← `pico_core` ← `pico_sdk` ← `pico_tui` (see [ADR-0001](docs/adr/0001-monorepo-package-split.md)). Sessions are a tree of immutable, append-only nodes (see [ADR-0002](docs/adr/0002-tree-based-session.md)).
65
+
66
+ ## Requirements
67
+
68
+ - Python **3.12+**
69
+ - [uv](https://docs.astral.sh/uv/) (workspace + dev tooling)
70
+ - An API key for your provider (or a local Ollama server — no key needed)
71
+
72
+ ## Providers
73
+
74
+ | Provider | Default env var | Notes |
75
+ |---|---|---|
76
+ | OpenRouter (default) | `OPENROUTER_API_KEY` | Many models through one gateway; `openrouter/free` auto-resolves |
77
+ | OpenAI | `OPENAI_API_KEY` | GPT models |
78
+ | Anthropic | `ANTHROPIC_API_KEY` | Claude models; model list is curated (`/model <id>` for newer ones) |
79
+ | Gemini | `GOOGLE_API_KEY` | Google AI Studio |
80
+ | DeepSeek | `DEEPSEEK_API_KEY` | Chat + reasoner (reasoning streams as thinking blocks) |
81
+ | Ollama | — | Local server (`OLLAMA_HOST`, default `http://localhost:11434`) |
82
+
83
+ In the TUI, `/provider` opens a picker with ✓/✗ setup status, then a setup form for that provider's API key, base URL, model, and extras. Only changed values are stored (in `settings.json` — prefer env vars on shared machines); blanks fall back to env/defaults. Effective precedence: field default < environment < stored value. Switching providers resets the model to that provider's stored/default model. Headless: `picoCLI run --provider ollama "..."`.
84
+
85
+ ## Installation
86
+
87
+ ```bash
88
+ uv sync
89
+ ```
90
+
91
+ ## Configuration
92
+
93
+ ### 1. Set your API key
94
+
95
+ The CLI reads the key from an environment variable (default `OPENROUTER_API_KEY`):
96
+
97
+ ```powershell
98
+ # temporary (current shell)
99
+ $env:OPENROUTER_API_KEY = "sk-or-v1-..."
100
+
101
+ # persistent (Windows, survives new shells)
102
+ setx OPENROUTER_API_KEY "sk-or-v1-..."
103
+ ```
104
+
105
+ ### 2. Optional `settings.json`
106
+
107
+ Create `~/.pico/settings.json` to override defaults:
108
+
109
+ ```json
110
+ {
111
+ "model": "openrouter/free",
112
+ "context_window": 128000,
113
+ "reserve_tokens": 16384,
114
+ "session_dir": "~/.pico/sessions",
115
+ "api_key_env": "OPENROUTER_API_KEY",
116
+ "provider": "openrouter",
117
+ "providers": {},
118
+ "skills_dir": "~/.pico/skills",
119
+ "allowed_tools": null
120
+ }
121
+ ```
122
+
123
+ `provider` is the active backend id; `providers` holds per-provider stored values (e.g. `{"openai": {"api_key": "sk-..."}}`) — only changed form values are stored, blanks fall back to env/defaults. `openrouter/free` is an alias: at startup it resolves to the first alphabetically-sorted free model with tool support.
124
+
125
+ ## Usage
126
+
127
+ ### Headless runs
128
+
129
+ ```bash
130
+ # complete a task in one shot
131
+ uv run picoCLI run "explain what this repo does"
132
+
133
+ # let the agent run shell commands (bash is on by default)
134
+ uv run picoCLI run "run the tests and fix failures"
135
+
136
+ # work in another directory, pick a model
137
+ uv run picoCLI run "summarize this code" --cwd D:\some\repo --model openai/gpt-4o-mini
138
+
139
+ # resume a previous session by id
140
+ uv run picoCLI run "continue" --session <session-id>
141
+
142
+ # compact a session headlessly (with optional steering text)
143
+ uv run picoCLI run "/compact focus on the auth refactor"
144
+ ```
145
+
146
+ Flags for `picoCLI run`:
147
+
148
+ | Flag | Purpose |
149
+ |---|---|
150
+ | `--no-bash` | Disable unsandboxed bash execution (on by default; ignored when `allowed_tools` is set without `bash`) |
151
+ | `--provider <id>` | Provider id (`openrouter`, `openai`, `anthropic`, `gemini`, `deepseek`, `ollama`) |
152
+ | `--allow-tools <csv>` | Tool allowlist, e.g. `--allow-tools read,grep,bash` (overrides `settings.allowed_tools`) |
153
+ | `--skills-dir <path>` | Override the configured skills directory |
154
+ | `--no-skills` | Disable `SKILL.md` loading |
155
+ | `--model <name>` | Override the configured model |
156
+ | `--cwd <path>` | Set the working directory |
157
+ | `--session <id>` | Resume an existing session |
158
+
159
+ ### Interactive TUI
160
+
161
+ ```bash
162
+ uv run picoCLI-chat
163
+ ```
164
+
165
+ `picoCLI-chat` shares the same flags. Inside the prompt you can type a message or use:
166
+
167
+ | Slash command | Key | Action |
168
+ |---|---|---|
169
+ | `/help` | `F1` | Show help |
170
+ | `/history` | `Ctrl+H` | Browse session nodes — pick one to jump to (forks the session) |
171
+ | `/compact [text]` | `Ctrl+K` | Compact context (optionally with steering text) |
172
+ | `/model [name]` | — | Change model (`/model` alone opens the interactive model picker; persists to `settings.json`) |
173
+ | `/skills` | — | Pick a loaded `SKILL.md` skill — inserts it into the input bar |
174
+ | `/provider [id]` | — | Pick the LLM provider, then fill its setup form (key, URL, model) |
175
+ | `/fork <n or id>` | — | Rewind to a node and start a new branch |
176
+ | `/undo` | `Ctrl+Z` | Rewind to the previous user turn |
177
+ | `/quit` | `Ctrl+Q` | Save the session and exit (`/exit`, `/q` also work) |
178
+
179
+ Every picker has a filter bar at the top — typing narrows the list; `Enter` picks the highlighted row. Tool activity is rendered inline — bash commands echoed before running (green), and tool calls/results shown as color-coded panels (`read` blue, `write` yellow, `edit` magenta, `bash` green, `todo` cyan). `todo` calls stay hidden (only the `todo` result shows); thinking blocks stream in full then collapse to one `💭 thinking: …` line, and bash results collapse to a one-line success/error — click either to expand. Failed tool calls (denied, unknown, or errored) render with a red border so permission gating is visible. The agent's todos also appear in a read-only panel on the right side of the chat while any exist.
180
+
181
+ ## Skills & permissions
182
+
183
+ Skills are model-invoked `SKILL.md` files — knowledge only, no code execution. Each skill is a directory with a `SKILL.md` (optional `name`/`description` frontmatter + markdown instructions):
184
+
185
+ ```
186
+ ~/.pico/skills/commit-helper/SKILL.md # global
187
+ ~/.agents/skills/commit-helper/SKILL.md # shared (e.g. opencode/Matt Pocock), also loaded
188
+ <project>/.pico/skills/commit-helper/SKILL.md # project-local, wins on name conflicts
189
+ ```
190
+
191
+ ```markdown
192
+ ---
193
+ name: commit-helper
194
+ description: Use when the user wants to commit code.
195
+ ---
196
+ Run `git status` first, then ...
197
+ ```
198
+
199
+ All discovered skills (alphabetical, no cap) are inlined into the system prompt. List them with `/skills` in the TUI, or disable with `--no-skills` / `--skills-dir <path>`.
200
+
201
+ Permission gating via `allowed_tools` in `settings.json` (`null` = all tools, `[]` = none) or `--allow-tools read,grep,bash`. Denied tools return an `error: tool not allowed` result the model can react to. When `allowed_tools` is set it wins over `--no-bash`; otherwise `--no-bash` disables bash.
202
+
203
+ ## Where sessions live
204
+
205
+ Sessions are persisted as JSONL under `~/.pico/sessions/<id>.jsonl` by default (configurable via `session_dir`). Both `picoCLI run` and `picoCLI-chat` accept `--session <id>` to resume; `/history`, `/fork`, and `/undo` rewind within the tree without deleting nodes.
206
+
207
+ ## Development
208
+
209
+ ```bash
210
+ # run all tests
211
+ uv run pytest
212
+
213
+ # typecheck every package
214
+ uv run mypy packages/pico_ai/src packages/pico_core/src packages/pico_sdk/src packages/pico_tui/src src/pico
215
+
216
+ # build all wheels into dist/ (root `pico-cli` is a meta-package: deps + entry points only)
217
+ uv build --package pico-cli --out-dir dist
218
+ uv build --package pico-ai --out-dir dist
219
+ uv build --package pico-core --out-dir dist
220
+ uv build --package pico-cli-sdk --out-dir dist
221
+ uv build --package pico-tui --out-dir dist
222
+ ```
223
+
224
+ The test suite is network-free: it drives the whole agent loop through a scripted fake provider (`FakeProvider`) and a temporary filesystem, exercising `pico_ai`, `pico_core`, `pico_sdk`, and `pico_tui`.
225
+
226
+ ## Domain vocabulary
227
+
228
+ See [CONTEXT.md](CONTEXT.md) for the full glossary. Key terms: **session**, **node**, **payload**, **branch**, **fork**, **turn**, **tool** / **tool request** / **tool result**, **sub-agent**, **compaction**, **context window**,
229
+ **provider**, **AI call**, **hook**, **skill**.
230
+
231
+ ## Documentation
232
+
233
+ - [Domain guide for agents](docs/agents/domain.md)
234
+ - [Architecture decision records](docs/adr/)
235
+ - [Issue-tracker conventions](docs/agents/issue-tracker.md)
236
+ - Milestone specs: [headless agent](.scratch/headless-agent/spec.md), [terminal UI](.scratch/pico-tui/spec.md)
@@ -0,0 +1,6 @@
1
+ pico/__init__.py,sha256=9hhK0TLzqQo1Y1aXk-s_2ZAFEm5caHdyuJrXOgZK7ic,273
2
+ pico_cli-0.1.0.dist-info/METADATA,sha256=RNRruhFq1JZh6AqJv0wRvybBcyzQAtLV2iwfOABPjDc,12871
3
+ pico_cli-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
4
+ pico_cli-0.1.0.dist-info/entry_points.txt,sha256=SByEBr3WGlHEA_lEPgUwxUsbXIAsEqZVQn_z8Ln2TGg,79
5
+ pico_cli-0.1.0.dist-info/licenses/LICENSE,sha256=Wy2OlwvFJAICj262iKAJ22esh6iMjTfvQrOpP1GIlwQ,1066
6
+ pico_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ picoCLI = pico_sdk.cli:main
3
+ picoCLI-chat = pico_tui.app:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arya-Ojha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.