@lucern/contracts 0.1.0-alpha.3 → 0.1.1-alpha.1

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 (145) hide show
  1. package/dist/index.d.ts +2003 -29
  2. package/dist/index.js +5627 -30
  3. package/package.json +15 -58
  4. package/src/agents/v1.ts +8 -0
  5. package/src/api-enums.contract.ts +183 -0
  6. package/{dist/auth-context.contract.js → src/auth-context.contract.ts} +1 -1
  7. package/{dist/auth-session.contract.js → src/auth-session.contract.ts} +1 -1
  8. package/src/auth.contract.ts +162 -0
  9. package/src/beliefs/v1.ts +8 -0
  10. package/src/context-pack.contract.ts +704 -0
  11. package/src/convex-admin.contract.ts +14 -0
  12. package/{dist/events-types.contract.js → src/events-types.contract.ts} +1 -1
  13. package/src/events.contract.ts +376 -0
  14. package/src/evidence/v1.ts +8 -0
  15. package/src/gateway.contract.ts +151 -0
  16. package/src/graph/v1.ts +8 -0
  17. package/src/ids.contract.ts +36 -0
  18. package/src/index.ts +30 -0
  19. package/src/lens-filter.contract.ts +183 -0
  20. package/src/lens-workflow.contract.ts +162 -0
  21. package/src/mcp-tools.contract.ts +3636 -0
  22. package/src/ontologies/v1.ts +8 -0
  23. package/{dist/ontology-matching.contract.js → src/ontology-matching.contract.ts} +1 -1
  24. package/src/prompt.contract.ts +50 -0
  25. package/src/questions/v1.ts +8 -0
  26. package/src/sdk-methods.contract.ts +522 -0
  27. package/src/sdk-tools.contract.ts +1545 -0
  28. package/src/text-matching.contract.ts +347 -0
  29. package/{dist/topic-scope.contract.js → src/topic-scope.contract.ts} +1 -1
  30. package/src/topics/v1.ts +8 -0
  31. package/{dist/v1/agents/v1.d.ts → src/v1/agents/v1.ts} +0 -1
  32. package/{dist/v1/beliefs/v1.d.ts → src/v1/beliefs/v1.ts} +0 -1
  33. package/{dist/v1/evidence/v1.d.ts → src/v1/evidence/v1.ts} +0 -1
  34. package/{dist/v1/graph/v1.d.ts → src/v1/graph/v1.ts} +0 -1
  35. package/src/v1/ontologies/v1.ts +276 -0
  36. package/{dist/v1/questions/v1.d.ts → src/v1/questions/v1.ts} +0 -1
  37. package/src/v1/topics/v1.ts +79 -0
  38. package/{dist/v1/worktrees/v1.d.ts → src/v1/worktrees/v1.ts} +0 -1
  39. package/src/workflow-runtime.contract.ts +440 -0
  40. package/src/worktrees/v1.ts +8 -0
  41. package/tsconfig.json +9 -0
  42. package/README.md +0 -43
  43. package/dist/api-enums.contract.d.ts +0 -59
  44. package/dist/api-enums.contract.d.ts.map +0 -1
  45. package/dist/api-enums.contract.js +0 -148
  46. package/dist/api-enums.contract.js.map +0 -1
  47. package/dist/auth-context.contract.d.ts +0 -9
  48. package/dist/auth-context.contract.d.ts.map +0 -1
  49. package/dist/auth-context.contract.js.map +0 -1
  50. package/dist/auth-session.contract.d.ts +0 -9
  51. package/dist/auth-session.contract.d.ts.map +0 -1
  52. package/dist/auth-session.contract.js.map +0 -1
  53. package/dist/auth.contract.d.ts +0 -89
  54. package/dist/auth.contract.d.ts.map +0 -1
  55. package/dist/auth.contract.js +0 -58
  56. package/dist/auth.contract.js.map +0 -1
  57. package/dist/context-pack.contract.d.ts +0 -495
  58. package/dist/context-pack.contract.d.ts.map +0 -1
  59. package/dist/context-pack.contract.js +0 -170
  60. package/dist/context-pack.contract.js.map +0 -1
  61. package/dist/convex-admin.contract.d.ts +0 -6
  62. package/dist/convex-admin.contract.d.ts.map +0 -1
  63. package/dist/convex-admin.contract.js +0 -2
  64. package/dist/convex-admin.contract.js.map +0 -1
  65. package/dist/events-types.contract.d.ts +0 -9
  66. package/dist/events-types.contract.d.ts.map +0 -1
  67. package/dist/events-types.contract.js.map +0 -1
  68. package/dist/events.contract.d.ts +0 -177
  69. package/dist/events.contract.d.ts.map +0 -1
  70. package/dist/events.contract.js +0 -160
  71. package/dist/events.contract.js.map +0 -1
  72. package/dist/gateway.contract.d.ts +0 -75
  73. package/dist/gateway.contract.d.ts.map +0 -1
  74. package/dist/gateway.contract.js +0 -20
  75. package/dist/gateway.contract.js.map +0 -1
  76. package/dist/ids.contract.d.ts +0 -8
  77. package/dist/ids.contract.d.ts.map +0 -1
  78. package/dist/ids.contract.js +0 -25
  79. package/dist/ids.contract.js.map +0 -1
  80. package/dist/index.d.ts.map +0 -1
  81. package/dist/index.js.map +0 -1
  82. package/dist/lens-filter.contract.d.ts +0 -71
  83. package/dist/lens-filter.contract.d.ts.map +0 -1
  84. package/dist/lens-filter.contract.js +0 -96
  85. package/dist/lens-filter.contract.js.map +0 -1
  86. package/dist/lens-workflow.contract.d.ts +0 -85
  87. package/dist/lens-workflow.contract.d.ts.map +0 -1
  88. package/dist/lens-workflow.contract.js +0 -55
  89. package/dist/lens-workflow.contract.js.map +0 -1
  90. package/dist/mcp-tools.contract.d.ts +0 -152
  91. package/dist/mcp-tools.contract.d.ts.map +0 -1
  92. package/dist/mcp-tools.contract.js +0 -3282
  93. package/dist/mcp-tools.contract.js.map +0 -1
  94. package/dist/ontology-matching.contract.d.ts +0 -9
  95. package/dist/ontology-matching.contract.d.ts.map +0 -1
  96. package/dist/ontology-matching.contract.js.map +0 -1
  97. package/dist/prompt.contract.d.ts +0 -25
  98. package/dist/prompt.contract.d.ts.map +0 -1
  99. package/dist/prompt.contract.js +0 -25
  100. package/dist/prompt.contract.js.map +0 -1
  101. package/dist/sdk-methods.contract.d.ts +0 -356
  102. package/dist/sdk-methods.contract.d.ts.map +0 -1
  103. package/dist/sdk-methods.contract.js +0 -17
  104. package/dist/sdk-methods.contract.js.map +0 -1
  105. package/dist/sdk-tools.contract.d.ts +0 -93
  106. package/dist/sdk-tools.contract.d.ts.map +0 -1
  107. package/dist/sdk-tools.contract.js +0 -1399
  108. package/dist/sdk-tools.contract.js.map +0 -1
  109. package/dist/text-matching.contract.d.ts +0 -54
  110. package/dist/text-matching.contract.d.ts.map +0 -1
  111. package/dist/text-matching.contract.js +0 -278
  112. package/dist/text-matching.contract.js.map +0 -1
  113. package/dist/topic-scope.contract.d.ts +0 -9
  114. package/dist/topic-scope.contract.d.ts.map +0 -1
  115. package/dist/topic-scope.contract.js.map +0 -1
  116. package/dist/v1/agents/v1.d.ts.map +0 -1
  117. package/dist/v1/agents/v1.js +0 -2
  118. package/dist/v1/agents/v1.js.map +0 -1
  119. package/dist/v1/beliefs/v1.d.ts.map +0 -1
  120. package/dist/v1/beliefs/v1.js +0 -2
  121. package/dist/v1/beliefs/v1.js.map +0 -1
  122. package/dist/v1/evidence/v1.d.ts.map +0 -1
  123. package/dist/v1/evidence/v1.js +0 -2
  124. package/dist/v1/evidence/v1.js.map +0 -1
  125. package/dist/v1/graph/v1.d.ts.map +0 -1
  126. package/dist/v1/graph/v1.js +0 -2
  127. package/dist/v1/graph/v1.js.map +0 -1
  128. package/dist/v1/ontologies/v1.d.ts +0 -77
  129. package/dist/v1/ontologies/v1.d.ts.map +0 -1
  130. package/dist/v1/ontologies/v1.js +0 -179
  131. package/dist/v1/ontologies/v1.js.map +0 -1
  132. package/dist/v1/questions/v1.d.ts.map +0 -1
  133. package/dist/v1/questions/v1.js +0 -2
  134. package/dist/v1/questions/v1.js.map +0 -1
  135. package/dist/v1/topics/v1.d.ts +0 -20
  136. package/dist/v1/topics/v1.d.ts.map +0 -1
  137. package/dist/v1/topics/v1.js +0 -62
  138. package/dist/v1/topics/v1.js.map +0 -1
  139. package/dist/v1/worktrees/v1.d.ts.map +0 -1
  140. package/dist/v1/worktrees/v1.js +0 -2
  141. package/dist/v1/worktrees/v1.js.map +0 -1
  142. package/dist/workflow-runtime.contract.d.ts +0 -162
  143. package/dist/workflow-runtime.contract.d.ts.map +0 -1
  144. package/dist/workflow-runtime.contract.js +0 -258
  145. package/dist/workflow-runtime.contract.js.map +0 -1
