promptex-js 0.0.1-alpha.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 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 ADDED
@@ -0,0 +1,84 @@
1
+ # promptex-js(alpha 原型)
2
+
3
+ promptex 的 TypeScript 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
+ npm install promptex-js@alpha
20
+ ```
21
+
22
+ 需要 Node.js 22.14 以上。
23
+
24
+ ## 用法
25
+
26
+ 把宣告寫在 `prompts/` 下:
27
+
28
+ ```ts
29
+ // prompts/skill.ts
30
+ import { defineSkill } from 'promptex-js'
31
+
32
+ export const commitHelper = defineSkill({
33
+ id: 'commit-helper',
34
+ name: 'Commit 訊息協助',
35
+ config: { whenToUse: '當使用者要求撰寫 commit 訊息時使用' },
36
+ content: [
37
+ '依 Conventional Commits 撰寫:type(scope): subject。',
38
+ 'subject 用繁體中文、50 字內,不以句號結尾;body 說明變更動機而非變更內容。',
39
+ ],
40
+ })
41
+ ```
42
+
43
+ 建置:
44
+
45
+ ```bash
46
+ npx 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
+ `.ts` 宣告檔不需要先經過建置步驟,命令列工具靠 Node 的型別剝離直接載入。
63
+
64
+ ### 命令列選項
65
+
66
+ ```text
67
+ promptex build [--src <目錄>] [--out <目錄>]
68
+
69
+ --src <目錄> 宣告檔所在目錄,預設 prompts
70
+ --out <目錄> 產物輸出目錄,預設當前目錄
71
+ ```
72
+
73
+ ### 程式化呼叫
74
+
75
+ ```ts
76
+ import { build, defineSkill, renderSkill } from 'promptex-js'
77
+
78
+ defineSkill({ /* ... */ })
79
+ const written = await build('.')
80
+ ```
81
+
82
+ ## 授權
83
+
84
+ MIT OR Apache-2.0,見 `LICENSE-MIT` 與 `LICENSE-APACHE`。
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+ // promptex 命令列工具(alpha 原型)。
3
+ //
4
+ // 只有一個動詞:`build`。載入來源目錄下的宣告檔,把登記處內的 skill 投影
5
+ // 成 SKILL.md。正式版的其餘動詞(evaluate、declare、config、diagnostics)
6
+ // 不在本原型範圍內。
7
+
8
+ import { spawnSync } from 'node:child_process'
9
+ import { readdir, stat } from 'node:fs/promises'
10
+ import { join, resolve } from 'node:path'
11
+ import { pathToFileURL } from 'node:url'
12
+
13
+ const USAGE = `promptex(alpha 原型)
14
+
15
+ 用法:
16
+ promptex build [--src <目錄>] [--out <目錄>]
17
+
18
+ 選項:
19
+ --src <目錄> 宣告檔所在目錄,預設 prompts
20
+ --out <目錄> 產物輸出目錄,預設當前目錄
21
+ --help 顯示本說明
22
+ `
23
+
24
+ /** 宣告檔的副檔名。`.ts` 依賴 Node 的型別剝離,不經過額外的建置步驟。 */
25
+ const SOURCE_EXTENSIONS = ['.ts', '.mts', '.js', '.mjs']
26
+
27
+ function parseArgs(argv) {
28
+ const args = { verb: argv[0], src: 'prompts', out: '.' }
29
+ for (let i = 1; i < argv.length; i += 1) {
30
+ const flag = argv[i]
31
+ if (flag === '--src' || flag === '--out') {
32
+ const value = argv[i + 1]
33
+ if (value === undefined) throw new Error(`${flag} 後面缺少值`)
34
+ args[flag.slice(2)] = value
35
+ i += 1
36
+ } else {
37
+ throw new Error(`未知的選項:${flag}`)
38
+ }
39
+ }
40
+ return args
41
+ }
42
+
43
+ /** 遞迴列出來源目錄下的宣告檔,依路徑排序讓載入順序不隨檔案系統而變。 */
44
+ async function collectSources(dir) {
45
+ const entries = await readdir(dir, { withFileTypes: true })
46
+ const found = []
47
+ for (const entry of entries) {
48
+ const path = join(dir, entry.name)
49
+ if (entry.isDirectory()) found.push(...(await collectSources(path)))
50
+ else if (SOURCE_EXTENSIONS.some((ext) => entry.name.endsWith(ext))) found.push(path)
51
+ }
52
+ return found.sort()
53
+ }
54
+
55
+ async function main() {
56
+ const argv = process.argv.slice(2)
57
+ if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
58
+ process.stdout.write(USAGE)
59
+ return
60
+ }
61
+
62
+ const args = parseArgs(argv)
63
+ if (args.verb !== 'build') {
64
+ process.stderr.write(`未知的動詞:${args.verb}\n\n${USAGE}`)
65
+ process.exitCode = 1
66
+ return
67
+ }
68
+
69
+ const srcDir = resolve(args.src)
70
+ try {
71
+ if (!(await stat(srcDir)).isDirectory()) throw new Error('不是目錄')
72
+ } catch {
73
+ process.stderr.write(`找不到來源目錄:${srcDir}\n`)
74
+ process.exitCode = 1
75
+ return
76
+ }
77
+
78
+ const sources = await collectSources(srcDir)
79
+ if (sources.length === 0) {
80
+ process.stderr.write(`來源目錄沒有宣告檔(${SOURCE_EXTENSIONS.join('、')}):${srcDir}\n`)
81
+ process.exitCode = 1
82
+ return
83
+ }
84
+
85
+ // 載入宣告檔與呼叫 build 必須共用同一個模組實例,登記處才看得到宣告;
86
+ // 兩邊都經 `promptex-js` 的 dist 進入點解析,因此指向同一個模組。
87
+ const { build, declaredCount } = await import('../dist/index.js')
88
+ for (const source of sources) await import(pathToFileURL(source).href)
89
+
90
+ if (declaredCount() === 0) {
91
+ process.stderr.write(`載入了 ${sources.length} 份宣告檔,但沒有任何 skill 被宣告。\n`)
92
+ process.exitCode = 1
93
+ return
94
+ }
95
+
96
+ for (const path of await build(resolve(args.out))) process.stdout.write(`${path}\n`)
97
+ }
98
+
99
+ // Node 未內建型別剝離時(22.18 之前)以旗標重跑一次,讓 `.ts` 宣告檔不必
100
+ // 先經過建置步驟。已內建的版本不重跑,避免多開一個行程。
101
+ if (!process.features.typescript) {
102
+ const result = spawnSync(
103
+ process.execPath,
104
+ ['--experimental-strip-types', new URL(import.meta.url).pathname, ...process.argv.slice(2)],
105
+ { stdio: 'inherit' },
106
+ )
107
+ process.exit(result.status ?? 1)
108
+ } else {
109
+ await main().catch((error) => {
110
+ process.stderr.write(`${error.message}\n`)
111
+ process.exitCode = 1
112
+ })
113
+ }
@@ -0,0 +1,48 @@
1
+ /** skill 的觸發設定。 */
2
+ export interface SkillConfig {
3
+ /** 觸發語料,投影為產物 frontmatter 的 `description`。 */
4
+ whenToUse: string;
5
+ }
6
+ /** 一份 skill 的宣告。本原型只承載正式版 `SkillDef` 的最小子集。 */
7
+ export interface SkillDef {
8
+ /** 資源識別,同時是產物目錄名。 */
9
+ id: string;
10
+ /** 顯示名稱。 */
11
+ name: string;
12
+ /** 觸發設定。 */
13
+ config: SkillConfig;
14
+ /** 內容。單段用字串,多段用陣列,段落之間以空行分隔。 */
15
+ content: string | string[];
16
+ }
17
+ /** 宣告後回傳的引用。正式版以它承載節點間的引用關係,本原型只帶識別。 */
18
+ export interface Ref {
19
+ readonly kind: 'skill';
20
+ readonly id: string;
21
+ }
22
+ /**
23
+ * 宣告一份 skill。
24
+ *
25
+ * 宣告本身不寫檔;產物在 {@link build} 被呼叫時一次產出。
26
+ */
27
+ export declare function defineSkill(def: SkillDef): Ref;
28
+ /** 目前已登記的宣告數。供呼叫端在建置前自我核對用。 */
29
+ export declare const declaredCount: () => number;
30
+ /**
31
+ * 把一份 skill 投影成 SKILL.md 的完整內容。
32
+ *
33
+ * frontmatter 的 `name` 取 id 而非顯示名稱:平台側以 `name` 作為喚起時的識別。
34
+ */
35
+ export declare function renderSkill(skill: {
36
+ id: string;
37
+ whenToUse: string;
38
+ content: string[];
39
+ }): string;
40
+ /** 一份 skill 在輸出目錄下的產物路徑。 */
41
+ export declare const skillPath: (outDir: string, id: string) => string;
42
+ /**
43
+ * 把目前登記的全部宣告投影到輸出目錄,回傳產物路徑。
44
+ *
45
+ * 呼叫後登記處清空:同一行程內連續建置兩個輸出目錄時,第二次不該重複寫出
46
+ * 第一次的內容。
47
+ */
48
+ export declare function build(outDir: string): Promise<string[]>;
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ // promptex-js(alpha 原型):TypeScript SDK 的公開入口。
2
+ //
3
+ // 目前的能力只有一條路徑:宣告 skill,投影成 Claude Code 的 SKILL.md。
4
+ // 正式版的核心綁定、多平台投影、引用與關係圖都不在本原型範圍內。
5
+ import { mkdir, writeFile } from 'node:fs/promises';
6
+ import { dirname, join } from 'node:path';
7
+ // 模組層級的登記處:宣告散落在多個檔案時,逐一回傳並手動彙整會讓每個檔案
8
+ // 都得認識彙整點。正式版的收集語意相同。
9
+ const registry = [];
10
+ /**
11
+ * id 是否可安全作為單層目錄名。
12
+ *
13
+ * 產物路徑由 id 直接組成,不擋下來的話 `../` 這類值會把檔案寫到輸出目錄之外。
14
+ */
15
+ const isValidId = (id) => id.length > 0 && !id.includes('/') && !id.includes('\\') && id !== '.' && id !== '..';
16
+ /**
17
+ * 宣告一份 skill。
18
+ *
19
+ * 宣告本身不寫檔;產物在 {@link build} 被呼叫時一次產出。
20
+ */
21
+ export function defineSkill(def) {
22
+ if (!isValidId(def.id)) {
23
+ throw new Error(`skill id 不可為空、且不可含 \`/\`、\`\\\` 或 \`..\`:${JSON.stringify(def.id)}`);
24
+ }
25
+ registry.push({
26
+ id: def.id,
27
+ name: def.name,
28
+ whenToUse: def.config.whenToUse,
29
+ content: Array.isArray(def.content) ? def.content : [def.content],
30
+ });
31
+ return { kind: 'skill', id: def.id };
32
+ }
33
+ /** 目前已登記的宣告數。供呼叫端在建置前自我核對用。 */
34
+ export const declaredCount = () => registry.length;
35
+ /**
36
+ * 把一份 skill 投影成 SKILL.md 的完整內容。
37
+ *
38
+ * frontmatter 的 `name` 取 id 而非顯示名稱:平台側以 `name` 作為喚起時的識別。
39
+ */
40
+ export function renderSkill(skill) {
41
+ const header = `---\nname: ${skill.id}\ndescription: ${skill.whenToUse}\n---\n`;
42
+ return skill.content.length === 0 ? header : `${header}\n${skill.content.join('\n\n')}\n`;
43
+ }
44
+ /** 一份 skill 在輸出目錄下的產物路徑。 */
45
+ export const skillPath = (outDir, id) => join(outDir, '.claude', 'skills', id, 'SKILL.md');
46
+ /**
47
+ * 把目前登記的全部宣告投影到輸出目錄,回傳產物路徑。
48
+ *
49
+ * 呼叫後登記處清空:同一行程內連續建置兩個輸出目錄時,第二次不該重複寫出
50
+ * 第一次的內容。
51
+ */
52
+ export async function build(outDir) {
53
+ const skills = registry.splice(0, registry.length);
54
+ const written = [];
55
+ for (const skill of skills) {
56
+ const path = skillPath(outDir, skill.id);
57
+ await mkdir(dirname(path), { recursive: true });
58
+ await writeFile(path, renderSkill(skill), 'utf8');
59
+ written.push(path);
60
+ }
61
+ return written;
62
+ }
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "promptex-js",
3
+ "version": "0.0.1-alpha.1",
4
+ "description": "promptex 的 TypeScript SDK 最小原型(alpha):宣告 skill 並投影成 SKILL.md",
5
+ "license": "MIT OR Apache-2.0",
6
+ "author": "promptex-ai",
7
+ "homepage": "https://github.com/promptex-ai/promptex#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/promptex-ai/promptex.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/promptex-ai/promptex/issues"
14
+ },
15
+ "keywords": [
16
+ "prompt",
17
+ "prompt-engineering",
18
+ "ai",
19
+ "llm",
20
+ "agent",
21
+ "claude",
22
+ "skills",
23
+ "codegen"
24
+ ],
25
+ "type": "module",
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "bin": {
35
+ "promptex": "./bin/promptex.mjs"
36
+ },
37
+ "engines": {
38
+ "node": ">=22.14.0"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "bin",
43
+ "README.md",
44
+ "LICENSE-MIT",
45
+ "LICENSE-APACHE"
46
+ ],
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.json",
49
+ "prepack": "npm run build",
50
+ "test": "node --test 'test/*.test.mjs'"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^22.10.0",
54
+ "typescript": "^5.7.0"
55
+ }
56
+ }