# PSMR Semantic Delta & Projection Specification v0.1

**版本：** v0.1  
**作者：** Neo.K  
**機構：** EveMissLab  
**日期：** 2026-09-15

**公司：** 一言諾科技有限公司  

---

## 0. 文件目的

本文件定義 PSMR 如何表示「修改」。

傳統工具以：

```text
diff
patch
file edit
```

表示變更。

PSMR 將修改提升為：

$$
\boxed{
\Delta W
}
$$

即 Semantic Workspace 的語義差分。

Patch 是：

$$
\Delta W
$$

的一種 Projection，而不是變更本體。

---

# 一、Semantic Delta

定義：

$$
\Delta W
=
(
\Delta A,
\Delta G,
\Delta K,
\Delta H,
\Delta U,
\Delta C
)
$$

其中：

- $\Delta A$：Artifact changes；
- $\Delta G$：Graph changes；
- $\Delta K$：Contract changes；
- $\Delta H$：History changes；
- $\Delta U$：Unknown / Conflict changes；
- $\Delta C$：Capability / policy-related changes。

---

# 二、Delta Lifecycle

正式狀態：

```text
draft
proposed
validated
approved
projected
applied
reconstructed
verified
rejected
superseded
```

---

# 三、Delta Identity

$$
ID_{\Delta}
=
H(
N(\Delta W)
)
$$

其中 $N$ 是 canonical normalization。

---

# 四、Delta Operation Types

最低集合：

```text
add_object
remove_object
replace_object
add_edge
remove_edge
replace_edge
add_contract
remove_contract
update_contract
resolve_unknown
introduce_unknown
resolve_conflict
introduce_conflict
```

---

# 五、Semantic Operation Example

不是：

```diff
- validate_old(token)
+ validate_new(token)
```

而是：

```json
{
  "op": "replace_relation",
  "subject": "semantic:auth.login",
  "relation": "calls",
  "before": "semantic:auth.validate_old",
  "after": "semantic:auth.validate_new"
}
```

Patch 可稍後生成。

---

# 六、Intent Link

每個 Delta 可指向：

```text
human intent
issue
AI proposal
policy requirement
defect
runtime evidence
```

Schema：

```json
{
  "delta_id": "...",
  "intent_refs": ["intent_..."],
  "operations": [],
  "authority": "ai_proposal"
}
```

---

# 七、Constraint Set

Delta 可以攜帶：

$$
K_{\Delta}
$$

例如：

```text
login observable behavior unchanged
no new network effect
preserve API signature
all existing tests pass
```

---

# 八、Precondition

Delta 可定義：

$$
P_{\Delta}
$$

例如：

> `auth.login` 目前仍呼叫 `validate_old`。

若不成立：

```text
DELTA_PRECONDITION_FAILED
```

---

# 九、Postcondition

應描述：

$$
Q_{\Delta}
$$

即應達成的新語義狀態。

---

# 十、Projection

Projection 定義：

$$
P_j
:
(W,\Delta W)
\rightarrow
Y_j
$$

其中：

$$
Y_j
$$

可以是：

```text
source patch
full source
test patch
schema migration
documentation update
PR description
runtime policy
configuration
```

---

# 十一、Projection Manifest

```json
{
  "projection_id": "proj_...",
  "projection_type": "source_patch",
  "delta_id": "delta_...",
  "projector_id": "python.source_projector",
  "projector_version": "0.1.0",
  "target_artifact_ids": [],
  "status": "preview",
  "payload_ref": "..."
}
```

---

# 十二、Projection 類型

## 12.1 Lossless Projection

理論上能完整保留語義資訊。

## 12.2 Conditionally Reversible

在特定 subset 可逆。

## 12.3 Lossy Projection

例如 human summary。

## 12.4 Generative Projection

例如：

$$
\Delta W
\rightarrow
\text{new source implementation}
$$

可能存在多個合法答案。

---

# 十三、Projection 不等於 Apply

$$
\boxed{
\text{Project}
\neq
\text{Apply}
}
$$

Projection 產生 candidate artifact。

Apply 才是 effectful operation。

---

# 十四、Projection Validation

投影後應至少檢查：

```text
syntax
type compatibility
contract compatibility
expected semantic change
unexpected semantic change
new findings
unknown changes
```

---

# 十五、Round-Trip Verification

完整閉環：

$$
W
\xrightarrow{\Delta}
W_{\mathrm{intended}}
$$

