mpt-workflow 0.6.0 → 0.7.0

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.
@@ -1,15 +1,16 @@
1
- import path from 'node:path';
2
1
  import { spawn } from 'node:child_process';
3
- import { exists, ensureDir, readText, readTextRequired, writeAtomic, within, truncate, isoNow, } from './fsutil.js';
4
- import { loadConfig, saveConfig, findRoot, runtimeDir, evidenceDir, } from './config.js';
5
- import { listTodoFiles, parsePlan, parseTodo, parseEvidence, setTodoStatus, setTodoSha, appendEvidenceSection, statusLabel, } from './docs.js';
6
- import { parseQuestionsFile, questionsFile, updateQuestion, } from './questions.js';
7
- import { gitInfo, allChangedFiles, workingTreeHash, workingTreeOid, stageAll, commit as gitCommit, diffStat, } from './git.js';
2
+ import path from 'node:path';
8
3
  import { checkAcl } from './acl.js';
9
- import { appendToSection } from './markdown.js';
4
+ import { evidenceDir, findRoot, loadConfig, runtimeDir, saveConfig } from './config.js';
5
+ import { appendEvidenceSection, listTodoFiles, parseEvidence, parsePlan, parseTodo, setTodoSha, setTodoStatus, statusLabel, } from './docs.js';
6
+ import { ensureDir, exists, isoNow, readText, readTextRequired, truncate, within, writeAtomic, } from './fsutil.js';
10
7
  import { dirSize, formatBytes } from './gc.js';
