leerness 1.9.382 → 1.9.384

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/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.9.384 — 2026-06-06 — 5번째 외부평가: status/verify --json 구조화 출력 일관성 (UR-0085)
4
+
5
+ **🔌 `status --json` / `verify --json` 이 사람용 텍스트 → 구조화 JSON — AI 에이전트 자동화용 출력 일관성 확보.**
6
+
7
+ ### 배경 (5번째 외부평가, GPT-5.5 web, 1.9.382 · "참고하되 맹신 X")
8
+ 외부 평가가 #1 AI-에이전트 리스크로 지목: audit/health/task list 는 `--json` 시 JSON 인데 `status --json` 은 "Leerness: 1.9.x / Files: 56/56", `verify --json` 은 "✓ verify passed" 처럼 **사람용 텍스트**를 그대로 냄. 자체 재현으로 확인 후 수정.
9
+
10
+ ### 구현
11
+ 1. **status --json**: `{ version, language, minimal, total, present, missing[], healthy }` 구조화 출력(없으면 기존 사람용 유지).
12
+ 2. **verify --json**: 실패를 `failures[]` 로 먼저 수집 → `{ ok, failures[], healthy }` 출력. **exit code 1 보존**(JSON·사람용 양쪽 모두 실패 시 exit 1).
13
+ 3. 사람용 출력/동작 무변경(--json 없을 때 기존 `✗ ...` 메시지 + exit code 그대로).
14
+
15
+ ### 검증 (회귀 0)
16
+ - **selftest 129→130 PASS** (status --json behavioral 파싱(total/present/healthy/missing) + verify --json 와이어 확인).
17
+ - **E2E 328→329 PASS** (status --json 구조 + verify --json pass(exit0)/fail(exit1) + 사람용 verify fail(exit1, JSON 아님) 보존).
18
+ - 실측: pass `{ok:true,failures:0}` exit0 / AGENTS.md 삭제 `{ok:false,failures:3}` exit1 / 사람용 `✗ ...` exit1.
19
+
20
+ ### 5번째 외부평가 후속 (UR-0086 contract spec markdown-bullet 파서, UR-0087 secret .env.bad 정책)은 검증 후 별도 라운드.
21
+
22
+ ## 1.9.383 — 2026-06-06 — UR-0025 큰 핸들러 모듈화 토대②: lib/io.js fs 프리미티브 분리
23
+
24
+ **🧩 lib/io.js 에 파일 I/O 프리미티브 추가 — 핸들러를 별도 lib 모듈로 분리할 토대 완비(io 14종).**
25
+
26
+ ### 구현
27
+ 1. **lib/io.js fs 프리미티브 추가**: `read`(BOM strip) / `readBuf` / `writeUtf8`(원자 temp→rename) / `exists` / `mkdirp` / `append` / `rel` / `absRoot`. io 모듈 14종(출력6+fs8) 완성.
28
+ 2. **harness 인라인 정의 제거** → import 확장. **호출부 무변경**(이름 동일, 수천 호출 그대로).
29
+ 3. e2e B(1.9.298) writeUtf8 원자성 소스체크 경로 `bin/harness.js` → `lib/io.js`(renameSync 이동 대응).
30
+
31
+ ### 검증 (회귀 0)
32
+ - **selftest 128→129 PASS** (io fs exports 8종 + reference equality(read/writeUtf8/exists) + 인라인 제거 + writeUtf8→read round-trip + rel).
33
+ - **E2E 327→328 PASS** (직접 round-trip + decision add(writeUtf8)→context(read) consumer 보존).
34
+ - 실측: io 14종, init/decision→context round-trip, migrate plan(read 다수) 정상.
35
+
36
+ ### 큰 핸들러 모듈화 토대 완비 → 이제 핸들러(migrate/team/audit)를 lib 모듈로 ctx-경량 분리 가능(io import 만으로 출력/파일 프리미티브 확보).
37
+
3
38
  ## 1.9.382 — 2026-06-06 — UR-0025 큰 핸들러 모듈화 토대: lib/io.js 출력·시간 프리미티브 분리
4
39
 
5
40
  **🧩 (사용자 명시 허용) 큰 핸들러 분리의 선결 토대 — 공유 출력/시간 프리미티브 모듈 신설.**
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  > **AI 코딩 에이전트의 거짓 완료·중복·망각·충돌을 막아주는 검수·기억·협업 CLI 하네스.**
4
4
  > **A CLI harness that stops AI coding agents from faking completion, duplicating work, forgetting context, and colliding.**
