---
name: project-step1391-4c-pc-side-stamp-and-5d-integration-2026-08-23
description: STEP 1369 Phase 11 - 4C 時刻機械 PC-side v0.1 (stamp) + 5D 意味機械 --stamp flag 統合 = metadata 3 側面 統合 第 1 実 wire
metadata: 
  node_type: memory
  type: project
  originSessionId: 3acd3853-c124-47b1-974e-9d8c55c72877
  modified: 2026-08-23T02:07:55.423Z
---

# STEP 1391 — 4C PC-side v0.1 + 5D 統合 同時 arc (STEP 1369 Phase 11, 2026-08-23)

## 契機
- STEP 1390 close report で 次候補 (1) 4C timestamp provenance v0.1 (chrony/w32time wrapper + monotonic clock trust、 5D 統合と 同時 arc) 提示
- 藤本さん directive: 「1. 4C timestamp provenance v0.1 (chrony/w32time wrapper + monotonic clock trust、 5D 統合と 同時 arc) でお願い致します」

## 実装 - 4C stamp

### scripts/timestamp-provenance/stamp.py

**StampRecord dataclass (15 field)**:
- System clock: `system_clock_iso` (ISO8601 UTC ms) / `system_clock_unix` (float seconds)
- Monotonic: `monotonic_ns` (process-local monotonic, duration trust only)
- NTP: `ntp_available` / `ntp_source` (chrony/w32time/"") / `ntp_stratum` / `ntp_offset_ms` / `ntp_leap`
- Hardware skeleton (v0.1 常に unavailable): `gps_available` / `gps_source` / `atomic_available` / `atomic_source`
- Meta: `trust_level` (string enum value) / `trust_rank` (1-5 int) / `platform` / `schema_version` "0.1"

**5 Trust levels (increasing rank)**:
| Level | Rank | Source | Notes |
|-------|------|--------|-------|
| SYSTEM_CLOCK | 1 | datetime.now() | always available floor, weak evidence |
| MONOTONIC | 2 | time.monotonic_ns() | duration trust only, no absolute time |
| NTP | 3 | chrony/w32time status | stratum-dependent (stratum 1 = 最強) |
| GPS_PPS | 4 | hardware GPS 1PPS | ⏸ v0.1 skeleton |
| ATOMIC_REFERENCE | 5 | NIST radio (JJY/DCF77) | ⏸ v0.1 skeleton |

**5 CLI subcommand**:
- `stamp [--pretty]`: one-shot all-source provenance JSON
- `ntp-status`: chrony/w32time status parse (exit 0 if available, 1 if not)
- `verify <stamp.json> [--tolerance-ms 100]`: cross-source verify (exit 0 consistent / 2 exceeds / 3 cannot verify)
- `record --interval 5 --duration 60 --out FILE`: datalogger jsonl
- `compact`: short descriptor for embedding (5D annotate consumer)

**verify_cross_source (library)**: NTP offset を proxy として system_clock vs NTP 距離 verify、 tolerance 内なら consistent

### NTP i18n handling (副次 finding)

Windows w32time output is locale-dependent (Shift-JIS cp932 on Japanese Windows):
- English: `Stratum: 5`、 `Phase Offset: -0.0001s`
- Japanese: `階層: 5`、 `位相オフセット: -0.0001s` (Shift-JIS bytes)

Fix implementation:
1. subprocess で bytes 取得、 encoding 順次試行 (utf-8 → cp932 → cp1252 → latin-1)
2. utf-8 で `�` replacement 5+ 個 検出時は 次 encoding 試行
3. 複数 locale label prefix 対応: `("Stratum", "階層", "階層 ")` / `("Phase Offset", "位相オフセット")` / etc.

**Japanese w32time `/status` view 制約 (honest scope)**: 「位相オフセット」 field 含まれず (「ルート遅延」 「ルート分散」 のみ) → offset_ms=-1 sentinel が残る。 stratum は正常 parse 済。 v0.2 で `/verbose` or XML output parse candidate。

### test_stamp.py (48/48 PASS)

- Trust levels 1
- stamp() library 10 (dataclass + iso + unix + monotonic increases + trust floor + gps/atomic unavailable + platform + serializable + ntp consistent)
- NTP status probes 3 (chrony/w32time/detect returns dict)
- verify_cross_source 3 (no NTP -> None / within tolerance -> True / exceeds -> False)
- CLI 8 (stamp json + pretty + ntp-status + verify no NTP exit 3 + verify within exit 0 + verify exceeds exit 2 + record jsonl + compact format)
- Integration hint 1 (compact fits time_source field)

