slife 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 (61) hide show
  1. slife-0.1.0/.claude/settings.local.json +10 -0
  2. slife-0.1.0/.gitignore +221 -0
  3. slife-0.1.0/.python-version +1 -0
  4. slife-0.1.0/.vscode/extensions.json +5 -0
  5. slife-0.1.0/.vscode/settings.json +21 -0
  6. slife-0.1.0/LICENSE +21 -0
  7. slife-0.1.0/PKG-INFO +147 -0
  8. slife-0.1.0/README.md +122 -0
  9. slife-0.1.0/docs/design.md +251 -0
  10. slife-0.1.0/pyproject.toml +56 -0
  11. slife-0.1.0/skills/baidu-search/SKILL.md +63 -0
  12. slife-0.1.0/skills/baidu-search/_meta.json +6 -0
  13. slife-0.1.0/skills/baidu-search/references/apikey-fetch.md +58 -0
  14. slife-0.1.0/skills/baidu-search/scripts/search.py +124 -0
  15. slife-0.1.0/slife/__init__.py +120 -0
  16. slife-0.1.0/slife/__main__.py +5 -0
  17. slife-0.1.0/slife/agent/__init__.py +0 -0
  18. slife-0.1.0/slife/agent/conversation.py +92 -0
  19. slife-0.1.0/slife/agent/llm_client.py +237 -0
  20. slife-0.1.0/slife/agent/loop.py +336 -0
  21. slife-0.1.0/slife/agent/multimodal.py +63 -0
  22. slife-0.1.0/slife/agent/service.py +61 -0
  23. slife-0.1.0/slife/agent/system_prompt.py +12 -0
  24. slife-0.1.0/slife/agent/templates/system_prompt.j2 +5 -0
  25. slife-0.1.0/slife/config.py +212 -0
  26. slife-0.1.0/slife/env.py +62 -0
  27. slife-0.1.0/slife/platform.py +97 -0
  28. slife-0.1.0/slife/tools/__init__.py +0 -0
  29. slife-0.1.0/slife/tools/base.py +51 -0
  30. slife-0.1.0/slife/tools/factory.py +68 -0
  31. slife-0.1.0/slife/tools/registry.py +55 -0
  32. slife-0.1.0/slife/tools/serper.py +62 -0
  33. slife-0.1.0/slife/tools/shell.py +69 -0
  34. slife-0.1.0/slife/tools/shell_command.py +54 -0
  35. slife-0.1.0/slife/tools/skill.py +151 -0
  36. slife-0.1.0/slife/ui/__init__.py +0 -0
  37. slife-0.1.0/slife/ui/app.py +172 -0
  38. slife-0.1.0/slife/ui/chat.py +121 -0
  39. slife-0.1.0/slife/ui/handler.py +66 -0
  40. slife-0.1.0/slife/ui/slife.tcss +104 -0
  41. slife-0.1.0/slife/ui/tool_display.py +288 -0
  42. slife-0.1.0/slife.json5.example +72 -0
  43. slife-0.1.0/tests/__init__.py +1 -0
  44. slife-0.1.0/tests/conftest.py +283 -0
  45. slife-0.1.0/tests/test_config.py +332 -0
  46. slife-0.1.0/tests/test_conversation.py +198 -0
  47. slife-0.1.0/tests/test_env.py +180 -0
  48. slife-0.1.0/tests/test_llm_client.py +442 -0
  49. slife-0.1.0/tests/test_loop.py +472 -0
  50. slife-0.1.0/tests/test_main.py +126 -0
  51. slife-0.1.0/tests/test_multimodal.py +202 -0
  52. slife-0.1.0/tests/test_system_prompt.py +22 -0
  53. slife-0.1.0/tests/test_tools_base.py +106 -0
  54. slife-0.1.0/tests/test_tools_factory.py +84 -0
  55. slife-0.1.0/tests/test_tools_registry.py +74 -0
  56. slife-0.1.0/tests/test_tools_serper.py +181 -0
  57. slife-0.1.0/tests/test_tools_shell.py +140 -0
  58. slife-0.1.0/tests/test_ui_app.py +226 -0
  59. slife-0.1.0/tests/test_ui_chat.py +167 -0
  60. slife-0.1.0/tests/test_ui_tool_display.py +290 -0
  61. slife-0.1.0/uv.lock +617 -0