5
5
 
6
- [![npm](https://img.shields.io/badge/npm-leerness-blue)](https://www.npmjs.com/package/leerness) [![version](https://img.shields.io/badge/version-1.9.382-green)]() [![tests](https://img.shields.io/badge/e2e-327%2F327-success)]() [![selftest](https://img.shields.io/badge/selftest-128-success)]() [![mcp](https://img.shields.io/badge/MCP--tools-85-brightgreen)]() [![providers](https://img.shields.io/badge/AI_providers-10-brightgreen)]() [![license](https://img.shields.io/badge/license-MIT-lightgrey)]()
6
+ [![npm](https://img.shields.io/badge/npm-leerness-blue)](https://www.npmjs.com/package/leerness) [![version](https://img.shields.io/badge/version-1.9.384-green)]() [![tests](https://img.shields.io/badge/e2e-329%2F329-success)]() [![selftest](https://img.shields.io/badge/selftest-130-success)]() [![mcp](https://img.shields.io/badge/MCP--tools-85-brightgreen)]() [![providers](https://img.shields.io/badge/AI_providers-10-brightgreen)]() [![license](https://img.shields.io/badge/license-MIT-lightgrey)]()
7
7
 
8
8
  ```
9
9
  ╔══════════════════════════════════════════════════════════════╗
@@ -471,7 +471,7 @@ MIT — © leerness contributors
471
471
  <!-- leerness:project-readme:start -->
472
472
  ## Leerness Project Harness
473
473
 
474
- 이 프로젝트는 Leerness v1.9.382 하네스를 사용합니다. AI 에이전트는 작업 전 `leerness handoff`로 컨텍스트를 적재하고, 작업 후 `leerness check`/`leerness audit`/`leerness session close`를 수행해야 합니다.
474
+ 이 프로젝트는 Leerness v1.9.384 하네스를 사용합니다. AI 에이전트는 작업 전 `leerness handoff`로 컨텍스트를 적재하고, 작업 후 `leerness check`/`leerness audit`/`leerness session close`를 수행해야 합니다.
475
475
 
476
476
  ### 정체성 — AI 에이전트 운영 레이어 (UR-0030)
477
477
 
@@ -525,7 +525,7 @@ leerness memory restore decision <date|title>
525
525
 
526
526
  ### MCP server (외부 AI 통합)
527
527
 
528
- Leerness v1.9.382는 stdio JSON-RPC MCP server를 내장합니다 — Claude Code · Cursor · Codex CLI 등 외부 AI에 **85개 도구**를 노출:
528
+ Leerness v1.9.384는 stdio JSON-RPC MCP server를 내장합니다 — Claude Code · Cursor · Codex CLI 등 외부 AI에 **85개 도구**를 노출:
529
529
 
530
530
  ```jsonc
531
531
  // 카테고리별
@@ -546,7 +546,7 @@ Leerness v1.9.382는 stdio JSON-RPC MCP server를 내장합니다 — Claude Cod
546
546
  `<<autonomous-loop-dynamic>>` 신호만 보내면 AI가:
547
547
  1) 다음 라운드 후보 선정 → 2) 코드 변경 → 3) stress-v* 신규 작성 + 누적 회귀 → 4) e2e 219/219 → 5) npm pack + git tag + GitHub release → 6) main 자동 push (1.9.140+) → 7) session close → 8) 다음 라운드 예약.
548
548
 
549
- 현재 누적: **70 라운드 (1.9.40 → 1.9.382)** · 매 라운드 GitHub release/태그 생성 · _reports/는 비공개 보존.
549
+ 현재 누적: **70 라운드 (1.9.40 → 1.9.384)** · 매 라운드 GitHub release/태그 생성 · _reports/는 비공개 보존.
550
550
 
551
551
  ### 성능 가이드 (1.9.140 측정)
552
552
 
@@ -584,6 +584,6 @@ leerness release pack --close --auto-main-push
584
584
  - `.harness/session-handoff.md`: 다음 세션 인수인계 (자동 작성)
585
585
  - `.harness/lessons.md` / `decisions.md` / `rules.md`: 영구 메모리 (5 surface)
586
586
 