package/package.json CHANGED
@@ -1,68 +1,25 @@
1
1
  {
2
2
  "name": "@lucern/contracts",
3
- "version": "0.1.0-alpha.3",
4
- "description": "Lucern shared boundary contracts and public types",
5
- "license": "UNLICENSED",
6
- "private": false,
3
+ "version": "0.1.1-alpha.1",
7
4
  "type": "module",
8
- "main": "./dist/index.js",
9
- "types": "./dist/index.d.ts",
10
- "files": [
11
- "dist"
12
- ],
5
+ "publishConfig": {
6
+ "access": "restricted"
7
+ },
8
+ "main": "src/index.ts",
9
+ "types": "src/index.ts",
13
10
  "exports": {
14
- ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js"
17
- },
18
- "./v1/beliefs": {
19
- "types": "./dist/v1/beliefs/v1.d.ts",
20
- "import": "./dist/v1/beliefs/v1.js"
21
- },
22
- "./v1/evidence": {
23
- "types": "./dist/v1/evidence/v1.d.ts",
24
- "import": "./dist/v1/evidence/v1.js"
25
- },
26
- "./v1/questions": {
27
- "types": "./dist/v1/questions/v1.d.ts",
28
- "import": "./dist/v1/questions/v1.js"
29
- },
30
- "./v1/topics": {
31
- "types": "./dist/v1/topics/v1.d.ts",
32
- "import": "./dist/v1/topics/v1.js"
33
- },
34
- "./v1/graph": {
35
- "types": "./dist/v1/graph/v1.d.ts",
36
- "import": "./dist/v1/graph/v1.js"
37
- },
38
- "./v1/agents": {
39
- "types": "./dist/v1/agents/v1.d.ts",
40
- "import": "./dist/v1/agents/v1.js"
41
- },
42
- "./v1/worktrees": {
43
- "types": "./dist/v1/worktrees/v1.d.ts",
44
- "import": "./dist/v1/worktrees/v1.js"
45
- },
46
- "./v1/ontologies": {
47
- "types": "./dist/v1/ontologies/v1.d.ts",
48
- "import": "./dist/v1/ontologies/v1.js"
49
- },
50
- "./*": {
51
- "types": "./dist/*.d.ts",
52
- "import": "./dist/*.js"
53
- }
11
+ ".": "./src/index.ts",
12
+ "./*": "./src/*.ts",
13
+ "./v1/*": "./src/v1/*.ts"
54
14
  },
