AIPodCli 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.
@@ -0,0 +1,364 @@
1
+ Metadata-Version: 2.4
2
+ Name: AIPodCli
3
+ Version: 0.1.0
4
+ Summary: AI-native Python development framework
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: openai
9
+ Requires-Dist: injector
10
+ Requires-Dist: python-dotenv
11
+ Requires-Dist: tomlkit
12
+
13
+ # AIPodCli
14
+
15
+ **AI 原生 Python 开发框架** — 让 AI 接管组件生成、依赖注入和管道编排。
16
+
17
+ AIPodCli 是一个 AI 原生的 Python 开发框架。它把 AI 深度集成到开发流程的每个环节:你描述需求,AI 生成组件代码;你描述业务指令,AI 规划执行管道。框架底层基于 `injector` 实现 IoC/DI 容器,在运行时自动组装和运行你(和 AI)构建的系统。
18
+
19
+ **和传统开发框架的区别:**
20
+
21
+ | | 传统框架 | AIPodCli |
22
+ |---|---------|----------|
23
+ | 写组件 | 你写 | AI 生成,你审核 |
24
+ | 配依赖 | 你手动注入 | AI 自动分析,DI 容器装配 |
25
+ | 编排流程 | 你写胶水代码 | AI 规划管道,框架执行 |
26
+ | 配置管理 | 你写配置代码 | AI 建议配置项,自动追加到 TOML |
27
+ | 项目入口 | 你选技术栈 | AI 根据描述决定(Flask/CLI/MQ...) |
28
+
29
+ ## 核心理念
30
+
31
+ ```
32
+ 人类描述需求 → AI 生成代码 → DI 容器自动组装 → Pipeline 管道执行
33
+ ```
34
+
35
+ - **生成与执行分离**:`build` 只生成代码,开发者自行决定何时、如何运行
36
+ - **IoC/DI 容器**:基于 `injector`,组件间依赖通过构造函数自动注入
37
+ - **AI 代码生成**:大模型根据需求 + 已有组件池,自动生成符合规范的组件
38
+ - **管道语法**:`(S(A) | S(B) | S(C)).execute_all(ctx)` 串联组件
39
+ - **PipelineContext**:组件间通过共享上下文流转数据
40
+ - **ConfigStore**:集中式 TOML 配置,组件通过 DI 注入读取
41
+ - **AST 安全检查**:拦截 `eval`/`exec`/dunder 链等代码注入模式
42
+
43
+ ## 快速开始
44
+
45
+ ### 1. 安装
46
+
47
+ ```bash
48
+ cd ai-code-cli
49
+ pip install -e .
50
+ ```
51
+
52
+ ### 2. 初始化项目
53
+
54
+ ```bash
55
+ python -m ai_pod_cli init "一个电商库存管理的 RESTful API"
56
+ ```
57
+
58
+ AI 会根据描述自主判断技术栈(Flask/FastAPI/CLI/RabbitMQ...),生成对应的入口文件:
59
+
60
+ ```
61
+ .
62
+ ├── cli.py (或 app.py / consumer.py) ← AI 生成的入口
63
+ ├── modules/ ← AI 生成的组件
64
+ │ ├── __init__.py
65
+ │ └── requirements.txt
66
+ ├── pipelines/ ← AI 生成的管道文件
67
+ ├── config.toml ← 项目配置(组件通过 ConfigStore 读取)
68
+ ├── routes.toml ← 路由映射(build 自动注册)
69
+ ├── beans_config.json ← 组件注册账本
70
+ ├── .env ← 大模型 API 配置
71
+ └── .gitignore
72
+ ```
73
+
74
+ ### 3. 配置大模型
75
+
76
+ 编辑 `.env`:
77
+
78
+ ```bash
79
+ OPENAI_API_KEY=sk-your-real-key-here
80
+ OPENAI_BASE_URL=https://api.openai.com/v1
81
+ OPENAI_MODEL=deepseek-chat
82
+ ```
83
+
84
+ 支持任何 OpenAI 兼容 API(DeepSeek / Moonshot / Ollama 等)。
85
+
86
+ ### 4. 完整工作流
87
+
88
+ ```bash
89
+ # ① 创建组件(AI 自动生成代码 + 注册配置)
90
+ python -m ai_pod_cli create --category entity --name SqliteStore \
91
+ --desc "SQLite存储组件,从ConfigStore读取database.sqlite_path,提供query/execute/insert方法"
92
+
93
+ python -m ai_pod_cli create --category entry --name DataCollector \
94
+ --desc "生成随机销售记录写入ctx.set('raw_sales', list)"
95
+
96
+ python -m ai_pod_cli create --category entry --name DataWriter \
97
+ --desc "依赖SqliteStore,从ctx读取raw_sales建表并逐条insert"
98
+
99
+ # ② 生成管道(AI 规划链路 → 保存文件 → 注册路由,不执行)
100
+ python -m ai_pod_cli build "采集销售数据并写入SQLite" --name collect_sales
101
+
102
+ # ③ 开发者自行运行
103
+ python cli.py collect_sales # CLI 入口
104
+ # 或 flask run # Web 入口
105
+ # 或 python consumer.py # 消息队列入口
106
+ ```
107
+
108
+ ## 命令参考
109
+
110
+ ### `init` — 初始化项目
111
+
112
+ ```bash
113
+ python -m ai_pod_cli init "项目描述"
114
+ python -m ai_pod_cli init # 不传描述,只创建骨架
115
+ python -m ai_pod_cli init "..." --install-deps # 同时安装依赖
116
+ ```
117
+
118
+ | 参数 | 说明 |
119
+ |------|------|
120
+ | `desc` | 项目描述,AI 据此判断技术栈并生成入口文件 |
121
+ | `--install-deps` | 自动安装 Python 依赖 |
122
+
123
+ AI 会自主决定:
124
+ - **项目类型**:Flask / FastAPI / CLI / RabbitMQ / Kafka / APScheduler / WebSocket 等
125
+ - **入口文件名**:`app.py` / `main.py` / `consumer.py` / `scheduler.py` 等
126
+ - **额外依赖**:自动追加到 `modules/requirements.txt`
127
+
128
+ ### `create` — AI 生成组件
129
+
130
+ ```bash
131
+ python -m ai_pod_cli create --category entry --name StockChecker \
132
+ --desc "查询指定商品库存,库存为0则发送短信通知管理员"
133
+ ```
134
+
135
+ | 参数 | 必填 | 说明 |
136
+ |------|------|------|
137
+ | `--name` | ✅ | 组件名称(必须与类名一致) |
138
+ | `--category` | ✅ | `entry`(业务组件)或 `entity`(基础实体) |
139
+ | `--desc` | ✅ | 需求描述 |
140
+
141
+ **AI 自动完成:**
142
+ 1. 从组件池中挑选依赖(DI 注入)
143
+ 2. 生成完整代码(含 `@inject` 构造函数 + `execute` 方法)
144
+ 3. 定义数据契约(`inputs` / `outputs`)
145
+ 4. 如需要新配置项,自动追加到 `config.toml`(通过 tomlkit)
146
+ 5. AST 安全检查(拦截 `eval`/`exec`/dunder 链)
147
+ 6. 写入 `modules/` 并注册到 `beans_config.json`
148
+
149
+ ### `add` — 注册人工编写的组件
150
+
151
+ ```bash
152
+ python -m ai_pod_cli add --name CacheClient \
153
+ --class-path my_infra.cache.CacheClient \
154
+ --desc "Redis 缓存客户端"
155
+ ```
156
+
157
+ | 参数 | 必填 | 说明 |
158
+ |------|------|------|
159
+ | `--name` | ✅ | 组件名称 |
160
+ | `--class-path` | ✅ | 完整类路径 |
161
+ | `--desc` | ✅ | 功能描述 |
162
+ | `--category` | ❌ | 默认 `entity` |
163
+
164
+ ### `build` — AI 生成管道
165
+
166
+ ```bash
167
+ # 生成管道文件 + 注册路由(不执行)
168
+ python -m ai_pod_cli build "采集销售数据并写入SQLite" --name collect_sales
169
+
170
+ # 列出所有已生成的管道
171
+ python -m ai_pod_cli build --list
172
+ ```
173
+
174
+ | 参数 | 说明 |
175
+ |------|------|
176
+ | `cmd` | 自然语言业务指令 |
177
+ | `--name` | 自定义管道文件名(默认从指令自动生成) |
178
+ | `--list` | 列出所有已保存的管道 |
179
+
180
+ **build 做了什么:**
181
+ 1. AI 分析指令,规划组件执行链
182
+ 2. 生成 `pipelines/<name>.py` 管道文件
183
+ 3. AST 安全检查
184
+ 4. 自动注册到 `routes.toml`
185
+ 5. **不执行** — 由开发者通过入口文件运行
186
+
187
+ ## 架构
188
+
189
+ ### 生成与执行分离
190
+
191
+ ```
192
+ ┌─────────────────────────────────┐
193
+ │ 开发时(生成) │
194
+ │ │
195
+ │ init "描述" → 入口文件 │
196
+ │ create → 组件代码 │
197
+ │ build "指令" → 管道文件 + 路由 │
198
+ └─────────────────────────────────┘
199
+
200
+ ┌─────────────────────────────────┐
201
+ │ 运行时(执行) │
202
+ │ │
203
+ │ python app.py │
204
+ │ → Flask/FastAPI/CLI/MQ │
205
+ │ → PipelineRunner │
206
+ │ → routes.toml 路由匹配 │
207
+ │ → 加载 pipeline.run(ctx) │
208
+ │ → DI 容器组装 + 管道执行 │
209
+ └─────────────────────────────────┘
210
+ ```
211
+
212
+ ### PipelineRunner — 统一执行器
213
+
214
+ 框架内置的 `PipelineRunner` 负责加载和执行管道:
215
+
216
+ ```python
217
+ from ai_pod_cli.runner import PipelineRunner
218
+
219
+ runner = PipelineRunner() # 读取 routes.toml
220
+ runner.route_names() # ['collect_sales', ...]
221
+ result = runner.run("collect_sales", {"sku_id": 1001})
222
+ ```
223
+
224
+ AI 生成的入口文件(Flask/CLI/MQ 等)内部都调用 PipelineRunner。
225
+
226
+ ### 管道语法
227
+
228
+ ```python
229
+ from ai_pod_cli.container import build_container, Pod
230
+
231
+ def run(ctx: PipelineContext):
232
+ container = build_container(load_config())
233
+ S = Pod(container)
234
+
235
+ # 管道符串联:依次执行 A → B → C,自动记录轨迹
236
+ (S(DataCollector) | S(DataCleaner) | S(DataWriter)).execute_all(ctx)
237
+
238
+ # 条件分支
239
+ if ctx.get("stock", 0) <= 0:
240
+ (S(StockNotifier)).execute_all(ctx)
241
+
242
+ return ctx.summary()
243
+ ```
244
+
245
+ ### PipelineContext — 数据流转
246
+
247
+ ```python
248
+ class DataProcessor:
249
+ def execute(self, ctx: PipelineContext) -> dict:
250
+ # 读取入口参数
251
+ count = ctx.params.get("order_count", 5)
252
+
253
+ # 读取上游数据
254
+ raw = ctx.get("raw_orders", [])
255
+
256
+ # 业务处理...
257
+
258
+ # 写入共享数据池,供下游使用
259
+ ctx.set("processed_orders", result)
260
+ return {"status": "success"}
261
+ ```
262
+
263
+ ### ConfigStore — 集中配置
264
+
265
+ 组件通过 DI 注入 ConfigStore 读取 `config.toml`:
266
+
267
+ ```toml
268
+ # config.toml
269
+ [database]
270
+ sqlite_path = "data.db" # build 时 AI 自动建议追加
271
+
272
+ [redis]
273
+ host = "localhost"
274
+ port = 6379
275
+ ```
276
+
277
+ ```python
278
+ class SqliteStore:
279
+ @inject
280
+ def __init__(self, config_store: ConfigStore):
281
+ db_path = config_store.get("database.sqlite_path", "data.db")
282
+ self.conn = sqlite3.connect(db_path)
283
+ ```
284
+
285
+ ### routes.toml — 路由映射
286
+
287
+ `build` 命令自动注册,也可手动编辑:
288
+
289
+ ```toml
290
+ [collect_sales]
291
+ pipeline = "pipelines/collect_sales.py"
292
+ description = "采集销售数据并写入SQLite"
293
+
294
+ [stock_alert]
295
+ pipeline = "pipelines/stock_alert.py"
296
+ description = "库存不足时发送预警"
297
+ ```
298
+
299
+ ## 项目结构
300
+
301
+ ```
302
+ ai-code-cli/
303
+ ├── pyproject.toml
304
+ ├── requirements.txt
305
+ ├── .env / .env.example
306
+ ├── config.toml ← 项目配置(用户 + AI 共同维护)
307
+ ├── routes.toml ← 路由映射(build 自动注册)
308
+ ├── beans_config.json ← 组件账本
309
+ ├── cli.py ← AI 生成的入口(CLI 示例)
310
+ ├── modules/ ← AI 生成的组件
311
+ │ ├── sqlitestore.py
312
+ │ ├── datacollector.py
313
+ │ └── datawriter.py
314
+ ├── pipelines/ ← AI 生成的管道
315
+ │ └── collect_sales.py
316
+ └── ai_pod_cli/ ← 引擎核心
317
+ ├── cli.py # CLI 参数解析
318
+ ├── client.py # 大模型客户端(含重试)
319
+ ├── config.py # 配置管理
320
+ ├── config_store.py # ConfigStore 实体
321
+ ├── container.py # DI 容器 + Pod 管道包装
322
+ ├── context.py # PipelineContext
323
+ ├── runner.py # PipelineRunner 执行器
324
+ ├── security.py # AST 安全检查
325
+ ├── entities.py # 内置实体(DbClient, SmsSender)
326
+ └── commands/
327
+ ├── init.py # init 命令
328
+ ├── create.py # create 命令
329
+ ├── add.py # add 命令
330
+ └── build.py # build 命令
331
+ ```
332
+
333
+ ## 安全
334
+
335
+ AI 生成的代码经过 AST 静态扫描,拦截以下模式:
336
+
337
+ | 类型 | 拦截内容 |
338
+ |------|---------|
339
+ | 危险函数 | `eval()`, `exec()`, `compile()`, `__import__()` |
340
+ | dunder 链 | `__subclasses__`, `__mro__`, `__globals__`, `__builtins__` 等 |
341
+
342
+ 不限制 `import`——这是本地开发工具,开发者对自己的代码负责。
343
+
344
+ ## 配置
345
+
346
+ | 文件 | 用途 | 谁维护 |
347
+ |------|------|--------|
348
+ | `.env` | 大模型 API 配置 | 开发者 |
349
+ | `config.toml` | 项目配置(DB路径、端口等) | 开发者 + AI 建议追加 |
350
+ | `routes.toml` | 管道路由映射 | AI 自动注册 + 开发者手动编辑 |
351
+ | `beans_config.json` | 组件账本 | AI 自动维护 |
352
+
353
+ ## 依赖
354
+
355
+ | 包 | 用途 |
356
+ |----|------|
357
+ | `openai` | 大模型 API 客户端 |
358
+ | `injector` | IoC/DI 容器框架 |
359
+ | `python-dotenv` | `.env` 环境变量加载 |
360
+ | `tomlkit` | TOML 读写(保留格式和注释) |
361
+
362
+ ## License
363
+
364
+ MIT
@@ -0,0 +1,24 @@
1
+ README.md
2
+ pyproject.toml
3
+ AIPodCli.egg-info/PKG-INFO
4
+ AIPodCli.egg-info/SOURCES.txt
5
+ AIPodCli.egg-info/dependency_links.txt
6
+ AIPodCli.egg-info/entry_points.txt
7
+ AIPodCli.egg-info/requires.txt
8
+ AIPodCli.egg-info/top_level.txt
9
+ ai_pod_cli/__init__.py
10
+ ai_pod_cli/__main__.py
11
+ ai_pod_cli/cli.py
12
+ ai_pod_cli/client.py
13
+ ai_pod_cli/config.py
14
+ ai_pod_cli/config_store.py
15
+ ai_pod_cli/container.py
16
+ ai_pod_cli/context.py
17
+ ai_pod_cli/entities.py
18
+ ai_pod_cli/runner.py
19
+ ai_pod_cli/security.py
20
+ ai_pod_cli/commands/__init__.py
21
+ ai_pod_cli/commands/add.py
22
+ ai_pod_cli/commands/build.py
23
+ ai_pod_cli/commands/create.py
24
+ ai_pod_cli/commands/init.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ai-pod = ai_pod_cli.cli:main
@@ -0,0 +1,4 @@
1
+ openai
2
+ injector
3
+ python-dotenv
4
+ tomlkit
@@ -0,0 +1 @@
1
+ ai_pod_cli