mycode-sdk 0.4.2__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,88 @@
1
+ # OS specific
2
+ .DS_Store
3
+ .DS_Store?
4
+ ._*
5
+ .Spotlight-V100
6
+ .Trashes
7
+ ehthumbs.db
8
+ Thumbs.db
9
+ *.swp
10
+ *.swo
11
+ *~
12
+
13
+ # IDEs and Editors
14
+ .vscode/
15
+ !.vscode/extensions.json
16
+ .idea/
17
+ *.suo
18
+ *.ntvs*
19
+ *.njsproj
20
+ *.sln
21
+ *.sw?
22
+
23
+ # Environment
24
+ .env
25
+ .env.local
26
+ .env.*.local
27
+ *.local
28
+
29
+ # Logs
30
+ logs/
31
+ *.log
32
+ npm-debug.log*
33
+ yarn-debug.log*
34
+ yarn-error.log*
35
+ pnpm-debug.log*
36
+ lerna-debug.log*
37
+
38
+ # Python
39
+ __pycache__/
40
+ *.py[cod]
41
+ *$py.class
42
+ *.pyc
43
+ *.pyo
44
+ *.pyd
45
+ .pytest_cache/
46
+ .mypy_cache/
47
+ .ruff_cache/
48
+ .venv/
49
+ venv/
50
+ env/
51
+ ENV/
52
+ .python-version
53
+ *.egg-info/
54
+ dist-python/
55
+ build/
56
+ *.egg
57
+ .uv-cache
58
+
59
+ # Node.js / Frontend
60
+ node_modules/
61
+ dist/
62
+ dist-ssr/
63
+ .vite/
64
+ *.tsbuildinfo
65
+ .eslintcache
66
+ .npm
67
+ .yarn/cache
68
+ .yarn/unplugged
69
+ .yarn/build-state.yml
70
+ .yarn/install-state.gz
71
+ .pnp.*
72
+
73
+ # Archives
74
+ archive/
75
+ legacy/
76
+
77
+ # Local data
78
+ /cli/src/mycode_cli/server/static/
79
+
80
+ # Config with secrets (use config.example.json as template)
81
+ config.json
82
+
83
+ # AI Agents
84
+ CLAUDE.md
85
+ .claude/
86
+ GEMINI.md
87
+ .gemini/
88
+ .pi/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LeGibet
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.
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.4
2
+ Name: mycode-sdk
3
+ Version: 0.4.2
4
+ Summary: Multi-turn tool-calling agent runtime for embedding the mycode agent loop.
5
+ Project-URL: Homepage, https://github.com/legibet/mycode
6
+ Project-URL: Repository, https://github.com/legibet/mycode
7
+ Project-URL: Issues, https://github.com/legibet/mycode/issues
8
+ Author-email: LeGibet <legibetpeng@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agent,anthropic,gemini,llm,openai,sdk
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: anthropic>=0.74.0
22
+ Requires-Dist: google-genai>=1.68.0
23
+ Requires-Dist: openai>=2.11.0
24
+ Description-Content-Type: text/markdown
25
+
26
+ # mycode-sdk
27
+
28
+ Lightweight Python SDK for the mycode multi-turn tool-calling agent. Import name: `mycode`.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ uv add mycode-sdk
34
+ # or
35
+ pip install mycode-sdk
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ `Agent(...)` fills in sensible defaults: provider inferred from the model id, `session_id` generated, session log auto-persisted to `~/.mycode/sessions/<session_id>/`. By default no tools are registered — pick the built-ins you want or register your own via `@tool`.
41
+
42
+ ```python
43
+ import asyncio
44
+
45
+ from mycode import Agent, bash_tool, read_tool
46
+
47
+
48
+ async def main() -> None:
49
+ agent = Agent(
50
+ model="claude-sonnet-4-6",
51
+ api_key="YOUR_API_KEY",
52
+ cwd=".",
53
+ system="You are a concise coding assistant.",
54
+ tools=[read_tool, bash_tool],
55
+ )
56
+
57
+ async for event in agent.achat("Read pyproject.toml and tell me the project name."):
58
+ if event.type == "text":
59
+ print(event.data["delta"], end="")
60
+
61
+
62
+ asyncio.run(main())
63
+ ```
64
+
65
+ To resume a previous conversation, pass the same `session_id` (the agent loads its own history from disk).
66
+
67
+ ## Built-in tools
68
+
69
+ Pick and combine the four bundled coding tools:
70
+
71
+ ```python
72
+ from mycode import read_tool, write_tool, edit_tool, bash_tool
73
+ ```
74
+
75
+ ## Custom Tools
76
+
77
+ `@tool` wraps a plain Python function (sync or async) as a `ToolSpec`. If the first parameter is annotated `ToolContext`, the context is injected; use `ctx.call("read", {...})` to invoke another registered tool.
78
+
79
+ ```python
80
+ from mycode import Agent, ToolContext, read_tool, tool
81
+
82
+
83
+ @tool
84
+ def summarize_file(ctx: ToolContext, path: str) -> str:
85
+ """Return the first line of a text file."""
86
+
87
+ result = ctx.call("read", {"path": path})
88
+ return result.model_text.splitlines()[0] if result.model_text else ""
89
+
90
+
91
+ agent = Agent(
92
+ model="claude-sonnet-4-6",
93
+ api_key="YOUR_API_KEY",
94
+ cwd=".",
95
+ tools=[read_tool, summarize_file],
96
+ )
97
+ ```
98
+
99
+ Type hints drive the JSON schema. Unknown types raise; missing docstrings raise. `async def` tools are run via `asyncio.run` on the executor's worker thread.
100
+
101
+ ## Disabling auto-persistence
102
+
103
+ Point `session_dir` (or the implied `SessionStore` data dir) at a temporary directory if you need an ephemeral session:
104
+
105
+ ```python
106
+ import tempfile
107
+ from pathlib import Path
108
+
109
+ agent = Agent(
110
+ model="claude-sonnet-4-6",
111
+ cwd=".",
112
+ session_dir=Path(tempfile.mkdtemp()) / "scratch",
113
+ )
114
+ ```
@@ -0,0 +1,89 @@
1
+ # mycode-sdk
2
+
3
+ Lightweight Python SDK for the mycode multi-turn tool-calling agent. Import name: `mycode`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ uv add mycode-sdk
9
+ # or
10
+ pip install mycode-sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ `Agent(...)` fills in sensible defaults: provider inferred from the model id, `session_id` generated, session log auto-persisted to `~/.mycode/sessions/<session_id>/`. By default no tools are registered — pick the built-ins you want or register your own via `@tool`.
16
+
17
+ ```python
18
+ import asyncio
19
+
20
+ from mycode import Agent, bash_tool, read_tool
21
+
22
+
23
+ async def main() -> None:
24
+ agent = Agent(
25
+ model="claude-sonnet-4-6",
26
+ api_key="YOUR_API_KEY",
27
+ cwd=".",
28
+ system="You are a concise coding assistant.",
29
+ tools=[read_tool, bash_tool],
30
+ )
31
+
32
+ async for event in agent.achat("Read pyproject.toml and tell me the project name."):
33
+ if event.type == "text":
34
+ print(event.data["delta"], end="")
35
+
36
+
37
+ asyncio.run(main())
38
+ ```
39
+
40
+ To resume a previous conversation, pass the same `session_id` (the agent loads its own history from disk).
41
+
42
+ ## Built-in tools
43
+
44
+ Pick and combine the four bundled coding tools:
45
+
46
+ ```python
47
+ from mycode import read_tool, write_tool, edit_tool, bash_tool
48
+ ```
49
+
50
+ ## Custom Tools
51
+
52
+ `@tool` wraps a plain Python function (sync or async) as a `ToolSpec`. If the first parameter is annotated `ToolContext`, the context is injected; use `ctx.call("read", {...})` to invoke another registered tool.
53
+
54
+ ```python
55
+ from mycode import Agent, ToolContext, read_tool, tool
56
+
57
+
58
+ @tool
59
+ def summarize_file(ctx: ToolContext, path: str) -> str:
60
+ """Return the first line of a text file."""
61
+
62
+ result = ctx.call("read", {"path": path})
63
+ return result.model_text.splitlines()[0] if result.model_text else ""
64
+
65
+
66
+ agent = Agent(
67
+ model="claude-sonnet-4-6",
68
+ api_key="YOUR_API_KEY",
69
+ cwd=".",
70
+ tools=[read_tool, summarize_file],
71
+ )
72
+ ```
73
+
74
+ Type hints drive the JSON schema. Unknown types raise; missing docstrings raise. `async def` tools are run via `asyncio.run` on the executor's worker thread.
75
+
76
+ ## Disabling auto-persistence
77
+
78
+ Point `session_dir` (or the implied `SessionStore` data dir) at a temporary directory if you need an ephemeral session:
79
+
80
+ ```python
81
+ import tempfile
82
+ from pathlib import Path
83
+
84
+ agent = Agent(
85
+ model="claude-sonnet-4-6",
86
+ cwd=".",
87
+ session_dir=Path(tempfile.mkdtemp()) / "scratch",
88
+ )
89
+ ```
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "mycode-sdk"
7
+ version = "0.4.2"
8
+ description = "Multi-turn tool-calling agent runtime for embedding the mycode agent loop."
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "LeGibet", email = "legibetpeng@gmail.com" }]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Operating System :: OS Independent",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: Software Development",
23
+ ]
24
+ keywords = ["agent", "llm", "anthropic", "openai", "gemini", "sdk"]
25
+ dependencies = [
26
+ "anthropic>=0.74.0",
27
+ "google-genai>=1.68.0",
28
+ "openai>=2.11.0",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/legibet/mycode"
33
+ Repository = "https://github.com/legibet/mycode"
34
+ Issues = "https://github.com/legibet/mycode/issues"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["src/mycode"]
38
+ artifacts = ["src/mycode/models_catalog.json"]
39
+
40
+ [tool.hatch.build.targets.sdist]
41
+ include = ["src/mycode", "README.md", "LICENSE", "pyproject.toml"]
42
+ artifacts = ["src/mycode/models_catalog.json"]
@@ -0,0 +1,72 @@
1
+ """mycode — multi-turn tool-calling agent runtime.
2
+
3
+ Public API for embedding the agent loop in other Python applications. The
4
+ runtime ships four built-in coding tools (``read``, ``write``, ``edit``,
5
+ ``bash``) exposed as :data:`read_tool`, :data:`write_tool`, :data:`edit_tool`,
6
+ :data:`bash_tool` — pick the ones you want via ``tools=[...]`` rather than
7
+ silently exposing file system and shell access.
8
+ """
9
+
10
+ from mycode.agent import Agent, Event, PersistCallback
11
+ from mycode.messages import (
12
+ ContentBlock,
13
+ ConversationMessage,
14
+ assistant_message,
15
+ build_message,
16
+ document_block,
17
+ flatten_message_text,
18
+ image_block,
19
+ text_block,
20
+ thinking_block,
21
+ tool_result_block,
22
+ tool_use_block,
23
+ user_text_message,
24
+ )
25
+ from mycode.session import SessionStore
26
+ from mycode.tools import (
27
+ DEFAULT_TOOL_SPECS,
28
+ ToolContext,
29
+ ToolExecutionResult,
30
+ ToolExecutor,
31
+ ToolSpec,
32
+ cancel_all_tools,
33
+ tool,
34
+ )
35
+
36
+ __version__ = "0.4.0"
37
+
38
+ # Built-in tool specs exposed as module-level constants so callers can pick
39
+ # which ones to register (``tools=[read_tool, bash_tool]``) rather than
40
+ # getting all four by default.
41
+ read_tool, write_tool, edit_tool, bash_tool = DEFAULT_TOOL_SPECS
42
+
43
+ __all__ = [
44
+ "Agent",
45
+ "ContentBlock",
46
+ "ConversationMessage",
47
+ "DEFAULT_TOOL_SPECS",
48
+ "Event",
49
+ "PersistCallback",
50
+ "SessionStore",
51
+ "ToolContext",
52
+ "ToolExecutionResult",
53
+ "ToolExecutor",
54
+ "ToolSpec",
55
+ "__version__",
56
+ "assistant_message",
57
+ "bash_tool",
58
+ "build_message",
59
+ "cancel_all_tools",
60
+ "document_block",
61
+ "edit_tool",
62
+ "flatten_message_text",
63
+ "image_block",
64
+ "read_tool",
65
+ "text_block",
66
+ "thinking_block",
67
+ "tool",
68
+ "tool_result_block",
69
+ "tool_use_block",
70
+ "user_text_message",
71
+ "write_tool",
72
+ ]