promptex-examples 0.0.0-stage → 1.4.0-alpha.2
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.
- package/LICENSE-APACHE +204 -0
- package/LICENSE-MIT +21 -0
- package/README.md +64 -2
- package/dist/index.json +2327 -0
- package/package.json +41 -3
package/LICENSE-APACHE
ADDED
|
@@ -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.
|
package/LICENSE-MIT
ADDED
|
@@ -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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# promptex-examples
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
promptex 各項特性的範例。每個範例是一個情境:讀者想做什麼、要寫的程式碼、跑完之後磁碟與終端機上出現什麼,以及它示範的 fact id。fact id 指向同一版的 [`promptex-facts`](../facts)。
|
|
4
|
+
|
|
5
|
+
範例由 promptex 自己的測試實際建置,所以程式碼片段就是實際執行的檔,終端機片段就是實際的輸出。
|
|
6
|
+
|
|
7
|
+
## 讀範例
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import examples from 'promptex-examples/index.json' with { type: 'json' }
|
|
11
|
+
|
|
12
|
+
for (const group of examples.groups) {
|
|
13
|
+
console.log(group.name, group.scenarios.length)
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`index.json` 的每個群組照 fact-kit 的範例組格式:`id`、`name`、`situation`、`claim` 與 `scenarios`。每個情境有 `title`、`situation`、`code`、`outcome`、`points` 與 `facts`。
|
|
18
|
+
|
|
19
|
+
## 目錄
|
|
20
|
+
|
|
21
|
+
| 路徑 | 內容 |
|
|
22
|
+
| :--- | :--- |
|
|
23
|
+
| `groups/<序號>-<群組>.ts` | 一個範例組,預設匯出。程式碼片段用 `project(群組, 專案).file(路徑)` 從專案讀出,終端機片段用 `.terminal(標題)` 從錄下的輸出組成 |
|
|
24
|
+
| `projects/<群組>/<專案>/` | 一個情境的最小可建置專案,放讀者要寫的檔 |
|
|
25
|
+
| `projects/<群組>/<專案>/scenario.json` | 情境的 `title`,與要執行的 `steps`。沒寫 `steps` 時跑一次 `promptex build --install` |
|
|
26
|
+
| `projects/<群組>/<專案>/expected/` | 執行後新增或改動的檔(`files/`)、刪掉的檔(`removed.json`)與每一步的終端輸出(`terminal.json`)。產出的 `.gitignore` 存成 `_gitignore`,因為原名會讓 git 忽略旁邊的預期檔 |
|
|
27
|
+
|
|
28
|
+
`scenario.json` 的每一步是執行一個指令,或在兩次執行之間換掉輸入檔。執行指令的步驟:
|
|
29
|
+
|
|
30
|
+
| 欄位 | 說明 |
|
|
31
|
+
| :--- | :--- |
|
|
32
|
+
| `run` | 指令與參數。指令只能是 `promptex` 或 `create-promptex-js`,都用這個倉庫的版本 |
|
|
33
|
+
| `status` | 預期的結束碼,預設 0 |
|
|
34
|
+
| `cwd` | 相對專案根目錄的執行位置,預設專案根目錄 |
|
|
35
|
+
| `schema` | 這一步印出 `--json` 時,驗證它用的 fact id,例如 `promptex.formats.build` |
|
|
36
|
+
|
|
37
|
+
換檔的步驟寫 `{ "copy": "variants/<檔>", "to": "<路徑>" }`,把專案 `variants/` 裡的檔放到 `<路徑>`。`{ "delete": "<路徑>" }` 刪掉一個輸入檔。`variants/` 裡的檔不算輸入,只在換檔時用到。
|
|
38
|
+
|
|
39
|
+
監看的步驟寫 `{ "watch": ["promptex", "build", "--install", "--watch"], "rounds": [<換檔步驟>, ...] }`:
|
|
40
|
+
|
|
41
|
+
1. 在背景啟動指令,等它印出第一輪完成的那行(以 `✓ Watch:` 或 `✗ Watch:` 開頭)。
|
|
42
|
+
2. 依序套用每一輪的換檔步驟,每套用一輪就等下一個完成行。一輪要換好幾個檔時,寫成換檔步驟的陣列。
|
|
43
|
+
3. 最後一輪完成後結束指令,整段輸出記成一筆終端輸出。
|
|
44
|
+
|
|
45
|
+
同步只看指令的輸出,不等固定時間。超過 `timeoutMs`(預設 60000)或指令自己結束,都算這一步失敗。
|
|
46
|
+
|
|
47
|
+
## 測試
|
|
48
|
+
|
|
49
|
+
```console
|
|
50
|
+
pnpm --filter promptex-examples test
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
依序做三件事:
|
|
54
|
+
|
|
55
|
+
1. `fact-kit check` 核對每個範例引用的 fact id 都存在。
|
|
56
|
+
2. 建出 `dist/index.json`。
|
|
57
|
+
3. 跑 `test/examples.test.mjs`。每個專案複製到暫存目錄,用這個倉庫的 CLI 執行,比對 `expected/`。產出的 `.promptex/` JSON 與 `--json` 輸出用 `promptex-facts` 的 schema 驗證。也核對每個情境的程式碼片段就是專案裡的檔,outcome 寫到的路徑都存在。
|
|
58
|
+
|
|
59
|
+
專案絕對路徑在預期產物裡寫成 `<project>`,promptex 版號寫成 `<version>`,所以升版不必重產。
|
|
60
|
+
|
|
61
|
+
## 改範例
|
|
62
|
+
|
|
63
|
+
1. 改 `projects/` 裡的檔,或新增一個專案並在對應的群組加一個情境。
|
|
64
|
+
2. 執行 `pnpm --filter promptex-examples run update <群組>/<專案>` 重產 `expected/`,不帶參數時重產全部。
|
|
65
|
+
3. 看過 `git diff` 確認產出是要的,再提交。
|