@cleocode/contracts 2026.4.100 → 2026.4.102

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.
Files changed (96) hide show
  1. package/dist/brain-graph.d.ts +245 -0
  2. package/dist/brain-graph.d.ts.map +1 -0
  3. package/dist/brain-graph.js +30 -0
  4. package/dist/brain-graph.js.map +1 -0
  5. package/dist/branch-lock.d.ts +225 -0
  6. package/dist/branch-lock.d.ts.map +1 -0
  7. package/dist/branch-lock.js +43 -0
  8. package/dist/branch-lock.js.map +1 -0
  9. package/dist/exit-codes.d.ts +1 -1
  10. package/dist/exit-codes.d.ts.map +1 -1
  11. package/dist/exit-codes.js +1 -1
  12. package/dist/exit-codes.js.map +1 -1
  13. package/dist/graph.d.ts +2 -0
  14. package/dist/graph.d.ts.map +1 -1
  15. package/dist/index.d.ts +11 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/nexus-contract-ops.d.ts +186 -0
  20. package/dist/nexus-contract-ops.d.ts.map +1 -0
  21. package/dist/nexus-contract-ops.js +11 -0
  22. package/dist/nexus-contract-ops.js.map +1 -0
  23. package/dist/nexus-living-brain-ops.d.ts +314 -0
  24. package/dist/nexus-living-brain-ops.d.ts.map +1 -0
  25. package/dist/nexus-living-brain-ops.js +15 -0
  26. package/dist/nexus-living-brain-ops.js.map +1 -0
  27. package/dist/nexus-query-ops.d.ts +82 -0
  28. package/dist/nexus-query-ops.d.ts.map +1 -0
  29. package/dist/nexus-query-ops.js +11 -0
  30. package/dist/nexus-query-ops.js.map +1 -0
  31. package/dist/nexus-route-ops.d.ts +103 -0
  32. package/dist/nexus-route-ops.d.ts.map +1 -0
  33. package/dist/nexus-route-ops.js +10 -0
  34. package/dist/nexus-route-ops.js.map +1 -0
  35. package/dist/nexus-tasks-bridge-ops.d.ts +68 -0
  36. package/dist/nexus-tasks-bridge-ops.d.ts.map +1 -0
  37. package/dist/nexus-tasks-bridge-ops.js +11 -0
  38. package/dist/nexus-tasks-bridge-ops.js.map +1 -0
  39. package/dist/nexus-wiki-ops.d.ts +127 -0
  40. package/dist/nexus-wiki-ops.d.ts.map +1 -0
  41. package/dist/nexus-wiki-ops.js +12 -0
  42. package/dist/nexus-wiki-ops.js.map +1 -0
  43. package/dist/operations/admin.d.ts +1781 -0
  44. package/dist/operations/admin.d.ts.map +1 -0
  45. package/dist/operations/admin.js +27 -0
  46. package/dist/operations/admin.js.map +1 -0
  47. package/dist/operations/brain.d.ts +34 -26
  48. package/dist/operations/brain.d.ts.map +1 -1
  49. package/dist/operations/brain.js +7 -6
  50. package/dist/operations/brain.js.map +1 -1
  51. package/dist/operations/docs.d.ts +279 -0
  52. package/dist/operations/docs.d.ts.map +1 -0
  53. package/dist/operations/docs.js +31 -0
  54. package/dist/operations/docs.js.map +1 -0
  55. package/dist/operations/intelligence.d.ts +319 -0
  56. package/dist/operations/intelligence.d.ts.map +1 -0
  57. package/dist/operations/intelligence.js +24 -0
  58. package/dist/operations/intelligence.js.map +1 -0
  59. package/dist/operations/orchestrate.d.ts +113 -2
  60. package/dist/operations/orchestrate.d.ts.map +1 -1
  61. package/dist/operations/orchestrate.js +3 -2
  62. package/dist/operations/orchestrate.js.map +1 -1
  63. package/dist/operations/session.d.ts +193 -47
  64. package/dist/operations/session.d.ts.map +1 -1
  65. package/dist/operations/session.js +7 -6
  66. package/dist/operations/session.js.map +1 -1
  67. package/dist/operations/sticky.d.ts +264 -0
  68. package/dist/operations/sticky.d.ts.map +1 -0
  69. package/dist/operations/sticky.js +19 -0
  70. package/dist/operations/sticky.js.map +1 -0
  71. package/dist/operations/validate.d.ts +145 -19
  72. package/dist/operations/validate.d.ts.map +1 -1
  73. package/dist/operations/validate.js +3 -3
  74. package/dist/task-record.d.ts +19 -0
  75. package/dist/task-record.d.ts.map +1 -1
  76. package/package.json +41 -1
  77. package/src/brain-graph.ts +282 -0
  78. package/src/branch-lock.ts +254 -0
  79. package/src/exit-codes.ts +1 -1
  80. package/src/graph.ts +2 -0
  81. package/src/index.ts +128 -0
  82. package/src/nexus-contract-ops.ts +244 -0
  83. package/src/nexus-living-brain-ops.ts +345 -0
  84. package/src/nexus-query-ops.ts +100 -0
  85. package/src/nexus-route-ops.ts +134 -0
  86. package/src/nexus-tasks-bridge-ops.ts +71 -0
  87. package/src/nexus-wiki-ops.ts +133 -0
  88. package/src/operations/admin.ts +2087 -0
  89. package/src/operations/brain.ts +34 -26
  90. package/src/operations/docs.ts +322 -0
  91. package/src/operations/intelligence.ts +399 -0
  92. package/src/operations/orchestrate.ts +117 -2
  93. package/src/operations/session.ts +225 -48
  94. package/src/operations/sticky.ts +308 -0
  95. package/src/operations/validate.ts +161 -55
  96. package/src/task-record.ts +19 -0
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Branch-lock and owner-override authentication contracts for T1118.
3
+ *
4
+ * Defines types, error codes, and interfaces for the four-layer agent
5
+ * branch-protection system:
6
+ *
7
+ * - L1: Git worktree isolation per spawned agent
8
+ * - L2: cleo-git-shim binary on PATH for harness-agnostic enforcement
9
+ * - L3: Filesystem hardening via chmod (+ optional chattr on Linux)
10
+ * - L4: Owner-override HMAC session authentication with TTY + rate-limit gates
11
+ *
12
+ * @task T1118
13
+ * @adr ADR-055
14
+ */
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // L1 — Worktree lifecycle types
18
+ // ---------------------------------------------------------------------------
19
+
20
+ /**
21
+ * State of an agent worktree created by orchestrate.spawn.
22
+ *
23
+ * @task T1118
24
+ * @task T1120
25
+ */
26
+ export interface AgentWorktreeState {
27
+ /** Absolute path to the worktree directory. */
28
+ path: string;
29
+ /** Branch name (format: task/<taskId>). */
30
+ branch: string;
31
+ /** Task ID that owns this worktree. */
32
+ taskId: string;
33
+ /** Base ref the branch was created from (e.g. "main"). */
34
+ baseRef: string;
35
+ /** Project hash for env-var injection. */
36
+ projectHash: string;
37
+ /** ISO 8601 timestamp when the worktree was created. */
38
+ createdAt: string;
39
+ /** Whether git worktree lock was applied to this entry. */
40
+ locked: boolean;
41
+ }
42
+
43
+ /**
44
+ * Result of creating a worktree during spawn.
45
+ *
46
+ * @task T1118
47
+ * @task T1120
48
+ */
49
+ export interface WorktreeSpawnResult {
50
+ /** The created worktree state. */
51
+ worktree: AgentWorktreeState;
52
+ /** Environment variables to inject into the agent's process. */
53
+ envVars: Record<string, string>;
54
+ /** CWD the agent MUST be started in. */
55
+ cwd: string;
56
+ /** Preamble text to prepend to the agent's spawn prompt. */
57
+ preamble: string;
58
+ }
59
+
60
+ /**
61
+ * Result from the orchestrate.worktree.complete operation.
62
+ *
63
+ * @task T1118
64
+ * @task T1120
65
+ */
66
+ export interface WorktreeCompleteResult {
67
+ /** Task ID that was completed. */
68
+ taskId: string;
69
+ /** Whether the cherry-pick succeeded. */
70
+ cherryPicked: boolean;
71
+ /** Number of commits cherry-picked. */
72
+ commitCount: number;
73
+ /** Whether the worktree was removed. */
74
+ worktreeRemoved: boolean;
75
+ /** Whether the task branch was deleted. */
76
+ branchDeleted: boolean;
77
+ /** Error message if any step failed (non-fatal — caller decides). */
78
+ error?: string;
79
+ }
80
+
81
+ /**
82
+ * Result from the orchestrate.worktree.cleanup operation.
83
+ *
84
+ * @task T1118
85
+ * @task T1120
86
+ */
87
+ export interface WorktreeCleanupResult {
88
+ /** Number of stale worktrees removed. */
89
+ removed: number;
90
+ /** Paths that were removed. */
91
+ removedPaths: string[];
92
+ /** Paths that failed to remove (with reasons). */
93
+ errors: Array<{ path: string; reason: string }>;
94
+ }
95
+
96
+ // ---------------------------------------------------------------------------
97
+ // L2 — Git shim contract types
98
+ // ---------------------------------------------------------------------------
99
+
100
+ /**
101
+ * Environment variables read by the cleo-git-shim binary.
102
+ *
103
+ * @task T1118
104
+ * @task T1121
105
+ */
106
+ export interface GitShimEnv {
107
+ /** Agent role. When set to worker|lead|subagent, branch-mutating ops are blocked. */
108
+ CLEO_AGENT_ROLE?: 'orchestrator' | 'worker' | 'lead' | 'subagent';
109
+ /** When set to "1", bypass the branch-mutation denylist for one command. */
110
+ CLEO_ALLOW_BRANCH_OPS?: '1';
111
+ /** Worktree root path — informational for shim error messages. */
112
+ CLEO_WORKTREE_ROOT?: string;
113
+ /** Branch protection mode. */
114
+ CLEO_BRANCH_PROTECTION?: 'strict' | 'permissive' | 'off';
115
+ }
116
+
117
+ /**
118
+ * A blocked git subcommand entry in the denylist.
119
+ *
120
+ * @task T1118
121
+ * @task T1121
122
+ */
123
+ export interface DeniedGitOp {
124
+ /** The git subcommand (e.g. "checkout"). */
125
+ subcommand: string;
126
+ /** Optional flag that triggers the denial (e.g. "--hard" for reset). */
127
+ flag?: string;
128
+ /** Human-readable reason shown in the shim's stderr output. */
129
+ reason: string;
130
+ }
131
+
132
+ // ---------------------------------------------------------------------------
133
+ // L3 — Filesystem hardening types
134
+ // ---------------------------------------------------------------------------
135
+
136
+ /**
137
+ * Platform capability report for filesystem hardening.
138
+ *
139
+ * @task T1118
140
+ * @task T1122
141
+ */
142
+ export interface FsHardenCapabilities {
143
+ /** Whether chmod is available (always true on POSIX). */
144
+ chmod: boolean;
145
+ /** Whether chattr is available (Linux ext2/3/4/xfs only). */
146
+ chattr: boolean;
147
+ /** Whether chflags is available (macOS). */
148
+ chflags: boolean;
149
+ /** Detected platform. */
150
+ platform: 'linux' | 'macos' | 'windows' | 'wsl' | 'unknown';
151
+ }
152
+
153
+ /**
154
+ * State of the filesystem hard-lock for the orchestrator's HEAD.
155
+ *
156
+ * @task T1118
157
+ * @task T1122
158
+ */
159
+ export interface FsHardenState {
160
+ /** Whether any lock is currently active. */
161
+ active: boolean;
162
+ /** Which mechanism was applied (chmod, chattr, or chflags). */
163
+ mechanism: 'chmod' | 'chattr' | 'chflags' | 'none';
164
+ /** Absolute path(s) that were locked. */
165
+ lockedPaths: string[];
166
+ /** ISO 8601 timestamp when the lock was applied. */
167
+ appliedAt?: string;
168
+ }
169
+
170
+ // ---------------------------------------------------------------------------
171
+ // L4 — Owner override authentication types
172
+ // ---------------------------------------------------------------------------
173
+
174
+ /**
175
+ * Record appended to force-bypass.jsonl when an override is used.
176
+ *
177
+ * Extends the base ForceBypassRecord with L4-specific authentication fields.
178
+ *
179
+ * @task T1118
180
+ * @task T1123
181
+ */
182
+ export interface OwnerOverrideAuditRecord {
183
+ /** ISO 8601 timestamp. */
184
+ timestamp: string;
185
+ /** Task ID being verified (may be "*" for session-level). */
186
+ taskId: string;
187
+ /** Gate being bypassed. */
188
+ gate: string;
189
+ /** Write action performed. */
190
+ action: string;
191
+ /** Agent ID that performed the bypass. */
192
+ agent_id: string;
193
+ /** Session ID. */
194
+ session_id: string | null;
195
+ /** Whether the HMAC token was validated (L4a). */
196
+ token_validated: boolean;
197
+ /** Whether TTY was present (L4c). */
198
+ tty_present: boolean;
199
+ /** Override count within the current session (L4d). */
200
+ override_count: number;
201
+ /** Webhook delivery status (L4d). */
202
+ webhook_delivered?: boolean;
203
+ /** Reason supplied by the operator. */
204
+ reason: string;
205
+ /** Process ID. */
206
+ pid: number;
207
+ }
208
+
209
+ /**
210
+ * Configuration for the owner override system.
211
+ *
212
+ * @task T1118
213
+ * @task T1123
214
+ */
215
+ export interface OwnerOverrideConfig {
216
+ /** Maximum number of overrides allowed per session (default: 3). */
217
+ maxPerSession: number;
218
+ /** Optional webhook URL to POST on each bypass. */
219
+ alertWebhook?: string;
220
+ }
221
+
222
+ // ---------------------------------------------------------------------------
223
+ // Error codes for branch-lock enforcement
224
+ // ---------------------------------------------------------------------------
225
+
226
+ /**
227
+ * Error codes emitted by the branch-lock + override-auth system.
228
+ *
229
+ * @task T1118
230
+ */
231
+ export const BRANCH_LOCK_ERROR_CODES = {
232
+ /** L2: git shim blocked a branch-mutating operation. */
233
+ E_GIT_OP_BLOCKED: 'E_GIT_OP_BLOCKED',
234
+ /** L1: spawn attempted without a worktree handle. */
235
+ E_WORKTREE_REQUIRED: 'E_WORKTREE_REQUIRED',
236
+ /** L1: worktree path does not exist or is not a valid git worktree. */
237
+ E_WORKTREE_INVALID: 'E_WORKTREE_INVALID',
238
+ /** L1: cherry-pick failed during worktree.complete. */
239
+ E_CHERRY_PICK_FAILED: 'E_CHERRY_PICK_FAILED',
240
+ /** L3: filesystem harden failed. */
241
+ E_FS_HARDEN_FAILED: 'E_FS_HARDEN_FAILED',
242
+ /** L4a: HMAC token invalid or missing. */
243
+ E_OVERRIDE_TOKEN_INVALID: 'E_OVERRIDE_TOKEN_INVALID',
244
+ /** L4b: caller has CLEO_AGENT_ROLE=worker|lead|subagent — override forbidden. */
245
+ E_OVERRIDE_FORBIDDEN_AGENT_ROLE: 'E_OVERRIDE_FORBIDDEN_AGENT_ROLE',
246
+ /** L4c: override requires TTY but stdin/stderr is not a TTY. */
247
+ E_OVERRIDE_NEEDS_TTY: 'E_OVERRIDE_NEEDS_TTY',
248
+ /** L4d: session override limit exceeded. */
249
+ E_OVERRIDE_RATE_LIMIT: 'E_OVERRIDE_RATE_LIMIT',
250
+ } as const;
251
+
252
+ /** Union of all branch-lock error code strings. */
253
+ export type BranchLockErrorCode =
254
+ (typeof BRANCH_LOCK_ERROR_CODES)[keyof typeof BRANCH_LOCK_ERROR_CODES];
package/src/exit-codes.ts CHANGED
@@ -111,7 +111,7 @@ export enum ExitCode {
111
111
  NEXUS_PROJECT_EXISTS = 76,
112
112
  NEXUS_QUERY_FAILED = 77,
113
113
  NEXUS_GRAPH_ERROR = 78,
114
- NEXUS_RESERVED = 79,
114
+ NEXUS_IMPACT_CRITICAL = 79,
115
115
 
116
116
  // === LIFECYCLE ENFORCEMENT (80-84) ===
117
117
  LIFECYCLE_GATE_FAILED = 80,
package/src/graph.ts CHANGED
@@ -154,6 +154,8 @@ export interface GraphNode {
154
154
  processIds?: string[];
155
155
  /** Kind-specific metadata blob (matches nexus_nodes.meta_json). */
156
156
  meta?: Record<string, unknown>;
157
+ /** Whether this node represents an external module (unresolved import). */
158
+ isExternal?: boolean;
157
159
  }
158
160
 
159
161
  // ---------------------------------------------------------------------------
package/src/index.ts CHANGED
@@ -132,6 +132,33 @@ export type {
132
132
  ContradictionDetail,
133
133
  SupersededEntry,
134
134
  } from './brain.js';
135
+ // === Brain Unified-Graph Types (canonical — T989 unification) ===
136
+ export type {
137
+ BrainConnectionStatus,
138
+ BrainEdge,
139
+ BrainGraph,
140
+ BrainNode,
141
+ BrainNodeKind,
142
+ BrainProjectContext,
143
+ BrainQueryOptions,
144
+ BrainStreamEvent,
145
+ BrainSubstrate,
146
+ } from './brain-graph.js';
147
+ export type {
148
+ AgentWorktreeState,
149
+ BranchLockErrorCode,
150
+ DeniedGitOp,
151
+ FsHardenCapabilities,
152
+ FsHardenState,
153
+ GitShimEnv,
154
+ OwnerOverrideAuditRecord,
155
+ OwnerOverrideConfig,
156
+ WorktreeCleanupResult,
157
+ WorktreeCompleteResult,
158
+ WorktreeSpawnResult,
159
+ } from './branch-lock.js';
160
+ // === Branch-Lock + Owner-Auth Types (T1118) ===
161
+ export { BRANCH_LOCK_ERROR_CODES } from './branch-lock.js';
135
162
  export type { AdapterCapabilities } from './capabilities.js';
136
163
  // === Code Symbol Types (tree-sitter AST) ===
137
164
  export type {
@@ -171,6 +198,7 @@ export type {
171
198
  LifecycleEnforcementMode,
172
199
  LoggingConfig,
173
200
  LogLevel,
201
+ MemoryBridgeMode,
174
202
  OutputConfig,
175
203
  OutputFormat,
176
204
  ProviderConfig,
@@ -339,6 +367,71 @@ export type {
339
367
  MemoryBridgeContent,
340
368
  SessionSummary,
341
369
  } from './memory.js';
370
+ export type {
371
+ Contract,
372
+ ContractCompatibilityMatrix,
373
+ ContractExtractionResult,
374
+ ContractMatch,
375
+ ContractMatchLevel,
376
+ ContractTaskLink,
377
+ GrpcContract,
378
+ HttpContract,
379
+ TopicContract,
380
+ } from './nexus-contract-ops.js';
381
+ // === Living Brain SDK Types (T1068 — 5-substrate traversal primitives) ===
382
+ // === Extended Code Reasoning Types (T1069 — reasonWhySymbol + reasonImpactOfChange) ===
383
+ export type {
384
+ BlastRadiusSummary,
385
+ BrainMemoryRef,
386
+ BrainRiskNote,
387
+ CodeAnchorResult,
388
+ CodeReasonTrace,
389
+ ConduitThreadRef,
390
+ DecisionRef,
391
+ ImpactFullReport,
392
+ LbTaskRef,
393
+ NexusContext,
394
+ NexusEdgeRef,
395
+ NexusNodeAnchor,
396
+ PlasticityMeasure,
397
+ ProposalRef,
398
+ ReasonTraceStep,
399
+ RiskTier,
400
+ SymbolFullContext,
401
+ SymbolImpactEntry,
402
+ TaskCodeImpact,
403
+ TasksForNodeEntry,
404
+ } from './nexus-living-brain-ops.js';
405
+ // === Nexus Query DSL (recursive CTE operations) ===
406
+ export type {
407
+ NexusCteAlias,
408
+ NexusCteMarkdownTable,
409
+ NexusCteParams,
410
+ NexusCtePlaceholder,
411
+ NexusCteResult,
412
+ } from './nexus-query-ops.js';
413
+ // === Route Analysis and Contract Registry Types (T1064, T1065) ===
414
+ export type {
415
+ RouteMapEntry,
416
+ RouteMapResult,
417
+ ShapeCheckCaller,
418
+ ShapeCheckResult,
419
+ ShapeCheckStatus,
420
+ } from './nexus-route-ops.js';
421
+ export type {
422
+ GitLogLinkerResult,
423
+ LinkTaskResult,
424
+ SymbolReference,
425
+ TaskReference,
426
+ } from './nexus-tasks-bridge-ops.js';
427
+ export type {
428
+ CommunityWikiStats,
429
+ GenerateNexusWikiOptions,
430
+ NexusWikiResult,
431
+ WikiDbHandle,
432
+ WikiStateFile,
433
+ WikiSymbolRow,
434
+ } from './nexus-wiki-ops.js';
342
435
  // === Operations Types (API wire format, namespaced to avoid collision with domain types) ===
343
436
  export * as ops from './operations/index.js';
344
437
  // Commonly used ops types re-exported at top level for convenience
@@ -352,6 +445,41 @@ export type {
352
445
  ParamType,
353
446
  } from './operations/params.js';
354
447
  export { paramsToCittyArgs } from './operations/params.js';
448
+ // Session operation param/result types — re-exported at top level for typed-dispatch consumers
449
+ // (T975 Wave D · ADR-051 migration)
450
+ export type {
451
+ DecisionRecord,
452
+ SessionBriefingShowParams,
453
+ SessionBriefingShowResult,
454
+ SessionContextDriftParams,
455
+ SessionContextDriftResult,
456
+ SessionDecisionLogParams,
457
+ SessionDecisionLogResult,
458
+ SessionEndParams,
459
+ SessionEndResult,
460
+ SessionFindParams,
461
+ SessionFindResult,
462
+ SessionGcParams,
463
+ SessionGcResult,
464
+ SessionHandoffShowParams,
465
+ SessionHandoffShowResult,
466
+ SessionListParams,
467
+ SessionListResult,
468
+ SessionOps,
469
+ SessionRecordAssumptionParams,
470
+ SessionRecordAssumptionResult,
471
+ SessionRecordDecisionParams,
472
+ SessionRecordDecisionResult,
473
+ SessionResumeParams,
474
+ SessionResumeResult,
475
+ SessionShowParams,
476
+ SessionShowResult,
477
+ SessionStartParams,
478
+ SessionStatusParams,
479
+ SessionStatusResult,
480
+ SessionSuspendParams,
481
+ SessionSuspendResult,
482
+ } from './operations/session.js';
355
483
  // === Orchestration Hierarchy ===
356
484
  export {
357
485
  type AgentHierarchy,
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Contract extraction and matching types for NEXUS cross-project compatibility.
3
+ *
4
+ * A contract represents a callable API (HTTP endpoint, gRPC service, pub/sub topic)
5
+ * that can be extracted from source code and matched with contracts from other projects
6
+ * to detect compatibility and integration points.
7
+ *
8
+ * @task T1065 — Contract Registry
9
+ */
10
+
11
+ /**
12
+ * HTTP contract extracted from route analysis.
13
+ *
14
+ * Represents a single HTTP endpoint with its path, method, and request/response schemas.
15
+ */
16
+ export interface HttpContract {
17
+ /** Unique contract ID (format: `http:<projectId>::<path>::<method>`) */
18
+ id: string;
19
+
20
+ /** Project ID this contract belongs to */
21
+ projectId: string;
22
+
23
+ /** Contract type — always 'http' */
24
+ type: 'http';
25
+
26
+ /** HTTP method (GET, POST, PUT, DELETE, PATCH, etc.) */
27
+ method: string;
28
+
29
+ /** Route path (e.g., `/api/v1/tasks`) */
30
+ path: string;
31
+
32
+ /** Request body schema as JSON string (or '{}' if no body) */
33
+ requestSchemaJson: string;
34
+
35
+ /** Response body schema as JSON string */
36
+ responseSchemaJson: string;
37
+
38
+ /** Source symbol ID (format: `<filePath>::<functionName>`) */
39
+ sourceSymbolId: string;
40
+
41
+ /** Route node ID from NEXUS graph */
42
+ routeNodeId?: string;
43
+
44
+ /** Confidence of extraction [0..1] */
45
+ confidence: number;
46
+
47
+ /** Human-readable summary */
48
+ description?: string;
49
+ }
50
+
51
+ /**
52
+ * gRPC contract extracted from proto file analysis.
53
+ *
54
+ * Represents a single gRPC service method.
55
+ * Extraction may be minimal/stub on projects without .proto files.
56
+ */
57
+ export interface GrpcContract {
58
+ /** Unique contract ID (format: `grpc:<projectId>::<serviceName>::<methodName>`) */
59
+ id: string;
60
+
61
+ /** Project ID this contract belongs to */
62
+ projectId: string;
63
+
64
+ /** Contract type — always 'grpc' */
65
+ type: 'grpc';
66
+
67
+ /** Service name (e.g., `TaskService`) */
68
+ serviceName: string;
69
+
70
+ /** Method name (e.g., `CreateTask`) */
71
+ methodName: string;
72
+
73
+ /** Request message type name */
74
+ requestMessageType: string;
75
+
76
+ /** Response message type name */
77
+ responseMessageType: string;
78
+
79
+ /** Request message schema as JSON string */
80
+ requestSchemaJson: string;
81
+
82
+ /** Response message schema as JSON string */
83
+ responseSchemaJson: string;
84
+
85
+ /** Source proto file path */
86
+ sourceProtoFile: string;
87
+
88
+ /** Confidence of extraction [0..1] */
89
+ confidence: number;
90
+
91
+ /** Human-readable summary */
92
+ description?: string;
93
+ }
94
+
95
+ /**
96
+ * Topic/pub-sub contract extracted from message queue code patterns.
97
+ *
98
+ * Represents a single publish or subscribe to a message topic.
99
+ * Extraction may be minimal/stub on projects without pub/sub patterns.
100
+ */
101
+ export interface TopicContract {
102
+ /** Unique contract ID (format: `topic:<projectId>::<topicName>::<direction>`) */
103
+ id: string;
104
+
105
+ /** Project ID this contract belongs to */
106
+ projectId: string;
107
+
108
+ /** Contract type — always 'topic' */
109
+ type: 'topic';
110
+
111
+ /** Topic name (e.g., `task.created`) */
112
+ topic: string;
113
+
114
+ /** Direction: 'publish' or 'subscribe' */
115
+ direction: 'publish' | 'subscribe';
116
+
117
+ /** Message payload schema as JSON string */
118
+ payloadSchemaJson: string;
119
+
120
+ /** Source symbol ID (format: `<filePath>::<functionName>`) */
121
+ sourceSymbolId: string;
122
+
123
+ /** Confidence of extraction [0..1] */
124
+ confidence: number;
125
+
126
+ /** Human-readable summary */
127
+ description?: string;
128
+ }
129
+
130
+ /** Union type of all contract kinds */
131
+ export type Contract = HttpContract | GrpcContract | TopicContract;
132
+
133
+ /**
134
+ * Matching level for contract compatibility.
135
+ *
136
+ * - 'exact': path + method match exactly (HTTP) or full signature match (gRPC)
137
+ * - 'name': service/method names match but signatures may differ
138
+ * - 'fuzzy': BM25 similarity above threshold on path/schema content
139
+ */
140
+ export type ContractMatchLevel = 'exact' | 'name' | 'fuzzy';
141
+
142
+ /**
143
+ * Result of matching two contracts.
144
+ *
145
+ * Indicates compatibility between a contract in project A and project B.
146
+ */
147
+ export interface ContractMatch {
148
+ /** Matched contract from project A */
149
+ contractA: Contract;
150
+
151
+ /** Matched contract from project B */
152
+ contractB: Contract;
153
+
154
+ /** Matching level (exact → name → fuzzy cascade) */
155
+ level: ContractMatchLevel;
156
+
157
+ /** Similarity score [0..1] where 1.0 is identical */
158
+ score: number;
159
+
160
+ /** Human-readable explanation of the match */
161
+ reason: string;
162
+
163
+ /** Compatibility verdict: 'compatible', 'incompatible', 'partial' */
164
+ compatibility: 'compatible' | 'incompatible' | 'partial';
165
+
166
+ /** Specific incompatibilities if any (e.g., schema mismatches) */
167
+ incompatibilities?: string[];
168
+ }
169
+
170
+ /**
171
+ * Contract compatibility matrix between two projects.
172
+ *
173
+ * Result of `cleo nexus contracts show --project-a <p> --project-b <p>`.
174
+ */
175
+ export interface ContractCompatibilityMatrix {
176
+ /** Project A ID */
177
+ projectAId: string;
178
+
179
+ /** Project B ID */
180
+ projectBId: string;
181
+
182
+ /** All matched contracts */
183
+ matches: ContractMatch[];
184
+
185
+ /** Count of compatible matches */
186
+ compatibleCount: number;
187
+
188
+ /** Count of incompatible matches */
189
+ incompatibleCount: number;
190
+
191
+ /** Count of partial/unresolved matches */
192
+ partialCount: number;
193
+
194
+ /** Overall compatibility percentage */
195
+ overallCompatibility: number;
196
+
197
+ /** Recommendations for integration */
198
+ recommendations: string[];
199
+ }
200
+
201
+ /**
202
+ * Result of extracting contracts from a project.
203
+ *
204
+ * Returned by contract extractors.
205
+ */
206
+ export interface ContractExtractionResult {
207
+ /** Project ID */
208
+ projectId: string;
209
+
210
+ /** HTTP contracts found */
211
+ httpContracts: HttpContract[];
212
+
213
+ /** gRPC contracts found */
214
+ grpcContracts: GrpcContract[];
215
+
216
+ /** Topic/pub-sub contracts found */
217
+ topicContracts: TopicContract[];
218
+
219
+ /** Total contracts extracted */
220
+ totalCount: number;
221
+
222
+ /** Any extraction warnings or notes */
223
+ notes: string[];
224
+ }
225
+
226
+ /**
227
+ * Result of linking contracts to affected tasks.
228
+ *
229
+ * When a contract's source symbol is touched by a task (via task_touches_symbol edge),
230
+ * we emit a contract_affected_by_task annotation.
231
+ */
232
+ export interface ContractTaskLink {
233
+ /** Contract ID */
234
+ contractId: string;
235
+
236
+ /** Task ID that affects this contract */
237
+ taskId: string;
238
+
239
+ /** Type of change (modified, added, removed) */
240
+ changeType: 'modified' | 'added' | 'removed';
241
+
242
+ /** Timestamp of the linkage */
243
+ linkedAt: string;
244
+ }