arkclaw-webchat-cli 0.1.0__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 (30) hide show
  1. arkclaw_webchat_cli-0.3.0/PKG-INFO +197 -0
  2. arkclaw_webchat_cli-0.3.0/README.md +173 -0
  3. {arkclaw_webchat_cli-0.1.0 → arkclaw_webchat_cli-0.3.0}/pyproject.toml +19 -2
  4. arkclaw_webchat_cli-0.3.0/src/ee_claw/attachments.py +81 -0
  5. arkclaw_webchat_cli-0.3.0/src/ee_claw/cli.py +445 -0
  6. arkclaw_webchat_cli-0.3.0/src/ee_claw/config.py +278 -0
  7. arkclaw_webchat_cli-0.3.0/src/ee_claw/control.py +64 -0
  8. arkclaw_webchat_cli-0.3.0/src/ee_claw/core.py +50 -0
  9. arkclaw_webchat_cli-0.3.0/src/ee_claw/doctor.py +139 -0
  10. arkclaw_webchat_cli-0.3.0/src/ee_claw/errors.py +132 -0
  11. arkclaw_webchat_cli-0.3.0/src/ee_claw/flows.py +1280 -0
  12. arkclaw_webchat_cli-0.3.0/src/ee_claw/identity.py +261 -0
  13. arkclaw_webchat_cli-0.3.0/src/ee_claw/oauth.py +306 -0
  14. arkclaw_webchat_cli-0.3.0/src/ee_claw/output.py +137 -0
  15. arkclaw_webchat_cli-0.3.0/src/ee_claw/policy.py +63 -0
  16. arkclaw_webchat_cli-0.3.0/src/ee_claw/providers.py +91 -0
  17. arkclaw_webchat_cli-0.3.0/src/ee_claw/secrets_store.py +151 -0
  18. arkclaw_webchat_cli-0.3.0/src/ee_claw/sts.py +154 -0
  19. arkclaw_webchat_cli-0.3.0/src/ee_claw/transport/__init__.py +3 -0
  20. arkclaw_webchat_cli-0.3.0/src/ee_claw/transport/a2a.py +399 -0
  21. arkclaw_webchat_cli-0.3.0/src/ee_claw/transport/base.py +77 -0
  22. arkclaw_webchat_cli-0.3.0/src/ee_claw/transport/openclaw.py +472 -0
  23. arkclaw_webchat_cli-0.3.0/src/ee_claw/update.py +74 -0
  24. arkclaw_webchat_cli-0.1.0/PKG-INFO +0 -87
  25. arkclaw_webchat_cli-0.1.0/README.md +0 -65
  26. arkclaw_webchat_cli-0.1.0/src/ee_claw/cli.py +0 -74
  27. arkclaw_webchat_cli-0.1.0/src/ee_claw/core.py +0 -472
  28. arkclaw_webchat_cli-0.1.0/tests/test_smoke.py +0 -41
  29. {arkclaw_webchat_cli-0.1.0 → arkclaw_webchat_cli-0.3.0}/.gitignore +0 -0
  30. {arkclaw_webchat_cli-0.1.0 → arkclaw_webchat_cli-0.3.0}/src/ee_claw/__init__.py +0 -0