55
15
  "scripts": {
56
- "build": "tsc --project tsconfig.build.json",
57
- "typecheck": "tsc --noEmit",
58
- "prepack": "npm run build",
59
- "prepublishOnly": "npm run build"
16
+ "build": "tsup src/index.ts --format esm --dts",
17
+ "typecheck": "tsc --noEmit"
18
+ },
19
+ "dependencies": {
20
+ "zod": "^3.23.0"
60
21
  },
61
22
  "devDependencies": {
62
23
  "typescript": "^5.7.0"
63
- },
64
- "publishConfig": {
65
- "access": "restricted"
66
- },
67
- "sideEffects": false
24
+ }
68
25
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Agent API Contract v1
3
+ *
4
+ * Defines the public surface for agent operations:
5
+ * session management, message passing, coordination, claims.
6
+ * Migrates from front-end/lucern/contracts/ during EK-16.
7
+ */
8
+ export {};
@@ -0,0 +1,183 @@
1
+ /**
2
+ * API Enum Contract Definitions
3
+ *
4
+ * Canonical enum values for all API-facing enumerations.
5
+ * These are co-equal with MCP contracts as external contracts.
6
+ * SDK types are DERIVED from these — not independently authored.
7
+ *
8
+ * CONTRACT SURFACE: Adding a new enum value is additive (non-breaking).
9
+ * Removing or renaming an existing value is a BREAKING CHANGE.
10
+ */
11
+
12
+ // =============================================================================
13
+ // BELIEF ENUMS
14
+ // =============================================================================
15
+
16
+ /** Fork reasons — why a scored belief was branched */
17
+ export const FORK_REASONS = [
18
+ "refinement", // Belief text evolved based on new understanding
19
+ "contradiction_response", // Created in response to a detected contradiction
20
+ "scope_change", // Belief scope narrowed or broadened
21
+ "confidence_collapse", // Confidence dropped below viability threshold
22
+ "manual", // User-initiated fork without specific trigger
23
+ ] as const;
24
+ export type ForkReason = (typeof FORK_REASONS)[number];
25
+
26
+ /** Confidence modulation triggers — what caused a confidence change */
27
+ export const CONFIDENCE_TRIGGERS = [
28
+ "evidence_added", // New evidence bore on the belief
29
+ "contradiction_detected", // A contradiction was flagged involving this belief
30
+ "merge_outcome", // Merge scoring determined this confidence
31
+ "manual", // User manually adjusted confidence
32
+ "decay", // Time-based confidence erosion
33
+ ] as const;
34
+ export type ConfidenceTrigger = (typeof CONFIDENCE_TRIGGERS)[number];
35
+
36
+ /** Belief status — lifecycle state */
37
+ export const BELIEF_STATUSES = [
38
+ "unscored", // Draft — editable in worktree (on feature branch, pre-merge)
39
+ "scored", // Merged — formulation frozen (merged to main)
40
+ "archived", // Soft-deleted — preserved in history (git rm)
41
+ ] as const;
42
+ export type BeliefStatus = (typeof BELIEF_STATUSES)[number];
43
+
44
+ // =============================================================================
45
+ // EDGE ENUMS
46
+ // =============================================================================
47
+
48
+ /** Reasoning methods — how an edge relationship was determined */
49
+ export const REASONING_METHODS = [
50
+ "deductive", // Logically entailed
51
+ "inductive", // Generalized from instances
52
+ "abductive", // Best explanation inference
53
+ "analogical", // Reasoning by analogy
54
+ "empirical", // Direct observation/measurement
55
+ ] as const;
56
+ export type ReasoningMethod = (typeof REASONING_METHODS)[number];
57
+
58
+ /** Defeat types (Pollock taxonomy) — how a contradiction operates */
59
+ export const DEFEAT_TYPES = [
60
+ "rebuts", // Direct contradiction — reasons for the negation
61
+ "undercuts", // Breaks the inference link between evidence and belief
62
+ "undermines", // Attacks a premise the belief depends on
63
+ ] as const;
64
+ export type DefeatType = (typeof DEFEAT_TYPES)[number];
65
+
66
+ /** Contradiction severity levels */
67
+ export const CONTRADICTION_SEVERITIES = [
68
+ "low", // Minor tension, may not require action
69
+ "medium", // Moderate conflict, should be investigated
70
+ "high", // Significant contradiction, likely needs resolution
71
+ "critical", // Blocks progress — must be addressed before judgment
72
+ ] as const;
73
+ export type ContradictionSeverity = (typeof CONTRADICTION_SEVERITIES)[number];
74
+
75
+ /** Contradiction resolution status */
76
+ export const CONTRADICTION_STATUSES = [
77
+ "unresolved", // Open conflict — may persist indefinitely
78
+ "resolved", // Conflict addressed (one belief forked, archived, or confidence adjusted)
79
+ "accepted", // Explicitly accepted as irreconcilable — both beliefs maintained
80
+ ] as const;
81
+ export type ContradictionStatus = (typeof CONTRADICTION_STATUSES)[number];
82
+
83
+ // =============================================================================
84
+ // WORKTREE ENUMS (git worktree lifecycle)
85
+ // =============================================================================
86
+
87
+ /** Merge outcome types — how a worktree merge resolved */
88
+ export const MERGE_OUTCOMES = [
89
+ "validated", // Beliefs confirmed — clean merge to main
90
+ "invalidated", // Defeat recorded — confidence collapsed (merge with revert)
91
+ "forked", // Beliefs split into competing versions (fork from merge point)
92
+ "inconclusive", // Insufficient evidence — stashed (git stash)
93
+ ] as const;
94
+ export type MergeOutcome = (typeof MERGE_OUTCOMES)[number];
95
+
96
+ /** Worktree phases — investigation lifecycle within a checked-out worktree */
97
+ export const WORKTREE_PHASES = [
98
+ "hypothesis", // Form testable claims (write the code — commits)
99
+ "investigation", // Collect evidence (run the tests — more commits)
100
+ "evaluation", // Update credences (review the results — amend as needed)
101
+ "resolution", // Determine outcome (merge to main, fork, or stash)
102
+ ] as const;
103
+ export type WorktreePhase = (typeof WORKTREE_PHASES)[number];
104
+
105
+ // =============================================================================
106
+ // BRANCH ENUMS (git branch lifecycle)
107
+ // =============================================================================
108
+
109
+ /** Branch status — thematic branch lifecycle */
110
+ export const BRANCH_STATUSES = [
111
+ "dormant", // Branch exists but no active worktree (no one investigating)
112
+ "active", // At least one worktree is investigating this branch
113
+ "archived", // Branch retired — no longer a relevant thematic container
114
+ ] as const;
115
+ export type BranchStatus = (typeof BRANCH_STATUSES)[number];
116
+
117
+ // =============================================================================
118
+ // PULL REQUEST ENUMS (git pull request lifecycle)
119
+ // =============================================================================
120
+
121
+ /** Pull request status — review lifecycle before merge */
122
+ export const PULL_REQUEST_STATUSES = [
123
+ "pending_review", // PR opened — awaiting reviewer feedback
124
+ "changes_requested", // Reviewer requests changes before merge
125
+ "approved", // Approved — ready to merge
126
+ "blocked", // Blocked — cannot merge until contradiction is resolved
127
+ ] as const;
128
+ export type PullRequestStatus = (typeof PULL_REQUEST_STATUSES)[number];
129
+
130
+ // =============================================================================
131
+ // LAYER ENUMS
132
+ // =============================================================================
133
+
134
+ /** Epistemic layers — the hierarchy of knowledge */
135
+ export const EPISTEMIC_LAYERS = [
136
+ "L1", // Source — the given (vendored deps)
137
+ "L2", // Evidence — the interpreted (test suite)
138
+ "L3", // Belief — the structural (source files)
139
+ "L4", // Judgment — the committed (release tags)
140
+ ] as const;
141
+ export type EpistemicLayer = (typeof EPISTEMIC_LAYERS)[number];
142
+
143
+ // =============================================================================
144
+ // JUDGMENT ENUMS (Phase 1: new vocabulary)
145
+ // =============================================================================
146
+
147
+ /**
148
+ * Judgment type — classification of the determination.
149
+ *
150
+ * Phase 1: These are new enum values for the Judgment (L4) vocabulary.
151
+ * The existing code uses "Decision" — these are the forward-looking terms
152
+ * that will eventually replace the Decision vocabulary (Phase 2-3).
153
+ */
154
+ export const JUDGMENT_TYPES = [
155
+ "investment_thesis", // Judgment on an investment opportunity
156
+ "thesis_maturity", // Judgment that a thesis is ready for IC presentation
157
+ "contradiction_ruling", // Judgment on how to handle an irreconcilable contradiction
158
+ "scope_determination", // Judgment that defines or redefines investigation scope
159
+ "confidence_ruling", // Judgment that overrides automated confidence for policy reasons
160
+ ] as const;
161
+ export type JudgmentType = (typeof JUDGMENT_TYPES)[number];
162
+
163
+ // =============================================================================
164
+ // SUPPORT RELATION ENUMS
165
+ // =============================================================================
166
+
167
+ /** Core edge types used in the Integration Surfaces */
168
+ export const INTEGRATION_EDGE_TYPES = [
169
+ // Support relations
170
+ "informs", // Evidence bears on a belief (weight = direction/strength)
171
+ "grounds", // Source provides raw basis for evidence
172
+ "answers", // Evidence or belief resolves a question
173
+ // Defeat relations (Pollock) — weight carries direction
174
+ "contradicts", // Rebuts — direct contradiction
175
+ "supports", // Weight carries valence (negative = weakens/undercuts)
176
+ // Structural relations
177
+ "depends_on", // Belief B requires Belief A
178
+ "derived_from", // Provenance lineage
179
+ "contains", // Hierarchical containment
180
+ "supersedes", // New version replaces old (lineage)
181
+ "tests", // Question tests a belief
182
+ ] as const;
183
+ export type IntegrationEdgeType = (typeof INTEGRATION_EDGE_TYPES)[number];
@@ -5,5 +5,5 @@
5
5
  * Retained here until the Lucern 1.0.0 barrel-sunset cut (D12).
