swarph-cli 0.1.1__tar.gz → 0.3.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.
Files changed (28) hide show
  1. swarph_cli-0.3.0/PKG-INFO +184 -0
  2. swarph_cli-0.3.0/README.md +152 -0
  3. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/pyproject.toml +5 -3
  4. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/src/swarph_cli/__init__.py +1 -1
  5. swarph_cli-0.3.0/src/swarph_cli/commands/__init__.py +15 -0
  6. swarph_cli-0.3.0/src/swarph_cli/commands/chat.py +348 -0
  7. swarph_cli-0.3.0/src/swarph_cli/commands/import_session.py +232 -0
  8. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/src/swarph_cli/main.py +58 -21
  9. swarph_cli-0.3.0/src/swarph_cli/parsers/__init__.py +27 -0
  10. swarph_cli-0.3.0/src/swarph_cli/parsers/claude.py +340 -0
  11. swarph_cli-0.3.0/src/swarph_cli.egg-info/PKG-INFO +184 -0
  12. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/src/swarph_cli.egg-info/SOURCES.txt +9 -0
  13. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/src/swarph_cli.egg-info/requires.txt +1 -1
  14. swarph_cli-0.3.0/tests/test_chat_command.py +444 -0
  15. swarph_cli-0.3.0/tests/test_claude_parser.py +332 -0
  16. swarph_cli-0.3.0/tests/test_import_command.py +288 -0
  17. swarph_cli-0.3.0/tests/test_smoke_chat.py +61 -0
  18. swarph_cli-0.1.1/PKG-INFO +0 -108
  19. swarph_cli-0.1.1/README.md +0 -76
  20. swarph_cli-0.1.1/src/swarph_cli.egg-info/PKG-INFO +0 -108
  21. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/LICENSE +0 -0
  22. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/setup.cfg +0 -0
  23. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/src/swarph_cli/caller.py +0 -0
  24. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/src/swarph_cli.egg-info/dependency_links.txt +0 -0
  25. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/src/swarph_cli.egg-info/entry_points.txt +0 -0
  26. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/src/swarph_cli.egg-info/top_level.txt +0 -0
  27. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/tests/test_main.py +0 -0
  28. {swarph_cli-0.1.1 → swarph_cli-0.3.0}/tests/test_smoke_one_shot.py +0 -0
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarph-cli
3
+ Version: 0.3.0
4
+ Summary: The `swarph` binary — multi-LLM CLI with mesh-gateway integration. v0.3.0 ships the Phase 5 `swarph chat` REPL on top of Phase 2 one-shot + Phase 2.5 import (PLAN.md §13).
5
+ Author: Pierre Samson, Claude Opus
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/darw007d/swarph-cli
8
+ Project-URL: Source, https://github.com/darw007d/swarph-cli
9
+ Project-URL: Substrate, https://github.com/darw007d/swarph-mesh
10
+ Project-URL: Spec, https://github.com/darw007d/hedge-fund-mcp/blob/main/research/swarph_cli/PLAN.md
11
+ Keywords: swarph,llm,cli,mesh,gemini,claude,deepseek
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Topic :: Utilities
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: swarph-mesh>=0.5.0
28
+ Requires-Dist: swarph-shared>=0.2.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # swarph-cli
34
+
35
+ The `swarph` binary — multi-LLM CLI with mesh-gateway integration. Thin client over the [`swarph-mesh`](https://github.com/darw007d/swarph-mesh) substrate.
36
+
37
+ ```bash
38
+ pip install swarph-cli
39
+ swarph --version
40
+ ```
41
+
42
+ This is one of three repos in the v0.3.x architecture:
43
+
44
+ | Repo | Role |
45
+ |---|---|
46
+ | [`swarph-mesh`](https://github.com/darw007d/swarph-mesh) | Substrate Python package — Protocol + adapters + SwarphCall + MeshClient. Pure library, no CLI |
47
+ | [`swarph-cli`](https://github.com/darw007d/swarph-cli) | This repo — the `swarph` binary |
48
+ | [`swarph-meshlm`](https://github.com/darw007d/swarph-meshlm) | Simon Willison `llm` plugin |
49
+
50
+ ## Status
51
+
52
+ **v0.3.0 — Phase 2 one-shot + Phase 2.5 import + Phase 5 REPL.** Three verbs ship:
53
+
54
+ 1. `swarph "prompt"` — Phase 2 one-shot mode (any of five providers)
55
+ 2. `swarph chat` — Phase 5 interactive REPL with multi-turn history + slash commands
56
+ 3. `swarph import <path>` — Phase 2.5 session import (Claude JSONL → swarph-native, with `--report-only` for honest pre-commit inspection)
57
+
58
+ Subsequent phases extend the CLI surface (`--ask <peer>`, onboard/ratify, daemon, additional source formats).
59
+
60
+ ### `swarph chat`
61
+
62
+ Interactive REPL against any of the five swarph-mesh adapters (`gemini` / `deepseek` / `claude` / `openai` / `grok`). Multi-turn conversation history accumulates in-memory; cumulative session cost + token totals tracked.
63
+
64
+ ```bash
65
+ $ swarph chat --provider claude
66
+ swarph chat — Phase 5 REPL
67
+ provider=claude model=(adapter default) caller=cli.repl.ubuntu
68
+
69
+ Type a message and press Enter to send. Slash commands:
70
+ /help /clear /system /provider /model /history /cost /quit
71
+ Ctrl-D to exit.
72
+
73
+ > hello
74
+ Hi! How can I help...
75
+ # 8+12t $0 0.34s
76
+
77
+ > /provider gemini
78
+ [switched to provider=gemini; model reset to adapter default; history cleared]
79
+
80
+ > /cost
81
+ [turns=1 in=8 out=12 cost=$0]
82
+
83
+ > /quit
84
+ [swarph-chat] bye.
85
+ ```
86
+
87
+ **Slash commands:**
88
+ - `/help` — print available commands
89
+ - `/quit`, `/exit` (or Ctrl-D) — exit
90
+ - `/clear`, `/reset` — clear history (keeps system prompt)
91
+ - `/system [prompt]` — set or clear system prompt
92
+ - `/provider <name>` — switch provider (resets history)
93
+ - `/model <name>` — switch model
94
+ - `/history` — print running message list
95
+ - `/cost` — cumulative session cost + tokens
96
+
97
+ **Out of scope until Phase 5.6** (`swarph daemon`): inbox drain coroutine, `/inbox` and `/reply` slash commands. Streaming output ships alongside the cross-adapter `stream()` work in v0.5+ of swarph-mesh.
98
+
99
+ ### `swarph import`
100
+
101
+ Per PLAN.md §17, session import is the **knowledge half of onboarding** — gives a memory-carrying peer (or human migrating CLIs) the substantive context they're bringing into the swarph, paired with §15's contract half (handshake DM acknowledging the four invariants).
102
+
103
+ ```bash
104
+ # Inspect what would be imported (lossy → honest framing)
105
+ $ swarph import ~/.claude/projects/.../X.jsonl --report-only
106
+
107
+ # Commit — writes ~/.swarph/sessions/<session-id>.jsonl
108
+ $ swarph import ~/.claude/projects/.../X.jsonl
109
+
110
+ # Refuse-with-error if target exists (protects continuation turns)
111
+ $ swarph import same-source.jsonl
112
+ swarph import: target /home/.../X.jsonl already exists (...)
113
+ To proceed:
114
+ --force overwrite (destroys continuation turns)
115
+ --target-session NAME write to a different file
116
+ ```
117
+
118
+ **What ports cleanly:** plain user/assistant/system text, role tags, conversation order.
119
+
120
+ **What's lossy** (counted in report, kept as visible text where possible):
121
+ - `thinking` blocks (Anthropic-specific reasoning trace)
122
+ - `tool_use` blocks (call shape doesn't port across providers)
123
+ - `tool_result` blocks (companion drop with `tool_use`)
124
+
125
+ **What's dropped:** attachments (would need re-upload), provider-side KV cache, conversation IDs, `cache_control` annotations.
126
+
127
+ Honest framing per PLAN.md §17.3: **teleport is "import + continue", not "freeze and resume"** — the first turn after import on a new provider pays cold-cache cost. Phase 5+ adds `--continue` for live REPL integration.
128
+
129
+ ```bash
130
+ $ swarph "say pong" --provider gemini
131
+ Pong!
132
+ # 3+26t $0.0000 0.73s caller=cli.oneshot.ubuntu provider=gemini
133
+ ```
134
+
135
+ ### `--json` mode semantics
136
+
137
+ `--json` is a **harness trigger**, not a strict-validation gate. When set, swarph routes the response through the swarph-mesh JSON harness:
138
+
139
+ - A permissive `{"type": "object"}` schema is synthesised when `--schema` is absent (Phase 5+ adds Pydantic validation).
140
+ - The harness retries once with `[USER]`-turn feedback on parse failure.
141
+ - **Malformed-JSON exits with code 1** + raw text on stdout for caller recovery. Useful for shell scripts:
142
+ ```bash
143
+ if swarph "give me a trade" --json; then
144
+ # parsed dict was on stdout
145
+ ...
146
+ fi
147
+ ```
148
+ - Pretty-printed parsed dict on stdout when parse succeeds; `error_class=malformed_json` shows up in the stderr attribution footer when it doesn't.
149
+
150
+ ## Spec
151
+
152
+ → [hedge-fund-mcp / research/swarph_cli/PLAN.md](https://github.com/darw007d/hedge-fund-mcp/blob/main/research/swarph_cli/PLAN.md)
153
+
154
+ ## Phase rollout
155
+
156
+ | Phase | What lands |
157
+ |---|---|
158
+ | **0** | Scaffold — entry-point + status banner |
159
+ | **2** (v0.1.0) | One-shot mode: `swarph "hello" --provider gemini` |
160
+ | **2.5** (v0.2.0) | `swarph import` — Claude JSONL → swarph-native session format |
161
+ | **5** (v0.3.0 — this release) | **`swarph chat` interactive REPL** — multi-turn against any of five adapters + slash commands (`/help`, `/clear`, `/system`, `/provider`, `/model`, `/history`, `/cost`, `/quit`) |
162
+ | **3** | `--ask <peer>` mesh-aware one-shot via MeshClient |
163
+ | **5.5** | `swarph onboard <peer-name>` + `swarph ratify <peer-name>` (PLAN.md §15) |
164
+ | **5.6** | `swarph daemon` foreground drain loop + REPL drain coroutine + `/inbox`, `/reply` (PLAN.md §16) |
165
+ | **6** | (already done) PyPI publish |
166
+
167
+ ## Why split CLI from substrate
168
+
169
+ `swarph-mesh` (the library) is imported by `omega-boss`, Council judges, `lab-orchestrator`, and any future swarph peer that wants to write programs against the Protocol. Those callers don't need the CLI surface or the console-script entry point. Keeping the CLI in a separate repo means library users `pip install swarph-mesh` without pulling argparse + REPL plumbing they'll never run.
170
+
171
+ ## Install (dev)
172
+
173
+ ```bash
174
+ git clone https://github.com/darw007d/swarph-cli
175
+ cd swarph-cli
176
+ python -m venv venv && source venv/bin/activate
177
+ pip install -e ".[dev]"
178
+ pytest
179
+ swarph --version
180
+ ```
181
+
182
+ ## License
183
+
184
+ MIT. Pierre Samson + Claude Opus, 2026.
@@ -0,0 +1,152 @@
1
+ # swarph-cli
2
+
3
+ The `swarph` binary — multi-LLM CLI with mesh-gateway integration. Thin client over the [`swarph-mesh`](https://github.com/darw007d/swarph-mesh) substrate.
4
+
5
+ ```bash
6
+ pip install swarph-cli
7
+ swarph --version
8
+ ```
9
+
10
+ This is one of three repos in the v0.3.x architecture:
11
+
12
+ | Repo | Role |
13
+ |---|---|
14
+ | [`swarph-mesh`](https://github.com/darw007d/swarph-mesh) | Substrate Python package — Protocol + adapters + SwarphCall + MeshClient. Pure library, no CLI |
15
+ | [`swarph-cli`](https://github.com/darw007d/swarph-cli) | This repo — the `swarph` binary |
16
+ | [`swarph-meshlm`](https://github.com/darw007d/swarph-meshlm) | Simon Willison `llm` plugin |
17
+
18
+ ## Status
19
+
20
+ **v0.3.0 — Phase 2 one-shot + Phase 2.5 import + Phase 5 REPL.** Three verbs ship:
21
+
22
+ 1. `swarph "prompt"` — Phase 2 one-shot mode (any of five providers)
23
+ 2. `swarph chat` — Phase 5 interactive REPL with multi-turn history + slash commands
24
+ 3. `swarph import <path>` — Phase 2.5 session import (Claude JSONL → swarph-native, with `--report-only` for honest pre-commit inspection)
25
+
26
+ Subsequent phases extend the CLI surface (`--ask <peer>`, onboard/ratify, daemon, additional source formats).
27
+
28
+ ### `swarph chat`
29
+
30
+ Interactive REPL against any of the five swarph-mesh adapters (`gemini` / `deepseek` / `claude` / `openai` / `grok`). Multi-turn conversation history accumulates in-memory; cumulative session cost + token totals tracked.
31
+
32
+ ```bash
33
+ $ swarph chat --provider claude
34
+ swarph chat — Phase 5 REPL
35
+ provider=claude model=(adapter default) caller=cli.repl.ubuntu
36
+
37
+ Type a message and press Enter to send. Slash commands:
38
+ /help /clear /system /provider /model /history /cost /quit
39
+ Ctrl-D to exit.
40
+
41
+ > hello
42
+ Hi! How can I help...
43
+ # 8+12t $0 0.34s
44
+
45
+ > /provider gemini
46
+ [switched to provider=gemini; model reset to adapter default; history cleared]
47
+
48
+ > /cost
49
+ [turns=1 in=8 out=12 cost=$0]
50
+
51
+ > /quit
52
+ [swarph-chat] bye.
53
+ ```
54
+
55
+ **Slash commands:**
56
+ - `/help` — print available commands
57
+ - `/quit`, `/exit` (or Ctrl-D) — exit
58
+ - `/clear`, `/reset` — clear history (keeps system prompt)
59
+ - `/system [prompt]` — set or clear system prompt
60
+ - `/provider <name>` — switch provider (resets history)
61
+ - `/model <name>` — switch model
62
+ - `/history` — print running message list
63
+ - `/cost` — cumulative session cost + tokens
64
+
65
+ **Out of scope until Phase 5.6** (`swarph daemon`): inbox drain coroutine, `/inbox` and `/reply` slash commands. Streaming output ships alongside the cross-adapter `stream()` work in v0.5+ of swarph-mesh.
66
+
67
+ ### `swarph import`
68
+
69
+ Per PLAN.md §17, session import is the **knowledge half of onboarding** — gives a memory-carrying peer (or human migrating CLIs) the substantive context they're bringing into the swarph, paired with §15's contract half (handshake DM acknowledging the four invariants).
70
+
71
+ ```bash
72
+ # Inspect what would be imported (lossy → honest framing)
73
+ $ swarph import ~/.claude/projects/.../X.jsonl --report-only
74
+
75
+ # Commit — writes ~/.swarph/sessions/<session-id>.jsonl
76
+ $ swarph import ~/.claude/projects/.../X.jsonl
77
+
78
+ # Refuse-with-error if target exists (protects continuation turns)
79
+ $ swarph import same-source.jsonl
80
+ swarph import: target /home/.../X.jsonl already exists (...)
81
+ To proceed:
82
+ --force overwrite (destroys continuation turns)
83
+ --target-session NAME write to a different file
84
+ ```
85
+
86
+ **What ports cleanly:** plain user/assistant/system text, role tags, conversation order.
87
+
88
+ **What's lossy** (counted in report, kept as visible text where possible):
89
+ - `thinking` blocks (Anthropic-specific reasoning trace)
90
+ - `tool_use` blocks (call shape doesn't port across providers)
91
+ - `tool_result` blocks (companion drop with `tool_use`)
92
+
93
+ **What's dropped:** attachments (would need re-upload), provider-side KV cache, conversation IDs, `cache_control` annotations.
94
+
95
+ Honest framing per PLAN.md §17.3: **teleport is "import + continue", not "freeze and resume"** — the first turn after import on a new provider pays cold-cache cost. Phase 5+ adds `--continue` for live REPL integration.
96
+
97
+ ```bash
98
+ $ swarph "say pong" --provider gemini
99
+ Pong!
100
+ # 3+26t $0.0000 0.73s caller=cli.oneshot.ubuntu provider=gemini
101
+ ```
102
+
103
+ ### `--json` mode semantics
104
+
105
+ `--json` is a **harness trigger**, not a strict-validation gate. When set, swarph routes the response through the swarph-mesh JSON harness:
106
+
107
+ - A permissive `{"type": "object"}` schema is synthesised when `--schema` is absent (Phase 5+ adds Pydantic validation).
108
+ - The harness retries once with `[USER]`-turn feedback on parse failure.
109
+ - **Malformed-JSON exits with code 1** + raw text on stdout for caller recovery. Useful for shell scripts:
110
+ ```bash
111
+ if swarph "give me a trade" --json; then
112
+ # parsed dict was on stdout
113
+ ...
114
+ fi
115
+ ```
116
+ - Pretty-printed parsed dict on stdout when parse succeeds; `error_class=malformed_json` shows up in the stderr attribution footer when it doesn't.
117
+
118
+ ## Spec
119
+
120
+ → [hedge-fund-mcp / research/swarph_cli/PLAN.md](https://github.com/darw007d/hedge-fund-mcp/blob/main/research/swarph_cli/PLAN.md)
121
+
122
+ ## Phase rollout
123
+
124
+ | Phase | What lands |
125
+ |---|---|
126
+ | **0** | Scaffold — entry-point + status banner |
127
+ | **2** (v0.1.0) | One-shot mode: `swarph "hello" --provider gemini` |
128
+ | **2.5** (v0.2.0) | `swarph import` — Claude JSONL → swarph-native session format |
129
+ | **5** (v0.3.0 — this release) | **`swarph chat` interactive REPL** — multi-turn against any of five adapters + slash commands (`/help`, `/clear`, `/system`, `/provider`, `/model`, `/history`, `/cost`, `/quit`) |
130
+ | **3** | `--ask <peer>` mesh-aware one-shot via MeshClient |
131
+ | **5.5** | `swarph onboard <peer-name>` + `swarph ratify <peer-name>` (PLAN.md §15) |
132
+ | **5.6** | `swarph daemon` foreground drain loop + REPL drain coroutine + `/inbox`, `/reply` (PLAN.md §16) |
133
+ | **6** | (already done) PyPI publish |
134
+
135
+ ## Why split CLI from substrate
136
+
137
+ `swarph-mesh` (the library) is imported by `omega-boss`, Council judges, `lab-orchestrator`, and any future swarph peer that wants to write programs against the Protocol. Those callers don't need the CLI surface or the console-script entry point. Keeping the CLI in a separate repo means library users `pip install swarph-mesh` without pulling argparse + REPL plumbing they'll never run.
138
+
139
+ ## Install (dev)
140
+
141
+ ```bash
142
+ git clone https://github.com/darw007d/swarph-cli
143
+ cd swarph-cli
144
+ python -m venv venv && source venv/bin/activate
145
+ pip install -e ".[dev]"
146
+ pytest
147
+ swarph --version
148
+ ```
149
+
150
+ ## License
151
+
152
+ MIT. Pierre Samson + Claude Opus, 2026.
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "swarph-cli"
7
- version = "0.1.1"
8
- description = "The `swarph` binary — multi-LLM CLI with mesh-gateway integration. Phase 2 one-shot mode shipped (PLAN.md §13)."
7
+ version = "0.3.0"
8
+ description = "The `swarph` binary — multi-LLM CLI with mesh-gateway integration. v0.3.0 ships the Phase 5 `swarph chat` REPL on top of Phase 2 one-shot + Phase 2.5 import (PLAN.md §13)."
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
11
11
  requires-python = ">=3.10"
@@ -29,7 +29,9 @@ classifiers = [
29
29
  "Topic :: Utilities",
30
30
  ]
31
31
  dependencies = [
32
- "swarph-mesh>=0.1.0",
32
+ # Phase 5 REPL exercises all five adapters; bumped to 0.5.0 for
33
+ # OpenAI + Grok availability in /provider switch.
34
+ "swarph-mesh>=0.5.0",
33
35
  "swarph-shared>=0.2.0",
34
36
  ]
35
37
 
@@ -16,6 +16,6 @@ The architecture splits CLI from substrate so:
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- __version__ = "0.1.1"
19
+ __version__ = "0.3.0"
20
20
 
21
21
  __all__ = ["__version__"]
@@ -0,0 +1,15 @@
1
+ """Subcommand handlers for ``swarph``.
2
+
3
+ Phase 2.5 ships ``import``. Phase 3+ adds ``--ask`` / ``list-peers``;
4
+ Phase 5+ adds ``chat`` REPL; Phase 5.5 adds ``onboard`` / ``ratify``;
5
+ Phase 5.7 adds ``daemon``.
6
+
7
+ Each handler is a function that takes a list of argv-style argument
8
+ strings (the verb stripped off) and returns an int exit code.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from swarph_cli.commands.import_session import run_import
14
+
15
+ __all__ = ["run_import"]