promptex-py 0.0.1a1__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.
- promptex_py-0.0.1a1/.gitignore +3 -0
- promptex_py-0.0.1a1/LICENSE-APACHE +204 -0
- promptex_py-0.0.1a1/LICENSE-MIT +21 -0
- promptex_py-0.0.1a1/PKG-INFO +109 -0
- promptex_py-0.0.1a1/README.md +82 -0
- promptex_py-0.0.1a1/pyproject.toml +49 -0
- promptex_py-0.0.1a1/src/promptex/__init__.py +131 -0
- promptex_py-0.0.1a1/src/promptex/__main__.py +5 -0
- promptex_py-0.0.1a1/src/promptex/cli.py +70 -0
- promptex_py-0.0.1a1/src/promptex/py.typed +0 -0
- promptex_py-0.0.1a1/tests/test_promptex.py +78 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the
|
|
44
|
+
purposes of this License, Derivative Works shall not include works
|
|
45
|
+
that remain separable from, or merely link (or bind by name) to the
|
|
46
|
+
interfaces of, the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including the
|
|
49
|
+
original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright
|
|
52
|
+
owner or by an individual or Legal Entity authorized to submit on
|
|
53
|
+
behalf of the copyright owner. For the purposes of this definition,
|
|
54
|
+
"submitted" means any form of electronic, verbal, or written
|
|
55
|
+
communication sent to the Licensor or its representatives,
|
|
56
|
+
including but not limited to communication on electronic mailing
|
|
57
|
+
lists, source code control systems, and issue tracking systems that
|
|
58
|
+
are managed by, or on behalf of, the Licensor for the purpose of
|
|
59
|
+
discussing and improving the Work, but excluding communication that
|
|
60
|
+
is conspicuously marked or otherwise designated in writing by the
|
|
61
|
+
copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing
|
|
142
|
+
the origin of the Work and reproducing the content of the NOTICE
|
|
143
|
+
file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this
|
|
154
|
+
License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright 2026 promptex-ai
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 promptex-ai
|
|
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,109 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: promptex-py
|
|
3
|
+
Version: 0.0.1a1
|
|
4
|
+
Summary: promptex 的 Python SDK 最小原型(alpha):宣告 skill 並投影成 SKILL.md
|
|
5
|
+
Project-URL: Homepage, https://github.com/promptex-ai/promptex
|
|
6
|
+
Project-URL: Repository, https://github.com/promptex-ai/promptex
|
|
7
|
+
Project-URL: Issues, https://github.com/promptex-ai/promptex/issues
|
|
8
|
+
Author: promptex-ai
|
|
9
|
+
License: MIT OR Apache-2.0
|
|
10
|
+
License-File: LICENSE-APACHE
|
|
11
|
+
License-File: LICENSE-MIT
|
|
12
|
+
Keywords: agent,ai,claude,codegen,llm,prompt,prompt-engineering,skills
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
23
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# promptex-py(alpha 原型)
|
|
29
|
+
|
|
30
|
+
promptex 的 Python SDK **最小原型**。目前的能力只有一項:宣告 skill,建置成
|
|
31
|
+
Claude Code 的 `SKILL.md` 產物。
|
|
32
|
+
|
|
33
|
+
## 這不是什麼
|
|
34
|
+
|
|
35
|
+
本套件是早期 alpha,**不是**完整的 promptex。正式版的單一套件內含 SDK、核心的
|
|
36
|
+
預編譯二進位綁定與完整命令列工具三者;本原型只有 SDK 的最窄一條路徑,命令列
|
|
37
|
+
工具只有 `build` 一個動詞,沒有原生綁定、沒有多平台投影、沒有引用與關係圖、
|
|
38
|
+
沒有安裝與所有權登記。
|
|
39
|
+
|
|
40
|
+
介面與產物格式在正式版之前都會變,不保證任何相容性。正式版發布時本原型會被
|
|
41
|
+
整份取代。
|
|
42
|
+
|
|
43
|
+
## 安裝
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install --pre promptex-py
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
需要 Python 3.10 以上。`--pre` 是必要的:預發布版號不會被 pip 預設選中。
|
|
50
|
+
|
|
51
|
+
## 用法
|
|
52
|
+
|
|
53
|
+
把宣告寫在 `prompts/` 下:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
# prompts/skill.py
|
|
57
|
+
from promptex import config, define_skill
|
|
58
|
+
|
|
59
|
+
commit_helper = define_skill(
|
|
60
|
+
"commit-helper",
|
|
61
|
+
"Commit 訊息協助",
|
|
62
|
+
config=config(when_to_use="當使用者要求撰寫 commit 訊息時使用"),
|
|
63
|
+
content=[
|
|
64
|
+
"依 Conventional Commits 撰寫:type(scope): subject。",
|
|
65
|
+
"subject 用繁體中文、50 字內,不以句號結尾;body 說明變更動機而非變更內容。",
|
|
66
|
+
],
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
建置:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
promptex build
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
產出 `./.claude/skills/commit-helper/SKILL.md`:
|
|
77
|
+
|
|
78
|
+
```text
|
|
79
|
+
---
|
|
80
|
+
name: commit-helper
|
|
81
|
+
description: 當使用者要求撰寫 commit 訊息時使用
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
依 Conventional Commits 撰寫:type(scope): subject。
|
|
85
|
+
|
|
86
|
+
subject 用繁體中文、50 字內,不以句號結尾;body 說明變更動機而非變更內容。
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 命令列選項
|
|
90
|
+
|
|
91
|
+
```text
|
|
92
|
+
promptex build [--src <目錄>] [--out <目錄>]
|
|
93
|
+
|
|
94
|
+
--src <目錄> 宣告檔所在目錄,預設 prompts
|
|
95
|
+
--out <目錄> 產物輸出目錄,預設當前目錄
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 程式化呼叫
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from promptex import build, config, define_skill
|
|
102
|
+
|
|
103
|
+
define_skill("commit-helper", "Commit 訊息協助", config=config(when_to_use="..."), content="...")
|
|
104
|
+
written = build(".")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 授權
|
|
108
|
+
|
|
109
|
+
MIT OR Apache-2.0,見 `LICENSE-MIT` 與 `LICENSE-APACHE`。
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# promptex-py(alpha 原型)
|
|
2
|
+
|
|
3
|
+
promptex 的 Python SDK **最小原型**。目前的能力只有一項:宣告 skill,建置成
|
|
4
|
+
Claude Code 的 `SKILL.md` 產物。
|
|
5
|
+
|
|
6
|
+
## 這不是什麼
|
|
7
|
+
|
|
8
|
+
本套件是早期 alpha,**不是**完整的 promptex。正式版的單一套件內含 SDK、核心的
|
|
9
|
+
預編譯二進位綁定與完整命令列工具三者;本原型只有 SDK 的最窄一條路徑,命令列
|
|
10
|
+
工具只有 `build` 一個動詞,沒有原生綁定、沒有多平台投影、沒有引用與關係圖、
|
|
11
|
+
沒有安裝與所有權登記。
|
|
12
|
+
|
|
13
|
+
介面與產物格式在正式版之前都會變,不保證任何相容性。正式版發布時本原型會被
|
|
14
|
+
整份取代。
|
|
15
|
+
|
|
16
|
+
## 安裝
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install --pre promptex-py
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
需要 Python 3.10 以上。`--pre` 是必要的:預發布版號不會被 pip 預設選中。
|
|
23
|
+
|
|
24
|
+
## 用法
|
|
25
|
+
|
|
26
|
+
把宣告寫在 `prompts/` 下:
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
# prompts/skill.py
|
|
30
|
+
from promptex import config, define_skill
|
|
31
|
+
|
|
32
|
+
commit_helper = define_skill(
|
|
33
|
+
"commit-helper",
|
|
34
|
+
"Commit 訊息協助",
|
|
35
|
+
config=config(when_to_use="當使用者要求撰寫 commit 訊息時使用"),
|
|
36
|
+
content=[
|
|
37
|
+
"依 Conventional Commits 撰寫:type(scope): subject。",
|
|
38
|
+
"subject 用繁體中文、50 字內,不以句號結尾;body 說明變更動機而非變更內容。",
|
|
39
|
+
],
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
建置:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
promptex build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
產出 `./.claude/skills/commit-helper/SKILL.md`:
|
|
50
|
+
|
|
51
|
+
```text
|
|
52
|
+
---
|
|
53
|
+
name: commit-helper
|
|
54
|
+
description: 當使用者要求撰寫 commit 訊息時使用
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
依 Conventional Commits 撰寫:type(scope): subject。
|
|
58
|
+
|
|
59
|
+
subject 用繁體中文、50 字內,不以句號結尾;body 說明變更動機而非變更內容。
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 命令列選項
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
promptex build [--src <目錄>] [--out <目錄>]
|
|
66
|
+
|
|
67
|
+
--src <目錄> 宣告檔所在目錄,預設 prompts
|
|
68
|
+
--out <目錄> 產物輸出目錄,預設當前目錄
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 程式化呼叫
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from promptex import build, config, define_skill
|
|
75
|
+
|
|
76
|
+
define_skill("commit-helper", "Commit 訊息協助", config=config(when_to_use="..."), content="...")
|
|
77
|
+
written = build(".")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 授權
|
|
81
|
+
|
|
82
|
+
MIT OR Apache-2.0,見 `LICENSE-MIT` 與 `LICENSE-APACHE`。
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "promptex-py"
|
|
3
|
+
# PEP 440 的正規化形態:npm 與 crates.io 側寫的是 semver 的 `0.0.1-alpha.1`,
|
|
4
|
+
# PyPI 會把它正規化成 `0.0.1a1`,兩者指同一個版本。三生態版號無法逐字相同,
|
|
5
|
+
# 這是預發布版號的既有限制。
|
|
6
|
+
version = "0.0.1a1"
|
|
7
|
+
description = "promptex 的 Python SDK 最小原型(alpha):宣告 skill 並投影成 SKILL.md"
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
license = { text = "MIT OR Apache-2.0" }
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
authors = [{ name = "promptex-ai" }]
|
|
12
|
+
keywords = ["prompt", "prompt-engineering", "ai", "llm", "agent", "claude", "skills", "codegen"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"License :: OSI Approved :: Apache Software License",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Build Tools",
|
|
24
|
+
"Topic :: Software Development :: Code Generators",
|
|
25
|
+
# 這一項要成立得靠 src/promptex/py.typed 隨 wheel 一起出貨(PEP 561):
|
|
26
|
+
# 型別檢查器對已安裝的套件一律先找標記檔,找不到就整個套件視為無標註。
|
|
27
|
+
"Typing :: Typed",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/promptex-ai/promptex"
|
|
32
|
+
Repository = "https://github.com/promptex-ai/promptex"
|
|
33
|
+
Issues = "https://github.com/promptex-ai/promptex/issues"
|
|
34
|
+
|
|
35
|
+
[project.scripts]
|
|
36
|
+
promptex = "promptex.cli:main"
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["hatchling>=1.25"]
|
|
40
|
+
build-backend = "hatchling.build"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/promptex"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build]
|
|
46
|
+
# 開發樹本身就是 python-source,直譯器跑過測試留下的 __pycache__ 會被收進
|
|
47
|
+
# wheel。那些 .pyc 綁死在建置機的 Python 版本上,對安裝端無用,卻讓 wheel
|
|
48
|
+
# 的內容清單隨「誰在哪台機器上建的」而變。
|
|
49
|
+
exclude = ["**/__pycache__/**"]
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""promptex 的 Python SDK 最小原型(alpha)。
|
|
2
|
+
|
|
3
|
+
目前的能力只有一條路徑:宣告 skill,投影成 Claude Code 的 SKILL.md。
|
|
4
|
+
正式版的核心綁定、多平台投影、引用與關係圖都不在本原型範圍內。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from dataclasses import dataclass, field
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"CapabilityConfig",
|
|
14
|
+
"Ref",
|
|
15
|
+
"build",
|
|
16
|
+
"config",
|
|
17
|
+
"declared_count",
|
|
18
|
+
"define_skill",
|
|
19
|
+
"render_skill",
|
|
20
|
+
"skill_path",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
__version__ = "0.0.1a1"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True)
|
|
27
|
+
class CapabilityConfig:
|
|
28
|
+
"""skill 的觸發設定。"""
|
|
29
|
+
|
|
30
|
+
when_to_use: str = ""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def config(*, when_to_use: str = "") -> CapabilityConfig:
|
|
34
|
+
"""建立觸發設定。與正式版的宣告形態一致,以具名參數承載。"""
|
|
35
|
+
return CapabilityConfig(when_to_use=when_to_use)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class Ref:
|
|
40
|
+
"""宣告後回傳的引用。正式版以它承載節點間的引用關係,本原型只帶識別。"""
|
|
41
|
+
|
|
42
|
+
kind: str
|
|
43
|
+
id: str
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class _Skill:
|
|
48
|
+
"""登記處內的正規化形態。"""
|
|
49
|
+
|
|
50
|
+
id: str
|
|
51
|
+
name: str
|
|
52
|
+
when_to_use: str
|
|
53
|
+
content: list[str] = field(default_factory=list)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# 模組層級的登記處:宣告散落在多個檔案時,逐一回傳並手動彙整會讓每個檔案
|
|
57
|
+
# 都得認識彙整點。正式版的收集語意相同。
|
|
58
|
+
_registry: list[_Skill] = []
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _is_valid_id(value: str) -> bool:
|
|
62
|
+
"""id 是否可安全作為單層目錄名。
|
|
63
|
+
|
|
64
|
+
產物路徑由 id 直接組成,不擋下來的話 ``../`` 這類值會把檔案寫到輸出
|
|
65
|
+
目錄之外。
|
|
66
|
+
"""
|
|
67
|
+
return bool(value) and "/" not in value and "\\" not in value and value not in {".", ".."}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def define_skill(
|
|
71
|
+
id: str,
|
|
72
|
+
name: str,
|
|
73
|
+
*,
|
|
74
|
+
config: CapabilityConfig | None = None,
|
|
75
|
+
content: str | list[str] | None = None,
|
|
76
|
+
) -> Ref:
|
|
77
|
+
"""宣告一份 skill。
|
|
78
|
+
|
|
79
|
+
宣告本身不寫檔;產物在 :func:`build` 被呼叫時一次產出。
|
|
80
|
+
"""
|
|
81
|
+
if not _is_valid_id(id):
|
|
82
|
+
raise ValueError(f"skill id 不可為空、且不可含 `/`、`\\` 或 `..`:{id!r}")
|
|
83
|
+
pieces = [] if content is None else ([content] if isinstance(content, str) else list(content))
|
|
84
|
+
_registry.append(
|
|
85
|
+
_Skill(
|
|
86
|
+
id=id,
|
|
87
|
+
name=name,
|
|
88
|
+
when_to_use=(config or CapabilityConfig()).when_to_use,
|
|
89
|
+
content=pieces,
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
return Ref(kind="skill", id=id)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def declared_count() -> int:
|
|
96
|
+
"""目前已登記的宣告數。供呼叫端在建置前自我核對用。"""
|
|
97
|
+
return len(_registry)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def render_skill(skill: _Skill) -> str:
|
|
101
|
+
"""把一份 skill 投影成 SKILL.md 的完整內容。
|
|
102
|
+
|
|
103
|
+
frontmatter 的 ``name`` 取 id 而非顯示名稱:平台側以 ``name`` 作為喚起時
|
|
104
|
+
的識別。
|
|
105
|
+
"""
|
|
106
|
+
header = f"---\nname: {skill.id}\ndescription: {skill.when_to_use}\n---\n"
|
|
107
|
+
if not skill.content:
|
|
108
|
+
return header
|
|
109
|
+
return header + "\n" + "\n\n".join(skill.content) + "\n"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def skill_path(out_dir: str | Path, id: str) -> Path:
|
|
113
|
+
"""一份 skill 在輸出目錄下的產物路徑。"""
|
|
114
|
+
return Path(out_dir) / ".claude" / "skills" / id / "SKILL.md"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def build(out_dir: str | Path) -> list[Path]:
|
|
118
|
+
"""把目前登記的全部宣告投影到輸出目錄,回傳產物路徑。
|
|
119
|
+
|
|
120
|
+
呼叫後登記處清空:同一行程內連續建置兩個輸出目錄時,第二次不該重複
|
|
121
|
+
寫出第一次的內容。
|
|
122
|
+
"""
|
|
123
|
+
skills = list(_registry)
|
|
124
|
+
_registry.clear()
|
|
125
|
+
written: list[Path] = []
|
|
126
|
+
for skill in skills:
|
|
127
|
+
path = skill_path(out_dir, skill.id)
|
|
128
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
129
|
+
path.write_text(render_skill(skill), encoding="utf-8")
|
|
130
|
+
written.append(path)
|
|
131
|
+
return written
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""promptex 命令列工具(alpha 原型)。
|
|
2
|
+
|
|
3
|
+
只有一個動詞:``build``。載入來源目錄下的宣告檔,把登記處內的 skill 投影成
|
|
4
|
+
SKILL.md。正式版的其餘動詞(evaluate、declare、config、diagnostics)不在本
|
|
5
|
+
原型範圍內。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import importlib.util
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from . import build, declared_count
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _load_source(path: Path) -> None:
|
|
19
|
+
"""以檔案路徑載入一份宣告檔。
|
|
20
|
+
|
|
21
|
+
走 importlib 的 spec 載入而非 ``import``:宣告檔住使用者的專案目錄,
|
|
22
|
+
不在套件搜尋路徑上,也不該為了載入它去改動 ``sys.path``。
|
|
23
|
+
"""
|
|
24
|
+
module_name = f"_promptex_source_{path.stem}"
|
|
25
|
+
spec = importlib.util.spec_from_file_location(module_name, path)
|
|
26
|
+
if spec is None or spec.loader is None:
|
|
27
|
+
raise RuntimeError(f"無法載入宣告檔:{path}")
|
|
28
|
+
module = importlib.util.module_from_spec(spec)
|
|
29
|
+
sys.modules[module_name] = module
|
|
30
|
+
spec.loader.exec_module(module)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _collect_sources(src_dir: Path) -> list[Path]:
|
|
34
|
+
"""列出來源目錄下的宣告檔,依路徑排序讓載入順序不隨檔案系統而變。"""
|
|
35
|
+
return sorted(p for p in src_dir.rglob("*.py") if p.name != "__init__.py")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def main(argv: list[str] | None = None) -> int:
|
|
39
|
+
parser = argparse.ArgumentParser(prog="promptex", description="promptex(alpha 原型)")
|
|
40
|
+
sub = parser.add_subparsers(dest="verb", required=True)
|
|
41
|
+
build_parser = sub.add_parser("build", help="把宣告投影成產物")
|
|
42
|
+
build_parser.add_argument("--src", default="prompts", help="宣告檔所在目錄,預設 prompts")
|
|
43
|
+
build_parser.add_argument("--out", default=".", help="產物輸出目錄,預設當前目錄")
|
|
44
|
+
|
|
45
|
+
args = parser.parse_args(sys.argv[1:] if argv is None else argv)
|
|
46
|
+
|
|
47
|
+
src_dir = Path(args.src).resolve()
|
|
48
|
+
if not src_dir.is_dir():
|
|
49
|
+
print(f"找不到來源目錄:{src_dir}", file=sys.stderr)
|
|
50
|
+
return 1
|
|
51
|
+
|
|
52
|
+
sources = _collect_sources(src_dir)
|
|
53
|
+
if not sources:
|
|
54
|
+
print(f"來源目錄沒有宣告檔(*.py):{src_dir}", file=sys.stderr)
|
|
55
|
+
return 1
|
|
56
|
+
|
|
57
|
+
for source in sources:
|
|
58
|
+
_load_source(source)
|
|
59
|
+
|
|
60
|
+
if declared_count() == 0:
|
|
61
|
+
print(f"載入了 {len(sources)} 份宣告檔,但沒有任何 skill 被宣告。", file=sys.stderr)
|
|
62
|
+
return 1
|
|
63
|
+
|
|
64
|
+
for path in build(Path(args.out).resolve()):
|
|
65
|
+
print(path)
|
|
66
|
+
return 0
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
raise SystemExit(main())
|
|
File without changes
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""SDK 的單元測試。以 stdlib 的 unittest 承載,不引入測試框架依賴。
|
|
2
|
+
|
|
3
|
+
執行:``PYTHONPATH=src python3 -m unittest discover -s tests``
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import tempfile
|
|
9
|
+
import unittest
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import promptex
|
|
13
|
+
from promptex import build, config, declared_count, define_skill, render_skill, skill_path
|
|
14
|
+
|
|
15
|
+
HEADER = "---\nname: commit-helper\ndescription: 當使用者要求撰寫 commit 訊息時使用\n---\n"
|
|
16
|
+
PARAGRAPHS = [
|
|
17
|
+
"依 Conventional Commits 撰寫:type(scope): subject。",
|
|
18
|
+
"subject 用繁體中文、50 字內,不以句號結尾。",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RenderTests(unittest.TestCase):
|
|
23
|
+
def setUp(self) -> None:
|
|
24
|
+
promptex._registry.clear()
|
|
25
|
+
|
|
26
|
+
def test_renders_frontmatter_and_paragraphs(self) -> None:
|
|
27
|
+
define_skill(
|
|
28
|
+
"commit-helper",
|
|
29
|
+
"Commit 訊息協助",
|
|
30
|
+
config=config(when_to_use="當使用者要求撰寫 commit 訊息時使用"),
|
|
31
|
+
content=PARAGRAPHS,
|
|
32
|
+
)
|
|
33
|
+
expected = HEADER + "\n" + "\n\n".join(PARAGRAPHS) + "\n"
|
|
34
|
+
self.assertEqual(render_skill(promptex._registry[0]), expected)
|
|
35
|
+
|
|
36
|
+
def test_renders_frontmatter_only_when_content_is_empty(self) -> None:
|
|
37
|
+
define_skill(
|
|
38
|
+
"commit-helper",
|
|
39
|
+
"Commit 訊息協助",
|
|
40
|
+
config=config(when_to_use="當使用者要求撰寫 commit 訊息時使用"),
|
|
41
|
+
)
|
|
42
|
+
self.assertEqual(render_skill(promptex._registry[0]), HEADER)
|
|
43
|
+
|
|
44
|
+
def test_single_string_content_becomes_one_paragraph(self) -> None:
|
|
45
|
+
define_skill("x", "X", config=config(when_to_use="t"), content="只有一段")
|
|
46
|
+
self.assertEqual(promptex._registry[0].content, ["只有一段"])
|
|
47
|
+
|
|
48
|
+
def test_rejects_ids_that_escape_the_output_directory(self) -> None:
|
|
49
|
+
with self.assertRaisesRegex(ValueError, "skill id 不可為空"):
|
|
50
|
+
define_skill("../escape", "X", config=config(when_to_use="t"), content="c")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class BuildTests(unittest.TestCase):
|
|
54
|
+
def setUp(self) -> None:
|
|
55
|
+
promptex._registry.clear()
|
|
56
|
+
|
|
57
|
+
def test_writes_to_claude_skills_layout_and_drains_registry(self) -> None:
|
|
58
|
+
define_skill(
|
|
59
|
+
"commit-helper",
|
|
60
|
+
"Commit 訊息協助",
|
|
61
|
+
config=config(when_to_use="當使用者要求撰寫 commit 訊息時使用"),
|
|
62
|
+
content=PARAGRAPHS,
|
|
63
|
+
)
|
|
64
|
+
self.assertEqual(declared_count(), 1)
|
|
65
|
+
|
|
66
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
67
|
+
written = build(tmp)
|
|
68
|
+
self.assertEqual(written, [skill_path(tmp, "commit-helper")])
|
|
69
|
+
self.assertEqual(
|
|
70
|
+
Path(written[0]).read_text(encoding="utf-8"),
|
|
71
|
+
HEADER + "\n" + "\n\n".join(PARAGRAPHS) + "\n",
|
|
72
|
+
)
|
|
73
|
+
self.assertEqual(declared_count(), 0)
|
|
74
|
+
self.assertEqual(build(tmp), [])
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
unittest.main()
|