ts-procedures 10.1.2 → 10.2.1

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 (272) hide show
  1. package/CHANGELOG.md +33 -86
  2. package/README.md +11 -6
  3. package/agent_config/bin/postinstall.mjs +20 -89
  4. package/agent_config/bin/setup.mjs +51 -264
  5. package/agent_config/lib/install-skills.mjs +108 -0
  6. package/agent_config/{claude-code/skills → skills}/ts-procedures/anti-patterns.md +8 -0
  7. package/agent_config/{claude-code/skills → skills}/ts-procedures/api-reference.md +25 -22
  8. package/agent_config/{claude-code/skills → skills}/ts-procedures/patterns.md +24 -13
  9. package/build/adapters/hono/envelope-parity.test.js +6 -17
  10. package/build/adapters/hono/envelope-parity.test.js.map +1 -1
  11. package/build/adapters/hono/handlers/http-stream.d.ts +2 -1
  12. package/build/adapters/hono/handlers/http-stream.js +9 -2
  13. package/build/adapters/hono/handlers/http-stream.js.map +1 -1
  14. package/build/adapters/hono/handlers/http.d.ts +2 -1
  15. package/build/adapters/hono/handlers/http.js +9 -2
  16. package/build/adapters/hono/handlers/http.js.map +1 -1
  17. package/build/adapters/hono/handlers/rpc.d.ts +2 -1
  18. package/build/adapters/hono/handlers/rpc.js +9 -2
  19. package/build/adapters/hono/handlers/rpc.js.map +1 -1
  20. package/build/adapters/hono/handlers/stream.d.ts +2 -1
  21. package/build/adapters/hono/handlers/stream.js +9 -2
  22. package/build/adapters/hono/handlers/stream.js.map +1 -1
  23. package/build/adapters/hono/index.d.ts +14 -7
  24. package/build/adapters/hono/index.js +45 -5
  25. package/build/adapters/hono/index.js.map +1 -1
  26. package/build/adapters/hono/index.test.js +55 -0
  27. package/build/adapters/hono/index.test.js.map +1 -1
  28. package/build/adapters/hono/request.d.ts +7 -0
  29. package/build/adapters/hono/request.js +15 -0
  30. package/build/adapters/hono/request.js.map +1 -1
  31. package/build/adapters/hono/types.d.ts +31 -0
  32. package/build/adapters/hono/types.js.map +1 -1
  33. package/build/codegen/bin/cli.js +1 -1
  34. package/build/codegen/bin/cli.js.map +1 -1
  35. package/build/codegen/constants.js +2 -2
  36. package/build/codegen/constants.js.map +1 -1
  37. package/build/codegen/emit/api-route.js +1 -1
  38. package/build/codegen/emit/api-route.js.map +1 -1
  39. package/build/codegen/emit/scope-file.js +1 -1
  40. package/build/codegen/emit/scope-file.js.map +1 -1
  41. package/build/codegen/emit-errors.integration.test.js +2 -2
  42. package/build/codegen/emit-errors.integration.test.js.map +1 -1
  43. package/build/codegen/resolve-envelope.js +1 -1
  44. package/build/codegen/resolve-envelope.js.map +1 -1
  45. package/build/codegen/test-helpers/run-tsc.js +1 -1
  46. package/build/codegen/test-helpers/run-tsc.js.map +1 -1
  47. package/build/core/create-http-stream.d.ts +3 -14
  48. package/build/core/create-http-stream.js +4 -2
  49. package/build/core/create-http-stream.js.map +1 -1
  50. package/build/core/create-http.d.ts +2 -9
  51. package/build/core/create-http.js +3 -2
  52. package/build/core/create-http.js.map +1 -1
  53. package/build/core/create-http.test-d.js +104 -0
  54. package/build/core/create-http.test-d.js.map +1 -0
  55. package/build/core/create-stream.js +6 -2
  56. package/build/core/create-stream.js.map +1 -1
  57. package/build/core/create.js +5 -4
  58. package/build/core/create.js.map +1 -1
  59. package/build/core/create.test.js +63 -0
  60. package/build/core/create.test.js.map +1 -1
  61. package/build/core/internal.d.ts +16 -0
  62. package/build/core/internal.js +22 -0
  63. package/build/core/internal.js.map +1 -1
  64. package/build/core/procedures.d.ts +9 -16
  65. package/build/core/procedures.js +4 -0
  66. package/build/core/procedures.js.map +1 -1
  67. package/build/core/types.d.ts +85 -4
  68. package/build/errors.d.ts +33 -0
  69. package/build/errors.js +91 -0
  70. package/build/errors.js.map +1 -0
  71. package/build/errors.test.d.ts +1 -0
  72. package/build/errors.test.js +122 -0
  73. package/build/errors.test.js.map +1 -0
  74. package/build/exports.d.ts +1 -2
  75. package/build/exports.js +0 -4
  76. package/build/exports.js.map +1 -1
  77. package/build/implementations/http/doc-registry.d.ts +28 -0
  78. package/build/implementations/http/doc-registry.js +96 -0
  79. package/build/implementations/http/doc-registry.js.map +1 -0
  80. package/build/implementations/http/doc-registry.test.d.ts +1 -0
  81. package/build/implementations/http/doc-registry.test.js +516 -0
  82. package/build/implementations/http/doc-registry.test.js.map +1 -0
  83. package/build/implementations/http/error-taxonomy.d.ts +249 -0
  84. package/build/implementations/http/error-taxonomy.js +252 -0
  85. package/build/implementations/http/error-taxonomy.js.map +1 -0
  86. package/build/implementations/http/error-taxonomy.test.d.ts +1 -0
  87. package/build/implementations/http/error-taxonomy.test.js +399 -0
  88. package/build/implementations/http/error-taxonomy.test.js.map +1 -0
  89. package/build/implementations/http/express-rpc/error-taxonomy.test.d.ts +1 -0
  90. package/build/implementations/http/express-rpc/error-taxonomy.test.js +83 -0
  91. package/build/implementations/http/express-rpc/error-taxonomy.test.js.map +1 -0
  92. package/build/implementations/http/express-rpc/index.d.ts +125 -0
  93. package/build/implementations/http/express-rpc/index.js +216 -0
  94. package/build/implementations/http/express-rpc/index.js.map +1 -0
  95. package/build/implementations/http/express-rpc/index.test.d.ts +1 -0
  96. package/build/implementations/http/express-rpc/index.test.js +684 -0
  97. package/build/implementations/http/express-rpc/index.test.js.map +1 -0
  98. package/build/implementations/http/express-rpc/types.d.ts +11 -0
  99. package/build/implementations/http/express-rpc/types.js +2 -0
  100. package/build/implementations/http/express-rpc/types.js.map +1 -0
  101. package/build/implementations/http/hono-api/error-taxonomy.test.d.ts +1 -0
  102. package/build/implementations/http/hono-api/error-taxonomy.test.js +137 -0
  103. package/build/implementations/http/hono-api/error-taxonomy.test.js.map +1 -0
  104. package/build/implementations/http/hono-api/index.d.ts +151 -0
  105. package/build/implementations/http/hono-api/index.js +344 -0
  106. package/build/implementations/http/hono-api/index.js.map +1 -0
  107. package/build/implementations/http/hono-api/index.test.d.ts +1 -0
  108. package/build/implementations/http/hono-api/index.test.js +992 -0
  109. package/build/implementations/http/hono-api/index.test.js.map +1 -0
  110. package/build/implementations/http/hono-api/types.d.ts +13 -0
  111. package/build/implementations/http/hono-api/types.js +2 -0
  112. package/build/implementations/http/hono-api/types.js.map +1 -0
  113. package/build/implementations/http/hono-rpc/error-taxonomy.test.d.ts +1 -0
  114. package/build/implementations/http/hono-rpc/error-taxonomy.test.js +64 -0
  115. package/build/implementations/http/hono-rpc/error-taxonomy.test.js.map +1 -0
  116. package/build/implementations/http/hono-rpc/index.d.ts +130 -0
  117. package/build/implementations/http/hono-rpc/index.js +209 -0
  118. package/build/implementations/http/hono-rpc/index.js.map +1 -0
  119. package/build/implementations/http/hono-rpc/index.test.d.ts +1 -0
  120. package/build/implementations/http/hono-rpc/index.test.js +828 -0
  121. package/build/implementations/http/hono-rpc/index.test.js.map +1 -0
  122. package/build/implementations/http/hono-rpc/types.d.ts +11 -0
  123. package/build/implementations/http/hono-rpc/types.js +2 -0
  124. package/build/implementations/http/hono-rpc/types.js.map +1 -0
  125. package/build/implementations/http/hono-stream/error-taxonomy.test.d.ts +1 -0
  126. package/build/implementations/http/hono-stream/error-taxonomy.test.js +159 -0
  127. package/build/implementations/http/hono-stream/error-taxonomy.test.js.map +1 -0
  128. package/build/implementations/http/hono-stream/index.d.ts +171 -0
  129. package/build/implementations/http/hono-stream/index.js +415 -0
  130. package/build/implementations/http/hono-stream/index.js.map +1 -0
  131. package/build/implementations/http/hono-stream/index.test.d.ts +1 -0
  132. package/build/implementations/http/hono-stream/index.test.js +1383 -0
  133. package/build/implementations/http/hono-stream/index.test.js.map +1 -0
  134. package/build/implementations/http/hono-stream/types.d.ts +15 -0
  135. package/build/implementations/http/hono-stream/types.js +2 -0
  136. package/build/implementations/http/hono-stream/types.js.map +1 -0
  137. package/build/implementations/http/on-request-error.test.d.ts +1 -0
  138. package/build/implementations/http/on-request-error.test.js +173 -0
  139. package/build/implementations/http/on-request-error.test.js.map +1 -0
  140. package/build/implementations/http/route-errors.test.d.ts +1 -0
  141. package/build/implementations/http/route-errors.test.js +139 -0
  142. package/build/implementations/http/route-errors.test.js.map +1 -0
  143. package/build/implementations/types.d.ts +192 -0
  144. package/build/implementations/types.js +2 -0
  145. package/build/implementations/types.js.map +1 -0
  146. package/build/index.d.ts +165 -0
  147. package/build/index.js +258 -0
  148. package/build/index.js.map +1 -0
  149. package/build/index.test.d.ts +1 -0
  150. package/build/index.test.js +920 -0
  151. package/build/index.test.js.map +1 -0
  152. package/build/schema/compute-schema.js +1 -5
  153. package/build/schema/compute-schema.js.map +1 -1
  154. package/build/schema/compute-schema.test.js +0 -13
  155. package/build/schema/compute-schema.test.js.map +1 -1
  156. package/build/schema/extract-json-schema.d.ts +2 -0
  157. package/build/schema/extract-json-schema.js +12 -0
  158. package/build/schema/extract-json-schema.js.map +1 -0
  159. package/build/schema/extract-json-schema.test.d.ts +1 -0
  160. package/build/schema/extract-json-schema.test.js +23 -0
  161. package/build/schema/extract-json-schema.test.js.map +1 -0
  162. package/build/schema/parser.d.ts +28 -0
  163. package/build/schema/parser.js +170 -0
  164. package/build/schema/parser.js.map +1 -0
  165. package/build/schema/parser.test.d.ts +1 -0
  166. package/build/schema/parser.test.js +120 -0
  167. package/build/schema/parser.test.js.map +1 -0
  168. package/build/schema/resolve-schema-lib.d.ts +12 -0
  169. package/build/schema/resolve-schema-lib.js +11 -0
  170. package/build/schema/resolve-schema-lib.js.map +1 -0
  171. package/build/schema/resolve-schema-lib.test.d.ts +1 -0
  172. package/build/schema/resolve-schema-lib.test.js +17 -0
  173. package/build/schema/resolve-schema-lib.test.js.map +1 -0
  174. package/build/schema/typebox.d.ts +1 -1
  175. package/build/schema/typebox.js +2 -20
  176. package/build/schema/typebox.js.map +1 -1
  177. package/build/schema/typebox.test.js +0 -10
  178. package/build/schema/typebox.test.js.map +1 -1
  179. package/build/schema/types.d.ts +8 -0
  180. package/build/schema/types.js +2 -0
  181. package/build/schema/types.js.map +1 -0
  182. package/build/server/context.d.ts +12 -2
  183. package/build/server/context.js +49 -4
  184. package/build/server/context.js.map +1 -1
  185. package/build/server/context.test.js +32 -1
  186. package/build/server/context.test.js.map +1 -1
  187. package/build/server/doc-registry.js +0 -3
  188. package/build/server/doc-registry.js.map +1 -1
  189. package/build/server/doc-registry.test.js +0 -31
  190. package/build/server/doc-registry.test.js.map +1 -1
  191. package/build/server/index.d.ts +0 -1
  192. package/build/server/index.js +0 -1
  193. package/build/server/index.js.map +1 -1
  194. package/build/server/types.d.ts +6 -27
  195. package/build/stack-utils.d.ts +25 -0
  196. package/build/stack-utils.js +95 -0
  197. package/build/stack-utils.js.map +1 -0
  198. package/build/stack-utils.test.d.ts +1 -0
  199. package/build/stack-utils.test.js +80 -0
  200. package/build/stack-utils.test.js.map +1 -0
  201. package/docs/ai-agent-setup.md +19 -27
  202. package/docs/client-error-handling.md +1 -1
  203. package/docs/core.md +8 -0
  204. package/docs/http-integrations.md +42 -28
  205. package/package.json +8 -8
  206. package/src/adapters/astro/README.md +2 -0
  207. package/src/adapters/hono/envelope-parity.test.ts +6 -18
  208. package/src/adapters/hono/handlers/http-stream.ts +12 -3
  209. package/src/adapters/hono/handlers/http.ts +12 -3
  210. package/src/adapters/hono/handlers/rpc.ts +12 -3
  211. package/src/adapters/hono/handlers/stream.ts +12 -3
  212. package/src/adapters/hono/index.test.ts +70 -0
  213. package/src/adapters/hono/index.ts +53 -11
  214. package/src/adapters/hono/request.ts +18 -0
  215. package/src/adapters/hono/types.ts +37 -0
  216. package/src/codegen/bin/cli.ts +1 -1
  217. package/src/codegen/constants.ts +2 -2
  218. package/src/codegen/emit/api-route.ts +1 -1
  219. package/src/codegen/emit/scope-file.ts +1 -2
  220. package/src/codegen/emit-errors.integration.test.ts +2 -2
  221. package/src/codegen/resolve-envelope.ts +1 -1
  222. package/src/codegen/test-helpers/run-tsc.ts +0 -1
  223. package/src/core/create-http-stream.ts +20 -13
  224. package/src/core/create-http.test-d.ts +154 -0
  225. package/src/core/create-http.ts +19 -8
  226. package/src/core/create-stream.ts +12 -4
  227. package/src/core/create.test.ts +74 -0
  228. package/src/core/create.ts +10 -5
  229. package/src/core/internal.ts +35 -0
  230. package/src/core/procedures.ts +4 -0
  231. package/src/core/types.ts +99 -4
  232. package/src/exports.ts +6 -4
  233. package/src/schema/compute-schema.test.ts +0 -16
  234. package/src/schema/compute-schema.ts +1 -5
  235. package/src/schema/typebox.test.ts +0 -12
  236. package/src/schema/typebox.ts +2 -21
  237. package/src/server/context.test.ts +39 -1
  238. package/src/server/context.ts +54 -4
  239. package/src/server/doc-registry.test.ts +0 -34
  240. package/src/server/doc-registry.ts +0 -3
  241. package/src/server/index.ts +0 -1
  242. package/src/server/types.ts +8 -27
  243. package/agent_config/claude-code/.claude-plugin/plugin.json +0 -5
  244. package/agent_config/claude-code/agents/ts-procedures-architect.md +0 -138
  245. package/agent_config/copilot/copilot-instructions.md +0 -521
  246. package/agent_config/cursor/cursorrules +0 -521
  247. package/agent_config/lib/install-claude.mjs +0 -57
  248. package/build/schema/strip-internal-keywords.d.ts +0 -18
  249. package/build/schema/strip-internal-keywords.js +0 -33
  250. package/build/schema/strip-internal-keywords.js.map +0 -1
  251. package/build/schema/strip-internal-keywords.test.js +0 -38
  252. package/build/schema/strip-internal-keywords.test.js.map +0 -1
  253. package/build/server/spec-version.d.ts +0 -24
  254. package/build/server/spec-version.js +0 -26
  255. package/build/server/spec-version.js.map +0 -1
  256. package/build/version.d.ts +0 -9
  257. package/build/version.js +0 -11
  258. package/build/version.js.map +0 -1
  259. package/docs/doc-envelope-spec-v1.md +0 -296
  260. package/docs/doc-envelope-v1.schema.json +0 -253
  261. package/src/schema/strip-internal-keywords.test.ts +0 -43
  262. package/src/schema/strip-internal-keywords.ts +0 -36
  263. package/src/server/spec-version.ts +0 -27
  264. package/src/version.ts +0 -11
  265. /package/agent_config/{claude-code/skills → skills}/ts-procedures/SKILL.md +0 -0
  266. /package/agent_config/{claude-code/skills → skills}/ts-procedures/checklist.md +0 -0
  267. /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/astro-catchall.md +0 -0
  268. /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/client.md +0 -0
  269. /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/hono.md +0 -0
  270. /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/procedure.md +0 -0
  271. /package/agent_config/{claude-code/skills → skills}/ts-procedures/templates/stream-procedure.md +0 -0
  272. /package/build/{schema/strip-internal-keywords.test.d.ts → core/create-http.test-d.d.ts} +0 -0
