mens 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.
Files changed (79) hide show
  1. mens-0.1.0/.github/workflows/release.yml +52 -0
  2. mens-0.1.0/.gitignore +17 -0
  3. mens-0.1.0/LICENSE +201 -0
  4. mens-0.1.0/PKG-INFO +108 -0
  5. mens-0.1.0/README.md +64 -0
  6. mens-0.1.0/docs/README.md +77 -0
  7. mens-0.1.0/docs/agent-cli.md +184 -0
  8. mens-0.1.0/docs/architecture.md +220 -0
  9. mens-0.1.0/docs/conversation-state.md +273 -0
  10. mens-0.1.0/docs/permissions.md +66 -0
  11. mens-0.1.0/docs/sessions.md +79 -0
  12. mens-0.1.0/docs/tui.md +245 -0
  13. mens-0.1.0/mens/__init__.py +57 -0
  14. mens-0.1.0/mens/__main__.py +11 -0
  15. mens-0.1.0/mens/agent_types.py +32 -0
  16. mens-0.1.0/mens/attachments.py +219 -0
  17. mens-0.1.0/mens/chat_web.py +213 -0
  18. mens-0.1.0/mens/cli/__init__.py +0 -0
  19. mens-0.1.0/mens/cli/chat_helpers.py +847 -0
  20. mens-0.1.0/mens/cli/commands.py +955 -0
  21. mens-0.1.0/mens/cli/console.py +248 -0
  22. mens-0.1.0/mens/cli/errors.py +83 -0
  23. mens-0.1.0/mens/cli/output.py +83 -0
  24. mens-0.1.0/mens/cli/runtime.py +128 -0
  25. mens-0.1.0/mens/client.py +1109 -0
  26. mens-0.1.0/mens/data/SKILL.md +146 -0
  27. mens-0.1.0/mens/data/chat_web.html +455 -0
  28. mens-0.1.0/mens/mcp/__init__.py +15 -0
  29. mens-0.1.0/mens/mcp/client.py +173 -0
  30. mens-0.1.0/mens/mcp/converter.py +92 -0
  31. mens-0.1.0/mens/memory.py +100 -0
  32. mens-0.1.0/mens/permissions.py +256 -0
  33. mens-0.1.0/mens/serve.py +388 -0
  34. mens-0.1.0/mens/session.py +127 -0
  35. mens-0.1.0/mens/task_manager.py +165 -0
  36. mens-0.1.0/mens/todo_tracker.py +70 -0
  37. mens-0.1.0/mens/tools/__init__.py +39 -0
  38. mens-0.1.0/mens/tools/base.py +299 -0
  39. mens-0.1.0/mens/tools/file_tools.py +222 -0
  40. mens-0.1.0/mens/tools/search_tools.py +205 -0
  41. mens-0.1.0/mens/tools/shell_tool.py +67 -0
  42. mens-0.1.0/mens/tools/task_tool.py +35 -0
  43. mens-0.1.0/mens/tools/task_tools.py +178 -0
  44. mens-0.1.0/mens/tracing.py +171 -0
  45. mens-0.1.0/mens/tui/__init__.py +5 -0
  46. mens-0.1.0/mens/tui/app.py +759 -0
  47. mens-0.1.0/mens/tui/clipboard.py +185 -0
  48. mens-0.1.0/mens/tui/completion.py +153 -0
  49. mens-0.1.0/mens/tui/latex.py +156 -0
  50. mens-0.1.0/mens/tui/screens.py +80 -0
  51. mens-0.1.0/mens/tui/slash.py +138 -0
  52. mens-0.1.0/mens/tui/widgets.py +240 -0
  53. mens-0.1.0/mens/types.py +45 -0
  54. mens-0.1.0/mens/validators/__init__.py +30 -0
  55. mens-0.1.0/mens/validators/base.py +112 -0
  56. mens-0.1.0/mens/validators/python.py +228 -0
  57. mens-0.1.0/pyproject.toml +83 -0
  58. mens-0.1.0/tests/__init__.py +0 -0
  59. mens-0.1.0/tests/unit/__init__.py +0 -0
  60. mens-0.1.0/tests/unit/test_agent_claude.py +307 -0
  61. mens-0.1.0/tests/unit/test_agent_client.py +1070 -0
  62. mens-0.1.0/tests/unit/test_agent_features.py +428 -0
  63. mens-0.1.0/tests/unit/test_agent_serve.py +229 -0
  64. mens-0.1.0/tests/unit/test_agent_subagent.py +275 -0
  65. mens-0.1.0/tests/unit/test_agent_tools.py +388 -0
  66. mens-0.1.0/tests/unit/test_approval.py +126 -0
  67. mens-0.1.0/tests/unit/test_attachments.py +136 -0
  68. mens-0.1.0/tests/unit/test_cli_contract.py +618 -0
  69. mens-0.1.0/tests/unit/test_cli_mcp_integration.py +84 -0
  70. mens-0.1.0/tests/unit/test_clipboard.py +179 -0
  71. mens-0.1.0/tests/unit/test_completion.py +112 -0
  72. mens-0.1.0/tests/unit/test_memory.py +178 -0
  73. mens-0.1.0/tests/unit/test_permissions.py +261 -0
  74. mens-0.1.0/tests/unit/test_session.py +149 -0
  75. mens-0.1.0/tests/unit/test_tool_registry.py +339 -0
  76. mens-0.1.0/tests/unit/test_tracing.py +319 -0
  77. mens-0.1.0/tests/unit/test_tui.py +1017 -0
  78. mens-0.1.0/tests/unit/test_tui_latex.py +97 -0
  79. mens-0.1.0/uv.lock +2980 -0
