@lssm/example.locale-jurisdiction-gate 0.0.0-canary-20251217060834 → 0.0.0-canary-20251217063201
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/.turbo/turbo-build$colon$bundle.log +197 -40
- package/.turbo/turbo-build.log +43 -41
- package/CHANGELOG.md +3 -3
- package/dist/contracts/assistant.d.ts +59 -59
- package/dist/contracts/assistant.js +1 -1
- package/dist/docs/locale-jurisdiction-gate.docblock.js +1 -1
- package/dist/entities/models.d.ts +48 -48
- package/dist/entities/models.js +1 -1
- package/dist/events.d.ts +1 -1
- package/dist/events.js +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/libs/contracts/dist/capabilities/openbanking.js +1 -0
- package/dist/libs/contracts/dist/client/index.js +1 -0
- package/dist/libs/contracts/dist/client/react/feature-render.js +1 -0
- package/dist/libs/contracts/dist/client/react/form-render.js +1 -0
- package/dist/libs/contracts/dist/client/react/index.js +1 -0
- package/dist/libs/contracts/dist/contract-registry/index.js +1 -0
- package/dist/libs/contracts/dist/contract-registry/schemas.js +1 -0
- package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +76 -0
- package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +350 -0
- package/dist/libs/contracts/dist/docs/index.js +1 -0
- package/dist/libs/contracts/dist/docs/presentations.js +1 -0
- package/dist/libs/contracts/dist/docs/registry.js +1 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +383 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +68 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +140 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +86 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +1 -0
- package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +58 -0
- package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +38 -0
- package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +213 -0
- package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +289 -0
- package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +1 -0
- package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +1 -0
- package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +262 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +1 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +57 -0
- package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +63 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +36 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +1 -0
- package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +20 -0
- package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +65 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +1 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +41 -0
- package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +122 -0
- package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +1 -0
- package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +68 -0
- package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +1 -0
- package/dist/libs/contracts/dist/events.js +1 -0
- package/dist/libs/contracts/dist/experiments/evaluator.js +1 -0
- package/dist/libs/contracts/dist/index.js +1 -0
- package/dist/libs/contracts/dist/install.js +1 -0
- package/dist/libs/contracts/dist/integrations/contracts.js +1 -0
- package/dist/libs/contracts/dist/integrations/index.js +1 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/accounts.js +1 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/balances.js +1 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/index.js +1 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/transactions.js +1 -0
- package/dist/libs/contracts/dist/integrations/openbanking/models.js +1 -0
- package/dist/libs/contracts/dist/integrations/openbanking/telemetry.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/elevenlabs.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/gcs-storage.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/gmail.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/google-calendar.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/index.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/mistral.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/postmark.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/powens.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/qdrant.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/registry.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/stripe.js +1 -0
- package/dist/libs/contracts/dist/integrations/providers/twilio-sms.js +1 -0
- package/dist/libs/contracts/dist/jsonschema.js +1 -0
- package/dist/libs/contracts/dist/knowledge/contracts.js +1 -0
- package/dist/libs/contracts/dist/knowledge/index.js +1 -0
- package/dist/libs/contracts/dist/knowledge/spaces/email-threads.js +1 -0
- package/dist/libs/contracts/dist/knowledge/spaces/financial-docs.js +1 -0
- package/dist/libs/contracts/dist/knowledge/spaces/financial-overview.js +1 -0
- package/dist/libs/contracts/dist/knowledge/spaces/index.js +1 -0
- package/dist/libs/contracts/dist/knowledge/spaces/product-canon.js +1 -0
- package/dist/libs/contracts/dist/knowledge/spaces/support-faq.js +1 -0
- package/dist/libs/contracts/dist/knowledge/spaces/uploaded-docs.js +1 -0
- package/dist/libs/contracts/dist/llm/exporters.js +1 -0
- package/dist/libs/contracts/dist/llm/index.js +1 -0
- package/dist/libs/contracts/dist/llm/prompts.js +1 -0
- package/dist/libs/contracts/dist/onboarding-base.js +1 -0
- package/dist/libs/contracts/dist/openapi.js +1 -0
- package/dist/libs/contracts/dist/ownership.js +1 -0
- package/dist/libs/contracts/dist/presentations.js +1 -0
- package/dist/libs/contracts/dist/presentations.v2.js +1 -0
- package/dist/libs/contracts/dist/prompt.js +1 -0
- package/dist/libs/contracts/dist/promptRegistry.js +1 -0
- package/dist/libs/contracts/dist/regenerator/index.js +1 -0
- package/dist/libs/contracts/dist/regenerator/service.js +1 -0
- package/dist/libs/contracts/dist/registry.js +1 -0
- package/dist/libs/contracts/dist/resources.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/EnumType.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/FieldType.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/ScalarTypeEnum.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/SchemaModel.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/entity/defineEntity.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/entity/index.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/entity/types.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/index.js +1 -0
- package/dist/libs/contracts/dist/server/graphql-pothos.js +1 -0
- package/dist/libs/contracts/dist/server/index.js +1 -0
- package/dist/libs/contracts/dist/server/mcp/createMcpServer.js +1 -0
- package/dist/libs/contracts/dist/server/mcp/registerPresentations.js +1 -0
- package/dist/libs/contracts/dist/server/mcp/registerPrompts.js +1 -0
- package/dist/libs/contracts/dist/server/mcp/registerResources.js +1 -0
- package/dist/libs/contracts/dist/server/mcp/registerTools.js +1 -0
- package/dist/libs/contracts/dist/server/provider-mcp.js +1 -0
- package/dist/libs/contracts/dist/server/rest-elysia.js +1 -0
- package/dist/libs/contracts/dist/server/rest-express.js +1 -0
- package/dist/libs/contracts/dist/server/rest-generic.js +1 -0
- package/dist/libs/contracts/dist/server/rest-next-app.js +1 -0
- package/dist/libs/contracts/dist/server/rest-next-pages.js +1 -0
- package/dist/libs/contracts/dist/spec.js +1 -0
- package/dist/libs/contracts/dist/telemetry/index.js +1 -0
- package/dist/libs/contracts/dist/telemetry/tracker.js +1 -0
- package/dist/libs/contracts/dist/tests/index.js +1 -0
- package/dist/libs/contracts/dist/tests/runner.js +1 -0
- package/dist/libs/contracts/dist/workflow/index.js +1 -0
- package/dist/libs/contracts/dist/workflow/runner.js +1 -0
- package/dist/libs/schema/dist/EnumType.js +1 -0
- package/dist/libs/schema/dist/FieldType.js +1 -0
- package/dist/libs/schema/dist/ScalarTypeEnum.js +1 -0
- package/dist/libs/schema/dist/SchemaModel.js +1 -0
- package/dist/libs/schema/dist/entity/defineEntity.js +1 -0
- package/dist/libs/schema/dist/entity/index.js +1 -0
- package/dist/libs/schema/dist/entity/types.js +1 -0
- package/dist/libs/schema/dist/index.js +1 -0
- package/package.json +5 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import{a as e}from"../registry.js";e([{id:`docs.tech.PHASE_1_QUICKSTART`,title:`Phase 1: API Reference Index`,summary:`Quick reference for all new Phase 1 APIs.`,kind:`reference`,visibility:`public`,route:`/docs/tech/PHASE_1_QUICKSTART`,tags:[`tech`,`PHASE_1_QUICKSTART`],body:`# Phase 1: API Reference Index
|
|
2
|
+
|
|
3
|
+
Quick reference for all new Phase 1 APIs.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## @lssm/lib.multi-tenancy
|
|
8
|
+
|
|
9
|
+
### RLS
|
|
10
|
+
\`\`\`typescript
|
|
11
|
+
import { createRlsMiddleware, type TenantIdProvider } from '@lssm/lib.multi-tenancy/rls';
|
|
12
|
+
\`\`\`
|
|
13
|
+
|
|
14
|
+
### Provisioning
|
|
15
|
+
\`\`\`typescript
|
|
16
|
+
import {
|
|
17
|
+
TenantProvisioningService,
|
|
18
|
+
type CreateTenantInput,
|
|
19
|
+
type TenantProvisioningConfig
|
|
20
|
+
} from '@lssm/lib.multi-tenancy/provisioning';
|
|
21
|
+
\`\`\`
|
|
22
|
+
|
|
23
|
+
### Isolation
|
|
24
|
+
\`\`\`typescript
|
|
25
|
+
import { IsolationValidator } from '@lssm/lib.multi-tenancy/isolation';
|
|
26
|
+
\`\`\`
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## @lssm/lib.observability
|
|
31
|
+
|
|
32
|
+
### Tracing
|
|
33
|
+
\`\`\`typescript
|
|
34
|
+
import {
|
|
35
|
+
getTracer,
|
|
36
|
+
traceAsync,
|
|
37
|
+
traceSync,
|
|
38
|
+
createTracingMiddleware
|
|
39
|
+
} from '@lssm/lib.observability/tracing';
|
|
40
|
+
\`\`\`
|
|
41
|
+
|
|
42
|
+
### Metrics
|
|
43
|
+
\`\`\`typescript
|
|
44
|
+
import {
|
|
45
|
+
getMeter,
|
|
46
|
+
createCounter,
|
|
47
|
+
createUpDownCounter,
|
|
48
|
+
createHistogram,
|
|
49
|
+
standardMetrics
|
|
50
|
+
} from '@lssm/lib.observability/metrics';
|
|
51
|
+
\`\`\`
|
|
52
|
+
|
|
53
|
+
### Logging
|
|
54
|
+
\`\`\`typescript
|
|
55
|
+
import {
|
|
56
|
+
Logger,
|
|
57
|
+
logger,
|
|
58
|
+
type LogLevel,
|
|
59
|
+
type LogEntry
|
|
60
|
+
} from '@lssm/lib.observability/logging';
|
|
61
|
+
\`\`\`
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## @lssm/lib.resilience
|
|
66
|
+
|
|
67
|
+
### Circuit Breaker
|
|
68
|
+
\`\`\`typescript
|
|
69
|
+
import {
|
|
70
|
+
CircuitBreaker,
|
|
71
|
+
type CircuitState,
|
|
72
|
+
type CircuitBreakerConfig
|
|
73
|
+
} from '@lssm/lib.resilience/circuit-breaker';
|
|
74
|
+
\`\`\`
|
|
75
|
+
|
|
76
|
+
### Retry
|
|
77
|
+
\`\`\`typescript
|
|
78
|
+
import { retry } from '@lssm/lib.resilience/retry';
|
|
79
|
+
\`\`\`
|
|
80
|
+
|
|
81
|
+
### Timeout
|
|
82
|
+
\`\`\`typescript
|
|
83
|
+
import { timeout } from '@lssm/lib.resilience/timeout';
|
|
84
|
+
\`\`\`
|
|
85
|
+
|
|
86
|
+
### Fallback
|
|
87
|
+
\`\`\`typescript
|
|
88
|
+
import { fallback } from '@lssm/lib.resilience/fallback';
|
|
89
|
+
\`\`\`
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Enhanced: @lssm/lib.contracts
|
|
94
|
+
|
|
95
|
+
### DataViews
|
|
96
|
+
\`\`\`typescript
|
|
97
|
+
import { DataViewQueryGenerator } from '@lssm/lib.contracts/data-views/query-generator';
|
|
98
|
+
import { DataViewRuntime } from '@lssm/lib.contracts/data-views/runtime';
|
|
99
|
+
\`\`\`
|
|
100
|
+
|
|
101
|
+
### Workflows
|
|
102
|
+
\`\`\`typescript
|
|
103
|
+
import { SLAMonitor, type SLABreachEvent } from '@lssm/lib.contracts/workflow/sla-monitor';
|
|
104
|
+
import { PrismaStateStore } from '@lssm/lib.contracts/workflow/adapters/db-adapter';
|
|
105
|
+
\`\`\`
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Enhanced: @lssm/lib.design-system
|
|
110
|
+
|
|
111
|
+
### DataView Components
|
|
112
|
+
\`\`\`typescript
|
|
113
|
+
import { DataViewRenderer } from '@lssm/lib.design-system/components/data-view/DataViewRenderer';
|
|
114
|
+
// Also available: DataViewList, DataViewTable, DataViewDetail
|
|
115
|
+
\`\`\`
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Usage Examples
|
|
120
|
+
|
|
121
|
+
### Complete Workflow with All Features
|
|
122
|
+
|
|
123
|
+
\`\`\`typescript
|
|
124
|
+
import { WorkflowRunner } from '@lssm/lib.contracts/workflow/runner';
|
|
125
|
+
import { PrismaStateStore } from '@lssm/lib.contracts/workflow/adapters/db-adapter';
|
|
126
|
+
import { SLAMonitor } from '@lssm/lib.contracts/workflow/sla-monitor';
|
|
127
|
+
import { CircuitBreaker } from '@lssm/lib.resilience/circuit-breaker';
|
|
128
|
+
import { traceAsync } from '@lssm/lib.observability/tracing';
|
|
129
|
+
|
|
130
|
+
const runner = new WorkflowRunner({
|
|
131
|
+
registry,
|
|
132
|
+
stateStore: new PrismaStateStore(db),
|
|
133
|
+
opExecutor: async (op, input, ctx) => {
|
|
134
|
+
return traceAsync(\`op.\${op.name}\`, async (span) => {
|
|
135
|
+
span.setAttribute('operation', op.name);
|
|
136
|
+
const breaker = getCircuitBreaker(op.name);
|
|
137
|
+
return breaker.execute(() => executeOperation(op, input, ctx));
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
eventEmitter: (event, payload) => {
|
|
141
|
+
if (event.startsWith('workflow.')) {
|
|
142
|
+
logger.info(event, payload);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const monitor = new SLAMonitor((event, payload) => {
|
|
148
|
+
logger.warn('SLA_BREACH', payload);
|
|
149
|
+
alertOps(payload);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Start workflow
|
|
153
|
+
const workflowId = await runner.start('payment.flow', 1);
|
|
154
|
+
|
|
155
|
+
// Monitor SLA
|
|
156
|
+
const state = await runner.getState(workflowId);
|
|
157
|
+
const spec = registry.get('payment.flow', 1);
|
|
158
|
+
monitor.check(state, spec!);
|
|
159
|
+
\`\`\`
|
|
160
|
+
|
|
161
|
+
### Complete DataView with Observability
|
|
162
|
+
|
|
163
|
+
\`\`\`typescript
|
|
164
|
+
import { DataViewRenderer } from '@lssm/lib.design-system';
|
|
165
|
+
import { DataViewQueryGenerator } from '@lssm/lib.contracts/data-views/query-generator';
|
|
166
|
+
import { traceAsync } from '@lssm/lib.observability/tracing';
|
|
167
|
+
import { MyDataView } from './specs/users.data-view';
|
|
168
|
+
|
|
169
|
+
export function UserListPage() {
|
|
170
|
+
const [page, setPage] = useState(1);
|
|
171
|
+
const [users, setUsers] = useState([]);
|
|
172
|
+
|
|
173
|
+
const loadUsers = async () => {
|
|
174
|
+
return traceAsync('load_users', async (span) => {
|
|
175
|
+
const generator = new DataViewQueryGenerator(MyDataView);
|
|
176
|
+
const query = generator.generate({ pagination: { page, pageSize: 20 } });
|
|
177
|
+
|
|
178
|
+
span.setAttribute('page', page);
|
|
179
|
+
const result = await api.execute(query);
|
|
180
|
+
setUsers(result.data);
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<DataViewRenderer
|
|
186
|
+
spec={MyDataView}
|
|
187
|
+
items={users}
|
|
188
|
+
pagination={{ page, pageSize: 20, total: users.length }}
|
|
189
|
+
onPageChange={setPage}
|
|
190
|
+
/>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
\`\`\`
|
|
194
|
+
|
|
195
|
+
### Complete Multi-Tenant Setup
|
|
196
|
+
|
|
197
|
+
\`\`\`typescript
|
|
198
|
+
// 1. RLS Middleware
|
|
199
|
+
import { createRlsMiddleware } from '@lssm/lib.multi-tenancy/rls';
|
|
200
|
+
db.$use(createRlsMiddleware(() => req.tenantId));
|
|
201
|
+
|
|
202
|
+
// 2. Tenant Provisioning
|
|
203
|
+
import { TenantProvisioningService } from '@lssm/lib.multi-tenancy/provisioning';
|
|
204
|
+
const service = new TenantProvisioningService({ db });
|
|
205
|
+
|
|
206
|
+
// 3. Create new tenant
|
|
207
|
+
await service.provision({
|
|
208
|
+
id: 'acme',
|
|
209
|
+
name: 'Acme Corp',
|
|
210
|
+
slug: 'acme',
|
|
211
|
+
ownerEmail: 'admin@acme.com',
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// 4. Validate isolation in tests
|
|
215
|
+
import { IsolationValidator } from '@lssm/lib.multi-tenancy/isolation';
|
|
216
|
+
|
|
217
|
+
test('queries are isolated', () => {
|
|
218
|
+
const isValid = IsolationValidator.validateQuery(
|
|
219
|
+
'User',
|
|
220
|
+
'findMany',
|
|
221
|
+
{ where: { tenantId: 'acme' } },
|
|
222
|
+
'acme'
|
|
223
|
+
);
|
|
224
|
+
expect(isValid).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
\`\`\`
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Testing
|
|
231
|
+
|
|
232
|
+
### Test Circuit Breakers
|
|
233
|
+
|
|
234
|
+
\`\`\`typescript
|
|
235
|
+
import { CircuitBreaker } from '@lssm/lib.resilience/circuit-breaker';
|
|
236
|
+
|
|
237
|
+
test('circuit opens after threshold', async () => {
|
|
238
|
+
const breaker = new CircuitBreaker({
|
|
239
|
+
failureThreshold: 3,
|
|
240
|
+
resetTimeoutMs: 5000,
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// Trigger failures
|
|
244
|
+
for (let i = 0; i < 3; i++) {
|
|
245
|
+
await expect(
|
|
246
|
+
breaker.execute(() => Promise.reject('error'))
|
|
247
|
+
).rejects.toThrow();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Circuit should be open
|
|
251
|
+
await expect(
|
|
252
|
+
breaker.execute(() => Promise.resolve('ok'))
|
|
253
|
+
).rejects.toThrow('CircuitBreaker is OPEN');
|
|
254
|
+
});
|
|
255
|
+
\`\`\`
|
|
256
|
+
|
|
257
|
+
### Test Workflow Retry
|
|
258
|
+
|
|
259
|
+
\`\`\`typescript
|
|
260
|
+
test('workflow retries on failure', async () => {
|
|
261
|
+
let attempts = 0;
|
|
262
|
+
const opExecutor = async () => {
|
|
263
|
+
attempts++;
|
|
264
|
+
if (attempts < 3) throw new Error('fail');
|
|
265
|
+
return 'success';
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const runner = new WorkflowRunner({ /* ... */ opExecutor });
|
|
269
|
+
await runner.executeStep(workflowId);
|
|
270
|
+
|
|
271
|
+
expect(attempts).toBe(3);
|
|
272
|
+
});
|
|
273
|
+
\`\`\`
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Common Patterns
|
|
278
|
+
|
|
279
|
+
### Pattern: Resilient External Call
|
|
280
|
+
|
|
281
|
+
\`\`\`typescript
|
|
282
|
+
import { CircuitBreaker } from '@lssm/lib.resilience/circuit-breaker';
|
|
283
|
+
import { retry } from '@lssm/lib.resilience/retry';
|
|
284
|
+
import { timeout } from '@lssm/lib.resilience/timeout';
|
|
285
|
+
import { traceAsync } from '@lssm/lib.observability/tracing';
|
|
286
|
+
|
|
287
|
+
const breaker = new CircuitBreaker({ failureThreshold: 5, resetTimeoutMs: 30000 });
|
|
288
|
+
|
|
289
|
+
export async function callExternalAPI(input: any) {
|
|
290
|
+
return traceAsync('external_api_call', async (span) => {
|
|
291
|
+
span.setAttribute('service', 'stripe');
|
|
292
|
+
|
|
293
|
+
return breaker.execute(() =>
|
|
294
|
+
retry(
|
|
295
|
+
() => timeout(() => stripe.api.call(input), 5000),
|
|
296
|
+
3,
|
|
297
|
+
1000,
|
|
298
|
+
true
|
|
299
|
+
)
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
\`\`\`
|
|
304
|
+
|
|
305
|
+
**Benefits**: Circuit breaker + retry + timeout + tracing in one place.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
### Pattern: Tenant-Aware Operation
|
|
310
|
+
|
|
311
|
+
\`\`\`typescript
|
|
312
|
+
import { traceAsync } from '@lssm/lib.observability/tracing';
|
|
313
|
+
|
|
314
|
+
export async function listUsers(tenantId: string) {
|
|
315
|
+
return traceAsync('list_users', async (span) => {
|
|
316
|
+
span.setAttribute('tenant_id', tenantId);
|
|
317
|
+
|
|
318
|
+
// RLS middleware will inject WHERE tenantId = ?
|
|
319
|
+
return db.user.findMany();
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
\`\`\`
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
### Pattern: Monitored Workflow
|
|
327
|
+
|
|
328
|
+
\`\`\`typescript
|
|
329
|
+
import { WorkflowRunner } from '@lssm/lib.contracts/workflow/runner';
|
|
330
|
+
import { SLAMonitor } from '@lssm/lib.contracts/workflow/sla-monitor';
|
|
331
|
+
import { logger } from '@lssm/lib.observability/logging';
|
|
332
|
+
|
|
333
|
+
const monitor = new SLAMonitor((event, payload) => {
|
|
334
|
+
logger.warn('workflow.sla_breach', payload);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// In workflow poller
|
|
338
|
+
const state = await runner.getState(workflowId);
|
|
339
|
+
const spec = registry.get(state.workflowName, state.workflowVersion);
|
|
340
|
+
if (spec) {
|
|
341
|
+
monitor.check(state, spec);
|
|
342
|
+
}
|
|
343
|
+
\`\`\`
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Next Steps
|
|
348
|
+
|
|
349
|
+
1. **Implement one quick win** (30 minutes)
|
|
350
|
+
2. **Add tests for new functionality** (1 hour)
|
|
351
|
+
3. **Deploy to staging and verify observability** (1 hour)
|
|
352
|
+
4. **Roll out to production** (monitor closely)
|
|
353
|
+
5. **Read full documentation** at https://contractspec.lssm.tech/docs
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
**Questions?** See \`/docs/guides/phase-1-migration\` or reach out via https://contractspec.lssm.tech/contact
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
`}]);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import{a as e}from"../registry.js";e([{id:`docs.tech.PHASE_2_AI_NATIVE_OPERATIONS`,title:`Phase 2: AI-Native Operations`,summary:`_Last updated: 2025-11-20_`,kind:`reference`,visibility:`public`,route:`/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS`,tags:[`tech`,`PHASE_2_AI_NATIVE_OPERATIONS`],body:`# Phase 2: AI-Native Operations
|
|
2
|
+
|
|
3
|
+
_Last updated: 2025-11-20_
|
|
4
|
+
|
|
5
|
+
Phase 2 turns ContractSpec into an AI-first operations stack. The new libraries below are the building blocks used by support bots, growth agents, and human-in-the-loop flows.
|
|
6
|
+
|
|
7
|
+
## Libraries
|
|
8
|
+
|
|
9
|
+
### @lssm/lib.ai-agent
|
|
10
|
+
|
|
11
|
+
- **Spec + Registry**: \`defineAgent\`, \`AgentRegistry\` keep agent definitions type-safe.
|
|
12
|
+
- **Runner**: \`AgentRunner\` drives LLM conversations, tool calls, retries, escalation, and telemetry hooks.
|
|
13
|
+
- **Tools**: \`ToolExecutor\` standardizes schema validation + timeouts.
|
|
14
|
+
- **Memory**: \`InMemoryAgentMemory\` + interfaces for plugging persistent stores.
|
|
15
|
+
- **Approvals**: new \`ApprovalWorkflow\` + \`InMemoryApprovalStore\` capture low-confidence decisions and surface them to reviewers.
|
|
16
|
+
|
|
17
|
+
### @lssm/lib.support-bot
|
|
18
|
+
|
|
19
|
+
Composable support automation primitives:
|
|
20
|
+
|
|
21
|
+
- \`TicketClassifier\` → heuristics + optional LLM validation for category, priority, sentiment.
|
|
22
|
+
- \`TicketResolver\` → RAG pipeline backed by knowledge spaces.
|
|
23
|
+
- \`AutoResponder\` → tone-aware drafts with citations.
|
|
24
|
+
- \`SupportFeedbackLoop\` → tracks resolution rates.
|
|
25
|
+
- \`createSupportTools\` → ready-made tool definitions for AgentRunner.
|
|
26
|
+
|
|
27
|
+
### @lssm/lib.content-gen
|
|
28
|
+
|
|
29
|
+
Content generators that consume a \`ContentBrief\` and output production-ready assets:
|
|
30
|
+
|
|
31
|
+
- \`BlogGenerator\`, \`LandingPageGenerator\`, \`EmailCampaignGenerator\`, \`SocialPostGenerator\`.
|
|
32
|
+
- \`SeoOptimizer\` builds metadata + schema markup.
|
|
33
|
+
|
|
34
|
+
### @lssm/lib.analytics
|
|
35
|
+
|
|
36
|
+
Queryless analytics helpers:
|
|
37
|
+
|
|
38
|
+
- \`FunnelAnalyzer\` – conversion/drop-off per step.
|
|
39
|
+
- \`CohortTracker\` – retention + LTV per cohort.
|
|
40
|
+
- \`ChurnPredictor\` – recency/frequency/error scoring.
|
|
41
|
+
- \`GrowthHypothesisGenerator\` – surfaces experiment ideas from metric trends.
|
|
42
|
+
|
|
43
|
+
### @lssm/lib.growth
|
|
44
|
+
|
|
45
|
+
A/B testing toolkit:
|
|
46
|
+
|
|
47
|
+
- \`ExperimentRegistry\` + \`ExperimentRunner\` – deterministic bucketing.
|
|
48
|
+
- \`ExperimentTracker\` – persist exposures + metrics.
|
|
49
|
+
- \`StatsEngine\` – Welch’s t-test + improvement calculations.
|
|
50
|
+
|
|
51
|
+
### Human-in-the-loop UI
|
|
52
|
+
|
|
53
|
+
\`@lssm/lib.design-system\` now exposes:
|
|
54
|
+
|
|
55
|
+
- \`ApprovalQueue\` – list + act on pending approvals.
|
|
56
|
+
- \`AgentMonitor\` – live view of agent sessions with confidence + status.
|
|
57
|
+
|
|
58
|
+
## Examples
|
|
59
|
+
|
|
60
|
+
- \`examples/ai-support-bot/setup.ts\` shows ticket classification → resolution → response draft.
|
|
61
|
+
- \`examples/content-generation/generate.ts\` produces blog, landing, email, social, SEO output from one brief.
|
|
62
|
+
|
|
63
|
+
## Next Steps
|
|
64
|
+
|
|
65
|
+
1. Wire these libraries into vertical apps (H-Circle, ArtisanOS, etc.).
|
|
66
|
+
2. Add background workers that consume the new analytics/growth trackers.
|
|
67
|
+
3. Expand web-landing to highlight these Phase 2 capabilities (see separate TODO).
|
|
68
|
+
`}]);
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import{a as e}from"../registry.js";e([{id:`docs.tech.PHASE_3_AUTO_EVOLUTION`,title:`Phase 3: Auto-Evolution Technical Notes`,summary:`**Status**: In progress`,kind:`reference`,visibility:`public`,route:`/docs/tech/PHASE_3_AUTO_EVOLUTION`,tags:[`tech`,`PHASE_3_AUTO_EVOLUTION`],body:`# Phase 3: Auto-Evolution Technical Notes
|
|
2
|
+
|
|
3
|
+
**Status**: In progress
|
|
4
|
+
**Last updated**: 2025-11-21
|
|
5
|
+
|
|
6
|
+
Phase 3 introduces self-learning capabilities that analyze production telemetry, suggest new specs, safely roll out variants, and generate golden tests from real traffic. This document captures the main building blocks delivered in this iteration.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 1. Libraries
|
|
11
|
+
|
|
12
|
+
### @lssm/lib.evolution
|
|
13
|
+
|
|
14
|
+
- \`SpecAnalyzer\` converts raw telemetry samples into usage stats + anomalies.
|
|
15
|
+
- \`SpecGenerator\` produces \`SpecSuggestion\` objects and validates confidence thresholds.
|
|
16
|
+
- \`SpecSuggestionOrchestrator\` routes proposals through the AI approval workflow and writes approved specs to \`packages/libs/contracts/src/generated\`.
|
|
17
|
+
- Storage adapters:
|
|
18
|
+
- \`InMemorySpecSuggestionRepository\` for tests.
|
|
19
|
+
- \`PrismaSpecSuggestionRepository\` persists to the new Prisma model (see §4).
|
|
20
|
+
- \`FileSystemSuggestionWriter\` emits JSON envelopes for git review.
|
|
21
|
+
|
|
22
|
+
### @lssm/lib.observability
|
|
23
|
+
|
|
24
|
+
- Added intent detection modules:
|
|
25
|
+
- \`IntentAggregator\` batches telemetry into rolling windows.
|
|
26
|
+
- \`IntentDetector\` surfaces latency/error/throughput regressions and sequential intents.
|
|
27
|
+
- \`EvolutionPipeline\` orchestrates aggregation → detection → intent events and exposes hooks for downstream orchestrators.
|
|
28
|
+
- \`createTracingMiddleware\` now accepts \`resolveOperation\`/\`onSample\` hooks to feed telemetry samples into the pipeline.
|
|
29
|
+
|
|
30
|
+
### @lssm/lib.growth
|
|
31
|
+
|
|
32
|
+
- New \`spec-experiments\` module:
|
|
33
|
+
- \`SpecExperimentRegistry\`, \`SpecExperimentRunner\`, \`SpecExperimentAdapter\`.
|
|
34
|
+
- \`SpecExperimentAnalyzer\` + \`SpecExperimentController\` handle guardrails and staged rollouts.
|
|
35
|
+
- Helper \`createSpecVariantResolver\` plugs directly into \`HandlerCtx.specVariantResolver\`.
|
|
36
|
+
- \`SpecVariantResolver\` is now a first-class concept in \`@lssm/lib.contracts\`. The runtime will attempt to execute variant specs before falling back to the registered handler.
|
|
37
|
+
|
|
38
|
+
### @lssm/lib.testing
|
|
39
|
+
|
|
40
|
+
- \`TrafficRecorder\` + \`TrafficStore\` capture production requests with sampling and sanitization hooks.
|
|
41
|
+
- \`GoldenTestGenerator\` converts \`TrafficSnapshot\`s into Vitest/Jest suites.
|
|
42
|
+
- \`generateVitestSuite\` / \`generateJestSuite\` output self-contained test files, and \`runGoldenTests\` offers a programmatic harness for CI pipelines.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 2. Telemetry → Intent → Spec Pipeline
|
|
47
|
+
|
|
48
|
+
1. \`createTracingMiddleware({ onSample })\` emits \`TelemetrySample\`s for every HTTP request.
|
|
49
|
+
2. \`IntentAggregator\` groups samples into statistical windows (default 15 minutes).
|
|
50
|
+
3. \`IntentDetector\` raises signals for:
|
|
51
|
+
- Error spikes
|
|
52
|
+
- Latency regressions
|
|
53
|
+
- Throughput drops
|
|
54
|
+
- Sequential workflows that hint at missing specs
|
|
55
|
+
4. \`EvolutionPipeline\` emits \`intent.detected\` events and hands them to \`SpecGenerator\`.
|
|
56
|
+
5. \`SpecSuggestionOrchestrator\` persists suggestions, triggers approval workflows, and—upon approval—writes JSON envelopes to \`packages/.../contracts/src/generated\`.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 3. Spec Experiments & Rollouts
|
|
61
|
+
|
|
62
|
+
1. Register spec experiments in \`SpecExperimentRegistry\` with control + variant bindings.
|
|
63
|
+
2. Expose bucketed specs by attaching \`createSpecVariantResolver\` to \`HandlerCtx.specVariantResolver\` inside adapters.
|
|
64
|
+
3. Record outcomes via \`SpecExperimentAdapter.trackOutcome()\` (latency + error metrics).
|
|
65
|
+
4. \`SpecExperimentController\` uses guardrails from config and \`SpecExperimentAnalyzer\` to:
|
|
66
|
+
- Auto-rollback on error/latency breaches.
|
|
67
|
+
- Advance rollout stages (1% → 10% → 50% → 100%) when metrics stay green.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 4. Data Models (Prisma)
|
|
72
|
+
|
|
73
|
+
File: \`packages/libs/database/prisma/schema.prisma\`
|
|
74
|
+
|
|
75
|
+
- \`SpecSuggestion\` – stores serialized suggestion payloads + statuses.
|
|
76
|
+
- \`IntentSnapshot\` – captured detector output for auditing/training.
|
|
77
|
+
- \`TrafficSnapshot\` – persisted production traffic (input/output/error blobs).
|
|
78
|
+
- \`SpecExperiment\` / \`SpecExperimentMetric\` – rollout state + metrics for each variant.
|
|
79
|
+
|
|
80
|
+
> Run \`bun database generate\` after pulling to refresh the Prisma client.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 5. Golden Test Workflow
|
|
85
|
+
|
|
86
|
+
1. Capture traffic via middleware or direct \`TrafficRecorder.record\`.
|
|
87
|
+
2. Use the new CLI command to materialize suites:
|
|
88
|
+
|
|
89
|
+
\`\`\`bash
|
|
90
|
+
contractspec test generate \\
|
|
91
|
+
--operation billing.createInvoice \\
|
|
92
|
+
--output tests/billing.createInvoice.golden.test.ts \\
|
|
93
|
+
--runner-import ./tests/run-operation \\
|
|
94
|
+
--runner-fn runBillingCommand \\
|
|
95
|
+
--from-production \\
|
|
96
|
+
--days 7 \\
|
|
97
|
+
--sample-rate 0.05
|
|
98
|
+
\`\`\`
|
|
99
|
+
|
|
100
|
+
3. Generated files import your runner and assert against recorded outputs (or expected errors for negative paths).
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 6. Operational Notes
|
|
105
|
+
|
|
106
|
+
- **Approvals**: By default, every suggestion still requires human approval. \`EvolutionConfig.autoApproveThreshold\` can be tuned per environment but should remain conservative (<0.3) until OverlaySpec tooling lands.
|
|
107
|
+
- **Sampling**: Keep \`TrafficRecorder.sampleRate\` ≤ 0.05 in production to avoid sensitive payload storage; scrub PII through the \`sanitize\` callback before persistence.
|
|
108
|
+
- **Rollouts**: Guardrails default to 5% error-rate and 750ms P99 latency. Override per experiment to match SLOs.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## 7. Next Steps
|
|
113
|
+
|
|
114
|
+
1. Wire \`SpecExperimentAdapter.trackOutcome\` into adapters (REST, GraphQL, Workers) so every execution logs metrics automatically.
|
|
115
|
+
2. Add a UI for reviewing \`SpecSuggestion\` objects alongside approval status.
|
|
116
|
+
3. Expand \`TrafficRecorder\` to ship directly to the Prisma-backed store (currently in-memory by default).
|
|
117
|
+
4. Integrate \`EvolutionPipeline\` events with the Regenerator to close the loop (auto-open proposals + attach evidence).
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
`}]);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import{a as e}from"../registry.js";e([{id:`docs.tech.PHASE_4_PERSONALIZATION_ENGINE`,title:`Phase 4: Personalization Engine`,summary:`**Status**: Complete`,kind:`reference`,visibility:`public`,route:`/docs/tech/PHASE_4_PERSONALIZATION_ENGINE`,tags:[`tech`,`PHASE_4_PERSONALIZATION_ENGINE`],body:`# Phase 4: Personalization Engine
|
|
2
|
+
|
|
3
|
+
**Status**: Complete
|
|
4
|
+
**Last updated**: 2025-11-21
|
|
5
|
+
|
|
6
|
+
Phase 4 unlocks tenant-scoped personalization with zero bespoke code. We shipped three new libraries, a signing-aware Overlay editor, and the persistence layer required to observe usage and apply overlays safely.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 1. Libraries
|
|
11
|
+
|
|
12
|
+
### @lssm/lib.overlay-engine
|
|
13
|
+
|
|
14
|
+
- OverlaySpec types + validator mirror the public spec.
|
|
15
|
+
- Cryptographic signer (\`ed25519\`, \`rsa-pss-sha256\`) with canonical JSON serialization.
|
|
16
|
+
- Registry that merges tenant/role/user/device overlays with predictable specificity.
|
|
17
|
+
- React hooks (\`useOverlay\`, \`useOverlayFields\`) for client-side rendering.
|
|
18
|
+
- Runtime engine audits every applied overlay for traceability.
|
|
19
|
+
|
|
20
|
+
### @lssm/lib.personalization
|
|
21
|
+
|
|
22
|
+
- Behavior tracker buffers field/feature/workflow events and exports OTel metrics.
|
|
23
|
+
- Analyzer summarizes field usage and workflow drop-offs into actionable insights.
|
|
24
|
+
- Adapter translates insights into overlay suggestions or workflow tweaks.
|
|
25
|
+
- In-memory store implementation + interface for plugging Prisma/ClickHouse later.
|
|
26
|
+
|
|
27
|
+
### @lssm/lib.workflow-composer
|
|
28
|
+
|
|
29
|
+
- \`WorkflowComposer\` merges base workflows with tenant/role/device extensions.
|
|
30
|
+
- Step injection utilities keep transitions intact and validate anchor steps.
|
|
31
|
+
- Template helpers for common tenant review/approval, plus merge helpers for multi-scope extensions.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 2. Overlay Editor App
|
|
36
|
+
|
|
37
|
+
Path: \`packages/apps/overlay-editor\`
|
|
38
|
+
|
|
39
|
+
- Next.js App Router UI for toggling field visibility, renaming labels, and reordering lists.
|
|
40
|
+
- Live JSON preview powered by \`defineOverlay\`.
|
|
41
|
+
- Server action that signs overlays via PEM private keys (Ed25519 by default) using the overlay engine signer.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 3. Persistence
|
|
46
|
+
|
|
47
|
+
Added Prisma models (see \`packages/libs/database/prisma/schema.prisma\`):
|
|
48
|
+
|
|
49
|
+
- \`UserBehaviorEvent\` – field/feature/workflow telemetry.
|
|
50
|
+
- \`OverlaySigningKey\` – tenant managed signing keys with revocation timestamps.
|
|
51
|
+
- \`Overlay\` – stored overlays (tenant/user/role/device scope) plus signature metadata.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 4. Integration Steps
|
|
56
|
+
|
|
57
|
+
1. Track usage inside apps via \`createBehaviorTracker\`.
|
|
58
|
+
2. Periodically run \`BehaviorAnalyzer.analyze\` to generate insights.
|
|
59
|
+
3. Convert insights into OverlaySpecs or Workflow extensions.
|
|
60
|
+
4. Register tenant overlays in \`OverlayRegistry\` and serve via presentation runtimes.
|
|
61
|
+
5. Compose workflows per tenant using \`WorkflowComposer\`.
|
|
62
|
+
|
|
63
|
+
See the \`docs/tech/personalization/*\` guides for concrete examples.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
`}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"../registry.js";e([{id:`docs.tech.PHASE_5_ZERO_TOUCH_OPERATIONS`,title:`Phase 5: Zero-Touch Operations`,summary:`**Status**: In progress`,kind:`reference`,visibility:`public`,route:`/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS`,tags:[`tech`,`PHASE_5_ZERO_TOUCH_OPERATIONS`],body:"# Phase 5: Zero-Touch Operations\n\n**Status**: In progress \n**Last updated**: 2025-11-21\n\nPhase 5 delivers progressive delivery, SLO intelligence, cost attribution, and anomaly-driven remediation so the platform can deploy continuously without pager rotations.\n\n---\n\n## 1. New Libraries\n\n### @lssm/lib.progressive-delivery\n- `DeploymentStrategy` types capture canary vs blue-green rollouts.\n- `CanaryController` + `CanaryAnalyzer` orchestrate stage evaluation against telemetry thresholds.\n- `TrafficShifter` keeps stable/candidate splits in sync with feature-flag or router state.\n- `DeploymentCoordinator` drives stage progression, emits events, and triggers rollbacks.\n- `RollbackManager` encapsulates safe revert hooks (spec version revert, traffic shift, etc.).\n\n### @lssm/lib.slo\n- Declarative `SLODefinition` with latency + availability targets per capability/spec.\n- `SLOTracker` stores rolling snapshots + error budget positions.\n- `BurnRateCalculator` implements multi-window burn computations (fast vs slow burn).\n- `SLOMonitor` pushes incidents to Ops tooling automatically when burn exceeds thresholds.\n\n### @lssm/lib.cost-tracking\n- `CostTracker` normalizes DB/API/compute metrics into per-operation cost totals.\n- `BudgetAlertManager` raises tenant budget warnings (80% default) with contextual payloads.\n- `OptimizationRecommender` suggests batching, caching, or contract tweaks to cut spend.\n\n### Observability Anomaly Toolkit\n- `BaselineCalculator` establishes rolling intent metrics (latency, error rate, throughput).\n- `AnomalyDetector` flags spikes/drops via relative deltas after 10+ samples.\n- `RootCauseAnalyzer` correlates anomalies with recent deployments.\n- `AlertManager` deduplicates notifications and feeds MCP/SRE transports.\n\n---\n\n## 2. Data Model Additions\n\nFile: `packages/libs/database/prisma/schema.prisma`\n\n| Model | Purpose |\n| --- | --- |\n| `SLODefinition`, `SLOSnapshot`, `ErrorBudget`, `SLOIncident` | Persist definitions, rolling windows, and incidents. |\n| `OperationCost`, `TenantBudget`, `CostAlert`, `OptimizationSuggestion` | Track per-operation costs, budgets, and generated recommendations. |\n| `Deployment`, `DeploymentStage`, `RollbackEvent` | Audit progressive delivery runs and automated rollbacks. |\n| `MetricBaseline`, `AnomalyEvent` | Store computed baselines and anomaly evidence for training/analytics. |\n\nRun `bun database generate` after pulling to refresh the Prisma client.\n\n---\n\n## 3. Operational Flow\n\n1. **Deploy**: Define a `DeploymentStrategy` and feed telemetry via `@lssm/lib.observability`. Canary stages run automatically.\n2. **Protect**: `CanaryAnalyzer` evaluates error rate + latency thresholds. Failures trigger `RollbackManager`.\n3. **Observe**: `SLOMonitor` consumes snapshots and opens incidents when burn rate exceeds thresholds.\n4. **Optimize**: `CostTracker` aggregates spend per tenant + capability, while `OptimizationRecommender` surfaces fixes.\n5. **Detect**: Anomaly signals route to `RootCauseAnalyzer`, which links them to specific deployments for auto-rollback.\n\n---\n\n## 4. Integration Checklist\n\n1. Instrument adapters with `createTracingMiddleware({ onSample })` to feed metric points into `AnomalyDetector`.\n2. Register SLOs per critical operation (`billing.charge`, `knowledge.search`) and wire monitors to Ops notifications.\n3. Attach `CostTracker.recordSample` to workflow runners (DB instrumentation + external call wrappers).\n4. Store deployment metadata using the new Prisma models for auditing + UI surfacing.\n5. Update `@lssm/app.ops-console` (next iteration) to list deployments, SLO status, costs, and anomalies in one timeline.\n\n---\n\n## 5. Next Steps\n\n- Wire `DeploymentCoordinator` into the Contracts CLI so `contractspec deploy` can run staged rollouts.\n- Add UI for SLO dashboards (burn rate sparkline + incident feed).\n- Ship budget suggestions into Growth Agent for automated cost optimizations.\n- Connect `AnomalyEvent` stream to MCP agents for root-cause playbooks.\n"}]);
|