@cleocode/contracts 2026.4.116 → 2026.4.121

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,155 @@
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
+ * A single user-profile trait record.
24
+ *
25
+ * This is the canonical in-memory / wire shape for all profile operations.
26
+ * The corresponding SQLite row type is `UserProfileRow` in
27
+ * `packages/core/src/store/nexus-schema.ts`.
28
+ */
29
+ export interface UserProfileTrait {
30
+ /** Stable semantic key, e.g. "prefers-zero-deps" or "verbose-git-logs". */
31
+ traitKey: string;
32
+ /** JSON-encoded value (string, number, boolean, or serialised object). */
33
+ traitValue: string;
34
+ /** Bayesian confidence in [0.0, 1.0]. */
35
+ confidence: number;
36
+ /**
37
+ * Origin of this observation. Convention:
38
+ * "dialectic:<sessionId>" — derived by the Dialectic Evaluator (Wave 3)
39
+ * "import:user_profile.json" — loaded from a portable profile export
40
+ * "manual" — set directly via CLI reinforce command
41
+ */
42
+ source: string;
43
+ /**
44
+ * Soft FK to a future session_messages.id.
45
+ * Null until Wave 5 (T1145) ships the session_messages table.
46
+ */
47
+ derivedFromMessageId: string | null;
48
+ /** ISO 8601 string when the trait was first observed. */
49
+ firstObservedAt: string;
50
+ /** ISO 8601 string of the most recent reinforcement event. */
51
+ lastReinforcedAt: string;
52
+ /** Number of times this trait has been confirmed (starts at 1). */
53
+ reinforcementCount: number;
54
+ /**
55
+ * traitKey of the superseding trait, or null if still active.
56
+ * Set by `supersedeTrait` (T1139 supersession graph prep).
57
+ */
58
+ supersededBy: string | null;
59
+ }
60
+ /** Parameters for `nexus.profile.view`. */
61
+ export interface NexusProfileViewParams {
62
+ /** Only return traits with confidence >= this value. Default: 0.0 (all). */
63
+ minConfidence?: number;
64
+ }
65
+ /** Result of `nexus.profile.view`. */
66
+ export interface NexusProfileViewResult {
67
+ /** All matching traits, ordered by confidence desc, then traitKey asc. */
68
+ traits: UserProfileTrait[];
69
+ /** Total count of traits returned. */
70
+ count: number;
71
+ }
72
+ /** Parameters for `nexus.profile.get`. */
73
+ export interface NexusProfileGetParams {
74
+ /** Trait key to retrieve (required). */
75
+ traitKey: string;
76
+ }
77
+ /** Result of `nexus.profile.get`. */
78
+ export interface NexusProfileGetResult {
79
+ /** The trait, or null when not found. */
80
+ trait: UserProfileTrait | null;
81
+ }
82
+ /** Parameters for `nexus.profile.import`. */
83
+ export interface NexusProfileImportParams {
84
+ /**
85
+ * Absolute path to the JSON file to import.
86
+ * Defaults to `~/.cleo/user_profile.json` when omitted.
87
+ */
88
+ path?: string;
89
+ }
90
+ /** Result of `nexus.profile.import`. */
91
+ export interface NexusProfileImportResult {
92
+ /** Number of traits successfully upserted. */
93
+ imported: number;
94
+ /** Number of traits skipped due to conflict resolution (lower confidence). */
95
+ skipped: number;
96
+ /** Number of traits where the incoming entry superseded the existing one. */
97
+ superseded: number;
98
+ }
99
+ /** Parameters for `nexus.profile.export`. */
100
+ export interface NexusProfileExportParams {
101
+ /**
102
+ * Absolute path for the output JSON file.
103
+ * Defaults to `~/.cleo/user_profile.json` when omitted.
104
+ */
105
+ path?: string;
106
+ }
107
+ /** Result of `nexus.profile.export`. */
108
+ export interface NexusProfileExportResult {
109
+ /** Absolute path the file was written to. */
110
+ path: string;
111
+ /** Number of traits written. */
112
+ count: number;
113
+ }
114
+ /** Parameters for `nexus.profile.reinforce`. */
115
+ export interface NexusProfileReinforceParams {
116
+ /** Key of the trait to reinforce (required). */
117
+ traitKey: string;
118
+ /**
119
+ * Source identifier for this reinforcement event.
120
+ * Defaults to "manual" when called from the CLI.
121
+ */
122
+ source?: string;
123
+ }
124
+ /** Result of `nexus.profile.reinforce`. */
125
+ export interface NexusProfileReinforceResult {
126
+ /** New reinforcement count after this event. */
127
+ reinforcementCount: number;
128
+ /** Updated confidence after this event. */
129
+ confidence: number;
130
+ }
131
+ /** Parameters for `nexus.profile.upsert`. */
132
+ export interface NexusProfileUpsertParams {
133
+ /** Trait to create or update (required). */
134
+ trait: Pick<UserProfileTrait, 'traitKey' | 'traitValue' | 'confidence' | 'source' | 'derivedFromMessageId'>;
135
+ }
136
+ /** Result of `nexus.profile.upsert`. */
137
+ export interface NexusProfileUpsertResult {
138
+ /** Whether a new row was created (true) or an existing row was updated (false). */
139
+ created: boolean;
140
+ }
141
+ /** Parameters for `nexus.profile.supersede`. */
142
+ export interface NexusProfileSupersedeParams {
143
+ /** The trait key that is being deprecated. */
144
+ oldKey: string;
145
+ /** The trait key that replaces it. */
146
+ newKey: string;
147
+ }
148
+ /** Result of `nexus.profile.supersede`. */
149
+ export interface NexusProfileSupersedeResult {
150
+ /** Old trait key (now has supersededBy set). */
151
+ oldKey: string;
152
+ /** New trait key (the superseding trait). */
153
+ newKey: string;
154
+ }
155
+ //# sourceMappingURL=nexus-user-profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexus-user-profile.d.ts","sourceRoot":"","sources":["../../src/operations/nexus-user-profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,yDAAyD;IACzD,eAAe,EAAE,MAAM,CAAC;IACxB,8DAA8D;IAC9D,gBAAgB,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAMD,2CAA2C;AAC3C,MAAM,WAAW,sBAAsB;IACrC,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,sCAAsC;AACtC,MAAM,WAAW,sBAAsB;IACrC,0EAA0E;IAC1E,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;CACf;AAMD,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IACpC,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qCAAqC;AACrC,MAAM,WAAW,qBAAqB;IACpC,yCAAyC;IACzC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAChC;AAMD,6CAA6C;AAC7C,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wCAAwC;AACxC,MAAM,WAAW,wBAAwB;IACvC,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,UAAU,EAAE,MAAM,CAAC;CACpB;AAMD,6CAA6C;AAC7C,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wCAAwC;AACxC,MAAM,WAAW,wBAAwB;IACvC,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,KAAK,EAAE,MAAM,CAAC;CACf;AAMD,gDAAgD;AAChD,MAAM,WAAW,2BAA2B;IAC1C,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,2CAA2C;AAC3C,MAAM,WAAW,2BAA2B;IAC1C,gDAAgD;IAChD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB;AAMD,6CAA6C;AAC7C,MAAM,WAAW,wBAAwB;IACvC,4CAA4C;IAC5C,KAAK,EAAE,IAAI,CACT,gBAAgB,EAChB,UAAU,GAAG,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,sBAAsB,CAC7E,CAAC;CACH;AAED,wCAAwC;AACxC,MAAM,WAAW,wBAAwB;IACvC,mFAAmF;IACnF,OAAO,EAAE,OAAO,CAAC;CAClB;AAMD,gDAAgD;AAChD,MAAM,WAAW,2BAA2B;IAC1C,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,2CAA2C;AAC3C,MAAM,WAAW,2BAA2B;IAC1C,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;CAChB"}
@@ -0,0 +1,23 @@
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
+ export {};
23
+ //# sourceMappingURL=nexus-user-profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nexus-user-profile.js","sourceRoot":"","sources":["../../src/operations/nexus-user-profile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Worktree backend SDK operation types (T1161).
3
3
  *
