coder-agent 0.1.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.
- coder_agent-0.1.0.dist-info/METADATA +262 -0
- coder_agent-0.1.0.dist-info/RECORD +163 -0
- coder_agent-0.1.0.dist-info/WHEEL +5 -0
- coder_agent-0.1.0.dist-info/entry_points.txt +2 -0
- coder_agent-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- coder_agent-0.1.0.dist-info/top_level.txt +1 -0
- coderagent/__init__.py +20 -0
- coderagent/compat/__init__.py +27 -0
- coderagent/compat/cache_control.py +69 -0
- coderagent/compat/config_spec.py +60 -0
- coderagent/compat/exceptions.py +20 -0
- coderagent/compat/retry.py +27 -0
- coderagent/compat/serialize.py +31 -0
- coderagent/config/__init__.py +1 -0
- coderagent/config/defaults.yaml +103 -0
- coderagent/config/loader.py +264 -0
- coderagent/config/schema.py +548 -0
- coderagent/config/writer.py +218 -0
- coderagent/core/__init__.py +1 -0
- coderagent/core/budget.py +47 -0
- coderagent/core/capabilities.py +136 -0
- coderagent/core/checkpoint.py +164 -0
- coderagent/core/content.py +156 -0
- coderagent/core/context.py +618 -0
- coderagent/core/events.py +83 -0
- coderagent/core/history.py +56 -0
- coderagent/core/instructions.py +99 -0
- coderagent/core/loop.py +702 -0
- coderagent/core/memory.py +56 -0
- coderagent/core/mentions.py +81 -0
- coderagent/core/os_sandbox.py +191 -0
- coderagent/core/otel.py +214 -0
- coderagent/core/protocols.py +38 -0
- coderagent/core/redact.py +49 -0
- coderagent/core/sandbox.py +82 -0
- coderagent/core/schema.py +107 -0
- coderagent/core/session.py +344 -0
- coderagent/core/shell_env.py +74 -0
- coderagent/core/subagent.py +474 -0
- coderagent/core/summarize.py +312 -0
- coderagent/core/telemetry.py +209 -0
- coderagent/core/tokens.py +132 -0
- coderagent/core/trust.py +301 -0
- coderagent/environments/__init__.py +11 -0
- coderagent/environments/bubblewrap.py +150 -0
- coderagent/environments/contree.py +146 -0
- coderagent/environments/docker.py +160 -0
- coderagent/environments/local.py +110 -0
- coderagent/environments/singularity.py +138 -0
- coderagent/environments/swerex_docker.py +79 -0
- coderagent/environments/swerex_modal.py +123 -0
- coderagent/eval/__init__.py +1 -0
- coderagent/eval/compare.py +190 -0
- coderagent/eval/report.py +141 -0
- coderagent/eval/runner.py +368 -0
- coderagent/eval/task.py +194 -0
- coderagent/extensions/__init__.py +1 -0
- coderagent/extensions/hooks.py +121 -0
- coderagent/extensions/plugins.py +217 -0
- coderagent/extensions/reflect.py +342 -0
- coderagent/models/__init__.py +33 -0
- coderagent/models/backends.py +218 -0
- coderagent/models/call.py +18 -0
- coderagent/models/check.py +139 -0
- coderagent/models/gateway.py +60 -0
- coderagent/models/litellm_config.py +70 -0
- coderagent/models/provider.py +98 -0
- coderagent/models/reasoning.py +28 -0
- coderagent/models/router.py +136 -0
- coderagent/models/settings.py +172 -0
- coderagent/models/streaming.py +122 -0
- coderagent/models/verbosity.py +14 -0
- coderagent/paths.py +31 -0
- coderagent/run.py +454 -0
- coderagent/skills/__init__.py +119 -0
- coderagent/skills/errors.py +11 -0
- coderagent/skills/install.py +340 -0
- coderagent/skills/presets/code-review/SKILL.md +35 -0
- coderagent/skills/presets/codebase-onboarding/SKILL.md +33 -0
- coderagent/skills/presets/data-analysis/SKILL.md +35 -0
- coderagent/skills/presets/deep-research/SKILL.md +38 -0
- coderagent/skills/presets/frontend-dev/SKILL.md +32 -0
- coderagent/skills/presets/long-document/SKILL.md +37 -0
- coderagent/skills/presets/long-document/scripts/pdf_text.py +37 -0
- coderagent/skills/presets/office-docx/SKILL.md +36 -0
- coderagent/skills/presets/office-docx/scripts/docx_text.py +36 -0
- coderagent/skills/presets/office-pptx/SKILL.md +32 -0
- coderagent/skills/presets/office-xlsx/SKILL.md +34 -0
- coderagent/skills/presets/office-xlsx/scripts/xlsx_text.py +72 -0
- coderagent/skills/presets/writing/SKILL.md +31 -0
- coderagent/skills/sandbox.py +269 -0
- coderagent/skills/sites.py +177 -0
- coderagent/skills/source.py +404 -0
- coderagent/testing/__init__.py +5 -0
- coderagent/testing/factory.py +59 -0
- coderagent/testing/scripted_model.py +54 -0
- coderagent/tools/__init__.py +1 -0
- coderagent/tools/base.py +54 -0
- coderagent/tools/bash_policy.py +486 -0
- coderagent/tools/builtin/__init__.py +35 -0
- coderagent/tools/builtin/fs.py +283 -0
- coderagent/tools/builtin/patch.py +279 -0
- coderagent/tools/builtin/search.py +242 -0
- coderagent/tools/builtin/shell.py +336 -0
- coderagent/tools/builtin/skill.py +41 -0
- coderagent/tools/builtin/task.py +53 -0
- coderagent/tools/builtin/todo.py +63 -0
- coderagent/tools/executor.py +243 -0
- coderagent/tools/mcp.py +317 -0
- coderagent/tools/permissions.py +472 -0
- coderagent/tools/registry.py +83 -0
- coderagent/tools/rules.py +138 -0
- coderagent/ui/__init__.py +1 -0
- coderagent/ui/cli.py +498 -0
- coderagent/ui/commands/__init__.py +109 -0
- coderagent/ui/commands/builtin.py +778 -0
- coderagent/ui/commands/compact.py +12 -0
- coderagent/ui/commands/resume.py +26 -0
- coderagent/ui/commands/review.py +73 -0
- coderagent/ui/commands/rewind.py +28 -0
- coderagent/ui/custom_commands.py +179 -0
- coderagent/ui/notify.py +46 -0
- coderagent/ui/open_file.py +48 -0
- coderagent/ui/render.py +62 -0
- coderagent/ui/spinner.py +68 -0
- coderagent/ui/tui.py +610 -0
- coderagent/ui/widgets/__init__.py +29 -0
- coderagent/ui/widgets/approval_prompt.py +129 -0
- coderagent/ui/widgets/diff_view.py +97 -0
- coderagent/ui/widgets/file_tree.py +105 -0
- coderagent/ui/widgets/markdown_message.py +44 -0
- coderagent/ui/widgets/markup.py +10 -0
- coderagent/ui/widgets/message_block.py +61 -0
- coderagent/ui/widgets/path_suggester.py +66 -0
- coderagent/ui/widgets/session_picker.py +49 -0
- coderagent/ui/widgets/status_bar.py +44 -0
- coderagent/ui/widgets/todo_panel.py +40 -0
- coderagent/ui/widgets/tool_card.py +104 -0
- coderagent/ui/widgets/working_dots.py +26 -0
- coderagent/version.py +7 -0
- coderagent/web/__init__.py +5 -0
- coderagent/web/api.py +449 -0
- coderagent/web/app.py +113 -0
- coderagent/web/approver.py +73 -0
- coderagent/web/config_api.py +53 -0
- coderagent/web/events.py +159 -0
- coderagent/web/files.py +115 -0
- coderagent/web/i18n.py +346 -0
- coderagent/web/server.py +100 -0
- coderagent/web/sessions.py +404 -0
- coderagent/web/skills_api.py +376 -0
- coderagent/web/static/app.css +283 -0
- coderagent/web/static/app.js +1466 -0
- coderagent/web/templates/en/base.html +31 -0
- coderagent/web/templates/en/chat.html +60 -0
- coderagent/web/templates/en/macros.html +9 -0
- coderagent/web/templates/en/settings.html +80 -0
- coderagent/web/templates/en/skills.html +64 -0
- coderagent/web/templates/zh/base.html +31 -0
- coderagent/web/templates/zh/chat.html +60 -0
- coderagent/web/templates/zh/macros.html +9 -0
- coderagent/web/templates/zh/settings.html +77 -0
- coderagent/web/templates/zh/skills.html +61 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"""The skills of the web interface: what is installed, and what can be installed.
|
|
2
|
+
|
|
3
|
+
The page asks the server and the server asks the domain layer
|
|
4
|
+
(`coderagent.skills`) to fetch, to check and to install. Every endpoint is a
|
|
5
|
+
plain function: a download blocks, so FastAPI puts these into a thread pool
|
|
6
|
+
instead of holding the event loop.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from fastapi import APIRouter, Depends, HTTPException, Request
|
|
13
|
+
from pydantic import BaseModel
|
|
14
|
+
|
|
15
|
+
from coderagent.paths import config_home
|
|
16
|
+
from coderagent.skills import PRESETS, SKILL_FILE, SKILLS_DIR, load_skills, parse_skill
|
|
17
|
+
from coderagent.skills.errors import SkillError
|
|
18
|
+
from coderagent.skills.install import (
|
|
19
|
+
Staged,
|
|
20
|
+
check_update,
|
|
21
|
+
install,
|
|
22
|
+
read_lock,
|
|
23
|
+
read_stage,
|
|
24
|
+
stage,
|
|
25
|
+
uninstall,
|
|
26
|
+
)
|
|
27
|
+
from coderagent.skills.sandbox import Policy, check_name, entries_of
|
|
28
|
+
from coderagent.skills.sites import ROWS, SITES, Site, SiteSkill, site_of
|
|
29
|
+
from coderagent.skills.sites import list_skills as site_skills
|
|
30
|
+
from coderagent.skills.source import fetch_registry, parse_source
|
|
31
|
+
from coderagent.web.api import require_client
|
|
32
|
+
from coderagent.web.i18n import STRINGS, locale_of
|
|
33
|
+
|
|
34
|
+
router = APIRouter(prefix="/api/skills")
|
|
35
|
+
|
|
36
|
+
REASONS = {
|
|
37
|
+
"there is no source": "没有填来源",
|
|
38
|
+
"there is no site with the name": "没有这个站点:{detail}",
|
|
39
|
+
"is not a source of a skill": "这不是一个技能的来源:{text}",
|
|
40
|
+
"does not point at a skill": "这不是一个技能的来源:{text}",
|
|
41
|
+
"is not a repository": "这不是一个仓库:{text}",
|
|
42
|
+
"is not a skill that can be installed": "这个来源装不了:{message}",
|
|
43
|
+
"may not be fetched": "这个地址不能下载:只允许 https",
|
|
44
|
+
"may not be cloned": "这个地址不能克隆:只允许 https 和 ssh",
|
|
45
|
+
"is inside the network": "这个地址在内网里,不允许",
|
|
46
|
+
"cannot be found": "找不到这个主机",
|
|
47
|
+
"the server said": "下载失败:服务器说 {detail}",
|
|
48
|
+
"the download failed": "下载失败:{detail}",
|
|
49
|
+
"the download is bigger than": "下载太大:超过了 {detail} 的上限",
|
|
50
|
+
"the registry cannot be read": "注册表读不了:{detail}",
|
|
51
|
+
"the registry does not list any skills": "这个注册表里没有技能",
|
|
52
|
+
"git is not installed": "机器上没有 git,用不了 git 地址",
|
|
53
|
+
"the clone failed": "克隆失败:{detail}",
|
|
54
|
+
"the clone took too long": "克隆太久了",
|
|
55
|
+
"there is no SKILL.md in it": "里面没有 SKILL.md",
|
|
56
|
+
"there is no": "这个来源里没有:{detail}",
|
|
57
|
+
"is not a plain file": "这个包里有一个不是普通文件的东西,已拒绝",
|
|
58
|
+
"is not a path inside the skill": "这个包里有一个越界的路径,已拒绝",
|
|
59
|
+
"points outside the skill": "这个包里有一个越界的路径,已拒绝",
|
|
60
|
+
"has a name that": "这个包里有一个不能用的名字,已拒绝",
|
|
61
|
+
"has more than": "这个包里的文件太多了",
|
|
62
|
+
"is deeper than": "这个包里的目录太深了",
|
|
63
|
+
"is bigger than": "这个包太大了",
|
|
64
|
+
"the archive cannot be read": "这个包读不了:{detail}",
|
|
65
|
+
"is not a name a skill can have": "{name} 不是技能能有的名字",
|
|
66
|
+
"the preview is gone": "预览已经过期,请重新下载",
|
|
67
|
+
"is installed already": "{name} 已经装过了",
|
|
68
|
+
"it is yours": "{name} 不是这里装的,是你自己的",
|
|
69
|
+
"cannot be read": "锁文件读不了:{detail}",
|
|
70
|
+
"the skills are turned off in the configuration": "配置里把技能关掉了",
|
|
71
|
+
}
|
|
72
|
+
"""Why it did not work, in Chinese. The domain layer speaks English."""
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class PreviewBody(BaseModel):
|
|
76
|
+
source: str = ""
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class InstallBody(BaseModel):
|
|
80
|
+
stage_id: str = ""
|
|
81
|
+
force: bool = False
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class NameBody(BaseModel):
|
|
85
|
+
name: str = ""
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class RegistryBody(BaseModel):
|
|
89
|
+
url: str = ""
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _settings(request: Request):
|
|
93
|
+
"""The skills section of the configuration."""
|
|
94
|
+
return request.app.state.config_of().skills
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _guard(request: Request):
|
|
98
|
+
"""The settings of the skills, when they are turned on."""
|
|
99
|
+
settings = _settings(request)
|
|
100
|
+
if not settings.enabled:
|
|
101
|
+
raise HTTPException(status_code=403, detail=_reason(request, "the skills are turned off in the configuration"))
|
|
102
|
+
return settings
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _policy(request: Request) -> Policy:
|
|
106
|
+
"""The limits of a download, as the configuration says them."""
|
|
107
|
+
return Policy.from_config(_settings(request))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _language(request: Request) -> str:
|
|
111
|
+
"""The language of the visitor."""
|
|
112
|
+
return locale_of(request, tuple(STRINGS))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _reason(request: Request, message: str, text: str = "") -> str:
|
|
116
|
+
"""The reason of a failure, in the language of the visitor."""
|
|
117
|
+
if _language(request) != "zh":
|
|
118
|
+
return message
|
|
119
|
+
name = message[1 : message.index("'", 1)] if message.startswith("'") and "'" in message[1:] else text
|
|
120
|
+
for key, template in REASONS.items():
|
|
121
|
+
index = message.find(key)
|
|
122
|
+
if index < 0:
|
|
123
|
+
continue
|
|
124
|
+
detail = message[index + len(key) :].strip(" :")
|
|
125
|
+
return template.format(detail=detail, text=text or detail, message=message, name=name)
|
|
126
|
+
return f"操作失败:{message}"
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _bad_request(request: Request, error: SkillError, text: str = "") -> HTTPException:
|
|
130
|
+
"""A failure that is the fault of what the user wrote."""
|
|
131
|
+
return HTTPException(status_code=400, detail=_reason(request, str(error), text))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _preview_view(staged: Staged) -> dict[str, Any]:
|
|
135
|
+
"""What the page shows before the skill is installed."""
|
|
136
|
+
return {
|
|
137
|
+
"stage_id": staged.stage_id,
|
|
138
|
+
"name": staged.name,
|
|
139
|
+
"description": staged.description,
|
|
140
|
+
"body": staged.body,
|
|
141
|
+
"files": [{"path": entry.path, "size": entry.size, "sha256": entry.sha256} for entry in staged.files],
|
|
142
|
+
"sha256": staged.sha256,
|
|
143
|
+
"warnings": staged.warnings,
|
|
144
|
+
"source": staged.source.as_dict(),
|
|
145
|
+
"source_text": staged.source.describe(),
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@router.get("")
|
|
150
|
+
def list_skills(request: Request) -> dict[str, Any]:
|
|
151
|
+
"""The skills of the user, the ones that come with the agent, and where they came from."""
|
|
152
|
+
lock = read_lock()
|
|
153
|
+
directory = config_home() / SKILLS_DIR
|
|
154
|
+
skills = []
|
|
155
|
+
for path in sorted(directory.glob(f"*/{SKILL_FILE}")) if directory.is_dir() else []:
|
|
156
|
+
skill = _parse(path)
|
|
157
|
+
if skill is None:
|
|
158
|
+
continue
|
|
159
|
+
installed = lock.get(path.parent.name)
|
|
160
|
+
skills.append(
|
|
161
|
+
{
|
|
162
|
+
"name": path.parent.name,
|
|
163
|
+
"description": skill.description,
|
|
164
|
+
"directory": str(path.parent),
|
|
165
|
+
"managed": installed is not None,
|
|
166
|
+
"source": installed.source.as_dict() if installed else {},
|
|
167
|
+
"source_text": installed.source.describe() if installed else "",
|
|
168
|
+
"sha256": installed.sha256 if installed else "",
|
|
169
|
+
"installed_at": installed.installed_at if installed else "",
|
|
170
|
+
"files": len(installed.files) if installed else _count_files(path.parent),
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
return {"skills": skills, "builtin": _builtin_skills(request), "registries": _settings(request).registries}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _builtin_skills(request: Request) -> list[dict[str, Any]]:
|
|
177
|
+
"""The skills that come with the agent.
|
|
178
|
+
|
|
179
|
+
A skill of the user or of the project with the same name replaces one of
|
|
180
|
+
them, and then it is not one of them any more.
|
|
181
|
+
"""
|
|
182
|
+
cwd = Path(request.app.state.cwd)
|
|
183
|
+
return [
|
|
184
|
+
{
|
|
185
|
+
"name": skill.name,
|
|
186
|
+
"description": skill.description,
|
|
187
|
+
"directory": str(skill.directory),
|
|
188
|
+
"files": _count_files(skill.directory),
|
|
189
|
+
}
|
|
190
|
+
for skill in load_skills(cwd, config_home()).values()
|
|
191
|
+
if skill.directory is not None and skill.directory.is_relative_to(PRESETS)
|
|
192
|
+
]
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
@router.get("/sites")
|
|
196
|
+
def list_sites(request: Request) -> dict[str, Any]:
|
|
197
|
+
"""The sites of skills: one tab for each of them."""
|
|
198
|
+
_guard(request)
|
|
199
|
+
return {"sites": [_site_view(site) for site in SITES]}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
@router.get("/sites/{site_id}")
|
|
203
|
+
def list_site_skills(site_id: str, request: Request, refresh: bool = False) -> dict[str, Any]:
|
|
204
|
+
"""Every skill of one site, with the size of a page.
|
|
205
|
+
|
|
206
|
+
With `refresh` the clone of the site is thrown away and fetched again: the
|
|
207
|
+
page asks for that when the user wants to see what the site looks like now.
|
|
208
|
+
"""
|
|
209
|
+
_guard(request)
|
|
210
|
+
try:
|
|
211
|
+
site = site_of(site_id)
|
|
212
|
+
skills = site_skills(site, _policy(request), refresh)
|
|
213
|
+
except SkillError as error:
|
|
214
|
+
raise _bad_request(request, error, site_id) from None
|
|
215
|
+
return {
|
|
216
|
+
"site": _site_view(site),
|
|
217
|
+
"total": len(skills),
|
|
218
|
+
"page_size": ROWS,
|
|
219
|
+
"skills": [_skill_view(site, skill) for skill in skills],
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
@router.get("/{name}")
|
|
224
|
+
def get_skill(name: str, request: Request) -> dict[str, Any]:
|
|
225
|
+
"""One skill, with the text the model would read."""
|
|
226
|
+
try:
|
|
227
|
+
check_name(name)
|
|
228
|
+
except SkillError as error:
|
|
229
|
+
raise _bad_request(request, error) from None
|
|
230
|
+
directory = config_home() / SKILLS_DIR / name
|
|
231
|
+
path = directory / SKILL_FILE
|
|
232
|
+
if not path.exists():
|
|
233
|
+
"""A skill that comes with the agent is in the package, not in the home."""
|
|
234
|
+
directory = PRESETS / name
|
|
235
|
+
path = directory / SKILL_FILE
|
|
236
|
+
if not path.exists():
|
|
237
|
+
raise HTTPException(status_code=404, detail=f"there is no skill with the name {name}")
|
|
238
|
+
skill = _parse(path)
|
|
239
|
+
installed = read_lock().get(name)
|
|
240
|
+
return {
|
|
241
|
+
"name": name,
|
|
242
|
+
"description": skill.description if skill else "",
|
|
243
|
+
"body": skill.body if skill else "",
|
|
244
|
+
"directory": str(directory),
|
|
245
|
+
"managed": installed is not None,
|
|
246
|
+
"source": installed.source.as_dict() if installed else {},
|
|
247
|
+
"source_text": installed.source.describe() if installed else "",
|
|
248
|
+
"sha256": installed.sha256 if installed else "",
|
|
249
|
+
"installed_at": installed.installed_at if installed else "",
|
|
250
|
+
"files": [{"path": entry.path, "size": entry.size, "sha256": entry.sha256} for entry in entries_of(directory)],
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@router.post("/preview")
|
|
255
|
+
def preview(body: PreviewBody, request: Request, _: None = Depends(require_client)) -> dict[str, Any]:
|
|
256
|
+
"""Download a skill and show what it is, without installing it."""
|
|
257
|
+
settings = _guard(request)
|
|
258
|
+
try:
|
|
259
|
+
source = parse_source(body.source)
|
|
260
|
+
except SkillError as error:
|
|
261
|
+
raise _bad_request(request, error, body.source) from None
|
|
262
|
+
try:
|
|
263
|
+
staged = stage(source, _policy(request), token=settings.github_token)
|
|
264
|
+
except SkillError as error:
|
|
265
|
+
raise _bad_request(request, error, body.source) from None
|
|
266
|
+
return _preview_view(staged)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@router.post("/install")
|
|
270
|
+
def install_skill(body: InstallBody, request: Request, _: None = Depends(require_client)) -> dict[str, Any]:
|
|
271
|
+
"""Put a previewed skill where the agent finds it."""
|
|
272
|
+
_guard(request)
|
|
273
|
+
try:
|
|
274
|
+
staged = read_stage(body.stage_id)
|
|
275
|
+
except SkillError as error:
|
|
276
|
+
raise _bad_request(request, error) from None
|
|
277
|
+
try:
|
|
278
|
+
installed = install(staged, force=body.force)
|
|
279
|
+
except SkillError as error:
|
|
280
|
+
if "is installed already" in str(error):
|
|
281
|
+
reason = _reason(request, f"'{staged.name}' is installed already")
|
|
282
|
+
hint = ";force=true 才能覆盖" if _language(request) == "zh" else "; force=true replaces it"
|
|
283
|
+
raise HTTPException(status_code=409, detail=reason + hint) from None
|
|
284
|
+
raise _bad_request(request, error) from None
|
|
285
|
+
return {"ok": True, "name": installed.name, "sha256": installed.sha256}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
@router.delete("/{name}")
|
|
289
|
+
def uninstall_skill(name: str, request: Request, _: None = Depends(require_client)) -> dict[str, Any]:
|
|
290
|
+
"""Remove a skill that was installed here."""
|
|
291
|
+
_guard(request)
|
|
292
|
+
try:
|
|
293
|
+
check_name(name)
|
|
294
|
+
uninstall(name)
|
|
295
|
+
except SkillError as error:
|
|
296
|
+
if "it is yours" in str(error):
|
|
297
|
+
raise HTTPException(status_code=403, detail=_reason(request, str(error))) from None
|
|
298
|
+
raise _bad_request(request, error) from None
|
|
299
|
+
return {"ok": True, "name": name}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
@router.post("/update")
|
|
303
|
+
def update_skill(body: NameBody, request: Request, _: None = Depends(require_client)) -> dict[str, Any]:
|
|
304
|
+
"""Fetch the source of a skill again and see whether it changed."""
|
|
305
|
+
settings = _guard(request)
|
|
306
|
+
installed = read_lock().get(body.name)
|
|
307
|
+
if installed is None:
|
|
308
|
+
raise HTTPException(
|
|
309
|
+
status_code=400, detail=_reason(request, f"'{body.name}' was not installed here, it is yours")
|
|
310
|
+
)
|
|
311
|
+
try:
|
|
312
|
+
staged = check_update(installed, _policy(request), token=settings.github_token)
|
|
313
|
+
except SkillError as error:
|
|
314
|
+
raise _bad_request(request, error) from None
|
|
315
|
+
if staged is None:
|
|
316
|
+
return {"ok": True, "up_to_date": True, "name": body.name}
|
|
317
|
+
return {"ok": True, "up_to_date": False, "preview": _preview_view(staged)}
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
@router.post("/registry")
|
|
321
|
+
def registry(body: RegistryBody, request: Request, _: None = Depends(require_client)) -> dict[str, Any]:
|
|
322
|
+
"""The skills a registry lists."""
|
|
323
|
+
_guard(request)
|
|
324
|
+
try:
|
|
325
|
+
entries = fetch_registry(body.url, _policy(request))
|
|
326
|
+
except SkillError as error:
|
|
327
|
+
raise _bad_request(request, error, body.url) from None
|
|
328
|
+
return {
|
|
329
|
+
"skills": [
|
|
330
|
+
{
|
|
331
|
+
"name": entry.name,
|
|
332
|
+
"description": entry.description,
|
|
333
|
+
"source": entry.source.as_dict(),
|
|
334
|
+
"source_text": entry.source.describe(),
|
|
335
|
+
}
|
|
336
|
+
for entry in entries
|
|
337
|
+
]
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def _site_view(site: Site) -> dict[str, Any]:
|
|
342
|
+
"""What the tab of a site says."""
|
|
343
|
+
return {
|
|
344
|
+
"id": site.id,
|
|
345
|
+
"repo": site.repo,
|
|
346
|
+
"url": site.url,
|
|
347
|
+
"path": site.path,
|
|
348
|
+
"accent": site.accent,
|
|
349
|
+
"page_size": ROWS,
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def _skill_view(site: Site, skill: SiteSkill) -> dict[str, Any]:
|
|
354
|
+
"""One skill of a site, with the source that downloads it."""
|
|
355
|
+
return {
|
|
356
|
+
"name": skill.name,
|
|
357
|
+
"description": skill.description,
|
|
358
|
+
"path": skill.path,
|
|
359
|
+
"source_text": f"{site.kind}:{site.repo}/{skill.path}",
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def _count_files(directory: Path) -> int:
|
|
364
|
+
"""How many files a skill of the user has."""
|
|
365
|
+
return sum(1 for path in directory.rglob("*") if path.is_file() and not path.is_symlink())
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def _parse(path: Path):
|
|
369
|
+
"""The skill of a file, when the file is one."""
|
|
370
|
+
try:
|
|
371
|
+
return parse_skill(path)
|
|
372
|
+
except (OSError, UnicodeDecodeError):
|
|
373
|
+
return None
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
__all__ = ["router"]
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--bg: #12141a;
|
|
3
|
+
--panel: #191c24;
|
|
4
|
+
--border: #2a2f3a;
|
|
5
|
+
--text: #e6e8ee;
|
|
6
|
+
--muted: #949cad;
|
|
7
|
+
--accent: #6aa9ff;
|
|
8
|
+
--ok: #58c98a;
|
|
9
|
+
--warn: #e0b64c;
|
|
10
|
+
--err: #e56a6a;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
* { box-sizing: border-box; }
|
|
14
|
+
|
|
15
|
+
body {
|
|
16
|
+
margin: 0;
|
|
17
|
+
height: 100vh;
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
background: var(--bg);
|
|
22
|
+
color: var(--text);
|
|
23
|
+
font: 14px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
a { color: var(--accent); text-decoration: none; }
|
|
27
|
+
|
|
28
|
+
.topbar {
|
|
29
|
+
flex: none;
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
gap: 16px;
|
|
33
|
+
padding: 8px 16px;
|
|
34
|
+
border-bottom: 1px solid var(--border);
|
|
35
|
+
background: var(--panel);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.brand { font-weight: 700; letter-spacing: 0.04em; }
|
|
39
|
+
.spacer { flex: 1; }
|
|
40
|
+
.language { font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 2px 4px; }
|
|
41
|
+
.status { color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
|
|
42
|
+
|
|
43
|
+
.layout {
|
|
44
|
+
flex: 1;
|
|
45
|
+
min-height: 0;
|
|
46
|
+
display: grid;
|
|
47
|
+
grid-template-columns: 260px minmax(0, 1fr) 300px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.sidebar, .inspector {
|
|
51
|
+
border-right: 1px solid var(--border);
|
|
52
|
+
padding: 12px;
|
|
53
|
+
overflow: auto;
|
|
54
|
+
min-height: 0;
|
|
55
|
+
background: var(--panel);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.inspector { border-right: none; border-left: 1px solid var(--border); }
|
|
59
|
+
|
|
60
|
+
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
|
|
61
|
+
h1 { font-size: 20px; }
|
|
62
|
+
|
|
63
|
+
.list { list-style: none; margin: 8px 0; padding: 0; }
|
|
64
|
+
.list li {
|
|
65
|
+
padding: 4px 6px;
|
|
66
|
+
border-radius: 4px;
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
font-family: ui-monospace, Menlo, monospace;
|
|
69
|
+
font-size: 12px;
|
|
70
|
+
white-space: nowrap;
|
|
71
|
+
overflow: hidden;
|
|
72
|
+
text-overflow: ellipsis;
|
|
73
|
+
}
|
|
74
|
+
.list li:hover { background: #232733; }
|
|
75
|
+
.list li.active { background: #2b3348; }
|
|
76
|
+
.list li.dir { color: var(--accent); }
|
|
77
|
+
|
|
78
|
+
.conversation { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; position: relative; }
|
|
79
|
+
.messages { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
|
|
80
|
+
|
|
81
|
+
/* The button that brings the newest content back into view. */
|
|
82
|
+
.to-latest {
|
|
83
|
+
position: absolute;
|
|
84
|
+
bottom: 16px;
|
|
85
|
+
left: 50%;
|
|
86
|
+
transform: translateX(-50%);
|
|
87
|
+
z-index: 5;
|
|
88
|
+
font-size: 12px;
|
|
89
|
+
padding: 4px 12px;
|
|
90
|
+
border-radius: 999px;
|
|
91
|
+
background: #23334d;
|
|
92
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
|
|
93
|
+
}
|
|
94
|
+
.to-latest[hidden] { display: none; }
|
|
95
|
+
|
|
96
|
+
.history {
|
|
97
|
+
margin: 0 0 12px;
|
|
98
|
+
border: 1px solid var(--border);
|
|
99
|
+
border-radius: 8px;
|
|
100
|
+
background: #171a22;
|
|
101
|
+
}
|
|
102
|
+
.history > summary {
|
|
103
|
+
cursor: pointer;
|
|
104
|
+
padding: 6px 10px;
|
|
105
|
+
color: var(--muted);
|
|
106
|
+
font-size: 12px;
|
|
107
|
+
user-select: none;
|
|
108
|
+
}
|
|
109
|
+
.history > summary:hover { color: var(--text); }
|
|
110
|
+
.history-body { padding: 0 10px 10px; border-top: 1px solid var(--border); }
|
|
111
|
+
/* A folded history takes no room: the browser keeps the space of the closed
|
|
112
|
+
details, and the conversation would not get any shorter. */
|
|
113
|
+
.history:not([open]) > .history-body { display: none; }
|
|
114
|
+
|
|
115
|
+
.bubble {
|
|
116
|
+
margin: 8px 0;
|
|
117
|
+
padding: 8px 12px;
|
|
118
|
+
border-radius: 8px;
|
|
119
|
+
background: #1e222c;
|
|
120
|
+
white-space: pre-wrap;
|
|
121
|
+
word-break: break-word;
|
|
122
|
+
}
|
|
123
|
+
.bubble.user { background: #23334d; }
|
|
124
|
+
.bubble.assistant { background: #1e222c; }
|
|
125
|
+
.bubble.error { background: #3a2020; color: #ffd7d7; }
|
|
126
|
+
.bubble.command { background: #1d2b26; color: #b6e3c8; }
|
|
127
|
+
.bubble.separator { background: none; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); border-radius: 0; }
|
|
128
|
+
/* The dots that say the agent is still working. */
|
|
129
|
+
.bubble.working { color: var(--muted); min-width: 48px; }
|
|
130
|
+
|
|
131
|
+
.rewritten {
|
|
132
|
+
margin: -4px 0 8px;
|
|
133
|
+
padding: 4px 12px;
|
|
134
|
+
color: var(--muted);
|
|
135
|
+
font-size: 12px;
|
|
136
|
+
white-space: pre-wrap;
|
|
137
|
+
word-break: break-word;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.tool {
|
|
141
|
+
margin: 8px 0;
|
|
142
|
+
border: 1px solid var(--border);
|
|
143
|
+
border-radius: 8px;
|
|
144
|
+
overflow: hidden;
|
|
145
|
+
}
|
|
146
|
+
.tool header {
|
|
147
|
+
padding: 6px 10px;
|
|
148
|
+
background: #212632;
|
|
149
|
+
font-family: ui-monospace, Menlo, monospace;
|
|
150
|
+
font-size: 12px;
|
|
151
|
+
display: flex;
|
|
152
|
+
gap: 8px;
|
|
153
|
+
align-items: center;
|
|
154
|
+
}
|
|
155
|
+
.tool .body { padding: 8px 10px; white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; font-size: 12px; max-height: 320px; overflow: auto; }
|
|
156
|
+
.tool .body.ok { color: var(--ok); }
|
|
157
|
+
.tool .body.bad { color: var(--err); }
|
|
158
|
+
.tool pre { margin: 0; }
|
|
159
|
+
|
|
160
|
+
.approval { border-color: var(--warn); }
|
|
161
|
+
.approval .buttons { padding: 8px 10px; display: flex; gap: 8px; }
|
|
162
|
+
|
|
163
|
+
/* The card that waits for an answer: it says so without being read. */
|
|
164
|
+
.approval.attention { animation: attention 1.8s ease-in-out infinite; }
|
|
165
|
+
@keyframes attention {
|
|
166
|
+
0%, 100% { box-shadow: 0 0 0 0 rgba(224, 182, 76, 0); }
|
|
167
|
+
50% { box-shadow: 0 0 0 4px rgba(224, 182, 76, 0.35); }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.todos { margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: #1b2130; }
|
|
171
|
+
.todos div.done { color: var(--muted); text-decoration: line-through; }
|
|
172
|
+
|
|
173
|
+
.composer { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
|
|
174
|
+
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
|
|
175
|
+
.composer textarea { flex: 1; resize: vertical; }
|
|
176
|
+
.attach { flex: none; width: 26px; height: 26px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; color: var(--muted); }
|
|
177
|
+
.attach svg { width: 13px; height: 13px; }
|
|
178
|
+
.attach:hover { color: var(--accent); border-color: var(--accent); }
|
|
179
|
+
.attachments { display: flex; gap: 8px; flex-wrap: wrap; }
|
|
180
|
+
.attachments:empty { display: none; }
|
|
181
|
+
.attachment { position: relative; }
|
|
182
|
+
.attachment img { max-height: 72px; border-radius: 6px; }
|
|
183
|
+
.attachment .remove { position: absolute; top: -8px; right: -8px; padding: 0 6px; font-size: 11px; line-height: 1.5; }
|
|
184
|
+
.bubble img.attached { display: block; max-width: 100%; max-height: 320px; margin-top: 8px; border-radius: 6px; }
|
|
185
|
+
.row { display: flex; gap: 8px; align-items: center; }
|
|
186
|
+
.commands { display: none; }
|
|
187
|
+
/* The row of the commands is hidden for now: the dropdown and the three
|
|
188
|
+
buttons under the box are a lot of noise, and the commands are typed in the
|
|
189
|
+
box anyway. Take the `display` away and they are back. */
|
|
190
|
+
|
|
191
|
+
input, textarea, select, button {
|
|
192
|
+
font: inherit;
|
|
193
|
+
color: var(--text);
|
|
194
|
+
background: #151821;
|
|
195
|
+
border: 1px solid var(--border);
|
|
196
|
+
border-radius: 6px;
|
|
197
|
+
padding: 6px 8px;
|
|
198
|
+
}
|
|
199
|
+
button { cursor: pointer; }
|
|
200
|
+
button:hover { border-color: var(--accent); }
|
|
201
|
+
button.primary { background: #24406e; border-color: #35578f; }
|
|
202
|
+
|
|
203
|
+
.page { flex: 1; min-height: 0; overflow: auto; max-width: 780px; margin: 0 auto; padding: 24px; }
|
|
204
|
+
.page label { display: block; margin: 12px 0; }
|
|
205
|
+
.page label input, .page label textarea, .page label select { display: block; width: 100%; margin-top: 4px; }
|
|
206
|
+
.source { color: var(--muted); font-size: 12px; }
|
|
207
|
+
.note { color: var(--muted); }
|
|
208
|
+
|
|
209
|
+
table { width: 100%; border-collapse: collapse; font-size: 12px; }
|
|
210
|
+
th, td { border: 1px solid var(--border); padding: 6px; text-align: left; vertical-align: top; }
|
|
211
|
+
td pre { margin: 0; white-space: pre-wrap; }
|
|
212
|
+
|
|
213
|
+
dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12px; }
|
|
214
|
+
dt { color: var(--muted); }
|
|
215
|
+
dd { margin: 0; font-family: ui-monospace, Menlo, monospace; word-break: break-all; }
|
|
216
|
+
|
|
217
|
+
.agent { border-bottom: 1px solid var(--border); padding: 6px 0; font-size: 12px; }
|
|
218
|
+
.agent:last-child { border-bottom: none; }
|
|
219
|
+
.agent-head { display: flex; gap: 8px; align-items: baseline; }
|
|
220
|
+
.agent-head span { color: var(--muted); }
|
|
221
|
+
.agent-turns { color: var(--accent); }
|
|
222
|
+
.agent-tools { color: var(--muted); font-family: ui-monospace, Menlo, monospace; word-break: break-all; }
|
|
223
|
+
.agent-description { margin-top: 2px; }
|
|
224
|
+
|
|
225
|
+
.skill { border-bottom: 1px solid var(--border); padding: 8px 0; }
|
|
226
|
+
.skill:last-child { border-bottom: none; }
|
|
227
|
+
.skill-head { display: flex; gap: 8px; align-items: baseline; }
|
|
228
|
+
.skill-head span { color: var(--muted); }
|
|
229
|
+
.skill-meta { color: var(--muted); font-size: 12px; font-family: ui-monospace, Menlo, monospace; margin: 2px 0 6px; word-break: break-all; }
|
|
230
|
+
|
|
231
|
+
/* The skills of a list stand in five columns: ten of them on a page. */
|
|
232
|
+
.skill-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
|
|
233
|
+
.skill-grid .skill { border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #171a22; }
|
|
234
|
+
.skill-grid .skill-head { flex-direction: column; align-items: flex-start; gap: 2px; }
|
|
235
|
+
.skill-grid .skill-head span { word-break: break-word; }
|
|
236
|
+
.skill-grid .row { flex-wrap: wrap; }
|
|
237
|
+
|
|
238
|
+
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
|
|
239
|
+
.tabs .tab { font-size: 12px; padding: 4px 8px; }
|
|
240
|
+
.tabs .tab.active { background: #1d2432; border-color: var(--site-accent, var(--accent)); color: #fff; }
|
|
241
|
+
.tabs .tab::before { content: "●"; color: var(--site-accent, var(--accent)); margin-right: 5px; font-size: 9px; vertical-align: middle; }
|
|
242
|
+
|
|
243
|
+
#skills-page { max-width: 1280px; }
|
|
244
|
+
|
|
245
|
+
.site-panel { --site-accent: var(--accent); margin-top: 4px; }
|
|
246
|
+
.site-head { display: flex; align-items: center; gap: 10px; margin: 14px 0 2px; }
|
|
247
|
+
.site-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
|
|
248
|
+
.site-name { color: var(--text); }
|
|
249
|
+
.site-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--site-accent); box-shadow: 0 0 10px var(--site-accent); }
|
|
250
|
+
.site-repo { color: var(--text); font-family: ui-monospace, Menlo, monospace; }
|
|
251
|
+
.site-repo:hover { color: var(--site-accent); }
|
|
252
|
+
.site-head .badge { margin-left: auto; }
|
|
253
|
+
button.ghost { background: transparent; }
|
|
254
|
+
|
|
255
|
+
.badge { font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: #151821; white-space: nowrap; }
|
|
256
|
+
.badge.ok { color: var(--ok); border-color: #2f6b4a; }
|
|
257
|
+
|
|
258
|
+
.site-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; margin: 12px 0; }
|
|
259
|
+
.site-card { display: flex; gap: 10px; align-items: flex-start; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
|
|
260
|
+
.site-card:hover { border-color: var(--site-accent); }
|
|
261
|
+
.site-avatar { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; color: #10131a; background: var(--site-accent); }
|
|
262
|
+
.site-card-body { flex: 1; min-width: 0; }
|
|
263
|
+
.site-card-title { display: flex; align-items: center; gap: 6px; }
|
|
264
|
+
.site-card-desc { color: var(--muted); font-size: 12px; margin: 2px 0 4px; cursor: help; }
|
|
265
|
+
.site-card-path { font-size: 11px; color: var(--muted); word-break: break-all; }
|
|
266
|
+
.site-card-actions { flex: none; }
|
|
267
|
+
.site-card-actions button { font-size: 12px; padding: 4px 8px; }
|
|
268
|
+
|
|
269
|
+
.pager { display: flex; align-items: center; gap: 6px; margin: 10px 0 4px; }
|
|
270
|
+
.pager button { font-size: 12px; padding: 3px 9px; }
|
|
271
|
+
.pager button.active { background: var(--site-accent); border-color: var(--site-accent); color: #10131a; }
|
|
272
|
+
.pager button:disabled { opacity: 0.4; cursor: default; }
|
|
273
|
+
|
|
274
|
+
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; width: 90%; max-width: 720px; padding: 16px; }
|
|
275
|
+
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
|
|
276
|
+
.preview-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
|
|
277
|
+
.warning { color: var(--warn); margin: 4px 0; }
|
|
278
|
+
button.close { background: none; border: none; font-size: 18px; line-height: 1; padding: 0 4px; }
|
|
279
|
+
|
|
280
|
+
pre { background: #151821; border: 1px solid var(--border); border-radius: 6px; padding: 8px; overflow: auto; max-height: 320px; }
|
|
281
|
+
.diff .add { color: var(--ok); }
|
|
282
|
+
.diff .del { color: var(--err); }
|
|
283
|
+
.diff .meta { color: var(--muted); }
|