Metadata-Version: 2.5
Name: pyxis-harness-market
Version: 0.1.1.dev10
Summary: PyxisHarness plugin: plugin markets — package indexes listed, searched and installed from
Project-URL: Homepage, https://github.com/Onenightcarnival/pyharness
Project-URL: Repository, https://github.com/Onenightcarnival/pyharness
Project-URL: Issues, https://github.com/Onenightcarnival/pyharness/issues
Project-URL: Documentation, https://github.com/Onenightcarnival/pyharness/tree/main/packages/market
Author: Onenightcarnival
License-Expression: MIT
Keywords: agent,deepagents,harness,langgraph,llm,plugin
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Requires-Python: >=3.12
Requires-Dist: fastapi==0.162.0
Requires-Dist: httpx==0.28.1
Requires-Dist: packaging==26.3
Requires-Dist: pydantic==2.14.1
Requires-Dist: pyxis-harness-core==0.1.1.dev10
Requires-Dist: pyxis-harness-launcher==0.1.1.dev10
Description-Content-Type: text/markdown

# pyxis-harness-market

插件市场：把包索引当作市场源，列出其中的插件，与 profile 比较，从它安装与更新。

| 项 | 值 |
|---|---|
| 条目 | `market`（`base` bundle） |
| 服务 | `MarketService`，`ctx.market` |
| 注入 | 无 |
| 可选 | `http`：路由，前缀 `/api/market`；`webui`：「插件市场」页 |

## 文件

| 文件 | 内容 |
|---|---|
| `__init__.py` | 导出 |
| `config.py` | 插件配置：市场源 |
| `index.py` | 简单索引（PEP 503）的读取：项目、文件、wheel 的自述 |
| `cache.py` | wheel 自述的缓存：按 SHA-256，存在 profile 的数据目录 |
| `service.py` | `MarketService`：目录、与 profile 的比较、安装 |
| `routes.py` | HTTP 路由 |
| `client.js` | 浏览器模块：左侧栏「插件市场」 |
| `config.toml` | 上限：超时、项目数、wheel 大小、并发、列表保留时间 |

## 与「插件」页的分工

| | 「插件」页（`pyxis-harness-web-ui`） | 「插件市场」页（本插件） |
|---|---|---|
| 回答 | profile 现在由什么组成、运行得怎么样 | 还能获得什么、有什么新版本 |
| 对象 | 已装的 bundle 与条目，含内置的 | 市场源里可获得的插件 |
| 动作 | 启用、停用、卸载、重启 | 安装、更新、装指定版本、管理市场源、其他安装方式 |
| 指路 | 用户 bundle 的来源；「可更新到 x」跳到市场页 | 已安装的插件：去「插件」页管理 |

## 市场的两层

| 层 | 内容 | 实现 |
|---|---|---|
| 包源 | wheel：一个简单索引（PEP 503），如 pypiserver | uv：解析、哈希、锁定、构建环境 |
| 目录 | 有哪些插件、版本、简介 | 本插件：读索引页与 wheel；没有独立的目录服务 |

## 市场源

`sources`：`{name, url}` 的列表，保存在 profile patch 的 `market` 条目；页面与 `PUT /api/market/sources` 修改，即时生效。

| 字段 | 契约 |
|---|---|
| `name` | 字母、数字、`_`、`-`；也是 profile 项目里该索引的名称 |
| `url` | `http://` 或 `https://` 的简单索引地址；末尾补 `/` |

凭据：与 uv 读同一处，环境变量 `UV_INDEX_<NAME>_USERNAME`、`UV_INDEX_<NAME>_PASSWORD`（`<NAME>`：大写，其余字符换成 `_`）。本插件不保存凭据。

## 读索引（`index.py`）

| 请求 | 读作 |
|---|---|
| `<url>/` | 该索引托管的项目 |
| `<url>/<项目>/` | 200：项目的文件；重定向或 404：该索引不托管它 |
| wheel | 字节；与链接里的 SHA-256 比对 |

不跟随重定向：把未知项目转给 PyPI 的索引（pypiserver 的默认行为），只托管它自己列出的项目。

| 上限（`config.toml`） | 值 |
|---|---|
| 索引列出的项目数 | 500：市场源是插件的索引，不是公有源的镜像 |
| 读取的 wheel | 50 MB |
| 列表保留 | 300 秒；`refresh` 重读 |

wheel 的自述（`cache.py`）：