@@ -5,9 +5,7 @@ import type {
5
5
  THttpStreamProcedureRegistration,
6
6
  TProcedureRegistration,
7
7
  } from '../core/types.js'
8
- import pkg from '../../package.json' with { type: 'json' }
9
8
  import { DocRegistry } from './doc-registry.js'
10
- import { DOC_ENVELOPE_SPEC_VERSION, DOC_ENVELOPE_GENERATOR_VERSION } from './spec-version.js'
11
9
  import { defineErrorTaxonomy } from './errors/taxonomy.js'
12
10
  import { buildRpcRouteDoc } from './docs/rpc-doc.js'
13
11
  import { buildHttpStreamRouteDoc } from './docs/http-stream-doc.js'
@@ -203,38 +201,6 @@ describe('DocRegistry', () => {
203
201
  })
204
202
  })
205
203
 
206
- // --------------------------------------------------------------------------
207
- // toJSON() spec metadata
208
- // --------------------------------------------------------------------------
209
- describe('toJSON() spec metadata', () => {
210
- test('emits specVersion (the constant, a number) and generatorVersion (the package version)', () => {
211
- const out = new DocRegistry().toJSON()
212
- expect(out.specVersion).toBe(DOC_ENVELOPE_SPEC_VERSION)
213
- expect(typeof out.specVersion).toBe('number')
214
- expect(out.generatorVersion).toBe(pkg.version)
215
- // the exported constant must track the real package version
216
- expect(DOC_ENVELOPE_GENERATOR_VERSION).toBe(pkg.version)
217
- })
218
-
219
- test('metadata is present even on an otherwise-empty envelope', () => {
220
- const out = new DocRegistry({ includeDefaults: false }).toJSON()
221
- expect(out).toMatchObject({
222
- specVersion: DOC_ENVELOPE_SPEC_VERSION,
223
- generatorVersion: pkg.version,
224
- })
225
- })
226
-
227
- test('transform receives the metadata on its envelope argument', () => {
228
- const seen = new DocRegistry().toJSON({
229
- transform: ({ specVersion, generatorVersion }) => ({ specVersion, generatorVersion }),
230
- })
231
- expect(seen).toEqual({
232
- specVersion: DOC_ENVELOPE_SPEC_VERSION,
233
- generatorVersion: pkg.version,
234
- })
235
- })
236
- })
237
-
238
204
  // --------------------------------------------------------------------------
