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.
@@ -0,0 +1,125 @@
1
+ /**
2
+ * 安装目标选择菜单(共享模块)
3
+ *
4
+ * 被 install.js 与 install-claude-code.js 共用,避免两套重复实现。
5
+ * 零依赖,手写 readline 按键处理:
6
+ * ↑/↓ 移动,Space 切换,Enter 确认,Ctrl+C 取消。
7
+ * 非 TTY 环境(CI、管道、重定向)直接返回全选,绝不卡住。
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ function log(msg) { console.log(msg); }
14
+
15
+ /**
16
+ * 目标探测:返回本机各平台的安装情况,用于菜单里标注。
17
+ *
18
+ * 只返回「是否检测到该平台目录」,不做任何写入。
19
+ */
20
+ function detectTargets(homeDir) {
21
+ return [
22
+ {
23
+ id: 'zcode',
24
+ label: 'ZCode',
25
+ hint: '~/.zcode',
26
+ detected: fs.existsSync(path.join(homeDir, '.zcode')),
27
+ },
28
+ {
29
+ id: 'claude-code',
30
+ label: 'Claude Code',
31
+ hint: '~/.claude',
32
+ detected: fs.existsSync(path.join(homeDir, '.claude')),
33
+ },
34
+ ];
35
+ }
36
+
37
+ /**
38
+ * 交互式多选菜单。
39
+ *
40
+ * 返回 Promise<string[]>(选中的 target id 列表)。
41
+ * 非 TTY 时回退为全选。
42
+ */
43
+ function selectTargets(options) {
44
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
45
+ log('(非交互终端,默认全选)');
46
+ return Promise.resolve(options.map((o) => o.id));
47
+ }
48
+
49
+ return new Promise((resolve) => {
50
+ const checked = options.map((o) => o.detected); // 检测到的默认勾选
51
+ let cursor = 0;
52
+
53
+ const render = (first) => {
54
+ if (!first) {
55
+ // 擦掉上一次渲染:光标上移 N 行,逐行清屏
56
+ process.stdout.write(`\x1b[${options.length + 3}A`);
57
+ for (let i = 0; i < options.length + 3; i += 1) {
58
+ process.stdout.write('\x1b[2K\x1b[1B');
59
+ }
60
+ process.stdout.write(`\x1b[${options.length + 3}A`);
61
+ }
62
+ const selectedCount = checked.filter(Boolean).length;
63
+ process.stdout.write(
64
+ `? 选择要安装到哪些工具(共 ${options.length} 个,已选 ${selectedCount})\n`
65
+ );
66
+ options.forEach((o, i) => {
67
+ const box = checked[i] ? '\x1b[36m◉\x1b[0m' : '\x1b[90m◯\x1b[0m';
68
+ const arrow = i === cursor ? '\x1b[36m❯\x1b[0m' : ' ';
69
+ const tag = o.detected ? ' \x1b[32m(detected)\x1b[0m' : '';
70
+ process.stdout.write(`${arrow} ${box} ${o.label}${tag} \x1b[90m${o.hint}\x1b[0m\n`);
71
+ });
72
+ process.stdout.write(
73
+ '\x1b[90m↑↓ 移动 · Space 切换 · Enter 确认 · Ctrl+C 取消\x1b[0m\n'
74
+ );
75
+ };
76
+
77
+ render(true);
78
+
79
+ const cleanup = () => {
80
+ process.stdin.setRawMode(false);
81
+ process.stdin.pause();
82
+ process.stdin.removeListener('data', onData);
83
+ process.stdout.removeListener('resize', onResize);
84
+ };
85
+
86
+ const onResize = () => render(false);
87
+
88
+ const onData = (chunk) => {
89
+ const key = chunk.toString();
90
+
91
+ if (key === '\u0003') { // Ctrl+C
92
+ cleanup();
93
+ process.stdout.write('\n');
94
+ log('已取消。');
95
+ process.exit(0);
96
+ } else if (key === '\r' || key === '\n') { // Enter
97
+ cleanup();
98
+ const chosen = options.filter((_, i) => checked[i]).map((o) => o.id);
99
+ if (chosen.length === 0) {
100
+ log('❌ 至少需要选择一个安装目标。');
101
+ process.exit(1);
102
+ }
103
+ render(false);
104
+ return resolve(chosen);
105
+ } else if (key === ' ') { // Space
106
+ checked[cursor] = !checked[cursor];
107
+ render(false);
108
+ } else if (key === '\u001b[A' || key === 'k') { // ↑
109
+ cursor = (cursor - 1 + options.length) % options.length;
110
+ render(false);
111
+ } else if (key === '\u001b[B' || key === 'j') { // ↓
112
+ cursor = (cursor + 1) % options.length;
113
+ render(false);
114
+ }
115
+ };
116
+
117
+ process.stdin.setRawMode(true);
118
+ process.stdin.resume();
119
+ process.stdin.setEncoding('utf8');
120
+ process.stdin.on('data', onData);
121
+ process.stdout.on('resize', onResize);
122
+ });
123
+ }
124
+
125
+ module.exports = { detectTargets, selectTargets, log };
@@ -1227,13 +1227,22 @@ def check_S8(ctx, rep, wf):
1227
1227
  status_path = os.path.join(ctx["change_dir"], ".status.json")
