agentic-flow-kit 1.1.0 → 1.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-flow-kit",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "AI-Native 闭环工作流 + wiki 知识层脚手架——flow-kit init 一条命令为新项目装好 .agents 工作流引擎(阶段命令/角色契约/门禁钩子/kb 检索/看板/规则面预算)+ workflow 文档闭环 + wiki 知识库,装完自包含、零运行时依赖",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -117,7 +117,8 @@ import { laneOfEntry } from './stage-gates.mjs';
117
117
  import { MARK_RE, approvedTraceHit } from './stage-gates.mjs';
118
118
 
119
119
  const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
120
- const GIT = process.platform === 'win32' ? 'git.exe' : 'git';
120
+ // CHECK_LOOP_GIT:测试注入钩子(指向不存在/不可执行路径可稳定触发 spawn 异常);未设置时与原行为逐字节一致(2026-10-05-gitout-fail-open)
121
+ const GIT = process.env.CHECK_LOOP_GIT || (process.platform === 'win32' ? 'git.exe' : 'git');
121
122
 
122
123
  function takeOpts() {
123
124
  const args = process.argv.slice(2);
@@ -210,19 +211,52 @@ const inSet = (v, arr) => arr.includes(v);
210
211
  const stOkDoc = (st) => inSet(st, ENUMS['doc.status.confirmed']);
211
212
 
212
213
  // git 调用(参数数组形式不走 shell——Windows cmd 不认单引号;git.exe 显式解析沿 doctor 先例)
214
+ // 基础设施异常与业务失败分流(2026-10-05-gitout-fail-open):spawn 异常响亮出账(进程级去重恰一条,
215
+ // 沿检查 16 装户「载入失败响亮出账」先例)+ 瞬时类错误码单次重试;「非 git 仓」(status≠0)仍是
216
+ // 合法装户语义、静默走降级。intentional-simple: 重试后仍异常继续走原降级/拦截语义(连续瞬时异常
217
+ // 残余面小且有账可查);升级路径 = 探测门(:720/:796)改三态拆分
218
+ let gitInfraWarned = false;
219
+ function warnGitInfra(args, code) {
220
+ if (gitInfraWarned) return;
221
+ gitInfraWarned = true;
222
+ console.error(`check-loop: git 探测异常 ${args[0]}(${code})——按非 git 仓降级,检查面可能收窄`);
223
+ }
224
+ const GIT_TRANSIENT = new Set(['EAGAIN', 'EPERM', 'EMFILE', 'EINTR']);
225
+ function spawnGit(args) {
226
+ const opts = { cwd: ROOT, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 };
227
+ let r = spawnSync(GIT, args, opts);
228
+ if (r.error) {
229
+ // 出账在重试终败后(与 linesOf 对称——瞬时重试恢复成功不打扰);非瞬时类直接出账
230
+ if (GIT_TRANSIENT.has(r.error.code)) r = spawnSync(GIT, args, opts);
231
+ if (r.error) warnGitInfra(args, r.error.code || r.error.message);
232
+ }
233
+ return r;
234
+ }
213
235
  function gitOut(args, { ok = () => true } = {}) {
214
- const r = spawnSync(GIT, args,
215
- { cwd: ROOT, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });
236
+ const r = spawnGit(args);
216
237
  if (r.error || r.status !== 0 || !ok(r)) return null;
217
238
  return r.stdout || '';
218
239
  }
219
240
 
220
241
  // ---- frontmatter 受限子集读取(fm_get 语义:首行 --- 进入、下一 --- 闭合、键在行首、首个命中、值两侧去空白)----
242
+ // fs 读取同走 fail-loud(2026-10-05-gitout-fail-open 实现期诊断追加,与 spawnGit 同一故障类):
243
+ // readFileSync 瞬时异常(宿主资源压力 EMFILE/共享冲突类)重试一次,仍失败响亮出账(进程级去重)
244
+ // 后按 null 降级——调用方按空文档跳过该件,但异常本身不再静默
245
+ let fsReadWarned = false;
221
246
  const fileLinesCache = new Map();
222
247
  function linesOf(file) {
223
248
  if (!fileLinesCache.has(file)) {
224
- try { fileLinesCache.set(file, fs.readFileSync(file, 'utf8').split(/\r?\n/)); }
225
- catch { fileLinesCache.set(file, null); }
249
+ let lines = null;
250
+ try {
251
+ lines = fs.readFileSync(file, 'utf8').split(/\r?\n/);
252
+ } catch (e) {
253
+ try { lines = fs.readFileSync(file, 'utf8').split(/\r?\n/); } catch { lines = null; }
254
+ if (!lines && !fsReadWarned) {
255
+ fsReadWarned = true;
256
+ console.error(`check-loop: 文档读取异常 ${path.basename(file)}(${e.code || e.message})——按空文档降级,检查面可能收窄`);
257
+ }
258
+ }
259
+ fileLinesCache.set(file, lines);
226
260
  }
227
261
  return fileLinesCache.get(file);
228
262
  }
@@ -578,7 +612,9 @@ function verifyEvidenceTruth(evidenceStr, planBase, root) {
578
612
  if (!shaMatch || /^\d+$/.test(shaMatch[1])) return { ok: true, type: 'text' };
579
613
 
580
614
  const sha = shaMatch[1];
581
- const revParse = spawnSync(GIT, ['rev-parse', sha], { cwd: ROOT, encoding: 'utf8' });
615
+ // 直连走 spawnGit(与 gitOut 同一 loud+retry 通道,注释互引):spawn 异常不再被静默算作业务失败;
616
+ // 重试后仍异常按下方 status!==0 判定(fail-closed 保持——本地核验不了就按伪造拦)
617
+ const revParse = spawnGit(['rev-parse', sha]);
582
618
  if (revParse.status !== 0) {
583
619
  // 区分本地伪造与外部仓库引用:
584
620
  // 剔除 SHA 与泛指词后仍有其他内容(如项目名、路径描述)→ 视为外部仓库引用,不硬拦(本地无法核验他仓哈希);
@@ -607,7 +643,7 @@ function verifyEvidenceTruth(evidenceStr, planBase, root) {
607
643
  }
608
644
  }
609
645
 
610
- const show = spawnSync(GIT, ['show', '--name-only', sha], { cwd: ROOT, encoding: 'utf8' });
646
+ const show = spawnGit(['show', '--name-only', sha]);
611
647
  if (show.status !== 0) return { ok: false, type: 'error', msg: `无法读取提交 ${sha} 的文件列表` };
612
648
 
613
649
  const changedFiles = show.stdout.split(/\r?\n/).filter(Boolean);
@@ -617,7 +653,7 @@ function verifyEvidenceTruth(evidenceStr, planBase, root) {
617
653
  // 过程证据(2026-10-03 check-evidence-process):执行器驱动的提交可作验收证据——提交信息带
618
654
  // 「pipeline-run <runId>」标记(docsCommit 四种格式共有段,runId 严格形态 日期8-时间4-主题-尾;
619
655
  // 与 run 事件流同源,git 历史留痕可对质)。只救 irrelevant:forged(SHA 不存在)在前已判,其余判据不动。
620
- const subj = spawnSync(GIT, ['log', '-1', '--format=%s', sha], { cwd: ROOT, encoding: 'utf8' });
656
+ const subj = spawnGit(['log', '-1', '--format=%s', sha]);
621
657
  if (subj.status === 0 && /pipeline-run [0-9]{8}-[0-9]{4}-[A-Za-z0-9-]+/.test(subj.stdout)) {
622
658
  return { ok: true, type: 'process' };
623
659
  }
@@ -68,9 +68,12 @@ ${refs ? ' - 是 → ../intents/2026-09-12-ghost.md\n' : ' - 否 → 理由:
68
68
  `;
69
69
 
70
70
  // run:默认 CHECK_LOOP_ROOT 注入(fixture 模式);{git:true} 时 cwd 注入(真 git 模式,测 tracked 过滤);
71
- // opts.args 追加 CLI 参数(--hardening 等加固门场景用,2026-09-30 hybrid-governance-explore-hardening)
71
+ // opts.args 追加 CLI 参数(--hardening 等加固门场景用,2026-09-30 hybrid-governance-explore-hardening);
72
+ // opts.env 增量覆盖子进程 env(CHECK_LOOP_GIT 替身注入用,2026-10-05-gitout-fail-open)
72
73
  const run = (root, opts = {}) => spawnSync(process.execPath, [CHECK_LOOP, ...(opts.args || [])], {
73
- ...(opts.git ? { cwd: root } : { cwd: ROOT_CWD, env: { ...process.env, CHECK_LOOP_ROOT: root } }),
74
+ ...(opts.git
75
+ ? { cwd: root, ...(opts.env ? { env: { ...process.env, ...opts.env } } : {}) }
76
+ : { cwd: ROOT_CWD, env: { ...process.env, ...(opts.env || {}), CHECK_LOOP_ROOT: root } }),
74
77
  encoding: 'utf8',
75
78
  });
76
79
  const ROOT_CWD = process.cwd();
@@ -83,13 +86,32 @@ const expectOk = (desc, root) => {
83
86
  const r = run(root);
84
87
  check(desc, r.status === 0, `exit=${r.status}\n${outOf(r)}`);
85
88
  };
89
+ // 夹具 git 调用防瞬时失败(2026-10-05-gitout-fail-open 夹具侧加固):宿主/CI 资源压力下 spawnSync 可能
90
+ // 瞬时 `r.error`,git 侧也可能瞬时 status≠0(如 index.lock 争用)——对夹具 setup 调用(init/add/commit/
91
+ // rev-parse)两者都永不合法:重试一次,持续失败抛错响亮失败。绝不静默产出空 sha / 缺提交的假夹具
92
+ // (那会让证据场景拿到「无裁决」的错误结果——CI run 37252874044 flake 的实际根因侧,诊断详见同名 incident)
93
+ function gitRetry(args, root) {
94
+ const opts = { cwd: root, encoding: 'utf8' };
95
+ let r = spawnSync(GIT, args, opts);
96
+ if (r.error || r.status !== 0) {
97
+ r = spawnSync(GIT, args, opts);
98
+ if (r.error || r.status !== 0) {
99
+ throw new Error(`fixture git 瞬时失败(重试后仍 ${r.error ? (r.error.code || r.error.message) : `exit ${r.status}`}): git ${args.join(' ')}\n${(r.stderr || '').slice(0, 300)}`);
100
+ }
101
+ }
102
+ return r;
103
+ }
104
+ const shortSha = (root, args = ['rev-parse', '--short', 'HEAD']) => {
105
+ const out = gitRetry(args, root).stdout.trim();
106
+ if (!out) throw new Error(`fixture git 空输出(假夹具防线): git ${args.join(' ')}`);
107
+ return out;
108
+ };
86
109
  const gitInit = (root) => {
87
- spawnSync(process.platform === 'win32' ? 'git.exe' : 'git', ['init', '-q'], { cwd: root });
110
+ gitRetry(['init', '-q'], root);
88
111
  };
89
112
  const gitCommitAll = (root, msg) => {
90
- const G = process.platform === 'win32' ? 'git.exe' : 'git';
91
- spawnSync(G, ['add', '-A'], { cwd: root });
92
- spawnSync(G, ['-c', 'user.email=t@t', '-c', 'user.name=t', 'commit', '-qm', msg], { cwd: root });
113
+ gitRetry(['add', '-A'], root);
114
+ gitRetry(['-c', 'user.email=t@t', '-c', 'user.name=t', 'commit', '-qm', msg], root);
93
115
  };
94
116
  const rmfix = (root) => fs.rmSync(root, { recursive: true, force: true });
95
117
  // writeLedger:fixture 台账辅助(检查 15 配对用;行 schema 同 confirm-doc.mjs appendLedger)
@@ -435,12 +457,12 @@ const mkConfirmedDoc = (root, rel, fmBody) => {
435
457
  fs.copyFileSync(path.join(SCRIPT_DIR, '..', 'rule-budgets.txt'), path.join(T, '.agents', 'rule-budgets.txt'));
436
458
  gitInit(T);
437
459
  w(T, 'AGENTS.md', 'x'.repeat(8000));
438
- spawnSync(process.platform === 'win32' ? 'git.exe' : 'git', ['add', 'AGENTS.md'], { cwd: T });
460
+ gitRetry(['add', 'AGENTS.md'], T);
439
461
  let r = spawnSync('sh', ['.agents/scripts/rule-budget.sh', '--staged'], { cwd: T, encoding: 'utf8' });
440
462
  check('rule-budget --staged:暂存超限 → exit 1(硬拦路径)',
441
463
  r.status === 1 && `${r.stdout}${r.stderr}`.includes('常驻面超限:AGENTS.md'), `${r.stdout}${r.stderr}`);
442
464
  w(T, 'AGENTS.md', '# 小体积\n');
443
- spawnSync(process.platform === 'win32' ? 'git.exe' : 'git', ['add', 'AGENTS.md'], { cwd: T });
465
+ gitRetry(['add', 'AGENTS.md'], T);
444
466
  r = spawnSync('sh', ['.agents/scripts/rule-budget.sh', '--staged'], { cwd: T, encoding: 'utf8' });
445
467
  check('rule-budget --staged:合规 → exit 0(不误拦)', r.status === 0, `${r.stdout}${r.stderr}`);
446
468
  rmfix(T);
@@ -582,7 +604,7 @@ const evidenceFixture = (slug, declared, createDeclared) => {
582
604
  w(T, `workflow/intents/2026-10-04-${slug}.md`, INTENT(slug, '状态: done\n级别: L1\n日期: 2026-10-04',
583
605
  '\n## 验收标准(可测试)\n- [x] 用例通过(证据:commit PLACEHOLDER)\n'));
584
606
  gitCommitAll(T, `feat: ${slug} fixture`);
585
- const sha = spawnSync(GIT, ['rev-parse', 'HEAD'], { cwd: T, encoding: 'utf8' }).stdout.trim().slice(0, 7);
607
+ const sha = shortSha(T, ['rev-parse', 'HEAD']).slice(0, 7);
586
608
  w(T, `workflow/intents/2026-10-04-${slug}.md`, INTENT(slug, '状态: done\n级别: L1\n日期: 2026-10-04',
587
609
  `\n## 验收标准(可测试)\n- [x] 用例通过(证据:commit ${sha})\n`));
588
610
  gitCommitAll(T, `docs: ${slug} evidence`);
@@ -620,7 +642,7 @@ const evidenceFixture = (slug, declared, createDeclared) => {
620
642
  fs.mkdirSync(path.join(T, 'src'), { recursive: true });
621
643
  w(T, 'src/app.mjs', '// fixture\n');
622
644
  gitCommitAll(T, 'feat: sh1 实现(无执行器标记)');
623
- const sha = spawnSync(GIT, ['rev-parse', '--short', 'HEAD'], { cwd: T, encoding: 'utf8' }).stdout.trim();
645
+ const sha = shortSha(T);
624
646
  w(T, 'workflow/intents/2026-09-26-sh1.md', INTENT('sh1', '状态: done\n级别: L1\n日期: 2026-09-26', `\n## 验收标准(可测试)\n- [x] 用例通过(证据:${sha})\n`));
625
647
  expectOk('证据 SHA 触及声明文件(无执行器标记)→ type=sha 校验通过 exit 0', T);
626
648
  rmfix(T);
@@ -672,8 +694,7 @@ const evidenceFixture = (slug, declared, createDeclared) => {
672
694
  fs.mkdirSync(path.join(T, 'notes'), { recursive: true });
673
695
  w(T, 'notes/other.md', 'x\n');
674
696
  gitCommitAll(T, 'docs(x): 演练穿越(pipeline-run 20260926-0900-pe1-abc1)');
675
- const G = process.platform === 'win32' ? 'git.exe' : 'git';
676
- const sha = spawnSync(G, ['rev-parse', '--short', 'HEAD'], { cwd: T, encoding: 'utf8' }).stdout.trim();
697
+ const sha = shortSha(T);
677
698
  w(T, 'workflow/intents/2026-09-26-pe1.md', INTENT('pe1', '状态: done\n级别: L1\n日期: 2026-09-26', `\n## 验收标准(可测试)\n- [x] 演练穿越(证据:${sha})\n`));
678
699
  expectOk('过程证据:提交信息带执行器标记(改动面外)→ 放行 exit 0', T);
679
700
  rmfix(T);
@@ -685,8 +706,7 @@ const evidenceFixture = (slug, declared, createDeclared) => {
685
706
  fs.mkdirSync(path.join(T, 'notes'), { recursive: true });
686
707
  w(T, 'notes/other.md', 'x\n');
687
708
  gitCommitAll(T, 'docs(x): 演练穿越(L0,无标记提交)');
688
- const G = process.platform === 'win32' ? 'git.exe' : 'git';
689
- const sha = spawnSync(G, ['rev-parse', '--short', 'HEAD'], { cwd: T, encoding: 'utf8' }).stdout.trim();
709
+ const sha = shortSha(T);
690
710
  w(T, 'workflow/intents/2026-09-26-pe2.md', INTENT('pe2', '状态: done\n级别: L1\n日期: 2026-09-26', `\n## 验收标准(可测试)\n- [x] 演练穿越(证据:${sha})\n`));
691
711
  expectHard('过程证据:无标记无关提交 → 仍拦 证据无关', T, '证据无关');
692
712
  rmfix(T);
@@ -699,6 +719,41 @@ const evidenceFixture = (slug, declared, createDeclared) => {
699
719
  expectHard('过程证据:SHA 不存在 → forged 仍拦(防伪线不放松)', T, '证据伪造');
700
720
  rmfix(T);
701
721
  }
722
+ // ---- 场景 5v:git 基础设施异常 fail-loud(2026-10-05-gitout-fail-open)----
723
+ // CHECK_LOOP_GIT 指向不存在路径 → spawnSync 跨平台稳定 r.error(ENOENT)→ 响亮出账恰一条(进程去重)
724
+ // + 证据核验降级(exit 语义不变、无业务裁决误报);正常 git 零出账(防误报负例)
725
+ // 注(L2 复核 P2-2):出账断言不构成 :581 接入 spawnGit 的独立钉死——探测门与 :581 共用去重 flag,
726
+ // 变异(:581 改回裸 spawnSync)三断言仍绿;:581 接线由代码走读 + CI 覆盖,瞬时重试路径静态替身不可测
727
+ {
728
+ const T = mkfix();
729
+ gitInit(T);
730
+ w(T, 'workflow/plans/2026-09-26-pe4.md', PLAN('pe4', '状态: done\n级别: L1\n模块: material', '\n## 改动方案\n\n- src/app.mjs:实现功能\n'));
731
+ fs.mkdirSync(path.join(T, 'notes'), { recursive: true });
732
+ w(T, 'notes/other.md', 'x\n');
733
+ gitCommitAll(T, 'docs(x): 演练穿越(L0,无标记提交)');
734
+ const sha = shortSha(T);
735
+ w(T, 'workflow/intents/2026-09-26-pe4.md', INTENT('pe4', '状态: done\n级别: L1\n日期: 2026-09-26', `\n## 验收标准(可测试)\n- [x] 演练穿越(证据:${sha})\n`));
736
+ const r = run(T, { env: { CHECK_LOOP_GIT: 'definitely-not-git-xyz-2026' } });
737
+ const hits = outOf(r).split('git 探测异常').length - 1;
738
+ check('git 基础设施异常:响亮出账恰一条(进程去重)', hits === 1, `hits=${hits}\n${outOf(r)}`);
739
+ check('git 基础设施异常:持续异常仍 fail-closed(伪造拦不放松,防静默降级)', r.status === 1 && outOf(r).includes('证据伪造'), `exit=${r.status}\n${outOf(r)}`);
740
+ check('git 基础设施异常:基础设施异常不冒充业务裁决(无证据无关误报)', !outOf(r).includes('证据无关'), outOf(r));
741
+ rmfix(T);
742
+ }
743
+ {
744
+ const T = mkfix();
745
+ gitInit(T);
746
+ w(T, 'workflow/plans/2026-09-26-pe5.md', PLAN('pe5', '状态: done\n级别: L1\n模块: material', '\n## 改动方案\n\n- src/app.mjs:实现功能\n'));
747
+ fs.mkdirSync(path.join(T, 'notes'), { recursive: true });
748
+ w(T, 'notes/other.md', 'x\n');
749
+ gitCommitAll(T, 'docs(x): 演练穿越(L0,无标记提交)');
750
+ const sha = shortSha(T);
751
+ w(T, 'workflow/intents/2026-09-26-pe5.md', INTENT('pe5', '状态: done\n级别: L1\n日期: 2026-09-26', `\n## 验收标准(可测试)\n- [x] 演练穿越(证据:${sha})\n`));
752
+ const r = run(T);
753
+ check('git 基础设施异常:正常 git 零出账(防误报负例)', !outOf(r).includes('git 探测异常'), outOf(r));
754
+ check('git 基础设施异常:正常 git 行为不变(无标记无关提交仍拦证据无关)', r.status === 1 && outOf(r).includes('证据无关'), `exit=${r.status}\n${outOf(r)}`);
755
+ rmfix(T);
756
+ }
702
757
  // ---- 场景 45:检查 2——真未填占位(标题 <主题>,无 .md)→ 仍报模板未填 ----
703
758
  {
704
759
  const T = mkfix();