| 项 | 契约 |
|---|---|
| 文件 | `<profile 数据目录>/market/wheels.json` |
| 内容 | 每个 wheel 的自述（几个字段与 readme）；不含 wheel 的字节 |
| 键 | 索引链接里的 SHA-256；链接不带哈希的 wheel 只在本进程内记住 |
| 有效期 | 永久：一个 SHA-256 只对应一份内容 |
| 条数 | 最近用到的 2000 条 |
| 效果 | 重启后索引页重读，wheel 不重新下载；只有新发布的文件才读取 |

## 目录

| 索引中的项目 | 列出 |
|---|---|
| harness 自身的分发包 | 否 |
| 没有 wheel | 否 |
| 最新版本的 wheel 没有 `pyxis_harness.bundles` 入口点 | 否 |
| 有 | 是 |

每个插件：`name`、`version`（最新）、`versions`、`summary`、`description`（wheel 里的 readme，至多 20000 字符）、`homepage`、`author`、`license`、`keywords`、`requires_python`、`bundles`、`requires`、`source`，以及与 profile 比较的结果：

| 键 | 值 |
|---|---|
| `installed` | 装进 profile 的版本；未安装为 `null` |
| `installed_from` | profile 把它钉在哪个索引；本地 bundle 为 `directory` |
| `update` | 市场源有比已安装更新的版本 |
| `incompatible` | 它对 harness 分发包的要求里，当前版本不满足的各项；为空即可安装。插件按约定声明所面向的版本线（`pyxis-harness-core>=X.Y.0,<X.(Y+1).0`）；未声明的插件此项恒为空 |

## 安装

`install(source, name, version?)` → `manage.install_package`：事务、预检、失败即恢复。

| 项 | 契约 |
|---|---|
| 版本 | 总是一个确切版本：给定的，否则市场源列出的最新版；项目里写作 `name==version` |
| 包的来源 | 钉在该市场源的索引上（`tool.uv.sources` 的 `index`，索引为 `explicit`）：只从它取，其他包不从它取 |
| 依赖的来源 | uv 配置的索引（默认 PyPI）；只存在于市场源的依赖不会被解析到 |
| 解析 | 先用缓存，缺文件时联网 |
| 更新 | 同一操作：写入新版本 |

## 页面（`client.js`）

| 区域 | 内容 |
|---|---|
| 标题栏 | 「其他安装方式」、「市场源」按钮（数量）、刷新 |
| 其他安装方式 | 弹窗：本机的 bundle 目录（可用系统对话框选），或按包名从默认索引安装；走 `POST /api/plugins/install` |
| 工具栏 | 搜索（名称、简介、bundle、关键词、作者）；全部 / 已安装 / 可更新，各带数量；两个以上市场源时的来源选择；总数 |
| 卡片 | 头像（由名称得出的颜色与首字母）、名称、作者与来源、两行简介、版本（可更新时为 `旧 → 新`）、「不兼容」徽标、操作按钮 |
| 操作按钮 | 安装 / 更新 / 已安装 / 改从此源安装；处理中显示转圈；不兼容时不可用 |
| 插件弹窗 | 点卡片打开：readme（Markdown）、不兼容的原因；侧栏为状态（已安装时带去「插件」页管理的链接）、版本选择与「安装此版本」、bundle、来源、依赖、Python、许可证、关键词、主页 |
| 市场源弹窗 | 各源的状态点、地址、插件数或错误；添加、移除 |
| 提示 | 源读取失败或有包读不出：列表上方一条提示；安装被拒绝：弹窗显示原文；成功：toast，等重启后重读目录 |
| 空状态 | 没有市场源、源里没有插件、没有可更新、没有已安装、没有匹配，各有说明 |

## 路由

前缀 `/api/market`。

| 方法 | 路径 | 请求体 | 效果 |
|---|---|---|---|
| GET | `` | — | 目录：`{"sources", "plugins"}`；`?refresh=true` 重读索引 |
| PUT | `/sources` | `{"sources": [{"name", "url"}]}` | 替换市场源；返回重读后的目录；非法为 422 |
| POST | `/install` | `{"source", "name", "version"?}` | 安装或更新；被拒绝为 422；成功后 `restart-scheduled`（受管理）或 `saved-restart-required` |

## agent

`plugin_manager`（`pyxis-harness-plugin-manager`）经 `ctx.get("market")` 使用本服务：

| 动作 | 效果 |
|---|---|
| `market [target=<词>]` | 目录中名称、简介、bundle 含这些词的插件；只读，不需批准 |
| `install_bundle target=<包名>` | 市场源列出该包时从该源安装，否则从默认索引；需批准 |
