phasegate 0.222.0 → 0.254.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.
Files changed (108) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/README.ja.md +28 -1
  3. package/README.md +27 -0
  4. package/docs/ADR/001-l1-biome-editor-time-enforcement.md +2 -0
  5. package/docs/ADR/015-architecture-preset.md +2 -0
  6. package/docs/ADR/031-world-model-ownership-and-corpus-lifecycle.md +155 -0
  7. package/docs/ADR/032-world-node-identity.md +198 -0
  8. package/docs/ADR/033-world-snapshot-canonicalization.md +246 -0
  9. package/docs/ADR/034-world-constraint-semantics.md +218 -0
  10. package/docs/ADR/035-world-adoption-baseline-and-waiver.md +341 -0
  11. package/docs/ADR/036-world-model-and-doc-freshness.md +169 -0
  12. package/docs/ADR/037-world-cli-and-output-contract.md +398 -0
  13. package/docs/contracts/requirement-test-matrix.schema.json +15 -0
  14. package/docs/contracts/world-baseline.schema.json +35 -0
  15. package/docs/contracts/world-constraints.schema.json +56 -0
  16. package/docs/contracts/world-debts.schema.json +32 -0
  17. package/docs/contracts/world-obligation-report.schema.json +259 -0
  18. package/docs/contracts/world-waivers.schema.json +32 -0
  19. package/docs/guide/cli-reference.md +34 -0
  20. package/package.json +1 -1
  21. package/scripts/harness/attestation/application/ports/sha256-capability.ts +25 -0
  22. package/scripts/harness/attestation/composition-root.ts +14 -4
  23. package/scripts/harness/attestation/index.ts +6 -1
  24. package/scripts/harness/attestation/infrastructure/adapters/node-crypto-content-hasher-adapter.ts +6 -6
  25. package/scripts/harness/attestation/infrastructure/adapters/node-crypto-sha256-capability.ts +19 -0
  26. package/scripts/harness/harness-api/domain/value-objects/known-harness-commands.ts +4 -1
  27. package/scripts/harness/main.ts +107 -1
  28. package/scripts/harness/nyquist-validation/application/dto/generate-matrix-output.ts +11 -0
  29. package/scripts/harness/nyquist-validation/application/usecases/check-ac-coverage-gate-usecase.ts +6 -0
  30. package/scripts/harness/nyquist-validation/application/usecases/generate-requirement-test-matrix-usecase.ts +8 -4
  31. package/scripts/harness/nyquist-validation/domain/entities/story-mapping.ts +29 -2
  32. package/scripts/harness/nyquist-validation/domain/services/ac-coverage-gate-policy.ts +28 -0
  33. package/scripts/harness/nyquist-validation/infrastructure/adapters/markdown-requirement-source-adapter.ts +71 -4
  34. package/scripts/harness/nyquist-validation/infrastructure/schema/matrix-schema-loader.ts +4 -0
  35. package/scripts/harness/traceability-model/application/dto/traceability-world-read-dto.ts +67 -0
  36. package/scripts/harness/traceability-model/application/facades/traceability-world-read-facade.ts +372 -0
  37. package/scripts/harness/traceability-model/application/ports/traceability-world-read-source-port.ts +61 -0
  38. package/scripts/harness/traceability-model/composition-root.ts +21 -5
  39. package/scripts/harness/traceability-model/index.ts +17 -6
  40. package/scripts/harness/traceability-model/infrastructure/adapters/file-system-traceability-world-read-adapter.ts +223 -0
  41. package/scripts/harness/traceability-model/infrastructure/parsers/story-catalog-parser.ts +86 -8
  42. package/scripts/harness/world-model/application/dto/world-inspection-dto.ts +43 -0
  43. package/scripts/harness/world-model/application/dto/world-obligation-report-dto.ts +54 -0
  44. package/scripts/harness/world-model/application/dto/world-resolved-config-input.ts +62 -0
  45. package/scripts/harness/world-model/application/ports/obligation-report-writer-port.ts +7 -0
  46. package/scripts/harness/world-model/application/ports/world-control-declaration-repository-port.ts +57 -0
  47. package/scripts/harness/world-model/application/ports/world-fact-source-port.ts +17 -0
  48. package/scripts/harness/world-model/application/usecases/build-snapshot-use-case.ts +111 -0
  49. package/scripts/harness/world-model/application/usecases/derive-obligations-use-case.ts +155 -0
  50. package/scripts/harness/world-model/application/usecases/derive-world-obligations-use-case.ts +144 -0
  51. package/scripts/harness/world-model/application/usecases/inspect-world-use-case.ts +74 -0
  52. package/scripts/harness/world-model/application/usecases/pin-constraint-endpoint-use-case.ts +139 -0
  53. package/scripts/harness/world-model/composition-root.ts +218 -0
  54. package/scripts/harness/world-model/domain/entities/constraint-record.ts +148 -0
  55. package/scripts/harness/world-model/domain/entities/control-declarations.ts +274 -0
  56. package/scripts/harness/world-model/domain/entities/edge.ts +41 -0
  57. package/scripts/harness/world-model/domain/entities/extraction-diagnostic.ts +60 -0
  58. package/scripts/harness/world-model/domain/entities/snapshot.ts +75 -0
  59. package/scripts/harness/world-model/domain/entities/world-node.ts +210 -0
  60. package/scripts/harness/world-model/domain/ports/world-hashing-port.ts +8 -0
  61. package/scripts/harness/world-model/domain/services/canonical-json-serializer.ts +113 -0
  62. package/scripts/harness/world-model/domain/services/constraint-evaluator.ts +486 -0
  63. package/scripts/harness/world-model/domain/services/obligation-derivation-service.ts +199 -0
  64. package/scripts/harness/world-model/domain/services/policy-inputs-digest-deriver.ts +66 -0
  65. package/scripts/harness/world-model/domain/services/snapshot-root-deriver.ts +218 -0
  66. package/scripts/harness/world-model/domain/services/text-content-normalizer.ts +30 -0
  67. package/scripts/harness/world-model/domain/services/violation-fingerprint-deriver.ts +183 -0
  68. package/scripts/harness/world-model/domain/value-objects/artifact-kind.ts +58 -0
  69. package/scripts/harness/world-model/domain/value-objects/change-provenance.ts +137 -0
  70. package/scripts/harness/world-model/domain/value-objects/corpus-role.ts +57 -0
  71. package/scripts/harness/world-model/domain/value-objects/declared-key.ts +35 -0
  72. package/scripts/harness/world-model/domain/value-objects/evaluation-id.ts +41 -0
  73. package/scripts/harness/world-model/domain/value-objects/explicit-constraint-relation.ts +53 -0
  74. package/scripts/harness/world-model/domain/value-objects/explicit-node-alias.ts +30 -0
  75. package/scripts/harness/world-model/domain/value-objects/node-pin.ts +34 -0
  76. package/scripts/harness/world-model/domain/value-objects/path-key.ts +103 -0
  77. package/scripts/harness/world-model/domain/value-objects/sha256-digest.ts +39 -0
  78. package/scripts/harness/world-model/domain/value-objects/violation-fingerprint.ts +36 -0
  79. package/scripts/harness/world-model/domain/value-objects/wcr-rule-id.ts +59 -0
  80. package/scripts/harness/world-model/domain/value-objects/world-node-id.ts +222 -0
  81. package/scripts/harness/world-model/index.ts +22 -0
  82. package/scripts/harness/world-model/infrastructure/adapters/adr-fact-extractor.ts +27 -0
  83. package/scripts/harness/world-model/infrastructure/adapters/assembled-world-fact-source.ts +17 -0
  84. package/scripts/harness/world-model/infrastructure/adapters/attestation-fact-extractor.ts +288 -0
  85. package/scripts/harness/world-model/infrastructure/adapters/attestation-sha256-world-hashing-adapter.ts +15 -0
  86. package/scripts/harness/world-model/infrastructure/adapters/composite-design-fact-source.ts +23 -0
  87. package/scripts/harness/world-model/infrastructure/adapters/design-corpus-fact-extractor.ts +285 -0
  88. package/scripts/harness/world-model/infrastructure/adapters/design-fact-extraction.ts +63 -0
  89. package/scripts/harness/world-model/infrastructure/adapters/file-system-obligation-report-writer-adapter.ts +37 -0
  90. package/scripts/harness/world-model/infrastructure/adapters/file-system-world-control-repository-adapters.ts +330 -0
  91. package/scripts/harness/world-model/infrastructure/adapters/integrity-manifest-fact-extractor.ts +101 -0
  92. package/scripts/harness/world-model/infrastructure/adapters/json-fact-extractor-support.ts +151 -0
  93. package/scripts/harness/world-model/infrastructure/adapters/markdown-design-fact-extractor.ts +493 -0
  94. package/scripts/harness/world-model/infrastructure/adapters/matrix-fact-extractor.ts +283 -0
  95. package/scripts/harness/world-model/infrastructure/adapters/product-fact-extractor.ts +29 -0
  96. package/scripts/harness/world-model/infrastructure/adapters/proposal-fact-extractor.ts +29 -0
  97. package/scripts/harness/world-model/infrastructure/adapters/runtime-fact-extraction.ts +19 -0
  98. package/scripts/harness/world-model/infrastructure/adapters/source-metadata-fact-extractor.ts +22 -0
  99. package/scripts/harness/world-model/infrastructure/adapters/test-reference-source-fact-extractor.ts +22 -0
  100. package/scripts/harness/world-model/infrastructure/adapters/traceability-design-fact-adapter.ts +112 -0
  101. package/scripts/harness/world-model/infrastructure/adapters/traceability-world-read-facade-merger.ts +38 -0
  102. package/scripts/harness/world-model/infrastructure/adapters/type-script-source-fact-extractor.ts +236 -0
  103. package/scripts/harness/world-model/infrastructure/adapters/unit-fact-extractor.ts +71 -0
  104. package/scripts/harness/world-model/infrastructure/adapters/world-control-declaration-mapper.ts +383 -0
  105. package/scripts/harness/world-model/presentation/cli/world-command-support.ts +60 -0
  106. package/scripts/harness/world-model/presentation/cli/world-derive-command-handler.ts +105 -0
  107. package/scripts/harness/world-model/presentation/cli/world-inspect-command-handler.ts +194 -0
  108. package/scripts/harness/world-model/presentation/cli/world-pin-command-handler.ts +100 -0
