@thinkai/tai-api-contract 2.78.0 → 2.79.0-pr.976.2077d2a6

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.
@@ -1,7 +1,7 @@
1
1
  openapi: 3.0.3
2
2
  info:
3
3
  title: ThinkAI API
4
- version: 2.78.0
4
+ version: 2.79.0
5
5
  description: >
6
6
  Contract surface for the AI Driven SDLC backend used by ThinkAI.
7
7
  Workspace-scoped routes use `/workspaces/{workspaceId}/...`.
@@ -80,6 +80,12 @@ tags:
80
80
  retrieval plus the workspace agent execution key (Claude or Cursor).
81
81
  - name: Platform
82
82
  description: Platform-wide banner surfaces (global outage/maintenance banner, issue #284).
83
+ - name: CodeInsights
84
+ description: >
85
+ Code Insights (`/insights/code`) — deterministic per-repo code-quality metrics
86
+ (LOC, cyclomatic complexity, duplication), hotspots, and playbook-threshold
87
+ findings collected during readiness scans. Every metric carries
88
+ `measured | derived | estimated | unavailable` provenance.
83
89
 
84
90
  paths:
85
91
  /admin/users/{userId}:
@@ -3280,6 +3286,113 @@ paths:
3280
3286
  "404":
3281
3287
  description: Workspace does not exist or malformed workspaceId
3282
3288
 
3289
+ /workspaces/{workspaceId}/insights/code/summary:
3290
+ get:
3291
+ tags: [CodeInsights]
3292
+ summary: Code Insights — org summary
3293
+ operationId: getCodeInsightsSummary
3294
+ description: >
3295
+ Org-level Code Insights summary for `/insights/code`. Aggregates each active
3296
+ repo's **latest** deterministic metrics row (unweighted medians — mega-repos
3297
+ are not down-weighted, by design), findings counts by severity across latest
3298
+ scans, the org top-10 complexity hotspots, and org-level SonarQube
3299
+ coverage/tech-debt-ratio when a SonarQube source is connected (per-repo Sonar
3300
+ mapping is v2). Reads stored scan outputs only — never recomputes on request.
3301
+ parameters:
3302
+ - $ref: "#/components/parameters/WorkspaceId"
3303
+ responses:
3304
+ "200":
3305
+ description: Code Insights org summary payload
3306
+ content:
3307
+ application/json:
3308
+ schema:
3309
+ $ref: "#/components/schemas/CodeInsightsSummaryDto"
3310
+ "401":
3311
+ $ref: "#/components/responses/Unauthorized"
3312
+ "403":
3313
+ $ref: "#/components/responses/Forbidden"
3314
+ "404":
3315
+ description: Workspace does not exist or malformed workspaceId
3316
+
3317
+ /workspaces/{workspaceId}/insights/code/repos:
3318
+ get:
3319
+ tags: [CodeInsights]
3320
+ summary: Code Insights — per-repo metrics list (paginated)
3321
+ operationId: listCodeInsightsRepos
3322
+ description: >
3323
+ Page of active (not user-archived) repos with their latest code-quality
3324
+ metrics, threshold badges, and finding counts. Repos without a completed
3325
+ metrics scan appear with `metricsStatus` absent/`null` ("pending first scan").
3326
+ parameters:
3327
+ - $ref: "#/components/parameters/WorkspaceId"
3328
+ - $ref: "#/components/parameters/PaginationLimit"
3329
+ - $ref: "#/components/parameters/PaginationOffset"
3330
+ - $ref: "#/components/parameters/CodeInsightsRepoSort"
3331
+ - $ref: "#/components/parameters/PaginationOrder"
3332
+ - $ref: "#/components/parameters/CodeInsightsRepoSearch"
3333
+ responses:
3334
+ "200":
3335
+ description: Paginated repo code-quality metrics
3336
+ content:
3337
+ application/json:
3338
+ schema:
3339
+ $ref: "#/components/schemas/CodeInsightsRepoListDto"
3340
+ "400":
3341
+ description: Invalid pagination or sort query
3342
+ content:
3343
+ application/json:
3344
+ schema:
3345
+ $ref: "#/components/schemas/ErrorMessageDto"
3346
+ "401":
3347
+ $ref: "#/components/responses/Unauthorized"
3348
+ "403":
3349
+ $ref: "#/components/responses/Forbidden"
3350
+ "404":
3351
+ description: Workspace does not exist or malformed workspaceId
3352
+
3353
+ /workspaces/{workspaceId}/insights/code/repos/{repoId}:
3354
+ get:
3355
+ tags: [CodeInsights]
3356
+ summary: Code Insights — repo detail (metrics, hotspots, findings)
3357
+ operationId: getCodeInsightsRepoDetail
3358
+ description: >
3359
+ Single-repo Code Insights detail: latest metrics row with per-metric
3360
+ provenance, current hotspot snapshot (top-N worst files), and the findings
3361
+ computed by the latest scan. `metrics` is `null` when the repo is pending
3362
+ its first metrics scan.
3363
+ parameters:
3364
+ - $ref: "#/components/parameters/WorkspaceId"
3365
+ - name: repoId
3366
+ in: path
3367
+ required: true
3368
+ description: Internal repo UUID (`tai_workspace_repos.id`).
3369
+ schema:
3370
+ type: string
3371
+ format: uuid
3372
+ responses:
3373
+ "200":
3374
+ description: Repo code-quality detail payload
3375
+ content:
3376
+ application/json:
3377
+ schema:
3378
+ $ref: "#/components/schemas/CodeInsightsRepoDetailDto"
3379
+ "400":
3380
+ description: Malformed repoId
3381
+ content:
3382
+ application/json:
3383
+ schema:
3384
+ $ref: "#/components/schemas/ErrorMessageDto"
3385
+ "401":
3386
+ $ref: "#/components/responses/Unauthorized"
3387
+ "403":
3388
+ $ref: "#/components/responses/Forbidden"
3389
+ "404":
3390
+ description: Workspace or repo does not exist
3391
+ content:
3392
+ application/json:
3393
+ schema:
3394
+ $ref: "#/components/schemas/ErrorMessageDto"
3395
+
3283
3396
  /workspaces/{workspaceId}/integrations/ai-tool/{provider}/members:
