---
name: project-step1389-4b-pc-side-v01-2026-08-23
description: STEP 1369 Phase 9 - 4B 環境機械 PC-side v0.1 spike (system-covariates) = hardware 未取得下 の 迂回路、統計 4 primitive 共変量供給 subset
metadata: 
  node_type: memory
  type: project
  originSessionId: 3acd3853-c124-47b1-974e-9d8c55c72877
  modified: 2026-08-23T00:24:06.461Z
---

# STEP 1389 — 4B PC-side v0.1 spike (STEP 1369 Phase 9, 2026-08-23)

## 契機
- STEP 1388 close report 後、 藤本さん質問 「hardware 購入 難しいか、 PC-app で 可能な こと」 = 実 hardware 導入せず 何が可能か 探索
- 私 (Claude Code) 応答: 4 機械の PC-side analog 整理 → 4 選択肢提示:
  - (a) 4B PC-side (system resource covariates) v0.1 spike ← 推奨
  - (b) 4D 拡張 (npm/pip/docker/db hook 追加)
  - (c) 4A software drift v0.1 spike
  - (d) 4C timestamp provenance v0.1 spike
  - (e) 上記 順次実行
- 藤本さん directive: 「(a) 4B PC-side (system resource covariates) v0.1 spike ← 推奨 でお願い致します」

## 実装 — scripts/system-covariates/

### system_covariates.py

**CovariatesSample dataclass (15 field)**:
- Time: `ts` (ISO8601 UTC ms), `wall_perf_counter` (monotonic), `process_cpu_time_sec` (cumulative)
- Platform: `platform` (sys.platform), `psutil_available` (bool), `schema_version` "0.1"
- CPU: `cpu_count` (os.cpu_count)、 `load_avg_1min/5min/15min` (Unix only、 Windows -> -1)、 `cpu_percent` (psutil required)
- Memory: `mem_total_mb / available_mb / percent` (psutil required)、 `process_rss_mb` (psutil OR resource.getrusage Unix)
- Disk: `tracked_path` (arg)、 `disk_total_gb / free_gb / used_percent` (shutil.disk_usage cross-platform)

**Watch context manager**:
- `interval` (seconds、 default 0.5) + `tracked_path`
- Background thread が interval ごとに sample を append
- `__enter__`: 開始 sample + thread start
- `__exit__`: thread stop + 終了 sample
- `summary()`: min/max/mean/n の CPU/mem/load_avg/rss + duration + rss_delta
- interval<=0 は ValueError raise

**CLI 4 subcommand**:
- `sample [--path .] [--pretty]`: 1-shot JSON
- `record --interval N --duration N --out PATH`: datalogger loop -> jsonl
- `summarize FILE`: recorded jsonl -> stats
- `attach --value N --unit U --interpretation "..." --duration N [--path .]`: 測定+covariates 複合 record

### test_system_covariates.py (44/44 PASS on Windows psutil available)

- **sample library**: dataclass 型 / ts ISO / cpu_count > 0 / disk populated / tracked_path stored / process_cpu_time >= 0 / perf_counter monotonic / platform recorded / psutil flag matches / load_avg sentinel or >= 0 / psutil-dependent fields conditional
- **Watch**: captures >= 3 samples in 0.5s / duration >= 0.4s / summary has 7 fields / invalid interval raises / survives thread
- **CLI**: sample json parseable / --pretty has newlines / record writes jsonl / summarize parses / attach compound record with source marker
- **Integration**: covariates + value pairing shape / serializable

### -1.0 SENTINEL discipline

**「取得不能」 marker** (`_SENTINEL = -1.0`)、 「測定が 0 だった」 と 誤読しないため `psutil_available` + `platform` field で verify 必須。 例: Windows で `load_avg_1min = -1.0` は 「Windows は getloadavg なし」 の 明示 (実際の 負荷が 0 ではない)。

### Stdlib-first + psutil optional

- **stdlib のみで動く subset**: disk_usage + cpu_count + wall_perf_counter + process_cpu_time = 全 OS 対応 minimal
- **psutil 追加で活性化**: cpu_percent + mem_percent + process_rss (Windows でも) cross-platform
- **Unix stdlib subset**: 上記 + load_avg + resource.getrusage RSS = ほぼ full 環境
- **Windows stdlib subset (psutil なし)**: disk + cpu_count + process_cpu_time のみ = 最小構成でも 有意義 (disk drift + process CPU time monitor 可)

## Verify

- Live sample (Windows, psutil available):
  ```
  cpu_count=8, mem_total=65.4GB, mem_used=40%, disk_used=58.1% (930GB total, 389GB free),
  process_rss=20.9MB, load_avg=-1.0 (Windows sentinel correct), cpu_percent=0.0
  ```
- Test: **44/44 PASS** on Windows + psutil available
- Site: md5 `5d092230425c1d146a0ca0d77ad5bf5f`、 882 行 (前 878 +4)
- Commit `1e7263c89` push (90f498ced..1e7263c89)、 5 files/797+/10-
- CF Pages deploy 105,523 bytes、 HTTP 200
- Phase 9 marker (STEP 1389/Phase 9/PC-side v0.1 spike/system-covariates/test 44/44): 4 hits

## 4 機械 PC-side analog 整理 (前段の 探索応答)

| 機械 | Hardware side (未取得) | PC-side analog |
|------|-----------|---------|
| **4A 校正** | 電圧標準/精密抵抗 | software drift detection (golden dataset + regression alert) |
| **4B 環境** | BME280/INA226 | ★ **本 STEP 実装** = system_covariates |
| **4C 時刻** | GPS PPS | timestamp provenance layer (chrony wrapper + monotonic clock trust) |
| **4D 作用hw** | Kikusui/Zaber | **既に STEP 1388 で 実装済** (git/gh/rm/SCPI hook) |

