@godman-protocols/soul 0.2.0 → 0.3.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.
package/src/types.ts CHANGED
@@ -1,67 +1,212 @@
1
1
  /**
2
- * SOUL — Constitutional Constraints and Safety
3
- * Core type definitions (skeleton)
4
- * @version 0.1.0-skeleton
2
+ * SOUL — Sovereign Open Universal Layer
3
+ * "One layer. Every chain. Every model. SOUL."
4
+ *
5
+ * Agent constitutional identity standard. Defines the SOUL.md format —
6
+ * a machine-readable constitutional passport declaring who the agent is,
7
+ * what it believes, and what constraints govern it. Anchored on-chain via ERC-8004.
8
+ *
9
+ * @version 0.3.0
5
10
  */
6
11
 
7
- export type AgentId = string;
12
+ // ---------------------------------------------------------------------------
13
+ // Primitive aliases
14
+ // ---------------------------------------------------------------------------
15
+
16
+ /** ISO 8601 timestamp */
8
17
  export type Timestamp = string;
9
- export type Signature = string;
10
-
11
- export type EnforcementLevel = 'hard' | 'soft' | 'advisory';
12
- export type ConstraintAction = 'allow' | 'deny' | 'require';
13
-
14
- /** A single constitutional constraint */
15
- export interface Constraint {
16
- id: string;
17
- name: string;
18
- description: string;
19
- action: ConstraintAction;
20
- enforcementLevel: EnforcementLevel;
21
- /** Resource or action pattern this constraint covers */
22
- scope: string;
23
- /** Whether this constraint survives context compaction (must be bootstrapped) */
24
- bootstrapped: boolean;
18
+
19
+ /** SHA-256 hex digest */
20
+ export type SHA256Hash = string;
21
+
22
+ /** Ethereum address (0x-prefixed) */
23
+ export type EthAddress = string;
24
+
25
+ /** ERC-8004 token ID (uint256 as string) */
26
+ export type TokenId = string;
27
+
28
+ /** Chain ID (e.g. 8453 for Base) */
29
+ export type ChainId = number;
30
+
31
+ // ---------------------------------------------------------------------------
32
+ // SOUL.md section keys the 9 required sections
33
+ // ---------------------------------------------------------------------------
34
+
35
+ /**
36
+ * The 9 required sections of a SOUL.md document.
37
+ * These map to the headings in the canonical SOUL.md format.
38
+ */
39
+ export type SoulSectionKey =
40
+ | 'who_we_are'
41
+ | 'why_we_exist'
42
+ | 'what_we_believe'
43
+ | 'what_we_will_never_do'
44
+ | 'what_we_owe_the_world'
45
+ | 'what_we_owe_each_other'
46
+ | 'founding_intention'
47
+ | 'self_committed_swarms'
48
+ | 'constitutional_foundation';
49
+
50
+ /**
51
+ * Human-readable titles for each required section key.
52
+ */
53
+ export const SOUL_SECTION_TITLES: Record<SoulSectionKey, string> = {
54
+ who_we_are: 'Who We Are',
55
+ why_we_exist: 'Why We Exist',
56
+ what_we_believe: 'What We Believe',
57
+ what_we_will_never_do: 'What We Will Never Do',
58
+ what_we_owe_the_world: 'What We Owe the World',
59
+ what_we_owe_each_other: 'What We Owe Each Other',
60
+ founding_intention: 'The Founding Intention',
61
+ self_committed_swarms: 'Self Committed Swarms',
62
+ constitutional_foundation: 'Constitutional Foundation',
63
+ } as const;
64
+
65
+ /**
66
+ * Ordered list of required section keys (canonical ordering in SOUL.md).
67
+ */
68
+ export const REQUIRED_SECTION_KEYS: readonly SoulSectionKey[] = [
69
+ 'who_we_are',
70
+ 'why_we_exist',
71
+ 'what_we_believe',
72
+ 'what_we_will_never_do',
73
+ 'what_we_owe_the_world',
74
+ 'what_we_owe_each_other',
75
+ 'founding_intention',
76
+ 'self_committed_swarms',
77
+ 'constitutional_foundation',
78
+ ] as const;
79
+
80
+ // ---------------------------------------------------------------------------
81
+ // Core interfaces
82
+ // ---------------------------------------------------------------------------
83
+
84
+ /**
85
+ * A single section of a SOUL.md document.
86
+ */
87
+ export interface SoulSection {
88
+ /** Human-readable section title (e.g. "Who We Are") */
89
+ title: string;
90
+
91
+ /** The markdown content of this section (body text, lists, etc.) */
92
+ content: string;
93
+
94
+ /**
95
+ * Whether this section is constitutionally immutable.
96
+ * Immutable sections cannot be modified after initial publication
97
+ * without invalidating the on-chain ERC-8004 anchor.
98
+ */
99
+ immutable: boolean;
100
+ }
101
+
102
+ /**
103
+ * A complete SOUL.md document — the agent's constitutional identity passport.
104
+ *
105
+ * Contains exactly 9 required sections that declare the agent's identity,
106
+ * beliefs, constraints, and constitutional foundation.
107
+ */
108
+ export interface SoulDocument {
109
+ /** SOUL format version */
110
+ soul_version: '1.0';
111
+
112
+ /** Agent or organisation name */
113
+ agent_name: string;
114
+
115
+ /** Agent DID (e.g. "did:kognai:harvey") */
116
+ agent_did: string;
117
+
118
+ /** ISO 8601 timestamp of when this SOUL.md was created */
119
+ created_at: Timestamp;
120
+
121
+ /** ISO 8601 timestamp of the most recent update */
122
+ updated_at: Timestamp;
123
+
124
+ // --- The 9 required sections ---
125
+
126
+ who_we_are: SoulSection;
127
+ why_we_exist: SoulSection;
128
+ what_we_believe: SoulSection;
129
+ what_we_will_never_do: SoulSection;
130
+ what_we_owe_the_world: SoulSection;
131
+ what_we_owe_each_other: SoulSection;
132
+ founding_intention: SoulSection;
133
+ self_committed_swarms: SoulSection;
134
+ constitutional_foundation: SoulSection;
135
+
136
+ /** Optional ERC-8004 on-chain anchor metadata */
137
+ erc8004_anchor?: ERC8004Anchor;
25
138
  }
26
139
 
27
- /** A kill switch — a hard-stop trigger that halts an agent unconditionally */
28
- export interface KillSwitch {
29
- id: string;
30
- name: string;
31
- /** Human-readable trigger condition */
32
- triggerCondition: string;
33
- /** What to do when triggered */
34
- action: 'halt' | 'pause' | 'alert';
35
- /** Cannot be delegated away or overridden */
36
- nonNegotiable: true;
140
+ /**
141
+ * ERC-8004 on-chain anchor for a SOUL.md document.
142
+ *
143
+ * SHA-256(SOUL.md) is committed on-chain as an identity token.
144
+ * This allows any agent to verify that a SOUL.md has not been
145
+ * tampered with by comparing the local hash against the on-chain value.
146
+ */
147
+ export interface ERC8004Anchor {
148
+ /** ERC-8004 token ID on the identity contract */
149
+ token_id: TokenId;
150
+
151
+ /** SHA-256 hash of the canonical SOUL.md content */
152
+ soul_hash: SHA256Hash;
153
+
154
+ /** Chain ID where the anchor lives (e.g. 8453 for Base) */
155
+ chain_id: ChainId;
156
+
157
+ /** Address of the ERC-8004 identity contract */
158
+ contract_address: EthAddress;
37
159
  }
38
160
 
39
- /** The root constitutional document for an operator */
40
- export interface Constitution {
41
- version: '0.1';
42
- operatorId: string;
43
- /** ISO 8601 */
44
- issuedAt: Timestamp;
45
- constraints: Constraint[];
46
- killSwitches: KillSwitch[];
47
- /** Operator's signature over the constitution */
48
- signature: Signature;
161
+ // ---------------------------------------------------------------------------
162
+ // Validation result
163
+ // ---------------------------------------------------------------------------
164
+
165
+ /**
166
+ * Result of validating a SoulDocument against the SOUL format spec.
167
+ */
168
+ export interface SoulValidationResult {
169
+ /** Whether the document passes all validation checks */
170
+ valid: boolean;
171
+
172
+ /** List of validation errors (empty if valid) */
173
+ errors: string[];
174
+
175
+ /** List of warnings (non-blocking) */
176
+ warnings: string[];
49
177
  }
50
178
 
51
- /** Result of evaluating an action against the constitution */
52
- export interface EvaluationResult {
53
- allowed: boolean;
54
- constraintId: string | null;
55
- enforcementLevel: EnforcementLevel | null;
179
+ /**
180
+ * Result of verifying a SOUL.md against its on-chain ERC-8004 anchor.
181
+ */
182
+ export interface SoulVerificationResult {
183
+ /** Whether the SOUL.md hash matches the on-chain anchor */
184
+ verified: boolean;
185
+
186
+ /** The locally computed SHA-256 hash of the SOUL.md content */
187
+ computed_hash: SHA256Hash;
188
+
189
+ /** The on-chain hash from the ERC-8004 anchor (if available) */
190
+ on_chain_hash: SHA256Hash | null;
191
+
192
+ /** Human-readable explanation */
56
193
  reason: string;
57
- evaluatedAt: Timestamp;
58
194
  }
59
195
 
60
- /** Append-only audit log entry */
61
- export interface AuditEntry {
62
- id: string;
63
- agentId: AgentId;
64
- action: string;
65
- evaluation: EvaluationResult;
66
- timestamp: Timestamp;
196
+ // ---------------------------------------------------------------------------
197
+ // Publisher config
198
+ // ---------------------------------------------------------------------------
199
+
200
+ /**
201
+ * Configuration for SoulPublisher — hosts SOUL.md at /.well-known/soul.md
202
+ */
203
+ export interface SoulPublisherConfig {
204
+ /** Port to listen on (default: 3000) */
205
+ port?: number;
206
+
207
+ /** Hostname to bind to (default: '0.0.0.0') */
208
+ hostname?: string;
209
+
210
+ /** Path to serve SOUL.md at (default: '/.well-known/soul.md') */
211
+ path?: string;
67
212
  }