dsh-bufeng 0.0.0-stage → 0.64.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 +21 -0
- package/README.md +68 -2
- package/bufeng.patch.yml +3 -0
- package/client/build-client.mjs +159 -0
- package/client/client.js +4038 -0
- package/client/src/board.js +133 -0
- package/client/src/capabilities.js +787 -0
- package/client/src/cards.js +263 -0
- package/client/src/data.js +43 -0
- package/client/src/graph.js +558 -0
- package/client/src/icons.js +88 -0
- package/client/src/projects.js +467 -0
- package/client/src/prompt.js +55 -0
- package/client/src/react.js +7 -0
- package/client/src/settings.js +407 -0
- package/client/src/styles.js +611 -0
- package/client/src/taskboard.js +321 -0
- package/client/src/taskgraph.js +145 -0
- package/client/src/ui.js +72 -0
- package/lib/acceptance-subject.js +71 -0
- package/lib/board/server.js +546 -0
- package/lib/board/snapshot.js +133 -0
- package/lib/board/taskview.js +151 -0
- package/lib/bootstrap.js +77 -0
- package/lib/catalog.js +385 -0
- package/lib/core.js +478 -0
- package/lib/data/capability-alias-catalog.json +301 -0
- package/lib/data/capability-alias.json +25 -0
- package/lib/domain.js +1342 -0
- package/lib/host-probe.js +176 -0
- package/lib/identity-hook.js +490 -0
- package/lib/index.js +119 -0
- package/lib/lessons.js +134 -0
- package/lib/metering.js +109 -0
- package/lib/scope.js +389 -0
- package/lib/session/child-watch.js +86 -0
- package/lib/session/evidence.js +118 -0
- package/lib/session/node-session.js +335 -0
- package/lib/session/queue.js +307 -0
- package/lib/session/reconcile.js +500 -0
- package/lib/tools/capabilities.js +1461 -0
- package/lib/tools/governance.js +579 -0
- package/lib/tools/index.js +33 -0
- package/lib/tools/project.js +500 -0
- package/lib/tools/readonly.js +566 -0
- package/lib/tools/recover.js +402 -0
- package/lib/tools/run.js +1609 -0
- package/lib/tools/skills.js +162 -0
- package/lib/tools/trees.js +637 -0
- package/lib/workspace-rmw.js +365 -0
- package/package.json +42 -4
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/tools/skills.js — v0.29.2 批2 装备层:bufeng_skill 技能加载工具(skill 轴语义B 的运行期入口,第 18 只工具)。
|
|
3
|
+
* 方案:bufeng-ws/prompt-redesign/skill-mcp装备改造方案-v1.md §5.1 skill 轴 + 客户拍板(逐字见 ADR v0.29.2):
|
|
4
|
+
* m00244 项1 选 B——默认技能实时自动放行:调用时实时解析宿主自带集(source==='bundled'),allowSkills 只列额外项,
|
|
5
|
+
* 不维护 DSH 默认技能列表副本;m00243 失效标注 fail-visible(改名/下架报错可见)。
|
|
6
|
+
* 语义B 三态(与 lib/session/node-session.js applyEquipTools 的挂闸条件同口径):
|
|
7
|
+
* 调用方节点 equip.allowSkills === undefined → 本工具不设闸,透传宿主技能目录(存量节点零变化);
|
|
8
|
+
* = [](空数组) → 仅默认集;= [...] → 默认集 ∪ 名单额外项。
|
|
9
|
+
* S1(modelInvocable 对齐宿主目录口径):invocation.modelInvocable !== true 的技能一律拒载(全模式含透传)——
|
|
10
|
+
* 与宿主 skill 工具「按可见性过滤」同语义,用户手势专用技能不进模型上下文。
|
|
11
|
+
* 默认集防缺失兜底(任务注意项):条目 source 元数据缺失(null)按非默认处理并在文案留注,不崩。
|
|
12
|
+
* 调用方解析(每任务新会话制):① running/pending 任务 childId anchorsMatch → 该任务执行节点(最新会话);
|
|
13
|
+
* ② node.sessionId anchorsMatch;③ rootSessions 名单锚点 → 根节点(总管给自己配的白名单同受闸)。
|
|
14
|
+
* 都未命中(总管未配/无身份会话/退役节点旧会话)= 无闸透传——编制除名即闸除名。
|
|
15
|
+
* 失败文案纪律(AGENTS §9 问题一):每个拒绝都给下一步指引(bufeng_update_node / bufeng_capabilities / bufeng_report)。
|
|
16
|
+
* 依赖方向:tools → core/domain(不反向)。
|
|
17
|
+
*/
|
|
18
|
+
import { loadLedger, objSchema, jsonRender, safeRegister } from '../core.js';
|
|
19
|
+
import { resolveNodeAnchorOf, isRosterRoot } from '../domain.js';
|
|
20
|
+
|
|
21
|
+
/** 默认集判定依据:source === 'bundled'(宿主内置,如 office 三件套)。
|
|
22
|
+
* 实时判定不落缓存(m00244:不维护 DSH 默认技能列表副本——目录演进免同步)。 */
|
|
23
|
+
function isDefaultSkillSource(source) {
|
|
24
|
+
return source === 'bundled';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 调用方节点解析:找到调用会话所属的在编节点(含根节点),返回 {node, tree} 或 null。
|
|
28
|
+
* 顺序:在跑任务 childId(每任务新会话制,node.sessionId 只存最近一会话)→ node.sessionId → 总管名单锚点→根节点。 */
|
|
29
|
+
function resolveSkillCallerNode(ledger, callerId) {
|
|
30
|
+
// v0.58.0:调用方节点解析收敛到 domain 唯一权威 resolveNodeAnchorOf(设计 §3 P-α 单一解析权威;
|
|
31
|
+
// 旧自建三路由与 tasks 反向拷贝退役)。返回契约不变:执行中任务 childId→执行节点;名单锚→root 节点;未知→null。
|
|
32
|
+
const a = resolveNodeAnchorOf(ledger, callerId);
|
|
33
|
+
if (a && a.node) return { node: a.node, tree: a.tree };
|
|
34
|
+
for (const tree of ledger.trees ?? []) {
|
|
35
|
+
if (!tree || tree.status === 'archived') continue;
|
|
36
|
+
if (isRosterRoot(tree, callerId)) {
|
|
37
|
+
const rootNode = (tree.nodes ?? []).find((n) => (n.kind ?? 'member') === 'root' || n.kind === 'orchestrator');
|
|
38
|
+
if (rootNode) return { node: rootNode, tree };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 宿主 get(name) 返回形状防御链:string / {content} / {markdown} / {text} / {body} / {instructions}(函数返回值同链)。 */
|
|
45
|
+
function extractSkillContent(raw) {
|
|
46
|
+
let v = raw;
|
|
47
|
+
if (typeof v === 'function') return null;
|
|
48
|
+
if (v && typeof v === 'object' && typeof v.then === 'function') return null; // 调用方 await 后再进本函数;防御双重 then 场景给 null
|
|
49
|
+
if (typeof v === 'string') return v;
|
|
50
|
+
if (v && typeof v === 'object') {
|
|
51
|
+
for (const k of ['content', 'markdown', 'text', 'body', 'instructions']) {
|
|
52
|
+
const s = v[k];
|
|
53
|
+
if (typeof s === 'string') return s;
|
|
54
|
+
}
|
|
55
|
+
if (typeof v.content === 'object' && v.content !== null && typeof v.content.text === 'string') return v.content.text;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 读取宿主技能注册表(实时,不缓存)。失败返回 {reg:null} 由调用方统一报错。 */
|
|
61
|
+
async function liveSkillRegistry(ctx) {
|
|
62
|
+
const reg = typeof ctx?.get === 'function' ? ctx.get('skills') : null;
|
|
63
|
+
if (!reg || typeof reg.list !== 'function' || typeof reg.get !== 'function') return { reg: null };
|
|
64
|
+
let list = null;
|
|
65
|
+
try {
|
|
66
|
+
const r = await reg.list();
|
|
67
|
+
if (Array.isArray(r)) list = r;
|
|
68
|
+
} catch { list = null; }
|
|
69
|
+
if (!list) return { reg: null };
|
|
70
|
+
return { reg, list };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function registerSkillTools(ctx, ledger) {
|
|
74
|
+
safeRegister(ctx, ledger, {
|
|
75
|
+
name: 'bufeng_skill',
|
|
76
|
+
description: '加载一项宿主技能的完整正文(skill 轴语义B 运行期入口,与节点白名单闸配套)。默认集(宿主自带 source=bundled)实时自动放行;节点 equip.allowSkills 只列额外项([]=仅默认集、[...]=默认集∪额外项、未配置=全目录透传)。未开放模型调用(modelInvocable=false)与白名单外的技能会被拒并给出修正指引;可用技能清单见 bufeng_capabilities action=list。',
|
|
77
|
+
parameters: {
|
|
78
|
+
type: 'object',
|
|
79
|
+
properties: {
|
|
80
|
+
name: { type: 'string', description: '技能名(精确匹配宿主技能目录,如 "office-docx";可用清单见 bufeng_capabilities action=list 的 skills 段)' }
|
|
81
|
+
},
|
|
82
|
+
required: ['name']
|
|
83
|
+
},
|
|
84
|
+
output: {
|
|
85
|
+
schema: objSchema({
|
|
86
|
+
ok: { type: 'boolean', description: 'true=正文已载入' },
|
|
87
|
+
name: { type: 'string', description: '技能名' },
|
|
88
|
+
gated: { type: 'boolean', description: '本次调用是否经节点 allowSkills 白名单闸判定' },
|
|
89
|
+
defaultSkill: { type: 'boolean', description: '是否宿主默认集(source=bundled,实时判定)' },
|
|
90
|
+
source: { type: 'string', description: '技能来源(bundled/filesystem/host 等);宿主未标注时整键缺省(v0.29.3 热修:宿主 schema 仅支持单值类型字符串,type 数组=注册期 JsonSchemaError)' },
|
|
91
|
+
content: { type: 'string', description: '技能正文(与宿主 skill 工具同款渲染路径)' },
|
|
92
|
+
note: { type: 'string', description: '备注(如 source 缺失按非默认处理的留注);无事缺省' }
|
|
93
|
+
}),
|
|
94
|
+
render: jsonRender
|
|
95
|
+
},
|
|
96
|
+
/** 只读宿主注册表+读账本判定调用方;不写账本(白名单变更是 bufeng_update_node 的治理动作)。 */
|
|
97
|
+
execute: async (args = {}, exec = {}) => {
|
|
98
|
+
const name = typeof args?.name === 'string' ? args.name.trim() : '';
|
|
99
|
+
if (!name) throw new Error('缺少技能名 name(string)。当前可用技能清单见 bufeng_capabilities action=list 的 skills 段。');
|
|
100
|
+
// 调用方节点解析(锁外只读账本快照:判定只依赖 equip.allowSkills 与任务/会话锚点,读写竞态影响=下一次调用生效)
|
|
101
|
+
const ledgerNow = await loadLedger();
|
|
102
|
+
const callerId = exec?.agent?.id ?? null;
|
|
103
|
+
const caller = resolveSkillCallerNode(ledgerNow, callerId);
|
|
104
|
+
const allowSkills = Array.isArray(caller?.node?.equip?.allowSkills) ? caller.node.equip.allowSkills : null;
|
|
105
|
+
// 宿主注册表(实时)
|
|
106
|
+
const { reg, list } = await liveSkillRegistry(ctx);
|
|
107
|
+
if (!reg) throw new Error('宿主技能注册表不可读(ctx.get("skills") 缺失或 list()/get() 不可用),无法加载技能正文——可先 bufeng_capabilities action=list 确认清单,异常请写进 bufeng_report 的 summary 上报。');
|
|
108
|
+
const entry = list.find((s) => s && typeof s === 'object' && s.name === name) ?? null;
|
|
109
|
+
// S1:modelInvocable 语义对齐(全模式含透传)
|
|
110
|
+
if (entry && entry.invocation?.modelInvocable !== true) {
|
|
111
|
+
throw new Error(`技能「${name}」未开放模型调用(modelInvocable=false,用户手势专用)——请改用 modelInvocable 技能,清单见 bufeng_capabilities action=list。`);
|
|
112
|
+
}
|
|
113
|
+
let note = null;
|
|
114
|
+
if (allowSkills) {
|
|
115
|
+
// 语义B:默认集(实时 source 判定)∪ 名单额外项
|
|
116
|
+
const isDefault = entry ? isDefaultSkillSource(entry.source) : false;
|
|
117
|
+
const extraHit = allowSkills.includes(name);
|
|
118
|
+
if (!entry && extraHit) {
|
|
119
|
+
// m00243 fail-visible:名单内但目录已无此技能(改名/下架)
|
|
120
|
+
throw new Error(`名单中的「${name}」已不在当前技能目录(可能改名或下架)。请有权限的总管/都管经 bufeng_update_node 修正该节点 allowSkills;当前可用技能见 bufeng_capabilities action=list。`);
|
|
121
|
+
}
|
|
122
|
+
if (!entry) {
|
|
123
|
+
throw new Error(`技能「${name}」不在当前技能目录。可用技能清单见 bufeng_capabilities action=list。`);
|
|
124
|
+
}
|
|
125
|
+
if (!isDefault && !extraHit) {
|
|
126
|
+
if (entry.source == null) note = '注:该技能缺 source 元数据,按非默认处理(语义B 兜底:缺失≠默认集)。';
|
|
127
|
+
throw new Error(`本节点技能白名单不含「${name}」:仅放行宿主默认集(source=bundled,实时解析)∪ allowSkills 额外项${note ? '(' + note + ')' : ''}。装备/增项走 bufeng_update_node(分级权限:总管配置自己与都管、都管配置名下成员);变更诉求可写进 bufeng_report 的 summary 上报。`);
|
|
128
|
+
}
|
|
129
|
+
if (isDefault && entry.source == null) note = '注:该技能缺 source 元数据,已按非默认处理并经名单放行。'; // 不可达路径(isDefault 蕴含 source 在场),防御性留注
|
|
130
|
+
} else if (!entry) {
|
|
131
|
+
throw new Error(`技能「${name}」不在当前技能目录。可用技能清单见 bufeng_capabilities action=list。`);
|
|
132
|
+
}
|
|
133
|
+
// 加载正文(renderSkillContent 同款路径:宿主 get(name))
|
|
134
|
+
let raw;
|
|
135
|
+
try {
|
|
136
|
+
raw = await reg.get(name);
|
|
137
|
+
if (raw && typeof raw === 'object' && typeof raw.then === 'function') raw = await raw;
|
|
138
|
+
} catch (e) {
|
|
139
|
+
throw new Error(`技能「${name}」正文读取失败(宿主 get() 抛错:${String(e?.message ?? e).slice(0, 140)})——请写进 bufeng_report 的 summary 上报。`);
|
|
140
|
+
}
|
|
141
|
+
const content = extractSkillContent(raw);
|
|
142
|
+
if (typeof content !== 'string' || !content.trim()) {
|
|
143
|
+
throw new Error(`技能「${name}」正文读取失败(宿主 get() 返回形状不认识:${raw === null ? 'null' : typeof raw})——请写进 bufeng_report 的 summary 上报。`);
|
|
144
|
+
}
|
|
145
|
+
// v0.29.3 热修:宿主未标注 source 时整键缺省(无事键缺省纪律),不再落 null——与单值 string schema 对齐
|
|
146
|
+
const out = {
|
|
147
|
+
ok: true,
|
|
148
|
+
name,
|
|
149
|
+
gated: allowSkills !== null,
|
|
150
|
+
defaultSkill: entry ? isDefaultSkillSource(entry.source) : false,
|
|
151
|
+
content
|
|
152
|
+
};
|
|
153
|
+
if (typeof entry?.source === 'string') out.source = entry.source;
|
|
154
|
+
if (allowSkills && entry?.source == null) out.note = '注:该技能缺 source 元数据,按非默认处理(语义B 兜底:缺失≠默认集)。';
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return 1;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { registerSkillTools, resolveSkillCallerNode, isDefaultSkillSource };
|
|
162
|
+
|