587
- Last synced by Leerness v1.9.382: 2026-06-06
587
+ Last synced by Leerness v1.9.384: 2026-06-06
588
588
  <!-- leerness:project-readme:end -->
589
589
 
package/bin/harness.js CHANGED
@@ -4,7 +4,7 @@
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
  const cp = require('child_process');
7
- const { log, ok, warn, fail, today, now } = require('../lib/io'); // 1.9.382 (UR-0025): 출력/시간 프리미티브 공유 모듈
7
+ const { log, ok, warn, fail, today, now, absRoot, exists, read, readBuf, mkdirp, writeUtf8, append, rel } = require('../lib/io'); // 1.9.382/383 (UR-0025): 출력/시간/파일 프리미티브 공유 모듈
8
8
  const os = require('os'); // 1.9.178: _publishToNpm 에서 os.tmpdir() 사용 (전역 import)
9
9
  const readline = require('readline');
10
10
  // 1.9.274 (UR-0025 1단계): 순수 유틸 함수 모듈 분리 (require-based, 비파괴). selftest 7종이 동작 검증.
@@ -29,7 +29,7 @@ const { _evidenceQuality, _parseEvidenceStats, _shellGuardAnalyze, _claimFileInG
29
29
  // 1.9.295 (UR-0025 4단계): 정적 데이터 카탈로그 모듈 분리 (비파괴, require-based).
30
30
  const { CAPABILITY_SURFACE, POWERFUL_COMMANDS, ADAPTERS, REUSE_CATEGORIES, REUSE_CHECKLIST, _DEFAULT_PLATFORM_CONSTRAINTS, _DEFAULT_DOMAIN_CATALOG, _LSP_LANG_PATTERNS, OPTIMISM_PATTERNS, BUILT_IN_PERSONAS, STRINGS, BUILTIN_CATALOG, ROADMAP_STATUS_LABEL, ROADMAP_STATUS_COLOR, SECRET_PATTERNS, MERGE_OVERWRITE_FILES, MINIMAL_SKIP_KEYS, REQUIRED_WORKSPACE_FILES, KEYWORD_STOPWORDS, SKILL_CATALOG_PRESETS } = require('../lib/catalogs'); // 1.9.344/368/369 (UR-0025): catalog 분리 (MERGE_OVERWRITE_FILES/MINIMAL_SKIP_KEYS 포함)
31
31
 
32
- const VERSION = '1.9.382';
32
+ const VERSION = '1.9.384';
33
33
 
34
34
  // 1.9.290 (UR-0037, Codex gpt-5.5 #4 수렴): CLI 전용 부작용은 require 시 실행하지 않는다.
35
35
  // 이전: warning listener 제거 / NODE_OPTIONS 변경 / chcp IIFE 가 top-level 즉시 실행 → require('harness') 시 호스트 프로세스 오염.
@@ -156,32 +156,6 @@ const STATUSES = ['requested','planned','in-progress','waiting','on-hold','block
156
156
  function _mcpToolCount() {
157
157
  try { return require('../lib/mcp-tools').length; } catch { return 0; }
158
158
  }
159
- function absRoot(p) { return path.resolve(p || process.cwd()); }
160
- function exists(p) { return fs.existsSync(p); }
161
- function read(p) {
162
- // 1.9.147: UTF-8 BOM 자동 strip — Windows PowerShell Out-File 등이 BOM 붙이는 경우 JSON.parse 실패 방지
163
- const text = fs.readFileSync(p, 'utf8');
164
- return text.charCodeAt(0) === 0xFEFF ? text.slice(1) : text;
165
- }
166
- function readBuf(p) { return fs.readFileSync(p); }
167
- function mkdirp(p) { fs.mkdirSync(p, { recursive: true }); }
168
- // 1.9.298 (UR-0038, 외부리뷰 3중수렴): 원자적 쓰기 — temp 파일에 기록 후 rename(원자 교체)으로 부분쓰기 손상 방지.
169
- // crash/타임아웃 kill/동시쓰기 중에도 대상 파일에 깨진 부분파일이 남지 않음 ('메모리 항상 보존' 코드 보증).
170
- // rename 은 동일 디렉토리(=동일 FS) 라 POSIX/NTFS 모두 원자적(Node renameSync = MOVEFILE_REPLACE_EXISTING).
171
- // temp 이름은 확장자 끝이 아니라 .tmp-PID-SEQ 라 *.md glob 에 안 걸림. 실패 시 temp 정리.
172
- let _writeSeq = 0;
173
- function writeUtf8(p, s) {
174
- mkdirp(path.dirname(p));
175
- const tmp = `${p}.tmp-${process.pid}-${++_writeSeq}`;
176
- try {
177
- fs.writeFileSync(tmp, s, { encoding: 'utf8' });
178
- fs.renameSync(tmp, p);
179
- } catch (e) {
180
- try { if (fs.existsSync(tmp)) fs.unlinkSync(tmp); } catch {}
181
- throw e;
182
- }
183
- }
184
- function append(p, s) { mkdirp(path.dirname(p)); fs.appendFileSync(p, s, 'utf8'); }
185
159
  // 1.9.303 (UR-0043, 외부리뷰): 동기 sleep (Atomics.wait, 실패 시 busy-wait 폴백).
186
160
  function _sleepSyncMs(ms) {
187
161
  try { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Math.max(1, ms | 0)); }
@@ -211,7 +185,6 @@ function _withLock(targetPath, fn, opts = {}) {
211
185
  try { return fn(); }
212
186
  finally { if (held) { _heldLocks.delete(lockPath); try { fs.unlinkSync(lockPath); } catch {} } }
213
187
  }
214
- function rel(root, p) { return path.relative(root, p).replace(/\\/g, '/') || '.'; }
215
188
  // 1.9.327 (UR-0025): _getLocalTz / _formatLocal → lib/pure-utils.js 로 이동 (순수 TZ/날짜 포맷, require 사용).
216
189
  // 자동 모드 활성 여부 (R-XXXX every-round 룰 존재 시 true)
217
190
  function _isAutoLoopActive(root) {
@@ -3012,6 +2985,8 @@ function _selfTestCases() {
3012
2985
  { name: 'UR-0025: REQUIRED_WORKSPACE_FILES 단일출처 — verify/migrate audit·apply 3중 중복 제거 (1.9.380)', run: () => { const c = require('../lib/catalogs'); if (REQUIRED_WORKSPACE_FILES !== c.REQUIRED_WORKSPACE_FILES) return false; const listOk = Array.isArray(c.REQUIRED_WORKSPACE_FILES) && c.REQUIRED_WORKSPACE_FILES.length === 9 && c.REQUIRED_WORKSPACE_FILES.includes('AGENTS.md') && c.REQUIRED_WORKSPACE_FILES.includes('.harness/plan.md'); const usesConst = (read(__filename).match(/const required = REQUIRED_WORKSPACE_FILES;/g) || []).length >= 3; return listOk && usesConst; } },
3013
2986
  { name: 'UR-0025: KEYWORD_STOPWORDS 단일출처 — handoff/lessons 키워드 stopwords 2중 중복 제거 (1.9.381)', run: () => { const c = require('../lib/catalogs'); if (KEYWORD_STOPWORDS !== c.KEYWORD_STOPWORDS) return false; const setOk = c.KEYWORD_STOPWORDS instanceof Set && c.KEYWORD_STOPWORDS.has('작업') && c.KEYWORD_STOPWORDS.has('task') && !c.KEYWORD_STOPWORDS.has('고유단어') && c.KEYWORD_STOPWORDS.size >= 25; const usesConst = (read(__filename).match(/const stopwords = KEYWORD_STOPWORDS;/g) || []).length >= 2 && !/const stopwords = new Set\(\[/.test(read(__filename)); return setOk && usesConst; } },
3014
2987
  { name: 'UR-0025 큰핸들러토대: lib/io.js 프리미티브(log/ok/warn/fail/today/now) 모듈 분리 + 동작 (1.9.382)', run: () => { const io = require('../lib/io'); const exportsOk = ['log', 'ok', 'warn', 'fail', 'today', 'now'].every(k => typeof io[k] === 'function') && io.log === log && io.fail === fail && io.now === now; const todayOk = /^\d{4}-\d{2}-\d{2}$/.test(io.today()) && /^\d{4}-\d{2}-\d{2}T/.test(io.now()); const src = read(__filename); const moved = src.includes("require('../lib/io')") && !/^function fail\(s\) \{ log/m.test(src) && !/^function now\(\) \{ return new Date/m.test(src); let exitOk = false; const saved = process.exitCode; const _w = process.stdout.write; try { process.stdout.write = () => true; process.exitCode = 0; io.fail('probe'); exitOk = process.exitCode === 1; } finally { process.stdout.write = _w; process.exitCode = saved; } return exportsOk && todayOk && moved && exitOk; } },
2988
+ { name: 'UR-0025 큰핸들러토대: lib/io.js fs 프리미티브(read/writeUtf8/exists/mkdirp/append/rel/absRoot) 분리 + round-trip (1.9.383)', run: () => { const io = require('../lib/io'); const exp = ['absRoot', 'exists', 'read', 'readBuf', 'mkdirp', 'writeUtf8', 'append', 'rel'].every(k => typeof io[k] === 'function') && io.read === read && io.writeUtf8 === writeUtf8 && io.exists === exists; const src = read(__filename); const moved = !/^function writeUtf8\(p, s\) \{/m.test(src) && !/^function read\(p\) \{/m.test(src) && !/^function exists\(p\) \{/m.test(src); const tmp = fs.mkdtempSync(path.join(os.tmpdir(), '__leerness_io_')); let rt = false; try { const f = path.join(tmp, 'a', 'b.txt'); io.writeUtf8(f, '한글RT'); rt = io.exists(f) && io.read(f) === '한글RT' && io.rel(tmp, f) === 'a/b.txt'; } finally { try { fs.rmSync(tmp, { recursive: true, force: true }); } catch {} } return exp && moved && rt; } },
2989
+ { name: '5th외부평가/UR-0085: status --json 구조화 출력 + verify --json 와이어 (1.9.384)', run: () => { if (typeof status !== 'function' || typeof verify !== 'function') return false; const tmp = fs.mkdtempSync(path.join(os.tmpdir(), '__leerness_sj_')); const save = process.argv; const _w = process.stdout.write; let so = ''; try { fs.mkdirSync(path.join(tmp, '.harness'), { recursive: true }); process.argv = ['node', 'h', 'status', tmp, '--json']; process.stdout.write = s => { so += s; return true; }; status(tmp); } catch {} finally { process.stdout.write = _w; process.argv = save; try { fs.rmSync(tmp, { recursive: true, force: true }); } catch {} } let sj; try { sj = JSON.parse(so); } catch {} const statusOk = !!sj && typeof sj.total === 'number' && typeof sj.present === 'number' && 'healthy' in sj && Array.isArray(sj.missing); const src = read(__filename); const verifyWired = /function verify\(root\) \{[\s\S]*?has\('--json'\)[\s\S]*?JSON\.stringify\(\{ ok:/.test(src); return statusOk && verifyWired; } },
3015
2990
  { name: 'VERSION 형식 (x.y.z)', run: () => /^\d+\.\d+\.\d+$/.test(VERSION) }
3016
2991
  ];
3017
2992
  }
@@ -6771,6 +6746,8 @@ function status(root) {
6771
6746
  try { const mf = path.join(root, '.harness/manifest.json'); if (exists(mf)) isMinimal = !!JSON.parse(read(mf)).minimal; } catch {}
6772
6747
  const files = Object.keys(coreFiles(root, lang, [], { minimal: isMinimal }));
6773
6748
  const missing = files.filter(f => !exists(path.join(root,f)));
6749
+ // 1.9.384 (5번째 외부평가/UR-0085): --json 일관성 — AI 에이전트용 구조화 출력.
6750
+ if (has('--json')) { log(JSON.stringify({ version: ver, language: lang, minimal: isMinimal, total: files.length, present: files.length - missing.length, missing, healthy: missing.length === 0 }, null, 2)); return; }
6774
6751
  log(`Leerness: ${ver}${isMinimal ? ' (minimal)' : ''}`);
6775
6752
  log(`Files: ${files.length - missing.length}/${files.length}`);
6776
6753
  if (missing.length) missing.forEach(x => warn('missing: ' + x));
@@ -6778,15 +6755,17 @@ function status(root) {
6778
6755
  }
6779
6756
  function verify(root) {
6780
6757
  root = absRoot(root);
6781
- let bad = 0;
6758
+ // 1.9.384 (5번째 외부평가/UR-0085): 실패를 먼저 수집 → --json 구조화 출력 + 사람용 분기 (exit code 일관 유지).
6759
+ const failures = [];
6782
6760
  const required = REQUIRED_WORKSPACE_FILES; // 1.9.380 (UR-0025): lib/catalogs 단일출처
6783
- for (const f of required) { if (!exists(path.join(root,f))) { bad++; fail(`missing: ${f}`); } }
6761
+ for (const f of required) { if (!exists(path.join(root,f))) failures.push(`missing: ${f}`); }
6784
6762
  const g = exists(path.join(root,'.harness/guideline.md')) ? read(path.join(root,'.harness/guideline.md')) : '';
6785
- if (!g.includes('plan.md') || !g.includes('progress-tracker.md')) { bad++; fail('guideline.md must reference plan.md and progress-tracker.md'); }
6763
+ if (!g.includes('plan.md') || !g.includes('progress-tracker.md')) failures.push('guideline.md must reference plan.md and progress-tracker.md');
6786
6764
  const a = exists(path.join(root,'AGENTS.md')) ? read(path.join(root,'AGENTS.md')) : '';
6787
- if (!a.includes('protected-files.md')) { bad++; fail('AGENTS.md must reference protected-files.md'); }
6788
- if (!a.includes('anti-lazy-work-policy.md')) { bad++; fail('AGENTS.md must reference anti-lazy-work-policy.md'); }
6789
- if (bad) process.exitCode = 1; else ok('verify passed');
6765
+ if (!a.includes('protected-files.md')) failures.push('AGENTS.md must reference protected-files.md');
6766
+ if (!a.includes('anti-lazy-work-policy.md')) failures.push('AGENTS.md must reference anti-lazy-work-policy.md');
6767
+ if (has('--json')) { log(JSON.stringify({ ok: failures.length === 0, failures, healthy: failures.length === 0 }, null, 2)); if (failures.length) process.exitCode = 1; return; }
6768
+ if (failures.length) { failures.forEach(f => fail(f)); process.exitCode = 1; } else ok('verify passed');
6790
6769
  }
6791
6770
  // 1.9.356 (UR-0075 Phase B): migrate audit — 비파괴 dry-run 스키마 drift 리포트(버전/ canonical JSON 백필/누락 파일). 실제 변경 X.
6792
6771
  function migrateAuditCmd(root, opts = {}) {
package/lib/io.js CHANGED
@@ -1,16 +1,43 @@
1
- // lib/io.js — 콘솔 출력 + 타임스탬프 기반 프리미티브 (단일출처).
2
- // 1.9.382 (UR-0025, 큰 핸들러 모듈화 토대): bin/harness.js 인라인 log/ok/warn/fail/today/now 분리.
3
- // 목적: 향후 핸들러를 별도 lib 모듈로 분리할 때 공유 가능한 출력 프리미티브 제공(harness 만 갖던 것 → 공용화).
4
- // 부작용: log/ok/warn stdout, fail stdout + process.exitCode=1. today/now 순수(시간 의존).
1
+ // lib/io.js — 콘솔 출력 + 타임스탬프 + 파일 I/O 기반 프리미티브 (단일출처).
2
+ // 1.9.382 (UR-0025, 큰 핸들러 모듈화 토대): log/ok/warn/fail/today/now 분리.
3
+ // 1.9.383 (UR-0025): fs 프리미티브(read/readBuf/writeUtf8/exists/mkdirp/append/rel/absRoot) 추가.
4
+ // 목적: 향후 핸들러를 별도 lib 모듈로 분리할 공유 가능한 I/O 프리미티브 제공(harness 만 갖던 것 → 공용화).
5
5
  'use strict';
6
+ const fs = require('fs');
7
+ const path = require('path');
6
8
 
7
9
  function log(s = '') { console.log(s); }
8
10
  function ok(s) { log('✓ ' + s); }
9
11
  function warn(s) { log('⚠ ' + s); }
10
12
  // fail() 은 오류 신호 → exit code 1 설정 (CI/MCP/에이전트가 실패를 성공으로 오판 방지, UR-0045).
11
- // process.exit 즉시종료가 아니라 exitCode 설정(후속 출력/정리 보존, main 종료 wrapper 가 강제).
12
13
  function fail(s) { log('✗ ' + s); process.exitCode = 1; }
13
14
  function today() { return new Date().toISOString().slice(0, 10); }
14
15
  function now() { return new Date().toISOString(); }
15
16
 
16
- module.exports = { log, ok, warn, fail, today, now };
17
+ function absRoot(p) { return path.resolve(p || process.cwd()); }
18
+ function exists(p) { return fs.existsSync(p); }
19
+ function read(p) {
20
+ // 1.9.147: UTF-8 BOM 자동 strip — Windows PowerShell Out-File 등이 BOM 붙이는 경우 JSON.parse 실패 방지
21
+ const text = fs.readFileSync(p, 'utf8');
22
+ return text.charCodeAt(0) === 0xFEFF ? text.slice(1) : text;
23
+ }
24
+ function readBuf(p) { return fs.readFileSync(p); }
25
+ function mkdirp(p) { fs.mkdirSync(p, { recursive: true }); }
26
+ // 1.9.298 (UR-0038, 외부리뷰 3중수렴): 원자적 쓰기 — temp 파일에 기록 후 rename(원자 교체)으로 부분쓰기 손상 방지.
27
+ // temp 이름은 .tmp-PID-SEQ 라 *.md glob 에 안 걸림. 실패 시 temp 정리.
28
+ let _writeSeq = 0;
29
+ function writeUtf8(p, s) {
30
+ mkdirp(path.dirname(p));
31
+ const tmp = `${p}.tmp-${process.pid}-${++_writeSeq}`;
32
+ try {
33
+ fs.writeFileSync(tmp, s, { encoding: 'utf8' });
34
+ fs.renameSync(tmp, p);
35
+ } catch (e) {
36
+ try { if (fs.existsSync(tmp)) fs.unlinkSync(tmp); } catch {}
37
+ throw e;
38
+ }
39
+ }
40
+ function append(p, s) { mkdirp(path.dirname(p)); fs.appendFileSync(p, s, 'utf8'); }
41
+ function rel(root, p) { return path.relative(root, p).replace(/\\/g, '/') || '.'; }
42
+
43
+ module.exports = { log, ok, warn, fail, today, now, absRoot, exists, read, readBuf, mkdirp, writeUtf8, append, rel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leerness",
3
- "version": "1.9.382",
3
+ "version": "1.9.384",
4
4
  "description": "Leerness: 비파괴 마이그레이션, 자동 버전 감지·업데이트, 계획/진행/핸드오프 자동화, 게으름·시크릿·인코딩 자동 가드, Claude Code 슬래시 통합을 갖춘 한국어 우선 AI 개발 하네스.",
5
5
  "keywords": [
6
6
  "leerness",
package/scripts/e2e.js CHANGED
@@ -3286,7 +3286,7 @@ total++;
3286
3286
  const walk = (d) => fs.readdirSync(d, { withFileTypes: true }).flatMap(e => e.isDirectory() ? walk(path.join(d, e.name)) : [path.join(d, e.name)]);
3287
3287
  const tmpLeftover = walk(path.join(aDir, '.harness')).filter(f => /\.tmp-\d+-\d+$/.test(f));
3288
3288
  // (3) 소스에 renameSync 원자 패턴 존재
3289
- const srcOk = /fs\.renameSync\(tmp, p\)/.test(fs.readFileSync(path.resolve(__dirname, '..', 'bin', 'harness.js'), 'utf8'));
3289
+ const srcOk = /fs\.renameSync\(tmp, p\)/.test(fs.readFileSync(path.resolve(__dirname, '..', 'lib', 'io.js'), 'utf8')); // 1.9.383: writeUtf8 → lib/io.js
3290
3290
  ok = tasksOk && tmpLeftover.length === 0 && srcOk;
3291
3291
  fs.rmSync(aDir, { recursive: true, force: true });
3292
3292
  } catch {}
@@ -5316,5 +5316,55 @@ total++;
5316
5316
  if (!ok) failed++;
5317
5317
  }
5318
5318
 
5319
+ // 1.9.383 회귀 (UR-0025 큰핸들러토대): lib/io.js fs 프리미티브 분리 — round-trip + decision write→context read consumer 유지
5320
+ total++;
5321
+ {
5322
+ let ok = false;
5323
+ try {
5324
+ const io = require(path.resolve(__dirname, '..', 'lib', 'io'));
5325
+ const expOk = ['absRoot', 'exists', 'read', 'readBuf', 'mkdirp', 'writeUtf8', 'append', 'rel'].every(k => typeof io[k] === 'function');
5326
+ const t = fs.mkdtempSync(path.join(os.tmpdir(), 'leerness-iofs-'));
5327
+ const f = path.join(t, 'sub', 'x.txt');
5328
+ io.writeUtf8(f, '한글IO');
5329
+ const rtOk = io.exists(f) && io.read(f) === '한글IO' && io.rel(t, f) === 'sub/x.txt';
5330
+ fs.rmSync(t, { recursive: true, force: true });
5331
+ const d = fs.mkdtempSync(path.join(os.tmpdir(), 'leerness-iocons-'));
5332
+ cp.spawnSync(process.execPath, [CLI, 'init', d, '--yes', '--language', 'ko'], { encoding: 'utf8', timeout: 30000 });
5333
+ cp.spawnSync(process.execPath, [CLI, 'decision', 'add', 'IO_RT_881', '--path', d], { encoding: 'utf8', timeout: 15000 });
5334
+ const ctx = cp.spawnSync(process.execPath, [CLI, 'context', '--path', d, '--json'], { encoding: 'utf8', timeout: 15000 });
5335
+ const consumerOk = (ctx.stdout || '').includes('IO_RT_881');
5336
+ fs.rmSync(d, { recursive: true, force: true });
5337
+ ok = expOk && rtOk && consumerOk;
5338
+ } catch {}
5339
+ console.log(ok ? '✓ B(1.9.383) UR-0025 큰핸들러토대: lib/io.js fs 프리미티브 분리 (round-trip + decision→context consumer)' : '✗ lib/io fs 프리미티브 실패');
5340
+ if (!ok) failed++;
5341
+ }
5342
+
5343
+ // 1.9.384 회귀 (5번째 외부평가/UR-0085): status/verify --json 구조화 출력 일관성 — pass JSON + fail JSON(exit1) + 사람용 exit1 유지
5344
+ total++;
5345
+ {
5346
+ let ok = false;
5347
+ try {
5348
+ const d = fs.mkdtempSync(path.join(os.tmpdir(), 'leerness-svjson-'));
5349
+ cp.spawnSync(process.execPath, [CLI, 'init', d, '--yes', '--language', 'ko'], { encoding: 'utf8', timeout: 30000 });
5350
+ const sr = cp.spawnSync(process.execPath, [CLI, 'status', d, '--json'], { encoding: 'utf8', timeout: 15000 });
5351
+ const sj = JSON.parse(sr.stdout);
5352
+ const statusOk = typeof sj.total === 'number' && sj.present === sj.total && sj.healthy === true && Array.isArray(sj.missing) && sj.missing.length === 0;
5353
+ const vr = cp.spawnSync(process.execPath, [CLI, 'verify', d, '--json'], { encoding: 'utf8', timeout: 15000 });
5354
+ const vj = JSON.parse(vr.stdout);
5355
+ const verifyPassOk = vj.ok === true && Array.isArray(vj.failures) && vj.failures.length === 0 && vr.status === 0;
5356
+ fs.rmSync(path.join(d, 'AGENTS.md'), { force: true });
5357
+ const vr2 = cp.spawnSync(process.execPath, [CLI, 'verify', d, '--json'], { encoding: 'utf8', timeout: 15000 });
5358
+ const vj2 = JSON.parse(vr2.stdout);
5359
+ const verifyFailOk = vj2.ok === false && vj2.failures.length >= 1 && vr2.status === 1; // --json 실패도 exit1
5360
+ const vr3 = cp.spawnSync(process.execPath, [CLI, 'verify', d], { encoding: 'utf8', timeout: 15000 }); // 사람용 분기 보존
5361
+ const humanFailOk = vr3.status === 1 && /✗/.test((vr3.stdout || '') + (vr3.stderr || '')) && !/^\s*\{/.test(vr3.stdout || '');
5362
+ fs.rmSync(d, { recursive: true, force: true });
5363
+ ok = statusOk && verifyPassOk && verifyFailOk && humanFailOk;
5364
+ } catch {}
5365
+ console.log(ok ? '✓ B(1.9.384) 5th외부평가: status/verify --json 구조화 일관성 (pass/fail JSON+exit1, 사람용 보존, UR-0085)' : '✗ status/verify --json 일관성 실패');
5366
+ if (!ok) failed++;
5367
+ }
5368
+
5319
5369
  console.log(`\nE2E result: ${total - failed}/${total} passed · ${((Date.now() - _e2eStart) / 1000).toFixed(0)}s`);
5320
5370
  if (failed > 0) process.exit(1);