4
- * Wire-format types for the `@cleocode/worktree-backend` SDK surface.
4
+ * Wire-format types for the `@cleocode/worktree` SDK surface.
5
5
  * Defines the contract for createWorktree, destroyWorktree, listWorktrees,
6
6
  * and pruneWorktrees operations with XDG path canon (D029) and declarative
7
7
  * hooks (D030 native lift of worktrunk missing features).
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Worktree backend SDK operation types (T1161).
3
3
  *
4
- * Wire-format types for the `@cleocode/worktree-backend` SDK surface.
4
+ * Wire-format types for the `@cleocode/worktree` SDK surface.
5
5
  * Defines the contract for createWorktree, destroyWorktree, listWorktrees,
6
6
  * and pruneWorktrees operations with XDG path canon (D029) and declarative
7
7
  * hooks (D030 native lift of worktrunk missing features).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleocode/contracts",
3
- "version": "2026.4.116",
3
+ "version": "2026.4.121",
4
4
  "description": "Domain types, interfaces, and contracts for the CLEO ecosystem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/index.ts CHANGED
@@ -435,8 +435,49 @@ export type {
435
435
  WikiStateFile,
436
436
  WikiSymbolRow,
437
437
  } from './nexus-wiki-ops.js';
438
+ // Dialectic Evaluator operation types (T1087 Wave 3)
439
+ export type {
440
+ ApplyInsightsParams,
441
+ ApplyInsightsResult,
442
+ DialecticInsights,
443
+ DialecticTurn,
444
+ EvaluateDialecticParams,
445
+ EvaluateDialecticResult,
446
+ } from './operations/dialectic.js';
438
447
  // === Operations Types (API wire format, namespaced to avoid collision with domain types) ===
