@company-semantics/contracts 0.19.0 → 0.21.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@company-semantics/contracts",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -281,6 +281,26 @@ export interface EvolutionBaselines {
281
281
  * @see ADR-2025-12-014
282
282
  */
283
283
  contractsFreshness?: ContractsFreshnessBaseline;
284
+
285
+ /**
286
+ * Coverage drift check configuration.
287
+ * CI injects checkCoverageDrift based on this config.
288
+ * Errors when coverage drops below baseline (enforced).
289
+ */
290
+ coverage?: CoverageBaseline;
291
+ }
292
+
293
+ /**
294
+ * Coverage baseline configuration.
295
+ * Used by CI orchestrator to inject coverage drift guard.
296
+ */
297
+ export interface CoverageBaseline {
298
+ /** Path to coverage-summary.json (default: 'coverage/coverage-summary.json') */
299
+ coverageFile?: string;
300
+ /** Baseline coverage percentage (lines) */
301
+ baseline: number;
302
+ /** Allowed drop threshold before error (default: 0 = any drop errors) */
303
+ dropThreshold?: number;
284
304
  }
285
305
 
286
306
  /**
@@ -299,11 +319,6 @@ export interface GuardCheckRegistry {
299
319
  structural?: BoundGuardCheck[];
300
320
  behavioral?: BoundGuardCheck[];
301
321
  invariants?: BoundGuardCheck[];
302
- /**
303
- * @deprecated Evolution guards are CI-owned. Use evolutionBaselines instead.
304
- * Product repos should not provide evolution check implementations.
305
- */
306
- evolution?: BoundGuardCheck[];
307
322
  /** Meta-guards: protect the guard system itself (coverage correctness) */
308
323
  meta?: BoundGuardCheck[];
309
324
  };
@@ -18,10 +18,23 @@ export type {
18
18
  GuardOutput,
19
19
  KnownVulnerability,
20
20
  VulnerabilityConfig,
21
+ // SOC 2 Compliance types
22
+ Soc2ControlArea,
23
+ Soc2ControlStatus,
24
+ Soc2ControlResult,
25
+ Soc2ComplianceOutput,
21
26
  } from './types.js';
22
27
 
23
28
  // Constants (these are type-level, not runtime)
24
- export { GUARD_SCHEMA_VERSION, GUARD_TIERS } from './types.js';
29
+ export {
30
+ GUARD_SCHEMA_VERSION,
31
+ GUARD_TIERS,
32
+ // SOC 2 Compliance constants
33
+ SOC2_CONTROL_NAMES,
34
+ REQUIRED_SOC2_CONTROLS,
35
+ BLOCKING_SOC2_CONTROLS,
36
+ SOC2_SCHEMA_VERSION,
37
+ } from './types.js';
25
38
 
26
39
  // Config types