3284
3397
  get:
3285
3398
  tags: [Workspace]
@@ -8650,6 +8763,22 @@ components:
8650
8763
  type: string
8651
8764
  enum: [repoName, overallScore, lastAnalyzed, language]
8652
8765
  default: overallScore
8766
+ CodeInsightsRepoSort:
8767
+ name: sort
8768
+ in: query
8769
+ required: false
8770
+ description: Allowlisted Code Insights repo sort field.
8771
+ schema:
8772
+ type: string
8773
+ enum: [repoName, locTotal, ccAvg, dupPct, lastMeasuredAt]
8774
+ default: repoName
8775
+ CodeInsightsRepoSearch:
8776
+ name: search
8777
+ in: query
8778
+ required: false
8779
+ description: Case-insensitive substring filter on repo name / provider slug.
8780
+ schema:
8781
+ type: string
8653
8782
  ReadinessRepoSearch:
8654
8783
  name: search
8655
8784
  in: query
@@ -17114,3 +17243,326 @@ components:
17114
17243
  snippets:
17115
17244
  type: array
17116
17245
  items: { type: string }
17246
+
17247
+ CodeInsightsMetricProvenance:
17248
+ type: string
17249
+ enum: [measured, derived, estimated, unavailable]
17250
+ description: >
17251
+ Where a metric value came from: `measured` (direct tool output),
17252
+ `derived` (computed from measured inputs, e.g. the maintainability band),
17253
+ `estimated` (heuristic proxy, e.g. test-to-source ratio), or `unavailable`
17254
+ (tool missing/failed, or the language is unsupported). Keyed per metric in
17255
+ `CodeInsightsMetricsDto.provenance`.
17256
+
17257
+ CodeInsightsMaintainabilityBand:
17258
+ type: string
17259
+ enum: [green, yellow, red]
17260
+ description: CC/LOC-derived maintainability band (documented heuristic, not Halstead MI).
17261
+
17262
+ CodeInsightsMetricsStatus:
17263
+ type: string
17264
+ enum: [ok, failed, skipped]
17265
+ description: >
17266
+ Outcome of the repo's latest metrics scan: `ok` (at least one tool measured),
17267
+ `failed` (every tool failed — metric fields are null with `unavailable`
17268
+ provenance), `skipped` (stage ran but found no measurable source).
17269
+
17270
+ CodeInsightsFindingSeverity:
17271
+ type: string
17272
+ enum: [critical, high, medium, low]
17273
+
17274
+ CodeInsightsFindingCategory:
17275
+ type: string
17276
+ enum: [duplication, complexity, proliferation, coverage]
17277
+ description: >
17278
+ v1 deterministic categories. The v2 LLM pass adds `anemic_domain`,
17279
+ `context_leak`, `tx_boundary`, `error_handling` (contract bump).
17280
+
17281
+ CodeInsightsFindingSource:
17282
+ type: string
17283
+ enum: [deterministic]
17284
+ description: v1 ships deterministic findings only; the v2 LLM pass adds `llm`.
17285
+
17286
+ CodeInsightsMetricsDto:
17287
+ type: object
17288
+ required: [runId, measuredAt, metricsStatus, structureCounts, provenance, toolVersions]
17289
+ properties:
17290
+ runId:
17291
+ type: string
17292
+ description: Readiness run that produced this metrics row.
17293
+ measuredAt:
17294
+ type: string
17295
+ format: date-time
17296
+ metricsStatus:
17297
+ $ref: "#/components/schemas/CodeInsightsMetricsStatus"
17298
+ locTotal:
17299
+ type: integer
17300
+ nullable: true
17301
+ filesTotal:
17302
+ type: integer
17303
+ nullable: true
17304
+ ccAvg:
17305
+ type: number
17306
+ nullable: true
17307
+ description: Mean cyclomatic complexity across analyzed functions.
17308
+ ccMax:
17309
+ type: integer
17310
+ nullable: true
17311
+ ccP90:
17312
+ type: number
17313
+ nullable: true
17314
+ description: 90th percentile function cyclomatic complexity (nearest-rank).
17315
+ dupPct:
17316
+ type: number
17317
+ nullable: true
17318
+ description: Duplicated lines as a percentage of analyzed lines (0–100).
17319
+ maintainabilityBand:
17320
+ allOf:
17321
+ - $ref: "#/components/schemas/CodeInsightsMaintainabilityBand"
17322
+ nullable: true
17323
+ coveragePct:
17324
+ type: number
17325
+ nullable: true
17326
+ description: Reserved for per-repo SonarQube enrichment (v2); null in v1.
17327
+ debtRatio:
17328
+ type: number
17329
+ nullable: true
17330
+ description: Reserved for per-repo SonarQube enrichment (v2); null in v1.
17331
+ structureCounts:
17332
+ type: object
17333
+ additionalProperties: true
17334
+ description: >
17335
+ Heuristic structure counters: dto/mapper/config/exception file + LOC
17336
+ counts, test/source LOC split, per-language LOC, functions_analyzed,
17337
+ test_ratio, dto_mapper_share_pct.
17338
+ provenance:
17339
+ type: object
17340
+ additionalProperties:
17341
+ $ref: "#/components/schemas/CodeInsightsMetricProvenance"
17342
+ description: Per-metric provenance keyed by DTO field name (e.g. `ccAvg`, `dupPct`, `testRatio`).
17343
+ toolVersions:
17344
+ type: object
17345
+ additionalProperties: { type: string }
17346
+ description: Tool name → version string for the tools that produced this row.
17347
+
17348
+ CodeInsightsHotspotDto:
17349
+ type: object
17350
+ required: [filePath, flags]
17351
+ properties:
17352
+ filePath:
17353
+ type: string
17354
+ description: Repo-relative file path.
17355
+ loc:
17356
+ type: integer
17357
+ nullable: true
17358
+ ccMax:
17359
+ type: integer
17360
+ nullable: true
17361
+ description: Max function cyclomatic complexity in the file.
17362
+ paramsMax:
17363
+ type: integer
17364
+ nullable: true
17365
+ nestingMax:
17366
+ type: integer
17367
+ nullable: true
17368
+ description: Max nested control structures (null when the analyzer does not report nesting).
17369
+ dupPct:
17370
+ type: number
17371
+ nullable: true
17372
+ description: Estimated per-file duplicated line share (0–100).
17373
+ flags:
17374
+ type: array
17375
+ items: { type: string }
17376
+ description: Subset of `god_file`, `high_cc`, `long_params`, `deep_nesting`.
17377
+
17378
+ CodeInsightsFindingDto:
17379
+ type: object
17380
+ required: [id, severity, category, title, explanation, evidence, source, runId, createdAt]
17381
+ properties:
17382
+ id:
17383
+ type: string
17384
+ format: uuid
17385
+ severity:
17386
+ $ref: "#/components/schemas/CodeInsightsFindingSeverity"
17387
+ category:
17388
+ $ref: "#/components/schemas/CodeInsightsFindingCategory"
17389
+ title:
17390
+ type: string
17391
+ explanation:
17392
+ type: string
17393
+ evidence:
17394
+ type: object
17395
+ additionalProperties: true
17396
+ description: Measured values and thresholds backing the finding.
17397
+ remediation:
17398
+ type: string
17399
+ nullable: true
17400
+ source:
17401
+ $ref: "#/components/schemas/CodeInsightsFindingSource"
17402
+ runId:
17403
+ type: string
17404
+ createdAt:
17405
+ type: string
17406
+ format: date-time
17407
+
17408
+ CodeInsightsFindingsBySeverityDto:
17409
+ type: object
17410
+ required: [critical, high, medium, low]
17411
+ properties:
17412
+ critical: { type: integer, minimum: 0 }
17413
+ high: { type: integer, minimum: 0 }
17414
+ medium: { type: integer, minimum: 0 }
17415
+ low: { type: integer, minimum: 0 }
17416
+
17417
+ CodeInsightsRepoListItemDto:
17418
+ type: object
17419
+ required: [repoId, repoName, language, providerSlug, webUrl, badges, findingsBySeverity, provenance]
17420
+ properties:
17421
+ repoId:
17422
+ type: string
17423
+ format: uuid
17424
+ repoName:
17425
+ type: string
17426
+ language:
17427
+ type: string
17428
+ providerSlug:
17429
+ type: string
17430
+ description: "owner/repo on the VCS provider."
17431
+ webUrl:
17432
+ type: string
17433
+ lastMeasuredAt:
17434
+ type: string
17435
+ format: date-time
17436
+ nullable: true
17437
+ description: Null when the repo is pending its first metrics scan.
17438
+ metricsStatus:
17439
+ allOf:
17440
+ - $ref: "#/components/schemas/CodeInsightsMetricsStatus"
17441
+ nullable: true
17442
+ locTotal:
17443
+ type: integer
17444
+ nullable: true
17445
+ ccAvg:
17446
+ type: number
17447
+ nullable: true
17448
+ ccMax:
17449
+ type: integer
17450
+ nullable: true
17451
+ dupPct:
17452
+ type: number
17453
+ nullable: true
17454
+ maintainabilityBand:
17455
+ allOf:
17456
+ - $ref: "#/components/schemas/CodeInsightsMaintainabilityBand"
17457
+ nullable: true
17458
+ badges:
17459
+ type: array
17460
+ items: { type: string }
17461
+ description: >
17462
+ Active threshold badges from the latest scan: subset of `god_files`,
17463
+ `high_complexity`, `duplication`, `proliferation`, `low_test_ratio`.
17464
+ findingsBySeverity:
17465
+ $ref: "#/components/schemas/CodeInsightsFindingsBySeverityDto"
17466
+ provenance:
17467
+ type: object
17468
+ additionalProperties:
17469
+ $ref: "#/components/schemas/CodeInsightsMetricProvenance"
17470
+
17471
+ CodeInsightsRepoListDto:
17472
+ allOf:
17473
+ - $ref: "#/components/schemas/PageMetaDto"
17474
+ - type: object
17475
+ required: [items]
17476
+ properties:
17477
+ items:
17478
+ type: array
17479
+ items:
17480
+ $ref: "#/components/schemas/CodeInsightsRepoListItemDto"
17481
+
17482
+ CodeInsightsRepoDetailDto:
17483
+ type: object
17484
+ required: [repoId, repoName, language, providerSlug, webUrl, metrics, hotspots, findings]
17485
+ properties:
17486
+ repoId:
17487
+ type: string
17488
+ format: uuid
17489
+ repoName:
17490
+ type: string
17491
+ language:
17492
+ type: string
17493
+ providerSlug:
17494
+ type: string
17495
+ webUrl:
17496
+ type: string
17497
+ metrics:
17498
+ allOf:
17499
+ - $ref: "#/components/schemas/CodeInsightsMetricsDto"
17500
+ nullable: true
17501
+ description: Null when the repo is pending its first metrics scan.
17502
+ hotspots:
17503
+ type: array
17504
+ items:
17505
+ $ref: "#/components/schemas/CodeInsightsHotspotDto"
17506
+ findings:
17507
+ type: array
17508
+ items:
17509
+ $ref: "#/components/schemas/CodeInsightsFindingDto"
17510
+ description: Findings from the latest scan only (history is retention-bounded).
17511
+
17512
+ CodeInsightsOrgHotspotDto:
17513
+ allOf:
17514
+ - $ref: "#/components/schemas/CodeInsightsHotspotDto"
17515
+ - type: object
17516
+ required: [repoId, repoName]
17517
+ properties:
17518
+ repoId:
17519
+ type: string
17520
+ format: uuid
17521
+ repoName:
17522
+ type: string
17523
+
17524
+ CodeInsightsSonarDto:
17525
+ type: object
17526
+ required: [connected]
17527
+ properties:
17528
+ connected:
17529
+ type: boolean
17530
+ description: Whether a SonarQube source is configured for the workspace.
17531
+ coveragePct:
17532
+ type: number
17533
+ nullable: true
17534
+ description: Org-level SonarQube coverage from the latest precomputed quality snapshot.
17535
+ techDebtRatioPct:
17536
+ type: number
17537
+ nullable: true
17538
+ description: Org-level SonarQube SQALE technical debt ratio from the latest quality snapshot.
17539
+
17540
+ CodeInsightsSummaryDto:
17541
+ type: object
17542
+ required: [reposMeasured, reposPending, findingsBySeverity, topHotspots, sonar]
17543
+ properties:
17544
+ reposMeasured:
17545
+ type: integer
17546
+ minimum: 0
17547
+ description: Active repos whose latest metrics scan completed (`ok`).
17548
+ reposPending:
17549
+ type: integer
17550
+ minimum: 0
17551
+ description: Active repos without a completed metrics scan (never scanned, or only failed/skipped).
17552
+ ccAvgMedian:
17553
+ type: number
17554
+ nullable: true
17555
+ description: Unweighted median of latest `ccAvg` across measured repos (null when none measured).
17556
+ dupPctMedian:
17557
+ type: number
17558
+ nullable: true
17559
+ description: Unweighted median of latest `dupPct` across measured repos (null when none measured).
17560
+ findingsBySeverity:
17561
+ $ref: "#/components/schemas/CodeInsightsFindingsBySeverityDto"
17562
+ topHotspots:
17563
+ type: array
17564
+ items:
17565
+ $ref: "#/components/schemas/CodeInsightsOrgHotspotDto"
17566
+ description: Org top-10 complexity hotspots by `ccMax` (current per-repo snapshots).
17567
+ sonar:
17568
+ $ref: "#/components/schemas/CodeInsightsSonarDto"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkai/tai-api-contract",
3
- "version": "2.78.0",
3
+ "version": "2.79.0-pr.976.2077d2a6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",