@@ -0,0 +1,197 @@
1
+ Metadata-Version: 2.4
2
+ Name: arkclaw-webchat-cli
3
+ Version: 0.3.0
4
+ Summary: CLI to chat with an ArkClaw EE space's Claw over enterprise SSO — zero permanent AK/SK.
5
+ Author: ArkClaw Team
6
+ Keywords: arkclaw,cli,ee,openclaw,sso,sts
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Operating System :: MacOS
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Python: >=3.10
16
+ Requires-Dist: keyring>=24.0
17
+ Requires-Dist: typer>=0.12.0
18
+ Requires-Dist: websockets>=12.0
19
+ Provides-Extra: dev
20
+ Requires-Dist: mypy>=1.10; extra == 'dev'
21
+ Requires-Dist: pytest>=7.4; extra == 'dev'
22
+ Requires-Dist: ruff>=0.6; extra == 'dev'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # arkclaw
26
+
27
+ **Chat with your ArkClaw claws (agents) from the terminal — log in with your
28
+ own SSO identity, no passwords, no permanent keys.** Works the same for a human
29
+ at a prompt and for another agent/script (`--json` + exit codes).
30
+
31
+ ```bash
32
+ arkclaw init # one-time interactive setup (asks only what it can't auto-detect)
33
+ arkclaw login # browser SSO
34
+ arkclaw agents # list the claws you can chat
35
+ arkclaw chat ci-xxxxxxxx
36
+ ```
37
+
38
+ ---
39
+
40
+ ## What it can do
41
+
42
+ - **Log in as you** — browser SSO (PKCE), short-lived token, auto-refresh. No AK/SK, no client secret, nothing permanent on disk but a token in your OS keychain.
43
+ - **List your agents** — `arkclaw agents` shows the claws you can chat with.
44
+ - **Chat** — interactive REPL or one-shot `-m`, streaming token-by-token, with a live "what's it doing" spinner and tool-event trace.
45
+ - **Talk to a specific claw** — by id (`chat ci-...`) or by name (`chat 答疑助手`).
46
+ - **Manage a claw's files** — read/write its managed workspace files (`AGENTS.md`, `SOUL.md`, `MEMORY.md`, …) with `ls` / `pull` / `push`.
47
+ - **Fan out** — send one message to many claws in parallel.
48
+ - **Be scripted** — every command takes `--json` (one clean `{ok,data,error}` envelope on stdout) and returns a typed exit code.
49
+
50
+ Two transports, picked at login: **openclaw** (your claws, the default) and **a2a** (an agent endpoint).
51
+
52
+ ---
53
+
54
+ ## Install
55
+
56
+ ```bash
57
+ pip install arkclaw-webchat-cli # provides the `arkclaw` command
58
+ ```
59
+
60
+ From source:
61
+
62
+ ```bash
63
+ git clone <repo> && cd ee-claw
64
+ uv venv && uv pip install -e .
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Quick start
70
+
71
+ ```bash
72
+ # 0. one-time setup — interactive. Asks for your space address and (only if the
73
+ # space doesn't already publish them) the CLI client + STS role. Saved to
74
+ # ~/.arkclaw/defaults.json so you never type them again.
75
+ arkclaw init
76
+
77
+ # 1. log in (a browser opens; sign in with SSO)
78
+ arkclaw login
79
+
80
+ # 2. see which claws you can talk to
81
+ arkclaw agents
82
+
83
+ # 3. chat — interactive…
84
+ arkclaw chat ci-xxxxxxxx
85
+ # …or one-shot:
86
+ arkclaw chat ci-xxxxxxxx -m "用一句话介绍你自己"
87
+ ```
88
+
89
+ `arkclaw init` resolves everything it can from the address (identity pool,
90
+ region) and only prompts for what's missing. Once your space publishes
91
+ auto-discovery, `init` asks for nothing but the address — and you can even skip
92
+ straight to `arkclaw login https://your-space...`. See **[Configuration](#configuration)**.
93
+
94
+ ---
95
+
96
+ ## Commands
97
+
98
+ | Command | What it does |
99
+ |---|---|
100
+ | `arkclaw init [address]` | One-time interactive setup. Saves the address + (only what isn't auto-discovered) the CLI client and STS role to `~/.arkclaw/defaults.json`, so later commands need no env/flags. |
101
+ | `arkclaw login [space-url]` | Browser SSO login. Uses `init` defaults if you omit the URL. `--transport a2a --endpoint <url>` for an agent endpoint. `--clawid ci-...` sets a default claw. Bare `arkclaw login` re-logs into the previous space. |
102
+ | `arkclaw agents` | List the claws/agents you can chat with. |
103
+ | `arkclaw chat [TARGET] [MSG]` | Chat. `TARGET` = a claw id (`ci-...`), an agent name (from `agents`), or a profile. With `MSG` → one-shot; without → interactive REPL. `-f` attach files, `-o` write the reply, `--session NAME` name the conversation, `--approve-all` auto-approve tool runs. |
104
+ | `arkclaw <name>` | Shortcut: `arkclaw 答疑助手` ≡ `arkclaw chat 答疑助手`. |
105
+ | `arkclaw ls` | List the claw's managed workspace files. |
106
+ | `arkclaw pull <name> [local]` | Download a managed file to local disk. |
107
+ | `arkclaw push <local> [name]` | Write a local text file into a managed file. |
108
+ | `arkclaw fanout "<msg>" --clawid ci-a --clawid ci-b` | Same message to many claws in parallel. |
109
+ | `arkclaw sessions` | Recent chat sessions on this machine. |
110
+ | `arkclaw profile save/use/list` | Named snapshots of the session config (multi-space / multi-claw). |
111
+ | `arkclaw doctor` | Self-check: login freshness, keychain, pool/STS/endpoint reachability. |
112
+ | `arkclaw schema --json` | Machine-readable command surface (for agents/tooling). |
113
+ | `arkclaw claw list/describe/create/delete` | Fleet management on the control plane. |
114
+
115
+ All commands accept `--clawid ci-...` (where relevant) to target a specific claw, and `--json` for machine output.
116
+
117
+ ---
118
+
119
+ ## Chatting
120
+
121
+ ```bash
122
+ arkclaw chat ci-xxxx # REPL with that claw (Ctrl-C: interrupt turn; twice: exit)
123
+ arkclaw chat ci-xxxx -m "你好" # one-shot
124
+ arkclaw chat 答疑助手 -m "怎么部署" # by name (names come from `arkclaw agents`)
125
+ echo "$DATA" | arkclaw chat ci-xxxx --json -m "总结" | jq -r .data.reply # piped, machine
126
+ arkclaw chat ci-xxxx -f notes.md -m "review" -o out.md # attach context, save reply
127
+ ```
128
+
129
+ - **Streaming** on both transports; until the first token a spinner shows elapsed time + the running tool.
130
+ - **Sessions are server-side** — `--session NAME` keeps a named conversation that survives CLI restarts.
131
+ - **Tool approvals**: in a terminal you're prompted; headless it fails closed (deny) unless `--approve-all`; a `~/.arkclaw/cmdpolicy.json` deny-list always wins.
132
+
133
+ ---
134
+
135
+ ## Files
136
+
137
+ `ls` / `pull` / `push` operate on a claw's **managed workspace files** — its
138
+ "brain": `AGENTS.md`, `SOUL.md`, `MEMORY.md`, `TOOLS.md`, `IDENTITY.md`,
139
+ `USER.md`, `HEARTBEAT.md`. (This is not a general file store — arbitrary
140
+ filenames are rejected.)
141
+
142
+ ```bash
143
+ arkclaw ls # list them (defaults to your default claw)
144
+ arkclaw pull SOUL.md # download SOUL.md here
145
+ arkclaw pull AGENTS.md ./agents.md # download to a path
146
+ arkclaw push ./agents.md AGENTS.md # write a managed file
147
+ arkclaw ls --clawid ci-other # a different claw
148
+ ```
149
+
150
+ ---
151
+
152
+ ## For agents / automation
153
+
154
+ - `--json` → stdout is exactly one `{ok, data, error}` document; progress/streaming goes to stderr. Pipe to `jq`.
155
+ - Exit codes: `0` ok · `1` api · `2` validation · `3` auth · `4` network · `5` internal.
156
+ - Headless never blocks: `--json` / piped stdin refuse the interactive REPL; tool approvals fail closed.
157
+ - `arkclaw schema --json` describes every command + option for programmatic discovery.
158
+
159
+ ---
160
+
161
+ ## Identity & security
162
+
163
+ - **Identity-through, zero permanent secrets.** Browser PKCE (S256, public client, loopback) → a short-lived `id_token` that *is your user identity* (same as the web app), auto-refreshed. The claw sees you, not a shared key.
164
+ - **openclaw** path exchanges that token (via a least-privilege STS role that can do exactly `GetClawInstanceChatToken`) for a one-time ChatToken, then connects over wss. **a2a** presents the token directly to the agent's gateway.
165
+ - Tokens live in the **OS keychain** (0600 file fallback). The config file holds only non-secret routing. Every upstream error is **redacted** (tokens / AK-SK) before display.
166
+
167
+ ---
168
+
169
+ ## Configuration
170
+
171
+ `login` resolves config in this order: **explicit flag → `ARKCLAW_*` env →
172
+ the space's published discovery → `arkclaw init` defaults → derived from the
173
+ address**. You normally only type the address.
174
+
175
+ **The easy way — `arkclaw init`** asks once (interactively) for whatever the
176
+ space doesn't yet auto-publish, and saves it. After that, just `arkclaw login`.
177
+
178
+ **The env way** (scripts/CI, or instead of `init`) — supply the same non-secret
179
+ values via env:
180
+
181
+ | Env | Purpose |
182
+ |---|---|
183
+ | `ARKCLAW_CLIENT_ID` | The CLI's public OAuth client id for the pool. |
184
+ | `ARKCLAW_ROLE_TRN` | STS role that mints the ChatToken (openclaw). |
185
+ | `ARKCLAW_REGION` / `ARKCLAW_SPACE_ID` | Override region / space (usually auto). |
186
+
187
+ Other config: `~/.arkclaw/defaults.json` (`init` answers, 0600), `~/.arkclaw/session.json` (routing, 0600), `~/.arkclaw/cmdpolicy.json` (tool-approval allow/deny), OS keychain (tokens).
188
+
189
+ > **Escape hatch (admin/test):** `arkclaw login <url> --transport openclaw --static-creds` uses `VOLCENGINE_ACCESS_KEY`/`SECRET_KEY` from the env instead of SSO — convenient for CI, but it's account-level keys, not identity-through.
190
+
191
+ ---
192
+
193
+ ## Notes
194
+
195
+ - `ls`/`pull`/`push` and a bare `chat` use your **default claw** (set at login, or the last one you opened in the browser); override with `--clawid` (or `chat ci-...`).
196
+ - File commands cover the claw's **managed** files only; arbitrary file drop isn't exposed by the API.
197
+ - Nothing is hardcoded per space — the CLI reads what the space serves.
@@ -0,0 +1,173 @@
1
+ # arkclaw
2
+
3
+ **Chat with your ArkClaw claws (agents) from the terminal — log in with your
4
+ own SSO identity, no passwords, no permanent keys.** Works the same for a human
5
+ at a prompt and for another agent/script (`--json` + exit codes).
6
+
7
+ ```bash
8
+ arkclaw init # one-time interactive setup (asks only what it can't auto-detect)
9
+ arkclaw login # browser SSO
10
+ arkclaw agents # list the claws you can chat
11
+ arkclaw chat ci-xxxxxxxx
12
+ ```
13
+
14
+ ---
15
+
16
+ ## What it can do
17
+
18
+ - **Log in as you** — browser SSO (PKCE), short-lived token, auto-refresh. No AK/SK, no client secret, nothing permanent on disk but a token in your OS keychain.
19
+ - **List your agents** — `arkclaw agents` shows the claws you can chat with.
20
+ - **Chat** — interactive REPL or one-shot `-m`, streaming token-by-token, with a live "what's it doing" spinner and tool-event trace.
21
+ - **Talk to a specific claw** — by id (`chat ci-...`) or by name (`chat 答疑助手`).
22
+ - **Manage a claw's files** — read/write its managed workspace files (`AGENTS.md`, `SOUL.md`, `MEMORY.md`, …) with `ls` / `pull` / `push`.
23
+ - **Fan out** — send one message to many claws in parallel.
24
+ - **Be scripted** — every command takes `--json` (one clean `{ok,data,error}` envelope on stdout) and returns a typed exit code.
25
+
26
+ Two transports, picked at login: **openclaw** (your claws, the default) and **a2a** (an agent endpoint).
27
+
28
+ ---
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ pip install arkclaw-webchat-cli # provides the `arkclaw` command
34
+ ```
35
+
36
+ From source:
37
+
38
+ ```bash
39
+ git clone <repo> && cd ee-claw
40
+ uv venv && uv pip install -e .
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Quick start
46
+
47
+ ```bash
48
+ # 0. one-time setup — interactive. Asks for your space address and (only if the
49
+ # space doesn't already publish them) the CLI client + STS role. Saved to
50
+ # ~/.arkclaw/defaults.json so you never type them again.
51
+ arkclaw init
52
+
53
+ # 1. log in (a browser opens; sign in with SSO)
54
+ arkclaw login
55
+
56
+ # 2. see which claws you can talk to
57
+ arkclaw agents
58
+
59
+ # 3. chat — interactive…
60
+ arkclaw chat ci-xxxxxxxx
61
+ # …or one-shot:
62
+ arkclaw chat ci-xxxxxxxx -m "用一句话介绍你自己"
63
+ ```
64
+
65
+ `arkclaw init` resolves everything it can from the address (identity pool,
66
+ region) and only prompts for what's missing. Once your space publishes
67
+ auto-discovery, `init` asks for nothing but the address — and you can even skip
68
+ straight to `arkclaw login https://your-space...`. See **[Configuration](#configuration)**.
69
+
70
+ ---
71
+
72
+ ## Commands
73
+
74
+ | Command | What it does |
75
+ |---|---|
76
+ | `arkclaw init [address]` | One-time interactive setup. Saves the address + (only what isn't auto-discovered) the CLI client and STS role to `~/.arkclaw/defaults.json`, so later commands need no env/flags. |
77
+ | `arkclaw login [space-url]` | Browser SSO login. Uses `init` defaults if you omit the URL. `--transport a2a --endpoint <url>` for an agent endpoint. `--clawid ci-...` sets a default claw. Bare `arkclaw login` re-logs into the previous space. |
78
+ | `arkclaw agents` | List the claws/agents you can chat with. |
79
+ | `arkclaw chat [TARGET] [MSG]` | Chat. `TARGET` = a claw id (`ci-...`), an agent name (from `agents`), or a profile. With `MSG` → one-shot; without → interactive REPL. `-f` attach files, `-o` write the reply, `--session NAME` name the conversation, `--approve-all` auto-approve tool runs. |
80
+ | `arkclaw <name>` | Shortcut: `arkclaw 答疑助手` ≡ `arkclaw chat 答疑助手`. |
81
+ | `arkclaw ls` | List the claw's managed workspace files. |
82
+ | `arkclaw pull <name> [local]` | Download a managed file to local disk. |
83
+ | `arkclaw push <local> [name]` | Write a local text file into a managed file. |
84
+ | `arkclaw fanout "<msg>" --clawid ci-a --clawid ci-b` | Same message to many claws in parallel. |
85
+ | `arkclaw sessions` | Recent chat sessions on this machine. |
86
+ | `arkclaw profile save/use/list` | Named snapshots of the session config (multi-space / multi-claw). |
87
+ | `arkclaw doctor` | Self-check: login freshness, keychain, pool/STS/endpoint reachability. |
88
+ | `arkclaw schema --json` | Machine-readable command surface (for agents/tooling). |
89
+ | `arkclaw claw list/describe/create/delete` | Fleet management on the control plane. |
90
+
91
+ All commands accept `--clawid ci-...` (where relevant) to target a specific claw, and `--json` for machine output.
92
+
93
+ ---
94
+
95
+ ## Chatting
96
+
97
+ ```bash
98
+ arkclaw chat ci-xxxx # REPL with that claw (Ctrl-C: interrupt turn; twice: exit)
99
+ arkclaw chat ci-xxxx -m "你好" # one-shot
100
+ arkclaw chat 答疑助手 -m "怎么部署" # by name (names come from `arkclaw agents`)
101
+ echo "$DATA" | arkclaw chat ci-xxxx --json -m "总结" | jq -r .data.reply # piped, machine
102
+ arkclaw chat ci-xxxx -f notes.md -m "review" -o out.md # attach context, save reply
103
+ ```
104
+
105
+ - **Streaming** on both transports; until the first token a spinner shows elapsed time + the running tool.
106
+ - **Sessions are server-side** — `--session NAME` keeps a named conversation that survives CLI restarts.
107
+ - **Tool approvals**: in a terminal you're prompted; headless it fails closed (deny) unless `--approve-all`; a `~/.arkclaw/cmdpolicy.json` deny-list always wins.
108
+
109
+ ---
110
+
111
+ ## Files
112
+
113
+ `ls` / `pull` / `push` operate on a claw's **managed workspace files** — its
114
+ "brain": `AGENTS.md`, `SOUL.md`, `MEMORY.md`, `TOOLS.md`, `IDENTITY.md`,
115
+ `USER.md`, `HEARTBEAT.md`. (This is not a general file store — arbitrary
116
+ filenames are rejected.)
117
+
118
+ ```bash
119
+ arkclaw ls # list them (defaults to your default claw)
120
+ arkclaw pull SOUL.md # download SOUL.md here
121
+ arkclaw pull AGENTS.md ./agents.md # download to a path
122
+ arkclaw push ./agents.md AGENTS.md # write a managed file
123
+ arkclaw ls --clawid ci-other # a different claw
124
+ ```
125
+
126
+ ---
127
+
128
+ ## For agents / automation
129
+
130
+ - `--json` → stdout is exactly one `{ok, data, error}` document; progress/streaming goes to stderr. Pipe to `jq`.
131
+ - Exit codes: `0` ok · `1` api · `2` validation · `3` auth · `4` network · `5` internal.
132
+ - Headless never blocks: `--json` / piped stdin refuse the interactive REPL; tool approvals fail closed.
133
+ - `arkclaw schema --json` describes every command + option for programmatic discovery.
134
+
135
+ ---
136
+
137
+ ## Identity & security
138
+
139
+ - **Identity-through, zero permanent secrets.** Browser PKCE (S256, public client, loopback) → a short-lived `id_token` that *is your user identity* (same as the web app), auto-refreshed. The claw sees you, not a shared key.
140
+ - **openclaw** path exchanges that token (via a least-privilege STS role that can do exactly `GetClawInstanceChatToken`) for a one-time ChatToken, then connects over wss. **a2a** presents the token directly to the agent's gateway.
141
+ - Tokens live in the **OS keychain** (0600 file fallback). The config file holds only non-secret routing. Every upstream error is **redacted** (tokens / AK-SK) before display.
142
+
143
+ ---
144
+
145
+ ## Configuration
146
+
147
+ `login` resolves config in this order: **explicit flag → `ARKCLAW_*` env →
148
+ the space's published discovery → `arkclaw init` defaults → derived from the
149
+ address**. You normally only type the address.
150
+
151
+ **The easy way — `arkclaw init`** asks once (interactively) for whatever the
152
+ space doesn't yet auto-publish, and saves it. After that, just `arkclaw login`.
153
+
154
+ **The env way** (scripts/CI, or instead of `init`) — supply the same non-secret
155
+ values via env:
156
+
157
+ | Env | Purpose |
158
+ |---|---|
159
+ | `ARKCLAW_CLIENT_ID` | The CLI's public OAuth client id for the pool. |
160
+ | `ARKCLAW_ROLE_TRN` | STS role that mints the ChatToken (openclaw). |
161
+ | `ARKCLAW_REGION` / `ARKCLAW_SPACE_ID` | Override region / space (usually auto). |
162
+
163
+ Other config: `~/.arkclaw/defaults.json` (`init` answers, 0600), `~/.arkclaw/session.json` (routing, 0600), `~/.arkclaw/cmdpolicy.json` (tool-approval allow/deny), OS keychain (tokens).
164
+
165
+ > **Escape hatch (admin/test):** `arkclaw login <url> --transport openclaw --static-creds` uses `VOLCENGINE_ACCESS_KEY`/`SECRET_KEY` from the env instead of SSO — convenient for CI, but it's account-level keys, not identity-through.
166
+
167
+ ---
168
+
169
+ ## Notes
170
+
171
+ - `ls`/`pull`/`push` and a bare `chat` use your **default claw** (set at login, or the last one you opened in the browser); override with `--clawid` (or `chat ci-...`).
172
+ - File commands cover the claw's **managed** files only; arbitrary file drop isn't exposed by the API.
173
+ - Nothing is hardcoded per space — the CLI reads what the space serves.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "arkclaw-webchat-cli"
7
- version = "0.1.0"
7
+ version = "0.3.0"
8
8
  description = "CLI to chat with an ArkClaw EE space's Claw over enterprise SSO — zero permanent AK/SK."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -23,20 +23,28 @@ classifiers = [
23
23
  dependencies = [
24
24
  "typer>=0.12.0",
25
25
  "websockets>=12.0",
26
+ "keyring>=24.0",
26
27
  ]
27
28
 
28
29
  [project.optional-dependencies]
29
30
  dev = [
30
31
  "pytest>=7.4",
31
32
  "ruff>=0.6",
33
+ "mypy>=1.10",
32
34
  ]
33
35
 
34
36
  [project.scripts]
35
- arkclaw-webchat = "ee_claw.cli:main"
37
+ arkclaw = "ee_claw.cli:main"
38
+ arkclaw-webchat = "ee_claw.cli:main" # legacy alias
36
39
 
37
40
  [tool.hatch.build.targets.wheel]
38
41
  packages = ["src/ee_claw"]
39
42
 
43
+ [tool.hatch.build.targets.sdist]
44
+ # Ship ONLY the package (+ auto: pyproject, README). Never publish the internal
45
+ # docs/ (SRE asks, well-known sample) — they carry real deployment identifiers.
46
+ only-include = ["src/ee_claw"]
47
+
40
48
  [tool.ruff]
41
49
  line-length = 100
42
50
  target-version = "py310"
@@ -45,3 +53,12 @@ src = ["src", "tests"]
45
53
  [tool.ruff.lint]
46
54
  select = ["E", "W", "F", "I", "UP", "B"]
47
55
  ignore = ["E501"]
56
+
57
+ [tool.ruff.lint.per-file-ignores]
58
+ # typer's API *is* function calls in argument defaults.
59
+ "src/ee_claw/cli.py" = ["B008"]
60
+
61
+ [tool.mypy]
62
+ python_version = "3.10"
63
+ ignore_missing_imports = true
64
+ check_untyped_defs = true
@@ -0,0 +1,81 @@
1
+ """Composable input: collect stdin / files / directories into Attachments.
2
+
3
+ Caps are explicit and every drop is reported (no silent truncation — a "we
4
+ covered everything" that didn't is worse than a visible limit)."""
5
+
6
+ from __future__ import annotations
7
+
8
+ import mimetypes
9
+ import pathlib
10
+
11
+ from ee_claw.errors import ValidationError
12
+ from ee_claw.transport.base import Attachment
13
+
14
+ MAX_FILE_BYTES = 64 * 1024
15
+ MAX_TOTAL_BYTES = 256 * 1024
16
+ MAX_FILES = 32
17
+
18
+
19
+ def collect_files(paths: list[str]) -> tuple[list[Attachment], list[str]]:
20
+ """Read files (and directories, shallow-recursively) into attachments.
21
+ Returns ``(attachments, notices)`` — notices describe everything that was
22
+ truncated or skipped, for the human stream."""
23
+ notices: list[str] = []
24
+ candidates: list[pathlib.Path] = []
25
+ for raw in paths:
26
+ p = pathlib.Path(raw).expanduser()
27
+ if not p.exists():
28
+ raise ValidationError(f"文件不存在: {raw}")
29
+ if p.is_dir():
30
+ # Exclude any path with a hidden COMPONENT below the requested dir
31
+ # (not just hidden leaves): rglob descends into .git/ and .ssh/,
32
+ # whose contents are exactly the secrets that must never ride
33
+ # along. relative_to(p) keeps a user-supplied hidden base
34
+ # (e.g. -f ~/.config/proj) workable.
35
+ inner = sorted(
36
+ f
37
+ for f in p.rglob("*")
38
+ if f.is_file()
39
+ and not any(part.startswith(".") for part in f.relative_to(p).parts)
40
+ )
41
+ candidates.extend(inner)
42
+ else:
43
+ candidates.append(p)
44
+
45
+ if len(candidates) > MAX_FILES:
46
+ notices.append(f"超出 {MAX_FILES} 个文件上限,丢弃了 {len(candidates) - MAX_FILES} 个")
47
+ candidates = candidates[:MAX_FILES]
48
+
49
+ attachments: list[Attachment] = []
50
+ total = 0
51
+ for f in candidates:
52
+ try:
53
+ content = f.read_bytes()
54
+ except OSError as e:
55
+ notices.append(f"读不了 {f}: {e.__class__.__name__}")
56
+ continue
57
+ if len(content) > MAX_FILE_BYTES:
58
+ notices.append(f"{f.name} 截断到 {MAX_FILE_BYTES // 1024}KB(原 {len(content)} 字节)")
59
+ content = content[:MAX_FILE_BYTES]
60
+ if total + len(content) > MAX_TOTAL_BYTES:
61
+ notices.append(f"总量超出 {MAX_TOTAL_BYTES // 1024}KB,从 {f.name} 起丢弃")
62
+ break
63
+ total += len(content)
64
+ mime = mimetypes.guess_type(f.name)[0] or "application/octet-stream"
65
+ attachments.append(Attachment(name=f.name, content=content, mime=mime))
66
+ return attachments, notices
67
+
68
+
69
+ def inline_attachments(message: str, files: tuple[Attachment, ...] | list[Attachment]) -> tuple[str, list[str]]:
70
+ """Render text attachments as context blocks appended to the message (for
71
+ transports without native file parts). Returns ``(message, skipped_names)``
72
+ — binary attachments can't be inlined and are reported, not dropped silently."""
73
+ blocks = [message]
74
+ skipped: list[str] = []
75
+ for att in files:
76
+ text = att.text
77
+ if text is None:
78
+ skipped.append(att.name)
79
+ continue
80
+ blocks.append(f"\n\n--- 文件: {att.name} ---\n{text}")
81
+ return "".join(blocks), skipped