439
448
  export * as ops from './operations/index.js';
449
+ // Multi-pass retrieval bundle types (PSYCHE Wave 4 · T1090)
450
+ export type {
451
+ PassMask,
452
+ RetrievalActiveTask,
453
+ RetrievalBundle,
454
+ RetrievalDecision,
455
+ RetrievalLearning,
456
+ RetrievalObservation,
457
+ RetrievalPattern,
458
+ RetrievalRequest,
459
+ RetrievalTokenCounts,
460
+ } from './operations/memory.js';
461
+ // === NEXUS User Profile Types (T1076 PSYCHE Wave 1) ===
462
+ // Re-exported at top level so @cleocode/core/nexus and CLI dispatch can
463
+ // import without the `ops.` namespace hop.
464
+ export type {
465
+ NexusProfileExportParams,
466
+ NexusProfileExportResult,
467
+ NexusProfileGetParams,
468
+ NexusProfileGetResult,
469
+ NexusProfileImportParams,
470
+ NexusProfileImportResult,
471
+ NexusProfileReinforceParams,
472
+ NexusProfileReinforceResult,
473
+ NexusProfileSupersedeParams,
474
+ NexusProfileSupersedeResult,
475
+ NexusProfileUpsertParams,
476
+ NexusProfileUpsertResult,
477
+ NexusProfileViewParams,
478
+ NexusProfileViewResult,
479
+ UserProfileTrait,
480
+ } from './operations/nexus-user-profile.js';
440
481
  // Commonly used ops types re-exported at top level for convenience
441
482
  export type { BrainState } from './operations/orchestrate.js';
442
483
  // ParamDef contract — re-exported at top level (SSoT for all operation param descriptors)
