@pikku/inspector 0.12.75 → 0.12.82

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.
Files changed (223) hide show
  1. package/CHANGELOG.md +357 -0
  2. package/dist/add/add-analytics.d.ts +9 -0
  3. package/dist/add/add-analytics.js +178 -0
  4. package/dist/add/add-auth.js +0 -54
  5. package/dist/add/add-feature-flag.d.ts +2 -0
  6. package/dist/add/add-feature-flag.js +162 -0
  7. package/dist/add/add-middleware.js +66 -42
  8. package/dist/add/add-wire-addon.js +7 -4
  9. package/dist/add/add-wire-remote-addon.js +1 -0
  10. package/dist/error-codes.d.ts +1 -0
  11. package/dist/error-codes.js +1 -0
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +3 -1
  14. package/dist/inspector.js +5 -0
  15. package/dist/surface/collect-surface.d.ts +58 -0
  16. package/dist/surface/collect-surface.js +613 -0
  17. package/dist/types.d.ts +36 -12
  18. package/dist/utils/filter-inspector-state.js +14 -0
  19. package/dist/utils/load-addon-functions-meta.js +24 -11
  20. package/dist/utils/post-process.js +15 -0
  21. package/dist/utils/read-module-specifiers.d.ts +8 -0
  22. package/dist/utils/read-module-specifiers.js +23 -0
  23. package/dist/utils/read-tsconfig-out-dir.d.ts +5 -0
  24. package/dist/utils/read-tsconfig-out-dir.js +12 -0
  25. package/dist/utils/resolve-deploy-target.d.ts +7 -0
  26. package/dist/utils/resolve-deploy-target.js +15 -7
  27. package/dist/utils/serialize-inspector-state.d.ts +6 -0
  28. package/dist/utils/serialize-inspector-state.js +10 -0
  29. package/dist/visit.js +4 -0
  30. package/package.json +16 -6
  31. package/run-tests.sh +21 -6
  32. package/src/add/add-addon-bans.ts +0 -85
  33. package/src/add/add-agent-scorer.test.ts +0 -197
  34. package/src/add/add-agent-scorer.ts +0 -83
  35. package/src/add/add-agent.test.ts +0 -87
  36. package/src/add/add-agent.ts +0 -638
  37. package/src/add/add-approval-description.ts +0 -76
  38. package/src/add/add-auth.test.ts +0 -791
  39. package/src/add/add-auth.ts +0 -424
  40. package/src/add/add-channel.ts +0 -778
  41. package/src/add/add-cli-renderers.test.ts +0 -74
  42. package/src/add/add-cli.ts +0 -1006
  43. package/src/add/add-credential.ts +0 -186
  44. package/src/add/add-feature.test.ts +0 -306
  45. package/src/add/add-feature.ts +0 -253
  46. package/src/add/add-file-extends-core-type.ts +0 -66
  47. package/src/add/add-file-with-config.ts +0 -45
  48. package/src/add/add-file-with-factory.test.ts +0 -134
  49. package/src/add/add-file-with-factory.ts +0 -288
  50. package/src/add/add-functions.test.ts +0 -743
  51. package/src/add/add-functions.ts +0 -1548
  52. package/src/add/add-gateway.ts +0 -143
  53. package/src/add/add-http-route-ref.test.ts +0 -149
  54. package/src/add/add-http-route.ts +0 -530
  55. package/src/add/add-http-routes.ts +0 -471
  56. package/src/add/add-keyed-wiring.ts +0 -180
  57. package/src/add/add-mcp-prompt.ts +0 -157
  58. package/src/add/add-mcp-resource.ts +0 -175
  59. package/src/add/add-middleware.test.ts +0 -196
  60. package/src/add/add-middleware.ts +0 -879
  61. package/src/add/add-permission-auth.test.ts +0 -59
  62. package/src/add/add-permission.ts +0 -311
  63. package/src/add/add-personas.test.ts +0 -406
  64. package/src/add/add-personas.ts +0 -287
  65. package/src/add/add-queue-worker.ts +0 -117
  66. package/src/add/add-rpc-invocations.test.ts +0 -287
  67. package/src/add/add-rpc-invocations.ts +0 -221
  68. package/src/add/add-scenario-step.test.ts +0 -509
  69. package/src/add/add-schedule.ts +0 -120
  70. package/src/add/add-scope.test.ts +0 -419
  71. package/src/add/add-scope.ts +0 -221
  72. package/src/add/add-secret.ts +0 -10
  73. package/src/add/add-subject-scenario-steps.test.ts +0 -161
  74. package/src/add/add-system-role.test.ts +0 -297
  75. package/src/add/add-system-role.ts +0 -162
  76. package/src/add/add-trigger.ts +0 -165
  77. package/src/add/add-variable.ts +0 -10
  78. package/src/add/add-wire-addon.test.ts +0 -185
  79. package/src/add/add-wire-addon.ts +0 -146
  80. package/src/add/add-wire-remote-addon.ts +0 -80
  81. package/src/add/add-workflow-edge-cases.test.ts +0 -201
  82. package/src/add/add-workflow-fanout.test.ts +0 -166
  83. package/src/add/add-workflow-graph-foreach.test.ts +0 -174
  84. package/src/add/add-workflow-graph-input.test.ts +0 -94
  85. package/src/add/add-workflow-graph-notes.test.ts +0 -74
  86. package/src/add/add-workflow-graph.ts +0 -644
  87. package/src/add/add-workflow-on-error.test.ts +0 -118
  88. package/src/add/add-workflow-return-switch.test.ts +0 -121
  89. package/src/add/add-workflow-silent-drops.test.ts +0 -261
  90. package/src/add/add-workflow-sleep-expression.test.ts +0 -96
  91. package/src/add/add-workflow.test.ts +0 -155
  92. package/src/add/add-workflow.ts +0 -482
  93. package/src/add/addon-bans.test.ts +0 -121
  94. package/src/add/addon-contracts.test.ts +0 -221
  95. package/src/add/allow-escape-hatches.test.ts +0 -144
  96. package/src/add/audit-meta.test.ts +0 -75
  97. package/src/add/classified-sink-check.test.ts +0 -347
  98. package/src/add/config-value-metadata.test.ts +0 -263
  99. package/src/add/dynamic-import-check.test.ts +0 -119
  100. package/src/add/expect-eventually-scenario-only.test.ts +0 -108
  101. package/src/add/function-body-span.test.ts +0 -96
  102. package/src/add/inline-wiring-function.test.ts +0 -104
  103. package/src/add/pii-check.test.ts +0 -258
  104. package/src/add/rpc-type-cast.test.ts +0 -123
  105. package/src/add/scenario-instrumentation.test.ts +0 -89
  106. package/src/add/scenario-instrumentation.ts +0 -42
  107. package/src/add/scenario-marker.test.ts +0 -89
  108. package/src/add/scenario-not-extractable.test.ts +0 -159
  109. package/src/add/scenario-services.test.ts +0 -103
  110. package/src/add/scenario-skip.test.ts +0 -83
  111. package/src/add/validate-workflow-graph-addons.test.ts +0 -102
  112. package/src/add/wire-name-literal.test.ts +0 -117
  113. package/src/error-codes-emitted.test.ts +0 -76
  114. package/src/error-codes.ts +0 -145
  115. package/src/index.ts +0 -66
  116. package/src/inspector.ts +0 -575
  117. package/src/schema-generator.ts +0 -1
  118. package/src/source-file-cache.ts +0 -73
  119. package/src/tsconfig-paths.test.ts +0 -90
  120. package/src/types-map.ts +0 -141
  121. package/src/types.ts +0 -775
  122. package/src/utils/annotate-http-route-auth.test.ts +0 -161
  123. package/src/utils/annotate-http-route-auth.ts +0 -53
  124. package/src/utils/check-classified-sinks.ts +0 -215
  125. package/src/utils/check-pii-output.ts +0 -120
  126. package/src/utils/compute-diagnostics.test.ts +0 -106
  127. package/src/utils/compute-required-schemas.ts +0 -48
  128. package/src/utils/contract-hashes.test.ts +0 -553
  129. package/src/utils/contract-hashes.ts +0 -387
  130. package/src/utils/custom-types-generator.test.ts +0 -124
  131. package/src/utils/custom-types-generator.ts +0 -150
  132. package/src/utils/detect-schema-vendor.test.ts +0 -123
  133. package/src/utils/detect-schema-vendor.ts +0 -120
  134. package/src/utils/does-type-extend-core-type.ts +0 -53
  135. package/src/utils/ensure-function-metadata.ts +0 -385
  136. package/src/utils/extract-function-name.ts +0 -612
  137. package/src/utils/extract-function-node.ts +0 -70
  138. package/src/utils/extract-node-value.test.ts +0 -117
  139. package/src/utils/extract-node-value.ts +0 -172
  140. package/src/utils/extract-secret-usage.test.ts +0 -81
  141. package/src/utils/extract-secret-usage.ts +0 -73
  142. package/src/utils/extract-services.ts +0 -70
  143. package/src/utils/extract-surface-usage.test.ts +0 -147
  144. package/src/utils/extract-surface-usage.ts +0 -121
  145. package/src/utils/filter-inspector-state.test.ts +0 -2232
  146. package/src/utils/filter-inspector-state.ts +0 -1298
  147. package/src/utils/filter-utils.test.ts +0 -843
  148. package/src/utils/filter-utils.ts +0 -161
  149. package/src/utils/find-root-dir.ts +0 -68
  150. package/src/utils/find-zod-transform.test.ts +0 -70
  151. package/src/utils/find-zod-transform.ts +0 -103
  152. package/src/utils/get-exported-variable-name.ts +0 -48
  153. package/src/utils/get-files-and-methods.ts +0 -157
  154. package/src/utils/get-property-value.test.ts +0 -141
  155. package/src/utils/get-property-value.ts +0 -331
  156. package/src/utils/hash.ts +0 -26
  157. package/src/utils/literal-properties.ts +0 -97
  158. package/src/utils/load-addon-functions-meta.test.ts +0 -157
  159. package/src/utils/load-addon-functions-meta.ts +0 -508
  160. package/src/utils/load-addon-scopes.test.ts +0 -138
  161. package/src/utils/middleware.test.ts +0 -204
  162. package/src/utils/middleware.ts +0 -303
  163. package/src/utils/nested-project-filter.test.ts +0 -53
  164. package/src/utils/nested-project-filter.ts +0 -28
  165. package/src/utils/permissions-shorthand.test.ts +0 -79
  166. package/src/utils/permissions.test.ts +0 -125
  167. package/src/utils/permissions.ts +0 -129
  168. package/src/utils/post-process.test.ts +0 -1094
  169. package/src/utils/post-process.ts +0 -1604
  170. package/src/utils/resolve-addon-package.ts +0 -106
  171. package/src/utils/resolve-core-type.test.ts +0 -142
  172. package/src/utils/resolve-core-type.ts +0 -35
  173. package/src/utils/resolve-deploy-target.test.ts +0 -135
  174. package/src/utils/resolve-deploy-target.ts +0 -65
  175. package/src/utils/resolve-function-meta.ts +0 -25
  176. package/src/utils/resolve-function-types.ts +0 -42
  177. package/src/utils/resolve-identifier.ts +0 -46
  178. package/src/utils/resolve-ref-contract.ts +0 -71
  179. package/src/utils/resolve-versions.test.ts +0 -499
  180. package/src/utils/resolve-versions.ts +0 -228
  181. package/src/utils/schema-cache.test.ts +0 -124
  182. package/src/utils/schema-generator.test.ts +0 -272
  183. package/src/utils/schema-generator.ts +0 -780
  184. package/src/utils/secret-alias-services.test.ts +0 -146
  185. package/src/utils/secret-alias-services.ts +0 -58
  186. package/src/utils/serialize-inspector-state.ts +0 -742
  187. package/src/utils/serialize-mcp-json.ts +0 -150
  188. package/src/utils/serialize-middleware-groups-meta.ts +0 -36
  189. package/src/utils/serialize-openapi-json.ts +0 -277
  190. package/src/utils/serialize-permissions-groups-meta.ts +0 -7
  191. package/src/utils/single-declaration.ts +0 -57
  192. package/src/utils/type-utils.ts +0 -145
  193. package/src/utils/validate-auth-sessionless.ts +0 -30
  194. package/src/utils/validate-exposed-functions-gated.test.ts +0 -230
  195. package/src/utils/validate-exposed-functions-gated.ts +0 -103
  196. package/src/utils/validate-tags-resolve-to-middleware.test.ts +0 -108
  197. package/src/utils/validate-tags-resolve-to-middleware.ts +0 -48
  198. package/src/utils/workflow/derive-workflow-plan.test.ts +0 -178
  199. package/src/utils/workflow/derive-workflow-plan.ts +0 -117
  200. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +0 -1465
  201. package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +0 -71
  202. package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +0 -99
  203. package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +0 -161
  204. package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +0 -121
  205. package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +0 -116
  206. package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +0 -145
  207. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +0 -71
  208. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +0 -2254
  209. package/src/utils/workflow/dsl/index.ts +0 -11
  210. package/src/utils/workflow/dsl/patterns.ts +0 -440
  211. package/src/utils/workflow/dsl/validation.ts +0 -203
  212. package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +0 -35
  213. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +0 -543
  214. package/src/utils/workflow/graph/fanout-node-identity.test.ts +0 -105
  215. package/src/utils/workflow/graph/finalize-workflow-wires.ts +0 -310
  216. package/src/utils/workflow/graph/finalize-workflows.test.ts +0 -50
  217. package/src/utils/workflow/graph/finalize-workflows.ts +0 -130
  218. package/src/utils/workflow/graph/index.ts +0 -28
  219. package/src/utils/workflow/graph/serialize-workflow-graph.ts +0 -240
  220. package/src/utils/workflow/graph/workflow-graph.types.ts +0 -281
  221. package/src/visit.ts +0 -181
  222. package/tsconfig.json +0 -19
  223. package/tsconfig.tsbuildinfo +0 -1