4B 選定理由: (i) 統計 4 primitive と 直接補完、 (ii) ¥0 stdlib only、 (iii) 「同じ 型 discipline を software domain で」 が 統計機械 実 pipeline 統合の stepping stone

## Honest scope

1. **PC-side は 「物理世界の evidence」 とは 別物** = hardware 4B (BME280+INA226) が 独立系統で 取る 温湿度電源 とは 質的に 異なる。 chat-Claude 「4B 環境機械」 の 「別系統」 概念は software では 「同じ OS 内で 別 process が sampling」 程度の 独立性 = **物理世界 evidence の 代替 ではない**、 「同じ 型 discipline の software analog」
2. **統計機械 との 実 pipeline 統合 未装備** = STEP 1350/1371/1376/1379 に covariates 引数 field なし、 v0.1 は 供給側 のみ、 pair は 手動
3. **psutil optional** = stdlib のみでも disk + cpu_count + process CPU time は 取れる、 但し 実用的な CPU %/mem % monitor は psutil 前提
4. **Windows で process_rss** は psutil 必須 (resource.getrusage Unix のみ)、 psutil なし Windows では `-1.0` sentinel
5. **Watch は background thread 1 個** = 高頻度 interval (<50ms) では 精度低下 / scheduler 依存、 v0.1 spike は 100ms+ 想定
6. **Network I/O は scope 外** (psutil.net_io_counters は 追加可能だが v0.1 除外)
7. **hardware 4B との mapping** = ProvenanceRecord.env_covariates field (STEP 1345 拡張 candidate) に software covariate + hardware covariate 両対応 schema が 望ましい (別 arc)
8. **schema_version "0.1"** = 将来 field 追加 (network I/O、 GPU 使用率、 GPU memory 等) 時 breaking change 予告
9. **「PC-side = hardware 代替 と 誤読させない」 discipline** を site page 8 台帳 update に embed = siren-family 回避 変種
10. **Live verify は Windows + psutil 環境のみ**、 Linux stdlib fallback + Windows psutil なし 環境の 実 動作は unit test conditional で verify (実運用 pilot 未実施)

## 「命名 → v0.1 spike → 実 pipeline 統合」 3 段の 現状

- 命名 済: 10 (七機械 忘却 + 物理附属 4 + 帳簿 4 + 橋 1)
- v0.1 spike 済: 7 (5A/5B/5C/5D/6/SVG map + **4B PC-side** = 本 STEP)
- 実 pipeline 統合 stage 進行中: 1 (5A STEP 1388 pathway hook 4 種)
- 未 spike (hardware blocker): 3 (4A/4C/4D hardware side、 4B の hardware は 未取得だが PC-side で 迂回)

## SAC-4 47 教訓 Phase 3-9 7 連続 clean 成功

- Phase 3+4+5+6+7+8+9 = 7 連続 clean commit
- 全 pre-staged 0 件 confirm 後 明示 file path のみ add
- 他タブ push 競合は Phase 4 + Phase 8 で 各 1 度発生 → `git pull --rebase` 綺麗 integrate、 5 Phase は 競合なし
- oukc/* sweep-in 一切なし

## Deferred (継続)

1. **hardware side 4B (BME280+INA226+RPi Pico ~¥3,600 spike)** = 藤本さん judgment 待ち、 実 物理世界 evidence のため 別 track
2. **統計機械 との 実 pipeline 統合** (STEP 1350/1371/1376/1379 に `--covariates-a` / `--covariates-b` field 追加、 SNR/FDR/Welch t/Cohen's d が covariates aware に)
3. **4A software drift v0.1** = LLM 応答 consistency baseline + benchmark regression alert (別 STEP candidate)
4. **4C timestamp provenance v0.1** = chrony/w32time status wrapper + monotonic clock trust flag (5D 統合と 同時 arc)
5. **4D 拡張** = npm install / pip install / apt / docker rm / db migration / cloud API hook (STEP 1388 pattern 継承、 8-10 hook に 拡張)
6. **network I/O + GPU 使用率** system_covariates.py への 追加 (schema v0.2)
7. **ProvenanceRecord.env_covariates schema 拡張** (STEP 1345 側): software + hardware 両対応
8. **その他 STEP 1388 で 継承した deferred** (TOCTOU / post-action verify / bypass audit review / 5B retroactive 記録 等)

## 関連

- [[project-step1388-5A-pathway-hook-integration-2026-08-23]] Phase 8 直前 (4D 導入禁止 解除 SW gate 達成)
- [[project-step1387-ledger-machines-5B-5C-5D-v01-2026-08-23]] Phase 7 帳簿 4 全 v0.1
- [[project-step1386-five-arc-sequential-execution-2026-08-23]] Phase 6 5A oughtctl core
- [[project-step1383-four-physical-auxiliary-machines-2026-08-23]] 4B hardware side origin (未取得)
- [[project-step1345-benchtop-provenance-spike-2026-08-19]] ProvenanceRecord schema 拡張 candidate (env_covariates 統合先)
- [[project-step1376-welch-t-primitive-2026-08-23]] Welch t = 覆う 統計 4 primitive の 1 例、 covariates aware 統合 target
- [[feedback-super-naming-siren-family-pattern]] 「PC-side = hardware 代替 と 誤読させない」 discipline 変種
- [[feedback-projection-self-audit-pattern]] SAC-4 47 教訓 Phase 3-9 7 連続 clean 成功
- [[feedback-no-rush-publication]] 「命名 → v0.1 spike → 実 pipeline 統合」 順序、 hardware 未取得下の 迂回路として PC-side 起動