@@ -494,7 +535,7 @@ export type {
494
535
  VariableResolver,
495
536
  } from './operations/variable-substitution.js';
496
537
  // === Worktree Backend SDK Types (T1161) ===
497
- // Re-exported at top level so @cleocode/worktree-backend and callers can
538
+ // Re-exported at top level so @cleocode/worktree and callers can
498
539
  // import without the `ops.` namespace hop.
499
540
  export type {
500
541
  CreateWorktreeOptions,
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Wire-format contracts for the Dialectic Evaluator SDK operations.
3
+ *
4
+ * Exported types describe the parameter and result shapes for the
5
+ * two primary dialectic evaluation functions shipped in T1087 (PSYCHE Wave 3).
6
+ * They follow the same contract pattern as the rest of @cleocode/contracts/operations/.
7
+ *
8
+ * Operations:
9
+ * evaluateDialectic — analyse a single user↔system turn and extract insights
10
+ * applyInsights — persist extracted insights to nexus.db and brain.db
11
+ *
12
+ * Design constraints (ADR-055 / D028 boundary rules):
13
+ * - Lives in `packages/contracts/` — ZERO runtime dependencies.
14
+ * - Consumed by `packages/core/src/memory/dialectic-evaluator.ts` and the CQRS
15
+ * dispatcher hook in `packages/cleo/src/dispatch/dispatcher.ts`.
16
+ * - No cross-package relative imports.
17
+ *
18
+ * @task T1087
19
+ * @task T1088
20
+ * @epic T1082
21
+ */
22
+
23
+ // ============================================================================
24
+ // Core domain types
25
+ // ============================================================================
26
+
27
+ /**
28
+ * A single conversational turn passed to the Dialectic Evaluator.
29
+ *
30
+ * Represents one exchange between a user and the system. Both sides are
31
+ * required so the evaluator can reason about what was asked, what the system
32
+ * inferred, and whether any behavioural traits or session-level insights can
33
+ * be extracted.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const turn: DialecticTurn = {
38
+ * userMessage: "always reuse existing helpers before creating new ones",
39
+ * systemResponse: "understood — I found `buildRetrievalBundle` which covers your case.",
40
+ * activePeerId: "cleo-prime",
41
+ * sessionId: "ses_20260422131135_5149eb",
42
+ * };
43
+ * ```
44
+ */
45
+ export interface DialecticTurn {
46
+ /** Raw text of the user's message in this turn. */
47
+ userMessage: string;
48
+ /** Raw text of the system's response in this turn. */
49
+ systemResponse: string;
50
+ /**
51
+ * The CANT agent peer ID that is active for this turn.
52
+ * Matches `PeerIdentity.peerId` from `packages/contracts/src/peer.ts`.
53
+ * Defaults to `"global"` when no peer context is available.
54
+ */
55
+ activePeerId: string;
56
+ /** Session ID from the CLEO session store (e.g. `ses_20260422131135_5149eb`). */
57
+ sessionId: string;
58
+ }
59
+
60
+ /**
61
+ * Structured insights extracted from a single dialectic turn.
62
+ *
63
+ * The Dialectic Evaluator populates this after analysing a conversational turn.
64
+ * It is then consumed by `applyInsights` to route each sub-array to the
65
+ * correct storage backend.
66
+ *
67
+ * Routing summary:
68
+ * - `globalTraits` → `upsertUserProfileTrait` (nexus.db user_profile table)
69
+ * - `peerInsights` → `observeBrain` with `peerId` set + source `"dialectic:<sessionId>"`
70
+ * - `sessionNarrativeDelta` → `appendNarrativeDelta` in session-narrative.ts
71
+ */
72
+ export interface DialecticInsights {
73
+ /**
74
+ * User-level behavioural traits extracted from the turn.
75
+ *
76
+ * These are global, session-independent facts about the user — e.g.
77
+ * "prefers-zero-deps", "verbose-git-logs". Persisted to the user_profile
78
+ * table in nexus.db via `upsertUserProfileTrait` (Wave 1).
79
+ */
80
+ globalTraits: Array<{
81
+ /** Stable semantic key for the trait (kebab-case). */
82
+ key: string;
83
+ /** JSON-serialisable value string. */
84
+ value: string;
85
+ /** Bayesian confidence in [0.0, 1.0]. */
86
+ confidence: number;
87
+ }>;
88
+
89
+ /**
90
+ * Peer-scoped insights relevant only to the active CANT agent.
91
+ *
92
+ * Persisted to brain.db via `observeBrain` with the `peerId` field set
93
+ * to the originating peer and `sourceType` set to `"dialectic"`.
94
+ */
95
+ peerInsights: Array<{
96
+ /** Observation key or short title. */
97
+ key: string;
98
+ /** Observation detail text (max ~300 chars). */
99
+ value: string;
100
+ /** Peer the insight belongs to (copied from `DialecticTurn.activePeerId`). */
101
+ peerId: string;
102
+ /** Bayesian confidence in [0.0, 1.0]. */
103
+ confidence: number;
104
+ }>;
105
+
106
+ /**
107
+ * Short narrative description of what happened in this turn.
108
+ *
109
+ * Appended to the rolling `session_narrative` table via `appendNarrativeDelta`.
110
+ * Omit (or leave undefined) when the turn has no meaningful narrative content
111
+ * (e.g. short ack messages).
112
+ *
113
+ * Max length: 500 chars.
114
+ */
115
+ sessionNarrativeDelta?: string;
116
+ }
117
+
118
+ // ============================================================================
119
+ // Params / Result types (for registry-driven dispatch surface)
120
+ // ============================================================================
121
+
122
+ /**
123
+ * Parameters for the `evaluateDialectic` SDK function.
124
+ *
125
+ * Wraps `DialecticTurn` in the standard params envelope so that the operation
126
+ * can be registered in the dispatch registry if needed in the future.
127
+ */
128
+ export interface EvaluateDialecticParams {
129
+ /** The conversational turn to evaluate. */
130
+ turn: DialecticTurn;
131
+ }
132
+
133
+ /**
134
+ * Result returned by `evaluateDialectic`.
135
+ *
136
+ * Contains the extracted insights ready for downstream persistence.
137
+ */
138
+ export interface EvaluateDialecticResult {
139
+ /** Extracted insights from the evaluated turn. */
140
+ insights: DialecticInsights;
141
+ /** Name of the LLM backend that was used, or `"stub"` when no backend was available. */
142
+ backend: 'anthropic' | 'ollama' | 'transformers' | 'stub';
143
+ }
144
+
145
+ /**
146
+ * Parameters for the `applyInsights` SDK function.
147
+ */
148
+ export interface ApplyInsightsParams {
149
+ /** Insights to persist (produced by `evaluateDialectic`). */
150
+ insights: DialecticInsights;
151
+ /** Session ID used to build the `dialectic:<sessionId>` source tag. */
152
+ sessionId: string;
153
+ /** The CANT agent peer ID that produced these insights. */
154
+ activePeerId: string;
155
+ }
156
+
157
+ /**
158
+ * Result returned by `applyInsights`.
159
+ */
160
+ export interface ApplyInsightsResult {
161
+ /** Number of global traits upserted to nexus.db user_profile. */
162
+ globalTraitsApplied: number;
163
+ /** Number of peer insights stored to brain.db. */
164
+ peerInsightsApplied: number;
165
+ /** Whether a session narrative entry was written. */
166
+ narrativeDeltaApplied: boolean;
167
+ }
@@ -11,6 +11,7 @@ export * from './issues.js';
11
11
  export * from './lifecycle.js';
12
12
  export * from './memory.js';
13
13
  export * from './nexus.js';
14
+ export * from './nexus-user-profile.js';
14
15
  export * from './orchestrate.js';
15
16
  export * from './params.js';
16
17
  export * from './release.js';
@@ -1038,6 +1038,186 @@ export interface MemoryPromoteExplainResult {
1038
1038
  scoreBreakdown: MemoryPromoteScoreBreakdown;
1039
1039
  }
1040
1040
 
1041
+ // ============================================================================
1042
+ // Multi-Pass Retrieval Bundle (PSYCHE Wave 4 · T1090)
1043
+ // ============================================================================
1044
+
1045
+ /**
1046
+ * Controls which passes are executed in `buildRetrievalBundle`.
1047
+ *
1048
+ * When all fields are `true` (the default), all three passes run in parallel.
1049
+ * Set individual passes to `false` to skip them for token-budget optimisation.
1050
+ */
1051
+ export interface PassMask {
1052
+ /** Cold pass: user-profile traits + peer instructions from NEXUS. */
1053
+ cold: boolean;
1054
+ /** Warm pass: peer-scoped learnings, patterns, and decisions from BRAIN. */
1055
+ warm: boolean;
1056
+ /** Hot pass: session narrative + recent observations + active tasks. */
1057
+ hot: boolean;
1058
+ }
1059
+
1060
+ /**
1061
+ * Input to `buildRetrievalBundle`.
1062
+ *
1063
+ * All four fields are required; pass an empty string for `query` when no
1064
+ * user-provided search term is available.
1065
+ */
1066
+ export interface RetrievalRequest {
1067
+ /** CANT peer identifier, e.g. `"cleo-prime"` or `"global"`. */
1068
+ peerId: string;
1069
+ /** Active session identifier. */
1070
+ sessionId: string;
1071
+ /** Optional user-query used to scope warm-pass memory search. */
1072
+ query?: string;
1073
+ /**
1074
+ * Which passes to execute. Defaults to `{ cold: true, warm: true, hot: true }`.
1075
+ */
1076
+ passMask?: PassMask;
1077
+ /**
1078
+ * Token budget for the bundle (default: 4000).
1079
+ * Split 20 / 50 / 30 across cold / warm / hot.
1080
+ * When total exceeds budget, hot pass is trimmed first.
1081
+ */
1082
+ tokenBudget?: number;
1083
+ }
1084
+
1085
+ /**
1086
+ * Compact task record returned by the hot pass.
1087
+ *
1088
+ * A narrow projection of the full `Task` type — only the fields needed for
1089
+ * briefing context are included to keep token cost low.
1090
+ */
1091
+ export interface RetrievalActiveTask {
1092
+ /** Task identifier (e.g. `"T1090"`). */
1093
+ id: string;
1094
+ /** Task title. */
1095
+ title: string;
1096
+ /** Current lifecycle status. */
1097
+ status: string;
1098
+ }
1099
+
1100
+ /**
1101
+ * Compact observation record returned by the hot pass.
1102
+ *
1103
+ * A narrow projection of a `brain_observations` row — only the display fields.
1104
+ */
1105
+ export interface RetrievalObservation {
1106
+ /** Observation identifier (e.g. `"O-abc123"`). */
1107
+ id: string;
1108
+ /** Short display title. */
1109
+ title: string;
1110
+ /** Full narrative text. */
1111
+ narrative: string;
1112
+ /** ISO 8601 creation timestamp. */
1113
+ createdAt: string;
1114
+ }
1115
+
1116
+ /**
1117
+ * Compact learning record returned by the warm pass.
1118
+ */
1119
+ export interface RetrievalLearning {
1120
+ /** Learning identifier (e.g. `"L-def456"`). */
1121
+ id: string;
1122
+ /** Insight text. */
1123
+ insight: string;
1124
+ /** ISO 8601 creation timestamp. */
1125
+ createdAt: string;
1126
+ }
1127
+
1128
+ /**
1129
+ * Compact pattern record returned by the warm pass.
1130
+ */
1131
+ export interface RetrievalPattern {
1132
+ /** Pattern identifier (e.g. `"P-ghi789"`). */
1133
+ id: string;
1134
+ /** Pattern text. */
1135
+ pattern: string;
1136
+ /** ISO 8601 extraction timestamp. */
1137
+ extractedAt: string;
1138
+ }
1139
+
1140
+ /**
1141
+ * Compact decision record returned by the warm pass.
1142
+ */
1143
+ export interface RetrievalDecision {
1144
+ /** Decision identifier (e.g. `"D-jkl012"`). */
1145
+ id: string;
1146
+ /** Decision statement. */
1147
+ decision: string;
1148
+ /** ISO 8601 creation timestamp. */
1149
+ createdAt: string;
1150
+ }
1151
+
1152
+ /**
1153
+ * Token-budget accounting for the three retrieval passes.
1154
+ */
1155
+ export interface RetrievalTokenCounts {
1156
+ /** Estimated tokens consumed by the cold pass. */
1157
+ cold: number;
1158
+ /** Estimated tokens consumed by the warm pass. */
1159
+ warm: number;
1160
+ /** Estimated tokens consumed by the hot pass. */
1161
+ hot: number;
1162
+ /** Sum of cold + warm + hot. */
1163
+ total: number;
1164
+ }
1165
+
1166
+ /**
1167
+ * Structured context bundle returned by `buildRetrievalBundle`.
1168
+ *
1169
+ * Three passes correspond to three temporal + topical distances:
1170
+ *
1171
+ * - **cold**: stable identity context (user profile + peer instructions)
1172
+ * - **warm**: recent project memory scoped to this peer (learnings, patterns, decisions)
1173
+ * - **hot**: live session state (narrative + recent observations + active tasks)
1174
+ *
1175
+ * @task T1090
1176
+ * @epic T1083
1177
+ */
1178
+ export interface RetrievalBundle {
1179
+ /**
1180
+ * Cold pass — identity + stable context.
1181
+ *
1182
+ * `userProfile` contains the user's known preferences and traits at
1183
+ * >= 0.5 confidence. `peerInstructions` is a brief instruction string
1184
+ * derived from the peer's CANT definition (empty string when unavailable).
1185
+ */
1186
+ cold: {
1187
+ userProfile: import('./nexus-user-profile.js').UserProfileTrait[];
1188
+ peerInstructions: string;
1189
+ };
1190
+
1191
+ /**
1192
+ * Warm pass — peer-scoped project memory.
1193
+ *
1194
+ * All entries are filtered to `peer_id = peerId OR peer_id = 'global'`
1195
+ * so each peer sees its own memory plus the shared global pool.
1196
+ */
1197
+ warm: {
1198
+ peerLearnings: RetrievalLearning[];
1199
+ peerPatterns: RetrievalPattern[];
1200
+ decisions: RetrievalDecision[];
1201
+ };
1202
+
1203
+ /**
1204
+ * Hot pass — live session state.
1205
+ *
1206
+ * `sessionNarrative` is the rolling prose summary from `session_narrative`
1207
+ * (empty string when no narrative has been recorded yet).
1208
+ * `recentObservations` are the last N observations created in this session.
1209
+ * `activeTasks` are tasks with status `active` or `in_progress`.
1210
+ */
1211
+ hot: {
1212
+ sessionNarrative: string;
1213
+ recentObservations: RetrievalObservation[];
1214
+ activeTasks: RetrievalActiveTask[];
1215
+ };
1216
+
1217
+ /** Per-pass and total token-budget accounting. */
1218
+ tokenCounts: RetrievalTokenCounts;
1219
+ }
1220
+
1041
1221
  // ============================================================================
1042
1222
  // Paginated result helper (for HTTP list surfaces that opt into LAFSPage)
1043
1223
  // ============================================================================