nx-kv 0.63.0 → 0.64.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/CHANGELOG.md +29 -0
- package/assets/nx-kv/references/A03-/346/226/207/346/241/243/344/270/216/345/275/222/345/261/236.md +6 -5
- package/package.json +2 -2
- package/src/core/attachmentdb/docs.ts +3 -6
- package/src/core/attachmentdb/query.ts +2 -2
- package/src/core/attachmentdb/relations.ts +36 -21
- package/src/core/db/import-json/refs.ts +17 -19
- package/src/core/db/import-json/repos.ts +4 -8
- package/src/core/db/migrations/index.ts +2 -0
- package/src/core/db/migrations/v13.sql +24 -0
- package/src/core/db/seed-templates.ts +15 -4
- package/src/core/db/version.ts +3 -1
- package/src/modules/docs/actions/_manifest.generated.ts +0 -3
- package/src/modules/docs/actions/doc-attach.ts +0 -1
- package/src/modules/docs/actions/docs-bindings.ts +2 -5
- package/src/modules/docs/actions/docs-link.ts +1 -2
- package/src/modules/docs/attach.ts +1 -36
- package/src/modules/docs/bound-docs.ts +2 -2
- package/src/modules/docs/brief.ts +0 -2
- package/src/modules/docs/docref.ts +7 -17
- package/src/modules/docs/knowledge-md.ts +1 -1
- package/src/modules/docs/knowledge.ts +48 -45
- package/src/modules/docs/ref-sync.ts +1 -5
- package/src/modules/docs/refs.ts +7 -10
- package/src/modules/docs/service.ts +1 -3
- package/src/modules/localtask/actions/localtask-config.ts +19 -58
- package/src/modules/localtask/actions/localtask-prune.ts +7 -2
- package/src/modules/localtask/repo/open.ts +0 -4
- package/src/modules/localtask/repo/settings.ts +20 -196
- package/src/modules/localtask/task-lifecycle.ts +7 -9
- package/src/modules/localtask/task-templates.ts +4 -4
- package/src/modules/localtask/task-view.ts +4 -0
- package/src/modules/localtask/topics.ts +30 -28
- package/src/modules/promptplug/actions/_manifest.generated.ts +0 -3
- package/src/modules/promptplug/actions/prompt-registry.ts +19 -30
- package/src/modules/promptplug/base.ts +69 -25
- package/src/modules/promptplug/compose.ts +40 -23
- package/src/modules/promptplug/factory.ts +91 -59
- package/src/modules/promptplug/index.ts +25 -11
- package/src/modules/promptplug/plugins/ack.ts +28 -0
- package/src/modules/promptplug/plugins/attachment.ts +237 -19
- package/src/modules/promptplug/plugins/context.ts +124 -30
- package/src/modules/promptplug/plugins/doneguard.ts +33 -0
- package/src/modules/promptplug/plugins/ext.ts +34 -11
- package/src/modules/promptplug/plugins/getloop.ts +29 -8
- package/src/modules/promptplug/plugins/goal-shape.ts +34 -0
- package/src/modules/promptplug/plugins/goalhint.ts +33 -0
- package/src/modules/promptplug/plugins/timecheck.ts +33 -0
- package/src/modules/promptplug/registry.ts +99 -0
- package/src/modules/promptplug/schema-bridge.ts +77 -13
- package/src/modules/repos/actions/board-rekey.ts +1 -1
- package/src/modules/repos/actions/repo-doc-add.ts +2 -3
- package/src/modules/repos/boards/core.ts +1 -13
- package/src/modules/repos/boards/docs.ts +2 -12
- package/src/modules/repos/boards/members.ts +2 -14
- package/src/modules/repos/boards/transfer.ts +2 -11
- package/src/modules/repos/keys.ts +4 -11
- package/src/modules/repos/repo/refs.ts +3 -5
- package/src/modules/repos/repo/repos.ts +12 -13
- package/src/modules/repos/repo/rows.ts +2 -8
- package/src/modules/repos/service/context.ts +0 -2
- package/src/modules/repos/service/crud.ts +1 -4
- package/src/modules/repos/service/store.ts +6 -7
- package/src/modules/repos/transfer/export.ts +3 -8
- package/src/modules/repos/transfer/import.ts +0 -13
- package/src/modules/repos/transfer/layout.ts +2 -2
- package/src/modules/tasktool/attach-template.ts +3 -3
- package/src/modules/tasktool/groupctx.ts +4 -5
- package/src/modules/tasktool/plugins/waitgoal-config.ts +5 -6
- package/src/modules/tasktool/preview.ts +20 -23
- package/src/modules/tasktool/wait.ts +24 -46
- package/src/modules/templates/actions/_manifest.generated.ts +3 -0
- package/src/modules/templates/actions/templates-reorder.ts +28 -0
- package/src/modules/templates/repo/templates.ts +32 -2
- package/src/modules/templates/service.ts +45 -0
- package/src/shared/prompt-blocks.ts +7 -173
- package/src/shared/prompt-plugin.ts +79 -59
- package/src/web/frontend/App.tsx +27 -1
- package/src/web/frontend/api/cli-tree.json +20 -35
- package/src/web/frontend/api/client.generated.ts +22 -32
- package/src/web/frontend/components/Introduction/rail.tsx +2 -2
- package/src/web/frontend/components/Introduction/use-intro.ts +2 -5
- package/src/web/frontend/components/bindings/bind-tags.tsx +1 -3
- package/src/web/frontend/components/list-search.tsx +37 -0
- package/src/web/frontend/components/md/attach-area.tsx +10 -15
- package/src/web/frontend/components/md/live-block.tsx +5 -14
- package/src/web/frontend/components/md/md-panes.tsx +3 -19
- package/src/web/frontend/modules/list-filter.ts +37 -0
- package/src/web/frontend/modules/md/fill-session.ts +36 -0
- package/src/web/frontend/modules/md/manage-session.ts +24 -0
- package/src/web/frontend/modules/md/new-task-from-template.ts +22 -0
- package/src/web/frontend/modules/md/styles/editor.css +5 -12
- package/src/web/frontend/modules/md/styles/shell.css +4 -0
- package/src/web/frontend/modules/md/task-intent.ts +29 -0
- package/src/web/frontend/modules/md/use-templates.ts +8 -0
- package/src/web/frontend/modules/prompts/template-preview.ts +12 -20
- package/src/web/frontend/modules/refs/api.ts +0 -1
- package/src/web/frontend/page/dir/index.tsx +20 -5
- package/src/web/frontend/page/dir/task-actions.ts +14 -0
- package/src/web/frontend/page/dir/task-preview-modal.tsx +1 -1
- package/src/web/frontend/page/dir/task.tsx +19 -0
- package/src/web/frontend/page/doc/api.ts +2 -3
- package/src/web/frontend/page/doc/bindings.tsx +46 -16
- package/src/web/frontend/page/doc/index.tsx +3 -4
- package/src/web/frontend/page/group/index.tsx +65 -117
- package/src/web/frontend/page/refs/index.tsx +27 -3
- package/src/web/frontend/page/refs/style.css +3 -0
- package/src/web/frontend/page/repos/bind-modals.tsx +18 -2
- package/src/web/frontend/page/repos/board-admin.tsx +1 -1
- package/src/web/frontend/page/repos/index.tsx +4 -8
- package/src/web/frontend/page/repos/ref-block.tsx +5 -12
- package/src/web/frontend/page/repos/ref-panel.tsx +3 -4
- package/src/web/frontend/page/repos/repo-form-modal.tsx +1 -8
- package/src/web/frontend/page/repos/repo-table.tsx +4 -29
- package/src/web/frontend/page/repos/use-repos-derive.ts +4 -5
- package/src/web/frontend/page/settings/api.ts +7 -15
- package/src/web/frontend/page/settings/prompt-templates-section.tsx +261 -289
- package/src/web/frontend/page/settings/prompt-vars.ts +56 -0
- package/src/web/frontend/page/settings/style.css +46 -64
- package/src/web/frontend/page/templates/fill.tsx +124 -0
- package/src/web/frontend/page/templates/index.tsx +11 -0
- package/src/web/frontend/page/templates/manage.tsx +218 -0
- package/src/web/frontend/page/templates/style.css +46 -0
- package/src/web/frontend/page/templates/template-list.tsx +58 -54
- package/src/web/frontend/refs/api.ts +0 -2
- package/src/web/frontend/routes/route-eq.ts +22 -0
- package/src/web/frontend/routes/templates.ts +20 -0
- package/src/web/frontend/style.css +1 -0
- package/src/web/frontend/styles/list-search.css +44 -0
- package/src/web/frontend/types.ts +5 -1
- package/src/web/public/assets/{bar-CYWfxHfm.js → bar-j14ON7uZ.js} +1 -1
- package/src/web/public/assets/{composer-launch-Bor4ngrQ.js → composer-launch-DRi9mZE1.js} +1 -1
- package/src/web/public/assets/{composer-panel-C7mNI7EW.js → composer-panel-swmDqlPw.js} +1 -1
- package/src/web/public/assets/dir-DhsB1ZhL.js +3 -0
- package/src/web/public/assets/doc-D4po3sDc.js +6 -0
- package/src/web/public/assets/fill-session-fHxQHFaD.js +1 -0
- package/src/web/public/assets/group-BxmSNzIB.js +1 -0
- package/src/web/public/assets/index-CMjG5NVU.js +2 -0
- package/src/web/public/assets/index-uMjSWNVr.css +1 -0
- package/src/web/public/assets/list-filter-D-x94TvA.js +1 -0
- package/src/web/public/assets/manage-session-CS8UvmUd.js +1 -0
- package/src/web/public/assets/md-history-CZUF_FhN.js +39 -0
- package/src/web/public/assets/new-task-from-template-DDWu4yR4.js +1 -0
- package/src/web/public/assets/refs-TuuoaRs7.js +2 -0
- package/src/web/public/assets/refs-zSA2k_45.css +1 -0
- package/src/web/public/assets/render-template-body-bXdedFig.js +1 -0
- package/src/web/public/assets/repo-form-modal-BD4N37MI.js +1 -0
- package/src/web/public/assets/repos-BPeuX4N9.js +12 -0
- package/src/web/public/assets/settings-CZJaKLZW.js +1 -0
- package/src/web/public/assets/settings-Cc6puKd5.css +1 -0
- package/src/web/public/assets/task-DgbbF5gy.js +11 -0
- package/src/web/public/assets/task-intent-CX5DZccN.js +1 -0
- package/src/web/public/assets/{task-utils-DpnPjZKJ.js → task-utils-bJH1-Cjy.js} +1 -1
- package/src/web/public/assets/templates-CBXlwyof.js +11 -0
- package/src/web/public/assets/templates-plA8R7jJ.css +1 -0
- package/src/web/public/assets/use-rail-drag-ufwy2XZB.js +1 -0
- package/src/web/public/index.html +8 -6
- package/src/modules/docs/actions/doc-attach-note.ts +0 -32
- package/src/modules/promptplug/Template/blockTemplates.json +0 -90
- package/src/modules/promptplug/actions/prompt-order.ts +0 -38
- package/src/modules/promptplug/ensure.ts +0 -57
- package/src/modules/promptplug/keys.ts +0 -9
- package/src/modules/promptplug/plugins/readonly-blocks.ts +0 -75
- package/src/modules/promptplug/template-bundle.ts +0 -59
- package/src/web/frontend/modules/md/template-locks.ts +0 -105
- package/src/web/frontend/page/settings/prompt-editor.tsx +0 -279
- package/src/web/frontend/page/settings/prompt-rail.tsx +0 -170
- package/src/web/public/assets/dir-CcffxXL2.js +0 -3
- package/src/web/public/assets/doc-BxWVzWkw.js +0 -6
- package/src/web/public/assets/group-C5Yu3oJr.js +0 -1
- package/src/web/public/assets/index-BvyZ1MA2.js +0 -2
- package/src/web/public/assets/index-Cp-TtHyA.css +0 -1
- package/src/web/public/assets/md-history-DejKuR12.js +0 -39
- package/src/web/public/assets/refs-DJdKV8_H.css +0 -1
- package/src/web/public/assets/refs-VbDnDTV0.js +0 -2
- package/src/web/public/assets/repo-form-modal-Dkdvu_uN.js +0 -1
- package/src/web/public/assets/repos-CY0eZheu.js +0 -16
- package/src/web/public/assets/settings-AwzLRYUu.css +0 -1
- package/src/web/public/assets/settings-D3T-vgCl.js +0 -1
- package/src/web/public/assets/task-CkCD82h_.js +0 -11
- package/src/web/public/assets/templates-BcuCbT4U.js +0 -10
- package/src/web/public/assets/templates-gNdtaMI2.css +0 -1
- package/src/web/public/assets/use-rail-drag-DMvr8-GE.js +0 -1
|
@@ -1,45 +1,79 @@
|
|
|
1
|
-
// PromptPlugin
|
|
1
|
+
// PromptPlugin 基类(#152 重构版)。
|
|
2
2
|
//
|
|
3
|
-
// 子类只写:id / order / tag / label / dataSchema
|
|
4
|
-
// 模板正文不进代码——构造注入(模板唯一真相是 DB 的 lt.blockTemplates)。
|
|
3
|
+
// 子类只写:id / order / group / tag / label / dataSchema / templates / buildData()。
|
|
5
4
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
5
|
+
// #152 的三条变化(用户口径):
|
|
6
|
+
// 1. **模板进类**:每个实现必须给出 `templates` —— 内置模板列表。正文唯一真相
|
|
7
|
+
// 就是这里的 TS 常量,不再有 Template/blockTemplates.json、不再 seed 进 DB。
|
|
8
|
+
// 2. **group 化**:每个实现必须给出 `group`(get / check / done),compose 按
|
|
9
|
+
// group 取整条链,链内按 order 排序 —— 触发一个时机 = 跑完这一组。
|
|
10
|
+
// 3. **数据自建**:`buildData()` 收在子类里,宿主只给 `Supply`(值或惰性函数)。
|
|
11
|
+
// 想发 HTTP 拉云端提示词就自己在这里发;没有中心化的大对象 builder。
|
|
12
|
+
//
|
|
13
|
+
// 两个 schema 名字的分工不变:
|
|
14
|
+
// - dataSchema(子类声明):zod 书写层,buildData() 返回形状 + 变量目录来源;
|
|
15
|
+
// - schema(注册面,本类派生):schema-bridge 折算后的纯数据 PluginSchema<unknown>。
|
|
10
16
|
//
|
|
11
17
|
// 铁律:
|
|
12
|
-
// - get 是唯一出口:无参 = 文本态;'data' =
|
|
18
|
+
// - get 是唯一出口:无参 = 文本态;'data' = 结构态。子类不得重写;
|
|
13
19
|
// - 运行时判别靠字面量 'data',不靠泛型(泛型擦除);泛型只把结构态收窄到 T;
|
|
14
|
-
// -
|
|
15
|
-
// - dataSchema 必须 z.strictObject
|
|
16
|
-
// 静默删掉,撞车校验与变量白名单全部失效(见方案 §1.4 边界 2)。
|
|
20
|
+
// - buildData() 校验只在 get('data') 出口发生一次(safeParse),运行期不兜底;
|
|
21
|
+
// - dataSchema 必须 z.strictObject(strip 会让撞车校验与变量白名单失效)。
|
|
17
22
|
import { z } from 'zod';
|
|
18
23
|
import type { AnyPromptPlugin, PluginSchema } from '../../shared/prompt-plugin.js';
|
|
19
24
|
import { pluginSchemaOf } from './schema-bridge.js';
|
|
20
25
|
|
|
26
|
+
/** 触发时机 = 链名。一个 group 是一条链,链内按 order 升序渲染。 */
|
|
27
|
+
export type PluginGroup = 'get' | 'check' | 'done';
|
|
28
|
+
|
|
29
|
+
/** 全部时机(顺序 = 注册表展示顺序)。 */
|
|
30
|
+
export const PLUGIN_GROUPS: readonly PluginGroup[] = ['get', 'check', 'done'];
|
|
31
|
+
|
|
32
|
+
/** 内置模板条目:正文进代码,id/name 只用于展示与追溯。 */
|
|
33
|
+
export interface TemplateText {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
/** 模板正文(Handlebars 子集,见 core/instruction-template.ts) */
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 惰性供给:宿主可以给值,也可以给「算的时候再调」的函数。
|
|
42
|
+
* 后者用于省掉构建期没有消费者时的无效拷贝(也允许异步——留给 HTTP 类取数)。
|
|
43
|
+
*/
|
|
44
|
+
export type Supply<T> = T | (() => T | Promise<T>);
|
|
45
|
+
|
|
46
|
+
/** 解析一个 Supply(值直接返回,函数则调用并 await)。 */
|
|
47
|
+
export async function supplied<T>(v: Supply<T>): Promise<T> {
|
|
48
|
+
return typeof v === 'function' ? await (v as () => T | Promise<T>)() : v;
|
|
49
|
+
}
|
|
50
|
+
|
|
21
51
|
export abstract class PromptPlugin<S extends z.ZodObject<z.ZodRawShape>>
|
|
22
52
|
implements AnyPromptPlugin {
|
|
23
53
|
|
|
24
54
|
abstract readonly id: string;
|
|
25
|
-
/**
|
|
55
|
+
/** 链内顺序(同一 group 内必须唯一;跨组不要求) */
|
|
26
56
|
abstract readonly order: number;
|
|
57
|
+
/** ★ 触发时机:compose 按它取整条链 */
|
|
58
|
+
abstract readonly group: PluginGroup;
|
|
27
59
|
/** 类 XML 输出标签('nx-kv.context' 等) */
|
|
28
60
|
abstract readonly tag: string;
|
|
29
61
|
abstract readonly label: string;
|
|
30
|
-
/** ★ data 形状(zod 书写层):可写段 required + seed 段 optional;
|
|
62
|
+
/** ★ data 形状(zod 书写层):可写段 required + seed 段 optional;buildData() 返回只含可写段 */
|
|
31
63
|
abstract readonly dataSchema: S;
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
64
|
+
/**
|
|
65
|
+
* ★ 内置模板列表(至少一条,第一条 = 出厂默认)。
|
|
66
|
+
* 正文进代码后,「模板从哪来」这件事只剩一个答案,不会再出现常量 ≡ JSON ≡ DB 的三角漂移。
|
|
67
|
+
*/
|
|
68
|
+
abstract readonly templates: readonly TemplateText[];
|
|
69
|
+
/** 显式覆盖正文(预览 / 测试用;正常流程走 templates[0])。 */
|
|
70
|
+
private readonly overrideText: string;
|
|
37
71
|
|
|
38
72
|
/** 注册面 schema(惰性派生一次:构造体内子类字段尚未初始化,不能在 super 里算) */
|
|
39
73
|
private registered: PluginSchema<unknown> | null = null;
|
|
40
74
|
|
|
41
|
-
constructor(
|
|
42
|
-
this.
|
|
75
|
+
constructor(text = '') {
|
|
76
|
+
this.overrideText = String(text ?? '');
|
|
43
77
|
}
|
|
44
78
|
|
|
45
79
|
/** 注册面:纯数据 PluginSchema(fields / blank),派生一次缓存 */
|
|
@@ -48,21 +82,31 @@ export abstract class PromptPlugin<S extends z.ZodObject<z.ZodRawShape>>
|
|
|
48
82
|
return this.registered;
|
|
49
83
|
}
|
|
50
84
|
|
|
51
|
-
/**
|
|
52
|
-
protected
|
|
85
|
+
/** 当前生效模板正文:显式覆盖优先,否则第一条内置模板。 */
|
|
86
|
+
protected activeTemplate(): string {
|
|
87
|
+
if (this.overrideText) return this.overrideText;
|
|
88
|
+
const first = this.templates[0];
|
|
89
|
+
return String((first && first.text) || '');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 子类只写这一处:自己取数 / 自己拼数据对象。
|
|
94
|
+
* 需要宿主材料的,从构造时拿到的 `Supply` 里 await supplied()。
|
|
95
|
+
*/
|
|
96
|
+
protected abstract buildData(): z.infer<S> | Promise<z.infer<S>>;
|
|
53
97
|
|
|
54
98
|
/** 唯一出口:无参 = 文本态;传 'data' = 结构态(校验只在这里发生一次) */
|
|
55
99
|
get<T extends z.infer<S> = z.infer<S>>(as: 'data'): Promise<T>;
|
|
56
100
|
get(): string;
|
|
57
101
|
get(as?: 'data'): string | Promise<z.infer<S>> {
|
|
58
|
-
if (as !== 'data') return this.
|
|
59
|
-
return Promise.resolve(this.
|
|
102
|
+
if (as !== 'data') return this.activeTemplate();
|
|
103
|
+
return Promise.resolve(this.buildData()).then((raw) => {
|
|
60
104
|
const r = this.dataSchema.safeParse(raw);
|
|
61
105
|
if (!r.success) {
|
|
62
106
|
const issues = r.error.issues
|
|
63
107
|
.map((i) => `${i.path.join('.') || '(根)'} ${i.message}`)
|
|
64
108
|
.join(';');
|
|
65
|
-
throw new Error(`${this.id}:
|
|
109
|
+
throw new Error(`${this.id}: buildData() 返回与 schema 不符——${issues}`);
|
|
66
110
|
}
|
|
67
111
|
return r.data;
|
|
68
112
|
});
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
// 编排 compose
|
|
2
|
-
// 顺序 →
|
|
3
|
-
//
|
|
4
|
-
// 是否出段 → 渲染结果 trim()
|
|
5
|
-
// 失败 →
|
|
1
|
+
// 编排 compose(#152 按时机链;#153 取消共享 ctx)——四种语义各只有一处答案:
|
|
2
|
+
// 顺序 → 链内按插件 order 升序(chainOf;顺序不再落库)
|
|
3
|
+
// 数据 → **每段一份自己的 ctx**:seed + 本段 buildData() 的产出,用完即弃
|
|
4
|
+
// 是否出段 → 渲染结果 trim() 为空即不出
|
|
5
|
+
// 失败 → buildData()/渲染抛错 = 整次交付失败,不吞、不回落(运行期不兜底)
|
|
6
6
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
7
|
+
// 为什么不再 Object.assign 出一个大 ctx:那样每段的模板就能偷偷引用别的段的变量
|
|
8
|
+
// (渲染顺序变成隐式依赖),白名单也被迫用「全局段集」放行跨段耦合。
|
|
9
|
+
// 现在「谁的数据给谁用」是硬边界,跨段引用在启动期就被 assertPluginList 拒。
|
|
10
|
+
//
|
|
11
|
+
// group 是硬闸门:传 'get' 就只跑 get 链,'check'/'done' 同理——
|
|
12
|
+
// 一个时机 = 一条链,链内顺序 = 插件类声明的 order。
|
|
13
|
+
//
|
|
14
|
+
// 一次触发可以要**多条链**(`groups`):交付就是这样——领取(get)时也要把
|
|
15
|
+
// 「每轮检查该做什么」(check)一并给出,否则 agent 永远看不到那段。多链合并后
|
|
16
|
+
// 仍按各类声明的 order 全局排序,所以「get+check」与旧的单链顺序逐段一致。
|
|
11
17
|
import { renderInstruction } from '../../core/instruction-template.js';
|
|
12
18
|
import { wrapXmlBlocks, type XmlBlockPart } from '../../shared/prompt-blocks.js';
|
|
13
|
-
import { assertPluginList,
|
|
19
|
+
import { assertPluginList, chainOf, type AnyPromptPlugin } from '../../shared/prompt-plugin.js';
|
|
20
|
+
import { assertRegistry } from './registry.js';
|
|
14
21
|
|
|
15
22
|
/** 预览用分段记录(与旧 system-blocks 同形,调用方无感)。 */
|
|
16
23
|
export interface RenderTraceEntry {
|
|
@@ -39,8 +46,10 @@ export interface SegmentMeta {
|
|
|
39
46
|
|
|
40
47
|
export interface ComposeOptions {
|
|
41
48
|
plugins: readonly AnyPromptPlugin[];
|
|
42
|
-
/**
|
|
43
|
-
|
|
49
|
+
/** 触发时机(链名):只跑这一条链(与 groups 二选一) */
|
|
50
|
+
group?: string;
|
|
51
|
+
/** 一次触发多条链(按 order 全局排序后合并;交付 = ['get','check']) */
|
|
52
|
+
groups?: readonly string[];
|
|
44
53
|
/** compose 的种子数据:task / cwd / goal / source / summary / name / params */
|
|
45
54
|
seed?: Record<string, unknown>;
|
|
46
55
|
mode?: 'xml' | 'plain';
|
|
@@ -50,25 +59,33 @@ export interface ComposeOptions {
|
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
/**
|
|
53
|
-
*
|
|
62
|
+
* 组装一条时机链的 instruction:按链内 order 取数合并 → 渲染 → 包标签。
|
|
54
63
|
* 返回 ''(无可输出段落)时调用方省略 instruction。
|
|
55
64
|
*/
|
|
56
65
|
export async function compose(opts: ComposeOptions): Promise<string> {
|
|
57
|
-
const { plugins, seed = {}, mode = 'xml', trace, segments } = opts;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
66
|
+
const { plugins, group, groups, seed = {}, mode = 'xml', trace, segments } = opts;
|
|
67
|
+
const wanted = groups && groups.length ? groups : group ? [group] : [];
|
|
68
|
+
if (!wanted.length) throw new Error('compose: 必须指定 group 或 groups');
|
|
69
|
+
const chain =
|
|
70
|
+
wanted.length === 1
|
|
71
|
+
? chainOf(plugins, wanted[0]!)
|
|
72
|
+
: wanted.flatMap((g) => chainOf(plugins, g)).sort((a, b) => a.order - b.order);
|
|
73
|
+
// 全量不变量(id / 链内 order / 模板非空 / 模板只引用自己的变量)只校验一次;
|
|
74
|
+
// 链内只保留本次要渲染的段。
|
|
75
|
+
assertRegistry();
|
|
76
|
+
assertPluginList(chain);
|
|
61
77
|
const segOf = new Map<string, SegmentMeta>((segments || []).map((s) => [s.id, s]));
|
|
62
78
|
|
|
63
|
-
const ctx: Record<string, unknown> = { ...seed };
|
|
64
|
-
for (const id of orderIds) Object.assign(ctx, await byId.get(id)!.get('data'));
|
|
65
|
-
|
|
66
79
|
const parts: XmlBlockPart[] = [];
|
|
67
|
-
for (const
|
|
68
|
-
const p = byId.get(id)!;
|
|
80
|
+
for (const p of chain) {
|
|
69
81
|
const template = p.get();
|
|
70
82
|
if (!String(template ?? '').trim()) continue;
|
|
71
|
-
|
|
83
|
+
// 每段的数据域 = seed + 本段产出;不向后传、也不接受别人传进来。
|
|
84
|
+
// seed 放在后面:任务本体 / 时间目标这些「宿主权威数据」不许被某段的 buildData 覆盖
|
|
85
|
+
// (段只能补充自己的段,不能改写 task.id 这类身份字段)。
|
|
86
|
+
const data = (await p.get('data')) as Record<string, unknown> | null | undefined;
|
|
87
|
+
const scope: Record<string, unknown> = { ...(data || {}), ...seed };
|
|
88
|
+
const text = renderInstruction(template, scope).trim();
|
|
72
89
|
if (!text) continue;
|
|
73
90
|
parts.push({ id: p.id, tag: p.tag, text });
|
|
74
91
|
if (trace) {
|
|
@@ -1,55 +1,96 @@
|
|
|
1
|
-
// promptplug
|
|
1
|
+
// promptplug 插件工厂:按**时机链**构造插件 + 字段目录 + 白名单数据源(#152)。
|
|
2
2
|
//
|
|
3
3
|
// 单独成文件的原因:actions/ 下的 action 经 _manifest.generated.ts 被 index.ts
|
|
4
4
|
// 装配,若 action 反向 import index.js 就形成 TDZ 回环——工厂是 actions 与
|
|
5
5
|
// tasktool 共同的依赖终点,不含任何装配代码。
|
|
6
6
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// 依赖方向(设计内):tasktool 是唯一消费方——领域取数(readGroupContext /
|
|
8
|
+
// attachTemplateCtx / pendingQueueInfo / getloop 指令渲染)由宿主完成,以 `Supply`
|
|
9
|
+
// 形式交给插件;插件在自己的 buildData() 里 await supplied() 后只做变换。
|
|
10
|
+
// promptplug 不 import 其他模块。
|
|
11
|
+
//
|
|
12
|
+
// #152 起模板不再注入:每个插件类的 `templates` 就是它的正文,构造只传 overrides(预览/测试用)。
|
|
10
13
|
import type { AnyPromptPlugin } from '../../shared/prompt-plugin.js';
|
|
14
|
+
import type { PluginGroup, Supply } from './base.js';
|
|
11
15
|
import { ContextPlugin } from './plugins/context.js';
|
|
12
16
|
import { AttachmentPlugin } from './plugins/attachment.js';
|
|
13
17
|
import { ExtPlugin } from './plugins/ext.js';
|
|
14
18
|
import { GetloopPlugin } from './plugins/getloop.js';
|
|
15
|
-
import { AckPlugin
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
import { AckPlugin } from './plugins/ack.js';
|
|
20
|
+
import { DoneguardPlugin } from './plugins/doneguard.js';
|
|
21
|
+
import { GoalhintPlugin } from './plugins/goalhint.js';
|
|
22
|
+
import { TimecheckPlugin } from './plugins/timecheck.js';
|
|
23
|
+
import { varScopeOf as varScopeOfFields } from '../../shared/prompt-plugin.js';
|
|
24
|
+
import { allPluginIds, groupPluginIds, pluginMeta } from './registry.js';
|
|
19
25
|
|
|
20
|
-
/**
|
|
26
|
+
/** 交付插件构造所需的宿主取数(值或惰性函数;异步留给 HTTP 类取数)。 */
|
|
21
27
|
export interface DeliveryPluginDeps {
|
|
22
|
-
groupCtx: unknown
|
|
23
|
-
attach: unknown
|
|
24
|
-
queueInfo: { topic: string; count: number; list: { id: number; title: string }[] } | null
|
|
25
|
-
loopText: string
|
|
26
|
-
waitMinutes: number
|
|
28
|
+
groupCtx: Supply<unknown>;
|
|
29
|
+
attach: Supply<unknown>;
|
|
30
|
+
queueInfo: Supply<{ topic: string; count: number; list: { id: number; title: string }[] } | null>;
|
|
31
|
+
loopText: Supply<string>;
|
|
32
|
+
waitMinutes: Supply<number>;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
/**
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
/** 空 deps(只出声明面 / 预览占位时用)。 */
|
|
36
|
+
export const EMPTY_DEPS: DeliveryPluginDeps = {
|
|
37
|
+
groupCtx: null,
|
|
38
|
+
attach: null,
|
|
39
|
+
queueInfo: null,
|
|
40
|
+
loopText: '',
|
|
41
|
+
waitMinutes: 0,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 正文覆盖(模板预览 / 测试):id → 模板正文;不给就用类里的内置模板。 */
|
|
45
|
+
export type TemplateOverrides = Record<string, string | undefined>;
|
|
46
|
+
|
|
47
|
+
/** 按时机链构造插件(链内已按 order 升序)。 */
|
|
48
|
+
export function buildPlugins(
|
|
49
|
+
group: PluginGroup,
|
|
50
|
+
deps: Partial<DeliveryPluginDeps> = {},
|
|
51
|
+
overrides: TemplateOverrides = {},
|
|
33
52
|
): AnyPromptPlugin[] {
|
|
34
|
-
const
|
|
53
|
+
const d = { ...EMPTY_DEPS, ...deps };
|
|
54
|
+
const text = (id: string): string => String(overrides[id] ?? '');
|
|
55
|
+
switch (group) {
|
|
56
|
+
case 'get':
|
|
57
|
+
return [
|
|
58
|
+
new ContextPlugin(text('context'), { groupCtx: d.groupCtx }),
|
|
59
|
+
new AttachmentPlugin(text('attachment'), { attach: d.attach }),
|
|
60
|
+
new ExtPlugin(text('ext'), { queueInfo: d.queueInfo }),
|
|
61
|
+
new AckPlugin(text('ack')),
|
|
62
|
+
new GetloopPlugin(text('getloop'), { loopText: d.loopText, waitMinutes: d.waitMinutes }),
|
|
63
|
+
];
|
|
64
|
+
case 'check':
|
|
65
|
+
return [new TimecheckPlugin(text('timecheck')), new GoalhintPlugin(text('goalhint'))];
|
|
66
|
+
case 'done':
|
|
67
|
+
return [new DoneguardPlugin(text('doneguard'))];
|
|
68
|
+
default:
|
|
69
|
+
throw new Error(`未知提示词时机:${String(group)}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 全部时机的插件(注册表 / 设置页用;不取数)。 */
|
|
74
|
+
export function buildAllPlugins(overrides: TemplateOverrides = {}): AnyPromptPlugin[] {
|
|
35
75
|
return [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
new GoalhintPlugin(t('goalhint')),
|
|
40
|
-
new DoneguardPlugin(t('doneguard')),
|
|
41
|
-
new ExtPlugin(t('ext'), { queueInfo: deps.queueInfo }),
|
|
42
|
-
new AckPlugin(t('ack')),
|
|
43
|
-
new GetloopPlugin(t('getloop'), { loopText: deps.loopText, waitMinutes: deps.waitMinutes }),
|
|
76
|
+
...buildPlugins('get', {}, overrides),
|
|
77
|
+
...buildPlugins('check', {}, overrides),
|
|
78
|
+
...buildPlugins('done', {}, overrides),
|
|
44
79
|
];
|
|
45
80
|
}
|
|
46
81
|
|
|
47
82
|
export { deliveryCtxOf } from './plugins/context.js';
|
|
48
83
|
|
|
49
|
-
// ──
|
|
84
|
+
// ── 校验用的数据源 ─────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
/** seed 段(宿主在 run 时传入的那份数据;每段都有一份,只读)。唯一真相在 shared。 */
|
|
87
|
+
export { SEED_SEGMENTS } from '../../shared/prompt-plugin.js';
|
|
50
88
|
|
|
51
|
-
/**
|
|
52
|
-
export const
|
|
89
|
+
/** 全部交付插件 id(按时机链 + 链内 order 的稳定序)。 */
|
|
90
|
+
export const PLUGIN_IDS: readonly string[] = Object.freeze(allPluginIds());
|
|
91
|
+
|
|
92
|
+
/** 某时机的链 id(按 order)。 */
|
|
93
|
+
export { groupPluginIds };
|
|
53
94
|
|
|
54
95
|
const fieldCache = new Map<string, { fields: string[]; top: string[] }>();
|
|
55
96
|
|
|
@@ -57,49 +98,40 @@ const fieldCache = new Map<string, { fields: string[]; top: string[] }>();
|
|
|
57
98
|
export function fieldCatalogOf(id: string): { fields: string[]; top: string[] } {
|
|
58
99
|
const hit = fieldCache.get(id);
|
|
59
100
|
if (hit) return hit;
|
|
60
|
-
const p =
|
|
101
|
+
const p = pluginMeta(id);
|
|
61
102
|
if (!p) throw new Error(`未知提示词插件:${id}`);
|
|
62
103
|
const fields = p.schema.fields.map((f) => f.key);
|
|
63
|
-
const top = [...new Set(fields.map((
|
|
104
|
+
const top = [...new Set(fields.map((k) => k.split('.')[0]!.replace(/\[\]$/, '')))];
|
|
64
105
|
const out = { fields, top };
|
|
65
106
|
fieldCache.set(id, out);
|
|
66
107
|
return out;
|
|
67
108
|
}
|
|
68
109
|
|
|
69
|
-
/** 按模板注入构造单个插件(fields / writes 与模板正文无关,空串即可)。 */
|
|
70
|
-
function pluginById(id: string): AnyPromptPlugin | undefined {
|
|
71
|
-
const t = '';
|
|
72
|
-
const deps = { groupCtx: null, attach: null, queueInfo: null, loopText: '', waitMinutes: 0 };
|
|
73
|
-
return buildDeliveryPlugins({ [id]: { template: t } }, deps).find((x) => x.id === id);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
110
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
111
|
+
* 某一段可见的变量域(**不再有全局段集**):seed ∪ 本段 dataSchema 顶层。
|
|
112
|
+
*
|
|
113
|
+
* 旧实现是「全局段集 + 全部字段并集」——那等于允许 a 段引用 b 段的变量,
|
|
114
|
+
* 跨段耦合被白名单亲手放行。#153 起每段只看自己的数据,白名单与运行期同域。
|
|
81
115
|
*/
|
|
82
|
-
export function
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const p = pluginById(id)!;
|
|
87
|
-
for (const w of p.writes) segments.add(w);
|
|
88
|
-
const { fields, top } = fieldCatalogOf(id);
|
|
89
|
-
for (const t of top) segments.add(t);
|
|
90
|
-
for (const f of fields) keys.add(f);
|
|
91
|
-
}
|
|
92
|
-
return { allowedSegments: [...segments], fieldKeys: [...keys] };
|
|
116
|
+
export function varScopeOf(id: string): { allowedSegments: string[]; fieldKeys: string[] } {
|
|
117
|
+
const p = pluginMeta(id);
|
|
118
|
+
if (!p) throw new Error(`未知提示词插件:${id}`);
|
|
119
|
+
return varScopeOfFields(id, p.schema.fields);
|
|
93
120
|
}
|
|
94
121
|
|
|
95
|
-
/**
|
|
96
|
-
export
|
|
97
|
-
|
|
98
|
-
]
|
|
122
|
+
/** shared 的实现(assertPluginList 直接吃 fields,省一次查表)。 */
|
|
123
|
+
export { varScopeOf as varScopeOfFields };
|
|
124
|
+
|
|
125
|
+
/** 某插件当前生效的模板正文(#152:就是类里 templates[0])。 */
|
|
126
|
+
export function activeTemplateOf(id: string): string {
|
|
127
|
+
const p = pluginMeta(id);
|
|
128
|
+
if (!p) throw new Error(`未知提示词插件:${id}`);
|
|
129
|
+
return p.get();
|
|
130
|
+
}
|
|
99
131
|
|
|
100
132
|
/** 区块显示名(错误消息 / 设置页 tab 用)——从插件 label 派生,不写第二份。 */
|
|
101
133
|
export function blockLabelOf(id: string): string {
|
|
102
|
-
const p =
|
|
134
|
+
const p = pluginMeta(id);
|
|
103
135
|
if (!p) throw new Error(`未知提示词插件:${id}`);
|
|
104
136
|
return p.label;
|
|
105
137
|
}
|
|
@@ -1,30 +1,44 @@
|
|
|
1
|
-
// promptplug 装配:模块元信息 + action
|
|
1
|
+
// promptplug 装配:模块元信息 + action 清单装配。
|
|
2
2
|
//
|
|
3
|
-
// 插件工厂 /
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// 插件工厂 / 注册表 / 字段目录在 factory.ts + registry.ts(actions 经 manifest 引
|
|
4
|
+
// 工厂,不能回环引本文件)。依赖方向(设计内):tasktool 是唯一消费方——宿主完成
|
|
5
|
+
// 领域取数,以 Supply 形式注入插件;插件在自己的 buildData() 里变换。
|
|
6
6
|
// promptplug 不 import 其他模块。
|
|
7
7
|
import { ModuleBase } from '../../runtime/types/module.js';
|
|
8
8
|
import { zodActionsOf, type ZodBoundAction } from '../../runtime/action-decorator.js';
|
|
9
9
|
import { container, type Container } from '../../runtime/container.js';
|
|
10
10
|
import { ACTIONS } from './actions/_manifest.generated.js';
|
|
11
11
|
|
|
12
|
-
//
|
|
12
|
+
// 装配无关的公开面(tasktool / settings.ts 从这里拿)
|
|
13
13
|
export {
|
|
14
|
+
activeTemplateOf,
|
|
14
15
|
blockLabelOf,
|
|
15
|
-
|
|
16
|
+
buildAllPlugins,
|
|
17
|
+
buildPlugins,
|
|
16
18
|
deliveryCtxOf,
|
|
17
19
|
fieldCatalogOf,
|
|
18
|
-
|
|
20
|
+
groupPluginIds,
|
|
19
21
|
PLUGIN_IDS,
|
|
20
22
|
SEED_SEGMENTS,
|
|
23
|
+
varScopeOf,
|
|
21
24
|
} from './factory.js';
|
|
22
|
-
export type { DeliveryPluginDeps,
|
|
25
|
+
export type { DeliveryPluginDeps, TemplateOverrides } from './factory.js';
|
|
26
|
+
export {
|
|
27
|
+
allPluginIds,
|
|
28
|
+
assertRegistry,
|
|
29
|
+
groupIndex,
|
|
30
|
+
groupOf,
|
|
31
|
+
pluginMeta,
|
|
32
|
+
templatesOf,
|
|
33
|
+
} from './registry.js';
|
|
34
|
+
export { PLUGIN_GROUPS } from './base.js';
|
|
35
|
+
export type { PluginGroup, TemplateText } from './base.js';
|
|
36
|
+
export { compose } from './compose.js';
|
|
23
37
|
|
|
24
38
|
/**
|
|
25
|
-
* 提示词插件模块:注册表外露(prompt.registry
|
|
26
|
-
* 业务面(compose /
|
|
27
|
-
* (tasktool → promptplug
|
|
39
|
+
* 提示词插件模块:注册表外露(prompt.registry)。
|
|
40
|
+
* 业务面(compose / buildPlugins)由 tasktool 直接消费——这是设计内依赖
|
|
41
|
+
* (tasktool → promptplug)。
|
|
28
42
|
*/
|
|
29
43
|
export class PromptplugModule extends ModuleBase {
|
|
30
44
|
override readonly id = 'promptplug';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ack 段(order 70 / get 链):完成回填指令。
|
|
2
|
+
//
|
|
3
|
+
// 一个段一个文件:正文就是这个类里的 BUILTIN(#152 起正文进代码,一个模板一个文件)。
|
|
4
|
+
// 只管「怎么交差」——完成总结该按什么格式写、用哪条命令回填。
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { PromptPlugin, type TemplateText } from '../base.js';
|
|
7
|
+
import { taskShape } from './goal-shape.js';
|
|
8
|
+
|
|
9
|
+
const schema = z.strictObject({ task: taskShape });
|
|
10
|
+
|
|
11
|
+
const BUILTIN: TemplateText = {
|
|
12
|
+
id: 'builtin',
|
|
13
|
+
name: '系统内置',
|
|
14
|
+
text: `完成之后必须调用 nx-kv localtask done --id {{task.id}} --summary "<完成总结>" 汇报结果。`,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class AckPlugin extends PromptPlugin<typeof schema> {
|
|
18
|
+
readonly id = 'ack';
|
|
19
|
+
readonly order = 70;
|
|
20
|
+
readonly group = 'get' as const;
|
|
21
|
+
readonly tag = 'nx-kv.ack';
|
|
22
|
+
readonly label = 'ack 完成总结';
|
|
23
|
+
readonly dataSchema = schema;
|
|
24
|
+
readonly templates = [BUILTIN];
|
|
25
|
+
|
|
26
|
+
constructor(template = '') { super(template); }
|
|
27
|
+
protected buildData() { return {} as never; }
|
|
28
|
+
}
|