nx-kv 0.60.0 → 0.61.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 +15 -0
- package/bin/kv.mjs +10 -0
- package/package.json +1 -1
- package/src/modules/localtask/actions/localtask-config.ts +3 -3
- package/src/modules/localtask/repo/open.ts +4 -0
- package/src/modules/localtask/repo/settings.ts +72 -202
- package/src/modules/localtask/task-templates.ts +10 -12
- package/src/modules/promptplug/Template/blockTemplates.json +90 -0
- package/src/modules/promptplug/actions/_manifest.generated.ts +20 -0
- package/src/modules/promptplug/actions/prompt-order.ts +38 -0
- package/src/modules/promptplug/actions/prompt-registry.ts +51 -0
- package/src/modules/promptplug/base.ts +70 -0
- package/src/modules/promptplug/compose.ts +86 -0
- package/src/modules/promptplug/ensure.ts +57 -0
- package/src/modules/promptplug/factory.ts +105 -0
- package/src/modules/promptplug/index.ts +39 -0
- package/src/modules/promptplug/keys.ts +9 -0
- package/src/modules/promptplug/plugins/attachment.ts +36 -0
- package/src/modules/promptplug/plugins/context.ts +167 -0
- package/src/modules/promptplug/plugins/ext.ts +32 -0
- package/src/modules/promptplug/plugins/getloop.ts +29 -0
- package/src/modules/promptplug/plugins/readonly-blocks.ts +75 -0
- package/src/modules/promptplug/schema-bridge.ts +88 -0
- package/src/modules/promptplug/template-bundle.ts +59 -0
- package/src/modules/tasktool/attach-template.ts +31 -1
- package/src/modules/tasktool/plugins/waitgoal-config.ts +11 -3
- package/src/modules/tasktool/preview.ts +7 -8
- package/src/modules/tasktool/wait.ts +78 -54
- package/src/runtime/registry.ts +2 -0
- package/src/shared/prompt-blocks.ts +93 -338
- package/src/shared/prompt-plugin.ts +182 -0
- package/src/web/frontend/api/cli-tree.json +39 -0
- package/src/web/frontend/api/client.generated.ts +20 -0
- package/src/web/frontend/components/md/block-rail.tsx +141 -0
- package/src/web/frontend/components/md/live-block.tsx +14 -2
- package/src/web/frontend/components/md/md-panes.tsx +36 -1
- package/src/web/frontend/components/md/use-block-drag.ts +68 -0
- package/src/web/frontend/components/md/use-live-preview.ts +46 -1
- package/src/web/frontend/modules/md/md-edit-ops.ts +32 -0
- package/src/web/frontend/modules/md/md-render.ts +61 -1
- package/src/web/frontend/modules/md/styles/docs.css +11 -0
- package/src/web/frontend/modules/md/styles/editor.css +35 -0
- package/src/web/frontend/modules/md/use-templates.ts +1 -1
- package/src/web/frontend/modules/prompts/render-template-body.ts +14 -0
- package/src/web/frontend/page/dir/index.tsx +1 -1
- package/src/web/frontend/page/group/index.tsx +1 -1
- package/src/web/frontend/page/settings/api.ts +29 -0
- package/src/web/frontend/page/settings/prompt-order-card.tsx +113 -0
- package/src/web/frontend/page/settings/prompt-templates-section.tsx +127 -68
- package/src/web/frontend/page/settings/style.css +31 -0
- package/src/web/frontend/page/templates/index.tsx +1 -1
- package/src/web/public/assets/bar-CGEZ954x.js +1 -0
- package/src/web/public/assets/{composer-launch-h-8g0f8A.js → composer-launch-Dhrj1gNT.js} +1 -1
- package/src/web/public/assets/{composer-panel-BhT_eFic.js → composer-panel-AXUbIJgb.js} +1 -1
- package/src/web/public/assets/{dir-1w7D_lg7.js → dir-TgJu4iE_.js} +1 -1
- package/src/web/public/assets/doc-utk54z7G.js +6 -0
- package/src/web/public/assets/{group-BsvhgO5r.js → group-CqtNx-o9.js} +1 -1
- package/src/web/public/assets/{index-BPxgsnXM.css → index-BJstNMuV.css} +1 -1
- package/src/web/public/assets/{index-CBVkXanT.js → index-BdJwacQ0.js} +2 -2
- package/src/web/public/assets/md-history-BRw2I-G_.js +39 -0
- package/src/web/public/assets/{refs-BHzLZnJn.js → refs-CIpytW-v.js} +1 -1
- package/src/web/public/assets/{repo-form-modal-BafSPVlv.js → repo-form-modal-CF9-xxFD.js} +1 -1
- package/src/web/public/assets/{repos-CmlsSN0h.js → repos-C8boX9eg.js} +1 -1
- package/src/web/public/assets/{settings-ZgyeQVU1.css → settings-BB1PvwRD.css} +1 -1
- package/src/web/public/assets/settings-Dzpmh-Ol.js +1 -0
- package/src/web/public/assets/{task-Ci94al50.js → task-h2ezBIz9.js} +5 -5
- package/src/web/public/assets/{task-utils-WfeuGNak.js → task-utils-dgdA6Pxs.js} +1 -1
- package/src/web/public/assets/{templates-Dc5Pln-Q.js → templates-D7eg9iE4.js} +1 -1
- package/src/web/public/assets/use-rail-drag-H0M8oQ0Z.js +1 -0
- package/src/web/public/index.html +7 -7
- package/src/modules/tasktool/delivery-template.ts +0 -235
- package/src/modules/tasktool/system-blocks.ts +0 -112
- package/src/web/frontend/modules/prompts/placeholders.ts +0 -106
- package/src/web/frontend/page/settings/prompt-template-params.ts +0 -296
- package/src/web/public/assets/bar-CmzzOYQi.js +0 -1
- package/src/web/public/assets/doc-Dn4-viog.js +0 -6
- package/src/web/public/assets/md-history-BF85zuFo.js +0 -39
- package/src/web/public/assets/settings-C_Dkc9gQ.js +0 -8
- package/src/web/public/assets/use-rail-drag-B1RQzqcB.js +0 -1
- /package/src/web/public/assets/{use-rail-drag-1h2zairf.css → md-history-1h2zairf.css} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// prompt.order —— 顺序数组写入(方案 §5.1 / §5.3)。
|
|
2
|
+
//
|
|
3
|
+
// 唯一真相是数组:恰好包含全部插件 id 各一次、无未知 id;不合法即拒绝保存
|
|
4
|
+
// (UI 拖动重排后 PUT 这里,CLI 渲染顺序随之变化)。
|
|
5
|
+
import { action } from '../../../runtime/action-decorator.js';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
8
|
+
import { getDb } from '../../../core/db/index.js';
|
|
9
|
+
import { writeSettingRaw } from '../../../core/db/settings.js';
|
|
10
|
+
import { assertOrder } from '../../../shared/prompt-plugin.js';
|
|
11
|
+
import { buildDeliveryPlugins } from '../factory.js';
|
|
12
|
+
import { PROMPT_ORDER_KEY } from '../keys.js';
|
|
13
|
+
|
|
14
|
+
/** prompt.order 的入参契约。 */
|
|
15
|
+
const input = z.object({
|
|
16
|
+
order: z.array(z.string()).describe('顺序数组:恰好包含全部插件 id 各一次'),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export class PromptOrderAction extends ActionBase<typeof input> {
|
|
20
|
+
@action({
|
|
21
|
+
id: 'prompt.order',
|
|
22
|
+
cli: ['prompt', 'order'],
|
|
23
|
+
http: ['PUT', '/api/prompt/order'],
|
|
24
|
+
summary: '写提示词插件顺序数组(唯一真相;必须恰好包含全部 8 个插件 id 各一次)',
|
|
25
|
+
input,
|
|
26
|
+
render: (d: any) => `顺序已保存:${d.order.join(' → ')}`,
|
|
27
|
+
})
|
|
28
|
+
override async run(ctx: ActionInput<this['_input']>) {
|
|
29
|
+
const plugins = buildDeliveryPlugins({}, {
|
|
30
|
+
groupCtx: null, attach: null, queueInfo: null, loopText: '', waitMinutes: 0,
|
|
31
|
+
});
|
|
32
|
+
// 只校验 id 集合不变量(模板为空串不影响 assertOrder / id 检查)
|
|
33
|
+
assertOrder(plugins, ctx.order);
|
|
34
|
+
const conn = getDb();
|
|
35
|
+
writeSettingRaw(conn, PROMPT_ORDER_KEY, ctx.order);
|
|
36
|
+
return { order: ctx.order };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// prompt.registry —— 注册表外露(方案 §5.3 / §7):三端同源的唯一出口。
|
|
2
|
+
//
|
|
3
|
+
// CLI(nx-kv prompt registry)、HTTP(GET /api/prompt/registry)与设置页
|
|
4
|
+
// 消费同一份 uiDescriptor():字段目录、生效模板、顺序位全部从插件声明 +
|
|
5
|
+
// DB 生效项派生,前端不再有手工副本(placeholders.ts / prompt-template-params.ts)。
|
|
6
|
+
//
|
|
7
|
+
// deps 全空:uiDescriptor 只读文本态(get())与 schema 派生面(fields/writes),
|
|
8
|
+
// 结构态 data() 永不被调用——不需要宿主取数。
|
|
9
|
+
import { action } from '../../../runtime/action-decorator.js';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import { ActionBase, type ActionInput } from '../../../runtime/action-base.js';
|
|
12
|
+
import { getDb } from '../../../core/db/index.js';
|
|
13
|
+
import { readSettingRaw } from '../../../core/db/settings.js';
|
|
14
|
+
import { resolveBlockTemplates } from '../../../shared/prompt-blocks.js';
|
|
15
|
+
import { uiDescriptor } from '../../../shared/prompt-plugin.js';
|
|
16
|
+
import { buildDeliveryPlugins, PLUGIN_IDS } from '../factory.js';
|
|
17
|
+
import { templateBundle } from '../template-bundle.js';
|
|
18
|
+
import { ensurePromptTemplates } from '../ensure.js';
|
|
19
|
+
import { LT_BLOCK_TEMPLATES, PROMPT_ORDER_KEY } from '../keys.js';
|
|
20
|
+
|
|
21
|
+
/** prompt.registry 的入参契约(无参)。 */
|
|
22
|
+
const input = z.object({});
|
|
23
|
+
|
|
24
|
+
export class PromptRegistryAction extends ActionBase<typeof input> {
|
|
25
|
+
@action({
|
|
26
|
+
id: 'prompt.registry',
|
|
27
|
+
cli: ['prompt', 'registry'],
|
|
28
|
+
http: ['GET', '/api/prompt/registry'],
|
|
29
|
+
summary: '提示词插件注册表:8 段的生效模板 / 变量目录 / 顺序位(三端同源,uiDescriptor 派生)',
|
|
30
|
+
input,
|
|
31
|
+
render: (d: any) =>
|
|
32
|
+
d.plugins.map((p: any) => `${p.order} ${p.id}(${p.label},标签 ${p.tag})`).join(';'),
|
|
33
|
+
})
|
|
34
|
+
override async run(_ctx: ActionInput<this['_input']>) {
|
|
35
|
+
const conn = getDb();
|
|
36
|
+
// 自举兜底(幂等,版本相同零写):注册表出口不依赖 localtask 的 open 链——
|
|
37
|
+
// 纯 core store 上也必须能出注册表(方案的「全仓唯一落库调用点」仍是 open.ts)。
|
|
38
|
+
let raw = readSettingRaw(conn, LT_BLOCK_TEMPLATES);
|
|
39
|
+
if (raw === undefined) {
|
|
40
|
+
ensurePromptTemplates(conn);
|
|
41
|
+
raw = readSettingRaw(conn, LT_BLOCK_TEMPLATES);
|
|
42
|
+
}
|
|
43
|
+
const resolved = resolveBlockTemplates(raw ?? templateBundle());
|
|
44
|
+
const plugins = buildDeliveryPlugins(resolved as any, {
|
|
45
|
+
groupCtx: null, attach: null, queueInfo: null, loopText: '', waitMinutes: 0,
|
|
46
|
+
});
|
|
47
|
+
const orderIds = readSettingRaw(conn, PROMPT_ORDER_KEY);
|
|
48
|
+
const pluginsDesc = uiDescriptor(plugins, Array.isArray(orderIds) ? orderIds : PLUGIN_IDS);
|
|
49
|
+
return { plugins: pluginsDesc };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// PromptPlugin 基类(唯一基准方案 §1 / §1.4)。
|
|
2
|
+
//
|
|
3
|
+
// 子类只写:id / order / tag / label / dataSchema(zod strictObject)/ writes / data()。
|
|
4
|
+
// 模板正文不进代码——构造注入(模板唯一真相是 DB 的 lt.blockTemplates)。
|
|
5
|
+
//
|
|
6
|
+
// 两个 schema 名字的分工:
|
|
7
|
+
// - dataSchema(子类声明):zod 书写层,data() 返回形状 + 可见变量目录的来源;
|
|
8
|
+
// - schema(注册面,本类派生):schema-bridge 折算后的纯数据 PluginSchema<unknown>,
|
|
9
|
+
// 注册表 / compose / uiDescriptor 只认它(shared 零依赖,zod 进不了注册面)。
|
|
10
|
+
//
|
|
11
|
+
// 铁律:
|
|
12
|
+
// - get 是唯一出口:无参 = 文本态;'data' = 结构态。子类不得重写(「怎么取」全仓一处答案);
|
|
13
|
+
// - 运行时判别靠字面量 'data',不靠泛型(泛型擦除);泛型只把结构态收窄到 T;
|
|
14
|
+
// - data() 校验只在 get('data') 出口发生一次(safeParse),运行期不兜底、不回落;
|
|
15
|
+
// - dataSchema 必须 z.strictObject:z.object 默认 strip 未声明键,data() 多写的段会被
|
|
16
|
+
// 静默删掉,撞车校验与变量白名单全部失效(见方案 §1.4 边界 2)。
|
|
17
|
+
import { z } from 'zod';
|
|
18
|
+
import type { AnyPromptPlugin, PluginSchema } from '../../shared/prompt-plugin.js';
|
|
19
|
+
import { pluginSchemaOf } from './schema-bridge.js';
|
|
20
|
+
|
|
21
|
+
export abstract class PromptPlugin<S extends z.ZodObject<z.ZodRawShape>>
|
|
22
|
+
implements AnyPromptPlugin {
|
|
23
|
+
|
|
24
|
+
abstract readonly id: string;
|
|
25
|
+
/** ★ 父类强制:子类漏写编译不过(TS2515)。值只是播种默认位,运行期由数组派生 */
|
|
26
|
+
abstract readonly order: number;
|
|
27
|
+
/** 类 XML 输出标签('nx-kv.context' 等) */
|
|
28
|
+
abstract readonly tag: string;
|
|
29
|
+
abstract readonly label: string;
|
|
30
|
+
/** ★ data 形状(zod 书写层):可写段 required + seed 段 optional;data() 返回只含可写段 */
|
|
31
|
+
abstract readonly dataSchema: S;
|
|
32
|
+
/** 默认只读:只读段不写 ctx(timecheck / goalhint / doneguard / ack) */
|
|
33
|
+
readonly writes: readonly string[] = [];
|
|
34
|
+
|
|
35
|
+
/** 当前生效模板(构造注入;空串视为该段不输出——启动期校验拦配置错误) */
|
|
36
|
+
private readonly tpl: string;
|
|
37
|
+
|
|
38
|
+
/** 注册面 schema(惰性派生一次:构造体内子类字段尚未初始化,不能在 super 里算) */
|
|
39
|
+
private registered: PluginSchema<unknown> | null = null;
|
|
40
|
+
|
|
41
|
+
constructor(template: string) {
|
|
42
|
+
this.tpl = String(template ?? '');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 注册面:纯数据 PluginSchema(fields / blank),派生一次缓存 */
|
|
46
|
+
get schema(): PluginSchema<unknown> {
|
|
47
|
+
if (!this.registered) this.registered = pluginSchemaOf(this.dataSchema);
|
|
48
|
+
return this.registered;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 子类只写这一处(同步即可;取数由宿主完成后注入,见方案 §8 分工说明) */
|
|
52
|
+
protected abstract data(): z.infer<S> | Promise<z.infer<S>>;
|
|
53
|
+
|
|
54
|
+
/** 唯一出口:无参 = 文本态;传 'data' = 结构态(校验只在这里发生一次) */
|
|
55
|
+
get<T extends z.infer<S> = z.infer<S>>(as: 'data'): Promise<T>;
|
|
56
|
+
get(): string;
|
|
57
|
+
get(as?: 'data'): string | Promise<z.infer<S>> {
|
|
58
|
+
if (as !== 'data') return this.tpl;
|
|
59
|
+
return Promise.resolve(this.data()).then((raw) => {
|
|
60
|
+
const r = this.dataSchema.safeParse(raw);
|
|
61
|
+
if (!r.success) {
|
|
62
|
+
const issues = r.error.issues
|
|
63
|
+
.map((i) => `${i.path.join('.') || '(根)'} ${i.message}`)
|
|
64
|
+
.join(';');
|
|
65
|
+
throw new Error(`${this.id}: data() 返回与 schema 不符——${issues}`);
|
|
66
|
+
}
|
|
67
|
+
return r.data;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// 编排 compose(唯一基准方案 §6)——四种语义各只有一处答案:
|
|
2
|
+
// 顺序 → orderIds(resolveOrderIds:数组唯一真相,缺失按 order 播种一次)
|
|
3
|
+
// ctx 合并 → 按序 Object.assign,段级命名互斥由 assertPluginList 保证
|
|
4
|
+
// 是否出段 → 渲染结果 trim() 为空即不出(模板为空 → 启动期已报错)
|
|
5
|
+
// 失败 → data()/渲染抛错 = 整次交付失败,不吞、不回落(运行期不兜底)
|
|
6
|
+
//
|
|
7
|
+
// 与旧 composeSystemBlocks(tasktool/system-blocks.ts,已删)的差异:
|
|
8
|
+
// - 双层 try/catch 回落(坏模板 → 内置 → 空串)**删除**:模板在保存期校验,
|
|
9
|
+
// 运行期抛错只可能是代码 bug,静默回落会让「提示词少了半段」无人知晓;
|
|
10
|
+
// - 段落清单不再来自 BLOCK_DEFS——由插件数组 + 顺序数组提供(§5.1)。
|
|
11
|
+
import { renderInstruction } from '../../core/instruction-template.js';
|
|
12
|
+
import { wrapXmlBlocks, type XmlBlockPart } from '../../shared/prompt-blocks.js';
|
|
13
|
+
import { assertPluginList, resolveOrderIds, type AnyPromptPlugin } from '../../shared/prompt-plugin.js';
|
|
14
|
+
|
|
15
|
+
/** 预览用分段记录(与旧 system-blocks 同形,调用方无感)。 */
|
|
16
|
+
export interface RenderTraceEntry {
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
text: string;
|
|
20
|
+
templateName: string;
|
|
21
|
+
warning?: string;
|
|
22
|
+
fellBack?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 渲染告警(ctx 级别的非致命问题,如 ext 读取失败;模板错误已改为抛出)。 */
|
|
26
|
+
export interface RenderWarning {
|
|
27
|
+
block: string;
|
|
28
|
+
label: string;
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** trace 里的段名映射(段落元数据,与旧 system-blocks 同形)。 */
|
|
33
|
+
export interface SegmentMeta {
|
|
34
|
+
id: string;
|
|
35
|
+
label?: string;
|
|
36
|
+
traceId?: string;
|
|
37
|
+
templateName?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ComposeOptions {
|
|
41
|
+
plugins: readonly AnyPromptPlugin[];
|
|
42
|
+
/** 顺序数组(唯一真相);缺失 / 不合法时按插件 order 播种 */
|
|
43
|
+
orderIds?: readonly string[];
|
|
44
|
+
/** compose 的种子数据:task / cwd / goal / source / summary / name / params */
|
|
45
|
+
seed?: Record<string, unknown>;
|
|
46
|
+
mode?: 'xml' | 'plain';
|
|
47
|
+
trace?: RenderTraceEntry[];
|
|
48
|
+
/** trace 的段名映射(traceId / label / 生效模板名)——真实领取不传,预览传 */
|
|
49
|
+
segments?: SegmentMeta[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 组装交付 instruction:按序取数合并 → 按序渲染 → 包标签。
|
|
54
|
+
* 返回 ''(无可输出段落)时调用方省略 instruction。
|
|
55
|
+
*/
|
|
56
|
+
export async function compose(opts: ComposeOptions): Promise<string> {
|
|
57
|
+
const { plugins, seed = {}, mode = 'xml', trace, segments } = opts;
|
|
58
|
+
assertPluginList(plugins);
|
|
59
|
+
const orderIds = resolveOrderIds(plugins, opts.orderIds);
|
|
60
|
+
const byId = new Map(plugins.map((p) => [p.id, p] as const));
|
|
61
|
+
const segOf = new Map<string, SegmentMeta>((segments || []).map((s) => [s.id, s]));
|
|
62
|
+
|
|
63
|
+
const ctx: Record<string, unknown> = { ...seed };
|
|
64
|
+
for (const id of orderIds) Object.assign(ctx, await byId.get(id)!.get('data'));
|
|
65
|
+
|
|
66
|
+
const parts: XmlBlockPart[] = [];
|
|
67
|
+
for (const id of orderIds) {
|
|
68
|
+
const p = byId.get(id)!;
|
|
69
|
+
const template = p.get();
|
|
70
|
+
if (!String(template ?? '').trim()) continue;
|
|
71
|
+
const text = renderInstruction(template, ctx).trim();
|
|
72
|
+
if (!text) continue;
|
|
73
|
+
parts.push({ id: p.id, tag: p.tag, text });
|
|
74
|
+
if (trace) {
|
|
75
|
+
const seg = segOf.get(p.id);
|
|
76
|
+
trace.push({
|
|
77
|
+
id: seg?.traceId || p.id,
|
|
78
|
+
label: seg?.label || p.label,
|
|
79
|
+
text,
|
|
80
|
+
templateName: seg?.templateName || '系统内置',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (mode === 'plain') return parts.map((p) => p.text).join('\n\n').trim();
|
|
85
|
+
return wrapXmlBlocks(parts);
|
|
86
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// ensure:首启落库与升级(唯一写点,方案 §3)。
|
|
2
|
+
//
|
|
3
|
+
// 时序:读版本键 → 已最新直接返回(重启零写、零查询)→ 落后时读出厂快照,
|
|
4
|
+
// 只刷 builtin 文本(用户条目 builtin:false、active、list 顺序一律不动),
|
|
5
|
+
// 同事务写回 lt.blockTemplates 与 lt.promptTemplatesVersion。
|
|
6
|
+
//
|
|
7
|
+
// 存量自愈(S1 补记):active 指向空模板条目 → 修回 builtin——空模板在运行期
|
|
8
|
+
// 是配置错误(assertPluginList 抛),落库后由这里一次性收敛,不让升级变成事故。
|
|
9
|
+
import { readSettingRaw, writeSettingRaw } from '../../core/db/settings.js';
|
|
10
|
+
import type { DbApi } from '../../core/db/driver.js';
|
|
11
|
+
import { tx } from '../../core/db/tx.js';
|
|
12
|
+
import { BUILTIN_TEMPLATE_ID } from '../../shared/prompt-blocks.js';
|
|
13
|
+
import { BUNDLE_VERSION, templateBundle } from './template-bundle.js';
|
|
14
|
+
import { LT_PROMPT_TEMPLATES_VERSION, LT_BLOCK_TEMPLATES } from './keys.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 首启 / 版本落后时把出厂快照写进 settings(全仓唯一调用点:localtask/repo/open.ts)。
|
|
18
|
+
* 返回是否发生写入(测试断言「重启零写」用)。
|
|
19
|
+
*/
|
|
20
|
+
export function ensurePromptTemplates(conn: DbApi): boolean {
|
|
21
|
+
const cur = Number(readSettingRaw(conn, LT_PROMPT_TEMPLATES_VERSION) ?? 0);
|
|
22
|
+
if (cur >= BUNDLE_VERSION) return false;
|
|
23
|
+
|
|
24
|
+
const bundle = templateBundle();
|
|
25
|
+
let wrote = false;
|
|
26
|
+
tx(() => {
|
|
27
|
+
const stored = readSettingRaw(conn, LT_BLOCK_TEMPLATES) as Record<string, any> | undefined;
|
|
28
|
+
const lists = { ...bundle };
|
|
29
|
+
if (stored && typeof stored === 'object' && !Array.isArray(stored)) {
|
|
30
|
+
// 升级语义只有一条:只覆盖内置文本;用户条目与 active 永不被覆盖。
|
|
31
|
+
for (const id of Object.keys(bundle)) {
|
|
32
|
+
const br = stored[id];
|
|
33
|
+
const rec = br && typeof br === 'object' && !Array.isArray(br) ? (br as Record<string, unknown>) : null;
|
|
34
|
+
const rawList = Array.isArray(rec?.list) ? (rec!.list as Record<string, unknown>[]) : null;
|
|
35
|
+
if (!rawList) continue; // 缺整块 → 出厂快照原样落
|
|
36
|
+
const items = rawList.map((item) => {
|
|
37
|
+
if (item && typeof item === 'object' && (item.builtin === true || item.id === BUILTIN_TEMPLATE_ID)) {
|
|
38
|
+
return { ...item, template: bundle[id]!.list[0]!.template };
|
|
39
|
+
}
|
|
40
|
+
return item;
|
|
41
|
+
});
|
|
42
|
+
// 存量自愈:active 指向不存在的条目或空模板 → 修回 builtin
|
|
43
|
+
const wanted = String(rec?.active ?? '').trim();
|
|
44
|
+
const activeItem = items.find((x) => x && (x as any).id === wanted);
|
|
45
|
+
const activeBlank = activeItem && String((activeItem as any).template ?? '').trim() === '';
|
|
46
|
+
const active = !activeItem || activeBlank ? BUILTIN_TEMPLATE_ID : wanted;
|
|
47
|
+
lists[id] = { active, list: items as any };
|
|
48
|
+
}
|
|
49
|
+
wrote = true;
|
|
50
|
+
} else {
|
|
51
|
+
wrote = true; // 首启:整份出厂快照落库
|
|
52
|
+
}
|
|
53
|
+
writeSettingRaw(conn, LT_BLOCK_TEMPLATES, lists);
|
|
54
|
+
writeSettingRaw(conn, LT_PROMPT_TEMPLATES_VERSION, BUNDLE_VERSION);
|
|
55
|
+
}, { db: conn });
|
|
56
|
+
return wrote;
|
|
57
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// promptplug 插件工厂:交付插件构造 + 字段目录 + 白名单数据源(方案 §8)。
|
|
2
|
+
//
|
|
3
|
+
// 单独成文件的原因:actions/ 下的 action 经 _manifest.generated.ts 被 index.ts
|
|
4
|
+
// 装配,若 action 反向 import index.js 就形成 TDZ 回环——工厂是 actions 与
|
|
5
|
+
// tasktool 共同的依赖终点,不含任何装配代码。
|
|
6
|
+
//
|
|
7
|
+
// 依赖方向(设计内,见方案 §8 说明):tasktool 是唯一消费方——宿主完成领域取数
|
|
8
|
+
// (readGroupContext / annotateTaskDelivery / pendingQueueInfo / getloop 指令渲染),
|
|
9
|
+
// 把结果注入插件构造;插件 data() 只做同步变换。promptplug 不 import 其他模块。
|
|
10
|
+
import type { AnyPromptPlugin } from '../../shared/prompt-plugin.js';
|
|
11
|
+
import { ContextPlugin } from './plugins/context.js';
|
|
12
|
+
import { AttachmentPlugin } from './plugins/attachment.js';
|
|
13
|
+
import { ExtPlugin } from './plugins/ext.js';
|
|
14
|
+
import { GetloopPlugin } from './plugins/getloop.js';
|
|
15
|
+
import { AckPlugin, DoneguardPlugin, GoalhintPlugin, TimecheckPlugin } from './plugins/readonly-blocks.js';
|
|
16
|
+
|
|
17
|
+
/** 每段生效模板(lt.blockTemplates 归一化后的 resolved 项,id → template)。 */
|
|
18
|
+
export type ResolvedTemplates = Record<string, { template: string } | undefined>;
|
|
19
|
+
|
|
20
|
+
/** 交付插件构造所需的宿主取数结果(全部可同步拿到)。 */
|
|
21
|
+
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;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 按默认 order 位构造 8 个交付插件(模板注入:DB 归一化后的生效项)。 */
|
|
30
|
+
export function buildDeliveryPlugins(
|
|
31
|
+
tpl: ResolvedTemplates,
|
|
32
|
+
deps: DeliveryPluginDeps,
|
|
33
|
+
): AnyPromptPlugin[] {
|
|
34
|
+
const t = (id: string): string => String(tpl[id]?.template ?? '');
|
|
35
|
+
return [
|
|
36
|
+
new ContextPlugin(t('context'), { groupCtx: deps.groupCtx }),
|
|
37
|
+
new AttachmentPlugin(t('attachment'), { attach: deps.attach }),
|
|
38
|
+
new TimecheckPlugin(t('timecheck')),
|
|
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 }),
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { deliveryCtxOf } from './plugins/context.js';
|
|
48
|
+
|
|
49
|
+
// ── 写路径校验的数据源(方案 §4.2)───────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
/** seed 段(compose 的种子数据;无输出段,因此没有 order 位)。 */
|
|
52
|
+
export const SEED_SEGMENTS: readonly string[] = ['task', 'cwd', 'goal', 'source', 'summary', 'name', 'params'];
|
|
53
|
+
|
|
54
|
+
const fieldCache = new Map<string, { fields: string[]; top: string[] }>();
|
|
55
|
+
|
|
56
|
+
/** 某插件的字段目录:fields 全键 + 顶层段(从 dataSchema 派生,缓存)。 */
|
|
57
|
+
export function fieldCatalogOf(id: string): { fields: string[]; top: string[] } {
|
|
58
|
+
const hit = fieldCache.get(id);
|
|
59
|
+
if (hit) return hit;
|
|
60
|
+
const p = pluginById(id);
|
|
61
|
+
if (!p) throw new Error(`未知提示词插件:${id}`);
|
|
62
|
+
const fields = p.schema.fields.map((f) => f.key);
|
|
63
|
+
const top = [...new Set(fields.map((f) => f.split('.')[0]!))];
|
|
64
|
+
const out = { fields, top };
|
|
65
|
+
fieldCache.set(id, out);
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
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
|
+
/**
|
|
77
|
+
* 白名单校验入参(**全局段集**,落地裁决——见方案 §4.2 补记):
|
|
78
|
+
* ctx 全共享是既有语义(「不存在某模块自带一套变量域」),per-block 硬隔离会误伤
|
|
79
|
+
* 旧 CLI 入口与跨段引用;白名单的目标收敛为「拦拼错的段名 / 变量名」——
|
|
80
|
+
* 段集合 = 全部插件 writes ∪ seed ∪ 全部 fields 顶层;字段键 = 全部 fields 并集。
|
|
81
|
+
*/
|
|
82
|
+
export function globalTemplateVarScope(): { allowedSegments: string[]; fieldKeys: string[] } {
|
|
83
|
+
const segments = new Set<string>(SEED_SEGMENTS);
|
|
84
|
+
const keys = new Set<string>();
|
|
85
|
+
for (const id of PLUGIN_IDS) {
|
|
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] };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 全部交付插件 id(8 段)。 */
|
|
96
|
+
export const PLUGIN_IDS: readonly string[] = [
|
|
97
|
+
'context', 'attachment', 'timecheck', 'goalhint', 'doneguard', 'ext', 'ack', 'getloop',
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
/** 区块显示名(错误消息 / 设置页 tab 用)——从插件 label 派生,不写第二份。 */
|
|
101
|
+
export function blockLabelOf(id: string): string {
|
|
102
|
+
const p = pluginById(id);
|
|
103
|
+
if (!p) throw new Error(`未知提示词插件:${id}`);
|
|
104
|
+
return p.label;
|
|
105
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// promptplug 装配:模块元信息 + action 清单装配(方案 §8 index.ts)。
|
|
2
|
+
//
|
|
3
|
+
// 插件工厂 / 字段目录 / 白名单数据源在 factory.ts(actions 经 manifest 引工厂,
|
|
4
|
+
// 不能回环引本文件)。依赖方向(设计内,见方案 §8 说明):tasktool 是唯一消费方
|
|
5
|
+
// ——宿主完成领域取数,把结果注入插件构造;插件 data() 只做同步变换。
|
|
6
|
+
// promptplug 不 import 其他模块。
|
|
7
|
+
import { ModuleBase } from '../../runtime/types/module.js';
|
|
8
|
+
import { zodActionsOf, type ZodBoundAction } from '../../runtime/action-decorator.js';
|
|
9
|
+
import { container, type Container } from '../../runtime/container.js';
|
|
10
|
+
import { ACTIONS } from './actions/_manifest.generated.js';
|
|
11
|
+
|
|
12
|
+
// 装配无关的公开面(历史 import 路径保持不变:tasktool / settings.ts 从这里拿)
|
|
13
|
+
export {
|
|
14
|
+
blockLabelOf,
|
|
15
|
+
buildDeliveryPlugins,
|
|
16
|
+
deliveryCtxOf,
|
|
17
|
+
fieldCatalogOf,
|
|
18
|
+
globalTemplateVarScope,
|
|
19
|
+
PLUGIN_IDS,
|
|
20
|
+
SEED_SEGMENTS,
|
|
21
|
+
} from './factory.js';
|
|
22
|
+
export type { DeliveryPluginDeps, ResolvedTemplates } from './factory.js';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 提示词插件模块:注册表外露(prompt.registry / prompt.order,方案 §5.3)。
|
|
26
|
+
* 业务面(compose / buildDeliveryPlugins)由 tasktool 直接消费——这是设计内依赖
|
|
27
|
+
* (tasktool → promptplug,见 docs/research/prompt-plugin-single-route.md §8)。
|
|
28
|
+
*/
|
|
29
|
+
export class PromptplugModule extends ModuleBase {
|
|
30
|
+
override readonly id = 'promptplug';
|
|
31
|
+
override readonly title = '提示词插件';
|
|
32
|
+
override readonly order = 85;
|
|
33
|
+
override readonly actions: readonly ZodBoundAction[];
|
|
34
|
+
|
|
35
|
+
constructor(c: Container = container) {
|
|
36
|
+
super();
|
|
37
|
+
this.actions = ACTIONS.flatMap((Cls) => zodActionsOf(c.create(Cls)));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// promptplug 的 settings 键名(与 localtask/repo/settings.ts 的 KEYS 对账——
|
|
2
|
+
// 不 import localtask:promptplug 不依赖其他模块,键名字符串由单测钉住一致)。
|
|
3
|
+
|
|
4
|
+
/** 模板唯一真相(8 段,每段 active + list)。 */
|
|
5
|
+
export const LT_BLOCK_TEMPLATES = 'lt.blockTemplates';
|
|
6
|
+
/** 出厂快照版本(升级时只刷 builtin 文本)。 */
|
|
7
|
+
export const LT_PROMPT_TEMPLATES_VERSION = 'lt.promptTemplatesVersion';
|
|
8
|
+
/** 顺序唯一真相(id 数组)。 */
|
|
9
|
+
export const PROMPT_ORDER_KEY = 'prompt.pluginOrder';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// attachment 插件(order 20):附件识别。数据变换(attachTemplateCtx)留在
|
|
2
|
+
// tasktool/attach-template.ts(依赖 attach-resource 的标注工具链,随插件搬会牵动
|
|
3
|
+
// 三处引用)——插件消费宿主取数标注后的 attach 对象,schema 声明变量目录。
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { PromptPlugin } from '../base.js';
|
|
6
|
+
|
|
7
|
+
const schema = z.strictObject({
|
|
8
|
+
// 内层 looseObject 且字段全 optional:attach 对象由宿主(attachTemplateCtx)构造,
|
|
9
|
+
// schema 的校验职责收敛在「顶层段键 ∈ writes」(strictObject),子形状是变量目录
|
|
10
|
+
attach: z.looseObject({
|
|
11
|
+
count: z.number().optional(),
|
|
12
|
+
inlineCount: z.number().optional(),
|
|
13
|
+
areaCount: z.number().optional(),
|
|
14
|
+
hasInline: z.boolean().optional(),
|
|
15
|
+
hasArea: z.boolean().optional(),
|
|
16
|
+
list: z.array(z.looseObject({})).optional(),
|
|
17
|
+
}).nullable(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export class AttachmentPlugin extends PromptPlugin<typeof schema> {
|
|
21
|
+
readonly id = 'attachment';
|
|
22
|
+
readonly order = 20;
|
|
23
|
+
readonly tag = 'nx-kv.attachment';
|
|
24
|
+
readonly label = '附件识别';
|
|
25
|
+
override readonly writes = ['attach'];
|
|
26
|
+
readonly dataSchema = schema;
|
|
27
|
+
|
|
28
|
+
/** deps.attach:attachTemplateCtx(attachments).attach(无附件 → null) */
|
|
29
|
+
constructor(template: string, private readonly deps: { attach: unknown }) {
|
|
30
|
+
super(template);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected data() {
|
|
34
|
+
return { attach: (this.deps.attach ?? null) as z.infer<typeof schema>['attach'] };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// context 插件(order 10):组 / 项目上下文。
|
|
2
|
+
// data() 搬自 tasktool/delivery-template.ts 的 deliveryCtxOf(原文件随 S1 删除),
|
|
3
|
+
// 口径注释一并迁入——#81 空壳组过滤、#104 已登记无介绍可见、参考仓库去重并集。
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { PromptPlugin } from '../base.js';
|
|
6
|
+
|
|
7
|
+
const docItemShape = z.looseObject({
|
|
8
|
+
refId: z.string(),
|
|
9
|
+
desc: z.string(),
|
|
10
|
+
title: z.string(),
|
|
11
|
+
hasBody: z.boolean(),
|
|
12
|
+
note: z.string(),
|
|
13
|
+
});
|
|
14
|
+
const refRepoShape = z.looseObject({ key: z.string(), name: z.string(), path: z.string(), note: z.string() });
|
|
15
|
+
const peerShape = z.looseObject({ name: z.string(), note: z.string(), path: z.string(), hasNote: z.boolean() });
|
|
16
|
+
|
|
17
|
+
const repoShape = z.looseObject({
|
|
18
|
+
name: z.string(), key: z.string(),
|
|
19
|
+
intro: z.string(), introPath: z.string(), introRefId: z.string(), introDesc: z.string(),
|
|
20
|
+
docs: z.array(docItemShape), docCount: z.number(),
|
|
21
|
+
refRepos: z.array(refRepoShape), refRepoCount: z.number(),
|
|
22
|
+
});
|
|
23
|
+
const groupShape = z.looseObject({
|
|
24
|
+
name: z.string(), key: z.string(), desc: z.string(),
|
|
25
|
+
intro: z.string(), introPath: z.string(), introRefId: z.string(), introDesc: z.string(),
|
|
26
|
+
note: z.string(), position: z.string(),
|
|
27
|
+
peers: z.array(peerShape), peerCount: z.number(),
|
|
28
|
+
docs: z.array(docItemShape), docCount: z.number(),
|
|
29
|
+
refRepos: z.array(refRepoShape), refRepoCount: z.number(),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const schema = z.strictObject({
|
|
33
|
+
repo: repoShape.nullable(),
|
|
34
|
+
group: groupShape.nullable(),
|
|
35
|
+
refRepos: z.looseObject({ list: z.array(refRepoShape), count: z.number() }),
|
|
36
|
+
groups: z.array(z.looseObject({ name: z.string(), desc: z.string(), path: z.string() })),
|
|
37
|
+
// 可见 seed 变量({{cwd}}),data() 不返回它
|
|
38
|
+
cwd: z.string().optional(),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/** 「项目文档 / 组文档」→ 结构化数组(模板用 {{#each}} 组织行)。 */
|
|
42
|
+
// #216 合并远端 schema v12:ref 的「分类标签」tag 已整个退役,这里不再搬它。
|
|
43
|
+
function docItems(links: any) {
|
|
44
|
+
return (links || []).map((d: any) => ({
|
|
45
|
+
refId: d.refId || '',
|
|
46
|
+
desc: d.desc || '',
|
|
47
|
+
title: d.title || '',
|
|
48
|
+
hasBody: d.hasBody !== false,
|
|
49
|
+
note: d.note || '',
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 组内成员 → 结构化数组({{name}} / {{note}} / {{path}}——#163:路径方便直接访问)。 */
|
|
54
|
+
function peerItems(peers: any) {
|
|
55
|
+
return (peers || []).map((p: any) => ({
|
|
56
|
+
name: p.name || '',
|
|
57
|
+
note: p.note || '',
|
|
58
|
+
path: p.path || '',
|
|
59
|
+
hasNote: !!p.note,
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 参考仓库(repos 里 type=ref,不是文档库 refs)→ 结构化数组。 */
|
|
64
|
+
function refRepoItems(list: any) {
|
|
65
|
+
return (list || []).map((r: any) => ({
|
|
66
|
+
key: r.key || '',
|
|
67
|
+
name: r.name || '',
|
|
68
|
+
path: r.path || '',
|
|
69
|
+
note: r.note || '',
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 组有没有值得交付的内容:定位 / 介绍 / 位置 / 参考文件 / 有描述的成员,任一即可。
|
|
75
|
+
* 纯「成员名单(全员无描述)」不算——那只会喷出一排空标签(#81)。
|
|
76
|
+
*/
|
|
77
|
+
function groupHasContent(g: any): boolean {
|
|
78
|
+
if (!g) return false;
|
|
79
|
+
if (g.desc || g.note) return true;
|
|
80
|
+
if (g.intro && g.intro.body) return true;
|
|
81
|
+
if (g.docLinks && g.docLinks.length) return true;
|
|
82
|
+
if (g.refRepos && g.refRepos.length) return true;
|
|
83
|
+
return (g.peers || []).some((p: any) => p.note);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function deliveryCtxOf(groupCtx: any) {
|
|
87
|
+
const repo = groupCtx && groupCtx.repo ? groupCtx.repo : null;
|
|
88
|
+
const allGroups = (groupCtx && groupCtx.groups) || [];
|
|
89
|
+
// 闸门是「键在不在」,不是「内容空不空」——空壳组进了 ctx 就会印出空标签(#81)。
|
|
90
|
+
// 多组时跳过空壳选第一个有料的当主组,其余有料的进 {{groups}} 概览。
|
|
91
|
+
const groups = allGroups.filter(groupHasContent);
|
|
92
|
+
const g = groups[0] || null;
|
|
93
|
+
const repoDocs = docItems(repo && repo.docLinks);
|
|
94
|
+
const peers = g ? peerItems(g.peers) : [];
|
|
95
|
+
const gdocs = g ? docItems(g.docLinks) : [];
|
|
96
|
+
const repoRefRepos = refRepoItems(repo && repo.refRepos);
|
|
97
|
+
const groupRefRepos = g ? refRepoItems(g.refRepos) : [];
|
|
98
|
+
// 交付口径:本仓库直接绑定 ∪ 本次任务所属组的组级绑定,去重后按本仓库在前排序。
|
|
99
|
+
const seenRefRepoKeys = new Set<string>();
|
|
100
|
+
const refRepoList: { key: string; name: string; path: string; note: string }[] = [];
|
|
101
|
+
for (const r of [...repoRefRepos, ...groupRefRepos]) {
|
|
102
|
+
const k = r.key || r.name;
|
|
103
|
+
if (seenRefRepoKeys.has(k)) continue;
|
|
104
|
+
seenRefRepoKeys.add(k);
|
|
105
|
+
refRepoList.push(r);
|
|
106
|
+
}
|
|
107
|
+
const others = groups.slice(1).map((x: any) => ({
|
|
108
|
+
name: x.name || '',
|
|
109
|
+
desc: x.desc || '',
|
|
110
|
+
path: (x.intro && x.intro.path) || '',
|
|
111
|
+
}));
|
|
112
|
+
return {
|
|
113
|
+
// #104:只要目录**已登记**,repo 就进 ctx(哪怕没写介绍、没绑文档)。
|
|
114
|
+
repo: repo
|
|
115
|
+
? {
|
|
116
|
+
name: repo.name || repo.key || '',
|
|
117
|
+
key: repo.key || '',
|
|
118
|
+
intro: (repo.intro && repo.intro.body) || '',
|
|
119
|
+
introPath: (repo.intro && repo.intro.path) || '',
|
|
120
|
+
introRefId: (repo.intro && repo.intro.refId) || '',
|
|
121
|
+
introDesc: (repo.intro && (repo.intro.desc || repo.intro.title)) || '',
|
|
122
|
+
docs: repoDocs,
|
|
123
|
+
docCount: repoDocs.length,
|
|
124
|
+
refRepos: repoRefRepos,
|
|
125
|
+
refRepoCount: repoRefRepos.length,
|
|
126
|
+
}
|
|
127
|
+
: null,
|
|
128
|
+
group: g
|
|
129
|
+
? {
|
|
130
|
+
name: g.name || '',
|
|
131
|
+
key: g.key || '',
|
|
132
|
+
desc: g.desc || '',
|
|
133
|
+
intro: (g.intro && g.intro.body) || '',
|
|
134
|
+
introPath: (g.intro && g.intro.path) || '',
|
|
135
|
+
introRefId: (g.intro && g.intro.refId) || '',
|
|
136
|
+
introDesc: (g.intro && (g.intro.desc || g.intro.title)) || '',
|
|
137
|
+
note: g.note || '',
|
|
138
|
+
position: g.note || '',
|
|
139
|
+
peers,
|
|
140
|
+
peerCount: peers.length,
|
|
141
|
+
docs: gdocs,
|
|
142
|
+
docCount: gdocs.length,
|
|
143
|
+
refRepos: groupRefRepos,
|
|
144
|
+
refRepoCount: groupRefRepos.length,
|
|
145
|
+
}
|
|
146
|
+
: null,
|
|
147
|
+
refRepos: { list: refRepoList, count: refRepoList.length },
|
|
148
|
+
groups: others,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export class ContextPlugin extends PromptPlugin<typeof schema> {
|
|
153
|
+
readonly id = 'context';
|
|
154
|
+
readonly order = 10;
|
|
155
|
+
readonly tag = 'nx-kv.context';
|
|
156
|
+
readonly label = '组 / 项目上下文';
|
|
157
|
+
override readonly writes = ['repo', 'group', 'refRepos', 'groups'];
|
|
158
|
+
readonly dataSchema = schema;
|
|
159
|
+
|
|
160
|
+
constructor(template: string, private readonly deps: { groupCtx: unknown }) {
|
|
161
|
+
super(template);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
protected data() {
|
|
165
|
+
return deliveryCtxOf(this.deps.groupCtx);
|
|
166
|
+
}
|
|
167
|
+
}
|