create-promptex-js 1.0.0 → 1.1.0
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/README.md +102 -18
- package/dist/contract.generated.d.ts +24 -0
- package/dist/contract.generated.js +59 -0
- package/dist/index.js +356 -176
- package/dist/messages.generated.js +145 -61
- package/dist/plan.d.ts +105 -0
- package/dist/plan.js +327 -0
- package/package.json +3 -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
|
@@ -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
|
-
}
|