@cleocode/contracts 2026.4.117 → 2026.4.122

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.
@@ -0,0 +1,204 @@
1
+ /**
2
+ * Wire-format contracts for the NEXUS user_profile SDK operations.
3
+ *
4
+ * These types describe the parameter and result shapes for the five
5
+ * user-profile SDK functions shipped in T1078 (PSYCHE Wave 1). They follow
6
+ * the same contract pattern as the rest of @cleocode/contracts/operations/.
7
+ *
8
+ * Operations:
9
+ * nexus.profile.view — query — list all traits (with optional confidence filter)
10
+ * nexus.profile.get — query — fetch a single trait by key
11
+ * nexus.profile.import — mutate — import from user_profile.json
12
+ * nexus.profile.export — mutate — export to user_profile.json
13
+ * nexus.profile.reinforce — mutate — increment reinforcement for a trait
14
+ * nexus.profile.upsert — mutate — create-or-update a single trait
15
+ * nexus.profile.supersede — mutate — mark one trait as superseded by another
16
+ *
17
+ * @task T1078
18
+ * @task T1079
19
+ * @task T1080
20
+ * @epic T1076
21
+ */
22
+
23
+ // ============================================================================
24
+ // Shared domain types
25
+ // ============================================================================
26
+
27
+ /**
28
+ * A single user-profile trait record.
29
+ *
30
+ * This is the canonical in-memory / wire shape for all profile operations.
31
+ * The corresponding SQLite row type is `UserProfileRow` in
32
+ * `packages/core/src/store/nexus-schema.ts`.
33
+ */
34
+ export interface UserProfileTrait {
35
+ /** Stable semantic key, e.g. "prefers-zero-deps" or "verbose-git-logs". */
36
+ traitKey: string;
37
+ /** JSON-encoded value (string, number, boolean, or serialised object). */
38
+ traitValue: string;
39
+ /** Bayesian confidence in [0.0, 1.0]. */
40
+ confidence: number;
41
+ /**
42
+ * Origin of this observation. Convention:
43
+ * "dialectic:<sessionId>" — derived by the Dialectic Evaluator (Wave 3)
44
+ * "import:user_profile.json" — loaded from a portable profile export
45
+ * "manual" — set directly via CLI reinforce command
46
+ */
47
+ source: string;
48
+ /**
49
+ * Soft FK to a future session_messages.id.
50
+ * Null until Wave 5 (T1145) ships the session_messages table.
51
+ */
52
+ derivedFromMessageId: string | null;
53
+ /** ISO 8601 string when the trait was first observed. */
54
+ firstObservedAt: string;
55
+ /** ISO 8601 string of the most recent reinforcement event. */
56
+ lastReinforcedAt: string;
57
+ /** Number of times this trait has been confirmed (starts at 1). */
58
+ reinforcementCount: number;
59
+ /**
60
+ * traitKey of the superseding trait, or null if still active.
61
+ * Set by `supersedeTrait` (T1139 supersession graph prep).
62
+ */
63
+ supersededBy: string | null;
64
+ }
65
+
66
+ // ============================================================================
67
+ // Query: nexus.profile.view
68
+ // ============================================================================
69
+
70
+ /** Parameters for `nexus.profile.view`. */
71
+ export interface NexusProfileViewParams {
72
+ /** Only return traits with confidence >= this value. Default: 0.0 (all). */
73
+ minConfidence?: number;
74
+ }
75
+
76
+ /** Result of `nexus.profile.view`. */
77
+ export interface NexusProfileViewResult {
78
+ /** All matching traits, ordered by confidence desc, then traitKey asc. */
79
+ traits: UserProfileTrait[];
80
+ /** Total count of traits returned. */
81
+ count: number;
82
+ }
83
+
84
+ // ============================================================================
85
+ // Query: nexus.profile.get
86
+ // ============================================================================
87
+
88
+ /** Parameters for `nexus.profile.get`. */
89
+ export interface NexusProfileGetParams {
90
+ /** Trait key to retrieve (required). */
91
+ traitKey: string;
92
+ }
93
+
94
+ /** Result of `nexus.profile.get`. */
95
+ export interface NexusProfileGetResult {
96
+ /** The trait, or null when not found. */
97
+ trait: UserProfileTrait | null;
98
+ }
99
+
100
+ // ============================================================================
101
+ // Mutate: nexus.profile.import
102
+ // ============================================================================
103
+
104
+ /** Parameters for `nexus.profile.import`. */
105
+ export interface NexusProfileImportParams {
106
+ /**
107
+ * Absolute path to the JSON file to import.
108
+ * Defaults to `~/.cleo/user_profile.json` when omitted.
109
+ */
110
+ path?: string;
111
+ }
112
+
113
+ /** Result of `nexus.profile.import`. */
114
+ export interface NexusProfileImportResult {
115
+ /** Number of traits successfully upserted. */
116
+ imported: number;
117
+ /** Number of traits skipped due to conflict resolution (lower confidence). */
118
+ skipped: number;
119
+ /** Number of traits where the incoming entry superseded the existing one. */
120
+ superseded: number;
121
+ }
122
+
123
+ // ============================================================================
124
+ // Mutate: nexus.profile.export
125
+ // ============================================================================
126
+
127
+ /** Parameters for `nexus.profile.export`. */
128
+ export interface NexusProfileExportParams {
129
+ /**
130
+ * Absolute path for the output JSON file.
131
+ * Defaults to `~/.cleo/user_profile.json` when omitted.
132
+ */
133
+ path?: string;
134
+ }
135
+
136
+ /** Result of `nexus.profile.export`. */
137
+ export interface NexusProfileExportResult {
138
+ /** Absolute path the file was written to. */
139
+ path: string;
140
+ /** Number of traits written. */
141
+ count: number;
142
+ }
143
+
144
+ // ============================================================================
145
+ // Mutate: nexus.profile.reinforce
146
+ // ============================================================================
147
+
148
+ /** Parameters for `nexus.profile.reinforce`. */
149
+ export interface NexusProfileReinforceParams {
150
+ /** Key of the trait to reinforce (required). */
151
+ traitKey: string;
152
+ /**
153
+ * Source identifier for this reinforcement event.
154
+ * Defaults to "manual" when called from the CLI.
155
+ */
156
+ source?: string;
157
+ }
158
+
159
+ /** Result of `nexus.profile.reinforce`. */
160
+ export interface NexusProfileReinforceResult {
161
+ /** New reinforcement count after this event. */
162
+ reinforcementCount: number;
163
+ /** Updated confidence after this event. */
164
+ confidence: number;
165
+ }
166
+
167
+ // ============================================================================
168
+ // Mutate: nexus.profile.upsert
169
+ // ============================================================================
170
+
171
+ /** Parameters for `nexus.profile.upsert`. */
172
+ export interface NexusProfileUpsertParams {
173
+ /** Trait to create or update (required). */
174
+ trait: Pick<
175
+ UserProfileTrait,
176
+ 'traitKey' | 'traitValue' | 'confidence' | 'source' | 'derivedFromMessageId'
177
+ >;
178
+ }
179
+
180
+ /** Result of `nexus.profile.upsert`. */
181
+ export interface NexusProfileUpsertResult {
182
+ /** Whether a new row was created (true) or an existing row was updated (false). */
183
+ created: boolean;
184
+ }
185
+
186
+ // ============================================================================
187
+ // Mutate: nexus.profile.supersede
188
+ // ============================================================================
189
+
190
+ /** Parameters for `nexus.profile.supersede`. */
191
+ export interface NexusProfileSupersedeParams {
192
+ /** The trait key that is being deprecated. */
193
+ oldKey: string;
194
+ /** The trait key that replaces it. */
195
+ newKey: string;
196
+ }
197
+
198
+ /** Result of `nexus.profile.supersede`. */
199
+ export interface NexusProfileSupersedeResult {
200
+ /** Old trait key (now has supersededBy set). */
201
+ oldKey: string;
202
+ /** New trait key (the superseding trait). */
203
+ newKey: string;
204
+ }