@@ -0,0 +1,10 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "PowerShell(uv sync *)",
5
+ "PowerShell(uv run *)",
6
+ "Bash(git config *)",
7
+ "PowerShell(uv build *)"
8
+ ]
9
+ }
10
+ }
slife-0.1.0/.gitignore ADDED
@@ -0,0 +1,221 @@
1
+ # Project config (contains local settings)
2
+ slife.json5
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[codz]
7
+ *$py.class
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py.cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ # Pipfile.lock
99
+
100
+ # UV
101
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ # uv.lock
105
+
106
+ # poetry
107
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
108
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
109
+ # commonly ignored for libraries.
110
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
111
+ # poetry.lock
112
+ # poetry.toml
113
+
114
+ # pdm
115
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
116
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
117
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
118
+ # pdm.lock
119
+ # pdm.toml
120
+ .pdm-python
121
+ .pdm-build/
122
+
123
+ # pixi
124
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
125
+ # pixi.lock
126
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
127
+ # in the .venv directory. It is recommended not to include this directory in version control.
128
+ .pixi
129
+
130
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
131
+ __pypackages__/
132
+
133
+ # Celery stuff
134
+ celerybeat-schedule
135
+ celerybeat.pid
136
+
137
+ # Redis
138
+ *.rdb
139
+ *.aof
140
+ *.pid
141
+
142
+ # RabbitMQ
143
+ mnesia/
144
+ rabbitmq/
145
+ rabbitmq-data/
146
+
147
+ # ActiveMQ
148
+ activemq-data/
149
+
150
+ # SageMath parsed files
151
+ *.sage.py
152
+
153
+ # Environments
154
+ .env
155
+ .envrc
156
+ .venv
157
+ env/
158
+ venv/
159
+ ENV/
160
+ env.bak/
161
+ venv.bak/
162
+
163
+ # Spyder project settings
164
+ .spyderproject
165
+ .spyproject
166
+
167
+ # Rope project settings
168
+ .ropeproject
169
+
170
+ # mkdocs documentation
171
+ /site
172
+
173
+ # mypy
174
+ .mypy_cache/
175
+ .dmypy.json
176
+ dmypy.json
177
+
178
+ # Pyre type checker
179
+ .pyre/
180
+
181
+ # pytype static type analyzer
182
+ .pytype/
183
+
184
+ # Cython debug symbols
185
+ cython_debug/
186
+
187
+ # PyCharm
188
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
189
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
190
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
191
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
192
+ # .idea/
193
+
194
+ # Abstra
195
+ # Abstra is an AI-powered process automation framework.
196
+ # Ignore directories containing user credentials, local state, and settings.
197
+ # Learn more at https://abstra.io/docs
198
+ .abstra/
199
+
200
+ # Visual Studio Code
201
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
202
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
203
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
204
+ # you could uncomment the following to ignore the entire vscode folder
205
+ # .vscode/
206
+ # Temporary file for partial code execution
207
+ tempCodeRunnerFile.py
208
+
209
+ # Ruff stuff:
210
+ .ruff_cache/
211
+
212
+ # PyPI configuration file
213
+ .pypirc
214
+
215
+ # Marimo
216
+ marimo/_static/
217
+ marimo/_lsp/
218
+ __marimo__/
219
+
220
+ # Streamlit
221
+ .streamlit/secrets.toml
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,5 @@
1
+ {
2
+ "recommendations": [
3
+ "mrmlnc.vscode-json5"
4
+ ]
5
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "files.associations": {
3
+ "*.json5": "json5",
4
+ "*.j2": "jinja"
5
+ },
6
+ "[json5]": {
7
+ "editor.tabSize": 2,
8
+ "editor.insertSpaces": true
9
+ },
10
+ "[jinja]": {
11
+ "editor.wordWrap": "on"
12
+ },
13
+ "[log]": {
14
+ "editor.wordWrap": "on",
15
+ "editor.quickSuggestions": {
16
+ "comments": "off",
17
+ "strings": "off",
18
+ "other": "off"
19
+ }
20
+ }
21
+ }
slife-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 juzcn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
slife-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.4
2
+ Name: slife
3
+ Version: 0.1.0
4
+ Summary: Terminal-based AI agent — a function-calling loop with minimum harness
5
+ Project-URL: Homepage, https://github.com/juzcn/slife
6
+ Project-URL: Repository, https://github.com/juzcn/slife
7
+ Author-email: juzcn <zhangjun@cueb.edu.cn>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Terminals
18
+ Requires-Python: >=3.13
19
+ Requires-Dist: httpx>=0.27.0
20
+ Requires-Dist: jinja2>=3.1.0
21
+ Requires-Dist: json5>=0.15.0
22
+ Requires-Dist: openai>=1.0.0
23
+ Requires-Dist: textual>=1.0.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ # slife
27
+
28
+ Terminal-based AI agent — a function-calling loop with minimum harness. Chat with an LLM that can execute shell commands, search the web, and load on-demand skills.
29
+
30
+ ## Quick Start
31
+
32
+ ```bash
33
+ # Install
34
+ uv sync
35
+
36
+ # Configure
37
+ cp slife.json5.example slife.json5
38
+ # Edit slife.json5 — set your API keys via ${ENV_VAR} references
39
+
40
+ # Run
41
+ uv run slife
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ Edit `slife.json5`. Key sections:
47
+
48
+ ```json5
49
+ {
50
+ models: {
51
+ providers: {
52
+ deepseek: {
53
+ base_url: "https://api.deepseek.com",
54
+ api_key: "${DEEPSEEK_API_KEY}",
55
+ models: [
56
+ { model: "deepseek-v4-flash", name: "DeepSeek V4 Flash" },
57
+ { model: "deepseek-v4-pro", name: "DeepSeek V4 Pro", reasoning: true },
58
+ ],
59
+ },
60
+ },
61
+ },
62
+ active_model: "deepseek/deepseek-v4-pro",
63
+ agent: { max_iterations: 10 },
64
+ tools: [
65
+ { type: "platform" },
66
+ { type: "shell", timeout: 30 },
67
+ { type: "serper" },
68
+ { type: "skill", skills_dir: "skills" },
69
+ ],
70
+ }
71
+ ```
72
+
73
+ API keys use `${ENV_VAR}` syntax — set them in your environment, not in the config file.
74
+
75
+ ## Tools
76
+
77
+ | Tool | Type | What it does |
78
+ |------|------|-------------|
79
+ | `execute_shell` | `shell` | Run shell commands on the host machine |
80
+ | `get_shell_command` | `platform` | Translate intent into OS-correct shell syntax |
81
+ | `web_search` | `serper` | Google Search via Serper.dev API |
82
+ | `list_skills` | `skill` | List available skill plugins |
83
+ | `use_skill` | `skill` | Load a skill's documentation into context |
84
+
85
+ Add or remove tools from the `tools[]` list to control what the agent can do.
86
+
87
+ ## Skills
88
+
89
+ Skills are on-demand documentation plugins. The agent loads them only when needed, keeping the context lean.
90
+
91
+ ```
92
+ skills/baidu-search/
93
+ SKILL.md # Instructions the agent reads
94
+ scripts/search.py # Supporting code
95
+ ```
96
+
97
+ Flow: the agent calls `list_skills` → sees what's available → calls `use_skill("baidu-search")` to load full instructions.
98
+
99
+ To add a skill, create a directory under `skills/` with a `SKILL.md` file.
100
+
101
+ ## Tips
102
+
103
+ - **`/file image.png`** — attach an image for vision models
104
+ - **`Ctrl+C`** — clear the conversation
105
+ - **`Ctrl+Q`** — quit
106
+
107
+ ## Design
108
+
109
+ slife is a **minimum-harness agent**. The harness only does three things the LLM cannot: execute tools, maintain conversation state, and stream responses. Everything else — reasoning, planning, tool selection, error recovery — is the LLM's job.
110
+
111
+ The system prompt is intentionally lean. It only contains project-specific information not in the LLM's training data. The LLM already knows how function calling works.
112
+
113
+ See [docs/design.md](docs/design.md) for the full design rationale.
114
+
115
+ ## Project Structure
116
+
117
+ ```
118
+ slife/
119
+ agent/ # Core agent loop, LLM client, conversation
120
+ loop.py # Function-calling while-loop
121
+ llm_client.py # OpenAI-compatible streaming client
122
+ conversation.py# Message history (OpenAI format)
123
+ service.py # Wiring: client + tools + loop
124
+ system_prompt.py# Jinja2 template rendering
125
+ tools/ # Extensible tool system
126
+ base.py # Tool ABC
127
+ registry.py # Name → Tool lookup
128
+ factory.py # Config type → Tool instances
129
+ shell.py # execute_shell
130
+ shell_command.py# get_shell_command (platform-aware)
131
+ serper.py # web_search (Serper.dev)
132
+ skill.py # list_skills / use_skill
133
+ ui/ # Textual TUI
134
+ app.py # Main application
135
+ chat.py # Message widgets
136
+ handler.py # Streaming event → UI bridge
137
+ tool_display.py# Tool call rendering
138
+ config.py # JSON5 config loading
139
+ env.py # ${ENV_VAR} resolution
140
+ platform.py # OS detection, shell syntax
141
+ skills/ # Skill plugins
142
+ docs/ # Design documents
143
+ ```
144
+
145
+ ## License
146
+
147
+ MIT
slife-0.1.0/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # slife
2
+
3
+ Terminal-based AI agent — a function-calling loop with minimum harness. Chat with an LLM that can execute shell commands, search the web, and load on-demand skills.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Install
9
+ uv sync
10
+
11
+ # Configure
12
+ cp slife.json5.example slife.json5
13
+ # Edit slife.json5 — set your API keys via ${ENV_VAR} references
14
+
15
+ # Run
16
+ uv run slife
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ Edit `slife.json5`. Key sections:
22
+
23
+ ```json5
24
+ {
25
+ models: {
26
+ providers: {
27
+ deepseek: {
28
+ base_url: "https://api.deepseek.com",
29
+ api_key: "${DEEPSEEK_API_KEY}",
30
+ models: [
31
+ { model: "deepseek-v4-flash", name: "DeepSeek V4 Flash" },
32
+ { model: "deepseek-v4-pro", name: "DeepSeek V4 Pro", reasoning: true },
33
+ ],
34
+ },
35
+ },
36
+ },
37
+ active_model: "deepseek/deepseek-v4-pro",
38
+ agent: { max_iterations: 10 },
39
+ tools: [
40
+ { type: "platform" },
41
+ { type: "shell", timeout: 30 },
42
+ { type: "serper" },
43
+ { type: "skill", skills_dir: "skills" },
44
+ ],
45
+ }
46
+ ```
47
+
48
+ API keys use `${ENV_VAR}` syntax — set them in your environment, not in the config file.
49
+
50
+ ## Tools
51
+
52
+ | Tool | Type | What it does |
53
+ |------|------|-------------|
54
+ | `execute_shell` | `shell` | Run shell commands on the host machine |
55
+ | `get_shell_command` | `platform` | Translate intent into OS-correct shell syntax |
56
+ | `web_search` | `serper` | Google Search via Serper.dev API |
57
+ | `list_skills` | `skill` | List available skill plugins |
58
+ | `use_skill` | `skill` | Load a skill's documentation into context |
59
+
60
+ Add or remove tools from the `tools[]` list to control what the agent can do.
61
+
62
+ ## Skills
63
+
64
+ Skills are on-demand documentation plugins. The agent loads them only when needed, keeping the context lean.
65
+
66
+ ```
67
+ skills/baidu-search/
68
+ SKILL.md # Instructions the agent reads
69
+ scripts/search.py # Supporting code
70
+ ```
71
+
72
+ Flow: the agent calls `list_skills` → sees what's available → calls `use_skill("baidu-search")` to load full instructions.
73
+
74
+ To add a skill, create a directory under `skills/` with a `SKILL.md` file.
75
+
76
+ ## Tips
77
+
78
+ - **`/file image.png`** — attach an image for vision models
79
+ - **`Ctrl+C`** — clear the conversation
80
+ - **`Ctrl+Q`** — quit
81
+
82
+ ## Design
83
+
84
+ slife is a **minimum-harness agent**. The harness only does three things the LLM cannot: execute tools, maintain conversation state, and stream responses. Everything else — reasoning, planning, tool selection, error recovery — is the LLM's job.
85
+
86
+ The system prompt is intentionally lean. It only contains project-specific information not in the LLM's training data. The LLM already knows how function calling works.
87
+
88
+ See [docs/design.md](docs/design.md) for the full design rationale.
89
+
90
+ ## Project Structure
91
+
92
+ ```
93
+ slife/
94
+ agent/ # Core agent loop, LLM client, conversation
95
+ loop.py # Function-calling while-loop
96
+ llm_client.py # OpenAI-compatible streaming client
97
+ conversation.py# Message history (OpenAI format)
98
+ service.py # Wiring: client + tools + loop
99
+ system_prompt.py# Jinja2 template rendering
100
+ tools/ # Extensible tool system
101
+ base.py # Tool ABC
102
+ registry.py # Name → Tool lookup
103
+ factory.py # Config type → Tool instances
104
+ shell.py # execute_shell
105
+ shell_command.py# get_shell_command (platform-aware)
106
+ serper.py # web_search (Serper.dev)
107
+ skill.py # list_skills / use_skill
108
+ ui/ # Textual TUI
109
+ app.py # Main application
110
+ chat.py # Message widgets
111
+ handler.py # Streaming event → UI bridge
112
+ tool_display.py# Tool call rendering
113
+ config.py # JSON5 config loading
114
+ env.py # ${ENV_VAR} resolution
115
+ platform.py # OS detection, shell syntax
116
+ skills/ # Skill plugins
117
+ docs/ # Design documents
118
+ ```
119
+
120
+ ## License
121
+
122
+ MIT