create-promptex-js 1.0.0-alpha.1 → 1.0.1
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 +5 -7
- package/dist/index.js +27 -42
- package/dist/messages.generated.js +12 -24
- package/package.json +21 -2
- package/templates/adapter-starter/README.md +45 -0
- package/templates/adapter-starter/_gitignore +6 -0
- package/templates/adapter-starter/example/promptex.config.ts +12 -0
- package/templates/adapter-starter/example/prompts/nodes.ts +18 -0
- package/templates/adapter-starter/package.json +28 -0
- package/templates/adapter-starter/promptex.config.schema.json +12 -0
- package/templates/adapter-starter/src/index.ts +93 -0
- package/templates/adapter-starter/tsconfig.json +14 -0
- package/templates/plugin-starter/README.md +40 -0
- package/templates/plugin-starter/_gitignore +5 -0
- package/templates/plugin-starter/example/promptex.config.ts +12 -0
- package/templates/plugin-starter/example/prompts/nodes.ts +16 -0
- package/templates/plugin-starter/package.json +28 -0
- package/templates/plugin-starter/promptex.config.schema.json +12 -0
- package/templates/plugin-starter/src/index.ts +63 -0
- package/templates/plugin-starter/tsconfig.json +14 -0
- package/templates/project-starter/README.md +30 -0
- package/templates/project-starter/_gitignore +11 -0
- package/templates/project-starter/package.json +13 -0
- package/templates/project-starter/promptex.config.ts +8 -0
- package/templates/project-starter/prompts/example-skill.ts +14 -0
- package/templates/project-starter/prompts/example.ts +14 -0
- package/dist/default-ref.d.ts +0 -6
- package/dist/default-ref.js +0 -14
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
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Scaffold a [promptex](https://github.com/promptex-ai/promptex) TypeScript
|
|
4
4
|
project, plugin or adapter from the
|
|
5
|
-
|
|
6
|
-
starters.
|
|
5
|
+
starter templates bundled with this package.
|
|
7
6
|
|
|
8
7
|
```console
|
|
9
8
|
npm create promptex-js
|
|
@@ -19,8 +18,7 @@ npm create promptex-js my-prompts -- --template project --name my-prompts --no-g
|
|
|
19
18
|
| :--- | :--- |
|
|
20
19
|
| `--template <t>` | `project`(消費專案)、`plugin`、`adapter` |
|
|
21
20
|
| `--name <n>` | kebab-case 名稱;預設取目標目錄名正規化 |
|
|
22
|
-
| `--
|
|
23
|
-
| `--source <p>` | 改用本地 promptex-templates checkout(離線與開發用) |
|
|
21
|
+
| `--source <p>` | 改讀本地模板目錄(含各 `*-starter` 的那一層),開發模板時用 |
|
|
24
22
|
| `--git` / `--no-git` | 是否 `git init`;互動預設是 |
|
|
25
23
|
| `--install` | 鷹架後直接 `npm install`;預設只印下一步 |
|
|
26
24
|
| `--yes` | 跳過互動,全部取預設或旗標值 |
|
|
@@ -32,9 +30,9 @@ npm create promptex-js my-prompts -- --template project --name my-prompts --no-g
|
|
|
32
30
|
用哪個語系寫([ADR-030](https://github.com/promptex-ai/ssot)):那份內容從產出
|
|
33
31
|
當下起就歸你,框架不再改寫它。plugin 與 adapter 骨架裡教你怎麼填的註解維持英文。
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
目標目錄非空時列出既有項目、零寫入退出。模板隨本套件一起發布,
|
|
34
|
+
鷹架時不需要網路,每個版本具現化的都是它發布時的模板。`{{promptexVersion}}`
|
|
35
|
+
於鷹架當下以本套件版本填入,三套件與 SDK 同版發布。
|
|
38
36
|
|
|
39
37
|
`promptex init` 與本工具的分工:init 在既有專案就地補上 promptex(非互動、
|
|
40
38
|
極簡骨架);本工具從零開一個 repo(互動、三種模板、git init)。
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// 鷹架 CLI
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// 鷹架 CLI:開出 TypeScript 的 project/plugin/adapter 專案。六階段:環境檢查 →
|
|
3
|
+
// 互動收集 → 模板取得 → 具現化 → 後處理 → 稽核輸出;非互動時(--yes 或無 TTY)
|
|
4
|
+
// 全部取預設或旗標值。
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// Templates ship inside this package (templates/), so every version scaffolds the
|
|
7
|
+
// templates it was released with, offline. --source points at a local templates
|
|
8
|
+
// directory (the one holding the *-starter folders) for template development.
|
|
9
9
|
//
|
|
10
10
|
// 用法:
|
|
11
11
|
// npm create promptex-js [目標目錄] [-- --template project|plugin|adapter \
|
|
12
|
-
// --name <kebab 名> --
|
|
12
|
+
// --name <kebab 名> --source <模板目錄> \
|
|
13
13
|
// --git|--no-git --install --yes --locale <語系>]
|
|
14
|
-
import {
|
|
15
|
-
import { existsSync, mkdirSync,
|
|
16
|
-
import { tmpdir } from 'node:os';
|
|
14
|
+
import { spawnSync } from 'node:child_process';
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
17
16
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
18
17
|
import { fileURLToPath } from 'node:url';
|
|
19
18
|
import * as p from '@clack/prompts';
|
|
20
19
|
import mri from 'mri';
|
|
21
|
-
import { resolveRef } from './default-ref.js';
|
|
22
20
|
import { resolveLocale, t } from './messages.generated.js';
|
|
23
21
|
const here = fileURLToPath(new URL('.', import.meta.url));
|
|
24
22
|
const ownVersion = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8')).version;
|
|
23
|
+
const BUNDLED_TEMPLATES = join(here, '..', 'templates');
|
|
25
24
|
const TEMPLATES = ['project', 'plugin', 'adapter'];
|
|
26
25
|
// 與 promptex init 的單元名正規化同一套規則(crates/promptex-core/src/init.rs)。
|
|
27
26
|
const RESERVED_UNIT_NAMES = ['cache', 'preview', 'content', 'content-index', 'graph', 'main'];
|
|
@@ -40,13 +39,21 @@ function bail(message) {
|
|
|
40
39
|
console.error(message);
|
|
41
40
|
process.exit(1);
|
|
42
41
|
}
|
|
43
|
-
const
|
|
42
|
+
const BOOLEAN_FLAGS = ['install', 'yes', 'git', 'help'];
|
|
43
|
+
const STRING_FLAGS = ['template', 'name', 'source', 'locale'];
|
|
44
44
|
const args = mri(process.argv.slice(2), {
|
|
45
|
-
boolean:
|
|
46
|
-
string:
|
|
45
|
+
boolean: BOOLEAN_FLAGS,
|
|
46
|
+
string: STRING_FLAGS,
|
|
47
47
|
alias: { h: 'help' },
|
|
48
48
|
});
|
|
49
49
|
const locale = resolveLocale(args.locale);
|
|
50
|
+
// mri accepts any flag, so reject the ones this tool does not declare (a removed
|
|
51
|
+
// --ref must fail loudly instead of being ignored). `--no-git` arrives as `git`.
|
|
52
|
+
const knownFlags = new Set(['_', 'h', ...BOOLEAN_FLAGS, ...STRING_FLAGS]);
|
|
53
|
+
for (const key of Object.keys(args)) {
|
|
54
|
+
if (!knownFlags.has(key))
|
|
55
|
+
bail(t('scaffold.error.unknown_argument', locale, { arg: `--${key}` }));
|
|
56
|
+
}
|
|
50
57
|
const separator = t('common.list_separator', locale);
|
|
51
58
|
if (args.help) {
|
|
52
59
|
console.log(t('scaffold.usage.js', locale));
|
|
@@ -116,32 +123,12 @@ if (existsSync(targetDir)) {
|
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
const gitAvailable = spawnSync('git', ['--version'], { stdio: 'ignore' }).status === 0;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (args.source) {
|
|
126
|
-
sourceRoot = join(resolve(args.source), 'typescript');
|
|
127
|
-
sourceLabel = t('scaffold.source.local', locale, { path: resolve(args.source) });
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
const { ref, showCloneHint } = resolveRef(args.ref, ownVersion);
|
|
131
|
-
cloneDir = mkdtempSync(join(tmpdir(), 'promptex-templates-'));
|
|
132
|
-
try {
|
|
133
|
-
execFileSync('git', ['clone', '--depth', '1', '--branch', ref, TEMPLATES_REPO, cloneDir], {
|
|
134
|
-
stdio: ['ignore', 'ignore', 'inherit'],
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
const hint = showCloneHint ? t('scaffold.error.clone_hint', locale) : '';
|
|
139
|
-
bail(t('scaffold.error.clone_failed', locale, { ref, hint }));
|
|
140
|
-
}
|
|
141
|
-
sourceRoot = join(cloneDir, 'typescript');
|
|
142
|
-
sourceLabel = `promptex-templates@${ref}`;
|
|
143
|
-
}
|
|
144
|
-
const starterDir = join(sourceRoot, `${template}-starter`);
|
|
126
|
+
// ── 模板取得:預設用內附模板;--source 讀本地模板目錄。 ──
|
|
127
|
+
const templatesRoot = args.source ? resolve(args.source) : BUNDLED_TEMPLATES;
|
|
128
|
+
const sourceLabel = args.source
|
|
129
|
+
? t('scaffold.source.local', locale, { path: templatesRoot })
|
|
130
|
+
: t('scaffold.source.bundled', locale, { version: ownVersion });
|
|
131
|
+
const starterDir = join(templatesRoot, `${template}-starter`);
|
|
145
132
|
if (!existsSync(starterDir))
|
|
146
133
|
bail(t('scaffold.error.starter_missing', locale, { template, path: starterDir }));
|
|
147
134
|
// ── 具現化:複製、佔位替換、_gitignore 改名。 ──
|
|
@@ -209,8 +196,6 @@ for (const rel of walk(starterDir)) {
|
|
|
209
196
|
writeFileSync(destPath, substitute(readFileSync(join(starterDir, rel), 'utf8')));
|
|
210
197
|
written.push(destRel);
|
|
211
198
|
}
|
|
212
|
-
if (cloneDir)
|
|
213
|
-
rmSync(cloneDir, { recursive: true, force: true });
|
|
214
199
|
// ── 後處理:git init(可選)、--install 裝依賴。 ──
|
|
215
200
|
if (wantGit && gitAvailable)
|
|
216
201
|
spawnSync('git', ['init', '--quiet'], { cwd: targetDir, stdio: 'inherit' });
|
|
@@ -19,14 +19,6 @@ export const MESSAGES = {
|
|
|
19
19
|
"en": "Wrote %{count} files → %{path} (template source: %{source})",
|
|
20
20
|
"zh-Hant": "已寫入 %{count} 個檔案 → %{path}(模板來源:%{source})",
|
|
21
21
|
},
|
|
22
|
-
"scaffold.error.clone_failed": {
|
|
23
|
-
"en": "git clone promptex-templates@%{ref} failed. %{hint}",
|
|
24
|
-
"zh-Hant": "git clone promptex-templates@%{ref} 失敗。%{hint}",
|
|
25
|
-
},
|
|
26
|
-
"scaffold.error.clone_hint": {
|
|
27
|
-
"en": "The tag for this version may not have been created yet: use --ref main to get the latest, or --source <local-path> to take it offline.",
|
|
28
|
-
"zh-Hant": "此版本的 tag 可能尚未建立:用 --ref main 抓最新、或 --source <本地路徑> 離線取用。",
|
|
29
|
-
},
|
|
30
22
|
"scaffold.error.dir_create": {
|
|
31
23
|
"en": "Creating %{path} failed: %{reason}",
|
|
32
24
|
"zh-Hant": "建立 %{path} 失敗:%{reason}",
|
|
@@ -47,10 +39,6 @@ export const MESSAGES = {
|
|
|
47
39
|
"en": "%{flag} is missing its value",
|
|
48
40
|
"zh-Hant": "%{flag} 缺值",
|
|
49
41
|
},
|
|
50
|
-
"scaffold.error.git_required": {
|
|
51
|
-
"en": "Getting the template needs git (or give a local promptex-templates path with --source).",
|
|
52
|
-
"zh-Hant": "取得模板需要 git(或用 --source 指定本地 promptex-templates 路徑)。",
|
|
53
|
-
},
|
|
54
42
|
"scaffold.error.install_failed.js": {
|
|
55
43
|
"en": "npm install failed; the scaffold files were written, the dependencies were not installed.",
|
|
56
44
|
"zh-Hant": "npm install 失敗,鷹架檔案已寫入、依賴未裝。",
|
|
@@ -95,13 +83,9 @@ export const MESSAGES = {
|
|
|
95
83
|
"en": "kebab-case name, defaults to the normalized target directory name",
|
|
96
84
|
"zh-Hant": "kebab-case 名稱,預設取目標目錄名正規化",
|
|
97
85
|
},
|
|
98
|
-
"scaffold.help.ref": {
|
|
99
|
-
"en": "take the given branch/tag of promptex-templates (defaults to v<this package's version>; pre-release versions default to main)",
|
|
100
|
-
"zh-Hant": "抓 promptex-templates 的指定 branch/tag(預設 v<本套件版本>;預發布版預設 main)",
|
|
101
|
-
},
|
|
102
86
|
"scaffold.help.source": {
|
|
103
|
-
"en": "use a local
|
|
104
|
-
"zh-Hant": "
|
|
87
|
+
"en": "use a local templates directory (the one holding the *-starter folders) instead of the bundled templates, for template development",
|
|
88
|
+
"zh-Hant": "改用本地模板目錄(含各 *-starter 的那一層)取代內附模板,開發模板時用",
|
|
105
89
|
},
|
|
106
90
|
"scaffold.help.target_dir": {
|
|
107
91
|
"en": "target directory",
|
|
@@ -139,6 +123,10 @@ export const MESSAGES = {
|
|
|
139
123
|
"en": "Template (%{choices})",
|
|
140
124
|
"zh-Hant": "模板(%{choices})",
|
|
141
125
|
},
|
|
126
|
+
"scaffold.source.bundled": {
|
|
127
|
+
"en": "bundled templates (v%{version})",
|
|
128
|
+
"zh-Hant": "內附模板(v%{version})",
|
|
129
|
+
},
|
|
142
130
|
"scaffold.source.local": {
|
|
143
131
|
"en": "local template (%{path})",
|
|
144
132
|
"zh-Hant": "本地模板(%{path})",
|
|
@@ -156,16 +144,16 @@ export const MESSAGES = {
|
|
|
156
144
|
"zh-Hant": "project:提示詞源碼樹(消費專案)",
|
|
157
145
|
},
|
|
158
146
|
"scaffold.usage.js": {
|
|
159
|
-
"en": "create-promptex-js [target-dir] --template project|plugin|adapter --name <kebab-name> [--
|
|
160
|
-
"zh-Hant": "create-promptex-js [目標目錄] --template project|plugin|adapter --name <kebab 名> [--
|
|
147
|
+
"en": "create-promptex-js [target-dir] --template project|plugin|adapter --name <kebab-name> [--source <templates-dir>] [--git|--no-git] [--install] [--yes] [--locale <locale>]",
|
|
148
|
+
"zh-Hant": "create-promptex-js [目標目錄] --template project|plugin|adapter --name <kebab 名> [--source <模板目錄>] [--git|--no-git] [--install] [--yes] [--locale <語系>]",
|
|
161
149
|
},
|
|
162
150
|
"scaffold.usage.py": {
|
|
163
|
-
"en": "uvx create-promptex-py [target-dir] [--template project|plugin|adapter] [--name <kebab-name>] [--
|
|
164
|
-
"zh-Hant": "uvx create-promptex-py [目標目錄] [--template project|plugin|adapter] [--name <kebab 名>] [--
|
|
151
|
+
"en": "uvx create-promptex-py [target-dir] [--template project|plugin|adapter] [--name <kebab-name>] [--source <templates-dir>] [--git|--no-git] [--install] [--yes] [--locale <locale>]",
|
|
152
|
+
"zh-Hant": "uvx create-promptex-py [目標目錄] [--template project|plugin|adapter] [--name <kebab 名>] [--source <模板目錄>] [--git|--no-git] [--install] [--yes] [--locale <語系>]",
|
|
165
153
|
},
|
|
166
154
|
"scaffold.usage.rs": {
|
|
167
|
-
"en": "cargo create-promptex-rs [target-dir] --template project|plugin|adapter --name <kebab-name> [--
|
|
168
|
-
"zh-Hant": "cargo create-promptex-rs [目標目錄] --template project|plugin|adapter --name <kebab 名> [--
|
|
155
|
+
"en": "cargo create-promptex-rs [target-dir] --template project|plugin|adapter --name <kebab-name> [--source <templates-dir>] [--git|--no-git] [--install] [--yes] [--locale <locale>]",
|
|
156
|
+
"zh-Hant": "cargo create-promptex-rs [目標目錄] --template project|plugin|adapter --name <kebab 名> [--source <模板目錄>] [--git|--no-git] [--install] [--yes] [--locale <語系>]",
|
|
169
157
|
},
|
|
170
158
|
"template.adapter_demo.rule_content": {
|
|
171
159
|
"en": "On the custom platform this rule degrades to always-on, with its scope noted in the body.",
|
package/package.json
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-promptex-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Scaffold a promptex TypeScript project, plugin or adapter.",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"homepage": "https://github.com/promptex-ai/promptex/tree/main/packages/create-promptex-js#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/promptex-ai/promptex/issues"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"promptex",
|
|
12
|
+
"create",
|
|
13
|
+
"scaffold",
|
|
14
|
+
"template",
|
|
15
|
+
"prompt",
|
|
16
|
+
"prompt-engineering",
|
|
17
|
+
"ai",
|
|
18
|
+
"llm",
|
|
19
|
+
"agent",
|
|
20
|
+
"codegen"
|
|
21
|
+
],
|
|
6
22
|
"repository": {
|
|
7
23
|
"type": "git",
|
|
8
24
|
"url": "https://github.com/promptex-ai/promptex.git",
|
|
@@ -14,7 +30,10 @@
|
|
|
14
30
|
},
|
|
15
31
|
"files": [
|
|
16
32
|
"bin",
|
|
17
|
-
"dist"
|
|
33
|
+
"dist",
|
|
34
|
+
"templates",
|
|
35
|
+
"LICENSE-MIT",
|
|
36
|
+
"LICENSE-APACHE"
|
|
18
37
|
],
|
|
19
38
|
"engines": {
|
|
20
39
|
"node": ">=18"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# promptex-adapter-{{name}}
|
|
2
|
+
|
|
3
|
+
A publishable third-party [promptex](https://github.com/promptex-ai/promptex)
|
|
4
|
+
platform adapter, written in TypeScript.
|
|
5
|
+
|
|
6
|
+
**Adapters are language-bound**: this package serves TypeScript prompt projects
|
|
7
|
+
only. To support the same platform from Python or Rust projects, implement the
|
|
8
|
+
same `emit` chain against that language's SDK.
|
|
9
|
+
|
|
10
|
+
The factory returns the same shape as the built-in `claude()` / `codex()`
|
|
11
|
+
targets, so consumers list it right alongside them. Its `emit` function walks a
|
|
12
|
+
fixed responsibility chain:
|
|
13
|
+
|
|
14
|
+
1. Compute the layout table first — rendering needs it to resolve references.
|
|
15
|
+
2. Report every unsupported kind via `ctx.unsupported` — never drop silently.
|
|
16
|
+
3. Render supported entries via `ctx.render(entry, selfPath, layout)`; where
|
|
17
|
+
the platform lacks a feature (e.g. scoped loading), record it with
|
|
18
|
+
`ctx.degrade` and degrade in the output. Read platform-native keys via
|
|
19
|
+
`ctx.overrides`, never from the entry config directly.
|
|
20
|
+
4. Emit referenced resources.
|
|
21
|
+
|
|
22
|
+
## Try it
|
|
23
|
+
|
|
24
|
+
```console
|
|
25
|
+
npm install
|
|
26
|
+
cd example
|
|
27
|
+
npx promptex build --install .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The example project lists `targets: [claude(), target()]`; after install you
|
|
31
|
+
get both `.claude/` and `.{{name}}/` artifacts, and the install report shows
|
|
32
|
+
the `scopedLoading` degradation for the example rule. `npx promptex build --install --dry-run .`
|
|
33
|
+
previews without writing.
|
|
34
|
+
|
|
35
|
+
## Publishing
|
|
36
|
+
|
|
37
|
+
- `npm run build` compiles `src/` to `dist/`; the package ships `dist/` plus
|
|
38
|
+
`promptex.config.schema.json`.
|
|
39
|
+
- Keep `promptex.config.schema.json` at the package root: `promptex config
|
|
40
|
+
declare promptex-adapter-{{name}}` reads it from there, and `src/index.ts`
|
|
41
|
+
reads that same root copy at load time (a runtime read, not a compile-time
|
|
42
|
+
JSON import, so the emitted tree keeps a single copy and `dist/` stays flat)
|
|
43
|
+
and passes it to `defineTarget`, so it also travels with the intermediate
|
|
44
|
+
representation.
|
|
45
|
+
- Keep the `promptex-adapter-` name prefix so consumers can find the package.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// 最小消費專案:自訂 target 與內建 claude() 並列,裝完依賴即可在本目錄執行
|
|
2
|
+
// npx promptex build --install . 驗證兩個平台的產物。真實消費端改為從發布後的套件名
|
|
3
|
+
// import。
|
|
4
|
+
import { claude, defineConfig } from 'promptex-js'
|
|
5
|
+
import target from '../src/index.ts'
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
name: 'adapter-example',
|
|
9
|
+
srcDir: './prompts',
|
|
10
|
+
outDir: '.',
|
|
11
|
+
targets: [claude(), target()],
|
|
12
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineRule, defineSkill } from 'promptex-js'
|
|
2
|
+
|
|
3
|
+
export const exampleSkill = defineSkill({
|
|
4
|
+
id: 'adapter-demo-skill',
|
|
5
|
+
name: '{{demoSkillName}}',
|
|
6
|
+
description: '{{adapterDemoSkillDescription}}',
|
|
7
|
+
config: { whenToUse: '{{adapterDemoSkillWhenToUse}}' },
|
|
8
|
+
content: '{{adapterDemoSkillContent}}',
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
// A rule carrying appliesTo: the custom platform has no scoped-loading mechanism,
|
|
12
|
+
// so the install report shows a scopedLoading degrade entry.
|
|
13
|
+
export const exampleRule = defineRule({
|
|
14
|
+
id: 'adapter-demo-rule',
|
|
15
|
+
name: '{{demoRuleName}}',
|
|
16
|
+
config: { appliesTo: ['prompts/**'] },
|
|
17
|
+
content: '{{adapterDemoRuleContent}}',
|
|
18
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "promptex-adapter-{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A third-party promptex platform adapter.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"promptex.config.schema.json"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"promptex-js": "^{{promptexVersion}}"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.10.0",
|
|
25
|
+
"promptex-js": "^{{promptexVersion}}",
|
|
26
|
+
"typescript": "^7.0.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "promptex-adapter-{{name}} options",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"root": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"description": "Root directory for emitted artifacts, relative to the install root. Defaults to \".{{name}}\"."
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"additionalProperties": false
|
|
12
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// 第三方 adapter:以 SDK 層實作,只用 AdapterContext 的公開介面。emit 的
|
|
2
|
+
// 責任鏈固定四步:① 算落點表 → ② 回報不支援的 kind → ③ 渲染並產出節點
|
|
3
|
+
// (平台缺某機制時記 degrade 降級)→ ④ 產出被引用的資源。發布前把落點
|
|
4
|
+
// 規則與能力集合換成你的平台實況。
|
|
5
|
+
//
|
|
6
|
+
// adapter 綁語言:本套件服務 TypeScript 專案;Python/Rust 專案要用同一個
|
|
7
|
+
// 平台時,各自以該語言的 SDK 實作一份。
|
|
8
|
+
import { readFileSync } from 'node:fs'
|
|
9
|
+
|
|
10
|
+
import { defineTarget, type AdapterContext, type AdapterTarget, type PluginEntry } from 'promptex-js'
|
|
11
|
+
|
|
12
|
+
// 參數宣告(標準 JSON Schema)住套件根,由本檔在載入時讀進來。用執行期讀檔而非
|
|
13
|
+
// 編譯期 import:JSON 在 include 的 src 之外,靜態 import 會把編譯器的共同來源根
|
|
14
|
+
// 抬到套件根,產物因此多一層 src/,包裡還會留下第二份 schema。改讀檔之後
|
|
15
|
+
// src/index.ts 與 dist/index.js 對套件根的相對位置相同,兩種形態都指向同一份。
|
|
16
|
+
const configSchema = JSON.parse(readFileSync(new URL('../promptex.config.schema.json', import.meta.url), 'utf8'))
|
|
17
|
+
|
|
18
|
+
/** 建構參數:與 promptex.config.schema.json 的宣告一一對應。 */
|
|
19
|
+
export interface Options {
|
|
20
|
+
/** 產物落點的根目錄;預設 `.{{name}}`。 */
|
|
21
|
+
readonly root?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 平台能力:本範例只有提示詞單檔與參考資料,無代理、無事件機制。 */
|
|
25
|
+
const SUPPORTED = ['skill', 'rule', 'instruction'] as const
|
|
26
|
+
const UNSUPPORTED = ['agent', 'hook', 'mcp', 'permission'] as const
|
|
27
|
+
|
|
28
|
+
export default function target(options: Options = {}): AdapterTarget {
|
|
29
|
+
const root = options.root ?? '.{{name}}'
|
|
30
|
+
// 落點規則:提示詞一律單檔平鋪,資源集中於 refs/。
|
|
31
|
+
const nodePath = (e: PluginEntry) => `${root}/prompts/${e.id}.md`
|
|
32
|
+
const resourcePath = (e: PluginEntry) => `${root}/refs/${e.id}.md`
|
|
33
|
+
|
|
34
|
+
const emit = (ctx: AdapterContext): Map<string, string> => {
|
|
35
|
+
const files = new Map<string, string>()
|
|
36
|
+
|
|
37
|
+
// ① 先算落點表:渲染需要它解析引用,故必須在渲染之前完成。
|
|
38
|
+
const layout = new Map<string, string>()
|
|
39
|
+
for (const kind of SUPPORTED) {
|
|
40
|
+
for (const e of ctx.entries(kind)) layout.set(`${kind}:${e.id}`, nodePath(e))
|
|
41
|
+
}
|
|
42
|
+
for (const kind of ['resource', 'asset', 'dir'] as const) {
|
|
43
|
+
for (const e of ctx.entries(kind)) layout.set(`${kind}:${e.id}`, resourcePath(e))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ② 不支援的 kind 逐一列報告,不靜默丟棄。
|
|
47
|
+
for (const kind of UNSUPPORTED) {
|
|
48
|
+
for (const e of ctx.entries(kind)) {
|
|
49
|
+
ctx.unsupported({ kind, nodeId: e.id, feature: kind, note: `{{name}} 無 ${kind} 對應機制,該節點未產出` })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ③ 產出提示詞單檔;rule 的載入範圍在本平台無對應機制,降級為內文標註。
|
|
54
|
+
for (const kind of SUPPORTED) {
|
|
55
|
+
for (const e of ctx.entries(kind)) {
|
|
56
|
+
const path = nodePath(e)
|
|
57
|
+
const cfg = e.def.config as { appliesTo?: readonly string[] } | undefined
|
|
58
|
+
let note = ''
|
|
59
|
+
if (kind === 'rule' && cfg?.appliesTo?.length) {
|
|
60
|
+
note = `適用範圍:${cfg.appliesTo.join('、')}\n\n`
|
|
61
|
+
ctx.degrade({
|
|
62
|
+
kind,
|
|
63
|
+
nodeId: e.id,
|
|
64
|
+
feature: 'scopedLoading',
|
|
65
|
+
note: '{{name}} 無範圍載入機制,改為常駐並於內文標註適用範圍',
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
files.set(path, `${frontmatter(ctx, e)}# ${e.name}\n\n${note}${ctx.render(e, path, layout)}\n`)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ④ 被引用的資源。
|
|
73
|
+
for (const e of ctx.entries('resource')) {
|
|
74
|
+
const path = resourcePath(e)
|
|
75
|
+
files.set(path, `# ${e.name}\n\n${ctx.render(e, path, layout)}\n`)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return files
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 參數宣告隨中介表示交給讀取端;
|
|
82
|
+
// `promptex config declare` 讀的是套件根的同一份檔案。
|
|
83
|
+
return defineTarget('{{name}}', emit, { configSchema })
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 平台原生鍵的覆寫:一律經 ctx.overrides 讀取,不自己走
|
|
87
|
+
// entry.def.config.platforms:「空物件視同未宣告」的判定與框架保留鍵
|
|
88
|
+
// (promptex: 前綴)的過濾都由核心同一份實作承載,自己讀會各自重造而漂移。
|
|
89
|
+
const frontmatter = (ctx: AdapterContext, e: PluginEntry): string => {
|
|
90
|
+
const overrides = ctx.overrides(e)
|
|
91
|
+
if (!overrides) return ''
|
|
92
|
+
return `---\n${Object.entries(overrides).map(([k, v]) => `${k}: ${String(v)}`).join('\n')}\n---\n\n`
|
|
93
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "nodenext",
|
|
4
|
+
"moduleResolution": "nodenext",
|
|
5
|
+
"target": "es2022",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# promptex-plugin-{{name}}
|
|
2
|
+
|
|
3
|
+
A publishable [promptex](https://github.com/promptex-ai/promptex) plugin,
|
|
4
|
+
written in TypeScript for TypeScript prompt projects.
|
|
5
|
+
|
|
6
|
+
A plugin hooks into the evaluation pipeline in a fixed order:
|
|
7
|
+
|
|
8
|
+
1. `prepare` — the only async stage, runs before source collection. Fetch
|
|
9
|
+
external data here (cache it under `ctx.cacheDir`, record pins with
|
|
10
|
+
`ctx.writeLock`) and pass it to later stages through the plugin's closure.
|
|
11
|
+
2. `transform` — rewrite existing entries through the context operations
|
|
12
|
+
(`appendContent` / `patchConfig`) or add new nodes with `define*`.
|
|
13
|
+
3. `validate` — structural checks over the registry; return diagnostics
|
|
14
|
+
(an empty array passes). Core checks run first.
|
|
15
|
+
|
|
16
|
+
Plugins produce **nodes**, not files: anything you want on disk becomes a
|
|
17
|
+
resource node that the core lays out.
|
|
18
|
+
|
|
19
|
+
## Try it
|
|
20
|
+
|
|
21
|
+
```console
|
|
22
|
+
npm install
|
|
23
|
+
cd example
|
|
24
|
+
npx promptex build --install .
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The example project wires the plugin in via `plugins: [createPlugin(...)]` and
|
|
28
|
+
shows the banner appended to both entries. `npx promptex build --install --dry-run .` previews
|
|
29
|
+
without writing.
|
|
30
|
+
|
|
31
|
+
## Publishing
|
|
32
|
+
|
|
33
|
+
- `npm run build` compiles `src/` to `dist/`; the package ships `dist/` plus
|
|
34
|
+
`promptex.config.schema.json`.
|
|
35
|
+
- Keep `promptex.config.schema.json` at the package root: `promptex config
|
|
36
|
+
declare promptex-plugin-{{name}}` reads it from there, and `src/index.ts`
|
|
37
|
+
reads that same root copy at load time (a runtime read, not a compile-time
|
|
38
|
+
JSON import, so the emitted tree keeps a single copy and `dist/` stays flat),
|
|
39
|
+
so the schema also travels with the intermediate representation.
|
|
40
|
+
- Keep the `promptex-plugin-` name prefix so consumers can find the package.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// 最小消費專案:直接以相對路徑掛上本套件的 plugin,裝完依賴即可在本目錄
|
|
2
|
+
// 執行 npx promptex build --install . 驗證產物。真實消費端改為從發布後的套件名 import。
|
|
3
|
+
import { claude, defineConfig } from 'promptex-js'
|
|
4
|
+
import { createPlugin } from '../src/index.ts'
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
name: 'plugin-example',
|
|
8
|
+
srcDir: './prompts',
|
|
9
|
+
outDir: '.',
|
|
10
|
+
targets: [claude()],
|
|
11
|
+
plugins: [createPlugin({ banner: '(由 {{name}} plugin 追加)' })],
|
|
12
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineRule, defineSkill } from 'promptex-js'
|
|
2
|
+
|
|
3
|
+
export const exampleSkill = defineSkill({
|
|
4
|
+
id: 'plugin-demo-skill',
|
|
5
|
+
name: '{{demoSkillName}}',
|
|
6
|
+
description: '{{pluginDemoSkillDescription}}',
|
|
7
|
+
config: { whenToUse: '{{pluginDemoSkillWhenToUse}}' },
|
|
8
|
+
content: '{{pluginDemoSkillContent}}',
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
export const exampleRule = defineRule({
|
|
12
|
+
id: 'plugin-demo-rule',
|
|
13
|
+
name: '{{demoRuleName}}',
|
|
14
|
+
config: { appliesTo: ['prompts/**'] },
|
|
15
|
+
content: '{{pluginDemoRuleContent}}',
|
|
16
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "promptex-plugin-{{name}}",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A promptex plugin.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"promptex.config.schema.json"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"promptex-js": "^{{promptexVersion}}"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^22.10.0",
|
|
25
|
+
"promptex-js": "^{{promptexVersion}}",
|
|
26
|
+
"typescript": "^7.0.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "promptex-plugin-{{name}} options",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"banner": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"description": "Appended to every skill and rule at the transform stage. Defaults to a built-in notice."
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"additionalProperties": false
|
|
12
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// 最小可發布 plugin:三個生命週期各示範一件事,發布前把內容換成你的邏輯。
|
|
2
|
+
// 生命週期固定順序:prepare(唯一 async 的階段,收集遍之前)→ 源碼求值 →
|
|
3
|
+
// transform(改寫遍)→ validate(解析遍,核心檢查在先)。
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
5
|
+
|
|
6
|
+
import type { Diagnostic, Plugin } from 'promptex-js'
|
|
7
|
+
|
|
8
|
+
// 參數宣告(標準 JSON Schema)住套件根,由本檔在載入時讀進來。用執行期讀檔而非
|
|
9
|
+
// 編譯期 import:JSON 在 include 的 src 之外,靜態 import 會把編譯器的共同來源根
|
|
10
|
+
// 抬到套件根,產物因此多一層 src/,包裡還會留下第二份 schema。改讀檔之後
|
|
11
|
+
// src/index.ts 與 dist/index.js 對套件根的相對位置相同,兩種形態都指向同一份。
|
|
12
|
+
const configSchema = JSON.parse(readFileSync(new URL('../promptex.config.schema.json', import.meta.url), 'utf8'))
|
|
13
|
+
|
|
14
|
+
/** 建構參數:與 promptex.config.schema.json 的宣告一一對應。 */
|
|
15
|
+
export interface Options {
|
|
16
|
+
/** transform 階段追加到每個 skill 與 rule 的內容;省略時用預設文字。 */
|
|
17
|
+
readonly banner?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const DEFAULT_BANNER = '(本節點由 {{name}} plugin 追加此行)'
|
|
21
|
+
|
|
22
|
+
export function createPlugin(options: Options = {}): Plugin {
|
|
23
|
+
// prepare 取得的資料存進閉包,transform 只讀閉包、不知道資料從何而來。
|
|
24
|
+
let banner = ''
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
name: '{{name}}',
|
|
28
|
+
// 宣告本擴充作用在哪幾種節點類型(供文件與讀取端),不隱含過濾。
|
|
29
|
+
kinds: ['skill', 'rule'],
|
|
30
|
+
// 相容的框架版本範圍:安裝的 promptex-js 落在範圍外時於編譯開始前報錯。
|
|
31
|
+
version: '^{{promptexVersion}}',
|
|
32
|
+
// 參數宣告隨中介表示交給讀取端;
|
|
33
|
+
// `promptex config declare` 讀的是套件根的同一份檔案。
|
|
34
|
+
configSchema,
|
|
35
|
+
|
|
36
|
+
// 準備:唯一 async 的生命週期。真實 plugin 在這裡請求外部資源,或以
|
|
37
|
+
// ctx.cacheDir 快取、ctx.writeLock 記錄鎖定;本範例只把參數收斂成
|
|
38
|
+
// transform 要用的值。
|
|
39
|
+
async prepare() {
|
|
40
|
+
banner = options.banner ?? DEFAULT_BANNER
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
// 改寫:改寫既有節點一律經 ctx 操作函式(appendContent/patchConfig),
|
|
44
|
+
// 型別安全、變更可追蹤、衝突可偵測;也可在此以 define* 新增節點。
|
|
45
|
+
transform(ctx) {
|
|
46
|
+
for (const entry of ctx.entries) {
|
|
47
|
+
if (entry.kind === 'skill' || entry.kind === 'rule') ctx.appendContent(entry, banner)
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
// 驗證:對註冊表做結構驗證,回傳診斷(空陣列即通過)。
|
|
52
|
+
validate(ctx): Diagnostic[] {
|
|
53
|
+
return ctx.entries
|
|
54
|
+
.filter((e) => e.id.startsWith('promptex-'))
|
|
55
|
+
.map((e) => ({
|
|
56
|
+
code: '{{name}}-reserved-id',
|
|
57
|
+
message: `節點 ${e.id} 以保留前綴 promptex- 命名,請改用其他 id`,
|
|
58
|
+
at: [e.at],
|
|
59
|
+
severity: 'error',
|
|
60
|
+
}))
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "nodenext",
|
|
4
|
+
"moduleResolution": "nodenext",
|
|
5
|
+
"target": "es2022",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
A [promptex](https://github.com/promptex-ai/promptex) prompt-source tree:
|
|
4
|
+
resources are declared in TypeScript under `prompts/` and projected onto your
|
|
5
|
+
AI coding tool by the `promptex` CLI.
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
```console
|
|
10
|
+
npm install
|
|
11
|
+
npm run install:prompts
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`npm run install:prompts` compiles the declarations and writes the platform
|
|
15
|
+
artifacts (e.g. `.claude/`) into this directory. `npm run build` only refreshes
|
|
16
|
+
the framework metadata under `.promptex/` without touching platform artifacts;
|
|
17
|
+
`npx promptex build --install --dry-run .` previews the diff without writing anything.
|
|
18
|
+
|
|
19
|
+
## Layout
|
|
20
|
+
|
|
21
|
+
| Path | Role |
|
|
22
|
+
| :--- | :--- |
|
|
23
|
+
| `promptex.config.ts` | Unit configuration: source dir, output dir, targets |
|
|
24
|
+
| `prompts/example.ts` | Example rule (scope-loaded via `appliesTo`) |
|
|
25
|
+
| `prompts/example-skill.ts` | Example skill (invoked via `whenToUse`) |
|
|
26
|
+
|
|
27
|
+
Add more resources as ordinary `.ts` files under `prompts/`; every file in the
|
|
28
|
+
source dir is evaluated. See the
|
|
29
|
+
[promptex-js README](https://github.com/promptex-ai/promptex/tree/main/packages/promptex-js)
|
|
30
|
+
for the full API.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# === promptex init 產生的忽略規則(重跑以本行判定,勿改寫)===
|
|
2
|
+
# 框架的建置快取。整個 .promptex/ 不忽略:查詢進入點的覆寫檔 .promptex/query
|
|
3
|
+
# 是作者手寫的內容,要入版控;匯出的 .promptex/preview/ 入不入版控由你決定。
|
|
4
|
+
.promptex/cache/
|
|
5
|
+
# 框架每次建置重寫的中繼(結構與內容本體),可重建、不入版控。逐檔明列而非
|
|
6
|
+
# 用 .promptex/*/ 這類萬用:同一層還住著所有權登記 {平台}.json,那是要入版控的。
|
|
7
|
+
.promptex/*/graph.json
|
|
8
|
+
.promptex/*/content.json
|
|
9
|
+
.promptex/*/content-index.json
|
|
10
|
+
# npm 安裝依賴的落點。
|
|
11
|
+
node_modules/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineSkill } from 'promptex-js'
|
|
2
|
+
|
|
3
|
+
export const exampleSkill = defineSkill({
|
|
4
|
+
id: 'example-skill',
|
|
5
|
+
name: '{{exampleSkillName}}',
|
|
6
|
+
description: '{{exampleSkillDescription}}',
|
|
7
|
+
config: {
|
|
8
|
+
whenToUse: '{{exampleSkillWhenToUse}}',
|
|
9
|
+
},
|
|
10
|
+
content: [
|
|
11
|
+
'{{exampleSkillIntro}}',
|
|
12
|
+
'{{exampleSkillInvoked}}',
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineRule } from 'promptex-js'
|
|
2
|
+
|
|
3
|
+
export const exampleRule = defineRule({
|
|
4
|
+
id: 'example-rule',
|
|
5
|
+
name: '{{exampleRuleName}}',
|
|
6
|
+
config: {
|
|
7
|
+
appliesTo: ['prompts/**'],
|
|
8
|
+
},
|
|
9
|
+
content: [
|
|
10
|
+
'{{exampleRuleIntro}}',
|
|
11
|
+
'{{exampleRuleScoped}}',
|
|
12
|
+
'{{exampleRuleOtherStates}}',
|
|
13
|
+
],
|
|
14
|
+
})
|
package/dist/default-ref.d.ts
DELETED
package/dist/default-ref.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// 預設 templates ref 的判定(決策 d006)。三個 create-* 鷹架規則一致:
|
|
2
|
-
// GA 版號(X.Y.Z)抓對應 tag `v<版本>`;帶預發布後綴(-alpha.N、-beta.N、-rc.N 等)
|
|
3
|
-
// 的版本,tag 不一定存在,預設抓 `main`;使用者給 --ref 一律照用。
|
|
4
|
-
const GA_VERSION = /^\d+\.\d+\.\d+$/;
|
|
5
|
-
export function defaultRef(version) {
|
|
6
|
-
return GA_VERSION.test(version) ? `v${version}` : 'main';
|
|
7
|
-
}
|
|
8
|
-
/** `showCloneHint`:clone 失敗時是否附上「tag 可能尚未建立」提示,只在 GA 預設 ref 時為真。 */
|
|
9
|
-
export function resolveRef(explicit, version) {
|
|
10
|
-
if (explicit)
|
|
11
|
-
return { ref: explicit, showCloneHint: false };
|
|
12
|
-
const ref = defaultRef(version);
|
|
13
|
-
return { ref, showCloneHint: ref !== 'main' };
|
|
14
|
-
}
|