Compare commits

..

4 Commits

18 changed files with 870 additions and 253 deletions

52
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,52 @@
name: CI
on:
push:
branches: [main]
tags: ['v*']
pull_request:
workflow_dispatch:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
permissions:
contents: read
jobs:
linux:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.target }}
path: dist
release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/v')"
needs: [linux]
permissions:
id-token: write # 必须开启,用于 Trusted Publishing
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/target
.idea
.cache

362
Cargo.lock generated
View File

@ -67,12 +67,6 @@ version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
[[package]]
name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]]
name = "bitflags"
version = "2.11.1"
@ -142,27 +136,6 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]]
name = "console"
version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d64e8af5551369d19cf50138de61f1c42074ab970f74e99be916646777f8fc87"
dependencies = [
"encode_unicode",
"libc",
"unicode-width",
"windows-sys",
]
[[package]]
name = "deranged"
version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
dependencies = [
"powerfmt",
]
[[package]]
name = "drop_bomb"
version = "0.1.5"
@ -176,74 +149,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
[[package]]
name = "encode_unicode"
version = "1.0.0"
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]]
name = "futures"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"
[[package]]
name = "futures-io"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"
[[package]]
name = "futures-sink"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"
[[package]]
name = "futures-task"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"
[[package]]
name = "futures-util"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"slab",
]
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "getopts"
@ -265,6 +174,12 @@ dependencies = [
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"
[[package]]
name = "heck"
version = "0.5.0"
@ -272,18 +187,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "indicator"
version = "0.4.4"
name = "indexmap"
version = "2.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fa345379fdc6422d1c280715d64baeb9199e4f4524f2c4f19bc1a54216416ff"
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
dependencies = [
"arrayvec",
"futures",
"pin-project-lite",
"thiserror",
"time",
"tinyvec",
"tracing",
"equivalent",
"hashbrown",
]
[[package]]
@ -337,12 +247,6 @@ version = "2.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
[[package]]
name = "num-conv"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6673768db2d862beb9b39a78fdcb1a69439615d5794a1be50caa9bc92c81967"
[[package]]
name = "once_cell"
version = "1.21.4"
@ -355,18 +259,6 @@ version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "path_abs"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ef02f6342ac01d8a93b65f96db53fe68a92a15f41144f97fb00a9e669633c3"
dependencies = [
"serde",
"serde_derive",
"std_prelude",
"stfu8",
]
[[package]]
name = "phf"
version = "0.11.3"
@ -406,16 +298,10 @@ dependencies = [
]
[[package]]
name = "pin-project-lite"
version = "0.2.17"
name = "portable-atomic"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
[[package]]
name = "ppv-lite86"
@ -426,6 +312,22 @@ dependencies = [
"zerocopy",
]
[[package]]
name = "pretor-viceroy"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"pyo3",
"regex",
"ruff_python_ast",
"ruff_python_parser",
"serde",
"serde_json",
"serde_yaml",
"walkdir",
]
[[package]]
name = "proc-macro2"
version = "1.0.106"
@ -435,6 +337,64 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "pyo3"
version = "0.28.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12"
dependencies = [
"libc",
"once_cell",
"portable-atomic",
"pyo3-build-config",
"pyo3-ffi",
"pyo3-macros",
]
[[package]]
name = "pyo3-build-config"
version = "0.28.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e"
dependencies = [
"target-lexicon",
]
[[package]]
name = "pyo3-ffi"
version = "0.28.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e"
dependencies = [
"libc",
"pyo3-build-config",
]
[[package]]
name = "pyo3-macros"
version = "0.28.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
"quote",
"syn",
]
[[package]]
name = "pyo3-macros-backend"
version = "0.28.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb"
dependencies = [
"heck",
"proc-macro2",
"pyo3-build-config",
"quote",
"syn",
]
[[package]]
name = "quote"
version = "1.0.45"
@ -474,11 +434,34 @@ dependencies = [
"getrandom",
]
[[package]]
name = "regex"
version = "1.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
[[package]]
name = "ruff_python_ast"
@ -549,6 +532,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "ryu"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
[[package]]
name = "same-file"
version = "1.0.6"
@ -601,36 +590,31 @@ dependencies = [
"zmij",
]
[[package]]
name = "serde_yaml"
version = "0.9.34+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
dependencies = [
"indexmap",
"itoa",
"ryu",
"serde",
"unsafe-libyaml",
]
[[package]]
name = "siphasher"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e"
[[package]]
name = "slab"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "std_prelude"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8207e78455ffdf55661170876f88daf85356e4edd54e0a3dbc79586ca1e50cbe"
[[package]]
name = "stfu8"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51f1e89f093f99e7432c491c382b88a6860a5adbe6bf02574bf0a08efff1978"
[[package]]
name = "strsim"
version = "0.11.1"
@ -649,43 +633,10 @@ dependencies = [
]
[[package]]
name = "thiserror"
version = "1.0.69"
name = "target-lexicon"
version = "0.13.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.3.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c"
dependencies = [
"deranged",
"num-conv",
"powerfmt",
"serde_core",
"time-core",
]
[[package]]
name = "time-core"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca"
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
[[package]]
name = "tinyvec"
@ -702,25 +653,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tracing"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [
"once_cell",
]
[[package]]
name = "unicode-ident"
version = "1.0.24"
@ -764,28 +696,18 @@ dependencies = [
"rand",
]
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "viceroy"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"console",
"indicator",
"path_abs",
"ruff_python_ast",
"ruff_python_parser",
"serde",
"serde_json",
"walkdir",
]
[[package]]
name = "walkdir"
version = "2.5.0"

