@lssm/example.analytics-dashboard 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/dist/dashboard/dashboard.contracts.d.ts +131 -131
- package/dist/dashboard/dashboard.contracts.js +5 -5
- package/dist/dashboard/dashboard.enum.d.ts +4 -4
- package/dist/dashboard/dashboard.enum.js +5 -4
- package/dist/dashboard/dashboard.schema.d.ts +79 -79
- package/dist/dashboard/dashboard.schema.js +44 -42
- package/dist/docs/analytics-dashboard.docblock.js +3 -2
- package/dist/events.d.ts +40 -40
- package/dist/events.js +27 -24
- package/dist/index.d.ts +0 -1
- package/dist/libs/contracts/dist/capabilities/openbanking.js +84 -0
- package/dist/libs/contracts/dist/client/index.js +5 -0
- package/dist/libs/contracts/dist/client/react/feature-render.js +2 -0
- package/dist/libs/contracts/dist/client/react/form-render.js +4 -0
- package/dist/libs/contracts/dist/client/react/index.js +4 -0
- package/dist/libs/contracts/dist/contract-registry/index.js +1 -0
- package/dist/libs/contracts/dist/contract-registry/schemas.js +57 -0
- package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +91 -0
- package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +365 -0
- package/dist/libs/contracts/dist/docs/index.js +29 -0
- package/dist/libs/contracts/dist/docs/presentations.js +67 -0
- package/dist/libs/contracts/dist/docs/registry.js +42 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +398 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +83 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +155 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +101 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +80 -0
- package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +57 -0
- package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +228 -0
- package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +357 -0
- package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +21 -0
- package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +281 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +22 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +79 -0
- package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +84 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +57 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +22 -0
- package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +40 -0
- package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +86 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +22 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +62 -0
- package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +155 -0
- package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -0
- package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +101 -0
- package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -0
- package/dist/libs/contracts/dist/events.js +9 -0
- package/dist/libs/contracts/dist/experiments/evaluator.js +1 -0
- package/dist/libs/contracts/dist/index.js +71 -0
- package/dist/libs/contracts/dist/install.js +2 -0
- package/dist/libs/contracts/dist/integrations/contracts.js +371 -0
- package/dist/libs/contracts/dist/integrations/index.js +18 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/accounts.js +225 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/balances.js +157 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/index.js +3 -0
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/transactions.js +208 -0
- package/dist/libs/contracts/dist/integrations/openbanking/models.js +240 -0
- package/dist/libs/contracts/dist/integrations/openbanking/telemetry.js +24 -0
- package/dist/libs/contracts/dist/integrations/providers/elevenlabs.js +52 -0
- package/dist/libs/contracts/dist/integrations/providers/gcs-storage.js +75 -0
- package/dist/libs/contracts/dist/integrations/providers/gmail.js +87 -0
- package/dist/libs/contracts/dist/integrations/providers/google-calendar.js +66 -0
- package/dist/libs/contracts/dist/integrations/providers/index.js +11 -0
- package/dist/libs/contracts/dist/integrations/providers/mistral.js +68 -0
- package/dist/libs/contracts/dist/integrations/providers/postmark.js +68 -0
- package/dist/libs/contracts/dist/integrations/providers/powens.js +116 -0
- package/dist/libs/contracts/dist/integrations/providers/qdrant.js +73 -0
- package/dist/libs/contracts/dist/integrations/providers/registry.js +10 -0
- package/dist/libs/contracts/dist/integrations/providers/stripe.js +83 -0
- package/dist/libs/contracts/dist/integrations/providers/twilio-sms.js +61 -0
- package/dist/libs/contracts/dist/jsonschema.js +1 -0
- package/dist/libs/contracts/dist/knowledge/contracts.js +299 -0
- package/dist/libs/contracts/dist/knowledge/index.js +7 -0
- package/dist/libs/contracts/dist/knowledge/spaces/email-threads.js +34 -0
- package/dist/libs/contracts/dist/knowledge/spaces/financial-docs.js +34 -0
- package/dist/libs/contracts/dist/knowledge/spaces/financial-overview.js +38 -0
- package/dist/libs/contracts/dist/knowledge/spaces/index.js +6 -0
- package/dist/libs/contracts/dist/knowledge/spaces/product-canon.js +34 -0
- package/dist/libs/contracts/dist/knowledge/spaces/support-faq.js +37 -0
- package/dist/libs/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -0
- package/dist/libs/contracts/dist/llm/exporters.js +18 -0
- package/dist/libs/contracts/dist/llm/index.js +2 -0
- package/dist/libs/contracts/dist/llm/prompts.js +1 -0
- package/dist/libs/contracts/dist/onboarding-base.js +179 -0
- package/dist/libs/contracts/dist/openapi.js +1 -0
- package/dist/libs/contracts/dist/ownership.js +36 -0
- package/dist/libs/contracts/dist/presentations.js +1 -0
- package/dist/libs/contracts/dist/presentations.v2.js +7 -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 +2 -0
- package/dist/libs/contracts/dist/resources.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/EnumType.js +2 -0
- package/dist/libs/contracts/dist/schema/dist/FieldType.js +39 -0
- package/dist/libs/contracts/dist/schema/dist/ScalarTypeEnum.js +222 -0
- package/dist/libs/contracts/dist/schema/dist/SchemaModel.js +23 -0
- package/dist/libs/contracts/dist/schema/dist/entity/defineEntity.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/entity/index.js +2 -0
- package/dist/libs/contracts/dist/schema/dist/entity/types.js +1 -0
- package/dist/libs/contracts/dist/schema/dist/index.js +6 -0
- package/dist/libs/contracts/dist/server/graphql-pothos.js +6 -0
- package/dist/libs/contracts/dist/server/index.js +8 -0
- package/dist/libs/contracts/dist/server/mcp/createMcpServer.js +4 -0
- package/dist/libs/contracts/dist/server/mcp/registerPresentations.js +2 -0
- package/dist/libs/contracts/dist/server/mcp/registerPrompts.js +1 -0
- package/dist/libs/contracts/dist/server/mcp/registerResources.js +2 -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 +25 -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 +2 -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 +40 -0
- package/dist/libs/schema/dist/FieldType.js +39 -0
- package/dist/libs/schema/dist/ScalarTypeEnum.js +222 -0
- package/dist/libs/schema/dist/SchemaModel.js +24 -0
- package/dist/libs/schema/dist/entity/defineEntity.js +1 -0
- package/dist/libs/schema/dist/entity/index.js +2 -0
- package/dist/libs/schema/dist/entity/types.js +1 -0
- package/dist/libs/schema/dist/index.js +6 -0
- package/dist/query/query.contracts.d.ts +44 -44
- package/dist/query/query.contracts.js +3 -3
- package/dist/query/query.enum.d.ts +2 -2
- package/dist/query/query.enum.js +3 -2
- package/dist/query/query.schema.d.ts +34 -34
- package/dist/query/query.schema.js +34 -32
- package/package.json +10 -10
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { a } from "../registry.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js
|
|
4
|
+
const t = [{
|
|
5
|
+
id: `docs.tech.PHASE_4_PERSONALIZATION_ENGINE`,
|
|
6
|
+
title: `Phase 4: Personalization Engine`,
|
|
7
|
+
summary: `**Status**: Complete`,
|
|
8
|
+
kind: `reference`,
|
|
9
|
+
visibility: `public`,
|
|
10
|
+
route: `/docs/tech/PHASE_4_PERSONALIZATION_ENGINE`,
|
|
11
|
+
tags: [`tech`, `PHASE_4_PERSONALIZATION_ENGINE`],
|
|
12
|
+
body: `# Phase 4: Personalization Engine
|
|
13
|
+
|
|
14
|
+
**Status**: Complete
|
|
15
|
+
**Last updated**: 2025-11-21
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 1. Libraries
|
|
22
|
+
|
|
23
|
+
### @lssm/lib.overlay-engine
|
|
24
|
+
|
|
25
|
+
- OverlaySpec types + validator mirror the public spec.
|
|
26
|
+
- Cryptographic signer (\`ed25519\`, \`rsa-pss-sha256\`) with canonical JSON serialization.
|
|
27
|
+
- Registry that merges tenant/role/user/device overlays with predictable specificity.
|
|
28
|
+
- React hooks (\`useOverlay\`, \`useOverlayFields\`) for client-side rendering.
|
|
29
|
+
- Runtime engine audits every applied overlay for traceability.
|
|
30
|
+
|
|
31
|
+
### @lssm/lib.personalization
|
|
32
|
+
|
|
33
|
+
- Behavior tracker buffers field/feature/workflow events and exports OTel metrics.
|
|
34
|
+
- Analyzer summarizes field usage and workflow drop-offs into actionable insights.
|
|
35
|
+
- Adapter translates insights into overlay suggestions or workflow tweaks.
|
|
36
|
+
- In-memory store implementation + interface for plugging Prisma/ClickHouse later.
|
|
37
|
+
|
|
38
|
+
### @lssm/lib.workflow-composer
|
|
39
|
+
|
|
40
|
+
- \`WorkflowComposer\` merges base workflows with tenant/role/device extensions.
|
|
41
|
+
- Step injection utilities keep transitions intact and validate anchor steps.
|
|
42
|
+
- Template helpers for common tenant review/approval, plus merge helpers for multi-scope extensions.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 2. Overlay Editor App
|
|
47
|
+
|
|
48
|
+
Path: \`packages/apps/overlay-editor\`
|
|
49
|
+
|
|
50
|
+
- Next.js App Router UI for toggling field visibility, renaming labels, and reordering lists.
|
|
51
|
+
- Live JSON preview powered by \`defineOverlay\`.
|
|
52
|
+
- Server action that signs overlays via PEM private keys (Ed25519 by default) using the overlay engine signer.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 3. Persistence
|
|
57
|
+
|
|
58
|
+
Added Prisma models (see \`packages/libs/database/prisma/schema.prisma\`):
|
|
59
|
+
|
|
60
|
+
- \`UserBehaviorEvent\` – field/feature/workflow telemetry.
|
|
61
|
+
- \`OverlaySigningKey\` – tenant managed signing keys with revocation timestamps.
|
|
62
|
+
- \`Overlay\` – stored overlays (tenant/user/role/device scope) plus signature metadata.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## 4. Integration Steps
|
|
67
|
+
|
|
68
|
+
1. Track usage inside apps via \`createBehaviorTracker\`.
|
|
69
|
+
2. Periodically run \`BehaviorAnalyzer.analyze\` to generate insights.
|
|
70
|
+
3. Convert insights into OverlaySpecs or Workflow extensions.
|
|
71
|
+
4. Register tenant overlays in \`OverlayRegistry\` and serve via presentation runtimes.
|
|
72
|
+
5. Compose workflows per tenant using \`WorkflowComposer\`.
|
|
73
|
+
|
|
74
|
+
See the \`docs/tech/personalization/*\` guides for concrete examples.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
`
|
|
98
|
+
}];
|
|
99
|
+
a(t);
|
|
100
|
+
|
|
101
|
+
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { a } from "../registry.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js
|
|
4
|
+
const t = [{
|
|
5
|
+
id: `docs.tech.PHASE_5_ZERO_TOUCH_OPERATIONS`,
|
|
6
|
+
title: `Phase 5: Zero-Touch Operations`,
|
|
7
|
+
summary: `**Status**: In progress`,
|
|
8
|
+
kind: `reference`,
|
|
9
|
+
visibility: `public`,
|
|
10
|
+
route: `/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS`,
|
|
11
|
+
tags: [`tech`, `PHASE_5_ZERO_TOUCH_OPERATIONS`],
|
|
12
|
+
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"
|
|
13
|
+
}];
|
|
14
|
+
a(t);
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { a } from "../../registry.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js
|
|
4
|
+
const t = [{
|
|
5
|
+
id: `docs.tech.auth.better-auth-nextjs`,
|
|
6
|
+
title: `Better Auth + Next.js integration (ContractSpec)`,
|
|
7
|
+
summary: `How ContractSpec wires Better Auth into Next.js (server config, client singleton, and proxy cookie-only redirects).`,
|
|
8
|
+
kind: `reference`,
|
|
9
|
+
visibility: `public`,
|
|
10
|
+
route: `/docs/tech/auth/better-auth-nextjs`,
|
|
11
|
+
tags: [
|
|
12
|
+
`auth`,
|
|
13
|
+
`better-auth`,
|
|
14
|
+
`nextjs`,
|
|
15
|
+
`cookies`,
|
|
16
|
+
`proxy`,
|
|
17
|
+
`hmr`
|
|
18
|
+
],
|
|
19
|
+
body: `# Better Auth + Next.js integration (ContractSpec)
|
|
20
|
+
|
|
21
|
+
This repo uses Better Auth as the primary auth layer (sessions, organizations, teams, API keys, and OAuth).
|
|
22
|
+
|
|
23
|
+
## Server config (Better Auth)
|
|
24
|
+
|
|
25
|
+
- Source: \`packages/bundles/contractspec-studio/src/application/services/auth.ts\`
|
|
26
|
+
- Important: \`nextCookies()\` must be the **last** plugin in the Better Auth plugin list so \`Set-Cookie\` is applied correctly in Next.js environments.
|
|
27
|
+
|
|
28
|
+
## Better Auth Admin plugin
|
|
29
|
+
|
|
30
|
+
ContractSpec Studio enables the Better Auth **Admin plugin** to support platform-admin user operations (list users, impersonation, etc.).
|
|
31
|
+
|
|
32
|
+
- Server: \`admin()\` plugin in \`packages/bundles/contractspec-studio/src/application/services/auth.ts\`
|
|
33
|
+
- Client: \`adminClient()\` in \`packages/bundles/contractspec-studio/src/presentation/providers/auth/client.ts\`
|
|
34
|
+
|
|
35
|
+
### PLATFORM_ADMIN ⇒ Better Auth admin role
|
|
36
|
+
|
|
37
|
+
Better Auth Admin endpoints authorize via \`user.role\`. ContractSpec enforces an org-driven rule:
|
|
38
|
+
|
|
39
|
+
- If the **active organization** has \`type = PLATFORM_ADMIN\`, the signed-in user is ensured to have \`User.role\` containing \`admin\`.
|
|
40
|
+
- This is applied in the session creation hook and re-checked in \`assertsPlatformAdmin()\`.
|
|
41
|
+
|
|
42
|
+
This keeps admin enablement deterministic and avoids manual role backfills.
|
|
43
|
+
|
|
44
|
+
## Client config (React web + Expo)
|
|
45
|
+
|
|
46
|
+
To avoid duplicate background refresh/polling loops in dev (Fast Refresh/HMR), the Better Auth client is implemented as a singleton cached on \`globalThis\`.
|
|
47
|
+
|
|
48
|
+
- Web client: \`packages/bundles/contractspec-studio/src/presentation/providers/auth/client.ts\`
|
|
49
|
+
- Native client: \`packages/bundles/contractspec-studio/src/presentation/providers/auth/client.native.ts\`
|
|
50
|
+
|
|
51
|
+
Import guidance:
|
|
52
|
+
|
|
53
|
+
- If you only need the context/hook, prefer importing from \`@lssm/bundle.contractspec-studio/presentation/providers/auth\`.
|
|
54
|
+
- If you explicitly need the Better Auth client instance (e.g. admin impersonation, direct API calls), import from \`@lssm/bundle.contractspec-studio/presentation/providers/auth/client\`.
|
|
55
|
+
|
|
56
|
+
## Public routes (login / signup)
|
|
57
|
+
|
|
58
|
+
Public auth pages should avoid eager \`authClient\` initialization.
|
|
59
|
+
|
|
60
|
+
Pattern used:
|
|
61
|
+
|
|
62
|
+
- In the submit handler, dynamically import \`@lssm/bundle.contractspec-studio/presentation/providers/auth/index.web\` and call \`authClient.signIn.*\` / \`authClient.signUp.*\`.
|
|
63
|
+
|
|
64
|
+
This prevents session refresh behavior from starting just because a public page rendered.
|
|
65
|
+
|
|
66
|
+
## Next.js proxy auth (web-landing)
|
|
67
|
+
|
|
68
|
+
The Next.js proxy/middleware is used for **redirect decisions only**. It must not perform DB-backed session reads on every request.
|
|
69
|
+
|
|
70
|
+
- Source: \`packages/apps/web-landing/src/proxy.ts\`
|
|
71
|
+
- Approach: cookie-only checks via Better Auth cookies helpers:
|
|
72
|
+
- \`getSessionCookie(request)\`
|
|
73
|
+
- \`getCookieCache(request)\`
|
|
74
|
+
|
|
75
|
+
These checks are intentionally optimistic and should only gate routing. Full authorization must still be enforced on server-side actions/routes and GraphQL resolvers.
|
|
76
|
+
`
|
|
77
|
+
}];
|
|
78
|
+
a(t);
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { a } from "../../registry.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js
|
|
4
|
+
const t = [{
|
|
5
|
+
id: `docs.tech.contracts.openapi-export`,
|
|
6
|
+
title: `OpenAPI export (OpenAPI 3.1) from SpecRegistry`,
|
|
7
|
+
summary: `Generate a deterministic OpenAPI document from a SpecRegistry using jsonSchemaForSpec + REST transport metadata.`,
|
|
8
|
+
kind: `reference`,
|
|
9
|
+
visibility: `public`,
|
|
10
|
+
route: `/docs/tech/contracts/openapi-export`,
|
|
11
|
+
tags: [
|
|
12
|
+
`contracts`,
|
|
13
|
+
`openapi`,
|
|
14
|
+
`rest`
|
|
15
|
+
],
|
|
16
|
+
body: `## OpenAPI export (OpenAPI 3.1) from SpecRegistry
|
|
17
|
+
|
|
18
|
+
### Purpose
|
|
19
|
+
|
|
20
|
+
ContractSpec specs can be exported into an **OpenAPI 3.1** document for tooling (SDK generation, docs, gateways).
|
|
21
|
+
|
|
22
|
+
The export is **spec-first**:
|
|
23
|
+
|
|
24
|
+
- Uses \`jsonSchemaForSpec(spec)\` for input/output JSON Schema (from SchemaModel → zod → JSON Schema)
|
|
25
|
+
- Uses \`spec.transport.rest.method/path\` when present
|
|
26
|
+
- Falls back to deterministic defaults:
|
|
27
|
+
- Method: \`POST\` for commands, \`GET\` for queries
|
|
28
|
+
- Path: \`defaultRestPath(name, version)\` → \`/<dot/name>/v<version>\`
|
|
29
|
+
|
|
30
|
+
### Library API
|
|
31
|
+
|
|
32
|
+
- Function: \`openApiForRegistry(registry, options?)\`
|
|
33
|
+
- Location: \`@lssm/lib.contracts/openapi\`
|
|
34
|
+
|
|
35
|
+
### CLI
|
|
36
|
+
|
|
37
|
+
Export OpenAPI from a registry module:
|
|
38
|
+
|
|
39
|
+
\`\`\`bash
|
|
40
|
+
contractspec openapi --registry ./src/registry.ts --out ./openapi.json
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
The registry module must export one of:
|
|
44
|
+
|
|
45
|
+
- \`registry: SpecRegistry\`
|
|
46
|
+
- \`default(): SpecRegistry | Promise<SpecRegistry>\`
|
|
47
|
+
- \`createRegistry(): SpecRegistry | Promise<SpecRegistry>\`
|
|
48
|
+
|
|
49
|
+
### Notes / limitations (current)
|
|
50
|
+
|
|
51
|
+
- Responses are generated as a basic \`200\` response (plus schemas when available).
|
|
52
|
+
- Query (GET) inputs are currently represented as a JSON request body when an input schema exists.
|
|
53
|
+
- Errors are not yet expanded into OpenAPI responses; that will be added when we standardize error envelopes.`
|
|
54
|
+
}];
|
|
55
|
+
a(t);
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { a } from "../registry.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js
|
|
4
|
+
const t = [{
|
|
5
|
+
id: `docs.tech.lifecycle-stage-system`,
|
|
6
|
+
title: `ContractSpec Lifecycle Stage System – Technical Design`,
|
|
7
|
+
summary: `This document describes how ContractSpec implements lifecycle detection and guidance. It covers architecture, module boundaries, scoring heuristics, and integration points so libraries, modules, bundles, and Studio surfaces stay synchronized.`,
|
|
8
|
+
kind: `reference`,
|
|
9
|
+
visibility: `public`,
|
|
10
|
+
route: `/docs/tech/lifecycle-stage-system`,
|
|
11
|
+
tags: [`tech`, `lifecycle-stage-system`],
|
|
12
|
+
body: `## ContractSpec Lifecycle Stage System – Technical Design
|
|
13
|
+
|
|
14
|
+
This document describes how ContractSpec implements lifecycle detection and guidance. It covers architecture, module boundaries, scoring heuristics, and integration points so libraries, modules, bundles, and Studio surfaces stay synchronized.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
### 1. Architecture Overview
|
|
19
|
+
|
|
20
|
+
\`\`\`
|
|
21
|
+
┌──────────────────────┐
|
|
22
|
+
│ @lssm/lib.lifecycle │ Types, enums, helpers (pure data)
|
|
23
|
+
└───────────┬──────────┘
|
|
24
|
+
│
|
|
25
|
+
┌───────────▼──────────┐ ┌───────────────────────────┐
|
|
26
|
+
│ modules/lifecycle- │ │ modules/lifecycle-advisor │
|
|
27
|
+
│ core (detection) │ │ (guidance & ceremonies) │
|
|
28
|
+
└───────────┬──────────┘ └───────────┬───────────────┘
|
|
29
|
+
│ │
|
|
30
|
+
├────────────┬──────────────┤
|
|
31
|
+
▼ ▼ ▼
|
|
32
|
+
Adapters: analytics, intent, questionnaires
|
|
33
|
+
│
|
|
34
|
+
┌───────────▼──────────┐
|
|
35
|
+
│ bundles/lifecycle- │ Managed service for Studio
|
|
36
|
+
│ managed │ (REST handlers, AI agent) │
|
|
37
|
+
└───────────┬──────────┘
|
|
38
|
+
│
|
|
39
|
+
ContractSpec Studio surfaces
|
|
40
|
+
(web/mobile APIs, CLI, docs)
|
|
41
|
+
\`\`\`
|
|
42
|
+
|
|
43
|
+
- **Libraries** provide shared vocabulary.
|
|
44
|
+
- **Modules** encapsulate logic, accepting adapters to avoid environment-specific code.
|
|
45
|
+
- **Bundles** compose modules, register agents/events, and expose APIs for Studio.
|
|
46
|
+
- **Apps** (web-landing, future Studio views) consume bundle APIs; they do not reimplement logic. For web-landing we now resolve \`@lssm/bundle.contractspec-studio\` and \`@lssm/lib.database-contractspec-studio\` directly from their \`packages/.../src\` folders via \`tsconfig\` path aliases so Prisma stays on the server build and Turbopack no longer pulls the prebundled \`dist\` artifacts into client chunks.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 2. Core Library (\`@lssm/lib.lifecycle\`)
|
|
51
|
+
|
|
52
|
+
- Stage enum (0–6) with metadata (\`question\`, \`signals\`, \`traps\`).
|
|
53
|
+
- Axes types (\`ProductPhase\`, \`CompanyPhase\`, \`CapitalPhase\`).
|
|
54
|
+
- \`LifecycleSignal\` (source, metric, value, timestamp).
|
|
55
|
+
- \`LifecycleMetricSnapshot\` (aggregated numbers).
|
|
56
|
+
- \`LifecycleMilestone\`, \`LifecycleAction\`, \`LifecycleAssessment\` interfaces.
|
|
57
|
+
- Utility helpers:
|
|
58
|
+
- \`formatStageSummary(stage, assessment)\`
|
|
59
|
+
- \`rankStageCandidates(scores)\`
|
|
60
|
+
|
|
61
|
+
The library exports **no runtime dependencies** so it can be imported from apps, modules, and bundles alike.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### 3. Lifecycle Core Module
|
|
66
|
+
|
|
67
|
+
**Location:** \`packages/modules/lifecycle-core/\`
|
|
68
|
+
|
|
69
|
+
#### Components
|
|
70
|
+
1. **StageSignalCollector**
|
|
71
|
+
- Accepts adapter interfaces:
|
|
72
|
+
- \`AnalyticsAdapter\` (pulls metrics from \`@lssm/lib.analytics\` or fixture streams).
|
|
73
|
+
- \`IntentAdapter\` (hooks into \`@lssm/lib.observability\` intent detectors or logs).
|
|
74
|
+
- \`QuestionnaireAdapter\` (loads JSON questionnaires and responses).
|
|
75
|
+
- Produces normalized \`LifecycleSignal[]\`.
|
|
76
|
+
|
|
77
|
+
2. **StageScorer**
|
|
78
|
+
- Weighted scoring model:
|
|
79
|
+
- Base weight per stage (reflecting expected maturity).
|
|
80
|
+
- Feature weights (retention, revenue, team size, qualitative feedback).
|
|
81
|
+
- Confidence computed via variance of contributing signals.
|
|
82
|
+
- Supports pluggable scoring matrices via JSON config.
|
|
83
|
+
- Accepts sparse metric snapshots; the orchestrator sanitizes metrics to numeric-only records before persisting assessments so downstream analytics stay consistent.
|
|
84
|
+
|
|
85
|
+
3. **LifecycleOrchestrator**
|
|
86
|
+
- Coordinates collectors + scorer.
|
|
87
|
+
- Returns \`LifecycleAssessment\` with:
|
|
88
|
+
- \`stage\`, \`confidence\`, \`axisSnapshot\`, \`signalsUsed\`.
|
|
89
|
+
- Recommended focus areas (high-level categories only).
|
|
90
|
+
- Emits events (internally) when stage confidence crosses thresholds (consumed later by bundle).
|
|
91
|
+
|
|
92
|
+
4. **LifecycleMilestonePlanner**
|
|
93
|
+
- Loads \`milestones-catalog.json\` (no DB).
|
|
94
|
+
- Filters upcoming milestones per stage + axis.
|
|
95
|
+
- Tracks completion using provided IDs (caller persists).
|
|
96
|
+
|
|
97
|
+
#### Data Files
|
|
98
|
+
- \`configs/stage-weights.json\`
|
|
99
|
+
- \`configs/milestones-catalog.json\`
|
|
100
|
+
- \`questionnaires/stage-readiness.json\`
|
|
101
|
+
|
|
102
|
+
#### Extension Hooks
|
|
103
|
+
- All adapters exported as TypeScript interfaces.
|
|
104
|
+
- Implementations for analytics/intent can live in bundles or apps without modifying module code.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
### 4. Lifecycle Advisor Module
|
|
109
|
+
|
|
110
|
+
**Location:** \`packages/modules/lifecycle-advisor/\`
|
|
111
|
+
|
|
112
|
+
#### Components
|
|
113
|
+
1. **LifecycleRecommendationEngine**
|
|
114
|
+
- Consumes \`LifecycleAssessment\`.
|
|
115
|
+
- Maps gaps to \`LifecycleAction[]\` using rule tables (\`stage-playbooks.ts\`).
|
|
116
|
+
- Supports override hooks for customer-specific rules.
|
|
117
|
+
|
|
118
|
+
2. **ContractSpecLibraryRecommender**
|
|
119
|
+
- Maintains mapping from stage → recommended libraries/modules/bundles.
|
|
120
|
+
- Returns prioritized list with rationale and adoption prerequisites.
|
|
121
|
+
|
|
122
|
+
3. **LifecycleCeremonyDesigner**
|
|
123
|
+
- Provides textual/structural data for ceremonies (title, copy, animation cues, soundtrack references).
|
|
124
|
+
- Ensures low-tech friendly instructions (clear copy, undo guidance).
|
|
125
|
+
|
|
126
|
+
4. **AI Hooks**
|
|
127
|
+
- Defines prompt templates and tool manifests for lifecycle advisor agents (consumed by bundles).
|
|
128
|
+
- Keeps actual LLM integration outside module.
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### 5. Managed Bundle (\`lifecycle-managed\`)
|
|
133
|
+
|
|
134
|
+
**Responsibilities**
|
|
135
|
+
- Wire modules together.
|
|
136
|
+
- Provide HTTP/GraphQL handlers (exact transport optional).
|
|
137
|
+
- Register LifecycleAdvisorAgent via \`@lssm/lib.ai-agent\`.
|
|
138
|
+
- LifecycleAdvisorAgent meta: domain \`operations\`, owners \`team-lifecycle\`, stability \`experimental\`, tags \`guide/lifecycle/ops\` so ops tooling can route incidents quickly.
|
|
139
|
+
- Emit lifecycle events through \`@lssm/lib.bus\` + \`@lssm/lib.analytics\`.
|
|
140
|
+
- Integrate with \`contractspec-studio\` packages:
|
|
141
|
+
- Use Studio contracts for authentication/tenant context (without accessing tenant DBs).
|
|
142
|
+
- Store assessments in Studio-managed storage abstractions (in-memory or file-based for now).
|
|
143
|
+
|
|
144
|
+
**APIs**
|
|
145
|
+
- \`POST /lifecycle/assessments\`: Accepts metrics + optional questionnaire answers. Returns \`LifecycleAssessment\`.
|
|
146
|
+
- \`GET /lifecycle/playbooks/:stage\`: Returns stage playbook + ceremonies.
|
|
147
|
+
- \`POST /lifecycle/advise\`: Invokes LifecycleAdvisorAgent with context.
|
|
148
|
+
|
|
149
|
+
**Events**
|
|
150
|
+
- \`LifecycleAssessmentCreated\`
|
|
151
|
+
- \`LifecycleStageChanged\`
|
|
152
|
+
- \`LifecycleGuidanceConsumed\`
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
### 6. Library Enhancements
|
|
157
|
+
|
|
158
|
+
| Library | Enhancement |
|
|
159
|
+
| --- | --- |
|
|
160
|
+
| \`@lssm/lib.analytics\` | Lifecycle metric collectors, helper to emit stage events, adapter implementation used by \`StageSignalCollector\`. |
|
|
161
|
+
| \`@lssm/lib.evolution\` | Accepts \`LifecycleContext\` when ranking spec anomalies/suggestions. |
|
|
162
|
+
| \`@lssm/lib.growth\` | Stage-specific experiment templates + guardrails referencing lifecycle enums. |
|
|
163
|
+
| \`@lssm/lib.observability\` | Lifecycle KPI pipeline definitions (drift detection, regression alerts). |
|
|
164
|
+
|
|
165
|
+
Each enhancement must import stage types from \`@lssm/lib.lifecycle\`.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
### 7. Feature Flags & Progressive Delivery
|
|
170
|
+
|
|
171
|
+
- Add new flags in progressive-delivery library:
|
|
172
|
+
- \`LIFECYCLE_DETECTION_ALPHA\`
|
|
173
|
+
- \`LIFECYCLE_ADVISOR_ALPHA\`
|
|
174
|
+
- \`LIFECYCLE_MANAGED_SERVICE\`
|
|
175
|
+
- Bundles/modules should check flags before enabling workflows.
|
|
176
|
+
- Flags referenced in docs + Studio UI to avoid accidental exposure.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### 8. Analytics & Telemetry
|
|
181
|
+
|
|
182
|
+
- Events defined in analytics library; consumed by bundle/app:
|
|
183
|
+
- \`lifecycle_assessment_run\`
|
|
184
|
+
- \`lifecycle_stage_changed\`
|
|
185
|
+
- \`lifecycle_guidance_consumed\`
|
|
186
|
+
- Observability pipeline includes:
|
|
187
|
+
- Composite lifecycle health metric (weighted sum of KPIs).
|
|
188
|
+
- Drift detection comparing stage predictions over time.
|
|
189
|
+
- Alert manager recipes for regression (e.g., PMF drop).
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
### 9. Testing Strategy
|
|
194
|
+
|
|
195
|
+
1. **Unit**
|
|
196
|
+
- StageScorer weight matrix.
|
|
197
|
+
- RecommendationEngine mapping.
|
|
198
|
+
- Library recommender stage coverage.
|
|
199
|
+
|
|
200
|
+
2. **Contract**
|
|
201
|
+
- Adapters: ensure mock adapters satisfy interfaces.
|
|
202
|
+
- Bundles: ensure HTTP handlers respect request/response contracts even without persistence.
|
|
203
|
+
|
|
204
|
+
3. **Integration**
|
|
205
|
+
- CLI example runs detection + guidance end-to-end on fixture data.
|
|
206
|
+
- Dashboard example renders assessments, verifying JSON structures remain stable.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
### 10. Implementation Checklist
|
|
211
|
+
|
|
212
|
+
- [ ] Documentation (product, tech, ops, user).
|
|
213
|
+
- [ ] Library creation (\`@lssm/lib.lifecycle\`).
|
|
214
|
+
- [ ] Modules (\`lifecycle-core\`, \`lifecycle-advisor\`).
|
|
215
|
+
- [ ] Bundle (\`lifecycle-managed\`) + Studio wiring.
|
|
216
|
+
- [ ] Library enhancements (analytics/evolution/growth/observability).
|
|
217
|
+
- [ ] Examples (CLI + dashboard).
|
|
218
|
+
- [ ] Feature flags + telemetry.
|
|
219
|
+
- [ ] Automated tests + fixtures.
|
|
220
|
+
|
|
221
|
+
Keep this document in sync as modules evolve. When adding new stages or axes, update \`@lssm/lib.lifecycle\` first, then cascade to adapters, then refresh docs + Studio copy.*** End Patch*** End Patch
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
`
|
|
225
|
+
}];
|
|
226
|
+
a(t);
|
|
227
|
+
|
|
228
|
+
//#endregion
|