### Live demo verified
```
$ stamp.py stamp --pretty
{
  "system_clock_iso": "2026-08-23T01:58:37.193+00:00",
  "monotonic_ns": 706577857885400,
  "ntp_available": true,
  "ntp_source": "w32time",
  "ntp_stratum": 5,                  # ← Japanese Windows i18n parse 成功
  "ntp_offset_ms": -1.0,             # ← Japanese /status に 含まれず (honest)
  "trust_level": "ntp",
  "trust_rank": 3
}

$ stamp.py compact
2026-08-23T01:58:37.402+00:00|trust:ntp|ntp:w32time/stratum-1/offset-1.00ms|mono:706578066505900
```

## 実装 - 5D 統合 (同時 arc)

### scripts/meaning/meaning.py update

**新 --stamp flag**:
- `_auto_stamp_time_source()` helper = subprocess で stamp.py stamp + compact 呼び出し、 exception 時 graceful degrade (time_source 未変更 + warn stderr)
- `--stamp` flag 追加 = 自動 4C call、 time_source (compact descriptor) + time_provenance (full JSON dict) 両 field populate
- **User の --time-source explicit 尊重**: --time-source X --stamp なら time_source=X (override せず)、 time_provenance のみ attach
- **completeness improvement**: 未 stamp 0.57 → --stamp 0.71 (time_source field populate 分)
- subprocess import 追加

### test_meaning_stamp_integration.py (14/14 PASS)

- without --stamp: time_provenance 不在
- with --stamp: time_provenance populated (dict with system_clock_iso + monotonic_ns + trust_level)
- with --stamp: time_source populated (compact descriptor with "trust:" token)
- user --time-source respected (not overridden by --stamp)
- output mentions "trust=" level info
- completeness > without --stamp

### Regression clean
- STEP 1387 existing 27/27 test 全 PASS 保持 (--stamp flag 追加は 既存 flow 無影響)

### Live end-to-end verified
```
$ meaning.py annotate 5.02 --unit V --interpretation "..." --stamp
annotated: 6652ce4f (5.02 V - ...)
  time_provenance attached (trust=ntp, source=w32time)
  completeness: 0.71 (partial - add calibration/purpose to strengthen)

$ cat annotations.jsonl (抜粋):
{
  "raw_value": 5.02, "unit": "V", "interpretation": "...", "observer": "user",
  "time_source": "2026-08-23T02:02:23.586+00:00|trust:ntp|ntp:w32time/stratum5/offset-1.00ms|mono:706804248656900",
  "time_provenance": {                    ← full 4C stamp record
    "system_clock_iso": "...", "ntp_available": true, "ntp_source": "w32time",
    "ntp_stratum": 5, "trust_level": "ntp", "trust_rank": 3, ...
  },
  "completeness": 0.71
}
```

## Metadata 3 側面 統合 の 第 1 実 wire 達成

STEP 1387 で 提示された 「4A + 4C + 5D 統合 candidate」 の うち **5D + 4C wire 実装完了**:
- **5D 意味** (interpretation metadata、 STEP 1387): live
- **4C 時刻** (time_source metadata、 STEP 1391): live
- **4A 校正** (calibration_source metadata、 STEP 1390 drift-detector で 別実装): 実 5D wire は 別 arc
- **4C ⟷ 5D wire**: 本 STEP で 実装 = 5D annotate `--stamp` → 4C auto-call → time_source + time_provenance 両 populate

**残 wire**:
- 5D `--drift-check <baseline_id>` = 4A drift 判定を 5D record に 埋込 candidate (別 arc)
- 5D `--calibration-record <id>` = 4A (hardware/software) calibration reference の 直接 link candidate
- ProvenanceRecord (STEP 1345 benchtop_provenance.py) schema 拡張 = software + hardware metadata 両対応 (別 arc)

## Verify

- 4C test: 48/48 PASS
- 5D regression: 27/27 PASS (existing)
- 5D + 4C integration: 14/14 PASS
- Total spike test: 48 + 14 = 62 new, 27 regression = 89 assertion

- Site: md5 `2929d179dca0f0348af2a0050114e191`、 890 行 (前 886 +4)
- Commit `51815c508` push (7778bd9b6..51815c508、 previous HEAD 変化 = 別タブ auto push 挟まり)、 7 files/1102+/11-
  - 2 M: public + dist-renderer/tools/step-1369-five-machines-index/index.html
  - 1 M: scripts/meaning/meaning.py (--stamp flag 追加)
  - 4 A: scripts/timestamp-provenance/{README + stamp.py + test_stamp.py} + scripts/meaning/test_meaning_stamp_integration.py
- CF Pages deploy 109,786 bytes、 HTTP 200
- Phase 11 marker (STEP 1391/Phase 11/timestamp-provenance/stamp.py/test 48/48/--stamp/4C PC-side/metadata 3 側面 統合/NTP i18n): 5 hits
- URL: https://rei-aios.pages.dev/tools/step-1369-five-machines-index/

## 命名予告 累計 「10 のうち **9 台 骨格実装 済**」

