7zon-cli 0.2.3__tar.gz → 0.2.4__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.
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/PKG-INFO +1 -1
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/pyproject.toml +1 -1
- 7zon_cli-0.2.4/src/zon7/__init__.py +1 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/cli.py +6 -8
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/menu.py +92 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/tools.py +2 -3
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_cli.py +9 -3
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_menu.py +36 -0
- 7zon_cli-0.2.3/src/zon7/__init__.py +0 -1
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/.github/workflows/ci.yml +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/.github/workflows/publish.yml +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/.gitignore +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/LICENSE +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/README.md +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/install-termux.sh +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/__main__.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/ai.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/banner.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/common.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/config.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/context.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/instagram.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/memory.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/prompts.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/providers/__init__.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/providers/claude.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/providers/gemini.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/safety.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/secrets.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/src/zon7/shell.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_config.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_context.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_gemini.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_instagram.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_memory.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_powershell_real.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_safety.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_secrets.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_shell.py +0 -0
- {7zon_cli-0.2.3 → 7zon_cli-0.2.4}/tests/test_tools.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: 7zon-cli
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: 7ZON — terminalda ishlaydigan AI yordamchi: buyruq yozadi, xatolarni tuzatadi, tushuntiradi.
|
|
5
5
|
Project-URL: Homepage, https://github.com/7zon-uz/7ZON-CLI
|
|
6
6
|
Project-URL: Issues, https://github.com/7zon-uz/7ZON-CLI/issues
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.4"
|
|
@@ -306,7 +306,8 @@ def _has_key(cfg: dict[str, Any]) -> bool:
|
|
|
306
306
|
name = cfg.get("provider", "gemini")
|
|
307
307
|
if any(os.environ.get(e) for e in KEY_ENV.get(name, ())):
|
|
308
308
|
return True
|
|
309
|
-
|
|
309
|
+
# Eski versiya ko'rinmas belgini kalit sifatida saqlagan bo'lishi mumkin
|
|
310
|
+
return bool(config.clean_key(cfg.get(config.KEY_FIELDS.get(name, "")) or ""))
|
|
310
311
|
|
|
311
312
|
|
|
312
313
|
def _is_set_key_line(line: str) -> bool:
|
|
@@ -317,15 +318,13 @@ def _is_set_key_line(line: str) -> bool:
|
|
|
317
318
|
|
|
318
319
|
def _prompt_key(cfg: dict[str, Any], name: str | None = None) -> bool:
|
|
319
320
|
"""Kalitni yashirin so'raydi va saqlaydi. Saqlansa True."""
|
|
320
|
-
import getpass
|
|
321
|
-
|
|
322
321
|
name = name or cfg.get("provider", "gemini")
|
|
323
322
|
field = config.KEY_FIELDS[name]
|
|
324
323
|
console.print(f"[bold]{name.capitalize()} API kalit[/] kerak. Olish: [cyan]{KEY_URL[name]}[/]\n"
|
|
325
324
|
"[dim]Kalitni qo'ying (Ctrl+V yoki sichqonchaning o'ng tugmasi) va Enter bosing. "
|
|
326
|
-
"
|
|
325
|
+
"Kalit ekranda ochiq ko'rinmaydi, bu normal.[/]")
|
|
327
326
|
try:
|
|
328
|
-
key = config.clean_key(
|
|
327
|
+
key = config.clean_key(menu.read_secret(f"{name.capitalize()} API kalit: "))
|
|
329
328
|
except (EOFError, KeyboardInterrupt):
|
|
330
329
|
console.print()
|
|
331
330
|
return False
|
|
@@ -486,7 +485,7 @@ def config_set_key(
|
|
|
486
485
|
name = provider or cfg["provider"]
|
|
487
486
|
if name not in config.KEY_FIELDS:
|
|
488
487
|
_fail("Provayder: gemini yoki claude")
|
|
489
|
-
key = config.clean_key(
|
|
488
|
+
key = config.clean_key(menu.read_secret(f"{name.capitalize()} API kalit (Ctrl+V yoki o'ng tugma bilan joylang, keyin Enter): "))
|
|
490
489
|
problem = config.key_problem(key)
|
|
491
490
|
if problem:
|
|
492
491
|
_fail(problem)
|
|
@@ -503,10 +502,9 @@ def secret_add(name: str = typer.Argument(..., help="Masalan: INSTAGRAM_PASSWORD
|
|
|
503
502
|
key = vault.normalize(name)
|
|
504
503
|
except vault.SecretError as e:
|
|
505
504
|
_fail(str(e))
|
|
506
|
-
import getpass
|
|
507
505
|
|
|
508
506
|
try:
|
|
509
|
-
value =
|
|
507
|
+
value = menu.read_secret(f"{key} (ekranda ko'rinmaydi): ")
|
|
510
508
|
except (KeyboardInterrupt, EOFError):
|
|
511
509
|
console.print("\n[dim]Bekor qilindi.[/]")
|
|
512
510
|
raise typer.Exit(130)
|
|
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|
|
9
9
|
import os
|
|
10
10
|
import sys
|
|
11
11
|
from collections.abc import Callable, Sequence
|
|
12
|
+
from typing import Any
|
|
12
13
|
|
|
13
14
|
ORANGE = "\x1b[1;38;2;255;172;60m"
|
|
14
15
|
DIM = "\x1b[2m"
|
|
@@ -160,3 +161,94 @@ def choose(
|
|
|
160
161
|
if answer == str(i + 1) or answer in aliases:
|
|
161
162
|
return i
|
|
162
163
|
return len(options) - 1
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
# --------------------------------------------------------------------------- yashirin kiritish
|
|
167
|
+
|
|
168
|
+
def _windows_clipboard() -> str:
|
|
169
|
+
"""Windows clipboard matni (qo'shimcha kutubxonasiz)."""
|
|
170
|
+
try:
|
|
171
|
+
import ctypes
|
|
172
|
+
from ctypes import wintypes
|
|
173
|
+
|
|
174
|
+
user32 = ctypes.windll.user32 # type: ignore[attr-defined]
|
|
175
|
+
kernel32 = ctypes.windll.kernel32 # type: ignore[attr-defined]
|
|
176
|
+
user32.GetClipboardData.restype = wintypes.HANDLE
|
|
177
|
+
kernel32.GlobalLock.argtypes = [wintypes.HGLOBAL]
|
|
178
|
+
kernel32.GlobalLock.restype = ctypes.c_void_p
|
|
179
|
+
kernel32.GlobalUnlock.argtypes = [wintypes.HGLOBAL]
|
|
180
|
+
if not user32.OpenClipboard(None):
|
|
181
|
+
return ""
|
|
182
|
+
try:
|
|
183
|
+
handle = user32.GetClipboardData(13) # CF_UNICODETEXT
|
|
184
|
+
if not handle:
|
|
185
|
+
return ""
|
|
186
|
+
ptr = kernel32.GlobalLock(handle)
|
|
187
|
+
if not ptr:
|
|
188
|
+
return ""
|
|
189
|
+
try:
|
|
190
|
+
return ctypes.wstring_at(ptr)
|
|
191
|
+
finally:
|
|
192
|
+
kernel32.GlobalUnlock(handle)
|
|
193
|
+
finally:
|
|
194
|
+
user32.CloseClipboard()
|
|
195
|
+
except Exception:
|
|
196
|
+
return ""
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _read_secret_windows(prompt: str, getch: Callable[[], str], clipboard: Callable[[], str],
|
|
200
|
+
write: Callable[[str], Any]) -> str:
|
|
201
|
+
"""Windows konsolida yashirin kiritish: Ctrl+V va o'ng tugma bilan joylash ishlaydi.
|
|
202
|
+
|
|
203
|
+
Oddiy getpass cmd.exe'da Ctrl+V'ni kalit o'rniga ko'rinmas \\x16 belgi sifatida o'qiydi.
|
|
204
|
+
Har bir belgi o'rniga • chiqariladi, shunda joylash ishlagani ko'rinib turadi.
|
|
205
|
+
"""
|
|
206
|
+
write(prompt)
|
|
207
|
+
chars: list[str] = []
|
|
208
|
+
while True:
|
|
209
|
+
ch = getch()
|
|
210
|
+
if ch in ("\r", "\n"):
|
|
211
|
+
break
|
|
212
|
+
if ch == "\x03":
|
|
213
|
+
write("\n")
|
|
214
|
+
raise KeyboardInterrupt
|
|
215
|
+
if ch == "\x1a" and not chars: # Ctrl+Z
|
|
216
|
+
write("\n")
|
|
217
|
+
raise EOFError
|
|
218
|
+
if ch in ("\x00", "\xe0"): # strelka va F tugmalari: ikkinchi belgini tashlaymiz
|
|
219
|
+
getch()
|
|
220
|
+
continue
|
|
221
|
+
if ch == "\x08": # Backspace
|
|
222
|
+
if chars:
|
|
223
|
+
chars.pop()
|
|
224
|
+
write("\b \b")
|
|
225
|
+
continue
|
|
226
|
+
added = clipboard() if ch == "\x16" else ch # Ctrl+V
|
|
227
|
+
added = "".join(c for c in added if c.isprintable())
|
|
228
|
+
chars.extend(added)
|
|
229
|
+
write("•" * len(added))
|
|
230
|
+
write("\n")
|
|
231
|
+
return "".join(chars)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def read_secret(prompt: str) -> str:
|
|
235
|
+
"""Parol yoki API kalitni ekranga chiqarmay o'qiydi (Windows'da joylash ham ishlaydi)."""
|
|
236
|
+
if os.name == "nt" and is_interactive():
|
|
237
|
+
import msvcrt
|
|
238
|
+
|
|
239
|
+
def write(s: str) -> None:
|
|
240
|
+
sys.stdout.write(s)
|
|
241
|
+
sys.stdout.flush()
|
|
242
|
+
|
|
243
|
+
return _read_secret_windows(prompt, msvcrt.getwch, _windows_clipboard, write)
|
|
244
|
+
try:
|
|
245
|
+
piped = not sys.stdin.isatty()
|
|
246
|
+
except (AttributeError, ValueError):
|
|
247
|
+
piped = True
|
|
248
|
+
if piped: # pipe yoki test: yashiradigan ekran yo'q, qatorni oddiy o'qiymiz
|
|
249
|
+
sys.stdout.write(prompt)
|
|
250
|
+
sys.stdout.flush()
|
|
251
|
+
return sys.stdin.readline().rstrip("\r\n")
|
|
252
|
+
import getpass
|
|
253
|
+
|
|
254
|
+
return getpass.getpass(prompt)
|
|
@@ -6,7 +6,6 @@ Har bir o'zgartiruvchi amal (buyruq, fayl yozish) foydalanuvchi tasdig'idan keyi
|
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
8
|
import difflib
|
|
9
|
-
import getpass
|
|
10
9
|
import html
|
|
11
10
|
import os
|
|
12
11
|
import re
|
|
@@ -263,14 +262,14 @@ class ToolRunner:
|
|
|
263
262
|
console: Console,
|
|
264
263
|
ask: Callable[[str], str],
|
|
265
264
|
cwd: Path | None = None,
|
|
266
|
-
secret_input: Callable[[str], str] =
|
|
265
|
+
secret_input: Callable[[str], str] | None = None,
|
|
267
266
|
load_saved_secrets: bool = True,
|
|
268
267
|
headless: bool = False,
|
|
269
268
|
) -> None:
|
|
270
269
|
self.headless = headless # -p rejimi: savol berib bo'lmaydi
|
|
271
270
|
self.console = console
|
|
272
271
|
self.ask = ask # oddiy qator kiritish (menyu terminal bo'lmaganda ishlatadi)
|
|
273
|
-
self.secret_input = secret_input # yashirin kiritish: yozilgan belgilar ekranda ko'rinmaydi
|
|
272
|
+
self.secret_input = secret_input or menu.read_secret # yashirin kiritish: yozilgan belgilar ekranda ko'rinmaydi
|
|
274
273
|
self.cwd = (cwd or Path.cwd()).resolve()
|
|
275
274
|
self.auto_approve = False # "Barchasiga ruxsat" tanlangandan keyin xavfli bo'lmagan amallar so'ralmaydi
|
|
276
275
|
# Maxfiy qiymatlar: faqat shu jarayon xotirasida va buyruqlar muhitida, AI'ga hech qachon bormaydi
|
|
@@ -250,7 +250,7 @@ def test_has_key(monkeypatch):
|
|
|
250
250
|
def test_prompt_key_saves_hidden(monkeypatch):
|
|
251
251
|
import getpass
|
|
252
252
|
|
|
253
|
-
monkeypatch.setattr(
|
|
253
|
+
monkeypatch.setattr(cli.menu, "read_secret", lambda prompt="": " SECRET123_long_test_key_000 ")
|
|
254
254
|
cfg = {"provider": "gemini"}
|
|
255
255
|
assert cli._prompt_key(cfg) is True
|
|
256
256
|
assert cfg["gemini_api_key"] == "SECRET123_long_test_key_000"
|
|
@@ -260,7 +260,7 @@ def test_prompt_key_saves_hidden(monkeypatch):
|
|
|
260
260
|
def test_prompt_key_empty(monkeypatch):
|
|
261
261
|
import getpass
|
|
262
262
|
|
|
263
|
-
monkeypatch.setattr(
|
|
263
|
+
monkeypatch.setattr(cli.menu, "read_secret", lambda prompt="": "")
|
|
264
264
|
cfg = {"provider": "gemini"}
|
|
265
265
|
assert cli._prompt_key(cfg) is False
|
|
266
266
|
assert "gemini_api_key" not in cfg
|
|
@@ -281,7 +281,7 @@ def test_set_key_typed_inside_chat(monkeypatch):
|
|
|
281
281
|
|
|
282
282
|
for e in ("GEMINI_API_KEY", "GOOGLE_API_KEY"):
|
|
283
283
|
monkeypatch.delenv(e, raising=False)
|
|
284
|
-
monkeypatch.setattr(
|
|
284
|
+
monkeypatch.setattr(cli.menu, "read_secret", lambda prompt="": "NEWKEY_long_test_key_00000")
|
|
285
285
|
monkeypatch.setattr(cli.ai, "make_agent", lambda *a, **k: FakeAgent())
|
|
286
286
|
result = runner.invoke(cli.app, ["chat"], input="7zon config set-key\nsalom\nexit\n")
|
|
287
287
|
assert result.exit_code == 0
|
|
@@ -289,3 +289,9 @@ def test_set_key_typed_inside_chat(monkeypatch):
|
|
|
289
289
|
assert "Javob" in result.output
|
|
290
290
|
assert "NEWKEY_long_test_key_00000" not in result.output
|
|
291
291
|
assert config.load()["gemini_api_key"] == "NEWKEY_long_test_key_00000"
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def test_junk_saved_key_counts_as_missing(monkeypatch):
|
|
295
|
+
for e in ("GEMINI_API_KEY", "GOOGLE_API_KEY"):
|
|
296
|
+
monkeypatch.delenv(e, raising=False)
|
|
297
|
+
assert cli._has_key({"provider": "gemini", "gemini_api_key": "\x16"}) is False
|
|
@@ -31,3 +31,39 @@ def test_arrow_ctrl_c(monkeypatch, capsys):
|
|
|
31
31
|
with pytest.raises(KeyboardInterrupt):
|
|
32
32
|
menu.select_arrows("?", ["a", "b"])
|
|
33
33
|
assert "\x1b[?25h" in capsys.readouterr().out # kursor qaytariladi
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# ---------------------------------------------------------------- Windows yashirin kiritish
|
|
37
|
+
|
|
38
|
+
def _run_reader(keys, clip=""):
|
|
39
|
+
from zon7 import menu
|
|
40
|
+
|
|
41
|
+
it = iter(keys)
|
|
42
|
+
out = []
|
|
43
|
+
value = menu._read_secret_windows("Kalit: ", lambda: next(it), lambda: clip, out.append)
|
|
44
|
+
return value, "".join(out)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_windows_secret_ctrl_v_pastes_clipboard():
|
|
48
|
+
value, shown = _run_reader(["\x16", "\r"], clip="AQ.secret_key_123\r\n")
|
|
49
|
+
assert value == "AQ.secret_key_123"
|
|
50
|
+
assert "secret" not in shown
|
|
51
|
+
assert "•" * len("AQ.secret_key_123") in shown
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_windows_secret_typed_and_backspace():
|
|
55
|
+
value, shown = _run_reader(["a", "b", "x", "\x08", "c", "\r"])
|
|
56
|
+
assert value == "abc"
|
|
57
|
+
assert "abc" not in shown
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_windows_secret_right_click_paste_arrives_as_keys():
|
|
61
|
+
value, _ = _run_reader(list("KEY123") + ["\r"])
|
|
62
|
+
assert value == "KEY123"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_windows_secret_ctrl_c():
|
|
66
|
+
import pytest
|
|
67
|
+
|
|
68
|
+
with pytest.raises(KeyboardInterrupt):
|
|
69
|
+
_run_reader(["a", "\x03"])
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.3"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|