monoco-toolkit 0.3.11__py3-none-any.whl → 0.4.0__py3-none-any.whl
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.
- monoco/core/automation/__init__.py +40 -0
- monoco/core/automation/field_watcher.py +296 -0
- monoco/core/automation/handlers.py +805 -0
- monoco/core/config.py +29 -11
- monoco/core/daemon/__init__.py +5 -0
- monoco/core/daemon/pid.py +290 -0
- monoco/core/git.py +15 -0
- monoco/core/hooks/context.py +74 -13
- monoco/core/injection.py +86 -8
- monoco/core/integrations.py +0 -24
- monoco/core/router/__init__.py +17 -0
- monoco/core/router/action.py +202 -0
- monoco/core/scheduler/__init__.py +63 -0
- monoco/core/scheduler/base.py +152 -0
- monoco/core/scheduler/engines.py +175 -0
- monoco/core/scheduler/events.py +197 -0
- monoco/core/scheduler/local.py +377 -0
- monoco/core/setup.py +9 -0
- monoco/core/sync.py +199 -4
- monoco/core/watcher/__init__.py +63 -0
- monoco/core/watcher/base.py +382 -0
- monoco/core/watcher/dropzone.py +152 -0
- monoco/core/watcher/im.py +460 -0
- monoco/core/watcher/issue.py +303 -0
- monoco/core/watcher/memo.py +192 -0
- monoco/core/watcher/task.py +238 -0
- monoco/daemon/app.py +3 -60
- monoco/daemon/commands.py +459 -25
- monoco/daemon/events.py +34 -0
- monoco/daemon/scheduler.py +157 -201
- monoco/daemon/services.py +42 -243
- monoco/features/agent/__init__.py +25 -7
- monoco/features/agent/cli.py +91 -57
- monoco/features/agent/engines.py +31 -170
- monoco/features/agent/resources/en/AGENTS.md +14 -14
- monoco/features/agent/resources/en/skills/monoco_role_engineer/SKILL.md +101 -0
- monoco/features/agent/resources/en/skills/monoco_role_manager/SKILL.md +95 -0
- monoco/features/agent/resources/en/skills/monoco_role_planner/SKILL.md +177 -0
- monoco/features/agent/resources/en/skills/monoco_role_reviewer/SKILL.md +139 -0
- monoco/features/agent/resources/zh/skills/monoco_role_engineer/SKILL.md +101 -0
- monoco/features/agent/resources/zh/skills/monoco_role_manager/SKILL.md +95 -0
- monoco/features/agent/resources/zh/skills/monoco_role_planner/SKILL.md +177 -0
- monoco/features/agent/resources/zh/skills/monoco_role_reviewer/SKILL.md +139 -0
- monoco/features/agent/worker.py +1 -1
- monoco/features/hooks/__init__.py +61 -6
- monoco/features/hooks/commands.py +281 -271
- monoco/features/hooks/dispatchers/__init__.py +23 -0
- monoco/features/hooks/dispatchers/agent_dispatcher.py +486 -0
- monoco/features/hooks/dispatchers/git_dispatcher.py +478 -0
- monoco/features/hooks/manager.py +357 -0
- monoco/features/hooks/models.py +262 -0
- monoco/features/hooks/parser.py +322 -0
- monoco/features/hooks/universal_interceptor.py +503 -0
- monoco/features/im/__init__.py +67 -0
- monoco/features/im/core.py +782 -0
- monoco/features/im/models.py +311 -0
- monoco/features/issue/commands.py +133 -60
- monoco/features/issue/core.py +385 -40
- monoco/features/issue/domain_commands.py +0 -19
- monoco/features/issue/resources/en/AGENTS.md +17 -122
- monoco/features/issue/resources/hooks/agent/before-tool.sh +102 -0
- monoco/features/issue/resources/hooks/agent/session-start.sh +88 -0
- monoco/features/issue/resources/hooks/{post-checkout.sh → git/git-post-checkout.sh} +10 -9
- monoco/features/issue/resources/hooks/git/git-pre-commit.sh +31 -0
- monoco/features/issue/resources/hooks/{pre-push.sh → git/git-pre-push.sh} +7 -13
- monoco/features/issue/resources/zh/AGENTS.md +18 -123
- monoco/features/memo/cli.py +15 -64
- monoco/features/memo/core.py +6 -34
- monoco/features/memo/models.py +24 -15
- monoco/features/memo/resources/en/AGENTS.md +31 -0
- monoco/features/memo/resources/zh/AGENTS.md +28 -5
- monoco/features/spike/commands.py +5 -3
- monoco/main.py +5 -3
- {monoco_toolkit-0.3.11.dist-info → monoco_toolkit-0.4.0.dist-info}/METADATA +1 -1
- monoco_toolkit-0.4.0.dist-info/RECORD +170 -0
- monoco/core/execution.py +0 -67
- monoco/features/agent/apoptosis.py +0 -44
- monoco/features/agent/manager.py +0 -127
- monoco/features/agent/resources/atoms/atom-code-dev.yaml +0 -61
- monoco/features/agent/resources/atoms/atom-issue-lifecycle.yaml +0 -73
- monoco/features/agent/resources/atoms/atom-knowledge.yaml +0 -55
- monoco/features/agent/resources/atoms/atom-review.yaml +0 -60
- monoco/features/agent/resources/en/skills/monoco_atom_core/SKILL.md +0 -99
- monoco/features/agent/resources/en/skills/monoco_workflow_agent_engineer/SKILL.md +0 -94
- monoco/features/agent/resources/en/skills/monoco_workflow_agent_manager/SKILL.md +0 -93
- monoco/features/agent/resources/en/skills/monoco_workflow_agent_planner/SKILL.md +0 -85
- monoco/features/agent/resources/en/skills/monoco_workflow_agent_reviewer/SKILL.md +0 -114
- monoco/features/agent/resources/workflows/workflow-dev.yaml +0 -83
- monoco/features/agent/resources/workflows/workflow-issue-create.yaml +0 -72
- monoco/features/agent/resources/workflows/workflow-review.yaml +0 -94
- monoco/features/agent/resources/zh/roles/monoco_role_engineer.yaml +0 -49
- monoco/features/agent/resources/zh/roles/monoco_role_manager.yaml +0 -46
- monoco/features/agent/resources/zh/roles/monoco_role_planner.yaml +0 -46
- monoco/features/agent/resources/zh/roles/monoco_role_reviewer.yaml +0 -47
- monoco/features/agent/resources/zh/skills/monoco_atom_core/SKILL.md +0 -99
- monoco/features/agent/resources/zh/skills/monoco_workflow_agent_engineer/SKILL.md +0 -94
- monoco/features/agent/resources/zh/skills/monoco_workflow_agent_manager/SKILL.md +0 -88
- monoco/features/agent/resources/zh/skills/monoco_workflow_agent_planner/SKILL.md +0 -259
- monoco/features/agent/resources/zh/skills/monoco_workflow_agent_reviewer/SKILL.md +0 -137
- monoco/features/agent/session.py +0 -169
- monoco/features/artifact/resources/zh/skills/monoco_atom_artifact/SKILL.md +0 -278
- monoco/features/glossary/resources/en/skills/monoco_atom_glossary/SKILL.md +0 -35
- monoco/features/glossary/resources/zh/skills/monoco_atom_glossary/SKILL.md +0 -35
- monoco/features/hooks/adapter.py +0 -67
- monoco/features/hooks/core.py +0 -441
- monoco/features/i18n/resources/en/skills/monoco_atom_i18n/SKILL.md +0 -96
- monoco/features/i18n/resources/en/skills/monoco_workflow_i18n_scan/SKILL.md +0 -105
- monoco/features/i18n/resources/zh/skills/monoco_atom_i18n/SKILL.md +0 -96
- monoco/features/i18n/resources/zh/skills/monoco_workflow_i18n_scan/SKILL.md +0 -105
- monoco/features/issue/resources/en/skills/monoco_atom_issue/SKILL.md +0 -165
- monoco/features/issue/resources/en/skills/monoco_workflow_issue_creation/SKILL.md +0 -167
- monoco/features/issue/resources/en/skills/monoco_workflow_issue_development/SKILL.md +0 -224
- monoco/features/issue/resources/en/skills/monoco_workflow_issue_management/SKILL.md +0 -159
- monoco/features/issue/resources/en/skills/monoco_workflow_issue_refinement/SKILL.md +0 -203
- monoco/features/issue/resources/hooks/pre-commit.sh +0 -41
- monoco/features/issue/resources/zh/skills/monoco_atom_issue_lifecycle/SKILL.md +0 -190
- monoco/features/issue/resources/zh/skills/monoco_workflow_issue_creation/SKILL.md +0 -167
- monoco/features/issue/resources/zh/skills/monoco_workflow_issue_development/SKILL.md +0 -224
- monoco/features/issue/resources/zh/skills/monoco_workflow_issue_management/SKILL.md +0 -159
- monoco/features/issue/resources/zh/skills/monoco_workflow_issue_refinement/SKILL.md +0 -203
- monoco/features/memo/resources/en/skills/monoco_atom_memo/SKILL.md +0 -77
- monoco/features/memo/resources/en/skills/monoco_workflow_note_processing/SKILL.md +0 -140
- monoco/features/memo/resources/zh/skills/monoco_atom_memo/SKILL.md +0 -77
- monoco/features/memo/resources/zh/skills/monoco_workflow_note_processing/SKILL.md +0 -140
- monoco/features/spike/resources/en/skills/monoco_atom_spike/SKILL.md +0 -76
- monoco/features/spike/resources/en/skills/monoco_workflow_research/SKILL.md +0 -121
- monoco/features/spike/resources/zh/skills/monoco_atom_spike/SKILL.md +0 -76
- monoco/features/spike/resources/zh/skills/monoco_workflow_research/SKILL.md +0 -121
- monoco_toolkit-0.3.11.dist-info/RECORD +0 -181
- {monoco_toolkit-0.3.11.dist-info → monoco_toolkit-0.4.0.dist-info}/WHEEL +0 -0
- {monoco_toolkit-0.3.11.dist-info → monoco_toolkit-0.4.0.dist-info}/entry_points.txt +0 -0
- {monoco_toolkit-0.3.11.dist-info → monoco_toolkit-0.4.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: monoco_workflow_agent_reviewer
|
|
3
|
-
description: Reviewer 角色的标准化工作流 (Flow Skill)。定义从代码检出、对抗性测试到评审完成的标准操作流程,确保代码质量和流程合规。
|
|
4
|
-
type: workflow
|
|
5
|
-
role: reviewer
|
|
6
|
-
version: 1.1.0
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# Reviewer Flow
|
|
10
|
-
|
|
11
|
-
Reviewer 角色的标准化工作流,确保 "Checkout → Verify → Challenge → Review → Decide → Cleanup" 流程。核心理念是**双层防御体系**:Engineer 负责自证 (Verify),Reviewer 负责对抗 (Challenge)。
|
|
12
|
-
|
|
13
|
-
## 工作流状态机
|
|
14
|
-
|
|
15
|
-
```mermaid
|
|
16
|
-
stateDiagram-v2
|
|
17
|
-
[*] --> Checkout: 收到评审请求
|
|
18
|
-
|
|
19
|
-
Checkout --> Verify: 检出完成
|
|
20
|
-
Checkout --> Checkout: 检出失败<br/>(环境检查)
|
|
21
|
-
|
|
22
|
-
Verify --> Challenge: 现有测试通过
|
|
23
|
-
Verify --> Verify: 现有测试失败<br/>(记录问题)
|
|
24
|
-
|
|
25
|
-
Challenge --> Review: 对抗测试完成
|
|
26
|
-
Challenge --> Reject: 发现致命漏洞
|
|
27
|
-
|
|
28
|
-
Review --> Approve: 代码 & 架构 OK
|
|
29
|
-
Review --> Reject: 发现质量问题
|
|
30
|
-
|
|
31
|
-
Reject --> Checkout: 修复后重审
|
|
32
|
-
|
|
33
|
-
Approve --> Cleanup: 批准
|
|
34
|
-
|
|
35
|
-
Cleanup --> [*]: 清理完成
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## 执行步骤
|
|
39
|
-
|
|
40
|
-
### 1. Checkout (检出)
|
|
41
|
-
|
|
42
|
-
- **目标**: 获取待评审的代码
|
|
43
|
-
- **检查点**:
|
|
44
|
-
- [ ] 检出 PR/Branch
|
|
45
|
-
- [ ] 确认与 Base 分支的差异
|
|
46
|
-
- [ ] 检查环境配置
|
|
47
|
-
|
|
48
|
-
### 2. Verify (验证)
|
|
49
|
-
|
|
50
|
-
- **目标**: 验证 Engineer 提交的功能正确性和测试覆盖 (White-box)
|
|
51
|
-
- **检查点**:
|
|
52
|
-
- [ ] 运行 **Engineer 编写的** 单元测试
|
|
53
|
-
- [ ] 运行集成测试 (如适用)
|
|
54
|
-
- [ ] 检查测试覆盖率报告
|
|
55
|
-
- [ ] **决策**: 如果现有测试失败,直接进入 `Reject` 流程。
|
|
56
|
-
|
|
57
|
-
### 3. Challenge (对抗测试)
|
|
58
|
-
|
|
59
|
-
- **目标**: 尝试破坏代码,寻找边界情况和安全漏洞 (Black-box / Edge Cases)
|
|
60
|
-
- **思维模式**: "Try to break it"
|
|
61
|
-
- **操作**:
|
|
62
|
-
1. 分析代码逻辑,寻找 Engineer 视角的盲区(并发、大/小数值、注入攻击等)。
|
|
63
|
-
2. 编写新的 **Challenge Test Cases**。
|
|
64
|
-
3. 运行这些新测试。
|
|
65
|
-
- **检查点**:
|
|
66
|
-
- [ ] **漏洞发现**: 如果新测试导致 Crash 或逻辑错误 -> **Reject** (并将测试用例作为反馈)。
|
|
67
|
-
- [ ] **鲁棒性验证**: 如果新测试通过 -> **保留测试用例** (提交到代码库) 并进入下一步。
|
|
68
|
-
|
|
69
|
-
### 4. Review (代码审查)
|
|
70
|
-
|
|
71
|
-
- **目标**: 检查代码质量、架构设计和可维护性
|
|
72
|
-
- **检查清单**:
|
|
73
|
-
- [ ] **功能**: 代码是否实现了需求?
|
|
74
|
-
- [ ] **设计**: 架构是否合理?是否遵循 KISS 原则?
|
|
75
|
-
- [ ] **可读性**: 命名和注释是否清晰?
|
|
76
|
-
- [ ] **文档**: 文档是否同步更新?
|
|
77
|
-
- [ ] **合规**: 是否遵循项目 Lint 规范?
|
|
78
|
-
|
|
79
|
-
### 5. Decide (决策)
|
|
80
|
-
|
|
81
|
-
- **目标**: 做出批准或拒绝的决定
|
|
82
|
-
- **选项**:
|
|
83
|
-
- **Approve**: 代码健壮且符合规范 (包含所有通过的 Challenge Tests)
|
|
84
|
-
- **Reject**: 需要修改,提供具体反馈 (附带失败的 Test Case 或 Log)
|
|
85
|
-
- **Request Changes**: 小问题,可快速修复
|
|
86
|
-
|
|
87
|
-
### 6. Cleanup (清理)
|
|
88
|
-
|
|
89
|
-
- **目标**: 完成评审后的环境清理
|
|
90
|
-
- **检查点**:
|
|
91
|
-
- [ ] 提交新增的测试用例 (如有)
|
|
92
|
-
- [ ] 删除本地临时分支
|
|
93
|
-
- [ ] 更新 Issue 状态
|
|
94
|
-
- [ ] 记录评审意见到 Review Comments
|
|
95
|
-
|
|
96
|
-
## 决策分支
|
|
97
|
-
|
|
98
|
-
| 条件 | 动作 |
|
|
99
|
-
| ------------------------- | --------------------------------------- |
|
|
100
|
-
| 现有测试 (Verify) 失败 | Reject,要求 Engineer 修复 |
|
|
101
|
-
| 对抗测试 (Challenge) 崩溃 | Reject,提交该测试用例证明漏洞 |
|
|
102
|
-
| 代码风格问题 | Request Changes 或提供建议 |
|
|
103
|
-
| 设计问题 | Reject,要求重新设计 |
|
|
104
|
-
| 一切正常 | Approve,并合并价值高的 Challenge Tests |
|
|
105
|
-
|
|
106
|
-
## 评审意见模板
|
|
107
|
-
|
|
108
|
-
```markdown
|
|
109
|
-
## Review Comments
|
|
110
|
-
|
|
111
|
-
### 🛡️ Challenge Reports
|
|
112
|
-
|
|
113
|
-
- [Pass/Fail] Test Case: `test_concurrency_limit`
|
|
114
|
-
- [Pass/Fail] Test Case: `test_invalid_inputs`
|
|
115
|
-
|
|
116
|
-
### ✅ 优点
|
|
117
|
-
|
|
118
|
-
-
|
|
119
|
-
|
|
120
|
-
### ⚠️ 建议
|
|
121
|
-
|
|
122
|
-
-
|
|
123
|
-
|
|
124
|
-
### ❌ 必须修改
|
|
125
|
-
|
|
126
|
-
-
|
|
127
|
-
|
|
128
|
-
### 📝 其他
|
|
129
|
-
|
|
130
|
-
-
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## 合规要求
|
|
134
|
-
|
|
135
|
-
- **必须**: 先通过 Engineer 的测试 (Verify),再进行对抗测试 (Challenge)
|
|
136
|
-
- **必须**: 试图编写至少一个边界测试用例
|
|
137
|
-
- **禁止**: 未经测试直接 Approve
|
monoco/features/agent/session.py
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
from typing import Optional
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
from pydantic import BaseModel, Field, ConfigDict
|
|
5
|
-
|
|
6
|
-
from .worker import Worker
|
|
7
|
-
from monoco.core.hooks import HookContext, HookRegistry, get_registry
|
|
8
|
-
from monoco.core.config import find_monoco_root
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Session(BaseModel):
|
|
12
|
-
"""
|
|
13
|
-
Represents a runtime session of a worker.
|
|
14
|
-
Persisted state of the session.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
18
|
-
|
|
19
|
-
id: str = Field(..., description="Unique session ID (likely UUID)")
|
|
20
|
-
issue_id: str = Field(..., description="The Issue ID this session is working on")
|
|
21
|
-
role_name: str = Field(..., description="Name of the role employed")
|
|
22
|
-
status: str = Field(
|
|
23
|
-
default="pending", description="pending, running, suspended, terminated"
|
|
24
|
-
)
|
|
25
|
-
branch_name: str = Field(
|
|
26
|
-
..., description="Git branch name associated with this session"
|
|
27
|
-
)
|
|
28
|
-
pid: Optional[int] = Field(default=None, description="Process ID of the worker")
|
|
29
|
-
created_at: datetime = Field(default_factory=datetime.now)
|
|
30
|
-
updated_at: datetime = Field(default_factory=datetime.now)
|
|
31
|
-
# History could be a list of logs or pointers to git commits
|
|
32
|
-
# For now, let's keep it simple. The git log IS the history.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class RuntimeSession:
|
|
36
|
-
"""
|
|
37
|
-
The in-memory wrapper around the Session model and the active Worker.
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
def __init__(
|
|
41
|
-
self,
|
|
42
|
-
session_model: Session,
|
|
43
|
-
worker: Optional[Worker],
|
|
44
|
-
hook_registry: Optional[HookRegistry] = None,
|
|
45
|
-
project_root: Optional[Path] = None,
|
|
46
|
-
save_callback: Optional[callable] = None,
|
|
47
|
-
):
|
|
48
|
-
self.model = session_model
|
|
49
|
-
self.worker = worker
|
|
50
|
-
self.hook_registry = hook_registry or get_registry()
|
|
51
|
-
self.project_root = project_root or find_monoco_root()
|
|
52
|
-
self.save_callback = save_callback
|
|
53
|
-
|
|
54
|
-
def _save(self):
|
|
55
|
-
if self.save_callback:
|
|
56
|
-
self.save_callback(self.model)
|
|
57
|
-
|
|
58
|
-
def _create_hook_context(self) -> HookContext:
|
|
59
|
-
"""Create a HookContext from the current session state."""
|
|
60
|
-
return HookContext.from_runtime_session(self, self.project_root)
|
|
61
|
-
|
|
62
|
-
def start(self, context: Optional[dict] = None):
|
|
63
|
-
if not self.worker:
|
|
64
|
-
raise RuntimeError(
|
|
65
|
-
"Cannot start session in observer mode (no worker attached)"
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
print(
|
|
69
|
-
f"Session {self.model.id}: Starting worker on branch {self.model.branch_name}"
|
|
70
|
-
)
|
|
71
|
-
# In real impl, checking out branch happening here
|
|
72
|
-
self.model.status = "running"
|
|
73
|
-
self.model.updated_at = datetime.now()
|
|
74
|
-
|
|
75
|
-
try:
|
|
76
|
-
# Execute on_session_start hooks
|
|
77
|
-
hook_context = self._create_hook_context()
|
|
78
|
-
self.hook_registry.execute_on_session_start(hook_context)
|
|
79
|
-
|
|
80
|
-
self.worker.start(context)
|
|
81
|
-
# Async mode: we assume it started running.
|
|
82
|
-
# Use poll or refresh_status to check later.
|
|
83
|
-
self.model.status = "running"
|
|
84
|
-
self.model.pid = self.worker.process_id
|
|
85
|
-
except Exception:
|
|
86
|
-
self.model.status = "failed"
|
|
87
|
-
raise
|
|
88
|
-
finally:
|
|
89
|
-
self.model.updated_at = datetime.now()
|
|
90
|
-
self._save()
|
|
91
|
-
|
|
92
|
-
def refresh_status(self) -> str:
|
|
93
|
-
"""
|
|
94
|
-
Polls the worker and updates the session model status.
|
|
95
|
-
"""
|
|
96
|
-
if self.worker:
|
|
97
|
-
worker_status = self.worker.poll()
|
|
98
|
-
self.model.status = worker_status
|
|
99
|
-
else:
|
|
100
|
-
# Observer mode
|
|
101
|
-
if self.model.pid:
|
|
102
|
-
try:
|
|
103
|
-
import os
|
|
104
|
-
|
|
105
|
-
# Check if process exists.
|
|
106
|
-
# kill(pid, 0) does not send a signal but raises OSError if pid missing
|
|
107
|
-
os.kill(self.model.pid, 0)
|
|
108
|
-
# If we are here, process exists. We assume running if it was running.
|
|
109
|
-
# We can't detect "suspended" easily without psutil.
|
|
110
|
-
if self.model.status == "terminated":
|
|
111
|
-
# If we thought it was terminated but it's alive, maybe update?
|
|
112
|
-
# Or keep as terminated? Let's assume running if found.
|
|
113
|
-
pass
|
|
114
|
-
except OSError:
|
|
115
|
-
self.model.status = "terminated"
|
|
116
|
-
else:
|
|
117
|
-
self.model.status = "terminated"
|
|
118
|
-
|
|
119
|
-
self.model.updated_at = datetime.now()
|
|
120
|
-
self._save()
|
|
121
|
-
return self.model.status
|
|
122
|
-
|
|
123
|
-
def suspend(self):
|
|
124
|
-
if not self.worker:
|
|
125
|
-
raise RuntimeError("Cannot suspend session in observer mode")
|
|
126
|
-
|
|
127
|
-
print(f"Session {self.model.id}: Suspending worker")
|
|
128
|
-
self.worker.stop()
|
|
129
|
-
self.model.status = "suspended"
|
|
130
|
-
self.model.updated_at = datetime.now()
|
|
131
|
-
self._save()
|
|
132
|
-
# In real impl, ensure git commit of current state?
|
|
133
|
-
|
|
134
|
-
def resume(self):
|
|
135
|
-
if not self.worker:
|
|
136
|
-
raise RuntimeError("Cannot resume session in observer mode")
|
|
137
|
-
|
|
138
|
-
print(f"Session {self.model.id}: Resuming worker")
|
|
139
|
-
self.worker.start() # In real impl, might need to re-init process
|
|
140
|
-
|
|
141
|
-
# Async mode: assume running
|
|
142
|
-
self.model.status = "running"
|
|
143
|
-
self.model.pid = self.worker.process_id
|
|
144
|
-
self.model.updated_at = datetime.now()
|
|
145
|
-
self._save()
|
|
146
|
-
|
|
147
|
-
def terminate(self):
|
|
148
|
-
print(f"Session {self.model.id}: Terminating")
|
|
149
|
-
|
|
150
|
-
# Execute on_session_end hooks before stopping worker
|
|
151
|
-
# This allows hooks to perform cleanup while session context is still valid
|
|
152
|
-
try:
|
|
153
|
-
hook_context = self._create_hook_context()
|
|
154
|
-
results = self.hook_registry.execute_on_session_end(hook_context)
|
|
155
|
-
|
|
156
|
-
# Log hook results
|
|
157
|
-
for result in results:
|
|
158
|
-
if result.status == "failure":
|
|
159
|
-
print(f" Hook warning: {result.message}")
|
|
160
|
-
except Exception as e:
|
|
161
|
-
# Don't let hook errors prevent session termination
|
|
162
|
-
print(f" Hook execution error: {e}")
|
|
163
|
-
|
|
164
|
-
if self.worker:
|
|
165
|
-
self.worker.stop()
|
|
166
|
-
|
|
167
|
-
self.model.status = "terminated"
|
|
168
|
-
self.model.updated_at = datetime.now()
|
|
169
|
-
self._save()
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: monoco_atom_artifact
|
|
3
|
-
description: 多模态文档处理 Skill。指导 Agent 将 Office 文档转换为 PDF 并渲染为 WebP 图片,注册到 Monoco Artifact 系统。
|
|
4
|
-
type: atom
|
|
5
|
-
version: 1.0.0
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Monoco Artifact: 多模态文档处理
|
|
9
|
-
|
|
10
|
-
本 Skill 指导 Agent 执行 Office 文档 → PDF → WebP 的完整转换流程,并将结果注册为 Monoco Artifact。
|
|
11
|
-
|
|
12
|
-
## 概述
|
|
13
|
-
|
|
14
|
-
多模态文档处理允许 Agent:
|
|
15
|
-
|
|
16
|
-
1. 将 Office 文档 (.docx, .xlsx, .pptx) 转换为 PDF
|
|
17
|
-
2. 将 PDF 页面渲染为 WebP 图片 (150 DPI)
|
|
18
|
-
3. 使用 Monoco CLI 注册转换产物为 Artifact
|
|
19
|
-
|
|
20
|
-
## 环境探测
|
|
21
|
-
|
|
22
|
-
在执行转换前,Agent 必须探测以下依赖:
|
|
23
|
-
|
|
24
|
-
### 1. LibreOffice (soffice)
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
# 检查 soffice 是否可用
|
|
28
|
-
which soffice
|
|
29
|
-
soffice --version
|
|
30
|
-
|
|
31
|
-
# 常见安装路径 (macOS)
|
|
32
|
-
# /Applications/LibreOffice.app/Contents/MacOS/soffice
|
|
33
|
-
|
|
34
|
-
# 常见安装路径 (Linux)
|
|
35
|
-
# /usr/bin/soffice
|
|
36
|
-
# /usr/lib/libreoffice/program/soffice
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
**如果未安装**:
|
|
40
|
-
|
|
41
|
-
- **macOS**: `brew install --cask libreoffice`
|
|
42
|
-
- **Ubuntu/Debian**: `sudo apt-get install libreoffice`
|
|
43
|
-
- **CentOS/RHEL**: `sudo yum install libreoffice`
|
|
44
|
-
|
|
45
|
-
### 2. Python 依赖
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
# 检查 PyMuPDF (fitz)
|
|
49
|
-
python3 -c "import fitz; print(fitz.__doc__)"
|
|
50
|
-
|
|
51
|
-
# 安装依赖
|
|
52
|
-
pip install pymupdf pillow
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### 3. Monoco CLI
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
# 验证 monoco 可用
|
|
59
|
-
monoco --version
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## 转换工作流
|
|
63
|
-
|
|
64
|
-
### 标准转换流程
|
|
65
|
-
|
|
66
|
-
```mermaid
|
|
67
|
-
flowchart LR
|
|
68
|
-
A[Office Doc] -->|soffice| B[PDF]
|
|
69
|
-
B -->|fitz| C[WebP Images]
|
|
70
|
-
C -->|monoco| D[Artifact Registry]
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### 步骤 1: Office → PDF
|
|
74
|
-
|
|
75
|
-
使用 LibreOffice Headless 模式进行转换:
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
# 基础转换
|
|
79
|
-
soffice --headless --convert-to pdf --outdir /output/path /input/document.docx
|
|
80
|
-
|
|
81
|
-
# 推荐参数 (高质量、安全模式)
|
|
82
|
-
soffice \
|
|
83
|
-
--headless \
|
|
84
|
-
--convert-to pdf:writer_pdf_Export:ExportBookmarks=true \
|
|
85
|
-
--outdir /output/path \
|
|
86
|
-
/input/document.docx
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**参数说明**:
|
|
90
|
-
|
|
91
|
-
- `--headless`: 无 GUI 模式,适合服务器/自动化环境
|
|
92
|
-
- `--convert-to pdf`: 指定输出格式
|
|
93
|
-
- `--outdir`: 输出目录
|
|
94
|
-
- `ExportBookmarks=true`: 保留文档书签
|
|
95
|
-
|
|
96
|
-
### 步骤 2: PDF → WebP
|
|
97
|
-
|
|
98
|
-
使用 PyMuPDF (fitz) 渲染页面:
|
|
99
|
-
|
|
100
|
-
```python
|
|
101
|
-
import fitz # PyMuPDF
|
|
102
|
-
from pathlib import Path
|
|
103
|
-
|
|
104
|
-
def pdf_to_webp(pdf_path: str, output_dir: str, dpi: int = 150) -> list[str]:
|
|
105
|
-
"""
|
|
106
|
-
将 PDF 页面渲染为 WebP 图片。
|
|
107
|
-
|
|
108
|
-
Args:
|
|
109
|
-
pdf_path: PDF 文件路径
|
|
110
|
-
output_dir: 输出目录
|
|
111
|
-
dpi: 渲染分辨率 (默认 150 DPI)
|
|
112
|
-
|
|
113
|
-
Returns:
|
|
114
|
-
生成的 WebP 文件路径列表
|
|
115
|
-
"""
|
|
116
|
-
doc = fitz.open(pdf_path)
|
|
117
|
-
output_path = Path(output_dir)
|
|
118
|
-
output_path.mkdir(parents=True, exist_ok=True)
|
|
119
|
-
|
|
120
|
-
webp_files = []
|
|
121
|
-
zoom = dpi / 72 # 72 DPI 是 PDF 默认分辨率
|
|
122
|
-
mat = fitz.Matrix(zoom, zoom)
|
|
123
|
-
|
|
124
|
-
for page_num in range(len(doc)):
|
|
125
|
-
page = doc[page_num]
|
|
126
|
-
pix = page.get_pixmap(matrix=mat)
|
|
127
|
-
|
|
128
|
-
webp_file = output_path / f"page_{page_num + 1:03d}.webp"
|
|
129
|
-
pix.save(str(webp_file))
|
|
130
|
-
webp_files.append(str(webp_file))
|
|
131
|
-
|
|
132
|
-
doc.close()
|
|
133
|
-
return webp_files
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
**DPI 选择指南**:
|
|
137
|
-
| DPI | 用途 | 文件大小 |
|
|
138
|
-
|-----|------|----------|
|
|
139
|
-
| 72 | 预览/缩略图 | 小 |
|
|
140
|
-
| 150 | 标准阅读 (推荐) | 中等 |
|
|
141
|
-
| 300 | 高质量打印 | 大 |
|
|
142
|
-
|
|
143
|
-
### 步骤 3: 注册 Artifact
|
|
144
|
-
|
|
145
|
-
使用 Monoco CLI 注册产物:
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
# 注册单个文件
|
|
149
|
-
monoco artifact register \
|
|
150
|
-
--file /path/to/page_001.webp \
|
|
151
|
-
--type image/webp \
|
|
152
|
-
--source-document original.docx \
|
|
153
|
-
--page 1
|
|
154
|
-
|
|
155
|
-
# 批量注册整个目录
|
|
156
|
-
monoco artifact register-batch \
|
|
157
|
-
--dir /path/to/webp/output \
|
|
158
|
-
--pattern "*.webp" \
|
|
159
|
-
--source-document original.docx
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
> **注意**: 如果 `monoco artifact` 命令不可用,使用 `monoco project` 或文件元数据记录产物信息。
|
|
163
|
-
|
|
164
|
-
## 辅助脚本
|
|
165
|
-
|
|
166
|
-
项目提供 `scripts/doc-to-webp.py` 脚本简化转换流程:
|
|
167
|
-
|
|
168
|
-
```bash
|
|
169
|
-
# 完整转换流程
|
|
170
|
-
python scripts/doc-to-webp.py /path/to/document.docx --output ./artifacts --dpi 150
|
|
171
|
-
|
|
172
|
-
# 仅转换特定页面
|
|
173
|
-
python scripts/doc-to-webp.py document.docx --pages 1-5,10
|
|
174
|
-
|
|
175
|
-
# 保留中间 PDF
|
|
176
|
-
python scripts/doc-to-webp.py document.docx --keep-pdf
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## 异常处理
|
|
180
|
-
|
|
181
|
-
### 常见问题排查
|
|
182
|
-
|
|
183
|
-
#### 1. 字体缺失
|
|
184
|
-
|
|
185
|
-
**症状**: PDF 中文字显示为方块或乱码
|
|
186
|
-
|
|
187
|
-
**解决方案**:
|
|
188
|
-
|
|
189
|
-
```bash
|
|
190
|
-
# macOS: 安装中文字体
|
|
191
|
-
brew install font-noto-cjk
|
|
192
|
-
|
|
193
|
-
# Linux: 安装文泉驿字体
|
|
194
|
-
sudo apt-get install fonts-wqy-zenhei
|
|
195
|
-
|
|
196
|
-
# 或使用 Docker 运行 (包含完整字体)
|
|
197
|
-
docker run --rm -v $(pwd):/docs \
|
|
198
|
-
linuxserver/libreoffice \
|
|
199
|
-
soffice --headless --convert-to pdf /docs/input.docx
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
#### 2. 转换锁死/超时
|
|
203
|
-
|
|
204
|
-
**症状**: soffice 进程无响应
|
|
205
|
-
|
|
206
|
-
**解决方案**:
|
|
207
|
-
|
|
208
|
-
```bash
|
|
209
|
-
# 设置超时
|
|
210
|
-
timeout 60 soffice --headless --convert-to pdf input.docx
|
|
211
|
-
|
|
212
|
-
# 检查并清理僵尸进程
|
|
213
|
-
pkill -9 soffice
|
|
214
|
-
pkill -9 soffice.bin
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
#### 3. PDF 渲染质量差
|
|
218
|
-
|
|
219
|
-
**症状**: WebP 图片模糊或有锯齿
|
|
220
|
-
|
|
221
|
-
**解决方案**:
|
|
222
|
-
|
|
223
|
-
- 提高 DPI (建议 150-300)
|
|
224
|
-
- 使用抗锯齿矩阵:
|
|
225
|
-
|
|
226
|
-
```python
|
|
227
|
-
mat = fitz.Matrix(zoom, zoom).prerotate(0)
|
|
228
|
-
pix = page.get_pixmap(matrix=mat, alpha=False)
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
#### 4. 内存不足 (大文档)
|
|
232
|
-
|
|
233
|
-
**症状**: 处理大 PDF 时内存溢出
|
|
234
|
-
|
|
235
|
-
**解决方案**:
|
|
236
|
-
|
|
237
|
-
```python
|
|
238
|
-
# 逐页处理,及时释放内存
|
|
239
|
-
for page_num in range(len(doc)):
|
|
240
|
-
page = doc[page_num]
|
|
241
|
-
pix = page.get_pixmap(matrix=mat)
|
|
242
|
-
pix.save(f"page_{page_num}.webp")
|
|
243
|
-
pix = None # 显式释放
|
|
244
|
-
page = None
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
## Agent 执行模板
|
|
248
|
-
|
|
249
|
-
当用户要求处理文档时,按以下步骤执行:
|
|
250
|
-
|
|
251
|
-
```
|
|
252
|
-
1. [探测] 检查 soffice 和 PyMuPDF 是否可用
|
|
253
|
-
└─ 如果缺失 → 提示用户安装并提供命令
|
|
254
|
-
|
|
255
|
-
2. [转换] Office → PDF
|
|
256
|
-
└─ 使用 soffice --headless --convert-to pdf
|
|
257
|
-
└─ 验证 PDF 生成成功
|
|
258
|
-
|
|
259
|
-
3. [渲染] PDF → WebP
|
|
260
|
-
└─ 使用 scripts/doc-to-webp.py 或内联代码
|
|
261
|
-
└─ 默认 150 DPI,可根据需求调整
|
|
262
|
-
|
|
263
|
-
4. [注册] 调用 monoco 注册 Artifact
|
|
264
|
-
└─ 记录 source-document 和 page 元数据
|
|
265
|
-
|
|
266
|
-
5. [汇报] 向用户展示:
|
|
267
|
-
- 生成的文件列表
|
|
268
|
-
- 文件大小统计
|
|
269
|
-
- 任何警告或错误
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
## 最佳实践
|
|
273
|
-
|
|
274
|
-
1. **临时文件管理**: 使用 `tempfile.TemporaryDirectory` 管理中间文件
|
|
275
|
-
2. **错误重试**: 转换失败时自动重试 1-2 次
|
|
276
|
-
3. **并发控制**: 大文档处理时限制并发页面数
|
|
277
|
-
4. **元数据保留**: 始终记录原始文档名称和转换参数
|
|
278
|
-
5. **清理策略**: 转换完成后可选保留或删除中间 PDF
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: monoco_atom_glossary
|
|
3
|
-
description: Official Monoco Glossary and Operational Laws
|
|
4
|
-
tags: [core, definition]
|
|
5
|
-
type: atom
|
|
6
|
-
version: 1.0.0
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# Monoco Glossary
|
|
10
|
-
|
|
11
|
-
## Core Architecture Metaphor: "Linux Distro"
|
|
12
|
-
|
|
13
|
-
| Term | Definition | Metaphor |
|
|
14
|
-
| :--------------- | :-------------------------------------------------------------------------------------------------- | :---------------------------------- |
|
|
15
|
-
| **Monoco** | The Agent Operating System Distribution. Managed policy, workflow, and package system. | **Distro** (e.g., Ubuntu, Arch) |
|
|
16
|
-
| **Kimi CLI** | The core runtime execution engine. Handles LLM interaction, tool execution, and process management. | **Kernel** (Linux Kernel) |
|
|
17
|
-
| **Session** | An initialized instance of the Agent Kernel, managed by Monoco. Has state and context. | **Init System / Daemon** (systemd) |
|
|
18
|
-
| **Issue** | An atomic unit of work with state (Open/Done) and strict lifecycle. | **Unit File** (systemd unit) |
|
|
19
|
-
| **Skill** | A package of capabilities (tools, prompts, flows) that extends the Agent. | **Package** (apt/pacman package) |
|
|
20
|
-
| **Context File** | Configuration files (e.g., `GEMINI.md`, `AGENTS.md`) defining environment rules and preferences. | **Config** (`/etc/config`) |
|
|
21
|
-
| **Agent Client** | The user interface connecting to Monoco (CLI, VSCode, Zed). | **Desktop Environment** (GNOME/KDE) |
|
|
22
|
-
|
|
23
|
-
## Key Concepts
|
|
24
|
-
|
|
25
|
-
### Context File
|
|
26
|
-
|
|
27
|
-
Files like `GEMINI.md` that provide the "Constitution" for the Agent. They define the role, scope, and behavioral policies of the Agent within a specific context (Root, Directory, Project).
|
|
28
|
-
|
|
29
|
-
### Headless
|
|
30
|
-
|
|
31
|
-
Monoco is designed to run without a native GUI. It exposes its capabilities via standard protocols (LSP, ACP) to be consumed by various Clients (IDEs, Terminals).
|
|
32
|
-
|
|
33
|
-
### Universal Shell
|
|
34
|
-
|
|
35
|
-
The concept that the CLI is the universal interface for all workflows. Monoco acts as an intelligent layer over the shell.
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: monoco_atom_glossary
|
|
3
|
-
description: Monoco 官方术语表和操作法则
|
|
4
|
-
tags: [core, definition]
|
|
5
|
-
type: atom
|
|
6
|
-
version: 1.0.0
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# Monoco 术语表
|
|
10
|
-
|
|
11
|
-
## 核心架构隐喻: "Linux 发行版"
|
|
12
|
-
|
|
13
|
-
| 术语 | 定义 | 隐喻 |
|
|
14
|
-
| :--- | :--- | :--- |
|
|
15
|
-
| **Monoco** | 智能体操作系统发行版。管理策略、工作流和包系统。 | **发行版** (如 Ubuntu, Arch) |
|
|
16
|
-
| **Kimi CLI** | 核心运行时执行引擎。处理 LLM 交互、工具执行和进程管理。 | **内核** (Linux Kernel) |
|
|
17
|
-
| **Session** | 由 Monoco 管理的智能体内核初始化实例。具有状态和上下文。 | **初始化系统/守护进程** (systemd) |
|
|
18
|
-
| **Issue** | 具有状态(Open/Done)和严格生命周期的原子工作单元。 | **单元文件** (systemd unit) |
|
|
19
|
-
| **Skill** | 扩展智能体功能的工具、提示词和流程包。 | **软件包** (apt/pacman package) |
|
|
20
|
-
| **Context File** | 定义环境规则和行为偏好的配置文件(如 `GEMINI.md`, `AGENTS.md`)。 | **配置** (`/etc/config`) |
|
|
21
|
-
| **Agent Client** | 连接 Monoco 的用户界面(CLI, VSCode, Zed)。 | **桌面环境** (GNOME/KDE) |
|
|
22
|
-
|
|
23
|
-
## 关键概念
|
|
24
|
-
|
|
25
|
-
### Context File
|
|
26
|
-
|
|
27
|
-
像 `GEMINI.md` 这样的文件,为智能体提供"宪法"。它们定义了特定上下文(根目录、目录、项目)中智能体的角色、范围和行为策略。
|
|
28
|
-
|
|
29
|
-
### Headless
|
|
30
|
-
|
|
31
|
-
Monoco 设计为无需原生 GUI 即可运行。它通过标准协议(LSP, ACP)暴露其能力,供各种客户端(IDE、终端)使用。
|
|
32
|
-
|
|
33
|
-
### Universal Shell
|
|
34
|
-
|
|
35
|
-
CLI 是所有工作流的通用接口的概念。Monoco 作为 shell 的智能层。
|