ssh-agent-harness 0.1.0rc1__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.
- ssh_agent_harness-0.1.0rc1/PKG-INFO +239 -0
- ssh_agent_harness-0.1.0rc1/README.md +197 -0
- ssh_agent_harness-0.1.0rc1/pyproject.toml +161 -0
- ssh_agent_harness-0.1.0rc1/setup.cfg +4 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/__init__.py +4 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/__init__.py +1 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/__main__.py +78 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/app.py +339 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/approvals.py +45 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/deps.py +95 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/hosts.py +146 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/knowledge.py +113 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/llm.py +136 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/package_inspect.py +120 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/packages.py +387 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/run_manager.py +528 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/runs.py +74 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/schemas.py +307 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/sessions.py +72 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/static/__init__.py +10 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/static/assets/index-C6jsNDMh.css +1 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/static/assets/index-D31rM0uZ.js +461 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/static/favicon-32.png +0 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/static/favicon.ico +0 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/static/icon-192.png +0 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/static/icon-512.png +0 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/api/static/index.html +14 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/config.py +256 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/__init__.py +76 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/fingerprint.py +541 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/generation.py +91 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/host_loader.py +104 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/host_workspace.py +67 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/install_step.py +117 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/llm.py +232 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/llm_logging.py +67 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/llm_presets.py +107 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/model_adapter.py +487 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/multi_turn.py +336 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/ollama_client.py +653 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/orchestrator.py +523 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/package_commands.py +156 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/package_installer.py +531 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/package_manager.py +245 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/progress.py +87 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/prompt_context.py +43 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/reflection.py +205 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/run_persistence.py +55 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/step_items.py +237 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/step_loop.py +481 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/step_observation.py +46 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/step_phases.py +134 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/step_state.py +60 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/transfer_directive.py +324 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/transfer_executor.py +180 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/core/two_phase.py +365 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/default_settings.yaml +77 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/harness/__init__.py +75 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/harness/confirmation.py +517 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/harness/note_policy.py +170 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/harness/prompts.py +436 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/harness/protocol.py +216 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/harness/safety.py +477 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/harness/transfer_policy.py +177 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/logging_setup.py +141 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/storage/__init__.py +25 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/storage/host_store.py +153 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/storage/llm_store.py +80 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/storage/run_store.py +282 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/storage/session_store.py +865 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/tests/__init__.py +0 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/tools/__init__.py +39 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/tools/command_executor.py +314 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness/tools/ssh_pool.py +446 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness.egg-info/PKG-INFO +239 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness.egg-info/SOURCES.txt +113 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness.egg-info/dependency_links.txt +1 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness.egg-info/entry_points.txt +2 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness.egg-info/requires.txt +28 -0
- ssh_agent_harness-0.1.0rc1/ssh_agent_harness.egg-info/top_level.txt +1 -0
- ssh_agent_harness-0.1.0rc1/tests/test_api_packages.py +378 -0
- ssh_agent_harness-0.1.0rc1/tests/test_api_smoke.py +35 -0
- ssh_agent_harness-0.1.0rc1/tests/test_approval_coordinator.py +271 -0
- ssh_agent_harness-0.1.0rc1/tests/test_cancellation.py +250 -0
- ssh_agent_harness-0.1.0rc1/tests/test_command_starters.py +71 -0
- ssh_agent_harness-0.1.0rc1/tests/test_config.py +21 -0
- ssh_agent_harness-0.1.0rc1/tests/test_config_sources.py +194 -0
- ssh_agent_harness-0.1.0rc1/tests/test_fingerprint_cache.py +233 -0
- ssh_agent_harness-0.1.0rc1/tests/test_host_identity.py +215 -0
- ssh_agent_harness-0.1.0rc1/tests/test_host_loader.py +76 -0
- ssh_agent_harness-0.1.0rc1/tests/test_host_workspace.py +122 -0
- ssh_agent_harness-0.1.0rc1/tests/test_knowledge_edit.py +217 -0
- ssh_agent_harness-0.1.0rc1/tests/test_launch_observation.py +124 -0
- ssh_agent_harness-0.1.0rc1/tests/test_lifetime_cleanup.py +134 -0
- ssh_agent_harness-0.1.0rc1/tests/test_logging_setup.py +105 -0
- ssh_agent_harness-0.1.0rc1/tests/test_note_parsing.py +103 -0
- ssh_agent_harness-0.1.0rc1/tests/test_note_policy.py +217 -0
- ssh_agent_harness-0.1.0rc1/tests/test_package_home_path.py +128 -0
- ssh_agent_harness-0.1.0rc1/tests/test_package_installer.py +473 -0
- ssh_agent_harness-0.1.0rc1/tests/test_package_manager.py +209 -0
- ssh_agent_harness-0.1.0rc1/tests/test_package_manifest_crud.py +144 -0
- ssh_agent_harness-0.1.0rc1/tests/test_package_strip.py +48 -0
- ssh_agent_harness-0.1.0rc1/tests/test_package_tilde.py +38 -0
- ssh_agent_harness-0.1.0rc1/tests/test_packaged_console.py +91 -0
- ssh_agent_harness-0.1.0rc1/tests/test_packaging_dependencies.py +186 -0
- ssh_agent_harness-0.1.0rc1/tests/test_progress.py +68 -0
- ssh_agent_harness-0.1.0rc1/tests/test_prompt_permissions.py +161 -0
- ssh_agent_harness-0.1.0rc1/tests/test_run_manager.py +439 -0
- ssh_agent_harness-0.1.0rc1/tests/test_run_persistence.py +131 -0
- ssh_agent_harness-0.1.0rc1/tests/test_step_loop_install.py +156 -0
- ssh_agent_harness-0.1.0rc1/tests/test_step_observation.py +130 -0
- ssh_agent_harness-0.1.0rc1/tests/test_step_prompt.py +76 -0
- ssh_agent_harness-0.1.0rc1/tests/test_step_split.py +206 -0
- ssh_agent_harness-0.1.0rc1/tests/test_web_entry.py +24 -0
- ssh_agent_harness-0.1.0rc1/tests/test_workspace_injection.py +152 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ssh-agent-harness
|
|
3
|
+
Version: 0.1.0rc1
|
|
4
|
+
Summary: SSH Agent Harness using local Ollama (deepseek-r1) for command generation/execution
|
|
5
|
+
Author: SSH Agent Harness Contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: ssh,agent,ollama,llm,automation,devops
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: System Administrators
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Topic :: System :: Systems Administration
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
Requires-Dist: asyncssh>=2.14
|
|
17
|
+
Requires-Dist: fastapi>=0.111
|
|
18
|
+
Requires-Dist: httpx>=0.27
|
|
19
|
+
Requires-Dist: pydantic>=2.7
|
|
20
|
+
Requires-Dist: pydantic-settings>=2.3
|
|
21
|
+
Requires-Dist: pyyaml>=6.0
|
|
22
|
+
Requires-Dist: requests>=2.31
|
|
23
|
+
Requires-Dist: typer>=0.12
|
|
24
|
+
Requires-Dist: rich>=13.7
|
|
25
|
+
Requires-Dist: sqlite-utils>=3.37
|
|
26
|
+
Requires-Dist: tenacity>=8.2
|
|
27
|
+
Requires-Dist: structlog>=24.1
|
|
28
|
+
Requires-Dist: uvicorn[standard]>=0.30
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
31
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest>=8.2; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pre-commit>=3.7; extra == "dev"
|
|
36
|
+
Requires-Dist: bandit>=1.7; extra == "dev"
|
|
37
|
+
Provides-Extra: test
|
|
38
|
+
Requires-Dist: pytest>=8.2; extra == "test"
|
|
39
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "test"
|
|
40
|
+
Requires-Dist: pytest-cov>=5.0; extra == "test"
|
|
41
|
+
Requires-Dist: fakeredis>=2.21; extra == "test"
|
|
42
|
+
|
|
43
|
+
# SSH Agent Harness
|
|
44
|
+
|
|
45
|
+
> LLM 驱动的 SSH 命令生成/执行框架,**仅本机 Web 控制台**。
|
|
46
|
+
> 支持本机 Ollama(deepseek-r1)或任意 OpenAI 兼容端点(DeepSeek/vLLM/Azure),
|
|
47
|
+
> 以 Harness 架构把「模型 + 工具 + 上下文 + 评估 + 护栏」组合成安全可审计的运维助手。
|
|
48
|
+
|
|
49
|
+
## 架构
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
53
|
+
│ SSH Agent Harness(纯 Web) │
|
|
54
|
+
├─────────────────────────────────────────────────────────────┤
|
|
55
|
+
│ Web 控制台(FastAPI + React SPA) │
|
|
56
|
+
├─────────────────────────────────────────────────────────────┤
|
|
57
|
+
│ Generator (deepseek-r1) │ 命令生成 + CoT / 多轮修复 │
|
|
58
|
+
├─────────────────────────────────────────────────────────────┤
|
|
59
|
+
│ Tool Execution Layer │ SSH / SFTP 传输 / 文件 │
|
|
60
|
+
├─────────────────────────────────────────────────────────────┤
|
|
61
|
+
│ Context & Memory │ 会话 / 服务器工作空间 / 指纹 │
|
|
62
|
+
├─────────────────────────────────────────────────────────────┤
|
|
63
|
+
│ Evaluator / Guardrails │ 安全分级 / 审批门控 / 审计 │
|
|
64
|
+
└─────────────────────────────────────────────────────────────┘
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 安装
|
|
68
|
+
|
|
69
|
+
从 PyPI 安装(**自带前端控制台**,装完直接可用):
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install ssh-agent-harness
|
|
73
|
+
ssh-agent-web # 浏览器打开 http://127.0.0.1:8000
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
开发(源码 + 热更新):
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
conda activate python312
|
|
80
|
+
pip install -e ".[dev]"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
打包与发布(本地构建、TestPyPI、正式 PyPI)见 [`docs/packaging-and-release.md`](docs/packaging-and-release.md)。
|
|
84
|
+
|
|
85
|
+
也可使用本机模型:先 `ollama serve`,再 `ollama pull deepseek-r1:1.5b`;
|
|
86
|
+
或通过环境变量指向外部 OpenAI 兼容端点(key 只走 env,勿入库):
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
export LLM_PROVIDER=openai LLM_MODEL=deepseek-chat LLM_API_KEY=***
|
|
90
|
+
# 可选:LLM_BASE_URL=https://api.deepseek.com
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 启动
|
|
94
|
+
|
|
95
|
+
**唯一入口是 Web 控制台 `ssh-agent-web`**(`ssh_agent_harness/api/__main__.py:main`):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
ssh-agent-web --db ./data/agent.db
|
|
99
|
+
# 或显式参数:
|
|
100
|
+
ssh-agent-web --host 127.0.0.1 --port 8000 --db ./data/agent.db --approval-timeout 900
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
> ⚠️ **只能用 `ssh-agent-web` 启动**。不要用 `uvicorn` 直启 app
|
|
104
|
+
> (`python -m uvicorn ssh_agent_harness.api.app:app`)——它不解析 `--db`,
|
|
105
|
+
> 会落到用户默认库并触发启动清理(误伤在飞任务)。
|
|
106
|
+
|
|
107
|
+
| 参数 | 默认值 | 说明 |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| `--host` | `127.0.0.1` | 绑定地址;默认只监听回环 |
|
|
110
|
+
| `--port` | `8000` | 监听端口 |
|
|
111
|
+
| `--db` | `settings.storage.db_path` | SQLite 路径 |
|
|
112
|
+
| `--approval-timeout` | `900.0` | 审批等待秒数;超时后审批置 expired、任务判 denied |
|
|
113
|
+
| `--static` | 包内自带的 SPA | 覆盖内置前端目录;源码开发时指向 `web/dist`,安装版无需传 |
|
|
114
|
+
|
|
115
|
+
交互式 API 文档:`http://127.0.0.1:<port>/docs`。
|
|
116
|
+
|
|
117
|
+
日志:启动时按 `settings.yaml` 的 `logging` 段装配(控制台 + 轮转文件,默认
|
|
118
|
+
`~/.ssh-agent-harness/ssh-agent.log`,`format: json` 每行一条;`~` 自动展开)。
|
|
119
|
+
|
|
120
|
+
### 前端 dev / 构建
|
|
121
|
+
|
|
122
|
+
前端控制台源码位于 `web/`(React 18 + TypeScript + Vite 5 + Ant Design 5 + react-query 5):
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# dev 双进程:只起本后端(纯 API),前端 dev server 另行启动并把 /api 反代到后端
|
|
126
|
+
ssh-agent-web --port 8000
|
|
127
|
+
npm run dev --prefix web # vite dev server(5173),/api 反代到 127.0.0.1:8000
|
|
128
|
+
|
|
129
|
+
# build 单进程:前端产出 dist,后端同一进程托管 SPA 与 /api
|
|
130
|
+
npm run build --prefix web # 产出 web/dist(不入库)
|
|
131
|
+
ssh-agent-web --port 8000 --static web/dist
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
> 后端未开 CORS,dev 模式请走 vite 的 `/api` 反向代理,勿让前端跨源直连。
|
|
135
|
+
|
|
136
|
+
## 配置
|
|
137
|
+
|
|
138
|
+
- `config/settings.yaml`:主设置(LLM provider、SSH、safety、storage/SQLite 路径)。
|
|
139
|
+
- 服务器清单存 SQLite `hosts` 表(经 Web 控制台「服务器管理」页增删改;DB 密码明文=已知接受风险,API 永不回显 password)。
|
|
140
|
+
- LLM provider 生效优先级:**UI 控制台配置 > env `LLM_*` > `settings.yaml`**。
|
|
141
|
+
- UI:「模型配置」可切 Ollama / DeepSeek API / 自定义端点,选择存 SQLite(密钥明文为已知风险、响应永不回显)。
|
|
142
|
+
- env:`LLM_PROVIDER` / `LLM_MODEL` / `LLM_BASE_URL` / `LLM_API_KEY`(或 `DEEPSEEK_API_KEY`)。
|
|
143
|
+
- `LLM_TIMEOUT`(env)可覆盖读超时(默认 600s)。
|
|
144
|
+
- 注意 `config.py` 以 YAML init 注入 Settings,`OLLAMA__*` 风格 env 覆盖**不生效**,请用 `LLM_*`。
|
|
145
|
+
- Safety:`rm -rf` 类黑名单为**硬 DENY**(审批不可越过);`systemctl stop` 等触发确认门;`kill/pkill` 默认直接放行。
|
|
146
|
+
|
|
147
|
+
## Web 功能
|
|
148
|
+
|
|
149
|
+
- **提交任务**:智能模式(默认)/ 快速模式,可设 dry-run、修复轮数(rounds)、步进循环。
|
|
150
|
+
- **审批弹窗**:危险命令挂起,弹窗内批准/拒绝;超时自动拒绝。
|
|
151
|
+
- **服务器管理**:YAML ∪ DB 合并视图,CRUD + 连通性测试。
|
|
152
|
+
- **服务器工作空间(知识库)**:按服务器维护规范与事实,供探测轮注入。
|
|
153
|
+
- **任务记录**:执行记录(sessions)与审计轨迹、run 详情时间线、按 run 撤销工作空间事实。
|
|
154
|
+
|
|
155
|
+
### run 状态机
|
|
156
|
+
|
|
157
|
+
`queued → generating → [awaiting_approval ⇄ running] → succeeded | failed | denied | cancelled`
|
|
158
|
+
(dry-run 不经审批;cancel 优先于并发完成;重启时未终结的 run 在启动清理中置 failed)
|
|
159
|
+
|
|
160
|
+
### 多轮修复(rounds)
|
|
161
|
+
|
|
162
|
+
`POST /api/runs` 请求体 `rounds`(1-10,缺省 1)大于 1 时启用反馈回路:每轮执行完毕,
|
|
163
|
+
把命令及其 stdout/stderr 组成观察回灌给模型,模型判定任务是否完成——输出 `TASK_COMPLETE`
|
|
164
|
+
是确认成功的唯一通道;未完成则给出修正命令,下一轮继续执行;轮尽仍未确认 → 终态 `failed`
|
|
165
|
+
(verdict=`exhausted`)。dry-run 同样适用。verdict 词表
|
|
166
|
+
`complete|exhausted|no-progress|repair-failed`,`null` = 终态未落判定。
|
|
167
|
+
|
|
168
|
+
### 安全边界
|
|
169
|
+
|
|
170
|
+
- **默认仅监听 127.0.0.1,且无任何鉴权**:能访问该端口即可完整操作服务器,勿暴露到公网。
|
|
171
|
+
- **明文密码为已知风险**:DB 服务器的密码明文存于 SQLite,且 `PUT /api/hosts` 请求体明文传输(仅回环缓解)。
|
|
172
|
+
- **cancel 不打断在飞命令**:只阻止后续命令执行并落终态 `cancelled`,已发出的 SSH 命令会跑完。
|
|
173
|
+
- **安全黑名单硬 DENY**:`rm -rf /`、`mkfs`、`dd of=/dev/*` 等被 gate 直接拒绝,审批无法越过。
|
|
174
|
+
- **审批超时即 denied**:等待 `--approval-timeout` 秒无人决策 → 审批 expired、任务 denied。
|
|
175
|
+
- **同一数据库文件同时只允许运行一个 `ssh-agent-web` 实例**:启动清理会把库内全部非终态 run
|
|
176
|
+
置 failed;多实例请各自指定独立 `--db`。
|
|
177
|
+
- **dry-run 不落库**:只生成不执行,也不写 session 历史。
|
|
178
|
+
- 服务器/审批响应一律脱敏:不回显密码与私钥内容。
|
|
179
|
+
|
|
180
|
+
### API 速览
|
|
181
|
+
|
|
182
|
+
| 方法与路径 | 说明 |
|
|
183
|
+
| --- | --- |
|
|
184
|
+
| `GET /api/version` | 版本号 |
|
|
185
|
+
| `GET /api/llm` | 当前生效模型 + provider 目录(presets)+ `api_key_set`;永不回显密钥 |
|
|
186
|
+
| `PUT /api/llm` `{provider, model, api_key?, adapter_type?, base_url?}` | 切换模型(UI 配置存 SQLite,优先于 env/settings) |
|
|
187
|
+
| `DELETE /api/llm` | 清除 UI 切换,回落 env/settings |
|
|
188
|
+
| `GET /api/hosts` | 服务器清单(读 SQLite `hosts` 表,脱敏) |
|
|
189
|
+
| `POST /api/hosts` | 新建 DB 服务器(同名 shadow YAML 服务器,DB 字段优先) |
|
|
190
|
+
| `PUT /api/hosts/{name}` | 更新 DB 服务器;YAML 服务器 403 |
|
|
191
|
+
| `DELETE /api/hosts/{name}` | 删除 DB 服务器行;YAML 服务器 403 |
|
|
192
|
+
| `POST /api/hosts/{name}/test` | 连通性探测,返回 `{reachable, latency_ms, error}` |
|
|
193
|
+
| `GET /api/sessions?host=&status=&limit=&offset=` | 执行历史,新→旧 |
|
|
194
|
+
| `GET /api/sessions/{id}` | 会话详情 + 按时间正序的审计轨迹 |
|
|
195
|
+
| `DELETE /api/sessions/{id}` | 删除会话及其审计 |
|
|
196
|
+
| `POST /api/runs` `{task, host, dry_run?, rounds?, step?}` | 提交后台任务 → 202 |
|
|
197
|
+
| `GET /api/runs?limit=&offset=` | run 列表(新→旧,全状态) |
|
|
198
|
+
| `GET /api/runs/{id}` | 轮询:status / current_step / commands / results |
|
|
199
|
+
| `POST /api/runs/{id}/cancel` | 取消活跃 run;终态或未知 → 409 |
|
|
200
|
+
| `GET /api/approvals?run_id=&status=pending` | 待审批收件箱(仅支持 pending) |
|
|
201
|
+
| `POST /api/approvals/{id}/decide` `{decision: approve\|deny}` | 首次决策生效并唤醒任务;重复 decide 409 |
|
|
202
|
+
| `GET/PUT/DELETE /api/knowledge/...` | 服务器工作空间(规范与事实)读写与撤销 |
|
|
203
|
+
|
|
204
|
+
## 测试与门禁
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# 后端单测(无需 Ollama/SSH)
|
|
208
|
+
conda run -n python312 --no-capture-output python -m pytest -m "not integration" -q
|
|
209
|
+
|
|
210
|
+
# 类型检查(strict)
|
|
211
|
+
mypy ssh_agent_harness
|
|
212
|
+
|
|
213
|
+
# 前端门禁
|
|
214
|
+
npm run typecheck --prefix web
|
|
215
|
+
npm run build --prefix web
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
提交门槛 = 上述四项全绿。集成测试(需 Ollama + 数据库中配置的真实服务器):
|
|
219
|
+
`conda run -n python312 --no-capture-output python -m pytest -m integration -v`。
|
|
220
|
+
|
|
221
|
+
## 目录结构(纯 Web)
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
ssh_agent_harness/
|
|
225
|
+
├── api/ # Web 后端 FastAPI 包(app/run_manager/routes/schemas/deps/__main__)
|
|
226
|
+
├── core/ # orchestrator/step_loop/multi_turn/llm 工厂/host_loader/run_persistence/...
|
|
227
|
+
├── tools/ # ssh_pool(asyncssh)/paramiko fallback/command_executor
|
|
228
|
+
├── harness/ # safety + confirmation(含 Web 挂起审批) + evaluator/rollback/protocol
|
|
229
|
+
├── storage/ # session_store(SQLite) + run_store(runs/approvals) + host_store
|
|
230
|
+
└── config.py # pydantic-settings Settings
|
|
231
|
+
web/ # React18+TS+Vite+AntD5 控制台(dist 不入库;打包前由 scripts/build_frontend.py 拷入包内 static/)
|
|
232
|
+
tests/ # 最小 Web 测试集(api smoke / web entry / config)
|
|
233
|
+
docs/superpowers/ # 黄金路径手册等
|
|
234
|
+
config/ # settings.yaml(服务器在 DB,经 Web 服务器管理页维护)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## License
|
|
238
|
+
|
|
239
|
+
MIT
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# SSH Agent Harness
|
|
2
|
+
|
|
3
|
+
> LLM 驱动的 SSH 命令生成/执行框架,**仅本机 Web 控制台**。
|
|
4
|
+
> 支持本机 Ollama(deepseek-r1)或任意 OpenAI 兼容端点(DeepSeek/vLLM/Azure),
|
|
5
|
+
> 以 Harness 架构把「模型 + 工具 + 上下文 + 评估 + 护栏」组合成安全可审计的运维助手。
|
|
6
|
+
|
|
7
|
+
## 架构
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
11
|
+
│ SSH Agent Harness(纯 Web) │
|
|
12
|
+
├─────────────────────────────────────────────────────────────┤
|
|
13
|
+
│ Web 控制台(FastAPI + React SPA) │
|
|
14
|
+
├─────────────────────────────────────────────────────────────┤
|
|
15
|
+
│ Generator (deepseek-r1) │ 命令生成 + CoT / 多轮修复 │
|
|
16
|
+
├─────────────────────────────────────────────────────────────┤
|
|
17
|
+
│ Tool Execution Layer │ SSH / SFTP 传输 / 文件 │
|
|
18
|
+
├─────────────────────────────────────────────────────────────┤
|
|
19
|
+
│ Context & Memory │ 会话 / 服务器工作空间 / 指纹 │
|
|
20
|
+
├─────────────────────────────────────────────────────────────┤
|
|
21
|
+
│ Evaluator / Guardrails │ 安全分级 / 审批门控 / 审计 │
|
|
22
|
+
└─────────────────────────────────────────────────────────────┘
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 安装
|
|
26
|
+
|
|
27
|
+
从 PyPI 安装(**自带前端控制台**,装完直接可用):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install ssh-agent-harness
|
|
31
|
+
ssh-agent-web # 浏览器打开 http://127.0.0.1:8000
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
开发(源码 + 热更新):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
conda activate python312
|
|
38
|
+
pip install -e ".[dev]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
打包与发布(本地构建、TestPyPI、正式 PyPI)见 [`docs/packaging-and-release.md`](docs/packaging-and-release.md)。
|
|
42
|
+
|
|
43
|
+
也可使用本机模型:先 `ollama serve`,再 `ollama pull deepseek-r1:1.5b`;
|
|
44
|
+
或通过环境变量指向外部 OpenAI 兼容端点(key 只走 env,勿入库):
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
export LLM_PROVIDER=openai LLM_MODEL=deepseek-chat LLM_API_KEY=***
|
|
48
|
+
# 可选:LLM_BASE_URL=https://api.deepseek.com
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 启动
|
|
52
|
+
|
|
53
|
+
**唯一入口是 Web 控制台 `ssh-agent-web`**(`ssh_agent_harness/api/__main__.py:main`):
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ssh-agent-web --db ./data/agent.db
|
|
57
|
+
# 或显式参数:
|
|
58
|
+
ssh-agent-web --host 127.0.0.1 --port 8000 --db ./data/agent.db --approval-timeout 900
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> ⚠️ **只能用 `ssh-agent-web` 启动**。不要用 `uvicorn` 直启 app
|
|
62
|
+
> (`python -m uvicorn ssh_agent_harness.api.app:app`)——它不解析 `--db`,
|
|
63
|
+
> 会落到用户默认库并触发启动清理(误伤在飞任务)。
|
|
64
|
+
|
|
65
|
+
| 参数 | 默认值 | 说明 |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| `--host` | `127.0.0.1` | 绑定地址;默认只监听回环 |
|
|
68
|
+
| `--port` | `8000` | 监听端口 |
|
|
69
|
+
| `--db` | `settings.storage.db_path` | SQLite 路径 |
|
|
70
|
+
| `--approval-timeout` | `900.0` | 审批等待秒数;超时后审批置 expired、任务判 denied |
|
|
71
|
+
| `--static` | 包内自带的 SPA | 覆盖内置前端目录;源码开发时指向 `web/dist`,安装版无需传 |
|
|
72
|
+
|
|
73
|
+
交互式 API 文档:`http://127.0.0.1:<port>/docs`。
|
|
74
|
+
|
|
75
|
+
日志:启动时按 `settings.yaml` 的 `logging` 段装配(控制台 + 轮转文件,默认
|
|
76
|
+
`~/.ssh-agent-harness/ssh-agent.log`,`format: json` 每行一条;`~` 自动展开)。
|
|
77
|
+
|
|
78
|
+
### 前端 dev / 构建
|
|
79
|
+
|
|
80
|
+
前端控制台源码位于 `web/`(React 18 + TypeScript + Vite 5 + Ant Design 5 + react-query 5):
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# dev 双进程:只起本后端(纯 API),前端 dev server 另行启动并把 /api 反代到后端
|
|
84
|
+
ssh-agent-web --port 8000
|
|
85
|
+
npm run dev --prefix web # vite dev server(5173),/api 反代到 127.0.0.1:8000
|
|
86
|
+
|
|
87
|
+
# build 单进程:前端产出 dist,后端同一进程托管 SPA 与 /api
|
|
88
|
+
npm run build --prefix web # 产出 web/dist(不入库)
|
|
89
|
+
ssh-agent-web --port 8000 --static web/dist
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
> 后端未开 CORS,dev 模式请走 vite 的 `/api` 反向代理,勿让前端跨源直连。
|
|
93
|
+
|
|
94
|
+
## 配置
|
|
95
|
+
|
|
96
|
+
- `config/settings.yaml`:主设置(LLM provider、SSH、safety、storage/SQLite 路径)。
|
|
97
|
+
- 服务器清单存 SQLite `hosts` 表(经 Web 控制台「服务器管理」页增删改;DB 密码明文=已知接受风险,API 永不回显 password)。
|
|
98
|
+
- LLM provider 生效优先级:**UI 控制台配置 > env `LLM_*` > `settings.yaml`**。
|
|
99
|
+
- UI:「模型配置」可切 Ollama / DeepSeek API / 自定义端点,选择存 SQLite(密钥明文为已知风险、响应永不回显)。
|
|
100
|
+
- env:`LLM_PROVIDER` / `LLM_MODEL` / `LLM_BASE_URL` / `LLM_API_KEY`(或 `DEEPSEEK_API_KEY`)。
|
|
101
|
+
- `LLM_TIMEOUT`(env)可覆盖读超时(默认 600s)。
|
|
102
|
+
- 注意 `config.py` 以 YAML init 注入 Settings,`OLLAMA__*` 风格 env 覆盖**不生效**,请用 `LLM_*`。
|
|
103
|
+
- Safety:`rm -rf` 类黑名单为**硬 DENY**(审批不可越过);`systemctl stop` 等触发确认门;`kill/pkill` 默认直接放行。
|
|
104
|
+
|
|
105
|
+
## Web 功能
|
|
106
|
+
|
|
107
|
+
- **提交任务**:智能模式(默认)/ 快速模式,可设 dry-run、修复轮数(rounds)、步进循环。
|
|
108
|
+
- **审批弹窗**:危险命令挂起,弹窗内批准/拒绝;超时自动拒绝。
|
|
109
|
+
- **服务器管理**:YAML ∪ DB 合并视图,CRUD + 连通性测试。
|
|
110
|
+
- **服务器工作空间(知识库)**:按服务器维护规范与事实,供探测轮注入。
|
|
111
|
+
- **任务记录**:执行记录(sessions)与审计轨迹、run 详情时间线、按 run 撤销工作空间事实。
|
|
112
|
+
|
|
113
|
+
### run 状态机
|
|
114
|
+
|
|
115
|
+
`queued → generating → [awaiting_approval ⇄ running] → succeeded | failed | denied | cancelled`
|
|
116
|
+
(dry-run 不经审批;cancel 优先于并发完成;重启时未终结的 run 在启动清理中置 failed)
|
|
117
|
+
|
|
118
|
+
### 多轮修复(rounds)
|
|
119
|
+
|
|
120
|
+
`POST /api/runs` 请求体 `rounds`(1-10,缺省 1)大于 1 时启用反馈回路:每轮执行完毕,
|
|
121
|
+
把命令及其 stdout/stderr 组成观察回灌给模型,模型判定任务是否完成——输出 `TASK_COMPLETE`
|
|
122
|
+
是确认成功的唯一通道;未完成则给出修正命令,下一轮继续执行;轮尽仍未确认 → 终态 `failed`
|
|
123
|
+
(verdict=`exhausted`)。dry-run 同样适用。verdict 词表
|
|
124
|
+
`complete|exhausted|no-progress|repair-failed`,`null` = 终态未落判定。
|
|
125
|
+
|
|
126
|
+
### 安全边界
|
|
127
|
+
|
|
128
|
+
- **默认仅监听 127.0.0.1,且无任何鉴权**:能访问该端口即可完整操作服务器,勿暴露到公网。
|
|
129
|
+
- **明文密码为已知风险**:DB 服务器的密码明文存于 SQLite,且 `PUT /api/hosts` 请求体明文传输(仅回环缓解)。
|
|
130
|
+
- **cancel 不打断在飞命令**:只阻止后续命令执行并落终态 `cancelled`,已发出的 SSH 命令会跑完。
|
|
131
|
+
- **安全黑名单硬 DENY**:`rm -rf /`、`mkfs`、`dd of=/dev/*` 等被 gate 直接拒绝,审批无法越过。
|
|
132
|
+
- **审批超时即 denied**:等待 `--approval-timeout` 秒无人决策 → 审批 expired、任务 denied。
|
|
133
|
+
- **同一数据库文件同时只允许运行一个 `ssh-agent-web` 实例**:启动清理会把库内全部非终态 run
|
|
134
|
+
置 failed;多实例请各自指定独立 `--db`。
|
|
135
|
+
- **dry-run 不落库**:只生成不执行,也不写 session 历史。
|
|
136
|
+
- 服务器/审批响应一律脱敏:不回显密码与私钥内容。
|
|
137
|
+
|
|
138
|
+
### API 速览
|
|
139
|
+
|
|
140
|
+
| 方法与路径 | 说明 |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
| `GET /api/version` | 版本号 |
|
|
143
|
+
| `GET /api/llm` | 当前生效模型 + provider 目录(presets)+ `api_key_set`;永不回显密钥 |
|
|
144
|
+
| `PUT /api/llm` `{provider, model, api_key?, adapter_type?, base_url?}` | 切换模型(UI 配置存 SQLite,优先于 env/settings) |
|
|
145
|
+
| `DELETE /api/llm` | 清除 UI 切换,回落 env/settings |
|
|
146
|
+
| `GET /api/hosts` | 服务器清单(读 SQLite `hosts` 表,脱敏) |
|
|
147
|
+
| `POST /api/hosts` | 新建 DB 服务器(同名 shadow YAML 服务器,DB 字段优先) |
|
|
148
|
+
| `PUT /api/hosts/{name}` | 更新 DB 服务器;YAML 服务器 403 |
|
|
149
|
+
| `DELETE /api/hosts/{name}` | 删除 DB 服务器行;YAML 服务器 403 |
|
|
150
|
+
| `POST /api/hosts/{name}/test` | 连通性探测,返回 `{reachable, latency_ms, error}` |
|
|
151
|
+
| `GET /api/sessions?host=&status=&limit=&offset=` | 执行历史,新→旧 |
|
|
152
|
+
| `GET /api/sessions/{id}` | 会话详情 + 按时间正序的审计轨迹 |
|
|
153
|
+
| `DELETE /api/sessions/{id}` | 删除会话及其审计 |
|
|
154
|
+
| `POST /api/runs` `{task, host, dry_run?, rounds?, step?}` | 提交后台任务 → 202 |
|
|
155
|
+
| `GET /api/runs?limit=&offset=` | run 列表(新→旧,全状态) |
|
|
156
|
+
| `GET /api/runs/{id}` | 轮询:status / current_step / commands / results |
|
|
157
|
+
| `POST /api/runs/{id}/cancel` | 取消活跃 run;终态或未知 → 409 |
|
|
158
|
+
| `GET /api/approvals?run_id=&status=pending` | 待审批收件箱(仅支持 pending) |
|
|
159
|
+
| `POST /api/approvals/{id}/decide` `{decision: approve\|deny}` | 首次决策生效并唤醒任务;重复 decide 409 |
|
|
160
|
+
| `GET/PUT/DELETE /api/knowledge/...` | 服务器工作空间(规范与事实)读写与撤销 |
|
|
161
|
+
|
|
162
|
+
## 测试与门禁
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
# 后端单测(无需 Ollama/SSH)
|
|
166
|
+
conda run -n python312 --no-capture-output python -m pytest -m "not integration" -q
|
|
167
|
+
|
|
168
|
+
# 类型检查(strict)
|
|
169
|
+
mypy ssh_agent_harness
|
|
170
|
+
|
|
171
|
+
# 前端门禁
|
|
172
|
+
npm run typecheck --prefix web
|
|
173
|
+
npm run build --prefix web
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
提交门槛 = 上述四项全绿。集成测试(需 Ollama + 数据库中配置的真实服务器):
|
|
177
|
+
`conda run -n python312 --no-capture-output python -m pytest -m integration -v`。
|
|
178
|
+
|
|
179
|
+
## 目录结构(纯 Web)
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
ssh_agent_harness/
|
|
183
|
+
├── api/ # Web 后端 FastAPI 包(app/run_manager/routes/schemas/deps/__main__)
|
|
184
|
+
├── core/ # orchestrator/step_loop/multi_turn/llm 工厂/host_loader/run_persistence/...
|
|
185
|
+
├── tools/ # ssh_pool(asyncssh)/paramiko fallback/command_executor
|
|
186
|
+
├── harness/ # safety + confirmation(含 Web 挂起审批) + evaluator/rollback/protocol
|
|
187
|
+
├── storage/ # session_store(SQLite) + run_store(runs/approvals) + host_store
|
|
188
|
+
└── config.py # pydantic-settings Settings
|
|
189
|
+
web/ # React18+TS+Vite+AntD5 控制台(dist 不入库;打包前由 scripts/build_frontend.py 拷入包内 static/)
|
|
190
|
+
tests/ # 最小 Web 测试集(api smoke / web entry / config)
|
|
191
|
+
docs/superpowers/ # 黄金路径手册等
|
|
192
|
+
config/ # settings.yaml(服务器在 DB,经 Web 服务器管理页维护)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
# setuptools>=77 is required for PEP 639 (SPDX license expression). With an older
|
|
3
|
+
# backend, `license = "MIT"` is rejected outright, and `license = {text = ...}` is
|
|
4
|
+
# deprecated until it stops working on 2027-02-18.
|
|
5
|
+
requires = ["setuptools>=77.0", "wheel"]
|
|
6
|
+
build-backend = "setuptools.build_meta"
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "ssh-agent-harness"
|
|
10
|
+
version = "0.1.0rc1"
|
|
11
|
+
description = "SSH Agent Harness using local Ollama (deepseek-r1) for command generation/execution"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.12"
|
|
14
|
+
# PEP 639: a plain SPDX expression, not a TOML table. The table form is deprecated
|
|
15
|
+
# and stops working on 2027-02-18. The matching "License ::" classifier is gone too
|
|
16
|
+
# - it is superseded by this field and setuptools warns on it.
|
|
17
|
+
license = "MIT"
|
|
18
|
+
authors = [{name = "SSH Agent Harness Contributors"}]
|
|
19
|
+
keywords = ["ssh", "agent", "ollama", "llm", "automation", "devops"]
|
|
20
|
+
classifiers = [
|
|
21
|
+
"Development Status :: 3 - Alpha",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"Intended Audience :: System Administrators",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: System :: Systems Administration",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
27
|
+
]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"asyncssh>=2.14",
|
|
30
|
+
"fastapi>=0.111",
|
|
31
|
+
# httpx is a RUNTIME dependency, not just a test one: core/ollama_client.py,
|
|
32
|
+
# core/model_adapter.py, core/package_manager.py and two siblings import it at
|
|
33
|
+
# module level. Leaving it in the `test` extra produced wheels that crashed on
|
|
34
|
+
# import with ModuleNotFoundError for anyone who installed without dev extras.
|
|
35
|
+
"httpx>=0.27",
|
|
36
|
+
"pydantic>=2.7",
|
|
37
|
+
"pydantic-settings>=2.3",
|
|
38
|
+
"pyyaml>=6.0",
|
|
39
|
+
"requests>=2.31",
|
|
40
|
+
"typer>=0.12",
|
|
41
|
+
"rich>=13.7",
|
|
42
|
+
"sqlite-utils>=3.37",
|
|
43
|
+
"tenacity>=8.2",
|
|
44
|
+
"structlog>=24.1",
|
|
45
|
+
"uvicorn[standard]>=0.30",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.optional-dependencies]
|
|
49
|
+
dev = [
|
|
50
|
+
"ruff>=0.4",
|
|
51
|
+
"mypy>=1.10",
|
|
52
|
+
"pytest>=8.2",
|
|
53
|
+
"pytest-asyncio>=0.23",
|
|
54
|
+
"pytest-cov>=5.0",
|
|
55
|
+
"pre-commit>=3.7",
|
|
56
|
+
"bandit>=1.7",
|
|
57
|
+
]
|
|
58
|
+
test = [
|
|
59
|
+
"pytest>=8.2",
|
|
60
|
+
"pytest-asyncio>=0.23",
|
|
61
|
+
"pytest-cov>=5.0",
|
|
62
|
+
"fakeredis>=2.21",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[project.scripts]
|
|
66
|
+
ssh-agent-web = "ssh_agent_harness.api.__main__:main"
|
|
67
|
+
|
|
68
|
+
[tool.setuptools.packages.find]
|
|
69
|
+
where = ["."]
|
|
70
|
+
include = ["ssh_agent_harness*"]
|
|
71
|
+
|
|
72
|
+
[tool.setuptools.package-data]
|
|
73
|
+
# The SPA build is copied into the package before `python -m build`
|
|
74
|
+
# (scripts/build_frontend.py). It must ship INSIDE the wheel: the console is the
|
|
75
|
+
# only face of this project, and a pip install that serves 404 at / is a broken
|
|
76
|
+
# install, not a missing optional.
|
|
77
|
+
"ssh_agent_harness.api" = ["static/**/*"]
|
|
78
|
+
# Built-in config. `get_settings()` used to read ../config/settings.yaml, which
|
|
79
|
+
# does not exist once installed (it resolved to site-packages/config/), so an
|
|
80
|
+
# installed copy silently ran on hardcoded class defaults. Shipping the file
|
|
81
|
+
# inside the package is what makes the config layer work outside a checkout.
|
|
82
|
+
"ssh_agent_harness" = ["default_settings.yaml"]
|
|
83
|
+
|
|
84
|
+
[tool.ruff]
|
|
85
|
+
target-version = "py312"
|
|
86
|
+
line-length = 100
|
|
87
|
+
select = [
|
|
88
|
+
"E", # pycodestyle errors
|
|
89
|
+
"W", # pycodestyle warnings
|
|
90
|
+
"F", # pyflakes
|
|
91
|
+
"I", # isort
|
|
92
|
+
"B", # flake8-bugbear
|
|
93
|
+
"C4", # flake8-comprehensions
|
|
94
|
+
"UP", # pyupgrade
|
|
95
|
+
"PT", # flake8-pytest-style
|
|
96
|
+
"TRY", # tryceratops
|
|
97
|
+
"SIM", # flake8-simplify
|
|
98
|
+
"TID", # flake8-tidy-imports
|
|
99
|
+
"ARG", # flake8-unused-arguments
|
|
100
|
+
"PTH", # flake8-use-pathlib
|
|
101
|
+
"ERA", # eradicate
|
|
102
|
+
"PL", # pylint
|
|
103
|
+
"RET", # flake8-return
|
|
104
|
+
]
|
|
105
|
+
ignore = [
|
|
106
|
+
"S101", # assert used (ok in tests)
|
|
107
|
+
"TRY003", # avoid specifying long messages outside the exception class
|
|
108
|
+
]
|
|
109
|
+
per-file-ignores = { "tests/*" = ["S101", "ARG001", "ARG002", "PT011"] }
|
|
110
|
+
exclude = [".venv", "dist", "build", "*.egg-info", "__pycache__"]
|
|
111
|
+
|
|
112
|
+
[tool.ruff.format]
|
|
113
|
+
quote-style = "double"
|
|
114
|
+
indent-style = "space"
|
|
115
|
+
skip-magic-trailing-comma = false
|
|
116
|
+
line-ending = "lf"
|
|
117
|
+
|
|
118
|
+
[tool.mypy]
|
|
119
|
+
python_version = "3.12"
|
|
120
|
+
strict = true
|
|
121
|
+
warn_return_any = true
|
|
122
|
+
warn_unused_configs = true
|
|
123
|
+
disallow_untyped_defs = true
|
|
124
|
+
disallow_incomplete_defs = true
|
|
125
|
+
check_untyped_defs = true
|
|
126
|
+
no_implicit_optional = true
|
|
127
|
+
show_error_codes = true
|
|
128
|
+
pretty = true
|
|
129
|
+
exclude = [".venv", "dist", "build", ".*\\.egg-info", "__pycache__", "tests"]
|
|
130
|
+
|
|
131
|
+
[tool.pytest.ini_options]
|
|
132
|
+
asyncio_mode = "auto"
|
|
133
|
+
testpaths = ["tests"]
|
|
134
|
+
python_files = ["test_*.py"]
|
|
135
|
+
python_classes = ["Test*"]
|
|
136
|
+
python_functions = ["test_*"]
|
|
137
|
+
addopts = "-v --tb=short --strict-markers"
|
|
138
|
+
markers = [
|
|
139
|
+
"unit: Unit tests",
|
|
140
|
+
"integration: Integration tests (require Ollama/SSH)",
|
|
141
|
+
"slow: Slow tests",
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
[tool.bandit]
|
|
145
|
+
exclude_dirs = ["tests", ".venv", "dist", "build"]
|
|
146
|
+
skips = ["B101", "B104", "B108", "B603"]
|
|
147
|
+
|
|
148
|
+
[tool.coverage.run]
|
|
149
|
+
source = ["ssh_agent_harness"]
|
|
150
|
+
omit = ["tests/*", "*/__pycache__/*"]
|
|
151
|
+
|
|
152
|
+
[tool.coverage.report]
|
|
153
|
+
exclude_lines = [
|
|
154
|
+
"pragma: no cover",
|
|
155
|
+
"def __repr__",
|
|
156
|
+
"raise AssertionError",
|
|
157
|
+
"raise NotImplementedError",
|
|
158
|
+
"if __name__ == .__main__.:",
|
|
159
|
+
]
|
|
160
|
+
precision = 2
|
|
161
|
+
show_missing = true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Web API package (FastAPI)."""
|