zcode-expert-system 3.2.1 → 3.2.3
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/.claude-plugin/marketplace.json +15 -0
- package/.claude-plugin/plugin.json +11 -0
- package/.zcode-plugin/plugin.json +1 -1
- package/README.md +141 -9
- package/README_CN.md +154 -11
- package/SKILL.md +1 -1
- package/bin/cli.js +22 -5
- package/commands/wf/archive.md +111 -107
- package/commands/wf/check.md +68 -68
- package/commands/wf/dispatch.md +90 -76
- package/commands/wf/env.md +81 -81
- package/commands/wf/plan.md +78 -78
- package/commands/wf/resume.md +59 -59
- package/commands/wf/spec.md +88 -88
- package/commands/wf/triage.md +50 -50
- package/commands/wf/verify.md +93 -93
- package/config/experts.json +1 -1
- package/config/workflow.json +15 -14
- package/context/context-manager.py +26 -4
- package/hooks/claude-hooks.json +16 -0
- package/hooks/prepend-global-rules-reminder.mjs +342 -297
- package/icon.png +0 -0
- package/package.json +13 -2
- package/references/stage-S0-triage.md +68 -56
- package/references/stage-S2-spec.md +135 -134
- package/references/stage-S4-env-baseline.md +81 -80
- package/references/stage-S5-implement.md +139 -138
- package/references/stage-S8-sync-archive.md +168 -162
- package/scripts/cc-uninstall.js +123 -0
- package/scripts/install-claude-code.js +477 -0
- package/scripts/install.js +1601 -898
- package/scripts/openspec_engine.py +707 -632
- package/scripts/target-menu.js +125 -0
- package/scripts/workflow_check.py +17 -4
- package/skill_entry.py +1 -1
- package/zcode_dev_workflow.py +1343 -1136
- package/zcode_expert_system.py +106 -7
package/zcode_expert_system.py
CHANGED
|
@@ -98,10 +98,28 @@ KEYWORD_MAP = {
|
|
|
98
98
|
"渗透", "漏洞", "安全审计", "威胁检测", "威胁情报", "加密", "防火墙策略",
|
|
99
99
|
"安全架构", "secops", "密钥", "凭据", "安全评估", "红队", "合规审计",
|
|
100
100
|
"soc2", "iso27001", "等保", "身份与访问", "越权", "csp",
|
|
101
|
+
# R6:认证授权安全词元。jwt/oauth/token 同时声明在 backend-architecture(功能视角),
|
|
102
|
+
# 此处补入安全视角,靠声明序(security 在前)让安全事件胜出。
|
|
103
|
+
# 裸 jwt/oauth/token 与 backend 同长 → 触发同分决胜(security 在 :97 靠前),
|
|
104
|
+
# 安全事件(如"JWT token 泄漏应急")由此拉回 security-compliance。
|
|
105
|
+
# 注意:裸 token 会让"实现 token 刷新"这类功能任务同分落 security,
|
|
106
|
+
# 与裸 jwt 的边界取舍一致(方案预期内,业务边界模糊可接受)。
|
|
107
|
+
# 另补 token泄漏/泄露 复合词,覆盖中文连写场景。
|
|
108
|
+
"jwt", "oauth", "token", "应急响应", "安全事件", "安全事故",
|
|
109
|
+
"token泄漏", "token泄露", "jwt泄漏", "jwt泄露",
|
|
110
|
+
# R7:补入「安全审查」「代码审计」——带安全意图的审查正确路由到 security。
|
|
111
|
+
"安全审查", "代码审计",
|
|
112
|
+
# H1 修复:补入「sql注入」「注入漏洞」「渗透测试」等复合词(长度≥4),
|
|
113
|
+
# 压过 data-database 的裸 sql(长度3)。否则「渗透测试发现 SQL 注入漏洞」
|
|
114
|
+
# 会被 data-database 的 sql 劫持(最长关键词独胜),误路由到数据库领域。
|
|
115
|
+
# 裸「渗透」「漏洞」保留(长度2),用于无 sql 语境的安全任务。
|
|
116
|
+
"sql注入", "注入漏洞", "渗透测试", "注入攻击", "sql注入漏洞",
|
|
101
117
|
],
|
|
102
118
|
"legal-compliance": [
|
|
103
119
|
"合同审查", "合同起草", "合同条款", "法律", "合规", "诉讼", "知识产权",
|
|
104
120
|
"专利", "商标", "法务", "法规", "制度文件", "隐私政策", "用户协议", "律所",
|
|
121
|
+
# R7:「合规检查」从 engineering-quality 迁入——合规语义归法律合规。
|
|
122
|
+
"合规检查",
|
|
105
123
|
],
|
|
106
124
|
"finance-tax": [
|
|
107
125
|
"财务", "会计", "预算", "发票", "报销", "账单", "理财", "税务", "纳税",
|
|
@@ -219,6 +237,13 @@ KEYWORD_MAP = {
|
|
|
219
237
|
"小程序",
|
|
220
238
|
"白屏",
|
|
221
239
|
"首屏",
|
|
240
|
+
# I-4:「博客」此前不在任何分类词表,「搭建一个博客系统」在退化二
|
|
241
|
+
# 打分里仅靠泛化词「一个」(STOP_TOKEN)与 hr「招一个」词元重叠,
|
|
242
|
+
# 以 0.0357×0.75=0.0268 的噪声分误路由 hr。补词后走精确关键词命中。
|
|
243
|
+
# 子串碰撞裁决:「博客园」等站点名会连带命中——爬取类任务从
|
|
244
|
+
# conf=0 兜底变为 frontend-client,属可接受轻度偏航(有测试守护
|
|
245
|
+
# 不得落入 hr/healthcare/finance 等明显无关域)。
|
|
246
|
+
"博客",
|
|
222
247
|
],
|
|
223
248
|
"backend-architecture": [
|
|
224
249
|
"后端", "api", "restful", "graphql", "grpc", "微服务", "服务端", "cms",
|
|
@@ -301,13 +326,18 @@ KEYWORD_MAP = {
|
|
|
301
326
|
# 这类任务误落 business-support 兜底导致无专家可派。
|
|
302
327
|
# 注意:不单独加「评估」——security-compliance 的「安全评估」已含词元
|
|
303
328
|
# "评估",单独加会制造跨类并列并破坏同分决胜的声明序契约;改用更具体的短语。
|
|
304
|
-
"审查", "诊断", "梳理", "检查", "冲突", "问题排查", "代码检查",
|
|
329
|
+
"审查", "诊断", "梳理", "检查", "冲突", "问题排查", "代码检查",
|
|
330
|
+
# R7:移除「合规检查」——合规属 legal-compliance/security-compliance,
|
|
331
|
+
# 放在通用工程词里是错位。合规语义由 legal-compliance 的「合规」承接。
|
|
305
332
|
],
|
|
306
333
|
# ---- 兜底:极通用词 ----
|
|
307
334
|
"business-support": [
|
|
308
335
|
# 「客户服务」只归 customer-support——本类是兜底类,不该持有抢具体类的词
|
|
336
|
+
# R8:移除「翻译服务」——它属 language-translation 的具体业务词,
|
|
337
|
+
# 4 字最长命中会压过 language-translation 的「翻译」(2字),导致
|
|
338
|
+
# "提供翻译服务"被兜底类抢走。移除后「翻译」自然命中 language-translation。
|
|
309
339
|
"酒店", "零售", "退货", "房地产", "旅行", "会议效率",
|
|
310
|
-
"个人成长", "
|
|
340
|
+
"个人成长", "养殖",
|
|
311
341
|
],
|
|
312
342
|
}
|
|
313
343
|
|
|
@@ -654,6 +684,19 @@ def llm_verdict(task_description, top_candidates, return_basis=False):
|
|
|
654
684
|
if best_score <= 0.0:
|
|
655
685
|
return (None, "heuristic") if return_basis else None
|
|
656
686
|
|
|
687
|
+
# 退化为精确相等比较:得分是浮点数,ratio 归一后才比较。
|
|
688
|
+
# 判平标记(P4,2026-11-23):`best_score` 若只由一个候选独占,主控可以信
|
|
689
|
+
# 「分最高」;若多个候选并列,最终选择退化为「取候选顺序最靠前者」,
|
|
690
|
+
# 那一票没有任何语义依据。旧实现不暴露这个区别——主控看到 0.1667
|
|
691
|
+
# 无法判断是「唯一最高」还是「并列取首」。
|
|
692
|
+
# 实测:任务「审查并验证…插件…」两候选都是 0.1667,name_hits 分别为 1 和 2,
|
|
693
|
+
# 按顺序取了 name_hits=1 的那个。这里在候选上打 tied 标记,并在
|
|
694
|
+
# score_breakdown 里带出 tied_count,让复核者一眼看出该不该改判。
|
|
695
|
+
tied = [e for score, _idx, e in scored if score == best_score]
|
|
696
|
+
tied_count = len(tied)
|
|
697
|
+
for score, _idx, expert in scored:
|
|
698
|
+
expert["tied"] = (score == best_score and tied_count > 1)
|
|
699
|
+
|
|
657
700
|
# 同分时取候选顺序最靠前者(稳定决胜,结果与输入顺序一致而非随机)
|
|
658
701
|
for score, _idx, expert in scored:
|
|
659
702
|
if score == best_score:
|
|
@@ -666,6 +709,10 @@ def score_breakdown(task_description, expert):
|
|
|
666
709
|
|
|
667
710
|
主控做语义精判时靠这个明细判断 Python 的排序是否可信——
|
|
668
711
|
例如「飞书集成开发工程师 desc_hits=1 命中『登录』」一眼就能看出是词面巧合。
|
|
712
|
+
|
|
713
|
+
tied(P4):该候选是否与首名**并列最高分**。True 时最终选择退化为
|
|
714
|
+
「取候选顺序最靠前者」,那一票没有语义依据——必须按业务语义改判,
|
|
715
|
+
不能因为「它在第一位」就采信。
|
|
669
716
|
"""
|
|
670
717
|
task_tokens = _tokenize(task_description)
|
|
671
718
|
effective = {t for t in task_tokens if t not in STOP_TOKENS} or task_tokens
|
|
@@ -679,6 +726,7 @@ def score_breakdown(task_description, expert):
|
|
|
679
726
|
"matched_in_name": sorted(name_hits),
|
|
680
727
|
"matched_in_desc": sorted(desc_hits),
|
|
681
728
|
"raw_score": round(_keyword_score_raw(task_tokens, expert), 4),
|
|
729
|
+
"tied": bool(expert.get("tied", False)),
|
|
682
730
|
}
|
|
683
731
|
|
|
684
732
|
|
|
@@ -702,7 +750,15 @@ def build_dispatch_for_expert(expert_name, task_description, context_summary="",
|
|
|
702
750
|
target = e
|
|
703
751
|
break
|
|
704
752
|
if target is None:
|
|
705
|
-
|
|
753
|
+
# N-04:给出近似专家名建议,降低主控排查成本(如「后端架构市」→「后端架构师」)。
|
|
754
|
+
# 仍抛 ValueError 不静默降级——建议只是错误信息的一部分。
|
|
755
|
+
import difflib
|
|
756
|
+
names = [e.get("name") for e in all_experts if e.get("name")]
|
|
757
|
+
close = difflib.get_close_matches(expert_name or "", names, n=3, cutoff=0.5)
|
|
758
|
+
hint = (";最接近的是:%s" % "、".join(close)) if close else ""
|
|
759
|
+
raise ValueError(
|
|
760
|
+
"未找到专家:%r%s。可用 zcode_expert_system.load_experts() 查看全部 %d 位专家名。"
|
|
761
|
+
% (expert_name, hint, len(names)))
|
|
706
762
|
return dispatch_expert(target, task_description, context_summary,
|
|
707
763
|
role_prefix=role_prefix)
|
|
708
764
|
|
|
@@ -720,7 +776,9 @@ def dispatch_manager(category, task_description, selected_expert, top_candidates
|
|
|
720
776
|
manager_result = {
|
|
721
777
|
"agent": manager_id,
|
|
722
778
|
"category": category,
|
|
723
|
-
|
|
779
|
+
# L1 修复:无专家时 status 为 no_expert(与 expert_result.skipped 对齐),
|
|
780
|
+
# 有专家时才为 dispatched/plan_ready。避免消费方误判总经理派发成功。
|
|
781
|
+
"status": "dispatched" if selected_expert else "no_expert",
|
|
724
782
|
"plan": [],
|
|
725
783
|
"assigned_expert": selected_expert,
|
|
726
784
|
"candidates": top_candidates,
|
|
@@ -744,6 +802,17 @@ def dispatch_manager(category, task_description, selected_expert, top_candidates
|
|
|
744
802
|
return manager_result
|
|
745
803
|
|
|
746
804
|
|
|
805
|
+
def _qualified_subagent_type(expert_name):
|
|
806
|
+
"""按运行平台决定子代理派发名。
|
|
807
|
+
|
|
808
|
+
Claude Code 要求 <插件名>:<frontmatter.name> 的限定形式;
|
|
809
|
+
ZCode 使用中文裸名。用 CLAUDE_PLUGIN_ROOT 是否注入作判据。
|
|
810
|
+
"""
|
|
811
|
+
if os.environ.get("CLAUDE_PLUGIN_ROOT"):
|
|
812
|
+
return "zcode-expert-system:%s" % expert_name
|
|
813
|
+
return expert_name
|
|
814
|
+
|
|
815
|
+
|
|
747
816
|
def dispatch_expert(selected_expert, task_description, context_summary="", role_prefix=""):
|
|
748
817
|
"""
|
|
749
818
|
生成专家派发指令(本模块不直接调用 Agent 工具)。
|
|
@@ -784,7 +853,7 @@ def dispatch_expert(selected_expert, task_description, context_summary="", role_
|
|
|
784
853
|
"status": "pending_dispatch",
|
|
785
854
|
"dispatch": {
|
|
786
855
|
"tool": "Agent",
|
|
787
|
-
"subagent_type": expert_name,
|
|
856
|
+
"subagent_type": _qualified_subagent_type(expert_name),
|
|
788
857
|
"description": f"{expert_name} 执行任务",
|
|
789
858
|
"prompt": prompt,
|
|
790
859
|
},
|
|
@@ -810,7 +879,11 @@ def build_context(task_id, category, manager_id, top_candidates, selected_expert
|
|
|
810
879
|
from datetime import datetime
|
|
811
880
|
|
|
812
881
|
context = {
|
|
813
|
-
|
|
882
|
+
# N-06:task_id 精度由秒级提升到微秒级(%f),与 context-manager.py
|
|
883
|
+
# 的 result 文件名口径(%Y%m%d-%H%M%S%f)一致。秒级下同一秒内两次
|
|
884
|
+
# 独立调用生成相同 task_id,导致 _load_context_summary 按 task_id
|
|
885
|
+
# 回填时,第二个任务读到第一个任务的历史摘要并注入派发单。
|
|
886
|
+
"task_id": task_id or f"task-{datetime.now().strftime('%Y%m%d-%H%M%S%f')}",
|
|
814
887
|
"category": category,
|
|
815
888
|
"manager_id": manager_id,
|
|
816
889
|
"top_candidates": top_candidates,
|
|
@@ -892,7 +965,7 @@ def zcode_expert_system(task_description, task_id=None, persist=True):
|
|
|
892
965
|
# 获取该分类下的所有专家
|
|
893
966
|
candidates = get_experts_by_category(category)
|
|
894
967
|
|
|
895
|
-
|
|
968
|
+
# 分类完全无信号时,不再往下挑专家。
|
|
896
969
|
# 理由:conf=0 说明任务描述与 32 个分类毫无匹配,此时在 DEFAULT_CATEGORY
|
|
897
970
|
# 里挑专家只能靠泛化词的微小词元重叠(实测「写个季度汇报」会选中
|
|
898
971
|
# 旅行规划师,score=0.067),属于纯粹的数字巧合,不是相关性判断。
|
|
@@ -914,6 +987,15 @@ def zcode_expert_system(task_description, task_id=None, persist=True):
|
|
|
914
987
|
e["score"] = round(_keyword_score(_task_tokens_for_score, e), 4)
|
|
915
988
|
e["score_detail"] = score_breakdown(task_description, e)
|
|
916
989
|
|
|
990
|
+
# H2 修复:分类置信度 >0 但无匹配专家时,显式暴露矛盾,避免满分置信度误导消费方。
|
|
991
|
+
# 仅当 confidence>0 且 selected_expert is None 时置 no_expert=True,并把 confidence
|
|
992
|
+
# 降为 0.0(与 conf=0 的「无信号」语义对齐),同时 semantic_selection_required
|
|
993
|
+
# 仍为 True(LLM 不可用时精判仍待主控)。这样消费方按 conf 判断不会误判满分。
|
|
994
|
+
no_expert = False
|
|
995
|
+
if confidence > 0.0 and selected_expert is None:
|
|
996
|
+
no_expert = True
|
|
997
|
+
confidence = 0.0
|
|
998
|
+
|
|
917
999
|
# 语义精判是否仍待主控完成:LLM 不可用时 Python 的挑选只是词元计数,
|
|
918
1000
|
# 不是语义判断。必须显式暴露,否则主控会直接采信错误结果。
|
|
919
1001
|
semantic_selection_required = (selection_basis != "semantic") and bool(top_candidates)
|
|
@@ -982,6 +1064,17 @@ def zcode_expert_system(task_description, task_id=None, persist=True):
|
|
|
982
1064
|
% (confidence, LOW_CONFIDENCE_THRESHOLD, category,
|
|
983
1065
|
(",备选:" + "、".join(alternatives)) if alternatives else "")
|
|
984
1066
|
)
|
|
1067
|
+
# P4:判平必须说出口——同分时 selected_expert 只是「候选顺序靠前者」,
|
|
1068
|
+
# 那一票没有语义依据。不说出来,主控会把并列当唯一最高直接采信。
|
|
1069
|
+
tied_names = [e.get("name") for e in top_candidates if e.get("tied")]
|
|
1070
|
+
if len(tied_names) > 1:
|
|
1071
|
+
warnings.append(
|
|
1072
|
+
"判平:最高分 %.4f 由 %d 位候选并列(%s),selected_expert 只是"
|
|
1073
|
+
"「候选顺序最靠前者」——这一票没有语义依据,必须按业务语义改判,"
|
|
1074
|
+
"不得因它在第一位而采信。"
|
|
1075
|
+
% (max([e.get("score") or 0 for e in top_candidates] or [0]),
|
|
1076
|
+
len(tied_names), "、".join(n for n in tied_names if n))
|
|
1077
|
+
)
|
|
985
1078
|
if warnings:
|
|
986
1079
|
routing_warning = " ".join(warnings)
|
|
987
1080
|
|
|
@@ -990,6 +1083,12 @@ def zcode_expert_system(task_description, task_id=None, persist=True):
|
|
|
990
1083
|
"confidence": confidence,
|
|
991
1084
|
"alternatives": alternatives,
|
|
992
1085
|
"routing_warning": routing_warning,
|
|
1086
|
+
# H2 修复标记:分类置信度>0 但无匹配专家时置 True,消费方据此不得按 conf 直接派发
|
|
1087
|
+
"no_expert": no_expert,
|
|
1088
|
+
# 判平标记(P4):最高分是否由多个候选并列——True 时 selected_expert
|
|
1089
|
+
# 的取胜依据是「候选顺序」而非分值,主控必须改判或明示采信理由。
|
|
1090
|
+
# 的取胜依据是「候选顺序」而非分值,主控必须改判或明示采信理由。
|
|
1091
|
+
"score_tied": len([e for e in top_candidates if e.get("tied")]) > 1,
|
|
993
1092
|
# 语义精判是否仍待主控完成(True 时不得直接采信 selected_expert)
|
|
994
1093
|
"semantic_selection_required": semantic_selection_required,
|
|
995
1094
|
# 本次选择的依据:semantic=模型判过 / heuristic=词元计数 / none=无候选
|