sec-gofer-agent 0.1.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.
- sec_gofer_agent-0.1.0/PKG-INFO +142 -0
- sec_gofer_agent-0.1.0/README.md +122 -0
- sec_gofer_agent-0.1.0/pyproject.toml +38 -0
- sec_gofer_agent-0.1.0/pyproject.toml.orig +42 -0
- sec_gofer_agent-0.1.0/sec/__init__.py +193 -0
- sec_gofer_agent-0.1.0/sec/__main__.py +7 -0
- sec_gofer_agent-0.1.0/sec/_runtime/__init__.py +9 -0
- sec_gofer_agent-0.1.0/sec/_runtime/budget.py +186 -0
- sec_gofer_agent-0.1.0/sec/_runtime/control.py +251 -0
- sec_gofer_agent-0.1.0/sec/_runtime/event_stream.py +173 -0
- sec_gofer_agent-0.1.0/sec/_runtime/harness.py +262 -0
- sec_gofer_agent-0.1.0/sec/_runtime/loop.py +418 -0
- sec_gofer_agent-0.1.0/sec/_runtime/metrics.py +84 -0
- sec_gofer_agent-0.1.0/sec/_runtime/model_generation.py +268 -0
- sec_gofer_agent-0.1.0/sec/_runtime/recovery.py +48 -0
- sec_gofer_agent-0.1.0/sec/_runtime/retry.py +24 -0
- sec_gofer_agent-0.1.0/sec/_runtime/state.py +64 -0
- sec_gofer_agent-0.1.0/sec/_runtime/subscriptions.py +149 -0
- sec_gofer_agent-0.1.0/sec/_runtime/tool_dispatch.py +320 -0
- sec_gofer_agent-0.1.0/sec/_types/__init__.py +235 -0
- sec_gofer_agent-0.1.0/sec/_types/approvals.py +73 -0
- sec_gofer_agent-0.1.0/sec/_types/checkpoints.py +6 -0
- sec_gofer_agent-0.1.0/sec/_types/content.py +159 -0
- sec_gofer_agent-0.1.0/sec/_types/context.py +21 -0
- sec_gofer_agent-0.1.0/sec/_types/events.py +341 -0
- sec_gofer_agent-0.1.0/sec/_types/execution.py +24 -0
- sec_gofer_agent-0.1.0/sec/_types/extensions.py +50 -0
- sec_gofer_agent-0.1.0/sec/_types/json.py +10 -0
- sec_gofer_agent-0.1.0/sec/_types/limits.py +52 -0
- sec_gofer_agent-0.1.0/sec/_types/messages.py +616 -0
- sec_gofer_agent-0.1.0/sec/_types/models.py +352 -0
- sec_gofer_agent-0.1.0/sec/_types/objects.py +21 -0
- sec_gofer_agent-0.1.0/sec/_types/observations.py +64 -0
- sec_gofer_agent-0.1.0/sec/_types/policy.py +97 -0
- sec_gofer_agent-0.1.0/sec/_types/providers.py +47 -0
- sec_gofer_agent-0.1.0/sec/_types/results.py +57 -0
- sec_gofer_agent-0.1.0/sec/_types/session.py +354 -0
- sec_gofer_agent-0.1.0/sec/_types/storage.py +78 -0
- sec_gofer_agent-0.1.0/sec/_types/streaming.py +25 -0
- sec_gofer_agent-0.1.0/sec/agent/__init__.py +7 -0
- sec_gofer_agent-0.1.0/sec/agent/definition.py +33 -0
- sec_gofer_agent-0.1.0/sec/agent/run.py +78 -0
- sec_gofer_agent-0.1.0/sec/agent/session.py +252 -0
- sec_gofer_agent-0.1.0/sec/apis/__init__.py +213 -0
- sec_gofer_agent-0.1.0/sec/apis/client.py +640 -0
- sec_gofer_agent-0.1.0/sec/apis/sync.py +281 -0
- sec_gofer_agent-0.1.0/sec/apps/__init__.py +40 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/__init__.py +18 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/app.py +982 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/chat_commands.py +335 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/command_catalog.py +95 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/presentation.py +163 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/resources.py +204 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/session_io.py +156 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/slash_commands.py +121 -0
- sec_gofer_agent-0.1.0/sec/apps/cli/terminal.py +770 -0
- sec_gofer_agent-0.1.0/sec/apps/dashboard/__init__.py +5 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/README.md +104 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/__init__.py +19 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/__main__.py +5 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/app.py +36 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/appearance.py +15 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/assets/icon.png +0 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/floating_ball.py +99 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/qt_plugins.py +39 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/runtime.py +336 -0
- sec_gofer_agent-0.1.0/sec/apps/desktop/window.py +628 -0
- sec_gofer_agent-0.1.0/sec/apps/extension_ui.py +124 -0
- sec_gofer_agent-0.1.0/sec/config.py +626 -0
- sec_gofer_agent-0.1.0/sec/exceptions.py +112 -0
- sec_gofer_agent-0.1.0/sec/executors/__init__.py +11 -0
- sec_gofer_agent-0.1.0/sec/executors/local.py +34 -0
- sec_gofer_agent-0.1.0/sec/extensions/__init__.py +25 -0
- sec_gofer_agent-0.1.0/sec/extensions/api.py +197 -0
- sec_gofer_agent-0.1.0/sec/extensions/manager.py +111 -0
- sec_gofer_agent-0.1.0/sec/integrations/__init__.py +7 -0
- sec_gofer_agent-0.1.0/sec/integrations/mcp.py +7 -0
- sec_gofer_agent-0.1.0/sec/memory/__init__.py +13 -0
- sec_gofer_agent-0.1.0/sec/memory/context_builder.py +296 -0
- sec_gofer_agent-0.1.0/sec/policies/__init__.py +11 -0
- sec_gofer_agent-0.1.0/sec/policies/modes.py +115 -0
- sec_gofer_agent-0.1.0/sec/policies/rules.py +35 -0
- sec_gofer_agent-0.1.0/sec/providers/__init__.py +6 -0
- sec_gofer_agent-0.1.0/sec/providers/_errors.py +50 -0
- sec_gofer_agent-0.1.0/sec/providers/anthropic.py +284 -0
- sec_gofer_agent-0.1.0/sec/providers/openai.py +357 -0
- sec_gofer_agent-0.1.0/sec/py.typed +0 -0
- sec_gofer_agent-0.1.0/sec/storage/__init__.py +19 -0
- sec_gofer_agent-0.1.0/sec/storage/resources/__init__.py +5 -0
- sec_gofer_agent-0.1.0/sec/storage/resources/database.py +111 -0
- sec_gofer_agent-0.1.0/sec/storage/session_store/__init__.py +17 -0
- sec_gofer_agent-0.1.0/sec/storage/session_store/codec.py +329 -0
- sec_gofer_agent-0.1.0/sec/storage/session_store/database/__init__.py +5 -0
- sec_gofer_agent-0.1.0/sec/storage/session_store/database/schema.py +79 -0
- sec_gofer_agent-0.1.0/sec/storage/session_store/database/store.py +312 -0
- sec_gofer_agent-0.1.0/sec/storage/session_store/in_memory/__init__.py +5 -0
- sec_gofer_agent-0.1.0/sec/storage/session_store/in_memory/store.py +151 -0
- sec_gofer_agent-0.1.0/sec/storage/session_store/store.py +63 -0
- sec_gofer_agent-0.1.0/sec/tools/__init__.py +18 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/__init__.py +42 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/bash.py +106 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/common.py +90 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/edit.py +41 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/find.py +38 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/grep.py +61 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/ls.py +46 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/read.py +35 -0
- sec_gofer_agent-0.1.0/sec/tools/_builtins/write.py +34 -0
- sec_gofer_agent-0.1.0/sec/tools/registry.py +49 -0
- sec_gofer_agent-0.1.0/sec/tools/tool.py +199 -0
- sec_gofer_agent-0.1.0/sec/utils/__init__.py +5 -0
- sec_gofer_agent-0.1.0/sec/utils/lock.py +50 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: sec-gofer-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Your gofer. A second you, in a second.
|
|
5
|
+
Author: Colin-zh
|
|
6
|
+
Author-email: Colin-zh <colin_zh@outlook.com>
|
|
7
|
+
Requires-Dist: aiosqlite>=0.22.1
|
|
8
|
+
Requires-Dist: anthropic>=1.13.0
|
|
9
|
+
Requires-Dist: openai>=3.29.0
|
|
10
|
+
Requires-Dist: python-dotenv>=1.2.4
|
|
11
|
+
Requires-Dist: rich>=15.0.0
|
|
12
|
+
Requires-Dist: sqlalchemy[asyncio]>=2.0.48,<2.1
|
|
13
|
+
Requires-Dist: pyside6>=6.8.0 ; extra == 'desktop'
|
|
14
|
+
Requires-Dist: asyncpg>=0.30.0 ; extra == 'opengauss'
|
|
15
|
+
Requires-Dist: opengauss-sqlalchemy>=2.4.0 ; extra == 'opengauss'
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
|
+
Provides-Extra: desktop
|
|
18
|
+
Provides-Extra: opengauss
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Sec
|
|
22
|
+
|
|
23
|
+
**Your gofer. A second you, in a second.**
|
|
24
|
+
|
|
25
|
+
Sec 是一个可编程的 AI Agent SDK,也提供终端聊天 CLI。你可以直接用 CLI 与模型协作,也可以通过 Python Client 将 Sec 集成到自己的应用,或用 Extension 添加工具、命令和运行时能力。
|
|
26
|
+
|
|
27
|
+
## 快速开始
|
|
28
|
+
|
|
29
|
+
要求 Python 3.12 和 [uv](https://docs.astral.sh/uv/)。
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
uv python install 3.12
|
|
33
|
+
uv sync
|
|
34
|
+
cp .env.example .env
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
编辑 `.env`,选择 OpenAI 或 Anthropic Provider,并填写模型名和 API key。也可以设置通用变量 `SEC_PROVIDER`、`SEC_MODEL`、`SEC_API_KEY`。不要提交包含真实凭据的 `.env`。
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
uv run python -m sec
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
CLI 支持交互式聊天、Session 管理、内置工作区工具和权限模式。第一次使用建议保持默认的 `normal` 模式;工具执行前会请求确认。详见[终端 CLI 教程](docs/tutorials/03-use-the-cli.md)和[权限与工具教程](docs/tutorials/06-tools-permissions-and-approvals.md)。
|
|
44
|
+
|
|
45
|
+
## 可选桌面应用
|
|
46
|
+
|
|
47
|
+
桌面应用位于 `sec/apps/desktop/`,与 CLI/SDK 共用主包和环境,Qt 仅作为
|
|
48
|
+
`desktop` 可选依赖。当前发行包名是 `sec-gofer-agent`,默认安装不包含 Qt:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
pip install sec-gofer-agent
|
|
52
|
+
pip install 'sec-gofer-agent[desktop]' # 需要桌面能力时安装
|
|
53
|
+
sec-desktop
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
仓库开发运行:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
uv sync --extra desktop --no-editable
|
|
60
|
+
uv run --no-sync sec-desktop
|
|
61
|
+
# 或 uv run --no-sync python -m sec.apps.desktop
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
支持大屏专注/悬浮球切换、会话恢复、流式回答、工具审批及 CLI 斜杠命令。
|
|
65
|
+
Extension 安装到同一 `.venv` 后,可通过 `--extension <name>` 启用。
|
|
66
|
+
详细说明见[桌面应用](sec/apps/desktop/README.md)。
|
|
67
|
+
|
|
68
|
+
## CLI 界面速览
|
|
69
|
+
|
|
70
|
+
交互式终端启动后会先显示当前运行环境摘要,再进入可编辑的 `you >` 输入框。下图为字段示意,实际路径、模型、Session ID 和资源数量取决于本机配置:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
╭ Sec v0.1.0 — Your gofer. A second you, in a second.
|
|
74
|
+
│
|
|
75
|
+
│ ⌂ Working directory /path/to/project
|
|
76
|
+
│ ◈ Model your-model
|
|
77
|
+
│ # Session <session-id>
|
|
78
|
+
│ ◉ Tool mode normal
|
|
79
|
+
│ ✦ Resources 1 Skills · 1 Prompts
|
|
80
|
+
│
|
|
81
|
+
│ Ctrl+C cancel Run · Ctrl+D exit · Tab complete · /help commands
|
|
82
|
+
│ Press Ctrl+O for full startup help and loaded resources.
|
|
83
|
+
╰
|
|
84
|
+
you >
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
发出消息后,Sec 会显示流式回答和 Run/工具状态。工具需要审批时,会显示工具名称、参数和策略原因,等待输入 `y` 或 `n`;默认拒绝。交互终端支持多行编辑和命令补全:Enter 发送,Alt+Enter 换行,Run 运行中按 Alt+S steer 当前 Run,按 Alt+F 将当前输入排到 Run 之后,Tab 补全命令。Run 运行中直接发送普通文本也会排为 follow-up。
|
|
88
|
+
|
|
89
|
+
终端不支持原始按键输入时会退回逐行输入界面;非交互式管道输入没有审批提示界面,需确认的工具调用会拒绝。详见[CLI 界面与操作指南](docs/tutorials/03-use-the-cli.md)。
|
|
90
|
+
|
|
91
|
+
## Python Client 一分钟
|
|
92
|
+
|
|
93
|
+
普通脚本可从同步 `SecClient` 开始。Client 上下文中连续调用 `run()` 会沿用同一个 Session 历史:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from sec.apis import SecClient
|
|
97
|
+
|
|
98
|
+
with SecClient("assistant", "遵循用户指令。") as client:
|
|
99
|
+
first = client.run("解释当前项目的入口。")
|
|
100
|
+
print(first.text)
|
|
101
|
+
print("Session:", client.session.id)
|
|
102
|
+
|
|
103
|
+
second = client.run("再说明它如何加载配置。")
|
|
104
|
+
print(second.text)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
需要 asyncio、流式事件、Session 恢复或精细 Run 控制时使用 `AsyncSecClient`。两类 Client 都应使用上下文管理器;失败通过异常传播,成功的 `RunResult` 提供文本、调用次数和用量信息。SDK Client 默认不附加 CLI 的内置文件/Bash 工具;通过 `tools=` 或 Extension 显式提供工具。完整示例见[同步 Client](docs/tutorials/07-build-a-sync-client.md)、[异步与流式 Client](docs/tutorials/08-build-an-async-streaming-client.md)和[Run 控制](docs/tutorials/09-control-runs-and-consume-events.md)。
|
|
108
|
+
|
|
109
|
+
## 选择使用方式
|
|
110
|
+
|
|
111
|
+
- **使用终端聊天**:从[安装与第一次对话](docs/tutorials/01-install-and-first-chat.md)开始。
|
|
112
|
+
- **集成 Python 应用**:查看[同步 Client](docs/tutorials/07-build-a-sync-client.md)或[异步与流式 Client](docs/tutorials/08-build-an-async-streaming-client.md)。
|
|
113
|
+
- **扩展 Sec**:跟随[创建第一个 Extension](docs/tutorials/11-create-your-first-extension.md)。
|
|
114
|
+
- **查询配置项**:查看[配置参数参考](docs/reference/configuration.md)。
|
|
115
|
+
- **浏览全部教程**:进入[教程首页](docs/tutorials/00-homepage.md)。
|
|
116
|
+
|
|
117
|
+
## 当前功能
|
|
118
|
+
|
|
119
|
+
- **CLI**:交互式与管道式对话、命令补全、Run 控制、权限模式、Session 分支和便携式导入/导出。
|
|
120
|
+
- **Python SDK**:同步和异步 Client、流式响应、工具调用、Run 事件与运行控制。
|
|
121
|
+
- **工具与策略**:类型化工具定义、参数校验、工作区内置文件工具、工具审批及可替换 Policy/Executor。
|
|
122
|
+
- **Skills 与 Prompts**:从 Markdown 文件加载可复用的操作说明和提示模板。
|
|
123
|
+
- **Extensions**:通过 Python entry point 显式启用,可注册工具、Provider、Policy、SessionStore、UI handler、CLI 命令和 Run hooks。
|
|
124
|
+
- **Session 与存储**:进程内或 SQLite SessionStore、会话恢复和分支操作;提供可实现的 ObjectStore 协议。
|
|
125
|
+
- **运行可靠性**:模型及安全声明工具的有限重试、每轮调用预算、用量统计和可选上下文压缩。
|
|
126
|
+
|
|
127
|
+
## 安全与支持边界
|
|
128
|
+
|
|
129
|
+
- `plan`、`normal`、`auto` 模式对工具调用应用不同策略。`auto` 仅自动允许工作区范围内的内置文件工具;Bash 和其他高风险操作仍需审批。
|
|
130
|
+
- 内置 Bash 以当前用户权限在主机上运行,**不是安全沙箱**。不要执行不可信命令。
|
|
131
|
+
- CLI 的 Skills 和 Prompts 是提示文本,不执行 Markdown 文件中的代码;Extension 则是可执行 Python 包,只应启用可信扩展。
|
|
132
|
+
- 当前 Provider 支持 OpenAI 与 Anthropic 的文本和工具交互;多模态内容尚未适配。
|
|
133
|
+
- MCP 连接管理、Dashboard 和云厂商 ObjectStore 适配器尚未实现。`/share`、`/thinking` 和手动 `/compact` 也尚不可用。
|
|
134
|
+
|
|
135
|
+
## 开发与测试
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
uv sync
|
|
139
|
+
uv run python -m unittest discover -s tests -v
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
项目使用 `uv.lock` 锁定依赖。修改依赖后请一并提交 `pyproject.toml` 和 `uv.lock`。
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Sec
|
|
2
|
+
|
|
3
|
+
**Your gofer. A second you, in a second.**
|
|
4
|
+
|
|
5
|
+
Sec 是一个可编程的 AI Agent SDK,也提供终端聊天 CLI。你可以直接用 CLI 与模型协作,也可以通过 Python Client 将 Sec 集成到自己的应用,或用 Extension 添加工具、命令和运行时能力。
|
|
6
|
+
|
|
7
|
+
## 快速开始
|
|
8
|
+
|
|
9
|
+
要求 Python 3.12 和 [uv](https://docs.astral.sh/uv/)。
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
uv python install 3.12
|
|
13
|
+
uv sync
|
|
14
|
+
cp .env.example .env
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
编辑 `.env`,选择 OpenAI 或 Anthropic Provider,并填写模型名和 API key。也可以设置通用变量 `SEC_PROVIDER`、`SEC_MODEL`、`SEC_API_KEY`。不要提交包含真实凭据的 `.env`。
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
uv run python -m sec
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
CLI 支持交互式聊天、Session 管理、内置工作区工具和权限模式。第一次使用建议保持默认的 `normal` 模式;工具执行前会请求确认。详见[终端 CLI 教程](docs/tutorials/03-use-the-cli.md)和[权限与工具教程](docs/tutorials/06-tools-permissions-and-approvals.md)。
|
|
24
|
+
|
|
25
|
+
## 可选桌面应用
|
|
26
|
+
|
|
27
|
+
桌面应用位于 `sec/apps/desktop/`,与 CLI/SDK 共用主包和环境,Qt 仅作为
|
|
28
|
+
`desktop` 可选依赖。当前发行包名是 `sec-gofer-agent`,默认安装不包含 Qt:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pip install sec-gofer-agent
|
|
32
|
+
pip install 'sec-gofer-agent[desktop]' # 需要桌面能力时安装
|
|
33
|
+
sec-desktop
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
仓库开发运行:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
uv sync --extra desktop --no-editable
|
|
40
|
+
uv run --no-sync sec-desktop
|
|
41
|
+
# 或 uv run --no-sync python -m sec.apps.desktop
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
支持大屏专注/悬浮球切换、会话恢复、流式回答、工具审批及 CLI 斜杠命令。
|
|
45
|
+
Extension 安装到同一 `.venv` 后,可通过 `--extension <name>` 启用。
|
|
46
|
+
详细说明见[桌面应用](sec/apps/desktop/README.md)。
|
|
47
|
+
|
|
48
|
+
## CLI 界面速览
|
|
49
|
+
|
|
50
|
+
交互式终端启动后会先显示当前运行环境摘要,再进入可编辑的 `you >` 输入框。下图为字段示意,实际路径、模型、Session ID 和资源数量取决于本机配置:
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
╭ Sec v0.1.0 — Your gofer. A second you, in a second.
|
|
54
|
+
│
|
|
55
|
+
│ ⌂ Working directory /path/to/project
|
|
56
|
+
│ ◈ Model your-model
|
|
57
|
+
│ # Session <session-id>
|
|
58
|
+
│ ◉ Tool mode normal
|
|
59
|
+
│ ✦ Resources 1 Skills · 1 Prompts
|
|
60
|
+
│
|
|
61
|
+
│ Ctrl+C cancel Run · Ctrl+D exit · Tab complete · /help commands
|
|
62
|
+
│ Press Ctrl+O for full startup help and loaded resources.
|
|
63
|
+
╰
|
|
64
|
+
you >
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
发出消息后,Sec 会显示流式回答和 Run/工具状态。工具需要审批时,会显示工具名称、参数和策略原因,等待输入 `y` 或 `n`;默认拒绝。交互终端支持多行编辑和命令补全:Enter 发送,Alt+Enter 换行,Run 运行中按 Alt+S steer 当前 Run,按 Alt+F 将当前输入排到 Run 之后,Tab 补全命令。Run 运行中直接发送普通文本也会排为 follow-up。
|
|
68
|
+
|
|
69
|
+
终端不支持原始按键输入时会退回逐行输入界面;非交互式管道输入没有审批提示界面,需确认的工具调用会拒绝。详见[CLI 界面与操作指南](docs/tutorials/03-use-the-cli.md)。
|
|
70
|
+
|
|
71
|
+
## Python Client 一分钟
|
|
72
|
+
|
|
73
|
+
普通脚本可从同步 `SecClient` 开始。Client 上下文中连续调用 `run()` 会沿用同一个 Session 历史:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from sec.apis import SecClient
|
|
77
|
+
|
|
78
|
+
with SecClient("assistant", "遵循用户指令。") as client:
|
|
79
|
+
first = client.run("解释当前项目的入口。")
|
|
80
|
+
print(first.text)
|
|
81
|
+
print("Session:", client.session.id)
|
|
82
|
+
|
|
83
|
+
second = client.run("再说明它如何加载配置。")
|
|
84
|
+
print(second.text)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
需要 asyncio、流式事件、Session 恢复或精细 Run 控制时使用 `AsyncSecClient`。两类 Client 都应使用上下文管理器;失败通过异常传播,成功的 `RunResult` 提供文本、调用次数和用量信息。SDK Client 默认不附加 CLI 的内置文件/Bash 工具;通过 `tools=` 或 Extension 显式提供工具。完整示例见[同步 Client](docs/tutorials/07-build-a-sync-client.md)、[异步与流式 Client](docs/tutorials/08-build-an-async-streaming-client.md)和[Run 控制](docs/tutorials/09-control-runs-and-consume-events.md)。
|
|
88
|
+
|
|
89
|
+
## 选择使用方式
|
|
90
|
+
|
|
91
|
+
- **使用终端聊天**:从[安装与第一次对话](docs/tutorials/01-install-and-first-chat.md)开始。
|
|
92
|
+
- **集成 Python 应用**:查看[同步 Client](docs/tutorials/07-build-a-sync-client.md)或[异步与流式 Client](docs/tutorials/08-build-an-async-streaming-client.md)。
|
|
93
|
+
- **扩展 Sec**:跟随[创建第一个 Extension](docs/tutorials/11-create-your-first-extension.md)。
|
|
94
|
+
- **查询配置项**:查看[配置参数参考](docs/reference/configuration.md)。
|
|
95
|
+
- **浏览全部教程**:进入[教程首页](docs/tutorials/00-homepage.md)。
|
|
96
|
+
|
|
97
|
+
## 当前功能
|
|
98
|
+
|
|
99
|
+
- **CLI**:交互式与管道式对话、命令补全、Run 控制、权限模式、Session 分支和便携式导入/导出。
|
|
100
|
+
- **Python SDK**:同步和异步 Client、流式响应、工具调用、Run 事件与运行控制。
|
|
101
|
+
- **工具与策略**:类型化工具定义、参数校验、工作区内置文件工具、工具审批及可替换 Policy/Executor。
|
|
102
|
+
- **Skills 与 Prompts**:从 Markdown 文件加载可复用的操作说明和提示模板。
|
|
103
|
+
- **Extensions**:通过 Python entry point 显式启用,可注册工具、Provider、Policy、SessionStore、UI handler、CLI 命令和 Run hooks。
|
|
104
|
+
- **Session 与存储**:进程内或 SQLite SessionStore、会话恢复和分支操作;提供可实现的 ObjectStore 协议。
|
|
105
|
+
- **运行可靠性**:模型及安全声明工具的有限重试、每轮调用预算、用量统计和可选上下文压缩。
|
|
106
|
+
|
|
107
|
+
## 安全与支持边界
|
|
108
|
+
|
|
109
|
+
- `plan`、`normal`、`auto` 模式对工具调用应用不同策略。`auto` 仅自动允许工作区范围内的内置文件工具;Bash 和其他高风险操作仍需审批。
|
|
110
|
+
- 内置 Bash 以当前用户权限在主机上运行,**不是安全沙箱**。不要执行不可信命令。
|
|
111
|
+
- CLI 的 Skills 和 Prompts 是提示文本,不执行 Markdown 文件中的代码;Extension 则是可执行 Python 包,只应启用可信扩展。
|
|
112
|
+
- 当前 Provider 支持 OpenAI 与 Anthropic 的文本和工具交互;多模态内容尚未适配。
|
|
113
|
+
- MCP 连接管理、Dashboard 和云厂商 ObjectStore 适配器尚未实现。`/share`、`/thinking` 和手动 `/compact` 也尚不可用。
|
|
114
|
+
|
|
115
|
+
## 开发与测试
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
uv sync
|
|
119
|
+
uv run python -m unittest discover -s tests -v
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
项目使用 `uv.lock` 锁定依赖。修改依赖后请一并提交 `pyproject.toml` 和 `uv.lock`。
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sec-gofer-agent"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Your gofer. A second you, in a second."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"aiosqlite>=0.22.1",
|
|
9
|
+
"anthropic>=1.13.0",
|
|
10
|
+
"openai>=3.29.0",
|
|
11
|
+
"python-dotenv>=1.2.4",
|
|
12
|
+
"rich>=15.0.0",
|
|
13
|
+
"sqlalchemy[asyncio]>=2.0.48,<2.1",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[[project.authors]]
|
|
17
|
+
name = "Colin-zh"
|
|
18
|
+
email = "colin_zh@outlook.com"
|
|
19
|
+
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
desktop = ["PySide6>=6.8.0"]
|
|
22
|
+
opengauss = [
|
|
23
|
+
"asyncpg>=0.30.0",
|
|
24
|
+
"opengauss-sqlalchemy>=2.4.0",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
sec = "sec.__main__:main"
|
|
29
|
+
sec-desktop = "sec.apps.desktop:main"
|
|
30
|
+
|
|
31
|
+
[build-system]
|
|
32
|
+
requires = ["uv_build>=0.12.21,<0.13.0"]
|
|
33
|
+
build-backend = "uv_build"
|
|
34
|
+
|
|
35
|
+
[tool.uv.build-backend]
|
|
36
|
+
module-name = "sec"
|
|
37
|
+
module-root = "."
|
|
38
|
+
source-exclude = ["**/.DS_Store"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sec-gofer-agent"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Your gofer. A second you, in a second."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Colin-zh", email = "colin_zh@outlook.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"aiosqlite>=0.22.1",
|
|
12
|
+
"anthropic>=1.13.0",
|
|
13
|
+
"openai>=3.29.0",
|
|
14
|
+
"python-dotenv>=1.2.4",
|
|
15
|
+
"rich>=15.0.0",
|
|
16
|
+
"sqlalchemy[asyncio]>=2.0.48,<2.1",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
desktop = [
|
|
21
|
+
"PySide6>=6.8.0",
|
|
22
|
+
]
|
|
23
|
+
opengauss = [
|
|
24
|
+
"asyncpg>=0.30.0",
|
|
25
|
+
"opengauss-sqlalchemy>=2.4.0",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
sec = "sec.__main__:main"
|
|
30
|
+
sec-desktop = "sec.apps.desktop:main"
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["uv_build>=0.12.21,<0.13.0"]
|
|
34
|
+
build-backend = "uv_build"
|
|
35
|
+
|
|
36
|
+
# pyproject.toml
|
|
37
|
+
[tool.uv.build-backend]
|
|
38
|
+
module-name = "sec"
|
|
39
|
+
module-root = "."
|
|
40
|
+
source-exclude = [
|
|
41
|
+
"**/.DS_Store",
|
|
42
|
+
]
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"""Convenient re-exports of the stable SDK surface."""
|
|
2
|
+
|
|
3
|
+
from sec.apis import (
|
|
4
|
+
AsyncSecClient,
|
|
5
|
+
AgentMessage,
|
|
6
|
+
AgentSettings,
|
|
7
|
+
ApprovalOutcome,
|
|
8
|
+
AllowListPolicy,
|
|
9
|
+
AssistantMessage,
|
|
10
|
+
BashExecutionMessage,
|
|
11
|
+
BranchSummaryMessage,
|
|
12
|
+
Config,
|
|
13
|
+
ConfigError,
|
|
14
|
+
CompactionSummaryMessage,
|
|
15
|
+
ContextBuildError,
|
|
16
|
+
ContextSettings,
|
|
17
|
+
ContextWindowExceeded,
|
|
18
|
+
Content,
|
|
19
|
+
CustomMessage,
|
|
20
|
+
Database,
|
|
21
|
+
DenyAllPolicy,
|
|
22
|
+
FileContent,
|
|
23
|
+
InMemorySessionStore,
|
|
24
|
+
Limits,
|
|
25
|
+
LocalToolExecutor,
|
|
26
|
+
Message,
|
|
27
|
+
MessageEntry,
|
|
28
|
+
ManagedStreamingModelProvider,
|
|
29
|
+
ModelResponseCompleted,
|
|
30
|
+
ModelStreamEvent,
|
|
31
|
+
ModelTextDelta,
|
|
32
|
+
ModelProvider,
|
|
33
|
+
ObjectNotFoundError,
|
|
34
|
+
ObjectStore,
|
|
35
|
+
ObjectStoreError,
|
|
36
|
+
PolicyCapabilityType,
|
|
37
|
+
PolicyRiskLevel,
|
|
38
|
+
PolicyDecision,
|
|
39
|
+
PolicyContext,
|
|
40
|
+
PolicyEngine,
|
|
41
|
+
PolicyOutcome,
|
|
42
|
+
PermissionMode,
|
|
43
|
+
PermissionModePolicy,
|
|
44
|
+
ProviderSettings,
|
|
45
|
+
RetryableProviderError,
|
|
46
|
+
RetryableToolError,
|
|
47
|
+
SecSubscriptionOverflow,
|
|
48
|
+
SecUIHandlerError,
|
|
49
|
+
RetrySettings,
|
|
50
|
+
Run,
|
|
51
|
+
RunUsage,
|
|
52
|
+
SessionEvent,
|
|
53
|
+
RunResult,
|
|
54
|
+
SecClient,
|
|
55
|
+
RuntimeSettings,
|
|
56
|
+
Session,
|
|
57
|
+
SessionEntry,
|
|
58
|
+
SessionInfoEntry,
|
|
59
|
+
SessionSnapshot,
|
|
60
|
+
SessionState,
|
|
61
|
+
SessionStats,
|
|
62
|
+
SessionSummary,
|
|
63
|
+
SessionTokens,
|
|
64
|
+
ContextUsage,
|
|
65
|
+
SessionStore,
|
|
66
|
+
SessionStoreError,
|
|
67
|
+
SessionStoreProtocol,
|
|
68
|
+
StreamingModelProvider,
|
|
69
|
+
SessionVersionConflictError,
|
|
70
|
+
DatabaseSessionStore,
|
|
71
|
+
StorageSettings,
|
|
72
|
+
StoredObject,
|
|
73
|
+
SystemMessage,
|
|
74
|
+
TextContent,
|
|
75
|
+
ThinkingContent,
|
|
76
|
+
Tool,
|
|
77
|
+
ToolApprovalDecision,
|
|
78
|
+
ToolApprovalRequest,
|
|
79
|
+
ToolRiskLevel,
|
|
80
|
+
ToolResultContent,
|
|
81
|
+
ToolResultMessage,
|
|
82
|
+
ToolRetrySettings,
|
|
83
|
+
TokenEstimator,
|
|
84
|
+
ToolExecutor,
|
|
85
|
+
ToolExecutorProtocolError,
|
|
86
|
+
ToolUseContent,
|
|
87
|
+
UserMessage,
|
|
88
|
+
content_from_dict,
|
|
89
|
+
content_to_dict,
|
|
90
|
+
create_database,
|
|
91
|
+
create_session_store,
|
|
92
|
+
merge_text,
|
|
93
|
+
message_from_dict,
|
|
94
|
+
message_to_dict,
|
|
95
|
+
tool,
|
|
96
|
+
validate_timeout,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
__all__ = [
|
|
100
|
+
"AgentMessage",
|
|
101
|
+
"AsyncSecClient",
|
|
102
|
+
"SecClient",
|
|
103
|
+
"AgentSettings",
|
|
104
|
+
"ApprovalOutcome",
|
|
105
|
+
"AllowListPolicy",
|
|
106
|
+
"AssistantMessage",
|
|
107
|
+
"BashExecutionMessage",
|
|
108
|
+
"BranchSummaryMessage",
|
|
109
|
+
"Config",
|
|
110
|
+
"ConfigError",
|
|
111
|
+
"CompactionSummaryMessage",
|
|
112
|
+
"ContextBuildError",
|
|
113
|
+
"ContextSettings",
|
|
114
|
+
"ContextWindowExceeded",
|
|
115
|
+
"Content",
|
|
116
|
+
"CustomMessage",
|
|
117
|
+
"Database",
|
|
118
|
+
"create_database",
|
|
119
|
+
"create_session_store",
|
|
120
|
+
"DenyAllPolicy",
|
|
121
|
+
"FileContent",
|
|
122
|
+
"LocalToolExecutor",
|
|
123
|
+
"InMemorySessionStore",
|
|
124
|
+
"Limits",
|
|
125
|
+
"Message",
|
|
126
|
+
"MessageEntry",
|
|
127
|
+
"ManagedStreamingModelProvider",
|
|
128
|
+
"ModelResponseCompleted",
|
|
129
|
+
"ModelStreamEvent",
|
|
130
|
+
"ModelTextDelta",
|
|
131
|
+
"ModelProvider",
|
|
132
|
+
"ObjectNotFoundError",
|
|
133
|
+
"ObjectStore",
|
|
134
|
+
"ObjectStoreError",
|
|
135
|
+
"PolicyCapabilityType",
|
|
136
|
+
"PolicyDecision",
|
|
137
|
+
"PolicyContext",
|
|
138
|
+
"PolicyEngine",
|
|
139
|
+
"PolicyOutcome",
|
|
140
|
+
"PolicyRiskLevel",
|
|
141
|
+
"PermissionMode",
|
|
142
|
+
"PermissionModePolicy",
|
|
143
|
+
"Run",
|
|
144
|
+
"SessionEvent",
|
|
145
|
+
"RunResult",
|
|
146
|
+
"ProviderSettings",
|
|
147
|
+
"RetryableProviderError",
|
|
148
|
+
"RetryableToolError",
|
|
149
|
+
"SecSubscriptionOverflow",
|
|
150
|
+
"SecUIHandlerError",
|
|
151
|
+
"RetrySettings",
|
|
152
|
+
"RunUsage",
|
|
153
|
+
"StorageSettings",
|
|
154
|
+
"RuntimeSettings",
|
|
155
|
+
"Session",
|
|
156
|
+
"SessionEntry",
|
|
157
|
+
"SessionInfoEntry",
|
|
158
|
+
"SessionSnapshot",
|
|
159
|
+
"SessionState",
|
|
160
|
+
"SessionStats",
|
|
161
|
+
"SessionSummary",
|
|
162
|
+
"SessionTokens",
|
|
163
|
+
"ContextUsage",
|
|
164
|
+
"SessionStore",
|
|
165
|
+
"SessionStoreProtocol",
|
|
166
|
+
"StreamingModelProvider",
|
|
167
|
+
"DatabaseSessionStore",
|
|
168
|
+
"SessionStoreError",
|
|
169
|
+
"SessionVersionConflictError",
|
|
170
|
+
"StoredObject",
|
|
171
|
+
"SystemMessage",
|
|
172
|
+
"TextContent",
|
|
173
|
+
"ThinkingContent",
|
|
174
|
+
"Tool",
|
|
175
|
+
"ToolApprovalDecision",
|
|
176
|
+
"ToolApprovalRequest",
|
|
177
|
+
"ToolRiskLevel",
|
|
178
|
+
"ToolResultContent",
|
|
179
|
+
"ToolResultMessage",
|
|
180
|
+
"ToolRetrySettings",
|
|
181
|
+
"TokenEstimator",
|
|
182
|
+
"ToolExecutor",
|
|
183
|
+
"ToolExecutorProtocolError",
|
|
184
|
+
"ToolUseContent",
|
|
185
|
+
"UserMessage",
|
|
186
|
+
"content_from_dict",
|
|
187
|
+
"content_to_dict",
|
|
188
|
+
"merge_text",
|
|
189
|
+
"message_from_dict",
|
|
190
|
+
"message_to_dict",
|
|
191
|
+
"tool",
|
|
192
|
+
"validate_timeout",
|
|
193
|
+
]
|