@@ -0,0 +1,52 @@
1
+ name: Release
2
+
3
+ # 打 v* tag 即发布:构建 → 上传 PyPI → 创建 GitHub Release。
4
+ # 认证走 PyPI Trusted Publishing(OIDC),仓库里不存任何 token。
5
+ on:
6
+ push:
7
+ tags:
8
+ - "v*"
9
+ workflow_dispatch:
10
+
11
+ permissions:
12
+ contents: write # 创建 GitHub Release
13
+ id-token: write # PyPI OIDC
14
+
15
+ jobs:
16
+ release:
17
+ runs-on: ubuntu-latest
18
+ environment: pypi
19
+ steps:
20
+ - uses: actions/checkout@v7
21
+
22
+ # setup-uv 不维护 v8/v9 移动标签,只能引用具体版本
23
+ - uses: astral-sh/setup-uv@v9.0.0
24
+ with:
25
+ python-version: "3.10"
26
+
27
+ # tag 与包内版本不一致必然是误操作,早失败好过发出错版本
28
+ - name: Verify tag matches package version
29
+ if: startsWith(github.ref, 'refs/tags/v')
30
+ run: |
31
+ tag="${GITHUB_REF#refs/tags/v}"
32
+ pkg="$(sed -n 's/^__version__ = "\(.*\)"/\1/p' mens/__init__.py)"
33
+ echo "tag=$tag __version__=$pkg"
34
+ [ "$tag" = "$pkg" ] || { echo "::error::tag v$tag 与 mens.__version__ ($pkg) 不一致"; exit 1; }
35
+
36
+ - name: Run tests
37
+ run: |
38
+ uv sync --all-extras --dev
39
+ uv run pytest -q
40
+
41
+ - name: Build
42
+ run: uv build
43
+
44
+ - name: Publish to PyPI
45
+ uses: pypa/gh-action-pypi-publish@release/v1
46
+
47
+ - name: Create GitHub Release
48
+ if: startsWith(github.ref, 'refs/tags/')
49
+ uses: softprops/action-gh-release@v3
50
+ with:
51
+ generate_release_notes: true
52
+ files: dist/*
mens-0.1.0/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .eggs/
7
+ *.egg
8
+ .venv/
9
+ .pytest_cache/
10
+ .ruff_cache/
11
+
12
+ # 运行时产物:项目级权限规则,由"总是允许"写入 cwd。
13
+ # 属于个人的信任决定(哪些命令可免审批),不适合随仓库共享
14
+ .mens/
15
+
16
+ # 外部参考资料克隆,不是本项目的一部分
17
+ learn-claude-code/
mens-0.1.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
mens-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: mens
3
+ Version: 0.1.0
4
+ Summary: Agent framework with built-in tools, MCP integration, and CLI
5
+ Project-URL: Homepage, https://github.com/KenyonY/mens
6
+ Project-URL: Repository, https://github.com/KenyonY/mens
7
+ Project-URL: Issues, https://github.com/KenyonY/mens/issues
8
+ Author-email: kunyuan <beidongjiedeguang@gmail.com>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agent,cli,llm,mcp,tool-use
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: flatlatex>=0.15
23
+ Requires-Dist: flaxkv2>=0.2.5
24
+ Requires-Dist: flexllm>=0.9.0
25
+ Requires-Dist: pillow>=10.0
26
+ Requires-Dist: psutil>=5.9.0
27
+ Requires-Dist: pylatexenc>=2.10
28
+ Requires-Dist: pyyaml>=6.0
29
+ Requires-Dist: rich>=12.0.0
30
+ Requires-Dist: textual>=8.2.8
31
+ Requires-Dist: typer>=0.9.0
32
+ Provides-Extra: all
33
+ Requires-Dist: aiohttp>=3.8.0; extra == 'all'
34
+ Requires-Dist: mcp>=1.0; extra == 'all'
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest-asyncio>=0.20.0; extra == 'dev'
37
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
38
+ Requires-Dist: ruff>=0.8.0; extra == 'dev'
39
+ Provides-Extra: mcp
40
+ Requires-Dist: mcp>=1.0; extra == 'mcp'
41
+ Provides-Extra: serve
42
+ Requires-Dist: aiohttp>=3.8.0; extra == 'serve'
43
+ Description-Content-Type: text/markdown
44
+
45
+ # mens
46
+
47
+ Agent framework with built-in tools, MCP integration, and CLI.
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install mens[all]
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ```python
58
+ from flexllm import LLMClient
59
+ from mens import AgentClient
60
+
61
+ llm = LLMClient(model="gpt-4o")
62
+ agent = AgentClient(llm)
63
+ result = await agent.run("读取 main.py 并分析")
64
+ ```
65
+
66
+ ## CLI
67
+
68
+ ```bash
69
+ mens run "查一下 cpu 使用率" # 非交互执行(支持 stdin 管道)
70
+ mens run --tools code "读取 main.py"
71
+ mens chat # 交互式全屏 TUI
72
+ mens chat -c # 恢复最近会话
73
+ mens sessions list # 会话管理
74
+ ```
75
+
76
+ ### 程序 / AI Agent 调用
77
+
78
+ `mens run` 是给自动化用的入口:stdout 是结果、stderr 是过程,退出码表达成败。
79
+
80
+ ```bash
81
+ mens info # 自描述:工具/skill/退出码(JSON)
82
+ mens run "任务" --format json # 完整执行记录
83
+ mens run "任务" --format json || echo "失败: $?" # 0 成功 / 2 参数错 / 5 未完成
84
+ ```
85
+
86
+ 跨调用多轮:`--session <id>` 新建会话、`--resume <id>` 续接(分开是为了让"撞上同名旧会话"
87
+ 报错而不是静默接上陌生上下文)。
88
+
89
+ 退出码与 JSON 字段的完整契约见 [docs/agent-cli.md](docs/agent-cli.md)。
90
+
91
+ 给 Claude Code 等 AI agent 用时,先装 skill 让它一次拿到心智模型,不必逐层 `--help` 摸索:
92
+
93
+ ```bash
94
+ mens install-skill # → 软链到 ~/.claude/skills/mens/(重开会话后生效)
95
+ ```
96
+
97
+ 软链而非复制:升级 mens 后 skill 自动跟着更新,不必记得重装。
98
+
99
+ ### 交互式 TUI(mens chat)
100
+
101
+ 全屏终端界面:流式输出、工具调用卡片、斜杠命令(`/help` `/clear` `/compact` `/model` `/resume` …)、
102
+ Esc 中断当前任务、↑/↓ 输入历史、Tab `@路径` 补全。
103
+
104
+ - **权限**:默认 `default` 模式(只读放行,写操作弹窗审批),"总是允许"会把规则持久化到
105
+ `.mens/settings.json`(如 `bash(git commit:*)`)。详见 [docs/permissions.md](docs/permissions.md)
106
+ - **会话**:每轮自动持久化(flaxkv2),`-c/--resume` 或 TUI 内 `/resume` 恢复。详见 [docs/sessions.md](docs/sessions.md)
107
+
108
+ 完整文档见 [docs/](docs/README.md)。
mens-0.1.0/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # mens
2
+
3
+ Agent framework with built-in tools, MCP integration, and CLI.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install mens[all]
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ from flexllm import LLMClient
15
+ from mens import AgentClient
16
+
17
+ llm = LLMClient(model="gpt-4o")
18
+ agent = AgentClient(llm)
19
+ result = await agent.run("读取 main.py 并分析")
20
+ ```
21
+
22
+ ## CLI
23
+
24
+ ```bash
25
+ mens run "查一下 cpu 使用率" # 非交互执行(支持 stdin 管道)
26
+ mens run --tools code "读取 main.py"
27
+ mens chat # 交互式全屏 TUI
28
+ mens chat -c # 恢复最近会话
29
+ mens sessions list # 会话管理
30
+ ```
31
+
32
+ ### 程序 / AI Agent 调用
33
+
34
+ `mens run` 是给自动化用的入口:stdout 是结果、stderr 是过程,退出码表达成败。
35
+
36
+ ```bash
37
+ mens info # 自描述:工具/skill/退出码(JSON)
38
+ mens run "任务" --format json # 完整执行记录
39
+ mens run "任务" --format json || echo "失败: $?" # 0 成功 / 2 参数错 / 5 未完成
40
+ ```
41
+
42
+ 跨调用多轮:`--session <id>` 新建会话、`--resume <id>` 续接(分开是为了让"撞上同名旧会话"
43
+ 报错而不是静默接上陌生上下文)。
44
+
45
+ 退出码与 JSON 字段的完整契约见 [docs/agent-cli.md](docs/agent-cli.md)。
46
+
47
+ 给 Claude Code 等 AI agent 用时,先装 skill 让它一次拿到心智模型,不必逐层 `--help` 摸索:
48
+
49
+ ```bash
50
+ mens install-skill # → 软链到 ~/.claude/skills/mens/(重开会话后生效)
51
+ ```
52
+
53
+ 软链而非复制:升级 mens 后 skill 自动跟着更新,不必记得重装。
54
+
55
+ ### 交互式 TUI(mens chat)
56
+
57
+ 全屏终端界面:流式输出、工具调用卡片、斜杠命令(`/help` `/clear` `/compact` `/model` `/resume` …)、
58
+ Esc 中断当前任务、↑/↓ 输入历史、Tab `@路径` 补全。
59
+
60
+ - **权限**:默认 `default` 模式(只读放行,写操作弹窗审批),"总是允许"会把规则持久化到
61
+ `.mens/settings.json`(如 `bash(git commit:*)`)。详见 [docs/permissions.md](docs/permissions.md)
62
+ - **会话**:每轮自动持久化(flaxkv2),`-c/--resume` 或 TUI 内 `/resume` 恢复。详见 [docs/sessions.md](docs/sessions.md)
63
+
64
+ 完整文档见 [docs/](docs/README.md)。
@@ -0,0 +1,77 @@
1
+ # mens 文档
2
+
3
+ mens 是一个 coding agent 框架:底层是可编程的 `AgentClient`(tool-use 循环 + MCP + 验证闭环),
4
+ 上层提供 Claude Code 风格的交互式 CLI(Textual TUI + 权限系统 + 会话持久化)。
5
+
6
+ ## 文档目录
7
+
8
+ ```
9
+ docs/
10
+ ├── README.md # 本文档:总览与模块清单
11
+ ├── architecture.md # 架构图:分层 / 运行时数据流 / 工具与 subagent / 权限 / 状态落点
12
+ ├── agent-cli.md # 供 Agent 调用的 CLI 契约(退出码 / JSON / 无人值守)
13
+ ├── conversation-state.md # 对话状态与消息序列不变式(工具轨迹为何不能丢)
14
+ ├── tui.md # 交互式 TUI(mens chat):布局 / 补全 / 图片输入 / 排队
15
+ ├── permissions.md # 权限系统(mode + rule + settings.json)
16
+ └── sessions.md # 会话持久化与恢复
17
+ ```
18
+
19
+ ## 架构总览
20
+
21
+ 图示版(分层、时序、权限决策、状态落点)见 [architecture.md](architecture.md)。
22
+
23
+ ```
24
+ mens/
25
+ ├── client.py AgentClient:tool-use 循环(流式/并行工具/审批/compact)
26
+ ├── attachments.py 图片附件:输入文本里的图片路径 → 多模态 content block
27
+ ├── permissions.py 权限系统:PermissionMode + PermissionRule + settings.json
28
+ ├── session.py SessionStore:会话持久化(flaxkv2 / LMDB)
29
+ ├── memory.py MemoryStore:库用户的通用记忆存储
30
+ ├── agent_types.py subagent 类型(explore/code/plan)
31
+ ├── tools/ 内置工具:read/write/edit/glob/grep/bash(async) + task/todo
32
+ ├── mcp/ MCP 集成(stdio + SSE)
33
+ ├── validators/ 代码验证器(syntax/lint/type/pytest),驱动自动修复闭环
34
+ ├── tui/ Textual 全屏 TUI(app/widgets/screens/slash)
35
+ ├── cli/
36
+ │ ├── runtime.py AgentRuntime:CLI 共享装配层(LLM/MCP/工具/权限生命周期)
37
+ │ ├── commands.py typer 命令:run/info/chat/serve/chat-web/sessions
38
+ │ ├── chat_helpers.py skill 加载、system 构建、run/简单循环/TUI 启动
39
+ │ ├── errors.py 退出码体系 + CliError(机器可读 code/suggestion/retryable)
40
+ │ ├── output.py 结构化输出:AgentResult/CliError → JSON 契约
41
+ │ └── console.py 非交互输出(verbose/compact/quiet,stderr 过程 + stdout 结果)
42
+ ├── serve.py HTTP API(aiohttp + SSE)
43
+ ├── chat_web.py Web 聊天界面
44
+ └── data/
45
+ ├── SKILL.md 给 AI agent 的心智模型(`mens install-skill` 软链到 ~/.claude/skills/)
46
+ └── chat_web.html Web 界面前端(单文件,无构建步骤)
47
+ ```
48
+
49
+ ## CLI 入口
50
+
51
+ | 命令 | 用途 |
52
+ |---|---|
53
+ | `mens run "任务"` | 非交互执行,支持 stdin 管道,默认 bypass 权限 |
54
+ | `mens info` | 自描述:可用工具 / skill / 权限模式 / 退出码(默认 JSON) |
55
+ | `mens chat` | 交互式全屏 TUI,默认 default 权限(写操作审批) |
56
+ | `mens chat -c` / `--resume <id>` | 恢复会话 |
57
+ | `mens chat --no-tui` | 简单 REPL(无 Textual 依赖场景保底) |
58
+ | `mens run --session <id>` / `--resume <id>` | 跨调用多轮:新建 / 续接 |
59
+ | `mens sessions list/show/delete` | 会话管理 |
60
+ | `mens serve` | HTTP API 服务 |
61
+ | `mens chat-web` | Web 聊天界面 |
62
+ | `mens install-skill` | 把 SKILL.md 软链进 Claude Code 的 skills 目录(升级后自动跟随) |
63
+
64
+ 模型配置沿用 flexllm(`~/.flexllm/config.yaml`),`-m` 指定模型名。
65
+
66
+ **程序 / AI agent 调用请用 `mens run`**,契约(退出码、`--format json`、错误结构)
67
+ 见 [agent-cli.md](agent-cli.md)。`mens chat` 面向人类,非 TTY 下会直接报错。
68
+
69
+ ## 设计要点
70
+
71
+ - **组合而非继承**:`AgentClient` 组合 `flexllm.LLMClient`,不修改底层客户端。
72
+ - **TUI 与引擎解耦**:`permissions.py`/`session.py`/`client.py` 不依赖 Textual;
73
+ `tui/` 只在交互模式导入,`mens run`/`serve` 路径零 TUI 开销。
74
+ - **bash 工具是 async**(`asyncio.create_subprocess_shell` + 进程组终止),
75
+ 保证 TUI 不被阻塞、Esc 中断能立刻杀掉子进程。
76
+ - **审批是 async 化的**:`approval_handler` 返回 awaitable 时会被 await,
77
+ TUI 的审批弹窗借此让 agent 循环自然挂起等待用户决策。