dsh-punky-swarm 0.3.6

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/LICENSE +661 -0
  3. package/README.en.md +281 -0
  4. package/README.md +281 -0
  5. package/cordis.patch.yml +59 -0
  6. package/lib/acps/certs.js +310 -0
  7. package/lib/acps/discovery-client.js +283 -0
  8. package/lib/acps/registry-client.js +527 -0
  9. package/lib/acps/server.js +302 -0
  10. package/lib/aip/agent-descriptor.js +170 -0
  11. package/lib/aip/identity.js +469 -0
  12. package/lib/aip/tool-descriptor.js +93 -0
  13. package/lib/api.js +266 -0
  14. package/lib/artifact-types.js +48 -0
  15. package/lib/assembly/audit-blind-review.js +170 -0
  16. package/lib/assembly/schema.js +253 -0
  17. package/lib/assembly.js +41 -0
  18. package/lib/assets.js +103 -0
  19. package/lib/bridge/trajectory.js +202 -0
  20. package/lib/client.js +704 -0
  21. package/lib/comms/acps-bridge.js +219 -0
  22. package/lib/comms/aip-format.js +141 -0
  23. package/lib/comms/budget.js +124 -0
  24. package/lib/comms/mailbox.js +221 -0
  25. package/lib/comms/topic-runtime.js +76 -0
  26. package/lib/comms/topic.js +115 -0
  27. package/lib/discovery/filter.js +199 -0
  28. package/lib/discovery/schema.js +157 -0
  29. package/lib/discovery/service.js +251 -0
  30. package/lib/hot/config-watch.js +252 -0
  31. package/lib/index.js +433 -0
  32. package/lib/lock.js +69 -0
  33. package/lib/panel/batch-detail.js +163 -0
  34. package/lib/panel/batch-list.js +84 -0
  35. package/lib/panel/locales.js +93 -0
  36. package/lib/panel/main.js +270 -0
  37. package/lib/panel/stream.js +348 -0
  38. package/lib/panel/theme.js +103 -0
  39. package/lib/panel/widgets.js +63 -0
  40. package/lib/schema.d.ts +192 -0
  41. package/lib/schema.js +259 -0
  42. package/lib/schema.ts +398 -0
  43. package/lib/state/archive.js +174 -0
  44. package/lib/state/command-exec.js +148 -0
  45. package/lib/state/constants.js +37 -0
  46. package/lib/state/corrupt-registry.js +103 -0
  47. package/lib/state/event-types.js +65 -0
  48. package/lib/state/gates.d.ts +226 -0
  49. package/lib/state/gates.js +428 -0
  50. package/lib/state/gates.ts +348 -0
  51. package/lib/state/machine-rules.d.ts +14 -0
  52. package/lib/state/machine-rules.js +76 -0
  53. package/lib/state/machine-rules.ts +88 -0
  54. package/lib/state/machine.js +68 -0
  55. package/lib/state/resume.js +201 -0
  56. package/lib/state/schema-v3.d.ts +10 -0
  57. package/lib/state/schema-v3.js +57 -0
  58. package/lib/state/schema-v3.ts +80 -0
  59. package/lib/state/store.js +607 -0
  60. package/lib/state/task-utils.js +40 -0
  61. package/lib/tools/core.js +323 -0
  62. package/lib/tools/git-utils.js +44 -0
  63. package/lib/tools/lane-tools.js +455 -0
  64. package/lib/tools/log-tools.js +173 -0
  65. package/lib/tools/mailbox-tools.js +121 -0
  66. package/lib/tools/merge-agent.js +127 -0
  67. package/lib/tools/register.js +85 -0
  68. package/lib/tools/shared.js +32 -0
  69. package/lib/types/contracts.d.ts +277 -0
  70. package/lib/types/contracts.js +17 -0
  71. package/lib/types/contracts.ts +279 -0
  72. package/lib/verify/evidence.js +249 -0
  73. package/lib/verify/gate.js +161 -0
  74. package/lib/verify/mount.js +48 -0
  75. package/lib/verify/selector.js +101 -0
  76. package/lib/watch/lane-heartbeat.js +333 -0
  77. package/lib/wave-plan.d.ts +48 -0
  78. package/lib/wave-plan.js +473 -0
  79. package/lib/wave-plan.ts +465 -0
  80. package/package.json +71 -0
  81. package/presets/jiufeng/NOTICE +5 -0
  82. package/presets/jiufeng/agent.cordis.yml +275 -0
  83. package/presets/jiufeng/preset.yml +3 -0
  84. package/skills/jiufeng-team/SKILL.md +214 -0
  85. package/skills/jiufeng-team/references/constitution.md +62 -0
  86. package/skills/jiufeng-team/references/roles/coder.md +17 -0
  87. package/skills/jiufeng-team/references/roles/coordinator.md +13 -0
  88. package/skills/jiufeng-team/references/roles/designer.md +14 -0
  89. package/skills/jiufeng-team/references/roles/doc-manager.md +13 -0
  90. package/skills/jiufeng-team/references/roles/manager.md +22 -0
  91. package/skills/jiufeng-team/references/roles/reviewer.md +19 -0
  92. package/skills/jiufeng-team/references/roles/supervisor.md +13 -0
  93. package/skills/jiufeng-team/references/roles/tester.md +13 -0
  94. package/skills/jiufeng-team/references/templates/call-chain-matrix-template.md +121 -0
  95. package/skills/jiufeng-team/references/templates/endpoint-behavior-template.md +60 -0
  96. package/skills/jiufeng-team/references/templates/gap-list.json +33 -0
  97. package/skills/jiufeng-team/references/templates/leader-decision-pack.md +92 -0
  98. package/skills/jiufeng-team/references/templates/plan-template.md +61 -0
  99. package/skills/jiufeng-team/references/templates/success-pattern-seeds.md +126 -0
  100. package/skills/jiufeng-team/references/workflow.md +98 -0
  101. package/skills/jiufeng-team/scripts/check-v3-density.mjs +98 -0
