reasonweave 1.4.10 → 1.4.12
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/AGENTS.md +15 -14
- package/INSTALL.md +8 -8
- package/README.md +19 -18
- package/docs/CONSUMER-PROMPTS.md +11 -11
- package/docs/backlogs/17-feat-role-action-matrix-and-ticket-affinity.md +52 -0
- package/group/architecture/adr/0019-declarative-role-action-matrix-session-ticket-affinity-and-cross-platform-resilience.md +115 -0
- package/group/architecture/adr/INDEX.md +1 -0
- package/package.json +1 -1
- package/units/handoffs/CHANGELOG.md +27 -0
- package/units/handoffs/README.md +3 -2
- package/units/handoffs/RESPONSE-TEMPLATE.md +20 -8
- package/units/handoffs/VERSION.md +1 -1
- package/units/handoffs/handoff.mjs +403 -93
- package//344/275/277/347/224/250/350/257/264/346/230/216.md +5 -5
|
@@ -794,17 +794,26 @@ function resolveTicketId(id) {
|
|
|
794
794
|
const clean = String(id).trim().replace(/\.md$/, '').replace(/-resp$/, '');
|
|
795
795
|
const direct = path.join(H_DIR, `${clean}.md`);
|
|
796
796
|
if (fs.existsSync(direct)) return clean;
|
|
797
|
-
// 支持通过 conversation_id 或 UUID 前缀反查工单 ID
|
|
797
|
+
// 支持通过 conversation_id 或 UUID 前缀反查工单 ID(支持大小写不敏感与跨平台路径)
|
|
798
798
|
if (fs.existsSync(H_DIR)) {
|
|
799
799
|
try {
|
|
800
800
|
const files = fs.readdirSync(H_DIR).filter(f => f.endsWith('.md') && f.toUpperCase() !== 'README.MD');
|
|
801
|
+
const cleanLower = clean.toLowerCase();
|
|
802
|
+
// 1. 优先查文件名(大小写不敏感匹配)
|
|
803
|
+
for (const f of files) {
|
|
804
|
+
if (f.toLowerCase().replace(/\.md$/, '') === cleanLower) {
|
|
805
|
+
return f.replace(/\.md$/, '');
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
// 2. 查 frontmatter 中的 conversation_id / handoff_id
|
|
801
809
|
const matches = [];
|
|
802
810
|
for (const f of files) {
|
|
803
811
|
try {
|
|
804
|
-
const raw =
|
|
812
|
+
const raw = safeReadFileWithRetry(path.join(H_DIR, f), 'utf8');
|
|
805
813
|
const fm = readFM(raw);
|
|
806
814
|
if (fm && fm.conversation_id) {
|
|
807
|
-
|
|
815
|
+
const convLower = String(fm.conversation_id).toLowerCase();
|
|
816
|
+
if (convLower === cleanLower || convLower.startsWith(cleanLower)) {
|
|
808
817
|
matches.push(fm.handoff_id || f.replace(/\.md$/, ''));
|
|
809
818
|
}
|
|
810
819
|
}
|
|
@@ -819,6 +828,33 @@ function resolveTicketId(id) {
|
|
|
819
828
|
return clean;
|
|
820
829
|
}
|
|
821
830
|
|
|
831
|
+
/** 安全读取文件,针对 Windows/NTFS 独占锁 (EBUSY / EPERM) 实施毫秒级指数退避自愈重试 */
|
|
832
|
+
function safeReadFileWithRetry(filePath, encoding = 'utf8', retries = 3) {
|
|
833
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
834
|
+
try {
|
|
835
|
+
return fs.readFileSync(filePath, encoding);
|
|
836
|
+
} catch (err) {
|
|
837
|
+
if ((err.code === 'EBUSY' || err.code === 'EPERM') && attempt < retries) {
|
|
838
|
+
const delay = 50 * Math.pow(2, attempt);
|
|
839
|
+
const start = Date.now();
|
|
840
|
+
while (Date.now() - start < delay) {}
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
843
|
+
throw err;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/** 跨平台路径统一归一化(Windows 下统一小写正斜杠,消除盘符与大小写判定分裂) */
|
|
849
|
+
function normalizeFsPath(p) {
|
|
850
|
+
if (!p) return '';
|
|
851
|
+
let norm = path.normalize(path.resolve(p));
|
|
852
|
+
if (process.platform === 'win32') {
|
|
853
|
+
norm = norm.toLowerCase().replaceAll('\\', '/');
|
|
854
|
+
}
|
|
855
|
+
return norm;
|
|
856
|
+
}
|
|
857
|
+
|
|
822
858
|
function readFM(content) {
|
|
823
859
|
if (!content) return null;
|
|
824
860
|
const m = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/);
|
|
@@ -845,17 +881,33 @@ function fmtVal(v) {
|
|
|
845
881
|
return v;
|
|
846
882
|
}
|
|
847
883
|
|
|
848
|
-
/** 原子写入文件(write tmp + rename
|
|
884
|
+
/** 原子写入文件(write tmp + rename),针对 Windows 独占锁实施重试自愈 */
|
|
849
885
|
function writeAtomic(file, content) {
|
|
850
886
|
const dir = path.dirname(file);
|
|
851
887
|
try { if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true }); } catch {}
|
|
852
888
|
const tmp = path.join(dir, `.${path.basename(file)}.tmp.${process.pid}.${Date.now()}`);
|
|
853
889
|
fs.writeFileSync(tmp, content, 'utf8');
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
890
|
+
let renamed = false;
|
|
891
|
+
for (let attempt = 0; attempt <= 3; attempt++) {
|
|
892
|
+
try {
|
|
893
|
+
fs.renameSync(tmp, file);
|
|
894
|
+
renamed = true;
|
|
895
|
+
break;
|
|
896
|
+
} catch (err) {
|
|
897
|
+
if ((err.code === 'EBUSY' || err.code === 'EPERM') && attempt < 3) {
|
|
898
|
+
const delay = 50 * Math.pow(2, attempt);
|
|
899
|
+
const start = Date.now();
|
|
900
|
+
while (Date.now() - start < delay) {}
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
903
|
+
break;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (!renamed) {
|
|
907
|
+
try {
|
|
908
|
+
fs.copyFileSync(tmp, file);
|
|
909
|
+
try { fs.unlinkSync(tmp); } catch {}
|
|
910
|
+
} catch {}
|
|
859
911
|
}
|
|
860
912
|
}
|
|
861
913
|
|
|
@@ -1112,16 +1164,49 @@ function assertNoUnrecognizedSession(op, args = []) {
|
|
|
1112
1164
|
process.exit(1);
|
|
1113
1165
|
}
|
|
1114
1166
|
|
|
1115
|
-
function
|
|
1167
|
+
function getSessionData() {
|
|
1116
1168
|
try {
|
|
1117
1169
|
const k = getSessionId();
|
|
1170
|
+
if (!k || k === 'global' || k.startsWith('ppid-')) return {};
|
|
1118
1171
|
const f = path.join(SESSIONS_DIR, `${k}.json`);
|
|
1119
1172
|
if (fs.existsSync(f)) {
|
|
1120
|
-
|
|
1121
|
-
if (data && data.lane) return String(data.lane).toLowerCase();
|
|
1173
|
+
return JSON.parse(safeReadFileWithRetry(f, 'utf8')) || {};
|
|
1122
1174
|
}
|
|
1123
1175
|
} catch {}
|
|
1124
|
-
return
|
|
1176
|
+
return {};
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
function setSessionData(patch) {
|
|
1180
|
+
try {
|
|
1181
|
+
const k = getSessionId();
|
|
1182
|
+
if (!k || k === 'global' || k.startsWith('ppid-')) return;
|
|
1183
|
+
if (!fs.existsSync(SESSIONS_DIR)) fs.mkdirSync(SESSIONS_DIR, { recursive: true });
|
|
1184
|
+
const f = path.join(SESSIONS_DIR, `${k}.json`);
|
|
1185
|
+
let current = {};
|
|
1186
|
+
if (fs.existsSync(f)) {
|
|
1187
|
+
try { current = JSON.parse(safeReadFileWithRetry(f, 'utf8')) || {}; } catch {}
|
|
1188
|
+
}
|
|
1189
|
+
const merged = { ...current, ...patch, ppid: process.ppid, ts: new Date().toISOString() };
|
|
1190
|
+
writeAtomic(f, JSON.stringify(merged, null, 2));
|
|
1191
|
+
} catch {}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
function getSessionLane() {
|
|
1195
|
+
const data = getSessionData();
|
|
1196
|
+
return data.lane ? String(data.lane).toLowerCase() : '';
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
function setSessionLane(lane) {
|
|
1200
|
+
if (!lane) return;
|
|
1201
|
+
setSessionData({ lane: String(lane).toLowerCase() });
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
function clearSessionLane() {
|
|
1205
|
+
try {
|
|
1206
|
+
const k = getSessionId();
|
|
1207
|
+
const f = path.join(SESSIONS_DIR, `${k}.json`);
|
|
1208
|
+
if (fs.existsSync(f)) fs.unlinkSync(f);
|
|
1209
|
+
} catch {}
|
|
1125
1210
|
}
|
|
1126
1211
|
|
|
1127
1212
|
/** 跨会话操作硬门禁(Anti-Cross-Session Hard Gate · v2.36.0 宪法 T6):
|
|
@@ -1144,35 +1229,78 @@ function assertSessionAffinity(fm, op, id, args = []) {
|
|
|
1144
1229
|
if (ticketSession && curSession !== ticketSession && !ticketSession.startsWith(curSession) && !curSession.startsWith(ticketSession)) {
|
|
1145
1230
|
const isZh = detectLang() === 'zh';
|
|
1146
1231
|
if (isZh) {
|
|
1147
|
-
console.error(`\n❌
|
|
1148
|
-
console.error(`
|
|
1149
|
-
console.error(` 根据
|
|
1150
|
-
console.error(` 👉
|
|
1232
|
+
console.error(`\n❌ 跨会话操作硬门禁拦截 (CROSS_SESSION_MUTATION_BLOCKED):`);
|
|
1233
|
+
console.error(` 当前工单 [${id}] 归属于会话 [${ticketSession}],但当前活跃会话为 [${curSession}]!`);
|
|
1234
|
+
console.error(` 根据 v2.36.0 宪法 T6 严禁跨会话处理工单律,推进 (forward)、闭环 (accept/close) 与重开 (reopen) 仅限原工单发起会话执行。`);
|
|
1235
|
+
console.error(` 👉 请切换回原发起会话处理,或在新建工单下流转。\n`);
|
|
1151
1236
|
} else {
|
|
1152
1237
|
console.error(`\n❌ Cross-Session Mutation Blocked (CROSS_SESSION_MUTATION_BLOCKED):`);
|
|
1153
|
-
console.error(` Ticket [${id}] belongs to session [${ticketSession}], but current session is [${curSession}]
|
|
1154
|
-
console.error(`
|
|
1238
|
+
console.error(` Ticket [${id}] belongs to session [${ticketSession}], but current active session is [${curSession}]!`);
|
|
1239
|
+
console.error(` Per v2.36.0 constitution T6, forward/accept/reopen are restricted to the origin session.`);
|
|
1240
|
+
console.error(` 👉 Switch back to the origin session or create a new ticket.\n`);
|
|
1155
1241
|
}
|
|
1156
1242
|
process.exit(1);
|
|
1157
1243
|
}
|
|
1158
1244
|
}
|
|
1159
1245
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
}
|
|
1246
|
+
/**
|
|
1247
|
+
* 校验会话-工单互斥粘性锁(Anti-Cross-Ticket Contamination · ADR-0019 / 借鉴 LangGraph thread_id)
|
|
1248
|
+
* 同一接单 Agent 会话在同一上下文只能处理同一份工单(一单到底),严禁向外部工单提交写操作。
|
|
1249
|
+
*/
|
|
1250
|
+
function assertTicketAffinity(ticketId, op, args = []) {
|
|
1251
|
+
if (args.includes('--force-ticket') || process.env.BATON_FORCE_TICKET === '1') {
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
const curSession = getSessionId();
|
|
1255
|
+
if (!curSession || curSession === 'global' || curSession.startsWith('ppid-')) {
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
const sessData = getSessionData();
|
|
1259
|
+
const boundTicket = sessData.bound_ticket;
|
|
1260
|
+
if (!boundTicket) {
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
const normBound = String(boundTicket).toLowerCase().trim();
|
|
1265
|
+
const normTarget = String(ticketId).toLowerCase().trim();
|
|
1266
|
+
|
|
1267
|
+
if (normBound !== normTarget) {
|
|
1268
|
+
const isZh = detectLang() === 'zh';
|
|
1269
|
+
if (isZh) {
|
|
1270
|
+
console.error(`\n❌ 跨工单污染拦截 (CROSS_TICKET_CONTAMINATION_BLOCKED):`);
|
|
1271
|
+
console.error(` 当前活跃会话 [${curSession}] 已锁定处理工单 [${boundTicket}](Round ${sessData.bound_round || 1}),`);
|
|
1272
|
+
console.error(` 检测到对不同工单 [${ticketId}] 的越界写操作(baton ${op})!`);
|
|
1273
|
+
console.error(` 根据 ADR-0019 单会话一单到底律,同一上下文只能处理同一份工单,严禁串单操作。`);
|
|
1274
|
+
console.error(` 👉 若需强制操作,请在终端追加 --force-ticket,或开启全新 Agent 会话。\n`);
|
|
1275
|
+
} else {
|
|
1276
|
+
console.error(`\n❌ Cross-Ticket Contamination Blocked (CROSS_TICKET_CONTAMINATION_BLOCKED):`);
|
|
1277
|
+
console.error(` Current session [${curSession}] is locked to ticket [${boundTicket}] (Round ${sessData.bound_round || 1}),`);
|
|
1278
|
+
console.error(` but attempted to perform '${op}' on different ticket [${ticketId}].`);
|
|
1279
|
+
console.error(` Per ADR-0019 single-ticket exclusive invariant, cross-ticket mutations in the same context are prohibited.`);
|
|
1280
|
+
console.error(` 👉 Use --force-ticket to bypass, or open a fresh agent session.\n`);
|
|
1281
|
+
}
|
|
1282
|
+
process.exit(1);
|
|
1283
|
+
}
|
|
1168
1284
|
}
|
|
1169
1285
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1286
|
+
/** 绑定或自动递增当前会话与工单的亲和锁 */
|
|
1287
|
+
function bindSessionTicket(ticketId, round = 1, force = false) {
|
|
1288
|
+
if (!ticketId) return;
|
|
1289
|
+
const curSession = getSessionId();
|
|
1290
|
+
if (!curSession || curSession === 'global' || curSession.startsWith('ppid-')) {
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
const sessData = getSessionData();
|
|
1294
|
+
const normTarget = String(ticketId).trim();
|
|
1295
|
+
const r = Number(round) || 1;
|
|
1296
|
+
if (force || !sessData.bound_ticket || String(sessData.bound_ticket).toLowerCase() === normTarget.toLowerCase()) {
|
|
1297
|
+
setSessionData({
|
|
1298
|
+
bound_ticket: normTarget,
|
|
1299
|
+
bound_round: (force && String(sessData.bound_ticket).toLowerCase() !== normTarget.toLowerCase())
|
|
1300
|
+
? r
|
|
1301
|
+
: Math.max(Number(sessData.bound_round) || 1, r)
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1176
1304
|
}
|
|
1177
1305
|
|
|
1178
1306
|
/** 获取或生成审计私钥凭据(.handoffs/.secrets/audit.token 或 BATON_AUDIT_TOKEN) */
|
|
@@ -1269,7 +1397,29 @@ function resolveExecutionLane(asInput, ctx = {}) {
|
|
|
1269
1397
|
}
|
|
1270
1398
|
|
|
1271
1399
|
/**
|
|
1272
|
-
*
|
|
1400
|
+
* Baton 角色-动作法定权能矩阵 (Role-Action Capability Matrix · ADR-0019 / 借鉴 MetaGPT set_actions)
|
|
1401
|
+
* 严格划分各角色(Initiator / Executor / Auditor)在状态机流转中所允许执行的命令白名单。
|
|
1402
|
+
*/
|
|
1403
|
+
const ROLE_ACTION_MATRIX = {
|
|
1404
|
+
// 发起角色 (Initiator / from_lane):负责工单生命周期调度、推进与最终验收
|
|
1405
|
+
initiator: new Set([
|
|
1406
|
+
'new', 'forward', 'wait', 'prompt', 'accept', 'close',
|
|
1407
|
+
'reopen', 'reject', 'show', 'status', 'check', 'brief', 'drift', 'sync', 'lane'
|
|
1408
|
+
]),
|
|
1409
|
+
|
|
1410
|
+
// 执行角色 (Executor / to_lane=impl 等):负责根据需求编写代码并提供证据
|
|
1411
|
+
executor: new Set([
|
|
1412
|
+
'show', 'status', 'receipt', 'deliver', 'check', 'wait', 'lane'
|
|
1413
|
+
]),
|
|
1414
|
+
|
|
1415
|
+
// 独立审查角色 (Auditor / to_lane=audit):负责独立测试核验与反向裁决(严禁自审关单)
|
|
1416
|
+
audit: new Set([
|
|
1417
|
+
'show', 'status', 'receipt', 'deliver', 'reject', 'nonce', 'check', 'wait', 'lane'
|
|
1418
|
+
])
|
|
1419
|
+
};
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* 校验当前角色执行该命令的合法性(防角色漂移物理门禁 · ADR-0018 & ADR-0019 / 借鉴 MetaGPT Role-Action 白名单)
|
|
1273
1423
|
* 核心原则:用物理能力限制取代提示词礼貌提示。
|
|
1274
1424
|
*/
|
|
1275
1425
|
function assertRoleCommandAllowed(op, lane, ticketFm = null) {
|
|
@@ -1277,13 +1427,49 @@ function assertRoleCommandAllowed(op, lane, ticketFm = null) {
|
|
|
1277
1427
|
const l = lane.toLowerCase().trim();
|
|
1278
1428
|
const isZh = detectLang() === 'zh';
|
|
1279
1429
|
|
|
1430
|
+
const fromLanes = ticketFm?.from_lane ? String(ticketFm.from_lane).toLowerCase().split(/[,/]/).map(s => s.trim()) : [];
|
|
1431
|
+
const toLane = String(ticketFm?.to_lane || ticketFm?.target || '').toLowerCase().trim();
|
|
1432
|
+
const isInitiator = fromLanes.includes(l) || (!toLane && l !== 'audit');
|
|
1433
|
+
|
|
1434
|
+
let roleCategory = 'executor';
|
|
1435
|
+
if (isInitiator) {
|
|
1436
|
+
roleCategory = 'initiator';
|
|
1437
|
+
} else if (l === 'audit') {
|
|
1438
|
+
roleCategory = 'audit';
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
const allowedActions = ROLE_ACTION_MATRIX[roleCategory] || ROLE_ACTION_MATRIX.executor;
|
|
1442
|
+
if (!allowedActions.has(op)) {
|
|
1443
|
+
const roleTitleZh = roleCategory === 'initiator' ? '发起方' : (roleCategory === 'audit' ? '独立审计方' : '执行方');
|
|
1444
|
+
const roleTitleEn = roleCategory === 'initiator' ? 'Initiator' : (roleCategory === 'audit' ? 'Auditor' : 'Executor');
|
|
1445
|
+
if (isZh) {
|
|
1446
|
+
console.error(`❌ [角色权限门禁拦截 (ROLE_ACTION_BLOCKED / ROLE_ACTION_VIOLATION)] 角色 [${l}](${roleTitleZh})法定权能无权执行动作 [baton ${op}]!`);
|
|
1447
|
+
console.error(` 👉 该角色法定可用动作仅限: ${[...allowedActions].map(a => `baton ${a}`).join(', ')}`);
|
|
1448
|
+
if (l === 'audit' && !isInitiator) {
|
|
1449
|
+
console.error(` 👉 audit 角色为独立审查方,其职责为签署回执 (baton receipt --deliver) 或驳回 (baton reject),严禁执行闭环 (baton ${op})!`);
|
|
1450
|
+
} else if ((op === 'accept' || op === 'close') && !isInitiator) {
|
|
1451
|
+
console.error(` 👉 终态验收闭环(accept/close)是发起方的专属特权,执行方禁止自审自闭环(严禁自审自闭环 / ANTI_SELF_CLOSE_BLOCKED)。`);
|
|
1452
|
+
} else if ((op === 'receipt' || op === 'deliver') && isInitiator) {
|
|
1453
|
+
console.error(` 👉 回执与交付(receipt/deliver)是接收方的专属职责,发起方禁止自填回执 (ANTI_SELF_RECEIPT_BLOCKED)。`);
|
|
1454
|
+
}
|
|
1455
|
+
} else {
|
|
1456
|
+
console.error(`❌ [Role Action Blocked (ROLE_ACTION_BLOCKED / ROLE_ACTION_VIOLATION)] Role [${l}] (${roleTitleEn}) is not permitted to execute action [baton ${op}]!`);
|
|
1457
|
+
console.error(` 👉 Allowed actions for this role: ${[...allowedActions].map(a => `baton ${a}`).join(', ')}`);
|
|
1458
|
+
if (l === 'audit' && !isInitiator) {
|
|
1459
|
+
console.error(` 👉 'audit' role is a reviewer: only allowed to submit receipt or reject, strictly prohibited from closing tickets (baton ${op})!`);
|
|
1460
|
+
} else if ((op === 'accept' || op === 'close') && !isInitiator) {
|
|
1461
|
+
console.error(` 👉 Ticket closure (accept/close) is reserved for the initiator; assignees cannot close their own tickets (执行方禁止自审自闭环 / ANTI_SELF_CLOSE_BLOCKED).`);
|
|
1462
|
+
} else if ((op === 'receipt' || op === 'deliver') && isInitiator) {
|
|
1463
|
+
console.error(` 👉 Submitting receipts (receipt/deliver) is reserved for assignees; initiators cannot submit receipts (禁止自填回执 / ANTI_SELF_RECEIPT_BLOCKED).`);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
process.exit(1);
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1280
1469
|
// 1. audit 角色的硬性白名单约束:
|
|
1281
1470
|
// audit 角色作为接收/审查方时,其职责为签署回执(receipt)或驳回(reject)
|
|
1282
1471
|
// 严禁执行 accept/close(不可自审自闭环)、forward(不可替发起方派发)、reopen
|
|
1283
1472
|
if (l === 'audit') {
|
|
1284
|
-
const fromLanes = ticketFm?.from_lane ? String(ticketFm.from_lane).toLowerCase().split(/[,/]/).map(s => s.trim()) : [];
|
|
1285
|
-
const isInitiator = fromLanes.includes('audit');
|
|
1286
|
-
|
|
1287
1473
|
if (!isInitiator) {
|
|
1288
1474
|
if (op === 'accept' || op === 'close') {
|
|
1289
1475
|
console.error(isZh
|
|
@@ -1308,22 +1494,52 @@ function assertRoleCommandAllowed(op, lane, ticketFm = null) {
|
|
|
1308
1494
|
|
|
1309
1495
|
// 2. 如果工单信息已知:校验当前角色是否与工单角色存在逆向错位
|
|
1310
1496
|
if (ticketFm) {
|
|
1311
|
-
const toLane = String(ticketFm.to_lane || ticketFm.target || '').toLowerCase().trim();
|
|
1312
|
-
const fromLane = String(ticketFm.from_lane || '').toLowerCase().trim();
|
|
1313
|
-
|
|
1314
1497
|
// 针对本工单的目标接收方(to_lane),无论其 lane 名称为何(audit / impl / pm / qa):
|
|
1315
1498
|
// 一律禁止对自己接收执行的工单执行 accept/close!
|
|
1316
1499
|
if (toLane && l === toLane) {
|
|
1317
1500
|
if (op === 'accept' || op === 'close') {
|
|
1318
1501
|
console.error(isZh
|
|
1319
|
-
? `❌ [角色漂移与自审自闭环拦截 (ANTI_SELF_CLOSE_BLOCKED)] 当前执行身份 lane=${l} 是本工单的目标执行/审查方 (to_lane=${toLane})。\n 👉 终态验收闭环(accept/close)是发起方的专属特权,必须由发起方 (from_lane=${
|
|
1320
|
-
: `❌ [Anti-Self-Close Blocked (ANTI_SELF_CLOSE_BLOCKED)] Role lane=${l} is the assignee (to_lane=${toLane}) of this ticket.\n 👉 Ticket closure (accept/close) is reserved for the initiator (from_lane=${
|
|
1502
|
+
? `❌ [角色漂移与自审自闭环拦截 (ANTI_SELF_CLOSE_BLOCKED)] 当前执行身份 lane=${l} 是本工单的目标执行/审查方 (to_lane=${toLane})。\n 👉 终态验收闭环(accept/close)是发起方的专属特权,必须由发起方 (from_lane=${fromLanes.join('/')}) 独立实测执行,执行方禁止自审自闭环!`
|
|
1503
|
+
: `❌ [Anti-Self-Close Blocked (ANTI_SELF_CLOSE_BLOCKED)] Role lane=${l} is the assignee (to_lane=${toLane}) of this ticket.\n 👉 Ticket closure (accept/close) is reserved for the initiator (from_lane=${fromLanes.join('/')}); assignees cannot close their own tickets (执行方禁止自审自闭环)!`);
|
|
1321
1504
|
process.exit(1);
|
|
1322
1505
|
}
|
|
1323
1506
|
}
|
|
1324
1507
|
}
|
|
1325
1508
|
}
|
|
1326
1509
|
|
|
1510
|
+
/** 动态角色权能横幅输出(Context Re-anchoring · ADR-0019 / 借鉴 MetaGPT Prefix 与 RoleFix) */
|
|
1511
|
+
function printRoleCapabilityBanner(lane, boundTicket = null, boundRound = 1) {
|
|
1512
|
+
if (!lane) return;
|
|
1513
|
+
const l = lane.toLowerCase().trim();
|
|
1514
|
+
const isZh = detectLang() === 'zh';
|
|
1515
|
+
const roleTitle = resolveLaneRole(l) || l;
|
|
1516
|
+
const isAudit = l === 'audit';
|
|
1517
|
+
const isInitiator = ['coordinator', 'arch', 'lead', 'product'].includes(l);
|
|
1518
|
+
const ticketStr = boundTicket ? (isZh ? ` | 绑定工单: ${boundTicket} (Round ${boundRound || 1})` : ` | Bound Ticket: ${boundTicket} (Round ${boundRound || 1})`) : '';
|
|
1519
|
+
|
|
1520
|
+
if (isZh) {
|
|
1521
|
+
const allowed = isInitiator
|
|
1522
|
+
? 'baton new / forward / wait / prompt / accept / close / reopen / status'
|
|
1523
|
+
: (isAudit ? 'baton receipt (--deliver) / reject / nonce / status' : 'baton receipt (--deliver) / status / check');
|
|
1524
|
+
const prohibited = isInitiator
|
|
1525
|
+
? '无(发起方主管全生命周期调度)'
|
|
1526
|
+
: (isAudit ? 'baton accept / close (禁止自审自结) / forward / prompt' : 'baton accept / close (禁止越权关单) / forward / prompt');
|
|
1527
|
+
console.log(`[Baton 角色锚定] 当前身份: 【${roleTitle} (${l})】${ticketStr}`);
|
|
1528
|
+
console.log(` - 法定可用: ${allowed}`);
|
|
1529
|
+
console.log(` - 物理禁止: ${prohibited}\n`);
|
|
1530
|
+
} else {
|
|
1531
|
+
const allowed = isInitiator
|
|
1532
|
+
? 'baton new / forward / wait / prompt / accept / close / reopen / status'
|
|
1533
|
+
: (isAudit ? 'baton receipt (--deliver) / reject / nonce / status' : 'baton receipt (--deliver) / status / check');
|
|
1534
|
+
const prohibited = isInitiator
|
|
1535
|
+
? 'None (Initiator manages lifecycle)'
|
|
1536
|
+
: (isAudit ? 'baton accept / close (No self-closing) / forward / prompt' : 'baton accept / close (Assignee cannot close) / forward / prompt');
|
|
1537
|
+
console.log(`[Role Anchor] Role: [${roleTitle} (${l})]${ticketStr}`);
|
|
1538
|
+
console.log(` - Allowed: ${allowed}`);
|
|
1539
|
+
console.log(` - Prohibited: ${prohibited}\n`);
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1327
1543
|
/** 会话身份锁 CLI 管理命令(ADR-0010) */
|
|
1328
1544
|
function cmdLane(args) {
|
|
1329
1545
|
const isZh = detectLang() === 'zh';
|
|
@@ -1344,10 +1560,12 @@ function cmdLane(args) {
|
|
|
1344
1560
|
if (targetLane) {
|
|
1345
1561
|
const laneNorm = targetLane.toLowerCase().trim();
|
|
1346
1562
|
setSessionLane(laneNorm);
|
|
1563
|
+
const sessData = getSessionData();
|
|
1347
1564
|
if (isJson) {
|
|
1348
1565
|
console.log(JSON.stringify({ ok: true, session_id: getSessionId(), lane: laneNorm }));
|
|
1349
1566
|
} else {
|
|
1350
1567
|
console.log(isZh ? `✅ 当前会话身份已锁定为: ${laneNorm}` : `✅ Current session lane bound to: ${laneNorm}`);
|
|
1568
|
+
printRoleCapabilityBanner(laneNorm, sessData.bound_ticket, sessData.bound_round || 1);
|
|
1351
1569
|
}
|
|
1352
1570
|
return;
|
|
1353
1571
|
}
|
|
@@ -1368,6 +1586,9 @@ function cmdLane(args) {
|
|
|
1368
1586
|
return;
|
|
1369
1587
|
}
|
|
1370
1588
|
|
|
1589
|
+
const sessData = getSessionData();
|
|
1590
|
+
printRoleCapabilityBanner(effectiveLane, sessData.bound_ticket, sessData.bound_round || 1);
|
|
1591
|
+
|
|
1371
1592
|
if (isZh) {
|
|
1372
1593
|
console.log(`🔐 Agent Baton 会话身份状态:`);
|
|
1373
1594
|
console.log(` Session ID: ${sessionId}`);
|
|
@@ -1691,6 +1912,14 @@ function cmdNewIntra(args) {
|
|
|
1691
1912
|
}
|
|
1692
1913
|
|
|
1693
1914
|
function cmdStatus(args) {
|
|
1915
|
+
const isJson = args.includes('--json');
|
|
1916
|
+
if (!isJson) {
|
|
1917
|
+
const curLane = (flagValue(args, '--as') || flagValue(args, '--by') || getSessionLane() || process.env.HANDOFF_LANE || '').toLowerCase().trim();
|
|
1918
|
+
if (curLane) {
|
|
1919
|
+
const sessData = getSessionData();
|
|
1920
|
+
printRoleCapabilityBanner(curLane, sessData.bound_ticket, sessData.bound_round || 1);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1694
1923
|
// 把解析到的根与模式显式传给 handoff-status.mjs,使其成为确定性入口(仓内根 ≠ 脚本目录)
|
|
1695
1924
|
const filtered = args.filter(a => a !== '--root' && a !== '--mode' && !a.startsWith('--root=') && !a.startsWith('--mode='));
|
|
1696
1925
|
try {
|
|
@@ -1937,6 +2166,12 @@ function cmdAccept(args) {
|
|
|
1937
2166
|
logStateJournal(id, 'accept', { from_status: st, to_status: 'closed', accepted_at: now, note });
|
|
1938
2167
|
console.log(`✅ 已审计闭环: ${id}(验收记录已写入交接文档)`);
|
|
1939
2168
|
|
|
2169
|
+
// 清空会话锁定的工单(ADR-0019 会话闭环解绑)
|
|
2170
|
+
const sessData = getSessionData();
|
|
2171
|
+
if (sessData.bound_ticket && String(sessData.bound_ticket).toLowerCase() === String(id).toLowerCase()) {
|
|
2172
|
+
setSessionData({ bound_ticket: '', bound_round: 1 });
|
|
2173
|
+
}
|
|
2174
|
+
|
|
1940
2175
|
// 清理注册表避免孤儿文件 (D2)
|
|
1941
2176
|
const watchFile = path.join(ROOT, '.watch', `${id}.json`);
|
|
1942
2177
|
try { if (fs.existsSync(watchFile)) fs.unlinkSync(watchFile); } catch {}
|
|
@@ -1992,6 +2227,7 @@ function cmdReject(args) {
|
|
|
1992
2227
|
const rawH = fs.readFileSync(file, 'utf8');
|
|
1993
2228
|
const hFm = readFM(rawH);
|
|
1994
2229
|
const st = hFm?.status;
|
|
2230
|
+
assertTicketAffinity(id, 'reject', args);
|
|
1995
2231
|
|
|
1996
2232
|
// 身份门禁:允许发起方驳回执行方交付,亦允许审计方(to_lane=audit)对被审工单给出驳回裁决
|
|
1997
2233
|
let cur = resolveExecutionLane(asArg || byArg, { fromLane: hFm?.from_lane, toLane: hFm?.to_lane, op: 'reject', ticketId: id });
|
|
@@ -2037,6 +2273,8 @@ function cmdReject(args) {
|
|
|
2037
2273
|
isFromLane = true;
|
|
2038
2274
|
}
|
|
2039
2275
|
|
|
2276
|
+
assertRoleCommandAllowed('reject', cur, hFm);
|
|
2277
|
+
|
|
2040
2278
|
if (st === 'draft' && !isAuditor && !isFromLane) {
|
|
2041
2279
|
console.error(`❌ 交接 ${id} 当前为 draft,尚无登记回执或交付,不能驳回${fs.existsSync(path.join(R_DIR, `${id}-resp.md`)) ? `;检测到回执文件,请先 baton deliver ${id} 交付后再核验驳回` : ''}。`);
|
|
2042
2280
|
process.exit(1);
|
|
@@ -2066,6 +2304,7 @@ function cmdReject(args) {
|
|
|
2066
2304
|
const rFile = path.join(R_DIR, `${id}-resp.md`);
|
|
2067
2305
|
let rHash = '';
|
|
2068
2306
|
const nextRound = (Number(hFm?.round) || 1) + 1;
|
|
2307
|
+
bindSessionTicket(id, nextRound);
|
|
2069
2308
|
const rejEntry = `- 日期:${todayISO()}\n- 理由:${note}\n`;
|
|
2070
2309
|
const rejTicketEntry = `- 轮次:Round ${nextRound}(驳回方: ${cur})\n- 日期:${todayISO()}\n- 理由:${note}\n`;
|
|
2071
2310
|
const updatedTicket = insertRejectionEntry(rawH, rejTicketEntry);
|
|
@@ -2140,19 +2379,23 @@ function cmdReject(args) {
|
|
|
2140
2379
|
const rejectorRole = resolveLaneRole(cur) || (isZh ? '驳回方' : 'Rejector');
|
|
2141
2380
|
const targetLane = (isAuditor || !isFromLane) ? (hFm?.from_lane || 'impl') : (hFm?.to_lane || 'impl');
|
|
2142
2381
|
const targetRole = resolveLaneRole(targetLane) || (isZh ? '实现方' : 'Implementer');
|
|
2382
|
+
const rDisplay = path.join(H_DIR, `../receipts/${id}-resp.md`);
|
|
2383
|
+
const rCleanDisplay = rDisplay.startsWith(os.homedir()) ? '~' + rDisplay.slice(os.homedir().length) : rDisplay;
|
|
2384
|
+
const cleanNote = (note || '').split('\n')[0].trim().slice(0, 40);
|
|
2385
|
+
const noteSuffix = cleanNote ? ` · ${cleanNote}` : '';
|
|
2143
2386
|
let verdictLine;
|
|
2144
2387
|
if (cur === 'audit') {
|
|
2145
2388
|
verdictLine = isZh
|
|
2146
|
-
?
|
|
2147
|
-
: `Audit complete, verdict NO-GO (Ticket returned to ${targetRole} entering Round ${nextRound})`;
|
|
2389
|
+
? `请 [${targetLane}] 按驳回记录修订并重新交付 [${id}]:${rCleanDisplay}(Round ${nextRound} · NO-GO${noteSuffix})\n(审计完成,裁决 NO-GO(工单已退回${targetRole}进入 Round ${nextRound}))`
|
|
2390
|
+
: `Please [${targetLane}] revise per rejection record and re-deliver [${id}]: ${rCleanDisplay} (Round ${nextRound} · NO-GO${noteSuffix})\n(Audit complete, verdict NO-GO (Ticket returned to ${targetRole} entering Round ${nextRound}))`;
|
|
2148
2391
|
} else if (isFromLane) {
|
|
2149
2392
|
verdictLine = isZh
|
|
2150
|
-
?
|
|
2151
|
-
:
|
|
2393
|
+
? `请 [${targetLane}] 按驳回记录修订并重新交付 [${id}]:${rCleanDisplay}(Round ${nextRound} · NO-GO${noteSuffix})\n(${rejectorRole}验收未通过,裁决 NO-GO(工单已退回${targetRole}进入 Round ${nextRound}))`
|
|
2394
|
+
: `Please [${targetLane}] revise per rejection record and re-deliver [${id}]: ${rCleanDisplay} (Round ${nextRound} · NO-GO${noteSuffix})\n(${rejectorRole} verification failed, verdict NO-GO (Ticket returned to ${targetRole} entering Round ${nextRound}))`;
|
|
2152
2395
|
} else {
|
|
2153
2396
|
verdictLine = isZh
|
|
2154
|
-
?
|
|
2155
|
-
:
|
|
2397
|
+
? `请 [${targetLane}] 按驳回记录修订并重新交付 [${id}]:${rCleanDisplay}(Round ${nextRound} · NO-GO${noteSuffix})\n(${rejectorRole}驳回退回,裁决 NO-GO(工单已退回${targetRole}进入 Round ${nextRound}))`
|
|
2398
|
+
: `Please [${targetLane}] revise per rejection record and re-deliver [${id}]: ${rCleanDisplay} (Round ${nextRound} · NO-GO${noteSuffix})\n(${rejectorRole} rejected, verdict NO-GO (Ticket returned to ${targetRole} entering Round ${nextRound}))`;
|
|
2156
2399
|
}
|
|
2157
2400
|
if (isZh) {
|
|
2158
2401
|
console.log(`\nℹ️ 裁决收尾(接收方回复末尾仅单行纯文本,无需标题与代码块):`);
|
|
@@ -2289,18 +2532,18 @@ function extractConclusion(raw) {
|
|
|
2289
2532
|
* **仓内(v2.13 修复):严禁 detectRepo 拼仓库名**,改读回执 frontmatter 的 from_lane/to_lane,
|
|
2290
2533
|
* 用 resolveLaneRole 拼自然角色(杜绝「请收 Tappy 回执」式把项目名当沟通角色的事故)。 */
|
|
2291
2534
|
function printReceiptDeliveryLine(rFile, needsChange, isDelivered = false) {
|
|
2292
|
-
let lines = 0, bytes = 0, fromLane = '', toLane = '', rawText = '', ticketId = '';
|
|
2535
|
+
let lines = 0, bytes = 0, fromLane = '', toLane = '', rawText = '', ticketId = '', rFm = {};
|
|
2293
2536
|
try {
|
|
2294
2537
|
const buf = fs.readFileSync(rFile);
|
|
2295
2538
|
bytes = buf.length;
|
|
2296
2539
|
const text = buf.toString('utf8');
|
|
2297
2540
|
rawText = text;
|
|
2298
2541
|
lines = text.split('\n').length - (text.endsWith('\n') ? 1 : 0);
|
|
2299
|
-
|
|
2300
|
-
fromLane =
|
|
2301
|
-
toLane =
|
|
2302
|
-
ticketId =
|
|
2303
|
-
if (
|
|
2542
|
+
rFm = readFM(text) || {};
|
|
2543
|
+
fromLane = rFm.from_lane || '';
|
|
2544
|
+
toLane = rFm.to_lane || '';
|
|
2545
|
+
ticketId = rFm.handoff_id || path.basename(rFile).replace(/-resp\.md$/, '');
|
|
2546
|
+
if (rFm.delivered_at) isDelivered = true;
|
|
2304
2547
|
} catch { /* 读不到不阻断主流程 */ }
|
|
2305
2548
|
const flag = needsChange ? '是' : '否';
|
|
2306
2549
|
const display = rFile.startsWith(os.homedir()) ? '~' + rFile.slice(os.homedir().length) : rFile;
|
|
@@ -2310,16 +2553,29 @@ function printReceiptDeliveryLine(rFile, needsChange, isDelivered = false) {
|
|
|
2310
2553
|
const fromRole = resolveLaneRole(fromLane) || fromLane || (isZh ? '本方' : 'Executor');
|
|
2311
2554
|
if (isDelivered) {
|
|
2312
2555
|
console.log(`\n✅ 仓内终态交付已生效 [${ticketId}](状态推进为 delivered,后台监听已自动感知平息并唤醒发起方 [${toRole}] 进行独立验收闭环)。`);
|
|
2556
|
+
const rRaw = rawText ? stripFM(rawText) : '';
|
|
2557
|
+
const rConcl = extractConclusion(rRaw) || (needsChange ? '需整改' : 'PASS');
|
|
2558
|
+
const rBodyClean = rRaw.replace(/^#+.*$/gm, '').replace(/[-*]\s+/g, '').replace(/\s+/g, ' ').trim();
|
|
2559
|
+
const rSummary = rBodyClean ? ` · ${rBodyClean.slice(0, 35)}` : '';
|
|
2560
|
+
let roundNum = rFm.round || 1;
|
|
2561
|
+
try {
|
|
2562
|
+
const hFmCheck = readFM(fs.readFileSync(path.join(H_DIR, `${ticketId}.md`), 'utf8')) || {};
|
|
2563
|
+
if (hFmCheck.round) roundNum = hFmCheck.round;
|
|
2564
|
+
} catch {}
|
|
2313
2565
|
const verdictLine = fromLane === 'audit'
|
|
2314
|
-
? (isZh
|
|
2315
|
-
|
|
2566
|
+
? (isZh
|
|
2567
|
+
? `请 [${toLane || 'initiator'}] 查收审计回执并闭环工单 [${ticketId}]:${display}(Round ${roundNum} · GO · ${rConcl}${rSummary})\n(审计完成,裁决 GO)`
|
|
2568
|
+
: `Please [${toLane || 'initiator'}] review audit receipt and close ticket [${ticketId}]: ${display} (Round ${roundNum} · GO · ${rConcl}${rSummary})\n(Audit complete, verdict GO)`)
|
|
2569
|
+
: (isZh
|
|
2570
|
+
? `请 [${toLane || 'initiator'}] 查收交付回执并独立实测 [${ticketId}]:${display}(Round ${roundNum} · DELIVERED · ${rConcl}${rSummary})\n(交付完成,回执已就绪 [${ticketId}]:${display})`
|
|
2571
|
+
: `Please [${toLane || 'initiator'}] review delivery receipt and verify tests [${ticketId}]: ${display} (Round ${roundNum} · DELIVERED · ${rConcl}${rSummary})\n(Delivery complete, receipt ready [${ticketId}]: ${display})`);
|
|
2316
2572
|
if (isZh) {
|
|
2317
|
-
console.log(`\nℹ️
|
|
2318
|
-
console.log(verdictLine + '\n');
|
|
2573
|
+
console.log(`\nℹ️ 交付收尾(接收方回复末尾单行纯文本,建议格式):`);
|
|
2574
|
+
console.log(verdictLine.split('\n')[0] + '\n');
|
|
2319
2575
|
console.log(`💡 [接收方纪律] 本端职责已完成,闭环(accept/close)归发起方所有,严禁接收方越权闭环;严禁反向输出交接卡片。\n`);
|
|
2320
2576
|
} else {
|
|
2321
|
-
console.log(`\nℹ️ Delivery Epilogue (Receiver outputs single
|
|
2322
|
-
console.log(verdictLine + '\n');
|
|
2577
|
+
console.log(`\nℹ️ Delivery Epilogue (Receiver outputs single line at the end, recommended format):`);
|
|
2578
|
+
console.log(verdictLine.split('\n')[0] + '\n');
|
|
2323
2579
|
console.log(`💡 [Receiver Rule] This lane task is complete. Ticket closure (accept/close) is reserved for the initiator.\n`);
|
|
2324
2580
|
}
|
|
2325
2581
|
} else {
|
|
@@ -2376,8 +2632,10 @@ function cmdReceipt(args) {
|
|
|
2376
2632
|
return withTicketLock(id, () => {
|
|
2377
2633
|
const hFm = readFM(fs.readFileSync(hFile, 'utf8'));
|
|
2378
2634
|
const st = hFm?.status;
|
|
2635
|
+
assertTicketAffinity(id, explicitDeliver ? 'deliver' : 'receipt', args);
|
|
2379
2636
|
// 防提前闭环(v2.13 / v2.25 P0-3 强化 / ADR-0008 Phase 2 显式声明):发起方禁止自填回执,且仓内模式强制校验执行身份
|
|
2380
2637
|
const cur = resolveExecutionLane(asInput, { fromLane: hFm?.from_lane, toLane: hFm?.to_lane, op: explicitDeliver ? 'deliver' : 'receipt', ticketId: id });
|
|
2638
|
+
assertRoleCommandAllowed(explicitDeliver ? 'deliver' : 'receipt', cur, hFm);
|
|
2381
2639
|
if (MODE === 'intra-repo') {
|
|
2382
2640
|
const toLane = String(hFm?.to_lane || '').toLowerCase();
|
|
2383
2641
|
const fromLane = String(hFm?.from_lane || '').toLowerCase();
|
|
@@ -2395,6 +2653,7 @@ function cmdReceipt(args) {
|
|
|
2395
2653
|
process.exit(1);
|
|
2396
2654
|
}
|
|
2397
2655
|
}
|
|
2656
|
+
bindSessionTicket(id, hFm?.round || 1, args.includes('--force-ticket') || process.env.BATON_FORCE_TICKET === '1');
|
|
2398
2657
|
// 状态转换合法性内联(v2.6;v2.12.5 放开 draft):draft/forwarded → received。
|
|
2399
2658
|
if (st === 'draft') {
|
|
2400
2659
|
console.log(`ℹ️ ${id} 仍为 draft(发起方未跑可选标记 forward)→ 直接登记回执(draft → received)。`);
|
|
@@ -2554,7 +2813,11 @@ function cmdReceipt(args) {
|
|
|
2554
2813
|
writeReceiptFile(rFile, rFm, note, receiptStubIntra(id, hFm.from_lane || ''));
|
|
2555
2814
|
setFM(hFile, { status: 'received', needs_change: needsChange });
|
|
2556
2815
|
if (shouldDeliver) {
|
|
2557
|
-
|
|
2816
|
+
const deliverArgs = [id, '--as', cur];
|
|
2817
|
+
if (args.includes('--force-ticket')) deliverArgs.push('--force-ticket');
|
|
2818
|
+
if (args.includes('--force-session')) deliverArgs.push('--force-session');
|
|
2819
|
+
if (args.includes('--auto-nonce')) deliverArgs.push('--auto-nonce');
|
|
2820
|
+
cmdDeliver(deliverArgs);
|
|
2558
2821
|
return;
|
|
2559
2822
|
}
|
|
2560
2823
|
logStateJournal(id, 'receipt', {
|
|
@@ -2582,7 +2845,10 @@ function cmdReceipt(args) {
|
|
|
2582
2845
|
const authorLabel = `${TARGET_LABELS[hTarget] || hTarget} 侧回执`;
|
|
2583
2846
|
writeReceiptFile(rFile, rFm, note, receiptStub(id, authorLabel));
|
|
2584
2847
|
if (shouldDeliver) {
|
|
2585
|
-
|
|
2848
|
+
const deliverArgs = [id];
|
|
2849
|
+
if (args.includes('--force-ticket')) deliverArgs.push('--force-ticket');
|
|
2850
|
+
if (args.includes('--force-session')) deliverArgs.push('--force-session');
|
|
2851
|
+
cmdDeliver(deliverArgs);
|
|
2586
2852
|
return;
|
|
2587
2853
|
}
|
|
2588
2854
|
setFM(hFile, { status: 'received', needs_change: needsChange, needs_iggle_change: needsChange });
|
|
@@ -2630,6 +2896,7 @@ function cmdDeliver(args) {
|
|
|
2630
2896
|
const hRaw = fs.readFileSync(hFile, 'utf8');
|
|
2631
2897
|
const hFm = readFM(hRaw) || {};
|
|
2632
2898
|
const st = hFm?.status;
|
|
2899
|
+
assertTicketAffinity(id, 'deliver', args);
|
|
2633
2900
|
if (st === 'closed') {
|
|
2634
2901
|
console.log(`↩️ ${id} 已闭环,跳过交付。`);
|
|
2635
2902
|
return;
|
|
@@ -2644,6 +2911,8 @@ function cmdDeliver(args) {
|
|
|
2644
2911
|
|
|
2645
2912
|
// 防提前闭环与越界交付(P0-3 修复 / ADR-0008 Phase 2 显式声明)
|
|
2646
2913
|
const cur = resolveExecutionLane(asInput, { fromLane: hFm?.from_lane, toLane: hFm?.to_lane, op: 'deliver', ticketId: id });
|
|
2914
|
+
assertRoleCommandAllowed('deliver', cur, hFm);
|
|
2915
|
+
bindSessionTicket(id, hFm?.round || 1, args.includes('--force-ticket') || process.env.BATON_FORCE_TICKET === '1');
|
|
2647
2916
|
if (MODE === 'intra-repo') {
|
|
2648
2917
|
const toLane = String(hFm?.to_lane || '').toLowerCase();
|
|
2649
2918
|
const fromLane = String(hFm?.from_lane || '').toLowerCase();
|
|
@@ -3270,6 +3539,12 @@ function cmdShow(args) {
|
|
|
3270
3539
|
console.log(fm.audit_nonce);
|
|
3271
3540
|
return;
|
|
3272
3541
|
}
|
|
3542
|
+
bindSessionTicket(id, fm?.round || 1);
|
|
3543
|
+
const asLane = flagValue(args, '--as') || flagValue(args, '--by');
|
|
3544
|
+
const curLane = resolveExecutionLane(asLane, { fromLane: fm?.from_lane, toLane: fm?.to_lane, op: 'show', ticketId: id });
|
|
3545
|
+
if (curLane && !args.includes('--json')) {
|
|
3546
|
+
printRoleCapabilityBanner(curLane, id, fm?.round || 1);
|
|
3547
|
+
}
|
|
3273
3548
|
const body = stripFM(raw);
|
|
3274
3549
|
console.log(`# ${id}`);
|
|
3275
3550
|
const keys = isResp
|
|
@@ -3364,7 +3639,7 @@ const STUB_BODY_ZH = `### Agent Baton (Handoff) 接入桩(轻量韧性版 ·
|
|
|
3364
3639
|
|
|
3365
3640
|
**核心守卫与身份(强制)**
|
|
3366
3641
|
- **物理工作区边界**:会话严格绑定当前宿主工作区,严禁跨仓 cd 操作外部代码;跨仓请输出交接提示词引导人类在目标仓 Agent 会话中派发。
|
|
3367
|
-
-
|
|
3642
|
+
- **一单到底与互斥粘性锁(强制 · v2.44.0)**:工单物理 ID 即为会话 ID(全局唯一统一),严禁物理 ID 与会话 ID 分裂。同一接单会话严格绑定单一工单(一单到底),严禁跨工单越界写操作(CROSS_TICKET_CONTAMINATION_BLOCKED);所有轮次(Round 1..N)在原单同一 ID 下流转闭环,严禁轮次变异;任务主题全生命周期保持一致。
|
|
3368
3643
|
- **严禁跨会话处理工单(最高宪法级隔离)**:工单全程严格绑定发起会话;严禁跨会话处理/推进/闭环外部工单(\`forward\`/\`accept\`/\`reopen\` 仅限原发起会话执行;接收方接单必须显式带工单编号,严禁从全局待办中盲目抢单)。
|
|
3369
3644
|
- **命令形态与显式身份**:一律 \`baton <op>\` 或 \`handoff <op>\`。全面支持 \`--as <lane>\` 显式声明身份,同一会话无缝切换多工单。
|
|
3370
3645
|
- **会话身份锁与凭证防伪**:支持 \`baton lane <lane>\` 锁定会话身份;环境绑定优先级 \`HANDOFF_LANE\` > \`baton lane\` > \`--as <lane>\`;审计交付必须持有 \`audit.token\` 密码学签章,禁止发起方跨角色自我闭环。
|
|
@@ -3373,28 +3648,29 @@ const STUB_BODY_ZH = `### Agent Baton (Handoff) 接入桩(轻量韧性版 ·
|
|
|
3373
3648
|
**入站工作流(接单 · 交付 · 退回)**
|
|
3374
3649
|
1. **查待办**:运行 \`baton status --as <本方 lane|target> --current\`(或全局 \`baton status --current\`)。
|
|
3375
3650
|
2. **读工单**:运行 \`baton show <id>\`,根据验收判据改动本 lane 范围代码并实测。
|
|
3376
|
-
3.
|
|
3377
|
-
-
|
|
3651
|
+
3. **交付或退回(实测为唯一准绳 · 必须调用 CLI 推进状态 · 必须写成 Markdown)**:
|
|
3652
|
+
- **格式铁律**:无论是开单还是回执,必须严格使用标准 Markdown 格式(.md),严禁写成无结构的纯文本(.txt)!
|
|
3653
|
+
- **实测通过**:严格遵循 \`$(lab path handoffs)/RESPONSE-TEMPLATE.md\` 骨架撰写回执(包含状态/结论锚节与明确结论)→ 运行 \`baton receipt <id> -n "<正文>" --deliver --as <本方 lane> --evidence-paths "<路径>"\`(审计工单附 \`--audit-nonce "<nonce>"\` 或同工作区授权下使用 \`--auto-nonce\` 自动绑定最新令牌;红队用例严格遵循 NO_DISPATCH / NO_COMPLETE / COMPLETE 三态标准;**严禁只写 Markdown 文件不翻状态**,必须通过 CLI 推进工单状态至 delivered!)。
|
|
3378
3654
|
- **实测未过(NO-GO/受阻)**:审计方享有安全下车通道,运行 \`baton reject <id> -n "<理由/差异在哪>" --as audit\` 退回整改;普通执行方若受阻/缺失条件,登记受阻回执 \`baton receipt <id> -n "<缺失条件/受阻理由>" --evidence-note "<说明>" --as <本方 lane>\` 由发起方核实并处理。
|
|
3379
3655
|
4. **收尾自检**:运行 \`baton check [id]\`(若有数据漂移可加 \`--fix\` 自动修复)。
|
|
3380
|
-
5. **入站回复收尾(简洁单行裁决 · 严禁角色漂移 ·
|
|
3381
|
-
-
|
|
3382
|
-
-
|
|
3383
|
-
-
|
|
3384
|
-
|
|
3656
|
+
5. **入站回复收尾(简洁单行裁决 · 严禁角色漂移 · 方案 A 权威标准)**:接收方受 CLI 物理权限白名单锁定,硬拦截 close/forward/prompt;接收方必须严格保持本方执行/审计角色,严禁切换为发起方角色;**严禁反向输出 \`## Baton Pass Prompt\` 卡片或调用 \`baton close\` 越权闭环**;最终回复人类的最末尾仅输出单行纯文本(无需标题,无需代码块,严禁多行出站卡片):
|
|
3657
|
+
- 审计驳回:\`请 [<目标角色>] 按驳回记录修订并重新交付 [<工单编号>]:<回执路径>(Round <轮次> · NO-GO · <一句话驳回原因>)\`
|
|
3658
|
+
- 审计通过:\`请 [<发起角色>] 查收审计回执并闭环工单 [<工单编号>]:<回执路径>(Round <轮次> · GO · <一句话通过总结>)\`
|
|
3659
|
+
- 普通交付:\`请 [<审查角色>] 查收交付回执并独立实测 [<工单编号>]:<回执路径>(Round <轮次> · DELIVERED · <一句话完成摘要>)\`
|
|
3660
|
+
(兼容极简格式:\`审计完成,裁决 NO-GO / GO / 交付完成,回执已就绪\`;后续 Round 轮次由发起方在出站重新转递时统筹计算并派发)。
|
|
3385
3661
|
|
|
3386
3662
|
**出站工作流(派发 · 监听 · 严禁漏开监听)**
|
|
3387
|
-
1. **建单与转递(单工单原子闭环 · 99%场景)**:\`baton new <target|lane> <type> "<标题>"\`,填写正文后直接作为宿主后台任务(如 \`WaitMsBeforeAsync: 500\`)运行 \`baton forward <id> --wait\`(双盲审计附加 \`--blind\` 脱敏思考自辩;单工单严禁使用 \`--async\`
|
|
3663
|
+
1. **建单与转递(单工单原子闭环 · 99%场景)**:\`baton new <target|lane> <type> "<标题>"\`,填写正文后直接作为宿主后台任务(如 \`WaitMsBeforeAsync: 500\`)运行 \`baton forward <id> --wait\`(双盲审计附加 \`--blind\` 脱敏思考自辩;单工单严禁使用 \`--async\` 拆分两步!**派发后必须挂起监听,严禁漏开监听**)。
|
|
3388
3664
|
2. **多单并发派发(仅限一次性派发多单)**:\`baton forward <id1> <id2> ... --async\`,派发后必须立即作为后台任务运行 \`baton wait <id1> <id2> ... --all\` 聚合监听平账(严禁将多单提示词混杂在同一个代码块内)。
|
|
3389
3665
|
3. **宿主任务与降级监听纪律(强制 · v2.42.0)**:
|
|
3390
3666
|
- **严禁将普通 shell \`session_id\` 当作自动唤醒保证**:\`exec_command\` 返回的 \`session_id\` 仅为普通终端会话,宿主无反应式自主唤醒机制;仅在确认宿主具备真正的任务完成事件驱动唤醒能力(如 Antigravity \`run_command\` 的 \`WaitMsBeforeAsync\`)时,才可宣称监听已自动接管。
|
|
3391
3667
|
- **非反应式宿主降级协议**:在不支持后台任务完成自主唤醒的宿主中,必须在提示词前向人类明示「降级监听:只监听、不自动续办」,说明执行方交付后人类只需发送任意消息/按回车唤起本会话;
|
|
3392
3668
|
- **会话恢复自动续办纪律**:任何会话恢复交互时,必须先运行 \`baton status --current\`,识别到 \`delivered\` 状态后自动进入 \`show → 独立实测复核 → close/reject\`,严禁要求用户重述已交付事实或粘贴回执!
|
|
3393
3669
|
4. **出站回复收尾(交接提示词规范)**:出站由发起方统一计算与推进 Round 轮次;回复最末块必须固定为独立代码块,方便人类一键复制给接收方 Agent(其后无任何正文):
|
|
3394
|
-
##
|
|
3670
|
+
## Baton Pass Prompt
|
|
3395
3671
|
\`\`\`text
|
|
3396
|
-
请 [
|
|
3397
|
-
[发起角色] [
|
|
3672
|
+
请 [<to_lane>] 接单:
|
|
3673
|
+
[发起角色] [<from_lane>]
|
|
3398
3674
|
[任务主题] <主题>
|
|
3399
3675
|
[任务轮次] Round <round>(第 <round> 轮复审)
|
|
3400
3676
|
[工单编号] [<conversation_id>]
|
|
@@ -3410,7 +3686,7 @@ const STUB_BODY_EN = `### Agent Baton (Handoff) Guard Stub (Resilient & Slim ·
|
|
|
3410
3686
|
|
|
3411
3687
|
**Core Guards & Identity (Mandatory)**
|
|
3412
3688
|
- **Workspace Boundary**: Agent session is strictly pinned to active workspace. Never cross boundaries via cd to mutate external code; output a Baton Pass Prompt for cross-repo tasks.
|
|
3413
|
-
- **Single Ticket Lifecycle &
|
|
3689
|
+
- **Single Ticket Lifecycle & Affinity Lock (Mandatory · v2.44.0)**: Ticket physical ID is conversation ID (unified), immutable across all rounds (Round 1..N); agent session strictly locked to single ticket per context (anti-cross-ticket contamination); task topic remains constant.
|
|
3414
3690
|
- **Anti-Cross-Session Hard Gate (Constitutional Isolation)**: Tickets strictly bind to initiator conversation; cross-session mutation/closure (\`forward\`/\`accept\`/\`reopen\`) is prohibited. Receivers take tickets with explicit IDs.
|
|
3415
3691
|
- **CLI Form & Explicit Identity**: Always use \`baton <op>\` or \`handoff <op>\`. Full support for \`--as <lane>\` explicit identity override, enabling multi-ticket processing within the same session.
|
|
3416
3692
|
- **Session Lane Lock & Cryptographic Signatures**: Lock identity via \`baton lane <lane>\`; precedence is \`HANDOFF_LANE\` > \`baton lane\` > \`--as <lane>\`; audit delivery requires \`audit.token\` signatures.
|
|
@@ -3419,18 +3695,19 @@ const STUB_BODY_EN = `### Agent Baton (Handoff) Guard Stub (Resilient & Slim ·
|
|
|
3419
3695
|
**Inbound Workflow (Receive · Deliver · Reject)**
|
|
3420
3696
|
1. **Check Pending**: Run \`baton status --as <my lane|target> --current\` (or global \`baton status --current\`).
|
|
3421
3697
|
2. **Inspect Ticket**: Run \`baton show <id>\`, implement scoped changes, and independently run tests.
|
|
3422
|
-
3. **Deliver or Reject (Empirical Tests are the Sole Authority)**:
|
|
3423
|
-
- **
|
|
3698
|
+
3. **Deliver or Reject (Empirical Tests are the Sole Authority · Must Update State via CLI · Must be Markdown)**:
|
|
3699
|
+
- **Markdown Format Invariant**: Both ticket creation and receipt submission MUST be authored in standard Markdown (.md). Never use plain text (.txt)!
|
|
3700
|
+
- **All Tests Pass**: Strictly follow \`$(lab path handoffs)/RESPONSE-TEMPLATE.md\` skeleton (must include verdict section & clear verdict line) → run \`baton receipt <id> -n "<Body>" --deliver --as <my lane> --evidence-paths "<files>"\` (audit tickets require \`--audit-nonce "<nonce>"\` or \`--auto-nonce\`; red-team probes must follow three-state standard: NO_DISPATCH / NO_COMPLETE / COMPLETE; **prohibited from only creating Markdown without state transition**, must advance ticket state via CLI!).
|
|
3424
3701
|
- **Tests Fail / Blocked (NO-GO)**: Use unconditional egress channel, run \`baton reject <id> -n "<reason/missing condition>" --as <my lane>\` to send back for revision (draft receipts can be logged without blocker).
|
|
3425
3702
|
4. **Wrap-up Check**: Run \`baton check [id]\` (supports \`--fix\` for auto-repair).
|
|
3426
|
-
5. **Inbound Reply Epilogue (Concise One-Line Verdict · Anti-Role-Drift ·
|
|
3427
|
-
-
|
|
3428
|
-
-
|
|
3429
|
-
- General Delivery: \`
|
|
3430
|
-
|
|
3703
|
+
5. **Inbound Reply Epilogue (Concise One-Line Verdict · Anti-Role-Drift · Scheme A Standard)**: Receiver is physically locked by role-command whitelist; CLI hard-blocks close/forward/prompt; receiver must strictly maintain own execution/audit role without role drift; strictly prohibited from generating reverse \`## Baton Pass Prompt\` cards or calling \`baton close\`; output only a single plain-text line at the very end of your response to the user (no markdown headers, no code blocks, strictly no multi-line outbound cards):
|
|
3704
|
+
- Rejection (NO-GO): \`Please [<target_lane>] revise per rejection record and re-deliver [<ticket_id>]: <receipt_path> (Round <N> · NO-GO · <one-line reason>)\`
|
|
3705
|
+
- Pass (GO): \`Please [<initiator_lane>] review audit receipt and close ticket [<ticket_id>]: <receipt_path> (Round <N> · GO · <one-line summary>)\`
|
|
3706
|
+
- General Delivery: \`Please [<reviewer_lane>] review delivery receipt and verify tests [<ticket_id>]: <receipt_path> (Round <N> · DELIVERED · <one-line summary>)\`
|
|
3707
|
+
(Compatible with legacy concise form: \`Audit complete, verdict NO-GO/GO / Delivery complete, receipt ready\`).
|
|
3431
3708
|
|
|
3432
3709
|
**Outbound Workflow (Dispatch · Listen · Mandatory Listener)**
|
|
3433
|
-
1. **Create & Forward (Single Ticket Atomic · 99% cases)**: \`baton new <target|lane> <type> "<Title>"\`, fill body, then run \`baton forward <id> --wait\` as a host background task (add \`--blind\` for double-blind audit; single-ticket \`--async\` split is strictly prohibited
|
|
3710
|
+
1. **Create & Forward (Single Ticket Atomic · 99% cases)**: \`baton new <target|lane> <type> "<Title>"\`, fill body, then run \`baton forward <id> --wait\` as a host background task (add \`--blind\` for double-blind audit; single-ticket \`--async\` split is strictly prohibited; **listener must be running, never forget listener**).
|
|
3434
3711
|
2. **Concurrent Batch Dispatch (Multiple tickets only)**: \`baton forward <id1> <id2> ... --async\`, then immediately run \`baton wait <id1> <id2> ... --all\` as a host background task to clear debt (never bundle multiple tickets into one prompt card).
|
|
3435
3712
|
3. **Host Task & Downgrade Protocol (Mandatory · v2.42.0)**:
|
|
3436
3713
|
- **Prohibit treating shell \`session_id\` as auto-wakeup guarantee**: Shell \`session_id\` from \`exec_command\` represents an interactive shell session without reactive wakeup; only claim auto-managed listener when the host confirms an event-driven task completion hook (e.g. Antigravity \`run_command\` \`WaitMsBeforeAsync\`).
|
|
@@ -3439,8 +3716,8 @@ const STUB_BODY_EN = `### Agent Baton (Handoff) Guard Stub (Resilient & Slim ·
|
|
|
3439
3716
|
4. **Outbound Reply Closing (Baton Pass Prompt)**: Initiator calculates and advances Round count; end outbound replies with an isolated code block for one-click human copying (no text after):
|
|
3440
3717
|
## Baton Pass Prompt
|
|
3441
3718
|
\`\`\`text
|
|
3442
|
-
Please [<
|
|
3443
|
-
[Initiator] [<
|
|
3719
|
+
Please [<to_lane>] take handoff:
|
|
3720
|
+
[Initiator] [<from_lane>]
|
|
3444
3721
|
[Task Topic] <Title>
|
|
3445
3722
|
[Task Round] Round <round> (Review Round <round>)
|
|
3446
3723
|
[Ticket ID] [<conversation_id>]
|
|
@@ -3597,6 +3874,22 @@ function cmdCheckCross(args = []) {
|
|
|
3597
3874
|
if (fm.status === 'closed' && !/^## (验收记录|Audit Record|Acceptance Record)/im.test(raw))
|
|
3598
3875
|
problems.push(`[交接] status=closed 但缺「验收记录」节(须经 handoff accept <id> -n "<结论>" 闭环): ${f}`);
|
|
3599
3876
|
|
|
3877
|
+
// 状态流转硬门禁:防止回执方只写回执 Markdown 文件却漏跑 baton receipt / baton deliver 推进状态
|
|
3878
|
+
const rPathCross = path.join(R_DIR, `${id}-resp.md`);
|
|
3879
|
+
if ((fm.status === 'draft' || fm.status === 'forwarded') && fs.existsSync(rPathCross)) {
|
|
3880
|
+
try {
|
|
3881
|
+
const rRaw = fs.readFileSync(rPathCross, 'utf8');
|
|
3882
|
+
const rBody = stripFM(rRaw);
|
|
3883
|
+
const rFm = readFM(rRaw) || {};
|
|
3884
|
+
const concl = extractConclusion(rBody);
|
|
3885
|
+
const hasSubstance = Boolean(concl || (rBody && rBody.length > 50) || rFm.evidence_paths);
|
|
3886
|
+
const isLegacy = fm.created && fm.created < '2026-11-15';
|
|
3887
|
+
if (!isLegacy && hasSubstance) {
|
|
3888
|
+
problems.push(`[状态流转违例] 检测到回执 receipts/${id}-resp.md 已存在且有实质内容,但工单状态仍停留在 ${fm.status}。回执方严禁只写 Markdown 文件不翻状态,必须调用 CLI (baton receipt ${id} --deliver 或 baton deliver ${id}) 推进工单状态!`);
|
|
3889
|
+
}
|
|
3890
|
+
} catch {}
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3600
3893
|
// 状态机语义不变量校验(v2.25 · P1-1 修复)
|
|
3601
3894
|
if (fm.status === 'closed') {
|
|
3602
3895
|
if (fm.rejected_at) {
|
|
@@ -3707,8 +4000,25 @@ function cmdCheckIntra(args = []) {
|
|
|
3707
4000
|
if (fm.status === 'closed' && !/^## (验收记录|Audit Record|Acceptance Record)/im.test(raw))
|
|
3708
4001
|
problems.push(`[交接] status=closed 但缺「验收记录」节(须经 handoff accept <id> -n "<结论>" 闭环): ${f}`);
|
|
3709
4002
|
|
|
3710
|
-
//
|
|
4003
|
+
// 状态流转硬门禁:防止回执方只写回执 Markdown 文件却漏跑 baton receipt / baton deliver 推进状态
|
|
4004
|
+
// 注意:若工单处于驳回待整改状态(rejected_at 存在且 needs_change=true),回执记录的是驳回意见而非待交付成果,豁免此项检测。
|
|
3711
4005
|
const rPath = path.join(R_DIR, `${id}-resp.md`);
|
|
4006
|
+
const isUnderRejection = Boolean(fm.rejected_at && (fm.needs_change === true || fm.needs_change === 'true'));
|
|
4007
|
+
if (!isUnderRejection && (fm.status === 'draft' || fm.status === 'forwarded') && fs.existsSync(rPath)) {
|
|
4008
|
+
try {
|
|
4009
|
+
const rRaw = fs.readFileSync(rPath, 'utf8');
|
|
4010
|
+
const rBody = stripFM(rRaw);
|
|
4011
|
+
const rFm = readFM(rRaw) || {};
|
|
4012
|
+
const concl = extractConclusion(rBody);
|
|
4013
|
+
const hasSubstance = Boolean(concl || (rBody && rBody.length > 50) || rFm.evidence_paths);
|
|
4014
|
+
const isLegacy = fm.created && fm.created < '2026-11-15';
|
|
4015
|
+
if (!isLegacy && hasSubstance) {
|
|
4016
|
+
problems.push(`[状态流转违例] 检测到回执 receipts/${id}-resp.md 已存在且有实质内容,但工单状态仍停留在 ${fm.status}。回执方严禁只写 Markdown 文件不翻状态,必须调用 CLI (baton receipt ${id} --deliver 或 baton deliver ${id}) 推进工单状态!`);
|
|
4017
|
+
}
|
|
4018
|
+
} catch {}
|
|
4019
|
+
}
|
|
4020
|
+
|
|
4021
|
+
// needs_change 一致性校验与安全修复
|
|
3712
4022
|
if (fs.existsSync(rPath)) {
|
|
3713
4023
|
const rRaw = fs.readFileSync(rPath, 'utf8');
|
|
3714
4024
|
const rFm = readFM(rRaw) || {};
|
|
@@ -4126,8 +4436,8 @@ function cmdPrompt(args) {
|
|
|
4126
4436
|
: `❌ [Reverse Prompt Blocked (REVERSE_PROMPT_BLOCKED)] Current role is the ticket's receiver (lane=${callerLane || asLane}). Outbound prompt cards are reserved for the initiator!`);
|
|
4127
4437
|
process.exit(1);
|
|
4128
4438
|
}
|
|
4129
|
-
const toRole =
|
|
4130
|
-
const fromRole =
|
|
4439
|
+
const toRole = toLane || (isZh ? '执行方' : 'Executor');
|
|
4440
|
+
const fromRole = fromLane || (isZh ? '发起方' : 'Initiator');
|
|
4131
4441
|
const cleanTitle = sanitizeTaskTopic(title);
|
|
4132
4442
|
const round = Number(fm.round || 1);
|
|
4133
4443
|
const roundLineZh = round > 1 ? `[任务轮次] Round ${round}(第 ${round} 轮复审)\n` : '';
|
|
@@ -4136,8 +4446,8 @@ function cmdPrompt(args) {
|
|
|
4136
4446
|
const profileLineEn = fm.tool_profile === 'readonly' ? `[Tool Profile] tool_profile=readonly (Read-only: Prohibited from modifying production code)\n` : '';
|
|
4137
4447
|
const convId = fm.conversation_id || getSessionId();
|
|
4138
4448
|
const promptId = convId || id;
|
|
4139
|
-
const initiatorLineZh = `[发起角色] [${fromRole}]
|
|
4140
|
-
const initiatorLineEn = `[Initiator] [${fromRole}]
|
|
4449
|
+
const initiatorLineZh = `[发起角色] [${fromRole}]\n`;
|
|
4450
|
+
const initiatorLineEn = `[Initiator] [${fromRole}]\n`;
|
|
4141
4451
|
const isAuditLane = (toLane === 'audit');
|
|
4142
4452
|
const roleAnchorZh = isAuditLane ? `[角色锚定] 本会话即为独立审计沙箱,请直接作为审计执行员进行独立测试与核验(切勿触发派单逻辑)\n` : '';
|
|
4143
4453
|
const roleAnchorEn = isAuditLane ? `[Role Anchor] This session is an isolated audit sandbox. Act directly as the audit verifier to execute and verify tests (do not trigger dispatch/forwarding logic).\n` : '';
|
|
@@ -4166,7 +4476,7 @@ function cmdPrompt(args) {
|
|
|
4166
4476
|
if (isZh) {
|
|
4167
4477
|
console.log(`📋 仓内交接 (${id}) · workspace=${ws}:`);
|
|
4168
4478
|
console.log(` 主题: ${cleanTitle}`);
|
|
4169
|
-
console.log(`\n##
|
|
4479
|
+
console.log(`\n## Baton Pass Prompt\n`);
|
|
4170
4480
|
console.log(`> 直接复制下方提示词,发送给接收方 Agent 接单:\n`);
|
|
4171
4481
|
console.log(`\`\`\`text`);
|
|
4172
4482
|
console.log(chosenPromptText);
|
|
@@ -4248,7 +4558,7 @@ function cmdPrompt(args) {
|
|
|
4248
4558
|
process.exit(3);
|
|
4249
4559
|
}
|
|
4250
4560
|
|
|
4251
|
-
const targetLabel = pTarget
|
|
4561
|
+
const targetLabel = pTarget || (isZh ? 'dependency' : 'dependency');
|
|
4252
4562
|
const cleanTitle = sanitizeTaskTopic(title);
|
|
4253
4563
|
const round = Number(readFM(content)?.round || 1);
|
|
4254
4564
|
const roundLineZh = round > 1 ? `[任务轮次] Round ${round}(第 ${round} 轮复审)\n` : '';
|
|
@@ -4268,7 +4578,7 @@ function cmdPrompt(args) {
|
|
|
4268
4578
|
if (isZh) {
|
|
4269
4579
|
console.log(`📋 跨仓交接 (${id}) · target=${pTarget || 'unknown'}:`);
|
|
4270
4580
|
console.log(` 主题: ${cleanTitle}`);
|
|
4271
|
-
console.log(`\n##
|
|
4581
|
+
console.log(`\n## Baton Pass Prompt\n`);
|
|
4272
4582
|
console.log(`> 直接复制下方提示词,发送给接收方 Agent 接单:\n`);
|
|
4273
4583
|
console.log(`\`\`\`text`);
|
|
4274
4584
|
console.log(chosenPromptText);
|