View File

@ -1,16 +1,26 @@
[package]
name = "viceroy"
name = "pretor-viceroy"
version = "0.1.0"
authors = ["zhaoxi826"]
description = "A high-performance skill installer and analysis tool for Pretor Multi-Agent system."
homepage = "https://github.com/zhaoxi826/viceroy"
repository = "https://github.com/zhaoxi826/viceroy"
license = "Apache-2.0"
readme = "README.md"
edition = "2024"
[lib]
name = "viceroy"
crate-type = ["cdylib", "rlib"]
[dependencies]
clap = { version = "4.4", features = ["derive"] }
anyhow = "1.0"
walkdir = "2.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
path_abs = "0.5"
console = "0.16.3"
indicator = "0.4.4"
ruff_python_parser = { git = "https://github.com/astral-sh/ruff", rev = "v0.4.0" }
ruff_python_ast = { git = "https://github.com/astral-sh/ruff", rev = "v0.4.0" }
regex = "1.12.3"
serde_yaml = "0.9.34"
pyo3 = { version = "0.28.3", features = ["extension-module"] }

202
LICENSE Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2026 zhaoxi826
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,10 +1,43 @@
<div align="center">
# Viceroy (总督)
Pretor的插件管理工具
![Rust](https://img.shields.io/badge/language-rust-orange.svg)
![Version](https://img.shields.io/badge/version-v0.1-blue.svg)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
</div>
---
*"你们搞大模型的就是码奸你们已经害死前端兄弟了还要害死后端兄弟测试兄弟运维兄弟害死网安兄弟害死ic兄弟最后害死自己害死全人类"*
>*"你们搞大模型的就是码奸你们已经害死前端兄弟了还要害死后端兄弟测试兄弟运维兄弟害死网安兄弟害死ic兄弟最后害死自己害死全人类"*
viceroy 是一个由rust编写的安装工具用于pretor的插件管理
pretor项目仓库https://github.com/zhaoxi826/Pretor
---
##快速开始
```Bash
pip install pretor-viceroy
#或者使用uv
uv pip install pretor-viceroy
```
在项目中使用
```python
import viceroy
```
---
## 目前支持对象
- skill: 安装skill并进行简单的解析到目标文件夹下
---
## 使用方法
#### Skill
**Skill** 是一个由指令、脚本和资源组成的集合Agent通过动态加载这些内容以在特定任务上提升表现。**Skill** 教会 **Agent** 如何以可重复的方式完成特定任务,例如按照公司品牌指南创建文档、使用组织特定的工作流程分析数据,或自动化个人任务。
目标仓库https://github.com/anthropics/skills
```Bash
./viceroy install (github仓库名) [-p (仓库内SKILL.md所在目录的相对路径)] -o (输出路径)
```
**viceroy**将在skill根目录下产生 **skill.json** 和 **metadata.json**两个文件。
**skill.json**包括SKILL.md的**name**,**description**,**instructions**。
**metadata**包含整个skill的文件树和架构和python脚本工具的函数信息。

21
pyproject.toml Normal file
View File

@ -0,0 +1,21 @@
[build-system]
requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"
[project]
name = "pretor-viceroy" # 确保这里和 Cargo.toml 中的 name 一致
version = "0.1.0"
description = "High-performance skill installer and analysis tool"
requires-python = ">=3.8"
authors = [
{ name = "zhaoxi826" }
]
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
[tool.maturin]
# 告诉 maturin 你的 Rust 源码在哪里(通常不用改)
features = ["pyo3/extension-module"]

View File

@ -1,2 +1,18 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
pub mod git;
pub mod install;

View File

@ -1,3 +1,19 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
use crate::installer::install::Installer;
use std::process::Command;
use anyhow::{Context, Result, anyhow};
@ -11,9 +27,7 @@ pub struct GitInstaller{
}
impl GitInstaller {
// 1. 增加一个关联函数 new负责“一键初始化”
pub fn new(git_repo_url: &str, root_cache_path: &str) -> Self {
// 逻辑:从 URL 提取仓库名(总督的直觉)
let repo_name = git_repo_url
.split('/')
.last()
@ -21,8 +35,6 @@ impl GitInstaller {
.trim_end_matches(".git");
let mut path_buf = PathBuf::from(root_cache_path);
path_buf.push(repo_name);
// 返回实例
Self {
git_repo_url: git_repo_url.to_owned(),
cache_path: Some(path_buf.display().to_string()),

View File

@ -1,5 +1,46 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
use anyhow::Result;
use std::path::Path;
use std::fs;
pub trait Installer {
fn download(&self) -> Result<()>;
}
pub fn copy_dir_recursive(src: &Path, dst: &Path) -> Result<()> {
if !dst.exists() {
fs::create_dir_all(dst)?;
}
for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
let target = dst.join(entry.file_name());
// Skip .git directory to avoid unnecessary weight
if entry.file_name() == ".git" {
continue;
}
if ty.is_dir() {
copy_dir_recursive(&entry.path(), &target)?;
} else {
fs::copy(&entry.path(), &target)?;
}
}
Ok(())
}

View File

@ -1,2 +1,37 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
pub mod installer;
pub mod manifest;
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
#[pyfunction]
#[pyo3(signature = (url, path=String::new(), cache=String::from(".cache"), output=None))]
fn install_skill(url: String, path: String, cache: String, output: Option<String>) -> PyResult<String> {
let skill = manifest::skill::model::SkillModel::install(url, cache, path, output);
skill.analysis().map_err(|e| {
PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(format!("Analysis failed: {}", e))
})?;
Ok(skill.skill_path)
}
#[pymodule]
fn viceroy(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(install_skill, m)?)?;
Ok(())
}

View File

@ -1,6 +1,84 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use viceroy::manifest::skill::analysis::process_and_save_skill;
use viceroy::manifest::skill::model::SkillModel;
use anyhow::Result;
fn main() {
#[derive(Parser)]
#[command(name = "viceroy")]
#[command(about = "Pretor's plugin management tool", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Parse a skill directory, extracting SKILL.md and analyzing python files.
Parse {
/// The path to the skill directory
#[arg(short, long, value_name = "DIR")]
path: PathBuf,
},
/// Install a skill from a Git repository and parse it
Install {
/// The Git repository URL
url: String,
/// Subdirectory path inside the repo (default is root)
#[arg(short = 'p', long, default_value = "")]
path: String,
/// Root cache directory to clone into
#[arg(short = 'c', long, default_value = ".cache")]
cache_dir: String,
/// Output directory to move the final skill into
#[arg(short = 'o', long)]
output: Option<String>,
},
}
fn main() -> Result<()> {
let cli = Cli::parse();
match &cli.command {
Commands::Parse { path } => {
if !path.exists() || !path.is_dir() {
anyhow::bail!("Error: path {:?} does not exist or is not a directory", path);
}
println!("Parsing skill directory: {:?}", path);
process_and_save_skill(path)?;
println!("Done.");
}
Commands::Install { url, path, cache_dir, output } => {
let mut final_url = url.clone();
if !final_url.starts_with("http://") && !final_url.starts_with("https://") && !final_url.starts_with("git@") {
final_url = format!("https://github.com/{}", final_url);
}
println!("Installing skill from {} into {}", final_url, cache_dir);
let skill = SkillModel::install(final_url, cache_dir.clone(), path.clone(), output.clone());
println!("Analyzing installed skill at {}", skill.skill_path);
skill.analysis()?;
println!("Done.");
}
}
Ok(())
}

View File

@ -1 +1,17 @@
mod skill;
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
pub mod skill;

View File

@ -1,3 +1,19 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
pub mod skill;
pub mod model;
pub mod analysis;

View File

@ -1,9 +1,55 @@
use crate::manifest::skill::skill_structure_tree::{SkillNode,PythonFuncNode,PythonFileNode};
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
use crate::manifest::skill::skill_structure_tree::{SkillNode, SkillJson, PythonFuncNode, PythonFileNode};
use walkdir::WalkDir;
use std::path::Path;
use std::collections::HashMap;
use ruff_python_parser::{parse, Mode};
use ruff_python_ast::{Mod, Stmt};
use regex::Regex;
pub fn parse_skill_md(content: &str) -> SkillJson {
let mut metadata = SkillJson::default();
// Pattern to match YAML frontmatter between `---` and `---`
let re_frontmatter = Regex::new(r"(?s)^---\s*(.*?)\s*---").unwrap();
if let Some(caps) = re_frontmatter.captures(content) {
let frontmatter = caps.get(1).map_or("", |m| m.as_str());
// Parse frontmatter properly using serde_yaml to support multiline values like `|`
if let Ok(yaml_data) = serde_yaml::from_str::<serde_json::Value>(frontmatter) {
if let Some(name) = yaml_data.get("name").and_then(|v| v.as_str()) {
metadata.name = name.to_string();
}
if let Some(desc) = yaml_data.get("description").and_then(|v| v.as_str()) {
metadata.description = desc.to_string();
}
}
// Extract instructions (everything after the frontmatter)
let body = re_frontmatter.replace(content, "").trim().to_string();
metadata.instructions = body;
} else {
// No frontmatter found, whole file is instructions
metadata.instructions = content.trim().to_string();
}
metadata
}
fn analyze_python_file(code: &str) -> PythonFileNode {
let mut func_dict = HashMap::new();
@ -29,25 +75,62 @@ fn analyze_python_file(code: &str) -> PythonFileNode {
}
}
fn main_scan_logic(root_path: &Path) {
pub fn analyze_skill_directory(root_path: &Path) -> (Option<SkillJson>, SkillNode) {
let mut root_node = SkillNode::new_folder("root");
let mut skill_metadata = None;
for entry in WalkDir::new(root_path).into_iter().filter_map(|e| e.ok()) {
let path = entry.path();
if path.is_file() {
let file_name_str = path.file_name().unwrap().to_string_lossy().to_string();
// Skip useless files
let lower_name = file_name_str.to_lowercase();
if lower_name.starts_with("license") || file_name_str.starts_with('.') {
continue;
}
let rel_path = path.strip_prefix(root_path).unwrap();
let segments: Vec<&str> = rel_path.iter().map(|s| s.to_str().unwrap()).collect();
let node = if path.extension().and_then(|s| s.to_str()) == Some("py") {
if file_name_str.to_lowercase() == "skill.md" && segments.len() == 1 {
let code = std::fs::read_to_string(path).expect("读取文件失败");
skill_metadata = Some(parse_skill_md(&code));
// We don't add SKILL.md to the tree since it will be in skill.json
continue;
}
let node = if path.extension().and_then(|s| s.to_str()) == Some("py") {
let code = std::fs::read_to_string(path).unwrap_or_default();
let mut py_node = analyze_python_file(&code);
py_node.file_name = path.file_stem().unwrap().to_string_lossy().into();
py_node.file_name = file_name_str.clone();
SkillNode::Python(py_node)
} else {
let file_name = path.file_name().unwrap().to_string_lossy().into();
SkillNode::File(file_name)
SkillNode::File(file_name_str)
};
root_node.insert_recursive(&segments, node);
}
}
let json = serde_json::to_string_pretty(&root_node).unwrap();
println!("{}", json);
(skill_metadata, root_node)
}
pub fn process_and_save_skill(root_path: &Path) -> anyhow::Result<()> {
let (metadata_opt, tree) = analyze_skill_directory(root_path);
// Save skill.json
if let Some(metadata) = metadata_opt {
let skill_json_path = root_path.join("skill.json");
let skill_json_content = serde_json::to_string_pretty(&metadata)?;
std::fs::write(&skill_json_path, skill_json_content)?;
println!("Saved {:?}", skill_json_path);
}
// Save metadata.json
let metadata_json_path = root_path.join("metadata.json");
let tree_json_content = serde_json::to_string_pretty(&tree)?;
std::fs::write(&metadata_json_path, tree_json_content)?;
println!("Saved {:?}", metadata_json_path);
Ok(())
}

View File

@ -1,3 +1,19 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
pub struct SkillModel{
pub skill_path: String,
}

View File

@ -1,10 +1,26 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
use crate::installer::git;
use crate::installer::install::Installer;
use crate::manifest::skill::model::SkillModel;
use std::path::PathBuf;
impl SkillModel{
fn install(git_repo_url: String, root_cache_path: String, relative_path: String) -> Self{
pub fn install(git_repo_url: String, root_cache_path: String, relative_path: String, output_dir: Option<String>) -> Self{
let git_installer = git::GitInstaller::new(&git_repo_url, &root_cache_path);
if let Err(e) = git_installer.download() {
eprintln!("安装失败: {}", e);
@ -17,12 +33,36 @@ impl SkillModel{
let mut path_builder = PathBuf::from(&root_cache_path);
path_builder.push(git_repo_name);
path_builder.push(&relative_path);
let skill_path = path_builder.to_string_lossy().to_string();
let mut final_path = path_builder.to_string_lossy().to_string();
if let Some(out_dir) = output_dir {
// Determine the name of the skill directory to create inside the output directory.
// e.g. if relative_path is "skills/skill-creator", skill_dir_name is "skill-creator".
// If relative_path is empty, use the repo name.
let skill_dir_name = if relative_path.is_empty() {
git_repo_name
} else {
relative_path.split('/').last().unwrap_or(git_repo_name)
};
let target_dst = std::path::Path::new(&out_dir).join(skill_dir_name);
// Copy the contents to the new target directory
if let Err(e) = crate::installer::install::copy_dir_recursive(&path_builder, &target_dst) {
eprintln!("复制到目标文件夹失败: {}", e);
} else {
final_path = target_dst.to_string_lossy().to_string();
}
}
Self{
skill_path,
skill_path: final_path,
}
}
fn analysis(&self){
pub fn analysis(&self) -> anyhow::Result<()> {
use std::path::Path;
use crate::manifest::skill::analysis::process_and_save_skill;
process_and_save_skill(Path::new(&self.skill_path))
}
}

View File

@ -1,5 +1,21 @@
/*
* // Copyright 2026 zhaoxi826
* //
* // Licensed under the Apache License, Version 2.0 (the "License");
* // you may not use this file except in compliance with the License.
* // You may obtain a copy of the License at
* //
* // http://www.apache.org/licenses/LICENSE-2.0
* //
* // Unless required by applicable law or agreed to in writing, software
* // distributed under the License is distributed on an "AS IS" BASIS,
* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* // See the License for the specific language governing permissions and
* // limitations under the License.
*/
use std::collections::HashMap;
use serde::Serialize;
use serde::{Serialize, Deserialize};
#[derive(Serialize)]
pub struct PythonFuncNode{
@ -45,3 +61,10 @@ impl SkillNode {
}
}
}
#[derive(Serialize, Deserialize, Default)]
pub struct SkillJson {
pub name: String,
pub description: String,
pub instructions: String,
}