6
6
  * New code should import from "@lucern/contracts" (barrel) or "./auth.contract".
7
7
  */
8
+
8
9
  export * from "./auth.contract";
9
- //# sourceMappingURL=auth-context.contract.js.map
@@ -5,5 +5,5 @@
5
5
  * Retained here until the Lucern 1.0.0 barrel-sunset cut (D12).
6
6
  * New code should import from "@lucern/contracts" (barrel) or "./auth.contract".
7
7
  */
8
+
8
9
  export * from "./auth.contract";
9
- //# sourceMappingURL=auth-session.contract.js.map
@@ -0,0 +1,162 @@
1
+ /**
2
+ * @lucern/contracts — auth (canonical support contract)
3
+ *
4
+ * Consolidated flat support surface for Lucern authentication:
5
+ * - Session primitives (auth modes, principal types, lifecycle)
6
+ * - AuthContext shape + McpTransportKind + LucernSdkClient alias
7
+ *
8
+ * Consolidated from src/auth-session.contract.ts and src/auth-context.contract.ts
9
+ * in EK-16 T1 PR 3a. Compat shims remain at both old paths until Lucern 1.0.0 (D12).
10
+ */
11
+
12
+ // =============================================================================
13
+ // SESSION PRIMITIVES
14
+ // (Formerly src/auth-session.contract.ts)
15
+ // =============================================================================
16
+
17
+ export const SESSION_AUTH_MODES = [
18
+ "interactive_user",
19
+ "service_principal",
20
+ "tenant_api_key",
21
+ "session_token",
22
+ ] as const;
23
+ export type SessionAuthMode = (typeof SESSION_AUTH_MODES)[number];
24
+
25
+ export const SESSION_PRINCIPAL_TYPES = ["human", "service", "agent"] as const;
26
+ export type SessionPrincipalType = (typeof SESSION_PRINCIPAL_TYPES)[number];
27
+
28
+ export const SESSION_LIFECYCLE_STATUSES = [
29
+ "active",
30
+ "expired",
31
+ "revoked",
32
+ ] as const;
33
+ export type SessionLifecycleStatus =
34
+ (typeof SESSION_LIFECYCLE_STATUSES)[number];
35
+
36
+ export type SessionDelegationHop = {
37
+ principalId: string;
38
+ principalType: SessionPrincipalType;
39
+ authMode?: SessionAuthMode;
40
+ sessionId?: string;
41
+ delegatedAt?: number;
42
+ reason?: string;
43
+ };
44
+
45
+ export type SessionAuditOutcome =
46
+ | "accepted"
47
+ | "rejected"
48
+ | "revoked"
49
+ | "expired";
50
+
51
+ export type SessionAuditEnvelope = {
52
+ sessionId: string;
53
+ authMode: SessionAuthMode;
54
+ principalId: string;
55
+ principalType: SessionPrincipalType;
56
+ tenantId: string;
57
+ workspaceId?: string;
58
+ apiKeyId?: string;
59
+ scopes: readonly string[];
60
+ roles?: readonly string[];
61
+ delegationChain?: readonly SessionDelegationHop[];
62
+ sourceSessionId?: string;
63
+ expiresAt?: number;
64
+ request?: {
65
+ endpoint?: string;
66
+ method?: string;
67
+ correlationId?: string;
68
+ };
69
+ result?: {
70
+ outcome: SessionAuditOutcome;
71
+ reason?: string;
72
+ };
73
+ };
74
+
75
+ export function inferSessionPrincipalType(
76
+ principalId: string
77
+ ): SessionPrincipalType {
78
+ if (principalId.startsWith("user:")) {
79
+ return "human";
80
+ }
81
+ if (principalId.startsWith("agent:")) {
82
+ return "agent";
83
+ }
84
+ return "service";
85
+ }
86
+
87
+ export function normalizeDelegationChain(args: {
88
+ delegationChain?: readonly SessionDelegationHop[];
89
+ delegatedBy?: string;
90
+ delegatedByType?: SessionPrincipalType;
91
+ delegatedAt?: number;
92
+ reason?: string;
93
+ }): SessionDelegationHop[] | undefined {
94
+ if (args.delegationChain && args.delegationChain.length > 0) {
95
+ return [...args.delegationChain];
96
+ }
97
+ if (!args.delegatedBy) {
98
+ return;
99
+ }
100
+ return [
101
+ {
102
+ principalId: args.delegatedBy,
103
+ principalType:
104
+ args.delegatedByType ?? inferSessionPrincipalType(args.delegatedBy),
105
+ delegatedAt: args.delegatedAt,
106
+ reason: args.reason,
107
+ },
108
+ ];
109
+ }
110
+
111
+ export function lastDelegator(
112
+ delegationChain?: readonly SessionDelegationHop[]
113
+ ): string | undefined {
114
+ if (!delegationChain || delegationChain.length === 0) {
115
+ return;
116
+ }
117
+ return delegationChain[delegationChain.length - 1]?.principalId;
118
+ }
119
+
120
+ // =============================================================================
121
+ // AUTH CONTEXT
122
+ // (Formerly src/auth-context.contract.ts)
123
+ // =============================================================================
124
+
125
+ import type { ConvexAdminClient } from "./convex-admin.contract";
126
+
127
+ export type McpTransportKind = "stdio" | "hosted";
128
+
129
+ export type LucernSdkClient = unknown;
130
+
131
+ /**
132
+ * Session authentication context — injected by withAuth() middleware.
133
+ *
134
+ * Built from TenantConfig at dispatch time. Agent sessions get
135
+ * AGENT_IDENTITY + "agent:internal" role + unrestricted access.
136
+ * User sessions get Clerk userId + resolved role + tool ACLs.
137
+ */
138
+ export type AuthContext = {
139
+ sessionType: "agent" | "user";
140
+ userId: string; // AGENT_IDENTITY for agents, Clerk userId for users
141
+ tenantId: string;
142
+ role: string; // "agent:internal" | "platform_admin" | "tenant_admin" | "editor" | "viewer" | ...
143
+ allowedTopics: string[] | null; // null = unrestricted (agents, admins). Block 11D populates this.
144
+ // Layer 2a: Group-pack binding — resolved at boot from MC resolveUserPackAccess
145
+ groupIds: string[]; // Groups this user belongs to (empty for agents)
146
+ permittedPackKeys: string[]; // Packs accessible via group assignments (empty = no pack filtering)
147
+ sessionId: string; // S2-13K: MCP process session UUID for audit attribution
148
+ principalId?: string;
149
+ principalType?: SessionPrincipalType;
150
+ workspaceId?: string;
151
+ scopes?: string[];
152
+ authMode?: SessionAuthMode;
153
+ roles?: string[];
154
+ transportKind?: McpTransportKind;
155
+ lucernClient?: LucernSdkClient;
156
+ convex?: ConvexAdminClient;
157
+ setDefaultScopeContext?: (scopeId: string) => Promise<unknown>;
158
+ matchesWorkspaceReasoningScope?: (
159
+ node: unknown,
160
+ scope: unknown
161
+ ) => boolean;
162
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Beliefs API Contract v1
3
+ *
4
+ * Defines the public surface for belief operations:
5
+ * create, refine, fork, score, archive, search, lineage.
6
+ * Migrates from front-end/lucern/contracts/ during EK-16.
7
+ */
8
+ export {};