-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
169 lines (142 loc) · 6.57 KB
/
types.ts
File metadata and controls
169 lines (142 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// =============================================================================
// @pmatrix/field-node-runtime — types.ts
// P-MATRIX 4.0 Field Protocol shared types
//
// References:
// - Field 개발기획서 v1.2 §4 (Architecture)
// - Field 구현 설계 v0.4 §5.1 (State Vector 5요소)
// - 4.0 논문 §5.1, §5.7
// =============================================================================
// ─── 4-axis Risk Info ─────────────────────────────────────────────────────────
/**
* 4-axis coordinate system (3.5 basis).
* Stability polarity: higher = more instability (monitor sends instability score).
*/
export interface RiskInfo {
baseline: number; // 0–1, tool risk accumulation
norm: number; // 0–1, behavioral compliance
stability: number; // 0–1, instability score (higher = more drift)
meta_control: number; // 0–1, meta-cognitive control
r_t: number; // computed: 1 - (baseline + norm + (1-stability) + meta_control) / 4
mode: string; // "Normal" | "Caution" | "Restricted" | "Isolated"
}
// ─── Lifecycle Info ───────────────────────────────────────────────────────────
export interface LifecycleInfo {
current_mode: string; // current operational mode
mode_since: string; // ISO8601 timestamp when mode was entered
loop_count: number; // total event loop count since session start
}
// ─── Freshness Evidence ───────────────────────────────────────────────────────
export interface FreshnessEvidence {
timestamp: string; // ISO8601 — when this SV was built
ttl_seconds: number; // how long this SV is considered fresh
}
// ─── Integrity Evidence ───────────────────────────────────────────────────────
//
// Phase 1: placeholder signature (hex digest of payload).
// Phase 2+: ed25519 proper signing with key pair.
//
export interface IntegrityEvidence {
signature: string; // Phase 1: "sha256:<hex>", Phase 2+: "ed25519:<base64>"
node_id: string; // unique node identifier
}
// ─── State Vector (4.0 §5.1) ─────────────────────────────────────────────────
/**
* 4.0 Protocol State Vector — 5요소 구조.
* Exchanged between nodes in Stage 1 (Exchange).
*/
export interface StateVector {
risk_info: RiskInfo;
lifecycle_info: LifecycleInfo;
policy_digest: string; // sha256 of active field policy
freshness_evidence: FreshnessEvidence;
integrity_evidence: IntegrityEvidence;
}
// ─── Verification Result (Stage 2) ───────────────────────────────────────────
export type VerificationStatus = 'pass' | 'warn' | 'fail';
export interface VerificationCheck {
name: string;
status: VerificationStatus;
detail?: string;
}
/**
* Result of LocalVerifier evaluation of a peer's StateVector.
* Input to LocalDecider (Stage 3).
*/
export interface VerificationResult {
peer_node_id: string;
overall: VerificationStatus;
checks: VerificationCheck[];
peer_r_t: number;
peer_mode: string;
verified_at: string; // ISO8601
}
// ─── Mode Transition Decision (Stage 3) ──────────────────────────────────────
/**
* Possible interaction postures toward a peer node.
* Decided by LocalDecider, executed by LocalPEP.
*/
export type PeerPosture =
| 'maintain' // no change — continue as normal
| 'caution' // flag and monitor — soft alert
| 'restrict' // limit interaction scope
| 'reject'; // refuse to interact with this peer
export interface ModeTransition {
peer_node_id: string;
previous_posture: PeerPosture;
new_posture: PeerPosture;
reason: string;
decided_at: string; // ISO8601
}
// ─── PEP Enforcement Result (Stage 4) ────────────────────────────────────────
export interface PepResult {
peer_node_id: string;
posture: PeerPosture;
action_taken: string;
enforced_at: string; // ISO8601
}
// ─── Audit Event ─────────────────────────────────────────────────────────────
export type AuditStage = 'exchange' | 'verify' | 'decide' | 'enforce';
export interface AuditEvent {
field_id?: string;
node_id: string;
stage: AuditStage;
event_type: string;
payload: Record<string, unknown>;
created_at: string; // ISO8601
}
// ─── Field Node Config ────────────────────────────────────────────────────────
export interface FieldNodeConfig {
/** P-MATRIX server WebSocket URL for State Vector exchange */
serverWsUrl: string;
/** P-MATRIX server REST URL for audit log */
serverApiUrl: string;
/** API key for authentication */
apiKey: string;
/** This node's identifier */
nodeId: string;
/** Active Field ID */
fieldId: string;
/** Active policy digest (sha256) */
policyDigest: string;
/** State Vector TTL in seconds (default: 30) */
svTtlSeconds: number;
/** Whether field mode is active — false = 3.5 only, no 4.0 protocol */
fieldModeEnabled: boolean;
/** Minimum peer r_t to trigger caution (default: 0.50) */
cautionThreshold: number;
/** Minimum peer r_t to trigger restrict (default: 0.75) */
restrictThreshold: number;
/** Debug logging */
debug: boolean;
}
export type PartialFieldNodeConfig = Partial<FieldNodeConfig> &
Pick<FieldNodeConfig, 'serverWsUrl' | 'serverApiUrl' | 'apiKey' | 'nodeId' | 'fieldId' | 'policyDigest'>;
// ─── WS Message envelope ──────────────────────────────────────────────────────
export interface WsEnvelope {
type: 'state_vector' | 'field_advisory' | 'ping' | 'pong';
node_id: string;
field_id: string;
payload: unknown;
sent_at: string;
}