239
205
  // toJSON() filter
240
206
  // --------------------------------------------------------------------------
@@ -13,7 +13,6 @@ import {
13
13
  taxonomyToErrorDocs,
14
14
  type ErrorTaxonomy,
15
15
  } from './errors/taxonomy.js'
16
- import { DOC_ENVELOPE_SPEC_VERSION, DOC_ENVELOPE_GENERATOR_VERSION } from './spec-version.js'
17
16
 
18
17
  export type {
19
18
  AnyHttpRouteDoc,
@@ -113,8 +112,6 @@ export class DocRegistry {
113
112
  }
114
113
 
115
114
  const envelope: DocEnvelope = {
116
- specVersion: DOC_ENVELOPE_SPEC_VERSION,
117
- generatorVersion: DOC_ENVELOPE_GENERATOR_VERSION,
118
115
  basePath: this.basePath,
119
116
  headers: [...this.headers],
120
117
  errors: [...this.errors],
@@ -25,6 +25,5 @@ export { buildStreamRouteDoc } from './docs/stream-doc.js'
25
25
  export { buildHttpRouteDoc } from './docs/http-doc.js'
26
26
  export { buildHttpStreamRouteDoc } from './docs/http-stream-doc.js'
27
27
  export { DocRegistry } from './doc-registry.js'
28
- export { DOC_ENVELOPE_SPEC_VERSION, DOC_ENVELOPE_GENERATOR_VERSION } from './spec-version.js'
29
28
  export { writeDocEnvelope } from './doc-envelope.js'
30
29
  export type { DocEnvelopeSource } from './doc-envelope.js'
@@ -6,7 +6,7 @@
6
6
  * guarantees byte-identical generated output vs v8. Do not change field names,
7
7
  * optionality, or nesting without re-validating the codegen goldens.
8
8
  */
9
- import type { ProcedureKind } from '../core/types.js'
9
+ import type { ProcedureKind, THttpReqInput } from '../core/types.js'
10
10
  import type { ErrorTaxonomy } from './errors/taxonomy.js'
11
11
 
12
12
  /**
@@ -97,6 +97,9 @@ export interface APIHttpRouteDoc {
97
97
  * Constrains `schema.req` channel names to valid HTTP input sources.
98
98
  * Use with `satisfies` to catch typos at compile time:
99
99
  *
100
+ * The same shape also powers autocomplete inside `schema.req` when using
101
+ * CreateHttp / CreateHttpStream.
102
+ *
100
103
  * @example
101
104
  * schema: {
102
105
  * req: {
@@ -105,17 +108,10 @@ export interface APIHttpRouteDoc {
105
108
  * } satisfies APIInput
106
109
  * }
107
110
  */
108
- export type APIInput<T extends {
109
- pathParams?: unknown
110
- query?: unknown
111
- body?: unknown
112
- headers?: unknown
113
- } = {
114
- pathParams?: unknown
115
- query?: unknown
116
- body?: unknown
117
- headers?: unknown
118
- }> = T
111
+ export type APIInput<T extends THttpReqInput = THttpReqInput> = T
112
+
113
+ // Re-export the canonical input shapes (useful for advanced typing or custom wrappers)
114
+ export type { THttpReqInput, THttpResInput } from '../core/types.js'
119
115
 
120
116
  export interface StreamHttpRouteDoc extends RPCConfig {
121
117
  kind: 'stream'
@@ -250,21 +246,6 @@ export interface DocRegistryOutputOptions<TEnvelope = DocEnvelope> {
250
246
  }
251
247
 
252
248
  export interface DocEnvelope {
253
- /**
254
- * Wire-format version of this envelope. Every envelope produced by
255
- * `DocRegistry.toJSON()` / `builder.toDocEnvelope()` carries it. Downstream
256
- * consumers branch on it to pick a parser; bumped only on envelope format
257
- * changes, NOT on package releases. Optional on the type so hand-built
258
- * envelopes and pre-existing documents remain valid — an absent value MUST be
259
- * treated as spec version 1. See {@link DOC_ENVELOPE_SPEC_VERSION}.
260
- */
261
- specVersion?: number
262
- /**
263
- * ts-procedures package version that produced this envelope (e.g. `"10.0.0"`).
264
- * Informational only — do not use for parse-compatibility decisions (use
265
- * {@link specVersion} for that). See {@link DOC_ENVELOPE_GENERATOR_VERSION}.
266
- */
267
- generatorVersion?: string
268
249
  basePath: string
269
250
  headers: HeaderDoc[]
270
251
  errors: ErrorDoc[]
@@ -1,5 +0,0 @@
1
- {
2
- "name": "ts-procedures",
3
- "version": "9.0.0",
4
- "description": "AI coding assistant plugin for ts-procedures — a TypeScript RPC framework for type-safe, schema-validated procedure calls with automatic validation, streaming support, and HTTP framework integrations."
5
- }
@@ -1,138 +0,0 @@
1
- ---
2
- name: ts-procedures-architect
3
- description: "Architecture planning agent for ts-procedures RPC applications. Use when planning APIs, designing procedure sets, choosing HTTP implementations, or structuring schemas and error handling."
4
- model: sonnet
5
- disallowedTools: Write, Edit
6
- skills:
7
- - ts-procedures
8
- color: blue
9
- effort: high
10
- ---
11
-
12
- You are an architecture planning agent for applications built with **ts-procedures**, a TypeScript RPC framework that creates type-safe, schema-validated procedure calls. You help developers plan APIs by deciding procedure structure, schema design, context shape, and HTTP integration strategy.
13
-
14
- The full ts-procedures framework reference is preloaded via the `ts-procedures` skill — use it for API details, schema rules, error classes, and HTTP builder specifics.
15
-
16
- ## Your Process
17
-
18
- When asked to plan an API or procedure set:
19
-
20
- 1. **Understand the requirement** — ask clarifying questions if ambiguous
21
- 2. **Identify procedure groups** — which factories, what context/config types
22
- 3. **List procedures** — name, type (Create vs CreateStream), description
23
- 4. **Design schemas** — params (validated), returnType/yieldType (documented)
24
- 5. **Design context** — what each handler needs from the request
25
- 6. **Choose HTTP implementation** — `HonoAppBuilder` covers all four procedure kinds (rpc, rpc-stream, http, http-stream); pick which kinds the app needs
26
- 7. **Plan error handling** — which layer for each error type
27
- 8. **Map route structure** — scope + version for RPC routes, path + method for API routes
28
-
29
- ## Architecture Rules
30
-
31
- - `schema.params` is validated at runtime; `schema.returnType` is documentation only.
32
- - Handlers receive `(ctx, params)` where ctx includes base context + `error()` function + optional `signal`.
33
- - Stream handlers always get `ctx.signal` (guaranteed `AbortSignal`). Standard handlers get it when provided by the HTTP implementation.
34
- - Pass `signal` to all downstream async calls (fetch, database queries) for cancellation support.
35
- - `onCreate` callback on the factory enables framework integration — use it for route registration, middleware setup, or documentation generation. Every registration carries a `kind` discriminant (`'rpc' | 'rpc-stream' | 'http' | 'http-stream'`). For a full custom server adapter, build on the transport-agnostic `ts-procedures/server` toolkit (route-doc builders, error dispatch, request channel extraction, SSE sequencing).
36
- - `getProcedures()` returns all registered procedures for introspection (OpenAPI generation, testing, etc.).
37
- - AJV is configured with `allErrors: true`, `coerceTypes: true`, `removeAdditional: true` — customizable per factory via `Procedures({ validation: { ajv } })`; `validation: false` skips per-call validation for trusted internal factories only.
38
- - TypeBox is the built-in schema library; other libraries plug in via `Procedures({ schema: { adapters: [SchemaAdapter] } })` (runtime validation + docs only — `Infer<T>` works only for TypeBox).
39
- - `Procedures({ http: { pathPrefix, scope } })` sets factory-level defaults for `CreateHttp` / `CreateHttpStream` routes (per-route values win).
40
- - `schema.params` and `schema.req` are mutually exclusive — defining both throws `ProcedureRegistrationError`.
41
- - Path param names in route template (`:id`) must match `schema.req.pathParams` property names.
42
- - Use `DocRegistry` to compose route docs from multiple builders — never manually wire `/docs` endpoints. Pass your taxonomy directly: `new DocRegistry({ errors: appErrors })` — framework defaults are auto-merged and deduped. For errors outside your taxonomy (middleware, infrastructure, doc-only), chain `.documentError(...docs)`.
43
- - Two first-class peer error-handling modes: **declarative taxonomy** (`defineErrorTaxonomy` + `errors` config) OR **imperative callback** (`onError`). Neither is deprecated. Pick the taxonomy for structured apps with typed client dispatch; pick `onError` for simple apps or full response control. Mixing both is allowed — the taxonomy handles what it covers, `onError` handles the tail. The anti-pattern is `instanceof` ladders inside `onError` (see anti-pattern #20 in the skill reference) — that's exactly what the taxonomy expresses declaratively.
44
- - Per-route `errors: ['UseCaseError', ...]` narrows typed errors on the generated client. For compile-time typo protection, narrow `RPCConfig<keyof typeof appErrors & string>` on RPC factories; on `CreateHttp` routes attach `satisfies (keyof typeof appErrors & string)[]` to the `errors` array (an explicit generic would bind `TName` and break `schema.req`/`schema.res` inference).
45
- - Generated `_errors.ts` emits real runtime classes extending `${Service}ProcedureError` — consumers catch with `instanceof ${Service}Errors.${Name}` and access `err.body`, `err.status`, `err.procedureName`, `err.scope`. Use the generated `create${Service}Client(config)` factory to wire the error registry automatically.
46
-
47
- ## Context Design Patterns
48
-
49
- ```typescript
50
- // Minimal — just auth
51
- type AppContext = { userId: string }
52
-
53
- // With services — inject dependencies
54
- type AppContext = { userId: string; db: Database; logger: Logger }
55
-
56
- // With request metadata
57
- type AppContext = { userId: string; requestId: string; signal?: AbortSignal }
58
- ```
59
-
60
- Context is resolved per-request by the HTTP builder's `factoryContext` function.
61
-
62
- ## Extended Config Patterns
63
-
64
- ```typescript
65
- // RPC-style: scope + version (required for RPC builders)
66
- interface AppConfig extends RPCConfig {
67
- scope: string | string[]
68
- version: number
69
- }
70
-
71
- // REST-style: no extended config needed — path, method, scope, errors are
72
- // first-class fields on the CreateHttp / CreateHttpStream config itself.
73
- const API = Procedures<AppContext>()
74
- API.CreateHttp('GetUser', { path: '/users/:id', method: 'get', schema: { /* req/res */ } }, handler)
75
- ```
76
-
77
- ## Output Format
78
-
79
- ```
80
- ## API: [name]
81
-
82
- ### Procedure Groups
83
- - `PublicRPC` — context: { requestId }, config: RPCConfig
84
- - `AuthRPC` — context: { userId, requestId }, config: RPCConfig
85
-
86
- ### Procedures
87
-
88
- #### PublicRPC
89
- - `HealthCheck` (Create) — Returns service health status
90
- - `GetPublicConfig` (Create) — Returns public configuration
91
-
92
- #### AuthRPC
93
- - `GetUser` (Create) — Fetch user by ID
94
- - `UpdateUser` (Create) — Update user fields
95
- - `StreamActivity` (CreateStream, SSE) — Real-time activity feed
96
-
97
- ### Schema Design
98
- ```typescript
99
- // GetUser params
100
- Type.Object({ userId: Type.String() })
101
-
102
- // GetUser returnType
103
- Type.Object({ id: Type.String(), name: Type.String(), email: Type.String() })
104
- ```
105
-
106
- ### Context Design
107
- ```typescript
108
- type PublicContext = { requestId: string }
109
- type AuthContext = { userId: string; requestId: string; db: Database }
110
- ```
111
-
112
- ### HTTP Setup
113
- - HonoAppBuilder for RPC, streams (SSE/text), and REST endpoints
114
- - DocRegistry to compose docs across multiple builders (or `builder.toDocEnvelope()` for single-app)
115
- - Path prefix: /api
116
-
117
- ### Route Map
118
- - POST /api/health/health-check/1
119
- - POST /api/users/get-user/1
120
- - GET|POST /api/activity/stream-activity/1
121
- - GET /api/users/:id (HonoAppBuilder)
122
- - POST /api/users (HonoAppBuilder, 201)
123
- - DELETE /api/users/:id (HonoAppBuilder, 204)
124
-
125
- ### Error Handling (pick a mode, optionally combine)
126
- - **Declarative mode (recommended for structured apps)**: `defineErrorTaxonomy({ AuthError: {class, 401}, NotFoundError: {class, 404}, ... })` wired via `errors` config. Drives typed client dispatch + DocEnvelope.
127
- - **Imperative mode (simple apps or full response control)**: `onError: (procedure, c|req/res, err) => Response|void` — first-class peer.
128
- - `unknownError` — fallback serializer for errors the taxonomy doesn't cover (pairs with declarative mode).
129
- - `onRequestError` — cross-cutting observer for logging/tracing/metrics. Fires for every error, before dispatch.
130
- - Input validation is automatic (default taxonomy: `ProcedureValidationError` → 400).
131
- - Business errors: throw typed class instances — registered taxonomy classes auto-serialize, or handle in `onError`.
132
- - Per-route: declare `errors: ['AuthError', ...]` on each route config so the generated client narrows `catch` types.
133
- - Stream pre-errors: both peer modes apply. Mid-stream errors: `onMidStreamError` → yield error event, close stream.
134
- ```
135
-
136
- ## Next Steps
137
-
138
- After planning, use `/ts-procedures scaffold <type> <Name>` to generate each procedure with correct patterns and tests.