@@ -0,0 +1,148 @@
1
+ /*
2
+ Copyright (C) 2025-2026 Punky
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ // command-exec:命令 gate(V1)确定性执行器(设计 §组件 3 / spec G4-G8、C6-C7)
19
+ // 接口:runCommand({ command, cwd, timeoutMs, retries, env, forbiddenRe, maxOutputBytes }) → { ok, exitCode, output(截断), durationMs, timedOut, forbidden, error }
20
+ // 语义:仅退出码判定(exit 0 = 通过;非 0 = 失败,不解析 stdout);超时 kill;重试容忍瞬态失败;黑名单只读守卫(命中不执行);
21
+ // 凭据只走 env 注入(不入文件/日志/输出);输出截断入审计。
22
+ // 实现决策(同步执行器):store.setMember 为同步 API(既有工具/测试全同步调用),merged 前置门禁须同步判定;
23
+ // runCommand 采用 spawnSync(child_process.spawn 家族同步形态),接口契约与 design 一致(参数/返回不变),
24
+ // 不异步化 setMember,保持既有调用点零破坏(C2 签名零改动、既有测试基线只增不减)。
25
+ // 超时:spawnSync timeout + killSignal(Windows 上 SIGTERM/SIGKILL 均映射 TerminateProcess,两段式在同步执行器中等价;
26
+ // POSIX 两段式 kill 若需细化留 V2 评估——见 code-change-summary 披露)。
27
+ import { spawnSync } from 'node:child_process';
28
+
29
+ // ---- 默认值(env 可调,全部有默认)----
30
+ export function envNumber(name, def) {
31
+ const v = Number(process.env[name]);
32
+ return Number.isFinite(v) && v > 0 ? v : def;
33
+ }
34
+
35
+ // 黑名单初始清单(coder 拟定,tester 验证补充——spec Open Questions):
36
+ // 破坏性(rm -rf / drop / mkfs / format / dd)/ 部署与发布类(git push / npm publish / kubectl / terraform / helm /
37
+ // ansible / 部署脚本)/ 覆盖与系统类(chmod -R 777 / shutdown / reboot / poweroff / fork bomb / sudo 提权)
38
+ export const DEFAULT_FORBIDDEN_PATTERNS = [
39
+ /\brm\s+-rf\b/i,
40
+ /\brm\s+-fr\b/i,
41
+ /\brm\s+-[a-zA-Z]*r[a-zA-Z]*f[a-zA-Z]*\b/i,
42
+ /\bdrop\s+database\b/i,
43
+ /\bdrop\s+table\b/i,
44
+ /\bmkfs(\.\w+)?\b/i,
45
+ /\bformat\s+[a-zA-Z]:/i,
46
+ /\bdd\s+if=/,
47
+ /\bgit\s+push\b/i,
48
+ /\bnpm\s+publish\b/i,
49
+ /\byarn\s+publish\b/i,
50
+ /\bpnpm\s+publish\b/i,
51
+ /\bkubectl\s+(apply|delete|destroy|replace)\b/i,
52
+ /\bterraform\s+(apply|destroy)\b/i,
53
+ /\bhelm\s+(install|upgrade|delete|uninstall)\b/i,
54
+ /\bansible-playbook\b/i,
55
+ /(^|[\s;&|])\.?\/?(deploy|release|publish|install)\.(sh|ps1|bat|cmd)\b/i,
56
+ /\bchmod\s+-R\s+777\b/i,
57
+ /\bshutdown\b/i,
58
+ /\breboot\b/i,
59
+ /\bpoweroff\b/i,
60
+ /\bsudo\b/i,
61
+ /:\(\)\s*\{\s*:\|\s*:\s*&\s*\}\s*;?/,
62
+ ];
63
+
64
+ // GATE_FORBIDDEN_RE env 覆盖(JSON 字符串数组,如 '["\\\\brm\\\\s+-rf\\\\b"]');解析失败回退默认清单
65
+ export function forbiddenReFromEnv() {
66
+ const raw = process.env.GATE_FORBIDDEN_RE;
67
+ if (!raw) return DEFAULT_FORBIDDEN_PATTERNS;
68
+ try {
69
+ const arr = JSON.parse(raw);
70
+ if (Array.isArray(arr) && arr.length > 0) return arr.map((s) => new RegExp(s, 'i'));
71
+ } catch { /* 无效配置回退默认(fail-closed 倾向默认清单) */ }
72
+ return DEFAULT_FORBIDDEN_PATTERNS;
73
+ }
74
+
75
+ // 统一黑名单判定:单个 RegExp 或 RegExp[];/g 正则 lastIndex 重置防状态泄漏
76
+ export function matchesForbidden(command, patterns) {
77
+ const list = Array.isArray(patterns) ? patterns : [patterns];
78
+ for (const re of list) {
79
+ if (!(re instanceof RegExp)) continue;
80
+ re.lastIndex = 0;
81
+ if (re.test(command)) return true;
82
+ }
83
+ return false;
84
+ }
85
+
86
+ // 输出截断(默认 8192B,截断部分入审计事件由调用方记录)
87
+ export function truncateOutput(buf, maxBytes) {
88
+ const s = typeof buf === 'string' ? buf : String(buf ?? '');
89
+ if (s.length <= maxBytes) return { output: s, truncated: false };
90
+ return { output: s.slice(0, maxBytes), truncated: true };
91
+ }
92
+
93
+ function execOnce(command, { cwd, timeoutMs, env, maxOutputBytes }) {
94
+ const start = Date.now();
95
+ // maxBuffer 宽松兜底(保证命令能跑完、退出码可取),审计截断由 truncateOutput 自行完成;
96
+ // 输出超 maxBuffer(默认 1MB,随 maxOutputBytes 抬升)视为 spawn 级异常(GATE_EXIT_SPAWN_FAIL),诚实披露
97
+ const maxBuffer = Math.max(1024 * 1024, maxOutputBytes + 4096);
98
+ const r = spawnSync(command, {
99
+ cwd,
100
+ env,
101
+ shell: true,
102
+ windowsHide: true,
103
+ timeout: timeoutMs,
104
+ killSignal: 'SIGTERM',
105
+ maxBuffer,
106
+ encoding: 'utf8',
107
+ });
108
+ const durationMs = Date.now() - start;
109
+ const timedOut = r.error && (r.error.code === 'ETIMEDOUT' || r.signal === 'SIGTERM');
110
+ const raw = String(r.stdout ?? '') + String(r.stderr ?? '');
111
+ const { output, truncated } = truncateOutput(raw, maxOutputBytes);
112
+ if (r.error && !timedOut) {
113
+ // spawn 异常(cwd 无效、shell 不可用、输出超 maxBuffer 等)——声明不可执行语义
114
+ return { ok: false, exitCode: r.status ?? null, output, durationMs, timedOut: false, forbidden: false, truncated, error: 'GATE_EXIT_SPAWN_FAIL: ' + (r.error.message ?? String(r.error)) };
115
+ }
116
+ if (timedOut) {
117
+ return { ok: false, exitCode: r.status ?? null, output, durationMs, timedOut: true, forbidden: false, truncated, error: 'GATE_EXIT_TIMEOUT' };
118
+ }
119
+ return { ok: r.status === 0, exitCode: r.status, output, durationMs, timedOut: false, forbidden: false, truncated, error: null };
120
+ }
121
+
122
+ /**
123
+ * 确定性命令执行:黑名单 → 执行(超时 kill + 退出码判定)→ 非 0/超时按 retries 重试 → 仍失败返回失败。
124
+ * @param {{command: string, cwd?: string, timeoutMs?: number, retries?: number, env?: object, forbiddenRe?: RegExp|RegExp[], maxOutputBytes?: number}} opts
125
+ * @returns {{ok: boolean, exitCode: number|null, output: string, durationMs: number, timedOut: boolean, forbidden: boolean, truncated: boolean, error: string|null}}
126
+ */
127
+ export function runCommand(opts = {}) {
128
+ const command = opts.command;
129
+ const timeoutMs = opts.timeoutMs ?? envNumber('GATE_TIMEOUT_MS', 120000);
130
+ const retries = opts.retries ?? envNumber('GATE_RETRY', 1);
131
+ const maxOutputBytes = opts.maxOutputBytes ?? envNumber('GATE_MAX_OUTPUT_BYTES', 8192);
132
+ const forbiddenRe = opts.forbiddenRe ?? forbiddenReFromEnv();
133
+ const env = opts.env !== undefined ? opts.env : process.env;
134
+ const cwd = opts.cwd;
135
+
136
+ if (typeof command !== 'string' || command.trim() === '') {
137
+ return { ok: false, exitCode: null, output: '', durationMs: 0, timedOut: false, forbidden: false, truncated: false, error: 'GATE_EXIT_NO_COMMAND' };
138
+ }
139
+ if (matchesForbidden(command, forbiddenRe)) {
140
+ return { ok: false, exitCode: null, output: '', durationMs: 0, timedOut: false, forbidden: true, truncated: false, error: 'GATE_EXIT_FORBIDDEN' };
141
+ }
142
+ let last = null;
143
+ for (let attempt = 0; attempt <= retries; attempt++) {
144
+ last = execOnce(command, { cwd, timeoutMs, env, maxOutputBytes });
145
+ if (last.ok) break; // 成功即停(重试仅容忍瞬态失败)
146
+ }
147
+ return last;
148
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright (C) 2025-2026 Punky
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ // lib/state/constants.js —— 标识符/路径校验常量单点(P1-07 收敛)
19
+ // 零依赖纯常量/纯函数模块:不 import 任何本包模块(避免循环依赖)。
20
+ // 消费方:store/gates/archive/corrupt-registry/evidence/log-tools/lane-tools/
21
+ // wave-plan/lane-heartbeat/client/panel 等(见契约 P1-07 消费点清单)。
22
+ // 浏览器端面板段(lib/panel/*.js 与 lib/client.js 合成 bundle)无 ESM import 能力,
23
+ // 其 TERMINAL 为手工同步副本(见该处注释),Node 端单点以本文件为准。
24
+
25
+ // 会话/批次/lane ID 合法字符集(原先散落 6 处:store/gates/archive/corrupt-registry/evidence/log-tools/lane-tools)
26
+ export const SAFE_ID = /^[a-zA-Z0-9._-]+$/;
27
+
28
+ // 兼容别名(既有消费方以 SESSION_RE 命名的正则,与 SAFE_ID 同款同引用)
29
+ export const SESSION_RE = SAFE_ID;
30
+
31
+ // 绝对路径判定(原 gates.js isAbsPath 现实现:盘符前缀 / UNC 反斜杠 / POSIX 根斜杠)
32
+ export function isAbsPath(p) {
33
+ return /^[A-Za-z]:[\\/]|^\\|^\//.test(p);
34
+ }
35
+
36
+ // 成员终态数组(原散落 3 处:log-tools / client.js / panel main.js;batch-list/batch-detail 引用共享段定义)
37
+ export const TERMINAL = ['merged', 'failed', 'skipped', 'conflict'];
@@ -0,0 +1,103 @@
1
+ /*
2
+ Copyright (C) 2025-2026 Punky
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ // 损坏批次旁路清单(v2-node-robustness ②,设计 D-001)
19
+ // 批次 JSON 唯一事实源结构零变更;损坏隔离信息走会话级旁路清单 corrupt-batches.json
20
+ // (<sessionDir>/corrupt-batches.json,与 governance.json 同层同级)。
21
+ // 语义:损坏批次无法写入 batch 文件本身(文件已坏),故隔离以「清单状态 + logger 留痕」呈现;
22
+ // 损坏文件本体保留现场供人工抢救(damaged-file-restoration 技能路线),
23
+ // 人工修复/删除文件后调 clearCorruptMark 清除标记。
24
+ // 容错:清单文件自身损坏 → 读降级空清单(governance.json 同款 try/catch 模式),不 throw。
25
+ import fs from 'node:fs';
26
+ import path from 'node:path';
27
+ import { SESSION_RE } from './constants.js'; // P1-07 单点(原 :29 定义迁出)
28
+
29
+ const CORRUPT_SCHEMA = 1;
30
+
31
+ // 清单文件路径(会话级;与 store.sessionDir 同源解析——root/sessions/<sessionId>/)
32
+ export function corruptFileOf(root, sessionId) {
33
+ if (!SESSION_RE.test(sessionId)) throw new Error('invalid sessionId: ' + sessionId);
34
+ return path.join(root, 'sessions', sessionId, 'corrupt-batches.json');
35
+ }
36
+
37
+ export function createCorruptRegistry(root) {
38
+ function readList(sessionId) {
39
+ const file = corruptFileOf(root, sessionId);
40
+ if (!fs.existsSync(file)) return [];
41
+ try {
42
+ const data = JSON.parse(fs.readFileSync(file, 'utf8'));
43
+ return Array.isArray(data?.corrupt) ? data.corrupt : [];
44
+ } catch {
45
+ return []; // 清单自身损坏 → 降级空清单(不 throw;人工重建)
46
+ }
47
+ }
48
+
49
+ // 原子写(与 store.atomicWrite 同模式:tmp + rename,防半写)
50
+ function writeList(sessionId, list) {
51
+ const file = corruptFileOf(root, sessionId);
52
+ fs.mkdirSync(path.dirname(file), { recursive: true });
53
+ const tmp = file + '.' + process.pid + '.tmp';
54
+ fs.writeFileSync(tmp, JSON.stringify({ schema: CORRUPT_SCHEMA, corrupt: list }, null, 2));
55
+ fs.renameSync(tmp, file);
56
+ }
57
+
58
+ // 幂等登记(INV-2/INV-3):同 sessionId+batchId 已登记 → first=false 不重复写、不重复刷日志
59
+ function markBatchCorrupt(sessionId, batchId, error) {
60
+ const list = readList(sessionId);
61
+ if (list.some((c) => c.batchId === batchId)) return { first: false };
62
+ const entry = {
63
+ sessionId,
64
+ batchId,
65
+ file: path.join('sessions', sessionId, 'batches', batchId + '.json'),
66
+ error: String((error && error.message) || error),
67
+ detectedAt: new Date().toISOString(),
68
+ };
69
+ list.push(entry);
70
+ writeList(sessionId, list);
71
+ return { first: true };
72
+ }
73
+
74
+ // 只读清单:sessionId 缺省 → 全部会话(排序稳定)
75
+ function listCorruptBatches(sessionId) {
76
+ if (sessionId) return readList(sessionId);
77
+ const out = [];
78
+ const sessionsDir = path.join(root, 'sessions');
79
+ if (fs.existsSync(sessionsDir)) {
80
+ for (const s of fs.readdirSync(sessionsDir).sort()) {
81
+ if (!SESSION_RE.test(s)) continue;
82
+ out.push(...readList(s));
83
+ }
84
+ }
85
+ return out;
86
+ }
87
+
88
+ // 人工修复/删除损坏文件后清除标记(幂等:无标记 → { removed:false })
89
+ function clearCorruptMark(sessionId, batchId) {
90
+ const list = readList(sessionId);
91
+ const next = list.filter((c) => c.batchId !== batchId);
92
+ if (next.length === list.length) return { removed: false };
93
+ writeList(sessionId, next);
94
+ return { removed: true };
95
+ }
96
+
97
+ // 区分「损坏」与「不存在」(readBatch 两者均返回 null,需区分的调用方二次查询)
98
+ function isCorrupt(sessionId, batchId) {
99
+ return readList(sessionId).some((c) => c.batchId === batchId);
100
+ }
101
+
102
+ return { markBatchCorrupt, listCorruptBatches, clearCorruptMark, isCorrupt, corruptFileOf };
103
+ }
@@ -0,0 +1,65 @@
1
+ /*
2
+ Copyright (C) 2025-2026 Punky
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ // lib/state/event-types.js —— 批次事件 type 常量单点(P2-07 收敛 + P1 批 R-01 全量扩面)
19
+ // 零依赖纯常量模块:不 import 任何本包模块(避免循环依赖)。
20
+ // 事实源 = store.js newEvent 工厂调用点(原裸字面量,2026-08-28 P2-07 收敛)+ R-01 扩面:
21
+ // R-01(2026-08-29,p1list 批)把 appendEvent/events.push 发端字面量全量收拢进本文件——
22
+ // resume/archive/lane-heartbeat/lane-tools/mailbox-tools/merge-agent/core 的写事件
23
+ // (system.restored/archive.done/lane.stalled/lane.over-budget/worktree.*/budget.rejected/gate.role_*)
24
+ // 全部改引常量;读端(gates/store/resume/log-tools/lane-tools 的 e.type 比较)同步收敛(R-07)。
25
+ // 纪律:新增事件类型须在本文件登记常量后于调用点引用,禁止散布裸字面量。
26
+
27
+ // 批次生命周期
28
+ export const EVT_BATCH_CREATED = 'batch.created';
29
+ export const EVT_BATCH_PHASE = 'batch.phase';
30
+ export const EVT_BATCH_FAILED_ESCALATE = 'batch.failed-escalate';
31
+ export const EVT_ARCHIVE_FAILED = 'archive.failed';
32
+ export const EVT_ARCHIVE_DONE = 'archive.done'; // R-01 扩面(archive.js:161 发端)
33
+ export const EVT_SYSTEM_RECOVERED = 'system.recovered';
34
+ export const EVT_SYSTEM_RESTORED = 'system.restored'; // R-01 扩面(resume.js:105 eventType 缺省)
35
+
36
+ // 成员迁移
37
+ export const EVT_MEMBER_SETTLED = 'member.settled';
38
+ export const EVT_LANE_SKIPPED = 'lane.skipped';
39
+ export const EVT_LANE_NEEDHUMAN = 'lane.needhuman';
40
+ export const EVT_LANE_RECYCLED = 'lane.recycled';
41
+ export const EVT_HUMAN_DECISION = 'human.decision';
42
+ export const EVT_ASSET_CLAIMED = 'asset.claimed';
43
+
44
+ // 监控/预算/进度事件(R-01 扩面)
45
+ export const EVT_LANE_STALLED = 'lane.stalled'; // R-01 扩面(lane-heartbeat.js:188 发端 + store.js:530 读端)
46
+ export const EVT_LANE_OVER_BUDGET = 'lane.over-budget'; // R-01 扩面(lane-tools.js:346 发端 + resume.js:179 读端)
47
+ export const EVT_BUDGET_REJECTED = 'budget.rejected'; // R-01 扩面(mailbox-tools.js:79 发端 + log-tools.js:53 读端)
48
+ export const EVT_WORKTREE_CREATED = 'worktree.created'; // R-01 扩面(lane-tools.js:278 发端)
49
+ export const EVT_WORKTREE_CHECKPOINT = 'worktree.checkpoint'; // R-01 扩面(lane-tools.js:338 发端 + :393 读端)
50
+ export const EVT_WORKTREE_MERGED = 'worktree.merged'; // R-01 扩面(lane-tools.js:441 发端)
51
+ export const EVT_WORKTREE_MERGE_CONFLICT = 'worktree.merge.conflict'; // R-01 扩面(merge-agent.js:87 发端)
52
+ export const EVT_WORKTREE_MERGE_RESOLVED = 'worktree.merge.resolved'; // R-01 扩面(merge-agent.js:121 发端)
53
+
54
+ // 门禁事件(Tier3)
55
+ export const EVT_GATE_ENTRY_MISSING = 'gate.entry.missing';
56
+ export const EVT_GATE_EXIT_MISSING = 'gate.exit.missing';
57
+ export const EVT_GATE_PASSED = 'gate.passed';
58
+ export const EVT_GATE_TARGET_BLOCKED = 'gate.target_blocked';
59
+ export const EVT_GATE_TARGET_PASSED = 'gate.target.passed';
60
+ export const EVT_GATE_EXIT_BLOCKED = 'gate.exit_blocked';
61
+ export const EVT_GATE_EXIT = 'gate.exit';
62
+ export const EVT_GATE_NEEDHUMAN_BLOCKED = 'gate.needhuman_blocked';
63
+ export const EVT_GATE_COMPLETE_BLOCKED = 'gate.complete_blocked';
64
+ export const EVT_GATE_ROLE_MISSING = 'gate.role_missing'; // R-01 扩面(core.js:123 发端)
65
+ export const EVT_GATE_ROLE_INVALID = 'gate.role_invalid'; // R-01 扩面(core.js:123 发端)
@@ -0,0 +1,226 @@
1
+ import { runCommand } from './command-exec.js';
2
+ import { isAbsPath } from './constants.js';
3
+ import type { Batch, Layer } from '../types/contracts.js';
4
+ export { isAbsPath };
5
+ export declare const TARGETS_CLAIMED_RE: RegExp;
6
+ export declare function detectNeedHuman(artifactsDir: string, producePaths: string[]): {
7
+ declared: boolean;
8
+ path: null;
9
+ } | {
10
+ declared: boolean;
11
+ path: string;
12
+ };
13
+ export declare const GATE_LINE_RE: RegExp;
14
+ export declare function detectGate(artifactsDir: string, paths: string[]): {
15
+ declared: boolean;
16
+ commands: string[];
17
+ path: string | null;
18
+ };
19
+ export declare function createGates(root: string): {
20
+ checkEntryGate: (sessionId: string, batchId: string, batch: Batch, lane: string) => {
21
+ ok: boolean;
22
+ code?: undefined;
23
+ missing?: undefined;
24
+ } | {
25
+ ok: boolean;
26
+ code: string;
27
+ missing: string[];
28
+ };
29
+ checkPlanContract: (sessionId: string, batchId: string, batch: Batch, lane: string) => {
30
+ ok: boolean;
31
+ code?: undefined;
32
+ problems?: undefined;
33
+ } | {
34
+ ok: boolean;
35
+ code: string;
36
+ problems: string[];
37
+ };
38
+ checkExitGate: (sessionId: string, batchId: string, batch: Batch, lane: string) => {
39
+ ok: boolean;
40
+ code?: undefined;
41
+ problems?: undefined;
42
+ } | {
43
+ ok: boolean;
44
+ code: string;
45
+ problems: string[];
46
+ } | {
47
+ ok: boolean;
48
+ code: string;
49
+ missing: string[];
50
+ };
51
+ checkNeedHumanGate: (sessionId: string, batchId: string, batch: Batch, lane: string, note?: string | null) => {
52
+ ok: boolean;
53
+ declared: boolean;
54
+ path: null;
55
+ evidence?: undefined;
56
+ code?: undefined;
57
+ message?: undefined;
58
+ } | {
59
+ ok: boolean;
60
+ declared: boolean;
61
+ path: string | null;
62
+ evidence: string;
63
+ code?: undefined;
64
+ message?: undefined;
65
+ } | {
66
+ ok: boolean;
67
+ code: string;
68
+ declared: boolean;
69
+ path: string | null;
70
+ message: string;
71
+ evidence?: undefined;
72
+ };
73
+ checkCommandGate: (sessionId: string, batchId: string, batch: Batch, lane: string, deps?: {
74
+ runCommand?: typeof runCommand;
75
+ }) => {
76
+ ok: boolean;
77
+ declared: boolean;
78
+ code?: undefined;
79
+ command?: undefined;
80
+ exitCode?: undefined;
81
+ needHumanEscalation?: undefined;
82
+ detail?: undefined;
83
+ commands?: undefined;
84
+ results?: undefined;
85
+ outputTruncated?: undefined;
86
+ path?: undefined;
87
+ } | {
88
+ ok: boolean;
89
+ code: string;
90
+ command: null;
91
+ exitCode: null;
92
+ declared: boolean;
93
+ needHumanEscalation: boolean;
94
+ detail: string;
95
+ commands?: undefined;
96
+ results?: undefined;
97
+ outputTruncated?: undefined;
98
+ path?: undefined;
99
+ } | {
100
+ declared: boolean;
101
+ needHumanEscalation: boolean;
102
+ path: string | null;
103
+ code: string;
104
+ command: string;
105
+ exitCode: number | null;
106
+ detail: string;
107
+ ok: boolean;
108
+ commands?: undefined;
109
+ results?: undefined;
110
+ outputTruncated?: undefined;
111
+ } | {
112
+ ok: boolean;
113
+ declared: boolean;
114
+ commands: string[];
115
+ results: {
116
+ command: string;
117
+ exitCode: number | null;
118
+ durationMs: number;
119
+ }[];
120
+ outputTruncated: boolean;
121
+ path: string | null;
122
+ code?: undefined;
123
+ command?: undefined;
124
+ exitCode?: undefined;
125
+ needHumanEscalation?: undefined;
126
+ detail?: undefined;
127
+ };
128
+ checkTargetsGate: (sessionId: string, batchId: string, batch: Batch, lane: string) => {
129
+ ok: boolean;
130
+ declared: boolean;
131
+ code?: undefined;
132
+ missing?: undefined;
133
+ unchanged?: undefined;
134
+ mode?: undefined;
135
+ targets?: undefined;
136
+ } | {
137
+ ok: boolean;
138
+ declared: boolean;
139
+ code: string;
140
+ missing: string[];
141
+ unchanged: never[];
142
+ mode: string;
143
+ targets: string[];
144
+ } | {
145
+ ok: boolean;
146
+ declared: boolean;
147
+ code: string;
148
+ missing: never[];
149
+ unchanged: string[];
150
+ mode: string;
151
+ targets: string[];
152
+ } | {
153
+ ok: boolean;
154
+ declared: boolean;
155
+ missing: never[];
156
+ unchanged: never[];
157
+ mode: string;
158
+ targets: string[];
159
+ code?: undefined;
160
+ };
161
+ checkCompleteGate: (batch: Batch) => {
162
+ ok: boolean;
163
+ code?: undefined;
164
+ pending?: undefined;
165
+ } | {
166
+ ok: boolean;
167
+ code: string;
168
+ pending?: undefined;
169
+ } | {
170
+ ok: boolean;
171
+ code: string;
172
+ pending: string[];
173
+ };
174
+ gateStatus: (sessionId: string, batchId: string, lane: string) => {
175
+ lane: string;
176
+ layer: null;
177
+ state: null;
178
+ team: null;
179
+ corrupt: boolean;
180
+ consume: never[];
181
+ produce: never[];
182
+ outputs: never[];
183
+ consumeMissing: never[];
184
+ outputsMissing: never[];
185
+ produceMissing: never[];
186
+ contractProblems: null;
187
+ targets: never[];
188
+ targetsMissing: never[];
189
+ targetsUnchanged: never[];
190
+ gates?: undefined;
191
+ } | {
192
+ lane: string;
193
+ layer: null;
194
+ state: import("../types/contracts.js").MemberState;
195
+ gates: string;
196
+ team: string;
197
+ corrupt?: undefined;
198
+ consume?: undefined;
199
+ produce?: undefined;
200
+ outputs?: undefined;
201
+ consumeMissing?: undefined;
202
+ outputsMissing?: undefined;
203
+ produceMissing?: undefined;
204
+ contractProblems?: undefined;
205
+ targets?: undefined;
206
+ targetsMissing?: undefined;
207
+ targetsUnchanged?: undefined;
208
+ } | {
209
+ lane: string;
210
+ layer: Layer | null;
211
+ state: import("../types/contracts.js").MemberState;
212
+ team: string;
213
+ consume: string[];
214
+ produce: string[];
215
+ outputs: string[];
216
+ consumeMissing: string[];
217
+ outputsMissing: string[];
218
+ produceMissing: string[];
219
+ contractProblems: string[] | null | undefined;
220
+ targets: string[];
221
+ targetsMissing: string[];
222
+ targetsUnchanged: string[];
223
+ corrupt?: undefined;
224
+ gates?: undefined;
225
+ };
226
+ };