package/src/types.ts DELETED
@@ -1,775 +0,0 @@
1
- import type * as ts from 'typescript'
2
- import type { SecretUsage } from './utils/extract-secret-usage.js'
3
- import type { SurfaceUsageCounts } from './utils/extract-surface-usage.js'
4
- import type { ChannelMessageMeta, ChannelsMeta } from '@pikku/core/channel'
5
- import type { GatewaysMeta } from '@pikku/core/gateway'
6
- import type { HTTPWiringsMeta } from '@pikku/core/http'
7
- import type { ScheduledTasksMeta } from '@pikku/core/scheduler'
8
- import type { TriggerMeta, TriggerSourceMeta } from '@pikku/core/trigger'
9
- import type { QueueWorkersMeta } from '@pikku/core/queue'
10
- import type { WorkflowsMeta } from '@pikku/core/workflow'
11
- import type {
12
- MCPResourceMeta,
13
- MCPToolMeta,
14
- MCPPromptMeta,
15
- } from '@pikku/core/mcp'
16
- import type { AgentsMeta } from '@pikku/core/agent'
17
- import type { ScorerMeta } from '@pikku/core/agent-scorer'
18
- import type { CLIMeta } from '@pikku/core/cli'
19
- import type { CLICommandMeta } from '@pikku/core/cli'
20
- import type { NodesMeta } from '@pikku/core/node'
21
- import type { SecretDefinitions } from '@pikku/core/secret'
22
- import type { CredentialDefinitions } from '@pikku/core/credential'
23
- import type { ScopeDefinitions } from '@pikku/core/scope'
24
- import type { SystemRoleDefinitions } from '@pikku/core/role'
25
- import type { PersonaDefinitions } from '@pikku/core/persona'
26
- import type { VariableDefinitions } from '@pikku/core/variable'
27
- import type { TypesMap } from './types-map.js'
28
- import type { FunctionsMeta } from '@pikku/core/services'
29
- import type {
30
- FunctionServicesMeta,
31
- FunctionWiresMeta,
32
- } from '@pikku/core/function'
33
- import type { JSONValue } from '@pikku/core/utils'
34
- import type { OpenAPISpecInfo } from './utils/serialize-openapi-json.js'
35
- import type { ErrorCode, CodedDiagnostic } from './error-codes.js'
36
- import type {
37
- VersionManifest,
38
- VersionValidateError,
39
- } from './utils/contract-hashes.js'
40
- import type { SerializedWorkflowGraphs } from './utils/workflow/graph/workflow-graph.types.js'
41
-
42
- export type PathToNameAndType = Map<
43
- string,
44
- { variable: string; type: string | null; typePath: string | null }[]
45
- >
46
-
47
- export type MetaInputTypes = Map<
48
- string,
49
- {
50
- query: string[] | undefined
51
- params: string[] | undefined
52
- body: string[] | undefined
53
- }
54
- >
55
-
56
- /** One `addHTTPMiddleware`/`addTagMiddleware`/`addChannelMiddleware` call. */
57
- export interface MiddlewareRegistration {
58
- exportName: string | null // null if not exported
59
- sourceFile: string
60
- position: number
61
- isFactory: boolean // true if wrapped in () => add...()
62
- }
63
-
64
- export interface MiddlewareGroupMeta extends MiddlewareRegistration {
65
- services: FunctionServicesMeta
66
- count: number
67
- instanceIds: string[]
68
- /**
69
- * The registrations after the first, when several files add middleware for
70
- * the same pattern or tag.
71
- *
72
- * A group is keyed by its pattern/tag, so without this a second file's call
73
- * overwrote the first's and only the survivor got an import emitted into
74
- * pikku-middleware.gen.ts — the losing file was never imported, so its
75
- * registration never ran. The runtime composes repeated registrations for a
76
- * pattern happily; only codegen dropped one, which is how an app could lose
77
- * its session-bridge middleware to an unrelated `'*'` group and see nothing
78
- * go wrong until a request arrived without a session.
79
- */
80
- additionalRegistrations?: MiddlewareRegistration[]
81
- }
82
-
83
- export interface InspectorHTTPState {
84
- metaInputTypes: MetaInputTypes
85
- meta: HTTPWiringsMeta
86
- files: Set<string>
87
- // HTTP middleware calls tracking - route pattern -> group metadata
88
- // Pattern '*' matches all routes (from addHTTPMiddleware('*', [...]))
89
- // Pattern '/api/*' matches specific routes (from addHTTPMiddleware('/api/*', [...]))
90
- routeMiddleware: Map<string, MiddlewareGroupMeta>
91
- }
92
-
93
- /**
94
- * Schema vendor types for Standard Schema compliant validators
95
- */
96
- export type SchemaVendor = 'zod' | 'valibot' | 'arktype' | 'effect' | 'unknown'
97
-
98
- /**
99
- * Schema reference for deferred conversion to JSON Schema at build time.
100
- * Supports Standard Schema compliant validators (Zod, Valibot, ArkType, Effect Schema).
101
- */
102
- export interface SchemaRef {
103
- variableName: string
104
- sourceFile: string
105
- vendor?: SchemaVendor
106
- }
107
-
108
- export interface InspectorFunctionState {
109
- typesMap: TypesMap
110
- meta: FunctionsMeta
111
- files: Map<string, { path: string; exportedName: string }>
112
- approvalDescriptions: Record<string, InspectorApprovalDescriptionDefinition>
113
- /**
114
- * pikkuFuncIds whose handler body performs a runtime dynamic `import(...)`.
115
- * Transient lint signal consumed by computeDiagnostics (PKU498) in the same
116
- * inspection pass — deliberately not part of the serialized function meta.
117
- */
118
- dynamicImportIds: Set<string>
119
- }
120
-
121
- export interface InspectorChannelState {
122
- meta: ChannelsMeta
123
- files: Set<string>
124
- }
125
-
126
- export interface ExportedHTTPRouteFunctionMeta {
127
- pikkuFuncId: string
128
- packageName?: string
129
- }
130
-
131
- export interface ExportedHTTPRouteConfigMeta {
132
- method: string
133
- route: string
134
- func: ExportedHTTPRouteFunctionMeta
135
- auth?: boolean
136
- tags?: string[]
137
- sse?: boolean
138
- contentType?: string
139
- timeout?: number
140
- headers?: Record<string, string>
141
- }
142
-
143
- export interface ExportedHTTPRoutesGroupMeta {
144
- basePath?: string
145
- tags?: string[]
146
- auth?: boolean
147
- routes: ExportedHTTPRouteMapMeta
148
- }
149
-
150
- export type ExportedHTTPRouteEntryMeta =
151
- | ExportedHTTPRouteConfigMeta
152
- | ExportedHTTPRoutesGroupMeta
153
- | ExportedHTTPRouteMapMeta
154
-
155
- export interface ExportedHTTPRouteMapMeta {
156
- [key: string]: ExportedHTTPRouteEntryMeta
157
- }
158
-
159
- export type ExportedHTTPContractsMeta = Record<
160
- string,
161
- ExportedHTTPRoutesGroupMeta
162
- >
163
-
164
- export interface ExportedChannelRouteMeta extends ChannelMessageMeta {
165
- auth?: boolean
166
- }
167
-
168
- export type ExportedChannelContractsMeta = Record<
169
- string,
170
- Record<string, ExportedChannelRouteMeta>
171
- >
172
-
173
- export type ExportedCLIContractsMeta = Record<
174
- string,
175
- Record<string, CLICommandMeta>
176
- >
177
-
178
- export interface InspectorExportedContractsState {
179
- http: ExportedHTTPContractsMeta
180
- cli: ExportedCLIContractsMeta
181
- channel: ExportedChannelContractsMeta
182
- addonHttp: Record<string, ExportedHTTPContractsMeta>
183
- addonCli: Record<string, ExportedCLIContractsMeta>
184
- addonChannel: Record<string, ExportedChannelContractsMeta>
185
- }
186
-
187
- export interface InspectorMiddlewareDefinition {
188
- services: FunctionServicesMeta
189
- wires?: FunctionWiresMeta
190
- sourceFile: string
191
- position: number
192
- exportedName: string | null
193
- factory?: boolean
194
- name?: string
195
- description?: string
196
- package?: string
197
- }
198
-
199
- export interface InspectorMiddlewareInstance {
200
- definitionId: string
201
- sourceFile: string
202
- position: number
203
- isFactoryCall: boolean
204
- }
205
-
206
- export interface InspectorMiddlewareState {
207
- definitions: Record<string, InspectorMiddlewareDefinition>
208
- instances: Record<string, InspectorMiddlewareInstance>
209
- tagMiddleware: Map<string, MiddlewareGroupMeta>
210
- }
211
-
212
- export interface InspectorChannelMiddlewareState {
213
- definitions: Record<string, InspectorMiddlewareDefinition>
214
- instances: Record<string, InspectorMiddlewareInstance>
215
- tagMiddleware: Map<string, MiddlewareGroupMeta>
216
- }
217
-
218
- export interface InspectorAIMiddlewareState {
219
- definitions: Record<string, InspectorMiddlewareDefinition>
220
- }
221
-
222
- export interface InspectorApprovalDescriptionDefinition {
223
- services: FunctionServicesMeta
224
- wires?: FunctionWiresMeta
225
- sourceFile: string
226
- position: number
227
- exportedName: string | null
228
- }
229
-
230
- export interface InspectorPermissionDefinition {
231
- services: FunctionServicesMeta
232
- wires?: FunctionWiresMeta
233
- sourceFile: string
234
- position: number
235
- exportedName: string | null
236
- factory?: boolean
237
- name?: string
238
- description?: string
239
- package?: string
240
- requiresData?: boolean
241
- }
242
-
243
- export interface InspectorPermissionInstance {
244
- definitionId: string
245
- sourceFile: string
246
- position: number
247
- isFactoryCall: boolean
248
- }
249
-
250
- export interface InspectorPermissionState {
251
- definitions: Record<string, InspectorPermissionDefinition>
252
- instances: Record<string, InspectorPermissionInstance>
253
- }
254
-
255
- export type InspectorFilters = {
256
- names?: string[] // Wildcard support: "email-*" matches "email-worker", "email-sender"
257
- tags?: string[]
258
- wires?: string[]
259
- directories?: string[]
260
- httpRoutes?: string[] // HTTP route patterns: "/api/*", "/webhooks/*"
261
- httpMethods?: string[] // HTTP methods: "GET", "POST", "DELETE", etc.
262
-
263
- excludeNames?: string[]
264
- excludeTags?: string[]
265
- excludeWires?: string[]
266
- excludeDirectories?: string[]
267
- excludeHttpRoutes?: string[]
268
- excludeHttpMethods?: string[]
269
-
270
- // Keep only functions whose effective deploy target is in this list.
271
- // A function's effective target is its explicit `deploy` field, or
272
- // 'server' if any of its services are listed in `serverlessIncompatible`,
273
- // otherwise 'serverless'.
274
- target?: Array<'serverless' | 'server'>
275
- excludeTarget?: Array<'serverless' | 'server'>
276
- // Service names that, when consumed by a function, force its target
277
- // to 'server'. Sourced from `pikku.config.json` →
278
- // `deploy.serverlessIncompatible`. Used only when deploy filters are set.
279
- serverlessIncompatible?: string[]
280
- // Default deploy target for functions without an explicit `deploy` flag.
281
- // Sourced from `pikku.config.json` → `deploy.defaultTarget`. Used only
282
- // when deploy filters are set. Defaults to 'serverless'.
283
- defaultTarget?: 'serverless' | 'server'
284
- }
285
-
286
- export type AddonConfig = {
287
- package: string
288
- rpcEndpoint?: string
289
- secretOverrides?: Record<string, string>
290
- forceInclude?: boolean
291
- }
292
-
293
- export interface InspectorPassStats {
294
- /** Source files in the ts.Program, node_modules and lib included. */
295
- files: number
296
- /** Files under rootDir the inspector actually swept. */
297
- projectFiles: number
298
- /**
299
- * Files served from the source-file cache without re-parsing. Zero on a
300
- * first pass; on a re-inspection it should be nearly all of `files` — that
301
- * reuse is what keeps a re-inspection cheaper than a cold one.
302
- */
303
- filesReused: number
304
- /** Checker work, as `tsc --extendedDiagnostics` counts it. */
305
- types: number
306
- instantiations: number
307
- symbols: number
308
- cpuMs: number
309
- wallMs: number
310
- /** V8 heap in use when the pass finished, before any GC. */
311
- heapUsedMb: number
312
- }
313
-
314
- export type InspectorOptions = Partial<{
315
- setupOnly: boolean
316
- rootDir: string
317
- isAddon: boolean
318
- /**
319
- * Fail the build on metadata that only an agent needs — currently an agent
320
- * tool with no description. Off by default: the runtime falls back to the
321
- * tool's own name, so this is a quality gate rather than a correctness one.
322
- */
323
- strictMeta: boolean
324
- /** The `models` table from pikku.config.json, alias -> `provider/model`. */
325
- modelAliases: Record<string, string>
326
- sourceFile: ts.SourceFile
327
- /**
328
- * The project's tsconfig, read for its path mappings only. The inspector's
329
- * program needs them to resolve imports the project reaches through `paths`;
330
- * unlike `schemaConfig.tsconfig` this is also needed on a setup-only run.
331
- */
332
- tsconfig: string
333
- types: Partial<{
334
- configFileType: string
335
- userSessionType: string
336
- singletonServicesFactoryType: string
337
- wireServicesFactoryType: string
338
- }>
339
- schemaConfig: {
340
- tsconfig: string
341
- schemasFromTypes?: string[]
342
- schema?: { additionalProperties?: boolean }
343
- /**
344
- * Directory for the on-disk TS-schema cache. When set, generated TS schemas
345
- * are persisted here keyed by a hash of the custom-types content, so a warm
346
- * `pikku all` whose function types are unchanged skips ts-json-schema-generator
347
- * entirely (the single largest cold-run cost). Omit to disable disk caching.
348
- */
349
- cacheDir?: string
350
- }
351
- openAPI: {
352
- additionalInfo: OpenAPISpecInfo
353
- }
354
- tags: string[]
355
- manifest: VersionManifest
356
- oldProgram: ts.Program | undefined
357
- /**
358
- * Run the data-classification leak scan (Private/Pii/Secret brands in function
359
- * return types). Off by default — it forces return-type inference on every
360
- * function, which is expensive. Enabled via `pikku all --security`.
361
- */
362
- classificationCheck: boolean
363
- /**
364
- * Escape hatches the project has opted into, from `allow` in
365
- * `pikku.config.json`. Absent or false means the feature is refused with a
366
- * critical naming the flag that would permit it.
367
- */
368
- allow: Partial<{
369
- permissionsInBody: boolean
370
- complexWorkflows: boolean
371
- }>
372
- }>
373
-
374
- export interface InspectorLogger {
375
- info: (message: string) => void
376
- error: (message: string) => void
377
- warn: (message: string) => void
378
- debug: (message: string) => void
379
- /**
380
- * Emit a tracked, coded diagnostic. It is recorded and printed; `error`/`warn`
381
- * only block the build when the CLI is run with `--fail-on-error` /
382
- * `--fail-on-warn` (default: critical only). Use this for issues worth
383
- * surfacing (e.g. data-classification leaks) that should not stop the dev
384
- * server from starting.
385
- */
386
- diagnostic: (diagnostic: CodedDiagnostic) => void
387
- /** Sugar for `diagnostic({ severity: 'critical', code, message })`. */
388
- critical: (code: ErrorCode, message: string) => void
389
- hasCriticalErrors: () => boolean
390
- /**
391
- * Opens a validation pass, discarding whatever a previous one recorded.
392
- *
393
- * A single `pikku all` inspects several times, because generating the
394
- * scaffold, the leaf indexes and the type files each changes the source graph
395
- * the next inspection reads. The validators are pure functions of that graph
396
- * and every full inspection re-runs all of them, so the newest pass is always
397
- * the complete one and the ones before it are strictly superseded.
398
- *
399
- * Without this the diagnostics accumulated instead, and a run failed on a
400
- * complaint about its own half-built input: a project whose roles reference
401
- * scaffold-declared scopes was reported as failing even though the pass that
402
- * ran once the scaffold existed was clean. Optional so a host supplying its
403
- * own logger keeps working — one that omits it simply never discards.
404
- */
405
- beginValidationPass?: () => void
406
- /** Closes the pass opened by `beginValidationPass`. */
407
- endValidationPass?: () => void
408
- }
409
-
410
- export type AddWiring = (
411
- logger: InspectorLogger,
412
- node: ts.Node,
413
- checker: ts.TypeChecker,
414
- state: InspectorState,
415
- options: InspectorOptions
416
- ) => void
417
- export interface InspectorFilesAndMethods {
418
- userSessionType?: {
419
- file: string
420
- variable: string
421
- type: string
422
- typePath: string
423
- }
424
- wireServicesType?: {
425
- file: string
426
- variable: string
427
- type: string
428
- typePath: string
429
- }
430
- singletonServicesType?: {
431
- file: string
432
- variable: string
433
- type: string
434
- typePath: string
435
- }
436
- pikkuConfigType?: {
437
- file: string
438
- variable: string
439
- type: string
440
- typePath: string
441
- }
442
- pikkuConfigFactory?: {
443
- file: string
444
- variable: string
445
- type: string
446
- typePath: string
447
- }
448
- singletonServicesFactory?: {
449
- file: string
450
- variable: string
451
- type: string
452
- typePath: string
453
- }
454
- wireServicesFactory?: {
455
- file: string
456
- variable: string
457
- type: string
458
- typePath: string
459
- }
460
- serverLifecycleFactory?: {
461
- file: string
462
- variable: string
463
- type: string
464
- typePath: string
465
- }
466
- }
467
-
468
- export interface InspectorDiagnostic {
469
- code: string
470
- message: string
471
- sourceFile: string
472
- position: number
473
- }
474
-
475
- /** A single discovered `export const X = pikkuBetterAuth((services) => betterAuth({...}))`. */
476
- export interface AuthDefinition {
477
- /** The exported binding name the CLI imports (`export const <exportName>`). */
478
- exportName: string
479
- /** Absolute path of the file declaring it. */
480
- sourceFile: string
481
- /** better-auth base path (the `basePath` option, default `/api/auth`). */
482
- basePath: string
483
- /** Whether email/password auth is enabled (`emailAndPassword.enabled`). Written
484
- * into the generated `auth-meta.gen.json` so the console knows credentials are
485
- * available alongside the OAuth providers. */
486
- hasCredentials: boolean
487
- /** better-auth plugin ids used in the config's `plugins: [...]` array, read
488
- * from each entry's callee name (e.g. `bearer()` → `'bearer'`). Written into
489
- * `auth-meta.gen.json` so the console SSO page can show which plugins are
490
- * enabled. */
491
- plugins: string[]
492
- /** Whether `session.cookieCache` is enabled — drives the stateless session
493
- * middleware split in the auth codegen. Absent/false ⇒ stateful middleware. */
494
- cookieCache?: boolean
495
- /**
496
- * Singleton services the generated auth handler must have available at
497
- * runtime — the services the `pikkuBetterAuth` factory reaches for (either
498
- * destructured from its first param, or accessed as `services.<name>` in its
499
- * body). better-auth's factory typically touches `secrets` and the DB.
500
- *
501
- * The generated `authHandler` calls `createAuthHandler(...).func`, an opaque
502
- * property access the inspector can't see through; without this stamp the
503
- * deployed auth worker would instantiate none of these services and the
504
- * factory would receive an undefined `kysely`. Re-derived every inspect and
505
- * applied to the handler meta before service aggregation runs.
506
- */
507
- services: FunctionServicesMeta
508
- }
509
-
510
- /** One statically resolved entry of a feature's `scenarios` array. */
511
- export interface InspectorFeatureEntry {
512
- /** The scenario's declared export name, with any import alias followed back. */
513
- scenario: string
514
- /** A `{ scenario, data }` entry's literal data — gherkin's `Examples:`. */
515
- data?: unknown
516
- }
517
-
518
- /** A `pikkuFeature` export, as far as it can be read from the source. */
519
- export interface InspectorFeature {
520
- path: string
521
- exportedName: string
522
- name?: string
523
- description?: string
524
- tags?: string[]
525
- entries: InspectorFeatureEntry[]
526
- /**
527
- * Entries that are not literal — a spread, a `.map()`, a call. Counted rather
528
- * than dropped so the console can say the listing is partial instead of
529
- * quietly showing a short feature.
530
- */
531
- unresolvedEntries: number
532
- /**
533
- * Feature hooks run once around the whole group, never per scenario, and are
534
- * runtime-only — so only their presence is recorded.
535
- */
536
- hasBefore: boolean
537
- hasAfter: boolean
538
- }
539
-
540
- export interface InspectorState {
541
- rootDir: string // Root directory inferred from source files
542
- singletonServicesTypeImportMap: PathToNameAndType
543
- wireServicesTypeImportMap: PathToNameAndType
544
- userSessionTypeImportMap: PathToNameAndType
545
- configTypeImportMap: PathToNameAndType
546
- singletonServicesFactories: PathToNameAndType
547
- wireServicesFactories: PathToNameAndType
548
- wireServicesMeta: Map<string, string[]> // variable name -> singleton services consumed
549
- addonRequiredParentServices: string[] // services an addon needs from the parent (extracted from pikkuAddonServices 2nd param)
550
- addonCreatedServices: string[] // services an addon's own pikkuAddonServices factory builds itself
551
- addonServicesFactorySeen: boolean // this project declares a pikkuAddonServices factory, i.e. it is an addon
552
- addonServerlessIncompatible: Map<string, string[]> // namespace → service names that are serverless-incompatible (scoped per addon)
553
- configFactories: PathToNameAndType
554
- serverLifecycleFactories: PathToNameAndType
555
- filesAndMethods: InspectorFilesAndMethods
556
- filesAndMethodsErrors: Map<string, PathToNameAndType>
557
- typesLookup: Map<string, ts.Type[]> // Lookup for types by name (e.g., function input types, Config type)
558
- /**
559
- * What this pass cost, in counts rather than time where it can be counted:
560
- * counts don't move with the machine, so they are what a perf gate can
561
- * compare across runners (see benchmarks/bench-codegen-perf.ts).
562
- */
563
- stats?: InspectorPassStats
564
- schemaLookup: Map<string, SchemaRef> // Lookup for schemas by name for deferred JSON Schema conversion (supports Standard Schema vendors)
565
- schemas: Record<string, JSONValue>
566
- http: InspectorHTTPState
567
- functions: InspectorFunctionState
568
- channels: InspectorChannelState
569
- gateways: {
570
- meta: GatewaysMeta
571
- files: Set<string>
572
- }
573
- triggers: {
574
- meta: TriggerMeta
575
- sourceMeta: TriggerSourceMeta
576
- files: Set<string>
577
- }
578
- scheduledTasks: {
579
- meta: ScheduledTasksMeta
580
- files: Set<string>
581
- }
582
- queueWorkers: {
583
- meta: QueueWorkersMeta
584
- files: Set<string>
585
- }
586
- workflows: {
587
- meta: WorkflowsMeta
588
- files: Map<string, { path: string; exportedName: string }>
589
- graphMeta: SerializedWorkflowGraphs
590
- graphFiles: Map<string, { path: string; exportedName: string }>
591
- /**
592
- * `pikkuFeature` exports, keyed by export identifier.
593
- *
594
- * Everything the config states literally is extracted here, because a
595
- * feature is the document structure the console renders. Entries built by
596
- * an ordinary loop cannot be enumerated statically — those are counted in
597
- * `unresolvedEntries` and resolved at runtime by object identity instead.
598
- */
599
- featureFiles: Map<string, InspectorFeature>
600
- invokedWorkflows: Set<string>
601
- }
602
- rpc: {
603
- internalMeta: Record<string, string>
604
- internalFiles: Map<string, { path: string; exportedName: string }>
605
- exposedMeta: Record<string, string>
606
- exposedFiles: Map<string, { path: string; exportedName: string }>
607
- /** Functions marked `remote: true` — the surface a wireRemoteAddon consumer imports */
608
- remoteMeta: Record<string, string>
609
- remoteFiles: Map<string, { path: string; exportedName: string }>
610
- invokedFunctions: Set<string>
611
- invokedFunctionsByFile: Map<string, Set<string>>
612
- usedAddons: Set<string>
613
- wireAddonDeclarations: Map<
614
- string,
615
- {
616
- package: string
617
- rpcEndpoint?: string
618
- mcp?: boolean
619
- /**
620
- * The addon's own gates. `runPikkuFunc` applies these to every function
621
- * in the package, on every wiring path — not just `namespace:function`.
622
- * Absent when the declared value was not a statically-knowable literal,
623
- * which must be read as "unknown", never as "ungated".
624
- */
625
- auth?: boolean
626
- tags?: string[]
627
- scopes?: string[]
628
- /** True when declared via `wireRemoteAddon` — import the addon's `.remote.gen` map, not `.internal.gen` */
629
- remote?: boolean
630
- /** wireRemoteAddon: whether an `auth` binding was supplied (vs a public surface) */
631
- hasAuth?: boolean
632
- /** wireRemoteAddon: statically-known `auth.credentialId`, for verify */
633
- authCredentialId?: string
634
- /** wireRemoteAddon: statically-known `auth.secretId`, for verify */
635
- authSecretId?: string
636
- secretOverrides?: Record<string, string>
637
- variableOverrides?: Record<string, string>
638
- credentialOverrides?: Record<string, string>
639
- /** Secrets the app lends this instance, named as the addon reads them. */
640
- secretGrants?: string[]
641
- /** Credentials the app lends this instance, named as the addon reads them. */
642
- credentialGrants?: string[]
643
- /**
644
- * The app's stated reason for handing this instance the whole
645
- * `SecretService` instead of one scoped to its declared secrets.
646
- */
647
- globalSecrets?: string
648
- /**
649
- * The app's stated reason for handing this instance the whole
650
- * `CredentialService` instead of one scoped to its declared credentials.
651
- */
652
- globalCredentials?: string
653
- }
654
- >
655
- wireAddonFiles: Set<string>
656
- }
657
- mcpEndpoints: {
658
- resourcesMeta: MCPResourceMeta
659
- toolsMeta: MCPToolMeta
660
- promptsMeta: MCPPromptMeta
661
- files: Set<string>
662
- }
663
- agents: {
664
- agentsMeta: AgentsMeta
665
- files: Map<string, { path: string; exportedName: string }>
666
- /**
667
- * Agent registry keys named by a `runAgent`/`rpc.agent.run` call in a
668
- * function body, keyed by the file the call was written in.
669
- *
670
- * The lookup those calls perform is in-process, so the agent has to be
671
- * registered in the same deployment unit as its caller. Without this the
672
- * deploy analyzer only ever saw an agent as its own unit, and a caller in
673
- * another unit failed at run time with "AI agent not found".
674
- */
675
- invokedAgentsByFile: Map<string, Set<string>>
676
- }
677
- scorers: {
678
- scorersMeta: ScorerMeta
679
- files: Map<string, { path: string; exportedName: string }>
680
- }
681
- cli: {
682
- meta: CLIMeta
683
- files: Set<string>
684
- }
685
- nodes: {
686
- meta: NodesMeta
687
- files: Set<string>
688
- }
689
- auth: {
690
- providers: string[]
691
- plugins: string[]
692
- files: Set<string>
693
- /** The single `export const X = pikkuBetterAuth({...})` discovered in the
694
- * codebase, if any. The CLI generates the `/auth/*` HTTP wiring from it.
695
- * More than one `pikkuBetterAuth` is a critical error. */
696
- definition: AuthDefinition | null
697
- /** True when a user (non-generated) file already registers
698
- * `betterAuthStatelessSession(...)`. The CLI then skips auto-generating its
699
- * own default-map stateless middleware, which would otherwise pre-empt the
700
- * user's custom mapSession (pikkujs/pikku#754). */
701
- userStatelessSession?: boolean
702
- /** True when a user (non-generated) file already registers a global
703
- * `betterAuthSession(...)`. The CLI then skips auto-generating its own
704
- * default stateful middleware, which would otherwise run first and pre-empt
705
- * the user's config (mapSession/impersonation/apiKey). Stateful analogue of
706
- * `userStatelessSession`. */
707
- hasUserSessionMiddleware?: boolean
708
- }
709
- secrets: {
710
- definitions: SecretDefinitions
711
- files: Set<string>
712
- /** Secret reads found per source file, keyed by absolute path. */
713
- usage: Map<string, SecretUsage>
714
- }
715
- /** How often each `#pikku/*` export is imported, and from where. */
716
- surfaceUsage: SurfaceUsageCounts
717
- credentials: {
718
- definitions: CredentialDefinitions
719
- files: Set<string>
720
- }
721
- scopes: {
722
- definitions: ScopeDefinitions
723
- files: Set<string>
724
- }
725
- systemRoles: {
726
- definitions: SystemRoleDefinitions
727
- files: Set<string>
728
- }
729
- personas: {
730
- definitions: PersonaDefinitions
731
- files: Set<string>
732
- }
733
- variables: {
734
- definitions: VariableDefinitions
735
- files: Set<string>
736
- }
737
- manifest: {
738
- initial: VersionManifest | null
739
- current: VersionManifest | null
740
- errors: VersionValidateError[]
741
- }
742
- middleware: InspectorMiddlewareState
743
- channelMiddleware: InspectorChannelMiddlewareState
744
- agentMiddleware: InspectorAIMiddlewareState
745
- permissions: InspectorPermissionState
746
- serviceAggregation: {
747
- requiredServices: Set<string>
748
- usedFunctions: Set<string>
749
- usedMiddleware: Set<string>
750
- usedPermissions: Set<string>
751
- allSingletonServices: string[]
752
- allWireServices: string[]
753
- }
754
- resolvedIOTypes: Record<string, { inputType: string; outputType: string }>
755
- middlewareGroupsMeta: {
756
- definitions: Record<string, InspectorMiddlewareDefinition>
757
- instances: Record<string, InspectorMiddlewareInstance>
758
- httpGroups: Record<string, MiddlewareGroupMeta>
759
- tagGroups: Record<string, MiddlewareGroupMeta>
760
- channelMiddleware: {
761
- definitions: Record<string, InspectorMiddlewareDefinition>
762
- instances: Record<string, InspectorMiddlewareInstance>
763
- tagGroups: Record<string, MiddlewareGroupMeta>
764
- }
765
- }
766
- permissionsGroupsMeta: {
767
- definitions: Record<string, InspectorPermissionDefinition>
768
- }
769
- requiredSchemas: Set<string>
770
- openAPISpec: Record<string, any> | null
771
- diagnostics: InspectorDiagnostic[]
772
- addonFunctions: Record<string, FunctionsMeta> // namespace -> addon's function metadata
773
- exportedContracts: InspectorExportedContractsState
774
- program: ts.Program | null // Retained for incremental re-inspection
775
- }