$$
(W,\Delta)
\xrightarrow{P}
Y
$$

$$
Y
\xrightarrow{A}
W_{\mathrm{observed}}
$$

驗證：

$$
W_{\mathrm{observed}}
\equiv_{\mathcal C}
W_{\mathrm{intended}}
$$

---

# 十六、Semantic Equivalence Relation

不要求 byte-equality。

定義：

$$
\equiv_{\mathcal C}
$$

由 Contract Set $\mathcal C$ 決定。

例如：

```text
same public API
same state effects
same call boundaries
same tests
no new confirmed defects
```

---

# 十七、Unexpected Delta

重建後：

$$
\Delta W_{\mathrm{observed}}
$$

若：

$$
\Delta W_{\mathrm{observed}}
\neq
\Delta W_{\mathrm{intended}}
$$

則產生：

$$
\Delta W_{\mathrm{unexpected}}
$$

---

# 十八、Projection Provenance

必須記錄：

```text
which delta
which projector
which version
which artifacts
which model if generative
which constraints
which validation
```

---

# 十九、AI-generated Projection

若 AI 生成 source：

```text
authority = ai_proposal
```

投影本身不提升為：

```text
implementation observed
```

只有 apply + reconstruct 後，新的 source 才是 implementation evidence。

---

# 二十、Multi-Projection

同一個 Delta 可同時生成：

```text
source patch
tests
documentation
migration note
PR summary
```

即：

$$
\Delta W
\rightarrow
\{
Y_1,Y_2,\ldots,Y_n
\}
$$

---

# 二十一、Projection Conflict

若不同 Projector 對同一 Delta 產生互斥結果：

```text
projection_conflict
```

不可靜默選一個。

---

# 二十二、Source Projector Interface

最低介面：

```text
supports(language, delta_type)
preview(workspace, delta)
validate_projection(workspace, delta, artifact)
```

---

# 二十三、Test Projector Interface

Delta 可推導：

```text
existing tests to rerun
new tests to generate
contract tests
regression tests
```

---

# 二十四、Documentation Projector

同一 Delta 可以轉成人類說明：

```text
what changed
why
impact
evidence
validation
```

這也是 Projection，而不是 ontology 本身。

---

# 二十五、PR Projector

可生成：

```text
title
summary
semantic change list
impact
new findings
validation
unknowns
```

---

# 二十六、No-Source Projection

若 Workspace 來源不是 source code，Projection 仍可輸出：

```text
report
schema patch
policy
test oracle
runtime recommendation
```

PSMR 不假設 output 必須是 source。

---

# 二十七、Delta Merge

兩個 Delta：

$$
\Delta_1
$$

與：

$$
\Delta_2
$$

可以嘗試：

$$
\Delta_1\oplus\Delta_2
$$

但必須做：

```text
semantic conflict detection
contract conflict detection
projection conflict detection
```

---

# 二十八、Delta Rebase

Workspace 演化後，舊 Delta 可嘗試：

$$
\operatorname{Rebase}(\Delta,W_t,W_{t+1})
$$

若 precondition 失效則拒絕。

---

# 二十九、Delta Review

Human-facing review 應顯示：

```text
intent
semantic operations
affected objects
impact
contracts
unknowns
projection preview
verification plan
```

而不只是一坨 text diff。

---

# 三十、與 PBSOI CISG v1.0 的關係

PBSOI 已具備：

$$
\text{Semantic Diff}
$$

即：

$$
W_A
\rightarrow
W_B
\Rightarrow
\Delta W_{\mathrm{observed}}
$$

下一步則是反方向：

$$
\Delta W_{\mathrm{intended}}
\rightarrow
\text{Projection}
\rightarrow
W_B
$$

這會把 PBSOI 從「理解已發生的修改」推向「先描述語義修改，再投影實作」。

---

# 三十一、結論

PSMR 的修改本體不是 Patch。

而是：

$$
\boxed{
\Delta W
}
$$

Patch、Source、Test、Documentation 都只是：

$$
\boxed{
\operatorname{Projection}(\Delta W)
}
$$

這讓 AI Coding 從：

$$
\text{Prompt}
\rightarrow
\text{Text Edit}
$$

升級成：

$$
\boxed{
\text{Intent}
\rightarrow
\text{Semantic Delta}
\rightarrow
\text{Projection}
\rightarrow
\text{Reconstruction}
\rightarrow
\text{Verification}
}
$$