27
40
  export type {
@@ -36,6 +49,7 @@ export type {
36
49
  VulnerabilitiesBaseline,
37
50
  EvolutionBaselines,
38
51
  ContractsFreshnessBaseline,
52
+ CoverageBaseline,
39
53
  MetaBaselines,
40
54
  } from './config.js';
41
55
 
@@ -158,3 +158,114 @@ export interface VulnerabilityConfig {
158
158
  /** Baseline of known/accepted vulnerabilities (grandfathered) */
159
159
  knownVulnerabilities?: KnownVulnerability[];
160
160
  }
161
+
162
+ // =============================================================================
163
+ // SOC 2 Compliance Types
164
+ // =============================================================================
165
+
166
+ /**
167
+ * SOC 2 control area identifiers.
168
+ * - CM: Change Management
169
+ * - AC: Access Control
170
+ * - LM: Logging & Monitoring
171
+ * - SD: Secure SDLC
172
+ * - BR: Backup & Recovery
173
+ */
174
+ export type Soc2ControlArea = 'CM' | 'AC' | 'LM' | 'SD' | 'BR';
175
+
176
+ /**
177
+ * Control status semantics:
178
+ * - PASS: Control asserted and within bounds
179
+ * - WARN: Control exists but has drift/open findings
180
+ * - FAIL: Control invariant broken
181
+ * - SKIP: Control explicitly out-of-scope for this repo (requires evidence)
182
+ *
183
+ * SKIP rules:
184
+ * - Must include an evidence string explaining why out-of-scope
185
+ * - Is never blocking
186
+ * - Must be explicit (configured in soc2Baselines), not implicit
187
+ */
188
+ export type Soc2ControlStatus = 'PASS' | 'WARN' | 'FAIL' | 'SKIP';
189
+
190
+ /**
191
+ * Human-readable names for SOC 2 control areas.
192
+ */
193
+ export const SOC2_CONTROL_NAMES: Record<Soc2ControlArea, string> = {
194
+ CM: 'Change Management',
195
+ AC: 'Access Control',
196
+ LM: 'Logging & Monitoring',
197
+ SD: 'Secure SDLC',
198
+ BR: 'Backup & Recovery',
199
+ } as const;
200
+
201
+ /**
202
+ * All required SOC 2 controls.
203
+ * Aggregator fails if any control is missing from the output.
204
+ */
205
+ export const REQUIRED_SOC2_CONTROLS: readonly Soc2ControlArea[] = [
206
+ 'CM',
207
+ 'AC',
208
+ 'LM',
209
+ 'SD',
210
+ 'BR',
211
+ ] as const;
212
+
213
+ /**
214
+ * Controls that block CI when status is FAIL.
215
+ * Non-blocking controls report FAIL but don't set exit code to 1.
216
+ */
217
+ export const BLOCKING_SOC2_CONTROLS: readonly Soc2ControlArea[] = ['CM', 'AC'] as const;
218
+
219
+ /**
220
+ * A single SOC 2 control assertion result.
221
+ */
222
+ export interface Soc2ControlResult {
223
+ /** Control area code (e.g., 'CM', 'AC') */
224
+ area: Soc2ControlArea;
225
+ /** Human-readable control name (e.g., 'Change Management') */
226
+ name: string;
227
+ /** Control status */
228
+ status: Soc2ControlStatus;
229
+ /**
230
+ * Evidence describes PROCESS or EXISTENCE, not outcomes.
231
+ * Good: "PR reviews enforced on main", "Backup config present"
232
+ * Bad: "Secure", "Compliant", "Safe"
233
+ */
234
+ evidence: string;
235
+ /** Whether this control blocks CI when status is FAIL */
236
+ blocking: boolean;
237
+ /**
238
+ * Control version for SOC 2 Type II audit trail.
239
+ * Increment when control definition changes materially.
240
+ */
241
+ controlVersion: number;
242
+ /** Underlying guard messages that contributed to this status (if any) */
243
+ messages?: GuardMessage[];
244
+ }
245
+
246
+ /**
247
+ * SOC 2 compliance snapshot output.
248
+ * This is the top-level structure emitted when --soc2 flag is used.
249
+ */
250
+ export interface Soc2ComplianceOutput {
251
+ /** ISO 8601 timestamp of when the compliance check ran */
252
+ timestamp: string;
253
+ /** Repository name */
254
+ repository: string;
255
+ /** Git commit SHA */
256
+ commitSha: string;
257
+ /** CI run ID (if available) */
258
+ ciRunId?: string;
259
+ /** CI run URL (if available) */
260
+ ciRunUrl?: string;
261
+ /** All control results (must include all REQUIRED_SOC2_CONTROLS) */
262
+ controls: Soc2ControlResult[];
263
+ /** Overall pass/fail based on blocking controls only */
264
+ overallStatus: 'PASS' | 'FAIL';
265
+ }
266
+
267
+ /**
268
+ * Current SOC 2 compliance schema version.
269
+ * Bump on breaking schema changes.
270
+ */
271
+ export const SOC2_SCHEMA_VERSION = '1.0.0';
package/src/index.ts CHANGED
@@ -30,16 +30,23 @@ export type {
30
30
  SystemCapability,
31
31
  SystemLayer,
32
32
  SystemCapabilityManifest,
33
- // Graph-based diagram spec (v0.18.0)
33
+ // Graph-based diagram spec (v0.19.0)
34
34
  DiagramNodeKind,
35
35
  DiagramEdgeRelation,
36
36
  EdgeDirection,
37
37
  FlowStage,
38
+ PipelinePhase,
38
39
  DiagramMode,
39
40
  DiagramNode,
40
41
  DiagramEdge,
41
42
  DiagramSpec,
42
43
  DiagramSnapshot,
44
+ // Repository capability types (v0.20.0)
45
+ RepoId,
46
+ CapabilityInvariants,
47
+ RepoCapability,
48
+ CapabilityManifest,
49
+ AggregatedCapabilities,
43
50
  } from './system/index.js'
44
51
 
45
52
  // Guard types (CI guard vocabulary)
@@ -61,6 +68,7 @@ export type {
61
68
  ScriptsDepsBaseline,
62
69
  EvolutionBaselines,
63
70
  ContractsFreshnessBaseline,
71
+ CoverageBaseline,
64
72
  MetaBaselines,
65
73
  } from './guards/index.js'
66
74
 
@@ -76,3 +84,19 @@ export {
76
84
  // @see ADR-2025-12-011 for design rationale
77
85
  export { COMPATIBILITY } from './compatibility.js'
78
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'
@@ -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
+ }
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Repository Capability Types
3
+ *
4
+ * Types for cross-repo capability registration and aggregation.
5
+ * Used by the system diagram to render repo-level features.
6
+ *
7
+ * Promoted from company-semantics-control/system-diagram/contracts/
8
+ *
9
+ * INVARIANTS:
10
+ * - RepoCapability is a strict superset of DiagramNode
11
+ * - Aggregation transforms RepoCapability → DiagramNode (validate + normalize only)
12
+ * - No semantic changes during aggregation
13
+ * - flowStage is required on repo-level nodes (primary organizing axis)
14
+ *
15
+ * @see ADR-CONTRACTS-NNN in DECISIONS.md
16
+ */
17
+
18
+ import type { DiagramNode, FlowStage, FeatureStatus } from './index.js'
19
+
20
+ // =============================================================================
21
+ // Types
22
+ // =============================================================================
23
+
24
+ /**
25
+ * Valid repository identifiers.
26
+ * Add new repos here as the system grows.
27
+ */
28
+ export type RepoId =
29
+ | 'backend'
30
+ | 'edge'
31
+ | 'app'
32
+ | 'site'
33
+ | 'ci'
34
+ | 'contracts'
35
+ | 'control'
36
+
37
+ /**
38
+ * Semantic invariants for a capability.
39
+ * Used for CI drift detection and diagram styling.
40
+ */
41
+ export interface CapabilityInvariants {
42
+ /** Does this capability invoke LLM/AI APIs? */
43
+ llmCalls: boolean
44
+
45
+ /** Is this an authority boundary (trust/gateway)? */
46
+ authority: boolean
47
+
48
+ /** Can this capability write to strategy/goals? */
49
+ writesStrategy: boolean
50
+ }
51
+
52
+ /**
53
+ * Repository Capability
54
+ *
55
+ * Extends DiagramNode with repo-specific fields.
56
+ * This is what each repo declares in their capabilities.ts.
57
+ *
58
+ * CRITICAL: This extends DiagramNode — do NOT add fields that duplicate
59
+ * or conflict with DiagramNode fields.
60
+ */
61
+ export interface RepoCapability extends DiagramNode {
62
+ /**
63
+ * Which repository owns this capability.
64
+ * Used for aggregation grouping and validation.
65
+ */
66
+ repo: RepoId
67
+
68
+ /**
69
+ * Whether this capability should appear in public diagrams.
70
+ * - true: visible on marketing site, docs
71
+ * - false: internal only, visible in app
72
+ */
73
+ public: boolean
74
+
75
+ /**
76
+ * Architecture layer for horizontal organization.
77
+ * Required for repo-level nodes. The primary organizing axis.
78
+ * Children inherit unless explicitly overridden.
79
+ */
80
+ flowStage?: FlowStage
81
+
82
+ /**
83
+ * Stage-level edges for flow projection.
84
+ * References other capability IDs in format: `repo:domain:capability`
85
+ *
86
+ * Example: ['backend:semantic:processing', 'backend:graph:storage']
87
+ */
88
+ flowsTo?: string[]
89
+
90
+ /**
91
+ * Whether this capability is exported at the architecture level.
92
+ * Exported capabilities represent repo boundaries and API surfaces.
93
+ * Visible in 'architecture' mode.
94
+ */
95
+ exported?: boolean
96
+
97
+ /**
98
+ * Semantic invariants for CI validation.
99
+ * Optional - defaults applied per-repo during aggregation.
100
+ */
101
+ invariants?: Partial<CapabilityInvariants>
102
+ }
103
+
104
+ /**
105
+ * Manifest of capabilities from a single repository.
106
+ *
107
+ * NOTE: No version field — add when actually needed for:
108
+ * - CI compatibility checks
109
+ * - Schema evolution
110
+ * - Breaking capability changes
111
+ */
112
+ export interface CapabilityManifest {
113
+ /** Which repository this manifest is from */
114
+ repo: RepoId
115
+
116
+ /** All capabilities declared by this repo */
117
+ capabilities: RepoCapability[]
118
+ }
119
+
120
+ /**
121
+ * Aggregated capabilities from all repositories.
122
+ * Output of the aggregation step.
123
+ */
124
+ export interface AggregatedCapabilities {
125
+ /** All capabilities from all repos, validated */
126
+ capabilities: RepoCapability[]
127
+
128
+ /** Which repos contributed to this aggregation */
129
+ repos: RepoId[]
130
+
131
+ /** ISO timestamp of aggregation */
132
+ aggregatedAt: string
133
+ }
134
+
135
+ // =============================================================================
136
+ // Re-exports for convenience
137
+ // =============================================================================
138
+
139
+ export type { FeatureStatus, FlowStage }
@@ -80,3 +80,12 @@ export type {
80
80
  DiagramSpec,
81
81
  DiagramSnapshot,
82
82
  } from './diagram.js'
83
+
84
+ // Repository capability types
85
+ export type {
86
+ RepoId,
87
+ CapabilityInvariants,
88
+ RepoCapability,
89
+ CapabilityManifest,
90
+ AggregatedCapabilities,
91
+ } from './capabilities.js'