1228
1228
  status_text = read(status_path)
1229
1229
  parked_from_status = False
1230
+ status_corrupt = False
1230
1231
  if status_text is not None:
1231
1232
  try:
1232
1233
  status = json.loads(status_text)
1233
1234
  except (json.JSONDecodeError, ValueError):
1235
+ # M3 修复:损坏的 .status.json 必须产 malformed FAIL,不得静默置 {} 放行
1236
+ # (W8:PARKED 默认禁归档;元数据损坏时无法确认,必须显式告警)
1237
+ status_corrupt = True
1234
1238
  status = {}
1235
1239
  parked_from_status = _status_flag(status, "parked", "PARKED")
1236
- if parked_from_status:
1240
+ if status_corrupt:
1241
+ rep.add(label, "无 PARKED 残留(W8)", FAIL,
1242
+ "[malformed:status_json] .status.json 存在但无法解析——"
1243
+ "无法确认是否有 PARKED 残留,须修复元数据",
1244
+ id="S8.PARKED", reason="malformed:status_json")
1245
+ elif parked_from_status:
1237
1246
  rep.add(label, "无 PARKED 残留(W8)", FAIL,
1238
1247
  "[forbidden:parked] .status.json 中 parked=true——默认禁归档,须迁出到新 change",
1239
1248
  id="S8.PARKED", reason="forbidden:parked")
@@ -1858,11 +1867,15 @@ def _apply_ledger_scale_conflict(ctx, rep, wf, scale_key):
1858
1867
  return
1859
1868
  order = {k: i for i, k in enumerate(scale_keys(wf))}
1860
1869
  downgrade = order.get(scale_key, 99) < order.get(recorded, -1)
1870
+ # M1 修复:降级时产独立 reason=ratchet_downgrade,使门禁报告可机械识别降级;
1871
+ # 升级(非降级冲突)保持原 malformed:scale_conflict。两者均 FAIL,但 reason 区分。
1861
1872
  rep.add(gate_label(wf, "S0"), "规模与账本一致", FAIL,
1862
- "[malformed:scale_conflict] 账本记录 scale=%s,而 --scale=%s%s;"
1873
+ "[malformed:%s] 账本记录 scale=%s,而 --scale=%s%s;"
1863
1874
  "规模只能升级不能降级——请修正 --scale 或更新账本"
1864
- % (recorded, scale_key, "(疑似降级)" if downgrade else ""),
1865
- id="S0.SCALE_CONFLICT", reason="malformed:scale_conflict")
1875
+ % ("ratchet_downgrade" if downgrade else "scale_conflict",
1876
+ recorded, scale_key, "(疑似降级)" if downgrade else ""),
1877
+ id="S0.SCALE_CONFLICT",
1878
+ reason="ratchet_downgrade" if downgrade else "malformed:scale_conflict")
1866
1879
 
1867
1880
 
1868
1881
  def main(argv=None):
package/skill_entry.py CHANGED
@@ -108,7 +108,7 @@ def get_skill_info():
108
108
  """
109
109
  return {
110
110
  "name": "zcode-expert-system",
111
- "version": "3.2.1",
111
+ "version": "3.2.3",
112
112
  "description": "ZCode 专家体系 v3 - 基于 dsh-agency-agents 的 331 位专家,三层路由架构:LLM 分类(32 个一级大类)→ 32 个领域总经理任务分解 → 331 位领域专家执行",
113
113
  "input": {
114
114
  "task_description": {