@thinkai/tai-api-contract 2.78.0 → 2.80.0-pr.976.4c124f8a

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.80.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,121 @@ 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
+ - name: source
3373
+ in: query
3374
+ required: false
3375
+ description: >
3376
+ Optional filter for findings by source. Omit to return both
3377
+ deterministic and llm findings.
3378
+ schema:
3379
+ $ref: "#/components/schemas/CodeInsightsFindingSource"
3380
+ responses:
3381
+ "200":
3382
+ description: Repo code-quality detail payload
3383
+ content:
3384
+ application/json:
3385
+ schema:
3386
+ $ref: "#/components/schemas/CodeInsightsRepoDetailDto"
3387
+ "400":
3388
+ description: Malformed repoId
3389
+ content:
3390
+ application/json:
3391
+ schema:
3392
+ $ref: "#/components/schemas/ErrorMessageDto"
3393
+ "401":
3394
+ $ref: "#/components/responses/Unauthorized"
3395
+ "403":
3396
+ $ref: "#/components/responses/Forbidden"
3397
+ "404":
3398
+ description: Workspace or repo does not exist
3399
+ content:
3400
+ application/json:
3401
+ schema:
3402
+ $ref: "#/components/schemas/ErrorMessageDto"
3403
+
3283
3404
  /workspaces/{workspaceId}/integrations/ai-tool/{provider}/members:
3284
3405
  get:
3285
3406
  tags: [Workspace]
@@ -8650,6 +8771,22 @@ components:
8650
8771
  type: string
8651
8772
  enum: [repoName, overallScore, lastAnalyzed, language]
8652
8773
  default: overallScore
8774
+ CodeInsightsRepoSort:
8775
+ name: sort
8776
+ in: query
8777
+ required: false
8778
+ description: Allowlisted Code Insights repo sort field.
8779
+ schema:
8780
+ type: string
8781
+ enum: [repoName, locTotal, ccAvg, dupPct, lastMeasuredAt]
8782
+ default: repoName
8783
+ CodeInsightsRepoSearch:
8784
+ name: search
8785
+ in: query
8786
+ required: false
8787
+ description: Case-insensitive substring filter on repo name / provider slug.
8788
+ schema:
8789
+ type: string
8653
8790
  ReadinessRepoSearch:
8654
8791
  name: search
8655
8792
  in: query
@@ -17114,3 +17251,329 @@ components:
17114
17251
  snippets:
17115
17252
  type: array
17116
17253
  items: { type: string }