- ✅ v0.1 spike 済 (9): 5A/5B/5C/5D/6/SVG map + 4B PC-side + 4A PC-side + **4C PC-side (本 STEP)**
- ⏸ 未着手 (1): 4D 作用hw の hardware side (SW side は STEP 1388 で 実装済、 HW blocker のみ)

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

Phase 3-11 = 9 連続 clean commit、 全 pre-staged 0 件 confirm 後 明示 file add、 sweep-in 一切なし
- Phase 3=252+、 4=264+、 5=468+、 6=1391+、 7=1440+、 8=1266+、 9=797+、 10=942+、 11=1102+
- 他タブ push 競合は Phase 4+8+11 で 各 1 度 → rebase 綺麗 integrate、 6 Phase は 競合なし

## Honest scope

1. **Python stdlib only** + subprocess wrapper (chrony/w32time は platform 標準 tool、 additional dependency なし)
2. **NTP i18n Japanese Windows /status view 制約**: 「位相オフセット」 field 含まれず → offset=-1 sentinel、 stratum のみ parse (v0.2 で /verbose or XML parse candidate)
3. **hardware sources (GPS_PPS / ATOMIC_REFERENCE)** は v0.1 skeleton (常に unavailable)、 hardware 導入時 実装
4. **monotonic trust**: 「duration trust」 のみ = process restart で reset、 absolute time は 保証しない
5. **cross-source verify** は NTP offset proxy、 GPS 独立照合 (真の cross-source) は hardware 到着時
6. **subprocess timeout 5 sec** = chrony/w32time hang 時 stamp 呼び出しが 5秒待つ、 CI で 注意 (v0.2 async 化 candidate)
7. **5D --stamp のgraceful degrade**: 4C script が 見つからない or exception 時、 time_source 未変更 + warn stderr、 annotation 自体は 進行 (regression 予防)
8. **5D --time-source user explicit 尊重**: --stamp override せず (user judgment 優先)、 time_provenance のみ attach
9. **PC-side は 「物理世界 evidence」 と別物** = hardware GPS が 独立系統で 取る絶対時刻 とは 質的に 異なる、 chat-Claude 「メモから 証拠に」 の 完全実現は hardware でしか (STEP 1389/1390 の PC-side discipline 継承)
10. **schema_version "0.1"** = 将来 field 追加 (GPS PPS + atomic reference 実装時) で breaking change 予告

## Deferred (継続)

1. **hardware side 4C** (GPS PPS ~¥1,500 or NIST radio) = 藤本さん judgment 待ち
2. **4D 拡張** (npm/pip/docker/db/cloud API hook 追加、 STEP 1388 pattern 継承) = 残 arc
3. **統計 4 primitive covariates-aware 化** (STEP 1389 4B covariates + STEP 1350/1371/1376/1379 integration) = 継続 defer
4. **4A drift baseline + 5D wire** (5D `--drift-check <baseline_id>` flag、 4C ↔ 5D wire と 同 pattern) = 残 metadata 統合 arc
5. **ProvenanceRecord.env_covariates + time_provenance schema 拡張** (STEP 1345 benchtop_provenance.py 側): software + hardware 両対応
6. **NTP /verbose or XML parse** (v0.2 for offset_ms 取得改善): Japanese Windows offset 対応
7. **hardware 4D** = 藤本さん judgment 依然待ち
8. **STEP 1388 実運用 pilot** (git pre-push installed + gh alias + rm alias + scpi 実 benchtop 統合) = 別 arc

## 関連

- [[project-step1390-4A-pc-side-drift-v01-2026-08-23]] Phase 10 直前 (4A PC-side pattern 継承)
- [[project-step1389-4B-pc-side-v01-2026-08-23]] Phase 9 (4B PC-side "PC-side = hardware 代替でない" discipline origin)
- [[project-step1387-ledger-machines-5B-5C-5D-v01-2026-08-23]] Phase 7 (5D meaning core、 本 STEP で --stamp 追加)
- [[project-step1345-benchtop-provenance-spike-2026-08-19]] ProvenanceRecord schema 拡張 candidate
- [[project-step1383-four-physical-auxiliary-machines-2026-08-23]] 4C hardware side origin (未取得)
- rei-open-problems DOI: 「時刻証拠の 制度的 anchor」 = 制度機械 6 との 交点 (chat-Claude 引用)
- [[feedback-super-naming-siren-family-pattern]] 「PC-side = hardware 代替 と 誤読させない」 継承
- [[feedback-projection-self-audit-pattern]] SAC-4 47 教訓 Phase 3-11 9 連続 clean 成功
- [[feedback-no-rush-publication]] 「命名 → v0.1 spike → 実 pipeline 統合」 継続、 metadata 3 側面 統合 第 1 実 wire (5D+4C)