@@ -0,0 +1,341 @@
1
+ ---
2
+ adr_id: "035"
3
+ title: "World adoption baseline、obligation、waiver"
4
+ status: Proposed
5
+ date: 2026-07-16
6
+ ---
7
+
8
+ # World adoption baseline、obligation、waiver
9
+
10
+ <!-- @work-item-id WI-284 -->
11
+
12
+ ## Context
13
+
14
+ World Modelは、current corpusとconstraint declarationsから構造violationを毎回再導出する。一方、導入時点のrepositoryには既存violationがあり得るため、全件を即時blockingにするとWorld Model自体を導入できない。既存violationだけを可視 debtとしてadoptし、新規claim / pinと壊れたdeclarationは初日から検査するratchetが必要である。
15
+
16
+ 既存PhaseGateにも`.phasegate/baseline.json`がある。実装を確認すると、ci-governance `CreateBaselineUseCase`が対象pathを列挙してSHA-1を保存し、agent-integration `CiGovernanceBaselineGrandfatherAdapter`が現在fileのSHA-1と一致するpathだけをphase-gate / full-mode / story-reflection hookでgrandfatherする。schemaは`version: "1.0"`, `createdAt`, `algorithm: "sha1"`, `files[{path, sha1}]`であり、World node、WCR rule、violation fingerprint、evaluation identityを持たない。
17
+
18
+ coverage attestationには別のlegacy patternがある。`<!-- @coverage-gating: ungated-legacy -->`を持つcoverage reportをL2-016がwarningとして可視化し、markerのない新規bare claimはfail-closedにする。ただしmarkerはfile全体のowner-specific exemptionであり、stable semantic debt IDではない。
19
+
20
+ ADR-031はadoption baseline、waiver、explicit debt declarationを、人がreviewして採用する`external-declaration`とした。ADR-033は`evaluationId`へ`policyInputsDigest`を含め、obligation reportとmutable repayment stateをrootから除外した。ADR-034はpolicy-free evaluation DTO、`WCR-NNN`、ChangeProvenanceを決定した。本ADRはこれらを接続し、structural obligationの同一性、adoption、waiver、返済、semantic debt importを決定する。
21
+
22
+ ## Decision
23
+
24
+ ### 1. Constraint、violation、obligationのidentityを分離する
25
+
26
+ - `constraintId`は`pgw:v1:constraint:<DeclaredKey>`であり、人が宣言したConstraintRecordの同一性を表す。
27
+ - `violationFingerprint`は特定rulesetが特定の構造不一致を観測した同一性を表す。同じconstraintから複数fingerprintが生じ得る。
28
+ - obligationはcurrent evaluation findingから導出する作業項目であり、保存されたEntity identityを持たない。structural obligationの照合keyは`violationFingerprint`である。
29
+ - `evaluationId`はcorpus / constraint / policy inputを含む一回の導出入力identityであり、violation identityではない。
30
+
31
+ constraintを修正せずpin、observed digest、endpoint cardinality、rule semanticsのいずれかが変われば、同じ`constraintId`でもfingerprintは変わり得る。逆にmessage、locator、表示順だけの変更ではfingerprintを変えない。
32
+
33
+ ### 2. `violationFingerprint`をsemantic evidenceから構成する
34
+
35
+ 外部形式を次とする。
36
+
37
+ ```text
38
+ pgw:v1:violation-fingerprint:sha256:<64 lowercase hex>
39
+ ```
40
+
41
+ hexは次のcanonical JSONをADR-033のSHA-256 capabilityでhashした値である。
42
+
43
+ ```text
44
+ {
45
+ schemaVersion: "phasegate-world-violation-fingerprint/v1",
46
+ rulesetVersion,
47
+ ruleId,
48
+ constraintId: string | null,
49
+ factType: string | null,
50
+ subject: {
51
+ endpointRole: "claimant" | "premise" | "both" | "declaration" | "global",
52
+ nodeIds: sorted stable World node IDs
53
+ },
54
+ claimantPin: { nodeId, contentDigest } | null,
55
+ premisePin: { nodeId, contentDigest } | null,
56
+ expected: rule-owned canonical evidence,
57
+ observed: rule-owned canonical evidence
58
+ }
59
+ ```
60
+
61
+ 各`WCR-NNN`は`expected` / `observed`のversioned projectionをruleset contractとして定義する。
62
+
63
+ - missing / deletionは対象endpoint ID、role、pinを含み、current contentがなければ`observed`を明示missing valueにする。
64
+ - invalid aliasはalias ID、declared target、resolution defectを含む。
65
+ - duplicate IDはcanonical node ID、candidate cardinality、sorted candidate content-digest multisetを含み、locatorは含めない。
66
+ - reference / dependencyはfact typeと両endpointのdeclared tupleを含む。
67
+ - digest mismatchはexpected pinとobserved current digestを含む。endpointがさらに編集されればnew fingerprintになる。
68
+ - malformed declarationはparse可能なdeclaration identity、field / diagnostic code、invalid value digestを含め得るが、後述のとおりadoption / waiver対象にはしない。
69
+
70
+ fingerprintへ含めないもの:
71
+
72
+ - `evaluationId`, `corpusRoot`, `constraintRoot`, `policyInputsDigest`
73
+ - baseline / waiver / blocking / severity / adopted / repaid status
74
+ - human message、suggestion、array index
75
+ - PathKey、line、column、heading text等のlocator
76
+ - ChangeProvenanceのbaseline/current Snapshot ID、changed candidate reason
77
+ - `generatedAt`、clock、git commit、package version
78
+
79
+ `rulesetVersion`を含めるため、異なるrulesetのfingerprintを同一violationとして自動比較しない。
80
+
81
+ ### 3. Obligation reportをimmutable derived outputとする
82
+
83
+ obligation reportは次の入力だけから毎回導出する。
84
+
85
+ ```text
86
+ World evaluation DTO
87
+ + adoption baseline declaration
88
+ + waiver declarations
89
+ + explicit semantic debt declarations
90
+ + resolved policy effective date
91
+ ```
92
+
93
+ reportは最低限、`schemaVersion`, `evaluationId`, `rulesetVersion`, `policyInputsDigest`と次の別collectionを持つ。
94
+
95
+ 1. `structuralObligations` — current WCR findings。fingerprint、rule ID、constraint ID、endpoint evidence、policy classificationを持つ。
96
+ 2. `repaidBaselineEntries` — baselineにはあるがcurrent findingsにないfingerprint。
97
+ 3. `declaredSemanticDebts` — external declarationからimportした既知の意味的負債。
98
+ 4. `policyDiagnostics` — invalid / expired waiver、ruleset mismatch、stale baseline等。
99
+
100
+ 全collectionはstable ID / fingerprintでsortし、summary countはcollectionから導出する。reportに`generatedAt`を入れず、同じ入力からbyte-identicalにserializeする。
101
+
102
+ persistしたreportはADR-031の`generated-artifact`であり、source / control inputではない。
103
+
104
+ - 手編集しても次のderiveで上書きされ、gate結果を変えない。
105
+ - L3は保存reportを信頼せず、clean corpusとexternal declarationsから再導出する。
106
+ - report自身をWorld ingestion / fingerprint / policy inputへ含めない。
107
+ - report path、Git tracking、human / JSON formatterはADR-037で決定する。
108
+
109
+ ### 4. `repaid`をcurrent set differenceとして導出する
110
+
111
+ 同一rulesetのvalid baseline fingerprint集合を`B`、current structural violation fingerprint集合を`V`とする。
112
+
113
+ ```text
114
+ adopted = B ∩ V
115
+ repaid = B − V
116
+ new = V − B
117
+ ```
118
+
119
+ `repaid`はreport上のderived classificationであり、baseline entryへ`repaid`, `repaidAt`, `status`, `remaining`を保存しない。current evaluationが変われば毎回再計算する。
120
+
121
+ `repaid` entryは同じ変更でbaselineから削除し、再deriveする。stale entryを残すと同じfingerprintの再発を再びlegacy扱いできるため、validator-systemは`repaidBaselineEntries`をbaseline cleanup requiredとしてblockingする。削除後の再deriveではentry自体がなくなり、返済履歴はbaselineのGit diffとWork-Item trailerに残る。
122
+
123
+ ### 5. Adoption baselineをclosed、monotonic-shrink declarationとする
124
+
125
+ adoption baselineはversioned external declarationであり、少なくとも次を持つ。正式file nameはADR-037へ委譲する。
126
+
127
+ ```text
128
+ AdoptionBaseline {
129
+ schemaVersion
130
+ rulesetVersion
131
+ sourceEvaluationId
132
+ sourceCorpusRoot
133
+ sourceConstraintRoot
134
+ adoptedByWorkItemId
135
+ adoptionReason
136
+ entries: sorted [{
137
+ violationFingerprint
138
+ ruleId
139
+ constraintId: string | null
140
+ }]
141
+ }
142
+ ```
143
+
144
+ これはADR-034 `ChangeProvenance.baselineSnapshotId`の比較snapshotとは別概念である。comparison baselineはnode change evidence、adoption baselineはknown violation fingerprintのpolicy inputであり、相互変換しない。
145
+
146
+ - `sourceEvaluationId`はbaseline採用前のcandidate evaluationを指す。baseline自身を含むevaluationIdへのself-referenceを作らない。
147
+ - entryはsource evaluationに実在し、人がlegacy structural debtとしてreviewしたfingerprintだけにする。
148
+ - `WCR-001` malformed declaration、invalid policy declaration、新規claim / pinに由来するfindingはadoption対象外。
149
+ - 同一ruleset内でbaseline entryを追加しない。返済による削除だけを許可する。
150
+ - commandがcandidateを生成しても自動採用せず、version control reviewと`adoptedByWorkItemId`を必要とする。
151
+ - duplicate fingerprint / unsupported schema / source identity欠落はfail-closed policy diagnosticとする。
152
+
153
+ このclosed-set ratchetにより、adoption後に発生したviolationをbaselineへ追記して非blocking化することを禁止する。例外が必要ならbaselineを拡張せず、§8のtime-bounded waiverを使う。
154
+
155
+ ### 6. Legacyと新規のblocking policyを固定する
156
+
157
+ world-modelはADR-034のpolicy-free evaluation DTOからclassificationを導出し、validator-systemが次のblocking mappingを所有・適用する。
158
+
159
+ | condition | classification | validator policy |
160
+ |---|---|---|
161
+ | valid current fingerprintがsame-ruleset baselineに存在 | `adopted-legacy` | non-blocking warning。常にreportへ表示 |
162
+ | current fingerprintがbaselineにない | `new-structural` | default blocking |
163
+ | new claim / pinが全ruleを通過 | findingなし | pass。新規であること自体はfailureにしない |
164
+ | new claim / pinにfindingあり | `new-structural` | 初日からblocking。baseline追加不可 |
165
+ | `WCR-001` malformed / unsupported declaration | `invalid-declaration` | blocking、non-adoptable、non-waivable |
166
+ | baseline entryがcurrent setにない | `repaid` | baseline cleanup requiredとしてblocking。entry削除後にpass |
167
+ | exact active waiverあり | `waived` | non-blockingだがreportへ理由・期限・WIを表示 |
168
+ | waiver expired / invalid | `new-structural`または元classification | waiverを適用せず、元のpolicyで判定 |
169
+
170
+ 新規claim / pinをfail-closedにするとは、validな追加を無条件blockすることではない。新規追加をlegacy baselineで免除せず、parse / resolution / pin / reference / dependency / digest ruleを全て通過しなければblockingするという意味である。
171
+
172
+ 新規violationには別review済みwaiverを適用できるが、baselineへ恒久追記しない。`WCR-001`とpolicy input自体のmalformed / unsupported状態にはwaiverを適用できない。
173
+
174
+ ### 7. Ruleset migrationではbaselineを自動carryしない
175
+
176
+ baselineの`rulesetVersion`とruntime rulesetが一致しない場合:
177
+
178
+ - old fingerprintをmatch対象にしない。
179
+ - version string置換、old hashの再label、rule IDだけによる自動carryを禁止する。
180
+ - baseline suppressionを適用せず、`baseline-ruleset-mismatch` policy diagnosticとしてfail-closedにする。
181
+
182
+ migrationは次のreviewed workflowとする。
183
+
184
+ 1. new rulesetでcurrent corpusを評価し、新fingerprint集合を生成する。
185
+ 2. old baseline entryごとに`carried`, `repaid`, `split`, `merged`, `removed-rule`を人が確認する。
186
+ 3. still-accepted legacy debtだけからnew baseline candidateを作る。new rulesetで初めて発見されたviolationを自動adoptしない。
187
+ 4. migration WIのreviewでold baselineをnew declarationへ原子的に置換する。
188
+ 5. new declarationを含めて再deriveし、fingerprint集合とserialized reportの再現性を確認する。
189
+
190
+ fingerprintにrulesetVersionを含め、baselineにもrulesetVersionをpinすることでfalse continuityより明示migrationを優先する。
191
+
192
+ ### 8. Waiverをexact、time-bounded external declarationとする
193
+
194
+ Waiverは次の必須fieldを持つ。正式file nameはADR-037で決定する。
195
+
196
+ ```text
197
+ Waiver {
198
+ schemaVersion
199
+ waiverId: pgw:v1:waiver:<DeclaredKey>
200
+ violationFingerprint
201
+ reason
202
+ expiresOn: YYYY-MM-DD
203
+ workItemId: WI-<digits>
204
+ renewalOf: waiverId | null
205
+ }
206
+ ```
207
+
208
+ - targetはexact fingerprint一件。rule ID、constraint ID、path、Unit、globによるwildcard waiverを禁止する。
209
+ - `reason`はnon-emptyで、なぜ即時返済できないかと期限内のnext actionを記述する。
210
+ - `expiresOn`はUTC dateのexclusive boundaryとする。`policyAsOfDate < expiresOn`の間だけactiveで、同日以降はexpired。
211
+ - `workItemId`はinception全体で一意に解決するWorkItemでなければならない。
212
+ - waiver declarationの追加・変更はversion control review対象であり、runtime flagやreport手編集で生成しない。
213
+ - expired waiverは削除またはrenewするまでreportへ表示するが、violationを抑止しない。
214
+
215
+ renewalはexpiry fieldの無言延長ではなく、新しい`waiverId`とreview WIを持つrecordとして作る。`renewalOf`で直前waiverを参照し、reasonとexpiryを再評価する。旧recordは同じ変更でcurrent declaration集合から除き、履歴はGitと`renewalOf`で保持する。自動renewal、無期限expiry、predecessor scopeの暗黙継承を禁止する。
216
+
217
+ `renewalOf`は直前waiver IDへのaudit referenceであり、predecessorがcurrent declaration集合に残ることを要求しない。runtimeはrenewal chainを辿ってsuppression scopeを拡張せず、新record自身のexact fingerprint、expiry、WIだけを評価する。
218
+
219
+ ### 9. Policy inputsを`evaluationId`へ結び付ける
220
+
221
+ ADR-033の`policyInputsDigest`を次で定義する。
222
+
223
+ ```text
224
+ sha256(canonicalJson({
225
+ schemaVersion: "phasegate-world-policy-inputs/v1",
226
+ adoptionBaseline: canonical declaration | null,
227
+ waivers: sorted canonical declarations,
228
+ semanticDebts: sorted canonical declarations,
229
+ policyAsOfDate: YYYY-MM-DD | null
230
+ }))
231
+ ```
232
+
233
+ - baseline / waiver / semantic debtは人が採用するimmutable evaluation inputとしてsemantic fieldを全て含める。
234
+ - `policyAsOfDate`はwaiverが一件以上ある場合だけUTC dateを含め、waiverがなければ`null`とする。
235
+ - `policyAsOfDate`はreport生成時刻ではなく、expiry判定を変える明示的なresolved policy inputである。同じderive中に一度だけ解決し、全waiverへ同じ値を使う。
236
+ - `generatedAt`, current timestamp、duration、mtimeは含めない。
237
+ - declaration file path、JSON formatting、array input orderは含めない。
238
+
239
+ したがってbaseline entry、waiver、semantic debt、waiver有効日の変更は`policyInputsDigest`と`evaluationId`を変える。一方、raw WCR findingと`violationFingerprint`はpolicyから独立し、同じ構造violationを維持する。
240
+
241
+ invalid / unsupported policy declarationはempty inputへfallbackしない。trustworthyな`policyInputsDigest` / obligation classificationを生成せず、validator-systemへfail-closed diagnosticを返す。
242
+
243
+ ADR-033が除外したclock metadataと矛盾させないため、`policyAsOfDate`を観測時刻metadataではなくwaiver semanticsの入力として限定する。CLIのdefault / override方法はADR-037、testではinjectable dateを使う。
244
+
245
+ ### 10. Semantic debtをstructural obligationと分離する
246
+
247
+ explicit semantic debtは、人が既知の意味的不足を宣言しWorldへimportするexternal declarationである。機械がWCR factsから発見したとは表現しない。
248
+
249
+ ```text
250
+ SemanticDebtDeclaration {
251
+ schemaVersion
252
+ debtId: pgw:v1:semantic-debt:<DeclaredKey>
253
+ kind: "semantic"
254
+ title
255
+ reason
256
+ ownerUnit
257
+ introducedByWorkItemId
258
+ references: sorted World node IDs
259
+ }
260
+ ```
261
+
262
+ - `debtId`はADR-032のDeclaredKey syntaxを使い、`<unit>.<topic>`を推奨する。同一projectで一意とする。
263
+ - declarationがcurrent集合に存在することをactive debtとする。`repaid` / `resolvedAt` stateを保存しない。
264
+ - 返済時はresolution WIでdeclarationとsource annotationを削除する。履歴はGitとWork-Item trailerに残す。
265
+ - semantic debtは`violationFingerprint`を持たず、adoption baseline / waiver対象にしない。
266
+ - semantic debt declarationはstructural violationを抑止しない。同じ箇所にWCR findingがあれば別collectionに両方表示する。
267
+ - reportは`declaredSemanticDebts`を「declared/imported」と表示し、`detected`, `rediscovered`, `repaid structural obligation`という表現を使わない。
268
+
269
+ ### 11. §10のsemantic debt ID / coverage report記法へ回答する
270
+
271
+ explicit semantic debt IDには`pgw:v1:semantic-debt:<DeclaredKey>`を採用する。既存coverage reportからexternal declarationを参照するfile-level annotationは次とする。
272
+
273
+ ```markdown
274
+ <!-- @world-semantic-debt pgw:v1:semantic-debt:skill-quality.coverage-attestation-legacy -->
275
+ ```
276
+
277
+ - optional YAML frontmatterとdocument H1の後、最初のprose / tableより前のfile-level metadata blockへ置く。
278
+ - repeatableとし、一commentにつき一debt IDを記述する。
279
+ - annotationはexternal declarationへのreferenceであり、debtのreason / owner / WIをMarkdownへ複製しない。
280
+ - `<!-- @coverage-gating: ungated-legacy -->`と併存できるが、置き換えない。owner-specific markerのL2-016 exemption semanticsを変更しない。
281
+ - `@world-semantic-debt`はattestation、waiver、adoption baselineではなく、bare claimをgreenにしない。
282
+
283
+ external declarationの正式file name / schema pathはADR-037へ委譲する。WM-17で実corpusをinventoryし、既知coverage gapをこのIDで宣言・annotation参照してからWorld reportへimportする。本ADRでは既存coverage reportを編集しない。
284
+
285
+ ### 12. 既存PhaseGate baselineとは統合しない
286
+
287
+ 既存`.phasegate/baseline.json`とWorld adoption baselineは別owner / schema / lifecycleを維持する。
288
+
289
+ | concern | existing PhaseGate baseline | World adoption baseline |
290
+ |---|---|---|
291
+ | owner / consumer | ci-governance + agent-integration hook | world-model evaluation、validator-system policy adapter |
292
+ | identity | project-relative path | `violationFingerprint` |
293
+ | digest | raw/current file SHA-1 | ADR-033 semantic SHA-256 evidence |
294
+ | purpose | unchanged legacy pathのhook grandfather | known structural violationのvisible non-blocking adoption |
295
+ | lifecycle | file bytes変更でgrandfather失効、`--force` overwriteあり | initial closed set、same-ruleset追加禁止、返済で削除 |
296
+ | config | current top-level `baseline.enabled/path` | ADR-037で別config / file discoveryを決定 |
297
+
298
+ World側から既存baseline fileをimport、upgrade、rewriteしない。同じpathに両者を保存せず、既存`baseline-reset` / `phasegate baseline` commandの意味も変更しない。
299
+
300
+ ## Consequences
301
+
302
+ ### Positive
303
+
304
+ - obligation reportを手編集可能なstateではなく、再現可能なderived outputにできる。
305
+ - legacy structural debtだけを導入時にadoptし、新規violationのbaseline launderingを防げる。
306
+ - 返済をcurrent set differenceで導出し、stale baselineによる再発の再免除を防げる。
307
+ - exact fingerprint / expiry / WIを持つwaiverにより、例外を局所的かつ期限付きにできる。
308
+ - ruleset変更時のfalse continuityを避け、人によるmigration reviewを要求できる。
309
+ - explicit semantic debtを機械検出したstructural obligationと混同せず表示できる。
310
+ - 既存path / SHA-1 hook baselineの互換性を維持できる。
311
+
312
+ ### Negative / Trade-off
313
+
314
+ - baseline採用、ruleset migration、waiver renewalにreview WIが必要になる。
315
+ - repaid entryを削除するまでbaseline cleanupがblockingになる。
316
+ - observed digestやcandidate cardinalityが変わると、同じconstraintでもnew fingerprintとしてblockingになり得る。
317
+ - active waiverがある間はUTC policy dateがevaluation identityへ影響する。
318
+ - reportにstructural obligation、repaid entry、semantic debt、policy diagnosticの複数sectionが必要になる。
319
+
320
+ ## Alternatives
321
+
322
+ - **obligation reportへ`repaid`を保存する** — report改竄やstale stateがcurrent evaluationを上書きするため不採用。
323
+ - **same-ruleset baselineへのentry追加を許可する** —新規violationを後からlegacy化でき、ratchetが成立しないため不採用。
324
+ - **fingerprintをconstraintIdだけにする** —一constraintの複数rule / endpoint driftを区別できないため不採用。
325
+ - **fingerprintへpath / line / messageを含める** —locator変更や文言修正だけでlegacy identityが壊れるため不採用。
326
+ - **ruleset versionを無視してold baselineを適用する** —rule semantics変更後にfalse matchを作るため不採用。
327
+ - **waiverをrule / path globで指定する** —将来の未知violationまで免除するため不採用。
328
+ - **既存`.phasegate/baseline.json`を拡張する** —path hook grandfatherとWorld violation adoptionのowner / identity / hash / lifecycleが異なるため不採用。
329
+ - **`ungated-legacy` markerをsemantic debt IDとして流用する** —file-wide booleanであり、project-global ID、reason、owner、WI traceabilityを持たないため不採用。
330
+
331
+ ## 関連要件・文書
332
+
333
+ - `docs/inception/_cross/WI-280/delivery_plan.md` §1, §3 WM-04, §7 ADR-035, §10
334
+ - `docs/inception/_cross/WI-284/description.md`
335
+ - `docs/inception/_cross/WI-284/logical_design.md`
336
+ - ADR-031(external declaration / ownership)
337
+ - ADR-032(DeclaredKey / World node identity)
338
+ - ADR-033(evaluationId / policyInputsDigest / canonicalization)
339
+ - ADR-034(WCR rules / ChangeProvenance / policy-free evaluation DTO)
340
+ - ADR-027(成果物駆動状態導出)
341
+ - ADR-030(coverage attestation / ungated-legacy ratchet)
@@ -0,0 +1,169 @@
1
+ ---
2
+ adr_id: "036"
3
+ title: "World constraints と L4-004 doc freshness の共存"
4
+ status: Proposed
5
+ date: 2026-07-16
6
+ ---
7
+
8
+ # World constraints と L4-004 doc freshness の共存
9
+
10
+ <!-- @work-item-id WI-284 -->
11
+
12
+ ## Context
13
+
14
+ World Modelのexplicit pin / reference driftとL4-004 `doc-freshness`は、どちらも「文書が現在の実装・設計に追随しているか」という利用者の懸念に関係する。しかし、検査するpredicateとevidenceは異なる。同じ文書に両findingが出たとき一方を機械的にduplicateとして消すと、時間経過のsignalか明示constraint違反のどちらかを失う。
15
+
16
+ 実コードを確認すると、L4-004は廃止済みではない。
17
+
18
+ - validator-system `buildDefaultRegistry()`は`L4-004`を`always` conditionで登録し、`ValidatorId`は`doc-freshness`へ対応付ける。
19
+ - validator-system composition-rootはphase2-extensions `CheckDocFreshnessUseCase`を`RunL4ValidatorsUseCase`へ注入する。
20
+ - RunL4はresolved design rootの`**/*.md`を対象にuse caseを実行し、non-`ok` resultを`L4-004`のwarning / errorへ写像する。
21
+ - phase2-extensions `GitLogDocumentAgeAdapter`はdocument自身の最新`git log --format=%ai`からageを計算し、取得できなければfile `mtime`へfallbackする。
22
+ - default freshness ruleはwarn 30日 / error 90日である。
23
+ - `DocumentAgeSource`には`related-source-change`が定義されるが、current production adapterが返すのは`git-log`または`file-mtime`だけである。source hash / explicit dependency / referenceを読むproduction pathはない。
24
+
25
+ self-repo `phasegate.config.json`は`layers.L4.enabled: false`である。minimal / standard presetもL4 disabled、strict presetはenabledだが、全presetのvalidator listに`doc-freshness-checker`が存在する。disabled L4はaggregate実行でskip resultになり、明示的な`validate --layer L4`は`forceLayerEnabled`により実行される。
26
+
27
+ ADR-031はvalidator-systemがgate / blocking policy、world-modelがexplicit constraint evaluationを所有すると決定した。ADR-034はWCRをexistence、ID uniqueness、explicit reference、declared dependency、digest equalityへ限定した。ADR-035はWorld `violationFingerprint` / adoption baseline / waiverをWCR findingだけに適用した。本ADRは既存L4-004を壊さず、この二つのsignalのcanonical ownerと移行条件を決める。
28
+
29
+ ## Decision
30
+
31
+ ### 1. L4-004は時間proxy、Worldは明示構造を検査する
32
+
33
+ | concern | L4-004 doc freshness | World WCR |
34
+ |---|---|---|
35
+ | predicate | document ageがconfigured warn / error days以上か | explicit endpoint、reference、dependency、pin digestが宣言どおりか |
36
+ | evidence | latest document git timestamp、fallback mtime、current date、threshold | stable World IDs、declared fact、claimant / premise pins、canonical content digest |
37
+ | identity | validator ID `L4-004` + phase2 freshness rule ID + document path | `WCR-NNN` + constraint ID + violation fingerprint |
38
+ | determinism | clock、Git history、fallback filesystem metadataに依存するoperational signal | ADR-033 rootsとexplicit policy inputsから再導出するcontent-addressed result |
39
+ | semantics | 古さをstaleness riskのproxyとして通知するheuristic | 宣言済み構造の一致 / 不一致を検証する |
40
+ | owner | phase2-extensionsがfreshness rule / age evaluation、validator-systemがregistry / gate | world-modelがWCR evaluation、validator-systemがgate |
41
+
42
+ L4-004は「古いから内容が誤っている」と断定しない。Worldはdigest / reference driftを「N日古い」と変換しない。clock、git timestamp、mtimeをWorld `corpusRoot`、constraint evaluation、violation fingerprintへ入れない。
43
+
44
+ current production L4-004はsource変更との因果やexplicit design-source relationを検査しない。将来`related-source-change` producerを追加する場合も、明示World dependency / pinで判定できる部分をL4 heuristicとして再実装しない。
45
+
46
+ ### 2. Predicateごとにcanonical rule ownerを一つにする
47
+
48
+ - **age threshold**のcanonical ownerはphase2-extensions `DocFreshnessRule` / `FreshnessCheckService`、public validator IDはvalidator-system `L4-004`。
49
+ - **explicit endpoint existence / uniqueness / reference / dependency / digest equality**のcanonical ownerはworld-model `WCR-001`〜`WCR-008`。
50
+ - **severity、blocking、fail-on-warning、layer execution、exit code**のcanonical ownerはvalidator-system。
51
+
52
+ L4-004 findingからWCR findingを生成しない。WCR findingからL4-004 ageを推定しない。rule text、message、document pathが似ていてもownerを統合しない。
53
+
54
+ 同じdocumentに両findingが出た場合、両predicateはそれぞれ正しいsignalである。ただしexplicit structural remediationについてはWCR obligationをcanonicalとし、L4-004はtemporal supporting signalとして関連付ける。
55
+
56
+ - World obligation reportの`structuralObligations`、`violationFingerprint`、adoption baseline、waiverにはWCR findingだけを入れる。
57
+ - L4-004 findingをWorld structural obligation数へ加えず、World baseline / waiverで抑止しない。
58
+ - L4-004がpassしてもWCR violationを打ち消さず、WCRがpass / adopted / waivedでもL4 age findingを打ち消さない。
59
+ - presentationで関連付ける場合はresolved Artifact / FragmentのPathKeyを使い、message substringや実行順でdeduplicateしない。
60
+ - 同じpathに両方ある場合、WCRをprimary remediation、L4-004を`supporting-temporal-signal`として表示できるが、raw validator resultsは保持する。
61
+
62
+ ### 3. L4-004を現役product capabilityとして維持する
63
+
64
+ World導入だけを理由にL4-004、`p2:check-freshness`、phase2-extensions freshness domainを削除しない。Worldのexplicit constraint coverageが増えても、宣言のない文書や「一定期間reviewされていない」という独立policyは残るためである。
65
+
66
+ 現行配置を維持する。
67
+
68
+ - phase2-extensions: `DocFreshnessRule`, threshold、age port / adapter、use case、compatibility handler
69
+ - validator-system: `L4-004` registry、RunL4 bridge、severity / aggregation
70
+ - config-foundation: preset validator listとL4 enablement
71
+
72
+ L4-004をWorld rulesetへ移動せず、World `rulesetVersion`変更の理由にしない。L4 threshold / age semantics変更はL4 capability自身のversioned product design / testsで管理する。
73
+
74
+ ### 4. Dual-run compatibility periodを設ける
75
+
76
+ compatibility periodは、WM-20でL3 authoritative World re-derivationが対象document patternに対して利用可能になった時点から開始する。終了は次の全条件を満たした後とする。
77
+
78
+ 1. WM-24 production-ready checkpointが完了している。
79
+ 2. 対象patternで少なくとも一つのconfigured L4 warn-threshold期間を経過している。default ruleでは30日。
80
+ 3. 対象patternで少なくとも2回のscheduled / explicit dual-run結果が保存reportではなく再実行から比較されている。
81
+ 4. overlap、L4-only、WCR-only findingをdocument class / rule owner別に集計し、canonical owner誤りとsilent lossがない。
82
+
83
+ 期間中はL4-004とWorld WCRを両方実行可能にし、既存validator ID / command / preset entryを削除しない。overlapはfinding数を隠すdedupではなく、presentation correlationとして扱う。
84
+
85
+ compatibility measurement自体をWorld adoption baselineへ入れず、L4-only findingを`violationFingerprint`へ変換しない。
86
+
87
+ ### 5. 維持、縮退、移行、廃止の条件を分ける
88
+
89
+ #### 維持
90
+
91
+ 次のいずれかが真なら対象patternのL4-004を維持する。
92
+
93
+ - time-since-review自体がproduct / consumer policyとして必要。
94
+ - explicit World constraintでcoveredされないdocumentがある。
95
+ - compatibility periodにactionableなL4-only findingがある。
96
+ - Git age / mtime fallbackを使うconsumer automationまたは`p2:check-freshness`互換経路がある。
97
+
98
+ #### 縮退
99
+
100
+ 対象document classについて次を全て満たす場合だけ、別WIでscan pattern、threshold policy、severityの縮退を提案できる。
101
+
102
+ - World explicit constraint inventoryが対象classをcompleteと判定している。
103
+ - compatibility periodにL4-only findingがない、または全てnon-actionableとreviewされた。
104
+ - time-only freshness policyを不要とするproduct ownerの明示判断がある。
105
+ - config / preset / compatibility commandへのimpactとmigration guideが用意される。
106
+
107
+ 縮退はpattern単位とし、repository全体のL4-004を一括disable / deleteしない。
108
+
109
+ #### Worldへ移行
110
+
111
+ L4 implementationに将来、explicit hash / reference / dependency checkが追加されてWorld WCRと同一predicateになった場合、そのsub-ruleはWorldをcanonical ownerとして移行する。dual-runで同値性を確認し、L4側duplicate sub-ruleをdeprecateする。
112
+
113
+ current git-age / mtime threshold predicateにはWCR equivalentがないため、Worldへ移行しない。
114
+
115
+ #### 廃止
116
+
117
+ `L4-004` IDまたはpublic compatibility command全体の廃止は本ADRでは決定しない。全supported preset / consumerでage policyが不要、unique L4-only valueがない、deprecation periodとregistry / config / docs / tests migrationが完了、という条件を満たした別ADR / breaking changeだけが決定できる。
118
+
119
+ ### 6. Self-repoのL4 disabledとproduct capabilityを分離する
120
+
121
+ self-repoの`layers.L4.enabled: false`はdogfood execution policyであり、capability不存在や廃止を意味しない。
122
+
123
+ - self-repoでaggregate / CI pathがL4をskipしても、L4-004 registry、composition wiring、tests、preset contractを維持する。
124
+ - operatorが明示する`validate --layer L4`はdisabled self-repoでもforce-enableしてL4-004を実行できる。
125
+ - strict presetはL4 enabledを維持し、minimal / standard presetのdisabled方針を本ADRで変更しない。
126
+ - self-repoをdefault-onへ変更するかは、World rolloutとは別のconfig / noise-budget判断とし、本ADRでは変更しない。
127
+
128
+ したがって、self-repoでL4がdisabledであることをL4-004 removalの根拠にしない。
129
+
130
+ ### 7. §10の未決事項には該当なし
131
+
132
+ `docs/inception/_cross/WI-280/delivery_plan.md` §10にADR-036固有の未決事項はない。本ADRは新しいconfig key、validator ID、file name、report pathを決定しない。それらはADR-037のscopeを維持する。
133
+
134
+ ## Consequences
135
+
136
+ ### Positive
137
+
138
+ - 時間proxyとexplicit structural proofを混同せず、それぞれのsignalを保持できる。
139
+ - WCR fingerprint / baselineへheuristic findingが混入することを防げる。
140
+ - self-repo configだけを理由に現役product capabilityを削除しない。
141
+ - pattern単位のmeasurementに基づき、維持 / 縮退 / 移行を段階判断できる。
142
+ - 将来L4へexplicit drift checkが重複実装されることを防げる。
143
+
144
+ ### Negative / Trade-off
145
+
146
+ - compatibility period中は同じdocumentに二つのfindingが表示され得る。
147
+ - L4-004はclock / Git / mtime依存であり、World snapshotと同じbyte determinismを持たない。
148
+ - correlation表示とoverlap / unique finding inventoryが必要になる。
149
+ - World coverageがcompleteでも、独立したtime policyが残ればL4-004を維持する必要がある。
150
+
151
+ ## Alternatives
152
+
153
+ - **World導入時にL4-004を即時削除する** — explicit constraintのないdocumentとtime-since-review signalを失い、現役registry / command contractを破るため不採用。
154
+ - **L4 age findingをWCR digest driftとして変換する** — ageはcontent mismatchの証拠ではなく、ADR-034のrule限界を越えるため不採用。
155
+ - **WCR findingがあればL4 findingを完全に隠す** — time policyの独立違反を失うため不採用。
156
+ - **同じpathなら一律duplicateとする** — predicate / evidenceを見ずに異なる責務を統合するため不採用。
157
+ - **self-repo L4 disabledをcapability廃止とみなす** — product preset / explicit execution / consumer contractとdogfood policyを混同するため不採用。
158
+
159
+ ## 関連要件・文書
160
+
161
+ - `docs/inception/_cross/WI-280/delivery_plan.md` §1, §3 WM-04, §7 ADR-036, §10
162
+ - `docs/inception/_cross/WI-284/description.md`
163
+ - `docs/inception/_cross/WI-284/logical_design.md`
164
+ - ADR-031(validator-system / world-model ownership)
165
+ - ADR-033(clock / mtime exclusion、canonical roots)
166
+ - ADR-034(WCR structural rule limits)
167
+ - ADR-035(WCR fingerprint / adoption baseline / waiver)
168
+ - phase2-extensions product design(doc freshness)
169
+ - validator-system product design(L4 registry / execution)