@company-semantics/contracts 0.20.0 → 0.21.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.
- package/package.json +1 -1
- package/src/guards/config.ts +0 -5
- package/src/identity/README.md +31 -0
- package/src/identity/display-name.ts +60 -0
- package/src/identity/index.ts +12 -0
- package/src/identity/types.ts +62 -0
- package/src/index.ts +16 -0
- package/src/mcp/index.ts +85 -0
package/package.json
CHANGED
package/src/guards/config.ts
CHANGED
|
@@ -319,11 +319,6 @@ export interface GuardCheckRegistry {
|
|
|
319
319
|
structural?: BoundGuardCheck[];
|
|
320
320
|
behavioral?: BoundGuardCheck[];
|
|
321
321
|
invariants?: BoundGuardCheck[];
|
|
322
|
-
/**
|
|
323
|
-
* @deprecated Evolution guards are CI-owned. Use evolutionBaselines instead.
|
|
324
|
-
* Product repos should not provide evolution check implementations.
|
|
325
|
-
*/
|
|
326
|
-
evolution?: BoundGuardCheck[];
|
|
327
322
|
/** Meta-guards: protect the guard system itself (coverage correctness) */
|
|
328
323
|
meta?: BoundGuardCheck[];
|
|
329
324
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# identity/
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
TypeScript types and functions for user identity and display name resolution.
|
|
6
|
+
|
|
7
|
+
## Invariants
|
|
8
|
+
|
|
9
|
+
- Types with minimal runtime code (pure functions only, no side effects)
|
|
10
|
+
- No external dependencies (contracts policy)
|
|
11
|
+
- `preferredName` is assistant-facing only, not user-edited label
|
|
12
|
+
- `fullName` is user-editable override of derived firstName + lastName
|
|
13
|
+
- `displayName` is NEVER stored — always derived at read time via `resolveDisplayName()`
|
|
14
|
+
- `resolveDisplayName()` is the ONLY approved way to determine assistant addressing
|
|
15
|
+
|
|
16
|
+
## Public API
|
|
17
|
+
|
|
18
|
+
### Types
|
|
19
|
+
|
|
20
|
+
- `ISODateString` — ISO 8601 date-time string alias
|
|
21
|
+
- `UserIdentity` — User identity with name fields and timestamps
|
|
22
|
+
|
|
23
|
+
### Functions
|
|
24
|
+
|
|
25
|
+
- `deriveFullName(firstName, lastName?)` — Derive full name from components
|
|
26
|
+
- `resolveDisplayName(identity)` — Get display name (preferredName or firstName)
|
|
27
|
+
|
|
28
|
+
## Dependencies
|
|
29
|
+
|
|
30
|
+
**Imports from:** (none — leaf module)
|
|
31
|
+
**Imported by:** company-semantics-backend, company-semantics-app
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display Name Functions
|
|
3
|
+
*
|
|
4
|
+
* Canonical functions for deriving and resolving user display names.
|
|
5
|
+
* These are the ONLY approved ways to handle display name logic.
|
|
6
|
+
*
|
|
7
|
+
* @see DECISIONS.md ADR-2026-01-020 for design rationale
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { UserIdentity } from './types.js';
|
|
11
|
+
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// Full Name Derivation
|
|
14
|
+
// =============================================================================
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Derive fullName from firstName and lastName.
|
|
18
|
+
*
|
|
19
|
+
* Invariant: fullName MUST be derived automatically unless explicitly provided.
|
|
20
|
+
*
|
|
21
|
+
* @param firstName - User's first name (required)
|
|
22
|
+
* @param lastName - User's last name (optional)
|
|
23
|
+
* @returns Combined full name
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* deriveFullName("Ian", "Heidt") // "Ian Heidt"
|
|
27
|
+
* deriveFullName("Ian") // "Ian"
|
|
28
|
+
*/
|
|
29
|
+
export function deriveFullName(firstName: string, lastName?: string): string {
|
|
30
|
+
return lastName ? `${firstName} ${lastName}` : firstName;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// Display Name Resolution
|
|
35
|
+
// =============================================================================
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the display name for assistant addressing.
|
|
39
|
+
*
|
|
40
|
+
* This is the ONLY approved way to determine how the assistant
|
|
41
|
+
* or UI should address a user.
|
|
42
|
+
*
|
|
43
|
+
* Invariants:
|
|
44
|
+
* - preferredName overrides if present and non-empty
|
|
45
|
+
* - Falls back to firstName (never blank)
|
|
46
|
+
* - displayName is NEVER stored, always derived at read time
|
|
47
|
+
*
|
|
48
|
+
* @param identity - Object with preferredName and firstName fields
|
|
49
|
+
* @returns The resolved display name
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* resolveDisplayName({ firstName: "Ian", preferredName: "Heidt" }) // "Heidt"
|
|
53
|
+
* resolveDisplayName({ firstName: "Ian", preferredName: "" }) // "Ian"
|
|
54
|
+
* resolveDisplayName({ firstName: "Ian" }) // "Ian"
|
|
55
|
+
*/
|
|
56
|
+
export function resolveDisplayName(
|
|
57
|
+
identity: Pick<UserIdentity, 'preferredName' | 'firstName'>
|
|
58
|
+
): string {
|
|
59
|
+
return identity.preferredName?.trim() || identity.firstName;
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity Types Barrel
|
|
3
|
+
*
|
|
4
|
+
* Re-exports user identity vocabulary types and functions.
|
|
5
|
+
* Import from '@company-semantics/contracts' (root).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Types
|
|
9
|
+
export type { ISODateString, UserIdentity } from './types.js';
|
|
10
|
+
|
|
11
|
+
// Functions
|
|
12
|
+
export { deriveFullName, resolveDisplayName } from './display-name.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Identity Types
|
|
3
|
+
*
|
|
4
|
+
* Canonical vocabulary for user identity across Company Semantics.
|
|
5
|
+
*
|
|
6
|
+
* @see DECISIONS.md ADR-2026-01-020 for design rationale
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// Utility Types
|
|
11
|
+
// =============================================================================
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* ISO 8601 date-time string.
|
|
15
|
+
* Example: "2025-12-25T14:30:00.000Z"
|
|
16
|
+
*/
|
|
17
|
+
export type ISODateString = string;
|
|
18
|
+
|
|
19
|
+
// =============================================================================
|
|
20
|
+
// User Identity
|
|
21
|
+
// =============================================================================
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* User identity information.
|
|
25
|
+
* Represents the canonical identity vocabulary for a user.
|
|
26
|
+
*
|
|
27
|
+
* Invariants:
|
|
28
|
+
* - firstName is required (always addressable)
|
|
29
|
+
* - lastName is optional (single-name users exist globally)
|
|
30
|
+
* - fullName is STORED (derived by default, user-editable)
|
|
31
|
+
* - preferredName is STORED (assistant-only addressing)
|
|
32
|
+
* - displayName is NEVER stored (derived at read time via resolveDisplayName)
|
|
33
|
+
*/
|
|
34
|
+
export type UserIdentity = {
|
|
35
|
+
/** Unique user identifier */
|
|
36
|
+
userId: string;
|
|
37
|
+
|
|
38
|
+
/** User's first name (required) */
|
|
39
|
+
firstName: string;
|
|
40
|
+
|
|
41
|
+
/** User's last name (optional) */
|
|
42
|
+
lastName?: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Full name for display in UI, exports, and audit logs.
|
|
46
|
+
* Derived by default from firstName + lastName, but user-editable.
|
|
47
|
+
*/
|
|
48
|
+
fullName: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Preferred name for AI assistant to use.
|
|
52
|
+
* Assistant-only field; may differ from firstName.
|
|
53
|
+
* If not set, assistant falls back to firstName via resolveDisplayName().
|
|
54
|
+
*/
|
|
55
|
+
preferredName?: string;
|
|
56
|
+
|
|
57
|
+
/** When the identity was created */
|
|
58
|
+
createdAt: ISODateString;
|
|
59
|
+
|
|
60
|
+
/** When the identity was last updated */
|
|
61
|
+
updatedAt: ISODateString;
|
|
62
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -84,3 +84,19 @@ export {
|
|
|
84
84
|
// @see ADR-2025-12-011 for design rationale
|
|
85
85
|
export { COMPATIBILITY } from './compatibility.js'
|
|
86
86
|
export type { Compatibility, Deprecation } from './compatibility.js'
|
|
87
|
+
|
|
88
|
+
// User identity types and functions
|
|
89
|
+
// @see ADR-2026-01-020 for design rationale
|
|
90
|
+
export type { ISODateString, UserIdentity } from './identity/index.js'
|
|
91
|
+
export { deriveFullName, resolveDisplayName } from './identity/index.js'
|
|
92
|
+
|
|
93
|
+
// MCP tool discovery types
|
|
94
|
+
// @see company-semantics-backend/src/interfaces/mcp/ for implementation
|
|
95
|
+
export type {
|
|
96
|
+
ToolCategory,
|
|
97
|
+
ToolVisibility,
|
|
98
|
+
ToolInvocationMode,
|
|
99
|
+
MCPToolDescriptor,
|
|
100
|
+
ToolDiscoveryResponse,
|
|
101
|
+
ToolListMessagePart,
|
|
102
|
+
} from './mcp/index.js'
|
package/src/mcp/index.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool Discovery Types
|
|
3
|
+
*
|
|
4
|
+
* Types for tool discovery flow (read-only, UI-first).
|
|
5
|
+
* Same descriptor used for discovery and invocation, different fields matter.
|
|
6
|
+
*
|
|
7
|
+
* INVARIANTS:
|
|
8
|
+
* - Discovery is descriptive (never executes)
|
|
9
|
+
* - Invocation is authoritative (runtime is executor)
|
|
10
|
+
* - Tool discovery output must be runtime-sourced
|
|
11
|
+
* - Tool discovery must not be streamed char-by-char
|
|
12
|
+
*
|
|
13
|
+
* @see company-semantics-backend/src/interfaces/mcp/ for implementation
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Tool categories for grouping in UI.
|
|
18
|
+
* Maps to user mental model, not implementation.
|
|
19
|
+
*/
|
|
20
|
+
export type ToolCategory =
|
|
21
|
+
| 'system' // System status, health checks
|
|
22
|
+
| 'data' // Data access, ingestion, queries
|
|
23
|
+
| 'connections' // OAuth, integrations
|
|
24
|
+
| 'automation' // Scheduled tasks, triggers
|
|
25
|
+
| 'developer' // Debug, internal tools
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Tool visibility levels.
|
|
29
|
+
* Controls who can see the tool in discovery.
|
|
30
|
+
*/
|
|
31
|
+
export type ToolVisibility = 'user' | 'admin'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* How the tool can be invoked.
|
|
35
|
+
* - manual: User must explicitly request
|
|
36
|
+
* - assistant: AI can invoke proactively
|
|
37
|
+
* - hybrid: Both manual and assistant invocation
|
|
38
|
+
*/
|
|
39
|
+
export type ToolInvocationMode = 'manual' | 'assistant' | 'hybrid'
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Complete tool descriptor for discovery and invocation.
|
|
43
|
+
*
|
|
44
|
+
* Discovery uses: id, name, description, category
|
|
45
|
+
* Invocation uses: id, requiresConfirmation, invocationMode
|
|
46
|
+
*/
|
|
47
|
+
export interface MCPToolDescriptor {
|
|
48
|
+
/** Unique identifier (matches MCP tool name, e.g., 'cs_help') */
|
|
49
|
+
id: string
|
|
50
|
+
/** Human-readable name for display */
|
|
51
|
+
name: string
|
|
52
|
+
/** User-facing description (what it does, not how) */
|
|
53
|
+
description: string
|
|
54
|
+
/** Grouping category for UI organization */
|
|
55
|
+
category: ToolCategory
|
|
56
|
+
/** Whether user confirmation is required before execution */
|
|
57
|
+
requiresConfirmation: boolean
|
|
58
|
+
/** How the tool can be triggered */
|
|
59
|
+
invocationMode: ToolInvocationMode
|
|
60
|
+
/** Who can see this tool */
|
|
61
|
+
visibility: ToolVisibility
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Response shape for tool discovery endpoint.
|
|
66
|
+
* Used by GET /api/capabilities/tools
|
|
67
|
+
*
|
|
68
|
+
* Transport-level type (HTTP API response).
|
|
69
|
+
* No timestamp - ephemeral, regenerated often.
|
|
70
|
+
*/
|
|
71
|
+
export interface ToolDiscoveryResponse {
|
|
72
|
+
/** Tools available to the current user */
|
|
73
|
+
tools: MCPToolDescriptor[]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Structured message part for protocol-level rendering.
|
|
78
|
+
*
|
|
79
|
+
* Conversation-level type (chat protocol part).
|
|
80
|
+
* Rendered atomically, not streamed char-by-char.
|
|
81
|
+
*/
|
|
82
|
+
export interface ToolListMessagePart {
|
|
83
|
+
type: 'tool-list'
|
|
84
|
+
tools: MCPToolDescriptor[]
|
|
85
|
+
}
|