11
- import { createApproval, readApproval, writeApproval, listApprovals, logEvent, withLock, } from './state.js';
12
- import { MessageStore, actorKey, actorFromRole } from './messages.js';
8
+ import { allChangedFiles, diffStat, commit as gitCommit, gitInfo, stageAll, stagedTreeHash, workingTreeHash, workingTreeOid, } from './git.js';
9
+ import { matchGlob } from './glob.js';
10
+ import { appendToSection } from './markdown.js';
11
+ import { actorFromRole, actorKey, MessageStore } from './messages.js';
12
+ import { parseQuestionsFile, questionsFile, updateQuestion } from './questions.js';
13
+ import { createApproval, listApprovals, logEvent, readApproval, withLock, writeApproval, } from './state.js';
13
14
  export class Workflow {
14
15
  root;
15
16
  cfg;
@@ -119,7 +120,7 @@ export class Workflow {
119
120
  }
120
121
  /** Answer a question: update the file, notify the asker, clear the blocker. */
121
122
  answerQuestion(q, answer, resolution, by) {
122
- updateQuestion(q.file, q.id, { status: 'answered', answer, resolution });
123
+ withLock(this.root, 'questions', () => updateQuestion(q.file, q.id, { status: 'answered', answer, resolution }));
123
124
  const asker = actorFromRole(String(q.from), q.repo);
124
125
  try {
125
126
  this.msgs.send({
@@ -146,7 +147,7 @@ export class Workflow {
146
147
  }
147
148
  /** Close a question: update the file, notify the other party. */
148
149
  closeQuestion(q, resolution, by) {
149
- updateQuestion(q.file, q.id, { status: 'closed', resolution });
150
+ withLock(this.root, 'questions', () => updateQuestion(q.file, q.id, { status: 'closed', resolution }));
150
151
  const asker = actorFromRole(String(q.from), q.repo);
151
152
  const addressee = actorFromRole(String(q.to), q.repo);
152
153
  const other = actorKey(by) === actorKey(asker) ? addressee : asker;
@@ -232,14 +233,15 @@ export class Workflow {
232
233
  problems.push('PLAN 中未解析到任何 M,且无 TODO-Mn.md');
233
234
  if (git.dirty)
234
235
  problems.push(`工作区有未提交改动: ${git.changed.length + git.untracked.length} 个文件`);
235
- if (current && current.status === 'accepted')
236
- problems.push(`${current.id} 已验收但尚未提交`);
236
+ const acceptedMilestones = milestones.filter((m) => m.status === 'accepted');
237
+ if (acceptedMilestones.length) {
238
+ problems.push(`${acceptedMilestones.map((m) => m.id).join(', ')} 已验收但尚未提交`);
239
+ }
237
240
  for (const q of questions.filter((q) => q.blocking && q.status === 'open')) {
238
241
  problems.push(`阻塞问题未回答: ${q.id}`);
239
242
  }
240
243
  // phase: explicit PLAN phase, else the phase that lists this repo
241
- const phase = plan?.phase ||
242
- this.cfg.phases.find((p) => p.repos.includes(id))?.id;
244
+ const phase = plan?.phase || this.cfg.phases.find((p) => p.repos.includes(id))?.id;
243
245
  return {
244
246
  id,
245
247
  path: conf.path,
@@ -321,6 +323,18 @@ export class Workflow {
321
323
  });
322
324
  return out;
323
325
  }
326
+ const pendingCommit = active.milestones.filter((x) => x.status === 'accepted');
327
+ if (pendingCommit.length) {
328
+ out.push({
329
+ actor: 'user',
330
+ action: '评审并 commit',
331
+ detail: `${pendingCommit.map((x) => x.id).join(', ')} 已验收,等待 review diff 后批准提交`,
332
+ repo: activeId,
333
+ milestone: pendingCommit[pendingCommit.length - 1].id,
334
+ blocking: false,
335
+ });
336
+ return out;
337
+ }
324
338
  const m = active.currentMilestone;
325
339
  if (active.milestones.length === 0) {
326
340
  out.push({
@@ -408,6 +422,9 @@ export class Workflow {
408
422
  throw new Error(`仓库目录不存在: ${ref.abs}`);
409
423
  }
410
424
  withLock(this.root, 'program', () => {
425
+ const fresh = loadConfig(this.root);
426
+ if (fresh)
427
+ this.cfg = fresh;
411
428
  this.cfg.active_repo = id;
412
429
  this.save();
413
430
  });
@@ -427,18 +444,20 @@ export class Workflow {
427
444
  }
428
445
  }
429
446
  updatePhase(id, status) {
430
- const p = this.cfg.phases.find((x) => x.id === id);
431
- if (!p)
432
- throw new Error(`未知阶段 ${id}`);
433
447
  withLock(this.root, 'program', () => {
434
- const idx = this.cfg.phases.indexOf(p);
448
+ const fresh = loadConfig(this.root);
449
+ if (fresh)
450
+ this.cfg = fresh;
451
+ const p = this.cfg.phases.find((x) => x.id === id);
452
+ if (!p)
453
+ throw new Error(`未知阶段 ${id}`);
435
454
  // keep only one active phase
436
455
  if (status === 'active') {
437
456
  for (const q of this.cfg.phases)
438
457
  if (q.status === 'active')
439
458
  q.status = 'accepted';
440
459
  }
441
- this.cfg.phases[idx].status = status;
460
+ p.status = status;
442
461
  this.save();
443
462
  });
444
463
  }
@@ -453,11 +472,15 @@ export class Workflow {
453
472
  return { abs, doc };
454
473
  }
455
474
  claim(repoId, milestone, role) {
475
+ return withLock(this.root, `todo-${repoId}-${milestone}`, () => this.claimUnlocked(repoId, milestone, role));
476
+ }
477
+ claimUnlocked(repoId, milestone, role) {
456
478
  this.assertNotBlocked(role, repoId);
457
479
  const { abs, doc } = this.requireTodo(repoId, milestone);
458
480
  if (!['todo_ready', 'rejected', 'planned'].includes(doc.status)) {
459
481
  throw new Error(`${milestone} 当前状态为 ${doc.statusRaw},不能 claim(需 待实现/已打回)`);
460
482
  }
483
+ const attempts = (doc.body.match(/^\s*-\s.*\*\*(?:通过|打回)\*\*/gm) ?? []).length;
461
484
  writeAtomic(abs, setTodoStatus(readTextRequired(abs), 'implementing'));
462
485
  logEvent(this.root, { role, tool: 'milestone_claim', repo: repoId, milestone, ok: true });
463
486
  this.notifyEvent({
@@ -467,11 +490,14 @@ export class Workflow {
467
490
  kind: 'event',
468
491
  subject: `${repoId}/${milestone} 开始实现`,
469
492
  refs: { repo: repoId, milestone },
470
- key: `${repoId}:${milestone}:claim`,
493
+ key: `${repoId}:${milestone}:claim:${attempts}`,
471
494
  });
472
495
  return this.milestone(repoId, milestone);
473
496
  }
474
497
  complete(repoId, milestone, role) {
498
+ return withLock(this.root, `todo-${repoId}-${milestone}`, () => this.completeUnlocked(repoId, milestone, role));
499
+ }
500
+ completeUnlocked(repoId, milestone, role) {
475
501
  this.assertNotBlocked(role, repoId);
476
502
  const { abs, doc } = this.requireTodo(repoId, milestone);
477
503
  if (doc.status !== 'implementing') {
@@ -507,6 +533,9 @@ export class Workflow {
507
533
  return m;
508
534
  }
509
535
  accept(repoId, milestone, role, opts = {}) {
536
+ return withLock(this.root, `todo-${repoId}-${milestone}`, () => this.acceptUnlocked(repoId, milestone, role, opts));
537
+ }
538
+ acceptUnlocked(repoId, milestone, role, opts = {}) {
510
539
  if (role !== 'plan' && role !== 'main') {
511
540
  throw new Error(`只有 PLAN/主 agent 能验收;当前角色 ${role}`);
512
541
  }
@@ -516,14 +545,17 @@ export class Workflow {
516
545
  throw new Error(`${milestone} 当前状态为 ${doc.statusRaw},需先 milestone_complete 进入待验收`);
517
546
  }
518
547
  const evidence = parseEvidence(doc);
519
- const passing = evidence.filter((e) => e.exitCode === 0);
520
- if (passing.length === 0 && !opts.force) {
521
- throw new Error(`${milestone} 没有成功的证据(exit=0);拒绝验收`);
548
+ const latest = evidence[evidence.length - 1];
549
+ if (!opts.force) {
550
+ if (!latest)
551
+ throw new Error(`${milestone} 没有证据;拒绝验收`);
552
+ if (latest.exitCode !== 0) {
553
+ throw new Error(`${milestone} 最新证据 exit=${latest.exitCode};拒绝验收`);
554
+ }
522
555
  }
523
556
  const ref = this.repoRef(repoId);
524
557
  const gi = gitInfo(ref.abs);
525
558
  const currentHash = workingTreeHash(ref.abs);
526
- const latest = passing[passing.length - 1];
527
559
  let note = opts.note || '';
528
560
  if (latest?.tree && latest.tree !== workingTreeOid(ref.abs)) {
529
561
  note += '\n⚠️ 最新证据之后工作区又发生了变化,建议重新跑 evidence_run。';
@@ -562,6 +594,9 @@ export class Workflow {
562
594
  return this.milestone(repoId, milestone);
563
595
  }
564
596
  reject(repoId, milestone, role, reason) {
597
+ return withLock(this.root, `todo-${repoId}-${milestone}`, () => this.rejectUnlocked(repoId, milestone, role, reason));
598
+ }
599
+ rejectUnlocked(repoId, milestone, role, reason) {
565
600
  if (role !== 'plan' && role !== 'main') {
566
601
  throw new Error(`只有 PLAN/主 agent 能打回;当前角色 ${role}`);
567
602
  }
@@ -609,7 +644,7 @@ export class Workflow {
609
644
  async runEvidence(input) {
610
645
  const { repoId, milestone, command, role } = input;
611
646
  const ref = this.repoRef(repoId);
612
- const { abs, doc } = this.requireTodo(repoId, milestone);
647
+ this.requireTodo(repoId, milestone); // validate early
613
648
  const cwd = input.cwd ? path.resolve(ref.abs, input.cwd) : ref.abs;
614
649
  if (!within(ref.abs, cwd))
615
650
  throw new Error(`evidence cwd 必须在仓库内: ${cwd}`);
@@ -617,36 +652,40 @@ export class Workflow {
617
652
  const result = await runCommand(command, cwd, input.timeoutMs ?? 900_000);
618
653
  const gi = gitInfo(ref.abs);
619
654
  const tree = workingTreeOid(ref.abs);
620
- const list = parseEvidence(doc);
621
- const id = `E${list.length + 1}`;
622
- const at = isoNow();
623
- const fullOutput = [
624
- `$ ${command}`,
625
- `exit: ${result.code}`,
626
- `head: ${gi.head}`,
627
- `tree: ${tree}`,
628
- `dirty: ${gi.dirty}`,
629
- '',
630
- '--- stdout ---',
631
- result.stdout,
632
- '--- stderr ---',
633
- result.stderr,
634
- ].join('\n');
635
- const dir = path.join(evidenceDir(this.root), repoId, milestone);
636
- ensureDir(dir);
637
- writeAtomic(path.join(dir, `${id}-${Date.now()}.log`), fullOutput);
638
- const tail = truncate([result.stdout, result.stderr].filter(Boolean).join('\n'), 4000);
639
- const text = appendEvidenceSection(readTextRequired(abs), {
640
- id,
641
- at,
642
- command,
643
- exitCode: result.code,
644
- head: gi.shortHead,
645
- tree,
646
- dirty: gi.dirty,
647
- output: tail,
655
+ const recorded = withLock(this.root, `todo-${repoId}-${milestone}`, () => {
656
+ const { abs, doc } = this.requireTodo(repoId, milestone);
657
+ const list = parseEvidence(doc);
658
+ const id = `E${list.length + 1}`;
659
+ const at = isoNow();
660
+ const fullOutput = [
661
+ `$ ${command}`,
662
+ `exit: ${result.code}`,
663
+ `head: ${gi.head}`,
664
+ `tree: ${tree}`,
665
+ `dirty: ${gi.dirty}`,
666
+ '',
667
+ '--- stdout ---',
668
+ result.stdout,
669
+ '--- stderr ---',
670
+ result.stderr,
671
+ ].join('\n');
672
+ const dir = path.join(evidenceDir(this.root), repoId, milestone);
673
+ ensureDir(dir);
674
+ writeAtomic(path.join(dir, `${id}-${Date.now()}.log`), fullOutput);
675
+ const tail = truncate([result.stdout, result.stderr].filter(Boolean).join('\n'), 4000);
676
+ const text = appendEvidenceSection(readTextRequired(abs), {
677
+ id,
678
+ at,
679
+ command,
680
+ exitCode: result.code,
681
+ head: gi.shortHead,
682
+ tree,
683
+ dirty: gi.dirty,
684
+ output: tail,
685
+ });
686
+ writeAtomic(abs, text);
687
+ return { id, output: tail, todoFile: path.relative(this.root, abs) };
648
688
  });
649
- writeAtomic(abs, text);
650
689
  logEvent(this.root, {
651
690
  role,
652
691
  tool: 'evidence_run',
@@ -656,13 +695,13 @@ export class Workflow {
656
695
  detail: { command, exit: result.code, ms: Date.now() - started },
657
696
  });
658
697
  return {
659
- id,
698
+ id: recorded.id,
660
699
  exitCode: result.code,
661
700
  head: gi.shortHead,
662
701
  tree,
663
702
  dirty: gi.dirty,
664
- output: tail,
665
- todoFile: path.relative(this.root, abs),
703
+ output: recorded.output,
704
+ todoFile: recorded.todoFile,
666
705
  };
667
706
  }
668
707
  /* --------------------------- scope check --------------------------- */
@@ -671,9 +710,7 @@ export class Workflow {
671
710
  const ref = this.repoRef(repoId);
672
711
  const changed = allChangedFiles(ref.abs);
673
712
  const st = this.repoState(repoId);
674
- const m = milestone
675
- ? st.milestones.find((x) => x.id === milestone)
676
- : st.currentMilestone;
713
+ const m = milestone ? st.milestones.find((x) => x.id === milestone) : st.currentMilestone;
677
714
  const todo = m ? parseTodo(path.join(ref.abs, `TODO-${m.id}.md`)) : null;
678
715
  const allowed = todo?.allowedFiles || [];
679
716
  const violations = [];
@@ -694,7 +731,7 @@ export class Workflow {
694
731
  for (const f of changed) {
695
732
  if (isWorkflowManaged(f))
696
733
  continue;
697
- const ok = allowed.some((a) => globMatchPath(f, a));
734
+ const ok = allowed.some((a) => matchGlob(f, a.replace(/^\.\//, '')));
698
735
  if (!ok) {
699
736
  outOfScope.push(f);
700
737
  warnings.push(`${f} 不在 TODO 声明的「影响文件」里`);
@@ -712,20 +749,42 @@ export class Workflow {
712
749
  outOfScope,
713
750
  violations,
714
751
  warnings,
715
- pass: violations.length === 0,
752
+ pass: violations.length === 0 && !(role === 'todo' && outOfScope.length > 0),
716
753
  };
717
754
  }
718
755
  /* ----------------------------- commit ------------------------------ */
756
+ /** The milestone being committed: explicit, accepted-but-uncommitted, or current. */
757
+ milestoneForCommit(repoId, explicit) {
758
+ const st = this.repoState(repoId);
759
+ if (explicit) {
760
+ const found = st.milestones.find((m) => m.id === explicit);
761
+ if (!found)
762
+ throw new Error(`${repoId} 没有里程碑 ${explicit}`);
763
+ return found;
764
+ }
765
+ const accepted = st.milestones.filter((m) => m.status === 'accepted');
766
+ if (accepted.length)
767
+ return accepted[accepted.length - 1];
768
+ return st.currentMilestone;
769
+ }
719
770
  requestCommit(input) {
720
771
  const ref = this.repoRef(input.repoId);
721
772
  const files = allChangedFiles(ref.abs);
722
773
  if (files.length === 0)
723
774
  throw new Error('没有可提交的改动');
724
- const scope = this.scopeCheck(input.repoId, undefined, input.role, { enforceAcl: false });
775
+ const milestone = this.milestoneForCommit(input.repoId, input.milestone);
776
+ const scope = this.scopeCheck(input.repoId, milestone?.id, input.role, {
777
+ enforceAcl: false,
778
+ });
725
779
  assertCommitScope(scope, input.role);
780
+ const stage = stageAll(ref.abs);
781
+ if (!stage.ok)
782
+ throw new Error(`git add 失败: ${stage.err}`);
726
783
  const a = createApproval(this.root, {
727
784
  repo: input.repoId,
785
+ milestone: milestone?.id,
728
786
  tree_hash: workingTreeHash(ref.abs),
787
+ staged_hash: stagedTreeHash(ref.abs),
729
788
  message: input.message,
730
789
  files,
731
790
  });
@@ -758,10 +817,20 @@ export class Workflow {
758
817
  throw new Error(`审批 ${id} 不存在`);
759
818
  if (a.used_at)
760
819
  throw new Error(`审批 ${id} 已使用`);
820
+ const current = workingTreeHash(this.repoRef(a.repo).abs);
821
+ if (current !== a.tree_hash) {
822
+ throw new Error(`工作区内容已变化(审批时 ${a.tree_hash},现在 ${current});请重新 commit_request`);
823
+ }
761
824
  a.approved_at = isoNow();
762
825
  a.approved_by = by;
763
826
  writeApproval(this.root, a);
764
- logEvent(this.root, { role: 'user', tool: 'approve', repo: a.repo, ok: true, detail: { approval: id } });
827
+ logEvent(this.root, {
828
+ role: 'user',
829
+ tool: 'approve',
830
+ repo: a.repo,
831
+ ok: true,
832
+ detail: { approval: id },
833
+ });
765
834
  // Approving is how the human handles the notification; clear it from the inbox.
766
835
  try {
767
836
  this.msgs.ackByRef({ role: 'user' }, 'approval_id', id);
@@ -786,7 +855,7 @@ export class Workflow {
786
855
  if (hash !== a.tree_hash) {
787
856
  throw new Error(`工作区内容已变化(审批时 ${a.tree_hash},现在 ${hash});请重新 commit_request 并批准`);
788
857
  }
789
- const scope = this.scopeCheck(input.repoId, undefined, input.role, { enforceAcl: false });
858
+ const scope = this.scopeCheck(input.repoId, a.milestone ?? this.milestoneForCommit(input.repoId)?.id, input.role, { enforceAcl: false });
790
859
  assertCommitScope(scope, input.role);
791
860
  const files = allChangedFiles(ref.abs);
792
861
  if (input.dryRun) {
@@ -795,6 +864,12 @@ export class Workflow {
795
864
  const stage = stageAll(ref.abs);
796
865
  if (!stage.ok)
797
866
  throw new Error(`git add 失败: ${stage.err}`);
867
+ if (a.staged_hash) {
868
+ const staged = stagedTreeHash(ref.abs);
869
+ if (staged !== a.staged_hash) {
870
+ throw new Error(`暂存区内容已变化(审批时 ${a.staged_hash},现在 ${staged});请重新 commit_request 并批准`);
871
+ }
872
+ }
798
873
  const res = gitCommit(ref.abs, a.message);
799
874
  if (!res.ok)
800
875
  throw new Error(`git commit 失败: ${res.err || res.out}`);
@@ -833,20 +908,40 @@ export class Workflow {
833
908
  }
834
909
  const active = this.cfg.active_repo;
835
910
  if (active && !this.cfg.repos.some((r) => r.id === active)) {
836
- push({ level: 'FAIL', code: 'active-repo', message: `active_repo=${active} 不在 repos 列表` });
911
+ push({
912
+ level: 'FAIL',
913
+ code: 'active-repo',
914
+ message: `active_repo=${active} 不在 repos 列表`,
915
+ });
837
916
  }
838
917
  if (!active) {
839
- push({ level: 'WARN', code: 'active-repo', message: '没有激活的仓库,所有实现工作都会停滞', hint: 'mpt-workflow activate <repo>' });
918
+ push({
919
+ level: 'WARN',
920
+ code: 'active-repo',
921
+ message: '没有激活的仓库,所有实现工作都会停滞',
922
+ hint: 'mpt-workflow activate <repo>',
923
+ });
840
924
  }
841
925
  for (const ref of this.repoRefs()) {
842
926
  if (!exists(ref.abs)) {
843
- push({ level: 'FAIL', code: 'repo-missing', repo: ref.id, message: `仓库目录不存在: ${ref.abs}` });
927
+ push({
928
+ level: 'FAIL',
929
+ code: 'repo-missing',
930
+ repo: ref.id,
931
+ message: `仓库目录不存在: ${ref.abs}`,
932
+ });
844
933
  continue;
845
934
  }
846
935
  const conf = this.repoConfig(ref.id);
847
936
  const gi = gitInfo(ref.abs);
848
937
  if (!gi.available) {
849
- push({ level: 'FAIL', code: 'git', repo: ref.id, message: '不是 git 仓库或无法读取 HEAD', hint: gi.error });
938
+ push({
939
+ level: 'FAIL',
940
+ code: 'git',
941
+ repo: ref.id,
942
+ message: '不是 git 仓库或无法读取 HEAD',
943
+ hint: gi.error,
944
+ });
850
945
  continue;
851
946
  }
852
947
  if (conf.branch && gi.branch && conf.branch !== gi.branch) {
@@ -891,12 +986,17 @@ export class Workflow {
891
986
  if (exists(path.join(ref.abs, 'rust-toolchain.toml'))) {
892
987
  const tc = readText(path.join(ref.abs, 'rust-toolchain.toml'));
893
988
  const ch = /channel\s*=\s*"([^"]+)"/.exec(tc)?.[1];
894
- if (ch && ch.includes('nightly')) {
989
+ if (ch?.includes('nightly')) {
895
990
  push({ level: 'OK', code: 'toolchain', repo: ref.id, message: `rust-toolchain: ${ch}` });
896
991
  }
897
992
  }
898
993
  if (exists(path.join(ref.abs, 'Cargo.toml')) && !exists(path.join(ref.abs, 'Cargo.lock'))) {
899
- push({ level: 'WARN', code: 'cargo-lock-missing', repo: ref.id, message: 'Cargo.toml 存在但没有 Cargo.lock' });
994
+ push({
995
+ level: 'WARN',
996
+ code: 'cargo-lock-missing',
997
+ repo: ref.id,
998
+ message: 'Cargo.toml 存在但没有 Cargo.lock',
999
+ });
900
1000
  }
901
1001
  // questions parse health
902
1002
  const qs = exists(questionsFile(ref.abs))
@@ -913,7 +1013,12 @@ export class Workflow {
913
1013
  }
914
1014
  const st = this.repoState(ref.id);
915
1015
  if (st.milestones.length === 0) {
916
- push({ level: 'WARN', code: 'milestones', repo: ref.id, message: '没有 M(PLAN 表未解析到,也没有 TODO)' });
1016
+ push({
1017
+ level: 'WARN',
1018
+ code: 'milestones',
1019
+ repo: ref.id,
1020
+ message: '没有 M(PLAN 表未解析到,也没有 TODO)',
1021
+ });
917
1022
  }
918
1023
  const acceptedDirty = st.milestones.filter((m) => m.status === 'accepted');
919
1024
  if (acceptedDirty.length && gi.dirty) {
@@ -930,9 +1035,7 @@ export class Workflow {
930
1035
  level: a.approved_at ? 'WARN' : 'OK',
931
1036
  code: 'approval',
932
1037
  repo: a.repo,
933
- message: a.approved_at
934
- ? `审批 ${a.id} 已批准但未使用`
935
- : `审批 ${a.id} 等待用户批准`,
1038
+ message: a.approved_at ? `审批 ${a.id} 已批准但未使用` : `审批 ${a.id} 等待用户批准`,
936
1039
  hint: `mpt-workflow approve ${a.id}`,
937
1040
  });
938
1041
  }
@@ -971,11 +1074,7 @@ export class Workflow {
971
1074
  * questions board change as a normal part of the workflow.
972
1075
  */
973
1076
  export function isMachineManagedFile(file) {
974
- return (/^TODO-M\d+\.md$/.test(file) ||
975
- file === 'docs/agent-questions.md' ||
976
- file === '.mcp.json' ||
977
- file.startsWith('.claude/') ||
978
- file.startsWith('.workflow/'));
1077
+ return /^TODO-M\d+\.md$/.test(file) || file === 'docs/agent-questions.md';
979
1078
  }
980
1079
  /** Machine-managed files plus the plan itself (derived-scope checks only). */
981
1080
  export function isWorkflowManaged(file) {
@@ -1069,13 +1168,6 @@ function runCommand(command, cwd, timeoutMs) {
1069
1168
  });
1070
1169
  });
1071
1170
  }
1072
- function globMatchPath(file, pattern) {
1073
- const p = pattern.replace(/^\.\//, '');
1074
- if (p === file)
1075
- return true;
1076
- const esc = p.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*\*/g, '\u0000').replace(/\*/g, '[^/]*').replace(/\u0000/g, '.*');
1077
- return new RegExp('^' + esc + '$').test(file);
1078
- }
1079
1171
  function appendReview(text, r) {
1080
1172
  const header = '## 验收记录';
1081
1173
  const line = [