17254
+
17255
+ CodeInsightsMetricProvenance:
17256
+ type: string
17257
+ enum: [measured, derived, estimated, unavailable]
17258
+ description: >
17259
+ Where a metric value came from: `measured` (direct tool output),
17260
+ `derived` (computed from measured inputs, e.g. the maintainability band),
17261
+ `estimated` (heuristic proxy, e.g. test-to-source ratio), or `unavailable`
17262
+ (tool missing/failed, or the language is unsupported). Keyed per metric in
17263
+ `CodeInsightsMetricsDto.provenance`.
17264
+
17265
+ CodeInsightsMaintainabilityBand:
17266
+ type: string
17267
+ enum: [green, yellow, red]
17268
+ description: CC/LOC-derived maintainability band (documented heuristic, not Halstead MI).
17269
+
17270
+ CodeInsightsMetricsStatus:
17271
+ type: string
17272
+ enum: [ok, failed, skipped]
17273
+ description: >
17274
+ Outcome of the repo's latest metrics scan: `ok` (at least one tool measured),
17275
+ `failed` (every tool failed — metric fields are null with `unavailable`
17276
+ provenance), `skipped` (stage ran but found no measurable source).
17277
+
17278
+ CodeInsightsFindingSeverity:
17279
+ type: string
17280
+ enum: [critical, high, medium, low]
17281
+
17282
+ CodeInsightsFindingCategory:
17283
+ type: string
17284
+ enum: [duplication, complexity, proliferation, coverage, anemic_domain, context_leak, tx_boundary, error_handling]
17285
+ description: >
17286
+ Deterministic categories (`duplication`, `complexity`, `proliferation`,
17287
+ `coverage`) plus LLM semantic detectors (`anemic_domain`, `context_leak`,
17288
+ `tx_boundary`, `error_handling`).
17289
+
17290
+ CodeInsightsFindingSource:
17291
+ type: string
17292
+ enum: [deterministic, llm]
17293
+ description: >
17294
+ `deterministic` = measured Code Insights rules; `llm` = AI-detected
17295
+ semantic findings (separate agent pass; never blended in scoring).
17296
+
17297
+ CodeInsightsMetricsDto:
17298
+ type: object
17299
+ required: [runId, measuredAt, metricsStatus, structureCounts, provenance, toolVersions]
17300
+ properties:
17301
+ runId:
17302
+ type: string
17303
+ description: Readiness run that produced this metrics row.
17304
+ measuredAt:
17305
+ type: string
17306
+ format: date-time
17307
+ metricsStatus:
17308
+ $ref: "#/components/schemas/CodeInsightsMetricsStatus"
17309
+ locTotal:
17310
+ type: integer
17311
+ nullable: true
17312
+ filesTotal:
17313
+ type: integer
17314
+ nullable: true
17315
+ ccAvg:
17316
+ type: number
17317
+ nullable: true
17318
+ description: Mean cyclomatic complexity across analyzed functions.
17319
+ ccMax:
17320
+ type: integer
17321
+ nullable: true
17322
+ ccP90:
17323
+ type: number
17324
+ nullable: true
17325
+ description: 90th percentile function cyclomatic complexity (nearest-rank).
17326
+ dupPct:
17327
+ type: number
17328
+ nullable: true
17329
+ description: Duplicated lines as a percentage of analyzed lines (0–100).
17330
+ maintainabilityBand:
17331
+ allOf:
17332
+ - $ref: "#/components/schemas/CodeInsightsMaintainabilityBand"
17333
+ nullable: true
17334
+ coveragePct:
17335
+ type: number
17336
+ nullable: true
17337
+ description: Reserved for per-repo SonarQube enrichment (v2); null in v1.
17338
+ debtRatio:
17339
+ type: number
17340
+ nullable: true
17341
+ description: Reserved for per-repo SonarQube enrichment (v2); null in v1.
17342
+ structureCounts:
17343
+ type: object
17344
+ additionalProperties: true
17345
+ description: >
17346
+ Heuristic structure counters: dto/mapper/config/exception file + LOC
17347
+ counts, test/source LOC split, per-language LOC, functions_analyzed,
17348
+ test_ratio, dto_mapper_share_pct.
17349
+ provenance:
17350
+ type: object
17351
+ additionalProperties:
17352
+ $ref: "#/components/schemas/CodeInsightsMetricProvenance"
17353
+ description: Per-metric provenance keyed by DTO field name (e.g. `ccAvg`, `dupPct`, `testRatio`).
17354
+ toolVersions:
17355
+ type: object
17356
+ additionalProperties: { type: string }
17357
+ description: Tool name → version string for the tools that produced this row.
17358
+
17359
+ CodeInsightsHotspotDto:
17360
+ type: object
17361
+ required: [filePath, flags]
17362
+ properties:
17363
+ filePath:
17364
+ type: string
17365
+ description: Repo-relative file path.
17366
+ loc:
17367
+ type: integer
17368
+ nullable: true
17369
+ ccMax:
17370
+ type: integer
17371
+ nullable: true
17372
+ description: Max function cyclomatic complexity in the file.
17373
+ paramsMax:
17374
+ type: integer
17375
+ nullable: true
17376
+ nestingMax:
17377
+ type: integer
17378
+ nullable: true
17379
+ description: Max nested control structures (null when the analyzer does not report nesting).
17380
+ dupPct:
17381
+ type: number
17382
+ nullable: true
17383
+ description: Estimated per-file duplicated line share (0–100).
17384
+ flags:
17385
+ type: array
17386
+ items: { type: string }
17387
+ description: Subset of `god_file`, `high_cc`, `long_params`, `deep_nesting`.
17388
+
17389
+ CodeInsightsFindingDto:
17390
+ type: object
17391
+ required: [id, severity, category, title, explanation, evidence, source, runId, createdAt]
17392
+ properties:
17393
+ id:
17394
+ type: string
17395
+ format: uuid
17396
+ severity:
17397
+ $ref: "#/components/schemas/CodeInsightsFindingSeverity"
17398
+ category:
17399
+ $ref: "#/components/schemas/CodeInsightsFindingCategory"
17400
+ title:
17401
+ type: string
17402
+ explanation:
17403
+ type: string
17404
+ evidence:
17405
+ type: object
17406
+ additionalProperties: true
17407
+ description: Measured values and thresholds backing the finding.
17408
+ remediation:
17409
+ type: string
17410
+ nullable: true
17411
+ source:
17412
+ $ref: "#/components/schemas/CodeInsightsFindingSource"
17413
+ runId:
17414
+ type: string
17415
+ createdAt:
17416
+ type: string
17417
+ format: date-time
17418
+
17419
+ CodeInsightsFindingsBySeverityDto:
17420
+ type: object
17421
+ required: [critical, high, medium, low]
17422
+ properties:
17423
+ critical: { type: integer, minimum: 0 }
17424
+ high: { type: integer, minimum: 0 }
17425
+ medium: { type: integer, minimum: 0 }
17426
+ low: { type: integer, minimum: 0 }
17427
+
17428
+ CodeInsightsRepoListItemDto:
17429
+ type: object
17430
+ required: [repoId, repoName, language, providerSlug, webUrl, badges, findingsBySeverity, provenance]
17431
+ properties:
17432
+ repoId:
17433
+ type: string
17434
+ format: uuid
17435
+ repoName:
17436
+ type: string
17437
+ language:
17438
+ type: string
17439
+ providerSlug:
17440
+ type: string
17441
+ description: "owner/repo on the VCS provider."
17442
+ webUrl:
17443
+ type: string
17444
+ lastMeasuredAt:
17445
+ type: string
17446
+ format: date-time
17447
+ nullable: true
17448
+ description: Null when the repo is pending its first metrics scan.
17449
+ metricsStatus:
17450
+ allOf:
17451
+ - $ref: "#/components/schemas/CodeInsightsMetricsStatus"
17452
+ nullable: true
17453
+ locTotal:
17454
+ type: integer
17455
+ nullable: true
17456
+ ccAvg:
17457
+ type: number
17458
+ nullable: true
17459
+ ccMax:
17460
+ type: integer
17461
+ nullable: true
17462
+ dupPct:
17463
+ type: number
17464
+ nullable: true
17465
+ maintainabilityBand:
17466
+ allOf:
17467
+ - $ref: "#/components/schemas/CodeInsightsMaintainabilityBand"
17468
+ nullable: true
17469
+ badges:
17470
+ type: array
17471
+ items: { type: string }
17472
+ description: >
17473
+ Active threshold badges from the latest scan: subset of `god_files`,
17474
+ `high_complexity`, `duplication`, `proliferation`, `low_test_ratio`.
17475
+ findingsBySeverity:
17476
+ $ref: "#/components/schemas/CodeInsightsFindingsBySeverityDto"
17477
+ provenance:
17478
+ type: object
17479
+ additionalProperties:
17480
+ $ref: "#/components/schemas/CodeInsightsMetricProvenance"
17481
+
17482
+ CodeInsightsRepoListDto:
17483
+ allOf:
17484
+ - $ref: "#/components/schemas/PageMetaDto"
17485
+ - type: object
17486
+ required: [items]
17487
+ properties:
17488
+ items:
17489
+ type: array
17490
+ items:
17491
+ $ref: "#/components/schemas/CodeInsightsRepoListItemDto"
17492
+
17493
+ CodeInsightsRepoDetailDto:
17494
+ type: object
17495
+ required: [repoId, repoName, language, providerSlug, webUrl, metrics, hotspots, findings]
17496
+ properties:
17497
+ repoId:
17498
+ type: string
17499
+ format: uuid
17500
+ repoName:
17501
+ type: string
17502
+ language:
17503
+ type: string
17504
+ providerSlug:
17505
+ type: string
17506
+ webUrl:
17507
+ type: string
17508
+ metrics:
17509
+ allOf:
17510
+ - $ref: "#/components/schemas/CodeInsightsMetricsDto"
17511
+ nullable: true
17512
+ description: Null when the repo is pending its first metrics scan.
17513
+ hotspots:
17514
+ type: array
17515
+ items:
17516
+ $ref: "#/components/schemas/CodeInsightsHotspotDto"
17517
+ findings:
17518
+ type: array
17519
+ items:
17520
+ $ref: "#/components/schemas/CodeInsightsFindingDto"
17521
+ description: Findings from the latest scan only (history is retention-bounded).
17522
+
17523
+ CodeInsightsOrgHotspotDto:
17524
+ allOf:
17525
+ - $ref: "#/components/schemas/CodeInsightsHotspotDto"
17526
+ - type: object
17527
+ required: [repoId, repoName]
17528
+ properties:
17529
+ repoId:
17530
+ type: string
17531
+ format: uuid
17532
+ repoName:
17533
+ type: string
17534
+
17535
+ CodeInsightsSonarDto:
17536
+ type: object
17537
+ required: [connected]
17538
+ properties:
17539
+ connected:
17540
+ type: boolean
17541
+ description: Whether a SonarQube source is configured for the workspace.
17542
+ coveragePct:
17543
+ type: number
17544
+ nullable: true
17545
+ description: Org-level SonarQube coverage from the latest precomputed quality snapshot.
17546
+ techDebtRatioPct:
17547
+ type: number
17548
+ nullable: true
17549
+ description: Org-level SonarQube SQALE technical debt ratio from the latest quality snapshot.
17550
+
17551
+ CodeInsightsSummaryDto:
17552
+ type: object
17553
+ required: [reposMeasured, reposPending, findingsBySeverity, topHotspots, sonar]
17554
+ properties:
17555
+ reposMeasured:
17556
+ type: integer
17557
+ minimum: 0
17558
+ description: Active repos whose latest metrics scan completed (`ok`).
17559
+ reposPending:
17560
+ type: integer
17561
+ minimum: 0
17562
+ description: Active repos without a completed metrics scan (never scanned, or only failed/skipped).
17563
+ ccAvgMedian:
17564
+ type: number
17565
+ nullable: true
17566
+ description: Unweighted median of latest `ccAvg` across measured repos (null when none measured).
17567
+ dupPctMedian:
17568
+ type: number
17569
+ nullable: true
17570
+ description: Unweighted median of latest `dupPct` across measured repos (null when none measured).
17571
+ findingsBySeverity:
17572
+ $ref: "#/components/schemas/CodeInsightsFindingsBySeverityDto"
17573
+ topHotspots:
17574
+ type: array
17575
+ items:
17576
+ $ref: "#/components/schemas/CodeInsightsOrgHotspotDto"
17577
+ description: Org top-10 complexity hotspots by `ccMax` (current per-repo snapshots).
17578
+ sonar:
17579
+ $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.80.0-pr.976.4c124f8a",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",